| Title: | Helper functions for the LandWeb project |
|---|---|
| Description: | Additional utilities for LandWeb analyses. |
| Authors: | Eliot J B McIntire [aut] (ORCID: <https://orcid.org/0000-0002-6914-8316>), Alex M Chubaty [aut, cre] (ORCID: <https://orcid.org/0000-0001-7146-8135>), His Majesty the Queen in Right of Canada, as represented by the Minister of Natural Resources Canada [cph] |
| Maintainer: | Alex M Chubaty <[email protected]> |
| License: | GPL-3 |
| Version: | 1.0.3.9010 |
| Built: | 2026-06-02 23:46:49 UTC |
| Source: | https://github.com/PredictiveEcology/LandWebUtils |
Clean up the LandWeb LTHFCs
.cleanLandWebStudyArea(poly, minFRI = 40).cleanLandWebStudyArea(poly, minFRI = 40)
poly |
A polygon or character string identifying the path to polygon |
minFRI |
Numeric or integer, indicating the minimum fire return interval
that will be part of the cleanup of polygon. Anything below
this will be |
Simulation timesteps for analyses
analysesOutputsTimes(period, interval)analysesOutputsTimes(period, interval)
period |
numeric vector of length 2 corresponding to the start and end times to use for analyses. |
interval |
numeric indicating the interval between timesteps for analyses |
numeric vector of timesteps for which to run analyses
CASFRItoSpRastsTODO: description and title needed
CASFRItoSpRasts( CASFRIRas, CASFRIattrLong, CASFRIdt, sppEquiv, sppEquivCol, destinationPath )CASFRItoSpRasts( CASFRIRas, CASFRIattrLong, CASFRIdt, sppEquiv, sppEquivCol, destinationPath )
CASFRIRas |
TODO: description needed |
CASFRIattrLong |
TODO: description needed |
CASFRIdt |
TODO: description needed |
sppEquiv |
table with species name equivalencies between the kNN and final naming formats.
See |
sppEquivCol |
the column name to use from |
destinationPath |
path to data directory where objects will be downloaded or saved to |
TODO: description needed
Extract study area name from run name
cleanAreaName(area)cleanAreaName(area)
area |
Simulated area (i.e., run) name |
Extract boundary polygon(s) for LandWeb forest management area(s)
extractFMA(fmas, name)extractFMA(fmas, name)
fmas |
|
name |
A character (regex) string to match. |
sf polygons object
Extract boundary polygon(s) for Alberta forest management unit(s)
extractFMU(fmus, name)extractFMU(fmus, name)
fmus |
|
name |
A character (regex) string to match. |
sf polygons object
Find LandWeb simulation output files
findSimFile(outputDir = NULL, rep = NULL) findOldSimFiles(outputDir = NULL, rep = NULL, before = "2024-01-01")findSimFile(outputDir = NULL, rep = NULL) findOldSimFiles(outputDir = NULL, rep = NULL, before = "2024-01-01")
outputDir |
path to LandWeb output directory. |
rep |
integer giving the replicate id, or character string in the form of |
before |
date before which files are considered outdated (default "2024-01-01"). |
path to the file
## Not run: outDir <- file.path("~/GitHub/LandWeb/outputs/Tolko_AB_S_aspenDispersal_logROS") if (dir.exists(outdir)) { oldFiles <- findOldSimFiles(outDir) ## search all reps oldFiles <- findOldSimFiles(outDir, 1:5) ## search specific reps # fs::file_delete(oldFiles) ## double check before deleting } ## End(Not run)## Not run: outDir <- file.path("~/GitHub/LandWeb/outputs/Tolko_AB_S_aspenDispersal_logROS") if (dir.exists(outdir)) { oldFiles <- findOldSimFiles(outDir) ## search all reps oldFiles <- findOldSimFiles(outDir, 1:5) ## search specific reps # fs::file_delete(oldFiles) ## double check before deleting } ## End(Not run)
Join two reporting polygons, preserving their features;
concatenate the Name.* fields into a single Name field.
E.g., if x and y each contain 2 features, the resulting object will contain 4
features (corresponding to x1.y1, x1.y2, x2.y1, and x2.y2).
joinReportingPolygons(x, y)joinReportingPolygons(x, y)
x, y
|
a |
an sf polygons object
The main function for the Andison Fire Module. See details.
landmine_burn1( landscape, startCells, fireSizes = 5, nActiveCells1 = c(10, 36), spawnNewActive = c(0.46, 0.2, 0.26, 0.11), maxRetriesPerID = 10L, sizeCutoffs = c(8000, 20000), spreadProbRel = NA_real_, spreadProb = 0.77, omitPixels = NULL ) landmine_burn( landscape, startCells, fireSizes = 5, nActiveCells1 = c(10, 36), spawnNewActive = c(0.46, 0.2, 0.26, 0.11), sizeCutoffs = c(8000, 20000), spreadProbRel = 0.23 )landmine_burn1( landscape, startCells, fireSizes = 5, nActiveCells1 = c(10, 36), spawnNewActive = c(0.46, 0.2, 0.26, 0.11), maxRetriesPerID = 10L, sizeCutoffs = c(8000, 20000), spreadProbRel = NA_real_, spreadProb = 0.77, omitPixels = NULL ) landmine_burn( landscape, startCells, fireSizes = 5, nActiveCells1 = c(10, 36), spawnNewActive = c(0.46, 0.2, 0.26, 0.11), sizeCutoffs = c(8000, 20000), spreadProbRel = 0.23 )
landscape |
A |
startCells |
A numeric vector indicating the indices on the |
fireSizes |
A numeric vector indicating the final size of each of the fires.
Must be same length as |
nActiveCells1 |
A numeric vector of length 2. These are cutoffs above and
below each of which different values of |
spawnNewActive |
A numeric vector of length 4. These are the probabilities of creating spreading to 2 neighbours instead of the 1 default neighbour, each time step. The 4 values are for 4 different fire size conditions. See details. |
maxRetriesPerID |
Integer. Maximum number of retry attempts per firelet ID. |
sizeCutoffs |
A numeric vector of length 2.
These are 2 size (in hectares) thresholds that affect which
|
spreadProbRel |
A raster layer of of relative probabilities, with non-flammable pixels |
spreadProb |
A raster layer of spread probabilities, with non-flammable pixels |
omitPixels |
An optional vector of pixel IDs to omit from fire size calculations.
Can be used if |
This algorithm is a modified contagious cellular automaton.
A data.table with 4 columns (initialPixels, pixels, state, order).
Each fire starts at a single pixel, startCells and will spread,
i.e., visit and convert from a 0 to the fire id number.
It will iteratively spread until the number of cells visited is equal to floor(fireSizes).
That can vary too, but it gets a bit complicated, so use that for now. Spawning probability was originally set at 13%, but created problems with very large and very small fires, so over time has been adjusted to vary depending on: a) number of active "firelets" (NF); and b) fire size (FS), such that:
- If 10 <= NF < 36 and FS < 20,000 ha then P = 20%; - If NF > 36 and FS < 8,000 ha, P = 11%; - If NF < 36 and FS > 20,000 ha, P = 26%; - If NF < 10 then P = 46%;
These rule create more heterogeneity in the pattern of burning.
If the fire has not reached its target size, it will try to pick new neighbours among
the 8 immediate neighbours up to 4 times.
If it still did not find enough neighbours, then it will jump or "spot" up to 4 pixels away.
It will then repeat the previous 2 stages again once (i.e., 4 neighbours, 1 jump, repeat),
then it will stop, unable to achieve the desired fireSize.
The original version (landmine_burn()) is deprecated and should not be used.
Use landmine_burn1() instead.
LandMine burn optimization function
landmine_optim_burnFun( ros, centreCell, fireSize, spawnNewActive, sizeCutoffs, spreadProb )landmine_optim_burnFun( ros, centreCell, fireSize, spawnNewActive, sizeCutoffs, spreadProb )
ros |
|
centreCell |
See |
fireSize |
See |
spawnNewActive |
A numeric vector of length 4. These are the probabilities of creating spreading to 2 neighbours instead of the 1 default neighbour, each time step. The 4 values are for 4 different fire size conditions. See details. |
sizeCutoffs |
A numeric vector of length 2.
These are 2 size (in hectares) thresholds that affect which
|
spreadProb |
A raster layer of spread probabilities, with non-flammable pixels |
named list of length 2 containing:
burnedMap: SpatRaster of burned pixels;
LM: data.frame of patch statistics from landscapemetrics.
Export objects used for optimization and load packages on cluster
landmine_optim_clusterExport(cl = NULL, objs = NULL, pkgs = NULL)landmine_optim_clusterExport(cl = NULL, objs = NULL, pkgs = NULL)
cl |
a cluster object or |
objs |
character vector of names of objects to export |
pkgs |
character vector of packages to pre-load on the cluster nodes |
NULL. Invoked for its side effects.
Setup a cluster for LandMine optimization
landmine_optim_clusterSetup(nodes = NULL)landmine_optim_clusterSetup(nodes = NULL)
nodes |
positive integer of length 1 specifying the number of threads
to use on the current machine ( |
a cluster object
Wrapper function to setup cluster, export objects and load packages
landmine_optim_clusterWrap(cl = NULL, nodes, reps, objs, pkgs)landmine_optim_clusterWrap(cl = NULL, nodes, reps, objs, pkgs)
cl |
a cluster object or |
nodes |
positive integer of length 1 specifying the number of threads
to use on the current machine ( |
reps |
integer. number of replicates to run. |
objs |
character vector of names of objects to export |
pkgs |
character vector of packages to pre-load on the cluster nodes |
named list of length 2 containing:
cl, a cluster object;
out, a list of burn maps (aka burnMapList).
landmine_fitSN() is used for the module.
landmine_optim_fitSN( sna, ros, centreCell, fireSizes = 10^(2:5), desiredPerimeterArea = 0.004 ) landmine_optim_fitSN2( par, ros, centreCell, fireSizes = 10^(2:5), desiredPerimeterArea = 0.003, spreadProb = 0.9 )landmine_optim_fitSN( sna, ros, centreCell, fireSizes = 10^(2:5), desiredPerimeterArea = 0.004 ) landmine_optim_fitSN2( par, ros, centreCell, fireSizes = 10^(2:5), desiredPerimeterArea = 0.003, spreadProb = 0.9 )
sna |
(i.e., |
ros |
Character, specifying the file path to raster of LandMine Rate Of Spread values. |
centreCell |
Integer id of the centre (start) cell of |
fireSizes |
A numeric vector indicating the final size of each of the fires.
See |
desiredPerimeterArea |
Numeric target perimeter-area ratio. |
par |
parameter vector of length 5 |
spreadProb |
spread probability |
landmine_fitSN2() is an alternative version tries the optimization using fewer parameters,
to test whether a simpler version gets better/different results.
Although this version was not used for the final module, we preserve it here for posterity.
Summary data.table of fit results.
landmine_burn1(), landmine_optim_burnFun()
landmine_plot_areaBurnedOverTime() plots the area burned over time by LTHFC polygon;
landmine_plot_LTHFC() produces a rasterVis::levelplot() a map of the LTHFC polygons;
landmine_plot_FRI() plots
landmine_plot_areaBurnedOverTime(areaBurnedOverTime) landmine_plot_LTHFC(lthfc, studyAreaName, ...) landmine_plot_FRI(friSummary)landmine_plot_areaBurnedOverTime(areaBurnedOverTime) landmine_plot_LTHFC(lthfc, studyAreaName, ...) landmine_plot_FRI(friSummary)
areaBurnedOverTime |
Summary |
lthfc |
long-term historic fire cycle map (raster). |
studyAreaName |
study area name (character). |
... |
additional arguments passed to |
friSummary |
Summary |
a ggplot2 or rasterVis object; invoked for side effect of creating plots.
As of September 2025, this corresponds to the SCANFI's NAD_1983_Canada_Lambert projection.
LandWebCRSLandWebCRS
An object of class character of length 1.
needs to be character, not CRS class, for downstream use with data.table
Study areas available for LandWeb simulations
LandWebStudyAreas studyAreaProv(name) studyAreaIn(name, prov)LandWebStudyAreas studyAreaProv(name) studyAreaIn(name, prov)
name |
character specifying the study area name. Must be one of |
prov |
character specifying the province abbreviation (i.e., "AB", "BC", "MB", "NWT", or "SK"). |
An object of class data.frame with 32 rows and 4 columns.
LandWebStudyAreas is a data.frame' with 4 columns:
Name specifies the shortname of the study area for use with simulation setup;
Province identifies the location of the study area;
ID corresponds to the polygon ID of the Updated FMA Boundaries polygons;
Description provides the full study area name and additional context (if any);
studyAreaProv returns a character indicating the province the study area is in.
studyAreaIn returns a logical indicating whether study area name is in prov.
TODO: needs description
LargePatches( tsf, vtm, poly, labelColumn, id, ageClassCutOffs, ageClasses, sppEquivCol, sppEquiv, crop2poly = FALSE )LargePatches( tsf, vtm, poly, labelColumn, id, ageClassCutOffs, ageClasses, sppEquivCol, sppEquiv, crop2poly = FALSE )
tsf |
A single filename, relative or absolute, pointing to a Time Since Fire raster.
Can be any format that |
vtm |
A single filename, relative or absolute, pointing to a Vegetation Type Map raster.
Can be any format that |
poly |
A single |
labelColumn |
TODO: description needed |
id |
TODO: description needed |
ageClassCutOffs |
A numeric vector with the endpoints for the |
ageClasses |
A character vector with labels for age classes to bin the |
sppEquivCol |
Character giving the column name to use in |
sppEquiv |
Species equivalency table, e.g., derived from |
crop2poly |
logical indicating whether to crop/mask |
This function is recursive.
If poly is a SpatialPolygon, then the function
will enter once, and convert this to a fasterized version, and pass that into
the function replacing poly.
It is also recursive of passed a vector of filenames for tsf and vtm.
LeadingVegTypeByAgeClass( tsf, vtm, poly, ageClassCutOffs, ageClasses, sppEquivCol, sppEquiv )LeadingVegTypeByAgeClass( tsf, vtm, poly, ageClassCutOffs, ageClasses, sppEquivCol, sppEquiv )
tsf |
A single filename, relative or absolute, pointing to a Time Since Fire raster.
Can be any format that |
vtm |
A single filename, relative or absolute, pointing to a Vegetation Type Map raster.
Can be any format that |
poly |
A single |
ageClassCutOffs |
A numeric vector with the endpoints for the |
ageClasses |
A character vector with labels for age classes to bin the |
sppEquivCol |
Character giving the column name to use in |
sppEquiv |
Species equivalency table, e.g., derived from |
A data.table with proportion of the pixels in each vegetation class,
for each given age class within each polygon.
Using CASFRI v4 data prepared for LandWeb.
loadCASFRI( CASFRIRas, attrFile, headerFile, sppEquiv, sppEquivCol, type = c("cover", "age") )loadCASFRI( CASFRIRas, attrFile, headerFile, sppEquiv, sppEquivCol, type = c("cover", "age") )
CASFRIRas |
TODO: description needed |
attrFile |
TODO: description needed |
headerFile |
TODO: description needed |
sppEquiv |
table with species name equivalencies between the kNN and final naming formats.
See |
sppEquivCol |
the column name to use from |
type |
Character string. Either |
TODO: description needed
Calculate the mean of a truncated Pareto distribution
meanTruncPareto(k, lower, upper, alpha)meanTruncPareto(k, lower, upper, alpha)
k |
TODO: description needed |
lower |
TODO: description needed |
upper |
TODO: description needed |
alpha |
TODO: description needed |
TODO: description needed
Plot boundary polygon(s) for forest management areas
plotFMA(x, provs, caribou = NULL, xsr = NULL, title = NULL, png = NULL) plotLandWeb(x, provs, caribou = NULL, xsr = NULL, title = NULL, png = NULL) plotGG(x, provs, caribou = NULL, png = NULL, title = NULL)plotFMA(x, provs, caribou = NULL, xsr = NULL, title = NULL, png = NULL) plotLandWeb(x, provs, caribou = NULL, xsr = NULL, title = NULL, png = NULL) plotGG(x, provs, caribou = NULL, png = NULL, title = NULL)
x |
|
provs |
|
caribou |
Optional |
xsr |
Optional |
title |
Character string to use for plot title |
png |
Optional. If non-NULL, must be a valid file path to write a png |
Do an arbitrary set of operations on a polygon
polygonClean(poly, fn = NULL, type = NULL, ...)polygonClean(poly, fn = NULL, type = NULL, ...)
poly |
A polygon object, or a character string identifying the shapefile path to load, and clean. |
fn |
A function identifying the type of cleaning to do. |
type |
If |
... |
Passed to |
LandWeb FMA boundaries (FMAs);
Alberta FMU boundaries (FMUs);
Alberta Natural Subregions (ANSRs);
prepFMAs(destinationPath, targetCRS = LandWebCRS) prepFMUs(destinationPath, targetCRS = LandWebCRS) prepANSRs(destinationPath, targetCRS = LandWebCRS)prepFMAs(destinationPath, targetCRS = LandWebCRS) prepFMUs(destinationPath, targetCRS = LandWebCRS) prepANSRs(destinationPath, targetCRS = LandWebCRS)
destinationPath |
character specifying path to destination directory |
targetCRS |
character specifying the CRS to reproject polygons to |
Prepare species layers from CASFRI v4
prepSpeciesLayers_CASFRI( destinationPath, outputPath, url = NULL, studyArea, rasterToMatch, sppEquiv, sppEquivCol, ... )prepSpeciesLayers_CASFRI( destinationPath, outputPath, url = NULL, studyArea, rasterToMatch, sppEquiv, sppEquivCol, ... )
destinationPath |
path to data directory where objects will be downloaded or saved to |
outputPath |
character, specifying the output directory to use |
url |
if |
studyArea |
A |
rasterToMatch |
A |
sppEquiv |
table with species name equivalencies between the kNN and final naming formats.
See |
sppEquivCol |
the column name to use from |
... |
other arguments, used for compatibility with other |
Extract boundary polygon(s) for LandWeb study areas
prepStudyArea(name, destinationPath, targetCRS = LandWebCRS) prepTestStudyArea(destinationPath, targetCRS = LandWebCRS, .seed = 867)prepStudyArea(name, destinationPath, targetCRS = LandWebCRS) prepTestStudyArea(destinationPath, targetCRS = LandWebCRS, .seed = 867)
name |
A character (regex) string to match. |
destinationPath |
character specifying path to destination directory |
targetCRS |
character specifying the CRS to reproject polygons to |
.seed |
integer specifying the random seed to use to generate study area boundary |
sf polygons object
Create a list of rasters in each rep, at each timestep, for each polygon area
rasterListByPoly(files, polys, names, col, filter)rasterListByPoly(files, polys, names, col, filter)
files |
character vector giving paths to raster files |
polys |
polygon object of class |
names |
character vector giving the names of each of the subpolygons in |
col |
character string giving the column name in |
filter |
regex string giving partial filename in |
list of SpatRaster objects with attributes reps, times, polyNames
uses future_lapply internally to loop across files;
set e.g., option future.availableCores.fallback appropriately for your system.
Generate box and whisker plots for leading vegetation cover
runBoxPlotsVegCover(map, functionName, analysisGroups, dPath)runBoxPlotsVegCover(map, functionName, analysisGroups, dPath)
map |
A |
functionName |
TODO: description needed |
analysisGroups |
TODO: description needed |
dPath |
Destination path for the resulting PNG files. |
TODO: description needed
runHistsLargePatches(map, functionName, analysisGroups, dPath)runHistsLargePatches(map, functionName, analysisGroups, dPath)
map |
A |
functionName |
TODO: description needed |
analysisGroups |
TODO: description needed |
dPath |
Destination path for the resulting PNG files. |
Generate histograms for leading vegetation cover
runHistsVegCover(map, functionName, analysisGroups, dPath)runHistsVegCover(map, functionName, analysisGroups, dPath)
map |
A |
functionName |
Character specifying the name of the function to apply. |
analysisGroups |
Character specifying the analysis groups to run. |
dPath |
Destination path for the resulting PNG files. |