diff --git a/.buildlibrary b/.buildlibrary index 5ed15d4d..8b8051c4 100644 --- a/.buildlibrary +++ b/.buildlibrary @@ -1,4 +1,4 @@ -ValidationKey: '38486525' +ValidationKey: '38546504' AcceptedWarnings: - 'Warning: package ''.*'' was built under R version' - 'Warning: namespace ''.*'' is not available and has been replaced' diff --git a/CITATION.cff b/CITATION.cff index e3966330..9beaec83 100644 --- a/CITATION.cff +++ b/CITATION.cff @@ -2,7 +2,7 @@ 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.192.5 +version: 0.192.8 date-released: '2024-09-27' abstract: The mrremind packages contains data preprocessing for the REMIND model. authors: diff --git a/DESCRIPTION b/DESCRIPTION index 0247e04d..e96b26f0 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,7 +1,7 @@ Type: Package Package: mrremind Title: MadRat REMIND Input Data Package -Version: 0.192.5 +Version: 0.192.8 Date: 2024-09-27 Authors@R: c( person("Lavinia", "Baumstark", , "lavinia@pik-potsdam.de", role = c("aut", "cre")), diff --git a/NAMESPACE b/NAMESPACE index 0fc2eca7..04590f83 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -48,7 +48,7 @@ export(convertUNFCCC) export(convertUNIDO) export(convertUSGS) export(filter_historical_mif) -export(fullThresholds) +export(fullTHRESHOLDS) export(readADVANCE_WP2) export(readAGEB) export(readAR6GWP) @@ -83,6 +83,7 @@ import(madrat) import(magclass) import(mrcommons) import(mrdrivers) +importFrom(GDPuc,convertGDP) importFrom(assertr,assert) importFrom(assertr,in_set) importFrom(assertr,not_na) diff --git a/R/EDGE-Industry.R b/R/EDGE-Industry.R index 9c48fac4..5a3f21f9 100644 --- a/R/EDGE-Industry.R +++ b/R/EDGE-Industry.R @@ -1334,75 +1334,11 @@ calcIndustry_Value_Added <- function(subtype = 'physical', select(region = 'RegionCode', iso3c = 'CountryCode') ## UNIDO INSTATA2 data ---- - INDSTAT <- readSource('UNIDO', 'INDSTAT2', convert = FALSE) %>% - madrat_mule() - - ### add iso3c codes and regions ---- - # FIXME We are substituting some historic country codes by 'default' codes of - # current countries. Generally, they are situated in the same aggregation - # region, so this has no impact on the derivation of regional statistics. - # This does not apply to former Yugoslavia however. Since the countries in - # question (currently Slovenia and Kroatia, others might join the EU at a - # later time and then require reclassification) are small compared to the - # respective regions (Europe and Rest-of-World), the impact should be limited. - INDSTAT <- INDSTAT %>% - # fix some country codes - filter(810 != .data$country) %>% # SUN data synthetic anyhow - mutate( - country = ifelse(200 == .data$country, 203, .data$country), # CSE for CSK - country = ifelse(530 == .data$country, 531, .data$country), # CUW for ANT - country = ifelse(890 == .data$country, 688, .data$country), # SRB for YUG - country = ifelse(891 == .data$country, 688, .data$country) # SRB for SCG - ) %>% - # add iso3c country codes - left_join( - bind_rows( - countrycode::codelist %>% - select('iso3c', 'un') %>% - filter(!is.na(.data$iso3c), !is.na(.data$un)), - - # country codes missing from package countrycode - tribble( - ~iso3c, ~un, - 'TWN', 158, # Taiwan - 'ETH', 230, # Ethiopia and Eritrea - 'DEU', 278, # East Germany - 'DEU', 280, # West Germany - 'PAN', 590, # Panama - 'SDN', 736 # Sudan - ) - ), - - c('country' = 'un') - ) %>% - assert(not_na, everything()) %>% - # add regions based on country codes - left_join( - bind_rows( - region_mapping, - tibble(iso3c = 'SUN', region = 'SUN') - ), - 'iso3c') %>% - assert(not_na, everything()) - - ### censor unreasonable data ---- - INDSTAT_censor <- bind_rows( - bind_rows( - tibble(iso3c = 'IRQ', year = 1994:1998), - tibble(iso3c = 'MDV', year = INDSTAT$year %>% unique()), - tibble(iso3c = 'BIH', year = 1990:1991) - ) %>% - mutate(censor = TRUE, - reason = 'unreasonable'), + INDSTAT <- readSource('UNIDO', 'INDSTAT2') %>% + as_tibble() %>% + filter(!is.na(.data$value)) %>% + left_join(region_mapping, 'iso3c') - bind_rows( - tibble(iso3c = 'HKG', year = unique(INDSTAT$year)), - tibble(iso3c = 'MAC', year = unique(INDSTAT$year)), - tibble(iso3c = 'CHN', year = min(INDSTAT$year):1997) - ) %>% - mutate(censor = TRUE, - reason = 'not representative') - ) ## population data ---- population <- calcOutput('Population', naming = 'scenario', @@ -1431,19 +1367,16 @@ calcIndustry_Value_Added <- function(subtype = 'physical', GDP = .data$GDP * 1e6) ## ---- load cement production data ---- - data_cement_production <- calcOutput('Cement', aggregate = FALSE, warnNA = FALSE) %>% + data_cement_production <- calcOutput('Cement', aggregate = FALSE, + warnNA = FALSE) %>% magclass_to_tibble() %>% select(-'data') %>% filter(!is.na(.data$value)) # calc manufacturing share in GDP ---- manufacturing_share <- INDSTAT %>% - filter('D' == .data$isic, - between(.data$utable, 17, 20)) %>% - group_by(!!!syms(c('iso3c', 'year'))) %>% - filter(max(.data$lastupdated) == .data$lastupdated) %>% - ungroup() %>% - select('region', 'iso3c', 'year', manufacturing = 'value') %>% + filter('manufacturing' == .data$subsector) %>% + pivot_wider(names_from = 'subsector') %>% inner_join( GDP %>% filter(max(INDSTAT$year) >= .data$year) %>% @@ -1459,19 +1392,10 @@ calcIndustry_Value_Added <- function(subtype = 'physical', summarise(population = calc_mode(.data$population), .groups = 'drop'), c('iso3c', 'year') - ) %>% - # mark unreasonable data for exclusion - full_join( - INDSTAT_censor %>% - select(-.data$reason), - - c('iso3c', 'year') - ) %>% - mutate(censor = ifelse(is.na(.data$censor), FALSE, TRUE)) + ) # regress per-capita industry value added ---- regression_data <- manufacturing_share %>% - filter(!.data$censor) %>% duplicate(region = 'World') %>% pivot_longer(c('population', 'GDP', 'manufacturing')) %>% group_by(.data$region, .data$iso3c, .data$year, .data$name) %>% @@ -1549,13 +1473,7 @@ calcIndustry_Value_Added <- function(subtype = 'physical', regression_data_steel <- inner_join( INDSTAT %>% - filter(20 == .data$ctable, - '27' == .data$isic, - between(.data$utable, 17, 20), - 0 < .data$value) %>% - group_by(.data$iso3c, .data$year) %>% - filter(max(.data$lastupdated) == .data$lastupdated) %>% - ungroup() %>% + filter('steel' == .data$subsector) %>% select('region', 'iso3c', 'year', steel.VA = 'value'), data_steel_production %>% @@ -1565,30 +1483,6 @@ calcIndustry_Value_Added <- function(subtype = 'physical', c('iso3c', 'year') ) - # Data with an obvious mismatch between steel production and steel value added - # figures is excluded from the regression. - # Data for Hong Kong (1973-1979) is excluded, since no data for China is - # available for this period and the data would bias the regression for the CHN - # region. - steel_censor <- list_to_data_frame( - list(BGD = 2011, - CHE = 1995:1996, - CHL = 2008, - HKG = 1973:1979, - HRV = 2012, - IRL = 1980, - LKA = 2006, - MAR = 1989:2004, - MKD = 1996, - PAK = 1981:1982, - TUN = 2003:2006), - 'iso3c', 'year') %>% - mutate(censored = TRUE) - - regression_data_steel <- regression_data_steel %>% - left_join(steel_censor, c('iso3c', 'year')) %>% - mutate(censored = ifelse(is.na(.data$censored), FALSE, TRUE)) - ## compute regional and World aggregates ---- regression_data_steel <- regression_data_steel %>% inner_join( @@ -1614,13 +1508,12 @@ calcIndustry_Value_Added <- function(subtype = 'physical', regression_data_steel, regression_data_steel %>% - filter(!.data$censored) %>% - group_by(.data$region, .data$year, .data$censored, .data$variable) %>% + group_by(.data$region, .data$year, .data$variable) %>% summarise(value = sum(.data$value, na.rm = TRUE), iso3c = 'Total', .groups = 'drop') ) %>% - group_by(!!!syms(c('region', 'iso3c', 'year', 'censored', 'variable'))) %>% + group_by(!!!syms(c('region', 'iso3c', 'year', 'variable'))) %>% pivot_wider(names_from = 'variable') ## compute regression parameters ---- @@ -1632,8 +1525,7 @@ calcIndustry_Value_Added <- function(subtype = 'physical', nls(formula = steel.VApt ~ a * exp(b / GDPpC), data = regression_data_steel %>% filter(r == .data$region, - 'Total' == .data$iso3c, - !.data$censored) %>% + 'Total' == .data$iso3c) %>% mutate(steel.VApt = .data$steel.VA / .data$steel.production, GDPpC = .data$GDP / .data$population), start = list(a = 500, b = 500), @@ -1732,8 +1624,7 @@ calcIndustry_Value_Added <- function(subtype = 'physical', if (!is.null(save.plots)) { d_plot_region_totals <- regression_data_steel %>% ungroup() %>% - filter('Total' == .data$iso3c, - !.data$censored) %>% + filter('Total' == .data$iso3c) %>% mutate(GDPpC = .data$GDP / .data$population, steel.VA.pt = .data$steel.VA / .data$steel.production) %>% # filter outliers @@ -1827,13 +1718,7 @@ calcIndustry_Value_Added <- function(subtype = 'physical', ## calculate regression data ---- regression_data_cement <- full_join( INDSTAT %>% - filter(20 == .data$ctable, - '26' == .data$isic, - between(.data$utable, 17, 20), - 0 < .data$value) %>% - group_by(.data$iso3c, .data$year) %>% - filter(max(.data$lastupdated) == .data$lastupdated) %>% - ungroup() %>% + filter('cement' == .data$subsector) %>% select('region', 'iso3c', 'year', cement.VA = 'value') %>% filter(.data$year >= min(data_cement_production$year)), @@ -1845,23 +1730,6 @@ calcIndustry_Value_Added <- function(subtype = 'physical', ) %>% filter(!is.na(.data$cement.production)) - ### censor nonsensical data ---- - cement_censor <- list_to_data_frame(list( - BDI = 1980:2010, # zero cement production - CIV = 1990:1993, # cement VA 100 times higher than before and after - NAM = 2007:2010, # zero cement production - HKG = 1973:1979, # no data for CHN prior to 1980 - IRQ = 1992:1997, # cement VA 100 times higher than before and after - RUS = 1970:1990, # exclude data from Soviet period which biases - # projections up - NULL), - 'iso3c', 'year') %>% - mutate(censored = TRUE) - - regression_data_cement <- regression_data_cement %>% - left_join(cement_censor, c('iso3c', 'year')) %>% - mutate(censored = ifelse(is.na(.data$censored), FALSE, TRUE)) - ### compute regional and World aggregates ---- regression_data_cement <- regression_data_cement %>% inner_join( @@ -1885,11 +1753,10 @@ calcIndustry_Value_Added <- function(subtype = 'physical', regression_data_cement, regression_data_cement %>% - filter(!.data$censored, - # exclude CHA from global regression data, because it dominates + filter(# exclude CHA from global regression data, because it dominates # the global regression !('World' == .data$region & 'CHN' == .data$iso3c)) %>% - group_by(!!!syms(c('region', 'year', 'censored', 'name'))) %>% + group_by(!!!syms(c('region', 'year', 'name'))) %>% summarise(value = sum(.data$value, na.rm = TRUE), iso3c = 'Total', .groups = 'drop') @@ -1905,8 +1772,7 @@ calcIndustry_Value_Added <- function(subtype = 'physical', nls(formula = cement.PpC ~ a * exp(b / GDPpC), data = regression_data_cement %>% filter(r == .data$region, - 'Total' == .data$iso3c, - !.data$censored) %>% + 'Total' == .data$iso3c) %>% mutate(cement.PpC = .data$cement.production / .data$population, GDPpC = .data$GDP / .data$population), start = list(a = 1, b = -1000), @@ -2007,18 +1873,17 @@ calcIndustry_Value_Added <- function(subtype = 'physical', data = regression_data_cement %>% filter(r == .data$region, 'Total' != .data$iso3c, - !is.na(.data$cement.VA), - !.data$censored) %>% + !is.na(.data$cement.VA)) %>% pivot_longer(all_of(c('population', 'cement.production', 'GDP', 'cement.VA'))) %>% - group_by(.data$region, .data$year, .data$censored, .data$name) %>% + group_by(.data$region, .data$year, .data$name) %>% summarise(value = sum(.data$value), iso3c = 'Total', .groups = 'drop') %>% pivot_wider() %>% mutate(cement.VApt = .data$cement.VA / .data$cement.production, GDPpC = .data$GDP / .data$population), - start = list(a = 250, b = -4000), + start = list(a = 250, b = 1500), trace = FALSE) %>% broom::tidy() %>% select('term', 'estimate') %>% @@ -2061,16 +1926,13 @@ calcIndustry_Value_Added <- function(subtype = 'physical', ## plot cement regressions ==== if (!is.null(save.plots)) { d_plot_region_totals <- regression_data_cement %>% - filter(!.data$censored, - 'Total' == .data$iso3c) %>% + filter('Total' == .data$iso3c) %>% mutate(GDPpC = .data$GDP / .data$population) d_plot_countries <- regression_data_cement %>% - filter(!.data$censored) %>% semi_join( regression_data_cement %>% - filter(!.data$censored, - 'World' != .data$region, + filter('World' != .data$region, 'Total' != .data$iso3c) %>% distinct(.data$region, .data$iso3c) %>% group_by(.data$region) %>% @@ -2230,8 +2092,7 @@ calcIndustry_Value_Added <- function(subtype = 'physical', if (!is.null(save.plots)) { d_plot_region_totals <- regression_data_cement %>% ungroup() %>% - filter('Total' == .data$iso3c, - !.data$censored) %>% + filter('Total' == .data$iso3c) %>% mutate(GDPpC = .data$GDP / .data$population, cement.VA.pt = .data$cement.VA / .data$cement.production) %>% # filter outliers @@ -2308,23 +2169,11 @@ calcIndustry_Value_Added <- function(subtype = 'physical', ## compile regression data ---- regression_data_chemicals <- inner_join( INDSTAT %>% - filter(20 == .data$ctable, - '24' == .data$isic, - between(.data$utable, 17, 20), - 0 < .data$value) %>% - group_by(!!!syms(c('region', 'iso3c', 'year'))) %>% - filter(max(.data$lastupdated) == .data$lastupdated) %>% - ungroup() %>% + filter('chemicals' == .data$subsector) %>% select('region', 'iso3c', 'year', chemicals.VA = 'value'), INDSTAT %>% - filter(20 == .data$ctable, - 'D' == .data$isic, - between(.data$utable, 17, 20), - 0 < .data$value) %>% - group_by(!!!syms(c('region', 'iso3c', 'year'))) %>% - filter(max(.data$lastupdated) == .data$lastupdated) %>% - ungroup() %>% + filter('manufacturing' == .data$subsector) %>% select('region', 'iso3c', 'year', manufacturing.VA = 'value'), c('region', 'iso3c', 'year') @@ -2345,28 +2194,14 @@ calcIndustry_Value_Added <- function(subtype = 'physical', ) %>% duplicate(region = 'World') - ### censor nonsensical data ---- - chemicals_censor <- list_to_data_frame(list( - CIV = 1989, - NER = 1999:2002, - HKG = c(1973:1979, 2008:2015), - MAC = c(1978:1979)), - 'iso3c', 'year') %>% - mutate(censored = TRUE) - - regression_data_chemicals <- regression_data_chemicals %>% - left_join(chemicals_censor, c('iso3c', 'year')) %>% - mutate(censored = ifelse(is.na(.data$censored), FALSE, TRUE)) - ### compute regional and World aggregates ---- regression_data_chemicals <- bind_rows( regression_data_chemicals, regression_data_chemicals %>% - filter(!.data$censored) %>% pivot_longer(c('population', 'GDP', 'manufacturing.VA', 'chemicals.VA')) %>% - group_by(!!!syms(c('region', 'year', 'censored', 'name'))) %>% + group_by(!!!syms(c('region', 'year', 'name'))) %>% summarise(value = sum(.data$value), iso3c = 'Total', .groups = 'drop') %>% @@ -2384,8 +2219,7 @@ calcIndustry_Value_Added <- function(subtype = 'physical', nls(formula = chemicals.VA / population ~ a * exp(b / GDPpC), data = regression_data_chemicals %>% filter(r == .data$region, - 'Total' == .data$iso3c, - !.data$censored), + 'Total' == .data$iso3c), start = list(a = 1000, b = -100), trace = FALSE) %>% broom::tidy() %>% @@ -2451,15 +2285,12 @@ calcIndustry_Value_Added <- function(subtype = 'physical', ## plot chemicals regressions ================================================ if (!is.null(save.plots)) { d_plot_region_totals <- regression_data_chemicals %>% - filter(!.data$censored, - 'Total' == .data$iso3c) + filter('Total' == .data$iso3c) d_plot_countries <- regression_data_chemicals %>% - filter(!.data$censored) %>% semi_join( regression_data_chemicals %>% - filter(!.data$censored, - 'World' != .data$region, + filter('World' != .data$region, 'Total' != .data$iso3c) %>% distinct(.data$region, .data$iso3c) %>% group_by(.data$region) %>% diff --git a/R/UNIDO.R b/R/UNIDO.R index be7231eb..e526ee18 100644 --- a/R/UNIDO.R +++ b/R/UNIDO.R @@ -61,9 +61,11 @@ #' #' @seealso [`readSource()`], [`calcOutput()`] #' -#' @importFrom assertr assert not_na +#' @importFrom assertr assert not_na verify #' @importFrom dplyr anti_join bind_rows filter group_by inner_join left_join #' mutate select summarise +#' @importFrom GDPuc convertGDP +#' @importFrom magrittr %>% #' @importFrom quitte list_to_data_frame madrat_mule #' @importFrom readr read_csv #' @importFrom rlang .data is_empty @@ -193,15 +195,23 @@ convertUNIDO <- function(x, subtype = 'INDSTAT2') ## subsector exclusion ---- subsector_exclusion <- bind_rows( list_to_data_frame( - list(IRQ = 1994:1998, - MDV = unique(x$year), - BIH = 1990:1991, - HKG = unique(x$year), - MAC = unique(x$year), - CHN = min(x$year):1997), + list( + # unreasonable data + IRQ = 1994:1998, + MDV = unique(x$year), + BIH = 1990:1991, + # unrepresentative data + HKG = unique(x$year), + MAC = unique(x$year), + CHN = min(x$year):1997), 'iso3c', 'year') %>% mutate(subsector = 'manufacturing'), + # Data with an obvious mismatch between steel production and + # steel value added figures is excluded. + # Data for Hong Kong (1973-1979) is excluded since no data for + # PR China is available for this period and the data would bias + # any regression for the CHA region. list_to_data_frame( list(BGD = 2011, CHE = 1995:1996, @@ -252,21 +262,21 @@ convertUNIDO <- function(x, subtype = 'INDSTAT2') c('iso3c', 'year', 'subsector') ) %>% + # GDP conversion is only valid for monetary units + verify('$' == .data$unit) %>% + convertGDP(unit_in = 'constant 2005 US$MER', + unit_out = mrdrivers::toolGetUnitDollar(), + replace_NAs = 'with_USA') %>% group_by(.data$iso3c, .data$subsector, .data$year) %>% filter(max(.data$lastupdated) == .data$lastupdated) %>% # for split countries, which lead to duplicates (e.g. CUW), use # the maximum summarise(value = max(.data$value), .groups = 'drop') - # convert from $2005 to $2017 and return ---- + # return ---- x %>% as.magpie(spatial = 1, temporal = 3, data = ncol(.)) %>% toolCountryFill(verbosity = 2) %>% - GDPuc::convertGDP( - unit_in = "constant 2005 US$MER", - unit_out = mrdrivers::toolGetUnitDollar(), - replace_NAs = "with_USA" - ) %>% return() } ) @@ -300,7 +310,6 @@ calcUNIDO <- function(subtype = 'INDSTAT2') # $/year * 1e-9 $bn/$ = $bn/year x <- mbind(x_no_manufacturing, x_otherInd) * 1e-9 - x[is.na(x)] <- 0 # give proper variable names subsector_names <- c('cement', 'chemicals', 'steel', 'otherInd') diff --git a/R/fullThresholds.R b/R/fullTHRESHOLDS.R similarity index 87% rename from R/fullThresholds.R rename to R/fullTHRESHOLDS.R index e5cdc1cb..fed3fb97 100644 --- a/R/fullThresholds.R +++ b/R/fullTHRESHOLDS.R @@ -8,7 +8,8 @@ #' validationConfig or "full" to export all pipeline data #' #' @export -fullThresholds <- function(type = "config") { +fullTHRESHOLDS <- function(type = "config") { + # get region mappings for aggregation ---- # Determines all regions data should be aggregated to by examining the columns # of the `regionmapping` and `extramappings` currently configured. @@ -53,8 +54,8 @@ fullThresholds <- function(type = "config") { warnNA = FALSE, try = FALSE, years = years) wind <- calcOutput("ProjectPipelines", subtype = "wind", - aggregate = columnsForAggregation, round = 3, - warnNA = FALSE, try = FALSE, years = years) + aggregate = columnsForAggregation, round = 3, + warnNA = FALSE, try = FALSE, years = years) solar <- calcOutput("ProjectPipelines", subtype = "solar", aggregate = columnsForAggregation, round = 3, @@ -89,6 +90,16 @@ fullThresholds <- function(type = "config") { out["GLO", 2020, "max_yel"] <- out["GLO", 2020, "operational"]*1.05 out["GLO", 2020, "max_red"] <- out["GLO", 2020, "operational"]*1.1 + # exception for Nuclear: use 10%, 20% + out["GLO", , "Cap|Electricity|Nuclear.min_red"] <- + out["GLO", , "Cap|Electricity|Nuclear.operational"]*0.8 + out["GLO", , "Cap|Electricity|Nuclear.min_yel"] <- + out["GLO", , "Cap|Electricity|Nuclear.operational"]*0.9 + out["GLO", , "Cap|Electricity|Nuclear.max_yel"] <- + out["GLO", , "Cap|Electricity|Nuclear.operational"]*1.1 + out["GLO", , "Cap|Electricity|Nuclear.max_red"] <- + out["GLO", , "Cap|Electricity|Nuclear.operational"]*1.2 + # exception for 2020: use yel and red bounds for regions out[regions, 2020, "min_red"] <- out[regions, 2020, "operational"]*0.6 out[regions, 2020, "min_yel"] <- out[regions, 2020, "operational"]*0.8 @@ -127,13 +138,13 @@ fullThresholds <- function(type = "config") { out <- out[, , c("min_", "max_"), pmatch = TRUE] %>% as.quitte() %>% pivot_wider(names_from = "status") %>% - select(-scenario) + 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 = outfile, row.names = FALSE, quote = FALSE) + utils::write.csv(file = outfile, row.names = FALSE, quote = FALSE) } else { warning("`type` must be either `full` or `config`") diff --git a/R/readGlobalEnergyMonitor.R b/R/readGlobalEnergyMonitor.R index 7df730ba..779ed686 100644 --- a/R/readGlobalEnergyMonitor.R +++ b/R/readGlobalEnergyMonitor.R @@ -13,7 +13,7 @@ readGlobalEnergyMonitor <- function() { # 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", + d <- readxl::read_excel("Global-Integrated-Power-June-2024.xlsx", sheet = "Power facilities", trim_ws = TRUE, col_types = "text") %>% @@ -32,11 +32,13 @@ readGlobalEnergyMonitor <- function() { 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) %>% + filter(!is.na(.data$start), .data$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)) + filter(.data$variable != "oil/gas") %>% + mutate(start = as.numeric(.data$start), + end = as.numeric(.data$end), + value = as.numeric(.data$value)) # no end year defined: # use average lifetime of technology (from generisdata_tech) @@ -51,10 +53,10 @@ readGlobalEnergyMonitor <- function() { # 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)) + d[!is.na(d$c2), ] %>% mutate(region = .data$c1, value = as.numeric(.data$v1)), + d[!is.na(d$c2), ] %>% mutate(region = .data$c2, value = as.numeric(.data$v2)) ) %>% - select(-c1, -c2, -v1, -v2) + select(-"c1", -"c2", -"v1", -"v2") # use proper variable names d[d$variable == "coal", "variable"] <- "Cap|Electricity|Coal" @@ -77,7 +79,7 @@ readGlobalEnergyMonitor <- function() { # 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 + d <- mutate(d, end = pmin(.data$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( @@ -86,9 +88,9 @@ readGlobalEnergyMonitor <- function() { ) } tmp <- do.call(rbind, tmp_list) %>% - group_by(region, variable, status, period) %>% - summarise(value = sum(value)) %>% - filter(period %in% c(2020, 2025, 2030)) + group_by(.data$region, .data$variable, .data$status, .data$period) %>% + summarise(value = sum(.data$value)) %>% + filter(.data$period %in% c(2020, 2025, 2030)) # convert to magclass object x <- as.magpie(tmp, spatial = "region") @@ -103,9 +105,6 @@ readGlobalEnergyMonitor <- function() { add_dimension(dim = 3.1, add = "variable", nm = "Cap|Electricity|Wind") ) - # collapse variable and status dimension into one - # getNames(x) <- gsub(pattern = "\\.", replacement = "|", x = getNames(x)) - # convert MW to GW x <- x / 1000 x <- add_dimension(x, dim = 3.4, add = "unit", nm = "GW") diff --git a/R/readIEA_CCUS.R b/R/readIEA_CCUS.R index e49277a8..d6ebbc87 100644 --- a/R/readIEA_CCUS.R +++ b/R/readIEA_CCUS.R @@ -16,7 +16,7 @@ readIEA_CCUS <- function(subtype) { # project types filter applied to source projectTypes <- c("Full chain", "Storage", "T&S") - data <- read_excel("IEA CCUS Projects Database 2024.xlsx", + data <- readxl::read_excel("IEA CCUS Projects Database 2024.xlsx", sheet = "CCUS Projects Database" ) %>% select( @@ -49,12 +49,12 @@ readIEA_CCUS <- function(subtype) { # remove mixed-country data and attach single country data weighted by GDP data <- data %>% - filter(!country %in% c("Japan-Malaysia", "Australia-Japan")) %>% + filter(!.data$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)) + mutate(JM, country = "Japan", value = .data$value*gdp_JPN/(gdp_JPN + gdp_MYS)), + mutate(JM, country = "Malaysia", value = .data$value*gdp_MYS/(gdp_JPN + gdp_MYS)), + mutate(AJ, country = "Australia", value = .data$value*gdp_AUS/(gdp_JPN + gdp_AUS)), + mutate(AJ, country = "Japan", value = .data$value*gdp_JPN/(gdp_JPN + gdp_AUS)) ) if (subtype == "historical") { diff --git a/R/readIEA_HSMR.R b/R/readIEA_HSMR.R index ac4f45e5..122a58c6 100644 --- a/R/readIEA_HSMR.R +++ b/R/readIEA_HSMR.R @@ -9,20 +9,20 @@ #' @export readIEA_HSMR <- function() { - x <- read_xlsx("IEA_Hydropower_Special_Market_Report.xlsx") %>% + x <- readxl::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, - "2020_pumped" = cap_2020_pumped, - "2030_pumped" = cap_2020_pumped + of_that_pumped, + mutate("2020_operational" = .data$capacity_2020, + "2030_expected" = .data$capacity_2020 + .data$add_expected_2030 - .data$of_that_pumped, + "2030_accelerated" = .data$capacity_2020 + .data$add_accelerated_2030 - .data$of_that_pumped, + "2020_pumped" = .data$cap_2020_pumped, + "2030_pumped" = .data$cap_2020_pumped + .data$of_that_pumped, variable = "Cap|Electricity|Hydro") %>% pivot_longer(cols = c("2020_operational", "2030_expected", "2030_accelerated", "2020_pumped", "2030_pumped"), names_to = "year_scen") %>% - select(country, variable, year_scen, unit, value) %>% - separate(year_scen, c("year", "status")) %>% + select("country", "variable", "year_scen", "unit", "value") %>% + separate(.data$year_scen, c("year", "status")) %>% as.magpie(spatial = "country") x[, 2020, "accelerated"] <- x[, 2020, "operational"] diff --git a/R/readIEA_PRIS.R b/R/readIEA_PRIS.R index 8a3ee880..9916941c 100644 --- a/R/readIEA_PRIS.R +++ b/R/readIEA_PRIS.R @@ -10,19 +10,19 @@ readIEA_PRIS <- function() { # only information given is what is currently operating and what is under # construction (without start date) - x <- read_xlsx("nuclear_capacities_20240716.xlsx") %>% - mutate("operational" = operational, - "construction" = construction, + x <- readxl::read_xlsx("nuclear_capacities_20240716.xlsx") %>% + mutate("operational" = .data$operational, + "construction" = .data$construction, variable = "Cap|Electricity|Nuclear") %>% mutate(year = "y2020") %>% # technically, its 2024 pivot_longer(cols = c("operational", "construction"), names_to = "status") %>% - select(country, year, variable, status, unit, value) %>% + select("country", "year", "variable", "status", "unit", "value") %>% as.magpie(spatial = "country", temporal = "year") %>% add_dimension(dim = 3.1, add = "model", nm = "IEA_PRIS") # move "construction" values to year 2030 - x <- add_columns(x, addnm = c("y2030"), dim = 2, fill= NA) + x <- add_columns(x, addnm = c("y2030"), dim = 2, fill = NA) x[, 2030, "construction"] <- x[, 2020, "construction"] x[, 2020, "construction"] <- 0 diff --git a/README.md b/README.md index 4c792cd4..1ea5368d 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # MadRat REMIND Input Data Package -R package **mrremind**, version **0.192.5** +R package **mrremind**, version **0.192.8** [![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,7 +39,7 @@ 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.192.8, . A BibTeX entry for LaTeX users is @@ -48,7 +48,7 @@ A BibTeX entry for LaTeX users is 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 and Johannes Koch}, year = {2024}, - note = {R package version 0.192.5}, + note = {R package version 0.192.8}, url = {https://github.com/pik-piam/mrremind}, } ``` diff --git a/man/fullThresholds.Rd b/man/fullTHRESHOLDS.Rd similarity index 75% rename from man/fullThresholds.Rd rename to man/fullTHRESHOLDS.Rd index aa47381c..a08bf55f 100644 --- a/man/fullThresholds.Rd +++ b/man/fullTHRESHOLDS.Rd @@ -1,10 +1,10 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/fullThresholds.R -\name{fullThresholds} -\alias{fullThresholds} +% Please edit documentation in R/fullTHRESHOLDS.R +\name{fullTHRESHOLDS} +\alias{fullTHRESHOLDS} \title{export validation thresholds} \usage{ -fullThresholds(type = "config") +fullTHRESHOLDS(type = "config") } \arguments{ \item{type}{choose either "config" to export thresholds as used in the