sertit / eoreader

Remote-sensing opensource python library reading optical and SAR sensors, loading and stacking bands, clouds, DEM and spectral indices in a sensor-agnostic way.
https://eoreader.readthedocs.io/en/latest/
Apache License 2.0
271 stars 22 forks source link

Return single band object instead of a list of band objects when converting a single string to band #138

Closed jsetty closed 2 months ago

jsetty commented 2 months ago

I would like to rename the DataArray key in the xr.Dataset object returned by S2Product.load() because I am unable to serialize xr.Dataset to a netCDF file. The xr.Dataset.to_netcdf() raises TypeError: DataArray.name or Dataset key must be either a string or None for serialization to netCDF files. Therefore, I rename the keys from SpectralBandNames objects to strings. When I load from the netcdf file, I would like to rename the string keys to band keys to exactly reconstuct the xr.Dataset object. For this, I call to_band for each str but the to_band returns a list.

Solution: return a single band instead of a list of bands when to_band is called with a single string

Could not find an alternative to this

remi-braun commented 2 months ago

Hi!

Thanks for this feature.

A workaround could be to take the list of all the string keys, convert them all at once in SpectralBandNames and loop on the converted keys. Wouldn't it be possible?