Skip to content

Commit

Permalink
add add_dimension
Browse files Browse the repository at this point in the history
  • Loading branch information
jdries committed Dec 17, 2024
1 parent 1f9274c commit 5adc8b4
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
5 changes: 5 additions & 0 deletions openeo/metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
7 changes: 7 additions & 0 deletions tests/test_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
{
Expand Down

0 comments on commit 5adc8b4

Please sign in to comment.