downsample_trialtree#

ethograph.downsample_trialtree(dt, factor)[source]#

Downsample every trial in a TrialTree using a min-max envelope.

For each contiguous block of factor samples, two values are kept: the block minimum and maximum. This preserves peaks and troughs (important for spike-like signals) while reducing the number of samples by roughly factor / 2.

All time-like dimensions in every trial are downsampled independently, so datasets with mixed sampling rates (e.g. 30 Hz pose + 44 kHz audio) are handled correctly.

Parameters:
  • dt (TrialTree) – Input tree. Not modified in place.

  • factor (int) – Number of raw samples per envelope block. For example, factor=10 on a 30 Hz signal produces ~6 Hz output (2 points per block).

Returns:

New tree with downsampled data. Each trial’s attrs includes downsample_factor and downsample_method.

Return type:

TrialTree

Examples

>>> import ethograph as eto
>>> dt = eto.open("high_rate_experiment.nc")
>>> dt_small = eto.downsample_trialtree(dt, factor=20)
>>> dt_small.save("experiment_downsampled.nc")