Converting legacy INLA mesh code to fmesher
Source:vignettes/inla_conversion.Rmd
inla_conversion.Rmd
Deprecation warnings
Three
INLA::inla.getOption()
/INLA::inla.setOption()
options control the transition behaviour of the INLA
package use of fmesher
.
-
fmesher.evolution
, integer:-
1L
uses the intermediatefm_*
methods infmesher
that were already available via inlabru from 2.8.0, but calls theINLA
built-infmesher
standalone programme for mesh construction and related operations. (FromINLA
version 23.06.29) -
2L
uses the full range offmesher
package methods, and does not use the standalonefmesher
programme. (FromINLA
around version 23.08.20)
-
fmesher.evolution.warn
, logical: WhenTRUE
,INLA
will show deprecation methods for all the methods inINLA
that are being replaced byfmesher
package methods. WhenFALSE
, no warnings will be shown. Set this option toTRUE
if you want to update your own code, but keep it atFALSE
when you need to run existing code without changing it.fmesher.evolution.verbosity
, character: Either “soft”, “warn”, or “stop”, indicating the minimum warning level whenfmesher.evolution.warn
isTRUE
. Set this to “warn” or “stop” to get more immediate feedback when testing conversion of old code, e.g. in package testing.
Compatibility
Great effort has been taken to preserve backwards compatibility as
far as practical, with in particular the old inla.mesh
,
inla.mesh.1d
, and inla.mesh.segment
object
classes given fallback methods that carry out methods for the new
fm_mesh_2d
, fm_mesh_1d
, and
fm_segm
classes.
An important change is that the handling of mesh crs
information is now more flexible, but stricter in the sense that user
code should make no assumption about how the information is stored in
the mesh, and should therefore avoid the direct mesh$crs
access, and instead use the fm_crs()
and
fm_CRS()
access methods, depending on what type of CRS
object is needed. The ideal way to specify crs information is in the
initial mesh creation call. If the crs needs to be explicitly assigned a
new value, use the fm_crs(mesh) <- crs
assignment
method.
For mesh and curve creation, the fm_rcdt_2d_inla()
,
fm_mesh_2d_inla()
, and
fm_nonconvex_hull_inla()
methods will keep the interface
syntax used by inla.mesh.create()
,
inla.mesh.2d()
, and inla.nonconvex.hull()
functions, respectively, whereas the fm_rcdt_2d()
,
fm_mesh_2d()
, and fm_nonconvex_hull()
interfaces may change in the future.
Mesh construction
INLA | fmesher |
---|---|
inla.mesh.create() |
fm_rcdt_2d()
,
fm_rcdt_2d_inla()
|
inla.mesh.2d() |
fm_mesh_2d()
,
fm_mesh_2d_inla()
|
inla.delaunay() |
fm_delaunay_2d() |
inla.mesh.1d() |
fm_mesh_1d() |
inla.mesh.lattice() |
fm_lattice_2d() |
inla.mesh.segment() |
fm_segm() |
inla.nonconvex.hull() |
fm_nonconvex_hull() ,
fm_extensions()
,
fm_simplify()
|
inla.nonconvex.hull() ,
inla.contour.segment() ,
inla.simplify.curve()
|
fm_nonconvex_hull_inla() ,
fm_simplify_helper()
,
fm_segm_contour_helper()
|
Basis and function evaluation
INLA | fmesher |
---|---|
inla.mesh.projector() |
fm_evaluator() |
inla.mesh.project() |
fm_evaluate() |
inla.spde.make.A() |
fm_basis()
, fm_row_kron()
,
inlabru::bru_mapper_multi()
,
inlabru::ibm_jacobian()
, fm_block() ,
fm_block_eval() ,
inlabru::bru_mapper_aggregate()
|
inla.mesh.deriv() |
fm_basis() |
Finite element methods
INLA | fmesher | Comment |
---|---|---|
inla.mesh.fem() ,
inla.mesh.1d.fem()
|
fm_fem() |
|
|
fm_matern_precision() |
|
|
fm_matern_sample() |
Convenience function that combines
fm_matern_precision() and fm_sample() . |
|
fm_covariance() |
Basic helper function for computing covariances between
different locations. Can produce sparse inverses like
inla.qinv() , but currently (version 0.1.1) only by a ‘brute
force’ method. |
|
fm_sample() |
Basic sampling method, like
inla.qsample()
|
Printing
INLA | fmesher | Comments |
---|---|---|
summary.inla.mesh() |
print.fm_mesh_2d() ,
print.fm_segm()
,
print.fm_mesh_1d()
|
Use print(mesh) etc. |
CRS information and coordinate transformations
INLA | fmesher | Comments |
---|---|---|
inla.spTransform() |
fm_transform() |
|
mesh$crs |
fm_crs(mesh)
,
fm_CRS(mesh)
|
The crs may now be stored in different formats; use
fm_crs() for sf format, and
fm_CRS() for sp format. fmesher
will attempt to convert when needed. |
mesh$crs<- |
fm_crs(mesh)<- |
Direct assignment of crs information should be avoided, but is allowed as long as its compatible with the actual mesh coordinates. |
Plotting
INLA | fmesher | Comment |
---|---|---|
No ggplot support |
geom_fm(data = mesh) ,
geom_fm(data = segm)
|
Use ggplot() + geom_fm(data = mesh) and
inlabru::gg() methods |
plot.inla.mesh(rgl = FALSE) |
plot.fm_mesh_2d()
,
lines.fm_mesh_2d()
|
Use plot() or lines()
|
lines.inla.mesh.segment(rgl = FALSE) |
plot.fm_segm()
,
lines.fm_segm()
|
Use plot() or lines()
|
plot.inla.mesh(rgl = TRUE) |
plot_rgl()
, lines_rgl()
|
|
lines.inla.mesh.segment(rgl = TRUE) |
plot_rgl()
, lines_rgl()
|