Skip to content

Commit

Permalink
upgrade to be compatible with newer version dependencies (#1389)
Browse files Browse the repository at this point in the history
* fix broken parts due to xarray updates

* update for shapely and numpy

---------

Co-authored-by: Emma Ai <emma.ai@ga.gov.au>
  • Loading branch information
emmaai and Emma Ai committed Jan 30, 2023
1 parent ead062c commit 9b38fa7
Show file tree
Hide file tree
Showing 9 changed files with 122 additions and 109 deletions.
2 changes: 1 addition & 1 deletion conda-environment.yml
Expand Up @@ -32,5 +32,5 @@ dependencies:
- rasterio >=1.3.2
- sqlalchemy
- GeoAlchemy2
- xarray >=0.9,!=2022.6.0
- xarray >=0.9
- toolz
3 changes: 1 addition & 2 deletions datacube/api/grid_workflow.py
Expand Up @@ -17,14 +17,13 @@
def _fast_slice(array, indexers):
data = array.values[indexers]
dims = [dim for dim, indexer in zip(array.dims, indexers) if isinstance(indexer, slice)]
variable = xarray.Variable(dims, data, attrs=array.attrs, fastpath=True)
coords = OrderedDict((dim,
xarray.Variable((dim,),
array.coords[dim].values[indexer],
attrs=array.coords[dim].attrs,
fastpath=True))
for dim, indexer in zip(array.dims, indexers) if isinstance(indexer, slice))
return xarray.DataArray(variable, coords=coords, fastpath=True)
return xarray.DataArray(data, dims=dims, coords=coords, attrs=array.attrs)


class Tile(object):
Expand Down
11 changes: 7 additions & 4 deletions datacube/utils/geometry/_base.py
Expand Up @@ -17,7 +17,7 @@
import xarray as xr
from affine import Affine
import rasterio # type: ignore[import]
from shapely import geometry, ops # type: ignore[import]
from shapely import geometry, ops, from_wkt # type: ignore[import]
from shapely.geometry import base # type: ignore[import]
from pyproj import CRS as _CRS
from pyproj.enums import WktVersion
Expand Down Expand Up @@ -438,7 +438,7 @@ def short_enough(p1, p2):


def _clone_shapely_geom(geom: base.BaseGeometry) -> base.BaseGeometry:
return type(geom)(geom)
return from_wkt(geom.wkt)


class Geometry:
Expand Down Expand Up @@ -604,7 +604,10 @@ def wkt(self) -> str:

@property
def __array_interface__(self):
return self.geom.__array_interface__
"""
Should consider to deprecate this interface as shapely > 1.8 does
"""
return numpy.array(self.geom.coords)

@property
def __geo_interface__(self):
Expand Down Expand Up @@ -710,7 +713,7 @@ def split(self, splitter: 'Geometry') -> Iterable['Geometry']:
if splitter.crs != self.crs:
raise CRSMismatchError(self.crs, splitter.crs)

for g in ops.split(self.geom, splitter.geom):
for g in ops.split(self.geom, splitter.geom).geoms:
yield Geometry(g, self.crs)

def __iter__(self) -> Iterator['Geometry']:
Expand Down
1 change: 1 addition & 0 deletions datacube/virtual/impl.py
Expand Up @@ -543,6 +543,7 @@ def statistic(coords, value):
data = self._input.fetch(value, **load_settings)
result = self._statistic.compute(data)
result.coords[dim] = coords[dim]
result = result.drop_indexes(dim, errors="ignore")
return result

groups = list(xr_map(grouped.box, statistic))
Expand Down
5 changes: 2 additions & 3 deletions docker/constraints.in
@@ -1,5 +1,5 @@
# datacube dependencies
Sphinx
Sphinx<6.0.0 # be compatible to sphinx_rtd_theme
affine
attrs>=18.1
# boto is too huge, need to set lower bound
Expand Down Expand Up @@ -37,8 +37,7 @@ sphinx_autodoc_typehints
sphinx_rtd_theme
sqlalchemy
toolz
# FOR INVESTIGATION: xarray 2022.6.0 breaks virtual products tests.
xarray>=0.18,!=2022.6.0
xarray>=0.18

# Previous pins were to very old versions
# pytest Py3.10 requires >6.2.5
Expand Down

0 comments on commit 9b38fa7

Please sign in to comment.