get_peak mode=abs gives negative values

Hi all,

I am using get_peak to obtain my peak values for every condition in my experiment (153 in total). However, with mode = 'abs' I still get negative values. Is this a bug?

For example;
In this image I have plotted the P1 timewindow for 1 evoked object.
example_neg_peak

If I run my code:

indoor_evoked_interest_p1 = indoor_evoked_interest.copy()
indoor_evoked_interest_p1.crop(tmin=0.080, tmax=0.130, include_tmax=False)            
indoor_evoked_interest_p1.plot()
        
                 
try:
#P1 get peak amplitude
      channel_p1, latency_p1, value_p1 = indoor_evoked_interest_p1.get_peak(return_amplitude=True, mode = 'abs')
      value_p1_microv = value_p1 * 1e3 #convert microV       
      latency_p1_milisec = latency_p1 * 1e3 # convert to milliseconds
      print(value_p1_microv)
      print(latency_p1_milisec)
            
except:
      pass

print(value_p1_microv) = -8.474316132876488
print(latency_p1_milisec) = 128.90625

However, I would except a positive value for my amplitude peak (value_p1_microv). Is this a bug?

I believe this is, in fact, expected behavior. mode='abs' means that we’ll find peaks and troughs, and the returned value will have the sign of whichever thing we found was the most extreme (peak – positive sign; trough – negative sign). So when you get a peak at 128 ms with a negative amplitude, this means that within the considered time period, the absolute amplitude value (distance from zero to this extreme point) was the highest there.

If you want the absolute values – just run abs(value_p1_microv)
Although I have to admit that a negative P1 is probably indicative of a small issue in the data or analysis flow :smiley:

… possibly indicative of a too-long time period you’re looking at, so you’re capturing a negative wave following the positive peak you’re actually interested in. To avoid this, use mode='pos'.

Thankyou! I would expect, based on the image above, P1 peaks at 0.097 with a peak value of 1.8microV. So I am trying to find this value and not the trough (probaly going towards N1).
If I run mode=pos I sometimes get a NaN indicating no pos values are found (not in many cases). For my N1 timewindow (130ms - 200ms, mode = neg) I do get a lot of NaN’s. It seem that my N1 is not really negative in my data. See example:
example_neg_n1

I do not know exacly why this is the case. I tried a longer baseline, but this did not had an effect. I did apply current source density conversion, so maybe this can explain? Otherwise my data is, unfortunately, noisy. Since I had this problem, I though having mode=abs will give me no NaN anymore, and more statistical power especially for my N1 component. However, mode=abs is not detecting the peaks I want. Maybe I can try sometime like this: Can get_peak function specify the maximum or minimum value? - #2 by richard

Can you please share this data and the code with me? I think you still have my email address :sweat_smile:

@Evelyne_Fraats I have downloaded the data you shared with me and will try to take a look within the next couple of days.