Title: | Helper functions for the LandWeb project |
---|---|
Description: | Additional utilities for LandWeb analyses. |
Authors: | Eliot J B McIntire [aut] , Alex M Chubaty [aut, cre] , 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.2 |
Built: | 2024-12-25 06:31:10 UTC |
Source: | https://github.com/PredictiveEcology/LandWebUtils |
Clean up the LandWeb study area from David Andison
.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
CASFRItoSpRasts
TODO: 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 |
Find LandWeb simulation output file
findSimFile(outputDir, rep)
findSimFile(outputDir, rep)
outputDir |
path to LandWeb output directory. |
rep |
integer giving the replicate id, or character string in the form of |
path to the file
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 |
TODO |
fireSize |
TODO |
spawnNewActive |
TODO |
sizeCutoffs |
TODO |
spreadProb |
TODO |
named list of length 2 containing:
burnedMap
: rasterLayer
of burned pixels;
LM
: data.frame
of patch statistics from SDMTools::PatchStats()
.
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 objct
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 |
TODO |
ros |
TODO |
centreCell |
TODO |
fireSizes |
TODO |
desiredPerimeterArea |
TODO |
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.
data.table
(TODO)
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.
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.
TODO: description needed
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
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 |
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 |
TODO: description needed |
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 |
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 RasterLayer
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.
TODO: description needed
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. |
TODO: description needed
runHistsVegCover(map, functionName, analysisGroups, dPath)
runHistsVegCover(map, functionName, analysisGroups, dPath)
map |
A |
functionName |
TODO: description needed |
analysisGroups |
TODO: description needed |
dPath |
Destination path for the resulting PNG files. |