From 95fa740cb2d19d89285b198471d92520cf31e10c Mon Sep 17 00:00:00 2001 From: Daniel Wiesmann Date: Wed, 6 Dec 2023 18:48:22 +0000 Subject: [PATCH] Fix more than one band error (#234) Precompute band count before closing the file Fixes #233 --- stackstac/rio_reader.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/stackstac/rio_reader.py b/stackstac/rio_reader.py index 61e44a1..ef66182 100644 --- a/stackstac/rio_reader.py +++ b/stackstac/rio_reader.py @@ -335,9 +335,10 @@ def _open(self) -> ThreadsafeRioDataset: raise RuntimeError(msg) from e if ds.count != 1: + nr_of_bands = ds.count ds.close() raise RuntimeError( - f"Assets must have exactly 1 band, but file {self.url!r} has {ds.count}. " + f"Assets must have exactly 1 band, but file {self.url!r} has {nr_of_bands}. " "We can't currently handle multi-band rasters (each band has to be " "a separate STAC asset), so you'll need to exclude this asset from your analysis." )