簡體   English   中英

擬合兩條 voigt 曲線,一個接一個使用 lmfit

[英]Fitting two voigt curves, one after the other using lmfit

我有以下在拉曼(背景減去數據)上收集的氖的發射光譜:

    x=np.array([[1114.120887, 1114.682293, 1115.243641, 1115.80493 , 1116.366161, 1116.927334, 1117.488449, 1118.049505, 1118.610503, 1119.171443, 1119.732324, 1120.293147, 1120.853912, 1121.414619, 1121.975267, 1122.535857, 1123.096389, 1123.656863, 1124.217278, 1124.777635, 1125.337934, 1125.898175, 1126.458357, 1127.018482, 1127.578548, 1128.138556, 1128.698505, 1129.258397, 1129.81823 , 1130.378005, 1130.937722, 1131.497381, 1132.056981]])

    y=np.array([[-4.89046878e+00, -4.90985832e+00, -5.92924587e+00, -3.28194437e+00, -1.96801488e+00, -3.32070938e+00, -5.34008887e+00, -3.59466330e-01, -2.04552879e+00, -1.06490224e+00,  8.24910035e+00,  5.32297309e+01, 1.11543677e+02,  8.98576241e+01,  2.18504948e+02,  7.15152212e+02, 7.62799601e+02,  2.89446870e+02,  7.24275144e+01,  1.94081610e+01, 1.72212272e+00,  7.02773412e-01, -3.16573861e-01,  4.99745483e+00, 7.97811157e+00,  6.25396305e-01,  6.27274408e+00, -4.41328018e+00, -7.76592840e+00,  3.88142539e+00,  6.52872017e+00,  1.50939096e+00, -8.43249208e-01]])

我使用 lmfit 安裝了一個 Voigt function,具體來說:

    model = VoigtModel()+ ConstantModel()
    params=model.make_params(center=1123.096389, amplitude=1000, sigma=0.27)
    result = model.fit(y.flatten(), params, x=x.flatten())

LH 肩上有第二個峰值(抱歉不能發布圖像)- 使用商業峰值擬合軟件的人適合第一個 voigt,然后添加第二個,然后調整兩者的擬合。 我將如何在 python 中執行此操作?

一個相關的問題——有沒有辦法優化峰值擬合中包含多少點。 現在,我只提供覆蓋一組光譜范圍的 x 和 y 數據來進行峰值擬合。 但是商業軟件優化了給定峰值擬合中包含的范圍(我假設使用殘差)。 我將如何重新創建它?

謝謝!

您可以像這樣手動完成:

import numpy as np
import matplotlib.pyplot as plt
from lmfit.models import VoigtModel, ConstantModel

x=np.array([1114.120887, 1114.682293, 1115.243641, 1115.80493 , 1116.366161, 1116.927334, 1117.488449, 1118.049505, 1118.610503, 1119.171443, 1119.732324, 1120.293147, 1120.853912, 1121.414619, 1121.975267, 1122.535857, 1123.096389, 1123.656863, 1124.217278, 1124.777635, 1125.337934, 1125.898175, 1126.458357, 1127.018482, 1127.578548, 1128.138556, 1128.698505, 1129.258397, 1129.81823 , 1130.378005, 1130.937722, 1131.497381, 1132.056981])
y=np.array([-4.89046878e+00, -4.90985832e+00, -5.92924587e+00, -3.28194437e+00, -1.96801488e+00, -3.32070938e+00, -5.34008887e+00, -3.59466330e-01, -2.04552879e+00, -1.06490224e+00,  8.24910035e+00,  5.32297309e+01, 1.11543677e+02,  8.98576241e+01,  2.18504948e+02,  7.15152212e+02, 7.62799601e+02,  2.89446870e+02,  7.24275144e+01,  1.94081610e+01, 1.72212272e+00,  7.02773412e-01, -3.16573861e-01,  4.99745483e+00, 7.97811157e+00,  6.25396305e-01,  6.27274408e+00, -4.41328018e+00, -7.76592840e+00,  3.88142539e+00,  6.52872017e+00,  1.50939096e+00, -8.43249208e-01])

model = VoigtModel() + ConstantModel()
params=model.make_params(center=1123.0, amplitude=1000, sigma=0.27)
result1 = model.fit(y.flatten(), params, x=x.flatten())

rest = y-result1.best_fit

model = VoigtModel() + ConstantModel()
params=model.make_params(center=1120.5, amplitude=200, sigma=0.27)
result2 = model.fit(rest, params, x=x.flatten())

rest -= result2.best_fit

plt.plot(x, y, label='Original')
plt.plot(x, result1.best_fit, label='1123.0')
plt.plot(x, result2.best_fit, label='1120.5')
plt.plot(x, rest, label='residual')
plt.legend()
plt.show()

在此處輸入圖像描述

您必須確保殘差有意義。 在這種情況下,非常接近於 0,所以我認為這很好。

lmfit確實優化了擬合,因此沒有必要精確定位峰值 position 的確切值。另外,重要的是要指出,由於該數據(以及一般的光譜學)的分辨率,最高點不一定是峰的中心。 此外,由於相同的原因,有些肩膀可能不是肩膀,但在這種情況下看起來像是。

對於您的相關問題 - 從lmfit文檔來看,它使用了您輸入的所有范圍。 殘差似乎不是解決方案,因為您遇到了同樣的問題(要考慮的范圍)。 我相信您提到的商業 SW 使用多元曲線分辨率 (MCR)。 幾十年來,這些反卷積問題一直是熱門話題。 如果您對這種解決方案感興趣,我建議您閱讀多元曲線分辨率 (MCR)。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM