AgentSkillsCN

usgs_integrate_gauges

完整的USGS水位计数据集成流程,从空间发现到模型验证。涵盖水位计查找、数据获取、与HEC-RAS特征匹配、边界条件生成、初始条件设定、实时监测以及验证指标(NSE、KGE)等环节。适用于处理USGS数据、NWIS水位计、基于观测流量生成边界、模型校准、用观测数据验证模型,或搭建运行预报系统。 触发条件:USGS、NWIS、水位计、流量、观测数据、水位计生成的边界条件、校准、验证、NSE、KGE、空间发现、水位计匹配、实时监测、初始条件、GaugeMatcher、UsgsGaugeSpatial、RasUsgsCore、流量数据、水位数据、泄洪量、率定曲线、观测流量、靠近模型的水位计。

SKILL.md
--- frontmatter
name: usgs_integrate_gauges
description: |
  Complete USGS gauge data integration workflow from spatial discovery to
  model validation. Handles gauge finding, data retrieval, matching to HEC-RAS
  features, boundary condition generation, initial conditions, real-time
  monitoring, and validation metrics (NSE, KGE). Use when working with USGS
  data, NWIS gauges, generating boundaries from observed flow, calibrating
  models, validating with observed data, or setting up operational forecasting.
  Triggers: USGS, NWIS, gauge, streamflow, observed data, boundary condition from gauge,
  calibration, validation, NSE, KGE, spatial discovery, gauge matching, real-time monitoring,
  initial conditions, GaugeMatcher, UsgsGaugeSpatial, RasUsgsCore, flow data, stage data,
  discharge, rating curve, observed flow, gauge near model.

Integrating USGS Gauges

Lightweight skill navigator -- Read authoritative sources instead of duplicating content.

Primary Documentation Sources

COMPLETE WORKFLOWS AND API REFERENCE:

  • ras_commander/usgs/CLAUDE.md (367 lines) - Complete module documentation with workflows
    • Module overview and API reference
    • 7-stage workflow (discovery → validation)
    • Real-time monitoring patterns
    • Catalog generation workflow

WORKING EXAMPLES:

  • examples/911_usgs_gauge_data_integration.ipynb - Complete workflow (discovery → validation)
  • examples/912_usgs_real_time_monitoring.ipynb - Real-time monitoring examples
  • examples/913_bc_generation_from_live_gauge.ipynb - Boundary condition generation
  • examples/914_model_validation_with_usgs.ipynb - Model validation workflow
  • examples/910_usgs_gauge_catalog.ipynb - Catalog generation (v0.89.0+)

CODE DOCSTRINGS:

  • All classes have comprehensive docstrings with examples
  • Read docstrings for detailed parameter documentation

Quick Navigation Guide

What to Use When

TaskPrimary SourceSecondary Source
API referenceras_commander/usgs/CLAUDE.mdCode docstrings
Complete workflowsras_commander/usgs/CLAUDE.mdExample notebooks
Spatial discoveryCLAUDE.md → Spatial Queries section421_usgs_*.ipynb
Data retrievalCLAUDE.md → Data Retrieval section421_usgs_*.ipynb
Gauge matchingCLAUDE.md → Gauge Matching section421_usgs_*.ipynb
Boundary generationCLAUDE.md → Boundary Conditions section423_bc_*.ipynb
Initial conditionsCLAUDE.md → Initial Conditions section423_bc_*.ipynb
Real-time monitoringCLAUDE.md → Real-Time Monitoring section422_*.ipynb
Catalog generationCLAUDE.md → Catalog Generation section420_*.ipynb
Model validationCLAUDE.md → Validation Metrics section424_*.ipynb
VisualizationCLAUDE.md → Visualization section424_*.ipynb
TroubleshootingExample notebooks (see errors/warnings)Code comments

Module Quick Reference

From ras_commander/usgs/CLAUDE.md:

Core Data Retrieval (core.py):

  • RasUsgsCore.retrieve_flow_data() - Get flow time series
  • RasUsgsCore.retrieve_stage_data() - Get stage time series
  • RasUsgsCore.get_gauge_metadata() - Get gauge info
  • RasUsgsCore.check_data_availability() - Check data exists

