imap-processing 0.7.0__py3-none-any.whl → 0.9.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of imap-processing might be problematic. Click here for more details.
- imap_processing/__init__.py +1 -1
- imap_processing/_version.py +2 -2
- imap_processing/ccsds/excel_to_xtce.py +36 -2
- imap_processing/cdf/config/imap_codice_global_cdf_attrs.yaml +1 -1
- imap_processing/cdf/config/imap_codice_l1a_variable_attrs.yaml +145 -30
- imap_processing/cdf/config/imap_glows_l1b_variable_attrs.yaml +36 -36
- imap_processing/cdf/config/imap_hi_variable_attrs.yaml +136 -9
- imap_processing/cdf/config/imap_hit_global_cdf_attrs.yaml +14 -0
- imap_processing/cdf/config/imap_hit_l1a_variable_attrs.yaml +63 -1
- imap_processing/cdf/config/imap_hit_l1b_variable_attrs.yaml +9 -0
- imap_processing/cdf/config/imap_idex_global_cdf_attrs.yaml +14 -7
- imap_processing/cdf/config/imap_idex_l1a_variable_attrs.yaml +577 -235
- imap_processing/cdf/config/imap_idex_l1b_variable_attrs.yaml +326 -0
- imap_processing/cdf/config/imap_lo_l1a_variable_attrs.yaml +33 -23
- imap_processing/cdf/config/imap_mag_l1_variable_attrs.yaml +24 -28
- imap_processing/cdf/config/imap_ultra_l1a_variable_attrs.yaml +1 -0
- imap_processing/cdf/config/imap_ultra_l1b_variable_attrs.yaml +137 -79
- imap_processing/cdf/config/imap_variable_schema.yaml +13 -0
- imap_processing/cdf/imap_cdf_manager.py +31 -27
- imap_processing/cdf/utils.py +3 -5
- imap_processing/cli.py +25 -14
- imap_processing/codice/codice_l1a.py +153 -63
- imap_processing/codice/constants.py +10 -10
- imap_processing/codice/decompress.py +10 -11
- imap_processing/codice/utils.py +1 -0
- imap_processing/glows/l1a/glows_l1a.py +1 -2
- imap_processing/glows/l1b/glows_l1b.py +3 -3
- imap_processing/glows/l1b/glows_l1b_data.py +59 -37
- imap_processing/glows/l2/glows_l2_data.py +123 -0
- imap_processing/hi/l1a/hi_l1a.py +4 -4
- imap_processing/hi/l1a/histogram.py +107 -109
- imap_processing/hi/l1a/science_direct_event.py +92 -225
- imap_processing/hi/l1b/hi_l1b.py +85 -11
- imap_processing/hi/l1c/hi_l1c.py +23 -1
- imap_processing/hi/packet_definitions/TLM_HI_COMBINED_SCI.xml +3994 -0
- imap_processing/hi/utils.py +1 -1
- imap_processing/hit/hit_utils.py +221 -0
- imap_processing/hit/l0/constants.py +118 -0
- imap_processing/hit/l0/decom_hit.py +100 -156
- imap_processing/hit/l1a/hit_l1a.py +170 -184
- imap_processing/hit/l1b/hit_l1b.py +33 -153
- imap_processing/ialirt/l0/process_codicelo.py +153 -0
- imap_processing/ialirt/l0/process_hit.py +5 -5
- imap_processing/ialirt/packet_definitions/ialirt_codicelo.xml +281 -0
- imap_processing/ialirt/process_ephemeris.py +212 -0
- imap_processing/idex/idex_l1a.py +65 -84
- imap_processing/idex/idex_l1b.py +192 -0
- imap_processing/idex/idex_variable_unpacking_and_eu_conversion.csv +33 -0
- imap_processing/idex/packet_definitions/idex_packet_definition.xml +97 -595
- imap_processing/lo/l0/decompression_tables/decompression_tables.py +17 -1
- imap_processing/lo/l0/lo_science.py +45 -13
- imap_processing/lo/l1a/lo_l1a.py +76 -8
- imap_processing/lo/packet_definitions/lo_xtce.xml +8344 -1849
- imap_processing/mag/l0/decom_mag.py +4 -3
- imap_processing/mag/l1a/mag_l1a.py +12 -13
- imap_processing/mag/l1a/mag_l1a_data.py +1 -2
- imap_processing/mag/l1b/mag_l1b.py +90 -7
- imap_processing/spice/geometry.py +156 -16
- imap_processing/spice/time.py +144 -2
- imap_processing/swapi/l1/swapi_l1.py +4 -4
- imap_processing/swapi/l2/swapi_l2.py +1 -1
- imap_processing/swapi/packet_definitions/swapi_packet_definition.xml +1535 -446
- imap_processing/swe/l1b/swe_l1b_science.py +8 -8
- imap_processing/swe/l2/swe_l2.py +134 -17
- imap_processing/tests/ccsds/test_data/expected_output.xml +2 -1
- imap_processing/tests/ccsds/test_excel_to_xtce.py +4 -4
- imap_processing/tests/cdf/test_imap_cdf_manager.py +0 -10
- imap_processing/tests/codice/conftest.py +1 -17
- imap_processing/tests/codice/data/imap_codice_l0_raw_20241110_v001.pkts +0 -0
- imap_processing/tests/codice/test_codice_l0.py +8 -2
- imap_processing/tests/codice/test_codice_l1a.py +127 -107
- imap_processing/tests/codice/test_codice_l1b.py +1 -0
- imap_processing/tests/codice/test_decompress.py +7 -7
- imap_processing/tests/conftest.py +100 -58
- imap_processing/tests/glows/conftest.py +6 -0
- imap_processing/tests/glows/test_glows_l1b.py +9 -9
- imap_processing/tests/glows/test_glows_l1b_data.py +9 -9
- imap_processing/tests/hi/test_data/l0/H90_NHK_20241104.bin +0 -0
- imap_processing/tests/hi/test_data/l0/H90_sci_cnt_20241104.bin +0 -0
- imap_processing/tests/hi/test_data/l0/H90_sci_de_20241104.bin +0 -0
- imap_processing/tests/hi/test_data/l1a/imap_hi_l1a_45sensor-de_20250415_v000.cdf +0 -0
- imap_processing/tests/hi/test_hi_l1b.py +73 -3
- imap_processing/tests/hi/test_hi_l1c.py +10 -2
- imap_processing/tests/hi/test_l1a.py +31 -58
- imap_processing/tests/hi/test_science_direct_event.py +58 -0
- imap_processing/tests/hi/test_utils.py +4 -3
- imap_processing/tests/hit/test_data/sci_sample1.ccsds +0 -0
- imap_processing/tests/hit/{test_hit_decom.py → test_decom_hit.py} +95 -36
- imap_processing/tests/hit/test_hit_l1a.py +299 -179
- imap_processing/tests/hit/test_hit_l1b.py +231 -24
- imap_processing/tests/hit/test_hit_utils.py +218 -0
- imap_processing/tests/hit/validation_data/hskp_sample_eu.csv +89 -0
- imap_processing/tests/hit/validation_data/sci_sample_raw1.csv +29 -0
- imap_processing/tests/ialirt/test_data/l0/apid01152.tlm +0 -0
- imap_processing/tests/ialirt/test_data/l0/imap_codice_l1a_lo-ialirt_20241110193700_v0.0.0.cdf +0 -0
- imap_processing/tests/ialirt/unit/test_process_codicelo.py +106 -0
- imap_processing/tests/ialirt/unit/test_process_ephemeris.py +109 -0
- imap_processing/tests/ialirt/unit/test_process_hit.py +9 -6
- imap_processing/tests/idex/conftest.py +2 -2
- imap_processing/tests/idex/imap_idex_l0_raw_20231214_v001.pkts +0 -0
- imap_processing/tests/idex/impact_14_tof_high_data.txt +4444 -4444
- imap_processing/tests/idex/test_idex_l0.py +4 -4
- imap_processing/tests/idex/test_idex_l1a.py +8 -2
- imap_processing/tests/idex/test_idex_l1b.py +126 -0
- imap_processing/tests/lo/test_lo_l1a.py +7 -16
- imap_processing/tests/lo/test_lo_science.py +69 -5
- imap_processing/tests/lo/test_pkts/imap_lo_l0_raw_20240803_v002.pkts +0 -0
- imap_processing/tests/lo/validation_data/Instrument_FM1_T104_R129_20240803_ILO_SCI_DE_dec_DN_with_fills.csv +1999 -0
- imap_processing/tests/mag/imap_mag_l1a_norm-magi_20251017_v001.cdf +0 -0
- imap_processing/tests/mag/test_mag_l1b.py +97 -7
- imap_processing/tests/spice/test_data/imap_ena_sim_metakernel.template +3 -1
- imap_processing/tests/spice/test_geometry.py +115 -9
- imap_processing/tests/spice/test_time.py +135 -6
- imap_processing/tests/swapi/test_swapi_decom.py +75 -69
- imap_processing/tests/swapi/test_swapi_l1.py +4 -4
- imap_processing/tests/swe/conftest.py +33 -0
- imap_processing/tests/swe/l1_validation/swe_l0_unpacked-data_20240510_v001_VALIDATION_L1B_v3.dat +4332 -0
- imap_processing/tests/swe/test_swe_l1b.py +29 -8
- imap_processing/tests/swe/test_swe_l2.py +64 -8
- imap_processing/tests/test_utils.py +2 -2
- imap_processing/tests/ultra/test_data/l0/ultra45_raw_sc_ultrarawimg_withFSWcalcs_FM45_40P_Phi28p5_BeamCal_LinearScan_phi2850_theta-000_20240207T102740.csv +3314 -3314
- imap_processing/tests/ultra/test_data/l1/dps_exposure_helio_45_E12.cdf +0 -0
- imap_processing/tests/ultra/test_data/l1/dps_exposure_helio_45_E24.cdf +0 -0
- imap_processing/tests/ultra/unit/test_de.py +113 -0
- imap_processing/tests/ultra/unit/test_spatial_utils.py +125 -0
- imap_processing/tests/ultra/unit/test_ultra_l1b.py +27 -3
- imap_processing/tests/ultra/unit/test_ultra_l1b_annotated.py +31 -10
- imap_processing/tests/ultra/unit/test_ultra_l1b_extended.py +55 -35
- imap_processing/tests/ultra/unit/test_ultra_l1c_pset_bins.py +10 -68
- imap_processing/ultra/constants.py +12 -3
- imap_processing/ultra/l1b/de.py +168 -30
- imap_processing/ultra/l1b/ultra_l1b_annotated.py +24 -10
- imap_processing/ultra/l1b/ultra_l1b_extended.py +46 -80
- imap_processing/ultra/l1c/ultra_l1c_pset_bins.py +60 -144
- imap_processing/ultra/utils/spatial_utils.py +221 -0
- {imap_processing-0.7.0.dist-info → imap_processing-0.9.0.dist-info}/METADATA +15 -14
- {imap_processing-0.7.0.dist-info → imap_processing-0.9.0.dist-info}/RECORD +142 -139
- imap_processing/cdf/cdf_attribute_manager.py +0 -322
- imap_processing/cdf/config/shared/default_global_cdf_attrs_schema.yaml +0 -246
- imap_processing/cdf/config/shared/default_variable_cdf_attrs_schema.yaml +0 -466
- imap_processing/hi/l0/decom_hi.py +0 -24
- imap_processing/hi/packet_definitions/hi_packet_definition.xml +0 -482
- imap_processing/hit/l0/data_classes/housekeeping.py +0 -240
- imap_processing/hit/l0/data_classes/science_packet.py +0 -259
- imap_processing/hit/l0/utils/hit_base.py +0 -57
- imap_processing/tests/cdf/shared/default_global_cdf_attrs_schema.yaml +0 -246
- imap_processing/tests/cdf/shared/default_variable_cdf_attrs_schema.yaml +0 -466
- imap_processing/tests/cdf/test_cdf_attribute_manager.py +0 -353
- imap_processing/tests/codice/data/imap_codice_l0_hi-counters-aggregated_20240429_v001.pkts +0 -0
- imap_processing/tests/codice/data/imap_codice_l0_hi-counters-singles_20240429_v001.pkts +0 -0
- imap_processing/tests/codice/data/imap_codice_l0_hi-omni_20240429_v001.pkts +0 -0
- imap_processing/tests/codice/data/imap_codice_l0_hi-pha_20240429_v001.pkts +0 -0
- imap_processing/tests/codice/data/imap_codice_l0_hi-sectored_20240429_v001.pkts +0 -0
- imap_processing/tests/codice/data/imap_codice_l0_hskp_20100101_v001.pkts +0 -0
- imap_processing/tests/codice/data/imap_codice_l0_lo-counters-aggregated_20240429_v001.pkts +0 -0
- imap_processing/tests/codice/data/imap_codice_l0_lo-counters-singles_20240429_v001.pkts +0 -0
- imap_processing/tests/codice/data/imap_codice_l0_lo-nsw-angular_20240429_v001.pkts +0 -0
- imap_processing/tests/codice/data/imap_codice_l0_lo-nsw-priority_20240429_v001.pkts +0 -0
- imap_processing/tests/codice/data/imap_codice_l0_lo-nsw-species_20240429_v001.pkts +0 -0
- imap_processing/tests/codice/data/imap_codice_l0_lo-pha_20240429_v001.pkts +0 -0
- imap_processing/tests/codice/data/imap_codice_l0_lo-sw-angular_20240429_v001.pkts +0 -0
- imap_processing/tests/codice/data/imap_codice_l0_lo-sw-priority_20240429_v001.pkts +0 -0
- imap_processing/tests/codice/data/imap_codice_l0_lo-sw-species_20240429_v001.pkts +0 -0
- imap_processing/tests/hi/test_decom.py +0 -55
- imap_processing/tests/hi/test_l1a_sci_de.py +0 -72
- imap_processing/tests/idex/imap_idex_l0_raw_20230725_v001.pkts +0 -0
- imap_processing/tests/mag/imap_mag_l1a_burst-magi_20231025_v001.cdf +0 -0
- /imap_processing/{hi/l0/__init__.py → tests/glows/test_glows_l2_data.py} +0 -0
- /imap_processing/tests/hit/test_data/{imap_hit_l0_hk_20100105_v001.pkts → imap_hit_l0_raw_20100105_v001.pkts} +0 -0
- {imap_processing-0.7.0.dist-info → imap_processing-0.9.0.dist-info}/LICENSE +0 -0
- {imap_processing-0.7.0.dist-info → imap_processing-0.9.0.dist-info}/WHEEL +0 -0
- {imap_processing-0.7.0.dist-info → imap_processing-0.9.0.dist-info}/entry_points.txt +0 -0
imap_processing/hi/utils.py
CHANGED
|
@@ -174,7 +174,7 @@ def create_dataset_variables(
|
|
|
174
174
|
"""
|
|
175
175
|
attr_mgr = ImapCdfAttributes()
|
|
176
176
|
attr_mgr.add_instrument_global_attrs("hi")
|
|
177
|
-
attr_mgr.
|
|
177
|
+
attr_mgr.add_instrument_variable_attrs(instrument="hi", level=None)
|
|
178
178
|
|
|
179
179
|
new_variables = dict()
|
|
180
180
|
for var in variable_names:
|
|
@@ -0,0 +1,221 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Classes and functions used in HIT processing.
|
|
3
|
+
|
|
4
|
+
This module contains utility classes and functions that are used by
|
|
5
|
+
HIT processing modules.
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
from enum import IntEnum
|
|
9
|
+
|
|
10
|
+
import numpy as np
|
|
11
|
+
import xarray as xr
|
|
12
|
+
|
|
13
|
+
from imap_processing import imap_module_directory
|
|
14
|
+
from imap_processing.cdf.imap_cdf_manager import ImapCdfAttributes
|
|
15
|
+
from imap_processing.utils import packet_file_to_datasets
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
class HitAPID(IntEnum):
|
|
19
|
+
"""
|
|
20
|
+
HIT APID Mappings.
|
|
21
|
+
|
|
22
|
+
Attributes
|
|
23
|
+
----------
|
|
24
|
+
HIT_HSKP: int
|
|
25
|
+
Housekeeping
|
|
26
|
+
HIT_SCIENCE : int
|
|
27
|
+
Science
|
|
28
|
+
HIT_IALRT : int
|
|
29
|
+
I-ALiRT
|
|
30
|
+
"""
|
|
31
|
+
|
|
32
|
+
HIT_HSKP = 1251
|
|
33
|
+
HIT_SCIENCE = 1252
|
|
34
|
+
HIT_IALRT = 1253
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
def get_datasets_by_apid(
|
|
38
|
+
packet_file: str, derived: bool = False
|
|
39
|
+
) -> dict[int, xr.Dataset]:
|
|
40
|
+
"""
|
|
41
|
+
Get datasets by APID from a CCSDS packet file.
|
|
42
|
+
|
|
43
|
+
Parameters
|
|
44
|
+
----------
|
|
45
|
+
packet_file : str
|
|
46
|
+
Path to the CCSDS data packet file.
|
|
47
|
+
derived : bool, optional
|
|
48
|
+
Flag to use derived values, by default False.
|
|
49
|
+
Only set to True to get engineering units for L1B
|
|
50
|
+
housekeeping data product.
|
|
51
|
+
|
|
52
|
+
Returns
|
|
53
|
+
-------
|
|
54
|
+
datasets_by_apid : dict[int, xr.Dataset]
|
|
55
|
+
Dictionary of xarray datasets by APID.
|
|
56
|
+
"""
|
|
57
|
+
# Unpack ccsds file
|
|
58
|
+
packet_definition = (
|
|
59
|
+
imap_module_directory / "hit/packet_definitions/hit_packet_definitions.xml"
|
|
60
|
+
)
|
|
61
|
+
datasets_by_apid: dict[int, xr.Dataset] = packet_file_to_datasets(
|
|
62
|
+
packet_file=packet_file,
|
|
63
|
+
xtce_packet_definition=packet_definition,
|
|
64
|
+
use_derived_value=derived,
|
|
65
|
+
)
|
|
66
|
+
return datasets_by_apid
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
def get_attribute_manager(data_version: str, level: str) -> ImapCdfAttributes:
|
|
70
|
+
"""
|
|
71
|
+
Create an attribute manager for the HIT data products.
|
|
72
|
+
|
|
73
|
+
Parameters
|
|
74
|
+
----------
|
|
75
|
+
data_version : str
|
|
76
|
+
Version of the data product being created.
|
|
77
|
+
level : str
|
|
78
|
+
Data level of the product being created.
|
|
79
|
+
|
|
80
|
+
Returns
|
|
81
|
+
-------
|
|
82
|
+
attr_mgr : ImapCdfAttributes
|
|
83
|
+
Attribute manager to set CDF attributes.
|
|
84
|
+
"""
|
|
85
|
+
# Create the attribute manager for this data level
|
|
86
|
+
attr_mgr = ImapCdfAttributes()
|
|
87
|
+
attr_mgr.add_instrument_global_attrs(instrument="hit")
|
|
88
|
+
attr_mgr.add_instrument_variable_attrs(instrument="hit", level=level)
|
|
89
|
+
attr_mgr.add_global_attribute("Data_version", data_version)
|
|
90
|
+
return attr_mgr
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
def concatenate_leak_variables(
|
|
94
|
+
dataset: xr.Dataset, adc_channels: xr.DataArray
|
|
95
|
+
) -> xr.Dataset:
|
|
96
|
+
"""
|
|
97
|
+
Concatenate leak variables in the dataset.
|
|
98
|
+
|
|
99
|
+
Updates the housekeeping dataset to replace the individual
|
|
100
|
+
leak_i_00, leak_i_01, ..., leak_i_63 variables with a single
|
|
101
|
+
leak_i variable as a 2D array. "i" here represents current
|
|
102
|
+
in the leakage current [Voltage] data.
|
|
103
|
+
|
|
104
|
+
Parameters
|
|
105
|
+
----------
|
|
106
|
+
dataset : xarray.Dataset
|
|
107
|
+
Dataset containing 64 leak variables.
|
|
108
|
+
adc_channels : xarray.DataArray
|
|
109
|
+
DataArray to be used as a dimension for the concatenated leak variables.
|
|
110
|
+
|
|
111
|
+
Returns
|
|
112
|
+
-------
|
|
113
|
+
dataset : xarray.Dataset
|
|
114
|
+
Updated dataset with concatenated leak variables.
|
|
115
|
+
"""
|
|
116
|
+
# Stack 64 leak variables (leak_00, leak_01, ..., leak_63)
|
|
117
|
+
leak_vars = [dataset[f"leak_i_{i:02d}"] for i in range(64)]
|
|
118
|
+
|
|
119
|
+
# Concatenate along 'adc_channels' and reorder dimensions
|
|
120
|
+
stacked_leaks = xr.concat(leak_vars, dim=adc_channels).transpose(
|
|
121
|
+
"epoch", "adc_channels"
|
|
122
|
+
)
|
|
123
|
+
dataset["leak_i"] = stacked_leaks
|
|
124
|
+
|
|
125
|
+
# Drop the individual leak variables
|
|
126
|
+
updated_dataset = dataset.drop_vars([f"leak_i_{i:02d}" for i in range(64)])
|
|
127
|
+
|
|
128
|
+
return updated_dataset
|
|
129
|
+
|
|
130
|
+
|
|
131
|
+
def process_housekeeping_data(
|
|
132
|
+
dataset: xr.Dataset, attr_mgr: ImapCdfAttributes, logical_source: str
|
|
133
|
+
) -> xr.Dataset:
|
|
134
|
+
"""
|
|
135
|
+
Will process housekeeping dataset for CDF product.
|
|
136
|
+
|
|
137
|
+
Updates the housekeeping dataset with a single 2D leak_i
|
|
138
|
+
variable. Also updates the dataset attributes, coordinates
|
|
139
|
+
and data variable dimensions according to specifications in
|
|
140
|
+
a cdf yaml file. This function is used for both L1A and L1B
|
|
141
|
+
housekeeping data products.
|
|
142
|
+
|
|
143
|
+
Parameters
|
|
144
|
+
----------
|
|
145
|
+
dataset : xarray.Dataset
|
|
146
|
+
Dataset containing HIT housekeeping data.
|
|
147
|
+
|
|
148
|
+
attr_mgr : ImapCdfAttributes
|
|
149
|
+
Attribute manager used to get the data product field's attributes.
|
|
150
|
+
|
|
151
|
+
logical_source : str
|
|
152
|
+
Logical source of the data -> imap_hit_l1a_hk or imap_hit_l1b_hk.
|
|
153
|
+
|
|
154
|
+
Returns
|
|
155
|
+
-------
|
|
156
|
+
dataset : xarray.Dataset
|
|
157
|
+
An updated dataset ready for CDF conversion.
|
|
158
|
+
"""
|
|
159
|
+
# Drop keys that are not CDF data variables
|
|
160
|
+
drop_keys = [
|
|
161
|
+
"pkt_apid",
|
|
162
|
+
"sc_tick",
|
|
163
|
+
"version",
|
|
164
|
+
"type",
|
|
165
|
+
"sec_hdr_flg",
|
|
166
|
+
"seq_flgs",
|
|
167
|
+
"src_seq_ctr",
|
|
168
|
+
"pkt_len",
|
|
169
|
+
"hskp_spare1",
|
|
170
|
+
"hskp_spare2",
|
|
171
|
+
"hskp_spare3",
|
|
172
|
+
"hskp_spare4",
|
|
173
|
+
"hskp_spare5",
|
|
174
|
+
]
|
|
175
|
+
|
|
176
|
+
# Drop variables not needed for CDF
|
|
177
|
+
dataset = dataset.drop_vars(drop_keys)
|
|
178
|
+
|
|
179
|
+
# Create data arrays for dependencies
|
|
180
|
+
adc_channels = xr.DataArray(
|
|
181
|
+
np.arange(64, dtype=np.uint8),
|
|
182
|
+
name="adc_channels",
|
|
183
|
+
dims=["adc_channels"],
|
|
184
|
+
attrs=attr_mgr.get_variable_attributes("adc_channels"),
|
|
185
|
+
)
|
|
186
|
+
|
|
187
|
+
# NOTE: LABL_PTR_1 should be CDF_CHAR.
|
|
188
|
+
adc_channels_label = xr.DataArray(
|
|
189
|
+
adc_channels.values.astype(str),
|
|
190
|
+
name="adc_channels_label",
|
|
191
|
+
dims=["adc_channels_label"],
|
|
192
|
+
attrs=attr_mgr.get_variable_attributes("adc_channels_label"),
|
|
193
|
+
)
|
|
194
|
+
|
|
195
|
+
# Update dataset coordinates and attributes
|
|
196
|
+
dataset = dataset.assign_coords(
|
|
197
|
+
{
|
|
198
|
+
"adc_channels": adc_channels,
|
|
199
|
+
"adc_channels_label": adc_channels_label,
|
|
200
|
+
}
|
|
201
|
+
)
|
|
202
|
+
dataset.attrs = attr_mgr.get_global_attributes(logical_source)
|
|
203
|
+
|
|
204
|
+
# Stack 64 leak variables (leak_00, leak_01, ..., leak_63)
|
|
205
|
+
dataset = concatenate_leak_variables(dataset, adc_channels)
|
|
206
|
+
|
|
207
|
+
# Assign attributes and dimensions to each data array in the Dataset
|
|
208
|
+
for field in dataset.data_vars.keys():
|
|
209
|
+
# Create a dict of dimensions using the DEPEND_I keys in the
|
|
210
|
+
# attributes
|
|
211
|
+
dims = {
|
|
212
|
+
key: value
|
|
213
|
+
for key, value in attr_mgr.get_variable_attributes(field).items()
|
|
214
|
+
if "DEPEND" in key
|
|
215
|
+
}
|
|
216
|
+
dataset[field].attrs = attr_mgr.get_variable_attributes(field)
|
|
217
|
+
dataset[field].assign_coords(dims)
|
|
218
|
+
|
|
219
|
+
dataset.epoch.attrs = attr_mgr.get_variable_attributes("epoch")
|
|
220
|
+
|
|
221
|
+
return dataset
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
"""HIT L0 constants for data decommutation."""
|
|
2
|
+
|
|
3
|
+
from collections import namedtuple
|
|
4
|
+
|
|
5
|
+
import numpy as np
|
|
6
|
+
|
|
7
|
+
# energy_units: MeV/n
|
|
8
|
+
MOD_10_MAPPING = {
|
|
9
|
+
0: {"species": "H", "energy_min": 1.8, "energy_max": 3.6},
|
|
10
|
+
1: {"species": "H", "energy_min": 4, "energy_max": 6},
|
|
11
|
+
2: {"species": "H", "energy_min": 6, "energy_max": 10},
|
|
12
|
+
3: {"species": "He4", "energy_min": 4, "energy_max": 6},
|
|
13
|
+
4: {"species": "He4", "energy_min": 6, "energy_max": 12},
|
|
14
|
+
5: {"species": "CNO", "energy_min": 4, "energy_max": 6},
|
|
15
|
+
6: {"species": "CNO", "energy_min": 6, "energy_max": 12},
|
|
16
|
+
7: {"species": "NeMgSi", "energy_min": 4, "energy_max": 6},
|
|
17
|
+
8: {"species": "NeMgSi", "energy_min": 6, "energy_max": 12},
|
|
18
|
+
9: {"species": "Fe", "energy_min": 4, "energy_max": 12},
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
# Structure to hold binary details for a
|
|
22
|
+
# section of science data. Used to unpack
|
|
23
|
+
# binary data.
|
|
24
|
+
HITPacking = namedtuple(
|
|
25
|
+
"HITPacking",
|
|
26
|
+
[
|
|
27
|
+
"bit_length",
|
|
28
|
+
"section_length",
|
|
29
|
+
"shape",
|
|
30
|
+
],
|
|
31
|
+
)
|
|
32
|
+
|
|
33
|
+
# Define data structure for counts rates data
|
|
34
|
+
COUNTS_DATA_STRUCTURE = {
|
|
35
|
+
# field: bit_length, section_length, shape
|
|
36
|
+
# ------------------------------------------
|
|
37
|
+
# science frame header
|
|
38
|
+
"hdr_unit_num": HITPacking(2, 2, (1,)),
|
|
39
|
+
"hdr_frame_version": HITPacking(6, 6, (1,)),
|
|
40
|
+
"hdr_dynamic_threshold_state": HITPacking(2, 2, (1,)),
|
|
41
|
+
"hdr_leak_conv": HITPacking(1, 1, (1,)),
|
|
42
|
+
"hdr_heater_duty_cycle": HITPacking(4, 4, (1,)),
|
|
43
|
+
"hdr_code_ok": HITPacking(1, 1, (1,)),
|
|
44
|
+
"hdr_minute_cnt": HITPacking(8, 8, (1,)),
|
|
45
|
+
# ------------------------------------------
|
|
46
|
+
# spare bits. Contains no data
|
|
47
|
+
"spare": HITPacking(24, 24, (1,)),
|
|
48
|
+
# ------------------------------------------
|
|
49
|
+
# erates - contains livetime counters
|
|
50
|
+
"livetime": HITPacking(16, 16, (1,)), # livetime counter
|
|
51
|
+
"num_trig": HITPacking(16, 16, (1,)), # number of triggers
|
|
52
|
+
"num_reject": HITPacking(16, 16, (1,)), # number of rejected events
|
|
53
|
+
"num_acc_w_pha": HITPacking(
|
|
54
|
+
16, 16, (1,)
|
|
55
|
+
), # number of accepted events with PHA data
|
|
56
|
+
"num_acc_no_pha": HITPacking(16, 16, (1,)), # number of events without PHA data
|
|
57
|
+
"num_haz_trig": HITPacking(16, 16, (1,)), # number of triggers with hazard flag
|
|
58
|
+
"num_haz_reject": HITPacking(
|
|
59
|
+
16, 16, (1,)
|
|
60
|
+
), # number of rejected events with hazard flag
|
|
61
|
+
"num_haz_acc_w_pha": HITPacking(
|
|
62
|
+
16, 16, (1,)
|
|
63
|
+
), # number of accepted hazard events with PHA data
|
|
64
|
+
"num_haz_acc_no_pha": HITPacking(
|
|
65
|
+
16, 16, (1,)
|
|
66
|
+
), # number of hazard events without PHA data
|
|
67
|
+
# -------------------------------------------
|
|
68
|
+
"sngrates": HITPacking(16, 1856, (2, 58)), # single rates
|
|
69
|
+
# -------------------------------------------
|
|
70
|
+
# evprates - contains event processing rates
|
|
71
|
+
"nread": HITPacking(16, 16, (1,)), # events read from event fifo
|
|
72
|
+
"nhazard": HITPacking(16, 16, (1,)), # events tagged with hazard flag
|
|
73
|
+
"nadcstim": HITPacking(16, 16, (1,)), # adc-stim events
|
|
74
|
+
"nodd": HITPacking(16, 16, (1,)), # odd events
|
|
75
|
+
"noddfix": HITPacking(16, 16, (1,)), # odd events that were fixed in sw
|
|
76
|
+
"nmulti": HITPacking(
|
|
77
|
+
16, 16, (1,)
|
|
78
|
+
), # events with multiple hits in a single detector
|
|
79
|
+
"nmultifix": HITPacking(16, 16, (1,)), # multi events that were fixed in sw
|
|
80
|
+
"nbadtraj": HITPacking(16, 16, (1,)), # bad trajectory
|
|
81
|
+
"nl2": HITPacking(16, 16, (1,)), # events sorted into L12 event category
|
|
82
|
+
"nl3": HITPacking(16, 16, (1,)), # events sorted into L123 event category
|
|
83
|
+
"nl4": HITPacking(16, 16, (1,)), # events sorted into L1423 event category
|
|
84
|
+
"npen": HITPacking(16, 16, (1,)), # events sorted into penetrating event category
|
|
85
|
+
"nformat": HITPacking(16, 16, (1,)), # nothing currently goes in this slot
|
|
86
|
+
"naside": HITPacking(16, 16, (1,)), # A-side events
|
|
87
|
+
"nbside": HITPacking(16, 16, (1,)), # B-side events
|
|
88
|
+
"nerror": HITPacking(16, 16, (1,)), # events that caused a processing error
|
|
89
|
+
"nbadtags": HITPacking(
|
|
90
|
+
16, 16, (1,)
|
|
91
|
+
), # events with inconsistent tags vs pulse heights
|
|
92
|
+
# -------------------------------------------
|
|
93
|
+
# other count rates
|
|
94
|
+
"coinrates": HITPacking(16, 416, (26,)), # coincidence rates
|
|
95
|
+
"bufrates": HITPacking(16, 512, (32,)), # priority buffer rates
|
|
96
|
+
"l2fgrates": HITPacking(16, 2112, (132,)), # range 2 foreground rates
|
|
97
|
+
"l2bgrates": HITPacking(16, 192, (12,)), # range 2 background rates
|
|
98
|
+
"l3fgrates": HITPacking(16, 2672, (167,)), # range 3 foreground rates
|
|
99
|
+
"l3bgrates": HITPacking(16, 192, (12,)), # range 3 background rates
|
|
100
|
+
"penfgrates": HITPacking(16, 528, (33,)), # range 4 foreground rates
|
|
101
|
+
"penbgrates": HITPacking(16, 240, (15,)), # range 4 background rates
|
|
102
|
+
"ialirtrates": HITPacking(16, 320, (20,)), # ialirt rates
|
|
103
|
+
"sectorates": HITPacking(16, 1920, (8, 15)), # sectored rates
|
|
104
|
+
"l4fgrates": HITPacking(16, 768, (48,)), # all range foreground rates
|
|
105
|
+
"l4bgrates": HITPacking(16, 384, (24,)), # all range foreground rates
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
|
|
109
|
+
# Define the pattern of grouping flags in a complete science frame.
|
|
110
|
+
FLAG_PATTERN = np.array([1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2])
|
|
111
|
+
|
|
112
|
+
# Define size of science frame (num of packets)
|
|
113
|
+
FRAME_SIZE = len(FLAG_PATTERN)
|
|
114
|
+
|
|
115
|
+
# Define the number of bits in the mantissa and exponent for
|
|
116
|
+
# decompressing data
|
|
117
|
+
MANTISSA_BITS = 12
|
|
118
|
+
EXPONENT_BITS = 4
|