| Title: | Utilities for modelling carbon based on CBM-CFS3 |
|---|---|
| Description: | Implementation of several components of the Carbon Budget Model of the Canadian Forest Service (v3). |
| Authors: | Céline Boisvenue [aut, cre], Alex M Chubaty [aut] (ORCID: <https://orcid.org/0000-0001-7146-8135>), Eliot McIntire [aut], Ian Eddy [ctb], Camille Giuliano [ctb], Susan Murray [ctb], Dominique Caron [ctb] |
| Maintainer: | Céline Boisvenue <[email protected]> |
| License: | GPL-3 |
| Version: | 2.5.4.9002 |
| Built: | 2026-05-25 21:11:40 UTC |
| Source: | https://github.com/PredictiveEcology/CBMutils |
Adjust cohort ages to represent a year before or after a given date. Optionally include disturbance events that reset ages to year 0.
adjustCohortAges( cohortAges, yearInput, yearOutput, disturbanceEvents = NULL, delay = NULL, default = NULL, warn = TRUE )adjustCohortAges( cohortAges, yearInput, yearOutput, disturbanceEvents = NULL, delay = NULL, default = NULL, warn = TRUE )
cohortAges |
data.table. Table of cohort ages
with an ID column and the numeric columns 'age'.
Optionally include a 'delay' column with regeneration delays for each cohort.
A standard delay can also be provided with the |
yearInput |
integer. The year that the 'ages' column in |
yearOutput |
integer. The year that cohort ages must be adjusted to. |
disturbanceEvents |
data.table. Optional.
Table of disturbance events with the ID column in |
delay |
integer. Optional. Regeneration delay after a disturbance event. |
default |
integer. A default age for cohorts is otherwise unknown.
If |
warn |
logical. Warn if ages cannot be calculated or if the provided disturbances do not match the input data. |
cohortAges with ages adjusted to yearOutput.
Step an age raster backwards in time.
Ages that are set as <0 are replaced with surrounding ages >0 with idw_replace.
ageStepBackward( ageRast, yearIn, yearOut, distEvents = NULL, fill = TRUE, fillLT0 = TRUE, idp = 2, nmax = 100, ..., agg.fact = 1, agg.fun = "median", agg.na.rm = TRUE )ageStepBackward( ageRast, yearIn, yearOut, distEvents = NULL, fill = TRUE, fillLT0 = TRUE, idp = 2, nmax = 100, ..., agg.fact = 1, agg.fun = "median", agg.na.rm = TRUE )
ageRast |
SpatRaster. Raster with numeric values of cohort ages. |
yearIn |
numeric. Year that ages in |
yearOut |
numeric. Year that ages will be stepped backwards to. |
distEvents |
data.table. Optional.
Table of disturbance events with columns "pixelIndex" and "year".
If provided, disturbances will be reversed and the disturbed areas
will be filled with |
fill |
logical. Fill disturbed areas with values interpolated from surrounding cells. |
fillLT0 |
logical. Fill cells with ages <0 with values interpolated from surrounding cells. |
idp |
numeric. IDW power. |
nmax |
numeric. The maximum number of nearest observations to use. |
... |
additional arguments to |
agg.fact |
Aggregation factor for the input raster.
If >1, the raster will be aggregated before cell values
are extracted as input data points for interpolation.
This smooths the input data and speeds up the interpolation process.
See |
agg.fun |
Aggregation function. |
agg.na.rm |
Remove NA cells when aggregating. |
SpatRaster
When there is no match for the given ecozone, the parameters for a different ecozone in the same province/territory is returned. If there is no match for a given province/territory, the parameters for a different province/territory in the same ecozone is returned. If there is no match for the given ecozone and province/territory, the parameters for a different location is returned.
alternativeParams(params, table, cols)alternativeParams(params, table, cols)
params |
|
table |
|
cols |
|
A single data.table containing a row for each curve with all required
parameters from both table6, table7, and tableMerchantability.
Implements equation 1 of Boudewyn et al. (2007) to determines the total stemwood biomass of
merchantable trees (in metric tonnes per hectare; ),
using parameters and from Table 3 (table3).
b_m(table3, vol)b_m(table3, vol)
table3 |
|
vol |
gross merchantable volume per hectare ( |
stemwood biomass of merchantable trees ( in units )
Boudewyn, P., Song, X., Magnussen, S., & Gillis, M. D. (2007). Model-based, volume-to-biomass conversion for forested and vegetated land in Canada (BC-X-411). Natural Resource Canada, Pacific Forestry Centre. https://cfs.nrcan.gc.ca/pubwarehouse/pdfs/27434.pdf
Implements equations 4-7 of Boudewyn et al. (2007), used to determine the proportions
of total tree biomass in stemwood, bark, branches, and foliage
(, , , , respectively),
using parameters , from Table 6 (table6) and volume-proportion caps
from Table 7 (table7).
biomProp(table6, table7, x, type = "volume")biomProp(table6, table7, x, type = "volume")
table6 |
|
table7 |
|
x |
|
type |
|
TODO: will eventually add species, ecozone
four-column matrix will columns corresponding to , ,
, and
Boudewyn, P., Song, X., Magnussen, S., & Gillis, M. D. (2007). Model-based, volume-to-biomass conversion for forested and vegetated land in Canada (BC-X-411). Natural Resource Canada, Pacific Forestry Centre. https://cfs.nrcan.gc.ca/pubwarehouse/pdfs/27434.pdf
Implements equations 4-7 of Boudewyn et al. (2007) adapted for biomass input
using parameters , , and from Table 6 (table6) and
biomass-proportion caps from Table 7 (table7).
biomPropAGB(AGBwithParams)biomPropAGB(AGBwithParams)
AGBwithParams |
|
four-column matrix will columns corresponding to , ,
, and
Boudewyn, P., Song, X., Magnussen, S., & Gillis, M. D. (2007). Model-based, volume-to-biomass conversion for forested and vegetated land in Canada (BC-X-411). Natural Resource Canada, Pacific Forestry Centre. https://cfs.nrcan.gc.ca/pubwarehouse/pdfs/27434.pdf
Subset Boudewyn tables to fit study area
boudewynSubsetTables(table, thisAdmin)boudewynSubsetTables(table, thisAdmin)
table |
Boudewyn table to subset |
thisAdmin |
Table defining study area with columns
|
smallTable data.table
totalCarbon or aboveGround or belowGround
Sum carbon for totalCarbon or aboveGround or belowGround
calcC(cbmPools, poolToSum, masterRaster)calcC(cbmPools, poolToSum, masterRaster)
cbmPools |
DESCRIPTION NEEDED |
poolToSum |
DESCRIPTION NEEDED |
masterRaster |
|
DESCRIPTION NEEDED
calcRootCcalcRootC calculates the mass of carbon in roots pools from above ground pools
calcRootC( aboveGroundC, sw_hw, a_sw = 0.222, b_sw = 1, a_hw = 1.576, b_hw = 0.615, a_frp = 0.072, b_frp = 0.354, c_frp = -0.060212, biomassToCarbonRate = 0.5 )calcRootC( aboveGroundC, sw_hw, a_sw = 0.222, b_sw = 1, a_hw = 1.576, b_hw = 0.615, a_frp = 0.072, b_frp = 0.354, c_frp = -0.060212, biomassToCarbonRate = 0.5 )
aboveGroundC |
data.table with mass of carbon (tonnes/ha) in the Merch, Foliage and Other pools |
sw_hw |
a boolean vector indicating if the cohort is softwood (0) or hardwood (1) |
a_sw |
"a" value for softwood root biomass |
b_sw |
"b" value for softwood root biomass |
a_hw |
"a" value for hardwood root biomass |
b_hw |
"b" value for hardwood root biomass |
a_frp |
"a" value for fine root proportion |
b_frp |
"b" value for fine root proportion |
c_frp |
"c" value for fine root proportion |
biomassToCarbonRate |
Conversion factor of biomass to carbon |
data.table with mass of carbon (tonnes/ha) in coarseRoots and fineRoots pools.
Li, Z., Kurz, W. A., Apps, M. J., & Beukema, S. J. (2003). Belowground biomass dynamics in the Carbon Budget Model of the Canadian Forest Sector: recent improvements and implications for the estimation of NPP and NEP. Canadian journal of forest research, 33(1), 126-136.
mapNPP
Map Net Primary Productivity (NPP) across a study area.
cbm4MapNPP(cbm4_results, years = NULL, yearStart = 1)cbm4MapNPP(cbm4_results, years = NULL, yearStart = 1)
cbm4_results |
character or |
years |
integer. Year(s) of simulation results. |
yearStart |
integer. Simulation start year. |
ggplot
mapTotalCarbon
Map total carbon across a study area.
cbm4MapTotalCarbon(cbm4_results, years = NULL, yearStart = 1)cbm4MapTotalCarbon(cbm4_results, years = NULL, yearStart = 1)
cbm4_results |
character or |
years |
integer. Year(s) of simulation results. |
yearStart |
integer. Simulation start year. |
ggplot
plotEmissionsProducts
Map total carbon across a study area.
cbm4PlotEmissionsProducts(cbm4_results, years = NULL, yearStart = 1)cbm4PlotEmissionsProducts(cbm4_results, years = NULL, yearStart = 1)
cbm4_results |
character or |
years |
integer. Year(s) of simulation results. |
yearStart |
integer. Simulation start year. |
ggplot
plotPoolProportions
CBM4: plotPoolProportions
cbm4PlotPoolProportions(cbm4_results, years = NULL, yearStart = 1)cbm4PlotPoolProportions(cbm4_results, years = NULL, yearStart = 1)
cbm4_results |
character or |
years |
integer. Year(s) of simulation results. |
yearStart |
integer. Simulation start year. |
ggplot
Prepare a data source from the CBMsources table
with link[reproducible]{prepInputs},
then align the data with a template raster and extract values for each cell
with link{extractToRast}.
CBMsourceExtractToRast(sourceID, templateRast, returnSource = FALSE, ...)CBMsourceExtractToRast(sourceID, templateRast, returnSource = FALSE, ...)
sourceID |
Source identifier. |
templateRast |
SpatRaster. Raster template. |
returnSource |
logical. Return the source spatial data object. |
... |
additional arguments to |
Prepare a data source from the CBMsources table
with link[reproducible]{prepInputs}.
CBMsourcePrepInputs( sourceID, inputPath = getOption("spades.inputPath", "."), ... )CBMsourcePrepInputs( sourceID, inputPath = getOption("spades.inputPath", "."), ... )
sourceID |
Source identifier. |
inputPath |
character. Path of download destination directory. Downloads will be sorted into subdirectories by data provider and region. |
... |
additional arguments to |
Data sources for CBM simulations. These can be read with CBMsourcePrepInputs.
CBMsourcesCBMsources
A data table with 8 columns and 6 rows:
Source identifier.
Data provider or inventory identifier.
Data year. The year that the data represents or was published.
Spatial domain. Defaults to all of Canada.
Cohort or stand attribute defined by the source.
Spatial data type: 'vector' or 'raster'.
Data table of one or more downloadable data sources:
url: Download URL of target data source.
targetFile: File name of target data source.
layer: Vector or raster layer.
field: Vector attribute field.
subattr: If the source is comprised of multiple vector fields or raster layers, this secondary attribute distinguishes each one.
...
).Implements the flowchart from figure 3 of Boudewyn et al. (2007) using an alternative
set of parameter to divide total above ground biomass () into total merchantable
stemwood biomass (), foliage biomass (), and other wood biomass ().
convertAGB2pools(AGB, allParams)convertAGB2pools(AGB, allParams)
AGB |
|
allParams |
|
three-column matrix with columns corresponding to biomass () for
total merchantable, foliage, and other wood.
Boudewyn, P., Song, X., Magnussen, S., & Gillis, M. D. (2007). Model-based, volume-to-biomass conversion for forested and vegetated land in Canada (BC-X-411). Natural Resource Canada, Pacific Forestry Centre. https://cfs.nrcan.gc.ca/pubwarehouse/pdfs/27434.pdf
Implements the flowchart from figure 3 of Boudewyn et al. (2007) to determined the
total above ground biomass () from gross merchantable volume ().
convertM3biom( meta, gCvalues, spsMatch, ecozones, params3, params4, params5, params6, params7 )convertM3biom( meta, gCvalues, spsMatch, ecozones, params3, params4, params5, params6, params7 )
meta |
Growth curve metadata |
gCvalues |
Growth curve volume values for each age |
spsMatch |
Species associated with growth curve |
ecozones |
Ecozone associated with the growth curve |
params3 |
|
params4 |
|
params5 |
|
params6 |
|
params7 |
|
three-column matrix with columns corresponding to biomass () for
total merchantable, foliage, and other.
Boudewyn, P., Song, X., Magnussen, S., & Gillis, M. D. (2007). Model-based, volume-to-biomass conversion for forested and vegetated land in Canada (BC-X-411). Natural Resource Canada, Pacific Forestry Centre. https://cfs.nrcan.gc.ca/pubwarehouse/pdfs/27434.pdf
cTransfersAlluvialMaps proportions of carbon transfers across pools during a disturbance.
cTransfersAlluvial( cTransfers, distMatrixID = NULL, distName = NULL, spuID = NULL, sw = NULL, nearMatches = TRUE, identical = !ask, ask = interactive(), ... )cTransfersAlluvial( cTransfers, distMatrixID = NULL, distName = NULL, spuID = NULL, sw = NULL, nearMatches = TRUE, identical = !ask, ask = interactive(), ... )
cTransfers |
Carbon pool transfer matrix |
distMatrixID |
disturbance_matrix_id of the disturbance to plot. |
distName |
disturbance name you wish to plot. Required only if |
spuID |
CBM-CFS3 spatial unit ID of the disturbance to plot. Required only if |
sw |
logical. Softwood (TRUE) or hardwood (FALSE). Required only if |
nearMatches |
logical. Allow for near matches; e.g. "clearcut" can match "clear-cut". |
identical |
logical. Require identical matches. |
ask |
logical. If TRUE, prompt the user to choose the correct matches. If FALSE, the function will look for a single match to each input. |
... |
additional arguments to |
alluvialDist Alluvial plot of a disturbance in a specific spatial unit.
cumPools data.tableCreate cumPools data.table
cumPoolsCreate( fullSpecies, gcMeta, userGcM3, stable3, stable4, stable5, stable6, stable7, thisAdmin, biomassToCarbonRate = 0.5 )cumPoolsCreate( fullSpecies, gcMeta, userGcM3, stable3, stable4, stable5, stable6, stable7, thisAdmin, biomassToCarbonRate = 0.5 )
fullSpecies |
Study area species' names |
gcMeta |
Growth curve metadata table |
userGcM3 |
Table of growth curve volume by age |
stable3 |
Boudewyn et al. 2007 stem wood biomass model parameters table for merchantable-sized trees |
stable4 |
Boudewyn et al. 2007 stem wood biomass model parameters table for non-merchantable-sized trees |
stable5 |
Boudewyn et al. 2007 stem wood biomass model parameters table for sapling-sized trees |
stable6 |
Boudewyn et al. 2007 stem wood biomass model parameters table for proportion model parameters |
stable7 |
Boudewyn et al. 2007 stem wood biomass model parameters table for caps on proportion models |
thisAdmin |
Ecozone and spatial unit information table for the study area |
biomassToCarbonRate |
Conversion factor of biomass to carbon |
cumPools data.table
).Implements the flowchart from figure 3 of Boudewyn et al. (2007) using an alternative
set of parameter to divide total above ground biomass () into total merchantable
stemwood biomass (), foliage biomass (), and other wood biomass ().
cumPoolsCreateAGB( allInfoAGBin, table6, table7, tableMerchantability, pixGroupCol, biomassToCarbonRate = 0.5 )cumPoolsCreateAGB( allInfoAGBin, table6, table7, tableMerchantability, pixGroupCol, biomassToCarbonRate = 0.5 )
allInfoAGBin |
|
table6 |
|
table7 |
|
tableMerchantability |
|
pixGroupCol |
the name of the column in |
biomassToCarbonRate |
Conversion factor of biomass to carbon |
biomass () in each above ground pool for each cohort per pixel group.
Boudewyn, P., Song, X., Magnussen, S., & Gillis, M. D. (2007). Model-based, volume-to-biomass conversion for forested and vegetated land in Canada (BC-X-411). Natural Resource Canada, Pacific Forestry Centre. https://cfs.nrcan.gc.ca/pubwarehouse/pdfs/27434.pdf
cumPools data.table
This uses the Chapman Richards equation to smooth the curves that are in colsToUse.
cumPoolsSmooth( cumPoolsRaw, colsToUse = c("totMerch", "fol", "other"), colsToUseNew = paste0(colsToUse, "_New") )cumPoolsSmooth( cumPoolsRaw, colsToUse = c("totMerch", "fol", "other"), colsToUseNew = paste0(colsToUse, "_New") )
cumPoolsRaw |
Data.table with a numeric column called |
colsToUse |
A character vector of columns to smooth. |
colsToUseNew |
A character vector of column names for the new smoothed columns |
#' A data.table with original columns plus new columns named 'colsToUseNew“.
Celine Boisvenue and Eliot McIntire
List CBM-CFS3 disturbance types.
distList(cbm_defaults_db, localeID = 1)distList(cbm_defaults_db, localeID = 1)
cbm_defaults_db |
Path to CBM defaults SQLite database. |
localeID |
CBM-CFS3 locale_id |
data.table with 'disturbance_type_tr' columns
'disturbance_type_id', 'name', 'description'
Match disturbance names with CBM-CFS3 disturbance types.
distMatch( distNames, nearMatches = TRUE, identical = !ask, ask = interactive(), listDist = NULL, cbm_defaults_db = NULL, localeID = 1, ... )distMatch( distNames, nearMatches = TRUE, identical = !ask, ask = interactive(), listDist = NULL, cbm_defaults_db = NULL, localeID = 1, ... )
distNames |
character. Disturbance names to match with CBM-CFS3 database disturbance type names. |
nearMatches |
logical. Allow for near matches; e.g. "clearcut" can match "clear-cut". |
identical |
logical. Require identical matches. |
ask |
logical. If TRUE, prompt the user to choose the correct matches. If FALSE, the function will look for a single match to each input. |
listDist |
data.table. Optional. Result of a call to |
cbm_defaults_db |
Path to CBM defaults SQLite database. |
localeID |
CBM-CFS3 locale_id |
... |
additional arguments to |
data.table with columns 'disturbance_type_id', 'name', 'description'
Extract values from a spatial data source for each cell of a template raster. Resampling is done using "mode" resampling to preserve categorical values.
extractToRast(input, templateRast, index = 1, crop = TRUE)extractToRast(input, templateRast, index = 1, crop = TRUE)
input |
terra SpatRaster, one or more raster files, or sf polygons. |
templateRast |
SpatRaster. Raster template. |
index |
numeric or character. Raster layer or vector field to extract. |
crop |
logical. Crop input before alignment to template raster. |
vector with a value for each cell of templateRast.
Data type matches input data type.
This uses the underscore delimiter between column names.
gcidsCreate(...)gcidsCreate(...)
... |
The data.table with ONLY the columns on which to determine unique gcids |
Extract the species- and location- specific parameters for equation 4-7 of Boudewyn et al. (2007). If there is no match for the given ecozone, the parameters for a different ecozone in the same province/territory is returned. If there is no match for a given province/territory, the parameters for a different province/territory in the same ecozone is returned. If there is no match for the given ecozone and province/territory, the parameters for a different location is returned.
getParameters(table6, table7, tableMerchantability, curves)getParameters(table6, table7, tableMerchantability, curves)
table6 |
|
table7 |
|
tableMerchantability |
|
curves |
A |
A single data.table containing a row for each curve with all required
parameters from both table6, table7, and tableMerchantability.
Boudewyn, P., Song, X., Magnussen, S., & Gillis, M. D. (2007). Model-based, volume-to-biomass conversion for forested and vegetated land in Canada (BC-X-411). Natural Resource Canada, Pacific Forestry Centre. https://cfs.nrcan.gc.ca/pubwarehouse/pdfs/27434.pdf
Makes plots of all columns for each id_col ID
m3ToBiomPlots(inc, id_col = "gcids", title)m3ToBiomPlots(inc, id_col = "gcids", title)
inc |
increment data |
id_col |
column by which to group plots |
title |
Title of plots |
mapNPPMap Net Primary Productivity (NPP) across a study area.
mapNPP(rastNPP, year = NULL)mapNPP(rastNPP, year = NULL)
rastNPP |
SpatRaster. Pixel values represent NPP (t/ha). |
year |
numeric. Year that the map represents. If provided, it will be included in the plot title. |
ggplot
mapTotalCarbonMap total carbon across a study area.
mapTotalCarbon(rastTC, year = NULL)mapTotalCarbon(rastTC, year = NULL)
rastTC |
SpatRaster. Pixel values represent total carbon (t/ha). |
year |
numeric. Year that the map represents. If provided, it will be included in the plot title. |
ggplot
Implements equation 2 of Boudewyn et al. (2007), used to determine the total stem wood biomass
(in metric tonnes per hectare; ) of non-merchantable trees (), together
with the stemwood biomass of live merchantable and non-merchantable trees (),
using parameters , , and from Table 4 (table4).
nmfac(table4, eq1, vol)nmfac(table4, eq1, vol)
table4 |
|
eq1 |
stemwood biomass of merchantable trees ( |
vol |
gross merchantable volume per hectare ( |
two-column matrix with columns corresponding to and
Boudewyn, P., Song, X., Magnussen, S., & Gillis, M. D. (2007). Model-based, volume-to-biomass conversion for forested and vegetated land in Canada (BC-X-411). Natural Resource Canada, Pacific Forestry Centre. https://cfs.nrcan.gc.ca/pubwarehouse/pdfs/27434.pdf
plotEmissionsProductsPlot yearly emissions and products.
plotEmissionsProducts(emissionsProducts)plotEmissionsProducts(emissionsProducts)
emissionsProducts |
Table of simlation emissions and products by cohort group by year |
ggplot
plotPoolProportionsplotPoolProportions
plotPoolProportions(pools)plotPoolProportions(pools)
pools |
data.table. Table of pools for each cohort, pixel, or year. Must include the 'year' column. |
ggplot
Calculates the proportion of total stemwood considered merchantable.
propMerch(totalStemWood, age, params)propMerch(totalStemWood, age, params)
totalStemWood |
|
age |
|
params |
|
numeric Vector of the proportion of stemwood that is merchantable.
Use reticulate to find or install Python to meet version requirements.
Download and use the pyenv-win
Python version management tool from Github if necessary.
ReticulateFindPython( version, versionInstall = version, pyenvRoot = tools::R_user_dir("CBMutils"), pyenvOnly = FALSE, useGit = TRUE, prompt = FALSE )ReticulateFindPython( version, versionInstall = version, pyenvRoot = tools::R_user_dir("CBMutils"), pyenvOnly = FALSE, useGit = TRUE, prompt = FALSE )
version |
character. Python version or a comma separated list of version constraints.
See |
versionInstall |
character. Version to install if suitable version not found.
Required if |
pyenvRoot |
character. Path of location for install of the pyenv-win tool. Defaults to the R user data directory. |
pyenvOnly |
logical. Exclude versions not within a pyenv install directory. |
useGit |
logical. Allow |
prompt |
logical. Prompt user to approve download of pyenv-win tool. |
This function was created to bypass the requirement for Git to be installed
when install_python is called on a Windows computer
without pyenv-win already installed.
If Git is available, reticulate will clone the
pyenv-win Github repository
and use the tool to install Python.
If Git is not available, this function will instead download the latest version
directly from the repository and make it available to reticulate.
character. Path to Python interpreter.
Implements equation 3 of Boudewyn et al. (2007), used to determine the total stem wood biomass
(in metric tonnes per hectare; ) of sapling-sized trees (),
using parameters , , and from Table 5 (table5).
sapfac(table5, eq2, vol)sapfac(table5, eq2, vol)
table5 |
|
eq2 |
two-column matrix giving stemwood biomass of non-merchantable trees
(i.e., |
vol |
gross merchantable volume per hectare ( |
stemwood biomass of sapling-sized trees ( in units )
Boudewyn, P., Song, X., Magnussen, S., & Gillis, M. D. (2007). Model-based, volume-to-biomass conversion for forested and vegetated land in Canada (BC-X-411). Natural Resource Canada, Pacific Forestry Centre. https://cfs.nrcan.gc.ca/pubwarehouse/pdfs/27434.pdf
Retrieve disturbance source pools, sink pools, and the proportions transferred.
seeDist( EXN = TRUE, matrixIDs = NULL, cbm_defaults_db = NULL, cbm_exn_dir = NULL )seeDist( EXN = TRUE, matrixIDs = NULL, cbm_defaults_db = NULL, cbm_exn_dir = NULL )
EXN |
logical. Use CBM-EXN CBM-CFS3 equivalent model data. |
matrixIDs |
character. Optional. Subset disturbances by disturbance_matrix_id |
cbm_defaults_db |
Path to CBM defaults SQLite database. |
cbm_exn_dir |
Path to CBM-EXN parameters directory. |
List of data.frame named by disturbance_matrix_id
Read a raw data table from a simulation's CBM_core SpaDES CBM database.
simCBMdbReadRaw(simCBM, year, table, ...)simCBMdbReadRaw(simCBM, year, table, ...)
simCBM |
SpaDES.core |
year |
numeric. Year of simulation results. Defaults to the current simulation year. |
table |
character. Name of database table to read. One of 'key', 'parameters', 'state', 'flux', or 'pools'. |
... |
not used |
data.table
Read a data summary from a simulation's CBM_core SpaDES CBM database.
simCBMdbReadSummary( simCBM, summary, by = "cohortID", units = "t/ha", year = NULL, years = NULL, useCache = TRUE )simCBMdbReadSummary( simCBM, summary, by = "cohortID", units = "t/ha", year = NULL, years = NULL, useCache = TRUE )
simCBM |
SpaDES.core |
summary |
character. Name of summary table to collect. |
by |
character. Name of field to summarize results by. Data can be summarized by 'cohortID', 'pixelIndex', or 'year' |
units |
character. 't/ha', 't', or 'Mt'. |
year |
numeric. Year of simulation results.
Required if |
years |
numeric. Years of simulation results to summarize.
Required if |
useCache |
logical. Cache database query result to the database's
|
data.table with key matching the by argument.
Read a table of cohort data from a simulation's CBM_core SpaDES CBM database.
simCBMdbReadTable(simCBM, year, table, useCache = TRUE)simCBMdbReadTable(simCBM, year, table, useCache = TRUE)
simCBM |
SpaDES.core |
year |
numeric. Year of simulation results. Defaults to the current simulation year. |
table |
character. Name of database table to read. One of 'key', 'parameters', 'state', 'flux', or 'pools'. |
useCache |
logical. Cache database query result to the database's
|
data.table with key 'cohortID', columns 'pixelIndex' and 'row_idx' (cohort group ID), and any additional columns in the source table.
Write simulation CBM_core module data to the SpaDES CBM database.
simCBMdbWrite( simCBM, year, parameters = TRUE, state = TRUE, flux = TRUE, pools = TRUE )simCBMdbWrite( simCBM, year, parameters = TRUE, state = TRUE, flux = TRUE, pools = TRUE )
simCBM |
SpaDES.core |
year |
numeric. Simulation data year. Defaults to the current simulation year. |
parameters |
logical. Write the 'parameters' table to file. |
state |
logical. Write the 'state' table to file. |
flux |
logical. Write the 'flux' table to file. |
pools |
logical. Write the 'pools' table to file. |
get the descriptive name and proportions transferred for disturbances in a simulation requires a simulation list post simulations (from spades()) and returns a list of data.frames. Each data had the descriptive name of a disturbance used in the simulations, the disturbance matrix identification number from cbm_defaults, the pool from which carbon is taken (source pools) in this specific disturbance, the pools into which carbon goes, and the proportion in which the carbon-transfers are completed.
simDist(simCBM)simDist(simCBM)
simCBM |
SpaDES.core |
List of data.frame for each disturbance matrix id in the study area, named by disturbance name
simMapNPPMap Net Primary Productivity (NPP) across a study area.
simMapNPP(simCBM, year = NULL, useCache = TRUE)simMapNPP(simCBM, year = NULL, useCache = TRUE)
simCBM |
SpaDES.core |
year |
numeric. Year of simulation results. Defaults to the current simulation year. |
useCache |
logical. Cache database query result to the database's
|
ggplot
simMapTotalCarbonMap total carbon across a study area.
simMapTotalCarbon(simCBM, year = NULL, useCache = TRUE)simMapTotalCarbon(simCBM, year = NULL, useCache = TRUE)
simCBM |
SpaDES.core |
year |
numeric. Year of simulation results. Defaults to the current simulation year. |
useCache |
logical. Cache database query result to the database's
|
ggplot
simPlotEmissionsProductsPlot yearly emissions and products.
simPlotEmissionsProducts(simCBM, years = NULL, useCache = TRUE)simPlotEmissionsProducts(simCBM, years = NULL, useCache = TRUE)
simCBM |
SpaDES.core |
years |
numeric. Simulation years to include in plot. Defaults to all simulation years. |
useCache |
logical. Cache database query result to the database's
|
ggplot
simPlotPoolProportionssimPlotPoolProportions
simPlotPoolProportions(simCBM, years = NULL, useCache = TRUE)simPlotPoolProportions(simCBM, years = NULL, useCache = TRUE)
simCBM |
SpaDES.core |
years |
numeric. Simulation years to include in plot. Defaults to all simulation years. |
useCache |
logical. Cache database query result to the database's
|
ggplot
mapNPP
Map Net Primary Productivity (NPP) across a study area.
spadesCBMdbMapNPP(spadesCBMdb, masterRaster, year, useCache = TRUE)spadesCBMdbMapNPP(spadesCBMdb, masterRaster, year, useCache = TRUE)
spadesCBMdb |
CBM_core module outputs database path. |
masterRaster |
|
year |
numeric. Year of simulation results. |
useCache |
logical. Cache database query result to the database's
|
ggplot
simMapTotalCarbon
Map total carbon across a study area.
spadesCBMdbMapTotalCarbon(spadesCBMdb, masterRaster, year, useCache = TRUE)spadesCBMdbMapTotalCarbon(spadesCBMdb, masterRaster, year, useCache = TRUE)
spadesCBMdb |
CBM_core module outputs database path. |
masterRaster |
|
year |
numeric. Year of simulation results. |
useCache |
logical. Cache database query result to the database's
|
ggplot
plotEmissionsProducts
Plot yearly emissions and products.
spadesCBMdbPlotEmissionsProducts(spadesCBMdb, years, useCache = TRUE)spadesCBMdbPlotEmissionsProducts(spadesCBMdb, years, useCache = TRUE)
spadesCBMdb |
CBM_core module outputs database path. |
years |
numeric. Simulation years to include in plot. |
useCache |
logical. Cache database query result to the database's
|
ggplot
simPlotPoolProportions
spadesCBMdb simPlotPoolProportions
spadesCBMdbPlotPoolProportions(spadesCBMdb, years, useCache = TRUE)spadesCBMdbPlotPoolProportions(spadesCBMdb, years, useCache = TRUE)
spadesCBMdb |
CBM_core module outputs database path. |
years |
numeric. Simulation years to include in plot. |
useCache |
logical. Cache database query result to the database's
|
ggplot
Read a raw data table from a CBM_core SpaDES CBM database.
spadesCBMdbReadRaw(spadesCBMdb, year, table, ...)spadesCBMdbReadRaw(spadesCBMdb, year, table, ...)
spadesCBMdb |
CBM_core module outputs database path. |
year |
numeric. Year of simulation results. |
table |
character. Name of database table to read. One of 'key', 'parameters', 'state', 'flux', or 'pools'. |
... |
not used |
data.table
Read a data summary from a CBM_core SpaDES CBM database.
spadesCBMdbReadSummary( spadesCBMdb, summary, by = "cohortID", units = "t/ha", year = NULL, years = NULL, useCache = TRUE )spadesCBMdbReadSummary( spadesCBMdb, summary, by = "cohortID", units = "t/ha", year = NULL, years = NULL, useCache = TRUE )
spadesCBMdb |
CBM_core module outputs database path. |
summary |
character. Name of summary table to collect. |
by |
character. Name of field to summarize results by. Data can be summarized by 'cohortID', 'pixelIndex', or 'year' |
units |
character. 't/ha', 't', or 'Mt'. |
year |
numeric. Year of simulation results.
Required if |
years |
numeric. Years of simulation results to summarize.
Required if |
useCache |
logical. Cache database query result to the database's
|
data.table with key matching the by argument.
Read a table of cohort data from a CBM_core SpaDES CBM database.
spadesCBMdbReadTable(spadesCBMdb, year, table, useCache = TRUE)spadesCBMdbReadTable(spadesCBMdb, year, table, useCache = TRUE)
spadesCBMdb |
CBM_core module outputs database path. |
year |
numeric. Year of simulation results. |
table |
character. Name of database table to read. One of 'key', 'parameters', 'state', 'flux', or 'pools'. |
useCache |
logical. Cache database query result to the database's
|
data.table with key 'cohortID', columns 'pixelIndex' and 'row_idx' (cohort group ID), and any additional columns in the source table.
Retrieve species metadata by matching species names or other identifiers with columns in sppEquivalencies.
sppMatch( species, match = c("LandR", "Latin_full", "EN_generic_short", "EN_generic_full"), otherNames = NULL, return = NULL, checkNA = !is.null(return), sppEquivalencies = NULL )sppMatch( species, match = c("LandR", "Latin_full", "EN_generic_short", "EN_generic_full"), otherNames = NULL, return = NULL, checkNA = !is.null(return), sppEquivalencies = NULL )
species |
Species identifiers. |
match |
character. |
otherNames |
list. A list of alternative species identified to allow in matching.
Item names must match |
return |
character. |
checkNA |
logical. Check for NA values in the returned columns.
Defaults to TRUE if the |
sppEquivalencies |
data.table. Table of species identifiers and metadata.
Defaults to |
data.table. Subset of sppEquivalencies with 1 row per species.
List the disturbances possible in spatial units.
spuDistList( EXN = TRUE, spuIDs = NULL, cbm_defaults_db = NULL, cbm_exn_dir = NULL, localeID = 1 )spuDistList( EXN = TRUE, spuIDs = NULL, cbm_defaults_db = NULL, cbm_exn_dir = NULL, localeID = 1 )
EXN |
logical. Use CBM-EXN CBM-CFS3 equivalent model data. |
spuIDs |
Optional. Subset by spatial unit ID(s) |
cbm_defaults_db |
Path to CBM defaults SQLite database. |
cbm_exn_dir |
Path to CBM-EXN parameters directory. |
localeID |
CBM-CFS3 locale_id |
data.table with 'disturbance_type_tr' columns
'disturbance_type_id', 'name', 'description'
and 'disturbance_matrix_association' columns
'spatial_unit_id' and 'disturbance_matrix_id'
Match disturbance names with CBM-CFS3 spatial unit disturbances.
spuDistMatch( distTable, nearMatches = TRUE, identical = !ask, ask = interactive(), listDist = NULL, ... )spuDistMatch( distTable, nearMatches = TRUE, identical = !ask, ask = interactive(), listDist = NULL, ... )
distTable |
|
nearMatches |
logical. Allow for near matches; e.g. "clearcut" can match "clear-cut". |
identical |
logical. Require identical matches. |
ask |
logical. If TRUE, prompt the user to choose the correct matches. If FALSE, the function will look for a single match to each input. |
listDist |
data.table. Optional. Result of a call to |
... |
arguments to |
data.table with columns
'spatial_unit_id', 'disturbance_type_id', 'disturbance_matrix_id', 'name', 'description'
Identifies the stand-replacing wildfire disturbance in each spatial unit.
spuHistDist(spuIDs, localeID = 1, ask = FALSE, ...)spuHistDist(spuIDs, localeID = 1, ask = FALSE, ...)
spuIDs |
Spatial unit ID(s) |
localeID |
CBM-CFS3 locale_id |
ask |
logical. If TRUE, prompt the user to choose the correct disturbance matches. If FALSE, the function will look for exact name matches. |
... |
arguments to |
In all spatial units in Canada, the historical disturbance is set to fire. Historical disturbances in CBM-CFS3 are used for "filling-up" the soil-related carbon pools. Boudewyn et al. (2007) translate the m3/ha curves into biomass per ha in each of four pools: total biomass for stem wood, total biomass for bark, total biomass for branches and total biomass for foliage. Biomass in coarse and fine roots, in aboveground- and belowground- very-fast, -fast, -slow, in medium-soil, and in snags still needs to be estimated. A stand-replacing fire disturbance is used in a disturb-grow cycle, where stands are disturbed and regrown with turnover, overmature, decay, functioning until the dead organic matter pools biomass values stabilize (+/- 10%) (TODO: check this).
Replace the values in a SpatRaster before writing it to file.
writeRasterWithValues(templateRast, filename, cells = NULL, values = NULL, ...)writeRasterWithValues(templateRast, filename, cells = NULL, values = NULL, ...)
templateRast |
terra |
filename |
character. Output filename. |
cells |
integer. Raster cell index. |
values |
numeric or character. New raster values. |
... |
arguments to |