Skip to content

MAG L1B: round time_shift to int64 ns to preserve TT2000 precision#3107

Merged
sapols merged 2 commits intoIMAP-Science-Operations-Center:devfrom
sapols:fix/issue-3102
Apr 30, 2026
Merged

MAG L1B: round time_shift to int64 ns to preserve TT2000 precision#3107
sapols merged 2 commits intoIMAP-Science-Operations-Center:devfrom
sapols:fix/issue-3102

Conversation

@sapols
Copy link
Copy Markdown
Contributor

@sapols sapols commented Apr 30, 2026

Summary

Fixes #3102.

mag_l1b.py had two lines that multiplied a calibration time_shift by 1e9 and left the result as float64:

time_shift_ns = time_shift.data * 1e9

When that float was added to the int64 TT2000 epoch array (values near 8e17 ns), NumPy promoted everything to float64, which can't represent those integers exactly. So each epoch was silently quantized by ~20-100 ns. This adds sub-microsecond cadence jitter to every L1B epoch even when the calibration shift is effectively zero, and the noise propagates to L1C, L1D, and L2.

The fix rounds the time shift to integer nanoseconds in both spots:

time_shift_ns = np.int64(round(time_shift.data.item() * 1e9))

int64 + int64 stays int64, so TT2000 precision is preserved. Everything else in those functions is unchanged.

New tests

test_shift_time_preserves_int64_precision covers shift_time with both a zero shift and a nonzero shift on TT2000-scale epochs. The zero-shift case is the most striking demonstration of the bug ("I added 0 and the values changed?"); the nonzero case proves the shift actually applies and stays integer.

test_timeshift_vectors_per_second_preserves_int64_precision is a separate test because it covers a different function and a different assertion shape (string equality on the formatted attribute).

Test plan

  • New tests above pass with the fix and would fail without it.
  • Existing test_mag_l1b.py suite passes (9/9).
  • Full MAG suite passes (96 passed, 12 deselected for external data).
  • pre-commit run --files clean (ruff, codespell, numpydoc, mypy).

…MAP-Science-Operations-Center#3102)

float64 cannot represent int64 TT2000 epochs near 8e17 ns exactly, so
adding a float time_shift_ns silently quantized the epoch values.
Round to integer nanoseconds in shift_time and timeshift_vectors_per_second
so the arithmetic stays on the int64 grid.
@sapols sapols changed the title MAG L1B: preserve int64 TT2000 precision in shift_time MAG L1B: round time_shift to int64 ns to preserve TT2000 precision Apr 30, 2026
@sapols sapols marked this pull request as ready for review April 30, 2026 05:34
@sapols sapols requested a review from maxinelasp April 30, 2026 05:35
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, thank you

@sapols sapols merged commit 262cd1f into IMAP-Science-Operations-Center:dev Apr 30, 2026
14 checks passed
@sapols sapols deleted the fix/issue-3102 branch April 30, 2026 15:52
maxinelasp pushed a commit to maxinelasp/imap_processing that referenced this pull request May 1, 2026
…MAP-Science-Operations-Center#3107)

float64 cannot represent int64 TT2000 epochs near 8e17 ns exactly, so
adding a float time_shift_ns silently quantized the epoch values.
Round to integer nanoseconds in shift_time and timeshift_vectors_per_second
so the arithmetic stays on the int64 grid.
lacoak21 pushed a commit to lacoak21/imap_processing that referenced this pull request May 4, 2026
…MAP-Science-Operations-Center#3107)

float64 cannot represent int64 TT2000 epochs near 8e17 ns exactly, so
adding a float time_shift_ns silently quantized the epoch values.
Round to integer nanoseconds in shift_time and timeshift_vectors_per_second
so the arithmetic stays on the int64 grid.
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.

BUG - MAG L1B shift_time loses int64 epoch precision

2 participants