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

Feature request: Search catalog for latest datetime #751

Open
ben-epoch-blue opened this issue Oct 28, 2024 · 3 comments
Open

Feature request: Search catalog for latest datetime #751

ben-epoch-blue opened this issue Oct 28, 2024 · 3 comments
Labels
enhancement New feature or request

Comments

@ben-epoch-blue
Copy link

I am trying to search for multiple datasets:

catalog = pystac_client.Client.open("https://planetarycomputer.microsoft.com/api/stac/v1", modifier=planetary_computer.sign_inplace)
search = catalog.search(collections=['nasadem', 'esa-worldcover', 'jrc-gsw'], datetime='2021', bbox=bbox).item_collection()

However, each dataset is derived from a different time period. I would like to get the latest dataset for each collection instead of all available datasets

@gadomski gadomski added the enhancement New feature or request label Oct 28, 2024
@gadomski
Copy link
Member

This isn't too hard to implement now:

from pystac_client import Client

client = Client.open("https://planetarycomputer.microsoft.com/api/stac/v1")
items = []
for collection in ["nasadem", "esa-worldcover", "jrc-gsw"]:
    items.append(
        next(
            client.search(
                collections=[collection], max_items=1, sortby="-properties.datetime"
            ).items()
        )
    )
# items == [<Item id=NASADEM_HGT_s56w072>, <Item id=ESA_WorldCover_10m_2021_v200_S60W030>, <Item id=90W_80Nv1_3_2020>]

I don't personally think this is a common-enough pattern to be worth building functionality around, but I'll leave this issue open to collect comments if others think differently.

@ben-epoch-blue
Copy link
Author

Thank you for taking the time to write up the code!

I think it's a common use case for non-temporal analysis (in my case, creating cost layers) as there's no need for older datasets

@jsignell
Copy link
Member

jsignell commented Nov 8, 2024

This is a good example of the type of thing that might be documented in a "How to..." section of the docs. Something like this: https://docs.xarray.dev/en/stable/howdoi.html

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants