Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

resample_spatial missing dimensions causing a crash #249

Merged
merged 8 commits into from
May 24, 2024
12 changes: 6 additions & 6 deletions openeo_processes_dask/process_implementations/cubes/resample.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,12 @@ def resample_spatial(

dims = list(data.dims)

known_dims = [
data.openeo.band_dims[0],
data.openeo.temporal_dims[0],
data.openeo.y_dim,
data.openeo.x_dim,
]
known_dims = []
if len(data.openeo.band_dims) > 0:
known_dims.append(data.openeo.band_dims[0])
if len(data.openeo.temporal_dims) > 0:
known_dims.append(data.openeo.temporal_dims[0])
known_dims += [data.openeo.y_dim, data.openeo.x_dim]

other_dims = [dim for dim in dims if dim not in known_dims]

Expand Down
27 changes: 26 additions & 1 deletion tests/test_resample.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
from functools import partial

import numpy as np
import pytest
from odc.geo.geobox import resolution_from_affine
from openeo_pg_parser_networkx.pg_schema import ParameterReference
from pyproj.crs import CRS

from openeo_processes_dask.process_implementations.cubes.reduce import reduce_dimension
from openeo_processes_dask.process_implementations.cubes.resample import (
resample_cube_spatial,
resample_spatial,
Expand All @@ -23,8 +27,15 @@
@pytest.mark.parametrize("output_res", [5, 30, 60])
@pytest.mark.parametrize("size", [(30, 30, 20, 4)])
@pytest.mark.parametrize("dtype", [np.float32])
@pytest.mark.parametrize("dims", [("x", "y", "bands"), ("x", "y", "t"), ("x", "y")])
def test_resample_spatial(
output_crs, output_res, temporal_interval, bounding_box, random_raster_data
output_crs,
output_res,
temporal_interval,
bounding_box,
random_raster_data,
dims,
process_registry,
):
"""Test to ensure resolution gets changed correctly."""
input_cube = create_fake_rastercube(
Expand All @@ -35,6 +46,20 @@ def test_resample_spatial(
backend="dask",
)

_process = partial(
process_registry["mean"].implementation,
ignore_nodata=True,
data=ParameterReference(from_parameter="data"),
)

if "bands" not in dims:
output_cube = reduce_dimension(
data=input_cube, reducer=_process, dimension="bands"
)

if "t" not in dims:
output_cube = reduce_dimension(data=input_cube, reducer=_process, dimension="t")

with pytest.raises(Exception):
output_cube = resample_spatial(
data=input_cube, projection=output_crs, resolution=output_res, method="bad"
Expand Down
Loading