Skip to content

Commit e3c93fa

Browse files
Fix for when x and y are not the first 2 dimensions. Assert x,y order. #690
1 parent 10797f0 commit e3c93fa

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

openeo/metadata.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,12 @@ def temporal_dimension(self) -> TemporalDimension:
304304

305305
@property
306306
def spatial_dimensions(self) -> List[SpatialDimension]:
307-
return [d for d in self._dimensions if isinstance(d, SpatialDimension)]
307+
lst = [d for d in self._dimensions if isinstance(d, SpatialDimension)]
308+
if lst:
309+
assert len(lst) == 2
310+
assert lst[0].name == "x"
311+
assert lst[1].name == "y"
312+
return lst
308313

309314
def has_geometry_dimension(self):
310315
return any(isinstance(d, GeometryDimension) for d in self._dimensions)
@@ -442,11 +447,13 @@ def resample_spatial(
442447
raise MetadataException(f"Expected two spatial resolutions but found {spatial_indixes=}")
443448
for i in spatial_indixes:
444449
dim: SpatialDimension = dimensions[i]
450+
assert dim.name in ["x", "y"]
451+
resolution_i = 0 if dim.name == "x" else 1
445452
dimensions[i] = SpatialDimension(
446453
name=dim.name,
447454
extent=dim.extent,
448455
crs=projection or dim.crs,
449-
step=resolution[i] if resolution[i] else dim.step,
456+
step=resolution[resolution_i] if resolution[resolution_i] else dim.step,
450457
)
451458

452459
return self._clone_and_update(dimensions=dimensions)

openeo/utils/normalize.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ def normalize_resample_resolution(
55
resolution: Union[int, float, Tuple[float, float], Tuple[int, int]]
66
) -> Tuple[Union[int, float], Union[int, float]]:
77
"""Normalize a resolution value, as used in the `resample_spatial` process to a two-element tuple."""
8+
# This is a stricter version than clean_number_pair()
89
if isinstance(resolution, (int, float)):
910
return (resolution, resolution)
1011
elif (

0 commit comments

Comments
 (0)