如何利用vue實(shí)現(xiàn)波譜擬合詳解
主頁面-功能介紹
小白初入職場(chǎng)第一篇總結(jié),廢話比較多,求輕噴~

波譜擬合用來對(duì)某種材料或物質(zhì)的譜圖進(jìn)行識(shí)別和分析,每種物質(zhì)可以有多種成分,每種成分用component1、component2...表示,用Add another component和Remove component來控制每種成分的增加和刪除,每種成分由多種原子核構(gòu)成,即nuclei,用Add nucleus和Remove nucleus來控制每種成分內(nèi)原子核數(shù)量,每新增一個(gè)原子核,波譜就會(huì)分裂一次,譜峰數(shù)量由(1->2->4->8...)依次分裂。另外可以通過更改默認(rèn)參數(shù),改變波譜形態(tài),成分參數(shù)中:Relative amount表示每種成分占繪圖分量的百分比,百分比之和不超過100,giso用來計(jì)算分裂的中心位置,LineWidth用來控設(shè)置譜峰到譜谷的寬度,%Lorentzian表示譜峰形態(tài),一共兩種形態(tài),高斯和洛倫茲,兩者之和為100;原子核參數(shù):No of equivalent nuclei用來改變?cè)雍藗€(gè)數(shù),如果一種成分內(nèi)包含很多個(gè)一模一樣的參數(shù)時(shí),就可以通過改變這個(gè)參數(shù)實(shí)現(xiàn),Nuclear spin用來改變?cè)雍朔N類,Hyperfine用來設(shè)置分裂后兩峰之間的寬度。
再來一張圖:

每種成分?jǐn)?shù)量和參數(shù)、每種成分內(nèi)每種原子核數(shù)量和參數(shù)設(shè)置好后,對(duì)數(shù)據(jù)進(jìn)行處理,由三種結(jié)果,卷積、積分、二重積分,那就來看看數(shù)據(jù)的處理邏輯吧~