Spatial Discovery (spatial.py):

  • UsgsGaugeSpatial.find_gauges_in_project() - Find gauges in project bounds
  • UsgsGaugeSpatial.get_project_gauges_with_data() - Find gauges with data for sim period

Gauge Matching (gauge_matching.py):

  • GaugeMatcher.auto_match_gauges() - Automatic matching
  • GaugeMatcher.match_gauge_to_cross_section() - Match to 1D XS
  • GaugeMatcher.match_gauge_to_2d_area() - Match to 2D area

Time Series (time_series.py):

  • RasUsgsTimeSeries.resample_to_hecras_interval() - Resample to HEC-RAS intervals
  • RasUsgsTimeSeries.check_data_gaps() - Detect gaps
  • RasUsgsTimeSeries.align_timeseries() - Align observed/modeled

Boundary Generation (boundary_generation.py):

  • RasUsgsBoundaryGeneration.generate_flow_hydrograph_table() - Create BC table
  • RasUsgsBoundaryGeneration.update_boundary_hydrograph() - Update .u## file

Initial Conditions (initial_conditions.py):

  • InitialConditions.create_ic_line() - Generate IC line
  • InitialConditions.get_ic_value_from_usgs() - Extract IC from USGS data

Real-Time (real_time.py) - v0.87.0+:

  • RasUsgsRealTime.get_latest_value() - Get most recent reading
  • RasUsgsRealTime.monitor_gauge() - Continuous monitoring with callbacks
  • RasUsgsRealTime.detect_threshold_crossing() - Flood detection

Catalog (catalog.py) - v0.89.0+:

  • catalog.generate_gauge_catalog() - Create standardized gauge catalog
  • catalog.load_gauge_catalog() - Load catalog
  • catalog.load_gauge_data() - Load historical data

Validation (metrics.py):

  • metrics.nash_sutcliffe_efficiency() - NSE metric
  • metrics.kling_gupta_efficiency() - KGE metric
  • metrics.calculate_all_metrics() - Complete validation suite

Visualization (visualization.py):

  • visualization.plot_timeseries_comparison() - Observed vs modeled plots
  • visualization.plot_scatter_comparison() - Scatter with 1:1 line
  • visualization.plot_residuals() - 4-panel diagnostics

File I/O (file_io.py):

  • RasUsgsFileIo.cache_gauge_data() - Save to CSV
  • RasUsgsFileIo.load_cached_gauge_data() - Load from CSV

Minimal Quick Start

For complete quick start, see ras_commander/usgs/CLAUDE.md.

Basic pattern (copy-paste starting point):

python
from ras_commander import init_ras_project
from ras_commander.usgs import UsgsGaugeSpatial, RasUsgsCore, GaugeMatcher

# Initialize
init_ras_project(r"C:\Projects\MyModel", "6.5")

# 1. Find gauges
gauges = UsgsGaugeSpatial.find_gauges_in_project(
    project_folder=r"C:\Projects\MyModel",
    buffer_miles=5.0
)

# 2. Get data
flow_data = RasUsgsCore.retrieve_flow_data(
    site_no="01646500",
    start_date="2023-09-01",
    end_date="2023-09-15",
    service='iv'  # Instantaneous values
)

# 3. Match to model
matches = GaugeMatcher.auto_match_gauges(
    gauges_gdf=gauges,
    project_folder=r"C:\Projects\MyModel"
)

# For complete workflow, see ras_commander/usgs/CLAUDE.md

Common Workflow Patterns

Pattern 1: Boundary Condition Generation

See: ras_commander/usgs/CLAUDE.md → "Complete Workflow" section → Stage 5 Example: examples/913_bc_generation_from_live_gauge.ipynb

Pattern 2: Model Validation

See: ras_commander/usgs/CLAUDE.md → "Complete Workflow" section → Stage 6 Example: examples/914_model_validation_with_usgs.ipynb

Pattern 3: Real-Time Monitoring

