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:

str

clear_data()[source]

clear the data

init_data()[source]

Initialize the data

modify_ManningsN(materialIDs, newManningsNValues, materialNames)[source]

Modify materialIDs’s Manning’s n values to new values

Parameters:
  • materialID (int) – material ID

  • newManningsNValue (float) – new Manning’s n value

  • materialName (str) – name of the material

reset_data()[source]

Reset the data

class HydraulicModel(name, version)[source]

Hydraulic model base class

name

name of the hydraulic model, e.g., SRH-2D, HEC-RAS

Type:

str

version

version of the hydaulic model, e.g., 3.3, 5.0.7, 6.0

Type:

str

exit_model()[source]

Exit the model

init_model()[source]

Initialize the model

run_model()[source]

Run the model

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(RASPlanResultFileName, TerrainFileName, SRHCaseName)[source]

A Python class to convert HEC-RAS case, mainly mesh and material (Manning’s n), to SRH-2D case

Typical work flow is as follows: 1. create 2D case in HEC-RAS 2. call RAS to SRH converter: create srhgeom and srhmat files 3. manually create and adjust srhhydro file 4. run SRH-2D

RASPlanResultFileName

HEC-RAS result from a plan, such as caseName.p01.hdf

Type:

str

SRHCaseName

Case name for SRH-2D; the resulted files will be SRHCaseName.srhgeom, SRHCaseName.srhmat

Type:

str

convert_to_SRH()[source]

Convert the case to SRH

class Terrain(name)[source]

A Python class for terrain data I/O, creation, and manipulation

Typical work flow is as follows:

  1. create the Terrain object

  2. 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(…)

  3. set the georeferencing by calling set_georeference(…)

  4. save the terrain to file by calling save_terrain_to_file(…)

name

name of the terrain

Type:

str

elevation

elevation of the terrain (2D numpy array)

Type:

numpy.ndarray

geoTopLeft_x

raster’s top-left corner georeferenced x-coordinate

Type:

float

geoTopLeft_y

raster’s top-left corner georeferenced y-coordinate

Type:

float

pixel_width

pixel width (in x), i.e, each pixel is how many meters/feet wide?

Type:

float

pixel_height

pixel height (in y), i.e, each pixel is how many meters/feet high?

Type:

float

EPSGCode

EPSG (European Petroleum Survey Group) code that defines the coordinate reference system

Type:

int

geoTransform

affine transform for the raster image from image pixel to real coordinates

Type:

list

supportedGDALDrivers

list of supported GDAL drivers (short names only)

Type:

list

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:
  • channel_lenx (float) – channel length in x

  • channel_leny (float) – channel length in y

  • L1 (float) – flood plain’s width on one side (the other side can be calculated)

  • B (float) – main channel bottom width

  • D (float) – main channel depth

  • alpha (float) – main channel’s side slope angle (in degrees)

build_supported_GDAL_drivers_list()[source]

Build the list of supported GDAL drivers list

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

get_terrain_name()[source]

Get the terrain name

Returns:

name – name of the terrain

Return type:

str

save_terrain_to_file(terrainFileName, geoDriverName='GTiff')[source]

save terrain to file, such as GeoTiff

Parameters:
  • terrainFileName (str) – file name for the saved terrain

  • geoDriverName (str) – GDAL raster driver names, such as ‘GTiff’

set_elevation(elevation)[source]

Set the elevation array

Parameters:

elevation (numpy.ndarray) – elevation 2D array

set_georeference(geoTopLeft_x, geoTopLeft_y, EPSGCode)[source]

Set the georeferencing information

Parameters:
  • geoTopLeft_x (float) – raster’s top-left corner georeferenced x location

  • geoTopLeft_y (float) – raster’s top-left corner georeferenced y location

  • EPSGCode (int) – EPSG (European Petroleum Survey Group) code that defines the coordinate reference system

set_pixel_size(pixel_width, pixel_height)[source]

Set the pixel size in x and y directions

Parameters:
  • pixel_width (float) – the width of each pixel in real world

  • pixel_height (float) – the height of each pixel in real world

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)