From 14d9fc5d976bd2a59cd37f7f9a2ff0d0911a38fd Mon Sep 17 00:00:00 2001 From: niksirbi Date: Thu, 29 Aug 2024 11:59:20 +0100 Subject: [PATCH] constrain kinematic functions to cartesian coordinates --- movement/analysis/kinematics.py | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/movement/analysis/kinematics.py b/movement/analysis/kinematics.py index c9538787..3479de02 100644 --- a/movement/analysis/kinematics.py +++ b/movement/analysis/kinematics.py @@ -18,8 +18,8 @@ def compute_displacement(data: xr.DataArray) -> xr.DataArray: Parameters ---------- data : xarray.DataArray - The input data containing position information, with - ``time`` as a dimension. + The input data containing position information, with ``time`` + and ``space`` (in Cartesian coordinates) as required dimensions. Returns ------- @@ -27,7 +27,7 @@ def compute_displacement(data: xr.DataArray) -> xr.DataArray: An xarray DataArray containing the computed displacement. """ - validate_dimension_coordinates(data, {"time": []}) + validate_dimension_coordinates(data, {"time": [], "space": ["x", "y"]}) result = data.diff(dim="time") result = result.reindex(data.coords, fill_value=0) return result @@ -43,8 +43,8 @@ def compute_velocity(data: xr.DataArray) -> xr.DataArray: Parameters ---------- data : xarray.DataArray - The input data containing position information, with - ``time`` as a dimension. + The input data containing position information, with ``time`` + and ``space`` (in Cartesian coordinates) as required dimensions. Returns ------- @@ -69,8 +69,8 @@ def compute_acceleration(data: xr.DataArray) -> xr.DataArray: Parameters ---------- data : xarray.DataArray - The input data containing position information, with - ``time`` as a dimension. + The input data containing position information, with ``time`` + and ``space`` (in Cartesian coordinates) as required dimensions. Returns ------- @@ -97,7 +97,8 @@ def _compute_approximate_time_derivative( Parameters ---------- data : xarray.DataArray - The input data containing ``time`` as a dimension. + The input data containing ``time`` and ``space`` (in Cartesian + coordinates) as require dimensions. order : int The order of the derivative. 1 for velocity, 2 for acceleration. Value must be a positive integer. @@ -114,7 +115,7 @@ def _compute_approximate_time_derivative( ) if order <= 0: raise log_error(ValueError, "Order must be a positive integer.") - validate_dimension_coordinates(data, {"time": []}) + validate_dimension_coordinates(data, {"time": [], "space": ["x", "y"]}) result = data for _ in range(order): result = result.differentiate("time")