Repository navigation
feat(waterdata): add catalog.search_items, the counterpart of R search_stac - #482
Draft
thodson-usgs wants to merge 6 commits into
Draft
thodson-usgs wants to merge 6 commits into
thodson-usgs wants to merge 6 commits into
Conversation
…files USGS publishes the daily and continuous collections as Parquet files, one set per monitoring location, written each night and indexed by the Water Data STAC catalog. waterdata.bulk.get_daily() and get_continuous() read a query's history from the files, and only the records changed since from the API, and return the columns and types of waterdata.get_daily() and get_continuous(), except the record id. waterdata.bulk.get_urls() lists the files and downloads nothing. waterdata.get_daily() and get_continuous() do not change. Also in this commit: - waterdata.catalog is the one STAC search. get_ratings() uses it, so a long monitoring_location_id list is split under the catalog's 2,094-character URL limit instead of failing with HTTP 403. The search stays scoped to the ratings collection (DOI-USGS#474). - files_api_key (API_USGS_FILES_PAT) is a second key, sent with requests for /stac-files/ and /stac/, so file downloads have their own hourly count. - The pyarrow extra, which the bulk getters need. [test] includes it. - On pandas 3, an OGC text column has the same type however the result was paged. Split from DOI-USGS#476, which keeps the bulk setting that routes waterdata.get_daily() and get_continuous() to the files, and ADR 0014. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- catalog: build each search through ogc.planning._try_build, so a filter over the 64 KB httpx can put in one URL component raises the ValueError with its remedy instead of httpx.InvalidURL. - One _as_list, in catalog, for ratings, catalog.search and _retrieval. - catalog.__all__ lists the names the bulk modules import. - One masked renderer for api_key and files_api_key in show_configuration. - ogc.errors._error_body reads the request URL and its key variables once. - _change_clauses builds the set of changing locations once and floors the cutoffs as one DatetimeIndex. - Without geopandas, the file rows' geometry is looked up once per location (pd.factorize), as with geopandas, instead of Series.map per row. - qualifier: only the non-null lists are converted to Python objects (1.4M rows, 3% non-null: 27 ms to 12 ms). - Wording: "the bulk getters" instead of "the files route". - Tests: the ratings scoping test duplicated DOI-USGS#474's and is removed; the world-readable warning test covers both keys; the no-pyarrow fixture leaves conftest for a monkeypatch in its one test; _response uses inert_response. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
With files_api_key, the catalog searches and file downloads count against a second key, but md.header reported the lowest x-ratelimit-remaining of every request, so it could show the files key's count as the API's. It now reports the lowest among the requests sent the change query's key. With one key, nothing changes. The live comparison with the API getters compares types only for columns with a value. The API getter types a column null in every row object, and the bulk getter keeps the files' type; method_category at USGS-01435000 has been null since 2026-10-01, so the test failed every run. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…full record Rename the second Water Data key from files_api_key / API_USGS_FILES_PAT to stac_api_key / STAC_USGS_PAT, the variable R dataRetrieval reads, so one export serves both packages. Document the bulk getters by their main use first: omit time to get a location's whole period of record. Add the example to the README, the configuration guide, the getter docstrings and NEWS. In get_urls, note that a location's current and historical continuous files can both hold a record, and show how to keep the newest last_modified in pandas and DuckDB. Scope the DuckDB example's secret to the Water Data host. Print a one-time pointer to a STAC key when a catalog search or file download is sent api_key because no STAC key is set. It is shown only for the authorized host. bulk._merge now orders file rows by last_modified, newest first, before dropping duplicates, so the newer of two overlapping files wins whatever order they were read in. Before, the first file read won. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…pe, and HUC bulk.get_urls() now takes the named location filters of get_monitoring_locations: state, state_code, state_name, agency_code, county_code, county_name, site_type_code, site_type, and hydrologic_unit_code. Each matches exactly. A single value becomes name = 'v' and several become name IN (...). The state argument accepts a name, postal code, or FIPS code and is sent as state_code. The clauses are joined by AND with the caller's CQL2 filter, which is parenthesized so an OR inside it stays inside it. A search too long for one URL raises ValueError before any request. The docstring and NEWS note that hydrologic_unit_code is not a prefix match and show a LIKE filter for every location inside a HUC8. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…h_stac Add `waterdata.catalog.search_items`, which searches the Water Data STAC catalog and returns the matching items unchanged, as GeoJSON Feature dicts with their assets, plus the search metadata. It takes one or several of the `daily`, `continuous` and `ratings` collections, searches each on its own, runs all the searches as concurrent chunks of one fan-out, and returns the items in collection order. `ratings` refuses location arguments the catalog cannot query it by, before any request is sent. The internal `catalog.search` is renamed `_search` and now accepts one collection or several. `catalog.__all__` lists `search_items` alone; the other helpers stay importable by the sibling modules that read the catalog. The location-argument filter builder (`_clause`, `_location_filter`) moves from `bulk/_urls.py` into `catalog.py`, so `search_items` and `get_urls` build the same CQL2 expression, including the `state` to `state_code` resolution. `bulk.get_urls` is now built on `search_items` and only flattens the items to one row per file. Add the Catalog item term to CONTEXT.md, the catalog page to the reference docs, and a NEWS entry. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
thodson-usgs
force-pushed
the
feat/catalog-search-items
branch
from
December 2, 2026 20:29
7007969 to
3dd8433
Compare
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Depends on #481, which depends on #479. Review only the last commit, 3dd8433.
waterdata.catalog.search_items()is the Python counterpart of R dataRetrieval'ssearch_stac. It searches the Water Data STAC catalog and returns each item as the catalog serves it (a GeoJSON Featuredictwithpropertiesandassets), withmdlike every other public getter.bulk.get_urls:monitoring_location_id, the location filters from feat(waterdata): select bulk.get_urls files by state, county, site type, and HUC #481,time,bboxandfilter.collectionis required and takes one name or a list. Each collection gets its own scoped search (see fix(waterdata): scope the ratings catalog search to its collection #474), and the items are concatenated in collection order.ratingscollection is queryable bymonitoring_location_idandagency_codeonly. A location filter it lacks raisesValueErrorbefore any request, and the message says to searchdailyfirst.bulk.get_urlsis nowsearch_itemsfor one collection plus one row per file. Its signature and frame don't change.catalog.searchis renamed_searchand leavescatalog.__all__, so the module's public names are the ones users should call. Its callers (get_ratings, the bulk getters) are updated. feat(waterdata)!: a cloud-optimized architecture that routes query chunks to the STAC files or the OGC API #476 importscatalog.searchand needs the same rename when it rebases.bulk/_urls.pytocatalog.py, where both functions use it.Evidence
search_items(["daily", "continuous"], state="MD", county_name="Montgomery County", site_type_code="ST")returns 52 items across both collections.search_items("ratings", monitoring_location_id="USGS-01646500")returns 3 items.search_items("ratings", state="MD")raises with the remedy above.Merge Danger
Door: two-way. Nothing here has been released.
Blast Radius: small. One new public function, and a private rename inside
waterdata.🤖 Generated with Claude Code