pythonastronomyspectrum

Standard deviation in python


This is the spectra I want to analyze. How do I measure the standard deviation excluding the channel where the peak is present? Lets say the peak is present between 30,000m/s and 90,000m/s. https://i.sstatic.net/6znnt.png


Solution

  • numpy.std()

    For excluding the peak, your going to have to define what you want to consider a peak to be - otherwise you are going to be making a solution for only the curve you present.

    If you know: (i) your data oscillates around 0, (ii) and that there are no massive troughs (i.e. very negative mins), (iii) and that it should roughly balance around 0 then you could use that to define a peak as greater than 2x the absolute of the min

    list1 = [0,1,2,15,-2,3,-3,5]
    list2 = [ent for ent in list1 if ent < 2*abs(min(list1))]
    
    std1 = numpy.std(list1)
    std2 = numpy.std(list2)
    

    If your data fails any of (i), (ii) or (iii) then your going to have to perform some filtering. Here's a useful link to get you started to that end: https://ocefpaf.github.io/python4oceanographers/blog/2015/03/16/outlier_detection/