OCSMesh
OCSMesh is a Python package for processing DEM data into georeferenced unstructured meshes using different meshing engine libraries (Gmsh, Triangle). It builds the domain geometry and the mesh size function from any number of DEM tiles, applies refinements (contours, channels, depth bands, flow limiters, patches, line features) and constraints, and runs the mesh engine. Size functions can be computed serially, on all cores of a node or with MPI across nodes.
Documentation: https://noaa-ocs-modeling.github.io/OCSMesh/
Installation
Two ways of installing OCSMesh are described below:
Using conda
The recommended way to setup the environment for installing OCSMesh is to
use conda
with the environment.yml file provided in the repo to install
required libraries.
You need to make sure you’ve installed the mesh engine you’d like to use (e.g., Triangle or Gmsh).
First you need to download the environment.yml file.
wget https://raw.githubusercontent.com/noaa-ocs-modeling/OCSMesh/main/environment.yml
conda env create -f environment.yml -n your-env-name
conda activate your-env-name
pip install ocsmesh
From GitHub repo
You need to make sure you’ve installed the mesh engine you’d like to use (e.g., Triangle or Gmsh).
OCSMesh can be installed from the GitHub repository as follows:
git clone https://github.com/noaa-ocs-modeling/ocsmesh
cd ocsmesh
pip install .[all]
MPI (optional)
MPI execution needs mpi4py built against the MPI library of your
machine. environment.yml installs it from conda-forge; on an HPC
system, prefer the system MPI (e.g. module load the MPI, then
pip install --no-binary mpi4py mpi4py), or pip install ocsmesh[mpi].
Requirements
3.10 <= Python < 3.14
CMake
C/C++ compilers
Quick start
import ocsmesh
dems = ["tile_1.tif", "tile_2.tif"] # later inputs take priority
domain = ocsmesh.Geom(dems, zmax=10) # everything below 10 m
hfun = ocsmesh.Hfun(dems, hmin=50, hmax=3000, method="exact",
nprocs=8, execution_mode="parallel")
hfun.add_contour(level=0, expansion_rate=0.01, target_size=100)
hfun.add_constant_value(value=500, lower_bound=-20, upper_bound=0)
mesh = ocsmesh.MeshDriver(domain, hfun, engine_name="gmsh").run()
mesh.write("mesh.2dm", format="2dm", overwrite=True)
Execution modes
|
runs on |
use it for |
|---|---|---|
|
this process |
small domains, debugging |
|
a pool of |
a workstation or one HPC node |
|
MPI ranks under |
many tiles, several nodes |
All modes give the same size function. With MPI every rank runs the
script and calls hfun.meshdata(); the result is returned on rank 0.
Temporary files go to $TMPDIR, which must be on a shared filesystem
for multi-node runs. See
Parallel and MPI execution
for details.
Contributing
Bug reports and pull requests are welcome; see CONTRIBUTING.md. Changes are listed in CHANGELOG.md.
How to Cite
Title : OCSMesh and an automated creek-to-ocean mesh generation workflow
Personal Author(s) : Cassalho, Felicio;Mani, Soroosh;Moghimi, Saeed;Ye, Fei;Zhang, Y. Joseph;
Journal: Ocean Modelling
Published Date : August 2026
DOI : http://dx.doi.org/10.1016/j.ocemod.2026.102774
Title : OCSMesh: a data-driven automated unstructured mesh generation software for coastal ocean modeling
Personal Author(s) : Mani, Soroosh;Calzada, Jaime R.;Moghimi, Saeed;Zhang, Y. Joseph;Myers, Edward;Pe’eri, Shachak;
Corporate Authors(s) : Coast Survey Development Laboratory (U.S.)
Published Date : 2021
Series : NOAA Technical Memorandum NOS CS ; 47
DOI : https://doi.org/10.25923/csba-m072
Disclaimer
This repository is a scientific product and is not official communication of the National Oceanic and Atmospheric Administration, or the United States Department of Commerce. All NOAA GitHub project code is provided on an “as is” basis and the user assumes responsibility for its use. Any claims against the Department of Commerce or Department of Commerce bureaus stemming from the use of this GitHub project will be governed by all applicable Federal law. Any reference to specific commercial products, processes, or services by service mark, trademark, manufacturer, or otherwise, does not constitute or imply their endorsement, recommendation or favoring by the Department of Commerce. The Department of Commerce seal and logo, or the seal and logo of a DOC bureau, shall not be used in any manner to imply endorsement of any commercial product or activity by DOC or the United States Government.
- Domain definition
- Mesh size definition
HfunHfunRasterHfunRaster.meshdata()HfunRaster.refine_on()HfunRaster.apply_added_constraints()HfunRaster.apply_constraints()HfunRaster.get_xy_memcache()HfunRaster.rasterHfunRaster.hminHfunRaster.hmaxHfunRaster.verbosityHfunRaster.add_band()HfunRaster.adjust()HfunRaster.average_filter()HfunRaster.bboxHfunRaster.chunk_sizeHfunRaster.clip()HfunRaster.close()HfunRaster.contourf()HfunRaster.countHfunRaster.crsHfunRaster.dtype()HfunRaster.dtypesHfunRaster.dxHfunRaster.dyHfunRaster.fill_nodata()HfunRaster.gaussian_filter()HfunRaster.generic_filter()HfunRaster.get_bbox()HfunRaster.get_channels()HfunRaster.get_contour()HfunRaster.get_multipolygon()HfunRaster.get_values()HfunRaster.get_window_bounds()HfunRaster.get_window_data()HfunRaster.get_window_transform()HfunRaster.get_x()HfunRaster.get_xy()HfunRaster.get_xyz()HfunRaster.get_y()HfunRaster.heightHfunRaster.is_maskedHfunRaster.iter_windows()HfunRaster.mask()HfunRaster.md5HfunRaster.modifying_raster()HfunRaster.msh_t()HfunRaster.nodataval()HfunRaster.overlapHfunRaster.pathHfunRaster.pixel_size_m()HfunRaster.read()HfunRaster.read_masks()HfunRaster.resample()HfunRaster.resampling_methodHfunRaster.sample()HfunRaster.save()HfunRaster.shapeHfunRaster.srcHfunRaster.tags()HfunRaster.tmpfileHfunRaster.transformHfunRaster.valuesHfunRaster.warp()HfunRaster.widthHfunRaster.xHfunRaster.xresHfunRaster.yHfunRaster.yres
HfunMeshHfunCollectorHfunCollector.meshdata()HfunCollector.add_topo_bound_constraint()HfunCollector.add_topo_func_constraint()HfunCollector.add_courant_num_constraint()HfunCollector.add_region_constraint()HfunCollector.add_contour()HfunCollector.add_channel()HfunCollector.add_subtidal_flow_limiter()HfunCollector.add_constant_value()HfunCollector.add_patch()HfunCollector.add_feature()HfunCollector.execution_modeHfunCollector.msh_t()
- Parallel and MPI execution
- DEM resampling
- Splitting channel and contour detection
- Mesh representation
MeshEuclideanMesh2DEuclideanMesh2D.get_bbox()EuclideanMesh2D.boundariesEuclideanMesh2D.tricontourf()EuclideanMesh2D.interpolate()EuclideanMesh2D.get_contour()EuclideanMesh2D.get_multipolygon()EuclideanMesh2D.vert2EuclideanMesh2D.valueEuclideanMesh2D.bboxEuclideanMesh2D.coordEuclideanMesh2D.crsEuclideanMesh2D.elementsEuclideanMesh2D.hullEuclideanMesh2D.meshdataEuclideanMesh2D.nodesEuclideanMesh2D.quadsEuclideanMesh2D.trianglesEuclideanMesh2D.write()
- Utility classes and functions
RasterRaster.modifying_raster()Raster.get_x()Raster.get_y()Raster.get_xy()Raster.get_values()Raster.get_xyz()Raster.get_multipolygon()Raster.get_bbox()Raster.contourf()Raster.tags()Raster.read()Raster.dtype()Raster.nodataval()Raster.sample()Raster.close()Raster.add_band()Raster.fill_nodata()Raster.gaussian_filter()Raster.average_filter()Raster.generic_filter()Raster.mask()Raster.read_masks()Raster.warp()Raster.resample()Raster.pixel_size_m()Raster.save()Raster.clip()Raster.adjust()Raster.get_contour()Raster.get_channels()Raster.iter_windows()Raster.get_window_data()Raster.get_window_bounds()Raster.get_window_transform()Raster.xRaster.yRaster.valuesRaster.pathRaster.tmpfileRaster.md5Raster.countRaster.is_maskedRaster.shapeRaster.heightRaster.bboxRaster.srcRaster.widthRaster.dxRaster.dyRaster.crsRaster.transformRaster.dtypesRaster.xresRaster.yresRaster.resampling_methodRaster.chunk_sizeRaster.overlap
mesh_to_tri()cleanup_isolates()cleanup_duplicates()cleanup_folded_bound_el()geom_to_multipolygon()get_boundary_segments()get_mesh_polygons()repartition_features()transform_linestring()needs_sieve()finalize_mesh()sieve()sort_edges()index_ring_collection()outer_ring_collection()inner_ring_collection()get_multipolygon_from_pathplot()signed_polygon_area()vertices_around_vertex()get_surrounding_elem_verts()get_lone_element_verts()get_verts_in_shape()select_adjacent()get_incident_edges()get_cross_edges()clip_mesh_by_shape()remove_mesh_by_edge()clip_mesh_by_vertex()get_mesh_edges()calculate_tria_areas()calculate_edge_lengths()get_boundary_edges()get_pinched_nodes()has_pinched_nodes()cleanup_pinched_nodes()interpolate()interpolate_euclidean_mesh_to_euclidean_mesh()tricontourf()triplot()reproject()msh_t_to_grd()meshdata_to_grd()grd_to_msh_t()grd_to_meshdata()msh_t_to_2dm()meshdata_to_2dm()sms2dm_to_msh_t()sms2dm_to_meshdata()msh_t_to_utm()project_to_utm()estimate_bounds_utm()estimate_mesh_utm()channel_min_area()get_polygon_channels()merge_msh_t()merge_meshdata()run_starmap()effective_cpu_count()add_pool_args()drop_extra_vertex_from_line()drop_extra_vertex_from_polygon()remove_holes()remove_holes_by_relative_size()get_element_size_courant()can_velocity_be_approximated_by_linear_wave_theory()estimate_particle_velocity_from_depth()approximate_courant_number_for_depth()create_rectangle_mesh()raster_from_numpy()msht_from_numpy()clip_elements_by_index()check_resample_factor()resample_geom_by_hfun()calc_el_angles()cleanup_skewed_el()cleanup_concave_quads()order_mesh()quads_from_tri()clip_elevation()
- Command line interface