Skip to content

Commit ae7aaf5

Browse files
committed
Issue #690/#712 best effort resample_spatial on cube without metadata
1 parent f012f45 commit ae7aaf5

File tree

3 files changed

+24
-5
lines changed

3 files changed

+24
-5
lines changed

openeo/metadata.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -422,7 +422,7 @@ def drop_dimension(self, name: str = None) -> CubeMetadata:
422422

423423
def resample_spatial(
424424
self,
425-
resolution: Union[int, float, Tuple[float, float], Tuple[int, int]] = 0.0,
425+
resolution: Union[float, Tuple[float, float], List[float]] = 0.0,
426426
projection: Union[int, str, None] = None,
427427
) -> CubeMetadata:
428428
resolution = normalize_resample_resolution(resolution)

openeo/rest/datacube.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
Band,
4141
BandDimension,
4242
CollectionMetadata,
43+
CubeMetadata,
4344
SpatialDimension,
4445
TemporalDimension,
4546
metadata_from_stac,
@@ -750,14 +751,12 @@ def band(self, band: Union[str, int]) -> DataCube:
750751
@openeo_process
751752
def resample_spatial(
752753
self,
753-
resolution: Union[int, float, Tuple[float, float], Tuple[int, int]] = 0.0,
754+
resolution: Union[float, Tuple[float, float], List[float]] = 0.0,
754755
projection: Union[int, str, None] = None,
755756
method: str = "near",
756757
align: str = "upper-left",
757758
) -> DataCube:
758-
metadata = (
759-
self.metadata.resample_spatial(resolution=resolution, projection=projection) if self.metadata else None
760-
)
759+
metadata = (self.metadata or CubeMetadata()).resample_spatial(resolution=resolution, projection=projection)
761760
return self.process(
762761
process_id="resample_spatial",
763762
arguments={

tests/rest/datacube/test_datacube.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -744,6 +744,26 @@ def test_resample_spatial(s2cube):
744744
]
745745

746746

747+
def test_resample_spatial_no_metadata(s2cube_without_metadata):
748+
cube = s2cube_without_metadata.resample_spatial(resolution=(3, 5), projection=4578)
749+
assert get_download_graph(cube, drop_load_collection=True, drop_save_result=True) == {
750+
"resamplespatial1": {
751+
"process_id": "resample_spatial",
752+
"arguments": {
753+
"data": {"from_node": "loadcollection1"},
754+
"resolution": [3, 5],
755+
"projection": 4578,
756+
"method": "near",
757+
"align": "upper-left",
758+
},
759+
}
760+
}
761+
assert cube.metadata.spatial_dimensions == [
762+
SpatialDimension(name="x", extent=[None, None], crs=4578, step=3.0),
763+
SpatialDimension(name="y", extent=[None, None], crs=4578, step=5.0),
764+
]
765+
766+
747767
def test_resample_cube_spatial(s2cube):
748768
cube1 = s2cube.resample_spatial(resolution=[2.0, 3.0], projection=4578)
749769
cube2 = s2cube.resample_spatial(resolution=10, projection=32631)

0 commit comments

Comments
 (0)