rioxarray icon indicating copy to clipboard operation
rioxarray copied to clipboard

ENH: Add ability to load bands as data_vars

Open snowman2 opened this issue 3 years ago • 2 comments

@alexamici brought this up in #197 and has been something I have thought about for a while and haven't come up with a great solution yet.

xarray-gdal implementation: https://github.com/bopen/xarray-gdal/blob/main/xarray_gdal/xarray_plugin.py

Benefits:

  • It could potentially enable round-trip loading in of data as in #249
  • Would provide a nice mechanism to store band specific attributes in each variable (possible fix for #81)

Why hasn't it been done already?

  • Backwards compatibility/consistency with xarray.open_rasterio
  • Loading it as a DataArray allows open_rasterio to work with multidimensional files where the band is a coordinate (time).
  • The coordinate mechanism provides a nice interface for selecting the band you are interested in by an index rds.sel(band=1).

It may make sense to have an option such as band_as_variable where you can toggle this mode on.

snowman2 avatar Apr 13 '21 20:04 snowman2

This looks like a really useful feature (and directly related to my issue in #484)

In the gdalbuildvrt tool, you can pass the option -separate that puts each file into a separate band in the VRT file (and in this case each source file can have a different dtype).

So I propose, if you make this an optional behavior, the option could be called separate.

ashleysommer avatar Mar 03 '22 04:03 ashleysommer

Related:

  • #525
  • #573

snowman2 avatar May 12 '22 02:05 snowman2

For those interested, see #600.

snowman2 avatar Nov 02 '22 13:11 snowman2