pyHMT2D API

pyHMT2D base classes, constants, and tools

class HydraulicData(name)

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()

clear the data

init_data()

Initialize the data

modify_ManningsN(materialID, newManningsNValue, materialName)

Modify materialID’s Manning’s n value to new value

Parameters
  • materialID (int) – material ID

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

  • materialName (str) – name of the material

reset_data()

Reset the data

class HydraulicModel(name, version)

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()

Exit the model

init_model()

Initialize the model

run_model()

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, RASTerrainGeoTiffFileName, 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

RASTerrainGeoTiffFileName

HEC-RAS Terrain’s GeoTiff file name

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

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