Skip to content

GLOWS L2 - Add ecliptic coordinates for histogram bin centers#2871

Merged
vmartinez-cu merged 8 commits intoIMAP-Science-Operations-Center:devfrom
vmartinez-cu:ecliptic-loc-cntr-bins
Mar 30, 2026
Merged

GLOWS L2 - Add ecliptic coordinates for histogram bin centers#2871
vmartinez-cu merged 8 commits intoIMAP-Science-Operations-Center:devfrom
vmartinez-cu:ecliptic-loc-cntr-bins

Conversation

@vmartinez-cu
Copy link
Copy Markdown
Collaborator

This PR adds a new method to compute the ecliptic longitude and latitude for each histogram bin center in the GLOWS L2 product using SPICE transformations. It also adds a unit test and mocking of these computations in existing tests where appropriate to remain independent of SPICE/time conversions.

Code Updates

  • Added the compute_ecliptic_coords_of_bin_centers static method to DailyLightcurve, which transforms instrument pointing directions from the IMAP spacecraft frame to the ECLIPJ2000 frame using SPICE, providing ecliptic longitude and latitude for each histogram bin center.
  • Updated the __post_init__ method of DailyLightcurve to compute and assign ecliptic_lon and ecliptic_lat using the new method, replacing the previous placeholder arrays.

