| externalMetrics2Vol | R Documentation |
Compute one or more tree-level volume outputs from external inventory data or from a precomputed external metrics table.
externalMetrics2Vol(x,
parametro = c("V"),
parameter_table = NULL,
method_registry = external_volume_method_registry(),
colmap = NULL, selector = c("first",
"priority")[1],
track_provenance = FALSE,
compute_metrics_if_needed = TRUE,
design = NULL, var = NULL,
metric_var = NULL,
levels = NULL, metric_levels = NULL,
keep_cols = NULL,
metric_keep_cols = NULL,
metric_colmap = list(d = c("d",
"dbh", "diameter",
"diameter_mm"),
h = c("h", "height",
"height_m")),
d_unit = NULL, metric_d_unit = c("mm",
"cm")[1], h_unit = NULL,
metric_h_unit = c("m",
"dm", "cm")[1],
volume_colmap = list(d = c("d"),
h = c("h"), dnm = c("dnm",
"d_nm", "D.n.m."),
v = c("v"), species = c("species",
"spec", "especie"),
region = c("region",
"pr"), equation_set = c("equation_set",
"eqset",
"tariff",
"model_set")),
...)
x |
Input data.frame or object inheriting from |
parametro |
Requested volume outputs or method names. |
parameter_table |
Optional data.frame of coefficients or parameter rows used by the
selected methods. Rows may be filtered by columns such as
|
method_registry |
Named list of method definitions, usually created with
|
colmap |
Optional alias list used to resolve contextual inputs for the volume
methods. If |
selector |
Rule used when several parameter rows remain after filtering. |
track_provenance |
If |
compute_metrics_if_needed |
If |
design |
Inventory |
var |
Legacy alias for |
metric_var |
Metric variables requested during automatic derivation. |
levels |
Legacy alias for |
metric_levels |
Grouping or identifier columns kept during metric derivation. |
keep_cols |
Legacy alias for |
metric_keep_cols |
Extra columns kept during metric derivation. |
metric_colmap |
Alias list for raw diameter and height columns used by |
d_unit |
Legacy alias for |
metric_d_unit |
Unit of raw diameter columns used during metric derivation. |
h_unit |
Legacy alias for |
metric_h_unit |
Unit of raw height columns used during metric derivation. |
volume_colmap |
Default alias list used to resolve standardized inputs and contextual columns such as species, region, and equation set. |
... |
Additional arguments passed only to |
Required inputs are inferred from the selected methods in method_registry. When one or more standardized inputs are missing and compute_metrics_if_needed = TRUE, the function calls externalMetrics() to derive them, using design, metric_colmap, units, grouping columns, and retained columns from the corresponding arguments.
Each requested output is evaluated with its method definition. A method can resolve its own parameter rows with get_pars, use embedded parameters in pars, or fall back to parameter_table. Raw outputs are converted to cubic metres with scale_to_m3.
When track_provenance = TRUE, the result stores per-output provenance columns together with a volume_meta attribute describing input units, returned units, required inputs, and method settings.
A data.frame containing the original columns in x plus the requested volume outputs.
The returned object inherits from classes "externalMetrics2Vol" and "metrics2vol". Named unit metadata are stored in attr(out, "units"), and the result may also preserve design_meta and volume_meta.
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>)
x <- data.frame(
species = c("sp1", "sp2"),
d = c(120, 260),
h = c(7.1, 13.2)
)
attr(x, "units") <- c(d = "mm", h = "m")
pars <- data.frame(
parameter = "V",
species = c("sp1", "sp2"),
a = c(0.00002, 0.00003),
b = c(2.30, 2.10),
model = c("demo_sp1", "demo_sp2")
)
ext_methods <- 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 <- externalMetrics2Vol(
x,
parametro = "V",
parameter_table = pars,
method_registry = ext_methods,
track_provenance = TRUE
)
out[, c("species", "v", "v_source", "v_status")]
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.