This function prepares obs_df in the exact format expected by
FINN::CohortMat$new() and calls it. The required long-table schema is:
siteID integer index of sites \(1..S\).
patchID integer index of patches within site \(1..P_s\).
species integer species code \(1..sp\).
dbh numeric DBH in cm (either exact or binned midpoints).
trees integer count of trees in the cohort.
Usage
makeInitCohorts(
init_trees,
dbh_binsize = NULL,
min_dbh = NULL,
Nspecies,
treeID_table = F,
singleCohortTreeNames = NULL
)Arguments
- init_trees
data.table of initial trees with columns
siteID,patchID,species,dbh,treeName; optionaltreesfor pre-counted individuals.- dbh_binsize
numeric or NULL. Bin width in cm. If NULL, keep exact DBH.
- min_dbh
numeric or NULL. Lower bound for binning. If NULL, uses min DBH.
- Nspecies
integer. Number of species levels passed to
sp.- treeID_table
logical. If TRUE, also return the cohort table used.
- singleCohortTreeNames
character vector or NULL. Tree names excluded from binning and kept as single-tree cohorts.
Value
If treeID_table = FALSE, a FINN::CohortMat object.
If TRUE, a list with:
initCohort: theCohortMatobject.init_trees: theobs_dfpassed toCohortMat$new().
Details
Aggregates initial trees into cohorts by DBH bins or exact DBH and
constructs a FINN::CohortMat object.
Internally calls:
FINN::CohortMat$new(
obs_df = <data.frame with columns siteID, patchID, species, dbh, trees>,
dbh = NULL,
trees = NULL,
species= NULL,
dims = c(S, P, K), # inferred from obs_df
sp = Nspecies, # passed from argument
device = "cpu"
)
Key fields of the resulting R6 object:
dbh,trees,species: tensors per cohort.dims: integer vectorc(S, P, K)for sites, patches, cohorts.sp: integer number of species.device: "cpu" or "cuda".dbh_r,trees_r,species_r: R arrays.obsDF2arrays: method convertingobs_dfinto arrays.