Skip to content

Commit

Permalink
Add hi_l1b_hk global attributes to imap_hi_global_cdf_attrs.yaml (#633)
Browse files Browse the repository at this point in the history
Convert l1b hk to use CDF attribute manager
Move Logical_source update to common l1b location
Update test value for l1b_hk Logical_source
  • Loading branch information
subagonsouth authored Jun 17, 2024
1 parent 883e454 commit 9b1c351
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 13 deletions.
6 changes: 6 additions & 0 deletions imap_processing/cdf/config/imap_hi_global_cdf_attrs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@ imap_hi_l1b_de_attrs:
Logical_source: imap_hi_l1b_{sensor}-de
Logical_source_description: IMAP-Hi Instrument Level-1B Direct Event Data.

imap_hi_l1b_hk_attrs:
Data_level: 1B
Data_type: L1B_HK>Level-1B Housekeeping
Logical_source: imap_hi_l1b_{sensor}-hk
Logical_source_description: IMAP-Hi Instrument Level-1B Housekeeping Data.

imap_hi_l1c_pset_attrs:
Data_level: 1C
Data_type: L1C_PSET>Level-1C Pointing Set
Expand Down
23 changes: 12 additions & 11 deletions imap_processing/hi/l1b/hi_l1b.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
from imap_processing import imap_module_directory
from imap_processing.cdf.cdf_attribute_manager import CdfAttributeManager
from imap_processing.cdf.utils import load_cdf
from imap_processing.hi.hi_cdf_attrs import hi_hk_l1b_global_attrs
from imap_processing.hi.utils import HIAPID
from imap_processing.utils import convert_raw_to_eu

Expand Down Expand Up @@ -56,14 +55,24 @@ def hi_l1b(l1a_cdf_path: Path, data_version: str):
converters={"mnemonic": str.lower},
)

l1b_dataset.attrs.update(hi_hk_l1b_global_attrs.output())
l1b_dataset.attrs.update(
CDF_MANAGER.get_global_attributes("imap_hi_l1b_hk_attrs")
)
elif logical_source_parts[-1].endswith("de"):
l1b_dataset = annotate_direct_events(l1a_dataset)
else:
raise NotImplementedError(
f"No Hi L1B processing defined for file type: "
f"{l1a_dataset.attrs['Logical_source']}"
)
# Update global attributes
# TODO: write a function that extracts the sensor from Logical_source
# some functionality can be found in imap_data_access.file_validation but
# only works on full file names
sensor_str = logical_source_parts[-1].split("-")[0]
l1b_dataset.attrs["Logical_source"] = l1b_dataset.attrs["Logical_source"].format(
sensor=sensor_str
)
# TODO: revisit this
l1b_dataset.attrs["Data_version"] = data_version
return l1b_dataset
Expand Down Expand Up @@ -112,14 +121,6 @@ def annotate_direct_events(l1a_dataset):
["tof_1", "tof_2", "tof_3", "de_tag", "ccsds_met", "meta_event_met"]
)

# Update global attributes
# TODO: write a function that extracts the sensor from Logical_source
# some functionality can be found in imap_data_access.file_validation but
# only works on full file names
sensor_str = l1a_dataset.attrs["Logical_source"].split("_")[-1].split("-")[0]
de_global_attrs = CDF_MANAGER.get_global_attributes("imap_hi_l1b_de_attrs").copy()
de_global_attrs["Logical_source"] = de_global_attrs["Logical_source"].format(
sensor=sensor_str
)
de_global_attrs = CDF_MANAGER.get_global_attributes("imap_hi_l1b_de_attrs")
l1b_dataset.attrs.update(**de_global_attrs)
return l1b_dataset
3 changes: 1 addition & 2 deletions imap_processing/tests/hi/test_hi_l1b.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

from imap_processing import imap_module_directory
from imap_processing.cdf.utils import write_cdf
from imap_processing.hi.hi_cdf_attrs import hi_hk_l1b_global_attrs
from imap_processing.hi.l1a.hi_l1a import hi_l1a
from imap_processing.hi.l1b.hi_l1b import hi_l1b
from imap_processing.hi.utils import HIAPID
Expand All @@ -19,7 +18,7 @@ def test_hi_l1b_hk():
l1a_cdf_path = write_cdf(processed_data[0])

l1b_dataset = hi_l1b(l1a_cdf_path, data_version=data_version)
assert l1b_dataset.attrs["Logical_source"] == hi_hk_l1b_global_attrs.logical_source
assert l1b_dataset.attrs["Logical_source"] == "imap_hi_l1b_45sensor-hk"


def test_hi_l1b_de(create_de_data, tmp_path):
Expand Down

0 comments on commit 9b1c351

Please sign in to comment.