cedalion.dataclasses.accessors
Accessors for Cedalion data types.
Classes
|
Accessor for time series data stored in xarray DataArrays. |
|
Accessor for |
|
Wraps a callable attribute of a statsmodels result object. |
|
Accessor for DataArrays containing statsmodel results. |
|
Accessor for stimulus DataFrames. |
- class cedalion.dataclasses.accessors.CedalionAccessor(xarray_obj)[source]
Bases:
objectAccessor for time series data stored in xarray DataArrays.
- property sampling_rate[source]
Return the sampling rate of the time series.
- The sampling rate is calculated as the reciprocal of the mean time difference
between consecutive samples.
- to_epochs(
- df_stim: pd.DataFrame,
- trial_types: list[str],
- before: cdt.QTime,
- after: cdt.QTime,
Extract epochs from the time series based on stimulus events.
- Parameters:
df_stim – DataFrame containing stimulus events.
trial_types – List of trial types to include in the epochs.
before – Time before stimulus event to include in epoch.
after – Time after stimulus event to include in epoch.
- Returns:
Array containing the extracted epochs.
- Return type:
xarray.DataArray
- freq_filter(fmin, fmax, butter_order=4)[source]
Apply a Butterworth bandpass filter.
- Parameters:
fmin (float) – The lower cutoff frequency.
fmax (float) – The upper cutoff frequency.
butter_order (int) – The order of the Butterworth filter.
- Returns:
The filtered time series.
- Return type:
result (xarray.DataArray)
- class cedalion.dataclasses.accessors.PointsAccessor(xarray_obj)[source]
Bases:
objectAccessor for
LabeledPointsDataArrays.Attached as the
.pointsattribute on any DataArray that carries a"label"dimension and coordinate (i.e. a labeled point cloud such asgeo3dorgeo2d).- to_homogeneous()[source]
Return the point cloud augmented with a homogeneous coordinate of 1.
Appends a column of ones so that affine transforms can be applied with a single matrix multiplication. Units are preserved.
- Returns:
LabeledPoints DataArray with shape
(n_points, n_coords + 1).
- rename(translations: Dict[str, str])[source]
Rename point labels according to a translation dictionary.
- Parameters:
translations – Mapping from old label strings to new label strings. Labels not present in the mapping are kept unchanged.
- Returns:
LabeledPoints DataArray with updated
"label"coordinate.
- common_labels(
- other: DataArray,
Return labels present in both this and other LabeledPoints arrays.
- Parameters:
other – Second LabeledPoints DataArray. Must have a
"label"dimension and coordinate.- Returns:
Sorted list of label strings shared by both point clouds.
- apply_transform(transform: cdt.AffineTransform | np.ndarray)[source]
Apply an affine transform to this point cloud.
Accepts either a cedalion
AffineTransform(a 4×4xr.DataArraywith CRS-named dimensions and pint units) or a plain 4×4numpy.ndarray.- Parameters:
transform – 4×4 affine transformation. If an
xr.DataArray, the source CRS must match the current CRS of the point cloud.- Returns:
Transformed LabeledPoints DataArray in the new coordinate system.
- Raises:
CRSMismatchError – If a DataArray transform’s source CRS does not match the current point cloud CRS.
ValueError – If transform is not a DataArray or ndarray.
- property crs[source]
Name of the coordinate reference system dimension (the non-label dim).
- Returns:
String name of the spatial dimension, e.g.
"pos","ras".
- set_crs(value: str)[source]
Return a copy of this point cloud with the CRS dimension renamed.
- Parameters:
value – New name for the spatial dimension.
- Returns:
LabeledPoints DataArray with the CRS dimension renamed to value.
- add(
- label: str | List[str],
- coordinates: ArrayLike,
- type: PointType | List[PointType],
- group: str | List[str] = None,
Append one or more points to this point cloud.
- Parameters:
label – Label string (single point) or list of label strings.
coordinates – Coordinates of the new point(s). Shape
(3,)for a single point or(n, 3)for multiple points.type –
PointType(single point) or list thereof for multiple points.group – Optional group string or list of group strings.
- Returns:
New LabeledPoints DataArray with the added point(s) concatenated.
- Raises:
KeyError – If a label already exists in the point cloud.
- class cedalion.dataclasses.accessors.StimAccessor(pandas_obj)[source]
Bases:
objectAccessor for stimulus DataFrames.
- rename_events(rename_dict)[source]
Renames trial types in the DataFrame based on the provided dictionary.
- Parameters:
rename_dict (dict) – A dictionary with the old trial type as key and the new trial type as value.
- class cedalion.dataclasses.accessors.SMCallableWrapper(accessor, attr_name)[source]
Bases:
objectWraps a callable attribute of a statsmodels result object.
When
StatsModelsAccessorresolves a callable attribute (e.g.summary()), it returns one of these wrappers. Calling the wrapper applies the method to every element in the 2-D array of result objects and collects the outputs into anxr.DataArray.
- class cedalion.dataclasses.accessors.StatsModelsAccessor(array: DataArray)[source]
Bases:
objectAccessor for DataArrays containing statsmodel results.
- map(func: Callable, name: str = 'map')[source]
Applies a callable to each object in the array and returns a xr.DataArray.
- Parameters:
func – a Callable that expects one argument, the object
name – used to name dimensions in the result array
- Returns:
an xr.DataArray whose first to dimensions match our array and that holds in each cell the result of the function call.
- regressor_variances()[source]
Return the variance of each regressor coefficient across all models.
Extracts the diagonal of the covariance matrix of parameter estimates for each model in the array.
- Returns:
DataArray with the same first two dims as the results array plus a
"regressor"dimension.- Raises:
NotImplementedError – If the underlying result objects are
ContrastResults(which carry no parameter estimates).