get_real_depths {LadderFuelsR} | R Documentation |
Effective fuel layers depth
Description
This function recalculates fuel layers depth after removing distances = 1 m
Usage
get_real_depths (effective_fbh, verbose=TRUE)
Arguments
effective_fbh |
tree metrics with the recalculated base height of fuel layers after considering distances > 1 m (output of [get_real_fbh()] function). An object of the class text. |
verbose |
Logical, indicating whether to display informational messages (default is TRUE). |
Details
# List of tree metrics:
treeID: tree ID with strings and numeric values
treeID1: tree ID with only numeric values
dist: Distance between consecutive fuel layers (m)
Hdist - Height of the distance between consecutive fuel layers (m)
Hcbh - Height of the base of each fuel layer (m)
dptf - Depth of fuel layers (m) after removing distances equal 1 m
Hdptf - Height of the depth of fuel layers (m) after removing distances equal 1 m
max_height - Maximum height of the tree profile
Value
A data frame giving the fuel layers depth after removing distances = 1 m.
Author(s)
Olga Viedma, Carlos Silva and JM Moreno
See Also
Examples
library(magrittr)
library(tidyr)
library(dplyr)
# Before running this example, make sure to run get_real_fbh().
if (interactive()) {
effective_fbh <- get_real_fbh()
LadderFuelsR::effective_fbh$treeID <- factor(LadderFuelsR::effective_fbh$treeID)
trees_name1 <- as.character(effective_fbh$treeID)
trees_name2 <- factor(unique(trees_name1))
depth_metrics_corr_list <- list()
for (i in levels(trees_name2)){
# Filter data for each tree
tree3 <- effective_fbh |> dplyr::filter(treeID == i)
# Get real depths for each tree
depth_metrics_corr <- get_real_depths(tree3, verbose=TRUE)
depth_metrics_corr_list[[i]] <- depth_metrics_corr
}
# Combine depth values for all trees
effective_depth <- dplyr::bind_rows(depth_metrics_corr_list)
# Reorder columns
original_column_names <- colnames(effective_depth)
# Specify prefixes
desired_order <- c("treeID", "Hcbh", "dptf", "dist", "Hdist", "Hdptf", "max_height")
# Identify unique prefixes
prefixes <- unique(sub("^([a-zA-Z]+).*", "\\1", original_column_names))
# Initialize vector to store new order
new_order <- c()
# Loop over desired order of prefixes
for (prefix in desired_order) {
# Find column names matching the current prefix
matching_columns <- grep(paste0("^", prefix), original_column_names, value = TRUE)
# Append to the new order
new_order <- c(new_order, matching_columns)
}
effective_depth <- effective_depth[, new_order]
}