imap-processing 0.8.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/_version.py +2 -2
- imap_processing/ccsds/excel_to_xtce.py +2 -0
- imap_processing/cdf/config/imap_hi_variable_attrs.yaml +100 -1
- 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_idex_global_cdf_attrs.yaml +7 -0
- imap_processing/cdf/config/imap_idex_l1a_variable_attrs.yaml +574 -231
- 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_ultra_l1b_variable_attrs.yaml +7 -4
- imap_processing/cdf/utils.py +3 -5
- imap_processing/cli.py +13 -4
- imap_processing/codice/codice_l1a.py +5 -5
- imap_processing/codice/constants.py +9 -9
- imap_processing/codice/decompress.py +6 -2
- imap_processing/glows/l1a/glows_l1a.py +1 -2
- imap_processing/hi/l1a/hi_l1a.py +4 -4
- imap_processing/hi/l1a/histogram.py +106 -108
- imap_processing/hi/l1a/science_direct_event.py +91 -224
- imap_processing/hi/packet_definitions/TLM_HI_COMBINED_SCI.xml +3994 -0
- imap_processing/hit/l0/constants.py +2 -2
- imap_processing/hit/l0/decom_hit.py +12 -101
- imap_processing/hit/l1a/hit_l1a.py +164 -23
- 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 +55 -75
- 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 +16 -0
- imap_processing/lo/l0/lo_science.py +44 -12
- imap_processing/lo/l1a/lo_l1a.py +76 -8
- imap_processing/lo/packet_definitions/lo_xtce.xml +9877 -87
- imap_processing/mag/l1a/mag_l1a.py +1 -2
- imap_processing/mag/l1a/mag_l1a_data.py +1 -2
- imap_processing/mag/l1b/mag_l1b.py +2 -1
- imap_processing/spice/geometry.py +37 -19
- imap_processing/spice/time.py +144 -2
- imap_processing/swapi/l1/swapi_l1.py +3 -3
- imap_processing/swapi/packet_definitions/swapi_packet_definition.xml +1535 -446
- imap_processing/swe/l2/swe_l2.py +134 -17
- imap_processing/tests/ccsds/test_data/expected_output.xml +1 -1
- imap_processing/tests/codice/test_codice_l1a.py +8 -8
- imap_processing/tests/codice/test_decompress.py +4 -4
- imap_processing/tests/conftest.py +46 -43
- 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_hi_l1b.py +2 -2
- imap_processing/tests/hi/test_l1a.py +31 -58
- imap_processing/tests/hi/test_science_direct_event.py +58 -0
- imap_processing/tests/hit/test_data/sci_sample1.ccsds +0 -0
- imap_processing/tests/hit/test_decom_hit.py +60 -50
- imap_processing/tests/hit/test_hit_l1a.py +327 -12
- imap_processing/tests/hit/test_hit_l1b.py +76 -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 +1 -1
- imap_processing/tests/idex/test_idex_l0.py +1 -1
- imap_processing/tests/idex/test_idex_l1a.py +7 -1
- 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 +67 -3
- 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/test_mag_l1b.py +39 -5
- imap_processing/tests/spice/test_geometry.py +32 -6
- 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/test_swe_l2.py +64 -8
- imap_processing/tests/test_utils.py +1 -1
- 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/unit/test_de.py +8 -3
- imap_processing/tests/ultra/unit/test_spatial_utils.py +125 -0
- imap_processing/tests/ultra/unit/test_ultra_l1b_extended.py +39 -29
- imap_processing/tests/ultra/unit/test_ultra_l1c_pset_bins.py +2 -25
- imap_processing/ultra/constants.py +4 -0
- imap_processing/ultra/l1b/de.py +8 -14
- imap_processing/ultra/l1b/ultra_l1b_extended.py +29 -70
- imap_processing/ultra/l1c/ultra_l1c_pset_bins.py +1 -36
- imap_processing/ultra/utils/spatial_utils.py +221 -0
- {imap_processing-0.8.0.dist-info → imap_processing-0.9.0.dist-info}/METADATA +1 -1
- {imap_processing-0.8.0.dist-info → imap_processing-0.9.0.dist-info}/RECORD +94 -76
- imap_processing/hi/l0/__init__.py +0 -0
- imap_processing/hi/l0/decom_hi.py +0 -24
- imap_processing/hi/packet_definitions/hi_packet_definition.xml +0 -482
- imap_processing/tests/hi/test_decom.py +0 -55
- imap_processing/tests/hi/test_l1a_sci_de.py +0 -72
- {imap_processing-0.8.0.dist-info → imap_processing-0.9.0.dist-info}/LICENSE +0 -0
- {imap_processing-0.8.0.dist-info → imap_processing-0.9.0.dist-info}/WHEEL +0 -0
- {imap_processing-0.8.0.dist-info → imap_processing-0.9.0.dist-info}/entry_points.txt +0 -0
|
@@ -15,7 +15,6 @@ from imap_processing.hit.l0.decom_hit import (
|
|
|
15
15
|
is_sequential,
|
|
16
16
|
parse_count_rates,
|
|
17
17
|
parse_data,
|
|
18
|
-
subcom_sectorates,
|
|
19
18
|
update_ccsds_header_dims,
|
|
20
19
|
)
|
|
21
20
|
from imap_processing.utils import packet_file_to_datasets
|
|
@@ -201,45 +200,6 @@ def test_assemble_science_frames(sci_dataset):
|
|
|
201
200
|
assert "pha_raw" in updated_dataset
|
|
202
201
|
|
|
203
202
|
|
|
204
|
-
def test_subcom_sectorates(sci_dataset):
|
|
205
|
-
"""Test the subcom_sectorates function.
|
|
206
|
-
|
|
207
|
-
This function organizes the sector rates data
|
|
208
|
-
into new variables for each species and adds
|
|
209
|
-
them to the dataset.
|
|
210
|
-
"""
|
|
211
|
-
|
|
212
|
-
# Prepare the input needed for the function to be called
|
|
213
|
-
sci_dataset = update_ccsds_header_dims(sci_dataset)
|
|
214
|
-
sci_dataset = assemble_science_frames(sci_dataset)
|
|
215
|
-
parse_count_rates(sci_dataset)
|
|
216
|
-
|
|
217
|
-
# Call the function to be tested
|
|
218
|
-
subcom_sectorates(sci_dataset)
|
|
219
|
-
|
|
220
|
-
# Check if the dataset has the expected new variables
|
|
221
|
-
for species in ["H", "4He", "CNO", "NeMgSi", "Fe"]:
|
|
222
|
-
assert species in sci_dataset
|
|
223
|
-
assert f"{species}_energy_min" in sci_dataset
|
|
224
|
-
assert f"{species}_energy_max" in sci_dataset
|
|
225
|
-
|
|
226
|
-
# Check the shape of the new variables
|
|
227
|
-
for species in ["H", "4He", "CNO", "NeMgSi", "Fe"]:
|
|
228
|
-
if species == "H":
|
|
229
|
-
assert sci_dataset[species].shape == (86, 3, 8, 15)
|
|
230
|
-
assert sci_dataset[f"{species}_energy_min"].shape == (3,)
|
|
231
|
-
elif species in ("4He", "CNO", "NeMgSi"):
|
|
232
|
-
assert sci_dataset[species].shape == (86, 2, 8, 15)
|
|
233
|
-
assert sci_dataset[f"{species}_energy_min"].shape == (2,)
|
|
234
|
-
elif species == "Fe":
|
|
235
|
-
assert sci_dataset[species].shape == (86, 1, 8, 15)
|
|
236
|
-
assert sci_dataset[f"{species}_energy_min"].shape == (1,)
|
|
237
|
-
assert (
|
|
238
|
-
sci_dataset[f"{species}_energy_max"].shape
|
|
239
|
-
== sci_dataset[f"{species}_energy_min"].shape
|
|
240
|
-
)
|
|
241
|
-
|
|
242
|
-
|
|
243
203
|
@pytest.mark.parametrize(
|
|
244
204
|
"packed, expected",
|
|
245
205
|
[
|
|
@@ -266,14 +226,64 @@ def test_decom_hit(sci_dataset):
|
|
|
266
226
|
This function orchestrates the unpacking and decompression
|
|
267
227
|
of the HIT science data.
|
|
268
228
|
"""
|
|
269
|
-
# TODO: complete this test once the function is complete
|
|
270
229
|
updated_dataset = decom_hit(sci_dataset)
|
|
271
|
-
# Check if the dataset has the expected
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
230
|
+
# Check if the dataset has the expected data variables
|
|
231
|
+
sci_fields = [
|
|
232
|
+
"version",
|
|
233
|
+
"type",
|
|
234
|
+
"sec_hdr_flg",
|
|
235
|
+
"pkt_apid",
|
|
236
|
+
"seq_flgs",
|
|
237
|
+
"src_seq_ctr",
|
|
238
|
+
"pkt_len",
|
|
239
|
+
"pha_raw",
|
|
240
|
+
"hdr_unit_num",
|
|
241
|
+
"hdr_frame_version",
|
|
242
|
+
"hdr_dynamic_threshold_state",
|
|
243
|
+
"hdr_leak_conv",
|
|
244
|
+
"hdr_heater_duty_cycle",
|
|
245
|
+
"hdr_code_ok",
|
|
246
|
+
"hdr_minute_cnt",
|
|
247
|
+
"livetime",
|
|
248
|
+
"num_trig",
|
|
249
|
+
"num_reject",
|
|
250
|
+
"num_acc_w_pha",
|
|
251
|
+
"num_acc_no_pha",
|
|
252
|
+
"num_haz_trig",
|
|
253
|
+
"num_haz_reject",
|
|
254
|
+
"num_haz_acc_w_pha",
|
|
255
|
+
"num_haz_acc_no_pha",
|
|
256
|
+
"sngrates",
|
|
257
|
+
"nread",
|
|
258
|
+
"nhazard",
|
|
259
|
+
"nadcstim",
|
|
260
|
+
"nodd",
|
|
261
|
+
"noddfix",
|
|
262
|
+
"nmulti",
|
|
263
|
+
"nmultifix",
|
|
264
|
+
"nbadtraj",
|
|
265
|
+
"nl2",
|
|
266
|
+
"nl3",
|
|
267
|
+
"nl4",
|
|
268
|
+
"npen",
|
|
269
|
+
"nformat",
|
|
270
|
+
"naside",
|
|
271
|
+
"nbside",
|
|
272
|
+
"nerror",
|
|
273
|
+
"nbadtags",
|
|
274
|
+
"coinrates",
|
|
275
|
+
"bufrates",
|
|
276
|
+
"l2fgrates",
|
|
277
|
+
"l2bgrates",
|
|
278
|
+
"l3fgrates",
|
|
279
|
+
"l3bgrates",
|
|
280
|
+
"penfgrates",
|
|
281
|
+
"penbgrates",
|
|
282
|
+
"ialirtrates",
|
|
283
|
+
"sectorates",
|
|
284
|
+
"l4fgrates",
|
|
285
|
+
"l4bgrates",
|
|
286
|
+
]
|
|
287
|
+
|
|
288
|
+
for field in sci_fields:
|
|
289
|
+
assert field in updated_dataset
|
|
@@ -1,29 +1,344 @@
|
|
|
1
|
+
import numpy as np
|
|
2
|
+
import pandas as pd
|
|
1
3
|
import pytest
|
|
2
4
|
import xarray as xr
|
|
3
5
|
|
|
4
6
|
from imap_processing import imap_module_directory
|
|
5
|
-
from imap_processing.hit.
|
|
7
|
+
from imap_processing.hit.hit_utils import (
|
|
8
|
+
HitAPID,
|
|
9
|
+
get_datasets_by_apid,
|
|
10
|
+
)
|
|
11
|
+
from imap_processing.hit.l1a.hit_l1a import decom_hit, hit_l1a, subcom_sectorates
|
|
12
|
+
|
|
13
|
+
# TODO: Packet files are per apid at the moment so the tests currently
|
|
14
|
+
# reflect this. Eventually, HIT will provide a packet file with all apids
|
|
15
|
+
# and the tests will need to be updated.
|
|
6
16
|
|
|
7
17
|
|
|
8
18
|
@pytest.fixture(scope="module")
|
|
9
|
-
def
|
|
19
|
+
def hk_packet_filepath():
|
|
10
20
|
"""Set path to test data file"""
|
|
11
21
|
return (
|
|
12
22
|
imap_module_directory / "tests/hit/test_data/imap_hit_l0_raw_20100105_v001.pkts"
|
|
13
23
|
)
|
|
14
24
|
|
|
15
25
|
|
|
16
|
-
|
|
17
|
-
|
|
26
|
+
@pytest.fixture(scope="module")
|
|
27
|
+
def sci_packet_filepath():
|
|
28
|
+
"""Set path to test data file"""
|
|
29
|
+
return imap_module_directory / "tests/hit/test_data/sci_sample1.ccsds"
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
def test_validate_l1a_housekeeping_data(hk_packet_filepath):
|
|
33
|
+
"""Validate the housekeeping dataset created by the L1A processing.
|
|
34
|
+
|
|
35
|
+
Compares the processed housekeeping data with expected values from
|
|
36
|
+
a validation csv file.
|
|
37
|
+
|
|
38
|
+
Parameters
|
|
39
|
+
----------
|
|
40
|
+
hk_packet_filepath : str
|
|
41
|
+
File path to housekeeping ccsds file
|
|
42
|
+
"""
|
|
43
|
+
datasets = hit_l1a(hk_packet_filepath, "001")
|
|
44
|
+
hk_dataset = None
|
|
45
|
+
for dataset in datasets:
|
|
46
|
+
if dataset.attrs["Logical_source"] == "imap_hit_l1a_hk":
|
|
47
|
+
hk_dataset = dataset
|
|
48
|
+
|
|
49
|
+
# Load the validation data
|
|
50
|
+
validation_file = (
|
|
51
|
+
imap_module_directory / "tests/hit/validation_data/hskp_sample_raw.csv"
|
|
52
|
+
)
|
|
53
|
+
validation_data = pd.read_csv(validation_file)
|
|
54
|
+
validation_data.columns = validation_data.columns.str.lower()
|
|
55
|
+
|
|
56
|
+
# Get a list of leak columns in ascending order
|
|
57
|
+
# (LEAK_I_00, LEAK_I_01, ..., LEAK_I_63)
|
|
58
|
+
# and group values into a single column
|
|
59
|
+
leak_columns = [col for col in validation_data.columns if col.startswith("leak")][
|
|
60
|
+
::-1
|
|
61
|
+
]
|
|
62
|
+
validation_data["leak_i"] = validation_data[leak_columns].apply(
|
|
63
|
+
lambda row: row.values, axis=1
|
|
64
|
+
)
|
|
65
|
+
validation_data.drop(columns=leak_columns, inplace=True)
|
|
66
|
+
|
|
67
|
+
# Define the keys that should have dropped from the housekeeping dataset
|
|
68
|
+
dropped_fields = {
|
|
69
|
+
"pkt_apid",
|
|
70
|
+
"sc_tick",
|
|
71
|
+
"version",
|
|
72
|
+
"type",
|
|
73
|
+
"sec_hdr_flg",
|
|
74
|
+
"seq_flgs",
|
|
75
|
+
"src_seq_ctr",
|
|
76
|
+
"pkt_len",
|
|
77
|
+
"hskp_spare1",
|
|
78
|
+
"hskp_spare2",
|
|
79
|
+
"hskp_spare3",
|
|
80
|
+
"hskp_spare4",
|
|
81
|
+
"hskp_spare5",
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
# Define the keys that should be ignored in the validation
|
|
85
|
+
# like ccsds headers
|
|
86
|
+
ignore_validation_fields = {
|
|
87
|
+
"ccsds_version",
|
|
88
|
+
"ccsds_type",
|
|
89
|
+
"ccsds_sec_hdr_flag",
|
|
90
|
+
"ccsds_appid",
|
|
91
|
+
"ccsds_grp_flag",
|
|
92
|
+
"ccsds_seq_cnt",
|
|
93
|
+
"ccsds_length",
|
|
94
|
+
"shcoarse",
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
# Check that dropped variables are not in the dataset
|
|
98
|
+
assert set(dropped_fields).isdisjoint(set(hk_dataset.data_vars.keys()))
|
|
99
|
+
|
|
100
|
+
# Compare the housekeeping dataset with the expected validation data
|
|
101
|
+
for field in validation_data.columns:
|
|
102
|
+
if field not in ignore_validation_fields:
|
|
103
|
+
assert field in hk_dataset.data_vars.keys()
|
|
104
|
+
for pkt in range(validation_data.shape[0]):
|
|
105
|
+
assert np.array_equal(
|
|
106
|
+
hk_dataset[field][pkt].data, validation_data[field][pkt]
|
|
107
|
+
)
|
|
108
|
+
|
|
109
|
+
|
|
110
|
+
def test_subcom_sectorates(sci_packet_filepath):
|
|
111
|
+
"""Test the subcom_sectorates function.
|
|
112
|
+
|
|
113
|
+
This function organizes the sector rates data
|
|
114
|
+
by species and adds the data as new variables
|
|
115
|
+
to the dataset.
|
|
116
|
+
"""
|
|
117
|
+
|
|
118
|
+
# Unpack and decompress ccsds file to xarray datasets
|
|
119
|
+
sci_dataset = get_datasets_by_apid(sci_packet_filepath)[HitAPID.HIT_SCIENCE]
|
|
120
|
+
sci_dataset = decom_hit(sci_dataset)
|
|
121
|
+
|
|
122
|
+
# Call the function to be tested
|
|
123
|
+
subcom_sectorates(sci_dataset)
|
|
124
|
+
|
|
125
|
+
# Number of science frames in the dataset
|
|
126
|
+
frames = sci_dataset["epoch"].shape[0]
|
|
127
|
+
|
|
128
|
+
# Check if the dataset has the expected new variables
|
|
129
|
+
for species in ["h", "he4", "cno", "nemgsi", "fe"]:
|
|
130
|
+
assert f"{species}_counts_sectored" in sci_dataset
|
|
131
|
+
assert f"{species}_energy_min" in sci_dataset
|
|
132
|
+
assert f"{species}_energy_max" in sci_dataset
|
|
133
|
+
|
|
134
|
+
# Check the shape of the new data variables
|
|
135
|
+
if species == "h":
|
|
136
|
+
assert sci_dataset[f"{species}_counts_sectored"].shape == (frames, 3, 8, 15)
|
|
137
|
+
assert sci_dataset[f"{species}_energy_min"].shape == (3,)
|
|
138
|
+
elif species in ("4he", "cno", "nemgsi"):
|
|
139
|
+
assert sci_dataset[f"{species}_counts_sectored"].shape == (frames, 2, 8, 15)
|
|
140
|
+
assert sci_dataset[f"{species}_energy_min"].shape == (2,)
|
|
141
|
+
elif species == "fe":
|
|
142
|
+
assert sci_dataset[f"{species}_counts_sectored"].shape == (frames, 1, 8, 15)
|
|
143
|
+
assert sci_dataset[f"{species}_energy_min"].shape == (1,)
|
|
144
|
+
assert (
|
|
145
|
+
sci_dataset[f"{species}_energy_max"].shape
|
|
146
|
+
== sci_dataset[f"{species}_energy_min"].shape
|
|
147
|
+
)
|
|
148
|
+
|
|
149
|
+
|
|
150
|
+
def test_validate_l1a_counts_data(sci_packet_filepath):
|
|
151
|
+
"""Compare the output of the L1A processing to the validation data.
|
|
152
|
+
|
|
153
|
+
This test compares the counts data product with the validation data.
|
|
154
|
+
The PHA data product is not validated since it's not being decommutated.
|
|
155
|
+
|
|
156
|
+
Parameters
|
|
157
|
+
----------
|
|
158
|
+
sci_packet_filepath : str
|
|
159
|
+
Path to ccsds file for science data
|
|
160
|
+
"""
|
|
161
|
+
# Process the sample data
|
|
162
|
+
processed_datasets = hit_l1a(sci_packet_filepath, "001")
|
|
163
|
+
l1a_counts_data = processed_datasets[0]
|
|
164
|
+
|
|
165
|
+
# Read in the validation data
|
|
166
|
+
validation_data = pd.read_csv(
|
|
167
|
+
imap_module_directory / "tests/hit/validation_data/sci_sample_raw1.csv"
|
|
168
|
+
)
|
|
169
|
+
|
|
170
|
+
# Helper functions for this test
|
|
171
|
+
def consolidate_rate_columns(data, rate_columns):
|
|
172
|
+
# The validation data isn't organized by arrays.
|
|
173
|
+
# Each value is in a separate column.
|
|
174
|
+
# Aggregate related data into arrays.
|
|
175
|
+
for new_col, prefix in rate_columns.items():
|
|
176
|
+
columns = [col for col in data.columns if prefix in col]
|
|
177
|
+
data[new_col] = data[columns].apply(lambda row: row.values, axis=1)
|
|
178
|
+
if new_col == "sectorates":
|
|
179
|
+
# Differentiate between the sectorate columns with three and
|
|
180
|
+
# five digits in the name. Those with three digits contain the
|
|
181
|
+
# sectorate value for the science frame and those with five digits
|
|
182
|
+
# are the sectorate values with the mod value appended to the end.
|
|
183
|
+
# The mod value determines the species and energy range for that
|
|
184
|
+
# science frame
|
|
185
|
+
sectorates_three_digits = data.filter(
|
|
186
|
+
regex=r"^SECTORATES_\d{3}$"
|
|
187
|
+
).columns
|
|
188
|
+
sectorates_five_digits = data.filter(
|
|
189
|
+
regex=r"^SECTORATES_\d{3}_\d{1}$"
|
|
190
|
+
).columns
|
|
191
|
+
data["sectorates"] = data[sectorates_three_digits].apply(
|
|
192
|
+
lambda row: row.values.reshape(8, 15), axis=1
|
|
193
|
+
)
|
|
194
|
+
data["sectorates_by_mod_val"] = data[sectorates_five_digits].apply(
|
|
195
|
+
lambda row: row.values, axis=1
|
|
196
|
+
)
|
|
197
|
+
data.drop(columns=columns, inplace=True)
|
|
198
|
+
return data
|
|
199
|
+
|
|
200
|
+
def process_single_rates(data):
|
|
201
|
+
# Combine the single rates for high and low gain into a 2D array
|
|
202
|
+
data["sngrates"] = data.apply(
|
|
203
|
+
lambda row: np.array([row["sngrates_hg"], row["sngrates_lg"]]), axis=1
|
|
204
|
+
)
|
|
205
|
+
data.drop(columns=["sngrates_hg", "sngrates_lg"], inplace=True)
|
|
206
|
+
return data
|
|
207
|
+
|
|
208
|
+
def process_sectorates(data):
|
|
209
|
+
# Add species and energy index to the data frame for each science frame
|
|
210
|
+
# First find the mod value for each science frame which equals the first index
|
|
211
|
+
# in the sectorates_by_mod_val array that has a value instead of a blank space
|
|
212
|
+
data["mod_10"] = data["sectorates_by_mod_val"].apply(
|
|
213
|
+
lambda row: next((i for i, value in enumerate(row) if value != " "), None)
|
|
214
|
+
)
|
|
215
|
+
# Mapping of mod value to species and energy index
|
|
216
|
+
species_energy = {
|
|
217
|
+
0: {"species": "H", "energy_idx": 0},
|
|
218
|
+
1: {"species": "H", "energy_idx": 1},
|
|
219
|
+
2: {"species": "H", "energy_idx": 2},
|
|
220
|
+
3: {"species": "He4", "energy_idx": 0},
|
|
221
|
+
4: {"species": "He4", "energy_idx": 1},
|
|
222
|
+
5: {"species": "CNO", "energy_idx": 0},
|
|
223
|
+
6: {"species": "CNO", "energy_idx": 1},
|
|
224
|
+
7: {"species": "NeMgSi", "energy_idx": 0},
|
|
225
|
+
8: {"species": "NeMgSi", "energy_idx": 1},
|
|
226
|
+
9: {"species": "Fe", "energy_idx": 0},
|
|
227
|
+
}
|
|
228
|
+
# Use the mod 10 value to determine the species and energy index
|
|
229
|
+
# for each science frame and add this information to the data frame
|
|
230
|
+
data["species"] = data["mod_10"].apply(
|
|
231
|
+
lambda row: species_energy[row]["species"].lower()
|
|
232
|
+
if row is not None
|
|
233
|
+
else None
|
|
234
|
+
)
|
|
235
|
+
data["energy_idx"] = data["mod_10"].apply(
|
|
236
|
+
lambda row: species_energy[row]["energy_idx"] if row is not None else None
|
|
237
|
+
)
|
|
238
|
+
data.drop(columns=["sectorates_by_mod_val", "mod_10"], inplace=True)
|
|
239
|
+
return data
|
|
240
|
+
|
|
241
|
+
def compare_data(expected_data, actual_data, skip):
|
|
242
|
+
# Compare the processed data to the validation data
|
|
243
|
+
for field in expected_data.columns:
|
|
244
|
+
if field not in [
|
|
245
|
+
"sc_tick",
|
|
246
|
+
"hdr_status_bits",
|
|
247
|
+
"species",
|
|
248
|
+
"energy_idx",
|
|
249
|
+
]:
|
|
250
|
+
assert field in l1a_counts_data.data_vars.keys()
|
|
251
|
+
if field not in ignore:
|
|
252
|
+
for frame in range(expected_data.shape[0]):
|
|
253
|
+
if field == "species":
|
|
254
|
+
species = expected_data[field][frame]
|
|
255
|
+
energy_idx = expected_data["energy_idx"][frame]
|
|
256
|
+
assert np.array_equal(
|
|
257
|
+
actual_data[f"{species}_counts_sectored"][frame][
|
|
258
|
+
energy_idx
|
|
259
|
+
].data,
|
|
260
|
+
expected_data["sectorates"][frame],
|
|
261
|
+
)
|
|
262
|
+
else:
|
|
263
|
+
assert np.array_equal(
|
|
264
|
+
actual_data[field][frame].data, expected_data[field][frame]
|
|
265
|
+
)
|
|
266
|
+
|
|
267
|
+
rate_columns = {
|
|
268
|
+
"coinrates": "COINRATES_",
|
|
269
|
+
"bufrates": "BUFRATES_",
|
|
270
|
+
"l2fgrates": "L2FGRATES_",
|
|
271
|
+
"l2bgrates": "L2BGRATES_",
|
|
272
|
+
"l3fgrates": "L3FGRATES_",
|
|
273
|
+
"l3bgrates": "L3BGRATES_",
|
|
274
|
+
"penfgrates": "PENFGRATES_",
|
|
275
|
+
"penbgrates": "PENBGRATES_",
|
|
276
|
+
"sectorates": "SECTORATES_",
|
|
277
|
+
"l4fgrates": "L4FGRATES_",
|
|
278
|
+
"l4bgrates": "L4BGRATES_",
|
|
279
|
+
"ialirtrates": "IALIRTRATES_",
|
|
280
|
+
"sngrates_hg": "SNGRATES_HG_",
|
|
281
|
+
"sngrates_lg": "SNGRATES_LG_",
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
# Prepare validation data for comparison with processed data
|
|
285
|
+
validation_data.columns = validation_data.columns.str.strip()
|
|
286
|
+
validation_data = consolidate_rate_columns(validation_data, rate_columns)
|
|
287
|
+
validation_data = process_single_rates(validation_data)
|
|
288
|
+
validation_data = process_sectorates(validation_data)
|
|
289
|
+
|
|
290
|
+
# Fields to skip in comparison. CCSDS headers plus a few others that are not
|
|
291
|
+
# relevant to the comparison.
|
|
292
|
+
# The CCSDS header fields contain data per packet in the dataset, but the
|
|
293
|
+
# validation data has a value per science frame so skipping comparison for now
|
|
294
|
+
ignore = [
|
|
295
|
+
"version",
|
|
296
|
+
"type",
|
|
297
|
+
"sec_hdr_flg",
|
|
298
|
+
"pkt_apid",
|
|
299
|
+
"seq_flgs",
|
|
300
|
+
"src_seq_ctr",
|
|
301
|
+
"pkt_len",
|
|
302
|
+
"sc_tick",
|
|
303
|
+
"hdr_status_bits",
|
|
304
|
+
"energy_idx",
|
|
305
|
+
]
|
|
306
|
+
|
|
307
|
+
# Compare processed data to validation data
|
|
308
|
+
validation_data.columns = validation_data.columns.str.lower()
|
|
309
|
+
compare_data(validation_data, l1a_counts_data, ignore)
|
|
310
|
+
|
|
311
|
+
# TODO: add validation for hdr_status_bits once validation data has been updated
|
|
312
|
+
# to include this field broken out into its subfields
|
|
313
|
+
|
|
314
|
+
# TODO: add validation for CCSDS fields? currently validation data only has
|
|
315
|
+
# one value per frame and the processed data has one value per packet.
|
|
316
|
+
|
|
317
|
+
|
|
318
|
+
def test_hit_l1a(hk_packet_filepath, sci_packet_filepath):
|
|
319
|
+
"""Create L1A datasets from packet files.
|
|
18
320
|
|
|
19
321
|
Parameters
|
|
20
322
|
----------
|
|
21
|
-
|
|
22
|
-
Path to ccsds file
|
|
323
|
+
hk_packet_filepath : str
|
|
324
|
+
Path to ccsds file for housekeeping data
|
|
325
|
+
sci_packet_filepath : str
|
|
326
|
+
Path to ccsds file for science data
|
|
23
327
|
"""
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
328
|
+
for packet_filepath in [hk_packet_filepath, sci_packet_filepath]:
|
|
329
|
+
processed_datasets = hit_l1a(packet_filepath, "001")
|
|
330
|
+
assert isinstance(processed_datasets, list)
|
|
331
|
+
assert all(isinstance(ds, xr.Dataset) for ds in processed_datasets)
|
|
332
|
+
if packet_filepath == hk_packet_filepath:
|
|
333
|
+
assert len(processed_datasets) == 1
|
|
334
|
+
assert processed_datasets[0].attrs["Logical_source"] == "imap_hit_l1a_hk"
|
|
335
|
+
else:
|
|
336
|
+
assert len(processed_datasets) == 2
|
|
337
|
+
assert (
|
|
338
|
+
processed_datasets[0].attrs["Logical_source"]
|
|
339
|
+
== "imap_hit_l1a_count-rates"
|
|
340
|
+
)
|
|
341
|
+
assert (
|
|
342
|
+
processed_datasets[1].attrs["Logical_source"]
|
|
343
|
+
== "imap_hit_l1a_pulse-height-events"
|
|
344
|
+
)
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import pandas as pd
|
|
1
2
|
import pytest
|
|
2
3
|
import xarray as xr
|
|
3
4
|
|
|
@@ -165,6 +166,81 @@ def test_hit_l1b_hk_dataset_attributes(hk_dataset):
|
|
|
165
166
|
assert hk_dataset.coords.keys() == dataset_coords_dims
|
|
166
167
|
|
|
167
168
|
|
|
169
|
+
def test_validate_l1b_housekeeping_data(hk_dataset):
|
|
170
|
+
"""Validate the housekeeping dataset created by the L1B processing.
|
|
171
|
+
|
|
172
|
+
Parameters
|
|
173
|
+
----------
|
|
174
|
+
hk_dataset : xr.Dataset
|
|
175
|
+
Housekeeping dataset created by the L1B processing.
|
|
176
|
+
"""
|
|
177
|
+
# TODO: finish test. HIT will provide an updated validation file to fix issues:
|
|
178
|
+
# - some fields have strings as values but in the processed data they're integers
|
|
179
|
+
# - Some columns have blank cells where there should be data
|
|
180
|
+
|
|
181
|
+
# Load the validation data
|
|
182
|
+
validation_file = (
|
|
183
|
+
imap_module_directory / "tests/hit/validation_data/hskp_sample_eu.csv"
|
|
184
|
+
)
|
|
185
|
+
validation_data = pd.read_csv(validation_file)
|
|
186
|
+
validation_data.columns = validation_data.columns.str.lower().str.strip()
|
|
187
|
+
|
|
188
|
+
# Get a list of leak columns in ascending order
|
|
189
|
+
# (LEAK_I_00, LEAK_I_01, ..., LEAK_I_63)
|
|
190
|
+
# and group values into a single column
|
|
191
|
+
leak_columns = [
|
|
192
|
+
col for col in validation_data.columns if col.startswith("leak_i_")
|
|
193
|
+
][::-1]
|
|
194
|
+
validation_data["leak_i"] = validation_data[leak_columns].apply(
|
|
195
|
+
lambda row: row.values, axis=1
|
|
196
|
+
)
|
|
197
|
+
validation_data.drop(columns=leak_columns, inplace=True)
|
|
198
|
+
|
|
199
|
+
# Define the keys that should have dropped from the housekeeping dataset
|
|
200
|
+
dropped_fields = {
|
|
201
|
+
"pkt_apid",
|
|
202
|
+
"sc_tick",
|
|
203
|
+
"version",
|
|
204
|
+
"type",
|
|
205
|
+
"sec_hdr_flg",
|
|
206
|
+
"seq_flgs",
|
|
207
|
+
"src_seq_ctr",
|
|
208
|
+
"pkt_len",
|
|
209
|
+
"hskp_spare1",
|
|
210
|
+
"hskp_spare2",
|
|
211
|
+
"hskp_spare3",
|
|
212
|
+
"hskp_spare4",
|
|
213
|
+
"hskp_spare5",
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
# Check that dropped variables are not in the dataset
|
|
217
|
+
assert set(dropped_fields).isdisjoint(set(hk_dataset.data_vars.keys()))
|
|
218
|
+
|
|
219
|
+
# TODO: uncomment block after new validation data is provided
|
|
220
|
+
# Define the keys that should be ignored in the validation
|
|
221
|
+
# like ccsds headers
|
|
222
|
+
# ignore_validation_fields = {
|
|
223
|
+
# "ccsds_version",
|
|
224
|
+
# "ccsds_type",
|
|
225
|
+
# "ccsds_sec_hdr_flag",
|
|
226
|
+
# "ccsds_appid",
|
|
227
|
+
# "ccsds_grp_flag",
|
|
228
|
+
# "ccsds_seq_cnt",
|
|
229
|
+
# "ccsds_length",
|
|
230
|
+
# "sc_tick",
|
|
231
|
+
# }
|
|
232
|
+
|
|
233
|
+
# # Compare the housekeeping dataset with the expected validation data
|
|
234
|
+
# for field in validation_data.columns:
|
|
235
|
+
# if field not in ignore_validation_fields:
|
|
236
|
+
# print(field)
|
|
237
|
+
# assert field in hk_dataset.data_vars.keys()
|
|
238
|
+
# for pkt in range(validation_data.shape[0]):
|
|
239
|
+
# assert np.array_equal(
|
|
240
|
+
# hk_dataset[field][pkt].data, validation_data[field][pkt]
|
|
241
|
+
# )
|
|
242
|
+
|
|
243
|
+
|
|
168
244
|
def test_hit_l1b(dependencies):
|
|
169
245
|
"""Test creating L1B CDF files
|
|
170
246
|
|