neuroinformatics-unit / movement

Python tools for analysing body movements across space and time
http://movement.neuroinformatics.dev
BSD 3-Clause "New" or "Revised" License
96 stars 8 forks source link

Simplify and expand kinematic tests for bboxes #265

Closed sfmig closed 3 weeks ago

sfmig commented 1 month ago

Description

What is this PR

Why is this PR needed? To ensure our existing kinematics methods play nicely with bboxes datasets.

What does this PR do?

Question

I am not sure if it existed or we were aware of it when we implemented these methods. If we decide to use it, we may need to change the tests, so that we continue to compute the expected kinematic variables with an 'independent' method.

The simplest way would be to check the kinematic variables for a very simple motion case, for which the velocity, acceleration and displacement are very easy to infer / derive by hand. In a way this is similar to the tests we currently have, except that we can more easily infer which values are expected. I added an example test like that called test_kinematics_uniform_linear_motion for reference, but right now it takes only the valid bboxes dataset.

References

Overflow from #246

How has this PR been tested?

Tests pass locally and in CI.

Is this a breaking change?

No.

Does this PR require an update to the documentation?

I updated the docstrings for the kinematics module so that the API reference is no longer specific to poses datasets.

Checklist:

codecov[bot] commented 1 month ago

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

Project coverage is 99.77%. Comparing base (a98ff45) to head (fad3257). Report is 1 commits behind head on main.

Additional details and impacted files ```diff @@ Coverage Diff @@ ## main #265 +/- ## ======================================= Coverage 99.77% 99.77% ======================================= Files 14 14 Lines 883 883 ======================================= Hits 881 881 Misses 2 2 ```

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

lochhh commented 1 month ago

Cool! I wasn't aware of xr.differentiate(), which is much simpler in code for our use case:

result = data.differentiate("time")

vs.

result = xr.apply_ufunc(
               np.gradient,
               data,
               data.coords["time"].values,
               kwargs={"axis": 0},
         )
result = result.reindex_like(data)

And in both cases, we no longer need to assume equidistant time-spacing. (Opened #268 for this)

sfmig commented 1 month ago

thanks for the review @lochhh. A summary of the main changes below.

In the tests:

In the docstrings of the kinematics functions:

Will re request review now

sonarcloud[bot] commented 3 weeks ago

Quality Gate Passed Quality Gate passed

Issues
0 New issues
0 Accepted issues

Measures
0 Security Hotspots
0.0% Coverage on New Code
0.0% Duplication on New Code

See analysis details on SonarCloud