Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Accessing COG overviews with read_rasterio #3269

Closed
rsignell-usgs opened this issue Aug 27, 2019 · 3 comments · Fixed by #5609
Closed

Accessing COG overviews with read_rasterio #3269

rsignell-usgs opened this issue Aug 27, 2019 · 3 comments · Fixed by #5609

Comments

@rsignell-usgs
Copy link

rsignell-usgs commented Aug 27, 2019

It's considered best practice to create cloud-optimized geotiff (COG) with overviews, which are essentially copies of the dataset at different resolutions to allow fast representation at different scales.

It would be nice if we could pick a specific overview using xr.read_rasterio, perhaps by just an additional parameter on the call, like xr.read_rasterio(url, overview=512) or something.

Currently we need to use Rasterio to find out what the overlays are, for example:

url = 'https://esip-pangeo-uswest2.s3-us-west-2.amazonaws.com/sciencebase/Southern_California_Topobathy_DEM_1m_cog.tif'
src = rasterio.open(url, 'r')
[src.overviews(i) for i in src.indexes]

which results in:

[[4, 8, 16, 32, 64, 128, 256, 512, 1023]]

See the notebook here for the hack workaround to extract an overlay from COG:
https://nbviewer.jupyter.org/gist/rsignell-usgs/dc4cf94fae97d085f6f2b9b896ec5336

@dcherian
Copy link
Contributor

That kwarg looks good to me. Can you send in a PR?

@scottyhq
Copy link
Contributor

@dcherian I was just revisiting a use-case for this and realized xr.open_rasterio() does not take **kwargs.
http://xarray.pydata.org/en/stable/generated/xarray.open_rasterio.html#xarray.open_rasterio

I think this would be easy to implement because a while back rasterio implemented a keyword argument so that you can do rasterio.open(path, overview_level=3)
rasterio/rasterio#1504

So is this just a matter of accepting kwargs in xr.open_rasterio() and passing them through?

manager = CachingFileManager(rasterio.open, filename, lock=lock, mode="r")

As seems to be done here for example:

manager = CachingFileManager(h5netcdf.File, filename, mode=mode, kwargs=kwargs)

@dcherian
Copy link
Contributor

looks right to me. Let's try it!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants