@@ -47,6 +47,7 @@ and set it as an environment variable:
4747
4848``` python
4949import os
50+
5051os.environ[" API_USGS_PAT" ] = " your_api_key_here"
5152```
5253
@@ -59,9 +60,9 @@ from dataretrieval import waterdata
5960
6061# Get daily streamflow data (returns DataFrame and metadata)
6162df, metadata = waterdata.get_daily(
62- monitoring_location_id = ' USGS-01646500' ,
63- parameter_code = ' 00060' , # Discharge
64- time = ' 2024-10-01/2025-09-30'
63+ monitoring_location_id = " USGS-01646500" ,
64+ parameter_code = " 00060" , # Discharge
65+ time = " 2024-10-01/2025-09-30" ,
6566)
6667
6768print (f " Retrieved { len (df)} records " )
@@ -72,9 +73,9 @@ Retrieve streamflow at multiple locations from October 1, 2024 to the present:
7273
7374``` python
7475df, metadata = waterdata.get_daily(
75- monitoring_location_id = [" USGS-13018750" ," USGS-13013650" ],
76- parameter_code = ' 00060' ,
77- time = ' 2024-10-01/..'
76+ monitoring_location_id = [" USGS-13018750" , " USGS-13013650" ],
77+ parameter_code = " 00060" ,
78+ time = " 2024-10-01/.." ,
7879)
7980
8081print (f " Retrieved { len (df)} records " )
@@ -85,8 +86,8 @@ stream sites in Maryland:
8586``` python
8687# Get monitoring location information
8788df, metadata = waterdata.get_monitoring_locations(
88- state = ' Maryland' , # full name, postal code ('MD'), or FIPS ('24')
89- site_type_code = ' ST ' # Stream sites
89+ state = " Maryland" , # full name, postal code ('MD'), or FIPS ('24')
90+ site_type_code = " ST " , # Stream sites
9091)
9192
9293print (f " Found { len (df)} stream monitoring locations in Maryland " )
@@ -98,9 +99,9 @@ windows to avoid timeouts and other issues:
9899``` python
99100# Get continuous data for a single monitoring location and water year
100101df, metadata = waterdata.get_continuous(
101- monitoring_location_id = ' USGS-01646500' ,
102- parameter_code = ' 00065' , # Gage height
103- time = ' 2024-10-01/2025-09-30'
102+ monitoring_location_id = " USGS-01646500" ,
103+ parameter_code = " 00065" , # Gage height
104+ time = " 2024-10-01/2025-09-30" ,
104105)
105106print (f " Retrieved { len (df)} continuous gage height measurements " )
106107```
@@ -125,10 +126,10 @@ from dataretrieval import waterdata
125126# enough to span many pages, so it profits from a finer split.
126127sites, _ = waterdata.get_monitoring_locations(state = " Ohio" , site_type_code = " ST" )
127128
128- with waterdata.parallel_chunks(32 ): # fan out into 32 sub-requests
129+ with waterdata.parallel_chunks(32 ): # fan out into 32 sub-requests
129130 df, md = waterdata.get_daily(
130131 monitoring_location_id = sites[" monitoring_location_id" ],
131- parameter_code = " 00060" , # discharge
132+ parameter_code = " 00060" , # discharge
132133 time = " 2004-01-01/2023-12-31" ,
133134 )
134135```
@@ -167,6 +168,7 @@ API — enable debug-level
167168
168169``` python
169170import logging
171+
170172logging.basicConfig(level = logging.DEBUG )
171173```
172174
@@ -181,14 +183,14 @@ from dataretrieval import ngwmn
181183
182184# Find the groundwater monitoring sites in a state
183185# (state accepts a full name, a postal code like 'WI', or a FIPS code like '55')
184- sites, metadata = ngwmn.get_sites(state = ' Wisconsin' )
186+ sites, metadata = ngwmn.get_sites(state = " Wisconsin" )
185187
186188print (f " Found { len (sites)} NGWMN sites in Wisconsin " )
187189
188190# Pull water levels from the first twenty sites over a time window.
189191water_levels, metadata = ngwmn.get_water_level(
190- monitoring_location_id = sites[' monitoring_location_id' ][:20 ],
191- datetime = [' 2022-01-01' , ' 2024-01-01' ]
192+ monitoring_location_id = sites[" monitoring_location_id" ][:20 ],
193+ datetime = [" 2022-01-01" , " 2024-01-01" ],
192194)
193195
194196print (f " Retrieved { len (water_levels)} water-level observations " )
@@ -203,16 +205,15 @@ from dataretrieval import wqp
203205
204206# Find water quality monitoring sites (returns a DataFrame and metadata)
205207sites, metadata = wqp.what_sites(
206- statecode = ' US:55' , # Wisconsin
207- siteType = ' Stream'
208+ statecode = " US:55" , # Wisconsin
209+ siteType = " Stream" ,
208210)
209211
210212print (f " Found { len (sites)} stream monitoring sites in Wisconsin " )
211213
212214# Get water quality results
213215results, metadata = wqp.get_results(
214- siteid = ' USGS-05427718' ,
215- characteristicName = ' Temperature, water'
216+ siteid = " USGS-05427718" , characteristicName = " Temperature, water"
216217)
217218
218219print (f " Retrieved { len (results)} temperature measurements " )
@@ -227,18 +228,18 @@ from dataretrieval import nldi
227228
228229# Get watershed basin for a stream reach
229230basin = nldi.get_basin(
230- feature_source = ' comid' ,
231- feature_id = ' 13293474' # NHD reach identifier
231+ feature_source = " comid" ,
232+ feature_id = " 13293474" , # NHD reach identifier
232233)
233234
234235print (f " Basin contains { len (basin)} feature(s) " )
235236
236237# Find upstream flowlines
237238flowlines = nldi.get_flowlines(
238- feature_source = ' comid' ,
239- feature_id = ' 13293474' ,
240- navigation_mode = ' UT ' , # Upstream tributaries
241- distance = 50 # km
239+ feature_source = " comid" ,
240+ feature_id = " 13293474" ,
241+ navigation_mode = " UT " , # Upstream tributaries
242+ distance = 50 , # km
242243)
243244
244245print (f " Found { len (flowlines)} upstream tributaries within 50km " )
@@ -255,17 +256,17 @@ from dataretrieval import wateruse
255256# Monthly public-supply withdrawals for Rhode Island, split into
256257# groundwater and surface-water sources (returns a DataFrame and metadata).
257258df, metadata = wateruse.get_wateruse(
258- model = ' wu-public-supply-wd' ,
259- variable = [' pswdtot' , ' pswdgw' , ' pswdsw' ],
260- state = ' RI ' , # name/postal/FIPS; pass a list to fan out over several areas
261- start_date = ' 2020-01' ,
262- time_resolution = ' monthly' ,
259+ model = " wu-public-supply-wd" ,
260+ variable = [" pswdtot" , " pswdgw" , " pswdsw" ],
261+ state = " RI " , # name/postal/FIPS; pass a list to fan out over several areas
262+ start_date = " 2020-01" ,
263+ time_resolution = " monthly" ,
263264)
264265
265266print (f " Retrieved { len (df)} records across { df[' huc12_id' ].nunique()} watersheds " )
266267
267268# Aggregate the HUC12 grid to a statewide monthly total (million gallons/day)
268- statewide = df.groupby(' year_month' )[ ' pswdtot_mgd' ].sum()
269+ statewide = df.groupby(" year_month" )[ " pswdtot_mgd" ].sum()
269270print (statewide.head())
270271```
271272
0 commit comments