Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions imap_processing/ialirt/l0/process_codice.py
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,7 @@ def convert_to_intensities(
+ cod_hi_l1b_data[f"energy_{species}_minus"]
).values[:, np.newaxis]

# g_g is 4 elements (replicate 15 times)
denom = g_g * eps_ig * energy_passbands # (15, 4)
# reshape to broadcast along h's first and third dimensions
denom = denom[None, :, None, :]
Expand Down
2 changes: 1 addition & 1 deletion imap_processing/tests/codice/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ def _side_effect(descriptor: str = None, data_type: str = None) -> list[Path]:
return [
TEST_DATA_PATH
/ "l1a_lut"
/ "imap_codice_l1a-sci-lut_20251007_v004.json"
/ "imap_codice_l1a-sci-lut_20251218_v001.json"
]
elif descriptor == "l2-hi-omni-efficiency":
return [
Expand Down
6 changes: 3 additions & 3 deletions imap_processing/tests/codice/test_codice_l1a_lut.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def test_codice_non_zero_patterns(codice_lut_path):
sci_lut_path = codice_lut_path(descriptor="l1a-sci-lut")[0]

sci_lut = json.loads(sci_lut_path.read_text())
table_id = "3952862729"
table_id = "3974360784"
assert table_id in sci_lut

collapse_lo = sci_lut[table_id]["collapse_lo"]
Expand Down Expand Up @@ -98,7 +98,7 @@ def test_get_collapse_pattern_shape(codice_lut_path):
"""
sci_lut_path = codice_lut_path(descriptor="l1a-sci-lut")[0]

table_id = "3952862729"
table_id = "3974360784"
sci_lut_data = json.loads(sci_lut_path.read_text()).get(table_id)

# Lo instrument counts - singles
Expand Down Expand Up @@ -141,7 +141,7 @@ def test_get_collapse_pattern_shape(codice_lut_path):
def test_acquisition_time(codice_lut_path):
sci_lut_path = codice_lut_path(descriptor="l1a-sci-lut")[0]
sci_lut_data = json.loads(sci_lut_path.read_text())
table_id = "3952862729"
table_id = "3974360784"
low_stepping_tab = sci_lut_data[table_id]["lo_stepping_tab"]
acq_time_per_step = calculate_acq_time_per_step(low_stepping_tab)
expected_acq_times = (
Expand Down
2 changes: 1 addition & 1 deletion imap_processing/tests/external_test_data_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
("imap_codice_hskp_20250814_v001.pkts", "codice/data/l1a_input/"),

# L1A LUT
("imap_codice_l1a-sci-lut_20251007_v004.json", "codice/data/l1a_lut/"),
("imap_codice_l1a-sci-lut_20251218_v001.json", "codice/data/l1a_lut/"),

# L1A validation data
(f"imap_codice_l1a_hi-counters-aggregated_{VALIDATION_FILE_DATE}_{VALIDATION_FILE_VERSION}.cdf", "codice/data/l1a_validation"),
Expand Down
88 changes: 41 additions & 47 deletions imap_processing/tests/ialirt/unit/test_process_codice.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,37 @@ def cod_lo_l1b_test_data():
return data


@pytest.fixture(scope="session")
@pytest.mark.external_test_data
def postlaunch_packet_path():
"""Returns the paths to the binary packets."""
directory = imap_module_directory / "tests" / "ialirt" / "data" / "l0"
filenames = [
"iois_1_packets_2026_019_14_02_18",
"iois_1_packets_2026_019_14_03_19",
"iois_1_packets_2026_019_14_04_20",
"iois_1_packets_2026_019_14_05_21",
"iois_1_packets_2026_019_14_06_22",
"iois_1_packets_2026_019_14_07_23",
"iois_1_packets_2026_019_14_08_24",
]
return tuple(directory / fname for fname in filenames)

@pytest.fixture
def postlaunch_xarray_data(postlaunch_packet_path, sc_packet_path):
"""Create xarray data for multiple packets."""
apid = 478
_, xtce_ialirt_path = sc_packet_path

xarray_data = tuple(
packet_file_to_datasets(packet, xtce_ialirt_path, use_derived_value=False)[apid]
for packet in postlaunch_packet_path
)

merged_xarray_data = xr.concat(xarray_data, dim="epoch")
return merged_xarray_data


def make_codice_lo_ialirt_dataset(cod_lo_l1a_test_data, descriptor):
coords = {
"epoch": cod_lo_l1a_test_data["epoch"],
Expand Down Expand Up @@ -351,7 +382,7 @@ def l1a_lut_path():
/ "codice"
/ "data"
/ "l1a_lut"
/ "imap_codice_l1a-sci-lut_20251007_v004.json"
/ "imap_codice_l1a-sci-lut_20251218_v001.json"
)

return lut_path
Expand Down Expand Up @@ -380,15 +411,15 @@ def l2_processing_dependencies():
/ "codice"
/ "data"
/ "l2_lut"
/ "imap_codice_l2-lo-efficiency_20251008_v001.csv"
/ "imap_codice_l2-lo-efficiency_20251212_v003.csv"
)
gf_path = (
imap_module_directory
/ "tests"
/ "codice"
/ "data"
/ "l2_lut"
/ "imap_codice_l2-lo-gfactor_20251008_v001.csv"
/ "imap_codice_l2-lo-gfactor_20251212_v003.csv"
)

return eff_path, gf_path
Expand All @@ -400,7 +431,7 @@ def test_create_xarray_dataset_basic(l1a_lut_path):
science_values = ["0000000100100011"]
metadata_values = {
"VIEW_ID": np.array([0]),
"TABLE_ID": np.array([3952862729]),
"TABLE_ID": np.array([3974360784]),
"ACQ_START_SECONDS": np.array([1625078400]),
"ACQ_START_SUBSECONDS": np.array([0]),
"SPIN_PERIOD": np.array([24]),
Expand Down Expand Up @@ -735,64 +766,27 @@ def test_l2_ialirt_cod_lo(

@pytest.mark.external_test_data
def test_process_codice_lo(
cod_lo_test_dataset,
postlaunch_xarray_data,
l1a_lut_path,
l2_lut_path,
cod_lo_l2_test_data,
l2_processing_dependencies,
):
"""Test process_codice for hi."""
eff_path, gf_path = l2_processing_dependencies

n = cod_lo_test_dataset.dims["epoch"]
cod_lo_test_dataset = cod_lo_test_dataset.assign(
sc_sclk_sec=("epoch", np.zeros(n, dtype=np.int64)),
sc_sclk_sub_sec=("epoch", np.zeros(n, dtype=np.int64)),
)

cod_lo_data, _ = process_codice(
cod_lo_test_dataset, l1a_lut_path, eff_path, "codice_lo", gf_path
postlaunch_xarray_data, l1a_lut_path, eff_path, "codice_lo", gf_path
)

l2_products = [
"codice_lo_c_over_o_abundance",
"codice_lo_mg_over_o_abundance",
"codice_lo_fe_over_o_abundance",
"codice_lo_c_plus_6_over_c_plus_5",
"codice_lo_o_plus_7_over_o_plus_6",
"codice_lo_fe_low_over_fe_high",
]

assert len(cod_lo_data) == 9

for product in l2_products:
assert cod_lo_data[0][product] == FILLVAL_FLOAT32
print('hi')


@pytest.mark.external_test_data
def test_process_codice_hi(
cod_hi_test_dataset, l1a_lut_path, l2_lut_path, cod_hi_l2_test_data
postlaunch_xarray_data, l1a_lut_path, l2_lut_path
):
"""Test process_codice for hi."""
test_data = cod_hi_l2_test_data["h"]

n = cod_hi_test_dataset.dims["epoch"]
cod_hi_test_dataset = cod_hi_test_dataset.assign(
sc_sclk_sec=("epoch", np.zeros(n, dtype=np.int64)),
sc_sclk_sub_sec=("epoch", np.zeros(n, dtype=np.int64)),
)

_, cod_hi_data = process_codice(
cod_hi_test_dataset, l1a_lut_path, l2_lut_path, "codice_hi"
)
samples_per_group = test_data.shape[0] // len(cod_hi_data)
grouped_test_data = test_data.reshape(
len(cod_hi_data),
samples_per_group,
*test_data.shape[1:],
postlaunch_xarray_data, l1a_lut_path, l2_lut_path, "codice_hi"
)

for i, group in enumerate(cod_hi_data):
arr = np.array(group["codice_hi_h"], dtype=float)

np.testing.assert_allclose(arr, grouped_test_data[i], atol=3e-2, rtol=1e-5)
print('hi')
Loading