Skip to content

Add waterdata.get_peaks for the annual peak-streamflow OGC collection#267

Merged
thodson-usgs merged 1 commit intoDOI-USGS:mainfrom
thodson-usgs:add-peaks
May 7, 2026
Merged

Add waterdata.get_peaks for the annual peak-streamflow OGC collection#267
thodson-usgs merged 1 commit intoDOI-USGS:mainfrom
thodson-usgs:add-peaks

Conversation

@thodson-usgs
Copy link
Copy Markdown
Collaborator

Adds a thin wrapper around the new /ogcapi/v0/collections/peaks collection. Returns the annual peak record for a monitoring location — one row per (location, parameter, water year) — which is the standard input to flood-frequency analysis (log-Pearson Type III, etc.).

The collection covers stage (parameter 00065) and discharge (00060); typical streamgages have a series for each.

Implementation

A thin parameter declaration plus a single call to the existing service-agnostic get_ogc_data(args, output_id, service):

  • service = "peaks"
  • output_id = "peak_id" — the API's id field is renamed for users, matching the project's other get_* functions.

R has no equivalent yet; the docstring was written from scratch following the project's existing get_* style.

Live API examples (verified)

from dataretrieval.waterdata import get_peaks

# Full annual record (both stage and discharge)
df, md = get_peaks(monitoring_location_id="USGS-02238500")
# 135 rows, parameter codes ['00060', '00065']

# Discharge peaks only
df, md = get_peaks(monitoring_location_id="USGS-02238500", parameter_code="00060")

# Multi-site over a water-year window
df, md = get_peaks(
    monitoring_location_id=["USGS-07069000", "USGS-07064000", "USGS-07068000"],
    parameter_code="00060",
    water_year=[2020, 2021, 2022, 2023],
)

Test plan

  • test_get_peaks — single-site happy path; asserts peak_id, value, water_year columns and a clean parameter-code subset.
  • test_get_peaks_water_year_filter — exercises the water_year filter.
  • Live verification: monitoring_location_id="USGS-02238500" returns 135 rows, parameter codes {"00060", "00065"}.

Related

Part of the v1.1.4 release-staging series; will be linked from a tracking issue.

@thodson-usgs
Copy link
Copy Markdown
Collaborator Author

Tracked in the v1.1.4 release-staging issue: #270.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated no new comments.

@thodson-usgs thodson-usgs requested a review from ldecicco-USGS May 6, 2026 17:30
Copy link
Copy Markdown
Collaborator

@ldecicco-USGS ldecicco-USGS left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you have deprecation messages in all the NWIS modules? I think with peaks and ratings, all NWIS functions should now have a waterdata replacement.

@thodson-usgs
Copy link
Copy Markdown
Collaborator Author

thodson-usgs commented May 6, 2026

Here's Claude's survey:

