Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated CoDICE XTCE files from imap_xtce tool #812

Merged
Merged
Show file tree
Hide file tree
Changes from 2 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
16 changes: 13 additions & 3 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 @@ -37,9 +36,20 @@ def decom_packets(packet_file: Path) -> dict[int, xr.Dataset]:
packets : 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 test housekeeping packet has LAST_OPCODE=0, and the
# telemetry definition "STATES" tab doesn't allow for a 0 value for
# this. Need to figure out if the test packet is bad, or the telemetry
# definition is wrong.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is an interesting case. Does an Enumeration need to exist for every possible value or should space_packet_parser just return the raw_value here and not decode anything rather than raising an error? Gavin might have some insight here as well.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From what I understand from Gavin's comment in the xtce slack channel, it sounds like his preference would be to explicitly define what a value of 0 means in the packet definition file. I will ask Joey about this in our next tagup.

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}"
)
packets: 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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you return the dataset now without assigning since it's not packets anymore? or this file itself might go away like mine did for SWE and SWAPI once your HK issue is fixed.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good call, this should really be called datasets now instead of packets. But I think I will keep the module around, at least for now, as a way to distinguish L0 code from L1 code.

9 changes: 2 additions & 7 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,10 +511,7 @@ 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)
packets = decom_packets(file_path)

for apid in packets:
packet = packets[apid]
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
Loading