GLOWS L2 - Add ecliptic coordinates for histogram bin centers#2871
Conversation
There was a problem hiding this comment.
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 populateecliptic_lon/ecliptic_latinstead 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_latare only assigned insideif self.number_of_bins:. Whennumber_of_binsis 0 (e.g., no good data for a day), these attributes are left uninitialized and later access will raiseAttributeError. 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.
| 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. | ||
|
|
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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."
There was a problem hiding this comment.
Your suggestions is much clearer, thanks! Are the IMAP spacecraft and DPS frames different?
There was a problem hiding this comment.
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.
subagonsouth
left a comment
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
| 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. | ||
|
|
There was a problem hiding this comment.
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."
c086c01 to
42b524b
Compare
|
Looks like Tim and Maxine is reviewing this PR. I will standby for now :) |
maxinelasp
left a comment
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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?
42b524b to
8aadbc5
Compare
subagonsouth
left a comment
There was a problem hiding this comment.
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( |
There was a problem hiding this comment.
Nit pick: You might want to update this variable name to indicate that it is the Pointing midpoint time.
There was a problem hiding this comment.
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
…s from a test that doesn't need it
…he repointing time coverage
8aadbc5 to
6015625
Compare
48641ea
into
IMAP-Science-Operations-Center:dev
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
compute_ecliptic_coords_of_bin_centersstatic method toDailyLightcurve, 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.__post_init__method ofDailyLightcurveto compute and assignecliptic_lonandecliptic_latusing the new method, replacing the previous placeholder arrays.Testing
mock_ecliptic_bin_centerstest fixture to mock ecliptic coordinate computations, ensuring unit tests forDailyLightcurveare independent of SPICE/time conversions.test_glows_l2_data.pyand `test_glows_l2.py to use the new fixture, ensuring their reliability and isolation fromCloses #2722