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

CoDICE L1a lo-sw-priority-counts #540

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
17 changes: 13 additions & 4 deletions imap_processing/codice/cdf_attrs.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,20 +55,29 @@
instrument_base=codice_base,
)

l1a_lo_sw_species_attrs = GlobalDataLevelAttrs(
l1a_lo_sw_species_counts_attrs = GlobalDataLevelAttrs(
data_type="L1A_SCI->Level-1A Science Data",
logical_source="imap_codice_l1a_lo-sw-species-counts",
logical_source_desc=(
"IMAP Mission CoDICE Instrument Level-1A Lo Sunward Species Data"
"IMAP Mission CoDICE Instrument Level-1A Lo Sunward Species Counts Data"
),
instrument_base=codice_base,
)

l1a_lo_nsw_species_attrs = GlobalDataLevelAttrs(
l1a_lo_nsw_species_counts_attrs = GlobalDataLevelAttrs(
data_type="L1A_SCI->Level-1A Science Data",
logical_source="imap_codice_l1a_lo-nsw-species-counts",
logical_source_desc=(
"IMAP Mission CoDICE Instrument Level-1A Lo Non-sunward Species Data"
"IMAP Mission CoDICE Instrument Level-1A Lo Non-sunward Species Counts Data"
),
instrument_base=codice_base,
)

l1a_lo_sw_priority_counts_attrs = GlobalDataLevelAttrs(
data_type="L1A_SCI->Level-1A Science Data",
logical_source="imap_codice_l1a_lo-sw-priority-counts",
logical_source_desc=(
"IMAP Mission CoDICE Instrument Level-1A Lo Sunward Priority Counts Data"
),
instrument_base=codice_base,
)
Expand Down
1 change: 1 addition & 0 deletions imap_processing/codice/codice_l0.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

PACKET_TO_XTCE_MAPPING = {
"raw_ccsds_20230822_122700Z_idle.bin": "P_COD_NHK.xml",
"lo_fsw_view_3_ccsds.bin": "P_COD_LO_PRIORITY_COUNTS.xml",
"lo_fsw_view_5_ccsds.bin": "P_COD_LO_SW_SPECIES_COUNTS.xml",
"lo_fsw_view_6_ccsds.bin": "P_COD_LO_NSW_SPECIES_COUNTS.xml",
}
Expand Down
46 changes: 26 additions & 20 deletions imap_processing/codice/codice_l1a.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
LO_COMPRESSION_ID_LOOKUP,
LO_NSW_SPECIES_NAMES,
LO_STEPPING_TABLE_ID_LOOKUP,
LO_SW_PRIORITY_NAMES,
LO_SW_SPECIES_NAMES,
)
from imap_processing.codice.utils import CODICEAPID, create_hskp_dataset
Expand Down Expand Up @@ -95,6 +96,7 @@ def create_science_dataset(self, packets: list) -> xr.Dataset:

# TODO: Pull out common code and put in codice.utils alongside
# create_hskp_dataset()
# TODO: Resolve "Python into too large to convert to C long" error
"""
epoch = xr.DataArray(
[calc_start_time(packets[0].data["SHCOARSE"].raw_value)],
Expand All @@ -116,15 +118,15 @@ def create_science_dataset(self, packets: list) -> xr.Dataset:
)

# Create a data variable for each species
for species_data, name in zip(self.data, self.species_names):
for variable_data, name in zip(self.data, self.variable_names):
varname, fieldname = name
species_data_arr = [int(item) for item in species_data]
species_data_arr = np.array(species_data_arr).reshape(
variable_data_arr = [int(item) for item in variable_data]
variable_data_arr = np.array(variable_data_arr).reshape(
-1, self.num_energy_steps
)

dataset[varname] = xr.DataArray(
species_data_arr,
variable_data_arr,
name=varname,
dims=["epoch", "energy"],
attrs=dataclasses.replace(
Expand Down Expand Up @@ -208,15 +210,20 @@ def get_lo_data_products(self, apid: int):
The APID of interest.
"""
if apid == CODICEAPID.COD_LO_SW_SPECIES_COUNTS:
self.num_species = 16
self.num_counters = 16
self.num_energy_steps = 128
self.species_names = LO_SW_SPECIES_NAMES
self.cdf_attrs = cdf_attrs.l1a_lo_sw_species_attrs
self.variable_names = LO_SW_SPECIES_NAMES
self.cdf_attrs = cdf_attrs.l1a_lo_sw_species_counts_attrs
elif apid == CODICEAPID.COD_LO_NSW_SPECIES_COUNTS:
self.num_species = 8
self.num_counters = 8
self.num_energy_steps = 112
self.species_names = LO_NSW_SPECIES_NAMES
self.cdf_attrs = cdf_attrs.l1a_lo_nsw_species_attrs
self.variable_names = LO_NSW_SPECIES_NAMES
self.cdf_attrs = cdf_attrs.l1a_lo_nsw_species_counts_attrs
elif apid == CODICEAPID.COD_LO_SW_PRIORITY_COUNTS:
self.num_counters = 5
self.num_energy_steps = 211
self.variable_names = LO_SW_PRIORITY_NAMES
self.cdf_attrs = cdf_attrs.l1a_lo_sw_priority_counts_attrs

def unpack_science_data(self, packets: list):
"""Unpack the science data from the packet.
Expand All @@ -238,9 +245,9 @@ def unpack_science_data(self, packets: list):

science_values = packets[0].data["DATA"].raw_value

# Divide up the data by the number of species
# Divide up the data by the number of priorities or species
num_bytes = len(science_values)
chunk_size = len(science_values) // self.num_species
chunk_size = len(science_values) // self.num_counters
self.data = [
science_values[i : i + chunk_size] for i in range(0, num_bytes, chunk_size)
]
Expand Down Expand Up @@ -295,6 +302,12 @@ def process_codice_l1a(packets) -> xr.Dataset:
dataset : xarray.Dataset
``xarray`` dataset containing the science data and supporting metadata
"""
apids_for_lo_science_processing = [
CODICEAPID.COD_LO_SW_SPECIES_COUNTS,
CODICEAPID.COD_LO_NSW_SPECIES_COUNTS,
CODICEAPID.COD_LO_SW_PRIORITY_COUNTS,
]

# Group data by APID and sort by time
grouped_data = group_by_apid(packets)

Expand All @@ -306,10 +319,7 @@ def process_codice_l1a(packets) -> xr.Dataset:
sorted_packets = sort_by_time(packets, "SHCOARSE")
dataset = create_hskp_dataset(packets=sorted_packets)

elif apid in [
CODICEAPID.COD_LO_SW_SPECIES_COUNTS,
CODICEAPID.COD_LO_NSW_SPECIES_COUNTS,
]:
elif apid in apids_for_lo_science_processing:
packets = sort_by_time(grouped_data[apid], "SHCOARSE")

# Get the four "main" parameters for processing
Expand All @@ -327,10 +337,6 @@ def process_codice_l1a(packets) -> xr.Dataset:
logger.info(f"{apid} is currently not supported")
continue

elif apid == CODICEAPID.COD_LO_SW_PRIORITY_COUNTS:
logger.info(f"{apid} is currently not supported")
continue

elif apid == CODICEAPID.COD_LO_NSW_PRIORITY_COUNTS:
logger.info(f"{apid} is currently not supported")
continue
Expand Down
9 changes: 9 additions & 0 deletions imap_processing/codice/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,15 @@

from imap_processing.codice.utils import CoDICECompression

# CDF-friendly FIELDNAMES and VARNAMES for lo-sw-priority-counts data product
LO_SW_PRIORITY_NAMES = [
("p0-tcrs", "SW Sector Triple Coincidence PUI's"),
("p1-hplus", "SW Sector H+"),
("p2-heplusplus", "SW Sector He++"),
("p3-heavies", "SW Sector High Charge State Heavies"),
("p4-dcrs", "SW Sector Double Coincidence PUI's"),
]

# CDF-friendly FIELDNAMES and VARNAMES for lo-sw-species-counts data product
LO_SW_SPECIES_NAMES = [
("hplus", "SW - H+"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,25 @@
<xtce:IntegerParameterType name="UINT32" signed="false">
<xtce:IntegerDataEncoding sizeInBits="32" encoding="unsigned" />
</xtce:IntegerParameterType>
<xtce:BinaryParameterType name="BYTE9437184">
<xtce:BinaryParameterType name="LO_PRIORITY_COUNTS_BITS">
<xtce:UnitSet />
<xtce:BinaryDataEncoding bitOrder="mostSignificantBitFirst">
<xtce:SizeInBits>
<xtce:FixedValue>9437184</xtce:FixedValue>
<xtce:DynamicValue>
<!--

Data is of variable length.
Slope is always 8 (8 bits per byte) and the intercept
is the total number of fixed length bits in the packet)

This currently works with an intercept of -216, but
this was determined empirically with test data. This
number should be revisited once an updated packet
definition is acquired.
-->
<xtce:ParameterInstanceRef parameterRef="PKT_LEN"/>
<xtce:LinearAdjustment intercept="-216" slope="8"/>
</xtce:DynamicValue>
</xtce:SizeInBits>
</xtce:BinaryDataEncoding>
</xtce:BinaryParameterType>
Expand Down Expand Up @@ -134,7 +148,7 @@
<xtce:ShortDescription>Number of bytes in the Data array</xtce:ShortDescription>
<xtce:LongDescription>Number of bytes in the Data array. If compressed, this value represents the length of the compressed data.</xtce:LongDescription>
</xtce:Parameter>
<xtce:Parameter name="DATA" parameterTypeRef="BYTE9437184">
<xtce:Parameter name="DATA" parameterTypeRef="LO_PRIORITY_COUNTS_BITS">
<xtce:ShortDescription>Data Array</xtce:ShortDescription>
<xtce:LongDescription>Counter Data

Expand Down
Binary file not shown.
5 changes: 5 additions & 0 deletions imap_processing/tests/codice/test_codice_l1a.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,30 +15,35 @@
(99,), # hskp
(1, 128), # lo-sw-species-counts
(1, 112), # lo-nsw-species-counts
(1, 211), # lo-sw-priority-counts
]
EXPECTED_ARRAY_SIZES = [
123, # hskp
16, # lo-sw-species-counts
8, # lo-nsw-species-counts
5, # lo-sw-priority-counts
]
EXPECTED_FILENAMES = [
"imap_codice_l1a_hskp_20100101_v001.cdf",
"imap_codice_l1a_lo-sw-species-counts_20240319_v001.cdf",
"imap_codice_l1a_lo-nsw-species-counts_20240319_v001.cdf",
"imap_codice_l1a_lo-sw-priority-counts_20240319_v001.cdf",
]
TEST_PACKETS = [
Path(
f"{imap_module_directory}/tests/codice/data/raw_ccsds_20230822_122700Z_idle.bin"
),
Path(f"{imap_module_directory}/tests/codice/data/lo_fsw_view_5_ccsds.bin"),
Path(f"{imap_module_directory}/tests/codice/data/lo_fsw_view_6_ccsds.bin"),
Path(f"{imap_module_directory}/tests/codice/data/lo_fsw_view_3_ccsds.bin"),
]

# Placeholder for validation data files
VALIDATION_DATA = [
f"{imap_module_directory}/tests/codice/data/validation_hskp.cdf",
f"{imap_module_directory}/tests/codice/data/validation_lo-sw-species-counts.cdf",
f"{imap_module_directory}/tests/codice/data/validation_lo-nsw-species-counts.cdf",
f"{imap_module_directory}/tests/codice/data/validataion_lo-sw-priority-counts.cdf",
]


Expand Down
Loading