Repository navigation
feat(waterdata): list the STAC-indexed Parquet files - #475
Closed
thodson-usgs wants to merge 4 commits into
Closed
thodson-usgs wants to merge 4 commits into
thodson-usgs wants to merge 4 commits into
Conversation
USGS now publishes the daily and continuous collections as Parquet files, one set per monitoring location, indexed by the Water Data STAC catalog (https://waterdata.usgs.gov/blog/api-faster-access/). The file host cannot be listed, so the catalog is the only way to learn which files exist. Add waterdata.get_parquet_files(collection, ...). It searches the catalog by monitoring location, time, bbox, or a CQL2 filter over monitoring-location fields, and returns (DataFrame, BaseMetadata) with one row per file: monitoring_location_id, asset (data / current / historical), url, start_datetime, end_datetime. It downloads nothing. The URLs go to a Parquet reader; the docstring shows DuckDB and Dask. Move the STAC item search out of ratings into waterdata.catalog so both getters share one page walk, and scope it to one collection. /search spans every collection, so get_ratings(download_and_parse=False) with a list of file types also returned each location's daily and continuous items once those collections were published.
This was referenced Nov 21, 2026
…er URL limit The Water Data STAC /search edge answers HTTP 403 (an HTML "Forbidden" page) to any GET URL longer than 2,094 characters, measured by bisection on 2026-11-22. get_parquet_files and get_ratings put the caller's whole monitoring_location_id list into one IN (...) filter in one search, so about 60 ids like OH015-383638082103300 or about 90 USGS ids failed with a 403 that named no remedy. catalog.search_items is split into _search_params and _run_search, which sends every request through one run_paginated call. search_items_chunked runs one search per filter as concurrent chunks and deduplicates items by (collection, id). chunk_in_filters splits the ids into chunks whose URL-encoded IN clause fits EDGE_URL_LIMIT less headroom, sized per id and capped at one page. Both getters use it and keep their frame shape, sorting, metadata and collection scoping. A filter, time or bbox that alone exceeds the limit raises ValueError before any request.
pd.to_datetime infers one format from the first value; continuous items mix 2005-10-01T04:00:00Z and 2018-12-04T22:26:36.420930Z, so a state-wide continuous listing raised ValueError. Parse as ISO 8601.
thodson-usgs
added a commit
to thodson-usgs/dataretrieval-python
that referenced
this pull request
Nov 22, 2026
bulk="auto" sends a query the bulk path cannot honor to the API, and otherwise estimates the rows the API would page through (locations x series x values per day x days) without a request. It reads the files when that exceeds 10,000 rows plus a per-location download cost (250 rows' worth for a daily or current file, 10,000 for a historical one). The constants come from a benchmark against the live services that drew fresh monitoring locations for every run, so no run hit a warm cache: 31 query shapes, two runs each, both paths. The rule picks the faster path in 29; the two misses cost 0.1 s and 0.4 s. A holdout of 7 shapes over other states: 7 of 7. bulk=False stays the default. Also: a live test that reads three files' footers with range requests and pins the layout a range-request reader would rely on (time-sorted, 50,000-row groups, UTC last_modified); and the catalog-time parsing fix from DOI-USGS#475 (fractional seconds), until this branch is rebased on it.
thodson-usgs
added a commit
to thodson-usgs/dataretrieval-python
that referenced
this pull request
Nov 22, 2026
- prefer_bulk reuses _check_args for eligibility instead of repeating it. - One _ROW_MODEL table and two named per-file constants replace three collection-keyed dicts and a string-keyed one. - _needs_historical replaces the continuous/current-window check that get_bulk and prefer_bulk each spelled out. - use_bulk resolves bulk='auto' in one place; each getter's dispatch is one condition. - Tests: the router cases are one table (max_rows included), and imports are at module level. The layout test reads each footer with one 64 KB suffix range, adding a second only for a footer that outgrows it. - Mark the URL-length splitter as a stopgap for DOI-USGS#475's chunk_in_filters.
thodson-usgs
added a commit
to thodson-usgs/dataretrieval-python
that referenced
this pull request
Nov 23, 2026
… bulk setting USGS now publishes the daily and continuous collections as Parquet files, one set per monitoring location, rewritten every night and indexed by the Water Data STAC catalog (https://waterdata.usgs.gov/blog/api-faster-access/). This commit combines DOI-USGS#475 and DOI-USGS#476. waterdata.get_parquet_files(collection, ...) lists the files. It searches the catalog by monitoring location, time, bbox, or a CQL2 filter over monitoring-location fields, and returns (DataFrame, BaseMetadata) with one row per file. It downloads nothing. A Water Data setting, bulk ("off", "auto", "always"), makes get_daily and get_continuous read a location's history from those files and only the records changed since from the API. "off" is the default and changes no call. "auto" reads the files for a query large enough to finish sooner, and "always" for every query they can answer. ADR 0014 records the design, the merge rule, the routing rule and its benchmark, and the alternatives. Structure: - waterdata.catalog.search is the one catalog search. It owns the edge's 2,094-character URL limit: it splits a long monitoring_location_id list across concurrent searches that fit, and raises before any request when the rest of the query cannot fit. get_ratings, get_parquet_files, and the bulk path pass identifiers and expressions and never size a URL. - The getters call one entry point, waterdata._bulk.get_data, which reads the setting and answers from the files or the API. A call's arguments are parsed once into a query, and what differs between daily and continuous is one table. - The file downloads run on FanOut, which combines their rows. The change query and the merge are its finalize hook, so exc.call.resume() returns the whole result. - transport.fanout.inert_response is the body-less response a download hands the executor. It moved from ratings, so the bulk path does not import from another collection family. Result contract: daily_id and continuous_id are random version-4 UUIDs that the files do not hold. With "auto" or "always", a query the files can answer returns no such column, whether the files or the API answered it, so the columns do not depend on the route. A query only the API accepts, and every call under "off", is returned as before. A record deleted from the API since the files were written is still returned until the next night's files. Bug fixes in get_ratings: the search is limited to the ratings collection (it returned daily and continuous items for a list of file types), and a long monitoring_location_id list no longer fails with HTTP 403. pyarrow is a new optional extra, dataretrieval[bulk]. Without it, a query the setting sends to the files pages the API and warns. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Collaborator
Author
|
Combined into #476, which now holds this work and the bulk setting as one commit. The branch |
thodson-usgs
added a commit
to thodson-usgs/dataretrieval-python
that referenced
this pull request
Nov 23, 2026
… bulk setting USGS now publishes the daily and continuous collections as Parquet files, one set per monitoring location, rewritten every night and indexed by the Water Data STAC catalog (https://waterdata.usgs.gov/blog/api-faster-access/). This commit combines DOI-USGS#475 and DOI-USGS#476. waterdata.get_parquet_files(collection, ...) lists the files. It searches the catalog by monitoring location, time, bbox, or a CQL2 filter over monitoring-location fields, and returns (DataFrame, BaseMetadata) with one row per file. It downloads nothing. A Water Data setting, bulk ("off", "auto", "always"), makes get_daily and get_continuous read a location's history from those files and only the records changed since from the API. "off" is the default and changes no call. "auto" reads the files for a query large enough to finish sooner, and "always" for every query they can answer. ADR 0014 records the design, the merge rule, the routing rule and its benchmark, and the alternatives. Structure: - waterdata.catalog.search is the one catalog search. It owns the edge's 2,094-character URL limit: it splits a long monitoring_location_id list across concurrent searches that fit, and raises before any request when the rest of the query cannot fit. get_ratings, get_parquet_files, and the bulk path pass identifiers and expressions and never size a URL. - The getters call one entry point, waterdata._bulk.get_data, which reads the setting and answers from the files or the API. A call's arguments are parsed once into a query, and what differs between daily and continuous is one table. - The file downloads run on FanOut, which combines their rows. The change query and the merge are its finalize hook, so exc.call.resume() returns the whole result. - transport.fanout.inert_response is the body-less response a download hands the executor. It moved from ratings, so the bulk path does not import from another collection family. Result contract: daily_id and continuous_id are random version-4 UUIDs that the files do not hold. With "auto" or "always", a query the files can answer returns no such column, whether the files or the API answered it, so the columns do not depend on the route. A query only the API accepts, and every call under "off", is returned as before. A record deleted from the API since the files were written is still returned until the next night's files. Bug fixes in get_ratings: the search is limited to the ratings collection (it returned daily and continuous items for a list of file types), and a long monitoring_location_id list no longer fails with HTTP 403. pyarrow is a new optional extra, dataretrieval[bulk]. Without it, a query the setting sends to the files pages the API and warns. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
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.
What
waterdata.get_parquet_files(collection, ...)lists the Parquet files that USGS now publishes for thedailyandcontinuouscollections (announcement). It searches the STAC catalog and returns(DataFrame, BaseMetadata)with one row per file:monitoring_location_id,asset(data,current,historical),url,start_datetime,end_datetime. It downloads nothing.The URLs go to any Parquet reader. Docstring examples show DuckDB (
read_parquetover a list, which fetches only the row groups theWHEREclause needs) and Dask (dd.from_map(pd.read_parquet, urls, ...)).Includes the fix from #474 (merge that first; this branch then rebases cleanly).
get_ratings()searched/searchwithoutcollections=. Sincedailyandcontinuouswere published,get_ratings(monitoring_location_id="USGS-01104475", file_type=["exsa", "corr"], download_and_parse=False)returned 5 items: 3 ratings plus the location'sdailyandcontinuousitems. The STAC page walk moved towaterdata/catalog.py, so both getters share it, and it always names its collection.Findings that shaped the design
429withretry-after: 1789after a few dozen files. WithX-Api-Key, the responses carryx-ratelimit-limit: 10000, and each range request consumes one unit. A DuckDB read of 20 files used 13 units. The docstring tells callers to send the key.?list-type=2returns 403), so the catalog is the only inventory. The prod bucket is not in thegs-chs-wma-devaccount, which is the only account my SSO reaches.Last-Modified06:00 UTC, new ETags).currentasset, sohistoricalis not guaranteed.dd.read_parquetover HTTPS fails with dask 2026.8 and fsspec 2026.9 (ClientSession._request() got an unexpected keyword argument 'default_cache'). That is an upstream bug, so the example usesdd.from_mapinstead.scan_parquetdid not send the header throughstorage_optionsand hit 429.Virtual dataset: assessment, not implemented
The question was whether something like VirtualiZarr could hold these URLs and present them as one dataset.
read_parquet([...]),pyarrow.dataset.dataset([...]), Polars, Dask. VirtualiZarr exists because NetCDF and HDF5 chunk byte offsets need an external index before Zarr readers can use them. Parquet doesn't have that problem.ducklake_add_data_filesregistered 10 of the remotehttps://URLs as one table without copying them, and queries pruned correctly.Not in this PR
get_dailyandget_continuous(Phase 2). It would fan out one chunk per file overtransport.fanout.FanOut. It needs pyarrow as an optional extra, so it should wait for a decision on that and for WDFN to confirm that the URL layout is stable.feat/waterdata-stac-apibranch (rawwaterdata.stacnamespace): this PR doesn't depend on it. If both land,catalog.search_itemsis the shared core.Checks
ruff, ruff format, mypy (strict), lint-imports (7 kept), xenon, complexipy all pass. The full suite has 1672 passing tests, and coverage is 99.17% (the ratchet is 98.9). The new modules are fully covered.
Fix: chunk searches under the catalog edge's URL limit (122a4cc)
The catalog's
/searchedge answers HTTP 403 (an HTML "Forbidden" page) to any GET URL longer than 2,094 characters (bisected 2026-11-22: 2,094 is served, 2,095 is refused).get_parquet_filesandget_ratingssent everymonitoring_location_idin oneIN (...)filter, so about 60 ids likeOH015-383638082103300, or about 90USGS-ids, failed with a 403 that named no remedy.catalog.py:search_itemsis now a thin wrapper over_search_paramsand_run_search, which sends all requests through onerun_paginatedcall. Newsearch_items_chunkedruns one search per filter as concurrent chunks and deduplicates items by(collection, id). Newchunk_in_filterssplits the ids so each URL-encodedINclause fitsEDGE_URL_LIMITless headroom, sized per id and capped at one page.collections=ratingsscoping. Afilter,timeorbboxthat alone exceeds the limit raisesValueErrorbefore any request.bbox(all offline). Gates (ruff, mypy, lint-imports, xenon, complexipy, coverage) pass.Live check against the real service:
get_parquet_files('daily', filter="state_code = '39'")returned 989 Ohio files. Passing the first 600 ids returned 600 rows, identical (ids, assets, URLs) to the state query restricted to those ids.get_ratings(monitoring_location_id=<200 USGS ids>, download_and_parse=False)returned 200 features covering all 200 ids.