Skip to content

feat(waterdata)!: a cloud-optimized architecture that routes query chunks to the STAC files or the OGC API - #476

Draft
thodson-usgs wants to merge 18 commits into
DOI-USGS:mainfrom
thodson-usgs:feat/bulk-getters
Draft

thodson-usgs wants to merge 18 commits into
DOI-USGS:mainfrom
thodson-usgs:feat/bulk-getters

Conversation

@thodson-usgs

@thodson-usgs thodson-usgs commented Nov 22, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Water Data now serves daily and continuous records from two endpoints: the OGC API, which pages through any query, and Parquet files that USGS writes to S3 each night, one set per monitoring location, indexed by a STAC catalog (announcement). This PR adds two ways to read them. A public package, waterdata.bulk, has get_daily and get_continuous, which answer every query from the files plus the API's changes, and get_urls, which lists the files. And a routing layer behind waterdata.get_daily and waterdata.get_continuous, with their signatures unchanged, sends a large query the same way. For each query, the router estimates the rows from the arguments, without a request. A small query pages the OGC API as before. A large one is split into chunks, and each chunk goes to one endpoint: one chunk per file reads a location's history from the files, and a few change-query chunks ask the OGC API for the records modified since each file was written, which only the API has. The API's copy of a record replaces the file's, so the result has the API's rows, columns, and types, less the record id.

One get_continuous query for 50 monitoring locations: a catalog request, a chunk plan of 108 chunks colored by endpoint with a row per monitoring location and columns along a time axis, and a fan-out that sends every chunk across the boundary between dataretrieval-python and api.waterdata.usgs.gov, through one load balancer, to the STAC catalog, the Parquet files, or the OGC API

The figure follows one query: get_continuous for 50 monitoring locations since 2025-07-01. The catalog request goes through the fan-out to the STAC catalog, and the Parquet URLs it returns are what the chunk plan is built from. The plan has 108 chunks, colored by endpoint: a row for each monitoring location, and columns whose widths follow the time axis. A chunk on the files path is one whole file, so the plan follows the way USGS stores the data: two file downloads per location (the historical file up to 150 days ago and the current file from then to T, the time of the last Parquet update), and a change query for every record modified since T, sent as 8 chunks of up to 7 locations each (step 3 below). The fan-out sends every request to one load balancer, in three runs in order: the catalog request, the file downloads, and the change query once every file is read. The dashed line is the boundary between dataretrieval-python and the service. The TikZ source is 0014-cloud-optimized-architecture.tex, beside the PNG that ADR 0014 includes.

Each step divides its work into chunks and sends them as one fan-out. Every chunk goes to the same host, which routes it by URL path to the catalog, the files, or the OGC API.

waterdata/
├── catalog.py         # the one STAC search; also used by get_ratings
├── _routing.py        # the bulk setting: off or auto, the row estimate, the pyarrow fallback
├── time_series.py     # get_daily / get_continuous -> _routing.get_data
└── bulk/              # never imports _routing, time_series, or api (.importlinter)
    ├── __init__.py    # get_daily, get_continuous, get_urls
    ├── _getters.py    # the bulk getters: only the arguments the files can answer
    ├── _retrieval.py  # the files route: parse(args) -> Query, read(Query) -> (df, md)
    └── _urls.py       # get_urls
bulk.get_daily(ids, ...) / bulk.get_continuous(ids, ...)
  read(parse(args))                                every query
waterdata.get_daily(...) / waterdata.get_continuous(...)
  _routing.get_data(args)
    "off"                                          get_ogc_data(args)
    "auto": query = _files_query(args)             None for an argument the bulk getters do not take
      if query and _prefers_files(query): read(query)
      else: get_ogc_data(args), less the record id

read(query)
  1 catalog.search(ids)                   chunks: ids split so each URL is <= 2,094 characters  -> /stac/v0/search
  2 FanOut, one chunk per file            current, historical; rows filtered while reading       -> /stac-files/...
      T[location] = newest last_modified in its current file, floored to the day
  3 get_ogc_data(change query)            one OR clause per cutoff day and group of locations,
                                          plus the whole query for locations without a file;
                                          one chunk per clause: up to 8, then 10 locations each,
                                          no more than the concurrency cap; daily sends no time   -> /ogcapi/...
  4 merge                                 the API copy of a (time_series_id, time) replaces the file
                                          copy; approval_status and method_category filtered after

