Skip to content

Commit

Permalink
Feedback changes
Browse files Browse the repository at this point in the history
  • Loading branch information
tech3371 committed Jul 31, 2024
1 parent 0b90194 commit 779880d
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 39 deletions.
12 changes: 2 additions & 10 deletions imap_processing/swapi/l2/swapi_l2.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import xarray as xr

from imap_processing.cdf.imap_cdf_manager import ImapCdfAttributes
from imap_processing.swapi.swapi_utils import SWAPIAPID

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -41,12 +40,6 @@ def swapi_l2(l1_dataset: xr.Dataset, data_version: str) -> xr.Dataset:
data : xarray.Dataset
Processed data to L2.
"""
apid = int(l1_dataset.attrs["Apid"])
# Right now, we don't process any other apid besides science packet
# to L2
if apid != SWAPIAPID.SWP_SCI:
raise ValueError(f"APID {apid} is not supported for L2 processing")

# Load the CDF attributes
cdf_manager = ImapCdfAttributes()
cdf_manager.add_instrument_global_attrs("swapi")
Expand All @@ -61,9 +54,8 @@ def swapi_l2(l1_dataset: xr.Dataset, data_version: str) -> xr.Dataset:
"swp_scem_flags",
"swp_coin_flags",
]
l2_dataset = l1_dataset[l1_data_keys].copy()
# Copy over attributes
l2_dataset.attrs = l1_dataset.attrs
l2_dataset = l1_dataset[l1_data_keys]

# Update L2 specific attributes
l2_dataset.attrs["Data_version"] = data_version
l2_global_attrs = cdf_manager.get_global_attributes("imap_swapi_l2_sci")
Expand Down
16 changes: 16 additions & 0 deletions imap_processing/tests/swapi/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import pytest


@pytest.fixture(scope="session")
def swapi_test_data_path(imap_tests_path):
return imap_tests_path / "swapi/"


@pytest.fixture(scope="session")
def swapi_l0_test_data_path(swapi_test_data_path):
return swapi_test_data_path / "l0_data/"


@pytest.fixture(scope="session")
def swapi_l0_validation_data_path(swapi_test_data_path):
return swapi_test_data_path / "l0_validation_data/"
24 changes: 10 additions & 14 deletions imap_processing/tests/swapi/test_swapi_decom.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,15 @@


@pytest.fixture(scope="session")
def decom_test_data():
def decom_test_data(swapi_l0_test_data_path):
"""Read test data from file"""
test_folder_path = "tests/swapi/l0_data"
packet_files = list(imap_module_directory.glob(f"{test_folder_path}/*.pkts"))
test_file = "imap_swapi_l0_raw_20231012_v001.pkts"
packet_file = imap_module_directory / swapi_l0_test_data_path / test_file
packet_definition = (
f"{imap_module_directory}/swapi/packet_definitions/swapi_packet_definition.xml"
)
data_list = []
for packet_file in packet_files:
data_list.extend(decom_packets(packet_file, packet_definition))
data_list.extend(decom_packets(packet_file, packet_definition))
return data_list


Expand All @@ -39,12 +38,11 @@ def test_number_of_packets(decom_test_data):
assert len(aut_packets) == expected_aut_packets


def test_swapi_sci_data(decom_test_data):
def test_swapi_sci_data(decom_test_data, swapi_l0_validation_data_path):
"""This test and validate raw data of SWAPI raw science data."""
# read validation data
test_data_path = imap_module_directory / "tests/swapi/l0_validation_data"
raw_validation_data = pd.read_csv(
test_data_path / "idle_export_eu.SWP_SCI_20231012_125245.csv",
swapi_l0_validation_data_path / "idle_export_eu.SWP_SCI_20231012_125245.csv",
index_col="SHCOARSE",
)

Expand Down Expand Up @@ -77,12 +75,11 @@ def test_swapi_sci_data(decom_test_data):
)


def test_swapi_hk_data(decom_test_data):
def test_swapi_hk_data(decom_test_data, swapi_l0_validation_data_path):
"""This test and validate raw data of SWAPI raw housekeeping data."""
# read validation data
test_data_path = imap_module_directory / "tests/swapi/l0_validation_data"
raw_validation_data = pd.read_csv(
test_data_path / "idle_export_raw.SWP_HK_20231012_125245.csv",
swapi_l0_validation_data_path / "idle_export_raw.SWP_HK_20231012_125245.csv",
index_col="SHCOARSE",
)

Expand Down Expand Up @@ -113,12 +110,11 @@ def test_swapi_hk_data(decom_test_data):
assert value.raw_value == validation_data[key]


def test_swapi_aut_data(decom_test_data):
def test_swapi_aut_data(decom_test_data, swapi_l0_validation_data_path):
"""This test and validate raw data of SWAPI raw autonomy data."""
# read validation data
test_data_path = imap_module_directory / "tests/swapi/l0_validation_data"
raw_validation_data = pd.read_csv(
test_data_path / "idle_export_raw.SWP_AUT_20231012_125245.csv",
swapi_l0_validation_data_path / "idle_export_raw.SWP_AUT_20231012_125245.csv",
index_col="SHCOARSE",
)

Expand Down
15 changes: 6 additions & 9 deletions imap_processing/tests/swapi/test_swapi_l1.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@


@pytest.fixture(scope="session")
def decom_test_data():
def decom_test_data(swapi_l0_test_data_path):
"""Read test data from file"""
test_file = "tests/swapi/l0_data/imap_swapi_l0_raw_20231012_v001.pkts"
packet_files = imap_module_directory / test_file
test_file = "imap_swapi_l0_raw_20231012_v001.pkts"
packet_files = imap_module_directory / swapi_l0_test_data_path / test_file
packet_definition = (
f"{imap_module_directory}/swapi/packet_definitions/swapi_packet_definition.xml"
)
Expand Down Expand Up @@ -316,13 +316,10 @@ def test_process_swapi_science(decom_test_data):
assert cdf_path.name == cdf_filename


def test_swapi_l1_cdf():
def test_swapi_l1_cdf(swapi_l0_test_data_path):
"""Test housekeeping processing and CDF file creation"""
l0_data_path = (
f"{imap_module_directory}/tests/swapi/l0_data/"
"imap_swapi_l0_raw_20231012_v001.pkts"
)
processed_data = swapi_l1(l0_data_path, data_version="v001")
test_packet_file = swapi_l0_test_data_path / "imap_swapi_l0_raw_20231012_v001.pkts"
processed_data = swapi_l1(test_packet_file, data_version="v001")

assert processed_data[0].attrs["Apid"] == f"{SWAPIAPID.SWP_SCI}"
assert processed_data[0].attrs["Plan_id"] == "0"
Expand Down
8 changes: 2 additions & 6 deletions imap_processing/tests/swapi/test_swapi_l2.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,13 @@
import numpy as np

from imap_processing import imap_module_directory
from imap_processing.cdf.utils import write_cdf
from imap_processing.swapi.l1.swapi_l1 import swapi_l1
from imap_processing.swapi.l2.swapi_l2 import TIME_PER_BIN, swapi_l2


def test_swapi_l2_cdf():
def test_swapi_l2_cdf(swapi_l0_test_data_path):
"""Test housekeeping processing and CDF file creation"""
l0_data_path = (
f"{imap_module_directory}/tests/swapi/l0_data/"
"imap_swapi_l0_raw_20231012_v001.pkts"
)
l0_data_path = swapi_l0_test_data_path / "imap_swapi_l0_raw_20231012_v001.pkts"
processed_data = swapi_l1(l0_data_path, data_version="v001")
l1_dataset = processed_data[0]

Expand Down

0 comments on commit 779880d

Please sign in to comment.