Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reg al #100

Closed
wants to merge 71 commits into from
Closed
Show file tree
Hide file tree
Changes from 70 commits
Commits
Show all changes
71 commits
Select commit Hold shift + click to select a range
eaa8dc8
regeneration: toevoeging van mean_nr_of_trees_ha
leymanan Jun 9, 2021
81bf81a
calc_reg_corte_area_XX:
leymanan Jun 9, 2021
32934b7
load_data_regeneration: naam subplot ook inladen
leymanan Jun 9, 2021
650340f
load_veg en load_herblayer: subplot-naam toegevoegd
leymanan Jun 10, 2021
f38d0d0
calc_veg_CA_species: correctie percentage plots met vegetatie (n_subp…
leymanan Jun 10, 2021
3ea45ae
calc_veg_plot:
leymanan Jun 10, 2021
1cbfbc8
calc_reg en calc_veg functies: subplot bij documentatie toegevoegd
leymanan Jun 10, 2021
02765da
calc_veg_ca_species: aanpassing browseindex (gewijzigde LU-list)
leymanan Jun 10, 2021
f579319
calc_veg_core_area_species: data_vegetation toegevogd bij argument
leymanan Jun 10, 2021
75d9833
load_plotinfo uitgebreid (+ manual)
leymanan Jun 10, 2021
eb9680b
load_plotinfo uitgebreid (+ manual)
leymanan Jun 10, 2021
83616a9
calc_veg_core_area: foutje (data_veg_CA vergeten)
leymanan Jun 10, 2021
2cfb7ef
problem
leymanan Jun 10, 2021
08469b5
problem
leymanan Jun 10, 2021
3617bb8
load_plotinfo: '-' vergeten
leymanan Jun 11, 2021
7184e01
read_forresdat:
leymanan Jun 11, 2021
520d2e4
read_forresdat
leymanan Jun 11, 2021
d5aed27
load_forresdat: aanpassing documentatie nalv uitbreiding plotinfo
leymanan Jun 11, 2021
c03a744
calc_veg_plot: variabele "cumm_herb_coverage_class_average_perc" teru…
leymanan Jun 11, 2021
93c7824
load-data_dendro: oldid toegevoegd
leymanan Jun 11, 2021
1d8ad15
create_unique_tree_id: periode 1 géén old_id's anders werkt code niet…
leymanan Jun 11, 2021
4e9e2d3
load_data_shoots: mogelijkheid om extra variables toe te voegen
leymanan Jul 15, 2021
bee94a6
load_data_dendrometry: "Trees." vergeten
leymanan Jul 15, 2021
78f05c6
load_data_shoots: extra "_shoots" toegeveogd bij iufro klasses: makke…
leymanan Jul 15, 2021
caf8d29
load_data_reg/veg/herbl: subplot_name verwijderd
leymanan Jul 16, 2021
2df7c3d
Update R/calculate_regeneration_core_area_height_species.R
leymanan Jul 20, 2021
9a99dd0
calc_reg_core_area: aanpassingen cfr Els (mutate ipv left_join)
leymanan Jul 20, 2021
2725cc7
calc_veg_core_area: cfr regeneration ook left_join vervangen door mutate
leymanan Jul 20, 2021
c1dce72
Update R/create_unique_tree_id.R
leymanan Jul 22, 2021
b4dbd4e
Update R/calculate_regeneration_plot_height.R
leymanan Jul 22, 2021
8d5ee21
Update R/calculate_regeneration_plot_height_species.R
leymanan Jul 22, 2021
70adc6e
Update R/calculate_vegetation_plot.R
leymanan Jul 22, 2021
04e1684
Update R/calculate_regeneration_plot.R
leymanan Jul 22, 2021
1efc593
fixes issue #90
ElsLommelen Aug 17, 2021
ab720a6
update documentation
ElsLommelen Aug 17, 2021
6fe8868
Merge pull request #93 from inbo/issue90
leymanan Mar 2, 2022
9c28d4d
Merge branch 'master' of https://github.com/inbo/forrescalc into reg_AL
leymanan Mar 2, 2022
abe2e4e
Merge branch 'statistics-and-other-issues' into reg_AL
leymanan Mar 25, 2022
3fb6815
na vgl van branch reg_Al en branch statistics nog 4 files aangepast:
leymanan Mar 25, 2022
a25d5d7
compose_stem_data: ook info mbt "remark" meenemen van layer shoots
leymanan Mar 28, 2022
d0be3a8
add height models to script Main.R
ElsLommelen Mar 29, 2022
2f8b2fc
Merge pull request #101 from inbo/update-Main-script
leymanan Mar 30, 2022
86340ce
Update R/read_forresdat.R
leymanan Apr 7, 2022
618bce4
Update R/read_forresdat.R
leymanan Apr 7, 2022
c144e8f
load & calc_veg_plot:
leymanan Apr 7, 2022
9e47057
compose_stem_data:
leymanan Apr 7, 2022
c430e85
Main.R: verwijderen code voor niet opgemeten deadwood.
leymanan Apr 7, 2022
afd79e7
aanpassingen nalv lint_package, vooral inkorten van lijnen
leymanan Apr 7, 2022
923ae6a
load_data_veg: dubbele aanmaak mid_cover
leymanan Apr 7, 2022
7ec13e6
load_data_veg, load_data_herblayer, calc_veg_plot:
leymanan Apr 7, 2022
b3767ac
load_data_veg: typo
leymanan Apr 7, 2022
04e28fd
calc_veg_plot: "date_vegetation" toegevoegd
leymanan Apr 7, 2022
92b2190
load_data_herblayer: typo
leymanan Apr 7, 2022
4afcf78
DAS_indicator.Rmd: verwijderen van blanco's op einde regels (cfr lint)
leymanan Apr 7, 2022
e9c6067
load_data_reg: "year_main_survey" verwijderd om verwarring te voorkomen.
leymanan Apr 7, 2022
7806699
load_data_veg: year_main_survey bij voorkeur obv data_vegetation, enk…
leymanan Apr 7, 2022
acbf7c9
load_plotinfo: date_dendro_1986 toegevoegd
leymanan Apr 7, 2022
0200341
calc_var_stem_level: height trees minimaal 1.3m
leymanan Apr 8, 2022
18f1758
removal of variable "nr_of_regeneration_ha" (or "nr_established_ha" a…
leymanan Jul 13, 2022
c3759ee
calc_reg_plot: error: "mean" instead of "sum" used
leymanan Jul 13, 2022
20901af
calc_regeneration_functions: extra info about confidence interval
leymanan Jul 13, 2022
0dba594
5 calc_reg_functions: info on "return" adjusted for the removal of nr…
leymanan Jul 13, 2022
7d3f221
sum_intervals: uci was NaN ipv 0 daar waar mean en lci wél 0 waren.
leymanan Jul 15, 2022
af84947
calculate_regeneration_plot &
leymanan Jul 15, 2022
a4ee087
calc_reg_plot_corearea_species: klein foutje (mean ipv sum)
leymanan Jul 15, 2022
3dbef1a
Update R/calc_variables_stem_level.R
leymanan Nov 29, 2022
a7c6e73
Update R/compose_stem_data.R
leymanan Nov 29, 2022
de4b312
Update R/compose_stem_data.R
leymanan Nov 29, 2022
22c606a
compose_stem_data: uitleg ivm parameter "extra variables" aangepast c…
leymanan Nov 29, 2022
2cdc15a
Merge branch 'reg_AL' of github.com:inbo/forrescalc into reg_AL
leymanan Nov 29, 2022
4fab058
remove mid_cover from load_data_vegetation()
ElsLommelen Nov 30, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 7 additions & 3 deletions R/access_to_sqlite.R
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
#' moves data from fieldmap database to SQLite database
#'
#' This function moves all relevant tables from an unindexed Access database to a SQLite database with indexes, for performance reasons. (Not finished yet and not exported!)
#' This function moves all relevant tables from an unindexed Access database to
#' a SQLite database with indexes, for performance reasons.
#' (Not finished yet and not exported!)
#'
#' @param source_db name of fieldmap/access database (with specific fieldmap structure) including path
#' @param source_db name of fieldmap/access database (with specific
#' fieldmap structure), including path
#' @param new_db name and path of SQLite database to be made
#'
#' @return A SQLite database with the specified name is saved at the specified path
#' @return A SQLite database with the specified name is saved at the
#' specified path
#'
#' @importFrom RODBC odbcClose odbcConnectAccess2007 sqlQuery
#'
Expand Down
43 changes: 32 additions & 11 deletions R/add_zeros.R
Original file line number Diff line number Diff line change
@@ -1,23 +1,43 @@
#' Add records with value zero for missing variable combinations in a given dataset
#' Add records with value zero for missing variable combinations in a
#' given dataset
#'
#' @description
#' Datasets for which this package has been developed, typically contain measurements of observations.
#' Absence is often not reported explicitly (e.g. there exists no record of a species that is not observed in a plot), while it can be important to include these zero values in an analysis (e.g. mean coverage per species in a certain forest reserve; mean stem number per diameter class in a forest reserve).
#' This function automatically adds missing combinations with value zero to the dataset for each combination of values of the variables given in `comb_vars` (within each value of `grouping_vars`).
#' All variables that are not mentioned in `comb_vars` or `grouping_vars`, are considered to be numerical variables and will get value 0 (zero).
#' Note that if a certain value is not present in the dataset (or in one of the subsets defined by `grouping_vars`), it will not be added automatically; at least one record should be added manually for this value (e.g. a plot or diameterclass that doesn't exist in the given dataset, but has to be included in the output).
#' Datasets for which this package has been developed, typically contain
#' measurements of observations.
#' Absence is often not reported explicitly (e.g. there exists no record of
#' a species that is not observed in a plot),
#' while it can be important to include these zero values in an analysis
#' (e.g. mean coverage per species in a certain forest reserve; mean stem number
#' per diameter class in a forest reserve).
#' This function automatically adds missing combinations with value zero to
#' the dataset #' for each combination of values of the variables given
#' in `comb_vars` (within each value of `grouping_vars`).
#' All variables that are not mentioned in `comb_vars` or `grouping_vars`,
#' are considered to be numerical variables and will get value 0 (zero).
#' Note that if a certain value is not present in the dataset
#' (or in one of the subsets defined by `grouping_vars`), it will not be
#' added automatically;
#' at least one record should be added manually for this value
#' (e.g. a plot or diameterclass that doesn't exist in the given dataset,
#' but has to be included in the output).
#'
#'
#' @param dataset data.frame in which records should be added
#' @param comb_vars variables (given as a vector of strings) of which all combinations of their values should have a record in the dataset.
#' @param grouping_vars one or more variables for which the combination of values of the variables given in `comb_vars` should be made for each value, e.g. if grouping_vars = "forest_reserve" and comb_vars = c("plot", "species"), all combinations of the values in "plot" and "species" are made within each value of "forest_reserve".
#' @param comb_vars variables (given as a vector of strings) of which all
#' combinations of their values should have a record in the dataset.
#' @param grouping_vars one or more variables for which the combination of
#' values of the variables given in `comb_vars` should be made for each value,
#' e.g. if grouping_vars = "forest_reserve" and comb_vars = c("plot", "species"),
#' all combinations of the values in "plot" and "species" are made
#' within each value of "forest_reserve".
#' @param add_zero_no_na variable indicating which records of the grouping_vars
#' should get a zero value (variable should be TRUE) or a NA value (variable
#' should be FALSE).
#' E.g. a variable indicating whether or not observations are done.
#' If no variable name is given (default NA), all added records get zero values.
#'
#' @return dataframe based on `dataset` to which records are added with value 0 (zero) for each measurement.
#' @return dataframe based on `dataset` to which records are added with
#' value 0 (zero) for each measurement.
#'
#' @examples
#' \dontrun{
Expand All @@ -38,7 +58,8 @@
#'
#' @importFrom plyr .
#' @importFrom assertthat assert_that has_name
#' @importFrom dplyr %>% distinct inner_join mutate mutate_at right_join select vars
#' @importFrom dplyr %>% distinct inner_join mutate mutate_at right_join select
#' vars
#' @importFrom tidyselect all_of matches
#' @importFrom rlang .data ensyms
#'
Expand All @@ -53,7 +74,7 @@ add_zeros <-
)
assert_that(
all(has_name(dataset, grouping_vars)),
msg = "dataset should contain all variables from grouping_vars as column names"
msg = "dataset should contain all variables from grouping_vars as column names" # nolint
)
if (!is.na(add_zero_no_na)) {
assert_that(
Expand Down
54 changes: 36 additions & 18 deletions R/calc_variables_stem_level.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,13 @@
#'
#' This function calculates additional variables based on measurements, such as
#' \itemize{
#' \item calc_height_m: calculated height based on `dbh_mm` and a species specific diameter-height model
#' \item calc_height_m: calculated height based on `dbh_mm` and a species
#' specific diameter-height model
#' \item basal_area_m2
#' \item vol_bole_m3: calculated based on `dbh_mm`, `calc_height_m` and species specific tariffs
#' \item vol_crown_m3: calculated based on `dbh_mm` and species specific tariffs
#' \item vol_bole_m3: calculated based on `dbh_mm`, `calc_height_m` and
#' species specific tariffs
#' \item vol_crown_m3: calculated based on `dbh_mm` and
#' species specific tariffs
#' \item vol_tot_m3: sum of `vol_bole_m3` and `vol_crowwn_m3`
#' \item basal_area_alive_m2_ha
#' \item basal_area_dead_m2_ha
Expand All @@ -16,7 +19,8 @@
#' }
#'
#' @inheritParams calculate_dendrometry
#' @param data_stems dataframe on stems (shoots and trees) as given from the function compose_stem_data()
#' @param data_stems dataframe on stems (shoots and trees) as given from the
#' function compose_stem_data()
#'
#' @return Dataframe with ...
#'
Expand All @@ -37,7 +41,8 @@
#'
#' @importFrom readr read_csv2
#' @importFrom rlang .data
#' @importFrom dplyr %>% bind_rows filter group_by left_join mutate n select summarise ungroup
#' @importFrom dplyr %>% bind_rows filter group_by left_join mutate n select
#' summarise ungroup
#'
calc_variables_stem_level <-
function(data_stems, height_model) {
Expand Down Expand Up @@ -70,9 +75,12 @@ calc_variables_stem_level <-
1.3 + .data$P1 + .data$P2 * log(.data$dbh_mm / 10)
),
dh_model = ifelse(!is.na(.data$P1), TRUE, FALSE),
# if no height_model is available, calc_height_fm on tree level (< FM-IA) is used
# if no height_model is available, calc_height_fm on tree level (< FM-IA)
# is used
calc_height_m =
ifelse(is.na(.data$calc_height_r), .data$calc_height_fm, .data$calc_height_r)
ifelse(is.na(.data$calc_height_r)
, pmax(1.3, .data$calc_height_fm)
, pmax(1.3, .data$calc_height_r))
) %>%
select(
-.data$model, -.data$P1, -.data$P2
Expand All @@ -85,7 +93,8 @@ calc_variables_stem_level <-
system.file("extdata/tariffs1entry.csv", package = "forrescalc")
)
) %>%
select(-.data$name_nl, -.data$tariff_id, -.data$tariff_group, -.data$source),
select(-.data$name_nl, -.data$tariff_id, -.data$tariff_group,
-.data$source),
by = "species"
) %>%
mutate(
Expand All @@ -105,7 +114,8 @@ calc_variables_stem_level <-
system.file("extdata/tariffs1entry_crown.csv", package = "forrescalc")
)
) %>%
select(-.data$name_nl, -.data$tariff_id, -.data$tariff_group, -.data$source),
select(-.data$name_nl, -.data$tariff_id, -.data$tariff_group,
-.data$source),
by = "species"
) %>%
mutate(
Expand All @@ -125,7 +135,8 @@ calc_variables_stem_level <-
system.file("extdata/tariffs2entries.csv", package = "forrescalc")
)
) %>%
select(-.data$name_nl, -.data$tariff_id, -.data$tariff_group, -.data$source),
select(-.data$name_nl, -.data$tariff_id, -.data$tariff_group,
-.data$source),
by = "species"
) %>%
mutate(
Expand All @@ -134,18 +145,23 @@ calc_variables_stem_level <-
ifelse(
.data$formula == 1,
yes =
.data$a + .data$b * .data$perimeter + .data$c * .data$perimeter ^ 2 +
.data$d * .data$perimeter ^ 3 + .data$e * .data$calc_height_m +
.data$a + .data$b * .data$perimeter +
.data$c * .data$perimeter ^ 2 +
.data$d * .data$perimeter ^ 3 +
.data$e * .data$calc_height_m +
.data$f * .data$calc_height_m * .data$perimeter +
.data$g * .data$calc_height_m * .data$perimeter ^ 2,
no =
1 / 1000 *
#spil
(exp(1.10597 * log(.data$calc_height_m) + 1.78865 * log(.data$d_cm) - 3.07192) -
(exp(1.10597 * log(.data$calc_height_m) +
1.78865 * log(.data$d_cm) - 3.07192) -
#Verlies
exp(-4.608923 * log(.data$d_cm) + 3.005989 * log(.data$calc_height_m) -
exp(-4.608923 * log(.data$d_cm) +
3.005989 * log(.data$calc_height_m) -
1.3209 * log(.data$calc_height_m) * log(.data$calc_height_m) +
1.605266 * log(.data$d_cm) * log(.data$calc_height_m) + 5.410272))
1.605266 * log(.data$d_cm) * log(.data$calc_height_m) +
5.410272))
)
, vol_bole_t2_m3 = pmax(0, .data$vol_bole_t2_m3)
, vol_bole_m3 =
Expand All @@ -171,7 +187,7 @@ calc_variables_stem_level <-
# 1/3 x π x h x ( R² + R x r + r² ) - truncated cone
# AS CILINDER - GIVES BETTER RESULTS
pi * .data$height_m * .data$dbh_mm^2 / 2000^2,
# ! TEMPORARY SOLUTION: goal is to incormporate taper functuions cfr FM-IA
# ! TEMPORARY SOLUTION: goal is to incorporate taper functions cfr FM-IA
NA),
# !!! ? als calc_height er niet is, dan ev. wel nog als cilinder???
# nee, want dan ook geen volumes van de andere bomen ...)
Expand All @@ -182,10 +198,12 @@ calc_variables_stem_level <-
mutate(
# volume correction for broken crown or branches
reduction_crown =
ifelse(is.na(.data$crown_volume_reduction), 0, .data$crown_volume_reduction),
ifelse(is.na(.data$crown_volume_reduction), 0,
.data$crown_volume_reduction),
vol_crown_m3 = .data$vol_crown_m3 * (1 - .data$reduction_crown),
reduction_branch =
ifelse(is.na(.data$branch_length_reduction), 0, .data$branch_length_reduction),
ifelse(is.na(.data$branch_length_reduction), 0,
.data$branch_length_reduction),
vol_crown_m3 = .data$vol_crown_m3 * (1 - .data$reduction_branch),
# total volume
vol_tot_m3 = .data$vol_bole_m3 + .data$vol_crown_m3
Expand Down
23 changes: 16 additions & 7 deletions R/calc_variables_tree_level.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,17 @@
#'
#' This function calculates additional variables based on measurements, such as
#' \itemize{
#' \item nr_of_stems: the number of shoots in the tree (= 1 for an individual tree; >= 1 when coppice)
#' \item individual: true for individual tree or coppice, false if record is a secondary shoot
#' \item calc_height_m: calculated height based on `dbh_mm` and a species specific diameter-height model
#' \item nr_of_stems: the number of shoots in the tree
#' (= 1 for an individual tree; >= 1 when coppice)
#' \item individual: true for individual tree or coppice,
#' false if record is a secondary shoot
#' \item calc_height_m: calculated height based on `dbh_mm` and
#' a species specific diameter-height model
#' \item basal_area_m2
#' \item vol_bole_m3: calculated based on `dbh_mm`, `calc_height_m` and species specific tariffs
#' \item vol_crown_m3: calculated based on `dbh_mm` and species specific tariffs
#' \item vol_bole_m3: calculated based on `dbh_mm`, `calc_height_m` and
#' species specific tariffs
#' \item vol_crown_m3: calculated based on `dbh_mm` and
#' species specific tariffs
#' \item vol_tot_m3: sum of `vol_bole_m3` and `vol_crowwn_m3`
#' \item dbh_mm (based on average for coppice trees)
#' \item decaystage (based on average for coppice trees)
Expand All @@ -20,7 +25,10 @@
#' }
#'
#' @inheritParams calculate_dendrometry
#' @param data_stems_calc dataframe on stem level measurements with variables plot_id, plottype, tree_measure_id, date_dendro, dbh_mm, height_m, species, alive_dead, decaystage, period, year, subcircle, plotarea_ha,... (output of function calc_variables_stem_level())
#' @param data_stems_calc dataframe on stem level measurements with variables
#' plot_id, plottype, tree_measure_id, date_dendro, dbh_mm, height_m, species,
#' alive_dead, decaystage, period, year, subcircle, plotarea_ha,...
#' (output of function calc_variables_stem_level())
#'
#' @return Dataframe with ...
#'
Expand All @@ -42,7 +50,8 @@
#'
#' @importFrom readr read_csv2
#' @importFrom rlang .data
#' @importFrom dplyr %>% bind_rows filter group_by left_join mutate n select summarise ungroup
#' @importFrom dplyr %>% bind_rows filter group_by left_join mutate n select
#' summarise ungroup
#'
calc_variables_tree_level <-
function(data_dendro, data_stems_calc) {
Expand Down
30 changes: 20 additions & 10 deletions R/calculate_DAS_indicator.R
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
#' @title calculate DAS indicator
#'
#' @description
#' This function does all preparing steps (selection of relevant plots and reserves) and calculations to obtain the DAS-indicator.
#' This function does all preparing steps (selection of relevant plots and
#' reserves) and calculations to obtain the DAS-indicator.
#'
#' First the relevant forest reserves are selected based on the following criteria:
#' First the relevant forest reserves are selected based on the following
#' criteria:
#'
#' @template selection_criteria_for_DAS
#'
#' @template calculate_das_indicator_explanation_part2
#'
#' @inheritParams calculate_dendro_plot
#' @param na.rm Ignore records with no value? Default is FALSE, so no records will be ignored unless it is explicitly mentioned by 'na.rm = TRUE'
#' @param na.rm Ignore records with no value? Default is FALSE, so no records
#' will be ignored unless it is explicitly mentioned by 'na.rm = TRUE'
#'
#' @return dataframe with results for DAS indicator on forest level (?)
#'
Expand All @@ -32,7 +35,8 @@
#' @export
#'
#' @importFrom assertthat assert_that
#' @importFrom dplyr %>% distinct filter group_by inner_join left_join mutate n select summarise ungroup
#' @importFrom dplyr %>% distinct filter group_by inner_join left_join mutate n
#' select summarise ungroup
#' @importFrom readr read_delim
#' @importFrom rlang .data
#' @importFrom tidyr pivot_wider
Expand Down Expand Up @@ -61,9 +65,12 @@ calculate_DAS_indicator <- function(data_dendro_calc, na.rm = FALSE) {

#select relevant plots
DAS_reserve <- data_dendro_calc %>%
select_for_DAS_indicator(grouping_vars = c("forest_reserve", "year", "period")) %>%
inner_join(data_dendro_calc, by = c("forest_reserve", "year", "period")) %>%
select_for_DAS_indicator(grouping_vars = c("plot_id", "year", "period")) %>%
select_for_DAS_indicator(grouping_vars = c("forest_reserve", "year",
"period")) %>%
inner_join(data_dendro_calc, by = c("forest_reserve", "year"
, "period")) %>%
select_for_DAS_indicator(grouping_vars = c("plot_id", "year"
, "period")) %>%
inner_join(
data_dendro_calc %>%
select(.data$plot_id, .data$forest_reserve) %>%
Expand All @@ -76,16 +83,19 @@ calculate_DAS_indicator <- function(data_dendro_calc, na.rm = FALSE) {
) %>%
ungroup() %>%
filter(.data$n_plots >= 12) %>%
#add data again to selected plots and calculate difference in basal area proportion
inner_join(data_dendro_calc, by = c("forest_reserve", "plot_id", "year", "period")) %>%
#add data again to selected plots and calculate difference in basal area
# proportion
inner_join(data_dendro_calc, by = c("forest_reserve", "plot_id", "year"
, "period")) %>%
left_join(
read_delim(
system.file("extdata/DAS_tree_groups.csv", package = "forrescalc"),
delim = ";", col_types = "cd"
),
by = "species"
) %>%
group_by(.data$forest_reserve, .data$period, .data$year, .data$group, .data$plot_id) %>%
group_by(.data$forest_reserve, .data$period, .data$year, .data$group,
.data$plot_id) %>%
summarise(
basal_area_m2_ha = sum(.data$basal_area_alive_m2_ha)
) %>%
Expand Down
11 changes: 8 additions & 3 deletions R/calculate_dendro_plot.R
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
#' aggregate parameters by plot and year
#'
#' This function calculates for each plot and year some values per hectare: number of tree species, number of trees, basal area and volume.
#' This function calculates for each plot and year some values per hectare:
#' number of tree species, number of trees, basal area and volume.
#'
#' @inheritParams calculate_dendrometry
#' @param data_dendro_calc dataframe on tree measures with variables plot_id, plottype, tree_measure_id, date_dendro, dbh_mm, height_m, species, alive_dead, decaystage, vol_tot_m3, basal_area_m2, period, OldID, year, subcircle, plotarea_ha,... (output of function calc_variables_tree_level())
#' @param data_dendro_calc dataframe on tree measures with variables plot_id,
#' plottype, tree_measure_id, date_dendro, dbh_mm, height_m, species,
#' alive_dead, decaystage, vol_tot_m3, basal_area_m2, period, OldID, year,
#' subcircle, plotarea_ha,... (output of function calc_variables_tree_level())
#'
#' @return dataframe with columns plot, year, number_of_tree_species, number_of_trees_ha, basal_area_m2_ha, volume_m3_ha
#' @return dataframe with columns plot, year, number_of_tree_species,
#' number_of_trees_ha, basal_area_m2_ha, volume_m3_ha
#'
#' @examples
#' \dontrun{
Expand Down
8 changes: 5 additions & 3 deletions R/calculate_dendro_plot_species.R
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
#' aggregate parameters by plot and tree species
#'
#' This function calculates for each plot, tree species and year some values per hectare: number of trees, basal area and volume.
#' This function calculates for each plot, tree species and year some values
#' per hectare: number of trees, basal area and volume.
#'
#' @inheritParams calculate_dendro_plot
#'
#' @return dataframe with columns plot, year, tree_species, number_of_trees_ha, basal_area_m2_ha, volume_m3_ha
#' @return dataframe with columns plot, year, tree_species, number_of_trees_ha,
#' basal_area_m2_ha, volume_m3_ha
#'
#' @examples
#' \dontrun{
Expand Down Expand Up @@ -39,7 +41,7 @@ calculate_dendro_plot_species <- function(data_dendro_calc, data_deadwood) {
sum((.data$alive_dead == 11) * .data$nr_of_stems / .data$plotarea_ha),
basal_area_alive_m2_ha = sum(.data$basal_area_alive_m2_ha),
basal_area_dead_m2_ha = sum(.data$basal_area_dead_m2_ha),
vol_alive_m3_ha = sum(.data$vol_alive_m3_ha ),
vol_alive_m3_ha = sum(.data$vol_alive_m3_ha),
vol_dead_standing_m3_ha = sum(.data$vol_dead_standing_m3_ha),
vol_bole_alive_m3_ha = sum(.data$vol_bole_alive_m3_ha),
vol_bole_dead_m3_ha = sum(.data$vol_bole_dead_m3_ha)
Expand Down