Skip to content

Commit 463690e

Browse files
authored
fix: augmented metadata formatting (#117)
1 parent 5581b79 commit 463690e

File tree

4 files changed

+10
-8
lines changed

4 files changed

+10
-8
lines changed

eodag_cube/api/product/_product.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -406,4 +406,7 @@ def augment_from_xarray(
406406
else:
407407
asset["bands"] = generated_bands
408408

409+
if any("cube:dimensions" in a for a in self.assets.values()):
410+
for key in self.assets:
411+
self.assets[key].setdefault("cube:dimensions", {})
409412
return self

eodag_cube/utils/metadata.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,8 @@ def extract_projection_info(ds: Dataset) -> dict[str, Any]:
4848
proj_info["proj:code"] = f"EPSG:{epsg_code}"
4949
if proj_bbox is not None:
5050
proj_info["proj:bbox"] = proj_bbox
51-
proj_info["proj:shape"] = list(ds.sizes.values())
51+
if "x" in ds.sizes and "y" in ds.sizes:
52+
proj_info["proj:shape"] = [ds.sizes["y"], ds.sizes["x"]]
5253
return proj_info
5354

5455

tests/integration/test_eoproduct_augment_from_xarray.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -114,8 +114,8 @@ def side_effect(asset_key=None, **kwargs):
114114
with mock.patch.object(product, "to_xarray", side_effect=side_effect):
115115
product.augment_from_xarray()
116116

117-
# asset1 untouched
118-
self.assertEqual(product.assets["asset1"], {"roles": ["data"]})
117+
# asset1 with only empty dimensions
118+
self.assertDictEqual(product.assets["asset1"], {"roles": ["data"], "cube:dimensions": {}})
119119

120120
# asset2 populated
121121
self.assertIn("cube:dimensions", product.assets["asset2"])
@@ -140,8 +140,7 @@ def test_augment_from_xarray_skips_non_matching_roles(self):
140140
self.assertIn("cube:dimensions", product.assets["matching_asset"])
141141

142142
# The ignored asset should still be exactly as it was
143-
self.assertEqual(product.assets["ignored_asset"], {"roles": ["thumbnail"]})
144-
self.assertNotIn("cube:dimensions", product.assets["ignored_asset"])
143+
self.assertDictEqual(product.assets["ignored_asset"], {"roles": ["thumbnail"], "cube:dimensions": {}})
145144

146145
# Verify that to_xarray was only called once (for the matching asset)
147146
self.assertEqual(mock_to_xarray.call_count, 1)

tests/units/test_utils.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -285,8 +285,7 @@ def test_extract_projection_info_default(self):
285285
proj_info = metadata.extract_projection_info(self.ds_1d)
286286
self.assertIn("proj:code", proj_info)
287287
self.assertEqual(proj_info["proj:code"], "EPSG:4326")
288-
self.assertIn("proj:shape", proj_info)
289-
self.assertEqual(proj_info["proj:shape"], [4, 4, 1])
288+
self.assertNotIn("proj:shape", proj_info)
290289
self.assertNotIn("proj:bbox", proj_info)
291290

292291
@mock.patch("builtins.hasattr", return_value=False)
@@ -456,7 +455,7 @@ def test_build_cube_metadata(self):
456455

457456
self.assertEqual(proj_info["proj:code"], "EPSG:4326")
458457
self.assertIn("proj:shape", proj_info)
459-
self.assertIsInstance(proj_info["proj:shape"], list)
458+
self.assertEqual(proj_info["proj:shape"], [2, 2])
460459

461460
def test_aux_variable_not_added_if_dimension(self):
462461
"""latitude/longitude must not be added as auxiliary if they are dimensions"""

0 commit comments

Comments
 (0)