Skip to content

Fix Hi L2 flux correction convergence logic#3143

Merged
tmplummer merged 4 commits intoIMAP-Science-Operations-Center:devfrom
tmplummer:3142-bug---hi-l2---flux-correction-convervence-with-zero-flux
May 7, 2026
Merged

Fix Hi L2 flux correction convergence logic#3143
tmplummer merged 4 commits intoIMAP-Science-Operations-Center:devfrom
tmplummer:3142-bug---hi-l2---flux-correction-convervence-with-zero-flux

Conversation

@tmplummer
Copy link
Copy Markdown
Contributor

@tmplummer tmplummer commented May 5, 2026

Change Summary

Fixes a bug in how convergence criteria was being calculated. The bug occurred when an input flux is zero causing the computed chi_n for that pixel to be NaN which will never be less than the convergence criteria. The easy fix is to just use a nanmean when computing the mean ratio. This is appropriate because zero fluxes will just stay zeros and thus are already converged.

Testing

I first added the test confirming that when a zero is in the input flux, the max iterations is hit. Once the bug was fixed, the test passes.

Closes: #3142

Copy link
Copy Markdown
Contributor

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 updates the Hi ENA flux-correction convergence logic so zero-valued flux bins do not poison the per-pixel convergence metric with NaNs. It also adds a regression test in the ENA maps test suite for a zero-flux scenario.

Changes:

  • Replaced np.mean with np.nanmean in predictor_corrector_iteration() when computing the convergence ratio.
  • Added a Hi-specific regression test intended to verify convergence when one ESA flux is set to zero.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
imap_processing/ena_maps/utils/corrections.py Adjusts the predictor-corrector convergence calculation to ignore NaN ratio entries.
imap_processing/tests/ena_maps/test_corrections.py Adds a regression test for zero-flux convergence behavior in the Hi correction path.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread imap_processing/ena_maps/utils/corrections.py Outdated
Copy link
Copy Markdown
Member

@bryan-harter bryan-harter left a comment

Choose a reason for hiding this comment

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

Seems good to me!

@tmplummer tmplummer merged commit 230f4c0 into IMAP-Science-Operations-Center:dev May 7, 2026
14 checks passed
@tmplummer tmplummer deleted the 3142-bug---hi-l2---flux-correction-convervence-with-zero-flux branch May 7, 2026 14:52
@github-project-automation github-project-automation Bot moved this to Done in IMAP May 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

BUG - Hi L2 - flux correction convervence with zero flux

3 participants