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

Hi all,
I’m curious if there have been any recent updates to the xarray package or related components. It’s strange that my script, which had been running smoothly on JupyterLab since January, suddenly started throwing this error last week. I haven’t encountered this issue before and I’m unsure what might be causing it.

--> 285         da_dem  = xr.open_rasterio(full_path_file_wgs).drop('band')[0].rename({'x':'longitude', 'y':'latitude'})
    286 
    287         mlat = da_dem.latitude.values.min()

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

I attempted to upgrade the xarray package using the “pip install --upgrade xarray” command in the terminal, but unfortunately, it does not work.

I appreciate any suggestions or recommendations you may have.

from xarray v2023.04.0 (April 14, 2023) changelog :
This release …, and removes deprecated backends for rasterio and cfgrib.

from old xarray.open_rasterio docs
Deprecated since version 0.20.0 (November 2021): Deprecated in favor of rioxarray. For information about transitioning, see: Getting Started — rioxarray 0.15.0 documentation

I haven’t played with it myself, but if I understand correctly, you should (instead of using xarray.open_rasterio) load the raster data file with

import xarray
xds = xarray.open_dataset("my.tif", engine="rasterio")

or

import rioxarray
xds = rioxarray.open_rasterio("my.tif")
1 Like

Correct works! Thanks