gjoseph92 / stackstac

Turn a STAC catalog into a dask-based xarray
https://stackstac.readthedocs.io
MIT License
232 stars 49 forks source link

Error for assests with multiple bands is not raised correctly #233

Closed yellowcap closed 8 months ago

yellowcap commented 8 months ago

Currently there is a ValueError being raised because the ds.count statement in the error message is executed on a closed file. So

File ~/apps/miniforge3/envs/devseed/lib/python3.11/site-packages/stackstac/rio_reader.py:340, in AutoParallelRioReader._open(self)
    337 if ds.count != 1:
    338     ds.close()
    339     raise RuntimeError(
--> 340         f"Assets must have exactly 1 band, but file {self.url!r} has {ds.count}. "
    341         "We can't currently handle multi-band rasters (each band has to be "
    342         "a separate STAC asset), so you'll need to exclude this asset from your analysis."
    343     )

With the following error

ValueError: Can't read closed raster file

Proposed solution: compute count before clsoing file.