Skip to content
Closed
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
2 changes: 1 addition & 1 deletion imap_processing/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
25 changes: 11 additions & 14 deletions imap_processing/swe/l1a/swe_l1a.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand All @@ -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
-------
Expand All @@ -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
Expand All @@ -56,17 +54,17 @@ 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"))
l1a_hk_ds["epoch"].attrs.update(epoch_attrs)
# 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(
Expand All @@ -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 []
6 changes: 3 additions & 3 deletions imap_processing/tests/swe/test_swe_l1a.py
Original file line number Diff line number Diff line change
Expand Up @@ -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])

Expand All @@ -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])

Expand All @@ -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])

Expand Down
2 changes: 1 addition & 1 deletion imap_processing/tests/swe/test_swe_l1b.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]

Expand Down
4 changes: 2 additions & 2 deletions imap_processing/tests/swe/test_swe_l2.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
Loading