Use this Skill for DEM-based hydrological analysis: watershed delineation, flow direction/accumulation, stream networks, and runoff estimation with pysheds.
Installer avec Codex ou Claude Copiez ce prompt, collez-le dans Codex, Claude ou un autre assistant, puis laissez-le vérifier la page du skill et l'installer pour vous.
Une commande directe contourne le prompt de vérification. Examinez la source avant de l'exécuter.
Use this Skill for DEM-based hydrological analysis: watershed delineation, flow direction/accumulation, stream networks, and runoff estimation with pysheds.
One-line summary: Derive watersheds, stream networks, and flow accumulation from Digital Elevation Models (DEMs) using pysheds, rasterio, and geopandas.
When to Use This Skill
When delineating watershed boundaries from a DEM for a pour point
When extracting stream networks from topographic data
When computing flow direction and accumulation grids
When estimating runoff and drainage basin area
When conditioning DEMs to remove pits and flat areas
When analyzing upstream contributing area for flood modeling
Trigger keywords: watershed delineation, DEM, flow direction, flow accumulation, stream network, pysheds, hydrological analysis, basin area, pour point
# Download SRTM DEM tile (90m resolution) for a test region# Using elevation package or manual download from USGS
pip install elevation
eio clip -o dem_test.tif --bounds -105.5 39.5 -104.5 40.5 # Colorado Front Range
Bartos, M. et al. (2021). pysheds: An open-source Python library for watershed delineation. JOSS.
Examples
Example 1: Extract Stream Network from SRTM DEM
# =============================================# Stream network extraction workflow# =============================================# NOTE: Requires actual DEM file (download from USGS Earth Explorer)# This shows the complete workflow assuming dem.tif existstry:
from pysheds.grid import Grid
import numpy as np
import matplotlib.pyplot as plt
import geopandas as gpd
# Step 1: Load
grid = Grid.from_raster('dem.tif')
dem = grid.read_raster('dem.tif')
print(f"DEM loaded: {dem.shape}, range {dem.min():.0f}–{dem.max():.0f} m")
# Step 2: Condition
pit_filled = grid.fill_pits(dem)
dep_filled = grid.fill_depressions(pit_filled)
inflated = grid.resolve_flats(dep_filled)
# Step 3: Flow analysis
fdir = grid.flowdir(inflated)
acc = grid.accumulation(fdir)
# Step 4: Extract streams at multiple thresholds
fig, axes = plt.subplots(1, 3, figsize=(15, 5))
for ax, thresh_pct inzip(axes, [0.1, 0.5, 2.0]):
thresh = int(acc.max() * thresh_pct / 100)
streams = acc > thresh
ax.imshow(np.log1p(acc), cmap='Blues', alpha=0.5)
ax.imshow(np.ma.masked_where(~streams, streams), cmap='Reds', alpha=0.8)
ax.set_title(f"Threshold: {thresh_pct}% ({thresh:,} cells)")
ax.axis('off')
plt.suptitle("Stream Networks at Different Thresholds")
plt.tight_layout()
plt.savefig("stream_networks.png", dpi=150)
plt.show()
except FileNotFoundError:
print("DEM file not found. Download from USGS Earth Explorer (https://earthexplorer.usgs.gov/)")
print("Then run: eio clip -o dem.tif --bounds <lon_min> <lat_min> <lon_max> <lat_max>")
Interpreting these results: Lower thresholds yield denser stream networks; higher thresholds show only major rivers. Use Strahler stream order to classify streams.
Last updated: 2026-03-17 | Maintainer: @xjtulycIssues: GitHub Issues