See: ras_commander/usgs/CLAUDE.md → "Real-Time Workflows" section Example: examples/912_usgs_real_time_monitoring.ipynb

Pattern 4: Gauge Catalog Generation

See: ras_commander/usgs/CLAUDE.md → "Complete Workflow" section → Stage 7 Example: examples/910_usgs_gauge_catalog.ipynb

Troubleshooting Guide

Missing dataretrieval Module

code
ModuleNotFoundError: No module named 'dataretrieval'

Solution: pip install dataretrieval

No Gauges Found

Check:

  1. Increase buffer_miles parameter
  2. Verify project coordinate system
  3. Check if project bounds are correct

See: examples/911_usgs_*.ipynb for spatial discovery debugging

Data Gaps

Tools:

  • RasUsgsTimeSeries.check_data_gaps() - Detect gaps
  • RasUsgsTimeSeries.fill_data_gaps() - Interpolate gaps

See: ras_commander/usgs/CLAUDE.md → Time Series Processing

Invalid Boundary Format

Check:

  1. Verify HEC-RAS interval code (15MIN, 1HOUR, etc.)
  2. Use validate_boundary_format() to check format
  3. Review fixed-width format requirements

See: examples/913_bc_*.ipynb for boundary generation debugging

Poor Validation Metrics (NSE < 0.5)

Investigate:

  1. Model calibration parameters
  2. Boundary condition accuracy
  3. Gauge location vs model feature match
  4. Timing alignment

See: examples/914_*.ipynb for validation workflow

Dependencies

Required (always available):

  • pandas, geopandas, requests

Optional (lazy-loaded):

  • dataretrieval - USGS NWIS client (recommended)
    • Install: pip install dataretrieval
    • Methods check availability on first use

Check dependencies:

python
from ras_commander.usgs import check_dependencies
deps = check_dependencies()
print(deps)  # {'pandas': True, 'geopandas': True, 'dataretrieval': True/False}

Validation Metric Interpretation

See: ras_commander/usgs/CLAUDE.md → Validation Metrics section for complete details.

Quick reference:

  • NSE (Nash-Sutcliffe): −∞ to 1 (perfect = 1)
    • 0.75: Very good

    • 0.65-0.75: Good
    • 0.50-0.65: Satisfactory
    • < 0.50: Unsatisfactory
  • KGE (Kling-Gupta): −∞ to 1 (perfect = 1)
    • Similar interpretation to NSE
    • Components: correlation, bias ratio, variability ratio

For detailed interpretation: See examples/914_model_validation_with_usgs.ipynb

Key Features

Multi-Level Verifiability

  • Boundary conditions in .u## files reviewable in HEC-RAS GUI
  • Visual outputs for domain expert review
  • Code audit trails with @log_call decorators

USGS Service Compliance

  • Rate limiting (1 req/sec default)
  • Proper parameter codes (00060 = flow, 00065 = stage)
  • Timeout handling and retry logic

Data Quality

  • Automatic gap detection
  • Data availability checks
  • Resampling validation

See: ras_commander/usgs/CLAUDE.md → Key Features for details

Cross-References

Rules (follow these):

  • .claude/rules/hec-ras/usgs.md -- USGS domain overview and gauge workflows
  • .claude/rules/hec-ras/dss-files.md -- Read when generating DSS from gauge data

Agents (delegate when needed):

  • usgs-integrator -- Delegate for complex multi-step USGS workflows

Skills (related workflows):

  • dss_read_boundary-data -- Use when working with DSS boundary conditions
  • hecras_compute_plans -- Use downstream after generating boundary conditions

Primary sources:

  • ras_commander/usgs/CLAUDE.md -- Complete USGS module documentation

Skill Development Philosophy

This skill is intentionally lightweight (~300 lines) and serves as a navigator to authoritative sources rather than duplicating content.

When to use this skill:

  • You need quick navigation to USGS integration resources
  • You want to know which module handles which task
  • You need a starting point for USGS workflows

When to read full docs:

  • You need complete workflow details -- Read ras_commander/usgs/CLAUDE.md
  • You need working code examples -- Open example notebooks
  • You need parameter documentation -- Read code docstrings