Skip to main content

Run from a TOML file

A TOML file records a run, so you can keep it in Git and repeat it exactly. The same file works on the command line and in Python (MeshSpec).

The file

cell_size = 32.0
transition_rows = [1, 2]
water_removal = "centre"
output = "mesh_net.nc"

[domain]
path = "model.gpkg"
layer = "modelgebied"

[[refinement_areas]]
path = "model.gpkg"
layer = "verfijning"
level = "refinement"   # a column name, or one integer level

[[water_areas]]
path = "model.gpkg"
layer = "water"

Paths are relative to the TOML file. Other keys: crs (for layers without CRS), origin = [x, y] (a lattice point) and more [[refinement_areas]] or [[water_areas]] tables. An unknown key or an invalid value is an error that names the key and the reason.

Generate on the command line

refined-quads generate run.toml
wrote C:\Users\Bake\AppData\Local\Temp\tmpwwtz8hnd\mesh_net.nc
lattice: origin (154976, 462976), base cell 32, 2 levels, unit 8
nodes: 807, cells: 857
cells per level: 0 (32): 341, 1 (16): 148, 2 (8): 368
nodes off the lattice: 0
duplicate nodes (information): 0
split edges: 0
hanging nodes: 0
2:1 balance violations: 0
non-orthogonal edges (> 0.30): 0 (worst 0.000)
clockwise cells: 0
unrecognised cells: 0
holes MeshKernel closes (information): 0
valid: yes
0

Options override the file: -o other_net.nc, --cell-size 25, --transition-rows 1 1, --water-removal inside, --crs EPSG:28992, --origin 155000 463000, and -v prints the progress.

The exit code is 0 when the mesh is written, 1 when the run failed (the orthogonality repair did not close; then mesh_net_raw.nc and mesh_net_problems.gpkg are written next to the output) and 2 for invalid input or arguments.

Look at a mesh

refined-quads info shows the lattice, the cells per refinement level and the checks of any UGRID file, also a D-HYDRO net file with a 1D network:

refined-quads info mesh_net.nc
C:\Users\Bake\AppData\Local\Temp\tmpwwtz8hnd\mesh_net.nc
crs: EPSG:28992
lattice: origin (154976, 462976), base cell 32, 2 levels, unit 8
nodes: 807, cells: 857
cells per level: 0 (32): 341, 1 (16): 148, 2 (8): 368
nodes off the lattice: 0
duplicate nodes (information): 0
split edges: 0
hanging nodes: 0
2:1 balance violations: 0
non-orthogonal edges (> 0.30): 0 (worst 0.000)
clockwise cells: 0
unrecognised cells: 0
holes MeshKernel closes (information): 0
valid: yes
0

The same in Python

from refined_quads import MeshSpec

spec = MeshSpec.from_toml(workdir / "run.toml")
quad_mesh = spec.replace(cell_size=25.0).generate()
print(quad_mesh)
Mesh(nodes=1133, faces=1184, cell_size=25, levels=2, crs=EPSG:28992)