Skip to main content

landlab-triangle

View Landlab Documentation

View triangle Documentation

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.

Metadata

Release files for landlab-triangle 1.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for landlab-triangle 1.0.0
File Size Uploaded Provenance Actions
landlab_triangle-1.0.0.tar.gz 149.4 kB With provenance Details for landlab_triangle-1.0.0.tar.gz

Built distributions (wheels)

Table of built distributions (wheels) for landlab-triangle 1.0.0
File Actions
landlab_triangle-1.0.0-py3-none-win_amd64.whl Python 3 none Windows x86-64 Details for landlab_triangle-1.0.0-py3-none-win_amd64.whl
landlab_triangle-1.0.0-py3-none-manylinux_2_17_aarch64.manylinux2014_aarch64.manylinux_2_28_aarch64.whl Python 3 none Linux glibc 2.17+ ARM64, Linux glibc 2.28+ ARM64 Details for landlab_triangle-1.0.0-py3-none-manylinux_2_17_aarch64.manylinux2014_aarch64.manylinux_2_28_aarch64.whl
landlab_triangle-1.0.0-py3-none-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_28_x86_64.whl Python 3 none Linux glibc 2.5+ x86-64, Linux glibc 2.28+ x86-64 Details for landlab_triangle-1.0.0-py3-none-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_28_x86_64.whl
landlab_triangle-1.0.0-py3-none-macosx_14_0_arm64.whl Python 3 none macOS 14.0+ ARM64 Details for landlab_triangle-1.0.0-py3-none-macosx_14_0_arm64.whl

Total release size: 1.2 MB

Release files / landlab_triangle-1.0.0.tar.gz

Download URL landlab_triangle-1.0.0.tar.gz
Size 149.4 kB
Tags Source
SHA-256 checksum
How to use checksums
bbea5da617b02a755dc4fc4421518cef983a7caa79e452ac64a3c86a90d03cf9
BLAKE2b-256 checksum
How to use checksums
177ce421cb65dc348cbc51b017f662316384b305f3617547166bb94d191420a4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Aug 22, 2026.

Transparency log

Release files / landlab_triangle-1.0.0-py3-none-win_amd64.whl

Download URL landlab_triangle-1.0.0-py3-none-win_amd64.whl
Size 264.8 kB
Tags Python 3 Windows x86-64
SHA-256 checksum
How to use checksums
db6b5ceabaff5bfeaa99a37a0e13961a0b478b52977c39e7f84cf99a23e71dea
BLAKE2b-256 checksum
How to use checksums
7f7f9934cae3bcd3ed341b5daccbed6cfd26e73a43f93b653d5a4b3e3fbf2ea1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Aug 22, 2026.

Transparency log

Release files / landlab_triangle-1.0.0-py3-none-manylinux_2_17_aarch64.manylinux2014_aarch64.manylinux_2_28_aarch64.whl

Download URL landlab_triangle-1.0.0-py3-none-manylinux_2_17_aarch64.manylinux2014_aarch64.manylinux_2_28_aarch64.whl
Size 252.9 kB
Tags Linux glibc 2.17+ ARM64 Linux glibc 2.28+ ARM64 Python 3
SHA-256 checksum
How to use checksums
c8a8c82b4da1132c75a3e4505af219458772efea88d263c150fabd4e9a573be1
BLAKE2b-256 checksum
How to use checksums
a3c590dd406996fc8115efebd2d986684d13a38a27643b21c38ca7e549e39e00
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Aug 22, 2026.

Transparency log

Release files / landlab_triangle-1.0.0-py3-none-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_28_x86_64.whl

Download URL landlab_triangle-1.0.0-py3-none-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_28_x86_64.whl
Size 253.2 kB
Tags Linux glibc 2.28+ x86-64 Linux glibc 2.5+ x86-64 Python 3
SHA-256 checksum
How to use checksums
4df47b5f14ee7f6a432369df3add80ca962a2e6e2cc1aca3885dd7b486b3c795
BLAKE2b-256 checksum
How to use checksums
eeee3a78b792deb2b54752fa9eb4872b90a63b183eca24a313bfbe5c5454755e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Aug 22, 2026.

Transparency log

Release files / landlab_triangle-1.0.0-py3-none-macosx_14_0_arm64.whl

Download URL landlab_triangle-1.0.0-py3-none-macosx_14_0_arm64.whl
Size 246.3 kB
Tags Python 3 macOS 14.0+ ARM64
SHA-256 checksum
How to use checksums
4059ffd4a710d11da8140ecb74cfb72b6b7ae2983bc7e0703d87f377d274c018
BLAKE2b-256 checksum
How to use checksums
d91de82663ddc38a32aacfe5ffc171e46433601be4da48e1fbb6a1d6e05d867a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Aug 22, 2026.

Transparency log

Security for landlab-triangle 1.0.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

All 5 files in this release have been uploaded with provenance metadata.

Select from 5 files

Attestation for landlab_triangle-1.0.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Aug 22, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

1.0.0 This release

5 release files Full provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page