jgrss / geowombat

GeoWombat: Utilities for geospatial data
https://geowombat.readthedocs.io
MIT License
184 stars 10 forks source link

Usage of xarray ufuncs is deprecated #183

Closed mattijn closed 2 years ago

mattijn commented 2 years ago

Xarray has removed support for the deprecated xarray.ufuncs functions since version v2022.06.rc0: https://docs.xarray.dev/en/stable/whats-new.html#breaking-changes.

Now I receive the following error:

import geowombat as gw
---------------------------------------------------------------------------
ModuleNotFoundError                       Traceback (most recent call last)
Input In [2], in <cell line: 1>()
----> 1 import geowombat as gw

File /opt/tljh/user/envs/stable/lib/python3.8/site-packages/geowombat/__init__.py:5, in <module>
      2 __version__ = '1.11.3'
      4 from . import config
----> 5 from .core.api import open
      6 from .core.api import load
      7 from .core.api import series

File /opt/tljh/user/envs/stable/lib/python3.8/site-packages/geowombat/core/__init__.py:1, in <module>
----> 1 from ..backends import transform_crs
      2 from .io import apply
      3 from .io import to_raster

File /opt/tljh/user/envs/stable/lib/python3.8/site-packages/geowombat/backends/__init__.py:2, in <module>
      1 from .dask_ import Cluster
----> 2 from .xarray_ import concat, mosaic
      3 from .xarray_ import warp_open
      4 from .xarray_ import transform_crs

File /opt/tljh/user/envs/stable/lib/python3.8/site-packages/geowombat/backends/xarray_.py:26, in <module>
     24 import dask.array as da
     25 import xarray as xr
---> 26 from xarray.ufuncs import maximum as xr_maximum
     27 from xarray.ufuncs import minimum as xr_mininum
     30 logger = logging.getLogger(__name__)

ModuleNotFoundError: No module named 'xarray.ufuncs'

Searching the repo: https://github.com/jgrss/geowombat/search?q=xarray.ufuncs&type=code Reveals at least one file needs updating: https://github.com/jgrss/geowombat/blob/342bb2b518350ac1617dcca3329b9645862c17c9/src/geowombat/backends/xarray_.py#L26-L27 Linked issue: https://github.com/jgrss/geowombat/issues/42

37310N commented 2 years ago

@jgrss is it possible to downgrade geowombat and/or xarray to solve the issue?

mattijn commented 2 years ago

Yes, you can use current version of geowombat with:

pip install xarray==2022.3.0
37310N commented 2 years ago

The following workaround solved the problem for me, but maybe this is not a really good solution. Only tested on calculating Band Math & Vegetation Indices following this guide.

Searching the repo: https://github.com/jgrss/geowombat/search?q=xarray.ufuncs&type=code Reveals at least one file needs updating:

https://github.com/jgrss/geowombat/blob/342bb2b518350ac1617dcca3329b9645862c17c9/src/geowombat/backends/xarray_.py#L26-L27

In the given file I commented the lines 26 & 27 out (see above) and changed the xarray min/max function to numpy.minimum() and numpy.maximum() as follows:

if overlap == 'min':
ds = np.minimum(ds, dsb)
elif overlap == 'max':
ds = np.maximum(ds, dsb)
elif overlap == 'mean':
ds = (ds + dsb) / 2.0

37310N commented 2 years ago

Yes, you can use current version of geowombat with:

pip install xarray==2022.3.0

Finally, after a bit of back and forth, I was able to freshly install geowombat and than downgrade xarray to the suggested version with conda. This works fine for me.

Thank you @mattijn

mmann1123 commented 2 years ago

@jgrss just opened a pull request to resolve this.

jgrss commented 2 years ago

@mmann1123 What is the status of PR #186? Was it closed because we had discussed using the fixes in jgrss/store?

jgrss commented 2 years ago

Yes, you can use current version of geowombat with:

pip install xarray==2022.3.0

Thanks for comfirming this, @mattijn -- a branch in the waiting that should push geowombat to v2.0.0 has xarray>=2022.6.0.

mmann1123 commented 2 years ago

@jgrss I intended PR #186 to resolve the ufunc issues but then some tests were failing in ML and another elsewhere, I was worried I had inadvertently pushed some old ML code, so closed it. But I think we need to push the jgrss/store. I will try to test it today, but its first day of classes so things are busy. Might be a few days. But I figure jgrss/store can't make things worse - since people can't write out files - and would likely fix things. But I defer to you on that.

jgrss commented 2 years ago

Should be addressed with #189.