Skip to content

Commit a39262f

Browse files
authored
Hi Processing fixes for SIT4 (IMAP-Science-Operations-Center#1785)
* Fix L1C PSET ISTP warning * Add epoch dimension to L2 solid_angle variable * Add epoch dimension to L2 solid_angle variable - test coverage * Convert obs_date to int64 after calculation * Don't check schema when getting variable attributes for label or delta variables * Make energy dependent attributes the default * Fix Hi L2 do_processing
1 parent 1103505 commit a39262f

File tree

10 files changed

+50
-29
lines changed

10 files changed

+50
-29
lines changed

imap_processing/cdf/config/imap_enamaps_l2-common_variable_attrs.yaml

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ sensitivity:
162162
DISPLAY_TYPE: image
163163
DICT_KEY: SPASE>Particle>ParticleType:Atom,ParticleQuantity:GeometricFactor,Qualifier:Directional,CoordinateSystemName:HAE,CoordinateRepresentation:Spherical
164164

165-
exposure_factor: &exposure_factor_energy_independent
165+
exposure_factor: &exposure_factor
166166
<<: *default_float32
167167
CATDESC: Exact or approximate time over which counts are accumulated.
168168
FIELDNAM: Exposure Times
@@ -173,7 +173,7 @@ exposure_factor: &exposure_factor_energy_independent
173173
DISPLAY_TYPE: no_plot
174174
DICT_KEY: SPASE>TemporalDescription:Exposure,Qualifier:Directional,CoordinateSystemName:HAE,CoordinateRepresentation:Spherical
175175

176-
obs_date: &obs_date_energy_independent
176+
obs_date: &obs_date
177177
<<: *default_int64
178178
datatype: int64
179179
CATDESC: Exposure time weighted mean collection date of data in a pixel.
@@ -195,15 +195,16 @@ obs_date_range:
195195
VAR_TYPE: data
196196
LABLAXIS: epoch
197197
DISPLAY_TYPE: image
198+
TIME_SCALE: Terrestrial Time
198199

199200
# These copied metadata vars will allow for variables
200201
# to be either energy-dependent or independent.
201202
# The tiling-specific YAML files will override the DEPENDs and LABL_PTRs.
202-
exposure_factor_energy_dependent:
203-
<<: *exposure_factor_energy_independent
203+
exposure_factor_energy_independent:
204+
<<: *exposure_factor
204205

205-
obs_date_energy_dependent:
206-
<<: *obs_date_energy_independent
206+
obs_date_energy_independent:
207+
<<: *obs_date
207208

208209
solid_angle:
209210
<<: *default_float32

imap_processing/cdf/config/imap_enamaps_l2-healpix_variable_attrs.yaml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,25 +75,25 @@ sensitivity:
7575
# These data variables will have an extra (energy) dimension
7676
# only if the energy dimension is present in the L1C data.
7777
# The default is energy-independent.
78-
exposure_factor:
78+
exposure_factor_energy_independent:
7979
DEPEND_1: pixel_index
8080
LABL_PTR_1: pixel_index_label
8181

82-
obs_date:
82+
obs_date_energy_independent:
8383
DEPEND_1: pixel_index
8484
LABL_PTR_1: pixel_index_label
8585

8686
obs_date_range:
8787
DEPEND_1: pixel_index
8888
LABL_PTR_1: pixel_index_label
8989

90-
exposure_factor_energy_dependent:
90+
exposure_factor:
9191
DEPEND_1: energy
9292
DEPEND_2: pixel_index
9393
LABL_PTR_1: energy_label
9494
LABL_PTR_2: pixel_index_label
9595

96-
obs_date_energy_dependent:
96+
obs_date:
9797
DEPEND_1: energy
9898
DEPEND_2: pixel_index
9999
LABL_PTR_1: energy_label

imap_processing/cdf/config/imap_enamaps_l2-rectangular_variable_attrs.yaml

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -90,33 +90,41 @@ sensitivity:
9090
# These data variables will have an extra (energy) dimension
9191
# only if the energy dimension is present in the L1C data.
9292
# The default is energy-independent.
93-
exposure_factor:
93+
exposure_factor_energy_independent:
9494
DEPEND_1: longitude
9595
DEPEND_2: latitude
9696
LABL_PTR_1: longitude_label
9797
LABL_PTR_2: latitude_label
9898

99-
obs_date:
99+
obs_date_energy_independent:
100100
DEPEND_1: longitude
101101
DEPEND_2: latitude
102102
LABL_PTR_1: longitude_label
103103
LABL_PTR_2: latitude_label
104104

105-
obs_date_range:
105+
obs_date_range_energy_independent:
106106
DEPEND_1: longitude
107107
DEPEND_2: latitude
108108
LABL_PTR_1: longitude_label
109109
LABL_PTR_2: latitude_label
110110

111-
exposure_factor_energy_dependent:
111+
exposure_factor:
112112
DEPEND_1: energy
113113
DEPEND_2: longitude
114114
DEPEND_3: latitude
115115
LABL_PTR_1: energy_label
116116
LABL_PTR_2: longitude_label
117117
LABL_PTR_3: latitude_label
118118

119-
obs_date_energy_dependent:
119+
obs_date:
120+
DEPEND_1: energy
121+
DEPEND_2: longitude
122+
DEPEND_3: latitude
123+
LABL_PTR_1: energy_label
124+
LABL_PTR_2: longitude_label
125+
LABL_PTR_3: latitude_label
126+
127+
obs_date_range:
120128
DEPEND_1: energy
121129
DEPEND_2: longitude
122130
DEPEND_3: latitude

imap_processing/cdf/config/imap_hi_variable_attrs.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -579,18 +579,21 @@ hi_pset_background_rates_uncertainty:
579579
hi_pset_spin_bin_label:
580580
CATDESC: Label spin angle bin
581581
FIELDNAM: Label spin angle bin
582+
DEPEND_1: spin_angle_bin
582583
FORMAT: A4
583584
VAR_TYPE: metadata
584585

585586
hi_pset_esa_energy_step_label:
586587
CATDESC: Label esa step
587588
FIELDNAM: Label esa step
589+
DEPEND_1: esa_energy_step
588590
FORMAT: A4
589591
VAR_TYPE: metadata
590592

591593
hi_pset_calibration_prod_label:
592594
CATDESC: Label calibration product
593595
FIELDNAM: Label calibration product
596+
DEPEND_1: calibration_prod
594597
FORMAT: A4
595598
VAR_TYPE: metadata
596599

imap_processing/cli.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -740,7 +740,7 @@ def do_processing(
740740
)
741741
datasets = hi_l1c.hi_l1c(load_cdf(science_paths[0]), anc_paths[0])
742742
elif self.data_level == "l2":
743-
science_paths = dependencies.get_file_paths(source="hi", data_type="l2")
743+
science_paths = dependencies.get_file_paths(source="hi", data_type="l1c")
744744
# TODO get ancillary paths
745745
geometric_factors_path = ""
746746
esa_energies_path = ""

imap_processing/ena_maps/ena_maps.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1119,9 +1119,9 @@ def to_dataset(self) -> xr.Dataset:
11191119
)
11201120
# Add the solid angle variable to the data_1d Dataset
11211121
self.data_1d["solid_angle"] = xr.DataArray(
1122-
self.solid_angle_points,
1122+
self.solid_angle_points[np.newaxis, :],
11231123
name="solid_angle",
1124-
dims=[CoordNames.GENERIC_PIXEL.value],
1124+
dims=[CoordNames.TIME.value, CoordNames.GENERIC_PIXEL.value],
11251125
)
11261126
# Rewrap each data array in the data_1d to the original 2D grid shape
11271127
rewrapped_data = {}
@@ -1275,8 +1275,14 @@ def build_cdf_dataset(
12751275
# Set the variable attributes
12761276
for var in [*cdf_ds.data_vars, *cdf_ds.coords]:
12771277
try:
1278+
# Don't check schema on label or delta variables
1279+
ignore_schema_substrings = ["_label", "_delta"]
1280+
check_schema = (
1281+
False if any(s in var for s in ignore_schema_substrings) else True
1282+
)
12781283
var_attrs = cdf_attrs.get_variable_attributes(
12791284
variable_name=var,
1285+
check_schema=check_schema,
12801286
)
12811287
except KeyError as e:
12821288
raise KeyError(

imap_processing/hi/l2/hi_l2.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,9 @@ def generate_hi_map(
136136
)
137137
)
138138

139+
rect_map.data_1d["obs_date"].data = rect_map.data_1d["obs_date"].data.astype(
140+
np.int64
141+
)
139142
# TODO: Figure out how to compute obs_date_range (stddev of obs_date)
140143
rect_map.data_1d["obs_date_range"] = xr.zeros_like(rect_map.data_1d["obs_date"])
141144

imap_processing/tests/ena_maps/test_ena_maps.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -443,6 +443,11 @@ def test_project_rect_pset_values_to_map_pull_method(
443443
# operations to be repeated as this test
444444
rect_map_ds = rectangular_map.to_dataset()
445445
assert "solid_angle" in rect_map_ds.data_vars
446+
assert rect_map_ds.data_vars["solid_angle"].shape == (
447+
1,
448+
360 / skymap_spacing,
449+
180 / skymap_spacing,
450+
)
446451
assert "counts" in rect_map_ds.data_vars
447452
assert rect_map_ds["counts"].shape == (
448453
1,

imap_processing/tests/hi/test_hi_l2.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import pytest
55
import xarray as xr
66

7+
from imap_processing.cdf.utils import write_cdf
78
from imap_processing.ena_maps.ena_maps import RectangularSkyMap
89
from imap_processing.hi.l2.hi_l2 import (
910
calculate_ena_intensity,
@@ -46,6 +47,8 @@ def test_hi_l2(hi_l1_test_data_path):
4647
np.testing.assert_array_equal(
4748
l2_dataset["ena_intensity"].dims, ["epoch", "energy", "longitude", "latitude"]
4849
)
50+
# Test ISTP compliance by writing the CDF
51+
write_cdf(l2_dataset, istp=True)
4952

5053

5154
@pytest.mark.external_test_data

imap_processing/ultra/l2/ultra_l2.py

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -118,10 +118,10 @@ def get_variable_attributes_optional_energy_dependence(
118118
# These variables must get metadata with a different key if they are energy
119119
# dependent.
120120
if (variable_name in INCONSISTENTLY_ENERGY_DEPENDENT_VARIABLES) and (
121-
(CoordNames.ENERGY_L2.value in variable_dims)
122-
or (CoordNames.ENERGY_ULTRA_L1C.value in variable_dims)
121+
(CoordNames.ENERGY_L2.value not in variable_dims)
122+
and (CoordNames.ENERGY_ULTRA_L1C.value not in variable_dims)
123123
):
124-
variable_name = f"{variable_name}_energy_dependent"
124+
variable_name = f"{variable_name}_energy_independent"
125125

126126
metadata = cdf_attrs.get_variable_attributes(
127127
variable_name=variable_name,
@@ -462,14 +462,6 @@ def ultra_l2(
462462

463463
map_dataset = rectangular_skymap.to_dataset()
464464

465-
# Reshape the solid_angle to have an epoch dimension at the start
466-
map_dataset["solid_angle"] = map_dataset["solid_angle"].expand_dims(
467-
{
468-
CoordNames.TIME.value: 1,
469-
},
470-
axis=0,
471-
)
472-
473465
# Add longitude_delta, latitude_delta to the map dataset
474466
map_dataset["longitude_delta"] = rectangular_skymap.spacing_deg / 2
475467
map_dataset["latitude_delta"] = rectangular_skymap.spacing_deg / 2

0 commit comments

Comments
 (0)