HmsHuc¶
HUC watershed boundary discovery and retrieval helpers.
hms_commander.HmsHuc
¶
HmsHuc - HUC Watershed Operations for HMS Commander
Provides static methods for downloading and working with USGS Hydrologic Unit Code (HUC) watersheds from the Watershed Boundary Dataset (WBD) via PyNHD.
This module enables automated download of standardized watershed boundaries for use in AORC precipitation grid cell mapping and other spatial operations.
Classes:
| Name | Description |
|---|---|
HmsHuc |
Static class for HUC watershed operations |
Key Functions
get_huc12_for_bounds: Download HUC12 watersheds within bounding box get_huc8_for_bounds: Download HUC8 watersheds within bounding box get_huc_by_ids: Download specific HUCs by ID get_available_levels: List available HUC levels
Dependencies
Required: - pygeohydro: HUC watershed download - geopandas: Spatial data handling - shapely: Geometry operations
Install with: pip install hms-commander[gis] # OR pip install pygeohydro geopandas shapely
Example
from hms_commander import HmsHuc
Download HUC12 watersheds for project area¶
bounds = (-77.71, 41.01, -77.25, 41.22) # west, south, east, north watersheds = HmsHuc.get_huc12_for_bounds(bounds) print(f"Downloaded {len(watersheds)} HUC12 watersheds")
Access data¶
for idx, ws in watersheds.iterrows(): ... print(f"{ws['huc12']}: {ws['name']} ({ws['areasqkm']:.1f} km²)")
Notes
- All methods are static (no instantiation required)
- Returns GeoPandas GeoDataFrames with WGS84 (EPSG:4326) CRS
- HUC boundaries are standardized, peer-reviewed by USGS
- Final WBD published January 2025 (static but authoritative)
HmsHuc
¶
Static class for HUC watershed operations.
Provides methods for downloading USGS Hydrologic Unit Code (HUC) watersheds from the Watershed Boundary Dataset (WBD) using PyNHD.
All methods are static - do not instantiate this class.
HUC Levels
- HUC2: Regions (21 in CONUS)
- HUC4: Subregions (222 in CONUS)
- HUC6: Basins (378 in CONUS)
- HUC8: Subbasins (2,264 in CONUS) - Good for regional HMS models
- HUC10: Watersheds (18,000+ in CONUS)
- HUC12: Subwatersheds (100,000+ in CONUS) - Good for detailed HMS models
Example
from hms_commander import HmsHuc
Download HUC12 watersheds¶
bounds = (-77.71, 41.01, -77.25, 41.22) huc12s = HmsHuc.get_huc12_for_bounds(bounds)
Download specific HUC by ID¶
specific = HmsHuc.get_huc_by_ids("huc12", ["020502030404"])
Source code in hms_commander/HmsHuc.py
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 | |
get_huc12_for_bounds(bounds, return_format='geodataframe')
staticmethod
¶
Download HUC12 watersheds within bounding box.
Parameters¶
bounds : Tuple[float, float, float, float] Bounding box as (west, south, east, north) in WGS84 decimal degrees. Example: (-77.71, 41.01, -77.25, 41.22) return_format : str, default "geodataframe" Return format: - "geodataframe": GeoPandas GeoDataFrame (default) - "shapefile": Save to shapefile and return path - "geojson": Save to GeoJSON and return path
Returns¶
gpd.GeoDataFrame or Path HUC12 watersheds as GeoDataFrame (if return_format="geodataframe") or Path to output file (if return_format="shapefile" or "geojson").
GeoDataFrame columns include:
- huc12: 12-digit HUC identifier
- name: Watershed name
- areasqkm: Area in square kilometers
- states: State abbreviations
- geometry: Polygon geometry (EPSG:4326)
Raises¶
ImportError If pygeohydro, geopandas, or shapely not installed ValueError If bounds are invalid or no HUCs found
Examples¶
from hms_commander import HmsHuc
Download HUC12s for project area¶
bounds = (-77.71, 41.01, -77.25, 41.22) watersheds = HmsHuc.get_huc12_for_bounds(bounds) print(f"Found {len(watersheds)} HUC12 watersheds")
Inspect data¶
print(watersheds[['huc12', 'name', 'areasqkm']])
Save to file¶
path = HmsHuc.get_huc12_for_bounds(bounds, return_format="geojson")
Notes¶
- Returns watersheds that intersect the bounding box
- CRS is always EPSG:4326 (WGS84)
- Typical HUC12 size: 0.1-1 square mile (~10-100 km²)
- May return 5-50+ HUC12s depending on area size
Source code in hms_commander/HmsHuc.py
101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 | |
get_huc8_for_bounds(bounds, return_format='geodataframe')
staticmethod
¶
Download HUC8 watersheds within bounding box.
Parameters¶
bounds : Tuple[float, float, float, float] Bounding box as (west, south, east, north) in WGS84 decimal degrees. return_format : str, default "geodataframe" Return format: "geodataframe", "shapefile", or "geojson"
Returns¶
gpd.GeoDataFrame or Path HUC8 watersheds as GeoDataFrame or path to output file.
GeoDataFrame columns include:
- huc8: 8-digit HUC identifier
- name: Watershed name
- areasqkm: Area in square kilometers
- states: State abbreviations
- geometry: Polygon geometry (EPSG:4326)
Examples¶
from hms_commander import HmsHuc
Download HUC8s for regional model¶
bounds = (-77.71, 41.01, -77.25, 41.22) watersheds = HmsHuc.get_huc8_for_bounds(bounds) print(f"Found {len(watersheds)} HUC8 watersheds")
Notes¶
- HUC8 represents subbasins (typically 10-100 square miles)
- Good for regional HMS models with multiple subbasins
- Fewer watersheds than HUC12 (typically 1-5 per small area)
Source code in hms_commander/HmsHuc.py
206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 | |
get_huc_by_ids(level, huc_ids, return_format='geodataframe')
staticmethod
¶
Download specific HUC watersheds by ID.
Parameters¶
level : str HUC level: "huc2", "huc4", "huc6", "huc8", "huc10", or "huc12" huc_ids : List[str] List of HUC identifiers to download. Example: ["020502030404", "020502030405"] for HUC12 return_format : str, default "geodataframe" Return format: "geodataframe", "shapefile", or "geojson"
Returns¶
gpd.GeoDataFrame or Path Requested HUC watersheds
Raises¶
ValueError If invalid level or no HUCs found
Examples¶
from hms_commander import HmsHuc
Download specific HUC12 watersheds¶
huc_ids = ["020502030404", "020502030405"] watersheds = HmsHuc.get_huc_by_ids("huc12", huc_ids)
Download specific HUC8¶
watersheds = HmsHuc.get_huc_by_ids("huc8", ["02050203"])
Notes¶
- Useful when you know specific HUC IDs you need
- Faster than bounding box query for specific watersheds
- Can mix HUCs from different regions
Source code in hms_commander/HmsHuc.py
289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 | |
get_available_levels()
staticmethod
¶
Get list of available HUC levels.
Returns¶
List[str] Available HUC levels: ["huc2", "huc4", "huc6", "huc8", "huc10", "huc12"]
Examples¶
from hms_commander import HmsHuc
levels = HmsHuc.get_available_levels() print(f"Available HUC levels: {levels}")
Source code in hms_commander/HmsHuc.py
get_huc_info()
staticmethod
¶
Get information about HUC levels and typical characteristics.
Returns¶
dict Information about each HUC level including typical size and count.
Examples¶
from hms_commander import HmsHuc
info = HmsHuc.get_huc_info() for level, data in info.items(): ... print(f"{level}: {data['description']}")