Steps 3 and 4 run as the downloads' finalize hook, so exc.call.resume() after an interruption returns the whole result.

Call Route
waterdata.bulk.get_daily / get_continuous Files + changes for every query. The signature takes only monitoring_location_id (required), parameter_code, statistic_id, time_series_id, approval_status, unit_of_measure, method_category (continuous), time, and skip_geometry; any other argument is a TypeError. Without pyarrow, ImportError.
waterdata.get_*, bulk="auto" (default) Files + changes when the estimated rows (locations × series × values per day × days) exceed a base (5,000 for daily, 10,000 for continuous) plus a per-file cost (100 rows for a daily or current file, 10,000 for a historical one). The API for the rest, including every query the bulk getters could not take.
waterdata.get_*, bulk="off" The API for every query, with the record id.
from dataretrieval.waterdata import bulk

df, md = bulk.get_continuous(sites, parameter_code="00060", time="2025-07-01/..")
urls, md = bulk.get_urls("daily", filter="state_code = '39'")

What the service does with the chunks

Checked on 2026-11-23 from DNS and response headers. Every chunk, from either path, is a separate HTTPS request to api.waterdata.usgs.gov, and every request passes the same hops:

  1. cloud.gov load balancer and Cloud Foundry router. The host name is a CNAME to api.data.gov, which is a CNAME to external-domains-production.cloud.gov. Every response has an x-vcap-request-id.
  2. api.data.gov gateway (API Umbrella). It checks the API key and counts requests (x-api-umbrella-request-id, via: ... api-umbrella). The three paths share one hourly count per key, with a different ceiling for each. After 33 keyed requests spread across the three, the OGC API reported 967 of 1,000 remaining and the catalog 3,968 of 4,000.
  3. CloudFront with a WAF. Every response has via: ... cloudfront.net and x-cache. A 2,095-character catalog URL is refused with HTTP 403 and x-cache: Error from cloudfront. The 2,094-character limit is the 46-character path plus 2,048 query-string bytes, which matches the query-string limit of the AWS WAF core rule set.
  4. Three origins, chosen by path. /ogcapi/ (the OGC API, x-build-version: 1.19.0), /stac/ (the STAC API, 0.3.4), and /stac-files/ (S3: x-amz-server-side-encryption and multipart ETags). The headers do not show whether the gateway or CloudFront routes by path.

