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.TsGroupwhere 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 aTsGroup, its metadata columns are forwarded as well.- Parameters:
data (nap.Tsd | nap.TsdFrame | nap.TsGroup) – Input time series. For a
Tsda single unit is produced; for aTsdFrameone unit per column; for aTsGroupone 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) -> arraythat 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, ... )