Skip to content

Commit

Permalink
ComDef: add pkgs
Browse files Browse the repository at this point in the history
  • Loading branch information
klau506 committed Jan 2, 2025
1 parent a51ee13 commit 81a1b50
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
16 changes: 8 additions & 8 deletions R/functions.R
Original file line number Diff line number Diff line change
Expand Up @@ -4336,7 +4336,7 @@ get_transport_sales <- function(GCAM_version = "v7.1") {
ucd_core_loads <- ucd_core_values %>%
dplyr::filter(variable == "annual travel per vehicle") %>%
dplyr::mutate(UCD_technology = ifelse(UCD_technology == "All", ucd_techs[1], UCD_technology)) %>%
tidyr::complete(nesting(UCD_region, rev_size.class, rev.mode, variable, unit, year, value), UCD_technology = ucd_techs) %>%
tidyr::complete(tidyr::nesting(UCD_region, rev_size.class, rev.mode, variable, unit, year, value), UCD_technology = ucd_techs) %>%
dplyr::bind_rows(ucd_core_values %>%
dplyr::filter(variable == "load factor"))

Expand All @@ -4357,18 +4357,18 @@ get_transport_sales <- function(GCAM_version = "v7.1") {
dplyr::summarise(value=mean(value, na.rm = T)) %>%
dplyr::ungroup() %>%
dplyr::mutate(UCD_region = "South America_Northern") %>%
tidyr::complete(nesting(rev_size.class, rev.mode, variable, UCD_technology, unit, year, value),
tidyr::complete(tidyr::nesting(rev_size.class, rev.mode, variable, UCD_technology, unit, year, value),
UCD_region = trn_regions[!(trn_regions %in% unique(ucd_core_A$UCD_region))])

## Check that
## a) annual travel per vehicle is in vkt/(vehicle*yr)
## b) load factors are in pass/vehicle and tonnes/vehicle
check <- unique(ucd_core_loads %>%
dplyr::select(-UCD_region, -year, -value, -UCD_technology))
if(check %>% dplyr::filter(variable == 'annual travel per vehicle') %>% pull(unit) %>% unique() != 'vkt/veh/yr'){
if(check %>% dplyr::filter(variable == 'annual travel per vehicle') %>% dplyr::pull(unit) %>% unique() != 'vkt/veh/yr'){
stop("ERROR: The `Stock|Transportation` variable has a units mismatch. The `annual travel per vehicle` units should be specified as 'vkt/veh/yr'.")
}
if(!all(check %>% dplyr::filter(variable == 'load factor') %>% pull(unit) %>% unique() %in% c('pers/veh', 'tonnes/veh'))){
if(!all(check %>% dplyr::filter(variable == 'load factor') %>% dplyr::pull(unit) %>% unique() %in% c('pers/veh', 'tonnes/veh'))){
stop("ERROR: The `Stock|Transportation` variable has a units mismatch. The `load factor` units should be specified as 'pers/veh' or 'tonnes/veh'.")
}

Expand Down Expand Up @@ -4449,7 +4449,7 @@ get_transport_stock <- function(GCAM_version = "v7.1") {
ucd_core_loads <- ucd_core_values %>%
dplyr::filter(variable == "annual travel per vehicle") %>%
dplyr::mutate(UCD_technology = ifelse(UCD_technology == "All", ucd_techs[1], UCD_technology)) %>%
tidyr::complete(nesting(UCD_region, rev_size.class, rev.mode, variable, unit, year, value), UCD_technology = ucd_techs) %>%
tidyr::complete(tidyr::nesting(UCD_region, rev_size.class, rev.mode, variable, unit, year, value), UCD_technology = ucd_techs) %>%
dplyr::bind_rows(ucd_core_values %>%
dplyr::filter(variable == "load factor"))

Expand All @@ -4470,18 +4470,18 @@ get_transport_stock <- function(GCAM_version = "v7.1") {
dplyr::summarise(value=mean(value, na.rm = T)) %>%
dplyr::ungroup() %>%
dplyr::mutate(UCD_region = "South America_Northern") %>%
tidyr::complete(nesting(rev_size.class, rev.mode, variable, UCD_technology, unit, year, value),
tidyr::complete(tidyr::nesting(rev_size.class, rev.mode, variable, UCD_technology, unit, year, value),
UCD_region = trn_regions[!(trn_regions %in% unique(ucd_core_A$UCD_region))])

## Check that
## a) annual travel per vehicle is in vkt/(vehicle*yr)
## b) load factors are in pass/vehicle and tonnes/vehicle
check <- unique(ucd_core_loads %>%
dplyr::select(-UCD_region, -year, -value, -UCD_technology))
if(check %>% dplyr::filter(variable == 'annual travel per vehicle') %>% pull(unit) %>% unique() != 'vkt/veh/yr'){
if(check %>% dplyr::filter(variable == 'annual travel per vehicle') %>% dplyr::pull(unit) %>% unique() != 'vkt/veh/yr'){
stop("ERROR: The `Stock|Transportation` variable has a units mismatch. The `annual travel per vehicle` units should be specified as 'vkt/veh/yr'.")
}
if(!all(check %>% dplyr::filter(variable == 'load factor') %>% pull(unit) %>% unique() %in% c('pers/veh', 'tonnes/veh'))){
if(!all(check %>% dplyr::filter(variable == 'load factor') %>% dplyr::pull(unit) %>% unique() %in% c('pers/veh', 'tonnes/veh'))){
stop("ERROR: The `Stock|Transportation` variable has a units mismatch. The `load factor` units should be specified as 'pers/veh' or 'tonnes/veh'.")
}

Expand Down
4 changes: 2 additions & 2 deletions R/main.R
Original file line number Diff line number Diff line change
Expand Up @@ -764,8 +764,8 @@ generate_report <- function(db_path = NULL, db_name = NULL, prj_name, scenarios

# for all desired variables, load the corresponding data
loaded_internal_variables.global <<- c()
desired_regions <<- desired_regions
desired_variables <<- desired_variables
assign("desired_regions", desired_regions, envir = globalenv())
assign("desired_variables", desired_variables, envir = globalenv())
for (i in 1:nrow(variables.global)) {
if (variables.global$required[i]) {
load_variable(variables.global[i, ], GCAM_version, GWP_version)
Expand Down

0 comments on commit 81a1b50

Please sign in to comment.