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

TypeError: cannot unpack non-iterable NoneType object on seemingly valid stac item list #187

Closed
vlandau opened this issue Nov 8, 2022 · 5 comments · Fixed by #188
Closed
Labels
needs-future-test Add a test for this in the future, once tests exist (#26)

Comments

@vlandau
Copy link

vlandau commented Nov 8, 2022

I'm currently working with some elevation data from Microsoft's Planetary Computer STAC, and I'm getting a stackstac error only for a specific area/tile (other AOIs seem to work).

To reproduce:

import planetary_computer as pc
from pystac_client import Client as stac_client
import stackstac

bbox = (-104.79075, 30.86168, -104.77074999999999, 30.881680000000003)

# Open the catalog with pystac_client  
catalog = stac_client.open("https://planetarycomputer.microsoft.com/api/stac/v1")

# Search the catalog
search = catalog.search(collections=["3dep-seamless"], bbox=bbox)
items = list(search.items())

# We only want the high res layers
items_high_res = [
    pc.sign(item).to_dict()
    for item in items
    if item.properties["gsd"] == 10
]

elevation = stackstac.stack(
    items_high_res,
    bounds=bbox,
    chunksize=64
)

Output:

>>> elevation = stackstac.stack(
...     items_high_res,
...     bounds=bbox,
...     chunksize=64
... )
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/vincent/miniconda3/envs/soil_moisture/lib/python3.10/site-packages/stackstac/stack.py", line 287, in stack
    asset_table, spec, asset_ids, plain_items = prepare_items(
  File "/home/vincent/miniconda3/envs/soil_moisture/lib/python3.10/site-packages/stackstac/prepare.py", line 333, in prepare_items
    out_bounds = geom_utils.snapped_bounds(out_bounds, out_resolutions_xy)
  File "/home/vincent/miniconda3/envs/soil_moisture/lib/python3.10/site-packages/stackstac/geom_utils.py", line 73, in snapped_bounds
    xres, yres = resolutions_xy
TypeError: cannot unpack non-iterable NoneType object

As you might expect based on the stacktrace, manually setting the resolution in the stack call avoids the issue. Notably, it is successful when the bbox is set to (-97.73474, 33.785180000000004, -97.71473999999999, 33.80518)

Could something be wrong with this particular item in the STAC?

Version/environment info:

Python: 3.10.6

Package versions:

stackstac==0.4.3
planetary-computer==0.4.9
pystac_client==0.5.1

@vlandau
Copy link
Author

vlandau commented Nov 8, 2022

I'm now noticing that passing a resolution results in a DataArray that has two additional empty indices, each with length 0 (band and time). It would appear there is something wrong with the STAC items.

@gjoseph92
Copy link
Owner

Thanks @vlandau, I can reproduce it. Because of the incorrect metadata, it looks to stackstac like the item doesn't overlap with the bounds you've specified. However, there's a bug in stackstac when 0 items overlap. I'll look into how to fix that.

@gjoseph92 gjoseph92 added the needs-future-test Add a test for this in the future, once tests exist (#26) label Nov 11, 2022
@vlandau
Copy link
Author

vlandau commented Nov 11, 2022

Thanks for looking into this @gjoseph92! Let me know if there's anything I can do to help out.

@gjoseph92
Copy link
Owner

Just merged a fix. I confirmed it works for your example, so no need to test it, but if you need something that works, go ahead and install from main for now.

@vlandau
Copy link
Author

vlandau commented Nov 11, 2022

Awesome, thanks for such a speedy resolution to this @gjoseph92, and that's for all your work on this software package!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs-future-test Add a test for this in the future, once tests exist (#26)
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants