0

Its easy to identify the highest peak on the right side of the bimodal distribution. I need to determine the left (always also lower in my data) peak value in the following bimodal distribution:https://drive.google.com/open?id=1n-Kp5loJze-L3vNgq7_3qFrmI-JiE20K

Here, 1 is the left peak and 2 is the right peak. 1 is always lower than 2.

Using scipy.signal.argrelmax, I have been able to find all the relative peaks but I need to extract specifically left peak in my data (marked by 1).

The values of only two peaks marked by 1 and 2 in the figure attached and ignore all other peaks that are determined. peak 2 on the right is easy to extract but I also want to extract peak 1.

  • can you provide an example? like bin height ? – Mr_U4913 Oct 17 '19 at 23:29
  • are the two peaks separated like this all the time? i.e. ~ greater than 0.2 belong to the second set, less than belongs to the first? or some kind of divider you can specify – Derek Eden Oct 17 '19 at 23:32
  • you could probably just fit a function to it to find the local min between the two peaks which would be your divider..i.e find absolute max left and right of the divider – Derek Eden Oct 17 '19 at 23:33
  • @Mr_U4913 array([ 3, 3, 5, 6, 11, 14, 16, 19, 24, 35, 49, 51, 52, 53, 56, 57, 57, 60, 62, 65, 67, 70, 72, 72, 73, 74, 91, 95, 97, 106, 109, 121, 130, 136, 177, 177, 179, 180, 191, 229, 325]). These are all the peak values of the histogram that I have uploaded. – studysmart Oct 17 '19 at 23:35
  • I found a guy has a similar question, https://stackoverflow.com/questions/31910524/calculate-histogram-peaks-in-python – Mr_U4913 Oct 17 '19 at 23:37
  • @DerekEden No, the distribution changes but its bimodal every time. The picture that I have attached is just one case. The distribution will be different in other cases. – studysmart Oct 17 '19 at 23:38
  • @Mr_U4913 I think his question is different he is asking about how to determine peaks. I already know how to determine peaks. I already have all the peaks of my distribution. I just need those two peaks and ignore all the other peaks. – studysmart Oct 17 '19 at 23:41
  • how bout my second comment by using a fitted function to determine where the split is? – Derek Eden Oct 17 '19 at 23:45
  • @DerekEden This strategy could work. I ll try and update you soon. Thank you – studysmart Oct 17 '19 at 23:47
  • I tried fitting a polynomial to the data and getting the local min as the divider which works, although sometimes choosing the order of the polynomial is difficult...you would think power 4 would work, but sometimes it doesn't fit a double-peaked quartic – Derek Eden Oct 18 '19 at 00:09
  • Why without smoothing? What if smoothing was just used in an intermediate step? Cause a simple rolling median or mean would fix this for you very easily, and you could then trivially find the local maxima – Mad Physicist Oct 18 '19 at 00:20
  • Please upload the picture to SO hosting. Also, please provide some information about the data, like noise characterization. How far between successive noise peaks, etc. – Mad Physicist Oct 18 '19 at 00:23
  • Please show how you use argrelmax. It should work perfectly well if you set the parameters right. – Mad Physicist Oct 18 '19 at 00:40

1 Answers1

0

something along these lines might work, assuming the x-bins and y-counts are np.arrays:

import numpy.polynomial.polynomial as poly from scipy.signal import argrelextrema

c = poly.polyfit(x,y,4)
fit = poly.polyval(x,c)
i = argrelextrema(fit, np.less)

this would give you the dividing point (approximately) between the bimodal distribution

then you could do something like:

p1 = np.max(y[:i])
p2 = np.max(y[i:])

sometimes the quartic doesn't fit the way you want it so I appreciate this might be challenging to implement, but potentially something along these lines, or even a trig fit?

Hope it helps

Derek Eden
  • 4,403
  • 3
  • 18
  • 31
  • Thank you. i has no value. When I print i it displays c = poly.polyfit(center_array,count_array,4) fit = poly.polyval(center_array,c) i = argrelextrema(fit, np.less) >>> i (array([], dtype=int32),) – studysmart Oct 18 '19 at 00:37
  • plot the fit to see if it's lining up good.. I made a few sample datasets where the quartic was basically quadratic shape, and sometimes it had 2 peaks..might have to play with it – Derek Eden Oct 18 '19 at 00:43
  • maybe a really smoothed moving avg? – Derek Eden Oct 18 '19 at 00:44
  • why you wrote np.less initially? – studysmart Oct 18 '19 at 01:08
  • Thank you.It worked with 5 instead of 4. So, every time I have to be careful regarding the degree of the fitting polynomial. Because, every time I ll have the unique bimodal distribution.So, I have to see which works according to the bimodal distribution. – studysmart Oct 18 '19 at 01:28