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], Alex M Chubaty [aut, cre] , Ian Eddy [ctb], Eliot McIntire [aut] |
Maintainer: | Alex M Chubaty <[email protected]> |
License: | GPL-3 |
Version: | 0.0.7.9011 |
Built: | 2024-11-14 23:23:37 UTC |
Source: | https://github.com/PredictiveEcology/CBMutils |
CBMutils
Utilities for modelling carbon in R/SpaDES based on the Carbon Budget Model of the Canadian Forest Service v3 (CBM-CFS3).
Maintainer: Alex M Chubaty [email protected] (ORCID)
Authors:
Céline Boisvenue [email protected]
Eliot McIntire [email protected]
Other contributors:
Ian Eddy [email protected] [contributor]
Useful links:
TODO: confirm these
.pooldef .pooldefids .poolnames .poolids
.pooldef .pooldefids .poolnames .poolids
An object of class character
of length 26.
An object of class environment
of length 26.
An object of class character
of length 25.
An object of class environment
of length 25.
NOTE: A reminder that indexing in R starts at 1, whereas in C++ it starts at 0.
Several C++ data structures do not include the Input category, so the indices there are
defined using .poolids - 1
.
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
barPlot
barPlot
barPlot(cbmPools, masterRaster)
barPlot(cbmPools, masterRaster)
cbmPools |
TODO |
masterRaster |
A |
TODO
Biomass turnover matrix
biomassTurnoverMatrix(turnoverParam, PoolCount)
biomassTurnoverMatrix(turnoverParam, PoolCount)
turnoverParam |
DESCRIPTION NEEDED |
PoolCount |
DESCRIPTION NEEDED |
DESCRIPTION NEEDED
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, vol)
biomProp(table6, table7, vol)
table6 |
|
table7 |
|
vol |
gross merchantable volume per hectare ( |
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
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 |
A |
DESCRIPTION NEEDED
For all spatial units in the simulation, calculate turnover rates.
calcTurnoverRates(turnoverRates, spatialUnitIds, spatialUnits)
calcTurnoverRates(turnoverRates, spatialUnitIds, spatialUnits)
turnoverRates |
DESCRIPTION NEEEDED |
spatialUnitIds |
DESCRIPTION NEEEDED |
spatialUnits |
DESCRIPTION NEEEDED |
extracts the turnover rates for the specific SPU you are in. These are used to in the core module to calculate the specific rates, which are the used to calculate Net Primary Productivity (NPP) both in the core module and in the next function.
carbonOutPlot
carbonOutPlot
carbonOutPlot(emissionsProducts, masterRaster)
carbonOutPlot(emissionsProducts, masterRaster)
emissionsProducts |
TODO |
masterRaster |
A |
invoked for side effect of creating plot
check that the proportions add up to 1
checkProp(DTofMatrices, tarCols)
checkProp(DTofMatrices, tarCols)
DTofMatrices |
DESCRIPTION NEEDED |
tarCols |
DESCRIPTION NEEEDED |
DESCRIPTION NEEDED
Post-simulations, this function takes the last two years of simulations,
and verifies that the C transfers are as expected on n random pixelGroups.
It randomly selects three pixelGroups
, calculated the expected transactions from time
end(sim)
and time end(sim) - 1
, and compares them to the last year of simulations.
Cases of disturbed, non disturbed, sw, hw, young and old stands were tested.
checkTransactions( cbmPools, pixelKeep, opMatrixCBM, allProcesses, pixelGroupC, pooldef, timeSim, outputsSim, n = 3 )
checkTransactions( cbmPools, pixelKeep, opMatrixCBM, allProcesses, pixelGroupC, pooldef, timeSim, outputsSim, n = 3 )
cbmPools |
from sim$cbmPools |
pixelKeep |
from sim$pixelKeep |
opMatrixCBM |
from sim$opMatrixCBM |
allProcesses |
from sim$allProcesses |
pixelGroupC |
from sim$pixelGroupC |
pooldef |
from sim$pooldef |
timeSim |
from time(sim) |
outputsSim |
from outputs(sim) |
n |
number of pixelGroups (i.e., size of subset) to check |
Read-in data
randomly select 3 pixelGroups
read-in carbon pools at timeSim
and timeSim - 1
for the three pixelGroup
pull-out matrices applied to these three pixelGroups
between t0
and t1
matrices into a data.table
prep pools at t0
merge three pools at t0
with their respective transaction matrices ids
apply all matrices (8.1:8.9
)
TODO: I am passing a whole simList
here for simplification, but only these objects needed:
$cbmPools
;
$pixelKeep
;
$opMatrixCBM
;
$allProcesses
;
$pooldef
.
TODO: there are still a bunch of checks that need to be changed to assertions (if statements?)
All arguments come from a simList
object of the same name, except timeSim (which comes from time(sim))
and outputsSim (which comes from outputs(sim)).
Compute Turnover Matrices
computeBioTurnoverMatrices(turnoverParameters, PoolCount)
computeBioTurnoverMatrices(turnoverParameters, PoolCount)
turnoverParameters |
DESCRIPTION NEEDED |
PoolCount |
DESCRIPTION NEEDED |
DESCRIPTION NEEDED
The first column in the specified decayRates
parameter acts as the key to each matrix.
computeDomDecayMatrices(decayRates, decayParameters, PoolCount)
computeDomDecayMatrices(decayRates, decayParameters, PoolCount)
decayRates |
matrix of decay rates column 1 is the key for the values
in columns |
decayParameters |
table of CBM decay parameters |
PoolCount |
DESCRIPTION NEEDED |
DESCRIPTION NEEDED
Compute DOM turnover matrices
computeDomTurnoverMatrices(turnoverParameters, PoolCount)
computeDomTurnoverMatrices(turnoverParameters, PoolCount)
turnoverParameters |
DESCRIPTION NEEDED |
PoolCount |
DESCRIPTION NEEDED |
DESCRIPTION NEEDED
DESCRIPTION NEEDED
growthIncrements |
Matrix of growth increments |
decline |
Matrix containing proportion decline for each pool |
DESCRIPTION NEEDED
ComputeGrowthAndDeclineMatrices2( growthIncrements, ages, gcids, pools, rootParameters, turnoverParams, biomassToCarbonRate, swMult = 1, hwMult = 1 )
ComputeGrowthAndDeclineMatrices2( growthIncrements, ages, gcids, pools, rootParameters, turnoverParams, biomassToCarbonRate, swMult = 1, hwMult = 1 )
growthIncrements |
a hash table of growth increments by |
ages |
the stand age, (the inventory age) stands will be simulated to this age in the final pass |
gcids |
integer vector of growth curve ids |
pools |
Matrix (DESCRIPTION NEEDED) |
rootParameters |
|
turnoverParams |
'data.frame specifying turnover parameters |
biomassToCarbonRate |
numeric DESCRIPTION NEEDED |
swMult |
softwood multiplier? (DESCRITION NEEDED) |
hwMult |
hardwood multiplier? (DESCRITION NEEDED) |
Transforms growth matrix into coordinate format matrix in terms of CBM pools.
pn |
|
growthIncrements |
Matrix of growth increments |
Compute the total growth (above ground and belowground) increment matrices for all stands based on age and hashtable of growth increments by growth curve id.
ComputeGrowthIncrements( growthIncrements, ages, gcids, pools, rootParameters, biomassToCarbonRate, swMult = 1, hwMult = 1 )
ComputeGrowthIncrements( growthIncrements, ages, gcids, pools, rootParameters, biomassToCarbonRate, swMult = 1, hwMult = 1 )
growthIncrements |
a hash table of growth increments by |
ages |
the stand age, (the inventory age) stands will be simulated to this age in the final pass |
gcids |
DESCRIPTION NEEDED |
pools |
DESCRIPTION NEEDED |
rootParameters |
|
biomassToCarbonRate |
DESCRIPTION NEEDED |
swMult |
softwood multiplier? (DESCRIPTION NEEDED) |
hwMult |
hardwood multiplier? (DESCRIPTION NEEDED) |
Compute flows to dom pools that occur on a growth curve decline.
ComputeOvermatureDecline(growthIncrements, turnoverParams)
ComputeOvermatureDecline(growthIncrements, turnoverParams)
growthIncrements |
Matrix of growth increments |
turnoverParams |
|
Transforms overmature decline matrix into coordinate format matrix in terms of CBM pools.
pn |
|
decline |
Matrix containing proportion decline for each pool |
Compute slow decay matrices
computeSlowDecayMatrices(decayRates, decayParameters, PoolCount)
computeSlowDecayMatrices(decayRates, decayParameters, PoolCount)
decayRates |
DESCRIPTION NEEDED |
decayParameters |
DESCRIPTION NEEDED |
PoolCount |
DESCRIPTION NEEDED |
DESCRIPTION NEEDED
Compute slow mixing matrix
computeSlowMixingMatrix(slowMixingRate, PoolCount)
computeSlowMixingMatrix(slowMixingRate, PoolCount)
slowMixingRate |
DESCRIPTION NEEDED |
PoolCount |
DESCRIPTION NEEDED |
DESCRIPTION NEEDED
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 |
DESCRIPTION NEEDED |
gCvalues |
DESCRIPTION NEEDED |
spsMatch |
DESCRIPTION NEEDED |
ecozones |
DESCRIPTION NEEDED |
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
cumPools
data.tableCreate cumPools
data.table
cumPoolsCreate( fullSpecies, gcMeta, userGcM3, stable3, stable4, stable5, stable6, stable7, thisAdmin )
cumPoolsCreate( fullSpecies, gcMeta, userGcM3, stable3, stable4, stable5, stable6, stable7, thisAdmin )
fullSpecies |
DESCRIPTION NEEDED |
gcMeta |
DESCRIPTION NEEDED |
userGcM3 |
DESCRIPTION NEEDED |
stable3 |
DESCRIPTION NEEDED |
stable4 |
DESCRIPTION NEEDED |
stable5 |
DESCRIPTION NEEDED |
stable6 |
DESCRIPTION NEEDED |
stable7 |
DESCRIPTION NEEDED |
thisAdmin |
DESCRIPTION NEEDED |
cumPools
data.table
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
This is the ecological theory for decomposing being used in CBM.
decayRate(meanAnnualTemp, baseDecayRate, q10, tref, max)
decayRate(meanAnnualTemp, baseDecayRate, q10, tref, max)
meanAnnualTemp |
scalar temperature in degrees Celsius |
baseDecayRate |
scalar base decay rate constant |
q10 |
the scalar q10 value |
tref |
the reference temperature |
max |
the maximum allowed decay rate |
the scalar rate of decay
Compute a single dom decay matrix based on the specified table of decay rates
domDecayMatrix(decayRates, decayParameters, PoolCount)
domDecayMatrix(decayRates, decayParameters, PoolCount)
decayRates |
vector of decay rates (each element represents a dom pool) |
decayParameters |
table of cbm decay parameters |
PoolCount |
DESCRIPTION NEEDED |
DESCRIPTION NEEDED
Calculate a portion of the DOM decay matrix
domDecayMatrixItem(mat, decayRates, propToAtmosphere, src, dst, emission)
domDecayMatrixItem(mat, decayRates, propToAtmosphere, src, dst, emission)
mat |
the datatable |
decayRates |
vector of annual decay rates by dom pool |
propToAtmosphere |
vector of the proportions of decay emitted to the atmosphere as CO2 by this process |
src |
the integer code for the dom pool being decayed |
dst |
the integer code for the dom pool receiving non-emitted decayed matter |
emission |
the integer code for the CO2 pool |
A modified copy of the input mat
DOM turnover matrix
domTurnOverMatrix(turnoverParam, PoolCount)
domTurnOverMatrix(turnoverParam, PoolCount)
turnoverParam |
DESCRIPTION NEEDED |
PoolCount |
DESCRIPTION NEEDED |
DESCRIPTION NEEDED
This uses the underscore delimiter between column names.
gcidsCreate(...)
gcidsCreate(...)
... |
The data.table with ONLY the columns on which to determine unique gcids |
Returns a vector of decay rates where the indices of the vector are the DOM pools of CBM.
getDecayRates(meanAnnualTemp, decayParameters, domPools)
getDecayRates(meanAnnualTemp, decayParameters, domPools)
meanAnnualTemp |
scalar temperature in deg Celcius |
decayParameters |
table of decay parameters for calculating the temperature dependent decay rate |
domPools |
DESCRIPTION NEEDED |
the vector of decay rates
DESCRIPTION NEEDED
getIdentityCoordinateMatrix(size)
getIdentityCoordinateMatrix(size)
size |
Numeric indicating the number of rows and columns in the matrix. |
DESCRIPTION NEEDED
getTable(filename, dbPath, sqlDir)
getTable(filename, dbPath, sqlDir)
filename |
DESCRIPTION NEEDED |
dbPath |
DESCRIPTION NEEDED |
sqlDir |
DESCRIPTION NEEDED |
DESCRIPTION NEEDED
hash(x) matrixHash(x)
hash(x) matrixHash(x)
x |
DESCRIPTION NEEDED |
Identifies the stand-replacing wildfire disturbance in each spatial unit.
histDist(mySpu = c(27, 28))
histDist(mySpu = c(27, 28))
mySpu |
Numeric spatial unit id(s). |
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. In all spatial units in Canada, the historical disturbance is set to fire. 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%).
By default the most recent is selected, but the user can change that.
Load disturbance matrix IDs
loadDisturbanceMatrixIds(disturbanceMatrixValues, dbPools)
loadDisturbanceMatrixIds(disturbanceMatrixValues, dbPools)
disturbanceMatrixValues |
DESCRIPTION NEEDED |
dbPools |
DESCRIPTION NEEDED |
DESCRIPTION NEEDED
m3ToBiomIncOnlyPlots
m3ToBiomIncOnlyPlots
m3ToBiomIncOnlyPlots(inc)
m3ToBiomIncOnlyPlots(inc)
inc |
TODO |
TODO
Plot all columns that are not id_col
m3ToBiomPlots( inc = "increments", id_col = "gcids", nrow = 5, ncol = 5, filenameBase = "rawCumBiomass_", path = NULL, title = "Cumulative merch fol other by gc id", scales = "free_y" )
m3ToBiomPlots( inc = "increments", id_col = "gcids", nrow = 5, ncol = 5, filenameBase = "rawCumBiomass_", path = NULL, title = "Cumulative merch fol other by gc id", scales = "free_y" )
inc |
DESCRIPTION NEEDED |
id_col |
DESCRIPTION NEEDED |
nrow |
DESCRIPTION NEEDED |
ncol |
DESCRIPTION NEEDED |
filenameBase |
DESCRIPTION NEEDED |
path |
DESCRIPTION NEEDED |
title |
DESCRIPTION NEEDED |
scales |
DESCRIPTION NEEDED |
Check the growth increments by above ground pool. This is necessary because the Boudewyn et al parameters used to translate the m3/ha into biomass/ha do not always work. Returns a list of plots, each plot show the merch, fol, and other increments for a specific growth curve.
m3ToVolCheckPlots(sim)
m3ToVolCheckPlots(sim)
sim |
A |
data.table
out of the carbon transfer matricesMake a data.table
out of the carbon transfer matrices
matrixDT(matricesIn, indicesIn)
matrixDT(matricesIn, indicesIn)
matricesIn |
DESCRIPTION NEEDED |
indicesIn |
DESCRIPTION NEEDED |
a data.table
object summarizing the carbon transfers
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
Calculate post-simulation net primary productivity
NPP(pools, pixelGroupSpu, year1, year2, turnoverRates)
NPP(pools, pixelGroupSpu, year1, year2, turnoverRates)
pools |
DESCRIPTION NEEDED |
pixelGroupSpu |
DESCRIPTION NEEDED |
year1 , year2
|
Consecutive start and end years (e.g., 1990, 1991) |
turnoverRates |
DESCRIPTION NEEDED |
## Not run: spadesCBMout <- simInitAndSpades() ## TODO: fill this in NPP(pools = spadesCBMout$cbmPools, pixelGroupSpu = spadesCBMout$pixelGroupC[, .(pixelGroup, spatial_unit_id)], year1 = 1990, year2 = 1991, turnoverRates = spadesCBMout$turnoverRates) ## End(Not run)
## Not run: spadesCBMout <- simInitAndSpades() ## TODO: fill this in NPP(pools = spadesCBMout$cbmPools, pixelGroupSpu = spadesCBMout$pixelGroupC[, .(pixelGroup, spatial_unit_id)], year1 = 1990, year2 = 1991, turnoverRates = spadesCBMout$turnoverRates) ## End(Not run)
NPPplot
NPPplot
NPPplot(spatialDT, NPP, masterRaster)
NPPplot(spatialDT, NPP, masterRaster)
spatialDT |
TODO |
NPP |
TODO |
masterRaster |
A |
TODO
Plotting pools
plotCarbonRasters(pixelkeep, cbmPools, poolsToPlot, years, masterRaster)
plotCarbonRasters(pixelkeep, cbmPools, poolsToPlot, years, masterRaster)
pixelkeep |
DESCRIPTION NEEDED |
cbmPools |
DESCRIPTION NEEDED |
poolsToPlot |
DESCRIPTION NEEDED |
years |
DESCRIPTION NEEDED |
masterRaster |
A |
## Not run: # include 'totalCarbon' in poolsToPlot to add plot of total carbon plotCarbonRasters( cbmPools = spadesCBMout$cbmPools, poolsToPlot = c("totalCarbon", "BelowGroundSlowSoil"), masterRaster = spadesCBMout$masterRaster, pixelkeep = spadesCBMout$pixelKeep, years = c(1990, 2000, 2005) ) ## End(Not run)
## Not run: # include 'totalCarbon' in poolsToPlot to add plot of total carbon plotCarbonRasters( cbmPools = spadesCBMout$cbmPools, poolsToPlot = c("totalCarbon", "BelowGroundSlowSoil"), masterRaster = spadesCBMout$masterRaster, pixelkeep = spadesCBMout$pixelKeep, years = c(1990, 2000, 2005) ) ## End(Not run)
prepInputsEcozones
prepInputsEcozones
prepInputsEcozones(url = NULL, dPath, rasterToMatch)
prepInputsEcozones(url = NULL, dPath, rasterToMatch)
url |
A URL to the data |
dPath |
destination path |
rasterToMatch |
A |
prepInputsVRI
Read in the BC VRI, with growth curve information (from ws3
), and creates a raster stack of
the age and gcID
.
prepInputsVRI(url, dPath, rasterToMatch)
prepInputsVRI(url, dPath, rasterToMatch)
url |
A URL to the data |
dPath |
destination path |
rasterToMatch |
A |
ws3
), and creates a raster stack of
the ageRead in the BC VRI, with growth curve information (from ws3
), and creates a raster stack of
the age
prepInputsVRIage( VRIurl, dPath, rasterToMatch, targetFile, field = "PROJ_AGE_1" )
prepInputsVRIage( VRIurl, dPath, rasterToMatch, targetFile, field = "PROJ_AGE_1" )
VRIurl |
a URL to the data |
dPath |
destination path |
rasterToMatch |
A |
targetFile |
A |
field |
The age column name in the inventory file. |
DESCRIPTION NEEDED
query(dbPath, sql)
query(dbPath, sql)
dbPath |
Path to sqlite database file. |
sql |
SQL statement with to execute in the database. |
DESCRIPTION NEEDED
readSqlFile(filePath)
readSqlFile(filePath)
filePath |
Path to sqlite database file. |
spUnits
Produce a raster with spUnits
retrieveSpuRaster( spatialUnitsFile = shapefile("data/spUnit_Locator.shp"), UserArea, rasterRes = c(250, 250) )
retrieveSpuRaster( spatialUnitsFile = shapefile("data/spUnit_Locator.shp"), UserArea, rasterRes = c(250, 250) )
spatialUnitsFile |
DESCRIPTION NEEDED |
UserArea |
DESCRIPTION NEEDED |
rasterRes |
The desired raster resolution. |
## Not run: test1 <- raster::shapefile("data/forIan/SK_data/CBM_GIS/SpadesCBM_TestArea.shp") out1 <- retrieveSpuRaster(UserArea = test1, rasterRes = c(250, 250)) if (interactive()) Plot(out1) ## End(Not run)
## Not run: test1 <- raster::shapefile("data/forIan/SK_data/CBM_GIS/SpadesCBM_TestArea.shp") out1 <- retrieveSpuRaster(UserArea = test1, rasterRes = c(250, 250)) if (interactive()) Plot(out1) ## End(Not run)
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
Get the descriptive name of the disturbance, the source pools, the sink pools, and the proportions transferred.
seeDist( distId = c(161, 230, 313, 361), dbPath = file.path("data", "cbm_defaults", "cbm_defaults.db") )
seeDist( distId = c(161, 230, 313, 361), dbPath = file.path("data", "cbm_defaults", "cbm_defaults.db") )
distId |
Description needed |
dbPath |
Path to sqlite database file. |
A list of data.frame
s, one per disturbance matrix id.
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(sim)
simDist(sim)
sim |
A |
Slow decay matrix
slowDecayMatrix(decayRates, decayParameters, PoolCount)
slowDecayMatrix(decayRates, decayParameters, PoolCount)
decayRates |
DESCRIPTION NEEDED |
decayParameters |
DESCRIPTION NEEDED |
PoolCount |
DESCRIPTION NEEDED |
DESCRIPTION NEEDED
spatialPlot
spatialPlot
spatialPlot(pixelkeep, cbmPools, poolsToPlot, years, masterRaster)
spatialPlot(pixelkeep, cbmPools, poolsToPlot, years, masterRaster)
pixelkeep |
TODO |
cbmPools |
TODO |
poolsToPlot |
TODO |
years |
TODO |
masterRaster |
A |
TODO
the spatialPlot
function plots rasters directly, but does not return rasters, whereas
it does so here.
spatialRaster(pixelkeep, cbmPools, poolsToPlot, years, masterRaster)
spatialRaster(pixelkeep, cbmPools, poolsToPlot, years, masterRaster)
pixelkeep |
DESCRIPTION NEEDED |
cbmPools |
DESCRIPTION NEEDED |
poolsToPlot |
DESCRIPTION NEEDED |
years |
DESCRIPTION NEEDED |
masterRaster |
A |
RasterLayer
but invoked for its side-effect of plotting the rasters.
spatialPlot
Spatial unit decay rates
spatialUnitDecayRates(climate, decayparameters, domPools)
spatialUnitDecayRates(climate, decayparameters, domPools)
climate |
DESCRIPTION NEEDED |
decayparameters |
DESCRIPTION NEEDED |
domPools |
DESCRIPTION NEEDED |
DESCRIPTION NEEDED
Spinup a landscape by running rotations of stand replacing disturbances repeatedly until the pre-disturbance slow pools and the last rotation pre-disturbance slow pools are within a tolerance. Stand then grows to inventory age, and is ready for CBM simulation.
Spinup( pools, opMatrix, constantProcesses, growthIncrements, ages, gcids, historicdmids, lastPassdmids, delays, minRotations, maxRotations, returnIntervals, rootParameters, turnoverParams, biomassToCarbonRate, debug = FALSE )
Spinup( pools, opMatrix, constantProcesses, growthIncrements, ages, gcids, historicdmids, lastPassdmids, delays, minRotations, maxRotations, returnIntervals, rootParameters, turnoverParams, biomassToCarbonRate, debug = FALSE )
pools |
Matrix (DESCRIPTION NEEDED) |
opMatrix |
Matrix (DESCRIPTION NEEDED) |
constantProcesses |
a list of constant process C dynamics matrices |
growthIncrements |
a hash table of growth increments by |
ages |
the stand age, (the inventory age) stands will be simulated to this age in the final pass |
gcids |
the growth curve ids (referenced by |
historicdmids |
(DESCRIPTION NEEDED) |
lastPassdmids |
(DESCRIPTION NEEDED) |
delays |
(DESCRIPTION NEEDED) |
minRotations |
(DESCRIPTION NEEDED) |
maxRotations |
(DESCRIPTION NEEDED) |
returnIntervals |
(DESCRIPTION NEEDED) |
rootParameters |
|
turnoverParams |
|
biomassToCarbonRate |
(DESCRIPTION NEEDED) |
debug |
logical indicating whether to run spinup in debug mode. |
You give is spatial units you are targeting mySpu
and it gives you the disturbance matrix id
that are possible/default in that specific spu and a descriptive name of that disturbance matrix
it creates a data.frame
of length number of disturbances, with three columns:
spatial_unit_is
, disturbance_matrix_id
, and a desciption
of the disturbance.
spuDist(mySpu, dbPath)
spuDist(mySpu, dbPath)
mySpu |
Numeric spatial unit id(s). |
dbPath |
Path to sqlite database file. |
TODO: can we have a Canada-wide SPU map and they locate themselves on the map? this needs to be done before simulations are run so the user can provide this info (location info) for the simulations - Ian is working on this.
the function has the defaults from the SK managed forest example. These can be changed by feeding in other SPU.
## Not run: ## using raster library(terra) spuRaster <- rast(file.path("data/forIan/SK_data/CBM_GIS/spUnits_TestArea.tif")) spatial_unit_id <- values(spuRaster) # 28 27 mySpu <- unique(spatial_unit_id) ## using growth curves f <- file.path("spadesCBMinputs/data/SK_ReclineRuns30m/LookupTables/yieldRCBM.csv") gcIn <- as.matrix(read.csv(f)) mySpu <- unique(gcIn[, 1]) ## End(Not run)
## Not run: ## using raster library(terra) spuRaster <- rast(file.path("data/forIan/SK_data/CBM_GIS/spUnits_TestArea.tif")) spatial_unit_id <- values(spuRaster) # 28 27 mySpu <- unique(spatial_unit_id) ## using growth curves f <- file.path("spadesCBMinputs/data/SK_ReclineRuns30m/LookupTables/yieldRCBM.csv") gcIn <- as.matrix(read.csv(f)) mySpu <- unique(gcIn[, 1]) ## End(Not run)
Computes by row (stand/pixelGroup
) across all columns (pools).
StepPools(pools, opMatrix, flowMatrices)
StepPools(pools, opMatrix, flowMatrices)
pools |
A numeric matrix describing the amount of carbon in each pool (column) across multiple stands/pixel groups (rows). |
opMatrix |
A numeric matrix with columns corresponding to flows, and rows corresponding
to stands/pixel groups. Values are indices into the |
flowMatrices |
A list of lists (or environments) containing all carbon flow matrices. |
nPixGrp <- 3 pools <- matrix(c(1.0, 10.0, 0.0, 1.0, 20.0, 0.0, 1.0, 5.0, 0.0), ncol = 3, nrow = nPixGrp, byrow = TRUE) colnames(pools) <- c("input", "pool1", "pool2") pools ## input pool1 pool2 ## [1,] 1 10 0 ## [2,] 1 20 0 ## [3,] 1 5 0 op <- matrix(rep(c(1, 1), nPixGrp), ncol = 2, nrow = nPixGrp, byrow = TRUE) colnames(op) <- c("disturbance", "growth") cnames <- c("row", "col", "value") dist <- matrix(c(2, 3, 1, 1, 1, 1), ncol = 3, nrow = 2, byrow = TRUE) colnames(dist) <- cnames grow <- matrix(c(1, 2, 0.1, 1, 3, 0.2, 2, 3, 0.3, 3, 3, 1.0), ncol = 3, nrow = 4, byrow = TRUE) colnames(grow) <- cnames flow <- list(Disturbance = list(dist), Growth = list(grow)) new_pools <- StepPools(pools, op, flow) new_pools ## input pool1 pool2 ## [1,] 1 0.1 10.2 ## [2,] 1 0.1 20.2 ## [3,] 1 0.1 5.2
nPixGrp <- 3 pools <- matrix(c(1.0, 10.0, 0.0, 1.0, 20.0, 0.0, 1.0, 5.0, 0.0), ncol = 3, nrow = nPixGrp, byrow = TRUE) colnames(pools) <- c("input", "pool1", "pool2") pools ## input pool1 pool2 ## [1,] 1 10 0 ## [2,] 1 20 0 ## [3,] 1 5 0 op <- matrix(rep(c(1, 1), nPixGrp), ncol = 2, nrow = nPixGrp, byrow = TRUE) colnames(op) <- c("disturbance", "growth") cnames <- c("row", "col", "value") dist <- matrix(c(2, 3, 1, 1, 1, 1), ncol = 3, nrow = 2, byrow = TRUE) colnames(dist) <- cnames grow <- matrix(c(1, 2, 0.1, 1, 3, 0.2, 2, 3, 0.3, 3, 3, 1.0), ncol = 3, nrow = 4, byrow = TRUE) colnames(grow) <- cnames flow <- list(Disturbance = list(dist), Growth = list(grow)) new_pools <- StepPools(pools, op, flow) new_pools ## input pool1 pool2 ## [1,] 1 0.1 10.2 ## [2,] 1 0.1 20.2 ## [3,] 1 0.1 5.2
Computes by row (stand/pixelGroup
) across all columns (pools) in place.
StepPoolsRef(pools, opMatrix, flowMatrices)
StepPoolsRef(pools, opMatrix, flowMatrices)
pools |
A numeric matrix describing the amount of carbon in each pool (column) across multiple stands/pixel groups (rows). |
opMatrix |
A numeric matrix with columns corresponding to flows, and rows corresponding
to stands/pixel groups. Values are indices into the |
flowMatrices |
A list of lists (or environments) containing all carbon flow matrices. |
ws3Build
ws3
, the harvest optimizer created by Greg Paradis provided the BC disturbance rasters
(harvest or harvest and fires) per TSA and not for the whole study area.
This function reads-in the file structure, pulls in all the TSA-level rasters,
knits them together and post-processes them to match the rasterToMatch
.
ws3Build(masterRaster, tsaDirs, years, pathsTifs)
ws3Build(masterRaster, tsaDirs, years, pathsTifs)
masterRaster |
A |
tsaDirs |
character vector of paths to the TSA directories |
years |
numeric or integer vector specifying the years for the data |
pathsTifs |
character vector of paths for the geotiff files |