Skip to content

Commit

Permalink
Updated CoDICE XTCE files from imap_xtce tool (#812)
Browse files Browse the repository at this point in the history
* Using new imap_xtce tool, generated new CoDICE packet definition
* Now using codice_l0.decom_packets as only place to perform decom
  • Loading branch information
bourque committed Sep 11, 2024
1 parent 725fe4b commit ebea6cc
Show file tree
Hide file tree
Showing 19 changed files with 5,097 additions and 2,661 deletions.
19 changes: 14 additions & 5 deletions imap_processing/codice/codice_l0.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
import xarray as xr

from imap_processing import imap_module_directory
from imap_processing.codice import constants
from imap_processing.utils import packet_file_to_datasets


Expand All @@ -34,12 +33,22 @@ def decom_packets(packet_file: Path) -> dict[int, xr.Dataset]:
Returns
-------
packets : dict[int, xarray.Dataset]
datasets : dict[int, xarray.Dataset]
Mapping from apid to ``xarray`` dataset, one dataset per apid.
"""
# TODO: Currently need to use the 'old' packet definition for housekeeping
# because the simulated housekeeping data being used has various
# mis-matches from the telemetry definition. This may be updated
# once new simulated housekeeping data are acquired.
if "hskp" in str(packet_file):
xtce_filename = "P_COD_NHK.xml"
else:
xtce_filename = "codice_packet_definition.xml"
xtce_packet_definition = Path(
f"{imap_module_directory}/codice/packet_definitions/{constants.PACKET_TO_XTCE_MAPPING[packet_file.name]}"
f"{imap_module_directory}/codice/packet_definitions/{xtce_filename}"
)
datasets: dict[int, xr.Dataset] = packet_file_to_datasets(
packet_file, xtce_packet_definition
)
packets = packet_file_to_datasets(packet_file, xtce_packet_definition)

return packets
return datasets
23 changes: 9 additions & 14 deletions imap_processing/codice/codice_l1a.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,13 @@
from imap_processing import imap_module_directory
from imap_processing.cdf.imap_cdf_manager import ImapCdfAttributes
from imap_processing.codice import constants
from imap_processing.codice.codice_l0 import decom_packets
from imap_processing.codice.decompress import decompress
from imap_processing.codice.utils import CODICEAPID
from imap_processing.utils import packet_file_to_datasets

logger = logging.getLogger(__name__)
logger.setLevel(logging.INFO)

# TODO: In decommutation, how to have a variable length data and then a checksum
# after it? (Might be fixed with new XTCE script updates)
# TODO: Add support for decomming multiple APIDs from a single file
# TODO: Add these as variables in CDF: SPIN_PERIOD, ST_BIAS_GAIN_MODE,
# SW_BIAS_GAIN_MODE, RGFO_HALF_SPIN, NSO_HALF_SPIN, DATA_QUALITY
Expand Down Expand Up @@ -513,33 +511,30 @@ def process_codice_l1a(file_path: Path, data_version: str) -> xr.Dataset:
The ``xarray`` dataset containing the science data and supporting metadata.
"""
# Decom the packets, group data by APID, and sort by time
xtce_packet_definition = Path(
f"{imap_module_directory}/codice/packet_definitions/{constants.PACKET_TO_XTCE_MAPPING[file_path.name]}"
)
packets = packet_file_to_datasets(file_path, xtce_packet_definition)
datasets = decom_packets(file_path)

for apid in packets:
packet = packets[apid]
for apid in datasets:
packet_dataset = datasets[apid]
logger.info(f"\nProcessing {CODICEAPID(apid).name} packet")

if apid == CODICEAPID.COD_NHK:
dataset = create_hskp_dataset(packet, data_version)
dataset = create_hskp_dataset(packet_dataset, data_version)

elif apid in [CODICEAPID.COD_LO_PHA, CODICEAPID.COD_HI_PHA]:
dataset = create_event_dataset(apid, packet, data_version)
dataset = create_event_dataset(apid, packet_dataset, data_version)

elif apid in constants.APIDS_FOR_SCIENCE_PROCESSING:
# Extract the data
science_values = packet.data.data[0]
science_values = packet_dataset.data.data[0]

# Get the four "main" parameters for processing
table_id, plan_id, plan_step, view_id = get_params(packet)
table_id, plan_id, plan_step, view_id = get_params(packet_dataset)

# Run the pipeline to create a dataset for the product
pipeline = CoDICEL1aPipeline(table_id, plan_id, plan_step, view_id)
pipeline.configure_data_products(apid)
pipeline.unpack_science_data(science_values)
dataset = pipeline.create_science_dataset(packet, data_version)
dataset = pipeline.create_science_dataset(packet_dataset, data_version)

logger.info(f"\nFinal data product:\n{dataset}\n")

Expand Down
19 changes: 0 additions & 19 deletions imap_processing/codice/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,28 +14,9 @@

# TODO: What to do in the case of a value of 255 in LOSSY_A and LOSSY_B
# compression?
# TODO: Improve PACKET_TO_XTCE_MAPPING to not have hard-coded dates/versions

from imap_processing.codice.utils import CODICEAPID, CoDICECompression

PACKET_TO_XTCE_MAPPING = {
"imap_codice_l0_hi-counters-aggregated_20240429_v001.pkts": "P_COD_HI_INST_COUNTS_AGGREGATED.xml", # noqa
"imap_codice_l0_hi-counters-singles_20240429_v001.pkts": "P_COD_HI_INST_COUNTS_SINGLES.xml", # noqa
"imap_codice_l0_hi-omni_20240429_v001.pkts": "P_COD_HI_OMNI_SPECIES_COUNTS.xml",
"imap_codice_l0_hi-sectored_20240429_v001.pkts": "P_COD_HI_SECT_SPECIES_COUNTS.xml",
"imap_codice_l0_hi-pha_20240429_v001.pkts": "P_COD_HI_PHA.xml",
"imap_codice_l0_hskp_20100101_v001.pkts": "P_COD_NHK.xml",
"imap_codice_l0_lo-counters-aggregated_20240429_v001.pkts": "P_COD_LO_INST_COUNTS_AGGREGATED.xml", # noqa
"imap_codice_l0_lo-counters-singles_20240429_v001.pkts": "P_COD_LO_INST_COUNTS_SINGLES.xml", # noqa
"imap_codice_l0_lo-sw-angular_20240429_v001.pkts": "P_COD_LO_SW_ANGULAR_COUNTS.xml",
"imap_codice_l0_lo-nsw-angular_20240429_v001.pkts": "P_COD_LO_NSW_ANGULAR_COUNTS.xml", # noqa
"imap_codice_l0_lo-sw-priority_20240429_v001.pkts": "P_COD_LO_SW_PRIORITY_COUNTS.xml", # noqa
"imap_codice_l0_lo-nsw-priority_20240429_v001.pkts": "P_COD_LO_NSW_PRIORITY_COUNTS.xml", # noqa
"imap_codice_l0_lo-sw-species_20240429_v001.pkts": "P_COD_LO_SW_SPECIES_COUNTS.xml",
"imap_codice_l0_lo-nsw-species_20240429_v001.pkts": "P_COD_LO_NSW_SPECIES_COUNTS.xml", # noqa
"imap_codice_l0_lo-pha_20240429_v001.pkts": "P_COD_LO_PHA.xml",
}

APIDS_FOR_SCIENCE_PROCESSING = [
CODICEAPID.COD_HI_INST_COUNTS_AGGREGATED,
CODICEAPID.COD_HI_INST_COUNTS_SINGLES,
Expand Down

This file was deleted.

Loading

0 comments on commit ebea6cc

Please sign in to comment.