Skip to content

Commit 95e5bf5

Browse files
authored
1147 hi l1c add calibration product coordinate to pset (IMAP-Science-Operations-Center#1172)
* Add calibration product dimension to pset data product * Add test coverage for coordinate size checks * fix test broken by addition of calibration_prod to pset * Fix swapped CATDESC and FIELDNAM
1 parent 03a2042 commit 95e5bf5

File tree

4 files changed

+70
-11
lines changed

4 files changed

+70
-11
lines changed

imap_processing/cdf/config/imap_hi_variable_attrs.yaml

Lines changed: 36 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,20 @@ hi_pset_esa_energy_step:
312312
VAR_TYPE: support_data
313313
dtype: uint8
314314

315+
hi_pset_calibration_prod:
316+
CATDESC: Coincidence types are combined into various calibration products
317+
FIELDNAM: Calibration product number
318+
FILLVAL: 65535
319+
FORMAT: I1
320+
LABLAXIS: Calibration Prod
321+
UNITS: " "
322+
SCALE_TYP: linear
323+
MONOTON: INCREASE
324+
VALIDMIN: 0
325+
VALIDMAX: 4
326+
VAR_TYPE: support_data
327+
dtype: uint8
328+
315329
hi_pset_spin_angle_bin:
316330
CATDESC: 0.1 degree spin angle bins
317331
FIELDNAM: Spin angle bin index
@@ -377,9 +391,11 @@ hi_pset_counts:
377391
FIELDNAM: Binned DE counts
378392
DEPEND_0: epoch
379393
DEPEND_1: esa_energy_step
380-
DEPEND_2: spin_angle_bin
394+
DEPEND_2: calibration_prod
395+
DEPEND_3: spin_angle_bin
381396
LABL_PTR_1: esa_energy_step_label
382-
LABL_PTR_2: spin_bin_label
397+
LABL_PTR_2: calibration_prod_label
398+
LABL_PTR_3: spin_bin_label
383399
DISPLAY_TYPE: stack_plot
384400
FORMAT: I5
385401

@@ -389,9 +405,11 @@ hi_pset_exposure_times:
389405
FIELDNAM: Bin exposure times
390406
DEPEND_0: epoch
391407
DEPEND_1: esa_energy_step
392-
DEPEND_2: spin_angle_bin
408+
DEPEND_2: calibration_prod
409+
DEPEND_3: spin_angle_bin
393410
LABL_PTR_1: esa_energy_step_label
394-
LABL_PTR_2: spin_bin_label
411+
LABL_PTR_2: calibration_prod_label
412+
LABL_PTR_3: spin_bin_label
395413
UNITS: sec
396414
DISPLAY_TYPE: stack_plot
397415
FORMAT: F6.2
@@ -402,9 +420,11 @@ hi_pset_background_rates:
402420
FIELDNAM: Background count rates
403421
DEPEND_0: epoch
404422
DEPEND_1: esa_energy_step
405-
DEPEND_2: spin_angle_bin
423+
DEPEND_2: calibration_prod
424+
DEPEND_3: spin_angle_bin
406425
LABL_PTR_1: esa_energy_step_label
407-
LABL_PTR_2: spin_bin_label
426+
LABL_PTR_2: calibration_prod_label
427+
LABL_PTR_3: spin_bin_label
408428
UNITS: counts / s
409429
DISPLAY_TYPE: stack_plot
410430
FORMAT: F4.2
@@ -415,9 +435,11 @@ hi_pset_background_rates_uncertainty:
415435
FIELDNAM: Background count rate uncertainties
416436
DEPEND_0: epoch
417437
DEPEND_1: esa_energy_step
418-
DEPEND_2: spin_angle_bin
438+
DEPEND_2: calibration_prod
439+
DEPEND_3: spin_angle_bin
419440
LABL_PTR_1: esa_energy_step_label
420-
LABL_PTR_2: spin_bin_label
441+
LABL_PTR_2: calibration_prod_label
442+
LABL_PTR_3: spin_bin_label
421443
UNITS: counts / s
422444
DISPLAY_TYPE: stack_plot
423445
FORMAT: F4.2
@@ -435,6 +457,12 @@ hi_pset_esa_energy_step_label:
435457
FORMAT: A4
436458
VAR_TYPE: metadata
437459

460+
hi_pset_calibration_prod_label:
461+
CATDESC: Label calibration product
462+
FIELDNAM: Label calibration product
463+
FORMAT: A4
464+
VAR_TYPE: metadata
465+
438466
hi_pset_label_vector_HAE:
439467
CATDESC: Label cartesian despun_z
440468
FIELDNAM: Label cartesian despun_z

imap_processing/hi/l1c/hi_l1c.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,20 @@ def allocate_pset_dataset(n_esa_steps: int, sensor_str: str) -> xr.Dataset:
115115
dims=["esa_energy_step"],
116116
attrs=attrs,
117117
)
118+
# TODO: define calibration product number to coincidence type mapping and
119+
# use the number of calibration products here. I believe it will be 5
120+
# 0 for any, 1-4, for the number of detector hits.
121+
n_calibration_prod = 5
122+
attrs = attr_mgr.get_variable_attributes(
123+
"hi_pset_calibration_prod", check_schema=False
124+
).copy()
125+
dtype = attrs.pop("dtype")
126+
coords["calibration_prod"] = xr.DataArray(
127+
np.arange(n_calibration_prod, dtype=dtype),
128+
name="calibration_prod",
129+
dims=["calibration_prod"],
130+
attrs=attrs,
131+
)
118132
# spin angle bins are 0.1 degree bins for full 360 degree spin
119133
attrs = attr_mgr.get_variable_attributes(
120134
"hi_pset_spin_angle_bin", check_schema=False
@@ -157,6 +171,14 @@ def allocate_pset_dataset(n_esa_steps: int, sensor_str: str) -> xr.Dataset:
157171
"hi_pset_esa_energy_step_label", check_schema=False
158172
),
159173
)
174+
data_vars["calibration_prod_label"] = xr.DataArray(
175+
coords["calibration_prod"].values.astype(str),
176+
name="calibration_prod_label",
177+
dims=["calibration_prod"],
178+
attrs=attr_mgr.get_variable_attributes(
179+
"hi_pset_calibration_prod_label", check_schema=False
180+
),
181+
)
160182
data_vars["spin_bin_label"] = xr.DataArray(
161183
coords["spin_angle_bin"].values.astype(str),
162184
name="spin_bin_label",

imap_processing/tests/hi/test_hi_l1c.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import numpy as np
44
import pytest
55

6+
from imap_processing.cdf.utils import write_cdf
67
from imap_processing.hi.l1a.hi_l1a import hi_l1a
78
from imap_processing.hi.l1b.hi_l1b import hi_l1b
89
from imap_processing.hi.l1c import hi_l1c
@@ -30,19 +31,26 @@ def test_generate_pset_dataset(create_de_data):
3031
def test_allocate_pset_dataset():
3132
"""Test coverage for allocate_pset_dataset function"""
3233
n_esa_steps = 10
34+
n_calibration_prods = 5
3335
sensor_str = HIAPID.H90_SCI_DE.sensor
3436
dataset = hi_l1c.allocate_pset_dataset(n_esa_steps, sensor_str)
3537

3638
assert dataset.epoch.size == 1
3739
assert dataset.spin_angle_bin.size == 3600
40+
assert dataset.esa_energy_step.size == n_esa_steps
41+
assert dataset.calibration_prod.size == n_calibration_prods
3842
np.testing.assert_array_equal(dataset.despun_z.data.shape, (1, 3))
3943
np.testing.assert_array_equal(dataset.hae_latitude.data.shape, (1, 3600))
4044
np.testing.assert_array_equal(dataset.hae_longitude.data.shape, (1, 3600))
41-
n_esa_step = dataset.esa_energy_step.data.size
4245
for var in [
4346
"counts",
4447
"exposure_times",
4548
"background_rates",
4649
"background_rates_uncertainty",
4750
]:
48-
np.testing.assert_array_equal(dataset[var].data.shape, (1, n_esa_step, 3600))
51+
np.testing.assert_array_equal(
52+
dataset[var].data.shape, (1, n_esa_steps, n_calibration_prods, 3600)
53+
)
54+
# Verify resulting CDF is ISTP compliant by writing to disk
55+
dataset.attrs["Data_version"] = 1
56+
write_cdf(dataset)

imap_processing/tests/hi/test_utils.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,14 +48,15 @@ def test_parse_sensor_number(test_str, expected):
4848
[
4949
("despun_z", (1, 3), (1, 3)),
5050
("hae_latitude", None, (1, 360)),
51-
("counts", None, (1, 10, 360)),
51+
("counts", None, (1, 10, 5, 360)),
5252
],
5353
)
5454
def test_full_dataarray(name, shape, expected_shape):
5555
"""Test coverage for full_dataarray function"""
5656
coords = {
5757
"epoch": xr.DataArray(np.array([0])),
5858
"esa_energy_step": xr.DataArray(np.arange(10)),
59+
"calibration_prod": xr.DataArray(np.arange(5)),
5960
"spin_angle_bin": xr.DataArray(np.arange(360)),
6061
}
6162
cdf_manager = ImapCdfAttributes()

0 commit comments

Comments
 (0)