stac-utils / stac-utils/pystac-client

Error with using `max_items` and `sortby` parameters with the LandsatLook endpoint

Open
#855 5 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug external
Dominant language
Python
Stars
209
Forks
64
Avg merge
1d 2h
Merged PRs (30d)
6

Description

When submitting a search to the Landsat STAC API with PySTAC setting both max_items and sortby parameters, the returned results are repeated to match the max_items value, e.g., this search setup has only 4 scenes that satisfy it, but 10 are returned, which is the set max_items value in the search :

landsat_stac = Client.open('https://landsatlook.usgs.gov/stac-server')
query_returns = landsat_stac.search(
    collections=['landsat-c2ard-sr'],
    datetime=f"2023-11-03/2023-11-03",
    max_items=10,
    intersects=river_linestring,
    sortby=[
        {'field': 'properties.landsat:grid_vertical', 'direction': 'asc'}, 
        {'field': 'properties.landsat:grid_horizontal', 'direction': 'asc'}
    ]
).item_collection_as_dict()['features']

Of the 10 returned, the metadata dictionary for 2 scenes is repeated 3 times, while the other 2 are repeated 2 times.
When the line of code is run without the max_items flag, the "pulling" of metadata from the Landsat STAC continues, seemingly with no end.

Is there a potential fix to this, or is this snippet incorrectly formatted?

Thank you,
Toni

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the provided Client.open and search call against the Landsat STAC endpoint, comparing results with and without max_items and sortby. Trace how PySTAC Client handles pagination and item collection assembly, then verify that matching scenes are returned once and that an uncapped search terminates normally.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
api, search
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.