bugfix: _energy_ratio bug fix (shape errors)#133
Conversation
There was a problem hiding this comment.
Pull request overview
This PR fixes two bugs in the _energy_ratio function that caused shape mismatches and incorrect results when computing energy ratios from EDCs with different channel shapes or when using np.inf limits.
Changes:
- Fixed incorrect shape initialization for
energy_decay_curve2_valuesto useenergy_decay_curve2.cshapeinstead ofenergy_decay_curve1.cshape - Added
np.atleast_1d()wrapper aroundfind_nearest_time()results to ensure consistent array indexing - Added regression test and refactored test parametrization data into shared constant
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| pyrato/parameters.py | Fixed shape initialization bug (line 330) and wrapped find_nearest_time() calls with np.atleast_1d() (lines 320-324, 332-336) to handle scalar returns correctly |
| tests/test_parameters.py | Added _MULTICHANNEL_ENERGY_SHAPES constant for shared test data, refactored existing test to use it, and added new regression test test_energy_ratio_inf_limit_multichannel_shape |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
f-brinkmann
left a comment
There was a problem hiding this comment.
I noted that a few ruff errors are caused by this. Can you please fix them. The remaining errors are fixed by #134
ruff tests have been completed! |
mberz
left a comment
There was a problem hiding this comment.
Seems like the git history is erroneous. Please fix this before we proceed.
- update input variable names - extend docstring - update tests
- formatting and linting fixes
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
81ae369 to
18deff7
Compare
Which issue(s) are closed by this pull request?
Closes #132
Changes proposed in this pull request:
Fix shape mismatch and scalar index bug in
_energy_ratiocomputation, used by #109 and #114Problem
Two bugs in the EDC-based energy ratio calculation caused incorrect results or shape errors:
energy_decay_curve2_valueswas initialized withenergy_decay_curve1.cshape + (2,)instead of
energy_decay_curve2.cshape + (2,). When the two EDCs have different channelshapes, this produced an incorrectly sized array, leading to wrong assignments or a shape
mismatch error.
The return value of
find_nearest_time()was used directly as an index without wrappingit in
np.atleast_1d(). When only a single infinite limit was present,find_nearest_time()returned a scalar, and the subsequent advanced indexing with
[..., idx]collapsed adimension unexpectedly, silently producing incorrect values in both
energy_decay_curve1_valuesandenergy_decay_curve2_values.Fix
energy_decay_curve2_valuesto useenergy_decay_curve2.cshape.find_nearest_time()results innp.atleast_1d()for both the denominator andnumerator index lookups to ensure consistent array indexing regardless of how many infinite
limits are present.