Skip to content

Commit f7021e6

Browse files
thodson-usgsclaude
andcommitted
docs(examples): align notebook narratives with the Water Data API
The half-migrated Hydroshare notebooks had code on waterdata.* but markdown still describing the old nwis API. Complete the narrative migration: - remove the stray, unused "from dataretrieval import nwis" imports - fix "...from NWIS" wording in print statements and prose -> the Water Data API - rewrite titles, Basic-Usage function names + argument lists (waterdata args such as monitoring_location_id, parameter_code, time, statistic_id, skip_geometry instead of sites/parameterCd/statCd/start/end), and Interpreting/behavior sections (waterdata returns a flat DataFrame with a time column, not a date-indexed frame) to match the actual waterdata functions (get_daily, get_continuous, get_field_measurements, get_monitoring_locations, get_reference_table). Markdown-only changes; code cells unchanged; notebooks remain output-free. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 66d3f95 commit f7021e6

8 files changed

Lines changed: 113 additions & 196 deletions

demos/hydroshare/USGS_WaterData_DailyValues_Examples.ipynb

Lines changed: 18 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44
"cell_type": "markdown",
55
"metadata": {},
66
"source": [
7-
"# USGS dataretrieval Python Package `get_dv()` Examples\n",
7+
"# USGS dataretrieval Python Package `get_daily()` Examples\n",
88
"\n",
9-
"This notebook provides examples of using the Python dataretrieval package to retrieve daily streamflow data for a United States Geological Survey (USGS) monitoring site. The dataretrieval package provides a collection of functions to get data from the USGS National Water Information System (NWIS) and other online sources of hydrology and water quality data, including the United States Environmental Protection Agency (USEPA)."
9+
"This notebook provides examples of using the Python dataretrieval package to retrieve daily streamflow data for a United States Geological Survey (USGS) monitoring location. The dataretrieval package provides a collection of functions to get data from the USGS Water Data API and other online sources of hydrology and water quality data."
1010
]
1111
},
1212
{
@@ -39,35 +39,30 @@
3939
"execution_count": null,
4040
"metadata": {},
4141
"outputs": [],
42-
"source": [
43-
"from IPython.display import display\n",
44-
"\n",
45-
"from dataretrieval import nwis\n",
46-
"import dataretrieval.waterdata as waterdata"
47-
]
42+
"source": "from IPython.display import display\n\nimport dataretrieval.waterdata as waterdata"
4843
},
4944
{
5045
"cell_type": "markdown",
5146
"metadata": {},
5247
"source": [
5348
"### Basic Usage\n",
5449
"\n",
55-
"The dataretrieval package has several functions that allow you to retrieve data from different web services. This examples uses the `get_dv()` function to retrieve daily streamflow data for a USGS monitoring site from NWIS. The following arguments are supported:\n",
50+
"The dataretrieval package has several functions that allow you to retrieve data from different web services. This example uses the `get_daily()` function to retrieve daily streamflow data for a USGS monitoring location from the USGS Water Data API. The following arguments are supported:\n",
5651
"\n",
5752
"Arguments (Additional arguments, if supplied, will be used as query parameters)\n",
5853
"\n",
59-
"* **sites** (string or list of strings): A list of USGS site identifiers for which to retrieve data.\n",
60-
"* **parameterCd** (list of strings): A list of USGS parameter codes for which to retrieve data.\n",
61-
"* **statCd** (list of strings): A list of USGS statistic codes for which to retrieve data.\n",
62-
"* **start** (string): The beginning date for a period for which to retrieve data. If the waterdata parameter startDT is supplied, it will overwrite the start parameter.\n",
63-
"* **end** (string): The ending date for a period for which to retrieve data. If the waterdata parameter endDT is supplied, it will overwrite the end parameter."
54+
"* **monitoring_location_id** (string or iterable of strings): A unique identifier representing a single monitoring location, formed by combining the agency code with the site number (e.g. `USGS-10109000`). Accepts a single ID or a list of IDs.\n",
55+
"* **parameter_code** (string or iterable of strings): One or more 5-digit USGS parameter codes identifying the constituent measured and its units of measure (e.g. `00060` for discharge).\n",
56+
"* **statistic_id** (string or iterable of strings): One or more codes corresponding to the statistic an observation represents (e.g. `00001` for maximum, `00003` for mean).\n",
57+
"* **time** (string): The date or interval an observation represents, following RFC 3339. May be a single date, a bounded or half-bounded interval (e.g. `2020-10-01/2021-09-30`), or an ISO 8601 duration (e.g. `P7D` for the past seven days).\n",
58+
"* **skip_geometry** (boolean): If `True`, response geometries are omitted and the returned data frame contains no spatial information."
6459
]
6560
},
6661
{
6762
"cell_type": "markdown",
6863
"metadata": {},
6964
"source": [
70-
"Example 1: Get daily value data for a specific parameter at a single USGS NWIS monitoring site between a begin and end date."
65+
"Example 1: Get daily value data for a specific parameter at a single USGS monitoring location between a begin and end date."
7166
]
7267
},
7368
{
@@ -83,7 +78,7 @@
8378
"source": [
8479
"### Interpreting the Result\n",
8580
"\n",
86-
"The result of calling the `get_dv()` function is an object that contains a Pandas data frame object and an associated metadata object. The Pandas data frame contains the daily values for the observed variable and time period requested. The data frame is indexed by the dates associated with the data values.\n",
81+
"The `get_daily()` function returns a tuple containing a pandas data frame and an associated metadata object. The data frame contains the daily values for the observed variable and time period requested. It is a flat table with a default integer index; the dates associated with each observation are held in a `time` column rather than in the index.\n",
8782
"\n",
8883
"Once you've got the data frame, there's several useful things you can do to explore the data."
8984
]
@@ -148,35 +143,31 @@
148143
"cell_type": "markdown",
149144
"metadata": {},
150145
"source": [
151-
"The other part of the result returned from the `get_dv()` function is a metadata object that contains information about the query that was executed to return the data. For example, you can access the URL that was assembled to retrieve the requested data from the USGS web service. The USGS web service responses contain a descriptive header that defines and can be helpful in interpreting the contents of the response."
146+
"The other part of the result returned from the `get_daily()` function is a metadata object that contains information about the query that was executed to return the data. For example, you can access the URL that was assembled to retrieve the requested data from the USGS Water Data API."
152147
]
153148
},
154149
{
155150
"cell_type": "code",
156151
"execution_count": null,
157152
"metadata": {},
158153
"outputs": [],
159-
"source": [
160-
"print(\n",
161-
" \"The query URL used to retrieve the data from NWIS was: \" + dailyStreamflow[1].url\n",
162-
")"
163-
]
154+
"source": "print(\n \"The query URL used to retrieve the data from the Water Data API was: \" + dailyStreamflow[1].url\n)"
164155
},
165156
{
166157
"cell_type": "markdown",
167158
"metadata": {},
168159
"source": [
169160
"### Additional Examples\n",
170161
"\n",
171-
"Example 2: Get daily mean and max discharge and temperature values for a site between a begin and end date.\n",
162+
"Example 2: Get daily mean and max discharge and temperature values for a location between a begin and end date.\n",
172163
"\n",
173164
"Parameter Code: 00010 = temperature, 00060 = discharge\n",
174165
"See https://help.waterdata.usgs.gov/codes-and-parameters/parameters\n",
175166
"\n",
176167
"Statistic Code: 00001 = Maximum, 00003 = Mean\n",
177168
"See https://help.waterdata.usgs.gov/stat_code\n",
178169
"\n",
179-
"NOTE: There's not full overlap in the availability of data for temperature and discharge for both statistics at this site. When data for one statistic is not available, a \"NaN\" value is returned in the data frame."
170+
"NOTE: There's not full overlap in the availability of data for temperature and discharge for both statistics at this location."
180171
]
181172
},
182173
{
@@ -190,7 +181,7 @@
190181
"cell_type": "markdown",
191182
"metadata": {},
192183
"source": [
193-
"Example 3: Get daily mean and max discharge and temperature values for multiple sites between a begin and end date"
184+
"Example 3: Get daily mean and max discharge and temperature values for multiple monitoring locations between a begin and end date."
194185
]
195186
},
196187
{
@@ -204,7 +195,7 @@
204195
"cell_type": "markdown",
205196
"metadata": {},
206197
"source": [
207-
"The following example is the same as the previous example but with multi index turned off (multi_index=False)"
198+
"Like all of the waterdata getters, `get_daily()` returns a flat data frame with a default integer index regardless of how many monitoring locations are requested. Each row carries its own `monitoring_location_id`, `parameter_code`, `statistic_id`, and `time`, so multi-location results can be filtered or pivoted as needed."
208199
]
209200
},
210201
{
@@ -218,7 +209,7 @@
218209
"cell_type": "markdown",
219210
"metadata": {},
220211
"source": [
221-
"Example 4: Test for a site that is not active - returns an empty DataFrame."
212+
"Example 4: Query a location that has no matching data for the requested period - returns an empty DataFrame."
222213
]
223214
},
224215
{

demos/hydroshare/USGS_WaterData_GroundwaterLevels_Examples.ipynb

Lines changed: 15 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44
"cell_type": "markdown",
55
"metadata": {},
66
"source": [
7-
"# USGS dataretrieval Python Package `get_gwlevels()` Examples\n",
7+
"# USGS dataretrieval Python Package `get_field_measurements()` Examples\n",
88
"\n",
9-
"This notebook provides examples of using the Python dataretrieval package to retrieve groundwater level data for a United States Geological Survey (USGS) monitoring site. The dataretrieval package provides a collection of functions to get data from the USGS National Water Information System (NWIS) and other online sources of hydrology and water quality data, including the United States Environmental Protection Agency (USEPA)."
9+
"This notebook provides examples of using the Python dataretrieval package to retrieve groundwater level field measurements for a United States Geological Survey (USGS) monitoring location. The dataretrieval package provides a collection of functions to get data from the USGS Water Data API and other online sources of hydrology and water quality data."
1010
]
1111
},
1212
{
@@ -39,33 +39,27 @@
3939
"execution_count": null,
4040
"metadata": {},
4141
"outputs": [],
42-
"source": [
43-
"from IPython.display import display\n",
44-
"\n",
45-
"from dataretrieval import nwis\n",
46-
"import dataretrieval.waterdata as waterdata"
47-
]
42+
"source": "from IPython.display import display\n\nimport dataretrieval.waterdata as waterdata"
4843
},
4944
{
5045
"cell_type": "markdown",
5146
"metadata": {},
5247
"source": [
5348
"### Basic Usage\n",
5449
"\n",
55-
"The dataretrieval package has several functions that allow you to retrieve data from different web services. This examples uses the `get_gwlevels()` function to retrieve groundwater level data from USGS NWIS. The following arguments are supported:\n",
50+
"The dataretrieval package has several functions that allow you to retrieve data from different services of the USGS Water Data API. This example uses the `get_field_measurements()` function to retrieve groundwater level field measurements. Field measurements are physically measured values collected during a visit to a monitoring location and are commonly used to record groundwater levels. The following arguments are commonly used:\n",
5651
"\n",
57-
"Arguments (Additional parameters, if supplied, will be used as query parameters)\n",
58-
"\n",
59-
"* **sites** (string or list of strings): A list of USGS site identifiers for which to retrieve data.\n",
60-
"* **start** (string): The beginning date for a period for which to retrieve data. If the waterdata parameter begin_date is supplied, it will overwrite the start parameter (defaults to '1851-01-01')\n",
61-
"* **end** (string): The ending date for a period for which to retrieve data. If the waterdata parameter end_date is supplied, it will overwrite the end parameter."
52+
"* **monitoring_location_id** (string or list of strings): A unique identifier representing one or more monitoring locations. IDs combine the responsible agency code with the location number, separated by a hyphen (e.g. `USGS-434400121275801`).\n",
53+
"* **parameter_code** (string or list of strings): One or more 5-digit codes identifying the constituent measured and its units of measure.\n",
54+
"* **time** (string): The date an observation represents. Accepts a single RFC 3339 date-time, a bounded or half-bounded interval (e.g. `\"1980-01-01/2000-12-31\"`, `\"1980-01-01/..\"`), or an ISO 8601 duration (e.g. `\"P20Y\"`). Only observations whose time intersects this value are returned.\n",
55+
"* **skip_geometry** (boolean): If `True`, response geometries are omitted and the returned data frame contains no spatial information."
6256
]
6357
},
6458
{
6559
"cell_type": "markdown",
6660
"metadata": {},
6761
"source": [
68-
"Example 1: Get groundwater level data for a single monitoring site."
62+
"Example 1: Get groundwater level field measurements for a single monitoring location."
6963
]
7064
},
7165
{
@@ -81,7 +75,7 @@
8175
"source": [
8276
"### Interpreting the Result\n",
8377
"\n",
84-
"The result of calling the `get_gwlevels()` function is an object that contains a Pandas data frame and an associated metadata object. The Pandas data frame contains the data requested. The data frame is indexed by the dates associated with the data values.\n",
78+
"The `get_field_measurements()` function returns a tuple of two objects: a pandas data frame containing the requested data and an associated metadata object. The data frame is flat, using a default integer index, and the observation dates are held in its `time` column.\n",
8579
"\n",
8680
"Once you've got the data frame, there's several useful things you can do to explore the data."
8781
]
@@ -122,7 +116,7 @@
122116
"cell_type": "markdown",
123117
"metadata": {},
124118
"source": [
125-
"Get summary statistics for the daily streamflow values."
119+
"Get summary statistics for the measured groundwater level values."
126120
]
127121
},
128122
{
@@ -152,7 +146,7 @@
152146
"cell_type": "markdown",
153147
"metadata": {},
154148
"source": [
155-
"The other part of the result returned from the `get_gwlevels()` function is a metadata object that contains information about the query that was executed to return the data. For example, you can access the URL that was assembled to retrieve the requested data from the USGS web service. The USGS web service responses contain a descriptive header that defines and can be helpful in interpreting the contents of the response."
149+
"The other part of the result returned from the `get_field_measurements()` function is a metadata object that contains information about the query that was executed to return the data. For example, you can access the URL that was assembled to retrieve the requested data from the USGS Water Data API."
156150
]
157151
},
158152
{
@@ -186,7 +180,7 @@
186180
"cell_type": "markdown",
187181
"metadata": {},
188182
"source": [
189-
"The following example is the same as the previous example but with multi index turned off (multi_index=False)"
183+
"The following example requests the same data as the previous example, again passing the site identifiers as a list of strings."
190184
]
191185
},
192186
{
@@ -216,18 +210,15 @@
216210
"cell_type": "markdown",
217211
"metadata": {},
218212
"source": [
219-
"If you want to see the USGS RDB (delimited text) version of the data just retrieved, you can get the URL for the request that was sent to the USGS web service."
213+
"If you want to inspect the request that was sent, you can get the URL for the query that was issued to the USGS Water Data API."
220214
]
221215
},
222216
{
223217
"cell_type": "code",
224218
"execution_count": null,
225219
"metadata": {},
226220
"outputs": [],
227-
"source": [
228-
"# Print the URL used to retrieve the data\n",
229-
"print(\"You can examine the data retrieved from NWIS at: \" + data3[1].url)"
230-
]
221+
"source": "# Print the URL used to retrieve the data\nprint(\"You can examine the data retrieved from the Water Data API at: \" + data3[1].url)"
231222
},
232223
{
233224
"cell_type": "markdown",

0 commit comments

Comments
 (0)