Skip to content

Commit 95fa740

Browse files
authored
Fix more than one band error (#234)
Precompute band count before closing the file Fixes #233
1 parent 694c686 commit 95fa740

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

stackstac/rio_reader.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -335,9 +335,10 @@ def _open(self) -> ThreadsafeRioDataset:
335335

336336
raise RuntimeError(msg) from e
337337
if ds.count != 1:
338+
nr_of_bands = ds.count
338339
ds.close()
339340
raise RuntimeError(
340-
f"Assets must have exactly 1 band, but file {self.url!r} has {ds.count}. "
341+
f"Assets must have exactly 1 band, but file {self.url!r} has {nr_of_bands}. "
341342
"We can't currently handle multi-band rasters (each band has to be "
342343
"a separate STAC asset), so you'll need to exclude this asset from your analysis."
343344
)

0 commit comments

Comments
 (0)