| inventoryMetrics | R Documentation |
Run a complete inventory workflow by dispatching to either
dendroMetrics for Spanish National Forest Inventory
inputs or to external_dendroMetrics() for external
inventories. The function is intentionally thin: it decides which
backend to use, forwards the relevant arguments, and stores the
original call so the result can be updated later with
update.
inventoryMetrics(nfi,
backend = c("auto",
"snfi", "external"),
summ.vr = "Estadillo",
cut.dt = "d == d",
report = FALSE, mc.cores = getOption("mc.cores",
1L), design = NULL,
schema = NULL, method_registry = NULL,
parameter_table = NULL,
...)
nfi |
|
backend |
|
summ.vr |
|
cut.dt |
|
report |
|
mc.cores |
|
design |
Optional sampling |
schema |
Optional external |
method_registry |
Optional method registry passed to the
selected |
parameter_table |
Optional table of parameters required
by the external |
... |
Additional named arguments forwarded to the selected
|
The dispatcher keeps computation inside the backend
functions. It only validates the backend choice,
forwards arguments, stores the reconstructed call in
attr(x, "call"), and records the chosen backend in
attr(x, "backend"). That makes the wrapper easier
to maintain while preserving a single public entry point.
A backend result augmented with class
"inventoryMetrics", a stored call in
attr(x, "call"), and the selected backend in
attr(x, "backend"). The returned object otherwise
preserves the class and attributes produced by the backend.
Tree-level outputs use n for the per-record expansion
factor; grouped outputs use n_tot for total stand density.
Wilson Lara [aut, cre] (ORCID: <https://orcid.org/0000-0003-3527-1380>), Cristobal Ordonez [aut] (ORCID: <https://orcid.org/0000-0001-5354-3760>), Aitor Vázquez-Veloso [aut] (ORCID: <https://orcid.org/0000-0003-0227-506X>), Felipe Bravo [aut] (ORCID: <https://orcid.org/0000-0001-7348-6695>)
dendroMetrics, nfiMetrics, metrics2Vol, update.inventoryMetrics NULL is meaningful here: it requests tree-level output. Add it after compacting optional arguments so it is not discarded. NULL is meaningful here: it requests tree-level output.
## External workflows require an external backend function and the
## corresponding schema, design, and parameter objects.
ext <- data.frame(
plot = c('P1', 'P1', 'P2'),
species = c('sp1', 'sp1', 'sp2'),
diameter_mm = c(120, 185, 260),
height_m = c(7.1, 9.4, 13.2),
stringsAsFactors = FALSE
)
sch <- new_external_schema(
colmap = list(
plot = 'plot',
species = 'species',
d = 'diameter_mm',
h = 'height_m'
),
units = list(d = 'mm', h = 'm'),
levels = 'plot',
keep_cols = c('plot', 'species')
)
dsg <- new_inventory_design(
sample_area_m2 = 1000,
min_dbh_cm = 7.5,
name = 'Square 0.1-ha plot',
metadata = list(shape = 'square', side_m = sqrt(1000))
)
pars <- data.frame(
species = c('sp1', 'sp2'),
a = c(0.00002, 0.00003),
b = c(2.30, 2.10),
stringsAsFactors = FALSE
)
reg <- external_volume_method_registry(list(
V = new_volume_method(
output = 'v',
fun = function(dbh_mm, h_m, pars) {
dbh_cm <- dbh_mm / 10
pars$a + pars$b * (dbh_cm^2) * h_m
},
raw_unit = 'cm3',
unit = 'm3',
scale_to_m3 = 1 / 1e6,
build_args = function(ctx, pars, resolved) {
list(dbh_mm = ctx$d_mm, h_m = ctx$h_m, pars = pars)
},
fallback = function(ctx, pars, resolved) NA_real_,
match_by = 'species',
required_inputs = c('d', 'h')
)
))
out <- inventoryMetrics(
ext,
backend = 'external',
schema = sch,
design = dsg,
parameter_table = pars,
method_registry = reg,
summ.vr = 'plot',
var = c('d', 'h', 'ba', 'n', 'v'),
parametro = 'V'
)
out
attr(out, 'backend')
attr(out, 'units')
## Downloadable Toledo workflow. It requires internet access and an
## Access backend (mdbtools on Unix-like systems, ODBC on Windows),
## so it is not run during package checks.
## Not run:
cache <- file.path(tempdir(), 'basifoR-cache')
dir.create(cache, showWarnings = FALSE)
toledo <- inventoryMetrics(
'toledo',
nfi.nr = 4,
dir = cache,
summ.vr = 'Estadillo'
)
head(toledo)
attr(toledo, 'units')
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.