Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions eodag_cube/api/product/_product.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
3 changes: 2 additions & 1 deletion eodag_cube/utils/metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down
7 changes: 3 additions & 4 deletions tests/integration/test_eoproduct_augment_from_xarray.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"])
Expand All @@ -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)
Expand Down
5 changes: 2 additions & 3 deletions tests/units/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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"""
Expand Down
Loading