You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
feat(wateruse): add water-use module for the USGS NWDC API
Add `dataretrieval.wateruse` for USGS National Water Availability Assessment
Data Companion (NWDC) water-use estimates — modeled on a HUC12 grid and
queryable by state, county, or hydrologic unit. This is the modern replacement
for the defunct legacy NWIS water-use service (`nwis.get_water_use` now points
callers here).
from dataretrieval import wateruse
df, md = wateruse.get_wateruse(
model="wu-public-supply-wd",
variable=["pswdtot", "pswdgw", "pswdsw"],
state="RI",
start_date="2020-01",
time_resolution="monthly",
)
The NWDC is a plain CSV REST service, not an OGC API Features collection, so the
module supplies the NWDC-specific pieces (CSV parsing, the RFC 8288 Link-header
pagination cursor, the `{detail}` error envelope, and state/county/huc location
builders) but reuses the OGC engine's generic transport rather than
re-implementing it: the shared pager (`_paginate`), the Jupyter-safe anyio sync
bridge (`_run_sync`), response/frame aggregation, and `_default_headers`. It
keeps the package conventions where they fit — a `(DataFrame, BaseMetadata)`
return, the typed `DataRetrievalError` taxonomy (surfacing the NWDC `detail`),
`API_USGS_PAT` token support, idiomatic snake_case params, and `state` /
`county` / `huc` selectors that each accept a value or a list (a list fans out
one concurrent request per location). Large areas paginate transparently.
A `FutureWarning` flags the module as experimental, since the NWDC service is
new and still changing.
Extracting the reusable engine seams also de-duplicated the engine itself
(~-66 LOC, behavior-preserving): `planning._merge_response` now backs both
pagination and fan-out aggregation; a generic `utils.Ambient[T]`
contextvar-with-scope helper collapses the per-call ambients; and
`x-ratelimit-remaining` now reports the lowest value any concurrent sub-request
saw (the quota actually left after a fan-out), fixing a latent inaccuracy in the
OGC chunker too.
Includes offline pytest-httpx coverage, a reference page, a README example, and
a demo notebook.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Sjb14HkwuCydKSKMsaXsgd
Copy file name to clipboardExpand all lines: AGENTS.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -6,7 +6,7 @@
6
6
- Exclude `.claude/worktrees/` from searches and edits; it contains stale worktrees that pollute results.
7
7
8
8
## Example Notebooks
9
-
-`demos/*.ipynb` — top-level Water Data tour: `USGS_WaterData_Introduction_Examples.ipynb` is the entry point; `_ContinuousData_`, `_DailyStatistics_`, `_DiscreteSamples_`, `_ReferenceLists_` cover individual collections; `WaterData_demo.ipynb`, `peak_streamflow_trends.ipynb`, and `R Python Vignette equivalents.ipynb` are standalone walkthroughs.
9
+
-`demos/*.ipynb` — top-level Water Data tour: `USGS_WaterData_Introduction_Examples.ipynb` is the entry point; `_ContinuousData_`, `_DailyStatistics_`, `_DiscreteSamples_`, `_ReferenceLists_` cover individual collections; `WaterData_demo.ipynb`, `peak_streamflow_trends.ipynb`, `USGS_WaterUse_Examples.ipynb` (NWDC water-use data via `wateruse.get_wateruse`), and `R Python Vignette equivalents.ipynb` are standalone walkthroughs.
10
10
-`demos/hydroshare/*.ipynb` — per-service HydroShare examples (NLDI, NWIS WaterUse, and Water Data DailyValues / GroundwaterLevels / Measurements / ParameterCodes / Peaks / Ratings / Samples / SiteInfo / SiteInventory / Statistics / UnitValues). Mirror these when adding examples for a new collection.
11
11
-`demos/nwqn_data_pull/` — non-notebook example: a lithops/Docker batch pipeline (`retrieve_nwqn_samples.py`, `retrieve_nwqn_streamflow.py`) with its own `README.md`.
12
12
- Any `Untitled*.ipynb`, `*_test.ipynb`, or notebooks not listed here are untracked local scratch; ignore them.
0 commit comments