Learn PyINLA

Creating Meshes

Spatial domains, boundaries, and triangular meshes for SPDE‑style models.

Meshing

Mesh Generation

Build triangular meshes with fm_mesh_2d(). Control resolution, quality, and boundary extension.

Boundaries

Boundary Methods

Three approaches: loc_domain, non-convex hull, and hexagon lattice for geographic regions.

Examples

Country Examples

Ready-to-use meshes for Saudi Arabia, Lebanon, Norway, Brazil, and more. Learn how to load any country boundary.

Working with the Mesh Object

The fm_mesh_2d() function returns an FmMesh object containing all the mesh data needed for SPDE modeling.

# Print mesh summary
print(mesh.summary())
# FmMesh:
#   Manifold: R2
#   Vertices: 534
#   Triangles: 1024
#   Edges: 1557
#   x range: [0.0000, 100.0000]
#   y range: [0.0000, 100.0000]

Key Properties

Property Description Used in SPDE
mesh.n Number of mesh vertices (nodes) Dimension of spatial random effect
mesh.n_triangle Number of triangles in the mesh FEM integration
mesh.n_edge Number of edges in the mesh Graph connectivity
mesh.loc Vertex coordinates, shape (n, 2) Projector matrix A construction
mesh.tv Triangle-vertex indices, shape (n_triangle, 3) FEM matrices C, G (precision Q)
mesh.vv Vertex-vertex adjacency (edges), shape (n_edge, 2) Graph structure
mesh.tt Triangle-triangle adjacency, shape (n_triangle, 3) Mesh topology
mesh.bbox Bounding box dictionary Domain extent

Plotting the Mesh

# Plot mesh with matplotlib
import matplotlib.pyplot as plt
from matplotlib.tri import Triangulation

tri = Triangulation(mesh.loc[:, 0], mesh.loc[:, 1], mesh.tv)

fig, ax = plt.subplots(figsize=(8, 8))
ax.triplot(tri, 'b-', linewidth=0.3, alpha=0.6)
ax.scatter(mesh.loc[:, 0], mesh.loc[:, 1], s=2, c='red')
ax.set_aspect('equal')
ax.set_title(f'Mesh: {mesh.n} vertices, {mesh.n_triangle} triangles')
plt.show()
For SPDE models: The mesh defines the computational domain. From it, FEM matrices (C, G) are computed to build the precision matrix Q of the spatial random effect. The projector matrix A links mesh vertices to observation locations.