[SciPy-User] Fitting Gaussian in spectra

Kevin Gullikson kevin.gullikson@gmail....
Sat Sep 29 10:28:17 CDT 2012

I'm not sure about the peak-finding part, but for fitting the continuum by
ignoring peaks I often do an iterative fit such as below. It ignores more
and more points from the peaks. I use this kind of an algorithm for fitting
the continuum on absorption spectra pretty often.

done = False
while not done:
  done = True
  fit = numpy.poly1d(numpy.polyfit(x,y,order))
  residuals = y - fit(x)
  std = numpy.std(residuals)
  badindices = numpy.where(residuals > 5*std)[0]
  if badindices.size > 0:
    done = False
    x = numpy.delete(x, badindices)
    y = numpy.delete(y, badindices)

That solution may not be the best for you if you have a very large array
though, because deleting indices from a numpy array is inefficient.


Kevin Gullikson

On Fri, Sep 28, 2012 at 1:45 PM, Joe Philip Ninan <indiajoe@gmail.com>wrote:

> Hi,
> I have a spectra with multiple gaussian emission lines over a noisy
> continuum.
> My primary objective is to find areas under all the gaussian peaks.
> For that, the following is the algorithm i have in mind.
> 1) fit the continuum and subtract it.
> 2) find the peaks
> 3) do least square fit of gaussian at the peaks to find the area under
> each gaussian peaks.
> I am basically stuck at the first step itself. Simple 2nd or 3rd order
> polynomial fit is not working because the contribution from peaks are
> significant. Any tool exist to fit continuum ignoring the peaks?
> For finding peaks, i tried find_peaks_cwt in signal module of scipy. But
> it seems to be quite sensitive of the width of peak and was picking up
> non-existing peaks also.
> The wavelet used was default mexican hat. Is there any better wavelet i
> should try?
> Or is there any other module in python/scipy which i should give a try?
> Thanking you.
> -cheers
> joe
> --
> /---------------------------------------------------------------
> "GNU/Linux: because a PC is a terrible thing to waste" -  GNU Generation
> _______________________________________________
> SciPy-User mailing list
> SciPy-User@scipy.org
> http://mail.scipy.org/mailman/listinfo/scipy-user
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.scipy.org/pipermail/scipy-user/attachments/20120929/5533e6c1/attachment.html 

More information about the SciPy-User mailing list