Show code
from pygeohydro import WBD
import geoviews as gv
import geoviews.tile_sources as gvts
from _helpers import init_session, save_outputs, show, categorical_colors
gv.extension("bokeh")
S = init_session()USGS API key loaded.
First notebook in the Thornforest hydrology series. It builds the spatial foundation (the three HUC-8 watershed boundaries) that the other notebooks rely on, and maps it.
Our study area is three HUC-8 subbasins in South Texas: - South Laguna Madre (12110208) - Los Olmos (13090001) - Lower Rio Grande (13090002)
New to Python notebooks? Run each cell in order with Shift + Enter.
All imports are at the top. init_session() (from our shared _helpers module) loads the optional USGS API key, configures the on-disk request cache, and returns the paths we use.
A dictionary maps each HUC-8 code to a friendly name. Colors come from a colorcet categorical palette (via categorical_colors) so the figure data colors are perceptually distinct and consistent across the project.
WBD("huc8").byids(...) fetches the three boundaries from the USGS Watershed Boundary Dataset. The request is cached on disk; the result is also saved to data/spatial/.
saved 3 rows → data/spatial/huc8_watersheds.parquet (+ .csv)
3 watershed boundaries.
A GeoDataFrame (one row per watershed, with a geometry shape). The coordinates are longitude/latitude (EPSG:4326).
We layer the boundaries over an Esri World Topo basemap; * stacks layers. data_aspect=1 keeps map pixels square so the basemap tiles aren’t stretched.
Explore: hover for name/area; zoom/pan with the toolbar; click legend entries.
watershed_layers = []
for code, name in HUC8_WATERSHEDS.items():
one = watersheds_gdf[watersheds_gdf["huc8"] == code]
watershed_layers.append(
gv.Polygons(one, vdims=["name", "huc8", "areasqkm"], label=name).opts(
color=HUC8_COLORS[code],
line_color=HUC8_COLORS[code],
alpha=0.45,
line_width=2,
tools=["hover"],
)
)
watersheds_map = gvts.EsriWorldTopo
for layer in watershed_layers:
watersheds_map = watersheds_map * layer
watersheds_map = watersheds_map.opts(
frame_width=850,
data_aspect=1,
title="Three HUC-8 Watersheds — Thornforest Study Area (South Texas)",
legend_position="top_left",
active_tools=["wheel_zoom"],
)
watersheds_mapThe boundaries are saved to data/spatial/. Notebook 2_usgs_waterdata reads them to discover the USGS monitoring stations inside the watersheds and the parameters they measure.