landlab-triangle
This repository adds TriangleModelGrid, a new Landlab grid type that enables unstructured triangular meshes. Unlike Landlab's standard structured grids, TriangleModelGrid allows for complex geometries with irregular boundaries, interior holes, and variable grid resolution.
Uses Jonathan Shewchuk's Triangle software.
Installation
Installing from PyPI
pip install landlab-triangle
A compiled build of Triangle ships inside the wheel, so there is nothing else
to install. See NOTICE for the terms of the bundled Triangle, which
remains under Jonathan Shewchuk's non-commercial license.
Usage
Option 1: direct initialization
from landlab_triangle import TriangleModelGrid
# Boundary vertices in order. x and y are separate arguments, x first.
x_of_boundary = [0.0, 10.0, 12.0, 6.0, -1.0]
y_of_boundary = [0.0, -1.0, 8.0, 12.0, 7.0]
# Optional interior holes: each ring is a sequence of (x, y) vertices.
interior_rings = [[(4.0, 4.0), (6.0, 4.0), (6.0, 6.0), (4.0, 6.0)]]
grid = TriangleModelGrid(
x_of_boundary,
y_of_boundary,
interior_rings=interior_rings,
triangle_options="pqa1Devjz",
)
print(f"Number of nodes: {grid.number_of_nodes}")
print(f"Number of cells: {grid.number_of_cells}")
Option 2: from a dictionary
from landlab_triangle import TriangleModelGrid
# Create a grid from a dictionary with "x" and "y" keys
grid_params = {
"x": [0.0, 10.0, 12.0, 6.0, -1.0],
"y": [0.0, -1.0, 8.0, 12.0, 7.0],
"triangle_options": "pqa1Devjz",
}
grid = TriangleModelGrid.from_dict(grid_params)
Any keys beyond "x" and "y" pass through as keyword arguments to the
constructor.
Option 3: from a vector file
from landlab_triangle import TriangleModelGrid
# Build from any vector file GeoPandas can read (shapefile, GeoJSON,
# GeoPackage, ...). Interior rings in the file become holes automatically.
grid = TriangleModelGrid.from_vector_file(
"path/to/polygon.geojson",
triangle_options="pqDevjz",
timeout=10,
)
print(f"Number of nodes: {grid.number_of_nodes}")
Triangle options
The triangle_options parameter controls the behavior of the Triangle meshing software (default "pqDevjz"). Common options include:
- q: Quality mesh generation - ensures no angles smaller than N degrees (defaults to 20)
- a: Area constraint - limits the maximum area of triangles
Timeout: The timeout parameter (in seconds) prevents the meshing process from running indefinitely if Triangle encounters complex geometries. It defaults to 10.
Example with area constraint
# Reusing the boundary from Option 1, cap the maximum triangle area at 0.1.
grid = TriangleModelGrid(
x_of_boundary,
y_of_boundary,
triangle_options="pqa0.1Devjz", # 'a0.1' sets max area to 0.1
)
Plotting
Field-aware plotters live in landlab_triangle as free functions that take the
grid first and draw on the current axes (or one you pass as ax=). Each returns
the matplotlib artist, so a bare call followed by plt.show() just works.
There is one plotter per grid element — plot_node, plot_link, plot_patch,
plot_corner, plot_face, plot_cell — plus plot_vector for components and
plot_mesh for the bare skeleton. The value argument accepts either a
field-name string or a raw array.
import matplotlib.pyplot as plt
from landlab_triangle import TriangleModelGrid, plot_node, plot_cell, plot_vector
grid = TriangleModelGrid(
[0.0, 10.0, 12.0, 6.0, -1.0], [0.0, -1.0, 8.0, 12.0, 7.0], triangle_options="pqa1Devjz"
)
grid.add_field("elevation", grid.x_of_node + grid.y_of_node, at="node")
# Smooth node field over the full domain, including perimeter nodes
plot_node(grid, "elevation", cmap="terrain", colorbar_label="elevation (m)")
plt.show()
# Flat-colored Voronoi cells from a raw array
import numpy as np
plot_cell(grid, np.arange(grid.number_of_cells, dtype=float))
plt.show()
# Component vectors as arrows colored by magnitude
u = np.ones(grid.number_of_nodes)
plot_vector(grid, u, u, at="node")
plt.show()
Common matplotlib keywords (vmin, vmax, norm, alpha, shading, ...)
pass straight through to the underlying call. plot_node defaults to Gouraud
shading; pass shading="flat" for per-triangle color instead.
To reconstruct a vector from flux-at-links, map the link components to nodes
with Landlab's mappers (e.g. map_link_vector_components_to_node) first, then
call plot_vector on the results.
Contributing
Contributions are welcome. See CONTRIBUTING.md for how to set up a development environment and submit changes, and please review the Code of Conduct. If you need help, see SUPPORT.md.
Citation
If you use landlab-triangle in your work, please cite it. Citation metadata lives in CITATION.cff; GitHub renders it as a "Cite this repository" button in the sidebar. Each release is archived on Zenodo:
Pierce, E. landlab-triangle. https://doi.org/10.5281/zenodo.22058174
DOI 10.5281/zenodo.22058174 resolves to the latest version.
Contact
Questions, bugs, and feature requests go to the issue tracker. For private inquiries, email Ethan Pierce at ethan.g.pierce@dartmouth.edu.
License
landlab-triangle is released under the MIT License. It bundles a compiled build of Triangle, which is not MIT-licensed and remains under Jonathan Shewchuk's non-commercial terms; see NOTICE for details.
Acknowledgments
This work was supported by the National Science Foundation under Award 2104102 (OpenEarthScape). See CREDITS.md for the full list of contributors and acknowledgments.
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distributions
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file landlab_triangle-1.0.0.tar.gz.
File metadata
- Download URL: landlab_triangle-1.0.0.tar.gz
- Upload date:
- Size: 149.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
bbea5da617b02a755dc4fc4421518cef983a7caa79e452ac64a3c86a90d03cf9
|
|
| MD5 |
c27f4a7102fa902c79575083cf73afce
|
|
| BLAKE2b-256 |
177ce421cb65dc348cbc51b017f662316384b305f3617547166bb94d191420a4
|
Provenance
The following attestation bundles were made for landlab_triangle-1.0.0.tar.gz:
Publisher:
wheels.yml on ethan-pierce/landlab-triangle
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
landlab_triangle-1.0.0.tar.gz -
Subject digest:
bbea5da617b02a755dc4fc4421518cef983a7caa79e452ac64a3c86a90d03cf9 - Sigstore transparency entry: 2566290684
- Sigstore integration time:
-
Permalink:
ethan-pierce/landlab-triangle@0a2bff2d46b3217d2b7486b1e00bfbb7b036eda5 -
Branch / Tag:
refs/tags/v1.0.0 - Owner: https://github.com/ethan-pierce
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
wheels.yml@0a2bff2d46b3217d2b7486b1e00bfbb7b036eda5 -
Trigger Event:
push
-
Statement type:
File details
Details for the file landlab_triangle-1.0.0-py3-none-win_amd64.whl.
File metadata
- Download URL: landlab_triangle-1.0.0-py3-none-win_amd64.whl
- Upload date:
- Size: 264.8 kB
- Tags: Python 3, Windows x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
db6b5ceabaff5bfeaa99a37a0e13961a0b478b52977c39e7f84cf99a23e71dea
|
|
| MD5 |
7cbfb7176e1db7f2e1358cbdfb84ef2c
|
|
| BLAKE2b-256 |
7f7f9934cae3bcd3ed341b5daccbed6cfd26e73a43f93b653d5a4b3e3fbf2ea1
|
Provenance
The following attestation bundles were made for landlab_triangle-1.0.0-py3-none-win_amd64.whl:
Publisher:
wheels.yml on ethan-pierce/landlab-triangle
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
landlab_triangle-1.0.0-py3-none-win_amd64.whl -
Subject digest:
db6b5ceabaff5bfeaa99a37a0e13961a0b478b52977c39e7f84cf99a23e71dea - Sigstore transparency entry: 2566291569
- Sigstore integration time:
-
Permalink:
ethan-pierce/landlab-triangle@0a2bff2d46b3217d2b7486b1e00bfbb7b036eda5 -
Branch / Tag:
refs/tags/v1.0.0 - Owner: https://github.com/ethan-pierce
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
wheels.yml@0a2bff2d46b3217d2b7486b1e00bfbb7b036eda5 -
Trigger Event:
push
-
Statement type:
File details
Details for the file landlab_triangle-1.0.0-py3-none-manylinux_2_17_aarch64.manylinux2014_aarch64.manylinux_2_28_aarch64.whl.
File metadata
- Download URL: landlab_triangle-1.0.0-py3-none-manylinux_2_17_aarch64.manylinux2014_aarch64.manylinux_2_28_aarch64.whl
- Upload date:
- Size: 252.9 kB
- Tags: Python 3, manylinux: glibc 2.17+ ARM64, manylinux: glibc 2.28+ ARM64
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c8a8c82b4da1132c75a3e4505af219458772efea88d263c150fabd4e9a573be1
|
|
| MD5 |
5540164e2ff2a520d5a509d12ce8f9d2
|
|
| BLAKE2b-256 |
a3c590dd406996fc8115efebd2d986684d13a38a27643b21c38ca7e549e39e00
|
Provenance
The following attestation bundles were made for landlab_triangle-1.0.0-py3-none-manylinux_2_17_aarch64.manylinux2014_aarch64.manylinux_2_28_aarch64.whl:
Publisher:
wheels.yml on ethan-pierce/landlab-triangle
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
landlab_triangle-1.0.0-py3-none-manylinux_2_17_aarch64.manylinux2014_aarch64.manylinux_2_28_aarch64.whl -
Subject digest:
c8a8c82b4da1132c75a3e4505af219458772efea88d263c150fabd4e9a573be1 - Sigstore transparency entry: 2566291136
- Sigstore integration time:
-
Permalink:
ethan-pierce/landlab-triangle@0a2bff2d46b3217d2b7486b1e00bfbb7b036eda5 -
Branch / Tag:
refs/tags/v1.0.0 - Owner: https://github.com/ethan-pierce
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
wheels.yml@0a2bff2d46b3217d2b7486b1e00bfbb7b036eda5 -
Trigger Event:
push
-
Statement type:
File details
Details for the file landlab_triangle-1.0.0-py3-none-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_28_x86_64.whl.
File metadata
- Download URL: landlab_triangle-1.0.0-py3-none-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_28_x86_64.whl
- Upload date:
- Size: 253.2 kB
- Tags: Python 3, manylinux: glibc 2.28+ x86-64, manylinux: glibc 2.5+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4df47b5f14ee7f6a432369df3add80ca962a2e6e2cc1aca3885dd7b486b3c795
|
|
| MD5 |
df37e76ab7bcb75af5b9c9331e6c9031
|
|
| BLAKE2b-256 |
eeee3a78b792deb2b54752fa9eb4872b90a63b183eca24a313bfbe5c5454755e
|
Provenance
The following attestation bundles were made for landlab_triangle-1.0.0-py3-none-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_28_x86_64.whl:
Publisher:
wheels.yml on ethan-pierce/landlab-triangle
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
landlab_triangle-1.0.0-py3-none-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_28_x86_64.whl -
Subject digest:
4df47b5f14ee7f6a432369df3add80ca962a2e6e2cc1aca3885dd7b486b3c795 - Sigstore transparency entry: 2566290907
- Sigstore integration time:
-
Permalink:
ethan-pierce/landlab-triangle@0a2bff2d46b3217d2b7486b1e00bfbb7b036eda5 -
Branch / Tag:
refs/tags/v1.0.0 - Owner: https://github.com/ethan-pierce
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
wheels.yml@0a2bff2d46b3217d2b7486b1e00bfbb7b036eda5 -
Trigger Event:
push
-
Statement type:
File details
Details for the file landlab_triangle-1.0.0-py3-none-macosx_14_0_arm64.whl.
File metadata
- Download URL: landlab_triangle-1.0.0-py3-none-macosx_14_0_arm64.whl
- Upload date:
- Size: 246.3 kB
- Tags: Python 3, macOS 14.0+ ARM64
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4059ffd4a710d11da8140ecb74cfb72b6b7ae2983bc7e0703d87f377d274c018
|
|
| MD5 |
605cbd031f9b36c21207e7ad59c52585
|
|
| BLAKE2b-256 |
d91de82663ddc38a32aacfe5ffc171e46433601be4da48e1fbb6a1d6e05d867a
|
Provenance
The following attestation bundles were made for landlab_triangle-1.0.0-py3-none-macosx_14_0_arm64.whl:
Publisher:
wheels.yml on ethan-pierce/landlab-triangle
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
landlab_triangle-1.0.0-py3-none-macosx_14_0_arm64.whl -
Subject digest:
4059ffd4a710d11da8140ecb74cfb72b6b7ae2983bc7e0703d87f377d274c018 - Sigstore transparency entry: 2566291450
- Sigstore integration time:
-
Permalink:
ethan-pierce/landlab-triangle@0a2bff2d46b3217d2b7486b1e00bfbb7b036eda5 -
Branch / Tag:
refs/tags/v1.0.0 - Owner: https://github.com/ethan-pierce
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
wheels.yml@0a2bff2d46b3217d2b7486b1e00bfbb7b036eda5 -
Trigger Event:
push
-
Statement type: