Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix dims and coords returned by compute_forward_vector #382

Merged
merged 5 commits into from
Jan 21, 2025

Conversation

willGraham01
Copy link
Contributor

Description

What is this PR

  • Bug fix
  • Addition of a new feature
  • Other

Why is this PR needed?

See #381

What does this PR do?

The function concerned, compute_forward_vector, has been changed to now explicitly construct the upwards_vector with appropriate labelling, and then the result has the extra spatial dimension dropped to ensure we always drop the correct axis.

The existing unit tests have been given a similar treatment.

  • The invalid inputs test has not been touched - this still passes since (functionally) nothing was wrong originally
  • The input/output test that was already present has largely stayed the same, save for the addition of additional checks that the coordinates we expect to be preserved, are indeed preserved. The existing numerical computations were valid, so have been left as part of the test.
  • The test involving nan values has been reworked to use the more precise sel and isnull method(s) to pull expected / unexpected NaN values out of the result, check that the appropriate time, space, and individuals axes are preserved, AND to force a comparison of the shape of the sub-array that contains NaN values against that which is expected. Previously this test did not actually check if the returned array was empty (which it was), so the np.isnan(...).all() and not np.isnan(...).any() were comparing to the empty container, this always returning True.

References

Closes #381

How has this PR been tested?

Local test suite passes, both prior to and with the additions mentioned above.

In the case of the old nan test, the old version of the test passed with the updates to the code (though this was to be expected due to the aforementioned empty-array bug), before being replaced.

Is this a breaking change?

No

Does this PR require an update to the documentation?

If any features have changed, or have been added. Please explain how the
documentation has been updated.

Checklist:

  • The code has been tested locally
  • Tests have been added to cover all new functionality
  • The documentation has been updated to reflect any changes
  • The code has been formatted with pre-commit

pre-commit-ci bot and others added 5 commits January 21, 2025 12:21
updates:
- [github.com/astral-sh/ruff-pre-commit: v0.8.1 → v0.8.6](astral-sh/ruff-pre-commit@v0.8.1...v0.8.6)
- [github.com/pre-commit/mirrors-mypy: v1.13.0 → v1.14.1](pre-commit/mirrors-mypy@v1.13.0...v1.14.1)

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
@willGraham01 willGraham01 requested a review from niksirbi January 21, 2025 14:14
Copy link

codecov bot commented Jan 21, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 99.79%. Comparing base (aac61b0) to head (044e11a).
Report is 2 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #382   +/-   ##
=======================================
  Coverage   99.79%   99.79%           
=======================================
  Files          14       14           
  Lines         969      969           
=======================================
  Hits          967      967           
  Misses          2        2           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Member

@niksirbi niksirbi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks a lot for the quick bug fix and the very thorough explanation @willGraham01!

Previously this test did not actually check if the returned array was empty (which it was), so the np.isnan(...).all() and not np.isnan(...).any() were comparing to the empty container, this always returning True.

Thanks for checking this, it makes sense now.

LGTM, barring an optional comment. Feel free to merge at your leisure.
I will make a patch release after this PR is merge.

@willGraham01 willGraham01 added this pull request to the merge queue Jan 21, 2025
Merged via the queue into main with commit 15b3f41 Jan 21, 2025
28 checks passed
@willGraham01 willGraham01 deleted the wgraham-381-forward-vector branch January 21, 2025 17:42
willGraham01 added a commit that referenced this pull request Jan 28, 2025
* Breakout vector valiadator with skeleton test

* Write validator tests, fix bug in missing .get method

* Fix dims and coords returned by `compute_forward_vector` (#382)

* Implement the expected fix

updates:
- [github.com/astral-sh/ruff-pre-commit: v0.8.1 → v0.8.6](astral-sh/ruff-pre-commit@v0.8.1...v0.8.6)
- [github.com/pre-commit/mirrors-mypy: v1.13.0 → v1.14.1](pre-commit/mirrors-mypy@v1.13.0...v1.14.1)

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>

* Revert "Implement the expected fix"

This reverts commit edbaa9c.

* Update method to explicitly construct and drop spatial z dimensions

* Force nan test to check for preserved coordinates

* Force explicit coordinate preservation checks in input/output test

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>

* Standardise compute_signed_angle_2d function as a purely mathematical impementation

* Patch up compute_forward_vector_angle

* Start on tests but encounter NaN bug that needs rebase fix

* Fix mapping of -pi to pi in signed_angle

* Write antisymmetry test

* Write invariance under transforms test

* Add tests for missing lines

* Apply batch suggestions from code review

Co-authored-by: Niko Sirmpilatze <[email protected]>

* Fix computer_forward_vector__angle docstring

* Remove unnecessary validation checks

* Use camera view variable name for codebase consistency

* Fix validator docstring backticks

* Move ref vector validator into array validators

* Fix typehints and test broken by removing earlier error check

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Niko Sirmpilatze <[email protected]>
github-merge-queue bot pushed a commit that referenced this pull request Jan 28, 2025
* Basic implementation of `compute_heading()` and `compute_relative_heading()`

* Minor fixes and docstring edits

* Remove `compute_relative_heading()` from this PR

* Created `signed_angle_between_2d_vectors()` vector util and refactored `compute_heading()`

* Cleaned up redundant code

* get rid of analysis folder

* add exact_coords boolean to the validator for dims and coords

* adapted reference vector validator

* renamed compute_heading to compute_heading_angle

* fixed docstring formatting errors

* renamed new vector util to compute_signed_angle_2d

* Add tests for heading angle (#385)

* Breakout vector valiadator with skeleton test

* Write validator tests, fix bug in missing .get method

* Fix dims and coords returned by `compute_forward_vector` (#382)

* Implement the expected fix

updates:
- [github.com/astral-sh/ruff-pre-commit: v0.8.1 → v0.8.6](astral-sh/ruff-pre-commit@v0.8.1...v0.8.6)
- [github.com/pre-commit/mirrors-mypy: v1.13.0 → v1.14.1](pre-commit/mirrors-mypy@v1.13.0...v1.14.1)

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>

* Revert "Implement the expected fix"

This reverts commit edbaa9c.

* Update method to explicitly construct and drop spatial z dimensions

* Force nan test to check for preserved coordinates

* Force explicit coordinate preservation checks in input/output test

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>

* Standardise compute_signed_angle_2d function as a purely mathematical impementation

* Patch up compute_forward_vector_angle

* Start on tests but encounter NaN bug that needs rebase fix

* Fix mapping of -pi to pi in signed_angle

* Write antisymmetry test

* Write invariance under transforms test

* Add tests for missing lines

* Apply batch suggestions from code review

Co-authored-by: Niko Sirmpilatze <[email protected]>

* Fix computer_forward_vector__angle docstring

* Remove unnecessary validation checks

* Use camera view variable name for codebase consistency

* Fix validator docstring backticks

* Move ref vector validator into array validators

* Fix typehints and test broken by removing earlier error check

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Niko Sirmpilatze <[email protected]>

---------

Co-authored-by: b-peri <[email protected]>
Co-authored-by: Will Graham <[email protected]>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
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.

compute_forward_vector returns empty DataArray with wrong dims and coords
2 participants