python数据处理3: 光谱曲线的洛伦兹函数拟合

33 篇文章 10 订阅

目标

光谱曲线拟合,采用洛伦兹函数。
python数据处理2: 拟合数据、整合数据、导出数据的一个应用。

软件

OriginPro 8.5
Anaconda3 + Spyder 3.3.6 + Python 3.7.4

理论

为什么原子光谱线具有宽度?https://www.zhihu.com/question/59484318
高斯分布+柯西-洛伦兹分布+三种光谱线型函数(洛伦兹线型函数+多普勒[高斯]线型函数+vogit 线型函数)https://blog.csdn.net/Gou_Hailong/article/details/105761432

公式

洛伦兹函数
在这里插入图片描述
y = y 0 + 2 A π w 4 ∗ ( x − x c ) 2 + w 2 y = y_0 + \frac{2A}{\pi}\frac{w}{4*(x-x_c)^2 + w^2} y=y0+π2A4(xxc)2+w2w

Origin拟合

Analsysis>>Fitting>>Nonlinear Cuver Fit>>Peak function>>Lorentz
在这里插入图片描述

Python拟合

代码

import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
from scipy.optimize import curve_fit

def Lorentz(x,y0,A,xc,w):
    y = y0 + (2*A/np.pi)*(w/(4*(x-xc)**2 + w**2))
    return y


fileName = 'data.csv'
data = pd.read_csv(fileName)

x = data['x']
y = data['y']

fig, ax = plt.subplots()
ax.plot(x,y,'o')

p,c = curve_fit(Lorentz, x, y,
                p0=[-100,500,427.5,0.1],absolute_sigma=True)
y0,A,xc,w=p

xfit = np.linspace(x.min(),x.max(),100)
yfit = Lorentz(xfit,y0,A,xc,w)

ax.plot(xfit,yfit,'-')

print('y0,A,xc,w:')
print(y0,A,xc,w)
print('y0,A,xc,w: standard error')
print(np.sqrt(np.diag(c)))

拟合效果

在这里插入图片描述

输出

y0,A,xc,w:
-96.63499195846272 645.4678298613572 427.4514687215421 0.1322134848839823
y0,A,xc,w: standard error
[1.01581504e+00 6.69016313e-01 2.91213859e-05 1.35725434e-04]

关于数据初始化

在这里插入图片描述
可以参考Origin的初始化算法。
https://www.chem.pku.edu.cn/resim/docs/2019-09/20190924213619569426.pdf
https://www.originlab.com/doc/en/OriginC/ref/peak_pos\

总结

获得peak位置 x c x_c xc和半峰宽 w w w

参考

光谱曲线的洛伦兹函数拟合
http://muchong.com/t-8968688-1
numpy.linspace使用详解
https://blog.csdn.net/You_are_my_dream/article/details/53493752
利用scipy.optimize.curve_fit对函数进行拟合
https://blog.csdn.net/jason_cuijiahui/article/details/87211889
markdown中插入图片怎么定义图片的大小或比例?
https://www.zhihu.com/question/23378396

data

data.csv

x,y
427.256,450.7287
427.327,385.4204
427.398,1831.3
427.469,2785.1
427.54,1106.8
427.611,221.6083
427.682,132.2139
  • 26
    点赞
  • 109
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 8
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 8
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

银河漫游者

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值