diff --git a/.buildlibrary b/.buildlibrary index b034f56b..19612f1e 100644 --- a/.buildlibrary +++ b/.buildlibrary @@ -1,4 +1,4 @@ -ValidationKey: '36399136' +ValidationKey: '36420877' 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 233ade70..82251d79 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.182.8 -date-released: '2024-07-08' +version: 0.182.9 +date-released: '2024-07-09' abstract: The mrremind packages contains data preprocessing for the REMIND model. authors: - family-names: Baumstark diff --git a/DESCRIPTION b/DESCRIPTION index 29496934..baa9a689 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,8 +1,8 @@ Type: Package Package: mrremind Title: MadRat REMIND Input Data Package -Version: 0.182.8 -Date: 2024-07-08 +Version: 0.182.9 +Date: 2024-07-09 Authors@R: c( person("Lavinia", "Baumstark", , "lavinia@pik-potsdam.de", role = c("aut", "cre")), person("Renato", "Rodrigues", role = "aut"), diff --git a/R/calcEEAGHGProjections.R b/R/calcEEAGHGProjections.R index 8875b13a..5a15230e 100644 --- a/R/calcEEAGHGProjections.R +++ b/R/calcEEAGHGProjections.R @@ -5,13 +5,14 @@ #' #' @author Falk Benke #' -#' @importFrom dplyr select mutate left_join +#' @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) %>% @@ -20,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"))) %>% @@ -47,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") @@ -70,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/calcHistorical.R b/R/calcHistorical.R index e3ab52ec..9079409a 100644 --- a/R/calcHistorical.R +++ b/R/calcHistorical.R @@ -99,9 +99,6 @@ calcHistorical <- function() { # Region specific historical data ==== - # EEA GHG Projections - EEA_GHGProjections <- toolFillEU34Countries(calcOutput("EEAGHGProjections", aggregate = FALSE, warnNA = 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") @@ -233,7 +230,7 @@ calcHistorical <- function() { 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/fullVALIDATIONREMIND.R b/R/fullVALIDATIONREMIND.R index d75b4260..d4412b4a 100644 --- a/R/fullVALIDATIONREMIND.R +++ b/R/fullVALIDATIONREMIND.R @@ -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( diff --git a/README.md b/README.md index 37b62a01..c6baf43a 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # MadRat REMIND Input Data Package -R package **mrremind**, version **0.182.8** +R package **mrremind**, version **0.182.9** [![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.182.9, . 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.182.8}, + note = {R package version 0.182.9}, url = {https://github.com/pik-piam/mrremind}, } ``` 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