Skip to content

Commit fe0db06

Browse files
authored
Remove need for unique map global attributes based on reference frame (IMAP-Science-Operations-Center#2238)
* Remove need for unique map global attributes based on reference frame * Fix test with expected change
1 parent b86f6d1 commit fe0db06

5 files changed

Lines changed: 15 additions & 21 deletions

File tree

imap_processing/cdf/config/imap_hi_global_cdf_attrs.yaml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,7 @@ imap_hi_l1c_pset_attrs:
5454
Logical_source: imap_hi_l1c_{sensor}-pset
5555
Logical_source_description: IMAP-Hi Instrument Level-1C Pointing Set Data.
5656

57-
# TODO: Finalize these global attributes
58-
imap_hi_l2_enamap-sf:
57+
imap_hi_l2_enamap:
5958
Data_type: L2_{descriptor}>Level-2 ENA Intensity Map for Hi{sensor}
6059
Logical_source: imap_hi_l2_{descriptor}
6160
Logical_source_description: IMAP-Hi Instrument Level-2 ENA Intensity Map Data for Hi{sensor} on rectangular tiling.

imap_processing/ena_maps/ena_maps.py

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1222,7 +1222,6 @@ def build_cdf_dataset(
12221222
self,
12231223
instrument: str,
12241224
level: str,
1225-
frame: str,
12261225
descriptor: str,
12271226
sensor: str | None = None,
12281227
) -> xr.Dataset:
@@ -1235,8 +1234,6 @@ def build_cdf_dataset(
12351234
Instrument name. "hi", "lo", "ultra".
12361235
level : str
12371236
Product level. "l2" or "l3".
1238-
frame : str
1239-
Map frame. "sf", "hf" or "hk".
12401237
descriptor : str
12411238
Descriptor for filename.
12421239
sensor : str, optional
@@ -1318,16 +1315,14 @@ def build_cdf_dataset(
13181315
)
13191316

13201317
# Now set global attributes
1321-
map_attrs = cdf_attrs.get_global_attributes(
1322-
f"imap_{instrument}_{level}_enamap-{frame}"
1323-
)
1318+
map_attrs = cdf_attrs.get_global_attributes(f"imap_{instrument}_{level}_enamap")
13241319
map_attrs["Spacing_degrees"] = str(self.spacing_deg)
13251320
for key in ["Data_type", "Logical_source", "Logical_source_description"]:
13261321
map_attrs[key] = map_attrs[key].format(
13271322
descriptor=descriptor,
13281323
sensor=sensor,
13291324
)
1330-
# Always add the following attributes to the map
1325+
# Always add the following attributes to the map
13311326
map_attrs.update(
13321327
{
13331328
"Sky_tiling_type": self.tiling_type.value,

imap_processing/hi/hi_l2.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,6 @@ def hi_l2(
6666
l2_ds = sky_map.build_cdf_dataset(
6767
"hi",
6868
"l2",
69-
map_descriptor.frame_descriptor,
7069
descriptor,
7170
sensor=map_descriptor.sensor,
7271
)

imap_processing/tests/ena_maps/test_ena_maps.py

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -642,7 +642,7 @@ def test_build_cdf_dataset(self, mock_to_dataset, mock_data_for_build_cdf_datase
642642
skymap.min_epoch = 10
643643
skymap.max_epoch = 15
644644
cdf_dataset = skymap.build_cdf_dataset(
645-
"hi", "l2", "sf", "foo_descriptor", sensor="45"
645+
"hi", "l2", "foo_descriptor", sensor="45"
646646
)
647647

648648
# Check that expected var gets removed
@@ -694,9 +694,7 @@ def test_build_cdf_dataset_key_error(
694694
with pytest.raises(
695695
KeyError, match="Attributes for variable no_attrs_var not found"
696696
):
697-
_ = skymap.build_cdf_dataset(
698-
"hi", "l2", "sf", "foo_descriptor", sensor="45"
699-
)
697+
_ = skymap.build_cdf_dataset("hi", "l2", "foo_descriptor", sensor="45")
700698

701699
# Test that missing energy delta variable raise KeyError
702700
# Test for missing energy_delta_plus
@@ -706,19 +704,15 @@ def test_build_cdf_dataset_key_error(
706704
KeyError,
707705
match="Required variable 'energy_delta_plus' not found in cdf Dataset.",
708706
):
709-
_ = skymap.build_cdf_dataset(
710-
"hi", "l2", "sf", "foo_descriptor", sensor="45"
711-
)
707+
_ = skymap.build_cdf_dataset("hi", "l2", "foo_descriptor", sensor="45")
712708
# Test for missing energy_delta_minus
713709
mock_dataset = mock_dataset.drop(["energy_delta_minus"])
714710
mock_to_dataset.return_value = mock_dataset
715711
with pytest.raises(
716712
KeyError,
717713
match="Required variable 'energy_delta_minus' not found in cdf Dataset.",
718714
):
719-
_ = skymap.build_cdf_dataset(
720-
"hi", "l2", "sf", "foo_descriptor", sensor="45"
721-
)
715+
_ = skymap.build_cdf_dataset("hi", "l2", "foo_descriptor", sensor="45")
722716

723717

724718
class TestHealpixSkyMap:

imap_processing/tests/hi/test_hi_l2.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,13 +152,20 @@ def test_hi_l2(
152152
):
153153
"""Integration type test for hi_l2()"""
154154
pset_path = hi_l1_test_data_path / "imap_hi_l1c_45sensor-pset_20250415_v999.cdf"
155+
descriptor = "h90-ena-h-sf-nsp-full-hae-4deg-3mo"
155156

156157
l2_dataset = hi_l2(
157158
[pset_path],
158159
anc_path_dict,
159160
"h90-ena-h-sf-nsp-full-hae-4deg-3mo",
160161
)[0]
161162
assert isinstance(l2_dataset, xr.Dataset)
163+
164+
# Check some global attributes
165+
assert l2_dataset.attrs["Data_type"].startswith(f"L2_{descriptor}")
166+
assert l2_dataset.attrs["Logical_source"] == f"imap_hi_l2_{descriptor}"
167+
assert "Hi90" in l2_dataset.attrs["Logical_source_description"]
168+
162169
assert len(l2_dataset.data_vars) == 15
163170
np.testing.assert_array_equal(
164171
l2_dataset["ena_intensity"].dims, ["epoch", "energy", "longitude", "latitude"]
@@ -190,7 +197,7 @@ def test_hi_l2_uses_descriptor_to_setup_map(
190197
assert rect_map.spacing_deg == 2.0
191198

192199
mock_map_build_cdf_dataset.assert_called_with(
193-
rect_map, "hi", "l2", "sf", descriptor_str, sensor="90"
200+
rect_map, "hi", "l2", descriptor_str, sensor="90"
194201
)
195202

196203

0 commit comments

Comments
 (0)