Finding the full width half maximum of a peak

后端 未结 5 1995
野的像风
野的像风 2020-12-07 23:28

I have been trying to figure out the full width half maximum (FWHM) of the the blue peak (see image). The green peak and the magenta peak combined make up the blue peak. I h

5条回答
  •  离开以前
    2020-12-08 00:00

    Here is a nice little function using the spline approach.

    from scipy.interpolate import splrep, sproot, splev
    
    class MultiplePeaks(Exception): pass
    class NoPeaksFound(Exception): pass
    
    def fwhm(x, y, k=10):
        """
        Determine full-with-half-maximum of a peaked set of points, x and y.
    
        Assumes that there is only one peak present in the datasset.  The function
        uses a spline interpolation of order k.
        """
    
        half_max = amax(y)/2.0
        s = splrep(x, y - half_max, k=k)
        roots = sproot(s)
    
        if len(roots) > 2:
            raise MultiplePeaks("The dataset appears to have multiple peaks, and "
                    "thus the FWHM can't be determined.")
        elif len(roots) < 2:
            raise NoPeaksFound("No proper peaks were found in the data set; likely "
                    "the dataset is flat (e.g. all zeros).")
        else:
            return abs(roots[1] - roots[0])
    

提交回复
热议问题