【问题标题】:FWHM calculation using python使用 python 计算 FWHM
【发布时间】:2018-08-12 12:52:56
【问题描述】:

我正在尝试使用 python 计算光谱的 FWHM。光谱描述(我说的是物理学)对我来说有点复杂,我无法使用一些简单的高斯或洛伦齐分布来拟合数据。

到目前为止,我设法管理数据的插值并通过半最大值绘制一条平行于 X 轴的直线。

如何找到峰两侧两条线的交点坐标?

我知道如果我将光标放在这些点上,它会给我坐标,但我想自动化这个过程,使它变得更加用户友好。我该怎么做?

【问题讨论】:

    标签: python analysis spectral


    【解决方案1】:

    除了前面的答案,如果baseline不为0,那么((max-min)/2) + min。这就是我为解决我的问题所做的。谢了。

    【讨论】:

      【解决方案2】:
      from matplotlib import pyplot as mp
      import numpy as np
      
      def peak(x, c):
          return np.exp(-np.power(x - c, 2) / 16.0)
      
      def lin_interp(x, y, i, half):
          return x[i] + (x[i+1] - x[i]) * ((half - y[i]) / (y[i+1] - y[i]))
      
      def half_max_x(x, y):
          half = max(y)/2.0
          signs = np.sign(np.add(y, -half))
          zero_crossings = (signs[0:-2] != signs[1:-1])
          zero_crossings_i = np.where(zero_crossings)[0]
          return [lin_interp(x, y, zero_crossings_i[0], half),
                  lin_interp(x, y, zero_crossings_i[1], half)]
      
      # make some fake data
      x=np.linspace(0,20,21)
      y=peak(x,10)
      
      # find the two crossing points
      hmx = half_max_x(x,y)
      
      # print the answer
      fwhm = hmx[1] - hmx[0]
      print("FWHM:{:.3f}".format(fwhm))
      
      # a convincing plot
      half = max(y)/2.0
      mp.plot(x,y)
      mp.plot(hmx, [half, half])
      mp.show()
      

      两点的(x, y)坐标分别为(hmx[0], half)(hmx[1], half)

      【讨论】:

      • 您好,请问基线/背景是否不为 0,这是否意味着需要将高度减去该基线/背景?谢谢!
      猜你喜欢
      • 2015-07-05
      • 2014-08-14
      • 1970-01-01
      • 2023-02-15
      • 2013-04-30
      • 2020-12-09
      • 2021-08-16
      • 1970-01-01
      • 2021-02-19
      相关资源
      最近更新 更多