From 38e7d01b37f789447762bcc17367c126ca3f3478 Mon Sep 17 00:00:00 2001 From: klau506 Date: Tue, 12 Mar 2024 13:09:06 +0100 Subject: [PATCH] allow to pass the prj as user parameter --- NAMESPACE | 2 +- R/m1_emissions_rescale.R | 62 +++--- R/m2_conc.R | 62 ++++-- R/m3_health.R | 92 ++++++-- R/m3b_health_ecoloss.R | 57 +++-- R/m4_agriculture.R | 200 +++++++++++++----- man/calc_price_gcam.Rd | 5 +- man/calc_prod_gcam.Rd | 5 +- man/calc_rev_gcam.Rd | 5 +- man/m1_emissions_rescale.Rd | 5 +- man/m2_get_conc_aot40.Rd | 5 +- man/m2_get_conc_m6m.Rd | 5 +- man/m2_get_conc_mi.Rd | 5 +- man/m2_get_conc_o3.Rd | 5 +- man/m2_get_conc_pm25.Rd | 5 +- man/m3_get_daly_o3.Rd | 6 +- man/m3_get_daly_pm25.Rd | 6 +- man/m3_get_mort_o3.Rd | 5 +- man/m3_get_mort_pm25.Rd | 5 +- ...oss_vsl.Rd => m3_get_mort_pm25_ecoloss.Rd} | 11 +- man/m3_get_o3_ecoloss_hcl.Rd | 5 +- man/m3_get_o3_ecoloss_vsl.Rd | 5 +- man/m3_get_pm25_ecoloss_hcl.Rd | 5 +- man/m3_get_yll_o3.Rd | 5 +- man/m3_get_yll_pm25.Rd | 6 +- man/m4_get_prod_loss.Rd | 5 +- man/m4_get_rev_loss.Rd | 5 +- man/m4_get_ryl_aot40.Rd | 5 +- man/m4_get_ryl_mi.Rd | 5 +- 29 files changed, 445 insertions(+), 154 deletions(-) rename man/{m3_get_pm25_ecoloss_vsl.Rd => m3_get_mort_pm25_ecoloss.Rd} (95%) diff --git a/NAMESPACE b/NAMESPACE index 8e526c1..b55b215 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -24,10 +24,10 @@ export(m3_get_daly_o3) export(m3_get_daly_pm25) export(m3_get_mort_o3) export(m3_get_mort_pm25) +export(m3_get_mort_pm25_ecoloss) export(m3_get_o3_ecoloss_hcl) export(m3_get_o3_ecoloss_vsl) export(m3_get_pm25_ecoloss_hcl) -export(m3_get_pm25_ecoloss_vsl) export(m3_get_yll_o3) export(m3_get_yll_pm25) export(m4_get_prod_loss) diff --git a/R/m1_emissions_rescale.R b/R/m1_emissions_rescale.R index 5f4c3fc..574a18b 100644 --- a/R/m1_emissions_rescale.R +++ b/R/m1_emissions_rescale.R @@ -8,6 +8,7 @@ #' @param query_path Path to the query file #' @param db_name Name of the GCAM database #' @param prj_name Name of the rgcam project. This can be an existing project, or, if not, this will be the name +#' @param prj rgcam loaded project #' @param rdata_name Name of the RData file. It must contain the queries in a list #' @param scen_name Name of the GCAM scenario to be processed #' @param queries Name of the GCAM query file. The file by default includes the queries required to run rfasst @@ -20,7 +21,7 @@ #' @importFrom magrittr %>% #' @export -m1_emissions_rescale<-function(db_path = NULL, query_path = "./inst/extdata", db_name = NULL, prj_name, +m1_emissions_rescale<-function(db_path = NULL, query_path = "./inst/extdata", db_name = NULL, prj_name = NULL, prj = NULL, rdata_name = NULL, scen_name, queries = "queries_rfasst.xml", final_db_year = 2100, saveOutput = T, map = F, mapIndivPol = F, anim = T, recompute = F){ @@ -32,7 +33,8 @@ m1_emissions_rescale<-function(db_path = NULL, query_path = "./inst/extdata", db #---------------------------------------------------------------------- # Assert that the parameters of the function are okay, or modify when necessary - #if (!endsWith(prj_name, '.dat')) prj_name = paste0(prj_name, '.dat') + if(!endsWith(prj_name, '.dat')) prj_name = paste0(prj_name, '.dat') + if(is.null(prj_name)) assertthat::assert_that(!is.null(prj), msg = 'Specify the project name or pass an uploaded project as parameter') #---------------------------------------------------------------------- #---------------------------------------------------------------------- @@ -64,33 +66,37 @@ m1_emissions_rescale<-function(db_path = NULL, query_path = "./inst/extdata", db dplyr::rename(`ISO 3`=subRegionAlt, `FASST Region`=fasst_region) - # Load the rgcam project: - if (!is.null(db_path) & !is.null(db_name)) { - rlang::inform('Creating project ...') - conn <- rgcam::localDBConn(db_path, - db_name,migabble = FALSE) - prj <- rgcam::addScenario(conn, - prj_name, - scen_name, - paste0(query_path,"/",queries), - saveProj = F) - prj <- fill_queries(prj, db_path, db_name, prj_name, scen_name, - query_path, queries = 'queries_rfasst_nonCO2.xml') - - rgcam::saveProject(prj, file = file.path('output',prj_name)) - - QUERY_LIST <- c(rgcam::listQueries(prj, c(scen_name))) - } else if (is.null(rdata_name)){ - rlang::inform('Loading project ...') - prj <- rgcam::loadProject(prj_name) - - QUERY_LIST <- c(rgcam::listQueries(prj, c(scen_name))) - } else { - rlang::inform('Loading RData ...') - if (!exists('prj_rd')) { - prj_rd = get(load(rdata_name)) - QUERY_LIST <- names(prj_rd) + # Load the rgcam project if prj not passed as a parameter: + if (is.null(prj)) { + if (!is.null(db_path) & !is.null(db_name)) { + rlang::inform('Creating project ...') + conn <- rgcam::localDBConn(db_path, + db_name,migabble = FALSE) + prj <- rgcam::addScenario(conn, + prj_name, + scen_name, + paste0(query_path,"/",queries), + saveProj = F) + prj <- fill_queries(prj, db_path, db_name, prj_name, scen_name, + query_path, queries = 'queries_rfasst_nonCO2.xml') + + rgcam::saveProject(prj, file = file.path('output',prj_name)) + + QUERY_LIST <- c(rgcam::listQueries(prj, c(scen_name))) + } else if (is.null(rdata_name)){ + rlang::inform('Loading project ...') + prj <- rgcam::loadProject(prj_name) + + QUERY_LIST <- c(rgcam::listQueries(prj, c(scen_name))) + } else { + rlang::inform('Loading RData ...') + if (!exists('prj_rd')) { + prj_rd = get(load(rdata_name)) + QUERY_LIST <- names(prj_rd) + } } + } else { + QUERY_LIST <- c(rgcam::listQueries(prj, c(scen_name))) } rlang::inform('Computing emissions ...') diff --git a/R/m2_conc.R b/R/m2_conc.R index eb30baf..d0afea9 100644 --- a/R/m2_conc.R +++ b/R/m2_conc.R @@ -1,6 +1,5 @@ #' m2_get_conc_pm25 #' -#' #' Produce fine particulate matter (PM2.5) concentration levels for TM5-FASST regions based on re-scaled emission pathways. #' @keywords module_2, concentration, PM2.5 #' @return Particulate matter (PM2.5) concentration levels for each TM5-FASST regions for all years (ug/m3).The list of countries that form each region and the full name of the region can be found in Table S2.2 in the TM5-FASST documentation paper: Van Dingenen, R., Dentener, F., Crippa, M., Leitao, J., Marmer, E., Rao, S., Solazzo, E. and Valentini, L., 2018. TM5-FASST: a global atmospheric source-receptor model for rapid impact analysis of emission changes on air quality and short-lived climate pollutants. Atmospheric Chemistry and Physics, 18(21), pp.16173-16211. @@ -8,6 +7,7 @@ #' @param query_path Path to the query file #' @param db_name Name of the GCAM database #' @param prj_name Name of the rgcam project. This can be an existing project, or, if not, this will be the name +#' @param prj rgcam loaded project #' @param rdata_name Name of the RData file. It must contain the queries in a list #' @param scen_name Name of the GCAM scenario to be processed #' @param queries Name of the GCAM query file. The file by default includes the queries required to run rfasst @@ -23,7 +23,7 @@ #' @importFrom magrittr %>% #' @export -m2_get_conc_pm25<-function(db_path = NULL, query_path = "./inst/extdata", db_name = NULL, prj_name, +m2_get_conc_pm25<-function(db_path = NULL, query_path = "./inst/extdata", db_name = NULL, prj_name = NULL, prj = NULL, rdata_name = NULL, scen_name, queries = "queries_rfasst.xml", final_db_year = 2100, saveOutput = T, map = F, anim = T, recompute = F, downscale = F, saveRaster_grid = F, @@ -42,6 +42,7 @@ m2_get_conc_pm25<-function(db_path = NULL, query_path = "./inst/extdata", db_nam if(agg_grid == "NUTS3") assertthat::assert_that(downscale == T, msg = 'Set `downscale` to TRUE to aggregate the downscaled PM2.5 to NUTS3') if(save_AggGrid == T) assertthat::assert_that(agg_grid == "NUTS3" & downscale == T, msg = 'Set `downscale` to TRUE and agg_grid to `NUTS3` to save the aggregated raster grid') + if(is.null(prj_name)) assertthat::assert_that(!is.null(prj), msg = 'Specify the project name or pass an uploaded project as parameter') #---------------------------------------------------------------------- @@ -69,7 +70,7 @@ m2_get_conc_pm25<-function(db_path = NULL, query_path = "./inst/extdata", db_nam dplyr::rename(subRegion=fasst_region) %>% dplyr::mutate(subRegionAlt=as.factor(subRegionAlt)) - em.list<-m1_emissions_rescale(db_path, query_path, db_name, prj_name, rdata_name, scen_name, queries, saveOutput = F, final_db_year, recompute = recompute) + em.list<-m1_emissions_rescale(db_path, query_path, db_name, prj_name, prj, rdata_name, scen_name, queries, saveOutput = F, final_db_year, recompute = recompute) #---------------------------------------------------------------------- #---------------------------------------------------------------------- @@ -561,7 +562,6 @@ m2_get_conc_pm25<-function(db_path = NULL, query_path = "./inst/extdata", db_nam #' m2_get_conc_o3 #' -#' #' Produce ozone (O3) concentration levels based on re-scaled emission pathways. #' @keywords module_2, concentration, O3 #' @return Produce ozone (O3) levels for each TM5-FASST regions for all years (ppb). The list of countries that form each region and the full name of the region can be found in Table S2.2 in the TM5-FASST documentation paper: Van Dingenen, R., Dentener, F., Crippa, M., Leitao, J., Marmer, E., Rao, S., Solazzo, E. and Valentini, L., 2018. TM5-FASST: a global atmospheric source-receptor model for rapid impact analysis of emission changes on air quality and short-lived climate pollutants. Atmospheric Chemistry and Physics, 18(21), pp.16173-16211. @@ -569,6 +569,7 @@ m2_get_conc_pm25<-function(db_path = NULL, query_path = "./inst/extdata", db_nam #' @param query_path Path to the query file #' @param db_name Name of the GCAM database #' @param prj_name Name of the rgcam project. This can be an existing project, or, if not, this will be the name +#' @param prj rgcam loaded project #' @param rdata_name Name of the RData file. It must contain the queries in a list #' @param scen_name Name of the GCAM scenario to be processed #' @param queries Name of the GCAM query file. The file by default includes the queries required to run rfasst @@ -581,13 +582,21 @@ m2_get_conc_pm25<-function(db_path = NULL, query_path = "./inst/extdata", db_nam #' @importFrom magrittr %>% #' @export -m2_get_conc_o3<-function(db_path = NULL, query_path = "./inst/extdata", db_name = NULL, prj_name, +m2_get_conc_o3<-function(db_path = NULL, query_path = "./inst/extdata", db_name = NULL, prj_name = NULL, prj = NULL, rdata_name = NULL, scen_name, queries = "queries_rfasst.xml", final_db_year = 2100, saveOutput = T, ch4_o3 = T, map = F, anim = T, recompute = F){ if (!recompute & exists('m2_get_conc_o3.output')) { return(m2_get_conc_o3.output) } else { + #---------------------------------------------------------------------- + #---------------------------------------------------------------------- + # Assert that the parameters of the function are okay, or modify when necessary + + if (is.null(prj_name)) assertthat::assert_that(!is.null(prj), msg = 'Specify the project name or pass an uploaded project as parameter') + + #---------------------------------------------------------------------- + #---------------------------------------------------------------------- all_years<-all_years[all_years <= final_db_year] @@ -810,6 +819,7 @@ m2_get_conc_o3<-function(db_path = NULL, query_path = "./inst/extdata", db_name #' @param query_path Path to the query file #' @param db_name Name of the GCAM database #' @param prj_name Name of the rgcam project. This can be an existing project, or, if not, this will be the name +#' @param prj rgcam loaded project #' @param rdata_name Name of the RData file. It must contain the queries in a list #' @param scen_name Name of the GCAM scenario to be processed #' @param queries Name of the GCAM query file. The file by default includes the queries required to run rfasst @@ -821,14 +831,21 @@ m2_get_conc_o3<-function(db_path = NULL, query_path = "./inst/extdata", db_name #' @importFrom magrittr %>% #' @export - -m2_get_conc_m6m<-function(db_path = NULL, query_path = "./inst/extdata", db_name = NULL, prj_name, +m2_get_conc_m6m<-function(db_path = NULL, query_path = "./inst/extdata", db_name = NULL, prj_name = NULL, prj = NULL, rdata_name = NULL, scen_name, queries = "queries_rfasst.xml", final_db_year = 2100, saveOutput = T, map = F, anim = T, recompute = F){ if (!recompute & exists('m2_get_conc_m6m.output')) { return(m2_get_conc_m6m.output) } else { + #---------------------------------------------------------------------- + #---------------------------------------------------------------------- + # Assert that the parameters of the function are okay, or modify when necessary + + if(is.null(prj_name)) assertthat::assert_that(!is.null(prj), msg = 'Specify the project name or pass an uploaded project as parameter') + + #---------------------------------------------------------------------- + #---------------------------------------------------------------------- all_years<-all_years[all_years <= final_db_year] @@ -852,7 +869,7 @@ m2_get_conc_m6m<-function(db_path = NULL, query_path = "./inst/extdata", db_name dplyr::rename(subRegion=fasst_region) %>% dplyr::mutate(subRegionAlt=as.factor(subRegionAlt)) - em.list<-m1_emissions_rescale(db_path,query_path,db_name,prj_name,rdata_name,scen_name,queries,saveOutput = F, final_db_year = final_db_year, recompute = recompute) + em.list<-m1_emissions_rescale(db_path,query_path,db_name,prj_name,prj,rdata_name,scen_name,queries,saveOutput = F, final_db_year = final_db_year, recompute = recompute) # First we load the base concentration and emissions, which are required for the calculations base_conc<-raw.base_conc %>% @@ -1076,6 +1093,7 @@ m2_get_conc_m6m<-function(db_path = NULL, query_path = "./inst/extdata", db_name #' @param query_path Path to the query file #' @param db_name Name of the GCAM database #' @param prj_name Name of the rgcam project. This can be an existing project, or, if not, this will be the name +#' @param prj rgcam loaded project #' @param rdata_name Name of the RData file. It must contain the queries in a list #' @param scen_name Name of the GCAM scenario to be processed #' @param queries Name of the GCAM query file. The file by default includes the queries required to run rfasst @@ -1088,7 +1106,7 @@ m2_get_conc_m6m<-function(db_path = NULL, query_path = "./inst/extdata", db_name #' @export -m2_get_conc_aot40<-function(db_path = NULL, query_path = "./inst/extdata", db_name = NULL, prj_name, +m2_get_conc_aot40<-function(db_path = NULL, query_path = "./inst/extdata", db_name = NULL, prj_name = NULL, prj = NULL, rdata_name = NULL, scen_name, queries = "queries_rfasst.xml", final_db_year = 2100, saveOutput = T, map = F, anim = T, recompute = F){ @@ -1096,6 +1114,15 @@ m2_get_conc_aot40<-function(db_path = NULL, query_path = "./inst/extdata", db_na return(m2_get_conc_aot40.output) } else { + #---------------------------------------------------------------------- + #---------------------------------------------------------------------- + # Assert that the parameters of the function are okay, or modify when necessary + + if(is.null(prj_name)) assertthat::assert_that(!is.null(prj), msg = 'Specify the project name or pass an uploaded project as parameter') + + #---------------------------------------------------------------------- + #---------------------------------------------------------------------- + all_years<-all_years[all_years <= final_db_year] # Create the directories if they do not exist: @@ -1118,7 +1145,7 @@ m2_get_conc_aot40<-function(db_path = NULL, query_path = "./inst/extdata", db_na dplyr::rename(subRegion=fasst_region) %>% dplyr::mutate(subRegionAlt=as.factor(subRegionAlt)) - em.list<-m1_emissions_rescale(db_path, query_path, db_name, prj_name, rdata_name, scen_name, queries, saveOutput = F, final_db_year = final_db_year, recompute = recompute) + em.list<-m1_emissions_rescale(db_path, query_path, db_name, prj_name, prj, rdata_name, scen_name, queries, saveOutput = F, final_db_year = final_db_year, recompute = recompute) # First we load the base concentration and emissions, which are required for the calculations @@ -1509,6 +1536,7 @@ m2_get_conc_aot40<-function(db_path = NULL, query_path = "./inst/extdata", db_na #' @param query_path Path to the query file #' @param db_name Name of the GCAM database #' @param prj_name Name of the rgcam project. This can be an existing project, or, if not, this will be the name +#' @param prj rgcam loaded project #' @param rdata_name Name of the RData file. It must contain the queries in a list #' @param scen_name Name of the GCAM scenario to be processed #' @param queries Name of the GCAM query file. The file by default includes the queries required to run rfasst @@ -1520,8 +1548,7 @@ m2_get_conc_aot40<-function(db_path = NULL, query_path = "./inst/extdata", db_na #' @importFrom magrittr %>% #' @export - -m2_get_conc_mi<-function(db_path = NULL, query_path = "./inst/extdata", db_name = NULL, prj_name, +m2_get_conc_mi<-function(db_path = NULL, query_path = "./inst/extdata", db_name = NULL, prj_name = NULL, prj = NULL, rdata_name = NULL, scen_name, queries = "queries_rfasst.xml", final_db_year = 2100, saveOutput = T, map = F, anim = T, recompute = F){ @@ -1529,6 +1556,15 @@ m2_get_conc_mi<-function(db_path = NULL, query_path = "./inst/extdata", db_name return(m2_get_conc_mi.output) } else { + #---------------------------------------------------------------------- + #---------------------------------------------------------------------- + # Assert that the parameters of the function are okay, or modify when necessary + + if(is.null(prj_name)) assertthat::assert_that(!is.null(prj), msg = 'Specify the project name or pass an uploaded project as parameter') + + #---------------------------------------------------------------------- + #---------------------------------------------------------------------- + all_years<-all_years[all_years <= final_db_year] # Create the directories if they do not exist: @@ -1551,7 +1587,7 @@ m2_get_conc_mi<-function(db_path = NULL, query_path = "./inst/extdata", db_name dplyr::rename(subRegion=fasst_region) %>% dplyr::mutate(subRegionAlt=as.factor(subRegionAlt)) - em.list<-m1_emissions_rescale(db_path,query_path, db_name, prj_name, rdata_name, scen_name, queries, saveOutput = F, final_db_year = final_db_year, recompute = recompute) + em.list<-m1_emissions_rescale(db_path,query_path, db_name, prj_name, prj, rdata_name, scen_name, queries, saveOutput = F, final_db_year = final_db_year, recompute = recompute) # First we load the base concentration and emissions, which are required for the calculations diff --git a/R/m3_health.R b/R/m3_health.R index b955d47..58fb668 100644 --- a/R/m3_health.R +++ b/R/m3_health.R @@ -115,6 +115,7 @@ calc_daly_o3<-function(){ #' @param query_path Path to the query file #' @param db_name Name of the GCAM database #' @param prj_name Name of the rgcam project. This can be an existing project, or, if not, this will be the name +#' @param prj rgcam loaded project #' @param rdata_name Name of the RData file. It must contain the queries in a list #' @param scen_name Name of the GCAM scenario to be processed #' @param queries Name of the GCAM query file. The file by default includes the queries required to run rfasst @@ -127,7 +128,7 @@ calc_daly_o3<-function(){ #' @importFrom magrittr %>% #' @export -m3_get_mort_pm25<-function(db_path = NULL, query_path = "./inst/extdata", db_name = NULL, prj_name, +m3_get_mort_pm25<-function(db_path = NULL, query_path = "./inst/extdata", db_name = NULL, prj_name = NULL, prj = NULL, rdata_name = NULL, scen_name, queries = "queries_rfasst.xml", final_db_year = 2100, ssp = "SSP2", saveOutput = T, map = F, anim = T, recompute = F){ @@ -135,6 +136,15 @@ m3_get_mort_pm25<-function(db_path = NULL, query_path = "./inst/extdata", db_nam return(m3_get_mort_pm25.output) } else { + #---------------------------------------------------------------------- + #---------------------------------------------------------------------- + # Assert that the parameters of the function are okay, or modify when necessary + + if(is.null(prj_name)) assertthat::assert_that(!is.null(prj), msg = 'Specify the project name or pass an uploaded project as parameter') + + #---------------------------------------------------------------------- + #---------------------------------------------------------------------- + all_years<-all_years[all_years <= final_db_year] # Create the directories if they do not exist: @@ -158,7 +168,7 @@ m3_get_mort_pm25<-function(db_path = NULL, query_path = "./inst/extdata", db_nam dplyr::mutate(subRegionAlt = as.factor(subRegionAlt)) # Get PM2.5 - pm.pre<-m2_get_conc_pm25(db_path, query_path, db_name, prj_name, rdata_name, scen_name, queries, saveOutput = F, final_db_year = final_db_year, recompute = recompute) + pm.pre<-m2_get_conc_pm25(db_path, query_path, db_name, prj_name, prj, rdata_name, scen_name, queries, saveOutput = F, final_db_year = final_db_year, recompute = recompute) #---------------------------------------------------------------------- #---------------------------------------------------------------------- rlang::inform('Computing premature deaths ...') @@ -362,6 +372,7 @@ m3_get_mort_pm25<-function(db_path = NULL, query_path = "./inst/extdata", db_nam #' @param query_path Path to the query file #' @param db_name Name of the GCAM database #' @param prj_name Name of the rgcam project. This can be an existing project, or, if not, this will be the name +#' @param prj rgcam loaded project #' @param rdata_name Name of the RData file. It must contain the queries in a list #' @param scen_name Name of the GCAM scenario to be processed #' @param queries Name of the GCAM query file. The file by default includes the queries required to run rfasst @@ -374,14 +385,23 @@ m3_get_mort_pm25<-function(db_path = NULL, query_path = "./inst/extdata", db_nam #' @importFrom magrittr %>% #' @export -m3_get_yll_pm25<-function(db_path = NULL, query_path = "./inst/extdata", db_name = NULL, prj_name, - rdata_name = NULL, scen_name, queries = "queries_rfasst.xml", final_db_year = 2100, +m3_get_yll_pm25<-function(db_path = NULL, query_path = "./inst/extdata", db_name = NULL, prj_name = NULL, prj = NULL, + rdata_name = NULL, scen_name, queries = "queries_rfasst.xml", final_db_year = 2100, mort_param = "GBD", ssp = "SSP2", saveOutput = T, map = F, anim = T, recompute = F){ if (!recompute & exists('m3_get_yll_pm25.output')) { return(m3_get_yll_pm25.output) } else { + #---------------------------------------------------------------------- + #---------------------------------------------------------------------- + # Assert that the parameters of the function are okay, or modify when necessary + + if(is.null(prj_name)) assertthat::assert_that(!is.null(prj), msg = 'Specify the project name or pass an uploaded project as parameter') + + #---------------------------------------------------------------------- + #---------------------------------------------------------------------- + all_years<-all_years[all_years <= final_db_year] # Create the directories if they do not exist: @@ -405,7 +425,7 @@ m3_get_yll_pm25<-function(db_path = NULL, query_path = "./inst/extdata", db_name dplyr::mutate(subRegionAlt = as.factor(subRegionAlt)) # Get pm.mort - pm.mort<-m3_get_mort_pm25(db_path = db_path, db_name = db_name, prj_name = prj_name, scen_name = scen_name, rdata_name = rdata_name, query_path = query_path, + pm.mort<-m3_get_mort_pm25(db_path = db_path, db_name = db_name, prj_name = prj_name, prj = prj, scen_name = scen_name, rdata_name = rdata_name, query_path = query_path, queries = queries, ssp = ssp, saveOutput = F, final_db_year = final_db_year, recompute = recompute) # Get years of life lost @@ -538,6 +558,7 @@ m3_get_yll_pm25<-function(db_path = NULL, query_path = "./inst/extdata", db_name #' @param query_path Path to the query file #' @param db_name Name of the GCAM database #' @param prj_name Name of the rgcam project. This can be an existing project, or, if not, this will be the name +#' @param prj rgcam loaded project #' @param rdata_name Name of the RData file. It must contain the queries in a list #' @param scen_name Name of the GCAM scenario to be processed #' @param queries Name of the GCAM query file. The file by default includes the queries required to run rfasst @@ -550,8 +571,8 @@ m3_get_yll_pm25<-function(db_path = NULL, query_path = "./inst/extdata", db_name #' @importFrom magrittr %>% #' @export -m3_get_daly_pm25<-function(db_path = NULL, query_path = "./inst/extdata", db_name = NULL, prj_name, - rdata_name = NULL, scen_name, queries = "queries_rfasst.xml", final_db_year = 2100, +m3_get_daly_pm25<-function(db_path = NULL, query_path = "./inst/extdata", db_name = NULL, prj_name = NULL, prj = NULL, + rdata_name = NULL, scen_name, queries = "queries_rfasst.xml", final_db_year = 2100, mort_param = "GBD2016_medium", ssp="SSP2", saveOutput = T, map = F, anim = T, recompute = F){ @@ -559,6 +580,15 @@ m3_get_daly_pm25<-function(db_path = NULL, query_path = "./inst/extdata", db_nam return(m3_get_daly_pm25.output) } else { + #---------------------------------------------------------------------- + #---------------------------------------------------------------------- + # Assert that the parameters of the function are okay, or modify when necessary + + if(is.null(prj_name)) assertthat::assert_that(!is.null(prj), msg = 'Specify the project name or pass an uploaded project as parameter') + + #---------------------------------------------------------------------- + #---------------------------------------------------------------------- + all_years<-all_years[all_years <= final_db_year] # Create the directories if they do not exist: @@ -585,7 +615,7 @@ m3_get_daly_pm25<-function(db_path = NULL, query_path = "./inst/extdata", db_nam daly_calc_pm<-calc_daly_pm25() # Get pm.mort - pm.mort<-m3_get_mort_pm25(db_path = db_path, db_name = db_name, prj_name = prj_name, scen_name = scen_name, rdata_name = rdata_name, query_path = query_path, + pm.mort<-m3_get_mort_pm25(db_path = db_path, db_name = db_name, prj_name = prj_name, prj = prj, scen_name = scen_name, rdata_name = rdata_name, query_path = query_path, queries = queries, ssp = ssp, saveOutput = F, final_db_year = final_db_year, recompute = recompute) #------------------------------------------------------------------------------------ #------------------------------------------------------------------------------------ @@ -692,6 +722,7 @@ m3_get_daly_pm25<-function(db_path = NULL, query_path = "./inst/extdata", db_nam #' @param query_path Path to the query file #' @param db_name Name of the GCAM database #' @param prj_name Name of the rgcam project. This can be an existing project, or, if not, this will be the name +#' @param prj rgcam loaded project #' @param rdata_name Name of the RData file. It must contain the queries in a list #' @param scen_name Name of the GCAM scenario to be processed #' @param queries Name of the GCAM query file. The file by default includes the queries required to run rfasst @@ -704,7 +735,7 @@ m3_get_daly_pm25<-function(db_path = NULL, query_path = "./inst/extdata", db_nam #' @importFrom magrittr %>% #' @export -m3_get_mort_o3<-function(db_path = NULL, query_path = "./inst/extdata", db_name = NULL, prj_name, +m3_get_mort_o3<-function(db_path = NULL, query_path = "./inst/extdata", db_name = NULL, prj_name = NULL, prj = NULL, rdata_name = NULL, scen_name, queries = "queries_rfasst.xml", final_db_year = 2100, ssp = "SSP2", saveOutput = T, map = F, anim = T, recompute = F){ @@ -712,6 +743,15 @@ m3_get_mort_o3<-function(db_path = NULL, query_path = "./inst/extdata", db_name return(m3_get_mort_o3.output) } else { + #---------------------------------------------------------------------- + #---------------------------------------------------------------------- + # Assert that the parameters of the function are okay, or modify when necessary + + if(is.null(prj_name)) assertthat::assert_that(!is.null(prj), msg = 'Specify the project name or pass an uploaded project as parameter') + + #---------------------------------------------------------------------- + #---------------------------------------------------------------------- + all_years<-all_years[all_years <= final_db_year] # Create the directories if they do not exist: @@ -735,7 +775,7 @@ m3_get_mort_o3<-function(db_path = NULL, query_path = "./inst/extdata", db_name dplyr::mutate(subRegionAlt=as.factor(subRegionAlt)) # Get PM2.5 - m6m<-m2_get_conc_m6m(db_path, query_path, db_name, prj_name, rdata_name, scen_name, queries, saveOutput = F, final_db_year = final_db_year, recompute = recompute) + m6m<-m2_get_conc_m6m(db_path, query_path, db_name, prj_name, prj, rdata_name, scen_name, queries, saveOutput = F, final_db_year = final_db_year, recompute = recompute) # Get population pop.all<-get(paste0('pop.all.',ssp)) @@ -837,6 +877,7 @@ m3_get_mort_o3<-function(db_path = NULL, query_path = "./inst/extdata", db_name #' @param query_path Path to the query file #' @param db_name Name of the GCAM database #' @param prj_name Name of the rgcam project. This can be an existing project, or, if not, this will be the name +#' @param prj rgcam loaded project #' @param rdata_name Name of the RData file. It must contain the queries in a list #' @param scen_name Name of the GCAM scenario to be processed #' @param queries Name of the GCAM query file. The file by default includes the queries required to run rfasst @@ -850,13 +891,21 @@ m3_get_mort_o3<-function(db_path = NULL, query_path = "./inst/extdata", db_name #' @importFrom magrittr %>% #' @export -m3_get_yll_o3<-function(db_path = NULL, query_path = "./inst/extdata", db_name = NULL, prj_name, +m3_get_yll_o3<-function(db_path = NULL, query_path = "./inst/extdata", db_name = NULL, prj_name = NULL, prj = NULL, rdata_name = NULL, scen_name, queries = "queries_rfasst.xml", final_db_year = 2100, mort_param = "mort_o3_gbd2016_med", ssp = "SSP2", saveOutput = T, map = F, anim = T, recompute = F){ if (!recompute & exists('m3_get_yll_o3.output')) { return(m3_get_yll_o3.output) } else { + #---------------------------------------------------------------------- + #---------------------------------------------------------------------- + # Assert that the parameters of the function are okay, or modify when necessary + + if(is.null(prj_name)) assertthat::assert_that(!is.null(prj), msg = 'Specify the project name or pass an uploaded project as parameter') + + #---------------------------------------------------------------------- + #---------------------------------------------------------------------- all_years<-all_years[all_years <= final_db_year] @@ -881,8 +930,9 @@ m3_get_yll_o3<-function(db_path = NULL, query_path = "./inst/extdata", db_name = dplyr::mutate(subRegionAlt = as.factor(subRegionAlt)) # Get pm.mort - o3.mort<-m3_get_mort_o3(db_path = db_path, db_name = db_name, prj_name = prj_name, scen_name = scen_name, rdata_name = rdata_name, query_path = query_path, - queries = queries, ssp = ssp, saveOutput = F, final_db_year = final_db_year, recompute = recompute) + o3.mort<-m3_get_mort_o3(db_path, query_path, db_name, prj_name, prj, scen_name, queries, ssp = ssp, saveOutput = F, final_db_year = final_db_year, recompute = recompute) %>% + dplyr::select(region, year, disease, mort_param) %>% + dplyr::rename(mort_o3 = mort_param) #------------------------------------------------------------------------------------ #------------------------------------------------------------------------------------ @@ -990,6 +1040,7 @@ m3_get_yll_o3<-function(db_path = NULL, query_path = "./inst/extdata", db_name = #' @param query_path Path to the query file #' @param db_name Name of the GCAM database #' @param prj_name Name of the rgcam project. This can be an existing project, or, if not, this will be the name +#' @param prj rgcam loaded project #' @param rdata_name Name of the RData file. It must contain the queries in a list #' @param scen_name Name of the GCAM scenario to be processed #' @param queries Name of the GCAM query file. The file by default includes the queries required to run rfasst @@ -1002,14 +1053,23 @@ m3_get_yll_o3<-function(db_path = NULL, query_path = "./inst/extdata", db_name = #' @importFrom magrittr %>% #' @export -m3_get_daly_o3<-function(db_path = NULL, query_path = "./inst/extdata", db_name = NULL, prj_name, - rdata_name = NULL, scen_name, queries = "queries_rfasst.xml", final_db_year = 2100, +m3_get_daly_o3<-function(db_path = NULL, query_path = "./inst/extdata", db_name = NULL, prj_name = NULL, prj = NULL, + rdata_name = NULL, scen_name, queries = "queries_rfasst.xml", final_db_year = 2100, mort_param = "mort_o3_gbd2016_med", ssp = "SSP2", saveOutput = T, map = F, anim = T, recompute = F){ if (!recompute & exists('m3_get_daly_o3.output')) { return(m3_get_daly_o3.output) } else { + #---------------------------------------------------------------------- + #---------------------------------------------------------------------- + # Assert that the parameters of the function are okay, or modify when necessary + + if(is.null(prj_name)) assertthat::assert_that(!is.null(prj), msg = 'Specify the project name or pass an uploaded project as parameter') + + #---------------------------------------------------------------------- + #---------------------------------------------------------------------- + all_years<-all_years[all_years <= final_db_year] # Create the directories if they do not exist: @@ -1036,7 +1096,7 @@ m3_get_daly_o3<-function(db_path = NULL, query_path = "./inst/extdata", db_name daly_calc_o3<-calc_daly_o3() # Get pm.mort - o3.mort <- m3_get_mort_o3(db_path = db_path, db_name = db_name, prj_name = prj_name, scen_name = scen_name, rdata_name = rdata_name, query_path = query_path, + o3.mort <- m3_get_mort_o3(db_path = db_path, db_name = db_name, prj_name = prj_name, prj = prj, scen_name = scen_name, rdata_name = rdata_name, query_path = query_path, queries = queries, ssp = ssp, saveOutput = F, final_db_year = final_db_year, recompute = recompute) #------------------------------------------------------------------------------------ diff --git a/R/m3b_health_ecoloss.R b/R/m3b_health_ecoloss.R index 4a67eeb..4ee4ccc 100644 --- a/R/m3b_health_ecoloss.R +++ b/R/m3b_health_ecoloss.R @@ -1,6 +1,5 @@ #' m3_get_pm25_ecoloss_vsl #' -#' #' Produce economic damages associated with premature mortality attributable to PM2.5 exposure based on the IER functions from Burnett et al (2014), consistent with the GBD 2016 study. The economic valuation takes as a base value the widely accepted Value of Statistical Life (VSL) of the OECD for 2005. This value, according to the literature ranges between US$1.8 and $4.5 million. The calculations for all regions are based on the “unit value transfer approach” which adjusts the VSL according to their GDP and GDP growth rates. (Markandya et al 2018) #' @source Narain, U. and Sall, C., 2016. Methodology for Valuing the Health Impacts of Air Pollution//// Markandya, A., Sampedro, J., Smith, S.J., Van Dingenen, R., Pizarro-Irizar, C., Arto, I. and González-Eguino, M., 2018. Health co-benefits from air pollution and mitigation costs of the Paris Agreement: a modelling study. The Lancet Planetary Health, 2(3), pp.e126-e133. #' @keywords module_3, VSL ,premature mortality, PM2.5 @@ -9,6 +8,7 @@ #' @param query_path Path to the query file #' @param db_name Name of the GCAM database #' @param prj_name Name of the rgcam project. This can be an existing project, or, if not, this will be the name +#' @param prj rgcam loaded project #' @param rdata_name Name of the RData file. It must contain the queries in a list #' @param scen_name Name of the GCAM scenario to be processed #' @param queries Name of the GCAM query file. The file by default includes the queries required to run rfasst @@ -24,7 +24,7 @@ #' @importFrom magrittr %>% #' @export -m3_get_pm25_ecoloss_vsl<-function(db_path = NULL, query_path = "./inst/extdata", db_name = NULL, prj_name, +m3_get_mort_pm25_ecoloss<-function(db_path = NULL, query_path = "./inst/extdata", db_name = NULL, prj_name = NULL, prj = NULL, rdata_name = NULL, scen_name, ssp = "SSP2", final_db_year = 2100, mort_model = "GBD", Damage_vsl_range = "VSL_med", inc_elas_vsl = 0.8, queries = "queries_rfasst.xml", saveOutput = T, map = F, anim = T, recompute = F){ @@ -33,6 +33,15 @@ m3_get_pm25_ecoloss_vsl<-function(db_path = NULL, query_path = "./inst/extdata", return(m3_get_pm25_ecoloss_vsl.output) } else { + #---------------------------------------------------------------------- + #---------------------------------------------------------------------- + # Assert that the parameters of the function are okay, or modify when necessary + + if(is.null(prj_name)) assertthat::assert_that(!is.null(prj), msg = 'Specify the project name or pass an uploaded project as parameter') + + #---------------------------------------------------------------------- + #---------------------------------------------------------------------- + all_years<-all_years[all_years <= final_db_year] # Create the directories if they do not exist: @@ -56,7 +65,7 @@ m3_get_pm25_ecoloss_vsl<-function(db_path = NULL, query_path = "./inst/extdata", dplyr::mutate(subRegionAlt = as.factor(subRegionAlt)) # Get Mortalities - pm.mort<-m3_get_mort_pm25(db_path = db_path, db_name = db_name, prj_name = prj_name, scen_name = scen_name, rdata_name = rdata_name, query_path = query_path, + pm.mort<-m3_get_mort_pm25(db_path = db_path, db_name = db_name, prj_name = prj_name, prj = prj, scen_name = scen_name, rdata_name = rdata_name, query_path = query_path, queries = queries, ssp = ssp, saveOutput = F, final_db_year = final_db_year, recompute = recompute) %>% tidyr::pivot_longer(cols = c("GBD", "GEMM", "FUSION"), names_to = "model", @@ -156,7 +165,6 @@ m3_get_pm25_ecoloss_vsl<-function(db_path = NULL, query_path = "./inst/extdata", #' m3_get_o3_ecoloss_vsl #' -#' #' Produce economic damages associated with premature mortality attributable to O3 (M6M) exposure based on the IER functions from Jerret et al (2009), consistent with the GBD 2016 study. The economic valuation takes as a base value the widely accepted Value of Statistical Life (VSL) of the OECD for 2005. This value, according to the literature ranges between US$1.8 and $4.5 million. The calculations for all regions are based on the “unit value transfer approach” which adjusts the VSL according to their GDP and GDP growth rates. (Markandya et al 2018) #' @source Jerrett, M., Burnett, R.T., Pope III, C.A., Ito, K., Thurston, G., Krewski, D., Shi, Y., Calle, E. and Thun, M., 2009. Long-term ozone exposure and mortality. New England Journal of Medicine, 360(11), pp.1085-1095.//// Markandya, A., Sampedro, J., Smith, S.J., Van Dingenen, R., Pizarro-Irizar, C., Arto, I. and González-Eguino, M., 2018. Health co-benefits from air pollution and mitigation costs of the Paris Agreement: a modelling study. The Lancet Planetary Health, 2(3), pp.e126-e133. #' @keywords module_3, VSL ,premature mortality, O3 @@ -165,6 +173,7 @@ m3_get_pm25_ecoloss_vsl<-function(db_path = NULL, query_path = "./inst/extdata", #' @param query_path Path to the query file #' @param db_name Name of the GCAM database #' @param prj_name Name of the rgcam project. This can be an existing project, or, if not, this will be the name +#' @param prj rgcam loaded project #' @param rdata_name Name of the RData file. It must contain the queries in a list #' @param scen_name Name of the GCAM scenario to be processed #' @param queries Name of the GCAM query file. The file by default includes the queries required to run rfasst @@ -180,7 +189,7 @@ m3_get_pm25_ecoloss_vsl<-function(db_path = NULL, query_path = "./inst/extdata", #' @importFrom magrittr %>% #' @export -m3_get_o3_ecoloss_vsl<-function(db_path = NULL, query_path = "./inst/extdata", db_name = NULL, prj_name, +m3_get_o3_ecoloss_vsl<-function(db_path = NULL, query_path = "./inst/extdata", db_name = NULL, prj_name = NULL, prj = NULL, rdata_name = NULL, scen_name, ssp = "SSP2", final_db_year = 2100, mort_model = "Jerret2009", Damage_vsl_range = "VSL_med", inc_elas_vsl = 0.8, queries = "queries_rfasst.xml", saveOutput = T, map = F, anim = T, recompute = F){ @@ -188,6 +197,14 @@ m3_get_o3_ecoloss_vsl<-function(db_path = NULL, query_path = "./inst/extdata", d if (!recompute & exists('m3_get_o3_ecoloss_vsl.output')) { return(m3_get_o3_ecoloss_vsl.output) } else { + #---------------------------------------------------------------------- + #---------------------------------------------------------------------- + # Assert that the parameters of the function are okay, or modify when necessary + + if(is.null(prj_name)) assertthat::assert_that(!is.null(prj), msg = 'Specify the project name or pass an uploaded project as parameter') + + #---------------------------------------------------------------------- + #---------------------------------------------------------------------- all_years<-all_years[all_years <= final_db_year] @@ -212,7 +229,7 @@ m3_get_o3_ecoloss_vsl<-function(db_path = NULL, query_path = "./inst/extdata", d dplyr::mutate(subRegionAlt=as.factor(subRegionAlt)) # Get Mortalities - o3.mort <- m3_get_mort_o3(db_path = db_path, db_name = db_name, prj_name = prj_name, scen_name = scen_name, rdata_name = rdata_name, query_path = query_path, + o3.mort <- m3_get_mort_o3(db_path = db_path, db_name = db_name, prj_name = prj_name, prj = prj, scen_name = scen_name, rdata_name = rdata_name, query_path = query_path, queries = queries, ssp = ssp, saveOutput = F, final_db_year = final_db_year, recompute = recompute) %>% tidyr::pivot_longer(cols = c("Jerret2009", "GBD2016"), names_to = "model", @@ -312,7 +329,6 @@ m3_get_o3_ecoloss_vsl<-function(db_path = NULL, query_path = "./inst/extdata", d #' m3_get_pm25_ecoloss_hcl #' -#' #' Produce economic damages associated with premature mortality attributable to PM2.5. The economic valuation is based on the Human Capital Loss approach #' @source Liu, G., Yang, Z., Chen, B. and Ulgiati, S., 2011. Monitoring trends of urban development and environmental impact of Beijing, 1999–2006. Science of the Total Environment, 409(18), pp.3295-3308. #' @keywords module_3, HCL ,premature mortality, PM2.5 @@ -321,6 +337,7 @@ m3_get_o3_ecoloss_vsl<-function(db_path = NULL, query_path = "./inst/extdata", d #' @param query_path Path to the query file #' @param db_name Name of the GCAM database #' @param prj_name Name of the rgcam project. This can be an existing project, or, if not, this will be the name +#' @param prj rgcam loaded project #' @param rdata_name Name of the RData file. It must contain the queries in a list #' @param scen_name Name of the GCAM scenario to be processed #' @param queries Name of the GCAM query file. The file by default includes the queries required to run rfasst @@ -336,7 +353,7 @@ m3_get_o3_ecoloss_vsl<-function(db_path = NULL, query_path = "./inst/extdata", d #' @importFrom magrittr %>% #' @export -m3_get_pm25_ecoloss_hcl<-function(db_path = NULL, query_path = "./inst/extdata", db_name = NULL, prj_name, +m3_get_pm25_ecoloss_hcl<-function(db_path = NULL, query_path = "./inst/extdata", db_name = NULL, prj_name = NULL, prj = NULL, rdata_name = NULL, scen_name, ssp = "SSP2", final_db_year = 2100, mort_model = "GBD", Damage_vsl_range = "VSL_med", inc_elas_vsl = 0.8, queries = "queries_rfasst.xml", saveOutput = T, map = F, anim = T, recompute = F){ @@ -344,6 +361,14 @@ m3_get_pm25_ecoloss_hcl<-function(db_path = NULL, query_path = "./inst/extdata", if (!recompute & exists('m3_get_pm25_ecoloss_hcl.output')) { return(m3_get_pm25_ecoloss_hcl.output) } else { + #---------------------------------------------------------------------- + #---------------------------------------------------------------------- + # Assert that the parameters of the function are okay, or modify when necessary + + if(is.null(prj_name)) assertthat::assert_that(!is.null(prj), msg = 'Specify the project name or pass an uploaded project as parameter') + + #---------------------------------------------------------------------- + #---------------------------------------------------------------------- all_years<-all_years[all_years <= final_db_year] @@ -368,7 +393,7 @@ m3_get_pm25_ecoloss_hcl<-function(db_path = NULL, query_path = "./inst/extdata", dplyr::mutate(subRegionAlt = as.factor(subRegionAlt)) # Get Mortalities - pm.mort<-m3_get_mort_pm25(db_path = db_path, db_name = db_name, prj_name = prj_name, scen_name = scen_name, rdata_name = rdata_name, query_path = query_path, + pm.mort<-m3_get_mort_pm25(db_path = db_path, db_name = db_name, prj_name = prj_name, prj = prj, scen_name = scen_name, rdata_name = rdata_name, query_path = query_path, queries = queries, ssp = ssp, saveOutput = F, final_db_year = final_db_year, recompute = recompute) %>% tidyr::pivot_longer(cols = c("GBD", "GEMM", "FUSION"), names_to = "model", @@ -452,7 +477,6 @@ m3_get_pm25_ecoloss_hcl<-function(db_path = NULL, query_path = "./inst/extdata", #' m3_get_o3_ecoloss_hcl #' -#' #' Produce economic damages associated with premature mortality attributable to O3. The economic valuation is based on the Human Capital Loss approach #' @source Liu, G., Yang, Z., Chen, B. and Ulgiati, S., 2011. Monitoring trends of urban development and environmental impact of Beijing, 1999–2006. Science of the Total Environment, 409(18), pp.3295-3308. #' @keywords module_3, HCL ,premature mortality, O3 @@ -461,6 +485,7 @@ m3_get_pm25_ecoloss_hcl<-function(db_path = NULL, query_path = "./inst/extdata", #' @param query_path Path to the query file #' @param db_name Name of the GCAM database #' @param prj_name Name of the rgcam project. This can be an existing project, or, if not, this will be the name +#' @param prj rgcam loaded project #' @param rdata_name Name of the RData file. It must contain the queries in a list #' @param scen_name Name of the GCAM scenario to be processed #' @param queries Name of the GCAM query file. The file by default includes the queries required to run rfasst @@ -476,7 +501,7 @@ m3_get_pm25_ecoloss_hcl<-function(db_path = NULL, query_path = "./inst/extdata", #' @importFrom magrittr %>% #' @export -m3_get_o3_ecoloss_hcl<-function(db_path = NULL, query_path = "./inst/extdata", db_name = NULL, prj_name, +m3_get_o3_ecoloss_hcl<-function(db_path = NULL, query_path = "./inst/extdata", db_name = NULL, prj_name = NULL, prj = NULL, rdata_name = NULL, scen_name, ssp = "SSP2", final_db_year = 2100, mort_model = "GBD", Damage_vsl_range = "VSL_med", inc_elas_vsl = 0.8, queries = "queries_rfasst.xml", saveOutput = T, map = F, anim = T, recompute = F){ @@ -484,6 +509,14 @@ m3_get_o3_ecoloss_hcl<-function(db_path = NULL, query_path = "./inst/extdata", d if (!recompute & exists('m3_get_o3_ecoloss_hcl.output')) { return(m3_get_o3_ecoloss_hcl.output) } else { + #---------------------------------------------------------------------- + #---------------------------------------------------------------------- + # Assert that the parameters of the function are okay, or modify when necessary + + if(is.null(prj_name)) assertthat::assert_that(!is.null(prj), msg = 'Specify the project name or pass an uploaded project as parameter') + + #---------------------------------------------------------------------- + #---------------------------------------------------------------------- all_years<-all_years[all_years <= final_db_year] @@ -508,7 +541,7 @@ m3_get_o3_ecoloss_hcl<-function(db_path = NULL, query_path = "./inst/extdata", d dplyr::mutate(subRegionAlt = as.factor(subRegionAlt)) # Get Mortalities - o3.mort <- m3_get_mort_o3(db_path = db_path, db_name = db_name, prj_name = prj_name, scen_name = scen_name, rdata_name = rdata_name, query_path = query_path, + o3.mort <- m3_get_mort_o3(db_path = db_path, db_name = db_name, prj_name = prj_name, prj = prj, scen_name = scen_name, rdata_name = rdata_name, query_path = query_path, queries = queries, ssp = ssp, saveOutput = F, final_db_year = final_db_year, recompute = recompute) %>% tidyr::pivot_longer(cols = c("Jerret2009", "GBD2016"), names_to = "model", diff --git a/R/m4_agriculture.R b/R/m4_agriculture.R index e17a2e6..5ad6750 100644 --- a/R/m4_agriculture.R +++ b/R/m4_agriculture.R @@ -8,6 +8,7 @@ #' @param query_path Path to the query file #' @param db_name Name of the GCAM database #' @param prj_name Name of the rgcam project. This can be an existing project, or, if not, this will be the name +#' @param prj rgcam loaded project #' @param rdata_name Name of the RData file. It must contain the queries in a list #' @param scen_name Name of the GCAM scenario to be processed #' @param queries Name of the GCAM query file. The file by default includes the queries required to run rfasst @@ -18,14 +19,21 @@ #' @param recompute If set to T, recomputes the function output. Otherwise, if the output was already computed once, it uses that value and avoids repeating computations. By default=F #' @importFrom magrittr %>% #' @export - -calc_prod_gcam<-function(db_path = NULL, query_path = "./inst/extdata", db_name = NULL, prj_name, +calc_prod_gcam<-function(db_path = NULL, query_path = "./inst/extdata", db_name = NULL, prj_name = NULL, prj = NULL, rdata_name = NULL, scen_name, queries = "queries_rfasst.xml", final_db_year = 2100, saveOutput = T, map = F, anim = T, recompute = F){ if (!recompute & exists('calc_prod_gcam.output')) { return(calc_prod_gcam.output) } else { + #---------------------------------------------------------------------- + #---------------------------------------------------------------------- + # Assert that the parameters of the function are okay, or modify when necessary + + if(is.null(prj_name)) assertthat::assert_that(!is.null(prj), msg = 'Specify the project name or pass an uploaded project as parameter') + + #---------------------------------------------------------------------- + #---------------------------------------------------------------------- all_years<-all_years[all_years <= final_db_year] @@ -46,28 +54,39 @@ calc_prod_gcam<-function(db_path = NULL, query_path = "./inst/extdata", db_name dplyr::rename(subRegion = fasst_region) %>% dplyr::mutate(subRegionAlt = as.factor(subRegionAlt)) - # Load the rgcam project: - if (!is.null(db_path) & !is.null(db_name)) { - print('creating prj') - conn <- rgcam::localDBConn(db_path, - db_name,migabble = FALSE) - prj <- rgcam::addScenario(conn, - prj_name, - scen_name, - paste0(query_path,"/",queries),clobber = F) - prj <- fill_queries(prj, db_path, db_name, prj_name, scen_name, - query_path, queries = 'queries_rfasst_nonCO2.xml') - } else if (is.null(rdata_name)){ - print('loading prj') - prj <- rgcam::loadProject(prj_name) - } else { - print('loading RData') - if (!exists('prj_rd')) { - prj_rd = get(load(rdata_name)) - QUERY_LIST <- names(prj_rd) + # Load the rgcam project if prj not passed as a parameter: + if (is.null(prj)) { + if (!is.null(db_path) & !is.null(db_name)) { + rlang::inform('Creating project ...') + conn <- rgcam::localDBConn(db_path, + db_name,migabble = FALSE) + prj <- rgcam::addScenario(conn, + prj_name, + scen_name, + paste0(query_path,"/",queries), + saveProj = F) + prj <- fill_queries(prj, db_path, db_name, prj_name, scen_name, + query_path, queries = 'queries_rfasst_nonCO2.xml') + + rgcam::saveProject(prj, file = file.path('output',prj_name)) + + QUERY_LIST <- c(rgcam::listQueries(prj, c(scen_name))) + } else if (is.null(rdata_name)){ + rlang::inform('Loading project ...') + prj <- rgcam::loadProject(prj_name) + + QUERY_LIST <- c(rgcam::listQueries(prj, c(scen_name))) + } else { + rlang::inform('Loading RData ...') + if (!exists('prj_rd')) { + prj_rd = get(load(rdata_name)) + QUERY_LIST <- names(prj_rd) + } } + } else { + QUERY_LIST <- c(rgcam::listQueries(prj, c(scen_name))) } - print('computing...') + rlang::inform('Computing ...') prod <- if_complex(is.null(rdata_name), rgcam::getQuery(prj,"ag production by subsector (land use region)"), @@ -148,6 +167,7 @@ calc_prod_gcam<-function(db_path = NULL, query_path = "./inst/extdata", db_name #' @param query_path Path to the query file #' @param db_name Name of the GCAM database #' @param prj_name Name of the rgcam project. This can be an existing project, or, if not, this will be the name +#' @param prj rgcam loaded project #' @param rdata_name Name of the RData file. It must contain the queries in a list #' @param scen_name Name of the GCAM scenario to be processed #' @param queries Name of the GCAM query file. The file by default includes the queries required to run rfasst @@ -159,13 +179,21 @@ calc_prod_gcam<-function(db_path = NULL, query_path = "./inst/extdata", db_name #' @importFrom magrittr %>% #' @export -calc_price_gcam<-function(db_path = NULL, query_path = "./inst/extdata", db_name = NULL, prj_name, +calc_price_gcam<-function(db_path = NULL, query_path = "./inst/extdata", db_name = NULL, prj_name = NULL, prj = NULL, rdata_name = NULL, scen_name, queries = "queries_rfasst.xml", final_db_year = 2100, saveOutput = T, map = F, anim = T, recompute = F){ if (!recompute & exists('calc_price_gcam.output')) { return(calc_price_gcam.output) } else { + #---------------------------------------------------------------------- + #---------------------------------------------------------------------- + # Assert that the parameters of the function are okay, or modify when necessary + + if(is.null(prj_name)) assertthat::assert_that(!is.null(prj), msg = 'Specify the project name or pass an uploaded project as parameter') + + #---------------------------------------------------------------------- + #---------------------------------------------------------------------- all_years<-all_years[all_years <= final_db_year] @@ -186,28 +214,39 @@ calc_price_gcam<-function(db_path = NULL, query_path = "./inst/extdata", db_name dplyr::rename(subRegion = fasst_region) %>% dplyr::mutate(subRegionAlt = as.factor(subRegionAlt)) - # Load the rgcam project: - if (!is.null(db_path) & !is.null(db_name)) { - print('creating prj') - conn <- rgcam::localDBConn(db_path, - db_name,migabble = FALSE) - prj <- rgcam::addScenario(conn, - prj_name, - scen_name, - paste0(query_path,"/",queries),clobber = F) - prj <- fill_queries(prj, db_path, db_name, prj_name, scen_name, - query_path, queries = 'queries_rfasst_nonCO2.xml') - } else if (is.null(rdata_name)){ - print('loading prj') - prj <- rgcam::loadProject(prj_name) - } else { - print('loading RData') - if (!exists('prj_rd')) { - prj_rd = get(load(rdata_name)) - QUERY_LIST <- names(prj_rd) + # Load the rgcam project if prj not passed as a parameter: + if (is.null(prj)) { + if (!is.null(db_path) & !is.null(db_name)) { + rlang::inform('Creating project ...') + conn <- rgcam::localDBConn(db_path, + db_name,migabble = FALSE) + prj <- rgcam::addScenario(conn, + prj_name, + scen_name, + paste0(query_path,"/",queries), + saveProj = F) + prj <- fill_queries(prj, db_path, db_name, prj_name, scen_name, + query_path, queries = 'queries_rfasst_nonCO2.xml') + + rgcam::saveProject(prj, file = file.path('output',prj_name)) + + QUERY_LIST <- c(rgcam::listQueries(prj, c(scen_name))) + } else if (is.null(rdata_name)){ + rlang::inform('Loading project ...') + prj <- rgcam::loadProject(prj_name) + + QUERY_LIST <- c(rgcam::listQueries(prj, c(scen_name))) + } else { + rlang::inform('Loading RData ...') + if (!exists('prj_rd')) { + prj_rd = get(load(rdata_name)) + QUERY_LIST <- names(prj_rd) + } } + } else { + QUERY_LIST <- c(rgcam::listQueries(prj, c(scen_name))) } - print('computing...') + rlang::inform('Computing ...') price <- if_complex(is.null(rdata_name), rgcam::getQuery(prj,"Ag Commodity Prices"), @@ -278,6 +317,7 @@ calc_price_gcam<-function(db_path = NULL, query_path = "./inst/extdata", db_name #' @param query_path Path to the query file #' @param db_name Name of the GCAM database #' @param prj_name Name of the rgcam project. This can be an existing project, or, if not, this will be the name +#' @param prj rgcam loaded project #' @param rdata_name Name of the RData file. It must contain the queries in a list #' @param scen_name Name of the GCAM scenario to be processed #' @param queries Name of the GCAM query file. The file by default includes the queries required to run rfasst @@ -289,13 +329,21 @@ calc_price_gcam<-function(db_path = NULL, query_path = "./inst/extdata", db_name #' @importFrom magrittr %>% #' @export -calc_rev_gcam<-function(db_path = NULL, query_path = "./inst/extdata", db_name = NULL, prj_name, +calc_rev_gcam<-function(db_path = NULL, query_path = "./inst/extdata", db_name = NULL, prj_name = NULL, prj = NULL, rdata_name = NULL, scen_name, queries = "queries_rfasst.xml", final_db_year = 2100, saveOutput = T, map = F, anim = T, recompute = F){ if (!recompute & exists('calc_rev_gcam.output')) { return(calc_rev_gcam.output) } else { + #---------------------------------------------------------------------- + #---------------------------------------------------------------------- + # Assert that the parameters of the function are okay, or modify when necessary + + if(is.null(prj_name)) assertthat::assert_that(!is.null(prj), msg = 'Specify the project name or pass an uploaded project as parameter') + + #---------------------------------------------------------------------- + #---------------------------------------------------------------------- all_years<-all_years[all_years <= final_db_year] @@ -319,10 +367,10 @@ calc_rev_gcam<-function(db_path = NULL, query_path = "./inst/extdata", db_name = # Get prod - prod<-calc_prod_gcam(db_path, query_path, db_name, prj_name, scen_name, queries, final_db_year = final_db_year, saveOutput = F, recompute = recompute) + prod<-calc_prod_gcam(db_path, query_path, db_name, prj_name, prj, scen_name, queries, final_db_year = final_db_year, saveOutput = F, recompute = recompute) # Get price - price<-calc_price_gcam(db_path, query_path, db_name, prj_name, scen_name, queries, final_db_year = final_db_year, saveOutput = F, recompute = recompute) + price<-calc_price_gcam(db_path, query_path, db_name, prj_name, prj, scen_name, queries, final_db_year = final_db_year, saveOutput = F, recompute = recompute) #------------------------------------------------------------------------------------ @@ -388,6 +436,7 @@ calc_rev_gcam<-function(db_path = NULL, query_path = "./inst/extdata", db_name = #' @param query_path Path to the query file #' @param db_name Name of the GCAM database #' @param prj_name Name of the rgcam project. This can be an existing project, or, if not, this will be the name +#' @param prj rgcam loaded project #' @param rdata_name Name of the RData file. It must contain the queries in a list #' @param scen_name Name of the GCAM scenario to be processed #' @param queries Name of the GCAM query file. The file by default includes the queries required to run rfasst @@ -399,7 +448,7 @@ calc_rev_gcam<-function(db_path = NULL, query_path = "./inst/extdata", db_name = #' @importFrom magrittr %>% #' @export -m4_get_ryl_aot40<-function(db_path = NULL, query_path = "./inst/extdata", db_name = NULL, prj_name, +m4_get_ryl_aot40<-function(db_path = NULL, query_path = "./inst/extdata", db_name = NULL, prj_name = NULL, prj = NULL, rdata_name = NULL, scen_name, queries = "queries_rfasst.xml", final_db_year = 2100, saveOutput = T, map = F, anim = T, recompute = F){ @@ -407,6 +456,14 @@ m4_get_ryl_aot40<-function(db_path = NULL, query_path = "./inst/extdata", db_nam if (!recompute & exists('m4_get_ryl_aot40.output')) { return(m4_get_ryl_aot40.output) } else { + #---------------------------------------------------------------------- + #---------------------------------------------------------------------- + # Assert that the parameters of the function are okay, or modify when necessary + + if(is.null(prj_name)) assertthat::assert_that(!is.null(prj), msg = 'Specify the project name or pass an uploaded project as parameter') + + #---------------------------------------------------------------------- + #---------------------------------------------------------------------- all_years<-all_years[all_years <= final_db_year] @@ -430,7 +487,7 @@ m4_get_ryl_aot40<-function(db_path = NULL, query_path = "./inst/extdata", db_nam dplyr::rename(subRegion=fasst_region) %>% dplyr::mutate(subRegionAlt=as.factor(subRegionAlt)) - aot40<-m2_get_conc_aot40(db_path, query_path, db_name, prj_name, rdata_name, scen_name, queries, final_db_year = final_db_year, saveOutput = F, recompute = recompute) + aot40<-m2_get_conc_aot40(db_path, query_path, db_name, prj_name, prj, rdata_name, scen_name, queries, final_db_year = final_db_year, saveOutput = F, recompute = recompute) rlang::inform('Computing relative yield losses with AOT40 method ...') @@ -518,6 +575,7 @@ m4_get_ryl_aot40<-function(db_path = NULL, query_path = "./inst/extdata", db_nam #' @param query_path Path to the query file #' @param db_name Name of the GCAM database #' @param prj_name Name of the rgcam project. This can be an existing project, or, if not, this will be the name +#' @param prj rgcam loaded project #' @param rdata_name Name of the RData file. It must contain the queries in a list #' @param scen_name Name of the GCAM scenario to be processed #' @param queries Name of the GCAM query file. The file by default includes the queries required to run rfasst @@ -529,13 +587,21 @@ m4_get_ryl_aot40<-function(db_path = NULL, query_path = "./inst/extdata", db_nam #' @importFrom magrittr %>% #' @export -m4_get_ryl_mi<-function(db_path = NULL, query_path = "./inst/extdata", db_name = NULL, prj_name, +m4_get_ryl_mi<-function(db_path = NULL, query_path = "./inst/extdata", db_name = NULL, prj_name = NULL, prj = NULL, rdata_name = NULL, scen_name, queries = "queries_rfasst.xml", final_db_year = 2100, saveOutput = T, map = F, anim = T, recompute = F){ if (!recompute & exists('m4_get_ryl_mi.output')) { return(m4_get_ryl_mi.output) } else { + #---------------------------------------------------------------------- + #---------------------------------------------------------------------- + # Assert that the parameters of the function are okay, or modify when necessary + + if(is.null(prj_name)) assertthat::assert_that(!is.null(prj), msg = 'Specify the project name or pass an uploaded project as parameter') + + #---------------------------------------------------------------------- + #---------------------------------------------------------------------- all_years<-all_years[all_years <= final_db_year] @@ -559,7 +625,7 @@ m4_get_ryl_mi<-function(db_path = NULL, query_path = "./inst/extdata", db_name = dplyr::rename(subRegion = fasst_region) %>% dplyr::mutate(subRegionAlt = as.factor(subRegionAlt)) - mi<-m2_get_conc_mi(db_path, query_path, db_name, prj_name, rdata_name, scen_name, queries, final_db_year = final_db_year, saveOutput = F, recompute = recompute) + mi<-m2_get_conc_mi(db_path, query_path, db_name, prj_name, prj, rdata_name, scen_name, queries, final_db_year = final_db_year, saveOutput = F, recompute = recompute) rlang::inform('Computing relative yield losses with Mi method ...') @@ -646,6 +712,7 @@ m4_get_ryl_mi<-function(db_path = NULL, query_path = "./inst/extdata", db_name = #' @param query_path Path to the query file #' @param db_name Name of the GCAM database #' @param prj_name Name of the rgcam project. This can be an existing project, or, if not, this will be the name +#' @param prj rgcam loaded project #' @param rdata_name Name of the RData file. It must contain the queries in a list #' @param scen_name Name of the GCAM scenario to be processed #' @param queries Name of the GCAM query file. The file by default includes the queries required to run rfasst @@ -657,13 +724,21 @@ m4_get_ryl_mi<-function(db_path = NULL, query_path = "./inst/extdata", db_name = #' @importFrom magrittr %>% #' @export -m4_get_prod_loss<-function(db_path = NULL, query_path = "./inst/extdata", db_name = NULL, prj_name, +m4_get_prod_loss<-function(db_path = NULL, query_path = "./inst/extdata", db_name = NULL, prj_name = NULL, prj = NULL, rdata_name = NULL, scen_name, queries = "queries_rfasst.xml", final_db_year = 2100, saveOutput = T, map = F, anim = T, recompute = F){ if (!recompute & exists('m4_get_prod_loss.output')) { return(m4_get_prod_loss.output) } else { + #---------------------------------------------------------------------- + #---------------------------------------------------------------------- + # Assert that the parameters of the function are okay, or modify when necessary + + if(is.null(prj_name)) assertthat::assert_that(!is.null(prj), msg = 'Specify the project name or pass an uploaded project as parameter') + + #---------------------------------------------------------------------- + #---------------------------------------------------------------------- all_years<-all_years[all_years <= final_db_year] @@ -688,13 +763,13 @@ m4_get_prod_loss<-function(db_path = NULL, query_path = "./inst/extdata", db_nam dplyr::mutate(subRegionAlt = as.factor(subRegionAlt)) # Get AOT40 RYLs - ryl.aot.40.fin<-m4_get_ryl_aot40(db_path, query_path, db_name, prj_name, scen_name, queries, final_db_year = final_db_year, saveOutput = F, recompute = recompute) + ryl.aot.40.fin<-m4_get_ryl_aot40(db_path, query_path, db_name, prj_name, prj, scen_name, queries, final_db_year = final_db_year, saveOutput = F, recompute = recompute) # Get Mi RYLs - ryl.mi.fin<-m4_get_ryl_mi(db_path, query_path, db_name, prj_name, scen_name, queries, final_db_year = final_db_year, saveOutput = F, recompute = recompute) + ryl.mi.fin<-m4_get_ryl_mi(db_path, query_path, db_name, prj_name, prj, scen_name, queries, final_db_year = final_db_year, saveOutput = F, recompute = recompute) # Get Prod - prod<-calc_prod_gcam(db_path, query_path, db_name, prj_name, scen_name, queries, final_db_year = final_db_year, saveOutput = F, recompute = recompute) + prod<-calc_prod_gcam(db_path, query_path, db_name, prj_name, prj, scen_name, queries, final_db_year = final_db_year, saveOutput = F, recompute = recompute) rlang::inform('Computing agricultural production losses ...') @@ -869,6 +944,7 @@ m4_get_prod_loss<-function(db_path = NULL, query_path = "./inst/extdata", db_nam #' @param query_path Path to the query file #' @param db_name Name of the GCAM database #' @param prj_name Name of the rgcam project. This can be an existing project, or, if not, this will be the name +#' @param prj rgcam loaded project #' @param rdata_name Name of the RData file. It must contain the queries in a list #' @param scen_name Name of the GCAM scenario to be processed #' @param queries Name of the GCAM query file. The file by default includes the queries required to run rfasst @@ -880,13 +956,21 @@ m4_get_prod_loss<-function(db_path = NULL, query_path = "./inst/extdata", db_nam #' @importFrom magrittr %>% #' @export -m4_get_rev_loss<-function(db_path = NULL, query_path = "./inst/extdata", db_name = NULL, prj_name, +m4_get_rev_loss<-function(db_path = NULL, query_path = "./inst/extdata", db_name = NULL, prj_name = NULL, prj = NULL, rdata_name = NULL, scen_name, queries = "queries_rfasst.xml", final_db_year = 2100, saveOutput = T, map = F, anim = T, recompute = F){ if (!recompute & exists('m4_get_rev_loss.output')) { return(m4_get_rev_loss.output) } else { + #---------------------------------------------------------------------- + #---------------------------------------------------------------------- + # Assert that the parameters of the function are okay, or modify when necessary + + if(is.null(prj_name)) assertthat::assert_that(!is.null(prj), msg = 'Specify the project name or pass an uploaded project as parameter') + + #---------------------------------------------------------------------- + #---------------------------------------------------------------------- all_years<-all_years[all_years <= final_db_year] @@ -911,13 +995,13 @@ m4_get_rev_loss<-function(db_path = NULL, query_path = "./inst/extdata", db_name dplyr::mutate(subRegionAlt = as.factor(subRegionAlt)) # Get AOT40 RYLs - ryl.aot.40.fin<-m4_get_ryl_aot40(db_path, query_path, db_name, prj_name, scen_name, queries, final_db_year = final_db_year, saveOutput = F, recompute = recompute) + ryl.aot.40.fin<-m4_get_ryl_aot40(db_path, query_path, db_name, prj_name, prj, scen_name, queries, final_db_year = final_db_year, saveOutput = F, recompute = recompute) # Get Mi RYLs - ryl.mi.fin<-m4_get_ryl_mi(db_path, query_path, db_name, prj_name, scen_name, queries, final_db_year = final_db_year, saveOutput = F, recompute = recompute) + ryl.mi.fin<-m4_get_ryl_mi(db_path, query_path, db_name, prj_name, prj, scen_name, queries, final_db_year = final_db_year, saveOutput = F, recompute = recompute) # Get Revenue: re-calculate to consider C4 categories - prod<-calc_prod_gcam(db_path, query_path, db_name, prj_name, scen_name, queries, final_db_year = final_db_year, saveOutput = F, recompute = recompute) + prod<-calc_prod_gcam(db_path, query_path, db_name, prj_name, prj, scen_name, queries, final_db_year = final_db_year, saveOutput = F, recompute = recompute) rlang::inform('Computing agricultural revenue losses ...') diff --git a/man/calc_price_gcam.Rd b/man/calc_price_gcam.Rd index 221c027..556a1d6 100644 --- a/man/calc_price_gcam.Rd +++ b/man/calc_price_gcam.Rd @@ -11,7 +11,8 @@ calc_price_gcam( db_path = NULL, query_path = "./inst/extdata", db_name = NULL, - prj_name, + prj_name = NULL, + prj = NULL, rdata_name = NULL, scen_name, queries = "queries_rfasst.xml", @@ -31,6 +32,8 @@ calc_price_gcam( \item{prj_name}{Name of the rgcam project. This can be an existing project, or, if not, this will be the name} +\item{prj}{rgcam loaded project} + \item{rdata_name}{Name of the RData file. It must contain the queries in a list} \item{scen_name}{Name of the GCAM scenario to be processed} diff --git a/man/calc_prod_gcam.Rd b/man/calc_prod_gcam.Rd index f614177..b89c1da 100644 --- a/man/calc_prod_gcam.Rd +++ b/man/calc_prod_gcam.Rd @@ -11,7 +11,8 @@ calc_prod_gcam( db_path = NULL, query_path = "./inst/extdata", db_name = NULL, - prj_name, + prj_name = NULL, + prj = NULL, rdata_name = NULL, scen_name, queries = "queries_rfasst.xml", @@ -31,6 +32,8 @@ calc_prod_gcam( \item{prj_name}{Name of the rgcam project. This can be an existing project, or, if not, this will be the name} +\item{prj}{rgcam loaded project} + \item{rdata_name}{Name of the RData file. It must contain the queries in a list} \item{scen_name}{Name of the GCAM scenario to be processed} diff --git a/man/calc_rev_gcam.Rd b/man/calc_rev_gcam.Rd index 5034395..192e985 100644 --- a/man/calc_rev_gcam.Rd +++ b/man/calc_rev_gcam.Rd @@ -11,7 +11,8 @@ calc_rev_gcam( db_path = NULL, query_path = "./inst/extdata", db_name = NULL, - prj_name, + prj_name = NULL, + prj = NULL, rdata_name = NULL, scen_name, queries = "queries_rfasst.xml", @@ -31,6 +32,8 @@ calc_rev_gcam( \item{prj_name}{Name of the rgcam project. This can be an existing project, or, if not, this will be the name} +\item{prj}{rgcam loaded project} + \item{rdata_name}{Name of the RData file. It must contain the queries in a list} \item{scen_name}{Name of the GCAM scenario to be processed} diff --git a/man/m1_emissions_rescale.Rd b/man/m1_emissions_rescale.Rd index b9233b7..70eb71b 100644 --- a/man/m1_emissions_rescale.Rd +++ b/man/m1_emissions_rescale.Rd @@ -8,7 +8,8 @@ m1_emissions_rescale( db_path = NULL, query_path = "./inst/extdata", db_name = NULL, - prj_name, + prj_name = NULL, + prj = NULL, rdata_name = NULL, scen_name, queries = "queries_rfasst.xml", @@ -29,6 +30,8 @@ m1_emissions_rescale( \item{prj_name}{Name of the rgcam project. This can be an existing project, or, if not, this will be the name} +\item{prj}{rgcam loaded project} + \item{rdata_name}{Name of the RData file. It must contain the queries in a list} \item{scen_name}{Name of the GCAM scenario to be processed} diff --git a/man/m2_get_conc_aot40.Rd b/man/m2_get_conc_aot40.Rd index d7e6bc9..6c247fd 100644 --- a/man/m2_get_conc_aot40.Rd +++ b/man/m2_get_conc_aot40.Rd @@ -8,7 +8,8 @@ m2_get_conc_aot40( db_path = NULL, query_path = "./inst/extdata", db_name = NULL, - prj_name, + prj_name = NULL, + prj = NULL, rdata_name = NULL, scen_name, queries = "queries_rfasst.xml", @@ -28,6 +29,8 @@ m2_get_conc_aot40( \item{prj_name}{Name of the rgcam project. This can be an existing project, or, if not, this will be the name} +\item{prj}{rgcam loaded project} + \item{rdata_name}{Name of the RData file. It must contain the queries in a list} \item{scen_name}{Name of the GCAM scenario to be processed} diff --git a/man/m2_get_conc_m6m.Rd b/man/m2_get_conc_m6m.Rd index ceb466d..a3352da 100644 --- a/man/m2_get_conc_m6m.Rd +++ b/man/m2_get_conc_m6m.Rd @@ -8,7 +8,8 @@ m2_get_conc_m6m( db_path = NULL, query_path = "./inst/extdata", db_name = NULL, - prj_name, + prj_name = NULL, + prj = NULL, rdata_name = NULL, scen_name, queries = "queries_rfasst.xml", @@ -28,6 +29,8 @@ m2_get_conc_m6m( \item{prj_name}{Name of the rgcam project. This can be an existing project, or, if not, this will be the name} +\item{prj}{rgcam loaded project} + \item{rdata_name}{Name of the RData file. It must contain the queries in a list} \item{scen_name}{Name of the GCAM scenario to be processed} diff --git a/man/m2_get_conc_mi.Rd b/man/m2_get_conc_mi.Rd index a55a663..cb21b6d 100644 --- a/man/m2_get_conc_mi.Rd +++ b/man/m2_get_conc_mi.Rd @@ -8,7 +8,8 @@ m2_get_conc_mi( db_path = NULL, query_path = "./inst/extdata", db_name = NULL, - prj_name, + prj_name = NULL, + prj = NULL, rdata_name = NULL, scen_name, queries = "queries_rfasst.xml", @@ -28,6 +29,8 @@ m2_get_conc_mi( \item{prj_name}{Name of the rgcam project. This can be an existing project, or, if not, this will be the name} +\item{prj}{rgcam loaded project} + \item{rdata_name}{Name of the RData file. It must contain the queries in a list} \item{scen_name}{Name of the GCAM scenario to be processed} diff --git a/man/m2_get_conc_o3.Rd b/man/m2_get_conc_o3.Rd index 94b3dc5..0bd19a0 100644 --- a/man/m2_get_conc_o3.Rd +++ b/man/m2_get_conc_o3.Rd @@ -8,7 +8,8 @@ m2_get_conc_o3( db_path = NULL, query_path = "./inst/extdata", db_name = NULL, - prj_name, + prj_name = NULL, + prj = NULL, rdata_name = NULL, scen_name, queries = "queries_rfasst.xml", @@ -29,6 +30,8 @@ m2_get_conc_o3( \item{prj_name}{Name of the rgcam project. This can be an existing project, or, if not, this will be the name} +\item{prj}{rgcam loaded project} + \item{rdata_name}{Name of the RData file. It must contain the queries in a list} \item{scen_name}{Name of the GCAM scenario to be processed} diff --git a/man/m2_get_conc_pm25.Rd b/man/m2_get_conc_pm25.Rd index ca710a8..f57ae8b 100644 --- a/man/m2_get_conc_pm25.Rd +++ b/man/m2_get_conc_pm25.Rd @@ -8,7 +8,8 @@ m2_get_conc_pm25( db_path = NULL, query_path = "./inst/extdata", db_name = NULL, - prj_name, + prj_name = NULL, + prj = NULL, rdata_name = NULL, scen_name, queries = "queries_rfasst.xml", @@ -32,6 +33,8 @@ m2_get_conc_pm25( \item{prj_name}{Name of the rgcam project. This can be an existing project, or, if not, this will be the name} +\item{prj}{rgcam loaded project} + \item{rdata_name}{Name of the RData file. It must contain the queries in a list} \item{scen_name}{Name of the GCAM scenario to be processed} diff --git a/man/m3_get_daly_o3.Rd b/man/m3_get_daly_o3.Rd index 174bd9d..8a3a0e1 100644 --- a/man/m3_get_daly_o3.Rd +++ b/man/m3_get_daly_o3.Rd @@ -11,11 +11,13 @@ m3_get_daly_o3( db_path = NULL, query_path = "./inst/extdata", db_name = NULL, - prj_name, + prj_name = NULL, + prj = NULL, rdata_name = NULL, scen_name, queries = "queries_rfasst.xml", final_db_year = 2100, + mort_param = "mort_o3_gbd2016_med", ssp = "SSP2", saveOutput = T, map = F, @@ -32,6 +34,8 @@ m3_get_daly_o3( \item{prj_name}{Name of the rgcam project. This can be an existing project, or, if not, this will be the name} +\item{prj}{rgcam loaded project} + \item{rdata_name}{Name of the RData file. It must contain the queries in a list} \item{scen_name}{Name of the GCAM scenario to be processed} diff --git a/man/m3_get_daly_pm25.Rd b/man/m3_get_daly_pm25.Rd index 6ad6426..916b67b 100644 --- a/man/m3_get_daly_pm25.Rd +++ b/man/m3_get_daly_pm25.Rd @@ -11,11 +11,13 @@ m3_get_daly_pm25( db_path = NULL, query_path = "./inst/extdata", db_name = NULL, - prj_name, + prj_name = NULL, + prj = NULL, rdata_name = NULL, scen_name, queries = "queries_rfasst.xml", final_db_year = 2100, + mort_param = "GBD2016_medium", ssp = "SSP2", saveOutput = T, map = F, @@ -32,6 +34,8 @@ m3_get_daly_pm25( \item{prj_name}{Name of the rgcam project. This can be an existing project, or, if not, this will be the name} +\item{prj}{rgcam loaded project} + \item{rdata_name}{Name of the RData file. It must contain the queries in a list} \item{scen_name}{Name of the GCAM scenario to be processed} diff --git a/man/m3_get_mort_o3.Rd b/man/m3_get_mort_o3.Rd index c9117c3..9a3568c 100644 --- a/man/m3_get_mort_o3.Rd +++ b/man/m3_get_mort_o3.Rd @@ -11,7 +11,8 @@ m3_get_mort_o3( db_path = NULL, query_path = "./inst/extdata", db_name = NULL, - prj_name, + prj_name = NULL, + prj = NULL, rdata_name = NULL, scen_name, queries = "queries_rfasst.xml", @@ -32,6 +33,8 @@ m3_get_mort_o3( \item{prj_name}{Name of the rgcam project. This can be an existing project, or, if not, this will be the name} +\item{prj}{rgcam loaded project} + \item{rdata_name}{Name of the RData file. It must contain the queries in a list} \item{scen_name}{Name of the GCAM scenario to be processed} diff --git a/man/m3_get_mort_pm25.Rd b/man/m3_get_mort_pm25.Rd index b4cb8b3..5ecbd33 100644 --- a/man/m3_get_mort_pm25.Rd +++ b/man/m3_get_mort_pm25.Rd @@ -11,7 +11,8 @@ m3_get_mort_pm25( db_path = NULL, query_path = "./inst/extdata", db_name = NULL, - prj_name, + prj_name = NULL, + prj = NULL, rdata_name = NULL, scen_name, queries = "queries_rfasst.xml", @@ -32,6 +33,8 @@ m3_get_mort_pm25( \item{prj_name}{Name of the rgcam project. This can be an existing project, or, if not, this will be the name} +\item{prj}{rgcam loaded project} + \item{rdata_name}{Name of the RData file. It must contain the queries in a list} \item{scen_name}{Name of the GCAM scenario to be processed} diff --git a/man/m3_get_pm25_ecoloss_vsl.Rd b/man/m3_get_mort_pm25_ecoloss.Rd similarity index 95% rename from man/m3_get_pm25_ecoloss_vsl.Rd rename to man/m3_get_mort_pm25_ecoloss.Rd index 6df384e..9d11410 100644 --- a/man/m3_get_pm25_ecoloss_vsl.Rd +++ b/man/m3_get_mort_pm25_ecoloss.Rd @@ -1,17 +1,18 @@ % Generated by roxygen2: do not edit by hand % Please edit documentation in R/m3b_health_ecoloss.R -\name{m3_get_pm25_ecoloss_vsl} -\alias{m3_get_pm25_ecoloss_vsl} +\name{m3_get_mort_pm25_ecoloss} +\alias{m3_get_mort_pm25_ecoloss} \title{m3_get_pm25_ecoloss_vsl} \source{ Narain, U. and Sall, C., 2016. Methodology for Valuing the Health Impacts of Air Pollution//// Markandya, A., Sampedro, J., Smith, S.J., Van Dingenen, R., Pizarro-Irizar, C., Arto, I. and González-Eguino, M., 2018. Health co-benefits from air pollution and mitigation costs of the Paris Agreement: a modelling study. The Lancet Planetary Health, 2(3), pp.e126-e133. } \usage{ -m3_get_pm25_ecoloss_vsl( +m3_get_mort_pm25_ecoloss( db_path = NULL, query_path = "./inst/extdata", db_name = NULL, - prj_name, + prj_name = NULL, + prj = NULL, rdata_name = NULL, scen_name, ssp = "SSP2", @@ -35,6 +36,8 @@ m3_get_pm25_ecoloss_vsl( \item{prj_name}{Name of the rgcam project. This can be an existing project, or, if not, this will be the name} +\item{prj}{rgcam loaded project} + \item{rdata_name}{Name of the RData file. It must contain the queries in a list} \item{scen_name}{Name of the GCAM scenario to be processed} diff --git a/man/m3_get_o3_ecoloss_hcl.Rd b/man/m3_get_o3_ecoloss_hcl.Rd index b5a1ec3..659a8d6 100644 --- a/man/m3_get_o3_ecoloss_hcl.Rd +++ b/man/m3_get_o3_ecoloss_hcl.Rd @@ -11,7 +11,8 @@ m3_get_o3_ecoloss_hcl( db_path = NULL, query_path = "./inst/extdata", db_name = NULL, - prj_name, + prj_name = NULL, + prj = NULL, rdata_name = NULL, scen_name, ssp = "SSP2", @@ -35,6 +36,8 @@ m3_get_o3_ecoloss_hcl( \item{prj_name}{Name of the rgcam project. This can be an existing project, or, if not, this will be the name} +\item{prj}{rgcam loaded project} + \item{rdata_name}{Name of the RData file. It must contain the queries in a list} \item{scen_name}{Name of the GCAM scenario to be processed} diff --git a/man/m3_get_o3_ecoloss_vsl.Rd b/man/m3_get_o3_ecoloss_vsl.Rd index 08dba9d..3f47bbc 100644 --- a/man/m3_get_o3_ecoloss_vsl.Rd +++ b/man/m3_get_o3_ecoloss_vsl.Rd @@ -11,7 +11,8 @@ m3_get_o3_ecoloss_vsl( db_path = NULL, query_path = "./inst/extdata", db_name = NULL, - prj_name, + prj_name = NULL, + prj = NULL, rdata_name = NULL, scen_name, ssp = "SSP2", @@ -35,6 +36,8 @@ m3_get_o3_ecoloss_vsl( \item{prj_name}{Name of the rgcam project. This can be an existing project, or, if not, this will be the name} +\item{prj}{rgcam loaded project} + \item{rdata_name}{Name of the RData file. It must contain the queries in a list} \item{scen_name}{Name of the GCAM scenario to be processed} diff --git a/man/m3_get_pm25_ecoloss_hcl.Rd b/man/m3_get_pm25_ecoloss_hcl.Rd index fab9a07..2e59833 100644 --- a/man/m3_get_pm25_ecoloss_hcl.Rd +++ b/man/m3_get_pm25_ecoloss_hcl.Rd @@ -11,7 +11,8 @@ m3_get_pm25_ecoloss_hcl( db_path = NULL, query_path = "./inst/extdata", db_name = NULL, - prj_name, + prj_name = NULL, + prj = NULL, rdata_name = NULL, scen_name, ssp = "SSP2", @@ -35,6 +36,8 @@ m3_get_pm25_ecoloss_hcl( \item{prj_name}{Name of the rgcam project. This can be an existing project, or, if not, this will be the name} +\item{prj}{rgcam loaded project} + \item{rdata_name}{Name of the RData file. It must contain the queries in a list} \item{scen_name}{Name of the GCAM scenario to be processed} diff --git a/man/m3_get_yll_o3.Rd b/man/m3_get_yll_o3.Rd index 379c6fd..ea3a085 100644 --- a/man/m3_get_yll_o3.Rd +++ b/man/m3_get_yll_o3.Rd @@ -8,7 +8,8 @@ m3_get_yll_o3( db_path = NULL, query_path = "./inst/extdata", db_name = NULL, - prj_name, + prj_name = NULL, + prj = NULL, rdata_name = NULL, scen_name, queries = "queries_rfasst.xml", @@ -30,6 +31,8 @@ m3_get_yll_o3( \item{prj_name}{Name of the rgcam project. This can be an existing project, or, if not, this will be the name} +\item{prj}{rgcam loaded project} + \item{rdata_name}{Name of the RData file. It must contain the queries in a list} \item{scen_name}{Name of the GCAM scenario to be processed} diff --git a/man/m3_get_yll_pm25.Rd b/man/m3_get_yll_pm25.Rd index d08a18b..5b644cd 100644 --- a/man/m3_get_yll_pm25.Rd +++ b/man/m3_get_yll_pm25.Rd @@ -8,11 +8,13 @@ m3_get_yll_pm25( db_path = NULL, query_path = "./inst/extdata", db_name = NULL, - prj_name, + prj_name = NULL, + prj = NULL, rdata_name = NULL, scen_name, queries = "queries_rfasst.xml", final_db_year = 2100, + mort_param = "GBD", ssp = "SSP2", saveOutput = T, map = F, @@ -29,6 +31,8 @@ m3_get_yll_pm25( \item{prj_name}{Name of the rgcam project. This can be an existing project, or, if not, this will be the name} +\item{prj}{rgcam loaded project} + \item{rdata_name}{Name of the RData file. It must contain the queries in a list} \item{scen_name}{Name of the GCAM scenario to be processed} diff --git a/man/m4_get_prod_loss.Rd b/man/m4_get_prod_loss.Rd index 151e44e..f199449 100644 --- a/man/m4_get_prod_loss.Rd +++ b/man/m4_get_prod_loss.Rd @@ -8,7 +8,8 @@ m4_get_prod_loss( db_path = NULL, query_path = "./inst/extdata", db_name = NULL, - prj_name, + prj_name = NULL, + prj = NULL, rdata_name = NULL, scen_name, queries = "queries_rfasst.xml", @@ -28,6 +29,8 @@ m4_get_prod_loss( \item{prj_name}{Name of the rgcam project. This can be an existing project, or, if not, this will be the name} +\item{prj}{rgcam loaded project} + \item{rdata_name}{Name of the RData file. It must contain the queries in a list} \item{scen_name}{Name of the GCAM scenario to be processed} diff --git a/man/m4_get_rev_loss.Rd b/man/m4_get_rev_loss.Rd index a09f7ec..cd1aa8f 100644 --- a/man/m4_get_rev_loss.Rd +++ b/man/m4_get_rev_loss.Rd @@ -8,7 +8,8 @@ m4_get_rev_loss( db_path = NULL, query_path = "./inst/extdata", db_name = NULL, - prj_name, + prj_name = NULL, + prj = NULL, rdata_name = NULL, scen_name, queries = "queries_rfasst.xml", @@ -28,6 +29,8 @@ m4_get_rev_loss( \item{prj_name}{Name of the rgcam project. This can be an existing project, or, if not, this will be the name} +\item{prj}{rgcam loaded project} + \item{rdata_name}{Name of the RData file. It must contain the queries in a list} \item{scen_name}{Name of the GCAM scenario to be processed} diff --git a/man/m4_get_ryl_aot40.Rd b/man/m4_get_ryl_aot40.Rd index f7800b2..7100fb9 100644 --- a/man/m4_get_ryl_aot40.Rd +++ b/man/m4_get_ryl_aot40.Rd @@ -8,7 +8,8 @@ m4_get_ryl_aot40( db_path = NULL, query_path = "./inst/extdata", db_name = NULL, - prj_name, + prj_name = NULL, + prj = NULL, rdata_name = NULL, scen_name, queries = "queries_rfasst.xml", @@ -28,6 +29,8 @@ m4_get_ryl_aot40( \item{prj_name}{Name of the rgcam project. This can be an existing project, or, if not, this will be the name} +\item{prj}{rgcam loaded project} + \item{rdata_name}{Name of the RData file. It must contain the queries in a list} \item{scen_name}{Name of the GCAM scenario to be processed} diff --git a/man/m4_get_ryl_mi.Rd b/man/m4_get_ryl_mi.Rd index 320e29c..828654c 100644 --- a/man/m4_get_ryl_mi.Rd +++ b/man/m4_get_ryl_mi.Rd @@ -8,7 +8,8 @@ m4_get_ryl_mi( db_path = NULL, query_path = "./inst/extdata", db_name = NULL, - prj_name, + prj_name = NULL, + prj = NULL, rdata_name = NULL, scen_name, queries = "queries_rfasst.xml", @@ -28,6 +29,8 @@ m4_get_ryl_mi( \item{prj_name}{Name of the rgcam project. This can be an existing project, or, if not, this will be the name} +\item{prj}{rgcam loaded project} + \item{rdata_name}{Name of the RData file. It must contain the queries in a list} \item{scen_name}{Name of the GCAM scenario to be processed}