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

fix: fix crash in resample_cube_spatial and remove odc-algo dependency #144

Merged
merged 1 commit into from
Jul 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 0 additions & 7 deletions openeo_processes_dask/process_implementations/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,6 @@
"Did not load machine learning processes due to missing dependencies: Install them like this: `pip install openeo-processes-dask[implementations, ml]`"
)

try:
from .experimental import *
except ImportError as e:
logger.warning(
"Did not load experimental processes due to missing dependencies. Install them like this: `pip install openeo-processes-dask[implementations, experimental]`"
)

import rioxarray as rio # Required for the .rio accessor on xarrays.

import openeo_processes_dask.process_implementations.cubes._xr_interop
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import odc.algo
import rioxarray # needs to be imported to set .rio accessor on xarray objects.

from openeo_processes_dask.process_implementations.data_model import RasterCube
Expand All @@ -9,13 +8,6 @@
def resample_cube_spatial(
data: RasterCube, target: RasterCube, method="near", options=None
) -> RasterCube:
# NOTE: Using the odc-algo library is not great, because it is only a random collection of experimental opendatacube features
# but we've investigated all other available alternatives for resampling that are currently available with dask and none do the job.
# We've tested pyresample (did not work at all and requires loads of helper code),
# rasterio.reproject_match (loads all the data into memory to do gdal.warp) and odc-geo (doesn't support dask yet).
# Github issue tracking this feature in rioxarray: https://github.com/corteva/rioxarray/issues/119
# Github issue tracking this feature in odc-geo: https://github.com/opendatacube/odc-geo/issues/26

methods_list = [
"near",
"bilinear",
Expand All @@ -31,8 +23,12 @@
"q3",
]

# ODC reproject requires y to be before x
required_dim_order = (
data.openeo.band_dims + data.openeo.temporal_dims + data.openeo.spatial_dims
data.openeo.band_dims
+ data.openeo.temporal_dims
+ tuple(data.openeo.y_dim)
+ tuple(data.openeo.x_dim)
)

data_reordered = data.transpose(*required_dim_order, missing_dims="ignore")
Expand All @@ -47,13 +43,14 @@
f"[{', '.join(methods_list)}]"
)

resampled_data = odc.algo._warp.xr_reproject(
data_reordered, target_reordered.geobox, resampling=method
resampled_data = data_reordered.odc.reproject(

Check warning on line 46 in openeo_processes_dask/process_implementations/experimental/resample.py

View check run for this annotation

Codecov / codecov/patch

openeo_processes_dask/process_implementations/experimental/resample.py#L46

Added line #L46 was not covered by tests
target_reordered.odc.geobox, resampling=method
)

resampled_data.rio.write_crs(target_reordered.rio.crs, inplace=True)

try:
# xr_reproject renames the coordinates according to the geobox, this undoes that.
# odc.reproject renames the coordinates according to the geobox, this undoes that.
resampled_data = resampled_data.rename(
{"longitude": data.openeo.x_dim, "latitude": data.openeo.y_dim}
)
Expand Down
2 changes: 0 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ rasterio = { version = "^1.3.4", optional = true }
dask-geopandas = { version = ">=0.2.0,<1", optional = true }
xgboost = { version = "^1.5.1", optional = true }
rioxarray = { version = ">=0.12.0,<1", optional = true }
odc-algo = { version = "==0.2.3", optional = true }
openeo-pg-parser-networkx = { version = ">=2023.5.1", optional = true }
odc-geo = { version = ">=0.3.2,<1", optional = true }
stac_validator = { version = ">=3.3.1", optional = true }
Expand All @@ -50,7 +49,6 @@ pytest-cov = "^4.0.0"

[tool.poetry.extras]
implementations = ["geopandas", "xarray", "dask", "rasterio", "dask-geopandas", "rioxarray", "openeo-pg-parser-networkx", "odc-geo", "stackstac", "planetary_computer", "pystac_client", "stac_validator"]
experimental = ["odc-algo"]
ml = ["xgboost"]

[tool.pytest.ini_options]
Expand Down