pynapple.core.time_series.Tsd.threshold#

Tsd.threshold(thr, method='above')[source]#

Apply a threshold function to the tsd to return a new tsd with the time support being the epochs above/below/>=/<= the threshold

Parameters:
  • thr (float) – The threshold value

  • method (str, optional) – The threshold method (“above”[default], “below”, “aboveequal”, “belowequal”)

Returns:

out – All the time points below/ above/greater than equal to/less than equal to the threshold

Return type:

Tsd

Raises:
  • ValueError – Raise an error if method is unknown.

  • RuntimeError – Raise an error if thr is too high/low and no epochs is found.

Examples

This example finds all epoch above 0.5 within the tsd object.

>>> import pynapple as nap
>>> tsd = nap.Tsd(t=np.arange(100), d=np.random.rand(100))
>>> newtsd = tsd.threshold(0.5)

The epochs with the times above/below the threshold can be accessed through the time support:

>>> tsd = nap.Tsd(t=np.arange(100), d=np.arange(100), time_units='s')
>>> tsd.threshold(50).time_support
>>>    start   end
>>> 0   50.5  99.0