Skip to content

Glows L1b - Fix spin angle offset calculation in histogram flags#3065

Merged
tmplummer merged 3 commits into
IMAP-Science-Operations-Center:devfrom
pleasant-menlo:glows-histogram-flags-offset-bugfix
Apr 23, 2026
Merged

Glows L1b - Fix spin angle offset calculation in histogram flags#3065
tmplummer merged 3 commits into
IMAP-Science-Operations-Center:devfrom
pleasant-menlo:glows-histogram-flags-offset-bugfix

Conversation

@pleasant-menlo
Copy link
Copy Markdown
Contributor

@pleasant-menlo pleasant-menlo commented Apr 22, 2026

Fix bug in how spin angle offset is used when calculating histogram flags, addressing issue #2946

Change Summary

Overview

Changed the calculation of the azimuth to use the correct operation (- instead of +) to match equation 29 in the algorithm document.

histogram_flags

File changes

  • glows_l1b_data.py
  • test_glows_l1b.py

Testing

Added test that asserts that the range of spin angles that are flagged for being close to a UV source and being excluded are accurate to the updated equation.

@pleasant-menlo pleasant-menlo force-pushed the glows-histogram-flags-offset-bugfix branch from cd9115d to cc443fb Compare April 22, 2026 18:26
@pleasant-menlo pleasant-menlo marked this pull request as ready for review April 22, 2026 19:56
Copy link
Copy Markdown
Contributor

@tmplummer tmplummer left a comment

Choose a reason for hiding this comment

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

Thanks for taking this ticket on. Couple of questions about the added test.

Comment on lines +411 to +412
assert np.all(hist_data.histogram_flag_array[0, 1397:1437] == 1)
assert hist_data.histogram_flag_array[1, 1417] == 2
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.

Where did these values come from? I saw the plot showing that this change makes output match the GLOWS JSON, but these asserts are really opaque as to why we are expecting these values to be set this way.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This assertion was meant to test that uv sources are flagged at these observed spin angles when using the updated calculation for azimuth. We can look into isolating and testing the look direction calculations instead to offer greater clarity to what is being tested.

@pytest.mark.external_kernel
@pytest.mark.usefixtures("use_fake_spin_data_for_time")
@patch("imap_processing.spice.geometry.imap_state")
def test_process_histogram_calculates_correct_angle_offset(
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.

Would there be a way to just test the HistogramL1B.flag_uv_and_excluded method instead of needing to run the entire HistogramL1B processing? It looks like many of the tests in this file are patching attributes of HistogramL1B to get around having to run the full processing.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

We pulled out the calculation of the look vectors in DPS so that we are able to test that in isolation. Does this seem like a reasonable approach?

…od that can be tested in isolation. Removed redundant test.
]
with furnish_kernels(kernels):
expected_imap_spin_angle_bin_cntr = np.array([0, 90, 180, 270])
expected_position_angle_offset_average = 71.5
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.

Can you add a comment on where 71.5 degrees comes from. I a looked at the GLOW algorithm document a bit and can't seem to figure it out.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This was just an arbitrary value that we had used since the actual input is coming from an upstream calculation. We have updated the variable names to avoid confusion.

with furnish_kernels(kernels):
expected_imap_spin_angle_bin_cntr = np.array([0, 90, 180, 270])
expected_position_angle_offset_average = 71.5
expected_azimuth = np.array([360 - 71.5, 90 - 71.5, 180 - 71.5, 270 - 71.5])
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.

Suggested change
expected_azimuth = np.array([360 - 71.5, 90 - 71.5, 180 - 71.5, 270 - 71.5])
expected_azimuth = np.array([360, 90, 180, 270]) - expected_position_angle_offset_average

Comment thread imap_processing/tests/glows/test_glows_l1b.py
Comment thread imap_processing/tests/glows/test_glows_l1b.py
Copy link
Copy Markdown
Contributor

@tmplummer tmplummer left a comment

Choose a reason for hiding this comment

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

Thanks for making this change. This makes the testing clearer to me. I just have some nit-picks on some of the implementation.

Copy link
Copy Markdown
Contributor

@tmplummer tmplummer left a comment

Choose a reason for hiding this comment

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

Excellent. Thanks for this work!

@tmplummer tmplummer merged commit 55bcc7c into IMAP-Science-Operations-Center:dev Apr 23, 2026
14 checks passed
lacoak21 pushed a commit to lacoak21/imap_processing that referenced this pull request May 4, 2026
…P-Science-Operations-Center#3065)

* Glows L1b - Fixed bug in how spin angle offset was used when calculating histogram flags (IMAP-Science-Operations-Center#2946)

* Glows L1b - Pulled out calculation of DPS look vectors to static method that can be tested in isolation. Removed redundant test.

* Glows L1b - Simplified test logic, variables with more descriptive naming

---------

Co-authored-by: Menlo Innovations - CAVA Project <harrison@menloinnovations.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants