pynapple.process.randomize#
Functions to shuffle timestamps to create surrogate datasets.
Functions
|
Jitters each time stamp independently of random amounts uniformly drawn between -max_jitter and max_jitter. |
Resamples the timestamps in the time support, with uniform distribution. |
|
|
Shifts all the time stamps of a random amount between a minimum and maximum shift, wrapping the end of the time support to the beginning. |
Randomizes the timestamps by shuffling the intervals between them. |
- pynapple.process.randomize.jitter_timestamps(ts, max_jitter=None, keep_tsupport=False)[source]#
Jitters each time stamp independently of random amounts uniformly drawn between -max_jitter and max_jitter.
- Parameters:
ts (Ts or TsGroup) – The timestamps to jitter. If TsGroup, jitter is applied to each element of the group.
max_jitter (float) – maximum jitter
keep_tsupport (bool, optional) – If True, keep time support of the input. The number of timestamps will not be conserved. If False, the time support is inferred from the jittered timestamps. The number of tmestamps is conserved. (default: False)
- Returns:
The jittered timestamps
- Return type:
- pynapple.process.randomize.resample_timestamps(ts)[source]#
Resamples the timestamps in the time support, with uniform distribution.
- pynapple.process.randomize.shift_timestamps(data, min_shift=0.0, max_shift=None, mode='drop')[source]#
Shifts all the time stamps of a random amount between a minimum and maximum shift, wrapping the end of the time support to the beginning.
Notes
If the time support of the input has multiple epochs, some timepoints will fall outside of those epochs after shifting. In
mode='drop', those timepoints are dropped. Inmode='wrap', timestamps are wrapped circularly using the full time support. However, if there are multiple epochs andmode='wrap', timepoints falling outside the epochs in the middle are still dropped.- Parameters:
data (Ts, TsGroup) – The timeseries object whose timestamps to shift. If TsGroup, shifts all objects in the group independently.
min_shift (float, optional) – minimum shift (default: 0)
max_shift (float, optional) – maximum shift, (default: length of time support)
mode (
'drop'or'wrap', optional) –How to handle timestamps that fall outside the time support after shifting.
'drop': (default): drop those timestamps'wrap': circularly wrap timestamps within the time support
- Returns:
The randomly shifted timestamps
- Return type:
Examples
Fixed shift with default
mode='drop':>>> import pynapple as nap >>> ts = nap.Ts([25, 27, 33.3, 34.5]) >>> shifted_ts = nap.shift_timestamps(ts, min_shift=1, max_shift=1, mode="drop") >>> shifted_ts Time (s) 26.0 28.0 34.3 shape: 4
The last timepoint falls outside the time support, so it is dropped.
With multiple epochs, timestamps falling outside the support anywhere are dropped:
>>> epochs = nap.IntervalSet(start=[25, 30], end=[27, 34.5]) >>> ts = nap.Ts([25, 27, 33.3, 34.5], time_support=epochs) >>> shifted_ts = nap.shift_timestamps(ts, min_shift=1, max_shift=1, mode="drop") >>> shifted_ts Time (s) 26.0 34.3 shape: 3
Using
mode='wrap'to circularly wrap timestamps within the full time support:>>> epochs = nap.IntervalSet(start=0, end=40) >>> ts = nap.Ts([38, 39.5], time_support=epochs) >>> shifted_ts = nap.shift_timestamps(ts, min_shift=5, max_shift=5, mode="wrap") >>> shifted_ts Time (s) 3.0 4.5 shape: 2
When
mode='wrap'and there are multiple epochs, the start and end are circular, but everything in between is not:>>> import pynapple as nap >>> epochs = nap.IntervalSet(start=[25, 30], end=[27, 34.5]) >>> ts = nap.Ts([25, 27, 33.3, 34.5], time_support=epochs) >>> shifted_ts = nap.shift_timestamps(ts, min_shift=1, max_shift=1, mode="wrap") >>> shifted_ts Time (s) 26.0 26.0 34.3 shape: 3