Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
yellowcap opened this issue Dec 6, 2023 · 0 comments · Fixed by #234
Closed

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

yellowcap opened this issue Dec 6, 2023 · 0 comments · Fixed by #234

Comments

@yellowcap
Copy link
Contributor

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.

@yellowcap yellowcap changed the title Error for assests with multiple bands is not raised correctly/ Error for assests with multiple bands is not raised correctly Dec 6, 2023
yellowcap added a commit to yellowcap/stackstac that referenced this issue Dec 6, 2023
Precompute band count before closing the file
Fixes gjoseph92#233
gjoseph92 pushed a commit that referenced this issue Dec 6, 2023
Precompute band count before closing the file
Fixes #233
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant