diff --git a/eodag_cube/api/product/_product.py b/eodag_cube/api/product/_product.py index e1c892e..c18ef68 100644 --- a/eodag_cube/api/product/_product.py +++ b/eodag_cube/api/product/_product.py @@ -406,4 +406,7 @@ def augment_from_xarray( else: asset["bands"] = generated_bands + if any("cube:dimensions" in a for a in self.assets.values()): + for key in self.assets: + self.assets[key].setdefault("cube:dimensions", {}) return self diff --git a/eodag_cube/utils/metadata.py b/eodag_cube/utils/metadata.py index 69601c3..fad0f31 100644 --- a/eodag_cube/utils/metadata.py +++ b/eodag_cube/utils/metadata.py @@ -48,7 +48,8 @@ def extract_projection_info(ds: Dataset) -> dict[str, Any]: proj_info["proj:code"] = f"EPSG:{epsg_code}" if proj_bbox is not None: proj_info["proj:bbox"] = proj_bbox - proj_info["proj:shape"] = list(ds.sizes.values()) + if "x" in ds.sizes and "y" in ds.sizes: + proj_info["proj:shape"] = [ds.sizes["y"], ds.sizes["x"]] return proj_info diff --git a/tests/integration/test_eoproduct_augment_from_xarray.py b/tests/integration/test_eoproduct_augment_from_xarray.py index f108bdf..ddc50cd 100644 --- a/tests/integration/test_eoproduct_augment_from_xarray.py +++ b/tests/integration/test_eoproduct_augment_from_xarray.py @@ -114,8 +114,8 @@ def side_effect(asset_key=None, **kwargs): with mock.patch.object(product, "to_xarray", side_effect=side_effect): product.augment_from_xarray() - # asset1 untouched - self.assertEqual(product.assets["asset1"], {"roles": ["data"]}) + # asset1 with only empty dimensions + self.assertDictEqual(product.assets["asset1"], {"roles": ["data"], "cube:dimensions": {}}) # asset2 populated self.assertIn("cube:dimensions", product.assets["asset2"]) @@ -140,8 +140,7 @@ def test_augment_from_xarray_skips_non_matching_roles(self): self.assertIn("cube:dimensions", product.assets["matching_asset"]) # The ignored asset should still be exactly as it was - self.assertEqual(product.assets["ignored_asset"], {"roles": ["thumbnail"]}) - self.assertNotIn("cube:dimensions", product.assets["ignored_asset"]) + self.assertDictEqual(product.assets["ignored_asset"], {"roles": ["thumbnail"], "cube:dimensions": {}}) # Verify that to_xarray was only called once (for the matching asset) self.assertEqual(mock_to_xarray.call_count, 1) diff --git a/tests/units/test_utils.py b/tests/units/test_utils.py index fa38af0..f94fe5e 100644 --- a/tests/units/test_utils.py +++ b/tests/units/test_utils.py @@ -285,8 +285,7 @@ def test_extract_projection_info_default(self): proj_info = metadata.extract_projection_info(self.ds_1d) self.assertIn("proj:code", proj_info) self.assertEqual(proj_info["proj:code"], "EPSG:4326") - self.assertIn("proj:shape", proj_info) - self.assertEqual(proj_info["proj:shape"], [4, 4, 1]) + self.assertNotIn("proj:shape", proj_info) self.assertNotIn("proj:bbox", proj_info) @mock.patch("builtins.hasattr", return_value=False) @@ -456,7 +455,7 @@ def test_build_cube_metadata(self): self.assertEqual(proj_info["proj:code"], "EPSG:4326") self.assertIn("proj:shape", proj_info) - self.assertIsInstance(proj_info["proj:shape"], list) + self.assertEqual(proj_info["proj:shape"], [2, 2]) def test_aux_variable_not_added_if_dimension(self): """latitude/longitude must not be added as auxiliary if they are dimensions"""