Skip to content

Commit 150d7be

Browse files
committed
add new validation tables. Vectorize lookup
1 parent 81dd9b1 commit 150d7be

File tree

3 files changed

+21
-34
lines changed

3 files changed

+21
-34
lines changed

imap_processing/codice/codice_l2.py

Lines changed: 8 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,9 @@ def get_mpq_calc_energy_conversion_vals(
9393
esa_kev : np.ndarray
9494
An array of energy in keV for each esa step.
9595
"""
96-
mpq_calc_lut_file = dependencies.get_file_paths(descriptor="lo-mpq-cal")[0]
96+
mpq_calc_lut_file = dependencies.get_file_paths(descriptor="l2-lo-onboard-mpq-cal")[
97+
0
98+
]
9799
mpq_df = pd.read_csv(mpq_calc_lut_file, header=None)
98100
k_factor = float(mpq_df.loc[0, 10])
99101
esa_v = mpq_df.loc[4, 4:].to_numpy().astype(np.float64)
@@ -1017,12 +1019,14 @@ def process_lo_direct_events(dependencies: ProcessingInputCollection) -> xr.Data
10171019
apd_energy_shape = l2_dataset["apd_energy"].shape
10181020

10191021
# The energy table lookup columns are ordered by apd_id and gain
1020-
# E.g. APD-0-LG, APD-0-HG, APD-1-LG, APD-1-HG, ..., APD-29-LG
1022+
# E.g. APD-1-LG, APD-1-HG, ..., APD-29-LG
10211023
# So we can get the col index like so: ind = apd_id * 2 + gain
10221024
col_inds = apd_ids * 2 + gains
10231025
# Get a mask of valid indices
1024-
valid_mask = (apd_energy < energy_table.shape[0]) & (
1025-
col_inds < energy_table.shape[1]
1026+
valid_mask = (
1027+
(apd_energy < energy_table.shape[0])
1028+
& (col_inds < energy_table.shape[1])
1029+
& (apd_ids > 0)
10261030
)
10271031
# Initialize output array with NaNs
10281032
energy_bins_inds = np.full(apd_energy.shape, np.nan)
@@ -1106,23 +1110,6 @@ def process_lo_direct_events(dependencies: ProcessingInputCollection) -> xr.Data
11061110
attrs=cdf_attrs.get_variable_attributes("priority_label", check_schema=False),
11071111
)
11081112

1109-
print("\n=== DATA TYPE CHECK ===")
1110-
print(f"event_num_label dtype: {l2_dataset['event_num_label'].dtype}")
1111-
print(f"priority_label dtype: {l2_dataset['priority_label'].dtype}")
1112-
print(f"elevation_angle dtype: {l2_dataset['elevation_angle'].dtype}")
1113-
print(f"spin_angle dtype: {l2_dataset['spin_angle'].dtype}")
1114-
print(f"apd_energy dtype: {l2_dataset['apd_energy'].dtype}")
1115-
print(f"energy_per_charge dtype: {l2_dataset['energy_per_charge'].dtype}")
1116-
print(f"tof dtype: {l2_dataset['tof'].dtype}")
1117-
print(f"epoch_delta_minus dtype: {l2_dataset['epoch_delta_minus'].dtype}")
1118-
print(f"epoch_delta_plus dtype: {l2_dataset['epoch_delta_plus'].dtype}")
1119-
1120-
# Check for any unexpected dtypes
1121-
for var in l2_dataset.data_vars:
1122-
if "U" in str(l2_dataset[var].dtype) and "|S" not in str(l2_dataset[var].dtype):
1123-
if "<U" not in str(l2_dataset[var].dtype):
1124-
print(f"⚠️ WARNING: {var} has dtype {l2_dataset[var].dtype}")
1125-
11261113
return l2_dataset
11271114

11281115

imap_processing/tests/codice/conftest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
TEST_L0_FILE = TEST_DATA_L0_PATH / "imap_codice_l0_raw_20241110_v001.pkts"
1010

1111
VALIDATION_FILE_DATE = "20250814"
12-
VALIDATION_FILE_VERSION = "v011"
12+
VALIDATION_FILE_VERSION = "v012"
1313

1414

1515
@pytest.fixture(scope="session")

imap_processing/tests/codice/test_codice_l2.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,7 @@
4848
def processing_dependencies(codice_lut_path):
4949
eff_file = "imap_codice_l2-lo-efficiency_20251008_v001.csv"
5050
gf_file = "imap_codice_l2-lo-gfactor_20251008_v001.csv"
51-
mpq_file = "imap_codice_lo-mpq-cal_20250101_v001.csv"
52-
return ProcessingInputCollection(
53-
AncillaryInput(gf_file), AncillaryInput(eff_file), AncillaryInput(mpq_file)
54-
)
51+
return ProcessingInputCollection(AncillaryInput(gf_file), AncillaryInput(eff_file))
5552

5653

5754
@pytest.fixture
@@ -181,9 +178,9 @@ def test_get_efficiency_lut(processing_dependencies, mock_get_file_paths):
181178
def test_get_tof_ns_from_mpq_lut(processing_dependencies, mock_get_file_paths):
182179
tof_ns = get_mpq_calc_tof_conversion_vals(processing_dependencies)
183180
assert tof_ns.shape == (1024,)
184-
mpq_calc_lut_file = processing_dependencies.get_file_paths(descriptor="lo-mpq-cal")[
185-
0
186-
]
181+
mpq_calc_lut_file = processing_dependencies.get_file_paths(
182+
descriptor="l2-lo-onboard-mpq-cal"
183+
)[0]
187184
mpq_df = pd.read_csv(mpq_calc_lut_file, header=None)
188185
expected_tof_ns = mpq_df.loc[6:, 1].to_numpy().astype(np.float64)
189186
# Calculated values should be more precise than LUT but should be close
@@ -193,9 +190,9 @@ def test_get_tof_ns_from_mpq_lut(processing_dependencies, mock_get_file_paths):
193190
def test_get_energy_kev_from_mpq_lut(processing_dependencies, mock_get_file_paths):
194191
energy_kev = get_mpq_calc_energy_conversion_vals(processing_dependencies)
195192
assert energy_kev.shape == (128,)
196-
mpq_calc_lut_file = processing_dependencies.get_file_paths(descriptor="lo-mpq-cal")[
197-
0
198-
]
193+
mpq_calc_lut_file = processing_dependencies.get_file_paths(
194+
descriptor="l2-lo-onboard-mpq-cal"
195+
)[0]
199196
mpq_df = pd.read_csv(mpq_calc_lut_file, header=None)
200197
expected_tof_ns = mpq_df.loc[5, 4:].to_numpy().astype(np.float64)
201198
# Calculated values should be more precise than LUT but should be close
@@ -524,6 +521,7 @@ def test_codice_l2_lo_de(mock_get_file_paths, codice_lut_path):
524521
codice_lut_path(descriptor="l2-lo-onboard-energy-table"),
525522
codice_lut_path(descriptor="l2-lo-onboard-energy-bins"),
526523
codice_lut_path(descriptor="l2-lo-onboard-mpq-cal"),
524+
codice_lut_path(descriptor="l2-lo-onboard-mpq-cal"),
527525
]
528526

529527
processed_l2_ds = process_codice_l2("lo-direct-events", ProcessingInputCollection())
@@ -538,7 +536,9 @@ def test_codice_l2_lo_de(mock_get_file_paths, codice_lut_path):
538536
f"_{VALIDATION_FILE_VERSION}.cdf"
539537
)
540538
)
539+
541540
l2_val_data = load_cdf(l2_val_data)
541+
542542
for variable in l2_val_data.data_vars:
543543
if variable in ["spin_angle"]:
544544
# TODO remove this block when joey fixes spin_angle calculation
@@ -555,11 +555,11 @@ def test_codice_l2_lo_de(mock_get_file_paths, codice_lut_path):
555555
l2_val_data[variable].values,
556556
rtol=5e-5,
557557
err_msg=f"Mismatch in variable '{variable}'",
558+
equal_nan=True,
558559
)
559-
560560
processed_l2_ds.attrs["Data_version"] = "001"
561561
assert processed_l2_ds.attrs["Logical_source"] == "imap_codice_l2_lo-direct-events"
562562
file = write_cdf(processed_l2_ds)
563-
errors = CDFValidator().validate_raw(file)
563+
errors = CDFValidator().validate(file)
564564
assert not errors
565565
load_cdf(file)

0 commit comments

Comments
 (0)