View source: R/veg_cover_functions.R
get_cover_difference | R Documentation |
This function uses the same approach for Bayesian estimation of vegetation
cover as described for function get_cover_quantiles
, but
applied to two rasters representing LiDAR point counts for the same area at
two different times. Argument rcounts0
is the raster for the earlier
time t0
, while argument rcounts1
is the raster for the later
time t1
. Each input raster should have two or more bands, with the
first band representing ground point counts and subsequent bands representing
point counts for vegetation strata arranged in increasing height order (i.e.
ground is band 1). For a given pixel and stratum, the distribution of
credible cover change values from time t0
to time t1
is found
via a simulation approach (see Details). This is a very time consuming
process, so rather than computing change quantiles for all pixels there is an
option to restrict the calculations to a set of sample locations which can
either be specified as either a two-column matrix or data frame of X-Y
coordinate values, or an sf
spatial data frame of point features.
get_cover_difference(
rcounts0,
rcounts1,
probs = c(0.05, 0.5, 0.95),
samplelocs = NULL,
backgroundNA = TRUE,
beta_prior = c(1, 1),
nsim = 1e+05,
seed = NULL
)
rcounts0 |
Point counts raster for the first (earlier) time. Normally,
this will be a |
rcounts1 |
Point counts raster for the second (later) time. This must
have the same dimensions (rows, columns and number of bands) as
|
probs |
A numeric vector of one or more probability values specifying
the quantiles of vegetation cover change to calculate. The default
|
samplelocs |
Spatial locations of raster pixels to sample. Can be a
two-column matrix or data frame of X-Y coordinates, or an |
backgroundNA |
Controls what pixel value should be returned for a
stratum when there are no LiDAR points for the stratum , any lower strata
or ground level in one or both point counts rasters. If set to |
beta_prior |
(Expert use only!) Either a numeric vector of two
values defining the prior beta distribution to use for all strata, or a
named list of two-element vectors where names match raster layer names for
vegetation strata (case-insensitive). The default is |
nsim |
Number of iterations for simulating the difference between the
two beta distributions representing possible cover values at times
|
seed |
An optional integer value to use as an initial seed for random
number generation when simulating the differences between beta
distributions representing possible cover values for a pixel and stratum at
the two times. This is useful when exactly reproducible results are
preferred. If |
As described for function get_cover_quantiles
, the estimation
of stratum vegetation cover is based on treating the discrete LiDAR returns
as a binomial sampling process, where the probability of a return from
vegetation in the stratum being considered corresponds to vegetation cover.
Under this model, the distribution of possible cover values that could have
generated the observed point counts for a pixel will follow a beta
distribution. Change in vegetation cover can therefore be estimated by taking
the distribution of differences between the beta distribution for time 2
minus that for time 1. This function uses a simulation approach to
approximate the distribution of differences.
If estimating change for all pixels (samplelocs=NULL
), the
function returns a SpatRast
(terra
package) raster object
with a layer for each requested quantile of vegetation cover change within
each stratum. For example, calculating the default median plus 90% bounds
(0.05 and 0.95 quantiles) of cover change for 5 vegetation strata would
return a raster object with 15 layers. Layers are arranged by stratum, then
by quantile. Layer names have the form stratum_dq_prob
, e.g.
'TallShrub_dq_0.5'
for the median (50%) quantile of cover change.
If estimating change for a subset of pixels specified via the
samplelocs
argument, an sf
spatial data frame is returned
with a row for each sample location and columns for stratum x quantile
change estimates. Column names have the same form as that described for
raster band names.
get_cover_quantiles
## Not run:
# Given two point count rasters, r0 (earlier time t0) and r1 (later time t1),
# calculate quantiles for difference in stratum cover at t1 compared to t0.
#
# Randomly select 100 pixels and create a set of point features
library(sf)
library(terra)
icells <- sample(1:ncells(r0), size = 100)
xy <- as.data.frame( xyFromCell(icells) )
xy <- st_as_sf(xy, coords = 1:2)
# Set the coordinate reference system for sample points. This is optional
# if r0 and r1 are in the same projection.
st_crs(xy) <- st_crs(r0)
# Quantiles of cover change (time t1 relative to t0) corresponding to
# median, 50\
# column for each stratum x quantile.
#
probs <- c(0.05, 0.25, 0.5, 0.75, 0.95)
dat_change <- get_cover_difference(r0, r1, probs, sample = xy, seed = 42)
# If the point count rasters are not too large, or you are happy to wait,
# you can calculate change estimates for all pixels by leaving the
# sample argument at its default of NULL. In this case, a terra::SpatRaster
# object is returned with a band for each stratum x quantile.
#
r_change <- get_cover_difference(r0, r1, probs, seed = 42)
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.