gjoseph92 / stackstac

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

Support `pystac.ItemCollection` #64

Closed TomAugspurger closed 3 years ago

TomAugspurger commented 3 years ago

https://github.com/stac-utils/pystac/pull/430 implemented pystac.ItemCollection, which is being removed from pystac-client in the next release. This PR adds similar handling for pystac.ItemCollection.

I haven't updated the documentation notebooks yet, since pystac and psytac-client are still in a release-candidate / beta. Once they're released I think the notebooks can be updated.

TomAugspurger commented 3 years ago

We should probably bump the pystac dependency to 1.0 once that's released, no?

Yeah, I think so. Both pystac-client and intake-stac will require pystac>=1.0 for their next releases.

scottyhq commented 3 years ago

@TomAugspurger @gjoseph92 I was just testing this out, but the iteration syntax needs to be changed to work with PyStac.ItemCollection. You can test with the basic example:

import pystac_client
import stackstac

URL = "https://earth-search.aws.element84.com/v0"
catalog = pystac_client.Client.open(URL)

lon, lat = -105.78, 35.79

results = catalog.search(
    intersects=dict(type="Point", coordinates=[lon, lat]),
    collections=["sentinel-s2-l2a-cogs"],
    datetime="2020-04-01/2020-05-01"
)

stack = stackstac.stack(results.get_all_items())
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<timed exec> in <module>

/srv/conda/envs/notebook/lib/python3.8/site-packages/stackstac/stack.py in stack(items, assets, epsg, resolution, bounds, bounds_latlon, snap_bounds, resampling, chunksize, dtype, fill_value, rescale, sortby_date, xy_coords, properties, band_coords, gdal_env, errors_as_nodata, reader)
    278         automatically computed from the items you pass in.
    279     """
--> 280     plain_items = items_to_plain(items)
    281 
    282     if sortby_date is not False:

/srv/conda/envs/notebook/lib/python3.8/site-packages/stackstac/stac_types.py in items_to_plain(items)
    157         return [item.to_dict() for item in items.features]
    158 
--> 159     raise TypeError(f"Unrecognized STAC collection type {type(items)}: {items!r}")

TypeError: Unrecognized STAC collection type <class 'pystac.item_collection.ItemCollection'>: <pystac.item_collection.ItemCollection object at 0x7f10d3d833a0>

Thoughts on just having some basic pytest tests to catch stuff like this before all the ideas for testing here https://github.com/gjoseph92/stackstac/issues/26 ?