Skip to content

Commit 6dde97f

Browse files
committed
edit readme, add tests
1 parent 933c56b commit 6dde97f

2 files changed

Lines changed: 38 additions & 10 deletions

File tree

README.md

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
## Latest Announcements
88

9-
:mega: **11/24/2025:** `dataretrieval` now features the new `waterdata` module,
9+
:mega: **12/03/2025:** `dataretrieval` now features the new `waterdata` module,
1010
which provides access to USGS's modernized [Water Data
1111
APIs](https://api.waterdata.usgs.gov/). The Water Data API endpoints include
1212
daily values, instantaneous values, field measurements, time series metadata,
@@ -69,27 +69,27 @@ input argument indicates a desired date range:
6969
from dataretrieval import waterdata
7070

7171
# Get daily streamflow data (returns DataFrame and metadata)
72-
df, metadata = waterdata.get_daily(
72+
daily, metadata = waterdata.get_daily(
7373
monitoring_location_id='USGS-01646500',
7474
parameter_code='00060', # Discharge
7575
time='2024-10-01/2025-09-30'
7676
)
7777

78-
print(f"Retrieved {len(df)} records")
79-
print(f"Site: {df['monitoring_location_id'].iloc[0]}")
80-
print(f"Mean discharge: {df['value'].mean():.2f} {df['unit_of_measure'].iloc[0]}")
78+
print(f"Retrieved {len(daily)} records")
79+
print(f"Site: {daily['monitoring_location_id'].iloc[0]}")
80+
print(f"Mean discharge: {daily['value'].mean():.2f} {daily['unit_of_measure'].iloc[0]}")
8181
```
8282
Fetch daily discharge data for multiple sites from a start date to present
8383
using the following code:
8484

8585
```python
86-
df, metadata = waterdata.get_daily(
86+
daily_twosites, metadata = waterdata.get_daily(
8787
monitoring_location_id=["USGS-13018750","USGS-13013650"],
8888
parameter_code='00060',
8989
time='2024-10-01/..'
9090
)
9191

92-
print(f"Retrieved {len(df)} records")
92+
print(f"Retrieved {len(daily_twosites)} records")
9393
```
9494
The following example downloads location information for all monitoring
9595
locations that are categorized as stream sites in the state of Maryland:
@@ -103,6 +103,21 @@ locations, metadata = waterdata.get_monitoring_locations(
103103

104104
print(f"Found {len(locations)} stream monitoring locations in Maryland")
105105
```
106+
Finally, this example downloads continuous (a.k.a. "instantaneous") data
107+
for one monitoring location over one year. You are *strongly advised* to
108+
break up continuous data requests into smaller time periods and smaller
109+
collections of sites to avoid timeouts and other issues:
110+
111+
```python
112+
# Get continuous data for a single monitoring location and water year
113+
continuous, metadata = waterdata.get_continuous(
114+
monitoring_location_id='USGS-01646500',
115+
parameter_code='00065', # Gage height
116+
time='2024-10-01/2025-09-30'
117+
)
118+
print(f"Retrieved {len(continuous)} continuous gage height measurements")
119+
```
120+
106121
Visit the
107122
[API Reference](https://doi-usgs.github.io/dataretrieval-python/reference/waterdata.html)
108123
for more information and examples on available services and input parameters.
@@ -202,13 +217,13 @@ print(f"Found {len(flowlines)} upstream tributaries within 50km")
202217

203218
### Modern USGS Water Data APIs (Recommended)
204219
- **Daily values**: Daily statistical summaries (mean, min, max)
220+
- **Instantaneous values**: High-frequency continuous data
205221
- **Field measurements**: Discrete measurements from field visits
206222
- **Monitoring locations**: Site information and metadata
207223
- **Time series metadata**: Information about available data parameters
208224
- **Latest daily values**: Most recent daily statistical summary data
209225
- **Latest instantaneous values**: Most recent high-frequency continuous data
210226
- **Samples data**: Discrete USGS water quality data
211-
- **Instantaneous values** (*COMING SOON*): High-frequency continuous data
212227

213228
### Legacy NWIS Services (Deprecated)
214229
- **Daily values (dv)**: Legacy daily statistical data

tests/waterdata_test.py

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
_check_profiles,
1111
get_samples,
1212
get_daily,
13+
get_continuous,
1314
get_monitoring_locations,
1415
get_latest_continuous,
1516
get_latest_daily,
@@ -142,7 +143,7 @@ def test_get_daily_properties():
142143
assert df.parameter_code.unique().tolist() == ["00060"]
143144

144145
def test_get_daily_no_geometry():
145-
df, md = get_daily(
146+
df,_ = get_daily(
146147
monitoring_location_id="USGS-05427718",
147148
parameter_code="00060",
148149
time="2025-01-01/..",
@@ -152,6 +153,18 @@ def test_get_daily_no_geometry():
152153
assert df.shape[1] == 11
153154
assert isinstance(df, DataFrame)
154155

156+
def test_get_continuous():
157+
df,_ = get_continuous(
158+
monitoring_location_id="USGS-06904500",
159+
parameter_code="00065",
160+
time="2025-01-01/2025-12-31"
161+
)
162+
assert isinstance(df, DataFrame)
163+
assert "geometry" not in df.columns
164+
assert df.shape[1] == 11
165+
assert df['time'].dtype == 'datetime64[ns, UTC]'
166+
assert "continuous_id" in df.columns
167+
155168
def test_get_monitoring_locations():
156169
df, md = get_monitoring_locations(
157170
state_name="Connecticut",
@@ -162,7 +175,7 @@ def test_get_monitoring_locations():
162175
assert hasattr(md, 'query_time')
163176

164177
def test_get_monitoring_locations_hucs():
165-
df, md = get_monitoring_locations(
178+
df,_ = get_monitoring_locations(
166179
hydrologic_unit_code=["010802050102", "010802050103"]
167180
)
168181
assert set(df.hydrologic_unit_code.unique().tolist()) == {"010802050102", "010802050103"}

0 commit comments

Comments
 (0)