Skip to content

Commit a8a8a79

Browse files
authored
singles counters (#2514)
1 parent 1dfbad1 commit a8a8a79

File tree

3 files changed

+87
-6
lines changed

3 files changed

+87
-6
lines changed

imap_processing/codice/codice_l1b.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ def convert_to_rates(dataset: xr.Dataset, descriptor: str) -> np.ndarray:
4141
rates_data : np.ndarray
4242
The converted data array.
4343
"""
44+
# No uncertainty calculation for diagnostic counters products
45+
calculate_unc = False if "counters" in descriptor else True
4446
# Variables to convert based on descriptor
4547
variables_to_convert = getattr(
4648
constants, f"{descriptor.upper().replace('-', '_')}_VARIABLE_NAMES"
@@ -139,12 +141,13 @@ def convert_to_rates(dataset: xr.Dataset, descriptor: str) -> np.ndarray:
139141
# Carry over attrs and update as needed
140142
dataset[variable].attrs["UNITS"] = "counts/s"
141143

142-
# Uncertainty calculation
143-
unc_variable = f"unc_{variable}"
144-
dataset[unc_variable].data = (
145-
dataset[unc_variable].astype(np.float64) / denominator
146-
)
147-
dataset[unc_variable].attrs["UNITS"] = "1/s"
144+
if calculate_unc:
145+
# Uncertainty calculation
146+
unc_variable = f"unc_{variable}"
147+
dataset[unc_variable].data = (
148+
dataset[unc_variable].astype(np.float64) / denominator
149+
)
150+
dataset[unc_variable].attrs["UNITS"] = "1/s"
148151

149152
# Drop spin_period
150153
if "spin_period" in dataset.variables:

imap_processing/codice/constants.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -798,6 +798,8 @@
798798
"cnoplus",
799799
]
800800

801+
LO_COUNTERS_SINGLES_VARIABLE_NAMES = ["apd_singles"]
802+
HI_COUNTERS_SINGLES_VARIABLE_NAMES = ["tcr", "ssdo", "stssd"]
801803
# Various configurations to support L1b processing of individual data products
802804
# Much of these are described in the algorithm document in chapter 11 ("Data
803805
# Level 1B")

imap_processing/tests/codice/test_codice_l1b.py

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -392,3 +392,79 @@ def test_l1b_sw_lo_priorities(mock_get_file_paths, codice_lut_path):
392392
cdf_file.name
393393
== f"imap_codice_l1b_lo-sw-priority_{VALIDATION_FILE_DATE}_v999.cdf"
394394
)
395+
396+
397+
@patch("imap_data_access.processing_input.ProcessingInputCollection.get_file_paths")
398+
def test_lo_counters_singles(mock_get_file_paths, codice_lut_path):
399+
"""Tests l1b lo-counters-singles."""
400+
mock_get_file_paths.side_effect = [
401+
codice_lut_path(descriptor="lo-counters-singles", data_type="l0"),
402+
codice_lut_path(descriptor="l1a-sci-lut"),
403+
]
404+
405+
l1a_data = process_l1a(dependency=ProcessingInputCollection())[0]
406+
l1a_file_path = write_cdf(l1a_data)
407+
processed_data = process_codice_l1b(file_path=l1a_file_path)
408+
409+
# Validation
410+
val_path = (
411+
imap_module_directory
412+
/ "tests/codice/data/l1b_validation/"
413+
/ (
414+
f"imap_codice_l1b_lo-counters-singles_{VALIDATION_FILE_DATE}"
415+
f"_{VALIDATION_FILE_VERSION}.cdf"
416+
)
417+
)
418+
val_data = load_cdf(val_path)
419+
for variable in val_data.data_vars:
420+
np.testing.assert_allclose(
421+
processed_data[variable].values,
422+
val_data[variable].values,
423+
rtol=1e-5,
424+
err_msg=f"Mismatch in variable '{variable}'",
425+
)
426+
427+
processed_data.attrs["Data_version"] = "001"
428+
cdf_file = write_cdf(processed_data, terminate_on_warning=True)
429+
assert (
430+
cdf_file.name
431+
== f"imap_codice_l1b_lo-counters-singles_{VALIDATION_FILE_DATE}_v001.cdf"
432+
)
433+
434+
435+
@patch("imap_data_access.processing_input.ProcessingInputCollection.get_file_paths")
436+
def test_hi_counters_singles(mock_get_file_paths, codice_lut_path):
437+
"""Tests l1b hi-counters-singles."""
438+
mock_get_file_paths.side_effect = [
439+
codice_lut_path(descriptor="hi-counters-singles", data_type="l0"),
440+
codice_lut_path(descriptor="l1a-sci-lut"),
441+
]
442+
443+
l1a_data = process_l1a(dependency=ProcessingInputCollection())[0]
444+
l1a_file_path = write_cdf(l1a_data)
445+
processed_data = process_codice_l1b(file_path=l1a_file_path)
446+
447+
# Validation
448+
val_path = (
449+
imap_module_directory
450+
/ "tests/codice/data/l1b_validation/"
451+
/ (
452+
f"imap_codice_l1b_hi-counters-singles_{VALIDATION_FILE_DATE}"
453+
f"_{VALIDATION_FILE_VERSION}.cdf"
454+
)
455+
)
456+
val_data = load_cdf(val_path)
457+
for variable in val_data.data_vars:
458+
np.testing.assert_allclose(
459+
processed_data[variable].values,
460+
val_data[variable].values,
461+
rtol=1.2e-5,
462+
err_msg=f"Mismatch in variable '{variable}'",
463+
)
464+
465+
processed_data.attrs["Data_version"] = "001"
466+
cdf_file = write_cdf(processed_data, terminate_on_warning=True)
467+
assert (
468+
cdf_file.name
469+
== f"imap_codice_l1b_hi-counters-singles_{VALIDATION_FILE_DATE}_v001.cdf"
470+
)

0 commit comments

Comments
 (0)