Skip to content

Commit

Permalink
renamed new validator to validate_dims_coords
Browse files Browse the repository at this point in the history
  • Loading branch information
niksirbi committed Sep 6, 2024
1 parent 1b078a1 commit 68a587c
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 11 deletions.
6 changes: 3 additions & 3 deletions movement/analysis/kinematics.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import xarray as xr

from movement.utils.logging import log_error
from movement.validators.arrays import validate_dimension_coordinates
from movement.validators.arrays import validate_dims_coords


def compute_displacement(data: xr.DataArray) -> xr.DataArray:
Expand Down Expand Up @@ -43,7 +43,7 @@ def compute_displacement(data: xr.DataArray) -> xr.DataArray:
height per bounding box, between consecutive time points.
"""
validate_dimension_coordinates(data, {"time": [], "space": ["x", "y"]})
validate_dims_coords(data, {"time": [], "space": ["x", "y"]})
result = data.diff(dim="time")
result = result.reindex(data.coords, fill_value=0)
return result
Expand Down Expand Up @@ -154,7 +154,7 @@ def _compute_approximate_time_derivative(
)
if order <= 0:
raise log_error(ValueError, "Order must be a positive integer.")
validate_dimension_coordinates(data, {"time": [], "space": ["x", "y"]})
validate_dims_coords(data, {"time": [], "space": ["x", "y"]})
result = data
for _ in range(order):
result = result.differentiate("time")
Expand Down
14 changes: 7 additions & 7 deletions movement/utils/vector.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import xarray as xr

from movement.utils.logging import log_error
from movement.validators.arrays import validate_dimension_coordinates
from movement.validators.arrays import validate_dims_coords


def compute_norm(data: xr.DataArray) -> xr.DataArray:
Expand Down Expand Up @@ -40,15 +40,15 @@ def compute_norm(data: xr.DataArray) -> xr.DataArray:
"""
if "space" in data.dims:
validate_dimension_coordinates(data, {"space": ["x", "y"]})
validate_dims_coords(data, {"space": ["x", "y"]})
return xr.apply_ufunc(
np.linalg.norm,
data,
input_core_dims=[["space"]],
kwargs={"axis": -1},
)
elif "space_pol" in data.dims:
validate_dimension_coordinates(data, {"space_pol": ["rho", "phi"]})
validate_dims_coords(data, {"space_pol": ["rho", "phi"]})
return data.sel(space_pol="rho", drop=True)
else:
_raise_error_for_missing_spatial_dim()
Expand Down Expand Up @@ -79,10 +79,10 @@ def convert_to_unit(data: xr.DataArray) -> xr.DataArray:
"""
if "space" in data.dims:
validate_dimension_coordinates(data, {"space": ["x", "y"]})
validate_dims_coords(data, {"space": ["x", "y"]})
return data / compute_norm(data)
elif "space_pol" in data.dims:
validate_dimension_coordinates(data, {"space_pol": ["rho", "phi"]})
validate_dims_coords(data, {"space_pol": ["rho", "phi"]})
# Set both rho and phi values to NaN at null vectors (where rho = 0)
new_data = xr.where(data.sel(space_pol="rho") == 0, np.nan, data)
# Set the rho values to 1 for non-null vectors (phi is preserved)
Expand Down Expand Up @@ -112,7 +112,7 @@ def cart2pol(data: xr.DataArray) -> xr.DataArray:
``phi`` returned are in radians, in the range ``[-pi, pi]``.
"""
validate_dimension_coordinates(data, {"space": ["x", "y"]})
validate_dims_coords(data, {"space": ["x", "y"]})
rho = compute_norm(data)
phi = xr.apply_ufunc(
np.arctan2,
Expand Down Expand Up @@ -148,7 +148,7 @@ def pol2cart(data: xr.DataArray) -> xr.DataArray:
in the dimension coordinate.
"""
validate_dimension_coordinates(data, {"space_pol": ["rho", "phi"]})
validate_dims_coords(data, {"space_pol": ["rho", "phi"]})
rho = data.sel(space_pol="rho")
phi = data.sel(space_pol="phi")
x = rho * np.cos(phi)
Expand Down
2 changes: 1 addition & 1 deletion movement/validators/arrays.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from movement.utils.logging import log_error


def validate_dimension_coordinates(
def validate_dims_coords(
data: xr.DataArray, required_dim_coords: dict
) -> None:
"""Validate dimensions and coordinates in a data array.
Expand Down

0 comments on commit 68a587c

Please sign in to comment.