nwis function status waterdata replacement
get_qwdata defunct (raises) waterdata.get_samples
get_discharge_measurements defunct (raises) waterdata.get_field_measurements
get_gwlevels defunct (raises) waterdata.get_field_measurements
get_pmcodes defunct (raises) waterdata.get_reference_table("parameter-codes")
get_water_use defunct (raises) (no equivalent; service retired upstream)
get_discharge_peaks active, no warning waterdata.get_peaks (this PR, #267)
get_ratings active, no warning waterdata.get_ratings (#269)
get_stats active, no warning waterdata.get_stats_por / get_stats_date_range
get_dv active, no warning waterdata.get_daily
get_iv active, no warning waterdata.get_continuous
get_info active, no warning waterdata.get_monitoring_locations
what_sites active, no warning waterdata.get_monitoring_locations
query_waterdata active, no warning low-level; superseded by direct waterdata.get_* calls
query_waterservices active, no warning low-level; superseded by direct waterdata.get_* calls
get_record active, no warning dispatcher; replace with the appropriate waterdata.get_*

So once #267 (peaks) and #269 (ratings) merge, every NWIS function has a waterdata replacement (except get_water_use, whose upstream service was retired) and the 9 still-active ones are eligible for DeprecationWarning.

I'll follow up with the warnings in a separate PR

Wraps the new /ogcapi/v0/collections/peaks collection. Returns the
annual peak record for a monitoring location — one row per (location,
parameter, water year) — which is the standard input to flood-
frequency analysis (log-Pearson Type III etc).

The collection covers stage (parameter 00065) and discharge (00060);
typical streamgages have a series for each.

Implementation reuses the existing get_ogc_data infrastructure:
- service = "peaks"
- output_id = "peak_id" (the API's `id` field is renamed for users,
  matching the project's other get_* functions)

R has no equivalent yet; the docstring was written from scratch
following the project's existing get_* style.

Two live tests cover the happy path (single-site, both parameters
present) and a water-year filter.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
thodson-usgs added a commit to thodson-usgs/dataretrieval-python that referenced this pull request May 7, 2026
…oval

The module-level "use waterdata instead" warning has been firing on
import for a while; this PR makes the migration guidance actionable
by emitting a per-function DeprecationWarning that names the specific
waterdata replacement the user should switch to.

Once peaks (DOI-USGS#267) and ratings (DOI-USGS#269) land, every active nwis function
has a waterdata replacement, so all nine of them are deprecated here:

  nwis.get_dv               -> waterdata.get_daily()
  nwis.get_iv               -> waterdata.get_continuous()
  nwis.get_info             -> waterdata.get_monitoring_locations()
  nwis.what_sites           -> waterdata.get_monitoring_locations()
  nwis.get_stats            -> waterdata.get_stats_por() /
                              waterdata.get_stats_date_range()
  nwis.get_discharge_peaks  -> waterdata.get_peaks()
  nwis.get_ratings          -> waterdata.get_ratings()
  nwis.get_record           -> the appropriate waterdata.get_*()
  nwis.query_waterdata      -> a high-level waterdata.get_*() helper
  nwis.query_waterservices  -> a high-level waterdata.get_*() helper

(get_qwdata, get_discharge_measurements, get_gwlevels, get_pmcodes,
and get_water_use are already defunct and raise NameError.)

Implementation follows the nadp deprecation template (DOI-USGS#243): a small
_REPLACEMENTS dict + a _warn_deprecated(func_name) helper called as
the first line of each public function. stacklevel=3 makes the
warning point at the caller's code, not the helper's frame.

11 new parametrized tests pin the warning text — that the function
name appears, the replacement helper appears, and the removal date
appears — plus one end-to-end test that get_iv() actually fires
its warning when called.

Removal date is set to 2027-05-06, one full year out (vs. the six
months used for nadp), since nwis is much more widely used and most
users will need migration time. Maintainer can adjust if desired.

This depends on DOI-USGS#267 (waterdata.get_peaks) and DOI-USGS#269 (waterdata.get_ratings)
being merged: until then the deprecation messages for get_discharge_peaks
and get_ratings point at functions users can't yet call. Hold this PR
draft until those land.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
thodson-usgs added a commit to thodson-usgs/dataretrieval-python that referenced this pull request May 7, 2026
Addresses Copilot review on DOI-USGS#271: `_REPLACEMENTS` points
`get_discharge_peaks` -> `waterdata.get_peaks()` and `get_ratings` ->
`waterdata.get_ratings()`. If this PR merged before its dependencies
landed, users following the migration guidance would hit AttributeError.

Adds a parametrized test that imports `dataretrieval.waterdata` and
asserts every concrete callable named in the deprecation messages exists.
The test currently fails on `get_peaks` (still on PR DOI-USGS#267, not yet on
main) — exactly the desired behavior: this PR cannot merge before DOI-USGS#267.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
@thodson-usgs thodson-usgs marked this pull request as ready for review May 7, 2026 00:23
@thodson-usgs thodson-usgs merged commit fca3d6c into DOI-USGS:main May 7, 2026
8 checks passed
thodson-usgs added a commit to thodson-usgs/dataretrieval-python that referenced this pull request May 7, 2026
…oval

The module-level "use waterdata instead" warning has been firing on
import for a while; this PR makes the migration guidance actionable
by emitting a per-function DeprecationWarning that names the specific
waterdata replacement the user should switch to.

Once peaks (DOI-USGS#267) and ratings (DOI-USGS#269) land, every active nwis function
has a waterdata replacement, so all nine of them are deprecated here:

  nwis.get_dv               -> waterdata.get_daily()
  nwis.get_iv               -> waterdata.get_continuous()
  nwis.get_info             -> waterdata.get_monitoring_locations()
  nwis.what_sites           -> waterdata.get_monitoring_locations()
  nwis.get_stats            -> waterdata.get_stats_por() /
                              waterdata.get_stats_date_range()
  nwis.get_discharge_peaks  -> waterdata.get_peaks()
  nwis.get_ratings          -> waterdata.get_ratings()
  nwis.get_record           -> the appropriate waterdata.get_*()
  nwis.query_waterdata      -> a high-level waterdata.get_*() helper
  nwis.query_waterservices  -> a high-level waterdata.get_*() helper

(get_qwdata, get_discharge_measurements, get_gwlevels, get_pmcodes,
and get_water_use are already defunct and raise NameError.)

Implementation follows the nadp deprecation template (DOI-USGS#243): a small
_REPLACEMENTS dict + a _warn_deprecated(func_name) helper called as
the first line of each public function. stacklevel=3 makes the
warning point at the caller's code, not the helper's frame.

11 new parametrized tests pin the warning text — that the function
name appears, the replacement helper appears, and the removal date
appears — plus one end-to-end test that get_iv() actually fires
its warning when called.

Removal date is set to 2027-05-06, one full year out (vs. the six
months used for nadp), since nwis is much more widely used and most
users will need migration time. Maintainer can adjust if desired.

This depends on DOI-USGS#267 (waterdata.get_peaks) and DOI-USGS#269 (waterdata.get_ratings)
being merged: until then the deprecation messages for get_discharge_peaks
and get_ratings point at functions users can't yet call. Hold this PR
draft until those land.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
thodson-usgs added a commit to thodson-usgs/dataretrieval-python that referenced this pull request May 7, 2026
Addresses Copilot review on DOI-USGS#271: `_REPLACEMENTS` points
`get_discharge_peaks` -> `waterdata.get_peaks()` and `get_ratings` ->
`waterdata.get_ratings()`. If this PR merged before its dependencies
landed, users following the migration guidance would hit AttributeError.

Adds a parametrized test that imports `dataretrieval.waterdata` and
asserts every concrete callable named in the deprecation messages exists.
The test currently fails on `get_peaks` (still on PR DOI-USGS#267, not yet on
main) — exactly the desired behavior: this PR cannot merge before DOI-USGS#267.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants