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.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

landlab_triangle-1.0.0.tar.gz (149.4 kB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

landlab_triangle-1.0.0-py3-none-win_amd64.whl (264.8 kB view details)

Uploaded Python 3Windows x86-64

landlab_triangle-1.0.0-py3-none-manylinux_2_17_aarch64.manylinux2014_aarch64.manylinux_2_28_aarch64.whl (252.9 kB view details)

Uploaded Python 3manylinux: glibc 2.17+ ARM64manylinux: glibc 2.28+ ARM64

landlab_triangle-1.0.0-py3-none-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_28_x86_64.whl (253.2 kB view details)

Uploaded Python 3manylinux: glibc 2.28+ x86-64manylinux: glibc 2.5+ x86-64

landlab_triangle-1.0.0-py3-none-macosx_14_0_arm64.whl (246.3 kB view details)

Uploaded Python 3macOS 14.0+ ARM64

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

Hashes for landlab_triangle-1.0.0.tar.gz
Algorithm Hash digest
SHA256 bbea5da617b02a755dc4fc4421518cef983a7caa79e452ac64a3c86a90d03cf9
MD5 c27f4a7102fa902c79575083cf73afce
BLAKE2b-256 177ce421cb65dc348cbc51b017f662316384b305f3617547166bb94d191420a4

See more details on using hashes here.

Provenance

The following attestation bundles were made for landlab_triangle-1.0.0.tar.gz:

Publisher: wheels.yml on ethan-pierce/landlab-triangle

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file landlab_triangle-1.0.0-py3-none-win_amd64.whl.

File metadata

File hashes

Hashes for landlab_triangle-1.0.0-py3-none-win_amd64.whl
Algorithm Hash digest
SHA256 db6b5ceabaff5bfeaa99a37a0e13961a0b478b52977c39e7f84cf99a23e71dea
MD5 7cbfb7176e1db7f2e1358cbdfb84ef2c
BLAKE2b-256 7f7f9934cae3bcd3ed341b5daccbed6cfd26e73a43f93b653d5a4b3e3fbf2ea1

See more details on using hashes here.

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

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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

File hashes

Hashes for landlab_triangle-1.0.0-py3-none-manylinux_2_17_aarch64.manylinux2014_aarch64.manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 c8a8c82b4da1132c75a3e4505af219458772efea88d263c150fabd4e9a573be1
MD5 5540164e2ff2a520d5a509d12ce8f9d2
BLAKE2b-256 a3c590dd406996fc8115efebd2d986684d13a38a27643b21c38ca7e549e39e00

See more details on using hashes here.

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

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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

File hashes

Hashes for landlab_triangle-1.0.0-py3-none-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 4df47b5f14ee7f6a432369df3add80ca962a2e6e2cc1aca3885dd7b486b3c795
MD5 df37e76ab7bcb75af5b9c9331e6c9031
BLAKE2b-256 eeee3a78b792deb2b54752fa9eb4872b90a63b183eca24a313bfbe5c5454755e

See more details on using hashes here.

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

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file landlab_triangle-1.0.0-py3-none-macosx_14_0_arm64.whl.

File metadata

File hashes

Hashes for landlab_triangle-1.0.0-py3-none-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 4059ffd4a710d11da8140ecb74cfb72b6b7ae2983bc7e0703d87f377d274c018
MD5 605cbd031f9b36c21207e7ad59c52585
BLAKE2b-256 d91de82663ddc38a32aacfe5ffc171e46433601be4da48e1fbb6a1d6e05d867a

See more details on using hashes here.

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

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Release history Release notifications | RSS feed

This release

1.0.0 This release

5 files

0.0.2

2 files

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