diff --git a/.buildlibrary b/.buildlibrary index dd99c2ba..93eb8903 100644 --- a/.buildlibrary +++ b/.buildlibrary @@ -1,4 +1,4 @@ -ValidationKey: '346207720' +ValidationKey: '37758420' AcceptedWarnings: - 'Warning: package ''.*'' was built under R version' - 'Warning: namespace ''.*'' is not available and has been replaced' @@ -9,6 +9,8 @@ AcceptedWarnings: AcceptedNotes: - unable to verify current time - Imports includes .* non-default packages. +- installed size is +- 'Undefined global functions or variables:' AutocreateReadme: yes allowLinterWarnings: yes enforceVersionUpdate: yes diff --git a/.github/workflows/check.yaml b/.github/workflows/check.yaml index 46f518a2..f6ea5d40 100644 --- a/.github/workflows/check.yaml +++ b/.github/workflows/check.yaml @@ -11,7 +11,7 @@ jobs: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - uses: r-lib/actions/setup-pandoc@v2 @@ -23,7 +23,6 @@ jobs: - uses: r-lib/actions/setup-r-dependencies@v2 with: extra-packages: | - gamstransfer=?ignore any::lucode2 any::covr any::madrat @@ -36,7 +35,7 @@ jobs: # gms, goxygen, GDPuc) will usually have an outdated binary version # available; by using extra-packages we get the newest version - - uses: actions/setup-python@v4 + - uses: actions/setup-python@v5 with: python-version: 3.9 diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 243f46a1..7ccf77e0 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -3,7 +3,7 @@ exclude: '^tests/testthat/_snaps/.*$' repos: - repo: https://github.com/pre-commit/pre-commit-hooks - rev: v4.5.0 + rev: 2c9f875913ee60ca25ce70243dc24d5b6415598c # frozen: v4.6.0 hooks: - id: check-case-conflict - id: check-json @@ -15,7 +15,7 @@ repos: - id: mixed-line-ending - repo: https://github.com/lorenzwalthert/precommit - rev: v0.4.0 + rev: bae853d82da476eee0e0a57960ee6b741a3b3fb7 # frozen: v0.4.3 hooks: - id: parsable-R - id: deps-in-desc diff --git a/CITATION.cff b/CITATION.cff index e189badd..a141e3ee 100644 --- a/CITATION.cff +++ b/CITATION.cff @@ -2,8 +2,8 @@ cff-version: 1.2.0 message: If you use this software, please cite it using the metadata from this file. type: software title: 'mrremind: MadRat REMIND Input Data Package' -version: 0.175.10 -date-released: '2024-02-19' +version: 0.189.0 +date-released: '2024-09-12' abstract: The mrremind packages contains data preprocessing for the REMIND model. authors: - family-names: Baumstark @@ -61,6 +61,8 @@ authors: given-names: Sophie - family-names: Mandaroux given-names: Rahel +- family-names: Koch + given-names: Johannes license: LGPL-3.0 repository-code: https://github.com/pik-piam/mrremind diff --git a/DESCRIPTION b/DESCRIPTION index 299b4044..b78649b9 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,8 +1,8 @@ Type: Package Package: mrremind Title: MadRat REMIND Input Data Package -Version: 0.175.10 -Date: 2024-02-19 +Version: 0.189.0 +Date: 2024-09-12 Authors@R: c( person("Lavinia", "Baumstark", , "lavinia@pik-potsdam.de", role = c("aut", "cre")), person("Renato", "Rodrigues", role = "aut"), @@ -30,22 +30,22 @@ Authors@R: c( person("Oliver", "Richters", role = "aut"), person("Robin", "Hasse", role = "aut"), person("Sophie", "Fuchs", role = "aut"), - person("Rahel", "Mandaroux", role = "aut") + person("Rahel", "Mandaroux", role = "aut"), + person("Johannes", "Koch", role = "aut") ) Description: The mrremind packages contains data preprocessing for the REMIND model. License: LGPL-3 | file LICENSE URL: https://github.com/pik-piam/mrremind Depends: - edgeTransport (>= 0.17.0), + edgeTransport (>= 1.5.5), madrat (>= 3.7.1), - magclass (>= 6.11.3), + magclass (>= 6.16.1), mrcommons (>= 1.38.0), - mrdrivers (>= 1.0.0), + mrdrivers (>= 2.0.0), R (>= 2.10.0) Imports: assertr, - assertthat, broom, car, countrycode, @@ -55,16 +55,13 @@ Imports: Hmisc, luscale, magrittr, - mgsub, nnls, - plyr, purrr, quitte (>= 0.3105.0), R.utils, readODS, readr, readxl, - reshape, reshape2, rlang, rmndt, @@ -81,4 +78,4 @@ VignetteBuilder: knitr Encoding: UTF-8 LazyData: no -RoxygenNote: 7.3.1 +RoxygenNote: 7.3.2 diff --git a/NAMESPACE b/NAMESPACE index 1c41dfed..5aeaf634 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -2,6 +2,7 @@ export(calcAGEB) export(calcBP) +export(calcCCScapacity) export(calcCement) export(calcCementShare) export(calcChemicalFeedstocksShare) @@ -10,17 +11,20 @@ export(calcEDGAR7Fgases) export(calcEEAGHGProjections) export(calcEmber) export(calcEmissionFactorsFeedstocks) +export(calcExpertGuess) export(calcFloorspace) export(calcGlobalEnergyMonitor) export(calcHRE) export(calcIEA_ETP) export(calcIEA_EVOutlook) -export(calcIEA_WEO_2021) +export(calcIEA_WorldEnergyOutlook) +export(calcIndustry_CCS_limits) export(calcIndustry_EEK) export(calcIndustry_Value_Added) export(calcODYM_RECC) export(calcOtherFossilInElectricity) export(calcPlasticsEoL) +export(calcProjectPipelines) export(calcShareIndFE) export(calcSteelStock) export(calcSteel_Projections) @@ -30,26 +34,31 @@ export(calcUNIDO) export(calcindustry_max_secondary_steel_share) export(calcindustry_specific_FE_limits) export(calcindustry_subsectors_specific) -export(calcpm_delta_kap_industry) export(convertADVANCE_WP2) export(convertAGEB) export(convertEDGAR7Fgases) export(convertEmber) +export(convertGlobalCCSinstitute) export(convertGlobalEnergyMonitor) export(convertHRE) +export(convertIEA_CCUS) export(convertMueller) export(convertUBA) export(convertUNFCCC) export(convertUNIDO) export(convertUSGS) +export(exportThresholds) export(filter_historical_mif) export(readADVANCE_WP2) export(readAGEB) export(readAR6GWP) export(readEDGAR7Fgases) export(readEmber) +export(readGlobalCCSinstitute) export(readGlobalEnergyMonitor) export(readHRE) +export(readIEA_CCUS) +export(readIEA_HSMR) export(readIEA_WEIO_2014) export(readMueller) export(readODYM_RECC) @@ -73,29 +82,18 @@ import(madrat) import(magclass) import(mrcommons) import(mrdrivers) -importFrom(Hmisc,wtd.quantile) -importFrom(R.utils,isZero) importFrom(assertr,assert) importFrom(assertr,in_set) importFrom(assertr,not_na) importFrom(assertr,verify) importFrom(assertr,within_bounds) -importFrom(broom,tidy) -importFrom(car,logit) -importFrom(countrycode,countrycode) importFrom(data.table,":=") -importFrom(data.table,as.data.table) importFrom(data.table,data.table) -importFrom(data.table,dcast) -importFrom(data.table,fread) importFrom(data.table,rbindlist) importFrom(data.table,setDT) -importFrom(data.table,setcolorder) importFrom(data.table,setkeyv) importFrom(data.table,setnames) -importFrom(dplyr,"%>%") importFrom(dplyr,across) -importFrom(dplyr,add_row) importFrom(dplyr,anti_join) importFrom(dplyr,arrange) importFrom(dplyr,as_tibble) @@ -107,11 +105,9 @@ importFrom(dplyr,desc) importFrom(dplyr,distinct) importFrom(dplyr,everything) importFrom(dplyr,filter) -importFrom(dplyr,filter_) importFrom(dplyr,first) importFrom(dplyr,full_join) importFrom(dplyr,group_by) -importFrom(dplyr,group_by_) importFrom(dplyr,inner_join) importFrom(dplyr,lag) importFrom(dplyr,last) @@ -120,23 +116,20 @@ importFrom(dplyr,left_join) importFrom(dplyr,matches) importFrom(dplyr,min_rank) importFrom(dplyr,mutate) -importFrom(dplyr,mutate_) importFrom(dplyr,n) importFrom(dplyr,pull) importFrom(dplyr,recode) importFrom(dplyr,relocate) importFrom(dplyr,rename) -importFrom(dplyr,rename_) importFrom(dplyr,rename_all) importFrom(dplyr,right_join) importFrom(dplyr,row_number) importFrom(dplyr,select) -importFrom(dplyr,select_) importFrom(dplyr,semi_join) importFrom(dplyr,starts_with) importFrom(dplyr,summarise) -importFrom(dplyr,summarise_) importFrom(dplyr,summarize) +importFrom(dplyr,tibble) importFrom(dplyr,tribble) importFrom(dplyr,ungroup) importFrom(dplyr,vars) @@ -159,68 +152,10 @@ importFrom(ggplot2,scale_linetype_manual) importFrom(ggplot2,scale_shape_manual) importFrom(ggplot2,theme) importFrom(ggplot2,theme_minimal) -importFrom(madrat,calcOutput) -importFrom(madrat,getConfig) -importFrom(madrat,getISOlist) importFrom(madrat,madratAttach) -importFrom(madrat,readSource) importFrom(madrat,toolAggregate) -importFrom(madrat,toolCountry2isocode) -importFrom(madrat,toolCountryFill) -importFrom(madrat,toolFillWithRegionAvg) -importFrom(madrat,toolFillYears) -importFrom(madrat,toolGetMapping) -importFrom(madrat,toolISOhistorical) -importFrom(madrat,toolNAreplace) -importFrom(madrat,toolSubtypeSelect) -importFrom(madrat,vcat) -importFrom(magclass,"getItems<-") -importFrom(magclass,"getNames<-") -importFrom(magclass,"getRegions<-") -importFrom(magclass,"getSets<-") -importFrom(magclass,"getYears<-") -importFrom(magclass,"mselect<-") -importFrom(magclass,add_columns) -importFrom(magclass,add_dimension) -importFrom(magclass,as.data.frame) -importFrom(magclass,as.magpie) -importFrom(magclass,clean_magpie) -importFrom(magclass,collapseDim) -importFrom(magclass,collapseNames) -importFrom(magclass,complete_magpie) -importFrom(magclass,dimReduce) -importFrom(magclass,dimSums) -importFrom(magclass,getCells) -importFrom(magclass,getItems) -importFrom(magclass,getNames) -importFrom(magclass,getRegions) -importFrom(magclass,getSets) -importFrom(magclass,getYears) -importFrom(magclass,is.magpie) -importFrom(magclass,magpiesort) -importFrom(magclass,magpply) -importFrom(magclass,mbind) -importFrom(magclass,mselect) -importFrom(magclass,ndim) -importFrom(magclass,new.magpie) -importFrom(magclass,nregions) -importFrom(magclass,nyears) -importFrom(magclass,read.magpie) -importFrom(magclass,read.report) -importFrom(magclass,replace_non_finite) -importFrom(magclass,setCells) -importFrom(magclass,setItems) -importFrom(magclass,setNames) -importFrom(magclass,setYears) -importFrom(magclass,time_interpolate) -importFrom(magclass,where) -importFrom(magclass,write.magpie) -importFrom(magclass,write.report) -importFrom(magrittr,"%<>%") +importFrom(magclass,matchDim) importFrom(magrittr,"%>%") -importFrom(plyr,round_any) -importFrom(purrr,map) -importFrom(purrr,reduce) importFrom(quitte,add_countrycode_) importFrom(quitte,as.quitte) importFrom(quitte,calc_addVariable) @@ -229,7 +164,6 @@ importFrom(quitte,cartesian) importFrom(quitte,character.data.frame) importFrom(quitte,df_populate_range) importFrom(quitte,duplicate) -importFrom(quitte,duplicate_) importFrom(quitte,inline.data.frame) importFrom(quitte,interpolate_missing_periods) importFrom(quitte,interpolate_missing_periods_) @@ -241,7 +175,6 @@ importFrom(quitte,overwrite) importFrom(quitte,removeColNa) importFrom(quitte,seq_range) importFrom(quitte,sum_total_) -importFrom(readODS,read_ods) importFrom(readr,col_character) importFrom(readr,col_skip) importFrom(readr,cols) @@ -252,8 +185,6 @@ importFrom(readr,write_rds) importFrom(readxl,excel_sheets) importFrom(readxl,read_excel) importFrom(readxl,read_xlsx) -importFrom(reshape2,acast) -importFrom(reshape2,melt) importFrom(rlang,"!!!") importFrom(rlang,"!!") importFrom(rlang,.data) @@ -270,10 +201,7 @@ importFrom(stats,na.exclude) importFrom(stats,na.omit) importFrom(stats,na.pass) importFrom(stats,nls) -importFrom(stats,qnorm) -importFrom(stats,reshape) importFrom(stats,sd) -importFrom(stats,uniroot) importFrom(stats,weighted.mean) importFrom(tibble,as_tibble) importFrom(tibble,tibble) @@ -284,15 +212,14 @@ importFrom(tidyr,drop_na) importFrom(tidyr,everything) importFrom(tidyr,expand_grid) importFrom(tidyr,extract) +importFrom(tidyr,fill) importFrom(tidyr,gather) -importFrom(tidyr,gather_) importFrom(tidyr,nest) importFrom(tidyr,nesting) importFrom(tidyr,pivot_longer) importFrom(tidyr,pivot_wider) importFrom(tidyr,replace_na) importFrom(tidyr,separate) -importFrom(tidyr,separate_) importFrom(tidyr,spread) importFrom(tidyr,unite) importFrom(tidyr,unnest) diff --git a/R/EDGE-Industry.R b/R/EDGE-Industry.R index f2f19d53..a7cb260e 100644 --- a/R/EDGE-Industry.R +++ b/R/EDGE-Industry.R @@ -33,23 +33,19 @@ #' @seealso [`calcOutput()`] #' #' @importFrom assertr assert not_na verify within_bounds -#' @importFrom broom tidy -#' @importFrom car logit -#' @importFrom dplyr %>% case_when bind_rows between distinct first last n +#' @importFrom dplyr case_when bind_rows between distinct first last n #' mutate pull right_join select semi_join vars -#' @importFrom Hmisc wtd.quantile #' @importFrom ggplot2 aes coord_cartesian expand_limits facet_wrap geom_area #' geom_line geom_path geom_point ggplot ggsave guide_legend labs #' scale_colour_manual scale_fill_discrete scale_fill_manual #' scale_linetype_manual scale_shape_manual theme theme_minimal -#' @importFrom madrat calcOutput readSource toolGetMapping #' @importFrom quitte calc_mode character.data.frame df_populate_range duplicate -#' duplicate_ list_to_data_frame madrat_mule magclass_to_tibble order.levels +#' list_to_data_frame madrat_mule magclass_to_tibble order.levels #' seq_range sum_total_ #' @importFrom readr write_rds #' @importFrom stats nls SSlogis sd #' @importFrom tibble as_tibble tibble tribble -#' @importFrom tidyr expand_grid pivot_longer pivot_wider +#' @importFrom tidyr expand_grid pivot_longer pivot_wider replace_na #' @importFrom zoo na.approx rollmean #' @rdname EDGE-Industry @@ -162,7 +158,8 @@ calcSteel_Projections <- function(subtype = 'production', # load required data ---- ## region mapping for aggregation ---- region_mapping <- toolGetMapping(name = 'regionmapping_21_EU11.csv', - type = 'regional') %>% + type = 'regional', + where = 'mappingfolder') %>% as_tibble() %>% select(region = 'RegionCode', iso3c = 'CountryCode') @@ -196,7 +193,8 @@ calcSteel_Projections <- function(subtype = 'production', ## set of OECD countries ---- OECD_iso3c <- toolGetMapping(name = 'regionmappingOECD.csv', - type = 'regional') %>% + type = 'regional', + where = 'mappingfolder') %>% as_tibble() %>% select(iso3c = 'CountryCode', region = 'RegionCode') %>% filter('OECD' == .data$region) %>% @@ -271,15 +269,15 @@ calcSteel_Projections <- function(subtype = 'production', Asym <- regression_data %>% filter(.estimate == .data$estimate) %>% group_by(.data$year) %>% - summarise(Asym = 1.1 * wtd.quantile(x = .data$steel.stock.per.capita, - weights = .data$population, - probs = 0.99), + summarise(Asym = 1.1 * Hmisc::wtd.quantile(x = .data$steel.stock.per.capita, + weights = .data$population, + probs = 0.99), .groups = 'drop') %>% pull('Asym') %>% max() coefficients <- lm( - formula = logit(x, adjust = 0.025) ~ y, + formula = car::logit(x, adjust = 0.025) ~ y, data = regression_data %>% filter(.estimate == .data$estimate, between(.data$steel.stock.per.capita, 0, Asym)) %>% @@ -303,7 +301,7 @@ calcSteel_Projections <- function(subtype = 'production', start = list(Asym = Asym, xmid = xmid, scal = scal), algorithm = 'port', trace = FALSE) %>% - tidy() %>% + broom::tidy() %>% select('term', 'estimate') %>% pivot_wider(names_from = 'term', values_from = 'estimate') %>% mutate(estimate = .estimate) @@ -869,41 +867,11 @@ calcSteel_Projections <- function(subtype = 'production', 1 + .data$m.factor) ), adj.trade.share = .data$trade / .data$new.stock, - production = .data$new.stock - .data$adj.trade) - - if (is.data.frame(China_Production)) { - China_Production <- China_Production %>% - interpolate_missing_periods(period = seq_range(range(.$period)), - value = 'total.production', - method = 'spline') %>% - mutate(total.production = .data$total.production * 1e6) - - production_estimates <- production_estimates %>% + production = .data$new.stock - .data$adj.trade) %>% ungroup() %>% - select('scenario', 'iso3c', 'year', 'production') %>% - filter('SSP2EU' == .data$scenario, - 'CHN' == .data$iso3c, - max(steel_historic_prod$year) < .data$year) %>% - left_join(China_Production, c('year' = 'period')) %>% - mutate(value = .data$total.production / .data$production) %>% - select('iso3c', 'year', 'value') %>% - expand_grid(scenario = unique(production_estimates$scenario)) %>% - complete(nesting(!!sym('scenario')), - iso3c = unique(production_estimates$iso3c), - year = unique(production_estimates$year)) %>% - group_by(.data$scenario, .data$iso3c) %>% - mutate( - value = case_when( - max(steel_historic_prod$year) >= .data$year ~ 1, - TRUE ~ .data$value), - value = case_when( - is.na(.data$value) ~ last(na.omit(.data$value)), - TRUE ~ .data$value)) %>% - ungroup() %>% - left_join(production_estimates, c('scenario', 'iso3c', 'year')) %>% - mutate(production = .data$production * .data$value) %>% - select(-'value') - } + select('scenario', 'region', 'iso3c', 'year', 'production', 'recyclable', + 'steel.stock', 'secondary.steel.max.share', 'depreciation', + 'adj.trade') production_estimates <- production_estimates %>% mutate( @@ -950,81 +918,66 @@ calcSteel_Projections <- function(subtype = 'production', # match historic values ---- if (match.steel.historic.values) { tmp <- full_join( - # estimates after last historic year production_estimates %>% - filter(max(unique(steel_historic_prod$year)) <= .data$year, - .data$variable %in% c('primary.production', - 'secondary.production'), - 'Total' != .data$iso3c), + filter(.data$variable %in% c('primary.production', + 'secondary.production')), - # estimates up to last historic year steel_historic_prod %>% - rename(historic = .data$value) %>% + filter(.data$variable %in% c('primary.production', + 'secondary.production')) %>% + rename(historic = 'value') %>% # Mt/year * 1e6 t/Mt = t/year - mutate(historic = .data$historic * 1e6, - scenario = production_estimates[[1,'scenario']]) %>% - # duplicate for all scenarios - complete( - nesting(!!!syms(c('region', 'iso3c', 'year', 'variable', - 'historic'))), - scenario = unique(pull(production_estimates, 'scenario'))) %>% - complete(nesting(!!!syms(c('scenario', 'region', 'iso3c'))), - year = unique(.data$year), - variable = unique(.data$variable), - fill = list(historic = 0)) %>% - assert(not_na, everything()), + mutate(historic = .data$historic * 1e6) %>% + expand_grid(scenario = unique(production_estimates$scenario)), c('scenario', 'region', 'iso3c', 'year', 'variable') ) - tmp <- bind_rows( - # shift country production to meet historic production in the last year - # for which data is available - tmp %>% - filter(.data$year >= max(steel_historic_prod$year)) %>% - group_by(!!!syms(c('scenario', 'region', 'iso3c', 'variable'))) %>% - filter(!is.na(first(.data$historic, order_by = .data$year))) %>% - mutate( - value = .data$value - / first(.data$value, order_by = .data$year) - * first(.data$historic, order_by = .data$year)) %>% - ungroup() %>% - select(-'historic') %>% - interpolate_missing_periods_(periods = list('year' = unique(.$year)), - expand.values = TRUE), - - # countries w/o historic production fade production in over 20 years - tmp %>% - filter(.data$year >= max(steel_historic_prod$year)) %>% - group_by(!!!syms(c('scenario', 'region', 'iso3c', 'variable'))) %>% - filter(any( - is.na(first(.data$historic, order_by = .data$year)), - 0 == first(.data$historic, order_by = .data$year))) %>% - mutate(value = .data$value - * pmin(1, (.data$year - first(.data$year)) / 20)) %>% - select(-'historic') %>% - ungroup(), - - # data up to last historic year - tmp %>% - filter(.data$year < max(steel_historic_prod$year)) %>% - select(-'value', value = 'historic') + tmp_factor <- tmp %>% + group_by(.data$scenario, .data$region, .data$iso3c, .data$variable) %>% + arrange(.data$year) %>% + mutate( + factor = .data$historic / .data$value, + factor = case_when( + # countries w/o historic production fade production in over 20 years + all(is.na(.data$historic)) ~ + pmin(1, pmax(0, (.data$year - max(steel_historic_prod$year)) / 20)), + # shift country production to meet historic production in the + # first/last year for which historic data is available + .data$year < first(.data$year * as.integer(Inf != .data$historic), + order_by = .data$year, na_rm = TRUE) ~ + first(.data$factor, order_by = .data$year, na_rm = TRUE), + .data$year > last(.data$year * as.integer(Inf != .data$historic), + order_by = .data$year, na_rm = TRUE) ~ + last(.data$factor, order_by = .data$year, na_rm = TRUE), + TRUE ~ .data$factor), + # if value is 0, x/0 is Inf, and 0 * (x/0) is NaN + factor = ifelse(is.infinite(.data$factor), 0, .data$factor)) %>% + ungroup() %>% + select(-'value', -'historic') %>% + interpolate_missing_periods_(periods = list(year = unique(.$year)), + value = 'factor', + expand.values = TRUE) + + tmp <- full_join( + tmp, + tmp_factor, + + c('scenario', 'region', 'iso3c', 'year', 'variable') ) %>% - semi_join(region_mapping, c('region', 'iso3c')) %>% - group_by(!!!syms(c('scenario', 'region', 'iso3c', 'year', - 'variable'))) %>% - summarise(value = sum(.data$value), .groups = 'drop') %>% - assert(not_na, everything()) %>% - arrange(.data$scenario, .data$region, .data$iso3c, .data$variable, - .data$year) + mutate(value = .data$value * .data$factor) %>% + ungroup() %>% + select(-'historic', -'factor') %>% + assert(not_na, everything()) - # make zero values explicit ---- + ## make zero values explicit ---- tmp <- tmp %>% semi_join(region_mapping, c('region', 'iso3c')) %>% complete(.data$scenario, .data$variable, nesting(!!sym('region'), !!sym('iso3c')), year = unique(!!sym('year')), - fill = list(value = 0)) + fill = list(value = 0)) %>% + assert(not_na, everything()) ## update max secondary steel shares ---- update.secondary.steel.max.share <- function(production, @@ -1036,7 +989,9 @@ calcSteel_Projections <- function(subtype = 'production', production %>% pivot_wider(names_from = 'variable') %>% mutate(share = .data$secondary.production - / (.data$primary.production + .data$secondary.production)), + / ( .data$primary.production + + .data$secondary.production)) %>% + replace_na(list(share = 0)), c('scenario', 'region', 'iso3c', 'year') ) %>% @@ -1068,6 +1023,63 @@ calcSteel_Projections <- function(subtype = 'production', as.magpie(spatial = 2, temporal = 4, data = 5) } + # match exogenous data for China ---- + if (is.data.frame(China_Production)) { + China_Production <- China_Production %>% + interpolate_missing_periods(period = seq_range(range(.$period)), + value = 'total.production', + method = 'spline') %>% + mutate(total.production = .data$total.production * 1e6) + + tmp <- tmp %>% + filter('SSP2EU' == .data$scenario, + 'CHN' == .data$iso3c, + max(steel_historic_prod$year) < .data$year, + .data$variable %in% c('primary.production', + 'secondary.production')) %>% + group_by(.data$scenario, .data$iso3c, .data$year) %>% + summarise(production = sum(.data$value), .groups = 'drop') %>% + left_join(China_Production, c('year' = 'period')) %>% + mutate(factor = .data$total.production / .data$production) %>% + select('iso3c', 'year', 'factor') %>% + expand_grid(scenario = unique(production_estimates$scenario)) %>% + complete(nesting(!!sym('scenario')), + iso3c = setdiff(unique(production_estimates$iso3c), 'Total'), + year = unique(production_estimates$year)) %>% + group_by(.data$scenario, .data$iso3c) %>% + mutate( + factor = case_when( + max(steel_historic_prod$year) >= .data$year ~ 1, + TRUE ~ .data$factor), + factor = case_when( + is.na(.data$factor) ~ last(na.omit(.data$factor)), + TRUE ~ .data$factor)) %>% + ungroup() %>% + left_join(tmp, c('scenario', 'iso3c', 'year')) %>% + mutate(value = .data$value * .data$factor) %>% + select(-'factor') %>% + assert(not_na, everything()) + + ## construct output ---- + x <- tmp %>% + filter(min(steel_historic_prod$year) <= .data$year) %>% + semi_join(region_mapping, c('region', 'iso3c')) %>% + right_join( + tribble( + ~variable, ~pf, + 'primary.production', 'ue_steel_primary', + 'secondary.production', 'ue_steel_secondary'), + + 'variable' + ) %>% + assert(not_na, everything()) %>% + # t/year * 1e-9 Gt/t = Gt/year + mutate(value = .data$value * 1e-9, + scenario = paste0('gdp_', .data$scenario)) %>% + select('scenario', 'iso3c', 'pf', 'year', 'value') %>% + as.magpie(spatial = 2, temporal = 4, data = 5) + } + # match exogenous estimates ---- ## IEA ETP 2017 ---- if ('IEA_ETP' == match.steel.estimates) { @@ -1226,7 +1238,8 @@ calcSteel_Projections <- function(subtype = 'production', if ('secondary.steel.max.share' == subtype) { return( list(x = secondary.steel.max.share %>% - filter(.data$year %in% unique(quitte::remind_timesteps$period)) %>% + filter(.data$year %in% unique(quitte::remind_timesteps$period), + 'Total' != .data$iso3c) %>% mutate(scenario = paste0('gdp_', .data$scenario)) %>% select('scenario', 'iso3c', 'year', 'share') %>% as.magpie(spatial = 2, temporal = 3, data = 4), @@ -1315,7 +1328,8 @@ calcIndustry_Value_Added <- function(subtype = 'physical', # load required data ---- ## region mapping for aggregation ---- region_mapping <- toolGetMapping(name = 'regionmapping_21_EU11.csv', - type = 'regional') %>% + type = 'regional', + where = 'mappingfolder') %>% as_tibble() %>% select(region = 'RegionCode', iso3c = 'CountryCode') @@ -1417,7 +1431,7 @@ calcIndustry_Value_Added <- function(subtype = 'physical', GDP = .data$GDP * 1e6) ## ---- load cement production data ---- - data_cement_production <- calcOutput('Cement', aggregate = FALSE) %>% + data_cement_production <- calcOutput('Cement', aggregate = FALSE, warnNA = FALSE) %>% magclass_to_tibble() %>% select(-'data') %>% filter(!is.na(.data$value)) @@ -1479,7 +1493,7 @@ calcIndustry_Value_Added <- function(subtype = 'physical', 'Total' == .data$iso3c), start = list(a = 1000, b = -2000), trace = FALSE) %>% - tidy() %>% + broom::tidy() %>% select('term', 'estimate') %>% pivot_wider(names_from = 'term', values_from = 'estimate') %>% mutate(region = r) @@ -1624,7 +1638,7 @@ calcIndustry_Value_Added <- function(subtype = 'physical', GDPpC = .data$GDP / .data$population), start = list(a = 500, b = 500), trace = FALSE) %>% - tidy() %>% + broom::tidy() %>% select('term', 'estimate') %>% pivot_wider(names_from = 'term', values_from = 'estimate') %>% mutate(region = r) @@ -1897,7 +1911,7 @@ calcIndustry_Value_Added <- function(subtype = 'physical', GDPpC = .data$GDP / .data$population), start = list(a = 1, b = -1000), trace = FALSE) %>% - tidy() %>% + broom::tidy() %>% select('term', 'estimate') %>% pivot_wider(names_from = 'term', values_from = 'estimate') %>% mutate(region = r) @@ -2006,7 +2020,7 @@ calcIndustry_Value_Added <- function(subtype = 'physical', GDPpC = .data$GDP / .data$population), start = list(a = 250, b = -4000), trace = FALSE) %>% - tidy() %>% + broom::tidy() %>% select('term', 'estimate') %>% pivot_wider(names_from = 'term', values_from = 'estimate') %>% mutate(region = r) @@ -2374,7 +2388,7 @@ calcIndustry_Value_Added <- function(subtype = 'physical', !.data$censored), start = list(a = 1000, b = -100), trace = FALSE) %>% - tidy() %>% + broom::tidy() %>% select('term', 'estimate') %>% pivot_wider(names_from = 'term', values_from = 'estimate') %>% mutate(region = r) diff --git a/R/ODYM_RECC.R b/R/ODYM_RECC.R index 412bfe4e..50ab1a9e 100644 --- a/R/ODYM_RECC.R +++ b/R/ODYM_RECC.R @@ -13,7 +13,6 @@ #' @author Michaja Pehl #' #' @importFrom dplyr left_join mutate n group_by select ungroup -#' @importFrom magrittr %>% #' @importFrom quitte madrat_mule #' @importFrom readr read_csv #' @importFrom rlang syms diff --git a/R/UNIDO.R b/R/UNIDO.R index ab03c0c5..64f929ba 100644 --- a/R/UNIDO.R +++ b/R/UNIDO.R @@ -64,9 +64,6 @@ #' @importFrom assertr assert not_na #' @importFrom dplyr anti_join bind_rows filter group_by inner_join left_join #' mutate select summarise -#' @importFrom madrat readSource toolCountryFill -#' @importFrom magclass as.magpie dimSums mbind setNames -#' @importFrom magrittr %>% #' @importFrom quitte list_to_data_frame madrat_mule #' @importFrom readr read_csv #' @importFrom rlang .data is_empty diff --git a/R/calcAGEB.R b/R/calcAGEB.R index 4955db6a..c3dd65ff 100644 --- a/R/calcAGEB.R +++ b/R/calcAGEB.R @@ -8,8 +8,6 @@ #' @param subtype data subtype. Either "balances" ("Auswertungstabellen zur Energiebilanz Deutschland") or #' "electricity" ("Bruttostromerzeugung in Deutschland nach Energieträgern") #' @importFrom dplyr select mutate left_join -#' @importFrom madrat toolGetMapping toolCountryFill -#' @importFrom magclass as.magpie mselect #' @importFrom rlang sym #' @importFrom stats aggregate #' @export @@ -17,7 +15,7 @@ calcAGEB <- function(subtype = "balances") { ageb <- readSource("AGEB", subtype = subtype) mapping <- toolGetMapping("Mapping_AGEB_REMIND.csv", type = "reportingVariables", where = "mappingfolder") %>% - mutate(!!sym("conversion") := as.numeric(!!sym("Factor")) * !!sym("Weight")) %>% + mutate("conversion" = as.numeric(!!sym("Factor")) * !!sym("Weight")) %>% select("variable" = "AGEB_variable", "REMIND_variable", "conversion", "unit" = "Unit_AGEB", "Unit_REMIND") %>% filter(!!sym("REMIND_variable") != "") @@ -34,8 +32,8 @@ calcAGEB <- function(subtype = "balances") { by = "variable" ) %>% mutate( - !!sym("value") := !!sym("value") * !!sym("conversion"), - !!sym("REMIND_variable") := paste0(!!sym("REMIND_variable"), " (", !!sym("Unit_REMIND"), ")") + "value" = !!sym("value") * !!sym("conversion"), + "REMIND_variable" = paste0(!!sym("REMIND_variable"), " (", !!sym("Unit_REMIND"), ")") ) %>% select("variable" = "REMIND_variable", "region", "year", "value") diff --git a/R/calcBP.R b/R/calcBP.R index 0064b2c6..ebf4c2f9 100644 --- a/R/calcBP.R +++ b/R/calcBP.R @@ -1,152 +1,153 @@ #' Calculate REMIND variables from historical BP values #' -#' @md -#' @return A [`magpie`][magclass::magclass] object. -#' #' @author Falk Benke -#' @importFrom dplyr select mutate left_join -#' @importFrom madrat toolGetMapping toolCountryFill -#' @importFrom magclass as.magpie mselect -#' @importFrom readxl read_excel -#' @importFrom rlang sym -#' @importFrom stats aggregate +#' @importFrom magclass matchDim +#' @importFrom quitte interpolate_missing_periods +#' #' @export - +#' calcBP <- function() { - .readFactors <- function() { - factors <- toolGetMapping("BP_Renewable_Efficiency_Factors.csv", type = "sectoral", where = "mappingfolder") - colnames(factors) <- c("year", "factor") - factors <- rbind( - factors, - data.frame(year = seq(1965, 2000, 1), factor = 0.36) - ) %>% - filter(!is.na(as.numeric(!!sym("year")))) - - return(factors[order(factors$year), ]) - } + # read in emissions, capacity, generation, price ---- - mapping <- toolGetMapping("Mapping_BP.csv", type = "reportingVariables") %>% - mutate(!!sym("conversion") := as.numeric(!!sym("Factor")) * !!sym("Weight")) %>% - select("variable" = "BP", "REMIND", "conversion", "unit" = "Unit_BP", "Unit_REMIND") - - mapping$REMIND <- trimws(mapping$REMIND) - - .convert <- function(data) { - data %>% - mselect(data = unique(mapping$variable)) %>% - as.data.frame() %>% - as_tibble() %>% - select( - "region" = "Region", "variable" = "Data1", - "year" = "Year", "value" = "Value" - ) %>% - return() - } - - # Emission - data <- .convert(readSource("BP", subtype = "Emission")) + emissions <- readSource("BP", subtype = "Emission") - # Capacity - data <- rbind(data, .convert(readSource("BP", subtype = "Capacity"))) + capacity <- readSource("BP", subtype = "Capacity") + capacity <- matchDim(capacity, emissions, dim = 2, fill = NA) - # Generation - data <- rbind(data, .convert(readSource("BP", subtype = "Generation"))) + generation <- readSource("BP", subtype = "Generation") - # Consumption + price <- readSource("BP", subtype = "Price") + price <- matchDim(price, emissions, dim = 2, fill = NA) - # prepare consumption data + # prepare consumption data ---- consumption <- readSource("BP", subtype = "Consumption") - # rescale renewables to direct equivalence method by multiplying with the numbers given on sheet "Methodology" - renewables.factors <- .readFactors() %>% + # read in efficiency factors described in sheet "Methodology + # 1965-2000: assumed constant efficiency of 36% + # 2000-2017: a linear increase from 36% to 40% based on observed data + # 2018 onwards: the annual rate of efficiency improvement is based on the simplified + # assumption that efficiency will increase linearly to 45% by 2050. + + efficiencyFactors <- rbind( + data.frame(period = seq(1965, 2000, 1), value = 0.36), + data.frame(period = seq(2001, 2016), value = NA), + data.frame(period = 2017, value = 0.4), + data.frame(period = seq(2018, 2049), value = NA), + data.frame(period = 2050, value = 0.45) + ) + + efficiencyFactors <- interpolate_missing_periods(efficiencyFactors, method = "linear") %>% as.magpie() %>% dimReduce() - renewables.vars <- c("Solar Consumption (EJ)", "Wind Consumption (EJ)", "Nuclear Consumption (EJ)", "Hydro Consumption (EJ)") + + renewables.vars <- c( + "Solar Consumption (EJ)", "Wind Consumption (EJ)", + "Nuclear Consumption (EJ)", "Hydro Consumption (EJ)" + ) # recalculate renewables to direct equivalent accounting - consumption.renewables <- consumption[, , renewables.vars] * renewables.factors + consumption.renewables <- consumption[, , renewables.vars] * efficiencyFactors[, getYears(consumption), ] - consumption.fossils <- consumption[, , c(renewables.vars, "Primary Energy Consumption (EJ)"), invert = T] + # store fossils, which need no conversion + consumption.fossils <- consumption[, , c(renewables.vars, "Primary Energy Consumption (EJ)"), invert = TRUE] # recalculate total pe consumption to direct equivalent accounting # 1. deduct original nuclear and electricity generation by renewables - pe.elec.renewable <- readSource("BP", subtype = "Generation")[, , "Generation|Electricity|Renewable (EJ)"] pe.nuclear <- consumption[, , "Nuclear Consumption (EJ)"] + pe.elec.renewable <- generation[, , "Generation|Electricity|Renewable (EJ)"] consumption.pe <- consumption[, , "Primary Energy Consumption (EJ)"] - pe.nuclear - pe.elec.renewable # 2. add adjusted nuclear and renewables values - pe.elec.renewable.dea <- pe.elec.renewable * renewables.factors - pe.nuclear.dea <- pe.nuclear * renewables.factors + pe.nuclear.dea <- pe.nuclear * efficiencyFactors[, getYears(pe.nuclear), ] + pe.elec.renewable.dea <- pe.elec.renewable * efficiencyFactors[, getYears(pe.elec.renewable), ] consumption.pe <- consumption.pe + pe.elec.renewable.dea + pe.nuclear.dea + consumption.pe <- collapseDim(consumption.pe) + getNames(consumption.pe) <- "Primary Energy Consumption (EJ)" + getSets(consumption.pe) <- c("region", "year", "data") - data <- rbind( - data, - .convert(consumption.fossils), - .convert(consumption.renewables), - .convert(consumption.pe) - ) - - # Trade + # prepare trade data ---- # calculate net oil trade trade.oil <- readSource("BP", subtype = "Trade Oil") + trade.oil <- matchDim(trade.oil, emissions, dim = 2, fill = NA) + trade.oil.net <- trade.oil[, , "Trade|Export|Oil (kb/d)"] - trade.oil[, , "Trade|Import|Oil (kb/d)"] getNames(trade.oil.net) <- c("Net Trade|Oil (kb/d)") getSets(trade.oil.net) <- c("region", "year", "data") # calculate net coal trade trade.coal <- readSource("BP", subtype = "Trade Coal") + trade.coal <- matchDim(trade.coal, emissions, dim = 2, fill = NA) + trade.coal.net <- trade.coal[, , "Trade|Export|Coal (EJ)"] - trade.coal[, , "Trade|Import|Coal (EJ)"] getNames(trade.coal.net) <- c("Net Trade|Coal (EJ)") getSets(trade.coal.net) <- c("region", "year", "data") # calculate net gas trade trade.gas <- readSource("BP", subtype = "Trade Gas") + trade.gas <- matchDim(trade.gas, emissions, dim = 2, fill = NA) + trade.gas.net <- trade.gas[, , "Trade|Export|Gas (bcm)"] - trade.gas[, , "Trade|Import|Gas (bcm)"] getNames(trade.gas.net) <- c("Net Trade|Gas (bcm)") getSets(trade.gas.net) <- c("region", "year", "data") - data <- rbind( - data, - .convert(trade.oil), - .convert(trade.oil.net), - .convert(trade.gas), - .convert(trade.gas.net), - .convert(trade.coal), - .convert(trade.coal.net) + # map to REMIND variables ---- + + x <- mbind( + emissions, + capacity, + generation, + consumption.fossils, + consumption.renewables, + consumption.pe, + trade.oil, + trade.oil.net, + trade.gas, + trade.gas.net, + trade.coal, + trade.coal.net, + price ) - # Trade - - p <- readSource("BP", subtype = "Price") - data <- rbind(data, .convert(p)) - - x <- left_join( - data, - mapping, - by = "variable" - ) %>% - filter(!!sym("REMIND") != "") %>% + map <- toolGetMapping("Mapping_BP.csv", type = "reportingVariables", where = "mrremind") %>% + filter(!is.na(.data$REMIND), .data$REMIND != "") %>% mutate( - !!sym("value") := !!sym("value") * !!sym("conversion"), - !!sym("REMIND") := paste0(!!sym("REMIND"), " (", !!sym("Unit_REMIND"), ")") + "from" := paste0(trimws(.data$variable), " (", .data$unit, ")"), + "to" := paste0(trimws(.data$REMIND), " (", .data$Unit_REMIND, ")"), + "conversion" := as.numeric(.data$Factor) ) %>% - select("variable" = "REMIND", "region", "year", "value") + select("from", "to", "conversion") - x <- aggregate(value ~ variable + region + year, x, sum) %>% - as.magpie() %>% - toolCountryFill(fill = 0) + + for (var in intersect(getNames(x, dim = 1), unique(map$from))) { + conv <- map[map$from == var, "conversion"] + + # there should be a distinct conversion factor in the mapping + # if there is more than one conversion factor, it means that one source variable + # is converted two more than one target variable using a different conversion + # this case is not covered by the logic + if (length(unique(conv)) > 1) { + stop(paste0("Cannot apply conversion factor for variable ", var)) + } + + x[, , var] <- x[, , var] * unique(conv) + } + + x <- toolAggregate(x, + dim = 3.1, rel = map, from = "from", partrel = TRUE, + to = "to", verbosity = 2 + ) weights <- x - weights[,,] <- NA - weights[,,"US$2005/GJ", pmatch = T] <- 1 + weights[, , ] <- NA + weights[, , "US$2005/GJ", pmatch = TRUE] <- 1 return(list( x = x, weight = weights, - mixed_aggregation = T, + mixed_aggregation = TRUE, unit = c("Mt CO2/yr", "GW", "EJ/yr", "US$2005/GJ"), - description = "Historical BP values as REMIND variables" + description = "Historical World Energy Statistics values as REMIND variables" )) } diff --git a/R/calcBiomassPrices.R b/R/calcBiomassPrices.R index f1cc6d3d..fa059a0a 100644 --- a/R/calcBiomassPrices.R +++ b/R/calcBiomassPrices.R @@ -1,7 +1,5 @@ #' read biomass supply curves from Magpie emulator #' @return Magpie object with two parameters determining linear biomass supply curve -#' @importFrom magclass dimReduce -#' @importFrom madrat readSource #' @import mrcommons calcBiomassPrices <- function(){ @@ -21,6 +19,11 @@ calcBiomassPrices <- function(){ # Introduce new SSP/SDP dimension by replacing "-" with "." getNames(x) <- gsub("(SSP[0-9]|SDP)-","\\1.",getNames(x)) + # add supply curves for SSP3 using the curves from SSP2 + tmp <- x[,,"SSP2"] + getNames(tmp) <- gsub("SSP2", "SSP3", getNames(tmp)) + x <- mbind(x, tmp) + # if fit coefficients of a country are NA for all years (there is no supplycurve at all for this country) # generate artificial supplycurve with VERY high prices x[,,"a"][is.na(x[,,"a"])] <- 1 diff --git a/R/calcCCSbounds.R b/R/calcCCSbounds.R index 03e59a8c..22e69562 100644 --- a/R/calcCCSbounds.R +++ b/R/calcCCSbounds.R @@ -1,16 +1,15 @@ #' Calculate CCS bound indicator for 2025 and 2030 -#' -#' -#' +#' #' @author Jessica Strefler, Lavinia Baumstark #' @seealso \code{\link{calcOutput}}, \code{\link{readSource}} calcCCSbounds <- function() { - - data <- readSource("ExpertGuess", subtype="CCSbounds") + data <- readSource("ExpertGuess", subtype = "CCSbounds") getNames(data) <- NULL - - return(list(x=data,weight=NULL, - unit="TW", - description="CCS bound indicator")) + + return(list( + x = data, weight = NULL, + unit = "TW", + description = "CCS bound indicator" + )) } diff --git a/R/calcCCScapacity.R b/R/calcCCScapacity.R index d69c02b6..b1c1e3ca 100644 --- a/R/calcCCScapacity.R +++ b/R/calcCCScapacity.R @@ -1,16 +1,34 @@ +#' calc CCS capacity +#' +#' Calculate CCS capacity from IEA CCUS data +#' +#' @author Anne Merfort, Falk Benke +#' +#' @param subtype either `historical` for data until 2022 or `projections` +#' for projections in 2020, 2025 and 2030 (including some redistribution on EU/NEU level) +#' +#' @export +calcCCScapacity <- function(subtype) { + x <- calcOutput("ProjectPipelines", subtype = "CCS", aggregate = F) -calcCCScapacity <- function(){ - - # Read capacity factor inputs - ccs <- readSource("GlobalCCSinstitute") - - # convert from MtCO2/yr to GtC/yr - out <- 1 / (3.666666666667 * 1000) * ccs - - return(list(x = out, - weight = NULL, - unit ="% of capacity", - description ="Installed capacity availability - capacity factor (fraction of the year that a plant is running)" + if (subtype == "pipeline") { + # used as input-data for CCS bounds + x <- x[, c(2020, 2025, 2030), c("operational", "construction", "planned")] + # remove "model", "variable" and "unit" dimension + x <- collapseDim(x, keepdim = "status") + } + + if (subtype == "historical") { + # project pipeline snapshot from beginning of 2024 + x <- x[, seq(2005, 2023), "operational"] + # remove "status" and "unit" dimension + x <- collapseDim(x, keepdim = c("model", "variable")) + } + + return(list( + x = x, + weight = NULL, + unit = "MtCO2/yr", + description = "CCS capacity derived from IEA CCUS project database" )) - } diff --git a/R/calcCO2Prices.R b/R/calcCO2Prices.R index b29d43cb..c7f32457 100644 --- a/R/calcCO2Prices.R +++ b/R/calcCO2Prices.R @@ -1,27 +1,18 @@ calcCO2Prices <- function() { - # read data x <- readSource("ExpertGuess", subtype = "co2prices") getNames(x) <- NULL # read data used for weight - ceds <- calcOutput("Emissions", datasource = "CEDS2021", aggregate = FALSE) + ceds <- calcOutput("Emissions", datasource = "CEDS2024", aggregate = FALSE) ceds <- ceds[, , "Emi|CO2|Energy and Industrial Processes (Mt CO2/yr)"] - # if most recent year is not in ceds, use latest ceds year that is available - cedsyears <- getYears(ceds, as.integer = TRUE) - xyears <- getYears(x, as.integer = TRUE) - cedsmissing <- setdiff(xyears, cedsyears) - if (length(cedsmissing) == 1 && cedsmissing > max(cedsyears)) { - cedsyears <- c(intersect(cedsyears, xyears), max(cedsyears)) - ceds <- ceds[, cedsyears, ] - getYears(ceds) <- xyears - } else if (length(cedsmissing) > 1) { - stop("CEDS data not available for ", paste(cedsmissing, collapse = ", ")) - } + ceds <- ceds[, getYears(x), ] - return(list(x = x, - weight = ceds, - unit = "US$2005/t CO2", - description = "CO2 prices in 2010, 2015 and 2020")) + return(list( + x = x, + weight = ceds, + unit = "US$2005/t CO2", + description = "CO2 prices in 2010, 2015 and 2020" + )) } diff --git a/R/calcCalibrationPrices.R b/R/calcCalibrationPrices.R deleted file mode 100644 index cc38c90b..00000000 --- a/R/calcCalibrationPrices.R +++ /dev/null @@ -1,34 +0,0 @@ -#' Prices of CES variables for calibration runs in REMIND -#' -#' Uses former REMIND runs -#' -#' @author Antoine Levesque -calcCalibrationPrices <- function() { - #----- Functions ------------------ - - #----- READ-IN DATA ------------------ - prices = readSource("RemindCesPrices") - - #----- Parameters ------------------ - epsilon = 1e-4 - #----- Process data ------------------ - #______________________________________ - #|In case of new variables not present | - #|in former runs, you can add them here| - #|by using the available prices | - #| | - #| | - #| | - #|_____________________________________| - - #Weighting could be improved by using calcFEdemand, but some variables are missing - # and prices are only instrumental - weights = prices - weights[,,] <- 1 - - prices[prices < epsilon] = epsilon - - return(list(x=prices,weight=weights, - unit = "CES variables derivatives in terms of inco", - description = "CES variables derivatives in terms of inco")) -} diff --git a/R/calcCapTarget.R b/R/calcCapTarget.R index 08a4aebb..7ad8e8d0 100644 --- a/R/calcCapTarget.R +++ b/R/calcCapTarget.R @@ -4,7 +4,7 @@ #' The UNFCCC_NDC capacity targets are further broken down to conditional and unconditional targets. #' @author Aman Malik, Oliver Richters #' @param sources Database source -#' @importFrom dplyr %>% filter +#' @importFrom dplyr filter calcCapTarget <- function(sources) { @@ -30,7 +30,9 @@ calcCapTarget <- function(sources) { "2022_cond" = readSource("UNFCCC_NDC", subtype = "Capacity_2022_cond"), "2022_uncond" = readSource("UNFCCC_NDC", subtype = "Capacity_2022_uncond"), "2023_cond" = readSource("UNFCCC_NDC", subtype = "Capacity_2023_cond"), - "2023_uncond" = readSource("UNFCCC_NDC", subtype = "Capacity_2023_uncond") + "2023_uncond" = readSource("UNFCCC_NDC", subtype = "Capacity_2023_uncond"), + "2024_cond" = readSource("UNFCCC_NDC", subtype = "Capacity_2024_cond"), + "2024_uncond" = readSource("UNFCCC_NDC", subtype = "Capacity_2024_uncond") ) listYears <- lapply(listCapacitiesNDC, getItems, dim = "year") %>% unlist() %>% unique() %>% sort() @@ -99,7 +101,7 @@ calcCapTarget <- function(sources) { # hydrogen capacity targets from national/EU hydrogen strategies # Region targets - reg.map <- toolGetMapping("regionmappingH12.csv", type = "regional", + reg.map <- toolGetMapping("regionmappingH12.csv", type = "regional", where = "mappingfolder") # get H12 regionmapping H2Target.reg <- new.magpie(unique(reg.map$RegionCode), getYears(x), "elh2", fill = 0) # Electrolyzer capacity target from the EU Hydrogen Strategy diff --git a/R/calcCapacity.R b/R/calcCapacity.R index 2c1dab6e..1c990469 100644 --- a/R/calcCapacity.R +++ b/R/calcCapacity.R @@ -22,7 +22,7 @@ calcCapacity <- function(subtype) { IRENAcap <- readSource(type="IRENA",subtype="Capacity") # Read IRENA renewables capacity data IRENAcap <- IRENAcap[,,c("Concentrated solar power", - "Geothermal", "Hydropower", + "Geothermal", "Renewable hydropower", "Solar photovoltaic", "Onshore wind energy", "Offshore wind energy" @@ -30,7 +30,7 @@ calcCapacity <- function(subtype) { mapping <- data.frame(IRENA_techs=c("Concentrated solar power", "Geothermal", - "Hydropower", + "Renewable hydropower", "Solar photovoltaic", "Onshore wind energy", "Offshore wind energy"), @@ -45,10 +45,10 @@ calcCapacity <- function(subtype) { # Technologies: "csp", "geohdr", "hydro", "spv", "wind" IRENAcap <- readSource(type="IRENA",subtype="Capacity") # Read IRENA renewables capacity data # selecting data used on REMIND - IRENAcap <- IRENAcap[,,c("Concentrated solar power", "Geothermal", "Hydropower", "Solar photovoltaic", "Wind")] + IRENAcap <- IRENAcap[,,c("Concentrated solar power", "Geothermal", "Renewable hydropower", "Solar photovoltaic", "Wind")] mapping <- data.frame(IRENA_techs=c("Concentrated solar power", - "Geothermal", "Hydropower", + "Geothermal", "Renewable hydropower", "Solar photovoltaic", "Wind"), REMIND_techs=c("csp", "geohdr", "hydro", "spv", "wind"), @@ -141,7 +141,7 @@ calcCapacity <- function(subtype) { output[getRegions(USA.2025.PVData),getYears(USA.2025.PVData), getNames(USA.2025.PVData)] <- USA.2025.PVData output[is.na(output)] <- 0 #set NA to 0 - output <- toolCountryFill(output,fill=0,verbosity=0) # fill missing countries + output <- toolCountryFill(output,fill=0,verbosity=2) # fill missing countries } else if (grepl("capacityByPE", subtype)) { @@ -226,7 +226,7 @@ calcCapacity <- function(subtype) { } } - output <- toolCountryFill(output,fill=0,verbosity=0) # fill missing countries + output <- toolCountryFill(output,fill=0,verbosity=2) # fill missing countries output <- magclass::add_dimension(output, dim = 3.2, add = "enty", nm = "seel") # add secondary energy dimension diff --git a/R/calcCapacityFactor.R b/R/calcCapacityFactor.R index e89d9491..aec4225a 100644 --- a/R/calcCapacityFactor.R +++ b/R/calcCapacityFactor.R @@ -2,7 +2,6 @@ #' @description provides capacity factor values #' @return magpie object of the capacity factor data #' @author Renato Rodrigues, Stephen Bi -#' @importFrom plyr round_any #' @examples #' \dontrun{ #' calcOutput("CapacityFactor") @@ -12,11 +11,15 @@ calcCapacityFactor <- function() { ### calculation of coal power capacity factor GWh_2_EJ <- 3.6e-6 + # Taken from the plyr package + round_any <- function(x, accuracy, f = round) f(x/ accuracy) * accuracy + # Read capacity factor inputs global <- readSource("REMIND_11Regi", subtype = "capacityFactorGlobal", convert = FALSE) # remove no longer used items - notUsed <- c("apcarelt", "aptrnelt", "apcarh2t", "apcarpet", "apcardit", "apcardiefft", "apcardieffH2t") + notUsed <- c("apcarelt", "aptrnelt", "apcarh2t", "apcarpet", "apcardit", + "apcardiefft", "apcardieffH2t", "pcc", "pco") global <- global[, , notUsed, invert = TRUE] # Set coal plant capacity factor long-term assumption to 50% (down from 60%) diff --git a/R/calcCapacityFactorHist.R b/R/calcCapacityFactorHist.R index d3c6e3d5..3fab8de5 100644 --- a/R/calcCapacityFactorHist.R +++ b/R/calcCapacityFactorHist.R @@ -19,7 +19,7 @@ calcCapacityFactorHist <- function(subtype){ #mapping of remind technology names to IRENA categories rem_Irena_map <- data.frame(rem=c("hydro","wind","spv","csp","bioigcc","geohdr"), - irena= c("Hydropower","Wind","Solar photovoltaic","Concentrated solar power", "Bioenergy","Geothermal")) + irena= c("Renewable hydropower","Wind","Solar photovoltaic","Concentrated solar power", "Bioenergy","Geothermal")) # Read capacity factor inputs hist_cap <- readSource(type="IRENA",subtype="Capacity")/1000 # converting from MW to GW hist_gen <- readSource("IRENA", subtype = "Generation")# Units are GWh @@ -58,7 +58,7 @@ calcCapacityFactorHist <- function(subtype){ #mapping of remind technology names to IRENA categories tech_list = c("hydro","wind","windoff","spv","csp","bioigcc","geohdr") rem_Irena_map <- data.frame(rem=tech_list, - irena= c("Hydropower","Onshore wind energy", "Offshore wind energy","Solar photovoltaic","Concentrated solar power", "Bioenergy","Geothermal")) + irena= c("Renewable hydropower","Onshore wind energy", "Offshore wind energy","Solar photovoltaic","Concentrated solar power", "Bioenergy","Geothermal")) # Read capacity factor inputs hist_cap <- readSource(type="IRENA",subtype="Capacity") / 1000 # converting from MW to GW hist_gen <- readSource("IRENA", subtype = "Generation")# Units are GWh diff --git a/R/calcCapacityNuclear.R b/R/calcCapacityNuclear.R index 1907d879..006d3fc0 100644 --- a/R/calcCapacityNuclear.R +++ b/R/calcCapacityNuclear.R @@ -1,5 +1,4 @@ -#' @importFrom magclass setYears calcCapacityNuclear <- function() { ### overall philosophy: diff --git a/R/calcCapacityOffset.R b/R/calcCapacityOffset.R index 7f6e47ef..f094c456 100644 --- a/R/calcCapacityOffset.R +++ b/R/calcCapacityOffset.R @@ -1,10 +1,9 @@ -#' @importFrom magclass getYears<- - calcCapacityOffset <- function() { - x <- readSource("REMIND_11Regi", subtype="deltacapoffset") - getYears(x) <- "y2010" - return(list(x=x,weight=NULL, - unit="TW", - description="global offset of 200MW multiplied with the regional share of PE2SE capacities" - )) + x <- readSource("REMIND_11Regi", subtype = "deltacapoffset") + getYears(x) <- "y2010" + + list(x = x, + weight = NULL, + unit = "TW", + description = "Global offset of 200MW multiplied with the regional share of PE2SE capacities") } diff --git a/R/calcCapital.R b/R/calcCapital.R index 348bd330..6f4f7140 100644 --- a/R/calcCapital.R +++ b/R/calcCapital.R @@ -3,13 +3,12 @@ calcCapital <- function() { # compute macroeconomic capital stock based on capital intensities from PWT and ssp scenarios # t.b.d.: correct for capital stock part that enters energy sectors capital <- readSource("PWT")[, , "rkna"] + gdppwt <- readSource("PWT")[, , "rgdpna"] getNames(capital) <- "kap" - capital[is.na(capital)] <- 0 - gdpppp_hist <- calcOutput("GDPPast", GDPPast = "PWT", aggregate = FALSE) - cap_intensity <- capital / setNames(gdpppp_hist, NULL) + cap_intensity <- capital / setNames(gdppwt, NULL) # use initial gdp as in REMIND which differs from PWT - gdpppp_hist <- calcOutput("GDPPast", aggregate = FALSE) + gdpppp_hist <- calcOutput("GDP", aggregate = FALSE, years = c("y1995", "y2000", "y2005")) gdpppp <- calcOutput("GDP", aggregate = FALSE, years = seq(2005, 2150, 5)) my_scen <- c("gdp_SSP1", "gdp_SSP2", "gdp_SSP3", "gdp_SSP4", "gdp_SSP5", "gdp_SSP2EU", "gdp_SDP", "gdp_SDP_EI", "gdp_SDP_RC", "gdp_SDP_MC") @@ -78,16 +77,11 @@ calcCapital <- function() { quitte::magclass_to_tibble(c("iso3c", NA, NA, NA, "kap")) %>% dplyr::select("iso3c", "kap") - EEK <- calcOutput("Industry_EEK", kap = kap, supplementary = FALSE, - aggregate = FALSE, years = getYears(cap_future)) + EEK <- calcOutput("Industry_EEK", kap = kap, supplementary = FALSE, aggregate = FALSE, years = getYears(cap_future)) # tie outputs together ---- - output <- list( - x = mbind(cap_future, EEK), - weight = NULL, - unit = "trillion 2005US$", - description = "Capital stock at constant 2005 national prices" - ) - - return(output) + list(x = mbind(cap_future, EEK), + weight = NULL, + unit = "trillion 2005US$", + description = "Capital stock, computed using the capital to GDP ratio from PWT, and GDP scenarios from mrdrivers.") } diff --git a/R/calcCement.R b/R/calcCement.R index f0b6ec6c..64ba1591 100644 --- a/R/calcCement.R +++ b/R/calcCement.R @@ -14,8 +14,6 @@ #' @seealso [calcOutput] #' #' @importFrom dplyr anti_join arrange bind_rows filter group_by select ungroup -#' @importFrom magclass as.magpie -#' @importFrom magrittr %>% #' @importFrom rlang .data syms !!! #' @export diff --git a/R/calcCementShare.R b/R/calcCementShare.R index 3ab330bd..59eeec00 100644 --- a/R/calcCementShare.R +++ b/R/calcCementShare.R @@ -14,9 +14,6 @@ #' @seealso [`calcOutput()`] #' #' @importFrom dplyr bind_rows left_join select filter mutate pull -#' @importFrom madrat toolGetMapping calcOutput -#' @importFrom magclass as.magpie dimSums -#' @importFrom magrittr %>% #' @importFrom rlang sym #' @importFrom tibble tribble as_tibble #' @importFrom tidyr pivot_longer complete nesting diff --git a/R/calcClinker_to_cement_ratio.R b/R/calcClinker_to_cement_ratio.R index 55f4f5a9..63ae5e81 100644 --- a/R/calcClinker_to_cement_ratio.R +++ b/R/calcClinker_to_cement_ratio.R @@ -8,7 +8,6 @@ #' #' @seealso [`calcOutput()`], [`readADVANCE_WP2()`], [`convertADVANCE_WP2()`] #' -#' @importFrom madrat readSource calcOutput #' #' @export calcClinker_to_cement_ratio <- function() { diff --git a/R/calcCoalLabourProductivity.R b/R/calcCoalLabourProductivity.R deleted file mode 100644 index a4d8cee8..00000000 --- a/R/calcCoalLabourProductivity.R +++ /dev/null @@ -1,116 +0,0 @@ -#' CalcCoalLabourProductivity -#' calculates historical employment in the coal sector and projects current (2020) and future employment factors (Jobs/PJ) -#' @author Aman Malik -#' @param subtype Either "Employment_factor" or "Employment" -#' @importFrom dplyr left_join - -calcCoalLabourProductivity <- function(subtype){ - Year <- NULL - emp <- calcOutput("ILO",subtype="all",aggregate = F)[,,"Coal and Lignite"] - dias <- readSource("Dias", subtype = "Employment") # Employment data from Dias et al. for EU - dias <- dias[,,"direct.Fuel_supply.Coal"] - #regs <- setdiff(getRegions(dias)[which(dias>0)],c("HUN","ITA","GBR")) #countries in Europe with coal employment - regs <- getRegions(dias)[which(dias>0)] - dias <- dias[regs,,] - dias <- collapseNames(dias) - prod <- readSource(type = "BP",subtype = "Production") # coal production from BP data - prod <- prod[,,c("Coal Production (EJ)","Coal Production (t)")] - prod["ZAF","y2019","Coal Production (t)"] <- 258.5 # overwriting BP value with data from national source - # eur <- dimSums(prod[regs,,c("Coal Production (t)","Coal Production (EJ")],dim = 1)# since EUR is not a region in BP, summing over all countries with coal production - # getRegions(eur) <- "EUR" # making a region EUR - # prod <- mbind(prod,eur)# adding it original data - - # Employment in coal mining from various local (not ILO) sources - - rus_loc <- new.magpie("RUS",years=c(2006:2014,2018),fill = c(169.5,191.4,190.9,173.8,168.8,168.6,168.2,163.1,154.7,146.9)) - rus_loc <- rus_loc*1000 - usa_loc <- new.magpie("USA",years = c(2012:2019),fill = c(84.65,78.1,73.3,64.05,50.73, 51.5, 51.59, 51.89)) - usa_loc <- usa_loc*1000 # source: BLS - ind_loc <- new.magpie("IND",years = c(2019:2010),fill = c(292118,304386, 316210, 327750, 339867, 352282, 364736, 377447, 390243, 404744),names = "Coal") - ind_loc <- ind_loc/0.8 # the above numbers are only for Coal India Limited which produces almost 80% of Indian coal. - ind_loc <- magpiesort(ind_loc)# source: CIL operational statistics - zaf_loc <- new.magpie("ZAF",years = c(2009:2019),fill=c(70791,74025,78580,83244,88039,86106,77747,77259,82372,89647,94297))# source mining south africa - aus_loc <- new.magpie("AUS",c(2000:2019),fill=c(17.1, 20.6, 15, 20.4, 19.4, 26.9, 28.9 ,23.2, 29, 32.4, 36, 47.6, 60, 46.4, 58, 38.7, 42.9, 47.3, 53.8, 57.9)) - aus_loc <- aus_loc*1000 # https://nationalindustryinsights.aisc.net.au/industries/mining-drilling-and-civil-infrastructure/coal-mining - chn_loc <- new.magpie("CHN",years = c(2000,2005,2010,2015,2018),fill = c(3.99,4.36,5.27,4.43,3.21)) # https://www.ncbi.nlm.nih.gov/pmc/articles/PMC7442150/ - chn_loc <- chn_loc*1000000*0.93 # above numbers are actually total of coal power and coal mining. Assuming 7% of labour is coal mining - #rus_prod <- new.magpie("RUS",years = c(1995,1997,1999,2001,2003,2005,2008,2009,2011,2012),fill = c(237,306, 449,563, 648,726,1151,1174,1350,1439))# from Rutovitz 2015 - #rus_loc <- prod["RUS",getYears(rus_prod),"Coal Production (t)"]*1000000/rus_prod - - all <- bind_rows(as.data.frame(usa_loc),as.data.frame(ind_loc),as.data.frame(zaf_loc),as.data.frame(aus_loc), - as.data.frame(chn_loc),as.data.frame(emp["IDN",c(2012:2015),"Coal and Lignite"]*1000), - as.data.frame(dias),as.data.frame(rus_loc)) %>% - select(-1,-4) %>% - mutate(Year=as.integer(as.character(Year))) - - x <- as.magpie(all,spatial=1,temporal=2) - x <- magpiesort(x) - x <- toolCountryFill(x,fill=0) - x[is.na(x)] <- 0 - - -if (subtype=="Employment"){ - return(list( - x=x, - weight=NULL, - unit="", - description="Total Employment in coal and lignite sector")) - } - -if (subtype=="Employment_factor"){ - - x_tmp <- x/(prod[getRegions(x),getYears(x),"Coal Production (EJ)"]*1000) # historical values - - prod <- prod[,,"Coal Production (EJ)"]*1000 # converting to PJ - #ef <- x/prod[getRegions(x),getYears(x),] - # employment factors in 2020, taking nearest historical value - ef_fut <- new.magpie(c("AUS","CHN",regs,"IDN","IND","RUS","USA","ZAF"),seq(2020,2050,5),names = "EF") - ef_fut[,2020,] <- c(4.4,39,rep(32,12),15,28.5,16,3.6,15.6) - imp <- new.magpie(getRegions(ef_fut),seq(2025,2050,5)) - imp["AUS",c(2025,2030),] <- 1.5 - imp["AUS",seq(2035,2050,5),] <- -0.6 - imp["CHN",c(2025,2030),] <- -8 - imp["CHN",seq(2035,2050,5),] <- -3 - imp[regs,c(2025,2030),] <- -2.5 - imp[regs,seq(2035,2050,5),] <- -1.7 - imp["IDN",c(2025,2030),] <- -5 - imp["IDN",seq(2035,2050,5),] <- -3 - imp["IND",c(2025,2030),] <- -7 - imp["IND",seq(2035,2050,5),] <- -3 - imp["RUS",c(2025,2030),] <- -6 - imp["RUS",seq(2035,2050,5),] <- -3 - imp["USA",c(2025,2030),] <- -1.1 - imp["USA",seq(2035,2050,5),] <- -0.3 - imp["ZAF",c(2025,2030),] <- 1.3 - imp["ZAF",seq(2035,2050,5),] <- -1.8 - - for (i in seq(2025,2030,5)){ - ef_fut[,i,] <- setYears(ef_fut[,2020,],NULL)*(1+0.01*imp[,i,])^(i-2020) - } - - for (i in seq(2035,2050,5)){ - ef_fut[,i,] <- setYears(ef_fut[,2030,],NULL)*(1+0.01*imp[,i,])^(i-2020) - } - # # value for 2050 - # ef_fut[c("USA","AUS"),2050,] <- 4 # for USA and AUS, EF = 4 in 2050 - # ef_fut[setdiff(getRegions(ef_fut),c("USA","AUS")),"y2050",] <- 10 # for all others EF = 10 in 2050 - # - # ef_fut <- time_interpolate(ef_fut,interpolated_year = seq( 2035,2045,5),integrate_interpolated_years = T) - x_tmp <- x_tmp[getRegions(ef_fut),,] - x_final <- new.magpie(cells_and_regions = getRegions(x_tmp),years = base::union(getYears(x_tmp),getYears(ef_fut))) - x_final[,getYears(x_tmp),] <- x_tmp - x_final[,getYears(ef_fut),] <- ef_fut - x_final[is.na(x_final)] <- 0 - x_final <- toolCountryFill(x_final,fill = 0) - x_final[c("ITA","SVK"),"y2015",] <- 32 - - return(list( - x=x_final, - weight=x_final , - unit="Jobs/PJ", - description="Employment factor projections")) - -} - -} - diff --git a/R/calcCoolingSharesAll.R b/R/calcCoolingSharesAll.R index 1888f6fa..23cf7107 100644 --- a/R/calcCoolingSharesAll.R +++ b/R/calcCoolingSharesAll.R @@ -1,5 +1,5 @@ #' Calculate Cooling Type Shares -#' +#' #' This function merges the output of two other functions that calculate REMIND #' input data for the shares of cooling types per electricity technology and #' REMIND region, using as initial information the Davies (2013) data per @@ -7,8 +7,8 @@ #' calculate data for the base year and for future time steps. The source data #' provide most required information but some assumptions on missing data are #' also made. -#' -#' +#' +#' #' @return MAgPIE object on cooling type shares per elecricity technology and #' REMIND region #' @author Ioanna Mouratiadou @@ -16,41 +16,43 @@ #' \code{\link{convertDaviesCooling}}, #' \code{\link{calcCoolingSharesBase}},\code{\link{calcCoolingSharesFuture}} #' @examples -#' -#' \dontrun{ -#' +#' \dontrun{ +#' #' a <- calcOutput("CoolingSharesAll") -#' #' } -#' @importFrom magclass mbind dimSums -#' +#' calcCoolingSharesAll <- function() { + cooloutputBase <- calcOutput("CoolingSharesBase", aggregate = FALSE) + cooloutputFuture <- calcOutput("CoolingSharesFuture", aggregate = FALSE) - cooloutputBase <- calcOutput("CoolingSharesBase", aggregate=FALSE) - cooloutputFuture <- calcOutput("CoolingSharesFuture",aggregate=FALSE) - # merge two datasets - outputAll <- mbind(cooloutputBase,cooloutputFuture) - - #assign aggregation weight - weight <- dimSums(calcOutput("IO",subtype="output",aggregate=FALSE)[,2010,c("feelb","feeli")],dim=3) - - #set weights to zero for countries that were not contained in the GCAM2ISO mapping - weight["ALA",,] <- 0 - weight["ATA",,] <- 0 - weight["BES",,] <- 0 - weight["BLM",,] <- 0 - weight["CUW",,] <- 0 - weight["GGY",,] <- 0 - weight["IMN",,] <- 0 - weight["JEY",,] <- 0 - weight["MAF",,] <- 0 - weight["PSE",,] <- 0 - weight["SSD",,] <- 0 - weight["SXM",,] <- 0 + outputAll <- mbind(cooloutputBase, cooloutputFuture) - return(list(x=outputAll, weight=weight, - unit="% of cooling type technologies", - description="Cooling shares for different cooling technologies based on Davies et al. (2013) publication and using electricity use weights (aggregated based on IEA World Energy Balances, 2014) for regional mapping" + # assign aggregation weight + weight <- dimSums(calcOutput("IO", subtype = "output", aggregate = FALSE)[, 2010, c("feelb", "feeli")], dim = 3) + + # set weights to zero for countries that were not contained in the GCAM2ISO mapping + weight["ALA", , ] <- 0 + weight["ATA", , ] <- 0 + weight["BES", , ] <- 0 + weight["BLM", , ] <- 0 + weight["CUW", , ] <- 0 + weight["GGY", , ] <- 0 + weight["IMN", , ] <- 0 + weight["JEY", , ] <- 0 + weight["MAF", , ] <- 0 + weight["PSE", , ] <- 0 + weight["SSD", , ] <- 0 + weight["SXM", , ] <- 0 + + return(list( + x = outputAll, + weight = weight, + unit = "% of cooling type technologies", + description = c( + "Cooling shares for different cooling technologies based on ", + "Davies et al. (2013) publication and using electricity use weights (aggregated ", + "based on IEA World Energy Balances, 2014) for regional mapping" + ) )) } diff --git a/R/calcCoolingSharesBase.R b/R/calcCoolingSharesBase.R index 86453723..07d3f511 100644 --- a/R/calcCoolingSharesBase.R +++ b/R/calcCoolingSharesBase.R @@ -1,12 +1,12 @@ #' Calculate Cooling Type Shares for the Base Year -#' +#' #' This function calculates REMIND input data for the shares of cooling types #' per electricity technology and REMIND region in 2005, using as initial #' information the Davies (2013) data per electricity technology and GCAM #' region. The source data provide most required information but some #' assumptions on missing data are also made. -#' -#' +#' +#' #' @return MAgPIE object on cooling type shares per elecricity technology and #' REMIND region #' @author Lavinia Baumstark, Ioanna Mouratiadou @@ -14,107 +14,111 @@ #' \code{\link{convertDaviesCooling}}, #' \code{\link{calcCoolingSharesAll}},\code{\link{calcCoolingSharesFuture}} #' @examples -#' -#' \dontrun{ +#' \dontrun{ #' a <- calcOutput("CoolingSharesBase") #' } -#' @importFrom magclass getNames<- -#' @importFrom readxl read_excel -#' @importFrom madrat toolGetMapping - - - calcCoolingSharesBase <- function() { - # read in data - data <- readSource("DaviesCooling", subtype="dataBase") - getNames(data)[grepl("^Sea",getNames(data))] <- "Sea.NA" - + data <- readSource("DaviesCooling", subtype = "dataBase") + getNames(data)[grepl("^Sea", getNames(data))] <- "Sea.NA" + # seperate data for Sea water - Sea <- data[,,"Sea"] - data <- data[,,-which(getNames(data)=="Sea.NA")] - - id <- getNames(data,dim=1) - + Sea <- data[, , "Sea"] + data <- data[, , -which(getNames(data) == "Sea.NA")] + + id <- getNames(data, dim = 1) + # calculate pond - pond <- new.magpie(getRegions(data),getYears(data),id) + pond <- new.magpie(getRegions(data), getYears(data), id) for (i in id) { - pond[,,i] <- 100 - dimSums(data[,,i],dim=3.2) + pond[, , i] <- 100 - dimSums(data[, , i], dim = 3.2) } - getNames(pond) <- paste(getNames(pond),"Pond",sep=".") - + getNames(pond) <- paste(getNames(pond), "Pond", sep = ".") + # add pond to data - data <- mbind(data,pond) - + data <- mbind(data, pond) + # calculate sea water - sea_new <- new.magpie(getRegions(data),getYears(data),id) + sea_new <- new.magpie(getRegions(data), getYears(data), id) for (i in id) { - sea_new[,,i] <- data[,,paste(i,"1-thru",sep=".")] * Sea/100 + sea_new[, , i] <- data[, , paste(i, "1-thru", sep = ".")] * Sea / 100 } - getNames(sea_new) <- paste(getNames(sea_new),"Sea",sep=".") - + getNames(sea_new) <- paste(getNames(sea_new), "Sea", sep = ".") + # correct 1-thru-data - data[,,"1-thru"] <- data[,,"1-thru"] * (1 - Sea/100) + data[, , "1-thru"] <- data[, , "1-thru"] * (1 - Sea / 100) # add sea data to data - data <- mbind(data,sea_new) - + data <- mbind(data, sea_new) + # check if all categories sum up to 100% - check <- new.magpie(getRegions(data),getYears(data),id) + check <- new.magpie(getRegions(data), getYears(data), id) for (i in id) { - check[,,i] <- dimSums(data[,,i],dim=3.2) + check[, , i] <- dimSums(data[, , i], dim = 3.2) } - if(!all(check==100)) { stop("sum of categorie XXX is not 100%")} - + if (!all(check == 100)) { + stop("sum of categorie XXX is not 100%") + } + # read in mapping to REMIND technologies - map_table <- read_excel(toolGetMapping(type = "sectoral", - name = "TechnologyMappingDavies2REMIND.xlsx", - returnPathOnly = TRUE, where = "mappingfolder")) + map_table <- toolGetMapping( + type = "sectoral", + name = "techmappingDaviesToREMIND.csv", + where = "mrremind" + ) map <- list() - map$davies <- paste(map_table$'Davies Source/Technology',map_table$'Davies Cooling',sep=".") - map$remind <- paste(map_table$'REMIND Technology',map_table$'REMIND Cooling',sep=".") - + map$davies <- paste(map_table$Davies.Source.Technology, map_table$Davies.Cooling, sep = ".") + map$remind <- paste(map_table$REMIND.Technology, map_table$REMIND.Cooling, sep = ".") + # calculate REMIND input in REMIND categories - output <- new.magpie(getRegions(data),getYears(data),map$remind) - output[,,] <- 0 - for(d in 1:length(map$davies)){ - if( !map$davies[d] == "-.-"){ - output[,,map$remind[d]] <- data[,,map$davies[d]] + output <- new.magpie(getRegions(data), getYears(data), map$remind) + output[, , ] <- 0 + for (d in 1:length(map$davies)) { + if (!map$davies[d] == "-.-") { + output[, , map$remind[d]] <- data[, , map$davies[d]] } } - + + # remove no longer used technologies pcc and pco + output <- output[, , c("pcc", "pco"), invert = TRUE] + # add assumed data - output[,,"geohdr.tower"] <- 70 - output[,,"geohdr.dry"] <- 20 - output[,,"geohdr.hybrid"] <- 10 - output[,,"hydro.default"] <- 100 - output[,,"wind.default"] <- 100 - output[,,"spv.default"] <- 100 - output[,,"csp.tower"] <- 70 - output[,,"csp.dry"] <- 20 - output[,,"csp.hybrid"] <- 10 - - outputBase <- new.magpie(getRegions(output),c(2005),getNames(output)) - outputBase[,,] <- output[,,] - - #assign aggregation weight - weight <- dimSums(calcOutput("IO",subtype="output",aggregate=FALSE)[,2010,c("feelb","feeli")],dim=3) - - #set weights to zero for countries that were not contained in the GCAM2ISO mapping - weight["ALA",,] <- 0 - weight["ATA",,] <- 0 - weight["BES",,] <- 0 - weight["BLM",,] <- 0 - weight["CUW",,] <- 0 - weight["GGY",,] <- 0 - weight["IMN",,] <- 0 - weight["JEY",,] <- 0 - weight["MAF",,] <- 0 - weight["PSE",,] <- 0 - weight["SSD",,] <- 0 - weight["SXM",,] <- 0 - - return(list(x=outputBase,weight=weight, - unit="% of cooling type technologies", - description="Cooling shares for different cooling technologies based on Davies et al. (2013) publication and using electricity use weights (aggregated based on IEA World Energy Balances, 2014) for regional mapping" + output[, , "geohdr.tower"] <- 70 + output[, , "geohdr.dry"] <- 20 + output[, , "geohdr.hybrid"] <- 10 + output[, , "hydro.default"] <- 100 + output[, , "wind.default"] <- 100 + output[, , "spv.default"] <- 100 + output[, , "csp.tower"] <- 70 + output[, , "csp.dry"] <- 20 + output[, , "csp.hybrid"] <- 10 + + outputBase <- new.magpie(getRegions(output), c(2005), getNames(output)) + outputBase[, , ] <- output[, , ] + + # assign aggregation weight + weight <- dimSums(calcOutput("IO", subtype = "output", aggregate = FALSE)[, 2010, c("feelb", "feeli")], dim = 3) + + # set weights to zero for countries that were not contained in the GCAM2ISO mapping + weight["ALA", , ] <- 0 + weight["ATA", , ] <- 0 + weight["BES", , ] <- 0 + weight["BLM", , ] <- 0 + weight["CUW", , ] <- 0 + weight["GGY", , ] <- 0 + weight["IMN", , ] <- 0 + weight["JEY", , ] <- 0 + weight["MAF", , ] <- 0 + weight["PSE", , ] <- 0 + weight["SSD", , ] <- 0 + weight["SXM", , ] <- 0 + + return(list( + x = outputBase, weight = weight, + unit = "% of cooling type technologies", + description = c( + "Cooling shares for different cooling technologies based on Davies et al. (2013) ", + "publication and using electricity use weights (aggregated based on IEA World ", + "Energy Balances, 2014) for regional mapping" + ) )) } diff --git a/R/calcCoolingSharesFuture.R b/R/calcCoolingSharesFuture.R index 00dab9de..a322e278 100644 --- a/R/calcCoolingSharesFuture.R +++ b/R/calcCoolingSharesFuture.R @@ -1,12 +1,12 @@ #' Calculate Cooling Type Shares for Future Timesteps -#' +#' #' This function calculates REMIND input data for the shares of cooling types #' per electricity technology and REMIND region in post-2020, using as initial #' information the Davies (2013) data per electricity technology and GCAM #' region. The source data provide most required information but some #' assumptions on missing data are also made. -#' -#' +#' +#' #' @return MAgPIE object on cooling type shares per elecricity technology and #' REMIND region #' @author Ioanna Mouratiadou @@ -14,104 +14,114 @@ #' \code{\link{convertDaviesCooling}}, #' \code{\link{calcCoolingSharesAll}},\code{\link{calcCoolingSharesBase}} #' @examples -#' -#' \dontrun{ +#' \dontrun{ #' a <- calcOutput("CoolingSharesFuture") -#' #' } -#' @importFrom magclass getNames<- dimSums mbind -#' @importFrom readxl read_excel -#' +#' calcCoolingSharesFuture <- function() { - # read in data - data <- readSource("DaviesCooling", subtype="dataFuture") - getNames(data)[grepl("^Sea",getNames(data))] <- "Sea.NA" - + data <- readSource("DaviesCooling", subtype = "dataFuture") + getNames(data)[grepl("^Sea", getNames(data))] <- "Sea.NA" + # seperate data for Sea water - Sea <- data[,,"Sea"] - data <- data[,,-which(getNames(data)=="Sea.NA")] - - id <- getNames(data,dim=1) - + Sea <- data[, , "Sea"] + data <- data[, , -which(getNames(data) == "Sea.NA")] + + id <- getNames(data, dim = 1) + # calculate pond - pond <- new.magpie(getRegions(data),getYears(data),id) + pond <- new.magpie(getRegions(data), getYears(data), id) for (i in id) { - pond[,,i] <- 100 - dimSums(data[,,i],dim=3.2) + pond[, , i] <- 100 - dimSums(data[, , i], dim = 3.2) } - getNames(pond) <- paste(getNames(pond),"Pond",sep=".") - + getNames(pond) <- paste(getNames(pond), "Pond", sep = ".") + # add pond to data - data <- mbind(data,pond) - + data <- mbind(data, pond) + # calculate sea water - sea_new <- new.magpie(getRegions(data),getYears(data),id) + sea_new <- new.magpie(getRegions(data), getYears(data), id) for (i in id) { - sea_new[,,i] <- data[,,paste(i,"1-thru",sep=".")] * Sea/100 + sea_new[, , i] <- data[, , paste(i, "1-thru", sep = ".")] * Sea / 100 } - getNames(sea_new) <- paste(getNames(sea_new),"Sea",sep=".") - + getNames(sea_new) <- paste(getNames(sea_new), "Sea", sep = ".") + # correct 1-thru-data - data[,,"1-thru"] <- data[,,"1-thru"] * (1 - Sea/100) + data[, , "1-thru"] <- data[, , "1-thru"] * (1 - Sea / 100) # add sea data to data - data <- mbind(data,sea_new) - + data <- mbind(data, sea_new) + # check if all categories sum up to 100% - check <- new.magpie(getRegions(data),getYears(data),id) + check <- new.magpie(getRegions(data), getYears(data), id) for (i in id) { - check[,,i] <- dimSums(data[,,i],dim=3.2) + check[, , i] <- dimSums(data[, , i], dim = 3.2) } - if(!all(check==100)) { stop("sum of categorie XXX is not 100%")} - + if (!all(check == 100)) { + stop("sum of categorie XXX is not 100%") + } + # read in mapping to REMIND technologies - map_table <- read_excel(toolGetMapping(type = "sectoral", name = "TechnologyMappingDavies2REMIND.xlsx", - returnPathOnly = TRUE, where = "mappingfolder")) + map_table <- toolGetMapping( + type = "sectoral", + name = "techmappingDaviesToREMIND.csv", + where = "mrremind" + ) map <- list() - map$davies <- paste(map_table$'Davies Source/Technology',map_table$'Davies Cooling',sep=".") - map$remind <- paste(map_table$'REMIND Technology',map_table$'REMIND Cooling',sep=".") - + map$davies <- paste(map_table$Davies.Source.Technology, map_table$Davies.Cooling, sep = ".") + map$remind <- paste(map_table$REMIND.Technology, map_table$REMIND.Cooling, sep = ".") + + # calculate REMIND input in REMIND categories - output <- new.magpie(getRegions(data),getYears(data),map$remind) - output[,,] <- 0 - for(d in 1:length(map$davies)){ - if( !map$davies[d] == "-.-"){ - output[,,map$remind[d]] <- data[,,map$davies[d]] + output <- new.magpie(getRegions(data), getYears(data), map$remind) + output[, , ] <- 0 + for (d in 1:length(map$davies)) { + if (!map$davies[d] == "-.-") { + output[, , map$remind[d]] <- data[, , map$davies[d]] } } - + + # remove no longer used technologies pcc and pco + output <- output[, , c("pcc", "pco"), invert = TRUE] + # add assumed data - output[,,"geohdr.tower"] <- 70 - output[,,"geohdr.dry"] <- 20 - output[,,"geohdr.hybrid"] <- 10 - output[,,"hydro.default"] <- 100 - output[,,"wind.default"] <- 100 - output[,,"spv.default"] <- 100 - output[,,"csp.tower"] <- 70 - output[,,"csp.dry"] <- 20 - output[,,"csp.hybrid"] <- 10 - - outputFuture <- new.magpie(getRegions(output),c(2020),getNames(output)) - outputFuture[,,] <- output[,,] - - #assign aggregation weight - weight <- dimSums(calcOutput("IO",subtype="output",aggregate=FALSE)[,2010,c("feelb","feeli")],dim=3) - - #set weights to zero for countries that were not contained in the GCAM2ISO mapping - weight["ALA",,] <- 0 - weight["ATA",,] <- 0 - weight["BES",,] <- 0 - weight["BLM",,] <- 0 - weight["CUW",,] <- 0 - weight["GGY",,] <- 0 - weight["IMN",,] <- 0 - weight["JEY",,] <- 0 - weight["MAF",,] <- 0 - weight["PSE",,] <- 0 - weight["SSD",,] <- 0 - weight["SXM",,] <- 0 - - return(list(x=outputFuture,weight=weight, - unit="% of cooling type technologies", - description="Cooling shares for different cooling technologies based on Davies et al. (2013) publication and using electricity use weights (aggregated based on IEA World Energy Balances, 2014) for regional mapping" + output[, , "geohdr.tower"] <- 70 + output[, , "geohdr.dry"] <- 20 + output[, , "geohdr.hybrid"] <- 10 + output[, , "hydro.default"] <- 100 + output[, , "wind.default"] <- 100 + output[, , "spv.default"] <- 100 + output[, , "csp.tower"] <- 70 + output[, , "csp.dry"] <- 20 + output[, , "csp.hybrid"] <- 10 + + outputFuture <- new.magpie(getRegions(output), c(2020), getNames(output)) + outputFuture[, , ] <- output[, , ] + + # assign aggregation weight + weight <- dimSums(calcOutput("IO", subtype = "output", aggregate = FALSE)[, 2010, c("feelb", "feeli")], dim = 3) + + # set weights to zero for countries that were not contained in the GCAM2ISO mapping + weight["ALA", , ] <- 0 + weight["ATA", , ] <- 0 + weight["BES", , ] <- 0 + weight["BLM", , ] <- 0 + weight["CUW", , ] <- 0 + weight["GGY", , ] <- 0 + weight["IMN", , ] <- 0 + weight["JEY", , ] <- 0 + weight["MAF", , ] <- 0 + weight["PSE", , ] <- 0 + weight["SSD", , ] <- 0 + weight["SXM", , ] <- 0 + + return(list( + x = outputFuture, + weight = weight, + unit = "% of cooling type technologies", + description = c( + "Cooling shares for different cooling technologies based on ", + "Davies et al. (2013) publication and using electricity use weights ", + "(aggregated based on IEA World Energy Balances, 2014) for regional mapping" + ) )) } diff --git a/R/calcCostsTrade.R b/R/calcCostsTrade.R index ccd13d8c..e9124448 100644 --- a/R/calcCostsTrade.R +++ b/R/calcCostsTrade.R @@ -1,24 +1,25 @@ #' Calculate trade costs -#' +#' #' Provides REMIND data for PE tradecosts (energy losses on import). -#' -#' +#' +#' #' @return REMIND data forPE tradecosts (energy losses on import) and #' corresonding weights (1) as a list of two MAgPIE objects #' @author Lavinia Baumstark #' @seealso \code{\link{calcOutput}}, \code{\link{readSource}} #' @examples -#' -#' \dontrun{ +#' \dontrun{ #' calcOutput("calcCostsTrade") #' } -#' +#' calcCostsTrade <- function() { x <- readSource("REMIND_11Regi", "tradecost") - w <- new.magpie(getRegions(x),"y2005",fill=1) - - return(list(x=x, - weight=w, - unit="share", - description="energy costs in share (0..1)")) + w <- new.magpie(getRegions(x), "y2005", fill = 1) + + return(list( + x = x, + weight = w, + unit = "share", + description = "energy costs in share (0..1)" + )) } diff --git a/R/calcCostsWeathering.R b/R/calcCostsWeathering.R index 69b5674c..05d1ebc1 100644 --- a/R/calcCostsWeathering.R +++ b/R/calcCostsWeathering.R @@ -1,4 +1,4 @@ -#' Calculate costs of transport of enahnced weathering +#' Calculate costs of transport of enhanced weathering #' #' @return transport costs of spreading rock on the fields #' @seealso \code{\link{calcOutput}} @@ -20,4 +20,4 @@ calcCostsWeathering <- function() { unit = "T$/Gt stone", description = "Transport costs for spreading rocks on the fields. The first rlf corresponds to climate regions (1 - warm, 2 - temperate). The second rlf are the distances of fields from the sources of the material." )) -} \ No newline at end of file +} diff --git a/R/calcDiffInvestCosts.R b/R/calcDiffInvestCosts.R index 5e5f5714..097f4383 100644 --- a/R/calcDiffInvestCosts.R +++ b/R/calcDiffInvestCosts.R @@ -1,217 +1,221 @@ #' Aggregated investment cost data for REMIND regions (based on IEA_WEO) -#' @description Disaggregated investment cost data is aggregated and technologies renamed to REMIND names +#' @description Disaggregated investment cost data is aggregated and technologies renamed to REMIND names #' @details REMIND does not have a classification of coal power plants e.g., sub-critical. Therefore, countries are given coal plant #' costs assuming what type of coal plants are expected to develop there. For other technologies, certain assumptions are taken #' to change to REMIND convention. -#' @param subtype Investment Costs, I&M Costs, and Efficiency -#' @return Magpie object with aggregated but diffrentiated investment costs for some technologies. +#' @param subtype "Invest_Costs", or "Efficiency" +#' @return Magpie object with aggregated but differentiated investment costs for some technologies. #' @author Aman Malik -#' @importFrom magclass new.magpie -#' @importFrom dplyr filter %>% - -calcDiffInvestCosts <- function(subtype){ - if (subtype == "Invest_Costs"){ - x <- readSource("IEA_WEO",subtype="Invest_Costs") - x_REN21 <- readSource("REN21",subtype="investmentCosts") - x_IEA_PVPS <- readSource("IEA_PVPS", subtype="CAPEX") - - # x <- readSource("IEA_WEO")# reading data end of convert function - x[,,] <- as.numeric(x[,,]) # convertng data values into numeric - - # Various mapping files used to get needed mappings, for e.g., South Asia - countries <- toolGetMapping("regionmappingREMIND.csv",where = "mappingfolder",type = "regional") - countries2 <- toolGetMapping("regionmappingMAgPIE.csv",where = "mappingfolder",type = "regional") - countries3 <- toolGetMapping("regionmappingSSP.csv",where = "mappingfolder",type = "regional") - - # For countries in Africa and South Asia (except India) use subcritical plant investment costs as coal plant costs - x[c(countries$CountryCode[countries$RegionCode=="AFR"], - countries2$CountryCode[countries2$RegionCode=="SAS"][-4]),,c("Coal.Steam Coal - SUPERCRITICAL", - "Coal.Steam Coal - ULTRASUPERCRITICAL")] <- 0 - # For countries in LAM, IND, FSU and MEA use supercritical plant investment costs as standard coal plant costs - x[c(countries$CountryCode[countries$RegionCode=="LAM"],"IND", - countries2$CountryCode[countries2$RegionCode=="FSU"], - countries$CountryCode[countries$RegionCode=="MEA"]),,c("Coal.Steam Coal - SUBCRITICAL", - "Coal.Steam Coal - ULTRASUPERCRITICAL")] <- 0 - - # For countries in OECD and CHN use ultrasupercritical investment costs ultrasupercritical plants for "Coal.Steam Coal - ULTRASUPERCRITICAL")] <- 0 - x[c("CHN","KOR","MAC","HKG", countries3$CountryCode[countries3$RegionCode=="OECD"]),,c("Coal.Steam Coal - SUBCRITICAL", - "Coal.Steam Coal - SUPERCRITICAL")] <- 0 - # For remaining countries not covered above, use subcritical plant investment costs - years <- getYears(x) - for (y in years){ - x[getRegions(x)[x[,y,"Coal.Steam Coal - SUBCRITICAL"]!=0 & - x[,y,"Coal.Steam Coal - SUPERCRITICAL"]!=0 & - x[,y,"Coal.Steam Coal - ULTRASUPERCRITICAL"]!=0],y, - c("Coal.Steam Coal - SUPERCRITICAL", - "Coal.Steam Coal - ULTRASUPERCRITICAL")] <- 0 - } - tech_mapping <- toolGetMapping("comparison.csv",where = "mappingfolder",type = "sectoral") %>% filter(!is.na(!!sym("tech"))) - - # create new magpie object with names of corresponding REMIND technologies - x_new <- new.magpie(getRegions(x),names = unique(tech_mapping$tech), years = getYears(x), fill = 0) - - # for "pc" add all types of coal plants so each country has one value of "pc" - x_new[,,"pc"] <- x[,,"Coal.Steam Coal - SUBCRITICAL"] + x[,,"Coal.Steam Coal - SUPERCRITICAL"] + - x[,,"Coal.Steam Coal - ULTRASUPERCRITICAL"] - - # for "spv" take 1/4 of costs from small-scale and 3/4 costs from large scale (utility scale)ildings - x_new[,,"spv"] <- 0.75*x[,,"Renewables.Solar photovoltaics - Large scale"] + 0.25*x[,,"Renewables.Solar photovoltaics - Buildings"] - - # same for hydro - removed when hydro values are fed from "private" data source - #x_new[,,"hydro"] <- 0.75*x[,,"Renewables.Hydropower - large-scale"] + 0.25*x[,,"Renewables.Hydropower - small-scale"] - x_new[,,"hydro"] <- x[,,"Renewables.Hydropower - large-scale"] - # and Biomass CHP - x_new[,,"biochp"] <- 0.75*x[,,"Renewables.Biomass CHP Medium"] + 0.25*x[,,"Renewables.Biomass CHP Small"] - - # for rest of technologies, simply match - further_techs_to_map <- filter(tech_mapping, !(!!sym("tech") %in% c("pc","spv","hydro","biochp"))) - x_new[, , further_techs_to_map$tech] <- as.numeric(x[,,further_techs_to_map$IEA]) - - x_new <- time_interpolate(x_new, c(2025, 2035), integrate_interpolated_years = T) - # overwrite investmetn costs vor renewables with data form REN21 - - x_REN21_wa <- collapseNames(x_REN21[,,"wa"]) # use weighted average - getNames(x_REN21_wa) <- gsub("hydropower","hydro",getNames(x_REN21_wa)) - getNames(x_REN21_wa) <- gsub("Solar PV","spv",getNames(x_REN21_wa)) - getNames(x_REN21_wa) <- gsub("wind-on","wind",getNames(x_REN21_wa)) - x_REN21_wa <- x_REN21_wa[,,c("Biopower","Geothermal Power", "wind-off", "csp"),invert=TRUE] - # use REN21 data for all time steps for hydro - # x_new[,,"hydro"] <- x_REN21_wa[,,"hydro"] - # use REN21 data only for 2015 for spv,csp and wind; all other time steps are 0 - x_new[,,c("spv","wind")] <- 0 - x_new[,2015,c("spv","wind")] <- x_REN21_wa[,,c("spv","wind")] - x_new["JPN",2015,"wind"] <- x_REN21["JPN",,"wind-on.max"] - x_new["JPN",2015,"spv"] <- 2000 # in USD/KW, source attached in input folder IEA_WEO - # (National_Survey_Report_of_PV_Power_Applications_in_Japan_-_2017.pdf) - x_new["JPN",2015,"hydro"] <- 2400 # in USD/KW, source is the 2016 WEO numbers - they seem more reliable here than the Oceania data of <2000USD/kW - # as Japan is not substantially expanding hydro even at high electricity prices - - ### Australia ### - - # for wind 2015: take average of Europe and USA from REN21 (not from "Oceania" as before) - x_new["AUS",2015,c("wind")] <- setNames(dimSums(x_REN21[c("USA","FRA"), ,c("wind-on.wa")], dim = 1)/2, c("wind")) - # for solar pv 2015: take IRENA number for large-scale solar investment cost by 2016 - # (neglect that rooftop is a bit more expensive) - # source: https://www.irena.org/-/media/Files/IRENA/Agency/Publication/2018/Jan/IRENA_2017_Power_Costs_2018.pdf - x_new["AUS",2015,"spv"] <- 1400 # in USD/kW - - - ### RP/FS: add PV investment cost for 2020 - # based on IEA PVPS data from 2018, - # some regions manually adjusted - - # add some manual adjustments to IEA PVPS data for 2020 PV investment cost input data - regmapping <- toolGetMapping("regionmappingH12.csv",where = "mappingfolder",type = "regional") - x_adj <- new.magpie(unique(regmapping$RegionCode), years = "y2020",fill = NA) - - # CAZ: The Australian utility-scale market saw a stong jump upwards in 2018. - # It is likely that the reported prices are a result of this jump, as in contrast, - # rooftop is already well-established and has prices around 1.25$/W. - # Accordingly, we expect that by 2020, the utility-scale solar market will be more - # in equilibrium and have prices below the current rooftop prices - x_adj["CAZ",,] <- 1200 - # IND: Other sources for Indian utility-scale prices (IRENA, WEO, REN21) are more in the range of ~800$/kW. - # Also, the reports around failed auctions and non-delivery of projects might indicate that - # the stated prices are below cost. - x_adj["IND",,] <- 700 - # JPN: We assume that Japan prices will be downward-influenced by the low prices realized everywhere else in Asia. - x_adj["JPN",,] <- 1500 - # LAM: IRENA states utility-scale prices in the range of ~1400-1500$/kW for LAM. - # Recent auctions in individual countries indicate lower prices, but it is unlikely that - # all the countries will immediately achieve the lowest prices realized in some auctions - x_adj["LAM",,] <- 950 - # MEA: IRENA states utility-scale prices in the range of ~1250$/kW for MEA - # Recent auctions in individual countries indicate lower prices, - # but it is unlikely that all the countries will immediately achieve - # the lowest prices realized in some auctions - x_adj["MEA",,] <- 850 - # REF: Very different costs in IRENA (2300) and REN21 (1300) - - # but unlikely to have higher capital costs than severly space-constrained Japan - x_adj["REF",,] <- 1400 - # SSA: IRENA states prices of ~1600$/W, but very likely that prices are currently decreasing through learning - # from the low prices in North African countries. - x_adj["SSA",,] <- 1300 - - # disaggregate adjustments to iso level - x_adj_iso <- toolAggregate(x_adj, regmapping) - - # regions which have not been manually adjusted -> replace by original IEA PVPS data - x_adj_iso[which(is.na(x_adj_iso))] <- x_IEA_PVPS[which(is.na(x_adj_iso))] - # add new 2020 values PV - x_new[,"y2020","spv"] <- x_adj_iso - - - - - - - - - - return(list(x = x_new,weight= x_new ,unit="USD$/KW 2015",description="Investment costs data" )) - -} +#' @importFrom dplyr filter + +calcDiffInvestCosts <- function(subtype) { + if (subtype == "Invest_Costs") { + x <- readSource("IEA_WEO", subtype = "Invest_Costs") + + x[, , ] <- as.numeric(x[, , ]) # convertng data values into numeric - else if (subtype=="O&M_Costs"){ - x <- readSource("IEA_WEO",subtype="Invest_Costs") - - } else if (subtype=="Efficiency"){ - x <- readSource("IEA_WEO",subtype="Efficiency") - x[,,] <- as.numeric(x[,,]) # convertng data values into numeric - # Various mapping files used to get needed mappings, for e.g., South Asia - countries <- toolGetMapping("regionmappingREMIND.csv",where = "mappingfolder",type = "regional") - countries2 <- toolGetMapping("regionmappingMAgPIE.csv",where = "mappingfolder",type = "regional") - countries3 <- toolGetMapping("regionmappingSSP.csv",where = "mappingfolder",type = "regional") - + countries <- toolGetMapping("regionmappingREMIND.csv", where = "mappingfolder", type = "regional") + countries2 <- toolGetMapping("regionmappingMAgPIE.csv", where = "mappingfolder", type = "regional") + countries3 <- toolGetMapping("regionmappingSSP.csv", where = "mappingfolder", type = "regional") + # For countries in Africa and South Asia (except India) use subcritical plant investment costs as coal plant costs - x[c(countries$CountryCode[countries$RegionCode=="AFR"], - countries2$CountryCode[countries2$RegionCode=="SAS"][-4]),,c("Coal.Steam Coal - SUPERCRITICAL", - "Coal.Steam Coal - ULTRASUPERCRITICAL")] <- 0 + x[c( + countries$CountryCode[countries$RegionCode == "AFR"], + countries2$CountryCode[countries2$RegionCode == "SAS"][-4] + ), , c( + "Coal.Steam Coal - SUPERCRITICAL", + "Coal.Steam Coal - ULTRASUPERCRITICAL" + )] <- 0 # For countries in LAM, IND, FSU and MEA use supercritical plant investment costs as standard coal plant costs - x[c(countries$CountryCode[countries$RegionCode=="LAM"],"IND", - countries2$CountryCode[countries2$RegionCode=="FSU"], - countries$CountryCode[countries$RegionCode=="MEA"]),,c("Coal.Steam Coal - SUBCRITICAL", - "Coal.Steam Coal - ULTRASUPERCRITICAL")] <- 0 - + x[c( + countries$CountryCode[countries$RegionCode == "LAM"], "IND", + countries2$CountryCode[countries2$RegionCode == "FSU"], + countries$CountryCode[countries$RegionCode == "MEA"] + ), , c( + "Coal.Steam Coal - SUBCRITICAL", + "Coal.Steam Coal - ULTRASUPERCRITICAL" + )] <- 0 + # For countries in OECD and CHN use ultrasupercritical investment costs ultrasupercritical plants for "Coal.Steam Coal - ULTRASUPERCRITICAL")] <- 0 - x[c("CHN","KOR","MAC","HKG", countries3$CountryCode[countries3$RegionCode=="OECD"]),,c("Coal.Steam Coal - SUBCRITICAL", - "Coal.Steam Coal - SUPERCRITICAL")] <- 0 + x[c("CHN", "KOR", "MAC", "HKG", countries3$CountryCode[countries3$RegionCode == "OECD"]), , c( + "Coal.Steam Coal - SUBCRITICAL", + "Coal.Steam Coal - SUPERCRITICAL" + )] <- 0 # For remaining countries not covered above, use subcritical plant investment costs years <- getYears(x) - for (y in years){ - x[getRegions(x)[x[,y,"Coal.Steam Coal - SUBCRITICAL"]!=0 & - x[,y,"Coal.Steam Coal - SUPERCRITICAL"]!=0 & - x[,y,"Coal.Steam Coal - ULTRASUPERCRITICAL"]!=0],y, - c("Coal.Steam Coal - SUPERCRITICAL", - "Coal.Steam Coal - ULTRASUPERCRITICAL")] <- 0 + for (y in years) { + x[ + getRegions(x)[x[, y, "Coal.Steam Coal - SUBCRITICAL"] != 0 & + x[, y, "Coal.Steam Coal - SUPERCRITICAL"] != 0 & + x[, y, "Coal.Steam Coal - ULTRASUPERCRITICAL"] != 0], y, + c( + "Coal.Steam Coal - SUPERCRITICAL", + "Coal.Steam Coal - ULTRASUPERCRITICAL" + ) + ] <- 0 } - tech_mapping <- toolGetMapping("comparison.csv",where = "mappingfolder",type = "sectoral") %>% filter(!is.na(!!sym("tech"))) + tech_mapping <- toolGetMapping("techmappingIeaWeoPgAssumptions.csv", where = "mrremind", type = "sectoral") %>% + filter(!is.na(!!sym("tech"))) # create new magpie object with names of corresponding REMIND technologies x_new <- new.magpie(getRegions(x), names = unique(tech_mapping$tech), years = getYears(x), fill = 0) - + # for "pc" add all types of coal plants so each country has one value of "pc" - x_new[,,"pc"] <- x[,,"Coal.Steam Coal - SUBCRITICAL"] + x[,,"Coal.Steam Coal - SUPERCRITICAL"] + - x[,,"Coal.Steam Coal - ULTRASUPERCRITICAL"] - - # for rest of technologies, simply match - further_techs_to_map <- filter(tech_mapping, !(!!sym("tech") %in% c("pc","spv","hydro","biochp"))) - x_new[, , further_techs_to_map$tech] <- as.numeric(x[,,further_techs_to_map$IEA]) - - x_new <- time_interpolate(x_new,c(2025,2035),integrate_interpolated_years = T) - - return(list(x = x_new,weight= x_new ,unit="NA",description="Efficiency data" )) - } - - - - - if (subtype=="Invest_Costs"|subtype=="O&M_Costs"){ - - return(list(x = x_new,weight= x_new ,unit="USD$/KW 2015",description="Investment costs data" )) - - } - - + x_new[, , "pc"] <- x[, , "Coal.Steam Coal - SUBCRITICAL"] + x[, , "Coal.Steam Coal - SUPERCRITICAL"] + + x[, , "Coal.Steam Coal - ULTRASUPERCRITICAL"] + + # for "spv" take 1/4 of costs from small-scale and 3/4 costs from large scale (utility scale)ildings + x_new[, , "spv"] <- 0.75 * x[, , "Renewables.Solar photovoltaics - Large scale"] + 0.25 * x[, , "Renewables.Solar photovoltaics - Buildings"] + + # same for hydro - removed when hydro values are fed from "private" data source + # x_new[,,"hydro"] <- 0.75*x[,,"Renewables.Hydropower - large-scale"] + 0.25*x[,,"Renewables.Hydropower - small-scale"] + x_new[, , "hydro"] <- x[, , "Renewables.Hydropower - large-scale"] + # and Biomass CHP + x_new[, , "biochp"] <- 0.75 * x[, , "Renewables.Biomass CHP Medium"] + 0.25 * x[, , "Renewables.Biomass CHP Small"] + + # for rest of technologies, simply match + further_techs_to_map <- filter(tech_mapping, !(!!sym("tech") %in% c("pc", "spv", "hydro", "biochp"))) + x_new[, , further_techs_to_map$tech] <- as.numeric(x[, , further_techs_to_map$IEA]) + + x_new <- time_interpolate(x_new, c(2025, 2035), integrate_interpolated_years = TRUE) + + # overwrite investmetn costs vor renewables with data form REN21 + x_REN21 <- readSource("REN21", subtype = "investmentCosts") + x_REN21_wa <- collapseNames(x_REN21[, , "wa"]) # use weighted average + getNames(x_REN21_wa) <- gsub("hydropower", "hydro", getNames(x_REN21_wa)) + getNames(x_REN21_wa) <- gsub("Solar PV", "spv", getNames(x_REN21_wa)) + getNames(x_REN21_wa) <- gsub("wind-on", "wind", getNames(x_REN21_wa)) + x_REN21_wa <- x_REN21_wa[, , c("Biopower", "Geothermal Power", "wind-off", "csp"), invert = TRUE] + # use REN21 data for all time steps for hydro + # x_new[,,"hydro"] <- x_REN21_wa[,,"hydro"] + # use REN21 data only for 2015 for spv,csp and wind; all other time steps are 0 + x_new[, , c("spv", "wind")] <- 0 + x_new[, 2015, c("spv", "wind")] <- x_REN21_wa[, , c("spv", "wind")] + x_new["JPN", 2015, "wind"] <- x_REN21["JPN", , "wind-on.max"] + x_new["JPN", 2015, "spv"] <- 2000 # in USD/KW, source attached in input folder IEA_WEO + # (National_Survey_Report_of_PV_Power_Applications_in_Japan_-_2017.pdf) + x_new["JPN", 2015, "hydro"] <- 2400 # in USD/KW, source is the 2016 WEO numbers - they seem more reliable here than the Oceania data of <2000USD/kW + # as Japan is not substantially expanding hydro even at high electricity prices + + ### Australia ### + + # for wind 2015: take average of Europe and USA from REN21 (not from "Oceania" as before) + x_new["AUS", 2015, c("wind")] <- setNames(dimSums(x_REN21[c("USA", "FRA"), , c("wind-on.wa")], dim = 1) / 2, c("wind")) + # for solar pv 2015: take IRENA number for large-scale solar investment cost by 2016 + # (neglect that rooftop is a bit more expensive) + # source: https://www.irena.org/-/media/Files/IRENA/Agency/Publication/2018/Jan/IRENA_2017_Power_Costs_2018.pdf + x_new["AUS", 2015, "spv"] <- 1400 # in USD/kW + + ### RP/FS: add PV investment cost for 2020 + # based on IEA PVPS data from 2018, + # some regions manually adjusted + + # add some manual adjustments to IEA PVPS data for 2020 PV investment cost input data + regmapping <- toolGetMapping("regionmappingH12.csv", where = "mappingfolder", type = "regional") + x_adj <- new.magpie(unique(regmapping$RegionCode), years = "y2020", fill = NA) + + # CAZ: The Australian utility-scale market saw a stong jump upwards in 2018. + # It is likely that the reported prices are a result of this jump, as in contrast, + # rooftop is already well-established and has prices around 1.25$/W. + # Accordingly, we expect that by 2020, the utility-scale solar market will be more + # in equilibrium and have prices below the current rooftop prices + x_adj["CAZ", , ] <- 1200 + # IND: Other sources for Indian utility-scale prices (IRENA, WEO, REN21) are more in the range of ~800$/kW. + # Also, the reports around failed auctions and non-delivery of projects might indicate that + # the stated prices are below cost. + x_adj["IND", , ] <- 700 + # JPN: We assume that Japan prices will be downward-influenced by the low prices realized everywhere else in Asia. + x_adj["JPN", , ] <- 1500 + # LAM: IRENA states utility-scale prices in the range of ~1400-1500$/kW for LAM. + # Recent auctions in individual countries indicate lower prices, but it is unlikely that + # all the countries will immediately achieve the lowest prices realized in some auctions + x_adj["LAM", , ] <- 950 + # MEA: IRENA states utility-scale prices in the range of ~1250$/kW for MEA + # Recent auctions in individual countries indicate lower prices, + # but it is unlikely that all the countries will immediately achieve + # the lowest prices realized in some auctions + x_adj["MEA", , ] <- 850 + # REF: Very different costs in IRENA (2300) and REN21 (1300) - + # but unlikely to have higher capital costs than severly space-constrained Japan + x_adj["REF", , ] <- 1400 + # SSA: IRENA states prices of ~1600$/W, but very likely that prices are currently decreasing through learning + # from the low prices in North African countries. + x_adj["SSA", , ] <- 1300 + + # disaggregate adjustments to iso level + x_adj_iso <- toolAggregate(x_adj, regmapping) + + # regions which have not been manually adjusted -> replace by original IEA PVPS data + x_IEA_PVPS <- readSource("IEA_PVPS", subtype = "CAPEX") + x_adj_iso[which(is.na(x_adj_iso))] <- x_IEA_PVPS[which(is.na(x_adj_iso))] + + # add new 2020 values PV + x_new[, "y2020", "spv"] <- x_adj_iso + + return(list(x = x_new, weight = x_new, unit = "USD$/KW 2015", description = "Investment costs data")) + } else if (subtype == "Efficiency") { + x <- readSource("IEA_WEO", subtype = "Efficiency") + x[, , ] <- as.numeric(x[, , ]) # converting data values into numeric + + # Various mapping files used to get needed mappings, for e.g., South Asia + countries <- toolGetMapping("regionmappingREMIND.csv", where = "mappingfolder", type = "regional") + countries2 <- toolGetMapping("regionmappingMAgPIE.csv", where = "mappingfolder", type = "regional") + countries3 <- toolGetMapping("regionmappingSSP.csv", where = "mappingfolder", type = "regional") + + # For countries in Africa and South Asia (except India) use subcritical plant investment costs as coal plant costs + x[c( + countries$CountryCode[countries$RegionCode == "AFR"], + countries2$CountryCode[countries2$RegionCode == "SAS"][-4] + ), , c( + "Coal.Steam Coal - SUPERCRITICAL", + "Coal.Steam Coal - ULTRASUPERCRITICAL" + )] <- 0 + # For countries in LAM, IND, FSU and MEA use supercritical plant investment costs as standard coal plant costs + x[c( + countries$CountryCode[countries$RegionCode == "LAM"], "IND", + countries2$CountryCode[countries2$RegionCode == "FSU"], + countries$CountryCode[countries$RegionCode == "MEA"] + ), , c( + "Coal.Steam Coal - SUBCRITICAL", + "Coal.Steam Coal - ULTRASUPERCRITICAL" + )] <- 0 + + # For countries in OECD and CHN use ultrasupercritical investment costs ultrasupercritical plants for "Coal.Steam Coal - ULTRASUPERCRITICAL")] <- 0 + x[c("CHN", "KOR", "MAC", "HKG", countries3$CountryCode[countries3$RegionCode == "OECD"]), , c( + "Coal.Steam Coal - SUBCRITICAL", + "Coal.Steam Coal - SUPERCRITICAL" + )] <- 0 + # For remaining countries not covered above, use subcritical plant investment costs + years <- getYears(x) + for (y in years) { + x[ + getRegions(x)[x[, y, "Coal.Steam Coal - SUBCRITICAL"] != 0 & + x[, y, "Coal.Steam Coal - SUPERCRITICAL"] != 0 & + x[, y, "Coal.Steam Coal - ULTRASUPERCRITICAL"] != 0], y, + c( + "Coal.Steam Coal - SUPERCRITICAL", + "Coal.Steam Coal - ULTRASUPERCRITICAL" + ) + ] <- 0 + } + + tech_mapping <- toolGetMapping("techmappingIeaWeoPgAssumptions.csv", where = "mrremind", type = "sectoral") %>% + filter(!is.na(!!sym("tech"))) + + # create new magpie object with names of corresponding REMIND technologies + x_new <- new.magpie(getRegions(x), names = unique(tech_mapping$tech), years = getYears(x), fill = 0) + + # for "pc" add all types of coal plants so each country has one value of "pc" + x_new[, , "pc"] <- x[, , "Coal.Steam Coal - SUBCRITICAL"] + x[, , "Coal.Steam Coal - SUPERCRITICAL"] + + x[, , "Coal.Steam Coal - ULTRASUPERCRITICAL"] + + # for rest of technologies, simply match + further_techs_to_map <- filter(tech_mapping, !(!!sym("tech") %in% c("pc", "spv", "hydro", "biochp"))) + x_new[, , further_techs_to_map$tech] <- as.numeric(x[, , further_techs_to_map$IEA]) + + x_new <- time_interpolate(x_new, c(2025, 2035), integrate_interpolated_years = TRUE) + + return(list(x = x_new, weight = x_new, unit = "NA", description = "Efficiency data")) } +} diff --git a/R/calcDspvEFmult.R b/R/calcDspvEFmult.R deleted file mode 100644 index 1f7d6442..00000000 --- a/R/calcDspvEFmult.R +++ /dev/null @@ -1,40 +0,0 @@ -#' Calculates a multiplier for the employment factor for distributed solar pv -#' @author Aman Malik - -calcDspvEFmult <- function() - { - - share_notagg <- calcOutput("DspvShare",aggregate = F) - - share_agg <- calcOutput("DspvShare") - - ef_ceew <- a <- readSource("CEEW",convert=F,subtype="Employment factors") - ef_ceew <- ef_ceew[,,c("Solar|PV.CI","Solar|PV|Rooftop.CI")] - #multiplier for countries with low rooftop penetration - mult_low <- as.numeric(ef_ceew[,,"Solar|PV|Rooftop.CI"]/ef_ceew[,,"Solar|PV.CI"]) - # multiplier for countries with high rooftop penetration - mult_high <- 1.3 # avg. jobs in construction phase from IEA sustainable futures report Fig 2.3 - # 10 for utility and 14 for rooftop. Assuming these values are weighted for capacity, the number represents - # mostly rooftop addition in China, Europe, and Japan - - mult_factor <- new.magpie(getRegions(share_notagg),getYears(share_notagg)) - slope <- (mult_high-mult_low)/(as.numeric(share_agg["EUR",2020,]-share_agg["IND",2020,])) - intercept <- as.numeric(mult_high - (slope*share_agg["EUR",2020,])) - # intercept <- as.numeric(mult_low - (slope*share_agg["IND",2020,])) - - for (i in getRegions(share_notagg)){ - if (share_notagg[i,2020,]>0.66) - mult_factor[i,,] <- 1.3 - else { - mult_factor[i,,] <- slope*share_notagg[i,,] + intercept - } - } - - - return(list(x = mult_factor, - weight = share_notagg, - unit = "none", - description = "multipler for Solar PV construction and installation employment factor")) - - } - diff --git a/R/calcEDGETransport.R b/R/calcEDGETransport.R index 14914d8f..d012f4c7 100644 --- a/R/calcEDGETransport.R +++ b/R/calcEDGETransport.R @@ -1,25 +1,106 @@ #' @title Prepare EDGETransport inputs #' -#' @return magpie object of EDGEtransport iterative inputs -#' @author Alois Dirnaichner, Marianna Rottoli +#' @author Johanna Hoppe #' @seealso \code{\link{readSource}} -#' @param subtype refer to the code for a list of allowed subtypes. -#' +#' @param subtype REMIND/iterative EDGE-T input data subtypes +#' @return REMIND/iterative EDGE-T input data for all scenario combinations #' @examples -#' \dontrun{ a <- calcOutput(type="EDGETransport", subtype="logit_exponent", aggregate=F) +#' \dontrun{ a <- calcOutput(type = "EDGETransport", subtype = "CAPEXandNonFuelOPEX", aggregate = F) #' } -#' -#'@importFrom data.table as.data.table + calcEDGETransport <- function(subtype) { + x <- readSource("EDGETransport", subtype) + switch(subtype, - ".." = { + "f35_esCapCost" = { + weight <- readSource("EDGETransport", subtype = "weightESdemand") + #Rule out numerical errors after disaggregating very small numbers + weight[weight < 1e-5] <- 0 + #check whether weightsum is zero for some cases + #if so, the values should just be aggregated equally in order to prevent zeros in the results + weight <- rmndt::magpie2dt(weight) + regMap <- toolGetMapping(getConfig("regionmapping"), type = "regional", where = "mappingfolder") + setnames(regMap, "CountryCode", "all_regi") + weight <- merge(weight, regMap[, c("all_regi", "RegionCode")], by = "all_regi") + weight[, weightSum := sum(value), by = c("RegionCode", "GDP_scenario", "DEM_scenario", "EDGE_scenario", "all_teEs", "tall")] + weight[weightSum == 0, value := 1] + weight[, c("RegionCode", "weightSum") := NULL] + weight <- as.magpie(weight) + unit = "2005US$/(p|t)km" + description = "Capital cost (purchase) per energy service demand on CES level." + }, + "f35_fe2es" = { + weight = readSource("EDGETransport", "f35_demByTech") + weight[weight < 1e-5] <- 0 + #check whether weightsum is zero for some cases + #if so, the values should just be aggregated equally in order to prevent zeros in the results + weight <- rmndt::magpie2dt(weight) + regMap <- toolGetMapping(getConfig("regionmapping"), type = "regional", where = "mappingfolder") + setnames(regMap, "CountryCode", "all_regi") + weight <- merge(weight, regMap[, c("all_regi", "RegionCode")], by = "all_regi") + weight[, weightSum := sum(value), by = c("RegionCode", "GDP_scenario", "DEM_scenario", "EDGE_scenario", "all_enty", "all_in", "all_teEs", "tall")] + weight[weightSum == 0, value := 1] + weight[, c("RegionCode", "weightSum", "all_enty", "all_in") := NULL] + weight <- as.magpie(weight) + unit = "trn (p|t)km/Twa" + description = "Energy efficiency on CES level." + }, + "f35_demByTech" = { + weight = NULL + unit = "TWa" + description = "Final energy demand on CES level." + }, + "f29_trpdemand" = { weight = NULL - unit = "[-]" - description = ".." - }) + unit = "trillion pkm/trillion tkm" + description = "Energy service demand on CES level." + }, + "CAPEXandNonFuelOPEX" = { + gdp <- calcOutput("GDP", aggregate = FALSE)[,,"gdp_SSP2"] + weight = gdp |> time_interpolate(getYears(x)) + unit = "2005US$/(p|t)km" + description = "Capital cost (purchase) and non-fuel operational costs on technology level." + }, + "scenSpecPrefTrends" = { + gdp <- calcOutput("GDP", aggregate = FALSE)[,,"gdp_SSP2"] + weight = gdp |> time_interpolate(getYears(x)) + unit = "-" + description = "Scenario specific preference trends on technology level." + }, + "scenSpecLoadFactor" = { + gdp <- calcOutput("GDP", aggregate = FALSE)[,,"gdp_SSP2"] + weight = gdp |> time_interpolate(getYears(x)) + unit = "-" + description = "Scenario specific load factor on technology level." + }, + "scenSpecEnIntensity" = { + gdp <- calcOutput("GDP", aggregate = FALSE)[,,"gdp_SSP2"] + weight = gdp |> time_interpolate(getYears(x)) + unit = "MJ/vehkm" + description = "Scenario specific energy intensity on technology level." + }, + "initialIncoCosts" = { + gdp <- calcOutput("GDP", aggregate = FALSE)[,,"gdp_SSP2"] + weight = gdp |> time_interpolate(getYears(x)) + unit = "2005US$/(p|t)km" + description = "Initial inconvenience cost values." + }, + "annualMileage" = { + gdp <- calcOutput("GDP", aggregate = FALSE)[,,"gdp_SSP2"] + weight = gdp |> time_interpolate(getYears(x)) + unit = "vehkm/yr" + description = "Annual vehicle km traveled." + }, + "timeValueCosts" = { + gdp <- calcOutput("GDP", aggregate = FALSE)[,,"gdp_SSP2"] + weight = gdp |> time_interpolate(getYears(x)) + unit = "2005US$/(p|t)km" + description = "Value of time cost equivalent." + } + ) - return(list(x = data, + return(list(x = x, weight = weight, unit = unit, description = description)) diff --git a/R/calcEEAGHGProjections.R b/R/calcEEAGHGProjections.R index 8bc230a2..5a15230e 100644 --- a/R/calcEEAGHGProjections.R +++ b/R/calcEEAGHGProjections.R @@ -5,15 +5,14 @@ #' #' @author Falk Benke #' -#' @importFrom dplyr select mutate left_join -#' @importFrom madrat toolGetMapping toolCountryFill -#' @importFrom magclass as.magpie +#' @importFrom dplyr select mutate left_join filter #' @importFrom rlang sym -#' @importFrom quitte calc_addVariable #' @export calcEEAGHGProjections <- function() { - mapping <- toolGetMapping(type = "sectoral", name = "mappingEEAGHGProjections.csv", where = "mappingfolder") + + mapping <- toolGetMapping(type = "sectoral", + name = "mappingEEAGHGProjections.csv", where = "mrremind") eea <- readSource("EEA_EuropeanEnvironmentAgency", subtype = "projections") projectionsOverview <- as.data.frame(eea) %>% @@ -22,26 +21,25 @@ calcEEAGHGProjections <- function() { "region" = "Region", "year" = "Year", "model" = "Data1", "Category" = "Data2", "Gas" = "Data3", "value" = "Value" ) %>% - mutate(!!sym("Category") := gsub("_", ".", !!sym("Category"))) %>% + mutate("Category" = gsub("_", ".", !!sym("Category"))) %>% left_join(mapping, by = c("Category", "Gas")) %>% filter(!is.na(!!sym("Variable"))) %>% select("region", "year", "model", "variable" = "Variable", "value") %>% - calc_addVariable( + quitte::calc_addVariable( "`Emi|GHG|Industry|ETS`" = "`Emi|GHG|Industrial Processes|ETS` + `Emi|GHG|Energy|Demand|Industry|ETS`", "`Emi|GHG|Industry|ESR`" = "`Emi|GHG|Industrial Processes|ESR` + `Emi|GHG|Energy|Demand|Industry|ESR`", - # "`Emi|GHG|Industry`" = "`Emi|GHG|Industry|ETS` + `Emi|GHG|Industry|ESR`", # currently calculated in detailed source "`Emi|GHG|Intl aviation in ETS|ETS`" = "`Emi|GHG|w/ Intl aviation` - `Emi|GHG`", completeMissing = F ) %>% mutate( - !!sym("value") := !!sym("value") / 1000, - !!sym("model") := paste0("EEA_", !!sym("model")), - !!sym("variable") := paste0(!!sym("variable"), " (Mt CO2eq/yr)") + "value" = !!sym("value") / 1000, + "model" = paste0("EEA_", !!sym("model")), + "variable" = paste0(!!sym("variable"), " (Mt CO2eq/yr)") ) eeaDetail <- readSource("EEA_EuropeanEnvironmentAgency", subtype = "projections-detailed") - mappingDetailed <- toolGetMapping(type = "sectoral", name = "mappingEEAGHGProjectionsDetailed.csv", - where = "mappingfolder") + mappingDetailed <- toolGetMapping(type = "sectoral", name = "mappingEEAGHGProjectionsDetailed.csv", + where = "mrremind") projectionsDetail <- as.data.frame(eeaDetail) %>% filter(!is.na(!!sym("Value"))) %>% @@ -49,20 +47,20 @@ calcEEAGHGProjections <- function() { "region" = "Region", "year" = "Year", "model" = "Data1", "Category" = "Data2", "Gas" = "Data3", "value" = "Value" ) %>% - mutate(!!sym("Category") := gsub("_", ".", !!sym("Category"))) %>% + mutate("Category" = gsub("_", ".", !!sym("Category"))) %>% left_join(mappingDetailed, by = c("Category", "Gas")) %>% filter(!is.na(!!sym("Variable"))) %>% - mutate(!!sym("value") := as.numeric(!!sym("value")) * !!sym("factor")) %>% + mutate("value" = as.numeric(!!sym("value")) * !!sym("factor")) %>% select("region", "year", "model", "variable" = "Variable", "value", "unit") %>% - calc_addVariable( + quitte::calc_addVariable( "`Emi|CO2|Industry`" = "`Emi|CO2|Energy|Demand|Industry` + `Emi|CO2|Industrial Processes`", "`Emi|GHG|Industry`" = "`Emi|GHG|Energy|Demand|Industry` + `Emi|GHG|Industrial Processes`", "`Emi|CO2|Energy|Demand|Buildings`" = "`Emi|CO2|Energy|Demand|Buildings|Residential` + `Emi|CO2|Energy|Demand|Buildings|Commercial`", completeMissing = F, units = c("Mt CO2/yr", "Mt CO2eq/yr", "Mt CO2/yr") ) %>% mutate( - !!sym("variable") := paste0(!!sym("variable"), " (", !!sym("unit"), ")"), - !!sym("model") := paste0("EEA_", !!sym("model")) + "variable" = paste0(!!sym("variable"), " (", !!sym("unit"), ")"), + "model" = paste0("EEA_", !!sym("model")) ) %>% select(-"unit") @@ -72,8 +70,10 @@ calcEEAGHGProjections <- function() { !!sym("region"), !!sym("year"), !!sym("model"), !!sym("variable"), .keep_all = TRUE ) + x <- as.magpie(projections, spatial = 1, temporal = 2, datacol = 5) %>% - toolCountryFill(fill = NA, verbosity = 2) + toolCountryFill(fill = NA, verbosity = 2) %>% + toolFillEU34Countries() return(list( x = x, diff --git a/R/calcEU_ReferenceScenario.R b/R/calcEU_ReferenceScenario.R index 74267fc3..f5cf15c5 100644 --- a/R/calcEU_ReferenceScenario.R +++ b/R/calcEU_ReferenceScenario.R @@ -1,17 +1,21 @@ calcEU_ReferenceScenario <- function() { - EU_ReferenceScenario_2016 <- readSource("EU_ReferenceScenario", subtype = "2016") - EU_ReferenceScenario_2016 <- add_dimension(EU_ReferenceScenario_2016, dim = 3.1, add = "model", nm = "EU_ReferenceScenario_2016") - + EU_ReferenceScenario_2016 <- add_dimension(EU_ReferenceScenario_2016, dim = 3.1, add = "model", + nm = "EU_ReferenceScenario_2016") + EU_ReferenceScenario_2020 <- readSource("EU_ReferenceScenario", subtype = "2020") EU_ReferenceScenario_2020 <- add_columns(EU_ReferenceScenario_2020, "y2000", dim = 2) - EU_ReferenceScenario_2020 <- add_dimension(EU_ReferenceScenario_2020, dim = 3.1, add = "model", nm = "EU_ReferenceScenario_2020") - + EU_ReferenceScenario_2020 <- add_dimension(EU_ReferenceScenario_2020, dim = 3.1, add = "model", + nm = "EU_ReferenceScenario_2020") + x <- mbind(EU_ReferenceScenario_2016, EU_ReferenceScenario_2020) - + weights <- x - weights[,,] <- NA - weights[,,"Price|Secondary Energy|Electricity (US$2005/GJ)"] <- 1 - - return(list(x = x, weight = weights, mixed_aggregation = T, unit = "Various", description = "Historical Data")) + weights[, , ] <- NA + weights[, , "Price|Secondary Energy|Electricity (EUR2013/GJ)"] <- 1 + + return(list( + x = x, weight = weights, mixed_aggregation = TRUE, + unit = "Various", description = "Historical Data" + )) } diff --git a/R/calcEarlyRetirementAdjFactor.R b/R/calcEarlyRetirementAdjFactor.R index 3e36d583..ba3e511c 100644 --- a/R/calcEarlyRetirementAdjFactor.R +++ b/R/calcEarlyRetirementAdjFactor.R @@ -1,45 +1,44 @@ #' @title calc Early Retirement Adjustment Factor #' @description provides the extra retirement rate to account for relatively old fleet technologies retirement #' @param subtype Some scenarios may require certain regions to increase retirement rate, e.g. PPCA coal phase-out -#' @return magpie object of additional adjusment percentage to be added to the fraction of the early retired capital in countries to account for relatively old technologies fleet +#' @return magpie object of additional adjusment percentage to be added to the fraction of the early retired capital in countries to account for relatively old technologies fleet #' @author Renato Rodrigues #' @seealso \code{\link{calcOutput}} #' @examples -#' -#' \dontrun{ -#' calcOutput(type="EarlyRetirementAdjFactor") +#' \dontrun{ +#' calcOutput(type = "EarlyRetirementAdjFactor") #' } -#' +#' +calcEarlyRetirementAdjFactor <- function(subtype = "none") { + # loading early retirement adjustment factor data + data <- readSource("REMIND_11Regi", subtype = "earlyRetirementAdjFactor") -calcEarlyRetirementAdjFactor <- function(subtype="none"){ - #loading early retirement adjustment factor data - data <- readSource("REMIND_11Regi", subtype="earlyRetirementAdjFactor") - - ### SB 09.2020 + ### SB 09.2020 ### Increasing China's maximum retirement rate to match the EU and US (13%) ### China's weighted average plant lifespan was half the global average for plants retired in 2015-2020, due to technology efficiency upgrades, ### overcapacity (ongoing), and mismatched local and national political agendas. Plants are permitted by local authorities but can be retired by ### federal authorities. We expect the trend to continue to some degree because of the CPC's recent climate commitments and their political longevity. - data["CHN",,] <- data["USA",,] - + data["CHN", , ] <- data["USA", , ] + ### SB 12.2020 ### Also increasing REF's retirement rate to match EU and US since they have an even older coal fleet - data["RUS",,] <- data["USA",,] - data["UKR",,] <- data["USA",,] - data["UZB",,] <- data["USA",,] - data["KAZ",,] <- data["USA",,] - data["KGZ",,] <- data["USA",,] - data["MDA",,] <- data["USA",,] - - #loading weight factor - IO <- calcOutput("IO",subtype="input",aggregate=FALSE) + data["RUS", , ] <- data["USA", , ] + data["UKR", , ] <- data["USA", , ] + data["UZB", , ] <- data["USA", , ] + data["KAZ", , ] <- data["USA", , ] + data["KGZ", , ] <- data["USA", , ] + data["MDA", , ] <- data["USA", , ] + + # loading weight factor + IO <- calcOutput("IO", subtype = "input", aggregate = FALSE) weight <- NULL - weight <- dimSums(IO[,2005,getNames(data)],dim=3) - weight <- setNames(weight,getNames(data)) + weight <- dimSums(IO[, 2005, getNames(data)], dim = 3) + weight <- setNames(weight, getNames(data)) - return(list(x=data, weight=weight, - unit="percentage", - description="extra retirement rate for technologies in countries with relatively old fleet", - mixed_aggregation=TRUE - )) + return(list( + x = data, weight = weight, + unit = "percentage", + description = "extra retirement rate for technologies in countries with relatively old fleet", + mixed_aggregation = TRUE + )) } diff --git a/R/calcEconometricEmiParameter.R b/R/calcEconometricEmiParameter.R index 8230dede..3d890592 100644 --- a/R/calcEconometricEmiParameter.R +++ b/R/calcEconometricEmiParameter.R @@ -14,7 +14,6 @@ #' calcOutput("calcEconometricEmiParameter") #' } #' @importFrom utils read.csv -#' @importFrom magclass getNames<- getYears<- calcEconometricEmiParameter <- function() { diff --git a/R/calcEffortSharingRefEmi.R b/R/calcEffortSharingRefEmi.R index 33f1beb8..85a00cfa 100644 --- a/R/calcEffortSharingRefEmi.R +++ b/R/calcEffortSharingRefEmi.R @@ -5,55 +5,55 @@ #' @return 2005 reference emissions to calculate effort sharing decision targets #' @author Renato Rodrigues #' @examples -#' -#' \dontrun{ +#' +#' \dontrun{ #' calcOutput("EffortSharingRefEmi",subtype="Eurostat_GHG") #' } -#' +#' calcEffortSharingRefEmi <- function(subtype){ - + if(subtype=="EEA_GHG"){ - - e <- readSource("EEA_EuropeanEnvironmentAgency", subtype="ESR")[,2005,"Emi|GHG|ESR (Mt CO2-equiv/yr)"] + + e <- readSource("EEA_EuropeanEnvironmentAgency", subtype="ESR")[,2005,"Emi|GHG|ESR (Mt CO2-equiv/yr)"] #e <- readSource("EEA_EuropeanEnvironmentAgency", subtype="sectoral")[,2005,"Emi|GHG|ESR (Mt CO2-equiv/yr)"] e[is.na(e)] <- 0 - description <- "Effort sharing reference 2005 emissions in Mt CO2-equiv from EEA data" + description <- "Effort sharing reference 2005 emissions in Mt CO2-equiv from EEA data" unit <- "Mt CO2-equiv" - + } else if(subtype=="Eurostat_GHG"){ - e <- readSource("Eurostat_EffortSharing",subtype="emissions")[,2005,] - description <- "Effort sharing reference 2005 emissions in Mt CO2-equiv from Eurostat" + e <- readSource("Eurostat_EffortSharing",subtype="emissions")[,2005,] + description <- "Effort sharing reference 2005 emissions in Mt CO2-equiv from Eurostat" unit <- "Mt CO2-equiv" - + } else if (subtype=="REMIND_GHG") { - e_ES <- readSource("Eurostat_EffortSharing",subtype="emissions") + e_ES <- readSource("Eurostat_EffortSharing",subtype="emissions") EU11map <- toolGetMapping("regionmapping_21_EU11.csv", type = "regional", where = "mappingfolder") e_REMIND <- as.magpie(data.frame( period=rep(2005,9), regionscode=c("DEU","ECE","ECS","ENC","ESC","ESW","EWN","FRA","UKI"), #REMIND_ESR_Emi=c(477.0574005,282.5551076,207.0889494,226.7403476,385.869115,341.4182047,313.5259699,395.4965811,394.6661034))) # GHG ESR 2005 REMIND emissions REMIND_ESR_Emi=c(469.902686605144,255.724675477596,166.732543751469,126.497826068766,363.185841688919,298.622613003952,308.269435719629,383.162590392638,409.297607369399))) # GHG ESR 2005 REMIND emissions (from REMIND) - + e <- toolAggregate(e_REMIND,EU11map[which(EU11map$RegionCode %in% getRegions(e_REMIND)), ][,c(1,2,3)],e_ES[EU11map[which(EU11map$RegionCode %in% getRegions(e_REMIND)), ]$CountryCode,2005,]) - e <- toolCountryFill(e,fill=0) - description <- "Effort sharing reference 2005 emissions in Mt CO2-equiv from REMIND" + e <- toolCountryFill(e, fill = 0, verbosity = 2) + description <- "Effort sharing reference 2005 emissions in Mt CO2-equiv from REMIND" unit <- "Mt CO2-equiv" - + } else if (subtype=="REMIND_CO2") { - e_ES <- readSource("Eurostat_EffortSharing",subtype="emissions") - EU11map <- toolGetMapping("regionmapping_21_EU11.csv", type = "regional") + e_ES <- readSource("Eurostat_EffortSharing",subtype="emissions") + EU11map <- toolGetMapping("regionmapping_21_EU11.csv", type = "regional", where = "mappingfolder") e_REMIND <- as.magpie(data.frame( period=rep(2005,9), regionscode=c("DEU","ECE","ECS","ENC","ESC","ESW","EWN","FRA","UKI"), REMIND_ESR_Emi=c(394.2864406,162.5137758,98.05365416,88.50179503,288.7617393,221.2791697,271.4385753,290.2774547,308.7078729))) # CO2 ESR 2005 REMIND emissions e <- toolAggregate(e_REMIND,EU11map[which(EU11map$RegionCode %in% getRegions(e_REMIND)), ][,c(1,2,3)],e_ES[EU11map[which(EU11map$RegionCode %in% getRegions(e_REMIND)), ]$CountryCode,2005,]) - e <- toolCountryFill(e,fill=0) - description <- "Effort sharing reference 2005 emissions in Mt CO2 from REMIND" + e <- toolCountryFill(e, fill = 0, verbosity = 2) + description <- "Effort sharing reference 2005 emissions in Mt CO2 from REMIND" unit <- "Mt CO2" - + } getNames(e) <- NULL - - return(list(x=e, weight=NULL,unit=unit,description=description)) + + return(list(x=e, weight=NULL,unit=unit,description=description)) } diff --git a/R/calcEmber.R b/R/calcEmber.R index cd6e34eb..e624fe86 100644 --- a/R/calcEmber.R +++ b/R/calcEmber.R @@ -11,8 +11,6 @@ #' #' @author Pascal Weigmann #' -#' @importFrom madrat toolAggregate toolGetMapping -#' @importFrom magclass collapseDim #' #' @export diff --git a/R/calcEmiFossilFuelExtr.R b/R/calcEmiFossilFuelExtr.R index 569ce2a0..9edba47f 100644 --- a/R/calcEmiFossilFuelExtr.R +++ b/R/calcEmiFossilFuelExtr.R @@ -1,4 +1,3 @@ -#' @importFrom magclass getNames<- calcEmiFossilFuelExtr <- function() { diff --git a/R/calcEmiLULUCFCountryAcc.R b/R/calcEmiLULUCFCountryAcc.R index e84e9a23..6ca4eb05 100644 --- a/R/calcEmiLULUCFCountryAcc.R +++ b/R/calcEmiLULUCFCountryAcc.R @@ -3,7 +3,6 @@ #' @return Magpie object with historical LULUCF emissions #' @param subtype Valid subtypes are 'UNFCCC' #' @author Felix Schreyer -#' @importFrom magclass dimReduce calcEmiLULUCFCountryAcc <- function(subtype) { if (subtype == "UNFCCC") { diff --git a/R/calcEmiMac1990.R b/R/calcEmiMac1990.R index 688f6fe7..2d7a17d2 100644 --- a/R/calcEmiMac1990.R +++ b/R/calcEmiMac1990.R @@ -12,7 +12,6 @@ #' \dontrun{ #' calcOutput("calcEmiMac1990") #' } -#' @importFrom magclass getNames<- getYears<- calcEmiMac1990 <- function() { # emissions for the calculation of econometric paramter p1 diff --git a/R/calcEmiPollutantExo.R b/R/calcEmiPollutantExo.R index 9955c558..62cfdcbe 100644 --- a/R/calcEmiPollutantExo.R +++ b/R/calcEmiPollutantExo.R @@ -12,7 +12,6 @@ #' } #' #' -#' @importFrom magclass getSets getYears time_interpolate complete_magpie calcEmiPollutantExo <- function(subtype, aviationshippingsource="RCP"){ diff --git a/R/calcEmiTarget.R b/R/calcEmiTarget.R index 265271e0..c987e0e6 100644 --- a/R/calcEmiTarget.R +++ b/R/calcEmiTarget.R @@ -2,7 +2,6 @@ #' @author Aman Malik, Christoph Bertram, Oliver Richters #' @param sources currently only UNFCCC_NDC #' @param subtype "Ghgshare2005", "Ghgfactor", "Ghghistshare" -#' @importFrom magclass getNames calcEmiTarget <- function(sources, subtype) { @@ -13,7 +12,7 @@ calcEmiTarget <- function(sources, subtype) { gwpCH4 <- 28 # "Global Warming Potentials of CH4, AR5 WG1 CH08 Table 8.7" /28/ gwpN2O <- 265 # "Global Warming Potentials of N2O, AR5 WG1 CH08 Table 8.7" /265/ # calculate GHG total of CO2, CH4 and N2O [unit Mt CO2eq] - # note: CEDS2021 does not include 'Emi|N2O|Land Use|*' variables and cannot be used. + # note: CEDS2024 does not include 'Emi|N2O|Land Use|*' variables and cannot be used. ghg <- ceds[, seq(1990, 2015, 1), c("Emi|CO2|Energy and Industrial Processes (Mt CO2/yr)")] + +gwpN2O / 1000 * dimSums(ceds[, seq(1990, 2015, 1), c("Emi|N2O|Energy and Industrial Processes (kt N2O/yr)", "Emi|N2O|Land Use|Agriculture and Biomass Burning (kt N2O/yr)", @@ -27,7 +26,7 @@ calcEmiTarget <- function(sources, subtype) { "Emi|CH4|Waste (Mt CH4/yr)")], dim = 3) # create global data for checking plausibility of data globGhg <- dimSums(ghg, dim = 1) - ghg <- toolCountryFill(ghg, fill = 0) + ghg <- toolCountryFill(ghg, fill = 0, verbosity = 2) # Future GDP values gdp <- calcOutput("GDP", aggregate = FALSE) @@ -47,7 +46,9 @@ calcEmiTarget <- function(sources, subtype) { "2022_cond" = readSource("UNFCCC_NDC", subtype = "Emissions_2022_cond"), "2022_uncond" = readSource("UNFCCC_NDC", subtype = "Emissions_2022_uncond"), "2023_cond" = readSource("UNFCCC_NDC", subtype = "Emissions_2023_cond"), - "2023_uncond" = readSource("UNFCCC_NDC", subtype = "Emissions_2023_uncond") + "2023_uncond" = readSource("UNFCCC_NDC", subtype = "Emissions_2023_uncond"), + "2024_cond" = readSource("UNFCCC_NDC", subtype = "Emissions_2024_cond"), + "2024_uncond" = readSource("UNFCCC_NDC", subtype = "Emissions_2024_uncond") ) listYears <- lapply(listGhgfactors, getItems, dim = "year") %>% unlist() %>% unique() %>% sort() diff --git a/R/calcEmissionFactors.R b/R/calcEmissionFactors.R index e5167915..55cf9ee8 100644 --- a/R/calcEmissionFactors.R +++ b/R/calcEmissionFactors.R @@ -1,37 +1,32 @@ -#' @importFrom dplyr group_by_ summarise_ ungroup mutate_ rename_ filter_ select_ -#' @importFrom magclass as.magpie getCells getSets<- getNames<- getSets getRegions<- -#' mselect<- setNames write.magpie setCells mselect -#' @importFrom tidyr gather_ +#' @importFrom dplyr ungroup #' @importFrom utils read.csv read.csv2 #' @importFrom quitte as.quitte - - calcEmissionFactors <- function(subtype = "emission_factors", sectoral_resolution = "aggregated") { - - if (!(subtype %in% c("emission_factors", "activities", "emissions"))) stop('subtype must be in c("emission_factors", "activities", "emissions")') + if (!(subtype %in% c("emission_factors", "activities", "emissions"))) { + stop('subtype must be in c("emission_factors", "activities", "emissions")') + } #-- INITIALISATION ---------------- + vcat(2, ">> Initialization...\n") + # local functions allocate_c2r_ef <- function(id_ef, ip_region, ip_country, ip_year, ip_scenario) { - dummy <- id_ef[ip_region, ip_year, ip_scenario] - dummy[, , ] <- setCells(id_ef[ip_country, ip_year, ip_scenario], "GLO") - # names(dimnames(dummy)) <- c("region", "years", "data1.data2.species.scenario") - + dummy <- id_ef[ip_region, ip_year, ip_scenario] + dummy[, , ] <- setCells(id_ef[ip_country, ip_year, ip_scenario], "GLO") return(dummy) } allocate_min2r_ef <- function(id_ef, ip_region, ip_countryGroup, ip_year, ip_scenario) { - dummy <- id_ef[ip_region, ip_year, ip_scenario] # Get minimum values across country group tmp <- as.quitte(id_ef[ip_countryGroup, ip_year, ip_scenario]) %>% - group_by(!!!syms(c('data1', 'data2'))) %>% + group_by(!!!syms(c("data1", "data2"))) %>% summarise(value = ifelse(all(.data$value == 0), 0, - min(.data$value[.data$value > 0], na.rm = TRUE)) - ) %>% # a value 0 is often a sign for a NA that has been replaced with 0 for small countries + min(.data$value[.data$value > 0], na.rm = TRUE) + )) %>% # a value 0 is often a sign for a NA that has been replaced with 0 for small countries ungroup() %>% as.data.frame() %>% as.quitte() %>% @@ -43,58 +38,46 @@ calcEmissionFactors <- function(subtype = "emission_factors", sectoral_resolutio return(dummy) } - fill_NAs_with_Emissions <- function(mdata, filldata, scenario = "CLE") { - # index gives the set elements where all values in a region for a sector are NA - index <- apply(mdata, c(1, 3), function(x) { - return(all(is.na(x))) - }) - index <- as.magpie(index) - index2 <- new.magpie(getCells(mdata), getYears(mdata), getNames(mdata)) - index2[, , ] <- index - index3 <- which(index2 == 1, arr.ind = TRUE) - - # filldata2 takes the structure of mdata and is filled with the values of filldata for the scenario chosen - - filldata2 <- new.magpie(getCells(mdata), getYears(mdata), getNames(mdata)) - if (!is.null(scenario)) filldata2[, , ] <- collapseNames(filldata[, getYears(mdata), scenario][, , getNames(filldata2, dim = 1)]) - if (is.null(scenario)) filldata2[, , ] <- collapseNames(filldata[, getYears(mdata), getNames(filldata2, dim = 1)]) - - mdata[index3] <- filldata2[index3] - - return(mdata) - } - # conversion factors - # TODO: should be centralised somewhere - conv_ktSO2_to_ktS <- 1 / 2 # 32/(32+2*16) + conv_ktSO2_to_ktS <- 1 / 2 # 32/(32+2*16) conv_kt_per_PJ_to_Tg_per_TWa <- 1e-3 / (1e15 / (365 * 24 * 60 * 60) * 1e-12) - conv_kt_to_Tg <- 1e-3 - conv_PJ_to_Twa <- (1e15 / (365 * 24 * 60 * 60) * 1e-12) # user-defined parameters - time <- c(seq(2005, 2055, 5), seq(2060, 2110, 10), 2130, 2150) - scenario <- c("SSP1", "SSP2", "SSP3", "SSP4", "SSP5", "FLE", "MFR", "CLE", "MFR_Transports", "GlobalEURO6", "FLE_building_transport", "SLCF_building_transport") # These are additional scenarios to the CLE and MFR + time <- c(seq(2005, 2055, 5), seq(2060, 2110, 10), 2130, 2150) - p_dagg_year <- 2005 - p_dagg_pop <- "pop_SSP2" - p_dagg_gdp <- "gdp_SSP2" + # These are additional scenarios to the CLE and MFR + scenario <- c( + "SSP1", "SSP2", "SSP3", "SSP4", "SSP5", "FLE", "MFR", "CLE", + "MFR_Transports", "GlobalEURO6", "FLE_building_transport", + "SLCF_building_transport" + ) p_countryCategories <- "useGAINSregions" # list of OECD countries # TODO: may want to place this in a mapping file or in a R library - r_oecd <- c("AUS", "AUT", "BEL", "CAN", "CHL", "CZE", "DNK", "EST", "FIN", "FRA", "DEU", "GRC", "HUN", "ISL", "IRL", "ISR", "ITA", - "JPN", "KOR", "LUX", "MEX", "NLD", "NZL", "NOR", "POL", "PRT", "SVK", "SVN", "ESP", "SWE", "CHE", "TUR", "GBR", "USA") - - # set of sectors for which no emission factor will be computed (because there is no activity reported, or not in terms of energy) - dimSector_skipEF <- c("AACID", "CEMENT", "CHEM", "CHEMBULK", "CUSM", "NACID", "PAPER", "STEEL", - "Losses_Coal", "Losses_Distribution_Use", "Losses_Vent_Flare", - "Transformations_Coal", "Transformations_HLF", "Transformations_HLF_Refinery", "Transformations_LLF", "Transformations_NatGas") - - dimSector_skipEF_edge <- c("End_Use_Industry_Bio_Trad", "End_Use_Industry_Coal", "End_Use_Industry_HLF", "End_Use_Industry_LLF", - "End_Use_Industry_NatGas", "End_Use_Residential_Bio_Mod", "End_Use_Residential_Bio_Trad", "End_Use_Residential_Coal", - "End_Use_Residential_HLF", "End_Use_Residential_LLF", "End_Use_Residential_NatGas", "End_Use_Services_Bio_Trad", - "End_Use_Services_Coal") + r_oecd <- c( + "AUS", "AUT", "BEL", "CAN", "CHL", "CZE", "DNK", "EST", "FIN", "FRA", "DEU", + "GRC", "HUN", "ISL", "IRL", "ISR", "ITA", "JPN", "KOR", "LUX", "MEX", "NLD", + "NZL", "NOR", "POL", "PRT", "SVK", "SVN", "ESP", "SWE", "CHE", "TUR", "GBR", "USA" + ) + + # set of sectors for which no emission factor will be computed + # (because there is no activity reported, or not in terms of energy) + dimSector_skipEF <- c( + "AACID", "CEMENT", "CHEM", "CHEMBULK", "CUSM", "NACID", "PAPER", "STEEL", + "Losses_Coal", "Losses_Distribution_Use", "Losses_Vent_Flare", + "Transformations_Coal", "Transformations_HLF", "Transformations_HLF_Refinery", + "Transformations_LLF", "Transformations_NatGas" + ) + + dimSector_skipEF_edge <- c( + "End_Use_Industry_Bio_Trad", "End_Use_Industry_Coal", "End_Use_Industry_HLF", + "End_Use_Industry_LLF", "End_Use_Industry_NatGas", "End_Use_Residential_Bio_Mod", + "End_Use_Residential_Bio_Trad", "End_Use_Residential_Coal", "End_Use_Residential_HLF", + "End_Use_Residential_LLF", "End_Use_Residential_NatGas", "End_Use_Services_Bio_Trad", + "End_Use_Services_Coal" + ) dimSector_skipEF_edge <- c("") #-- READ IN DATA ------------------ @@ -106,62 +89,54 @@ calcEmissionFactors <- function(subtype = "emission_factors", sectoral_resolutio # > emission data emissions <- readSource("ECLIPSE", subtype = paste0("emissions.", sectoral_resolution)) emissions <- emissions[, c(2005, 2010, 2020, 2030, 2050), ] - setsEmissions <- getSets(emissions) # read in sectoral mapping (ECLIPSE (IMAGE) <> REMIND) - map_sectors_ECLIPSE2Agg <- read.csv(toolGetMapping(type = "sectoral", name = "mappingECLIPSEtoAggREMINDsectors.csv", - returnPathOnly = TRUE, where = "mappingfolder"), - stringsAsFactors = TRUE) - map_sectors_Agg2REMIND <- read.csv(toolGetMapping(type = "sectoral", name = "mappingAggREMINDtoREMINDsectors.csv", - returnPathOnly = TRUE, where = "mappingfolder"), - stringsAsFactors = TRUE) - map_sectors_ECLIPSE2REMIND <- read.csv(toolGetMapping(type = "sectoral", name = "mappingECLIPSEtoREMINDsectors.csv", - returnPathOnly = TRUE, where = "mappingfolder"), - stringsAsFactors = TRUE) - # map_sectors <- map_sectors[which(!is.na(map_sectors$EDGE)),] # Remove transport sector (which is not represented in EDGE) + map_sectors_ECLIPSE2REMIND <- toolGetMapping( + type = "sectoral", name = "mappingECLIPSEtoREMINDsectors.csv", + where = "mrremind" + ) %>% + # remove no longer used technologies pcc and pco + filter(!grepl("pcc|pco", .data$remind)) # read in regional map (select ISO and GAINS codes only). This is required for the construction of the SSPs - map_REMINDregions <- read.csv2(toolGetMapping(type = "regional", name = "regionmappingREMIND.csv", - returnPathOnly = TRUE, where = "mappingfolder"), - stringsAsFactors = TRUE) - map_regions <- read.csv2(toolGetMapping(type = "regional", name = "regionmappingGAINS.csv", returnPathOnly = TRUE, - where = "mappingfolder"), - stringsAsFactors = TRUE)[, c(2, 3)] - map_regions <- map_regions %>% + + map_regions <- read.csv2( + toolGetMapping(type = "regional", name = "regionmappingGAINS.csv", returnPathOnly = TRUE, where = "mrremind"), + stringsAsFactors = TRUE + )[, c(2, 3)] + + map_regions <- map_regions %>% filter(.data$CountryCode != "ANT") %>% # Remove Netherland Antilles (not in REMIND regional mapping) filter(.data$RegionCode != "") %>% - mutate(RegionCode = gsub("\\ \\+", "\\+", - gsub("^\\s+|\\s+$", "", - gsub("[0-9]", "", .data$RegionCode)))) %>% + mutate(RegionCode = gsub( + "\\ \\+", "\\+", + gsub( + "^\\s+|\\s+$", "", + gsub("[0-9]", "", .data$RegionCode) + ) + )) %>% mutate(CountryCode = factor(.data$CountryCode)) - # read in population and GDP data. required to compute gdp per cap - pop <- calcOutput("Population", aggregate = FALSE)[, p_dagg_year, p_dagg_pop] - gdp <- calcOutput("GDP", aggregate = FALSE)[, p_dagg_year, p_dagg_gdp] - + gdp_cap <- calcOutput("GDPpc", aggregate = FALSE)[, 2005, "gdppc_SSP2"] #-- PROCESS DATA ------------------ vcat(2, ">> Process data... \n") # set of sectors for which emission factors are computed dimSector_EF <- getNames(activities)[!getNames(activities) %in% c(dimSector_skipEF, dimSector_skipEF_edge)] - # calculate gdp per capita - gdp_cap <- gdp / pop - gdp_cap[is.na(gdp_cap)] <- 0 # set NA to 0 - # Regional selections # select one country pertaining to WEU (all WEU countries should have the same EF). Used for SSP scenario rules select_weu <- paste(map_regions[which(map_regions$RegionCode == "Western Europe")[1], 1]) # Retrieve Transport names transportNames <- getNames(activities)[grepl("End_Use_Transport", getNames(activities))] - - buildingNames <- getNames(activities)[grepl("End_Use_Industry|End_Use_Residential|End_Use_Services", getNames(activities))] + buildingNames <- getNames(activities)[grepl("End_Use_Industry|End_Use_Residential|End_Use_Services", getNames(activities))] # convert SO2 emission from TgSO2 to TgS emissions[, , "SO2"] <- emissions[, , "SO2"] * conv_ktSO2_to_ktS - # define missing SLE scenario (assumed to be 3/4 of the distance between CLE and MFR, according to discussion with Zig Klimont on 18th Feb 2016) + # define missing SLE scenario (assumed to be 3/4 of the distance between CLE and MFR, + # according to discussion with Zig Klimont on 18th Feb 2016) cle <- emissions[, , "CLE"] getNames(cle) <- gsub("CLE", "MFR", getNames(cle)) sle <- cle - (cle - emissions[, , "MFR"]) * 0.75 @@ -169,161 +144,209 @@ calcEmissionFactors <- function(subtype = "emission_factors", sectoral_resolutio emissions <- mbind(emissions, sle) rm(cle, sle) - # calculate emission factors (only for power and end-use sectors, and not empty activities) and convert from kt/PJ to Tg/Twa - ef_eclipse <- emissions[, , dimSector_EF] / + # calculate emission factors (only for power and end-use sectors, and not empty activities) + # and convert from kt/PJ to Tg/Twa + ef_eclipse <- emissions[, , dimSector_EF] / activities[, , dimSector_EF] * conv_kt_per_PJ_to_Tg_per_TWa - getSets(ef_eclipse) <- c("region", "year", "data1", "data2", "data3") - - # some regions/countries have NA values everywhere. Allocate EF of the region to which they belong (except for Antartica) - # NAregions <- which(sapply(getRegions(which(is.na(ef_eclipse), arr.ind = TRUE)), function(k) all(is.na(as.numeric(ef_eclipse[k,,]))))) - NAregions <- c("AIA", "ATF", "BVT", "CCK", "COK", "CXR", "ESH", "FLK", "GIB", "GLP", "GUF", - "HMD", "IOT", "MSR", "MTQ", "MYT", "NFK", "NIU", "NRU", "PCN", - "REU", "SGS", "SHN", "SJM", "SPM", "TKL", "TWN", "UMI", "VAT", "VGB", "WLF") + getSets(ef_eclipse) <- c("region", "year", "data1", "data2", "data3") + + # some regions/countries have NA values everywhere. Allocate EF of the region to which they belong (except for Antarctica) + NAregions <- c( + "AIA", "ATF", "BVT", "CCK", "COK", "CXR", "ESH", "FLK", "GIB", "GLP", "GUF", + "HMD", "IOT", "MSR", "MTQ", "MYT", "NFK", "NIU", "NRU", "PCN", + "REU", "SGS", "SHN", "SJM", "SPM", "TKL", "TWN", "UMI", "VAT", "VGB", "WLF" + ) MissingRegions <- c("ALA", "BES", "BLM", "CUW", "GGY", "IMN", "JEY", "MAF", "PSE", "SSD", "SXM") - AssociatedGAINSregions <- c("Western Europe", "Rest Central America", "Rest Central America", "Rest Central America", "Western Europe", "Western Europe", "Western Europe", - "Rest Central America", "Middle East", "Northern Africa", "Rest Central America") - ef_eclipse["ATA", , ] <- 0 # Antartica -> 0 + AssociatedGAINSregions <- c( + "Western Europe", "Rest Central America", "Rest Central America", "Rest Central America", + "Western Europe", "Western Europe", "Western Europe", + "Rest Central America", "Middle East", "Northern Africa", "Rest Central America" + ) + ef_eclipse["ATA", , ] <- 0 # Antarctica -> 0 for (kregi in NAregions) { subsitute_region <- map_regions$CountryCode[map_regions$RegionCode == map_regions$RegionCode[map_regions$CountryCode == kregi] & !map_regions$CountryCode %in% c(NAregions, MissingRegions)][1] tmp <- ef_eclipse[subsitute_region, , ] - getRegions(tmp) <- kregi + getItems(tmp, dim = 1) <- kregi ef_eclipse[kregi, , ] <- tmp } # some regions have no population data when disaggregating. for (kregi in MissingRegions) { substitute_region <- map_regions$CountryCode[map_regions$RegionCode == AssociatedGAINSregions[which(MissingRegions == kregi)] & - !map_regions$CountryCode %in% MissingRegions][1] + !map_regions$CountryCode %in% MissingRegions][1] tmp <- ef_eclipse[substitute_region, , ] - getRegions(tmp) <- kregi + getItems(tmp, dim = 1) <- kregi ef_eclipse[kregi, , ] <- tmp } # for the remaining NAs just set EF to 0 (activity levels are 0) - ef_eclipse[is.na(ef_eclipse)] <- 0 + ef_eclipse[is.na(ef_eclipse)] <- 0 rm(NAregions, MissingRegions, AssociatedGAINSregions) # define exogenous emission data emissions_exogenous <- emissions[, , dimSector_skipEF] # make output dummy "ef" and "emi" which then has to be filled by the data - ef <- do.call("mbind", - lapply(scenario, - function(s) { -new.magpie(getRegions(ef_eclipse), - c(2005, 2010, 2030, 2050, 2100), - gsub("CLE", s, getNames(ef_eclipse[, , "CLE"]))) - })) + ef <- do.call( + "mbind", + lapply( + scenario, + function(s) { + new.magpie( + getItems(ef_eclipse, dim = 1), + c(2005, 2010, 2030, 2050, 2100), + gsub("CLE", s, getNames(ef_eclipse[, , "CLE"])) + ) + } + ) + ) getSets(ef) <- c("region", "year", "data1", "data2", "data3") # forcing set names to avoid errors while filtering - emi <- do.call("mbind", - lapply(scenario, - function(s) { -new.magpie(getRegions(emissions_exogenous), - c(2005, 2010, 2030, 2050, 2100), - gsub("CLE", s, getNames(emissions_exogenous[, , "CLE"]))) - })) + emi <- do.call( + "mbind", + lapply( + scenario, + function(s) { + new.magpie( + getItems(emissions_exogenous, dim = 1), + c(2005, 2010, 2030, 2050, 2100), + gsub("CLE", s, getNames(emissions_exogenous[, , "CLE"])) + ) + } + ) + ) # define country categories if (p_countryCategories == "perCountry") { # low income countries (using World Bank definition < 2750 US$(2010)/Cap) - r_L <- dimnames(gdp_cap[getRegions(ef), , ])$ISO3[which(gdp_cap[getRegions(ef), , ] <= 2750)] + r_L <- dimnames(gdp_cap[getItems(ef, dim = 1), , ])$ISO3[which(gdp_cap[getItems(ef, dim = 1), , ] <= 2750)] # high and medium income countries - r_HM <- setdiff(getRegions(ef), r_L) + r_HM <- setdiff(getItems(ef, dim = 1), r_L) # High-Medium income countries with strong pollution policies in place - r_HMStrong <- c("AUS", "CAN", "USA", "JPN") # FIXME which definition??? + r_HMStrong <- c("AUS", "CAN", "USA", "JPN") # FIXME which definition??? # High-Medium income countries with lower emissions goals - r_HMRest <- setdiff(r_HM, r_HMStrong) + r_HMRest <- setdiff(r_HM, r_HMStrong) } else { # Compute mean GDP/Cap per GAINS region regionMean_gdppcap <- sapply(unique(map_regions$RegionCode), function(x) { -mean(gdp_cap[map_regions$CountryCode[map_regions$RegionCode == x], , ]) -}) + mean(gdp_cap[map_regions$CountryCode[map_regions$RegionCode == x], , ]) + }) # low income countries (using World Bank definition < 2750 US$(2010)/Cap) - r_L <- levels(map_regions$CountryCode[map_regions$RegionCode %in% names(regionMean_gdppcap[regionMean_gdppcap <= 2750])]) + r_L <- levels(map_regions$CountryCode[map_regions$RegionCode %in% names(regionMean_gdppcap[regionMean_gdppcap <= 2750])]) # high and medium income countries - r_HM <- setdiff(getRegions(ef), r_L) + r_HM <- setdiff(getItems(ef, dim = 1), r_L) # High-Medium income countries with strong pollution policies in place - r_HMStrong <- map_regions$CountryCode[map_regions$RegionCode %in% c("Western Europe", "Japan")] # FIXME definition taken from JeS matlab script + r_HMStrong <- map_regions$CountryCode[map_regions$RegionCode %in% c("Western Europe", "Japan")] # FIXME definition taken from JeS matlab script # High-Medium income countries with lower emissions goals - r_HMRest <- setdiff(r_HM, r_HMStrong) + r_HMRest <- setdiff(r_HM, r_HMStrong) } # generate FLE and SSP scenarios # -------- Fix all scenarios to CLE in 2005 and 2010 ---------- - ef[, c(2005, 2010), ] <- ef_eclipse[, c(2005, 2010), "CLE"] + ef[, c(2005, 2010), ] <- ef_eclipse[, c(2005, 2010), "CLE"] emi[, c(2005, 2010), ] <- emissions_exogenous[, c(2005, 2010), "CLE"] # ---------------- FLE ---------------------------------------- # FLE: CLE 2010 emission factors and emissions are held constant - ef[, , "FLE"] <- setYears(ef[, 2010, "FLE"], NULL) # NULL is actually the default value, skipping afterwards + ef[, , "FLE"] <- setYears(ef[, 2010, "FLE"], NULL) # NULL is actually the default value, skipping afterwards emi[, , "FLE"] <- setYears(emi[, 2010, "FLE"], NULL) # ---------------- SSP1 --------------------------------------- # Emission factors # low income countries - ef[r_L, 2030, "SSP1"] <- ef_eclipse[r_L, 2030, "CLE"] # 2030: CLE30 - ef[r_L, 2050, "SSP1"] <- pmin(setYears(ef[r_L, 2030, "SSP1"]), - setYears(allocate_c2r_ef(ef_eclipse, r_L, select_weu, 2030, "CLE"))) # 2050: CLE30 WEU, if not higher than 2030 value - ef[r_L, 2100, "SSP1"] <- pmin(setYears(ef[r_L, 2050, "SSP1"]), setYears(ef_eclipse[r_L, 2030, "SLE"])) # 2100: SLE30, if not higher than 2050 value + ef[r_L, 2030, "SSP1"] <- ef_eclipse[r_L, 2030, "CLE"] # 2030: CLE30 + ef[r_L, 2050, "SSP1"] <- pmin( + setYears(ef[r_L, 2030, "SSP1"]), + setYears(allocate_c2r_ef(ef_eclipse, r_L, select_weu, 2030, "CLE")) + ) # 2050: CLE30 WEU, if not higher than 2030 value + + # 2100: SLE30, if not higher than 2050 value + ef[r_L, 2100, "SSP1"] <- pmin(setYears(ef[r_L, 2050, "SSP1"]), setYears(ef_eclipse[r_L, 2030, "SLE"])) # high income countries - ef[r_HM, 2030, "SSP1"] <- 0.75 * ef_eclipse[r_HM, 2030, "CLE"] # 2030: 75% of CLE30 - ef[r_HM, 2050, "SSP1"] <- pmin(setYears(ef[r_HM, 2030, "SSP1"]), setYears(ef_eclipse[r_HM, 2030, "SLE"])) # 2050: SLE30, if not higher than 2030 value - ef[r_HM, 2100, "SSP1"] <- pmin(setYears(ef[r_HM, 2050, "SSP1"]), setYears(ef_eclipse[r_HM, 2030, "MFR"])) # 2100: MFR, if not higher than 2050 value + ef[r_HM, 2030, "SSP1"] <- 0.75 * ef_eclipse[r_HM, 2030, "CLE"] # 2030: 75% of CLE30 + # 2050: SLE30, if not higher than 2030 value + ef[r_HM, 2050, "SSP1"] <- pmin(setYears(ef[r_HM, 2030, "SSP1"]), setYears(ef_eclipse[r_HM, 2030, "SLE"])) + # 2100: MFR, if not higher than 2050 value + ef[r_HM, 2100, "SSP1"] <- pmin(setYears(ef[r_HM, 2050, "SSP1"]), setYears(ef_eclipse[r_HM, 2030, "MFR"])) # Emissions # low income countries - emi[r_L, 2030, "SSP1"] <- emissions_exogenous[r_L, 2030, "CLE"] # 2030: CLE30 - emi[r_L, 2050, "SSP1"] <- pmin(setYears(emi[r_L, 2030, "SSP1"]), setYears(0.5 * emissions_exogenous[r_L, 2030, "CLE"] - + 0.5 * emissions_exogenous[r_L, 2030, "SLE"])) # 2050: CLE30 WEU, if not higher than 2030 value - emi[r_L, 2100, "SSP1"] <- pmin(setYears(emi[r_L, 2050, "SSP1"]), setYears(emissions_exogenous[r_L, 2030, "SLE"])) # 2100: SLE30, if not higher than 2050 value + emi[r_L, 2030, "SSP1"] <- emissions_exogenous[r_L, 2030, "CLE"] # 2030: CLE30 + emi[r_L, 2050, "SSP1"] <- pmin(setYears(emi[r_L, 2030, "SSP1"]), setYears(0.5 * emissions_exogenous[r_L, 2030, "CLE"] + + 0.5 * emissions_exogenous[r_L, 2030, "SLE"])) # 2050: CLE30 WEU, if not higher than 2030 value + emi[r_L, 2100, "SSP1"] <- pmin(setYears(emi[r_L, 2050, "SSP1"]), setYears(emissions_exogenous[r_L, 2030, "SLE"])) # 2100: SLE30, if not higher than 2050 value # high income countries - emi[r_HM, 2030, "SSP1"] <- 0.75 * emissions_exogenous[r_HM, 2030, "CLE"] # 2030: 75% of CLE30 - emi[r_HM, 2050, "SSP1"] <- pmin(setYears(emi[r_HM, 2030, "SSP1"]), setYears(emissions_exogenous[r_HM, 2030, "SLE"])) # 2050: SLE30, if not higher than 2030 value - emi[r_HM, 2100, "SSP1"] <- pmin(setYears(emi[r_HM, 2050, "SSP1"]), setYears(emissions_exogenous[r_HM, 2030, "MFR"])) # 2100: MFR, if not higher than 2050 value + emi[r_HM, 2030, "SSP1"] <- 0.75 * emissions_exogenous[r_HM, 2030, "CLE"] # 2030: 75% of CLE30 + emi[r_HM, 2050, "SSP1"] <- pmin(setYears(emi[r_HM, 2030, "SSP1"]), setYears(emissions_exogenous[r_HM, 2030, "SLE"])) # 2050: SLE30, if not higher than 2030 value + emi[r_HM, 2100, "SSP1"] <- pmin(setYears(emi[r_HM, 2050, "SSP1"]), setYears(emissions_exogenous[r_HM, 2030, "MFR"])) # 2100: MFR, if not higher than 2050 value # ----------------- SSP2 -------------------------------------- # Emission factors # High-Medium income countries with strong pollution policies in place - ef[r_HMStrong, 2030, "SSP2"] <- ef_eclipse[r_HMStrong, 2030, "CLE"] # 2030: CLE30 - ef[r_HMStrong, 2050, "SSP2"] <- pmin(setYears(ef[r_HMStrong, 2030, "SSP2"]), - setYears(ef_eclipse[r_HMStrong, 2030, "SLE"])) # 2050: SLE30 - ef[r_HMStrong, 2100, "SSP2"] <- pmin(setYears(ef[r_HMStrong, 2050, "SSP2"]), - setYears(allocate_min2r_ef(ef_eclipse, r_HMStrong, r_oecd, 2030, "SLE"))) # 2100: Lowest SLE30 or lower + ef[r_HMStrong, 2030, "SSP2"] <- ef_eclipse[r_HMStrong, 2030, "CLE"] # 2030: CLE30 + ef[r_HMStrong, 2050, "SSP2"] <- pmin( + setYears(ef[r_HMStrong, 2030, "SSP2"]), + setYears(ef_eclipse[r_HMStrong, 2030, "SLE"]) + ) # 2050: SLE30 + ef[r_HMStrong, 2100, "SSP2"] <- pmin( + setYears(ef[r_HMStrong, 2050, "SSP2"]), + setYears(allocate_min2r_ef(ef_eclipse, r_HMStrong, r_oecd, 2030, "SLE")) + ) # 2100: Lowest SLE30 or lower # High-Medium income countries with lower emissions goals - ef[r_HMRest, 2030, "SSP2"] <- ef_eclipse[r_HMRest, 2030, "CLE"] # 2030: CLE30 - ef[r_HMRest, 2050, "SSP2"] <- pmin(setYears(ef[r_HMRest, 2030, "SSP2"]), - setYears(allocate_min2r_ef(ef_eclipse, r_HMRest, r_HMRest, 2030, "CLE"))) # 2050: Min CLE30 - ef[r_HMRest, 2100, "SSP2"] <- pmin(setYears(ef[r_HMRest, 2050, "SSP2"]), - setYears(allocate_c2r_ef(ef_eclipse, r_HMRest, select_weu, 2030, "SLE"))) # 2100: SLE30 WEU + ef[r_HMRest, 2030, "SSP2"] <- ef_eclipse[r_HMRest, 2030, "CLE"] # 2030: CLE30 + ef[r_HMRest, 2050, "SSP2"] <- pmin( + setYears(ef[r_HMRest, 2030, "SSP2"]), + setYears(allocate_min2r_ef(ef_eclipse, r_HMRest, r_HMRest, 2030, "CLE")) + ) # 2050: Min CLE30 + ef[r_HMRest, 2100, "SSP2"] <- pmin( + setYears(ef[r_HMRest, 2050, "SSP2"]), + setYears(allocate_c2r_ef(ef_eclipse, r_HMRest, select_weu, 2030, "SLE")) + ) # 2100: SLE30 WEU # low income countries - ef[r_L, 2030, "SSP2"] <- setYears(ef_eclipse[r_L, 2020, "CLE"]) # 2030: CLE20 - ef[r_L, 2050, "SSP2"] <- pmin(setYears(ef[r_L, 2030, "SSP2"]), - setYears(allocate_min2r_ef(ef_eclipse, r_L, r_L, 2030, "CLE"))) # 2050: Min CLE30 - ef[r_L, 2100, "SSP2"] <- pmin(setYears(ef[r_L, 2050, "SSP2"]), - setYears(allocate_c2r_ef(ef_eclipse, r_L, select_weu, 2030, "CLE"))) # 2100: CLE30 WEU + ef[r_L, 2030, "SSP2"] <- setYears(ef_eclipse[r_L, 2020, "CLE"]) # 2030: CLE20 + ef[r_L, 2050, "SSP2"] <- pmin( + setYears(ef[r_L, 2030, "SSP2"]), + setYears(allocate_min2r_ef(ef_eclipse, r_L, r_L, 2030, "CLE")) + ) # 2050: Min CLE30 + ef[r_L, 2100, "SSP2"] <- pmin( + setYears(ef[r_L, 2050, "SSP2"]), + setYears(allocate_c2r_ef(ef_eclipse, r_L, select_weu, 2030, "CLE")) + ) # 2100: CLE30 WEU # Emissions # High-Medium income countries with strong pollution policies in place - emi[r_HMStrong, 2030, "SSP2"] <- emissions_exogenous[r_HMStrong, 2030, "CLE"] # 2030: CLE30 - emi[r_HMStrong, 2050, "SSP2"] <- pmin(setYears(emi[r_HMStrong, 2030, "SSP2"]), - setYears(emissions_exogenous[r_HMStrong, 2030, "SLE"])) # 2050: SLE30 - emi[r_HMStrong, 2100, "SSP2"] <- pmin(setYears(emi[r_HMStrong, 2050, "SSP2"]), - setYears(emissions_exogenous[r_HMStrong, 2030, "SLE"] * 0.8)) # 2100: Lowest SLE30 or lower -> 0.8*SLE30 + emi[r_HMStrong, 2030, "SSP2"] <- emissions_exogenous[r_HMStrong, 2030, "CLE"] # 2030: CLE30 + emi[r_HMStrong, 2050, "SSP2"] <- pmin( + setYears(emi[r_HMStrong, 2030, "SSP2"]), + setYears(emissions_exogenous[r_HMStrong, 2030, "SLE"]) + ) # 2050: SLE30 + emi[r_HMStrong, 2100, "SSP2"] <- pmin( + setYears(emi[r_HMStrong, 2050, "SSP2"]), + setYears(emissions_exogenous[r_HMStrong, 2030, "SLE"] * 0.8) + ) # 2100: Lowest SLE30 or lower -> 0.8*SLE30 # High-Medium income countries with lower emissions goals - emi[r_HMRest, 2030, "SSP2"] <- emissions_exogenous[r_HMRest, 2030, "CLE"] # 2030: CLE30 - emi[r_HMRest, 2050, "SSP2"] <- pmin(setYears(emi[r_HMRest, 2030, "SSP2"]), - setYears(emissions_exogenous[r_HMRest, 2030, "SLE"])) # 2050: Min CLE30 -> SLE30 - emi[r_HMRest, 2100, "SSP2"] <- pmin(setYears(emi[r_HMRest, 2050, "SSP2"]), - setYears(emissions_exogenous[r_HMRest, 2030, "SLE"] * 0.8)) # 2100: SLE30 WEU -> 0.8*SLE30 + emi[r_HMRest, 2030, "SSP2"] <- emissions_exogenous[r_HMRest, 2030, "CLE"] # 2030: CLE30 + emi[r_HMRest, 2050, "SSP2"] <- pmin( + setYears(emi[r_HMRest, 2030, "SSP2"]), + setYears(emissions_exogenous[r_HMRest, 2030, "SLE"]) + ) # 2050: Min CLE30 -> SLE30 + emi[r_HMRest, 2100, "SSP2"] <- pmin( + setYears(emi[r_HMRest, 2050, "SSP2"]), + setYears(emissions_exogenous[r_HMRest, 2030, "SLE"] * 0.8) + ) # 2100: SLE30 WEU -> 0.8*SLE30 # low income countries - emi[r_L, 2030, "SSP2"] <- setYears(emissions_exogenous[r_L, 2020, "CLE"]) # 2030: CLE20 - emi[r_L, 2050, "SSP2"] <- pmin(setYears(emi[r_L, 2030, "SSP2"]), - setYears(emissions_exogenous[r_L, 2030, "CLE"])) # 2050: Min CLE30 -> CLE30 - emi[r_L, 2100, "SSP2"] <- pmin(setYears(emi[r_L, 2050, "SSP2"]), - setYears(emissions_exogenous[r_L, 2030, "SLE"] * 0.95)) # 2100: CLE30 WEU -> 0.95*SLE30 + emi[r_L, 2030, "SSP2"] <- setYears(emissions_exogenous[r_L, 2020, "CLE"]) # 2030: CLE20 + emi[r_L, 2050, "SSP2"] <- pmin( + setYears(emi[r_L, 2030, "SSP2"]), + setYears(emissions_exogenous[r_L, 2030, "CLE"]) + ) # 2050: Min CLE30 -> CLE30 + emi[r_L, 2100, "SSP2"] <- pmin( + setYears(emi[r_L, 2050, "SSP2"]), + setYears(emissions_exogenous[r_L, 2030, "SLE"] * 0.95) + ) # 2100: CLE30 WEU -> 0.95*SLE30 + # H-M-Strong: 2030 CLE30; 2050 SLE30; 2100 Lowest SLE30 or lower [EUR, JPN] = [3 5] # H-M-Rest: 2030 CLE30; 2050 Min CLE30; 2100 EUR SLE30 [CHN, LAM, MEA, ROW, RUS, USA] = [2 6 7 9 10 11] # Low: 2030 CLE20; 2050 Min CLE30; 2100 EUR CLE30 [AFR, IND, OAS] = [1 4 8] @@ -336,69 +359,18 @@ mean(gdp_cap[map_regions$CountryCode[map_regions$RegionCode == x], , ]) # ----------------- SSP5 -------------------------------------- # set SSP5 to the values of SSP1 - ef[, , "SSP5"] <- ef[, , "SSP1"] + ef[, , "SSP5"] <- ef[, , "SSP1"] emi[, , "SSP5"] <- emi[, , "SSP1"] # does not really make sense... - # Find occurences where the EF path is not monotonously decreasing -# for (kregi in getRegions(ef)) { -# for (kdata in getNames(ef)) { -# -# y1 = ef[kregi,2005,kdata] %>% as.numeric() -# y2 = ef[kregi,2010,kdata] %>% as.numeric() -# y3 = ef[kregi,2030,kdata] %>% as.numeric() -# y4 = ef[kregi,2050,kdata] %>% as.numeric() -# y5 = ef[kregi,2100,kdata] %>% as.numeric() -# -# if (y1 > y2 || y2 > y3 || y3 > y4 || y4 > y5) { -# print(paste0(kregi, ": ", kdata)) -# } -# } -# stop() -# } - - # make sure that SSP2 is always higher than SSP1 (and SSP5) - # Takes toooooooooooooo much time (~1h30). commented out for now -# for (kregi in getRegions(ef)) { -# for (kssp1 in getNames(ef[,,"SSP1"])) { -# -# kssp2 = paste0(strsplit(kdata, ".", fixed=TRUE)[[1]][1], ".", strsplit(kdata, ".", fixed=TRUE)[[1]][2], ".SSP2") -# -# for (kyear in getYears(ef)) { -# y1 = ef[kregi,kyear,kssp1] %>% as.numeric() -# y2 = ef[kregi,kyear,kssp2] %>% as.numeric() -# -# if (y1 > y2) { -# ef[kregi,kyear,kssp2] = y1 -# } -# } -# } -# } -# for (kregi in getRegions(emi)) { -# for (kssp1 in getNames(emi[,,"SSP1"])) { -# -# kssp2 = paste0(strsplit(kdata, ".", fixed=TRUE)[[1]][1], ".", strsplit(kdata, ".", fixed=TRUE)[[1]][2], ".SSP2") -# -# for (kyear in getYears(emi)) { -# y1 = emi[kregi,kyear,kssp1] %>% as.numeric() -# y2 = emi[kregi,kyear,kssp2] %>% as.numeric() -# -# if (y1 > y2) { -# emi[kregi,kyear,kssp2] = y1 -# } -# } -# } -# } - # filter all regions and sectors that are constant between 2030 and 2050 and continue to decline afterwards. Replace by linear interpolation # between 2030 and 2100 - # ----------------- CLE and MFR ------------------------------- ef[, c(2005, 2010, 2030, 2050), c("CLE", "MFR")] <- ef_eclipse[, c(2005, 2010, 2030, 2050), c("CLE", "MFR")] - ef[, 2100, c("CLE", "MFR")] <- setYears(ef_eclipse[, 2050, c("CLE", "MFR")]) # for 2100, take the same values as in 2050 + ef[, 2100, c("CLE", "MFR")] <- setYears(ef_eclipse[, 2050, c("CLE", "MFR")]) # for 2100, take the same values as in 2050 emi[, c(2005, 2010, 2030, 2050), c("CLE", "MFR")] <- emissions_exogenous[, c(2005, 2010, 2030, 2050), c("CLE", "MFR")] - emi[, 2100, c("CLE", "MFR")] <- setYears(emissions_exogenous[, 2050, c("CLE", "MFR")]) # for 2100, take the same values as in 2050 + emi[, 2100, c("CLE", "MFR")] <- setYears(emissions_exogenous[, 2050, c("CLE", "MFR")]) # for 2100, take the same values as in 2050 # ---------------- Global EURO6 for Transports ----------------------------- ef[, c(2030, 2050, 2100), "GlobalEURO6"] <- ef[, c(2030, 2050, 2100), "SSP2"] @@ -414,14 +386,14 @@ mean(gdp_cap[map_regions$CountryCode[map_regions$RegionCode == x], , ]) # ---------------- FLE_building_transport ------------------------------ ef[, c(2030, 2050, 2100), "FLE_building_transport"] <- ef[, c(2030, 2050, 2100), "SSP2"] - mselect(ef, year = c("y2030", "y2050", "y2100"), data1 = buildingNames, data3 = "FLE_building_transport") <- mselect(ef, year = c("y2030", "y2050", "y2100"), data1 = buildingNames, data3 = "FLE") + mselect(ef, year = c("y2030", "y2050", "y2100"), data1 = buildingNames, data3 = "FLE_building_transport") <- mselect(ef, year = c("y2030", "y2050", "y2100"), data1 = buildingNames, data3 = "FLE") mselect(ef, year = c("y2030", "y2050", "y2100"), data1 = transportNames, data3 = "FLE_building_transport") <- mselect(ef, year = c("y2030", "y2050", "y2100"), data1 = transportNames, data3 = "FLE") emi[, c(2030, 2050, 2100), "FLE_building_transport"] <- emi[, c(2030, 2050, 2100), "SSP2"] # ---------------- SLCF_building_transport ------------------------------ ef[, c(2030, 2050, 2100), "SLCF_building_transport"] <- ef[, c(2030, 2050, 2100), "SSP2"] - mselect(ef, year = c("y2030", "y2050", "y2100"), data1 = buildingNames, data2 = c("BC", "OC"), data3 = "SLCF_building_transport") <- mselect(ef, year = c("y2030", "y2050", "y2100"), data1 = buildingNames, data2 = c("BC", "OC"), data3 = "FLE") + mselect(ef, year = c("y2030", "y2050", "y2100"), data1 = buildingNames, data2 = c("BC", "OC"), data3 = "SLCF_building_transport") <- mselect(ef, year = c("y2030", "y2050", "y2100"), data1 = buildingNames, data2 = c("BC", "OC"), data3 = "FLE") mselect(ef, year = c("y2030", "y2050", "y2100"), data1 = transportNames, data2 = c("BC", "OC"), data3 = "SLCF_building_transport") <- mselect(ef, year = c("y2030", "y2050", "y2100"), data1 = transportNames, data2 = c("BC", "OC"), data3 = "FLE") emi[, c(2030, 2050, 2100), "SLCF_building_transport"] <- emi[, c(2030, 2050, 2100), "SSP2"] @@ -430,45 +402,52 @@ mean(gdp_cap[map_regions$CountryCode[map_regions$RegionCode == x], , ]) emiNam <- getNames(ef, TRUE)[2:3] newdim <- apply( sapply( - do.call("expand.grid", emiNam), as.character), - 1, paste, collapse = ".") - - activities.EF <- do.call("mbind", - lapply(newdim, - function(scen) { -setNames(activities[, , dimSector_EF], paste(getNames(activities[, , dimSector_EF]), scen, sep = ".")) -})) - # activities.full <- time_interpolate(activities.full, interpolated_year=time, integrate=TRUE, extrapolation_type="constant") - # activities.full <- activities.full[,time,] #remove 2000 + do.call("expand.grid", emiNam), as.character + ), + 1, paste, + collapse = "." + ) + + activities.EF <- do.call( + "mbind", + lapply( + newdim, + function(scen) { + setNames(activities[, , dimSector_EF], paste(getNames(activities[, , dimSector_EF]), scen, sep = ".")) + } + ) + ) getSets(ef) <- c("region", "year", "sector.species.scenario") getSets(activities.EF) <- c("region", "year", "sector.species.scenario") - # ef_eclipseR = toolAggregate(ef_eclipse[,,dimSector_EF], map_REMINDregions[,2:3], weight=setYears(activities[,2010,dimSector_EF])) - # ef_remind = toolAggregate(ef, map_REMINDregions[,2:3], weight=setYears(activities.EF[,2010,])) - # ----- EFs for advanced coal and biomass technologies ------- - mapsec <- map_sectors_ECLIPSE2REMIND[map_sectors_ECLIPSE2REMIND$eclipse %in% getNames(ef, dim = 1), c(1, 3)] + mapsec <- map_sectors_ECLIPSE2REMIND %>% + filter(.data$eclipse %in% getNames(ef, dim = 1)) %>% + select(c(1, 3)) + ef <- toolAggregate(ef, mapsec, dim = 3.1) - adv_techs <- c("igcc", "igccc", "pcc", "pco", "coalgas", "bioigcc", "bioigccc", "biogas") - adv_coaltechs <- c("igcc", "igccc", "pcc", "pco") - adv_biotechs <- c("coalgas", "bioigcc", "bioigccc", "biogas") - adv_specs <- c("NOx", "SO2", "BC", "OC") - adv_factor <- c(0.85, 0.6, 0.6, 0.6) + adv_techs <- c("igcc", "igccc", "coalgas", "bioigcc", "bioigccc", "biogas") + adv_coaltechs <- c("igcc", "igccc") + adv_specs <- c("NOx", "SO2", "BC", "OC") + adv_factor <- c(0.85, 0.6, 0.6, 0.6) - for (kscen in getNames(ef, dim = 6)) { + for (kscen in getNames(ef, dim = 6)) { for (ktech in adv_techs) { curtech <- ifelse(ktech %in% adv_coaltechs, "Power_Gen_Coal.", "Power_Gen_Bio_Trad.") - for (kspec in adv_specs) + for (kspec in adv_specs) { nm <- getNames(ef[, , paste0("power.", kspec)][, , ktech][, , kscen]) - ef[, intersect(getYears(ef), getYears(ef_eclipse)), paste0("power.", kspec)][, , ktech][, , kscen] <- setNames( - pmin( - mbind(lapply(getYears(ef), function(x) { -setYears(ef_eclipse[, 2030, paste0(curtech, kspec, ".MFR")] / adv_factor[adv_specs == kspec], x) -}))[, intersect(getYears(ef), getYears(ef_eclipse)), ], - ef_eclipse[, intersect(getYears(ef), getYears(ef_eclipse)), paste0(curtech, kspec, ".CLE")]), - nm) + } + ef[, intersect(getYears(ef), getYears(ef_eclipse)), paste0("power.", kspec)][, , ktech][, , kscen] <- setNames( + pmin( + mbind(lapply(getYears(ef), function(x) { + setYears(ef_eclipse[, 2030, paste0(curtech, kspec, ".MFR")] / adv_factor[adv_specs == kspec], x) + }))[, intersect(getYears(ef), getYears(ef_eclipse)), ], + ef_eclipse[, intersect(getYears(ef), getYears(ef_eclipse)), paste0(curtech, kspec, ".CLE")] + ), + nm + ) } } @@ -478,27 +457,27 @@ setYears(ef_eclipse[, 2030, paste0(curtech, kspec, ".MFR")] / adv_factor[adv_spe # interpolate data (EFs and activities) over time. Remove y2000 from activities (this is the first time item hence -1) vcat(2, " > Interpolate data over time... \n") - ef <- time_interpolate(ef, interpolated_year = time, integrate_interpolated_years = TRUE, extrapolation_type = "constant") + ef <- time_interpolate(ef, interpolated_year = time, integrate_interpolated_years = TRUE, extrapolation_type = "constant") emi <- time_interpolate(emi, interpolated_year = time, integrate_interpolated_years = TRUE, extrapolation_type = "constant") - # change scenario names - # getNames(emi) <- gsub("SSP","forcing_SSP",getNames(emi)) - # getNames(ef) <- gsub("SSP","forcing_SSP",getNames(ef)) - if (subtype == "emissions") { x <- emi w <- NULL } else if (subtype == "emission_factors") { x <- ef w <- setYears(activities.EF[, 2010, dimSector_EF]) - mapsec <- map_sectors_ECLIPSE2REMIND[map_sectors_ECLIPSE2REMIND$eclipse %in% getNames(w, dim = 1), c(1, 3)] + mapsec <- map_sectors_ECLIPSE2REMIND %>% + filter(.data$eclipse %in% getNames(w, dim = 1)) %>% + select(c(1, 3)) w <- toolAggregate(w, mapsec, dim = 3.1) - # getNames(w) <- gsub("SSP","forcing_SSP",getNames(w)) - } else (stop("do not know which weight to use for acrivities")) - - return(list(x = x, - weight = w, - unit = "unit", - description = "calcECLIPSE substitute" - )) + } else { + stop("do not know which weight to use for activities") + } + + return(list( + x = x, + weight = w, + unit = "unit", + description = "calcECLIPSE substitute" + )) } diff --git a/R/calcEmissionFactorsFeedstocks.R b/R/calcEmissionFactorsFeedstocks.R index f17ae927..663076b8 100644 --- a/R/calcEmissionFactorsFeedstocks.R +++ b/R/calcEmissionFactorsFeedstocks.R @@ -11,8 +11,6 @@ #' @seealso [`calcOutput()`] #' #' @importFrom dplyr filter pull select -#' @importFrom madrat getISOlist toolFillYears -#' @importFrom magclass new.magpie getItems #' @importFrom rlang .data #' @importFrom tibble as_tibble diff --git a/R/calcEmissions.R b/R/calcEmissions.R index af6652a1..91809b57 100644 --- a/R/calcEmissions.R +++ b/R/calcEmissions.R @@ -1,15 +1,12 @@ #' @title calcEmissions #' #' @return magpie object with historical emissions -#' @param datasource "CEDS16", "CEDS2REMIND", "CEDS2021", "EDGAR", "EDGAR6", "LIMITS", "ECLIPSE", "GFED", "CDIAC" +#' @param datasource "CEDS16", "CEDS2REMIND", "CEDS2024", "EDGAR", "EDGAR6", +#' "EDGAR8" "LIMITS", "ECLIPSE", "GFED", "CDIAC" #' #' @author Steve Smith, Pascal Weigmann #' -#' @importFrom magclass ndim setNames getNames<- #' @importFrom utils read.csv2 -#' @importFrom dplyr filter_ mutate_ - - calcEmissions <- function(datasource = "CEDS16") { ## ---- CEDS 16 ---- if (datasource == "CEDS16") { @@ -233,47 +230,39 @@ calcEmissions <- function(datasource = "CEDS16") { description <- "historic emissions from 1970-2015" - ## ---- CEDS 2021 ---- - } else if (datasource == "CEDS2021") { + ## ---- CEDS 2024 ---- + } else if (datasource == "CEDS2024") { # read CEDS emissions data from source (in Mt) # opposed to older version, doesn't contain Land-Use Change and thus no # aggregation to highest level is performed - emi <- readSource("CEDS2021") + emi <- readSource("CEDS2024") - # remove 6B_Other-not-in-total but warn in case it contains data - if (any(!emi[, , "6B_Other-not-in-total"] == 0)) { - cat( - "CEDS59 sector 6B_Other-not-in-total was removed - although it contains data! Please check CEDS source files.\n" - ) - } + # remove 6B_Other-not-in-total (no data in there anyway) emi <- emi[, , "6B_Other-not-in-total", invert = TRUE] - # aggregate and rename CEDS59 sectors to REMIND sectors - map_CEDS59_to_REMIND <- - toolGetMapping(type = "sectoral", - name = "mappingCEDS59toREMINDreporting_2021.csv", - where = "mappingfolder") + # aggregate and rename CEDS sectors to REMIND sectors + map <- toolGetMapping(type = "sectoral", + name = "mappingCEDS2024toREMIND.csv", + where = "mrremind") emi <- toolAggregate( x = emi, weight = NULL, dim = 3.1, - rel = map_CEDS59_to_REMIND, - from = "CEDS59", + rel = map, + from = "CEDS2024", to = "REMIND" ) - # undo unnecessary conversion from convertCEDS2021.R + # undo unnecessary conversion from convertCEDS2024 emi[, , "n2o_n"] <- emi[, , "n2o_n"] * 44 / 28 emi[, , "nh3_n"] <- emi[, , "nh3_n"] * 17 / 14 emi[, , "no2_n"] <- emi[, , "no2_n"] * 46 / 14 emi[, , "co2_c"] <- emi[, , "co2_c"] * 44 / 12 # rename emissions according to map - map <- - c( - bc_c = "BC", + emi_map <- + c(bc_c = "BC", ch4 = "CH4", co = "CO", co2_c = "CO2", @@ -282,9 +271,8 @@ calcEmissions <- function(datasource = "CEDS16") { no2_n = "NOX", nmvoc = "VOC", oc_c = "OC", - so2 = "SO2" - ) - getNames(emi, dim = 2) <- map[getNames(emi, dim = 2)] + so2 = "SO2") + getNames(emi, dim = 2) <- emi_map[getNames(emi, dim = 2)] # sectoral sums emi <- @@ -301,7 +289,7 @@ calcEmissions <- function(datasource = "CEDS16") { emi[, , "Energy|Supply|Heat"] + emi[, , "Energy|Supply|Fuel Production"] - #Addition of new items for industry subsectors + # Addition of new items for industry subsectors emi <- add_columns(emi, "Energy|Demand|Industry", dim = 3.1) emi[, , "Energy|Demand|Industry"] <- emi[, , "Energy|Demand|Industry|Chemicals"] + @@ -426,7 +414,7 @@ calcEmissions <- function(datasource = "CEDS16") { tmp[, , "Emi|GHG|Industrial Processes (Mt CO2eq/yr)"] + tmp[, , "Emi|GHG|Energy|Demand|Industry (Mt CO2eq/yr)"] - description <- "historic emissions from 1750-2019" + description <- "historic emissions from 1750-2022" ## ---- EDGAR ---- } else if (datasource == "EDGAR") { diff --git a/R/calcEmploymentfactors.R b/R/calcEmploymentfactors.R deleted file mode 100644 index 3d007f65..00000000 --- a/R/calcEmploymentfactors.R +++ /dev/null @@ -1,247 +0,0 @@ -#' @title calcEmploymentfactors -#' @description Collects and combines employment factors for different technologies and activities, from different sources. For all activities except Fuel_supply, units are Full Time Equivalent (FTE)/MW. For Fuel supply, units are FTE/PJ; for nuclear FTE/GWh. The param improvements denotes specific country-level data and is considered an improvement over stock data from rutovitz2015(none) -#' @author Aman Malik -#' @param improvements Either "None", "CEEW", "Dias", "Rutovitz_aus","Solar_found" or "All". Use "All" for all improvements. -#' @param multiplier source of regional multiplier. Either "Ram", "Rutovitz", "own" or "static". By default use "own" - -#' @return employment factors aggregated by region for certain techs and activities - -calcEmploymentfactors <- function(improvements,multiplier){ - if (improvements=="None"||improvements=="CEEW"||improvements=="Dias"||improvements=="Rutovitz_aus"||improvements=="Solar_found"||improvements=="All"){ - mapping <- toolGetMapping(type = "regional",name = "regionalmappingWEO2014.csv", where = "mappingfolder") - mapping_remind <- toolGetMapping(type = "regional",name = "regionmappingH12.csv", where = "mappingfolder") - colnames(mapping) <- c("region","country") - mapping$country <- toolCountry2isocode(mapping$country) - - oecd <- c("OECD Europe","OECD Americas","OECD Asia Oceania") - oecd_con <- mapping[mapping$region %in% oecd,]$country - # all non-OECD countries (difference taken between countries listed in remindH12 mapping file and IEA region/country definition assumed in Rutovitz et al.) - non_oecd <- setdiff(mapping_remind$CountryCode,oecd_con) - - - #x1->oecd efs, x2 -> regional multiplier, x3-> regional_ef, x4-> coal_ef, x5-> gas_ef, x6-> IND specofoc EF, - #x7-> EU_specific_coal EF, x9-> AUS specific EF, x10-> US_specific EF - - x1 <- readSource(type = "Rutovitz2015",subtype = "oecd_ef")[,2020,]# EFs for OECD countries in 2020. The 2020 values taken from Rutovitz. - - if (multiplier=="Rutovitz"){ - x2 <- readSource(type = "Rutovitz2015",subtype = "regional_mult") # regional multipliers for non-OECD countries - - # for countries left out by rutovitz2015, they should get values depending on their location. Since these are mostly small island nations, they get values for africa (here ghana is taken as reprs.) - x2[which(x2==0),] <- as.numeric(x2["GHA",,]) - x2_tmp <- new.magpie(getRegions(x2),c(getYears(x2),"y2050"),getNames(x2)) - x2_tmp[,getYears(x2),] <- x2 - x2_tmp[,2050,] <- 1 - x2_tmp <- time_interpolate(x2_tmp,c(2025,2035,2040,2045),integrate_interpolated_years = T) - x2 <- x2_tmp - - } - - if (multiplier=="Ram"){ - x2 <- readSource("Ram") - } - - if (multiplier=="own"||multiplier=="static"){ - # LP is labor productivity - y <- readSource("ConferenceBoard") - #y <- collapseNames(y,collapsedim = 2) - y_lp <- y[,"y2019","Output per person (without agriculture)"] - y_lp <- y_lp/ magclass::colMeans(y_lp[oecd_con,,],dims = 1) # all LP relative to average oecd LP - x2 <- new.magpie(mapping_remind$CountryCode,seq(2015,2050,5)) # will eventually be the regional multiplier from 2015 to 2050 - x2[,2020,] <- 1/y_lp # 2020 regional multiplier based on inverse of 2020 labour productivity - x2[oecd_con,2020,] <- 1 # all oecd countries have the same multiplier because they have the same Employment factor - y_gdpcc <- calcOutput("GDPpc", naming = "scenario", aggregate = F)[ , seq(2015, 2050, 5), "SSP2"] # SSP2 gdp per capita projections - y_gdpcc <- y_gdpcc/setYears(y_gdpcc[,2020,],NULL)# relative to 2020 since we only want the growth and not absolute values - x2[,c(2015,seq(2025,2050,5)),] <- setYears(x2[,2020,],NULL)*(1/y_gdpcc[,c(2015,seq(2025,2050,5))]) - - } - - x3 <- readSource(type = "Rutovitz2015",subtype = "regional_ef")[,2015,] # EFs for specific regions and techs - getYears(x3) <- 2020 - # x4 <- readSource(type = "Rutovitz2015",subtype = "coal_ef")[,2015,]# EFs for coal fuel supply - # getYears(x4) <- 2020 - # Coal fuel_supply employment factors - x4 <- calcOutput("CoalLabourProductivity",subtype = "Employment_factor",aggregate = F)[,2020,] - # Gas fuel supply employment factors - x5 <- readSource(type = "Rutovitz2015",subtype = "gas_ef")[,2015,]# EFs for gas fuel supply - getYears(x5) <- 2020 - - if (improvements=="CEEW"||improvements=="All"){ - x6 <- readSource(type = "CEEW",subtype = "Employment factors") # EFs for India from CEEW - getRegions(x6) <- "IND" - getYears(x6) <- 2020 - } - - if (improvements=="Dias"||improvements=="All"){ - x7 <- readSource(type = "Dias", subtype = "Employment factors") # EFs for coal and coal mining for EU - # using Dias et al. data, regions with non-zero values - getYears(x7) <- 2020 - regs <- getRegions(x7)[which(x7>0)] - x7 <- x7[regs,,] - } - - if (improvements=="Rutovitz_aus"||improvements=="All"){ - # Data from Renewable Energy Jobs in Australia: Stage One, June 2020 by Rutovitz et al. - x9 <- new.magpie(cells_and_regions = "AUS",2020, - names = c("Wind onshore","Solar|PV-utility","Solar|PV-rooftop","Storage|Battery","Hydro-large")) - x9 <- add_dimension(x9,dim = 3.2,nm = c("CI","OM")) - x9[,,"Wind onshore",pmatch=T] <- c(2.8,0.2) - x9[,,"Solar|PV-utility",pmatch=T] <- c(2.3,0.1) - x9[,,"Solar|PV-rooftop",pmatch=T] <- c(5.8,0.2) - x9[,,"Storage|Battery",pmatch=T] <- c(4.7,1.2) - x9[,,"Hydro-large",pmatch=T] <- c(6,0.15) - - } - - if (improvements=="Solar_found"||improvements=="All"){ - # from “National Solar Jobs Census 2018, The Solar Foundation, available at: SolarJobsCensus.org” for USA - # oil and gas EF from the total oil and gas extraction jobs (US bureua of Labour statistics) and BP Production 2020 - x10 <- new.magpie(cells_and_regions = "USA",2020, - names = c("Solar|PV-utility.CI","Solar|PV-rooftop.CI","Hydro-large.OM","Hydro-small.OM","Oil.Fuel_supply","Gas.Fuel_supply")) - - x10[,,] <- c(3.3,31,0.1,2.5,3.3,3.3) # 31 is taken as an average for residential (38.7) and non-residential (21.9) - # hydro numbers from Job Creation Opportunities in Hydropower, Navigant consulting 2009 for USA - } - - - - # solar pv numbers are actually for utility scale - getNames(x1) <- gsub(x = getNames(x1),replacement = "Solar|PV-utility",pattern = "Solar\\|PV") - getNames(x3) <- gsub(x = getNames(x3),replacement = "Solar|PV-utility",pattern = "Solar\\|PV") - - # Changes for OECD countries in 2020 using updated data - x1[,,"Solar|PV-utility.CI"] <- 3.2 # from IRENA (2017), Renewable energy benefits: Leveraging local capacity for solar PV, - x1[,,"Solar|PV-utility.Manf"] <- 3.4 # from IRENA (2017), Renewable energy benefits: Leveraging local capacity for solar PV, - x1[,,"Wind onshore.CI"] <- 3.3 # from IRENA (2017) Renewable energy benefits: Leveraging capacity for wind onshore - x1[,,"Wind onshore.Manf"] <- 1.7 # - x1[,,"Wind onshore.OM"] <- 0.19 # Fragkos is the average data for OM from Fragkos and Paroussos, "Employment creation in EU related to renewables expansion", Applied Energy, 2018 - # only those OM values are used which deviate significantly from Rutovitz et al. These are assumed to be for all OECD countries - x1[,,"Solar|PV-utility.OM"] <- 0.15 # Fragkos - x1[,,"Biomass.OM"] <- 0.25 # Fragkos - - # differentiate Solar PV into utility and rooftop - x1 <- add_columns(x1,"Solar|PV-rooftop", dim = 3.1) - # Rooftop gets 2 X Utility values, but for CI and OM only - from Supplementary info Ram et al. who cite a Solar Power Europe 2020 study - x1[,,"Solar|PV-rooftop"][,,c("OM","CI")] <- 2*x1[,,"Solar|PV-utility"][,,c("OM","CI")] - # for Manf, values same as spv utility. Fuel supply is anyway 0 - x1[,,"Solar|PV-rooftop"][,,c("Manf","Fuel_supply")] <- x1[,,"Solar|PV-utility"][,,c("Manf","Fuel_supply")] - x1 <- add_columns(x1,"Storage|Battery",dim = 3.1) - - # add battery storage jobs - x1[,,"Storage|Battery.Manf"] <- 16.9 # values for Battery storage large scale from Supplementary info. (sheet Employment factors) Ram et al. 2019 - x1[,,"Storage|Battery.CI"] <- 10.8 - x1[,,"Storage|Battery.OM"] <- 0.4 - x1[,,"Storage|Battery.Fuel_supply"] <- 0 # No fuel supply component - x1[,,"Hydro-large.CI"] <- 5 # changed because REMIND numbers in 2020 are much higher than IRENA numbers (from 7.4 to 5) - x1[,,"Hydro-large.OM"] <- 0.1 # changed because REMIND numbers in 2020 are much higher than IRENA numbers (from 0.2 to 0.1) - x1[,,"Hydro-small.OM"] <- 2.5 # changed because REMIND numbers in 2020 are much higher than IRENA numbers (from 4.9 to 2) - x1[,,"Biomass.Fuel_supply"] <- 25 - - - ###### Step 1-3 are for 2020 ONLY!! - # Step 1: all countries get OECD values, DEU as reprs. - x1[,,] <- x1["DEU",,] - - # Step 2: Multiply all non-oecd countries by a regional multiplier, relative to OECD - # for 2020 - if (multiplier=="Rutovitz"){ - x1[non_oecd,,] <- x1[non_oecd,,] * setNames(x2[non_oecd,2020,],nm = NULL) - } - - if(multiplier=="Ram"){ - x1[non_oecd,,] <- x1[non_oecd,,] * setNames(x2[non_oecd,2020,],nm = NULL) - - } - - if(multiplier=="own"||multiplier=="static"){ - x1[non_oecd,,] <- x1[non_oecd,,] * setNames(x2[non_oecd,2020,],nm = NULL) - } - # Step 3: overwrite efs (values) for 2020 for countries for which there is - # better data - - # 3a.Replacing EFs in x1 for common elements in x1 and x3, only for 2020 - for (i in getRegions(x3)){ - for (j in setdiff(getNames(x3),c("Solar|PV-utility.CI","Solar|PV-utility.OM"))){ # all except solar pv utility for OECD North America as this seems to be over-estimated - if (x3[i,,j]!=0) # for all non-zero values in x3, replace data in x1 with x3 - (x1[i,,j] <- x3[i,,j]) - } - } - - - # 3b. Replacing coal fuel supply EFs in x1 with those of x4, only for 2020 - x1[,,"Coal.Fuel_supply"] <- setNames(x4[,,],NULL) - - - # 3c. Replacing gas and oil EFs in x1 with those of x5, only for 2020 - for (i in getRegions(x5)){ - for (j in getNames(x5)){ - if (x5[i,,j]!=0) - (x1[i,,j] <- x5[i,,j]) - } - } - # for india - if (improvements=="CEEW"||improvements=="All"){ - x1[getRegions(x6),,getNames(x6)] <- x6[,,] - } - # For EU - coal o&m - if (improvements=="Dias"||improvements=="All"){ - x1[regs,,getNames(x7)] <- x7[regs,,] - } - # For AUS - battery, hydro etc. - if (improvements=="Rutovitz_aus"||improvements=="All"){ - x1[getRegions(x9),,getNames(x9)] <- x9[,,] - } - # For USA - solar - if (improvements=="Solar_found"||improvements=="All"){ - x1[getRegions(x10),,getNames(x10)] <- x10[,,] - } - - ## Step 4: Regional multipliers for year > 2020, normalised to 2020 and extrapolated until 2050 (only for Rutovitz) - - x1_tmp <- new.magpie(getRegions(x1),seq(2015,2050,5),getNames(x1),fill=1) - x1_tmp[,getYears(x1),] <- x1 - x1 <- x1_tmp - x2[,,] <- x2[,,]/setYears(x2[,"y2020",],NULL) - if (multiplier=="Ram"){x2[oecd_con,,] <- 1} # EF for OECD countries does not change - if(multiplier=="static"){ # efs in all future years for all countries remains same as in 2020 - x2[,seq(2020,2050,5),] <- x2[,2020,] - } - # future values based on regional multipliers - x1[,,] <- setNames(x2[,,],NULL)*setYears(x1[,2020,],NULL) - - - x1 <- collapseNames(x1) - -} -# for regional aggregation. The weights for different technologies are based on -# either the total production/generation of that fuel/resource or employment -gen <- readSource("BP",subtype = "Generation") -prod <- readSource("BP",subtype = "Production") -wt <- x1 -y <- readSource("ConferenceBoard") -wt[,,c("Solar|PV","Storage"),pmatch = T] <- gen[,"y2019","Generation|Solar (TWh)"] -wt[,,"Hydro",pmatch = T] <- gen[,"y2019","Generation|Hydro (TWh)"] -wt[,,c("Coal.OM","Coal.CI","Coal.Manf")] <- gen[,"y2019","Generation|Electricity|Coal (TWh)"] -wt[,,c("Gas.OM","Gas.CI","Gas.Manf")] <- gen[,"y2019","Generation|Electricity|Gas (TWh)"] -wt[,,c("Oil.OM","Oil.CI","Oil.Manf")] <- gen[,"y2019","Generation|Electricity|Oil (TWh)"] -wt[,,"Wind",pmatch = T] <- gen[,"y2019","Generation|Wind (TWh)"] -wt[,,"Nuclear",pmatch = T] <- gen[,"y2019","Generation|Nuclear (TWh)"] -wt[,,"Coal.Fuel_supply"] <- prod[,"y2019","Coal Production (EJ)"] -wt[,,"Gas.Fuel_supply"] <- prod[,"y2019","Gas Production (EJ)"] -wt[,,"Oil.Fuel_supply"] <- prod[,"y2019","Oil Production (million t)"] -wt[,,"Biomass.Fuel_supply"] <- y[,"y2019","Employment in agriculture"] - - - # using gdp per capita fpr regional aggregation - # gdp <- calcOutput("GDP", years=2020, aggregate = F) - # gdp <- gdp[,,"gdp_SSP2"] - - # pop <- calcOutput("Population",aggregate = F) - # pop <- pop[,seq(2015,2050,5),"pop_SSP2"] - - # gdppercap <- gdp/pop - - return(list(x=x1, weight=wt, unit="FTE/MW or FTE/PJ", - description="Employment factors")) - -} diff --git a/R/calcEuropeanEnergyDatasheets.R b/R/calcEuropeanEnergyDatasheets.R index 8864ac8f..d8ac018e 100644 --- a/R/calcEuropeanEnergyDatasheets.R +++ b/R/calcEuropeanEnergyDatasheets.R @@ -7,8 +7,6 @@ #' @author Falk Benke #' #' @importFrom dplyr select mutate left_join -#' @importFrom madrat toolGetMapping -#' @importFrom magclass as.magpie #' @importFrom rlang sym #' @importFrom stats aggregate na.exclude @@ -30,32 +28,25 @@ calcEuropeanEnergyDatasheets <- function(subtype) { mapping <- toolGetMapping("Mapping_EuropeanEnergyDatasheets.csv", type = "reportingVariables", where = "mrremind") %>% filter(!is.na(!!sym("REMIND")), !!sym("REMIND") != "") %>% - mutate(!!sym("Conversion") := as.numeric(!!sym("Conversion"))) %>% + mutate("Conversion" = as.numeric(.data$Conversion)) %>% select("variable" = "EED", "REMIND", "Conversion") mapping$variable <- trimws(mapping$variable) mapping$REMIND <- trimws(mapping$REMIND) - x <- left_join( - data, - mapping, - by = "variable", - relationship = "many-to-many" - ) %>% - filter(!!sym("REMIND") != "") %>% - mutate( - !!sym("value") := !!sym("value") * !!sym("Conversion") - ) %>% + x <- left_join(data, mapping, by = "variable", relationship = "many-to-many") %>% + filter(.data$REMIND != "") %>% + mutate("value" = .data$value * .data$Conversion) %>% select("region", "year", "variable" = "REMIND", "value") x <- aggregate(value ~ region + year + variable, x, sum, na.action = na.exclude) %>% as.magpie() %>% toolCountryFill(fill = NA, verbosity = 2) - # get GBR data from older versions of the source, as it is no longer updated eurostat.gbr <- readSource("EuropeanEnergyDatasheets", subtype = "EU28")["GBR", , ] - x["GBR", getItems(eurostat.gbr, dim = 2), ] <- eurostat.gbr + commonVars <- intersect(getNames(eurostat.gbr), getNames(x)) + x["GBR", getItems(eurostat.gbr, dim = 2), commonVars] <- eurostat.gbr[, , commonVars] x <- add_columns(x, "Emi|CO2|Industry (Mt CO2/yr)", dim = 3.1) x[, , "Emi|CO2|Industry (Mt CO2/yr)"] <- diff --git a/R/calcExogDemScen.R b/R/calcExogDemScen.R index 5e64c68d..7ad8d572 100644 --- a/R/calcExogDemScen.R +++ b/R/calcExogDemScen.R @@ -1,77 +1,95 @@ #' calculate exogenuous FE and ES demand pathways -#' @description prepare data for exogenuous FE and ES demand pathways that do not come from EDGE models but from other sources and/or scenario literature. +#' @description prepare data for exogenuous FE and ES demand pathways that do not +#' come from EDGE models but from other sources and/or scenario literature. #' REMIND can be fixed to those demand pathways if the switch cm_exogDem_scen is activated. #' #' @return A [`magpie`][magclass::magclass] object. #' @author Felix Schreyer -#' @importFrom magclass mselect collapseNames getNames getRegions - - calcExogDemScen <- function() { - ### ARIADNE steel and cement production trajectories for Germany from FORECAST - # read scenario data from Ariadne IIASA database - AriadneDB.data <- readSource("AriadneDB") + data <- readSource("AriadneDB") - # which variables, scenarios and models from ariadne DB to select + # which variables, scenarios and models from Ariadne DB to select ariadne.vars <- c("Production|Steel|Primary", "Production|Steel|Secondary", "Production|Non-Metallic Minerals|Cement") - ariadne.scens <- c("8Gt_Bal v2","8Gt_EnSec") + ariadne.scens <- c("KN2045_Bal_v4", "KN2045plus_EasyRide", "KN2045minus_WorstCase") ariadne.model <- c("FORECAST v1_0") - # select only specified variables and scenarios for Germany, # convert from Mt production to Gt production - ariadne.ind.demand <- mselect(AriadneDB.data["DEU",,]*1e-3, - variable = ariadne.vars, - scenario = ariadne.scens,model = ariadne.model) - - # map ariadne scenarios and variables to scenario and production factor names used for input data in REMIND - mapping.scens <- data.frame( scen.ariadne = ariadne.scens, - scen.remind = c("ariadne_bal", - "ariadne_ensec")) - - mapping.vars <- data.frame( vars.ariadne = ariadne.vars, - vars.remind = c("ue_steel_primary", - "ue_steel_secondary", - "ue_cement")) + ariadne.ind.demand <- mselect(data["DEU", , ] * 1e-3, + variable = ariadne.vars, + scenario = ariadne.scens, + model = ariadne.model + ) + + # map Ariadne scenarios and variables to scenario and production factor names used for input data in REMIND + mapping.scens <- data.frame( + scen.ariadne = ariadne.scens, + scen.remind = c( + "ariadne_bal", + "ariadne_lowDem", + "ariadne_highDem" + ) + ) + + mapping.vars <- data.frame( + vars.ariadne = ariadne.vars, + vars.remind = c( + "ue_steel_primary", + "ue_steel_secondary", + "ue_cement" + ) + ) ariadne.ind.demand <- collapseNames(ariadne.ind.demand) + ariadne.ind.demand <- toolAggregate( + x = ariadne.ind.demand, + rel = mapping.scens, + dim = 3.1 + ) - ariadne.ind.demand <- toolAggregate(x = ariadne.ind.demand, - rel = mapping.scens, - dim=3.1) + ariadne.ind.demand <- toolAggregate( + x = ariadne.ind.demand, + rel = mapping.vars, + dim = 3.2 + ) - ariadne.ind.demand <- toolAggregate(x = ariadne.ind.demand, - rel = mapping.vars, - dim=3.2) + # rearrange to output format + years <- c( + 2005, 2010, 2015, 2020, 2025, 2030, 2035, 2040, 2045, + 2050, 2055, 2060, 2070, 2080, 2090, 2100 + ) - # rearrange to ouptut format - years <- c(2005, 2010, 2015, 2020, 2025, 2030, 2035, 2040, 2045, 2050, 2055, 2060, 2070, 2080, 2090, 2100) - out <- new.magpie(getRegions(AriadneDB.data), - years = years, - names = getNames(ariadne.ind.demand), - fill = 0) + out <- new.magpie( + cells_and_regions = magclass::getItems(data, dim = 1), + years = years, + names = magclass::getNames(ariadne.ind.demand), + fill = 0 + ) - # take data from ariadne DB only between 2025 and 2050 - ariadne.period <- seq(2025,2050,5) - out["DEU",paste0("y",ariadne.period),] <- ariadne.ind.demand["DEU",paste0("y",ariadne.period),] + # take data from Ariadne DB only between 2025 and 2050 + ariadne.period <- seq(2025, 2050, 5) + out["DEU", paste0("y", ariadne.period), ] <- ariadne.ind.demand["DEU", paste0("y", ariadne.period), ] - # constant production after 2050 - # out["DEU",paste0("y",c(2055, 2060, 2070, 2080, 2090, 2100)),] <- out["DEU","y2050",] + # FORECAST only provides data until 2050. After 2050, assume linear decline until 2080 to + # levels in line with REMIND runs with endogenous production". - ### end Ariadne trajectories + out["DEU", 2080, "ue_steel_primary"] <- 10 * 1e-3 + out["DEU", 2080, "ue_steel_secondary"] <- 20 * 1e-3 + out["DEU", 2080, "ue_cement"] <- 20 * 1e-3 - x <- out + out["DEU", c(2050, 2055, 2060, 2070, 2080), ] <- madrat::toolFillYears( + out["DEU", c(2050, 2080), ], c(2050, 2055, 2060, 2070, 2080) + ) return(list( - x = x, + x = out, weight = NULL, unit = c("Gt steel/yr for ue_steel_primary and ue_steel_secondary, Gt cement/yr for ue_cement"), description = "Exogenous demand scenarios that REMIND can be fixed to using cm_exogDem_scen" )) - } diff --git a/R/calcExpertGuess.R b/R/calcExpertGuess.R new file mode 100644 index 00000000..2571e45f --- /dev/null +++ b/R/calcExpertGuess.R @@ -0,0 +1,32 @@ +#' Calculate expert guesses +#' +#' @author Falk Benke +#' +#' @param subtype must be 'tradeConstraints' (more to come) +#' @export +calcExpertGuess <- function(subtype) { + if (subtype != "tradeConstraints") { + stop("Invalid subtype. Supported subtypes: 'tradeConstraints'") + } + + x <- readSource("ExpertGuess", subtype = subtype, convert = FALSE) + + if (subtype == "tradeConstraints") { + unit <- "unitless" + description <- c( + "parameter by Nicolas Bauer (2024) for the region specific ", + "trade constraints, values different to 1 activate constraints ", + "and the value is used as effectiveness to varying degrees ", + "such as percentage numbers" + ) + isocountries <- FALSE + } + + return(list( + x = x, + weight = NULL, + unit = unit, + description = description, + isocountries = isocountries + )) +} diff --git a/R/calcFE.R b/R/calcFE.R index bfdf04c8..4860068c 100644 --- a/R/calcFE.R +++ b/R/calcFE.R @@ -1,7 +1,6 @@ #' Calculates FE historical from IEA energy balances, projections from EDGE, and historical #' values from IEA WEO 2019 #' @author Lavinia Baumstark, Aman Malik -#' @importFrom dplyr %>% #' @importFrom quitte inline.data.frame #' @importFrom stats na.omit #' @param source "IEA" or "IEA_WEO" @@ -27,7 +26,7 @@ calcFE <- function(source = "IEA", scenario_proj = "SSP2", ieaVersion = "default colnames(map) <- gsub("io", "names_in", colnames(map)) # Give description - ieaYear <- if (ieaVersion == "default") 2022 else 2023 + ieaYear <- if (ieaVersion == "default") 2022 else 2024 descript <- paste0("IEA Final Energy Data based on ", ieaYear, " version of IEA Energy Balances") #------ PROCESS DATA ------------------------------------------ diff --git a/R/calcFGas.R b/R/calcFGas.R index a3a6c018..757478b9 100644 --- a/R/calcFGas.R +++ b/R/calcFGas.R @@ -10,7 +10,6 @@ #' \dontrun{ #' x <- calcOutput("FGas") #' } -#' @importFrom magclass getNames<- getSets clean_magpie calcFGas <- function(subtype = "interpolate2025") { # read in IMAGE data diff --git a/R/calcFeDemandIndustry.R b/R/calcFeDemandIndustry.R index ff628c98..cd50e1b1 100644 --- a/R/calcFeDemandIndustry.R +++ b/R/calcFeDemandIndustry.R @@ -7,9 +7,6 @@ #' @importFrom dplyr anti_join arrange as_tibble between bind_rows case_when #' distinct filter first full_join group_by inner_join lag last left_join #' matches mutate n rename right_join select semi_join summarise ungroup -#' @importFrom magclass mselect getItems getItems<- time_interpolate -#' @importFrom madrat toolAggregate -#' @importFrom magrittr %>% %<>% #' @importFrom quitte as.quitte cartesian character.data.frame #' interpolate_missing_periods interpolate_missing_periods_ madrat_mule #' magclass_to_tibble overwrite seq_range @@ -419,7 +416,10 @@ calcFeDemandIndustry <- function(use_ODYM_RECC = FALSE) { convert = FALSE) %>% madrat_mule(), aggregate = FALSE, - years = getYears(remind), supplementary = FALSE), + years = getYears(remind), + supplementary = FALSE, + warnNA = FALSE + ), calcOutput( type = "Steel_Projections", @@ -588,7 +588,7 @@ calcFeDemandIndustry <- function(use_ODYM_RECC = FALSE) { mutate(subsector = paste0("ue_", .data$subsector)) if (use_ODYM_RECC) { - industry_subsectors_material_relative %<>% + industry_subsectors_material_relative <- industry_subsectors_material_relative %>% filter(!.data$scenario %in% c("gdp_SDP_EI", "gdp_SDP_MC", "gdp_SDP_RC")) } @@ -950,53 +950,8 @@ calcFeDemandIndustry <- function(use_ODYM_RECC = FALSE) { industry_subsectors_en <- industry_subsectors_en %>% mutate(pf = sub("^feelwlth_", "feel_", .data$pf)) - ### extend to 2020 using WEO 2021 data ---- - IEA_WEO_2021_ref_year <- 2020L - last_industry_subsectors_en_year <- max(industry_subsectors_en$year) - if (IEA_WEO_2021_ref_year > last_industry_subsectors_en_year) { - industry_subsectors_en <- bind_rows( - industry_subsectors_en, - - inner_join( - industry_subsectors_en %>% - filter(2010 == .data$year), - - readSource(type = "IEA_WEO_2021", subtype = "region", - convert = TRUE) %>% - magclass_to_tibble(c("iso3c", "year", "scenario", "variable", "industry.FE")) %>% - filter(.data$year %in% c(2010, IEA_WEO_2021_ref_year), - "Stated Policies Scenario" == .data$scenario, - "Energy-Total-Industry (EJ)" == .data$variable) %>% - left_join(region_mapping_21, "iso3c") %>% - group_by(!!!syms(c("region", "year"))) %>% - summarise(industry.FE = sum(.data$industry.FE, na.rm = TRUE), - .groups = "drop_last") %>% - summarise(change = last(.data$industry.FE, order_by = .data$year) - / first(.data$industry.FE, order_by = .data$year), - .groups = "drop"), - - "region" - ) %>% - mutate(value = .data$value * .data$change, - year = IEA_WEO_2021_ref_year) %>% - select(-"change") - ) %>% - pivot_wider(names_from = "year") %>% - mutate(`2015` = (!!sym("2010") - + !!sym("2015") - + !!sym(as.character(IEA_WEO_2021_ref_year)) - ) - / 3) %>% - pivot_longer(matches("^[0-9]*$"), names_to = "year", - names_transform = list(year = as.integer)) %>% - interpolate_missing_periods_(periods = list(year = seq_range(range(.$year)))) %>% - assert(not_na, everything()) %>% - verify(is.finite(.data$value)) - FE_alpha_mod <- 0.9 # found by fiddling around - } else { - FE_alpha_mod <- 1 - } + FE_alpha_mod <- 1 ### calculate 1993-2020 industry subsector FE shares ---- industry_subsectors_en_shares <- industry_subsectors_en %>% @@ -1070,21 +1025,33 @@ calcFeDemandIndustry <- function(use_ODYM_RECC = FALSE) { "variable" ) %>% - # drop 2055/OECD/Chemicals as the data is faulty - filter(!("OECD" == .data$region & - 2055 == .data$year & - "chemicals" == .data$subsector)) %>% + # drop faulty data + # - 2055/OECD/Chemicals (all zero) + anti_join( + tribble( + ~region, ~year, ~subsector, + 'OECD', 2055, 'chemicals'), + c('region', 'year', 'subsector')) %>% + # - 2055/Non-OECD/Chemicals/Oil (exceeds total Oil) + anti_join( + tribble( + ~region, ~year, ~subsector, ~fety, + 'Non-OECD', 2055, 'chemicals', 'feli'), + c('region', 'year', 'subsector', 'fety')) %>% # aggregate by subsector and fety group_by(!!!syms(c("region", "year", "subsector", "fety"))) %>% summarise(value = sum(.data$value), .groups = "drop") %>% - # fill 2055/OECD/Chemicals gap with interpolated data - complete(nesting(!!!syms(c("region", "subsector", "fety"))), year = unique(.data$year)) %>% + # fill gaps (e.g. 2055/Chemicals) with interpolated data + complete(nesting(!!!syms(c("region", "subsector", "fety"))), + year = unique(.data$year)) %>% interpolate_missing_periods_(periods = list(year = unique(.$year))) %>% # calculate otherInd as total - cement - chemicals - steel pivot_wider(names_from = "subsector", values_fill = 0) %>% - mutate(otherInd = .data$total - (.data$cement + .data$chemicals + .data$steel)) %>% + mutate(otherInd = .data$total + - (.data$cement + .data$chemicals + .data$steel)) %>% select(-"total") %>% - pivot_longer(c("cement", "chemicals", "steel", "otherInd"), names_to = "subsector") %>% + pivot_longer(c("cement", "chemicals", "steel", "otherInd"), + names_to = "subsector") %>% filter(0 != .data$value) %>% # calculate share group_by(!!!syms(c("region", "year", "subsector"))) %>% diff --git a/R/calcFloorspace.R b/R/calcFloorspace.R index be6573ca..307b01e4 100644 --- a/R/calcFloorspace.R +++ b/R/calcFloorspace.R @@ -7,8 +7,6 @@ #' @param onlyTotal boolean, only give total instead of sub-sectoral floor space #' @return MAgPIE object with buildings floor space #' -#' @importFrom madrat readSource -#' @importFrom magclass collapseNames #' @export #' calcFloorspace <- function(onlyTotal = FALSE) { diff --git a/R/calcFossilExtraction.R b/R/calcFossilExtraction.R index 70d65e09..66b24b96 100644 --- a/R/calcFossilExtraction.R +++ b/R/calcFossilExtraction.R @@ -5,36 +5,29 @@ #' @param subtype Either 'FossilExtraction' or 'UraniumExtraction' #' @seealso \code{\link{calcOutput}} #' @examples -#' -#' \dontrun{ -#' calcOutput(type="FossilExtraction",subtype='FossilExtraction') +#' \dontrun{ +#' calcOutput(type = "FossilExtraction", subtype = "FossilExtraction") #' } -#' @importFrom dplyr %>% mutate select rename arrange +#' @importFrom dplyr mutate select rename arrange #' @importFrom stats lm coef -calcFossilExtraction <- function(subtype="FossilExtraction"){ - - if (!((subtype=="FossilExtraction") || (subtype=="UraniumExtraction"))){ +calcFossilExtraction <- function(subtype = "FossilExtraction") { + if (!((subtype == "FossilExtraction") || (subtype == "UraniumExtraction"))) { stop("Not a valid subtype!") } - - #setting the weight to the country reserves potential (same weight used on the convertREMIND_11Regi, fossilExtractionCoeff and uraniumExtractionCoeff subtypes) + + # setting the weight to the country reserves potential (same weight used on the convertREMIND_11Regi, fossilExtractionCoeff and uraniumExtractionCoeff subtypes) if (subtype == "FossilExtraction") { - description <- "Coefficients for the 3rd-order polynomial Oil, Gas and Coal extraction costs." - #loading coefficients data at country level - output <- readSource("REMIND_11Regi", subtype="fossilExtractionCoeff") + # loading coefficients data at country level + output <- readSource("REMIND_11Regi", subtype = "fossilExtractionCoeff") # upper bound - upperBoundMaxExtraction <- readSource("REMIND_11Regi", subtype = "ffPolyCumEx")[,,"max"] - # high cost curve -> empty list :the aggregation function will choose the coefficients even for regions with no extraction potential - highCostCurve = list() - - - + upperBoundMaxExtraction <- readSource("REMIND_11Regi", subtype = "ffPolyCumEx")[, , "max"] + # high cost curve -> empty list :the aggregation function will choose the coefficients even for regions with no extraction potential + highCostCurve <- list() # FS: add specific Austrlian gas extraction cost curve based on Dylan McConnell/GSOO data AusRawData <- readSource("DylanAusGasCost") - #AusRawData <- x_help s_GJ_2_twa <- 31.71e-12 @@ -44,24 +37,24 @@ calcFossilExtraction <- function(subtype="FossilExtraction"){ Price <- NULL CumRes <- NULL - RegrData <- as.data.frame(AusRawData["AUS",,]) %>% - select(Data2, Value) %>% - rename( Res = Data2, Price = Value) %>% - mutate( Price = as.numeric(Price), Res = as.numeric(as.character(Res))) + RegrData <- as.data.frame(AusRawData["AUS", , ]) %>% + select(Data2, Value) %>% + rename(Res = Data2, Price = Value) %>% + mutate(Price = as.numeric(Price), Res = as.numeric(as.character(Res))) RegrData <- RegrData %>% - # remove depleted sites (zero resources) %>% - filter( Res > 0) %>% - # add extraction between 2005 and 2015 - # DIIS data: 2005-2015 natural gas production: 23EJ - # assume that 23 EJ were extracted at 1.5AUSD/GJ -> 0.9 USD - # (1.58 is lowest price in gas extraction data after 2015) -> 0.9 USD - rbind(data.frame(Res=23000, Price = 0.9)) %>% - # convert from PJ to TWa - mutate(Res = Res * 1e-15 / s_GJ_2_twa) %>% - # convert from 2005USD/GJ to tr 2005USD/Twa - mutate(Price = Price / s_GJ_2_twa / 1e12 ) %>% - arrange(Price) + # remove depleted sites (zero resources) %>% + filter(Res > 0) %>% + # add extraction between 2005 and 2015 + # DIIS data: 2005-2015 natural gas production: 23EJ + # assume that 23 EJ were extracted at 1.5AUSD/GJ -> 0.9 USD + # (1.58 is lowest price in gas extraction data after 2015) -> 0.9 USD + rbind(data.frame(Res = 23000, Price = 0.9)) %>% + # convert from PJ to TWa + mutate(Res = Res * 1e-15 / s_GJ_2_twa) %>% + # convert from 2005USD/GJ to tr 2005USD/Twa + mutate(Price = Price / s_GJ_2_twa / 1e12) %>% + arrange(Price) RegrData$CumRes <- cumsum(RegrData$Res) @@ -70,53 +63,50 @@ calcFossilExtraction <- function(subtype="FossilExtraction"){ RegrData <- RegrData %>% # remove data points above 6 TWa Cumulative Extraaction, because then Extraction cost constant and would only be outliers to fit, # assume that we do not reach with extraction there anyways - filter( CumRes < 6) + filter(CumRes < 6) # linear fit to extraction cost data - linfit <- lm(Price ~ poly(CumRes,1, raw = T), data = RegrData) + linfit <- lm(Price ~ poly(CumRes, 1, raw = TRUE), data = RegrData) # subsitute Australia gas extraction polcy coef for medium Scenario with linear fit to Dylan's data - output["AUS",,"medGas.0"] <- coef(linfit)[1] - output["AUS",,"medGas.1"] <- coef(linfit)[2] - output["AUS",,"medGas.2"] <- 0 - output["AUS",,"medGas.3"] <- 0 - + output["AUS", , "medGas.0"] <- coef(linfit)[1] + output["AUS", , "medGas.1"] <- coef(linfit)[2] + output["AUS", , "medGas.2"] <- 0 + output["AUS", , "medGas.3"] <- 0 + # SB & NB edit 2019/09/11: # Shift SSP5 coal extraction cost curve down by 33% based on calibration with the SSP IAM project 2017 - output[,,c("highCoal.0","highCoal.1")] <- output[,,c("highCoal.0","highCoal.1")]*(1 - 0.33) + output[, , c("highCoal.0", "highCoal.1")] <- output[, , c("highCoal.0", "highCoal.1")] * (1 - 0.33) # Shift SSP5 oil extraction cost curve for USA and CAZ down by 20% based on calibration with the SSP IAM project 2017 - output[c("USA","CAN","AUS","NZL","HMD","SPM"),,c("highOil.0","highOil.1")] <- - output[c("USA","CAN","AUS","NZL","HMD","SPM"),,c("highOil.0","highOil.1")] * (1 - 0.2) - - #SB & NB edit 2019/11/14: + output[c("USA", "CAN", "AUS", "NZL", "HMD", "SPM"), , c("highOil.0", "highOil.1")] <- + output[c("USA", "CAN", "AUS", "NZL", "HMD", "SPM"), , c("highOil.0", "highOil.1")] * (1 - 0.2) + + # SB & NB edit 2019/11/14: # Reduce SSP5 coal extraction costs for USA and CAZ by 25% - output[c("USA","CAN","AUS","NZL","HMD","SPM"),,"highCoal.0"] <- output[c("USA","CAN","AUS","NZL","HMD","SPM"),,"highCoal.0"] * (1 - 0.25) + output[c("USA", "CAN", "AUS", "NZL", "HMD", "SPM"), , "highCoal.0"] <- output[c("USA", "CAN", "AUS", "NZL", "HMD", "SPM"), , "highCoal.0"] * (1 - 0.25) # Reduce SSP5 gas extraction costs for all regions by 10% - output[,,"highGas.0"] <- output[,,"highGas.0"] * (1 - 0.1) - - } else if (subtype == "UraniumExtraction"){ - + output[, , "highGas.0"] <- output[, , "highGas.0"] * (1 - 0.1) + } else if (subtype == "UraniumExtraction") { description <- "Coefficients for the 3rd-order polynomial Uranium extraction costs." - #loading coefficients data at country level - data <- readSource("REMIND_11Regi", subtype="uraniumExtractionCoeff") + # loading coefficients data at country level + data <- readSource("REMIND_11Regi", subtype = "uraniumExtractionCoeff") # maxExtraction (upper limit for function estimation) - BGRuranium <- readSource("BGR", subtype="uranium")[,,"Remaining_Potential"] # Remaining extraction potential per country - BGRuranium <- toolCountryFill(BGRuranium,fill=0) + BGRuranium <- readSource("BGR", subtype = "uranium")[, , "Remaining_Potential"] # Remaining extraction potential per country + BGRuranium <- toolCountryFill(BGRuranium, fill = 0, verbosity = 2) totalBGRuranium <- as.numeric(colSums(BGRuranium)) - upperBoundMaxExtraction <- 23* ( BGRuranium/totalBGRuranium ) # 23 -> from s31_max_disp_peur -> max global "maximum amount of cumulative uranium production in Megatonnes of metal uranium (U3O8, the stuff that is traded at 40-60US$/lb)." + upperBoundMaxExtraction <- 23 * (BGRuranium / totalBGRuranium) # 23 -> from s31_max_disp_peur -> max global "maximum amount of cumulative uranium production in Megatonnes of metal uranium (U3O8, the stuff that is traded at 40-60US$/lb)." upperBoundMaxExtraction <- add_dimension(upperBoundMaxExtraction, dim = 3.1, add = "pe", nm = "peur") upperBoundMaxExtraction <- upperBoundMaxExtraction * 1.5 # adding a 50% more to the maximum extraction because the countries shares do not take into consideration the different marginal costs of each country output <- data - #set high cost curve if all countries within a region have zero extraction capacity + # set high cost curve if all countries within a region have zero extraction capacity highCostCurve <- list("xi1" = 0.025, "xi2" = 1000, "xi3" = 0, "xi4" = 0) - } - - return(list(x=output, weight=NULL, - unit="tr USD2005/TWa", - description=description, - aggregationFunction=toolCubicFunctionAggregate, - aggregationArguments=list(xUpperBound=upperBoundMaxExtraction,steepCurve = highCostCurve) + + return(list( + x = output, weight = NULL, + unit = "tr USD2005/TWa", + description = description, + aggregationFunction = toolCubicFunctionAggregate, + aggregationArguments = list(xUpperBound = upperBoundMaxExtraction, steepCurve = highCostCurve) )) - } diff --git a/R/calcFossilPolyCumEx.R b/R/calcFossilPolyCumEx.R index 5cd6bc85..58ad8d89 100644 --- a/R/calcFossilPolyCumEx.R +++ b/R/calcFossilPolyCumEx.R @@ -1,12 +1,10 @@ - - -calcFossilPolyCumEx <- function(){ - +calcFossilPolyCumEx <- function() { x <- readSource("REMIND_11Regi", subtype = "ffPolyCumEx") - return(list(x = x, - weight = NULL, - unit = "none", - description = "vintages, installed capacities")) + return(list( + x = x, + weight = NULL, + unit = "none", + description = "vintages, installed capacities" + )) } - diff --git a/R/calcFossilPolyRent.R b/R/calcFossilPolyRent.R index 71f54695..298e199e 100644 --- a/R/calcFossilPolyRent.R +++ b/R/calcFossilPolyRent.R @@ -1,27 +1,25 @@ - - -calcFossilPolyRent <- function(){ - +calcFossilPolyRent <- function() { x <- readSource("REMIND_11Regi", subtype = "ffPolyRent") # use pe as weigth for aggregation - w <- new.magpie(getRegions(x),getYears(x),getNames(x)) - oil <- readSource("BGR", subtype="oil")[,,"Remaining_Potential"] - getNames(oil) <- "peoil" - gas <- readSource("BGR", subtype="gas")[,,"Remaining_Potential"] - getNames(gas) <- "pegas" - coal <- readSource("BGR", subtype="coal")[,,"Remaining_Potential"] + w <- new.magpie(getRegions(x), getYears(x), getNames(x)) + oil <- readSource("BGR", subtype = "oil")[, , "Remaining_Potential"] + getNames(oil) <- "peoil" + gas <- readSource("BGR", subtype = "gas")[, , "Remaining_Potential"] + getNames(gas) <- "pegas" + coal <- readSource("BGR", subtype = "coal")[, , "Remaining_Potential"] getNames(coal) <- "pecoal" # put the data for all fossils together - bgr <- mbind(oil,coal,gas) + bgr <- mbind(oil, coal, gas) bgr[is.na(bgr)] <- 0 - for(s in getNames(x,dim=1)) { - w[,,s] <- bgr[,,s] + for (s in getNames(x, dim = 1)) { + w[, , s] <- bgr[, , s] } - - return(list(x = x, - weight = w, - unit = "none", - description = "vintages, installed capacities")) + + return(list( + x = x, + weight = w, + unit = "none", + description = "vintages, installed capacities" + )) } - diff --git a/R/calcGAINS.R b/R/calcGAINS.R index c6ab1bca..3cc506df 100644 --- a/R/calcGAINS.R +++ b/R/calcGAINS.R @@ -8,14 +8,9 @@ #' #' @param subtype decides whether emissions or emission factors are returned #' @param sectoral_resolution aggreaged or extenden (uses different GAINS input data) -#' @importFrom dplyr group_by_ summarise_ ungroup mutate_ rename_ filter_ select_ -#' @importFrom magclass as.magpie getCells getSets<- getNames<- getSets getRegions<- mselect<- setNames write.magpie -#' @importFrom tidyr gather_ +#' @importFrom dplyr ungroup #' @importFrom utils read.csv read.csv2 #' @importFrom quitte as.quitte - - - calcGAINS <- function(subtype = "emission_factors", sectoral_resolution = "extended") { if (!(subtype %in% c("emission_factors", "emissions"))) stop('subtype must be in c("emission_factors", "emissions")') @@ -26,16 +21,14 @@ calcGAINS <- function(subtype = "emission_factors", sectoral_resolution = "exten allocate_c2r_ef <- function(id_ef, ip_region, ip_country, ip_year, ip_scenario) { dummy <- id_ef[ip_region, ip_year, ip_scenario] dummy[, , ] <- setCells(id_ef[ip_country, ip_year, ip_scenario], "GLO") - # names(dimnames(dummy)) <- c("region", "years", "data1.data2.species.scenario") return(dummy) } - # allocate_min2r_ef <- function(id_ef, ip_region, ip_countryGroup, ip_year, ip_scenario) { dummy <- id_ef[ip_region, ip_year, ip_scenario] # Get minimum values across country group tmp <- as.quitte(id_ef[ip_countryGroup, ip_year, ip_scenario]) %>% - group_by(!!!syms(c('data1', 'data2'))) %>% + group_by(!!!syms(c("data1", "data2"))) %>% summarise(value = ifelse(all(.data$value == 0), 0, min(.data$value[.data$value > 0], na.rm = TRUE)) ) %>% # a value 0 is often a sign for a NA that has been replaced with 0 for small countries @@ -47,12 +40,9 @@ calcGAINS <- function(subtype = "emission_factors", sectoral_resolution = "exten dummy[ip_region, ip_year, ip_scenario] <- setYears(tmp) return(dummy) } - # DK: deleted unused function # conversion factors - conv_ktSO2_to_ktS <- 1 / 2 # 32/(32+2*16) conv_kt_per_PJ_to_Tg_per_TWa <- 1e-3 / (1e15 / (365 * 24 * 60 * 60) * 1e-12) - conv_PJ_to_Twa <- (1e15 / (365 * 24 * 60 * 60) * 1e-12) # user-defined parameters time <- c(seq(2005, 2055, 5), seq(2060, 2110, 10), 2130, 2150) @@ -65,7 +55,6 @@ calcGAINS <- function(subtype = "emission_factors", sectoral_resolution = "exten p_countryCategories <- "useGAINSregions" # "perCountry" # list of OECD countries - # TODO: may want to place this in a mapping file or in a R library r_oecd <- c("AUS", "AUT", "BEL", "CAN", "CHL", "CZE", "DNK", "EST", "FIN", "FRA", "DEU", "GRC", "HUN", "ISL", "IRL", "ISR", "ITA", "JPN", "KOR", "LUX", "MEX", "NLD", "NZL", "NOR", "POL", "PRT", "SVK", "SVN", "ESP", "SWE", "CHE", "TUR", "GBR", "USA") @@ -89,19 +78,8 @@ calcGAINS <- function(subtype = "emission_factors", sectoral_resolution = "exten emissions <- readSource("ECLIPSE", subtype = paste0("emissions.", sectoral_resolution)) emissions <- emissions[, c(2005, 2010, 2020, 2030, 2050), ] - # read in sectoral mapping (ECLIPSE (IMAGE) <> REMIND) - # DK map_sectors_ECLIPSE2Agg <- read.csv(toolGetMapping(type = "sectoral", - # name = "mappingECLIPSEtoAggREMINDsectors.csv", - # returnPathOnly = TRUE, where = "mappingfolder"), - # stringsAsFactors=TRUE) - # DK map_sectors_Agg2REMIND <- read.csv(toolGetMapping(type = "sectoral", - # name = "mappingAggREMINDtoREMINDsectors.csv" - # returnPathOnly = TRUE), - # stringsAsFactors=TRUE) - # map_sectors <- map_sectors[which(!is.na(map_sectors$EDGE)),] # Remove transport sector (which is not represented in EDGE) - # read in regional map (select ISO and GAINS codes only). This is required for the construction of the SSPs - map_regions <- read.csv2(toolGetMapping(type = "regional", name = "regionmappingGAINS.csv", + map_regions <- read.csv2(toolGetMapping(type = "regional", name = "regionmappingGAINS.csv", returnPathOnly = TRUE, where = "mappingfolder"), stringsAsFactors = TRUE)[, c(2, 3)] map_regions <- map_regions %>% @@ -116,9 +94,6 @@ calcGAINS <- function(subtype = "emission_factors", sectoral_resolution = "exten pop <- calcOutput("Population", aggregate = FALSE)[, p_dagg_year, p_dagg_pop] gdp <- calcOutput("GDP", aggregate = FALSE)[, p_dagg_year, p_dagg_gdp] - # co <- map_regions$CountryCode[map_regions$RegionCode %in% c("Northern Africa","Middle East","Asia-Stan","Russia+")] - # e <- dimSums(emissions["IRN",,"End_Use_Industry_Coal.VOC"],dim=1) - # a <- dimSums(activities["IRN",,"End_Use_Industry_Coal"],dim=1) #-- PROCESS DATA ------------------ # set of sectors for which emission factors are computed @@ -133,12 +108,6 @@ calcGAINS <- function(subtype = "emission_factors", sectoral_resolution = "exten select_weu <- paste(map_regions[which(map_regions$RegionCode == "Western Europe")[1], 1]) # Retrieve Transport names - # transportNames <- getNames(activities)[grepl("End_Use_Transport", getNames(activities))] - - # buildingNames <- getNames(activities)[grepl("End_Use_Industry|End_Use_Residential|End_Use_Services", getNames(activities))] - - # convert SO2 emission from TgSO2 to TgS - # emissions[,,"SO2"] <- emissions[,,"SO2"]*conv_ktSO2_to_ktS # define missing SLE scenario (assumed to be 3/4 of the distance between CLE and MFR, according to discussion with Zig Klimont on 18th Feb 2016) cle <- emissions[, , "CLE"] @@ -164,86 +133,63 @@ calcGAINS <- function(subtype = "emission_factors", sectoral_resolution = "exten # ISO countries belonging to this GAINS region => ef will be NA for those sectors and countries. Set those NAs to zero. When ef is reaggregated # to REMIND regions this is done using the activites as weight. And the activity is zero for the countries and sectors that have zeros due to zero # activity and thus have no effect on the result. - # # some regions/countries have NA values everywhere (pop data is zero). Allocate EF of another country that belongs to the same GAINS region (except for Antartica) # Find countries that have NA for all sectors and species (then probably due to missing population data, see above) ef_eclipse["ATA", , ] <- 0 # Antartica -> 0 NAregions <- c("AIA", "ALA", "ATF", "BES", "BLM", "BVT", "CCK", "COK", "CXR", "ESH", "FLK", "GGY", "GIB", "GLP", "GUF", "HMD", "IOT", "JEY", "MSR", "MTQ", "MYT", "NFK", "NIU", "NRU", "PCN", "REU", "SGS", "SHN", "SJM", "SPM", "TKL", "TWN", "UMI", "VAT", "VGB", "WLF") - # NAregions <- names(which( - # sapply( - # getRegions( which(is.na(ef_eclipse), arr.ind = TRUE)), function(k) all(is.na(as.numeric(ef_eclipse[k,,]))) - # ) - # ) - # ) - - # NAregions <- c("AIA", "ATF", "BVT", "CCK", "COK", "CXR", "ESH", "FLK", "GIB", "GLP", "GUF", - # "HMD", "IOT", "MSR", "MTQ", "MYT", "NFK", "NIU", "NRU", "PCN", - # "REU", "SGS", "SHN", "SJM", "SPM", "TKL", "TWN", "UMI", "VAT", "VGB", "WLF") MissingRegions <- c("ALA", "BES", "BLM", "CUW", "GGY", "IMN", "JEY", "MAF", "PSE", "SSD", "SXM") - # AssociatedGAINSregions <- c("Western Europe", "Rest Central America", "Rest Central America", "Rest Central America", "Western Europe", "Western Europe", "Western Europe", - # "Rest Central America", "Middle East", "Northern Africa", "Rest Central America") - # for countries that have NAs everywhere (missing population, see reason 1 above) replace NA with ef of country that belongs to same GAINS region - cat("ef_eclipse: NA values in first country replaced with ef of second country:\n") for (kregi in NAregions) { # suche die countrycodes aller countries, die zu der region gehören, zu der auch kregi gehört, lasse die Regionen aus NAregions und missingRegions weg # take the value of the first country since all countries that belong to the same GAINS region have the same ef subsitute_region <- map_regions$CountryCode[map_regions$RegionCode == map_regions$RegionCode[map_regions$CountryCode == kregi] & !map_regions$CountryCode %in% c(NAregions, MissingRegions)][1] - cat(kregi, as.character(subsitute_region), "\n") - # subsitute_region<-subsitute_region[-which(as.character(subsitute_region)=="ANT")] # remove ANT - - # if (all(is.na(ef_eclipse[subsitute_region,,]))) { - # # NAs in all countries - # } elese { } tmp <- ef_eclipse[subsitute_region, , ] - getRegions(tmp) <- kregi + getItems(tmp, dim = 1) <- kregi ef_eclipse[kregi, , ] <- tmp } - # some regions have no population data when disaggregating. - # DK: I think this case was already addressed above (country has NAs everywhere) - # for (kregi in MissingRegions) { - # # warum hier so kompliziert mit AssociatedGAINSregions und nicht automatisch wie oben? - # # es gibt einen Unterschied: oben würde SSD Western Africa zugeordnet, hier wird es Northern Africa zugeordnet - # substitute_region = map_regions$CountryCode[map_regions$RegionCode == AssociatedGAINSregions[which(MissingRegions == kregi)] & - # !map_regions$CountryCode %in% MissingRegions][1] - # tmp <- ef_eclipse[substitute_region,,] - # getRegions(tmp) <- kregi - # ef_eclipse[kregi,,] <- tmp - # } # for the remaining NAs (0/0 = NaN) and Infs (1/0 = Inf ) just set EF to 0 (activity levels are 0, although in some cases emissions exist) ef_eclipse[is.na(ef_eclipse)] <- 0 ef_eclipse[is.infinite(ef_eclipse)] <- 0 - rm(NAregions, MissingRegions) # , AssociatedGAINSregions) - - # DK: deleted outcommented code - # Check ef corresponds to initial data + rm(NAregions, MissingRegions) # define exogenous emission data - emissions_exogenous <- emissions # [,,dimSector_skipEF] + emissions_exogenous <- emissions # make output dummy "ef" and "emi" which then has to be filled by the data - ef <- do.call("mbind", - lapply(scenario, - function(s) { -new.magpie(getRegions(ef_eclipse), - c(2005, 2010, 2030, 2050, 2100), - gsub("CLE", s, getNames(ef_eclipse[, , "CLE"]))) - })) - - emi <- do.call("mbind", - lapply(scenario, - function(s) { -new.magpie(getRegions(emissions_exogenous), - c(2005, 2010, 2030, 2050, 2100), - gsub("CLE", s, getNames(emissions_exogenous[, , "CLE"]))) - })) + ef <- do.call( + "mbind", + lapply( + scenario, + function(s) { + new.magpie( + getRegions(ef_eclipse), + c(2005, 2010, 2030, 2050, 2100), + gsub("CLE", s, getNames(ef_eclipse[, , "CLE"])) + ) + } + ) + ) + + emi <- do.call( + "mbind", + lapply( + scenario, + function(s) { + new.magpie( + getRegions(emissions_exogenous), + c(2005, 2010, 2030, 2050, 2100), + gsub("CLE", s, getNames(emissions_exogenous[, , "CLE"])) + ) + } + ) + ) # define country categories if (p_countryCategories == "perCountry") { @@ -258,8 +204,8 @@ new.magpie(getRegions(emissions_exogenous), } else if (p_countryCategories == "useGAINSregions") { # Compute mean GDP/Cap per GAINS region regionMean_gdppcap <- sapply(unique(map_regions$RegionCode), function(x) { -mean(gdp_cap[map_regions$CountryCode[map_regions$RegionCode == x], , ]) -}) + mean(gdp_cap[map_regions$CountryCode[map_regions$RegionCode == x], , ]) + }) # low income countries (using World Bank definition < 2750 US$(2010)/Cap) r_L <- levels(map_regions$CountryCode[map_regions$RegionCode %in% names(regionMean_gdppcap[regionMean_gdppcap <= 2750])]) @@ -358,8 +304,6 @@ mean(gdp_cap[map_regions$CountryCode[map_regions$RegionCode == x], , ]) ef[, , "SSP5"] <- ef[, , "SSP1"] emi[, , "SSP5"] <- emi[, , "SSP1"] # does not really make sense... - # DK: deleted outcommented code: - # ----------------- CLE and MFR ------------------------------- ef[, c(2005, 2010, 2030, 2050), c("CLE", "MFR")] <- ef_eclipse[, c(2005, 2010, 2030, 2050), c("CLE", "MFR")] ef[, 2100, c("CLE", "MFR")] <- setYears(ef_eclipse[, 2050, c("CLE", "MFR")]) # for 2100, take the same values as in 2050 @@ -367,9 +311,6 @@ mean(gdp_cap[map_regions$CountryCode[map_regions$RegionCode == x], , ]) emi[, c(2005, 2010, 2030, 2050), c("CLE", "MFR")] <- emissions_exogenous[, c(2005, 2010, 2030, 2050), c("CLE", "MFR")] emi[, 2100, c("CLE", "MFR")] <- setYears(emissions_exogenous[, 2050, c("CLE", "MFR")]) # for 2100, take the same values as in 2050 - # DK: deleted outcommented code: - # DK select the scenario before returning - if (subtype == "emissions") { result <- time_interpolate(emi, interpolated_year = time, integrate_interpolated_years = TRUE, extrapolation_type = "constant") result <- result / 1000 # kt -> Mt @@ -379,12 +320,11 @@ mean(gdp_cap[map_regions$CountryCode[map_regions$RegionCode == x], , ]) common_y <- intersect(getYears(ef), getYears(activities)) result <- time_interpolate(ef[, common_y, ], interpolated_year = time, integrate_interpolated_years = TRUE, extrapolation_type = "constant") getSets(result) <- c("region", "year", "sector", "emi", "scenario") - # - w <- time_interpolate(activities[, common_y, getNames(result, dim = 1)], interpolated_year = time, integrate_interpolated_years = TRUE, extrapolation_type = "constant") + w <- time_interpolate(activities[, common_y, getNames(result, dim = 1)], interpolated_year = time, integrate_interpolated_years = TRUE, extrapolation_type = "constant") getSets(w) <- c("region", "year", "sector") } else { - stop("Unknown subtype ", subtype, "!") -} + stop("Unknown subtype ", subtype, "!") + } return(list(x = result, weight = w, diff --git a/R/calcGAINSEmi.R b/R/calcGAINSEmi.R index acfb2506..6113e901 100644 --- a/R/calcGAINSEmi.R +++ b/R/calcGAINSEmi.R @@ -1,103 +1,91 @@ #' Calculate air pollution emissions and emission factors from GAINS data -#' +#' #' Provides input data for exoGAINSAirpollutants.R -#' -#' +#' +#' #' @return Emissions and emission factors #' @author Sebastian Rauner #' @param subtype "emission_factors", "emissions","emissions_starting_values" #' @seealso \code{\link{calcOutput}} #' @examples -#' -#' \dontrun{ +#' \dontrun{ #' calcOutput("calcGAINSEmi") #' } +calcGAINSEmi <- function(subtype = "emissions") { + if (!(subtype %in% c("emission_factors", "emissions", "emissions_starting_values"))) stop('subtype must be in c("emission_factors", "emissions","emissions_starting_values")') + + if (subtype == "emissions") { + emi_gains_ext_in <- calcOutput("GAINS", subtype = "emissions", sectoral_resolution = "extended", aggregate = FALSE) # in Mt + emi_gains_agg_in <- calcOutput("GAINS", subtype = "emissions", sectoral_resolution = "aggregated", aggregate = FALSE) # in Mt + + + # mainly: combine extended and aggregated GAINS data by appending + # waste sectors from extended to aggregated and then using + # aggregated only + + # construct mappings: add waste from extended mapping to aggregated mapping + map_mix <- toolGetMapping(type = "sectoral", name = "mappingGAINSmixedtoREMIND17activities.csv", + where = "mappingfolder") + map_waste <- map_mix[map_mix$GAINS %in% c("Waste_Solid_Industrial", "Waste_Solid_Municipal", "Waste_Water_Industrial", "Waste_Water_Municipal"), ] + + # append waste ef and emi from extended to aggregated + emi_gains <- mbind(emi_gains_agg_in, emi_gains_ext_in[, , map_waste$GAINS]) + + # many of the 2005 values seem to be outliers + emi_gains[, 2005, ] <- setYears(emi_gains[, 2010, ]) + + x <- emi_gains + unit <- "Mt" + description <- "Emissions from GAINS for all CEDS setors execpt aviation and shipping" + weight <- NULL -calcGAINSEmi <- function(subtype="emissions") { - - if (!(subtype %in% c("emission_factors", "emissions","emissions_starting_values"))) stop('subtype must be in c("emission_factors", "emissions","emissions_starting_values")') - - if(subtype=="emissions") { - emi_gains_ext_in <- calcOutput("GAINS",subtype = "emissions",sectoral_resolution="extended",aggregate=FALSE) # in Mt - emi_gains_agg_in <- calcOutput("GAINS",subtype = "emissions",sectoral_resolution="aggregated",aggregate=FALSE) # in Mt - - - # mainly: combine extended and aggregated GAINS data by appending - # waste sectors from extended to aggregated and then using - # aggregated only - - # construct mappings: add waste from extended mapping to aggregated mapping - map_mix <- toolGetMapping(type = "sectoral", name = "mappingGAINSmixedtoREMIND17activities.csv", - where = "mappingfolder") - map_waste <- map_mix[map_mix$GAINS %in% c("Waste_Solid_Industrial","Waste_Solid_Municipal","Waste_Water_Industrial","Waste_Water_Municipal"),] - - # append waste ef and emi from extended to aggregated - emi_gains <- mbind(emi_gains_agg_in,emi_gains_ext_in[,,map_waste$GAINS]) - - # many of the 2005 values seem to be outliers - warning("GAINS data for 2005 was set to 2010 values (for emi and ef) because 2005 often seems to be an outlier!!!\n") - emi_gains[,2005,] <- setYears(emi_gains[,2010,]) - - x <- emi_gains - unit = 'Mt' - description = 'Emissions from GAINS for all CEDS setors execpt aviation and shipping' - weight = NULL - - } - - if(subtype=="emission_factors") { - ef_gains_ext_in <- calcOutput("GAINS",subtype = "emission_factors",sectoral_resolution="extended",aggregate=FALSE) # in Tg/TWa - ef_gains_agg_in <- calcOutput("GAINS",subtype = "emission_factors",sectoral_resolution="aggregated",aggregate=FALSE) # in Tg/TWa - emi_gains_ext_in <- calcOutput("GAINS",subtype = "emissions",sectoral_resolution="extended",aggregate=FALSE) # in Mt - emi_gains_agg_in <- calcOutput("GAINS",subtype = "emissions",sectoral_resolution="aggregated",aggregate=FALSE) # in Mt - - # mainly: combine extended and aggregated GAINS data by appending - # waste sectors from extended to aggregated and then using - # aggregated only - - # construct mappings: add waste from extended mapping to aggregated mapping - map_mix <- toolGetMapping(type = "sectoral", name = "mappingGAINSmixedtoREMIND17activities.csv", - where = "mappingfolder") - map_waste <- map_mix[map_mix$GAINS %in% c("Waste_Solid_Industrial","Waste_Solid_Municipal","Waste_Water_Industrial","Waste_Water_Municipal"),] - - # append waste ef and emi from extended to aggregated - ef_gains <- mbind(ef_gains_agg_in, ef_gains_ext_in[,,map_waste$GAINS]) - emi_gains <- mbind(emi_gains_agg_in,emi_gains_ext_in[,,map_waste$GAINS]) - - - # many of the 2005 values seem to be outliers - warning("GAINS data for 2005 was set to 2010 values (for emi and ef) because 2005 often seems to be an outlier!!!\n") - ef_gains[,2005,] <- setYears(ef_gains[,2010,]) - emi_gains[,2005,] <- setYears(emi_gains[,2010,]) - - w <- emi_gains - - - x <- ef_gains - unit = 'Mt/TWa' - description = 'Emission factors from GAINS for all CEDS setors execpt aviation and shipping' - weight=w - } - - if(subtype=="emissions_starting_values") { - - - start_value_REMIND_regions <- readSource(type="REMIND_11Regi", subtype="AP_starting_values", convert = TRUE) - + if (subtype == "emission_factors") { + ef_gains_ext_in <- calcOutput("GAINS", subtype = "emission_factors", sectoral_resolution = "extended", aggregate = FALSE) # in Tg/TWa + ef_gains_agg_in <- calcOutput("GAINS", subtype = "emission_factors", sectoral_resolution = "aggregated", aggregate = FALSE) # in Tg/TWa + emi_gains_ext_in <- calcOutput("GAINS", subtype = "emissions", sectoral_resolution = "extended", aggregate = FALSE) # in Mt + emi_gains_agg_in <- calcOutput("GAINS", subtype = "emissions", sectoral_resolution = "aggregated", aggregate = FALSE) # in Mt + + # mainly: combine extended and aggregated GAINS data by appending + # waste sectors from extended to aggregated and then using + # aggregated only + + # construct mappings: add waste from extended mapping to aggregated mapping + map_mix <- toolGetMapping(type = "sectoral", name = "mappingGAINSmixedtoREMIND17activities.csv", + where = "mappingfolder") + map_waste <- map_mix[map_mix$GAINS %in% c("Waste_Solid_Industrial", "Waste_Solid_Municipal", "Waste_Water_Industrial", "Waste_Water_Municipal"), ] + + # append waste ef and emi from extended to aggregated + ef_gains <- mbind(ef_gains_agg_in, ef_gains_ext_in[, , map_waste$GAINS]) + emi_gains <- mbind(emi_gains_agg_in, emi_gains_ext_in[, , map_waste$GAINS]) + + # many of the 2005 values seem to be outliers + ef_gains[, 2005, ] <- setYears(ef_gains[, 2010, ]) + emi_gains[, 2005, ] <- setYears(emi_gains[, 2010, ]) + + w <- emi_gains + x <- ef_gains + unit <- "Mt/TWa" + description <- "Emission factors from GAINS for all CEDS setors execpt aviation and shipping" + weight <- w + } + + if (subtype == "emissions_starting_values") { + + start_value_REMIND_regions <- readSource(type = "REMIND_11Regi", subtype = "AP_starting_values", convert = TRUE) + x <- start_value_REMIND_regions - unit = 'Mt' - description = 'AP starting values for the first iteration of REMIND' - weight = NULL - + unit <- "Mt" + description <- "AP starting values for the first iteration of REMIND" + weight <- NULL + } - - - return(list(x=x, - weight=weight, - unit=unit, - description=description)) - + + return(list(x = x, + weight = weight, + unit = unit, + description = description)) + } diff --git a/R/calcGlobalEnergyMonitor.R b/R/calcGlobalEnergyMonitor.R index 8727e3aa..0ed29433 100644 --- a/R/calcGlobalEnergyMonitor.R +++ b/R/calcGlobalEnergyMonitor.R @@ -1,10 +1,11 @@ -#' Calculate REMIND variables from Global Energy Monitor +#' Calc capacities from Global Energy Monitor +#' +#' Calculate near-term expectations of capacities for use in fullVALIDATION.R #' #' @md #' @return A [`magpie`][magclass::magclass] object. #' #' @author Falk Benke -#' @importFrom magclass add_dimension #' @export calcGlobalEnergyMonitor <- function() { @@ -14,6 +15,10 @@ calcGlobalEnergyMonitor <- function() { # set 0s in other CHA countries than China to approximate CHA as China x[c("HKG", "MAC", "TWN"), , ] <- 0 + # ASSUMPTION: sum over all statuses + # this means that all planned projects will be realized! + x <- dimSums(x, dim = "status") + return(list( x = x, weight = NULL, diff --git a/R/calcGridFactor.R b/R/calcGridFactor.R index a75a0e59..48c7e7a2 100644 --- a/R/calcGridFactor.R +++ b/R/calcGridFactor.R @@ -1,13 +1,16 @@ - calcGridFactor <- function() { - - x <- readSource("REMIND_11Regi",subtype = "gridFactor") + x <- readSource("REMIND_11Regi", subtype = "gridFactor") getNames(x) <- NULL - - w <- dimSums(calcOutput("IO",subtype="output",aggregate=FALSE)[,2005,c("feeli","feelb")],dim=3) - - return(list(x = x, - weight = w, - unit = "factor", - description = "multiplicative factor that scales total grid requirements down in comparatively small or homogeneous regions")) + + w <- dimSums(calcOutput("IO", subtype = "output", aggregate = FALSE)[, 2005, c("feeli", "feelb")], dim = 3) + + return(list( + x = x, + weight = w, + unit = "factor", + description = paste0( + "multiplicative factor that scales total grid requirements ", + "down in comparatively small or homogeneous regions" + ) + )) } diff --git a/R/calcHRE.R b/R/calcHRE.R index 72ecb7da..7ce1647f 100644 --- a/R/calcHRE.R +++ b/R/calcHRE.R @@ -6,8 +6,6 @@ #' @author Pascal Weigmann #' #' @importFrom dplyr select -#' @importFrom madrat toolGetMapping -#' @importFrom magclass as.magpie #' @export calcHRE <- function() { diff --git a/R/calcHistorical.R b/R/calcHistorical.R index ffa6611d..9079409a 100644 --- a/R/calcHistorical.R +++ b/R/calcHistorical.R @@ -1,12 +1,11 @@ #' Gather reference data from various sources. -#' @importFrom magclass setNames getNames getSets add_columns #' @importFrom dplyr filter group_by mutate select ungroup #' @importFrom rlang syms #' @importFrom tidyr complete nesting calcHistorical <- function() { # Final Energy - fe_iea <- calcOutput("FE", source = "IEA", ieaVersion = "latest", aggregate = FALSE) + fe_iea <- calcOutput("FE", source = "IEA", ieaVersion = "latest", aggregate = FALSE, warnNA = FALSE) fe_iea <- add_dimension(fe_iea, dim = 3.1, add = "model", nm = "IEA") fe_weo <- calcOutput("FE", source = "IEA_WEO", aggregate = FALSE) @@ -15,7 +14,7 @@ calcHistorical <- function() { fe_weo <- add_dimension(fe_weo, dim = 3.1, add = "model", nm = "IEA_WEO") # Primary Energy - pe_iea <- calcOutput("PE", subtype = "IEA", ieaVersion = "latest", aggregate = FALSE) + pe_iea <- calcOutput("PE", subtype = "IEA", ieaVersion = "latest", aggregate = FALSE, warnNA = FALSE) pe_iea <- add_dimension(pe_iea, dim = 3.1, add = "model", nm = "IEA") pe_weo <- calcOutput("PE", subtype = "IEA_WEO", aggregate = FALSE) @@ -34,20 +33,12 @@ calcHistorical <- function() { pop <- add_dimension(pop, dim = 3.1, add = "model", nm = "WDI") # GDP in ppp - gdpp_James <- calcOutput("GDPPast", aggregate = FALSE) / 1000 - getNames(gdpp_James) <- paste0("GDP|PPP (billion US$2005/yr)") - gdpp_James <- add_dimension(gdpp_James, dim = 3.1, add = "model", nm = "James_IHME") - - gdpp_WB <- calcOutput("GDPPast", GDPPast = "WB_USD05_PPP_pc", aggregate = FALSE) / 1000 - getNames(gdpp_WB) <- paste0("GDP|PPP (billion US$2005/yr)") - gdpp_WB <- add_dimension(gdpp_WB, dim = 3.1, add = "model", nm = "James_WB") - - gdpp_IMF <- calcOutput("GDPPast", GDPPast = "IMF_USD05_PPP_pc", aggregate = FALSE) / 1000 - getNames(gdpp_IMF) <- paste0("GDP|PPP (billion US$2005/yr)") - gdpp_IMF <- add_dimension(gdpp_IMF, dim = 3.1, add = "model", nm = "James_IMF") + gdp <- calcOutput("GDPPast", GDPPast = "WDI", aggregate = FALSE) / 1000 + getNames(gdp) <- paste0("GDP|PPP (billion US$2017/yr)") + gdp <- add_dimension(gdp, dim = 3.1, add = "model", nm = "WDI") # Historical emissions from CEDS data base - ceds <- calcOutput("Emissions", datasource = "CEDS2021", aggregate = FALSE) + ceds <- calcOutput("Emissions", datasource = "CEDS2024", aggregate = FALSE) ceds <- add_dimension(ceds, dim = 3.1, add = "model", nm = "CEDS") # Historical emissions from PRIMAPhist data base @@ -65,11 +56,11 @@ calcHistorical <- function() { cdiac <- add_dimension(cdiac, dim = 3.1, add = "model", nm = "CDIAC") # Historical land use emissions (taken from "mrvalidation/R/fullVALIDATION.R") - LU_EDGAR_LU <- calcOutput(type = "LandEmissions", datasource = "EDGAR_LU", aggregate = FALSE, try = TRUE) - LU_CEDS <- calcOutput(type = "LandEmissions", datasource = "CEDS", aggregate = FALSE, try = TRUE) - LU_FAO_EmisLUC <- calcOutput(type = "LandEmissions", datasource = "FAO_EmisLUC", aggregate = FALSE, try = TRUE) - LU_FAO_EmisAg <- calcOutput(type = "LandEmissions", datasource = "FAO_EmisAg", aggregate = FALSE, try = TRUE) - LU_PRIMAPhist <- calcOutput(type = "LandEmissions", datasource = "PRIMAPhist", aggregate = FALSE, try = TRUE) + LU_EDGAR_LU <- calcOutput(type = "LandEmissions", datasource = "EDGAR_LU", aggregate = FALSE, try = TRUE, warnNA = FALSE) + LU_CEDS <- calcOutput(type = "LandEmissions", datasource = "CEDS", aggregate = FALSE, try = TRUE, warnNA = FALSE) + LU_FAO_EmisLUC <- calcOutput(type = "LandEmissions", datasource = "FAO_EmisLUC", aggregate = FALSE, try = TRUE, warnNA = FALSE) + LU_FAO_EmisAg <- calcOutput(type = "LandEmissions", datasource = "FAO_EmisAg", aggregate = FALSE, try = TRUE, warnNA = FALSE) + LU_PRIMAPhist <- calcOutput(type = "LandEmissions", datasource = "PRIMAPhist", aggregate = FALSE, try = TRUE, warnNA = FALSE) # remove scenario dimension (will be added below as also for remind variables) LU_EDGAR_LU <- collapseNames(LU_EDGAR_LU, collapsedim = 1) @@ -91,11 +82,11 @@ calcHistorical <- function() { # Read IRENA renewables capacity data IRENAcap <- readSource(type = "IRENA", subtype = "Capacity")[, , c("Concentrated solar power", - "Geothermal", "Hydropower", + "Geothermal", "Renewable hydropower", "Solar photovoltaic", "Wind")] IRENAcap <- IRENAcap * 1E-03 # converting MW to GW mapping <- data.frame( - IRENA_techs = c("Concentrated solar power", "Geothermal", "Hydropower", "Solar photovoltaic", "Wind"), + IRENA_techs = c("Concentrated solar power", "Geothermal", "Renewable hydropower", "Solar photovoltaic", "Wind"), REMIND_var = c("Cap|Electricity|Solar|CSP (GW)", "Cap|Electricity|Geothermal (GW)", "Cap|Electricity|Hydro (GW)", "Cap|Electricity|Solar|PV (GW)", "Cap|Electricity|Wind (GW)"), stringsAsFactors = FALSE @@ -108,9 +99,6 @@ calcHistorical <- function() { # Region specific historical data ==== - # EEA GHG Projections - EEA_GHGProjections <- toolFillEU34Countries(calcOutput("EEAGHGProjections", aggregate = FALSE)) - # EEA GHG Sectoral Historical Data EEA_GHGSectoral <- toolFillEU34Countries(readSource("EEA_EuropeanEnvironmentAgency", subtype = "sectoral")) EEA_GHGSectoral <- add_dimension(EEA_GHGSectoral, dim = 3.1, add = "model", nm = "EEA_historical") @@ -119,7 +107,7 @@ calcHistorical <- function() { EEA_GHGTotal <- add_dimension(EEA_GHGTotal, dim = 3.1, add = "model", nm = "EEA_historical") # Calculate Emission Reference Values - Emi_Reference <- toolFillEU34Countries(calcOutput("EmiReference", aggregate = FALSE)) + Emi_Reference <- toolFillEU34Countries(calcOutput("EmiReference", aggregate = FALSE, warnNA = TRUE)) Emi_Reference <- add_dimension(Emi_Reference, dim = 3.1, add = "model", nm = "EEA") # Eurostat emissions @@ -239,10 +227,10 @@ calcHistorical <- function() { # find all existing years (y) and variable names (n) varlist <- list( - fe_iea, fe_weo, pe_iea, pe_weo, trade, pop, gdpp_James, - gdpp_WB, gdpp_IMF, ceds, primap, cdiac, LU_EDGAR_LU, LU_CEDS, + fe_iea, fe_weo, pe_iea, pe_weo, trade, pop, gdp, + ceds, primap, cdiac, LU_EDGAR_LU, LU_CEDS, LU_FAO_EmisLUC, LU_FAO_EmisAg, LU_PRIMAPhist, IRENAcap, emiEurostat, - EEA_GHGSectoral, EEA_GHGTotal, EEA_GHGProjections, Emi_Reference, + EEA_GHGSectoral, EEA_GHGTotal, Emi_Reference, worldsteel, USGS_cement ) diff --git a/R/calcIEA_ETP.R b/R/calcIEA_ETP.R index c5a29d39..a3ef5a5b 100644 --- a/R/calcIEA_ETP.R +++ b/R/calcIEA_ETP.R @@ -6,8 +6,6 @@ #' @author Falk Benke #' #' @importFrom dplyr select mutate left_join -#' @importFrom madrat toolGetMapping -#' @importFrom magclass as.magpie #' @importFrom rlang sym #' @importFrom stats aggregate na.pass #' @export @@ -16,7 +14,7 @@ calcIEA_ETP <- function() { mapping <- toolGetMapping("Mapping_IEA_ETP.csv", type = "reportingVariables", where = "mrremind") %>% filter(!is.na(!!sym("REMIND")), !!sym("REMIND") != "") %>% - mutate(!!sym("Conversion") := as.numeric(!!sym("Conversion"))) %>% + mutate("Conversion" = as.numeric(!!sym("Conversion"))) %>% select("variable" = "IEA_ETP", "REMIND", "Conversion", "Unit_REMIND") mapping$variable <- trimws(mapping$variable) @@ -44,10 +42,10 @@ calcIEA_ETP <- function() { ) %>% filter(!!sym("REMIND") != "") %>% mutate( - !!sym("value") := !!sym("value") * !!sym("Conversion"), - !!sym("REMIND") := paste0(!!sym("REMIND"), " (", !!sym("Unit_REMIND"), ")"), - !!sym("model") := paste0("IEA ETP ", !!sym("scenario")), - !!sym("year") := as.numeric(as.character(!!sym("year"))) + "value" = !!sym("value") * !!sym("Conversion"), + "REMIND" = paste0(!!sym("REMIND"), " (", !!sym("Unit_REMIND"), ")"), + "model" = paste0("IEA ETP ", !!sym("scenario")), + "year" = as.numeric(as.character(!!sym("year"))) ) %>% select("region", "year", "model", "variable" = "REMIND", "value") diff --git a/R/calcIEA_EVOutlook.R b/R/calcIEA_EVOutlook.R index 343a84ab..efe10f7c 100644 --- a/R/calcIEA_EVOutlook.R +++ b/R/calcIEA_EVOutlook.R @@ -1,60 +1,92 @@ -#' Calculate REMIND variables from IEA EV Outlook data -#' -#' @md -#' @return A [`magpie`][magclass::magclass] object. +#' Calculate REMIND variables from IEA Global EV Outlook data #' #' @author Falk Benke -#' @importFrom dplyr select mutate left_join -#' @importFrom madrat toolGetMapping toolCountryFill -#' @importFrom magclass as.magpie -#' @importFrom readxl read_excel -#' @importFrom rlang sym -#' @importFrom stats aggregate #' @export - calcIEA_EVOutlook <- function() { - data <- readSource("IEA_EVOutlook") + x <- readSource("IEA_EVOutlook", convert = FALSE)[c("World", "Europe", "EU27"), , ] + getItems(x, dim = 1) <- c("GLO", "EUR", "EU27") + + x <- mbind(x, readSource("IEA_EVOutlook", convert = TRUE)) + + # merge variable and unit to one dimension + getNames(x, dim = 2) <- unlist( + lapply( + strsplit(getNames(x), "\\."), + function(y) { + paste0(y[2], " (", y[3], ")") + } + ) + ) + x <- collapseDim(x, dim = 3.3) + + # rename scenario + getNames(x, dim = 1) <- paste0("IEA GEVO ", gsub("Projection-", "", getNames(x, dim = 1))) - data <- as.data.frame(data) %>% - as_tibble() %>% - select( - "region" = "Region", "scenario" = "Data1", "variable" = "Data2", - "unit" = "Data3", "year" = "Year", "value" = "Value" + map <- toolGetMapping("Mapping_IEA_EV_Outlook.csv", type = "reportingVariables", where = "mrremind") %>% + filter(!is.na(.data$REMIND_Variable), .data$REMIND_Variable != "") %>% + mutate( + "REMIND" = paste0(.data$REMIND_Variable, " (", .data$REMIND_Unit, ")"), + "Variable" = paste0(.data$Variable, " (", .data$Unit, ")") ) %>% - mutate(!!sym("model") := case_when( - !!sym("scenario") %in% c("Historical_MoMo", "Historical") ~ "IEA EV Historical", - !!sym("scenario") == "Projection-SDS" ~ "IEA EV Outlook SDS", - !!sym("scenario") == "Projection-STEPS" ~ "IEA EV Outlook STEPS" - )) - - mapping <- toolGetMapping("Mapping_IEA_EV_Outlook.csv", type = "reportingVariables", where = "mrremind") %>% - filter(!is.na(!!sym("REMIND_Variable")), !!sym("REMIND_Variable") != "") %>% - mutate(!!sym("REMIND") := paste0(!!sym("REMIND_Variable"), " (", !!sym("REMIND_Unit"), ")")) %>% - select("variable" = "Variable", "REMIND", "Factor") - - mapping$variable <- trimws(mapping$variable) - mapping$REMIND <- trimws(mapping$REMIND) - - x <- left_join( - data, - mapping, - by = "variable" - ) %>% - filter(!!sym("REMIND") != "") %>% - mutate(!!sym("value") := !!sym("value") * !!sym("Factor")) %>% - select("region", "year", "model", "variable" = "REMIND", "value") - - x <- aggregate(value ~ region + year + model + variable, x, sum, na.action = na.exclude) %>% - as.magpie() %>% - toolCountryFill(fill = NA, verbosity = 2) - - # set 0s in other CHA countries than China to approximate CHA as China - x[c("HKG", "MAC", "TWN"), , ] <- 0 + select("Variable", "REMIND", "Factor") + + for (var in intersect(getNames(x, dim = 2), unique(map$Variable))) { + conv <- map[map$Variable == var, "Factor"] + + # there should be a distinct conversion factor in the mapping + # if there is more than one conversion factor, it means that one source variable + # is converted two more than one target variable using a different conversion + # this case is not covered by the logic + if (length(unique(conv)) > 1) { + stop(paste0("Cannot apply conversion factor for variable ", var)) + } + + x[, , var] <- x[, , var] * unique(conv) + } + + x <- toolAggregate(x, + dim = 3.2, rel = map, from = "Variable", + to = "REMIND", partrel = TRUE, verbosity = 2 + ) + + getSets(x)[3.1] <- "model" + + dataReg <- x[c("GLO", "EUR", "EU27"), , ] + x <- x[c("GLO", "EUR", "EU27"), , , invert = TRUE] + + # includes region values from the original source instead of calculating + # them as the sum of all countries (as countries are incomplete) + .customAggregate <- function(x, rel, to = NULL, reg) { + x <- toolAggregate(x, rel = rel, to = to) + + if (any(c("GLO", "EUR", "EU27") %in% getItems(x, dim = 1))) { + + r <- intersect(c("GLO", "EUR", "EU27"), getItems(x, dim = 1)) + x <- x[r, , , invert = TRUE] + + out <- new.magpie( + cells_and_regions = union(getItems(x, dim = 1), r), + years = union(getYears(x), getYears(reg)), + names = union(getNames(x), getNames(reg)), + fill = NA, + sets = names(dimnames(x)) + ) + + out[getItems(x, dim = 1), getYears(x), getNames(x)] <- x + out[r, getYears(reg), getNames(reg)] <- reg[r, , ] + + return(out) + } else { + return(x) + } + } return(list( x = x, weight = NULL, unit = c("EJ/yr", "Million vehicles"), + aggregationFunction = .customAggregate, + aggregationArguments = list(reg = dataReg), description = "IEA EV Outlook data in REMIND variables" )) } diff --git a/R/calcIEA_WEO_2021.R b/R/calcIEA_WEO_2021.R deleted file mode 100644 index 611d9be6..00000000 --- a/R/calcIEA_WEO_2021.R +++ /dev/null @@ -1,107 +0,0 @@ -#' Calculate REMIND variables from IEA WEO 2021 data -#' -#' @md -#' @return A [`magpie`][magclass::magclass] object. -#' @param subtype Either "global" or "region". On global level, the source offers -#' more variables than on regional level, but the data should not be used on sub- -#' global level due to its coarse disaggregation. -#' @author Falk Benke -#' @importFrom dplyr select mutate left_join case_when -#' @importFrom madrat toolGetMapping -#' @importFrom magclass as.magpie -#' @importFrom rlang sym -#' @importFrom stats aggregate -#' @export - -calcIEA_WEO_2021 <- function(subtype) { # nolint - - mapping <- toolGetMapping("Mapping_IEA_WEO_2021_complete.csv", type = "reportingVariables", - where = "mappingfolder") %>% - filter(!is.na(!!sym("REMIND")), !!sym("REMIND") != "") %>% - mutate( - !!sym("WEO") := paste0(!!sym("WEO"), " (", !!sym("Unit_WEO"), ")"), # nolint - !!sym("Conversion") := as.numeric(!!sym("Conversion")) # nolint - ) %>% - select("variable" = "WEO", "REMIND", "Conversion", "unit" = "Unit_WEO", "Unit_REMIND") - - mapping$variable <- trimws(mapping$variable) - - data <- readSource("IEA_WEO_2021", subtype = subtype) - - # copy over Stated Policies Scenario for 2010 - 2020 to other scenarios - for (s in getNames(data, dim = 1)) { - data[, c("y2010", "y2019", "y2020"), s] <- - data[, c("y2010", "y2019", "y2020"), "Stated Policies Scenario"][, , getNames(data[, , s], dim = 2)] - } - - data <- as.data.frame(data) %>% - as_tibble() %>% - select( - "region" = "Region", "scenario" = "Data1", "variable" = "Data2", - "year" = "Year", "value" = "Value" - ) %>% - mutate(!!sym("scenario_short") := case_when( # nolint - scenario == "Stated Policies Scenario" ~ "SPS", - scenario == "Announced pledges scenario" ~ "APS", - scenario == "Announced Pledges Scenario" ~ "APS", - scenario == "Sustainable Development Scenario" ~ "SDS", - scenario == "Net Zero Emissions by 2050 Scenario" ~ "Net2050" - )) - - x <- left_join( - data, - mapping, - by = "variable" - ) %>% - filter(!!sym("REMIND") != "") %>% - mutate( - !!sym("value") := !!sym("value") * !!sym("Conversion"), - !!sym("REMIND") := paste0(!!sym("REMIND"), " (", !!sym("Unit_REMIND"), ")"), # nolint - !!sym("model") := paste0("IEA WEO 2021 ", !!sym("scenario_short")) # nolint - ) %>% - select("region", "year", "model", "variable" = "REMIND", "value") - - x <- aggregate(value ~ region + year + model + variable, x, sum) %>% - as.magpie(spatial = 1, temporal = 2, data = 5) %>% - toolCountryFill(fill = NA) - - if (subtype == "global") { - x <- add_columns(x, "Cap|Electricity|Biomass|w/o CC (GW)", dim = 3.2) - x[, , "Cap|Electricity|Biomass|w/o CC (GW)"] <- - x[, , "Cap|Electricity|Biomass (GW)"] - x[, , "Cap|Electricity|Biomass|w/ CC (GW)"] - - x <- add_columns(x, "Cap|Electricity|Coal (GW)", dim = 3.2) - x[, , "Cap|Electricity|Coal (GW)"] <- - x[, , "Cap|Electricity|Coal|w/o CC (GW)"] + x[, , "Cap|Electricity|Coal|w/ CC (GW)"] - - x <- add_columns(x, "Cap|Electricity|Solar (GW)", dim = 3.2) - x[, , "Cap|Electricity|Solar (GW)"] <- - x[, , "Cap|Electricity|Solar|CSP (GW)"] + x[, , "Cap|Electricity|Solar|PV (GW)"] - - x <- add_columns(x, "Cap|Electricity|Fossil (GW)", dim = 3.2) - x[, , "Cap|Electricity|Fossil (GW)"] <- - x[, , "Cap|Electricity|Fossil|w/o CC (GW)"] + x[, , "Cap|Electricity|Fossil|w/ CC (GW)"] - - x <- add_columns(x, "Cap|Electricity|Gas (GW)", dim = 3.2) - x[, , "Cap|Electricity|Gas (GW)"] <- - x[, , "Cap|Electricity|Gas|w/o CC (GW)"] + x[, , "Cap|Electricity|Gas|w/ CC (GW)"] - - x <- add_columns(x, "SE|Electricity|Solar (EJ/yr)", dim = 3.2) - x[, , "SE|Electricity|Solar (EJ/yr)"] <- - x[, , "SE|Electricity|Solar|PV (EJ/yr)"] + x[, , "SE|Electricity|Solar|CSP (EJ/yr)"] - } - - # correct PE|Nuclear and PE - # PE Nuclear is usually reported in direct equivalents, values from IEA are - # roughly 3 times higher than the REMIND ones - x[, , "PE (EJ/yr)"] <- x[, , "PE (EJ/yr)"] - x[, , "PE|Nuclear (EJ/yr)"] - x[, , "PE|Nuclear (EJ/yr)"] <- x[, , "PE|Nuclear (EJ/yr)"] / 3 - x[, , "PE (EJ/yr)"] <- x[, , "PE (EJ/yr)"] + x[, , "PE|Nuclear (EJ/yr)"] - - return(list( - x = x, - weight = NULL, - unit = c("GW", "EJ/yr", "Mt CO2/yr"), - description = "IEA WEO 2021 values as REMIND variables" - )) -} diff --git a/R/calcIEA_WorldEnergyOutlook.R b/R/calcIEA_WorldEnergyOutlook.R new file mode 100644 index 00000000..927955c6 --- /dev/null +++ b/R/calcIEA_WorldEnergyOutlook.R @@ -0,0 +1,140 @@ +#' Calculate REMIND variables from IEA World Energy Outlook data. +#' +#' @author Falk Benke +#' @export + +calcIEA_WorldEnergyOutlook <- function() { # nolint + + dataGlo <- readSource("IEA_WorldEnergyOutlook", convert = FALSE)["World", , ] + magclass::getItems(dataGlo, dim = 1) <- "GLO" + dataReg <- readSource("IEA_WorldEnergyOutlook", convert = TRUE) + + .mapToRemind <- function(data) { + + # copy over Stated Policies Scenario for 2010 - 2022 to other scenarios + for (s in magclass::getNames(data, dim = 1)) { + data[, c("y2010", "y2015", "y2021", "y2022"), s] <- + data[, c("y2010", "y2015", "y2021", "y2022"), "Stated Policies Scenario"][, , magclass::getNames(data[, , s], dim = 2)] + } + + # rename scenarios + scens <- c( + "Stated Policies Scenario" = "SPS", + "Announced pledges scenario" = "APS", + "Announced Pledges Scenario" = "APS", + "Net Zero Emissions by 2050 Scenario" = "Net2050" + ) + + magclass::getNames(data, dim = 1) <- paste0("IEA WEO 2023 ", scens[magclass::getNames(data, dim = 1)]) + magclass::getSets(data)[3] <- "model" + + map <- toolGetMapping("Mapping_IEA_WEO_complete.csv", type = "reportingVariables", where = "mrremind") %>% + dplyr::filter(!is.na(.data$REMIND), .data$REMIND != "") %>% + dplyr::mutate("conversion" = as.numeric(.data$Conversion)) %>% + dplyr::select("from" = "Variable", "to" = "REMIND", "conversion") + + for (var in intersect(getNames(data, dim = 2), unique(map$from))) { + conv <- map[map$from == var, "conversion"] + + # if there is more than one conversion factor, it means that one source variable + # is converted two more than one target variable using a different conversion factor + if (length(unique(conv)) > 1) { + + # create unique "from" variables for each mapping entry by appending numbers + map[map$from == var, "from"] <- paste0(map[map$from == var, "from"], " ", seq(1, nrow(map[map$from == var, ]))) + + # duplicate "from" data with for each mapping entry + for (i in seq(1, length(unique(conv)))) { + dup <- data[, , var] + getNames(dup, dim = 2) <- paste0(getNames(dup, dim = 2), " ", i) + data <- mbind(data, dup) + } + data <- data[, , var, invert = TRUE] + } else { + data[, , var] <- data[, , var] * unique(conv) + } + } + + x <- toolAggregate(data, + dim = 3.2, rel = map, from = "from", + to = "to", partrel = TRUE, verbosity = 2 + ) + + return(x) + } + + dataGlo <- .mapToRemind(dataGlo) + dataReg <- .mapToRemind(dataReg) + + .calcAdditionalVars <- function(x) { + # correct PE|Nuclear and PE + # PE Nuclear is usually reported in direct equivalents, values from IEA are + # roughly 3 times higher than the REMIND ones + x[, , "PE (EJ/yr)"] <- x[, , "PE (EJ/yr)"] - x[, , "PE|Nuclear (EJ/yr)"] + x[, , "PE|Nuclear (EJ/yr)"] <- x[, , "PE|Nuclear (EJ/yr)"] / 3 + x[, , "PE (EJ/yr)"] <- x[, , "PE (EJ/yr)"] + x[, , "PE|Nuclear (EJ/yr)"] + + return(x) + } + + dataGlo <- .calcAdditionalVars(dataGlo) + dataReg <- .calcAdditionalVars(dataReg) + + dataGlo <- magclass::add_columns(dataGlo, "Cap|Electricity|Biomass|w/o CC (GW)", dim = 3.2) + dataGlo[, , "Cap|Electricity|Biomass|w/o CC (GW)"] <- + dataGlo[, , "Cap|Electricity|Biomass (GW)"] - dataGlo[, , "Cap|Electricity|Biomass|w/ CC (GW)"] + + dataGlo <- magclass::add_columns(dataGlo, "Cap|Electricity|Coal (GW)", dim = 3.2) + dataGlo[, , "Cap|Electricity|Coal (GW)"] <- + dataGlo[, , "Cap|Electricity|Coal|w/o CC (GW)"] + dataGlo[, , "Cap|Electricity|Coal|w/ CC (GW)"] + + dataGlo <- magclass::add_columns(dataGlo, "Cap|Electricity|Solar (GW)", dim = 3.2) + dataGlo[, , "Cap|Electricity|Solar (GW)"] <- + dataGlo[, , "Cap|Electricity|Solar|CSP (GW)"] + dataGlo[, , "Cap|Electricity|Solar|PV (GW)"] + + dataGlo <- magclass::add_columns(dataGlo, "Cap|Electricity|Fossil (GW)", dim = 3.2) + dataGlo[, , "Cap|Electricity|Fossil (GW)"] <- + dataGlo[, , "Cap|Electricity|Fossil|w/o CC (GW)"] + dataGlo[, , "Cap|Electricity|Fossil|w/ CC (GW)"] + + dataGlo <- magclass::add_columns(dataGlo, "Cap|Electricity|Gas (GW)", dim = 3.2) + dataGlo[, , "Cap|Electricity|Gas (GW)"] <- + dataGlo[, , "Cap|Electricity|Gas|w/o CC (GW)"] + dataGlo[, , "Cap|Electricity|Gas|w/ CC (GW)"] + + dataGlo <- magclass::add_columns(dataGlo, "SE|Electricity|Solar (EJ/yr)", dim = 3.2) + dataGlo[, , "SE|Electricity|Solar (EJ/yr)"] <- + dataGlo[, , "SE|Electricity|Solar|PV (EJ/yr)"] + dataGlo[, , "SE|Electricity|Solar|CSP (EJ/yr)"] + + # includes values from the original source for global region instead of calculating + # it as the sum of all countries (as countries are incomplete) + .customAggregate <- function(x, rel, to = NULL, glo) { + x <- toolAggregate(x, rel = rel, to = to) + + if ("GLO" %in% magclass::getItems(x, dim = 1)) { + x <- x["GLO", , , invert = TRUE] + + out <- magclass::new.magpie( + cells_and_regions = union(magclass::getItems(x, dim = 1), "GLO"), + years = union(magclass::getYears(x), magclass::getYears(glo)), + names = union(magclass::getNames(x), magclass::getNames(glo)), + fill = NA, + sets = names(dimnames(x)) + ) + + out[magclass::getItems(x, dim = 1), magclass::getYears(x), magclass::getNames(x)] <- x + out["GLO", magclass::getYears(glo), magclass::getNames(glo)] <- glo + + return(out) + } else { + return(x) + } + } + + return(list( + x = dataReg, + weight = NULL, + unit = c("GW", "EJ/yr", "Mt CO2/yr"), + aggregationFunction = .customAggregate, + aggregationArguments = list(glo = dataGlo), + description = "IEA World Energy Outlook 2023 values as REMIND variables" + )) +} diff --git a/R/calcILO.R b/R/calcILO.R deleted file mode 100644 index 87134152..00000000 --- a/R/calcILO.R +++ /dev/null @@ -1,35 +0,0 @@ -#' calcILO -#' ILO data for employment in oil and gas; coal and lignite -#' @param subtype "Reliable" and "all". ILO classifies its data per country into reliable, unreliable, and break in series (years without data). "Reliable" contains both reliable and break-in-series-data, "all" contains both reliable and unreliable data -#' @author Aman Malik -#' @return magpie object with employment data for different years - -calcILO <- function(subtype){ - x <- readSource("ILO") - x[is.na(x)] <- 0 - - if(subtype=="Reliable") - { - x <- x[,,"Unreliable",pmatch=T,invert=T] - x[,,"Oil and Gas. "] <- x[,,"Oil and Gas. "]+x[,,"Oil and Gas.Break in series"] - x[,,"Coal and Lignite. "] <- x[,,"Coal and Lignite. "]+x[,,"Coal and Lignite.Break in series"] - x <- x[,,c("Oil and Gas. ","Coal and Lignite. ")] - x <- collapseNames(x) - x <- magpiesort(x) - - } - - if(subtype=="all"){ # containts both unreliable and "break in series" labels - x[,,"Oil and Gas. "] <- dimSums(x[,,"Oil and Gas",pmatch=T]) - x[,,"Coal and Lignite. "] <- dimSums(x[,,"Coal and Lignite",pmatch=T]) - x <- x[,,c("Oil and Gas. ","Coal and Lignite. ")] - x <- collapseNames(x) - x <- magpiesort(x) - } - - return(list( - x=x, - weight=NULL, - unit="000s", - description="Employment in coal and lignite or oil and gas")) -} diff --git a/R/calcINNOPATHS.R b/R/calcINNOPATHS.R index 85bcb84b..85aa43ef 100644 --- a/R/calcINNOPATHS.R +++ b/R/calcINNOPATHS.R @@ -1,49 +1,43 @@ -#' @importFrom dplyr left_join select filter mutate %>% -#' @importFrom madrat toolGetMapping -#' -calcINNOPATHS <- function(x) { - mapping <- toolGetMapping("Mapping_INNOPATHS.csv", type = "reportingVariables", where = "mappingfolder") %>% - filter(!is.na(!!sym("REMIND"))) %>% - mutate( - !!sym("REMIND_unit") := gsub("\\)", "", gsub(".*\\(", "", !!sym("REMIND"))), - !!sym("REMIND") := gsub(" \\(.*", "", !!sym("REMIND")), - !!sym("INNOPATHS") := gsub(" \\(.*", "", !!sym("Variable")), - !!sym("INNOPATHS_unit") := gsub("\\)", "", gsub(".*\\(", "", !!sym("Variable"))) - ) %>% - select( - "INNOPATHS", "INNOPATHS_unit", "REMIND", "REMIND_unit", "factor" - ) - - data <- readSource("INNOPATHS") %>% - as.data.frame() %>% - as_tibble() %>% - select( - "region" = "Region", "variable" = "Data1", - "unit" = "Data2", "year" = "Year", "value" = "Value" - ) - - x <- left_join( - data, - mapping, - by = c("variable" = "INNOPATHS") - ) %>% - filter(!!sym("REMIND") != "") %>% - mutate( - !!sym("value") := !!sym("value") * !!sym("factor"), - !!sym("year") := as.numeric(as.character(!!sym("year"))), - !!sym("REMIND") := paste0(!!sym("REMIND"), " (", !!sym("REMIND_unit"), ")") - ) %>% - select("region", "year", "variable" = "REMIND", "value") %>% - as.magpie() +calcINNOPATHS <- function() { + + x <- readSource("INNOPATHS") + + # merge variable and unit to one dimension + getNames(x, dim = 1) <- paste0(gsub("\\.", " (", getNames(x)), ")") + x <- collapseDim(x, dim = 3.2) + + map <- toolGetMapping("Mapping_INNOPATHS.csv", type = "reportingVariables", where = "mrremind") %>% + filter(!is.na(.data$REMIND)) + + for (var in intersect(getNames(x, dim = 1), unique(map$Variable))) { + + conv <- map[map$Variable == var, "factor"] + + # there should be a distinct conversion factor in the mapping + # if there is more than one conversion factor, it means that one source variable + # is converted two more than one target variable using a different conversion + # this case is not covered by the logic + if (length(unique(conv)) > 1) { + stop(paste0("Cannot apply conversion factor for variable ", var)) + } + + x[, , var] <- x[, , var] * unique(conv) + } + + x <- toolAggregate(x, + dim = 3.1, rel = map, from = "Variable", + to = "REMIND", partrel = TRUE, verbosity = 2 + ) weights <- x weights[, , ] <- NA - weights[, , "US$2005", pmatch = T] <- 1 + weights[, , "US$2005", pmatch = TRUE] <- 1 + weights[, , "GDP|MER (billion US$2005/yr)"] <- NA return(list( x = x, weight = weights, - mixed_aggregation = T, + mixed_aggregation = TRUE, unit = "Various", description = "INNOPATHS projections as REMIND variables" )) diff --git a/R/calcIO.R b/R/calcIO.R index ac14d9b8..a2295e89 100644 --- a/R/calcIO.R +++ b/R/calcIO.R @@ -22,7 +22,7 @@ #' } #' #' @importFrom rlang .data -#' @importFrom dplyr %>% filter mutate +#' @importFrom dplyr filter mutate #' @importFrom tidyr unite #' @importFrom tidyselect all_of calcIO <- function(subtype = c("input", "output", "output_biomass", "trade", @@ -33,61 +33,84 @@ calcIO <- function(subtype = c("input", "output", "output_biomass", "trade", switch( subtype, input = { - mapping <- "structuremappingIO_inputs.csv" - where <- "mrremind" + mapping <- toolGetMapping(type = "sectoral", + name = "structuremappingIO_inputs.csv", + where = "mrremind", + returnPathOnly = TRUE) target <- c("REMINDitems_in", "REMINDitems_out", "REMINDitems_tech") }, output = { - mapping <- "structuremappingIO_outputs.csv" - where <- "mrcommons" + mapping <- toolGetMapping(type = "sectoral", + name = "structuremappingIO_outputs.csv", + where = "mrcommons", + returnPathOnly = TRUE) target <- c("REMINDitems_in", "REMINDitems_out", "REMINDitems_tech") }, output_biomass = { - mapping <- "structuremappingIO_outputs.csv" - where <- "mrcommons" + mapping <- toolGetMapping(type = "sectoral", + name = "structuremappingIO_outputs.csv", + where = "mrcommons", + returnPathOnly = TRUE) target <- c("REMINDitems_in", "REMINDitems_out", "REMINDitems_tech") }, trade = { - mapping <- "structuremappingIO_trade.csv" - where <- "mrremind" + mapping <- toolGetMapping(type = "sectoral", + name = "structuremappingIO_trade.csv", + where = "mrremind", + returnPathOnly = TRUE) target <- c("REMINDitems_enty", "REMINDitems_trade") }, input_Industry_subsectors = { - mapping <- "structuremappingIO_inputs_Industry_subsectors.csv" - where <- "mrremind" + mapping <- toolGetMapping(type = "sectoral", + name = "structuremappingIO_inputs_Industry_subsectors.csv", + where = "mrremind", + returnPathOnly = TRUE) target <- c("REMINDitems_in", "REMINDitems_out", "REMINDitems_tech") }, output_Industry_subsectors = { - mapping <- "structuremappingIO_outputs_Industry_subsectors.csv" - where <- "mrremind" + mapping <- toolGetMapping(type = "sectoral", + name = "structuremappingIO_outputs_Industry_subsectors.csv", + where = "mrremind", + returnPathOnly = TRUE) target <- c("REMINDitems_in", "REMINDitems_out", "REMINDitems_tech") }, IEA_output = { - mapping <- "structuremappingIO_outputs.csv" - where <- "mrcommons" + mapping <- toolGetMapping(type = "sectoral", + name = "structuremappingIO_outputs.csv", + where = "mrcommons", + returnPathOnly = TRUE) target <- c("REMINDitems_in", "REMINDitems_out", "REMINDitems_tech", "iea_product", "iea_flows") }, IEA_input = { - mapping <- "structuremappingIO_inputs.csv" - where <- "mrremind" + mapping <- toolGetMapping(type = "sectoral", + name = "structuremappingIO_inputs.csv", + where = "mrremind", + returnPathOnly = TRUE) target <- c("REMINDitems_in", "REMINDitems_out", "REMINDitems_tech", "iea_product", "iea_flows") } ) - mapping <- toolGetMapping(type = "sectoral", name = mapping, where = where, - returnPathOnly = TRUE) if (!(ieaVersion %in% c("default", "latest"))) { stop("Invalid parameter `ieaVersion`. Must be either 'default' or 'latest'") } ieaSubtype <- if (ieaVersion == "default") "EnergyBalances" else "EnergyBalances-latest" - ieaYear <- if (ieaVersion == "default") 2022 else 2023 + ieaYear <- if (ieaVersion == "default") 2022 else 2024 # read in data and convert from ktoe to EJ data <- readSource("IEA", subtype = ieaSubtype) * 4.1868e-5 + # Correct transport reporting issue in IEA data for NONBIODIES.MARBUNK in RUS + # FE is reported in 1990 and 2010 but not in the years in between. This cause problems in the harmonization of EDGE-Transport + # and the IEA data in 2005 as there is no MARBUNK demand at all for REF regions. + data["RUS", seq(1990, 2010, 1), "NONBIODIES.MARBUNK"] <- + data["RUS", c(1990, 2010),"NONBIODIES.MARBUNK"]|> time_interpolate(seq(1990, 2010, 1)) + #Adjust totals + data["RUS", seq(1991, 2009, 1),"TOTAL.MARBUNK"] <- + data["RUS", seq(1991, 2009, 1),"TOTAL.MARBUNK"] + data["RUS", seq(1991, 2009, 1), "NONBIODIES.MARBUNK"] + ieamatch <- read.csv2(mapping, stringsAsFactors = FALSE, na.strings = "") # add total buildings electricity demand (feelb = feelcb + feelhpb + feelrhb) diff --git a/R/calcIndustry_CCS_limits.R b/R/calcIndustry_CCS_limits.R new file mode 100644 index 00000000..a164d1fa --- /dev/null +++ b/R/calcIndustry_CCS_limits.R @@ -0,0 +1,283 @@ +#' Calculate Limits on Industry CCS Capacities +#' +#' @md +#' @details +#' The limits on industry CCS capacities are calculated from data of the +#' [Global Status of CCS 2023](zotero://select/items/3_E5GNNPZ8) report (through +#' [`readGlobalCCSinstitute()`]. CCS projects are +#' - filtered for valid (i.e. not "Under Evaluation") data for "Operation date" +#' and "CO~2~ capture capacity" +#' - assigned to REMIND industry subsectors according to `facility_subsector`, +#' which defaults to +#' | Facility Industry | subsector | +#' |:--------------------------------|:----------| +#' | Cement | cement | +#' | Chemical | chemicals | +#' | Hydrogen / Ammonia / Fertiliser | chemicals | +#' | Ethan | chemicals | +#' | Iron and Steel Production | steel | +#' +#' - weighted by lifecycle stage according to `stage_weight`, which defaults to +#' | Lifecycle stage | weight | +#' |:---------------------|-------:| +#' | Operational | 100 % | +#' | In construction | 100 % | +#' | Advanced development | 50 % | +#' | Early development | 20 % | +#' +#' The resulting project capacities constitute the limits on industry subsector +#' CCS capacity for 2025. The limit on CCS capacities for regions (or countries +#' if `region_mapping` is `NULL`) is set to a value of total 2025 subsector CCS +#' capacity, times the regions share in subsector activity (e.g. cement +#' production) of the SSP2EU scenario +#' - in 2030 if the region as some CCS capacity in 2025 in a different industry +#' subsector, or +#' - in 2035 if the region has no industry CCS capacity in 2030 at all. +#' +#' CCS capacities are increased by the annual growth factor `a1` for the ten +#' first years, and by the annual growth factor `a2` afterwards (defaulting to +#' 70 % and 20 %, respectively). +#' +#' @param a1,a2 Annual growth factors of CCS capacity limits, for the first ten +#' years and thereafter, default to `0.7` and `0.2` (70 % and 20 %, +#' respectively). +#' @param installation_minimum Minimum emission capacity (in MtCO~2~/year) +#' capacities are rounded up to. Defaults to `0.5` (500 ktCO~2~/year). +#' @param stage_weight A named vector of weight factors for different lifecycle +#' stages. See Details. +#' @param facility_subsector A named vector mapping the "Facility Industry" of +#' CCS projects to REMIND industry subsectors. See Details. +#' @param region_mapping A data frame with columns `iso3c` and `region` detailing +#' the regional resolution on which data should be extrapolated. If `NULL` +#' (the default), extrapolation is done at the country level. +#' +#' @return A list with a [`magpie`][magclass::magclass] object `x`, `weight`, +#' `unit`, `description`, and `min`. +#' +#' @author Michaja Pehl +#' +#' @importFrom dplyr arrange group_by full_join inner_join left_join mutate +#' pull rename select summarise tibble ungroup +#' @importFrom quitte add_countrycode_ madrat_mule magclass_to_tibble +#' @importFrom readr read_delim +#' @importFrom rlang .data +#' @importFrom tidyr complete fill pivot_longer replace_na +#' +#' @export +calcIndustry_CCS_limits <- function( + a1 = 0.3, a2 = 0.15, + installation_minimum = 1, + stage_weight = c('Operational' = 1, + 'In construction' = 1, + 'Advanced development' = 0.5, + 'Early development' = 0.2), + facility_subsector = c('Cement' = 'cement', + 'Chemical' = 'chemicals', + 'Hydrogen / Ammonia / Fertiliser' = 'chemicals', + 'Ethan' = 'chemicals', + 'Iron and Steel Production' = 'steel'), + region_mapping = NULL) { + + # configuration ---- + stage_weight <- tibble(stage = names(stage_weight), factor = stage_weight) + + facility_subsector <- tibble(`Facility Industry` = names(facility_subsector), + subsector = facility_subsector) + + remind_timesteps <- unique(quitte::remind_timesteps$period) + + ## read SSP2EU industry activity ---- + ind_activity <- calcOutput('FEdemand', aggregate = FALSE, + years = remind_timesteps) %>% + `[`(,,paste0('gdp_SSP2EU.', + c('ue_cement', 'ue_chemicals', 'ue_steel_primary'))) %>% + magclass_to_tibble() %>% + mutate(subsector = sub('ue_([^_]+).*', '\\1', .data$item), + .keep = 'unused') %>% + select(iso3c = 'region', 'subsector', period= 'year', activity = 'value') + + ## set/check region mapping ---- + iso3c_list <- read_delim( + file = system.file('extdata', 'iso_country.csv', package = 'madrat'), + delim = ';', + col_names = c('-', 'iso3c'), + col_types = '-c', + skip = 1) %>% + pull('iso3c') %>% + sort() + + if (is.null(region_mapping)) { + region_mapping <- tibble(iso3c = iso3c_list, region = iso3c_list) + } + else if (!setequal(region_mapping[['iso3c']], iso3c_list)) { + stop('region_mapping iso3c column does not match madrat prescribed iso3c list') + } + + # calculation ---- + x <- readSource('GlobalCCSinstitute', '2023-11', convert = FALSE) %>% + madrat_mule() %>% + rename(value = 'Capture, transport and/or storage capacity (Mtpa CO2)', + stage = 'Lifecycle stage') %>% + filter(!is.na(.data$value)) %>% + # filter for facility industry + inner_join(facility_subsector, 'Facility Industry') %>% + add_countrycode_(origin = c('Country' = 'country.name'), + destination = 'iso3c') %>% + left_join(region_mapping, 'iso3c' ) %>% + left_join(stage_weight, 'stage') %>% + # split facilities existing already in 2025 or only in 2030 + mutate(`2025` = .data$`Operational date` <= 2027, + `2030` = .data$`Operational date` <= 2032) %>% + pivot_longer(cols = c('2025', '2030'), names_to = 'period', + names_transform = as.integer, values_to = 'include') %>% + filter(.data$include) %>% + select(-'include') %>% + # regional aggregation and applying stage factors + group_by(.data$period, .data$region, .data$subsector) %>% + summarise(value = sum(.data$value * .data$factor), .groups = 'drop') %>% + complete(crossing(!!!syms(c('region', 'subsector', 'period'))), + fill = list(value = 0)) %>% + full_join( + ind_activity %>% + full_join(region_mapping, 'iso3c') %>% + group_by(.data$region, .data$subsector, .data$period) %>% + summarise(activity = sum(.data$activity), .groups = 'drop'), + + c('region', 'subsector', 'period') + ) %>% + replace_na(list(period = 2025L, value = 0)) %>% + # classes: - A: non-zero 2025 data (is continued) + # - B: zero 2025 data, but non-zero 2025 data in different + # subsector (gets initialised in 2030) + # - C: zero 2025 data in all subsectors (get initialised in 2035) + group_by(.data$region, .data$subsector) %>% + mutate( + class = ifelse(0 != .data$value[2025 == .data$period], 'A', NA)) %>% + group_by(.data$region) %>% + mutate( + class = case_when( + 'A' == .data$class ~ .data$class, + 0 != sum(.data$value[2025 == .data$period]) ~ 'B', + 0 == sum(.data$value[2025 == .data$period]) ~ 'C')) %>% + ungroup() %>% + complete(nesting(!!!syms(c('region', 'subsector', 'class'))), + period = remind_timesteps, + fill = list(value = NA)) %>% + group_by(.data$period, .data$subsector) %>% + mutate(activity.total = sum(.data$activity, na.rm = TRUE), + value.total = case_when( + .data$period <= 2030 ~ sum(.data$value, na.rm = TRUE))) %>% + group_by(.data$subsector) %>% + fill('value.total', .direction = 'down') %>% + arrange(.data$region, .data$subsector, .data$period) %>% + # conversion factors for activity to emissions for cement and steel + full_join( + tribble( + ~subsector, ~factor, # ad-hoc emission factors + 'cement', 0.78, # Gt cement/a -> GtCO2/a + 'chemicals', NA, + 'steel', 1.85), # Gt steel/a -> GtCO2/a + + 'subsector') %>% + group_by(.data$region, .data$subsector) %>% + mutate( + value = case_when( + 2045 < .data$period ~ NA, + TRUE ~ .data$value), + + value = case_when( + ## before 2025 ---- + .data$period < 2025 ~ 0, + + # 2025 just keeps data present + + ## 2030 ---- + + 'A' == .data$class & 2030 == .data$period ~ + # either the 2030 value, or the expanded 2025 value, whichever is + # higher + max(sum(.data$value, na.rm = TRUE), + .data$value[2025 == .data$period] * (1 + a1) ^ 5), + + 'B' == .data$class & 2030 == .data$period ~ + # global 2025 subsector CCS times regional share in global subsector + # activity, rounded up to MtCO2/a, but not + # exceeding regional subsector emissions + (.data$value.total * .data$activity / .data$activity.total) %>% + max(installation_minimum) %>% + min(.data$activity * 1e3 * .data$factor, na.rm = TRUE), + + 'C' == .data$class & 2030 == .data$period ~ 0, + + TRUE ~ .data$value), + + ## 2035 ---- + value = case_when( + .data$class %in% c('A', 'B') & 2035 == .data$period ~ + # expanded 2030 value + .data$value[2030 == .data$period] * (1 + a1) ^ 5, + + 'C' == .data$class & 2035 == .data$period ~ + # global 2025 subsector CCS times regional share in global subsector + # activity, rounded up to MtCO2/a, but not + # exceeding regional subsector emissions + (.data$value.total * .data$activity / .data$activity.total) %>% + max(installation_minimum) %>% + min(.data$activity * 1e3 * .data$factor, na.rm = TRUE), + + TRUE ~ .data$value), + + ## 2040 ---- + value = case_when( + 'A' == .data$class & 2040 == .data$period ~ + # expand 2035 value, using a2 + .data$value[2035 == .data$period] * (1 + a2) ^ 5, + + .data$class %in% c('B', 'C') & 2040 == .data$period ~ + # expand 2035 value, using a1 + .data$value[2035 == .data$period] * (1 + a1) ^ 5, + + TRUE ~ .data$value), + + ## 2045 ---- + value = case_when( + .data$class %in% c('A', 'B') & 2045 == .data$period ~ + # expand 2040 value, using a2 + .data$value[2040 == .data$period] * (1 + a2) ^ 5, + + 'C' == .data$class & 2045 == .data$period ~ + # expand 2040 value, using a1 + .data$value[2040 == .data$period] * (1 + a1) ^ 5, + + TRUE ~ .data$value), + + ## after 2045 ---- + value = ifelse(!is.na(.data$value), .data$value, + ( last(.data$value[!is.na(.data$value)]) + * (1 + a2) + ^ (.data$period - last(.data$period[!is.na(.data$value)])) + ))) %>% + ungroup() %>% + select('region', 'subsector', 'period', 'value') %>% + # expand from regions to iso3c (if different), convert unit + full_join( + full_join(ind_activity, region_mapping, 'iso3c'), + + by = c('region', 'subsector', 'period'), + relationship = 'many-to-many' + ) %>% + group_by(.data$region, .data$subsector, .data$period) %>% + ## convert units ---- + # MtCO2/yr * 1e-3 Gt/Mt / (44/12 CO2/C) = GtC/yr + mutate(value = .data$value + * .data$activity / sum(.data$activity) + * 12/44 * 1e-3) %>% + ungroup() %>% + select('iso3c', 'period', 'subsector', 'value') + + return(list(x = as.magpie(x = x, spatial = 1, temporal = 2, datacol = 4), + weight = NULL, + unit = 'GtC/yr', + description = 'Limits on Industry CCS Capacities', + min = 0)) +} diff --git a/R/calcIndustry_EEK.R b/R/calcIndustry_EEK.R index a7cdd3aa..39fbf6d6 100644 --- a/R/calcIndustry_EEK.R +++ b/R/calcIndustry_EEK.R @@ -7,12 +7,9 @@ #' `unit`, and `description` fields. #' #' @importFrom assertr assert -#' @importFrom dplyr %>% arrange bind_rows filter group_by lag lead mutate n +#' @importFrom dplyr arrange bind_rows filter group_by lag lead mutate n #' row_number select -#' @importFrom madrat calcOutput readSource getISOlist -#' @importFrom magclass mbind #' @importFrom quitte madrat_mule -#' @importFrom purrr map reduce #' @importFrom rlang .data .env sym syms #' @importFrom tidyr nest pivot_longer unnest @@ -35,7 +32,7 @@ calcIndustry_EEK <- function(kap) { subtype = 'Chinese_Steel_Production', convert = FALSE) %>% madrat_mule(), - aggregate = FALSE, years = base_year, supplementary = FALSE) %>% + aggregate = FALSE, years = base_year, supplementary = FALSE, warnNA = FALSE) %>% `[`(,,'gdp_SSP2EU') %>% quitte::magclass_to_tibble() %>% select('iso3c', subsector = 'name', VA = 'value') %>% @@ -234,7 +231,7 @@ calcIndustry_EEK <- function(kap) { # depreciation limit, as it has already been processed. reduce() returns # only the last row of the computation, so we get one output row for each # of the input rows. - reduce( + purrr::reduce( .f = function(x, y) { bind_rows(x, y) %>% group_by(.data$iso3c, .data$scenario, .data$subsector) %>% @@ -268,7 +265,7 @@ calcIndustry_EEK <- function(kap) { group_by(.data$year2) %>% nest() %>% pull(.data$data) %>% - reduce( + purrr::reduce( .f = function(x, y) { bind_rows(x, y) %>% group_by(.data$iso3c, .data$scenario, .data$subsector) %>% diff --git a/R/calcJRC_IDEES.R b/R/calcJRC_IDEES.R index 4bc304da..cfdd1e64 100644 --- a/R/calcJRC_IDEES.R +++ b/R/calcJRC_IDEES.R @@ -12,8 +12,6 @@ #' #' #' @importFrom dplyr select mutate left_join -#' @importFrom madrat toolGetMapping toolCountryFill -#' @importFrom magclass as.magpie mbind mselect #' @importFrom rlang sym #' @importFrom stats aggregate @@ -72,7 +70,7 @@ calcJRC_IDEES <- function(subtype) { x <- aggregate(value ~ variable + region + year, x, sum) %>% as.magpie() %>% - toolCountryFill(fill = NA) + toolCountryFill(fill = NA, verbosity = 2) # fill smaller EU-countries with 0s to allow for aggregation of EU-region x[c("ALA", "FRO", "GIB", "GGY", "IMN", "JEY"),,] <- 0 diff --git a/R/calcKLWdamage.R b/R/calcKLWdamage.R new file mode 100644 index 00000000..f935b3c8 --- /dev/null +++ b/R/calcKLWdamage.R @@ -0,0 +1,29 @@ +#' write KLW damage parameters (from Kotz et al. 2024) into input data +#' they are country-specific and should not be aggregated to the regional level at all + +#' @author Franziska Piontek +#' @param subtype "beta1", "beta2", "maxGMT" +#' @return MAgPIE object of damage parameters for KLW damage function on country level and for 1000 boostrapping samples + +calcKLWdamage <- function(subtype) { + if (subtype == "beta1") { + output <- readSource("KLWdamage", subtype = "beta1") + description <- "first damage coefficient for KLW damages (linear temperature)" + # average weight + weight <- new.magpie(getRegions(output), getYears(output), getNames(output), fill = 1) + } else if (subtype == "beta2") { + output <- readSource("KLWdamage", subtype = "beta2") + description <- "second damage coefficient for KLW damages (temperature squared)" + # average weight + weight <- new.magpie(getRegions(output), getYears(output), getNames(output), fill = 1) + } else if (subtype == "maxGMT") { + output <- readSource("KLWdamage", subtype = "maxGMT") + description <- "KLW damage: maximum GMT change for countries for which the KLW damage estimate is valid" + # average weight + weight <- new.magpie(getRegions(output), getYears(output), getNames(output), fill = 1) + } + return(list(x = output, + weight = weight, + unit = "dimensionless", + description = description)) +} diff --git a/R/calcLimitCCS.R b/R/calcLimitCCS.R index 6f40448b..f456165b 100644 --- a/R/calcLimitCCS.R +++ b/R/calcLimitCCS.R @@ -1,24 +1,26 @@ - -calcLimitCCS <- function(){ - +calcLimitCCS <- function() { # Read capacity factor inputs - data <- readSource("REMIND_11Regi",subtype="ccs") + data <- readSource("REMIND_11Regi", subtype = "ccs") # add dimensions that are the same for all regions but a dimension of the parameter in the GAMS code getNames(data) <- "quan" - data <- add_dimension(data, dim=3.2, add="rlf",nm="1") - + data <- add_dimension(data, dim = 3.2, add = "rlf", nm = "1") + # overwrite values for regions that belong to EUR and NEU data_ccs_storage_potential <- readSource("CCS_StoragePotential") - eur.34 <- c("ALA","AUT","BEL","BGR","HRV","CYP","CZE","DNK","EST","FRO","FIN","FRA","DEU","GIB","GRC","GGY","HUN","IRL","IMN","ITA","JEY","LVA","LTU","LUX","MLT","NLD","POL","PRT","ROU","SVK","SVN","ESP","SWE","GBR") - non.eu <- c('ALB','AND','BIH','GRL','VAT','ISL','LIE','MKD','MCO','MNE','NOR','SMR','SRB','SJM','CHE','TUR') - overwrite <- c(eur.34,non.eu) - data[overwrite,,] <- data_ccs_storage_potential[overwrite,,] - - return(list(x = data, - weight = NULL, - unit ="GtC", - description ="maximum CO2 storage capacity using CCS technology" + eur.34 <- c("ALA", "AUT", "BEL", "BGR", "HRV", "CYP", "CZE", "DNK", "EST", "FRO", + "FIN", "FRA", "DEU", "GIB", "GRC", "GGY", "HUN", "IRL", "IMN", "ITA", + "JEY", "LVA", "LTU", "LUX", "MLT", "NLD", "POL", "PRT", "ROU", "SVK", + "SVN", "ESP", "SWE", "GBR") + non.eu <- c("ALB", "AND", "BIH", "GRL", "VAT", "ISL", "LIE", "MKD", "MCO", "MNE", + "NOR", "SMR", "SRB", "SJM", "CHE", "TUR") + overwrite <- c(eur.34, non.eu) + data[overwrite, , ] <- data_ccs_storage_potential[overwrite, , ] + + return(list( + x = data, + weight = NULL, + unit = "GtC", + description = "maximum CO2 storage capacity using CCS technology" )) - } diff --git a/R/calcMACCbaseN2O.R b/R/calcMACCbaseN2O.R index e827bc72..709d6fbd 100644 --- a/R/calcMACCbaseN2O.R +++ b/R/calcMACCbaseN2O.R @@ -1,4 +1,3 @@ -#' @importFrom magclass getNames calcMACCbaseN2O <- function() { diff --git a/R/calcMACCsCO2.R b/R/calcMACCsCO2.R index c93c9ad2..60d9ed52 100644 --- a/R/calcMACCsCO2.R +++ b/R/calcMACCsCO2.R @@ -10,7 +10,6 @@ #' calcOutput("MACCsCO2") #' #' } -#' @importFrom magclass getNames calcMACCsCO2 <- function() { x <- readSource("MAgPIE", subtype = "abatparam_co2",convert=FALSE) diff --git a/R/calcMacroInvestments.R b/R/calcMacroInvestments.R index f712b215..423c8328 100644 --- a/R/calcMacroInvestments.R +++ b/R/calcMacroInvestments.R @@ -1,26 +1,25 @@ -#' @importFrom madrat toolFillWithRegionAvg - calcMacroInvestments <- function() { - - # read in investment share - shInv <- readSource("PWT")[,2005,"csh_i"] + # read in investment share + shInv <- readSource("PWT")[, 2005, "csh_i"] # read in gdp - gdp <- calcOutput("GDP",aggregate=FALSE)[,2005,"gdp_SSP2"] - + gdp <- calcOutput("GDP", aggregate = FALSE)[, 2005, "gdp_SSP2"] + # BS 01-03-2019: updated to use new toolFillWithRegionAvg function shInv_new <- toolFillWithRegionAvg(shInv, valueToReplace = 0, weight = gdp) - + # # calculate macro investments data <- shInv_new * gdp - + # convert unit data <- data / 1000000 - - getYears(data) <- NULL - getNames(data) <- NULL - - return(list(x = data, - weight = NULL, - unit = "trillion 2005US$", - description = "Investments in the macro-economic capital stock at constant 2005 national prices")) + + getYears(data) <- NULL + getNames(data) <- NULL + + return(list( + x = data, + weight = NULL, + unit = "trillion 2005US$", + description = "Investments in the macro-economic capital stock at constant 2005 national prices" + )) } diff --git a/R/calcNetForeignAsset.R b/R/calcNetForeignAsset.R index 028d2cc9..a6ba1008 100644 --- a/R/calcNetForeignAsset.R +++ b/R/calcNetForeignAsset.R @@ -1,25 +1,26 @@ +calcNetForeignAsset <- function() { + # Read in Current account balance from the IMF WEO + x <- readSource("IMF")[, , "Current account balance [Billions U.S. dollars]"] + ### Allocate global current account to the countries + # Calculate global sum which is not 0 + xSum <- -dimSums(x, dim = 1, na.rm = TRUE) + # Calculate global absolute share of current account + xShare <- abs(x) / dimSums(abs(x), dim = 1, na.rm = TRUE) + # Calculate additional value for each country + xRest <- xShare * xSum + # Add global rest to the countries + x <- x + xRest + # Sum over the years until 2005 + x <- dimSums(x[, getYears(x, as.integer = TRUE) <= 2005, ], dim = 2) -calcNetForeignAsset <- function() { - - # read data - x <- readSource("IMF") - - # filter all data until 2005 - x <- x[,getYears(x,as.integer=TRUE)<=2005,] - # sum over years - x <- dimSums(x,dim=2) - - # delete dimensions that are same and not in the GAMS-code + # Delete dimensions that are same and not in the GAMS-code getNames(x) <- NULL getYears(x) <- NULL - - # convert billion into trilllion + + # Convert billion into trillion x <- x / 1000 - - return(list(x = x, - weight = NULL, - unit = "trillion U.S. dollar", - description = "net foreign asset")) + + list(x = x, weight = NULL, unit = "trillion current US$MER", description = "Net foreign asset") } diff --git a/R/calcOtherFossilInElectricity.R b/R/calcOtherFossilInElectricity.R index 64d74d32..f8abd220 100644 --- a/R/calcOtherFossilInElectricity.R +++ b/R/calcOtherFossilInElectricity.R @@ -17,7 +17,6 @@ #' #' @seealso [`calcOutput()`] #' -#' @importFrom magclass new.magpie getItems time_interpolate magpiesort #' @export #' diff --git a/R/calcPE.R b/R/calcPE.R index d347cb72..ecde6517 100644 --- a/R/calcPE.R +++ b/R/calcPE.R @@ -45,7 +45,7 @@ calcPE <- function(subtype = "IEA", ieaVersion = "default") { x <- mbind(x, setNames(dimSums(x[, , "PE|Gas", pmatch = TRUE], dim = 3), "PE|Gas (EJ/yr)")) x <- mbind(x, setNames(dimSums(x[, , "PE|Biomass", pmatch = TRUE], dim = 3), "PE|Biomass (EJ/yr)")) - ieaYear <- if (ieaVersion == "default") 2022 else 2023 + ieaYear <- if (ieaVersion == "default") 2022 else 2024 return(list(x = x, weight = NULL, unit = "EJ", description = paste0("IEA Primary Energy Data based on ", ieaYear, diff --git a/R/calcPlasticsEoL.R b/R/calcPlasticsEoL.R index da28a288..969fc775 100644 --- a/R/calcPlasticsEoL.R +++ b/R/calcPlasticsEoL.R @@ -10,8 +10,6 @@ #' @seealso [`calcOutput()`] #' #' @importFrom dplyr filter pull select -#' @importFrom madrat getISOlist toolFillYears -#' @importFrom magclass new.magpie getItems #' @importFrom rlang .data #' @importFrom tibble as_tibble #' @importFrom quitte calc_addVariable @@ -68,9 +66,10 @@ calcPlasticsEoL <- function() { ", units = "fraction", only.new = TRUE ) %>% - # remove unused dimensions + # remove unused dimensions select(-"model", -"scenario", -"variable", -"unit") %>% - interpolate_missing_periods(seq(2050, 2060, 5), method = "linear") + interpolate_missing_periods(seq(2050, 2060, 5), method = "linear") %>% + suppressWarnings() # as magpie x <- as.magpie(incinerationShares) @@ -86,10 +85,9 @@ calcPlasticsEoL <- function() { xNew[, c(seq(2110, 2150, 20)), ] <- x[, 2100, ] x <- mbind(x, xNew) %>% - toolCountryFill(fill = 0) %>% + toolCountryFill(fill = 0, verbosity = 2) %>% collapseDim() - # create weights ---- fe <- calcOutput("FE", source = "IEA", aggregate = FALSE)[, 2016, "FE (EJ/yr)"] diff --git a/R/calcPotentialGeothermal.R b/R/calcPotentialGeothermal.R index 30c9862d..23a29f52 100644 --- a/R/calcPotentialGeothermal.R +++ b/R/calcPotentialGeothermal.R @@ -13,7 +13,6 @@ #' #' } #' -#' @importFrom magclass setNames calcPotentialGeothermal <- function() { diff --git a/R/calcPotentialHydro.R b/R/calcPotentialHydro.R index a76be25a..6684b5d1 100644 --- a/R/calcPotentialHydro.R +++ b/R/calcPotentialHydro.R @@ -15,7 +15,6 @@ #' #' } #' -#' @importFrom magclass setNames calcPotentialHydro <- function() { @@ -30,10 +29,10 @@ calcPotentialHydro <- function() { # # prodElec <- wgbu[,,"Erzeugter Strom(GWh/a)"] / 1000 prodElec <- readSource("IRENA","Generation") - prodElec <- prodElec[,2015,"Hydropower"] / 1000 + prodElec <- prodElec[,2015,"Renewable hydropower"] / 1000 IRENA_hydro_cap <- readSource("IRENA","Capacity") # in MW - IRENA_hydro_cap <- IRENA_hydro_cap[,2015,"Hydropower"] + IRENA_hydro_cap <- IRENA_hydro_cap[,2015,"Renewable hydropower"] # ensure that overall potential can produce the generation of 2015, if not set potential to IRENA 2015 generation checkDiff <- new.magpie(getRegions(techPot),NULL,fill = 0) @@ -219,12 +218,13 @@ calcPotentialHydro <- function() { data["SWE",,"maxprod"] <- data["SWE",,"maxprod"]*1.05 data["DEU",,"maxprod"] <- data["DEU",,"maxprod"]*1.05 - data["CZE",,"maxprod"] <- data["CZE",,"maxprod"]*1.05 - data["EST",,"maxprod"] <- data["EST",,"maxprod"]*1.05 - data["LVA",,"maxprod"] <- data["LVA",,"maxprod"]*1.05 - data["LTU",,"maxprod"] <- data["LTU",,"maxprod"]*1.05 - data["POL",,"maxprod"] <- data["POL",,"maxprod"]*1.05 - data["SVK",,"maxprod"] <- data["SVK",,"maxprod"]*1.05 + # AO: Increase hydro potential in ECE region to avoid infeasibilities + data["CZE",,"maxprod"] <- data["CZE",,"maxprod"]*1.3 + data["EST",,"maxprod"] <- data["EST",,"maxprod"]*1.3 + data["LVA",,"maxprod"] <- data["LVA",,"maxprod"]*1.3 + data["LTU",,"maxprod"] <- data["LTU",,"maxprod"]*1.3 + data["POL",,"maxprod"] <- data["POL",,"maxprod"]*1.3 + data["SVK",,"maxprod"] <- data["SVK",,"maxprod"]*1.3 return(list(x = data, weight = w, diff --git a/R/calcPotentialWindOff.R b/R/calcPotentialWindOff.R index c98d1e24..7fabd4ac 100644 --- a/R/calcPotentialWindOff.R +++ b/R/calcPotentialWindOff.R @@ -14,7 +14,6 @@ #' calcOutput("PotentialWindOff") #' #' } -#' @importFrom magclass getNames calcPotentialWindOff <- function() { # read wind data diff --git a/R/calcPotentialWindOn.R b/R/calcPotentialWindOn.R index fdfb2db0..dfa5403d 100644 --- a/R/calcPotentialWindOn.R +++ b/R/calcPotentialWindOn.R @@ -14,7 +14,6 @@ #' calcOutput("PotentialWindOn") #' #' } -#' @importFrom magclass getNames calcPotentialWindOn <- function() { # read wind onshore data diff --git a/R/calcProjectPipelines.R b/R/calcProjectPipelines.R new file mode 100644 index 00000000..b25eb0fb --- /dev/null +++ b/R/calcProjectPipelines.R @@ -0,0 +1,265 @@ +#' calc Project Pipelines +#' +#' Calculate the expected near-term deployment of technologies based on +#' projects that are currently either being built or in a planning stage +#' for some technologies multiple sources are available +#' +#' @author Pascal Weigmann +#' +#' @param subtype choose technology `biomass`, `coal`, `geothermal`, `hydro`, +#' `nuclear`, `solar`, `wind` or `CCS` +#' +#' @export +calcProjectPipelines <- function(subtype) { + # CCS #### + # Discussion about CCS assumptions + # https://gitlab.pik-potsdam.de/REMIND/committed/-/issues/1 + if (subtype == "CCS") { + + x <- readSource("IEA_CCUS", subtype = "pipeline") + + # take away 50% of capacities from Norway and UK and shift to EUR + x[c("NOR", "GBR"), , ] <- x[c("NOR", "GBR"), , ] * 0.5 + + mapping <- toolGetMapping("extramapping_EU27.csv", + where = "mappingfolder", type = "regional") %>% + filter(.data$EU27_map == "EU27") + eu27 <- unique(mapping$CountryCode) + + # sum up EU27 capacities and add half of Norway / UK capacities + eu27Pool <- + dimSums(x[eu27, , ], dim = 1) + dimSums(x[c("NOR", "GBR"), , ], dim = 1) + getItems(eu27Pool, dim = 1) <- "EU27" + + # distribute EU27 pool to the countries according to GDP + gdp <- calcOutput("GDP", aggregate = FALSE)[eu27, 2020, "gdp_SSP2EU"] + eu27Pool <- toolAggregate(eu27Pool, + rel = mapping, weight = gdp, + from = "EU27_map", to = "CountryCode") + x[eu27, , ] <- eu27Pool + + # ASSUMPTION: no projects are under way in Brasil which means all thresholds are equal + # to avoid this, add manually an upper estimate of what could still be planned in BRA + x["BRA", 2025:2029, "Carbon Management|Storage.planned"] <- + x["BRA", 2025:2029, "Carbon Management|Storage.planned"] + 2 + x["BRA", 2030, "Carbon Management|Storage.planned"] <- + x["BRA", 2030, "Carbon Management|Storage.planned"] + 10 + + + # formulation of upper and lower bounds for the near-term validation + x <- mbind( + x, + # ASSUMPTION: min_red = operational + setNames(x[, , "Carbon Management|Storage.operational"], + "Carbon Management|Storage.min_red"), + + # ASSUMPTION: min_yel = operational + 0.5*construction + setNames(x[, , "Carbon Management|Storage.operational"] + + x[, , "Carbon Management|Storage.construction"]*0.5, + "Carbon Management|Storage.min_yel"), + + # ASSUMPTION: max_yel = operational + construction + 0.3*planned + setNames(x[, , "Carbon Management|Storage.operational"] + + x[, , "Carbon Management|Storage.construction"] + + x[, , "Carbon Management|Storage.planned"]*0.3, + "Carbon Management|Storage.max_yel"), + + # ASSUMPTION: max_red = operational + construction + planned + setNames(x[, , "Carbon Management|Storage.operational"] + + x[, , "Carbon Management|Storage.construction"] + + x[, , "Carbon Management|Storage.planned"], + "Carbon Management|Storage.max_red")) + + # meta data + x <- add_dimension(x, dim = 3.1, add = "model", nm = "IEA CCUS") + x <- add_dimension(x, dim = 3.4, add = "unit", nm = "MtCO2/yr") + unit <- "MtCO2/yr" + description <- "CCS project pipeline from IEA CCUS project database" + + # Hydro #### + # Discussion about Hydro assumptions + # https://gitlab.pik-potsdam.de/REMIND/committed/-/issues/2 + } else if (subtype == "hydro") { + # Source 1: GEM + # -> does not include units < 75MW + # without pumped storage + x <- readSource("GlobalEnergyMonitor") + x <- x[, , "Hydro", pmatch = T] + + x <- mbind(x, + # ASSUMPTION: min_red = operating + setNames(x[, , "operating"], + "GlobalEnergyMonitor.Cap|Electricity|Hydro.min_red.GW"), + + # ASSUMPTION: min_yel = operating + 0.5*construction + 0.2*pre-construction + setNames(x[, , "operating"] + + x[, , "construction"]*0.5 + + x[, , "pre-construction"]*0.2, + "GlobalEnergyMonitor.Cap|Electricity|Hydro.min_yel.GW"), + + # ASSUMPTION: max_yel = operating + construction + 0.8*pre-construction + 0.3*announced + setNames(x[, , "operating"] + + x[, , "construction"] + + x[, , "pre-construction"]*0.8 + + x[, , "announced"]*0.3, + "GlobalEnergyMonitor.Cap|Electricity|Hydro.max_yel.GW"), + + # ASSUMPTION: max_red = operating + construction + pre-construction + announced + setNames(x[, , "operating"] + + x[, , "construction"] + + x[, , "pre-construction"] + + x[, , "announced"], + "GlobalEnergyMonitor.Cap|Electricity|Hydro.max_red.GW") + ) + + # Source 2: IEA Hydropower Special Market Report + # no access to granular data, only scraping online data explorer, + # only 2030 available: scenarios "expected" and "accelerated case" + # "operational" corresponds to existing capacities in 2020 + # without pumped storage (accelerated case has no differentiation, + # assume pumped storage equally to expected case) + y <- readSource("IEA_HSMR") + + y <- mbind(y, + # ASSUMPTION: min_red = operating in 2020 + setNames(y[, , "operational"], + "IEA_HSMR.Cap|Electricity|Hydro.min_red.GW"), + + # ASSUMPTION: min_yel = expected case + setNames(y[, , "expected"], + "IEA_HSMR.Cap|Electricity|Hydro.min_yel.GW"), + + # ASSUMPTION: max_yel = accelerated case + setNames(y[, , "accelerated"], + "IEA_HSMR.Cap|Electricity|Hydro.max_yel.GW") + + # ASSUMPTION: max_red = accelerated case + ? + # setNames(x[, , "operating"] + + # x[, , "construction"] + + # x[, , "pre-construction"] + + # x[, , "announced"], + # "IEA_HSMR.Cap|Electricity|Hydro.max_red.GW") + ) + + # add empty 2025 column, so IEA and GEM data can be merged + y <- add_columns(y, addnm = "y2025", dim = 2, fill= NA) + + x <- mbind(x, y) + + + # meta data + unit <- "GW" + description <- "Hydro project pipeline from GEM and IEA" + + # TODO: coming up next + + # Biomass #### + # } else if (subtype == "biomass") { + # x <- readSource("GlobalEnergyMonitor") + # x <- x[, , "Biomass", pmatch = T] + # + # + # # meta data + # unit <- "GW" + # description <- "Biomass project pipeline from GEM" + # + # # Nuclear #### + # } else if (subtype == "nuclear") { + # x <- readSource("GlobalEnergyMonitor") + # x <- x[, , "Nuclear", pmatch = T] + # + # + # + # # meta data + # unit <- "GW" + # description <- "Nuclear project pipeline from GEM" + # + # # Coal #### + # } else if (subtype == "coal") { + # x <- readSource("GlobalEnergyMonitor") + # x <- x[, , "Coal", pmatch = T] + # + # + # + # # meta data + # unit <- "GW" + # description <- "Coal project pipeline from GEM" + # + # # Geothermal #### + # } else if (subtype == "geothermal") { + # x <- readSource("GlobalEnergyMonitor") + # x <- x[, , "Geothermal", pmatch = T] + # + # + # + # # meta data + # unit <- "GW" + # description <- "Geothermal project pipeline from GEM" + # Solar #### + } else if (subtype == "solar") { + x <- readSource("GlobalEnergyMonitor") + x <- x[, , "Solar", pmatch = T] + + # TODO: PV/CSP differentiation + # lower bounds only, as solar can be built quickly + x <- mbind(x, + # ASSUMPTION: min_red = operating + setNames(x[, , "Cap|Electricity|Solar.operating"], + "GlobalEnergyMonitor.Cap|Electricity|Solar.min_red.GW"), + + # ASSUMPTION: min_yel = operating + 0.5*construction + 0.2*pre-construction + setNames(x[, , "Cap|Electricity|Solar.operating"] + + x[, , "Cap|Electricity|Solar.construction"]*0.5 + + x[, , "Cap|Electricity|Solar.pre-construction"]*0.2, + "GlobalEnergyMonitor.Cap|Electricity|Solar.min_yel.GW") + ) + + # meta data + unit <- "GW" + description <- "Solar project pipeline from GEM" + + # Wind #### + } else if (subtype == "wind") { + x <- readSource("GlobalEnergyMonitor") + x <- x[, , "Wind", pmatch = T] + + # TODO: On/Offshore differentiation + x <- mbind(x, + # ASSUMPTION: min_red = operating + setNames(x[, , "Cap|Electricity|Wind.operating"], + "GlobalEnergyMonitor.Cap|Electricity|Wind.min_red.GW"), + + # ASSUMPTION: min_yel = operating + 0.5*construction + 0.2*pre-construction + setNames(x[, , "Cap|Electricity|Wind.operating"] + + x[, , "Cap|Electricity|Wind.construction"]*0.5 + + x[, , "Cap|Electricity|Wind.pre-construction"]*0.2, + "GlobalEnergyMonitor.Cap|Electricity|Wind.min_yel.GW"), + + # ASSUMPTION: max_yel = operating + construction + 0.8*pre-construction + 0.3*announced + setNames(x[, , "Cap|Electricity|Wind.operating"] + + x[, , "Cap|Electricity|Wind.construction"] + + x[, , "Cap|Electricity|Wind.pre-construction"]*0.8 + + x[, , "Cap|Electricity|Wind.announced"]*0.3, + "GlobalEnergyMonitor.Cap|Electricity|Wind.max_yel.GW"), + + # ASSUMPTION: max_red = operating + construction + pre-construction + announced + setNames(x[, , "Cap|Electricity|Wind.operating"] + + x[, , "Cap|Electricity|Wind.construction"] + + x[, , "Cap|Electricity|Wind.pre-construction"] + + x[, , "Cap|Electricity|Wind.announced"], + "GlobalEnergyMonitor.Cap|Electricity|Wind.max_red.GW") + ) + + # meta data + unit <- "GW" + description <- "Wind project pipeline from GEM" + + } + + return(list( + x = x, + unit = unit, + weight = NULL, + description = description + )) + } diff --git a/R/calcRegion2MAGICC.R b/R/calcRegion2MAGICC.R index 0ae3eebe..073cee6a 100644 --- a/R/calcRegion2MAGICC.R +++ b/R/calcRegion2MAGICC.R @@ -1,25 +1,23 @@ -#' @importFrom dplyr %>% - calcRegion2MAGICC <- function() { - + # read in data used as weight w <- readSource("EDGAR",subtype="SO2") # sum over all types w <- dimSums(w,dim=3) getSets(w)[1] <- "region" - + # read in regional mapping map <- toolGetMapping(type = "regional", name = "regionmappingRCP.csv", where = "mappingfolder") map$RegionCode <- paste0("R5",map$RegionCode) - + # make magpie-objects in the right dimension x <- new.magpie(getRegions(w),getYears(w),unique(map$RegionCode),fill=0) for(i in 1:length(map$CountryCode)) { x[map$CountryCode[i],,map$RegionCode[i]] <- 1 } - + getYears(x) <- NULL - + return(list(x=x,weight=w,unit="Percent", description="percentage of REMIND-region that is allocated to R5-Regions, weighted by EDGAR-SO2-data")) } diff --git a/R/calcRiskPremium.R b/R/calcRiskPremium.R index 0f645d03..8cd4a219 100644 --- a/R/calcRiskPremium.R +++ b/R/calcRiskPremium.R @@ -1,23 +1,19 @@ - - - calcRiskPremium <- function() { - - # read data - x <- readSource("OECD",subtype = "riskClass") - - # convert into percent + # Read risk class data from OECD + x <- readSource("OECD") + + # Convert into percent x <- x / 100 - - # delete dimensions that are same and not in the GAMS-code + + # Delete dimensions that are same and not in the GAMS-code getNames(x) <- NULL getYears(x) <- NULL - - # use GDP as weight - w <- calcOutput("GDP",aggregate=FALSE)[,2005,"gdp_SSP2"] - - return(list(x = x, - weight = w, - unit = "dimensionless", - description = "risk premium that lowers the use of capital imports")) + + # Use GDP as weight + w <- calcOutput("GDP", aggregate = FALSE)[, 2005, "gdp_SSP2"] + + list(x = x, + weight = w, + unit = "Dimensionless", + description = "Risk premium that lowers the use of capital imports") } diff --git a/R/calcSharedTarget.R b/R/calcSharedTarget.R index 74b78f9f..0053905f 100644 --- a/R/calcSharedTarget.R +++ b/R/calcSharedTarget.R @@ -5,42 +5,42 @@ #' @return target data magpie object #' @author Renato Rodrigues #' @examples -#' -#' \dontrun{ +#' +#' \dontrun{ #' calcOutput("SharedTarget",subtype="FErenewablesShare") #' } -#' +#' calcSharedTarget <- function(subtype){ - + if (subtype == "FErenewablesShare") { - + description <- "Lower bound on renewables share" unit <- "percentage (e.g. 0.2 for 20%)" - + # determine European renewables targets EURcountries <-c("ALA","AUT","BEL","BGR","CYP","CZE","DEU","DNK","ESP","EST","FIN","FRA","FRO","GBR","GGY","GIB","GRC","HRV","HUN","IMN","IRL","ITA","JEY","LTU","LUX","LVA","MLT","NLD","POL","PRT","ROU","SVK","SVN","SWE") years <- c(seq(2030,2060,5),seq(2070,2110,10), 2130, 2150) # apply targets to REMIND years from 2030 on EURTarget <- 0.32 + (years-2030)*0.005 # set renewables target based on the EU Energy and Climate package for 2030, with 2018 Agreement update - EURTarget[which(EURTarget>0.75)] <- 0.75 # set maximum target to 75% + EURTarget[which(EURTarget>0.75)] <- 0.75 # set maximum target to 75% names(EURTarget) <- years # create magpie object with targets out <- new.magpie(cells_and_regions = EURcountries,years = years, names = "FErenewablesShare") for (year in years) out[,year,] <- EURTarget[as.character(year)] - out <- toolCountryFill(out, fill = 0) # fill other countries with zero as target + out <- toolCountryFill(out, fill = 0, verbosity = 2) # fill other countries with zero as target getNames(out) <- NULL # weight weight <- new.magpie(cells_and_regions = getRegions(out),years = getYears(out), names = getNames(out), fill=1) - + } else { stop("Not a valid subtype!") } - + #Returning capacity values return(list(x=out, weight=weight, - unit=unit, - description=description - )) + unit=unit, + description=description + )) } diff --git a/R/calcSolar.R b/R/calcSolar.R index d2e912b9..5605f728 100644 --- a/R/calcSolar.R +++ b/R/calcSolar.R @@ -12,7 +12,6 @@ #' #' #' @importFrom utils head -#' @importFrom magclass where calcSolar <- function() { diff --git a/R/calcSteelStock.R b/R/calcSteelStock.R index a91063bd..5a8d4fa1 100644 --- a/R/calcSteelStock.R +++ b/R/calcSteelStock.R @@ -5,7 +5,7 @@ #' #' @author Falk Benke #' -#' @importFrom dplyr filter select mutate left_join %>% +#' @importFrom dplyr filter select mutate left_join #' @export calcSteelStock <- function() { diff --git a/R/calcStorageFactor.R b/R/calcStorageFactor.R index 6082ee4f..c73949c9 100644 --- a/R/calcStorageFactor.R +++ b/R/calcStorageFactor.R @@ -5,39 +5,38 @@ #' @author Lavinia Baumstark #' @seealso \code{\link{calcOutput}} #' @examples -#' -#' \dontrun{ +#' \dontrun{ #' calcOutput("StorageFactor") #' } -#' - -calcStorageFactor <- function(){ - +#' +calcStorageFactor <- function() { # Read storage factor inputs - x <- readSource("REMIND_11Regi", subtype="storageFactor") + x <- readSource("REMIND_11Regi", subtype = "storageFactor") getSets(x)[3] <- "all_te" - + # read in weight data # for solar - w1_tmp <- calcOutput("Solar",aggregate=FALSE) - w1 <- dimSums(w1_tmp[,,"area"][,,"PV"][,,c("0-50","50-100")], dim=c(3.4,3.3)) + w1_tmp <- calcOutput("Solar", aggregate = FALSE) + w1 <- dimSums(w1_tmp[, , "area"][, , "PV"][, , c("0-50", "50-100")], dim = c(3.4, 3.3)) w1 <- collapseNames(w1) - getNames(w1) <- c("spv") - w1 <- mbind(w1,setNames(w1,"csp")) + getNames(w1) <- c("spv") + w1 <- mbind(w1, setNames(w1, "csp")) # for wind - w2 <- calcOutput("PotentialWindOn",aggregate=FALSE) - w2 <- collapseNames(dimSums(w2, dim=3)) + w2 <- calcOutput("PotentialWindOn", aggregate = FALSE) + w2 <- collapseNames(dimSums(w2, dim = 3)) getSets(w2)[1] <- getSets(w1)[1] getSets(w2)[2] <- getSets(w1)[2] - getNames(w2) <- "wind" - getYears(w2) <- getYears(w1) + getNames(w2) <- "wind" + getYears(w2) <- getYears(w1) # combile all weights - w <- mbind(w1,w2) - - return(list(x = x, - weight = w, - unit = "% of capacity", - description = "multiplicative factor that scales total curtailment and storage requirements up or down in different regions for different technologies" + w <- mbind(w1, w2) + + return(list( + x = x, + weight = w, + unit = "% of capacity", + description = paste0("multiplicative factor that scales total curtailment and ", + "storage requirements up or down in different regions for ", + "different technologies") )) - } diff --git a/R/calcTaxConvergence.R b/R/calcTaxConvergence.R index e86ee967..c595216e 100644 --- a/R/calcTaxConvergence.R +++ b/R/calcTaxConvergence.R @@ -4,22 +4,19 @@ #' @return magpie object of the tax convergence levels #' @author Renato Rodrigues #' @examples -#' -#' \dontrun{ +#' \dontrun{ #' calcOutput("TaxConvergence") #' } -#' - -calcTaxConvergence <- function(){ - +#' +calcTaxConvergence <- function() { # Read tax convergence levels at specific year and final energy type - taxConvergence <- readSource("REMIND_11Regi", subtype="taxConvergence") + taxConvergence <- readSource("REMIND_11Regi", subtype = "taxConvergence") # average weight - w <- new.magpie(getRegions(taxConvergence),getYears(taxConvergence),getNames(taxConvergence),fill=1) + w <- new.magpie(getRegions(taxConvergence), getYears(taxConvergence), getNames(taxConvergence), fill = 1) # Return tax convergence levels aggregated to selected REMIND regions - return(list(x=taxConvergence, weight=w, - unit="$/GJ", - description="Tax convergence level for specific regions, year and final energy type" + return(list( + x = taxConvergence, weight = w, + unit = "$/GJ", + description = "Tax convergence level for specific regions, year and final energy type" )) - } diff --git a/R/calcTaxXport.R b/R/calcTaxXport.R index 92ad326d..b662553e 100644 --- a/R/calcTaxXport.R +++ b/R/calcTaxXport.R @@ -1,12 +1,13 @@ calcTaxXport <- function() { - x <- readSource("REMIND_11Regi", subtype="xpres_tax") - - weight <- new.magpie(getRegions(x),getYears(x),getNames(x),fill=1) # or use export, from IEA? - - x <- time_interpolate(x,c(seq(2010,2150,5)),extrapolation_type="constant",integrate_interpolated_years=TRUE) - - return(list(x=x,weight=weight, - unit="$/GJ", - description="resource export taxes, not used in default settings." + x <- readSource("REMIND_11Regi", subtype = "xpres_tax") + + weight <- new.magpie(getRegions(x), getYears(x), getNames(x), fill = 1) # or use export, from IEA? + + x <- time_interpolate(x, c(seq(2010, 2150, 5)), extrapolation_type = "constant", integrate_interpolated_years = TRUE) + + return(list( + x = x, weight = weight, + unit = "$/GJ", + description = "resource export taxes, not used in default settings." )) } diff --git a/R/calcTheil.R b/R/calcTheil.R index b8731756..e8dba0c8 100644 --- a/R/calcTheil.R +++ b/R/calcTheil.R @@ -1,12 +1,9 @@ #' Calculate regional Theil-T index #' - -#' To calculate the regional Theil-T index (= correction to welfare function for -#' a lognormal income distribution) we do the following: -#' (1) convert country-level Gini coefficients to Theil (2) calculate contribution -#' to Theil-T index that includes both between-countries and within-country inequality -#' (see e.g. https://en.wikipedia.org/wiki/Theil_index). The latter can then be -#' aggregated with calcOutput(). +#' To calculate the regional Theil-T index (= correction to welfare function for a lognormal income distribution) we do +#' the following: (1) convert country-level Gini coefficients to Theil (2) calculate contribution to Theil-T index that +#' includes both between-countries and within-country inequality (see e.g. https://en.wikipedia.org/wiki/Theil_index). +#' The latter can then be aggregated with calcOutput(). #' #' NB 1: the aggregation depends on the region mapping. It is implemented such #' that the regionmapping specified in getConfig()$regionmapping is used. @@ -14,88 +11,59 @@ #' NB 2: the result of calcOutput('Theil', aggregate = FALSE), is NOT the country #' Theil-T, but the unweighted contribution from a given country to the regional value. #' -#' @return magpie objects of unweighted contribution to Theil, -#' weights (= country shares of regional GDP), docstring +#' @return magpie objects of unweighted contribution to Theil, weights (= country shares of regional GDP) #' @author Bjoern Soergel #' @seealso \code{\link{calcOutput}} \code{\link{convertGini},\link{readGini}} #' @examples #' \dontrun{ -#' a <- calcOutput("Theil") +#' calcOutput("Theil") #' } #' -#' @importFrom stats qnorm - calcTheil <- function() { - - ## helper functions. - TheilT.from.sigma <- function(sigma) { - # Theil T coefficient for lognormal distribution - TheilT <- sigma^2 / 2. - return(TheilT) - } - - sigma.from.Gini <- function(G) { - # assuming lognormal distribution: convert Gini to sigmas - sigma <- sqrt(2) * qnorm((G + 1) / 2) - return(sigma) - } - - # Gini and Theil + # Read Gini Gini <- readSource("Gini") - years <- getYears(Gini) - TheilT <- TheilT.from.sigma(sigma.from.Gini(Gini)) - # population (in 1e6) - pop <- calcOutput(type = "Population", aggregate = FALSE) - sspnames <- c(paste0("SSP", 1:5), "SDP", "SSP2EU") - pop <- pop[, years, paste0("pop_", sspnames)] - getNames(pop) <- sspnames - getSets(pop) <- c("iso3c", "year", "scenario") + # Convert Gini to sigmas assuming lognormal distribution + sigma <- sqrt(2) * stats::qnorm((Gini + 1) / 2) + # Theil T coefficient for lognormal distribution + TheilT <- sigma^2 / 2 - # GDP (in million $ PPP 2005) - GDPppp <- calcOutput(type = "GDP", aggregate = FALSE) - GDPnames <- paste0("gdp_", sspnames) - GDPppp <- GDPppp[, years, GDPnames] - getNames(GDPppp) <- sspnames - getSets(GDPppp) <- c("iso3c", "year", "scenario") + # We need the GDP and GDP per capita scenarios, for the scenarios and years of Gini. + # We set extension2150 = "constant" because the Gini coefficients are also extended in the same way. + # As a regionmapping we use the one set in the config (which is the default behavior). The same is called explicitly + # later, as it is used in the calculations of the Theil contribution and weights. + s <- getNames(Gini) + y <- getYears(Gini) + gdp <- calcOutput("GDP", naming = "scenario", extension2150 = "constant", years = y, aggregate = FALSE)[, , s] + gdpReg <- calcOutput("GDP", naming = "scenario", extension2150 = "constant", years = y)[, , s] + gdppc <- calcOutput("GDPpc", naming = "scenario", extension2150 = "constant", years = y, aggregate = FALSE)[, , s] + gdppcReg <- calcOutput("GDPpc", naming = "scenario", extension2150 = "constant", years = y)[, , s] - # allocate empty objects for storing Theil contribution and weights - contribTheilT <- pop + # Allocate empty objects for storing Theil contribution and weights + contribTheilT <- TheilT contribTheilT[, , ] <- NA - s_i <- pop - s_i[, , ] <- NA - - # contribution to Theil index depends on region mapping. We always use the one specified in getConfig(). - regionmapping <- read.csv( - toolGetMapping( - type = "regional", name = getConfig()$regionmapping, - returnPathOnly = TRUE, where = "mappingfolder" - ), - sep = ";", colClasses = "character" - ) + weight <- TheilT + weight[, , ] <- NA - # GDP per capita - xbar_i <- GDPppp / pop - for (rr in unique(regionmapping$RegionCode)) { + # Compute Theil contribution and weights + regionmapping <- toolGetMapping(getConfig("regionmapping"), type = "regional", where = "mappingfolder") + for (rr in getRegions(gdppcReg)) { rrCountries <- regionmapping$CountryCode[regionmapping$RegionCode == rr] - # regional GDP per capita - GDPppp_rr <- dimSums(GDPppp[rrCountries, , ], dim = 1) - Ntot_rr <- dimSums(pop[rrCountries, , ], dim = 1) - xbar_rr <- GDPppp_rr / Ntot_rr - # contribution to Theil index (unweighted) - contribTheilT[rrCountries, , ] <- TheilT[rrCountries, , ] + log(xbar_i[rrCountries, , ] / xbar_rr) - # weights = income share of country i: - # s_i = N_i/N * xbar_i/xbar = GDP_i/GDP_rr # nolint - s_i[rrCountries, , ] <- GDPppp[rrCountries, , ] / GDPppp_rr - # sanity check: ensure that weights for a region sum to one (within floating point precision) - assertthat::assert_that(max(abs(dimSums(s_i[rrCountries, , ], dim = 1) - 1)) < 1e-10) + # Contribution to Theil index (unweighted) + contribTheilT[rrCountries, , ] <- TheilT[rrCountries, , ] + log(gdppc[rrCountries, , ] / gdppcReg[rr, , ]) + # Weights = country shares of regional GDP + weight[rrCountries, , ] <- gdp[rrCountries, , ] / gdpReg[rr, , ] + # Sanity check: ensure that weights for a region sum to one (within floating point precision) + stopifnot(max(abs(dimSums(weight[rrCountries, , ], dim = 1) - 1)) < 1e-10) } - # for easier REMIND integration use same names as GDP scenarios for Theil - # change this if we later want to test effect of per capita income growth vs. inequality - getNames(contribTheilT) <- GDPnames - getNames(s_i) <- GDPnames + # For easier REMIND integration use same names as GDP scenarios for Theil + # Change this if we later want to test effect of per capita income growth vs. inequality + getNames(contribTheilT) <- paste0("gdp_", getNames(contribTheilT)) + getNames(weight) <- paste0("gdp_", getNames(weight)) - return(list(x = contribTheilT, weight = s_i, unit = "-", - description = "aggregated: Theil-T index, not-aggregated: unweighted contribution to Theil-T")) + list(x = contribTheilT, + weight = weight, + unit = "-", + description = "Aggregated: Theil-T index. Not-aggregated: unweighted contribution to Theil-T") } diff --git a/R/calcTimePref.R b/R/calcTimePref.R index e5192da7..026604b8 100644 --- a/R/calcTimePref.R +++ b/R/calcTimePref.R @@ -1,22 +1,19 @@ - - - calcTimePref <- function() { - # read data - x <- readSource("ExpertGuess",subtype="prtp") + x <- readSource("ExpertGuess", subtype = "prtp") getNames(x) <- NULL getYears(x) <- NULL - + # read data used for weight - pop <- calcOutput("Population",aggregate=FALSE)[,2005,"pop_SSP2"] - gdp <- calcOutput("GDP",aggregate=FALSE)[,2005,"gdp_SSP2"] - # use half pop and half gdp - w <- (pop / dimSums(pop,dim=1)) + setNames(gdp / dimSums(gdp,dim=1),NULL) - - - return(list(x = x, - weight = w, - unit = "dimensionless", - description = "pure rate of time preference")) + pop <- calcOutput("Population", aggregate = FALSE)[, 2005, "pop_SSP2"] + gdp <- calcOutput("GDP", aggregate = FALSE)[, 2005, "gdp_SSP2"] + # use half pop and half gdp + w <- (pop / dimSums(pop, dim = 1)) + setNames(gdp / dimSums(gdp, dim = 1), NULL) + + return(list( + x = x, + weight = w, + unit = "dimensionless", + description = "pure rate of time preference" + )) } diff --git a/R/calcTrade.R b/R/calcTrade.R index b1cbffa7..583055a1 100644 --- a/R/calcTrade.R +++ b/R/calcTrade.R @@ -23,6 +23,6 @@ calcTrade <- function() { return(list( x = x, weight = NULL, unit = "EJ", - description = "IEA Final Energy Data based on 2023 version of IEA Energy Balances" + description = "IEA Final Energy Data based on 2024 version of IEA Energy Balances" )) } diff --git a/R/calcTransportGDPshare.R b/R/calcTransportGDPshare.R index 1d6de9fa..35f6c271 100644 --- a/R/calcTransportGDPshare.R +++ b/R/calcTransportGDPshare.R @@ -9,7 +9,6 @@ #' calcOutput("TransportGDPshare") #' } #' -#' @importFrom magclass add_dimension #' calcTransportGDPshare <- function() { diff --git a/R/calcUBA.R b/R/calcUBA.R index 32f1bd27..adbaa15e 100644 --- a/R/calcUBA.R +++ b/R/calcUBA.R @@ -6,8 +6,6 @@ #' @author Falk Benke #' #' @importFrom dplyr select mutate left_join filter -#' @importFrom madrat toolGetMapping toolCountryFill -#' @importFrom magclass as.magpie mselect #' @importFrom rlang sym #' @importFrom stats aggregate #' @export @@ -30,14 +28,12 @@ calcUBA <- function() { mapping, by = "variable" ) %>% - mutate( - !!sym("REMIND_variable") := paste0(!!sym("REMIND_variable"), " (", !!sym("Unit_REMIND"), ")") - ) %>% + mutate("REMIND_variable" = paste0(!!sym("REMIND_variable"), " (", !!sym("Unit_REMIND"), ")")) %>% select("variable" = "REMIND_variable", "region", "year", "value") x <- aggregate(value ~ variable + region + year, x, sum) %>% as.magpie() %>% - toolCountryFill(fill = NA) + toolCountryFill(fill = NA, verbosity = 2) return(list( x = x, weight = NULL, diff --git a/R/calcUNFCCC.R b/R/calcUNFCCC.R index 640a936c..f6246749 100644 --- a/R/calcUNFCCC.R +++ b/R/calcUNFCCC.R @@ -5,9 +5,6 @@ #' #' @author Falk Benke, Pascal Weigmann #' @importFrom dplyr select mutate left_join -#' @importFrom madrat toolGetMapping toolCountryFill -#' @importFrom magclass as.magpie mselect -#' @importFrom rlang sym #' @importFrom stats aggregate #' @export calcUNFCCC <- function() { @@ -15,7 +12,7 @@ calcUNFCCC <- function() { data <- readSource("UNFCCC") mapping <- toolGetMapping("Mapping_UNFCCC.csv", type = "reportingVariables", where = "mappingfolder") %>% - mutate(!!sym("conversion") := as.numeric(!!sym("Factor")) * !!sym("Weight")) %>% + mutate("conversion" = as.numeric(.data$Factor) * .data$Weight) %>% select("variable" = "UNFCCC", "REMIND", "conversion", "unit" = "Unit_UNFCCC", "Unit_REMIND") mapping$variable <- gsub(pattern = "\\.", replacement = "_", mapping$variable) %>% trimws() @@ -31,12 +28,13 @@ calcUNFCCC <- function() { "year" = "Year", "value" = "Value" ), mapping, - by = "variable" + by = "variable", + relationship = "many-to-many" ) %>% - filter(!!sym("REMIND") != "") %>% + filter(.data$REMIND != "") %>% mutate( - !!sym("value") := !!sym("value") * !!sym("conversion"), - !!sym("REMIND") := paste0(!!sym("REMIND"), " (", !!sym("Unit_REMIND"), ")") # nolint + "value" = .data$value * .data$conversion, + "REMIND" = paste0(.data$REMIND, " (", .data$Unit_REMIND, ")") ) %>% select("variable" = "REMIND", "region", "year", "value") @@ -44,8 +42,6 @@ calcUNFCCC <- function() { as.magpie() %>% toolCountryFill(fill = NA, verbosity = 2) - mappedVariables <- getNames(x) - # aggregate pollutants ---- x <- add_columns(x, "Emi|CH4 (Mt CH4/yr)", dim = 3.1) @@ -216,7 +212,6 @@ calcUNFCCC <- function() { x[, , "Emi|GHG|Energy|Demand|Transport (Mt CO2eq/yr)"] + x[, , "Emi|GHG|Energy|Demand|Buildings (Mt CO2eq/yr)"] - x <- add_columns(x, "Emi|GHG|w/ Bunkers|Energy|Demand (Mt CO2eq/yr)", dim = 3.1) x[, , "Emi|GHG|w/ Bunkers|Energy|Demand (Mt CO2eq/yr)"] <- x[, , "Emi|GHG|Energy|Demand (Mt CO2eq/yr)"] + @@ -239,11 +234,14 @@ calcUNFCCC <- function() { # return results ---- - # set 0 to NA in calculated variables - calculatedVariabes <- setdiff(getNames(x), mappedVariables) - tmp <- x[, , calculatedVariabes] - tmp[tmp == 0] <- NA - x[, , calculatedVariabes] <- tmp + # fill countries of selected regions with 0 to allow for regional aggregation + regions.fill <- c("EUR", "REF", "NEU", "CAZ") + mapping <- toolGetMapping("regionmappingH12.csv", type = "regional", where = "mappingfolder") %>% + filter(.data$RegionCode %in% regions.fill) + + tmp <- x[unique(mapping$CountryCode), , ] + tmp[is.na(tmp)] <- 0 + x[unique(mapping$CountryCode), , ] <- tmp # remove years before 1990 due to incomplete data x <- x[, seq(1986, 1989, 1), , invert = TRUE] diff --git a/R/calcWasteEnergyUseShares.R b/R/calcWasteEnergyUseShares.R new file mode 100644 index 00000000..9a9a6d27 --- /dev/null +++ b/R/calcWasteEnergyUseShares.R @@ -0,0 +1,91 @@ +#' Calculate waste energy use shares based on IEA World Energy Balances +#' +#' The output of this function is used in remind2 for reporting purposes. +#' +#' @author Robert Pietzcker, Falk Benke +#' +calcWasteEnergyUseShares <- function() { + x <- readSource("IEA", subtype = "EnergyBalances") + x <- dimSums(x[, , c("INDWASTE", "MUNWASTEN")], dim = 3.1, na.rm = TRUE) + + numerator <- NULL + denominator <- NULL + + numerator <- mbind(numerator, setNames( + x[, , "TFC"], + "Waste for FE|Share in Waste" + )) + + denominator <- mbind(denominator, setNames( + x[, , "TFC"] - x[, , "TOTTRANF"], + "Waste for FE|Share in Waste" + )) + + numerator <- mbind(numerator, setNames( + -x[, , "TOTTRANF"], + "Waste for Energy Supply|Share in Waste" + )) + + denominator <- mbind(denominator, setNames( + x[, , "TFC"] - x[, , "TOTTRANF"], + "Waste for Energy Supply|Share in Waste" + )) + + numerator <- mbind(numerator, setNames( + x[, , "TOTIND"], + "Waste for Industry|Share in Waste for FE" + )) + + denominator <- mbind(denominator, setNames( + x[, , "TFC"], + "Waste for Industry|Share in Waste for FE" + )) + + numerator <- mbind(numerator, setNames( + x[, , "COMMPUB"], + "Waste for CommPub|Share in Waste for FE" + )) + + denominator <- mbind(denominator, setNames( + x[, , "TFC"], + "Waste for CommPub|Share in Waste for FE" + )) + + # the factor 2 represents the lower conversion efficiency of heat to electricity + numerator <- mbind(numerator, setNames( + 2 * x[, , "ELOUTPUT"], + "Waste for Electricity|Share in Waste for Energy Supply" + )) + + denominator <- mbind(denominator, setNames( + 2 * x[, , "ELOUTPUT"] + x[, , "HEATOUT"], + "Waste for Electricity|Share in Waste for Energy Supply" + )) + + numerator <- mbind(numerator, setNames( + x[, , "HEATOUT"], + "Waste for Heat|Share in Waste for Energy Supply" + )) + + denominator <- mbind(denominator, setNames( + 2 * x[, , "ELOUTPUT"] + x[, , "HEATOUT"], + "Waste for Heat|Share in Waste for Energy Supply" + )) + + .calcShares <- function(x, rel, denominator) { + return( + toolAggregate(x, rel = rel) / + toolAggregate(denominator, rel = rel) + ) + } + + return(list( + x = numerator, + weight = NULL, + unit = "%", + aggregationFunction = .calcShares, + aggregationArguments = list(denominator = denominator), + min = 0, max = 1, + description = "Waste Energy Use Shares based on IEA World Energy Balances" + )) +} diff --git a/R/calcWaterConsCoef.R b/R/calcWaterConsCoef.R index d2e80373..9ca4ebbe 100644 --- a/R/calcWaterConsCoef.R +++ b/R/calcWaterConsCoef.R @@ -1,77 +1,91 @@ #' Calculate Water Consumption Coefficients -#' +#' #' This function calculates REMIND input data on water consumption coefficients #' per electricity technology, using as initial information the Macknick (2011) #' data per electricity technology. The source data provide most required #' information but some assumptions on missing data are also made. -#' -#' -#' @return MAgPIE object on water consumption coefficients per elecricity +#' +#' +#' @return MAgPIE object on water consumption coefficients per electricity #' technology #' @author Ioanna Mouratiadou #' @seealso \code{\link{calcOutput}}, \code{\link{readMacknickIntensities}}, #' \code{\link{calcWaterWithCoef}} #' @examples -#' -#' \dontrun{ +#' \dontrun{ #' calcOutput("WaterConsCoef") -#' #' } -#' +#' calcWaterConsCoef <- function() { - # read in data - data <- readSource("MacknickIntensities","data") - - #use data for median withdrawal - data <- collapseNames(data[,,"Water consumption median (gal/MWh)",drop=FALSE]) + data <- readSource("MacknickIntensities", "data") + + # use data for median withdrawal + data <- collapseNames(data[, , "Water consumption median (gal/MWh)", drop = FALSE]) + + # convert from gal/MWh into m3/MWh + data <- data * 0.0037854 - #convert from gal/MWh into m3/MWh - data <- data * 0.0037854 - # read in mapping to REMIND technologies - map_table <- read_excel(toolGetMapping(type = "sectoral", name = "TechnologyMappingMacknick2REMIND.xlsx", - returnPathOnly = TRUE, where = "mappingfolder")) + map_table <- toolGetMapping( + type = "sectoral", + name = "techmappingMacknickToREMIND.csv", + where = "mrremind" + ) + map <- list() - map$macknick <- paste(map_table$'Macknick Source',map_table$'Macknick Technology',map_table$'Macknick Cooling',sep=".") - map$remind <- paste(map_table$`REMIND Technology`,map_table$`REMIND Cooling`,sep=".") - + map$macknick <- paste(map_table$Macknick.Source, + map_table$Macknick.Technology, map_table$Macknick.Cooling, + sep = "." + ) + + map$remind <- paste(map_table$REMIND.Technology, map_table$REMIND.Cooling, sep = ".") + # calculate REMIND input in REMIND categories - output <- new.magpie(getRegions(data),getYears(data),map$remind) - output[,,] <- 0 - for(d in 1:length(map$macknick)){ - if( !map$macknick[d] == "-.-.-"){ - output[,,map$remind[d]] <- data[,,map$macknick[d]] + output <- new.magpie(getRegions(data), getYears(data), map$remind) + output[, , ] <- 0 + for (d in 1:length(map$macknick)) { + if (!map$macknick[d] == "-.-.-") { + output[, , map$remind[d]] <- data[, , map$macknick[d]] } } - + + # remove no longer used technologies pcc and pco + output <- output[, , c("pcc", "pco"), invert = TRUE] + # add some assumed data - assudata <- readSource("MacknickIntensities","missingAssumed") - assudata <- collapseNames(assudata[,,"Water consumption median (gal/MWh)",drop=TRUE],1) - assudata <- assudata * 0.0037854 - - # add assumed data to data (by overrighting) - output[,,getNames(assudata)] <- assudata[,,getNames(assudata)] - output[,,"ngcc.once"] <- 0.66 * output[,,"ngcc.once"] + 0.34 * output[,,"dot.once"] - output[,,"ngcc.tower"] <- 0.66 * output[,,"ngcc.tower"] + 0.34 * output[,,"dot.tower"] - output[,,"ngcc.pond"] <- 0.66 * output[,,"ngcc.pond"] + 0.34 * output[,,"dot.pond"] - output[,,"ngcc.dry"] <- 0.66 * output[,,"ngcc.dry"] + 0.34 * output[,,"dot.dry"] - output[,,"gaschp.once"] <- 0.50 * output[,,"dot.once"] - output[,,"gaschp.tower"] <- 0.50 * output[,,"dot.tower"] - output[,,"gaschp.pond"] <- 0.50 * output[,,"dot.pond"] - output[,,"gaschp.dry"] <- 0.50 * output[,,"dot.dry"] - output[,,"coalchp.once"] <- 0.50 * output[,,"pc.once"] - output[,,"coalchp.tower"] <- 0.50 * output[,,"pc.tower"] - output[,,"coalchp.pond"] <- 0.50 * output[,,"pc.pond"] - output[,,"coalchp.dry"] <- 0.50 * output[,,"pc.dry"] - output[,,"biochp.once"] <- 0.50 * output[,,"pc.once"] - output[,,"biochp.tower"] <- 0.50 * output[,,"pc.tower"] - output[,,"biochp.pond"] <- 0.50 * output[,,"pc.pond"] - output[,,"biochp.dry"] <- 0.50 * output[,,"pc.dry"] - - return(list(x=output,weight=NULL, - unit="m3/MWh", - description="Water Consumption coefficients for different electricity and cooling technologies based on Macknick et al. (2011) report", - isocountries=FALSE + assudata <- readSource("MacknickIntensities", "missingAssumed") + assudata <- assudata[, , c("pcc", "pco"), invert = TRUE] + assudata <- collapseNames(assudata[, , "Water consumption median (gal/MWh)", drop = TRUE], 1) + assudata <- assudata * 0.0037854 + + # add assumed data to data (by overwriting) + output[, , getNames(assudata)] <- assudata[, , getNames(assudata)] + output[, , "ngcc.once"] <- 0.66 * output[, , "ngcc.once"] + 0.34 * output[, , "dot.once"] + output[, , "ngcc.tower"] <- 0.66 * output[, , "ngcc.tower"] + 0.34 * output[, , "dot.tower"] + output[, , "ngcc.pond"] <- 0.66 * output[, , "ngcc.pond"] + 0.34 * output[, , "dot.pond"] + output[, , "ngcc.dry"] <- 0.66 * output[, , "ngcc.dry"] + 0.34 * output[, , "dot.dry"] + output[, , "gaschp.once"] <- 0.50 * output[, , "dot.once"] + output[, , "gaschp.tower"] <- 0.50 * output[, , "dot.tower"] + output[, , "gaschp.pond"] <- 0.50 * output[, , "dot.pond"] + output[, , "gaschp.dry"] <- 0.50 * output[, , "dot.dry"] + output[, , "coalchp.once"] <- 0.50 * output[, , "pc.once"] + output[, , "coalchp.tower"] <- 0.50 * output[, , "pc.tower"] + output[, , "coalchp.pond"] <- 0.50 * output[, , "pc.pond"] + output[, , "coalchp.dry"] <- 0.50 * output[, , "pc.dry"] + output[, , "biochp.once"] <- 0.50 * output[, , "pc.once"] + output[, , "biochp.tower"] <- 0.50 * output[, , "pc.tower"] + output[, , "biochp.pond"] <- 0.50 * output[, , "pc.pond"] + output[, , "biochp.dry"] <- 0.50 * output[, , "pc.dry"] + + return(list( + x = output, + weight = NULL, + unit = "m3/MWh", + description = c( + "Water Consumption coefficients for different electricity and cooling technologies ", + "based on Macknick et al. (2011) report" + ), + isocountries = FALSE )) } diff --git a/R/calcWaterWithCoef.R b/R/calcWaterWithCoef.R index d32c124e..4adddcc3 100644 --- a/R/calcWaterWithCoef.R +++ b/R/calcWaterWithCoef.R @@ -1,77 +1,91 @@ #' Calculate Water Withdrawal Coefficients -#' +#' #' This function calculates REMIND input data on water withdrawal coefficients #' per electricity technology, using as initial information the Macknick (2011) #' data per electricity technology. The source data provide most required #' information but some assumptions on missing data are also made. -#' -#' +#' +#' #' @return MAgPIE object on water withdrawal coefficients per elecricity #' technology #' @author Ioanna Mouratiadou #' @seealso \code{\link{calcOutput}}, \code{\link{readMacknickIntensities}}, #' \code{\link{calcWaterConsCoef}} #' @examples -#' -#' \dontrun{ +#' \dontrun{ #' calcOutput("WaterWithCoeff") -#' #' } -#' +#' calcWaterWithCoef <- function() { - # read in data - data <- readSource("MacknickIntensities","data") - - #use data for median withdrawal - data <- collapseNames(data[,,"Water withdrawal median (gal/MWh)",drop=FALSE]) + data <- readSource("MacknickIntensities", "data") + + # use data for median withdrawal + data <- collapseNames(data[, , "Water withdrawal median (gal/MWh)", drop = FALSE]) + + # convert from gal/MWh into m3/MWh + data <- data * 0.0037854 - #convert from gal/MWh into m3/MWh - data <- data * 0.0037854 - # read in mapping to REMIND technologies - map_table <- read_excel(toolGetMapping(type = "sectoral", name = "TechnologyMappingMacknick2REMIND.xlsx", - returnPathOnly = TRUE, where = "mappingfolder")) + map_table <- toolGetMapping( + type = "sectoral", + name = "techmappingMacknickToREMIND.csv", + where = "mrremind" + ) + + map <- list() - map$macknick <- paste(map_table$'Macknick Source',map_table$'Macknick Technology',map_table$'Macknick Cooling',sep=".") - map$remind <- paste(map_table$'REMIND Technology',map_table$'REMIND Cooling',sep=".") - + map$macknick <- paste(map_table$Macknick.Source, + map_table$Macknick.Technology, map_table$Macknick.Cooling, + sep = "." + ) + map$remind <- paste(map_table$REMIND.Technology, map_table$REMIND.Cooling, sep = ".") + # calculate REMIND input in REMIND categories - output <- new.magpie(getRegions(data),getYears(data),map$remind) - output[,,] <- 0 - for(d in 1:length(map$macknick)){ - if( !map$macknick[d] == "-.-.-"){ - output[,,map$remind[d]] <- data[,,map$macknick[d]] + output <- new.magpie(getRegions(data), getYears(data), map$remind) + output[, , ] <- 0 + for (d in 1:length(map$macknick)) { + if (!map$macknick[d] == "-.-.-") { + output[, , map$remind[d]] <- data[, , map$macknick[d]] } } - + + # remove no longer used technologies pcc and pco + output <- output[, , c("pcc", "pco"), invert = TRUE] + # add some assumed data - assudata <- readSource("MacknickIntensities","missingAssumed") - assudata <- collapseNames(assudata[,,"Water withdrawal median (gal/MWh)",drop=TRUE],1) - assudata <- assudata * 0.0037854 - + assudata <- readSource("MacknickIntensities", "missingAssumed") + assudata <- assudata[, , c("pcc", "pco"), invert = TRUE] + assudata <- collapseNames(assudata[, , "Water withdrawal median (gal/MWh)", drop = TRUE], 1) + assudata <- assudata * 0.0037854 + # add assumed data to data (by overrighting) - output[,,getNames(assudata)] <- assudata[,,getNames(assudata)] - output[,,"ngcc.once"] <- 0.66 * output[,,"ngcc.once"] + 0.34 * output[,,"dot.once"] - output[,,"ngcc.tower"] <- 0.66 * output[,,"ngcc.tower"] + 0.34 * output[,,"dot.tower"] - output[,,"ngcc.pond"] <- 0.66 * output[,,"ngcc.pond"] + 0.34 * output[,,"dot.pond"] - output[,,"ngcc.dry"] <- 0.66 * output[,,"ngcc.dry"] + 0.34 * output[,,"dot.dry"] - output[,,"gaschp.once"] <- 0.50 * output[,,"dot.once"] - output[,,"gaschp.tower"] <- 0.50 * output[,,"dot.tower"] - output[,,"gaschp.pond"] <- 0.50 * output[,,"dot.pond"] - output[,,"gaschp.dry"] <- 0.50 * output[,,"dot.dry"] - output[,,"coalchp.once"] <- 0.50 * output[,,"pc.once"] - output[,,"coalchp.tower"] <- 0.50 * output[,,"pc.tower"] - output[,,"coalchp.pond"] <- 0.50 * output[,,"pc.pond"] - output[,,"coalchp.dry"] <- 0.50 * output[,,"pc.dry"] - output[,,"biochp.once"] <- 0.50 * output[,,"pc.once"] - output[,,"biochp.tower"] <- 0.50 * output[,,"pc.tower"] - output[,,"biochp.pond"] <- 0.50 * output[,,"pc.pond"] - output[,,"biochp.dry"] <- 0.50 * output[,,"pc.dry"] - - return(list(x=output,weight=NULL, - unit="m3/MWh", - description="Water withdrawal coefficients for different electricity and cooling technologies based on Macknick et al. (2011) report", - isocountries=FALSE + output[, , getNames(assudata)] <- assudata[, , getNames(assudata)] + output[, , "ngcc.once"] <- 0.66 * output[, , "ngcc.once"] + 0.34 * output[, , "dot.once"] + output[, , "ngcc.tower"] <- 0.66 * output[, , "ngcc.tower"] + 0.34 * output[, , "dot.tower"] + output[, , "ngcc.pond"] <- 0.66 * output[, , "ngcc.pond"] + 0.34 * output[, , "dot.pond"] + output[, , "ngcc.dry"] <- 0.66 * output[, , "ngcc.dry"] + 0.34 * output[, , "dot.dry"] + output[, , "gaschp.once"] <- 0.50 * output[, , "dot.once"] + output[, , "gaschp.tower"] <- 0.50 * output[, , "dot.tower"] + output[, , "gaschp.pond"] <- 0.50 * output[, , "dot.pond"] + output[, , "gaschp.dry"] <- 0.50 * output[, , "dot.dry"] + output[, , "coalchp.once"] <- 0.50 * output[, , "pc.once"] + output[, , "coalchp.tower"] <- 0.50 * output[, , "pc.tower"] + output[, , "coalchp.pond"] <- 0.50 * output[, , "pc.pond"] + output[, , "coalchp.dry"] <- 0.50 * output[, , "pc.dry"] + output[, , "biochp.once"] <- 0.50 * output[, , "pc.once"] + output[, , "biochp.tower"] <- 0.50 * output[, , "pc.tower"] + output[, , "biochp.pond"] <- 0.50 * output[, , "pc.pond"] + output[, , "biochp.dry"] <- 0.50 * output[, , "pc.dry"] + + return(list( + x = output, + weight = NULL, + unit = "m3/MWh", + description = c( + "Water withdrawal coefficients for different electricity and cooling technologies ", + "based on Macknick et al. (2011) report" + ), + isocountries = FALSE )) } diff --git a/R/calcWeightNash.R b/R/calcWeightNash.R index 6a89fac3..8c9883bc 100644 --- a/R/calcWeightNash.R +++ b/R/calcWeightNash.R @@ -1,11 +1,14 @@ - calcWeightNash <- function() { - - x <- readSource("REMIND_11Regi",subtype="nashWeight") + x <- readSource("REMIND_11Regi", subtype = "nashWeight") getNames(x) <- NULL - return(list(x = x, - weight = NULL, - unit = "factor", - description = "fallback Nash weights only to be used if due to infeasibilities internal computation of weights does not work")) + return(list( + x = x, + weight = NULL, + unit = "factor", + description = paste0( + "fallback Nash weights only to be used if due to infeasibilities ", + "internal computation of weights does not work" + ) + )) } diff --git a/R/calcindustry_specific_FE_limits.R b/R/calcindustry_specific_FE_limits.R index ebd08729..9227fa04 100644 --- a/R/calcindustry_specific_FE_limits.R +++ b/R/calcindustry_specific_FE_limits.R @@ -9,8 +9,6 @@ #' @author Michaja Pehl #' #' @importFrom dplyr filter mutate select -#' @importFrom madrat readSource -#' @importFrom magclass as.magpie #' @importFrom quitte madrat_mule #' @export diff --git a/R/calcpm_delta_kap_industry.R b/R/calcpm_delta_kap_industry.R deleted file mode 100644 index 511a58ae..00000000 --- a/R/calcpm_delta_kap_industry.R +++ /dev/null @@ -1,31 +0,0 @@ -#' Calculate depreciation rate of industry energy-efficiency capital (EEK). -#' -#' @md -#' @return A list with a [`magpie`][magclass::magclass] object `x`, `unit`, and -#' `description`. -#' -#' @author Michaja Pehl -#' -#' @seealso [`calcOutput()`] -#' -#' @importFrom magclass new.magpie -#' - -#' @export -calcpm_delta_kap_industry <- function() { - lifetime <- 50 - - pm_delta_kap_industry <- new.magpie( - cells_and_regions = toolGetMapping(name = 'regionmapping_21_EU11.csv', - type = 'regional', where = "mappingfolder")$CountryCode, - years = NULL, - names = 'pm_delta_kap', - fill = log(4) / lifetime, - sort = TRUE) - return( - list(x = pm_delta_kap_industry, - weight = pm_delta_kap_industry, - unit = 'fraction', - description = paste('Depreciation rate of industry energy-efficiency', - 'capital (EEK).'))) -} diff --git a/R/convertADVANCE_WP2.R b/R/convertADVANCE_WP2.R index 0ea34572..92a96978 100644 --- a/R/convertADVANCE_WP2.R +++ b/R/convertADVANCE_WP2.R @@ -1,7 +1,7 @@ #' Convert ADVANCE WP2 Data #' #' @md -#' @param x A [`magpie`][magclass::magclass] object returned by +#' @param x A [`magpie`][magclass::magclass] object returned by #' [`readADVANCE_WP2()`]. #' @param subtype One of #' - `clinker-to-cement-ratio` for the clinker-to-cement ratios from figure 21 @@ -11,44 +11,42 @@ #' which is extended from H12 regions to country level. #' #' @return A [`magpie`][magclass::magclass] object. -#' +#' #' @author Michaja Pehl -#' +#' #' @seealso [`readSource()`], [`readADVANCE_WP2()`] -#' +#' #' @importFrom assertr assert -#' @importFrom dplyr %>% full_join select -#' @importFrom madrat toolGetMapping -#' @importFrom magclass as.data.frame as.magpie +#' @importFrom dplyr full_join select #' @importFrom rlang sym #' @importFrom tibble as_tibble #' @importFrom tidyselect everything -#' +#' #' @export convertADVANCE_WP2 <- function(x, subtype) { # ---- list all available subtypes with functions doing all the work ---- switchboard <- list( 'clinker-to-cement-ratio' = function(x) { - x %>% - as.data.frame() %>% - as_tibble() %>% - select(region = 'Region', ratio = 'Value') %>% + x %>% + as.data.frame() %>% + as_tibble() %>% + select(region = 'Region', ratio = 'Value') %>% full_join( - toolGetMapping(name = 'regionmappingH12.csv', type = 'regional', where = "mappingfolder") %>% - as_tibble() %>% + toolGetMapping(name = 'regionmappingH12.csv', type = 'regional', where = "mappingfolder") %>% + as_tibble() %>% select(iso3c = 'CountryCode', region= 'RegionCode'), - + 'region' - ) %>% - assert(not_na, everything()) %>% - select(-'region') %>% + ) %>% + assert(not_na, everything()) %>% + select(-'region') %>% as.magpie() } ) - + # ---- check if the subtype called is available ---- if (is_empty(intersect(subtype, names(switchboard)))) { - stop(paste('Invalid subtype -- supported subtypes are:', + stop(paste('Invalid subtype -- supported subtypes are:', paste(names(switchboard), collapse = ', '))) } else { # ---- load data and do whatever ---- diff --git a/R/convertAGEB.R b/R/convertAGEB.R index bf38ff06..3fc1ea37 100644 --- a/R/convertAGEB.R +++ b/R/convertAGEB.R @@ -8,9 +8,6 @@ #' #' @author Falk Benke #' -#' @importFrom dplyr %>% -#' @importFrom madrat getISOlist -#' #' @export convertAGEB <- function(x) { add_columns(x, addnm = setdiff(getISOlist(), "DEU"), dim = 1, fill = NA) %>% return() diff --git a/R/convertAriadneDB.R b/R/convertAriadneDB.R index 45448770..43cec231 100644 --- a/R/convertAriadneDB.R +++ b/R/convertAriadneDB.R @@ -4,10 +4,9 @@ #' @param x A [`magpie`][magclass::magclass] object returned from #' [`readAriadneDB()`]. #' @author Felix Schreyer -#' @importFrom magclass getItems add_columns convertAriadneDB <- function(x) { - getItems(x, dim=1) <- "DEU" + getItems(x, dim = 1) <- "DEU" x <- add_columns(x, addnm = setdiff(getISOlist(), "DEU"), dim = 1, fill = NA) return(x) } diff --git a/R/convertBGR.R b/R/convertBGR.R index f9ccb93f..7e4498ae 100644 --- a/R/convertBGR.R +++ b/R/convertBGR.R @@ -1,21 +1,19 @@ #' Converts BGR oil, gas, coal and uranium reserves data -#' +#' #' @param x MAgPIE object to be converted #' @param subtype data subtype. Either "oil", "gas", "coal" or "uranium". -#' @return A MAgPIE object containing BGR (Federal Institute for Geosciences and Natural Resources) country reserves disaggregated data of oil, gas, coal and uranium. +#' @return A MAgPIE object containing BGR (Federal Institute for Geosciences and +#' Natural Resources) country reserves disaggregated data of oil, gas, coal and uranium. #' @author Renato Rodrigues #' @examples -#' -#' \dontrun{ a <- convertBGR(x,subtype="oil") +#' \dontrun{ +#' a <- convertBGR(x, subtype = "oil") #' } -#' - - convertBGR <- function(x,subtype) { - # rename countries to REMIND iso codes - getRegions(x) <- toolCountry2isocode(getRegions(x)) - x[is.na(x)] <- 0 # setting NA values to zero - x <- toolCountryFill(x,fill=0,verbosity=2) # fill countries with no data - return(x) - } - - +#' +convertBGR <- function(x, subtype) { + # rename countries to REMIND iso codes + getItems(x, dim = 1) <- toolCountry2isocode(getItems(x, dim = 1)) + x[is.na(x)] <- 0 # setting NA values to zero + x <- toolCountryFill(x, fill = 0, verbosity = 2) # fill countries with no data + return(x) +} diff --git a/R/convertBP.R b/R/convertBP.R index f23f55ba..6523c87a 100644 --- a/R/convertBP.R +++ b/R/convertBP.R @@ -1,20 +1,16 @@ #' Disaggregates and cleans BP data. +#' #' @param x MAgPIE object to be converted -#' @param subtype Either "Emission", "Capacity", "Generation", "Production", "Consumption", "Trade Oil", "Trade Gas", "Trade Coal" or "Price" -#' @description Disaggregates historical data. +#' @param subtype Either "Emission", "Capacity", "Generation", "Production", +#' "Consumption", "Trade Oil", "Trade Gas", "Trade Coal" or "Price" +#' #' @return A [`magpie`][magclass::magclass] object. #' @author Aman Malik, Falk Benke +#' #' @importFrom dplyr filter -#' @importFrom madrat getISOlist toolGetMapping toolCountryFill -#' @importFrom magclass magpply -#' @importFrom rlang sym - +#' convertBP <- function(x, subtype) { - Region_name <- NULL - ISO_code <- NULL - ISO3.code <- NULL - PE <- calcOutput("PE", aggregate = FALSE) .removeNaRegions <- function(x) { @@ -24,37 +20,38 @@ convertBP <- function(x, subtype) { .removeNaYears <- function(x) { remove <- magpply(x, function(y) all(is.na(y)), MARGIN = 2) - return(x[,!remove, ]) + return(x[, !remove, ]) } - - # disaggregate regions of x by mapping to iso countries belonging to that regions, but not listed in x (i.e. other countries) - .disaggregate_regions <- function(x_in, regions) { - + # disaggregate regions of x by mapping to iso countries belonging to that regions, + # but not listed in x (i.e. other countries) + .disaggregateRegions <- function(x_in, regions) { x <- .removeNaRegions(x_in) x <- .removeNaYears(x) # full mapping of regions to iso countries - mapping_full <- toolGetMapping("regionmappingBP_Full.csv", type = "regional", where = "mappingfolder") + mappingFull <- toolGetMapping("regionmappingBP_Full.csv", type = "regional", where = "mrremind") # iso countries in x - ctry <- toolCountry2isocode(getItems(x, dim = 1), warn = F) + ctry <- toolCountry2isocode(getItems(x, dim = 1), warn = FALSE) ctry <- ctry[!is.na(ctry)] # mapping of regions to iso countries other than in ctry (i.e. other regions) - mapping_regions <- mapping_full[mapping_full$Region_name %in% regions & - !mapping_full$ISO3.code %in% ctry & mapping_full$ISO3.code != "SUN", ] + mappingRegions <- mappingFull[mappingFull$Region_name %in% regions & + !mappingFull$ISO3.code %in% ctry & mappingFull$ISO3.code != "SUN", ] - weight = PE[mapping_regions$ISO3.code, 2014, "PE (EJ/yr)"] + weight <- PE[mappingRegions$ISO3.code, 2014, "PE (EJ/yr)"] # disaggregation of other regions to iso countries - x2 <- toolAggregate(x[regions, , ], rel = mapping_regions, weight = weight) + x2 <- toolAggregate(x[regions, , ], rel = mappingRegions, weight = weight) x2 <- toolCountryFill(x2, fill = 0, verbosity = 2) x2[is.na(x2)] <- 0 # iso countries in x that do not need to be disaggregated x1 <- x[regions, , invert = TRUE] - getItems(x1, dim = 1) <- toolCountry2isocode(getItems(x1, dim = 1), warn = F) + getItems(x1, dim = 1) <- toolCountry2isocode(getItems(x1, dim = 1), + mapping = c("The Dominican Republic" = "DOM"), + warn = FALSE) x1 <- toolCountryFill(x1, fill = 0, verbosity = 2) # combine the two objects @@ -63,40 +60,38 @@ convertBP <- function(x, subtype) { return(x) } - .mergeReg <- function(x, from, to) { x1 <- new.magpie(to, getYears(x), getNames(x), fill = NA) for (n in getNames(x)) { tmp <- x[, , n] tmp <- .removeNaYears(tmp) - x1[, getItems(tmp, dim = 2), n] <- dimSums(tmp[intersect(getItems(x, dim = 1), from), , ], dim = 1, na.rm = T) + x1[, getItems(tmp, dim = 2), n] <- dimSums(tmp[intersect(getItems(x, dim = 1), from), , ], dim = 1, na.rm = TRUE) } - return(mbind(x[from, , invert = T], x1)) + return(mbind(x[from, , invert = TRUE], x1)) } getItems(x, dim = 1) <- gsub("\\bUS\\b", "USA", getItems(x, dim = 1)) getItems(x, dim = 1) <- gsub(pattern = "China Hong Kong SAR", "Hong Kong", x = getItems(x, dim = 1)) # for now, we exclude data from Sowjet Union (recorded until 1993) - x <- x["USSR & Central Europe",,invert = T] - x <- x["USSR",,invert = T] + x <- x["USSR & Central Europe", , invert = TRUE] + x <- x["USSR", , invert = TRUE] if (subtype == "Emission") { + x <- .mergeReg(x, from = c("Central America", "Other Caribbean", "Other South America"), to = "S & C America") x <- .mergeReg(x, from = c("Other Europe"), to = "Europe") x <- .mergeReg(x, from = c("Other CIS"), to = "CIS") x <- .mergeReg(x, from = c("Other Middle East"), to = "Middle East") - x <- .mergeReg(x, from = c("Eastern Africa", "Middle Africa", "Western Africa", "Other Northern Africa", "Other Southern Africa"), to = "Africa") + x <- .mergeReg(x, from = c("Eastern Africa", "Middle Africa", "Western Africa", + "Other Northern Africa", "Other Southern Africa"), to = "Africa") x <- .mergeReg(x, from = c("Other Asia Pacific"), to = "Asia Pacific") regions <- c("Africa", "Asia Pacific", "CIS", "Europe", "Middle East", "S & C America") + x <- .disaggregateRegions(x, regions) - x <- .disaggregate_regions(x, regions) - - } - - else if (subtype == "Capacity") { + } else if (subtype == "Capacity") { x <- .mergeReg(x, from = c("Other Europe"), to = "Europe") x <- .mergeReg(x, from = c("Other Middle East"), to = "Middle East") @@ -108,18 +103,22 @@ convertBP <- function(x, subtype) { regions <- c("Africa", "Asia Pacific", "CIS", "Europe", "Middle East", "S & C America") x <- mbind( - .disaggregate_regions(x[, , "Capacity|Solar (MW)"], regions), - .disaggregate_regions(x[, , "Capacity|Wind (MW)"], regions), - .disaggregate_regions(x[, , "Capacity|Geothermal (MW)"], regions) + .disaggregateRegions(x[, , "Capacity|Solar (MW)"], regions), + .disaggregateRegions(x[, , "Capacity|Wind (MW)"], regions) ) - } - else if (subtype == "Generation") { + } else if (subtype == "Generation") { + + x <- .mergeReg(x, from = c( + "Other Africa", "Other Northern Africa", "Other Southern Africa", + "Middle Africa", "Eastern Africa", "Western Africa" + ), to = "Africa") + + x <- .mergeReg(x, from = c( + "Other South America", "Other Caribbean", "Central America", + "Other S & Cent America" + ), to = "S & C America") - x <- .mergeReg(x, from = c("Other Africa", "Other Northern Africa", "Other Southern Africa", - "Middle Africa", "Eastern Africa", "Western Africa"), to = "Africa") - x <- .mergeReg(x, from = c("Other South America", "Other Caribbean", "Central America", - "Other S & Cent America"), to = "S & C America") x <- .mergeReg(x, from = c("Other Asia Pacific"), to = "Asia Pacific") x <- .mergeReg(x, from = c("Other CIS"), to = "CIS") x <- .mergeReg(x, from = c("Other Europe"), to = "Europe") @@ -127,22 +126,21 @@ convertBP <- function(x, subtype) { regions <- c("Africa", "Asia Pacific", "CIS", "Europe", "Middle East", "S & C America") + x <- x["Other North Africa", , , invert = TRUE] + x <- mbind( - .disaggregate_regions(x[,,"Generation|Wind (TWh)"], regions), - .disaggregate_regions(x[,,"Generation|Solar (TWh)"], regions), - .disaggregate_regions(x[,,"Generation|Hydro (TWh)"], regions), - .disaggregate_regions(x[,,"Generation|Geo_biomass (TWh)"], regions), - .disaggregate_regions(x[,,"Generation|Nuclear (TWh)"], regions), - .disaggregate_regions(x[,,"Generation|Electricity (TWh)"], regions), - .disaggregate_regions(x[,,"Generation|Electricity|Renewable (EJ)"], regions), - .disaggregate_regions(x[,,"Generation|Electricity|Gas (TWh)"], regions), - .disaggregate_regions(x[,,"Generation|Electricity|Oil (TWh)"], regions), - .disaggregate_regions(x[,,"Generation|Electricity|Coal (TWh)"], regions) + .disaggregateRegions(x[, , "Generation|Wind (TWh)"], regions), + .disaggregateRegions(x[, , "Generation|Solar (TWh)"], regions), + .disaggregateRegions(x[, , "Generation|Hydro (TWh)"], regions), + .disaggregateRegions(x[, , "Generation|Geo_biomass (TWh)"], regions), + .disaggregateRegions(x[, , "Generation|Nuclear (TWh)"], regions), + .disaggregateRegions(x[, , "Generation|Electricity (TWh)"], regions), + .disaggregateRegions(x[, , "Generation|Electricity|Renewable (EJ)"], regions), + .disaggregateRegions(x[, , "Generation|Electricity|Gas (TWh)"], regions), + .disaggregateRegions(x[, , "Generation|Electricity|Oil (TWh)"], regions), + .disaggregateRegions(x[, , "Generation|Electricity|Coal (TWh)"], regions) ) - - } - - else if (subtype == "Production") { + } else if (subtype == "Production") { regions <- c("Africa", "Asia Pacific", "CIS", "Europe", "Middle East", "S & C America") @@ -154,92 +152,99 @@ convertBP <- function(x, subtype) { x <- .mergeReg(x, from = c("Other CIS"), to = "CIS") x <- mbind( - .disaggregate_regions(x[,,"Oil Production (million t)"], regions), - .disaggregate_regions(x[,,"Coal Production (EJ)"], regions), - .disaggregate_regions(x[,,"Coal Production (t)"], regions), - .disaggregate_regions(x[,,"Gas Production (EJ)"], regions) + .disaggregateRegions(x[, , "Oil Production (million t)"], regions), + .disaggregateRegions(x[, , "Coal Production (EJ)"], regions), + .disaggregateRegions(x[, , "Coal Production (million t)"], regions), + .disaggregateRegions(x[, , "Gas Production (EJ)"], regions) ) - } - else if (subtype == "Consumption") { + } else if (subtype == "Consumption") { regions <- c("Africa", "Asia Pacific", "CIS", "Europe", "Middle East", "S & C America") x <- .mergeReg(x, from = c("Other Europe"), to = "Europe") x <- .mergeReg(x, from = c("Other Middle East"), to = "Middle East") - x <- .mergeReg(x, from = c("Other Northern Africa", "Other Southern Africa", "Middle Africa", "Eastern Africa", "Western Africa"), to = "Africa") + x <- .mergeReg(x, from = c("Other Northern Africa", "Other Southern Africa", + "Middle Africa", "Eastern Africa", "Western Africa"), to = "Africa") x <- .mergeReg(x, from = c("Other South America", "Other Caribbean", "Central America"), to = "S & C America") x <- .mergeReg(x, from = c("Other Asia Pacific"), to = "Asia Pacific") x <- .mergeReg(x, from = c("Other CIS"), to = "CIS") x <- mbind( - .disaggregate_regions(x[,,"Primary Energy Consumption (EJ)"], regions), - .disaggregate_regions(x[,,"Liquids Consumption (kb/d)"], regions), - .disaggregate_regions(x[,,"Oil Consumption (EJ)"], regions), - .disaggregate_regions(x[,,"Gas Consumption (EJ)"], regions), - .disaggregate_regions(x[,,"Coal Consumption (EJ)"], regions), - .disaggregate_regions(x[,,"Solar Consumption (EJ)"], regions), - .disaggregate_regions(x[,,"Wind Consumption (EJ)"], regions), - .disaggregate_regions(x[,,"Nuclear Consumption (EJ)"], regions), - .disaggregate_regions(x[,,"Hydro Consumption (EJ)"], regions) + .disaggregateRegions(x[, , "Primary Energy Consumption (EJ)"], regions), + .disaggregateRegions(x[, , "Liquids Consumption (kb/d)"], regions), + .disaggregateRegions(x[, , "Oil Consumption (EJ)"], regions), + .disaggregateRegions(x[, , "Gas Consumption (EJ)"], regions), + .disaggregateRegions(x[, , "Coal Consumption (EJ)"], regions), + .disaggregateRegions(x[, , "Solar Consumption (EJ)"], regions), + .disaggregateRegions(x[, , "Wind Consumption (EJ)"], regions), + .disaggregateRegions(x[, , "Nuclear Consumption (EJ)"], regions), + .disaggregateRegions(x[, , "Hydro Consumption (EJ)"], regions) ) - } - else if (subtype == "Trade Oil") { + } else if (subtype == "Trade Oil") { getItems(x, dim = 1) <- gsub("S & Cent America", "S & C America", getItems(x, dim = 1)) trade.export.oil <- .removeNaRegions(x[, , "Trade|Export|Oil (kb/d)"]) trade.import.oil <- .removeNaRegions(x[, , "Trade|Import|Oil (kb/d)"]) - # step 1: resolve to more fine granual regions based on detailed Oil Trade Data for 2019 and 2020 available + # step 1: resolve to more fine granual regions based on detailed Oil Trade Data for 2022 and 2023 available # reference data trade.ref.export.oil <- new.magpie(getItems(x, dim = 1), getYears(x), "Trade|Export|Oil (kb/d)") - trade.ref.export.oil[, , "Trade|Export|Oil (kb/d)"] <- x[, , "Trade|Export|Oil|Crude (kb/d)"] + x[, , "Trade|Export|Oil|Product (kb/d)"] + trade.ref.export.oil[, , "Trade|Export|Oil (kb/d)"] <- x[, , "Trade|Export|Oil|Crude (kb/d)"] + + x[, , "Trade|Export|Oil|Product (kb/d)"] trade.ref.export.oil <- .removeNaRegions(trade.ref.export.oil) - trade.ref.export.oil <- trade.ref.export.oil[, c(2019, 2020), ] + trade.ref.export.oil <- trade.ref.export.oil[, c(2022, 2023), ] trade.ref.import.oil <- new.magpie(getItems(x, dim = 1), getYears(x), "Trade|Import|Oil (kb/d)") - trade.ref.import.oil[, , "Trade|Import|Oil (kb/d)"] <- x[, , "Trade|Import|Oil|Crude (kb/d)"] + x[, , "Trade|Import|Oil|Product (kb/d)"] + trade.ref.import.oil[, , "Trade|Import|Oil (kb/d)"] <- x[, , "Trade|Import|Oil|Crude (kb/d)"] + + x[, , "Trade|Import|Oil|Product (kb/d)"] trade.ref.import.oil <- .removeNaRegions(trade.ref.import.oil) - trade.ref.import.oil <- trade.ref.import.oil[, c(2019, 2020), ] + trade.ref.import.oil <- trade.ref.import.oil[, c(2022, 2023), ] reg2detailReg <- toolGetMapping("regionmappingBP_Oil_Region_To_DetailReg.csv", - type = "regional", where = "mappingfolder") - reg2detailReg.export <- filter(reg2detailReg, !!sym("Type") == "Export") - reg2detailReg.import <- filter(reg2detailReg, !!sym("Type") == "Import") + type = "regional", where = "mrremind") + + reg2detailReg.export <- filter(reg2detailReg, .data$Type == "Export") + reg2detailReg.import <- filter(reg2detailReg, .data$Type == "Import") from_regions <- intersect(reg2detailReg.export$BP_Region, getItems(trade.export.oil, dim = 1)) to_regions <- intersect(reg2detailReg.export$BP_Region_Detail, getItems(trade.ref.export.oil, dim = 1)) unchanged_regions <- setdiff(getItems(trade.export.oil, dim = 1), from_regions) + trade.ref.export.split <- toolAggregate(trade.export.oil[from_regions, , ], rel = reg2detailReg.export, - weight = trade.ref.export.oil[to_regions, 2020, ] + weight = trade.ref.export.oil[to_regions, 2023, ] ) x1 <- new.magpie(c(to_regions, unchanged_regions), getYears(x), "Trade|Export|Oil (kb/d)") - # for 2019 and 2020 we use the detailed data - x1[, c(2019, 2020), ] <- trade.ref.export.oil - # for 1980 - 2018 we split some regions into more fine granular regions by 2020 data - x1[unchanged_regions, seq(1980, 2018, 1), ] <- trade.export.oil[unchanged_regions, seq(1980, 2018, 1), ] - x1[to_regions, seq(1980, 2018, 1), ] <- trade.ref.export.split[, seq(1980, 2018, 1), ] + # for 2022 and 2023 we use the detailed data + x1[, c(2022, 2023), ] <- trade.ref.export.oil + + # for 1980 - 2021 we split some regions into more fine granular regions by 2021 data + x1[unchanged_regions, seq(1980, 2021, 1), ] <- trade.export.oil[unchanged_regions, seq(1980, 2021, 1), ] + x1[to_regions, seq(1980, 2021, 1), ] <- trade.ref.export.split[, seq(1980, 2021, 1), ] from_regions <- intersect(reg2detailReg.import$BP_Region, getItems(trade.import.oil, dim = 1)) to_regions <- intersect(reg2detailReg.import$BP_Region_Detail, getItems(trade.ref.import.oil, dim = 1)) unchanged_regions <- setdiff(getItems(trade.import.oil, dim = 1), from_regions) + trade.ref.import.split <- toolAggregate(trade.import.oil[from_regions, , ], rel = reg2detailReg.import, - weight = trade.ref.import.oil[to_regions, 2020, ] + weight = trade.ref.import.oil[to_regions, 2023, ] ) x2 <- new.magpie(c(to_regions, unchanged_regions), getYears(x), "Trade|Import|Oil (kb/d)") - # for 2019 and 2020 we use the detailed data - x2[, c(2019, 2020), ] <- trade.ref.import.oil - # for 1980 - 2018 we split some regions into more fine granular regions by 2020 data - x2[unchanged_regions, seq(1980, 2018, 1), ] <- trade.import.oil[unchanged_regions, seq(1980, 2018, 1), ] - x2[to_regions, seq(1980, 2018, 1), ] <- trade.ref.import.split[, seq(1980, 2018, 1), ] + + # for 2022 and 2023 we use the detailed data + x2[, c(2022, 2023), ] <- trade.ref.import.oil + + # for 1980 - 2021 we split some regions into more fine granular regions by 2021 data + x2[unchanged_regions, seq(1980, 2021, 1), ] <- trade.import.oil[unchanged_regions, seq(1980, 2021, 1), ] + x2[to_regions, seq(1980, 2021, 1), ] <- trade.ref.import.split[, seq(1980, 2021, 1), ] x.trade <- new.magpie(getItems(x1, dim = 1), getYears(x1), c("Trade|Import|Oil (kb/d)", "Trade|Export|Oil (kb/d)")) x.trade[, , "Trade|Export|Oil (kb/d)"] <- x1 @@ -254,21 +259,21 @@ convertBP <- function(x, subtype) { x.trade <- .mergeReg(x.trade, from = c("Other CIS"), to = "CIS") x.trade <- .mergeReg(x.trade, from = c("Other Middle East"), to = "Middle East") - oil_regions <- c("Africa", "Asia Pacific", "CIS", "Middle East", "S & C America", "Europe") - x <- .disaggregate_regions(x.trade, oil_regions) - } + oilRegions <- c("Africa", "Asia Pacific", "CIS", "Middle East", "S & C America", "Europe") + x <- .disaggregateRegions(x.trade, oilRegions) + + } else if (subtype == "Trade Gas") { - else if (subtype == "Trade Gas") { x <- .mergeReg(x, from = c("Other Asia", "OECD Asia"), to = "Asia Pacific") x <- .mergeReg(x, from = c("Other CIS"), to = "CIS") x <- .mergeReg(x, from = c("Other North America"), to = "North America") x <- .mergeReg(x, from = c("Other S & C America"), to = "S & C America") - gas_regions <- c("Africa", "Asia Pacific", "CIS", "Middle East", "S & C America", "Europe", "North America") - x <- .disaggregate_regions(x, gas_regions) - } + gasRegions <- c("Africa", "Asia Pacific", "CIS", "Middle East", "S & C America", "Europe", "North America") + x <- .disaggregateRegions(x, gasRegions) + + } else if (subtype == "Trade Coal") { - else if (subtype == "Trade Coal") { getItems(x, dim = 1) <- gsub("S & Cent America", "S & C America", getItems(x, dim = 1)) trade.export.coal <- .removeNaRegions(x[, , "Trade|Export|Coal (EJ)"]) @@ -276,26 +281,27 @@ convertBP <- function(x, subtype) { trade.export.coal <- .mergeReg(trade.export.coal, from = c("Other CIS"), to = "CIS") trade.export.coal <- .mergeReg(trade.export.coal, from = c("Other Africa"), to = "Africa") - coal_regions <- c("Africa", "Asia Pacific", "CIS", "Europe") - trade.export.coal <- .disaggregate_regions(trade.export.coal, coal_regions) + coalRegions <- c("Africa", "Asia Pacific", "CIS", "Europe") + trade.export.coal <- .disaggregateRegions(trade.export.coal, coalRegions) trade.import.coal <- .removeNaRegions(x[, , "Trade|Import|Coal (EJ)"]) trade.import.coal <- .mergeReg(trade.import.coal, from = c("Other Asia Pacific"), to = "Asia Pacific") - coal_regions <- c("Africa", "Asia Pacific", "CIS", "Middle East", "S & C America", "Europe") - trade.import.coal <- .disaggregate_regions(trade.import.coal, coal_regions) + coalRegions <- c("Africa", "Asia Pacific", "CIS", "Middle East", "S & C America", "Europe") + trade.import.coal <- .disaggregateRegions(trade.import.coal, coalRegions) x <- mbind(trade.export.coal, trade.import.coal) - } - else if (subtype == "Price") { + } else if (subtype == "Price") { + x.price <- new.magpie(getISOlist(), getYears(x), getNames(x)) x.price[getISOlist(), , ] <- x["GLO", , ] - mapping <- toolGetMapping("regionmappingH12.csv", where = "mappingfolder") + mapping <- toolGetMapping("regionmappingH12.csv", where = "mappingfolder", type = "regional") caz <- mapping[mapping$RegionCode == "CAZ", "CountryCode"] oas <- mapping[mapping$RegionCode == "OAS", "CountryCode"] eur <- setdiff(mapping[mapping$RegionCode == "EUR", "CountryCode"], "GBR") + lam <- mapping[mapping$RegionCode == "LAM", "CountryCode"] # specific region mapping for gas prices: # Japan -> JPN, Korea -> OAS, average (Netherlands, Germany) -> EUR, US-> USA, Can -> CAZ @@ -309,20 +315,23 @@ convertBP <- function(x, subtype) { price.gas[caz, , "Price|Natural Gas ($/mbtu)"] <- x.price[caz, , "Price|Natural Gas|Alberta ($/mbtu)"] price.gas <- toolCountryFill(price.gas, fill = 0, verbosity = 2) - # specific region mapping for coal prices: - # Japan steam spot -> JPN, Asian marker -> OAS, IND, NW EU -> EUR, US-> USA, Chn -> CHN - price.coal <- new.magpie(c(oas, eur, "USA", "GBR", "JPN", "IND", "CHN"), getYears(x.price), "Price|Coal ($/t)") - price.coal["JPN", , "Price|Coal ($/t)"] <- x.price["JPN", , "Price|Coal|Japan steam spot CIF price ($/t)"] - price.coal[c(oas, "IND"), , "Price|Coal ($/t)"] <- x.price[c(oas, "IND"), , "Price|Coal|Asian marker price (t/$)"] - price.coal[c(eur, "GBR"), , "Price|Coal ($/t)"] <- x.price[c(eur, "GBR"), , "Price|Coal|Northwest Europe marker price ($/t)"] - price.coal["USA", , "Price|Coal ($/t)"] <- x.price["USA", , "Price|Coal|US Central Appalachian coal spot price index ($/t)"] - price.coal["CHN", , "Price|Coal ($/t)"] <- x.price["CHN", , "Price|Coal|China Qinhuangdao spot price ($/t)"] + price.coal <- new.magpie(c(lam, oas, eur, "USA", "GBR", "JPN", "IND", "CHN", "AUS", "ZAF"), + getYears(x.price), "Price|Coal ($/t)") + + price.coal["JPN", , "Price|Coal ($/t)"] <- x.price["JPN", , "Price|Coal|Japan ($/t)"] + price.coal[c(oas, "IND"), , "Price|Coal ($/t)"] <- x.price[c(oas, "IND"), , "Price|Coal|Indonesia ($/t)"] + price.coal[c(eur, "GBR"), , "Price|Coal ($/t)"] <- x.price[c(eur, "GBR"), , "Price|Coal|Northwest Europe ($/t)"] + price.coal["USA", , "Price|Coal ($/t)"] <- x.price["USA", , "Price|Coal|United States ($/t)"] + price.coal["CHN", , "Price|Coal ($/t)"] <- x.price["CHN", , "Price|Coal|South China ($/t)"] + price.coal["AUS", , "Price|Coal ($/t)"] <- x.price["AUS", , "Price|Coal|Australia ($/t)"] + price.coal["ZAF", , "Price|Coal ($/t)"] <- x.price["ZAF", , "Price|Coal|South Africa ($/t)"] + price.coal[lam, , "Price|Coal ($/t)"] <- x.price[lam, , "Price|Coal|Colombia ($/t)"] + price.coal <- toolCountryFill(price.coal, fill = 0, verbosity = 2) x <- mbind(x.price, price.gas, price.coal) - } - else { + } else { stop("Not a valid subtype!") } diff --git a/R/convertCCS_StoragePotential.R b/R/convertCCS_StoragePotential.R index 1ae9f522..de94f5f7 100644 --- a/R/convertCCS_StoragePotential.R +++ b/R/convertCCS_StoragePotential.R @@ -1,4 +1,4 @@ convertCCS_StoragePotential <- function(x){ - x <- toolCountryFill(x) + x <- toolCountryFill(x, verbosity = 2) return(x) } diff --git a/R/convertCDIAC.R b/R/convertCDIAC.R index cb9f6ac5..ce49e84a 100644 --- a/R/convertCDIAC.R +++ b/R/convertCDIAC.R @@ -1,38 +1,39 @@ -#' @importFrom madrat toolCountry2isocode toolISOhistorical toolAggregate convertCDIAC <- function(x) { + # Filter regions mapping to XXX + remove <- getRegions(x)[toolCountry2isocode(getRegions(x)) == "XXX"] + x <- x[remove, , , invert = TRUE] + # Nations names to ISO country codes - getRegions(x) <- toolCountry2isocode(getRegions(x)) - # delete XXX-Regions - x <- x["XXX",,,invert=TRUE] # FIXME better solution for XXX-regions + getItems(x, dim = 1) <- toolCountry2isocode(getRegions(x)) # CDIAC(XIT) -> ISO(ITA + SMR) # CDIAC(XFR) -> ISO(FRA + MCO) - m <- matrix(c(c("XIT","XIT","XFR","XFR"),c("ITA","SMR","FRA","MCO")),4) - w <- calcOutput("Population",years=2005,aggregate=FALSE)[c("ITA","SMR","FRA","MCO"),,"pop_SSP2"] - x_split <- toolAggregate(x[c("XIT","XFR"),,],m,weight=w) + m <- matrix(c(c("XIT", "XIT", "XFR", "XFR"), c("ITA", "SMR", "FRA", "MCO")), 4) + w <- calcOutput("Population", years = 2005, aggregate = FALSE)[c("ITA", "SMR", "FRA", "MCO"), , "pop_SSP2"] + x_split <- toolAggregate(x[c("XIT", "XFR"), , ], m, weight = w) # delete XIT and XFR from x - x <- x[c("XIT","XFR"),,invert=TRUE] - x <- mbind(x,x_split) - + x <- x[c("XIT", "XFR"), , invert = TRUE] + x <- mbind(x, x_split) + # sort years - x <- x[,sort(getYears(x)),] - + x <- x[, sort(getYears(x)), ] + # split Germany before 2045 - x_DE <- x["DEU",,] - getRegions(x_DE) <- "XDE" - x_DE[getYears(x_DE,as.integer=TRUE)>=1945] <- 0 # set to 0 for the time after 1945 - x["DEU",,][getYears(x,as.integer=TRUE)<1945] <- 0 # set to 0 for the time before 1945 - x <- mbind(x,x_DE) - + x_DE <- x["DEU", , ] + getItems(x_DE, dim = 1) <- "XDE" + x_DE[getYears(x_DE, as.integer = TRUE) >= 1945] <- 0 # set to 0 for the time after 1945 + x["DEU", , ][getYears(x, as.integer = TRUE) < 1945] <- 0 # set to 0 for the time before 1945 + x <- mbind(x, x_DE) + # FIXME: ANT and XAN exist in CDIAC -> has to be distributed properly (for a starting point see ISOhistorical.csv) - - x[is.na(x)]<-0 - x <- toolISOhistorical(x,overwrite=TRUE) - x <- toolCountryFill(x,fill=0) + + x[is.na(x)] <- 0 + x <- toolISOhistorical(x, overwrite = TRUE) + x <- toolCountryFill(x, fill = 0, verbosity = 2, no_remove_warning = c("XAN")) getSets(x) <- getSets(new.magpie()) return(x) -} +} diff --git a/R/convertConferenceBoard.R b/R/convertConferenceBoard.R deleted file mode 100644 index 551c0fd2..00000000 --- a/R/convertConferenceBoard.R +++ /dev/null @@ -1,20 +0,0 @@ -#' convertConferenceBoard -#' @param x MAgPIE object to be converted -#' @author Aman Malik -#' @return A magpie object with country-level results - -convertConferenceBoard <- function(x){ - #x <- readSource("ConferenceBoard",convert = F) - # CHN1 is the China alternative and CHN2 is the China official numbers. - #The former is based on alternative growth estimates, while the latter is based on official data - #avg <- colMeans(x,dims = 1,na.rm = T) - #means <- colMeans(x,na.rm = T) - #means1 <- as.numeric(means["GLO","y2019","Output per person (without agriculture)"]) -y <- toolCountryFill(x[,,"Output per person (without agriculture)"],fill = 58302 )# all countries with no value get average labour productivity (without agriculture) of the world - z <- toolCountryFill(x[,,"Output per Employed Person"],fill = 54114.77) - a <- toolCountryFill(x[,,"Employment in agriculture"],fill = 0) - x <- mbind(y,z,a) - - return (x) - -} diff --git a/R/convertDLR.R b/R/convertDLR.R index 7c645ffe..c6f366b8 100644 --- a/R/convertDLR.R +++ b/R/convertDLR.R @@ -1,5 +1,5 @@ convertDLR <- function(x) { # fill all missing countries with 0 - x <- toolCountryFill(x,fill=0) + x <- toolCountryFill(x, fill = 0, verbosity = 2) return(x) } diff --git a/R/convertDaviesCooling.R b/R/convertDaviesCooling.R index 8e3880da..bfc4325f 100644 --- a/R/convertDaviesCooling.R +++ b/R/convertDaviesCooling.R @@ -1,24 +1,24 @@ #' Convert Davies Cooling -#' +#' #' Convert Davies (2013) data on on shares of cooling types using mapping from #' GCAM regions to ISO country level. -#' -#' +#' +#' #' @param x MAgPIE object containing DaviesCooling data region resolution #' @return MAgPIE object of the Davies (2013) data disaggregated to country #' level #' @author Lavinia Baumstark, Ioanna Mouratiadou #' @seealso \code{\link{readDaviesCooling}} #' @examples -#' +#' #' \dontrun{ a <- convertDaviesCooling(x) #' } -#' +#' convertDaviesCooling <- function(x) { - + mapping <- "RegionMappingDavies2ISO.csv" y <- toolAggregate(x, mapping, weight=NULL ) - y <- toolCountryFill(y,fill=0) - + y <- toolCountryFill(y, fill = 0, verbosity = 2) + return(y) } diff --git a/R/convertDias.R b/R/convertDias.R deleted file mode 100644 index 56bd1bde..00000000 --- a/R/convertDias.R +++ /dev/null @@ -1,24 +0,0 @@ -#' @title convertDias -#' @author Aman Malik -#' @param x magpie object to be converted -#' @param subtype "Employment factors" or "Employment" -#' -convertDias <- function(x,subtype){ - if (subtype=="Employment factors"){ - #x <- readSource(type = "Dias", subtype = "Employment factors", convert = F) # EFs for coal and coal mining - - getRegions(x) <- toolCountry2isocode(getRegions(x)) - x <- toolCountryFill(x,fill=NA) - } - if (subtype=="Employment"){ - #x <- readSource(type = "Dias", subtype = "Employment", convert = F) # EFs for coal and coal mining - getNames(x) <- gsub(getNames(x),pattern = "mine",replacement = "Fuel_supply") - getNames(x) <- gsub(getNames(x),pattern = "power_plant",replacement = "OM") - getSets(x)[4] <- "activity" - x <- add_dimension(x,dim = 3.3,add = "tech",nm = "Coal") - getRegions(x) <- toolCountry2isocode(getRegions(x)) - x <- toolCountryFill(x,fill=NA) - } - return (x) - -} diff --git a/R/convertDylanAusGasCost.R b/R/convertDylanAusGasCost.R index ac521bc6..e32764f5 100644 --- a/R/convertDylanAusGasCost.R +++ b/R/convertDylanAusGasCost.R @@ -4,20 +4,16 @@ #' @author Felix Schreyer #' @seealso \code{\link{readSource}} +convertDylanAusGasCost <- function(x) { + all_c <- toolGetMapping("regionmappingH12.csv", where = "mappingfolder", type = "regional") - -convertDylanAusGasCost <- function(x){ - - - all_c <- toolGetMapping("regionmappingH12.csv",where = "mappingfolder",type = "regional") - - # converting to 2005USD, conversion factor from 2015AUSD to 2005USD assumed 0.6 + # converting to 2005USD, conversion factor from 2015AUSD to 2005USD assumed 0.6 x_help <- x * 0.6 - x_help <- add_dimension(x_help, dim=3.4, add="unit", nm = "Natural Gas Extraction Cost [2005USD/GJ]") + x_help <- add_dimension(x_help, dim = 3.4, add = "unit", nm = "Natural Gas Extraction Cost [2005USD/GJ]") - x = new.magpie(all_c$CountryCode, getYears(x_help), getNames(x_help), fill=0) - x["AUS",,] <- x_help + x <- new.magpie(all_c$CountryCode, getYears(x_help), getNames(x_help), fill = 0) + x["AUS", , ] <- x_help return(x) } diff --git a/R/convertECLIPSE.R b/R/convertECLIPSE.R index 9f1b39cb..fd651bd9 100755 --- a/R/convertECLIPSE.R +++ b/R/convertECLIPSE.R @@ -1,4 +1,4 @@ -#' @importFrom dplyr group_by_ min_rank select_ mutate_ +#' @importFrom dplyr min_rank #' @importFrom quitte as.quitte convertECLIPSE <- function(x, subtype) { @@ -104,7 +104,7 @@ convertECLIPSE <- function(x, subtype) { #-- Regional downscaling --------------- if (downscaling) { - m <- toolGetMapping(type = "regional", name = "regionmappingGAINS.csv", + m <- toolGetMapping(type = "regional", name = "regionmappingGAINS.csv", returnPathOnly = TRUE, where = "mappingfolder") # Get GAINS regional mapping @@ -120,7 +120,7 @@ convertECLIPSE <- function(x, subtype) { x <- toolAggregate(x[, , ], map, weight = w) # fill all missing countries with 0 (add Antarctica) - x <- toolCountryFill(x, fill = 0) + x <- toolCountryFill(x, fill = 0, verbosity = 2) } } @@ -131,7 +131,7 @@ convertECLIPSE <- function(x, subtype) { #-- Regional downscaling --------------- if (downscaling) { - m <- toolGetMapping(type = "regional", name = "regionmappingGAINS.csv", + m <- toolGetMapping(type = "regional", name = "regionmappingGAINS.csv", returnPathOnly = TRUE, where = "mappingfolder") # Get GAINS regional mapping @@ -147,7 +147,7 @@ convertECLIPSE <- function(x, subtype) { x <- toolAggregate(x[, , ], map, weight = w) # fill all missing countries with 0 (add Antarctica) - x <- toolCountryFill(x, fill = 0) + x <- toolCountryFill(x, fill = 0, verbosity = 2) } } diff --git a/R/convertEDGAR7Fgases.R b/R/convertEDGAR7Fgases.R index fed91cf6..7a3130ce 100644 --- a/R/convertEDGAR7Fgases.R +++ b/R/convertEDGAR7Fgases.R @@ -3,108 +3,93 @@ #' @param x magpie object to be converted #' #' @export - convertEDGAR7Fgases <- function(x) { - # F-gases emissions in kt of each species - # x <- readSource("EDGAR7Fgases") - - # Aggregate regions, but not species yet - x[is.na(x)] <- 0 #set NA to 0 - x <- toolCountryFill(x,fill=0,verbosity=0) # fill missing countries - # map <- toolGetMapping(getConfig("regionmapping", where = "mappingfolder"),type="regional") - # fgaskt <- toolAggregate(x,map,weight=NULL) - fgaskt <- x - - - # Converting to CO2 equivalent - - # Read AR6 GWP table - dfgwp <- readSource("AR6GWP") - - # Rename some gases in the AR6 table to be compatible with the names in EDGAR - dfgwp$Gas[dfgwp$Gas == "PFC-116"] <- "C2F6" - dfgwp$Gas[dfgwp$Gas == "PFC-14"] <- "CF4" - dfgwp$Gas[dfgwp$Gas == "Sulfur hexafluoride"] <- "SF6" - dfgwp$Gas[dfgwp$Gas == "PFC-218"] <- "C3F8" - dfgwp$Gas[dfgwp$Gas == "PFC-31-10"] <- "C4F10" - dfgwp$Gas[dfgwp$Gas == "Octafluorooxolane"] <- "c-C4F8" # Formula is actually c-C4F8O, but couldn't find anything on a gas without the O so assuming a typo in EDGAR - dfgwp$Gas[dfgwp$Gas == "HFC-43-10mee"] <- "HFC-43-10-mee" - dfgwp$Gas[dfgwp$Gas == "Nitrogen trifluoride"] <- "NF3" - dfgwp$Gas[dfgwp$Gas == "PFC-41-12"] <- "C5F12" - dfgwp$Gas[dfgwp$Gas == "PFC-51-14"] <- "C6F14" - - # Gas species in EDGAR data - gases_edgar <- getItems(fgaskt,"Gas") - - # Gas species in AR6 data - gases_ar6 <- dfgwp[["Gas"]] - - # Check if there are gases in EDGAR without a GWP in AR6 and throw a warning - unknown_gases <- setdiff(gases_edgar, intersect(gases_ar6,gases_edgar)) - if (length(unknown_gases) > 0) { - warning(paste0("calcEDGAR7Fgases couldn't find GWPs for the following gases: ",paste(unknown_gases, collapse = ","))) - } - - # Keep only used gases - dfgwp <- dfgwp[dfgwp$Gas %in% gases_edgar,] - - # Convert to MAgPIE object - gwp <- as.magpie(dfgwp, spatial = 0, temporal = 0) - - # Multiply to get emissions per species in kt CO2eq, convert to Mt - co2eq_gas <- fgaskt*gwp*1e-3 - - # To keep with the IMAGE standard, we have to report total F-gases (in Mt CO2eq) plus - # individual emissions of the following gases (in kt of themselves): - # HFC, which is the total of HFC125, HFC134a, HFC143a, HFC227ea, HFC23, HFC245fa, HFC32, HFC43-10 - # HFC125, HFC134a, HFC143a, HFC227ea, HFC23, HFC245fa, HFC32, HFC43-10, PFC, SF6, C2F6, C6F14, CF4 - - # Total CO2eq - co2eq_tot <- setNames(dimSums(co2eq_gas, 3.1), "emiFgasTotal") - # getSets(co2eq_tot)[3] <- "Gas" - - # PFC and HFC gases - gases_pfc <- c("CF4","C2F6","C3F8","C4F10","C5F12","C6F14") - gases_hfc <- c("HFC-125", "HFC-134a", "HFC-143a", "HFC-152a", "HFC-227ea", "HFC-245fa", "HFC-32", "HFC-365mfc", "HFC-23","HFC-134", - "HFC-143", "HFC-236fa", "HFC-41", "HFC-43-10-mee") - - pfc_tot <- setNames(dimSums(fgaskt[,,gases_pfc], 3.1), "emiFgasPFC") - hfc_tot <- setNames(dimSums(fgaskt[,,gases_hfc], 3.1), "emiFgasHFC") - - - # Individual gases - # report_gases <- c("HFC125","HFC134a","HFC143a","HFC227ea","HFC23","HFC245fa","HFC32","HFC43-10","PFC","SF6","C2F6","C6F14","CF4") - # First rename the individual gases - eminame_mapping <-c( - "HFC-125" = "emiFgasHFC125", - "HFC-134a" = "emiFgasHFC134a", - "HFC-143a" = "emiFgasHFC143a", - "HFC-227ea" = "emiFgasHFC227ea", - "HFC-245fa" = "emiFgasHFC245fa", - "HFC-43-10-mee" = "emiFgasHFC43-10", - "HFC-32" = "emiFgasHFC32", - "C2F6" = "emiFgasC2F6", - "CF4" = "emiFgasCF4", - "SF6" = "emiFgasSF6", - "HFC-23" = "emiFgasHFC23", - "C6F14" = "emiFgasC6F14" - ) - - fgaskt_ind <- fgaskt[,,names(eminame_mapping)] - fgaskt_ind <- setNames(fgaskt_ind,eminame_mapping) - - # Bind all gases in the format already used by REMIND (legacy of IMAGE's reported species) - xout <- mbind(co2eq_tot, hfc_tot, pfc_tot, fgaskt_ind) - - return(xout) - # # Write units more or less automatically from the mapping names - # outunits <- paste0("kt ",gsub("emiFgas","",getNames(xout)),"/yr") - # outunits[1] <- "Mt CO2eq/yr" - - # return(list( - # x = xout, - # weight = NULL, - # unit = outunits, - # description = "F-gas emissions from EDGAR7" - # )) + # Aggregate regions, but not species yet + x[is.na(x)] <- 0 # set NA to 0 + x <- toolCountryFill(x, fill = 0, verbosity = 2) # fill missing countries + + fgaskt <- x + + # Converting to CO2 equivalent + + # Read AR6 GWP table + dfgwp <- readSource("AR6GWP") + + # Rename some gases in the AR6 table to be compatible with the names in EDGAR + dfgwp$Gas[dfgwp$Gas == "PFC-116"] <- "C2F6" + dfgwp$Gas[dfgwp$Gas == "PFC-14"] <- "CF4" + dfgwp$Gas[dfgwp$Gas == "Sulfur hexafluoride"] <- "SF6" + dfgwp$Gas[dfgwp$Gas == "PFC-218"] <- "C3F8" + dfgwp$Gas[dfgwp$Gas == "PFC-31-10"] <- "C4F10" + dfgwp$Gas[dfgwp$Gas == "Octafluorooxolane"] <- "c-C4F8" # Formula is actually c-C4F8O, but couldn't find anything on a gas without the O so assuming a typo in EDGAR + dfgwp$Gas[dfgwp$Gas == "HFC-43-10mee"] <- "HFC-43-10-mee" + dfgwp$Gas[dfgwp$Gas == "Nitrogen trifluoride"] <- "NF3" + dfgwp$Gas[dfgwp$Gas == "PFC-41-12"] <- "C5F12" + dfgwp$Gas[dfgwp$Gas == "PFC-51-14"] <- "C6F14" + + # Gas species in EDGAR data + gases_edgar <- getItems(fgaskt, "Gas") + + # Gas species in AR6 data + gases_ar6 <- dfgwp[["Gas"]] + + # Check if there are gases in EDGAR without a GWP in AR6 and throw a warning + unknown_gases <- setdiff(gases_edgar, intersect(gases_ar6, gases_edgar)) + if (length(unknown_gases) > 0) { + warning(paste0("calcEDGAR7Fgases couldn't find GWPs for the following gases: ", + paste(unknown_gases, collapse = ","))) + } + + # Keep only used gases + dfgwp <- dfgwp[dfgwp$Gas %in% gases_edgar, ] + + # Convert to MAgPIE object + gwp <- as.magpie(dfgwp, spatial = 0, temporal = 0) + + # Multiply to get emissions per species in kt CO2eq, convert to Mt + co2eq_gas <- fgaskt * gwp * 1e-3 + + # To keep with the IMAGE standard, we have to report total F-gases (in Mt CO2eq) plus + # individual emissions of the following gases (in kt of themselves): + # HFC, which is the total of HFC125, HFC134a, HFC143a, HFC227ea, HFC23, HFC245fa, HFC32, HFC43-10 + # HFC125, HFC134a, HFC143a, HFC227ea, HFC23, HFC245fa, HFC32, HFC43-10, PFC, SF6, C2F6, C6F14, CF4 + + # Total CO2eq + co2eq_tot <- setNames(dimSums(co2eq_gas, 3.1), "emiFgasTotal") + + # PFC and HFC gases + gases_pfc <- c("CF4", "C2F6", "C3F8", "C4F10", "C5F12", "C6F14") + gases_hfc <- c( + "HFC-125", "HFC-134a", "HFC-143a", "HFC-152a", "HFC-227ea", "HFC-245fa", + "HFC-32", "HFC-365mfc", "HFC-23", "HFC-134", + "HFC-143", "HFC-236fa", "HFC-41", "HFC-43-10-mee" + ) + + pfc_tot <- setNames(dimSums(fgaskt[, , gases_pfc], 3.1), "emiFgasPFC") + hfc_tot <- setNames(dimSums(fgaskt[, , gases_hfc], 3.1), "emiFgasHFC") + + # Individual gases + # First rename the individual gases + eminame_mapping <- c( + "HFC-125" = "emiFgasHFC125", + "HFC-134a" = "emiFgasHFC134a", + "HFC-143a" = "emiFgasHFC143a", + "HFC-227ea" = "emiFgasHFC227ea", + "HFC-245fa" = "emiFgasHFC245fa", + "HFC-43-10-mee" = "emiFgasHFC43-10", + "HFC-32" = "emiFgasHFC32", + "C2F6" = "emiFgasC2F6", + "CF4" = "emiFgasCF4", + "SF6" = "emiFgasSF6", + "HFC-23" = "emiFgasHFC23", + "C6F14" = "emiFgasC6F14" + ) + + fgaskt_ind <- fgaskt[, , names(eminame_mapping)] + fgaskt_ind <- setNames(fgaskt_ind, eminame_mapping) + + # Bind all gases in the format already used by REMIND (legacy of IMAGE's reported species) + xout <- mbind(co2eq_tot, hfc_tot, pfc_tot, fgaskt_ind) + + return(xout) } diff --git a/R/convertEDGETransport.R b/R/convertEDGETransport.R index 85beece7..9a16041b 100644 --- a/R/convertEDGETransport.R +++ b/R/convertEDGETransport.R @@ -1,24 +1,33 @@ #' Convert EDGEtransport #' -#' Ship EDGETransport data through, as already on ISO level -#' -#' @param subtype EDGE entries -#' @param x MAgPIE object containing EDGE values at ISO country resolution -#' @return EDGETransport data as MAgPIE object disaggregated to ISO level -#' @author Marianna Rottoli -#' +#' @param subtype REMIND/iterative EDGE-T input data subtypes +#' @param x MAgPIE object containing EDGE-T values in 21 region resolution +#' @return REMIND/iterative EDGE-T input data as MAgPIE object disaggregated to ISO level #' @importFrom data.table setDT -#' +#' @importFrom madrat toolAggregate +#' @author Johanna Hoppe + convertEDGETransport = function(x, subtype) { mappingfile <- setDT(toolGetMapping("regionmapping_21_EU11.csv", type = "regional", where = "mappingfolder"))[, .(iso = CountryCode, region = RegionCode)] - if subtype %in% c() { - gdp <- calcOutput("GDP", aggregate = F) - x = toolAggregate(x = x, weight = gdp, rel = mappingfile, from = "region", to = "iso") - } else { + if (subtype %in% c("f35_demByTech", "f29_trpdemand", "weightESdemand")) { + gdp <- calcOutput("GDP", aggregate = FALSE) |> time_interpolate(getYears(x), extrapolation_type = "constant") + gdp <- gdp[,,"gdp_SSP2"] + result <- toolAggregate(x = x, weight = gdp, rel = mappingfile, from = "region", to = "iso") + } else if (!subtype == "shares_LDV_transport") { result <- toolAggregate(x = x, rel = mappingfile, weight = NULL, from = "region", to = "iso") - } + } else if (subtype %in% c("shares_LDV_transport")) { + ## only the first EDGE-T scenario for SSP2 is used as a proxy for the LDV shares + x <- x[,, "gdp_SSP2.Mix1.gdp_SSP2.share_LDV_totliq.shares_LDV_transport"] + for (year in getYears(x, as.integer = T)){ + x[,year,] <- as.vector(x[,c(2010),]) + ((0.55 - as.vector(x[,c(2010),]))/(2100-2010))*(year-2010) + } + #extending values + x <- time_interpolate(x, integrate_interpolated_years=T, interpolated_year = seq(from = 1990, to = 2100), extrapolation_type = "linear") + x <- time_interpolate(x, integrate_interpolated_years=T, interpolated_year = c(seq(from = 1970, to = 1989),seq(from = 2101, to = 2150)), extrapolation_type = "constant") + result <- x + } return(result) } diff --git a/R/convertEdgeBuildings.R b/R/convertEdgeBuildings.R index d013fdcd..2bf2152f 100644 --- a/R/convertEdgeBuildings.R +++ b/R/convertEdgeBuildings.R @@ -5,7 +5,6 @@ #' @return EDGE data as MAgPIE object aggregated to country level #' @author Antoine Levesque, Robin Hasse #' -#' @importFrom magclass new.magpie getItems<- getNames getSets getYears mselect mbind convertEdgeBuildings <- function(x, subtype = "FE") { #---- Functions ------------- @@ -148,7 +147,7 @@ convertEdgeBuildings <- function(x, subtype = "FE") { xadd <- toolAggregate(x, mappingfile, weight = wfe, from = region_col, to = iso_col) - result <- toolCountryFill(xadd, 0) + result <- toolCountryFill(xadd, 0, verbosity = 2) # Attribute the growth in water heating demand of the EDGE Region OCD to TUR, # and retrieve it from AUS, CAN, CHE (Swiss), NOR, NZL diff --git a/R/convertEmber.R b/R/convertEmber.R index d63dad18..9ca253e3 100644 --- a/R/convertEmber.R +++ b/R/convertEmber.R @@ -8,14 +8,13 @@ #' #' @author Pascal Weigmann #' -#' @importFrom madrat toolCountryFill #' #' @export convertEmber <- function(x) { # add missing countries - x <- toolCountryFill(x, fill = 0, verbosity = 2) + x <- toolCountryFill(x, fill = 0, verbosity = 2, no_remove_warning = "XKX") # replace NA by 0 to enable aggregation over incomplete regions x[is.na(x)] <- 0 diff --git a/R/convertEuropeanEnergyDatasheets.R b/R/convertEuropeanEnergyDatasheets.R index 88008376..9633ea4b 100644 --- a/R/convertEuropeanEnergyDatasheets.R +++ b/R/convertEuropeanEnergyDatasheets.R @@ -17,10 +17,8 @@ convertEuropeanEnergyDatasheets <- function(x, subtype) { getItems(x, dim = 1) <- sapply(getRegions(x), function(y) iso3[which(iso3[, 1] == y), 2]) # fill up zero countries - x <- toolCountryFill(x, fill = NA, verbosity = 2) - - # fill smaller EU-countries with 0s to allow for aggregation of EU-region - x[c("ALA", "FRO", "GIB", "GGY", "IMN", "JEY"), , ] <- 0 + x <- toolCountryFill(x, fill = NA, verbosity = 2) %>% + toolFillEU34Countries() # in never mapping, this is handled directly in mapping if (subtype == "EU28") { diff --git a/R/convertEurostat_EffortSharing.R b/R/convertEurostat_EffortSharing.R index f245a90d..0014400b 100644 --- a/R/convertEurostat_EffortSharing.R +++ b/R/convertEurostat_EffortSharing.R @@ -1,21 +1,21 @@ -#' Converts EU Effort Sharing targets and historical emissions -#' +#' Converts EU Effort Sharing targets and historical emissions +#' #' @param x MAgPIE object to be converted #' @param subtype data subtype. Either "target" or "emissions" -#' @return A MAgPIE object containing the EU Effort Sharing targets (%) or Effort Sharing historical emissions (MtCO2) +#' @return A MAgPIE object containing the EU Effort Sharing targets (%) or Effort Sharing historical emissions (MtCO2) #' @author Renato Rodrigues #' @examples -#' +#' #' \dontrun{ a <- convertEurostat_EffortSharing(x,subtype="target") #' } -#' +#' convertEurostat_EffortSharing <- function(x,subtype) { # fill countries with no data - x <- toolCountryFill(x,fill=0,verbosity=0) + x <- toolCountryFill(x, fill = 0, verbosity = 2) # replace NAs with 0 x[is.na(x)] <- 0 return(x) } - - + + diff --git a/R/convertExpertGuess.R b/R/convertExpertGuess.R index 010fc205..f497475e 100644 --- a/R/convertExpertGuess.R +++ b/R/convertExpertGuess.R @@ -1,24 +1,25 @@ #' @title convertExpertGuess #' @description Converts data from expert guess #' @param x unconverted magpie object from read-script -#' @param subtype Type of data that are converted. -#' +#' @param subtype Type of data that are converted. +#' #' @return magpie object with a completed dataset. -#' +#' #' @seealso #' \code{\link{convertExpertGuess}} -convertExpertGuess <- function(x,subtype) -{ - - if (subtype == "costsTradePeFinancial"){ +convertExpertGuess <- function(x, subtype) { + if (subtype == "costsTradePeFinancial") { # use data for each country that belongs to a region # No weighting for spatial aggregation - out <- toolAggregate(x, toolGetMapping(type = "regional", name = "regionmappingH12.csv", - returnPathOnly = TRUE, where = "mappingfolder"), - weight=NULL) - } else { + out <- toolAggregate(x, toolGetMapping( + type = "regional", name = "regionmappingH12.csv", + returnPathOnly = TRUE, where = "mappingfolder" + ), + weight = NULL + ) + } else { out <- x } diff --git a/R/convertGEA2012.R b/R/convertGEA2012.R index 00af0f96..606d6926 100644 --- a/R/convertGEA2012.R +++ b/R/convertGEA2012.R @@ -6,53 +6,55 @@ #' @author Stephen Bi #' @seealso \code{\link{readSource}} #' @examples -#' -#' \dontrun{ a <- readSource("GEA2012") +#' \dontrun{ +#' a <- readSource("GEA2012") #' } -#' - -convertGEA2012 <- function(x,subtype) { - if (subtype=='coal') { - #Load mapping file for GEA regions to country level - mapping <- toolGetMapping("regionmappingREMIND.csv","regional", where = "mappingfolder") - #Load country-level BGR data on coal combined reserve & resource distribution to serve as a disaggregation weight - w <- read.csv(paste0(getConfig("sourcefolder"),"/BGR/coal_reserves.csv"),header=TRUE,sep=";")[,c("Land_Region","Remaining_Potential")] - #convert the data into a magpie object, convert countries to ISO code and set missing countries to 0 - w <- as.magpie(w,spatial=1,temporal=0,datacol=2) - getRegions(w) <- toolCountry2isocode(getRegions(w)) - w <- toolNAreplace(toolCountryFill(w,fill=0))[[1]] - #Disaggregate GEA coal data to country level based on the BGR weights - out <- toolAggregate(x[,,'xi3'],mapping,w) - #Cost data xi1 and xi2 kept constant across regions - out <- mbind(out,toolAggregate(x[,,c('xi1','xi2')],mapping,weight=NULL)) - }else if (subtype %in% c('oil','gas')) { - #Load mapping file for GEA regions to country level - mapping <- toolGetMapping("regionmappingGEA2012.csv","regional") - mapping$RegionCode[which(mapping$RegionCode=="ARC")] <- "WEU" - mapping$RegionCode[which(mapping$RegionCode=="SOO")] <- "LAC" +#' +convertGEA2012 <- function(x, subtype) { + if (subtype == "coal") { + + # Load mapping file for GEA regions to country level + mapping <- toolGetMapping("regionmappingREMIND.csv", "regional", where = "mappingfolder") + + # Load country-level BGR data on coal combined reserve & resource distribution to serve as a disaggregation weight + w <- readSource("BGR", subtype = "coal", convert = FALSE)[, , "Remaining_Potential"] + getItems(w, dim = 1) <- toolCountry2isocode(getRegions(w)) + w <- toolNAreplace(toolCountryFill(w, fill = 0, verbosity = 2))[[1]] + + # Disaggregate GEA coal data to country level based on the BGR weights + out <- toolAggregate(x[, , "xi3"], mapping, w) + + # Cost data xi1 and xi2 kept constant across regions + out <- mbind(out, toolAggregate(x[, , c("xi1", "xi2")], mapping, weight = NULL)) + + } else if (subtype %in% c("oil", "gas")) { + + # Load mapping file for GEA regions to country level + mapping <- toolGetMapping("regionmappingGEA2012.csv", "regional", where = "mappingfolder") + mapping$RegionCode[which(mapping$RegionCode == "ARC")] <- "WEU" + mapping$RegionCode[which(mapping$RegionCode == "SOO")] <- "LAC" # Divide ARC fuels equally among EUR (WEU), USA, RUS (FSU), CAN # UNCLOS not ratified by USA, and territorial dispute would be uncertain even if it were for (reg in c("WEU", "USA", "FSU", "CAN")) { - x[reg,,"xi3"] <- x[reg,,"xi3"] + 0.25 * x["ARC",,"xi3"] + x[reg, , "xi3"] <- x[reg, , "xi3"] + 0.25 * x["ARC", , "xi3"] } - x <- x[getRegions(x)!="ARC",,] #Remove ARC region + x <- x["ARC", , invert = TRUE] # Remove ARC region + # Antarctic Treaty banned resource extraction until at least 2048 - x <- x[getRegions(x)!="SOO",,] #Remove SOO region - - #Read country-level BGR data, distinguished between reserves and resources - w <- read.csv(paste0(getConfig("sourcefolder"),"/BGR/",subtype,"_reserves.csv"),header=TRUE,sep=";")[,c("Land_Region","Reserves","Resources")] - #Remove NAs - w[is.na(w)] <- 0 - #Convert to magpie for use as a disaggregation weight, convert countries to ISO code and set missing countries to 0 - w <- as.magpie(w,spatial=1,temporal=0,datacol=2) - getRegions(w) <- toolCountry2isocode(getRegions(w)) - w <- toolNAreplace(toolCountryFill(w,fill=0))[[1]] - #Disaggregate the GEA data according to the BGR data on country-level oil/gas combined reserves + resources - w <- dimSums(w,dim=3) - out <- toolAggregate(x[,,getNames(x[,,'xi3'])],mapping,weight=w) - #Cost data xi1 and xi2 kept constant across regions - out <- mbind(out,toolAggregate(x[,,c('xi1','xi2','dec')],mapping,weight=NULL)) + x <- x["SOO", , invert = TRUE] # Remove SOO region + + # Read country-level BGR data, distinguished between reserves and resources + w <- readSource("BGR", subtype = subtype, convert = FALSE)[, , c("Reserves", "Resources")] + getItems(w, dim = 1) <- toolCountry2isocode(getRegions(w)) + w <- toolNAreplace(toolCountryFill(w, fill = 0, verbosity = 2))[[1]] + + # Disaggregate the GEA data according to the BGR data on country-level oil/gas combined reserves + resources + w <- dimSums(w, dim = 3) + out <- toolAggregate(x[, , getNames(x[, , "xi3"])], mapping, weight = w) + + # Cost data xi1 and xi2 kept constant across regions + out <- mbind(out, toolAggregate(x[, , c("xi1", "xi2", "dec")], mapping, weight = NULL)) } - + return(out) } diff --git a/R/convertGGDC10.R b/R/convertGGDC10.R index 8f8ae4f2..493ef516 100644 --- a/R/convertGGDC10.R +++ b/R/convertGGDC10.R @@ -7,14 +7,13 @@ #' a <- convertGGDC10(x) #' } #' -#' @importFrom madrat toolCountryFill convertGGDC10 <- function(x) { #removing unnecessary regions data <- x[!(getItems(x, dim = 1) %in% c("NGA(alt)", "DEW", "MOR")), , ] data[is.na(data)] <- 0 - data <- toolCountryFill(data, fill = 0) + data <- toolCountryFill(data, fill = 0, verbosity = 2) return(data) diff --git a/R/convertGini.R b/R/convertGini.R index d1df9720..c47808b4 100644 --- a/R/convertGini.R +++ b/R/convertGini.R @@ -1,51 +1,53 @@ #' Convert Gini -#' -#' Converts Gini data from readGini() to ISO country level. -#' Countries missing in the original data set will have their Gini set to zero (a very small number for numerical reasons to be precise). -#' The original data range is 2011-2100 in one-year steps, here we extend it to 2000-2150 in 5-year steps. +#' +#' Converts Gini data from readGini() to ISO country level. +#' Countries missing in the original data set will have their Gini set to zero ( +#' a very small number for numerical reasons to be precise). +#' The original data range is 2011-2100 in one-year steps, +#' here we extend it to 2000-2150 in 5-year steps. #' Values before (after) the original range are held fixed at 2011 (2100) levels. #' Gini values for the SDP scenario are taken from the SSP1 scenario -#' -#' +#' +#' #' @param x MAgPIE object containing Gini data with World Bank codes, 2011-2100, in percent (range 0-100) #' @return MAgPIE object of the Gini data in ISO countries, range 0-1 #' @author Bjoern Soergel #' @seealso \code{\link{readSource}} \code{\link{readGini}} #' @examples -#' -#' \dontrun{ a <- convertGini(x) +#' \dontrun{ +#' a <- convertGini(x) #' } -#' @importFrom countrycode countrycode - - -convertGini <- function(x){ - +convertGini <- function(x) { # add SDP scenario, with same data as SSP1 - xSDP <- x[,,"SSP1"] + xSDP <- x[, , "SSP1"] getNames(xSDP) <- "SDP" - x <- mbind(x,xSDP) + x <- mbind(x, xSDP) # add SSP2EU, same data as SSP2 - xSSP2EU <- x[,,"SSP2"] + xSSP2EU <- x[, , "SSP2"] getNames(xSSP2EU) <- "SSP2EU" - x <- mbind(x,xSSP2EU) - + x <- mbind(x, xSSP2EU) + # conversion to iso3c codes, match Somalia by hand because countrycode fails - getRegions(x) <- countrycode(getRegions(x), origin = 'wb', destination = 'iso3c' , custom_match = c('SOM' = 'SOM')) - getSets(x)[1] <- 'iso3c' - + getItems(x, dim = 1) <- countrycode::countrycode(getRegions(x), + origin = "wb", + destination = "iso3c", + custom_match = c("SOM" = "SOM")) + getSets(x)[1] <- "iso3c" + # fill missing countries with a small number (not zero because this might cause numerical problems in Gini aggregation later) - x <- toolCountryFill(x, fill = 1e-8) - + x <- toolCountryFill(x, fill = 1e-8, verbosity = 2) + # fill years outside original range # NB: time_interpolate breaks set names, so restore them explicitly xsets <- getSets(x) - x <- time_interpolate(x,interpolated_year = c(seq(2000,2010,by=5),seq(2105,2150,by=5)), integrate_interpolated_years = TRUE, extrapolation_type = 'constant') - x <- x[,seq(2000,2150,by=5),] + x <- time_interpolate(x, interpolated_year = c(seq(2000, 2010, by = 5), seq(2105, 2150, by = 5)), + integrate_interpolated_years = TRUE, extrapolation_type = "constant") + x <- x[, seq(2000, 2150, by = 5), ] getSets(x) <- xsets - - #convert to 0..1 range - x <- x/100 + + # convert to 0..1 range + x <- x / 100 return(x) } diff --git a/R/convertGlobalCCSinstitute.R b/R/convertGlobalCCSinstitute.R index 7ee2392f..6373603b 100644 --- a/R/convertGlobalCCSinstitute.R +++ b/R/convertGlobalCCSinstitute.R @@ -1,15 +1,33 @@ +#' Convert Global CCS Institute Project Database +#' +#' @md +#' @param x A [`magpie`][magclass::magclass] object returned by +#' [readGlobalCCSinstitute()]. +#' @inherit readGlobalCCSinstitute +#' +#' @return A [`magpie`][magclass::magclass] object. +#' +#' @importFrom quitte add_countrycode_ madrat_mule +#' +#' @export +convertGlobalCCSinstitute <- function(x, subtype = '08-09-2017') { + if ('08-09-2017' == subtype) { # 08-09-2017 ---- - -convertGlobalCCSinstitute <- function(x) { - # sum over districts of a country - y <- dimSums(x,dim=3) - + y <- dimSums(x, dim = 3) + # transfer into ISO country names - getRegions(y) <- toolCountry2isocode(getRegions(y)) - + getItems(y, dim = 1) <- toolCountry2isocode(getRegions(y)) + # fill all other countries with 0 - y <- toolCountryFill(y, fill = 0, verbosity=2) - - return(y) + y <- toolCountryFill(y, fill = 0, verbosity = 2) + + return(y) + } + else if ('2023-11' == subtype) { # 2023-11 ---- + stop('Subtype "2023-11" does not support conversion.') + } + else { + stop('Unsupported version argument.') + } } diff --git a/R/convertGlobalEnergyMonitor.R b/R/convertGlobalEnergyMonitor.R index 26b07f6d..4f883da3 100644 --- a/R/convertGlobalEnergyMonitor.R +++ b/R/convertGlobalEnergyMonitor.R @@ -1,17 +1,12 @@ #' Convert Global Energy Monitor data #' -#' @md -#' @param x A [`magpie`][magclass::magclass] object returned from -#' [`readGlobalEnergyMonitor()`]. +#' @author Rahel Mandaroux, Falk Benke #' -#' @return A [`magpie`][magclass::magclass] object. -#' -#' @author Falk Benke -#' -#' @importFrom madrat toolCountry2isocode toolCountryFill +#' @param x A magclass object returned from readGlobalEnergyMonitor(). #' #' @export convertGlobalEnergyMonitor <- function(x) { getItems(x, dim = 1) <- toolCountry2isocode(getItems(x, dim = 1)) - return(toolCountryFill(x, no_remove_warning = "KOS")) + x <- toolCountryFill(x, no_remove_warning = "KOS", verbosity = 2, fill = 0) + return(x) } diff --git a/R/convertHRE.R b/R/convertHRE.R index b37a8c66..425b90b4 100644 --- a/R/convertHRE.R +++ b/R/convertHRE.R @@ -8,7 +8,6 @@ #' #' @author Pascal Weigmann #' -#' @importFrom madrat toolCountryFill #' #' @export diff --git a/R/convertIAEA.R b/R/convertIAEA.R index d50fa54f..a8a7e188 100644 --- a/R/convertIAEA.R +++ b/R/convertIAEA.R @@ -1,22 +1,21 @@ #' Nuclear data from world-nuclear.org -#' @description Data on currently operating and under-construction nuclear power plants, reactors planned and proposed, -#' electricity generation from nuclear +#' @description Data on currently operating and under-construction nuclear power plants, reactors planned and proposed, +#' electricity generation from nuclear #' @author Christoph Bertram - #' @param x MAgPIE object to be converted - +#' @param x MAgPIE object to be converted + convertIAEA <- function(x) { - - # remove world data - x <- x["WORLD",,,invert=TRUE] - # Data for TAiwan in 2020 is given seperately and not included in the list - x["Taiwan","y2020","REACTORS OPERABLE (MWe net)"] <- 3719 - x["Taiwan","y2020","REACTORS OPERABLE (No)"] <- 4 - x["Taiwan","y2020","NUCLEAR ELECTRICITY GENERATION (billion kWh)"] <- 26.7 - # rename countries into ISO - getRegions(x) <- toolCountry2isocode(getRegions(x)) - # fill missing countries - x <- toolCountryFill(x,fill=0,verbisity=2) - x[is.na(x)] <- 0 - - return(x) -} + # remove world data + x <- x["WORLD", , , invert = TRUE] + # Data for Taiwan in 2020 is given separately and not included in the list + x["Taiwan", "y2020", "REACTORS OPERABLE (MWe net)"] <- 3719 + x["Taiwan", "y2020", "REACTORS OPERABLE (No)"] <- 4 + x["Taiwan", "y2020", "NUCLEAR ELECTRICITY GENERATION (billion kWh)"] <- 26.7 + # rename countries into ISO + getItems(x, dim = 1) <- toolCountry2isocode(getItems(x, dim = 1)) + # fill missing countries + x <- toolCountryFill(x, fill = 0, verbosity = 2) + x[is.na(x)] <- 0 + + return(x) +} diff --git a/R/convertIEA_CCUS.R b/R/convertIEA_CCUS.R new file mode 100644 index 00000000..4ef4c490 --- /dev/null +++ b/R/convertIEA_CCUS.R @@ -0,0 +1,16 @@ +#' Convert IEA CCUS data +#' +#' @md +#' @param x A magclass object returned from readIEA_CCUS(). +#' +#' @return A magclass object. +#' +#' @author Anne Merfort, Falk Benke +#' +#' +#' @export +convertIEA_CCUS <- function(x) { + getItems(x, dim = 1) <- toolCountry2isocode(getItems(x, dim = 1)) + x <- toolCountryFill(x, fill = 0, verbosity = 2) + return(x) +} diff --git a/R/convertIEA_ETP.R b/R/convertIEA_ETP.R index 8a602f7c..60d5738f 100644 --- a/R/convertIEA_ETP.R +++ b/R/convertIEA_ETP.R @@ -3,8 +3,6 @@ #' @author Falk Benke #' @param x IEA ETP projection magpie object derived from readIEA_ETP function #' @param subtype data subtype. Either "industry", "buildings", "summary", or "transport" -#' @importFrom madrat toolGetMapping getISOlist -#' @importFrom dplyr %>% #' convertIEA_ETP <- function(x, subtype) { diff --git a/R/convertIEA_EVOutlook.R b/R/convertIEA_EVOutlook.R index 7e5dafce..b1a99dc4 100644 --- a/R/convertIEA_EVOutlook.R +++ b/R/convertIEA_EVOutlook.R @@ -4,88 +4,13 @@ #' @author Falk Benke convertIEA_EVOutlook <- function(x) { - Non28EUcountries <- c("ALA", "FRO", "GIB", "GGY", "IMN", "JEY") - - w <- calcOutput("GDPPast", aggregate = F)[, "y2015", ] - mapping <- toolGetMapping(type = "regional", name = "regionmappingH12.csv", where = "mappingfolder") - - .removeNaRegions <- function(x) { - remove <- magpply(x, function(y) all(is.na(y)), MARGIN = 1) - return(x[!remove, , ]) - } - - .disaggregate_other_europe <- function(x1, var) { - - # get eu countries that do not belong to "Other Europe" for this variable - eu.countries <- getItems(.removeNaRegions(x[, , var]), dim = 1) - - # get mapping to "Other Europe" - m <- mapping %>% - filter( - !!sym("RegionCode") == "EUR", - !(!!sym("CountryCode") %in% c(eu.countries, Non28EUcountries)) - ) %>% - mutate(!!sym("Reg") := "Other Europe") - - y <- toolAggregate(x1, m, - from = "Reg", to = "CountryCode", - dim = 1, weight = w[unique(m$CountryCode), , ] - ) - return(y) - } - - # we attempt to disaggregate "Other Europe" and "Europe" per variable to the EU28 countries - other.europe <- x["Other Europe", , ] - na.vars <- magpply(other.europe, function(y) all(is.na(y)), MARGIN = 3) - other.europe <- other.europe[, , !na.vars] - - europe <- x["Europe", , ] - na.vars <- magpply(europe, function(y) all(is.na(y)), MARGIN = 3) - europe <- europe[, , !na.vars] - - # remove regions that require disaggregation - x <- x[c("World", "Rest of the world", "Europe", "Other Europe", "EU27"), , invert = TRUE] - getItems(x, dim = 1) <- toolCountry2isocode(getItems(x, dim = 1)) - - varlist <- list(x) - - # disaggregate "Other Europe" where applicable - for (var in getNames(other.europe)) { - varlist <- append(varlist, list(.disaggregate_other_europe(other.europe[, , var], var))) - } - - # merge magclass objects into one - years <- sort(Reduce(union, lapply(varlist, getYears))) - regions <- Reduce(union, lapply(varlist, getRegions)) - data <- new.magpie(regions, years, getNames(x), fill = NA) - for (i in varlist) { - data[getRegions(i), getYears(i), getNames(i)] <- i - } - - # disaggregate "Europe" - m <- mapping %>% - filter( - !!sym("RegionCode") == "EUR", - !(!!sym("CountryCode") %in% c(Non28EUcountries)) - ) - europe <- toolAggregate( - europe, m, - from = "RegionCode", to = "CountryCode", - dim = 1, weight = w[unique(m$CountryCode), , ] - ) - - # if no finer disaggregation of Europe (countries + Other Europe) is available, - # use the coarse disaggregation (Europe to 28 countries) - for (v in getNames(europe)) { - if (all(is.na(data[getRegions(europe), , v]))) { - data[getRegions(europe), , v] <- europe[, , v] - } - } + data <- x[c("World", "Rest of the world", "Europe", "EU27"), , invert = TRUE] + getItems(data, dim = 1) <- toolCountry2isocode(getItems(data, dim = 1)) data <- toolCountryFill(data, fill = NA, verbosity = 2) - # set small EU countries to 0 to allow for aggregation of EU region - data[Non28EUcountries, , ] <- 0 + # set 0s in other CHA countries than China to approximate CHA as China + data[c("HKG", "MAC", "TWN"), , ] <- 0 return(data) } diff --git a/R/convertIEA_HSMR.R b/R/convertIEA_HSMR.R new file mode 100644 index 00000000..0dd8ab3d --- /dev/null +++ b/R/convertIEA_HSMR.R @@ -0,0 +1,14 @@ +#' convert IEA Hydro Special Market Report +#' +#' @param x a magclass object returned from `readIEA_HSMR()` +#' @author Pascal Weigmann + +convertIEA_HSMR <- function(x) { + + getItems(x, dim = 1) <- toolCountry2isocode(getItems(x, dim = 1)) + x <- toolCountryFill(x, fill = 0, verbosity = 2) + x[, 2030, "operational"] <- x[, 2020, "operational"] + x <- x[, 2030, ] + + return(x) +} diff --git a/R/convertIEA_PVPS.R b/R/convertIEA_PVPS.R index bc12b15f..0803cdf5 100644 --- a/R/convertIEA_PVPS.R +++ b/R/convertIEA_PVPS.R @@ -5,11 +5,8 @@ #' @return Magpie object with IEA PVPS investment cost per country #' @author Felix Schreyer - - convertIEA_PVPS <- function(x, subtype) { - - regmapping <- toolGetMapping("regionmappingH12.csv",where = "mappingfolder",type = "regional") + regmapping <- toolGetMapping("regionmappingH12.csv", where = "mappingfolder", type = "regional") x_iso <- toolAggregate(x, regmapping) - return(x_iso) -} + return(x_iso) +} diff --git a/R/convertIEA_REN.R b/R/convertIEA_REN.R index 33ddfd54..4e93e16b 100644 --- a/R/convertIEA_REN.R +++ b/R/convertIEA_REN.R @@ -1,5 +1,5 @@ -#' Reads the distributed solar pv capacity from IEA Renewables report (2019). -#' @details Capacity in GW. Distributed solar, defined in the IEA Renewables (2019), includes +#' Reads the distributed solar pv capacity from IEA Renewables report (2019). +#' @details Capacity in GW. Distributed solar, defined in the IEA Renewables (2019), includes #' rooftop residential (0-10 kW, grid-connected), rooftop and ground-mounted commercial #' and industrial (10-1000kW, grid-connected), and off-grid (8W - 100 kW) #' @author Aman Malik @@ -7,85 +7,69 @@ #' @return magpie object with country-wise distributed solar pv capacity #' @param x input magpie object -convertIEA_REN <- function(x){ +convertIEA_REN <- function(x) { country <- NULL region <- NULL - - mapping_rem <- toolGetMapping(getConfig()[1],where = "mappingfolder",type = "regional") + + mapping_rem <- toolGetMapping(getConfig()[1], where = "mappingfolder", type = "regional") # mapping file - mapping_IEA <- toolGetMapping("mappingIEA-REN.csv", where = "mappingfolder",type = "regional") - mapping_IEA$country <- gsub("Bolivarian Republic of Venezuela \\(Venezuela\\)","Venezuela",mapping_IEA$country) - mapping_IEA$country <- gsub("Kingdom of Eswatini Lesotho","Lesotho",mapping_IEA$country) - #mapping_IEA$country <- grep(pattern = "Lao" ,value = T, mapping_IEA$country) - - mapping_IEA$country <- gsub("Plurinational State of Bolivia \\(Bolivia\\)","Bolivia",mapping_IEA$country) + mapping_IEA <- toolGetMapping("mappingIEA-REN.csv", where = "mappingfolder", type = "regional") + mapping_IEA$country <- gsub("Bolivarian Republic of Venezuela \\(Venezuela\\)", "Venezuela", mapping_IEA$country) + mapping_IEA$country <- gsub("Kingdom of Eswatini Lesotho", "Lesotho", mapping_IEA$country) + + mapping_IEA$country <- gsub("Plurinational State of Bolivia \\(Bolivia\\)", "Bolivia", mapping_IEA$country) mapping_IEA$country <- toolCountry2isocode(mapping_IEA$country) - mapping_IEA <- mapping_IEA %>% filter(country!="KOS") + mapping_IEA <- mapping_IEA %>% filter(country != "KOS") # IEA Regions - Asia-Pacific, MENA, North and Central America, South America, # Europe, Eurasia, Sub-saharan Africa - #x <- readSource("IEA_REN",convert=F) - getRegions(x) <- gsub("Central and South America","Latin America",getRegions(x)) + getRegions(x) <- gsub("Central and South America", "Latin America", getRegions(x)) # new magpie object with only country values, excluding region names and World - y <- new.magpie(setdiff(getRegions(x),c(unique(mapping_IEA$region),"World")), - years = getYears(x),names = getNames(x),fill = 0) - y[,,] <- x[getRegions(y),,] + y <- new.magpie(setdiff(getRegions(x), c(unique(mapping_IEA$region), "World")), + years = getYears(x), names = getNames(x), fill = 0 + ) + y[, , ] <- x[getRegions(y), , ] getRegions(y) <- toolCountry2isocode(getRegions(y)) - + # wt by solar pv capacity in 2018 - wt <- calcOutput("Capacity", subtype="capacityByTech",aggregate =F) - wt <- wt[,"y2018","spv"] - - output <- new.magpie(mapping_rem$CountryCode,years = getYears(x),names=getNames(x),fill=0) - - for (i in c("Europe","Asia-Pacific","Latin America")){ - - cont_iea <- mapping_IEA[mapping_IEA$region==i,]$country - reg <- new.magpie(i,years = getYears(x),names = getNames(x),fill = 0) - cont_y <- intersect(getRegions(y),cont_iea) - reg[,,] <- x[i,,]-dimSums(y[cont_y,,],dim = 1) - rel=mapping_IEA %>% filter(!country %in% cont_y,region==i) - reg <- toolAggregate(x = reg, - rel=rel, - weight = wt[rel$country,,], - from="region", - to="country") - output[getRegions(reg),,] <- reg - } + wt <- calcOutput("Capacity", subtype = "capacityByTech", aggregate = FALSE) + wt <- wt[, "y2018", "spv"] -# other regions + output <- new.magpie(mapping_rem$CountryCode, years = getYears(x), names = getNames(x), fill = 0) - for (j in c("Eurasia","MENA","Sub-Saharan Africa","North America")){ - reg <- x[j,,] - rel= mapping_IEA %>% filter(region==j) - reg <- toolAggregate(x = reg, - rel = rel, - weight = wt[rel$country,,], - from="region", - to="country") - output[getRegions(reg),,] <- reg - + for (i in c("Europe", "Asia-Pacific", "Latin America")) { + cont_iea <- mapping_IEA[mapping_IEA$region == i, ]$country + reg <- new.magpie(i, years = getYears(x), names = getNames(x), fill = 0) + cont_y <- intersect(getRegions(y), cont_iea) + reg[, , ] <- x[i, , ] - dimSums(y[cont_y, , ], dim = 1) + rel <- mapping_IEA %>% filter(!country %in% cont_y, region == i) + reg <- toolAggregate( + x = reg, + rel = rel, + weight = wt[rel$country, , ], + from = "region", + to = "country" + ) + output[getRegions(reg), , ] <- reg } - -output[getRegions(y),,] <- y -x <- toolCountryFill(output,fill=0) - -# # part of resulting magpie object, mo gets difference of region and countries which -# # already have data -# Europe <- new.magpie("Europe" ,years = getYears(x),fill = 0) -# # countries with region "Europe" in magpie object -# eu_count_in_y <- intersect(getRegions(y),mapping_IEA[mapping_IEA$region=="Europe",]$country) -# Europe[,,] <- x["Europe",,]-dimSums(y[eu_count_in_y,,],dim = 1) -# -# eu_count_iea <- mapping_IEA[mapping_IEA$region=="Europe",]$country -# -# -# -# Europe <- toolAggregate(x = Europe, -# rel=mapping_IEA %>% filter(!country %in% eu_count_in_y,region=="Europe"), -# weight = wt[setdiff(eu_count_iea,eu_count_in_y),,], -# from="region", -# to="country") -return (x) + # other regions + + for (j in c("Eurasia", "MENA", "Sub-Saharan Africa", "North America")) { + reg <- x[j, , ] + rel <- mapping_IEA %>% filter(region == j) + reg <- toolAggregate( + x = reg, + rel = rel, + weight = wt[rel$country, , ], + from = "region", + to = "country" + ) + output[getRegions(reg), , ] <- reg + } + + output[getRegions(y), , ] <- y + x <- toolCountryFill(output, fill = 0, verbosity = 2) + + return(x) } diff --git a/R/convertIEA_WEO.R b/R/convertIEA_WEO.R index 02bd2c4f..f6c34538 100644 --- a/R/convertIEA_WEO.R +++ b/R/convertIEA_WEO.R @@ -1,199 +1,175 @@ #' Converts IEA World Energy Outlook data -#' +#' #' @param x MAgPIE object to be converted -#' @param subtype data subtype. Either "Capacity", "Generation", "Emissions", "Investment Costs", "O&M Costs" or "Efficiency" -#' @return magpie object of the WEO data on generation (TWh), capacities (GW), emissions (Mt CO2) or disaggregated investment cost as magpie object +#' @param subtype data subtype. Either "Capacity", "Generation", "Emissions", +#' "Investment Costs", "O&M Costs" or "Efficiency" +#' @return magpie object of the WEO data on generation (TWh), capacities (GW), +#' emissions (Mt CO2) or disaggregated investment cost as magpie object #' @author Renato Rodrigues and Aman Malik #' @seealso \code{\link{readSource}} #' @examples -#' -#' \dontrun{ a <- convertWEO(x,subtype="Capacity") +#' \dontrun{ +#' a <- convertWEO(x, subtype = "Capacity") #' } -#' +#' #' @importFrom tidyr gather #' @importFrom readxl read_excel -#' @importFrom magclass nregions +convertIEA_WEO <- function(x, subtype) { + if ((subtype == "Invest_Costs") || (subtype == "O&M_Costs") || (subtype == "Efficiency")) { -convertIEA_WEO <- function(x,subtype){ - - if ((subtype=="Invest_Costs") || (subtype=="O&M_Costs") || (subtype=="Efficiency")) - { - # x <- readSource("IEA_WEO",subtype = "Invest_Costs",convert = FALSE) - # x[,,] <- as.numeric(x[,,]) - # # mapping of all countries and their respective regions - all_c <- toolGetMapping("regionmappingH12.csv",where = "mappingfolder",type = "regional") + # mapping of all countries and their respective regions + all_c <- toolGetMapping("regionmappingH12.csv", where = "mappingfolder", type = "regional") # seperating hydro case - x_hydro <- x[unique(all_c$RegionCode),,"Hydro_2.hydro"] - x <- x[unique(all_c$RegionCode),,"Hydro_2.hydro",invert=T] - eu_costs <- new.magpie(all_c$CountryCode[all_c$RegionCode=="EUR"],years = getYears(x),names=getNames(x)) - neu_costs <- new.magpie(all_c$CountryCode[all_c$RegionCode=="NEU"],years = getYears(x),names=getNames(x)) - africa_costs <- new.magpie(all_c$CountryCode[all_c$RegionCode=="SSA"],years = getYears(x),names = getNames(x)) - mea_costs <- new.magpie(all_c$CountryCode[all_c$RegionCode=="MEA"],years = getYears(x),names = getNames(x)) - asia_costs <- new.magpie(all_c$CountryCode[all_c$RegionCode=="OAS"],years = getYears(x),names = getNames(x)) - caz_costs <- new.magpie(all_c$CountryCode[all_c$RegionCode=="CAZ"],years = getYears(x),names = getNames(x)) - sc_america_costs <- new.magpie(all_c$CountryCode[all_c$RegionCode=="LAM"],years = getYears(x),names = getNames(x)) - + x_hydro <- x[unique(all_c$RegionCode), , "Hydro_2.hydro"] + x <- x[unique(all_c$RegionCode), , "Hydro_2.hydro", invert = TRUE] + eu_costs <- new.magpie(all_c$CountryCode[all_c$RegionCode == "EUR"], years = getYears(x), names = getNames(x)) + neu_costs <- new.magpie(all_c$CountryCode[all_c$RegionCode == "NEU"], years = getYears(x), names = getNames(x)) + africa_costs <- new.magpie(all_c$CountryCode[all_c$RegionCode == "SSA"], years = getYears(x), names = getNames(x)) + mea_costs <- new.magpie(all_c$CountryCode[all_c$RegionCode == "MEA"], years = getYears(x), names = getNames(x)) + asia_costs <- new.magpie(all_c$CountryCode[all_c$RegionCode == "OAS"], years = getYears(x), names = getNames(x)) + caz_costs <- new.magpie(all_c$CountryCode[all_c$RegionCode == "CAZ"], years = getYears(x), names = getNames(x)) + sc_america_costs <- new.magpie(all_c$CountryCode[all_c$RegionCode == "LAM"], years = getYears(x), names = getNames(x)) + # All countries from the database which have zero investment costs get some numbers # So, for e.g., Brazil and Middle East have zero for all the CCS related investment costs. They get their value from the # average of all other regions/countries for the same technology. - x[c("Brazil","Middle East"),,"CCS",pmatch=TRUE] <- dimSums(x[c("Brazil","Middle East"),,invert=TRUE][,,"CCS"],na.rm = TRUE,dim=1)/ - nregions(x[c("Brazil","Middle East"),,invert=T]) - x["Brazil",,"Renewables.Geothermal"] <- dimSums(x["Brazil",,,invert=TRUE][,,"Renewables.Geothermal"],dim = 1)/ - nregions(x["Brazil",,invert=T]) - x["Brazil",,"Renewables.Marine"] <- dimSums(x["Brazil",,,invert=TRUE][,,"Renewables.Marine"],dim=1)/ - nregions(x["Brazil",,invert=T]) - x[c("Japan","Russia"),,"Renewables.Concentrating solar power"] <- dimSums(x[c("Japan","Russia"),,,invert=TRUE][,,"Renewables.Concentrating solar power"],dim=1)/ - nregions(x[c("Japan","Russia"),,invert=T]) - for (n in getRegions(eu_costs)){# all EU28 countries get "Europe" investment costs - eu_costs[n,,] <- as.numeric(x["Europe",,]) - } - for (n in getRegions(neu_costs)){# all non-EU european countries get average of "Europe" and "RUS" investment costs - neu_costs[n,,] <- 0.5*as.numeric(x["Europe",,])+0.5*as.numeric(x["Russia",,]) - } - for (n in getRegions(caz_costs)){# all CAZ countries get "OECD" average investment costs - caz_costs[n,,] <- 0.34*as.numeric(x["Europe",,])+0.33*as.numeric(x["United States",,])+0.33*as.numeric(x["Japan",,]) - } - for (n in getRegions(africa_costs)){# all african countries get "Africa" investment costs - africa_costs[n,,]<- as.numeric(x["Africa",,]) - } - for (n in getRegions(mea_costs)){# all OAS countries get average of Indian and Japanese investment costs - mea_costs[n,,] <- as.numeric(x["Middle East",,]) - } - for (n in getRegions(asia_costs)){# all OAS countries get average of Indian and Japanese investment costs - asia_costs[n,,] <- 0.5*as.numeric(x["India",,])+0.5*as.numeric(x["Japan",,]) - } - for (n in getRegions(sc_america_costs)){ - sc_america_costs[n,,] <- as.numeric(x["Brazil",,])# all S. and C. American countries get "Brazilian" investment costs - } - + x[c("Brazil", "Middle East"), , "CCS", pmatch = TRUE] <- dimSums(x[c("Brazil", "Middle East"), , invert = TRUE][, , "CCS"], na.rm = TRUE, dim = 1) / + nregions(x[c("Brazil", "Middle East"), , invert = TRUE]) + x["Brazil", , "Renewables.Geothermal"] <- dimSums(x["Brazil", , , invert = TRUE][, , "Renewables.Geothermal"], dim = 1) / + nregions(x["Brazil", , invert = TRUE]) + x["Brazil", , "Renewables.Marine"] <- dimSums(x["Brazil", , , invert = TRUE][, , "Renewables.Marine"], dim = 1) / + nregions(x["Brazil", , invert = TRUE]) + x[c("Japan", "Russia"), , "Renewables.Concentrating solar power"] <- dimSums(x[c("Japan", "Russia"), , , invert = TRUE][, , "Renewables.Concentrating solar power"], dim = 1) / + nregions(x[c("Japan", "Russia"), , invert = TRUE]) + for (n in getItems(eu_costs, dim = 1)) { # all EU28 countries get "Europe" investment costs + eu_costs[n, , ] <- as.numeric(x["Europe", , ]) + } + for (n in getItems(neu_costs, dim = 1)) { # all non-EU european countries get average of "Europe" and "RUS" investment costs + neu_costs[n, , ] <- 0.5 * as.numeric(x["Europe", , ]) + 0.5 * as.numeric(x["Russia", , ]) + } + for (n in getItems(caz_costs, dim = 1)) { # all CAZ countries get "OECD" average investment costs + caz_costs[n, , ] <- 0.34 * as.numeric(x["Europe", , ]) + 0.33 * as.numeric(x["United States", , ]) + 0.33 * as.numeric(x["Japan", , ]) + } + for (n in getItems(africa_costs, dim = 1)) { # all african countries get "Africa" investment costs + africa_costs[n, , ] <- as.numeric(x["Africa", , ]) + } + for (n in getItems(mea_costs, dim = 1)) { # all OAS countries get average of Indian and Japanese investment costs + mea_costs[n, , ] <- as.numeric(x["Middle East", , ]) + } + for (n in getItems(asia_costs, dim = 1)) { # all OAS countries get average of Indian and Japanese investment costs + asia_costs[n, , ] <- 0.5 * as.numeric(x["India", , ]) + 0.5 * as.numeric(x["Japan", , ]) + } + + for (n in getItems(sc_america_costs, dim = 1)) { + sc_america_costs[n, , ] <- as.numeric(x["Brazil", , ]) # all S. and C. American countries get "Brazilian" investment costs + } + # Extracting proper countries from the region/country list in input data - x_countries <- x[c("Europe","Middle East","Africa"),,,invert=TRUE] + x_countries <- x[c("Europe", "Middle East", "Africa"), , , invert = TRUE] + # converting to ISO country names - getRegions(x_countries) <- toolCountry2isocode(getRegions(x_countries)) - + getItems(x_countries, dim = 1) <- toolCountry2isocode(getItems(x_countries, dim = 1)) + # one magpie object with all names - x_total <- mbind(eu_costs,neu_costs,caz_costs,africa_costs,mea_costs,asia_costs, - sc_america_costs,x_countries[c("BRA"),,invert=TRUE]) + x_total <- mbind( + eu_costs, neu_costs, caz_costs, africa_costs, mea_costs, asia_costs, + sc_america_costs, x_countries[c("BRA"), , invert = TRUE] + ) # remaining countries - x_total <- toolCountryFill(x_total,"HKG"="CHN","PRI"="USA","MAC"="CHN") - - x_hydro <- toolAggregate(x_hydro,rel = all_c,from = "RegionCode",to = "CountryCode") + x_total <- toolCountryFill(x_total, verbosity = 2, "HKG" = "CHN", "PRI" = "USA", "MAC" = "CHN") + + x_hydro <- toolAggregate(x_hydro, rel = all_c, from = "RegionCode", to = "CountryCode") + # setting 2040 values as 2030 values - x_hydro[,"y2040",] <- setYears(x_hydro[,2030,]) - - x_total[,,"Renewables.Hydropower - large-scale"] <- x_hydro[,,"Hydro_2.hydro"] - + x_hydro[, "y2040", ] <- setYears(x_hydro[, 2030, ]) + + x_total[, , "Renewables.Hydropower - large-scale"] <- x_hydro[, , "Hydro_2.hydro"] + x <- x_total - + x[is.na(x)] <- 0 - - } - else if ((subtype=="Capacity") || (subtype=="Generation") || (subtype=="Emissions")) - { - - # WEO_regions -> c("World", "OECDNAM", "US", "CSAM", "BRAZIL", "EUR", "EU", "Africa", "SAFR", "ME", "EURASIA", "RUS", "ASIAPAC", "CHINA", "INDIA", "JPN", "ASEAN", "OECD", "NonOECD" - + } else if ((subtype == "Capacity") || (subtype == "Generation") || (subtype == "Emissions")) { + H12map <- toolGetMapping("regionmappingH12.csv", type = "regional", where = "mappingfolder") - - if (subtype=="Capacity"){ # estimate OAS coal + + if (subtype == "Capacity") { # estimate OAS coal + # Approximate Caspian countries (part of the REF) - weight <- calcOutput("IO",subtype="input",aggregate=FALSE)[,2015,"pecoal.seel.pc"] - caspian <- new.magpie(cells_and_regions = "Caspian",names=getNames(x),years = 2015, fill=as.vector(x["EURASIA",2015,getNames(x)]) - as.vector(x["RUS",2015,getNames(x)])) - caspianMap <- data.frame(CountryCode=c("ARM","AZE","GEO","KAZ","KGZ","TJK","TKM","UZB"),RegionCode="Caspian") - caspianCountries <- toolAggregate(caspian, caspianMap, weight[c("ARM","AZE","GEO","KAZ","KGZ","TJK","TKM","UZB"),,]) - + weight <- calcOutput("IO", subtype = "input", aggregate = FALSE)[, 2015, "pecoal.seel.pc"] + caspian <- new.magpie(cells_and_regions = "Caspian", names = getNames(x), years = 2015, fill = as.vector(x["EURASIA", 2015, getNames(x)]) - as.vector(x["RUS", 2015, getNames(x)])) + caspianMap <- data.frame(CountryCode = c("ARM", "AZE", "GEO", "KAZ", "KGZ", "TJK", "TKM", "UZB"), RegionCode = "Caspian") + caspianCountries <- toolAggregate(caspian, caspianMap, weight[c("ARM", "AZE", "GEO", "KAZ", "KGZ", "TJK", "TKM", "UZB"), , ]) + # Approximate Latin America countries (minus MEX) - LAM <- new.magpie(cells_and_regions = "LAM",names=getNames(x),years = 2015, fill=as.vector(x["CSAM",2015,getNames(x)])-as.vector(x["BRAZIL",2015,getNames(x)])) - LAMCountryCode <- H12map[which(H12map$RegionCode=="LAM"),]$CountryCode - LAMCountries <- toolAggregate(LAM, H12map[which(H12map$CountryCode %in% LAMCountryCode[! LAMCountryCode %in% c("MEX","BRA")]),], weight[LAMCountryCode[! LAMCountryCode %in% c("MEX","BRA")],,]) - + LAM <- new.magpie(cells_and_regions = "LAM", names = getNames(x), years = 2015, fill = as.vector(x["CSAM", 2015, getNames(x)]) - as.vector(x["BRAZIL", 2015, getNames(x)])) + LAMCountryCode <- H12map[which(H12map$RegionCode == "LAM"), ]$CountryCode + LAMCountries <- toolAggregate(LAM, H12map[which(H12map$CountryCode %in% LAMCountryCode[!LAMCountryCode %in% c("MEX", "BRA")]), ], weight[LAMCountryCode[!LAMCountryCode %in% c("MEX", "BRA")], , ]) + # Approximate OAS countries - AUS_Coal <- 20 # Australia coal capacity in 2015 (GW) + AUS_Coal <- 20 # Australia coal capacity in 2015 (GW) NZL_Coal <- 0.55 # New zealand coal capacity in 2015 (GW) - OAStotal <- as.vector(x["ASIAPAC",2015,"Coal"]) - as.vector(x["CHINA",2015,"Coal"]) - as.vector(x["INDIA",2015,"Coal"]) - as.vector(x["JPN",2015,"Coal"]) - AUS_Coal - NZL_Coal - OAS <- new.magpie(cells_and_regions = "OAS",names=c("Coal"),years = 2015, fill = OAStotal) - OASCountries <- toolAggregate(OAS, H12map[which(H12map$RegionCode=="OAS"),], weight[H12map[which(H12map$RegionCode=="OAS"),]$CountryCode,,]) + OAStotal <- as.vector(x["ASIAPAC", 2015, "Coal"]) - as.vector(x["CHINA", 2015, "Coal"]) - as.vector(x["INDIA", 2015, "Coal"]) - as.vector(x["JPN", 2015, "Coal"]) - AUS_Coal - NZL_Coal + OAS <- new.magpie(cells_and_regions = "OAS", names = c("Coal"), years = 2015, fill = OAStotal) + OASCountries <- toolAggregate(OAS, H12map[which(H12map$RegionCode == "OAS"), ], weight[H12map[which(H12map$RegionCode == "OAS"), ]$CountryCode, , ]) } - + # get other regions directly from WEO data - otherCap <- x[c("US", "BRAZIL", "RUS", "CHINA", "INDIA", "JPN"),2015,] # countries only - getRegions(otherCap) <- toolCountry2isocode(getRegions(otherCap), mapping = c("US"="USA", "RUS"="RUS", "JPN" = "JPN")) - - #merge data - if (subtype=="Capacity"){ - reg <- unique(c(getRegions(otherCap),getRegions(OASCountries),getRegions(caspianCountries),getRegions(LAMCountries),"MEX")) - names <- unique(c(getNames(otherCap),getNames(OASCountries),getNames(caspianCountries),getNames(LAMCountries))) - years <- unique(c(getYears(otherCap),getYears(OASCountries),getYears(caspianCountries),getYears(LAMCountries))) - out <- new.magpie(cells_and_regions = reg, names = names, years = years) - out[getRegions(otherCap),,] <- otherCap[getRegions(otherCap),,] - out[getRegions(OASCountries),,"Coal"] <- OASCountries[getRegions(OASCountries),,"Coal"] - out[getRegions(caspianCountries),,"Coal"] <- caspianCountries[getRegions(caspianCountries),,"Coal"] - out[getRegions(LAMCountries),,"Coal"] <- LAMCountries[getRegions(LAMCountries),,"Coal"] - out["MEX",,"Coal"] <- 5.378 # Mexico coal capacity in 2015 (GW) + otherCap <- x[c("US", "BRAZIL", "RUS", "CHINA", "INDIA", "JPN"), 2015, ] # countries only + getItems(otherCap, dim = 1) <- toolCountry2isocode(getItems(otherCap, dim = 1), mapping = c("US" = "USA", "RUS" = "RUS", "JPN" = "JPN")) + + # merge data + if (subtype == "Capacity") { + reg <- unique(c(getItems(otherCap, dim = 1), getItems(OASCountries, dim = 1), getItems(caspianCountries, dim = 1), getItems(LAMCountries, dim = 1), "MEX")) + names <- unique(c(getNames(otherCap), getNames(OASCountries), getNames(caspianCountries), getNames(LAMCountries))) + years <- unique(c(getYears(otherCap), getYears(OASCountries), getYears(caspianCountries), getYears(LAMCountries))) + out <- new.magpie(cells_and_regions = reg, names = names, years = years) + out[getItems(otherCap, dim = 1), , ] <- otherCap + out[getItems(OASCountries, dim = 1), , "Coal"] <- OASCountries[, , "Coal"] + out[getItems(caspianCountries, dim = 1), , "Coal"] <- caspianCountries[, , "Coal"] + out[getItems(LAMCountries, dim = 1), , "Coal"] <- LAMCountries[, , "Coal"] + out["MEX", , "Coal"] <- 5.378 # Mexico coal capacity in 2015 (GW) } else { out <- otherCap } - + # fill countries with no data - out <- toolCountryFill(out,fill=0,verbosity=0) + out <- toolCountryFill(out, fill = 0, verbosity = 2) + # replace NAs with 0 out[is.na(out)] <- 0 - + x <- out - } - - if ((subtype=="PE") || (subtype=="FE")) - { - # x <- readSource(type = "IEA_WEO",subtype = "PE",convert = F) - x <- collapseNames(x) - # countries <- toolGetMapping("regionmappingREMIND.csv",where = "mappingfolder",type = "regional") - # countries <- countries[countries$RegionCode=="EUR",] - # eu <- new.magpie( countries[countries$RegionCode=="EUR",]$X,getYears(x),getNames(x)) - # # EU countries get EU values from IEA WEO data - # for (i in getRegions(eu)) - # { - # eu[i,,] <- x["European Union (28 member countries)",,]/nregions(eu) - # - # } - - regions <- c( "BRAZIL","CHINA" ,"JPN", - "INDIA", - "US","RUS","SAFR") - y <- x[regions,,] - #getRegions(y) <- gsub("People's Repulic of China","China",getRegions(y)) - # getRegions(y) <- gsub("European Union \\(28 member countries\\)","EUR",getRegions(y)) - # getRegions(y) <- gsub("Republic of India","India",getRegions(y)) - getRegions(y) <- gsub("JPN","Japan",getRegions(y)) - getRegions(y) <- gsub("RUS","Russia",getRegions(y)) - getRegions(y) <- gsub("US","United States of America",getRegions(y)) - getRegions(y) <- gsub("SAFR","South Africa",getRegions(y)) - - - #z <- mbind(y,eu) - y <- mbind(y) - - getRegions(y) <- toolCountry2isocode(getRegions(y)) - x <- y - x <- toolCountryFill(x = y,fill = NA) - - - if (subtype=="PE") - { - x <- x[,,"Primary Energy",pmatch=T] - } - - - if (subtype=="FE") - { x <- x[,,"Final Energy",pmatch=T] + + if ((subtype == "PE") || (subtype == "FE")) { + x <- collapseNames(x) + + regions <- c( + "BRAZIL", "CHINA", "JPN", + "INDIA", + "US", "RUS", "SAFR" + ) + y <- x[regions, , ] + + getItems(y, dim = 1) <- gsub("JPN", "Japan", getItems(y, dim = 1)) + getItems(y, dim = 1) <- gsub("RUS", "Russia", getItems(y, dim = 1)) + getItems(y, dim = 1) <- gsub("US", "United States of America", getItems(y, dim = 1)) + getItems(y, dim = 1) <- gsub("SAFR", "South Africa", getItems(y, dim = 1)) + + y <- mbind(y) + + getItems(y, dim = 1) <- toolCountry2isocode(getItems(y, dim = 1)) + x <- y + x <- toolCountryFill(x = y, fill = NA, verbosity = 2) + + if (subtype == "PE") { + x <- x[, , "Primary Energy", pmatch = TRUE] } + if (subtype == "FE") { + x <- x[, , "Final Energy", pmatch = TRUE] + } } - - return(x) - } - - diff --git a/R/convertIEA_WEO_2021.R b/R/convertIEA_WEO_2021.R deleted file mode 100644 index fbdbabef..00000000 --- a/R/convertIEA_WEO_2021.R +++ /dev/null @@ -1,133 +0,0 @@ -#' Disaggregates IEA WEO 2021 Data -#' @param x MAgPIE object to be converted -#' @return A [`magpie`][magclass::magclass] object. -#' @param subtype Either "global" or "region". On global level, the source offers -#' more variables than on regional level, but the data should not be used on sub- -#' global level due to its coarse disaggregation. -#' @author Falk Benke -#' @importFrom madrat getISOlist -#' - -convertIEA_WEO_2021 <- function(x, subtype = "global") { # nolint - pe <- calcOutput("PE", aggregate = FALSE) - if (subtype == "global") { - # for now, we only have complete data on global level - xWorld <- x["World", , ] - - # remove all-NA variables - remove <- magpply(xWorld, function(y) all(is.na(y)), MARGIN = 3) - xWorld <- xWorld[, , !remove] - - # to integrate the data in historical.mif, we need to disaggregate to country level - # the disaggregation is very unprecise and therefore values below global granularity - # are not reliable - - mappingWorld <- tibble( - regions = "World", - country = getISOlist() - ) - - weight <- pe[, 2014, "PE (EJ/yr)"] - xWorld <- toolAggregate(xWorld, rel = mappingWorld, weight = weight) - return(xWorld) - } else if (subtype == "region") { - .removeNaRegions <- function(x) { - remove <- magpply(x, function(y) all(is.na(y)), MARGIN = 1) - return(x[!remove, , ]) - } - - mappingFull <- toolGetMapping("regionmapping_IEA_WEO_2021.csv", type = "regional", where = "mappingfolder") - - .disaggregateRegions <- function(xIn, regionsIn) { - x <- .removeNaRegions(xIn) - - regions <- intersect(regionsIn, getItems(x, dim = 1)) - - if (length(regions) == 0) { - return(toolCountryFill(x, fill = NA, verbosity = 2)) - } - - # ISO countries in x and the corresponding mapping - ctry <- setdiff(getItems(x, dim = 1), regions) - mappingCtry <- mappingFull[mappingFull$ISO3.code %in% ctry & - mappingFull$Region_name %in% regions, ] - - # subtract country values in x from region values - # e.g. USA from North America, if both are in data - xSub <- x[mappingCtry$ISO3.code, , ] - getItems(xSub, dim = 1) <- mappingCtry$Region_name - x[unique(mappingCtry$Region_name), , ] <- x[unique(mappingCtry$Region_name), , ] - dimSums(xSub, dim = 3) - - # mapping of regions to ISO countries other than in ctry (i.e. other regions) - mappingRegions <- mappingFull[mappingFull$Region_name %in% regions & - !mappingFull$ISO3.code %in% ctry & mappingFull$ISO3.code != "SUN", ] - - # regions fully covered by country values can be removed - coveredRegions <- setdiff(regions, unique(mappingRegions$Region_name)) - - if (length(coveredRegions) > 0) { - x <- x[coveredRegions, , invert = TRUE] - regions <- setdiff(regions, coveredRegions) - } - - weight <- pe[mappingRegions$ISO3.code, 2014, "PE (EJ/yr)"] - - # disaggregation of other regions to ISO countries - x2 <- toolAggregate(x[regions, , ], rel = mappingRegions, weight = weight) - - # ISO countries in x that do not need to be disaggregated - x1 <- x[regions, , invert = TRUE] - - if (length(getItems(x1, dim = 1)) == 0) { - return(toolCountryFill(x2, fill = NA, verbosity = 2)) - } - - # combine the two objects - x <- mbind(x1, x2) - x <- toolCountryFill(x, fill = NA, verbosity = 2) - - return(x) - } - - # exclude all regions we don't want to disaggregate due to redundancies, - # low relevance, or lack of accuracy - xReg <- x[c( - "Atlantic Basin", "East of Suez", "NonOPEC", "OPEC", "Japan and Korea", - "Southeast Asia", "Other", "European Union", "World", - "Advanced economies", "Emerging market and developing economies", - "International Energy Agency", "OECD", "Non-OECD", - "North Africa", "Sub-Saharan Africa", "Rest of world", - "Other Asia Pacific", "Other Europe" - ), , , invert = TRUE] - - # remove all-NA variables - remove <- magpply(xReg, function(y) all(is.na(y)), MARGIN = 3) - xReg <- xReg[, , !remove] - - regions <- c( - "Africa", "Asia Pacific", "Central and South America", "Europe", - "Eurasia", "Middle East", "North America" - ) - x1 <- xReg[regions, , ] - - # convert country names to ISO - ctry <- toolCountry2isocode(getItems(xReg, dim = 1), warn = FALSE) - x2 <- xReg[!is.na(ctry), , ] - getItems(x2, dim = 1) <- ctry[!is.na(ctry)] - xReg <- mbind(x1, x2) - - xRegional <- NULL - for (i in getItems(xReg, dim = 3)) { - j <- xReg[, , i] - j <- .removeNaRegions(j) - xRegional <- mbind(xRegional, .disaggregateRegions(xIn = j, regionsIn = regions)) - } - - non28EUcountries <- c("ALA", "FRO", "GIB", "GGY", "IMN", "JEY") - xRegional[non28EUcountries, , ] <- 0 - - return(xRegional) - } else { - stop("Not a valid subtype! Must be either \"region\" or \"global\"") - } -} diff --git a/R/convertIEA_WorldEnergyOutlook.R b/R/convertIEA_WorldEnergyOutlook.R new file mode 100644 index 00000000..d06ae163 --- /dev/null +++ b/R/convertIEA_WorldEnergyOutlook.R @@ -0,0 +1,115 @@ +#' Convert IEA World Energy Outlook Data from 2023 +#' +#' @param x magclass object to be converted +#' @author Falk Benke +#' + +convertIEA_WorldEnergyOutlook <- function(x) { # nolint + + .removeNaRegions <- function(x) { + remove <- magpply(x, function(y) all(is.na(y)), MARGIN = 1) + return(x[!remove, , ]) + } + + mappingFull <- toolGetMapping("regionmapping_IEAWorldEnergyOutlook.csv", + type = "regional", where = "mrremind" + ) + + pe <- calcOutput("PE", aggregate = FALSE) + + .disaggregateRegions <- function(xIn, regionsIn) { + x <- .removeNaRegions(xIn) + + regions <- intersect(regionsIn, getItems(x, dim = 1)) + + if (length(regions) == 0) { + return(toolCountryFill(x, fill = NA, verbosity = 2)) + } + + # ISO countries in x and the corresponding mapping + ctry <- setdiff(getItems(x, dim = 1), regions) + mappingCtry <- mappingFull[mappingFull$ISO3.code %in% ctry & + mappingFull$Region_name %in% regions, ] + + # subtract country values in x from region values + # e.g. USA from North America, if both are in data + xSub <- x[mappingCtry$ISO3.code, , ] + getItems(xSub, dim = 1) <- mappingCtry$Region_name + x[unique(mappingCtry$Region_name), , ] <- x[unique(mappingCtry$Region_name), , ] - dimSums(xSub, dim = 3) + + # mapping of regions to ISO countries other than in ctry (i.e. other regions) + mappingRegions <- mappingFull[mappingFull$Region_name %in% regions & + !mappingFull$ISO3.code %in% ctry & mappingFull$ISO3.code != "SUN", ] + + # regions fully covered by country values can be removed + coveredRegions <- setdiff(regions, unique(mappingRegions$Region_name)) + + if (length(coveredRegions) > 0) { + x <- x[coveredRegions, , invert = TRUE] + regions <- setdiff(regions, coveredRegions) + } + + weight <- pe[mappingRegions$ISO3.code, 2014, "PE (EJ/yr)"] + + # disaggregation of other regions to ISO countries + x2 <- toolAggregate(x[regions, , ], rel = mappingRegions, weight = weight) + + # ISO countries in x that do not need to be disaggregated + x1 <- x[regions, , invert = TRUE] + + if (length(getItems(x1, dim = 1)) == 0) { + return(toolCountryFill(x2, fill = NA, verbosity = 2)) + } + + # combine the two objects + x <- mbind(x1, x2) + x <- toolCountryFill(x, fill = NA, verbosity = 2) + + return(x) + } + + # exclude all regions we don't want to disaggregate due to redundancies, + # low relevance, or lack of accuracy + xReg <- x[c( + "Atlantic Basin", "East of Suez", "NonOPEC", "OPEC", "Japan and Korea", + "Southeast Asia", "Other", "European Union", "World", + "Advanced economies", "Emerging market and developing economies", + "International Energy Agency", "OECD", "Non-OECD", + "North Africa", "Sub-Saharan Africa", "Rest of world", + "Other Asia Pacific", "Other Europe", "Non-OPEC" + ), , , invert = TRUE] + + # remove all-NA variables + remove <- magpply(xReg, function(y) all(is.na(y)), MARGIN = 3) + xReg <- xReg[, , !remove] + + # regions we disaggregate + regions <- c( + "Africa", "Asia Pacific", "Central and South America", "Europe", + "Eurasia", "Middle East", "North America" + ) + x1 <- xReg[regions, , ] + + # convert country names to ISO + x2 <- xReg[regions, , , invert = TRUE] + + # remove International bunkers, as it is unclear how to assign them + x2 <- x2["International bunkers", , , invert = TRUE] + getItems(x2, dim = 1) <- toolCountry2isocode(getItems(x2, dim = 1), warn = TRUE) + + xReg <- mbind(x1, x2) + + xRegional <- NULL + + # disaggregate regions per variable + for (v in getItems(xReg, dim = 3)) { + xRegional <- mbind( + xRegional, + .disaggregateRegions(xIn = xReg[, , v], regionsIn = regions) + ) + } + + xRegional <- toolFillEU34Countries(xRegional) + + return(xRegional) +} diff --git a/R/convertIIASA_subs_taxes.R b/R/convertIIASA_subs_taxes.R index a3e0384d..dec708cf 100644 --- a/R/convertIIASA_subs_taxes.R +++ b/R/convertIIASA_subs_taxes.R @@ -1,20 +1,20 @@ #' Convert IIASA_subs_taxes data -#' +#' #' Convert IIASA subsidy and taxes data on ISO country level (removes countries #' not part of 249 oficial ISO countries and fills missing with zeros). -#' -#' +#' +#' #' @param x MAgPIE object containing IIASA subsidies and taxes data in country #' resolution #' @return IIASA_subs_taxes data as MAgPIE object aggregated to country level #' @author Christoph Bertram #' @examples -#' +#' #' \dontrun{ a <- convertIIASA_subs_taxes(x) #' } -#' +#' convertIIASA_subs_taxes <- function(x) { - # fill all missing countries with 0, remove all countries not part of oficial 249 ISO countries - x <- toolCountryFill(x,fill=0) + # fill all missing countries with 0, remove all countries not part of official 249 ISO countries + x <- toolCountryFill(x, verbosity = 2, fill = 0) return(x) -} +} diff --git a/R/convertILO.R b/R/convertILO.R deleted file mode 100644 index 9f610ba8..00000000 --- a/R/convertILO.R +++ /dev/null @@ -1,5 +0,0 @@ -convertILO <- function(x){ - getRegions(x) <- toolCountry2isocode(getRegions(x)) - x <- toolCountryFill(x,fill = 0) - -} diff --git a/R/convertINNOPATHS.R b/R/convertINNOPATHS.R index 5566ec60..898d3aad 100644 --- a/R/convertINNOPATHS.R +++ b/R/convertINNOPATHS.R @@ -1,14 +1,12 @@ -#' @importFrom madrat toolGetMapping -#' @importFrom dplyr %>% convertINNOPATHS <- function(x) { regmapping <- toolGetMapping("regionmapping_21_EU11.csv", type = "regional", where = "mappingfolder") gdpPerCapita <- calcOutput("GDPpc", aggregate = F) - + # ensure that regions match for disaggregation commonRegions <- intersect(getItems(x, dim = 1), regmapping$RegionCode) - + # restrict disaggregation to EU28 countries Non28EUcountries <- c("ALA", "FRO", "GIB", "GGY", "IMN", "JEY") @@ -20,7 +18,7 @@ convertINNOPATHS <- function(x) { w <- gdpPerCapita[regmapping$CountryCode, 2005, "gdppc_SSP2EU"] x <- toolAggregate(x, regmapping, from = "RegionCode", to = "CountryCode", weight = w) - + x <- toolCountryFill(x, fill = NA, verbosity = 2) x[Non28EUcountries,,] <- 0 return(x) diff --git a/R/convertIRENA.R b/R/convertIRENA.R index 7086e7d8..dd6b36b6 100644 --- a/R/convertIRENA.R +++ b/R/convertIRENA.R @@ -5,7 +5,6 @@ #' @return A MAgPIE object containing IRENA country disaggregated data with #' historical electricity renewable capacities (MW) or generation levels (GWh) #' @author Renato Rodrigues -#' @importFrom madrat toolCountry2isocode #' @examples #' \dontrun{ #' a <- convertIRENA(x, subtype = "Capacity") @@ -25,6 +24,6 @@ convertIRENA <- function(x, subtype) { x["SRB", , ] <- x["SRB", , ] + x1 x <- x[c("KOS"), , , invert = TRUE] # fill countries with no data - x <- toolCountryFill(x, fill = 0, verbosity = 0) + x <- toolCountryFill(x, fill = 0, verbosity = 2) return(x) } diff --git a/R/convertKLWdamage.R b/R/convertKLWdamage.R new file mode 100644 index 00000000..7a7ebe2b --- /dev/null +++ b/R/convertKLWdamage.R @@ -0,0 +1,10 @@ +#' convert KLW damage +#' fills in countries for which no damage parameters are provided, setting parameters to zero +#' @author Franziska Piontek +#' @param x is MAgPIE object containing the damage parameters from KLW +#' @return MAgPIE object containing values for all 249 ISO countries + +convertKLWdamage <- function(x) { + out <- toolCountryFill(x, fill = 0, verbosity = 2, no_remove_warning = c("GLB")) + return(out) +} diff --git a/R/convertLIMITS.R b/R/convertLIMITS.R index b1a0f91d..a7bb3066 100755 --- a/R/convertLIMITS.R +++ b/R/convertLIMITS.R @@ -11,7 +11,7 @@ convertLIMITS <- function(x, subtype) { # For now, this is useless as the processing for activities and emissions is the same if (subtype == "activities") { - m <- toolGetMapping(type = "regional", name = "regionmappingTIMER.csv", + m <- toolGetMapping(type = "regional", name = "regionmappingTIMER.csv", returnPathOnly = TRUE, where = "mappingfolder") # Get TIMER regional mapping @@ -26,7 +26,7 @@ convertLIMITS <- function(x, subtype) { if (subtype == "emissions") { - m <- toolGetMapping(type = "regional", name = "regionmappingTIMER.csv", + m <- toolGetMapping(type = "regional", name = "regionmappingTIMER.csv", returnPathOnly = TRUE, where = "mappingfolder") map <- read.csv2(m) @@ -39,7 +39,7 @@ convertLIMITS <- function(x, subtype) { } # fill all missing countries with 0 - x <- toolCountryFill(x, fill = 0) + x <- toolCountryFill(x, fill = 0, verbosity = 2) return(x) } diff --git a/R/convertMueller.R b/R/convertMueller.R index c6fc9b47..de02b905 100644 --- a/R/convertMueller.R +++ b/R/convertMueller.R @@ -13,9 +13,7 @@ #' #' @author Falk Benke #' -#' @importFrom dplyr %>% mutate select -#' @importFrom madrat getISOlist toolCountryFill -#' @importFrom magclass as.magpie +#' @importFrom dplyr mutate select #' @importFrom quitte madrat_mule #' #' @@ -24,10 +22,10 @@ convertMueller <- function(x, subtype) { if (subtype == "stocks") { x %>% madrat_mule() %>% - mutate(!!sym("variable") := paste0("Steel stock per-capita|", !!sym("estimate"), " (t)")) %>% + mutate("variable" = paste0("Steel stock per-capita|", !!sym("estimate"), " (t)")) %>% select("region" = "iso3c", "period" = "year", "variable", "value" = "steel.stock.per.capita") %>% as.magpie() %>% - toolCountryFill(fill = 0, verbosity = 2) %>% + toolCountryFill(fill = 0, verbosity = 2, no_remove_warning = c("ANT")) %>% return() } else { return(x) diff --git a/R/convertNIR.R b/R/convertNIR.R index 3e7961de..74175de6 100644 --- a/R/convertNIR.R +++ b/R/convertNIR.R @@ -1,24 +1,23 @@ convertNIR <- function(x) { - # add data for USA and CAN for 2005 by hand based on data in different data format from 2014 - x_add <- new.magpie(c("USA","CAN"),getYears(x),getNames(x),fill=0) - x <- mbind(x,x_add) - - x["USA",2005,"Oil"] <- 1373.51 - x["USA",2005,"Gas"] <- 7240.27 - x["USA",2005,"VentingOil"] <- 0 - x["USA",2005,"VentingGas"] <- 0 - x["USA",2005,"FlaringOil"] <- 0 - x["USA",2005,"FlaringGas"] <- 0 - - x["CAN",2005,"Oil"] <- 260.1 - x["CAN",2005,"Gas"] <- 909.04 - x["CAN",2005,"VentingOil"] <- 819.51 - x["CAN",2005,"VentingGas"] <- 227.59 - x["CAN",2005,"FlaringOil"] <- 2.51 - x["CAN",2005,"FlaringGas"] <- 0.33 - + x_add <- new.magpie(c("USA", "CAN"), getYears(x), getNames(x), fill = 0) + x <- mbind(x, x_add) + + x["USA", 2005, "Oil"] <- 1373.51 + x["USA", 2005, "Gas"] <- 7240.27 + x["USA", 2005, "VentingOil"] <- 0 + x["USA", 2005, "VentingGas"] <- 0 + x["USA", 2005, "FlaringOil"] <- 0 + x["USA", 2005, "FlaringGas"] <- 0 + + x["CAN", 2005, "Oil"] <- 260.1 + x["CAN", 2005, "Gas"] <- 909.04 + x["CAN", 2005, "VentingOil"] <- 819.51 + x["CAN", 2005, "VentingGas"] <- 227.59 + x["CAN", 2005, "FlaringOil"] <- 2.51 + x["CAN", 2005, "FlaringGas"] <- 0.33 + # fill all missing countries with 0 - x <- toolCountryFill(x,fill=0) + x <- toolCountryFill(x, fill = 0, verbosity = 2) return(x) -} +} diff --git a/R/convertNREL.R b/R/convertNREL.R index ccdaeb52..462fbf8d 100644 --- a/R/convertNREL.R +++ b/R/convertNREL.R @@ -1,36 +1,36 @@ #' Convert NREL data -#' +#' #' Convert NREL data on ISO country level. -#' -#' +#' +#' #' @param x MAgPIE object containing NREL data country-region resolution #' @return NRELWirsenius data as MAgPIE object aggregated to country level #' @author Lavinia Baumstark #' @examples -#' -#' \dontrun{ a <- convertNREL(x,subtype="onshore") +#' \dontrun{ +#' a <- convertNREL(x, subtype = "onshore") #' } -#' @importFrom madrat toolCountryFill convertNREL <- function(x) { - # rename countries with ISO-code - getRegions(x) <- toolCountry2isocode(getRegions(x)) - - #-------------------- allocation of aggretations ------------------------------- + getItems(x, dim = 1) <- toolCountry2isocode(getItems(x, dim = 1)) + + #-------------------- allocation of aggregations ------------------------------- # "ANT" -> "SXM", "CUW", "BES" # "YUG" -> "SRB", "MNE" # YUG seems to be only these two, "SVN", "HRV", "MKD", "BIH" - m <- matrix(c(c("ANT","ANT","ANT", "YUG","YUG"), #,"YUG","YUG","YUG","YUG"), - c("SXM","CUW","BES", "SRB","MNE")),5) #,"SVN","HRV","MKD","BIH")),9) - w <- calcOutput("Population",aggregate=FALSE)[m[,2],2010,"pop_SSP2"] - x_split <- toolAggregate(x[c("ANT","YUG"),,],m,weight=w) + m <- matrix(c( + c("ANT", "ANT", "ANT", "YUG", "YUG"), # ,"YUG","YUG","YUG","YUG"), + c("SXM", "CUW", "BES", "SRB", "MNE") + ), 5) # ,"SVN","HRV","MKD","BIH")),9) + w <- calcOutput("Population", aggregate = FALSE)[m[, 2], 2010, "pop_SSP2"] + x_split <- toolAggregate(x[c("ANT", "YUG"), , ], m, weight = w) # delete ANT and YUG from x - x <- x[c("ANT","YUG"),,invert=TRUE] - x <- mbind(x,x_split) - + x <- x[c("ANT", "YUG"), , invert = TRUE] + x <- mbind(x, x_split) + #-------------------------------------------------------------------------------- - + # fill all missing countries with 0 - x <- toolCountryFill(x,fill=0) - + x <- toolCountryFill(x, fill = 0, verbosity = 2) + return(x) -} +} diff --git a/R/convertOpenmod.R b/R/convertOpenmod.R index b718c6d5..695bb13e 100644 --- a/R/convertOpenmod.R +++ b/R/convertOpenmod.R @@ -1,33 +1,38 @@ #' Converts Openmod capacities data -#' +#' #' @param x MAgPIE object to be converted -#' @return A MAgPIE object containing openmod EU country disaggregated data with 2010 and 2015 electricity capacities (GW) +#' @return A MAgPIE object containing openmod EU country disaggregated data with +#' 2010 and 2015 electricity capacities (GW) #' @author Renato Rodrigues #' @examples -#' -#' \dontrun{ a <- convertOpenmod(x) +#' \dontrun{ +#' a <- convertOpenmod(x) #' } -#' -#' -#' @importFrom madrat toolCountry2isocode toolGetMapping toolCountryFill -#' - +#' +#' convertOpenmod <- function(x) { - + # loading LIMES country iso code - LIMESMapping <- toolGetMapping("regionmappingLIMES.csv",where = "mappingfolder",type = "regional") + LIMESMapping <- toolGetMapping("regionmappingLIMES.csv", where = "mappingfolder", type = "regional") + # filter only relevant region names - x <- x[LIMESMapping$LIMES_ISO2,,] + x <- x[LIMESMapping$LIMES_ISO2, , ] + # rename countries to REMIND iso codes - getRegions(x) <- toolCountry2isocode(getRegions(x), mapping = setNames(as.character(LIMESMapping$LIMES_ISO3), LIMESMapping$LIMES_ISO2)) - # disaggregate BAL (Balkans) = BIH (Bosnia and Herzegovina), SRB (Serbia), MNE (Montenegro), MKD (Macedonia, the former Yugoslav Republic of) and Albania (ALB) - # todo + getItems(x, dim = 1) <- toolCountry2isocode( + getItems(x, dim = 1), + mapping = setNames(as.character(LIMESMapping$LIMES_ISO3), LIMESMapping$LIMES_ISO2) + ) + + # disaggregate BAL (Balkans) = BIH (Bosnia and Herzegovina), SRB (Serbia), MNE (Montenegro), + # MKD (Macedonia, the former Yugoslav Republic of) and Albania (ALB) + # fill countries with no data - x <- toolCountryFill(x,fill=0,verbosity=0) + x <- toolCountryFill(x, fill = 0, verbosity = 2, no_remove_warning = "BAL") + # replace NAs with 0 x[is.na(x)] <- 0 - + return(x) - } - +} diff --git a/R/convertProdShares.R b/R/convertProdShares.R index 69661c8e..ae0c92a3 100644 --- a/R/convertProdShares.R +++ b/R/convertProdShares.R @@ -1,69 +1,67 @@ #' Reads shares of world manufacture for spv modules and wind turbines. #' @author Aman Malik #' @param x input magpie object -#' @return magpie object with shares +#' @return magpie object with shares + +convertProdShares <- function(x) { + x <- readSource(type = "ProdShares", convert = F) -convertProdShares <- function(x){ - - x <- readSource(type = "ProdShares",convert = F) - # mapping needed for disaggregation - mapping <- toolGetMapping("regionmappingH12.csv",type = "regional",where = "mappingfolder") + mapping <- toolGetMapping("regionmappingH12.csv", type = "regional", where = "mappingfolder") # weight needed for disaggregation - wt= calcOutput(type = "GDP",aggregate = F) - + wt <- calcOutput(type = "GDP", aggregate = F) + # Disaggregating "Europe" in spv - mapping_eur <- mapping[mapping$RegionCode=="EUR",] + mapping_eur <- mapping[mapping$RegionCode == "EUR", ] mapping_eur$RegionCode <- "Europe" - - wt_eur <- wt[mapping_eur$CountryCode,2020,"gdp_SSP2"] - x2 <- toolAggregate(x = x["Europe","y2018","spv"],rel = mapping_eur,weight = wt_eur,from = "CountryCode",to = "RegionCode") - + + wt_eur <- wt[mapping_eur$CountryCode, 2020, "gdp_SSP2"] + x2 <- toolAggregate(x = x["Europe", "y2018", "spv"], rel = mapping_eur, weight = wt_eur, from = "CountryCode", to = "RegionCode") + # Disaggregating "Other" in spv - spv <- x[,"y2018","spv"] - other_cont <- data.frame(setdiff( mapping[mapping$RegionCode!="EUR",]$CountryCode,toolCountry2isocode(getRegions(spv[which(spv>0)])))) - other_cont$Region <- "Other" + spv <- x[, "y2018", "spv"] + other_cont <- data.frame(setdiff(mapping[mapping$RegionCode != "EUR", ]$CountryCode, toolCountry2isocode(getRegions(spv[which(spv > 0)])))) + other_cont$Region <- "Other" colnames(other_cont)[1] <- "Country" - wt_other <- wt[other_cont$Country,"y2020","gdp_SSP2"] - x3 <- toolAggregate(x=spv["Other",,],rel=other_cont,from = "Country",to="Region",weight = wt_other) - + wt_other <- wt[other_cont$Country, "y2020", "gdp_SSP2"] + x3 <- toolAggregate(x = spv["Other", , ], rel = other_cont, from = "Country", to = "Region", weight = wt_other) + # Disaggregating "Other" in wind - - wind <- x[,,"wind"] - wind["Other",,] <- 1- dimSums(wind,dim = 1,na.rm = T) - other_cont <- data.frame(setdiff(mapping$CountryCode,toolCountry2isocode(getRegions(wind[which(wind>0)])))) - other_cont$Region <- "Other" + wind <- x[, , "wind"] + wind["Other", , ] <- 1 - dimSums(wind, dim = 1, na.rm = T) + + other_cont <- data.frame(setdiff(mapping$CountryCode, toolCountry2isocode(getRegions(wind[which(wind > 0)])))) + other_cont$Region <- "Other" colnames(other_cont)[1] <- "Country" - wt_other <- wt[other_cont$Country,"y2020","gdp_SSP2"] - x4 <- toolAggregate(x=wind["Other",,],rel=other_cont,from = "Country",to="Region",weight = wt_other) - + wt_other <- wt[other_cont$Country, "y2020", "gdp_SSP2"] + x4 <- toolAggregate(x = wind["Other", , ], rel = other_cont, from = "Country", to = "Region", weight = wt_other) + # creating copy of x without aggregated regions and countries as ISO and not NA - y <- x[c("Europe","Other"),,invert=T] + y <- x[c("Europe", "Other"), , invert = T] getRegions(y) <- toolCountry2isocode(getRegions(y)) - y[,2019,"spv"] <- y[,2018,"spv"] # forcing spv shares in 2019 to be same as 2018 + y[, 2019, "spv"] <- y[, 2018, "spv"] # forcing spv shares in 2019 to be same as 2018 y[is.na(y)] <- 0 - + # creating new magpie with disaggregated values - z <- new.magpie(mapping$CountryCode,years = getYears(x),names = getNames(x)) - z[getRegions(x2),,"spv"] <- x2 # adding elements from disaggregated spv - z[getRegions(x3),,"spv"] <- x3 - z[getRegions(x4),,"wind"] <- x4 # adding elements from disaggegrated wind - + z <- new.magpie(mapping$CountryCode, years = getYears(x), names = getNames(x)) + z[getRegions(x2), , "spv"] <- x2 # adding elements from disaggregated spv + z[getRegions(x3), , "spv"] <- x3 + z[getRegions(x4), , "wind"] <- x4 # adding elements from disaggegrated wind + # adding elements orignially in magpie object - for (i in getRegions(y)){ - for (j in getNames(y)){ - for (k in getYears(y)){ - if(y[i,k,j]!=0){ - z[i,k,j] <- y[i,k,j] + for (i in getRegions(y)) { + for (j in getNames(y)) { + for (k in getYears(y)) { + if (y[i, k, j] != 0) { + z[i, k, j] <- y[i, k, j] } } } } - - x <- toolCountryFill(z,fill=0) - - return (x) - + + x <- toolCountryFill(z, fill = 0, verbosity = 2) + + return(x) } diff --git a/R/convertRCP.R b/R/convertRCP.R index 8d7eb0bf..ad22847e 100644 --- a/R/convertRCP.R +++ b/R/convertRCP.R @@ -1,63 +1,55 @@ -#' convertRCP +#' convertRCP #' convert RCP data -#' +#' #' @return magpie object of the RCP data #' @author Julian Oeser #' @param x Input object obtained by readSource #' @param subtype Either 'Waste' or 'AviationShipping' #' -#' @importFrom madrat toolAggregate +convertRCP <- function(x, subtype) { + if (subtype == "Waste") { + # weights from EDGAR emissions + ch4 <- readSource("EDGAR", subtype = "ch4waste") + so2 <- readSource("EDGAR", subtype = "SO2") + bc <- readSource("EDGAR", subtype = "CO") + oc <- readSource("EDGAR", subtype = "CO") + co <- readSource("EDGAR", subtype = "CO") + voc <- readSource("EDGAR", subtype = "VOC") + nh3 <- readSource("EDGAR", subtype = "NH3") + nox <- readSource("EDGAR", subtype = "NOx") + ch4 <- add_dimension(ch4, dim = 3.1, "type", "ch4") + so2 <- add_dimension(so2, dim = 3.1, "type", "so2") + bc <- add_dimension(bc, dim = 3.1, "type", "bc") + oc <- add_dimension(oc, dim = 3.1, "type", "oc") + co <- add_dimension(co, dim = 3.1, "type", "CO") + voc <- add_dimension(voc, dim = 3.1, "type", "VOC") + nh3 <- add_dimension(nh3, dim = 3.1, "type", "nh3") + nox <- add_dimension(nox, dim = 3.1, "type", "NOx") -convertRCP <- function(x, subtype){ - - if (subtype=="Waste") { - - # weights from EDGAR emissions - ch4 <- readSource("EDGAR", subtype="ch4waste") - so2 <- readSource("EDGAR", subtype="SO2") - bc <- readSource("EDGAR", subtype="CO") - oc <- readSource("EDGAR", subtype="CO") - co <- readSource("EDGAR", subtype="CO") - voc <- readSource("EDGAR", subtype="VOC") - nh3 <- readSource("EDGAR", subtype="NH3") - nox <- readSource("EDGAR", subtype="NOx") - - - ch4 <- add_dimension(ch4, dim=3.1, "type", "ch4") - so2 <- add_dimension(so2, dim=3.1, "type", "so2") - bc <- add_dimension(bc, dim=3.1, "type", "bc") - oc <- add_dimension(oc, dim=3.1, "type", "oc") - co <- add_dimension(co, dim=3.1, "type", "CO") - voc <- add_dimension(voc, dim=3.1, "type", "VOC") - nh3 <- add_dimension(nh3, dim=3.1, "type", "nh3") - nox <- add_dimension(nox, dim=3.1, "type", "NOx") - weights <- mbind(ch4, so2, bc, oc, co, voc, nh3, nox) - - mappingfile <- toolGetMapping(type = "regional", name = "regionmappingRCP.csv", - returnPathOnly = TRUE, where = "mappingfolder") + mappingfile <- toolGetMapping( + type = "regional", name = "regionmappingRCP.csv", + returnPathOnly = TRUE, where = "mappingfolder" + ) + mapping <- read.csv2(mappingfile, stringsAsFactors = FALSE) countries <- mapping$CountryCode - - weights <- weights[countries,,] - weights <- suppressWarnings(weights[,,"TOTAL", drop=TRUE]) - - weights <- weights[,,getNames(x, dim="type")] + + weights <- weights[countries, , ] + weights <- suppressWarnings(weights[, , "TOTAL", drop = TRUE]) + + weights <- weights[, , getNames(x, dim = "type")] out <- toolAggregate(x, mappingfile, weight = weights) - - out <- toolCountryFill(out, fill=0) - - - } else if (subtype=="AviationShipping") { - - out <- x - + + out <- toolCountryFill(out, fill = 0, verbosity = 2) + } else if (subtype == "AviationShipping") { + out <- x } else { stop("Invalid subtype. Must be 'Waste' or 'AviationShipping'") } - + return(out) } diff --git a/R/convertREMIND_11Regi.R b/R/convertREMIND_11Regi.R index bb95b567..afcc72cd 100644 --- a/R/convertREMIND_11Regi.R +++ b/R/convertREMIND_11Regi.R @@ -36,7 +36,7 @@ convertREMIND_11Regi <- function(x,subtype) { # Converting old Region data to country data y <- toolAggregate(x, mapping, weight=NULL) # Filling missing country data with zero values to avoid convert error check - y <- toolCountryFill(y,fill=0) + y <- toolCountryFill(y, fill = 0, verbosity = 2) } else if (subtype == "fossilExtractionCoeff"){ # weight oil <- readSource("BGR", subtype="oil")[,,"Remaining_Potential"] @@ -45,7 +45,7 @@ convertREMIND_11Regi <- function(x,subtype) { BGRData <- list(lowOil = oil, medOil = oil, highOil = oil, lowGas = gas, medGas = gas, highGas = gas, lowCoal = coal, medCoal = coal, highCoal = coal) # filling all countries weights and adding a very small weight to countries with no remaining potential to estimate a very step cost curve in this case weight <- lapply(BGRData, function(df){ - df <- toolCountryFill(df,fill=0) + df <- toolCountryFill(df, fill = 0, verbosity = 2) df[df == 0] <- 1E-20 return(df) }) @@ -71,7 +71,7 @@ convertREMIND_11Regi <- function(x,subtype) { x[,,"peur.xi4"] <- 0 # weight BGRuranium <- readSource("BGR", subtype="uranium")[,,"Remaining_Potential"] # Remaining extraction potential per country - BGRuranium <- toolCountryFill(BGRuranium,fill=0) + BGRuranium <- toolCountryFill(BGRuranium, fill = 0, verbosity = 2) BGRuranium[BGRuranium == 0] <- 1E-3 # assigning small uranium extraction potential for countries with none to help the curves estimation weight <- list(peur = BGRuranium) # mapping - original REMIND region mapping (11 regions) diff --git a/R/convertREN21.R b/R/convertREN21.R index d764dd31..1d39dea8 100644 --- a/R/convertREN21.R +++ b/R/convertREN21.R @@ -1,32 +1,32 @@ #' Policy targets for REN21 -#' @description This code aggregates and homogenises different types of renewable energy targets into total installed capacity targets (in GW). +#' @description This code aggregates and homogenises different types of +#' renewable energy targets into total installed capacity targets (in GW). #' @details Policy database accessible in "inputdata/sources/REN21/README" #' @param x MAgPIE object to be converted #' @param subtype Only "Capacity" asof now #' @return Magpie object with Total Installed Capacity targets. The target years differ depending upon the database. -#' @importFrom R.utils isZero -#' @importFrom magclass magpiesort getItems #' @author Aman Malik - convertREN21 <- function(x, subtype) { if (subtype == "Capacity") { x <- magpiesort(x) # sorting years chronologically and region names alphabetically x[is.na(x)] <- 0 # Converting all NAs to zero - getItems(x,dim = 1) <- toolCountry2isocode(getItems(x,dim = 1)) # Country names to ISO3 code + getItems(x, dim = 1) <- toolCountry2isocode(getItems(x, dim = 1)) # Country names to ISO3 code # reading historical data hist_cap <- readSource(type = "IRENA", subtype = "Capacity") / 1000 # converting from MW to GW hist_gen <- readSource("IRENA", subtype = "Generation") # Units are GWh # Real world capacity factor for hydro = Generation in last year/Capacity in 2015 - cf_realworld <- hist_gen[, 2015, "Hydropower"] / (8760 * hist_cap[, 2015, "Hydropower"]) + cf_realworld <- hist_gen[, 2015, "Renewable hydropower"] / (8760 * hist_cap[, 2015, "Renewable hydropower"]) cf_realworld[is.na(cf_realworld)] <- 0 getNames(cf_realworld) <- "Hydro" # renaming variable names from IRENA historical database - getNames(hist_cap)[c(2, 7, 8, 10, 11, 12)] <- c("Hydro", "Wind_ON", "Wind_OFF", "SolarPV", - "SolarCSP", "Biomass") + getNames(hist_cap)[c(2, 7, 8, 10, 11, 12)] <- c( + "Hydro", "Wind_ON", "Wind_OFF", "SolarPV", + "SolarCSP", "Biomass" + ) x_tmp <- x # contains original targets + targets extrapolated to model years @@ -34,7 +34,7 @@ convertREN21 <- function(x, subtype) { x_tmp <- add_columns(x_tmp, addnm = "Wind", dim = 3.2) x_tmp[, , "Wind"] <- x_tmp[, , "Wind_ON"] + x_tmp[, , "Wind_OFF"] - # Selecting relevant technologies i.e., all except "Base Year" + # Selecting relevant technologies i.e., all except "Base Year" techs <- c("SolarPV", "SolarCSP", "Wind", "Hydro", "Biomass", "Geothermal") # 1. If targets are given in non-model year. e.g., 2022, 2032, then targets are extrapolated linearly. @@ -42,125 +42,119 @@ convertREN21 <- function(x, subtype) { input_yr <- input_yr[input_yr %% 5 != 0] # years not multiple of 5/non-model years # Selecting relevant model years target_years <- c(2020, 2025, 2030, 2035, 2040) - regions <- getItems(x_tmp,dim = 1) + regions <- getItems(x_tmp, dim = 1) tech_n <- getNames(x_tmp[, , techs]) for (r in regions) { for (t in tech_n) { - for (i in input_yr) { - if (x_tmp[r, i, t] != 0) { - if (i > 2015 & i < 2020) - x_tmp[r, 2020, tech_n] <- setYears(x_tmp[r, i, tech_n]) * (1 + (2020 - i) * 0.05) - if (i > 2020 & i < 2025) - x_tmp[r, 2025, tech_n] <- setYears(x_tmp[r, i, tech_n]) * (1 + (2025 - i) * 0.05) - if (i > 2025 & i < 2030) - x_tmp[r, 2030, tech_n] <- setYears(x_tmp[r, i, tech_n]) * (1 + (2030 - i) * 0.05) - if (i > 2030 & i < 2035) - x_tmp[r, 2035, tech_n] <- setYears(x_tmp[r, i, tech_n]) * (1 + (2035 - i) * 0.05) - if (i > 2035 & i < 2040) - x_tmp[r, 2040, tech_n] <- setYears(x_tmp[r, i, tech_n]) * (1 + (2040 - i) * 0.05) - # else - } - } + for (i in input_yr) { + if (x_tmp[r, i, t] != 0) { + if (i > 2015 && i < 2020) { + x_tmp[r, 2020, tech_n] <- setYears(x_tmp[r, i, tech_n]) * (1 + (2020 - i) * 0.05) + } + if (i > 2020 && i < 2025) { + x_tmp[r, 2025, tech_n] <- setYears(x_tmp[r, i, tech_n]) * (1 + (2025 - i) * 0.05) + } + if (i > 2025 && i < 2030) { + x_tmp[r, 2030, tech_n] <- setYears(x_tmp[r, i, tech_n]) * (1 + (2030 - i) * 0.05) + } + if (i > 2030 && i < 2035) { + x_tmp[r, 2035, tech_n] <- setYears(x_tmp[r, i, tech_n]) * (1 + (2035 - i) * 0.05) + } + if (i > 2035 && i < 2040) { + x_tmp[r, 2040, tech_n] <- setYears(x_tmp[r, i, tech_n]) * (1 + (2040 - i) * 0.05) + } + # else + } + } } } # for now# x_tmp <- x_tmp[,target_years,] # only take model years # Creating new magpie object containing historical or base year targets - x_cap <- new.magpie(getItems(x_tmp,dim = 1), target_years, techs) + x_cap <- new.magpie(getItems(x_tmp, dim = 1), target_years, techs) x_cap[is.na(x_cap)] <- 0 # replacing NAs with zero # Capacity factors in REMIND. From : calcOutput("Capacityfactor"...) cf_biomass <- 0.75 cf_geothermal <- 0.8 cf_hydro <- cf_realworld - # Initialising all capacities for all model years to historical 2015 capacities. - # except when Base year is mentioned (then initialise with base year capacities) and except for Hydro which will get historical generation. + # except when Base year is mentioned (then initialise with base year capacities) + # and except for Hydro which will get historical generation. year <- getYears(x_tmp) for (t in year) { - for (r in getItems(x_tmp,dim = 1)) { - if (x_tmp[r, t, "AC-Absolute.Base year"] != 0) - x_cap[r, , ] <- setYears(hist_cap[r, x_tmp[r, t, "AC-Absolute.Base year"], techs]) - else - x_cap[r, , ] <- setYears(hist_cap[r, 2015, techs]) + for (r in getItems(x_tmp, dim = 1)) { + if (x_tmp[r, t, "AC-Absolute.Base year"] != 0) { + x_cap[r, , ] <- setYears(hist_cap[r, x_tmp[r, t, "AC-Absolute.Base year"], techs]) + } else { + x_cap[r, , ] <- setYears(hist_cap[r, 2015, techs]) + } } } # for hydro overwrite capacity with generation - x_cap[, , "Hydro"] <- setYears(hist_gen[getRegions(x_cap), 2015, "Hydropower"]) - + x_cap[, , "Hydro"] <- setYears(hist_gen[getItems(x_cap, dim = 1), 2015, "Renewable hydropower"]) - # x_current <- x_cap x_cap_ac <- x_cap # object will contain additional capacity targets as absolute capacity targets x_cap_ac[] <- 0 - x_cap_pt <- x_cap # object will contain generation targets as absolute capacity targets + x_cap_pt <- x_cap # object will contain generation targets as absolute capacity targets x_cap_pt[] <- 0 x_cap_tic <- x_cap # object will contain total installed capacity targets x_cap_tic[] <- 0 - - # Converting additional capacity targets to absolute capacity targets. - # x_new_abs[,,"Biomass"] <- x_current[,,"Biomass"] + x_tmp[,,"AC-Absolute.Biomass",drop=TRUE] - # + x_cap_ac[, , c("Biomass", "Wind", "SolarPV", "SolarCSP")] <- x_cap[, , c("Biomass", "Wind", "SolarPV", "SolarCSP")] + x_tmp[, target_years, c("AC-Absolute.Biomass", "AC-Absolute.Wind", "AC-Absolute.SolarPV", "AC-Absolute.SolarCSP"), drop = TRUE] # For hydro converting to additional generation targets - x_cap_ac[, , "Hydro"] <- x_cap[, , "Hydro"] + x_tmp[, target_years, "AC-Absolute.Hydro", drop = TRUE] * setYears(cf_hydro[getItems(x_tmp,dim = 1), , ] * 8760) + x_cap_ac[, , "Hydro"] <- x_cap[, , "Hydro"] + x_tmp[, target_years, "AC-Absolute.Hydro", drop = TRUE] * setYears(cf_hydro[getItems(x_tmp, dim = 1), , ] * 8760) - # Total installed capacity Targets for all technologies + # Total installed capacity Targets for all technologies x_cap_tic[, , c("Wind", "SolarPV", "SolarCSP", "Biomass")] <- pmax(x_cap[, , c("Wind", "SolarPV", "SolarCSP", "Biomass")], x_tmp[, target_years, c("Wind", "SolarPV", "SolarCSP", "Biomass")][, , "TIC-Absolute", drop = TRUE]) - x_cap_tic[, , "Hydro"] <- pmax(x_cap[, , "Hydro"], x_tmp[, target_years, "TIC-Absolute.Hydro", drop = TRUE] * setYears(cf_hydro[getItems(x_tmp,dim=1), , ] * 8760)) + x_cap_tic[, , "Hydro"] <- pmax(x_cap[, , "Hydro"], x_tmp[, target_years, "TIC-Absolute.Hydro", drop = TRUE] * setYears(cf_hydro[getItems(x_tmp, dim = 1), , ] * 8760)) # Converting Production targets (GWh) to Capacity targets (TIC-Absolute) (GW) for geothermal and biomass # pmax takes the higher value from existing capacity and new capacity derived (from production) x_cap_pt[, , "Biomass"] <- pmax(x_cap[, , "Biomass"], x_tmp[, target_years, "Production-Absolute.Biomass"] / (8760 * cf_biomass)) x_cap_pt[, , "Geothermal"] <- pmax(x_cap[, , "Geothermal"], x_tmp[, target_years, c("Production-Absolute.Geothermal")] / (8760 * cf_geothermal)) - # for solar, wind, and hydro conversion will be done using another method below - x_cap_pt[, target_years, c("SolarPV", "SolarCSP", "Wind")] <- x_tmp[, target_years, c("SolarPV", "SolarCSP", "Wind")][, , "Production-Absolute", drop = TRUE] + # for solar, wind, and hydro conversion will be done using another method below + x_cap_pt[, target_years, c("SolarPV", "SolarCSP", "Wind")] <- x_tmp[, target_years, c("SolarPV", "SolarCSP", "Wind")][, , "Production-Absolute", drop = TRUE] -# Converting Production targets to capacity targets for solar and wind -# Fpr Hydro, all targets (which have already been converted into generation targets) will be converted into capacity targets based on maxprod and capacity factors. -# + # Converting Production targets to capacity targets for solar and wind + # For Hydro, all targets (which have already been converted into generation targets) will be + # converted into capacity targets based on maxprod and capacity factors. - # x_tmp[,target_years,"Production-Absolute.Hydro"] <- pmax(x_tmp[,target_years,"Production-Absolute.Hydro"],x_cap_tic[,,"Hydro"],x_cap_ac[,,"Hydro"]) - # Special case for hydro as mentioned above - x_cap_pt[, target_years, "Hydro"] <- pmax(x_tmp[, target_years, "Production-Absolute.Hydro"], x_cap_tic[, , "Hydro"], x_cap_ac[, , "Hydro"]) + # Special case for hydro as mentioned above + x_cap_pt[, target_years, "Hydro"] <- pmax(x_tmp[, target_years, "Production-Absolute.Hydro"], x_cap_tic[, , "Hydro"], x_cap_ac[, , "Hydro"]) -# Obtaining the capacity factors (nur) values and associated maxproduction (maxprod) for Hydro, Wind, and Solar + # Obtaining the capacity factors (nur) values and associated maxproduction (maxprod) for Hydro, Wind, and Solar data_wind <- calcOutput("PotentialWindOn", aggregate = FALSE) # Reordering dim=3 for data_wind so that 1st position corresponds to maxprod.nur.1 and not maxprod.nur.9 - data_wind_sorted <- mbind(data_wind[, , "1"], data_wind[, , "2"], data_wind[, , "3"], data_wind[, , "4"], - data_wind[, , "5"], data_wind[, , "6"], data_wind[, , "7"], data_wind[, , "8"], data_wind[, , "9"]) + data_wind_sorted <- mbind( + data_wind[, , "1"], data_wind[, , "2"], data_wind[, , "3"], data_wind[, , "4"], + data_wind[, , "5"], data_wind[, , "6"], data_wind[, , "7"], data_wind[, , "8"], data_wind[, , "9"] + ) data_hydro <- calcOutput("PotentialHydro", aggregate = FALSE) - #data_solar <- calcOutput("Solar", aggregate = FALSE) data_solar <- calcOutput("Solar") names_solarPV <- paste0("SolarPV.", getNames(collapseNames((mselect(data_solar, type = c("nur", "maxprod"), technology = "spv")), collapsedim = 2))) names_solarCSP <- paste0("SolarCSP.", getNames(collapseNames((mselect(data_solar, type = c("nur", "maxprod"), technology = "csp")), collapsedim = 2))) names_hydro <- paste0("Hydro.", getNames(data_hydro)) names_wind <- paste0("Wind.", getNames(data_wind_sorted)) - data_combined <- new.magpie(getItems(data_hydro, dim=1), NULL, c(names_solarPV, names_solarCSP, names_hydro, names_wind)) + data_combined <- new.magpie(getItems(data_hydro, dim = 1), NULL, c(names_solarPV, names_solarCSP, names_hydro, names_wind)) data_combined[, , "Hydro"] <- data_hydro data_combined[, , "Wind"] <- data_wind_sorted - # For countries with targets but without maxprod and nur value for solar (in data_solar), - # we hardcode - # data_combined[c("KOR"), , "SolarPV"][, , "maxprod"] <- as.vector(data_solar[c("JPN","GRC"), , "maxprod"][, , "spv"]) - # data_combined[c("KOR"), , "SolarPV"][, , "nur"] <- as.vector(data_solar[c("JPN", "GRC"), , "nur"][, , "spv"]) - # data_combined[c("KOR"), , "SolarCSP"][, , "maxprod"] <- as.vector(data_solar[c("GRC", "GRC"), , "maxprod"][, , "csp"]) - # data_combined[c("KOR"), , "SolarCSP"][, , "nur"] <- as.vector(data_solar[c("JPN", "GRC"), , "nur"][, , "csp"]) - - data_combined[c("MKD"), , c("SolarPV","SolarCSP")][, , c("maxprod","nur")] <- as.vector(data_solar[c("JPN"), , c("spv","csp")][, , c("maxprod","nur")]) - data_combined[c("KOR"), , c("SolarPV","SolarCSP")][, , c("maxprod","nur")] <- as.vector(data_solar[c("JPN"), , c("spv","csp")][, , c("maxprod","nur")]) - - data_combined <- data_combined[getItems(x_tmp, dim=1), , ] # only interested in limited dataset + data_combined[c("MKD"), , c("SolarPV", "SolarCSP")][, , c("maxprod", "nur")] <- as.vector(data_solar[c("JPN"), , c("spv", "csp")][, , c("maxprod", "nur")]) + data_combined[c("KOR"), , c("SolarPV", "SolarCSP")][, , c("maxprod", "nur")] <- as.vector(data_solar[c("JPN"), , c("spv", "csp")][, , c("maxprod", "nur")]) + + data_combined <- data_combined[getItems(x_tmp, dim = 1), , ] # only interested in limited dataset for (n in getNames(data_combined, dim = 1)) { name <- paste0(n, ".maxprod") @@ -169,99 +163,98 @@ convertREN21 <- function(x, subtype) { } final <- numeric(nregions(x_tmp)) - names(final) <- getItems(x_tmp,dim=1) + names(final) <- getItems(x_tmp, dim = 1) tmp_target <- numeric(10) x_cap_pt_2_tic <- x_cap x_cap_pt_2_tic[] <- 0 - # # For all countries which have non-zero generation values but zero or negative maxprod() for hydro (i.e., for some read), replace x_tmp[,,"Production-Absolute.Hydro]==0, Even if there is one +ve production absolute value for Hydro but all maxprod are zero + # For all countries which have non-zero generation values but zero or negative + # maxprod() for hydro (i.e., for some read), replace x_tmp[,,"Production-Absolute.Hydro]==0, + # Even if there is one +ve production absolute value for Hydro but all maxprod are zero for (t in c("SolarPV", "SolarCSP", "Wind", "Hydro")) { data_sel <- data_combined[, , t] - data_in_use <- data_sel[, , "maxprod"] / data_sel[, , "nur"] + data_in_use <- data_sel[, , "maxprod"] / data_sel[, , "nur"] for (y in target_years) { final[] <- 0 for (r in names(final)) { # Only start loop if Production targets are non-zero and if the maxprod for that country can absorb the targets set. name <- paste0(t, ".maxprod") - # name2 <- paste0("Production-Absolute.",t) - if (!isZero(x_cap_pt[r, y, t] & - dimSums(data_combined[r, , name]) > max(x_cap_pt[r, , t]))) { # extracting the first non-zero location of maxprod - # name <- paste0(t,".maxprod") - loc <- min(which(!isZero(data_combined[r, , name, pmatch = TRUE]))) + if (!R.utils::isZero(x_cap_pt[r, y, t] & + dimSums(data_combined[r, , name]) > max(x_cap_pt[r, , t]))) { # extracting the first non-zero location of maxprod + loc <- min(which(!R.utils::isZero(data_combined[r, , name, pmatch = TRUE]))) tmp_target[1] <- x_cap_pt[r, y, t] if (data_sel[r, , "maxprod"][, , loc] > tmp_target[1]) { final[r] <- tmp_target[1] / (8760 * data_sel[r, , "nur"][, , loc]) } else { -tmp_target[2] <- tmp_target[1] - data_sel[r, , "maxprod"][, , loc] - if (data_sel[r, , "maxprod"][, , loc + 1] > tmp_target[2]) { - final[r] <- (1 / 8760) * (data_in_use[r, , ][, , loc] + tmp_target[2] / data_sel[r, , "nur"][, , loc + 1]) - } else { -tmp_target[3] <- tmp_target[2] - data_sel[r, , "maxprod"][loc + 1] - if (data_sel[r, , "maxprod"][, , loc + 2] > tmp_target[3]) { - final[r] <- (1 / 8760) * (data_in_use[r, , ][loc] + data_in_use[r, , ][loc + 1] + - tmp_target[3] / data_sel[r, , "nur"][loc + 2]) - } else { -tmp_target[4] <- tmp_target[3] - data_sel[r, , "maxprod"][, , loc + 2] - if (data_sel[r, , "maxprod"][, , loc + 3] > tmp_target[4]) { - final[r] <- (1 / 8760) * (data_in_use[r, , ][, , loc] + data_in_use[r, , ][loc + 1] + data_in_use[r, , ][, , loc + 2] + - tmp_target[4] / data_sel[r, , "nur"][, , loc + 3]) - - } else { -tmp_target[5] <- tmp_target[4] - data_sel[r, , "maxprod"][, , loc + 3] - if (data_sel[r, , "maxprod"][loc + 4] > tmp_target[5]) { - final[r] <- (1 / 8760) * (data_in_use[r, , ][, , loc] + data_in_use[r, , ][loc + 1] + data_in_use[r, , ][, , loc + 2] + - data_in_use[r, , ][, , loc + 3] + tmp_target[5] / data_sel[r, , "nur"][, , loc + 4]) - } else { -tmp_target[6] <- tmp_target[5] - data_sel[r, , "maxprod"][, , loc + 4] - if (data_sel[r, , "maxprod"][loc + 5] > tmp_target[6]) { - final[r] <- (1 / 8760) * (data_in_use[r, , ][, , loc] + data_in_use[r, , ][loc + 1] + data_in_use[r, , ][, , loc + 2] + - data_in_use[r, , ][, , loc + 3] + data_in_use[r, , ][, , loc + 4] + - tmp_target[6] / data_sel[r, , "nur"][, , loc + 5]) - } else { -tmp_target[7] <- tmp_target[6] - data_sel[r, , "maxprod"][, , loc + 5] - if (data_sel[r, , "maxprod"][loc + 6] > tmp_target[7]) { - final[r] <- (1 / 8760) * (data_in_use[r, , ][, , loc] + data_in_use[r, , ][loc + 1] + data_in_use[r, , ][, , loc + 2] + - data_in_use[r, , ][, , loc + 3] + data_in_use[r, , ][, , loc + 4] + data_in_use[r, , ][, , loc + 5] - + tmp_target[7] / data_sel[r, , "nur"][, , loc + 6]) - } else { -tmp_target[8] <- tmp_target[7] - data_sel[r, , "maxprod"][, , loc + 6] - if (data_sel[r, , "maxprod"][loc + 7] > tmp_target[8]) { - final[r] <- (1 / 8760) * (data_in_use[r, , ][, , loc] + data_in_use[r, , ][loc + 1] + data_in_use[r, , ][, , loc + 2] + - data_in_use[r, , ][, , loc + 3] + data_in_use[r, , ][, , loc + 4] + data_in_use[r, , ][, , loc + 5] - + data_in_use[r, , ][, , loc + 6] + tmp_target[8] / data_sel[r, , "nur"][, , loc + 7]) - } - } - } - } - } - } + tmp_target[2] <- tmp_target[1] - data_sel[r, , "maxprod"][, , loc] + if (data_sel[r, , "maxprod"][, , loc + 1] > tmp_target[2]) { + final[r] <- (1 / 8760) * (data_in_use[r, , ][, , loc] + tmp_target[2] / data_sel[r, , "nur"][, , loc + 1]) + } else { + tmp_target[3] <- tmp_target[2] - data_sel[r, , "maxprod"][loc + 1] + if (data_sel[r, , "maxprod"][, , loc + 2] > tmp_target[3]) { + final[r] <- (1 / 8760) * (data_in_use[r, , ][loc] + data_in_use[r, , ][loc + 1] + + tmp_target[3] / data_sel[r, , "nur"][loc + 2]) + } else { + tmp_target[4] <- tmp_target[3] - data_sel[r, , "maxprod"][, , loc + 2] + if (data_sel[r, , "maxprod"][, , loc + 3] > tmp_target[4]) { + final[r] <- (1 / 8760) * (data_in_use[r, , ][, , loc] + data_in_use[r, , ][loc + 1] + data_in_use[r, , ][, , loc + 2] + + tmp_target[4] / data_sel[r, , "nur"][, , loc + 3]) + } else { + tmp_target[5] <- tmp_target[4] - data_sel[r, , "maxprod"][, , loc + 3] + if (data_sel[r, , "maxprod"][loc + 4] > tmp_target[5]) { + final[r] <- (1 / 8760) * (data_in_use[r, , ][, , loc] + data_in_use[r, , ][loc + 1] + data_in_use[r, , ][, , loc + 2] + + data_in_use[r, , ][, , loc + 3] + tmp_target[5] / data_sel[r, , "nur"][, , loc + 4]) + } else { + tmp_target[6] <- tmp_target[5] - data_sel[r, , "maxprod"][, , loc + 4] + if (data_sel[r, , "maxprod"][loc + 5] > tmp_target[6]) { + final[r] <- (1 / 8760) * (data_in_use[r, , ][, , loc] + data_in_use[r, , ][loc + 1] + data_in_use[r, , ][, , loc + 2] + + data_in_use[r, , ][, , loc + 3] + data_in_use[r, , ][, , loc + 4] + + tmp_target[6] / data_sel[r, , "nur"][, , loc + 5]) + } else { + tmp_target[7] <- tmp_target[6] - data_sel[r, , "maxprod"][, , loc + 5] + if (data_sel[r, , "maxprod"][loc + 6] > tmp_target[7]) { + final[r] <- (1 / 8760) * (data_in_use[r, , ][, , loc] + data_in_use[r, , ][loc + 1] + data_in_use[r, , ][, , loc + 2] + + data_in_use[r, , ][, , loc + 3] + data_in_use[r, , ][, , loc + 4] + data_in_use[r, , ][, , loc + 5] + + tmp_target[7] / data_sel[r, , "nur"][, , loc + 6]) + } else { + tmp_target[8] <- tmp_target[7] - data_sel[r, , "maxprod"][, , loc + 6] + if (data_sel[r, , "maxprod"][loc + 7] > tmp_target[8]) { + final[r] <- (1 / 8760) * (data_in_use[r, , ][, , loc] + data_in_use[r, , ][loc + 1] + data_in_use[r, , ][, , loc + 2] + + data_in_use[r, , ][, , loc + 3] + data_in_use[r, , ][, , loc + 4] + data_in_use[r, , ][, , loc + 5] + + data_in_use[r, , ][, , loc + 6] + tmp_target[8] / data_sel[r, , "nur"][, , loc + 7]) + } + } + } + } + } + } + } } - } - } } + } x_cap_pt_2_tic[, y, t] <- final } } - # combining generation to installed capacity targets of biomass and geothermal from before - x_cap_pt_2_tic <- mbind(x_cap_pt_2_tic[, , c("SolarPV", "SolarCSP", "Wind", "Hydro")], x_cap_pt[, , c("Biomass", "Geothermal")]) - # choose the maximum of installed capacity targets - techs_e_hydro <- setdiff(techs, "Hydro") - x_cap_pt_2_tic[, , techs_e_hydro] <- pmax(x_cap_ac[, , techs_e_hydro], x_cap_tic[, , techs_e_hydro], x_cap_pt_2_tic[, , techs_e_hydro]) - - for (r in regions) { - for (t in techs) { - for (i in c(2020, 2025, 2030, 2035)) { - if (x_cap_pt_2_tic[r, i + 5, t] < setYears(x_cap_pt_2_tic[r, i, t])) { - x_cap_pt_2_tic[r, i + 5, t] <- setYears(x_cap_pt_2_tic[r, i, t]) + # combining generation to installed capacity targets of biomass and geothermal from before + x_cap_pt_2_tic <- mbind(x_cap_pt_2_tic[, , c("SolarPV", "SolarCSP", "Wind", "Hydro")], x_cap_pt[, , c("Biomass", "Geothermal")]) + # choose the maximum of installed capacity targets + techs_e_hydro <- setdiff(techs, "Hydro") + x_cap_pt_2_tic[, , techs_e_hydro] <- pmax(x_cap_ac[, , techs_e_hydro], x_cap_tic[, , techs_e_hydro], x_cap_pt_2_tic[, , techs_e_hydro]) + + for (r in regions) { + for (t in techs) { + for (i in c(2020, 2025, 2030, 2035)) { + if (x_cap_pt_2_tic[r, i + 5, t] < setYears(x_cap_pt_2_tic[r, i, t])) { + x_cap_pt_2_tic[r, i + 5, t] <- setYears(x_cap_pt_2_tic[r, i, t]) + } } } } - } # countries not in the REN21 capacity targets database - rest_regions <- setdiff(getRegions(hist_cap), getRegions(x_cap)) - x_other <- new.magpie(rest_regions, target_years, techs) + rest_regions <- setdiff(getRegions(hist_cap), getRegions(x_cap)) + x_other <- new.magpie(rest_regions, target_years, techs) # for all other countries not in database, targets for all model years are historical capacities x_other[, , c("Wind", "SolarPV", "SolarCSP", "Biomass", "Geothermal")] <- setYears(hist_cap[rest_regions, 2019, techs_e_hydro]) x_other[, , "Hydro"] <- setYears(hist_cap[rest_regions, 2019, "Hydro"]) * setYears(cf_hydro[rest_regions, , ]) @@ -271,11 +264,10 @@ tmp_target[8] <- tmp_target[7] - data_sel[r, , "maxprod"][, , loc + 6] # renaming to REMIND convention getNames(x) <- c("spv", "csp", "wind", "hydro", "biochp", "geohdr") } else if (subtype == "investmentCosts") { - # save data of specific countries x_country <- x[c("China", "India", "United States"), , ] # translate country names into ISO-codes - getRegions(x_country) <- toolCountry2isocode(getRegions(x_country)) + getItems(x_country, dim = 1) <- toolCountry2isocode(getRegions(x_country)) # delete those countries from x x <- x[c("China", "India", "United States"), , , invert = TRUE] @@ -285,8 +277,7 @@ tmp_target[8] <- tmp_target[7] - data_sel[r, , "maxprod"][, , loc + 6] # overwrite country data x[getRegions(x_country), , ] <- x_country - } - return (x) + return(x) } diff --git a/R/convertRam.R b/R/convertRam.R deleted file mode 100644 index 519ed65e..00000000 --- a/R/convertRam.R +++ /dev/null @@ -1,29 +0,0 @@ -#' Regional multiliers from Ram et al. , 2018 -# x <- readSource("Ram",convert=F) -#' @param x MAgPIE object to be converted - -convertRam <- function(x){ - mapr <- toolGetMapping(type = "regional", name = "regionmappingH12.csv", where = "mappingfolder") - - #x <- readSource(type = "Ram",convert=F) - x_final <- new.magpie(cells_and_regions = mapr$CountryCode,years = seq(2015,2050,5),names = "value") - - # mapping REMIND regions to regions from Ram et al. - - x_final[mapr[mapr$RegionCode=="EUR",]$CountryCode,,] <- x["Europe",,] - x_final[mapr[mapr$RegionCode=="NEU",]$CountryCode,,] <- x["Europe",,] - x_final[mapr[mapr$RegionCode=="LAM",]$CountryCode,,] <- x["South America",,] - x_final[mapr[mapr$RegionCode=="MEA",]$CountryCode,,] <- x["MENA",,] - x_final[mapr[mapr$RegionCode=="SSA",]$CountryCode,,] <- x["Sub-Saharan Africa",,] - x_final[mapr[mapr$RegionCode=="CHA",]$CountryCode,,] <- x["Northeast Asia",,] - x_final[mapr[mapr$RegionCode=="JPN",]$CountryCode,,] <- x["Northeast Asia",,] - x_final[mapr[mapr$RegionCode=="REF",]$CountryCode,,] <- x["Eurasia",,] - x_final[mapr[mapr$RegionCode=="OAS",]$CountryCode,,] <- x["Southeast Asia",,] - x_final[mapr[mapr$RegionCode=="USA",]$CountryCode,,] <- x["North America",,] - x_final[mapr[mapr$RegionCode=="OAS",]$CountryCode,,] <- x["Southeast Asia",,] - x_final[mapr[mapr$RegionCode=="CAZ",]$CountryCode,,] <- x["North America",,] - x_final[c("IND","PAK","BGD","NPL","LKA","MDV","AFG","BTN"),,] <- x["SAARC",,] - x <- x_final - return (x) - -} diff --git a/R/convertRutovitz2015.R b/R/convertRutovitz2015.R deleted file mode 100644 index 5c19630c..00000000 --- a/R/convertRutovitz2015.R +++ /dev/null @@ -1,159 +0,0 @@ -#' @title convertRutovitz2015 -#' @param x MAgPIE object to be converted -#' @param subtype "oecd_ef" or "regional_mult" or "regional_ef" or "coal_ef" or "gas_ef" -#' @author Aman Malik -#' @importFrom stats na.omit - - -convertRutovitz2015 <- function(x, subtype) { - country <- NULL - year <- NULL - region <- NULL - value <- NULL - tech <- NULL - activity <- NULL - - mapping <- toolGetMapping(type = "regional", name = "regionalmappingWEO2014.csv", where = "mappingfolder") - colnames(mapping) <- c("region", "country") - mapping$country <- toolCountry2isocode(mapping$country) - - if (subtype == "oecd_ef") { - # x <- readSource(type = "Rutovitz2015",subtype = "oecd_ef",convert = FALSE) - - # oecd regions in mapping file - oecd <- c("OECD Europe", "OECD Americas", "OECD Asia Oceania") - # oecd countries from mapping file - oecd_con <- mapping[mapping$region %in% oecd, ]$country - - - # since x cannot directly be changed to accept OECD countries and years, - # make a new magpie object - oecd_ef <- new.magpie(unique(oecd_con), c(2015, 2020, 2030), names = getNames(x)) - getSets(oecd_ef) <- getSets(x) - - # assign all countries and techs, same value as x - oecd_ef[, , ] <- x - oecd_ef[is.na(oecd_ef)] <- 0 - x <- toolCountryFill(oecd_ef, fill = 0) - - - } - if (subtype == "regional_mult") { - - # x <- readSource(type = "Rutovitz2015",subtype = "regional_mult",convert=FALSE) - reg_mult <- as.data.frame(x) %>% - select(2, 3, 5) %>% - rename(region = 1, year = 2, value = 3) - - mapping$region <- gsub("OECD Europe|OECD Asia Oceania|OECD Americas", "OECD", x = mapping$region) - mapping$region <- gsub("Central Africa|West Africa|Southern Africa|East Africa|North Africa", "Africa", x = mapping$region) - - # assign countries to regions - reg_mult2 <- left_join(reg_mult, mapping, by = "region") %>% - mutate(country = ifelse(region == "China", "CHN", country)) %>% - mutate(country = ifelse(region == "India", "IND", country)) %>% - filter(!(region == "Non-OECD Asia" & country == "CHN")) %>% # removing duplicates - filter(!(region == "Non-OECD Asia" & country == "IND")) %>% # removing duplicates - select(country, year, value) - - x <- as.magpie(reg_mult2) - - x <- toolCountryFill(x, fill = 0) - x["CYP", , ] <- as.numeric(x["DEU", , ]) # cyprus gets oecd values - - } - if (subtype == "regional_ef") { - - # x <- readSource(type = "Rutovitz2015",subtype = "regional_ef",convert = FALSE) - - # Changing names of column "regions" in mapping to better match both data frames - mapping$region <- gsub("Central Africa|West Africa|Southern Africa|East Africa|North Africa", "Africa", x = mapping$region) - getItems(x, dim = 1) <- gsub(getItems(x, dim = 1), replacement = c("OECD Americas"), pattern = c("OECD North America")) # replace OECD Americas with OECD North America - - - x_df <- as.data.frame(x) %>% - select(2, 4, 5, 6) %>% - rename(region = 1, tech = 2, activity = 3, value = 4) %>% - na.omit() %>% - left_join(mapping, by = "region") %>% - select(country, tech, activity, value) - - x <- as.magpie(x_df, spatial = 1, temporal = NULL, datacol = 4) - x[is.na(x)] <- 0 # for all countries with no data, replace by 0 - x <- toolCountryFill(x, fill = 0) - getYears(x) <- 2015 - - } - if (subtype == "coal_ef") { - # x <- readSource(type = "Rutovitz2015",subtype = "coal_ef",convert = FALSE) - - mapping$region <- gsub("Central Africa|West Africa|Southern Africa|East Africa|North Africa", "Africa", x = mapping$region) - - getItems(x, dim = 1) <- gsub("OECD North America", "OECD Americas", x = getItems(x, dim = 1)) - getItems(x, dim = 1) <- gsub("OECD Pacific", "OECD Asia Oceania", x = getItems(x, dim = 1)) - getItems(x, dim = 1) <- gsub("Developing Asia", "Non-OECD Asia", x = getItems(x, dim = 1)) - - # assign countries to all regions in Rutovitz for coal employment factors - x_df <- as.data.frame(x) %>% - select(2, 4, 5, 6) %>% - rename(region = 1, tech = 2, activity = 3, value = 4) - - x_df <- left_join(x_df, mapping, by = "region") - x_df <- x_df %>% - mutate(country = ifelse(region == "China", "CHN", country)) %>% - mutate(country = ifelse(region == "India", "IND", country)) %>% - filter(!(region == "Non-OECD Asia" & country == "CHN")) %>% # removing duplicates - filter(!(region == "Non-OECD Asia" & country == "IND")) %>% # removing duplicates - na.omit() %>% - select(country, tech, activity, value, -region) - - x <- as.magpie(x_df, spatial = 1, temporal = NULL, datacol = 4) - getYears(x) <- 2015 - x <- toolCountryFill(x, fill = 0) - - } - if (subtype == "gas_ef") { - # x <- readSource(type = "Rutovitz2015",subtype = "gas_ef",convert = FALSE) - # getRegions(x) <- gsub("OECD North America","OECD Americas",x = getRegions(x)) - # getRegions(x) <- gsub("OECD Pacific","OECD Asia Oceania",x = getRegions(x)) - # getRegions(x) <- gsub("Developing Asia","Non-OECD Asia",x = getRegions(x)) - getItems(x, dim = 1) <- gsub("OECD North America", "OECD Americas", getItems(x, dim = 1)) - getItems(x, dim = 1) <- gsub("OECD Pacific", "OECD Asia Oceania", getItems(x, dim = 1)) - getItems(x, dim = 1) <- gsub("Developing Asia", "Non-OECD Asia", getItems(x, dim = 1)) - - - mapping$region <- gsub("Central Africa|West Africa|Southern Africa|East Africa|North Africa", "Africa", x = mapping$region) - - - x_df <- as.data.frame(x) %>% - select(2, 4, 5, 6) %>% - rename(region = 1, tech = 2, activity = 3, value = 4) %>% - filter(!region %in% unique(mapping$region)) - - - x_df$region <- toolCountry2isocode(x_df$region) - - x_df_2 <- as.data.frame(x) %>% - select(2, 4, 5, 6) %>% - rename(region = 1, tech = 2, activity = 3, value = 4) %>% - filter(region %in% unique(mapping$region)) %>% - left_join(mapping, by = "region") %>% - filter(!country %in% x_df$region) %>% - na.omit() %>% - select(-region) %>% - rename(region = country) %>% - select(region, tech, activity, value) - - x_df <- bind_rows(x_df, x_df_2) - - x <- as.magpie(x_df, spatial = 1, temporal = NULL, datacol = 4) - getYears(x) <- 2015 - x <- toolCountryFill(x, fill = 0) - # Oil EF for Fuel_supply is same as Gas Fuel supply - x <- add_columns(x, addnm = "Oil", dim = 3.1) - x[, , "Oil"] <- x[, , "Gas"] - - } - - return (x) -} diff --git a/R/convertStationary.R b/R/convertStationary.R index b236cc34..de3d59b7 100644 --- a/R/convertStationary.R +++ b/R/convertStationary.R @@ -164,7 +164,7 @@ convertStationary <- function(x) { xadd <- toolAggregate(x, mappingfile, weight = wfe, from = region_col, to = iso_col) - result <- toolCountryFill(xadd, 0) + result <- toolCountryFill(xadd, 0, verbosity = 2) # re-calculating fepet and fedie final energy based on updated EDGE shares share <- readSource(type = "EDGETransport", subtype = "shares_LDV_transport") diff --git a/R/convertStegmann2022.R b/R/convertStegmann2022.R index f1167795..99da3922 100644 --- a/R/convertStegmann2022.R +++ b/R/convertStegmann2022.R @@ -13,7 +13,7 @@ convertStegmann2022 <- function(x) { fe <- calcOutput("FE", source = "IEA", aggregate = FALSE)[unique(regmapping$CountryCode), 2016, "FE (EJ/yr)"] out <- toolAggregate(x, regmapping, from = "RegionAbbreviation", to = "CountryCode", weight = fe) - out <- toolCountryFill(out, fill = 0) + out <- toolCountryFill(out, fill = 0, verbosity = 2) return(out) } diff --git a/R/convertTCdamageKrichene.R b/R/convertTCdamageKrichene.R index 65d347a4..77a1a96e 100644 --- a/R/convertTCdamageKrichene.R +++ b/R/convertTCdamageKrichene.R @@ -5,6 +5,6 @@ #' @return MAgPIE object containing values for all 249 ISO countries convertTCdamageKrichene <- function(x){ - out <- toolCountryFill(x,fill=0,verbosity=1) + out <- toolCountryFill(x, fill = 0, verbosity = 2, no_remove_warning = c("GLB")) return(out) } diff --git a/R/convertTransportSubisidies.R b/R/convertTransportSubisidies.R index 7a7b6ecc..75e21d0d 100644 --- a/R/convertTransportSubisidies.R +++ b/R/convertTransportSubisidies.R @@ -1,19 +1,16 @@ #' Converts transport subsidies data -#' +#' #' @param x MAgPIE object to be converted #' @return A MAgPIE object containing transport subsidies per technology #' @author Renato Rodrigues #' @examples -#' -#' \dontrun{ a <- convertTransportSubsidies(x) +#' \dontrun{ +#' a <- convertTransportSubsidies(x) #' } -#' +#' +convertTransportSubsidies <- function(x) { + x <- toolCountryFill(x, fill = 0, verbosity = 2) # fill countries with no data + x[is.na(x)] <- 0 - convertTransportSubsidies <- function(x) { - - x <- toolCountryFill(x,fill=0,verbosity=2) # fill countries with no data - x[is.na(x)] <- 0 - - return(x) - } - + return(x) +} diff --git a/R/convertUBA.R b/R/convertUBA.R index 542d54b4..8f6f7581 100644 --- a/R/convertUBA.R +++ b/R/convertUBA.R @@ -1,34 +1,15 @@ #' Convert UBA data -#' +#' #' @md -#' @param x A [`magpie`][magclass::magclass] object returned from +#' @param x A [`magpie`][magclass::magclass] object returned from #' [`readUBA()`]. #' #' @return A [`magpie`][magclass::magclass] object. -#' +#' #' @author Falk Benke -#' -#' @importFrom dplyr %>% mutate select -#' @importFrom madrat getISOlist -#' @importFrom magclass as.data.frame as.magpie -#' @importFrom quitte character.data.frame -#' @importFrom rlang sym syms -#' @importFrom tibble as_tibble -#' @importFrom tidyr complete nesting -#' +#' +#' #' @export -convertUBA <- function(x) -{ - - x %>% - as.data.frame() %>% - as_tibble() %>% - select('region' = 'Region', 'variable' = 'Data1', 'unit' = 'Data2', - 'year' = 'Year', 'value' = 'Value') %>% - character.data.frame() %>% - mutate(year = as.integer(!!sym('year'))) %>% - complete(nesting(!!!syms(c('variable', 'unit', 'year'))), - region = setNames(getISOlist(), NULL)) %>% - as.magpie(tidy = TRUE) %>% - return() +convertUBA <- function(x) { + return(add_columns(x, addnm = setdiff(getISOlist(), "DEU"), dim = 1, fill = NA)) } diff --git a/R/convertUNFCCC.R b/R/convertUNFCCC.R index a276231f..4524afa2 100644 --- a/R/convertUNFCCC.R +++ b/R/convertUNFCCC.R @@ -1,43 +1,16 @@ #' Convert UNFCCC data -#' +#' #' @md -#' @param x A [`magpie`][magclass::magclass] object returned from +#' @param x A [`magpie`][magclass::magclass] object returned from #' [`readUNFCCC()`]. #' #' @return A [`magpie`][magclass::magclass] object. -#' +#' #' @author Falk Benke -#' -#' @importFrom dplyr %>% mutate select -#' @importFrom madrat getISOlist -#' @importFrom magclass as.data.frame as.magpie -#' @importFrom quitte character.data.frame -#' @importFrom rlang sym syms -#' @importFrom tibble as_tibble -#' @importFrom tidyr complete nesting -#' +#' +#' #' @export -convertUNFCCC <- function(x) -{ - x <- as.data.frame(x) %>% - as_tibble() %>% - select('region' = 'Region', 'variable' = 'Data1', 'unit' = 'Data2', - 'year' = 'Year', 'value' = 'Value') %>% - character.data.frame() %>% - filter(!!sym("region") %in% getISOlist()) %>% - mutate(year = as.integer(!!sym('year'))) %>% - complete(nesting(!!!syms(c('variable', 'unit', 'year'))), - region = setNames(getISOlist(), NULL)) %>% - as.magpie(tidy = TRUE) - - # fill countries of selected regions with 0 to allow for region aggregation - regions.fill <- c("EUR", "REF", "NEU", "CAZ") - mapping <- toolGetMapping("regionmappingH12.csv", type = "regional", where = "mappingfolder") %>% filter( - !!sym("RegionCode") %in% regions.fill - ) - tmp <- x[unique(mapping$CountryCode),,] - tmp[is.na(tmp)] <- 0 - x[unique(mapping$CountryCode),,] <- tmp - +convertUNFCCC <- function(x) { + x <- toolCountryFill(x, verbosity = 2, no_remove_warning = "EUA") return(x) } diff --git a/R/convertUNFCCC_NDC.R b/R/convertUNFCCC_NDC.R index 76066e01..b62bd4f1 100644 --- a/R/convertUNFCCC_NDC.R +++ b/R/convertUNFCCC_NDC.R @@ -7,8 +7,6 @@ #' Emissions_YYYY_uncond for Emissions targets, with YYYY NDC version year #' @return Magpie object with Total Installed Capacity (GW) targets, target years differ depending upon the database. #' @author Aman Malik, Christoph Bertram, Oliver Richters -#' @importFrom magclass nyears -#' @importFrom R.utils isZero convertUNFCCC_NDC <- function(x, subtype) { # nolint: object_name_linter. if (grepl("Capacity", subtype, fixed = TRUE)) { @@ -75,7 +73,7 @@ convertUNFCCC_NDC <- function(x, subtype) { # nol hist_gen <- readSource("IRENA", subtype = "Generation") # Units are GWh # Real world capacity factor for hydro = Generation in last year/Capacity in last year - cf_hydro_realworld <- hist_gen[, 2015, "Hydropower"] / (8760 * hist_cap[, 2015, "Hydropower"]) + cf_hydro_realworld <- hist_gen[, 2015, "Renewable hydropower"] / (8760 * hist_cap[, 2015, "Renewable hydropower"]) cf_hydro_realworld[is.na(cf_hydro_realworld) | is.infinite(cf_hydro_realworld)] <- 0 getNames(cf_hydro_realworld) <- "Hydro" @@ -90,7 +88,7 @@ convertUNFCCC_NDC <- function(x, subtype) { # nol x_capacity[, , "Biomass"] <- setYears(hist_cap[getItems(x_mod5, dim = "region"), 2015, "Bioenergy"]) # special case for hydro. - x_capacity[, , "Hydro"] <- setYears(hist_gen[getItems(x_capacity, dim = "region"), 2015, "Hydropower"]) + x_capacity[, , "Hydro"] <- setYears(hist_gen[getItems(x_capacity, dim = "region"), 2015, "Renewable hydropower"]) # Special case for nuclear hist_gen_nuclear <- readSource("BP", subtype = "Generation") * 1000 # TWh to GWh for (i in targetYears) { @@ -172,7 +170,7 @@ convertUNFCCC_NDC <- function(x, subtype) { # nol tmp_target <- numeric(10) name <- paste0(t, ".maxprod") name2 <- paste0("Production-Absolute.", t) - if (!isZero(x_mod5[, , "Production-Absolute"][, , t])[r, y, ] & + if (!R.utils::isZero(x_mod5[, , "Production-Absolute"][, , t])[r, y, ] & dimSums(data_combined[r, , name], na.rm = TRUE) > max(x_mod5[r, , name2])) { # extracting the first non-zero location of maxprod name <- paste0(t, ".maxprod") @@ -243,11 +241,11 @@ convertUNFCCC_NDC <- function(x, subtype) { # nol x_other[, , c("Wind", "Solar")] <- setYears(hist_cap[rest_regions, 2015, c("Solar", "Wind")]) x_other[, , "Nuclear"] <- 0 x_other[, , "Biomass"] <- setYears(hist_cap[rest_regions, 2015, "Bioenergy"]) - x_other[, , "Hydro"] <- setYears(hist_cap[rest_regions, 2015, "Hydropower"]) * setYears(cf_hydro[rest_regions, , ]) + x_other[, , "Hydro"] <- setYears(hist_cap[rest_regions, 2015, "Renewable hydropower"]) * setYears(cf_hydro[rest_regions, , ]) x_final <- magpiesort(mbind(x_capacity, x_other)) x_final[is.na(x_final)] <- 0 - x <- toolCountryFill(x_final, fill = NA) # will be returned + x <- toolCountryFill(x_final, fill = NA, verbosity = 2) # will be returned getNames(x) <- c("wind", "spv", "hydro", "tnrs", "bioigcc") # end subtype contains Capacity @@ -376,7 +374,7 @@ convertUNFCCC_NDC <- function(x, subtype) { # nol ghgfactor[regi, , ][ghgfactor[regi, , ] > 2.5] <- NA } } - x <- toolCountryFill(ghgfactor, fill = NA) + x <- toolCountryFill(ghgfactor, fill = NA, verbosity = 2) } # end subtype = Emissions_all diff --git a/R/convertWGBU.R b/R/convertWGBU.R index d8cb2919..fb983649 100644 --- a/R/convertWGBU.R +++ b/R/convertWGBU.R @@ -1,33 +1,34 @@ #' Convert WGBU data -#' +#' #' Convert WGBU data on ISO country level. -#' -#' +#' +#' #' @param x MAgPIE object containing WGBU data country-region resolution #' @return WGBU data as MAgPIE object aggregated to country level #' @author Lavinia Baumstark #' @examples -#' -#' \dontrun{ a <- convertWGBU(x) +#' \dontrun{ +#' a <- convertWGBU(x) #' } -#' +#' convertWGBU <- function(x) { - - # remove world data - x <- x["Welt",,invert=TRUE] # FIXME do we need it for the missing regions? - - # remove aggregated data ("total * ") # FIXME do we need it for the difference to the sum over the related countries? - x <- x["Total",,pmatch=TRUE,invert=TRUE] - + # remove world data + # FIXME do we need it for the missing regions? + x <- x["Welt", , invert = TRUE] + + # remove aggregated data ("total * ") + # FIXME do we need it for the difference to the sum over the related countries? + x <- x["Total", , pmatch = TRUE, invert = TRUE] + # remove space from region names - getRegions(x) <- gsub(" ","",getRegions(x)) + getItems(x, dim = 1) <- gsub(" ", "", getItems(x, dim = 1)) # rename countries with ISO-code # FIXME delete Persien for now - x <- x["Persien",,invert=TRUE] - getRegions(x) <- toolCountry2isocode(getRegions(x)) - + x <- x["Persien", , invert = TRUE] + getItems(x, dim = 1) <- toolCountry2isocode(getItems(x, dim = 1)) + # fill all missing countries with 0 - x <- toolCountryFill(x,fill=0) - + x <- toolCountryFill(x, fill = 0, verbose = 2) + return(x) -} +} diff --git a/R/convertnonEnergyDemand.R b/R/convertnonEnergyDemand.R index de5f47b2..e5f8fc9a 100644 --- a/R/convertnonEnergyDemand.R +++ b/R/convertnonEnergyDemand.R @@ -1,25 +1,23 @@ #' Converts Final energy demand for feedstocks (non-energy use) -#' +#' #' @param x MAgPIE object to be converted #' @return A MAgPIE object containing country disaggregated data #' @author Renato Rodrigues #' @examples -#' -#' \dontrun{ a <- convertnonEnergyDemand(x) +#' \dontrun{ +#' a <- convertnonEnergyDemand(x) #' } -#' - +#' convertnonEnergyDemand <- function(x) { - # Replacing NA values with zero x[is.na(x)] <- 0 - + # weight to convert to country data values - IO <- calcOutput("IO",subtype="output",aggregate=FALSE)[,2010,c("seliqfos.fehoi","segafos.fegai","sesofos.fesoi")] - w <- setNames(IO[,,c("seliqfos.fehoi.tdfoshoi","segafos.fegai.tdfosgai","sesofos.fesoi.tdfossoi")],c("chemicals.fehos","chemicals.fegas","chemicals.fesos")) - + IO <- calcOutput("IO", subtype = "output", aggregate = FALSE)[, 2010, c("seliqfos.fehoi", "segafos.fegai", "sesofos.fesoi")] + w <- setNames(IO[, , c("seliqfos.fehoi.tdfoshoi", "segafos.fegai.tdfosgai", "sesofos.fesoi.tdfossoi")], c("chemicals.fehos", "chemicals.fegas", "chemicals.fesos")) + # converting from REMIND-EU regions to country data using industry FE as weight - y <- toolAggregate(x, toolGetMapping(type = "regional", name = "regionmapping_21_EU11.csv", where = "mappingfolder")[,c(1:3)], weight=w) + y <- toolAggregate(x, toolGetMapping(type = "regional", name = "regionmapping_21_EU11.csv", where = "mappingfolder")[, c(1:3)], weight = w) -return(y) + return(y) } diff --git a/R/exportThresholds.R b/R/exportThresholds.R new file mode 100644 index 00000000..9bf37c99 --- /dev/null +++ b/R/exportThresholds.R @@ -0,0 +1,98 @@ +#' export validation thresholds +#' +#' assemble near-term thresholds from project pipelines and potentially other +#' data sources and export them to a file +#' +#' @author Pascal Weigmann +#' @param type choose either "config" to export thresholds as used in the +#' validationConfig or "full" to export all pipeline data +#' @param years choose years to include, currently only 2025 and 2030 are +#' available for all sources +#' @export +exportThresholds <- function(type = "config", years = c(2025, 2030)) { + # extra regions for ELEVATE + # setConfig(regionmapping = "regionmappingR10_elevate.csv") + # setConfig(forcecache = "GDP") + # extraRegions <- c("CHN", "IND", "IDN", "VNM", "PAK") + + # get region mappings for aggregation ---- + # Determines all regions data should be aggregated to by examining the columns + # of the `regionmapping` and `extramappings` currently configured. + rel <- "global" # always compute global aggregate + for (mapping in c(getConfig("regionmapping"), getConfig("extramappings"))) { + columns <- setdiff( + colnames(toolGetMapping(mapping, "regional")), + c("X", "CountryCode") + ) + + if (any(columns %in% rel)) { + warning( + "The following column(s) from ", mapping, + " exist in another mapping an will be ignored: ", + paste(columns[columns %in% rel], collapse = ", ") + ) + } + rel <- unique(c(rel, columns)) + } + + columnsForAggregation <- gsub( + "RegionCode", "region", + paste(rel, collapse = "+") + ) + + # the following magclass objects are expected to have the dimensions "status" + # as dim 3.3 + ccs <- calcOutput("ProjectPipelines", subtype = "CCS", + aggregate = columnsForAggregation, round = 3, + warnNA = FALSE, try = FALSE, years = years) + + hydro <- calcOutput("ProjectPipelines", subtype = "hydro", + aggregate = columnsForAggregation, round = 3, + warnNA = FALSE, try = FALSE, years = years) + + wind <- calcOutput("ProjectPipelines", subtype = "wind", + aggregate = columnsForAggregation, round = 3, + warnNA = FALSE, try = FALSE, years = years) + + solar <- calcOutput("ProjectPipelines", subtype = "solar", + aggregate = columnsForAggregation, round = 3, + warnNA = FALSE, try = FALSE, years = years) + + # combine and export data to madrat output folder + + out <- mbind(ccs, hydro, wind, solar) + # remove ROW region, in case it exists + out <- out["ROW", , invert = TRUE] + + # export + if (type == "full") { + # write report containing all available data, including all statuses and + # thresholds attached to "variable" + outfile <- "pipelines.mif" + as.quitte(out) %>% + mutate(variable = paste(variable, status, sep = "|")) %>% + select(-scenario, -status) %>% + as.magpie() %>% + write.report(file = paste0(getConfig("outputfolder"), "/", outfile)) + + } else if (type == "config") { + # write report containing only the "min/max" thresholds in extra columns + # (as used in a validationConfig) + outfile <- "thresholds.mif" + out <- out[, , c("min_", "max_"), pmatch = TRUE] %>% + as.quitte() %>% + pivot_wider(names_from = "status") %>% + select(-scenario) + # exclude rows without any threshold + out[!(is.na(out$min_red) + & is.na(out$min_yel) + & is.na(out$max_yel) + & is.na(out$max_red)), ] %>% + write.csv(file = paste0(getConfig("outputfolder"), "/", outfile), + row.names = FALSE, quote = FALSE) + + } else { + warning("`type` must be either `full` or `config`") + } + +} diff --git a/R/filter_historical_mif.R b/R/filter_historical_mif.R index d5928198..c86d3f27 100644 --- a/R/filter_historical_mif.R +++ b/R/filter_historical_mif.R @@ -19,8 +19,6 @@ #' `include_regions`, and `exclude_regions`. Defaults to the built-in #' `./inst/extdata/historical_mif_filter_table.csv` of the `mrremind` package. #' -#' @importFrom madrat getConfig -#' @importFrom magclass getItems mbind read.report write.report #' @importFrom quitte cartesian #' @export diff --git a/R/fullREMIND.R b/R/fullREMIND.R index 97396908..e7c2e8a3 100644 --- a/R/fullREMIND.R +++ b/R/fullREMIND.R @@ -18,8 +18,6 @@ fullREMIND <- function() { rem_years <- seq(2005, 2150, 5) rem_years_hist <- seq(1990, 2150, 5) - madratAttach("edgeTransport") # enable madrat caching for edgeTransport - #-------------- macro-economic parameters ----------------------------------------------------------- calcOutput("Population", years = rem_years_hist, round = 8, file = "f_pop.cs3r") calcOutput("Labour", years = rem_years, round = 8, file = "f_lab.cs3r") @@ -65,33 +63,36 @@ fullREMIND <- function() { calcOutput("GDP", years = rem_years_hist, round = 8, file = "f50_gdp.cs3r", aggregate = FALSE) calcOutput("TCdamage", subtype = "const", round = 8, file = "f50_TC_df_const.cs4r", aggregate = FALSE) calcOutput("TCdamage", subtype = "tasK", round = 8, file = "f50_TC_df_tasK.cs4r", aggregate = FALSE) + calcOutput("KLWdamage", subtype = "beta1", round = 8, file = "f50_KLW_df_beta1.cs4r", aggregate = FALSE) + calcOutput("KLWdamage", subtype = "beta2", round = 8, file = "f50_KLW_df_beta2.cs4r", aggregate = FALSE) + calcOutput("KLWdamage", subtype = "maxGMT", round = 8, file = "f50_KLW_df_maxGMT.cs4r", aggregate = FALSE) #-------------- emission parameter ------------------------------------------------------------------ - calcOutput("EconometricEmiParameter", round = 5, file = "p_emineg_econometric.cs3r") - calcOutput("EmissionsTe", round = 5, file = "p_boundEmi.cs4r") - calcOutput("HistEmissions", subtype = "sector", round = 8, file = "p_histEmiSector.cs4r") - calcOutput("HistEmissions", subtype = "MAC", round = 8, file = "p_histEmiMac.cs4r") - calcOutput("EmiCO2LandUse", round = 5, file = "p_macPolCO2luc.cs4r") - calcOutput("MacBaseLandUse", subtype = "DirectlyFromMAgPIE", round = 5, file = "f_macBaseMagpie.cs4r") - calcOutput("MacBaseLandUse", subtype = "Exogenous", round = 5, file = "f_macBaseExo.cs4r") - calcOutput("MACCsCO2", round = 5, file = "p_abatparam_CO2.cs4r", aggregate = FALSE) - calcOutput("EmiMac", round = 5, file = "p_macBase2005.cs4r") - calcOutput("EmiMac1990", round = 5, file = "p_macBase1990.cs4r") - calcOutput("MACCbaseN2O", round = 5, file = "p_macBaseVanv.cs4r") - calcOutput("MACCsCH4", round = 6, file = "p_abatparam_CH4.cs4r") - calcOutput("MACCsN2O", round = 6, file = "p_abatparam_N2O.cs4r") - calcOutput("FGas", round = 6, file = "f_emiFgas.cs4r") - calcOutput("EmiFossilFuelExtr", round = 6, file = "p_emiFossilFuelExtr.cs4r") - calcOutput("Region2MAGICC", round = 6, file = "p_regi_2_MAGICC_regions.cs3r") - calcOutput("EmiPollutantExo", subtype = "AviationShipping", round = 6, file = "f11_emiAPexoGlob.cs4r", aggregate = FALSE) - calcOutput("EmiPollutantExo", subtype = "Waste", round = 6, file = "f11_emiAPexo.cs4r") - calcOutput("EmiAirPollLandUse", round = 6, file = "f11_emiAPexoAgricult.cs4r") - calcOutput("GAINSEmi", subtype = "emissions", round = 5, file = "emi_gains.cs4r") - calcOutput("GAINSEmi", subtype = "emission_factors", round = 5, file = "ef_gains.cs4r") - calcOutput("GAINSEmi", subtype = "emissions_starting_values", round = 5, file = "f11_emiAPexsolve.cs4r") - calcOutput("EmissionFactors", subtype = "emission_factors", round = 5, file = "f11_emiFacAP.cs4r") - calcOutput("EmissionFactorsFeedstocks", round = 5, file = "f_nechem_emissionFactors.cs4r") - calcOutput("EmiLULUCFCountryAcc", subtype = "UNFCCC", round = 5, file = "p_EmiLULUCFCountryAcc.cs4r") + calcOutput("EconometricEmiParameter", round = 5, file = "p_emineg_econometric.cs3r") + calcOutput("EmissionsTe", round = 5, file = "p_boundEmi.cs4r") + calcOutput("HistEmissions", subtype = "sector", round = 8, file = "p_histEmiSector.cs4r") + calcOutput("HistEmissions", subtype = "MAC", round = 8, file = "p_histEmiMac.cs4r") + calcOutput("EmiCO2LandUse", round = 5, file = "p_macPolCO2luc.cs4r") + calcOutput("MacBaseLandUse", subtype = "DirectlyFromMAgPIE", round = 5, file = "f_macBaseMagpie.cs4r") + calcOutput("MacBaseLandUse", subtype = "Exogenous", round = 5, file = "f_macBaseExo.cs4r") + calcOutput("MACCsCO2", round = 5, file = "p_abatparam_CO2.cs4r", aggregate = FALSE) + calcOutput("EmiMac", round = 5, file = "p_macBase2005.cs4r") + calcOutput("EmiMac1990", round = 5, file = "p_macBase1990.cs4r") + calcOutput("MACCbaseN2O", round = 5, file = "p_macBaseVanv.cs4r") + calcOutput("MACCsCH4", round = 6, file = "p_abatparam_CH4.cs4r") + calcOutput("MACCsN2O", round = 6, file = "p_abatparam_N2O.cs4r") + calcOutput("FGas", round = 6, file = "f_emiFgas.cs4r") + calcOutput("EmiFossilFuelExtr", round = 6, file = "p_emiFossilFuelExtr.cs4r") + calcOutput("Region2MAGICC", round = 6, file = "p_regi_2_MAGICC_regions.cs3r") + calcOutput("EmiPollutantExo", subtype = "AviationShipping", round = 6, file = "f11_emiAPexoGlob.cs4r", aggregate = FALSE) + calcOutput("EmiPollutantExo", subtype = "Waste", round = 6, file = "f11_emiAPexo.cs4r") + calcOutput("EmiAirPollLandUse", round = 6, file = "f11_emiAPexoAgricult.cs4r") + calcOutput("GAINSEmi", subtype = "emissions", round = 5, file = "emi_gains.cs4r") + calcOutput("GAINSEmi", subtype = "emission_factors", round = 5, file = "ef_gains.cs4r") + calcOutput("GAINSEmi", subtype = "emissions_starting_values", round = 5, file = "f11_emiAPexsolve.cs4r") + calcOutput("EmissionFactors", subtype = "emission_factors", warnNA = TRUE, round = 5, file = "f11_emiFacAP.cs4r") + calcOutput("EmissionFactorsFeedstocks", round = 5, file = "f_nechem_emissionFactors.cs4r") + calcOutput("EmiLULUCFCountryAcc", subtype = "UNFCCC", round = 5, file = "p_EmiLULUCFCountryAcc.cs4r") #-------------- energy/technology parameters --------------------------------------------------------- calcOutput("PotentialHydro", round = 3, file = "f_maxProdGradeRegiHydro.cs3r") @@ -116,7 +117,6 @@ fullREMIND <- function() { # delete the 'dummy' line system(paste0('sed -i "/dummy/d" ', getConfig()$outputfolder, "/p37_clinker-to-cement-ratio.cs3r")) - calcOutput("Capacity", subtype = "capacityByTech", round = 6, file = "p_histCap.cs3r") # will be deleted after the merge of REMIND-EU calcOutput("Capacity", subtype = "capacityByTech", round = 6, file = "pm_histCap.cs3r") calcOutput("Capacity", subtype = "capacityByTech_windoff", round = 6, file = "pm_histCap_windoff.cs3r") calcOutput("Capacity", subtype = "capacityByPE", round = 6, file = "p_PE_histCap.cs3r") @@ -128,9 +128,25 @@ fullREMIND <- function() { calcOutput("FEShares", subtype = "ind_liq", round = 5, file = "p_share_ind_fehos.cs4r") calcOutput("Solar", round = 5, file = "f_dataRegiSolar.cs3r") calcOutput("CapacityNuclear", round = 5, file = "pm_NuclearConstraint.cs4r") - calcOutput("CCScapacity", round = 8, file = "pm_boundCapCCS.cs4r") + calcOutput("CCScapacity", subtype = "pipeline", round = 8, file = "p_boundCapCCS.cs4r") calcOutput("CCSbounds", round = 8, file = "p_boundCapCCSindicator.cs4r") calcOutput("LimitCCS", round = 8, file = "pm_dataccs.cs3r") + calcOutput('Industry_CCS_limits', + a1 = 0.3, a2 = 0.15, installation_minimum = 1, + stage_weight = c('Operational' = 1, + 'In construction' = 1, + 'Advanced development' = 0.5, + 'Early development' = 0.2), + signif = 3, file = 'f37_indCCSlimit_default.cs4r', + years = seq(2005, 2050, 5)) + calcOutput('Industry_CCS_limits', + a1 = 0.5, a2 = 0.25, installation_minimum = 1, + stage_weight = c('Operational' = 1, + 'In construction' = 1, + 'Advanced development' = 0.8, + 'Early development' = 0.5), + signif = 3, file = 'f37_indCCSlimit_high.cs4r', + years = seq(2005, 2050, 5)) calcOutput("BiomassPrices", round = 6, file = "f30_bioen_price.cs4r") calcOutput("ResFor2ndBioengery", years = rem_years, round = 5, file = "p30_biolcResidues.cs3r") calcOutput("1stBioDem", subtype = "ethanol_oils", years = rem_years, round = 5, file = "p30_bio1stgen.cs3r") @@ -157,22 +173,17 @@ fullREMIND <- function() { #--------------- EDGE Transport --------------------------------------------------------------------- calcOutput("TransportGDPshare", round = 6, file = "f35_transportGDPshare.cs4r") - calcOutput("EDGETransport", subtype = "value_time", file = "value_time.cs4r") - calcOutput("EDGETransport", subtype = "harmonized_intensities", file = "harmonized_intensities.cs4r") - calcOutput("EDGETransport", subtype = "price_nonmot", file = "price_nonmot.cs4r") - calcOutput("EDGETransport", subtype = "pref", file = "pref.cs4r") - calcOutput("EDGETransport", subtype = "UCD_NEC_iso", file = "UCD_NEC_iso.cs4r") - calcOutput("EDGETransport", subtype = "loadFactor", file = "loadFactor.cs4r") - calcOutput("EDGETransport", subtype = "fe_demand_tech", file = "fe_demand_tech.cs4r") - calcOutput("EDGETransport", subtype = "fe2es", file = "fe2es.cs4r") - calcOutput("EDGETransport", subtype = "esCapCost", file = "esCapCost.cs4r") - calcOutput("EDGETransport", subtype = "pm_trp_demand", file = "pm_trp_demand.cs4r") - calcOutput("EDGETransport", subtype = "pm_fe_demand_EDGETbased", file = "pm_fe_demand_EDGETbased.cs4r") - calcOutput("EDGETransport", subtype = "annual_mileage", file = "annual_mileage.cs4r") - - # not to be aggregated as global - calcOutput("EDGETransport", subtype = "logit_exponent", aggregate = FALSE, file = "logit_exponent.cs4r") - calcOutput("EDGETransport", subtype = "ptab4W", aggregate = FALSE, file = "ptab4W.cs4r") + calcOutput("EDGETransport", subtype = "f35_esCapCost", file = "f35_esCapCost.cs4r") + calcOutput("EDGETransport", subtype = "f35_fe2es", file = "f35_fe2es.cs4r") + calcOutput("EDGETransport", subtype = "f35_demByTech", file = "f35_demByTech.cs4r") + calcOutput("EDGETransport", subtype = "f29_trpdemand", file = "f29_trpdemand.cs4r") + calcOutput("EDGETransport", subtype = "CAPEXandNonFuelOPEX", file = "CAPEXandNonFuelOPEX.cs4r") + calcOutput("EDGETransport", subtype = "scenSpecPrefTrends", file = "scenSpecPrefTrends.cs4r") + calcOutput("EDGETransport", subtype = "scenSpecLoadFactor", file = "scenSpecLoadFactor.cs4r") + calcOutput("EDGETransport", subtype = "scenSpecEnIntensity", file = "scenSpecEnIntensity.cs4r") + calcOutput("EDGETransport", subtype = "initialIncoCosts", file = "initialIncoCosts.cs4r") + calcOutput("EDGETransport", subtype = "annualMileage", file = "annualMileage.cs4r") + calcOutput("EDGETransport", subtype = "timeValueCosts", file = "timeValueCosts.cs4r") #---------------policy parameters-------------------------------------------------------------------- calcOutput("EmiTarget", sources = "UNFCCC_NDC", subtype = "Ghgshare2005", round = 4, file = "fm_2005shareTarget.cs3r") @@ -186,4 +197,6 @@ fullREMIND <- function() { calcOutput("EffortSharingRefEmi", subtype = "EEA_GHG", round = 6, file = "p47_ESR_GHG_referenceEmissions.cs4r") calcOutput("EffortSharingRefEmi", subtype = "REMIND_CO2", round = 6, file = "p47_ESR_CO2_referenceEmissions.cs4r") calcOutput("ETSRefEmi", subtype = "EEA_GHG", round = 6, file = "p47_ETS_GHG_referenceEmissions.cs4r") + calcOutput("ExpertGuess", subtype = "tradeConstraints", aggregate = FALSE, file = "p24_trade_constraints.cs4r") + } diff --git a/R/fullVALIDATIONREMIND.R b/R/fullVALIDATIONREMIND.R index 4fbb775b..d79ab3d7 100644 --- a/R/fullVALIDATIONREMIND.R +++ b/R/fullVALIDATIONREMIND.R @@ -15,7 +15,7 @@ fullVALIDATIONREMIND <- function(rev = 0) { - years = NULL + years <- NULL # get region mappings for aggregation ---- # Determines all regions data should be aggregated to by examining the columns @@ -88,6 +88,7 @@ fullVALIDATIONREMIND <- function(rev = 0) { ) # EDGAR8 Emissions---- + edg8 <- calcOutput( type = "Emissions", datasource = "EDGAR8", aggregate = columnsForAggregation, warnNA = FALSE, @@ -131,6 +132,15 @@ fullVALIDATIONREMIND <- function(rev = 0) { writeArgs = list(scenario = "historical") ) + # EU National GHG Projections ---- + + calcOutput( + type = "EEAGHGProjections", file = valfile, + aggregate = columnsForAggregation, append = TRUE, warnNA = FALSE, + try = FALSE, years = years, + writeArgs = list(scenario = "historical") + ) + # Global Energy Monitor ---- calcOutput( @@ -157,7 +167,7 @@ fullVALIDATIONREMIND <- function(rev = 0) { writeArgs = list(scenario = "historical") ) - # IEA EV Outlook ---- + # IEA Global EV Outlook ---- calcOutput( type = "IEA_EVOutlook", file = valfile, @@ -166,23 +176,22 @@ fullVALIDATIONREMIND <- function(rev = 0) { ) - # IEA WEO 2021 ---- - weo <- calcOutput( - type = "IEA_WEO_2021", subtype = "global", aggregate = columnsForAggregation, - warnNA = FALSE, try = FALSE, years = years, + # IEA World Energy Outlook ---- + calcOutput( + type = "IEA_WorldEnergyOutlook", file = valfile, + aggregate = columnsForAggregation, append = TRUE, warnNA = FALSE, + try = FALSE, years = years, writeArgs = list(scenario = "historical") ) - weo <- weo["GLO", , ] - write.report(weo, file = valfile, append = TRUE, scenario = "historical") + # IEA CCUS ---- - weo <- calcOutput( - type = "IEA_WEO_2021", subtype = "region", aggregate = columnsForAggregation, - warnNA = FALSE, try = FALSE, years = years, + calcOutput( + type = "CCScapacity", subtype = "historical", file = valfile, + aggregate = columnsForAggregation, append = TRUE, warnNA = FALSE, + try = FALSE, years = years, + writeArgs = list(scenario = "historical") ) - weo <- weo["GLO", , invert = TRUE] - write.report(weo, file = valfile, append = TRUE, scenario = "historical") - # INNOPATHS ---- calcOutput( diff --git a/R/industry_subsectors_specific.R b/R/industry_subsectors_specific.R index a741740c..f1e70156 100644 --- a/R/industry_subsectors_specific.R +++ b/R/industry_subsectors_specific.R @@ -50,7 +50,6 @@ #' @author Michaja Pehl #' #' @importFrom dplyr anti_join bind_rows filter select -#' @importFrom magclass as.magpie #' @importFrom quitte madrat_mule #' @importFrom readr read_csv #' @importFrom tidyr complete nesting @@ -65,7 +64,7 @@ readindustry_subsectors_specific <- function(subtype = NULL) { # subtype switchboard ---- switchboard <- list( 'FE' = function() { - read_csv(file = file.path(path, 'specific_FE.csv'), + read_csv(file = file.path(path, 'specific_FE.SSP3.csv'), col_types = 'cccd', comment = '#', progress = FALSE) %>% diff --git a/R/madrat.R b/R/madrat.R index 29c719f7..66c537ad 100644 --- a/R/madrat.R +++ b/R/madrat.R @@ -1,4 +1,3 @@ -#' @importFrom madrat vcat .onAttach <- function(libname, pkgname) { madrat::madratAttach(pkgname) diff --git a/R/mrremind-package.R b/R/mrremind-package.R index e173e726..d7d12e21 100644 --- a/R/mrremind-package.R +++ b/R/mrremind-package.R @@ -1,4 +1,6 @@ # The package documentation is defined in this file. # You can get it via `library(); ?`. +#' @importFrom magrittr %>% +#' @importFrom rlang .data sym syms !! !!! #' @docType package "_PACKAGE" diff --git a/R/readADVANCE_WP2.R b/R/readADVANCE_WP2.R index a7f51cf8..5f55aeb8 100644 --- a/R/readADVANCE_WP2.R +++ b/R/readADVANCE_WP2.R @@ -8,15 +8,13 @@ #' (2015) [zotero://select/items/JP8X2QFK](zotero://select/items/JP8X2QFK) #' #' @return A [`magpie`][magclass::magclass] object. -#' +#' #' @author Michaja Pehl -#' +#' #' @seealso [`readSource()`], [`convertADVANCE_WP2()`] -#' -#' @importFrom dplyr %>% -#' @importFrom magclass as.magpie +#' #' @importFrom readr read_csv -#' +#' #' @export readADVANCE_WP2 <- function(subtype) { # ---- list all available subtypes with functions doing all the work ---- @@ -24,14 +22,14 @@ readADVANCE_WP2 <- function(subtype) { 'clinker-to-cement-ratio' = function() { read_csv(file = './clinker-to-cement-ratio.csv', col_types = 'cd', - comment = '#') %>% + comment = '#') %>% as.magpie() } ) - + # ---- check if the subtype called is available ---- if (is_empty(intersect(subtype, names(switchboard)))) { - stop(paste('Invalid subtype -- supported subtypes are:', + stop(paste('Invalid subtype -- supported subtypes are:', paste(names(switchboard), collapse = ', '))) } else { # ---- load data and do whatever ---- diff --git a/R/readAGEB.R b/R/readAGEB.R index 0995abc3..16a06395 100644 --- a/R/readAGEB.R +++ b/R/readAGEB.R @@ -10,8 +10,6 @@ #' @importFrom tibble tibble #' @importFrom dplyr bind_rows select filter mutate #' @importFrom rlang sym -#' @importFrom reshape2 melt -#' @importFrom magclass as.magpie #' #' @export readAGEB <- function(subtype = "balances") { @@ -68,7 +66,7 @@ readAGEB <- function(subtype = "balances") { ) ) %>% filter(!is.na(!!sym("Einheit"))) %>% - mutate(!!sym("Energietraeger") := paste0(sheets[["name"]][[i]], "|", !!sym("Energietr\u00E4ger"))) %>% + mutate("Energietraeger" = paste0(sheets[["name"]][[i]], "|", !!sym("Energietr\u00E4ger"))) %>% select(-1) data <- bind_rows(data, tmp) @@ -89,13 +87,13 @@ readAGEB <- function(subtype = "balances") { col_types = c("text", rep("numeric", 32)), range = "B3:AH17", .name_repair = "minimal", na = c("k.A.") ) %>% - mutate(!!sym("TWh") := gsub(", darunter:", "", !!sym("TWh"))) %>% - mutate(!!sym("TWh") := gsub("- ", "", !!sym("TWh"))) %>% - mutate(!!sym("TWh") := gsub("[0-9])", "", !!sym("TWh"))) %>% - mutate(!!sym("variable") := paste0("9 Bruttostromerzeugung|", !!sym("TWh"))) %>% + mutate("TWh" = gsub(", darunter:", "", !!sym("TWh"))) %>% + mutate("TWh" = gsub("- ", "", !!sym("TWh"))) %>% + mutate("TWh" = gsub("[0-9])", "", !!sym("TWh"))) %>% + mutate("variable" = paste0("9 Bruttostromerzeugung|", !!sym("TWh"))) %>% select(-1) %>% reshape2::melt(id.vars = c("variable"), variable.name = "period", value.name = "value") %>% - mutate(!!sym("region") := "DEU", !!sym("unit") := "TWh") %>% + mutate("region" = "DEU", "unit" = "TWh") %>% select("region", "period", "variable", "unit", "value") %>% as.magpie() %>% return() diff --git a/R/readAR6GWP.R b/R/readAR6GWP.R index f6921d28..8595ab4f 100644 --- a/R/readAR6GWP.R +++ b/R/readAR6GWP.R @@ -1,22 +1,23 @@ #' Read GWP (or other metrics) from the AR6 WGIII Table SM7 per GHG species #' @md #' -#' @return A data.frame with two columns, "Gas", with the common name of the GHG species, and "GWP", with the selected GWP +#' @return A data.frame with two columns, "Gas", with the common name of the GHG +#' species, and "GWP", with the selected GWP #' #' @author Gabriel Abrahao #' -#' @param subtype data subtype. Currently just "GWP100", but other metrics are also available in the input data +#' @param subtype data subtype. Currently just "GWP100", but other metrics are +#' also available in the input data #' @importFrom readxl read_xlsx #' #' @export readAR6GWP <- function(subtype = "GWP100") { - if (subtype == "GWP100") { - # intable <- as.data.frame(read_excel("/p/projects/rd3mod/inputdata/sources/AR6/AR6_WGIII_TableSM7.xlsx", sheet = "table")) - intable <- as.data.frame(read_excel("AR6_WGIII_TableSM7.xlsx", sheet = "table")) + if (subtype == "GWP100") { + intable <- as.data.frame(read_excel("AR6_WGIII_TableSM7.xlsx", sheet = "table")) - x <- intable[,c("Name","GWP 100")] - colnames(x) <- c("Gas","GWP") - out <- list(class = "data.frame", x = x) - } - return(out) -} \ No newline at end of file + x <- intable[, c("Name", "GWP 100")] + colnames(x) <- c("Gas", "GWP") + out <- list(class = "data.frame", x = x) + } + return(out) +} diff --git a/R/readAriadneDB.R b/R/readAriadneDB.R index aa93aeab..2fb5e7dd 100644 --- a/R/readAriadneDB.R +++ b/R/readAriadneDB.R @@ -1,34 +1,30 @@ #' Ariadne database scenario data -#' @description Scenario data from the Ariadne modeling intercomparison project for Germany. See README in input file for more details. +#' @description Scenario data from the Ariadne modeling intercomparison project for Germany. +#' See README in input file for more details. #' #' @return A [`magpie`][magclass::magclass] object. #' @author Felix Schreyer #' @importFrom tidyr gather -#' @importFrom rlang sym -#' @importFrom dplyr filter %>% mutate +#' @importFrom dplyr filter mutate #' @importFrom readxl read_excel readAriadneDB <- function() { - - - - filename <- "IASA_DB_Complete_12_09_2022.xlsx" - # read in file - data <- read_excel(filename, - sheet = "data", - col_types = c(rep("text",6), - rep("numeric",19))) - + data <- read_excel( + "IIASA_DB_Complete_06_03_2024.xlsx", + sheet = "data", + col_types = c( + rep("text", 5), + rep("numeric", 19) + ) + ) # rearrange and convert to magclass object out <- data %>% - gather(!!sym("period"),!!sym("value"),-!!sym("model"),-!!sym("scenario"),-!!sym("region"),-!!sym("variable"), -!!sym("unit"), -!!sym("subannual")) %>% - filter( !is.na(!!sym("value"))) %>% - as.magpie(temporal = 7, spatial = 3, datacol = 8) - + gather("period", "value", -"model", -"scenario", -"region", -"variable", -"unit") %>% + filter(!is.na(.data$value)) %>% + as.magpie(temporal = 6, spatial = 3, datacol = 7) return(out) - } diff --git a/R/readBGR.R b/R/readBGR.R index 464345b9..87d7774a 100644 --- a/R/readBGR.R +++ b/R/readBGR.R @@ -1,34 +1,34 @@ #' Read BGR oil, gas, coal and uranium reserves data -#' +#' #' Read-in BGR csv files as magclass object -#' -#' +#' +#' #' @param subtype data subtype. Either "oil", "gas", "coal" or "uranium". -#' @return magpie object of the BGR (Federal Institute for Geosciences and Natural Resources) data of reserves of oil, gas, coal and uranium per country. +#' @return magpie object of the BGR (Federal Institute for Geosciences and +#' Natural Resources) data of reserves of oil, gas, coal and uranium per country. #' @author Renato Rodrigues #' @seealso \code{\link{readSource}} #' @examples -#' -#' \dontrun{ a <- readSource(type="BGR",subtype="oil") +#' \dontrun{ +#' a <- readSource(type = "BGR", subtype = "oil") #' } -#' - - readBGR <- function(subtype) { - if (subtype == "oil") { - #Reading oil resources per country values in 2009 [Mt] from csv - data <- read.csv("oil_reserves.csv",sep=";") - } else if (subtype== "gas") { - #Reading gas resources per country values in 2009 [Mrd. m³] from csv - data <- read.csv("gas_reserves.csv",sep=";") - } else if (subtype== "coal") { - #Reading coal resources per country values in 2009 [Mt] from csv - data <- read.csv("coal_reserves.csv",sep=";") - } else if (subtype== "uranium") { - #Reading uranium resources per country values in 2009 [kt U] from csv - data <- read.csv("uranium_reserves.csv",sep=";") - } else { - stop("Not a valid subtype!") - } - x <- as.magpie(data,temporal=0,spatial=1,datacol=2) - return(x) - } +#' +readBGR <- function(subtype) { + if (subtype == "oil") { + # Reading oil resources per country values in 2009 [Mt] from csv + data <- read.csv("oil_reserves.csv", sep = ";") + } else if (subtype == "gas") { + # Reading gas resources per country values in 2009 [Mrd. m³] from csv + data <- read.csv("gas_reserves.csv", sep = ";") + } else if (subtype == "coal") { + # Reading coal resources per country values in 2009 [Mt] from csv + data <- read.csv("coal_reserves.csv", sep = ";") + } else if (subtype == "uranium") { + # Reading uranium resources per country values in 2009 [kt U] from csv + data <- read.csv("uranium_reserves.csv", sep = ";") + } else { + stop("Not a valid subtype!") + } + x <- as.magpie(data, temporal = 0, spatial = 1, datacol = 2) + return(x) +} diff --git a/R/readBP.R b/R/readBP.R index c1305dfe..8d3e6bac 100644 --- a/R/readBP.R +++ b/R/readBP.R @@ -1,196 +1,200 @@ #' BP Capacity and Generation Data -#' @description BP data. See README in input file for more details. #' -#' @param subtype Either "Emission", Capacity", "Generation", "Production", "Consumption", "Trade Oil", "Trade Gas", "Trade Coal" or "Price" +#' @param subtype Either "Emission", Capacity", "Generation", "Production", +#' "Consumption", "Trade Oil", "Trade Gas", "Trade Coal" or "Price" #' @return A [`magpie`][magclass::magclass] object. #' @author Aman Malik, Falk Benke -#' @importFrom tidyr gather -#' @importFrom dplyr filter %>% mutate -#' @importFrom readxl read_excel -#' @importFrom reshape2 melt -#' @importFrom rlang sym - readBP <- function(subtype) { - rlang::check_installed("reshape") - value <- NULL - Country <- NULL - Year <- NULL - filename <- c("bp-stats-review-2021-all-data.xlsx") + filename <- file.path("2022", "EI-Stats-Review-All-Data.xlsx") - tidy_data <- function(df, variable, rows2remove = c("Total|OECD|European")) { - years <- as.character(c(1900:2020)) + tidyData <- function(df, variable, rows2remove = c("Total|OECD|European")) { colnames(df)[1] <- "Country" df$Country <- gsub("\\.", "", df$Country) df <- df %>% - gather(colnames(df[1, -1]), key = "Year", value = value) %>% - filter(!grepl(rows2remove, Country), !is.na(value), !value == "n/a", Year %in% years) %>% - mutate(Year = as.integer(Year), value = as.numeric(value)) %>% - mutate(Country = gsub(pattern = " and ", replacement = " & ", x = Country)) %>% - mutate(Country = gsub(pattern = "[0-9]", replacement = "", x = Country)) + tidyr::gather(colnames(df[1, -1]), key = "Year", value = "value") %>% + dplyr::mutate("Year" = as.integer(.data$Year), + "value" = suppressWarnings(as.numeric(.data$value))) %>% + dplyr::filter(!grepl(rows2remove, .data$Country), !is.na(.data$value), + .data$value != "n/a", .data$Year >= 1900) %>% + dplyr::mutate("Country" = gsub(pattern = " and ", replacement = " & ", x = .data$Country)) %>% + dplyr::mutate("Country" = gsub(pattern = "[0-9]", replacement = "", x = .data$Country)) colnames(df)[3] <- variable return(df) } - tidy_data_vertical <- function(df, rows2remove = c("Total|OECD|European")) { - years <- as.character(c(1900:2020)) + tidyDataVertical <- function(df, rows2remove = c("Total|OECD|European")) { df$Country <- gsub("\\.", "", df$Country) if (!is.null(rows2remove)) { - df <- filter(df, !grepl(rows2remove, Country)) + df <- dplyr::filter(df, !grepl(rows2remove, .data$Country)) } df <- df %>% - filter(Year %in% years) %>% - mutate(Year = as.integer(as.character(Year))) %>% - mutate(Country = gsub(pattern = " and ", replacement = " & ", x = Country)) %>% - mutate(Country = gsub(pattern = "[0-9]", replacement = "", x = Country)) + dplyr::mutate("Year" = suppressWarnings(as.integer(as.character(.data$Year)))) %>% + dplyr::filter(.data$Year > 1990) %>% + dplyr::mutate("Country" = gsub(pattern = " and ", replacement = " & ", x = .data$Country)) %>% + dplyr::mutate("Country" = gsub(pattern = "[0-9]", replacement = "", x = .data$Country)) return(df) } if (subtype == "Emission") { - data_emi <- read_excel(filename, sheet = "Carbon Dioxide Emissions", range = "A3:BE109") - data <- tidy_data(data_emi, "Emi|CO2 (Mt CO2)") - } - # Capacity Data for Wind, Solar, and Geobiomass - else if (subtype == "Capacity") { - data_solar <- read_excel(filename, sheet = "Solar Capacity", range = "A4:Z72") - data_solar <- tidy_data(data_solar, "Capacity|Solar (MW)") - data_wind <- read_excel(filename, sheet = "Wind Capacity", range = "A4:AA70") - data_wind <- tidy_data(data_wind, "Capacity|Wind (MW)") + dataEmi <- readxl::read_excel(filename, sheet = "Carbon Dioxide from Energy", range = "A3:BH109") + data <- tidyData(dataEmi, "Emi|CO2 (Mt CO2)") - data_geothermal <- read_excel(filename, sheet = "Geothermal Capacity", range = "A4:AA43") - data_geothermal <- tidy_data(data_geothermal, "Capacity|Geothermal (MW)") + } else if (subtype == "Capacity") { + # Capacity Data for Wind, Solar, and Geobiomass + dataSolar <- readxl::read_excel(filename, sheet = "Solar Installed Capacity", range = "A4:Y78") + dataSolar <- tidyData(dataSolar, "Capacity|Solar (MW)") - data <- reshape::merge_recurse(list(data_solar, data_wind, data_geothermal)) - } - # Generation data for Nuclear, Hydro, Solar, Wind, Geobiomass, Other Renewables - else if (subtype == "Generation") { - data_nuclear <- read_excel(filename, sheet = "Nuclear Generation - TWh", range = "A3:BE114") - data_nuclear <- tidy_data(data_nuclear, "Generation|Nuclear (TWh)") + dataWind <- readxl::read_excel(filename, sheet = "Wind Installed Capacity", range = "A4:AB70") + dataWind <- tidyData(dataWind, "Capacity|Wind (MW)") + + data <- list(dataSolar, dataWind) %>% + purrr::reduce(~ dplyr::full_join(.x, .y, by = c("Country", "Year"))) + + } else if (subtype == "Generation") { + # Generation data for Nuclear, Hydro, Solar, Wind, Geobiomass, Other Renewables + + dataNuclear <- readxl::read_excel(filename, sheet = "Nuclear Generation - TWh", range = "A3:BH114") + dataNuclear <- tidyData(dataNuclear, "Generation|Nuclear (TWh)") + + dataHydro <- readxl::read_excel(filename, sheet = "Hydro Generation - TWh", range = "A3:BH114") + dataHydro <- tidyData(dataHydro, "Generation|Hydro (TWh)") + + dataSolar <- readxl::read_excel(filename, sheet = "Solar Generation - TWh", range = "A3:BH114") + dataSolar <- tidyData(dataSolar, "Generation|Solar (TWh)") - data_hydro <- read_excel(filename, sheet = "Hydro Generation - TWh", range = "A3:BE114") - data_hydro <- tidy_data(data_hydro, "Generation|Hydro (TWh)") + dataWind <- readxl::read_excel(filename, sheet = "Wind Generation - TWh", range = "A3:BH114") + dataWind <- tidyData(dataWind, "Generation|Wind (TWh)") - data_solar <- read_excel(filename, sheet = "Solar Generation - TWh", range = "A3:BE114") - data_solar <- tidy_data(data_solar, "Generation|Solar (TWh)") + dataElec <- readxl::read_excel(filename, sheet = "Electricity Generation - TWh", range = "A3:AN113") + dataElec <- tidyData(dataElec, "Generation|Electricity (TWh)") - data_wind <- read_excel(filename, sheet = "Wind Generation - TWh", range = "A3:BE114") - data_wind <- tidy_data(data_wind, "Generation|Wind (TWh)") + dataElectRenewable <- readxl::read_excel(filename, sheet = "Renewable Power (inc hydro) -EJ", range = "A3:BH114") + dataElectRenewable <- tidyData(dataElectRenewable, "Generation|Electricity|Renewable (EJ)") - data_elec <- read_excel(filename, sheet = "Electricity Generation ", range = "A3:AK113") - data_elec <- tidy_data(data_elec, "Generation|Electricity (TWh)") + dataElecGas <- readxl::read_excel(filename, sheet = "Gas inputs - Elec generation", range = "A3:AN59") + dataElecGas <- tidyData(dataElecGas, "Generation|Electricity|Gas (TWh)") - data_elect_renewable <- read_excel(filename, sheet = "Renewables Power - EJ", range = "A3:BE114") - data_elect_renewable <- tidy_data(data_elect_renewable, "Generation|Electricity|Renewable (EJ)") + dataElecOil <- readxl::read_excel(filename, sheet = "Oil inputs - Elec generation ", range = "A3:AN59") + dataElecOil <- tidyData(dataElecOil, "Generation|Electricity|Oil (TWh)") - data_elec_gas <- read_excel(filename, sheet = "Elec Gen from Gas", range = "A3:AK58") - data_elec_gas <- tidy_data(data_elec_gas, "Generation|Electricity|Gas (TWh)") + dataElecCoal <- readxl::read_excel(filename, sheet = "Coal inputs - Elec generation ", range = "A3:AN59") + dataElecCoal <- tidyData(dataElecCoal, "Generation|Electricity|Coal (TWh)") - data_elec_oil <- read_excel(filename, sheet = "Elec Gen from Oil", range = "A3:AK58") - data_elec_oil <- tidy_data(data_elec_oil, "Generation|Electricity|Oil (TWh)") + dataGeoBiomass <- readxl::read_excel(filename, sheet = "Geo Biomass Other - TWh", range = "A3:BH114") + dataGeoBiomass <- tidyData(dataGeoBiomass, "Generation|Geo_biomass (TWh)") - data_elec_coal <- read_excel(filename, sheet = "Elec Gen from Coal", range = "A3:AK58") - data_elec_coal <- tidy_data(data_elec_coal, "Generation|Electricity|Coal (TWh)") + data <- list( + dataWind, dataSolar, dataHydro, dataGeoBiomass, dataNuclear, + dataElec, dataElectRenewable, dataElecGas, dataElecOil, dataElecCoal + ) %>% + purrr::reduce(~ dplyr::full_join(.x, .y, by = c("Country", "Year"))) - data_geo_biomass <- read_excel(filename, sheet = "Geo Biomass Other - TWh", range = "A3:BE114") - data_geo_biomass <- tidy_data(data_geo_biomass, "Generation|Geo_biomass (TWh)") + } else if (subtype == "Production") { - data <- reshape::merge_recurse(list( - data_wind, data_solar, data_hydro, data_geo_biomass, data_nuclear, - data_elec, data_elect_renewable, data_elec_gas, data_elec_oil, data_elec_coal - )) + # This part is currently not used in any other madrat function - data <- filter(data, !grepl("\\.", data$Year)) - } - else if (subtype == "Production") { - data_oil <- read_excel(filename, sheet = "Oil Production - Tonnes", range = "A3:BE73") - data_oil <- tidy_data(data_oil, "Oil Production (million t)") + dataOil <- readxl::read_excel(filename, sheet = "Oil Production - tonnes", range = "A3:BH76") + dataOil <- tidyData(dataOil, "Oil Production (million t)") - data_coal_ej <- read_excel(filename, sheet = "Coal Production - EJ", range = "A3:AO62") - data_coal_ej <- tidy_data(data_coal_ej, "Coal Production (EJ)") + dataCoalEj <- readxl::read_excel(filename, sheet = "Coal Production - EJ", range = "A3:AR62") + dataCoalEj <- tidyData(dataCoalEj, "Coal Production (EJ)") - data_coal_ton <- read_excel(filename, sheet = "Coal Production - Tonnes", range = "A3:AO62") - data_coal_ton <- tidy_data(data_coal_ton, "Coal Production (t)") + dataCoalTon <- readxl::read_excel(filename, sheet = "Coal Production - mt", range = "A3:AR62") + dataCoalTon <- tidyData(dataCoalTon, "Coal Production (million t)") - data_gas <- read_excel(filename, sheet = "Gas Production - EJ", range = "A3:AZ73") - data_gas <- tidy_data(data_gas, "Gas Production (EJ)") + dataGas <- readxl::read_excel(filename, sheet = "Gas Production - EJ", range = "A3:BC78") + dataGas <- tidyData(dataGas, "Gas Production (EJ)") # Includes crude oil, shale oil, oil sands, condensates (lease condensate or gas condensates that require - # further refining) and NGLs (natural gas liquids - ethane, LPG and naphtha separated from the production of natural gas). - data <- reshape::merge_recurse(list(data_oil, data_coal_ej, data_coal_ton, data_gas)) # merging all datasets into one - data <- filter(data, !grepl("\\.", data$Year)) - } - else if (subtype == "Consumption") { - data_pe_consumption <- read_excel(filename, sheet = "Primary Energy Consumption", range = "A3:BE114") - data_pe_consumption <- tidy_data(data_pe_consumption, "Primary Energy Consumption (EJ)") + # further refining) and NGLs (natural gas liquids - ethane, LPG and naphtha separated from the production of + # natural gas). + data <- list(dataOil, dataCoalEj, dataCoalTon, dataGas) %>% + purrr::reduce(~ dplyr::full_join(.x, .y, by = c("Country", "Year"))) - data_liq_consumption <- read_excel(filename, sheet = "Total Liquids - Consumption", range = "A3:BE114") - data_liq_consumption <- tidy_data(data_liq_consumption, "Liquids Consumption (kb/d)") + } else if (subtype == "Consumption") { - data_oil_consumption <- read_excel(filename, sheet = "Oil Consumption - EJ", range = "A3:BE114") - data_oil_consumption <- tidy_data(data_oil_consumption, "Oil Consumption (EJ)") + dataPeConsumption <- readxl::read_excel(filename, sheet = "Primary energy cons - EJ", range = "A3:BH114") + dataPeConsumption <- tidyData(dataPeConsumption, "Primary Energy Consumption (EJ)") - data_gas_consumption <- read_excel(filename, sheet = "Gas Consumption - EJ", range = "A3:BE114") - data_gas_consumption <- tidy_data(data_gas_consumption, "Gas Consumption (EJ)") + dataLiqConsumption <- readxl::read_excel(filename, sheet = "Liquids Consumption - barrels", range = "A3:BH114") + dataLiqConsumption <- tidyData(dataLiqConsumption, "Liquids Consumption (kb/d)") - data_coal_consumption <- read_excel(filename, sheet = "Coal Consumption - EJ", range = "A3:BE114") - data_coal_consumption <- tidy_data(data_coal_consumption, "Coal Consumption (EJ)") + dataOilConsumption <- readxl::read_excel(filename, sheet = "Oil Consumption - EJ", range = "A3:BH114") + dataOilConsumption <- tidyData(dataOilConsumption, "Oil Consumption (EJ)") - data_solar_consumption <- read_excel(filename, sheet = "Solar Consumption - EJ", range = "A3:BE114") - data_solar_consumption <- tidy_data(data_solar_consumption, "Solar Consumption (EJ)") + dataGasConsumption <- readxl::read_excel(filename, sheet = "Gas Consumption - EJ", range = "A3:BH114") + dataGasConsumption <- tidyData(dataGasConsumption, "Gas Consumption (EJ)") - data_wind_consumption <- read_excel(filename, sheet = "Wind Consumption - EJ", range = "A3:BE114") - data_wind_consumption <- tidy_data(data_wind_consumption, "Wind Consumption (EJ)") + dataCoalConsumption <- readxl::read_excel(filename, sheet = "Coal Consumption - EJ", range = "A3:BH114") + dataCoalConsumption <- tidyData(dataCoalConsumption, "Coal Consumption (EJ)") - data_nuclear_consumption <- read_excel(filename, sheet = "Nuclear Consumption - EJ", range = "A3:BE114") - data_nuclear_consumption <- tidy_data(data_nuclear_consumption, "Nuclear Consumption (EJ)") + dataSolarConsumption <- readxl::read_excel(filename, sheet = "Solar Consumption - EJ", range = "A3:BH114") + dataSolarConsumption <- tidyData(dataSolarConsumption, "Solar Consumption (EJ)") - data_hydro_consumption <- read_excel(filename, sheet = "Hydro Consumption - EJ", range = "A3:BE114") - data_hydro_consumption <- tidy_data(data_hydro_consumption, "Hydro Consumption (EJ)") + dataWindConsumption <- readxl::read_excel(filename, sheet = "Wind Consumption - EJ", range = "A3:BH114") + dataWindConsumption <- tidyData(dataWindConsumption, "Wind Consumption (EJ)") - data <- reshape::merge_recurse(list( - data_pe_consumption, data_liq_consumption, data_oil_consumption, data_gas_consumption, - data_coal_consumption, data_solar_consumption, data_wind_consumption, data_nuclear_consumption, - data_hydro_consumption - )) - } - else if (subtype == "Trade Oil") { + dataNuclearConsumption <- readxl::read_excel(filename, sheet = "Nuclear Consumption - EJ", range = "A3:BH114") + dataNuclearConsumption <- tidyData(dataNuclearConsumption, "Nuclear Consumption (EJ)") + + dataHydroConsumption <- readxl::read_excel(filename, sheet = "Hydro Consumption - EJ", range = "A3:BH114") + dataHydroConsumption <- tidyData(dataHydroConsumption, "Hydro Consumption (EJ)") + + data <- list( + dataPeConsumption, dataLiqConsumption, dataOilConsumption, dataGasConsumption, + dataCoalConsumption, dataSolarConsumption, dataWindConsumption, dataNuclearConsumption, + dataHydroConsumption + ) %>% + purrr::reduce(~ dplyr::full_join(.x, .y, by = c("Country", "Year"))) + + } else if (subtype == "Trade Oil") { - data_oil_trade <- read_excel(filename, sheet = "Oil - Trade movements", range = "A3:AP27") - data_oil_trade_import <- tidy_data(data_oil_trade[seq(1, 8), ], "Trade|Import|Oil (kb/d)") - data_oil_trade_export <- tidy_data(data_oil_trade[seq(9, 24), ], "Trade|Export|Oil (kb/d)") + dataOilTrade <- readxl::read_excel(filename, sheet = "Oil trade movements", range = "A3:AS27") - data_oil_trade_detail <- read_excel(filename, sheet = "Oil - Trade 2019 - 2020", range = "A28:I50") - colnames(data_oil_trade_detail) <- c("Country", rep(c( + dataOilTradeImport <- tidyData(dataOilTrade[seq(1, 8), ], "Trade|Import|Oil (kb/d)") + dataOilTradeExport <- tidyData(dataOilTrade[seq(9, 24), ], "Trade|Export|Oil (kb/d)") + + dataOilTradeDetail <- readxl::read_excel(filename, sheet = "Oil - Trade movements in 22-23", + range = "A28:I50", .name_repair = "unique_quiet") + + colnames(dataOilTradeDetail) <- c("Country", rep(c( "Trade|Import|Oil|Crude (kb/d)", "Trade|Import|Oil|Product (kb/d)", "Trade|Export|Oil|Crude (kb/d)", "Trade|Export|Oil|Product (kb/d)" ), times = 2)) - data_oil_trade_detail <- rbind(data_oil_trade_detail[, seq(1, 5)] %>% - mutate(Year := 2019), data_oil_trade_detail[, c(1, seq(6, 9))] %>% - mutate(Year := 2020)) %>% - tidy_data_vertical() - data <- reshape::merge_recurse(list(data_oil_trade_import, data_oil_trade_export, data_oil_trade_detail)) + dataOilTradeDetail <- rbind( + dataOilTradeDetail[, seq(1, 5)] %>% dplyr::mutate("Year" = 2022), + dataOilTradeDetail[, c(1, seq(6, 9))] %>% dplyr::mutate("Year" = 2023) + ) %>% + tidyDataVertical() - } - else if (subtype == "Trade Coal") { + data <- list(dataOilTradeImport, dataOilTradeExport, dataOilTradeDetail) %>% + purrr::reduce(~ dplyr::full_join(.x, .y, by = c("Country", "Year"))) - data_coal_trade <- read_excel(filename, sheet = "Coal - Trade movements", range = "A3:V34") - data_coal_trade_import <- tidy_data(data_coal_trade[seq(1, 15), ], "Trade|Import|Coal (EJ)", - rows2remove = c("Total|OECD|European|Rest")) - data_coal_trade_export <- tidy_data(data_coal_trade[seq(17, 31), ], "Trade|Export|Coal (EJ)", - rows2remove = c("Total|OECD|European|Rest")) + } else if (subtype == "Trade Coal") { - data <- reshape::merge_recurse(list(data_coal_trade_import, data_coal_trade_export)) + dataCoalTrade <- readxl::read_excel(filename, sheet = "Coal - Trade movements", range = "A3:Y34") - } - else if (subtype == "Trade Gas") { + dataCoalTradeImport <- tidyData(dataCoalTrade[seq(1, 15), ], "Trade|Import|Coal (EJ)", + rows2remove = c("Total|OECD|European|Rest") + ) + + dataCoalTradeExport <- tidyData(dataCoalTrade[seq(17, 31), ], "Trade|Export|Coal (EJ)", + rows2remove = c("Total|OECD|European|Rest") + ) + + data <- list(dataCoalTradeImport, dataCoalTradeExport) %>% + purrr::reduce(~ dplyr::full_join(.x, .y, by = c("Country", "Year"))) - data_gas_trade <- read_excel(filename, sheet = "Gas - Inter-regional trade", range = "A3:V105") - colnames(data_gas_trade)[1] <- "Variable" - variable_mapping <- { + } else if (subtype == "Trade Gas") { + + dataGasTrade <- readxl::read_excel(filename, sheet = "Gas - Trade movements", range = "A3:Y106") + colnames(dataGasTrade)[1] <- "Variable" + variableMapping <- { c( NA, NA, @@ -268,6 +272,7 @@ readBP <- function(subtype) { NA, NA, NA, + NA, "China|Trade|Import|Gas (bcm)", NA, "China|Trade|Export|Gas (bcm)", @@ -296,39 +301,42 @@ readBP <- function(subtype) { NA ) } - data_gas_trade$Variable <- variable_mapping - data_gas_trade <- filter(data_gas_trade, !is.na(!!sym("Variable"))) %>% - mutate( - !!sym("Country") := sub("\\|.*", "", !!sym("Variable")), - !!sym("Variable") := sub(".*\\|Trade", "\\Trade", !!sym("Variable")), + dataGasTrade$Variable <- variableMapping + dataGasTrade <- dplyr::filter(dataGasTrade, !is.na(.data$Variable)) %>% + dplyr::mutate( + Country = sub("\\|.*", "", .data$Variable), + Variable = sub(".*\\|Trade", "\\Trade", .data$Variable) ) %>% - reshape2::melt(id.vars = c("Variable", "Country")) %>% - reshape2::dcast(Country + variable ~ Variable, value.var = "value") - colnames(data_gas_trade)[2] <- "Year" - data <- tidy_data_vertical(data_gas_trade, rows2remove = NULL) + reshape2::melt(id.vars = c("Variable", "Country"), variable.name = "Year") %>% + reshape2::dcast(Country + Year ~ Variable, value.var = "value") - } - else if (subtype == "Price") { - - data_oil_spot_crude_price <- read_excel(filename, sheet = "Oil - Spot crude prices", range = "A4:E54") - colnames(data_oil_spot_crude_price) <- c( + data <- tidyDataVertical(dataGasTrade, rows2remove = NULL) + + } else if (subtype == "Price") { + + dataOilSpotCrudePrice <- readxl::read_excel(filename, sheet = "Spot crude prices", range = "A4:E56") + + colnames(dataOilSpotCrudePrice) <- c( "Year", "Price|Oil|Dubai ($/bbl)", "Price|Oil|Brent ($/bbl)", "Price|Oil|Nigerian Forcados ($/bbl)", "Price|Oil|Western Texas Intermediate ($/bbl)" ) - data_oil_spot_crude_price <- filter(data_oil_spot_crude_price, !is.na(Year)) - data_oil_crude_price <- read_excel(filename, sheet = "Oil - Crude prices since 1861", range = "A4:C164") - colnames(data_oil_crude_price) <- c( + dataOilSpotCrudePrice <- dplyr::filter(dataOilSpotCrudePrice, !is.na(.data$Year)) + + dataOilCrudePrice <- readxl::read_excel(filename, sheet = "Oil crude prices since 1861", range = "A4:C167") + + colnames(dataOilCrudePrice) <- c( "Year", "Price|Crude Oil ($money of the day/bbl)", - "Price|Crude Oil ($2020/bbl)" + "Price|Crude Oil ($2023/bbl)" ) - data_gas_price <- read_excel(filename, sheet = "Gas - Prices ", range = "A5:H42") - colnames(data_gas_price) <- c( + dataGasPrice <- readxl::read_excel(filename, sheet = "Gas Prices ", range = "A5:H45", + .name_repair = "unique_quiet") + colnames(dataGasPrice) <- c( "Year", "Price|LNG|Japan|CIF ($/mbtu)", "Price|LNG|Japan|Korea Marker ($/mbtu)", @@ -339,24 +347,31 @@ readBP <- function(subtype) { "Price|Natural Gas|Alberta ($/mbtu)" ) - data_coal_price <- read_excel(filename, sheet = "Coal - Prices", range = "A2:H37") - colnames(data_coal_price) <- c( + dataCoalPrice <- readxl::read_excel(filename, sheet = "Coal & Uranium - Prices", range = "A4:I41", + .name_repair = "unique_quiet") + + colnames(dataCoalPrice) <- c( "Year", - "Price|Coal|Northwest Europe marker price ($/t)", - "Price|Coal|US Central Appalachian coal spot price index ($/t)", - "Price|Coal|Japan steam spot CIF price ($/t)", - "Price|Coal|China Qinhuangdao spot price ($/t)", - "Price|Coal|Japan coking coal import CIF price (t/$)", - "Price|Coal|Japan steam coal import CIF price (t/$)", - "Price|Coal|Asian marker price (t/$)" + "Price|Coal|United States ($/t)", + "Price|Coal|Colombia ($/t)", + "Price|Coal|Northwest Europe ($/t)", + "Price|Coal|South Africa ($/t)", + "Price|Coal|Indonesia ($/t)", + "Price|Coal|South China ($/t)", + "Price|Coal|Japan ($/t)", + "Price|Coal|Australia ($/t)" ) - data_coal_price <- filter(data_coal_price, !is.na(Year)) - data <- reshape::merge_recurse(list(data_oil_spot_crude_price, data_oil_crude_price, data_gas_price, data_coal_price)) - data[-1] <- lapply(data[-1], as.numeric) + dataCoalPrice <- dplyr::filter(dataCoalPrice, !is.na(.data$Year)) + + data <- list(dataOilSpotCrudePrice, dataOilCrudePrice, dataGasPrice, dataCoalPrice) %>% + purrr::reduce(~ dplyr::full_join(.x, .y, by = "Year")) + + data[-1] <- lapply(data[-1], function(x) { + suppressWarnings(as.numeric(x)) + }) data <- cbind(Country = "GLO", data) - } - else { + } else { stop("Not a valid subtype!") } diff --git a/R/readCCS_StoragePotential.R b/R/readCCS_StoragePotential.R index 649a56b4..72602ff5 100644 --- a/R/readCCS_StoragePotential.R +++ b/R/readCCS_StoragePotential.R @@ -1,10 +1,8 @@ -#' @importFrom magclass as.magpie #' @importFrom readxl read_excel -#' - -readCCS_StoragePotential<- function() { - data <- read_excel(path='EU_CCS_storage_capacity.xlsx') - data <- data[,c("CountryCode", "CCS_capacity")] - x <- as.magpie(data,spatial=1,datacol=2) +#' +readCCS_StoragePotential <- function() { + data <- read_excel(path = "EU_CCS_storage_capacity.xlsx") + data <- data[, c("CountryCode", "CCS_capacity")] + x <- as.magpie(data, spatial = 1, datacol = 2) return(x) } diff --git a/R/readCDIAC.R b/R/readCDIAC.R index 886326f5..059972b0 100644 --- a/R/readCDIAC.R +++ b/R/readCDIAC.R @@ -1,10 +1,10 @@ -readCDIAC<- function() { - - emi <- read.csv("nation.1751_2013.csv",stringsAsFactors = TRUE) +readCDIAC <- function() { + + emi <- read.csv("nation.1751_2013.csv", stringsAsFactors = TRUE) # replace dots with spaces, remove double spaces - names(emi) <- gsub(" "," ",gsub("\\."," ",names(emi))) - - map <- c("Total CO2 emissions from fossil fuels and cement production thousand metric tons of C "= "FFIC", + names(emi) <- gsub(" ", " ", gsub("\\.", " ", names(emi))) + + map <- c("Total CO2 emissions from fossil fuels and cement production thousand metric tons of C " = "FFIC", "Emissions from solid fuel consumption" = "Solids", "Emissions from liquid fuel consumption" = "Liquids", "Emissions from gas fuel consumption" = "Gases", @@ -12,25 +12,25 @@ readCDIAC<- function() { "Emissions from gas flaring" = "Flaring", "Per capita CO2 emissions metric tons of carbon " = "PerCap", "Emissions from bunker fuels not included in the totals " = "Bunker") - + # rename columns according to mapping defined above for (i in 1:length(map)) { - names(emi) <- gsub(names(map)[i],map[i],names(emi)) + names(emi) <- gsub(names(map)[i], map[i], names(emi)) } - + # remove rows 1-4 containing comments - emi <- emi[-(1:4),] - + emi <- emi[-(1:4), ] + # replace "." with NA - emi[emi=="."]<-NA + emi[emi == "."] <- NA - # change classes of data columns from Factor or int to numeric + # change classes of data columns from Factor or int to numeric cols <- 3:10 - emi[,cols] <- apply(emi[,cols], 2, function(x) as.numeric(as.character(x))) - - emi$Nation <- gsub("\\.","",emi$Nation) - - x <- as.magpie(emi,spatial=1,datacol=3) + emi[, cols] <- apply(emi[, cols], 2, function(x) as.numeric(as.character(x))) + + emi$Nation <- gsub("\\.", "", emi$Nation) + + x <- as.magpie(emi, spatial = 1, datacol = 3) return(x) } diff --git a/R/readCEEW.R b/R/readCEEW.R index e68bd13d..882b053c 100644 --- a/R/readCEEW.R +++ b/R/readCEEW.R @@ -3,59 +3,48 @@ #' @author Aman Malik #' @importFrom readxl read_excel #' @param subtype data subtype. Either "Employment factors" or "Employment" -#' @examples -#' \dontrun{ +#' @examples +#' \dontrun{ #' a <- readSource("CEEW",convert=F,subtype="Employment") #' } -readCEEW <- function(subtype){ - if (subtype=="Employment factors") - { - # Using following convention for tech names - # techs <- c("Solar|CSP","Wind","Hydro","Biomass","Coal","Gas","Nuclear","Oil") - # Using following convention for activity names - # c("Manf","CI","OM") - - input <- readxl::read_excel("Employment_CEEW.xlsx",sheet = 1) - tech <- input$Tech - input$Tech <- gsub(x = input$Tech,pattern = "Solar \\(ground mounted\\)",replacement = "Solar|PV-utility") - input$Tech <- gsub(x = input$Tech,pattern = "Solar \\(rooftop\\)",replacement = "Solar|PV-rooftop") - input$Tech <- gsub(x = input$Tech,pattern = "Large Hydro",replacement = "Hydro-large") - input$Tech <- gsub(x = input$Tech,pattern = "Small Hydro",replacement = "Hydro-small") - input$Tech <- gsub(x = input$Tech,pattern = "Wind",replacement = "Wind onshore") - +readCEEW <- function(subtype) { + if (subtype == "Employment factors") { + + input <- readxl::read_excel("Employment_CEEW.xlsx", sheet = 1) + input$Tech <- gsub(x = input$Tech, pattern = "Solar \\(ground mounted\\)", replacement = "Solar|PV-utility") + input$Tech <- gsub(x = input$Tech, pattern = "Solar \\(rooftop\\)", replacement = "Solar|PV-rooftop") + input$Tech <- gsub(x = input$Tech, pattern = "Large Hydro", replacement = "Hydro-large") + input$Tech <- gsub(x = input$Tech, pattern = "Small Hydro", replacement = "Hydro-small") + input$Tech <- gsub(x = input$Tech, pattern = "Wind", replacement = "Wind onshore") + colnames(input)[2] <- "CI" colnames(input)[3] <- "OM" - - input$CI <- input$CI*input$`Construction Period` - input <- input[,c(1:3)] + + input$CI <- input$CI * input$`Construction Period` + input <- input[, c(1:3)] x <- as.magpie(input) - #getRegions(x) <- "IND" - - return (x) - + + return(x) } - - if(subtype=="Employment") - { - input <- readxl::read_excel("Employment_CEEW.xlsx",sheet = 3) + + if (subtype == "Employment") { + input <- readxl::read_excel("Employment_CEEW.xlsx", sheet = 3) # Assuming FY2016 to be year 2015 and FY2019 to be year 2018 - input$Year <- gsub(x = input$Year,pattern = "FY16",replacement = "2015") - input$Year <- gsub(x = input$Year,pattern = "FY17",replacement = "2016") - input$Year <- gsub(x = input$Year,pattern = "FY18",replacement = "2017") - input$Year <- gsub(x = input$Year,pattern = "FY19",replacement = "2018") + input$Year <- gsub(x = input$Year, pattern = "FY16", replacement = "2015") + input$Year <- gsub(x = input$Year, pattern = "FY17", replacement = "2016") + input$Year <- gsub(x = input$Year, pattern = "FY18", replacement = "2017") + input$Year <- gsub(x = input$Year, pattern = "FY19", replacement = "2018") # naming convention according to Rutovitz et al. 2015 - input$Tech <- gsub(x = input$Tech,pattern = "Utility-scale Solar",replacement = "Solar|PV-utility") - input$Tech <- gsub(x = input$Tech,pattern = "Rooftop Solar",replacement = "Solar|PV-rooftop") - input$Tech <- gsub(x = input$Tech,pattern = "Large Hydro",replacement = "Hydro-large") - input$Tech <- gsub(x = input$Tech,pattern = "Small Hydro",replacement = "Hydro-small") - input$Tech <- gsub(x = input$Tech,pattern = "Wind",replacement = "Wind onshore") - - x <- as.magpie(input,spatial=NULL) - # getRegions(x) <- "IND" - - return (x) - + input$Tech <- gsub(x = input$Tech, pattern = "Utility-scale Solar", replacement = "Solar|PV-utility") + input$Tech <- gsub(x = input$Tech, pattern = "Rooftop Solar", replacement = "Solar|PV-rooftop") + input$Tech <- gsub(x = input$Tech, pattern = "Large Hydro", replacement = "Hydro-large") + input$Tech <- gsub(x = input$Tech, pattern = "Small Hydro", replacement = "Hydro-small") + input$Tech <- gsub(x = input$Tech, pattern = "Wind", replacement = "Wind onshore") + + x <- as.magpie(input, spatial = NULL) + + return(x) } } diff --git a/R/readConferenceBoard.R b/R/readConferenceBoard.R deleted file mode 100644 index e6240d49..00000000 --- a/R/readConferenceBoard.R +++ /dev/null @@ -1,62 +0,0 @@ -#' readConferenceBoard -#' @description Employment and GDP-related data from Conference Board https://www.conference-board.org/data/economydatabase/total-economy-database-productivity -#' @author Aman Malik -#' @importFrom readxl read_excel -#' @return A magpie object - -readConferenceBoard <- function(){ - # Data on labour productivity - input <- readxl::read_excel(path = "TED_1_JULY20201.xlsx",sheet = "TCB_ORIGINAL",skip = 4 ) - input <- input[,c(2,4:75)] - input <- as.magpie(input,spatial=1) - getRegions(input) <- gsub(pattern = "SCG","SRB",getRegions(input)) - getRegions(input) <- gsub(pattern = "CHN2","CHN",getRegions(input))# CHN1 is the China alternative and CHN2 is the China official numbers. - #The former is based on alternative growth estimates, while the latter is based on official data - - input <- collapseNames(input,collapsedim = 2) - - - # Data on agri as percent of GDP - agri_percent_gdp <- read_excel(path = "agri_percent_gdp.xls",sheet = "Data",skip=3) - agri_percent_gdp <- agri_percent_gdp[,-c(1,4)] - agri_percent_gdp <- as.magpie(agri_percent_gdp,spatial=1,data=3) - agri_percent_gdp <- collapseNames(agri_percent_gdp,collapsedim = 2) - - # Data on agri employment as percent of total employment - agri_percent_emp <- read_excel(path = "agri_percent_employment.xls",skip = 4) - agri_percent_emp <- agri_percent_emp[,-c(1,4, seq(4,35,1))] - agri_percent_emp <- as.magpie(agri_percent_emp,spatial=1) - #agri_percent_emp <- collapseNames(agri_percent_emp,preservedim = 1) - - # common years and regions so that it can be merged later - com_regions <- intersect(getRegions(input),getRegions(agri_percent_gdp)) - com_years <- intersect(getYears(input),getYears(agri_percent_emp)) - input <- input[com_regions,com_years,] - agri_percent_gdp <- agri_percent_gdp[com_regions,com_years,] - agri_percent_emp <- agri_percent_emp[com_regions,com_years] - - x <- mbind(agri_percent_emp,agri_percent_gdp,input) - x <- add_columns(x,addnm = "Employment in agriculture",dim = 3.1) - x <- add_columns(x,addnm = "Agriculture GDP",dim = 3.1) - x <- add_columns(x,addnm = "Output per person (agriculture)",dim = 3.1) - x <- add_columns(x,addnm = "Output per person (without agriculture)",dim=3.1) - x[,,"Employment in agriculture"] <- x[,,"Employment"]*(x[,,"Employment in agriculture (% of total employment) (modeled ILO estimate)"]/100) - x[,,"Agriculture GDP"] <- x[,,"GDP EKS"]*(x[,,"Agriculture, forestry, and fishing, value added (% of GDP)"]/100) - x[,,"Output per person (agriculture)"] <- (x[,,"Agriculture GDP"]*1000)/x[,,"Employment in agriculture"] - x[,,"Output per person (without agriculture)"] <- (x[,,"GDP EKS"]-x[,,"Agriculture GDP"])*1000/(x[,,"Employment"]-x[,,"Employment in agriculture"]) - - x <- x[,2015:2019,c("Output per person (without agriculture)","Output per Employed Person","Employment in agriculture")] - x <- magpiesort(x) - x <- x[c("SYR","VEN","LBY"),,invert=T] - - # for all NA values, use last available value -for (i in getRegions(x)){ - for (j in getYears(x,as.integer = T)){ - for (k in getNames(x)) - if(is.na(x[i,j,k])) - {x[i,j,k] <- x[i,j-1,k]} - } -} - - return (x) -} diff --git a/R/readDLR.R b/R/readDLR.R index a7925ea4..4bb290b0 100644 --- a/R/readDLR.R +++ b/R/readDLR.R @@ -1,294 +1,294 @@ -#' @importFrom reshape2 melt #' @importFrom utils read.table readDLR <- function() { - countries <- c( - 'Afghanistan', - 'Algeria', - 'Azerbaijan', - 'Albania', - 'Armenia', - 'Andorra', - 'Angola', - 'American Samoa', - 'Argentina', - 'Australia', - 'Austria', - 'Anguilla', - 'Bahrain', - 'Barbados', - 'Botswana', - 'Bermuda', - 'Belgium', - 'Bahamas', - 'Bangladesh', - 'Belize', - 'Bosnia and Herzegovina', - 'Bolivia', - 'Myanmar', - 'Benin', - 'Belarus', - 'Solomon Islands', - 'Brazil', - 'Bhutan', - 'Bulgaria', - 'Bouvet Island', - 'Brunei', - 'Burundi', - 'Canada', - 'Cambodia', - 'Chad', - 'Sri Lanka', - 'Congo', - 'Congo, the Democratic Republic of the', - 'China', - 'China-Disputed', - 'Hong Kong', - 'Macau', - 'Chile', - 'Cameroon', - 'Comoros', - 'Colombia', - 'Costa Rica', - 'Central African Republic', - 'Cuba', - 'Cape Verde', - 'Cyprus', - 'Czech Republic', - 'Denmark', - 'Djibouti', - 'Dominica', - 'Dominican Republic', - 'Ecuador', - 'Egypt', - 'Ireland', - 'Equatorial Guinea', - 'Estonia', - 'Eritrea', - 'El Salvador', - 'Ethiopia', - 'French Guiana', - 'Finland', - 'Fiji', - 'Faroe Islands', - 'French Polynesia', - 'France', - 'Gambia', - 'Gabon', - 'Georgia', - 'Ghana', - 'Gibraltar', - 'Grenada', - 'Guernsey', - 'Germany', - 'Guadeloupe', - 'Greece', - 'Guatemala', - 'Guinea', - 'Guyana', - 'Haiti', - 'Honduras', - 'Croatia', - 'Hungary', - 'Iceland', - 'Indonesia', - 'Isle of Man', - 'India', - 'Iran', - 'Israel', - 'Israel-Disputed (Golan Heights)', - 'West_Bank', - 'Israel-Disputed (Gaza Strip)', - 'Italy', - 'Cote d Ivoire', - 'Iraq', - 'Japan', - 'Jersey', - 'Jamaica', - 'Jordan', - 'Kenya', - 'Kyrgyzstan', - 'North Korea', - 'Kiribati', - 'South Korea', - 'Kuwait', - 'Kazakhstan', - 'Laos', - 'Lebanon', - 'Latvia', - 'Lithuania', - 'Liberia', - 'Slovakia', - 'Liechtenstein', - 'Lesotho', - 'Luxembourg', - 'Libya', - 'Madagascar', - 'Martinique', - 'Moldova', - 'Mongolia', - 'Montserrat', - 'Malawi', - 'FYR of Macedonia', - 'Mali', - 'Monaco', - 'Morocco', - 'Mauritius', - 'Mauritania', - 'Malta', - 'Oman', - 'Maldives', - 'Montenegro', - 'Mexico', - 'Malaysia', - 'Mozambique', - 'New Caledonia', - 'Niger', - 'Vanuatu', - 'Nigeria', - 'Netherlands', - 'Norway', - 'Nepal', - 'Suriname', - 'Netherlands Antilles', - 'Nicaragua', - 'New Zealand', - 'Paraguay', - 'Peru', - 'Pakistan', - 'Poland', - 'Panama', - 'Portugal', - 'Papua New Guinea', - 'Guinea-Bissau', - 'Qatar', - 'Reunion', - 'Romania', - 'Philippines', - 'Puerto Rico', - 'Russia', - 'Rwanda', - 'Saudi Arabia', - 'Saint Kitts and Nevis', - 'Seychelles', - 'South Africa', - 'Senegal', - 'Slovenia', - 'Sierra Leone', - 'San Marino', - 'Singapore', - 'Somalia', - 'Spain', - 'Serbia', - 'Saint Lucia', - 'Sudan', - 'Sweden', - 'Syria', - 'Switzerland', - 'United Arab Emirates', - 'Trinidad and Tobago', - 'Thailand', - 'Tajikistan', - 'Turks and Caicos Islands', - 'Togo', - 'Sao Tome and Principe', - 'Tunisia', - 'Turkey', - 'Taiwan', - 'Turkmenistan', - 'Tanzania', - 'Uganda', - 'United Kingdom', - 'Ukraine', - 'United States', - 'Burkina Faso', - 'Uruguay', - 'Uzbekistan', - 'Saint Vincent and the Grenadines', - 'Venezuela', - 'Virgin Islands, British', - 'Vietnam', - 'Virgin Islands, U.S.', - 'Namibia', - 'Western Sahara', - 'Swaziland', - 'Yemen', - 'Zambia', - 'Zimbabwe') - + "Afghanistan", + "Algeria", + "Azerbaijan", + "Albania", + "Armenia", + "Andorra", + "Angola", + "American Samoa", + "Argentina", + "Australia", + "Austria", + "Anguilla", + "Bahrain", + "Barbados", + "Botswana", + "Bermuda", + "Belgium", + "Bahamas", + "Bangladesh", + "Belize", + "Bosnia and Herzegovina", + "Bolivia", + "Myanmar", + "Benin", + "Belarus", + "Solomon Islands", + "Brazil", + "Bhutan", + "Bulgaria", + "Bouvet Island", + "Brunei", + "Burundi", + "Canada", + "Cambodia", + "Chad", + "Sri Lanka", + "Congo", + "Congo, the Democratic Republic of the", + "China", + "China-Disputed", + "Hong Kong", + "Macau", + "Chile", + "Cameroon", + "Comoros", + "Colombia", + "Costa Rica", + "Central African Republic", + "Cuba", + "Cape Verde", + "Cyprus", + "Czech Republic", + "Denmark", + "Djibouti", + "Dominica", + "Dominican Republic", + "Ecuador", + "Egypt", + "Ireland", + "Equatorial Guinea", + "Estonia", + "Eritrea", + "El Salvador", + "Ethiopia", + "French Guiana", + "Finland", + "Fiji", + "Faroe Islands", + "French Polynesia", + "France", + "Gambia", + "Gabon", + "Georgia", + "Ghana", + "Gibraltar", + "Grenada", + "Guernsey", + "Germany", + "Guadeloupe", + "Greece", + "Guatemala", + "Guinea", + "Guyana", + "Haiti", + "Honduras", + "Croatia", + "Hungary", + "Iceland", + "Indonesia", + "Isle of Man", + "India", + "Iran", + "Israel", + "Israel-Disputed (Golan Heights)", + "West_Bank", + "Israel-Disputed (Gaza Strip)", + "Italy", + "Cote d Ivoire", + "Iraq", + "Japan", + "Jersey", + "Jamaica", + "Jordan", + "Kenya", + "Kyrgyzstan", + "North Korea", + "Kiribati", + "South Korea", + "Kuwait", + "Kazakhstan", + "Laos", + "Lebanon", + "Latvia", + "Lithuania", + "Liberia", + "Slovakia", + "Liechtenstein", + "Lesotho", + "Luxembourg", + "Libya", + "Madagascar", + "Martinique", + "Moldova", + "Mongolia", + "Montserrat", + "Malawi", + "FYR of Macedonia", + "Mali", + "Monaco", + "Morocco", + "Mauritius", + "Mauritania", + "Malta", + "Oman", + "Maldives", + "Montenegro", + "Mexico", + "Malaysia", + "Mozambique", + "New Caledonia", + "Niger", + "Vanuatu", + "Nigeria", + "Netherlands", + "Norway", + "Nepal", + "Suriname", + "Netherlands Antilles", + "Nicaragua", + "New Zealand", + "Paraguay", + "Peru", + "Pakistan", + "Poland", + "Panama", + "Portugal", + "Papua New Guinea", + "Guinea-Bissau", + "Qatar", + "Reunion", + "Romania", + "Philippines", + "Puerto Rico", + "Russia", + "Rwanda", + "Saudi Arabia", + "Saint Kitts and Nevis", + "Seychelles", + "South Africa", + "Senegal", + "Slovenia", + "Sierra Leone", + "San Marino", + "Singapore", + "Somalia", + "Spain", + "Serbia", + "Saint Lucia", + "Sudan", + "Sweden", + "Syria", + "Switzerland", + "United Arab Emirates", + "Trinidad and Tobago", + "Thailand", + "Tajikistan", + "Turks and Caicos Islands", + "Togo", + "Sao Tome and Principe", + "Tunisia", + "Turkey", + "Taiwan", + "Turkmenistan", + "Tanzania", + "Uganda", + "United Kingdom", + "Ukraine", + "United States", + "Burkina Faso", + "Uruguay", + "Uzbekistan", + "Saint Vincent and the Grenadines", + "Venezuela", + "Virgin Islands, British", + "Vietnam", + "Virgin Islands, U.S.", + "Namibia", + "Western Sahara", + "Swaziland", + "Yemen", + "Zambia", + "Zimbabwe" + ) + iso.countries <- suppressWarnings(toolCountry2isocode(countries)) ### year year <- "y2010" - + ### quality bin bins <- read.table("FLh_bins_TriebFormula_2013_11_26.txt", col.names = c("PV", "CSP")) - + ### define which columns to read, psv: odd columns, csp: even columns (exclude first two and last two) colClasses.df <- data.frame(PV = character(428), CSP = character(428)) colClasses.df$PV <- c(rep("NULL", 2), rep(c(NA, "NULL"), length(countries)), rep("NULL", 2)) colClasses.df$CSP <- c(rep("NULL", 2), rep(c("NULL", NA), length(countries)), rep("NULL", 2)) - + ### csv files - csv.files <- list.files(pattern=".csv$") - + csv.files <- list.files(pattern = ".csv$") + ### read csv function read.csv.Solar <- function(x) { - - technology <- ifelse(grepl(x=x, pattern="PV"), "PV", - ifelse(grepl(x=x, pattern="CSP"), "CSP", NA)) - - distance <- ifelse(grepl(x=x, pattern="1-50"), "0-50", - ifelse(grepl(x=x, pattern="1-100"), "0-100", - ifelse(grepl(x=x, pattern="1-inf"), "0-inf", NA))) - - type <- ifelse(grepl(x=x, pattern="_MW_"), "capacity", - ifelse(grepl(x=x, pattern="_area_"), "area", NA)) - - bin <- bins[,technology] - bin.names <- paste0("bin", 1:nrow(bins)) - - out <- read.csv2(x, header=FALSE, colClasses=colClasses.df[,technology]) + technology <- ifelse(grepl(x = x, pattern = "PV"), "PV", + ifelse(grepl(x = x, pattern = "CSP"), "CSP", NA) + ) + + distance <- ifelse(grepl(x = x, pattern = "1-50"), "0-50", + ifelse(grepl(x = x, pattern = "1-100"), "0-100", + ifelse(grepl(x = x, pattern = "1-inf"), "0-inf", NA) + ) + ) + + type <- ifelse(grepl(x = x, pattern = "_MW_"), "capacity", + ifelse(grepl(x = x, pattern = "_area_"), "area", NA) + ) + + bin <- bins[, technology] + + out <- read.csv2(x, header = FALSE, colClasses = colClasses.df[, technology]) colnames(out) <- iso.countries out$type <- type out$technology <- technology out$distance <- distance out$bin <- bin - + ### add empty data frames for csp area data - - if(all(technology=="CSP", type=="capacity")){ + + if (all(technology == "CSP", type == "capacity")) { out.area.csp <- out out.area.csp$type <- "area" - out.area.csp[,1:length(iso.countries)] <- NA - + out.area.csp[, 1:length(iso.countries)] <- NA + out <- rbind(out, out.area.csp) } - + return(out) } - + ### read data - + df <- do.call(rbind, lapply(csv.files, read.csv.Solar)) - - dat <- melt(df, id.vars = c("technology", "distance", "bin", "type")) + + dat <- reshape2::melt(df, id.vars = c("technology", "distance", "bin", "type")) # sort bin dimension - dat <- dat[order(dat$bin),] - + dat <- dat[order(dat$bin), ] + dat$Year <- year - dat <- dat[c(5,7,4,1,2,3,6)] - colnames(dat) <- c("region", "Year", "Type","Technology", "Distance", "Bin", "Value") + dat <- dat[c(5, 7, 4, 1, 2, 3, 6)] + colnames(dat) <- c("region", "Year", "Type", "Technology", "Distance", "Bin", "Value") dat$region <- as.character(dat$region) - dat <- dat[!(dat$region =="ANT"),] - - dat <- dat[which(!is.na(dat$region)),] - - out <- as.magpie(dat, datacol=7) - + dat <- dat[!(dat$region == "ANT"), ] + + dat <- dat[which(!is.na(dat$region)), ] + + out <- as.magpie(dat, datacol = 7) + return(out) - } diff --git a/R/readDaviesCooling.R b/R/readDaviesCooling.R index 224ce6f3..693481c8 100644 --- a/R/readDaviesCooling.R +++ b/R/readDaviesCooling.R @@ -1,9 +1,9 @@ #' Read Davies Cooling -#' +#' #' Read in Davies (2013) data on shares of cooling types per electricity #' technology and GCAM region -#' -#' +#' +#' #' @param subtype Type of Davies data that should be read. Available types are: #' \itemize{ \item \code{dataBase}: The Davies source data for the base year #' \item \code{dataFuture}: The Daves source data for the future } @@ -11,27 +11,30 @@ #' @author Lavinia Baumstark, Ioanna Mouratiadou #' @seealso \code{\link{readSource}} #' @examples -#' -#' \dontrun{ a <- readSource(type="DaviesCooling") +#' \dontrun{ +#' a <- readSource(type = "DaviesCooling") #' } -#' +#' readDaviesCooling <- function(subtype) { - - sheets <- c(dataBase=1, dataFuture=2) - sheet <- toolSubtypeSelect(subtype,sheets) - + sheets <- c(dataBase = 1, dataFuture = 2) + sheet <- toolSubtypeSelect(subtype, sheets) + cool <- as.data.frame(read_excel("DaviesCooling.xlsx", sheet = sheet)) - cool <- cool[!is.na(cool$`Davies Source`),] - - row.names(cool) <- paste(cool$'Davies Source',cool$'Davies Cooling',sep=".") - cool$'Davies Source' <- NULL - cool$'Davies Cooling' <- NULL - - regions <- c("USA"="USA","Canada"="CAN", "Western Europe"="WEU", "Japan"="JPN", "Australia & NZ"="ANZ", "Former Soviet Union"="FSU", "China"="CHN", "Middle East"="MEA", "Africa"="AFR", "Latin America"="LAM", "Southeast Asia"="SEA", "Eastern Europe"="EEU" , "Korea"="KOR" , "India"="IND") - names(cool) <- regions #three-letter code" - + cool <- cool[!is.na(cool$`Davies Source`), ] + + row.names(cool) <- paste(cool$"Davies Source", cool$"Davies Cooling", sep = ".") + cool$"Davies Source" <- NULL + cool$"Davies Cooling" <- NULL + + regions <- c("USA" = "USA", "Canada" = "CAN", "Western Europe" = "WEU", + "Japan" = "JPN", "Australia & NZ" = "ANZ", "Former Soviet Union" = "FSU", + "China" = "CHN", "Middle East" = "MEA", "Africa" = "AFR", + "Latin America" = "LAM", "Southeast Asia" = "SEA", + "Eastern Europe" = "EEU", "Korea" = "KOR", "India" = "IND") + names(cool) <- regions # three-letter code" + cool <- as.magpie(cool) getYears(cool) <- NULL - + return(cool) -} +} diff --git a/R/readDias.R b/R/readDias.R deleted file mode 100644 index 4c627a8b..00000000 --- a/R/readDias.R +++ /dev/null @@ -1,60 +0,0 @@ -#' @title readDias -#' Contains employment factors and direct jobs for coal power, employment factors and indirect jobs -#' for coal mining for EU countries. Numbers taken from Dias et al. (2018) -#' @author Aman Malik -#' @param subtype Employment factors or Employment -#' @importFrom readxl read_excel -#' @importFrom dplyr rename mutate select -#' @importFrom tidyr gather -#' @examples -#' \dontrun{ a <- readSource(type="Dias",convert=FALSE) } -#' @return magpie object containing either employment or employment factors. - - -readDias <- function(subtype){ - - - if (subtype=="Employment factors"){ - # values are in Jobs/MW and only include O&M jobs - input <- readxl::read_excel("Employment_Dias.xlsx",sheet = 1) - input <- input[-2] - colnames(input)[2] <- "value" - input$tech <- "Coal" - input$activity <- "OM" - input$year <- 2015 - input <- input[c(1,5,3,4,2)] - - x <- as.magpie(input,spatial=1,temporal=2) - - - return (x) - - } - if(subtype=="Employment"){ - # includes direct jobs in power plants and coal mines - input_d <- readxl::read_excel("Employment_Dias.xlsx",sheet = 2) - input_d <- input_d %>% - rename(power_plant=2,mine=3) %>% - gather(2:3,key = "job_source",value="value") %>% - mutate(type="direct") %>% - select(1,4,2,3) - - # includes indirect jobs from coal mines - input_ind <- readxl::read_excel("Employment_Dias.xlsx",sheet = 3) - input_ind <- input_ind[-3]# considering only intra-regional jobs - colnames(input_ind)[2] <- "value" - input_ind$type="indirect" - input_ind$job_source="mine" - input_ind <- input_ind[c(1,3,4,2)] - - # aggregating - input <- rbind(input_d,input_ind) - input$period <- 2015 - input <- input[c(1,5,2,3,4)] - - x <- as.magpie(input,spatial=1,temporal=2,datacol=5) - - return (x) - - } -} diff --git a/R/readDylanAusGasCost.R b/R/readDylanAusGasCost.R index 79388e20..7c183ce6 100644 --- a/R/readDylanAusGasCost.R +++ b/R/readDylanAusGasCost.R @@ -3,24 +3,22 @@ #' @return magpie object of the cemo database data #' @author Felix Schreyer #' @seealso \code{\link{readSource}} - - +#' readDylanAusGasCost <- function() { - # Dylan's gas extraction cost curve based on GSOO data on reserves and resources in 2015 - #(only for Eastern gas reserves, not Western Australia!!) - - GasData <- read.csv("GSOO-costcurve.csv", stringsAsFactors = F) + # (only for Eastern gas reserves, not Western Australia!!) + + GasData <- read.csv("GSOO-costcurve.csv", stringsAsFactors = FALSE) GasData$country <- "AUS" GasData$year <- "y2005" - GasData$PRICE[GasData$PRICE == '-'] <- "" + GasData$PRICE[GasData$PRICE == "-"] <- "" GasData$PRICE <- as.numeric(GasData$PRICE) GasData$ID <- 1:dim(GasData)[1] - - GasData <- GasData[,c(6,7,8,3,4,5)] - - x <- as.magpie(GasData, spatial = 1, temporal = 2, datacol=6) - + + GasData <- GasData[, c(6, 7, 8, 3, 4, 5)] + + x <- as.magpie(GasData, spatial = 1, temporal = 2, datacol = 6) + return(x) -} +} diff --git a/R/readECLIPSE.R b/R/readECLIPSE.R index 6066d319..d45a37cd 100755 --- a/R/readECLIPSE.R +++ b/R/readECLIPSE.R @@ -1,7 +1,4 @@ -#' @importFrom dplyr mutate_ rename_ filter_ select_ -#' @importFrom tidyr gather_ # NH3 only has one scenario - readECLIPSE <- function(subtype) { if (is.null(subtype) | ! subtype %in% c('activities.aggregated', 'activities.extended', 'emissions.aggregated', 'emissions.extended', 'shipping.emi', 'shipping.ef')) diff --git a/R/readEDGAR7Fgases.R b/R/readEDGAR7Fgases.R index cd220cf0..0b4f8717 100644 --- a/R/readEDGAR7Fgases.R +++ b/R/readEDGAR7Fgases.R @@ -10,18 +10,20 @@ #' @importFrom dplyr starts_with #' @export readEDGAR7Fgases <- function() { - intable <- read_excel( - "EDGAR_F-gases_1990-2021.xlsx", - sheet = "TOTALS BY COUNTRY", skip = 10) + intable <- read_excel( + "EDGAR_F-gases_1990-2021.xlsx", + sheet = "TOTALS BY COUNTRY", skip = 10 + ) - intable <- intable[,-c(1,2,4)] - colnames(intable)[1:2] <- c("CountryCode","Gas") - longtable <- tidyr::pivot_longer(intable, - cols = starts_with("Y_"), - names_prefix = "Y_", - names_to = "period", - values_to = "value") + intable <- intable[, -c(1, 2, 4)] + colnames(intable)[1:2] <- c("CountryCode", "Gas") + longtable <- tidyr::pivot_longer(intable, + cols = starts_with("Y_"), + names_prefix = "Y_", + names_to = "period", + values_to = "value" + ) - x <- as.magpie(longtable) - return(x) -} \ No newline at end of file + x <- as.magpie(longtable) + return(x) +} diff --git a/R/readEDGETransport.R b/R/readEDGETransport.R index 157ddcbf..2914357d 100644 --- a/R/readEDGETransport.R +++ b/R/readEDGETransport.R @@ -1,20 +1,19 @@ -#' Read EDGETransport inputs -#' -#' Read-in EDGETransport inputs csv file as magclass object +#' Read REMIND/EDGE-T iterative input data #' +#' Run EDGE-Transport Standalone in all used scenario combinations to supply input data +#' to REMIND and the iterative EDGE-T script #' #' @return magpie object of EDGEtransport iterative inputs -#' @author Marianna Rottoli, Alois Dirnaichner +#' @author Johanna Hoppe #' @seealso \code{\link{readSource}} -#' @param subtype +#' @param subtype REMIND/iterative EDGE-T input data subtypes #' #' @examples #' \dontrun{ a <- readSource(type = "EDGETransport") #' } -#' @importFrom magclass read.magpie -#' @importFrom tydir expand_grid +#' @importFrom tidyr expand_grid #' @importFrom dplyr bind_rows -#' @importFrom data.table data.table rbindlist fread setcolorder := setnames setkeyv +#' @importFrom data.table data.table rbindlist := setnames setkeyv readEDGETransport <- function(subtype) { @@ -29,36 +28,38 @@ readEDGETransport <- function(subtype) { expand_grid( SSPscen = c("SSP1", "SSP2", "SSP5", "SSP2EU", "SDP"), transportPolScen = c("Mix1", "Mix2", "Mix3", "Mix4"), - demScen = c("default", "SSP2EU_demRedWeak", "SSP2EU_demRedStrong")), - - ## Specific project scenarios + isICEban = c(TRUE, FALSE), + demScen = c("default")), + # Specific project scenarios tribble( - ~SSPscen, ~transportPolScen, ~demScen, - 'SDP_EI', 'Mix4', 'default', - 'SDP_MC', 'Mix4', 'default', - 'SDP_RC', 'Mix3', 'default', - 'SSP2EU', 'HydrHype4', 'default', - 'SSP2EU', 'ECEMF_HighEl_HighEff', 'default', - 'SSP2EU', 'ECEMF_HighEl_LifestCha', 'SSP2EU_demRedStrong', - 'SSP2EU', 'ECEMF_HighEl_ModEff', 'default', - 'SSP2EU', 'ECEMF_HighH2_HighEff', 'default', - 'SSP2EU', 'ECEMF_HighH2_LifestCha', 'SSP2EU_demRedStrong', - 'SSP2EU', 'ECEMF_HighH2_ModEff', 'default', - 'SSP2EU', 'NAV_act', 'SSP2EU_demRedStrong', - 'SSP2EU', 'NAV_tec', 'default', - 'SSP2EU', 'NAV_ele', 'default', - 'SSP2EU', 'NAV_all', 'SSP2EU_demRedStrong', - 'SSP2EU', 'NAV_lce', 'SSP2EU_demRedStrong', - 'SSP2EU', 'PhOP', 'default', - 'SSP2EU', 'CAMP_lscWeak', 'SSP2EU_demRedWeak', - 'SSP2EU', 'CAMP_lscStrong', 'SSP2EU_demRedStrong' + ~SSPscen, ~transportPolScen, ~isICEban, ~demScen, + 'SSP2', 'Mix1', FALSE, 'SSP2EU_demRedStrong', + 'SSP2', 'Mix2', FALSE, 'SSP2EU_demRedStrong', + 'SSP2', 'Mix3', TRUE, 'SSP2EU_demRedStrong', + 'SSP2', 'Mix4', TRUE, 'SSP2EU_demRedStrong', + 'SSP2', 'Mix4', TRUE, 'SSP2_demDiffer', + 'SDP_EI', 'Mix4', TRUE, 'default', + 'SDP_MC', 'Mix4', TRUE, 'default', + 'SDP_RC', 'Mix3', TRUE, 'default', + 'SSP2EU', 'HydrHype4', TRUE, 'default', + 'SSP2EU', 'ECEMF_HighEl_HighEff', TRUE, 'default', + 'SSP2EU', 'ECEMF_HighEl_LifestCha', TRUE, 'SSP2EU_demRedStrong', + 'SSP2EU', 'ECEMF_HighEl_ModEff', TRUE, 'default', + 'SSP2EU', 'ECEMF_HighH2_HighEff', TRUE, 'default', + 'SSP2EU', 'ECEMF_HighH2_LifestCha', TRUE, 'SSP2EU_demRedStrong', + 'SSP2EU', 'ECEMF_HighH2_ModEff', TRUE, 'default', + 'SSP2EU', 'NAV_act', FALSE, 'SSP2EU_demRedStrong', + 'SSP2EU', 'NAV_tec', FALSE, 'default', + 'SSP2EU', 'NAV_ele', TRUE, 'default', + 'SSP2EU', 'NAV_all', TRUE, 'SSP2EU_demRedStrong', + 'SSP2EU', 'NAV_lce', FALSE, 'SSP2EU_demRedStrong', + 'SSP2EU', 'CAMP_lscWeak', TRUE, 'SSP2EU_demRedWeak', + 'SSP2EU', 'CAMP_lscStrong', TRUE, 'SSP2EU_demRedStrong' ) ) # generate list from data frame rows - allScens <- lapply(1:nrow(allScens), function(x) { - setNames(unlist(allScens[x, ]), NULL) - }) + allScens <- split(allScens, seq(nrow(allScens))) ############################################################# ## Run EDGE-Transport SA with all scenario combinations @@ -66,45 +67,47 @@ readEDGETransport <- function(subtype) { EdgeTransportSAdata <- lapply(allScens, function(x) { - toolEdgeTransport <- function(SSPscen = x[1], - transportPolScen = x[2], - demScen = x[3], - generateTransportData = FALSE, - generateREMINDinputData = TRUE) + calcOutput(type = "EdgeTransportSA", + aggregate = FALSE, + supplementary = FALSE, + SSPscen = x[["SSPscen"]], + transportPolScen = x[["transportPolScen"]], + isICEban = x[["isICEban"]], + demScen = x[["demScen"]], + isTransportReported = FALSE, + isREMINDinputReported = TRUE, + isStored = FALSE) }) + types <- unique(unlist(lapply(EdgeTransportSAdata, names))) + # Bind rows of equally named subtypes + EdgeTransportSAdata <- lapply(types, function(type, outerList) { + listOfDataTables <- lapply(outerList, function(innerList) innerList[[type]]) + result <- rbindlist(listOfDataTables) + }, EdgeTransportSAdata) + + EdgeTransportSAdata <- setNames(EdgeTransportSAdata, types) ############################################################# ## Rename EDGE-Transport demScens and map to REMIND demScens ## that are applied to all sectors simultaneously ############################################################# - - createCopyDemScens <- function(dt) { - setkeyv(dt, c("DEM_scenario", "GDP_scenario", "EDGE_scenario")) - ## Workaround for NAVIGATE: copy-create demand scenarios which we do not supply by EDGE-T - dt <- rbind(dt, - dt[.("gdp_SSP2EU", "gdp_SSP2EU", "NAV_ele"), nomatch = NULL][ - , DEM_scenario := "gdp_SSP2EU_NAV_ele"], - dt[.("gdp_SSP2EU", "gdp_SSP2EU", "NAV_tec"), nomatch = NULL][ - , DEM_scenario := "gdp_SSP2EU_NAV_tec"], - dt[.("gdp_SSP2EU_demRedStrong", "gdp_SSP2EU", "NAV_act"), nomatch = NULL][ - , DEM_scenario := "gdp_SSP2EU_NAV_act"], - dt[.("gdp_SSP2EU_demRedStrong", "gdp_SSP2EU", "NAV_all"), nomatch = NULL][ - , DEM_scenario := "gdp_SSP2EU_NAV_all"], - dt[.("gdp_SSP2EU_demRedStrong", "gdp_SSP2EU", "NAV_lce"), nomatch = NULL][ - , DEM_scenario := "gdp_SSP2EU_NAV_lce"], - dt[.("gdp_SSP2EU_demRedWeak", "gdp_SSP2EU", "CAMP_lscWeak"), nomatch = NULL][ - , DEM_scenario := "gdp_SSP2EU_CAMP_weak"], - dt[.("gdp_SSP2EU_demRedStrong", "gdp_SSP2EU", "CAMP_lscStrong"), nomatch = NULL][ - , DEM_scenario := "gdp_SSP2EU_CAMP_strong"] - ) - setkeyv(dt, "DEM_scenario") - dt[.("gdp_SSP2EU_demRedStrong"), DEM_scenario := "gdp_SSP2_lowEn"] + translateEdgeTransportDemScentoREMIND <- function(dt) { + dt[DEM_scenario == "gdp_SSP2_demDiffer" & EDGE_scenario == "Mix4ICEban", DEM_scenario := "gdp_SSP2_demDiffer_IKEA"] + dt[DEM_scenario == "gdp_SSP2EU" & EDGE_scenario == "NAV_ele", DEM_scenario := "gdp_SSP2EU_NAV_ele"] + dt[DEM_scenario == "gdp_SSP2EU" & EDGE_scenario == "NAV_tec", DEM_scenario := "gdp_SSP2EU_NAV_tec"] + dt[DEM_scenario == "gdp_SSP2EU_demRedStrong" & EDGE_scenario == "NAV_act", DEM_scenario := "gdp_SSP2EU_NAV_act"] + dt[DEM_scenario == "gdp_SSP2EU_demRedStrong" & EDGE_scenario == "NAV_all", DEM_scenario := "gdp_SSP2EU_NAV_all"] + dt[DEM_scenario == "gdp_SSP2EU_demRedStrong" & EDGE_scenario == "NAV_lce", DEM_scenario := "gdp_SSP2EU_NAV_lce"] + dt[DEM_scenario == "gdp_SSP2EU_demRedWeak" & EDGE_scenario == "CAMP_lscWeak", DEM_scenario := "gdp_SSP2EU_CAMP_weak"] + dt[DEM_scenario == "gdp_SSP2EU_demRedStrong" & EDGE_scenario == "CAMP_lscStrong", DEM_scenario := "gdp_SSP2EU_CAMP_strong"] + dt[DEM_scenario == "gdp_SSP2EU_demRedStrong" & EDGE_scenario == "Mix1", DEM_scenario := "gdp_SSP2_lowEn"] + dt[DEM_scenario == "gdp_SSP2EU_demRedStrong" & EDGE_scenario == "Mix2", DEM_scenario := "gdp_SSP2_lowEn"] + dt[DEM_scenario == "gdp_SSP2EU_demRedStrong" & EDGE_scenario == "Mix3ICEban", DEM_scenario := "gdp_SSP2_lowEn"] + dt[DEM_scenario == "gdp_SSP2EU_demRedStrong" & EDGE_scenario == "Mix4ICEban", DEM_scenario := "gdp_SSP2_lowEn"] return(dt) } - - EdgeTransportSAdata <- lapply(EdgeTransportSAdata, createCopyDemScens) - + EdgeTransportSAdata <- lapply(EdgeTransportSAdata, translateEdgeTransportDemScentoREMIND) ############################################################# ## Create magpie object for every subtype ############################################################# @@ -114,6 +117,5 @@ readEDGETransport <- function(subtype) { magpieobj <- as.magpie(EdgeTransportSAdata[[subtype]]) - return(magpieobj) } diff --git a/R/readEdgeBuildings.R b/R/readEdgeBuildings.R index 38d53ded..ff856444 100644 --- a/R/readEdgeBuildings.R +++ b/R/readEdgeBuildings.R @@ -4,7 +4,6 @@ #' @return magclass object #' #' @author Antoine Levesque, Robin Hasse -#' @importFrom magclass mselect as.magpie readEdgeBuildings <- function(subtype = c("FE", "Floorspace")) { subtype <- match.arg(subtype) diff --git a/R/readEmber.R b/R/readEmber.R index 7863a553..8caa9ed9 100644 --- a/R/readEmber.R +++ b/R/readEmber.R @@ -8,7 +8,6 @@ #' @source https://ember-climate.org/data-catalogue/yearly-electricity-data/ #' #' @importFrom dplyr select -#' @importFrom magclass as.magpie #' #' @export diff --git a/R/readEuropeanEnergyDatasheets.R b/R/readEuropeanEnergyDatasheets.R index b3e6dbfa..5fa229bf 100644 --- a/R/readEuropeanEnergyDatasheets.R +++ b/R/readEuropeanEnergyDatasheets.R @@ -13,8 +13,6 @@ #' @importFrom readxl excel_sheets read_excel #' @param subtype data subtype. Either "EU28" (data from June 20 including GBR) #' or "EU27" (latest data from August 23 without GBR) -#' @importFrom reshape2 melt -#' @importFrom dplyr %>% #' @importFrom tidyr drop_na extract #' @importFrom readxl excel_sheets read_excel #' @importFrom stats aggregate @@ -91,7 +89,7 @@ readEuropeanEnergyDatasheets <- function(subtype) { # merge into single dataframe data <- do.call("rbind", data) # long format - data <- melt(data, id.vars = 1:2) + data <- reshape2::melt(data, id.vars = 1:2) colnames(data) <- c("variable", "region", "period", "value") # dump contents into magpie x <- as.magpie(data, spatial = 2, datacol = 4, temporal = 3) @@ -654,11 +652,11 @@ readEuropeanEnergyDatasheets <- function(subtype) { bind_cols(rows) %>% drop_na("variable", "unit") %>% select(-1) %>% - melt(id.vars = c("variable", "unit"), variable.name = "year") %>% + reshape2::melt(id.vars = c("variable", "unit"), variable.name = "year") %>% mutate( - "year" := as.numeric(as.character(.data$year)), - "region" := sheet, - "value" := suppressWarnings(as.numeric(.data$value)) + "year" = as.numeric(as.character(.data$year)), + "region" = sheet, + "value" = suppressWarnings(as.numeric(.data$value)) ) ) } diff --git a/R/readEurostat_EffortSharing.R b/R/readEurostat_EffortSharing.R index 59522184..0356fd13 100644 --- a/R/readEurostat_EffortSharing.R +++ b/R/readEurostat_EffortSharing.R @@ -1,49 +1,46 @@ -#' Read EU Effort Sharing targets and historical emissions -#' +#' Read EU Effort Sharing targets and historical emissions +#' #' Read-in EU Effort Sharing targets and historical emissions csv files as magclass object -#' -#' +#' #' @param subtype data subtype. Either "target" or "emissions" -#' @return magpie object of the EU Effort Sharing targets (%) or Effort Sharing historical historical emissions (MtCO2) +#' @return magpie object of the EU Effort Sharing targets (%) or Effort Sharing historical historical emissions (MtCO2) #' @author Renato Rodrigues #' @seealso \code{\link{readSource}} #' @examples -#' -#' \dontrun{ a <- readSource(type="Eurostat_EffortSharing",subtype="target") +#' \dontrun{ +#' a <- readSource(type = "Eurostat_EffortSharing", subtype = "target") #' } -#' -#' @importFrom reshape2 melt -#' @importFrom magclass as.magpie -#' - +#' readEurostat_EffortSharing <- function(subtype) { - - if (subtype == "target") { - #Reading EU Effort Sharing country targets - data <- read.csv("effort_sharing_targets.csv",sep=";",skip=5) - colnames(data) <- c("iso2", "country.name", "iso3", "2020", "2030", "flexibility_from_ETS_in_2030", "flexibility_from_land_use_in_2030") - data <- na.omit(data[,c("iso3","2020","2030")]) - } else if (subtype== "emissions") { - #Reading EU Effort Sharing country historical emissions - data <- read.csv("t2020_35.csv",sep=";") - colnames(data) <- c("indic_eu", "iso2", "2005", "2006", "2007", "2008", "2009", "2010", "2011", "2012", "2013", "2014", "2015", "2016", "2017", "target") - iso2toiso3 <- c("LU" = "LUX", "SE" = "SWE", "DK" = "DNK", "FI" = "FIN", "DE" = "DEU", - "FR" = "FRA", "UK" = "GBR", "NL" = "NLD", "AT" = "AUT", "BE" = "BEL", - "IT" = "ITA", "IE" = "IRL", "ES" = "ESP", "CY" = "CYP", "MT" = "MLT", - "PT" = "PRT", "EL" = "GRC", "SI" = "SVN", "CZ" = "CZE", "EE" = "EST", - "SK" = "SVK", "LT" = "LTU", "PL" = "POL", "HR" = "HRV", "HU" = "HUN", - "LV" = "LVA", "RO" = "ROU", "BG" = "BGR") - data$iso3 <- iso2toiso3[as.character(data$iso2)] - data <- na.omit(data[,c("iso3", "2005","2006", "2007", "2008", "2009", "2010", "2011", "2012", "2013", "2014", "2015", "2016")]) - } else { - stop("Not a valid subtype!") - } - - # data in wide format - data <- melt(data, id.vars=c("iso3"), variable.name="period", value.name="value") # melt requires library(reshape2) - - # converting to magpie object - x <- as.magpie(data,spatial=1,temporal=2) - - return(x) - } + if (subtype == "target") { + # Reading EU Effort Sharing country targets + data <- read.csv("effort_sharing_targets.csv", sep = ";", skip = 5) + colnames(data) <- c("iso2", "country.name", "iso3", "2020", "2030", + "flexibility_from_ETS_in_2030", "flexibility_from_land_use_in_2030") + data <- na.omit(data[, c("iso3", "2020", "2030")]) + } else if (subtype == "emissions") { + # Reading EU Effort Sharing country historical emissions + data <- read.csv("t2020_35.csv", sep = ";") + colnames(data) <- c("indic_eu", "iso2", "2005", "2006", "2007", "2008", "2009", "2010", "2011", + "2012", "2013", "2014", "2015", "2016", "2017", "target") + iso2toiso3 <- c( + "LU" = "LUX", "SE" = "SWE", "DK" = "DNK", "FI" = "FIN", "DE" = "DEU", + "FR" = "FRA", "UK" = "GBR", "NL" = "NLD", "AT" = "AUT", "BE" = "BEL", + "IT" = "ITA", "IE" = "IRL", "ES" = "ESP", "CY" = "CYP", "MT" = "MLT", + "PT" = "PRT", "EL" = "GRC", "SI" = "SVN", "CZ" = "CZE", "EE" = "EST", + "SK" = "SVK", "LT" = "LTU", "PL" = "POL", "HR" = "HRV", "HU" = "HUN", + "LV" = "LVA", "RO" = "ROU", "BG" = "BGR" + ) + data$iso3 <- iso2toiso3[as.character(data$iso2)] + data <- na.omit(data[, c("iso3", "2005", "2006", "2007", "2008", "2009", "2010", "2011", "2012", + "2013", "2014", "2015", "2016")]) + } else { + stop("Not a valid subtype!") + } + + # data in wide format + data <- reshape2::melt(data, id.vars = c("iso3"), variable.name = "period", value.name = "value") + + # converting to magpie object + as.magpie(data, spatial = 1, temporal = 2) +} diff --git a/R/readExpertGuess.R b/R/readExpertGuess.R index c0b33a31..90b0b4c9 100644 --- a/R/readExpertGuess.R +++ b/R/readExpertGuess.R @@ -11,25 +11,27 @@ #' convergence from historic to target shares is to be applied. #' - `cement_production_convergence_parameters`: convergence year and level #' (relative to global average) to which per-capita cement demand converges -#' - Any of the others nobody cared to document. +#' - `ies` +#' - `prtp` +#' - `CCSbounds` +#' - `costsTradePeFinancial` +#' - `tradeContsraints`: parameter by Nicolas Bauer (2024) for the region +#' specific trade constraints, values different to 1 activate constraints +#' and the value is used as effectiveness to varying degrees such as percentage numbers #' @return magpie object of the data #' @author Lavinia Baumstark #' @seealso \code{\link{readSource}} #' @examples -#' -#' \dontrun{ a <- readSource(type="ExpertGuess",subtype="ies") +#' \dontrun{ +#' a <- readSource(type = "ExpertGuess", subtype = "ies") #' } #' #' @importFrom dplyr bind_rows filter pull select -#' @importFrom magrittr %>% #' @importFrom quitte madrat_mule #' @importFrom readr read_csv #' @importFrom tidyr expand_grid readExpertGuess <- function(subtype) { - path <- '~/PIK/swap/inputdata/sources/ExpertGuess/' - path <- './' - if (subtype == "ies") { a <- read.csv("ies.csv", sep = ";") } else if (subtype == "prtp") { @@ -40,63 +42,69 @@ readExpertGuess <- function(subtype) { a <- read.csv("co2prices-2023-06.csv", sep = ";") } else if (subtype == "costsTradePeFinancial") { a <- read.csv("pm_costsTradePeFinancial.csv", - sep = ";", - skip = 2) + sep = ";", + skip = 2 + ) } - if (subtype == "ies" | - subtype == "prtp" | - subtype == "CCSbounds" | subtype == "co2prices") { + if (subtype == "ies" || subtype == "prtp" || subtype == "CCSbounds" || subtype == "co2prices") { a$RegionCode <- NULL - a$Country <- NULL + a$Country <- NULL out <- as.magpie(a) } else if (subtype == "costsTradePeFinancial") { out <- as.magpie(a, - spatial = 1, - temporal = 0, - datacol = 3) + spatial = 1, + temporal = 0, + datacol = 3 + ) out <- collapseNames(out) - # getSets(out) <- c("region","year","type","pe") } - if (subtype == "ies" | subtype == "prtp") { + if (subtype == "ies" || subtype == "prtp") { getYears(out) <- "2005" } - if ('Chinese_Steel_Production' == subtype) { - out <- read_csv(file = file.path(path, 'Chinese_Steel_Production.csv'), - comment = '#', - show_col_types = FALSE) %>% + if ("Chinese_Steel_Production" == subtype) { + out <- read_csv( + file = "Chinese_Steel_Production.csv", + comment = "#", + show_col_types = FALSE + ) %>% madrat_mule() - } else if ('industry_max_secondary_steel_share' == subtype) { + } else if ("industry_max_secondary_steel_share" == subtype) { out <- read_csv( - file = file.path(path, 'industry_max_secondary_steel_share.csv'), - comment = '#', + file = "industry_max_secondary_steel_share.csv", + comment = "#", show_col_types = FALSE ) %>% madrat_mule() - } else if ('cement_production_convergence_parameters' == subtype) { + } else if ("cement_production_convergence_parameters" == subtype) { out <- read_csv( - file = file.path(path, 'cement_production_convergence_parameters.csv'), - col_types = 'cdi', - comment = '#') + file = "cement_production_convergence_parameters.csv", + col_types = "cdi", + comment = "#" + ) out <- bind_rows( out %>% filter(!is.na(.data$region)), - out %>% head(n = 1) %>% filter(is.na(.data$region)) %>% - select(-'region') %>% - expand_grid(region = toolGetMapping(name = 'regionmapping_21_EU11.csv', - type = 'regional', where = "mappingfolder") %>% - pull('RegionCode') %>% - unique() %>% - sort() %>% - setdiff(out$region)) + select(-"region") %>% + expand_grid(region = toolGetMapping( + name = "regionmapping_21_EU11.csv", + type = "regional", where = "mappingfolder" + ) %>% + pull("RegionCode") %>% + unique() %>% + sort() %>% + setdiff(out$region)) ) %>% madrat_mule() + } else if (subtype == "tradeConstraints") { + a <- read.csv("tradeConstraints.csv", sep = ";") + out <- as.magpie(a) } return(out) diff --git a/R/readGCPT.R b/R/readGCPT.R index feeac150..3a737991 100644 --- a/R/readGCPT.R +++ b/R/readGCPT.R @@ -4,101 +4,26 @@ #' @param subtype Options are status, historical, future, lifespans, comp_rates and emissions #' @author Stephen Bi #' @importFrom readxl read_excel -#' @importFrom dplyr %>% filter select mutate summarize group_by left_join across everything starts_with -#' @importFrom magclass replace_non_finite +#' @importFrom dplyr filter select mutate summarize group_by left_join across everything starts_with #' @importFrom quitte removeColNa #' @aliases readEndCoal readGCPT <- function(subtype) { - map <- toolGetMapping(getConfig("regionmapping"), type="regional", where = "mappingfolder") - year <- NULL - if (!(subtype %in% c("early_retire","historical","status","future","lifespans","emissions","comp_rates","reg_comp_rates","glo_comp_rates","meanAge","ppca_emi","G20_FinEx", - "PEGASOS","PEGASOS_pubfinex","PEGASOS_prefinex","REM_PEGASOS_pubfinex","REM_PEGASOS_pubfinex_REsub"))) { + if (!(subtype %in% c("early_retire", "historical", "status", "future", + "lifespans", "emissions", "comp_rates", "reg_comp_rates", + "glo_comp_rates", "meanAge", "ppca_emi", "G20_FinEx", + "PEGASOS", "PEGASOS_pubfinex", "PEGASOS_prefinex", + "REM_PEGASOS_pubfinex", "REM_PEGASOS_pubfinex_REsub"))) { stop("Invalid subtype!") } - # Data files to be read in - status_changes_encoding <- 'UTF-8' - if (is.null(year)) { - summary_data <- "GCPT_data_Jan2023.xlsx" - status_changes <- - "Jan 2023 GCPT Status Changes - 2014 - 2022 (final).csv" - status_changes_encoding <- 'ANSI_X3.4-1986' - plant_data <- "Global-Coal-Plant-Tracker-January-2023.xlsx" - lastCol <- "X" - sep = ";" - latest_col <- 3 - } else if (grepl('2021', year)) { - summary_data <- "GCPT_data_Jan2021.xlsx" - status_changes <- "GCPT Status Changes_1Feb2021.csv" - plant_data <- "January 2021 Global Coal Plant Tracker.xlsx" - lastCol <- "V" - sep = "," - latest_col <- 3 - } else if (grepl('2022', year)) { - summary_data <- "GCPT_data_Jan2022.xlsx" - status_changes <- - "Jan 2022 GCPT Status Changes - 2014 - 2021 (b).csv" - status_changes_encoding <- 'ANSI_X3.4-1986' - plant_data <- "Global-Coal-Plant-Tracker-Jan-2022.xlsx" - lastCol <- "W" - sep = ";" - latest_col <- 3 - } else if (grepl('2020', year)) { - summary_data <- "GCPT_data_Jul2020.xlsx" - status_changes <- "GCPT Status Changes H1 2015 to H1 2020.xlsx" - plant_data <- "July 2020 Global Coal Plant Tracker.xlsx" - lastCol <- "V" - sep = "," - plant_status <- - read_excel("GCPT Status Changes H1 2015 to H1 2020.xlsx", sheet = 2) - plant_status <- - plant_status %>% select(Country, MW, Jul20, Jan20, Jan19, Jan18, Jan17, Jan16, Jan15) - colnames(plant_status)[3:ncol(plant_status)] <- c(2020:2014) - latest_col <- 3 - } - - plant_status <- read.csv(status_changes, sep = sep, - stringsAsFactors = FALSE) - - plant_status <- plant_status %>% - select(Country, MW, starts_with("H2")) %>% - # mutate(across(where(is.character), ~iconv(., from = status_changes_encoding, to = "UTF-8"))) %>% - mutate(Country = ifelse(grepl("rkiye", Country), "Turkey", Country), - Country = ifelse(grepl("Ivoire", Country), "Cote d'Ivoire", Country)) - - colnames(plant_status)[3:ncol(plant_status)] <- as.numeric(gsub("H2.","",colnames(plant_status)[3:ncol(plant_status)])) - - present_year <- as.numeric(substr(summary_data,nchar(summary_data)-8,nchar(summary_data)-5)) - `Announced + Pre-permit + Permitted` <- NULL . <- NULL - H2.2014 <- NULL - H2.2015 <- NULL - H2.2016 <- NULL - H2.2017 <- NULL - H2.2018 <- NULL - H2.2019 <- NULL - H2.2020 <- NULL - H2.2021 <- NULL - Jan15 <- NULL - Jan16 <- NULL - Jan17 <- NULL - Jan18 <- NULL - Jan19 <- NULL - Jan20 <- NULL - Jul20 <- NULL Country <- NULL CountryCode <- NULL MW <- NULL - `2015` <- NULL - `2016` <- NULL - `2017` <- NULL - `2018` <- NULL - `2019` <- NULL - `2020` <- NULL `Plant Age` <- NULL `Capacity (MW)` <- NULL Status <- NULL @@ -116,596 +41,626 @@ readGCPT <- function(subtype) { brown_5yr_emi <- NULL norm_5yr_emi <- NULL BAU_emi <- NULL - All_total_emi <- NULL Value <- NULL - BAU_total_emi <- NULL - green_total_emi <- NULL - brown_total_emi <- NULL - norm_total_emi <- NULL brown_emi <- NULL green_emi <- NULL norm_emi <- NULL - # Capacity by country as of January 2022, with select manual updates according to the Global Coal Finance Tracker and news media - cap_sum <- read_excel(summary_data,sheet="Summary",range="A4:K112") %>% - filter(!grepl("Total",Country) & !grepl("World",Country)) + map <- toolGetMapping(getConfig("regionmapping"), type = "regional", where = "mappingfolder") + + # Data files to be read in + summary_data <- "GCPT_data_Jan2023.xlsx" + status_changes <- "Jan 2023 GCPT Status Changes - 2014 - 2022 (final).csv" + plant_data <- "Global-Coal-Plant-Tracker-January-2023.xlsx" + lastCol <- "X" + sep <- ";" + latest_col <- 3 - # cap_sum <- ifelse(grepl("2020",subtype) | grepl("2021",subtype), - # read_excel(summary_data,sheet="Summary",range="A4:K112"), - # read_excel(summary_data,sheet="Summary")) + plant_status <- read.csv2(status_changes, sep = sep, stringsAsFactors = FALSE, fileEncoding = "ISO-8859-13") + + plant_status <- plant_status %>% + select(Country, MW, starts_with("H2")) %>% + mutate("Country" = ifelse(grepl("rkiye", Country), "Turkey", Country), + "Country" = ifelse(grepl("Ivoire", Country), "Cote d'Ivoire", Country), + "MW" = as.numeric(MW)) - cap_sum <- cap_sum %>% select(-`Announced + Pre-permit + Permitted`) - cap_sum <- as.magpie(cap_sum,spatial=1) + colnames(plant_status)[3:ncol(plant_status)] <- as.numeric(gsub("H2.", "", colnames(plant_status)[3:ncol(plant_status)])) + + present_year <- as.numeric(substr(summary_data, nchar(summary_data) - 8, nchar(summary_data) - 5)) + + # Capacity by country as of January 2022, with select manual updates according + # to the Global Coal Finance Tracker and news media + cap_sum <- read_excel(summary_data, sheet = "Summary", range = "A4:K112") %>% + filter(!grepl("Total", Country) & !grepl("World", Country)) + + cap_sum <- cap_sum %>% + select(-`Announced + Pre-permit + Permitted`) + cap_sum <- as.magpie(cap_sum, spatial = 1) cap_sum <- toolCountryFill(setItems(dim = 1, x = cap_sum, value = toolCountry2isocode(mapping = c("DR Congo" = "COD"), country = getItems(dim = 1, x = cap_sum))), - fill=0, + fill = 0, no_remove_warning = "KOS", - verbosity=2) + verbosity = 2) - cap_sum_oper <- cap_sum[,,"Operating"] + cap_sum_oper <- cap_sum[, , "Operating"] ################################################### ### Historical capacity additions & retirements ### ################################################### - additions <- read_excel(summary_data,sheet="Additions",range = c(paste0("A4:",lastCol,"112"))) %>% - filter(!grepl("Total",Country) & !grepl("World",Country)) - # colnames(additions)[length(colnames(additions))]="2020" - retirements <- read_excel(summary_data,sheet="Retirements",range = c(paste0("A4:",lastCol,"112"))) %>% - filter(!grepl("Total",Country) & !grepl("World",Country)) + additions <- read_excel(summary_data, sheet = "Additions", range = c(paste0("A4:", lastCol, "112"))) %>% + filter(!grepl("Total", Country) & !grepl("World", Country)) + retirements <- read_excel(summary_data, sheet = "Retirements", range = c(paste0("A4:", lastCol, "112"))) %>% + filter(!grepl("Total", Country) & !grepl("World", Country)) add_startyr <- as.numeric(colnames(additions)[2]) add_endyr <- as.numeric(colnames(additions)[length(additions)]) - status_startyr <- as.numeric(colnames(plant_status)[ncol(plant_status)]) - status_endyr <- as.numeric(colnames(plant_status)[3]) - # Filter for all plants that were mothballed during this period mothballed <- plant_status %>% - filter(rowSums(across(everything(),~grepl("Moth",.)))>0) %>% - filter(rowSums(across(everything(),~grepl("Oper",.)))>0) + filter(rowSums(across(everything(), ~ grepl("Moth", .))) > 0) %>% + filter(rowSums(across(everything(), ~ grepl("Oper", .))) > 0) + + # Calculate capacity that was mothballed or restarted each year since 2014 + # (to be fed into back-calculation of annual capacity below) + cap_moth <- new.magpie(getItems(dim = 1, x = cap_sum), + years = as.numeric(colnames(additions)[2:length(additions)]), + names = c("Operating", "pre_status"), fill = 0) - # Calculate capacity that was mothballed or restarted each year since 2014 (to be fed into back-calculation of annual capacity below) - cap_moth <- new.magpie(getItems(dim = 1, x = cap_sum),years=as.numeric(colnames(additions)[2:length(additions)]),names=c("Operating","pre_status"),fill=0) for (j in 4:ncol(mothballed)) { + # Mothballed plants in 2020 which were operating earlier oper_moth <- mothballed %>% - filter(mothballed[,j]=="Operating" & mothballed[,3]=="Mothballed") %>% + filter(mothballed[, j] == "Operating" & mothballed[, 3] == "Mothballed") %>% group_by(Country) %>% - summarize(sum=sum(MW)) + summarize(sum = sum(MW)) + oper_moth$Country <- toolCountry2isocode(mapping = c("DR Congo" = "COD"), country = oper_moth$Country) + oper_moth <- suppressWarnings( - toolCountryFill(as.magpie(oper_moth,spatial=1,temporal=as.numeric(colnames(mothballed)[j]),datacol=2),verbosity=2,fill=0,no_remove_warning = "KOS") + toolCountryFill(as.magpie(oper_moth, spatial = 1, temporal = as.numeric(colnames(mothballed)[j]), datacol = 2), + verbosity = 2, fill = 0, no_remove_warning = "KOS") ) # Retired plants in 2020 which were mothballed earlier moth_ret <- mothballed %>% - filter(mothballed[,j]=="Mothballed" & mothballed[,3]=="Retired") %>% + filter(mothballed[, j] == "Mothballed" & mothballed[, 3] == "Retired") %>% group_by(Country) %>% - summarize(sum=sum(MW)) + summarize(sum = sum(MW)) moth_ret$Country <- toolCountry2isocode(mapping = c("DR Congo" = "COD"), country = moth_ret$Country) moth_ret <- suppressWarnings( - toolCountryFill(as.magpie(moth_ret,spatial=1,temporal=as.numeric(colnames(mothballed)[j]),datacol=2),verbosity=2,fill=0,no_remove_warning = "KOS") + toolCountryFill(as.magpie(moth_ret, spatial = 1, temporal = as.numeric(colnames(mothballed)[j]), datacol = 2), verbosity = 2, fill = 0, no_remove_warning = "KOS") ) # Operating plants in 2020 which were mothballed earlier moth_oper <- mothballed %>% - filter(mothballed[,j]=="Mothballed" & mothballed[,3]=="Operating") %>% + filter(mothballed[, j] == "Mothballed" & mothballed[, 3] == "Operating") %>% group_by(Country) %>% - summarize(sum=sum(MW)) + summarize(sum = sum(MW)) moth_oper$Country <- toolCountry2isocode(mapping = c("DR Congo" = "COD"), country = moth_oper$Country) moth_oper <- suppressWarnings( - toolCountryFill(as.magpie(moth_oper,spatial=1,temporal=as.numeric(colnames(mothballed)[j]),datacol=2),verbosity=2,fill=0,no_remove_warning = "KOS") + toolCountryFill(as.magpie(moth_oper, spatial = 1, temporal = as.numeric(colnames(mothballed)[j]), datacol = 2), verbosity = 2, fill = 0, no_remove_warning = "KOS") ) constr_moth <- mothballed %>% - filter(mothballed[,3]=="Mothballed" & mothballed[,j]!="Mothballed" & mothballed[,j]!="Operating") %>% + filter(mothballed[, 3] == "Mothballed" & mothballed[, j] != "Mothballed" & mothballed[, j] != "Operating") %>% group_by(Country) %>% - summarize(sum=sum(MW)) + summarize(sum = sum(MW)) constr_moth$Country <- toolCountry2isocode(mapping = c("DR Congo" = "COD"), country = constr_moth$Country) constr_moth <- suppressWarnings( - toolCountryFill(as.magpie(constr_moth,spatial=1,temporal=as.numeric(colnames(mothballed)[j]),datacol=2),verbosity=2,fill=0,no_remove_warning = "KOS") + toolCountryFill(as.magpie(constr_moth, spatial = 1, temporal = as.numeric(colnames(mothballed)[j]), datacol = 2), verbosity = 2, fill = 0, no_remove_warning = "KOS") ) # Annual flux of mothballing/restarting - cap_moth[,as.numeric(colnames(mothballed)[j]),"Operating"] <- oper_moth + constr_moth - moth_oper - moth_ret + cap_moth[, as.numeric(colnames(mothballed)[j]), "Operating"] <- oper_moth + constr_moth - moth_oper - moth_ret } # Capacity with mothballed status in the first and last year shall be added as operating capacity in years prior to status tracking moth_moth <- mothballed %>% - filter(mothballed[,3]=="Mothballed" & mothballed[,j]=="Mothballed") %>% + filter(mothballed[, 3] == "Mothballed" & mothballed[, j] == "Mothballed") %>% group_by(Country) %>% - summarize(sum=sum(MW)) + summarize(sum = sum(MW)) + moth_moth$Country <- toolCountry2isocode(mapping = c("DR Congo" = "COD"), country = moth_moth$Country) moth_moth <- suppressWarnings( - toolCountryFill(as.magpie(moth_moth,spatial=1,temporal=as.numeric(colnames(mothballed)[j]),datacol=2),verbosity=2,fill=0,no_remove_warning = "KOS") + toolCountryFill(as.magpie(moth_moth, spatial = 1, temporal = as.numeric(colnames(mothballed)[j]), datacol = 2), verbosity = 2, fill = 0, no_remove_warning = "KOS") ) - cap_moth[,add_startyr:(as.numeric(colnames(mothballed)[j])-1),"pre_status"] <- oper_moth + constr_moth + moth_moth + cap_moth[, add_startyr:(as.numeric(colnames(mothballed)[j]) - 1), "pre_status"] <- oper_moth + constr_moth + moth_moth # Back-calculate annual capacity by adding retired and mothballed plants and subtracting added plants each year - cap <- new.magpie(getItems(dim = 1, x = cap_sum),years=as.numeric(colnames(additions)[2:length(additions)]),fill = 0) - # j <- ncol(mothballed) - for (i in add_startyr:(add_endyr-1)) { - cap_add <- additions %>% select(Country,as.character(i+1):as.character(add_endyr)) %>% - mutate(Operating=rowSums(.[-1])) %>% - mutate(Country=toolCountry2isocode(mapping = c("DR Congo" = "COD"), country = Country)) - cap_add <- as.magpie(cap_add[,c("Country","Operating")]) - cap_add <- toolCountryFill(cap_add,verbosity=2,fill=0,no_remove_warning = "KOS") - getItems(cap_add,dim=2) <- i - - cap_ret <- retirements %>% select(Country,as.character(i+1):as.character(add_endyr)) %>% - mutate(Operating=rowSums(.[-1])) %>% - mutate(Country=toolCountry2isocode(mapping = c("DR Congo" = "COD"), country = Country)) - cap_ret <- as.magpie(cap_ret[,c("Country","Operating")]) - cap_ret <- toolCountryFill(cap_ret,verbosity=2,fill=0,no_remove_warning = "KOS") - getItems(cap_ret,dim=2) <- i - - cap[,i,] <- cap_sum[,,"Operating"] - cap_add[,,"Operating"] + cap_ret[,,"Operating"] + cap_moth[,i,"Operating"] + cap_moth[,i,"pre_status"] + cap <- new.magpie(getItems(dim = 1, x = cap_sum), years = as.numeric(colnames(additions)[2:length(additions)]), fill = 0) + + for (i in add_startyr:(add_endyr - 1)) { + cap_add <- additions %>% + select(Country, as.character(i + 1):as.character(add_endyr)) %>% + mutate(Operating = rowSums(.[-1])) %>% + mutate(Country = toolCountry2isocode(mapping = c("DR Congo" = "COD"), country = Country)) + cap_add <- as.magpie(cap_add[, c("Country", "Operating")]) + cap_add <- toolCountryFill(cap_add, verbosity = 2, fill = 0, no_remove_warning = "KOS") + getItems(cap_add, dim = 2) <- i + + cap_ret <- retirements %>% + select(Country, as.character(i + 1):as.character(add_endyr)) %>% + mutate(Operating = rowSums(.[-1])) %>% + mutate(Country = toolCountry2isocode(mapping = c("DR Congo" = "COD"), country = Country)) + cap_ret <- as.magpie(cap_ret[, c("Country", "Operating")]) + cap_ret <- toolCountryFill(cap_ret, verbosity = 2, fill = 0, no_remove_warning = "KOS") + getItems(cap_ret, dim = 2) <- i + + cap[, i, ] <- cap_sum[, , "Operating"] - cap_add[, , "Operating"] + cap_ret[, , "Operating"] + cap_moth[, i, "Operating"] + cap_moth[, i, "pre_status"] } - cap[,add_endyr,] <- cap_sum_oper + cap[, add_endyr, ] <- cap_sum_oper - if (grepl("historical",subtype)) { - return(cap/1000) - }else if (grepl("status",subtype)) { - return(cap_sum/1000) + if (grepl("historical", subtype)) { + return(cap / 1000) + } else if (grepl("status", subtype)) { + return(cap_sum / 1000) } - #Plant-level data detailing capacities, commissioning and retirement dates, location and more. - retire <- suppressWarnings(read_excel(plant_data,sheet=2)) + # Plant-level data detailing capacities, commissioning and retirement dates, location and more. + retire <- suppressWarnings(read_excel(plant_data, sheet = 2)) retire$`Capacity (MW)` <- as.numeric(retire$`Capacity (MW)`) retire$`Planned Retire` <- suppressWarnings(as.numeric(retire$`Planned Retire`)) retire$Country <- toolCountry2isocode(mapping = c("DR Congo" = "COD"), country = retire$Country) - retire <- retire[-which(retire$Country=="KOS"),] - if (present_year!=2020) { - retire <- retire %>% mutate(`Plant Age` = - ifelse(is.na(Year), - NA, - ifelse(grepl("retire",Status,ignore.case=T), - ifelse(is.na(RETIRED), - NA, - RETIRED - Year), - present_year - Year))) + retire <- retire[-which(retire$Country == "KOS"), ] + if (present_year != 2020) { + retire <- retire %>% + mutate( + `Plant Age` = + ifelse(is.na(Year), + NA, + ifelse(grepl("retire", Status, ignore.case = TRUE), + ifelse(is.na(RETIRED), + NA, + RETIRED - Year + ), + present_year - Year + ) + ) + ) } - retAge <- retire %>% select(Country,`Plant Age`,`Capacity (MW)`,Status) %>% - filter(Status %in% c("Retired","retired")) %>% filter(!is.na(`Plant Age`)) %>% filter(`Plant Age` > 0) %>% filter(!is.na(`Capacity (MW)`)) - avgRetAge <- retAge %>% group_by(Country) %>% summarise(Avg_Ret_Age=weighted.mean(`Plant Age`,`Capacity (MW)`)) - retCap <- retAge %>% group_by(Country) %>% summarise(Retired_Cap=sum(`Capacity (MW)`)) - avgRetAge <- avgRetAge[do.call(order,avgRetAge),] - retCap <- retCap[do.call(order,retCap),] - - mavgRetAge <- as.magpie(avgRetAge,spatial=1) - mavgRetAge <- toolCountryFill(mavgRetAge,fill=0,no_remove_warning = "KOS",verbosity=2) - retCap <- as.magpie(retCap,spatial=1) - retCap <- toolCountryFill(retCap,fill=0,no_remove_warning = "KOS",verbosity=2) - regAvgRetAge <- toolAggregate(mavgRetAge,map,weight=retCap) - regAvgRetAge[which(regAvgRetAge==0)] <- mean(regAvgRetAge) - mavgRetAge[getItems(dim = 1, x = mavgRetAge)[mavgRetAge == 0],,] <- as.vector(regAvgRetAge[map$RegionCode[which(map$CountryCode %in% getItems(dim = 1, x = mavgRetAge)[mavgRetAge == 0])],,]) - - if (grepl("lifespans",subtype)) { + retAge <- retire %>% + select(Country, `Plant Age`, `Capacity (MW)`, Status) %>% + filter(Status %in% c("Retired", "retired")) %>% + filter(!is.na(`Plant Age`)) %>% + filter(`Plant Age` > 0) %>% + filter(!is.na(`Capacity (MW)`)) + + avgRetAge <- retAge %>% + group_by(Country) %>% + summarise(Avg_Ret_Age = weighted.mean(`Plant Age`, `Capacity (MW)`)) + retCap <- retAge %>% + group_by(Country) %>% + summarise(Retired_Cap = sum(`Capacity (MW)`)) + avgRetAge <- avgRetAge[do.call(order, avgRetAge), ] + retCap <- retCap[do.call(order, retCap), ] + + mavgRetAge <- as.magpie(avgRetAge, spatial = 1) + mavgRetAge <- toolCountryFill(mavgRetAge, fill = 0, no_remove_warning = "KOS", verbosity = 2) + retCap <- as.magpie(retCap, spatial = 1) + retCap <- toolCountryFill(retCap, fill = 0, no_remove_warning = "KOS", verbosity = 2) + regAvgRetAge <- toolAggregate(mavgRetAge, map, weight = retCap) + regAvgRetAge[which(regAvgRetAge == 0)] <- mean(regAvgRetAge) + mavgRetAge[getItems(dim = 1, x = mavgRetAge)[mavgRetAge == 0], , ] <- as.vector(regAvgRetAge[map$RegionCode[which(map$CountryCode %in% getItems(dim = 1, x = mavgRetAge)[mavgRetAge == 0])], , ]) + + if (grepl("lifespans", subtype)) { return(mavgRetAge) - }else if (grepl("meanAge",subtype)) { - meanAge <- retire %>% select(Country,`Plant Age`,`Capacity (MW)`,Status) %>% - filter(Status %in% c("Operating","operating") & !is.na(`Capacity (MW)`) & !is.na(`Plant Age`)) - meanAge_c <- meanAge %>% group_by(Country) %>% summarise(meanAge=weighted.mean(`Plant Age`,`Capacity (MW)`)) - meanAge_c <- toolCountryFill(as.magpie(meanAge_c,spatial=1),fill=0) - capWeight <- meanAge %>% group_by(Country) %>% summarise(Capacity=sum(`Capacity (MW)`)) - capWeight <- toolCountryFill(as.magpie(capWeight,spatial=1),fill=0) - return(toolAggregate(meanAge_c,map,capWeight)) + } else if (grepl("meanAge", subtype)) { + meanAge <- retire %>% + select(Country, `Plant Age`, `Capacity (MW)`, Status) %>% + filter(Status %in% c("Operating", "operating") & !is.na(`Capacity (MW)`) & !is.na(`Plant Age`)) + meanAge_c <- meanAge %>% + group_by(Country) %>% + summarise(meanAge = weighted.mean(`Plant Age`, `Capacity (MW)`)) + meanAge_c <- toolCountryFill(as.magpie(meanAge_c, spatial = 1), fill = 0, verbosity = 2) + capWeight <- meanAge %>% + group_by(Country) %>% + summarise(Capacity = sum(`Capacity (MW)`)) + capWeight <- toolCountryFill(as.magpie(capWeight, spatial = 1), fill = 0, verbosity = 2) + return(toolAggregate(meanAge_c, map, capWeight)) } - # Return national average lifespans to calculate early retirement adjustment factors - if (grepl("early_retire",subtype)) { + # Return national average lifespans to calculate early retirement adjustment factors + if (grepl("early_retire", subtype)) { retired <- retire %>% - select(Country,`Plant Age`,`Capacity (MW)`,RETIRED) %>% - left_join(avgRetAge,by="Country") - #Sum up capacity retired in each country in each year 2000-2020 + select(Country, `Plant Age`, `Capacity (MW)`, RETIRED) %>% + left_join(avgRetAge, by = "Country") + # Sum up capacity retired in each country in each year 2000-2020 early_ret <- retired %>% filter(!is.na(RETIRED) & !is.na(`Plant Age`)) %>% filter(`Plant Age` < Avg_Ret_Age) %>% - group_by(Country,.add=TRUE) %>% - group_by(RETIRED,.add=TRUE) %>% - summarise(Retired_cap=sum(`Capacity (MW)`)) - early_ret <- as.magpie(early_ret,spatial=1,temporal=2) - early_ret <- toolCountryFill(early_ret,fill=0,no_remove_warning = "KOS",verbosity = 0) - ret_rate <- new.magpie(getItems(dim = 1, x = mavgRetAge),seq(2000,2015,5),names="Early_Retirement",fill=0) - for (t in seq(2000,2015,5)) { - ret_rate[,t,] <- dimSums(early_ret[,t:(t+5),],dim=2)/cap[,t,] + group_by(Country, .add = TRUE) %>% + group_by(RETIRED, .add = TRUE) %>% + summarise(Retired_cap = sum(`Capacity (MW)`)) + early_ret <- as.magpie(early_ret, spatial = 1, temporal = 2) + early_ret <- toolCountryFill(early_ret, fill = 0, no_remove_warning = "KOS", verbosity = 0) + ret_rate <- new.magpie(getItems(dim = 1, x = mavgRetAge), seq(2000, 2015, 5), names = "Early_Retirement", fill = 0) + for (t in seq(2000, 2015, 5)) { + ret_rate[, t, ] <- dimSums(early_ret[, t:(t + 5), ], dim = 2) / cap[, t, ] } ret_rate <- replace_non_finite(ret_rate) - max_ret <- new.magpie(getItems(dim = 1, x = ret_rate),NULL,names="Max_Early_Retirement",fill=0) + max_ret <- new.magpie(getItems(dim = 1, x = ret_rate), NULL, names = "Max_Early_Retirement", fill = 0) for (reg in getItems(dim = 1, x = ret_rate)) { - max_ret[reg,,] <- max(ret_rate[reg,,]) + max_ret[reg, , ] <- max(ret_rate[reg, , ]) } return(max_ret) } - #Use the national lifespans to derive scenarios of 2025 coal capacity - avgRetAge <- data.frame(Country=getItems(dim = 1, x = mavgRetAge),Avg_Ret_Age=array(mavgRetAge)) - retire <- left_join(retire,avgRetAge,by="Country") + # Use the national lifespans to derive scenarios of 2025 coal capacity + avgRetAge <- data.frame(Country = getItems(dim = 1, x = mavgRetAge), Avg_Ret_Age = array(mavgRetAge)) + retire <- left_join(retire, avgRetAge, by = "Country") - #Neutral COVID recovery scenario: Countries maintain their historical average lifespans - retireBAU <- retire %>% select(Country,`Planned Retire`,`Plant Age`,`Capacity (MW)`,Status,Avg_Ret_Age) %>% - filter(Status %in% c("Operating","operating")) %>% - filter(`Planned Retire`<=2028 | `Plant Age` >= (Avg_Ret_Age-5)) %>% + # Neutral COVID recovery scenario: Countries maintain their historical average lifespans + retireBAU <- retire %>% + select(Country, `Planned Retire`, `Plant Age`, `Capacity (MW)`, Status, Avg_Ret_Age) %>% + filter(Status %in% c("Operating", "operating")) %>% + filter(`Planned Retire` <= 2028 | `Plant Age` >= (Avg_Ret_Age - 5)) %>% filter(!is.na(`Capacity (MW)`)) %>% - group_by(Country) %>% summarise(Retiring_Cap=sum(`Capacity (MW)`)) + group_by(Country) %>% + summarise(Retiring_Cap = sum(`Capacity (MW)`)) retireBAU$Retiring_Cap[which(is.na(retireBAU$Retiring_Cap))] <- 0 - retireBAU <- as.magpie(retireBAU,spatial=1) - retireBAU <- toolCountryFill(retireBAU,fill=0,no_remove_warning = "KOS",verbosity=2) - - #Brown COVID recovery scenario: Countries extend their average lifespans by 5 years - retireBrown <- retire %>% select(Country,`Planned Retire`,`Plant Age`,`Capacity (MW)`,Status,Avg_Ret_Age) %>% - filter(Status %in% c("Operating","operating")) %>% - filter(`Planned Retire`<=2028 | `Plant Age` >= (Avg_Ret_Age)) %>% + retireBAU <- as.magpie(retireBAU, spatial = 1) + retireBAU <- toolCountryFill(retireBAU, fill = 0, no_remove_warning = "KOS", verbosity = 2) + + # Brown COVID recovery scenario: Countries extend their average lifespans by 5 years + retireBrown <- retire %>% + select(Country, `Planned Retire`, `Plant Age`, `Capacity (MW)`, Status, Avg_Ret_Age) %>% + filter(Status %in% c("Operating", "operating")) %>% + filter(`Planned Retire` <= 2028 | `Plant Age` >= (Avg_Ret_Age)) %>% filter(!is.na(`Capacity (MW)`)) %>% - group_by(Country) %>% summarise(Retiring_Cap=sum(`Capacity (MW)`)) + group_by(Country) %>% + summarise(Retiring_Cap = sum(`Capacity (MW)`)) retireBrown$Retiring_Cap[which(is.na(retireBrown$Retiring_Cap))] <- 0 - retireBrown <- as.magpie(retireBrown,spatial=1) - retireBrown <- toolCountryFill(retireBrown,fill=0,no_remove_warning = "KOS",verbosity=2) - - #Green COVID recovery scenario: Countries reduce historical average lifespans by 5 years - retireGreen <- retire %>% select(Country,`Planned Retire`,`Plant Age`,`Capacity (MW)`,Status,Avg_Ret_Age) %>% - filter(Status %in% c("Operating","operating")) %>% - filter(`Planned Retire`<=2028 | `Plant Age` >= (Avg_Ret_Age-10)) %>% + retireBrown <- as.magpie(retireBrown, spatial = 1) + retireBrown <- toolCountryFill(retireBrown, fill = 0, no_remove_warning = "KOS", verbosity = 2) + + # Green COVID recovery scenario: Countries reduce historical average lifespans by 5 years + retireGreen <- retire %>% + select(Country, `Planned Retire`, `Plant Age`, `Capacity (MW)`, Status, Avg_Ret_Age) %>% + filter(Status %in% c("Operating", "operating")) %>% + filter(`Planned Retire` <= 2028 | `Plant Age` >= (Avg_Ret_Age - 10)) %>% filter(!is.na(`Capacity (MW)`)) %>% - group_by(Country) %>% summarise(Retiring_Cap=sum(`Capacity (MW)`)) + group_by(Country) %>% + summarise(Retiring_Cap = sum(`Capacity (MW)`)) retireGreen$Retiring_Cap[which(is.na(retireGreen$Retiring_Cap))] <- 0 - retireGreen <- as.magpie(retireGreen,spatial=1) - retireGreen <- toolCountryFill(retireGreen,fill=0,no_remove_warning = "KOS",verbosity=2) + retireGreen <- as.magpie(retireGreen, spatial = 1) + retireGreen <- toolCountryFill(retireGreen, fill = 0, no_remove_warning = "KOS", verbosity = 2) - #Literature norm scenario: Popular choice in literature has been to use a globally uniform 40-yr lifespan - retireNorm <- retire %>% select(Country,`Planned Retire`,`Plant Age`,`Capacity (MW)`,Status,Avg_Ret_Age) %>% - filter(Status %in% c("Operating","operating")) %>% + # Literature norm scenario: Popular choice in literature has been to use a globally uniform 40-yr lifespan + retireNorm <- retire %>% + select(Country, `Planned Retire`, `Plant Age`, `Capacity (MW)`, Status, Avg_Ret_Age) %>% + filter(Status %in% c("Operating", "operating")) %>% filter(`Plant Age` >= 35) %>% filter(!is.na(`Capacity (MW)`)) %>% - group_by(Country) %>% summarise(Retiring_Cap=sum(`Capacity (MW)`)) + group_by(Country) %>% + summarise(Retiring_Cap = sum(`Capacity (MW)`)) retireNorm$Retiring_Cap[which(is.na(retireNorm$Retiring_Cap))] <- 0 - retireNorm <- as.magpie(retireNorm,spatial=1) - retireNorm <- toolCountryFill(retireNorm,fill=0,no_remove_warning = "KOS",verbosity=2) - - - #Relevant regional mappings and country classifications - #Current members of PPCA - PPCAmap <- toolGetMapping("regionmappingPPCA.csv",type = "regional") - #Current OECD members - OECDmap <- toolGetMapping("regionmappingOECD.csv",type = "regional") - ppca <- PPCAmap$CountryCode[which(PPCAmap$RegionCode=="PPCA")] - oecd <- OECDmap$CountryCode[which(OECDmap$RegionCode=="OECD")] - EU27 <- map$CountryCode[which(map$RegionCode=="EUR")] - nonoecd <- OECDmap$CountryCode[which(OECDmap$RegionCode=="NON")] - #The PPCA stipulates that OECD and EU members must phase out coal power by 2030 + retireNorm <- as.magpie(retireNorm, spatial = 1) + retireNorm <- toolCountryFill(retireNorm, fill = 0, no_remove_warning = "KOS", verbosity = 2) + + + # Relevant regional mappings and country classifications + # Current members of PPCA + PPCAmap <- toolGetMapping("regionmappingPPCA.csv", type = "regional", where = "mappingfolder") + # Current OECD members + OECDmap <- toolGetMapping("regionmappingOECD.csv", type = "regional", where = "mappingfolder") + ppca <- PPCAmap$CountryCode[which(PPCAmap$RegionCode == "PPCA")] + oecd <- OECDmap$CountryCode[which(OECDmap$RegionCode == "OECD")] + EU27 <- map$CountryCode[which(map$RegionCode == "EUR")] + # The PPCA stipulates that OECD and EU members must phase out coal power by 2030 oecdPPCA <- ppca[which(ppca %in% oecd | ppca %in% EU27)] - #While non-OECD members must phase out coal power by 2050 + # While non-OECD members must phase out coal power by 2050 nonOECDppca <- ppca[which(!(ppca %in% oecdPPCA))] - #There are several countries which have explicit plans to abandon coal power in their COVID recovery packages - greenNations <- c(EU27[-which(EU27=="POL")][-which(EU27 %in% ppca)],"EGY","AUS","KOR","CHL") - if (subtype!="PEGASOS") greenNations <- c(greenNations,"BGD","PAK","PHL","VNM") + # There are several countries which have explicit plans to abandon coal power in their COVID recovery packages + greenNations <- c(EU27[-which(EU27 == "POL")][-which(EU27 %in% ppca)], "EGY", "AUS", "KOR", "CHL") + if (subtype != "PEGASOS") greenNations <- c(greenNations, "BGD", "PAK", "PHL", "VNM") ########################### ### ANNUAL PLANT STATUS ### ########################### # Remove any plants with unknown (NA) capacity from plant status data frame - plant_status <- plant_status %>% filter(!is.na(MW)) + plant_status <- plant_status %>% + filter(!is.na(MW)) - tran <- data.frame(Country=unique(plant_status$Country),shelved=0,she2she=0,she2can=0,she2oper=0,she2ann=0,she2pre=0,pre2she=0,pre2con=0, - she2perm=0,she2con=0,newcon=0,con2she=0,con2she2oper=0,con2she2con=0,con2she2can=0,con2can=0,perm2she=0,perm2con=0, - con2oper=0,con2she2she=0,plan2she=0,ann=0,ann2oper=0,ann2can=0,ann2she=0,ann2con=0,pre=0,pre2oper=0,pre2can=0,perm=0, - perm2oper=0,perm2can=0,moth=0,moth2ret=0,moth2oper=0) + tran <- data.frame(Country = unique(plant_status$Country), shelved = 0, she2she = 0, she2can = 0, she2oper = 0, she2ann = 0, she2pre = 0, pre2she = 0, pre2con = 0, + she2perm = 0, she2con = 0, newcon = 0, con2she = 0, con2she2oper = 0, con2she2con = 0, con2she2can = 0, con2can = 0, perm2she = 0, perm2con = 0, + con2oper = 0, con2she2she = 0, plan2she = 0, ann = 0, ann2oper = 0, ann2can = 0, ann2she = 0, ann2con = 0, pre = 0, pre2oper = 0, pre2can = 0, perm = 0, + perm2oper = 0, perm2can = 0, moth = 0, moth2ret = 0, moth2oper = 0) for (i in 1:nrow(plant_status)) { j <- ncol(plant_status) - if (plant_status[i,j]=="XXX") { - plant_status[i,which(plant_status[i,]=="XXX")] <- "Announced" + if (plant_status[i, j] == "XXX") { + plant_status[i, which(plant_status[i, ] == "XXX")] <- "Announced" } while (j > latest_col) { - if (grepl("She",plant_status[i,j])) { - if (j==ncol(plant_status) || !any(grepl("She",plant_status[i,j:ncol(plant_status)]))) { - tran$shelved[which(tran$Country==plant_status$Country[i])] <- tran$shelved[which(tran$Country==plant_status$Country[i])] + plant_status$MW[i] - if (grepl("Can",plant_status[i,latest_col])) { - tran$she2can[which(tran$Country==plant_status$Country[i])]<- tran$she2can[which(tran$Country==plant_status$Country[i])] + plant_status$MW[i] - }else if (grepl("She",plant_status[i,latest_col])) { - tran$she2she[which(tran$Country==plant_status$Country[i])]<- tran$she2she[which(tran$Country==plant_status$Country[i])] + plant_status$MW[i] - }else if (grepl("Oper",plant_status[i,latest_col])) { - tran$she2oper[which(tran$Country==plant_status$Country[i])]<- tran$she2oper[which(tran$Country==plant_status$Country[i])] + plant_status$MW[i] - }else if (grepl("Ann",plant_status[i,latest_col])) { - tran$she2ann[which(tran$Country==plant_status$Country[i])]<- tran$she2ann[which(tran$Country==plant_status$Country[i])] + plant_status$MW[i] - }else if (grepl("Pre",plant_status[i,latest_col])) { - tran$she2pre[which(tran$Country==plant_status$Country[i])]<- tran$she2pre[which(tran$Country==plant_status$Country[i])] + plant_status$MW[i] - }else if (grepl("Perm",plant_status[i,latest_col])) { - tran$she2perm[which(tran$Country==plant_status$Country[i])]<- tran$she2perm[which(tran$Country==plant_status$Country[i])] + plant_status$MW[i] - }else if (grepl("Con",plant_status[i,latest_col])) { - tran$she2con[which(tran$Country==plant_status$Country[i])]<- tran$she2con[which(tran$Country==plant_status$Country[i])] + plant_status$MW[i] + if (grepl("She", plant_status[i, j])) { + if (j == ncol(plant_status) || !any(grepl("She", plant_status[i, j:ncol(plant_status)]))) { + tran$shelved[which(tran$Country == plant_status$Country[i])] <- tran$shelved[which(tran$Country == plant_status$Country[i])] + plant_status$MW[i] + if (grepl("Can", plant_status[i, latest_col])) { + tran$she2can[which(tran$Country == plant_status$Country[i])] <- tran$she2can[which(tran$Country == plant_status$Country[i])] + plant_status$MW[i] + } else if (grepl("She", plant_status[i, latest_col])) { + tran$she2she[which(tran$Country == plant_status$Country[i])] <- tran$she2she[which(tran$Country == plant_status$Country[i])] + plant_status$MW[i] + } else if (grepl("Oper", plant_status[i, latest_col])) { + tran$she2oper[which(tran$Country == plant_status$Country[i])] <- tran$she2oper[which(tran$Country == plant_status$Country[i])] + plant_status$MW[i] + } else if (grepl("Ann", plant_status[i, latest_col])) { + tran$she2ann[which(tran$Country == plant_status$Country[i])] <- tran$she2ann[which(tran$Country == plant_status$Country[i])] + plant_status$MW[i] + } else if (grepl("Pre", plant_status[i, latest_col])) { + tran$she2pre[which(tran$Country == plant_status$Country[i])] <- tran$she2pre[which(tran$Country == plant_status$Country[i])] + plant_status$MW[i] + } else if (grepl("Perm", plant_status[i, latest_col])) { + tran$she2perm[which(tran$Country == plant_status$Country[i])] <- tran$she2perm[which(tran$Country == plant_status$Country[i])] + plant_status$MW[i] + } else if (grepl("Con", plant_status[i, latest_col])) { + tran$she2con[which(tran$Country == plant_status$Country[i])] <- tran$she2con[which(tran$Country == plant_status$Country[i])] + plant_status$MW[i] } } - }else if (grepl("Con",plant_status[i,j])) { - if (j==ncol(plant_status) || !any(grepl("Con",plant_status[i,(j+1):ncol(plant_status)]))) { - tran$newcon[which(tran$Country==plant_status$Country[i])] <- tran$newcon[which(tran$Country==plant_status$Country[i])] + plant_status$MW[i] - if (grepl("Can",plant_status[i,latest_col])) { - tran$con2can[which(tran$Country==plant_status$Country[i])] <- tran$con2can[which(tran$Country==plant_status$Country[i])] + plant_status$MW[i] - }else if (grepl("She",plant_status[i,latest_col])) { - tran$con2she2she[which(tran$Country==plant_status$Country[i])]<- tran$con2she2she[which(tran$Country==plant_status$Country[i])] + plant_status$MW[i] - }else if (grepl("Oper",plant_status[i,latest_col])) { - tran$con2oper[which(tran$Country==plant_status$Country[i])]<- tran$con2oper[which(tran$Country==plant_status$Country[i])] + plant_status$MW[i] - }else if (grepl("Con",plant_status[i,latest_col])) { - tran$con2con[which(tran$Country==plant_status$Country[i])]<- tran$con2con[which(tran$Country==plant_status$Country[i])] + plant_status$MW[i] + } else if (grepl("Con", plant_status[i, j])) { + if (j == ncol(plant_status) || !any(grepl("Con", plant_status[i, (j + 1):ncol(plant_status)]))) { + tran$newcon[which(tran$Country == plant_status$Country[i])] <- tran$newcon[which(tran$Country == plant_status$Country[i])] + plant_status$MW[i] + if (grepl("Can", plant_status[i, latest_col])) { + tran$con2can[which(tran$Country == plant_status$Country[i])] <- tran$con2can[which(tran$Country == plant_status$Country[i])] + plant_status$MW[i] + } else if (grepl("She", plant_status[i, latest_col])) { + tran$con2she2she[which(tran$Country == plant_status$Country[i])] <- tran$con2she2she[which(tran$Country == plant_status$Country[i])] + plant_status$MW[i] + } else if (grepl("Oper", plant_status[i, latest_col])) { + tran$con2oper[which(tran$Country == plant_status$Country[i])] <- tran$con2oper[which(tran$Country == plant_status$Country[i])] + plant_status$MW[i] + } else if (grepl("Con", plant_status[i, latest_col])) { + tran$con2con[which(tran$Country == plant_status$Country[i])] <- tran$con2con[which(tran$Country == plant_status$Country[i])] + plant_status$MW[i] } } - }else if (grepl("Ann",plant_status[i,j])) { - if (j==ncol(plant_status) || !any(grepl("Ann",plant_status[i,(j+1):ncol(plant_status)]))) { - tran$ann[which(tran$Country==plant_status$Country[i])] <- tran$ann[which(tran$Country==plant_status$Country[i])] + plant_status$MW[i] - if (grepl("Can",plant_status[i,latest_col])) { - tran$ann2can[which(tran$Country==plant_status$Country[i])] <- tran$ann2can[which(tran$Country==plant_status$Country[i])] + plant_status$MW[i] - }else if (grepl("She",plant_status[i,latest_col])) { - tran$ann2she[which(tran$Country==plant_status$Country[i])]<- tran$ann2she[which(tran$Country==plant_status$Country[i])] + plant_status$MW[i] - }else if (grepl("Oper",plant_status[i,latest_col])) { - tran$ann2oper[which(tran$Country==plant_status$Country[i])]<- tran$ann2oper[which(tran$Country==plant_status$Country[i])] + plant_status$MW[i] - }else if (grepl("Con",plant_status[i,latest_col])) { - tran$ann2con[which(tran$Country==plant_status$Country[i])]<- tran$ann2con[which(tran$Country==plant_status$Country[i])] + plant_status$MW[i] + } else if (grepl("Ann", plant_status[i, j])) { + if (j == ncol(plant_status) || !any(grepl("Ann", plant_status[i, (j + 1):ncol(plant_status)]))) { + tran$ann[which(tran$Country == plant_status$Country[i])] <- tran$ann[which(tran$Country == plant_status$Country[i])] + plant_status$MW[i] + if (grepl("Can", plant_status[i, latest_col])) { + tran$ann2can[which(tran$Country == plant_status$Country[i])] <- tran$ann2can[which(tran$Country == plant_status$Country[i])] + plant_status$MW[i] + } else if (grepl("She", plant_status[i, latest_col])) { + tran$ann2she[which(tran$Country == plant_status$Country[i])] <- tran$ann2she[which(tran$Country == plant_status$Country[i])] + plant_status$MW[i] + } else if (grepl("Oper", plant_status[i, latest_col])) { + tran$ann2oper[which(tran$Country == plant_status$Country[i])] <- tran$ann2oper[which(tran$Country == plant_status$Country[i])] + plant_status$MW[i] + } else if (grepl("Con", plant_status[i, latest_col])) { + tran$ann2con[which(tran$Country == plant_status$Country[i])] <- tran$ann2con[which(tran$Country == plant_status$Country[i])] + plant_status$MW[i] } } - }else if (grepl("Pre",plant_status[i,j])) { - if (j==ncol(plant_status) || !any(grepl("Pre",plant_status[i,(j+1):ncol(plant_status)]))) { - tran$pre[which(tran$Country==plant_status$Country[i])] <- tran$pre[which(tran$Country==plant_status$Country[i])] + plant_status$MW[i] - if (grepl("Can",plant_status[i,latest_col])) { - tran$pre2can[which(tran$Country==plant_status$Country[i])] <- tran$pre2can[which(tran$Country==plant_status$Country[i])] + plant_status$MW[i] - }else if (grepl("She",plant_status[i,latest_col])) { - tran$pre2she[which(tran$Country==plant_status$Country[i])]<- tran$pre2she[which(tran$Country==plant_status$Country[i])] + plant_status$MW[i] - }else if (grepl("Oper",plant_status[i,latest_col])) { - tran$pre2oper[which(tran$Country==plant_status$Country[i])]<- tran$pre2oper[which(tran$Country==plant_status$Country[i])] + plant_status$MW[i] - }else if (grepl("Con",plant_status[i,latest_col])) { - tran$pre2con[which(tran$Country==plant_status$Country[i])]<- tran$pre2con[which(tran$Country==plant_status$Country[i])] + plant_status$MW[i] + } else if (grepl("Pre", plant_status[i, j])) { + if (j == ncol(plant_status) || !any(grepl("Pre", plant_status[i, (j + 1):ncol(plant_status)]))) { + tran$pre[which(tran$Country == plant_status$Country[i])] <- tran$pre[which(tran$Country == plant_status$Country[i])] + plant_status$MW[i] + if (grepl("Can", plant_status[i, latest_col])) { + tran$pre2can[which(tran$Country == plant_status$Country[i])] <- tran$pre2can[which(tran$Country == plant_status$Country[i])] + plant_status$MW[i] + } else if (grepl("She", plant_status[i, latest_col])) { + tran$pre2she[which(tran$Country == plant_status$Country[i])] <- tran$pre2she[which(tran$Country == plant_status$Country[i])] + plant_status$MW[i] + } else if (grepl("Oper", plant_status[i, latest_col])) { + tran$pre2oper[which(tran$Country == plant_status$Country[i])] <- tran$pre2oper[which(tran$Country == plant_status$Country[i])] + plant_status$MW[i] + } else if (grepl("Con", plant_status[i, latest_col])) { + tran$pre2con[which(tran$Country == plant_status$Country[i])] <- tran$pre2con[which(tran$Country == plant_status$Country[i])] + plant_status$MW[i] } } - }else if (grepl("Perm",plant_status[i,j])) { - if (j==ncol(plant_status) || !any(grepl("Perm",plant_status[i,(j+1):ncol(plant_status)]))) { - tran$perm[which(tran$Country==plant_status$Country[i])] <- tran$perm[which(tran$Country==plant_status$Country[i])] + plant_status$MW[i] - if (grepl("Can",plant_status[i,latest_col])) { - tran$perm2can[which(tran$Country==plant_status$Country[i])] <- tran$perm2can[which(tran$Country==plant_status$Country[i])] + plant_status$MW[i] - }else if (grepl("She",plant_status[i,latest_col])) { - tran$perm2she[which(tran$Country==plant_status$Country[i])]<- tran$perm2she[which(tran$Country==plant_status$Country[i])] + plant_status$MW[i] - }else if (grepl("Oper",plant_status[i,latest_col])) { - tran$perm2oper[which(tran$Country==plant_status$Country[i])]<- tran$perm2oper[which(tran$Country==plant_status$Country[i])] + plant_status$MW[i] - }else if (grepl("Con",plant_status[i,latest_col])) { - tran$perm2con[which(tran$Country==plant_status$Country[i])]<- tran$perm2con[which(tran$Country==plant_status$Country[i])] + plant_status$MW[i] + } else if (grepl("Perm", plant_status[i, j])) { + if (j == ncol(plant_status) || !any(grepl("Perm", plant_status[i, (j + 1):ncol(plant_status)]))) { + tran$perm[which(tran$Country == plant_status$Country[i])] <- tran$perm[which(tran$Country == plant_status$Country[i])] + plant_status$MW[i] + if (grepl("Can", plant_status[i, latest_col])) { + tran$perm2can[which(tran$Country == plant_status$Country[i])] <- tran$perm2can[which(tran$Country == plant_status$Country[i])] + plant_status$MW[i] + } else if (grepl("She", plant_status[i, latest_col])) { + tran$perm2she[which(tran$Country == plant_status$Country[i])] <- tran$perm2she[which(tran$Country == plant_status$Country[i])] + plant_status$MW[i] + } else if (grepl("Oper", plant_status[i, latest_col])) { + tran$perm2oper[which(tran$Country == plant_status$Country[i])] <- tran$perm2oper[which(tran$Country == plant_status$Country[i])] + plant_status$MW[i] + } else if (grepl("Con", plant_status[i, latest_col])) { + tran$perm2con[which(tran$Country == plant_status$Country[i])] <- tran$perm2con[which(tran$Country == plant_status$Country[i])] + plant_status$MW[i] } } - }else if (grepl("Moth",plant_status[i,j])) { - if (j==ncol(plant_status) || !any(grepl("Moth",plant_status[i,(j+1):ncol(plant_status)]))) { - tran$moth[which(tran$Country==plant_status$Country[i])] <- tran$moth[which(tran$Country==plant_status$Country[i])] + plant_status$MW[i] - if (grepl("Ret",plant_status[i,latest_col])) { - tran$moth2ret[which(tran$Country==plant_status$Country[i])] <- tran$moth2ret[which(tran$Country==plant_status$Country[i])] + plant_status$MW[i] - }else if (any(grepl("Oper",plant_status[i,latest_col:(j-1)]))) { - tran$moth2oper[which(tran$Country==plant_status$Country[i])] <- tran$moth2oper[which(tran$Country==plant_status$Country[i])] + plant_status$MW[i] + } else if (grepl("Moth", plant_status[i, j])) { + if (j == ncol(plant_status) || !any(grepl("Moth", plant_status[i, (j + 1):ncol(plant_status)]))) { + tran$moth[which(tran$Country == plant_status$Country[i])] <- tran$moth[which(tran$Country == plant_status$Country[i])] + plant_status$MW[i] + if (grepl("Ret", plant_status[i, latest_col])) { + tran$moth2ret[which(tran$Country == plant_status$Country[i])] <- tran$moth2ret[which(tran$Country == plant_status$Country[i])] + plant_status$MW[i] + } else if (any(grepl("Oper", plant_status[i, latest_col:(j - 1)]))) { + tran$moth2oper[which(tran$Country == plant_status$Country[i])] <- tran$moth2oper[which(tran$Country == plant_status$Country[i])] + plant_status$MW[i] } } } - j <- j-1 - if (grepl("She",plant_status[i,j])) { - if (plant_status[i,j+1]=="Con") { - tran$con2she[which(tran$Country==plant_status$Country[i])]<- tran$con2she[which(tran$Country==plant_status$Country[i])] + plant_status$MW[i] - if (grepl("Oper",plant_status[i,latest_col])) { - tran$con2she2oper[which(tran$Country==plant_status$Country[i])] <- tran$con2she2oper[which(tran$Country==plant_status$Country[i])] + plant_status$MW[i] - }else if (grepl("Con",plant_status[i,latest_col])) { - tran$con2she2con[which(tran$Country==plant_status$Country[i])] <- tran$con2she2con[which(tran$Country==plant_status$Country[i])] + plant_status$MW[i] - }else if (grepl("Can",plant_status[i,latest_col])) { - tran$con2she2can[which(tran$Country==plant_status$Country[i])] <- tran$con2she2can[which(tran$Country==plant_status$Country[i])] + plant_status$MW[i] + j <- j - 1 + if (grepl("She", plant_status[i, j])) { + if (plant_status[i, j + 1] == "Con") { + tran$con2she[which(tran$Country == plant_status$Country[i])] <- tran$con2she[which(tran$Country == plant_status$Country[i])] + plant_status$MW[i] + if (grepl("Oper", plant_status[i, latest_col])) { + tran$con2she2oper[which(tran$Country == plant_status$Country[i])] <- tran$con2she2oper[which(tran$Country == plant_status$Country[i])] + plant_status$MW[i] + } else if (grepl("Con", plant_status[i, latest_col])) { + tran$con2she2con[which(tran$Country == plant_status$Country[i])] <- tran$con2she2con[which(tran$Country == plant_status$Country[i])] + plant_status$MW[i] + } else if (grepl("Can", plant_status[i, latest_col])) { + tran$con2she2can[which(tran$Country == plant_status$Country[i])] <- tran$con2she2can[which(tran$Country == plant_status$Country[i])] + plant_status$MW[i] } - }else if (grepl("Ann",plant_status[i,j+1]) | grepl("Pre",plant_status[i,j+1]) | grepl("Perm",plant_status[i,j+1])) { - tran$plan2she[which(tran$Country==plant_status$Country[i])] <- tran$plan2she[which(tran$Country==plant_status$Country[i])] + plant_status$MW[i] + } else if (grepl("Ann", plant_status[i, j + 1]) || grepl("Pre", plant_status[i, j + 1]) || grepl("Perm", plant_status[i, j + 1])) { + tran$plan2she[which(tran$Country == plant_status$Country[i])] <- tran$plan2she[which(tran$Country == plant_status$Country[i])] + plant_status$MW[i] } } } } - tran <- tran[-which(tran$Country=="Kosovo"),] + tran <- tran[-which(tran$Country == "Kosovo"), ] - mtran <- as.magpie(tran,spatial=1) + mtran <- as.magpie(tran, spatial = 1) getYears(mtran) <- "y2020" mtran <- setItems(dim = 1, x = mtran, value = toolCountry2isocode(mapping = c("DR Congo" = "COD"), country = getItems(dim = 1, x = mtran))) - mtran <- toolCountryFill(mtran,fill=0,verbosity=2) + mtran <- toolCountryFill(mtran, fill = 0, verbosity = 2) # Combined cancellation + shelving rates of each project phase, to be used for completion rate calculation - can_she_rate <- new.magpie(getItems(dim = 1, x = mtran),getYears(mtran),getNames(mtran)[which(!grepl("2",getNames(mtran)) & getNames(mtran)!="moth")],fill=NA) + can_she_rate <- new.magpie(getItems(dim = 1, x = mtran), getYears(mtran), getNames(mtran)[which(!grepl("2", getNames(mtran)) & getNames(mtran) != "moth")], fill = NA) # Shelving rate of projects in each phase - she_rate <- new.magpie(getItems(dim = 1, x = mtran),getYears(mtran),getNames(can_she_rate),fill=NA) + she_rate <- new.magpie(getItems(dim = 1, x = mtran), getYears(mtran), getNames(can_she_rate), fill = NA) # Cancellation rate of projects in the shelving phase - can_rate <- new.magpie(getItems(dim = 1, x = mtran),getYears(mtran),"shelved",fill=NA) + can_rate <- new.magpie(getItems(dim = 1, x = mtran), getYears(mtran), "shelved", fill = NA) - reg_can_rate <- new.magpie(getItems(dim = 1, x = regAvgRetAge),getYears(mtran),getNames(can_rate)) - reg_can_she_rate <- new.magpie(getItems(dim = 1, x = regAvgRetAge),getYears(mtran),getNames(can_she_rate)) - reg_she_rate <- new.magpie(getItems(dim = 1, x = regAvgRetAge),getYears(mtran),getNames(she_rate)) + reg_can_rate <- new.magpie(getItems(dim = 1, x = regAvgRetAge), getYears(mtran), getNames(can_rate)) + reg_can_she_rate <- new.magpie(getItems(dim = 1, x = regAvgRetAge), getYears(mtran), getNames(can_she_rate)) + reg_she_rate <- new.magpie(getItems(dim = 1, x = regAvgRetAge), getYears(mtran), getNames(she_rate)) for (phase in getNames(can_she_rate)) { - nonzero_countries <- getItems(dim = 1, x = mtran)[which(mtran[,,phase]!=0)] - zero_countries <- getItems(dim = 1, x = mtran)[which(mtran[,,phase]==0)] - if (phase=="newcon") { - can_she_rate[,,phase] <- (mtran[,,"con2can"] + mtran[,,"con2she2she"])/mtran[,,"newcon"] - she_rate[,,phase] <- mtran[,,"con2she2she"]/mtran[,,"newcon"] - }else if (phase=="shelved") { - can_she_rate[,,phase] <- (mtran[,,"she2can"] + mtran[,,"she2she"])/mtran[,,phase] - she_rate[,,phase] <- mtran[,,"she2she"]/mtran[,,"shelved"] - can_rate[nonzero_countries,,phase] <- mtran[nonzero_countries,,"she2can"]/mtran[nonzero_countries,,"shelved"] - #Calculate global mean rates - glo_can_rate <- weighted.mean(can_rate[nonzero_countries,,phase],mtran[nonzero_countries,,phase]) - #Calculate regional rates - tmp <- toolAggregate(can_rate[nonzero_countries,,phase],rel=map[which(map$CountryCode %in% nonzero_countries),],mtran[nonzero_countries,,phase]) - #For regions which had zero projects in a certain phase, assign the global weighted mean - reg_can_rate <- suppressWarnings(mbind(tmp,new.magpie(getItems(dim = 1, x = reg_can_rate)[which(!(getItems(dim = 1, x = reg_can_rate)) %in% getItems(dim = 1, x = tmp))],getYears(can_rate),phase,glo_can_rate))) - #Assign regional rates to countries without projects in the present phase - can_rate[zero_countries,,phase] <- as.numeric(reg_can_rate[map$RegionCode[which(map$CountryCode %in% zero_countries)],,phase]) - - }else { - can_she_rate[,,phase] <- (mtran[,,paste0(phase,"2can")] + mtran[,,paste0(phase,"2she")])/mtran[,,phase] - she_rate[,,phase] <- mtran[,,paste0(phase,"2she")]/mtran[,,phase] + nonzero_countries <- getItems(dim = 1, x = mtran)[which(mtran[, , phase] != 0)] + zero_countries <- getItems(dim = 1, x = mtran)[which(mtran[, , phase] == 0)] + if (phase == "newcon") { + can_she_rate[, , phase] <- (mtran[, , "con2can"] + mtran[, , "con2she2she"]) / mtran[, , "newcon"] + she_rate[, , phase] <- mtran[, , "con2she2she"] / mtran[, , "newcon"] + } else if (phase == "shelved") { + can_she_rate[, , phase] <- (mtran[, , "she2can"] + mtran[, , "she2she"]) / mtran[, , phase] + she_rate[, , phase] <- mtran[, , "she2she"] / mtran[, , "shelved"] + can_rate[nonzero_countries, , phase] <- mtran[nonzero_countries, , "she2can"] / mtran[nonzero_countries, , "shelved"] + # Calculate global mean rates + glo_can_rate <- weighted.mean(can_rate[nonzero_countries, , phase], mtran[nonzero_countries, , phase]) + # Calculate regional rates + tmp <- toolAggregate(can_rate[nonzero_countries, , phase], rel = map[which(map$CountryCode %in% nonzero_countries), ], mtran[nonzero_countries, , phase]) + # For regions which had zero projects in a certain phase, assign the global weighted mean + reg_can_rate <- suppressWarnings(mbind(tmp, new.magpie(getItems(dim = 1, x = reg_can_rate)[which(!(getItems(dim = 1, x = reg_can_rate)) %in% getItems(dim = 1, x = tmp))], getYears(can_rate), phase, glo_can_rate))) + # Assign regional rates to countries without projects in the present phase + can_rate[zero_countries, , phase] <- as.numeric(reg_can_rate[map$RegionCode[which(map$CountryCode %in% zero_countries)], , phase]) + + } else { + can_she_rate[, , phase] <- (mtran[, , paste0(phase, "2can")] + mtran[, , paste0(phase, "2she")]) / mtran[, , phase] + she_rate[, , phase] <- mtran[, , paste0(phase, "2she")] / mtran[, , phase] } - #Calculate global mean rates - glo_can_she_rate <- weighted.mean(can_she_rate[nonzero_countries,,phase],mtran[nonzero_countries,,phase]) - glo_she_rate <- weighted.mean(she_rate[nonzero_countries,,phase],mtran[nonzero_countries,,phase]) - - #Calculate regional rates - tmp_can_she <- toolAggregate(can_she_rate[nonzero_countries,,phase],rel=map[which(map$CountryCode %in% nonzero_countries),],mtran[nonzero_countries,,phase]) - tmp_she <- toolAggregate(she_rate[nonzero_countries,,phase],rel=map[which(map$CountryCode %in% nonzero_countries),],mtran[nonzero_countries,,phase]) - - #For regions which had zero projects in a certain phase, assign the global weighted mean - reg_can_she_rate[,,phase] <- suppressWarnings(mbind(tmp_can_she, - new.magpie(getItems(dim = 1, x = reg_can_she_rate)[which(!(getItems(dim = 1, x = reg_can_she_rate)) %in% getItems(dim = 1, x = tmp_can_she))],getYears(mtran),phase,glo_can_she_rate))) - reg_she_rate[,,phase] <- suppressWarnings(mbind(tmp_she, - new.magpie(getItems(dim = 1, x = reg_she_rate)[which(!(getItems(dim = 1, x = reg_she_rate)) %in% getItems(dim = 1, x = tmp_she))],getYears(mtran),phase,glo_she_rate))) - - #Assign regional rates to countries without projects in the present phase - can_she_rate[zero_countries,,phase] <- as.numeric(reg_can_she_rate[map$RegionCode[which(map$CountryCode %in% zero_countries)],,phase]) - she_rate[zero_countries,,phase] <- as.numeric(reg_she_rate[map$RegionCode[which(map$CountryCode %in% zero_countries)],,phase]) + # Calculate global mean rates + glo_can_she_rate <- weighted.mean(can_she_rate[nonzero_countries, , phase], mtran[nonzero_countries, , phase]) + glo_she_rate <- weighted.mean(she_rate[nonzero_countries, , phase], mtran[nonzero_countries, , phase]) + + # Calculate regional rates + tmp_can_she <- toolAggregate(can_she_rate[nonzero_countries, , phase], rel = map[which(map$CountryCode %in% nonzero_countries), ], mtran[nonzero_countries, , phase]) + tmp_she <- toolAggregate(she_rate[nonzero_countries, , phase], rel = map[which(map$CountryCode %in% nonzero_countries), ], mtran[nonzero_countries, , phase]) + + # For regions which had zero projects in a certain phase, assign the global weighted mean + reg_can_she_rate[, , phase] <- suppressWarnings(mbind(tmp_can_she, + new.magpie(getItems(dim = 1, x = reg_can_she_rate)[which(!(getItems(dim = 1, x = reg_can_she_rate)) %in% getItems(dim = 1, x = tmp_can_she))], getYears(mtran), phase, glo_can_she_rate))) + reg_she_rate[, , phase] <- suppressWarnings(mbind(tmp_she, + new.magpie(getItems(dim = 1, x = reg_she_rate)[which(!(getItems(dim = 1, x = reg_she_rate)) %in% getItems(dim = 1, x = tmp_she))], getYears(mtran), phase, glo_she_rate))) + + # Assign regional rates to countries without projects in the present phase + can_she_rate[zero_countries, , phase] <- as.numeric(reg_can_she_rate[map$RegionCode[which(map$CountryCode %in% zero_countries)], , phase]) + she_rate[zero_countries, , phase] <- as.numeric(reg_she_rate[map$RegionCode[which(map$CountryCode %in% zero_countries)], , phase]) } + # Immaturity index formula to determine nascent coal consuming nations, where >50% of all coal plants are in the current pipeline + immaturity <- (cap_sum[, , "Announced"] + cap_sum[, , "Pre-permit"] + cap_sum[, , "Permitted"] + cap_sum[, , "Construction"] + cap_sum[, , "Shelved"]) / + (dimSums(cap_sum, dim = 3)) - # - # #Regional average cancellation and shelving rates, weighted by each country's total projects from 2015-2020 - # reg_can_she_rate <- toolAggregate(can_she_rate,rel=map,weight=dimSums(mtran[,,getNames(can_she_rate)],dim=3)) - # reg_she_rate <- toolAggregate(she_rate,rel=map,weight=dimSums(mtran[,,getNames(she_rate)],dim=3)) - # reg_can_rate <- toolAggregate(can_rate,rel=map,weight=dimSums(mtran[,,getNames(can_rate)],dim=3)) - # - - #Immaturity index formula to determine nascent coal consuming nations, where >50% of all coal plants are in the current pipeline - immaturity <- (cap_sum[,,"Announced"] + cap_sum[,,"Pre-permit"] + cap_sum[,,"Permitted"] + cap_sum[,,"Construction"] + cap_sum[,,"Shelved"]) / - (dimSums(cap_sum,dim=3)) + # Nascent coal consumers AND countries without any projects in the past 6 years are assigned their regional cancellation/shelving rates + can_rate[which(immaturity > 0.5)] <- reg_can_rate[map$RegionCode[which(map$CountryCode %in% getItems(dim = 1, x = immaturity)[which(immaturity > 0.5)])], , ] + can_rate[which(can_rate == 0.5)] <- reg_can_rate[map$RegionCode[which(map$CountryCode %in% getItems(dim = 1, x = immaturity)[which(immaturity > 0.5)])], , ] - #Nascent coal consumers AND countries without any projects in the past 6 years are assigned their regional cancellation/shelving rates - can_rate[which(immaturity>0.5)] <- reg_can_rate[map$RegionCode[which(map$CountryCode %in% getItems(dim = 1, x = immaturity)[which(immaturity>0.5)])],,] - can_rate[which(can_rate==0.5)] <- reg_can_rate[map$RegionCode[which(map$CountryCode %in% getItems(dim = 1, x = immaturity)[which(immaturity>0.5)])],,] - - comp_rate <- new.magpie(getItems(dim = 1, x = can_she_rate),getYears(mtran),getNames(can_she_rate),fill=NA) - comp_rate_brown <- new.magpie(getItems(dim = 1, x = can_she_rate),getYears(mtran),getNames(can_she_rate),fill=NA) - reg_comp_rate <- new.magpie(getItems(dim = 1, x = reg_can_rate),getYears(mtran),getNames(can_she_rate),fill=NA) - reg_comp_rate_brown <- new.magpie(getItems(dim = 1, x = reg_can_rate),getYears(mtran),getNames(can_she_rate),fill=NA) - glo_comp_rate <- new.magpie("GLO",getYears(mtran),getNames(can_she_rate),fill=NA) - glo_comp_rate_brown <- new.magpie("GLO",getYears(mtran),getNames(can_she_rate),fill=NA) + comp_rate <- new.magpie(getItems(dim = 1, x = can_she_rate), getYears(mtran), getNames(can_she_rate), fill = NA) + comp_rate_brown <- new.magpie(getItems(dim = 1, x = can_she_rate), getYears(mtran), getNames(can_she_rate), fill = NA) + reg_comp_rate <- new.magpie(getItems(dim = 1, x = reg_can_rate), getYears(mtran), getNames(can_she_rate), fill = NA) + reg_comp_rate_brown <- new.magpie(getItems(dim = 1, x = reg_can_rate), getYears(mtran), getNames(can_she_rate), fill = NA) + glo_comp_rate <- new.magpie("GLO", getYears(mtran), getNames(can_she_rate), fill = NA) + glo_comp_rate_brown <- new.magpie("GLO", getYears(mtran), getNames(can_she_rate), fill = NA) for (status in getNames(can_she_rate)) { - nonzero_countries <- getItems(dim = 1, x = mtran)[which(mtran[,,status]!=0)] - zero_countries <- getItems(dim = 1, x = mtran)[which(mtran[,,status]==0)] - can_she_rate[,,status][which(immaturity>0.5)] <- reg_can_she_rate[map$RegionCode[which(map$CountryCode %in% getItems(dim = 1, x = immaturity)[which(immaturity>0.5)])],,status] - she_rate[,,status][which(immaturity>0.5)] <- reg_she_rate[map$RegionCode[which(map$CountryCode %in% getItems(dim = 1, x = immaturity)[which(immaturity>0.5)])],,status] + nonzero_countries <- getItems(dim = 1, x = mtran)[which(mtran[, , status] != 0)] + zero_countries <- getItems(dim = 1, x = mtran)[which(mtran[, , status] == 0)] + can_she_rate[, , status][which(immaturity > 0.5)] <- reg_can_she_rate[map$RegionCode[which(map$CountryCode %in% getItems(dim = 1, x = immaturity)[which(immaturity > 0.5)])], , status] + she_rate[, , status][which(immaturity > 0.5)] <- reg_she_rate[map$RegionCode[which(map$CountryCode %in% getItems(dim = 1, x = immaturity)[which(immaturity > 0.5)])], , status] # Derive completion rates to be used in the 2025 capacity estimation - if (status=="shelved") { - comp_rate[,,status] <- 1 - can_rate[,,status] - comp_rate_brown[,,status] <- 1 - 0.5*can_rate[,,status] - }else { - comp_rate[,,status] <- 1 - can_she_rate[,,status] - comp_rate_brown[,,status] <- 1 - 0.5*can_she_rate[,,status] + if (status == "shelved") { + comp_rate[, , status] <- 1 - can_rate[, , status] + comp_rate_brown[, , status] <- 1 - 0.5 * can_rate[, , status] + } else { + comp_rate[, , status] <- 1 - can_she_rate[, , status] + comp_rate_brown[, , status] <- 1 - 0.5 * can_she_rate[, , status] } - glo_comp_rate[,,status] <- weighted.mean(comp_rate[nonzero_countries,,status],mtran[nonzero_countries,,status]) - glo_comp_rate_brown[,,status] <- weighted.mean(comp_rate_brown[nonzero_countries,,status],mtran[nonzero_countries,,status]) + glo_comp_rate[, , status] <- weighted.mean(comp_rate[nonzero_countries, , status], mtran[nonzero_countries, , status]) + glo_comp_rate_brown[, , status] <- weighted.mean(comp_rate_brown[nonzero_countries, , status], mtran[nonzero_countries, , status]) if (length(nonzero_countries)) { - #Calculate regional rates - tmp <- toolAggregate(comp_rate[nonzero_countries,,status],filter(map,CountryCode %in% nonzero_countries),mtran[nonzero_countries,,status]) - tmp_brown <- toolAggregate(comp_rate_brown[nonzero_countries,,status],filter(map,CountryCode %in% nonzero_countries),mtran[nonzero_countries,,status]) - #For regions which had zero projects in a certain status, assign the global weighted mean - reg_comp_rate[,,status] <- suppressWarnings(mbind(tmp,new.magpie(getItems(dim = 1, x = reg_comp_rate)[which(!(getItems(dim = 1, x = reg_comp_rate)) %in% getItems(dim = 1, x = tmp))],getYears(comp_rate),status,glo_comp_rate))) - reg_comp_rate_brown[,,status] <- suppressWarnings(mbind(tmp_brown,new.magpie(getItems(dim = 1, x = reg_comp_rate_brown)[which(!(getItems(dim = 1, x = reg_comp_rate_brown)) %in% getItems(dim = 1, x = tmp_brown))],getYears(comp_rate_brown),status,glo_comp_rate_brown))) - }else { - reg_comp_rate[,,status] <- 0 - reg_comp_rate_brown[,,status] <- 0 + # Calculate regional rates + tmp <- toolAggregate(comp_rate[nonzero_countries, , status], filter(map, CountryCode %in% nonzero_countries), mtran[nonzero_countries, , status]) + tmp_brown <- toolAggregate(comp_rate_brown[nonzero_countries, , status], filter(map, CountryCode %in% nonzero_countries), mtran[nonzero_countries, , status]) + # For regions which had zero projects in a certain status, assign the global weighted mean + reg_comp_rate[, , status] <- suppressWarnings(mbind(tmp, new.magpie(getItems(dim = 1, x = reg_comp_rate)[which(!(getItems(dim = 1, x = reg_comp_rate)) %in% getItems(dim = 1, x = tmp))], getYears(comp_rate), status, glo_comp_rate))) + reg_comp_rate_brown[, , status] <- suppressWarnings(mbind(tmp_brown, new.magpie(getItems(dim = 1, x = reg_comp_rate_brown)[which(!(getItems(dim = 1, x = reg_comp_rate_brown)) %in% getItems(dim = 1, x = tmp_brown))], getYears(comp_rate_brown), status, glo_comp_rate_brown))) + } else { + reg_comp_rate[, , status] <- 0 + reg_comp_rate_brown[, , status] <- 0 } } - # Countries which have indicated an anti-coal recovery plan are assumed to halve their BAU completion rates in the brown and BAU recovery scenarios - # In the green recovery scenario, their completion rates will be 0 (except for under-construction plants which will be built at BAU rates) - # comp_rate_brown[c(nonOECDppca,greenNations),,] <- 0.5 * comp_rate_brown[c(nonOECDppca,greenNations),,] - # comp_rate[c(nonOECDppca,greenNations),,] <- 0.5 * comp_rate[c(nonOECDppca,greenNations),,] - # # Under-construction plants in anti-coal nations will all be completed in both scenarios - # comp_rate[c(nonOECDppca,greenNations),,"newcon"] <- 2 * comp_rate[c(nonOECDppca,greenNations),,"newcon"] - # comp_rate_brown[c(nonOECDppca,greenNations),,"newcon"] <- 2 * comp_rate_brown[c(nonOECDppca,greenNations),,"newcon"] - # - # #OECD PPCA members cannot complete any pipeline projects to meet their 2030 phase-out target - # comp_rate[oecdPPCA,,] <- 0 - # comp_rate_brown[oecdPPCA,,] <- 0 - - #OECD PPCA members and green recovery nations are assumed to cancel all shelved projects and retire mothballed ones. - comp_rate[c(greenNations,oecdPPCA,nonOECDppca),,"shelved"] <- 0 - comp_rate_brown[c(greenNations,oecdPPCA,nonOECDppca),,"shelved"] <- 0 - cap_sum[c(oecdPPCA,greenNations,nonOECDppca),,"Mothballed"] <- 0 - # browser() + # OECD PPCA members and green recovery nations are assumed to cancel all shelved projects and retire mothballed ones. + comp_rate[c(greenNations, oecdPPCA, nonOECDppca), , "shelved"] <- 0 + comp_rate_brown[c(greenNations, oecdPPCA, nonOECDppca), , "shelved"] <- 0 + cap_sum[c(oecdPPCA, greenNations, nonOECDppca), , "Mothballed"] <- 0 + # Return completion rate magpies - if (grepl("comp_rates",subtype)) { - getNames(comp_rate) <- c("Shelved","Construction","Announced","Pre-permit","Permitted") - getNames(comp_rate_brown) <- c("Shelved_brown","Construction_brown","Announced_brown","Pre-permit_brown","Permitted_brown") - getNames(glo_comp_rate) <- c("Shelved","Construction","Announced","Pre-permit","Permitted") - getNames(glo_comp_rate_brown) <- c("Shelved_brown","Construction_brown","Announced_brown","Pre-permit_brown","Permitted_brown") - getNames(reg_comp_rate) <- c("Shelved","Construction","Announced","Pre-permit","Permitted") - getNames(reg_comp_rate_brown) <- c("Shelved_brown","Construction_brown","Announced_brown","Pre-permit_brown","Permitted_brown") - getNames(she_rate) <- c("Shelved_shelving","Construction_shelving","Announced_shelving","Pre-permit_shelving","Permitted_shelving") - getNames(reg_she_rate) <- c("Shelved_shelving","Construction_shelving","Announced_shelving","Pre-permit_shelving","Permitted_shelving") - # getNames(glo_she_rate) <- c("Shelved_shelving","Construction_shelving","Announced_shelving","Pre-permit_shelving","Permitted_shelving") - - if (grepl("reg",subtype)) { + if (grepl("comp_rates", subtype)) { + getNames(comp_rate) <- c("Shelved", "Construction", "Announced", "Pre-permit", "Permitted") + getNames(comp_rate_brown) <- c("Shelved_brown", "Construction_brown", "Announced_brown", "Pre-permit_brown", "Permitted_brown") + getNames(glo_comp_rate) <- c("Shelved", "Construction", "Announced", "Pre-permit", "Permitted") + getNames(glo_comp_rate_brown) <- c("Shelved_brown", "Construction_brown", "Announced_brown", "Pre-permit_brown", "Permitted_brown") + getNames(reg_comp_rate) <- c("Shelved", "Construction", "Announced", "Pre-permit", "Permitted") + getNames(reg_comp_rate_brown) <- c("Shelved_brown", "Construction_brown", "Announced_brown", "Pre-permit_brown", "Permitted_brown") + getNames(she_rate) <- c("Shelved_shelving", "Construction_shelving", "Announced_shelving", "Pre-permit_shelving", "Permitted_shelving") + getNames(reg_she_rate) <- c("Shelved_shelving", "Construction_shelving", "Announced_shelving", "Pre-permit_shelving", "Permitted_shelving") + + if (grepl("reg", subtype)) { reg_mtran <- toolAggregate( - setNames(mtran[,,c("shelved","newcon","ann","pre","perm")], - c("Shelved","Construction","Announced","Pre-permit","Permitted")),map,NULL) - reg_all_comp_rate <- toolAggregate(reg_comp_rate,weight=reg_mtran,dim=3,rel=data.frame(from=getNames(reg_mtran),to=rep("all",5))) - - out <- suppressWarnings(mbind(reg_comp_rate,reg_all_comp_rate,reg_she_rate)) - }else if (grepl("glo",subtype)) { - out <- suppressWarnings(mbind(glo_comp_rate,glo_comp_rate_brown)) - # out <- suppressWarnings(mbind(glo_comp_rate,glo_comp_rate_brown,glo_she_rate) - }else out <- suppressWarnings(mbind(comp_rate,comp_rate_brown,she_rate)) + setNames(mtran[, , c("shelved", "newcon", "ann", "pre", "perm")], + c("Shelved", "Construction", "Announced", "Pre-permit", "Permitted")), map, NULL) + reg_all_comp_rate <- toolAggregate(reg_comp_rate, weight = reg_mtran, dim = 3, rel = data.frame(from = getNames(reg_mtran), to = rep("all", 5))) + + out <- suppressWarnings(mbind(reg_comp_rate, reg_all_comp_rate, reg_she_rate)) + } else if (grepl("glo", subtype)) { + out <- suppressWarnings(mbind(glo_comp_rate, glo_comp_rate_brown)) + } else { + out <- suppressWarnings(mbind(comp_rate, comp_rate_brown, she_rate)) + } return(out) } # *********************************Derive Coal capacity in 2025****************************** # browser - cap2025_brown <- cap_sum[,,"Operating"] + - cap_sum[,,"Mothballed"]*0.5 + - cap_sum[,,"Announced"] * comp_rate_brown[,,"ann"] + - cap_sum[,,"Pre-permit"] * comp_rate_brown[,,"pre"] + - cap_sum[,,"Permitted"] * comp_rate_brown[,,"perm"] + - cap_sum[,,"Construction"] * comp_rate_brown[,,"newcon"] + - comp_rate_brown[,,"shelved"] * (cap_sum[,,"Shelved"] + - cap_sum[,,"Announced"] * (she_rate[,,"ann"]) + - cap_sum[,,"Pre-permit"] * (she_rate[,,"pre"]) + - cap_sum[,,"Permitted"] * (she_rate[,,"perm"]) + - cap_sum[,,"Construction"] * (she_rate[,,"newcon"])) - - retireBrown[,,"Retiring_Cap"] - - cap2025_BAU <- cap_sum[,,"Operating"] + - cap_sum[,,"Mothballed"]*0.5 + - cap_sum[,,"Announced"] * comp_rate[,,"ann"] + - cap_sum[,,"Pre-permit"] * comp_rate[,,"pre"] + - cap_sum[,,"Permitted"] * comp_rate[,,"perm"] + - cap_sum[,,"Construction"] * comp_rate[,,"newcon"] + - comp_rate[,,"shelved"] * (cap_sum[,,"Shelved"] + - cap_sum[,,"Announced"] * (she_rate[,,"ann"]) + - cap_sum[,,"Pre-permit"] * (she_rate[,,"pre"]) + - cap_sum[,,"Permitted"] * (she_rate[,,"perm"]) + - cap_sum[,,"Construction"] * (she_rate[,,"newcon"])) - - retireBAU[,,"Retiring_Cap"] - - cap2025_green <- cap_sum[,,"Operating"] + - cap_sum[,,"Announced"] * comp_rate[,,"ann"]/2 + - cap_sum[,,"Pre-permit"] * comp_rate[,,"pre"]/2 + - cap_sum[,,"Permitted"] * comp_rate[,,"perm"]/2 + - 0.5 * comp_rate[,,"newcon"] * cap_sum[,,"Construction"] + - 0.5 * comp_rate[,,"shelved"] * cap_sum[,,"Construction"] * (she_rate[,,"newcon"]) - - retireBAU[,,"Retiring_Cap"] - - cap2025_norm <- cap_sum[,,"Operating"] + - cap_sum[,,"Mothballed"]*0.5 + - cap_sum[,,"Announced"] + - cap_sum[,,"Pre-permit"] + - cap_sum[,,"Permitted"] + - cap_sum[,,"Construction"] + - cap_sum[,,"Shelved"] - - retireNorm[,,"Retiring_Cap"] - - cap2025_brown[which(cap2025_brown<0)] <- 0 - cap2025_green[which(cap2025_green<0)] <- 0 - cap2025_norm[which(cap2025_norm<0)] <- 0 - cap2025_BAU[which(cap2025_BAU<0)] <- 0 + cap2025_brown <- cap_sum[, , "Operating"] + + cap_sum[, , "Mothballed"] * 0.5 + + cap_sum[, , "Announced"] * comp_rate_brown[, , "ann"] + + cap_sum[, , "Pre-permit"] * comp_rate_brown[, , "pre"] + + cap_sum[, , "Permitted"] * comp_rate_brown[, , "perm"] + + cap_sum[, , "Construction"] * comp_rate_brown[, , "newcon"] + + comp_rate_brown[, , "shelved"] * (cap_sum[, , "Shelved"] + + cap_sum[, , "Announced"] * (she_rate[, , "ann"]) + + cap_sum[, , "Pre-permit"] * (she_rate[, , "pre"]) + + cap_sum[, , "Permitted"] * (she_rate[, , "perm"]) + + cap_sum[, , "Construction"] * (she_rate[, , "newcon"])) - + retireBrown[, , "Retiring_Cap"] + + cap2025_BAU <- cap_sum[, , "Operating"] + + cap_sum[, , "Mothballed"] * 0.5 + + cap_sum[, , "Announced"] * comp_rate[, , "ann"] + + cap_sum[, , "Pre-permit"] * comp_rate[, , "pre"] + + cap_sum[, , "Permitted"] * comp_rate[, , "perm"] + + cap_sum[, , "Construction"] * comp_rate[, , "newcon"] + + comp_rate[, , "shelved"] * (cap_sum[, , "Shelved"] + + cap_sum[, , "Announced"] * (she_rate[, , "ann"]) + + cap_sum[, , "Pre-permit"] * (she_rate[, , "pre"]) + + cap_sum[, , "Permitted"] * (she_rate[, , "perm"]) + + cap_sum[, , "Construction"] * (she_rate[, , "newcon"])) - + retireBAU[, , "Retiring_Cap"] + + cap2025_green <- cap_sum[, , "Operating"] + + cap_sum[, , "Announced"] * comp_rate[, , "ann"] / 2 + + cap_sum[, , "Pre-permit"] * comp_rate[, , "pre"] / 2 + + cap_sum[, , "Permitted"] * comp_rate[, , "perm"] / 2 + + 0.5 * comp_rate[, , "newcon"] * cap_sum[, , "Construction"] + + 0.5 * comp_rate[, , "shelved"] * cap_sum[, , "Construction"] * (she_rate[, , "newcon"]) - + retireBAU[, , "Retiring_Cap"] + + cap2025_norm <- cap_sum[, , "Operating"] + + cap_sum[, , "Mothballed"] * 0.5 + + cap_sum[, , "Announced"] + + cap_sum[, , "Pre-permit"] + + cap_sum[, , "Permitted"] + + cap_sum[, , "Construction"] + + cap_sum[, , "Shelved"] - + retireNorm[, , "Retiring_Cap"] + + cap2025_brown[which(cap2025_brown < 0)] <- 0 + cap2025_green[which(cap2025_green < 0)] <- 0 + cap2025_norm[which(cap2025_norm < 0)] <- 0 + cap2025_BAU[which(cap2025_BAU < 0)] <- 0 getNames(cap2025_brown) <- "Brown" getNames(cap2025_green) <- "Green" @@ -718,41 +673,47 @@ readGCPT <- function(subtype) { getYears(cap2025_norm) <- "y2025" getYears(cap2025_BAU) <- "y2025" - mcap2025 <- suppressWarnings(mbind(cap2025_brown/1000,cap2025_green/1000,cap2025_BAU/1000,cap2025_norm/1000)) + mcap2025 <- suppressWarnings(mbind(cap2025_brown / 1000, cap2025_green / 1000, cap2025_BAU / 1000, cap2025_norm / 1000)) # Return Capacity scenarios - if (grepl("future",subtype) | grepl("FinEx",subtype)) { + if (grepl("future", subtype) || grepl("FinEx", subtype)) { return(mcap2025) } ###### PEGASOS Policy Brief Calcs ########## - if (grepl("PEGASOS",subtype)) { - #PEGASOS policy brief scenario: Popular choice in literature has been to use a globally uniform 35-yr lifespan - retirePEGA <- retire %>% select(Country,`Planned Retire`,`Plant Age`,`Capacity (MW)`,Status,Avg_Ret_Age,`Heat rate`,`Emission factor`) %>% - filter(Status %in% c("Operating","operating")) %>% + if (grepl("PEGASOS", subtype)) { + # PEGASOS policy brief scenario: Popular choice in literature has been to use a globally uniform 35-yr lifespan + retirePEGA <- retire %>% + select(Country, `Planned Retire`, `Plant Age`, `Capacity (MW)`, Status, Avg_Ret_Age, `Heat rate`, `Emission factor`) %>% + filter(Status %in% c("Operating", "operating")) %>% filter(`Plant Age` >= 25) %>% filter(!is.na(`Capacity (MW)`)) %>% - group_by(Country) %>% summarise(Retiring_Cap=sum(`Capacity (MW)`)) + group_by(Country) %>% + summarise(Retiring_Cap = sum(`Capacity (MW)`)) retirePEGA$Retiring_Cap[which(is.na(retirePEGA$Retiring_Cap))] <- 0 - retirePEGA <- as.magpie(retirePEGA,spatial=1) - retirePEGA <- toolCountryFill(retirePEGA,fill=0,no_remove_warning = "KOS",verbosity=2) + retirePEGA <- as.magpie(retirePEGA, spatial = 1) + retirePEGA <- toolCountryFill(retirePEGA, fill = 0, no_remove_warning = "KOS", verbosity = 2) - retireNorm <- retire %>% select(Country,`Planned Retire`,`Plant Age`,`Capacity (MW)`,Status,Avg_Ret_Age,`Heat rate`,`Emission factor`) %>% - filter(Status %in% c("Operating","operating")) %>% + retireNorm <- retire %>% + select(Country, `Planned Retire`, `Plant Age`, `Capacity (MW)`, Status, Avg_Ret_Age, `Heat rate`, `Emission factor`) %>% + filter(Status %in% c("Operating", "operating")) %>% filter(`Plant Age` >= 30) %>% filter(!is.na(`Capacity (MW)`)) %>% - group_by(Country) %>% summarise(Retiring_Cap=sum(`Capacity (MW)`)) + group_by(Country) %>% + summarise(Retiring_Cap = sum(`Capacity (MW)`)) retireNorm$Retiring_Cap[which(is.na(retireNorm$Retiring_Cap))] <- 0 - retireNorm <- as.magpie(retireNorm,spatial=1) - retireNorm <- toolCountryFill(retireNorm,fill=0,no_remove_warning = "KOS",verbosity=2) + retireNorm <- as.magpie(retireNorm, spatial = 1) + retireNorm <- toolCountryFill(retireNorm, fill = 0, no_remove_warning = "KOS", verbosity = 2) - retire1p5C <- retire %>% select(Country,`Planned Retire`,`Plant Age`,`Capacity (MW)`,Status,Avg_Ret_Age) %>% - filter(Status %in% c("Operating","operating")) %>% + retire1p5C <- retire %>% + select(Country, `Planned Retire`, `Plant Age`, `Capacity (MW)`, Status, Avg_Ret_Age) %>% + filter(Status %in% c("Operating", "operating")) %>% filter(`Plant Age` >= 10) %>% filter(!is.na(`Capacity (MW)`)) %>% - group_by(Country) %>% summarise(Retiring_Cap=sum(`Capacity (MW)`)) + group_by(Country) %>% + summarise(Retiring_Cap = sum(`Capacity (MW)`)) retire1p5C$Retiring_Cap[which(is.na(retire1p5C$Retiring_Cap))] <- 0 - retire1p5C <- as.magpie(retire1p5C,spatial=1) - retire1p5C <- toolCountryFill(retire1p5C,fill=0,no_remove_warning = "KOS",verbosity=2) + retire1p5C <- as.magpie(retire1p5C, spatial = 1) + retire1p5C <- toolCountryFill(retire1p5C, fill = 0, no_remove_warning = "KOS", verbosity = 2) getYears(retireBAU) <- "y2025" getYears(retireGreen) <- "y2025" @@ -761,203 +722,212 @@ readGCPT <- function(subtype) { getYears(retire1p5C) <- "y2025" getYears(retireNorm) <- "y2025" - for (ts in seq(2030,2070,5)) { - #BAU COVID recovery scenario: Countries maintain their historical average lifespans - retireBAUts <- retire %>% select(Country,`Planned Retire`,`Plant Age`,`Capacity (MW)`,Status,Avg_Ret_Age) %>% - filter(Status %in% c("Operating","operating")) %>% - filter(`Planned Retire`<=ts | `Plant Age` >= (Avg_Ret_Age-(ts-2020))) %>% + for (ts in seq(2030, 2070, 5)) { + # BAU COVID recovery scenario: Countries maintain their historical average lifespans + retireBAUts <- retire %>% + select(Country, `Planned Retire`, `Plant Age`, `Capacity (MW)`, Status, Avg_Ret_Age) %>% + filter(Status %in% c("Operating", "operating")) %>% + filter(`Planned Retire` <= ts | `Plant Age` >= (Avg_Ret_Age - (ts - 2020))) %>% filter(!is.na(`Capacity (MW)`)) %>% - group_by(Country) %>% summarise(Retiring_Cap=sum(`Capacity (MW)`)) + group_by(Country) %>% + summarise(Retiring_Cap = sum(`Capacity (MW)`)) retireBAUts$Retiring_Cap[which(is.na(retireBAUts$Retiring_Cap))] <- 0 - retireBAUts <- as.magpie(retireBAUts,spatial=1) - retireBAUts <- toolCountryFill(setYears(retireBAUts,ts),fill=0,no_remove_warning = "KOS",verbosity=2) - - #Green COVID recovery scenario: Countries maintain their historical average lifespans - retireGreents <- retire %>% select(Country,`Planned Retire`,`Plant Age`,`Capacity (MW)`,Status,Avg_Ret_Age) %>% - filter(Status %in% c("Operating","operating")) %>% - filter(`Planned Retire`<=ts | `Plant Age` >= (Avg_Ret_Age-(ts-2015))) %>% + retireBAUts <- as.magpie(retireBAUts, spatial = 1) + retireBAUts <- toolCountryFill(setYears(retireBAUts, ts), fill = 0, no_remove_warning = "KOS", verbosity = 2) + + # Green COVID recovery scenario: Countries maintain their historical average lifespans + retireGreents <- retire %>% + select(Country, `Planned Retire`, `Plant Age`, `Capacity (MW)`, Status, Avg_Ret_Age) %>% + filter(Status %in% c("Operating", "operating")) %>% + filter(`Planned Retire` <= ts | `Plant Age` >= (Avg_Ret_Age - (ts - 2015))) %>% filter(!is.na(`Capacity (MW)`)) %>% - group_by(Country) %>% summarise(Retiring_Cap=sum(`Capacity (MW)`)) + group_by(Country) %>% + summarise(Retiring_Cap = sum(`Capacity (MW)`)) retireGreents$Retiring_Cap[which(is.na(retireGreents$Retiring_Cap))] <- 0 - retireGreents <- as.magpie(retireGreents,spatial=1) - retireGreents <- toolCountryFill(setYears(retireGreents,ts),fill=0,no_remove_warning = "KOS",verbosity=2) - - #Brown COVID recovery scenario: Countries maintain their historical average lifespans - retireBrownts <- retire %>% select(Country,`Planned Retire`,`Plant Age`,`Capacity (MW)`,Status,Avg_Ret_Age) %>% - filter(Status %in% c("Operating","operating")) %>% - filter(`Planned Retire`<=ts | `Plant Age` >= (Avg_Ret_Age-(ts-2025))) %>% + retireGreents <- as.magpie(retireGreents, spatial = 1) + retireGreents <- toolCountryFill(setYears(retireGreents, ts), fill = 0, no_remove_warning = "KOS", verbosity = 2) + + # Brown COVID recovery scenario: Countries maintain their historical average lifespans + retireBrownts <- retire %>% + select(Country, `Planned Retire`, `Plant Age`, `Capacity (MW)`, Status, Avg_Ret_Age) %>% + filter(Status %in% c("Operating", "operating")) %>% + filter(`Planned Retire` <= ts | `Plant Age` >= (Avg_Ret_Age - (ts - 2025))) %>% filter(!is.na(`Capacity (MW)`)) %>% - group_by(Country) %>% summarise(Retiring_Cap=sum(`Capacity (MW)`)) + group_by(Country) %>% + summarise(Retiring_Cap = sum(`Capacity (MW)`)) retireBrownts$Retiring_Cap[which(is.na(retireBrownts$Retiring_Cap))] <- 0 - retireBrownts <- as.magpie(retireBrownts,spatial=1) - retireBrownts <- toolCountryFill(setYears(retireBrownts,ts),fill=0,no_remove_warning = "KOS",verbosity=2) - - #PEGASOS policy brief scenario: Popular choice in literature has been to use a globally uniform 35-yr lifespan - retirePEGAts <- retire %>% select(Country,`Planned Retire`,`Plant Age`,`Capacity (MW)`,Status,Avg_Ret_Age) %>% - filter(Status %in% c("Operating","operating")) %>% - filter(`Plant Age` + (ts-2020) >= 35) %>% + retireBrownts <- as.magpie(retireBrownts, spatial = 1) + retireBrownts <- toolCountryFill(setYears(retireBrownts, ts), fill = 0, no_remove_warning = "KOS", verbosity = 2) + + # PEGASOS policy brief scenario: Popular choice in literature has been to use a globally uniform 35-yr lifespan + retirePEGAts <- retire %>% + select(Country, `Planned Retire`, `Plant Age`, `Capacity (MW)`, Status, Avg_Ret_Age) %>% + filter(Status %in% c("Operating", "operating")) %>% + filter(`Plant Age` + (ts - 2020) >= 35) %>% filter(!is.na(`Capacity (MW)`)) %>% - group_by(Country) %>% summarise(Retiring_Cap=sum(`Capacity (MW)`)) + group_by(Country) %>% + summarise(Retiring_Cap = sum(`Capacity (MW)`)) retirePEGAts$Retiring_Cap[which(is.na(retirePEGAts$Retiring_Cap))] <- 0 - retirePEGAts <- as.magpie(retirePEGAts,spatial=1) - retirePEGAts <- toolCountryFill(setYears(retirePEGAts,ts),fill=0,no_remove_warning = "KOS",verbosity=2) - - #Another common literature figure has been to use a globally uniform 40-yr lifespan - retireNormts <- retire %>% select(Country,`Planned Retire`,`Plant Age`,`Capacity (MW)`,Status,Avg_Ret_Age) %>% - filter(Status %in% c("Operating","operating")) %>% - filter(`Plant Age` + (ts-2020) >= 40) %>% + retirePEGAts <- as.magpie(retirePEGAts, spatial = 1) + retirePEGAts <- toolCountryFill(setYears(retirePEGAts, ts), fill = 0, no_remove_warning = "KOS", verbosity = 2) + + # Another common literature figure has been to use a globally uniform 40-yr lifespan + retireNormts <- retire %>% + select(Country, `Planned Retire`, `Plant Age`, `Capacity (MW)`, Status, Avg_Ret_Age) %>% + filter(Status %in% c("Operating", "operating")) %>% + filter(`Plant Age` + (ts - 2020) >= 40) %>% filter(!is.na(`Capacity (MW)`)) %>% - group_by(Country) %>% summarise(Retiring_Cap=sum(`Capacity (MW)`)) + group_by(Country) %>% + summarise(Retiring_Cap = sum(`Capacity (MW)`)) retireNormts$Retiring_Cap[which(is.na(retireNormts$Retiring_Cap))] <- 0 - retireNormts <- as.magpie(retireNormts,spatial=1) - retireNormts <- toolCountryFill(setYears(retireNormts,ts),fill=0,no_remove_warning = "KOS",verbosity=2) - - #20 year lifespans are roughly compatible with Hi-1p5C scenarios - retire1p5Cts <- retire %>% select(Country,`Planned Retire`,`Plant Age`,`Capacity (MW)`,Status,Avg_Ret_Age) %>% - filter(Status %in% c("Operating","operating")) %>% - filter(`Plant Age` + (ts-2020) >= 20) %>% + retireNormts <- as.magpie(retireNormts, spatial = 1) + retireNormts <- toolCountryFill(setYears(retireNormts, ts), fill = 0, no_remove_warning = "KOS", verbosity = 2) + + # 20 year lifespans are roughly compatible with Hi-1p5C scenarios + retire1p5Cts <- retire %>% + select(Country, `Planned Retire`, `Plant Age`, `Capacity (MW)`, Status, Avg_Ret_Age) %>% + filter(Status %in% c("Operating", "operating")) %>% + filter(`Plant Age` + (ts - 2020) >= 20) %>% filter(!is.na(`Capacity (MW)`)) %>% - group_by(Country) %>% summarise(Retiring_Cap=sum(`Capacity (MW)`)) + group_by(Country) %>% + summarise(Retiring_Cap = sum(`Capacity (MW)`)) retire1p5Cts$Retiring_Cap[which(is.na(retire1p5Cts$Retiring_Cap))] <- 0 - retire1p5Cts <- as.magpie(retire1p5Cts,spatial=1) - retire1p5Cts <- toolCountryFill(setYears(retire1p5Cts,ts),fill=0,no_remove_warning = "KOS",verbosity=2) + retire1p5Cts <- as.magpie(retire1p5Cts, spatial = 1) + retire1p5Cts <- toolCountryFill(setYears(retire1p5Cts, ts), fill = 0, no_remove_warning = "KOS", verbosity = 2) - retireBAU <- mbind(retireBAU,retireBAUts) - retireGreen <- mbind(retireGreen,retireGreents) - retireBrown <- mbind(retireBrown,retireBrownts) - retirePEGA <- mbind(retirePEGA,retirePEGAts) - retire1p5C <- mbind(retire1p5C,retire1p5Cts) - retireNorm <- mbind(retireNorm,retireNormts) + retireBAU <- mbind(retireBAU, retireBAUts) + retireGreen <- mbind(retireGreen, retireGreents) + retireBrown <- mbind(retireBrown, retireBrownts) + retirePEGA <- mbind(retirePEGA, retirePEGAts) + retire1p5C <- mbind(retire1p5C, retire1p5Cts) + retireNorm <- mbind(retireNorm, retireNormts) } - if (grepl("pubfinex",subtype)) { - pubfinex <- read.csv("C:/Users/stephenb/Downloads/madrat_main/sources/GCPT/Public_Foreign_Finance_Cap_2021.csv",sep = ";") - if (grepl("REsub",subtype)) { - output <- new.magpie(pubfinex$Country,c(2025,2030),NULL,fill = 0) + if (grepl("pubfinex", subtype)) { + pubfinex <- read.csv(file.path("Coal_Finance_Exit", "Public_Foreign_Finance_Cap_2021.csv"), sep = ";") + if (grepl("REsub", subtype)) { + output <- new.magpie(pubfinex$Country, c(2025, 2030), NULL, fill = 0) - output[,2025,] <- as.numeric(pubfinex$Foreign) * (1-as.numeric(pubfinex$Ann_share)) - output[,2030,] <- as.numeric(pubfinex$Foreign) * as.numeric(pubfinex$Ann_share) - return(toolCountryFill(output,fill = 0)) + output[, 2025, ] <- as.numeric(pubfinex$Foreign) * (1 - as.numeric(pubfinex$Ann_share)) + output[, 2030, ] <- as.numeric(pubfinex$Foreign) * as.numeric(pubfinex$Ann_share) + return(toolCountryFill(output, fill = 0, verbosity = 2)) } - for (iii in c("Ann","Pre","Perm")) { - cap_sum[pubfinex$Country,,grepl(iii,getNames(cap_sum),ignore.case = F)] <- pubfinex[,paste0(iii,"_dom")] + for (iii in c("Ann", "Pre", "Perm")) { + cap_sum[pubfinex$Country, , grepl(iii, getNames(cap_sum), ignore.case = FALSE)] <- pubfinex[, paste0(iii, "_dom")] } } ############ CALCULATE FUTURE CAPACITY TRAJECTORIES ################# - brown_PEGA <- cap_sum[,,"Operating"] + - cap_sum[,,"Mothballed"]*0.5 + - cap_sum[,,"Announced"] * comp_rate[,,"ann"] + - cap_sum[,,"Pre-permit"] * comp_rate[,,"pre"] + - cap_sum[,,"Permitted"] * comp_rate[,,"perm"] + - cap_sum[,,"Construction"] * comp_rate[,,"newcon"] + - comp_rate[,,"shelved"] * (cap_sum[,,"Shelved"] + - cap_sum[,,"Announced"] * (she_rate[,,"ann"]) + - cap_sum[,,"Pre-permit"] * (she_rate[,,"pre"]) + - cap_sum[,,"Permitted"] * (she_rate[,,"perm"]) + - cap_sum[,,"Construction"] * (she_rate[,,"newcon"])) - - retireBAU[,,"Retiring_Cap"] - - cap_green <- cap_sum[,,"Operating"] + - cap_sum[,,"Announced"] * comp_rate[,,"ann"]/2 + - cap_sum[,,"Pre-permit"] * comp_rate[,,"pre"]/2 + - cap_sum[,,"Permitted"] * comp_rate[,,"perm"]/2 + - 0.5 * comp_rate[,,"newcon"] * cap_sum[,,"Construction"] + - 0.5 * comp_rate[,,"shelved"] * cap_sum[,,"Construction"] * (she_rate[,,"newcon"]) - - retireGreen[,,"Retiring_Cap"] - - upper_gray_PEGA <- cap_sum[,,"Operating"] + - cap_sum[,,"Mothballed"]*0.5 + - cap_sum[,,"Announced"] * comp_rate_brown[,,"ann"] + - cap_sum[,,"Pre-permit"] * comp_rate_brown[,,"pre"] + - cap_sum[,,"Permitted"] * comp_rate_brown[,,"perm"] + - cap_sum[,,"Construction"] * comp_rate_brown[,,"newcon"] + - comp_rate_brown[,,"shelved"] * (cap_sum[,,"Shelved"] + - cap_sum[,,"Announced"] * (she_rate[,,"ann"]) + - cap_sum[,,"Pre-permit"] * (she_rate[,,"pre"]) + - cap_sum[,,"Permitted"] * (she_rate[,,"perm"]) + - cap_sum[,,"Construction"] * (she_rate[,,"newcon"])) - - retireBrown[,,"Retiring_Cap"] - - if(grepl("PEGASOS",subtype)) { - red_PEGA <- cap_sum[,,"Operating"] + - cap_sum[,,"Mothballed"]*0.5 + - cap_sum[,,"Announced"] + - cap_sum[,,"Pre-permit"] + - cap_sum[,,"Permitted"] + - cap_sum[,,"Construction"] + - cap_sum[,,"Shelved"] - - retirePEGA[,,"Retiring_Cap"] - }else { - red_PEGA <- cap_sum[,,"Operating"] + - cap_sum[,,"Mothballed"]*0.5 + - cap_sum[,,"Announced"] + - cap_sum[,,"Pre-permit"] + - cap_sum[,,"Permitted"] + - cap_sum[,,"Construction"] + - cap_sum[,,"Shelved"] - - retireNorm[,,"Retiring_Cap"] + brown_PEGA <- cap_sum[, , "Operating"] + + cap_sum[, , "Mothballed"] * 0.5 + + cap_sum[, , "Announced"] * comp_rate[, , "ann"] + + cap_sum[, , "Pre-permit"] * comp_rate[, , "pre"] + + cap_sum[, , "Permitted"] * comp_rate[, , "perm"] + + cap_sum[, , "Construction"] * comp_rate[, , "newcon"] + + comp_rate[, , "shelved"] * (cap_sum[, , "Shelved"] + + cap_sum[, , "Announced"] * (she_rate[, , "ann"]) + + cap_sum[, , "Pre-permit"] * (she_rate[, , "pre"]) + + cap_sum[, , "Permitted"] * (she_rate[, , "perm"]) + + cap_sum[, , "Construction"] * (she_rate[, , "newcon"])) - + retireBAU[, , "Retiring_Cap"] + + cap_green <- cap_sum[, , "Operating"] + + cap_sum[, , "Announced"] * comp_rate[, , "ann"] / 2 + + cap_sum[, , "Pre-permit"] * comp_rate[, , "pre"] / 2 + + cap_sum[, , "Permitted"] * comp_rate[, , "perm"] / 2 + + 0.5 * comp_rate[, , "newcon"] * cap_sum[, , "Construction"] + + 0.5 * comp_rate[, , "shelved"] * cap_sum[, , "Construction"] * (she_rate[, , "newcon"]) - + retireGreen[, , "Retiring_Cap"] + + upper_gray_PEGA <- cap_sum[, , "Operating"] + + cap_sum[, , "Mothballed"] * 0.5 + + cap_sum[, , "Announced"] * comp_rate_brown[, , "ann"] + + cap_sum[, , "Pre-permit"] * comp_rate_brown[, , "pre"] + + cap_sum[, , "Permitted"] * comp_rate_brown[, , "perm"] + + cap_sum[, , "Construction"] * comp_rate_brown[, , "newcon"] + + comp_rate_brown[, , "shelved"] * (cap_sum[, , "Shelved"] + + cap_sum[, , "Announced"] * (she_rate[, , "ann"]) + + cap_sum[, , "Pre-permit"] * (she_rate[, , "pre"]) + + cap_sum[, , "Permitted"] * (she_rate[, , "perm"]) + + cap_sum[, , "Construction"] * (she_rate[, , "newcon"])) - + retireBrown[, , "Retiring_Cap"] + + if (grepl("PEGASOS", subtype)) { + red_PEGA <- cap_sum[, , "Operating"] + + cap_sum[, , "Mothballed"] * 0.5 + + cap_sum[, , "Announced"] + + cap_sum[, , "Pre-permit"] + + cap_sum[, , "Permitted"] + + cap_sum[, , "Construction"] + + cap_sum[, , "Shelved"] - + retirePEGA[, , "Retiring_Cap"] + } else { + red_PEGA <- cap_sum[, , "Operating"] + + cap_sum[, , "Mothballed"] * 0.5 + + cap_sum[, , "Announced"] + + cap_sum[, , "Pre-permit"] + + cap_sum[, , "Permitted"] + + cap_sum[, , "Construction"] + + cap_sum[, , "Shelved"] - + retireNorm[, , "Retiring_Cap"] } - silver_PEGA <- setYears(cap_sum[,,"Operating"],NULL) - retirePEGA - lower_gray_PEGA <- setYears(cap_sum[,,"Operating"],NULL) - retire1p5C + silver_PEGA <- setYears(cap_sum[, , "Operating"], NULL) - retirePEGA + lower_gray_PEGA <- setYears(cap_sum[, , "Operating"], NULL) - retire1p5C - green_PEGA <- setYears(cap_sum[,,"Operating"],NULL) - retireGreen + green_PEGA <- setYears(cap_sum[, , "Operating"], NULL) - retireGreen - gold_PEGA <- setYears(cap_sum[,,"Operating"],NULL) - retireGreen + gold_PEGA <- setYears(cap_sum[, , "Operating"], NULL) - retireGreen - bronze_PEGA <- setYears(cap_sum[,,"Operating"],NULL) - retireBrown + bronze_PEGA <- setYears(cap_sum[, , "Operating"], NULL) - retireBrown - silver_PEGA[which(silver_PEGA<0)] <- 0 - cap_green[which(cap_green<0)] <- 0 - gold_PEGA[which(gold_PEGA<0)] <- 0 - brown_PEGA[which(brown_PEGA<0)] <- 0 + silver_PEGA[which(silver_PEGA < 0)] <- 0 + cap_green[which(cap_green < 0)] <- 0 + gold_PEGA[which(gold_PEGA < 0)] <- 0 + brown_PEGA[which(brown_PEGA < 0)] <- 0 - getYears(silver_PEGA) <- seq(2025,2070,5) - getYears(cap_green) <- seq(2025,2070,5) - getYears(gold_PEGA) <- seq(2025,2070,5) - getYears(brown_PEGA) <- seq(2025,2070,5) - getYears(bronze_PEGA) <- seq(2025,2070,5) - getYears(upper_gray_PEGA) <- seq(2025,2070,5) - getYears(red_PEGA) <- seq(2025,2070,5) - getYears(green_PEGA) <- seq(2025,2070,5) - getYears(lower_gray_PEGA) <- seq(2025,2070,5) + getYears(silver_PEGA) <- seq(2025, 2070, 5) + getYears(cap_green) <- seq(2025, 2070, 5) + getYears(gold_PEGA) <- seq(2025, 2070, 5) + getYears(brown_PEGA) <- seq(2025, 2070, 5) + getYears(bronze_PEGA) <- seq(2025, 2070, 5) + getYears(upper_gray_PEGA) <- seq(2025, 2070, 5) + getYears(red_PEGA) <- seq(2025, 2070, 5) + getYears(green_PEGA) <- seq(2025, 2070, 5) + getYears(lower_gray_PEGA) <- seq(2025, 2070, 5) ### Time Series: Announced and pre-permit projects finish in 2030 ## - if (!grepl("2025",subtype)) { - brown_PEGA[,2025,] <- brown_PEGA[,2025,] - (cap_sum[,,"Announced"] * comp_rate[,,"ann"] + - cap_sum[,,"Pre-permit"] * comp_rate[,,"pre"]) + if (!grepl("2025", subtype)) { + brown_PEGA[, 2025, ] <- brown_PEGA[, 2025, ] - (cap_sum[, , "Announced"] * comp_rate[, , "ann"] + + cap_sum[, , "Pre-permit"] * comp_rate[, , "pre"]) - cap_green[,2025,] <- cap_green[,2025,] - (cap_sum[,,"Announced"] * comp_rate[,,"ann"] + - cap_sum[,,"Pre-permit"] * comp_rate[,,"pre"]) + cap_green[, 2025, ] <- cap_green[, 2025, ] - (cap_sum[, , "Announced"] * comp_rate[, , "ann"] + + cap_sum[, , "Pre-permit"] * comp_rate[, , "pre"]) - upper_gray_PEGA[,2025,] <- upper_gray_PEGA[,2025,] - (cap_sum[,,"Announced"] * comp_rate[,,"ann"] + - cap_sum[,,"Pre-permit"] * comp_rate[,,"pre"]) + upper_gray_PEGA[, 2025, ] <- upper_gray_PEGA[, 2025, ] - (cap_sum[, , "Announced"] * comp_rate[, , "ann"] + + cap_sum[, , "Pre-permit"] * comp_rate[, , "pre"]) - red_PEGA[,2025,] <- red_PEGA[,2025,] - (cap_sum[,,"Announced"] * comp_rate[,,"ann"] + - cap_sum[,,"Pre-permit"] * comp_rate[,,"pre"]) + red_PEGA[, 2025, ] <- red_PEGA[, 2025, ] - (cap_sum[, , "Announced"] * comp_rate[, , "ann"] + + cap_sum[, , "Pre-permit"] * comp_rate[, , "pre"]) } - # getNames(silver_PEGA) <- "BAU_can" getNames(cap_green) <- "Green" - # getNames(gold_PEGA) <- "Green_can" - getNames(brown_PEGA) <- ifelse(grepl("REM",subtype), "Neutral", "Brown") - # getNames(bronze_PEGA) <- "Brown_can" - getNames(upper_gray_PEGA) <- ifelse(grepl("REM",subtype), "Brown", "upGray") + getNames(brown_PEGA) <- ifelse(grepl("REM", subtype), "Neutral", "Brown") + getNames(upper_gray_PEGA) <- ifelse(grepl("REM", subtype), "Brown", "upGray") getNames(red_PEGA) <- "Red" getNames(green_PEGA) <- "Green" getNames(lower_gray_PEGA) <- "lowGray" - if(grepl("REM",subtype)) { - mcap <- mbind(brown_PEGA,upper_gray_PEGA,cap_green)/1000 - mcap <- mcap[,getYears(mcap)<="y2030",] - }else { - mcap <- mbind(brown_PEGA,upper_gray_PEGA,red_PEGA,lower_gray_PEGA,cap_green)/1000 + if (grepl("REM", subtype)) { + mcap <- mbind(brown_PEGA, upper_gray_PEGA, cap_green) / 1000 + mcap <- mcap[, getYears(mcap) <= "y2030", ] + } else { + mcap <- mbind(brown_PEGA, upper_gray_PEGA, red_PEGA, lower_gray_PEGA, cap_green) / 1000 } # Return Capacity scenarios @@ -966,137 +936,133 @@ readGCPT <- function(subtype) { # Prepare completion rate data frames - getNames(comp_rate) <- c("Shelved","Construction","Announced","Pre-permit","Permitted") + getNames(comp_rate) <- c("Shelved", "Construction", "Announced", "Pre-permit", "Permitted") df_comp <- as.data.frame(comp_rate) colnames(df_comp)[2] <- "Country" - df_comp <- df_comp[,-3] - df_comp <- df_comp[,-1] + df_comp <- df_comp[, -3] + df_comp <- df_comp[, -1] colnames(df_comp)[2] <- "Status" - getNames(comp_rate_brown) <- c("Shelved","Construction","Announced","Pre-permit","Permitted") + getNames(comp_rate_brown) <- c("Shelved", "Construction", "Announced", "Pre-permit", "Permitted") df_comp_brown <- as.data.frame(comp_rate_brown) colnames(df_comp_brown)[2] <- "Country" - df_comp_brown <- df_comp_brown[,-3] - df_comp_brown <- df_comp_brown[,-1] + df_comp_brown <- df_comp_brown[, -3] + df_comp_brown <- df_comp_brown[, -1] colnames(df_comp_brown)[2] <- "Status" - #Calculate committed emissions + # Calculate committed emissions # Select necessary columns from plant-level database - emi_data <- retire %>% select(Country,`Plant Age`,`Capacity (MW)`,Status,`Heat rate`,`Emission factor`,`Combustion technology`,RETIRED,Year) %>% - filter(!(Status %in% c("Retired","Cancelled","retired","cancelled")) & !is.na(`Capacity (MW)`) & is.na(RETIRED) & !is.na(`Emission factor`)) %>% - left_join(avgRetAge,by="Country") %>% mutate(Brown_Ret_Age=Avg_Ret_Age+5) %>% mutate(Norm_Ret_Age=40) - - #Convert Year column to numeric, first handling the special non-numeric cases - emi_data$Year[which(grepl("after",emi_data$Year,ignore.case=TRUE))] <- - as.numeric(gsub("after ","",emi_data$Year[which(grepl("after",emi_data$Year,ignore.case=TRUE))],ignore.case=TRUE))+1 - emi_data$Year[which(grepl("/",emi_data$Year,fixed=TRUE) | grepl("-",emi_data$Year,fixed=TRUE))] <- - substr(emi_data$Year[which(grepl("/",emi_data$Year,fixed=TRUE) | grepl("-",emi_data$Year,fixed=TRUE))],1,4) + emi_data <- retire %>% + select(Country, `Plant Age`, `Capacity (MW)`, Status, `Heat rate`, `Emission factor`, `Combustion technology`, RETIRED, Year) %>% + filter(!(Status %in% c("Retired", "Cancelled", "retired", "cancelled")) & !is.na(`Capacity (MW)`) & is.na(RETIRED) & !is.na(`Emission factor`)) %>% + left_join(avgRetAge, by = "Country") %>% + mutate(Brown_Ret_Age = Avg_Ret_Age + 5) %>% + mutate(Norm_Ret_Age = 40) + + # Convert Year column to numeric, first handling the special non-numeric cases + emi_data$Year[which(grepl("after", emi_data$Year, ignore.case = TRUE))] <- + as.numeric(gsub("after ", "", emi_data$Year[which(grepl("after", emi_data$Year, ignore.case = TRUE))], ignore.case = TRUE)) + 1 + emi_data$Year[which(grepl("/", emi_data$Year, fixed = TRUE) | grepl("-", emi_data$Year, fixed = TRUE))] <- + substr(emi_data$Year[which(grepl("/", emi_data$Year, fixed = TRUE) | grepl("-", emi_data$Year, fixed = TRUE))], 1, 4) emi_data$Year <- as.numeric(emi_data$Year) # Set operating plants with an unknown age to 50% of the national average lifespan emi_data <- emi_data %>% - mutate(`Plant Age`= - ifelse(is.na(Year) & Status %in% c("Operating","operating"), + mutate(`Plant Age` = + ifelse(is.na(Year) & Status %in% c("Operating", "operating"), 0.5 * Avg_Ret_Age, `Plant Age`)) - # emi_data[which(is.na(emi_data$`Plant Age`)),] <- emi_data[which(is.na(emi_data$`Plant Age`)),] %>% mutate(`Plant Age`=Avg_Ret_Age/2) - # Set pipeline plants to appropriate ages for (Phase in getNames(comp_rate)) { emi_data <- emi_data %>% mutate(`Plant Age` = - ifelse(grepl(Phase,Status,ignore.case=F) & is.finite(Year) & Year >=2020, + ifelse(grepl(Phase, Status, ignore.case = FALSE) & is.finite(Year) & Year >= 2020, 2020 - Year, `Plant Age`)) meanAge <- emi_data %>% - filter(grepl(Phase,Status,ignore.case=F) & is.finite(Year) & Year >=2020) %>% - summarise(age=mean(`Plant Age`)) + filter(grepl(Phase, Status, ignore.case = FALSE) & is.finite(Year) & Year >= 2020) %>% + summarise(age = mean(`Plant Age`)) - # emi_data$`Plant Age`[which(emi_data$Status==Phase & is.finite(emi_data$Year) & emi_data$Year>=2020)] <- - # 2020 - emi_data$Year[which(emi_data$Status==Phase & is.finite(emi_data$Year) & emi_data$Year>=2020)] - - # meanAge <- mean(emi_data$`Plant Age`[which(emi_data$Status==Phase & is.finite(emi_data$Year) & emi_data$Year>=2020)]) - - emi_data$`Plant Age`[which(emi_data$Status==Phase & is.na(emi_data$Year))] <- meanAge$age + emi_data$`Plant Age`[which(emi_data$Status == Phase & is.na(emi_data$Year))] <- meanAge$age } # Read in national average capacity factor assumption for each 5-year time-step - capFac <- calcOutput("CapacityFactor",aggregate=F)[,seq(2020,2100,5),"pc"] - capFac <- removeColNa(as.data.frame(capFac))[,-3] - colnames(capFac) <- c("Country","Period","Cap_Factor") + capFac <- calcOutput("CapacityFactor", aggregate = FALSE)[, seq(2020, 2100, 5), "pc"] + capFac <- removeColNa(as.data.frame(capFac))[, -3] + colnames(capFac) <- c("Country", "Period", "Cap_Factor") capFac$Period <- as.numeric(as.character(capFac$Period)) # Assign each coal plant its country's average capacity factor per time-step - emi_data <- emi_data %>% left_join(capFac,by="Country") %>% mutate(`Plant Age`=`Plant Age`+(Period-2020)) + emi_data <- emi_data %>% left_join(capFac, by = "Country") %>% mutate(`Plant Age` = `Plant Age` + (Period - 2020)) # Calculate emissions from each plant for each 5-yr timestep in each scenario using GCPT methodology - # 5 * MW * cf * Btu/kWh * kgCO2/TJ * 9.2427e-12 - emi_data <- emi_data %>% mutate(green_5yr_emi=ifelse(emi_data$`Plant Age`>=0 & (emi_data$`Plant Age` < emi_data$Avg_Ret_Age), - 5 * `Capacity (MW)` * Cap_Factor * `Heat rate` * `Emission factor`*9.2427e-12, 0)) %>% - mutate(bau_5yr_emi=ifelse(emi_data$`Plant Age`>=0 & (emi_data$`Plant Age` < emi_data$Avg_Ret_Age), - 5 * `Capacity (MW)` * Cap_Factor * `Heat rate` * `Emission factor`*9.2427e-12, 0)) %>% - mutate(brown_5yr_emi=ifelse(emi_data$`Plant Age`>=0 & (emi_data$`Plant Age` < emi_data$Brown_Ret_Age), - 5 * `Capacity (MW)` * Cap_Factor * `Heat rate` * `Emission factor`*9.2427e-12, 0)) %>% - mutate(norm_5yr_emi=ifelse(emi_data$`Plant Age`>=0 & (emi_data$`Plant Age` < emi_data$Norm_Ret_Age), - 5 * `Capacity (MW)` * 0.53 * `Heat rate` * `Emission factor`*9.2427e-12, 0)) + # 5 * MW * cf * Btu/kWh * kgCO2/TJ * 9.2427e-12 #nolint + emi_data <- emi_data %>% mutate(green_5yr_emi = ifelse(emi_data$`Plant Age` >= 0 & (emi_data$`Plant Age` < emi_data$Avg_Ret_Age), + 5 * `Capacity (MW)` * Cap_Factor * `Heat rate` * `Emission factor` * 9.2427e-12, 0)) %>% + mutate(bau_5yr_emi = ifelse(emi_data$`Plant Age` >= 0 & (emi_data$`Plant Age` < emi_data$Avg_Ret_Age), + 5 * `Capacity (MW)` * Cap_Factor * `Heat rate` * `Emission factor` * 9.2427e-12, 0)) %>% + mutate(brown_5yr_emi = ifelse(emi_data$`Plant Age` >= 0 & (emi_data$`Plant Age` < emi_data$Brown_Ret_Age), + 5 * `Capacity (MW)` * Cap_Factor * `Heat rate` * `Emission factor` * 9.2427e-12, 0)) %>% + mutate(norm_5yr_emi = ifelse(emi_data$`Plant Age` >= 0 & (emi_data$`Plant Age` < emi_data$Norm_Ret_Age), + 5 * `Capacity (MW)` * 0.53 * `Heat rate` * `Emission factor` * 9.2427e-12, 0)) # Calculate total emissions (MtCO2) over the lifespan of plants in operation and development for each scenario - green_emi <- emi_data %>% group_by(Country,.add=TRUE) %>% group_by(Status,.add=TRUE) %>% summarise(green_emi = sum(green_5yr_emi)) - - bau_emi <- emi_data %>% group_by(Country,.add=TRUE) %>% group_by(Status,.add=TRUE) %>% summarise(BAU_emi = sum(bau_5yr_emi)) - - brown_emi <- emi_data %>% group_by(Country,.add=TRUE) %>% group_by(Status,.add=TRUE) %>% summarise(brown_emi = sum(brown_5yr_emi)) - - norm_emi <- emi_data %>% group_by(Country,.add=TRUE) %>% group_by(Status,.add=TRUE) %>% summarise(norm_emi = sum(norm_5yr_emi)) + green_emi <- emi_data %>% + group_by(Country, .add = TRUE) %>% + group_by(Status, .add = TRUE) %>% + summarise(green_emi = sum(green_5yr_emi)) + + bau_emi <- emi_data %>% + group_by(Country, .add = TRUE) %>% + group_by(Status, .add = TRUE) %>% + summarise(BAU_emi = sum(bau_5yr_emi)) + + brown_emi <- emi_data %>% + group_by(Country, .add = TRUE) %>% + group_by(Status, .add = TRUE) %>% + summarise(brown_emi = sum(brown_5yr_emi)) + + norm_emi <- emi_data %>% + group_by(Country, .add = TRUE) %>% + group_by(Status, .add = TRUE) %>% + summarise(norm_emi = sum(norm_5yr_emi)) # Calculate total emissions from all operating & pipeline plants with 40-yr lifespans - norm_emi <- norm_emi %>% group_by(Country) %>% summarise(norm_total_emi=sum(norm_emi)/1000) - glo_norm_emi <- norm_emi %>% summarise(norm_global_emi=sum(norm_total_emi)) + norm_emi <- norm_emi %>% group_by(Country) %>% summarise(norm_total_emi = sum(norm_emi) / 1000) # Calculate committed emissions reduced by PPCA members based on norm assumptions ppca_emi <- emi_data %>% - filter(Period>=2030 & Country %in% ppca) %>% - mutate(norm_5yr_emi=ifelse(Period==2030,norm_5yr_emi/2,norm_5yr_emi)) %>% - summarise(avoided_emissions=sum(norm_5yr_emi)/1000) - - # Calculate total emissions from all operating & pipeline plants - all_emi <- bau_emi %>% group_by(Country) %>% summarise(All_total_emi=sum(BAU_emi)/1000) - glo_all_emi <- all_emi %>% summarise(All_global_emi=sum(All_total_emi)) + filter(Period >= 2030 & Country %in% ppca) %>% + mutate(norm_5yr_emi = ifelse(Period == 2030, norm_5yr_emi / 2, norm_5yr_emi)) %>% + summarise(avoided_emissions = sum(norm_5yr_emi) / 1000) # Calculate total emissions from operating & pipeline plants in each recovery scenario - bau_emi <- left_join(bau_emi,df_comp,by=c("Country","Status")) - bau_emi$Value[which(bau_emi$Status=="Operating")] <- 1 - bau_emi$Value[which(bau_emi$Status=="Mothballed")] <- 0.5 - bau_emi <- bau_emi %>% group_by(Country) %>% summarize(BAU_total_emi=sum(BAU_emi*Value)/1000) - glo_bau_emi <- bau_emi %>% summarise(Global_BAU_emi=sum(BAU_total_emi)) + bau_emi <- left_join(bau_emi, df_comp, by = c("Country", "Status")) + bau_emi$Value[which(bau_emi$Status == "Operating")] <- 1 + bau_emi$Value[which(bau_emi$Status == "Mothballed")] <- 0.5 + bau_emi <- bau_emi %>% group_by(Country) %>% summarize(BAU_total_emi = sum(BAU_emi * Value) / 1000) - green_emi <- left_join(green_emi,df_comp,by=c("Country","Status")) + green_emi <- left_join(green_emi, df_comp, by = c("Country", "Status")) green_emi$Value <- 0.5 * green_emi$Value - green_emi$Value[which(green_emi$Status=="Operating")] <- 1 - green_emi$Value[which(green_emi$Status=="Mothballed")] <- 0 - green_emi <- green_emi %>% group_by(Country) %>% summarize(green_total_emi=sum(green_emi*Value)/1000) - glo_green_emi <- green_emi %>% summarise(Global_green_emi=sum(green_total_emi)) - - brown_emi <- left_join(brown_emi,df_comp_brown,by=c("Country","Status")) - brown_emi$Value[which(brown_emi$Status=="Operating")] <- 1 - brown_emi$Value[which(brown_emi$Status=="Mothballed")] <- 0.5 - brown_emi <- brown_emi %>% group_by(Country) %>% summarize(brown_total_emi=sum(brown_emi*Value)/1000) - glo_brown_emi <- brown_emi %>% summarise(Global_brown_emi=sum(brown_total_emi)) - - # Calculate capacity-weighted mean emission factor by country and plant status - # emifac <- emi_data %>% group_by(Country,.add=TRUE) %>% group_by(Status,.add=TRUE) %>% - # summarise(EF_w_mean = weighted.mean(`Emission factor`,`Capacity (MW)`)) - - bau_emi <- toolCountryFill(as.magpie(bau_emi),fill=0,verbosity=2) - green_emi <- toolCountryFill(as.magpie(green_emi),fill=0,verbosity=2) - brown_emi <- toolCountryFill(as.magpie(brown_emi),fill=0,verbosity=2) - norm_emi <- toolCountryFill(as.magpie(norm_emi),fill=0,verbosity=2) - - if (grepl("emissions",subtype)) { - return(mbind(bau_emi,green_emi,brown_emi,norm_emi)) - }else if (grepl("ppca_emi",subtype)) { + green_emi$Value[which(green_emi$Status == "Operating")] <- 1 + green_emi$Value[which(green_emi$Status == "Mothballed")] <- 0 + green_emi <- green_emi %>% group_by(Country) %>% summarize(green_total_emi = sum(green_emi * Value) / 1000) + + brown_emi <- left_join(brown_emi, df_comp_brown, by = c("Country", "Status")) + brown_emi$Value[which(brown_emi$Status == "Operating")] <- 1 + brown_emi$Value[which(brown_emi$Status == "Mothballed")] <- 0.5 + brown_emi <- brown_emi %>% group_by(Country) %>% summarize(brown_total_emi = sum(brown_emi * Value) / 1000) + + bau_emi <- toolCountryFill(as.magpie(bau_emi), fill = 0, verbosity = 2) + green_emi <- toolCountryFill(as.magpie(green_emi), fill = 0, verbosity = 2) + brown_emi <- toolCountryFill(as.magpie(brown_emi), fill = 0, verbosity = 2) + norm_emi <- toolCountryFill(as.magpie(norm_emi), fill = 0, verbosity = 2) + + if (grepl("emissions", subtype)) { + return(mbind(bau_emi, green_emi, brown_emi, norm_emi)) + } else if (grepl("ppca_emi", subtype)) { return(as.magpie(ppca_emi)) } } diff --git a/R/readGEA2012.R b/R/readGEA2012.R index 533edf38..2df3bfe7 100644 --- a/R/readGEA2012.R +++ b/R/readGEA2012.R @@ -5,102 +5,103 @@ #' @author Stephen Bi #' @seealso \code{\link{readSource}} #' @examples -#' -#' \dontrun{ a <- readSource("GEA2012","coal") +#' \dontrun{ +#' a <- readSource("GEA2012", "coal") #' } -#' +#' #' @importFrom readxl read_excel -#' @importFrom madrat toolNAreplace #' @importFrom dplyr relocate mutate readGEA2012 <- function(subtype) { - EJ_2_TWyr <- 1/31.536 + EJ_2_TWyr <- 1 / 31.536 ts1 <- 5 ts2 <- 10 - ttot <- c(seq(2005,2055,ts1),seq(2060,2150,ts2)) + ttot <- c(seq(2005, 2055, ts1), seq(2060, 2150, ts2)) t_cutoff <- 2050 t0 <- 2020 t_trans <- (t_cutoff - t0) - #================================================================ + # ================================================================ # Data retrieval and processing function selection - #================================================================ + # ================================================================ ffTypeData <- list() ffTypeScenData <- list() tmp <- NULL enty <- NULL scenario <- NULL - - #Ordering of SSPs in this vector corresponds to ordering of coded scenarios in "Scenario data XX.xlsx" - scen <- c('SSP5','SSP2','SSP1','SSP3','SSP4') - if ("gas" %in% subtype) ffType <- c('SHG-rv','COG-rv','CMG-rv','TIG-rv','HYG-rv','DEG-rv','SHG-rs','COG-rs','CMG-rs','TIG-rs','HYG-rs','DEG-rs') - if ("oil" %in% subtype) ffType <- c('TAO-rv','SHO-rv','EHO-rv','COO-rv','TAO-rs','SHO-rs','EHO-rs','COO-rs') - #subtype <- c('SHG-rv','COG-rv','CMG-rv','TIG-rv','HYG-rv','DEG-rv','SHG-rs','COG-rs','CMG-rs','TIG-rs','HYG-rs','DEG-rs', + + # Ordering of SSPs in this vector corresponds to ordering of coded scenarios in "Scenario data XX.xlsx" + scen <- c("SSP5", "SSP2", "SSP1", "SSP3", "SSP4") + if ("gas" %in% subtype) ffType <- c("SHG-rv", "COG-rv", "CMG-rv", "TIG-rv", "HYG-rv", "DEG-rv", "SHG-rs", "COG-rs", "CMG-rs", "TIG-rs", "HYG-rs", "DEG-rs") + if ("oil" %in% subtype) ffType <- c("TAO-rv", "SHO-rv", "EHO-rv", "COO-rv", "TAO-rs", "SHO-rs", "EHO-rs", "COO-rs") + # subtype <- c('SHG-rv','COG-rv','CMG-rv','TIG-rv','HYG-rv','DEG-rv','SHG-rs','COG-rs','CMG-rs','TIG-rs','HYG-rs','DEG-rs', # 'TAO-rv','SHO-rv','EHO-rv','COO-rv','TAO-rs','SHO-rs','EHO-rs','COO-rs','HAC','LIC') - + if ("coal" %in% subtype) { - rawData <- read.csv2("Scenario Data HAC_LIC.csv",header=TRUE,as.is = T) + rawData <- read.csv2("Scenario Data HAC_LIC.csv", header = TRUE, as.is = T) rawData$grade <- as.factor(rawData$grade) rawData$value <- as.numeric(rawData$value) - rawData <- rawData %>% mutate(enty="pecoal") %>% relocate(enty,.before=scenario) - out <- setYears(as.magpie(rawData),ttot[1]) + rawData <- rawData %>% + mutate(enty = "pecoal") %>% + relocate(enty, .before = scenario) + out <- setYears(as.magpie(rawData), ttot[1]) tmp <- out - #out <- new.magpie(unique(rawData$region),ttot,names=paste(rawData$scenario,rawData$xi,rawData$grade,sep="."),fill=0) for (rlf in 2:length(unique(rawData$grade))) { - mselect(out,grade=rlf,xi="xi3") <- mselect(tmp,grade=rlf,xi="xi3") - mselect(tmp,grade=rlf-1,xi="xi3") + mselect(out, grade = rlf, xi = "xi3") <- mselect(tmp, grade = rlf, xi = "xi3") - mselect(tmp, grade = rlf - 1, xi = "xi3") } - for (ts in ttot[-1]) out <- mbind(out,setYears(out[,ttot[1],],ts)) - out[,,"xi3"] <- out[,,"xi3"]/EJ_2_TWyr - out[,,c("xi1","xi2")] <- out[,,c("xi1","xi2")]*EJ_2_TWyr - - }else { + for (ts in ttot[-1]) out <- mbind(out, setYears(out[, ttot[1], ], ts)) + out[, , "xi3"] <- out[, , "xi3"] / EJ_2_TWyr + out[, , c("xi1", "xi2")] <- out[, , c("xi1", "xi2")] * EJ_2_TWyr + } else { # Loop over FF types for (i in ffType) { - #Read FF type data - typeFilename <- paste0("FF data ",i,".xlsx") + # Read FF type data + typeFilename <- paste0("FF data ", i, ".xlsx") rawData <- as.data.frame(readxl::read_excel(typeFilename)) - rawData <- rawData[,which(!is.na(rawData[1,]))] - if (i==ffType[1]) { - regions <- rawData[,"Region code"] + rawData <- rawData[, which(!is.na(rawData[1, ]))] + if (i == ffType[1]) { + regions <- rawData[, "Region code"] nreg <- dim(rawData)[1] } - #Read appropriate pre-processing function from the file - ppFunc <- as.character(rawData[1,"R Pre-Proc Function"]) - ppFunc <- source(file=paste0(ppFunc,".r"))[[1]] - #Retain only numerical data - numData <- rawData[1:nreg,5:dim(rawData)[2]] - #Execute pre-processing function + # Read appropriate pre-processing function from the file + ppFunc <- as.character(rawData[1, "R Pre-Proc Function"]) + ppFunc <- source(file = paste0(ppFunc, ".r"))[[1]] + # Retain only numerical data + numData <- rawData[1:nreg, 5:dim(rawData)[2]] + # Execute pre-processing function ffTypeData[[i]] <- ppFunc(numData) - - #Read Scenario data (cost and quantity mark-ups/factors) - scenFilename <- paste0("Scenario data ",i,".xlsx") + + # Read Scenario data (cost and quantity mark-ups/factors) + scenFilename <- paste0("Scenario data ", i, ".xlsx") scenData <- as.data.frame(readxl::read_excel(scenFilename)) - scenData <- scenData[,which(!is.na(scenData[1,]))] - - #Some data files are associated with 2 scenario adjustment functions -- these must be handled differently (EHO and TAO) - n_scenFuncs <- length(unique(scenData[,"R Scenario Function"])) - #Loop over scenarios + scenData <- scenData[, which(!is.na(scenData[1, ]))] + + # Some data files are associated with 2 scenario adjustment functions -- these must be handled differently (EHO and TAO) + n_scenFuncs <- length(unique(scenData[, "R Scenario Function"])) + # Loop over scenarios for (j in 1:length(scen)) { - #Case 1: only 1 scenario adjustment function for the FF type - if (n_scenFuncs==1) { - #The Scenario processing func requires the full data frame and the scenario multiplier columns as arguments - scenFunc <- as.character(unique(scenData[,"R Scenario Function"])) - scenFunc <- source(file=paste0(scenFunc,".r"))[[1]] - ffTypeScenData[[i]][[scen[j]]] <- scenFunc(ffTypeData[[i]],scenData[((j-1)*nreg+1):(j*nreg),which(grepl("Data",colnames(scenData)))]) - }else { - #Case 2: 1 scenario adustment function for this scenario of the FF type - if (length(unique(scenData[((j-1)*nreg+1):(j*nreg),"R Scenario Function"]))==1) { - scenFunc <- as.character(scenData[1+(j-1)*nreg,"R Scenario Function"]) - scenFunc <- source(file=paste0(scenFunc,".r"))[[1]] - ffTypeScenData[[i]][[scen[j]]] <- scenFunc(ffTypeData[[i]],scenData[((j-1)*nreg+1):(j*nreg),which(grepl("Data",colnames(scenData)))]) - #Case 3: Different scenario adjustment functions across regions within the scenario of the FF type - }else { - ffTypeScenData[[i]][[scen[j]]] <- array(NA,dim=dim(ffTypeData[[i]])) - #Read and use the scenario function for each region + # Case 1: only 1 scenario adjustment function for the FF type + if (n_scenFuncs == 1) { + # The Scenario processing func requires the full data frame and the scenario multiplier columns as arguments + scenFunc <- as.character(unique(scenData[, "R Scenario Function"])) + scenFunc <- source(file = paste0(scenFunc, ".r"))[[1]] + ffTypeScenData[[i]][[scen[j]]] <- scenFunc(ffTypeData[[i]], scenData[((j - 1) * nreg + 1):(j * nreg), which(grepl("Data", colnames(scenData)))]) + } else { + # Case 2: 1 scenario adustment function for this scenario of the FF type + if (length(unique(scenData[((j - 1) * nreg + 1):(j * nreg), "R Scenario Function"])) == 1) { + scenFunc <- as.character(scenData[1 + (j - 1) * nreg, "R Scenario Function"]) + scenFunc <- source(file = paste0(scenFunc, ".r"))[[1]] + ffTypeScenData[[i]][[scen[j]]] <- scenFunc(ffTypeData[[i]], scenData[((j - 1) * nreg + 1):(j * nreg), which(grepl("Data", colnames(scenData)))]) + # Case 3: Different scenario adjustment functions across regions within the scenario of the FF type + } else { + ffTypeScenData[[i]][[scen[j]]] <- array(NA, dim = dim(ffTypeData[[i]])) + # Read and use the scenario function for each region for (k in 1:nreg) { - scenFunc <- as.character(scenData[k+(j-1)*nreg,"R Scenario Function"]) - scenFunc <- source(file=paste0(scenFunc,".r"))[[1]] - ffTypeScenData[[i]][[scen[j]]][k,,] <- scenFunc(array(ffTypeData[[i]][k,,],dim=c(1,dim(ffTypeData[[i]])[2],2)), - scenData[k+(j-1)*nreg,which(grepl("Data",colnames(scenData)))]) + scenFunc <- as.character(scenData[k + (j - 1) * nreg, "R Scenario Function"]) + scenFunc <- source(file = paste0(scenFunc, ".r"))[[1]] + ffTypeScenData[[i]][[scen[j]]][k, , ] <- scenFunc( + array(ffTypeData[[i]][k, , ], dim = c(1, dim(ffTypeData[[i]])[2], 2)), + scenData[k + (j - 1) * nreg, which(grepl("Data", colnames(scenData)))] + ) } } } @@ -109,180 +110,152 @@ readGEA2012 <- function(subtype) { for (ii in names(ffTypeScenData)) { for (jj in scen) { grades <- dim(ffTypeScenData[[ii]][[jj]])[2] - tmp <- mbind(tmp,new.magpie(regions,NULL,paste(rep(c("costs","qtys"),each=grades),ii,jj,paste0("\"",as.character(1:grades),"\""),sep="."), - ffTypeScenData[[ii]][[jj]])) + tmp <- mbind(tmp, new.magpie( + regions, NULL, paste(rep(c("costs", "qtys"), each = grades), ii, jj, paste0("\"", as.character(1:grades), "\""), sep = "."), + ffTypeScenData[[ii]][[jj]] + )) } } - getSets(tmp) <- c("region","year","xi","type","scen","grade") - tmp <- toolNAreplace(tmp,replaceby=0)[[1]] - - - #Conversion to REMIND-readable data - - #Store regions, FF types, data type (xi), and scenarios from input data + getSets(tmp) <- c("region", "year", "xi", "type", "scen", "grade") + tmp <- toolNAreplace(tmp, replaceby = 0)[[1]] + + # Conversion to REMIND-readable data + + # Store regions, FF types, data type (xi), and scenarios from input data regions <- getRegions(tmp) - types <- getNames(tmp,fulldim=TRUE,"type") - scens <- getNames(tmp,fulldim=TRUE,"scen") - #Move SSP2 to the front - important for loop below - scens <- c("SSP2",scens[which(scens!="SSP2")]) - sets <- c("region","year","type","scen","xi","grade") - xis <- c(paste0('xi',1:3),"dec") - + scens <- getNames(tmp, fulldim = TRUE, "scen") + # Move SSP2 to the front - important for loop below + scens <- c("SSP2", scens[which(scens != "SSP2")]) + xis <- c(paste0("xi", 1:3), "dec") + # Cost grades taken from expert judgment of production cost curves by JH & NB (FFECCM) in 2012 - costGrades = list( - SSP1 = list( # US$(2005)/TWa + costGrades <- list( + SSP1 = list( # US$(2005)/TWa "oil_mea" = c(0.054909051, 0.093408501, 0.204015527, 0.747400879, 1.390996080, 2.076113553, 2.480955695, 3.170979198), "oil_row" = c(0.109818102, 0.186817002, 0.276754241, 0.415222711, 0.747400879, 1.141862454, 2.480955695, 3.170979198), "gas_mea" = c(0.022089848, 0.060589298, 0.080943515, 0.236355064, 0.286536888, 0.863137859, 3.170979198), "gas_row" = c(0.044179696, 0.121178596, 0.157626845, 0.236355064, 0.350155651, 0.863137859, 3.170979198), "coal" = c(0.0158548960, 0.0761035008, 0.0919583968, 0.1331811263, 0.1997716895, 0.2980720446, 0.9512937595) ), - SSP2 = list( # US$(2005)/TWa + SSP2 = list( # US$(2005)/TWa "oil_mea" = c(0.048594510, 0.082666523, 0.165612325, 0.328856387, 0.493284580, 0.918057413, 1.637430759, 3.170979198), "oil_row" = c(0.069185405, 0.117694711, 0.174355172, 0.257059564, 0.493284580, 0.918057413, 1.637430759, 3.170979198), "gas_mea" = c(0.019549516, 0.036585522, 0.071635011, 0.201339499, 0.262616738, 0.779742897, 3.170979198), "gas_row" = c(0.027833209, 0.076342515, 0.108871395, 0.198808634, 0.262616738, 0.779742897, 3.170979198), "coal" = c(0.0158548960, 0.0761035008, 0.0919583968, 0.1331811263, 0.1997716895, 0.2980720446, 0.9512937595) ), - SSP5 = list( # US$(2005)/TWa + SSP5 = list( # US$(2005)/TWa "oil_mea" = c(0.027454526, 0.046704250, 0.093566286, 0.304322191, 0.463490897, 0.909855311, 1.240477848, 3.170979198), "oil_row" = c(0.027454526, 0.046704250, 0.102007763, 0.166089084, 0.332003705, 0.546535439, 1.240477848, 3.170979198), "gas_mea" = c(0.011044924, 0.030294649, 0.040471758, 0.094670778, 0.175077825, 0.416974811, 3.170979198), "gas_row" = c(0.011044924, 0.030294649, 0.043864127, 0.094670778, 0.175077825, 0.416974811, 3.170979198), "coal" = c(0.0158548960, 0.0761035008, 0.0919583968, 0.1331811263, 0.1997716895, 0.2980720446, 0.9512937595) - ) + ) ) - + if ("grades2poly" %in% subtype) { - #More granular function for grades2poly parametrization + # More granular function for grades2poly parametrization for (ssp in names(costGrades)) { for (type in names(costGrades[[ssp]])) { - costGrades[[ssp]][[type]] <- seq(min(costGrades[[ssp]][[type]]),max(costGrades[[ssp]][[type]]),length.out = 50) + costGrades[[ssp]][[type]] <- seq(min(costGrades[[ssp]][[type]]), max(costGrades[[ssp]][[type]]), length.out = 50) } } } # IEA decline rate data from WEO 2008/09 - if (subtype=="oil") { - sp_IEADecRat <- new.magpie(c("MEA", "EUR", "USA", "JPN", "RUS", "LAM", "CHN", "IND", "OAS", "AFR", "ROW"),years=NULL,names=c("conv","unconv"),fill=0) - sp_IEADecRat[,,"conv"] <- c(0.034, 0.119, 0.097, 0.126, 0.058, 0.066, 0.067, 0.067, 0.067, 0.068, 0.067) - sp_IEADecRat[,,"unconv"] <- c(0.150, 0.150, 0.150, 0.150, 0.150, 0.150, 0.150, 0.150, 0.150, 0.150, 0.150) - }else if (subtype=="gas") { - sp_IEADecRat <- new.magpie(c("MEA", "EUR", "USA", "JPN", "RUS", "LAM", "CHN", "IND", "OAS", "AFR", "ROW"),years=NULL,names=c("conv","unconv"),fill=0) - sp_IEADecRat[,,"conv"] <- c(0.041, 0.111, 0.111, 0.111, 0.041, 0.111, 0.082, 0.082, 0.082, 0.082, 0.111) - sp_IEADecRat[,,"unconv"] <- c(0.150, 0.150, 0.150, 0.150, 0.150, 0.150, 0.150, 0.150, 0.150, 0.150, 0.150) + if (subtype == "oil") { + sp_IEADecRat <- new.magpie(c("MEA", "EUR", "USA", "JPN", "RUS", "LAM", "CHN", "IND", "OAS", "AFR", "ROW"), years = NULL, names = c("conv", "unconv"), fill = 0) + sp_IEADecRat[, , "conv"] <- c(0.034, 0.119, 0.097, 0.126, 0.058, 0.066, 0.067, 0.067, 0.067, 0.068, 0.067) + sp_IEADecRat[, , "unconv"] <- c(0.150, 0.150, 0.150, 0.150, 0.150, 0.150, 0.150, 0.150, 0.150, 0.150, 0.150) + } else if (subtype == "gas") { + sp_IEADecRat <- new.magpie(c("MEA", "EUR", "USA", "JPN", "RUS", "LAM", "CHN", "IND", "OAS", "AFR", "ROW"), years = NULL, names = c("conv", "unconv"), fill = 0) + sp_IEADecRat[, , "conv"] <- c(0.041, 0.111, 0.111, 0.111, 0.041, 0.111, 0.082, 0.082, 0.082, 0.082, 0.111) + sp_IEADecRat[, , "unconv"] <- c(0.150, 0.150, 0.150, 0.150, 0.150, 0.150, 0.150, 0.150, 0.150, 0.150, 0.150) } - mappingREM11 <- toolGetMapping("regionmappingREMIND.csv","regional", where = "mappingfolder") - mappingGEA <- toolGetMapping("regionmappingGEA2012.csv","regional", where = "mappingfolder") - w <- read.csv(paste0(getConfig("sourcefolder"),"/BGR/",subtype,"_reserves.csv"),header=TRUE,sep=";")[,c("Land_Region","Reserves","Resources")] - #Remove NAs - w[is.na(w)] <- 0 - #Convert to magpie for use as a disaggregation weight, convert countries to ISO code and set missing countries to 0 - w <- as.magpie(w,spatial=1,temporal=0,datacol=2) - getRegions(w) <- toolCountry2isocode(getRegions(w)) - w <- toolNAreplace(toolCountryFill(w,fill=0))[[1]] - #Disaggregate the GEA data according to the BGR data on country-level oil/gas combined reserves + resources - w <- dimSums(w,dim=3) - sp_IEADecRat <- toolAggregate(sp_IEADecRat,mappingREM11,weight=NULL) - sp_IEADecRat <- toolAggregate(sp_IEADecRat,mappingGEA,weight=w) - #ordered_names <- list(SSP1=getNames(tmp[,,'qtys'][,,"SSP1"]),SSP2=getNames(tmp[,,'qtys'][,,"SSP2"]),SSP5=getNames(tmp[,,'qtys'][,,"SSP5"])) + mappingREM11 <- toolGetMapping("regionmappingREMIND.csv", "regional", where = "mappingfolder") + mappingGEA <- toolGetMapping("regionmappingGEA2012.csv", "regional", where = "mappingfolder") + + w <- readSource("BGR", subtype = subtype, convert = FALSE)[, , c("Reserves", "Resources")] + getItems(w, dim = 1) <- toolCountry2isocode(getRegions(w)) + w <- toolNAreplace(toolCountryFill(w, fill = 0, verbosity = 2))[[1]] + # Disaggregate the GEA data according to the BGR data on country-level oil/gas combined reserves + resources + w <- dimSums(w, dim = 3) + sp_IEADecRat <- toolAggregate(sp_IEADecRat, mappingREM11, weight = NULL) + sp_IEADecRat <- toolAggregate(sp_IEADecRat, mappingGEA, weight = w) + ordered_names <- list(list()) - cum_qtys <- list() + for (scen in names(costGrades)) { for (r in regions) { - tmp[r,,'qtys'][,,scen] <- tmp[r,,'qtys'][,,scen][order(tmp[r,,'costs'][,,scen])] * EJ_2_TWyr - ordered_names[[scen]][[r]] <- getNames(tmp[r,,'qtys'][,,scen])[order(tmp[r,,'costs'][,,scen])] - tmp[r,,'costs'][,,scen] <- tmp[r,,'costs'][,,scen][order(tmp[r,,'costs'][,,scen])] * EJ_2_TWyr + tmp[r, , "qtys"][, , scen] <- tmp[r, , "qtys"][, , scen][order(tmp[r, , "costs"][, , scen])] * EJ_2_TWyr + ordered_names[[scen]][[r]] <- getNames(tmp[r, , "qtys"][, , scen])[order(tmp[r, , "costs"][, , scen])] + tmp[r, , "costs"][, , scen] <- tmp[r, , "costs"][, , scen][order(tmp[r, , "costs"][, , scen])] * EJ_2_TWyr } - - #For plotting cumulative production cost curve - #cum_qtys[[scen]] <- cumsum(as.numeric(dimSums(tmp[,,'qtys'][,,scen],dim=1))) } - - #For plotting cumulative production cost curve - #return(data.frame(qtys=cum_qtys$SSP2/EJ_2_TWyr,costs=as.numeric(tmp[r,,'costs'][,,"SSP2"])/EJ_2_TWyr,type=substr(ordered_names[["SSP2"]][[r]],6,8))) - - row <- paste0(subtype,'_row') - mea <- paste0(subtype,'_mea') - ngrades <- length(costGrades[['SSP2']][[row]])-1 - out <- new.magpie(regions,ttot,paste(paste0("pe",subtype),rep(names(costGrades),each=ngrades*length(xis)),rep(xis,each=ngrades),as.character(1:ngrades),sep="."),fill=0) - conv <- new.magpie(regions,ttot,paste(rep(names(costGrades),each=ngrades),"dec",as.character(1:ngrades),sep="."),fill=0) - unconv <- new.magpie(regions,ttot,paste(rep(names(costGrades),each=ngrades),"dec",as.character(1:ngrades),sep="."),fill=0) - + + row <- paste0(subtype, "_row") + mea <- paste0(subtype, "_mea") + ngrades <- length(costGrades[["SSP2"]][[row]]) - 1 + out <- new.magpie(regions, ttot, paste(paste0("pe", subtype), rep(names(costGrades), each = ngrades * length(xis)), rep(xis, each = ngrades), as.character(1:ngrades), sep = "."), fill = 0) + conv <- new.magpie(regions, ttot, paste(rep(names(costGrades), each = ngrades), "dec", as.character(1:ngrades), sep = "."), fill = 0) + unconv <- new.magpie(regions, ttot, paste(rep(names(costGrades), each = ngrades), "dec", as.character(1:ngrades), sep = "."), fill = 0) + for (s in scens) { if (s %in% names(costGrades)) { - #if (s=="SSP2") { t <- ttot - #}else { - # t <- ttot[which(ttot>=t_cutoff)] - #} for (r in regions) { i <- 1 - costs <- as.numeric(tmp[r,,s][,,'costs']) - if (r=="MEE" || r=="FSU") { + costs <- as.numeric(tmp[r, , s][, , "costs"]) + if (r == "MEE" || r == "FSU") { grades <- costGrades[[s]][[mea]] - }else { + } else { grades <- costGrades[[s]][[row]] } - ngrades <- length(grades)-1 + ngrades <- length(grades) - 1 for (g in 1:ngrades) { - if (g==1) { - grades[g] <- min(costs[1],grades[1]) - }else if (g==ngrades) { - grades[g+1] <- max(costs[i],grades[g+1]) + if (g == 1) { + grades[g] <- min(costs[1], grades[1]) + } else if (g == ngrades) { + grades[g + 1] <- max(costs[i], grades[g + 1]) } - out[r,t,paste0(s,'.xi1')][,,g] <- grades[g] - out[r,t,paste0(s,'.xi2')][,,g] <- grades[g+1] + out[r, t, paste0(s, ".xi1")][, , g] <- grades[g] + out[r, t, paste0(s, ".xi2")][, , g] <- grades[g + 1] for (c in i:(length(costs))) { - if (costs[c] <= grades[g+1] && costs[c] >= grades[g] && tmp[r,,'qtys'][,,s][,,c]>0) { - out[r,t,paste0(s,'.xi3')][,,g] <- out[r,t,paste0(s,'.xi3')][,,g] + tmp[r,,'qtys'][,,s][,,c] - #Distinguish between conventional and unconventional reservoirs in each cost grade to calculate decline rates - if (grepl('CO',ordered_names[[s]][[r]][c])) { - conv[r,t,s][,,g] <- conv[r,t,s][,,g] + tmp[r,,'qtys'][,,s][,,c] - }else { - unconv[r,t,s][,,g] <- unconv[r,t,s][,,g] + tmp[r,,'qtys'][,,s][,,c] + if (costs[c] <= grades[g + 1] && costs[c] >= grades[g] && tmp[r, , "qtys"][, , s][, , c] > 0) { + out[r, t, paste0(s, ".xi3")][, , g] <- out[r, t, paste0(s, ".xi3")][, , g] + tmp[r, , "qtys"][, , s][, , c] + # Distinguish between conventional and unconventional reservoirs in each cost grade to calculate decline rates + if (grepl("CO", ordered_names[[s]][[r]][c])) { + conv[r, t, s][, , g] <- conv[r, t, s][, , g] + tmp[r, , "qtys"][, , s][, , c] + } else { + unconv[r, t, s][, , g] <- unconv[r, t, s][, , g] + tmp[r, , "qtys"][, , s][, , c] } - }else if (costs[c] > grades[g+1]) { + } else if (costs[c] > grades[g + 1]) { i <- c break } } } } - #out[,,s][,,'xi3'] <- conv[,,s] + unconv[,,s] - #Introduce time dependence of grades: costs start at SSP2 levels in initial year and change linearly until the cutoff year - if (s!="SSP2") { - m1 <- (out[,t_cutoff,'xi1'][,,s] - out[,t0,'xi1'][,,'SSP2'])/t_trans - m2 <- (out[,t_cutoff,'xi2'][,,s] - out[,t0,'xi2'][,,'SSP2'])/t_trans - m3 <- (out[,t_cutoff,'xi3'][,,s] - out[,t0,'xi3'][,,'SSP2'])/t_trans - out[,getYears(out)= out[r1,t1,'xi1'][,,s][,,g1] && tmp[r1,,'costs'][,,s][,,c1] <= out[r1,t1,'xi2'][,,s][,,g1]) { - # out[r1,t1,'xi3'][,,s][,,g1] <- out[r1,t1,'xi3'][,,s][,,g1] + tmp[r1,,'qtys'][,,s][,,c1] - # }else if (tmp[r1,,'costs'][,,s][,,c1] > out[r1,t1,'xi2'][,,s][,,g1]) { - # j <- c1 - # break - # } - # } - # } - #} + # Introduce time dependence of grades: costs start at SSP2 levels in initial year and change linearly until the cutoff year + if (s != "SSP2") { + m1 <- (out[, t_cutoff, "xi1"][, , s] - out[, t0, "xi1"][, , "SSP2"]) / t_trans + m2 <- (out[, t_cutoff, "xi2"][, , s] - out[, t0, "xi2"][, , "SSP2"]) / t_trans + m3 <- (out[, t_cutoff, "xi3"][, , s] - out[, t0, "xi3"][, , "SSP2"]) / t_trans + out[, getYears(out) < paste0("y", t0), !"dec" %in% getNames(out)][, , s] <- out[, getYears(out) < paste0("y", t0), !"dec" %in% getNames(out)][, , "SSP2"] + for (t1 in seq(t0, t_cutoff - ts1, ts1)) { + out[, t1, "xi1"][, , s] <- out[, t1, "xi1"][, , "SSP2"] + m1 * (t1 - t0) + out[, t1, "xi2"][, , s] <- out[, t1, "xi2"][, , "SSP2"] + m2 * (t1 - t0) + out[, t1, "xi3"][, , s] <- out[, t1, "xi3"][, , "SSP2"] + m3 * (t1 - t0) } } - #Calculate decline rates - convRatio <- conv[,,s]/(unconv[,,s]+conv[,,s]) - convRatio[which(unconv[,,s]==0)] <- 1 - convRatio[which(conv[,,s]==0)] <- 0 - out[,,s][,,'dec'] <- (sp_IEADecRat[,,"conv"] * convRatio) + (sp_IEADecRat[,,"unconv"] * (1-convRatio)) + # Calculate decline rates + convRatio <- conv[, , s] / (unconv[, , s] + conv[, , s]) + convRatio[which(unconv[, , s] == 0)] <- 1 + convRatio[which(conv[, , s] == 0)] <- 0 + out[, , s][, , "dec"] <- (sp_IEADecRat[, , "conv"] * convRatio) + (sp_IEADecRat[, , "unconv"] * (1 - convRatio)) for (regi in regions) { - out[regi,,paste0(s,".dec.1")][which(out[regi,,paste0(s,".dec.1")]==sp_IEADecRat[regi,,"unconv"])] <- - sp_IEADecRat[regi,,"conv"] + out[regi, , paste0(s, ".dec.1")][which(out[regi, , paste0(s, ".dec.1")] == sp_IEADecRat[regi, , "unconv"])] <- + sp_IEADecRat[regi, , "conv"] } } } diff --git a/R/readGGDC10.R b/R/readGGDC10.R index 6092f9f9..f24f8968 100644 --- a/R/readGGDC10.R +++ b/R/readGGDC10.R @@ -5,20 +5,16 @@ #' a <- readSource("GGDC10",convert=F) #' } #' -#' @importFrom magclass as.magpie #' @importFrom readxl read_excel #' @importFrom tidyr gather -#' @importFrom dplyr %>% #' readGGDC10 <- function() { - Sector <- Value <- NULL # empty declarations of variables used in dplyr operations - - data <- read_xlsx(path = "ggdc10.xlsx", sheet = "dataset") + data <- suppressWarnings(read_xlsx(path = "ggdc10.xlsx", sheet = "dataset")) dataLong <- data[, -c(2, 3)] %>% - gather(Sector, Value, -c(1:3)) + gather("Sector", "Value", -c(1:3)) x <- as.magpie(dataLong, spatial = 1, temporal = 3, datacol = 5) diff --git a/R/readGlobalCCSinstitute.R b/R/readGlobalCCSinstitute.R index 31be07ef..055909f1 100644 --- a/R/readGlobalCCSinstitute.R +++ b/R/readGlobalCCSinstitute.R @@ -1,25 +1,43 @@ +#' Read Global CCS Institute Project Database +#' +#' @md +#' @param subtype Project Database version to read, one of +#' - `'08-09-2017'`: Data apparently from June 2017. +#' - `'2023-11'`: Data from the +#' [Global Status of CCS 2023](zotero://select/items/3_E5GNNPZ8) report. +#' +#' @return A [`magpie`][magclass::magclass] object. +#' +#' @importFrom dplyr mutate select +#' @importFrom quitte madrat_mule +#' @importFrom readr read_csv #' @importFrom readxl read_excel +#' +#' @export +readGlobalCCSinstitute <- function(subtype = '08-09-2017') { + if ('08-09-2017' == subtype) { # 08-09-2017 ---- + . <- NULL + read_excel("status-ccs-project-database-current-08-09-2017.xlsx", + skip = 3) %>% + select('Country', 'State / district', 'CO2 capture capacity (Mtpa)', + 'Operation date', 'Industry') %>% + # use approximated values, or upper values from ranges + mutate(value = as.numeric(sub('^(Approx. |[0-9]+\\.[0-9]+-)', '', + .data$`CO2 capture capacity (Mtpa)`)), + .keep = 'unused') %>% + as.magpie(spatial = 1, datacol = 5) %>% + `[<-`(is.na(.), value = 0) %>% + return() + } + else if ('2023-11' == subtype) { # 2023-11 ---- + read_csv(file = 'Global_Status_of_CCS_2023-11.csv', col_types = 'cccicnc', + na = 'Under Evaluation', comment = '#', trim_ws = TRUE) %>% + madrat_mule() %>% + return() + } + else { + stop('Unsupported version argument.') + } +} -readGlobalCCSinstitute<- function() { - - x <- read_excel("status-ccs-project-database-current-08-09-2017.xlsx",skip=3) - # delete not needed information - x$`Facility name (click on link to view)` <- NULL - x$`Lifecycle stage` <- NULL - #x$Industry <- NULL - x$`Capture type` <- NULL - x$`Transport type` <- NULL - x$`Transport length (km)` <- NULL - x$`Primary storage type` <- NULL - # transfer CO2 capture rate into one numeric number - x$value <- gsub("Approx. ","",x$`CO2 capture capacity (Mtpa)`) - x$value <- gsub("[0-9].[0-9]-","",x$value) - x$`CO2 capture capacity (Mtpa)` <- NULL - # transfer x$value into numeric - x$value <- as.numeric(x$value) - # convert into a magpie object - x <- as.magpie(x,spatial=1,datacol=5) - x[is.na(x)] <- 0 - return(x) -} diff --git a/R/readGlobalEnergyMonitor.R b/R/readGlobalEnergyMonitor.R index 421f7139..56687c93 100644 --- a/R/readGlobalEnergyMonitor.R +++ b/R/readGlobalEnergyMonitor.R @@ -1,136 +1,115 @@ #' Read Global Energy Monitor data #' -#' @return A [`magpie`][magclass::magclass] object. +#' read GEM data for all available technologies and relevant statuses #' -#' @author Falk Benke +#' @author Rahel Mandaroux, Falk Benke, Pascal Weigmann #' -#' @seealso [`readSource()`] -#' -#' @importFrom dplyr %>% filter mutate select -#' -#' @importFrom magclass as.magpie +#' @importFrom dplyr filter mutate select #' @importFrom readxl read_xlsx #' @importFrom rlang sym #' -#' #' @export readGlobalEnergyMonitor <- function() { - notebooks <- list( - "Bioenergy" = list( - file = "Global-Bioenergy-Power-Tracker-January-2023.xlsx", - variable = "Cap|Electricity|Biomass", - statusCol = "Operating Status" - ), - "Hydropower" = list( - file = "Global-Hydropower-Tracker-May-2023.xlsx", - variable = "Cap|Electricity|Hydro", - # Hydro Power might affect 2 countries, we assign it to the first one - countryCol = "Country 1", - startCol = "Start Year", - endCol = "Retired Year" - ), - "Nuclear" = list( - file = "Global-Nuclear-Power-Tracker-January-2023.xlsx", - variable = "Cap|Electricity|Nuclear", - startCol = "Start Year", - endCol = "Retired Year" - ), - "Solar" = list( - file = "Global-Solar-Power-Tracker-May-2023.xlsx", - variable = "Cap|Electricity|Solar" - ), - "Wind Offshore" = list( - file = "Global-Wind-Power-Tracker-May-2023.xlsx", - variable = "Cap|Electricity|Wind|Offshore", - typeCol = "Installation Type", - typeVals = c("offshore hard mount", "offshore mount unknown", "offshore floating") - ), - "Wind Onshore" = list( - file = "Global-Wind-Power-Tracker-May-2023.xlsx", - variable = "Cap|Electricity|Wind|Onshore", - typeCol = "Installation Type", - typeVals = c("onshore") - ), - "Coal" = list( - file = "Global-Coal-Plant-Tracker-July-2023.xlsx", - variable = "Cap|Coal", - sheetName = "Units", - projectCol = "Plant name" - ) - ) + # GEM GIPT 2024 + # file available after filling out questionnaire: + # https://globalenergymonitor.org/projects/global-integrated-power-tracker/download-data/ + d <- read_excel("Global-Integrated-Power-June-2024.xlsx", + sheet = "Power facilities", + trim_ws = TRUE, + col_types = "text") %>% + select(variable = "Type", + tech = "Technology", + region = "Country/area", + value = "Capacity (MW)", + status = "Status", + start = "Start year", + end = "Retired year", + # hydropower specific columns for shared projects + c1 = "Country/area 1 (hydropower only)", + c2 = "Country/area 2 (hydropower only)", + v1 = "Country/area 1 Capacity (MW) (hydropower only)", + v2 = "Country/area 2 Capacity (MW) (hydropower only)") %>% + filter(status %in% c("announced", "pre-construction", "construction", "operating")) %>% + # ASSUMPTION: rows with empty start year are ignored + # only look at pipeline until 2030 + filter(!is.na(start), start < 2031) %>% + # Oil/Gas needs to be separated by technology or fuel (seems complicated?) + # remove for now + filter(variable != "oil/gas") %>% + mutate(start = as.numeric(start), end = as.numeric(end), value = as.numeric(value)) - out <- NULL + # no end year defined: + # use average lifetime of technology (from generisdata_tech) + lifetime <- c(coal = 40, bioenergy = 40, nuclear = 50, hydropower = 130, + geothermal = 30, wind = 25, solar = 30) + for (tech in names(lifetime)) { + d[is.na(d$end) & d$variable == tech, "end"] <- + d[is.na(d$end) & d$variable == tech, "start"] + lifetime[[tech]] + } - for (nb in notebooks) { - cols <- c( - "region" = ifelse(is.null(nb$countryCol), "Country", nb$countryCol), - "project" = ifelse(is.null(nb$projectCol), "Project Name", nb$projectCol), - "value" = "Capacity (MW)", - "status" = ifelse(is.null(nb$statusCol), "Status", nb$statusCol), - "start" = ifelse(is.null(nb$startCol), "Start year", nb$startCol), - "end" = ifelse(is.null(nb$endCol), "Retired year", nb$endCol) - ) + # special case hydropower: some projects are divided between 2 countries + # find all of these cases and put them in 2 rows, one per country + d <- rbind( + d[is.na(d$c2), ], + d[!is.na(d$c2), ] %>% mutate(region = c1, value = as.numeric(v1)), + d[!is.na(d$c2), ] %>% mutate(region = c2, value = as.numeric(v2)) + ) %>% + select(-c1, -c2, -v1, -v2) - if (!is.null(nb$typeCol)) { - cols <- c(cols, "type" = nb$typeCol) - } + # use proper variable names + d[d$variable == "coal", "variable"] <- "Cap|Electricity|Coal" + d[d$variable == "bioenergy", "variable"] <- "Cap|Electricity|Biomass" + d[d$variable == "nuclear", "variable"] <- "Cap|Electricity|Nuclear" + d[d$variable == "geothermal", "variable"] <- "Cap|Electricity|Geothermal" - data <- read_excel( - path = nb$file, - sheet = ifelse(is.null(nb$sheetName), "Data", nb$sheetName), - trim_ws = TRUE, col_types = "text" - ) %>% - select(all_of(cols)) %>% - mutate( - !!sym("value") := as.numeric(!!sym("value")), - !!sym("start") := as.numeric(!!sym("start")), - !!sym("end") := as.numeric(!!sym("end")) - ) + # remove pumped storage, keep ca. 3 GW of "conventional and pumped storage" + d <- d[!d$tech %in% "pumped storage", ] + d[d$variable == "hydropower", "variable"] <- "Cap|Electricity|Hydro" - if (!is.null(nb$typeCol)) { - data <- data %>% - filter( - !!sym("type") %in% nb$typeVals - ) %>% - select(-"type") - } + # separate wind into on- and offshore, "Unknown"/"blank" are all onshore + offshore_tech <- c("Offshore hard mount", "Offshore floating", "Offshore mount unknown") + d[d$variable == "wind" & d$tech %in% offshore_tech, "variable"] <- "Cap|Electricity|Wind|Offshore" + d[d$variable == "wind", "variable"] <- "Cap|Electricity|Wind|Onshore" + # separate solar into PV and CSP (called "Solar Thermal" by GEM) + d[d$variable == "solar" & d$tech == "Solar Thermal", "variable"] <- "Cap|Electricity|Solar|CSP" + d[d$variable == "solar", "variable"] <- "Cap|Electricity|Solar|PV" - # read in completed projects - completed <- data %>% filter(!is.na(!!sym("start")), !is.na(!!sym("end"))) + # transform data from list of capacities with start and end date + # to sum of active capacities in 2025 and 2030 + d <- mutate(d, end = pmin(end, 2030)) # improves performance of next step + tmp_list <- vector("list", nrow(d)) + for (i in seq_len(nrow(d))) { + tmp_list[[i]] <- data.frame( + d[i, c("region", "value", "variable", "status")], + period = seq(as.numeric(d[i, "start"]), as.numeric(d[i, "end"]), 1) + ) + } + tmp <- do.call(rbind, tmp_list) %>% + group_by(region, variable, status, period) %>% + summarise(value = sum(value)) %>% + filter(period %in% c(2025, 2030)) - # read in projects with start year and no retirement, as well as a status - # indicating probable realization, assume them running until 2050 - # rows with empty start year are ignored - status <- c("announced", "pre-construction", "construction", "operating") - ongoing <- data %>% - filter( - !is.na(!!sym("start")), is.na(!!sym("end")), - !!sym("status") %in% status - ) %>% - mutate(!!sym("end") := 2050) + # convert to magclass object + x <- as.magpie(tmp, spatial = "region") + x[is.na(x)] <- 0 - production <- rbind(completed, ongoing) - tmp <- NULL - for (i in seq_len(nrow(production))) { - d <- data.frame( - production[i, c("region", "value", "project")], - period = seq(as.numeric(production[i, "start"]), as.numeric(production[i, "end"]), 1) - ) - tmp <- rbind(tmp, d) - } - cap <- aggregate(value ~ region + period, data = tmp, FUN = sum) %>% - mutate(!!sym("variable") := nb$variable) %>% - select("region", "period", "variable", "value") + # add solar and wind totals as variables + x <- mbind( + x, + dimSums(x[, , c("Cap|Electricity|Solar|PV", "Cap|Electricity|Solar|CSP")], dim = 3.1) %>% + add_dimension(dim = 3.1, add = "variable", nm = "Cap|Electricity|Solar"), + dimSums(x[, , c("Cap|Electricity|Wind|Offshore", "Cap|Electricity|Wind|Onshore")], dim = 3.1) %>% + add_dimension(dim = 3.1, add = "variable", nm = "Cap|Electricity|Wind") + ) - out <- rbind(out, cap) - } - x <- as.magpie(out, spatial = 1) + # collapse variable and status dimension into one + # getNames(x) <- gsub(pattern = "\\.", replacement = "|", x = getNames(x)) - # convert to GW + # convert MW to GW x <- x / 1000 - x <- add_dimension(x, dim = 3.2, add = "unit", nm = "GW") - x <- add_dimension(x, dim = 3.1, add = "model", nm = "Global Energy Monitor") + x <- add_dimension(x, dim = 3.4, add = "unit", nm = "GW") + x <- add_dimension(x, dim = 3.1, add = "model", nm = "GlobalEnergyMonitor") return(x) } diff --git a/R/readHRE.R b/R/readHRE.R index 8d0c16e2..fe59cd66 100644 --- a/R/readHRE.R +++ b/R/readHRE.R @@ -8,7 +8,6 @@ #' @source https://heatroadmap.eu/roadmaps/ #' #' @importFrom dplyr select -#' @importFrom magclass as.magpie #' @importFrom tidyr separate #' @importFrom readxl read_xlsx #' @@ -31,7 +30,7 @@ readHRE <- function() { x <- as.magpie(df, spatial="Country", temporal="year", tidy = TRUE) # change country code to iso3 - getItems(x, dim=1) <- countrycode(getItems(x, dim=1), "eurostat", "iso3c") + getItems(x, dim=1) <- countrycode::countrycode(getItems(x, dim=1), "eurostat", "iso3c") getSets(x)[1] <- "region" return(x) diff --git a/R/readIAEA.R b/R/readIAEA.R index 54d6a4b2..e55f7aec 100644 --- a/R/readIAEA.R +++ b/R/readIAEA.R @@ -1,29 +1,27 @@ #' Nuclear data from world-nuclear.org -#' @description Data on currently operating and under-construction nuclear power plants, reactors planned and proposed, -#' electricity generation from nuclear +#' @description Data on currently operating and under-construction nuclear power plants, reactors planned and proposed, +#' electricity generation from nuclear #' @author Christoph Bertram #' @importFrom dplyr bind_rows -readIAEA <- function(){ - - x_2016 <- read.csv("January2016.csv",sep=";",skip=2,check.names=FALSE) +readIAEA <- function() { + x_2016 <- read.csv("January2016.csv", sep = ";", skip = 2, check.names = FALSE) x_2016$YEAR <- 2016 - x_2018 <- read.csv("August2018.csv",sep=";",skip=2,check.names=FALSE) + x_2018 <- read.csv("August2018.csv", sep = ";", skip = 2, check.names = FALSE) x_2018$YEAR <- 2018 - x_2020 <- read.csv("April2020.csv",sep=",",skip=2,check.names=FALSE) + x_2020 <- read.csv("April2020.csv", sep = ",", skip = 2, check.names = FALSE) x_2020$YEAR <- 2020 - x_2020$COUNTRY <- gsub(pattern = "UAE",replacement = "United Arab Emirates",x = x_2020$COUNTRY) - x <- bind_rows(x_2016,x_2018,x_2020) + x_2020$COUNTRY <- gsub(pattern = "UAE", replacement = "United Arab Emirates", x = x_2020$COUNTRY) + x <- bind_rows(x_2016, x_2018, x_2020) # rearranging columns so magpie object can be easily created - x <- x[,c(1,13,2:12)] - x <- as.magpie(x,spatial=1,temporal=2,datacol=3) - - # the number of countries in 2020 are 43, whereas in 2016 and 2018 are 51. - # The no. of countries in the former are fewer because many of the - # planned or proposed plants in 2016 and 2018 have been shelved. + x <- x[, c(1, 13, 2:12)] + x <- as.magpie(x, spatial = 1, temporal = 2, datacol = 3) + + # the number of countries in 2020 are 43, whereas in 2016 and 2018 are 51. + # The no. of countries in the former are fewer because many of the + # planned or proposed plants in 2016 and 2018 have been shelved. # Thus, all these countries get "0" for all columns with values. x[is.na(x)] <- 0 - - + return(x) } diff --git a/R/readIEA_CCUS.R b/R/readIEA_CCUS.R new file mode 100644 index 00000000..e49277a8 --- /dev/null +++ b/R/readIEA_CCUS.R @@ -0,0 +1,190 @@ +#' Read IEA CCUS data +#' +#' Reads in capacities from projects in IEA CCUS database +#' +#' @author Anne Merfort, Falk Benke +#' +#' @param subtype either `historical` for data until 2023, +#' `projections` for "high" and "low" projections up to 2030 used as input-data +#' or `pipeline` separated by status for use in formulating near-term bounds +#' @importFrom dplyr filter mutate select +#' @importFrom readxl read_xlsx +#' +#' @export +readIEA_CCUS <- function(subtype) { + # ASSUMPTION: transport and storage are limiting factors for CCS + # project types filter applied to source + projectTypes <- c("Full chain", "Storage", "T&S") + + data <- read_excel("IEA CCUS Projects Database 2024.xlsx", + sheet = "CCUS Projects Database" + ) %>% + select( + "project" = "Project name", + "country" = "Country", + "type" = "Project type", + "start" = "Operation", + "end" = "Suspension/decommissioning", + "status" = "Project Status", + "value" = "Estimated capacity by IEA (Mt CO2/yr)" + ) %>% + # remove entries without announced capacities and not matching project type + filter(!is.na(.data$value), .data$type %in% projectTypes) + + # manually assign shared project(s) to one (currently: first) country + data[data$project == "EU2NSEA", "country"] <- "Norway" + data[data$country == "Japan-unknown", "country"] <- "Japan" + + # correct typo in IEA Data + data[data$country == "Lybia", "country"] <- "Libya" + + # share capacities of projects by multiple countries according to their GDP + gdp <- calcOutput("GDP", aggregate = FALSE) + gdp_JPN <- as.numeric(gdp["JPN", 2020, "gdp_SSP2EU"]) + gdp_AUS <- as.numeric(gdp["AUS", 2020, "gdp_SSP2EU"]) + gdp_MYS <- as.numeric(gdp["MYS", 2020, "gdp_SSP2EU"]) + + JM <- data[data$country == "Japan-Malaysia", ] + AJ <- data[data$country == "Australia-Japan", ] + + # remove mixed-country data and attach single country data weighted by GDP + data <- data %>% + filter(!country %in% c("Japan-Malaysia", "Australia-Japan")) %>% + rbind( + mutate(JM, country = "Japan", value = value*gdp_JPN/(gdp_JPN+gdp_MYS)), + mutate(JM, country = "Malaysia", value = value*gdp_MYS/(gdp_JPN+gdp_MYS)), + mutate(AJ, country = "Australia", value = value*gdp_AUS/(gdp_JPN+gdp_AUS)), + mutate(AJ, country = "Japan", value = value*gdp_JPN/(gdp_JPN+gdp_AUS)) + ) + + if (subtype == "historical") { + hist <- data %>% + filter(.data$start <= 2023, + .data$status != "Suspended/cancelled/decommissioned") + # ASSUMPTION: if no end year is given, assume project remains active at + # least until present + hist[is.na(hist$end), "end"] <- 2023 + + tmp <- NULL + for (i in seq_len(nrow(hist))) { + tmp <- rbind( + tmp, + data.frame( + hist[i, c("country", "value")], + period = seq(as.numeric(hist[i, "start"]), as.numeric(hist[i, "end"]), 1) + ) + ) + } + + cap <- aggregate(value ~ country + period, data = tmp, FUN = sum) %>% + filter(.data$period <= 2023) %>% + mutate(variable = "Carbon Management|Storage") + + cap <- cap[, c("country", "period", "variable", "value")] + x <- as.magpie(cap, spatial = 1) + + } else if (subtype == "projections") { + + # ASSUMPTION: if empty start year, assume project start in 2030 + # end in 2030, unless decommissioned before + proj <- data %>% + mutate( + "start" = ifelse(is.na(.data$start), 2030, .data$start), + "end" = ifelse(is.na(.data$end), 2030, .data$end) + ) %>% + # remove entries where suspension is before operation or in same year + filter(.data$start < .data$end) + + # ASSUMPTION: low or high expectations for realized projects by status + statusLow <- c("Operational", "Under construction") + statusHigh <- c(statusLow, "Planned") + + proj <- proj %>% + filter(.data$status %in% statusHigh) + + # convert to data.frame with yearly active capacities + tmp <- NULL + for (i in seq_len(nrow(proj))) { + tmp <- rbind( + tmp, + data.frame( + proj[i, c("country", "status", "value")], + period = seq(as.numeric(proj[i, "start"]), as.numeric(proj[i, "end"]), 1) + ) + ) + } + + capLow <- aggregate(value ~ country + period, + data = filter(tmp, .data$status %in% statusLow), + FUN = sum + ) %>% + mutate(variable = "low") + + capHigh <- aggregate(value ~ country + period, + data = filter(tmp, .data$status %in% statusHigh), + FUN = sum + ) %>% + mutate(variable = "up") + + cap <- rbind(capLow, capHigh) + cap <- cap[, c("country", "period", "variable", "value")] + x <- as.magpie(cap, spatial = 1) + x <- x[, c(2020, 2025, 2030), ] + + } else if (subtype == "pipeline") { + + # ASSUMPTION: if empty start year, remove project + # assume projects run at least until 2030 + pipe <- data %>% + filter(!is.na(.data$start)) %>% + mutate("end" = ifelse(is.na(.data$end), 2030, .data$end)) %>% + # remove entries where suspension is before operation or in same year + filter(.data$start < .data$end) %>% + # remove cancelled projects + filter(.data$status != "Suspended/cancelled/decommissioned") + + # convert to data.frame with yearly active capacities + tmp <- NULL + for (i in seq_len(nrow(pipe))) { + tmp <- rbind( + tmp, + data.frame( + pipe[i, c("country", "status", "value")], + period = seq(as.numeric(pipe[i, "start"]), as.numeric(pipe[i, "end"]), 1) + ) + ) + } + + # aggregate by country and period, new variables depending on status + capOp <- aggregate(value ~ country + period, + data = filter(tmp, .data$status %in% "Operational"), + FUN = sum + ) %>% + mutate(status = "operational") + + capCon <- aggregate(value ~ country + period, + data = filter(tmp, .data$status %in% "Under construction"), + FUN = sum + ) %>% + mutate(status = "construction") + + capPlan <- aggregate(value ~ country + period, + data = filter(tmp, .data$status %in% "Planned"), + FUN = sum + ) %>% + mutate(status = "planned") + + cap <- rbind(capOp, capCon, capPlan) %>% + mutate(variable = "Carbon Management|Storage") + cap <- cap[, c("country", "period", "variable", "status", "value")] + x <- as.magpie(cap, spatial = 1) + + } else { + stop("Invalid subtype. Must be either + `historical`, `pipeline` or `projections`") + } + + x[is.na(x)] <- 0 + + return(x) +} diff --git a/R/readIEA_ETP.R b/R/readIEA_ETP.R index a7b8f4da..ee3adbc2 100644 --- a/R/readIEA_ETP.R +++ b/R/readIEA_ETP.R @@ -7,7 +7,6 @@ #' @importFrom readxl read_xlsx #' @importFrom tidyr drop_na pivot_longer extract #' @importFrom rlang sym -#' @importFrom magclass as.magpie readIEA_ETP <- function(subtype) { @@ -547,12 +546,12 @@ readIEA_ETP <- function(subtype) { # drop rownames from worksheet select(-1) %>% # add variable prefix - mutate(variable = paste0(subtypes[[subtype]]$prefix, "|", !!sym("variable"))) %>% + mutate("variable" = paste0(subtypes[[subtype]]$prefix, "|", !!sym("variable"))) %>% pivot_longer( cols = c(-"variable", -"unit"), names_to = "year", names_transform = list("year" = as.integer) ) %>% - mutate(region := sheet, scenario := scenario) + mutate("region" = sheet, "scenario" = scenario) ) } } diff --git a/R/readIEA_EVOutlook.R b/R/readIEA_EVOutlook.R index c0bf7155..1f0baced 100644 --- a/R/readIEA_EVOutlook.R +++ b/R/readIEA_EVOutlook.R @@ -2,18 +2,17 @@ #' #' @author Falk Benke readIEA_EVOutlook <- function() { - data <- read.csv2("data/2023/IEA Global EV Data 2023.csv", sep = ",") + data <- read.csv2(file.path("data", "2024", "IEA Global EV Data 2024.csv"), sep = ",") data <- data %>% mutate( - !!sym("variable") := sub("\\|NA", "", paste0(!!sym("parameter"), "|", !!sym("mode"), "|", !!sym("powertrain"))), - !!sym("value") := as.numeric(!!sym("value")), - !!sym("unit") := ifelse(is.na(!!sym("unit")), "no", !!sym("unit")) + "variable" = sub("\\|NA", "", paste0(.data$parameter, "|", .data$mode, "|", .data$powertrain)), + "value" = as.numeric(.data$value), + "unit" = ifelse(is.na(.data$unit), "no", .data$unit) ) %>% select("region", "year", "scenario" = "category", "variable", "unit", "value") x <- as.magpie(data, spatial = 1) - return(x) } diff --git a/R/readIEA_HSMR.R b/R/readIEA_HSMR.R new file mode 100644 index 00000000..09254a51 --- /dev/null +++ b/R/readIEA_HSMR.R @@ -0,0 +1,31 @@ +#' read IEA Hydro Special Market Report +#' +#' read Hydro capacities and near-term outlook from data scraped from +#' https://www.iea.org/data-and-statistics/data-tools/hydropower-data-explorer +#' +#' @author Pascal Weigmann +#' @importFrom readxl read_xlsx +#' +#' @export +readIEA_HSMR <- function() { + + x <- read_xlsx("IEA_Hydropower_Special_Market_Report.xlsx") %>% + # get capacities in 2030 by adding 2020 values to additions + # subtract pumped storage as it is not part of Cap Hydro in REMIND + mutate("2020_operational" = capacity_2020, + "2030_expected" = capacity_2020 + add_expected_2030 - of_that_pumped, + "2030_accelerated" = capacity_2020 + add_accelerated_2030 - of_that_pumped, + variable = "Cap|Electricity|Hydro") %>% + pivot_longer(cols = c("2020_operational", "2030_expected", "2030_accelerated"), + names_to = "year_scen") %>% + select(country, variable, year_scen, unit, value) %>% + separate(year_scen, c("year", "status")) %>% + as.magpie(spatial = "country") + + x[, 2020, "accelerated"] <- x[, 2020,"operational"] + x[, 2020, "expected"] <- x[, 2020,"operational"] + + x <- add_dimension(x, dim = 3.1, add = "model", nm = "IEA_HSMR") + + return(x) +} diff --git a/R/readIEA_PVPS.R b/R/readIEA_PVPS.R index 81b67347..f94ceb66 100644 --- a/R/readIEA_PVPS.R +++ b/R/readIEA_PVPS.R @@ -1,16 +1,13 @@ #' Reads PV investment cost data for 2020 which are based on 2018 data from IEA PVPS report -#' @description reads excel sheet with PV investment cost data +#' @description reads excel sheet with PV investment cost data #' @return magpie object with PV investment cost data #' @author Felix Schreyer #' @param subtype type of data read from IEA PVPS #' @importFrom readxl read_excel -#' @importFrom magclass collapseNames - - -readIEA_PVPS <- function(subtype){ +readIEA_PVPS <- function(subtype) { if (subtype == "CAPEX") { - IEA.PVPS <- read_excel("IEA_PVPS.xlsx", sheet = "IEA_PVPS_data") - x <- collapseNames(as.magpie(IEA.PVPS,spatial=1,datacol=2)) - } + IEA.PVPS <- read_excel("IEA_PVPS.xlsx", sheet = "IEA_PVPS_data") + x <- collapseNames(as.magpie(IEA.PVPS, spatial = 1, datacol = 2)) + } return(x) } diff --git a/R/readIEA_REN.R b/R/readIEA_REN.R index 4697dd7c..2bd759f0 100644 --- a/R/readIEA_REN.R +++ b/R/readIEA_REN.R @@ -1,18 +1,15 @@ -#' Reads the distributed solar pv capacity from IEA Renewables report (2019). -#' @details Capacity in GW. Distributed solar, defined in the IEA Renewables (2019), includes +#' Reads the distributed solar pv capacity from IEA Renewables report (2019). +#' @details Capacity in GW. Distributed solar, defined in the IEA Renewables (2019), includes #' rooftop residential (0-10 kW, grid-connected), tooftop and ground-mounted commercial #' and industrial (10-1000kW, grid-connected), and off-grid (8W - 100 kW) #' @author Aman Malik #' @importFrom readxl read_excel - - -readIEA_REN <- function() -{ +readIEA_REN <- function() { input <- read_excel("IEA-dis-spv.xlsx") colnames(input)[1] <- "region" - input <- as.magpie(input,spatial=1) + input <- as.magpie(input, spatial = 1) getNames(input) <- "capacity" - getSets(input) <- c("region","year","value") + getSets(input) <- c("region", "year", "value") x <- input return(x) } diff --git a/R/readIEA_WEIO_2014.R b/R/readIEA_WEIO_2014.R index 6493ccc8..5570da82 100644 --- a/R/readIEA_WEIO_2014.R +++ b/R/readIEA_WEIO_2014.R @@ -10,12 +10,10 @@ #' codes. #' #' @importFrom dplyr anti_join group_by left_join mutate pull select summarise -#' @importFrom purrr map #' @importFrom quitte madrat_mule #' @importFrom readr read_csv #' @importFrom readxl excel_sheets read_excel #' @importFrom tidyr nest unnest - #' @export readIEA_WEIO_2014 <- function() { # define file paths ---- @@ -30,7 +28,7 @@ readIEA_WEIO_2014 <- function() { country_groups <- read_csv(file = file_country_groups, show_col_types = FALSE) %>% nest(data = .data$Countries) %>% - mutate(result = map(.data$data, function(x) { + mutate(result = purrr::map(.data$data, function(x) { tibble(iso3c = unlist(strsplit(x$Countries, ', ', fixed = TRUE))) })) %>% select(-'data') %>% @@ -71,7 +69,7 @@ readIEA_WEIO_2014 <- function() { ) %>% mutate(`IEA region` = paste(.data$superset, 'w/o', .data$subsets)) %>% nest(data = .data$subsets) %>% - mutate(result = map(.data$data, function(x) { + mutate(result = purrr::map(.data$data, function(x) { tibble(subsets = unlist(strsplit(x$subsets, ', ', fixed = TRUE))) })) %>% select(-'data') %>% diff --git a/R/readIEA_WEO.R b/R/readIEA_WEO.R index 3ed9ea02..3cc0b150 100644 --- a/R/readIEA_WEO.R +++ b/R/readIEA_WEO.R @@ -1,10 +1,13 @@ #' Read IEA World Energy Outlook data #' -#' @description Read-in IEA WEO 2016 data for investment costs, O&M costs and Efficiency of different technologies, and -#' WEO 2017 data for historical electricity capacities (GW), generation (TWh) or emissions (Mt CO2). +#' @description Read-in IEA WEO 2016 data for investment costs, O&M costs and +#' Efficiency of different technologies, and WEO 2017 data for historical +#' electricity capacities (GW), generation (TWh) or emissions (Mt CO2). #' WEO 2019 data for PE and FE (Mtoe). -#' @param subtype data subtype. Either "Capacity", "Generation", "Emissions", "Investment Costs", "O&M Costs" or "Efficiency" -#' @return magpie object of the WEO data on generation (TWh), capacities (GW), emissions (Mt CO2) or disaggregated investment cost as magpie object +#' @param subtype data subtype. Either "Capacity", "Generation", "Emissions", +#' "Investment Costs", "O&M Costs" or "Efficiency" +#' @return magpie object of the WEO data on generation (TWh), capacities (GW), +#' emissions (Mt CO2) or disaggregated investment cost as magpie object #' @author Renato Rodrigues, Aman Malik, and Jerome Hilaire #' @seealso \code{\link{readSource}} #' @examples @@ -16,8 +19,7 @@ #' @importFrom readxl read_excel readIEA_WEO <- function(subtype) { - # to do - remove dirty fixes for tidyr, dplyr functions; move some parts of the function in PE and FE subtypes - # into convertIEA_WEO + period <- NULL value <- NULL variable <- NULL @@ -26,419 +28,407 @@ readIEA_WEO <- function(subtype) { region <- NULL unit <- NULL - if ((subtype == "Invest_Costs") || (subtype == "O&M_Costs") || (subtype == "Efficiency")) { - - # read WEO 2016 input files- values are from the New Policy scenario, except for CCS costs which are from 450 scenario. - # Coal - input_coal <- read.csv(file = "WEO_2016-coal.csv", na.strings = "n.a.", stringsAsFactors = F) - input_coal$maintech <- "Coal" - # Gas - input_gas <- read.csv(file = "WEO_2016-gas.csv", na.strings = "n.a.", stringsAsFactors = F) - input_gas$maintech <- "Gas" - # Tech with CCS - input_ccs <- read.csv(file = "WEO_2016-ccs.csv", na.strings = "n.a.", stringsAsFactors = F) - input_ccs$maintech <- "CCS" - # Tech with NUC - input_nuc <- read.csv(file = "WEO_2016-nuclear.csv", na.strings = "n.a.", stringsAsFactors = F) - input_nuc$maintech <- "Nuclear" - # Tech with REN - input_ren <- read.csv(file = "WEO_2016-ren.csv", na.strings = "n.a.", stringsAsFactors = F) - input_ren$maintech <- "Renewables" - # Special case for hydro, values are taken not from the IEA database. - input_hydro <- read.csv(file = "hydro.csv", stringsAsFactors = F) - # removing 2025 values - input_hydro <- input_hydro %>% select(-5) - - # 2040 values same as 2030 values - input_hydro$X2040 <- input_hydro$X2030 - input_hydro <- cbind(input_hydro, input_ren[1:12, 7:14]) - # input_hydro <- input_hydro[,c(1:5,15,6:14)] - input_hydro[, 7:14] <- 0 - input_hydro$maintech <- "Hydro_2" - # col.names = c("tech","region","2015","2020","2030","2040","2015", "2020","2030","2040","2015","2020","2030","2040") - input_all <- bind_rows(input_coal, input_gas, input_ccs, input_nuc, input_ren, input_hydro) - - if (subtype == "Invest_Costs") { - input <- input_all[, c(15, 1:6)] - colnames(input)[4:7] <- c(2015, 2020, 2030, 2040) - input <- input %>% - gather(4:7, key = "Year", value = "costs") - - x <- as.magpie(input, spatial = 3, temporal = 4, datacol = 5) - } else if (subtype == "O&M_Costs") { - input <- input_all[, c(15, 1:2, 7:10)] - colnames(input)[4:7] <- c(2015, 2020, 2030, 2040) - input <- input %>% - gather(4:7, key = "Year", value = "costs") - - x <- as.magpie(input, spatial = 3, temporal = 4, datacol = 5) - } else if (subtype == "Efficiency") { - input <- input_all[, c(15, 1:2, 11:14)] - colnames(input)[4:7] <- c(2015, 2020, 2030, 2040) - input <- input %>% - gather(4:7, key = "Year", value = "efficiency") - x <- as.magpie(input, spatial = 3, temporal = 4, datacol = 5) - } + if ((subtype == "Invest_Costs") || (subtype == "O&M_Costs") || (subtype == "Efficiency")) { + # read WEO 2016 input files- values are from the New Policy scenario, + # except for CCS costs which are from 450 scenario. + # Coal + input_coal <- read.csv(file = "WEO_2016-coal.csv", na.strings = "n.a.", stringsAsFactors = FALSE) + input_coal$maintech <- "Coal" + # Gas + input_gas <- read.csv(file = "WEO_2016-gas.csv", na.strings = "n.a.", stringsAsFactors = FALSE) + input_gas$maintech <- "Gas" + # Tech with CCS + input_ccs <- read.csv(file = "WEO_2016-ccs.csv", na.strings = "n.a.", stringsAsFactors = FALSE) + input_ccs$maintech <- "CCS" + # Tech with NUC + input_nuc <- read.csv(file = "WEO_2016-nuclear.csv", na.strings = "n.a.", stringsAsFactors = FALSE) + input_nuc$maintech <- "Nuclear" + # Tech with REN + input_ren <- read.csv(file = "WEO_2016-ren.csv", na.strings = "n.a.", stringsAsFactors = FALSE) + input_ren$maintech <- "Renewables" + # Special case for hydro, values are taken not from the IEA database. + input_hydro <- read.csv(file = "hydro.csv", stringsAsFactors = FALSE) + # removing 2025 values + input_hydro <- input_hydro %>% select(-5) + + # 2040 values same as 2030 values + input_hydro$X2040 <- input_hydro$X2030 + input_hydro <- cbind(input_hydro, input_ren[1:12, 7:14]) + input_hydro[, 7:14] <- 0 + input_hydro$maintech <- "Hydro_2" + input_all <- bind_rows(input_coal, input_gas, input_ccs, input_nuc, input_ren, input_hydro) + + if (subtype == "Invest_Costs") { + input <- input_all[, c(15, 1:6)] + colnames(input)[4:7] <- c(2015, 2020, 2030, 2040) + input <- input %>% + gather(4:7, key = "Year", value = "costs") + + x <- as.magpie(input, spatial = 3, temporal = 4, datacol = 5) + } else if (subtype == "O&M_Costs") { + input <- input_all[, c(15, 1:2, 7:10)] + colnames(input)[4:7] <- c(2015, 2020, 2030, 2040) + input <- input %>% + gather(4:7, key = "Year", value = "costs") + x <- as.magpie(input, spatial = 3, temporal = 4, datacol = 5) + } else if (subtype == "Efficiency") { + input <- input_all[, c(15, 1:2, 11:14)] + colnames(input)[4:7] <- c(2015, 2020, 2030, 2040) + input <- input %>% + gather(4:7, key = "Year", value = "efficiency") + x <- as.magpie(input, spatial = 3, temporal = 4, datacol = 5) } - else if ((subtype == "Capacity") || (subtype == "Generation") || (subtype == "Emissions")) { - - if (subtype == "Capacity") { - data <- read.csv("WEO_2017/WEO-capacity.csv", sep = ";")[, c(2, 3, 4, 5)] - } else if (subtype == "Generation") { - data <- read.csv("WEO_2017/WEO-generation.csv", sep = ";")[, c(2, 3, 4, 5)] - } else if (subtype == "Emissions") { - data <- read.csv("WEO_2017/WEO-EmiCO2.csv", sep = ";")[, c(2, 3, 4, 5)] - # data <- read.csv("WEO_2017/WEO-Emi_seel_CO2.csv",sep=";")[,c(2,3,4,5)] - # data <- read.csv("WEO_2017/WEO-Emi_fe_CO2.csv",sep=";")[,c(2,3,4,5)] - } - # creating capacity, generation or emissions magpie object - x <- as.magpie(data, temporal = 2, spatial = 1, datacol = 4) + } else if ((subtype == "Capacity") || (subtype == "Generation") || (subtype == "Emissions")) { + + if (subtype == "Capacity") { + data <- read.csv("WEO_2017/WEO-capacity.csv", sep = ";")[, c(2, 3, 4, 5)] + } else if (subtype == "Generation") { + data <- read.csv("WEO_2017/WEO-generation.csv", sep = ";")[, c(2, 3, 4, 5)] + } else if (subtype == "Emissions") { + data <- read.csv("WEO_2017/WEO-EmiCO2.csv", sep = ";")[, c(2, 3, 4, 5)] } - else if ((subtype == "PE") || (subtype == "FE")) { - # read-in sheet names from the excel file - data_weo2019_sheets <- readxl::excel_sheets("WEO2019_AnnexA.xlsx") - - sheets_balance <- grep("Balance", data_weo2019_sheets, value = T) - - tmp_all <- list() - for (ksheet in sheets_balance) { - kreg <- substr(ksheet, 1, nchar(ksheet) - nchar("_Balance")) - tmp_sps <- readxl::read_excel("WEO2019_AnnexA.xlsx", sheet = ksheet, range = "A5:H56") - tmp_cps <- readxl::read_excel("WEO2019_AnnexA.xlsx", sheet = ksheet, range = "M5:Q56") - tmp_sds <- readxl::read_excel("WEO2019_AnnexA.xlsx", sheet = ksheet, range = "U5:X56") - - names(tmp_sps)[1] <- "variable" - names(tmp_cps)[1] <- "variable" - - tmp_sds <- cbind( - tmp_cps[, 1], - tmp_sds) - - # Primary energy demand - tmp1 <- tmp_sps[which(tmp_sps[, 1] == "Total primary demand"):(which(tmp_sps[, 1] == "Power sector") - 1), ] %>% - gather(period, value, -variable) %>% - mutate(period = as.numeric(period)) %>% - mutate(model = "IEA-WEM2019") %>% - mutate(scenario = "Stated Policies Scenario") %>% - mutate(region = kreg) %>% - mutate(variable = ifelse(variable == "Natural gas", "Gas", variable)) %>% - mutate(variable = ifelse(variable == "Bioenergy", "Biomass", variable)) %>% - mutate(variable = paste0("Primary Energy|", variable)) %>% - mutate(variable = ifelse(variable == "Primary Energy|Total primary demand", "Primary Energy", variable)) %>% - mutate(unit = "Mtoe") %>% - select(model, scenario, region, variable, unit, period, value) - tmp1 <- rbind( - tmp1, - rbind( - tmp1 %>% - filter(period < 2025) %>% - mutate(scenario = "Current Policies Scenario"), - tmp_cps[which(tmp_sps[, 1] == "Total primary demand"):(which(tmp_sps[, 1] == "Power sector") - 1), ] %>% - gather(period, value, -variable) %>% - mutate(period = as.numeric(period)) %>% - mutate(model = "IEA-WEM2019") %>% - mutate(scenario = "Current Policies Scenario") %>% - mutate(region = kreg) %>% - mutate(variable = ifelse(variable == "Natural gas", "Gas", variable)) %>% - mutate(variable = ifelse(variable == "Bioenergy", "Biomass", variable)) %>% - mutate(variable = paste0("Primary Energy|", variable)) %>% - mutate(variable = ifelse(variable == "Primary Energy|Total primary demand", "Primary Energy", variable)) %>% - mutate(unit = "Mtoe") %>% - select(model, scenario, region, variable, unit, period, value)), - rbind( - tmp1 %>% - filter(period < 2025) %>% - mutate(scenario = "Sustainable Development Scenario"), - tmp_sds[which(tmp_sps[, 1] == "Total primary demand"):(which(tmp_sps[, 1] == "Power sector") - 1), ] %>% - gather(period, value, -variable) %>% - mutate(period = as.numeric(period)) %>% - mutate(model = "IEA-WEM2019") %>% - mutate(scenario = "Sustainable Development Scenario") %>% - mutate(region = kreg) %>% - mutate(variable = ifelse(variable == "Natural gas", "Gas", variable)) %>% - mutate(variable = ifelse(variable == "Bioenergy", "Biomass", variable)) %>% - mutate(variable = paste0("Primary Energy|", variable)) %>% - mutate(variable = ifelse(variable == "Primary Energy|Total primary demand", "Primary Energy", variable)) %>% - mutate(unit = "Mtoe") %>% - select(model, scenario, region, variable, unit, period, value))) - - # Power sector - tmp2 <- tmp_sps[which(tmp_sps[, 1] == "Power sector"):(which(tmp_sps[, 1] == "Other energy sector") - 1), ] %>% - gather(period, value, -variable) %>% - mutate(period = as.numeric(period)) %>% - mutate(model = "IEA-WEM2019") %>% - mutate(scenario = "Stated Policies Scenario") %>% - mutate(region = kreg) %>% - mutate(variable = ifelse(variable == "Natural gas", "Gas", variable)) %>% - # mutate(variable = ifelse(variable == "Bioenergy", "Biomass", variable)) %>% - mutate(variable = paste0("Primary Energy|Electricity|", variable)) %>% - mutate(variable = ifelse(variable == "Primary Energy|Electricity|Power Sector", "Primary Energy|Electricity", variable)) %>% - mutate(unit = "Mtoe") %>% - select(model, scenario, region, variable, unit, period, value) - tmp2 <- rbind( - tmp2, - rbind( - tmp2 %>% - filter(period < 2025) %>% - mutate(scenario = "Current Policies Scenario"), - tmp_cps[which(tmp_sps[, 1] == "Power sector"):(which(tmp_sps[, 1] == "Other energy sector") - 1), ] %>% - gather(period, value, -variable) %>% - mutate(period = as.numeric(period)) %>% - mutate(model = "IEA-WEM2019") %>% - mutate(scenario = "Current Policies Scenario") %>% - mutate(region = kreg) %>% - mutate(variable = ifelse(variable == "Natural gas", "Gas", variable)) %>% - # mutate(variable = ifelse(variable == "Bioenergy", "Biomass", variable)) %>% - mutate(variable = paste0("Primary Energy|Electricity|", variable)) %>% - mutate(variable = ifelse(variable == "Primary Energy|Electricity|Power Sector", "Primary Energy|Electricity", variable)) %>% - mutate(unit = "Mtoe") %>% - select(model, scenario, region, variable, unit, period, value)), - rbind( - tmp2 %>% - filter(period < 2025) %>% - mutate(scenario = "Sustainable Development Scenario"), - tmp_sds[which(tmp_sps[, 1] == "Power sector"):(which(tmp_sps[, 1] == "Other energy sector") - 1), ] %>% - gather(period, value, -variable) %>% - mutate(period = as.numeric(period)) %>% - mutate(model = "IEA-WEM2019") %>% - mutate(scenario = "Sustainable Development Scenario") %>% - mutate(region = kreg) %>% - mutate(variable = ifelse(variable == "Natural gas", "Gas", variable)) %>% - # mutate(variable = ifelse(variable == "Bioenergy", "Biomass", variable)) %>% - mutate(variable = paste0("Primary Energy|Electricity|", variable)) %>% - mutate(variable = ifelse(variable == "Primary Energy|Electricity|Power Sector", "Primary Energy|Electricity", variable)) %>% - mutate(unit = "Mtoe") %>% - select(model, scenario, region, variable, unit, period, value))) - - - # Final energy consumption - tmp3 <- tmp_sps[which(tmp_sps[, 1] == "Total final consumption"):(which(tmp_sps[, 1] == "Industry") - 1), ] %>% - gather(period, value, -variable) %>% - mutate(period = as.numeric(period)) %>% - mutate(model = "IEA-WEM2019") %>% - mutate(scenario = "Stated Policies Scenario") %>% - mutate(region = kreg) %>% - mutate(variable = ifelse(variable == "Natural gas", "Gas", variable)) %>% - # mutate(variable = ifelse(variable == "Bioenergy", "Biomass", variable)) %>% - mutate(variable = paste0("Final Energy|", variable)) %>% - mutate(variable = ifelse(variable == "Final Energy|Total final consumption", "Final Energy", variable)) %>% - mutate(unit = "Mtoe") %>% - select(model, scenario, region, variable, unit, period, value) - tmp3 <- rbind( - tmp3, - rbind( - tmp3 %>% - filter(period < 2025) %>% - mutate(scenario = "Current Policies Scenario"), - tmp_cps[which(tmp_sps[, 1] == "Total final consumption"):(which(tmp_sps[, 1] == "Industry") - 1), ] %>% - gather(period, value, -variable) %>% - mutate(period = as.numeric(period)) %>% - mutate(model = "IEA-WEM2019") %>% - mutate(scenario = "Current Policies Scenario") %>% - mutate(region = kreg) %>% - mutate(variable = ifelse(variable == "Natural gas", "Gas", variable)) %>% - # mutate(variable = ifelse(variable == "Bioenergy", "Biomass", variable)) %>% - mutate(variable = paste0("Final Energy|", variable)) %>% - mutate(variable = ifelse(variable == "Final Energy|Total final consumption", "Final Energy", variable)) %>% - mutate(unit = "Mtoe") %>% - select(model, scenario, region, variable, unit, period, value)), - rbind( - tmp3 %>% - filter(period < 2025) %>% - mutate(scenario = "Sustainable Development Scenario"), - tmp_sds[which(tmp_sps[, 1] == "Total final consumption"):(which(tmp_sps[, 1] == "Industry") - 1), ] %>% - gather(period, value, -variable) %>% - mutate(period = as.numeric(period)) %>% - mutate(model = "IEA-WEM2019") %>% - mutate(scenario = "Sustainable Development Scenario") %>% - mutate(region = kreg) %>% - mutate(variable = ifelse(variable == "Natural gas", "Gas", variable)) %>% - # mutate(variable = ifelse(variable == "Bioenergy", "Biomass", variable)) %>% - mutate(variable = paste0("Final Energy|", variable)) %>% - mutate(variable = ifelse(variable == "Final Energy|Total final consumption", "Final Energy", variable)) %>% - mutate(unit = "Mtoe") %>% - select(model, scenario, region, variable, unit, period, value))) - - - # Final energy consumption (Industry) - tmp4 <- tmp_sps[which(tmp_sps[, 1] == "Industry"):(which(tmp_sps[, 1] == "Transport") - 1), ] %>% - gather(period, value, -variable) %>% - mutate(period = as.numeric(period)) %>% - mutate(model = "IEA-WEM2019") %>% - mutate(scenario = "Stated Policies Scenario") %>% - mutate(region = kreg) %>% - mutate(variable = ifelse(variable == "Natural gas", "Gas", variable)) %>% - # mutate(variable = ifelse(variable == "Bioenergy", "Biomass", variable)) %>% - mutate(variable = paste0("Final Energy|Industry|", variable)) %>% - mutate(variable = ifelse(variable == "Final Energy|Industry|Industry", "Final Energy|Industry", variable)) %>% - mutate(unit = "Mtoe") %>% - select(model, scenario, region, variable, unit, period, value) - tmp4 <- rbind( - tmp4, - rbind( - tmp4 %>% - filter(period < 2025) %>% - mutate(scenario = "Current Policies Scenario"), - tmp_cps[which(tmp_sps[, 1] == "Industry"):(which(tmp_sps[, 1] == "Transport") - 1), ] %>% - gather(period, value, -variable) %>% - mutate(period = as.numeric(period)) %>% - mutate(model = "IEA-WEM2019") %>% - mutate(scenario = "Current Policies Scenario") %>% - mutate(region = kreg) %>% - mutate(variable = ifelse(variable == "Natural gas", "Gas", variable)) %>% - # mutate(variable = ifelse(variable == "Bioenergy", "Biomass", variable)) %>% - mutate(variable = paste0("Final Energy|Industry|", variable)) %>% - mutate(variable = ifelse(variable == "Final Energy|Industry|Industry", "Final Energy|Industry", variable)) %>% - mutate(unit = "Mtoe") %>% - select(model, scenario, region, variable, unit, period, value)), - rbind( - tmp4 %>% - filter(period < 2025) %>% - mutate(scenario = "Sustainable Development Scenario"), - tmp_sds[which(tmp_sps[, 1] == "Industry"):(which(tmp_sps[, 1] == "Transport") - 1), ] %>% - gather(period, value, -variable) %>% - mutate(period = as.numeric(period)) %>% - mutate(model = "IEA-WEM2019") %>% - mutate(scenario = "Sustainable Development Scenario") %>% - mutate(region = kreg) %>% - mutate(variable = ifelse(variable == "Natural gas", "Gas", variable)) %>% - # mutate(variable = ifelse(variable == "Bioenergy", "Biomass", variable)) %>% - mutate(variable = paste0("Final Energy|Industry|", variable)) %>% - mutate(variable = ifelse(variable == "Final Energy|Industry|Industry", "Final Energy|Industry", variable)) %>% - mutate(unit = "Mtoe") %>% - select(model, scenario, region, variable, unit, period, value))) - - # Final energy consumption (Transport) - tmp5 <- tmp_sps[which(tmp_sps[, 1] == "Transport"):(which(tmp_sps[, 1] == "Buildings") - 1), ] %>% - gather(period, value, -variable) %>% - mutate(period = as.numeric(period)) %>% - mutate(model = "IEA-WEM2019") %>% - mutate(scenario = "Stated Policies Scenario") %>% - mutate(region = kreg) %>% - mutate(variable = ifelse(variable == "International bunkers", "Oil|International bunkers", variable)) %>% - # mutate(variable = ifelse(variable == "Bioenergy", "Biomass", variable)) %>% - mutate(variable = paste0("Final Energy|Transportation|", variable)) %>% - mutate(variable = ifelse(variable == "Final Energy|Transportation|Transport", "Final Energy|Transportation", variable)) %>% - mutate(unit = "Mtoe") %>% - select(model, scenario, region, variable, unit, period, value) - tmp5 <- rbind( - tmp5, - rbind( - tmp5 %>% - filter(period < 2025) %>% - mutate(scenario = "Current Policies Scenario"), - tmp_cps[which(tmp_sps[, 1] == "Transport"):(which(tmp_sps[, 1] == "Buildings") - 1), ] %>% - gather(period, value, -variable) %>% - mutate(period = as.numeric(period)) %>% - mutate(model = "IEA-WEM2019") %>% - mutate(scenario = "Current Policies Scenario") %>% - mutate(region = kreg) %>% - mutate(variable = ifelse(variable == "International bunkers", "Oil|International bunkers", variable)) %>% - # mutate(variable = ifelse(variable == "Bioenergy", "Biomass", variable)) %>% - mutate(variable = paste0("Final Energy|Transportation|", variable)) %>% - mutate(variable = ifelse(variable == "Final Energy|Transportation|Transport", "Final Energy|Transportation", variable)) %>% - mutate(unit = "Mtoe") %>% - select(model, scenario, region, variable, unit, period, value)), - rbind( - tmp5 %>% - filter(period < 2025) %>% - mutate(scenario = "Sustainable Development Scenario"), - tmp_sds[which(tmp_sps[, 1] == "Transport"):(which(tmp_sps[, 1] == "Buildings") - 1), ] %>% - gather(period, value, -variable) %>% - mutate(period = as.numeric(period)) %>% - mutate(model = "IEA-WEM2019") %>% - mutate(scenario = "Sustainable Development Scenario") %>% - mutate(region = kreg) %>% - mutate(variable = ifelse(variable == "International bunkers", "Oil|International bunkers", variable)) %>% - # mutate(variable = ifelse(variable == "Bioenergy", "Biomass", variable)) %>% - mutate(variable = paste0("Final Energy|Transportation|", variable)) %>% - mutate(variable = ifelse(variable == "Final Energy|Transportation|Transport", "Final Energy|Transportation", variable)) %>% - mutate(unit = "Mtoe") %>% - select(model, scenario, region, variable, unit, period, value))) - - - # Final energy consumption (Buildings) - tmp6 <- tmp_sps[which(tmp_sps[, 1] == "Buildings"):(which(tmp_sps[, 1] == "Other") - 1), ] %>% - gather(period, value, -variable) %>% - mutate(period = as.numeric(period)) %>% - mutate(model = "IEA-WEM2019") %>% - mutate(scenario = "Stated Policies Scenario") %>% - mutate(region = kreg) %>% - mutate(variable = ifelse(variable == "Traditional biomass", "Bioenergy|Traditional biomass", variable)) %>% - # mutate(variable = ifelse(variable == "Bioenergy", "Biomass", variable)) %>% - mutate(variable = paste0("Final Energy|Buildings|", variable)) %>% - mutate(variable = ifelse(variable == "Final Energy|Buildings|Buildings", "Final Energy|Buildings", variable)) %>% - mutate(unit = "Mtoe") %>% - select(model, scenario, region, variable, unit, period, value) - tmp6 <- rbind( - tmp6, - rbind( - tmp6 %>% - filter(period < 2025) %>% - mutate(scenario = "Current Policies Scenario"), - tmp_cps[which(tmp_sps[, 1] == "Buildings"):(which(tmp_sps[, 1] == "Other") - 1), ] %>% - gather(period, value, -variable) %>% - mutate(period = as.numeric(period)) %>% - mutate(model = "IEA-WEM2019") %>% - mutate(scenario = "Current Policies Scenario") %>% - mutate(region = kreg) %>% - mutate(variable = ifelse(variable == "Traditional biomass", "Bioenergy|Traditional biomass", variable)) %>% - # mutate(variable = ifelse(variable == "Bioenergy", "Biomass", variable)) %>% - mutate(variable = paste0("Final Energy|Buildings|", variable)) %>% - mutate(variable = ifelse(variable == "Final Energy|Buildings|Buildings", "Final Energy|Buildings", variable)) %>% - mutate(unit = "Mtoe") %>% - select(model, scenario, region, variable, unit, period, value)), - rbind( - tmp6 %>% - filter(period < 2025) %>% - mutate(scenario = "Sustainable Development Scenario"), - tmp_sds[which(tmp_sps[, 1] == "Buildings"):(which(tmp_sps[, 1] == "Other") - 1), ] %>% - gather(period, value, -variable) %>% - mutate(period = as.numeric(period)) %>% - mutate(model = "IEA-WEM2019") %>% - mutate(scenario = "Sustainable Development Scenario") %>% - mutate(region = kreg) %>% - mutate(variable = ifelse(variable == "Traditional biomass", "Bioenergy|Traditional biomass", variable)) %>% - # mutate(variable = ifelse(variable == "Bioenergy", "Biomass", variable)) %>% - mutate(variable = paste0("Final Energy|Buildings|", variable)) %>% - mutate(variable = ifelse(variable == "Final Energy|Buildings|Buildings", "Final Energy|Buildings", variable)) %>% - mutate(unit = "Mtoe") %>% - select(model, scenario, region, variable, unit, period, value))) - - # Final energy consumption (Other) - tmp7 <- tmp_sps[which(tmp_sps[, 1] == "Other"):which(tmp_sps[, 1] == "Petrochem. feedstock"), ] %>% - gather(period, value, -variable) %>% - mutate(period = as.numeric(period)) %>% - mutate(model = "IEA-WEM2019") %>% - mutate(scenario = "Stated Policies Scenario") %>% - mutate(region = kreg) %>% - # mutate(variable = ifelse(variable == "Traditional biomass", "Bioenergy|Traditional biomass", variable)) %>% - # mutate(variable = ifelse(variable == "Bioenergy", "Biomass", variable)) %>% - mutate(variable = paste0("Final Energy|Other|", variable)) %>% - mutate(variable = ifelse(variable == "Final Energy|Other|Other", "Final Energy|Other", variable)) %>% - mutate(unit = "Mtoe") %>% - select(model, scenario, region, variable, unit, period, value) - tmp7 <- rbind( - tmp7, - rbind( - tmp7 %>% - filter(period < 2025) %>% - mutate(scenario = "Current Policies Scenario"), - tmp_cps[which(tmp_sps[, 1] == "Other"):which(tmp_sps[, 1] == "Petrochem. feedstock"), ] %>% - gather(period, value, -variable) %>% - mutate(period = as.numeric(period)) %>% - mutate(model = "IEA-WEM2019") %>% - mutate(scenario = "Current Policies Scenario") %>% - mutate(region = kreg) %>% - # mutate(variable = ifelse(variable == "Traditional biomass", "Bioenergy|Traditional biomass", variable)) %>% - # mutate(variable = ifelse(variable == "Bioenergy", "Biomass", variable)) %>% - mutate(variable = paste0("Final Energy|Other|", variable)) %>% - mutate(variable = ifelse(variable == "Final Energy|Other|Other", "Final Energy|Other", variable)) %>% - mutate(unit = "Mtoe") %>% - select(model, scenario, region, variable, unit, period, value)), - rbind( + + # creating capacity, generation or emissions magpie object + x <- as.magpie(data, temporal = 2, spatial = 1, datacol = 4) + + } else if ((subtype == "PE") || (subtype == "FE")) { + # read-in sheet names from the excel file + data_weo2019_sheets <- readxl::excel_sheets("WEO2019_AnnexA.xlsx") + + sheets_balance <- grep("Balance", data_weo2019_sheets, value = TRUE) + + tmp_all <- list() + for (ksheet in sheets_balance) { + kreg <- substr(ksheet, 1, nchar(ksheet) - nchar("_Balance")) + tmp_sps <- readxl::read_excel("WEO2019_AnnexA.xlsx", sheet = ksheet, range = "A5:H56", .name_repair = "unique_quiet") + tmp_cps <- readxl::read_excel("WEO2019_AnnexA.xlsx", sheet = ksheet, range = "M5:Q56", .name_repair = "unique_quiet") + tmp_sds <- readxl::read_excel("WEO2019_AnnexA.xlsx", sheet = ksheet, range = "U5:X56", .name_repair = "unique_quiet") + + names(tmp_sps)[1] <- "variable" + names(tmp_cps)[1] <- "variable" + + tmp_sds <- cbind( + tmp_cps[, 1], + tmp_sds + ) + + # Primary energy demand + tmp1 <- tmp_sps[which(tmp_sps[, 1] == "Total primary demand"):(which(tmp_sps[, 1] == "Power sector") - 1), ] %>% + gather(period, value, -variable) %>% + mutate(period = as.numeric(period)) %>% + mutate(model = "IEA-WEM2019") %>% + mutate(scenario = "Stated Policies Scenario") %>% + mutate(region = kreg) %>% + mutate(variable = ifelse(variable == "Natural gas", "Gas", variable)) %>% + mutate(variable = ifelse(variable == "Bioenergy", "Biomass", variable)) %>% + mutate(variable = paste0("Primary Energy|", variable)) %>% + mutate(variable = ifelse(variable == "Primary Energy|Total primary demand", "Primary Energy", variable)) %>% + mutate(unit = "Mtoe") %>% + select("model", "scenario", "region", "variable", "unit", "period", "value") + + tmp1 <- rbind( + tmp1, + rbind( + tmp1 %>% + filter(period < 2025) %>% + mutate(scenario = "Current Policies Scenario"), + tmp_cps[which(tmp_sps[, 1] == "Total primary demand"):(which(tmp_sps[, 1] == "Power sector") - 1), ] %>% + gather(period, value, -variable) %>% + mutate(period = as.numeric(period)) %>% + mutate(model = "IEA-WEM2019") %>% + mutate(scenario = "Current Policies Scenario") %>% + mutate(region = kreg) %>% + mutate(variable = ifelse(variable == "Natural gas", "Gas", variable)) %>% + mutate(variable = ifelse(variable == "Bioenergy", "Biomass", variable)) %>% + mutate(variable = paste0("Primary Energy|", variable)) %>% + mutate(variable = ifelse(variable == "Primary Energy|Total primary demand", "Primary Energy", variable)) %>% + mutate(unit = "Mtoe") %>% + select(model, scenario, region, variable, unit, period, value)), + rbind( + tmp1 %>% + filter(period < 2025) %>% + mutate(scenario = "Sustainable Development Scenario"), + tmp_sds[which(tmp_sps[, 1] == "Total primary demand"):(which(tmp_sps[, 1] == "Power sector") - 1), ] %>% + gather(period, value, -variable) %>% + mutate(period = as.numeric(period)) %>% + mutate(model = "IEA-WEM2019") %>% + mutate(scenario = "Sustainable Development Scenario") %>% + mutate(region = kreg) %>% + mutate(variable = ifelse(variable == "Natural gas", "Gas", variable)) %>% + mutate(variable = ifelse(variable == "Bioenergy", "Biomass", variable)) %>% + mutate(variable = paste0("Primary Energy|", variable)) %>% + mutate(variable = ifelse(variable == "Primary Energy|Total primary demand", "Primary Energy", variable)) %>% + mutate(unit = "Mtoe") %>% + select(model, scenario, region, variable, unit, period, value))) + + # Power sector + tmp2 <- tmp_sps[which(tmp_sps[, 1] == "Power sector"):(which(tmp_sps[, 1] == "Other energy sector") - 1), ] %>% + gather(period, value, -variable) %>% + mutate(period = as.numeric(period)) %>% + mutate(model = "IEA-WEM2019") %>% + mutate(scenario = "Stated Policies Scenario") %>% + mutate(region = kreg) %>% + mutate(variable = ifelse(variable == "Natural gas", "Gas", variable)) %>% + # mutate(variable = ifelse(variable == "Bioenergy", "Biomass", variable)) %>% + mutate(variable = paste0("Primary Energy|Electricity|", variable)) %>% + mutate(variable = ifelse(variable == "Primary Energy|Electricity|Power Sector", "Primary Energy|Electricity", variable)) %>% + mutate(unit = "Mtoe") %>% + select(model, scenario, region, variable, unit, period, value) + tmp2 <- rbind( + tmp2, + rbind( + tmp2 %>% + filter(period < 2025) %>% + mutate(scenario = "Current Policies Scenario"), + tmp_cps[which(tmp_sps[, 1] == "Power sector"):(which(tmp_sps[, 1] == "Other energy sector") - 1), ] %>% + gather(period, value, -variable) %>% + mutate(period = as.numeric(period)) %>% + mutate(model = "IEA-WEM2019") %>% + mutate(scenario = "Current Policies Scenario") %>% + mutate(region = kreg) %>% + mutate(variable = ifelse(variable == "Natural gas", "Gas", variable)) %>% + # mutate(variable = ifelse(variable == "Bioenergy", "Biomass", variable)) %>% + mutate(variable = paste0("Primary Energy|Electricity|", variable)) %>% + mutate(variable = ifelse(variable == "Primary Energy|Electricity|Power Sector", "Primary Energy|Electricity", variable)) %>% + mutate(unit = "Mtoe") %>% + select(model, scenario, region, variable, unit, period, value)), + rbind( + tmp2 %>% + filter(period < 2025) %>% + mutate(scenario = "Sustainable Development Scenario"), + tmp_sds[which(tmp_sps[, 1] == "Power sector"):(which(tmp_sps[, 1] == "Other energy sector") - 1), ] %>% + gather(period, value, -variable) %>% + mutate(period = as.numeric(period)) %>% + mutate(model = "IEA-WEM2019") %>% + mutate(scenario = "Sustainable Development Scenario") %>% + mutate(region = kreg) %>% + mutate(variable = ifelse(variable == "Natural gas", "Gas", variable)) %>% + # mutate(variable = ifelse(variable == "Bioenergy", "Biomass", variable)) %>% + mutate(variable = paste0("Primary Energy|Electricity|", variable)) %>% + mutate(variable = ifelse(variable == "Primary Energy|Electricity|Power Sector", "Primary Energy|Electricity", variable)) %>% + mutate(unit = "Mtoe") %>% + select(model, scenario, region, variable, unit, period, value))) + + + # Final energy consumption + tmp3 <- tmp_sps[which(tmp_sps[, 1] == "Total final consumption"):(which(tmp_sps[, 1] == "Industry") - 1), ] %>% + gather(period, value, -variable) %>% + mutate(period = as.numeric(period)) %>% + mutate(model = "IEA-WEM2019") %>% + mutate(scenario = "Stated Policies Scenario") %>% + mutate(region = kreg) %>% + mutate(variable = ifelse(variable == "Natural gas", "Gas", variable)) %>% + # mutate(variable = ifelse(variable == "Bioenergy", "Biomass", variable)) %>% + mutate(variable = paste0("Final Energy|", variable)) %>% + mutate(variable = ifelse(variable == "Final Energy|Total final consumption", "Final Energy", variable)) %>% + mutate(unit = "Mtoe") %>% + select(model, scenario, region, variable, unit, period, value) + tmp3 <- rbind( + tmp3, + rbind( + tmp3 %>% + filter(period < 2025) %>% + mutate(scenario = "Current Policies Scenario"), + tmp_cps[which(tmp_sps[, 1] == "Total final consumption"):(which(tmp_sps[, 1] == "Industry") - 1), ] %>% + gather(period, value, -variable) %>% + mutate(period = as.numeric(period)) %>% + mutate(model = "IEA-WEM2019") %>% + mutate(scenario = "Current Policies Scenario") %>% + mutate(region = kreg) %>% + mutate(variable = ifelse(variable == "Natural gas", "Gas", variable)) %>% + # mutate(variable = ifelse(variable == "Bioenergy", "Biomass", variable)) %>% + mutate(variable = paste0("Final Energy|", variable)) %>% + mutate(variable = ifelse(variable == "Final Energy|Total final consumption", "Final Energy", variable)) %>% + mutate(unit = "Mtoe") %>% + select(model, scenario, region, variable, unit, period, value)), + rbind( + tmp3 %>% + filter(period < 2025) %>% + mutate(scenario = "Sustainable Development Scenario"), + tmp_sds[which(tmp_sps[, 1] == "Total final consumption"):(which(tmp_sps[, 1] == "Industry") - 1), ] %>% + gather(period, value, -variable) %>% + mutate(period = as.numeric(period)) %>% + mutate(model = "IEA-WEM2019") %>% + mutate(scenario = "Sustainable Development Scenario") %>% + mutate(region = kreg) %>% + mutate(variable = ifelse(variable == "Natural gas", "Gas", variable)) %>% + # mutate(variable = ifelse(variable == "Bioenergy", "Biomass", variable)) %>% + mutate(variable = paste0("Final Energy|", variable)) %>% + mutate(variable = ifelse(variable == "Final Energy|Total final consumption", "Final Energy", variable)) %>% + mutate(unit = "Mtoe") %>% + select(model, scenario, region, variable, unit, period, value))) + + # Final energy consumption (Industry) + tmp4 <- tmp_sps[which(tmp_sps[, 1] == "Industry"):(which(tmp_sps[, 1] == "Transport") - 1), ] %>% + gather(period, value, -variable) %>% + mutate(period = as.numeric(period)) %>% + mutate(model = "IEA-WEM2019") %>% + mutate(scenario = "Stated Policies Scenario") %>% + mutate(region = kreg) %>% + mutate(variable = ifelse(variable == "Natural gas", "Gas", variable)) %>% + mutate(variable = paste0("Final Energy|Industry|", variable)) %>% + mutate(variable = ifelse(variable == "Final Energy|Industry|Industry", "Final Energy|Industry", variable)) %>% + mutate(unit = "Mtoe") %>% + select(model, scenario, region, variable, unit, period, value) + + tmp4 <- rbind( + tmp4, + rbind( + tmp4 %>% + filter(period < 2025) %>% + mutate(scenario = "Current Policies Scenario"), + tmp_cps[which(tmp_sps[, 1] == "Industry"):(which(tmp_sps[, 1] == "Transport") - 1), ] %>% + gather(period, value, -variable) %>% + mutate(period = as.numeric(period)) %>% + mutate(model = "IEA-WEM2019") %>% + mutate(scenario = "Current Policies Scenario") %>% + mutate(region = kreg) %>% + mutate(variable = ifelse(variable == "Natural gas", "Gas", variable)) %>% + # mutate(variable = ifelse(variable == "Bioenergy", "Biomass", variable)) %>% + mutate(variable = paste0("Final Energy|Industry|", variable)) %>% + mutate(variable = ifelse(variable == "Final Energy|Industry|Industry", "Final Energy|Industry", variable)) %>% + mutate(unit = "Mtoe") %>% + select(model, scenario, region, variable, unit, period, value)), + rbind( + tmp4 %>% + filter(period < 2025) %>% + mutate(scenario = "Sustainable Development Scenario"), + tmp_sds[which(tmp_sps[, 1] == "Industry"):(which(tmp_sps[, 1] == "Transport") - 1), ] %>% + gather(period, value, -variable) %>% + mutate(period = as.numeric(period)) %>% + mutate(model = "IEA-WEM2019") %>% + mutate(scenario = "Sustainable Development Scenario") %>% + mutate(region = kreg) %>% + mutate(variable = ifelse(variable == "Natural gas", "Gas", variable)) %>% + # mutate(variable = ifelse(variable == "Bioenergy", "Biomass", variable)) %>% + mutate(variable = paste0("Final Energy|Industry|", variable)) %>% + mutate(variable = ifelse(variable == "Final Energy|Industry|Industry", "Final Energy|Industry", variable)) %>% + mutate(unit = "Mtoe") %>% + select(model, scenario, region, variable, unit, period, value))) + + # Final energy consumption (Transport) + tmp5 <- tmp_sps[which(tmp_sps[, 1] == "Transport"):(which(tmp_sps[, 1] == "Buildings") - 1), ] %>% + gather(period, value, -variable) %>% + mutate(period = as.numeric(period)) %>% + mutate(model = "IEA-WEM2019") %>% + mutate(scenario = "Stated Policies Scenario") %>% + mutate(region = kreg) %>% + mutate(variable = ifelse(variable == "International bunkers", "Oil|International bunkers", variable)) %>% + mutate(variable = paste0("Final Energy|Transportation|", variable)) %>% + mutate(variable = ifelse(variable == "Final Energy|Transportation|Transport", "Final Energy|Transportation", variable)) %>% + mutate(unit = "Mtoe") %>% + select(model, scenario, region, variable, unit, period, value) + + tmp5 <- rbind( + tmp5, + rbind( + tmp5 %>% + filter(period < 2025) %>% + mutate(scenario = "Current Policies Scenario"), + tmp_cps[which(tmp_sps[, 1] == "Transport"):(which(tmp_sps[, 1] == "Buildings") - 1), ] %>% + gather(period, value, -variable) %>% + mutate(period = as.numeric(period)) %>% + mutate(model = "IEA-WEM2019") %>% + mutate(scenario = "Current Policies Scenario") %>% + mutate(region = kreg) %>% + mutate(variable = ifelse(variable == "International bunkers", "Oil|International bunkers", variable)) %>% + mutate(variable = paste0("Final Energy|Transportation|", variable)) %>% + mutate(variable = ifelse(variable == "Final Energy|Transportation|Transport", "Final Energy|Transportation", variable)) %>% + mutate(unit = "Mtoe") %>% + select(model, scenario, region, variable, unit, period, value)), + rbind( + tmp5 %>% + filter(period < 2025) %>% + mutate(scenario = "Sustainable Development Scenario"), + tmp_sds[which(tmp_sps[, 1] == "Transport"):(which(tmp_sps[, 1] == "Buildings") - 1), ] %>% + gather(period, value, -variable) %>% + mutate(period = as.numeric(period)) %>% + mutate(model = "IEA-WEM2019") %>% + mutate(scenario = "Sustainable Development Scenario") %>% + mutate(region = kreg) %>% + mutate(variable = ifelse(variable == "International bunkers", "Oil|International bunkers", variable)) %>% + mutate(variable = paste0("Final Energy|Transportation|", variable)) %>% + mutate(variable = ifelse(variable == "Final Energy|Transportation|Transport", "Final Energy|Transportation", variable)) %>% + mutate(unit = "Mtoe") %>% + select(model, scenario, region, variable, unit, period, value))) + + + # Final energy consumption (Buildings) + tmp6 <- tmp_sps[which(tmp_sps[, 1] == "Buildings"):(which(tmp_sps[, 1] == "Other") - 1), ] %>% + gather(period, value, -variable) %>% + mutate(period = as.numeric(period)) %>% + mutate(model = "IEA-WEM2019") %>% + mutate(scenario = "Stated Policies Scenario") %>% + mutate(region = kreg) %>% + mutate(variable = ifelse(variable == "Traditional biomass", "Bioenergy|Traditional biomass", variable)) %>% + mutate(variable = paste0("Final Energy|Buildings|", variable)) %>% + mutate(variable = ifelse(variable == "Final Energy|Buildings|Buildings", "Final Energy|Buildings", variable)) %>% + mutate(unit = "Mtoe") %>% + select(model, scenario, region, variable, unit, period, value) + + tmp6 <- rbind( + tmp6, + rbind( + tmp6 %>% + filter(period < 2025) %>% + mutate(scenario = "Current Policies Scenario"), + tmp_cps[which(tmp_sps[, 1] == "Buildings"):(which(tmp_sps[, 1] == "Other") - 1), ] %>% + gather(period, value, -variable) %>% + mutate(period = as.numeric(period)) %>% + mutate(model = "IEA-WEM2019") %>% + mutate(scenario = "Current Policies Scenario") %>% + mutate(region = kreg) %>% + mutate(variable = ifelse(variable == "Traditional biomass", "Bioenergy|Traditional biomass", variable)) %>% + mutate(variable = paste0("Final Energy|Buildings|", variable)) %>% + mutate(variable = ifelse(variable == "Final Energy|Buildings|Buildings", "Final Energy|Buildings", variable)) %>% + mutate(unit = "Mtoe") %>% + select(model, scenario, region, variable, unit, period, value)), + rbind( + tmp6 %>% + filter(period < 2025) %>% + mutate(scenario = "Sustainable Development Scenario"), + tmp_sds[which(tmp_sps[, 1] == "Buildings"):(which(tmp_sps[, 1] == "Other") - 1), ] %>% + gather(period, value, -variable) %>% + mutate(period = as.numeric(period)) %>% + mutate(model = "IEA-WEM2019") %>% + mutate(scenario = "Sustainable Development Scenario") %>% + mutate(region = kreg) %>% + mutate(variable = ifelse(variable == "Traditional biomass", "Bioenergy|Traditional biomass", variable)) %>% + mutate(variable = paste0("Final Energy|Buildings|", variable)) %>% + mutate(variable = ifelse(variable == "Final Energy|Buildings|Buildings", "Final Energy|Buildings", variable)) %>% + mutate(unit = "Mtoe") %>% + select(model, scenario, region, variable, unit, period, value))) + + # Final energy consumption (Other) + tmp7 <- tmp_sps[which(tmp_sps[, 1] == "Other"):which(tmp_sps[, 1] == "Petrochem. feedstock"), ] %>% + gather(period, value, -variable) %>% + mutate(period = as.numeric(period)) %>% + mutate(model = "IEA-WEM2019") %>% + mutate(scenario = "Stated Policies Scenario") %>% + mutate(region = kreg) %>% + mutate(variable = paste0("Final Energy|Other|", variable)) %>% + mutate(variable = ifelse(variable == "Final Energy|Other|Other", "Final Energy|Other", variable)) %>% + mutate(unit = "Mtoe") %>% + select(model, scenario, region, variable, unit, period, value) + tmp7 <- rbind( + tmp7, + rbind( + tmp7 %>% + filter(period < 2025) %>% + mutate(scenario = "Current Policies Scenario"), + tmp_cps[which(tmp_sps[, 1] == "Other"):which(tmp_sps[, 1] == "Petrochem. feedstock"), ] %>% + gather(period, value, -variable) %>% + mutate(period = as.numeric(period)) %>% + mutate(model = "IEA-WEM2019") %>% + mutate(scenario = "Current Policies Scenario") %>% + mutate(region = kreg) %>% + mutate(variable = paste0("Final Energy|Other|", variable)) %>% + mutate(variable = ifelse(variable == "Final Energy|Other|Other", "Final Energy|Other", variable)) %>% + mutate(unit = "Mtoe") %>% + select(model, scenario, region, variable, unit, period, value)), + rbind( tmp7 %>% filter(period < 2025) %>% mutate(scenario = "Sustainable Development Scenario"), @@ -448,39 +438,33 @@ readIEA_WEO <- function(subtype) { mutate(model = "IEA-WEM2019") %>% mutate(scenario = "Sustainable Development Scenario") %>% mutate(region = kreg) %>% - # mutate(variable = ifelse(variable == "Traditional biomass", "Bioenergy|Traditional biomass", variable)) %>% - # mutate(variable = ifelse(variable == "Bioenergy", "Biomass", variable)) %>% mutate(variable = paste0("Final Energy|Other|", variable)) %>% mutate(variable = ifelse(variable == "Final Energy|Other|Other", "Final Energy|Other", variable)) %>% mutate(unit = "Mtoe") %>% - select(model, scenario, region, variable, unit, period, value))) - - tmp_all[[kreg]] <- rbind(tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7) - - } + select(model, scenario, region, variable, unit, period, value)) + ) - data_weo2019 <- do.call("rbind", tmp_all) + tmp_all[[kreg]] <- rbind(tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7) - # load(file = "data_weo2019.RData") - data_weo2019 <- data_weo2019[, c(3, 6, 1, 2, 5, 4, 7)] - data_weo2019$period <- as.numeric(data_weo2019$period) - data_weo2019$variable <- gsub(pattern = "\\.", replacement = "_", x = data_weo2019$variable) + } - if (subtype == "PE") { - data_weo2019 <- data_weo2019 %>% filter(variable %in% - grep("Primary Energy", unique(data_weo2019$variable), value = T)) - } - else if (subtype == "FE") { - data_weo2019 <- data_weo2019 %>% filter(variable %in% - grep("Final Energy", unique(data_weo2019$variable), value = T)) - } + data_weo2019 <- do.call("rbind", tmp_all) + data_weo2019 <- data_weo2019[, c(3, 6, 1, 2, 5, 4, 7)] + data_weo2019$period <- as.numeric(data_weo2019$period) + data_weo2019$variable <- gsub(pattern = "\\.", replacement = "_", x = data_weo2019$variable) - x <- as.magpie(data_weo2019, spatial = 1, temporal = 2, datacol = 7) + if (subtype == "PE") { + data_weo2019 <- data_weo2019 %>% filter(variable %in% + grep("Primary Energy", unique(data_weo2019$variable), value = TRUE)) + } else if (subtype == "FE") { + data_weo2019 <- data_weo2019 %>% filter(variable %in% + grep("Final Energy", unique(data_weo2019$variable), value = TRUE)) } - else { - stop("Not a valid subtype!") - } - # x[,,] <- as.numeric(x[,,]) - return(x) + x <- as.magpie(data_weo2019, spatial = 1, temporal = 2, datacol = 7) + } else { + stop("Not a valid subtype!") } + + return(x) +} diff --git a/R/readIEA_WEO_2021.R b/R/readIEA_WEO_2021.R deleted file mode 100644 index 56fc2703..00000000 --- a/R/readIEA_WEO_2021.R +++ /dev/null @@ -1,70 +0,0 @@ -#' IEA WEO 2021 Data -#' @description IEA WEO 2021 Data. See README in input file for more details. -#' -#' @return A [`magpie`][magclass::magclass] object. -#' @author Falk Benke -#' @importFrom dplyr filter %>% distinct group_by ungroup rename_all -#' @importFrom rlang sym -#' - -readIEA_WEO_2021 <- function() { # nolint - - data <- rbind( - read.csv2( - file = "complete/WEO2021_Extended_Data_Regions.csv", - sep = "," - ) %>% rename_all(tolower), - read.csv2( - file = "complete/WEO2021_Extended_Data_Supply_Refining_Trade_Prices.csv", - sep = "," - ) %>% rename_all(tolower), - read.csv( - file = "complete/WEO2021_Extended_Data_World.csv", - sep = "," - ) %>% rename_all(tolower), - read.csv( - file = "complete/WEO2021_Extended_Data_Investment.csv", - sep = "," - ) %>% rename_all(tolower) - ) %>% - mutate( - !!sym("value") := ifelse(!!sym("unit") == "PJ", as.numeric(!!sym("value")) / 1000, as.numeric(!!sym("value"))), - !!sym("unit") := ifelse(!!sym("unit") == "PJ", "EJ", !!sym("unit")), - variable = paste0(!!sym("category"), "-", !!sym("product"), "-", !!sym("flow"), " (", !!sym("unit"), ")") - ) %>% - select("region", "year", "scenario", "variable", "value") %>% - group_by( - !!sym("region"), !!sym("year"), !!sym("scenario"), !!sym("variable") - ) %>% - distinct() %>% - ungroup() - - # investment data uses yearly ranges and needs special treatment - # we currently don't read in cumulative investment spending, only annual average spending - rangeData <- filter( - data, is.na(as.numeric(!!sym("year"))), - grepl("Investment spending, annual average", !!sym("variable")) - ) - - # remove non-annual data - data <- filter(data, !is.na(as.numeric(!!sym("year")))) - - years <- as.numeric(unique(data$year)) - - splitData <- data.frame() - - for (i in seq(1, nrow(rangeData))) { - d <- rangeData[i, ] - minY <- as.numeric(sub("-[0-9]{4}", "", d[, "year"])) - maxY <- as.numeric(sub("[0-9]{4}-", "", d[, "year"])) - y <- data.frame(year = seq(minY, maxY, 1), variable = d[, "variable"]) %>% - filter(!!sym("year") %in% years) - splitData <- rbind(splitData, left_join(y, select(d, -2), by = "variable")) - } - - data <- rbind(data, splitData) - - as.magpie(data, temporal = 2, spatial = 1, datacol = 5) %>% - magpiesort() %>% - return() -} diff --git a/R/readIEA_WorldEnergyOutlook.R b/R/readIEA_WorldEnergyOutlook.R new file mode 100644 index 00000000..7f4c623b --- /dev/null +++ b/R/readIEA_WorldEnergyOutlook.R @@ -0,0 +1,66 @@ +#' Read in IEA World Energy Outlook Data from 2023 +#' +#' @author Falk Benke +#' @importFrom dplyr filter distinct group_by ungroup rename_all +#' +readIEA_WorldEnergyOutlook <- function() { # nolint + + data <- rbind( + read.csv2( + file = "2023/complete/WEO2023_Extended_Data_Regions.csv", + sep = "," + ) %>% rename_all(tolower), + read.csv2( + file = "2023/complete/WEO2023_Extended_Data_Supply_Refining_H2_Trade_Prices.csv", + sep = "," + ) %>% rename_all(tolower), + read.csv( + file = "2023/complete/WEO2023_Extended_Data_World.csv", + sep = "," + ) %>% rename_all(tolower), + read.csv( + file = "2023/complete/WEO2023_Extended_Data_Investment.csv", + sep = "," + ) %>% rename_all(tolower) + ) %>% + mutate( + "value" = ifelse(.data$unit == "PJ", as.numeric(.data$value) / 1000, as.numeric(.data$value)), + "unit" = ifelse(.data$unit == "PJ", "EJ", .data$unit), + "variable" = paste0(.data$category, "-", .data$product, "-", .data$flow, " (", .data$unit, ")") + ) %>% + select("region", "year", "scenario", "variable", "value") %>% + group_by(.data$region, .data$year, .data$scenario, .data$variable) %>% + distinct() %>% + ungroup() + + # investment data uses yearly ranges and needs special treatment + # we currently don't read in cumulative investment spending, only annual average spending + rangeData <- data %>% filter( + is.na(suppressWarnings(as.numeric(.data$year))), + grepl("Investment spending, annual average", .data$variable) + ) + + # remove non-annual data + data <- data %>% + filter(!is.na(suppressWarnings(as.numeric(.data$year)))) + + years <- as.numeric(unique(data$year)) + + splitData <- data.frame() + + for (i in seq(1, nrow(rangeData))) { + d <- rangeData[i, ] + minY <- as.numeric(sub("-[0-9]{4}", "", d[, "year"])) + maxY <- as.numeric(sub("[0-9]{4}-", "", d[, "year"])) + y <- data.frame(year = seq(minY, maxY, 1), variable = d[, "variable"]) %>% + filter(.data$year %in% years) + splitData <- rbind(splitData, left_join(y, select(d, -2), by = "variable")) + } + + data <- rbind(data, splitData) + + as.magpie(data, temporal = 2, spatial = 1, datacol = 5) %>% + magpiesort() %>% + return() + +} diff --git a/R/readIIASA_subs_taxes.R b/R/readIIASA_subs_taxes.R index cadad4d0..ff65867e 100644 --- a/R/readIIASA_subs_taxes.R +++ b/R/readIIASA_subs_taxes.R @@ -1,9 +1,9 @@ - #' Read IIASA subsidies and taxes -#' +#' Read IIASA subsidies and taxes +#' #' Read-in country level data on final energy taxes and subsidies as provided #' from IIASA from .csv file as magclass object -#' -#' +#' +#' #' @param subtype Type of country level data as compiled by IIASA that should #' be read in. Available types are: \itemize{ \item \code{tax_rate}: tax rate #' pre final energy category \item \code{sub_rate}: subsidy rate per final @@ -12,18 +12,18 @@ #' @author Christoph Bertram #' @seealso \code{\link{readSource}} #' @examples -#' -#' \dontrun{ a <- readSource(type="IIASA_subs_taxes","tax_rate") +#' \dontrun{ +#' a <- readSource(type = "IIASA_subs_taxes", "tax_rate") #' } -#' -readIIASA_subs_taxes<- function(subtype){ +#' +readIIASA_subs_taxes <- function(subtype) { file <- "unlinked_countries_2017_03.xlsx" - #subtype = tax_rate, sub_rate, energy - data <- read_excel(file, sheet=subtype) - data <- data[!is.na(data[[1]]),] - - data$CountryName <- NULL# remove country - x <- as.data.frame(sapply(data[!names(data)=="CountryCode"],as.numeric)) + # subtype = tax_rate, sub_rate, energy + data <- read_excel(file, sheet = subtype) + data <- data[!is.na(data[[1]]), ] + + data$CountryName <- NULL # remove country + x <- as.data.frame(sapply(data[!names(data) == "CountryCode"], as.numeric)) x$CountryCode <- data$CountryCode x <- as.magpie(x) return(x) diff --git a/R/readILO.R b/R/readILO.R deleted file mode 100644 index 76eedfd5..00000000 --- a/R/readILO.R +++ /dev/null @@ -1,17 +0,0 @@ -#' Read ILO - -readILO <- function(){ - obs_value <- NULL - input <- read.csv(file = "ilostat-2020-10-09.csv") %>% select(-2,-3,-4,-9,-10) %>% - filter(!is.na(obs_value)) %>% rename(Country=1,Variable=2,Year=3,Value=4,Confidence=5) - -input$Variable <- gsub(pattern = unique(input$Variable)[1], - replacement = "Oil and Gas",x = input$Variable,fixed = T) - -input$Variable <- gsub(pattern = unique(input$Variable)[2], - replacement = "Coal and Lignite",x = input$Variable,fixed = T) - -input <- input[,c(1,3,4,2,5)] -x <- as.magpie(input,spatial=1,temporal=2,datacol=3) -x <- collapseNames(x) -} diff --git a/R/readINNOPATHS.R b/R/readINNOPATHS.R index 753538c4..2ca7c9e2 100644 --- a/R/readINNOPATHS.R +++ b/R/readINNOPATHS.R @@ -1,22 +1,11 @@ #' Read INNOPATHS -#' -#' @author Falk Benke -#' @importFrom utils read.csv -#' @importFrom reshape2 melt -#' @importFrom magclass as.magpie -#' @importFrom dplyr select filter mutate %>% - readINNOPATHS <- function() { - - data <- read.csv(file = "INNPATHS database.csv", sep = ";") - - data <- melt(data, id.vars = 1:5, variable.name = "period", value.name = "value") %>% - filter(!is.na(!!sym("value"))) %>% - mutate(!!sym("value") := as.double(!!sym("value")), - !!sym("period") := as.numeric(sub("X","",!!sym("period")))) %>% - select(-c("MODEL", "SCENARIO")) - - x <- as.magpie(data, spatial = 1, temporal = 4) - - return(x) + utils::read.csv(file = "INNPATHS database.csv", sep = ";") %>% + tidyr::pivot_longer(tidyselect::starts_with("X"), + names_to = "period", + names_pattern = "X(.*)", + names_transform = as.numeric) %>% + dplyr::filter(!is.na(.data$value)) %>% + dplyr::select(-"MODEL", -"SCENARIO") %>% + as.magpie(spatial = 1, temporal = 4) } diff --git a/R/readIRENA.R b/R/readIRENA.R index 3c2bd7b4..3c12b00a 100644 --- a/R/readIRENA.R +++ b/R/readIRENA.R @@ -12,7 +12,7 @@ #' a <- readSource(type = "IRENA", subtype = "Capacity") #' } #' -#' @importFrom dplyr mutate %>% rename +#' @importFrom dplyr mutate rename #' @importFrom readr read_csv readIRENA <- function(subtype) { @@ -31,7 +31,7 @@ readIRENA <- function(subtype) { id.vars = c(1, 2), variable.name = "years", value.name = "value" ) %>% - mutate(!!sym("value") := as.numeric(!!sym("value"))) %>% + mutate("value" = as.numeric(!!sym("value"))) %>% suppressWarnings() # rearrange column order to more readable format: year, country, tech, value (capacity or generation) diff --git a/R/readKLWdamage.R b/R/readKLWdamage.R new file mode 100644 index 00000000..91486c35 --- /dev/null +++ b/R/readKLWdamage.R @@ -0,0 +1,31 @@ +#' Reads country-specific damage coefficients for the damage function presented in +#' Kotz et al. (2024). Data has been provided by the authors. +#' This contains data for all countries and for 1000 boostrapping realizations per country, +#' capturing uncertainty from climate and empirical modeling. +#' Subtypes are the temperature and temperature^2 coefficients and the maximum temperature +#' per country for which the function is defined. +#' +#' @return KLW damage coefficients +#' @author Franziska Piontek +#' @param subtype data subtype. Either "beta1", "beta2" or "maxGMT" + +readKLWdamage <- function(subtype) { + if (subtype == "beta1") { + a <- read.csv(file = "PERC_scaling_coefs_ssp2_ssp585_lagdiff_lintren_fix_spec_NL_8_9_10_movfix_30_Nboot1000_beta1.csv") + } else if (subtype == "beta2") { + a <- read.csv(file = "PERC_scaling_coefs_ssp2_ssp585_lagdiff_lintren_fix_spec_NL_8_9_10_movfix_30_Nboot1000_beta2.csv") + } else if (subtype == "maxGMT") { + a <- read.csv(file = "PERC_scaling_coefs_ssp2_ssp585_lagdiff_lintren_fix_spec_NL_8_9_10_movfix_30_Nboot1000_maxGMT.csv") + } + iso <- colnames(a)[2:length(colnames(a))] + + for (i in iso) { + col <- which(colnames(a) == i) + if (col == 2) { + out <- new.magpie(iso[1], NULL, seq(1:1000), a[, col], sets = c("CountryCode", "year", "sample")) + } else { + out <- mbind(out, new.magpie(i, NULL, seq(1:1000), a[, col], sets = c("CountryCode", "year", "sample"))) + } + } + return(out) +} diff --git a/R/readLIMITS.R b/R/readLIMITS.R index 961ed695..33dcb9ad 100755 --- a/R/readLIMITS.R +++ b/R/readLIMITS.R @@ -1,14 +1,13 @@ readLIMITS <- function(subtype) { - if (is.null(subtype)) stop("Please provide one of the following subtypes: 'activities' or 'emissions'") - x <- as.data.frame(read_excel("LIMITS_sector_act_emi.xlsx", sheet=subtype)) - + x <- as.data.frame(read_excel("LIMITS_sector_act_emi.xlsx", sheet = subtype)) + if (subtype == "activities") { - x <- as.magpie(x, spatial=1, temporal=4) + x <- as.magpie(x, spatial = 1, temporal = 4) } else if (subtype == "emissions") { - x <- as.magpie(x, spatial=1, temporal=5, datacol=6) + x <- as.magpie(x, spatial = 1, temporal = 5, datacol = 6) } - + return(x) } diff --git a/R/readLee.R b/R/readLee.R index e21166db..20584afc 100644 --- a/R/readLee.R +++ b/R/readLee.R @@ -1,61 +1,55 @@ #' readLee #' Read in Aviation emission data from Lee -#' +#' #' @return magpie object of Aviation emission / emission factors data #' @author Julian Oeser #' @param subtype Either 'emi' or 'ef' #' @seealso \code{\link{readSource}} #' @examples -#' -#' \dontrun{ a <- readSource(type="", subtype="Waste") +#' \dontrun{ +#' a <- readSource(type = "", subtype = "Waste") #' } -#' -#' -#' @importFrom readxl read_excel -#' @importFrom reshape2 melt -#' @importFrom data.table dcast - - readLee <- function(subtype) { - - avi <- read_excel("Lee_Global_Aviation.xlsx", sheet="output_to_R") # data only contains BC and NOx emissions from aircraft - - # restructure dataframe - avi <- melt(avi,id=c("Year","Tg")) # from wide to long format, keep only Year and Tg - avi <- dcast(avi,Year + variable ~ Tg) # from long to wide format, bring contents of Tg to columns and differentiate by Year and variable - avi <- avi[,c(1,2,4,3,5)] # reorder columns - tmp_A1 <- as.magpie(avi[avi$variable=="A1", !names(avi) == "variable"]) - tmp_A1 <- add_dimension(tmp_A1,dim=3.2,add="scenario",nm="A1") + # Data only contains BC and NOx emissions from aircraft + avi <- readxl::read_excel("Lee_Global_Aviation.xlsx", sheet = "output_to_R") + + # Restructure dataframe + avi <- reshape2::melt(avi, id = c("Year", "Tg")) + avi <- data.table::dcast(avi, Year + variable ~ Tg) + avi <- avi[, c(1, 2, 4, 3, 5)] + tmp_A1 <- as.magpie(avi[avi$variable == "A1", !names(avi) == "variable"]) + tmp_A1 <- add_dimension(tmp_A1, dim = 3.2, add = "scenario", nm = "A1") avi <- mbind(tmp_A1) - - avi <- time_interpolate(avi, interpolated_year=seq(2005,2100,5), integrate_interpolated_years=TRUE, extrapolation_type="constant") - avi <- avi[,"y2000",invert=TRUE] - + + avi <- time_interpolate(avi, + interpolated_year = seq(2005, 2100, 5), + integrate_interpolated_years = TRUE, + extrapolation_type = "constant") + avi <- avi[, "y2000", invert = TRUE] + # Add sector name - getNames(avi) <- paste0("Aviation.",getNames(avi)) - - avi_act <- collapseNames(avi[,,"Fuel"]) # activity until 2020 is scenario independent - avi_emi <- avi[,,"Fuel",invert=TRUE] - + getNames(avi) <- paste0("Aviation.", getNames(avi)) + + avi_act <- collapseNames(avi[, , "Fuel"]) # activity until 2020 is scenario independent + avi_emi <- avi[, , "Fuel", invert = TRUE] + # add empty SSP dimensions - getSets(avi_emi) <- c("region","year","sector","emi","scenario") - avi_emi <- add_columns(avi_emi, addnm=c("SSP1","SSP2","SSP5"),dim=3.3) - + getSets(avi_emi) <- c("region", "year", "sector", "emi", "scenario") + avi_emi <- add_columns(avi_emi, addnm = c("SSP1", "SSP2", "SSP5"), dim = 3.3) + # fill with scenrio data (SSP5 = A1, SSP1 and SSP2 need to be confirmed) - avi_emi[,,"SSP1"] <- avi_emi[,,"A1"] - avi_emi[,,"SSP5"] <- avi_emi[,,"SSP1"] - avi_emi[,,"SSP2"] <- avi_emi[,,"A1"] - avi_ef <- avi_emi/avi_act - getSets(avi_ef) <- c("region","year","sector","emi","scenario") - + avi_emi[, , "SSP1"] <- avi_emi[, , "A1"] + avi_emi[, , "SSP5"] <- avi_emi[, , "SSP1"] + avi_emi[, , "SSP2"] <- avi_emi[, , "A1"] + avi_ef <- avi_emi / avi_act + getSets(avi_ef) <- c("region", "year", "sector", "emi", "scenario") + if (subtype == "ef") { out <- avi_ef - } else if (subtype == "emi"){ + } else if (subtype == "emi") { out <- avi_emi } else { stop("Invalid subtype.") } - - return(out) - + out } diff --git a/R/readMacknickIntensities.R b/R/readMacknickIntensities.R index 7a4c138e..d640154b 100644 --- a/R/readMacknickIntensities.R +++ b/R/readMacknickIntensities.R @@ -1,9 +1,9 @@ #' Read Macknic Intensities -#' +#' #' Read in Macknick (2011) data on water consumption and withdrawal #' coefficients per electricity technology -#' -#' +#' +#' #' @param subtype Type of Macknick data that should be read. Available types #' are: \itemize{ \item \code{data}: The original Macknick source data \item #' \code{missingAssumed}: Additional data to fill gaps } @@ -11,17 +11,15 @@ #' @author Ioanna Mouratiadou #' @seealso \code{\link{readSource}} #' @examples -#' -#' \dontrun{ a <- readSource(type="MacknickIntensities", convert = FALSE) +#' \dontrun{ +#' a <- readSource(type = "MacknickIntensities", convert = FALSE) #' } -#' @importFrom madrat toolSubtypeSelect -readMacknickIntensities <- function(subtype) { - - sheets <- c(data=1, missingAssumed=2) - sheet <- toolSubtypeSelect(subtype,sheets) - +readMacknickIntensities <- function(subtype) { + sheets <- c(data = 1, missingAssumed = 2) + sheet <- toolSubtypeSelect(subtype, sheets) + x <- as.data.frame(read_excel("MacknickIntensities.xlsx", sheet = sheet)) - x <- x[,!is.na(names(x))] - + x <- x[, !is.na(names(x))] + return(as.magpie(x)) -} +} diff --git a/R/readNIR.R b/R/readNIR.R index 347932cb..ba85ef1f 100644 --- a/R/readNIR.R +++ b/R/readNIR.R @@ -1,32 +1,33 @@ -#' @importFrom magclass new.magpie as.magpie getYears #' @importFrom readxl read_excel -readNIR<- function(subtype) { - sheets <- c("1B2"="Table1.B.2") - - sheet <- toolSubtypeSelect(subtype,sheets) - - files <- list.files(pattern=".xlsx$") - countries <- unique(regmatches(files,regexpr("[A-Z]{3}",files))) +readNIR <- function(subtype) { + + sheets <- c("1B2" = "Table1.B.2") + + sheet <- toolSubtypeSelect(subtype, sheets) + + files <- list.files(pattern = ".xlsx$") + countries <- unique(regmatches(files, regexpr("[A-Z]{3}", files))) years <- paste0("y", unique(substr(gsub("[^0-9]", "", files, ""), 5, 8))) - - if(subtype=="1B2") { - data <- new.magpie(countries, years, names=c("Oil", "Gas", "VentingOil", "VentingGas","FlaringOil", "FlaringGas"), sets=c("region", "year", "emissions")) + + if (subtype == "1B2") { + data <- new.magpie(countries, years, names = c("Oil", "Gas", "VentingOil", "VentingGas", + "FlaringOil", "FlaringGas"), sets = c("region", "year", "emissions")) for (i in files) { - country <- regmatches(i,regexpr("[A-Z]{3}",i)) + country <- regmatches(i, regexpr("[A-Z]{3}", i)) year <- paste0("y", substr(gsub("[^0-9]", "", i, ""), 5, 8)) - - nir <- read_excel(i, sheet = sheet, skip=4) - nir <- unname(unlist(nir[,10]))[c(4,11,20,21,24,25)] # select the needed column - nir[which(nir %in% c("NE", "IE","NO", "NA", NA))] <- 0 - nir <- as.numeric(nir) - - data[country,year,] <- nir + + nir <- read_excel(i, sheet = sheet, skip = 4, .name_repair = "unique_quiet") + nir <- unname(unlist(nir[, 10]))[c(4, 11, 20, 21, 24, 25)] + nir[which(nir %in% c("NE", "IE", "NO", "NA", NA))] <- 0 + nir <- suppressWarnings(as.numeric(nir)) + + data[country, year, ] <- nir } } else { stop("This it not a valid subtype for readNIR") - } + } x <- as.magpie(data) x[is.na(x)] <- 0 getYears(x) <- years diff --git a/R/readNREL.R b/R/readNREL.R index 1fd4d505..e29fbb8a 100644 --- a/R/readNREL.R +++ b/R/readNREL.R @@ -1,55 +1,57 @@ #' Read NREL -#' +#' #' Read-in NREL xlsx file as magclass object -#' -#' +#' #' @param subtype type either "onshore" or "offshore" #' @return magpie object of NREL #' @author Lavinia Baumstark #' @seealso \code{\link{readSource}} #' @examples -#' -#' \dontrun{ a <- readSource(type="NREL",subtype="onshore") +#' \dontrun{ +#' a <- readSource(type = "NREL", subtype = "onshore") #' } -#' +#' readNREL <- function(subtype) { - if (subtype == "onshore") { + if (subtype == "onshore") { + # read in data - x <- as.data.frame(read_excel("nrelcfddawindsc20130603.xlsx", sheet="Onshore Energy",skip=2)) - x <- x[1:182,1:32] + x <- as.data.frame(read_excel("nrelcfddawindsc20130603.xlsx", sheet = "Onshore Energy", + skip = 2, .name_repair = "unique_quiet")) + x <- x[1:182, 1:32] x <- x[-length(names(x))] - names(x) <- sub("\\.[0-9]*$","",names(x)) - names(x) <- gsub(" ",".",names(x)) - colnames(x)[2:11] <- paste("near",colnames(x)[2:11],sep=".") - colnames(x)[12:21] <- paste("transitional ",colnames(x)[12:21],sep=".") - colnames(x)[22:31] <- paste("far",colnames(x)[22:31],sep=".") - + names(x) <- sub("\\.[0-9]*$", "", names(x)) + names(x) <- gsub(" ", ".", names(x)) + colnames(x)[2:11] <- paste("near", colnames(x)[2:11], sep = ".") + colnames(x)[12:21] <- paste("transitional ", colnames(x)[12:21], sep = ".") + colnames(x)[22:31] <- paste("far", colnames(x)[22:31], sep = ".") + } else if (subtype == "offshore") { - + # read in data - x <- as.data.frame(read_excel("nrelcfddawindsc20130603.xlsx", sheet="Offshore Energy",skip=3)) - x <- x[1:560,1:33] + x <- as.data.frame(read_excel("nrelcfddawindsc20130603.xlsx", + sheet = "Offshore Energy", skip = 3, + .name_repair = "unique_quiet")) + x <- x[1:560, 1:33] x <- x[-length(names(x))] - names(x) <- sub("\\.[0-9]*$","",names(x)) - names(x) <- gsub(" ",".",names(x)) - colnames(x)[3:12] <- paste("near",colnames(x)[3:12],sep=".") - colnames(x)[13:22] <- paste("transitional ",colnames(x)[13:22],sep=".") - colnames(x)[23:32] <- paste("far",colnames(x)[23:32],sep=".") + names(x) <- sub("\\.[0-9]*$", "", names(x)) + names(x) <- gsub(" ", ".", names(x)) + colnames(x)[3:12] <- paste("near", colnames(x)[3:12], sep = ".") + colnames(x)[13:22] <- paste("transitional ", colnames(x)[13:22], sep = ".") + colnames(x)[23:32] <- paste("far", colnames(x)[23:32], sep = ".") x$depth_class[is.na(x$depth_class)] <- "Total" - x$IAM.country <- gsub(" Total","",x$IAM.country) - x$IAM.country[is.na(x$IAM.country)] <- x$IAM.country[which(is.na(x$IAM.country))-1] - x$IAM.country[is.na(x$IAM.country)] <- x$IAM.country[which(is.na(x$IAM.country))-1] - - - } - + x$IAM.country <- gsub(" Total", "", x$IAM.country) + x$IAM.country[is.na(x$IAM.country)] <- x$IAM.country[which(is.na(x$IAM.country)) - 1] + x$IAM.country[is.na(x$IAM.country)] <- x$IAM.country[which(is.na(x$IAM.country)) - 1] + } + # turn into a magclass object - x <- as.magpie(x, spatial=1) - + x <- as.magpie(x, spatial = 1) + if (subtype == "offshore") { - x <- x["Guadeloupe and Martinique",,,invert=TRUE] # FIXME find better solution how to deal with this part of ANT - } + # FIXME find better solution how to deal with this part of ANT + x <- x["Guadeloupe and Martinique", , , invert = TRUE] + } return(x) } diff --git a/R/readOECD.R b/R/readOECD.R new file mode 100644 index 00000000..f3657252 --- /dev/null +++ b/R/readOECD.R @@ -0,0 +1,26 @@ +#' Read OECD +#' +#' Read-in risk premium +#' +#' @order 1 +#' @inherit madrat::readSource return +#' @seealso [madrat::readSource()] +#' @examples \dontrun{ +#' readSource("OECD") +#' } +readOECD <- function() { + readxl::read_excel("cre-crc-current-english.xlsx", na = "-", progress = FALSE) %>% + dplyr::select("iso3c" = "Country Code\r\nISO Alpha 3", "Current Prevailing Classification") %>% + dplyr::mutate("Current Prevailing Classification" = as.numeric(.data$`Current Prevailing Classification`)) %>% + dplyr::filter(!is.na(.data$iso3c)) %>% + as.magpie() +} + +#' @rdname readOECD +#' @order 2 +#' @param x MAgPIE object returned from readOECD +convertOECD <- function(x) { + x[is.na(x)] <- 0 + x <- toolCountryFill(x, fill = 0) + x +} diff --git a/R/readOpenmod.R b/R/readOpenmod.R index 789549f1..a91c97ae 100644 --- a/R/readOpenmod.R +++ b/R/readOpenmod.R @@ -1,35 +1,28 @@ #' Read Openmod capacities data -#' +#' #' Read-in an modified openmod capacities data file as magclass object -#' -#' +#' #' @return magpie object of the LIMES team updated Openmod data on capacities (GW) -#' @author Renato Rodrigues #' @seealso \code{\link{readSource}} #' @examples -#' -#' \dontrun{ a <- readSource(type="Openmod") +#' \dontrun{ +#' a <- readSource(type = "Openmod") #' } -#' -#' @importFrom readxl read_excel -#' @importFrom reshape2 melt -#' +#' +readOpenmod <- function() { + # Read 2010 capacity data + data2010 <- read.csv2("LIMES_gencap_2010.csv", stringsAsFactors = FALSE) + data2010$period <- 2010 + data2010 <- reshape2::melt(data2010, id.vars = c("dummy", "period"), variable.name = "tech", value.name = "value") + data2010$value <- as.numeric(data2010$value) - readOpenmod <- function() { - - # read 2010 capacity data - data2010 <- read.csv2("LIMES_gencap_2010.csv",stringsAsFactors = F) - data2010$period <- 2010 - data2010 <- melt(data2010, id.vars=c("dummy","period"), variable.name="tech", value.name="value") # data in wide format. melt requires library(reshape2) - data2010$value <- as.numeric(data2010$value) - # read 2015 capacity data - data2015 <- read_excel("Generation capacity EU countries 2015 v3 - in preparation.xlsx",sheet="gencap2015_nooldT") - data2015$period <- 2015 - data2015 <- melt(data2015, id.vars=c("dummy","period"), variable.name="tech", value.name="value") # data in wide format. melt requires library(reshape2) - # data - x <- rbind(data2010,data2015) - # transform to magpie - x <- as.magpie(x,temporal=2,spatial=1,datacol=4) - - return(x) - } + # Read 2015 capacity data + data2015 <- readxl::read_excel("Generation capacity EU countries 2015 v3 - in preparation.xlsx", + sheet = "gencap2015_nooldT") + data2015$period <- 2015 + data2015 <- reshape2::melt(data2015, id.vars = c("dummy", "period"), variable.name = "tech", value.name = "value") + + x <- rbind(data2010, data2015) + + as.magpie(x, temporal = 2, spatial = 1, datacol = 4) +} diff --git a/R/readPWT.R b/R/readPWT.R new file mode 100644 index 00000000..8a68ed40 --- /dev/null +++ b/R/readPWT.R @@ -0,0 +1,27 @@ +#' Read PWT +#' +#' Read-in PWT data as magclass object +#' +#' @order 1 +#' @inherit madrat::readSource return +#' @seealso [madrat::readSource()] +#' @examples \dontrun{ +#' readSource("PWT") +#' } +readPWT <- function() { + pwt <- readxl::read_excel("pwt80.xlsx", sheet = "Data") + # Remove "country", "currency_unit" and indicator ("i_") columns + pwt <- pwt[, !grepl("(^country$|^currency_unit$|^i_)", names(pwt))] + # Transform to magpie + as.magpie(pwt) +} + +#' @rdname readPWT +#' @order 2 +#' @param x MAgPIE object returned by readPWT +convertPWT <- function(x) { + getSets(x) <- c("iso3c", "year", "variable") + x <- toolCountryFill(x) + x[is.na(x)] <- 0 + x +} diff --git a/R/readPauliuk.R b/R/readPauliuk.R index f3b1d8f4..5e068b78 100644 --- a/R/readPauliuk.R +++ b/R/readPauliuk.R @@ -1,6 +1,6 @@ #' Read Pauliuk et al. 2013 data -#' -#' Read data from Pauliuk et al. 2013 +#' +#' Read data from Pauliuk et al. 2013 #' (https://dx.doi.org/10.1016/j.resconrec.2012.11.008). #' #' @md @@ -9,12 +9,12 @@ #' in years. #' #' @return A [`magpie`][magclass::magclass] object. -#' +#' #' @author Michaja Pehl -#' +#' #' @seealso [`readSource()`] -#' -#' @importFrom dplyr %>% mutate +#' +#' @importFrom dplyr mutate #' @importFrom quitte madrat_mule #' @importFrom readxl read_xlsx #' @importFrom rlang .data @@ -30,15 +30,15 @@ readPauliuk <- function(subtype = 'lifetime') sheet = 'Supplementray_Table_23', range = 'A5:J201', col_names = c('country', 'lifetime'), - col_types = c('text', rep('skip', 8), 'numeric')) %>% - mutate(lifetime = as.integer(.data$lifetime)) %>% - madrat_mule() %>% + col_types = c('text', rep('skip', 8), 'numeric')) %>% + mutate(lifetime = as.integer(.data$lifetime)) %>% + madrat_mule() %>% return() }) - + # ---- check if the subtype called is available ---- if (is_empty(intersect(subtype, names(switchboard)))) { - stop(paste('Invalid subtype -- supported subtypes are:', + stop(paste('Invalid subtype -- supported subtypes are:', names(switchboard))) } else { # ---- load data and do whatever ---- diff --git a/R/readProdShares.R b/R/readProdShares.R index 1e346380..c5308a7b 100644 --- a/R/readProdShares.R +++ b/R/readProdShares.R @@ -1,22 +1,19 @@ -#'Reads shares of world manufacture for spv modules and wind turbines. +#' Reads shares of world manufacture for spv modules and wind turbines. #' @author Aman Malik #' @importFrom dplyr bind_rows #' @importFrom readxl read_excel -readProdShares <- function(){ +readProdShares <- function() { - - input_spv <- read_excel("shares.xlsx",sheet = "spv") + input_spv <- read_excel("shares.xlsx", sheet = "spv") input_spv$tech <- "spv" - - - input_wind <- read_excel("shares.xlsx",sheet="wind") + + input_wind <- read_excel("shares.xlsx", sheet = "wind") input_wind$tech <- "wind" - - input <- bind_rows(input_spv,input_wind) - - x <- as.magpie(input,spatial=1) - - return (x) + input <- bind_rows(input_spv, input_wind) + + x <- as.magpie(input, spatial = 1) + + return(x) } diff --git a/R/readRCP.R b/R/readRCP.R index c0a54dd0..8eaaa4e6 100644 --- a/R/readRCP.R +++ b/R/readRCP.R @@ -12,8 +12,7 @@ #' @param subtype Either 'Waste' or 'AviationShipping' #' #' @importFrom readxl read_excel -#' @importFrom dplyr filter_ mutate_ rename_ select_ recode -#' @importFrom tidyr gather_ separate_ +#' @importFrom dplyr recode #' @importFrom stats complete.cases readRCP <- function(subtype) { diff --git a/R/readREMIND_11Regi.R b/R/readREMIND_11Regi.R index 465e89ab..f1a9eefb 100644 --- a/R/readREMIND_11Regi.R +++ b/R/readREMIND_11Regi.R @@ -1,4 +1,3 @@ - #' Read REMIND region dependent data #' #' Read-in an csv files that contains regional data @@ -16,100 +15,62 @@ #' a <- readSource(type = "REMIND_11Regi", subtype = "capacityFactorGlobal") #' } readREMIND_11Regi <- function(subtype) { - - if (subtype == "p4") { - x <- read.csv("EconometricEmissionParameter_p4.csv", sep = ";", row.names = 1) - x <- as.magpie(x) - } else if (subtype == "biomass") { - x <- read_excel("biomass.xlsx") - x <- as.magpie(x, datacol = 4) - } else if (subtype == "ch4waste") { - x <- read.csv("emimac0_ch4waste.csv", sep = ";", row.names = 1) - x <- as.magpie(x) - } else if (subtype == "tradecost") { - x <- read.csv("LueckenDiss_TradeCost.csv", sep = ";", row.names = 1) - x <- as.magpie(x) - } else if (subtype == "pe2se") { - x <- read.csv("tax_pe2se_sub.csv", sep = ";") - x <- as.magpie(x, datacol = 2) - } else if (subtype == "xpres_tax") { - x <- read.csv("p21_tau_xpres_tax.csv", sep = ";") - x <- as.magpie(x, datacol = 2) - getYears(x) <- "y2005" - getNames(x) <- "peoil" - } else if (subtype == "deltacapoffset") { - x <- read.csv("p_adj_deltacapoffset.csv", sep = ";") - x <- as.magpie(x, datacol = 2) - } else if (subtype == "capacityFactorGlobal") { - x <- read.csv("f_cf-global.csv", sep = ";") - x[x$Tech == "rockgrind", "Tech"] <- "weathering" - x <- as.magpie(x, datacol = 2) - } else if (subtype == "capacityFactorRules") { - x <- read.csv("f_cf-rules.csv", sep = ";") - x <- as.magpie(x, datacol = 4) - } else if (subtype == "storageFactor") { - x <- read.csv("storageFactor.csv", sep = ";") - x <- as.magpie(x, datacol = 2) - } else if (subtype == "residuesShare") { - x <- read.csv("residuesShare.csv", row.names = 1) - x <- as.magpie(x, datacol = 4) - } else if (subtype == "shareIndFE") { - x <- read.csv("shareIndustyFE.csv", sep = ";", skip = 3) - x <- as.magpie(x, datacol = 3) - } else if (subtype == "taxConvergence") { - x <- read.csv("tax_convergence.csv", sep = ";") - x <- as.magpie(x, datacol = 4) - } else if (subtype == "maxFeSubsidy") { - x <- read.csv("max_FE_subsidy.csv", sep = ";") - x <- as.magpie(x, datacol = 4) - } else if (subtype == "maxPeSubsidy") { - x <- read.csv("max_PE_subsidy.csv", sep = ";") - x <- as.magpie(x, datacol = 4) - } else if (subtype == "propFeSubsidy") { - x <- read.csv("prop_FE_subsidy.csv", sep = ";") - x <- as.magpie(x, datacol = 4) - } else if (subtype == "gridFactor") { - x <- read.csv("homogenous_regions_for grids.csv", sep = ";") - x$X <- NULL - x <- as.magpie(x, datacol = 2) - } else if (subtype == "AP_starting_values") { - x <- read.csv("f11_emiAPexsolve.cs4r", sep = ",", skip = 1, header = FALSE) - x <- as.magpie(x, datacol = 6) - } else if (subtype == "ccs") { - x <- read.csv("p_dataccs.csv", sep = ";") - x <- as.magpie(x, spatial = 1, datacol = 2) - } else if (subtype == "ffPolyRent") { - x <- read.csv("ffPolyRent.csv", sep = ";") - x <- as.magpie(x, spatial = 1, datacol = 5) - } else if (subtype == "ffPolyCumEx") { - x <- read.csv("ffPolyCumEx.csv", sep = ";") - x <- as.magpie(x, spatial = 1, datacol = 5) - } else if (subtype == "fossilExtractionCoeff") { - x <- read.csv("fossil_extraction_cost_eq_coefficients.csv", sep = ";") - # removing the X string added to the column names because how the read.table call inside - # the read.csv function converts column name numbers to valid variable strings (by using check.names) - colnames(x) <- gsub("^X", "", colnames(x)) - x <- as.magpie(x, spatial = 1, temporal = 0, datacol = 3) - # JPN SSP5 gas extraction zero-order coeff was originally negative. - x["JPN", , "highGas.0"] <- 0 - } else if (subtype == "uraniumExtractionCoeff") { - x <- read.csv("uranium_extraction_cost_eq_coefficients.csv", sep = ";") - x <- as.magpie(x, spatial = 1, temporal = 0, datacol = 3) - } else if (subtype == "RLDCCoefficientsLoB") { - x <- read.csv("RLDC_Coefficients_LoB.csv", sep = ";") - x <- as.magpie(x, spatial = 1, temporal = 0, datacol = 3) - } else if (subtype == "RLDCCoefficientsPeak") { - x <- read.csv("RLDC_Coefficients_Peak.csv", sep = ";") - x <- as.magpie(x, spatial = 1, temporal = 0, datacol = 3) - } else if (subtype == "earlyRetirementAdjFactor") { - y <- read.csv("earlyRetirementAdjFactor.csv", sep = ";", skip = 5) - x <- as.magpie(y, spatial = 1, temporal = 0, datacol = 2) - x <- setNames(x, colnames(y)[-1]) - } else if (subtype == "nashWeight") { - x <- read.csv("nash_weights.csv", sep = ";") - x <- as.magpie(x, spatial = 1, datacol = 2) - } else { + switch( + subtype, + "p4" = read.csv("EconometricEmissionParameter_p4.csv", sep = ";", row.names = 1) %>% as.magpie(), + "biomass" = readxl::read_excel("biomass.xlsx") %>% as.magpie(x, datacol = 4), + "ch4waste" = read.csv("emimac0_ch4waste.csv", sep = ";", row.names = 1) %>% as.magpie(), + "tradecost" = read.csv("LueckenDiss_TradeCost.csv", sep = ";", row.names = 1) %>% as.magpie(), + "pe2se" = read.csv("tax_pe2se_sub.csv", sep = ";") %>% as.magpie(datacol = 2), + "xpres_tax" = { + x <- read.csv("p21_tau_xpres_tax.csv", sep = ";") + x <- as.magpie(x, datacol = 2) + getYears(x) <- "y2005" + getNames(x) <- "peoil" + x + }, + "deltacapoffset" = read.csv("p_adj_deltacapoffset.csv", sep = ";") %>% as.magpie(datacol = 2), + "capacityFactorGlobal" = read.csv("f_cf-global_REMIND_3.3.5.csv", sep = ";") %>% as.magpie(datacol = 2), + "capacityFactorRules" = read.csv("f_cf-rules.csv", sep = ";") %>% as.magpie(datacol = 4), + "storageFactor" = read.csv("storageFactor.csv", sep = ";") %>% as.magpie(datacol = 2), + "residuesShare" = read.csv("residuesShare.csv", row.names = 1) %>% as.magpie(datacol = 4), + "shareIndFE" = read.csv("shareIndustyFE.csv", sep = ";", skip = 3) %>% as.magpie(datacol = 3), + "taxConvergence" = read.csv("tax_convergence.csv", sep = ";") %>% as.magpie(datacol = 4), + "maxFeSubsidy" = read.csv("max_FE_subsidy.csv", sep = ";") %>% as.magpie(datacol = 4), + "maxPeSubsidy" = read.csv("max_PE_subsidy.csv", sep = ";") %>% as.magpie(datacol = 4), + "propFeSubsidy" = read.csv("prop_FE_subsidy.csv", sep = ";") %>% as.magpie(datacol = 4), + "gridFactor" = { + x <- read.csv("homogenous_regions_for grids.csv", sep = ";") + x$X <- NULL + as.magpie(x, datacol = 2) + }, + "AP_starting_values" = read.csv("f11_emiAPexsolve.cs4r", skip = 1, header = FALSE) %>% as.magpie(datacol = 6), + "ccs" = read.csv("p_dataccs.csv", sep = ";") %>% as.magpie(spatial = 1, datacol = 2), + "ffPolyRent" = read.csv("ffPolyRent.csv", sep = ";") %>% as.magpie(spatial = 1, datacol = 5), + "ffPolyCumEx" = read.csv("ffPolyCumEx.csv", sep = ";") %>% as.magpie(spatial = 1, datacol = 5), + "fossilExtractionCoeff" = { + x <- read.csv("fossil_extraction_cost_eq_coefficients.csv", sep = ";") + # Removing the X string added to the column names because how the read.table call inside + # the read.csv function converts column name numbers to valid variable strings (by using check.names) + colnames(x) <- gsub("^X", "", colnames(x)) + x <- as.magpie(x, spatial = 1, temporal = 0, datacol = 3) + # JPN SSP5 gas extraction zero-order coeff was originally negative. + x["JPN", , "highGas.0"] <- 0 + x + }, + "uraniumExtractionCoeff" = read.csv("uranium_extraction_cost_eq_coefficients.csv", sep = ";") %>% + as.magpie(spatial = 1, temporal = 0, datacol = 3), + "RLDCCoefficientsLoB" = read.csv("RLDC_Coefficients_LoB.csv", sep = ";") %>% + as.magpie(spatial = 1, temporal = 0, datacol = 3), + "RLDCCoefficientsPeak" = read.csv("RLDC_Coefficients_Peak.csv", sep = ";") %>% + as.magpie(spatial = 1, temporal = 0, datacol = 3), + "earlyRetirementAdjFactor" = { + y <- read.csv("earlyRetirementAdjFactor.csv", sep = ";", skip = 5) + x <- as.magpie(y, spatial = 1, temporal = 0, datacol = 2) + x <- setNames(x, colnames(y)[-1]) + x + }, + "nashWeight" = read.csv("nash_weights.csv", sep = ";") %>% as.magpie(spatial = 1, datacol = 2), stop("Not a valid subtype!") - } - return(x) + ) } diff --git a/R/readREN21.R b/R/readREN21.R index 1508389d..69e34b60 100644 --- a/R/readREN21.R +++ b/R/readREN21.R @@ -1,7 +1,7 @@ #' Reads policy database from REN21 2017 with capacity targets or regional technology costs -#' @description Reads excel sheet with data on proposed policies, -#' on Renewable energy capacity targets (which are broken down into Total Installed Capacity -#' (TIC-Absolute), Additional Installed Capacity (AC-Absolute), and Production Absolute targets) +#' @description Reads excel sheet with data on proposed policies, +#' on Renewable energy capacity targets (which are broken down into Total Installed Capacity +#' (TIC-Absolute), Additional Installed Capacity (AC-Absolute), and Production Absolute targets) #' or regional technology costs #' @details Country name is ISO coded. Capacity/Additional Capacity targets are in GW. Generation/Production targets are in GWh. #' @return magpie object with Total Installed Capacity targets in GW for different target years @@ -9,15 +9,13 @@ #' @param subtype Capacity Generation Emissions Share #' @importFrom readxl read_excel - -readREN21 <- function(subtype){ +readREN21 <- function(subtype) { if (subtype == "Capacity") { REN21 <- read_excel("REN21.xlsx", sheet = "REN21") - x <- as.magpie(REN21,spatial=1,temporal=2,datacol=3) + x <- as.magpie(REN21, spatial = 1, temporal = 2, datacol = 3) } else if (subtype == "investmentCosts") { - REN21 <- read.csv("REN21_investment_costs.csv",sep=";") - x <- as.magpie(REN21,spatial=1) + REN21 <- read.csv("REN21_investment_costs.csv", sep = ";") + x <- as.magpie(REN21, spatial = 1) } - -return(x) + return(x) } diff --git a/R/readRam.R b/R/readRam.R deleted file mode 100644 index 20e8c7e5..00000000 --- a/R/readRam.R +++ /dev/null @@ -1,9 +0,0 @@ -#' Regional multiliers from Ram et al. , 2018 - -readRam <- function(){ - regional_multiplier <- read_excel("regional_multiplier.xlsx") - x <- as.magpie(regional_multiplier,spatial=1) - - return (x) -} - diff --git a/R/readRemindCesPrices.R b/R/readRemindCesPrices.R deleted file mode 100644 index d5e4f593..00000000 --- a/R/readRemindCesPrices.R +++ /dev/null @@ -1,62 +0,0 @@ -#' Read RemindCesPrices -#' -#' Read-in CES derivatives/prices from former REMIND runs -#' -#' -#' @return magpie object of REMIND prices -#' @author Antoine Levesque -#' @seealso \code{\link{readSource}} -#' @param subtype Regional resolution of REMIND data which should be loaded. ccd632d33a corresponds to the REMIND-11, -#' and 690d3718e1 to REMIND-H12 -#' -#' @examples -#' \dontrun{ a <- readSource(type="RemindCesPrices", subtype = "ccd632d33a") -#' } -#' @importFrom magclass as.magpie -#' @importFrom quitte inline.data.frame -#' @importFrom dplyr mutate_ group_by_ summarise_ -#' -#' -readRemindCesPrices <- function(subtype = "ccd632d33a") { - - #-----FUNCTIONS-------- - loadfiles = function(regmap){ - files2load = list.files(pattern = paste0(regmap,".inc$")) - - data = NULL - - for (.file in files2load){ - - settings_file = as.list(unlist(strsplit(.file,"-"))) - names_list = unlist(lapply(settings_file, function(x) sub("^([^_]+)_.+$","\\1",x))) - names(settings_file) = names_list - settings_file = lapply(settings_file, function(x) sub("^([^_]+)_(.+$)","\\2",x)) - - tmp = readLines(.file,encoding = "UTF-8") - tmp = gsub("(pm_cesdata\\(|\\)| |\"|;)","",tmp ) - tmp = gsub("=",",",tmp) - tmp = grep("price",tmp,value = T) - tmp = c("period,region,variable,parameter,value", tmp) - tmp = inline.data.frame(tmp,sep = ",") - - data = rbind(data,tmp) - } - data <- data %>% - group_by(!!!syms(setdiff(colnames(data), "value"))) %>% - summarise(value = mean(.data$value)) %>% - ungroup() - - data$parameter = NULL - return(data) - } - #-----END FUNCTIONS---- - - - if (!subtype %in% c("ccd632d33a", "690d3718e1")) stop("valid subtypes are 'ccd632d33a', '690d3718e1'") - - mdata = as.magpie(loadfiles(subtype)) - - - - return(mdata) -} diff --git a/R/readRutovitz2015.R b/R/readRutovitz2015.R deleted file mode 100644 index ec087eeb..00000000 --- a/R/readRutovitz2015.R +++ /dev/null @@ -1,122 +0,0 @@ -#' Employment factors for various power production technologies from Rutovitz et al. 2015 -#' @description Rutovitz, J., Dominish, E., & Downes, J. (2015). Calculating global energy sector jobs—2015 methodology update. Institute for Sustainable Futures, University of Technology, Sydney. https://opus.lib.uts.edu.au/bitstream/10453/43718/1/Rutovitzetal2015Calculatingglobalenergysectorjobsmethodology.pdf -#' @author Aman Malik -#' @importFrom tidyr pivot_longer -#' @importFrom dplyr rename add_row filter_ mutate_ select_ left_join filter mutate -#' @importFrom readr read_csv -#' @return magpie object of employment factors for different technologies and activities in Jobs/MW (all except fuel_supply) or Jobs/PJ (fuel_supply). Subtype "regional_mult" is a regional multiplier without units. -#' @param subtype Either "oecd_ef","regional_ef","coal_ef","gas_ef", "regional_mult" - - -readRutovitz2015 <- function(subtype) { - # note: Employment factors from rutovitz2015 et al. are wt. average values from OECD countries. (Regional) Exceptions are input in subtype "regional_ef", "coal_ef" and "gas_ef" - CI <- NULL # construction and installation - Fuel_supply <- NULL # process of extraction of resource - Manf <- NULL # manufacturing - OM <- NULL # operation and maintenance - activity <- NULL # all 4 categories above are "activities" - region <- NULL - tech <- NULL # power production technology - duration <- NULL # average time (years) from start of construction to commission. - Productivity <- NULL - Year <- NULL - value <- NULL - if (subtype == "oecd_ef") { - input <- read_csv(file = "oecd_ef.csv", na = "", col_types = "cddddc") %>% - rename(tech = 1, duration = 2, CI = 3, Manf = 4, OM = 5, Fuel_supply = 6) %>% - filter(!is.na(tech)) %>% - add_row(tech = "CoalHP", duration = 5, CI = 11.2, Manf = 5.4, OM = 0.14 * 1.5, Fuel_supply = "Regional") %>% # for *HP technologies, multiply OM EF by 1.5 as in rutovitz - add_row(tech = "GasHP", duration = 2, CI = 1.3, Manf = 0.93, OM = 0.14 * 1.5, Fuel_supply = "Regional") %>% - add_row(tech = "BiomassHP", duration = 2, CI = 14, Manf = 2.9, OM = 1.5 * 1.5, Fuel_supply = "Regional") %>% - add_row(tech = "Oil", CI = 1.3, Manf = 0.93, OM = 0.14, Fuel_supply = "Regional", duration = 2) %>% # oil EF= Gas EF as in rutovitz - filter(!tech %in% grep("Ocean|decommissioning|heat|diesel", - x = tech, value = TRUE)) %>% # removing techs not relevant - mutate(tech = mgsub::mgsub(tech, c("Solar Photovoltaics", "Solar thermal"), - c("Solar|PV", "Solar|CSP"))) %>% ## renaming techs - mutate(across(c(CI, Manf, OM, duration), as.numeric)) %>% - mutate(Fuel_supply = ifelse(Fuel_supply == "0.001 jobs/GWh final demand", 0.001, Fuel_supply)) %>% - # mutate_(CI=~CI/duration) %>% # dividing employment intensity by construction period - # mutate_(Manf=~Manf/duration) %>% - select(-duration) %>% - mutate(`Fuel_supply` = ifelse(`Fuel_supply` == "Regional", 0, `Fuel_supply`), - `Fuel_supply` = as.numeric(`Fuel_supply`)) %>% - pivot_longer(names_to = "activity", values_to = "value", c(2:5)) %>% - # regional values exist for coal and gas and are read later - mutate(across(c(tech, activity), as.factor)) %>% - mutate(value = as.numeric(value)) - - x <- as.magpie(input, temporal = NULL, spatial = NULL, datacol = 3) - return(x) - } - - - if (subtype == "regional_ef") { - - input <- read_csv("regional_ef.csv", na = "", col_types = "ccdddd") %>% - rename(tech = 1, region = 2, CI = 3, Manf = 4, OM = 5, Fuel_supply = 6) %>% - filter(!is.na(tech)) %>% - # mutate(across(c(tech,region),as.character)) %>% - # mutate(across(c(CI,Manf,OM,Fuel_supply),as.numeric)) %>% - mutate(tech = mgsub::mgsub(tech, c("Solar PV", "Solar Thermal power", "Wind-offshore", "Wind-onshore"), - c("Solar|PV", "Solar|CSP", "Wind offshore", "Wind onshore"))) %>% - pivot_longer(c("CI", "Manf", "OM", "Fuel_supply"), names_to = "activity", values_to = "value") %>% - filter(!grepl("average", region)) %>% # removed OECD average values - na.omit() %>% - # left_join(const,by="tech") %>% - # mutate(region=ifelse(region=="OECD North America","OECD Americas",region)) - # mutate(value=ifelse(!activity %in% c("Fuel_supply","OM"),value/duration,value)) %>% - select(region, tech, activity, value) - - - x <- as.magpie(input, spatial = 1, temporal = NULL, datacol = 4) - - return(x) - } - - if (subtype == "coal_ef") { - input <- read_csv("coal_ef.csv", col_types = "cddd") %>% - select(-Year, -Productivity) %>% - rename(region = 1, value = 2) %>% - filter(!is.na(region)) %>% - mutate(value = ifelse(region == "Middle East", 39.7, value)) %>% - filter(!grepl("World", region)) %>% - mutate(region = ifelse(region == "Eastern Europe/Eurasia", "Eurasia", region)) %>% - mutate(tech = "Coal") %>% - mutate(activity = "Fuel_supply") %>% - mutate(value = as.numeric(value)) - input <- input[, c("region", "tech", "activity", "value")] - - x <- as.magpie(input, temporal = NULL, datacol = 4, spatial = 1) - - return(x) - } - - if (subtype == "gas_ef") { - input <- read_csv("gas_ef.csv", na = "", col_types = "cdcc") %>% - rename(region = 1, value = 2, notes = 3, Sources = 4) %>% - select(region, value) %>% - rbind(data.frame(region = c("India", "Latin America", "Developing Asia", "Middle East"), value = 15.1)) %>% # using world average values from dataset - filter(!is.na(value)) %>% - filter(!grepl("World", region)) %>% - mutate(region = ifelse(region == "Eastern Europe/Eurasia", "Eurasia", region)) %>% - mutate(tech = "Gas") %>% - mutate(activity = "Fuel_supply") - - input <- input[, c("region", "tech", "activity", "value")] - - x <- as.magpie(input, temporal = NULL, datacol = 4, spatial = 1) - - return(x) -} - if (subtype == "regional_mult") { - input <- read_csv("regional_mult.csv", na = "", col_types = "c") %>% - pivot_longer(cols = 2:4, names_to = "year") %>% - mutate(region = ifelse(region == "Eastern Europe/Eurasia", "Eurasia", region)) - - x <- as.magpie(input, spatial = 1, temporal = 2) - - return (x) - - } - -} diff --git a/R/readStationary.R b/R/readStationary.R index e654281e..66c78fea 100644 --- a/R/readStationary.R +++ b/R/readStationary.R @@ -3,7 +3,6 @@ #' @return magclass object #' #' @author Antoine Levesque, Robin Hasse -#' @importFrom magclass read.magpie mselect as.magpie mbind add_dimension readStationary <- function() { scenarios <- list( diff --git a/R/readStegmann2022.R b/R/readStegmann2022.R index 2f2e9a77..4185ccc6 100644 --- a/R/readStegmann2022.R +++ b/R/readStegmann2022.R @@ -18,13 +18,11 @@ #' } #' #' @importFrom readxl read_xlsx -#' @importFrom reshape2 melt readStegmann2022 <- function() { data <- read_xlsx("41586_2022_5422_MOESM1_ESM.xlsx", sheet = "Data") reshape2::melt(data, id.vars = seq(1, 5), variable.name = "period") %>% - as.magpie(spatial = 3) %>% - return() + as.magpie(spatial = 3) } diff --git a/R/readTCdamageKrichene.R b/R/readTCdamageKrichene.R index b0f95267..496ac2e6 100644 --- a/R/readTCdamageKrichene.R +++ b/R/readTCdamageKrichene.R @@ -10,21 +10,22 @@ #' @param subtype data subtype. Either "const" or "tasK" readTCdamageKrichene <- function(subtype) { + if (subtype == "const") { + a <- read.csv(file = "TC_df_parameters_const.csv", sep = ";") + } else if (subtype == "tasK") { + a <- read.csv(file = "TC_df_parameters_tasK.csv", sep = ";") + } - if (subtype == "const") { - a <- read.csv(file = "./TC_df_parameters_const.csv",sep=";") - } else if (subtype == "tasK") { - a <- read.csv(file = "./TC_df_parameters_tasK.csv",sep=";") - } + quant <- gsub("estimates_", "", colnames(a)[grepl("estimates", colnames(a))]) - quant <- gsub("estimates_", "", colnames(a)[grepl("estimates", colnames(a))]) - for (q in quant) { - col <- which(colnames(a) == paste0("estimates_", q)) - if (q == quant[1]) { - out <- new.magpie(a$iso, NULL, q, a[, col], sets = c("CountryCode", "year", "quantile")) - } else { - out <- mbind(out, new.magpie(a$iso, NULL, q, a[, col], sets = c("CountryCode", "year", "quantile"))) - } - } - return(out) + for (q in quant) { + col <- which(colnames(a) == paste0("estimates_", q)) + if (q == quant[1]) { + out <- new.magpie(a$iso, NULL, q, a[, col], sets = c("CountryCode", "year", "quantile")) + } else { + out <- mbind(out, new.magpie(a$iso, NULL, q, a[, col], + sets = c("CountryCode", "year", "quantile"))) + } + } + return(out) } diff --git a/R/readUBA.R b/R/readUBA.R index 637d1cc6..dd9acd32 100644 --- a/R/readUBA.R +++ b/R/readUBA.R @@ -9,12 +9,9 @@ #' @importFrom tibble tibble #' @importFrom dplyr select mutate #' @importFrom rlang sym -#' @importFrom reshape2 melt -#' @importFrom magclass as.magpie #' #' @export readUBA <- function() { - sheets <- tibble( sheet = c("THG", "CO2"), name = c("Emi|GHG", "Emi|CO2"), @@ -25,24 +22,38 @@ readUBA <- function() { data <- NULL for (i in seq(1:nrow(sheets))) { - tmp <- read_xlsx( - path = "2023_03_15_em_entwicklung_in_d_ksg-sektoren_pm.xlsx", sheet = sheets[["sheet"]][[i]], col_names = T, - range = sheets[["range"]][[i]], .name_repair = "minimal", na = c("n/a") - ) %>% select(-2) - colnames(tmp) <- c("sektor", seq(1990,2022,1)) + tmp <- suppressWarnings( + read_xlsx( + path = "2024_03_13_em_entwicklung_in_d_ksg-sektoren_thg_v1.0.xlsx", + sheet = sheets[["sheet"]][[i]], + col_names = T, + col_types = c("text", rep("numeric", 34)), + range = sheets[["range"]][[i]], + .name_repair = "minimal", + na = c("n/a") + ) + ) + + colnames(tmp) <- c("sektor", seq(1990, 2023, 1)) - tmp <- filter(tmp, !is.na(!!sym("sektor"))) %>% - mutate(!!sym("sektor") := paste0(sheets[["name"]][[i]], "|", sub("\\d - ", "", !!sym("sektor"))), !!sym("unit") := sheets[["unit"]][[i]]) + tmp <- tmp %>% + filter(!is.na(.data$sektor)) %>% + mutate( + "sektor" = paste0(sheets[["name"]][[i]], "|", sub("\\d - ", "", .data$sektor)), + "unit" = sheets[["unit"]][[i]] + ) data <- bind_rows(data, tmp) } - melt(data, id.vars = c("sektor", "unit")) %>% - select("period" = "variable", "unit" = "unit", "value", "variable" = "sektor") %>% - mutate("region" := "DEU", "value" := as.numeric(!!sym("value")) / 1000) %>% - select("region", "variable", "unit", "period", "value") %>% + reshape2::melt(data, id.vars = c("sektor", "unit")) %>% + select("period" = "variable", "unit" = "unit", "value", "variable" = "sektor") %>% + mutate( + "region" = "DEU", + "value" = as.numeric(.data$value) / 1000 + ) %>% + select("region", "variable", "unit", "period", "value") %>% filter(!is.na(!!sym("value"))) %>% - as.magpie() %>% - return() + as.magpie() } diff --git a/R/readUNFCCC.R b/R/readUNFCCC.R index b6d90606..33314ab8 100644 --- a/R/readUNFCCC.R +++ b/R/readUNFCCC.R @@ -6,12 +6,10 @@ #' #' @seealso [`readSource()`] #' -#' @importFrom dplyr %>% bind_rows bind_cols mutate select +#' @importFrom dplyr bind_rows bind_cols mutate select #' -#' @importFrom magclass as.magpie #' @importFrom tibble tibble #' @importFrom tidyr drop_na -#' @importFrom reshape2 melt #' @importFrom readxl read_xlsx #' @importFrom rlang sym #' @@ -24,6 +22,7 @@ readUNFCCC <- function() { # structural definition of the source ---- + # nolint start sheets <- list( "Table1s1" = list( range = "A7:H26", @@ -437,6 +436,7 @@ readUNFCCC <- function() { ) ) ) + # nolint end # parse directories ---- @@ -467,7 +467,7 @@ readUNFCCC <- function() { if (!is.null(sheets[[i]][["extraVariables"]])) { extra <- suppressMessages( read_xlsx(path = file.path("2023", dir, file), sheet = i) %>% - select(seq(1:4)) + select(seq(1:4)) ) colnames(extra) <- c("variable", sheets[[i]][["colnames"]]) extra <- extra %>% @@ -484,10 +484,10 @@ readUNFCCC <- function() { select(-1) %>% select(-which(is.na(sheets[[i]][["colnames"]]))) %>% filter(!is.na(!!sym("name"))) %>% - melt(id.vars = c("name", "region", "year")) %>% + reshape2::melt(id.vars = c("name", "region", "year")) %>% mutate( - !!sym("value") := as.double(!!sym("value")), - !!sym("name") := paste0(sub("\\.", "_", i), "|", !!sym("name"), "|", sub(".+ ", "", !!sym("variable"))) + "value" = suppressWarnings(as.double(!!sym("value"))), + "name" = paste0(sub("\\.", "_", i), "|", !!sym("name"), "|", sub(".+ ", "", !!sym("variable"))) ) %>% select(-"name", "unit" = "variable", "variable" = "name") %>% filter(!is.na(!!sym("value"))) diff --git a/R/readUNFCCC_NDC.R b/R/readUNFCCC_NDC.R index e16d27a0..ab6b8ec3 100644 --- a/R/readUNFCCC_NDC.R +++ b/R/readUNFCCC_NDC.R @@ -17,9 +17,11 @@ readUNFCCC_NDC <- function(subtype) { NDCfile <- "NDC_2021.xlsx" } else if (grepl("2022", subtype, fixed = TRUE)) { NDCfile <- "NDC_2022-12-31.xlsx" - } else { + } else if (grepl("2023", subtype, fixed = TRUE)) { NDCfile <- "NDC_2023-11-29.xlsx" - if (!grepl("2023", subtype, fixed = TRUE)) { + } else { + NDCfile <- "NDC_2024-08-31.xlsx" + if (!grepl("2024", subtype, fixed = TRUE)) { warning("\nNo data for year in ", subtype, " available. Choose default: ", NDCfile) } } diff --git a/R/readUSGS.R b/R/readUSGS.R index 4abfd726..de3931c8 100644 --- a/R/readUSGS.R +++ b/R/readUSGS.R @@ -12,7 +12,6 @@ #' @author Michaja Pehl #' #' @importFrom assertr assert -#' @importFrom countrycode countrycode #' @importFrom dplyr bind_rows mutate pull rename select distinct #' @importFrom readr read_csv #' @importFrom readxl read_excel diff --git a/R/readWGBU.R b/R/readWGBU.R index bdc1cd8e..8d59da0a 100644 --- a/R/readWGBU.R +++ b/R/readWGBU.R @@ -1,28 +1,27 @@ #' Read WGBU -#' +#' #' Read-in an WGBU xlsx file as magclass object -#' -#' +#' +#' #' @return magpie object of WGBU #' @author Lavinia Baumstark #' @seealso \code{\link{readSource}} #' @examples -#' -#' \dontrun{ a <- readSource(type="WGBU") +#' \dontrun{ +#' a <- readSource(type = "WGBU") #' } -#' +#' readWGBU <- function() { - # read in data - x <- as.data.frame(read_excel("Global Technical Potential of Hydro Power_WGBU_adjusted.xlsx", sheet=1)) - x <- x[!is.na(x[[1]]),] - # delete last not meaningfull dimension - x <- x[-73,] + x <- as.data.frame(read_excel("Global Technical Potential of Hydro Power_WGBU_adjusted.xlsx", sheet = 1)) + x <- x[!is.na(x[[1]]), ] + # delete last not meaningful dimension + x <- x[-73, ] # substitute . in region names - x$Land <- gsub("\\.",",",x$Land) + x$Land <- gsub("\\.", ",", x$Land) # turn into a magclass object - x <- as.magpie(x, spatial=1) + x <- as.magpie(x, spatial = 1) # clean up the names - getNames(x) <- gsub("\\."," ",getNames(x)) + getNames(x) <- gsub("\\.", " ", getNames(x)) return(x) } diff --git a/R/readnonEnergyDemand.R b/R/readnonEnergyDemand.R index 7ead00c5..90164fe8 100644 --- a/R/readnonEnergyDemand.R +++ b/R/readnonEnergyDemand.R @@ -1,20 +1,18 @@ - #' Read Final energy demand for feedstocks (non-energy use) -#' +#' #' @return magpie object of region dependent data #' @author Renato Rodrigues -#' +#' #' @seealso \code{\link{readSource}} -#' +#' #' @examples -#' -#' \dontrun{ a <- readSource(type="nonEnergyDemand") +#' \dontrun{ +#' a <- readSource(type = "nonEnergyDemand") #' } -#' +#' readnonEnergyDemand <- function() { - x <- read.csv("Final_Energy_demand_for_non_energy_use_in_industry.csv") - x <- as.magpie(x,spatial=2,temporal=1) - + x <- as.magpie(x, spatial = 2, temporal = 1) + return(x) } diff --git a/R/readvanRuijven2016.R b/R/readvanRuijven2016.R index 78103586..65c20145 100644 --- a/R/readvanRuijven2016.R +++ b/R/readvanRuijven2016.R @@ -1,58 +1,57 @@ #' Read van Ruijven et al. (2016) data. -#' +#' #' Read data from van Ruijven et al. 2016, #' (http://dx.doi.org/10.1016/j.resconrec.2016.04.016, -#' https://www.zotero.org/groups/52011/rd3/items/itemKey/6QMNBEHQ), obtained -#' through personal communication (e-mail to Michaja Pehl). Units are tonnes +#' https://www.zotero.org/groups/52011/rd3/items/itemKey/6QMNBEHQ), obtained +#' through personal communication (e-mail to Michaja Pehl). Units are tonnes #' per year. #' #' @md #' @return A [`magpie`][magclass::magclass] object. -#' +#' #' @author Michaja Pehl -#' +#' #' @importFrom dplyr filter mutate select -#' @importFrom magrittr %>% #' @importFrom quitte add_countrycode_ madrat_mule #' @importFrom readxl read_excel #' @importFrom tidyr expand_grid pivot_longer -#' +#' #' @seealso [`readSource()`] #' @export readvanRuijven2016 <- function() { - USSR_iso3c <- c('ARM', 'AZE', 'BLR', 'EST', 'GEO', 'KAZ', 'KGZ', 'LTU', - 'LVA', 'MDA', 'RUS', 'TJK', 'TKM', 'UKR', 'UZB') - + USSR_iso3c <- c('ARM', 'AZE', 'BLR', 'EST', 'GEO', 'KAZ', 'KGZ', 'LTU', + 'LVA', 'MDA', 'RUS', 'TJK', 'TKM', 'UKR', 'UZB') + x <- read_excel( path = './Cement_data_from_Bas.xlsx', # path = '~/PIK/swap/inputdata/sources/vanRuijven2016/Cement_data_from_Bas.xlsx', sheet = 'Production', - range = 'A4:AS321') %>% - filter(999 != .data$`Region #`) %>% - pivot_longer(cols = matches('^[0-9]{4}$'), names_to = 'year', - names_transform = list(year = as.integer), - values_drop_na = TRUE) %>% - add_countrycode_(origin = c('FAO #' = 'fao'), destination = 'iso3c', - warn = FALSE) %>% - add_countrycode_(origin = c('FAO Name' = 'country.name'), + range = 'A4:AS321') %>% + filter(999 != .data$`Region #`) %>% + pivot_longer(cols = matches('^[0-9]{4}$'), names_to = 'year', + names_transform = list(year = as.integer), + values_drop_na = TRUE) %>% + add_countrycode_(origin = c('FAO #' = 'fao'), destination = 'iso3c', + warn = FALSE) %>% + add_countrycode_(origin = c('FAO Name' = 'country.name'), destination = c('iso3c.alt' = 'iso3c'), warn = FALSE) - + # remove Soviet Republics if USSR is available, to avoid double counting - x %>% + x %>% anti_join( expand_grid(iso3c = USSR_iso3c, - year = x %>% - filter('USSR' == .data$`FAO Name`) %>% - pull('year') %>% + year = x %>% + filter('USSR' == .data$`FAO Name`) %>% + pull('year') %>% unique()), - + c('iso3c', 'year') - ) %>% + ) %>% mutate(iso3c = ifelse(!is.na(.data$iso3c), .data$iso3c, .data$iso3c.alt), # kg * 0.001 t/kg = t - value = .data$value * 1e-3) %>% - filter(!is.na(.data$iso3c)) %>% - select('iso3c', 'year', 'value') %>% + value = .data$value * 1e-3) %>% + filter(!is.na(.data$iso3c)) %>% + select('iso3c', 'year', 'value') %>% madrat_mule() } diff --git a/R/readworldsteel.R b/R/readworldsteel.R index 7d9f62df..f6680134 100644 --- a/R/readworldsteel.R +++ b/R/readworldsteel.R @@ -21,10 +21,7 @@ #' #' @importFrom dplyr bind_rows filter group_by inner_join left_join mutate #' select summarise -#' @importFrom madrat toolISOhistorical -#' @importFrom magclass as.data.frame as.magpie #' @importFrom quitte add_countrycode_ madrat_mule -#' @importFrom readODS read_ods #' @importFrom readr read_delim read_rds #' @importFrom rlang is_empty #' @importFrom tibble as_tibble tribble @@ -41,8 +38,40 @@ readworldsteel <- function(subtype = 'detailed') { # to facilitate debugging file_path <- './Steel_Statistical_Yearbook_combined.ods' + base_path <- file.path('./source/statistical_yearbook_2023_data/') - d <- lapply( + .country_to_iso3c <- function(data) + { + data %>% + add_countrycode_(origin = c(country = 'country.name'), + destination = 'iso3c', warn = FALSE) %>% + # add fake iso3c codes for former countries and aggregates + left_join( + tribble( + ~country, ~iso3c.alt, + 'Belgium-Luxembourg', 'blx', + 'Belgium-Luxemburg', 'blx', + 'Czechoslovakia', 'CSK', + 'Serbia and Montenegro', 'SCG', + 'Serbia-Montenegro', 'SCG', + 'Yugoslavia', 'YUG', + 'F.R. Yugoslavia', 'YUG', + 'Former Yugoslavia', 'YUG'), + + 'country' + ) %>% + mutate(iso3c = ifelse(!is.na(.data$iso3c), .data$iso3c, + .data$iso3c.alt)) %>% + select('iso3c', 'year', 'name', 'value') %>% + assert(not_na, 'iso3c') %>% + # combine country aggregates + group_by(.data$iso3c, .data$year, .data$name) %>% + summarise(value = sum(.data$value, na.rm = TRUE), + .groups = 'drop') %>% + filter(0 != .data$value) + } + + d_old <- lapply( # read these worksheets c('Pig Iron Production', 'DRI Production', @@ -53,7 +82,7 @@ readworldsteel <- function(subtype = 'detailed') { 'Apparent Steel Use (Crude Steel Equivalent)'), function(sheet) { # from this file - read_ods(path = file_path, sheet = sheet, na = '...') %>% + readODS::read_ods(path = file_path, sheet = sheet, na = '...') %>% as_tibble() %>% mutate(name = sheet) %>% pivot_longer(c(-'country', -'name'), names_to = 'year', @@ -61,27 +90,43 @@ readworldsteel <- function(subtype = 'detailed') { as.integer(sub('^X', '', x)) })) }) %>% bind_rows() %>% - add_countrycode_(origin = c(country = 'country.name'), - destination = 'iso3c', warn = FALSE) %>% - # add fake iso3c codes for former countries and aggregates - left_join( - tribble( - ~country, ~iso3c.alt, - 'Belgium-Luxembourg', 'blx', - 'Czechoslovakia', 'CSK', - 'Serbia and Montenegro', 'SCG', - 'Yugoslavia', 'YUG', - 'F.R. Yugoslavia', 'YUG'), - - 'country' - ) %>% - mutate( - iso3c = ifelse(!is.na(.data$iso3c), .data$iso3c, .data$iso3c.alt)) %>% - select('iso3c', 'year', 'name', 'value') %>% - # combine country aggregates - group_by(.data$iso3c, .data$year, .data$name) %>% - summarise(value = sum(.data$value, na.rm = TRUE), .groups = 'drop') %>% - filter(0 != .data$value) + .country_to_iso3c() + + layout <- tribble( + ~name, ~file, ~range, + 'Pig Iron Production', 'P26_Production_of_pig_iron.xlsx', 'A3:U54', + 'DRI Production', 'P27_Production_of_direct_reduced_iron.xlsx', 'A3:U35', + 'Total Production of Crude Steel', 'P01_Total_production_of_crude_steel.xlsx', 'A3:U101', + 'Production in Oxygen-Blown Converters', 'P05_Production_of_crude_steel_in_oxygen_blown_converters.xlsx', 'A3:U54', + 'Production in Open Hearth Furnaces', 'P07_Production_of_crude_steel_in_other_processes.xlsx', 'A3:U82', + 'Production in Electric Arc Furnaces', 'P06_Production_of_crude_steel_in_electric_furnaces.xlsx', 'A3:U100', + 'Apparent Steel Use (Crude Steel Equivalent)', 'U01_Apparent_steel_use_(crude_steel_equivalent).xlsx', 'A3:U125') + + d_new <- lapply(seq_len(nrow(layout)), + function(i) { + readxl::read_excel(path = file.path(base_path, layout[[i,'file']]), + range = layout[[i,'range']]) %>% + rename(country = 'Country') %>% + filter(!.data$country %in% c('World', 'Others')) %>% + pivot_longer(-'country', names_to = 'year', + names_transform = as.integer) %>% + mutate(name = layout[[i,'name']]) + }) %>% + bind_rows() %>% + .country_to_iso3c() + + d_new_incomplete_years <- d_new %>% + group_by(.data$year) %>% + distinct(.data$name) %>% + summarise(count = n()) %>% + filter(max(.data$count) != .data$count) %>% + pull('year') + + d_new <- d_new %>% + filter(!.data$year %in% d_new_incomplete_years) + + d <- overwrite(d_new, d_old) + # split historic aggregates into current countries d %>% diff --git a/R/toolBiomassSupplyAggregate.R b/R/toolBiomassSupplyAggregate.R index ca8d3e31..07bbc9f1 100644 --- a/R/toolBiomassSupplyAggregate.R +++ b/R/toolBiomassSupplyAggregate.R @@ -10,8 +10,7 @@ #' @param weight aggregation weight #' @author Felix Schreyer #' @export -#' @importFrom magclass as.magpie dimReduce -#' @importFrom dplyr %>% mutate select rename left_join +#' @importFrom dplyr mutate select rename left_join #' @importFrom quitte as.quitte toolBiomassSupplyAggregate <- function(x, rel=NULL, weight = calcOutput("FAOLand", aggregate = F)[,,"6610",pmatch=TRUE][,"y2010",]){ diff --git a/R/toolCubicFunctionAggregate.R b/R/toolCubicFunctionAggregate.R index b6ee970e..a74bd037 100644 --- a/R/toolCubicFunctionAggregate.R +++ b/R/toolCubicFunctionAggregate.R @@ -50,45 +50,54 @@ #' #' @author Renato Rodrigues #' @export -#' @importFrom magclass is.magpie as.data.frame -#' @importFrom reshape2 acast -#' @importFrom stats reshape uniroot #' @seealso \code{\link{toolCubicFunctionDisaggregate}} #' @examples #' #' # Example #' # data -#' EUR <- setNames(data.frame(30,50,0.123432,2),c("c1","c2","c3","c4")) -#' NEU <- setNames(data.frame(30,50,1.650330,2),c("c1","c2","c3","c4")) -#' df <- rbind(EUR,NEU) -#' row.names(df) <- c("EUR","NEU") +#' EUR <- setNames(data.frame(30, 50, 0.123432, 2), c("c1", "c2", "c3", "c4")) +#' NEU <- setNames(data.frame(30, 50, 1.650330, 2), c("c1", "c2", "c3", "c4")) +#' df <- rbind(EUR, NEU) +#' row.names(df) <- c("EUR", "NEU") #' # maxExtraction (upper limit for function estimation) #' maxExtraction <- 23 #' # output -#' output <- toolCubicFunctionAggregate(df,xUpperBound=maxExtraction, -#' returnMagpie=FALSE,returnChart=TRUE,returnSample=TRUE, -#' label=list(x="Cumulated Extraction", y="Cost", legend="Region Fuel Functions")) +#' output <- toolCubicFunctionAggregate(df, +#' xUpperBound = maxExtraction, +#' returnMagpie = FALSE, returnChart = TRUE, returnSample = TRUE, +#' label = list(x = "Cumulated Extraction", y = "Cost", legend = "Region Fuel Functions") +#' ) #' output$coeff #' output$chart - - -toolCubicFunctionAggregate <- function(x, rel=NULL, xLowerBound=0, xUpperBound=100, returnMagpie=TRUE, returnCoeff=TRUE, returnChart=FALSE, returnSample=FALSE, numberOfSamples=1e3, unirootLowerBound = -10,unirootUpperBound = 1e100, colourPallete=FALSE, label = list(x = "x", y = "y", legend = "legend"), steepCurve = list()){ - +toolCubicFunctionAggregate <- function(x, + rel = NULL, + xLowerBound = 0, + xUpperBound = 100, + returnMagpie = TRUE, + returnCoeff = TRUE, + returnChart = FALSE, + returnSample = FALSE, + numberOfSamples = 1e3, + unirootLowerBound = -10, + unirootUpperBound = 1e100, + colourPallete = FALSE, + label = list(x = "x", y = "y", legend = "legend"), + steepCurve = list()) { data <- x - if(is.null(rel$RegionCode)) rel$RegionCode <- rel$region - if(is.null(rel$CountryCode)) rel$CountryCode <- rel$country + if (is.null(rel$RegionCode)) rel$RegionCode <- rel$region + if (is.null(rel$CountryCode)) rel$CountryCode <- rel$country - if (!(length(steepCurve) == 0)){ #set steep curve if all countries within a region have zero upper bound - for (region in unique(rel$RegionCode)){ - countries <- rel$CountryCode[rel$RegionCode== as.character(region)] - if (all(xUpperBound[countries,,] == 0)){ # if all countries within the region do not have any extraction potential + if (!(length(steepCurve) == 0)) { # set steep curve if all countries within a region have zero upper bound + for (region in unique(rel$RegionCode)) { + countries <- rel$CountryCode[rel$RegionCode == as.character(region)] + if (all(xUpperBound[countries, , ] == 0)) { # if all countries within the region do not have any extraction potential # set a very high cost curve count <- 0 for (coeff in names(steepCurve)) { - data[countries,,coeff] = steepCurve[[coeff]]*(length(countries)^count) - count <- count+1 + data[countries, , coeff] <- steepCurve[[coeff]] * (length(countries)^count) + count <- count + 1 } } } @@ -99,51 +108,50 @@ toolCubicFunctionAggregate <- function(x, rel=NULL, xLowerBound=0, xUpperBound=1 # function used to fit by sampling the sum of function inverses (sum in the x-axis) # input: data <- data table with coefficients of the functions to be aggregated. Format: one column for each coefficient - cubicFitAggregate <- function(data, xLowerBound=0, xUpperBound=100, returnCoeff=TRUE, returnChart=FALSE, returnSample=FALSE, numberOfSamples=1e3, unirootLowerBound = -10,unirootUpperBound = 1e100, colourPallete=FALSE, label = list(x = "x", y = "y", legend = "legend")){ - - if (nrow(data) == 1 || is.null(nrow(data))){ # no need to aggregate a single function + cubicFitAggregate <- function(data, xLowerBound = 0, xUpperBound = 100, returnCoeff = TRUE, returnChart = FALSE, returnSample = FALSE, numberOfSamples = 1e3, unirootLowerBound = -10, unirootUpperBound = 1e100, colourPallete = FALSE, label = list(x = "x", y = "y", legend = "legend")) { + if (nrow(data) == 1 || is.null(nrow(data))) { # no need to aggregate a single function # preparing results result <- list() - if (returnChart == TRUE){ - thirdDegreeFunction <- function(x) { - return( data[1] + data[2]*x + data[3]*x^2 + data[4]*x^3 ) + if (returnChart == TRUE) { + thirdDegreeFunction <- function(x) { + return(data[1] + data[2] * x + data[3] * x^2 + data[4] * x^3) } p <- ggplot2::ggplot(data = NULL) p <- p + ggplot2::xlim(xLowerBound, xUpperBound) - p <- p + ggplot2::stat_function(fun = thirdDegreeFunction, size=1, ggplot2::aes(colour = "_aggregated function", linetype = "_aggregated function"), na.rm=TRUE) + p <- p + ggplot2::stat_function(fun = thirdDegreeFunction, size = 1, ggplot2::aes(colour = "_aggregated function", linetype = "_aggregated function"), na.rm = TRUE) p <- p + ggplot2::scale_linetype_manual(values = c("solid"), guide = FALSE) p <- p + ggplot2::labs(colour = label$legend, x = label$x, y = label$y) result$chart <- p # return chart } - if (returnCoeff == TRUE){ # return coeff of estimated function - if(length(result) == 0) { - result <- c(data[1],data[2],data[3],data[4]) + if (returnCoeff == TRUE) { # return coeff of estimated function + if (length(result) == 0) { + result <- c(data[1], data[2], data[3], data[4]) } else { - result$coeff <- c(data[1],data[2],data[3],data[4]) + result$coeff <- c(data[1], data[2], data[3], data[4]) } } return(result) } - #cubic function of each row to be aggregated (ex: fY[[rowName]](20)) - fY <- apply(data, 1, function(coef){ function(x){ as.numeric(coef[1]) + as.numeric(coef[2])*x + as.numeric(coef[3])*x^2 + as.numeric(coef[4])*x^3 } }) + # cubic function of each row to be aggregated (ex: fY[[rowName]](20)) + fY <- apply(data, 1, function(coef) { + function(x) { + as.numeric(coef[1]) + as.numeric(coef[2]) * x + as.numeric(coef[3]) * x^2 + as.numeric(coef[4]) * x^3 + } + }) - #inverse function - inverse = function (f, lower = unirootLowerBound, upper = unirootUpperBound) { - function (y) { - result <- stats::uniroot((function (x) f(x) - y), lower = lower, upper = upper, extendInt = "yes")$root - #tryCatch( - # result <- uniroot((function (x) f(x) - y), lower = lower, upper = upper, extendInt = "yes",maxiter = 10000, trace =2)$root, - # error = return(NA) - #) + # inverse function + inverse <- function(f, lower = unirootLowerBound, upper = unirootUpperBound) { + function(y) { + result <- stats::uniroot((function(x) f(x) - y), lower = lower, upper = upper, extendInt = "yes")$root return(result) } } - fYInverse <- lapply(rownames(data), function(rowName){ - function(x, lower = unirootLowerBound, upper = unirootUpperBound){ - lis<-vector() - for(i in x){ - lis<-append(lis,inverse(fY[[rowName]],lower,upper)(i)) + fYInverse <- lapply(rownames(data), function(rowName) { + function(x, lower = unirootLowerBound, upper = unirootUpperBound) { + lis <- vector() + for (i in x) { + lis <- append(lis, inverse(fY[[rowName]], lower, upper)(i)) } return(lis) } @@ -153,62 +161,64 @@ toolCubicFunctionAggregate <- function(x, rel=NULL, xLowerBound=0, xUpperBound=1 # Boundaries for which all functions should be defined maxXtolerance <- 1e-10 minX <- xLowerBound - if (length(xUpperBound) > 1){ # one bound for each row + if (length(xUpperBound) > 1) { # one bound for each row maxX <- sum(xUpperBound) - if (maxX < maxXtolerance){ # all rows have corner solution values for bounds + if (maxX < maxXtolerance) { # all rows have corner solution values for bounds maxX <- 1 - maxY <- max(sapply(rownames(data),function(rowName) fY[[as.character(rowName)]](maxX) ) ) + maxY <- max(sapply(rownames(data), function(rowName) fY[[as.character(rowName)]](maxX))) } else { # consider only rows with non corner solutions - maxY <- max(sapply(rownames(data),function(rowName) ifelse(xUpperBound[rowName] > maxXtolerance, fY[[as.character(rowName)]](xUpperBound[rowName]),0) )) + maxY <- max(sapply(rownames(data), function(rowName) ifelse(xUpperBound[rowName] > maxXtolerance, fY[[as.character(rowName)]](xUpperBound[rowName]), 0))) } - minY <- max(sapply(rownames(data),function(rowName) fY[[as.character(rowName)]](xLowerBound))) + minY <- max(sapply(rownames(data), function(rowName) fY[[as.character(rowName)]](xLowerBound))) } else { # single bound for all rows maxX <- xUpperBound - if (maxX < maxXtolerance){ # all rows have corner solution values for bounds + if (maxX < maxXtolerance) { # all rows have corner solution values for bounds maxX <- 1 - maxY <- max(sapply(rownames(data),function(rowName) fY[[as.character(rowName)]](maxX) ) ) + maxY <- max(sapply(rownames(data), function(rowName) fY[[as.character(rowName)]](maxX))) } else { # consider only rows with non corner solutions - maxY <- max(sapply(rownames(data),function(rowName) { ifelse(xUpperBound > maxXtolerance, fY[[as.character(rowName)]](xUpperBound),0) } )) + maxY <- max(sapply(rownames(data), function(rowName) { + ifelse(xUpperBound > maxXtolerance, fY[[as.character(rowName)]](xUpperBound), 0) + })) } - minY <- max(sapply(rownames(data),function(rowName) fY[[as.character(rowName)]](xLowerBound))) + minY <- max(sapply(rownames(data), function(rowName) fY[[as.character(rowName)]](xLowerBound))) } - minY <- max(c(0,minY)) + minY <- max(c(0, minY)) # Sampling # sampling y - samples <- data.frame(y = seq(from=minY, to=maxY, length.out = numberOfSamples)) + samples <- data.frame(y = seq(from = minY, to = maxY, length.out = numberOfSamples)) # sampling x per function - for (rowName in rownames(data)){ - samples[,(paste0(rowName,".x"))] <- fYInverse[[rowName]](samples$y,minX,maxX) + for (rowName in rownames(data)) { + samples[, (paste0(rowName, ".x"))] <- fYInverse[[rowName]](samples$y, minX, maxX) } # total x - samples$x <-rowSums(samples[grep("x", names(samples))]) - samples[samples<0] <- 0 #make sure all samples are greater or equal to zero + samples$x <- rowSums(samples[grep("x", names(samples))]) + samples[samples < 0] <- 0 # make sure all samples are greater or equal to zero # estimating the new function - #use nnls to force positive coefficients + # use nnls to force positive coefficients df <- data.frame(1, samples$x, samples$x^2, samples$x^3) df <- as.matrix(df) - newFunction <- nnls::nnls(df,samples$y) + newFunction <- nnls::nnls(df, samples$y) newFunctionCoeff <- newFunction$x # preparing results result <- list() - if (returnSample == TRUE){ + if (returnSample == TRUE) { result$sample <- samples # return samples table } - if (returnChart == TRUE){ - thirdDegreeFunction <- function(x) { - return( newFunctionCoeff[1] + newFunctionCoeff[2]*x + newFunctionCoeff[3]*x^2 + newFunctionCoeff[4]*x^3 ) + if (returnChart == TRUE) { + thirdDegreeFunction <- function(x) { + return(newFunctionCoeff[1] + newFunctionCoeff[2] * x + newFunctionCoeff[3] * x^2 + newFunctionCoeff[4] * x^3) } p <- ggplot2::ggplot(samples, ggplot2::aes(samples$x, samples$y, group = 1)) + ggplot2::coord_cartesian(ylim = c(0, max(samples$y))) - p <- p + ggplot2::stat_function(fun=thirdDegreeFunction, size=1, ggplot2::aes(colour = "_aggregated function", linetype = "_aggregated function"), na.rm=TRUE) - for (i in 1:(nrow(data))){ - p <- p + eval(parse(text = paste0("ggplot2::stat_function(fun=fY[[\"", as.character(rownames(data)[i]) , "\"]], ggplot2::aes(colour = \"", as.character(rownames(data)[i]) , "\" , linetype = \"" , as.character(rownames(data)[i]), "\"), na.rm=TRUE)"))) #hack to allow legend + p <- p + ggplot2::stat_function(fun = thirdDegreeFunction, size = 1, ggplot2::aes(colour = "_aggregated function", linetype = "_aggregated function"), na.rm = TRUE) + for (i in 1:(nrow(data))) { + p <- p + eval(parse(text = paste0("ggplot2::stat_function(fun=fY[[\"", as.character(rownames(data)[i]), "\"]], ggplot2::aes(colour = \"", as.character(rownames(data)[i]), "\" , linetype = \"", as.character(rownames(data)[i]), "\"), na.rm=TRUE)"))) # hack to allow legend } - if ( !(colourPallete[1] == FALSE) & (length(colourPallete) >= nrow(data))){ + if (!(colourPallete[1] == FALSE) & (length(colourPallete) >= nrow(data))) { p <- p + ggplot2::scale_colour_manual(label$legend, values = colourPallete) } p <- p + ggplot2::scale_linetype_manual(values = c("solid", rep.int("dashed", nrow(data))), guide = FALSE) @@ -219,9 +229,9 @@ toolCubicFunctionAggregate <- function(x, rel=NULL, xLowerBound=0, xUpperBound=1 result$chart <- p # return chart } - if (returnCoeff == TRUE){ # return coeff of estimated function + if (returnCoeff == TRUE) { # return coeff of estimated function names(newFunctionCoeff) <- colnames(data) - if(length(result) == 0) { + if (length(result) == 0) { result <- newFunctionCoeff } else { result$coeff <- newFunctionCoeff @@ -234,53 +244,55 @@ toolCubicFunctionAggregate <- function(x, rel=NULL, xLowerBound=0, xUpperBound=1 # pre processing data formats and executing estimations - if(is.magpie(data)){ + if (is.magpie(data)) { df <- as.data.frame(data) # splitting large dimensional magpie objects - dataNames <- names(df[,grep("Data", names(df))]) # all data names + dataNames <- names(df[, grep("Data", names(df))]) # all data names dataNames <- dataNames[-length(dataNames)] # remove last element (coefficient labels) - factorGroups <- interaction(df[,dataNames]) # all combinations of Data values + factorGroups <- interaction(df[, dataNames]) # all combinations of Data values groupsList <- split(df, with(df, factorGroups), drop = TRUE) - #looping through all data sets and estimating the respective aggregated functions - output <- lapply(seq_along(groupsList), - function(i) { - # preparing data (row names equal to regions, one column for each coefficient) - currentDf <- groupsList[[i]] - currentDf <- currentDf[c(2,length(currentDf)-1,length(currentDf))] #region, coeff, value - names(currentDf) <- c("Region","coeff","value") - currentDf <- reshape2::acast(currentDf, Region ~ coeff, value.var = 'value') - # estimating aggregated function - if (is.null(rel)){ # single aggregated function - out <- cubicFitAggregate(currentDf, xLowerBound=xLowerBound, xUpperBound=xUpperBound, returnCoeff=returnCoeff, returnChart=returnChart, returnSample=returnSample, numberOfSamples=numberOfSamples, unirootLowerBound =unirootLowerBound,unirootUpperBound =unirootUpperBound, colourPallete=colourPallete, label = label) - } else { # looping through new regions and estimating the aggregated function - if (returnMagpie==TRUE){ - returnCoeff=TRUE - returnChart=FALSE - returnSample=FALSE - } - from <- ifelse(dim(rel)[2]>2,2,1) # country - to <- ifelse(dim(rel)[2]>2,3,2) # region - out <- sapply(unique(rel[[to]]), function(region) { - currentFilteredDf <- currentDf[rel[from][rel[to]==as.character(region)],] - # upper bound - currentxUpperBound <- as.numeric(xUpperBound[rel[from][rel[to]==as.character(region)],,names(groupsList[i])]) - names(currentxUpperBound) <- getRegions(xUpperBound[rel[from][rel[to]==as.character(region)],,names(groupsList[i])]) - outRegion <- cubicFitAggregate(currentFilteredDf, xLowerBound=xLowerBound, xUpperBound=currentxUpperBound, returnCoeff=returnCoeff, returnChart=returnChart, returnSample=returnSample, numberOfSamples=numberOfSamples, unirootLowerBound =unirootLowerBound,unirootUpperBound =unirootUpperBound, colourPallete=colourPallete, label = label) - return(outRegion) - }) - if (returnMagpie==TRUE){ - colnames(out) <- unique(rel[[to]]) - rownames(out) <- colnames(currentDf) - out <- as.magpie(out) - } else { - names(out) <- unique(rel[[to]]) - } - } - return(out) - }) + # looping through all data sets and estimating the respective aggregated functions + output <- lapply( + seq_along(groupsList), + function(i) { + # preparing data (row names equal to regions, one column for each coefficient) + currentDf <- groupsList[[i]] + currentDf <- currentDf[c(2, length(currentDf) - 1, length(currentDf))] # region, coeff, value + names(currentDf) <- c("Region", "coeff", "value") + currentDf <- reshape2::acast(currentDf, Region ~ coeff, value.var = "value") + # estimating aggregated function + if (is.null(rel)) { # single aggregated function + out <- cubicFitAggregate(currentDf, xLowerBound = xLowerBound, xUpperBound = xUpperBound, returnCoeff = returnCoeff, returnChart = returnChart, returnSample = returnSample, numberOfSamples = numberOfSamples, unirootLowerBound = unirootLowerBound, unirootUpperBound = unirootUpperBound, colourPallete = colourPallete, label = label) + } else { # looping through new regions and estimating the aggregated function + if (returnMagpie == TRUE) { + returnCoeff <- TRUE + returnChart <- FALSE + returnSample <- FALSE + } + from <- ifelse(dim(rel)[2] > 2, 2, 1) # country + to <- ifelse(dim(rel)[2] > 2, 3, 2) # region + out <- sapply(unique(rel[[to]]), function(region) { + currentFilteredDf <- currentDf[rel[from][rel[to] == as.character(region)], ] + # upper bound + currentxUpperBound <- as.numeric(xUpperBound[rel[from][rel[to] == as.character(region)], , names(groupsList[i])]) + names(currentxUpperBound) <- getRegions(xUpperBound[rel[from][rel[to] == as.character(region)], , names(groupsList[i])]) + outRegion <- cubicFitAggregate(currentFilteredDf, xLowerBound = xLowerBound, xUpperBound = currentxUpperBound, returnCoeff = returnCoeff, returnChart = returnChart, returnSample = returnSample, numberOfSamples = numberOfSamples, unirootLowerBound = unirootLowerBound, unirootUpperBound = unirootUpperBound, colourPallete = colourPallete, label = label) + return(outRegion) + }) + if (returnMagpie == TRUE) { + colnames(out) <- unique(rel[[to]]) + rownames(out) <- colnames(currentDf) + out <- as.magpie(out) + } else { + names(out) <- unique(rel[[to]]) + } + } + return(out) + } + ) names(output) <- names(groupsList) - #from lists to dimension in the magpie names + # from lists to dimension in the magpie names outputList <- output output <- lapply(seq_along(outputList), function(i) { out <- add_dimension(outputList[[i]], dim = 3.1, nm = names(outputList)[i]) @@ -288,25 +300,24 @@ toolCubicFunctionAggregate <- function(x, rel=NULL, xLowerBound=0, xUpperBound=1 names(output) <- names(outputList) # merge all magpie objects into a single one output <- mbind(output) - } else { - if (is.null(rel)){ # single aggregated function - output <- cubicFitAggregate(data, xLowerBound=xLowerBound, xUpperBound=xUpperBound, returnCoeff=returnCoeff, returnChart=returnChart, returnSample=returnSample, numberOfSamples=numberOfSamples, unirootLowerBound =unirootLowerBound,unirootUpperBound =unirootUpperBound, colourPallete=colourPallete, label = label) + if (is.null(rel)) { # single aggregated function + output <- cubicFitAggregate(data, xLowerBound = xLowerBound, xUpperBound = xUpperBound, returnCoeff = returnCoeff, returnChart = returnChart, returnSample = returnSample, numberOfSamples = numberOfSamples, unirootLowerBound = unirootLowerBound, unirootUpperBound = unirootUpperBound, colourPallete = colourPallete, label = label) } else { # looping through new regions and estimating the aggregated function - if (returnMagpie==TRUE){ - returnCoeff=TRUE - returnChart=FALSE - returnSample=FALSE + if (returnMagpie == TRUE) { + returnCoeff <- TRUE + returnChart <- FALSE + returnSample <- FALSE } - from <- ifelse(dim(rel)[2]>2,2,1) # country - to <- ifelse(dim(rel)[2]>2,3,2) # region + from <- ifelse(dim(rel)[2] > 2, 2, 1) # country + to <- ifelse(dim(rel)[2] > 2, 3, 2) # region output <- sapply(unique(rel[[to]]), function(region) { - currentFilteredDf <- data[rel[from][rel[to]==as.character(region)],] - currentxUpperBound <- as.numeric(xUpperBound[rel[from][rel[to]==as.character(region)],,]) - outRegion <- cubicFitAggregate(currentFilteredDf, xLowerBound=xLowerBound, xUpperBound=currentxUpperBound, returnCoeff=returnCoeff, returnChart=returnChart, returnSample=returnSample, numberOfSamples=numberOfSamples, unirootLowerBound =unirootLowerBound,unirootUpperBound =unirootUpperBound, colourPallete=colourPallete, label = label) + currentFilteredDf <- data[rel[from][rel[to] == as.character(region)], ] + currentxUpperBound <- as.numeric(xUpperBound[rel[from][rel[to] == as.character(region)], , ]) + outRegion <- cubicFitAggregate(currentFilteredDf, xLowerBound = xLowerBound, xUpperBound = currentxUpperBound, returnCoeff = returnCoeff, returnChart = returnChart, returnSample = returnSample, numberOfSamples = numberOfSamples, unirootLowerBound = unirootLowerBound, unirootUpperBound = unirootUpperBound, colourPallete = colourPallete, label = label) return(outRegion) }) - if (returnMagpie==TRUE){ + if (returnMagpie == TRUE) { colnames(output) <- unique(rel[[to]]) rownames(output) <- colnames(data) output <- as.magpie(output) diff --git a/R/toolCubicFunctionDisaggregate.R b/R/toolCubicFunctionDisaggregate.R index f6e8c6f1..eed77156 100644 --- a/R/toolCubicFunctionDisaggregate.R +++ b/R/toolCubicFunctionDisaggregate.R @@ -53,225 +53,238 @@ #' #' @author Renato Rodrigues #' @export -#' @importFrom magclass is.magpie as.data.frame -#' @importFrom reshape2 acast -#' @importFrom stats reshape uniroot #' @seealso \code{\link{toolCubicFunctionAggregate}} #' @examples #' #' # Example #' # LAM coefficients -#' df <- setNames(data.frame(30,50,0.34369,2),c("c1","c2","c3","c4")) +#' df <- setNames(data.frame(30, 50, 0.34369, 2), c("c1", "c2", "c3", "c4")) #' row.names(df) <- "LAM" #' # weight -#' weight <- setNames(c(21,0,579,3,228),c("ARG","BOL","BRA","CHL","COL")) +#' weight <- setNames(c(21, 0, 579, 3, 228), c("ARG", "BOL", "BRA", "CHL", "COL")) #' # maxExtraction (upper limit for function estimation) #' maxExtraction <- 100 #' # output -#' output <- toolCubicFunctionDisaggregate(df, weight,xUpperBound=maxExtraction, -#' returnMagpie=FALSE,returnChart=TRUE,returnSample=TRUE, -#' label=list(x="Cumulated Extraction", y="Cost", legend="Region Fuel Functions"))#' output$chart +#' output <- toolCubicFunctionDisaggregate(df, weight, +#' xUpperBound = maxExtraction, +#' returnMagpie = FALSE, returnChart = TRUE, returnSample = TRUE, +#' label = list(x = "Cumulated Extraction", y = "Cost", legend = "Region Fuel Functions") +#' ) #' output$chart #' output$coeff #' output$chart - - -toolCubicFunctionDisaggregate <- function(x, weight, rel=NULL, xLowerBound=0, xUpperBound=100, returnMagpie=TRUE, returnCoeff=TRUE, returnChart=FALSE, returnSample=FALSE, numberOfSamples=1e3, unirootLowerBound = -10,unirootUpperBound = 1e100, colourPallete=FALSE, label = list(x = "x", y = "y", legend = "legend")){ - +toolCubicFunctionDisaggregate <- function(x, + weight, + rel = NULL, + xLowerBound = 0, + xUpperBound = 100, + returnMagpie = TRUE, + returnCoeff = TRUE, + returnChart = FALSE, + returnSample = FALSE, + numberOfSamples = 1e3, + unirootLowerBound = -10, + unirootUpperBound = 1e100, + colourPallete = FALSE, + label = list(x = "x", y = "y", legend = "legend")) { data <- x ### Start of cubicFitDisaggregate function - cubicFitDisaggregate <- function(data, weight, xLowerBound=0, xUpperBound=100, returnCoeff=TRUE, returnChart=FALSE, returnSample=FALSE, numberOfSamples=1e3, unirootLowerBound = -10,unirootUpperBound = 1e100, colourPallete=FALSE, label = list(x = "x", y = "y", legend = "legend")){ + cubicFitDisaggregate <- function(data, weight, xLowerBound = 0, xUpperBound = 100, returnCoeff = TRUE, returnChart = FALSE, returnSample = FALSE, numberOfSamples = 1e3, unirootLowerBound = -10, unirootUpperBound = 1e100, colourPallete = FALSE, label = list(x = "x", y = "y", legend = "legend")) { + # initialize coefficients list + coeffList <- lapply(names(weight), function(x) { + row <- rep(0, length(names(data))) + names(row) <- names(data) + return(row) + }) + names(coeffList) <- names(weight) - # initialize coefficients list - coeffList <- lapply(names(weight),function(x){ - row <- rep(0, length(names(data))) - names(row) <- names(data) - return(row) - } - ) - names(coeffList) <- names(weight) - - if (length(weight[weight != 0]) == 1){ # no need to disaggregate a single function - # preparing results - result <- list() - singleWeight <- names(weight[weight != 0]) - coeffList[[singleWeight]][] <- data - if (returnChart == TRUE){ - thirdDegreeFunction <- function(x) { - return( as.numeric(coeffList[[singleWeight]][1]) + as.numeric(coeffList[[singleWeight]][2])*x + as.numeric(coeffList[[singleWeight]][3])*x^2 + as.numeric(coeffList[[singleWeight]][4])*x^3 ) - } - p <- ggplot2::ggplot(data = NULL) - p <- p + ggplot2::xlim(xLowerBound, xUpperBound) - p <- p + ggplot2::stat_function(fun = thirdDegreeFunction, size=1, ggplot2::aes(colour = "_aggregated function", linetype = "_aggregated function"), na.rm=TRUE) - p <- p + ggplot2::scale_linetype_manual(values = c("solid"), guide = FALSE) - p <- p + ggplot2::labs(colour = label$legend, x = label$x, y = label$y) - result$chart <- p # return chart + if (length(weight[weight != 0]) == 1) { # no need to disaggregate a single function + # preparing results + result <- list() + singleWeight <- names(weight[weight != 0]) + coeffList[[singleWeight]][] <- data + if (returnChart == TRUE) { + thirdDegreeFunction <- function(x) { + return(as.numeric(coeffList[[singleWeight]][1]) + as.numeric(coeffList[[singleWeight]][2]) * x + as.numeric(coeffList[[singleWeight]][3]) * x^2 + as.numeric(coeffList[[singleWeight]][4]) * x^3) } - if (returnCoeff == TRUE){ # return coeff of estimated function - if(length(result) == 0) { - result <- coeffList - } else { - result$coeff <- coeffList - } + p <- ggplot2::ggplot(data = NULL) + p <- p + ggplot2::xlim(xLowerBound, xUpperBound) + p <- p + ggplot2::stat_function(fun = thirdDegreeFunction, size = 1, ggplot2::aes(colour = "_aggregated function", linetype = "_aggregated function"), na.rm = TRUE) + p <- p + ggplot2::scale_linetype_manual(values = c("solid"), guide = FALSE) + p <- p + ggplot2::labs(colour = label$legend, x = label$x, y = label$y) + result$chart <- p # return chart + } + if (returnCoeff == TRUE) { # return coeff of estimated function + if (length(result) == 0) { + result <- coeffList + } else { + result$coeff <- coeffList } - return(result) } + return(result) + } - #function to be disaggregated - fTotal <- function(x){ as.numeric(data[1]) + as.numeric(data[2])*x + as.numeric(data[3])*x^2 + as.numeric(data[4])*x^3 } - - #Boundaries for which all functions are defined - #X (= sum X of each function) - maxX <- xUpperBound - minX <- xLowerBound - #Y - maxY <- fTotal(xUpperBound) - minY <- fTotal(xLowerBound) - minY <- max(c(0,minY)) # negative y do not make sense (avoid negative prices) - - # Sampling - # sampling x - samples <- data.frame(x = seq(from=minX, to=maxX, length.out = numberOfSamples)) - # sampling y - samples$y <- fTotal(samples$x) + # function to be disaggregated + fTotal <- function(x) { + as.numeric(data[1]) + as.numeric(data[2]) * x + as.numeric(data[3]) * x^2 + as.numeric(data[4]) * x^3 + } - # sampling y - totalWeight <- sum(weight) - for (rowName in names(weight)){ - samples[,(paste0(rowName,".x"))] <- samples$x*(weight[rowName]/totalWeight) - } - samples[samples<0] <- 0 #make sure all samples are greater or equal to zero + # Boundaries for which all functions are defined + # X (= sum X of each function) + maxX <- xUpperBound + minX <- xLowerBound + # Y + maxY <- fTotal(xUpperBound) + minY <- fTotal(xLowerBound) + minY <- max(c(0, minY)) # negative y do not make sense (avoid negative prices) - # estimating functions to each row from the new samples created from weights - for (rowName in names(weight)){ - #use nls to force positive coefficients - current <- data.frame(x = samples[paste0(rowName,".x")], y = samples[,"y"]) - names(current) <- c("x","y") - df <- data.frame(1, current$x, current$x^2, current$x^3) - df <- as.matrix(df) - newFunction <- nnls::nnls(df,current$y) - newFunctionCoeff <- newFunction$x - names(newFunctionCoeff) <- names(data) - coeffList[[rowName]][] <- newFunctionCoeff - } + # Sampling + # sampling x + samples <- data.frame(x = seq(from = minX, to = maxX, length.out = numberOfSamples)) + # sampling y + samples$y <- fTotal(samples$x) - # preparing results - result <- list() - if (returnSample == TRUE){ - result$sample <- samples # return samples table - } - if (returnChart == TRUE){ + # sampling y + totalWeight <- sum(weight) + for (rowName in names(weight)) { + samples[, (paste0(rowName, ".x"))] <- samples$x * (weight[rowName] / totalWeight) + } + samples[samples < 0] <- 0 # make sure all samples are greater or equal to zero - #estimated functions - fY <- lapply(coeffList, function(coef){ function(x){ as.numeric(coef[1]) + as.numeric(coef[2])*x + as.numeric(coef[3])*x^2 + as.numeric(coef[4])*x^3 } }) + # estimating functions to each row from the new samples created from weights + for (rowName in names(weight)) { + # use nls to force positive coefficients + current <- data.frame(x = samples[paste0(rowName, ".x")], y = samples[, "y"]) + names(current) <- c("x", "y") + df <- data.frame(1, current$x, current$x^2, current$x^3) + df <- as.matrix(df) + newFunction <- nnls::nnls(df, current$y) + newFunctionCoeff <- newFunction$x + names(newFunctionCoeff) <- names(data) + coeffList[[rowName]][] <- newFunctionCoeff + } - p <- ggplot2::ggplot(samples, ggplot2::aes(samples$x, samples$y, group = 1)) + - ggplot2::coord_cartesian(ylim = c(0, max(samples$y))) - p <- p + ggplot2::stat_function(fun=fTotal, size=1, ggplot2::aes(colour = "_aggregated function", linetype = "_aggregated function"), na.rm=TRUE) - for (i in 1:(length(weight))){ - p <- p + eval(parse(text = paste0("ggplot2::stat_function(fun=fY[[\"", as.character(names(weight)[i]) , "\"]], ggplot2::aes(colour = \"", as.character(names(weight)[i]) , "\" , linetype = \"" , as.character(names(weight)[i]), "\"), na.rm=TRUE)"))) #hack to allow legend - } - if ( !(colourPallete[1] == FALSE) & (length(colourPallete) >= length(weight))){ - p <- p + ggplot2::scale_colour_manual(label$legend, values = colourPallete) + # preparing results + result <- list() + if (returnSample == TRUE) { + result$sample <- samples # return samples table + } + if (returnChart == TRUE) { + # estimated functions + fY <- lapply(coeffList, function(coef) { + function(x) { + as.numeric(coef[1]) + as.numeric(coef[2]) * x + as.numeric(coef[3]) * x^2 + as.numeric(coef[4]) * x^3 } - p <- p + ggplot2::scale_linetype_manual(values = c("solid", rep.int("dashed", length(weight))), guide = FALSE) + }) - p <- p + ggplot2::guides(colour = ggplot2::guide_legend(override.aes = list(linetype = c("solid", rep.int("dashed", length(weight)))))) + p <- ggplot2::ggplot(samples, ggplot2::aes(samples$x, samples$y, group = 1)) + + ggplot2::coord_cartesian(ylim = c(0, max(samples$y))) + p <- p + ggplot2::stat_function(fun = fTotal, size = 1, ggplot2::aes(colour = "_aggregated function", linetype = "_aggregated function"), na.rm = TRUE) + for (i in 1:(length(weight))) { + p <- p + eval(parse(text = paste0("ggplot2::stat_function(fun=fY[[\"", as.character(names(weight)[i]), "\"]], ggplot2::aes(colour = \"", as.character(names(weight)[i]), "\" , linetype = \"", as.character(names(weight)[i]), "\"), na.rm=TRUE)"))) # hack to allow legend + } + if (!(colourPallete[1] == FALSE) & (length(colourPallete) >= length(weight))) { + p <- p + ggplot2::scale_colour_manual(label$legend, values = colourPallete) + } + p <- p + ggplot2::scale_linetype_manual(values = c("solid", rep.int("dashed", length(weight))), guide = FALSE) - p <- p + ggplot2::labs(colour = label$legend, x = label$x, y = label$y) + p <- p + ggplot2::guides(colour = ggplot2::guide_legend(override.aes = list(linetype = c("solid", rep.int("dashed", length(weight)))))) - result$chart <- p # return chart + p <- p + ggplot2::labs(colour = label$legend, x = label$x, y = label$y) + result$chart <- p # return chart + } + if (returnCoeff == TRUE) { # return coeff of estimated function + if (length(result) == 0) { + result <- coeffList + } else { + result$coeff <- coeffList } - if (returnCoeff == TRUE){ # return coeff of estimated function - if(length(result) == 0) { - result <- coeffList - } else { - result$coeff <- coeffList - } - } - return(result) } + return(result) + } ### End of cubicFitDisaggregate function # pre processing data formats and executing estimations - if(is.magpie(data)){ + if (is.magpie(data)) { df <- as.data.frame(data) # splitting large dimensional magpie objects - dataNames <- names(df[,grep("Data", names(df))]) # all data names + dataNames <- names(df[, grep("Data", names(df))]) # all data names dataNames <- dataNames[-length(dataNames)] # remove last element (coefficient labels) - factorGroups <- interaction(df[,dataNames]) # all combinations of Data values + factorGroups <- interaction(df[, dataNames]) # all combinations of Data values groupsList <- split(df, with(df, factorGroups), drop = TRUE) - #looping through all data sets and estimating the respective aggregated functions - output <- lapply(seq_along(groupsList), - function(i) { - # preparing data (row names equal to regions, one column for each coefficient) - currentDf <- groupsList[[i]] - currentDf <- currentDf[c(2,length(currentDf)-1,length(currentDf))] #region, coeff, value - names(currentDf) <- c("Region","coeff","value") - currentDf <- reshape2::acast(currentDf, Region ~ coeff, value.var = 'value') - currentWeight <- as.data.frame(weight[[names(groupsList[i])]])[c("Value")] - rownames(currentWeight) <- getRegions(weight[[names(groupsList[i])]]) - # estimating aggregated function - if (is.null(rel)){ # single aggregated function - out <- cubicFitDisaggregate(currentDf, currentWeight, xLowerBound=xLowerBound, xUpperBound=xUpperBound, returnCoeff=returnCoeff, returnChart=returnChart, returnSample=returnSample, numberOfSamples=numberOfSamples, unirootLowerBound=unirootLowerBound,unirootUpperBound=unirootUpperBound, colourPallete=colourPallete, label=label) - } else { # looping through new regions and estimating the aggregated function - if (returnMagpie==TRUE){ - returnCoeff=TRUE - returnChart=FALSE - returnSample=FALSE - } - from <- ifelse(dim(rel)[2]>2,2,1) # country - to <- ifelse(dim(rel)[2]>2,3,2) # region - out <- sapply(unique(rel[[to]]), function(region) { - currentFilteredDf <- currentDf[region,] - currentWeight <- currentWeight[rel[from][rel[to]==as.character(region)],] - names(currentWeight) <- rel[from][rel[to]==as.character(region)] - outRegion <- cubicFitDisaggregate(currentFilteredDf, currentWeight, xLowerBound=xLowerBound, xUpperBound=as.numeric(xUpperBound[region,,names(groupsList[i])]), returnCoeff=returnCoeff, returnChart=returnChart, returnSample=returnSample, numberOfSamples=numberOfSamples, unirootLowerBound=unirootLowerBound,unirootUpperBound=unirootUpperBound, colourPallete=colourPallete, label=label) - return(outRegion) - }) - names(out) <- unique(rel[[to]]) - if (returnMagpie==TRUE){ - df <- out - df <- data.frame(sapply(unique(names(df)), function(name) df[[name]] )) # unlist results - out <- data.frame(t(df[])) - names(out) <- rownames(df) - rownames(out) <- gsub(".*\\.", "", names(df)) - out <- stats::reshape(out, direction='long', varying=names(out), v.names='Value', timevar='coeff',times=names(out), idvar='Region', ids = rownames(out)) # long format - out <- as.magpie(out[,c("Region","coeff","Value")],temporal=0,datacol=3) - } - } - return(out) - }) + # looping through all data sets and estimating the respective aggregated functions + output <- lapply( + seq_along(groupsList), + function(i) { + # preparing data (row names equal to regions, one column for each coefficient) + currentDf <- groupsList[[i]] + currentDf <- currentDf[c(2, length(currentDf) - 1, length(currentDf))] # region, coeff, value + names(currentDf) <- c("Region", "coeff", "value") + currentDf <- reshape2::acast(currentDf, Region ~ coeff, value.var = "value") + currentWeight <- as.data.frame(weight[[names(groupsList[i])]])[c("Value")] + rownames(currentWeight) <- getRegions(weight[[names(groupsList[i])]]) + # estimating aggregated function + if (is.null(rel)) { # single aggregated function + out <- cubicFitDisaggregate(currentDf, currentWeight, xLowerBound = xLowerBound, xUpperBound = xUpperBound, returnCoeff = returnCoeff, returnChart = returnChart, returnSample = returnSample, numberOfSamples = numberOfSamples, unirootLowerBound = unirootLowerBound, unirootUpperBound = unirootUpperBound, colourPallete = colourPallete, label = label) + } else { # looping through new regions and estimating the aggregated function + if (returnMagpie == TRUE) { + returnCoeff <- TRUE + returnChart <- FALSE + returnSample <- FALSE + } + from <- ifelse(dim(rel)[2] > 2, 2, 1) # country + to <- ifelse(dim(rel)[2] > 2, 3, 2) # region + out <- sapply(unique(rel[[to]]), function(region) { + currentFilteredDf <- currentDf[region, ] + currentWeight <- currentWeight[rel[from][rel[to] == as.character(region)], ] + names(currentWeight) <- rel[from][rel[to] == as.character(region)] + outRegion <- cubicFitDisaggregate(currentFilteredDf, currentWeight, xLowerBound = xLowerBound, xUpperBound = as.numeric(xUpperBound[region, , names(groupsList[i])]), returnCoeff = returnCoeff, returnChart = returnChart, returnSample = returnSample, numberOfSamples = numberOfSamples, unirootLowerBound = unirootLowerBound, unirootUpperBound = unirootUpperBound, colourPallete = colourPallete, label = label) + return(outRegion) + }) + names(out) <- unique(rel[[to]]) + if (returnMagpie == TRUE) { + df <- out + df <- data.frame(sapply(unique(names(df)), function(name) df[[name]])) # unlist results + out <- data.frame(t(df[])) + names(out) <- rownames(df) + rownames(out) <- gsub(".*\\.", "", names(df)) + out <- stats::reshape(out, direction = "long", varying = names(out), v.names = "Value", timevar = "coeff", times = names(out), idvar = "Region", ids = rownames(out)) # long format + out <- as.magpie(out[, c("Region", "coeff", "Value")], temporal = 0, datacol = 3) + } + } + return(out) + } + ) names(output) <- names(groupsList) } else { - if (is.null(rel)){ # single aggregated function - output <- cubicFitDisaggregate(data, weight, xLowerBound=xLowerBound, xUpperBound=xUpperBound, returnCoeff=returnCoeff, returnChart=returnChart, returnSample=returnSample, numberOfSamples=numberOfSamples, unirootLowerBound=unirootLowerBound,unirootUpperBound=unirootUpperBound, colourPallete=colourPallete, label=label) + if (is.null(rel)) { # single aggregated function + output <- cubicFitDisaggregate(data, weight, xLowerBound = xLowerBound, xUpperBound = xUpperBound, returnCoeff = returnCoeff, returnChart = returnChart, returnSample = returnSample, numberOfSamples = numberOfSamples, unirootLowerBound = unirootLowerBound, unirootUpperBound = unirootUpperBound, colourPallete = colourPallete, label = label) } else { # looping through new regions and estimating the aggregated function - if (returnMagpie==TRUE){ - returnCoeff=TRUE - returnChart=FALSE - returnSample=FALSE + if (returnMagpie == TRUE) { + returnCoeff <- TRUE + returnChart <- FALSE + returnSample <- FALSE } - from <- ifelse(dim(rel)[2]>2,2,1) # country - to <- ifelse(dim(rel)[2]>2,3,2) # region + from <- ifelse(dim(rel)[2] > 2, 2, 1) # country + to <- ifelse(dim(rel)[2] > 2, 3, 2) # region output <- sapply(unique(rel[[to]]), function(region) { - currentFilteredDf <- data[region,] - currentWeight <- weight[rel[from][rel[to]==as.character(region)],] - outRegion <- cubicFitDisaggregate(currentFilteredDf, currentWeight, xLowerBound=xLowerBound, xUpperBound=xUpperBound, returnCoeff=returnCoeff, returnChart=returnChart, returnSample=returnSample, numberOfSamples=numberOfSamples, unirootLowerBound=unirootLowerBound,unirootUpperBound=unirootUpperBound, colourPallete=colourPallete, label=label) + currentFilteredDf <- data[region, ] + currentWeight <- weight[rel[from][rel[to] == as.character(region)], ] + outRegion <- cubicFitDisaggregate(currentFilteredDf, currentWeight, xLowerBound = xLowerBound, xUpperBound = xUpperBound, returnCoeff = returnCoeff, returnChart = returnChart, returnSample = returnSample, numberOfSamples = numberOfSamples, unirootLowerBound = unirootLowerBound, unirootUpperBound = unirootUpperBound, colourPallete = colourPallete, label = label) return(outRegion) }) names(output) <- unique(rel[[to]]) - if (returnMagpie==TRUE){ + if (returnMagpie == TRUE) { df <- output - df <- data.frame(sapply(unique(names(df)), function(name) df[[name]] )) # unlist results + df <- data.frame(sapply(unique(names(df)), function(name) df[[name]])) # unlist results output <- data.frame(t(df[])) names(output) <- rownames(df) rownames(output) <- gsub(".*\\.", "", names(df)) - output <- stats::reshape(output, direction='long', varying=names(output), v.names='Value', timevar='coeff',times=names(output), idvar='Region', ids = rownames(output)) # long format - output <- as.magpie(output[,c("Region","coeff","Value")],temporal=0,datacol=3) + output <- stats::reshape(output, direction = "long", varying = names(output), v.names = "Value", timevar = "coeff", times = names(output), idvar = "Region", ids = rownames(output)) # long format + output <- as.magpie(output[, c("Region", "coeff", "Value")], temporal = 0, datacol = 3) } } } diff --git a/R/toolFillEU34Countries.R b/R/toolFillEU34Countries.R index b101423b..43122cd2 100644 --- a/R/toolFillEU34Countries.R +++ b/R/toolFillEU34Countries.R @@ -1,5 +1,5 @@ #' Sets values for 6 EU countries not belonging to EU 28 but EU 34 to zero if -#' they are NA. Used to avoid EUR region not yielding NA because of these countries. +#' they are NA. Used to avoid EUR region yielding NA because of these countries. #' #' @param x magpie object with 249 ISO country codes in the spatial dimension #' @author Falk Benke diff --git a/R/toolSolarFunctionAggregate.R b/R/toolSolarFunctionAggregate.R index 0048e007..8dac04f5 100644 --- a/R/toolSolarFunctionAggregate.R +++ b/R/toolSolarFunctionAggregate.R @@ -1,19 +1,17 @@ #' toolSolarFunctionAggregate -#' +#' #' Aggregate Solar data into regions -#' +#' #' @param x magclass object that should be aggregated #' @param rel relation matrix containing a region mapping. #' A mapping object should contain 2 columns in which each element of x #' is mapped to the category it should belong to after (dis-)aggregation #' @param weight aggregation weight (should be FE|Electricity (EJ/yr) in 2015) #' @return return: returns region aggregated solar data -#' +#' #' @author Felix Schreyer, Renato Rodrigues, Julian Oeser #' @export -#' @importFrom magclass is.magpie as.data.frame as.magpie collapseNames add_columns getSets getItems -#' setItems collapseDim -#' @importFrom dplyr %>% mutate select rename filter left_join group_by ungroup arrange summarise desc +#' @importFrom dplyr mutate select rename filter left_join group_by ungroup arrange summarise desc #' lag full_join #' @importFrom tidyr spread gather complete #' @importFrom quitte as.quitte @@ -22,64 +20,64 @@ toolSolarFunctionAggregate <- function(x, rel=NULL, weight = calcOutput("FE", aggregate = FALSE)[,"y2015","FE|Electricity (EJ/yr)"]){ - + # old part by Julian Oeser - + # aggregate to regions x <- toolAggregate(x,rel) getSets(x)[1] <- "Region" - + ### split up pv in (needed?) - + # PVall (install PV everywhere), # PVcomp (install PV only where also csp could be installed) (FS: Why should one want to do this???), # PVonly (install PV only where no csp can be installed) - + # installable area for csp, pv in region area.pv <- dimSums(x[,,"area"][,,"PV"][,,c("0-50", "50-100")], dim=c(3.4,3.3)) # sum over bins and distance classes area.csp <- dimSums(x[,,"area"][,,"CSP"][,,c("0-50", "50-100")], dim=c(3.4, 3.3)) - + # share of area if PV installed only where no csp can be installed if(packageVersion("magclass") < 6) { area.only.pv.share <- ((area.pv+1)-(area.csp+1)) / (area.pv+1) x <- add_columns(x, c("PVcomp", "PVonly"), 3.2) x[,,"PVonly"] <- x[,,"PV"]*area.only.pv.share[,,"PV"] - x[,,"PVcomp"] <- x[,,"PV"]-(x[,,"PV"]*area.only.pv.share[,,"PV"]) + x[,,"PVcomp"] <- x[,,"PV"]-(x[,,"PV"]*area.only.pv.share[,,"PV"]) } else { area.only.pv.share <- collapseDim(((area.pv+1)-(area.csp+1)) / (area.pv+1)) xPVonly <- setItems(x[,,"PV"]*area.only.pv.share, dim = "Technology", value = "PVonly") xPVcomp <- setItems(x[,,"PV"]-(x[,,"PV"]*area.only.pv.share), dim = "Technology", value = "PVcomp") x <- mbind(x, xPVonly, xPVcomp) } - - ### create new distance class: 1-100red (distance class where all between 1-100 are included and + + ### create new distance class: 1-100red (distance class where all between 1-100 are included and # far away distanced classes are reduced in FLH which accounts for transmission losses) bins.pv <- getNames(x[,,"PV"], dim = 4) bins.csp <- getNames(x[,,"CSP"], dim = 4) - + x1.pv <- x[,,"0-50"][,,"PV"][,,bins.pv] x1.csp <- x[,,"0-50"][,,"CSP"][,,bins.csp] - + x2.pv <- x[,,"50-100"][,,"PV"][,,bins.pv] x2.csp <- x[,,"50-100"][,,"CSP"][,,bins.csp] - + # equivalents of bins in the two distance classes offset.pv <- 4 offset.csp <- 2 - + bins.pv.d2 <- c(rep(head(bins.pv, 1), offset.pv), bins.pv[1:(length(bins.pv)-offset.pv)]) bins.pv.agg <- cbind(bins.pv, bins.pv.d2) colnames(bins.pv.agg) <- c("d1", "d2") - + bins.csp.d2 <- c(rep(head(bins.csp, 1), offset.csp), bins.csp[1:(length(bins.csp)-offset.csp)]) bins.csp.agg <- cbind(bins.csp, bins.csp.d2) colnames(bins.csp.agg) <- c("d1", "d2") - + x2.pv <- toolAggregate(x2.pv, rel=bins.pv.agg, dim=3.4) getSets(x2.pv) <- getSets(x1.pv) x2.csp <- toolAggregate(x2.csp, rel=bins.csp.agg, dim=3.4) getSets(x2.csp) <- getSets(x1.csp) - + .missingBins <- function(x1,x2) { bin1 <- getItems(x1, dim = "Bin") bin2 <- getItems(x2, dim = "Bin") @@ -87,23 +85,23 @@ toolSolarFunctionAggregate <- function(x, rel=NULL, weight = calcOutput("FE", ag } missing.bins.pv <- .missingBins(x1.pv, x2.pv) missing.bins.csp <- .missingBins(x1.csp, x2.csp) - + x2.pv <- add_columns(x2.pv, missing.bins.pv, 3.4) x2.pv[,,missing.bins.pv] <- 0 - + x2.csp <- add_columns(x2.csp, missing.bins.csp, 3.4) x2.csp[,,missing.bins.csp] <- 0 - + # do summation x <- add_columns(x, "1-100red", 3.3) x[,,"PV"][,,"1-100red"] <- x1.pv[,,"0-50"]+ x2.pv[,,"50-100"] x[,,"CSP"][,,"1-100red"] <- x1.csp[,,"0-50"]+ x2.csp[,,"50-100"] - - - + + + # emtpy declarations of variables used in dplyr operations # (needed to make dplyr work within library) - + region <- NULL Type <- NULL Technology <- NULL @@ -125,13 +123,13 @@ toolSolarFunctionAggregate <- function(x, rel=NULL, weight = calcOutput("FE", ag Seclast <- NULL Max <- NULL Min <- NULL - - - + + + ### FS: map and aggregate FLH bins from DLR data to REMIND grades - - # method: - # 1. cumulative potential (maxprod) is calculated in descending order of FLHs + + # method: + # 1. cumulative potential (maxprod) is calculated in descending order of FLHs # 2. cumulative potential is normalized by current (2015) FE electricity consumption (IEA) # 3. cumulative potential vs. FLH is interpolated between given data points step-wise and linearly # to have at least one point in each REMIND grade @@ -140,76 +138,76 @@ toolSolarFunctionAggregate <- function(x, rel=NULL, weight = calcOutput("FE", ag # 5. all potential that is above the last value of grade breaks are mapped into the last grade # 6. an exception is made for regions/technologies where total potential is below the lower bound of the last grade s.t. # last grade would be emtpy -> here the grades are determined by equally spaced bins of potential up to the total potential (e.g. for Japan) - - + + # set parameters for bin to grade mapping - grade.breaks <- c(0.1,0.3,0.6,1,2,5,10,20) # grade breaks normalized by current production + grade.breaks <- c(0.1,0.3,0.6,1,2,5,10,20) # grade breaks normalized by current production n.intp <- 400 # number of interpolation points between given bins (to make sure at least one value is assigned to every REMIND grade) thres.offset <- 30 # interpolation will be applied up to lower bound of last grade + offset (unit: normalized cumulative production) # for assuring that enough data points are there for interpolation up to lower bound of last grade - + techs <- c("CSP", "PV") # technologies to aggregate dist <- "1-100red" # distance class to aggregate # reference for grade distinction = 2015 production # assign 0.01 EJ/yr as reference for grade distinction to countries with zero 2015 production MaxProd.Norm <- toolAggregate(weight, rel) - MaxProd.Norm[MaxProd.Norm == 0] <- 0.01 + MaxProd.Norm[MaxProd.Norm == 0] <- 0.01 # convert data to quitte format because more convenient for the following operations - df.x <- as.quitte(x[,,techs][,,dist]) %>% - # drop 0 and NA potentials - #filter(value > 0 , !is.na(value)) %>% + df.x <- as.quitte(x[,,techs][,,dist]) %>% + # drop 0 and NA potentials + #filter(value > 0 , !is.na(value)) %>% # rename Bin to Full load hours, convert to numerical mutate(FLH = as.numeric(as.character(Bin))) %>% select(region, Type, Technology, Distance, value, FLH) - - + + # calculate maxprod (potential/maximum possible production in grade) in GWh by: capacity * FLH (Full Load Hours) / 1000 - df.pot <- df.x %>% - spread(Type, value) %>% - mutate( maxprod = capacity * FLH / 1000) %>% + df.pot <- df.x %>% + spread(Type, value) %>% + mutate( maxprod = capacity * FLH / 1000) %>% # remove those locations with NA or 0 area or potential - filter( maxprod > 0, area > 0) %>% + filter( maxprod > 0, area > 0) %>% gather(Type, value, capacity, area, maxprod) - - # calculate cumulated capacity, maxprod (potential) and area in descending grade order - # to obtain how much can be produced in total at this FLH or higher FLH + + # calculate cumulated capacity, maxprod (potential) and area in descending grade order + # to obtain how much can be produced in total at this FLH or higher FLH df.cuml <- df.pot %>% group_by(region, Type, Technology, Distance) %>% arrange(desc(FLH)) %>% mutate( value = cumsum(value)) %>% ungroup() - + # process 2015 IEA electricity production - df.prod.2015 <- as.quitte(MaxProd.Norm) %>% + df.prod.2015 <- as.quitte(MaxProd.Norm) %>% # FE 2015 in GWh/yr - mutate( production = value / 3.6 * 1e6) %>% + mutate( production = value / 3.6 * 1e6) %>% select(region, production) - - - # calculate cumulative normalized potential + + + # calculate cumulative normalized potential # noramlized by current (2015) production df.maxprod.norm <- df.cuml %>% filter(Type == "maxprod") %>% left_join( df.prod.2015) %>% - mutate(maxprod.norm = value/production) %>% + mutate(maxprod.norm = value/production) %>% select(region, Technology, Distance, FLH, maxprod.norm) - - ## join normalized cumulative maxprod agin to df with cumulative maxprod, area, capacity + + ## join normalized cumulative maxprod agin to df with cumulative maxprod, area, capacity #to be able to interplolate all three measures df.cuml <- df.cuml %>% spread(Type, value) %>% left_join(df.maxprod.norm) - + # get total potential per region, technology, distance, # needed for distinguishing mapping of fine grades to REMIND grades later - df.totalPot <- df.cuml %>% - group_by(region, Technology, Distance) %>% + df.totalPot <- df.cuml %>% + group_by(region, Technology, Distance) %>% summarise( TotalPot = max(maxprod.norm)) - - + + # define function needed for interpolation inbetween given points # returns vector x appended by n equally spaced values between those points # x: x coordinates of given (x,y) points @@ -223,74 +221,74 @@ toolSolarFunctionAggregate <- function(x, rel=NULL, weight = calcOutput("FE", ag } return(out) } - + # interpolate cumulative normalized potential vs. FLH step-wise linearly between the given data points to obtain fine grades df.interpolate <- df.cuml %>% - # filter for potential below last grade, the rest will go into last grade, + # filter for potential below last grade, the rest will go into last grade, # add offset (thres.offset) to obtain values above the lower bound of the last grade - # to assure that values are interpolated at least up to this lower bound + # to assure that values are interpolated at least up to this lower bound filter( maxprod.norm < grade.breaks[length(grade.breaks)]+thres.offset) %>% group_by(region, Technology, Distance) %>% # order by descending FLH - arrange(desc(FLH)) %>% - # recompute potential as difference between normalized potential of neighboring FLH bins - mutate( diff = maxprod.norm - lag(maxprod.norm)) %>% - mutate( diff = ifelse(is.na(diff), maxprod.norm, diff)) %>% + arrange(desc(FLH)) %>% + # recompute potential as difference between normalized potential of neighboring FLH bins + mutate( diff = maxprod.norm - lag(maxprod.norm)) %>% + mutate( diff = ifelse(is.na(diff), maxprod.norm, diff)) %>% # expand by n.intp equally spaced values between the given maxprod.norm values - complete(maxprod.norm = seq.between(maxprod.norm, diff, n.intp)) %>% + complete(maxprod.norm = seq.between(maxprod.norm, diff, n.intp)) %>% # interpolate maxprod, area, capacity linearly at new data points between given data points - mutate(FLH = zoo::na.approx(FLH, na.rm = F), maxprod = zoo::na.approx(maxprod, na.rm = F), - area = zoo::na.approx(area, na.rm = F), capacity = zoo::na.approx(capacity, na.rm = F)) %>% + mutate(FLH = zoo::na.approx(FLH, na.rm = F), maxprod = zoo::na.approx(maxprod, na.rm = F), + area = zoo::na.approx(area, na.rm = F), capacity = zoo::na.approx(capacity, na.rm = F)) %>% # remove NAs that were appended above FLHs of first data point filter( !is.na(FLH)) - + # transform cumulative values (maxprod, area, capacity) of fine grades to values per fine grade # by performing gradient operation - df.fine.grades <- df.interpolate %>% - select(region, Technology, Distance, FLH, maxprod.norm, maxprod, capacity, area) %>% - gather(Type, value, maxprod, capacity, area) %>% - group_by(region, Type, Technology, Distance) %>% - arrange(desc(FLH)) %>% - # calculate value per fine grade by gradient of cumulative value - mutate( diff = value - lag(value)) %>% + df.fine.grades <- df.interpolate %>% + select(region, Technology, Distance, FLH, maxprod.norm, maxprod, capacity, area) %>% + gather(Type, value, maxprod, capacity, area) %>% + group_by(region, Type, Technology, Distance) %>% + arrange(desc(FLH)) %>% + # calculate value per fine grade by gradient of cumulative value + mutate( diff = value - lag(value)) %>% # highest FLH has no predecessor, so take diff to 0, i.e. value itself - mutate( diff = ifelse(is.na(diff), value, diff)) %>% - ungroup() %>% - # relabel: value is now the potential in this fine grade, + mutate( diff = ifelse(is.na(diff), value, diff)) %>% + ungroup() %>% + # relabel: value is now the potential in this fine grade, # while the other is the cumulative value incl. all grades with higher FLH rename( cumulative = value, value = diff) - + ## for regions/technologies with total potential WITHIN last grade: # assign REMIND grades to interpolated FLH bins according to grade breaks of normalized potential defined above - df.map.REMIND <- df.fine.grades %>% + df.map.REMIND <- df.fine.grades %>% select(region, Technology, Distance, Type, maxprod.norm, FLH, value) %>% - mutate(grade = .bincode(maxprod.norm, c(0,grade.breaks))) %>% - # filter out NA grades (maxprod.norm greater than largest element in grade.breaks), + mutate(grade = .bincode(maxprod.norm, c(0,grade.breaks))) %>% + # filter out NA grades (maxprod.norm greater than largest element in grade.breaks), # this potential would be in last grade filter(!is.na(grade)) - - + + ## for regions/technologies with total potential BELOW last grade (so that last grade would be empty): # map to equally sized grades up to total potential (so that each grade filled) - + # determine region/technologies with first (highest FLH) data point above first grade # and with total potential below last grade - df.OutsideBreaks <- df.cuml %>% - group_by(region, Technology, Distance) %>% + df.OutsideBreaks <- df.cuml %>% + group_by(region, Technology, Distance) %>% summarise( Min = min(maxprod.norm)) %>% - ungroup() %>% - full_join(df.totalPot) %>% - filter( Min > grade.breaks[1] | TotalPot < grade.breaks[length(grade.breaks)]) %>% + ungroup() %>% + full_join(df.totalPot) %>% + filter( Min > grade.breaks[1] | TotalPot < grade.breaks[length(grade.breaks)]) %>% mutate( Max = ifelse(is.na(TotalPot), grade.breaks[length(grade.breaks)], TotalPot)) - - # for both (too large first grade and too small last grade): distribute grades equally spaced - # ugly loop soluation, I have not found a dplyr grouping solution + + # for both (too large first grade and too small last grade): distribute grades equally spaced + # ugly loop soluation, I have not found a dplyr grouping solution # for making .bincode() breaks argument depend on group for (i in 1:nrow(df.OutsideBreaks)) { # temporary dataframe for mapping small potentials to equally spaced grades - df.map.temp <- df.fine.grades %>% + df.map.temp <- df.fine.grades %>% select(region, Technology, Distance, Type, maxprod.norm, FLH, value) %>% - filter( region == as.character(df.OutsideBreaks$region[i]), + filter( region == as.character(df.OutsideBreaks$region[i]), Technology == as.character(df.OutsideBreaks$Technology[i]), Distance == as.character(df.OutsideBreaks$Distance[i])) # sry: a bit messay the following case distinction...if there is ever time, could be structured better @@ -305,8 +303,8 @@ toolSolarFunctionAggregate <- function(x, rel=NULL, weight = calcOutput("FE", ag new.grade.breaks <- seq(df.OutsideBreaks$Min[i]-1e-5,min(grades.to.shift), length.out = (9-length(grades.to.shift)+1)) new.grade.breaks <- c(new.grade.breaks, grades.to.shift[-1]) } - # 2. if highest FLH data point (DLR) outside first grade and (!) - # total potential below lower bound of last grade -> + # 2. if highest FLH data point (DLR) outside first grade and (!) + # total potential below lower bound of last grade -> # equally spaced grades up to the first element of grade.breaks that is within the original FLH data bins and (!) # split last grade into multiple equally spaced grades } else if (df.OutsideBreaks$Min[i] > grade.breaks[1] & df.OutsideBreaks$Max[i] < grade.breaks[8] & nrow(df.map.temp) > 0) { @@ -315,24 +313,24 @@ toolSolarFunctionAggregate <- function(x, rel=NULL, weight = calcOutput("FE", ag new.grade.breaks <- c(new.grade.breaks, grades.to.shift[-1]) grades.to.keep <- new.grade.breaks[new.grade.breaks < df.OutsideBreaks$Max[i]] new.grade.breaks <- c(grades.to.keep[-length(grades.to.keep)], seq(grades.to.keep[length(grades.to.keep)], - df.OutsideBreaks$Max[i]+1e-2, + df.OutsideBreaks$Max[i]+1e-2, length.out = (9-length(grades.to.keep)+2))) # 3. if total potential is below the current generation -> equally spaced grades up to total potential } else if (df.OutsideBreaks$Max[i] < 1 ) { - new.grade.breaks <- c(seq(df.OutsideBreaks$Min[i]-1e-5,df.OutsideBreaks$Max[i], + new.grade.breaks <- c(seq(df.OutsideBreaks$Min[i]-1e-5,df.OutsideBreaks$Max[i], length.out=(length(grade.breaks)+2))) - # 4. if total potential is above current generation but below lower bound of last grade - # -> split last grade into multiple equally spaced grades + # 4. if total potential is above current generation but below lower bound of last grade + # -> split last grade into multiple equally spaced grades } else if (df.OutsideBreaks$Max[i] > 1 & df.OutsideBreaks$Max[i] < grade.breaks[8] ) { - grades.to.keep <- grade.breaks[grade.breaks < df.OutsideBreaks$Max[i]] + grades.to.keep <- grade.breaks[grade.breaks < df.OutsideBreaks$Max[i]] new.grade.breaks <- c(0,grades.to.keep[-length(grades.to.keep)], seq(grades.to.keep[length(grades.to.keep)], - df.OutsideBreaks$Max[i]+1e-2, + df.OutsideBreaks$Max[i]+1e-2, length.out = (9-length(grades.to.keep)+1))) } - - df.map.temp <- df.map.temp %>% + + df.map.temp <- df.map.temp %>% mutate(grade.seq = .bincode(maxprod.norm, new.grade.breaks)) - + # bind rows of temporary datafrage to output dataframe of loop: df.map.small if (i == 1) { df.outside <- df.map.temp @@ -341,110 +339,110 @@ toolSolarFunctionAggregate <- function(x, rel=NULL, weight = calcOutput("FE", ag } } # replace potential values of small potential regions with the equally spaced grades from the loop to avoid emtpy grades - df.map.REMIND <- df.map.REMIND %>% - left_join(df.outside) %>% - mutate(grade = ifelse(is.na(grade.seq), grade, grade.seq)) %>% - select(-grade.seq) - - + df.map.REMIND <- df.map.REMIND %>% + left_join(df.outside) %>% + mutate(grade = ifelse(is.na(grade.seq), grade, grade.seq)) %>% + select(-grade.seq) + + # spread maxprod column to have weight for FLH aggregation in next step - df.map.REMIND <- df.map.REMIND %>% - spread(Type, value) %>% - mutate(maxprod.weight = maxprod) %>% + df.map.REMIND <- df.map.REMIND %>% + spread(Type, value) %>% + mutate(maxprod.weight = maxprod) %>% gather(Type, value, maxprod, capacity, area) - - - - - ## aggregate fine grades to REMIND grades - df.aggregate.grades <- df.map.REMIND %>% + + + + + ## aggregate fine grades to REMIND grades + df.aggregate.grades <- df.map.REMIND %>% group_by(region, Type, Technology, Distance, grade) %>% # aggregate fine grade to REMIND grades: FLH <- FLHs weighted by maxprod of fine grade # potential, area, capacity <- sum over all values potential/area/capacity REMIND grade summarise( FLH = weighted.mean(FLH, maxprod.weight), value = sum(value)) %>% - ungroup() %>% + ungroup() %>% # add FLH to Type column to make it another dimension like maxprod, area etc. spread(Type, value) %>% gather(Type, value, capacity, area, maxprod, FLH) %>% - select(region, Type, Technology, Distance, grade, value) - - # get overlap of first data point in last grade with second last grade - # needs to be substracted from last grade later + select(region, Type, Technology, Distance, grade, value) + + # get overlap of first data point in last grade with second last grade + # needs to be substracted from last grade later # to make sure that we get the right totals over all grades - + # last data point before lastgrade - df.seclast <- df.cuml %>% - filter(maxprod.norm < grade.breaks[length(grade.breaks)]) %>% - group_by(region, Technology, Distance) %>% - mutate( Max = max(maxprod.norm)) %>% - ungroup() %>% - filter( maxprod.norm == Max) %>% - select(-Max) %>% - gather(Type, Seclast, maxprod, area, capacity) %>% + df.seclast <- df.cuml %>% + filter(maxprod.norm < grade.breaks[length(grade.breaks)]) %>% + group_by(region, Technology, Distance) %>% + mutate( Max = max(maxprod.norm)) %>% + ungroup() %>% + filter( maxprod.norm == Max) %>% + select(-Max) %>% + gather(Type, Seclast, maxprod, area, capacity) %>% select(region, Technology, Distance, Type, Seclast) - - # calculate maxprod, area, capacity difference between last data point before last grade + + # calculate maxprod, area, capacity difference between last data point before last grade # and lower bound of last grade, to be added removed from lastgrade later df.lastgrade.overlap <- df.interpolate %>% # filter for maxprod, area, capacity at lower bound of last grade (threshold) - filter(maxprod.norm < grade.breaks[length(grade.breaks)]) %>% - gather(Type, value, maxprod, area, capacity) %>% - group_by(region, Technology, Distance) %>% - mutate( Max = max(maxprod.norm)) %>% - ungroup() %>% - filter(maxprod.norm == Max) %>% - select(-Max) %>% + filter(maxprod.norm < grade.breaks[length(grade.breaks)]) %>% + gather(Type, value, maxprod, area, capacity) %>% + group_by(region, Technology, Distance) %>% + mutate( Max = max(maxprod.norm)) %>% + ungroup() %>% + filter(maxprod.norm == Max) %>% + select(-Max) %>% #join lsat data point before last grade - left_join(df.seclast) %>% - mutate( diff = value - Seclast) %>% + left_join(df.seclast) %>% + mutate( diff = value - Seclast) %>% select(region, Technology, Distance, Type, diff) - - - - - # assign remaining potential to last grade for regions/technologies + + + + + # assign remaining potential to last grade for regions/technologies # with total potential greater than last grade - df.lastgrade <- df.cuml %>% + df.lastgrade <- df.cuml %>% # filter for regions/technologies... with total potential within last grade - filter( maxprod.norm >= grade.breaks[length(grade.breaks)]) %>% - select(region, Technology, FLH) %>% - left_join(df.pot) %>% - group_by(region, Technology, Distance, Type) %>% + filter( maxprod.norm >= grade.breaks[length(grade.breaks)]) %>% + select(region, Technology, FLH) %>% + left_join(df.pot) %>% + group_by(region, Technology, Distance, Type) %>% # sum all data point above lower bound of last grade to get last grade - summarise( value = sum(value), FLH = mean(FLH)) %>% - ungroup() %>% - mutate( grade = length(grade.breaks)+1) %>% + summarise( value = sum(value), FLH = mean(FLH)) %>% + ungroup() %>% + mutate( grade = length(grade.breaks)+1) %>% spread(Type, value) %>% - gather(Type, value, capacity, area, maxprod, FLH) %>% + gather(Type, value, capacity, area, maxprod, FLH) %>% # join overlap of first data point in last grade with second last grade from last grade - left_join(df.lastgrade.overlap) %>% - # subtract overlap from maxprod, area, capacity of last grade + left_join(df.lastgrade.overlap) %>% + # subtract overlap from maxprod, area, capacity of last grade # because this overlap was already assgined to second last grade - mutate( value = ifelse(is.na(diff), value, value - diff)) %>% - select(region, Type, Technology, Distance, grade, value) - - - - df.aggregate.grades <- df.lastgrade %>% - rbind(df.aggregate.grades) %>% + mutate( value = ifelse(is.na(diff), value, value - diff)) %>% + select(region, Type, Technology, Distance, grade, value) + + + + df.aggregate.grades <- df.lastgrade %>% + rbind(df.aggregate.grades) %>% arrange(region, Technology, Distance, Type, grade, value) - - + + # relabel dimensions, convert values to fit to desired REMIND input - df.out <- df.aggregate.grades %>% + df.out <- df.aggregate.grades %>% quitte::revalue.levels(Type = c("area" = "limitGeopot", "FLH" = "nur"), - Technology = c("PV" = "spv", "CSP" = "csp")) %>% + Technology = c("PV" = "spv", "CSP" = "csp")) %>% # convert FLH to capacity factor - mutate( value = ifelse( Type=="nur", round(value/8760,4), value)) %>% + mutate( value = ifelse( Type=="nur", round(value/8760,4), value)) %>% # convert maxprod from GWh to EJ - mutate( value = ifelse( Type == "maxprod", value * 3.6 * 1e-6, value)) %>% + mutate( value = ifelse( Type == "maxprod", value * 3.6 * 1e-6, value)) %>% arrange(region, Technology, Distance, Type, grade, value) - - - - + + + + ### create output magpie object - + # convert to magpie object out <- as.magpie(df.out, spatial = 1, temporal=NULL, datacol=6) # remove additional dimensions (e.g. Distance class) @@ -457,7 +455,7 @@ toolSolarFunctionAggregate <- function(x, rel=NULL, weight = calcOutput("FE", ag out <- out[,,"capacity",invert=TRUE] # relabel sets getSets(out) <- c("region", "year", "type", "technology" , "rlf") - - + + return(out) } diff --git a/R/tool_expand_tibble.R b/R/tool_expand_tibble.R index 7a9e0b52..045948a1 100644 --- a/R/tool_expand_tibble.R +++ b/R/tool_expand_tibble.R @@ -15,7 +15,6 @@ #' @return A `tibble`. #' #' @importFrom dplyr anti_join bind_rows filter select -#' @importFrom magrittr %>% #' @importFrom rlang syms #' @importFrom tidyr complete nesting #' @importFrom tidyselect all_of diff --git a/R/tool_fix_IEA_data_for_Industry_subsectors.R b/R/tool_fix_IEA_data_for_Industry_subsectors.R index a453a6cc..bf7601b3 100644 --- a/R/tool_fix_IEA_data_for_Industry_subsectors.R +++ b/R/tool_fix_IEA_data_for_Industry_subsectors.R @@ -29,7 +29,6 @@ #' @importFrom assertr not_na assert #' @importFrom dplyr anti_join group_by inner_join left_join mutate pull rename #' select summarise -#' @importFrom magclass getRegions getYears getNames #' @importFrom readr read_delim cols col_skip col_character #' @importFrom quitte cartesian interpolate_missing_periods overwrite #' character.data.frame interpolate_missing_periods_ @@ -506,7 +505,8 @@ tool_fix_IEA_data_for_Industry_subsectors <- function(data, ieamatch, unique() region_mapping <- toolGetMapping(name = 'regionmapping_21_EU11.csv', - type = 'regional') %>% + type = 'regional', + where = 'mappingfolder') %>% as_tibble() %>% select('iso3c' = .data$CountryCode, 'region' = .data$RegionCode) diff --git a/R/zzz.R b/R/zzz.R index 007bd05c..7038624b 100644 --- a/R/zzz.R +++ b/R/zzz.R @@ -1,3 +1,6 @@ .onLoad <- function(libname, pkgname) { - madrat::setConfig(nolabels = c(madrat::getConfig("nolabels"), "REMIND", "VALIDATIONREMIND"), .cfgchecks = FALSE, .verbose = FALSE) + madrat::setConfig( + nolabels = c(madrat::getConfig("nolabels"), "REMIND", "VALIDATIONREMIND"), + .cfgchecks = FALSE, .verbose = FALSE + ) } diff --git a/README.md b/README.md index 104402f2..40e3451b 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # MadRat REMIND Input Data Package -R package **mrremind**, version **0.175.10** +R package **mrremind**, version **0.189.0** [![CRAN status](https://www.r-pkg.org/badges/version/mrremind)](https://cran.r-project.org/package=mrremind) [![R build status](https://github.com/pik-piam/mrremind/workflows/check/badge.svg)](https://github.com/pik-piam/mrremind/actions) [![codecov](https://codecov.io/gh/pik-piam/mrremind/branch/master/graph/badge.svg)](https://app.codecov.io/gh/pik-piam/mrremind) [![r-universe](https://pik-piam.r-universe.dev/badges/mrremind)](https://pik-piam.r-universe.dev/builds) @@ -39,16 +39,16 @@ In case of questions / problems please contact Lavinia Baumstark . +Baumstark L, Rodrigues R, Levesque A, Oeser J, Bertram C, Mouratiadou I, Malik A, Schreyer F, Soergel B, Rottoli M, Mishra A, Dirnaichner A, Pehl M, Giannousakis A, Klein D, Strefler J, Feldhaus L, Brecha R, Rauner S, Dietrich J, Bi S, Benke F, Weigmann P, Richters O, Hasse R, Fuchs S, Mandaroux R, Koch J (2024). _mrremind: MadRat REMIND Input Data Package_. R package version 0.189.0, . A BibTeX entry for LaTeX users is ```latex @Manual{, title = {mrremind: MadRat REMIND Input Data Package}, - author = {Lavinia Baumstark and Renato Rodrigues and Antoine Levesque and Julian Oeser and Christoph Bertram and Ioanna Mouratiadou and Aman Malik and Felix Schreyer and Bjoern Soergel and Marianna Rottoli and Abhijeet Mishra and Alois Dirnaichner and Michaja Pehl and Anastasis Giannousakis and David Klein and Jessica Strefler and Lukas Feldhaus and Regina Brecha and Sebastian Rauner and Jan Philipp Dietrich and Stephen Bi and Falk Benke and Pascal Weigmann and Oliver Richters and Robin Hasse and Sophie Fuchs and Rahel Mandaroux}, + author = {Lavinia Baumstark and Renato Rodrigues and Antoine Levesque and Julian Oeser and Christoph Bertram and Ioanna Mouratiadou and Aman Malik and Felix Schreyer and Bjoern Soergel and Marianna Rottoli and Abhijeet Mishra and Alois Dirnaichner and Michaja Pehl and Anastasis Giannousakis and David Klein and Jessica Strefler and Lukas Feldhaus and Regina Brecha and Sebastian Rauner and Jan Philipp Dietrich and Stephen Bi and Falk Benke and Pascal Weigmann and Oliver Richters and Robin Hasse and Sophie Fuchs and Rahel Mandaroux and Johannes Koch}, year = {2024}, - note = {R package version 0.175.10}, + note = {R package version 0.189.0}, url = {https://github.com/pik-piam/mrremind}, } ``` diff --git a/inst/extdata/regional/regionmappingBP_Full.csv b/inst/extdata/regional/regionmappingBP_Full.csv new file mode 100755 index 00000000..85f3be42 --- /dev/null +++ b/inst/extdata/regional/regionmappingBP_Full.csv @@ -0,0 +1,212 @@ +"Region_name","ISO3 code" +"S & C America","ABW" +"Asia Pacific","AFG" +"Africa","AGO" +"Europe","ALB" +"Middle East","ARE" +"S & C America","ARG" +"CIS","ARM" +"Asia Pacific","ATA" +"S & C America","ATG" +"Asia Pacific","AUS" +"Europe","AUT" +"CIS","AZE" +"Africa","BDI" +"Europe","BEL" +"Africa","BEN" +"Africa","BFA" +"Asia Pacific","BGD" +"Europe","BGR" +"Middle East","BHR" +"S & C America","BHS" +"Europe","BIH" +"S & C America","BLM" +"CIS","BLR" +"S & C America","BLZ" +"S & C America","BOL" +"S & C America","BRA" +"S & C America","BRB" +"Asia Pacific","BRN" +"Asia Pacific","BTN" +"Africa","BWA" +"Africa","CAF" +"Asia Pacific","CCK" +"Europe","CHE" +"S & C America","CHL" +"Asia Pacific","CHN" +"Africa","CIV" +"Africa","CMR" +"Africa","COD" +"Africa","COG" +"Asia Pacific","COK" +"S & C America","COL" +"Africa","COM" +"Africa","CPV" +"S & C America","CRI" +"S & C America","CUB" +"Asia Pacific","CXR" +"S & C America","CYM" +"Europe","CYP" +"Europe","CZE" +"Europe","DEU" +"Africa","DJI" +"S & C America","DMA" +"Europe","DNK" +"S & C America","DOM" +"Africa","DZA" +"S & C America","ECU" +"Africa","EGY" +"Africa","ERI" +"Europe","ESP" +"Europe","EST" +"Africa","ETH" +"Europe","FIN" +"Asia Pacific","FJI" +"Europe","FRA" +"Asia Pacific","FSM" +"Africa","GAB" +"Europe","GBR" +"Europe","GEO" +"Africa","GHA" +"Europe","GIB" +"Africa","GIN" +"S & C America","GLP" +"Africa","GMB" +"Africa","GNB" +"Africa","GNQ" +"Europe","GRC" +"S & C America","GRD" +"S & C America","GTM" +"S & C America","GUF" +"S & C America","GUY" +"Asia Pacific","HKG" +"Asia Pacific","HMD" +"S & C America","HND" +"Europe","HRV" +"S & C America","HTI" +"Europe","HUN" +"Asia Pacific","IDN" +"Asia Pacific","IND" +"Europe","IRL" +"Middle East","IRN" +"Middle East","IRQ" +"Europe","ISL" +"Middle East","ISR" +"Europe","ITA" +"S & C America","JAM" +"Middle East","JOR" +"Asia Pacific","JPN" +"CIS","KAZ" +"Africa","KEN" +"CIS","KGZ" +"Asia Pacific","KHM" +"Asia Pacific","KIR" +"S & C America","KNA" +"Asia Pacific","KOR" +"Middle East","KWT" +"Asia Pacific","LAO" +"Middle East","LBN" +"Africa","LBR" +"Africa","LBY" +"S & C America","LCA" +"Asia Pacific","LKA" +"Africa","LSO" +"Europe","LTU" +"Europe","LUX" +"Europe","LVA" +"Asia Pacific","MAC" +"Africa","MAR" +"CIS","MDA" +"Africa","MDG" +"Asia Pacific","MDV" +"Asia Pacific","MHL" +"Europe","MKD" +"Africa","MLI" +"Europe","MLT" +"Asia Pacific","MMR" +"Europe","MNE" +"Asia Pacific","MNG" +"Africa","MOZ" +"Africa","MRT" +"S & C America","MTQ" +"Africa","MUS" +"Africa","MWI" +"Asia Pacific","MYS" +"Africa","NAM" +"Africa","NER" +"Asia Pacific","NFK" +"Africa","NGA" +"S & C America","NIC" +"Asia Pacific","NIU" +"Europe","NLD" +"Europe","NOR" +"Asia Pacific","NPL" +"Asia Pacific","NRU" +"Asia Pacific","NZL" +"Middle East","OMN" +"Asia Pacific","PAK" +"S & C America","PAN" +"S & C America","PER" +"Asia Pacific","PHL" +"Asia Pacific","PLW" +"Asia Pacific","PNG" +"Europe","POL" +"S & C America","PRI" +"Asia Pacific","PRK" +"Europe","PRT" +"S & C America","PRY" +"Asia Pacific","PSE" +"Middle East","QAT" +"Europe","ROU" +"CIS","RUS" +"Africa","RWA" +"Middle East","SAU" +"Africa","SDN" +"Africa","SEN" +"Asia Pacific","SGP" +"Asia Pacific","SLB" +"Africa","SLE" +"S & C America","SLV" +"Africa","SOM" +"Europe","SRB" +"Africa","STP" +"Europe","SUN" +"S & C America","SUR" +"Europe","SVK" +"Europe","SVN" +"Europe","SWE" +"Africa","SWZ" +"Africa","SYC" +"Middle East","SYR" +"S & C America","TCA" +"Africa","TCD" +"Africa","TGO" +"Asia Pacific","THA" +"CIS","TJK" +"Asia Pacific","TKL" +"CIS","TKM" +"Asia Pacific","TLS" +"Asia Pacific","TON" +"S & C America","TTO" +"Africa","TUN" +"Europe","TUR" +"Asia Pacific","TUV" +"Asia Pacific","TWN" +"Africa","TZA" +"Africa","UGA" +"CIS","UKR" +"S & C America","URY" +"CIS","UZB" +"S & C America","VCT" +"S & C America","VEN" +"S & C America","VGB" +"Asia Pacific","VNM" +"Asia Pacific","VUT" +"Asia Pacific","WSM" +"Asia Pacific","YEM" +"Africa","ZAF" +"Africa","ZMB" +"Africa","ZWE" +"North America","USA" +"North America","CAN" +"North America","MEX" diff --git a/inst/extdata/regional/regionmappingBP_Oil_Region_To_DetailReg.csv b/inst/extdata/regional/regionmappingBP_Oil_Region_To_DetailReg.csv new file mode 100755 index 00000000..ddd8878f --- /dev/null +++ b/inst/extdata/regional/regionmappingBP_Oil_Region_To_DetailReg.csv @@ -0,0 +1,28 @@ +BP_Region,BP_Region_Detail,Type +Middle East (ex Saudi Arabia),Iraq,Export +Middle East (ex Saudi Arabia),Kuwait,Export +Middle East (ex Saudi Arabia),United Arab Emirates,Export +Middle East (ex Saudi Arabia),Other Middle East,Export +Asia Pacific (ex Japan),Australasia,Export +Asia Pacific (ex Japan),China,Export +Asia Pacific (ex Japan),India,Export +Asia Pacific (ex Japan),Singapore,Export +Asia Pacific (ex Japan),Other Asia Pacific,Export +Rest of World,East & S Africa,Export +Rest of World,Japan,Export +Rest of World,Canada,Import +Rest of World,Mexico,Import +Rest of World,S & C America,Import +Rest of World,Russian Federation,Import +Rest of World,Other CIS,Import +Rest of World,Iraq,Import +Rest of World,Kuwait,Import +Rest of World,Saudi Arabia,Import +Rest of World,United Arab Emirates,Import +Rest of World,Other Middle East,Import +Rest of World,North Africa,Import +Rest of World,West Africa,Import +Rest of World,East & S Africa,Import +Rest of World,Australasia,Import +Rest of World,Singapore,Import +Rest of World,Other Asia Pacific,Import diff --git a/inst/extdata/regional/regionmappingGAINS.csv b/inst/extdata/regional/regionmappingGAINS.csv new file mode 100755 index 00000000..86437351 --- /dev/null +++ b/inst/extdata/regional/regionmappingGAINS.csv @@ -0,0 +1,251 @@ +CountryName;CountryCode;RegionCode;RegionName;;;; +Aruba ;ABW;4 Rest Central America;Rest Central America;;Aruba;ABW;LAM +Afghanistan ;AFG;25 Rest South Asia;Rest South Asia;;Afghanistan;AFG;OAS +Angola;AGO;8 Western Africa;Western Africa;Added manually by JH;Angola;AGO;AFR +Anguilla ;AIA;4 Rest Central America;Rest Central America;;Anguilla;AIA;LAM +Aland Islands;ALA;11 Western Europe;Western Europe;Added manually by JH;Aland Islands;ALA;EUR +Albania ;ALB;12 Central Europe;Central Europe;;Albania;ALB;ROW +Andorra ;AND;11 Western Europe;Western Europe;;Andorra;AND;ROW +Netherlands Antilles ;ANT;4 Rest Central America;Rest Central America;Removed afterwards in R scripts;;; +United Arab Emirates ;ARE;17 Middle East;Middle East;;United Arab Emirates;ARE;MEA +Argentina;ARG;6 Rest South America;Rest South America;;Argentina;ARG;LAM +Armenia ;ARM;16 Russia +;Russia +;;Armenia;ARM;MEA +American Samoa ;ASM;24 Oceania;Oceania;;American Samoa;ASM;OAS +Antarctica;ATA;;;Set to 0 afterwards in R scripts;Antarctica;ATA;ROW +French Southern Territories ;ATF;24 Oceania;Oceania;;French Southern Territories;ATF;OAS +Antigua and Barbuda ;ATG;4 Rest Central America;Rest Central America;;Antigua and Barbuda;ATG;LAM +Australia ;AUS;24 Oceania;Oceania;;Australia;AUS;ROW +Austria ;AUT;11 Western Europe;Western Europe;;Austria;AUT;EUR +Azerbaijan;AZE;16 Russia +;Russia +;;Azerbaijan;AZE;MEA +Burundi ;BDI;8 Western Africa;Eastern Africa;;Burundi;BDI;AFR +Belgium ;BEL;11 Western Europe;Western Europe;;Belgium;BEL;EUR +Benin ;BEN;8 Western Africa;Western Africa;;Benin;BEN;AFR +Bonaire Sint Eustatius and Saba;BES;4 Rest Central America;Rest Central America;Added manually by JH;Bonaire Sint Eustatius and Saba;BES;LAM +Burkina Faso ;BFA;8 Western Africa;Western Africa;;Burkina Faso;BFA;AFR +Bangladesh;BGD;25 Rest South Asia;Rest South Asia;;Bangladesh;BGD;OAS +Bulgaria ;BGR;12 Central Europe;Central Europe;;Bulgaria;BGR;EUR +Bahrain ;BHR;17 Middle East;Middle East;;Bahrain;BHR;MEA +Bahamas ;BHS;4 Rest Central America;Rest Central America;;Bahamas;BHS;LAM +Bosnia and Herzegovina ;BIH;12 Central Europe;Central Europe;;Bosnia and Herzegovina;BIH;ROW +Saint Barthelemy;BLM;4 Rest Central America;Rest Central America;Added manually by JH;Saint Barthelemy;BLM;LAM +Belarus ;BLR;14 Ukraine +;Ukraine +;;Belarus;BLR;ROW +Belize ;BLZ;4 Rest Central America;Rest Central America;;Belize;BLZ;LAM +Bermuda ;BMU;4 Rest Central America;Rest Central America;;Bermuda;BMU;LAM +Bolivia;BOL;6 Rest South America;Rest South America;;Bolivia Plurinational State of;BOL;LAM +Brazil ;BRA;5 Brazil;Brazil;;Brazil;BRA;LAM +Barbados ;BRB;4 Rest Central America;Rest Central America;;Barbados;BRB;LAM +Brunei Darussalam ;BRN;21 Southeastern Asia;Southeastern Asia;;Brunei Darussalam;BRN;OAS +Bhutan ;BTN;25 Rest South Asia;Rest South Asia;;Bhutan;BTN;OAS +Bouvet Island;BVT;6 Rest South America;Rest South America;;Bouvet Island;BVT;ROW +Botswana ;BWA;8 Western Africa;Rest Southern Africa;;Botswana;BWA;AFR +Central African Republic ;CAF;8 Western Africa;Western Africa;;Central African Republic;CAF;AFR +Canada ;CAN;1 Canada;Canada;;Canada;CAN;ROW +Cocos (Keeling) Islands ;CCK;24 Oceania;Oceania;;Cocos (Keeling) Islands;CCK;OAS +Switzerland;CHE;11 Western Europe;Western Europe;;Switzerland;CHE;ROW +Chile ;CHL;6 Rest South America;Rest South America;;Chile;CHL;LAM +China;CHN;20 China +;China +;;China;CHN;CHN +Côte d'Ivoire ;CIV;8 Western Africa;Western Africa;;Cote d Ivoire;CIV;AFR +Cameroon ;CMR;8 Western Africa;Western Africa;;Cameroon;CMR;AFR +Congo, the Democratic Republic of the;COD;8 Western Africa;Western Africa;;Congo the Democratic Republic of the;COD;AFR +Congo ;COG;8 Western Africa;Western Africa;;Congo;COG;AFR +Cook Islands ;COK;24 Oceania;Oceania;;Cook Islands;COK;OAS +Colombia ;COL;6 Rest South America;Rest South America;;Colombia;COL;LAM +Comoros ;COM;8 Western Africa;Eastern Africa;;Comoros;COM;AFR +Cape Verde ;CPV;8 Western Africa;Western Africa;;Cape Verde;CPV;AFR +Costa Rica ;CRI;4 Rest Central America;Rest Central America;;Costa Rica;CRI;LAM +Cuba ;CUB;4 Rest Central America;Rest Central America;;Cuba;CUB;LAM +Curacao;CUW;4 Rest Central America;Rest Central America;Added manually by JH;Curacao;CUW;LAM +Christmas Island ;CXR;24 Oceania;Oceania;;Christmas Island;CXR;OAS +Cayman Islands ;CYM;4 Rest Central America;Rest Central America;;Cayman Islands;CYM;LAM +Cyprus ;CYP;12 Central Europe;Central Europe;;Cyprus;CYP;EUR +Czech Republic ;CZE;12 Central Europe;Central Europe;;Czech Republic;CZE;EUR +Germany ;DEU;11 Western Europe;Western Europe;;Germany;DEU;EUR +Djibouti ;DJI;8 Western Africa;Eastern Africa;;Djibouti;DJI;AFR +Dominica ;DMA;4 Rest Central America;Rest Central America;;Dominica;DMA;LAM +Denmark ;DNK;11 Western Europe;Western Europe;;Denmark;DNK;EUR +Dominican Republic ;DOM;4 Rest Central America;Rest Central America;;Dominican Republic;DOM;LAM +Algeria ;DZA;7 Northern Africa;Northern Africa;;Algeria;DZA;MEA +Ecuador ;ECU;6 Rest South America;Rest South America;;Ecuador;ECU;LAM +Egypt ;EGY;7 Northern Africa;Northern Africa;;Egypt;EGY;MEA +Eritrea ;ERI;8 Western Africa;Eastern Africa;;Eritrea;ERI;AFR +Western Sahara ;ESH;7 Northern Africa;Northern Africa;;Western Sahara;ESH;MEA +Spain ;ESP;11 Western Europe;Western Europe;;Spain;ESP;EUR +Estonia ;EST;12 Central Europe;Central Europe;;Estonia;EST;EUR +Ethiopia;ETH;8 Western Africa;Eastern Africa;;Ethiopia;ETH;AFR +Finland ;FIN;11 Western Europe;Western Europe;;Finland;FIN;EUR +Fiji ;FJI;24 Oceania;Oceania;;Fiji;FJI;OAS +Falklands Islands (Malvinas);FLK;6 Rest South America;Rest South America;;Falkland Islands (Malvinas);FLK;LAM +France;FRA;11 Western Europe;Western Europe;;France;FRA;EUR +Faroe Islands;FRO;11 Western Europe;Western Europe;;Faroe Islands;FRO;EUR +Micronesia, Federated States of;FSM;24 Oceania;Oceania;;Micronesia Federated States of;FSM;OAS +Gabon;GAB;8 Western Africa;Western Africa;;Gabon;GAB;AFR +United Kingdom;GBR;11 Western Europe;Western Europe;;United Kingdom;GBR;EUR +Georgia ;GEO;16 Russia +;Russia +;;Georgia;GEO;MEA +Guernsey;GGY;11 Western Europe;Western Europe;Added manually by JH;Guernsey;GGY;ROW +Ghana ;GHA;8 Western Africa;Western Africa;;Ghana;GHA;AFR +Gibraltar ;GIB;11 Western Europe;Western Europe;;Gibraltar;GIB;EUR +Guinea ;GIN;8 Western Africa;Western Africa;;Guinea;GIN;AFR +Guadeloupe ;GLP;4 Rest Central America;Rest Central America;;Guadeloupe;GLP;LAM +Gambia ;GMB;8 Western Africa;Western Africa;;Gambia;GMB;AFR +Guinea-Bissau ;GNB;8 Western Africa;Western Africa;;Guinea-Bissau;GNB;AFR +Equatorial Guinea ;GNQ;8 Western Africa;Western Africa;;Equatorial Guinea;GNQ;AFR +Greece;GRC;11 Western Europe;Western Europe;;Greece;GRC;EUR +Grenada ;GRD;4 Rest Central America;Rest Central America;;Grenada;GRD;LAM +Greenland;GRL;11 Western Europe;Western Europe;Added manually by JH;Greenland;GRL;EUR +Guatemala ;GTM;4 Rest Central America;Rest Central America;;Guatemala;GTM;LAM +French Guiana ;GUF;4 Rest Central America;Rest South America;;French Guiana;GUF;LAM +Guam ;GUM;24 Oceania;Oceania;;Guam;GUM;OAS +Guyana ;GUY;4 Rest Central America;Rest South America;;Guyana;GUY;LAM +Hong Kong ;HKG;20 China +;China +;;Hong Kong;HKG;CHN +Heard Island and McDonald Islands ;HMD;24 Oceania;Oceania;;Heard Island and McDonald Islands;HMD;ROW +Honduras ;HND;4 Rest Central America;Rest Central America;;Honduras;HND;LAM +Croatia ;HRV;12 Central Europe;Central Europe;;Croatia;HRV;ROW +Haiti ;HTI;4 Rest Central America;Rest Central America;;Haiti;HTI;LAM +Hungary ;HUN;12 Central Europe;Central Europe;;Hungary;HUN;EUR +Indonesia ;IDN;22 Indonesia +;Indonesia +;;Indonesia;IDN;OAS +Isle of Man;IMN;11 Western Europe;Western Europe;Added manually by JH;Isle of Man;IMN;EUR +India ;IND;18 India ;India ;;India;IND;IND +British Indian Ocean Territory;IOT;25 Rest South Asia;Rest South Asia;;British Indian Ocean Territory;IOT;OAS +Ireland ;IRL;11 Western Europe;Western Europe;;Ireland;IRL;EUR +Iran, Islamic Republic of;IRN;17 Middle East;Middle East;;Iran Islamic Republic of;IRN;MEA +Iraq ;IRQ;17 Middle East;Middle East;;Iraq;IRQ;MEA +Iceland ;ISL;11 Western Europe;Western Europe;;Iceland;ISL;ROW +Israel ;ISR;17 Middle East;Middle East;;Israel;ISR;MEA +Italy;ITA;11 Western Europe;Western Europe;;Italy;ITA;EUR +Jamaica ;JAM;4 Rest Central America;Rest Central America;;Jamaica;JAM;LAM +Jersey;JEY;11 Western Europe;Western Europe;Added manually by JH;Jersey;JEY;EUR +Jordan ;JOR;17 Middle East;Middle East;;Jordan;JOR;MEA +Japan ;JPN;23 Japan;Japan;;Japan;JPN;JPN +Kazakstan ;KAZ;15 Asia-Stan;Asia-Stan;;Kazakhstan;KAZ;MEA +Kenya ;KEN;8 Western Africa;Eastern Africa;;Kenya;KEN;AFR +Kyrgyzstan;KGZ;15 Asia-Stan;Asia-Stan;;Kyrgyzstan;KGZ;MEA +Cambodia ;KHM;21 Southeastern Asia;Southeastern Asia;;Cambodia;KHM;OAS +Kiribati ;KIR;24 Oceania;Oceania;;Kiribati;KIR;OAS +Saint Kitts and Nevis ;KNA;4 Rest Central America;Rest Central America;;Saint Kitts and Nevis;KNA;LAM +Korea, Republic of;KOR;19 Korea;Korea;;Korea Republic of;KOR;OAS +Kuwait ;KWT;17 Middle East;Middle East;;Kuwait;KWT;MEA +Lao People's Democratic Republic;LAO;21 Southeastern Asia;Southeastern Asia;;Lao People's Democratic Republic;LAO;OAS +Lebanon;LBN;17 Middle East;Middle East;;Lebanon;LBN;MEA +Liberia ;LBR;8 Western Africa;Western Africa;;Liberia;LBR;AFR +Libyan Arab Jamahiriya;LBY;7 Northern Africa;Northern Africa;;Libya;LBY;MEA +Saint Lucia ;LCA;4 Rest Central America;Rest Central America;;Saint Lucia;LCA;LAM +Liechtenstein ;LIE;11 Western Europe;Western Europe;;Liechtenstein;LIE;ROW +Sri Lanka ;LKA;25 Rest South Asia;Rest South Asia;;Sri Lanka;LKA;OAS +Lesotho ;LSO;8 Western Africa;Rest Southern Africa;;Lesotho;LSO;AFR +Lithuania ;LTU;12 Central Europe;Central Europe;;Lithuania;LTU;EUR +Luxembourg ;LUX;11 Western Europe;Western Europe;;Luxembourg;LUX;EUR +Latvia ;LVA;12 Central Europe;Central Europe;;Latvia;LVA;EUR +Macau ;MAC;20 China +;China +;;Macao;MAC;CHN +Saint Martin (French part);MAF;4 Rest Central America;Rest Central America;Added manually by JH;Saint Martin (French part);MAF;ROW +Morocco ;MAR;7 Northern Africa;Northern Africa;;Morocco;MAR;MEA +Monaco ;MCO;11 Western Europe;Western Europe;;Monaco;MCO;ROW +Moldova, Republic of;MDA;14 Ukraine +;Ukraine +;;Moldova Republic of;MDA;ROW +Madagascar ;MDG;8 Western Africa;Eastern Africa;;Madagascar;MDG;AFR +Maldives ;MDV;25 Rest South Asia;Rest South Asia;;Maldives;MDV;OAS +Mexico;MEX;3 Mexico;Mexico;;Mexico;MEX;LAM +Marshall Islands ;MHL;24 Oceania;Oceania;;Marshall Islands;MHL;OAS +Macedonia, the former Yugoslav Republic of;MKD;12 Central Europe;Central Europe;;Macedonia the former Yugoslav Republic of;MKD;ROW +Mali ;MLI;8 Western Africa;Western Africa;;Mali;MLI;AFR +Malta ;MLT;12 Central Europe;Central Europe;;Malta;MLT;EUR +Myanmar ;MMR;21 Southeastern Asia;Southeastern Asia;;Myanmar;MMR;OAS +Yugoslavia ;MNE;12 Central Europe;Central Europe;;Montenegro;MNE;ROW +Mongolia ;MNG;20 China +;China +;;Mongolia;MNG;OAS +Northern Mariana Islands ;MNP;24 Oceania;Oceania;;Northern Mariana Islands;MNP;OAS +Mozambique ;MOZ;8 Western Africa;Rest Southern Africa;;Mozambique;MOZ;AFR +Mauritania ;MRT;8 Western Africa;Western Africa;;Mauritania;MRT;AFR +Montserrat ;MSR;4 Rest Central America;Rest Central America;;Montserrat;MSR;LAM +Martinique ;MTQ;4 Rest Central America;Rest Central America;;Martinique;MTQ;LAM +Mauritius ;MUS;8 Western Africa;Eastern Africa;;Mauritius;MUS;AFR +Malawi ;MWI;8 Western Africa;Rest Southern Africa;;Malawi;MWI;AFR +Malaysia ;MYS;21 Southeastern Asia;Southeastern Asia;;Malaysia;MYS;OAS +Mayotte ;MYT;8 Western Africa;Eastern Africa;;Mayotte;MYT;AFR +Namibia ;NAM;8 Western Africa;Rest Southern Africa;;Namibia;NAM;AFR +New Caledonia ;NCL;24 Oceania;Oceania;;New Caledonia;NCL;OAS +Niger ;NER;8 Western Africa;Western Africa;;Niger;NER;AFR +Norfolk Island ;NFK;24 Oceania;Oceania;;Norfolk Island;NFK;OAS +Nigeria ;NGA;8 Western Africa;Western Africa;;Nigeria;NGA;AFR +Nicaragua ;NIC;4 Rest Central America;Rest Central America;;Nicaragua;NIC;LAM +Niue ;NIU;24 Oceania;Oceania;;Niue;NIU;OAS +Netherlands ;NLD;11 Western Europe;Western Europe;;Netherlands;NLD;EUR +Norway ;NOR;11 Western Europe;Western Europe;;Norway;NOR;ROW +Nepal ;NPL;25 Rest South Asia;Rest South Asia;;Nepal;NPL;OAS +Nauru ;NRU;24 Oceania;Oceania;;Nauru;NRU;ROW +New Zealand ;NZL;24 Oceania;Oceania;;New Zealand;NZL;ROW +Oman ;OMN;17 Middle East;Middle East;;Oman;OMN;MEA +Pakistan ;PAK;25 Rest South Asia;Rest South Asia;;Pakistan;PAK;OAS +Panama ;PAN;4 Rest Central America;Rest Central America;;Panama;PAN;LAM +Pitcairn ;PCN;24 Oceania;Oceania;;Pitcairn;PCN;OAS +Peru ;PER;6 Rest South America;Rest South America;;Peru;PER;LAM +Philippines ;PHL;21 Southeastern Asia;Southeastern Asia;;Philippines;PHL;OAS +Palau ;PLW;24 Oceania;Oceania;;Palau;PLW;OAS +Papua New Guinea ;PNG;22 Indonesia +;Indonesia +;;Papua New Guinea;PNG;OAS +Poland ;POL;12 Central Europe;Central Europe;;Poland;POL;EUR +Puerto Rico ;PRI;4 Rest Central America;Rest Central America;;Puerto Rico;PRI;LAM +Korea, Democratic People's Republic of;PRK;19 Korea;Korea;;Korea Democratic People's Republic of;PRK;OAS +Portugal;PRT;11 Western Europe;Western Europe;;Portugal;PRT;EUR +Paraguay ;PRY;6 Rest South America;Rest South America;;Paraguay;PRY;LAM +Palestine, State of;PSE;17 Middle East;Middle East;Added manually by JH;Palestine State of;PSE;MEA +French Polynesia;PYF;24 Oceania;Oceania;;French Polynesia;PYF;OAS +Qatar ;QAT;17 Middle East;Middle East;;Qatar;QAT;MEA +Réunion ;REU;8 Western Africa;Eastern Africa;;Reunion;REU;AFR +Romania ;ROU;12 Central Europe;Central Europe;;Romania;ROU;EUR +Russian Federation ;RUS;16 Russia +;Russia +;;Russian Federation;RUS;RUS +Rwanda;RWA;8 Western Africa;Eastern Africa;;Rwanda;RWA;AFR +Saudi Arabia ;SAU;17 Middle East;Middle East;;Saudi Arabia;SAU;MEA +Sudan ;SDN;7 Northern Africa;Eastern Africa;;Sudan;SDN;AFR +Senegal ;SEN;8 Western Africa;Western Africa;;Senegal;SEN;AFR +Singapore ;SGP;21 Southeastern Asia;Southeastern Asia;;Singapore;SGP;OAS +South Georgia and the South Sandwich Islands;SGS;6 Rest South America;Rest South America;;South Georgia and the South Sandwich Islands;SGS;ROW +Saint Helena ;SHN;8 Western Africa;Western Africa;;Saint Helena Ascension and Tristan da Cunha;SHN;AFR +Svalbard and Jan Mayen ;SJM;11 Western Europe;Western Europe;;Svalbard and Jan Mayen;SJM;ROW +Solomon Islands ;SLB;24 Oceania;Oceania;;Solomon Islands;SLB;OAS +Sierra Leone ;SLE;8 Western Africa;Western Africa;;Sierra Leone;SLE;AFR +El Salvador ;SLV;4 Rest Central America;Rest Central America;;El Salvador;SLV;LAM +San Marino ;SMR;11 Western Europe;Western Europe;;San Marino;SMR;ROW +Somalia;SOM;8 Western Africa;Eastern Africa;;Somalia;SOM;AFR +Saint Pierre and Miquelon ;SPM;2 USA;USA;;Saint Pierre and Miquelon;SPM;ROW +Yugoslavia ;SRB;12 Central Europe;Central Europe;;Serbia;SRB;ROW +South Sudan;SSD;8 Western Africa;Western Africa;Added manually by JH;South Sudan;SSD;AFR +Sao Tome and Principe ;STP;8 Western Africa;Western Africa;;Sao Tome and Principe;STP;AFR +Suriname ;SUR;4 Rest Central America;Rest Central America;;Suriname;SUR;LAM +Slovakia;SVK;12 Central Europe;Central Europe;;Slovakia;SVK;EUR +Slovenia ;SVN;12 Central Europe;Central Europe;;Slovenia;SVN;EUR +Sweden ;SWE;11 Western Europe;Western Europe;;Sweden;SWE;EUR +Swaziland ;SWZ;8 Western Africa;Rest Southern Africa;;Swaziland;SWZ;AFR +Sint Maarten (Dutch part);SXM;4 Rest Central America;Rest Central America;Added manually by JH;Sint Maarten (Dutch part);SXM;LAM +Seychelles ;SYC;8 Western Africa;Eastern Africa;;Seychelles;SYC;AFR +Syrian Arab Republic;SYR;17 Middle East;Middle East;;Syrian Arab Republic;SYR;MEA +Turks and Caicos Islands ;TCA;4 Rest Central America;Rest Central America;;Turks and Caicos Islands;TCA;LAM +Chad ;TCD;8 Western Africa;Western Africa;;Chad;TCD;AFR +Togo;TGO;8 Western Africa;Western Africa;;Togo;TGO;AFR +Thailand ;THA;21 Southeastern Asia;Southeastern Asia;;Thailand;THA;OAS +Tajikistan ;TJK;15 Asia-Stan;Asia-Stan;;Tajikistan;TJK;MEA +Tokelau ;TKL;24 Oceania;Oceania;;Tokelau;TKL;OAS +Turkmenistan ;TKM;15 Asia-Stan;Asia-Stan;;Turkmenistan;TKM;MEA +East Timor;TLS;22 Indonesia +;Indonesia +;;Timor-Leste;TLS;OAS +Tonga ;TON;24 Oceania;Oceania;;Tonga;TON;OAS +Trinidad and Tobago ;TTO;4 Rest Central America;Rest Central America;;Trinidad and Tobago;TTO;LAM +Tunisia ;TUN;7 Northern Africa;Northern Africa;;Tunisia;TUN;MEA +Turkey ;TUR;13 Turkey;Turkey;;Turkey;TUR;ROW +Tuvalu ;TUV;24 Oceania;Oceania;;Tuvalu;TUV;OAS +Taiwan, Province of China ;TWN;20 China +;China +;;Taiwan Province of China;TWN;OAS +Tanzania, United Republic of;TZA;8 Western Africa;Rest Southern Africa;;Tanzania United Republic of;TZA;AFR +Uganda ;UGA;8 Western Africa;Eastern Africa;;Uganda;UGA;AFR +Ukraine ;UKR;14 Ukraine +;Ukraine +;;Ukraine;UKR;ROW +United States Minor Outlying Islands ;UMI;2 USA;USA;;United States Minor Outlying Islands;UMI;OAS +Uruguay ;URY;6 Rest South America;Rest South America;;Uruguay;URY;LAM +United States;USA;2 USA;USA;;United States;USA;USA +Uzbekistan ;UZB;15 Asia-Stan;Asia-Stan;;Uzbekistan;UZB;MEA +Holy See (Vatican City State);VAT;11 Western Europe;Western Europe;;Holy See (Vatican City State);VAT;ROW +Saint Vincent and the Grenadines;VCT;4 Rest Central America;Rest Central America;;Saint Vincent and the Grenadines;VCT;LAM +Venezuela ;VEN;6 Rest South America;Rest South America;;Venezuela Bolivarian Republic of;VEN;LAM +Virgin Islands, British ;VGB;4 Rest Central America;Rest Central America;;Virgin Islands British;VGB;LAM +Virgin Islands, U.S.;VIR;4 Rest Central America;Rest Central America;;Virgin Islands U.S.;VIR;LAM +Viet Nam ;VNM;21 Southeastern Asia;Southeastern Asia;;Viet Nam;VNM;OAS +Vanuatu ;VUT;24 Oceania;Oceania;;Vanuatu;VUT;OAS +Wallis and Futuna;WLF;24 Oceania;Oceania;;Wallis and Futuna;WLF;OAS +Samoa ;WSM;24 Oceania;Oceania;;Samoa;WSM;OAS +Yemen ;YEM;17 Middle East;Middle East;;Yemen;YEM;MEA +South Africa ;ZAF;10 South Africa;South Africa;;South Africa;ZAF;ROW +Zambia ;ZMB;8 Western Africa;Rest Southern Africa;;Zambia;ZMB;AFR +Zimbabwe ;ZWE;8 Western Africa;Rest Southern Africa;;Zimbabwe;ZWE;AFR diff --git a/inst/extdata/regional/regionmapping_IEAWorldEnergyOutlook.csv b/inst/extdata/regional/regionmapping_IEAWorldEnergyOutlook.csv new file mode 100755 index 00000000..eae9f656 --- /dev/null +++ b/inst/extdata/regional/regionmapping_IEAWorldEnergyOutlook.csv @@ -0,0 +1,212 @@ +"Region_name";"ISO3.code" +"Central and South America";"ABW" +"Asia Pacific";"AFG" +"Africa";"AGO" +"Europe";"ALB" +"Middle East";"ARE" +"Central and South America";"ARG" +"Asia Pacific";"ATA" +"Central and South America";"ATG" +"Asia Pacific";"AUS" +"Europe";"AUT" +"Africa";"BDI" +"Europe";"BEL" +"Africa";"BEN" +"Africa";"BFA" +"Asia Pacific";"BGD" +"Europe";"BGR" +"Middle East";"BHR" +"Central and South America";"BHS" +"Europe";"BIH" +"Central and South America";"BLM" +"Central and South America";"BLZ" +"Central and South America";"BOL" +"Central and South America";"BRA" +"Central and South America";"BRB" +"Asia Pacific";"BRN" +"Asia Pacific";"BTN" +"Africa";"BWA" +"Africa";"CAF" +"Asia Pacific";"CCK" +"Europe";"CHE" +"Central and South America";"CHL" +"Asia Pacific";"CHN" +"Africa";"CIV" +"Africa";"CMR" +"Africa";"COD" +"Africa";"COG" +"Asia Pacific";"COK" +"Central and South America";"COL" +"Africa";"COM" +"Africa";"CPV" +"Central and South America";"CRI" +"Central and South America";"CUB" +"Asia Pacific";"CXR" +"Central and South America";"CYM" +"Europe";"CYP" +"Europe";"CZE" +"Europe";"DEU" +"Africa";"DJI" +"Central and South America";"DMA" +"Europe";"DNK" +"Central and South America";"DOM" +"Africa";"DZA" +"Central and South America";"ECU" +"Africa";"EGY" +"Africa";"ERI" +"Europe";"ESP" +"Europe";"EST" +"Africa";"ETH" +"Europe";"FIN" +"Asia Pacific";"FJI" +"Europe";"FRA" +"Asia Pacific";"FSM" +"Africa";"GAB" +"Europe";"GBR" +"Europe";"GEO" +"Africa";"GHA" +"Europe";"GIB" +"Africa";"GIN" +"Central and South America";"GLP" +"Africa";"GMB" +"Africa";"GNB" +"Africa";"GNQ" +"Europe";"GRC" +"Central and South America";"GRD" +"Central and South America";"GTM" +"Central and South America";"GUF" +"Central and South America";"GUY" +"Asia Pacific";"HKG" +"Asia Pacific";"HMD" +"Central and South America";"HND" +"Europe";"HRV" +"Central and South America";"HTI" +"Europe";"HUN" +"Asia Pacific";"IDN" +"Asia Pacific";"IND" +"Europe";"IRL" +"Middle East";"IRN" +"Middle East";"IRQ" +"Europe";"ISL" +"Middle East";"ISR" +"Europe";"ITA" +"Central and South America";"JAM" +"Middle East";"JOR" +"Asia Pacific";"JPN" +"Africa";"KEN" +"Asia Pacific";"KHM" +"Asia Pacific";"KIR" +"Central and South America";"KNA" +"Asia Pacific";"KOR" +"Middle East";"KWT" +"Asia Pacific";"LAO" +"Middle East";"LBN" +"Africa";"LBR" +"Africa";"LBY" +"Central and South America";"LCA" +"Asia Pacific";"LKA" +"Africa";"LSO" +"Europe";"LTU" +"Europe";"LUX" +"Europe";"LVA" +"Asia Pacific";"MAC" +"Africa";"MAR" +"Africa";"MDG" +"Asia Pacific";"MDV" +"Asia Pacific";"MHL" +"Europe";"MKD" +"Africa";"MLI" +"Europe";"MLT" +"Asia Pacific";"MMR" +"Europe";"MNE" +"Asia Pacific";"MNG" +"Africa";"MOZ" +"Africa";"MRT" +"Central and South America";"MTQ" +"Africa";"MUS" +"Africa";"MWI" +"Asia Pacific";"MYS" +"Africa";"NAM" +"Africa";"NER" +"Asia Pacific";"NFK" +"Africa";"NGA" +"Central and South America";"NIC" +"Asia Pacific";"NIU" +"Europe";"NLD" +"Europe";"NOR" +"Asia Pacific";"NPL" +"Asia Pacific";"NRU" +"Asia Pacific";"NZL" +"Middle East";"OMN" +"Asia Pacific";"PAK" +"Central and South America";"PAN" +"Central and South America";"PER" +"Asia Pacific";"PHL" +"Asia Pacific";"PLW" +"Asia Pacific";"PNG" +"Europe";"POL" +"Central and South America";"PRI" +"Asia Pacific";"PRK" +"Europe";"PRT" +"Central and South America";"PRY" +"Asia Pacific";"PSE" +"Middle East";"QAT" +"Europe";"ROU" +"Africa";"RWA" +"Middle East";"SAU" +"Africa";"SDN" +"Africa";"SEN" +"Asia Pacific";"SGP" +"Asia Pacific";"SLB" +"Africa";"SLE" +"Central and South America";"SLV" +"Africa";"SOM" +"Europe";"SRB" +"Africa";"STP" +"Europe";"SUN" +"Central and South America";"SUR" +"Europe";"SVK" +"Europe";"SVN" +"Europe";"SWE" +"Africa";"SWZ" +"Africa";"SYC" +"Middle East";"SYR" +"Central and South America";"TCA" +"Africa";"TCD" +"Africa";"TGO" +"Asia Pacific";"THA" +"Asia Pacific";"TKL" +"Asia Pacific";"TLS" +"Asia Pacific";"TON" +"Central and South America";"TTO" +"Africa";"TUN" +"Europe";"TUR" +"Asia Pacific";"TUV" +"Asia Pacific";"TWN" +"Africa";"TZA" +"Africa";"UGA" +"Central and South America";"URY" +"Central and South America";"VCT" +"Central and South America";"VEN" +"Central and South America";"VGB" +"Asia Pacific";"VNM" +"Asia Pacific";"VUT" +"Asia Pacific";"WSM" +"Asia Pacific";"YEM" +"Africa";"ZAF" +"Africa";"ZMB" +"Africa";"ZWE" +"North America";"USA" +"North America";"CAN" +"North America";"MEX" +"Eurasia";"RUS" +"Eurasia";"ARM" +"Eurasia";"MDA" +"Eurasia";"AZE" +"Eurasia";"TJK" +"Eurasia";"BLR" +"Eurasia";"KAZ" +"Eurasia";"TKM" +"Eurasia";"UKR" +"Eurasia";"KGZ" +"Eurasia";"UZB" diff --git a/inst/extdata/reportingVariables/Mapping_BP.csv b/inst/extdata/reportingVariables/Mapping_BP.csv new file mode 100755 index 00000000..847d6d56 --- /dev/null +++ b/inst/extdata/reportingVariables/Mapping_BP.csv @@ -0,0 +1,43 @@ +variable,unit,Factor,Unit_REMIND,REMIND,conversion remarks,comment +Generation|Wind,TWh,0.0036,EJ/yr,SE|Electricity|Wind,, +Generation|Solar,TWh,0.0036,EJ/yr,SE|Electricity|Solar,, +Generation|Hydro,TWh,0.0036,EJ/yr,SE|Electricity|Hydro,, +Generation|Geo_biomass,TWh,0.0036,EJ/yr,,, +Generation|Nuclear,TWh,0.0036,EJ/yr,SE|Electricity|Nuclear,, +Generation|Electricity,TWh,0.0036,EJ/yr,SE|Electricity,, +Generation|Electricity|Gas,TWh,0.0036,EJ/yr,SE|Electricity|Gas,, +Generation|Electricity|Oil,TWh,0.0036,EJ/yr,SE|Electricity|Oil,, +Generation|Electricity|Coal,TWh,0.0036,EJ/yr,SE|Electricity|Coal,, +Capacity|Solar,MW,0.001,GW,Cap|Electricity|Solar,, +Capacity|Wind,MW,0.001,GW,Cap|Electricity|Wind,, +Oil Production,million t,,,,, +Coal Production,EJ,,,,, +Coal Production,t,,,,, +Gas Production,EJ,,,,, +Primary Energy Consumption,EJ,1,EJ/yr,PE,, +Liquids Consumption,kb/d,0.002233435,EJ/yr,SE|Liquids,"Source: 1 barrel of oil equivalent (boe) = 6.119 million kJ +conversion: 6.119E-6 * 365", +Oil Consumption,EJ,1,EJ/yr,PE|Oil,, +Gas Consumption,EJ,1,EJ/yr,PE|Gas,, +Coal Consumption,EJ,1,EJ/yr,PE|Coal,, +Solar Consumption,EJ,1,EJ/yr,PE|Solar,, +Wind Consumption,EJ,1,EJ/yr,PE|Wind,, +Nuclear Consumption,EJ,1,EJ/yr,PE|Nuclear,, +Hydro Consumption,EJ,1,EJ/yr,PE|Hydro,, +Trade|Export|Oil,kb/d,0.002233435,EJ/yr,Trade|Exports|Oil,"Source: 1 barrel of oil equivalent (boe) = 6.119 million kJ +conversion: 6.119E-6 * 365", +Trade|Import|Oil,kb/d,0.002233435,EJ/yr,Trade|Imports|Oil,, +Net Trade|Oil,kb/d,0.002233435,EJ/yr,Trade|Oil,, +Trade|Export|Gas,bcm,0.036,EJ/yr,Trade|Exports|Gas,"Source: 1 billion cubic metres NG = 36 PJ NG +conversion: 36/1000", +Trade|Import|Gas,bcm,0.036,EJ/yr,Trade|Imports|Gas,, +Net Trade|Gas,bcm,0.036,EJ/yr,Trade|Gas,, +Trade|Export|Coal,EJ,1,EJ/yr,Trade|Exports|Coal,, +Trade|Import|Coal,EJ,1,EJ/yr,Trade|Imports|Coal,, +Net Trade|Coal,EJ,1,EJ/yr,Trade|Coal,, +Price|Crude Oil,$2023/bbl,0.12256904722994,US$2005/GJ,Price|Primary Energy|Oil,"Source: $2020 → $2005 = 0.75 (online) +1 barrel of oil equivalent (boe) = 6.119 million kJ +Conversion: 0.75 / 6.119", +Price|Natural Gas,$/mbtu,1.05,US$2005/GJ,Price|Primary Energy|Gas,source: 1 trillion British thermal units = 1.050 petajoules NG, +Price|Coal,$/t,0.025,US$2005/GJ,Price|Primary Energy|Coal,source: 1EJ = 40 million tonnes of hard coal, +Emi|CO2,Mt CO2,1,Mt CO2/yr,Emi|CO2|Energy,, diff --git a/inst/extdata/reportingVariables/Mapping_EuropeanEnergyDatasheets.csv b/inst/extdata/reportingVariables/Mapping_EuropeanEnergyDatasheets.csv index 1974b4bb..064f9f7c 100755 --- a/inst/extdata/reportingVariables/Mapping_EuropeanEnergyDatasheets.csv +++ b/inst/extdata/reportingVariables/Mapping_EuropeanEnergyDatasheets.csv @@ -51,8 +51,12 @@ "Energy Balance|Gross available energy";"Mtoe";; "Energy Balance|International maritime bunkers";"Mtoe";"FE (EJ/yr)";0.041868 "Energy Balance|International maritime bunkers";"Mtoe";"FE|Transport (EJ/yr)";0.041868 +"Energy Balance|International maritime bunkers";"Mtoe";"FE|Transport|Bunkers (EJ/yr)";0.041868 +"Energy Balance|International maritime bunkers";"Mtoe";"FE|Transport|Freight|International Shipping (EJ/yr)";0.041868 "Energy Balance|International maritime bunkers|of which petroleum products";"Mtoe";"FE|Liquids (EJ/yr)";0.041868 -"Energy Balance|International maritime bunkers|of which petroleum products";"Mtoe";"FE|Transport|Liquids (EJ/yr)";0.041868 +"Energy Balance|International maritime bunkers|of which petroleum products";"Mtoe";"FE|Transport|w/o Bunkers|Liquids (EJ/yr)";-0.041868 +"Energy Balance|International maritime bunkers|of which petroleum products";"Mtoe";"FE|Transport|Bunkers|Liquids (EJ/yr)";0.041868 +"Energy Balance|International maritime bunkers|of which petroleum products";"Mtoe";"FE|Transport|Freight|International Shipping|Liquids (EJ/yr)";0.041868 "Energy Balance|Gross inland consumption";"Mtoe";"PE (EJ/yr)";0.041868 "Energy Balance|Gross inland consumption|Solid fossil fuels";"Mtoe";; "Energy Balance|Gross inland consumption|Solid fossil fuels|of which hard coal";"Mtoe";"PE|Coal (EJ/yr)";0.041868 @@ -78,8 +82,12 @@ "Energy Balance|Gross inland consumption|Waste, non-renewable";"Mtoe";; "Energy Balance|International aviation";"Mtoe";"FE (EJ/yr)";0.041868 "Energy Balance|International aviation";"Mtoe";"FE|Transport (EJ/yr)";0.041868 +"Energy Balance|International aviation";"Mtoe";"FE|Transport|Bunkers (EJ/yr)";0.041868 +"Energy Balance|International aviation";"Mtoe";"FE|Transport|Pass|Aviation|International (EJ/yr)";0.041868 +"Energy Balance|International aviation|of which petroleum products";"Mtoe";"FE|Transport|Bunkers|Liquids (EJ/yr)";0.041868 +"Energy Balance|International aviation|of which petroleum products";"Mtoe";"FE|Transport|Pass|Aviation|International|Liquids (EJ/yr)";0.041868 "Energy Balance|International aviation|of which petroleum products";"Mtoe";"FE|Liquids (EJ/yr)";0.041868 -"Energy Balance|International aviation|of which petroleum products";"Mtoe";"FE|Transport|Liquids (EJ/yr)";0.041868 +"Energy Balance|International aviation|of which petroleum products";"Mtoe";"FE|Transport|w/o Bunkers|Liquids (EJ/yr)";-0.041868 "Energy Balance|Total energy supply";"Mtoe";; "Energy Balance|Total energy supply|Solid fossil fuels";"Mtoe";; "Energy Balance|Total energy supply|Solid fossil fuels|of which hard coal";"Mtoe";; @@ -151,9 +159,9 @@ "Energy Balance|Transformation Input|Refineries, Petroleum and sub-products";"Mtoe";; "Energy Balance|Transformation Input|Other transformation input";"Mtoe";; "Energy Balance|Transformation Output";"Mtoe";; -"Energy Balance|Transformation Output|Solid fossil fuels";"Mtoe";"SE|Solids (EJ/yr)";0.041868 +"Energy Balance|Transformation Output|Solid fossil fuels";"Mtoe";; "Energy Balance|Transformation Output|Manufactured gases";"Mtoe";; -"Energy Balance|Transformation Output|Peat and peat products";"Mtoe";"SE|Solids (EJ/yr)";0.041868 +"Energy Balance|Transformation Output|Peat and peat products";"Mtoe";; "Energy Balance|Transformation Output|Oil and petroleum products";"Mtoe";; "Energy Balance|Transformation Output|Natural gas";"Mtoe";; "Energy Balance|Transformation Output|Renewables and biofuels";"Mtoe";; @@ -183,10 +191,16 @@ "Energy Balance|Final non-energy consumption";"Mtoe";"FE (EJ/yr)";0.041868 "Energy Balance|Final non-energy consumption";"Mtoe";"FE|Liquids (EJ/yr)";0.041868 "Energy Balance|Final non-energy consumption";"Mtoe";"FE|Industry (EJ/yr)";0.041868 +"Energy Balance|Final non-energy consumption";"Mtoe";"FE|Non-energy Use|Industry (EJ/yr)";0.041868 "Energy Balance|Final energy consumption";"Mtoe";"FE (EJ/yr)";0.041868 "Energy Balance|Final energy consumption|Solid fossil fuels";"Mtoe";"FE|Solids (EJ/yr)";0.041868 +"Energy Balance|Final energy consumption|Solid fossil fuels";"Mtoe";"SE|Solids (EJ/yr)";0.041868 +"Energy Balance|Final energy consumption|Solid fossil fuels";"Mtoe";"FE|Solids|Fossil (EJ/yr)";0.041868 +"Energy Balance|Final energy consumption|Solid fossil fuels";"Mtoe";"SE|Solids|Fossil (EJ/yr)";0.041868 "Energy Balance|Final energy consumption|Solid fossil fuels|of which hard coal";"Mtoe";"FE|Solids|Coal (EJ/yr)";0.041868 +"Energy Balance|Final energy consumption|Solid fossil fuels|of which hard coal";"Mtoe";"SE|Solids|Coal (EJ/yr)";0.041868 "Energy Balance|Final energy consumption|Solid fossil fuels|of which brown coal";"Mtoe";"FE|Solids|Coal (EJ/yr)";0.041868 +"Energy Balance|Final energy consumption|Solid fossil fuels|of which brown coal";"Mtoe";"SE|Solids|Coal (EJ/yr)";0.041868 "Energy Balance|Final energy consumption|Manufactured gases";"Mtoe";"FE|Gases (EJ/yr)";0.041868 "Energy Balance|Final energy consumption|Manufactured gases";"Mtoe";"FE|Gases|Fossil (EJ/yr)";0.041868 "Energy Balance|Final energy consumption|Peat and peat products";"Mtoe";"FE|Solids (EJ/yr)";0.041868 @@ -204,6 +218,8 @@ "Energy Balance|Final energy consumption|Renewables and biofuels|Geothermal";"Mtoe";"FE|Heat|Geothermal (EJ/yr)";0.041868 "Energy Balance|Final energy consumption|Renewables and biofuels|Solid biofuels and renewable waste";"Mtoe";"FE|Solids (EJ/yr)";0.041868 "Energy Balance|Final energy consumption|Renewables and biofuels|Solid biofuels and renewable waste";"Mtoe";"FE|Solids|Biomass (EJ/yr)";0.041868 +"Energy Balance|Final energy consumption|Renewables and biofuels|Solid biofuels and renewable waste";"Mtoe";"SE|Solids (EJ/yr)";0.041868 +"Energy Balance|Final energy consumption|Renewables and biofuels|Solid biofuels and renewable waste";"Mtoe";"SE|Solids|Biomass (EJ/yr)";0.041868 "Energy Balance|Final energy consumption|Renewables and biofuels|Biogases";"Mtoe";"FE|Gases (EJ/yr)";0.041868 "Energy Balance|Final energy consumption|Renewables and biofuels|Biogases";"Mtoe";"FE|Gases|Biomass (EJ/yr)";0.041868 "Energy Balance|Final energy consumption|Renewables and biofuels|Liquid biofuels";"Mtoe";"FE|Liquids (EJ/yr)";0.041868 @@ -212,9 +228,13 @@ "Energy Balance|Final energy consumption|Renewables and biofuels|Ambient heat, heat pumps";"Mtoe";"FE|Heat|Heat Pumps (EJ/yr)";0.041868 "Energy Balance|Final energy consumption|Waste, non-renewable";"Mtoe";"FE|Solids (EJ/yr)";0.041868 "Energy Balance|Final energy consumption|Waste, non-renewable";"Mtoe";"FE|Solids|Waste (EJ/yr)";0.041868 +"Energy Balance|Final energy consumption|Waste, non-renewable";"Mtoe";"SE|Solids (EJ/yr)";0.041868 +"Energy Balance|Final energy consumption|Waste, non-renewable";"Mtoe";"FE|Solids|Fossil (EJ/yr)";0.041868 +"Energy Balance|Final energy consumption|Waste, non-renewable";"Mtoe";"SE|Solids|Fossil (EJ/yr)";0.041868 "Energy Balance|Final energy consumption|Electricity";"Mtoe";"FE|Electricity (EJ/yr)";0.041868 "Energy Balance|Final energy consumption|Heat";"Mtoe";"FE|Heat (EJ/yr)";0.041868 "Energy Balance|Final energy consumption|Industry";"Mtoe";"FE|Industry (EJ/yr)";0.041868 +"Energy Balance|Final energy consumption|Industry";"Mtoe";"FE|w/o Non-energy Use|Industry (EJ/yr)";0.041868 "Energy Balance|Final energy consumption|Industry|Iron and steel";"Mtoe";; "Energy Balance|Final energy consumption|Industry|Chemical and petrochemical";"Mtoe";; "Energy Balance|Final energy consumption|Industry|Non-ferrous metals";"Mtoe";; @@ -241,10 +261,10 @@ "Energy Balance|Final energy consumption|Agriculture and Fishing";"Mtoe";"FE|AFOFI (EJ/yr)";0.041868 "Energy Balance|Final energy consumption|Others";"Mtoe";"FE|Other Sector (EJ/yr)";0.041868 "Electricity Production|Gross Electricity Generation";"TWh";"SE|Electricity (EJ/yr)";0.0036 -"Electricity Production|Solid fossil fuels, peat and products, oil shale and oil sands";"TWh";"SE|Electricity|Solids (EJ/yr)";0.0036 -"Electricity Production|Solid fossil fuels, peat and products, oil shale and oil sands|of which hard coal";"TWh";"SE|Electricity|Coal (EJ/yr)";0.0036 -"Electricity Production|Solid fossil fuels, peat and products, oil shale and oil sands|of which brown coal";"TWh";"SE|Electricity|Coal (EJ/yr)";0.0036 -"Electricity Production|Oil and petroleum products";"TWh";"SE|Electricity|Liquids (EJ/yr)";0.0036 +"Electricity Production|Solid fossil fuels, peat and products, oil shale and oil sands";"TWh";"SE|Electricity|Coal (EJ/yr)";0.0036 +"Electricity Production|Solid fossil fuels, peat and products, oil shale and oil sands|of which hard coal";"TWh";; +"Electricity Production|Solid fossil fuels, peat and products, oil shale and oil sands|of which brown coal";"TWh";; +"Electricity Production|Oil and petroleum products";"TWh";; "Electricity Production|Oil and petroleum products";"TWh";"SE|Electricity|Oil (EJ/yr)";0.0036 "Electricity Production|Natural gas and manufactured gas";"TWh";"SE|Electricity|Gas (EJ/yr)";0.0036 "Electricity Production|Natural gas and manufactured gas|of which natural gas";"TWh";; @@ -338,21 +358,21 @@ "Transport Fuels|Production biofuels|Pure biogasoline";"ktoe";; "Transport Fuels|Production biofuels|Pure biodiesel";"ktoe";; "Transport Fuels|Production biofuels|Other liquid biofuels";"ktoe";; -"Transport Fuels|Final consumption biofuels";"ktoe";"FE|Transport|w/o Bunkers|Liquids (EJ/yr)";4.1868E-05 -"Transport Fuels|Final consumption biofuels";"ktoe";"FE|Transport|Liquids|Biomass (EJ/yr)";4.1868E-05 -"Transport Fuels|Final consumption biofuels";"ktoe";"FE|Transport|Liquids (EJ/yr)";4.1868E-05 +"Transport Fuels|Final consumption biofuels";"ktoe";"FE|Transport|w/o Bunkers|Liquids (EJ/yr)";0.000041868 +"Transport Fuels|Final consumption biofuels";"ktoe";"FE|Transport|Liquids|Biomass (EJ/yr)";0.000041868 +"Transport Fuels|Final consumption biofuels";"ktoe";"FE|Transport|Liquids (EJ/yr)";0.000041868 "Transport Fuels|Final consumption biofuels|Pure biogasoline";"ktoe";; "Transport Fuels|Final consumption biofuels|Blended biogasoline";"ktoe";; "Transport Fuels|Final consumption biofuels|Pure biodiesel";"ktoe";; "Transport Fuels|Final consumption biofuels|Blended biodiesel";"ktoe";; "Transport Fuels|Final consumption biofuels|Other liquid biofuels";"ktoe";; -"Transport Fuels|Final consumption petroleum products";"ktoe";"FE|Transport|w/o Bunkers|Liquids (EJ/yr)";4.1868E-05 -"Transport Fuels|Final consumption petroleum products";"ktoe";"FE|Transport|Liquids|Oil (EJ/yr)";4.1868E-05 -"Transport Fuels|Final consumption petroleum products";"ktoe";"FE|Transport|Liquids (EJ/yr)";4.1868E-05 +"Transport Fuels|Final consumption petroleum products";"ktoe";"FE|Transport|w/o Bunkers|Liquids (EJ/yr)";0.000041868 +"Transport Fuels|Final consumption petroleum products";"ktoe";"FE|Transport|Liquids|Oil (EJ/yr)";0.000041868 +"Transport Fuels|Final consumption petroleum products";"ktoe";"FE|Transport|Liquids (EJ/yr)";0.000041868 "Transport Fuels|Final consumption petroleum products|of which LPG";"ktoe";; "Transport Fuels|Final consumption petroleum products|of which motor gasoline";"ktoe";; "Transport Fuels|Final consumption petroleum products|of which Gas/Diesel oil";"ktoe";; -"Transport Fuels|Final consumption natural gas";"ktoe";"FE|Transport|Gases (EJ/yr)";4.1868E-05 +"Transport Fuels|Final consumption natural gas";"ktoe";"FE|Transport|Gases (EJ/yr)";0.000041868 "Transport Fuels|Biofuels Production Capacity";"kton/year";; "Transport Fuels|Biofuels Production Capacity|Biogasoline";"kton/year";; "Transport Fuels|Biofuels Production Capacity|Biodiesel";"kton/year";; @@ -396,8 +416,9 @@ "Main Energy Indicators|Final Energy by sector|Services";"%";; "Main Energy Indicators|Final Energy by sector|Agriculture and Fishing";"%";; "Main Energy Indicators|Final Energy by sector|Other";"%";; -"CO2 emissions - National total [incl_ int_ aviation, without LULUCF]";"Mt CO2";"Emi|CO2 (Mt CO2/yr)";1 +"CO2 emissions - National total [incl_ int_ aviation, without LULUCF]";"Mt CO2";; "CO2 emissions|Energy";"Mt CO2";"Emi|CO2|Energy (Mt CO2/yr)";1 +"CO2 emissions|Energy";"Mt CO2";"Emi|CO2|w/ Bunkers|Energy and Industrial Processes (Mt CO2/yr)";1 "CO2 emissions|Energy|Energy Industries";"Mt CO2";"Emi|CO2|Fossil Fuels and Industry|Indirect (Mt CO2/yr)";1 "CO2 emissions|Energy|Energy Industries|Public Electricity and Heat Production";"Mt CO2";"Emi|CO2|Energy|Supply|Electricity and Heat (Mt CO2/yr)";1 "CO2 emissions|Energy|Energy Industries|Petroleum Refining";"Mt CO2";"Emi|CO2|Energy|Supply|Liquids w/ couple prod (Mt CO2/yr)";1 @@ -412,6 +433,7 @@ "CO2 emissions|Energy|Manufacturing Industries and Construction|Non-metallic minerals";"Mt CO2";"Emi|CO2|Energy|Industry|ETS (Mt CO2/yr)";1 "CO2 emissions|Energy|Manufacturing Industries and Construction|Other Manufacturing Industries and Constructions";"Mt CO2";"Emi|CO2|Energy|Industry|Non ETS (Mt CO2/yr)";1 "CO2 emissions|Energy|Transport";"Mt CO2";"Emi|CO2|Energy|Demand|Transport (Mt CO2/yr)";1 +"CO2 emissions|Energy|Transport";"Mt CO2";"Emi|CO2|w/ Bunkers|Energy|Demand|Transport (MtCO2/yr)";1 "CO2 emissions|Energy|Transport|Domestic Aviation";"Mt CO2";; "CO2 emissions|Energy|Transport|Road Transportation";"Mt CO2";; "CO2 emissions|Energy|Transport|Road Transportation|Cars";"Mt CO2";; @@ -431,13 +453,19 @@ "CO2 emissions|Energy|Other Combustion and Fugitive Emissions";"Mt CO2";"Emi|CO2|Energy|Other (Mt CO2/yr)";1 "CO2 emissions|Industrial Processes and Product Use";"Mt CO2";"Emi|CO2|Industrial Processes (Mt CO2/yr)";1 "CO2 emissions|Industrial Processes and Product Use";"Mt CO2";"Emi|CO2|FFaI|Industry|Process (Mt CO2/yr)";1 +"CO2 emissions|Industrial Processes and Product Use";"Mt CO2";"Emi|CO2|w/ Bunkers|Energy and Industrial Processes (Mt CO2/yr)";1 "CO2 emissions|Agriculture";"Mt CO2";"Emi|CO2|AFOLU (Mt CO2/yr)";1 "CO2 emissions|Waste and Others";"Mt CO2";"Emi|CO2|Waste (Mt CO2/yr)";1 "CO2 emissions|Indirect CO2";"Mt CO2";"Emi|CO2|Indirect CO2 (Mt CO2/yr)";1 "CO2 emissions|International aviation";"Mt CO2";"Emi|CO2|Transport|Pass|Aviation|International|Demand (Mt CO2/yr)";1 -"CO2 emissions|International aviation";"Mt CO2";"Emi|CO2 (Mt CO2/yr)";-1 +"CO2 emissions|International aviation";"Mt CO2";"Emi|CO2|Energy|Demand|Transport|International Bunkers (Mt CO2/yr)";1 +"CO2 emissions|International aviation";"Mt CO2";"Emi|CO2|w/ Bunkers|Energy and Industrial Processes (Mt CO2/yr)";1 +"CO2 emissions|International aviation";"Mt CO2";"Emi|CO2|w/ Bunkers|Energy|Demand|Transport (MtCO2/yr)";1 "CO2 emissions|International navigation";"Mt CO2";"Emi|CO2|Transport|Freight|International Shipping|Demand (Mt CO2/yr)";1 -"GHG emissions - National total [incl_ int_ aviation, without LULUCF]";"Mt CO2eq";"Emi|GHG (Mt CO2eq/yr)";1 +"CO2 emissions|International navigation";"Mt CO2";"Emi|CO2|Energy|Demand|Transport|International Bunkers (Mt CO2/yr)";1 +"CO2 emissions|International navigation";"Mt CO2";"Emi|CO2|w/ Bunkers|Energy and Industrial Processes (Mt CO2/yr)";1 +"CO2 emissions|International navigation";"Mt CO2";"Emi|CO2|w/ Bunkers|Energy|Demand|Transport (MtCO2/yr)";1 +"GHG emissions - National total [incl_ int_ aviation, without LULUCF]";"Mt CO2eq";"Emi|GHG|w/ Bunkers|w/o Land-Use Change (Mt CO2eq/yr)";1 "GHG emissions|Energy";"Mt CO2eq";"Emi|GHG|Energy (Mt CO2eq/yr)";1 "GHG emissions|Energy|Energy Industries";"Mt CO2eq";; "GHG emissions|Energy|Energy Industries|Public Electricity and Heat Production";"Mt CO2eq";"Emi|GHG|Energy|Electricity and Heat (Mt CO2eq/yr)";1 @@ -452,6 +480,7 @@ "GHG emissions|Energy|Manufacturing Industries and Construction|Non-metallic minerals";"Mt CO2eq";"Emi|GHG|Energy|Industry|ETS (Mt CO2eq/yr)";1 "GHG emissions|Energy|Manufacturing Industries and Construction|Other Manufacturing Industries and Constructions";"Mt CO2eq";"Emi|GHG|Energy|Industry|Non ETS (Mt CO2eq/yr)";1 "GHG emissions|Energy|Transport";"Mt CO2eq";"Emi|GHG|Energy|Demand|Transport (Mt CO2eq/yr)";1 +"GHG emissions|Energy|Transport";"Mt CO2eq";"Emi|GHG|w/ Bunkers|Energy|Demand|Transport (MtCO2eq/yr)";1 "GHG emissions|Energy|Transport|Domestic Aviation";"Mt CO2eq";; "GHG emissions|Energy|Transport|Road Transportation";"Mt CO2eq";; "GHG emissions|Energy|Transport|Road Transportation|Cars";"Mt CO2eq";; @@ -472,8 +501,10 @@ "GHG emissions|Waste and Others";"Mt CO2eq";"Emi|GHG|Waste (Mt CO2eq/yr)";1 "GHG emissions|Indirect CO2";"Mt CO2eq";"Emi|GHG|Indirect CO2 (Mt CO2eq/yr)";1 "GHG emissions|International aviation";"Mt CO2eq";"Emi|GHG|Bunkers|International Aviation (Mt CO2eq/yr)";1 -"GHG emissions|International aviation";"Mt CO2eq";"Emi|GHG (Mt CO2eq/yr)";-1 +"GHG emissions|International aviation";"Mt CO2eq";"Emi|GHG|w/ Bunkers|Energy|Demand|Transport (MtCO2eq/yr)";1 "GHG emissions|International navigation";"Mt CO2eq";"Emi|GHG|Bunkers|International Maritime Transport (Mt CO2eq/yr)";1 +"GHG emissions|International navigation";"Mt CO2eq";"Emi|GHG|w/ Bunkers|Energy|Demand|Transport (MtCO2eq/yr)";1 +"GHG emissions|International navigation";"Mt CO2eq";"Emi|GHG|w/ Bunkers|w/o Land-Use Change (Mt CO2eq/yr)";1 "Main Emissions Indicators|GHG national total emissions";"index 1990=100";; "Main Emissions Indicators|Total GHG per capita";"t CO2 eq_/capita";; "Main Emissions Indicators|GHG Intensity of Energy";"kg CO2 eq_/toe";; diff --git a/inst/extdata/reportingVariables/Mapping_IEA_EV_Outlook.csv b/inst/extdata/reportingVariables/Mapping_IEA_EV_Outlook.csv old mode 100755 new mode 100644 index 1d0dd1af..dff0405c --- a/inst/extdata/reportingVariables/Mapping_IEA_EV_Outlook.csv +++ b/inst/extdata/reportingVariables/Mapping_IEA_EV_Outlook.csv @@ -1,55 +1,47 @@ Variable;Unit;REMIND_Variable;REMIND_Unit;Comment;Factor -Electricity demand|Buses|BEV;GWh;FE|Transport|Pass|Road|Bus|Electricity;EJ/yr;;0.0000036 -Electricity demand|Buses|PHEV;GWh;;;; -Electricity demand|Cars|BEV;GWh;FE|Transport|Pass|Road|LDV|Electricity;EJ/yr;Contains PHEV, but should be small;0.0000036 -Electricity demand|Cars|PHEV;GWh;;;; -Electricity demand|Trucks|BEV;GWh;FE|Transport|Freight|Road|Electricity;EJ/yr;Contains light trucks, see below;0.0000036 -Electricity demand|Trucks|PHEV;GWh;;;; -Electricity demand|Vans|BEV;GWh;FE|Transport|Freight|Road|Truck (0-3$dot$5t)|Electricity;EJ/yr;;0.0000036 -Electricity demand|Vans|PHEV;GWh;;;; -EV chargers|Publicly available fast;no;;;; -EV chargers|Publicly available slow;no;;;; +EV charging points|EV|Publicly available fast;charging points;;;; +EV charging points|EV|Publicly available slow;charging points;;;; EV sales share|Buses|EV;percent;;;; EV sales share|Cars|EV;percent;;;; EV sales share|Trucks|EV;percent;;;; EV sales share|Vans|EV;percent;;;; -EV sales|Buses|BEV;no;Sales|Transport|Bus|Electric;Million vehicles;;1.00E-06 -EV sales|Buses|PHEV;no;;;; -EV sales|Buses|FCEV;no;Sales|Transport|Bus|FCEV;Million vehicles;;1.00E-06 -EV sales|Cars|BEV;no;Sales|Transport|Car|Electric;Million vehicles;;1.00E-06 -EV sales|Cars|PHEV;no;Sales|Transport|Car|Hybrid Electric;Million vehicles;;1.00E-06 -EV sales|Cars|FCEV;no;Sales|Transport|Car|FCEV;Million vehicles;;1.00E-06 -EV sales|Trucks|BEV;no;Sales|Transport|Truck|Electric;Million vehicles;;1.00E-06 -EV sales|Trucks|FCEV;no;Sales|Transport|Truck|FCEV;Million vehicles;;1.00E-06 -EV sales|Trucks|PHEV;no;;;; -EV sales|Vans|BEV;no;Sales|Transport|LDV|Van|BEV;Million vehicles;;1.00E-06 -EV sales|Vans|PHEV;no;Sales|Transport|LDV|Van|Hybrid Electric;Million vehicles;;1.00E-06 -EV sales|Vans|FCEV;no;Sales|Transport|LDV|Van|FCEV;Million vehicles;;1.00E-06 +EV sales|Buses|BEV;Vehicles;Sales|Transport|Bus|Electric;Million vehicles;;0.000001 +EV sales|Buses|FCEV;Vehicles;Sales|Transport|Bus|FCEV;Million vehicles;;0.000001 +EV sales|Buses|PHEV;Vehicles;;;; +EV sales|Cars|BEV;Vehicles;Sales|Transport|Car|Electric;Million vehicles;;0.000001 +EV sales|Cars|FCEV;Vehicles;Sales|Transport|Car|FCEV;Million vehicles;;0.000001 +EV sales|Cars|PHEV;Vehicles;Sales|Transport|Car|Hybrid Electric;Million vehicles;;0.000001 +EV sales|Trucks|BEV;Vehicles;Sales|Transport|Truck|Electric;Million vehicles;;0.000001 +EV sales|Trucks|FCEV;Vehicles;Sales|Transport|Truck|FCEV;Million vehicles;;0.000001 +EV sales|Trucks|PHEV;Vehicles;;;; +EV sales|Vans|BEV;Vehicles;Sales|Transport|LDV|Van|BEV;Million vehicles;;0.000001 +EV sales|Vans|FCEV;Vehicles;Sales|Transport|LDV|Van|FCEV;Million vehicles;;0.000001 +EV sales|Vans|PHEV;Vehicles;Sales|Transport|LDV|Van|Hybrid Electric;Million vehicles;;0.000001 EV stock share|Buses|EV;percent;;;; EV stock share|Cars|EV;percent;;;; EV stock share|Trucks|EV;percent;;;; EV stock share|Vans|EV;percent;;;; -EV stock|Buses|BEV;no;Stock|Transport|Bus|Electric;Million vehicles;;1.00E-06 -EV stock|Buses|PHEV;no;;;; -EV stock|Buses|FCEV;no;Stock|Transport|Bus|FCEV;Million vehicles;;1.00E-06 -EV stock|Cars|BEV;no;Stock|Transport|Car|Electric;Million vehicles;;1.00E-06 -EV stock|Cars|PHEV;no;Stock|Transport|Car|Hybrid Electric;Million vehicles;;1.00E-06 -EV stock|Cars|FCEV;no;Sales|Transport|Car|FCEV;Million vehicles;;1.00E-06 -EV stock|Trucks|BEV;no;Stock|Transport|Truck|Electric;Million vehicles;;1.00E-06 -EV stock|Trucks|FCEV;no;Stock|Transport|Truck|FCEV;Million vehicles;;1.00E-06 -EV stock|Trucks|PHEV;no;;;; -EV stock|Vans|BEV;no;Stock|Transport|LDV|Van|BEV;Million vehicles;;1.00E-06 -EV stock|Vans|PHEV;no;Stock|Transport|LDV|Van|Hybrid Electric;Million vehicles;;1.00E-06 -EV stock|Vans|FCEV;no;Stock|Transport|LDV|Van|FCEV;Million vehicles;;1.00E-06 -Oil displacement|Buses|EV;Milion liters of gasoline equivalent;;;; -Oil displacement|Buses|BEV;Milion liters of gasoline equivalent;;;; -Oil displacement|Buses|PHEV;Milion liters of gasoline equivalent;;;; -Oil displacement|Cars|EV;Milion liters of gasoline equivalent;;;; -Oil displacement|Cars|BEV;Milion liters of gasoline equivalent;;;; -Oil displacement|Cars|PHEV;Milion liters of gasoline equivalent;;;; -Oil displacement|Trucks|EV;Milion liters of gasoline equivalent;;;; -Oil displacement|Trucks|BEV;Milion liters of gasoline equivalent;;;; -Oil displacement|Trucks|PHEV;Milion liters of gasoline equivalent;;;; -Oil displacement|Vans|EV;Milion liters of gasoline equivalent;;;; -Oil displacement|Vans|BEV;Milion liters of gasoline equivalent;;;; -Oil displacement|Vans|PHEV;Milion liters of gasoline equivalent;;;; +EV stock|Buses|BEV;Vehicles;Stock|Transport|Bus|Electric;Million vehicles;;0.000001 +EV stock|Buses|FCEV;Vehicles;Stock|Transport|Bus|FCEV;Million vehicles;;0.000001 +EV stock|Buses|PHEV;Vehicles;;;; +EV stock|Cars|BEV;Vehicles;Stock|Transport|Car|Electric;Million vehicles;;0.000001 +EV stock|Cars|FCEV;Vehicles;Sales|Transport|Car|FCEV;Million vehicles;;0.000001 +EV stock|Cars|PHEV;Vehicles;Stock|Transport|Car|Hybrid Electric;Million vehicles;;0.000001 +EV stock|Trucks|BEV;Vehicles;Stock|Transport|Truck|Electric;Million vehicles;;0.000001 +EV stock|Trucks|FCEV;Vehicles;Stock|Transport|Truck|FCEV;Million vehicles;;0.000001 +EV stock|Trucks|PHEV;Vehicles;;;; +EV stock|Vans|BEV;Vehicles;Stock|Transport|LDV|Van|BEV;Million vehicles;;0.000001 +EV stock|Vans|FCEV;Vehicles;Stock|Transport|LDV|Van|FCEV;Million vehicles;;0.000001 +EV stock|Vans|PHEV;Vehicles;Stock|Transport|LDV|Van|Hybrid Electric;Million vehicles;;0.000001 +Electricity demand|Buses|EV;GWh;FE|Transport|Pass|Road|Bus|Electricity;EJ/yr;;0.0000036 +Electricity demand|Cars|EV;GWh;FE|Transport|Pass|Road|LDV|Electricity;EJ/yr;Contains PHEV, but should be small;0.0000036 +Electricity demand|Trucks|EV;GWh;FE|Transport|Freight|Road|Electricity;EJ/yr;Contains light trucks, see below;0.0000036 +Electricity demand|Vans|EV;GWh;FE|Transport|Freight|Road|Truck (0-3p5t)|Electricity;EJ/yr;;0.0000036 +Oil displacement Mbd|Buses|EV;Milion barrels per day;;;; +Oil displacement Mbd|Cars|EV;Milion barrels per day;;;; +Oil displacement Mbd|Trucks|EV;Milion barrels per day;;;; +Oil displacement Mbd|Vans|EV;Milion barrels per day;;;; +Oil displacement, million lge|Buses|EV;Oil displacement, million lge;;;; +Oil displacement, million lge|Cars|EV;Oil displacement, million lge;;;; +Oil displacement, million lge|Trucks|EV;Oil displacement, million lge;;;; +Oil displacement, million lge|Vans|EV;Oil displacement, million lge;;;; diff --git a/inst/extdata/reportingVariables/Mapping_IEA_WEO_complete.csv b/inst/extdata/reportingVariables/Mapping_IEA_WEO_complete.csv new file mode 100644 index 00000000..67a2459d --- /dev/null +++ b/inst/extdata/reportingVariables/Mapping_IEA_WEO_complete.csv @@ -0,0 +1,311 @@ +Variable;REMIND;Conversion +Activity of stock-Total-International marine bunkers (Billion tonne-km);; +Activity of stock-Total-Road freight trucks (Billion tonne-km);; +Activity of stock-Total-Road heavy-duty trucks (Billion tonne-km);; +Activity of stock-Total-Road passenger light duty vehicle (Billion passenger-km);; +Activity of stock-Total-Total aviation (domestic and bunkers) (Billion passenger-km);; +Capacity: installed-Battery storage-Electrical capacity (GW);Cap|Electricity|Storage|Battery (GW);1 +Capacity: installed-Bioenergy: with CCUS-Electrical capacity (GW);Cap|Electricity|Biomass|w/ CC (GW);1 +Capacity: installed-Coal: unabated-Electrical capacity (GW);Cap|Electricity|Coal|w/o CC (GW);1 +Capacity: installed-Coal: with CCUS-Electrical capacity (GW);Cap|Electricity|Coal|w/ CC (GW);1 +Capacity: installed-Concentrating solar power-Electrical capacity (GW);Cap|Electricity|Solar|CSP (GW);1 +Capacity: installed-Fossil fuels: unabated-Electrical capacity (GW);Cap|Electricity|Fossil|w/o CC (GW);1 +Capacity: installed-Fossil fuels: with CCUS-Electrical capacity (GW);Cap|Electricity|Fossil|w/ CC (GW);1 +Capacity: installed-Geothermal-Electrical capacity (GW);Cap|Electricity|Geothermal (GW);1 +Capacity: installed-Hydro-Electrical capacity (GW);Cap|Electricity|Hydro (GW);1 +Capacity: installed-Hydrogen and H2-based fuels-Electrical capacity (GW);Cap|Electricity|Hydrogen (GW);1 +Capacity: installed-Marine-Electrical capacity (GW);; +Capacity: installed-Modern bioenergy and renewable waste-Electrical capacity (GW);Cap|Electricity|Biomass (GW);1 +Capacity: installed-Natural gas: unabated-Electrical capacity (GW);Cap|Electricity|Gas|w/o CC (GW);1 +Capacity: installed-Natural gas: with CCUS-Electrical capacity (GW);Cap|Electricity|Gas|w/ CC (GW);1 +Capacity: installed-Nuclear-Electrical capacity (GW);Cap|Electricity|Nuclear (GW);1 +Capacity: installed-Oil-Electrical capacity (GW);Cap|Electricity|Oil (GW);1 +Capacity: installed-Renewables-Electrical capacity (GW);; +Capacity: installed-Solar PV-Electrical capacity (GW);Cap|Electricity|Solar|PV (GW);1 +Capacity: installed-Total-Electrical capacity (GW);Cap|Electricity (GW);1 +Capacity: installed-Wind-Electrical capacity (GW);Cap|Electricity|Wind (GW);1 +CO2 combustion and process-Total-Chemicals (Mt CO2);; +CO2 combustion and process-Total-Industry (Mt CO2);; +CO2 combustion and process-Total-Iron and steel (Mt CO2);; +CO2 combustion and process-Total-Non-ferrous metals: aluminium (Mt CO2);; +CO2 combustion and process-Total-Non-metallic minerals: cement (Mt CO2);; +CO2 combustion and process-Total-Other energy sector (Mt CO2);; +CO2 combustion and process-Total-Total final consumption (Mt CO2);; +CO2 combustion-Bioenergy and waste-Power sector inputs (Mt CO2);; +CO2 combustion-Bioenergy and waste-Total energy supply (Mt CO2);; +CO2 combustion-Bioenergy and waste-Total final consumption (Mt CO2);; +CO2 combustion-Coal-Power sector inputs (Mt CO2);; +CO2 combustion-Coal-Total energy supply (Mt CO2);; +CO2 combustion-Coal-Total final consumption (Mt CO2);; +CO2 combustion-Natural gas-Power sector inputs (Mt CO2);; +CO2 combustion-Natural gas-Total energy supply (Mt CO2);; +CO2 combustion-Natural gas-Total final consumption (Mt CO2);; +CO2 combustion-Oil-Power sector inputs (Mt CO2);; +CO2 combustion-Oil-Total energy supply (Mt CO2);; +CO2 combustion-Oil-Total final consumption (Mt CO2);; +CO2 combustion-Total-Buildings (Mt CO2);Emi|CO2|Energy|Demand|Buildings (Mt CO2/yr);1 +CO2 combustion-Total-Power sector inputs (Mt CO2);Emi|CO2|Energy|Supply|Electricity w/ couple prod (Mt CO2/yr);1 +CO2 combustion-Total-Residential (Mt CO2);; +CO2 combustion-Total-Road (Mt CO2);Emi|CO2|Transport|Road|Demand (Mt CO2/yr);1 +CO2 combustion-Total-Road heavy-duty trucks (Mt CO2);; +CO2 combustion-Total-Road passenger light duty vehicle (Mt CO2);Emi|CO2|Transport|Pass|Road|LDV|Demand (Mt CO2/yr);1 +CO2 combustion-Total-Services (Mt CO2);; +CO2 combustion-Total-Total aviation (domestic and bunkers) (Mt CO2);; +CO2 combustion-Total-Total energy supply (Mt CO2);Emi|CO2|Energy (Mt CO2/yr);1 +CO2 combustion-Total-Total navigation (domestic and bunkers) (Mt CO2);; +CO2 combustion-Total-Transport (Mt CO2);Emi|CO2|Energy|Demand|Transport (Mt CO2/yr);1 +CO2 DAC stored-Total-Direct air capture: offsite (Mt CO2);; +CO2 process stored-Modern bioenergy: liquid-Biofuels production (Mt CO2);; +CO2 total captured-Total-Total energy supply (Mt CO2);; +CO2 total intensity-Electricity-Electricity generation (gCO2 per kWh);; +CO2 total removed-Total-Biofuels production and direct air capture (Mt CO2);; +CO2 total removed-Total-Total energy supply (Mt CO2);; +CO2 total-Total-Total energy supply (Mt CO2);; +Economic indicators-Floorspace-Services (Million square meters);; +Economic indicators-Total-GDP per capita (USD per capita (2022, PPP));; +Economic indicators-Total-Gross domestic product (Billion USD (2022, PPP));; +Economic indicators-Total-Household (Million units);; +Energy intensity-Total-TES per GDP (GJ per thousand USD (2022, PPP));; +Energy intensity-Total-Total final consumption per GDP (GJ per thousand USD (2022, PPP));; +Energy-Ammonia-Power sector inputs (EJ);; +Energy-Ammonia-Total final consumption (EJ);; +Energy-Bioenergy: with CCUS-Electricity generation (TWh);SE|Electricity|Biomass|w/ CC (EJ/yr);0.0036 +Energy-Biomethane-Buildings (EJ);; +Energy-Biomethane-Industry (EJ);; +Energy-Biomethane-Total final consumption (EJ);; +Energy-Biomethane-Transport (EJ);; +Energy-Coal-Buildings (EJ);FE|Buildings|Solids|Fossil (EJ/yr);1 +Energy-Coal-Net exports (Million tonnes of coal equivalent);; +Energy-Coal-Net imports (Million tonnes of coal equivalent);; +Energy-Coal-Net trade (Million tonnes of coal equivalent);; +Energy-Coal-Power sector inputs (EJ);; +Energy-Coal-Production (Million tonnes of coal equivalent);; +Energy-Coal-Total energy supply (EJ);; +Energy-Coal-Total energy supply (Million tonnes of coal equivalent);; +Energy-Coal-Total final consumption (EJ);; +Energy-Coal: unabated-Electricity generation (TWh);SE|Electricity|Coal|w/o CC (EJ/yr);0.0036 +Energy-Coal: unabated-Industry (EJ);; +Energy-Coal: unabated-Power sector inputs (EJ);PE|Coal|Electricity (EJ/yr);1 +Energy-Coal: unabated-Total energy supply (EJ);PE|Coal (EJ/yr);1 +Energy-Coal: with CCUS-Electricity generation (TWh);SE|Electricity|Coal|w/ CC (EJ/yr);0.0036 +Energy-Coal: with CCUS-Industry (EJ);; +Energy-Coal: with CCUS-Power sector inputs (EJ);PE|Coal|Electricity|w/ CC (EJ/yr);1 +Energy-Coal: with CCUS-Total energy supply (EJ);PE|Coal (EJ/yr);1 +Energy-Coalbed methane-Production (Billion cubic metres);; +Energy-Coking coal-Net trade (Million tonnes of coal equivalent);; +Energy-Coking coal-Production (Million tonnes of coal equivalent);; +Energy-Concentrating solar power-Electricity generation (TWh);SE|Electricity|Solar|CSP (EJ/yr);0.0036 +Energy-Conventional crude oil-Production (Million barrels per day);; +Energy-Conventional gas-Production (Billion cubic metres);; +Energy-CTL, GTL and additives-Demand (Million barrels per day);; +Energy-Diesel-Demand (Million barrels per day);; +Energy-Direct use of crude oil-Demand (Million barrels per day);; +Energy-District heat-Buildings (EJ);FE|Buildings|Heat (EJ/yr);1 +Energy-District heat-Industry (EJ);FE|Industry|Heat (EJ/yr);1 +Energy-District heat-Total final consumption (EJ);FE|Heat (EJ/yr);1 +Energy-Electricity-Buildings (EJ);FE|Buildings|Electricity (EJ/yr);1 +Energy-Electricity-Industry (EJ);FE|Industry|Electricity (EJ/yr);1 +Energy-Electricity-Total final consumption (EJ);FE|Electricity (EJ/yr);1 +Energy-Electricity-Transport (EJ);FE|Transport|Electricity (EJ/yr);1 +Energy-Extra-heavy oil and bitumen-Production (Million barrels per day);; +Energy-Fossil fuels: unabated-Electricity generation (TWh);SE|Electricity|Fossil|w/o CC (EJ/yr);0.0036 +Energy-Fossil fuels: with CCUS-Electricity generation (TWh);SE|Electricity|Fossil|w/ CC (EJ/yr);0.0036 +Energy-Fuel oil-Demand (Million barrels per day);; +Energy-Gasoline-Demand (Million barrels per day);; +Energy-Geothermal-Electricity generation (TWh);SE|Electricity|Geothermal (EJ/yr);0.0036 +Energy-Hydro-Electricity generation (TWh);SE|Electricity|Hydro (EJ/yr);0.0036 +Energy-Hydro-Power sector inputs (EJ);; +Energy-Hydro-Total energy supply (EJ);PE|Hydro (EJ/yr);1 +Energy-Hydrogen and H2-based fuels-Electricity generation (TWh);SE|Electricity|Hydrogen (EJ/yr);0.0036 +Energy-Hydrogen based fuels-Demand (Million barrels per day);; +Energy-Hydrogen-based fuels: liquid-Total final consumption (EJ);; +Energy-Hydrogen-Bioenergy and other (Million tonnes);; +Energy-Hydrogen-Buildings (EJ);FE|Buildings|Hydrogen (EJ/yr);1 +Energy-Hydrogen-Final demand (EJ);FE|Industry|Hydrogen (EJ/yr);1 +Energy-Hydrogen-Fossil fuels with CCUS (Million tonnes);; +Energy-Hydrogen-Hydrogen demand for end-use sectors (Million tonnes);; +Energy-Hydrogen-In oil refining (Million tonnes);; +Energy-Hydrogen-Industry (EJ);; +Energy-Hydrogen-International bunkers (EJ);; +Energy-Hydrogen-Low-emissions hydrogen production (Million tonnes);; +Energy-Hydrogen-Low-emissions hydrogen-based fuels (Million tonnes);; +Energy-Hydrogen-Power generation (Million tonnes);; +Energy-Hydrogen-Power sector inputs (EJ);SE|Input|Hydrogen|Electricity (EJ/yr);1 +Energy-Hydrogen-To biofuels (Million tonnes);; +Energy-Hydrogen-To hydrogen-based fuels (Million tonnes);; +Energy-Hydrogen-To power generation (Million tonnes);; +Energy-Hydrogen-Total final consumption (EJ);FE|Hydrogen (EJ/yr);1 +Energy-Hydrogen-Total final consumption (Million tonnes);; +Energy-Hydrogen-Trade (Million tonnes);; +Energy-Hydrogen-Trade as share of demand (Million tonnes);; +Energy-Hydrogen-Transformation of hydrogen (Million tonnes);; +Energy-Hydrogen-Transport (EJ);FE|Transport|Hydrogen (EJ/yr);1 +Energy-Hydrogen-Water electrolysis (Million tonnes);; +Energy-Hydrogen: low emissions-Hydrogen production inputs: offsite (EJ);; +Energy-Hydrogen: low emissions-Hydrogen production: offsite (EJ);; +Energy-Hydrogen: low emissions-Hydrogen-based fuels production inputs (EJ);SE|Hydrogen|Electricity (EJ/yr);1 +Energy-Kerosene-Demand (Million barrels per day);; +Energy-Lignite and peat-Production (Million tonnes of coal equivalent);; +Energy-Liquids-Demand (Million barrels per day);; +Energy-LNG-Net trade (Billion cubic metres);; +Energy-LPG and ethane-Demand (Million barrels per day);; +Energy-Marine-Electricity generation (TWh);; +Energy-Modern bioenergy and renewable waste-Electricity generation (TWh);SE|Electricity|Biomass (EJ/yr);0.0036 +Energy-Modern bioenergy and renewable waste-Power sector inputs (EJ);PE|Biomass|Electricity (EJ/yr);1 +Energy-Modern bioenergy-Total energy supply (EJ);PE|Biomass (EJ/yr);1 +Energy-Modern bioenergy: gas-Total energy supply (EJ);FE|Gases|Biomass (EJ/yr);1 +Energy-Modern bioenergy: gas-Total energy supply (EJ);PE|Biomass (EJ/yr);1 +Energy-Modern bioenergy: liquid-Buildings (EJ);FE|Buildings|Liquids|Biomass (EJ/yr);1 +Energy-Modern bioenergy: liquid-Total energy supply (EJ);; +Energy-Modern bioenergy: liquid-Total final consumption (EJ);FE|Liquids|Biomass (EJ/yr);1 +Energy-Modern bioenergy: liquid-Transport (EJ);; +Energy-Modern bioenergy: solid-Buildings (EJ);FE|Buildings|Solids|Biomass|Modern (EJ/yr);1 +Energy-Modern bioenergy: solid-Industry (EJ);; +Energy-Modern bioenergy: solid-Total energy supply (EJ);FE|Solids|Biomass|Modern (EJ/yr);1 +Energy-Modern bioenergy: solid-Total energy supply (EJ);PE|Biomass (EJ/yr);1 +Energy-Naphtha-Demand (Million barrels per day);; +Energy-Natural gas liquids-Production (Million barrels per day);; +Energy-Natural gas-Buildings (EJ);; +Energy-Natural gas-Net exports (Billion cubic metres);; +Energy-Natural gas-Net imports (Billion cubic metres);; +Energy-Natural gas-Net trade (Billion cubic metres);; +Energy-Natural gas-Power sector inputs (EJ);; +Energy-Natural gas-Price (US dollars per million British thermal units);; +Energy-Natural gas-Production (Billion cubic metres);; +Energy-Natural gas-Total energy supply (Billion cubic metres);; +Energy-Natural gas-Total energy supply (EJ);; +Energy-Natural gas-Total final consumption (EJ);; +Energy-Natural gas-Transport (EJ);; +Energy-Natural gas: unabated-Electricity generation (TWh);SE|Electricity|Gas|w/o CC (EJ/yr);0.0036 +Energy-Natural gas: unabated-Industry (EJ);; +Energy-Natural gas: unabated-Power sector inputs (EJ);PE|Gas|Electricity (EJ/yr);1 +Energy-Natural gas: unabated-Total energy supply (EJ);PE|Gas (EJ/yr);1 +Energy-Natural gas: with CCUS-Electricity generation (TWh);SE|Electricity|Gas|w/ CC (EJ/yr);0.0036 +Energy-Natural gas: with CCUS-Industry (EJ);; +Energy-Natural gas: with CCUS-Power sector inputs (EJ);PE|Gas|Electricity|w/ CC (EJ/yr);1 +Energy-Natural gas: with CCUS-Total energy supply (EJ);PE|Gas (EJ/yr);1 +Energy-Nuclear-Electricity generation (TWh);SE|Electricity|Nuclear (EJ/yr);0.0036 +Energy-Nuclear-Power sector inputs (EJ);; +Energy-Nuclear-Total energy supply (EJ);PE|Nuclear (EJ/yr);1 +Energy-Oil products-Demand (Million barrels per day);; +Energy-Oil-Buildings (EJ);FE|Buildings|Liquids|Fossil|Oil (EJ/yr);1 +Energy-Oil-Demand (Million barrels per day);; +Energy-Oil-Electricity generation (TWh);; +Energy-Oil-Industry (EJ);; +Energy-Oil-Net exports (Million barrels per day);; +Energy-Oil-Net imports (Million barrels per day);; +Energy-Oil-Non-energy use (EJ);; +Energy-Oil-Power sector inputs (EJ);; +Energy-Oil-Price (US dollars per barrel);; +Energy-Oil-Processing gains (Million barrels per day);; +Energy-Oil-Production (Million barrels per day);; +Energy-Oil-Supply (Million barrels per day);; +Energy-Oil-Total energy supply (EJ);PE|Oil (EJ/yr);1 +Energy-Oil-Total energy supply (Million barrels per day);; +Energy-Oil-Total final consumption (EJ);FE|Liquids|Fossil|Oil (EJ/yr);1 +Energy-Oil-Transport (EJ);FE|Transport|Liquids|Fossil|Oil (EJ/yr);1 +Energy-Other products-Demand (Million barrels per day);; +Energy-Other-Production (Billion cubic metres);; +Energy-Other-Production (Million barrels per day);; +Energy-Pipeline-Net trade (Billion cubic metres);; +Energy-Products from NGLs-Demand (Million barrels per day);; +Energy-Refinery market share-Demand (Percentage);; +Energy-Refinery products-Demand (Million barrels per day);; +Energy-Renewables-Electricity generation (TWh);; +Energy-Renewables-Power sector inputs (EJ);; +Energy-Renewables-Total energy supply (EJ);; +Energy-Shale gas-Production (Billion cubic metres);; +Energy-Solar PV-Electricity generation (TWh);SE|Electricity|Solar|PV (EJ/yr);0.0036 +Energy-Solar PV-Power sector inputs (EJ);; +Energy-Solar-Total energy supply (EJ);PE|Solar (EJ/yr);1 +Energy-Solid bioenergy incl_ TUOB-Total final consumption (EJ);; +Energy-Steam coal-Net trade (Million tonnes of coal equivalent);; +Energy-Steam coal-Price (US dollars per tonne);; +Energy-Steam coal-Production (Million tonnes of coal equivalent);; +Energy-Synthetic methane-Total final consumption (EJ);; +Energy-Synthetic oil products-Total final consumption (EJ);; +Energy-Tight gas-Production (Billion cubic metres);; +Energy-Tight oil-Production (Million barrels per day);; +Energy-Total gases-Buildings (EJ);FE|Buildings|Gases (EJ/yr);1 +Energy-Total gases-Industry (EJ);FE|Industry|Gases (EJ/yr);1 +Energy-Total gases-Total final consumption (EJ);FE|Gases (EJ/yr);1 +Energy-Total gases-Transport (EJ);FE|Transport|Gases (EJ/yr);1 +Energy-Total liquids-Buildings (EJ);FE|Buildings|Liquids (EJ/yr);1 +Energy-Total liquids-Industry (EJ);FE|Industry|Liquids (EJ/yr);1 +Energy-Total liquids-Total final consumption (EJ);FE|Liquids (EJ/yr);1 +Energy-Total liquids-Transport (EJ);FE|Transport|Liquids (EJ/yr);1 +Energy-Total solid fuels-Buildings (EJ);FE|Buildings|Solids (EJ/yr);1 +Energy-Total solid fuels-Industry (EJ);FE|Industry|Solids (EJ/yr);1 +Energy-Total solid fuels-Total final consumption (EJ);FE|Solids (EJ/yr);1 +Energy-Total-Biofuels production: own use (EJ);SE|Liquids|Biomass (EJ/yr);1 +Energy-Total-Buildings (EJ);FE|Buildings (EJ/yr);1 +Energy-Total-Chemicals (EJ);; +Energy-Total-Electricity generation (TWh);SE|Electricity (EJ/yr);0.0036 +Energy-Total-Industry (EJ);FE|Industry (EJ/yr);1 +Energy-Total-Iron and steel (EJ);FE|Industry|Steel (EJ/yr);1 +Energy-Total-Non-ferrous metals: aluminium (EJ);; +Energy-Total-Non-metallic minerals: cement (EJ);; +Energy-Total-Other energy sector (EJ);; +Energy-Total-Power sector inputs (EJ);; +Energy-Total-Refinery runs (Million barrels per day);; +Energy-Total-Refining capacity (Million barrels per day);; +Energy-Total-Refining capacity: capacity at risk (Million barrels per day);; +Energy-Total-Residential (EJ);; +Energy-Total-Road (EJ);FE|Transport|Road (EJ/yr);1 +Energy-Total-Road heavy-duty trucks (EJ);; +Energy-Total-Road passenger light duty vehicle (EJ);FE|Transport|Pass|Road|LDV (EJ/yr);1 +Energy-Total-Services (EJ);; +Energy-Total-Total aviation (domestic and bunkers) (EJ);; +Energy-Total-Total energy supply (EJ);PE (EJ/yr);1 +Energy-Total-Total final consumption (EJ);FE (EJ/yr);1 +Energy-Total-Total navigation (domestic and bunkers) (EJ);FE|Transport|Freight|International Shipping (EJ/yr);1 +Energy-Total-Transport (EJ);FE|Transport (EJ/yr);1 +Energy-Traditional use of biomass-Residential (EJ);FE|Buildings|Solids|Biomass|Traditional (EJ/yr);1 +Energy-Traditional use of biomass-Total energy supply (EJ);PE|Biomass (EJ/yr);1 +Energy-Traditional use of biomass-Total energy supply (EJ);PE|Biomass|Traditional (EJ/yr);1 +Energy-Wind-Electricity generation (TWh);SE|Electricity|Wind (EJ/yr);0.0036 +Energy-Wind-Power sector inputs (EJ);; +Energy-Wind-Total energy supply (EJ);PE|Wind (EJ/yr);1 +Industrial material production-Aluminium-Non-ferrous metals: aluminium (excl internal scrap) (Million tonnes);; +Industrial material production-Cement-Non-metallic minerals: cement (Million tonnes);; +Industrial material production-Crude steel-Iron and steel (Million tonnes);; +Industrial material production-Primary chemicals-Chemicals (Million tonnes);; +Investment spending, annual average-Battery storage-Generation (Billion US dollars);; +Investment spending, annual average-Coal-Generation (Billion US dollars);; +Investment spending, annual average-Coal-Supply (Billion US dollars);; +Investment spending, annual average-Electricity-Transmission and distribution (Billion US dollars);; +Investment spending, annual average-Fossil fuels with CCUS-Generation (Billion US dollars);; +Investment spending, annual average-Fuels-Supply (Billion US dollars);; +Investment spending, annual average-Gas-Generation (Billion US dollars);; +Investment spending, annual average-Hydro-Generation (Billion US dollars);; +Investment spending, annual average-Hydrogen and Hydrogen-based fuels-Supply (Billion US dollars);; +Investment spending, annual average-Liquid biofuels and biogases-Supply (Billion US dollars);; +Investment spending, annual average-Nuclear-Generation (Billion US dollars);; +Investment spending, annual average-Oil and gas-Supply (Billion US dollars);; +Investment spending, annual average-Other-Generation (Billion US dollars);; +Investment spending, annual average-Renewables and other-Supply, power and end-use (Billion US dollars);; +Investment spending, annual average-Renewables-Generation (Billion US dollars);; +Investment spending, annual average-Solar PV-Generation (Billion US dollars);; +Investment spending, annual average-Total-Direct air capture (Billion US dollars);; +Investment spending, annual average-Total-End-use (Billion US dollars);; +Investment spending, annual average-Total-Energy efficiency (Billion US dollars);; +Investment spending, annual average-Total-Fuels and Power (Billion US dollars);; +Investment spending, annual average-Total-Generation (Billion US dollars);; +Investment spending, annual average-Total-Power (Billion US dollars);; +Investment spending, annual average-Total-Supply, power and end-use (Billion US dollars);; +Investment spending, annual average-Unabated fossil fuels-Generation (Billion US dollars);; +Investment spending, annual average-Wind-Generation (Billion US dollars);; +Population indicators-Total-Population (Million people);; +Share of demand-Coal-Net imports (Percentage);; +Share of demand-Natural gas-Net imports (Percentage);; +Share of demand-Oil-Net imports (Percentage);; +Share of production-Coal-Net exports (Percentage);; +Share of production-Coal-Net trade (Percentage);; +Share of production-Coking coal-Net trade (Percentage);; +Share of production-LNG-Net trade (Percentage);; +Share of production-Natural gas-Net exports (Percentage);; +Share of production-Natural gas-Net trade (Percentage);; +Share of production-Oil-Net exports (Percentage);; +Share of production-Pipeline-Net trade (Percentage);; +Share of production-Steam coal-Net trade (Percentage);; +Stock-Floorspace-Residential (Million square meters);; diff --git a/inst/extdata/reportingVariables/Mapping_INNOPATHS.csv b/inst/extdata/reportingVariables/Mapping_INNOPATHS.csv new file mode 100755 index 00000000..3882025a --- /dev/null +++ b/inst/extdata/reportingVariables/Mapping_INNOPATHS.csv @@ -0,0 +1,750 @@ +"REMIND";"Variable";"factor";"remark" +"Cap|Electricity (GW)";"Capacity|Electricity (GW)";1; +"Cap|Electricity|Biomass (GW)";"Capacity|Electricity|Biomass (GW)";1; +"Cap|Electricity|Biomass|w/ CC (GW)";"Capacity|Electricity|Biomass|w/ CCS (GW)";1; +"Cap|Electricity|Biomass|w/o CC (GW)";"Capacity|Electricity|Biomass|w/o CCS (GW)";1; +"Cap|Electricity|Coal (GW)";"Capacity|Electricity|Coal (GW)";1; +"Cap|Electricity|Coal|w/ CC (GW)";"Capacity|Electricity|Coal|w/ CCS (GW)";1; +"Cap|Electricity|Coal|w/o CC (GW)";"Capacity|Electricity|Coal|w/o CCS (GW)";1; +"Cap|Electricity|Gas (GW)";"Capacity|Electricity|Gas (GW)";1; +"Cap|Electricity|Gas|CC|w/ CC (GW)";"Capacity|Electricity|Gas|CC|w/ CCS (GW)";1; +"Cap|Electricity|Gas|CC|w/o CC (GW)";"Capacity|Electricity|Gas|CC|w/o CCS (GW)";1; +"Cap|Electricity|Gas|w/ CC (GW)";"Capacity|Electricity|Gas|w/ CCS (GW)";1; +"Cap|Electricity|Gas|w/o CC (GW)";"Capacity|Electricity|Gas|w/o CCS (GW)";1; +"Cap|Electricity|Geothermal (GW)";"Capacity|Electricity|Geothermal (GW)";1; +"Cap|Electricity|Hydro (GW)";"Capacity|Electricity|Hydro (GW)";1; +"Cap|Electricity|Hydrogen (GW)";"Capacity|Electricity|Hydrogen (GW)";1; +"Cap|Electricity|Nuclear (GW)";"Capacity|Electricity|Nuclear (GW)";1; +"Cap|Electricity|Oil|w/o CC (GW)";"Capacity|Electricity|Oil (GW)";1; +"Cap|Electricity|Peak Demand|Estimated from FE x 1p4 x 1p1 (GW)";"Capacity|Electricity|Peak Demand (GW)";1; +"Cap|Electricity|Solar (GW)";"Capacity|Electricity|Solar (GW)";1; +"Cap|Electricity|Solar|CSP (GW)";"Capacity|Electricity|Solar|CSP (GW)";1; +"Cap|Electricity|Solar|PV (GW)";"Capacity|Electricity|Solar|PV (GW)";1; +"Cap|Electricity|Wind (GW)";"Capacity|Electricity|Wind (GW)";1; +"Cap|Electricity|Wind|Onshore (GW)";"Capacity|Electricity|Wind|Onshore (GW)";1; +"Emi|BC (Mt BC/yr)";"Emissions|BC (Mt BC/yr)";1; +"Emi|CH4 (Mt CH4/yr)";"Emissions|CH4 (Mt CH4/yr)";1; +"Emi|CO (Mt CO/yr)";"Emissions|CO (Mt CO/yr)";1; +"Emi|CO2 (Mt CO2/yr)";"Emissions|CO2 (Mt CO2/yr)";1; +"Emi|CO2|Energy|Demand|Buildings (Mt CO2/yr)";"Emissions|CO2|Energy|Demand|Residential and Commercial (Mt CO2/yr)";1; +"Emissions|CO2|Energy|Negative (Mt CO2/yr)";"Emissions|CO2|Energy|Negative (Mt CO2/yr)";1; +"Emissions|CO2|DACCS sequestered (Mt CO2/yr)";"Emissions|CO2|DACCS sequestered (Mt CO2/yr)";1; +"Emissions|CO2|Other (Mt CO2/yr)";"Emissions|CO2|Other (Mt CO2/yr)";1; +"Emi|CO2|Energy (Mt CO2/yr)";"Emissions|CO2|Energy (Mt CO2/yr)";1; +"Emi|CO2|Energy|Demand|Industry (Mt CO2/yr)";"Emissions|CO2|Energy|Demand|Industry (Mt CO2/yr)";1; +"Emissions|CO2|Energy|Supply|Gross|Electricity (Mt CO2/yr)";"Emissions|CO2|Energy|Supply (Gross)|Electricity (Mt CO2/yr)";1; +"Emissions|CO2|Energy|Supply|Gross|Gases (Mt CO2/yr)";"Emissions|CO2|Energy|Supply (Gross)|Gases (Mt CO2/yr)";1; +"Emissions|CO2|Energy|Supply|Gross (Mt CO2/yr)";"Emissions|CO2|Energy|Supply (Gross) (Mt CO2/yr)";1; +"Emissions|CO2|Energy|Supply|Gross|Heat (Mt CO2/yr)";"Emissions|CO2|Energy|Supply (Gross)|Heat (Mt CO2/yr)";1; +"Emissions|CO2|Energy|Supply|Gross|Hydrogen (Mt CO2/yr)";"Emissions|CO2|Energy|Supply (Gross)|Hydrogen (Mt CO2/yr)";1; +"Emissions|CO2|Energy|Supply|Gross|Liquids (Mt CO2/yr)";"Emissions|CO2|Energy|Supply (Gross)|Liquids (Mt CO2/yr)";1; +"Emissions|CO2|Energy|Supply|Gross|Solids (Mt CO2/yr)";"Emissions|CO2|Energy|Supply (Gross)|Solids (Mt CO2/yr)";1; +"Emi|CO2|ES (Mt CO2/yr)";"Emissions|CO2|ESD (Mt CO2/yr)";1; +"Emi|CO2|ETS (Mt CO2/yr)";"Emissions|CO2|ETS (Mt CO2/yr)";1; +"Emi|CO2|Industrial Processes (Mt CO2/yr)";"Emissions|CO2|Industrial Processes (Mt CO2/yr)";1; +"Emi|CO2|Energy|Demand (Mt CO2/yr)";"Emissions|CO2|Energy|Demand (Mt CO2/yr)";1; +"Emissions|CO2|AFOLU (Mt CO2/yr)";"Emissions|CO2|AFOLU (Mt CO2/yr)";1; +"Emi|CO2|other - Non ETS and ES (Mt CO2/yr)";"Emissions|CO2|Other regulation (Mt CO2/yr)";1; +"Emi|CO2|Energy|Demand|Transport (Mt CO2/yr)";"Emissions|CO2|Energy|Demand|Transportation (Mt CO2/yr)";1; +"Emi|F-Gases (Mt CO2-equiv/yr)";"Emissions|F-Gases (Mt CO2eq/yr)";1; +"Emi|HFC (kt HFC134a-equiv/yr)";"Emissions|HFC (kt HFC134a-equiv/yr)";1; +"Emi|GHG (Mt CO2eq/yr)";"Emissions|Kyoto Gases (Mt CO2eq/yr)";1; +"Emi|N2O (kt N2O/yr)";"Emissions|N2O (kt N2O/yr)";1; +"Emi|NH3 (Mt NH3/yr)";"Emissions|NH3 (Mt NH3/yr)";1; +"Emi|OC (Mt OC/yr)";"Emissions|OC (Mt OC/yr)";1; +"Emi|PFC (kt CF4-equiv/yr)";"Emissions|PFC (kt CF4-equiv/yr)";1; +"Emi|SF6 (kt SF6/yr)";"Emissions|SF6 (kt SF6/yr)";1; +"Emi|SO2 (Mt SO2/yr)";"Emissions|Sulfur (Mt SO2/yr)";1; +"Emi|VOC (Mt VOC/yr)";"Emissions|VOC (Mt VOC/yr)";1; +"NA";"Emissions|CO2|Energy|Supply (Gross)|Other (Mt CO2/yr)";"NA"; +"ES|Transport|Freight (bn tkm/yr)";"Services and Products|Transportation|Freight (Gtkm/yr)";1; +"ES|Transport|Pass (bn pkm/yr)";"Services and Products|Transportation|Passenger (Gpkm/yr)";1; +"ES|Transport|Pass|LDV (bn pkm/yr)";"Services and Products|Transportation|Passenger|LDV (Gpkm/yr)";1; +"ES|Transport|Pass|non-LDV (bn pkm/yr)";"Services and Products|Transportation|Passenger|HDV (Gpkm/yr)";1; +"FE (EJ/yr)";"Final Energy (PJ/yr)";0.001; +"FE|Buildings (EJ/yr)";"Final Energy|Residential and Commercial (PJ/yr)";0.001; +"FE|Buildings|Appliances and Light (EJ/yr)";"Final Energy|Residential and Commercial|Appliances and Lighting (PJ/yr)";0.001; +"FE|Buildings|Appliances and Light|Electricity (EJ/yr)";"Final Energy|Residential and Commercial|Appliances and Lighting|Electricity (PJ/yr)";0.001; +"FE|Buildings|Cooking and Water (EJ/yr)";"Final Energy|Residential and Commercial|Water Heating and Cooking (PJ/yr)";0.001; +"FE|Buildings|Cooking and Water|Electricity (EJ/yr)";"Final Energy|Residential and Commercial|Water Heating and Cooking|Electricity (PJ/yr)";0.001; +"FE|Buildings|Cooking and Water|Electricity|Heat pumps (EJ/yr)";"Final Energy|Residential and Commercial|Water Heating and Cooking|Electricity|Heat Pumps (PJ/yr)";0.001; +"FE|Buildings|Cooking and Water|Electricity|Resistance (EJ/yr)";"Final Energy|Residential and Commercial|Water Heating and Cooking|Electricity|Resistive (PJ/yr)";0.001; +"FE|Buildings|Cooking and Water|Gases (EJ/yr)";"Final Energy|Residential and Commercial|Water Heating and Cooking|Gases (PJ/yr)";0.001; +"FE|Buildings|Cooking and Water|Heat (EJ/yr)";"Final Energy|Residential and Commercial|Water Heating and Cooking|Heat (PJ/yr)";0.001; +"FE|Buildings|Cooking and Water|Hydrogen (EJ/yr)";"Final Energy|Residential and Commercial|Water Heating and Cooking|Hydrogen (PJ/yr)";0.001; +"FE|Buildings|Cooking and Water|Liquids (EJ/yr)";"Final Energy|Residential and Commercial|Water Heating and Cooking|Liquids (PJ/yr)";0.001; +"FE|Buildings|Cooking and Water|Solids (EJ/yr)";"Final Energy|Residential and Commercial|Water Heating and Cooking|Solids (PJ/yr)";0.001; +"FE|Buildings|Electricity (EJ/yr)";"Final Energy|Residential and Commercial|Electricity (PJ/yr)";0.001; +"FE|Buildings|Gases (EJ/yr)";"Final Energy|Residential and Commercial|Gases (PJ/yr)";0.001; +"FE|Buildings|Heat (EJ/yr)";"Final Energy|Residential and Commercial|Heat (PJ/yr)";0.001; +"FE|Buildings|Hydrogen (EJ/yr)";"Final Energy|Residential and Commercial|Hydrogen (PJ/yr)";0.001; +"FE|Buildings|Liquids (EJ/yr)";"Final Energy|Residential and Commercial|Liquids (PJ/yr)";0.001; +"FE|Buildings|Solids (EJ/yr)";"Final Energy|Residential and Commercial|Solids (PJ/yr)";0.001; +"FE|Buildings|Space Cooling (EJ/yr)";"Final Energy|Residential and Commercial|Space Cooling (PJ/yr)";0.001; +"FE|Buildings|Space Cooling|Electricity (EJ/yr)";"Final Energy|Residential and Commercial|Space Cooling|Electricity (PJ/yr)";0.001; +"FE|Buildings|Space Heating (EJ/yr)";"Final Energy|Residential and Commercial|Space Heating (PJ/yr)";0.001; +"FE|Buildings|Space Heating|Electricity (EJ/yr)";"Final Energy|Residential and Commercial|Space Heating|Electricity (PJ/yr)";0.001; +"FE|Buildings|Space Heating|Electricity|Heat pumps (EJ/yr)";"Final Energy|Residential and Commercial|Space Heating|Electricity|Heat Pumps (PJ/yr)";0.001; +"FE|Buildings|Space Heating|Electricity|Resistance (EJ/yr)";"Final Energy|Residential and Commercial|Space Heating|Electricity|Resistive (PJ/yr)";0.001; +"FE|Buildings|Space Heating|Gases (EJ/yr)";"Final Energy|Residential and Commercial|Space Heating|Gases (PJ/yr)";0.001; +"FE|Buildings|Space Heating|Heat (EJ/yr)";"Final Energy|Residential and Commercial|Space Heating|Heat (PJ/yr)";0.001; +"FE|Buildings|Space Heating|Hydrogen (EJ/yr)";"Final Energy|Residential and Commercial|Space Heating|Hydrogen (PJ/yr)";0.001; +"FE|Buildings|Space Heating|Liquids (EJ/yr)";"Final Energy|Residential and Commercial|Space Heating|Liquids (PJ/yr)";0.001; +"FE|Buildings|Space Heating|Solids (EJ/yr)";"Final Energy|Residential and Commercial|Space Heating|Solids (PJ/yr)";0.001; +"FE|CDR (EJ/yr)";"Final Energy|Carbon Dioxide Removal (PJ/yr)";0.001; +"FE|CDR|Electricity (EJ/yr)";"Final Energy|Carbon Dioxide Removal|Electricity (PJ/yr)";0.001; +"FE|CDR|Gases (EJ/yr)";"Final Energy|Carbon Dioxide Removal|Gases (PJ/yr)";0.001; +"FE|CDR|Hydrogen (EJ/yr)";"Final Energy|Carbon Dioxide Removal|Hydrogen (PJ/yr)";0.001; +"FE|CDR|Liquids (EJ/yr)";"Final Energy|Carbon Dioxide Removal|Liquids (PJ/yr)";0.001; +"FE|Electricity (EJ/yr)";"Final Energy|Electricity (PJ/yr)";0.001; +"FE|Gases (EJ/yr)";"Final Energy|Gases (PJ/yr)";0.001; +"FE|Heat (EJ/yr)";"Final Energy|Heat (PJ/yr)";0.001; +"FE|Hydrogen (EJ/yr)";"Final Energy|Hydrogen (PJ/yr)";0.001; +"FE|Industry (EJ/yr)";"Final Energy|Industry (PJ/yr)";0.001; +"FE|Industry|Electricity (EJ/yr)";"Final Energy|Industry|Electricity (PJ/yr)";0.001; +"FE|Industry|Gases (EJ/yr)";"Final Energy|Industry|Gases (PJ/yr)";0.001; +"FE|Industry|Heat (EJ/yr)";"Final Energy|Industry|Heat (PJ/yr)";0.001; +"FE|Industry|Hydrogen (EJ/yr)";"Final Energy|Industry|Hydrogen (PJ/yr)";0.001; +"FE|Industry|Liquids (EJ/yr)";"Final Energy|Industry|Liquids (PJ/yr)";0.001; +"FE|Industry|Solids (EJ/yr)";"Final Energy|Industry|Solids (PJ/yr)";0.001; +"FE|Liquids (EJ/yr)";"Final Energy|Liquids (PJ/yr)";0.001; +"FE|Solids (EJ/yr)";"Final Energy|Solids (PJ/yr)";0.001; +"FE|Transport (EJ/yr)";"Final Energy|Transportation (PJ/yr)";0.001; +"FE|Transport|Electricity (EJ/yr)";"Final Energy|Transportation|Electricity (PJ/yr)";0.001; +"FE|Transport|Freight (EJ/yr)";"Final Energy|Transportation|Freight (PJ/yr)";0.001; +"FE|Transport|Hydrogen (EJ/yr)";"Final Energy|Transportation|Hydrogen (PJ/yr)";0.001; +"FE|Transport|Liquids (EJ/yr)";"Final Energy|Transportation|Liquids (PJ/yr)";0.001; +"FE|Transport|Pass (EJ/yr)";"Final Energy|Transportation|Passenger (PJ/yr)";0.001; +"FE|Transport|Pass|Electricity (EJ/yr)";"Final Energy|Transportation|Passenger|Electricity (PJ/yr)";0.001; +"FE|Transport|Pass|Hydrogen (EJ/yr)";"Final Energy|Transportation|Passenger|Hydrogen (PJ/yr)";0.001; +"NA";"Final Energy|Transportation|Passenger|HDV (PJ/yr)";"NA"; +"NA";"Final Energy|Transportation|Passenger|LDV (PJ/yr)";"NA"; +"NA";"Final Energy|Transportation|Passenger|LDV|Electricity (PJ/yr)";"NA"; +"NA";"Final Energy|Transportation|Passenger|LDV|Hydrogen (PJ/yr)";"NA"; +"NA";"Final Energy|Transportation|Passenger|LDV|Liquids (PJ/yr)";"NA"; +"FE|Transport|Pass|Train|Electricity (EJ/yr)";"Final Energy|Transportation|Passenger|Train|Electricity (PJ/yr)";0.001; +"Floorspace demand (million m2)";"Services and Products|Residential and Commercial|Floorspace demand (million m2)";1; +"GDP|MER (billion US$2005/yr)";"Economy|GDP|MER (billion EUR2015/yr)";0.9259259; +"GDP|PPP (billion US$2005/yr)";"Economy|GDP|PPP (billion EUR2015/yr)";0.9259259; +"NA";"Capacity Additions|Electricity|Gas|CC (GW/yr)";"NA"; +"NA";"Capacity Additions|Electricity|Gas|OC (GW/yr)";"NA"; +"NA";"Capacity Additions|Electricity|Geothermal (GW/yr)";"NA"; +"NA";"Capacity Additions|Electricity|Hydrogen|CC (GW/yr)";"NA"; +"NA";"Capacity Additions|Electricity|Hydrogen|FC (GW/yr)";"NA"; +"NA";"Capacity Additions|Electricity|Hydrogen|OC (GW/yr)";"NA"; +"NA";"Capacity Additions|Electricity|Ocean (GW/yr)";"NA"; +"NA";"Capacity Additions|Electricity|Oil (GW/yr)";"NA"; +"NA";"Capacity Additions|Electricity|Other (GW/yr)";"NA"; +"NA";"Capacity Additions|Electricity|Storage (GW/yr)";"NA"; +"NA";"Capacity Additions|Electricity|Storage|CAES (GW/yr)";"NA"; +"NA";"Capacity Additions|Electricity|Storage|Hydro Dam Reservoir (GW/yr)";"NA"; +"NA";"Capacity Additions|Electricity|Storage|Pump Hydro (GW/yr)";"NA"; +"NA";"Capacity Additions|Electricity|Storage|Stationary Batteries (GW/yr)";"NA"; +"NA";"Capacity Additions|Electricity|Storage|Vehicles (GW/yr)";"NA"; +"NA";"Capacity Additions|Electricity|Transmission Grid (GWkm/yr)";"NA"; +"NA";"Capacity Additions|Electricity|Wind|Offshore (GW/yr)";"NA"; +"NA";"Capacity|Electricity|Coal|Hard Coal (GW)";"NA"; +"NA";"Capacity|Electricity|Coal|Lignite (GW)";"NA"; +"NA";"Capacity|Electricity|Gas|CC (GW)";"NA"; +"NA";"Capacity|Electricity|Gas|OC (GW)";"NA"; +"NA";"Capacity|Electricity|Hydrogen|CC (GW)";"NA"; +"NA";"Capacity|Electricity|Hydrogen|FC (GW)";"NA"; +"NA";"Capacity|Electricity|Hydrogen|OC (GW)";"NA"; +"NA";"Capacity|Electricity|Ocean (GW)";"NA"; +"NA";"Capacity|Electricity|Other (GW)";"NA"; +"NA";"Capacity|Electricity|Storage (GW)";"NA"; +"NA";"Capacity|Electricity|Storage|CAES (GW)";"NA"; +"NA";"Capacity|Electricity|Storage|Hydro Dam Reservoir (GW)";"NA"; +"NA";"Capacity|Electricity|Storage|Pump Hydro (GW)";"NA"; +"NA";"Capacity|Electricity|Storage|Stationary Batteries (GW)";"NA"; +"NA";"Capacity|Electricity|Storage|Vehicles (GW)";"NA"; +"NA";"Capacity|Electricity|Transmission Grid (GWkm)";"NA"; +"NA";"Capacity|Electricity|Wind|Offshore (GW)";"NA"; +"Carbon Management|Carbon Sinks|Storage (Mt CO2/yr)";"Carbon Management|Carbon Capture (Mt CO2/yr)";1; +"Emi|CO2|Carbon Capture and Storage|Biomass (Mt CO2/yr)";"Carbon Management|Carbon Capture|Primary Energy|Biomass (Mt CO2/yr)";1; +"Emi|CO2|Carbon Capture and Storage|Fossil|Pe2Se (Mt CO2/yr)";"Carbon Management|Carbon Capture|Primary Energy|Fossil (Mt CO2/yr)";1; +"Carbon Sequestration|Direct Air Capture (Mt CO2/yr)";"Carbon Management|Carbon Capture|Process|Direct Air Capture (Mt CO2/yr)";1; +"Carbon Management|Carbon Sinks|Storage|Biomass|Pe2Se (Mt CO2/yr)";"Carbon Management|Carbon Capture|Process|Energy (Mt CO2/yr)";1; +"NA";"Carbon Management|Carbon Capture|Process|Energy|Electricity (Mt CO2/yr)";"NA"; +"Carbon Management|Carbon Capture|Process|Energy|Other (Mt CO2/yr)";"Carbon Management|Carbon Capture|Process|Energy|Other (Mt CO2/yr)";1; +"NA";"Carbon Management|Carbon Capture|Process|Industrial Processes (Mt CO2/yr)";"NA";"Carbon Management|Carbon Sinks|Storage|+|Industry Energy (Mt CO2/yr) + Carbon Management|Carbon Sources|+|Industry Process (Mt CO2/yr)" +"Carbon Sequestration|CCU (Mt CO2/yr)";"Carbon Management|CCU (Mt CO2/yr)";1; +"Emissions|CO2|AFOLU (Mt CO2/yr)";"Carbon Management|Land Use (Mt CO2/yr)";-1; +"Carbon Sequestration|CCS (Mt CO2/yr)";"Carbon Management|Underground Storage (Mt CO2/yr)";1; +"NA";"Economy|Capital Stock|Residential and Commercial (billion EUR2015/yr)";"NA"; +"NA";"Economy|Capital Stock|Residential and Commercial|Appliances and Lighting (billion EUR2015/yr)";"NA"; +"NA";"Economy|Capital Stock|Residential and Commercial|Insulation (billion EUR2015/yr)";"NA"; +"NA";"Economy|Capital Stock|Residential and Commercial|Space Cooling (billion EUR2015/yr)";"NA"; +"NA";"Economy|Capital Stock|Residential and Commercial|Space Heating (billion EUR2015/yr)";"NA"; +"NA";"Economy|Capital Stock|Residential and Commercial|Water Heating and Cooking (billion EUR2015/yr)";"NA"; +"NA";"Economy|Capital Stock|Residential and Commercial|Water Heating and Cooking|Cooking (billion EUR2015/yr)";"NA"; +"NA";"Economy|Capital Stock|Residential and Commercial|Water Heating and Cooking|Water Heating (billion EUR2015/yr)";"NA"; +"NA";"Emissions|CO2|Energy|Demand|AFOFI (Mt CO2/yr)";"NA"; +"NA";"Emissions|CO2|Energy|Demand|Commercial (Mt CO2/yr)";"NA"; +"NA";"Emissions|CO2|Energy|Demand|Other Sector (Mt CO2/yr)";"NA"; +"NA";"Emissions|CO2|Energy|Demand|Residential (Mt CO2/yr)";"NA"; +"NA";"Emissions|CO2|Energy|Demand|Transportation|Freight (Mt CO2/yr)";"NA"; +"NA";"Emissions|CO2|Energy|Demand|Transportation|Passenger (Mt CO2/yr)";"NA"; +"NA";"Emissions|CO2|Energy|Supply (Gross)|Industry (Mt CO2/yr)";"NA"; +"NA";"Emissions|CO2|Energy|Supply (Gross)|Residential and Commercial (Mt CO2/yr)";"NA"; +"NA";"Emissions|CO2|Energy|Supply (Gross)|Transportation (Mt CO2/yr)";"NA"; +"NA";"Emissions|Kyoto Gases|AFOLU (Mt CO2eq/yr)";"NA"; +"NA";"Emissions|Kyoto Gases|Energy (Mt CO2eq/yr)";"NA"; +"NA";"Emissions|Kyoto Gases|Industrial Processes (Mt CO2eq/yr)";"NA"; +"NA";"Emissions|Kyoto Gases|Other (Mt CO2eq/yr)";"NA"; +"NA";"Emissions|NOx (Mt NOx/yr)";"NA"; +"NA";"Final Energy|Carbon Dioxide Removal|Heat (PJ/yr)";"NA"; +"NA";"Final Energy|Carbon Dioxide Removal|Other (PJ/yr)";"NA"; +"NA";"Final Energy|Industry|Cement (PJ/yr)";"NA"; +"NA";"Final Energy|Industry|Cement|Electricity (PJ/yr)";"NA"; +"NA";"Final Energy|Industry|Cement|Gases (PJ/yr)";"NA"; +"NA";"Final Energy|Industry|Cement|Heat (PJ/yr)";"NA"; +"NA";"Final Energy|Industry|Cement|Hydrogen (PJ/yr)";"NA"; +"NA";"Final Energy|Industry|Cement|Liquids (PJ/yr)";"NA"; +"NA";"Final Energy|Industry|Cement|Solids (PJ/yr)";"NA"; +"NA";"Final Energy|Industry|Chemicals (PJ/yr)";"NA"; +"NA";"Final Energy|Industry|Chemicals|Electricity (PJ/yr)";"NA"; +"NA";"Final Energy|Industry|Chemicals|Gases (PJ/yr)";"NA"; +"NA";"Final Energy|Industry|Chemicals|Heat (PJ/yr)";"NA"; +"NA";"Final Energy|Industry|Chemicals|Hydrogen (PJ/yr)";"NA"; +"NA";"Final Energy|Industry|Chemicals|Liquids (PJ/yr)";"NA"; +"NA";"Final Energy|Industry|Chemicals|Solids (PJ/yr)";"NA"; +"NA";"Final Energy|Industry|Other (PJ/yr)";"NA"; +"NA";"Final Energy|Industry|other Industries (PJ/yr)";"NA"; +"NA";"Final Energy|Industry|other Industries|Electricity (PJ/yr)";"NA"; +"NA";"Final Energy|Industry|other Industries|Gases (PJ/yr)";"NA"; +"NA";"Final Energy|Industry|other Industries|Heat (PJ/yr)";"NA"; +"NA";"Final Energy|Industry|other Industries|Hydrogen (PJ/yr)";"NA"; +"NA";"Final Energy|Industry|other Industries|Liquids (PJ/yr)";"NA"; +"NA";"Final Energy|Industry|other Industries|Solids (PJ/yr)";"NA"; +"NA";"Final Energy|Industry|Steel (PJ/yr)";"NA"; +"NA";"Final Energy|Industry|Steel|Electricity (PJ/yr)";"NA"; +"NA";"Final Energy|Industry|Steel|Gases (PJ/yr)";"NA"; +"NA";"Final Energy|Industry|Steel|Heat (PJ/yr)";"NA"; +"NA";"Final Energy|Industry|Steel|Hydrogen (PJ/yr)";"NA"; +"NA";"Final Energy|Industry|Steel|Liquids (PJ/yr)";"NA"; +"NA";"Final Energy|Industry|Steel|Solids (PJ/yr)";"NA"; +"NA";"Final Energy|Non-Energy Use (PJ/yr)";"NA"; +"NA";"Final Energy|Non-Energy Use|Gases (PJ/yr)";"NA"; +"NA";"Final Energy|Non-Energy Use|Liquids (PJ/yr)";"NA"; +"NA";"Final Energy|Non-Energy Use|Solids (PJ/yr)";"NA"; +"NA";"Final Energy|Other (PJ/yr)";"NA"; +"NA";"Final Energy|Other Sector (PJ/yr)";"NA"; +"NA";"Final Energy|Other Sector|Electricity (PJ/yr)";"NA"; +"NA";"Final Energy|Other Sector|Gases (PJ/yr)";"NA"; +"NA";"Final Energy|Other Sector|Heat (PJ/yr)";"NA"; +"NA";"Final Energy|Other Sector|Hydrogen (PJ/yr)";"NA"; +"NA";"Final Energy|Other Sector|Liquids (PJ/yr)";"NA"; +"NA";"Final Energy|Other Sector|Other (PJ/yr)";"NA"; +"NA";"Final Energy|Other Sector|Solids (PJ/yr)";"NA"; +"NA";"Final Energy|Residential and Commercial|Appliances and Lighting|Gases (PJ/yr)";"NA"; +"NA";"Final Energy|Residential and Commercial|Appliances and Lighting|Heat (PJ/yr)";"NA"; +"NA";"Final Energy|Residential and Commercial|Appliances and Lighting|Hydrogen (PJ/yr)";"NA"; +"NA";"Final Energy|Residential and Commercial|Appliances and Lighting|Liquids (PJ/yr)";"NA"; +"NA";"Final Energy|Residential and Commercial|Appliances and Lighting|Other (PJ/yr)";"NA"; +"NA";"Final Energy|Residential and Commercial|Appliances and Lighting|Solids (PJ/yr)";"NA"; +"NA";"Final Energy|Residential and Commercial|Cooking (PJ/yr)";"NA"; +"NA";"Final Energy|Residential and Commercial|Cooking|Electricity (PJ/yr)";"NA"; +"NA";"Final Energy|Residential and Commercial|Cooking|Electricity|Heat Pumps (PJ/yr)";"NA"; +"NA";"Final Energy|Residential and Commercial|Cooking|Electricity|Resistive (PJ/yr)";"NA"; +"NA";"Final Energy|Residential and Commercial|Cooking|Gases (PJ/yr)";"NA"; +"NA";"Final Energy|Residential and Commercial|Cooking|Heat (PJ/yr)";"NA"; +"NA";"Final Energy|Residential and Commercial|Cooking|Hydrogen (PJ/yr)";"NA"; +"NA";"Final Energy|Residential and Commercial|Cooking|Liquids (PJ/yr)";"NA"; +"NA";"Final Energy|Residential and Commercial|Cooking|Other (PJ/yr)";"NA"; +"NA";"Final Energy|Residential and Commercial|Cooking|Solids (PJ/yr)";"NA"; +"NA";"Final Energy|Residential and Commercial|Other (PJ/yr)";"NA"; +"NA";"Final Energy|Residential and Commercial|Space Cooling|Electricity|Heat Pumps (PJ/yr)";"NA"; +"NA";"Final Energy|Residential and Commercial|Space Cooling|Electricity|Resistive (PJ/yr)";"NA"; +"NA";"Final Energy|Residential and Commercial|Space Cooling|Gases (PJ/yr)";"NA"; +"NA";"Final Energy|Residential and Commercial|Space Cooling|Heat (PJ/yr)";"NA"; +"NA";"Final Energy|Residential and Commercial|Space Cooling|Hydrogen (PJ/yr)";"NA"; +"NA";"Final Energy|Residential and Commercial|Space Cooling|Liquids (PJ/yr)";"NA"; +"NA";"Final Energy|Residential and Commercial|Space Cooling|Other (PJ/yr)";"NA"; +"NA";"Final Energy|Residential and Commercial|Space Cooling|Solids (PJ/yr)";"NA"; +"NA";"Final Energy|Residential and Commercial|Space Heating|Other (PJ/yr)";"NA"; +"NA";"Final Energy|Residential and Commercial|Water Heating (PJ/yr)";"NA"; +"NA";"Final Energy|Residential and Commercial|Water Heating and Cooking|Other (PJ/yr)";"NA"; +"NA";"Final Energy|Residential and Commercial|Water Heating|Electricity (PJ/yr)";"NA"; +"NA";"Final Energy|Residential and Commercial|Water Heating|Electricity|Heat Pumps (PJ/yr)";"NA"; +"NA";"Final Energy|Residential and Commercial|Water Heating|Electricity|Resistive (PJ/yr)";"NA"; +"NA";"Final Energy|Residential and Commercial|Water Heating|Gases (PJ/yr)";"NA"; +"NA";"Final Energy|Residential and Commercial|Water Heating|Heat (PJ/yr)";"NA"; +"NA";"Final Energy|Residential and Commercial|Water Heating|Hydrogen (PJ/yr)";"NA"; +"NA";"Final Energy|Residential and Commercial|Water Heating|Liquids (PJ/yr)";"NA"; +"NA";"Final Energy|Residential and Commercial|Water Heating|Other (PJ/yr)";"NA"; +"NA";"Final Energy|Residential and Commercial|Water Heating|Solids (PJ/yr)";"NA"; +"NA";"Final Energy|Transportation|Freight|Domestic Airplane (PJ/yr)";"NA"; +"NA";"Final Energy|Transportation|Freight|Domestic Airplane|Electricity (PJ/yr)";"NA"; +"NA";"Final Energy|Transportation|Freight|Domestic Airplane|Hydrogen (PJ/yr)";"NA"; +"NA";"Final Energy|Transportation|Freight|Domestic Airplane|Liquids (PJ/yr)";"NA"; +"FE|Transport|Freight|Electricity (EJ/yr)";"Final Energy|Transportation|Freight|Electricity (PJ/yr)";0.001; +"FE|Transport|Freight|Gases (EJ/yr)";"Final Energy|Transportation|Freight|Gases (PJ/yr)";0.001; +"FE|Transport|Freight|Hydrogen (EJ/yr)";"Final Energy|Transportation|Freight|Hydrogen (PJ/yr)";0.001; +"NA";"Final Energy|Transportation|Freight|International (PJ/yr)";"NA"; +"NA";"Final Energy|Transportation|Freight|International|Electricty (PJ/yr)";"NA"; +"NA";"Final Energy|Transportation|Freight|International|Gases (PJ/yr)";"NA"; +"NA";"Final Energy|Transportation|Freight|International|Hydrogen (PJ/yr)";"NA"; +"NA";"Final Energy|Transportation|Freight|International|Liquids (PJ/yr)";"NA"; +"NA";"Final Energy|Transportation|Freight|International|Solids (PJ/yr)";"NA"; +"FE|Transport|Freight|Liquids (EJ/yr)";"Final Energy|Transportation|Freight|Liquids (PJ/yr)";0.001; +"NA";"Final Energy|Transportation|Freight|Other (PJ/yr)";"NA"; +"FE|Transport|Freight|Shipping (EJ/yr)";"Final Energy|Transportation|Freight|Ship (PJ/yr)";0.001; +"NA";"Final Energy|Transportation|Freight|Ship|Electricity (PJ/yr)";"NA"; +"NA";"Final Energy|Transportation|Freight|Ship|Gases (PJ/yr)";"NA"; +"NA";"Final Energy|Transportation|Freight|Ship|Hydrogen (PJ/yr)";"NA"; +"NA";"Final Energy|Transportation|Freight|Ship|Liquids (PJ/yr)";"NA"; +"NA";"Final Energy|Transportation|Freight|Ship|Solids (PJ/yr)";"NA"; +"NA";"Final Energy|Transportation|Freight|Solids (PJ/yr)";"NA"; +"FE|Transport|Freight|Rail (EJ/yr)";"Final Energy|Transportation|Freight|Train (PJ/yr)";0.001; +"NA";"Final Energy|Transportation|Freight|Train|Electricity (PJ/yr)";"NA"; +"NA";"Final Energy|Transportation|Freight|Train|Gases (PJ/yr)";"NA"; +"NA";"Final Energy|Transportation|Freight|Train|Hydrogen (PJ/yr)";"NA"; +"NA";"Final Energy|Transportation|Freight|Train|Liquids (PJ/yr)";"NA"; +"NA";"Final Energy|Transportation|Freight|Train|Solids (PJ/yr)";"NA"; +"FE|Transport|Freight|Road (EJ/yr)";"Final Energy|Transportation|Freight|Trucks (PJ/yr)";0.001; +"FE|Transport|Freight|Road|Electricity (EJ/yr)";"Final Energy|Transportation|Freight|Trucks|Electricity (PJ/yr)";0.001; +"NA";"Final Energy|Transportation|Freight|Trucks|Gases (PJ/yr)";"NA"; +"FE|Transport|Freight|Road|Hydrogen (EJ/yr)";"Final Energy|Transportation|Freight|Trucks|Hydrogen (PJ/yr)";0.001; +"FE|Transport|Freight|Road|Liquids (EJ/yr)";"Final Energy|Transportation|Freight|Trucks|Liquids (PJ/yr)";0.001; +"NA";"Final Energy|Transportation|Freight|within Europe (PJ/yr)";"NA"; +"NA";"Final Energy|Transportation|Freight|within Europe|Electricty (PJ/yr)";"NA"; +"NA";"Final Energy|Transportation|Freight|within Europe|Gases (PJ/yr)";"NA"; +"NA";"Final Energy|Transportation|Freight|within Europe|Hydrogen (PJ/yr)";"NA"; +"NA";"Final Energy|Transportation|Freight|within Europe|Liquids (PJ/yr)";"NA"; +"NA";"Final Energy|Transportation|Freight|within Europe|Solids (PJ/yr)";"NA"; +"FE|Transport|Gases (EJ/yr)";"Final Energy|Transportation|Gases (PJ/yr)";0.001; +"NA";"Final Energy|Transportation|Other (PJ/yr)";"NA"; +"NA";"Final Energy|Transportation|Passenger|Domestic Airplane (PJ/yr)";"NA"; +"NA";"Final Energy|Transportation|Passenger|Domestic Airplane|Electricity (PJ/yr)";"NA"; +"NA";"Final Energy|Transportation|Passenger|Domestic Airplane|Hydrogen (PJ/yr)";"NA"; +"NA";"Final Energy|Transportation|Passenger|Domestic Airplane|Liquids (PJ/yr)";"NA"; +"FE|Transport|Pass|Gases (EJ/yr)";"Final Energy|Transportation|Passenger|Gases (PJ/yr)";0.001; +"NA";"Final Energy|Transportation|Passenger|HDV|Electricity (PJ/yr)";"NA"; +"NA";"Final Energy|Transportation|Passenger|HDV|Gases (PJ/yr)";"NA"; +"NA";"Final Energy|Transportation|Passenger|HDV|Hydrogen (PJ/yr)";"NA"; +"NA";"Final Energy|Transportation|Passenger|HDV|Liquids (PJ/yr)";"NA"; +"NA";"Final Energy|Transportation|Passenger|International (PJ/yr)";"NA"; +"NA";"Final Energy|Transportation|Passenger|International|Electricty (PJ/yr)";"NA"; +"NA";"Final Energy|Transportation|Passenger|International|Gases (PJ/yr)";"NA"; +"NA";"Final Energy|Transportation|Passenger|International|Hydrogen (PJ/yr)";"NA"; +"NA";"Final Energy|Transportation|Passenger|International|Liquids (PJ/yr)";"NA"; +"NA";"Final Energy|Transportation|Passenger|International|Solids (PJ/yr)";"NA"; +"NA";"Final Energy|Transportation|Passenger|LDV|Gases (PJ/yr)";"NA"; +"FE|Transport|Pass|Liquids (EJ/yr)";"Final Energy|Transportation|Passenger|Liquids (PJ/yr)";0.001; +"NA";"Final Energy|Transportation|Passenger|Ship (PJ/yr)";"NA"; +"NA";"Final Energy|Transportation|Passenger|Ship|Electricity (PJ/yr)";"NA"; +"NA";"Final Energy|Transportation|Passenger|Ship|Gases (PJ/yr)";"NA"; +"NA";"Final Energy|Transportation|Passenger|Ship|Hydrogen (PJ/yr)";"NA"; +"NA";"Final Energy|Transportation|Passenger|Ship|Liquids (PJ/yr)";"NA"; +"NA";"Final Energy|Transportation|Passenger|Ship|Solids (PJ/yr)";"NA"; +"NA";"Final Energy|Transportation|Passenger|Solids (PJ/yr)";"NA"; +"FE|Transport|Pass|Rail (EJ/yr)";"Final Energy|Transportation|Passenger|Train (PJ/yr)";0.001; +"NA";"Final Energy|Transportation|Passenger|Train|Gases (PJ/yr)";"NA"; +"NA";"Final Energy|Transportation|Passenger|Train|Hydrogen (PJ/yr)";"NA"; +"NA";"Final Energy|Transportation|Passenger|Train|Liquids (PJ/yr)";"NA"; +"NA";"Final Energy|Transportation|Passenger|Train|Solids (PJ/yr)";"NA"; +"NA";"Final Energy|Transportation|Passenger|within Europe (PJ/yr)";"NA"; +"NA";"Final Energy|Transportation|Passenger|within Europe|Electricty (PJ/yr)";"NA"; +"NA";"Final Energy|Transportation|Passenger|within Europe|Gases (PJ/yr)";"NA"; +"NA";"Final Energy|Transportation|Passenger|within Europe|Hydrogen (PJ/yr)";"NA"; +"NA";"Final Energy|Transportation|Passenger|within Europe|Liquids (PJ/yr)";"NA"; +"NA";"Final Energy|Transportation|Passenger|within Europe|Solids (PJ/yr)";"NA"; +"NA";"Price|Carbon|ETS (EUR2015/t CO2)";"NA"; +"NA";"Price|Carbon|EU-wide Regulation Non-ETS (EUR2015/t CO2)";"NA"; +"NA";"Price|Carbon|National Climate Target (EUR2015/t CO2)";"NA"; +"NA";"Price|Carbon|National Climate Target Non-ETS (EUR2015/t CO2)";"NA"; +"NA";"Price|Carbon|Net|Electricity (EUR2015/t CO2)";"NA"; +"NA";"Price|Carbon|Net|Industry (EUR2015/t CO2)";"NA"; +"NA";"Price|Carbon|Net|Residential and Commercial (EUR2015/t CO2)";"NA"; +"NA";"Price|Final Energy|Transportation|Freight|Electricity (EUR2015/GJ)";"NA"; +"NA";"Price|Final Energy|Transportation|Freight|Gases (EUR2015/GJ)";"NA"; +"NA";"Price|Final Energy|Transportation|Freight|Hydrogen (EUR2015/GJ)";"NA"; +"NA";"Price|Final Energy|Transportation|Freight|Liquids (EUR2015/GJ)";"NA"; +"NA";"Price|Final Energy|Transportation|Freight|Solids (EUR2015/GJ)";"NA"; +"NA";"Price|Final Energy|Transportation|Passenger|Electricity (EUR2015/GJ)";"NA"; +"NA";"Price|Final Energy|Transportation|Passenger|Gases (EUR2015/GJ)";"NA"; +"NA";"Price|Final Energy|Transportation|Passenger|Hydrogen (EUR2015/GJ)";"NA"; +"NA";"Price|Final Energy|Transportation|Passenger|Liquids (EUR2015/GJ)";"NA"; +"NA";"Price|Final Energy|Transportation|Passenger|Solids (EUR2015/GJ)";"NA"; +"NA";"Primary Energy|Biomass|Gases|w/ CCS (PJ/yr)";"NA"; +"NA";"Primary Energy|Biomass|Gases|w/o CCS (PJ/yr)";"NA"; +"NA";"Primary Energy|Biomass|Other (PJ/yr)";"NA"; +"NA";"Primary Energy|Coal|Other (PJ/yr)";"NA"; +"NA";"Primary Energy|Gas|Other (PJ/yr)";"NA"; +"NA";"Primary Energy|Ocean (PJ/yr)";"NA"; +"NA";"Primary Energy|Oil|Electricity (PJ/yr)";"NA"; +"NA";"Primary Energy|Oil|Heat (PJ/yr)";"NA"; +"NA";"Primary Energy|Oil|Hydrogen (PJ/yr)";"NA"; +"NA";"Primary Energy|Oil|Liquids (PJ/yr)";"NA"; +"NA";"Primary Energy|Oil|Other (PJ/yr)";"NA"; +"NA";"Primary Energy|Oil|w/ CCS (PJ/yr)";"NA"; +"NA";"Primary Energy|Other (PJ/yr)";"NA"; +"NA";"Secondary Energy|Electricity|Coal|Hard Coal (TWh/yr)";"NA"; +"NA";"Secondary Energy|Electricity|Coal|Lignite (TWh/yr)";"NA"; +"NA";"Secondary Energy|Electricity|Curtailment (TWh/yr)";"NA"; +"NA";"Secondary Energy|Electricity|Gas|CC (TWh/yr)";"NA"; +"NA";"Secondary Energy|Electricity|Gas|CC|w/ CCS (TWh/yr)";"NA"; +"NA";"Secondary Energy|Electricity|Gas|OC (TWh/yr)";"NA"; +"NA";"Secondary Energy|Electricity|Hydrogen|CC (TWh/yr)";"NA"; +"NA";"Secondary Energy|Electricity|Hydrogen|FC (TWh/yr)";"NA"; +"NA";"Secondary Energy|Electricity|Hydrogen|OC (TWh/yr)";"NA"; +"NA";"Secondary Energy|Electricity|Losses (TWh/yr)";"NA"; +"NA";"Secondary Energy|Electricity|Net Imports (TWh/yr)";"NA"; +"NA";"Secondary Energy|Electricity|Ocean (TWh/yr)";"NA"; +"NA";"Secondary Energy|Electricity|Other (TWh/yr)";"NA"; +"NA";"Secondary Energy|Electricity|Storage (TWh/yr)";"NA"; +"NA";"Secondary Energy|Electricity|Storage Losses (TWh/yr)";"NA"; +"NA";"Secondary Energy|Electricity|Transmission Losses (TWh/yr)";"NA"; +"NA";"Secondary Energy|Electricity|Wind|Offshore (TWh/yr)";"NA"; +"NA";"Secondary Energy|Electricity|Wind|Onshore (TWh/yr)";"NA"; +"SE|Gases|Hydrogen (EJ/yr)";"Secondary Energy|Gases|Hydrogen (PJ/yr)";0.001; +"NA";"Secondary Energy|Gases|Other (PJ/yr)";"NA"; +"NA";"Secondary Energy|Heat|Biomass|w/ CCS (PJ/yr)";"NA"; +"NA";"Secondary Energy|Heat|Biomass|w/o CCS (PJ/yr)";"NA"; +"NA";"Secondary Energy|Heat|Electricity|Heat Pumps (PJ/yr)";"NA"; +"NA";"Secondary Energy|Heat|Electricity|Resistive (PJ/yr)";"NA"; +"NA";"Secondary Energy|Heat|Nuclear (PJ/yr)";"NA"; +"NA";"Secondary Energy|Heat|Oil (PJ/yr)";"NA"; +"NA";"Secondary Energy|Heat|Other (PJ/yr)";"NA"; +"NA";"Secondary Energy|Heat|Solar (PJ/yr)";"NA"; +"NA";"Secondary Energy|Hydrogen|Nuclear (PJ/yr)";"NA"; +"NA";"Secondary Energy|Hydrogen|Oil (PJ/yr)";"NA"; +"NA";"Secondary Energy|Hydrogen|Other (PJ/yr)";"NA"; +"NA";"Secondary Energy|Hydrogen|Solar (PJ/yr)";"NA"; +"SE|Liquids|Hydrogen (EJ/yr)";"Secondary Energy|Liquids|Hydrogen (PJ/yr)";0.001; +"NA";"Secondary Energy|Liquids|Other (PJ/yr)";"NA"; +"NA";"Secondary Energy|Other Carrier (PJ/yr)";"NA"; +"NA";"Services and Products|Industry|Cement|Physical (Mt/yr)";"NA"; +"NA";"Services and Products|Industry|Chemicals|Value Added (EUR2015/yr)";"NA"; +"NA";"Services and Products|Industry|Other Industries|Value Added (EUR2015/yr)";"NA"; +"NA";"Services and Products|Industry|Steel|Physical (Mt/yr)";"NA"; +"NA";"Services and Products|Transportation|Freight|Domestic Airplane (Gtkm/yr)";"NA"; +"NA";"Services and Products|Transportation|Freight|International (Gtkm/yr)";"NA"; +"NA";"Services and Products|Transportation|Freight|Other (Gtkm/yr)";"NA"; +"NA";"Services and Products|Transportation|Freight|Ship (Gtkm/yr)";"NA"; +"NA";"Services and Products|Transportation|Freight|Train (Gtkm/yr)";"NA"; +"NA";"Services and Products|Transportation|Freight|Trucks (Gtkm/yr)";"NA"; +"NA";"Services and Products|Transportation|Freight|within Europe (Gtkm/yr)";"NA"; +"NA";"Services and Products|Transportation|Passenger|Domestic Airplane (Gpkm/yr)";"NA"; +"NA";"Services and Products|Transportation|Passenger|International (Gpkm/yr)";"NA"; +"NA";"Services and Products|Transportation|Passenger|Other (Gpkm/yr)";"NA"; +"NA";"Services and Products|Transportation|Passenger|Ship (Gpkm/yr)";"NA"; +"NA";"Services and Products|Transportation|Passenger|Train (Gpkm/yr)";"NA"; +"NA";"Services and Products|Transportation|Passenger|within Europe (Gpkm/yr)";"NA"; +"NA";"Total Energy System Cost|CO2 Costs (billion EUR2015/yr)";"NA"; +"NA";"Total Energy System Cost|Energy Supply (billion EUR2015/yr)";"NA"; +"NA";"Total Energy System Cost|Energy Supply|CO2 Costs (billion EUR2015/yr)";"NA"; +"NA";"Total Energy System Cost|Energy Supply|Fuel Costs (billion EUR2015/yr)";"NA"; +"NA";"Total Energy System Cost|Energy Supply|Investments (billion EUR2015/yr)";"NA"; +"NA";"Total Energy System Cost|Energy Supply|O&M Costs (billion EUR2015/yr)";"NA"; +"NA";"Total Energy System Cost|Energy Supply|Trade Costs (billion EUR2015/yr)";"NA"; +"NA";"Total Energy System Cost|Fuel Costs (billion EUR2015/yr)";"NA"; +"NA";"Total Energy System Cost|Investments (billion EUR2015/yr)";"NA"; +"NA";"Total Energy System Cost|Power Sector|CO2 Costs (billion EUR2015/yr)";"NA"; +"NA";"Total Energy System Cost|Power Sector|Fuel Costs (billion EUR2015/yr)";"NA"; +"NA";"Total Energy System Cost|Power Sector|Investments (billion EUR2015/yr)";"NA"; +"NA";"Total Energy System Cost|Power Sector|O&M Costs (billion EUR2015/yr)";"NA"; +"NA";"Total Energy System Cost|Power Sector|Trade Costs (billion EUR2015/yr)";"NA"; +"NA";"Total Energy System Cost|Trade Costs (billion EUR2015/yr)";"NA"; +"NA";"Trade|Secondary Energy|Electricity|Volume (PJ/yr)";"NA"; +"NA";"Useful Energy|Residential and Commercial|Appliances and Lighting|Gases (PJ/yr)";"NA"; +"NA";"Useful Energy|Residential and Commercial|Appliances and Lighting|Heat (PJ/yr)";"NA"; +"NA";"Useful Energy|Residential and Commercial|Appliances and Lighting|Hydrogen (PJ/yr)";"NA"; +"NA";"Useful Energy|Residential and Commercial|Appliances and Lighting|Liquids (PJ/yr)";"NA"; +"NA";"Useful Energy|Residential and Commercial|Appliances and Lighting|Solids (PJ/yr)";"NA"; +"NA";"Useful Energy|Residential and Commercial|Cooking (PJ/yr)";"NA"; +"NA";"Useful Energy|Residential and Commercial|Cooking|Electricity (PJ/yr)";"NA"; +"NA";"Useful Energy|Residential and Commercial|Cooking|Electricity|Heat Pumps (PJ/yr)";"NA"; +"NA";"Useful Energy|Residential and Commercial|Cooking|Electricity|Resistive (PJ/yr)";"NA"; +"NA";"Useful Energy|Residential and Commercial|Cooking|Gases (PJ/yr)";"NA"; +"NA";"Useful Energy|Residential and Commercial|Cooking|Heat (PJ/yr)";"NA"; +"NA";"Useful Energy|Residential and Commercial|Cooking|Hydrogen (PJ/yr)";"NA"; +"NA";"Useful Energy|Residential and Commercial|Cooking|Liquids (PJ/yr)";"NA"; +"NA";"Useful Energy|Residential and Commercial|Cooking|Solids (PJ/yr)";"NA"; +"NA";"Useful Energy|Residential and Commercial|Space Cooling|Gases (PJ/yr)";"NA"; +"NA";"Useful Energy|Residential and Commercial|Space Cooling|Heat (PJ/yr)";"NA"; +"NA";"Useful Energy|Residential and Commercial|Space Cooling|Hydrogen (PJ/yr)";"NA"; +"NA";"Useful Energy|Residential and Commercial|Space Cooling|Liquids (PJ/yr)";"NA"; +"NA";"Useful Energy|Residential and Commercial|Space Cooling|Solids (PJ/yr)";"NA"; +"NA";"Useful Energy|Residential and Commercial|Water Heating (PJ/yr)";"NA"; +"NA";"Useful Energy|Residential and Commercial|Water Heating|Electricity (PJ/yr)";"NA"; +"NA";"Useful Energy|Residential and Commercial|Water Heating|Electricity|Heat Pumps (PJ/yr)";"NA"; +"NA";"Useful Energy|Residential and Commercial|Water Heating|Electricity|Resistive (PJ/yr)";"NA"; +"NA";"Useful Energy|Residential and Commercial|Water Heating|Gases (PJ/yr)";"NA"; +"NA";"Useful Energy|Residential and Commercial|Water Heating|Heat (PJ/yr)";"NA"; +"NA";"Useful Energy|Residential and Commercial|Water Heating|Hydrogen (PJ/yr)";"NA"; +"NA";"Useful Energy|Residential and Commercial|Water Heating|Liquids (PJ/yr)";"NA"; +"NA";"Useful Energy|Residential and Commercial|Water Heating|Solids (PJ/yr)";"NA"; +"NA";"Useful Energy|Transportation (PJ/yr)";"NA"; +"NA";"Useful Energy|Transportation|Electricity (PJ/yr)";"NA"; +"NA";"Useful Energy|Transportation|Freight (PJ/yr)";"NA"; +"NA";"Useful Energy|Transportation|Freight|Domestic Airplane (PJ/yr)";"NA"; +"NA";"Useful Energy|Transportation|Freight|Domestic Airplane|Electricity (PJ/yr)";"NA"; +"NA";"Useful Energy|Transportation|Freight|Domestic Airplane|Hydrogen (PJ/yr)";"NA"; +"NA";"Useful Energy|Transportation|Freight|Domestic Airplane|Liquids (PJ/yr)";"NA"; +"NA";"Useful Energy|Transportation|Freight|Electricity (PJ/yr)";"NA"; +"NA";"Useful Energy|Transportation|Freight|Gases (PJ/yr)";"NA"; +"NA";"Useful Energy|Transportation|Freight|Hydrogen (PJ/yr)";"NA"; +"NA";"Useful Energy|Transportation|Freight|International (PJ/yr)";"NA"; +"NA";"Useful Energy|Transportation|Freight|International|Electricty (PJ/yr)";"NA"; +"NA";"Useful Energy|Transportation|Freight|International|Gases (PJ/yr)";"NA"; +"NA";"Useful Energy|Transportation|Freight|International|Hydrogen (PJ/yr)";"NA"; +"NA";"Useful Energy|Transportation|Freight|International|Liquids (PJ/yr)";"NA"; +"NA";"Useful Energy|Transportation|Freight|International|Solids (PJ/yr)";"NA"; +"NA";"Useful Energy|Transportation|Freight|Liquids (PJ/yr)";"NA"; +"NA";"Useful Energy|Transportation|Freight|Other (PJ/yr)";"NA"; +"NA";"Useful Energy|Transportation|Freight|Ship (PJ/yr)";"NA"; +"NA";"Useful Energy|Transportation|Freight|Ship|Electricity (PJ/yr)";"NA"; +"NA";"Useful Energy|Transportation|Freight|Ship|Gases (PJ/yr)";"NA"; +"NA";"Useful Energy|Transportation|Freight|Ship|Hydrogen (PJ/yr)";"NA"; +"NA";"Useful Energy|Transportation|Freight|Ship|Liquids (PJ/yr)";"NA"; +"NA";"Useful Energy|Transportation|Freight|Ship|Solids (PJ/yr)";"NA"; +"NA";"Useful Energy|Transportation|Freight|Solids (PJ/yr)";"NA"; +"NA";"Useful Energy|Transportation|Freight|Train (PJ/yr)";"NA"; +"NA";"Useful Energy|Transportation|Freight|Train|Electricity (PJ/yr)";"NA"; +"NA";"Useful Energy|Transportation|Freight|Train|Gases (PJ/yr)";"NA"; +"NA";"Useful Energy|Transportation|Freight|Train|Hydrogen (PJ/yr)";"NA"; +"NA";"Useful Energy|Transportation|Freight|Train|Liquids (PJ/yr)";"NA"; +"NA";"Useful Energy|Transportation|Freight|Train|Solids (PJ/yr)";"NA"; +"NA";"Useful Energy|Transportation|Freight|Trucks (PJ/yr)";"NA"; +"NA";"Useful Energy|Transportation|Freight|Trucks|Electricity (PJ/yr)";"NA"; +"NA";"Useful Energy|Transportation|Freight|Trucks|Gases (PJ/yr)";"NA"; +"NA";"Useful Energy|Transportation|Freight|Trucks|Hydrogen (PJ/yr)";"NA"; +"NA";"Useful Energy|Transportation|Freight|Trucks|Liquids (PJ/yr)";"NA"; +"NA";"Useful Energy|Transportation|Freight|within Europe (PJ/yr)";"NA"; +"NA";"Useful Energy|Transportation|Freight|within Europe|Electricty (PJ/yr)";"NA"; +"NA";"Useful Energy|Transportation|Freight|within Europe|Gases (PJ/yr)";"NA"; +"NA";"Useful Energy|Transportation|Freight|within Europe|Hydrogen (PJ/yr)";"NA"; +"NA";"Useful Energy|Transportation|Freight|within Europe|Liquids (PJ/yr)";"NA"; +"NA";"Useful Energy|Transportation|Freight|within Europe|Solids (PJ/yr)";"NA"; +"NA";"Useful Energy|Transportation|Gases (PJ/yr)";"NA"; +"NA";"Useful Energy|Transportation|Hydrogen (PJ/yr)";"NA"; +"NA";"Useful Energy|Transportation|Liquids (PJ/yr)";"NA"; +"NA";"Useful Energy|Transportation|Other (PJ/yr)";"NA"; +"NA";"Useful Energy|Transportation|Passenger (PJ/yr)";"NA"; +"NA";"Useful Energy|Transportation|Passenger|Domestic Airplane (PJ/yr)";"NA"; +"NA";"Useful Energy|Transportation|Passenger|Domestic Airplane|Electricity (PJ/yr)";"NA"; +"NA";"Useful Energy|Transportation|Passenger|Domestic Airplane|Hydrogen (PJ/yr)";"NA"; +"NA";"Useful Energy|Transportation|Passenger|Domestic Airplane|Liquids (PJ/yr)";"NA"; +"NA";"Useful Energy|Transportation|Passenger|Electricity (PJ/yr)";"NA"; +"NA";"Useful Energy|Transportation|Passenger|Gases (PJ/yr)";"NA"; +"NA";"Useful Energy|Transportation|Passenger|HDV (PJ/yr)";"NA"; +"NA";"Useful Energy|Transportation|Passenger|HDV|Electricity (PJ/yr)";"NA"; +"NA";"Useful Energy|Transportation|Passenger|HDV|Gases (PJ/yr)";"NA"; +"NA";"Useful Energy|Transportation|Passenger|HDV|Hydrogen (PJ/yr)";"NA"; +"NA";"Useful Energy|Transportation|Passenger|HDV|Liquids (PJ/yr)";"NA"; +"NA";"Useful Energy|Transportation|Passenger|Hydrogen (PJ/yr)";"NA"; +"NA";"Useful Energy|Transportation|Passenger|International (PJ/yr)";"NA"; +"NA";"Useful Energy|Transportation|Passenger|International|Electricty (PJ/yr)";"NA"; +"NA";"Useful Energy|Transportation|Passenger|International|Gases (PJ/yr)";"NA"; +"NA";"Useful Energy|Transportation|Passenger|International|Hydrogen (PJ/yr)";"NA"; +"NA";"Useful Energy|Transportation|Passenger|International|Liquids (PJ/yr)";"NA"; +"NA";"Useful Energy|Transportation|Passenger|International|Solids (PJ/yr)";"NA"; +"NA";"Useful Energy|Transportation|Passenger|LDV (PJ/yr)";"NA"; +"NA";"Useful Energy|Transportation|Passenger|LDV|Electricity (PJ/yr)";"NA"; +"NA";"Useful Energy|Transportation|Passenger|LDV|Gases (PJ/yr)";"NA"; +"NA";"Useful Energy|Transportation|Passenger|LDV|Hydrogen (PJ/yr)";"NA"; +"NA";"Useful Energy|Transportation|Passenger|LDV|Liquids (PJ/yr)";"NA"; +"NA";"Useful Energy|Transportation|Passenger|Liquids (PJ/yr)";"NA"; +"NA";"Useful Energy|Transportation|Passenger|Ship (PJ/yr)";"NA"; +"NA";"Useful Energy|Transportation|Passenger|Ship|Electricity (PJ/yr)";"NA"; +"NA";"Useful Energy|Transportation|Passenger|Ship|Gases (PJ/yr)";"NA"; +"NA";"Useful Energy|Transportation|Passenger|Ship|Hydrogen (PJ/yr)";"NA"; +"NA";"Useful Energy|Transportation|Passenger|Ship|Liquids (PJ/yr)";"NA"; +"NA";"Useful Energy|Transportation|Passenger|Ship|Solids (PJ/yr)";"NA"; +"NA";"Useful Energy|Transportation|Passenger|Solids (PJ/yr)";"NA"; +"NA";"Useful Energy|Transportation|Passenger|Train (PJ/yr)";"NA"; +"NA";"Useful Energy|Transportation|Passenger|Train|Electricity (PJ/yr)";"NA"; +"NA";"Useful Energy|Transportation|Passenger|Train|Gases (PJ/yr)";"NA"; +"NA";"Useful Energy|Transportation|Passenger|Train|Hydrogen (PJ/yr)";"NA"; +"NA";"Useful Energy|Transportation|Passenger|Train|Liquids (PJ/yr)";"NA"; +"NA";"Useful Energy|Transportation|Passenger|Train|Solids (PJ/yr)";"NA"; +"NA";"Useful Energy|Transportation|Passenger|within Europe (PJ/yr)";"NA"; +"NA";"Useful Energy|Transportation|Passenger|within Europe|Electricty (PJ/yr)";"NA"; +"NA";"Useful Energy|Transportation|Passenger|within Europe|Gases (PJ/yr)";"NA"; +"NA";"Useful Energy|Transportation|Passenger|within Europe|Hydrogen (PJ/yr)";"NA"; +"NA";"Useful Energy|Transportation|Passenger|within Europe|Liquids (PJ/yr)";"NA"; +"NA";"Useful Energy|Transportation|Passenger|within Europe|Solids (PJ/yr)";"NA"; +"NA";"Capacity Additions|Electricity (GW/yr)";"NA";"zero values in source" +"NA";"Capacity Additions|Electricity|Biomass (GW/yr)";"NA";"zero values in source" +"NA";"Capacity Additions|Electricity|Biomass|w/ CCS (GW/yr)";"NA";"zero values in source" +"NA";"Capacity Additions|Electricity|Biomass|w/o CCS (GW/yr)";"NA";"zero values in source" +"NA";"Capacity Additions|Electricity|Coal (GW/yr)";"NA";"zero values in source" +"NA";"Capacity Additions|Electricity|Coal|w/ CCS (GW/yr)";"NA";"zero values in source" +"NA";"Capacity Additions|Electricity|Coal|w/o CCS (GW/yr)";"NA";"zero values in source" +"NA";"Capacity Additions|Electricity|Gas (GW/yr)";"NA";"zero values in source" +"NA";"Capacity Additions|Electricity|Gas|CC|w/ CCS (GW/yr)";"NA";"zero values in source" +"NA";"Capacity Additions|Electricity|Gas|CC|w/o CCS (GW/yr)";"NA";"zero values in source" +"NA";"Capacity Additions|Electricity|Gas|w/ CCS (GW/yr)";"NA";"zero values in source" +"NA";"Capacity Additions|Electricity|Gas|w/o CCS (GW/yr)";"NA";"zero values in source" +"NA";"Capacity Additions|Electricity|Hydro (GW/yr)";"NA";"zero values in source" +"NA";"Capacity Additions|Electricity|Hydrogen (GW/yr)";"NA";"zero values in source" +"NA";"Capacity Additions|Electricity|Nuclear (GW/yr)";"NA";"zero values in source" +"NA";"Capacity Additions|Electricity|Solar (GW/yr)";"NA";"zero values in source" +"NA";"Capacity Additions|Electricity|Solar|CSP (GW/yr)";"NA";"zero values in source" +"NA";"Capacity Additions|Electricity|Solar|PV (GW/yr)";"NA";"zero values in source" +"NA";"Capacity Additions|Electricity|Wind (GW/yr)";"NA";"zero values in source" +"NA";"Capacity Additions|Electricity|Wind|Onshore (GW/yr)";"NA";"zero values in source" +"OandM costs (billion US$2005/yr)";"Total Energy System Cost|O&M Costs (billion EUR2015/yr)";0.9259259; +"PE (EJ/yr)";"Primary Energy (PJ/yr)";0.001; +"PE|Biomass (EJ/yr)";"Primary Energy|Biomass (PJ/yr)";0.001; +"PE|Biomass|Electricity (EJ/yr)";"Primary Energy|Biomass|Electricity (PJ/yr)";0.001; +"PE|Biomass|Electricity|w/ CC (EJ/yr)";"Primary Energy|Biomass|Electricity|w/ CCS (PJ/yr)";0.001; +"PE|Biomass|Electricity|w/o CC (EJ/yr)";"Primary Energy|Biomass|Electricity|w/o CCS (PJ/yr)";0.001; +"PE|Biomass|Gases (EJ/yr)";"Primary Energy|Biomass|Gases (PJ/yr)";0.001; +"PE|Biomass|Heat (EJ/yr)";"Primary Energy|Biomass|Heat (PJ/yr)";0.001; +"PE|Biomass|Hydrogen (EJ/yr)";"Primary Energy|Biomass|Hydrogen (PJ/yr)";0.001; +"PE|Biomass|Hydrogen|w/ CC (EJ/yr)";"Primary Energy|Biomass|Hydrogen|w/ CCS (PJ/yr)";0.001; +"PE|Biomass|Hydrogen|w/o CC (EJ/yr)";"Primary Energy|Biomass|Hydrogen|w/o CCS (PJ/yr)";0.001; +"PE|Biomass|Liquids (EJ/yr)";"Primary Energy|Biomass|Liquids (PJ/yr)";0.001; +"PE|Biomass|Liquids|w/ CC (EJ/yr)";"Primary Energy|Biomass|Liquids|w/ CCS (PJ/yr)";0.001; +"PE|Biomass|Liquids|w/o CC (EJ/yr)";"Primary Energy|Biomass|Liquids|w/o CCS (PJ/yr)";0.001; +"PE|Biomass|Solids (EJ/yr)";"Primary Energy|Biomass|Solids (PJ/yr)";0.001; +"PE|Biomass|w/ CC (EJ/yr)";"Primary Energy|Biomass|w/ CCS (PJ/yr)";0.001; +"PE|Biomass|w/o CC (EJ/yr)";"Primary Energy|Biomass|w/o CCS (PJ/yr)";0.001; +"PE|Coal (EJ/yr)";"Primary Energy|Coal (PJ/yr)";0.001; +"PE|Coal|Electricity (EJ/yr)";"Primary Energy|Coal|Electricity (PJ/yr)";0.001; +"PE|Coal|Electricity|w/ CC (EJ/yr)";"Primary Energy|Coal|Electricity|w/ CCS (PJ/yr)";0.001; +"PE|Coal|Electricity|w/o CC (EJ/yr)";"Primary Energy|Coal|Electricity|w/o CCS (PJ/yr)";0.001; +"PE|Coal|Gases (EJ/yr)";"Primary Energy|Coal|Gases (PJ/yr)";0.001; +"PE|Coal|Heat (EJ/yr)";"Primary Energy|Coal|Heat (PJ/yr)";0.001; +"PE|Coal|Hydrogen (EJ/yr)";"Primary Energy|Coal|Hydrogen (PJ/yr)";0.001; +"PE|Coal|Liquids (EJ/yr)";"Primary Energy|Coal|Liquids (PJ/yr)";0.001; +"PE|Coal|Solids (EJ/yr)";"Primary Energy|Coal|Solids (PJ/yr)";0.001; +"PE|Coal|w/ CC (EJ/yr)";"Primary Energy|Coal|w/ CCS (PJ/yr)";0.001; +"PE|Coal|w/o CC (EJ/yr)";"Primary Energy|Coal|w/o CCS (PJ/yr)";0.001; +"PE|Fossil (EJ/yr)";"Primary Energy|Fossil (PJ/yr)";0.001; +"PE|Fossil|w/ CC (EJ/yr)";"Primary Energy|Fossil|w/ CCS (PJ/yr)";0.001; +"PE|Fossil|w/o CC (EJ/yr)";"Primary Energy|Fossil|w/o CCS (PJ/yr)";0.001; +"PE|Gas (EJ/yr)";"Primary Energy|Gas (PJ/yr)";0.001; +"PE|Gas|Electricity (EJ/yr)";"Primary Energy|Gas|Electricity (PJ/yr)";0.001; +"PE|Gas|Electricity|w/ CC (EJ/yr)";"Primary Energy|Gas|Electricity|w/ CCS (PJ/yr)";0.001; +"PE|Gas|Electricity|w/o CC (EJ/yr)";"Primary Energy|Gas|Electricity|w/o CCS (PJ/yr)";0.001; +"PE|Gas|Gases (EJ/yr)";"Primary Energy|Gas|Gases (PJ/yr)";0.001; +"PE|Gas|Heat (EJ/yr)";"Primary Energy|Gas|Heat (PJ/yr)";0.001; +"PE|Gas|Hydrogen (EJ/yr)";"Primary Energy|Gas|Hydrogen (PJ/yr)";0.001; +"PE|Gas|Hydrogen|w/ CC (EJ/yr)";"Primary Energy|Gas|Hydrogen|w/ CCS (PJ/yr)";0.001; +"PE|Gas|Hydrogen|w/o CC (EJ/yr)";"Primary Energy|Gas|Hydrogen|w/o CCS (PJ/yr)";0.001; +"PE|Gas|Liquids (EJ/yr)";"Primary Energy|Gas|Liquids (PJ/yr)";0.001; +"PE|Gas|w/ CC (EJ/yr)";"Primary Energy|Gas|w/ CCS (PJ/yr)";0.001; +"PE|Gas|w/o CC (EJ/yr)";"Primary Energy|Gas|w/o CCS (PJ/yr)";0.001; +"PE|Geothermal (EJ/yr)";"Primary Energy|Geothermal (PJ/yr)";0.001; +"PE|Hydro (EJ/yr)";"Primary Energy|Hydro (PJ/yr)";0.001; +"PE|Non-Biomass Renewables (EJ/yr)";"Primary Energy|Non-Biomass Renewables (PJ/yr)";0.001; +"PE|Nuclear (EJ/yr)";"Primary Energy|Nuclear (PJ/yr)";0.001; +"PE|Oil (EJ/yr)";"Primary Energy|Oil (PJ/yr)";0.001; +"PE|Oil|w/o CC (EJ/yr)";"Primary Energy|Oil|w/o CCS (PJ/yr)";0.001; +"PE|Solar (EJ/yr)";"Primary Energy|Solar (PJ/yr)";0.001; +"PE|Wind (EJ/yr)";"Primary Energy|Wind (PJ/yr)";0.001; +"Population (million)";"Economy|Population (million people)";1; +"Price|Biomass|World Market (US$2005/GJ)";"Price|Primary Energy|Biomass (EUR2015/GJ)";0.9259259; +"Price|Carbon (US$2005/t CO2)";"Price|Carbon|Net|Transport (EUR2015/t CO2)";0.9259259; +"Price|Carbon (US$2005/t CO2)";"Price|Carbon|EU-wide Regulation All Sectors (EUR2015/t CO2)";0.9259259; +"Price|Primary Energy|Coal (US$2005/GJ)";"Price|Primary Energy|Coal (EUR2015/GJ)";0.9259259; +"Price|Secondary Energy|Solids|Fossil (US$2005/GJ)";"Price|Secondary Energy|Solids|Coal (EUR2015/GJ)";0.9259259; +"Price|Primary Energy|Oil (US$2005/GJ)";"Price|Primary Energy|Oil (EUR2015/GJ)";0.9259259; +"Price|Final Energy|Buildings|Electricity (US$2005/GJ)";"Price|Final Energy|Residential and Commercial|Electricity (EUR2015/GJ)";0.9259259; +"Price|Final Energy|Industry|Electricity (US$2005/GJ)";"Price|Final Energy|Industry|Electricity (EUR2015/GJ)";0.9259259; +"Price|Final Energy|Buildings|Gases (US$2005/GJ)";"Price|Final Energy|Residential and Commercial|Gases (EUR2015/GJ)";0.9259259; +"Price|Final Energy|Industry|Gases (US$2005/GJ)";"Price|Final Energy|Industry|Gases (EUR2015/GJ)";0.9259259; +"Price|Final Energy|Buildings|Heat (US$2005/GJ)";"Price|Final Energy|Residential and Commercial|Heat (EUR2015/GJ)";0.9259259; +"Price|Final Energy|Industry|Heat (US$2005/GJ)";"Price|Final Energy|Industry|Heat (EUR2015/GJ)";0.9259259; +"Price|Final Energy|Buildings|Heating Oil (US$2005/GJ)";"Price|Final Energy|Residential and Commercial|Liquids (EUR2015/GJ)";0.9259259; +"Price|Final Energy|Industry|Heating Oil (US$2005/GJ)";"Price|Final Energy|Industry|Liquids (EUR2015/GJ)";0.9259259; +"Price|Final Energy|Buildings|Hydrogen (US$2005/GJ)";"Price|Final Energy|Residential and Commercial|Hydrogen (EUR2015/GJ)";0.9259259; +"Price|Final Energy|Industry|Hydrogen (US$2005/GJ)";"Price|Final Energy|Industry|Hydrogen (EUR2015/GJ)";0.9259259; +"Price|Final Energy|Buildings|Solids (US$2005/GJ)";"Price|Final Energy|Residential and Commercial|Solids (EUR2015/GJ)";0.9259259; +"Price|Final Energy|Industry|Solids (US$2005/GJ)";"Price|Final Energy|Industry|Solids (EUR2015/GJ)";0.9259259; +"Price|Primary Energy|Gas (US$2005/GJ)";"Price|Primary Energy|Gas (EUR2015/GJ)";0.9259259; +"Price|Secondary Energy|Electricity (US$2005/GJ)";"Price|Secondary Energy|Electricity (EUR2015/GJ)";0.9259259; +"Price|Secondary Energy|Gases (US$2005/GJ)";"Price|Secondary Energy|Gases (EUR2015/GJ)";0.9259259; +"Price|Secondary Energy|Hydrogen (US$2005/GJ)";"Price|Secondary Energy|Hydrogen (EUR2015/GJ)";0.9259259; +"Price|Secondary Energy|Liquids (US$2005/GJ)";"Price|Secondary Energy|Liquids (EUR2015/GJ)";0.9259259; +"Price|Secondary Energy|Solids|Biomass (US$2005/GJ)";"Price|Secondary Energy|Solids|Biomass (EUR2015/GJ)";0.9259259; +"NA";"Secondary Energy (PJ/yr)";"NA";"zero values in source" +"SE|Electricity (EJ/yr)";"Secondary Energy|Electricity (PJ/yr)";0.001; +"SE|Electricity|Biomass (EJ/yr)";"Secondary Energy|Electricity|Biomass (TWh/yr)";0.0036; +"SE|Electricity|Biomass|w/ CC (EJ/yr)";"Secondary Energy|Electricity|Biomass|w/ CCS (TWh/yr)";0.0036; +"SE|Electricity|Biomass|w/o CC (EJ/yr)";"Secondary Energy|Electricity|Biomass|w/o CCS (TWh/yr)";0.0036; +"SE|Electricity|Coal (EJ/yr)";"Secondary Energy|Electricity|Coal (TWh/yr)";0.0036; +"SE|Electricity|Coal|w/ CC (EJ/yr)";"Secondary Energy|Electricity|Coal|w/ CCS (TWh/yr)";0.0036; +"SE|Electricity|Coal|w/o CC (EJ/yr)";"Secondary Energy|Electricity|Coal|w/o CCS (TWh/yr)";0.0036; +"SE|Electricity|Gas (EJ/yr)";"Secondary Energy|Electricity|Gas (TWh/yr)";0.0036; +"SE|Electricity|Gas|CC|w/o CC (EJ/yr)";"Secondary Energy|Electricity|Gas|CC|w/o CCS (TWh/yr)";0.0036; +"SE|Electricity|Gas|w/ CC (EJ/yr)";"Secondary Energy|Electricity|Gas|w/ CCS (TWh/yr)";0.0036; +"SE|Electricity|Gas|w/o CC (EJ/yr)";"Secondary Energy|Electricity|Gas|w/o CCS (TWh/yr)";0.0036; +"SE|Electricity|Geothermal (EJ/yr)";"Secondary Energy|Electricity|Geothermal (TWh/yr)";0.0036; +"SE|Electricity|Hydro (EJ/yr)";"Secondary Energy|Electricity|Hydro (TWh/yr)";0.0036; +"SE|Electricity|Hydrogen (EJ/yr)";"Secondary Energy|Electricity|Hydrogen (TWh/yr)";0.0036; +"SE|Electricity|Nuclear (EJ/yr)";"Secondary Energy|Electricity|Nuclear (TWh/yr)";0.0036; +"SE|Electricity|Oil (EJ/yr)";"Secondary Energy|Electricity|Oil (TWh/yr)";0.0036; +"SE|Electricity|Solar (EJ/yr)";"Secondary Energy|Electricity|Solar (TWh/yr)";0.0036; +"SE|Electricity|Solar|CSP (EJ/yr)";"Secondary Energy|Electricity|Solar|CSP (TWh/yr)";0.0036; +"SE|Electricity|Solar|PV (EJ/yr)";"Secondary Energy|Electricity|Solar|PV (TWh/yr)";0.0036; +"SE|Electricity|Wind (EJ/yr)";"Secondary Energy|Electricity|Wind (TWh/yr)";0.0036; +"SE|Gases (EJ/yr)";"Secondary Energy|Gases (PJ/yr)";0.001; +"SE|Gases|Biomass (EJ/yr)";"Secondary Energy|Gases|Biomass (PJ/yr)";0.001; +"SE|Gases|Biomass|w/ CC (EJ/yr)";"Secondary Energy|Gases|Biomass|w/ CCS (PJ/yr)";0.001; +"SE|Gases|Biomass|w/o CC (EJ/yr)";"Secondary Energy|Gases|Biomass|w/o CCS (PJ/yr)";0.001; +"SE|Gases|Liquids|Coal (EJ/yr)";"Secondary Energy|Gases|Coal (PJ/yr)";0.001; +"SE|Gases|Liquids|Natural Gas (EJ/yr)";"Secondary Energy|Gases|Natural Gas (PJ/yr)";0.001; +"SE|Heat (EJ/yr)";"Secondary Energy|Heat (PJ/yr)";0.001; +"SE|Heat|Biomass (EJ/yr)";"Secondary Energy|Heat|Biomass (PJ/yr)";0.001; +"NA";"Secondary Energy|Heat|Electricity (PJ/yr)";"NA"; +"SE|Heat|Coal (EJ/yr)";"Secondary Energy|Heat|Coal (PJ/yr)";0.001; +"SE|Heat|Gas (EJ/yr)";"Secondary Energy|Heat|Gas (PJ/yr)";0.001; +"SE|Heat|Geothermal (EJ/yr)";"Secondary Energy|Heat|Geothermal (PJ/yr)";0.001; +"SE|Hydrogen (EJ/yr)";"Secondary Energy|Hydrogen (PJ/yr)";0.001; +"SE|Hydrogen|Biomass (EJ/yr)";"Secondary Energy|Hydrogen|Biomass (PJ/yr)";0.001; +"SE|Hydrogen|Biomass|w/ CC (EJ/yr)";"Secondary Energy|Hydrogen|Biomass|w/ CCS (PJ/yr)";0.001; +"SE|Hydrogen|Biomass|w/o CC (EJ/yr)";"Secondary Energy|Hydrogen|Biomass|w/o CCS (PJ/yr)";0.001; +"SE|Hydrogen|Coal (EJ/yr)";"Secondary Energy|Hydrogen|Coal (PJ/yr)";0.001; +"SE|Hydrogen|Coal|w/ CC (EJ/yr)";"Secondary Energy|Hydrogen|Coal|w/ CCS (PJ/yr)";0.001; +"SE|Hydrogen|Coal|w/o CC (EJ/yr)";"Secondary Energy|Hydrogen|Coal|w/o CCS (PJ/yr)";0.001; +"SE|Hydrogen|Electricity (EJ/yr)";"Secondary Energy|Hydrogen|Electricity (PJ/yr)";0.001; +"SE|Hydrogen|Gas (EJ/yr)";"Secondary Energy|Hydrogen|Gas (PJ/yr)";0.001; +"SE|Hydrogen|Gas|w/ CC (EJ/yr)";"Secondary Energy|Hydrogen|Gas|w/ CCS (PJ/yr)";0.001; +"SE|Hydrogen|Gas|w/o CC (EJ/yr)";"Secondary Energy|Hydrogen|Gas|w/o CCS (PJ/yr)";0.001; +"SE|Liquids (EJ/yr)";"Secondary Energy|Liquids (PJ/yr)";0.001; +"SE|Liquids|Biomass (EJ/yr)";"Secondary Energy|Liquids|Biomass (PJ/yr)";0.001; +"SE|Liquids|Biomass|w/ CC (EJ/yr)";"Secondary Energy|Liquids|Biomass|w/ CCS (PJ/yr)";0.001; +"SE|Liquids|Biomass|w/o CC (EJ/yr)";"Secondary Energy|Liquids|Biomass|w/o CCS (PJ/yr)";0.001; +"SE|Liquids|Fossil|Coal (EJ/yr)";"Secondary Energy|Liquids|Coal (PJ/yr)";0.001; +"SE|Liquids|Fossil|Coal|w/ CC (EJ/yr)";"Secondary Energy|Liquids|Coal|w/ CCS (PJ/yr)";0.001; +"SE|Liquids|Fossil|Coal|w/o CC (EJ/yr)";"Secondary Energy|Liquids|Coal|w/o CCS (PJ/yr)";0.001; +"SE|Liquids|Fossil|Gas (EJ/yr)";"Secondary Energy|Liquids|Gas (PJ/yr)";0.001; +"SE|Liquids|Fossil|Oil (EJ/yr)";"Secondary Energy|Liquids|Oil (PJ/yr)";0.001; +"SE|Solids (EJ/yr)";"Secondary Energy|Solids (PJ/yr)";0.001; +"SE|Solids|Biomass (EJ/yr)";"Secondary Energy|Solids|Biomass (PJ/yr)";0.001; +"SE|Solids|Coal (EJ/yr)";"Secondary Energy|Solids|Coal (PJ/yr)";0.001; +"Total Energy costs (billion US$2005/yr)";"Total Energy System Cost (billion EUR2015/yr)";0.9259259; +"Total Energy costs|Electricity (billion US$2005/yr)";"Total Energy System Cost|Power Sector (billion EUR2015/yr)";0.9259259; +"Trade|Biomass (EJ/yr)";"Trade|Primary Energy|Biomass|Volume (PJ/yr)";0.001; +"Trade|Coal (EJ/yr)";"Trade|Primary Energy|Coal|Volume (PJ/yr)";0.001; +"Trade|Gas (EJ/yr)";"Trade|Primary Energy|Gas|Volume (PJ/yr)";0.001; +"Trade|Oil (EJ/yr)";"Trade|Primary Energy|Oil|Volume (PJ/yr)";0.001; +"Trade|Uranium|Mass (ktU/yr)";"Trade|Uranium|Mass (kt U/yr)";1; +"UE|Buildings|Appliances and Light (EJ/yr)";"Useful Energy|Residential and Commercial|Appliances and Lighting (PJ/yr)";0.001; +"UE|Buildings|Appliances and Light|Electricity (EJ/yr)";"Useful Energy|Residential and Commercial|Appliances and Lighting|Electricity (PJ/yr)";0.001; +"UE|Buildings|Cooking and Water (EJ/yr)";"Useful Energy|Residential and Commercial|Water Heating and Cooking (PJ/yr)";0.001; +"UE|Buildings|Cooking and Water|Electricity (EJ/yr)";"Useful Energy|Residential and Commercial|Water Heating and Cooking|Electricity (PJ/yr)";0.001; +"UE|Buildings|Cooking and Water|Electricity|Heat pumps (EJ/yr)";"Useful Energy|Residential and Commercial|Water Heating and Cooking|Electricity|Heat Pumps (PJ/yr)";0.001; +"UE|Buildings|Cooking and Water|Electricity|Resistance (EJ/yr)";"Useful Energy|Residential and Commercial|Water Heating and Cooking|Electricity|Resistive (PJ/yr)";0.001; +"UE|Buildings|Cooking and Water|Gases (EJ/yr)";"Useful Energy|Residential and Commercial|Water Heating and Cooking|Gases (PJ/yr)";0.001; +"UE|Buildings|Cooking and Water|Heat (EJ/yr)";"Useful Energy|Residential and Commercial|Water Heating and Cooking|Heat (PJ/yr)";0.001; +"UE|Buildings|Cooking and Water|Hydrogen (EJ/yr)";"Useful Energy|Residential and Commercial|Water Heating and Cooking|Hydrogen (PJ/yr)";0.001; +"UE|Buildings|Cooking and Water|Liquids (EJ/yr)";"Useful Energy|Residential and Commercial|Water Heating and Cooking|Liquids (PJ/yr)";0.001; +"UE|Buildings|Cooking and Water|Solids (EJ/yr)";"Useful Energy|Residential and Commercial|Water Heating and Cooking|Solids (PJ/yr)";0.001; +"UE|Buildings|Space Cooling (EJ/yr)";"Useful Energy|Residential and Commercial|Space Cooling (PJ/yr)";0.001; +"UE|Buildings|Space Cooling|Electricity (EJ/yr)";"Useful Energy|Residential and Commercial|Space Cooling|Electricity (PJ/yr)";0.001; +"UE|Buildings|Space Heating (EJ/yr)";"Useful Energy|Residential and Commercial|Space Heating (PJ/yr)";0.001; +"UE|Buildings|Space Heating|Electricity (EJ/yr)";"Useful Energy|Residential and Commercial|Space Heating|Electricity (PJ/yr)";0.001; +"UE|Buildings|Space Heating|Electricity|Heat pumps (EJ/yr)";"Useful Energy|Residential and Commercial|Space Heating|Electricity|Heat Pumps (PJ/yr)";0.001; +"UE|Buildings|Space Heating|Electricity|Resistance (EJ/yr)";"Useful Energy|Residential and Commercial|Space Heating|Electricity|Resistive (PJ/yr)";0.001; +"UE|Buildings|Space Heating|Gases (EJ/yr)";"Useful Energy|Residential and Commercial|Space Heating|Gases (PJ/yr)";0.001; +"UE|Buildings|Space Heating|Heat (EJ/yr)";"Useful Energy|Residential and Commercial|Space Heating|Heat (PJ/yr)";0.001; +"UE|Buildings|Space Heating|Hydrogen (EJ/yr)";"Useful Energy|Residential and Commercial|Space Heating|Hydrogen (PJ/yr)";0.001; +"UE|Buildings|Space Heating|Liquids (EJ/yr)";"Useful Energy|Residential and Commercial|Space Heating|Liquids (PJ/yr)";0.001; +"UE|Buildings|Space Heating|Solids (EJ/yr)";"Useful Energy|Residential and Commercial|Space Heating|Solids (PJ/yr)";0.001; +"Emissions|CO2|Energy|Fugitive Emissions (Mt CO2/yr)";"Emissions|CO2|Energy|Fugitive Emissions (Mt CO2/yr)";1; diff --git a/inst/extdata/sectoral/mappingCEDS2024toREMIND.csv b/inst/extdata/sectoral/mappingCEDS2024toREMIND.csv new file mode 100644 index 00000000..f8f29d03 --- /dev/null +++ b/inst/extdata/sectoral/mappingCEDS2024toREMIND.csv @@ -0,0 +1,61 @@ +CEDS2024;REMIND;Comment +1A1a_Electricity-autoproducer;Energy|Supply|Electricity; +1A1a_Electricity-public;Energy|Supply|Electricity; +1A1a_Heat-production;Energy|Supply|Heat; +1A1bc_Other-transformation;Energy|Supply|Fuel Production;This variable does not exist in REMIND yet, it is the sum of Supply|Liquids/Gases/Solids +1A2a_Ind-Comb-Iron-steel;Energy|Demand|Industry|Steel; +1A2b_Ind-Comb-Non-ferrous-metals;Energy|Demand|Industry|Other; +1A2c_Ind-Comb-Chemicals;Energy|Demand|Industry|Chemicals; +1A2d_Ind-Comb-Pulp-paper;Energy|Demand|Industry|Other; +1A2e_Ind-Comb-Food-tobacco;Energy|Demand|Industry|Other; +1A2f_Ind-Comb-Non-metalic-minerals;Energy|Demand|Industry|Non-Metallic Minerals; +1A2g_Ind-Comb-Construction;Energy|Demand|Industry|Other; +1A2g_Ind-Comb-machinery;Energy|Demand|Industry|Other; +1A2g_Ind-Comb-mining-quarying;Energy|Demand|Industry|Other; +1A2g_Ind-Comb-other;Energy|Demand|Industry|Other; +1A2g_Ind-Comb-textile-leather;Energy|Demand|Industry|Other; +1A2g_Ind-Comb-transpequip;Energy|Demand|Industry|Other; +1A2g_Ind-Comb-wood-products;Energy|Demand|Industry|Other; +1A3ai_International-aviation;Transport|Pass|Aviation|International|Demand;Transport emissions variables from EDGE-T reporting do not comply with emissions reporting structure so far, once REMIND names adapted -> adapt here as well +1A3aii_Domestic-aviation;Energy|Demand|Transport; +1A3b_Road;Energy|Demand|Transport; +1A3c_Rail;Energy|Demand|Transport; +1A3di_International-shipping;Transport|Freight|International Shipping|Demand;Transport emissions variables from EDGE-T reporting do not comply with emissions reporting structure so far, once REMIND names adapted -> adapt here as well +1A3dii_Domestic-navigation;Energy|Demand|Transport; +1A3eii_Other-transp;Energy|Demand|Transport; +1A4a_Commercial-institutional;Energy|Demand|Buildings; +1A4b_Residential;Energy|Demand|Buildings; +1A4c_Agriculture-forestry-fishing;Energy|Demand|Industry|Other;AFOFI energy use is accounted in industry in REMIND as it relies on IEA energy balances +1A5_Other-unspecified;Energy|Demand|Industry|Other; +1B1_Fugitive-solid-fuels;Energy|Supply|Fuel Production;In the future REMIND emissions accounting should separate fugitive from combustion emissions to be in line with IPCC accounting, once this is done in REMIND reporting -> adapt here +1B2d_Fugitive-other-energy;Energy|Supply|Fuel Production;In the future REMIND emissions accounting should separate fugitive from combustion emissions to be in line with IPCC accounting, once this is done in REMIND reporting -> adapt here +2A1_Cement-production;Industrial Processes|Non-Metallic Minerals; +2A2_Lime-production;Industrial Processes|Non-Metallic Minerals; +2B_Chemical-industry;Industrial Processes|Chemicals; +2C1_Iron-steel-alloy-prod;Industrial Processes|Steel; +2C3_Aluminum-production;Industrial Processes|Other; +2C4_Non-Ferrous-other-metals;Industrial Processes|Other; +2D_Degreasing-Cleaning;Industrial Processes|Other; +2D_Paint-application;Industrial Processes|Other; +2H_Pulp-and-paper-food-beverage-wood;Industrial Processes|Other; +3B_Manure-management;Agriculture; +3D_Rice-Cultivation;Agriculture; +3D_Soil-emissions;Agriculture; +3E_Enteric-fermentation;Agriculture; +3I_Agriculture-other;Agriculture; +5A_Solid-waste-disposal;Waste; +5D_Wastewater-handling;Waste; +5E_Other-waste-handling;Waste; +6A_Other-in-total;Industrial Processes|Other;"Not sure what this is, put it to ""industrial processes"" category for now" +7A_Fossil-fuel-fires;Energy|Supply|Fuel Production; +1A3di_Oil_Tanker_Loading;Energy|Demand|Transport; +1B2_Fugitive-petr;Energy|Supply|Fuel Production;In the future REMIND emissions accounting should separate fugitive from combustion emissions to be in line with IPCC accounting, once this is done in REMIND reporting -> adapt here +1B2b_Fugitive-NG-distr;Energy|Supply|Fuel Production;In the future REMIND emissions accounting should separate fugitive from combustion emissions to be in line with IPCC accounting, once this is done in REMIND reporting -> adapt here +1B2b_Fugitive-NG-prod;Energy|Supply|Fuel Production;In the future REMIND emissions accounting should separate fugitive from combustion emissions to be in line with IPCC accounting, once this is done in REMIND reporting -> adapt here +2Ax_Other-minerals;Industrial Processes|Other; +2B2_Chemicals-Nitric-acid;Industrial Processes|Chemicals; +2B3_Chemicals-Adipic-acid;Industrial Processes|Chemicals; +2D_Chemical-products-manufacture-processing;Industrial Processes|Chemicals; +2D_Other-product-use;Industrial Processes|Other; +5C_Waste-combustion;Waste; +7BC_Indirect-N2O-non-agricultural-N;Industrial Processes|Other;"Not sure what this is, put it to ""industrial processes"" category for now" diff --git a/inst/extdata/sectoral/mappingECLIPSEtoREMINDsectors.csv b/inst/extdata/sectoral/mappingECLIPSEtoREMINDsectors.csv new file mode 100755 index 00000000..f9da1287 --- /dev/null +++ b/inst/extdata/sectoral/mappingECLIPSEtoREMINDsectors.csv @@ -0,0 +1,65 @@ +"eclipse";"agg";"remind" +"AACID";"indprocess";"indprocess" +"CEMENT";"indprocess";"indprocess" +"CHEM";"solvents";"solvents" +"CHEMBULK";"indprocess";"indprocess" +"CUSM";"indprocess";"indprocess" +"End_Use_Industry_Bio_Trad";"bioind";"pebiolc.sesobio.biotr.indst" +"End_Use_Industry_Coal";"coalind";"pecoal.sesofos.coaltr.indst" +"End_Use_Industry_HLF";"fehosind";"peoil.seliqfos.refliq.indst" +"End_Use_Industry_LLF";"fehosind";"peoil.seliqfos.refliq.indst" +"End_Use_Industry_NatGas";"gasind";"pegas.segafos.gastr.indst" +"End_Use_Others_Bio_Mod";"biotrmod";"pebiolc.sesobio.biotrmod.indst" +"End_Use_Others_Bio_Trad";"bioind";"pebiolc.sesobio.biotr.indst" +"End_Use_Others_Coal";"coalind";"pecoal.sesofos.coaltr.indst" +"End_Use_Others_HLF";"fehosind";"peoil.seliqfos.refliq.indst" +"End_Use_Others_LLF";"fehosind";"peoil.seliqfos.refliq.indst" +"End_Use_Others_NatGas";"gasind";"pegas.segafos.gastr.indst" +"End_Use_Residential_Bio_Mod";"biotrmod";"pebiolc.sesobio.biotrmod.res" +"End_Use_Residential_Bio_Trad";"biores";"pebiolc.sesobio.biotr.res" +"End_Use_Residential_Coal";"coalres";"pecoal.sesofos.coaltr.res" +"End_Use_Residential_HLF";"fehosres";"peoil.seliqfos.refliq.res" +"End_Use_Residential_LLF";"fehosres";"peoil.seliqfos.refliq.res" +"End_Use_Residential_NatGas";"gasres";"pegas.segafos.gastr.res" +"End_Use_Services_Bio_Mod";"biotrmod";"pebiolc.sesobio.biotrmod.indst" +"End_Use_Services_Bio_Trad";"bioind";"pebiolc.sesobio.biotr.indst" +"End_Use_Services_Coal";"coalind";"pecoal.sesofos.coaltr.indst" +"End_Use_Services_HLF";"fehosind";"peoil.seliqfos.refliq.indst" +"End_Use_Services_LLF";"fehosind";"peoil.seliqfos.refliq.indst" +"End_Use_Services_NatGas";"gasind";"pegas.segafos.gastr.indst" +"End_Use_Transport_Air_Domestic";"fedie";"peoil.seliqfos.refliq.trans" +"End_Use_Transport_Air_LTO";"fedie";"peoil.seliqfos.refliq.trans" +"End_Use_Transport_Coal";"coalind";"pecoal.sesofos.coaltr.indst" +"End_Use_Transport_HLF";"fedie";"peoil.seliqfos.refliq.trans" +"End_Use_Transport_LLF";"fepet";"peoil.seliqfos.refliq.trans" +"End_Use_Transport_NatGas";"gasind";"pegas.segafos.gastr.indst" +"Losses_Coal";"extraction";"extraction" +"Losses_Distribution_Use";"extraction";"extraction" +"Losses_Vent_Flare";"extraction";"extraction" +"NACID";"indprocess";"indprocess" +"PAPER";"indprocess";"indprocess" +"Power_Gen_Bio_Trad";"bio_el";"pebiolc.seel.biochp.power" +"Power_Gen_Bio_Trad";"bio_el";"pebiolc.sehe.biohp.power" +"Power_Gen_Bio_Trad";"bio_el_adv";"pebiolc.seel.bioigcc.power" +"Power_Gen_Bio_Trad";"bio_el_adv";"pebiolc.seel.bioigccc.power" +"Power_Gen_Bio_Trad";"bio_el_adv";"pebiolc.segabio.biogas.power" +"Power_Gen_Coal";"coal_el";"pecoal.seel.pc.power" +"Power_Gen_Coal";"coal_el";"pecoal.seel.coalchp.power" +"Power_Gen_Coal";"coal_el";"pecoal.sehe.coalhp.power" +"Power_Gen_Coal";"coal_el_adv";"pecoal.seel.igcc.power" +"Power_Gen_Coal";"coal_el_adv";"pecoal.seel.igccc.power" +"Power_Gen_Coal";"coal_el_adv";"pecoal.seel.pcc.power" +"Power_Gen_Coal";"coal_el_adv";"pecoal.seel.pco.power" +"Power_Gen_Coal";"coal_el_adv";"pecoal.segafos.coalgas.power" +"Power_Gen_HLF";"dot";"peoil.seel.dot.power" +"Power_Gen_LLF";"dot";"peoil.seel.dot.power" +"Power_Gen_NatGas";"gas_el";"pegas.seel.ngcc.power" +"Power_Gen_NatGas";"gas_el";"pegas.seel.ngt.power" +"Power_Gen_NatGas";"gas_el";"pegas.seel.gaschp.power" +"Power_Gen_NatGas";"gas_el";"pegas.sehe.gashp.power" +"STEEL";"indprocess";"indprocess" +"Transformations_Coal";"extraction";"extraction" +"Transformations_HLF";"extraction";"extraction" +"Transformations_HLF_Refinery";"extraction";"extraction" +"Transformations_LLF";"extraction";"extraction" +"Transformations_NatGas";"extraction";"extraction" diff --git a/inst/extdata/sectoral/mappingEEAGHGProjections.csv b/inst/extdata/sectoral/mappingEEAGHGProjections.csv new file mode 100755 index 00000000..745fc6b8 --- /dev/null +++ b/inst/extdata/sectoral/mappingEEAGHGProjections.csv @@ -0,0 +1,22 @@ +Variable;Category;Gas +Emi|GHG;Total excluding LULUCF;Total GHG emissions (ktCO2e) +Emi|GHG|ESR;Total excluding LULUCF;ESR emissions (ktCO2e) +Emi|GHG|ETS;Total excluding LULUCF;ETS emissions (ktCO2e) +Emi|GHG|Supply|ETS;1.A.1. Energy industries;ETS emissions (ktCO2e) +Emi|GHG|Supply|ESR;1.A.1. Energy industries;ESR emissions (ktCO2e) +Emi|GHG|Supply|FugitiveEmifromFuels|ETS;1.B. Fugitive emissions from fuels;ETS emissions (ktCO2e) +Emi|GHG|Energy|Demand|Industry|ETS;1.A.2. Manufacturing industries and construction;ETS emissions (ktCO2e) +Emi|GHG|Industrial Processes|ETS;2. Industrial processes;ETS emissions (ktCO2e) +Emi|GHG|Energy|Demand|Industry|ESR;1.A.2. Manufacturing industries and construction;ESR emissions (ktCO2e) +Emi|GHG|Energy|Demand|Transport|ESR;1.A.3. Transport;ESR emissions (ktCO2e) +Emi|GHG|Industrial Processes|ESR;2. Industrial processes;ESR emissions (ktCO2e) +Emi|GHG|Energy|Demand|Industry;1.A.2. Manufacturing industries and construction;Total GHG emissions (ktCO2e) +Emi|GHG|Industrial Processes;2. Industrial processes;Total GHG emissions (ktCO2e) +Emi|GHG|Agriculture;3. Agriculture;ESR emissions (ktCO2e) +Emi|GHG|Supply|FugitiveEmifromFuels|ESR;1.B. Fugitive emissions from fuels;ESR emissions (ktCO2e) +Emi|GHG|Demand|Other Sectors(Residential+X)|ESR;1.A.4. Other sectors;ESR emissions (ktCO2e) +Emi|GHG|Waste;5. Waste;ESR emissions (ktCO2e) +Emi|GHG|Bunkers|Aviation;IB.Aviation;Total GHG emissions (ktCO2e) +Emi|GHG|Bunkers|Navigation;IB.Navigation;Total GHG emissions (ktCO2e) +Emi|GHG|w/o LULUCF;Total excluding LULUCF;Total GHG emissions (ktCO2e) +Emi|GHG|w/ Intl aviation;Total excluding LULUCF (incl. Int. Aviation);Total GHG emissions (ktCO2e) diff --git a/inst/extdata/sectoral/mappingEEAGHGProjectionsDetailed.csv b/inst/extdata/sectoral/mappingEEAGHGProjectionsDetailed.csv new file mode 100755 index 00000000..134497bf --- /dev/null +++ b/inst/extdata/sectoral/mappingEEAGHGProjectionsDetailed.csv @@ -0,0 +1,19 @@ +Variable;Category;Gas;unit;factor +Emi|CO2;Total excluding LULUCF;CO2 (kt);Mt CO2/yr;0.001 +Emi|GHG;Total excluding LULUCF;Total GHG emissions (ktCO2e);Mt CO2eq/yr;0.001 +Emi|CO2|Energy;1. Energy;CO2 (kt);Mt CO2/yr;0.001 +Emi|GHG|Energy;1. Energy;Total GHG emissions (ktCO2e);Mt CO2eq/yr;0.001 +Emi|CO2|Energy|Supply;1.A.1. Energy industries;CO2 (kt);Mt CO2/yr;0.001 +Emi|CO2|Energy|Supply|Electricity and Heat;1.A.1.a. Public electricity and heat production;CO2 (kt);Mt CO2/yr;0.001 +Emi|CO2|Energy|Demand|Industry;1.A.2. Manufacturing industries and construction;CO2 (kt);Mt CO2/yr;0.001 +Emi|GHG|Energy|Demand|Industry;1.A.2. Manufacturing industries and construction;Total GHG emissions (ktCO2e);Mt CO2eq/yr;0.001 +Emi|CO2|Energy|Demand|Transport;1.A.3. Transport;CO2 (kt);Mt CO2/yr;0.001 +Emi|CO2|Energy|Demand|Buildings|Commercial;1.A.4.a. Commercial/Institutional;CO2 (kt);Mt CO2/yr;0.001 +Emi|CO2|Energy|Demand|Buildings|Residential;1.A.4.b. Residential;CO2 (kt);Mt CO2/yr;0.001 +Emi|CO2|Industrial Processes;2. Industrial processes;CO2 (kt);Mt CO2/yr;0.001 +Emi|GHG|Industrial Processes;2. Industrial processes;Total GHG emissions (ktCO2e);Mt CO2eq/yr;0.001 +Emi|GHG|Agriculture;3. Agriculture;Total GHG emissions (ktCO2e);Mt CO2eq/yr;0.001 +Emi|CO2|Land-Use Change;4. Land Use, Land-Use Change and Forestry (LULUCF, reported emissions and removals) (9);CO2 (kt);Mt CO2/yr;0.001 +Emi|GHG|Land-Use Change;4. Land Use, Land-Use Change and Forestry (LULUCF, reported emissions and removals) (9);Total GHG emissions (ktCO2e);Mt CO2eq/yr;0.001 +Emi|GHG|Waste;5. Waste;Total GHG emissions (ktCO2e);Mt CO2eq/yr;0.001 +Emi|CO2|Energy|Demand|Transport|International Bunkers;International bunkers;CO2 (kt);Mt CO2/yr;0.001 diff --git a/inst/extdata/sectoral/techmappingDaviesToREMIND.csv b/inst/extdata/sectoral/techmappingDaviesToREMIND.csv new file mode 100644 index 00000000..876e476c --- /dev/null +++ b/inst/extdata/sectoral/techmappingDaviesToREMIND.csv @@ -0,0 +1,70 @@ +"REMIND Source";"REMIND Technology";"REMIND Cooling";"Davies Source/Technology";"Davies Cooling" +"pegas";"ngcc";"tower";"Combined Cycle";"WT" +"pegas";"ngcc";"once";"Combined Cycle";"1-thru" +"pegas";"ngcc";"pond";"Combined Cycle";"Pond" +"pegas";"ngcc";"dry";"Combined Cycle";"Dry" +"pegas";"ngccc";"tower";"Combined Cycle";"WT" +"pegas";"ngccc";"once";"Combined Cycle";"1-thru" +"pegas";"ngccc";"pond";"Combined Cycle";"Pond" +"pegas";"ngccc";"dry";"Combined Cycle";"Dry" +"pegas";"ngt";"tower";"Other fossil/bio";"WT" +"pegas";"ngt";"once";"Other fossil/bio";"1-thru" +"pegas";"ngt";"pond";"Other fossil/bio";"Pond" +"pegas";"ngt";"dry";"Other fossil/bio";"Dry" +"pegas";"gaschp";"tower";"Other fossil/bio";"WT" +"pegas";"gaschp";"once";"Other fossil/bio";"1-thru" +"pegas";"gaschp";"pond";"Other fossil/bio";"Pond" +"pegas";"gaschp";"dry";"Other fossil/bio";"Dry" +"pecoal";"igcc";"tower";"Combined Cycle";"WT" +"pecoal";"igcc";"once";"Combined Cycle";"1-thru" +"pecoal";"igcc";"pond";"Combined Cycle";"Pond" +"pecoal";"igcc";"dry";"Combined Cycle";"Dry" +"pecoal";"igccc";"tower";"Combined Cycle";"WT" +"pecoal";"igccc";"once";"Combined Cycle";"1-thru" +"pecoal";"igccc";"pond";"Combined Cycle";"Pond" +"pecoal";"igccc";"dry";"Combined Cycle";"Dry" +"pecoal";"pc";"tower";"Coal";"WT" +"pecoal";"pc";"once";"Coal";"1-thru" +"pecoal";"pc";"pond";"Coal";"Pond" +"pecoal";"pc";"dry";"Coal";"Dry" +"pecoal";"pcc";"tower";"Coal";"WT" +"pecoal";"pcc";"once";"Coal";"1-thru" +"pecoal";"pcc";"pond";"Coal";"Pond" +"pecoal";"pcc";"dry";"Coal";"Dry" +"pecoal";"pco";"tower";"Coal";"WT" +"pecoal";"pco";"once";"Coal";"1-thru" +"pecoal";"pco";"pond";"Coal";"Pond" +"pecoal";"pco";"dry";"Coal";"Dry" +"pecoal";"coalchp";"tower";"Coal";"WT" +"pecoal";"coalchp";"once";"Coal";"1-thru" +"pecoal";"coalchp";"pond";"Coal";"Pond" +"pecoal";"coalchp";"dry";"Coal";"Dry" +"peoil";"dot";"tower";"Other fossil/bio";"WT" +"peoil";"dot";"once";"Other fossil/bio";"1-thru" +"peoil";"dot";"pond";"Other fossil/bio";"Pond" +"peoil";"dot";"dry";"Other fossil/bio";"Dry" +"peur";"tnrs";"tower";"Nuclear";"WT" +"peur";"tnrs";"once";"Nuclear";"1-thru" +"peur";"tnrs";"pond";"Nuclear";"Pond" +"peur";"tnrs";"dry";"Nuclear";"Dry" +"pebiolc";"biochp";"tower";"Other fossil/bio";"WT" +"pebiolc";"biochp";"once";"Other fossil/bio";"1-thru" +"pebiolc";"biochp";"pond";"Other fossil/bio";"Pond" +"pebiolc";"biochp";"dry";"Other fossil/bio";"Dry" +"pebiolc";"bioigcc";"tower";"Combined Cycle";"WT" +"pebiolc";"bioigcc";"once";"Combined Cycle";"1-thru" +"pebiolc";"bioigcc";"pond";"Combined Cycle";"Pond" +"pebiolc";"bioigcc";"dry";"Combined Cycle";"Dry" +"pebiolc";"bioigccc";"tower";"Combined Cycle";"WT" +"pebiolc";"bioigccc";"once";"Combined Cycle";"1-thru" +"pebiolc";"bioigccc";"pond";"Combined Cycle";"Pond" +"pebiolc";"bioigccc";"dry";"Combined Cycle";"Dry" +"pegeo";"geohdr";"tower";"-";"-" +"pegeo";"geohdr";"dry";"-";"-" +"pegeo";"geohdr";"hybrid";"-";"-" +"pehyd";"hydro";"default";"-";"-" +"pewin";"wind";"default";"-";"-" +"pesol";"spv";"default";"-";"-" +"pesol";"csp";"tower";"-";"-" +"pesol";"csp";"dry";"-";"-" +"pesol";"csp";"hybrid";"-";"-" diff --git a/inst/extdata/sectoral/techmappingIeaWeoPgAssumptions.csv b/inst/extdata/sectoral/techmappingIeaWeoPgAssumptions.csv new file mode 100644 index 00000000..e6c2ba2b --- /dev/null +++ b/inst/extdata/sectoral/techmappingIeaWeoPgAssumptions.csv @@ -0,0 +1,29 @@ +"IEA";"tech";"Comments" +"Steam Coal - SUBCRITICAL";"pc";"Africa, South Asia" +"Steam Coal - SUPERCRITICAL";"pc";"LAM, IND, FSU, MEA" +"Steam Coal - ULTRASUPERCRITICAL";"pc";"China, OECD/IEA" +"IGCC";"igcc"; +"CCGT";"ngcc"; +"Gas turbine";"ngt"; +"CCGT - CHP";"gaschp"; +"Fuel cell (distributed electricity generation)";"NA";"Not in REMIND" +"Coal + CCS";"NA";"pcc, no longer in REMIND" +"Oxyfuel + CCS";"NA";"pco, no longer in REMIND" +"IGCC + CCS";"igccc"; +"CCGT + CCS";"ngccc"; +"Nuclear";"tnrs"; +"Biomass Power plant";"bioigcc";"Dummy for bio-electricity plants" +"Biogas - DG Industry";"NA";" the IEA tech represents distributed generation of electricity from biogas in industry applications-not represented in REMIND" +"Biomass Cofiring";"NA";"Not in REMIND" +"Biomass CHP Medium";"biochp"; +"Biomass CHP Small";"biochp"; +"Biomass - waste incineration - CHP";"NA";"Not in REMIND" +"Geothermal";"geohdr"; +"Hydropower - large-scale";"hydro"; +"Hydropower - small-scale";"hydro"; +"Solar photovoltaics - Large scale";"spv"; +"Solar photovoltaics - Buildings";"spv"; +"Concentrating solar power";"csp"; +"Marine";"NA";"Not in REMIND" +"Wind onshore";"wind"; +"Wind offshore";"NA";"Not in REMIND" diff --git a/inst/extdata/sectoral/techmappingMacknickToREMIND.csv b/inst/extdata/sectoral/techmappingMacknickToREMIND.csv new file mode 100644 index 00000000..3b0075d3 --- /dev/null +++ b/inst/extdata/sectoral/techmappingMacknickToREMIND.csv @@ -0,0 +1,70 @@ +"REMIND Source";"REMIND Technology";"REMIND Cooling";"Macknick Source";"Macknick Technology";"Macknick Cooling" +"pegas";"ngcc";"tower";"Natural Gas";"Combined Cycle";"Tower" +"pegas";"ngcc";"once";"Natural Gas";"Combined Cycle";"Once-through" +"pegas";"ngcc";"pond";"Natural Gas";"Combined Cycle";"Pond" +"pegas";"ngcc";"dry";"Natural Gas";"Combined Cycle";"Dry" +"pegas";"ngccc";"tower";"Natural Gas";"Combined Cycle with CCS";"Tower" +"pegas";"ngccc";"once";"-";"-";"-" +"pegas";"ngccc";"pond";"-";"-";"-" +"pegas";"ngccc";"dry";"-";"-";"-" +"pegas";"ngt";"tower";"-";"-";"-" +"pegas";"ngt";"once";"-";"-";"-" +"pegas";"ngt";"pond";"-";"-";"-" +"pegas";"ngt";"dry";"-";"-";"-" +"pegas";"gaschp";"tower";"-";"-";"-" +"pegas";"gaschp";"once";"-";"-";"-" +"pegas";"gaschp";"pond";"-";"-";"-" +"pegas";"gaschp";"dry";"-";"-";"-" +"pecoal";"igcc";"tower";"Coal";"IGCC";"Tower" +"pecoal";"igcc";"once";"-";"-";"-" +"pecoal";"igcc";"pond";"-";"-";"-" +"pecoal";"igcc";"dry";"-";"-";"-" +"pecoal";"igccc";"tower";"Coal";"IGCC with CCS";"Tower" +"pecoal";"igccc";"once";"-";"-";"-" +"pecoal";"igccc";"pond";"-";"-";"-" +"pecoal";"igccc";"dry";"-";"-";"-" +"pecoal";"pc";"tower";"Coal";"Generic";"Tower" +"pecoal";"pc";"once";"Coal";"Generic";"Once-through" +"pecoal";"pc";"pond";"Coal";"Generic";"Pond" +"pecoal";"pc";"dry";"-";"-";"-" +"pecoal";"pcc";"tower";"Coal";"Supercritical with CCS";"Tower" +"pecoal";"pcc";"once";"-";"-";"-" +"pecoal";"pcc";"pond";"-";"-";"-" +"pecoal";"pcc";"dry";"-";"-";"-" +"pecoal";"pco";"tower";"Coal";"Supercritical with CCS";"Tower" +"pecoal";"pco";"once";"-";"-";"-" +"pecoal";"pco";"pond";"-";"-";"-" +"pecoal";"pco";"dry";"-";"-";"-" +"pecoal";"coalchp";"tower";"-";"-";"-" +"pecoal";"coalchp";"once";"-";"-";"-" +"pecoal";"coalchp";"pond";"-";"-";"-" +"pecoal";"coalchp";"dry";"-";"-";"-" +"peoil";"dot";"tower";"Natural Gas";"Steam";"Tower" +"peoil";"dot";"once";"Natural Gas";"Steam";"Once-through" +"peoil";"dot";"pond";"Natural Gas";"Steam";"Tower" +"peoil";"dot";"dry";"-";"-";"-" +"peur";"tnrs";"tower";"Nuclear";"Generic";"Tower" +"peur";"tnrs";"once";"Nuclear";"Generic";"Once-through" +"peur";"tnrs";"pond";"Nuclear";"Generic";"Pond" +"peur";"tnrs";"dry";"-";"-";"-" +"pebiolc";"biochp";"tower";"-";"-";"-" +"pebiolc";"biochp";"once";"-";"-";"-" +"pebiolc";"biochp";"pond";"-";"-";"-" +"pebiolc";"biochp";"dry";"-";"-";"-" +"pebiolc";"bioigcc";"tower";"Coal";"IGCC";"Tower" +"pebiolc";"bioigcc";"once";"-";"-";"-" +"pebiolc";"bioigcc";"pond";"-";"-";"-" +"pebiolc";"bioigcc";"dry";"-";"-";"-" +"pebiolc";"bioigccc";"tower";"Coal";"IGCC with CCS";"Tower" +"pebiolc";"bioigccc";"once";"-";"-";"-" +"pebiolc";"bioigccc";"pond";"-";"-";"-" +"pebiolc";"bioigccc";"dry";"-";"-";"-" +"pegeo";"geohdr";"tower";"Geothermal";"EGS";"Tower" +"pegeo";"geohdr";"dry";"Geothermal";"EGS";"Dry" +"pegeo";"geohdr";"hybrid";"Geothermal";"EGS";"Hybrid" +"pehyd";"hydro";"default";"Hydropower";"Aggregated in-stream and reservoir";"n/a" +"pewin";"wind";"default";"Wind";"Wind Turbine";"n/a" +"pesol";"spv";"default";"PV";"Utility Scale PV";"n/a" +"pesol";"csp";"tower";"CSP";"Trough";"Tower" +"pesol";"csp";"dry";"CSP";"Trough";"Dry" +"pesol";"csp";"hybrid";"CSP";"Trough";"Hybrid" diff --git a/man/calcBP.Rd b/man/calcBP.Rd index fc52bd79..1daf232b 100644 --- a/man/calcBP.Rd +++ b/man/calcBP.Rd @@ -6,9 +6,6 @@ \usage{ calcBP() } -\value{ -A \code{\link[magclass:magclass-package]{magpie}} object. -} \description{ Calculate REMIND variables from historical BP values } diff --git a/man/calcCCScapacity.Rd b/man/calcCCScapacity.Rd new file mode 100644 index 00000000..fef48978 --- /dev/null +++ b/man/calcCCScapacity.Rd @@ -0,0 +1,18 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/calcCCScapacity.R +\name{calcCCScapacity} +\alias{calcCCScapacity} +\title{calc CCS capacity} +\usage{ +calcCCScapacity(subtype) +} +\arguments{ +\item{subtype}{either `historical` for data until 2022 or `projections` +for projections in 2020, 2025 and 2030 (including some redistribution on EU/NEU level)} +} +\description{ +Calculate CCS capacity from IEA CCUS data +} +\author{ +Anne Merfort, Falk Benke +} diff --git a/man/calcCalibrationPrices.Rd b/man/calcCalibrationPrices.Rd deleted file mode 100644 index 2d2b148f..00000000 --- a/man/calcCalibrationPrices.Rd +++ /dev/null @@ -1,14 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/calcCalibrationPrices.R -\name{calcCalibrationPrices} -\alias{calcCalibrationPrices} -\title{Prices of CES variables for calibration runs in REMIND} -\usage{ -calcCalibrationPrices() -} -\description{ -Uses former REMIND runs -} -\author{ -Antoine Levesque -} diff --git a/man/calcCoalLabourProductivity.Rd b/man/calcCoalLabourProductivity.Rd deleted file mode 100644 index 46ef7aa4..00000000 --- a/man/calcCoalLabourProductivity.Rd +++ /dev/null @@ -1,19 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/calcCoalLabourProductivity.R -\name{calcCoalLabourProductivity} -\alias{calcCoalLabourProductivity} -\title{CalcCoalLabourProductivity -calculates historical employment in the coal sector and projects current (2020) and future employment factors (Jobs/PJ)} -\usage{ -calcCoalLabourProductivity(subtype) -} -\arguments{ -\item{subtype}{Either "Employment_factor" or "Employment"} -} -\description{ -CalcCoalLabourProductivity -calculates historical employment in the coal sector and projects current (2020) and future employment factors (Jobs/PJ) -} -\author{ -Aman Malik -} diff --git a/man/calcCoolingSharesAll.Rd b/man/calcCoolingSharesAll.Rd index 7db7177a..e5c17d7a 100644 --- a/man/calcCoolingSharesAll.Rd +++ b/man/calcCoolingSharesAll.Rd @@ -20,12 +20,11 @@ provide most required information but some assumptions on missing data are also made. } \examples{ - -\dontrun{ +\dontrun{ a <- calcOutput("CoolingSharesAll") - } + } \seealso{ \code{\link{calcOutput}}, \code{\link{readDaviesCooling}}, diff --git a/man/calcCoolingSharesBase.Rd b/man/calcCoolingSharesBase.Rd index 8f994b3d..ca2649de 100644 --- a/man/calcCoolingSharesBase.Rd +++ b/man/calcCoolingSharesBase.Rd @@ -18,8 +18,7 @@ region. The source data provide most required information but some assumptions on missing data are also made. } \examples{ - -\dontrun{ +\dontrun{ a <- calcOutput("CoolingSharesBase") } } diff --git a/man/calcCoolingSharesFuture.Rd b/man/calcCoolingSharesFuture.Rd index 5414c33d..18254eb5 100644 --- a/man/calcCoolingSharesFuture.Rd +++ b/man/calcCoolingSharesFuture.Rd @@ -18,11 +18,10 @@ region. The source data provide most required information but some assumptions on missing data are also made. } \examples{ - -\dontrun{ +\dontrun{ a <- calcOutput("CoolingSharesFuture") - } + } \seealso{ \code{\link{calcOutput}}, \code{\link{readDaviesCooling}}, diff --git a/man/calcCostsTrade.Rd b/man/calcCostsTrade.Rd index 18a82c9a..29aac301 100644 --- a/man/calcCostsTrade.Rd +++ b/man/calcCostsTrade.Rd @@ -14,8 +14,7 @@ corresonding weights (1) as a list of two MAgPIE objects Provides REMIND data for PE tradecosts (energy losses on import). } \examples{ - -\dontrun{ +\dontrun{ calcOutput("calcCostsTrade") } diff --git a/man/calcCostsWeathering.Rd b/man/calcCostsWeathering.Rd index 2db46d65..9e1ab247 100644 --- a/man/calcCostsWeathering.Rd +++ b/man/calcCostsWeathering.Rd @@ -2,7 +2,7 @@ % Please edit documentation in R/calcCostsWeathering.R \name{calcCostsWeathering} \alias{calcCostsWeathering} -\title{Calculate costs of transport of enahnced weathering} +\title{Calculate costs of transport of enhanced weathering} \usage{ calcCostsWeathering() } @@ -10,7 +10,7 @@ calcCostsWeathering() transport costs of spreading rock on the fields } \description{ -Calculate costs of transport of enahnced weathering +Calculate costs of transport of enhanced weathering } \examples{ diff --git a/man/calcDiffInvestCosts.Rd b/man/calcDiffInvestCosts.Rd index 5492967d..1a12c18c 100644 --- a/man/calcDiffInvestCosts.Rd +++ b/man/calcDiffInvestCosts.Rd @@ -7,10 +7,10 @@ calcDiffInvestCosts(subtype) } \arguments{ -\item{subtype}{Investment Costs, I&M Costs, and Efficiency} +\item{subtype}{"Invest_Costs", or "Efficiency"} } \value{ -Magpie object with aggregated but diffrentiated investment costs for some technologies. +Magpie object with aggregated but differentiated investment costs for some technologies. } \description{ Disaggregated investment cost data is aggregated and technologies renamed to REMIND names diff --git a/man/calcDspvEFmult.Rd b/man/calcDspvEFmult.Rd deleted file mode 100644 index 8e997aa8..00000000 --- a/man/calcDspvEFmult.Rd +++ /dev/null @@ -1,14 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/calcDspvEFmult.R -\name{calcDspvEFmult} -\alias{calcDspvEFmult} -\title{Calculates a multiplier for the employment factor for distributed solar pv} -\usage{ -calcDspvEFmult() -} -\description{ -Calculates a multiplier for the employment factor for distributed solar pv -} -\author{ -Aman Malik -} diff --git a/man/calcEDGETrData.Rd b/man/calcEDGETrData.Rd deleted file mode 100644 index 72b9aad2..00000000 --- a/man/calcEDGETrData.Rd +++ /dev/null @@ -1,25 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/calcEDGETrData.R -\name{calcEDGETrData} -\alias{calcEDGETrData} -\title{Runs EDGE-T model} -\usage{ -calcEDGETrData() -} -\value{ -list of EDGEtransport iterative inputs -} -\description{ -Runs EDGE-T model -} -\examples{ -\dontrun{ a <- calcOutput(type="EDGETrData", aggregate = F) -} - -} -\seealso{ -\code{\link{readEDGETransport}}, \code{\link[madrat]{calcOutput}} -} -\author{ -Marianna Rottoli -} diff --git a/man/calcEDGETransport.Rd b/man/calcEDGETransport.Rd index 0830bc49..295070a4 100644 --- a/man/calcEDGETransport.Rd +++ b/man/calcEDGETransport.Rd @@ -4,25 +4,24 @@ \alias{calcEDGETransport} \title{Prepare EDGETransport inputs} \usage{ -calcEDGETransport(subtype = "logit_exponent") +calcEDGETransport(subtype) } \arguments{ -\item{subtype}{refer to the code for a list of allowed subtypes.} +\item{subtype}{REMIND/iterative EDGE-T input data subtypes} } \value{ -magpie object of EDGEtransport iterative inputs +REMIND/iterative EDGE-T input data for all scenario combinations } \description{ Prepare EDGETransport inputs } \examples{ -\dontrun{ a <- calcOutput(type="EDGETransport", subtype="logit_exponent", aggregate=F) +\dontrun{ a <- calcOutput(type = "EDGETransport", subtype = "CAPEXandNonFuelOPEX", aggregate = F) } - } \seealso{ \code{\link{readSource}} } \author{ -Alois Dirnaichner, Marianna Rottoli +Johanna Hoppe } diff --git a/man/calcEarlyRetirementAdjFactor.Rd b/man/calcEarlyRetirementAdjFactor.Rd index 89f0c711..3395581d 100644 --- a/man/calcEarlyRetirementAdjFactor.Rd +++ b/man/calcEarlyRetirementAdjFactor.Rd @@ -16,11 +16,10 @@ magpie object of additional adjusment percentage to be added to the fraction of provides the extra retirement rate to account for relatively old fleet technologies retirement } \examples{ - -\dontrun{ -calcOutput(type="EarlyRetirementAdjFactor") +\dontrun{ +calcOutput(type = "EarlyRetirementAdjFactor") } - + } \seealso{ \code{\link{calcOutput}} diff --git a/man/calcEffortSharingRefEmi.Rd b/man/calcEffortSharingRefEmi.Rd index ba2f0c59..b0b6a37a 100644 --- a/man/calcEffortSharingRefEmi.Rd +++ b/man/calcEffortSharingRefEmi.Rd @@ -17,7 +17,7 @@ provides region specific Effort Sharing Reference Emissions } \examples{ -\dontrun{ +\dontrun{ calcOutput("EffortSharingRefEmi",subtype="Eurostat_GHG") } diff --git a/man/calcEmissions.Rd b/man/calcEmissions.Rd index d4b72ea1..769e3dde 100644 --- a/man/calcEmissions.Rd +++ b/man/calcEmissions.Rd @@ -7,7 +7,8 @@ calcEmissions(datasource = "CEDS16") } \arguments{ -\item{datasource}{"CEDS16", "CEDS2REMIND", "CEDS2021", "EDGAR", "EDGAR6", "LIMITS", "ECLIPSE", "GFED", "CDIAC"} +\item{datasource}{"CEDS16", "CEDS2REMIND", "CEDS2024", "EDGAR", "EDGAR6", +"EDGAR8" "LIMITS", "ECLIPSE", "GFED", "CDIAC"} } \value{ magpie object with historical emissions diff --git a/man/calcEmploymentfactors.Rd b/man/calcEmploymentfactors.Rd deleted file mode 100644 index 0ea7c66e..00000000 --- a/man/calcEmploymentfactors.Rd +++ /dev/null @@ -1,22 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/calcEmploymentfactors.R -\name{calcEmploymentfactors} -\alias{calcEmploymentfactors} -\title{calcEmploymentfactors} -\usage{ -calcEmploymentfactors(improvements, multiplier) -} -\arguments{ -\item{improvements}{Either "None", "CEEW", "Dias", "Rutovitz_aus","Solar_found" or "All". Use "All" for all improvements.} - -\item{multiplier}{source of regional multiplier. Either "Ram", "Rutovitz", "own" or "static". By default use "own"} -} -\value{ -employment factors aggregated by region for certain techs and activities -} -\description{ -Collects and combines employment factors for different technologies and activities, from different sources. For all activities except Fuel_supply, units are Full Time Equivalent (FTE)/MW. For Fuel supply, units are FTE/PJ; for nuclear FTE/GWh. The param improvements denotes specific country-level data and is considered an improvement over stock data from rutovitz2015(none) -} -\author{ -Aman Malik -} diff --git a/man/calcExogDemScen.Rd b/man/calcExogDemScen.Rd index 8c20f087..55c428fa 100644 --- a/man/calcExogDemScen.Rd +++ b/man/calcExogDemScen.Rd @@ -10,7 +10,8 @@ calcExogDemScen() A [`magpie`][magclass::magclass] object. } \description{ -prepare data for exogenuous FE and ES demand pathways that do not come from EDGE models but from other sources and/or scenario literature. +prepare data for exogenuous FE and ES demand pathways that do not +come from EDGE models but from other sources and/or scenario literature. REMIND can be fixed to those demand pathways if the switch cm_exogDem_scen is activated. } \author{ diff --git a/man/calcExpertGuess.Rd b/man/calcExpertGuess.Rd new file mode 100644 index 00000000..1fe861af --- /dev/null +++ b/man/calcExpertGuess.Rd @@ -0,0 +1,17 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/calcExpertGuess.R +\name{calcExpertGuess} +\alias{calcExpertGuess} +\title{Calculate expert guesses} +\usage{ +calcExpertGuess(subtype) +} +\arguments{ +\item{subtype}{must be 'tradeConstraints' (more to come)} +} +\description{ +Calculate expert guesses +} +\author{ +Falk Benke +} diff --git a/man/calcFossilExtraction.Rd b/man/calcFossilExtraction.Rd index 871c284e..45e18669 100644 --- a/man/calcFossilExtraction.Rd +++ b/man/calcFossilExtraction.Rd @@ -16,9 +16,8 @@ magpie object of the coefficients for fossil fuels and uranium extraction cost e provides coefficients for fossil fuels (oil, gas and coal) and uranium extraction cost equations. } \examples{ - -\dontrun{ -calcOutput(type="FossilExtraction",subtype='FossilExtraction') +\dontrun{ +calcOutput(type = "FossilExtraction", subtype = "FossilExtraction") } } \seealso{ diff --git a/man/calcGAINSEmi.Rd b/man/calcGAINSEmi.Rd index 27adbb76..1bf762ce 100644 --- a/man/calcGAINSEmi.Rd +++ b/man/calcGAINSEmi.Rd @@ -16,8 +16,7 @@ Emissions and emission factors Provides input data for exoGAINSAirpollutants.R } \examples{ - -\dontrun{ +\dontrun{ calcOutput("calcGAINSEmi") } } diff --git a/man/calcGlobalEnergyMonitor.Rd b/man/calcGlobalEnergyMonitor.Rd index e02460ee..9df6ca71 100644 --- a/man/calcGlobalEnergyMonitor.Rd +++ b/man/calcGlobalEnergyMonitor.Rd @@ -2,7 +2,7 @@ % Please edit documentation in R/calcGlobalEnergyMonitor.R \name{calcGlobalEnergyMonitor} \alias{calcGlobalEnergyMonitor} -\title{Calculate REMIND variables from Global Energy Monitor} +\title{Calc capacities from Global Energy Monitor} \usage{ calcGlobalEnergyMonitor() } @@ -10,7 +10,7 @@ calcGlobalEnergyMonitor() A \code{\link[magclass:magclass-package]{magpie}} object. } \description{ -Calculate REMIND variables from Global Energy Monitor +Calculate near-term expectations of capacities for use in fullVALIDATION.R } \author{ Falk Benke diff --git a/man/calcIEA_EVOutlook.Rd b/man/calcIEA_EVOutlook.Rd index 116fceda..a77d2b80 100644 --- a/man/calcIEA_EVOutlook.Rd +++ b/man/calcIEA_EVOutlook.Rd @@ -2,15 +2,12 @@ % Please edit documentation in R/calcIEA_EVOutlook.R \name{calcIEA_EVOutlook} \alias{calcIEA_EVOutlook} -\title{Calculate REMIND variables from IEA EV Outlook data} +\title{Calculate REMIND variables from IEA Global EV Outlook data} \usage{ calcIEA_EVOutlook() } -\value{ -A \code{\link[magclass:magclass-package]{magpie}} object. -} \description{ -Calculate REMIND variables from IEA EV Outlook data +Calculate REMIND variables from IEA Global EV Outlook data } \author{ Falk Benke diff --git a/man/calcIEA_WEO_2021.Rd b/man/calcIEA_WEO_2021.Rd deleted file mode 100644 index 5b41c513..00000000 --- a/man/calcIEA_WEO_2021.Rd +++ /dev/null @@ -1,22 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/calcIEA_WEO_2021.R -\name{calcIEA_WEO_2021} -\alias{calcIEA_WEO_2021} -\title{Calculate REMIND variables from IEA WEO 2021 data} -\usage{ -calcIEA_WEO_2021(subtype) -} -\arguments{ -\item{subtype}{Either "global" or "region". On global level, the source offers -more variables than on regional level, but the data should not be used on sub- -global level due to its coarse disaggregation.} -} -\value{ -A \code{\link[magclass:magclass-package]{magpie}} object. -} -\description{ -Calculate REMIND variables from IEA WEO 2021 data -} -\author{ -Falk Benke -} diff --git a/man/calcIEA_WorldEnergyOutlook.Rd b/man/calcIEA_WorldEnergyOutlook.Rd new file mode 100644 index 00000000..86616bb6 --- /dev/null +++ b/man/calcIEA_WorldEnergyOutlook.Rd @@ -0,0 +1,14 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/calcIEA_WorldEnergyOutlook.R +\name{calcIEA_WorldEnergyOutlook} +\alias{calcIEA_WorldEnergyOutlook} +\title{Calculate REMIND variables from IEA World Energy Outlook data.} +\usage{ +calcIEA_WorldEnergyOutlook() +} +\description{ +Calculate REMIND variables from IEA World Energy Outlook data. +} +\author{ +Falk Benke +} diff --git a/man/calcILO.Rd b/man/calcILO.Rd deleted file mode 100644 index 88b68322..00000000 --- a/man/calcILO.Rd +++ /dev/null @@ -1,22 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/calcILO.R -\name{calcILO} -\alias{calcILO} -\title{calcILO -ILO data for employment in oil and gas; coal and lignite} -\usage{ -calcILO(subtype) -} -\arguments{ -\item{subtype}{"Reliable" and "all". ILO classifies its data per country into reliable, unreliable, and break in series (years without data). "Reliable" contains both reliable and break-in-series-data, "all" contains both reliable and unreliable data} -} -\value{ -magpie object with employment data for different years -} -\description{ -calcILO -ILO data for employment in oil and gas; coal and lignite -} -\author{ -Aman Malik -} diff --git a/man/calcIndustry_CCS_limits.Rd b/man/calcIndustry_CCS_limits.Rd new file mode 100644 index 00000000..09837819 --- /dev/null +++ b/man/calcIndustry_CCS_limits.Rd @@ -0,0 +1,88 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/calcIndustry_CCS_limits.R +\name{calcIndustry_CCS_limits} +\alias{calcIndustry_CCS_limits} +\title{Calculate Limits on Industry CCS Capacities} +\usage{ +calcIndustry_CCS_limits( + a1 = 0.3, + a2 = 0.15, + installation_minimum = 1, + stage_weight = c(Operational = 1, `In construction` = 1, `Advanced development` = 0.5, + `Early development` = 0.2), + facility_subsector = c(Cement = "cement", Chemical = "chemicals", + `Hydrogen / Ammonia / Fertiliser` = "chemicals", Ethan = "chemicals", + `Iron and Steel Production` = "steel"), + region_mapping = NULL +) +} +\arguments{ +\item{a1, a2}{Annual growth factors of CCS capacity limits, for the first ten +years and thereafter, default to \code{0.7} and \code{0.2} (70 \% and 20 \%, +respectively).} + +\item{installation_minimum}{Minimum emission capacity (in MtCO~2~/year) +capacities are rounded up to. Defaults to \code{0.5} (500 ktCO~2~/year).} + +\item{stage_weight}{A named vector of weight factors for different lifecycle +stages. See Details.} + +\item{facility_subsector}{A named vector mapping the "Facility Industry" of +CCS projects to REMIND industry subsectors. See Details.} + +\item{region_mapping}{A data frame with columns \code{iso3c} and \code{region} detailing +the regional resolution on which data should be extrapolated. If \code{NULL} +(the default), extrapolation is done at the country level.} +} +\value{ +A list with a \code{\link[magclass:magclass-package]{magpie}} object \code{x}, \code{weight}, +\code{unit}, \code{description}, and \code{min}. +} +\description{ +Calculate Limits on Industry CCS Capacities +} +\details{ +The limits on industry CCS capacities are calculated from data of the +\href{zotero://select/items/3_E5GNNPZ8}{Global Status of CCS 2023} report (through +\code{\link[=readGlobalCCSinstitute]{readGlobalCCSinstitute()}}. CCS projects are +\itemize{ +\item filtered for valid (i.e. not "Under Evaluation") data for "Operation date" +and "CO~2~ capture capacity" +\item assigned to REMIND industry subsectors according to \code{facility_subsector}, +which defaults to\tabular{ll}{ + Facility Industry \tab subsector \cr + Cement \tab cement \cr + Chemical \tab chemicals \cr + Hydrogen / Ammonia / Fertiliser \tab chemicals \cr + Ethan \tab chemicals \cr + Iron and Steel Production \tab steel \cr +} + +\item weighted by lifecycle stage according to \code{stage_weight}, which defaults to\tabular{lr}{ + Lifecycle stage \tab weight \cr + Operational \tab 100 \% \cr + In construction \tab 100 \% \cr + Advanced development \tab 50 \% \cr + Early development \tab 20 \% \cr +} + +} + +The resulting project capacities constitute the limits on industry subsector +CCS capacity for 2025. The limit on CCS capacities for regions (or countries +if \code{region_mapping} is \code{NULL}) is set to a value of total 2025 subsector CCS +capacity, times the regions share in subsector activity (e.g. cement +production) of the SSP2EU scenario +\itemize{ +\item in 2030 if the region as some CCS capacity in 2025 in a different industry +subsector, or +\item in 2035 if the region has no industry CCS capacity in 2030 at all. +} + +CCS capacities are increased by the annual growth factor \code{a1} for the ten +first years, and by the annual growth factor \code{a2} afterwards (defaulting to +70 \% and 20 \%, respectively). +} +\author{ +Michaja Pehl +} diff --git a/man/calcKLWdamage.Rd b/man/calcKLWdamage.Rd new file mode 100644 index 00000000..49ed7193 --- /dev/null +++ b/man/calcKLWdamage.Rd @@ -0,0 +1,22 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/calcKLWdamage.R +\name{calcKLWdamage} +\alias{calcKLWdamage} +\title{write KLW damage parameters (from Kotz et al. 2024) into input data +they are country-specific and should not be aggregated to the regional level at all} +\usage{ +calcKLWdamage(subtype) +} +\arguments{ +\item{subtype}{"beta1", "beta2", "maxGMT"} +} +\value{ +MAgPIE object of damage parameters for KLW damage function on country level and for 1000 boostrapping samples +} +\description{ +write KLW damage parameters (from Kotz et al. 2024) into input data +they are country-specific and should not be aggregated to the regional level at all +} +\author{ +Franziska Piontek +} diff --git a/man/calcProjectPipelines.Rd b/man/calcProjectPipelines.Rd new file mode 100644 index 00000000..17d52beb --- /dev/null +++ b/man/calcProjectPipelines.Rd @@ -0,0 +1,20 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/calcProjectPipelines.R +\name{calcProjectPipelines} +\alias{calcProjectPipelines} +\title{calc Project Pipelines} +\usage{ +calcProjectPipelines(subtype) +} +\arguments{ +\item{subtype}{choose technology `biomass`, `coal`, `geothermal`, `hydro`, +`nuclear`, `solar`, `wind` or `CCS`} +} +\description{ +Calculate the expected near-term deployment of technologies based on +projects that are currently either being built or in a planning stage +for some technologies multiple sources are available +} +\author{ +Pascal Weigmann +} diff --git a/man/calcSharedTarget.Rd b/man/calcSharedTarget.Rd index 6c3ca536..1211461f 100644 --- a/man/calcSharedTarget.Rd +++ b/man/calcSharedTarget.Rd @@ -17,7 +17,7 @@ provides region specific target } \examples{ -\dontrun{ +\dontrun{ calcOutput("SharedTarget",subtype="FErenewablesShare") } diff --git a/man/calcStorageFactor.Rd b/man/calcStorageFactor.Rd index 59b4eb19..aed792b0 100644 --- a/man/calcStorageFactor.Rd +++ b/man/calcStorageFactor.Rd @@ -13,8 +13,7 @@ magpie object of the capacity factor data provides capacity factor values } \examples{ - -\dontrun{ +\dontrun{ calcOutput("StorageFactor") } diff --git a/man/calcTaxConvergence.Rd b/man/calcTaxConvergence.Rd index ec37f3af..a7acccec 100644 --- a/man/calcTaxConvergence.Rd +++ b/man/calcTaxConvergence.Rd @@ -13,8 +13,7 @@ magpie object of the tax convergence levels tax convergence levels for specific regions } \examples{ - -\dontrun{ +\dontrun{ calcOutput("TaxConvergence") } diff --git a/man/calcTheil.Rd b/man/calcTheil.Rd index 4a304f05..b8268027 100644 --- a/man/calcTheil.Rd +++ b/man/calcTheil.Rd @@ -7,16 +7,13 @@ calcTheil() } \value{ -magpie objects of unweighted contribution to Theil, -weights (= country shares of regional GDP), docstring +magpie objects of unweighted contribution to Theil, weights (= country shares of regional GDP) } \description{ -To calculate the regional Theil-T index (= correction to welfare function for -a lognormal income distribution) we do the following: -(1) convert country-level Gini coefficients to Theil (2) calculate contribution -to Theil-T index that includes both between-countries and within-country inequality -(see e.g. https://en.wikipedia.org/wiki/Theil_index). The latter can then be -aggregated with calcOutput(). +To calculate the regional Theil-T index (= correction to welfare function for a lognormal income distribution) we do +the following: (1) convert country-level Gini coefficients to Theil (2) calculate contribution to Theil-T index that +includes both between-countries and within-country inequality (see e.g. https://en.wikipedia.org/wiki/Theil_index). +The latter can then be aggregated with calcOutput(). } \details{ NB 1: the aggregation depends on the region mapping. It is implemented such @@ -27,7 +24,7 @@ Theil-T, but the unweighted contribution from a given country to the regional va } \examples{ \dontrun{ -a <- calcOutput("Theil") + calcOutput("Theil") } } diff --git a/man/calcTransportGDPshare.Rd b/man/calcTransportGDPshare.Rd index 902fea91..b4b0447d 100644 --- a/man/calcTransportGDPshare.Rd +++ b/man/calcTransportGDPshare.Rd @@ -18,6 +18,7 @@ provides transport share in GDP to resize edge-t transportation purchase costs calcOutput("TransportGDPshare") } + } \author{ Renato Rodrigues diff --git a/man/calcWasteEnergyUseShares.Rd b/man/calcWasteEnergyUseShares.Rd new file mode 100644 index 00000000..a459c659 --- /dev/null +++ b/man/calcWasteEnergyUseShares.Rd @@ -0,0 +1,14 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/calcWasteEnergyUseShares.R +\name{calcWasteEnergyUseShares} +\alias{calcWasteEnergyUseShares} +\title{Calculate waste energy use shares based on IEA World Energy Balances} +\usage{ +calcWasteEnergyUseShares() +} +\description{ +The output of this function is used in remind2 for reporting purposes. +} +\author{ +Robert Pietzcker, Falk Benke +} diff --git a/man/calcWaterConsCoef.Rd b/man/calcWaterConsCoef.Rd index aa764ac7..5860676a 100644 --- a/man/calcWaterConsCoef.Rd +++ b/man/calcWaterConsCoef.Rd @@ -7,7 +7,7 @@ calcWaterConsCoef() } \value{ -MAgPIE object on water consumption coefficients per elecricity +MAgPIE object on water consumption coefficients per electricity technology } \description{ @@ -17,10 +17,8 @@ data per electricity technology. The source data provide most required information but some assumptions on missing data are also made. } \examples{ - -\dontrun{ +\dontrun{ calcOutput("WaterConsCoef") - } } diff --git a/man/calcWaterWithCoef.Rd b/man/calcWaterWithCoef.Rd index ef8e8d9c..cdf3eeef 100644 --- a/man/calcWaterWithCoef.Rd +++ b/man/calcWaterWithCoef.Rd @@ -17,10 +17,8 @@ data per electricity technology. The source data provide most required information but some assumptions on missing data are also made. } \examples{ - -\dontrun{ +\dontrun{ calcOutput("WaterWithCoeff") - } } diff --git a/man/calcpm_delta_kap_industry.Rd b/man/calcpm_delta_kap_industry.Rd deleted file mode 100644 index e15974b4..00000000 --- a/man/calcpm_delta_kap_industry.Rd +++ /dev/null @@ -1,21 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/calcpm_delta_kap_industry.R -\name{calcpm_delta_kap_industry} -\alias{calcpm_delta_kap_industry} -\title{Calculate depreciation rate of industry energy-efficiency capital (EEK).} -\usage{ -calcpm_delta_kap_industry() -} -\value{ -A list with a \code{\link[magclass:magclass-package]{magpie}} object \code{x}, \code{unit}, and -\code{description}. -} -\description{ -Calculate depreciation rate of industry energy-efficiency capital (EEK). -} -\seealso{ -\code{\link[=calcOutput]{calcOutput()}} -} -\author{ -Michaja Pehl -} diff --git a/man/convertBGR.Rd b/man/convertBGR.Rd index 50575cb0..a8094525 100644 --- a/man/convertBGR.Rd +++ b/man/convertBGR.Rd @@ -12,16 +12,17 @@ convertBGR(x, subtype) \item{subtype}{data subtype. Either "oil", "gas", "coal" or "uranium".} } \value{ -A MAgPIE object containing BGR (Federal Institute for Geosciences and Natural Resources) country reserves disaggregated data of oil, gas, coal and uranium. +A MAgPIE object containing BGR (Federal Institute for Geosciences and +Natural Resources) country reserves disaggregated data of oil, gas, coal and uranium. } \description{ Converts BGR oil, gas, coal and uranium reserves data } \examples{ - -\dontrun{ a <- convertBGR(x,subtype="oil") +\dontrun{ +a <- convertBGR(x, subtype = "oil") } - + } \author{ Renato Rodrigues diff --git a/man/convertBP.Rd b/man/convertBP.Rd index f8e79e88..015c74d6 100644 --- a/man/convertBP.Rd +++ b/man/convertBP.Rd @@ -9,13 +9,14 @@ convertBP(x, subtype) \arguments{ \item{x}{MAgPIE object to be converted} -\item{subtype}{Either "Emission", "Capacity", "Generation", "Production", "Consumption", "Trade Oil", "Trade Gas", "Trade Coal" or "Price"} +\item{subtype}{Either "Emission", "Capacity", "Generation", "Production", +"Consumption", "Trade Oil", "Trade Gas", "Trade Coal" or "Price"} } \value{ A [`magpie`][magclass::magclass] object. } \description{ -Disaggregates historical data. +Disaggregates and cleans BP data. } \author{ Aman Malik, Falk Benke diff --git a/man/convertConferenceBoard.Rd b/man/convertConferenceBoard.Rd deleted file mode 100644 index 383d77e9..00000000 --- a/man/convertConferenceBoard.Rd +++ /dev/null @@ -1,20 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/convertConferenceBoard.R -\name{convertConferenceBoard} -\alias{convertConferenceBoard} -\title{convertConferenceBoard} -\usage{ -convertConferenceBoard(x) -} -\arguments{ -\item{x}{MAgPIE object to be converted} -} -\value{ -A magpie object with country-level results -} -\description{ -convertConferenceBoard -} -\author{ -Aman Malik -} diff --git a/man/convertDias.Rd b/man/convertDias.Rd deleted file mode 100644 index bab7158e..00000000 --- a/man/convertDias.Rd +++ /dev/null @@ -1,19 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/convertDias.R -\name{convertDias} -\alias{convertDias} -\title{convertDias} -\usage{ -convertDias(x, subtype) -} -\arguments{ -\item{x}{magpie object to be converted} - -\item{subtype}{"Employment factors" or "Employment"} -} -\description{ -convertDias -} -\author{ -Aman Malik -} diff --git a/man/convertEDGETransport.Rd b/man/convertEDGETransport.Rd index 0a982de0..7d13d37c 100644 --- a/man/convertEDGETransport.Rd +++ b/man/convertEDGETransport.Rd @@ -7,16 +7,16 @@ convertEDGETransport(x, subtype) } \arguments{ -\item{x}{MAgPIE object containing EDGE values at ISO country resolution} +\item{x}{MAgPIE object containing EDGE-T values in 21 region resolution} -\item{subtype}{EDGE entries} +\item{subtype}{REMIND/iterative EDGE-T input data subtypes} } \value{ -EDGETransport data as MAgPIE object aggregated to ISO level +REMIND/iterative EDGE-T input data as MAgPIE object disaggregated to ISO level } \description{ -Ship EDGETransport data through, as already on ISO level +Convert EDGEtransport } \author{ -Marianna Rottoli +Johanna Hoppe } diff --git a/man/convertEurostat_EffortSharing.Rd b/man/convertEurostat_EffortSharing.Rd index 59234200..303b7504 100644 --- a/man/convertEurostat_EffortSharing.Rd +++ b/man/convertEurostat_EffortSharing.Rd @@ -21,7 +21,7 @@ Converts EU Effort Sharing targets and historical emissions \dontrun{ a <- convertEurostat_EffortSharing(x,subtype="target") } - + } \author{ Renato Rodrigues diff --git a/man/convertGEA2012.Rd b/man/convertGEA2012.Rd index f1316c03..c01d0013 100644 --- a/man/convertGEA2012.Rd +++ b/man/convertGEA2012.Rd @@ -18,8 +18,8 @@ MAgPIE object containing country-level disaggregation of GEA 2012 data Converts oil, gas and coal data from the Global Energy Assessment 2012 to country-level aggregation } \examples{ - -\dontrun{ a <- readSource("GEA2012") +\dontrun{ +a <- readSource("GEA2012") } } diff --git a/man/convertGini.Rd b/man/convertGini.Rd index f125c6c5..d16ed6cc 100644 --- a/man/convertGini.Rd +++ b/man/convertGini.Rd @@ -13,15 +13,17 @@ convertGini(x) MAgPIE object of the Gini data in ISO countries, range 0-1 } \description{ -Converts Gini data from readGini() to ISO country level. -Countries missing in the original data set will have their Gini set to zero (a very small number for numerical reasons to be precise). -The original data range is 2011-2100 in one-year steps, here we extend it to 2000-2150 in 5-year steps. +Converts Gini data from readGini() to ISO country level. +Countries missing in the original data set will have their Gini set to zero ( +a very small number for numerical reasons to be precise). +The original data range is 2011-2100 in one-year steps, +here we extend it to 2000-2150 in 5-year steps. Values before (after) the original range are held fixed at 2011 (2100) levels. Gini values for the SDP scenario are taken from the SSP1 scenario } \examples{ - -\dontrun{ a <- convertGini(x) +\dontrun{ +a <- convertGini(x) } } \seealso{ diff --git a/man/convertGlobalCCSinstitute.Rd b/man/convertGlobalCCSinstitute.Rd new file mode 100644 index 00000000..9b8c8576 --- /dev/null +++ b/man/convertGlobalCCSinstitute.Rd @@ -0,0 +1,23 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/convertGlobalCCSinstitute.R +\name{convertGlobalCCSinstitute} +\alias{convertGlobalCCSinstitute} +\title{Convert Global CCS Institute Project Database} +\usage{ +convertGlobalCCSinstitute(x, subtype = "08-09-2017") +} +\arguments{ +\item{x}{A \code{\link[magclass:magclass-package]{magpie}} object returned by +\code{\link[=readGlobalCCSinstitute]{readGlobalCCSinstitute()}}.} + +\item{subtype}{Project Database version to read, one of +- \code{'08-09-2017'}: Data apparently from June 2017. +- \code{'2023-11'}: Data from the +\href{zotero://select/items/3_E5GNNPZ8}{Global Status of CCS 2023} report.} +} +\value{ +A \code{\link[magclass:magclass-package]{magpie}} object. +} +\description{ +Convert Global CCS Institute Project Database +} diff --git a/man/convertGlobalEnergyMonitor.Rd b/man/convertGlobalEnergyMonitor.Rd index fce5b3f7..6b8ecb2a 100644 --- a/man/convertGlobalEnergyMonitor.Rd +++ b/man/convertGlobalEnergyMonitor.Rd @@ -7,15 +7,11 @@ convertGlobalEnergyMonitor(x) } \arguments{ -\item{x}{A \code{\link[magclass:magclass-package]{magpie}} object returned from -\code{\link[=readGlobalEnergyMonitor]{readGlobalEnergyMonitor()}}.} -} -\value{ -A \code{\link[magclass:magclass-package]{magpie}} object. +\item{x}{A magclass object returned from readGlobalEnergyMonitor().} } \description{ Convert Global Energy Monitor data } \author{ -Falk Benke +Rahel Mandaroux, Falk Benke } diff --git a/man/convertIAEA.Rd b/man/convertIAEA.Rd index 240922a7..f92e286a 100644 --- a/man/convertIAEA.Rd +++ b/man/convertIAEA.Rd @@ -10,7 +10,7 @@ convertIAEA(x) \item{x}{MAgPIE object to be converted} } \description{ -Data on currently operating and under-construction nuclear power plants, reactors planned and proposed, +Data on currently operating and under-construction nuclear power plants, reactors planned and proposed, electricity generation from nuclear } \author{ diff --git a/man/convertIEA_CCUS.Rd b/man/convertIEA_CCUS.Rd new file mode 100644 index 00000000..32845be5 --- /dev/null +++ b/man/convertIEA_CCUS.Rd @@ -0,0 +1,20 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/convertIEA_CCUS.R +\name{convertIEA_CCUS} +\alias{convertIEA_CCUS} +\title{Convert IEA CCUS data} +\usage{ +convertIEA_CCUS(x) +} +\arguments{ +\item{x}{A magclass object returned from readIEA_CCUS().} +} +\value{ +A magclass object. +} +\description{ +Convert IEA CCUS data +} +\author{ +Anne Merfort, Falk Benke +} diff --git a/man/convertIEA_HSMR.Rd b/man/convertIEA_HSMR.Rd new file mode 100644 index 00000000..66b2cb22 --- /dev/null +++ b/man/convertIEA_HSMR.Rd @@ -0,0 +1,17 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/convertIEA_HSMR.R +\name{convertIEA_HSMR} +\alias{convertIEA_HSMR} +\title{convert IEA Hydro Special Market Report} +\usage{ +convertIEA_HSMR(x) +} +\arguments{ +\item{x}{a magclass object returned from `readIEA_HSMR()`} +} +\description{ +convert IEA Hydro Special Market Report +} +\author{ +Pascal Weigmann +} diff --git a/man/convertIEA_REN.Rd b/man/convertIEA_REN.Rd index 31f7c92c..13d1edd4 100644 --- a/man/convertIEA_REN.Rd +++ b/man/convertIEA_REN.Rd @@ -16,7 +16,7 @@ magpie object with country-wise distributed solar pv capacity Reads the distributed solar pv capacity from IEA Renewables report (2019). } \details{ -Capacity in GW. Distributed solar, defined in the IEA Renewables (2019), includes +Capacity in GW. Distributed solar, defined in the IEA Renewables (2019), includes rooftop residential (0-10 kW, grid-connected), rooftop and ground-mounted commercial and industrial (10-1000kW, grid-connected), and off-grid (8W - 100 kW) } diff --git a/man/convertIEA_WEO.Rd b/man/convertIEA_WEO.Rd index d7846d6a..9eb291a6 100644 --- a/man/convertIEA_WEO.Rd +++ b/man/convertIEA_WEO.Rd @@ -9,19 +9,21 @@ convertIEA_WEO(x, subtype) \arguments{ \item{x}{MAgPIE object to be converted} -\item{subtype}{data subtype. Either "Capacity", "Generation", "Emissions", "Investment Costs", "O&M Costs" or "Efficiency"} +\item{subtype}{data subtype. Either "Capacity", "Generation", "Emissions", +"Investment Costs", "O&M Costs" or "Efficiency"} } \value{ -magpie object of the WEO data on generation (TWh), capacities (GW), emissions (Mt CO2) or disaggregated investment cost as magpie object +magpie object of the WEO data on generation (TWh), capacities (GW), +emissions (Mt CO2) or disaggregated investment cost as magpie object } \description{ Converts IEA World Energy Outlook data } \examples{ - -\dontrun{ a <- convertWEO(x,subtype="Capacity") +\dontrun{ +a <- convertWEO(x, subtype = "Capacity") } - + } \seealso{ \code{\link{readSource}} diff --git a/man/convertIEA_WEO_2021.Rd b/man/convertIEA_WEO_2021.Rd deleted file mode 100644 index f6c210a7..00000000 --- a/man/convertIEA_WEO_2021.Rd +++ /dev/null @@ -1,24 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/convertIEA_WEO_2021.R -\name{convertIEA_WEO_2021} -\alias{convertIEA_WEO_2021} -\title{Disaggregates IEA WEO 2021 Data} -\usage{ -convertIEA_WEO_2021(x, subtype = "global") -} -\arguments{ -\item{x}{MAgPIE object to be converted} - -\item{subtype}{Either "global" or "region". On global level, the source offers -more variables than on regional level, but the data should not be used on sub- -global level due to its coarse disaggregation.} -} -\value{ -A [`magpie`][magclass::magclass] object. -} -\description{ -Disaggregates IEA WEO 2021 Data -} -\author{ -Falk Benke -} diff --git a/man/convertIEA_WorldEnergyOutlook.Rd b/man/convertIEA_WorldEnergyOutlook.Rd new file mode 100644 index 00000000..4e4f8cc7 --- /dev/null +++ b/man/convertIEA_WorldEnergyOutlook.Rd @@ -0,0 +1,17 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/convertIEA_WorldEnergyOutlook.R +\name{convertIEA_WorldEnergyOutlook} +\alias{convertIEA_WorldEnergyOutlook} +\title{Convert IEA World Energy Outlook Data from 2023} +\usage{ +convertIEA_WorldEnergyOutlook(x) +} +\arguments{ +\item{x}{magclass object to be converted} +} +\description{ +Convert IEA World Energy Outlook Data from 2023 +} +\author{ +Falk Benke +} diff --git a/man/convertKLWdamage.Rd b/man/convertKLWdamage.Rd new file mode 100644 index 00000000..e3a1fd13 --- /dev/null +++ b/man/convertKLWdamage.Rd @@ -0,0 +1,22 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/convertKLWdamage.R +\name{convertKLWdamage} +\alias{convertKLWdamage} +\title{convert KLW damage +fills in countries for which no damage parameters are provided, setting parameters to zero} +\usage{ +convertKLWdamage(x) +} +\arguments{ +\item{x}{is MAgPIE object containing the damage parameters from KLW} +} +\value{ +MAgPIE object containing values for all 249 ISO countries +} +\description{ +convert KLW damage +fills in countries for which no damage parameters are provided, setting parameters to zero +} +\author{ +Franziska Piontek +} diff --git a/man/convertNREL.Rd b/man/convertNREL.Rd index 545fb3ec..7e2c4d21 100644 --- a/man/convertNREL.Rd +++ b/man/convertNREL.Rd @@ -16,8 +16,8 @@ NRELWirsenius data as MAgPIE object aggregated to country level Convert NREL data on ISO country level. } \examples{ - -\dontrun{ a <- convertNREL(x,subtype="onshore") +\dontrun{ +a <- convertNREL(x, subtype = "onshore") } } \author{ diff --git a/man/convertOpenmod.Rd b/man/convertOpenmod.Rd index 8b80e8fa..9cae1ee8 100644 --- a/man/convertOpenmod.Rd +++ b/man/convertOpenmod.Rd @@ -10,17 +10,18 @@ convertOpenmod(x) \item{x}{MAgPIE object to be converted} } \value{ -A MAgPIE object containing openmod EU country disaggregated data with 2010 and 2015 electricity capacities (GW) +A MAgPIE object containing openmod EU country disaggregated data with +2010 and 2015 electricity capacities (GW) } \description{ Converts Openmod capacities data } \examples{ - -\dontrun{ a <- convertOpenmod(x) +\dontrun{ +a <- convertOpenmod(x) } - - + + } \author{ Renato Rodrigues diff --git a/man/convertRCP.Rd b/man/convertRCP.Rd index 9d12430f..7efeef91 100644 --- a/man/convertRCP.Rd +++ b/man/convertRCP.Rd @@ -2,7 +2,7 @@ % Please edit documentation in R/convertRCP.R \name{convertRCP} \alias{convertRCP} -\title{convertRCP +\title{convertRCP convert RCP data} \usage{ convertRCP(x, subtype) @@ -16,7 +16,7 @@ convertRCP(x, subtype) magpie object of the RCP data } \description{ -convertRCP +convertRCP convert RCP data } \author{ diff --git a/man/convertREN21.Rd b/man/convertREN21.Rd index d0ae06ab..d3191fe9 100644 --- a/man/convertREN21.Rd +++ b/man/convertREN21.Rd @@ -15,7 +15,8 @@ convertREN21(x, subtype) Magpie object with Total Installed Capacity targets. The target years differ depending upon the database. } \description{ -This code aggregates and homogenises different types of renewable energy targets into total installed capacity targets (in GW). +This code aggregates and homogenises different types of +renewable energy targets into total installed capacity targets (in GW). } \details{ Policy database accessible in "inputdata/sources/REN21/README" diff --git a/man/convertRam.Rd b/man/convertRam.Rd deleted file mode 100644 index f9b82d66..00000000 --- a/man/convertRam.Rd +++ /dev/null @@ -1,14 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/convertRam.R -\name{convertRam} -\alias{convertRam} -\title{Regional multiliers from Ram et al. , 2018} -\usage{ -convertRam(x) -} -\arguments{ -\item{x}{MAgPIE object to be converted} -} -\description{ -Regional multiliers from Ram et al. , 2018 -} diff --git a/man/convertRutovitz2015.Rd b/man/convertRutovitz2015.Rd deleted file mode 100644 index 51f522f4..00000000 --- a/man/convertRutovitz2015.Rd +++ /dev/null @@ -1,19 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/convertRutovitz2015.R -\name{convertRutovitz2015} -\alias{convertRutovitz2015} -\title{convertRutovitz2015} -\usage{ -convertRutovitz2015(x, subtype) -} -\arguments{ -\item{x}{MAgPIE object to be converted} - -\item{subtype}{"oecd_ef" or "regional_mult" or "regional_ef" or "coal_ef" or "gas_ef"} -} -\description{ -convertRutovitz2015 -} -\author{ -Aman Malik -} diff --git a/man/convertTransportSubsidies.Rd b/man/convertTransportSubsidies.Rd index f3b921ff..50200c70 100644 --- a/man/convertTransportSubsidies.Rd +++ b/man/convertTransportSubsidies.Rd @@ -16,10 +16,10 @@ A MAgPIE object containing transport subsidies per technology Converts transport subsidies data } \examples{ - -\dontrun{ a <- convertTransportSubsidies(x) +\dontrun{ +a <- convertTransportSubsidies(x) } - + } \author{ Renato Rodrigues diff --git a/man/convertWGBU.Rd b/man/convertWGBU.Rd index 76eda5ea..0343e3ca 100644 --- a/man/convertWGBU.Rd +++ b/man/convertWGBU.Rd @@ -16,8 +16,8 @@ WGBU data as MAgPIE object aggregated to country level Convert WGBU data on ISO country level. } \examples{ - -\dontrun{ a <- convertWGBU(x) +\dontrun{ +a <- convertWGBU(x) } } diff --git a/man/convertnonEnergyDemand.Rd b/man/convertnonEnergyDemand.Rd index 6e79ed36..9f876756 100644 --- a/man/convertnonEnergyDemand.Rd +++ b/man/convertnonEnergyDemand.Rd @@ -16,8 +16,8 @@ A MAgPIE object containing country disaggregated data Converts Final energy demand for feedstocks (non-energy use) } \examples{ - -\dontrun{ a <- convertnonEnergyDemand(x) +\dontrun{ +a <- convertnonEnergyDemand(x) } } diff --git a/man/exportThresholds.Rd b/man/exportThresholds.Rd new file mode 100644 index 00000000..6f0972bd --- /dev/null +++ b/man/exportThresholds.Rd @@ -0,0 +1,22 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/exportThresholds.R +\name{exportThresholds} +\alias{exportThresholds} +\title{export validation thresholds} +\usage{ +exportThresholds(type = "config", years = c(2025, 2030)) +} +\arguments{ +\item{type}{choose either "config" to export thresholds as used in the +validationConfig or "full" to export all pipeline data} + +\item{years}{choose years to include, currently only 2025 and 2030 are +available for all sources} +} +\description{ +assemble near-term thresholds from project pipelines and potentially other +data sources and export them to a file +} +\author{ +Pascal Weigmann +} diff --git a/man/mrremind-package.Rd b/man/mrremind-package.Rd index 33c8dd85..82198d2c 100644 --- a/man/mrremind-package.Rd +++ b/man/mrremind-package.Rd @@ -46,6 +46,7 @@ Authors: \item Robin Hasse \item Sophie Fuchs \item Rahel Mandaroux + \item Johannes Koch } } diff --git a/man/readAR6GWP.Rd b/man/readAR6GWP.Rd index d7405840..b8046e8c 100644 --- a/man/readAR6GWP.Rd +++ b/man/readAR6GWP.Rd @@ -7,10 +7,12 @@ readAR6GWP(subtype = "GWP100") } \arguments{ -\item{subtype}{data subtype. Currently just "GWP100", but other metrics are also available in the input data} +\item{subtype}{data subtype. Currently just "GWP100", but other metrics are +also available in the input data} } \value{ -A data.frame with two columns, "Gas", with the common name of the GHG species, and "GWP", with the selected GWP +A data.frame with two columns, "Gas", with the common name of the GHG +species, and "GWP", with the selected GWP } \description{ Read GWP (or other metrics) from the AR6 WGIII Table SM7 per GHG species diff --git a/man/readAriadneDB.Rd b/man/readAriadneDB.Rd index 99084b04..0254a437 100644 --- a/man/readAriadneDB.Rd +++ b/man/readAriadneDB.Rd @@ -10,7 +10,8 @@ readAriadneDB() A [`magpie`][magclass::magclass] object. } \description{ -Scenario data from the Ariadne modeling intercomparison project for Germany. See README in input file for more details. +Scenario data from the Ariadne modeling intercomparison project for Germany. +See README in input file for more details. } \author{ Felix Schreyer diff --git a/man/readBGR.Rd b/man/readBGR.Rd index 1a208864..ead61f9b 100644 --- a/man/readBGR.Rd +++ b/man/readBGR.Rd @@ -10,16 +10,17 @@ readBGR(subtype) \item{subtype}{data subtype. Either "oil", "gas", "coal" or "uranium".} } \value{ -magpie object of the BGR (Federal Institute for Geosciences and Natural Resources) data of reserves of oil, gas, coal and uranium per country. +magpie object of the BGR (Federal Institute for Geosciences and +Natural Resources) data of reserves of oil, gas, coal and uranium per country. } \description{ Read-in BGR csv files as magclass object } \examples{ - -\dontrun{ a <- readSource(type="BGR",subtype="oil") +\dontrun{ +a <- readSource(type = "BGR", subtype = "oil") } - + } \seealso{ \code{\link{readSource}} diff --git a/man/readBP.Rd b/man/readBP.Rd index e48e968b..a21e2841 100644 --- a/man/readBP.Rd +++ b/man/readBP.Rd @@ -7,13 +7,14 @@ readBP(subtype) } \arguments{ -\item{subtype}{Either "Emission", Capacity", "Generation", "Production", "Consumption", "Trade Oil", "Trade Gas", "Trade Coal" or "Price"} +\item{subtype}{Either "Emission", Capacity", "Generation", "Production", +"Consumption", "Trade Oil", "Trade Gas", "Trade Coal" or "Price"} } \value{ A [`magpie`][magclass::magclass] object. } \description{ -BP data. See README in input file for more details. +BP Capacity and Generation Data } \author{ Aman Malik, Falk Benke diff --git a/man/readCEEW.Rd b/man/readCEEW.Rd index 2df8e0ea..4b6729ab 100644 --- a/man/readCEEW.Rd +++ b/man/readCEEW.Rd @@ -16,7 +16,7 @@ Read Employment factors and cumulative jobs for RE techs (for India) Reports published by CEEW et al. See README.txt in the source folder for more information. } \examples{ - \dontrun{ + \dontrun{ a <- readSource("CEEW",convert=F,subtype="Employment") } } diff --git a/man/readConferenceBoard.Rd b/man/readConferenceBoard.Rd deleted file mode 100644 index bf96a277..00000000 --- a/man/readConferenceBoard.Rd +++ /dev/null @@ -1,17 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/readConferenceBoard.R -\name{readConferenceBoard} -\alias{readConferenceBoard} -\title{readConferenceBoard} -\usage{ -readConferenceBoard() -} -\value{ -A magpie object -} -\description{ -Employment and GDP-related data from Conference Board https://www.conference-board.org/data/economydatabase/total-economy-database-productivity -} -\author{ -Aman Malik -} diff --git a/man/readDaviesCooling.Rd b/man/readDaviesCooling.Rd index 1004c551..2c84d298 100644 --- a/man/readDaviesCooling.Rd +++ b/man/readDaviesCooling.Rd @@ -19,8 +19,8 @@ Read in Davies (2013) data on shares of cooling types per electricity technology and GCAM region } \examples{ - -\dontrun{ a <- readSource(type="DaviesCooling") +\dontrun{ +a <- readSource(type = "DaviesCooling") } } diff --git a/man/readDias.Rd b/man/readDias.Rd deleted file mode 100644 index 9e256061..00000000 --- a/man/readDias.Rd +++ /dev/null @@ -1,27 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/readDias.R -\name{readDias} -\alias{readDias} -\title{readDias -Contains employment factors and direct jobs for coal power, employment factors and indirect jobs -for coal mining for EU countries. Numbers taken from Dias et al. (2018)} -\usage{ -readDias(subtype) -} -\arguments{ -\item{subtype}{Employment factors or Employment} -} -\value{ -magpie object containing either employment or employment factors. -} -\description{ -readDias -Contains employment factors and direct jobs for coal power, employment factors and indirect jobs -for coal mining for EU countries. Numbers taken from Dias et al. (2018) -} -\examples{ - \dontrun{ a <- readSource(type="Dias",convert=FALSE) } -} -\author{ -Aman Malik -} diff --git a/man/readEDGETransport.Rd b/man/readEDGETransport.Rd index e8663c63..21d8cff7 100644 --- a/man/readEDGETransport.Rd +++ b/man/readEDGETransport.Rd @@ -2,26 +2,27 @@ % Please edit documentation in R/readEDGETransport.R \name{readEDGETransport} \alias{readEDGETransport} -\title{Read EDGETransport inputs} +\title{Read REMIND/EDGE-T iterative input data} \usage{ -readEDGETransport(subtype = "logit_exponent") +readEDGETransport(subtype) } \arguments{ -\item{subtype}{logit_exponents, SW, pref, ptab4W, value_time, harmonized_intensities, price_nonmot, UCD_NEC_iso, loadFactor, esCapCost, fe_demand_tech, shares_LDV_transport, demISO, annual_mileage} +\item{subtype}{REMIND/iterative EDGE-T input data subtypes} } \value{ magpie object of EDGEtransport iterative inputs } \description{ -Read-in EDGETransport inputs csv file as magclass object +Run EDGE-Transport Standalone in all used scenario combinations to supply input data +to REMIND and the iterative EDGE-T script } \examples{ -\dontrun{ a <- readSource(type="EDGETransport") +\dontrun{ a <- readSource(type = "EDGETransport") } } \seealso{ \code{\link{readSource}} } \author{ -Marianna Rottoli, Alois Dirnaichner +Johanna Hoppe } diff --git a/man/readEurostat_EffortSharing.Rd b/man/readEurostat_EffortSharing.Rd index 2a1946a4..079c09d8 100644 --- a/man/readEurostat_EffortSharing.Rd +++ b/man/readEurostat_EffortSharing.Rd @@ -16,10 +16,10 @@ magpie object of the EU Effort Sharing targets (%) or Effort Sharing historical Read-in EU Effort Sharing targets and historical emissions csv files as magclass object } \examples{ - -\dontrun{ a <- readSource(type="Eurostat_EffortSharing",subtype="target") +\dontrun{ +a <- readSource(type = "Eurostat_EffortSharing", subtype = "target") } - + } \seealso{ \code{\link{readSource}} diff --git a/man/readExpertGuess.Rd b/man/readExpertGuess.Rd index 6323cb4b..576494e3 100644 --- a/man/readExpertGuess.Rd +++ b/man/readExpertGuess.Rd @@ -16,7 +16,13 @@ production in total steel production and years between which a linear convergence from historic to target shares is to be applied. \item \code{cement_production_convergence_parameters}: convergence year and level (relative to global average) to which per-capita cement demand converges -\item Any of the others nobody cared to document. +\item \code{ies} +\item \code{prtp} +\item \code{CCSbounds} +\item \code{costsTradePeFinancial} +\item \code{tradeContsraints}: parameter by Nicolas Bauer (2024) for the region +specific trade constraints, values different to 1 activate constraints +and the value is used as effectiveness to varying degrees such as percentage numbers }} } \value{ @@ -26,8 +32,8 @@ magpie object of the data Read-in data that are based on expert guess } \examples{ - -\dontrun{ a <- readSource(type="ExpertGuess",subtype="ies") +\dontrun{ +a <- readSource(type = "ExpertGuess", subtype = "ies") } } diff --git a/man/readGEA2012.Rd b/man/readGEA2012.Rd index b6527fd9..427cfd9d 100644 --- a/man/readGEA2012.Rd +++ b/man/readGEA2012.Rd @@ -16,8 +16,8 @@ MAgPIE object of the GEA data Read in datafiles comprising fossil fuel data from the Global Energy Assessment 2012 } \examples{ - -\dontrun{ a <- readSource("GEA2012","coal") +\dontrun{ +a <- readSource("GEA2012", "coal") } } diff --git a/man/readGlobalCCSinstitute.Rd b/man/readGlobalCCSinstitute.Rd new file mode 100644 index 00000000..4fed6ea8 --- /dev/null +++ b/man/readGlobalCCSinstitute.Rd @@ -0,0 +1,20 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/readGlobalCCSinstitute.R +\name{readGlobalCCSinstitute} +\alias{readGlobalCCSinstitute} +\title{Read Global CCS Institute Project Database} +\usage{ +readGlobalCCSinstitute(subtype = "08-09-2017") +} +\arguments{ +\item{subtype}{Project Database version to read, one of +- \code{'08-09-2017'}: Data apparently from June 2017. +- \code{'2023-11'}: Data from the +\href{zotero://select/items/3_E5GNNPZ8}{Global Status of CCS 2023} report.} +} +\value{ +A \code{\link[magclass:magclass-package]{magpie}} object. +} +\description{ +Read Global CCS Institute Project Database +} diff --git a/man/readGlobalEnergyMonitor.Rd b/man/readGlobalEnergyMonitor.Rd index 9a1f0424..453bf758 100644 --- a/man/readGlobalEnergyMonitor.Rd +++ b/man/readGlobalEnergyMonitor.Rd @@ -6,15 +6,9 @@ \usage{ readGlobalEnergyMonitor() } -\value{ -A [`magpie`][magclass::magclass] object. -} \description{ -Read Global Energy Monitor data -} -\seealso{ -[`readSource()`] +read GEM data for all available technologies and relevant statuses } \author{ -Falk Benke +Rahel Mandaroux, Falk Benke, Pascal Weigmann } diff --git a/man/readIAEA.Rd b/man/readIAEA.Rd index 9bfdb411..fa8723b4 100644 --- a/man/readIAEA.Rd +++ b/man/readIAEA.Rd @@ -7,7 +7,7 @@ readIAEA() } \description{ -Data on currently operating and under-construction nuclear power plants, reactors planned and proposed, +Data on currently operating and under-construction nuclear power plants, reactors planned and proposed, electricity generation from nuclear } \author{ diff --git a/man/readIEA_CCUS.Rd b/man/readIEA_CCUS.Rd new file mode 100644 index 00000000..8c847359 --- /dev/null +++ b/man/readIEA_CCUS.Rd @@ -0,0 +1,19 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/readIEA_CCUS.R +\name{readIEA_CCUS} +\alias{readIEA_CCUS} +\title{Read IEA CCUS data} +\usage{ +readIEA_CCUS(subtype) +} +\arguments{ +\item{subtype}{either `historical` for data until 2023, +`projections` for "high" and "low" projections up to 2030 used as input-data + or `pipeline` separated by status for use in formulating near-term bounds} +} +\description{ +Reads in capacities from projects in IEA CCUS database +} +\author{ +Anne Merfort, Falk Benke +} diff --git a/man/readIEA_HSMR.Rd b/man/readIEA_HSMR.Rd new file mode 100644 index 00000000..24ddfa68 --- /dev/null +++ b/man/readIEA_HSMR.Rd @@ -0,0 +1,15 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/readIEA_HSMR.R +\name{readIEA_HSMR} +\alias{readIEA_HSMR} +\title{read IEA Hydro Special Market Report} +\usage{ +readIEA_HSMR() +} +\description{ +read Hydro capacities and near-term outlook from data scraped from +https://www.iea.org/data-and-statistics/data-tools/hydropower-data-explorer +} +\author{ +Pascal Weigmann +} diff --git a/man/readIEA_REN.Rd b/man/readIEA_REN.Rd index 9077da2c..787aff5c 100644 --- a/man/readIEA_REN.Rd +++ b/man/readIEA_REN.Rd @@ -10,7 +10,7 @@ readIEA_REN() Reads the distributed solar pv capacity from IEA Renewables report (2019). } \details{ -Capacity in GW. Distributed solar, defined in the IEA Renewables (2019), includes +Capacity in GW. Distributed solar, defined in the IEA Renewables (2019), includes rooftop residential (0-10 kW, grid-connected), tooftop and ground-mounted commercial and industrial (10-1000kW, grid-connected), and off-grid (8W - 100 kW) } diff --git a/man/readIEA_WEO.Rd b/man/readIEA_WEO.Rd index 81d5fab4..5ead5561 100644 --- a/man/readIEA_WEO.Rd +++ b/man/readIEA_WEO.Rd @@ -7,14 +7,17 @@ readIEA_WEO(subtype) } \arguments{ -\item{subtype}{data subtype. Either "Capacity", "Generation", "Emissions", "Investment Costs", "O&M Costs" or "Efficiency"} +\item{subtype}{data subtype. Either "Capacity", "Generation", "Emissions", +"Investment Costs", "O&M Costs" or "Efficiency"} } \value{ -magpie object of the WEO data on generation (TWh), capacities (GW), emissions (Mt CO2) or disaggregated investment cost as magpie object +magpie object of the WEO data on generation (TWh), capacities (GW), +emissions (Mt CO2) or disaggregated investment cost as magpie object } \description{ -Read-in IEA WEO 2016 data for investment costs, O&M costs and Efficiency of different technologies, and -WEO 2017 data for historical electricity capacities (GW), generation (TWh) or emissions (Mt CO2). +Read-in IEA WEO 2016 data for investment costs, O&M costs and +Efficiency of different technologies, and WEO 2017 data for historical +electricity capacities (GW), generation (TWh) or emissions (Mt CO2). WEO 2019 data for PE and FE (Mtoe). } \examples{ diff --git a/man/readIEA_WEO_2021.Rd b/man/readIEA_WEO_2021.Rd deleted file mode 100644 index f763f19b..00000000 --- a/man/readIEA_WEO_2021.Rd +++ /dev/null @@ -1,17 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/readIEA_WEO_2021.R -\name{readIEA_WEO_2021} -\alias{readIEA_WEO_2021} -\title{IEA WEO 2021 Data} -\usage{ -readIEA_WEO_2021() -} -\value{ -A [`magpie`][magclass::magclass] object. -} -\description{ -IEA WEO 2021 Data. See README in input file for more details. -} -\author{ -Falk Benke -} diff --git a/man/readIEA_WorldEnergyOutlook.Rd b/man/readIEA_WorldEnergyOutlook.Rd new file mode 100644 index 00000000..b657748d --- /dev/null +++ b/man/readIEA_WorldEnergyOutlook.Rd @@ -0,0 +1,14 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/readIEA_WorldEnergyOutlook.R +\name{readIEA_WorldEnergyOutlook} +\alias{readIEA_WorldEnergyOutlook} +\title{Read in IEA World Energy Outlook Data from 2023} +\usage{ +readIEA_WorldEnergyOutlook() +} +\description{ +Read in IEA World Energy Outlook Data from 2023 +} +\author{ +Falk Benke +} diff --git a/man/readIIASA_subs_taxes.Rd b/man/readIIASA_subs_taxes.Rd index 85014229..71b5d48e 100644 --- a/man/readIIASA_subs_taxes.Rd +++ b/man/readIIASA_subs_taxes.Rd @@ -20,8 +20,8 @@ Read-in country level data on final energy taxes and subsidies as provided from IIASA from .csv file as magclass object } \examples{ - -\dontrun{ a <- readSource(type="IIASA_subs_taxes","tax_rate") +\dontrun{ +a <- readSource(type = "IIASA_subs_taxes", "tax_rate") } } diff --git a/man/readILO.Rd b/man/readILO.Rd deleted file mode 100644 index 4eb2fbb5..00000000 --- a/man/readILO.Rd +++ /dev/null @@ -1,11 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/readILO.R -\name{readILO} -\alias{readILO} -\title{Read ILO} -\usage{ -readILO() -} -\description{ -Read ILO -} diff --git a/man/readINNOPATHS.Rd b/man/readINNOPATHS.Rd index c4127f65..c1e6a8f6 100644 --- a/man/readINNOPATHS.Rd +++ b/man/readINNOPATHS.Rd @@ -9,6 +9,3 @@ readINNOPATHS() \description{ Read INNOPATHS } -\author{ -Falk Benke -} diff --git a/man/readKLWdamage.Rd b/man/readKLWdamage.Rd new file mode 100644 index 00000000..c0f62b34 --- /dev/null +++ b/man/readKLWdamage.Rd @@ -0,0 +1,30 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/readKLWdamage.R +\name{readKLWdamage} +\alias{readKLWdamage} +\title{Reads country-specific damage coefficients for the damage function presented in +Kotz et al. (2024). Data has been provided by the authors. +This contains data for all countries and for 1000 boostrapping realizations per country, +capturing uncertainty from climate and empirical modeling. +Subtypes are the temperature and temperature^2 coefficients and the maximum temperature +per country for which the function is defined.} +\usage{ +readKLWdamage(subtype) +} +\arguments{ +\item{subtype}{data subtype. Either "beta1", "beta2" or "maxGMT"} +} +\value{ +KLW damage coefficients +} +\description{ +Reads country-specific damage coefficients for the damage function presented in +Kotz et al. (2024). Data has been provided by the authors. +This contains data for all countries and for 1000 boostrapping realizations per country, +capturing uncertainty from climate and empirical modeling. +Subtypes are the temperature and temperature^2 coefficients and the maximum temperature +per country for which the function is defined. +} +\author{ +Franziska Piontek +} diff --git a/man/readLee.Rd b/man/readLee.Rd index c1b25cd4..9ef7769e 100644 --- a/man/readLee.Rd +++ b/man/readLee.Rd @@ -18,11 +18,9 @@ readLee Read in Aviation emission data from Lee } \examples{ - -\dontrun{ a <- readSource(type="", subtype="Waste") +\dontrun{ +a <- readSource(type = "", subtype = "Waste") } - - } \seealso{ \code{\link{readSource}} diff --git a/man/readMacknickIntensities.Rd b/man/readMacknickIntensities.Rd index 53ad695d..66e86caa 100644 --- a/man/readMacknickIntensities.Rd +++ b/man/readMacknickIntensities.Rd @@ -19,8 +19,8 @@ Read in Macknick (2011) data on water consumption and withdrawal coefficients per electricity technology } \examples{ - -\dontrun{ a <- readSource(type="MacknickIntensities", convert = FALSE) +\dontrun{ +a <- readSource(type = "MacknickIntensities", convert = FALSE) } } \seealso{ diff --git a/man/readNREL.Rd b/man/readNREL.Rd index 895d0607..9e797803 100644 --- a/man/readNREL.Rd +++ b/man/readNREL.Rd @@ -16,8 +16,8 @@ magpie object of NREL Read-in NREL xlsx file as magclass object } \examples{ - -\dontrun{ a <- readSource(type="NREL",subtype="onshore") +\dontrun{ +a <- readSource(type = "NREL", subtype = "onshore") } } diff --git a/man/readOECD.Rd b/man/readOECD.Rd new file mode 100644 index 00000000..57f71fc6 --- /dev/null +++ b/man/readOECD.Rd @@ -0,0 +1,31 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/readOECD.R +\name{readOECD} +\alias{readOECD} +\alias{convertOECD} +\title{Read OECD} +\usage{ +readOECD() + +convertOECD(x) +} +\arguments{ +\item{x}{MAgPIE object returned from readOECD} +} +\value{ +The read-in data, usually a magpie object. If supplementary is TRUE a list including +the data and metadata is returned instead. The temporal and data dimensionality +should match the source data. The spatial dimension should either match the source data or, +if the convert argument is set to TRUE, should be on ISO code country level. +} +\description{ +Read-in risk premium +} +\examples{ +\dontrun{ +readSource("OECD") +} +} +\seealso{ +[madrat::readSource()] +} diff --git a/man/readOpenmod.Rd b/man/readOpenmod.Rd index 9392c636..47dc074e 100644 --- a/man/readOpenmod.Rd +++ b/man/readOpenmod.Rd @@ -13,14 +13,11 @@ magpie object of the LIMES team updated Openmod data on capacities (GW) Read-in an modified openmod capacities data file as magclass object } \examples{ - -\dontrun{ a <- readSource(type="Openmod") +\dontrun{ +a <- readSource(type = "Openmod") } - + } \seealso{ \code{\link{readSource}} } -\author{ -Renato Rodrigues -} diff --git a/man/readPWT.Rd b/man/readPWT.Rd new file mode 100644 index 00000000..2dea8e47 --- /dev/null +++ b/man/readPWT.Rd @@ -0,0 +1,31 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/readPWT.R +\name{readPWT} +\alias{readPWT} +\alias{convertPWT} +\title{Read PWT} +\usage{ +readPWT() + +convertPWT(x) +} +\arguments{ +\item{x}{MAgPIE object returned by readPWT} +} +\value{ +The read-in data, usually a magpie object. If supplementary is TRUE a list including +the data and metadata is returned instead. The temporal and data dimensionality +should match the source data. The spatial dimension should either match the source data or, +if the convert argument is set to TRUE, should be on ISO code country level. +} +\description{ +Read-in PWT data as magclass object +} +\examples{ +\dontrun{ +readSource("PWT") +} +} +\seealso{ +[madrat::readSource()] +} diff --git a/man/readREN21.Rd b/man/readREN21.Rd index 24a51ebd..61cbc348 100644 --- a/man/readREN21.Rd +++ b/man/readREN21.Rd @@ -13,9 +13,9 @@ readREN21(subtype) magpie object with Total Installed Capacity targets in GW for different target years } \description{ -Reads excel sheet with data on proposed policies, -on Renewable energy capacity targets (which are broken down into Total Installed Capacity -(TIC-Absolute), Additional Installed Capacity (AC-Absolute), and Production Absolute targets) +Reads excel sheet with data on proposed policies, +on Renewable energy capacity targets (which are broken down into Total Installed Capacity +(TIC-Absolute), Additional Installed Capacity (AC-Absolute), and Production Absolute targets) or regional technology costs } \details{ diff --git a/man/readRam.Rd b/man/readRam.Rd deleted file mode 100644 index aeefd659..00000000 --- a/man/readRam.Rd +++ /dev/null @@ -1,11 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/readRam.R -\name{readRam} -\alias{readRam} -\title{Regional multiliers from Ram et al. , 2018} -\usage{ -readRam() -} -\description{ -Regional multiliers from Ram et al. , 2018 -} diff --git a/man/readRemindCesPrices.Rd b/man/readRemindCesPrices.Rd deleted file mode 100644 index f912a0bd..00000000 --- a/man/readRemindCesPrices.Rd +++ /dev/null @@ -1,28 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/readRemindCesPrices.R -\name{readRemindCesPrices} -\alias{readRemindCesPrices} -\title{Read RemindCesPrices} -\usage{ -readRemindCesPrices(subtype = "ccd632d33a") -} -\arguments{ -\item{subtype}{Regional resolution of REMIND data which should be loaded. ccd632d33a corresponds to the REMIND-11, -and 690d3718e1 to REMIND-H12} -} -\value{ -magpie object of REMIND prices -} -\description{ -Read-in CES derivatives/prices from former REMIND runs -} -\examples{ -\dontrun{ a <- readSource(type="RemindCesPrices", subtype = "ccd632d33a") -} -} -\seealso{ -\code{\link{readSource}} -} -\author{ -Antoine Levesque -} diff --git a/man/readRutovitz2015.Rd b/man/readRutovitz2015.Rd deleted file mode 100644 index d0806af0..00000000 --- a/man/readRutovitz2015.Rd +++ /dev/null @@ -1,20 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/readRutovitz2015.R -\name{readRutovitz2015} -\alias{readRutovitz2015} -\title{Employment factors for various power production technologies from Rutovitz et al. 2015} -\usage{ -readRutovitz2015(subtype) -} -\arguments{ -\item{subtype}{Either "oecd_ef","regional_ef","coal_ef","gas_ef", "regional_mult"} -} -\value{ -magpie object of employment factors for different technologies and activities in Jobs/MW (all except fuel_supply) or Jobs/PJ (fuel_supply). Subtype "regional_mult" is a regional multiplier without units. -} -\description{ -Rutovitz, J., Dominish, E., & Downes, J. (2015). Calculating global energy sector jobs—2015 methodology update. Institute for Sustainable Futures, University of Technology, Sydney. https://opus.lib.uts.edu.au/bitstream/10453/43718/1/Rutovitzetal2015Calculatingglobalenergysectorjobsmethodology.pdf -} -\author{ -Aman Malik -} diff --git a/man/readWGBU.Rd b/man/readWGBU.Rd index 3a63c234..bdfdba7a 100644 --- a/man/readWGBU.Rd +++ b/man/readWGBU.Rd @@ -13,8 +13,8 @@ magpie object of WGBU Read-in an WGBU xlsx file as magclass object } \examples{ - -\dontrun{ a <- readSource(type="WGBU") +\dontrun{ +a <- readSource(type = "WGBU") } } diff --git a/man/readnonEnergyDemand.Rd b/man/readnonEnergyDemand.Rd index e293aff4..feac7581 100644 --- a/man/readnonEnergyDemand.Rd +++ b/man/readnonEnergyDemand.Rd @@ -13,8 +13,8 @@ magpie object of region dependent data Read Final energy demand for feedstocks (non-energy use) } \examples{ - -\dontrun{ a <- readSource(type="nonEnergyDemand") +\dontrun{ +a <- readSource(type = "nonEnergyDemand") } } diff --git a/man/toolCubicFunctionAggregate.Rd b/man/toolCubicFunctionAggregate.Rd index bb71d5b2..04ef45a3 100644 --- a/man/toolCubicFunctionAggregate.Rd +++ b/man/toolCubicFunctionAggregate.Rd @@ -90,16 +90,18 @@ defined inverse function in the selected boundaries. # Example # data -EUR <- setNames(data.frame(30,50,0.123432,2),c("c1","c2","c3","c4")) -NEU <- setNames(data.frame(30,50,1.650330,2),c("c1","c2","c3","c4")) -df <- rbind(EUR,NEU) -row.names(df) <- c("EUR","NEU") +EUR <- setNames(data.frame(30, 50, 0.123432, 2), c("c1", "c2", "c3", "c4")) +NEU <- setNames(data.frame(30, 50, 1.650330, 2), c("c1", "c2", "c3", "c4")) +df <- rbind(EUR, NEU) +row.names(df) <- c("EUR", "NEU") # maxExtraction (upper limit for function estimation) maxExtraction <- 23 # output -output <- toolCubicFunctionAggregate(df,xUpperBound=maxExtraction, - returnMagpie=FALSE,returnChart=TRUE,returnSample=TRUE, - label=list(x="Cumulated Extraction", y="Cost", legend="Region Fuel Functions")) +output <- toolCubicFunctionAggregate(df, + xUpperBound = maxExtraction, + returnMagpie = FALSE, returnChart = TRUE, returnSample = TRUE, + label = list(x = "Cumulated Extraction", y = "Cost", legend = "Region Fuel Functions") +) output$coeff output$chart } diff --git a/man/toolCubicFunctionDisaggregate.Rd b/man/toolCubicFunctionDisaggregate.Rd index 7c2e5333..b3d586df 100644 --- a/man/toolCubicFunctionDisaggregate.Rd +++ b/man/toolCubicFunctionDisaggregate.Rd @@ -93,16 +93,18 @@ defined inverse function in the selected boundaries. # Example # LAM coefficients -df <- setNames(data.frame(30,50,0.34369,2),c("c1","c2","c3","c4")) +df <- setNames(data.frame(30, 50, 0.34369, 2), c("c1", "c2", "c3", "c4")) row.names(df) <- "LAM" # weight -weight <- setNames(c(21,0,579,3,228),c("ARG","BOL","BRA","CHL","COL")) +weight <- setNames(c(21, 0, 579, 3, 228), c("ARG", "BOL", "BRA", "CHL", "COL")) # maxExtraction (upper limit for function estimation) maxExtraction <- 100 # output -output <- toolCubicFunctionDisaggregate(df, weight,xUpperBound=maxExtraction, - returnMagpie=FALSE,returnChart=TRUE,returnSample=TRUE, - label=list(x="Cumulated Extraction", y="Cost", legend="Region Fuel Functions"))#' output$chart +output <- toolCubicFunctionDisaggregate(df, weight, + xUpperBound = maxExtraction, + returnMagpie = FALSE, returnChart = TRUE, returnSample = TRUE, + label = list(x = "Cumulated Extraction", y = "Cost", legend = "Region Fuel Functions") +) #' output$chart output$coeff output$chart } diff --git a/man/toolFillEU34Countries.Rd b/man/toolFillEU34Countries.Rd index 3c283d74..05b6ad52 100644 --- a/man/toolFillEU34Countries.Rd +++ b/man/toolFillEU34Countries.Rd @@ -3,7 +3,7 @@ \name{toolFillEU34Countries} \alias{toolFillEU34Countries} \title{Sets values for 6 EU countries not belonging to EU 28 but EU 34 to zero if -they are NA. Used to avoid EUR region not yielding NA because of these countries.} +they are NA. Used to avoid EUR region yielding NA because of these countries.} \usage{ toolFillEU34Countries(x) } @@ -12,7 +12,7 @@ toolFillEU34Countries(x) } \description{ Sets values for 6 EU countries not belonging to EU 28 but EU 34 to zero if -they are NA. Used to avoid EUR region not yielding NA because of these countries. +they are NA. Used to avoid EUR region yielding NA because of these countries. } \author{ Falk Benke