Skip to content

Commit d49cf2c

Browse files
author
Menlo Innovations - CAVA Project
committed
Harrison 3029 - PMCL - CoDICE Lo direct events: Convert spin_sector from float to int when reading L2 to workaround a bug
1 parent 7bd2a87 commit d49cf2c

2 files changed

Lines changed: 18 additions & 2 deletions

File tree

imap_l3_processing/codice/l3/lo/models.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ def read_from_cdf(cls, l2_direct_event_cdf: Path):
128128
num_events=read_variable_and_mask_fill_values(cdf["num_events"])[:, :CODICE_LO_L2_NUM_PRIORITIES, ...],
129129
spin_angle=read_variable_and_mask_fill_values(cdf["spin_angle"])[:, :CODICE_LO_L2_NUM_PRIORITIES, ...],
130130
spin_sector=read_variable_and_mask_fill_values(cdf["spin_sector"])[:, :CODICE_LO_L2_NUM_PRIORITIES,
131-
...],
131+
...].astype(int),
132132
elevation_angle=read_variable_and_mask_fill_values(cdf["elevation_angle"])[:,
133133
:CODICE_LO_L2_NUM_PRIORITIES, ...],
134134
tof=read_variable_and_mask_fill_values(cdf["tof"])[:, :CODICE_LO_L2_NUM_PRIORITIES, ...],

tests/codice/l3/lo/test_models.py

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -547,7 +547,7 @@ def test_codice_lo_l2_direct_events_reads_from_correct_float_data(self):
547547
cdf["energy_step"] = rng.random(cdf["energy_step"].shape)
548548
cdf["energy_per_charge"] = rng.random(cdf["energy_per_charge"].shape)
549549
cdf["spin_angle"] = rng.random(cdf["spin_angle"].shape)
550-
cdf["spin_sector"] = rng.random(cdf["spin_sector"].shape)
550+
cdf["spin_sector"] = rng.integers(0, 24, cdf["spin_sector"].shape)
551551
cdf["elevation_angle"] = rng.random(cdf["elevation_angle"].shape)
552552
cdf["position"] = rng.random(cdf["position"].shape)
553553

@@ -561,6 +561,22 @@ def test_codice_lo_l2_direct_events_reads_from_correct_float_data(self):
561561
np.testing.assert_array_equal(l2_direct_event.spin_angle, cdf["spin_angle"][:, :7, ...])
562562
np.testing.assert_array_equal(l2_direct_event.elevation_angle, cdf["elevation_angle"][:, :7, ...])
563563

564+
def test_workaround_to_convert_float_spin_sector_to_int(self):
565+
all_fill_l2_cdf_path = get_test_data_path('codice/imap_codice_l2_lo-direct-events_20260307_v003-all-fill.cdf')
566+
567+
rng = np.random.default_rng()
568+
with tempfile.TemporaryDirectory() as tmpdir:
569+
tmpdir = Path(tmpdir)
570+
571+
test_cdf_path = tmpdir / "test_cdf.cdf"
572+
with CDF(str(test_cdf_path), masterpath=str(all_fill_l2_cdf_path)) as cdf:
573+
expected_spin_sector = rng.integers(0, 24, cdf["spin_sector"].shape, dtype=int)
574+
cdf["spin_sector"] = expected_spin_sector.astype(float)
575+
576+
l2_direct_event = CodiceLoL2DirectEventData.read_from_cdf(test_cdf_path)
577+
578+
np.testing.assert_array_equal(l2_direct_event.spin_sector, expected_spin_sector[:, :7, ...], strict=True)
579+
564580
def test_codice_lo_l2_direct_events_read_from_cdf_handles_fill_value(self):
565581
all_fill_l2_cdf_path = get_test_data_path('codice/imap_codice_l2_lo-direct-events_20260307_v003-all-fill.cdf')
566582
l2_direct_event = CodiceLoL2DirectEventData.read_from_cdf(all_fill_l2_cdf_path)

0 commit comments

Comments
 (0)