pyHMT2D API
pyHMT2D base classes, constants, and tools
- class HydraulicData(name)[source]
Hydraulic data base class
- name
name of the hydraulic mode that this data is for, e.g., SRH-2D, HEC-RAS, or just the name of the data set, e.g., terrain, flow
- Type:
- gMax_Nodes_per_Element
maximum number of nodes for an element
- gMax_Elements_per_Node
maximum number of elements for a node
Miscellaneous classes and tools
Package summary for Misc:
- class RAS_to_SRH_Converter(prj_file, plan_id_or_name, srh_case_name, twoDAreaNumber=0)[source]
Converts a HEC-RAS 2D plan result to SRH-2D input format.
For cases with multiple 2D areas, specify which area to convert via twoDAreaNumber (default: 0, the first area).
- Parameters:
prj_file (str) – Path to the HEC-RAS project file (.prj).
plan_id_or_name (str) – Plan short ID (e.g. ‘p03’) or plan title to convert.
srh_case_name (str) – Base name for the output SRH-2D files (.srhgeom, .srhmat).
twoDAreaNumber (int, optional) – Index of the 2D area to convert (default 0, i.e. first area). For single-area cases this should always be 0.
- class Terrain(name)[source]
A Python class for terrain data I/O, creation, and manipulation
Typical work flow is as follows:
create the Terrain object
create the terrain (elevation, pixel_width/height): user can either call some pre-defined terrains such as constant slope, or create the terrain by themsleves and then call set_terrain(…), and set_pixel_size(…)
set the georeferencing by calling set_georeference(…)
save the terrain to file by calling save_terrain_to_file(…)
- elevation
elevation of the terrain (2D numpy array)
- Type:
numpy.ndarray
- EPSGCode
EPSG (European Petroleum Survey Group) code that defines the coordinate reference system
- Type:
Terrain class constructor
- Parameters:
name (str) – name of the terrain
- add_bedform(channel_lenx, channel_leny, Lb, Hb, alpha_lee, a_stoss, rotation=0, perturbation=0, perturb_distribution=0)[source]
Add bedform feature to the terrain
Typical use scenario is firstly to create a constant slope channel and then add the bedform features.
- Parameters:
channel_lenx (float) – channel length in x
channel_leny (float) – channel length in y
Lb (float) – bed form length
Hb (float) – bed form height
alpha_lee (float) – bed-form’s lee side slope angle (in degrees)
a_stoss (float) – bed-form’s stoss size sine function amplitude
rotation (float) – optional rotation angle of the domain in degrees (default is zero)
perturbation (float) – optional perturbation added to the terrain (default is zero)
perturb_distribution (integer) – optional perturbation distribution type: 0-uniform, 1-normal (mean=0, sd=perturbation/1.96)
- add_composite_channel(channel_lenx, channel_leny, L1, B, D, alpha)[source]
Add composite channel to the terrain
Typical use scenario is firstly to create a constant slope channel and then add the composite channel.
- Parameters:
- create_constant_slope_channel_elevation(slope, channel_lenx, channel_leny, pixel_width, pixel_height, elevation_origin=0, extra_len=0)[source]
Create a constant slope channel elevation
The slope is in the x direction only. The slope in the y direction is zero.
- Parameters:
slope (float) – slope in x
channel_lenx (float) – channel length in x
channel_leny (float) – channel length in y
elevation_origin (float) – the elevation at the origin (top left; does not account for the extra fringe)
extra_len (float) – optional extra fringe length added to the channel domain (to have some free room in developing 2D models in e.g., SMS or HEC-RAS.
- get_elevation()[source]
Get the elevation array
- Returns:
elevation – elevation 2D array
- Return type:
numpy.array
- save_terrain_to_file(terrainFileName, geoDriverName='GTiff')[source]
save terrain to file, such as GeoTiff
- set_elevation(elevation)[source]
Set the elevation array
- Parameters:
elevation (numpy.ndarray) – elevation 2D array
- gmsh2d_to_srh(gmsh2d_fileName, srh_caseName, shift_x=0.0, shift_y=0.0, units='Meters', bAddMonitoringLines=False, monitoringLines=[], monitoringlineTol=0.001)[source]
Convert Gmsh 2D mesh into SRH-2D format with the option to add monitoring lines.
It generates two files: srhgeom for mesh and srhmat for Manning’s n
The srhhydro file has to be generated separately.
For monitoring lines: SRH-2D treats the monitoring lines similarly as boundaries. Both are nodeStrings in the srhgeom file. However, Gmsh2d does not directly support internal boundary such as the monitoring lines. Thus, for any monitoring line, we need to add it to the nodeStrings list here.
- Parameters:
gmsh2d_fileName (str) – file name of the Gmsh MSH file
srh_caseName (str) – case name for SRH-2D.
shift_x (float) – shift of coordinates in x direction
shift_y (float) – shift of coordinates in y direction
units (str, default Meters) – length units of Gmsh file
bAddMonitoringLines (whether add monitoring lines)
monitoringLines (list of monitoring lines. Currently only straightlines are supported.)
monitoringlineTol (a float tolerance to check whether a node is close to the monitoring line)
AI Tools (MCP Server)
Package summary for AI_Tools:
pyHMT2D AI Tools
A collection of 25 AI-agent-callable tools for automating 2D hydraulic modelling workflows with SRH-2D and HEC-RAS.
Quick start
Python API:
from pyHMT2D.AI_Tools.tools import get_project_info, get_materials, set_manning_n
MCP server (stdio, for Claude Desktop / Claude Code):
python -m pyHMT2D.AI_Tools.mcp_server
Tool groups
- Discoverylist_model_files, get_project_info, get_materials,
get_boundary_conditions, get_result_variables
- Parametersset_manning_n, set_inlet_flow, set_exit_wse,
save_modified_inputs
Execution : run_preprocessing, run_simulation, get_simulation_status
- Resultsread_results, get_value_at_point, get_result_statistics,
get_flood_extent, get_cross_section_profile
Export : export_to_vtk, export_mesh_to_vtk
Calibration : load_observations, evaluate_parameters, run_calibration
Monte Carlo : generate_mc_samples, run_monte_carlo, get_mc_statistics