xiaohongshu
xiaohongshu
executing-hecras-rascontrol
Executes HEC-RAS plans using RasControl class via HECRASController COM interface for legacy HEC-RAS versions (3.x-5.x). Handles COM lifecycle management, session tracking, orphan cleanup, steady/unsteady result extraction, and watchdog protection for Jupyter notebooks. Use when automating legacy ...
Full skill instructions
This skill helps you automate HEC-RAS versions 3.x-5.x using the RasControl class, which wraps the HECRASController COM interface with ras-commander conventions.
Location: ras_commander/RasControl.py
Key sections:
RasControl class with version mapping and output variable codes_com_open_close())run_plan() with smart skip and watchdog protectionget_steady_results() - extract steady state profilesget_unsteady_results() - extract time series with Max WSexamples/120_automating_ras_with_win32com.ipynb - Low-level win32com explorationexamples/121_legacy_hecrascontroller_and_rascontrol.ipynb - Complete RasControl workflows.claude/rules/hec-ras/execution.md - Execution mode comparisonras_commander/CLAUDE.md - Library context and module organization| Scenario | Use RasControl | Use RasCmdr |
|---|---|---|
| HEC-RAS 3.x-5.x | Yes | No |
| HEC-RAS 6.x+ | No (use COM only if needed) | Yes (preferred) |
| Need GUI interaction | Yes (COM opens GUI) | No (headless) |
| Version comparison | Yes | Yes |
| Production workflows | Limited | Preferred |
| Parallel execution | No (single-threaded) | Yes |
from ras_commander import init_ras_project, RasControl
# Initialize project with version
init_ras_project(project_path, "5.0.6") # Or "506", "4.1", "41", etc.
# Run plan (checks if current, skips if up-to-date)
success, msgs = RasControl.run_plan("02")
# Force recomputation
success, msgs = RasControl.run_plan("02", force_recompute=True)
# Extract steady state results
df_steady = RasControl.get_steady_results("02")
# Extract unsteady time series (includes Max WS row)
df_unsteady = RasControl.get_unsteady_results("01")
RasControl accepts flexible version formats:
# All equivalent - HEC-RAS 4.1
init_ras_project(path, "4.1")
init_ras_project(path, "41")
# All equivalent - HEC-RAS 5.0.6
init_ras_project(path, "5.0.6")
init_ras_project(path, "506")
# All equivalent - HEC-RAS 6.6
init_ras_project(path, "6.6")
init_ras_project(path, "66")
Supported versions: 3.0-3.1.3, 4.0-4.1, 5.0-5.0.7, 6.0-6.7
# Max WS contains computational maximums (critical for design!)
df_maxws = df_unsteady[df_unsteady['time_string'] == 'Max WS']
df_timeseries = df_unsteady[df_unsteady['datetime'].notna()]
# Plot time series with Max WS reference line
import matplotlib.pyplot as plt
xs_data = df_timeseries[df_timeseries['node_id'] == '10000']
plt.plot(xs_data['datetime'], xs_data['wsel'])
plt.axhline(df_maxws[df_maxws['node_id'] == '10000']['wsel'].iloc[0],
color='r', linestyle='--', label='Max WS')
RasControl handles COM lifecycle automatically via _com_open_close():
# Internal pattern (you don't call this directly)
# 1. Create COM object: win32com.client.Dispatch("RAS66.HECRASController")
# 2. Open project: com_rc.Project_Open(project_path)
# 3. Create session lock for crash recovery
# 4. Execute operation
# 5. Close HEC-RAS: com_rc.QuitRas()
# 6. Clean up session tracking
Why this matters:
RasControl tracks all active COM sessions:
# List tracked processes
df = RasControl.list_processes()
print(df) # Shows PID, tracked status, project, age
# List all ras.exe (including untracked)
df_all = RasControl.list_processes(show_all=True)
After crashes or Jupyter kernel restarts:
# Scan for orphaned processes
orphans = RasControl.scan_orphans()
if orphans:
print(f"Found {len(orphans)} orphaned processes")
# Interactive cleanup (prompts for confirmation)
RasControl.cleanup_orphans()
# Automatic cleanup (no prompts)
count = RasControl.cleanup_orphans(interactive=False)
# Dry run (see what would be cleaned)
RasControl.cleanup_orphans(dry_run=True)
# Nuclear option - kill ALL ras.exe (requires "YES" confirmation)
RasControl.force_cleanup_all()
For long-running operations in Jupyter:
# With watchdog (default) - survives kernel restarts
success, msgs = RasControl.run_plan("01", use_watchdog=True, max_runtime=3600)
# Without watchdog (not recommended in Jupyter)
success, msgs = RasControl.run_plan("01", use_watchdog=False)
Watchdog features:
df = RasControl.get_steady_results("02")
# DataFrame columns:
# - river, reach, node_id (location)
# - profile (profile name)
# - wsel (water surface elevation)
# - velocity, flow, froude, energy, max_depth, min_ch_el
df = RasControl.get_unsteady_results("01")
# DataFrame columns:
# - river, reach, node_id (location)
# - time_index (1 = Max WS, 2+ = timesteps)
# - time_string ("Max WS" or "18FEB1999 0000")
# - datetime (datetime64[ns], NaT for Max WS)
# - wsel, velocity, flow, froude, energy, max_depth, min_ch_el
# Read computation messages (tries .txt then HDF)
msgs = RasControl.get_comp_msgs("01")
print(msgs)
from ras_commander import RasPlan
versions = [("5.0.6", "506"), ("6.3.1", "631"), ("6.6", "66")]
results = {}
for version_name, version_code in versions:
# Clone plan for this version
new_plan = RasPlan.clone_plan("01", new_shortid=f"v{version_code}")
# Run with this version
init_ras_project(project_path, version_name)
RasControl.run_plan(new_plan, force_recompute=True)
# Extract results
results[version_name] = RasControl.get_unsteady_results(new_plan)
# Compare across versions
for version, df in results.items():
max_wse = df[df['time_string'] == 'Max WS']['wsel'].max()
print(f"v{version}: Max WSE = {max_wse:.2f} ft")
try:
success, msgs = RasControl.run_plan("01")
except Exception as e:
print(f"COM error: {e}")
# Clean up any orphaned processes
RasControl.cleanup_orphans(interactive=False)
# Read computation messages for diagnosis
comp_msgs = RasControl.get_comp_msgs("01")
print(f"Computation messages:\n{comp_msgs}")
# Check if results are current before running
success, msgs = RasControl.run_plan("01")
if "Results are current" in msgs[0]:
print("Skipped - results already up-to-date")
else:
print("Plan executed")
# Extract results (works whether run or skipped)
df = RasControl.get_unsteady_results("01")
# Error: "COM object not found" or "Class not registered"
# Verify HEC-RAS COM registration
import win32com.client
try:
rc = win32com.client.Dispatch("RAS66.HECRASController")
print("COM registered correctly")
except Exception as e:
print(f"COM issue: {e}")
print("Solution: Reinstall HEC-RAS or run as Administrator")
# Check for orphaned processes
RasControl.list_processes(show_all=True)
# Clean up orphans
RasControl.cleanup_orphans()
# If still stuck, nuclear option (kills ALL ras.exe)
RasControl.force_cleanup_all()
# If get_steady_results() or get_unsteady_results() fails:
# 1. Check if plan was executed
success, msgs = RasControl.run_plan("01", force_recompute=True)
# 2. Check computation messages
comp_msgs = RasControl.get_comp_msgs("01")
print(comp_msgs)
# 3. Look for "error" or "warning" in messages
if "error" in comp_msgs.lower():
print("Computation had errors - fix model issues")
# Error: Version 'X.Y' not supported
# Check supported versions
print(RasControl.VERSION_MAP.keys())
# Use normalized format
init_ras_project(path, "5.0.6") # Not "5.06" or "5.6"
max_times parameter to limit extraction:
df = RasControl.get_unsteady_results("01", max_times=20)
When upgrading to HEC-RAS 6.x+:
# Legacy (RasControl - HEC-RAS 5.x)
init_ras_project(path, "5.0.6")
RasControl.run_plan("01")
df = RasControl.get_steady_results("01")
# Modern (RasCmdr - HEC-RAS 6.x)
from ras_commander import RasCmdr
from ras_commander.hdf import HdfResultsPlan
init_ras_project(path, "6.6")
RasCmdr.compute_plan("01")
hdf = HdfResultsPlan(ras.plan_df.loc[0, 'HDF_Results_Path'])
wse = hdf.get_steady_wse()
.claude/rules/hec-ras/execution.md - Execution mode comparison.claude/rules/python/static-classes.md - Static class patternRemember: RasControl is for legacy HEC-RAS (3.x-5.x). For HEC-RAS 6.x+, prefer RasCmdr and HDF-based methods for better performance and reliability.
xiaohongshu
technical spec
product ux expert
database patterns
Conduct multi-agent task orchestration and workflow coordination.
Initialize project with Conductor artifacts (product definition,
Expert in web animations, transitions, and motion design using Framer Motion and CSS
Creates Mermaid and ASCII diagrams for flowcharts, architecture, ERDs, state machines, mindmaps, and more. Use when user mentions diagram, flowchart, mermaid, ASCII diagram, text diagram, terminal diagram, visualize, C4, mindmap, architecture diagram, sequence diagram, ERD, or needs visual docume...
PostgreSQL bindings for H3 hexagonal grid system. Use when working with H3 cells in Postgres, including spatial indexing, geometry/geography integration, and raster analysis.
Context-Driven Development skill for projects using Conductor. Use this skill when you detect a `conductor/` directory in the project, when working on tasks defined in a `plan.md` file, or when the user asks about tracks, specs, or plans. Automatically applies TDD workflow, tracks task completion...
Display project status, active tracks, and next actions
Official Stakpak application containerization standard operating procedure, a step-by-step guidline to properly dockerize applications. This is a rule book curated by the Stakpak Team.
Generate, edit, and beat-sync AI video with leading models in one workspace.
The world's fastest calendar for remote work
Transform Your Design with AI Designer by ImgCreator.ai
Revolutionizing Video Production with AI-Powered Creativity
Extend an image past the frame and let AI fill the new aspect ratio.
Discover your celebrity doppelgänger with StarByFace!
ChainClarity explains 700+ crypto whitepapers in plain English, with layered summaries, comparisons, research tools, alerts, and a $4.99 Pro plan.
Opus.ai: Revolutionize Your Web Experience