geossm.covmodel.buildMesh2d

geossm.covmodel.buildMesh2d(points, domain=None, max_edge=None, min_edge=None, offset=None, cutoff=None, min_angle=21.0, lowrank=None, density_neighbors=8, tol=0.02, max_iter=25)[source]

Build a 2D triangular (gmsh/pygmsh) mesh around a set of observed locations, in the spirit of R-INLA’s inla.mesh.2d().

The mesh covers the convex hull of domain (or of points if domain is not given), extended outward by offset to limit boundary effects, with triangle edges bounded by max_edge/min_edge.

Parameters:
  • points ((n, 2) array_like) – Observed locations. Drive the default domain and, when lowrank is set, the local mesh density. Analogous to INLA’s loc.

  • domain (Polygon, MultiPolygon, or (possibly nested) list of these, optional) – The scientific-interest domain, e.g. the same composition of polygons passed to spdeAppoxCov/FEMSolver. It does not need to be convex or a single piece (it can be a disconnected set of regions, as for a country plus its islands): all parts are unioned together, and the mesh is built over the convex hull of that union, extended by offset. Defaults to the convex hull of points.

  • max_edge (float, optional) – Largest allowed triangle edge length. Defaults to 1/15 of the domain’s bounding-box diagonal.

  • min_edge (float, optional) – Smallest allowed triangle edge length. Defaults to max_edge / 10.

  • offset (float, optional) – Buffer added around domain so the mesh extends past the data. Defaults to max_edge.

  • cutoff (float, optional) – Points closer together than cutoff are merged before building the density field. Defaults to max_edge / 5.

  • min_angle (float, default 21.0) – Target minimum interior angle (degrees); drives extra mesh optimization passes. Mirrors INLA’s min.angle. This is a soft target: no unstructured mesher guarantees it exactly.

  • lowrank (float, optional) – Value in (0, 1]. When given, the local element size is rescaled by the density of points (finer where points are dense, coarser where they are sparse), so that the mesh has approximately round(lowrank * len(points)) vertices inside the scientific- interest domain – i.e. inside the union of domain before it is widened to its convex hull and offset (or inside the convex hull of points, if domain is not given). Vertices in the outer buffer region are not counted and are free to be as sparse as the size field makes them. Local density is a k-nearest-neighbor estimate (see density_neighbors) ranked by percentile, rather than a single-bandwidth KDE, so that separate clusters of comparable local density (e.g. several cities) are all refined even if one cluster has far more points overall.

  • density_neighbors (int, default 8) – Number of neighbors used for the local density estimate that drives lowrank. Ignored if lowrank is not given.

  • tol (float, default 0.02) – Relative tolerance on the vertex-count target used to stop the lowrank search.

  • max_iter (int, default 25) – Maximum number of mesh (re)generations used by the lowrank search.

Returns:

  • mesh (meshio.Mesh)

  • convex_hull (shapely.geometry.Polygon) – The (buffered) convex hull the mesh was built over – i.e. where the SPDE/FEM problem is defined – domain (or its default) widened to its convex hull and extended by offset.