從數(shù)據(jù)流角度,主要進(jìn)行三步處理:數(shù)據(jù)->數(shù)據(jù)裂變->光譜計(jì)算->繪圖,左邊是算法實(shí)現(xiàn)所需的參數(shù)、右邊是對(duì)數(shù)據(jù)及每個(gè)步驟的描述。
代碼實(shí)現(xiàn)
遇到一個(gè)坑,一開始寫demo的時(shí)候用的vue+Ant design of vue,在select等其他組件的使用上都是正常的,但是在input number中就很變態(tài)了,給input number綁定的change事件,用戶在輸入兩位以上數(shù)據(jù)的時(shí)候,change事件會(huì)觸發(fā)兩次!??!想避免這個(gè)問題,于是用blur事件,問題又來了,因?yàn)檫@個(gè)頁面中組件的生成和刪除需要?jiǎng)討B(tài)渲染,并且根據(jù)前面的介紹很容易知道組件的渲染是有兩層結(jié)構(gòu)的,那么在用戶進(jìn)行點(diǎn)擊或輸入操作的時(shí)候,就需要傳遞一個(gè)參數(shù)(用來定位是哪個(gè)component以及每個(gè)component下面對(duì)應(yīng)的某一個(gè)nucle等等),能力有限( ╯□╰ )目前我沒有找到解決辦法,于是轉(zhuǎn)elementUI框架。
組件的動(dòng)態(tài)渲染用了一個(gè)比較巧妙的辦法,一開始我打算用render來寫,后來從部門大神那里學(xué)到通過遍歷列表進(jìn)行渲染,腦子之間還是有差距的。。。
<div v-for="(Con, i) in componentList" :key="Con[i]"><strong>Component {{i+1}}.</div>
同理原子核的動(dòng)態(tài)渲染也是這么實(shí)現(xiàn)的:
<div v-for="(li, j) in nucleusList[i]" :key="li[j]">{{j+1}}. No of equivalent nuclei:</div>
然后每次增加和刪除只需要操作數(shù)組列表的長(zhǎng)度即可~
各參數(shù)的綁定:component中參數(shù)均使用一維數(shù)組,chenge事件需傳遞一維數(shù)組的下標(biāo),component內(nèi)的nucleui均使用二維數(shù)組,change事件需傳遞二維數(shù)組的下標(biāo)。
以上介紹參數(shù)定義,接下來是數(shù)據(jù)處理:
// 首先計(jì)算裂變數(shù)據(jù)
stickspectrum (w) {
// console.log('組件信息', w)
const stick = new Array(2) // 返回包含stick[0]的stick光譜數(shù)組,stick[1]是位置
stick[0] = new Array()// 光譜強(qiáng)度
stick[1] = new Array()// 光譜位置
stick[1][0] = this.h * this.frequency / (this.r[w].g * this.mu)
for (var j = 0; j < this.r[w].equiv.length; j++) {
// console.log('stick[0].length', stick[0].length) //分裂后的光譜數(shù)據(jù)長(zhǎng)度
for (var i = stick[0].length - 1; i >= 0; i--) {
stick[0][i] /= Math.pow((2 * this.r[w].spin[j] + 1), this.r[w].equiv[j])
stick[1][i] -= this.r[w].equiv[j] * this.r[w].spin[j] * this.r[w].hfc[j]
for (var k = 0; k < 2 * this.r[w].equiv[j] * this.r[w].spin[j]; k++) {
stick[1].splice(i + k + 1, 0, stick[1][i] + this.r[w].hfc[j] * (k + 1))
stick[0].splice(i + k + 1, 0, 0)
}
for (var k = 0; k < this.r[w].equiv[j]; k++) {
for (var m = i + 2 * this.r[w].spin[j] * k; m >= i; m--) {
for (var ii = 0; ii < 2 * this.r[w].spin[j]; ii++) {
stick[0][m + ii + 1] += stick[0][m]
}
}
}
}
}
return stick
},
// 再對(duì)裂變后的數(shù)據(jù)進(jìn)行光譜計(jì)算
spectrum (stick) {
let xmin = Infinity; let xmax = 0
for (var k = 0; k < this.r.length; k++) {
xmin = Math.min(Math.min.apply(Math, stick[k][1]) - 10 * this.r[k].width, xmin)
xmax = Math.max(Math.max.apply(Math, stick[k][1]) + 10 * this.r[k].width, xmax)
}
const tmp = xmax - xmin
xmax += tmp * 0.05
xmin -= tmp * 0.05
const step = (xmax - xmin) / (this.No_integers - 1)
for (let i = 0; i < this.No_integers; i++) {
this.XY[0][i][0] = xmin + step * i
this.XY[0][i][1] = 0
this.XYint[0][i][0] = this.XY[0][i][0]
this.XYint[0][i][1] = 0
this.XYdoubleint[0][i][0] = this.XY[0][i][0]
this.XYdoubleint[0][i][1] = 0
}
for (let k = 0; k < this.r.length; k++) { // 分量累加
const sticks = new Array(this.No_integers)
for (var i = 0; i < stick[k][0].length; i++) {
var j = Math.round((stick[k][1][i] - xmin) / step)
sticks[j] = sticks[j] ? sticks[j] + stick[k][0][i] : stick[k][0][i]
}
const tmp = new Array(this.No_integers)// 第一種光譜繪圖位置數(shù)據(jù)
let ind = 0
for (var i = 0; i < this.No_integers; i++) {
if (sticks[i]) { // 建立峰值索引——sticks[i]===1即峰值所在。
tmp[ind] = i
ind++
}
}
const tmpint = new Array(this.No_integers) // 用來保存每個(gè)分量的積分
const tmpdoubleint = new Array(this.No_integers) // 用來保存每個(gè)分量的二重積分
for (var i = 0; i < this.No_integers; i++) tmpint[i] = 0
tmpdoubleint[0] = 0
const rwid = Number(this.r[k].width)
const rwid2 = Math.pow(rwid, 2)
const lortmp = Number(this.r[k].percent) * Number(this.r[k].lor) / 100 * Math.sqrt(3) / Math.PI // 洛倫茲線乘積
const gaustmp = Number(this.r[k].percent) * (100 - Number(this.r[k].lor)) / 100 * Math.sqrt(2 / Math.PI) // 高斯線乘法器
for (let i = 0; i < this.No_integers; i++) {
for (let j = 0; j < ind; j++) {
const delta = this.XY[0][i][0] - this.XY[0][tmp[j]][0]
const delta2 = Math.pow(delta, 2)
if ((rwid > step && Math.abs(-0.5 * rwid - delta) < 0.5 * step) || (rwid < step && -0.5 * rwid - delta > 0 && -0.5 * rwid - delta < step)) {
this.XY[0][i][1] += sticks[tmp[j]] * (lortmp * 0.5 / rwid2 + gaustmp * 2 / Math.sqrt(Math.E) / rwid2)
} else if ((rwid > step && Math.abs(0.5 * rwid - delta) < 0.5 * step) || (rwid < step && delta - 0.5 * rwid > 0 && delta - 0.5 * rwid < step)) {
this.XY[0][i][1] -= sticks[tmp[j]] * (lortmp * 0.5 / rwid2 + gaustmp * 2 / Math.sqrt(Math.E) / rwid2)
} else {
this.XY[0][i][1] += sticks[tmp[j]] * (gaustmp * (-4) / rwid / rwid2 * delta * Math.exp(-2 * delta2 / rwid2) + lortmp * (-delta) * rwid / Math.pow((delta2 + 3 / 4 * rwid2), 2)) // 其他情況下的正常計(jì)算,高斯+洛倫茲
}
this.dataarray = [this.XY, this.XYint, this.XYdoubleint]
tmpint[i] += sticks[tmp[j]] * (gaustmp * Math.exp(-2 * delta2 / rwid2) / rwid + lortmp / 2 / rwid / (0.75 + delta2 / rwid2)) // 高斯+洛倫茲積分-明確計(jì)算以避免積分誤差
}
}
for (let j = 1; j < this.No_integers; j++) {
tmpdoubleint[j] = tmpdoubleint[j - 1] + step * (tmpint[j] + tmpint[j - 1]) / 2
} // 二重積分
// console.log('二重積分', tmpdoubleint)
const mm = tmpdoubleint[this.No_integers - 1] / Number(this.r[k].percent) // 有多少積分高于理論(只發(fā)生在非常尖銳的線)
for (let j = 1; j < this.No_integers; j++) {
this.XYdoubleint[0][j][1] += mm > 1 ? tmpdoubleint[j] / mm : tmpdoubleint[j] // 第三種頻譜數(shù)據(jù) 如果二重積分高于理論,將其標(biāo)準(zhǔn)化
this.XYint[0][j][1] += tmpint[j] // 第二種頻譜數(shù)據(jù)
}
}
// console.log('XYint', this.XYint[0])
},
計(jì)算完成的光譜,返回三種數(shù)據(jù)XY、XYint、XYdouble,然后就是繪圖~
到此這篇關(guān)于如何利用vue實(shí)現(xiàn)波譜擬合的文章就介紹到這了,更多相關(guān)vue實(shí)現(xiàn)波譜擬合內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
vue中使用v-if隱藏元素時(shí)會(huì)出現(xiàn)閃爍問題的解決
這篇文章主要介紹了vue中使用v-if隱藏元素時(shí)會(huì)出現(xiàn)閃爍問題的解決方案,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2022-04-04
vue項(xiàng)目中圖片選擇路徑位置static或assets的區(qū)別及說明
這篇文章主要介紹了vue項(xiàng)目中圖片選擇路徑位置static或assets的區(qū)別及說明,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2022-09-09
微信小程序Echarts動(dòng)態(tài)使用及圖表層級(jí)踩坑解決方案
這篇文章主要為大家介紹了微信小程序Echarts動(dòng)態(tài)使用及圖表層級(jí)踩坑解決方案,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2023-03-03
Vue?Router解決多路由復(fù)用同一組件頁面不刷新問題(場(chǎng)景分析)
這篇文章主要介紹了Vue?Router解決多路由復(fù)用同一組件頁面不刷新問題,多路由復(fù)用同一組件的場(chǎng)景分析,本文給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2022-08-08
關(guān)于vue.js彈窗組件的知識(shí)點(diǎn)總結(jié)
最近在開發(fā)過程對(duì)對(duì)于組件化的開發(fā)有一些感想,于是開始記錄下這些。彈窗組件一直是 web 開發(fā)中必備的,使用頻率相當(dāng)高,最常見的莫過于 alert,confirm和prompt這些,不同的組件庫對(duì)于彈窗的處理也是不一樣的,下面來一起看看吧。2016-09-09

