add_changepoints_to_nap#

ethograph.io.pynapple.add_changepoints_to_nap(data, target_feature, changepoint_func, **func_kwargs)[source]#

Detect changepoints in a pynapple time series and return them as a TsGroup.

Applies changepoint_func independently to each unit or column in data. Returns a nap.TsGroup where each unit contains the changepoint timestamps for one source series. Source metadata (label, feature name, type) is stored as group metadata columns; if data is itself a TsGroup, its metadata columns are forwarded as well.

Parameters:
  • data (nap.Tsd | nap.TsdFrame | nap.TsGroup) – Input time series. For a Tsd a single unit is produced; for a TsdFrame one unit per column; for a TsGroup one unit per neuron/unit.

  • target_feature (str) – Human-readable label recorded in the output metadata (e.g. "speed").

  • changepoint_func (callable) – A function f(x, **kwargs) -> array that accepts a 1-D numpy array of values and returns an array of changepoint times (or a binary indicator of the same length).

  • **func_kwargs – Forwarded to changepoint_func.

Returns:

One unit per input series, containing changepoint timestamps.

Return type:

nap.TsGroup

Examples

>>> import ethograph as eto
>>> from ethograph.features.changepoints import find_troughs
>>> data = eto.load_nap_data("experiment.nwb")
>>> cp_group = eto.add_changepoints_to_nap(
...     data["speed"],
...     target_feature="speed",
...     changepoint_func=find_troughs,
...     prominence=0.3,
... )