holoviz / geoviews

Simple, concise geographical visualization in Python
http://geoviews.org
BSD 3-Clause "New" or "Revised" License
592 stars 76 forks source link

deprecated synthaxe to open tiff using xarray #639

Closed agrouaze closed 1 year ago

agrouaze commented 1 year ago

Hello geoviews team,

ALL software version info

geoviews 1.9.5 pyhd8ed1ab_0 conda-forge geoviews-core 1.9.5 pyha770c72_0 conda-forge rioxarray 0.14.1 pyhd8ed1ab_0 conda-forge xarray 2023.5.0 pyhd8ed1ab_0 conda-forge Python 3.10.8 Ubuntu 22.04.2 LTS

Description of expected behavior and the observed behavior

geoviews.util.load_tiff() should open .tiff files. With xarray==2023.5.0 the syntaxe da = xr.open_rasterio(filename) is not valid anymore. see the code.

Complete, minimal, self-contained example code that reproduces the issue

to reproduce the issue you can download any .tiff file. I randomly fetch this one

In [1]: ff = '/tmp/file_example_TIFF_1MB.tiff'

In [2]: import geoviews as gv

In [3]: gv.load_tiff(ff)
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
Cell In[3], line 1
----> 1 gv.load_tiff(ff)

File /opt/conda-envs/dev/lib/python3.10/site-packages/geoviews/util.py:644, in load_tiff(filename, crs, apply_transform, nan_nodata, **kwargs)
    642 with warnings.catch_warnings():
    643     warnings.filterwarnings('ignore')
--> 644     da = xr.open_rasterio(filename)
    645 return from_xarray(da, crs, apply_transform, nan_nodata, **kwargs)

AttributeError: module 'xarray' has no attribute 'open_rasterio'

While this file is readable with rioxarray for instance:


In [5]: import rioxarray

In [6]: rioxarray.open_rasterio(ff)
/opt/conda-envs/dev/lib/python3.10/site-packages/rioxarray/_io.py:1132: NotGeoreferencedWarning: Dataset has no geotransform, gcps, or rpcs. The identity matrix will be returned.
  warnings.warn(str(rio_warning.message), type(rio_warning.message))  # type: ignore
Out[6]: 
<xarray.DataArray (band: 4, y: 434, x: 650)>
[1128400 values with dtype=uint8]
Coordinates:
  * band         (band) int64 1 2 3 4
  * x            (x) float64 0.5 1.5 2.5 3.5 4.5 ... 646.5 647.5 648.5 649.5
  * y            (y) float64 0.5 1.5 2.5 3.5 4.5 ... 430.5 431.5 432.5 433.5
    spatial_ref  int64 0
Attributes:
    TIFFTAG_DOCUMENTNAME:    /home/marta/Desktop/www/file ex/files/grafa/tiff...
    TIFFTAG_RESOLUTIONUNIT:  2 (pixels/inch)
    TIFFTAG_XRESOLUTION:     72.009003
    TIFFTAG_YRESOLUTION:     72.009003
    scale_factor:            1.0
    add_offset:              0.0

Stack traceback

File /opt/conda-envs/dev/lib/python3.10/site-packages/geoviews/util.py:644, in load_tiff(filename, crs, apply_transform, nan_nodata, **kwargs)
    642 with warnings.catch_warnings():
    643     warnings.filterwarnings('ignore')
--> 644     da = xr.open_rasterio(filename)
    645 return from_xarray(da, crs, apply_transform, nan_nodata, **kwargs)

AttributeError: module 'xarray' has no attribute 'open_rasterio'
agrouaze commented 1 year ago

thank you @Hoxbro !