From 88e510dd3f1464ee64e92944f92a922c80657d89 Mon Sep 17 00:00:00 2001 From: Luisa Coakley Date: Wed, 14 Oct 2026 10:22:36 -0600 Subject: [PATCH 1/3] add message and return if there is no data to process for swapi l1 --- imap_processing/swapi/l1/swapi_l1.py | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/imap_processing/swapi/l1/swapi_l1.py b/imap_processing/swapi/l1/swapi_l1.py index b552caa27f..8e535ef0a4 100644 --- a/imap_processing/swapi/l1/swapi_l1.py +++ b/imap_processing/swapi/l1/swapi_l1.py @@ -429,7 +429,7 @@ def process_sweep_data(full_sweep_sci: xr.Dataset, cem_prefix: str) -> xr.Datase def process_swapi_science( sci_dataset: xr.Dataset, hk_dataset: xr.Dataset -) -> xr.Dataset: +) -> xr.Dataset | None: """ Will process SWAPI science data and create CDF file. @@ -442,8 +442,9 @@ def process_swapi_science( Returns ------- - dataset : xarray.Dataset - Dataset. + dataset : xarray.Dataset, optional + Dataset or None. If there is no HVSCI mode found in any + science packets, then return None. """ # ==================================================== # Step 1: Filter full cycle data @@ -456,6 +457,10 @@ def process_swapi_science( good_data_indices = filter_good_data(full_sweep_sci) good_sweep_sci = full_sweep_sci.isel({"epoch": good_data_indices}) + if good_sweep_sci.dims["epoch"] == 0: + logger.info("No data to process: no HVSCI mode found in any science packets.") + return None + # ==================================================== # Step 2: Process good sweep data # ==================================================== @@ -754,7 +759,9 @@ def process_swapi_science( return dataset -def swapi_l1(dependencies: ProcessingInputCollection, descriptor: str) -> xr.Dataset: +def swapi_l1( + dependencies: ProcessingInputCollection, descriptor: str +) -> list[xr.Dataset]: """ Will process SWAPI level 0 data to level 1. @@ -768,7 +775,7 @@ def swapi_l1(dependencies: ProcessingInputCollection, descriptor: str) -> xr.Dat Returns ------- - processed_data : xarray.Dataset + processed_data : list[xarray.Dataset] Set of processed data. """ xtce_definition = ( @@ -800,7 +807,7 @@ def swapi_l1(dependencies: ProcessingInputCollection, descriptor: str) -> xr.Dat sci_dataset = process_swapi_science( l0_unpacked_dict[SWAPIAPID.SWP_SCI], l1b_hk_ds ) - return [sci_dataset] + return [sci_dataset] if sci_dataset is not None else [] elif descriptor == "hk": logger.info(f"Processing HK data for {l0_files[0]}.") From 15c6f68c2849ec119b40154359e232a5bd4e3df7 Mon Sep 17 00:00:00 2001 From: Luisa Coakley Date: Wed, 14 Oct 2026 10:54:38 -0600 Subject: [PATCH 2/3] add test --- imap_processing/swapi/l1/swapi_l1.py | 2 +- imap_processing/tests/swapi/test_swapi_l1.py | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/imap_processing/swapi/l1/swapi_l1.py b/imap_processing/swapi/l1/swapi_l1.py index 8e535ef0a4..65c83c29c4 100644 --- a/imap_processing/swapi/l1/swapi_l1.py +++ b/imap_processing/swapi/l1/swapi_l1.py @@ -457,7 +457,7 @@ def process_swapi_science( good_data_indices = filter_good_data(full_sweep_sci) good_sweep_sci = full_sweep_sci.isel({"epoch": good_data_indices}) - if good_sweep_sci.dims["epoch"] == 0: + if good_sweep_sci.sizes["epoch"] == 0: logger.info("No data to process: no HVSCI mode found in any science packets.") return None diff --git a/imap_processing/tests/swapi/test_swapi_l1.py b/imap_processing/tests/swapi/test_swapi_l1.py index 1054b1ecb3..7d121ceaf7 100644 --- a/imap_processing/tests/swapi/test_swapi_l1.py +++ b/imap_processing/tests/swapi/test_swapi_l1.py @@ -242,3 +242,14 @@ def second_get_file_paths_side_effect(descriptor): cdf_filename = "imap_swapi_l1_sci_20240924_v001.0001.cdf" cdf_path = write_cdf(processed_data[0]) assert cdf_path.name == cdf_filename + + +def test_process_swapi_no_valid_data(decom_test_data): + """Test process swapi science""" + ds_data = decom_test_data[SWAPIAPID.SWP_SCI] + + # make all modes invalid. + ds_data["mode"].data = np.zeros(ds_data["plan_id"].data.shape) * -1 + processed_data = process_swapi_science(ds_data, decom_test_data[SWAPIAPID.SWP_HK]) + # process_swapi_science should return None if there is no valid data to process + assert processed_data is None From 7f1bd2e4aaf9a9447d7e5d8846c7be153ec6dd6a Mon Sep 17 00:00:00 2001 From: Luisa Coakley Date: Mon, 19 Oct 2026 10:02:44 -0600 Subject: [PATCH 3/3] fix docstring --- imap_processing/swapi/l1/swapi_l1.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/imap_processing/swapi/l1/swapi_l1.py b/imap_processing/swapi/l1/swapi_l1.py index 65c83c29c4..d407160d62 100644 --- a/imap_processing/swapi/l1/swapi_l1.py +++ b/imap_processing/swapi/l1/swapi_l1.py @@ -442,7 +442,7 @@ def process_swapi_science( Returns ------- - dataset : xarray.Dataset, optional + dataset : xarray.Dataset or None Dataset or None. If there is no HVSCI mode found in any science packets, then return None. """