dataretrieval.nwdc
The National Water Availability Assessment Data Companion. Water use is one of
the datasets it serves; the module was named wateruse until that became
misleading, and the old name remains as a deprecated alias.
Retrieve USGS water-use data from the NWDC web service.
The National Water Availability Assessment Data Companion (NWDC) web services
provide national-scale, USGS-modeled water-use data that underlie the USGS
National Water Availability Assessment.
Estimates are served on a HUC12 (12-digit hydrologic unit) spatial grid and can
be queried for any county, state, or hydrologic unit. This is the modern
replacement for the defunct legacy NWIS water-use service
(nwis.get_water_use).
Unlike the main Water Data getters (dataretrieval.waterdata) and NGWMN
(dataretrieval.ngwmn), the NWDC is a plain CSV REST service rather than
an OGC API Features collection. This module supplies the NWDC-specific bits —
request building, CSV parsing, the Link-header cursor, and the {detail}
error envelope. The service-neutral transport layer supplies cursor pagination,
response aggregation, client lifecycle, and sync-from-async dispatch. The module
follows the same conventions: host-scoped request headers, the typed
DataRetrievalError taxonomy, and a
(DataFrame, BaseMetadata) return.
See https://api.water.usgs.gov/docs/nwaa-data/ for the API reference and https://water.usgs.gov/nwaa-data/ for the catalog of available models and variables.
Examples
from dataretrieval import nwdc
# Monthly public-supply withdrawals for Rhode Island, 2020 onward.
df, md = nwdc.get_wateruse(
model="wu-public-supply-wd",
variable=["pswdtot", "pswdgw", "pswdsw"],
state="RI",
start_date="2020-01",
time_resolution="monthly",
)
- dataretrieval.nwdc.DEFAULT_CONCURRENT_REQUESTS = 4
This service’s preferred in-flight cap when nothing is configured. Lower than the package default of 32 because every location retries independently, so a rate-limit episode bursts this number times the retry count; the NWDC tolerates this level without rate-limit errors (verified by stress test) and higher has not been tested. Any configured concurrency overrides it – see
dataretrieval.configuration.concurrency()for why the general setting outranks a module’s default rather than the reverse.
- dataretrieval.nwdc.MODELS = ('wu-public-supply-wd', 'wu-public-supply-cu', 'wu-thermoelectric', 'wu-irrigation-wd', 'wu-irrigation-cu')
Water-use models (categories) served by the NWDC. The catalog at https://water.usgs.gov/nwaa-data/ lists the variables available within each.
- class dataretrieval.nwdc.NwdcConfiguration(retries: int | None = <not set>, stall_timeout: float | int | None = <not set>, base_url: str | None = <not set>, concurrency: int | str | None = <not set>)[source]
Settings for NWDC calls alone.
No
parallel_chunks: the NWDC is a plain CSV service, so a query fans out per location rather than being divided along a URL byte budget. There is nothing for the planner to divide more finely.Lives here rather than in
dataretrieval.configurationbecause which settings a service reads is the service’s own knowledge (ADR 0011); what each of them means is shared, so the fields come from the setting groups declared beside their grammar.- Parameters:
retries (int, optional) – Retries attempted after a transient failure;
0disables retrying.stall_timeout (float, optional) – Seconds a call may go without receiving any data before retrying stops.
base_url (str, optional) – Endpoint to send NWDC requests to, instead of the service’s own (
WATERUSE_URL). Arel="next"cursor is then followed only back to that host, since the service’s own host aliases mean nothing there. Code only: the file and the environment refuse it.concurrency (int or str, optional) – Cap on simultaneous sub-requests, or
"unbounded".
- adapter: ClassVar[str] = 'nwdc'
The adapter this configuration targets, by the name of the module a caller imports.
Noneon the package-wideConfiguration, which every adapter reads. AClassVar, not a field: the adapter is a property of the class, which is what stops the caller restating it at every call site and stops the roster being spelled twice.
- dataretrieval.nwdc.TIME_RESOLUTIONS = ('monthly', 'annualcy', 'annualwy')
monthly, annual calendar year, annual water year.
- Type:
Temporal resolutions
- dataretrieval.nwdc.get_wateruse(model: str, variable: str | Iterable[str] | None = None, state: str | int | Iterable[str | int] | None = None, county: str | Iterable[str] | None = None, huc: str | Iterable[str] | None = None, time_resolution: str | None = None, start_date: str | None = None, end_date: str | None = None, intersection: str = 'overlap', limit: int = 600, ssl_check: bool = True) tuple[DataFrame, BaseMetadata][source]
Get USGS water-use data from the NWDC web service.
Retrieves modeled water-use estimates from the USGS National Water Availability Assessment Data Companion. The area is given as exactly one of
state,county, orhuc; results are always returned on a HUC12 grid, in a long (tidy) frame with one row per HUC12 and time step. Large areas (e.g. a whole region or a populous state) are served across multiple pages; this function follows those pages transparently and concatenates them into one frame.Each selector also accepts a list of values. The NWDC queries one area per request, so a list is fanned out into one request per value — up to the effective
concurrencysetting in parallel, defaulting toDEFAULT_CONCURRENT_REQUESTSfor this service — and the results are concatenated in the order given. That cap resolves through the configuration chain, so it can be raised or lowered for this service alone (configure(NwdcConfiguration(concurrency=2)), or an[nwdc]table in the config file) as well as package-wide viaAPI_USGS_CONCURRENT; see the configuration guide. A fan-out interrupted by a rate limit or an upstream fault raises a resumableFanOutInterrupted, whose.call.resume()re-issues only the locations that did not complete.- Parameters:
model (string) – Water-use category to query. See
MODELSfor the available options (e.g."wu-public-supply-wd"). The full catalog of models and their variables is at https://water.usgs.gov/nwaa-data/.variable (string or iterable of strings, optional) – One or more variable IDs within
model(e.g."pswdtot"for total public-supply withdrawals, or["pswdgw", "pswdsw"]for the groundwater and surface-water components). Multiple variables are comma-joined into a single request. The service requires at least one variable; omitting it returns a 400 listing the model’s valid variable IDs (surfaced as aDataRetrievalError).state (string, int, or iterable, optional) – One or more US states/territories to query. Each accepts a full name (
"Wisconsin"), a two-letter postal code ("WI"), or a two-digit ANSI/FIPS code ("55"or55), mirroringdataretrieval.ngwmn.get_sites().county (string or iterable, optional) – One or more five-digit county FIPS codes — state FIPS + county FIPS, e.g.
"55025"for Dane County, Wisconsin.huc (string or iterable, optional) –
One or more hydrologic unit codes. Each code’s level is taken from its length: a 2-digit code queries a HUC2 region, 8-digit a HUC8 subbasin, 12-digit a single HUC12, and so on (even lengths 2-12, e.g.
"04","07070005","010900020502").Provide exactly one of
state,county, orhuc(each may be a single value or a list).time_resolution (string, optional) – Temporal resolution:
"monthly","annualcy"(annual, calendar year), or"annualwy"(annual, water year). SeeTIME_RESOLUTIONS.start_date (string, optional) – Start of the query window, formatted
"YYYY"for annual data or"YYYY-MM"for monthly data.end_date (string, optional) – End of the query window, in the same format as
start_date.intersection (string, optional) – How to select HUC12s that straddle the queried-area boundary:
"overlap"(any overlap, the default) or"envelop"(fully enclosed).limit (int, optional) – Maximum number of HUC12s returned per page. Queries spanning more than
limitHUC12s are split across pages and reassembled. Default 600.ssl_check (bool, optional) – If True (default), verify SSL certificates; set False to skip verification (e.g. behind a TLS-intercepting proxy).
- Returns:
df (
pandas.DataFrame) – Water-use estimates in long form: ahuc12_idcolumn (string, leading zeros preserved), a time column (year_monthfor monthly data oryearfor annual data), and one value column per requested variable (suffixed with its unit, e.g.pswdtot_mgdfor million gallons per day).md (
dataretrieval.utils.BaseMetadata) – Metadata describing the request (URL, query time, response headers).
- Raises:
ValueError – If not exactly one of
state,county, orhucis given, or a given selector is malformed (an unrecognized state, a county code that is not five digits, or a HUC of invalid length).DataRetrievalError – On an HTTP error response, the typed subclass for the status (see
dataretrieval.exceptions.error_for_status()). A transient 429, 5xx, or recoverable connection failure that exhausts inline retries is raised as a resumableFanOutInterrupted; a deterministic connection failure (for example, a permanently unresolvable host) remains aNetworkError.
Examples
>>> from dataretrieval import nwdc >>> df, md = nwdc.get_wateruse( ... model="wu-public-supply-wd", ... variable=["pswdtot", "pswdgw", "pswdsw"], ... state="RI", ... start_date="2020-01", ... time_resolution="monthly", ... )