Skip to content

Commit 95c44d5

Browse files
thodson-usgsclaude
andcommitted
docs: clean up Water Data API vignettes
- Rename `daily_modern`/`field_modern` → `daily_data`/`field_data` (the "_modern" suffix was a leftover NWIS-vs-modern comparison artifact) - Rename `what_huc_sites` → `huc_sites`, `sites_information` → `sites_info`, `site_1`/`site_2` → `renamed`/`raw_id`, and `site1` → `site` in the daily statistics notebook (no `site2` ever existed) - Fix broken intra-notebook anchor `#General-retrieval-and-CQL2` → `#general-retrieval-and-cql2` - Simplify the daily-values facet plot by dropping the unnecessary `squeeze=False` + axes-indexing workaround - Clean up the `map_sites` helper in the samples notebook to use the conventional `fig, ax = plt.subplots(...)` unpacking and a docstring Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 1783f2c commit 95c44d5

3 files changed

Lines changed: 52 additions & 36 deletions

demos/USGS_WaterData_DailyStatistics_Examples.ipynb

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
"\n",
4242
"%matplotlib inline\n",
4343
"\n",
44-
"site1 = \"USGS-02037500\""
44+
"site = \"USGS-02037500\""
4545
]
4646
},
4747
{
@@ -66,7 +66,7 @@
6666
"outputs": [],
6767
"source": [
6868
"jan_por_mean, _ = waterdata.get_stats_por(\n",
69-
" monitoring_location_id=site1,\n",
69+
" monitoring_location_id=site,\n",
7070
" parameter_code=\"00060\",\n",
7171
" computation_type=\"arithmetic_mean\",\n",
7272
" start_date=\"01-01\",\n",
@@ -126,7 +126,7 @@
126126
"outputs": [],
127127
"source": [
128128
"full_por_percentiles, _ = waterdata.get_stats_por(\n",
129-
" monitoring_location_id=site1,\n",
129+
" monitoring_location_id=site,\n",
130130
" parameter_code=\"00060\",\n",
131131
" computation_type=[\"minimum\", \"maximum\", \"percentile\"],\n",
132132
" start_date=\"01-01\",\n",
@@ -210,7 +210,7 @@
210210
"outputs": [],
211211
"source": [
212212
"daily, _ = waterdata.get_daily(\n",
213-
" monitoring_location_id=site1,\n",
213+
" monitoring_location_id=site,\n",
214214
" parameter_code=\"00060\",\n",
215215
" statistic_id=\"00003\",\n",
216216
" time=[\"2024-01-01\", \"2025-12-31\"],\n",
@@ -259,7 +259,7 @@
259259
"outputs": [],
260260
"source": [
261261
"jan_daterange_mean, _ = waterdata.get_stats_date_range(\n",
262-
" monitoring_location_id=site1,\n",
262+
" monitoring_location_id=site,\n",
263263
" parameter_code=\"00060\",\n",
264264
" computation_type=\"arithmetic_mean\",\n",
265265
" start_date=\"2024-01-01\",\n",
@@ -287,7 +287,7 @@
287287
"outputs": [],
288288
"source": [
289289
"multiyear, _ = waterdata.get_stats_date_range(\n",
290-
" monitoring_location_id=site1,\n",
290+
" monitoring_location_id=site,\n",
291291
" parameter_code=\"00060\",\n",
292292
" computation_type=\"arithmetic_mean\",\n",
293293
" start_date=\"2023-09-30\",\n",
@@ -338,7 +338,7 @@
338338
"outputs": [],
339339
"source": [
340340
"monthly_raw, _ = waterdata.get_stats_date_range(\n",
341-
" monitoring_location_id=site1,\n",
341+
" monitoring_location_id=site,\n",
342342
" parameter_code=\"00060\",\n",
343343
" computation_type=\"arithmetic_mean\",\n",
344344
")\n",

demos/USGS_WaterData_DiscreteSamples_Examples.ipynb

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,11 @@
4343
"plt.rcParams[\"figure.figsize\"] = (7, 4)\n",
4444
"\n",
4545
"\n",
46-
"# Scatter plot of sample-site locations (a static map; use folium for an\n",
47-
"# interactive version).\n",
4846
"def map_sites(df, title=\"\"):\n",
47+
" \"\"\"Static scatter plot of sample-site locations. Use folium for interactive.\"\"\"\n",
4948
" lon = pd.to_numeric(df[\"Location_Longitude\"], errors=\"coerce\")\n",
5049
" lat = pd.to_numeric(df[\"Location_Latitude\"], errors=\"coerce\")\n",
51-
" ax = plt.subplots(figsize=(7, 5))[1]\n",
50+
" fig, ax = plt.subplots(figsize=(7, 5))\n",
5251
" ax.scatter(lon, lat, s=10, color=\"red\", alpha=0.7)\n",
5352
" ax.set_xlabel(\"Longitude\")\n",
5453
" ax.set_ylabel(\"Latitude\")\n",
@@ -528,12 +527,21 @@
528527
],
529528
"metadata": {
530529
"kernelspec": {
531-
"display_name": "Python 3",
530+
"display_name": "Python 3 (ipykernel)",
532531
"language": "python",
533532
"name": "python3"
534533
},
535534
"language_info": {
536-
"name": "python"
535+
"codemirror_mode": {
536+
"name": "ipython",
537+
"version": 3
538+
},
539+
"file_extension": ".py",
540+
"mimetype": "text/x-python",
541+
"name": "python",
542+
"nbconvert_exporter": "python",
543+
"pygments_lexer": "ipython3",
544+
"version": "3.12.10"
537545
}
538546
},
539547
"nbformat": 4,

demos/USGS_WaterData_Introduction_Examples.ipynb

Lines changed: 32 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@
9797
"outputs": [],
9898
"source": [
9999
"# Ask for just a few columns instead of the full ~40-column record.\n",
100-
"site_info, _ = waterdata.get_monitoring_locations(\n",
100+
"sites_info, _ = waterdata.get_monitoring_locations(\n",
101101
" monitoring_location_id=\"USGS-01491000\",\n",
102102
" properties=[\n",
103103
" \"monitoring_location_id\",\n",
@@ -106,7 +106,7 @@
106106
" \"monitoring_location_name\",\n",
107107
" ],\n",
108108
")\n",
109-
"site_info.drop(columns=\"geometry\")"
109+
"sites_info.drop(columns=\"geometry\")"
110110
]
111111
},
112112
{
@@ -126,7 +126,7 @@
126126
"\n",
127127
"The APIs accept [CQL2](https://www.loc.gov/standards/sru/cql/) expressions for\n",
128128
"complex queries through the `filter` / `filter_lang` arguments. See the\n",
129-
"[General retrieval and CQL2](#General-retrieval-and-CQL2) section below.\n",
129+
"[General retrieval and CQL2](#general-retrieval-and-cql2) section below.\n",
130130
"\n",
131131
"### Simple features\n",
132132
"\n",
@@ -176,11 +176,11 @@
176176
"metadata": {},
177177
"outputs": [],
178178
"source": [
179-
"sites_information, _ = waterdata.get_monitoring_locations(\n",
179+
"sites_info, _ = waterdata.get_monitoring_locations(\n",
180180
" monitoring_location_id=\"USGS-01491000\"\n",
181181
")\n",
182-
"print(f\"{sites_information.shape[1]} columns returned\")\n",
183-
"sites_information.drop(columns=\"geometry\").T"
182+
"print(f\"{sites_info.shape[1]} columns returned\")\n",
183+
"sites_info.drop(columns=\"geometry\").T"
184184
]
185185
},
186186
{
@@ -299,13 +299,13 @@
299299
"metadata": {},
300300
"outputs": [],
301301
"source": [
302-
"daily_modern, _ = waterdata.get_daily(\n",
302+
"daily_data, _ = waterdata.get_daily(\n",
303303
" monitoring_location_id=\"USGS-01491000\",\n",
304304
" parameter_code=[\"00060\", \"00010\"],\n",
305305
" statistic_id=\"00003\",\n",
306306
" time=[\"2023-10-01\", \"2024-09-30\"],\n",
307307
")\n",
308-
"daily_modern[[\"time\", \"parameter_code\", \"value\", \"approval_status\"]].head()"
308+
"daily_data[[\"time\", \"parameter_code\", \"value\", \"approval_status\"]].head()"
309309
]
310310
},
311311
{
@@ -324,11 +324,10 @@
324324
"metadata": {},
325325
"outputs": [],
326326
"source": [
327-
"params = sorted(daily_modern[\"parameter_code\"].unique())\n",
328-
"fig, axes = plt.subplots(len(params), 1, figsize=(7, 5), sharex=True, squeeze=False)\n",
329-
"axes = axes[:, 0] # squeeze=False -> always a 2-D array, even for one param\n",
327+
"params = sorted(daily_data[\"parameter_code\"].unique())\n",
328+
"fig, axes = plt.subplots(len(params), 1, figsize=(7, 5), sharex=True)\n",
330329
"for ax, pcode in zip(axes, params):\n",
331-
" sub = daily_modern[daily_modern[\"parameter_code\"] == pcode]\n",
330+
" sub = daily_data[daily_data[\"parameter_code\"] == pcode]\n",
332331
" ax.scatter(sub[\"time\"], sub[\"value\"], s=4)\n",
333332
" ax.set_ylabel(pcode)\n",
334333
"axes[0].set_title(\"Daily values at USGS-01491000 (water year 2024)\")\n",
@@ -386,14 +385,14 @@
386385
"metadata": {},
387386
"outputs": [],
388387
"source": [
389-
"field_modern, _ = waterdata.get_field_measurements(\n",
388+
"field_data, _ = waterdata.get_field_measurements(\n",
390389
" monitoring_location_id=[\n",
391390
" \"USGS-451605097071701\",\n",
392391
" \"USGS-263819081585801\",\n",
393392
" ],\n",
394393
" time=[\"2023-10-01\", \"2024-09-30\"],\n",
395394
")\n",
396-
"field_modern[[\"time\", \"monitoring_location_id\", \"parameter_code\", \"value\"]].head()"
395+
"field_data[[\"time\", \"monitoring_location_id\", \"parameter_code\", \"value\"]].head()"
397396
]
398397
},
399398
{
@@ -404,7 +403,7 @@
404403
"outputs": [],
405404
"source": [
406405
"fig, ax = plt.subplots(figsize=(7, 4))\n",
407-
"for site, sub in field_modern.groupby(\"monitoring_location_id\"):\n",
406+
"for site, sub in field_data.groupby(\"monitoring_location_id\"):\n",
408407
" ax.scatter(sub[\"time\"], sub[\"value\"], s=12, label=site)\n",
409408
"ax.set_ylabel(\"value\")\n",
410409
"ax.set_title(\"Field measurements\")\n",
@@ -499,12 +498,12 @@
499498
"metadata": {},
500499
"outputs": [],
501500
"source": [
502-
"what_huc_sites, _ = waterdata.get_monitoring_locations(\n",
501+
"huc_sites, _ = waterdata.get_monitoring_locations(\n",
503502
" filter=\"hydrologic_unit_code LIKE '02070010%'\",\n",
504503
" filter_lang=\"cql-text\",\n",
505504
")\n",
506-
"print(f\"{len(what_huc_sites)} sites in HUC 02070010\")\n",
507-
"ax = what_huc_sites.plot(markersize=2, figsize=(7, 5))\n",
505+
"print(f\"{len(huc_sites)} sites in HUC 02070010\")\n",
506+
"ax = huc_sites.plot(markersize=2, figsize=(7, 5))\n",
508507
"ax.set_title(\"Sites within HUC 02070010\")\n",
509508
"plt.show()"
510509
]
@@ -620,16 +619,16 @@
620619
"outputs": [],
621620
"source": [
622621
"site = \"USGS-02238500\"\n",
623-
"site_1, _ = waterdata.get_monitoring_locations(\n",
622+
"renamed, _ = waterdata.get_monitoring_locations(\n",
624623
" monitoring_location_id=site,\n",
625624
" properties=[\"monitoring_location_id\", \"state_name\", \"country_name\"],\n",
626625
")\n",
627-
"site_2, _ = waterdata.get_monitoring_locations(\n",
626+
"raw_id, _ = waterdata.get_monitoring_locations(\n",
628627
" monitoring_location_id=site,\n",
629628
" properties=[\"id\", \"state_name\", \"country_name\"],\n",
630629
")\n",
631-
"print(\"renamed:\", [c for c in site_1.columns if c != \"geometry\"])\n",
632-
"print(\"raw id :\", [c for c in site_2.columns if c != \"geometry\"])"
630+
"print(\"renamed:\", [c for c in renamed.columns if c != \"geometry\"])\n",
631+
"print(\"raw id :\", [c for c in raw_id.columns if c != \"geometry\"])"
633632
]
634633
},
635634
{
@@ -647,12 +646,21 @@
647646
],
648647
"metadata": {
649648
"kernelspec": {
650-
"display_name": "Python 3",
649+
"display_name": "Python 3 (ipykernel)",
651650
"language": "python",
652651
"name": "python3"
653652
},
654653
"language_info": {
655-
"name": "python"
654+
"codemirror_mode": {
655+
"name": "ipython",
656+
"version": 3
657+
},
658+
"file_extension": ".py",
659+
"mimetype": "text/x-python",
660+
"name": "python",
661+
"nbconvert_exporter": "python",
662+
"pygments_lexer": "ipython3",
663+
"version": "3.12.10"
656664
}
657665
},
658666
"nbformat": 4,

0 commit comments

Comments
 (0)