aind_ephys_utils.ops.psth module

Peristimulus time histogram operations.

aind_ephys_utils.ops.psth.psth(data: DataArray | ndarray | Sequence[object] | Sequence[Sequence[object]], *, dim: str = 'trial', method: str = 'mean', group_by: str | Sequence[str] | None = None, keep_trials: bool = False, dims: Sequence[str] | None = None, coords: Dict[str, object] | None = None, return_type: str = 'auto') DataArray | object

Reduce across trials to compute a PSTH-style summary.

Parameters:
  • data – Input DataArray or NumPy-like data (binned or continuous).

  • dim – Dimension to reduce across.

  • method – Reduction method (e.g. “mean”, “median”).

  • group_by – Optional coord name(s) to group along dim before reducing.

  • keep_trials – If True, keep per-trial data along with the summary.

  • dims – Optional dimension names used when data is a dense NumPy array.

  • coords – Optional coordinate mapping used when constructing a DataArray from dense NumPy input.

  • return_type – Output type policy: "auto", "xarray", or "numpy". "auto" mirrors the input style.

Returns:

PSTH summary (or summary plus trials when keep_trials=True) in the selected output representation.

Return type:

xr.DataArray or object