| compute_pu_scores_crossscale | R Documentation |
This function computes a feature-based importance score at each resolution present in a multiscale planning-unit set, and then propagates those resolution-specific scores through the H3 hierarchy so every planning unit receives a score "as seen from" each resolution.
Propagation rules:
Downward (parent \rightarrow children): undamped broadcast.
All descendants of a given parent at resolution r inherit the same
score_from_r value.
Upward (children \rightarrow parent): aggregation of descendant
scores at resolution r using mean (default) or max.
compute_pu_scores_crossscale(
s,
feature_mat,
maps,
cs_idx,
feature_weights = NULL,
winsor_p = NULL,
cost_col = NULL,
cost_beta = 1,
agg_mode = c("mean", "max"),
res_col = "res",
res_levels = NULL,
feature_cols_by_res = NULL,
prefix = "score_from_r"
)
s |
An |
feature_mat |
A numeric matrix/data.frame with one row per planning unit
and one column per feature. Feature columns are expected to be prefixed by
resolution (e.g., |
maps |
Output of |
cs_idx |
Output of |
feature_weights |
Optional named numeric vector of user weights for
features. Names must match |
winsor_p |
Optional winsorization level passed to the feature-only score
computation. See |
cost_col |
Optional name of a numeric cost column in |
cost_beta |
Numeric exponent applied to costs when |
agg_mode |
Character, aggregation used for upward propagation
(children |
res_col |
Name of the resolution column in |
res_levels |
Optional integer vector of resolutions to compute. Defaults
to |
feature_cols_by_res |
Optional named list mapping each resolution (as a
character) to a character vector of feature column names. If |
prefix |
Column name prefix for outputs. Defaults to |
The same sf object s with one new numeric column per
resolution, named paste0(prefix, res) (e.g., score_from_r5).
# Tiny 2-level setup: 2 parents (r7), and 2 children (r8) under the first parent
parent1 <- "872a1072bffffff"
parent2 <- "872a10729ffffff"
kids <- c("882a1072b1fffff", "882a1072b3fffff")
h3_vec <- c(parent1, parent2, kids)
res_vec <- c(7L, 7L, 8L, 8L)
s <- sf::st_as_sf(
data.frame(
h3_address = h3_vec,
res = res_vec,
cost = c(1, 1, 1, 1),
x = c(0, 1, 2, 3),
y = c(0, 0, 0, 0)
),
coords = c("x", "y"), crs = 4326
)
# Feature columns prefixed by resolution (r7_, r8_)
feature_mat <- data.frame(
r7_f1 = c(1.0, 0.2, 0.0, 0.0),
r8_f1 = c(0.0, 0.0, 0.6, 0.2)
)
maps <- build_h3_maps(s)
cs_idx <- build_crossscale_index(maps)
s2 <- compute_pu_scores_crossscale(
s, feature_mat,
maps = maps, cs_idx = cs_idx,
agg_mode = "mean",
res_col = "res"
)
s2[, c("res", "score_from_r7", "score_from_r8")]
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.