Skip to content
Merged
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
19 changes: 13 additions & 6 deletions imap_processing/swapi/l1/swapi_l1.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand All @@ -442,8 +442,9 @@ def process_swapi_science(

Returns
-------
dataset : xarray.Dataset
Dataset.
dataset : xarray.Dataset or None
Dataset or None. If there is no HVSCI mode found in any
science packets, then return None.
"""
# ====================================================
# Step 1: Filter full cycle data
Expand All @@ -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.sizes["epoch"] == 0:
logger.info("No data to process: no HVSCI mode found in any science packets.")
return None

# ====================================================
# Step 2: Process good sweep data
# ====================================================
Expand Down Expand Up @@ -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.

Expand All @@ -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 = (
Expand Down Expand Up @@ -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]}.")
Expand Down
11 changes: 11 additions & 0 deletions imap_processing/tests/swapi/test_swapi_l1.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Loading