aind_ephys_utils.ops.bin module

Binning operations for ragged spikes.

aind_ephys_utils.ops.bin.bin(data: DataArray | ndarray | Sequence[object] | Sequence[Sequence[object]], dt: float, window: Tuple[float, float] | None = None, output: str = 'rate', time_unit: str = 's', dims: Sequence[str] | None = None, coords: Dict[str, object] | None = None, return_type: str = 'auto') DataArray | object

Bin ragged spikes into a dense representation.

Parameters:
  • data – Ragged spike DataArray/list or object NumPy array.

  • dt – Bin width in seconds.

  • window – Optional (tmin, tmax) window to bin.

  • output – Output type, typically “rate” or “count”.

  • time_unit – Unit for time values, recorded in attrs.

  • dims – Optional dimension names used when data is a dense NumPy array. This is ignored for ragged list inputs.

  • 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 (xarray in/xarray out, list/NumPy ragged in/list or NumPy out).

Returns:

Binned dense output. For return_type="numpy", returns a NumPy array with the same dense shape as the xarray result values.

Return type:

xr.DataArray or object