The client creates the concurrency: FanOut sends up to API_USGS_CONCURRENT chunks at once. The service has one load balancer in front of every request and then routes each chunk by URL path. No second load balancer is visible. The origins serve concurrent chunks in parallel: a 35-year daily pull took 1.77 s as one request and 0.69 s as 12 concurrent time chunks (measured 2026-11-17 for #469). What runs behind CloudFront is not visible from the client.

Issues with the hybrid architecture

Found by reading the files route (now bulk/_retrieval.py) and checking the files and the API on 2026-11-23. Issues 1, 4, and 5 are fixed or addressed in this PR; the rest are open. Issue 8 was found on 2026-11-24.

  1. Fixed: possible data loss when a location's two continuous files come from different nights. current starts at the value after historical ends (nine gages checked). historical is rewritten only after one of its records changes: its Last-Modified ranged from 2026-10-26 to that night across ten gages. When historical is rewritten, its end moves to 150 days before that night, and the new current starts there. A new current read with an old historical misses the records between the two ends, and the change query does not return them because they have not changed. For USGS-02037500 that is four weeks of 15-minute values: its historical ends 2026-05-29, and a rewrite on 2026-11-24 would move the end to 2026-06-27. The reverse pair, an old current with a new historical, overlaps (the merge removes the duplicates), and it misses recent values when the new file's cutoff falls on a later UTC day. CloudFront serves the files without Cache-Control and kept one for at least 10 minutes. The files were written between 06:11 and 09:21 UTC on 2026-11-23, so a mixed pair is possible during that window and for as long as CloudFront keeps the older file. Not observed. Fixed in 1f5e7e6: where a location's current file starts more than 12 hours after its historical file ends, the change query gets one more clause asking the API for every record between them. A gage that recorded nothing there costs an empty answer. The cutoff is now the current file's instead of the later of the two, so an old current no longer hides the changes made since its own snapshot.
  2. A missing historical asset would drop history without an error. Not observed. _plan downloads only the assets an item lists, and only a 404 marks a location as missing. In 730 Ohio continuous items, 228 listed only historical and 6 listed only current. None of the 6 had API records in the 1,000 days before its current file starts, and none of 8 historical-only items checked had a current file (404). Three of the 6 had an unlisted historical file at the usual URL, holding 64 to 178 rows that the API no longer serves, so the catalog listing was the correct one. Fix, as a safeguard: when the query needs historical and the item has none, add the location to missing.
  3. Revisions to old continuous records depend on the rewrite rule. The cutoff is the current file's newest last_modified. That is correct while historical is rewritten the night after one of its records changes. For five gages whose historical predated the current night, the API had no change in the last 1,000 days of that file's range after it was written. If USGS rewrites historical on a schedule instead, a revision made between rewrites is missed and the result has the old value. Fix: add one clause per group of locations, time <= historical end AND last_modified >= historical written, which returns no rows while the rule holds.
  4. Fixed: a long continuous query downloaded every file, then failed. The continuous collection refuses a time argument with an open start or a span over 1,100 days (HTTP 400), whatever the filter. Such a query was routed to the files, downloaded them, and then sent the same time in the change query. The API accepts a query with no time, and a filter can compare time itself (both checked live). Fixed in 1f5e7e6: when the query's time is over the limit, the change query sends none, and every clause carries the bounds instead. Live, get_continuous for 8 gages with time="2000-01-01/.." returned 2.44 million rows in 12.8 s, equal to the API on a 2012 day and over the last week. Under "off" the same call still fails on its first request.
  5. Addressed with a second key: the change query could exceed the hourly ceiling after the downloads finish. USGS counts requests per key, not per endpoint, with ceilings of 1,000 (OGC API), 4,000 (catalog), and 10,000 (files). The change query runs last, so a pull of about 1,000 files under one key left it no OGC requests, and it failed with HTTP 429 after every download. The service's maintainer recommends a separate key for the files. This PR adds files_api_key (API_USGS_FILES_PAT), sent in place of api_key only on requests under /stac-files/ and /stac/, as he suggested, so the downloads and catalog searches have their own count and the change query is the only request the files path sends under api_key. The cost is the catalog's ceiling: once the files' key has made 4,000 requests in an hour, the next query's search is refused, before any download. With one key, the limit remains, and the interruption is resumable: exc.call.resume() after the hour returns the whole result. Not tested live with two keys.
  6. Without pyarrow, every large query warns. pip install dataretrieval does not install pyarrow, so under the new default each large get_daily or get_continuous call pages the API and emits a UserWarning. For the major release, pyarrow could become a required dependency (docs: show how pyarrow reduces result memory, and test with it in CI #468 measured 62% less frame memory with it on pandas 3).
  7. Known and documented: a record deleted from the API since the files were written is still returned until the next files. The cases seen are rolling windows: Provisional daily values after 3 years, and series that keep 120 days. The merge keys on (time_series_id, time), so a record whose time was corrected would also leave its old file row in the result. Not observed.
  8. A parameter_code list takes part of the change query's fan-out. The OGC planner caps the total chunk count across every list argument and the filter. With a list of codes, some chunks split the list, and each request names two or more change clauses, which the API answers more slowly. A single code is not affected. Fix: a planner option that splits the filter first. Not measured.

Checked, and not an issue:

  • With both files from the same night, the boundary has no gap or overlap (nine gages).
  • Skipping historical for a query that starts within 120 days is safe: current covered 150 to 178 days on every gage checked.
  • The change query still fits the URL limit with a parameter_code list. The request builder folds the list into each chunk after the planner splits at OR. Offline, 600 locations with two codes made 2 GET chunks of at most 7,362 bytes (before the split in step 3).

Also in this PR

  • waterdata.bulk.get_urls(collection, ...) lists the files from the catalog by monitoring location, time, bbox, or a CQL2 filter, and downloads nothing. This PR includes feat(waterdata): list the STAC-indexed Parquet files #475, where it was waterdata.get_parquet_files.
  • waterdata.catalog.search is the one catalog search, and the only code that sizes a URL for the 2,094-character limit. get_ratings now uses it, which fixes two bugs: it searched every collection, and a long monitoring_location_id list failed with HTTP 403.
  • files_api_key is a new package-wide setting for a second API key, used only for the published files and their catalog (issue 5).
  • pyarrow is a new optional extra, dataretrieval[pyarrow], included in [test] and [doc].
  • Every OGC getter (waterdata and ngwmn) types a text column the same however the result was paged. On pandas 3, a column such as method_category was object whenever one page held only nulls for it. This is its own commit, afdc0b7, so it can ship in a 1.x release.
  • From review: the files path returns continuous geometry; the record id is left out of every answer under "auto" unless properties names it; md is the same on both paths; a 403 or 429 names the key the request was sent; an interrupted change query resumes through exc.call.resume(); and the configuration guide's example profile is [waterdata.overnight], since a [waterdata.bulk] table cannot sit beside the bulk setting.
  • ADR 0014 (Proposed) records the design, the two entry points, the merge rule, the routing rule and its benchmark, and the alternatives, including the "always" mode the bulk getters replace, and includes the figure above. This revision corrects its description of the files from the checks above.

Evidence

  • Before (4be181f): configuration.bulk(adapter="waterdata") returned "off" with nothing configured, so every call paged the API.
    After (f1dbec0): test_bulk_is_auto_unless_code_or_the_waterdata_table_sets_it passes: "auto" by default, "off" from the [waterdata] table, and a configure() block over both. Nine tests of the API path now take a bulk_off fixture.
  • Before (4d246e3): the files route was reachable only through bulk="always", and an argument it could not answer raised ValueError inside the call.
    After (b094968): test_a_bulk_getter_takes_the_arguments_the_files_route_accepts pins each bulk getter's signature to the route's accepted arguments, and the waterdata-bulk import contract is KEPT (a probe import of time_series from bulk/_urls.py makes it BROKEN). The routing tests are in tests/waterdata_routing_test.py.
  • On the branch head (b094968): 1,774 tests pass, coverage is 99.02% (the ratchet is 98.9), and ruff, ruff format, mypy (strict), lint-imports (8 contracts), xenon, complexipy, and pre-commit pass. The docs build renders the dataretrieval.waterdata.bulk reference section. Live, bulk.get_daily matches waterdata.get_daily under "off". The live continuous comparison fails on 4d246e3 and on b094968 alike: USGS-01435000's method_category is null in every row since 2026-10-01, and on pandas 3 the API path types the column object and the files path str. New tests pin files_api_key: sent only under /stac-files/ and /stac/, never to another host, api_key when unset, and never printed by show_configuration.
  • Live and cold on 2026-11-24: every run used never-queried monitoring locations and its own time window, and CloudFront reported no cache hit on the API.
    • The daily change query without a time window: the files path was faster in 5 of 7 query shapes (25 gages over 5 years: 10.3 s to 4.6 s), the same in 1, and 2 s slower in 1. Rows, values, columns, and types matched bulk="off" in all 5 shapes compared. A continuous change query without its window took 11 to 14 s or timed out, so it keeps the window.
    • The change query split into concurrent requests: 100 gages' change query took 12.1 s as one request and 1.2 s as ten. End to end, 20 daily gages over 10 years went from 2.6 s to 1.9 s, and 5 continuous sites over 60 days from 5.5 s to 3.0 s.
    • The lower daily base: one site with many daily series over 5 years took 4.6 s from the API and 1.8 s from the files. A single-series gage just over the base is 0.3 s slower from the files.
  • Benchmark from ADR 0014 (2026-11-22, before this revision lowered the daily base): 40 Ohio gages' full daily record took 39.8 s from the API and 10.6 s from the files, and 100 gages' whole daily record took 304.5 s and 9.7 s. The router picked the faster path in 29 of 31 query shapes. The two misses cost 0.1 s and 0.4 s.

Merge Danger

Door: one-way for callers of waterdata.get_daily and get_continuous. The waterdata.bulk package changes no existing call and could ship alone in a minor release. The default removes daily_id / continuous_id from every get_daily and get_continuous result the files can answer, including the small queries the router sends to the API. Restoring "off" later would be a second breaking change. In the code, the default is one constant in a private module.

Hold for the next major release, and re-date the NEWS entry to the merge date.

Blast Radius: every caller of get_daily and get_continuous.

A query routed to the files depends on file behavior USGS has not documented as a contract (issues 1 to 3). Before merge, confirm the file layout, the rewrite rule for historical, and the retention rules with WDFN, and decide whether issues 2, 3, and 6 are fixed here or in follow-ups. The maintainer also says the files can be a week behind the API. The result does not depend on the lag, because the cutoff is read from each file, but the router's benchmark assumed files a day old.

🤖 Generated with Claude Code

Comment thread dataretrieval/waterdata/_bulk.py Resolved
Comment thread dataretrieval/waterdata/_bulk.py Resolved
Comment thread dataretrieval/waterdata/_bulk.py Resolved
Comment thread dataretrieval/waterdata/_bulk.py Resolved
Comment thread NEWS.md Resolved
Comment thread dataretrieval/waterdata/catalog.py Resolved
Comment thread pyproject.toml Resolved
Comment thread dataretrieval/waterdata/_bulk.py Resolved
@thodson-usgs thodson-usgs changed the title feat(waterdata): bulk=True for get_daily and get_continuous Bulk retrieval for get_daily/get_continuous via a Water Data 'bulk' setting Nov 22, 2026
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>
@thodson-usgs thodson-usgs changed the title Bulk retrieval for get_daily/get_continuous via a Water Data 'bulk' setting feat(waterdata): list the nightly Parquet files, and read them with a bulk setting 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>
@thodson-usgs thodson-usgs added the v2 Breaking or major change: defer to the 2.0 release label Nov 23, 2026
get_daily and get_continuous now choose per query, without a request,
between the nightly Parquet files plus the API's changes and the API
alone. This is a breaking change for the next major release: under
"auto", a query the files can answer returns no daily_id /
continuous_id column, whichever path returned it. bulk = "off" in the
[waterdata] table keeps the column.

The default is a named constant, DEFAULT_BULK, beside BULK_MODES.
Tests of the API path take a bulk_off fixture. The [doc] extra installs
pyarrow, because the demos run under the default.

ADR 0014 is corrected from live checks on 2026-11-23: historical files
are rewritten only after one of their records changes (Last-Modified
from 2026-10-26 to that night across ten gages), current starts at the
value after historical ends, and the OGC API, the catalog, and the files
share one hourly count per key with ceilings of 1,000, 4,000, and 10,000.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@thodson-usgs thodson-usgs changed the title feat(waterdata): list the nightly Parquet files, and read them with a bulk setting feat(waterdata)!: a cloud-optimized architecture that routes query chunks to the STAC files or the OGC API Nov 23, 2026
@ehinman

ehinman commented Nov 23, 2026

Copy link
Copy Markdown
Collaborator

Am I reading this correctly? On "auto", a request for 2025-present data for 3 sites will hit the STAC files and the OGC API because the number of rows returned will be > 10,000?

thodson-usgs and others added 11 commits November 23, 2026 13:12
One get_continuous call drawn as its catalog request, its chunk plan, and
the fan-out that sends each chunk through the load balancer to the STAC
catalog, the Parquet files, or the OGC API. The TikZ source sits beside the
rendered PNG, with the commands that rebuild it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The catalog request now passes under the chunk plan and enters the fan-out
from below, so the STAC catalog lane is the bottom one. The endpoints are
evenly spaced, the fan-out and the load balancer are only as tall as they
need to be, and the two side labels are centered over their sides of the
boundary.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
USGS counts requests per key, with an hourly ceiling of 1,000 for the OGC
API and 10,000 for the files. A bulk pull of more than about 1,000 files
under one key left the change query, which runs last, no OGC requests. The
service's maintainer recommends a separate key for the files.

files_api_key (API_USGS_FILES_PAT) is package-wide, like api_key. The
credentials leaf sends it in place of api_key on requests under
/stac-files/ and falls back to api_key when it is unset. Catalog searches
stay on api_key.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
The chunk plan's columns are now labeled as a location's historical and
current files, so the figure shows that a chunk is a file. The service's
maintainer says the files can be a week behind the API, not a day; the
path reads its cutoff from each file, so the result is unaffected, and the
ADR now says so. It also records files_api_key.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
The service's maintainer suggested one key for /stac and /stac-files and
another for /ogcapi. With catalog searches on api_key, a bulk call spent
two requests against the OGC API's ceiling of 1,000, a search and the
change query. Now the change query is the only request the files path
sends under api_key.

The cost is the catalog's ceiling: once the files' key has made 4,000
requests in an hour, the next query's search is refused before any
download.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…een files

The continuous collection refuses a time argument with an open start or a
span over 1,100 days. A query that long was routed to the files, downloaded
every one, and then failed, because the change query sent the same time.
The change query now sends no time when the API would refuse it: a change
clause needs none, the clause for locations without a file carries the
bounds, and the merge applies them. Live, 8 gages since 2000 returned 2.44
million rows in 12.8 s, equal to the API on the days compared.

A location's two files written on different nights leave the span between
them in neither, and no change clause returns it. Where current starts more
than 12 hours after historical ends, one more clause asks the API for that
span.

The cutoff is now the current file's instead of the later of the two, so a
current file older than its historical no longer hides the changes made
since its own snapshot.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
The extra installs only pyarrow, and pyarrow has other uses: with pandas 3
it also reduces a result's memory. An extra named for the package covers
both, so a second extra installing the same thing is never needed. The
bulk extra was new on this branch and never released, so no alias is kept.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
The rename in the previous commit changed the install command the warning
names, and this test still matched the old one.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
A page whose values are all null for a text column has an object
column, and concatenating the pages widens the other pages' strings to
object. On pandas 3 the same query could therefore return method_category
as str or object, depending on how the rows fell into pages; live, the
continuous files path and the API path disagreed on five sites.

_finalize_ogc now re-infers each object column. It works column by column
because DataFrame.infer_objects leaves object columns that share a block
as they are (pandas 3.1), which the first attempt missed on a real result.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… fixes

Change query (ADR 0014, measured cold on 2026-11-24 with never-queried
sites and a unique window per run):

- A daily change query sends no time window; the rows outside the window
  are dropped before the merge. With the window, the API took up to 9 s to
  answer a change query that returned few rows, and 2 to 6 s without it.
  The daily files path was faster in 5 of 7 query shapes, the same in 1,
  and 2 s slower in 1. A continuous change query keeps its window: without
  it the query took 11 to 14 s or timed out.
- The change query is split into up to 8 concurrent requests, then 10
  locations each, but no more requests than the concurrency cap. The API's
  time grows with the locations a request names: 100 gages took 12.1 s as
  one request and 1.2 s as ten. It asks the chunker for that fan-out with a
  per-call chunks= argument, so the library never enters the caller's
  configuration; a larger parallel_chunks setting still wins.

Routing: the daily base is 5,000 estimated rows (continuous keeps 10,000),
and a small file costs 100 rows. A location with many series is
underestimated severalfold: one such site over 5 years took 4.6 s from the
API and 1.8 s from the files.

Review fixes:

- The files path returns continuous geometry.
- The record id is left out of every answer under "auto" and "always"
  unless properties names it.
- 403 and 429 messages name the key the request was sent
  (credentials.key_variables), and a refused catalog or file request names
  bulk='off'.
- Without pyarrow, a get_continuous time over 1,100 days or with an open
  start raises ValueError before any request.
- md is the same on either path: md.url is the URL bulk='off' sends, and
  md.query_time sums every request.
- An interruption of the change query resumes through the downloads
  (FanOutInterrupted._bind), and the downloads are no longer kept alive
  after return by a reference cycle with their finalize hook.
- The merge gives an all-null text column the files' type before the
  concat, instead of widening and narrowing every row.
- The configuration guide's example profile is [waterdata.overnight], since
  a [waterdata.bulk] table cannot sit beside the bulk setting.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The figure's 50 locations now split into 8 change-query requests of up to
7 locations each (chunks 101 to 108), as the code sends them. ADR 0014's
step 4 names the clause per cutoff day and group of locations, and the
per-call chunk count the change query asks for.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
thodson-usgs and others added 5 commits November 24, 2026 11:12
The figure is drawn at 18 cm, so its type prints at the sizes set: 12 pt
for the two sides, 9 pt bold for each step and endpoint, 8 pt for labels,
7 pt for chunk numbers. A rule under each side's name spans that side, the
file dates move to a time axis under the chunk plan, and the note on T
moves to the bottom right.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The query passes monitoring_locations positionally with an n=50 comment,
the lane counts read 8x, 100x, and 1x, and the file columns are headed
historical and current. The saved width goes to the file columns. The
chunk plan's title sits on its headers, and the note on T moves to the
bottom left. The figure stays 18 cm wide.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The catalog request sits under the query on two lines, and its Parquet
URLs pass under the code into the chunk plan, so the plan starts after the
code. The arrow into the fan-out reads 108x, the plan's chunks. The width
this frees widens the plan's columns, and the note on T is one line at the
bottom left. The figure stays 18 cm wide; ADR 0014's alt text and caption
describe the new layout.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The plan's rows are monitoring locations and its columns follow time, so
both axes have a title, and the column widths follow the time axis: 360
days for the historical file, about 150 for the current file, and the few
days since T for the new records, drawn as wide as their label. The plan
shows locations 1 to 4, 49, and 50, which puts the catalog request lower
and gives the code room. The note on T moves onto the line of the Time
title, and the caption says the catalog request finishes before any chunk
starts.

The code asked for 7.5 pt, which the typewriter font has no size for, so
it was set at 7 pt. It now asks for 8 pt, the size it is set at.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…apart

The files route becomes a public package, waterdata.bulk, with get_daily
and get_continuous, which read every query from the Parquet files plus
the API's changes, and get_urls, which was waterdata.get_parquet_files.
A bulk getter's signature holds only the arguments the files can answer,
so any other argument is a TypeError at the call, and a test pins each
signature to the route's accepted arguments. Without pyarrow, a bulk
getter raises ImportError before any request.

The bulk setting's router moves to waterdata/_routing.py, with the row
estimate's terms in their own table, and calls the route through the same
parse and read the bulk getters use. waterdata.get_daily and
get_continuous call the router as before. The setting keeps "off" and
"auto" and drops "always", which the bulk getters replace.

A new import contract keeps waterdata.bulk from importing the router or
the API getters, so the package can be released without them. The STAC
search stays in waterdata/catalog.py, which get_ratings also uses.

The routing tests move to waterdata_routing_test.py; the files route
tests call the bulk getters. ADR 0014, the configuration guide, the
reference page, CONTEXT.md, and NEWS describe the two entry points. The
change query now asks the engine to convert types itself, since a bulk
getter's arguments carry no convert_type.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@ldecicco-USGS

Copy link
Copy Markdown
Collaborator

(For now) I'm leaving the R code as either STAC or OGC. We might consider an argument source = "OGC", "STAC", "auto" in the future, but I wanted to make sure the dedicated STAC functions are solid.

If you want to see the R proposed workflow, you can see the introduction vignette here:
https://ldecicco-usgs.github.io/dataRetrieval/articles/STAC_Introduction.html
and the pull request is here:
DOI-USGS/dataRetrieval#939

Looking at this PR I don't think we're that far apart in terms of user experience.

@thodson-usgs

Copy link
Copy Markdown
Collaborator Author

thanks @ldecicco-USGS. I'll take a look. I think I'm also leaning simpler to start, then revisit routing later.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

v2 Breaking or major change: defer to the 2.0 release

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants