Skip to content

BUG - MAG L1D IndexError on spin offsets #2832

@maxinelasp

Description

@maxinelasp

Description of the issue

Seeing an index error during calculate_spin_offsets. Probably just needs a check on chunk_epoch to ensure the chunk has any values in it.

Steps to reproduce the issue

["--instrument","mag","--data-level","l1d","--descriptor","norm-srf","--start-date","20260109","--version","v002","--dependency","imap_mag_l1d_norm-srf-e9bfa7c8_20260109_v002.json","--upload-to-sdc"]

imap_mag_l1d_norm-srf-e9bfa7c8_20260109_v002.json

Expected vs Actual behavior

/usr/local/lib/python3.12/site-packages/imap_processing/mag/l1d/mag_l1d_data.py:515: RuntimeWarning: Mean of empty slice
54
2026-03-04T04:35:57.179Z
avg_x = np.nanmean(chunk_vectors[:, 0])
55
2026-03-04T04:35:57.179Z
/usr/local/lib/python3.12/site-packages/imap_processing/mag/l1d/mag_l1d_data.py:516: RuntimeWarning: Mean of empty slice
56
2026-03-04T04:35:57.179Z
avg_y = np.nanmean(chunk_vectors[:, 1])
57
2026-03-04T04:35:57.179Z
Traceback (most recent call last):
58
2026-03-04T04:35:57.179Z
File "/usr/local/bin/imap_cli", line 8, in <module>
59
2026-03-04T04:35:57.179Z
Processing MAG l1d
60
2026-03-04T04:35:57.179Z
sys.exit(main())
61
2026-03-04T04:35:57.179Z
^^^^^^
62
2026-03-04T04:35:57.179Z
File "/usr/local/lib/python3.12/site-packages/imap_processing/cli.py", line 1604, in main
63
2026-03-04T04:35:57.179Z
instrument.process()
64
2026-03-04T04:35:57.179Z
File "/usr/local/lib/python3.12/site-packages/imap_processing/cli.py", line 447, in process
65
2026-03-04T04:35:57.179Z
products = self.do_processing(dependencies)
66
2026-03-04T04:35:57.179Z
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
67
2026-03-04T04:35:57.179Z
File "/usr/local/lib/python3.12/site-packages/imap_processing/cli.py", line 1161, in do_processing
68
2026-03-04T04:35:57.179Z
datasets = mag_l1d(
69
2026-03-04T04:35:57.179Z
^^^^^^^^
70
2026-03-04T04:35:57.179Z
File "/usr/local/lib/python3.12/site-packages/imap_processing/mag/l1d/mag_l1d.py", line 85, in mag_l1d
71
2026-03-04T04:35:57.179Z
l1d_norm = MagL1d(
72
2026-03-04T04:35:57.179Z
^^^^^^^
73
2026-03-04T04:35:57.179Z
File "<string>", line 16, in __init__
74
2026-03-04T04:35:57.179Z
File "/usr/local/lib/python3.12/site-packages/imap_processing/mag/l1d/mag_l1d_data.py", line 189, in __post_init__
75
2026-03-04T04:35:57.179Z
self.spin_offsets = self.calculate_spin_offsets()
76
2026-03-04T04:35:57.179Z
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
77
2026-03-04T04:35:57.179Z
File "/usr/local/lib/python3.12/site-packages/imap_processing/mag/l1d/mag_l1d_data.py", line 530, in calculate_spin_offsets
78
2026-03-04T04:35:57.179Z
offset_epochs.append(chunk_epoch[0])
79
2026-03-04T04:35:57.179Z
~~~~~~~~~~~^^^
80
2026-03-04T04:35:57.179Z
IndexError: index 0 is out of bounds for axis 0 with size 0

Additional notes, affected areas, and suggested fixes

Add a check to see if chunk_epoch has a length of zero before continuing processing. Possibly, fail with a smarter error, although I think one chunk being empty is probably ok.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Ins: MAGRelated to the MAG instrumentbugSomething isn't working

    Type

    No type

    Projects

    Status

    Todo

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions