Skip to content

Commit

Permalink
ComDef: forestry production and demand
Browse files Browse the repository at this point in the history
  • Loading branch information
klau506 committed Nov 13, 2024
1 parent 332f2ce commit d4a0185
Show file tree
Hide file tree
Showing 5 changed files with 82 additions and 0 deletions.
71 changes: 71 additions & 0 deletions R/functions.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Binary file modified data/queries_general_v7.1.rda
Binary file not shown.
Binary file modified data/var_fun_map_v7.1.rda
Binary file not shown.
2 changes: 2 additions & 0 deletions inst/extdata/mappings/GCAM7.1/variables_functions_mapping.csv
Original file line number Diff line number Diff line change
Expand Up @@ -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
9 changes: 9 additions & 0 deletions inst/extdata/queries/GCAM7.1/queries_gcamreport_general.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1189,6 +1189,15 @@ A user can adjust the query to search for any of:
<comments />
</supplyDemandQuery>
</aQuery>
<aQuery>
<all-regions />
<supplyDemandQuery title="inputs by tech">
<axis1 name="input">input</axis1>
<axis2 name="Year">demand-physical[@vintage]</axis2>
<xPath buildList="true" dataName="input" group="false" sumAll="false">*[@type='sector']/*[@type='subsector']/*[@type='technology']/*[@type='input']/demand-physical/node()</xPath>
<comments/>
</supplyDemandQuery>
</aQuery>
<aQuery>
<all-regions />
<supplyDemandQuery title="transport service output by mode">
Expand Down

0 comments on commit d4a0185

Please sign in to comment.