Testing

  • Added a mock_ecliptic_bin_centers test fixture to mock ecliptic coordinate computations, ensuring unit tests for DailyLightcurve are independent of SPICE/time conversions.
  • Updated all affected tests in test_glows_l2_data.py and `test_glows_l2.py to use the new fixture, ensuring their reliability and isolation from
  • Added a unit test to test the output of the new method

Closes #2722

@vmartinez-cu vmartinez-cu added this to the March 2026 milestone Mar 25, 2026
@vmartinez-cu vmartinez-cu added Ins: GLOWS Related to the GLOWS instrument Level: L2 Level 2 processing labels Mar 25, 2026
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 adds computation of ecliptic longitude/latitude for GLOWS L2 histogram bin centers (via SPICE frame transforms) and updates the test suite to mock this computation in most unit tests while adding a kernel-backed unit test for the new method.

Changes:

  • Add DailyLightcurve.compute_ecliptic_coords_of_bin_centers() to compute bin-center ecliptic coordinates using SPICE transforms.
  • Update DailyLightcurve.__post_init__ to populate ecliptic_lon/ecliptic_lat instead of placeholder zeros.
  • Add a mocking fixture for ecliptic bin-center computation and update affected tests; add an external-kernel unit test for the new method.

Reviewed changes

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

File Description
imap_processing/glows/l2/glows_l2_data.py Compute and store ecliptic lon/lat for L2 daily lightcurve bin centers using SPICE transforms.
imap_processing/tests/glows/test_glows_l2_data.py Add external-kernel test for ecliptic coordinate computation; update DailyLightcurve tests to use mocking fixture and include imap_start_time.
imap_processing/tests/glows/test_glows_l2.py Inject new mocking fixture into L2 generation tests to avoid geometry-dependent SPICE calls.
imap_processing/tests/glows/conftest.py Add mock_ecliptic_bin_centers fixture to monkeypatch the new SPICE-based computation.
Comments suppressed due to low confidence (1)

imap_processing/glows/l2/glows_l2_data.py:133

  • ecliptic_lon/ecliptic_lat are only assigned inside if self.number_of_bins:. When number_of_bins is 0 (e.g., no good data for a day), these attributes are left uninitialized and later access will raise AttributeError. Initialize them to empty arrays (or the correct fill values) before the conditional so the object is always in a valid state.
        if self.number_of_bins:
            # imap_spin_angle_bin_cntr is the raw IMAP spin angle ψ (0 - 360°,
            # bin midpoints).

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

Comment on lines +186 to +190
Histogram bin centers represent the center spin angle for each bin in the imap
frame, which corresponds to a specific pointing direction in space. This method
transforms the instrument pointing direction for each bin center from the IMAP
spacecraft frame to the ECLIPJ2000 frame.

Copy link

Copilot AI Mar 25, 2026

Choose a reason for hiding this comment

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

The docstring says the pointing is transformed from the "IMAP spacecraft frame" to ECLIPJ2000, but the implementation builds az/el in SpiceFrame.IMAP_DPS and transforms from IMAP_DPS to ECLIPJ2000. Please update the docstring/parameter descriptions to match the actual frames to avoid confusion for future maintainers.

Copilot uses AI. Check for mistakes.
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.

Agree. Perhaps this should read "This method transforms the instrument pointing direction for each bin center from the IMAP Pointing frame (IMAP_DPS) to the ECLIPJ2000 frame."

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Your suggestions is much clearer, thanks! Are the IMAP spacecraft and DPS frames different?

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.

Yes. The IMAP_SPACECRAFT frame is attached to the spacecraft and rotates with it. The IMAP_DPS frame is coincident with the s/c but does not rotate with it.

Copy link
Copy Markdown
Contributor

@subagonsouth subagonsouth left a comment

Choose a reason for hiding this comment

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

Great! Everything looks good to me except for the one gotcha I mentioned about the time used for the transform_az_el call. Probably worth checking in with @maxinelasp about where that start time comes from.

self.ecliptic_lon = np.roll(self.ecliptic_lon, roll)
self.ecliptic_lat = np.roll(self.ecliptic_lat, roll)
et_imap_start_time = sct_to_et(
met_to_sclkticks(l1b_data["imap_start_time"][0].data)
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.

Something that recently came up to be aware of: If this start time is identically equal to the start time of the Pointing, it can sometimes have a type conversion error that causes the queried value to be outside the coverage window of the DPS kernel. If "imap_start_time" is a MET time that has been checked against the repoint table MET time to ensure it is in the Pointing, this implementation should be fine. If there is a chance of a rounding error, I suggest using the midpoint MET time instead of start time here.

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.

That is not a safe assumption we can make here, so I think Tim's suggestion of midpoint timestamp makes the most sense. @subagonsouth, is this only for the sct_to_et conversion? Or are there other cases where this might be an issue?

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.

The problem isn't really with the time conversion functions. Those functions will work for whatever time you give them. The problem arises when a certain series of time conversions happen to the Pointing start time that gets passed into a frame_transform call that uses the DPS kernel. I don't know how much detail you want but, here goes.

The DPS kernel has times represented in spacecraft clock format which is integer seconds and integer ticks (1 tick is 20us on IMAP). The repoint table also has times represented in sclk format. But, spice functions use double precision floating point TDB seconds (AKA ET). To complicate this even more, often in IMAP, we are storing the epoch as integer nanoseconds. So, a condition can arise where the conversion from sclk (MET) to epoch then back to TDB to pass into the frame_transform function which SPICE then converts back to sclk can result in an sclk value that is slightly before the sclk start time of the coverage provided by the DPS kernel. Since the DPS kernel is static during a pointing, the safest way to avoid this situation is to use the midpoint time of the Pointing.

Comment on lines +186 to +190
Histogram bin centers represent the center spin angle for each bin in the imap
frame, which corresponds to a specific pointing direction in space. This method
transforms the instrument pointing direction for each bin center from the IMAP
spacecraft frame to the ECLIPJ2000 frame.

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.

Agree. Perhaps this should read "This method transforms the instrument pointing direction for each bin center from the IMAP Pointing frame (IMAP_DPS) to the ECLIPJ2000 frame."

@vmartinez-cu vmartinez-cu force-pushed the ecliptic-loc-cntr-bins branch from c086c01 to 42b524b Compare March 26, 2026 18:23
@tech3371
Copy link
Copy Markdown
Contributor

Looks like Tim and Maxine is reviewing this PR. I will standby for now :)

Copy link
Copy Markdown
Contributor

@maxinelasp maxinelasp left a comment

Choose a reason for hiding this comment

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

Nice work! Only thing is the change suggested by Tim - everything else looks good :) Once that is addressed, consider this approved by me

self.ecliptic_lon = np.roll(self.ecliptic_lon, roll)
self.ecliptic_lat = np.roll(self.ecliptic_lat, roll)
et_imap_start_time = sct_to_et(
met_to_sclkticks(l1b_data["imap_start_time"][0].data)
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.

That is not a safe assumption we can make here, so I think Tim's suggestion of midpoint timestamp makes the most sense. @subagonsouth, is this only for the sct_to_et conversion? Or are there other cases where this might be an issue?

@tech3371 tech3371 removed this from the March 2026 milestone Mar 27, 2026
@vmartinez-cu vmartinez-cu force-pushed the ecliptic-loc-cntr-bins branch from 42b524b to 8aadbc5 Compare March 30, 2026 17:13
Copy link
Copy Markdown
Contributor

@subagonsouth subagonsouth left a comment

Choose a reason for hiding this comment

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

Other than the one nit-pick... Looks great!

# Get the midpoint start time covered by repointing kernels
# needed to compute ecliptic coordinates
mid_idx = len(l1b_data["imap_start_time"]) // 2
et_imap_start_time = sct_to_et(
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.

Nit pick: You might want to update this variable name to indicate that it is the Pointing midpoint time.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Good suggestion - renaming this variable will make this step more clear

…eclipitic coordinates of histogram bin centers to populate the DailyLightcurve ecliptic_lon and ecliptic_lat attributes.
…ts that were failing. Rebase and merge Maxine's spin angle work"
…o conftest. Modify method computing ecliptic coordinates to take two args rather than the l1b dataset
@vmartinez-cu vmartinez-cu force-pushed the ecliptic-loc-cntr-bins branch from 8aadbc5 to 6015625 Compare March 30, 2026 19:16
@vmartinez-cu vmartinez-cu merged commit 48641ea into IMAP-Science-Operations-Center:dev Mar 30, 2026
14 checks passed
@github-project-automation github-project-automation bot moved this to Done in IMAP Mar 30, 2026
@vmartinez-cu vmartinez-cu deleted the ecliptic-loc-cntr-bins branch March 30, 2026 19:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Ins: GLOWS Related to the GLOWS instrument Level: L2 Level 2 processing

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

ENH - Compute ecliptic location of bin centers in GLOWS L2 (post-SPICE)

5 participants