1. Why Do We Need Meshes?
In SPDE (Stochastic Partial Differential Equations) approaches to spatial modeling, we approximate continuous spatial processes using a finite element representation. The mesh discretizes the spatial domain into triangles.
| Concept | Description |
|---|---|
| Vertices | Points where triangles meet - the SPDE solution is computed here |
| Triangles | Connect vertices, define the spatial basis functions |
| Resolution | Smaller triangles = more accuracy but higher computation cost |
| Extension | Buffer zone beyond data reduces boundary artifacts |
2. Setup: Sample Data
We'll use 50 random points to demonstrate each parameter:
3. Minimal Example: Just the Data Points
The simplest mesh uses only your data point locations:
4. Parameter: max_edge (Triangle Size Control)
max_edge sets the maximum allowed edge length for triangles.
- Single value: Same maximum edge everywhere
- [inner, outer]: Different limits for inner domain vs. extension zone
- Smaller values = More triangles, finer resolution, higher computation
- Larger values = Fewer triangles, coarser resolution, faster computation
max_edge as a percentage of your domain size:• Quick exploration: 15-25%
• Standard analysis: 5-15%
• High precision: 2-5%
5. Parameter: offset (Boundary Extension)
offset extends the mesh beyond your data points. This creates a buffer zone that reduces boundary artifacts in SPDE models.
- Positive value: Absolute distance in data units
- Negative value: Fraction of data diameter (e.g.,
-0.1= 10% of extent) - [inner, outer]: Two extension layers with different sizes
6. Inner vs Outer Zones: [inner, outer] Syntax
Many parameters accept two values [inner, outer] to control different mesh regions:
offset!
7. Parameter: cutoff (Point Merging)
cutoff sets the minimum distance allowed between mesh vertices. Points closer than cutoff are merged together.
Why use cutoff?
- Prevents degenerate triangles from nearly coincident points
- Reduces mesh complexity when data has clusters
- Improves numerical stability
| Data Type | Recommended cutoff |
|---|---|
| Well-spaced observations | Not needed |
| Some clustering | 3-5% of domain |
| Heavy clustering | 5-10% of domain |
cutoff too large will lose spatial detail!
8. Parameter: min_angle (Triangle Quality)
min_angle sets the minimum interior angle for triangles (in degrees).
- Well-shaped triangles (closer to equilateral) improve numerical accuracy
- Skinny triangles can cause numerical instability
- Typical range: 21-30 degrees
- Maximum practical value: ~33 degrees (theoretical limit for guaranteed convergence)
9. Parameter: boundary (Custom Boundaries)
Instead of the convex hull, you can specify a custom boundary polygon.
Use cases:
- Irregular study regions (countries, watersheds)
- Excluding certain areas
- Matching administrative boundaries
10. Non-Convex Hull: Following Data Shape
Use fm_nonconvex_hull() to create a boundary that follows your data more closely:
11. Complete Example: Putting It All Together
Here's a well-configured mesh combining all the parameters:
12. Quick Reference Card
| Parameter | Type | Description | Typical Values |
|---|---|---|---|
loc |
array (n, 2) | Data point locations | Required |
max_edge |
float or [inner, outer] | Maximum triangle edge length | 5-15% of domain |
offset |
float or [inner, outer] | Extension beyond data | 10-30% of domain |
cutoff |
float | Minimum point spacing | 3-10% of domain |
min_angle |
float | Minimum triangle angle (degrees) | 21-30 |
boundary |
FmSegment or array | Custom boundary polygon | Optional |
13. Best Practices
- Always use
offsetfor SPDE models to reduce boundary artifacts - Use
[inner, outer]syntax to save computation - fine mesh near data, coarse in extension - Set
cutoffwhen data has clusters to prevent degenerate triangles - Start coarse, refine as needed - begin with larger
max_edgeand decrease until results stabilize - Match parameters to data scale - always calculate domain size first
14. Helper Function: Suggest Mesh Parameters
Use this helper function to get suggested parameters based on your data: