Skip to content

Comments

bugfix: _energy_ratio bug fix (shape errors)#133

Closed
artur-pa wants to merge 22 commits intodevelopfrom
feature/_energy_ratio_bug_fix
Closed

bugfix: _energy_ratio bug fix (shape errors)#133
artur-pa wants to merge 22 commits intodevelopfrom
feature/_energy_ratio_bug_fix

Conversation

@artur-pa
Copy link

@artur-pa artur-pa commented Feb 18, 2026

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_ratio computation, used by #109 and #114

Problem
Two bugs in the EDC-based energy ratio calculation caused incorrect results or shape errors:

  1. energy_decay_curve2_values was initialized with energy_decay_curve1.cshape + (2,)
    instead of energy_decay_curve2.cshape + (2,). When the two EDCs have different channel
    shapes, this produced an incorrectly sized array, leading to wrong assignments or a shape
    mismatch error.

  2. The return value of find_nearest_time() was used directly as an index without wrapping
    it 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 a
    dimension unexpectedly, silently producing incorrect values in both
    energy_decay_curve1_values and energy_decay_curve2_values.

Fix

  • Corrected the shape initialization of energy_decay_curve2_values to use
    energy_decay_curve2.cshape.
  • Wrapped find_nearest_time() results in np.atleast_1d() for both the denominator and
    numerator index lookups to ensure consistent array indexing regardless of how many infinite
    limits are present.
  • Add test

@artur-pa artur-pa self-assigned this Feb 18, 2026
Copilot AI review requested due to automatic review settings February 18, 2026 16:56
@artur-pa artur-pa added the bug Something isn't working label Feb 18, 2026
@artur-pa artur-pa changed the title bugfix/ energy ratio bug fix (shape errors) bugfix: _energy_ratio bug fix (shape errors) Feb 18, 2026
@artur-pa artur-pa added this to the v1.0.0 milestone Feb 18, 2026
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

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_values to use energy_decay_curve2.cshape instead of energy_decay_curve1.cshape
  • Added np.atleast_1d() wrapper around find_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.

@artur-pa artur-pa moved this from Backlog to Require review in Weekly Planning Feb 18, 2026
Copy link
Member

@f-brinkmann f-brinkmann left a comment

Choose a reason for hiding this comment

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

I noted that a few ruff errors are caused by this. Can you please fix them. The remaining errors are fixed by #134

@artur-pa
Copy link
Author

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!

Copy link
Member

@mberz mberz left a comment

Choose a reason for hiding this comment

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

Seems like the git history is erroneous. Please fix this before we proceed.

@mberz mberz moved this from Require review to Implementation in progress in Weekly Planning Feb 20, 2026
@artur-pa artur-pa force-pushed the feature/_energy_ratio_bug_fix branch from 81ae369 to 18deff7 Compare February 20, 2026 10:56
@artur-pa artur-pa closed this Feb 20, 2026
@artur-pa artur-pa deleted the feature/_energy_ratio_bug_fix branch February 20, 2026 11:04
@github-project-automation github-project-automation bot moved this from Implementation in progress to Done in Weekly Planning Feb 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

3 participants