diff --git a/R/functions.R b/R/functions.R
index a58b0524..310db899 100644
--- a/R/functions.R
+++ b/R/functions.R
@@ -833,6 +833,77 @@ get_food_intake <- function(GCAM_version = "v7.0") {
}
+#' get_forestry
+#'
+#' Computes Forestry production and demand
+#'
+#' @param GCAM_version Main GCAM compatible version: 'v7.0' (default), 'v7.1', or 'v6.0'.
+#' @return `forestry_demand` and `forestry_production` global variables.
+#' @keywords internal forestry
+#' @importFrom magrittr %>%
+#' @export
+get_forestry <- function(GCAM_version = "v7.0") {
+ value <- forestry_demand <- forestry_production <- NULL
+
+ # demand = domestic + imports
+ forestry_demand <-
+ rgcam::getQuery(prj, "inputs by tech") %>%
+ dplyr::filter(grepl('regional industrial_roundwood', sector)) %>%
+ dplyr::group_by(scenario, region, year) %>%
+ # billion m3 to million m3
+ dplyr::summarise(value = sum(value) /
+ get(paste('convert',GCAM_version,sep='_'), envir = asNamespace("gcamreport"))[['conv_million_billion']]) %>%
+ dplyr::ungroup() %>%
+ dplyr::mutate(var = 'Forestry Demand|Roundwood') %>%
+ dplyr::select(dplyr::all_of(gcamreport::long_columns))
+
+ forestry_demand <- rbind(
+ forestry_demand,
+ forestry_demand %>%
+ dplyr::mutate(var = 'Forestry Demand|Roundwood|Industrial Roundwood')
+ )
+
+ # production = domestic + exports
+ forestry_exports <-
+ rgcam::getQuery(prj, "inputs by tech") %>%
+ dplyr::filter(stringr::str_detect(technology, stringr::regex("traded industrial_roundwood", ignore_case = TRUE))) %>%
+ dplyr::select(-sector,-technology,-input) %>%
+ dplyr::mutate(
+ region = stringr::str_split_fixed(subsector, " traded industrial_roundwood", 2)[, 1],
+ subsector = 'traded industrial_roundwood'
+ )
+
+ forestry_domestic <-
+ rgcam::getQuery(prj, "inputs by tech") %>%
+ dplyr::filter(grepl('domestic industrial_roundwood', subsector)) %>%
+ dplyr::select(-sector,-technology,-input)
+
+
+ forestry_production <- rbind(
+ forestry_domestic,
+ forestry_exports
+ ) %>%
+ dplyr::group_by(scenario, region, year) %>%
+ # billion m3 to million m3
+ dplyr::summarise(value = sum(value) /
+ get(paste('convert',GCAM_version,sep='_'), envir = asNamespace("gcamreport"))[['conv_million_billion']]) %>%
+ dplyr::ungroup() %>%
+ dplyr::mutate(var = 'Forestry Production|Roundwood') %>%
+ dplyr::select(dplyr::all_of(gcamreport::long_columns))
+
+ forestry_production <- rbind(
+ forestry_production,
+ forestry_production %>%
+ dplyr::mutate(var = 'Forestry Demand|Roundwood|Industrial Roundwood')
+ )
+
+
+ forestry_demand <<- forestry_demand
+ forestry_production <<- forestry_production
+
+}
+
+
#' get_ag_trade
#'
#' Computes Agricultural trade
diff --git a/data/queries_general_v7.1.rda b/data/queries_general_v7.1.rda
index 95799d41..4e800471 100644
Binary files a/data/queries_general_v7.1.rda and b/data/queries_general_v7.1.rda differ
diff --git a/data/var_fun_map_v7.1.rda b/data/var_fun_map_v7.1.rda
index 3f102be9..282687a0 100644
Binary files a/data/var_fun_map_v7.1.rda and b/data/var_fun_map_v7.1.rda differ
diff --git a/inst/extdata/mappings/GCAM7.1/variables_functions_mapping.csv b/inst/extdata/mappings/GCAM7.1/variables_functions_mapping.csv
index 178375e8..bca11fa8 100644
--- a/inst/extdata/mappings/GCAM7.1/variables_functions_mapping.csv
+++ b/inst/extdata/mappings/GCAM7.1/variables_functions_mapping.csv
@@ -82,3 +82,5 @@ fert_consumption_clean;get_fert_consumption;;;fertilizer consumption by region
fert_price_clean;get_fert_price;;;ammonia and N fertilizer prices
food_availability_clean;get_food_availability;food_intake_clean;;
food_intake_clean;get_food_intake;population_clean;;food consumption by type (specific)
+forestry_demand;get_forestry;;;inputs by tech
+forestry_production;get_forestry;;;inputs by tech
\ No newline at end of file
diff --git a/inst/extdata/queries/GCAM7.1/queries_gcamreport_general.xml b/inst/extdata/queries/GCAM7.1/queries_gcamreport_general.xml
index 01ebb2f8..dd8e8bbf 100644
--- a/inst/extdata/queries/GCAM7.1/queries_gcamreport_general.xml
+++ b/inst/extdata/queries/GCAM7.1/queries_gcamreport_general.xml
@@ -1189,6 +1189,15 @@ A user can adjust the query to search for any of:
+
+
+
+ input
+ demand-physical[@vintage]
+ *[@type='sector']/*[@type='subsector']/*[@type='technology']/*[@type='input']/demand-physical/node()
+
+
+