Skip to content

Commit

Permalink
constrain kinematic functions to cartesian coordinates
Browse files Browse the repository at this point in the history
  • Loading branch information
niksirbi committed Aug 29, 2024
1 parent d33ac25 commit 14d9fc5
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions movement/analysis/kinematics.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,16 @@ 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
-------
xarray.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
Expand All @@ -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
-------
Expand All @@ -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
-------
Expand All @@ -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.
Expand All @@ -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")
Expand Down

0 comments on commit 14d9fc5

Please sign in to comment.