From 5adc8b41596cdd8279071294c1873e378ad97d49 Mon Sep 17 00:00:00 2001 From: Jeroen Dries Date: Tue, 17 Dec 2024 07:45:52 +0100 Subject: [PATCH] add add_dimension --- openeo/metadata.py | 5 +++++ tests/test_metadata.py | 7 +++++++ 2 files changed, 12 insertions(+) diff --git a/openeo/metadata.py b/openeo/metadata.py index c9162ece1..4b48b375c 100644 --- a/openeo/metadata.py +++ b/openeo/metadata.py @@ -394,6 +394,11 @@ def add_dimension(self, name: str, label: Union[str, float], type: str = None) - dim = Dimension(type=type or "other", name=name) return self._clone_and_update(dimensions=self._dimensions + [dim]) + def add_dimension(self, dimension: Dimension) -> CubeMetadata: + """Create new CubeMetadata object with added dimension""" + return self._clone_and_update(dimensions=self._dimensions + [dimension]) + + def drop_dimension(self, name: str = None) -> CubeMetadata: """Create new CubeMetadata object without dropped dimension with given name""" dimension_names = self.dimension_names() diff --git a/tests/test_metadata.py b/tests/test_metadata.py index 32658b4fd..f97525a0a 100644 --- a/tests/test_metadata.py +++ b/tests/test_metadata.py @@ -681,6 +681,13 @@ def test_cubemetadata_add_temporal_dimension_duplicate(): _ = metadata.add_dimension("date", "2020-05-15", "temporal") +def test_cubemetadata_add_spatial_dimension(): + metadata = CubeMetadata(dimensions=[SpatialDimension(name="x", extent=[4,6])]) + updated = metadata.add_dimension(SpatialDimension(name="y", extent=[51,56])) + + assert ["x"] == metadata.dimension_names() + assert ["x", "y"] == updated.dimension_names() + def test_collectionmetadata_drop_dimension(): metadata = CollectionMetadata( {