Skip to content

SWAPI: Flag alpha fits with out-of-range proton-to-alpha peak ratios - #168

Open
leowerneck wants to merge 7 commits into
IMAP-Science-Operations-Center:mainfrom
leowerneck:lw/146-bug---unflagged-alpha-peak-confusion
Open

SWAPI: Flag alpha fits with out-of-range proton-to-alpha peak ratios#168
leowerneck wants to merge 7 commits into
IMAP-Science-Operations-Center:mainfrom
leowerneck:lw/146-bug---unflagged-alpha-peak-confusion

Conversation

@leowerneck

@leowerneck leowerneck commented Aug 21, 2026

Copy link
Copy Markdown
Collaborator

Change Summary

Closes #146.

Overview

Flag alpha solar-wind fits as BAD_FIT when the approximate fitted alpha-to-proton peak energy ratio is below 1.7. Calculate the ratio analytically from the fitted bulk velocity magnitudes, without evaluating additional model-rate curves.

File changes

  • fit_solar_wind_alpha_model.py: Calculate the approximate peak-energy ratio as $2|v_\alpha|^2/|v_p|^2$ and flag ratios below 1.7 as BAD_FIT.
  • test_fit_solar_wind_alpha_model.py: Verify that ratios below 1.7 are rejected.
  • alpha-sw.md: Document the explicit 1.7 lower threshold.

Testing

The focused alpha-fit unit test suite passes:

uv run python -m unittest \
    tests.swapi.l3a.science.solar_wind.alpha.test_fit_solar_wind_alpha_model

results in:

..............................
----------------------------------------------------------------------
Ran 30 tests

OK

@leowerneck
leowerneck requested a balanced review from Copilot August 21, 2026 20:10
@leowerneck leowerneck self-assigned this Aug 21, 2026
@leowerneck leowerneck added bug Something isn't working Data Release 2 Deadline: September 1, 2026 labels Aug 21, 2026

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Adds a peak-energy ratio guard to reject implausible SWAPI alpha fits as BAD_FIT.

Changes:

  • Computes modeled proton/alpha peaks across the coarse ESA grid.
  • Rejects ratios outside 1.7–2.3.
  • Adds regression coverage and documentation.

Reviewed changes

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

File Description
fit_solar_wind_alpha_model.py Implements peak-ratio validation.
test_fit_solar_wind_alpha_model.py Tests upper-bound rejection.
alpha-sw.md Documents the quality check.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread tests/swapi/l3a/science/solar_wind/alpha/test_fit_solar_wind_alpha_model.py Outdated

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated no new comments.

@hafarooki hafarooki left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

It is not necessary to calculate the model rates for this. Simply calculate the approximate location of the peak based on the magnitude of the bulk velocity vsctor in the same place the bad fit flag is currently computed. The energy per charge is (.5 mv^2 / q). Since you need only calculate the ratio the actual calculation is even simpler and can be derived quire straightforwardly. With this approach it should only be a few lines of code at most.

Comment thread docs/swapi/alpha-sw.md Outdated
Comment thread docs/swapi/alpha-sw.md Outdated
@leowerneck
leowerneck force-pushed the lw/146-bug---unflagged-alpha-peak-confusion branch from 0fb6384 to fe02cc2 Compare August 21, 2026 23:08
@leowerneck

Copy link
Copy Markdown
Collaborator Author

@hafarooki thank you for the comments! I have updated the code. The main modification is now much, much shorter, with the bulk of the added lines coming from testing. Please take another look when you have a chance.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated no new comments.

Comment thread docs/swapi/alpha-sw.md Outdated
Comment thread docs/swapi/alpha-sw.md Outdated
Comment thread docs/swapi/alpha-sw.md Outdated
Comment thread docs/swapi/alpha-sw.md Outdated
@hafarooki

Copy link
Copy Markdown
Contributor

Regarding the axis=-1: may not be necessary because the function uses raw return statements suggesting that there is not a timeseries and it is just a vector of shape (3,).

@leowerneck

Copy link
Copy Markdown
Collaborator Author

It is not wrong, though, and would prevent errors if that changes at some point. I'd be happy to remove it if preferred.

@hafarooki

Copy link
Copy Markdown
Contributor

Before merging I would suggest validation testing that with this change the time I pointed out in that ticket gets flagged. I would also request @bishwassth to comment on whether the limit should be 1.7 or some other number

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working Data Release 2 Deadline: September 1, 2026

Projects

None yet

Development

Successfully merging this pull request may close these issues.

BUG - Unflagged alpha peak confusion

3 participants