Skip to content

Improve xarray compatibility in vector utilities (compute_signed_angle_2d and cart2pol) [fixes #901]#902

Open
swagat-mishra28 wants to merge 1 commit into
neuroinformatics-unit:mainfrom
swagat-mishra28:fix-xarray-vector-compat
Open

Improve xarray compatibility in vector utilities (compute_signed_angle_2d and cart2pol) [fixes #901]#902
swagat-mishra28 wants to merge 1 commit into
neuroinformatics-unit:mainfrom
swagat-mishra28:fix-xarray-vector-compat

Conversation

@swagat-mishra28

Copy link
Copy Markdown

Closes #901

Summary

While reviewing movement/utils/vector.py, I noticed a few places where NumPy operations were applied directly to xarray DataArray objects or where .values was accessed. These patterns can bypass xarray’s abstraction layer and may cause issues with lazy backends (e.g., dask) or metadata handling.

This PR improves compatibility with xarray best practices.

Changes

  • Replace np.arctan2(cross, dot) with xr.apply_ufunc(np.arctan2, cross, dot) in compute_signed_angle_2d
  • Replace in-place mutation of .values with xr.where
  • Avoid direct .values access in cart2pol

Rationale

Using xarray-aware operations preserves metadata and ensures compatibility with lazy computation frameworks such as dask.

Testing

All existing tests pass locally:

pytest --ignore=tests/test_unit/test_napari_plugin

Result:
1011 passed, 4 deselected, 2 xfailed

No functional behavior of the library was changed; the modifications only improve implementation safety and compatibility with xarray.

@sonarqubecloud

Copy link
Copy Markdown

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Improve xarray compatibility in vector utilities (compute_signed_angle_2d and cart2pol)

1 participant