aind_ephys_utils.accessors.dataarray module¶
xarray accessor for exploratory electrophysiology analysis.
This module registers the .ephys accessor for xarray.DataArray.
The accessor is intended to provide a small, composable public surface area that interoperates with standard xarray operations (e.g., .sel, .mean).
- class aind_ephys_utils.accessors.dataarray.EphysDataArrayAccessor(xarray_obj: DataArray)¶
Bases:
objectAccessor for exploratory electrophysiology analysis.
- Public surface area (intentionally small):
da.ephys.validate()
da.ephys.align(events, to, window)
da.ephys.bin(…)
da.ephys.smooth(…)
da.ephys.baseline(…)
da.ephys.normalize(…)
da.ephys.psth(…)
da.ephys.reduce(…)
da.ephys.restrict(…)
da.ephys.plot.<…>
- align(events: DataArray | Sequence[float] | ndarray, *, window: Tuple[float, float], to: str | None = None) DataArray¶
Align to an event and extract a time window.
- Parameters:
events – Events object describing event times.
to – Event label to align to. Optional for array-like event times.
window – (tmin, tmax) window around the event time.
- Returns:
Aligned DataArray.
- Return type:
xr.DataArray
- baseline(*, window: Tuple[float, float], dim: str = 'time', mode: str = 'subtract') DataArray¶
Apply baseline correction over a window.
Notes
Applies subtract/divide/zscore baselining over a time window.
- bin(dt: float, window: Tuple[float, float] | None = None, output: str = 'rate', time_unit: str = 's') DataArray¶
Bin ragged spikes into a dense (trial, unit, time) representation.
- Parameters:
dt – Bin width in seconds.
output – Output type (e.g. “rate” or “count”).
time_unit – Unit for time values.
- Returns:
Binned spikes.
- Return type:
xr.DataArray
Notes
Binning preserves compatible coordinates and updates ephys attrs.
- property guide: _Help¶
Return a short cheatsheet describing the accessor API.
- normalize(*, dim: str | Tuple[str, ...], method: str = 'zscore') DataArray¶
Normalize data across one or more dimensions.
Notes
Zero-variance slices are set to 0 to avoid NaNs.
- property plot: _PlotAccessor¶
Plot helper sub-accessor.
- psth(*, dim: str = 'trial', method: str = 'mean', group_by: str | Sequence[str] | None = None, keep_trials: bool = False) DataArray¶
Reduce across trials to compute a PSTH-style summary.
Notes
If keep_trials=True, includes the trial-wise data alongside summary.
- reduce(*args: Any, **kwargs: Any) DataArray¶
Reduce data dimensionality (e.g. PCA) in an xarray-friendly way.
Notes
Methods include PCA variants, dPCA, and supervised linear reductions.
- restrict(*, window: Tuple[float, float], dim: str = 'time') DataArray¶
Restrict to a time window for dense or ragged data.
- smooth(*, dim: str = 'time', method: str = 'boxcar', sigma: float | None = None, window: float | None = None, boundary: str = 'reflect') DataArray¶
Smooth a signal along a dimension.
Notes
Supports gaussian or boxcar smoothing over a single dimension.
- validate(*, kind: str | None = None) DataArray¶
Validate and return the underlying DataArray.
- Parameters:
kind – If provided, require that the DataArray matches the inferred kind.
- Returns:
The same object, returned for call chaining.
- Return type:
xr.DataArray