MovementDataset#
- class movement.move_accessor.MovementDataset(ds)[source]#
Bases:
object
An
xarray.Dataset
accessor formovement
data.A
movement
dataset is anxarray.Dataset
with a specific structure to represent pose tracks or bounding boxes data, associated confidence scores and relevant metadata.Methods/properties that extend the standard
xarray
functionality are defined in this class. To avoid conflicts withxarray
’s namespace,movement
-specific methods are accessed using themove
keyword, for exampleds.move.validate()
(see [1] for more details).- dim_names#
A dictionary with the names of the expected dimensions in the dataset, for each dataset type (
"poses"
or"bboxes"
).- Type:
dict
- var_names#
A dictionary with the expected data variables in the dataset, for each dataset type (
"poses"
or"bboxes"
).- Type:
dict
References
Methods
filtering_wrapper
(fn_name, *args[, data_vars])Provide convenience method for filtering data variables.
kinematics_wrapper
(fn_name, *args, **kwargs)Provide convenience method for computing kinematic properties.
validate
()Validate the dataset.
- filtering_wrapper(fn_name, *args, data_vars=None, **kwargs)[source]#
Provide convenience method for filtering data variables.
This method forwards filtering and/or smoothing to the respective functions in
movement.filtering
. The data variables to filter can be specified indata_vars
. Ifdata_vars
is not specified, theposition
data variable is selected by default.- Parameters:
fn_name (str) – The name of the filtering function to call.
args (tuple) – Positional arguments to pass to the function.
data_vars (list[str] | None) – The data variables to apply filtering. If
None
, theposition
data variable will be passed by default.kwargs (dict) – Keyword arguments to pass to the function.
- Returns:
The filtered data variable or a dictionary of filtered data variables, if multiple data variables are specified.
- Return type:
xarray.DataArray | dict[str, xarray.DataArray]
- Raises:
RuntimeError – If the requested function fails to execute.
Examples
Filter the
position
data variable to drop points withconfidence
below 0.7 and store the result back into the Datasetds
. Sincedata_vars
is not supplied, the filter will be applied to theposition
data variable by default.>>> ds["position"] = ds.move.filter_by_confidence(threshold=0.7)
Apply a median filter to the
position
data variable and store this back into the Datasetds
.>>> ds["position"] = ds.move.median_filter(window=3)
Apply a Savitzky-Golay filter to both the
position
andvelocity
data variables and store these back into the Datasetds
.filtered_data
is a dictionary, where the keys are the data variable names and the values are the filtered DataArrays.>>> filtered_data = ds.move.savgol_filter( ... window=3, data_vars=["position", "velocity"] ... ) >>> ds.update(filtered_data)
- kinematics_wrapper(fn_name, *args, **kwargs)[source]#
Provide convenience method for computing kinematic properties.
This method forwards kinematic property computation to the respective functions in
movement.analysis.kinematics
.- Parameters:
fn_name (str) – The name of the kinematics function to call.
args (tuple) – Positional arguments to pass to the function.
kwargs (dict) – Keyword arguments to pass to the function.
- Returns:
The computed kinematics attribute value.
- Return type:
- Raises:
RuntimeError – If the requested function fails to execute.
Examples
Compute
displacement
based on theposition
data variable in the Datasetds
and store the result inds
.>>> ds["displacement"] = ds.move.compute_displacement()
Compute
velocity
based on theposition
data variable in the Datasetds
and store the result inds
.>>> ds["velocity"] = ds.move.compute_velocity()
Compute
acceleration
based on theposition
data variable in the Datasetds
and store the result inds
.>>> ds["acceleration"] = ds.move.compute_acceleration()
- validate()[source]#
Validate the dataset.
This method checks if the dataset contains the expected dimensions, data variables, and metadata attributes. It also ensures that the dataset contains valid poses or bounding boxes data.
- Raises:
ValueError – If the dataset is missing required dimensions, data variables, or contains invalid poses or bounding boxes data.
- Return type:
None