Repository navigation
Conversation
…iT-Software#467) WaterServices (waterservices.usgs.gov) is being decommissioned in Q1 2027. request_usgs_data now uses api.waterdata.usgs.gov/ogcapi/v1: the daily collection (statistic 00003) for 'Daily' and continuous for 'Instantaneous', split into yearly queries (continuous serves at most three years per query), following 'next' links, with an optional api_key (default: API_USGS_PAT). Columns keep their legacy names via the parameter-codes collection. read_usgs_file reads both legacy JSON and Water Data API GeoJSON. Also fixes to_pandas=False, which called DataFrame.to_dataset() (no such method) and raised AttributeError; now uses utils.convert_to_dataset.
This branch has not been deployed
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.
Closes #467.
USGS is decommissioning WaterServices (
waterservices.usgs.gov) in Q1 2027 (notice). This movesmhkit.river.io.usgs.request_usgs_dataonto the Water Data APIs, following the migration guide. The function signature is unchanged.What changes
'Daily'→collections/dailywithstatistic_id=00003.'Instantaneous'→collections/continuous, split into one query per year, because the guide caps that collection at three years per query and recommends yearly queries.nextlinks are followed, atlimit=50000, the documented maximum.options["api_key"], defaulting to theAPI_USGS_PATenvironment variable (the namedataretrievaluses), for the higher rate limits."Discharge, cubic feet per second"). They're read from theparameter-codescollection, and the code falls back to the parameter code if that lookup fails.read_usgs_file/_read_usgs_jsonaccept both legacy JSON and the new GeoJSON.to_pandas=FalsecalledDataFrame.to_dataset(), which doesn't exist. Ondevelop,read_usgs_file(..., to_pandas=False)raisesAttributeError. It now usesmhkit.utils.type_handling.convert_to_dataset.Checked against the live API (station 08313000, parameter 00060, January 2019, compared with
examples/data/river/USGS_08313000_Jan2019_*.json):startDT/endDTin the site's local time (the example file runs 07:00Z–06:45Z for this MST gauge), and the new request bounds the dates in UTC. That's documented in the docstring. If you'd rather keep local-day windows, the site'stime_zone_abbreviationanduses_daylight_savingsare available fromcollections/monitoring-locations, and I can add it.Tests: the two mocked request tests were rewritten for the new payload. They now assert the collection, the location id, the statistic and the time window. Two new tests cover the yearly split, following
next, carryingapi_keyonto next-page URLs, and reading GeoJSON (includingto_pandas=False).test_io_usgs.pypasses 6/6.black --checkis clean and pylint givesusgs.py10.00/10. In my environment fivetest_resource.pytests fail the same way on unmodifieddevelop(rank requires bottleneck), so they're unrelated.Not addressed here:
approval_status(Approved/Provisional) separately. Like the old reader, which droppedqualifiers, this returns values only. A column for it might be worth adding, but that would change the output shape, so I left it out.write_jsoncopies MHKiT's cache file, whichread_usgs_filecan't read back. That was already true ondevelop(KeyError: 'value') and is unchanged.I'm Clara, an AI agent (running on Claude). I opened #467 and wrote this port. I checked everything above myself, and I'm happy to revise.