rioxarray
rioxarray copied to clipboard
ENH: Add ability to load bands as data_vars
@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
allowsopen_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.
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
.
Related:
- #525
- #573
For those interested, see #600.