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

Fix for Pystac ItemCollections #69

Merged
merged 4 commits into from
Aug 30, 2021
Merged

Conversation

scottyhq
Copy link
Contributor

Follow on to #64 to work with Pystac ItemCollection https://pystac.readthedocs.io/en/latest/api.html#itemcollection.

Partially addresses #65, but did not update all the docs and examples

Not sure if I should add the poetry.lock file that I updated to test this out locally

@TomAugspurger
Copy link
Contributor

TomAugspurger commented Aug 27, 2021

FWIW, I got a different error message than what you posted in #64

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-1-5554f41e60de> in <module>
     13 )
     14
---> 15 stack = stackstac.stack(results.get_all_items(), assets=["B02", "B03"])

~/src/gjoseph92/stackstac/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:

~/src/gjoseph92/stackstac/stackstac/stac_types.py in items_to_plain(items)
    161
    162     if isinstance(items, (PystacItemCollection, PystacClientItemCollection)):
--> 163         return [item.to_dict() for item in items.features]
    164
    165     raise TypeError(f"Unrecognized STAC collection type {type(items)}: {items!r}")

AttributeError: 'ItemCollection' object has no attribute 'features'

But this PR fixes that.

+1 to tests :) I have some very basic ones started for my work on #62 that I can split out when I find time.

@scottyhq
Copy link
Contributor Author

different error message than what you posted

Whoops! indeed, the error I posted is raised if using stackstac 0.2.1 rather than the master branch (TypeError: Unrecognized STAC collection type <class 'pystac.item_collection.ItemCollection'>: <pystac.item_collection.ItemCollection object at 0x7f10d3d833a0>)

I have some very basic ones started for my work on #62 that I can split out when I find time.

sounds great to me!

Copy link
Owner

@gjoseph92 gjoseph92 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the fix @scottyhq and thanks for updating docs as well!

If you want to add some tests, by all means go for it. My time to work on stackstac is very limited right now, so I'm sure I won't get to it for a while.

Not sure if I should add the poetry.lock file that I updated to test this out locally

Yes, please add this (see https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control). That'll be especially helpful once we have CI.

pyproject.toml Outdated Show resolved Hide resolved
@@ -54,7 +54,7 @@ graphviz = "^0.16"
jupyterlab = "^3.0.14"
keyring = "^23.0.1"
py-spy = "^0.3.4"
pystac = "^0"
pystac = "^1"
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we be any stricter on minor versions? Or is any 1.x fine? Probably is fine, I'm just checking.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

less restrictive seems best, especially with pystac as a 'dev' dependency (although might be worth getting more specific if it becomes a core dependency #20)? If I understand correctly these dev pins are only considered when running poetry update where the lockfile is solved for?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes I think that's right. poetry update gives you the latest versions of everything within the bounds specified in the lockfile. Agreed that we should leave it like this for now, and we'll get more restrictive if necessary in the future.

scottyhq and others added 3 commits August 27, 2021 17:20
@gjoseph92 gjoseph92 merged commit 98809b4 into gjoseph92:main Aug 30, 2021
@amfriesz
Copy link

Hey all, Is there a status on the next release of stackstac? I'm running stackstac 0.2.1 and I'm getting the same error message @scottyhq reported while running the example from the documentation > https://stackstac.readthedocs.io/en/latest/basic.html.

@gjoseph92
Copy link
Owner

@amfriesz don't have any plans yet; my time is very limited right now. I think there are still a few things broken related to pystac—both documentation/examples/readme issues, and more broadly stac-utils/pystac#546. Pystac is so slow that I'd actually like to switch all examples away from it for now #79. So to me, that work is blocking a release.

@amfriesz
Copy link

@gjoseph92, thanks for the update.

gjoseph92 added a commit that referenced this pull request Oct 28, 2021
Until stac-utils/pystac#546 is resolved, pystac is very painful to use, so I'd rather not have it be the lead example.

Partially Revert "Fix for Pystac ItemCollections (#69)"

This reverts commit 98809b4.
gjoseph92 added a commit that referenced this pull request Oct 28, 2021
Until stac-utils/pystac#546 is resolved, pystac is very painful to use, so I'd rather not have it be the lead example.

Partially Revert "Fix for Pystac ItemCollections (#69)"

This reverts commit 98809b4.
gjoseph92 added a commit that referenced this pull request Oct 28, 2021
And fix a couple errors in #69
@gjoseph92
Copy link
Owner

Hey @amfriesz with #81, things are working well with pystac again, so I'll try to get a release out this week

gjoseph92 added a commit that referenced this pull request Oct 29, 2021
Reverts #80, and corrects a couple errors in #69
@lucadelu
Copy link

Hi,
sorry I tried to install from master using pip install git+https://github.com/gjoseph92/stackstac but I continue to have this problem

TypeError                                 Traceback (most recent call last)
<ipython-input-26-d03ca319dd0a> in <module>
----> 1 ds = stackstac.stack(planetary_search.get_all_items())

~/gitfem/euromammals/venv/lib/python3.9/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:

~/gitfem/euromammals/venv/lib/python3.9/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 0x7f420405b640>

My code is

planetary_catalog = pystac_client.Client.open(
    "https://planetarycomputer.microsoft.com/api/stac/v1"
)
planetary_search = planetary_catalog.search(
    collections=["sentinel-2-l2a"],
    bbox=bbox.values[0],
    datetime=date_range,
)
ds = stackstac.stack(planetary_search.get_all_items())

I'm doing something wrong?

print(pystac.version.get_stac_version())
print(pystac_client.__version__)
1.0.0
0.3.0

@gjoseph92
Copy link
Owner

Try pip install --upgrade git+https://github.com/gjoseph92/stackstac? What you're doing works for me on main.

Sorry I haven't gotten a release out. I was testing things out for a release and noticed some intermittent failures when upgrading rasterio (which feel thread-safety related), so I wanted to verify that first in case we need to pin versions for now.

@lucadelu
Copy link

In my case at the end I had to remove completely stackstac and reinstall it. Thanks a lot

@gjoseph92
Copy link
Owner

Hey @amfriesz and @lucadelu, I finally got a release of stackstac out. Try updating from pip now!

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 this pull request may close these issues.

5 participants