Meshing: Generation, Diagnostics and Repair¶
GeomMesh authors computation points and invokes the native RASMapper mesh
engine. Import it from ras_commander.geom (also exported at package root).
Use HdfMesh to inspect meshes; use RasCmdr to compute hydraulic plans.
For HEC-RAS 6.6 and later, generate(min_face_length_ratio=...) starts at the
requested positive, finite ratio, then escalates to larger values in the repair
ladder if needed. A successful generation persists the used ratio in geometry
text and the RASMapper workspace. Before 6.6, the mesh constructor does not
accept this ratio.
MeshResult.ok reports mesh authoring success. Validate the saved geometry with
native preprocessing through GeomPreprocessor.run_geometry_preprocessor() or
RasCmdr.compute_plan(force_geompre=True) before accepting it for computation.
Passing an in-memory mesh check at one or several ratios does not establish
native preprocessing success.
| Stage | API | Input → output |
|---|---|---|
| Bootstrap points | generate_computation_points |
Authored perimeter text and spacing -> regular-grid computation points in text; no existing HDF required |
| Explicit points | write_computation_points |
Authored perimeter text and supplied XY coordinates -> validated native text seed block; no native DLL or existing HDF required |
| Compile geometry | RasCmdr preprocessing | Referencing project/plan and authored geometry -> native compiled HDF workspace |
| Author controls | Breakline/refinement methods | Names, spacing and polygons/flowlines → updated text or compiled-HDF controls, as specified per method |
| Check domain | audit_domain_containment |
Selected 2D area and cell spacing → DomainContainmentResult |
| Regenerate mesh | generate, generate_all |
Current compiled HDF, domain, breaklines/refinements and spacing -> MeshResult records and updated computation points |
| Build properties | compute_property_tables |
Mesh and terrain/classification associations → native property tables; Boolean result |
| Check boundary conflicts | detect_bc_conflicts, fix_bc_conflicts |
Compiled perimeter faces and BC lines → conflicts or BCFixResult. fix_bc_conflicts reads and writes only the old per-area Geometry/2D Flow Areas/<area>/BC Lines layout, so on HEC-RAS 6.x/7.x geometry HDFs (Geometry/Boundary Condition Lines) it finds no conflicts and changes nothing; use detect_bc_conflicts for detection |
write_computation_points preserves UTF-8 or legacy CP1252 encoding, including
non-ASCII area names. Undecodable text is refused before backup or replacement.
Unrelated record contents are preserved; model writes use CRLF line endings.
flowchart LR
A[Geometry text and spatial inputs] --> S[Bootstrap points if no mesh exists]
S --> B[Native geometry preprocessing]
B --> C[Author and audit mesh controls]
C --> D[Generate computation points and mesh]
D --> E[Review repairs and associations]
E --> F[Build property tables]
F --> G[Prepare and compute hydraulic plan]
generate_computation_points() creates a breakline-unaware regular grid from
the authored perimeter. HEC-RAS preprocessing then builds the full mesh.
GeomMesh.compile_geometry() is a disabled compatibility shim and never
returns successfully; it is documented below only for compatibility.
RASMapper completion of an existing HDF is not text-to-HDF compilation.
Retain an exact subset of parent cells¶
Use GeomMesh.plan_cell_subset() when a child domain is the union of explicit
physical parent cells and must retain their faces and vertices. The parent must
be a geometry-only HDF with complete native topology; a plan/results HDF is
rejected. Prepare an owned child text/HDF pair with one matching area, consistent
CRS, and the selected union as its perimeter. Cell IDs are zero-based physical
IDs from HdfMesh; ghost cells, duplicate IDs, holes, disconnected components,
and boundary pinch points are rejected. The API never expands the selection.
Native completion can stamp the owned geometry target HEC-RAS Results.
Planning accepts that target only if its sole root group is Geometry.
The parent source follows the same rule: HEC-RAS Geometry, or a natively
compiled HEC-RAS Results stamp whose sole root group is Geometry. Plan HDFs
and any file holding result data are rejected.
from ras_commander.geom import GeomMesh, GeomPreprocessor
from ras_commander import RasPreprocess
subset = GeomMesh.plan_cell_subset(
"source/Model.g01.hdf", "review-copy/Model.g02",
parent_cell_ids=selected_ids, mesh_name="Area",
)
review_record = subset.to_dict() # ras-mesh-cell-subset/v1; no writes
# Review the IDs, source hashes, CRS and counts before applying.
# review_project is initialized for the owned copy and selected HEC-RAS 6.6;
# plan 08 references g02. Reuse that exact runtime for both native phases.
written = GeomMesh.apply_cell_subset(subset, ras_object=review_project)
assert written.ok and written.operation == "cell_subset"
geometry = GeomPreprocessor.run_geometry_preprocessor(
"08", ras_object=review_project, require_complete_products=True,
)
assert geometry.success
assert GeomMesh.validate_cell_subset(subset)["topology_exact"]
event = RasPreprocess.preprocess_plan(
"08", ras_object=review_project, clear_existing=True,
)
assert event.success
assert GeomMesh.validate_cell_subset(subset)["topology_exact"]
Planning binds source HDF, child text and child HDF hashes. Applying refuses stale inputs, preserves physical cell coordinates and face polylines, reindexes native incidence tables, and creates one ghost cell per new perimeter face. HEC-RAS 6.6 or 6.4.1 serializes the mesh in an isolated worker. The text perimeter is written from the exact native ring with the existing 16-character formatter. Completion checks can bind the full-precision ring only when that formatter reproduces the authored polygon exactly; the bound ring must remain unchanged and all mesh segments must remain inside it. This adds no containment tolerance.
With ras_object, application uses that project's exact ras_exe_path.
An optional hecras_dir must identify the same installation; conflicting paths
are rejected. Without an explicit project, the active global project's runtime
is retained. The declared hecras_version="6.6" is discovered only when neither
project selects a runtime. The caller controls serialization timeout in seconds
(default 1800); an expired worker raises RuntimeError and preserves the inputs.
The native worker verifies the selected executable's file version: 6.6, or
exactly 6.4.1 (file version 6.4.0.1; 6.4.0 is refused). 6.4.1 was qualified on
the FEMA eBFE Salt Draw delivery, a 6.4.1 model: a 2,592-cell cut of the
delivered mesh serialized, preprocessed and ran in 6.4.1, and reproduced the
parent's maximum WSE to 0.017 ft at the 95th percentile. Cutting in the model's
own version avoids re-meshing a delivered mesh that a newer version rejects.
Returned
cell_subset.native_serialization records the install directory, executable file
version, executable SHA-256, and RasMapperLib DLL SHA-256.
Native staging resolves associated sidecars against the original geometry folder, retains calibration overrides, then restores the original relative association spelling. Inherited hydraulic property tables are invalidated for fresh native computation. Two unique sibling backups support exception rollback if either file replacement fails. Exclusive access is required: the text/HDF pair is not crash atomic. Restore both backups after an interrupted replacement.
MeshResult.ok here means topology writing completed. Retain the strict geometry
receipt, fresh Event Conditions completion, independent HdfMesh cell/face
readback, boundary attachments, and spatial review before accepting a child for
simulation. The library does not produce an engineering approval or a review map.
For an already planned breakout, pass parent_cell_ids=selected_ids to
RasBreakout2D.prepare_cloned_geometry() with refresh_method="rasexe",
remesh=False, and require_complete_products=True. This applies the exact
subset before the first native completion pass and validates source-bound face
coordinates, endpoints, cell ownership, counts and reciprocal incidence again
after preprocessing. Evidence is retained in
cell_subset.post_preprocess_validation. Native remeshing from the same seeds
and perimeter cannot pass this gate if it changes the exact topology.
It cannot be combined with
computation_points or grid anchoring.
validate_cell_subset() returns ras-mesh-cell-subset-validation/v1 evidence
only on success; failed identity, array, count or incidence checks raise
RuntimeError. Both source and child hashes must remain stable across the read.
Cell vertices may rotate/reverse or change padding only when their edges still
follow the same incident faces. Packed cell/face memberships may reorder when
their sets and orientations remain reciprocal. Face coordinates, endpoints,
cell ownership, polylines, normals/lengths and perimeter flags remain unchanged.
| Validation field | Type | Meaning |
|---|---|---|
schema, status |
string | ras-mesh-cell-subset-validation/v1, pass |
source_sha256 |
string | Immutable planned parent geometry identity |
geometry_hdf_sha256 |
string | Stable child HDF bytes inspected by this validation |
physical_cells, total_cells |
integer | Physical and physical-plus-boundary-ghost counts |
faces, facepoints |
integer | Exact selected face and vertex counts |
topology_exact |
boolean | Always true in returned evidence; failed checks raise |
hydraulic_acceptance |
string | Always not_established |
The opt-in tests/test_mesh_cell_subset_native.py test copies a prepared real
project and checks strict Geometry, Event completion and topology after each
native phase. It skips cleanly without Windows/Wine, HEC-RAS 6.6, pythonnet, or
the explicitly configured RAS_EXACT_SUBSET_NATIVE_CASE fixture.
MeshCellSubsetPlan
dataclass
¶
Read-only plan for copying exact physical cells into an owned geometry.
Coordinates retain the source horizontal CRS and units. The selection is explicit and sorted; it is never expanded, repaired or reseeded. Hashes bind both inputs to application. This plan establishes no native completion or hydraulic acceptance.
Source code in ras_commander/geom/GeomMeshDataclasses.py
to_dict
¶
Return the planned source identities and topology counts.
Source code in ras_commander/geom/GeomMeshDataclasses.py
Diagnose before repairing¶
| Symptom or question | Inspection | Supported next step |
|---|---|---|
| Missing mesh arrays or older HDF layout | HdfMesh.diagnose_mesh_layout() |
Inspect capability status and source paths; preprocess a copy when topology is absent. A recovered perimeter does not supply face connectivity. |
| Omitted or ambiguous cell polygons | HdfMesh.diagnose_mesh_cell_polygons(); get_mesh_cell_polygons(strict=True) |
Review native cell/face IDs. The reader does not repair topology or substitute a convex hull. |
| Breakline or structure outside the domain; invalid refinement polygon | GeomMesh.audit_domain_containment() |
Correct the source controls or perimeter and recompile through ras-commander before regeneration. |
| BC lines near the same perimeter face | GeomMesh.detect_bc_conflicts(); fix_bc_conflicts(dry_run=True) |
Review candidate overlaps; supported repair trims BC endpoints in the copied HDF. detect_bc_conflicts() reads Geometry/Boundary Condition Lines and the ghost-cell perimeter faces HEC-RAS writes; fix_bc_conflicts() still reads per-area BC Lines groups, which HEC-RAS does not write, so it finds nothing to repair in HEC-RAS output. |
| Native generation fails | GeomMesh.generate() result or raised exception |
Review the bounded retry/repair evidence below; persisted perimeter changes have a separate failure contract. |
| Extreme areas, aspect ratios, or face velocities | RasCheck.check_mesh_quality(plan_hdf, geom_hdf) |
Inspect messages and source outputs; these checks do not select an acceptable mesh resolution. |
| Unusual subgrid sampling settings | RasCheck.check_subgrid_sampling(geom_file) |
Review geometry-text settings against terrain resolution and the intended study. |
The BC conflict detector uses a geometric proximity buffer of 0.01 * cell_size.
It is different from HdfMesh.get_mesh_perimeter_faces(), which reads native
BC ownership. Use both when association evidence matters. BC repair prefers a
Normal Depth endpoint, otherwise the longer BC. It writes HDF coordinates in
place, does not create a backup or update geometry text, and does not prove that
native associations or a later preprocessing run will preserve the edit. Keep a
project copy, inspect the trims, and recheck native ownership before use.
RasCheck.check_mesh_quality() currently compares native areas and velocities
with thresholds named in square feet and feet per second, without converting
SI values. It uses bounding-box aspect ratios, aggregates returned cells under
the first mesh name, and catches some reader failures. Its informational
"no issues" result is not proof that every dataset was inspected. Check layout
and polygon completeness first; interpret thresholds in the actual source
units. General connectivity validation is not implemented by this check.
from pathlib import Path
from ras_commander import HdfMesh, GeomMesh
# Existing compiled geometry; inspection does not alter it.
geom_hdf = Path("review-copy/Model.g01.hdf")
layout = HdfMesh.diagnose_mesh_layout(geom_hdf)
polygon_issues = HdfMesh.diagnose_mesh_cell_polygons(geom_hdf)
print(layout)
print(polygon_issues)
# Set spacing from this model's geometry, in project length units.
cell_size = 100.0
conflicts = GeomMesh.detect_bc_conflicts(geom_hdf, cell_size)
preview = GeomMesh.fix_bc_conflicts(geom_hdf, cell_size, dry_run=True)
print(preview.conflicts_found, preview.modified_hdf)
The dry run reports candidates without computing a repair: conflicts_fixed
remains zero, and every detected conflict is placed in unresolvable. Therefore
BCFixResult.ok is false when a dry run finds conflicts. These entries are
unattempted candidates, not evidence that repair is impossible. Inspect
conflicts_found, unresolvable, and modified_hdf explicitly.
Repair and its dry run use a proximity buffer of
max(0.1, 0.01 * cell_size) in project length units. The detection-only method
uses 0.01 * cell_size without that minimum, so the two methods can report
different candidate counts for small cells.
Repair on a project copy¶
The following fragment assumes an initialized review_project for a disposable
copy, a plan referencing geometry 01, and a current compiled HDF. Select the
installed runtime explicitly; these values must come from the actual project.
from ras_commander import GeomMesh
result = GeomMesh.generate(
"01",
ras_object=review_project,
hecras_dir=installed_hecras_directory,
recompile_via_rasexe=True,
)
print(result.status, result.error_message)
print(result.fixes_applied, result.perimeter_repairs)
Review text/HDF changes, geometry associations, diagnostics, and final cell properties before computing a hydraulic plan. A completed mesh is not a hydraulic validation result.
Diagnostic method reference¶
A class for handling mesh-related operations on HEC-RAS HDF files.
This class provides methods to extract and analyze mesh data from HEC-RAS HDF files, including mesh area names, mesh areas, cell polygons, cell points, cell faces, and 2D flow area attributes.
Methods in this class are designed to work with the mesh geometry data stored in HEC-RAS HDF files, providing functionality to retrieve and process various aspects of the 2D flow areas and their associated mesh structures.
Note: This class relies on HdfBase and HdfUtils for some underlying operations.
diagnose_mesh_layout
staticmethod
¶
Inspect mesh-layout capabilities without modifying the HDF.
Parameters¶
hdf_path : Path
Geometry or plan HDF containing the Geometry/2D Flow Areas group.
program_version : str, optional
Program version read from the companion plan or geometry text file.
For example, HEC-RAS 6.2 commonly stores "6.20".
Returns¶
pandas.DataFrame
One row per 2D flow area. Capability status columns use
standard, collection_fallback, not_present,
malformed, or read_error. Dataset-path columns identify the
evidence used for each decision.
Notes¶
Collection-level Cell Info and Cell Points are reported as
evidence only. They are never promoted to face connectivity or cell
polygon topology.
Source code in ras_commander/hdf/HdfMesh.py
| Python | |
|---|---|
561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 | |
diagnose_mesh_cell_polygons
staticmethod
¶
Return cells not reconstructed as exactly one polygon.
The result contains the native mesh_name and zero-based cell_id,
face and polygon counts, a status and reason code, and the referenced
face IDs. boundary_only rows identify validated native one- or
two-face records and do not make strict reconstruction fail. omitted
and ambiguous rows identify physical-cell problems;
not_present and read_error distinguish unavailable or malformed
topology from a clean reconstruction. An empty result means every
named mesh supplied topology and every processed physical cell produced
exactly one polygon.
engine is as in :meth:get_mesh_cell_polygons. engine="auto"
falls back to the reference polygonizer on any native failure, and
whenever the native records cannot be proven equal to the reference's,
so its rows, statuses, reason codes and warnings are the reference
ones. engine="native" (or RAS_COMMANDER_FAST_HDF=native) never
falls back; there the native records can differ from the reference's
as described under diagnostics in :meth:get_mesh_cell_polygons.
Source code in ras_commander/hdf/HdfMesh.py
get_mesh_cell_polygons
staticmethod
¶
get_mesh_cell_polygons(hdf_path: Path, *, strict: bool = False, engine: str = 'auto', threads: Optional[int] = None, diagnostics: bool = False) -> GeoDataFrame
Return 2D flow mesh cell polygons.
Parameters¶
hdf_path : Path
Path to the HEC-RAS geometry HDF file.
strict : bool, default False
Raise :class:MeshCellPolygonError when a native cell produces no
polygon or more than one polygon. The default preserves the legacy
return behavior and emits a warning for omitted cells.
engine : str, default "auto"
"auto": native first, with the Python reference polygonizer on
any native refusal or failure, so results and exceptions are the
reference ones. "h5py": the reference polygonizer only.
"native": native execution or
:class:~ras_commander.fast_hdf.FastHdfError.
threads : int, optional
Maximum threads for native extraction and polygon construction.
diagnostics : bool, default False
Attach anomaly rows to result.attrs["cell_polygon_diagnostics"]
as an equality-safe tuple of record dictionaries. Off by default
(behaviour change from ras-commander 0.106.1, which always attached
them); :meth:diagnose_mesh_cell_polygons returns them as a
DataFrame.
Native and Python diagnostics: with engine="auto" the records
are always the Python reference's (native results are used only
when every record is proven equal, else the Python polygonizer
runs). With engine="native" (or
RAS_COMMANDER_FAST_HDF=native) the native records are returned
as produced and can differ: the engine labels a cell it did not
assemble omitted/no_polygon only when it detected an invalid
ring, otherwise boundary_only/insufficient_faces even if the
cell has three or more faces; it never reports ambiguous/
multiple_polygons, invalid_face_span or
missing_face_reference (the reference polygonizes the faces
and can). The polygons themselves are unaffected.
Returns¶
GeoDataFrame A GeoDataFrame containing the 2D flow mesh cell polygons with columns: - mesh_name: str - Name of the 2D flow area - cell_id: int - Unique cell identifier (0-indexed) - geometry: Polygon - Cell polygon geometry constructed from face edges Returns an empty GeoDataFrame if no 2D areas exist or if there's an error.
Notes¶
Cell IDs are native, zero-based IDs within each mesh. The returned row
index must not be treated as a complete or positional cell identifier.
Use :meth:diagnose_mesh_cell_polygons or strict=True whenever an
exhaustive physical-cell mask is required.
Source code in ras_commander/hdf/HdfMesh.py
get_mesh_perimeter_faces
staticmethod
¶
get_mesh_perimeter_faces(hdf_path: str | Path, mesh_name: str, *, ras_object=None, on_duplicate_ownership: Literal['raise', 'report'] = 'raise') -> GeoDataFrame
Read every perimeter face of a named 2D area, including unassigned faces.
hdf_path accepts geometry/plan HDF paths, open HDF handles, or
project numbers resolved by the standard HDF decorator. ras_object
selects the project used for number resolution. No files are modified.
Returns a GeoDataFrame with mesh_name, face_id, cell0,
cell1, interior_cell_id, exterior_cell_id,
fp_start_index, fp_end_index, face_length, bc_line_id,
bc_line_name, bc_line_type, and geometry. IDs retain their
native zero-based numbering. Exterior cells retain ghost IDs (or -1).
Length is the native Faces NormalUnitVector and Length value in
model units, falling back to complete face geometry length if absent.
BC columns are nullable for confirmed unassigned faces.
on_duplicate_ownership="report" keeps one row per face and adds
duplicate_ownership (bool), owning_bc_line_ids and
owning_bc_line_names (parallel lists in native encounter order).
Duplicate-owned faces have null scalar BC ID, name and type; unassigned
faces have empty owner lists. Repeated native associations are also
marked, even for the same owner. Default "raise" retains strict
validation and the original columns. Other validations remain active.
attrs['duplicate_ownership'] lists duplicate faces and owners for
the requested mesh, with duplicate face and association-row counts.
Physical cells are identified by collection Attributes/Cell Count;
higher cell IDs identify native ghost cells. Surface area and the
sometimes stale Cell Maximum Index attribute are not used.
Faces with one physical cell and one exterior cell form the inventory,
including any mesh interior-hole boundary faces. It does not classify
perimeter rings or infer associations from geometric proximity.
Raises KeyError for an unknown mesh or missing required native tables.
Raises ValueError for malformed topology, duplicate BC ownership,
stale BC face/endpoints, or missing native association evidence when
the selected area has boundary lines. Missing preprocessing is never
reported as confirmed unassigned ownership. Association availability
is also retained in attrs['association_status'].
Source code in ras_commander/hdf/HdfMesh.py
| Python | |
|---|---|
1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 | |
Quality assurance validation for HEC-RAS 6.x models.
Supports both steady flow and unsteady flow plans. Flow type is auto-detected from the plan HDF file.
All methods are static and follow ras-commander conventions. Use @standardize_input decorator for flexible path handling.
This class is a facade that delegates to domain-specific check classes: - CheckUnsteady: Mass balance, computation, peaks, stability, mesh quality - CheckNt: Manning's n values, HTAB parameters - CheckXs: Cross section validation - CheckStructures: Bridge, culvert, inline weir validation - CheckFloodways: Floodway encroachment validation - CheckProfiles: Multiple profile consistency
For full check-result and threshold behavior, see the quality-assurance guide.
Runtime and persisted changes¶
Native mesh generation uses Windows Python, pythonnet and the selected installed
HEC-RAS RasMapperLib.dll. The version matrix and qualification notes
cover 6.0–7.0.1 and the specifically tested Windows-Python-under-Wine setup;
this does not make native Linux Python a supported CLR runtime. Select
hecras_dir explicitly for reproducibility: generate() otherwise discovers
the newest installation, which need not match the project's version. Use a
fresh process when changing the loaded DLL version.
generate() needs a content-current compiled HDF workspace. Its
recompile_via_rasexe=True option refreshes missing/stale HDF through the library's
preprocessor and requires an initialized project with a referencing plan.
Computation points are written into geometry text. Automatic perimeter repairs
can also change text and HDF: work on a disposable project copy and inspect
MeshResult.perimeter_repairs, backups, displacement and area changes.
See the repair contract for failure semantics.
The domain gate checks breaklines and structures against the exact perimeter
buffered inward by one base-cell spacing. Valid refinement regions can touch
or extend beyond the perimeter. strict_refinement_containment=True applies
the earlier inward margin to regions too. BC lines need separate association
and overlap checks.
Property-table success does not prove that intended land-cover assignments were
used: validate associations and inspect final cell properties.
Refinement-region spacing_dy is stored for schema fidelity, not evidence of
independent anisotropic Y refinement. Retain the
release-specific refinement caveats
and flowline-refinement workflow
when designing an authoring workflow. GUI mesh-refresh/import operations are
separate from computation-point generation.
Examples with retained outputs¶
- 230 — mesh sensitivity
- 231 — pipe-network mesh generation
- 232 — Weise sediment mesh sensitivity
These notebooks retain outputs for their demonstrated models and runtimes; they do not qualify every geometry, release or hydraulic configuration.
Repair persistence and failure contract¶
audit_domain_containment(geom_number, mesh_name=..., cell_size=..., ras_object=...)checks the breakline/structure margin and region validity.strict_refinement_containment=Truealso checks region extents against the inward margin. BC lines require a separate audit.generate(geom_number, mesh_name=..., ras_object=...)runs that gate before loading native RAS Mapper dependencies.
When the existing automatic-repair loop removes perimeter vertices or applies
Douglas–Peucker simplification, generate() writes the repaired perimeter through
GeomStorage.set_2d_flow_area_perimeter(create_backup=True), regenerates initial
computation points, and runs GeomPreprocessor.run_geometry_preprocessor() with
geometry_only=True, force=True, and clear_geompre=True. Supply an initialized
ras_object with a plan referencing that geometry. Work on a disposable project
copy: repair changes the geometry text and compiled HDF. The loop reloads the HDF,
checks text/HDF consistency and feature containment, then retries within
max_iterations. recompile_via_rasexe still controls the initial missing/stale
HDF refresh; it is not required for this automatic repair handoff.
MeshResult.perimeter_repairs contains one record per persisted repair: reason,
original_perimeter_hash, repaired_perimeter_hash, max_vertex_displacement,
area_change, and backup_path. SHA-256 hashes cover ordered closed XY rings as
compact JSON floating-point pairs, using actual persisted coordinates after
writer rounding. Displacement is the maximum vertex-to-opposite-boundary distance
in both directions, in project length units; signed area change is repaired minus
original polygon area in squared project units. CRS and units remain those of the
project. Evidence is logged before preprocessing so failures remain traceable.
Failed repair handoffs and retries raise RuntimeError chained to the original
mesh repair reason, including iteration exhaustion. Ordinary failures before any
repair retain the existing MeshResult behavior. These records describe geometry
changes; they do not establish hydraulic acceptance.
compute_property_tables(geom_number, mesh_name=..., ras_object=...)- Compute face profiles, Manning's n assignments, face hydraulic tables, and cell properties against the restored geometry associations. A missing or broken land-cover link emits a non-fatal warning because HEC-RAS may still return success while populating every cell with the 2D area's scalar default.
Before property-table generation, use
RasMap.list_geometry_associations() to inspect every compiled geometry and
RasMap.validate_geometry_associations() to require the exact terrain and
land-cover paths needed by the workflow. Registration in .rasmap does not
prove that a geometry HDF is associated. After preprocessing, validate the
temporary plan HDF; after computation, repeat the check on the final plan HDF
with HdfLandCover.audit_final_mannings_n() and explicit cell-center criteria.
Saved-point compilation and RAS Mapper constraints¶
generate() and generate_all() default to
refinement_region_constraints=False. Breaklines and structures remain
constraints. Refinement regions shape computation-point generation through
native RAS Mapper, including interior spacing, perimeter spacing, near repeats,
far spacing and protection radius. Region edges are excluded from the mesh
used to classify and repair the saved computation points. Set
refinement_region_constraints=True to retain the earlier RAS Mapper mesh
with region-edge constraints.
Qualification with HEC-RAS 6.6 distinguishes a cached RAS Mapper mesh from
a fresh geometry-text point compile. Mapper can retain region-edge constraints
in a compiled HDF; a text-point rebuild can produce different face counts.
An unchanged cache is therefore insufficient evidence of compile agreement.
Point writes refresh Storage Area 2D PointsPerimeterTime, and successful
generation persists the face-length ratio used by the repair loop. Native
region generation can also return points outside a smaller flow area;
generate() removes outside and boundary points before meshing and records
the removal in fixes_applied.
The trimmed 26-point regression has a nine-face cell with breakline constraints
and a seven-face cell with region-edge constraints. The latter reports
Complete; the saved-point mesh reports MaxFacesPerCellExceeded. This
qualification concerns mesh classification in 6.6. Inspect fresh compiled HDF
face counts and native data errors after preprocessing, particularly with
other releases or internal structures.
HEC's HEC-RAS 6.6 Mapper manual, 2D Flow Areas describes the point-generation controls and Mapper's enforcement workflow. The saved-point/cache distinction above comes from RAS Commander qualification.
Optional multi-configuration screening¶
Enable robustness_screening=True in GeomMesh.generate() or
generate_all() to run an additional RAS Commander optimization:
result = GeomMesh.generate(
"02", cell_size=125, min_face_length_ratio=0.0025,
robustness_screening=True, ras_object=ras, hecras_dir=hecras_dir,
)
if not result.ok:
raise RuntimeError(result.error_message)
print(result.robustness_screening)
The default is False, with no extra mesh builds. The option requires a single
2D flow area, known HDF length units and the ratio-aware native constructor
introduced in HEC-RAS 6.6. Screening checks native MeshFV2D.CellFacesCount
at the requested ratio, the successful generation ratio, 0.05 and 0.1
(duplicates removed). Each ratio is checked with:
- breakline and structure constraints;
- breakline, structure and refinement-region boundary constraints;
- no constraints, as a stress case only.
Refinement-generated points remain in all three cases. The unconstrained mesh
is never saved as the production mesh. The saved mesh uses the successful
generation ratio and the caller's refinement_region_constraints setting.
This retains the structure constraints while testing the influence of region
edges separately.
Each round checks the same points in every configuration. Cells with more than
eight faces propose midpoint additions; additions must be distinct and strictly
inside a 0.5 ft (0.1524 m) inward perimeter buffer. All configurations are
rechecked after additions. Screening permits at most max_iterations repair
rounds plus a final check, and at most 50% seed growth. Unsupported states,
unreadable constraints, failed native point generation, unavailable counts or
exhausted budgets fail the
operation before the screened mesh is saved. Ordinary generation may already
have updated spacing or repaired a perimeter; use a project copy as described
above. MeshResult.robustness_screening records checks, counts, additions,
convergence and elapsed time. It is empty when screening is disabled.
This is an independent RAS Commander optimization, not a HEC-RAS preprocessor replica or an HEC-endorsed method. It deliberately has no fallback that reports successful screening after an unresolved check. Run the native preprocessor and inspect its data errors and fresh topology before accepting the mesh.
Qualification used HEC-RAS 6.6 and the public BaldEagleCrkMulti2D geometry 02:
seven breaklines, internal structures Dam and Upper Levee, and an added
500 ft square refinement region with 25 ft spacing. Tests included 100 ft base
spacing and 125 ft base spacing with 12.5 ft near-breakline spacing. Both
structures retained verified attachments and the region retained 400 interior
points after native preprocessing and a one-minute connectivity solve.
A controlled nine-face cell in the finer mesh failed native preprocessing;
midpoint repair cleared all nine screening configurations and passed native
preprocessing. This tests the repair path, not a naturally occurring defect
that appears only at another ratio, and does not establish flood-simulation
accuracy or support for every structure type. The library screening run on the 125 ft case added about 41 seconds for the
clean mesh and 89 seconds for the two-round repair on two CPU cores. These
are single-run timings, not a benchmark; runtime varies with model and hardware.
Carry refinement regions into a child area¶
Prepare the collection from a content-current source HDF, then replace the collection in a disposable child geometry:
regions, report = GeomMesh.clip_refinement_regions(
source_geom,
child_perimeter,
min_area=0.0,
)
GeomMesh.replace_refinement_regions(child_geom, regions)
Coordinates must use the source CRS and project units. The source remains
unchanged. replace_refinement_regions() stages the child HDF update
atomically and makes a backup by default. It retains X/Y spacing, shifts,
perimeter spacing, near repeats, far spacing and protection radius from the
returned mappings. Regenerate points and preprocess the child afterward.
The report has one row per source region: source_fid, name, status,
reason, source_area, retained_area, output_fids, touches_perimeter
and below_one_cell_area. Disconnected intersections become separate regions
with the source name and properties. A line-only intersection is dropped as
no_polygon_overlap. Every positive-area fragment is retained by default;
small regions need not generate an interior grid point. A caller-selected
min_area drops smaller fragments with a recorded reason. Areas use squared
project units.
Invalid source polygons and interior rings raise by default. To retain a
reviewable report while omitting unsupported source regions, pass
invalid_regions="drop" and inspect every dropped row. The replacement writer
rejects holes rather than filling them.
Clipping changes the region extent used as the interior grid origin and adds new perimeter transitions. Preserving spacing and shift fields does not reproduce the full region's original points or transitions exactly. A region that surrounds the child can therefore produce different points when clipped to the child boundary.
Anchor a child's regular grid to its parent¶
RAS Mapper starts a 2D area's regular computation-point grid half a cell inside
the area's own bounding box, at (min x + dx/2, max y - dy/2). The Shift dx
and Shift dy attributes stored with the 2D area are not used by the point
generator (decompiled RasMapperLib 6.5 through 7.0.1). A child area cut from a
parent therefore gets a grid offset from the parent's by a sub-cell vector,
even with the parent's spacing, breaklines and refinement regions.
Pass the parent's lattice point to generate() to keep the parent's grid:
anchor = GeomMesh.get_grid_anchor(parent_geometry_hdf, mesh_name="Parent")
result = GeomMesh.generate("02", mesh_name="Parent", ras_object=child_ras,
grid_anchor=anchor)
print(result.grid_anchor) # anchor, lattice and enforced point counts
get_grid_anchor() reads the stored perimeter and Spacing dx/dy from a
compiled geometry HDF; it uses h5py only. With an anchor, generate() builds
the lattice through the anchor and filters it with RAS Mapper's own perimeter
rules. That lattice replaces the area's points in memory. RAS Mapper's
RegenerateMeshPoints then runs with the area active but not regenerated, the
same call RAS Mapper's breakline and refinement-region editors make. It adds
the refinement-region points and enforces the breaklines on the anchored
lattice. The anchor spacing must equal the mesh cell size, and there is no
unanchored fallback. An (x, y) pair is accepted and takes the cell size as
its spacing. With the area's own anchor, the result equals RAS Mapper's
regeneration exactly.
RasBreakout2D.prepare_cloned_geometry(anchor_grid_to_parent=True) applies the
parent's anchor to the child remesh. Use it with
Breakout2DSpec(max_breakline_perimeter_crossings=2) (recommended; the default
None clips every line). That drops, rather than clips, a source breakline that
weaves across the child's one-cell trim boundary, crossing it more than twice
(reason exceeds_child_perimeter_crossing_limit). Crossings are inside/outside
transitions along the line; running along the boundary is not a crossing. A line
that ends inside or passes straight through is clipped as usual.
The feature notes in feature_dev_notes/Mesh_Grid_Anchor/ record the
evidence and the comparison with a translate-and-restore workaround.
HEC-RAS Version Support for Headless Mesh Generation¶
GeomMesh.generate() and GeomMesh.compute_property_tables() support
HEC-RAS 6.0 through 7.0.1, including the 6.7 betas. They run RASMapper's own
mesh engine (RasMapperLib.dll) from the HEC-RAS installation they load, so
each release produces its own RASMapper result.
| HEC-RAS | Headless mesh generation | Notes |
|---|---|---|
| 6.6, 6.7 Beta 4, 6.7 Beta 5, 7.0, 7.0.1 | Supported | Full retry ladder, including minimum face-length ratio escalation. |
| 6.3 – 6.5 | Supported | No minimum face-length ratio escalation (see below). |
| 6.0 – 6.2 | Supported | As above. Preprocessing needs every land-cover, infiltration, and sediment file the geometry references (see below). |
Why older releases need different calls. Two RasMapperLib members changed
their parameters between releases, and generate() adapts to whichever form
the loaded release has:
| RasMapperLib member | 6.0 – 6.2 | 6.3 – 6.3.1 | 6.4.1 – 6.5 | 6.6 and later |
|---|---|---|---|---|
MeshFV2D(perimeter, points, breaklines, progress, ...) constructor |
4 parameters | 4 | 4 | 5 (adds minFaceLengthRatio) |
PointGenerator.RegenerateMeshPoints (breakline-aware seeding) |
4 parameters | 6 (adds progress reporters) | 7 (adds treatInactiveAsNotPresent) |
7 |
RASD2FlowArea.CreatePropertyTables (used by compute_property_tables) |
3 parameters | 4 (adds per-task reporters) | 4 | 4 |
Before 6.6, MeshFV2D has no minimum face-length ratio, so generate() skips
the ratio-escalation step of its retry ladder. A mesh that 6.6 completes only
after raising the ratio can therefore fail on 6.0 – 6.5; the other retry steps
still apply.
Known limitations.
- HEC-RAS 6.0 – 6.2 and missing referenced files. If a land-cover,
infiltration, or sediment file referenced by the geometry is missing,
HEC-RAS 6.0 – 6.2 skip the geometry during preprocessing without an error,
and the plan HDF has no 2D mesh. With these releases,
RasPreprocess.preprocess_plan()checks for the files first and fails, naming each missing file, instead of reporting success. HEC-RAS 6.3 and later preprocess the mesh anyway, so the check does not apply to them. - Property-table values differ by release.
compute_property_tables()writes tables on every supported release, but HEC-RAS changed its property-table computation over time. Values from 6.0 – 6.3.1 differ from 6.4.1 and later, which match each other. - Terms and Conditions for Use. A release must have its TCU accepted for
the current user before
Ras.execan preprocess headlessly.
Selecting the HEC-RAS version. Without hecras_dir, generate() loads the
newest installed release it finds (7.0.1, 7.0, 6.6, 6.7 Beta 5, then 6.5 down
to 6.0), regardless of the project's version. Pass hecras_dir to pin the
release. Only one RasMapperLib version can be loaded per Python process.
Linux / Wine. The same behavior applies under Wine
(rascommander/hec-ras-wine-precompute_{version} images). Loading
RasMapperLib there also requires the C:\Python311\GDAL link to the HEC-RAS
GDAL folder, prepared from the Linux side.
How refinement regions were tested. A region-only A/B test uses the real
RasExamples Chippewa_2D project: a 200-ft base mesh (357 cells), followed by a
1,600-ft-square refinement region requesting 40-ft spacing. RAS Mapper must
reload the authored region before regeneration, the refined mesh must contain
2,118 cells, and median nearest-neighbor spacing inside the region must be
40 ft. Native Windows produced the same result on every locally installed 6.x
runtime: 6.0, 6.1, 6.2, 6.3, 6.3.1, 6.5, 6.6, and 6.7 Beta 5. A 6.4/6.4.1
installation was not available for this qualification. The private
RegenerateMeshPoints API was also reflected independently in each process:
activeRegions is parameter 2 in every tested release; only the documented
trailing argument count changes.
HEC-RAS 6.6 was also qualified under Wine 11.0 on CLB07 using the pinned
rascommander/hec-ras-wine-precompute_6.6 runtime. Both the RAS Mapper
product-layer writer and the native-schema fallback produced 2,118 generated
computation points (also the HDF Cell Count), 2,209 compiled cell-center
rows, 4,376 faces, and 1,600 centers inside the region at exactly 40-ft median
nearest-neighbor spacing; outside-region spacing was 122.327 ft. The run used
an isolated writable prefix and the Linux-side C:\Python311\GDAL link noted
above.
HEC-RAS Refinement-Region Caveats¶
- Independent Y spacing is not implemented by HEC-RAS. RAS Mapper stores
both X and Y spacing, but the 6.6 Mapper manual labels Cell Spacing Y as
"not implemented yet."
spacing_dyis preserved for schema fidelity; do not interpret a different Y value as verified anisotropic refinement. - HEC-RAS 6.2 GUI row reordering. HEC documented that reordering the
Refinement Region Editor table could create duplicate regions and deleting
those duplicates could crash. The documented workaround was the feature
Send...command; HEC lists the defect as fixed in 6.3. ras-commander does not drive that GUI reorder path. - HEC-RAS 6.4 breakline interactions. HEC fixed lost properties after splitting breaklines, incorrect one-cell protection-radius behavior when breakline/region inclusion was disabled, and some breaklines that failed to enforce. Prefer 6.4 or later for models combining these behaviors.
- HEC-RAS 6.6 perimeter-loss symptom. HEC documented exceptional cases in which a 2D perimeter disappeared and the mesh stopped updating or selecting. Product-backed authoring therefore backs up the geometry HDF and requires a fresh RAS Mapper reload before reporting success.
- HEC-RAS 6.7 betas. Beta 2/3 had an initial mesh-recompute "Unknown Error"/arithmetic-overflow issue. Beta 5 passes the region-only qualification above, but a stable release is preferable for production.
See HEC's official 6.2 known issues, 6.3 fixes, 6.4 fixes, 6.6 known issues, 7.0's archived beta fixes, and the 6.6 Mapper manual.
Mesh methods¶
Headless 2D mesh generation, repair, and BC conflict resolution.
Uses RasMapperLib.dll via pythonnet to generate finite volume meshes without the RAS Mapper GUI. Includes a 5-tier auto-fix pipeline that mirrors TryAutoFix behavior from the GUI.
All methods are static — no instantiation needed.
Example
from ras_commander.geom import GeomMesh GeomMesh.setup_gdal_bridge() # optional explicit preflight result = GeomMesh.generate("01") # by geometry number result = GeomMesh.generate("project.g01") # or by file path if result: ... print(f"Mesh: {result.cell_count} cells")
setup_gdal_bridge
staticmethod
¶
setup_gdal_bridge(hecras_dir: Optional[Union[str, Path]] = None, python_dir: Optional[Union[str, Path]] = None, create_junction: bool = True) -> bool
Configure HEC-RAS GDAL runtime for RasMapperLib.
The default path points GDAL environment variables and DLL search paths
at the GDAL runtime bundled with HEC-RAS, then verifies the legacy
python.exe sibling GDAL bridge before RasMapperLib is loaded.
Returns True if the process runtime was configured successfully.
Source code in ras_commander/geom/GeomMesh.py
audit_domain_containment
staticmethod
¶
audit_domain_containment(geom_number: Union[str, Number, Path], mesh_name: Optional[str] = None, mesh_index: int = 0, cell_size: Optional[float] = None, ras_object=None, recompile_via_rasexe: bool = False, strict_refinement_containment: bool = False, require_complete_products: bool = False) -> DomainContainmentResult
Audit mesh features before point generation.
Packed refinement regions retain interior rings, disjoint shells and islands using feature-local Parts offsets. Malformed ranges raise.
The admissible geometry is the exact compiled 2D perimeter buffered inward by one base mesh-cell spacing. Every breakline and structure associated with the selected 2D area must be wholly covered by that eroded polygon. Boundary-condition lines are intentionally excluded because external BC lines are authored at the perimeter and require a separate association audit.
Valid refinement regions may touch or extend beyond the perimeter;
generate() removes native points outside the 2D area. Set
strict_refinement_containment=True to apply the earlier one-cell
inward margin to regions as well.
This read-only check is cross-platform and does not load RasMapperLib.
A missing, stale, malformed, or ambiguous geometry HDF fails closed.
require_complete_products defaults to False and is forwarded to
native preprocessing when recompile_via_rasexe=True permits mutation.
Packed polyline Parts offsets resolve for each complete feature. Native local offsets, valid when every part lies within the feature's point count, take precedence over legacy whole-feature global offsets.
Source code in ras_commander/geom/GeomMesh.py
| Python | |
|---|---|
3897 3898 3899 3900 3901 3902 3903 3904 3905 3906 3907 3908 3909 3910 3911 3912 3913 3914 3915 3916 3917 3918 3919 3920 3921 3922 3923 3924 3925 3926 3927 3928 3929 3930 3931 3932 3933 3934 3935 3936 3937 3938 3939 3940 3941 3942 3943 3944 3945 3946 3947 3948 3949 3950 3951 3952 3953 3954 3955 3956 3957 3958 3959 3960 3961 3962 3963 3964 3965 3966 3967 3968 3969 3970 3971 3972 3973 3974 3975 3976 3977 3978 3979 3980 3981 3982 | |
set_breakline_spacing
staticmethod
¶
set_breakline_spacing(geom_number: Union[str, Number, Path], near: Optional[float] = None, far: Optional[float] = None, near_repeats: Optional[int] = None, protection_radius: Optional[int] = None, breakline_name: Optional[str] = None, breakline_fid: Optional[int] = None, all_breaklines: bool = False, ras_object=None) -> Path
Edit BreakLine spacing properties in a .g## text file.
Target a single breakline by breakline_name or breakline_fid
(0-based index in file order). Set all_breaklines=True for
bulk changes (model building, sensitivity analysis).
HEC-RAS allows duplicate breakline names (including empty names).
When duplicates exist, breakline_name matches the first
occurrence. Use breakline_fid for reliable targeting — call
get_breakline_names() to inspect the FID-to-name mapping and
check for duplicates before editing by name.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
geom_number
|
Union[str, Number, Path]
|
Geometry number ("01", 1) or path to .g## text file. |
required |
near
|
Optional[float]
|
BreakLine near-spacing in project units. None keeps existing. |
None
|
far
|
Optional[float]
|
BreakLine far-spacing in project units. None keeps existing. |
None
|
near_repeats
|
Optional[int]
|
Number of offset seed rows on each side of breaklines. None keeps existing value. |
None
|
protection_radius
|
Optional[int]
|
Enable 1-cell protection radius (0 or 1). None keeps existing value. |
None
|
breakline_name
|
Optional[str]
|
Name of the breakline to modify. |
None
|
breakline_fid
|
Optional[int]
|
0-based index of the breakline in file order. Most reliable selector — breaklines can be unnamed or have duplicate names. |
None
|
all_breaklines
|
bool
|
If True, apply spacing to every breakline. |
False
|
ras_object
|
RasPrj
|
Optional RasPrj instance for multi-project support. |
None
|
Returns:
| Type | Description |
|---|---|
Path
|
Path to .bak backup file created before writing. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If no target is specified, or if the target is not found in the file. |
Source code in ras_commander/geom/GeomMesh.py
| Python | |
|---|---|
3984 3985 3986 3987 3988 3989 3990 3991 3992 3993 3994 3995 3996 3997 3998 3999 4000 4001 4002 4003 4004 4005 4006 4007 4008 4009 4010 4011 4012 4013 4014 4015 4016 4017 4018 4019 4020 4021 4022 4023 4024 4025 4026 4027 4028 4029 4030 4031 4032 4033 4034 4035 4036 4037 4038 4039 4040 4041 4042 4043 4044 4045 4046 4047 4048 4049 4050 4051 4052 4053 4054 | |
get_breakline_names
staticmethod
¶
get_breakline_names(geom_number: Union[str, Number, Path], ras_object=None) -> list[tuple[int, str]]
Read breakline names from a .g## text file.
HEC-RAS allows duplicate and empty breakline names. Use this
method to inspect the FID-to-name mapping before calling
set_breakline_spacing() or set_breakline_name() by name.
When duplicates exist, targeting by breakline_fid is the most
reliable approach.
Returns:
| Type | Description |
|---|---|
list[tuple[int, str]]
|
List of (fid, name) tuples in file order. fid is the |
list[tuple[int, str]]
|
0-based index. Unnamed breaklines have |
Source code in ras_commander/geom/GeomMesh.py
set_breakline_name
staticmethod
¶
set_breakline_name(geom_number: Union[str, Number, Path], new_name: str, breakline_fid: Optional[int] = None, old_name: Optional[str] = None, ras_object=None) -> Path
Rename a breakline in a .g## text file.
HEC-RAS allows duplicate and empty breakline names.
breakline_fid (0-based index in file order) is the most
reliable selector. When using old_name, this method raises
ValueError if multiple breaklines share that name — use
get_breakline_names() to inspect duplicates first, then
target by FID or assign unique descriptive names.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
geom_number
|
Union[str, Number, Path]
|
Geometry number or path to .g## text file. |
required |
new_name
|
str
|
New name to assign. |
required |
breakline_fid
|
Optional[int]
|
0-based index of the breakline in file order. Most reliable selector — breaklines can be unnamed or have duplicate names. |
None
|
old_name
|
Optional[str]
|
Current name of the breakline. Raises if multiple breaklines share this name. |
None
|
ras_object
|
RasPrj
|
Optional RasPrj instance. |
None
|
Returns:
| Type | Description |
|---|---|
Path
|
Path to .bak backup file created before writing. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If neither selector is given, both are given, the target is not found, or old_name matches multiple breaklines. |
Source code in ras_commander/geom/GeomMesh.py
get_breakline_spacing
staticmethod
¶
get_breakline_spacing(geom_number: Union[str, Number, Path], ras_object=None) -> list[tuple[int, str, float, float, int, int]]
Read per-breakline spacing from a .g## text file.
HEC-RAS allows duplicate and empty breakline names. The fid
in each tuple is the most reliable identifier — use it with
set_breakline_spacing(breakline_fid=...) when names are
ambiguous.
Returns:
| Type | Description |
|---|---|
list[tuple[int, str, float, float, int, int]]
|
List of (fid, name, near, far, near_repeats, protection_radius) |
list[tuple[int, str, float, float, int, int]]
|
tuples in file order. fid is the 0-based index. |
Source code in ras_commander/geom/GeomMesh.py
get_refinement_region_names
staticmethod
¶
get_refinement_region_names(geom_number: Union[str, Number, Path], hecras_dir: Optional[Union[str, Path]] = None, ras_object=None) -> list[tuple[int, str]]
Read refinement region names from the compiled HDF.
HEC-RAS allows duplicate and empty refinement region names.
Use this method to inspect the FID-to-name mapping before
calling set_refinement_region_spacing() or
set_refinement_region_name() by name. When duplicates
exist, targeting by region_fid is the most reliable approach.
Refinement regions are stored in HDF, not .g## text. The compiled HDF must already exist.
Returns:
| Type | Description |
|---|---|
list[tuple[int, str]]
|
List of (fid, name) tuples in HDF order. fid is the |
list[tuple[int, str]]
|
0-based index. |
Source code in ras_commander/geom/GeomMesh.py
set_refinement_region_name
staticmethod
¶
set_refinement_region_name(geom_number: Union[str, Number, Path], new_name: str, region_fid: Optional[int] = None, old_name: Optional[str] = None, hecras_dir: Optional[Union[str, Path]] = None, ras_object=None) -> None
Rename a refinement region in the compiled HDF.
HEC-RAS allows duplicate and empty refinement region names.
region_fid (0-based index in HDF order) is the most reliable
selector. When using old_name, this method raises
ValueError if multiple regions share that name — use
get_refinement_region_names() to inspect duplicates first,
then target by FID or assign unique descriptive names.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
geom_number
|
Union[str, Number, Path]
|
Geometry number or path to .g## text file. |
required |
new_name
|
str
|
New name to assign. |
required |
region_fid
|
Optional[int]
|
0-based index of the region in HDF order. Most reliable selector — regions can be unnamed or have duplicate names. |
None
|
old_name
|
Optional[str]
|
Current name of the region. Raises if multiple regions share this name. |
None
|
hecras_dir
|
Optional[Union[str, Path]]
|
Override HEC-RAS installation directory. |
None
|
ras_object
|
RasPrj
|
Optional RasPrj instance. |
None
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If neither selector is given, both are given, the target is not found, or old_name matches multiple regions. |
Source code in ras_commander/geom/GeomMesh.py
| Python | |
|---|---|
4190 4191 4192 4193 4194 4195 4196 4197 4198 4199 4200 4201 4202 4203 4204 4205 4206 4207 4208 4209 4210 4211 4212 4213 4214 4215 4216 4217 4218 4219 4220 4221 4222 4223 4224 4225 4226 4227 4228 4229 4230 4231 4232 4233 4234 4235 4236 4237 4238 4239 4240 4241 4242 4243 4244 4245 4246 4247 4248 4249 4250 4251 4252 4253 4254 4255 4256 4257 4258 4259 4260 4261 4262 4263 4264 4265 4266 4267 4268 4269 4270 4271 4272 4273 4274 4275 4276 4277 4278 4279 4280 4281 4282 | |
get_refinement_regions
staticmethod
¶
get_refinement_regions(geom_number: Union[str, Number, Path], hecras_dir: Optional[Union[str, Path]] = None, ras_object=None) -> list[dict]
Read refinement region names and spacing from the compiled HDF.
HEC-RAS allows duplicate and empty refinement region names.
The fid in each dict is the most reliable identifier — use it
with set_refinement_region_spacing(region_fid=...) or
set_refinement_region_name(region_fid=...) when names are
ambiguous.
Refinement regions are stored in HDF, not .g## text. The compiled HDF must already exist.
Returns:
| Type | Description |
|---|---|
List of dicts with keys
|
fid, name, spacing_dx, spacing_dy. |
list[dict]
|
Empty list if no refinement regions exist. |
Source code in ras_commander/geom/GeomMesh.py
set_refinement_region_spacing
staticmethod
¶
set_refinement_region_spacing(geom_number: Union[str, Number, Path], spacing_dx: Optional[float] = None, spacing_dy: Optional[float] = None, region_name: Optional[str] = None, region_fid: Optional[int] = None, all_regions: bool = False, hecras_dir: Optional[Union[str, Path]] = None, ras_object=None) -> None
Set refinement region cell spacing in the compiled HDF.
Refinement regions override the base cell size within their
polygon boundaries. Target a single region by region_name
or region_fid (0-based index in HDF order). Set
all_regions=True for bulk changes.
HEC-RAS allows duplicate and empty refinement region names.
When duplicates exist, region_name matches the first
occurrence. Use region_fid for reliable targeting — call
get_refinement_region_names() to inspect the FID-to-name
mapping and check for duplicates before editing by name.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
geom_number
|
Union[str, Number, Path]
|
Geometry number or path to .g## text file. |
required |
spacing_dx
|
Optional[float]
|
Cell spacing in the X direction (project units). None keeps existing value. |
None
|
spacing_dy
|
Optional[float]
|
Cell spacing in the Y direction (project units). None keeps existing value. Defaults to spacing_dx if spacing_dx is provided and spacing_dy is None. |
None
|
region_name
|
Optional[str]
|
Name of the refinement region to modify. |
None
|
region_fid
|
Optional[int]
|
0-based index of the region in HDF order. Most reliable selector — regions can be unnamed or have duplicate names. |
None
|
all_regions
|
bool
|
If True, apply spacing to every region. |
False
|
hecras_dir
|
Optional[Union[str, Path]]
|
Override HEC-RAS installation directory. |
None
|
ras_object
|
RasPrj
|
Optional RasPrj instance. |
None
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If no target is specified, or if the target is not found. |
Source code in ras_commander/geom/GeomMesh.py
| Python | |
|---|---|
4334 4335 4336 4337 4338 4339 4340 4341 4342 4343 4344 4345 4346 4347 4348 4349 4350 4351 4352 4353 4354 4355 4356 4357 4358 4359 4360 4361 4362 4363 4364 4365 4366 4367 4368 4369 4370 4371 4372 4373 4374 4375 4376 4377 4378 4379 4380 4381 4382 4383 4384 4385 4386 4387 4388 4389 4390 4391 4392 4393 4394 4395 4396 4397 4398 4399 4400 4401 4402 4403 4404 4405 4406 4407 4408 4409 4410 4411 4412 4413 4414 4415 4416 4417 4418 4419 4420 4421 4422 4423 4424 4425 4426 4427 4428 4429 4430 4431 4432 4433 4434 4435 4436 4437 4438 4439 4440 4441 4442 4443 4444 4445 4446 4447 4448 4449 4450 4451 4452 4453 4454 4455 4456 4457 4458 4459 4460 4461 4462 4463 4464 4465 4466 4467 4468 4469 4470 4471 | |
replace_refinement_regions
staticmethod
¶
replace_refinement_regions(geom_number: Union[str, Number, Path], regions: Sequence[Mapping[str, Any]], *, expected_existing_names: Optional[Sequence[str]] = None, hecras_dir: Optional[Union[str, Path]] = None, ras_object=None, create_backup: bool = True) -> Optional[Path]
Atomically replace the complete HDF refinement-region collection.
Each region mapping requires polygon (or geometry) and
spacing_dx; spacing_dy defaults to spacing_dx and name
defaults to an empty string. The replacement is built and validated in
a same-directory temporary HDF before it is promoted over the original.
Optional native properties are shift_dx, shift_dy,
perimeter_spacing, near_repeats, far_spacing and
protection_radius. Missing floating properties default to NaN;
missing repeats and protection radius default to zero. Polygon holes
are rejected rather than silently filled. Use clip_refinement_regions
to prepare a delivered collection for a child perimeter.
expected_existing_names is an optimistic-concurrency guard. Names
are compared in HDF/FID order and may contain duplicates or empty
strings because HEC-RAS permits both. Passing an empty regions
sequence removes the refinement-region group.
Source code in ras_commander/geom/GeomMesh.py
| Python | |
|---|---|
4641 4642 4643 4644 4645 4646 4647 4648 4649 4650 4651 4652 4653 4654 4655 4656 4657 4658 4659 4660 4661 4662 4663 4664 4665 4666 4667 4668 4669 4670 4671 4672 4673 4674 4675 4676 4677 4678 4679 4680 4681 4682 4683 4684 4685 4686 4687 4688 4689 4690 4691 4692 4693 4694 4695 4696 4697 4698 4699 4700 4701 4702 4703 4704 4705 4706 4707 4708 4709 4710 4711 4712 4713 4714 4715 4716 4717 4718 4719 4720 4721 4722 4723 4724 4725 4726 4727 4728 4729 4730 4731 4732 4733 4734 4735 4736 4737 4738 4739 4740 4741 4742 4743 4744 4745 4746 4747 4748 4749 4750 4751 4752 4753 4754 4755 4756 4757 4758 4759 4760 4761 4762 4763 4764 4765 4766 4767 4768 4769 4770 4771 4772 4773 4774 4775 4776 4777 4778 4779 4780 4781 4782 4783 4784 4785 4786 4787 4788 4789 4790 4791 4792 4793 4794 4795 4796 4797 4798 4799 4800 4801 4802 4803 4804 4805 4806 4807 4808 4809 4810 4811 4812 4813 4814 4815 4816 4817 4818 4819 4820 4821 4822 4823 4824 4825 4826 4827 4828 | |
clip_refinement_regions
staticmethod
¶
clip_refinement_regions(geom_number: str | Number | Path, perimeter, *, min_area: float = 0.0, invalid_regions: str = 'raise', hecras_dir: str | Path | None = None, ras_object=None) -> tuple[list[dict[str, Any]], pandas.DataFrame]
Prepare delivered refinement regions for a smaller 2D perimeter.
Read the source HDF without modifying it. Intersect each region with
perimeter, retain its native spacing properties, and return mappings
for replace_refinement_regions() plus a per-source-region DataFrame.
Disconnected intersections become separate output regions in source
order, with the same name and properties. Duplicate names are permitted.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
geom_number
|
str | Number | Path
|
Source geometry number or .g## text path. |
required |
perimeter
|
Polygon | MultiPolygon | Sequence[Sequence[float]]
|
Clipping mask or (N, 2) XY coordinates in the source geometry's CRS and project length units. Holes are not supported by the replacement writer. A disconnected inward buffer may be a MultiPolygon; every positive-area intersection fragment is retained by default. This mask does not author the computational-domain perimeter. |
required |
min_area
|
float
|
Optional fragment area cutoff in squared project units. Default zero retains every positive-area fragment, including regions smaller than one spacing_dx * spacing_dy cell. Such regions do not necessarily produce an interior grid point. |
0.0
|
invalid_regions
|
str
|
"raise" (default) rejects invalid polygons or unsupported holes; "drop" records them as dropped and continues. "repair" uses GEOS make_valid and partitions holes without filling them. Zero-area remnants are recorded. Repair hashes and areas are returned in report.attrs["repairs"]. |
'raise'
|
hecras_dir
|
str | Path | None
|
Optional HEC-RAS installation for source HDF validation. |
None
|
ras_object
|
RasPrj | None
|
Optional source RasPrj context. |
None
|
Returns:
| Type | Description |
|---|---|
list[dict[str, Any]]
|
(regions, report). Regions preserve X/Y spacing, shifts, perimeter |
DataFrame
|
spacing, near repeats, far spacing and protection radius. Report |
tuple[list[dict[str, Any]], DataFrame]
|
columns are source_fid, name, status (kept/clipped/dropped), reason, |
tuple[list[dict[str, Any]], DataFrame]
|
source_area, retained_area, output_fids, touches_perimeter and |
tuple[list[dict[str, Any]], DataFrame]
|
below_one_cell_area. Areas use squared project units. |
Raises:
| Type | Description |
|---|---|
ValueError
|
Invalid perimeter, area cutoff, source polygon or unsupported interior rings. No files are written. |
Notes
Clipping changes the region extent used as the grid origin and creates new perimeter transitions. Retaining spacing and shifts does not reproduce the full region's original points or transitions.
Source code in ras_commander/geom/GeomMesh.py
| Python | |
|---|---|
4473 4474 4475 4476 4477 4478 4479 4480 4481 4482 4483 4484 4485 4486 4487 4488 4489 4490 4491 4492 4493 4494 4495 4496 4497 4498 4499 4500 4501 4502 4503 4504 4505 4506 4507 4508 4509 4510 4511 4512 4513 4514 4515 4516 4517 4518 4519 4520 4521 4522 4523 4524 4525 4526 4527 4528 4529 4530 4531 4532 4533 4534 4535 4536 4537 4538 4539 4540 4541 4542 4543 4544 4545 4546 4547 4548 4549 4550 4551 4552 4553 4554 4555 4556 4557 4558 4559 4560 4561 4562 4563 4564 4565 4566 4567 4568 4569 4570 4571 4572 4573 4574 4575 4576 4577 4578 4579 4580 4581 4582 4583 4584 4585 4586 4587 4588 4589 4590 4591 4592 4593 4594 4595 4596 4597 4598 4599 4600 4601 4602 4603 4604 4605 4606 4607 4608 4609 4610 4611 4612 4613 4614 4615 4616 4617 4618 4619 4620 4621 4622 4623 4624 4625 4626 4627 4628 4629 4630 4631 4632 4633 4634 4635 4636 4637 4638 4639 | |
add_refinement_region
staticmethod
¶
add_refinement_region(geom_number: Union[str, Number, Path], polygon, spacing_dx: float, spacing_dy: Optional[float] = None, name: str = '', hecras_dir: Optional[Union[str, Path]] = None, ras_object=None, use_rasmapper: Optional[bool] = None) -> int
Create a new refinement region in the compiled geometry HDF.
Refinement regions override the base cell size within their polygon boundaries during mesh generation. They are stored exclusively in HDF — there is no .g## text representation.
On Windows/Wine, real product geometry is authored through RAS
Mapper's MeshRegions feature layer and verified with a fresh
product reload. Synthetic or cross-platform fixtures use the complete
nine-field native HDF schema and polygon-table metadata.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
geom_number
|
Union[str, Number, Path]
|
Geometry number or path to .g## text file. |
required |
polygon
|
list[tuple[float, float]] | Polygon
|
Region boundary as a list of (x, y) tuples,
a Shapely Polygon, or any object whose
|
required |
spacing_dx
|
float
|
Cell spacing in the X direction (project units, e.g. feet or metres). |
required |
spacing_dy
|
Optional[float]
|
Stored Y-direction spacing. Defaults to spacing_dx
when |
None
|
name
|
str
|
Region name stored in the HDF |
''
|
hecras_dir
|
Optional[Union[str, Path]]
|
Override HEC-RAS installation directory. |
None
|
ras_object
|
RasPrj
|
Optional RasPrj instance. |
None
|
use_rasmapper
|
Optional[bool]
|
Force product-backed authoring (True) or the
low-level native-schema writer (False). |
None
|
Returns:
| Type | Description |
|---|---|
int
|
The 0-based FID of the newly created region. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If polygon has fewer than 3 vertices or spacing_dx is not positive. |
Source code in ras_commander/geom/GeomMesh.py
| Python | |
|---|---|
4830 4831 4832 4833 4834 4835 4836 4837 4838 4839 4840 4841 4842 4843 4844 4845 4846 4847 4848 4849 4850 4851 4852 4853 4854 4855 4856 4857 4858 4859 4860 4861 4862 4863 4864 4865 4866 4867 4868 4869 4870 4871 4872 4873 4874 4875 4876 4877 4878 4879 4880 4881 4882 4883 4884 4885 4886 4887 4888 4889 4890 4891 4892 4893 4894 4895 4896 4897 4898 4899 4900 4901 4902 4903 4904 4905 4906 4907 4908 4909 4910 4911 4912 4913 4914 4915 4916 4917 4918 4919 4920 4921 4922 4923 4924 4925 4926 4927 4928 4929 4930 4931 4932 4933 4934 4935 4936 4937 4938 4939 4940 4941 4942 4943 4944 4945 4946 4947 4948 4949 4950 4951 4952 4953 4954 4955 4956 4957 4958 4959 4960 4961 4962 4963 4964 4965 4966 4967 4968 4969 4970 4971 4972 4973 4974 4975 4976 4977 4978 4979 4980 4981 4982 4983 4984 4985 4986 4987 4988 4989 4990 4991 4992 4993 4994 4995 4996 4997 4998 4999 5000 5001 5002 5003 5004 5005 5006 5007 5008 5009 5010 5011 5012 5013 5014 5015 5016 5017 5018 5019 5020 5021 5022 5023 5024 | |
add_flowline_refinement_regions
staticmethod
¶
add_flowline_refinement_regions(geom_number: Union[str, Number, Path], flowlines, buffer_width: float, spacing_dx: Optional[float] = None, spacing_dy: Optional[float] = None, name_prefix: str = 'FlowlineRR', name_column: Optional[str] = None, simplify_tolerance: Optional[float] = None, preserve_topology: bool = True, trim_geometries=None, trim_distance: float = 0.0, trim_hook: Optional[Callable] = None, trim_overlaps: bool = False, cap_style: Union[str, int] = 'flat', join_style: Union[str, int] = 'round', mitre_limit: float = 5.0, min_area: float = 0.0, project_crs: Optional[object] = None, hecras_dir: Optional[Union[str, Path]] = None, ras_object=None) -> list[dict]
Buffer channel flowlines into HEC-RAS refinement regions.
This is the high-level API equivalent of the HEC-RAS Mapper workflow
that filters flowlines, buffers them to refinement-region polygons,
and sets the region X/Y cell spacing to the selected buffer width.
The final write still goes through add_refinement_region() so the
generated HDF datasets use the same schema as the lower-level helper.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
geom_number
|
Union[str, Number, Path]
|
Geometry number, .g## text path, or resolvable geometry selector. A current compiled .g##.hdf workspace must exist. |
required |
flowlines
|
GeoDataFrame | GeoSeries | LineString | MultiLineString | Iterable
|
GeoDataFrame, GeoSeries, LineString, MultiLineString, or iterable of shapely line geometries. GeoDataFrame inputs are reprojected to the project CRS when both CRS values are known; inputs without a CRS are assumed to already be in project CRS. |
required |
buffer_width
|
float
|
Distance used to buffer each flowline, in project
units. Defaults |
required |
spacing_dx
|
Optional[float]
|
Refinement-region X spacing. Defaults to
|
None
|
spacing_dy
|
Optional[float]
|
Refinement-region Y spacing. Defaults to
|
None
|
name_prefix
|
str
|
Prefix used when |
'FlowlineRR'
|
name_column
|
Optional[str]
|
Optional GeoDataFrame column for region names. |
None
|
simplify_tolerance
|
Optional[float]
|
Optional line simplification tolerance applied before buffering. |
None
|
preserve_topology
|
bool
|
Passed to shapely |
True
|
trim_geometries
|
GeoDataFrame | BaseGeometry | Iterable
|
Optional GeoDataFrame, geometry, or iterable of geometries to subtract from generated buffers. Use this for bridge, confluence, levee, or other overlap avoidance zones. |
None
|
trim_distance
|
float
|
Optional buffer distance applied to
|
0.0
|
trim_hook
|
Optional[Callable]
|
Optional callable |
None
|
trim_overlaps
|
bool
|
If True, subtract previously-created flowline regions from later regions. This is order-dependent but useful for quickly removing confluence overlaps. |
False
|
cap_style
|
Union[str, int]
|
Shapely buffer cap style: |
'flat'
|
join_style
|
Union[str, int]
|
Shapely buffer join style: |
'round'
|
mitre_limit
|
float
|
Shapely buffer mitre limit. |
5.0
|
min_area
|
float
|
Skip trimmed polygon parts smaller than this area. |
0.0
|
project_crs
|
Optional[object]
|
Optional CRS override for GeoDataFrame reprojection. If omitted, the method attempts to read the project CRS from the compiled geometry HDF/RASMapper files when needed. |
None
|
hecras_dir
|
Optional[Union[str, Path]]
|
Override HEC-RAS installation directory for HDF
resolution consistency with other |
None
|
ras_object
|
RasPrj
|
Optional RasPrj instance. |
None
|
Returns:
| Type | Description |
|---|---|
list[dict]
|
List of dictionaries mapping each written region to its HDF FID, |
list[dict]
|
stored name, source feature index, spacing, buffer width, and area. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If spacing/buffer inputs are non-positive, if
|
Source code in ras_commander/geom/GeomMesh.py
| Python | |
|---|---|
5026 5027 5028 5029 5030 5031 5032 5033 5034 5035 5036 5037 5038 5039 5040 5041 5042 5043 5044 5045 5046 5047 5048 5049 5050 5051 5052 5053 5054 5055 5056 5057 5058 5059 5060 5061 5062 5063 5064 5065 5066 5067 5068 5069 5070 5071 5072 5073 5074 5075 5076 5077 5078 5079 5080 5081 5082 5083 5084 5085 5086 5087 5088 5089 5090 5091 5092 5093 5094 5095 5096 5097 5098 5099 5100 5101 5102 5103 5104 5105 5106 5107 5108 5109 5110 5111 5112 5113 5114 5115 5116 5117 5118 5119 5120 5121 5122 5123 5124 5125 5126 5127 5128 5129 5130 5131 5132 5133 5134 5135 5136 5137 5138 5139 5140 5141 5142 5143 5144 5145 5146 5147 5148 5149 5150 5151 5152 5153 5154 5155 5156 5157 5158 5159 5160 5161 5162 5163 5164 5165 5166 5167 5168 5169 5170 5171 5172 5173 5174 5175 5176 5177 5178 5179 5180 5181 5182 5183 5184 5185 5186 5187 5188 5189 5190 5191 5192 5193 5194 5195 5196 5197 5198 5199 5200 5201 5202 5203 5204 5205 5206 5207 5208 5209 5210 5211 5212 5213 5214 5215 5216 5217 5218 5219 5220 5221 5222 5223 5224 5225 5226 5227 5228 5229 5230 5231 5232 5233 5234 5235 5236 5237 5238 5239 5240 5241 5242 5243 5244 5245 5246 5247 5248 5249 5250 5251 5252 5253 5254 5255 5256 5257 5258 | |
compile_geometry
staticmethod
¶
compile_geometry(geom_number: Union[str, Number, Path], hecras_dir: Optional[Union[str, Path]] = None, ras_object=None) -> Path
Disabled compatibility shim for .g## text -> .g##.hdf generation.
ras-commander cannot compile a plain-text geometry file into its compiled HDF representation without full HEC-RAS/Ras.exe behavior. RasMapperLib's CompleteGeometryCommand only completes existing HDF files; it is not a text geometry compiler.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
geom_number
|
Union[str, Number, Path]
|
Geometry number ("01", 1) or path to .g## text file. |
required |
hecras_dir
|
Optional[Union[str, Path]]
|
Override HEC-RAS installation directory. |
None
|
ras_object
|
RasPrj
|
Optional RasPrj instance for multi-project support. |
None
|
Returns:
| Type | Description |
|---|---|
Path
|
Never returns successfully. |
Raises:
| Type | Description |
|---|---|
FileNotFoundError
|
If geometry file cannot be resolved. |
RuntimeError
|
Always, because this path is unavailable. |
Source code in ras_commander/geom/GeomMesh.py
get_geometry_association
staticmethod
¶
get_geometry_association(geom_number: Union[str, Number, Path], hecras_dir: Optional[Union[str, Path]] = None, ras_object=None, resolve_paths: bool = True) -> dict
Read terrain and classification associations from a geometry HDF.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
geom_number
|
Union[str, Number, Path]
|
Geometry number, .g## text path, or .g##.hdf path. Text inputs require an existing current .g##.hdf. |
required |
hecras_dir
|
Optional[Union[str, Path]]
|
Kept for API symmetry; no DLLs are loaded here. |
None
|
ras_object
|
RasPrj
|
Optional RasPrj instance for geometry-number lookup. |
None
|
resolve_paths
|
bool
|
If True, return absolute paths resolved relative to the geometry HDF. If False, return the raw HDF attribute text. |
True
|
Returns:
| Type | Description |
|---|---|
dict
|
Dict with keys |
dict
|
|
dict
|
|
Source code in ras_commander/geom/GeomMesh.py
set_geometry_association
staticmethod
¶
set_geometry_association(geom_number: Union[str, Number, Path], terrain_hdf_path: Optional[Union[str, Path]] = None, landcover_hdf_path: Optional[Union[str, Path]] = None, infiltration_hdf_path: Optional[Union[str, Path]] = None, sediment_soils_hdf_path: Optional[Union[str, Path]] = None, hecras_dir: Optional[Union[str, Path]] = None, ras_object=None, validate: bool = True) -> Path
Associate terrain / classification layers to an existing geometry HDF.
This wraps RasMapperLib's SetGeometryAssociationCommand and writes
attributes under /Geometry in the compiled .g##.hdf. It does
not create or refresh a missing geometry HDF.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
geom_number
|
Union[str, Number, Path]
|
Geometry number, .g## text path, or .g##.hdf path. Text inputs require an existing current .g##.hdf. |
required |
terrain_hdf_path
|
Optional[Union[str, Path]]
|
Terrain HDF to associate. |
None
|
landcover_hdf_path
|
Optional[Union[str, Path]]
|
Land-cover / Manning's n HDF. |
None
|
infiltration_hdf_path
|
Optional[Union[str, Path]]
|
Infiltration HDF. |
None
|
sediment_soils_hdf_path
|
Optional[Union[str, Path]]
|
Sediment bed-material soils HDF. This is
the HEC-RAS |
None
|
hecras_dir
|
Optional[Union[str, Path]]
|
Override HEC-RAS installation directory. |
None
|
ras_object
|
RasPrj
|
Optional RasPrj instance for geometry-number lookup. |
None
|
validate
|
bool
|
Re-read |
True
|
Returns:
| Type | Description |
|---|---|
Path
|
Path to the existing geometry HDF that was updated. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If no association paths are supplied. |
FileNotFoundError
|
If any supplied artifact is missing. |
RuntimeError
|
If the HDF is missing /Geometry, execution fails, or validation does not find the expected attributes. |
Source code in ras_commander/geom/GeomMesh.py
| Python | |
|---|---|
5329 5330 5331 5332 5333 5334 5335 5336 5337 5338 5339 5340 5341 5342 5343 5344 5345 5346 5347 5348 5349 5350 5351 5352 5353 5354 5355 5356 5357 5358 5359 5360 5361 5362 5363 5364 5365 5366 5367 5368 5369 5370 5371 5372 5373 5374 5375 5376 5377 5378 5379 5380 5381 5382 5383 5384 5385 5386 5387 5388 5389 5390 5391 5392 5393 5394 5395 5396 5397 5398 5399 5400 5401 5402 5403 5404 5405 5406 5407 5408 5409 5410 5411 5412 5413 5414 5415 5416 5417 5418 5419 5420 5421 5422 5423 5424 5425 5426 5427 5428 5429 5430 5431 5432 5433 | |
compute_property_tables
staticmethod
¶
compute_property_tables(geom_number: Union[str, Number, Path], mesh_name: Optional[str] = None, mesh_index: int = 0, force: bool = True, hecras_dir: Optional[Union[str, Path]] = None, ras_object=None) -> bool
Compute 2D hydraulic property tables for a geometry.
Triggers RAS Mapper's property table computation: face profiles, Manning's n assignment, face hydraulic tables, and cell properties. Requires a terrain layer associated with the geometry.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
geom_number
|
Union[str, Number, Path]
|
Geometry number ("01", 1) or path to .g## text file. |
required |
mesh_name
|
Optional[str]
|
2D flow area name. Auto-detected if only one exists. |
None
|
mesh_index
|
int
|
Index of the 2D flow area (default 0). |
0
|
force
|
bool
|
Force recomputation even if tables are up-to-date. |
True
|
hecras_dir
|
Optional[Union[str, Path]]
|
Override HEC-RAS installation directory. |
None
|
ras_object
|
RasPrj
|
Optional RasPrj instance for multi-project support. |
None
|
Returns:
| Type | Description |
|---|---|
bool
|
True if property tables were computed successfully. |
Raises:
| Type | Description |
|---|---|
FileNotFoundError
|
If geometry file cannot be resolved. |
RuntimeError
|
If terrain is missing or computation fails. |
Source code in ras_commander/geom/GeomMesh.py
| Python | |
|---|---|
5435 5436 5437 5438 5439 5440 5441 5442 5443 5444 5445 5446 5447 5448 5449 5450 5451 5452 5453 5454 5455 5456 5457 5458 5459 5460 5461 5462 5463 5464 5465 5466 5467 5468 5469 5470 5471 5472 5473 5474 5475 5476 5477 5478 5479 5480 5481 5482 5483 5484 5485 5486 5487 5488 5489 5490 5491 5492 5493 5494 5495 5496 5497 5498 5499 5500 5501 5502 5503 5504 5505 5506 5507 5508 5509 5510 5511 5512 5513 5514 5515 5516 5517 5518 5519 5520 5521 5522 5523 5524 5525 5526 5527 | |
generate_computation_points
staticmethod
¶
generate_computation_points(geom_number: Union[str, Number, Path], mesh_name: Optional[str] = None, mesh_index: int = 0, cell_size: Optional[float] = None, hecras_dir: Optional[Union[str, Path]] = None, ras_object=None, repair_generated_points: bool = False, min_face_length_ratio: float = 0.05, evidence_callback: Optional[Callable[[str, Any], None]] = None) -> 'MeshResult'
Generate initial 2D computation points for a 2D flow area directly from the authored .g## perimeter text — no pre-existing compiled .g##.hdf required.
This is the greenfield bootstrap for a brand-new 2D flow area. It builds
a RasMapperLib perimeter Polygon from the Storage Area Surface
Line= block and runs PointGenerator.GeneratePoints (RASMapper's
"Generate Computation Points on Regular Interval"), then writes the
resulting cell centers into the Storage Area 2D Points= block of the
.g## text. HEC-RAS builds the full Voronoi mesh from those points during
geometry preprocessing (e.g. RasCmdr.compute_plan(force_geompre=True)).
Unlike :meth:generate, this does NOT load a compiled HDF and is
therefore the path to use before any mesh exists. It is
breakline-unaware (regular-interval grid clipped to the perimeter); use
:meth:generate for breakline-aware regeneration once a compiled HDF
exists.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
geom_number
|
Union[str, Number, Path]
|
Geometry number ("01", 1) or path to .g## text file. |
required |
mesh_name
|
Optional[str]
|
Name of the 2D flow area (None -> use mesh_index). |
None
|
mesh_index
|
int
|
0-based 2D-area index when mesh_name is None. |
0
|
cell_size
|
Optional[float]
|
Regular-interval spacing in project units. When None, it
is read from |
None
|
hecras_dir
|
Optional[Union[str, Path]]
|
Override HEC-RAS installation directory (for RasMapperLib). |
None
|
ras_object
|
RasPrj
|
Optional RasPrj instance for multi-project support. |
None
|
repair_generated_points
|
bool
|
Inspect native bootstrap topology and remove only recorded, index-matched seeds implicated by perimeter or fewer-than-three-face errors, with at most five repairs. The authored perimeter is never changed. Default preserves legacy point generation. Final Ras.exe compile and QA remain required. |
False
|
min_face_length_ratio
|
float
|
Dimensionless native preview setting; supply the persisted geometry setting when enabling repairs. |
0.05
|
evidence_callback
|
Optional[Callable[[str, Any], None]]
|
Observer receiving each bootstrap_seed_repair plan before any text mutation. Observer errors abort generation and are reported in the returned MeshResult error message. |
None
|
Returns:
| Type | Description |
|---|---|
'MeshResult'
|
MeshResult with status, mesh_name, cell_count (= number of generated |
'MeshResult'
|
computation points), and geom_text_path. Points are written to the |
'MeshResult'
|
.g## text; the full mesh is produced by the subsequent HEC-RAS |
'MeshResult'
|
geometry preprocess. Successful bootstrap returns status="complete" |
'MeshResult'
|
and operation="computation_points" and is truthy. This means points |
'MeshResult'
|
were generated, not that a compiled mesh or hydraulically accepted |
'MeshResult'
|
model exists. |
Source code in ras_commander/geom/GeomMesh.py
| Python | |
|---|---|
5764 5765 5766 5767 5768 5769 5770 5771 5772 5773 5774 5775 5776 5777 5778 5779 5780 5781 5782 5783 5784 5785 5786 5787 5788 5789 5790 5791 5792 5793 5794 5795 5796 5797 5798 5799 5800 5801 5802 5803 5804 5805 5806 5807 5808 5809 5810 5811 5812 5813 5814 5815 5816 5817 5818 5819 5820 5821 5822 5823 5824 5825 5826 5827 5828 5829 5830 5831 5832 5833 5834 5835 5836 5837 5838 5839 5840 5841 5842 5843 5844 5845 5846 5847 5848 5849 5850 5851 5852 5853 5854 5855 5856 5857 5858 5859 5860 5861 5862 5863 5864 5865 5866 5867 5868 5869 5870 5871 5872 5873 5874 5875 5876 5877 5878 5879 5880 5881 5882 5883 5884 5885 5886 5887 5888 5889 5890 5891 5892 5893 5894 5895 5896 5897 5898 5899 5900 5901 5902 5903 5904 5905 5906 5907 5908 5909 5910 5911 5912 5913 5914 5915 5916 5917 5918 5919 5920 5921 5922 5923 | |
get_grid_anchor
staticmethod
¶
get_grid_anchor(geometry: Union[str, Number, Path], mesh_name: Optional[str] = None, mesh_index: int = 0, ras_object: Optional[RasPrj] = None) -> GridAnchor
Return the regular-grid lattice point of a compiled 2D flow area.
RAS Mapper starts a 2D area's regular computation-point grid half a
cell inside the area's bounding box: at (min x + dx/2, max y - dy/2)
of the stored perimeter, then one point every Spacing dx /
Spacing dy. This reads that point and the spacing from the
compiled geometry HDF. Pass the result to
GeomMesh.generate(grid_anchor=...) so a child or ensemble member
cut from this area re-meshes on the same lattice.
Read-only; nothing is loaded through .NET, so it runs on any platform with h5py.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
geometry
|
Union[str, Number, Path]
|
Compiled geometry HDF path ( |
required |
mesh_name
|
Optional[str]
|
2D flow area name (None = use |
None
|
mesh_index
|
int
|
0-based 2D-area index when |
0
|
ras_object
|
RasPrj
|
RasPrj instance for geometry-number lookup; None uses the global project. |
None
|
Returns:
| Type | Description |
|---|---|
GridAnchor
|
GridAnchor in the geometry's CRS and horizontal units, with |
GridAnchor
|
|
Raises:
| Type | Description |
|---|---|
FileNotFoundError
|
The geometry or its compiled HDF is missing. |
ValueError
|
The area is missing or has no positive spacing. |
Source code in ras_commander/geom/GeomMesh.py
generate
staticmethod
¶
generate(geom_number: Union[str, Number, Path], mesh_name: Optional[str] = None, mesh_index: int = 0, cell_size: Optional[float] = None, bl_spacing: Optional[float] = None, near_repeats: Optional[int] = None, protection_radius: Optional[int] = None, min_face_length_ratio: float = 0.05, max_iterations: int = 8, hecras_dir: Optional[Union[str, Path]] = None, bl_spacing_near: Optional[float] = None, bl_spacing_far: Optional[float] = None, ras_object=None, recompile_via_rasexe: bool = False, _require_current_hdf: bool = True, refinement_region_constraints: bool = False, strict_refinement_containment: bool = False, robustness_screening: bool = False, require_complete_products: bool = False, grid_anchor: Optional[Union[GridAnchor, Tuple[float, float]]] = None) -> MeshResult
Generate or regenerate a 2D mesh headlessly via text-first workflow.
The .g01 text file is the sole persistent output. The HDF is used only as an existing temporary workspace for .NET geometry loading and cell center extraction. ras-commander does not generate .g##.hdf from text.
Workflow
- Validate an existing content-current compiled .g##.hdf workspace, optionally refreshing it through HEC-RAS/Ras.exe. If the selected area has no computation points and refresh is enabled, bootstrap regular-interval points from the authored perimeter first. Native recompilation still checks full products.
- Read per-breakline spacing from .g01 text (preserve existing)
- Sync text spacing -> HDF (RegenerateMeshPoints reads HDF)
- Load .NET geometry -> perimeter, breaklines
- Generate seeds: RegenerateMeshPoints (primary) or GeneratePoints
- Fix loop (matches TryAutoFix tier ordering):
- Tier 0: Diagnose short perimeter segments while preserving the exact authored perimeter
- Tier 1: DuplicatePoints -> remove duplicate seed points
- Tier 2: MaxFaces -> add midpoint seeds (before ratio escalation)
- Tier 3: Perimeter errors -> remove bad vertices
- Tier 4: Escalate MinFaceLengthRatio [0.05 -> 0.25]
- Tier 5: Douglas-Peucker perimeter simplification (last resort)
- Extract cell centers via geom.Save() + h5py read
- Write cell centers to .g01 text - sole persistent output
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
geom_number
|
Union[str, Number, Path]
|
Geometry number ("01", 1) or path to .g## text file. |
required |
mesh_name
|
Optional[str]
|
Name of 2D flow area (None = use mesh_index). |
None
|
mesh_index
|
int
|
0-based index if mesh_name not provided. |
0
|
cell_size
|
Optional[float]
|
Base grid spacing in project units. When |
None
|
bl_spacing
|
Optional[float]
|
Legacy alias that applies the same positive value to both near and far breakline spacing when explicit values are omitted. |
None
|
near_repeats
|
Optional[int]
|
Number of offset seed rows on each side of breaklines. None preserves existing values from the .g01 text. |
None
|
protection_radius
|
Optional[int]
|
Enable 1-cell protection radius (0 or 1). None preserves existing values from the .g01 text. |
None
|
min_face_length_ratio
|
float
|
Positive, finite initial face-length ratio. The first attempt uses this value exactly; ratio escalation uses larger values from 0.05, 0.10, 0.15 and 0.25. Before HEC-RAS 6.6, the mesh constructor does not accept a ratio. On success the used ratio is written to geometry text and the Mapper workspace. Native geometry preprocessing remains the validation step. |
0.05
|
max_iterations
|
int
|
Maximum fix-and-retry attempts. |
8
|
hecras_dir
|
Optional[Union[str, Path]]
|
HEC-RAS installation whose RasMapperLib to load (6.0 or later). Defaults to the newest installed release found, regardless of the project's version. |
None
|
bl_spacing_near
|
Optional[float]
|
Optional override for near spacing in project units. If omitted, existing per-breakline values in the .g01 text are preserved (read from geometry, not defaulted). |
None
|
bl_spacing_far
|
Optional[float]
|
Optional override for far spacing in project units. If omitted, existing per-breakline values are preserved. |
None
|
ras_object
|
RasPrj
|
Optional RasPrj instance for multi-project support. |
None
|
recompile_via_rasexe
|
bool
|
If True, refresh a missing or content-stale
compiled geometry HDF through |
False
|
require_complete_products
|
bool
|
Forward strict completion to native recompilation and perimeter-repair preprocessing. Defaults False. |
False
|
refinement_region_constraints
|
bool
|
If False (default), evaluate and repair the saved-point mesh with breakline/structure constraints. Regions still shape point generation. True retains the earlier RAS Mapper mesh with region-edge constraints. A cached Mapper mesh may differ from a fresh text-point compile. |
False
|
strict_refinement_containment
|
bool
|
If True, retain the earlier one-cell inward margin for regions. False permits valid region extents across or outside the perimeter, as RAS Mapper does. |
False
|
robustness_screening
|
bool
|
Opt-in ras-commander optimization (default False). Screen requested/accepted ratios, 0.05 and 0.1 with saved-point, region-edge and unconstrained variants. Retain region seeds and structure constraints in production. Requires one 2D area and a ratio-aware native constructor (HEC-RAS 6.6+). Adds up to max_iterations repair rounds and 50% more seeds; failure prevents saving the screened mesh. Native preprocessing is still required. Diagnostics are returned in MeshResult.robustness_screening. |
False
|
grid_anchor
|
Optional[Union[GridAnchor, Tuple[float, float]]]
|
Optional lattice point for the regular (base) grid,
as a :class: |
None
|
Returns:
| Type | Description |
|---|---|
MeshResult
|
MeshResult with status, cell_count, face_count, fixes_applied, and |
MeshResult
|
the compiled geometry HDF path on success. |
MeshResult
|
records each persisted automatic repair's reason, ordered-ring |
MeshResult
|
SHA-256 hashes, maximum vertex-to-opposite-boundary displacement |
MeshResult
|
(both directions, project length units), signed area change |
MeshResult
|
(squared project units), and backup path. Coordinates retain the |
MeshResult
|
project's CRS. Repair mutates text and HDF, with a text backup; |
MeshResult
|
supply an initialized project with a referencing plan. |
Raises:
| Type | Description |
|---|---|
ValueError
|
The face-length ratio is not positive and finite. |
TypeError
|
|
RuntimeError
|
A perimeter repair handoff or subsequent mesh retry
fails, chained to the original mesh repair reason. Retries
share the existing |
Source code in ras_commander/geom/GeomMesh.py
| Python | |
|---|---|
5925 5926 5927 5928 5929 5930 5931 5932 5933 5934 5935 5936 5937 5938 5939 5940 5941 5942 5943 5944 5945 5946 5947 5948 5949 5950 5951 5952 5953 5954 5955 5956 5957 5958 5959 5960 5961 5962 5963 5964 5965 5966 5967 5968 5969 5970 5971 5972 5973 5974 5975 5976 5977 5978 5979 5980 5981 5982 5983 5984 5985 5986 5987 5988 5989 5990 5991 5992 5993 5994 5995 5996 5997 5998 5999 6000 6001 6002 6003 6004 6005 6006 6007 6008 6009 6010 6011 6012 6013 6014 6015 6016 6017 6018 6019 6020 6021 6022 6023 6024 6025 6026 6027 6028 6029 6030 6031 6032 6033 6034 6035 6036 6037 6038 6039 6040 6041 6042 6043 6044 6045 6046 6047 6048 6049 6050 6051 6052 6053 6054 6055 6056 6057 6058 6059 6060 6061 6062 6063 6064 6065 6066 6067 6068 6069 6070 6071 6072 6073 6074 6075 6076 6077 6078 6079 6080 6081 6082 6083 6084 6085 6086 6087 6088 6089 6090 6091 6092 6093 6094 6095 6096 6097 6098 6099 6100 6101 6102 6103 6104 6105 6106 6107 6108 6109 6110 6111 6112 6113 6114 6115 6116 6117 6118 6119 6120 6121 6122 6123 6124 6125 6126 6127 6128 6129 6130 6131 6132 6133 6134 6135 6136 6137 6138 6139 6140 6141 6142 6143 6144 6145 6146 6147 6148 6149 6150 6151 6152 6153 6154 6155 6156 6157 6158 6159 6160 6161 6162 6163 6164 6165 6166 6167 6168 6169 6170 6171 6172 6173 6174 6175 6176 6177 6178 6179 6180 6181 6182 6183 6184 6185 6186 6187 6188 6189 6190 6191 6192 6193 6194 6195 6196 6197 6198 6199 6200 6201 6202 6203 6204 6205 6206 6207 6208 6209 6210 6211 6212 6213 6214 6215 6216 6217 6218 6219 6220 6221 6222 6223 6224 6225 6226 6227 6228 6229 6230 6231 6232 6233 6234 6235 6236 6237 6238 6239 6240 6241 6242 6243 6244 6245 6246 6247 6248 6249 6250 6251 6252 6253 6254 6255 6256 6257 6258 6259 6260 6261 6262 6263 6264 6265 6266 6267 6268 6269 6270 6271 6272 6273 6274 6275 6276 6277 6278 6279 6280 6281 6282 6283 6284 6285 6286 6287 6288 6289 6290 6291 6292 6293 6294 6295 6296 6297 6298 6299 6300 6301 6302 6303 6304 6305 6306 6307 6308 6309 6310 6311 6312 6313 6314 6315 6316 6317 6318 6319 6320 6321 6322 6323 6324 6325 6326 6327 6328 6329 6330 6331 6332 6333 6334 6335 6336 6337 6338 6339 6340 6341 6342 6343 6344 6345 6346 6347 6348 6349 6350 6351 6352 6353 6354 6355 6356 6357 6358 6359 6360 6361 6362 6363 6364 6365 6366 6367 6368 6369 6370 6371 6372 6373 6374 6375 6376 6377 6378 6379 6380 6381 6382 6383 6384 6385 6386 6387 6388 6389 6390 6391 6392 6393 6394 6395 6396 6397 6398 6399 6400 6401 6402 6403 6404 6405 6406 6407 6408 6409 6410 6411 6412 6413 6414 6415 6416 6417 6418 6419 6420 6421 6422 6423 6424 6425 6426 6427 6428 6429 6430 6431 6432 6433 6434 6435 6436 6437 6438 6439 6440 6441 6442 6443 6444 6445 6446 6447 6448 6449 6450 6451 6452 6453 6454 6455 6456 6457 6458 6459 6460 6461 6462 6463 6464 6465 6466 6467 6468 6469 6470 6471 6472 6473 6474 6475 6476 6477 6478 6479 6480 6481 6482 6483 6484 6485 6486 6487 6488 6489 6490 6491 6492 6493 6494 6495 6496 6497 6498 6499 6500 6501 6502 6503 6504 6505 6506 6507 6508 6509 6510 6511 6512 6513 6514 6515 6516 6517 6518 6519 6520 6521 6522 6523 6524 6525 6526 6527 6528 6529 6530 6531 6532 6533 6534 6535 6536 6537 6538 6539 6540 6541 6542 6543 6544 6545 6546 6547 6548 6549 6550 6551 6552 6553 6554 6555 6556 6557 6558 6559 6560 6561 6562 6563 6564 6565 6566 6567 6568 6569 6570 6571 6572 6573 6574 6575 6576 6577 6578 6579 6580 6581 6582 6583 6584 6585 6586 6587 6588 6589 6590 6591 6592 6593 6594 6595 6596 6597 6598 6599 6600 6601 6602 6603 6604 6605 6606 6607 6608 6609 6610 6611 6612 6613 6614 6615 6616 6617 6618 6619 6620 6621 6622 6623 6624 6625 6626 6627 6628 6629 6630 6631 6632 6633 6634 6635 6636 6637 6638 6639 6640 6641 6642 6643 6644 6645 6646 6647 6648 6649 6650 6651 6652 6653 6654 6655 6656 6657 6658 6659 6660 6661 6662 6663 6664 6665 6666 6667 6668 6669 6670 6671 6672 6673 6674 6675 6676 6677 6678 6679 6680 6681 6682 6683 6684 6685 6686 6687 6688 6689 6690 6691 6692 6693 6694 6695 6696 6697 6698 6699 6700 6701 6702 6703 6704 6705 6706 6707 6708 6709 6710 6711 6712 6713 6714 6715 6716 6717 6718 6719 6720 6721 6722 6723 6724 6725 6726 6727 6728 6729 6730 6731 6732 6733 | |
generate_all
staticmethod
¶
generate_all(geom_number: Union[str, Number, Path], cell_size: Optional[float] = None, bl_spacing: Optional[float] = None, bl_spacing_near: Optional[float] = None, bl_spacing_far: Optional[float] = None, near_repeats: Optional[int] = None, protection_radius: Optional[int] = None, min_face_length_ratio: float = 0.05, max_iterations: int = 8, hecras_dir: Optional[Union[str, Path]] = None, ras_object: Optional['RasPrj'] = None, recompile_via_rasexe: bool = False, refinement_region_constraints: bool = False, strict_refinement_containment: bool = False, robustness_screening: bool = False, require_complete_products: bool = False) -> List[MeshResult]
Generate/repair all 2D mesh areas in a geometry file.
Discovers every 2D flow area in the geometry and calls
generate() for each one.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
geom_number
|
Union[str, Number, Path]
|
Geometry number (e.g. |
required |
cell_size
|
Optional[float]
|
Default mesh cell size. When |
None
|
bl_spacing
|
Optional[float]
|
Shorthand — sets both near and far breakline spacing. |
None
|
bl_spacing_near
|
Optional[float]
|
Breakline near-spacing override. |
None
|
bl_spacing_far
|
Optional[float]
|
Breakline far-spacing override. |
None
|
near_repeats
|
Optional[int]
|
Number of offset seed rows along breaklines. |
None
|
protection_radius
|
Optional[int]
|
Enable 1-cell protection radius (0 or 1). |
None
|
min_face_length_ratio
|
float
|
Minimum face-length ratio for mesh quality. |
0.05
|
max_iterations
|
int
|
Maximum fix-loop iterations per mesh area. |
8
|
hecras_dir
|
Optional[Union[str, Path]]
|
Override path to the HEC-RAS installation directory. |
None
|
ras_object
|
RasPrj
|
Optional RasPrj instance for multi-project support. |
None
|
recompile_via_rasexe
|
bool
|
If True, refresh a missing or content-stale
compiled geometry HDF through |
False
|
require_complete_products
|
bool
|
Forward strict completion to all native recompilation and mesh-repair calls. Defaults False. |
False
|
refinement_region_constraints
|
bool
|
Include region edges in mesh constraints (RAS Mapper compatibility); defaults to False. |
False
|
strict_refinement_containment
|
bool
|
Apply the old inward region margin; defaults to False. |
False
|
robustness_screening
|
bool
|
Forward the opt-in screening described by generate(). Currently requires a single 2D flow area. |
False
|
Returns:
| Type | Description |
|---|---|
List[MeshResult]
|
List of MeshResult, one per 2D flow area. |
Source code in ras_commander/geom/GeomMesh.py
| Python | |
|---|---|
6735 6736 6737 6738 6739 6740 6741 6742 6743 6744 6745 6746 6747 6748 6749 6750 6751 6752 6753 6754 6755 6756 6757 6758 6759 6760 6761 6762 6763 6764 6765 6766 6767 6768 6769 6770 6771 6772 6773 6774 6775 6776 6777 6778 6779 6780 6781 6782 6783 6784 6785 6786 6787 6788 6789 6790 6791 6792 6793 6794 6795 6796 6797 6798 6799 6800 6801 6802 6803 6804 6805 6806 6807 6808 6809 6810 6811 6812 6813 6814 6815 6816 6817 6818 6819 6820 6821 6822 6823 6824 6825 6826 6827 | |
detect_bc_conflicts
staticmethod
¶
Detect perimeter faces covered by 2+ BC lines.
Reads the boundary condition lines HEC-RAS stores in
Geometry/Boundary Condition Lines (Attributes Name,
SA-2D and Type with Polyline Info/Parts/Points)
and, for each 2D flow area named in SA-2D, its perimeter faces:
faces whose Faces Cell Indexes include a ghost cell (an index at or
above the area's Attributes Cell Count), drawn from
Faces FacePoint Indexes, FacePoints Coordinate and
Faces Perimeter Info/Values. A face is reported when two or
more of the area's BC lines lie within 0.01 * cell_size of it.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
geom_hdf_path
|
Union[str, Path]
|
Path to a compiled .g##.hdf file (a plan HDF, which carries the same geometry, also works). |
required |
cell_size
|
float
|
Mesh cell size for intersection buffer scaling. |
required |
Returns:
| Type | Description |
|---|---|
List[BCConflict]
|
List of BCConflict (one per conflicting face), in 2D-area and face |
List[BCConflict]
|
order. |
List[BCConflict]
|
|
``External`` or ``Internal``
|
the geometry HDF does not record |
List[BCConflict]
|
the hydraulic boundary type (Normal Depth, Flow Hydrograph, ...), |
List[BCConflict]
|
which belongs to the unsteady flow file. |
List[BCConflict]
|
therefore filled only from a plan HDF, whose |
List[BCConflict]
|
|
List[BCConflict]
|
entries name the 2D area and BC line; it is |
List[BCConflict]
|
geometry HDF. Areas without |
List[BCConflict]
|
example an uncompiled geometry) yield no conflicts. |
Source code in ras_commander/geom/GeomMesh.py
| Python | |
|---|---|
6829 6830 6831 6832 6833 6834 6835 6836 6837 6838 6839 6840 6841 6842 6843 6844 6845 6846 6847 6848 6849 6850 6851 6852 6853 6854 6855 6856 6857 6858 6859 6860 6861 6862 6863 6864 6865 6866 6867 6868 6869 6870 6871 6872 6873 6874 6875 6876 6877 6878 6879 6880 6881 6882 6883 6884 6885 6886 6887 6888 6889 6890 6891 6892 6893 6894 6895 6896 6897 6898 6899 6900 6901 6902 6903 6904 6905 | |
fix_bc_conflicts
staticmethod
¶
fix_bc_conflicts(geom_hdf_path: Union[str, Path], cell_size: float, dry_run: bool = False) -> BCFixResult
Detect and fix BC conflicts by trimming overlapping BC endpoints.
.. warning::
This method reads and writes the old per-area
Geometry/2D Flow Areas/<area>/BC Lines layout. HEC-RAS 6.x and
7.x geometry HDFs store 2D boundary condition lines in
Geometry/Boundary Condition Lines instead, so on those files it
finds no conflicts and changes nothing (an empty BCFixResult).
Use :meth:detect_bc_conflicts to detect conflicts in HEC-RAS
6.x/7.x geometry.
Prefers trimming Normal Depth BCs (least sensitive to endpoint placement). Falls back to trimming the longer BC when no Normal Depth BC is involved.
Trim is vertex-by-vertex from the endpoint nearest the conflicting face, stopping once the BC no longer intersects that face. If vertex-walking exhausts all vertices, interpolates a new endpoint.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
geom_hdf_path
|
Union[str, Path]
|
Path to compiled .g##.hdf file. |
required |
cell_size
|
float
|
Mesh cell size for buffer scaling. |
required |
dry_run
|
bool
|
If True, detect only — do not modify HDF. |
False
|
Returns:
| Type | Description |
|---|---|
BCFixResult
|
BCFixResult with conflicts_found, conflicts_fixed, unresolvable. |
Source code in ras_commander/geom/GeomMesh.py
| Python | |
|---|---|
6907 6908 6909 6910 6911 6912 6913 6914 6915 6916 6917 6918 6919 6920 6921 6922 6923 6924 6925 6926 6927 6928 6929 6930 6931 6932 6933 6934 6935 6936 6937 6938 6939 6940 6941 6942 6943 6944 6945 6946 6947 6948 6949 6950 6951 6952 6953 6954 6955 6956 6957 6958 6959 6960 6961 6962 6963 6964 6965 6966 6967 6968 6969 6970 6971 6972 6973 6974 6975 6976 6977 6978 6979 6980 6981 6982 6983 6984 6985 6986 6987 6988 6989 6990 6991 6992 6993 6994 6995 6996 6997 6998 6999 7000 7001 7002 7003 7004 7005 7006 7007 7008 7009 7010 7011 7012 7013 7014 7015 7016 7017 7018 7019 7020 7021 7022 7023 7024 7025 7026 7027 7028 7029 7030 7031 7032 7033 7034 7035 7036 7037 7038 7039 7040 7041 7042 7043 7044 7045 7046 7047 7048 7049 7050 7051 7052 7053 7054 7055 7056 7057 7058 7059 7060 7061 7062 7063 7064 7065 7066 7067 7068 7069 7070 7071 7072 7073 7074 7075 7076 7077 7078 7079 7080 7081 7082 7083 7084 7085 7086 7087 7088 7089 7090 7091 7092 7093 7094 7095 7096 7097 7098 7099 7100 7101 7102 7103 7104 7105 7106 7107 7108 7109 7110 7111 7112 7113 7114 7115 7116 7117 7118 7119 7120 7121 7122 7123 7124 7125 7126 7127 7128 7129 7130 7131 7132 7133 | |
Result and audit records¶
For generate() and generate_all(), inspect MeshResult.ok/status, error
information and repair evidence rather than cell count alone.
MeshResult.status == "complete", MeshResult.ok and bool(result) report
that the requested operation succeeded. Error, exception, and unknown statuses
are false. operation identifies "computation_points" for bootstrap and
"mesh_generation" for mesh generation, including failed operations.
For generate_computation_points(), cell_count counts generated points;
geom_hdf_path is empty and the operation does not produce a compiled mesh.
Callers requiring a compiled mesh must perform and verify native geometry
preprocessing. Truthiness is not hydraulic acceptance.
Migration: Bootstrap previously returned status == "success" while
ok and truthiness were false. Bootstrap now returns status == "complete",
matching mesh generation. Replace checks for the old "success" string with
result.ok; inspect result.operation when the operation type matters.
DomainContainmentResult.ok means no recorded containment
violations. BCFixResult.ok means no unresolved conflicts in that result; these
are operation-specific states, not hydraulic acceptance criteria.
MeshResult
dataclass
¶
Result of a mesh operation, including computation-point bootstrap.
status="complete", ok and truthiness mean the requested operation
succeeded. operation identifies computation-point generation versus
mesh generation. Completion does not establish hydraulic acceptance.
Source code in ras_commander/geom/GeomMeshDataclasses.py
GridAnchor
dataclass
¶
One point of a 2D area's regular computation-point lattice.
RAS Mapper lays the regular (base) grid of a 2D flow area from the
area's own bounding box: the first point is half a cell inside the
minimum x and the maximum y, then one point every spacing_dx /
spacing_dy. A child area cut from a parent therefore gets a grid
that is offset from the parent's by a sub-cell vector. A GridAnchor
names a lattice point (and the spacing) that the regenerated grid must
pass through instead, so a child or ensemble member re-meshes on the
parent's lattice.
Coordinates and spacing are in the geometry's projected CRS and
horizontal units. Only the phase (x mod spacing_dx, y mod spacing_dy)
matters; any lattice point of the parent gives the same grid.
Attributes:
| Name | Type | Description |
|---|---|---|
x |
float
|
X coordinate of a lattice point. |
y |
float
|
Y coordinate of a lattice point. |
spacing_dx |
float
|
Lattice spacing in x (the base cell size). |
spacing_dy |
float
|
Lattice spacing in y. |
source |
str
|
Free-text provenance, such as the parent HDF and area name. |
Source code in ras_commander/geom/GeomMeshDataclasses.py
DomainContainmentResult
dataclass
¶
Pre-mesh containment evidence for one 2D flow area.
Source code in ras_commander/geom/GeomMeshDataclasses.py
to_dict
¶
Return machine-readable audit evidence without geometry payloads.
Source code in ras_commander/geom/GeomMeshDataclasses.py
DomainContainmentViolation
dataclass
¶
One mesh-owned feature that is not inside the eroded 2D domain.
Source code in ras_commander/geom/GeomMeshDataclasses.py
to_dict
¶
Return machine-readable violation evidence.
Source code in ras_commander/geom/GeomMeshDataclasses.py
BCConflict
dataclass
¶
A perimeter face covered by 2+ BC lines.
Source code in ras_commander/geom/GeomMeshDataclasses.py
BCFixResult
dataclass
¶
Result of BC conflict detection and repair.
Source code in ras_commander/geom/GeomMeshDataclasses.py
Mesh engine selection and qualification (experimental fast-mesh)¶
HEC-RAS is the default mesh engine. GeomMeshEngine.build_mesh writes a meshed
project copy with engine="native" (default), "fast-mesh" (explicit experimental
opt-in; not HEC software) or "auto". "auto" uses fast-mesh only with a valid
approval from RasEngineQualification. Run RasEngineQualification.validate_mesh on
your project before relying on fast-mesh, and report any gap with
write_gap_report. See the Mesh Engine guide and
the validation how-to.
GeomMeshEngine
¶
Engine-selectable 2D mesh generation (native HEC-RAS default; fast-mesh experimental).
All methods are static; do not instantiate this class.
Source code in ras_commander/geom/GeomMeshEngine.py
| Python | |
|---|---|
221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 | |
is_fast_mesh_available
staticmethod
¶
Return True when the fast-mesh executable can be located (it is not run).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
engine_path
|
Optional[Union[str, Path]]
|
Explicit executable path. Otherwise
|
None
|
Returns:
| Type | Description |
|---|---|
bool
|
Whether the executable resolves. |
Source code in ras_commander/geom/GeomMeshEngine.py
get_engine_info
staticmethod
¶
Describe the installed experimental fast-mesh engine.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
engine_path
|
Optional[Union[str, Path]]
|
Explicit executable path (see :meth: |
None
|
Returns:
| Type | Description |
|---|---|
dict
|
|
Dict[str, Any]
|
|
Dict[str, Any]
|
|
Raises:
| Type | Description |
|---|---|
FastMeshNotFoundError
|
The executable is not installed. |
FastMeshEngineError
|
The engine is incompatible with this adapter. |
Source code in ras_commander/geom/GeomMeshEngine.py
resolve_mesh_engine
staticmethod
¶
resolve_mesh_engine(geometry: Union[str, int, Path], engine: str = 'auto', profile: str = 'hec701-exact', repair: bool = False, seeds: str = 'stored', project: Optional[Union[str, Path, Any]] = None, engine_path: Optional[Union[str, Path]] = None, ras_object: Optional[Any] = None) -> Dict[str, Any]
Decide which mesh engine build_mesh would run, without running it.
native and fast-mesh resolve to themselves. auto resolves to
fast-mesh only when :meth:RasEngineQualification.status reports a valid
approval for this project, geometry, profile, repair and seeds settings;
otherwise to native.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
geometry
|
Union[str, int, Path]
|
Geometry number, |
required |
engine
|
str
|
|
'auto'
|
profile
|
str
|
fast-mesh profile ( |
'hec701-exact'
|
repair
|
bool
|
Seed and perimeter repair flag. |
False
|
seeds
|
str
|
|
'stored'
|
project
|
Optional[Union[str, Path, Any]]
|
|
None
|
engine_path
|
Optional[Union[str, Path]]
|
Explicit fast-mesh executable. |
None
|
ras_object
|
Optional[Any]
|
Optional |
None
|
Returns:
| Type | Description |
|---|---|
dict
|
|
Source code in ras_commander/geom/GeomMeshEngine.py
build_mesh
staticmethod
¶
build_mesh(geometry: Union[str, int, Path], dest_folder: Union[str, Path], engine: str = 'native', profile: str = 'hec701-exact', repair: bool = False, seeds: str = 'stored', plan: Optional[Union[str, int]] = None, hecras_version: Optional[str] = None, engine_path: Optional[Union[str, Path]] = None, areas: Optional[Sequence[str]] = None, timeout: float = 3600, project: Optional[Union[str, Path, Any]] = None, ras_object: Optional[Any] = None) -> MeshBuildResult
Write a meshed copy of a project with the selected engine.
The native HEC-RAS engine is the default. engine="fast-mesh" is an
explicit opt-in to the experimental Rust engine (not HEC software).
engine="auto" uses fast-mesh only when the project holds a valid
approval from :meth:RasEngineQualification.approve; any change to the
approved inputs or engine version reverts it to native. Run
:meth:RasEngineQualification.validate_mesh on your project before
relying on fast-mesh, and file an issue or PR for any gap it finds.
The source project is never modified: both engines write into
dest_folder, which must be new and outside the source.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
geometry
|
Union[str, int, Path]
|
Geometry number ( |
required |
dest_folder
|
Union[str, Path]
|
New folder for the meshed project copy. |
required |
engine
|
str
|
|
'native'
|
profile
|
str
|
fast-mesh profile: |
'hec701-exact'
|
repair
|
bool
|
fast-mesh |
False
|
seeds
|
str
|
|
'stored'
|
plan
|
Optional[Union[str, int]]
|
Native only: plan used for geometry preprocessing. Default: the
first plan in |
None
|
hecras_version
|
Optional[str]
|
Native only: HEC-RAS version or |
None
|
engine_path
|
Optional[Union[str, Path]]
|
Explicit fast-mesh executable. |
None
|
areas
|
Optional[Sequence[str]]
|
2D area names to mesh, only with |
None
|
timeout
|
float
|
Seconds allowed for the engine run. |
3600
|
project
|
Optional[Union[str, Path, Any]]
|
|
None
|
ras_object
|
Optional[Any]
|
Optional |
None
|
Returns:
| Type | Description |
|---|---|
MeshBuildResult
|
Engine used, reason, version and output paths. |
Raises:
| Type | Description |
|---|---|
FastMeshNotFoundError
|
fast-mesh requested but not installed. |
FastMeshEngineError
|
fast-mesh failed or refused the input. |
RuntimeError
|
Native preprocessing failed. |
Source code in ras_commander/geom/GeomMeshEngine.py
| Python | |
|---|---|
321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 | |
MeshBuildResult
dataclass
¶
Outcome of :meth:GeomMeshEngine.build_mesh.
Attributes:
| Name | Type | Description |
|---|---|---|
engine |
str
|
Engine that ran: |
requested_engine |
str
|
The |
resolution_reason |
str
|
Why that engine ran (for |
engine_version |
Optional[str]
|
fast-mesh version, or the HEC-RAS version label for native. |
project_folder |
Path
|
The written project copy. |
geometry_file |
Path
|
The meshed |
geometry_hdf |
Path
|
The meshed |
profile |
Optional[str]
|
fast-mesh profile ( |
seeds |
str
|
|
repair |
bool
|
Whether seed and perimeter repair was requested. |
manifest |
Optional[Dict[str, Any]]
|
fast-mesh run manifest ( |
preprocess |
Any
|
Native |
engine_details |
Dict[str, Any]
|
Engine identity (version, commit, executable digest) without paths. |
Source code in ras_commander/geom/GeomMeshEngine.py
RasEngineQualification
¶
Qualify, approve and resolve experimental engines per project.
All methods are static; do not instantiate this class.
The native engine stays the default. An experimental engine runs by default for a project only with a saved approval whose input fingerprints and engine version still match. Run the validation API on your project before relying on a Rust engine; file an issue or PR for any gap it finds, and keep private project data out.
Source code in ras_commander/RasEngineQualification.py
| Python | |
|---|---|
600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 | |
register_engine
staticmethod
¶
Register an engine and its equivalence check (extension point).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
spec
|
EngineSpec
|
Engine registration. |
required |
replace
|
bool
|
Allow replacing an existing registration. |
False
|
Returns:
| Type | Description |
|---|---|
EngineSpec
|
The registered spec. |
Source code in ras_commander/RasEngineQualification.py
unregister_engine
staticmethod
¶
Remove a registration added with :meth:register_engine. Built-ins are re-registered on reset.
Source code in ras_commander/RasEngineQualification.py
registered_engines
staticmethod
¶
List registered engines (schema engine_registry).
Returns:
| Type | Description |
|---|---|
DataFrame
|
|
DataFrame
|
|
Source code in ras_commander/RasEngineQualification.py
validate
staticmethod
¶
validate(engine: str, project: Optional[Union[str, Path, Any]] = None, **kwargs) -> EngineQualificationReport
Run the registered equivalence check for engine.
Raises:
| Type | Description |
|---|---|
KeyError
|
Unknown engine. |
NotImplementedError
|
The engine has no equivalence check yet. |
Source code in ras_commander/RasEngineQualification.py
compare_mesh_tables
staticmethod
¶
compare_mesh_tables(reference_hdf: Union[str, Path], candidate_hdf: Union[str, Path]) -> pd.DataFrame
Compare the 15 mesh tables of every 2D area in two geometry HDF files.
Comparison is exact: same shape, same dtype, same bytes (-0.0 and
0.0 differ). Only counts and indices are reported, never values.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
reference_hdf
|
Union[str, Path]
|
Native HEC-RAS geometry HDF (the reference). |
required |
candidate_hdf
|
Union[str, Path]
|
Candidate geometry HDF (for example fast-mesh's). |
required |
Returns:
| Type | Description |
|---|---|
DataFrame
|
One row per area and table (schema |
Source code in ras_commander/RasEngineQualification.py
validate_mesh
staticmethod
¶
validate_mesh(project: Optional[Union[str, Path, Any]] = None, geometry: Union[str, int, Path] = None, profile: str = 'hec701-exact', repair: bool = False, seeds: str = 'stored', plan: Optional[Union[str, int]] = None, hecras_version: str = '7.0.1', workspace: Optional[Union[str, Path]] = None, keep_projects: bool = False, engine_path: Optional[Union[str, Path]] = None, timeout: float = 3600, write_gap_report: bool = True, ras_object: Optional[Any] = None) -> EngineQualificationReport
Prove (or disprove) that fast-mesh reproduces HEC-RAS's mesh for one geometry.
Run this on your own project before relying on the experimental fast-mesh engine. The source project is never modified:
- The native reference is built on a staged copy: HEC-RAS
hecras_versiongeometry preprocessing throughGeomPreprocessor.run_geometry_preprocessor(afterGeomMesh.generate_allwhenseeds="generated"). - fast-mesh meshes another copy (
mesh --out-dir) from the source geometry text and source geometry HDF. - The 15 mesh tables of every 2D area are compared byte for byte, and
the run manifest is checked (schema, validation, profile and label,
official_equivalent, output hashes, warnings). - The source tree fingerprint is checked before and after.
When the result is not equivalent and the native reference succeeded,
a gap report (markdown and JSON, no project data) is written to the
workspace. Nothing is posted. When it is equivalent, call
report.approve() to let engine="auto" use fast-mesh for this
geometry and these settings.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
project
|
Optional[Union[str, Path, Any]]
|
|
None
|
geometry
|
Union[str, int, Path]
|
Geometry number, |
None
|
profile
|
str
|
Must be |
'hec701-exact'
|
repair
|
bool
|
fast-mesh |
False
|
seeds
|
str
|
|
'stored'
|
plan
|
Optional[Union[str, int]]
|
Plan for native preprocessing (default: first plan using the geometry). |
None
|
hecras_version
|
str
|
Reference HEC-RAS version (default |
'7.0.1'
|
workspace
|
Optional[Union[str, Path]]
|
Folder for staged copies and reports (default: a new temp folder). Keep it short; HEC-RAS needs short paths. |
None
|
keep_projects
|
bool
|
Keep the two meshed project copies after comparison. |
False
|
engine_path
|
Optional[Union[str, Path]]
|
Explicit fast-mesh executable. |
None
|
timeout
|
float
|
Seconds allowed for each engine run. |
3600
|
write_gap_report
|
bool
|
Write the gap-report bundle on non-equivalence. |
True
|
ras_object
|
Optional[Any]
|
Optional |
None
|
Returns:
| Type | Description |
|---|---|
EngineQualificationReport
|
|
EngineQualificationReport
|
|
EngineQualificationReport
|
output could not be compared), |
EngineQualificationReport
|
|
EngineQualificationReport
|
|
EngineQualificationReport
|
executable resolved at the start is not the build that produced the |
EngineQualificationReport
|
candidate). Only |
Source code in ras_commander/RasEngineQualification.py
| Python | |
|---|---|
726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 | |
approve
staticmethod
¶
approve(report: EngineQualificationReport, user: Optional[str] = None, note: Optional[str] = None, engine_path: Optional[Union[str, Path]] = None) -> EngineApprovalStatus
Save an approval from a fully equivalent qualification report.
Writes <project>/.ras-commander/engine_approvals.json (the only
write this module makes to a project). The inputs and the installed
engine must still match the report.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
report
|
EngineQualificationReport
|
Report from :meth: |
required |
user
|
Optional[str]
|
Recorded approver (default: the signed-in user name). |
None
|
note
|
Optional[str]
|
Optional free-text note. |
None
|
engine_path
|
Optional[Union[str, Path]]
|
Explicit engine executable for the version check. |
None
|
Returns:
| Type | Description |
|---|---|
EngineApprovalStatus
|
The saved record, valid. |
Raises:
| Type | Description |
|---|---|
ValueError
|
The report is not equivalent, or the inputs or engine changed. |
Source code in ras_commander/RasEngineQualification.py
| Python | |
|---|---|
940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 | |
status
staticmethod
¶
status(project: Optional[Union[str, Path, Any]] = None, engine: str = 'fast-mesh', scope: Optional[Union[str, int, Path]] = None, config: Optional[Mapping[str, Any]] = None, engine_path: Optional[Union[str, Path]] = None) -> List[EngineApprovalStatus]
Check saved approvals against the current inputs and installed engine.
Approvals belong to one project file. A RasPrj, a .prj path or a
folder with a single .prj returns only that project's records; a
folder holding several projects returns every project's records.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
project
|
Optional[Union[str, Path, Any]]
|
|
None
|
engine
|
str
|
Engine name. |
'fast-mesh'
|
scope
|
Optional[Union[str, int, Path]]
|
Limit to one scope (for fast-mesh, the geometry: |
None
|
config
|
Optional[Mapping[str, Any]]
|
Limit to records with exactly this configuration
(for fast-mesh: |
None
|
engine_path
|
Optional[Union[str, Path]]
|
Explicit engine executable for the version check. |
None
|
Returns:
| Type | Description |
|---|---|
list[EngineApprovalStatus]
|
One entry per matching record, with |
List[EngineApprovalStatus]
|
|
Source code in ras_commander/RasEngineQualification.py
| Python | |
|---|---|
1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 | |
list_approvals
staticmethod
¶
list_approvals(project: Optional[Union[str, Path, Any]] = None, engine_path: Optional[Union[str, Path]] = None) -> pd.DataFrame
List every saved approval with its current validity (schema engine_approvals).
Returns:
| Type | Description |
|---|---|
DataFrame
|
One row per record. |
Source code in ras_commander/RasEngineQualification.py
revoke
staticmethod
¶
revoke(project: Optional[Union[str, Path, Any]] = None, engine: str = 'fast-mesh', scope: Optional[Union[str, int, Path]] = None, config: Optional[Mapping[str, Any]] = None) -> int
Remove saved approvals; the project reverts to the native engine for them.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
project
|
Optional[Union[str, Path, Any]]
|
|
None
|
engine
|
str
|
Engine name. |
'fast-mesh'
|
scope
|
Optional[Union[str, int, Path]]
|
Limit to one scope (default: every scope of |
None
|
config
|
Optional[Mapping[str, Any]]
|
Limit to exactly this configuration. |
None
|
Returns:
| Type | Description |
|---|---|
int
|
Number of records removed. |
Source code in ras_commander/RasEngineQualification.py
resolve_engine
staticmethod
¶
resolve_engine(project: Union[str, Path, Any], family: str, scope: Optional[Union[str, int, Path]] = None, config: Optional[Mapping[str, Any]] = None, engine_path: Optional[Union[str, Path]] = None) -> Dict[str, Any]
Decide which engine runs by default for a family, scope and configuration.
The platform default wins when the family has one. Otherwise the first
registered engine with a valid approval runs; without one, the native
engine runs. Only GeomMeshEngine.build_mesh(engine="auto") consults
this today; the HDF, mapping and DSS paths are unchanged.
Returns:
| Type | Description |
|---|---|
dict
|
|
Source code in ras_commander/RasEngineQualification.py
write_gap_report
staticmethod
¶
write_gap_report(report: EngineQualificationReport, output_dir: Union[str, Path], include_project_data: bool = False) -> Dict[str, str]
Write a gap-report bundle (markdown and JSON) for a non-equivalent result.
By default the bundle holds no project data: area names become
area-1, area-2, ..., and no coordinates, values, paths, project
names or user names are written. include_project_data=True adds
area names and file names; review the bundle before sharing it.
The bundle includes a pre-filled GitHub issue for the fast-mesh repository and guidance for preparing a PR. Nothing is posted.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
report
|
EngineQualificationReport
|
A qualification report. |
required |
output_dir
|
Union[str, Path]
|
Folder for |
required |
include_project_data
|
bool
|
Opt in to area and file names. |
False
|
Returns:
| Type | Description |
|---|---|
dict
|
|
Source code in ras_commander/RasEngineQualification.py
| Python | |
|---|---|
1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 | |
EngineQualificationReport
dataclass
¶
Result of an engine equivalence check (for fast-mesh: :meth:RasEngineQualification.validate_mesh).
tables has one row per area and mesh table (schema
engine_mesh_qualification). equivalent is True only when every
table is byte-identical, every engine check passed and the source project
was not modified. Call :meth:approve to save an approval.
Source code in ras_commander/RasEngineQualification.py
summary
¶
Counts only: no paths, names or coordinates.
Source code in ras_commander/RasEngineQualification.py
to_dict
¶
JSON-serializable form (ras-commander-engine-qualification/v1).
Source code in ras_commander/RasEngineQualification.py
approve
¶
approve(user: Optional[str] = None, note: Optional[str] = None, engine_path: Optional[Union[str, Path]] = None) -> 'EngineApprovalStatus'
Save an approval for this report; see :meth:RasEngineQualification.approve.
Source code in ras_commander/RasEngineQualification.py
EngineSpec
dataclass
¶
Registration of an engine for qualification and default resolution.
Attributes:
| Name | Type | Description |
|---|---|---|
name |
str
|
Engine identifier (for example |
family |
str
|
Operation family: |
platform_default |
bool
|
True when the engine already runs by default (approvals are then not needed and not consulted). |
status |
str
|
|
description |
str
|
One-line description. |
validator |
Optional[Callable[..., 'EngineQualificationReport']]
|
Equivalence check |
fingerprint |
Optional[Callable[[Path, str], Dict[str, Dict[str, Optional[str]]]]]
|
|
version_probe |
Optional[Callable[[Optional[Union[str, Path]]], Dict[str, Any]]]
|
|
Source code in ras_commander/RasEngineQualification.py
EngineApprovalStatus
dataclass
¶
Validity of one saved approval (see :meth:RasEngineQualification.status).