Places subsets (grains) of two dimension space randomly on a given point pattern. This is useful for simulating germ-grain models such as Boolean models. Also described here are functions for computing summary properties of the a list of grains.
placegrainsfromlib(
pp,
grainlib,
replace = TRUE,
prob = NULL,
w = NULL,
xy = NULL
)meanarea.grainlib(
grainlib,
weights = rep(1/length(grainlib), length(grainlib))
)
meansetcov.grainlib(
grainlib,
weights = rep(1/length(grainlib), length(grainlib)),
xy
)
covar.grainlib(lambda, grainlib, weights, xy)
A point pattern (in ppp
format).
A list of grains as owin
objects in a solist
.
passed directly to sample
. When TRUE grains are chosen from library with replacement.
A list of probability weights for each grain in the library. Passed directly to sample
.
If NULL the grains are selected with equal probability.
Optional desired observation window. If this is non-null then any grains with Frame outside the Frame of w
will be ignored.
This reduces polygonal intersection calculations for very large buffer distances
An im
or binary mask object that is used to specify the pixel array of objects.
Probability of selecting each grain in the library
Intensity of germs of a Boolean model - for computing the covariance of a Boolean model that has grain distribution given by grainlib
and weights
.
Returns an owin
object.
placegrainsfromlib
: Place grains randomly from a list of grains.
meanarea.grainlib
: Compute mean area of a random grain given by the library
meansetcov.grainlib
: Computes the mean of the set covariance of the grains in grainlib
.
xy
is required because the set covariance function must rasterise the owin
objects.
covar.grainlib
: Compute the covariance of a Boolean model with random grain given by the library
Germ-grain models have two components, a point process (called germs) and a process that creates
grains that are centred on the germs.
The point process of germs can be easily simulated using a number of spatstat functions
(e.g. rpoispp
for Boolean models).
To simulate a germ-grain model in a window
placegrainsfromlib
randomly samples from a library of grains (grainlib
) and places these on the points in pp
.
Sampling of the grain is independent of the location of the point in pp
.
It can be used to simulate the grain process in some germ-grain models.
# NOT RUN {
# Simulate a germ-grain model where germs are a Poisson point process
# and grains are randomly selected from 3 different disc sizes.
grainlib <- solist(disc(radius = 1), disc(radius = 1.9), disc(radius = 0.2))
bufferdist <- 2 #chosen to be larger than the largest radius in library
w <- owin(xrange = c(0, 10), yrange = c(0, 10))
# Simulate the germ process in the window plus a buffer region around window
pp <- rpoispp(lambda = 0.1, win = dilation(w, bufferdist), nsim = 1, drop = TRUE)
xi_withbuffer <- placegrainsfromlib(pp, grainlib)
# Simulation of germ-grain model is the part within the window
xi <- intersect.owin(xi_withbuffer, w)
# Computation of properties from parameters
lambda <- 0.1
discr <- 10
weights <- c(0.9999, 0.0001)
grainlib <- solist(disc(r = discr), disc(r = 2*discr))
meanarea.grainlib(grainlib, weights)
truecovar <- covar.grainlib(lambda, grainlib, weights, xy = as.mask(w, eps = 2))
# }
Run the code above in your browser using DataLab