Skip to content

Allow energy as input to plotters#128

Merged
henrikjacobsenfys merged 5 commits into
developfrom
handle-nans-in-data-for-fitter
Mar 13, 2026
Merged

Allow energy as input to plotters#128
henrikjacobsenfys merged 5 commits into
developfrom
handle-nans-in-data-for-fitter

Conversation

@henrikjacobsenfys

@henrikjacobsenfys henrikjacobsenfys commented Mar 12, 2026

Copy link
Copy Markdown
Member

Ensures that the correct energies are used when calculating the model for plotting. Also allows users to input a finer energy grid to make the plot prettier.

Closes #119

@henrikjacobsenfys henrikjacobsenfys added [scope] enhancement Adds/improves features (major.MINOR.patch) [priority] high Should be prioritized soon labels Mar 12, 2026
@codecov

codecov Bot commented Mar 12, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 95.91837% with 4 lines in your changes missing coverage. Please review.
⚠️ Please upload report for BASE (develop@e28e3c0). Learn more about missing BASE report.

Files with missing lines Patch % Lines
src/easydynamics/analysis/analysis.py 81.25% 0 Missing and 3 partials ⚠️
src/easydynamics/analysis/analysis1d.py 98.21% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             develop     #128   +/-   ##
==========================================
  Coverage           ?   97.65%           
==========================================
  Files              ?       36           
  Lines              ?     2385           
  Branches           ?      403           
==========================================
  Hits               ?     2329           
  Misses             ?       32           
  Partials           ?       24           
Flag Coverage Δ
integration 0.00% <0.00%> (?)
unittests 97.65% <95.91%> (?)

Flags with carried forward coverage won't be shown. Click here to find out more.

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

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@rozyczko

Copy link
Copy Markdown
Member

the title of the PR and the name of the branch seem pretty far off
Are you sure you are merging the correct thing? :)

@henrikjacobsenfys

Copy link
Copy Markdown
Member Author

the title of the PR and the name of the branch seem pretty far off Are you sure you are merging the correct thing? :)

Yes, this is the "fixing a bug (NaNs in data give errors because the energy axis is inconsistent since it changes depending on where the NaNs are) by making an enhancement (give users control over the energy axis for plotting, and make the defaults sensible so they work both for fitting and plotting with default args)" that I mentioned :)
'
I set out to just fix the bug (hence the branch name) and found this to be the best/easiest solution

@rozyczko rozyczko left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

minor issues only, otherwise looks solid.

Comment thread src/easydynamics/analysis/analysis1d.py Outdated
Comment on lines 493 to 494
def _evaluate_sample(self, energy: sc.DataArray | None = None) -> np.ndarray:
"""Evaluate the sample contribution for a given Q index.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Hasn't energy been typed as sc.Variable? (Also in the following docstring)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I blame copilot!

Comment thread src/easydynamics/analysis/analysis1d.py Outdated
Comment on lines 539 to 540
def _evaluate_background(self, energy: sc.DataArray | None = None) -> np.ndarray:
"""Evaluate the background contribution for the chosen Q index.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Hasn't energy been typed as sc.Variable? (Also in the following docstring)

Comment on lines +160 to 161
self._convolver = self._create_convolver(energy=energy)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The convolver is now recreated on every call to calculate(), even when energy is None (most common case?). Previously it was cached and only updated on Q-index changes. Looks like performance regression?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I think it's ok here, fit uses _calculate

masked_energy = experiment_with_data.get_masked_energy(Q_index=Q_index)

# EXPECT
len(masked_energy) == 1

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think you meant assert len(masked_energy) == 1?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I blame.. ummm... myself?

Comment on lines +189 to +196
def get_masked_energy(self, Q_index: int) -> sc.Variable | None:
"""Get the energy values from the dataset, applying the mask if
present.

Returns:
sc.Variable | None: The masked energy values from the
dataset, or None if no data is loaded.
"""

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

no description of args: Q_index

@henrikjacobsenfys henrikjacobsenfys merged commit 9c43f48 into develop Mar 13, 2026
34 checks passed
@henrikjacobsenfys henrikjacobsenfys deleted the handle-nans-in-data-for-fitter branch March 25, 2026 09:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[priority] high Should be prioritized soon [scope] enhancement Adds/improves features (major.MINOR.patch)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants