corteva / rioxarray

geospatial xarray extension powered by rasterio
https://corteva.github.io/rioxarray
Other
502 stars 80 forks source link

overview_level failing in xarray with engine='rasterio' due to missing doc? #755

Closed rsignell closed 2 months ago

rsignell commented 3 months ago

I use the awesome overview_level parameter in rioxarray all the time to explore big COG images before analysis. I just recently tried using it with the invocation from xarray (with engine='rasterio') and it surprised me when it failed with:

TypeError: RasterioBackend.open_dataset() got an unexpected keyword argument 'overview_level'

Here's a MRE:

import xarray as xr
import rioxarray as rxr

https_url = 'https://s3.us-west-2.amazonaws.com/prod-is-usgs-sb-prod-publish/618e83cad34ec04fc9caa715/South_Carolina_CoNED_Topobathy_DEM_1m.tif'

da = rxr.open_rasterio(https_url, overview_level=6)   # works

ds = xr.open_dataset(https_url, engine='rasterio', backend_kwargs=dict(overview_level=6))  # doesn't work

I'm raising the issue here instead of on xarray repo because it seems perhaps the problem is that overview_level argument seems undocumented in the method: https://corteva.github.io/rioxarray/stable/rioxarray.html#rioxarray-open-rasterio and only exists in the documentation in the COG example here: https://corteva.github.io/rioxarray/stable/examples/COG.html

Forgive me if I've got this all wrong! 🙃

snowman2 commented 3 months ago

You have to use open_kwargs. See: https://github.com/corteva/rioxarray/blob/6b768ec260fc65752c5396fbfe3a9b25e49ae2b1/rioxarray/xarray_plugin.py#L50

rsignell commented 3 months ago

Yep, so this works:


import xarray as xr

https_url = 'https://s3.us-west-2.amazonaws.com/prod-is-usgs-sb-prod-publish/618e83cad34ec04fc9caa715/South_Carolina_CoNED_Topobathy_DEM_1m.tif'

ds = xr.open_dataset(https_url, 
                     engine='rasterio', 
                     backend_kwargs=dict(open_kwargs={'overview_level':6},masked=True)
                     ).squeeze(drop=True)

thanks @snowman2 !