diff --git a/imap_processing/cli.py b/imap_processing/cli.py index bdb8153711..67be9a92a2 100644 --- a/imap_processing/cli.py +++ b/imap_processing/cli.py @@ -1537,7 +1537,7 @@ def do_processing( "L0 data and time kernels." ) science_files = dependencies.get_file_paths(source="swe") - datasets = swe_l1a(str(science_files[0])) + datasets = swe_l1a(str(science_files[0]), self.descriptor) # Right now, we only process science data. Therefore, # we expect only one dataset to be returned. diff --git a/imap_processing/swe/l1a/swe_l1a.py b/imap_processing/swe/l1a/swe_l1a.py index 45e0f20238..65910dd501 100644 --- a/imap_processing/swe/l1a/swe_l1a.py +++ b/imap_processing/swe/l1a/swe_l1a.py @@ -15,7 +15,7 @@ logger = logging.getLogger(__name__) -def swe_l1a(packet_file: str) -> xr.Dataset: +def swe_l1a(packet_file: str, descriptor: str) -> xr.Dataset: """ Will process SWE l0 data into l1a data. @@ -27,6 +27,8 @@ def swe_l1a(packet_file: str) -> xr.Dataset: ---------- packet_file : str Path where the raw packet file is stored. + descriptor : str + The descriptor of the data to be processed. Returns ------- @@ -40,13 +42,9 @@ def swe_l1a(packet_file: str) -> xr.Dataset: packet_file, xtce_document, use_derived_value=False ) - processed_data = [] - - if SWEAPID.SWE_SCIENCE in datasets_by_apid: + if SWEAPID.SWE_SCIENCE in datasets_by_apid and descriptor == "sci": logger.info("Processing SWE science data.") - processed_data.append( - swe_science(l0_dataset=datasets_by_apid[SWEAPID.SWE_SCIENCE]) - ) + return [(swe_science(l0_dataset=datasets_by_apid[SWEAPID.SWE_SCIENCE]))] # Process non-science data # Define minimal CDF attrs for the non science dataset @@ -56,7 +54,7 @@ def swe_l1a(packet_file: str) -> xr.Dataset: non_science_attrs = imap_attrs.get_variable_attributes("non_science_attrs") epoch_attrs = imap_attrs.get_variable_attributes("epoch", check_schema=False) - if SWEAPID.SWE_APP_HK in datasets_by_apid: + if SWEAPID.SWE_APP_HK in datasets_by_apid and descriptor == "hk": logger.info("Processing SWE housekeeping data.") l1a_hk_ds = datasets_by_apid[SWEAPID.SWE_APP_HK] l1a_hk_ds.attrs.update(imap_attrs.get_global_attributes("imap_swe_l1a_hk")) @@ -64,9 +62,9 @@ def swe_l1a(packet_file: str) -> xr.Dataset: # Add attrs to HK data variables for var_name in l1a_hk_ds.data_vars: l1a_hk_ds[var_name].attrs.update(non_science_attrs) - processed_data.append(l1a_hk_ds) + return [l1a_hk_ds] - if SWEAPID.SWE_CEM_RAW in datasets_by_apid: + if SWEAPID.SWE_CEM_RAW in datasets_by_apid and descriptor == "cem-raw": logger.info("Processing SWE CEM raw data.") cem_raw_ds = datasets_by_apid[SWEAPID.SWE_CEM_RAW] cem_raw_ds.attrs.update( @@ -77,9 +75,8 @@ def swe_l1a(packet_file: str) -> xr.Dataset: # Add attrs to CEM raw data variables for var_name in cem_raw_ds.data_vars: cem_raw_ds[var_name].attrs.update(non_science_attrs) - processed_data.append(cem_raw_ds) + return [cem_raw_ds] - if len(processed_data) == 0: - logger.info("Data contains unknown APID.") + logger.info("Data contains unknown APID.") - return processed_data + return [] diff --git a/imap_processing/tests/swe/test_swe_l1a.py b/imap_processing/tests/swe/test_swe_l1a.py index 359cbc92d7..9f67fff0fb 100644 --- a/imap_processing/tests/swe/test_swe_l1a.py +++ b/imap_processing/tests/swe/test_swe_l1a.py @@ -5,7 +5,7 @@ def test_cdf_creation(): test_data_path = "tests/swe/l0_data/2024051010_SWE_SCIENCE_packet.bin" - processed_data = swe_l1a(imap_module_directory / test_data_path) + processed_data = swe_l1a(imap_module_directory / test_data_path, "sci") cem_raw_cdf_filepath = write_cdf(processed_data[0]) @@ -14,7 +14,7 @@ def test_cdf_creation(): def test_cdf_creation_hk(): test_data_path = "tests/swe/l0_data/2024051010_SWE_HK_packet.bin" - processed_data = swe_l1a(imap_module_directory / test_data_path) + processed_data = swe_l1a(imap_module_directory / test_data_path, "hk") hk_cdf_filepath = write_cdf(processed_data[0]) @@ -23,7 +23,7 @@ def test_cdf_creation_hk(): def test_cdf_creation_cem_raw(): test_data_path = "tests/swe/l0_data/2024051011_SWE_CEM_RAW_packet.bin" - processed_data = swe_l1a(imap_module_directory / test_data_path) + processed_data = swe_l1a(imap_module_directory / test_data_path, "cem-raw") cem_raw_cdf_filepath = write_cdf(processed_data[0]) diff --git a/imap_processing/tests/swe/test_swe_l1b.py b/imap_processing/tests/swe/test_swe_l1b.py index cb9addeff3..b8440276bd 100644 --- a/imap_processing/tests/swe/test_swe_l1b.py +++ b/imap_processing/tests/swe/test_swe_l1b.py @@ -166,7 +166,7 @@ def test_get_checker_board_pattern(): def test_swe_l1b(mock_get_file_paths, l1b_validation_df): """Test that CDF file is created and has the correct name.""" test_data_path = "tests/swe/l0_data/2024051010_SWE_SCIENCE_packet.bin" - l1a_datasets = swe_l1a(imap_module_directory / test_data_path) + l1a_datasets = swe_l1a(imap_module_directory / test_data_path, "sci") l1b_input = l1a_datasets[0] diff --git a/imap_processing/tests/swe/test_swe_l2.py b/imap_processing/tests/swe/test_swe_l2.py index 9a8f880c9c..66d3bdea04 100644 --- a/imap_processing/tests/swe/test_swe_l2.py +++ b/imap_processing/tests/swe/test_swe_l2.py @@ -291,7 +291,7 @@ def test_swe_l2_15sec( use_fake_spin_data_for_time(data_start_time, data_end_time) test_data_path = "tests/swe/l0_data/2024051010_SWE_SCIENCE_packet.bin" - l1a_datasets = swe_l1a(imap_module_directory / test_data_path) + l1a_datasets = swe_l1a(imap_module_directory / test_data_path, "sci") l1a_ds = l1a_datasets[0] l1a_ds.attrs["Data_version"] = "000" l1a_cdf_filepath = write_cdf(l1a_ds) @@ -403,7 +403,7 @@ def test_swe_l2_14_6sec( use_fake_spin_data_for_time(data_start_time, data_end_time, spin_period=14.6) test_data_path = "tests/swe/l0_data/2024051010_SWE_SCIENCE_packet.bin" - l1a_datasets = swe_l1a(imap_module_directory / test_data_path) + l1a_datasets = swe_l1a(imap_module_directory / test_data_path, "sci") l1a_ds = l1a_datasets[0] l1a_ds.attrs["Data_version"] = "000" l1a_cdf_filepath = write_cdf(l1a_ds)