Skip to content

Commit

Permalink
Merge pull request pik-piam#162 from pweigmann/fix-fe-v2
Browse files Browse the repository at this point in the history
fix FE aggregation bug v2
  • Loading branch information
pweigmann authored Dec 1, 2021
2 parents cdacb9f + 946539a commit 6e36496
Show file tree
Hide file tree
Showing 6 changed files with 92 additions and 39 deletions.
2 changes: 1 addition & 1 deletion .buildlibrary
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
ValidationKey: '17255420'
ValidationKey: '17274382'
AcceptedWarnings:
- 'Warning: package ''.*'' was built under R version'
- 'Warning: namespace ''.*'' is not available and has been replaced'
Expand Down
2 changes: 1 addition & 1 deletion .zenodo.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"title": "mrremind: MadRat REMIND Input Data Package",
"version": "0.91.0",
"version": "0.91.1",
"description": "<p>The mrremind packages contains data preprocessing for the REMIND model.<\/p>",
"creators": [
{
Expand Down
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: mrremind
Type: Package
Title: MadRat REMIND Input Data Package
Version: 0.91.0
Version: 0.91.1
Date: 2021-12-01
Authors@R: c(person("Lavinia", "Baumstark", email = "lavinia@pik-potsdam.de", role = c("aut","cre")),
person("Renato", "Rodrigues", role = "aut"),
Expand Down
94 changes: 59 additions & 35 deletions R/calcFE.R
Original file line number Diff line number Diff line change
Expand Up @@ -36,53 +36,77 @@ calcFE <- function(source = "IEA", scenario_proj = "SSP2") {
# rename entries of data to match the reporting names
getNames(x) <- paste0(map$output," (EJ/yr)")

# add more variables
x <- mbind(x,setNames(dimSums(x[,,"FE|",pmatch=TRUE],dim=3),"FE (EJ/yr)"))
x <- mbind(x,setNames(dimSums(x[,,"FE|",pmatch=TRUE][,,"Electricity",pmatch=TRUE],dim=3),"FE|Electricity (EJ/yr)"))
x <- mbind(x,setNames(dimSums(x[,,"FE|",pmatch=TRUE][,,"Gases",pmatch=TRUE],dim=3),"FE|Gases (EJ/yr)"))
x <- mbind(x,setNames(dimSums(x[,,"FE|",pmatch=TRUE][,,"Heat",pmatch=TRUE],dim=3),"FE|Heat (EJ/yr)"))
x <- mbind(x,setNames(dimSums(x[,,"FE|",pmatch=TRUE][,,"Liquids",pmatch=TRUE],dim=3),"FE|Liquids (EJ/yr)"))
x <- mbind(x,setNames(dimSums(x[,,"FE|",pmatch=TRUE][,,"Solids",pmatch=TRUE],dim=3),"FE|Solids (EJ/yr)"))

# aggregate CHP and nonCHP electricity
x <- mbind(x,setNames(x[,,"SE|Electricity|Coal|CHP (EJ/yr)"] + x[,,"SE|Electricity|Coal|nonCHP (EJ/yr)"],"SE|Electricity|Coal (EJ/yr)"))
x <- mbind(x,setNames(x[,,"SE|Electricity|Gas|CHP (EJ/yr)"] + x[,,"SE|Electricity|Gas|nonCHP (EJ/yr)"],"SE|Electricity|Gas (EJ/yr)"))
x <- mbind(x,setNames(x[,,"SE|Electricity|Biomass|CHP (EJ/yr)"] + x[,,"SE|Electricity|Biomass|nonCHP (EJ/yr)"],"SE|Electricity|Biomass (EJ/yr)"))
x <- mbind(x,setNames(x[,,"SE|Electricity|Coal|CHP (EJ/yr)"] +
x[,,"SE|Electricity|Coal|nonCHP (EJ/yr)"], "SE|Electricity|Coal (EJ/yr)"))
x <- mbind(x,setNames(x[,,"SE|Electricity|Gas|CHP (EJ/yr)"] +
x[,,"SE|Electricity|Gas|nonCHP (EJ/yr)"], "SE|Electricity|Gas (EJ/yr)"))
x <- mbind(x,setNames(x[,,"SE|Electricity|Biomass|CHP (EJ/yr)"] +
x[,,"SE|Electricity|Biomass|nonCHP (EJ/yr)"], "SE|Electricity|Biomass (EJ/yr)"))

# aggregate CHP and HP heat
x <- mbind(x,setNames(x[,,"SE|Heat|Coal|CHP (EJ/yr)"] + x[,,"SE|Heat|Coal|HP (EJ/yr)"],"SE|Heat|Coal (EJ/yr)"))
x <- mbind(x,setNames(x[,,"SE|Heat|Gas|CHP (EJ/yr)"] + x[,,"SE|Heat|Gas|HP (EJ/yr)"],"SE|Heat|Gas (EJ/yr)"))
x <- mbind(x,setNames(x[,,"SE|Heat|Biomass|CHP (EJ/yr)"] + x[,,"SE|Heat|Biomass|HP (EJ/yr)"],"SE|Heat|Biomass (EJ/yr)"))
x <- mbind(x,setNames(x[,,"SE|Heat|Coal|CHP (EJ/yr)"] +
x[,,"SE|Heat|Coal|HP (EJ/yr)"], "SE|Heat|Coal (EJ/yr)"))
x <- mbind(x,setNames(x[,,"SE|Heat|Gas|CHP (EJ/yr)"] +
x[,,"SE|Heat|Gas|HP (EJ/yr)"], "SE|Heat|Gas (EJ/yr)"))
x <- mbind(x,setNames(x[,,"SE|Heat|Biomass|CHP (EJ/yr)"] +
x[,,"SE|Heat|Biomass|HP (EJ/yr)"], "SE|Heat|Biomass (EJ/yr)"))

# rename Diesel/Petrol to LDV/non-LDV
x <- mbind(x,setNames(x[,,"FE|Transport|Liquids|Diesel|Biomass (EJ/yr)"],"FE|Transport|non-LDV|Liquids|Biomass (EJ/yr)"))
x <- mbind(x,setNames(x[,,"FE|Transport|Liquids|Diesel|Fossil (EJ/yr)"], "FE|Transport|non-LDV|Liquids|Fossil (EJ/yr)"))
x <- mbind(x,setNames(x[,,"FE|Transport|Liquids|Petrol|Biomass (EJ/yr)"],"FE|Transport|LDV|Liquids|Biomass (EJ/yr)"))
x <- mbind(x,setNames(x[,,"FE|Transport|Liquids|Petrol|Fossil (EJ/yr)"], "FE|Transport|LDV|Liquids|Fossil (EJ/yr)"))
x <- x[,,c("FE|Transport|Liquids|Diesel|Biomass (EJ/yr)","FE|Transport|Liquids|Diesel|Fossil (EJ/yr)","FE|Transport|Liquids|Petrol|Biomass (EJ/yr)","FE|Transport|Liquids|Petrol|Fossil (EJ/yr)"),invert=TRUE]
x <- mbind(x,setNames(x[,,"FE|Transport|Liquids|Diesel|Biomass (EJ/yr)"], "FE|Transport|non-LDV|Liquids|Biomass (EJ/yr)"))
x <- mbind(x,setNames(x[,,"FE|Transport|Liquids|Diesel|Fossil (EJ/yr)"], "FE|Transport|non-LDV|Liquids|Fossil (EJ/yr)"))
x <- mbind(x,setNames(x[,,"FE|Transport|Liquids|Petrol|Biomass (EJ/yr)"], "FE|Transport|LDV|Liquids|Biomass (EJ/yr)"))
x <- mbind(x,setNames(x[,,"FE|Transport|Liquids|Petrol|Fossil (EJ/yr)"], "FE|Transport|LDV|Liquids|Fossil (EJ/yr)"))
x <- x[,, c("FE|Transport|Liquids|Diesel|Biomass (EJ/yr)",
"FE|Transport|Liquids|Diesel|Fossil (EJ/yr)",
"FE|Transport|Liquids|Petrol|Biomass (EJ/yr)",
"FE|Transport|Liquids|Petrol|Fossil (EJ/yr)"), invert=TRUE]

# aggregate LDV and non-LDV to Liquids|Biomass/Fossil
x <- mbind(x,setNames(x[,,"FE|Transport|LDV|Liquids|Biomass (EJ/yr)"] + x[,,"FE|Transport|non-LDV|Liquids|Biomass (EJ/yr)"],"FE|Transport|Liquids|Biomass (EJ/yr)"))
x <- mbind(x,setNames(x[,,"FE|Transport|LDV|Liquids|Fossil (EJ/yr)"] + x[,,"FE|Transport|non-LDV|Liquids|Fossil (EJ/yr)"],"FE|Transport|Liquids|Fossil (EJ/yr)"))
x <- mbind(x,setNames(x[,,"FE|Transport|LDV|Liquids|Biomass (EJ/yr)"] +
x[,,"FE|Transport|non-LDV|Liquids|Biomass (EJ/yr)"], "FE|Transport|Liquids|Biomass (EJ/yr)"))
x <- mbind(x,setNames(x[,,"FE|Transport|LDV|Liquids|Fossil (EJ/yr)"] +
x[,,"FE|Transport|non-LDV|Liquids|Fossil (EJ/yr)"], "FE|Transport|Liquids|Fossil (EJ/yr)"))

# aggregate biomass and fossil data
x <- mbind(x,setNames(x[,,"FE|Buildings|Gases|Biomass (EJ/yr)"] + x[,,"FE|Buildings|Gases|Fossil (EJ/yr)"],"FE|Buildings|Gases (EJ/yr)"))
x <- mbind(x,setNames(x[,,"FE|Industry|Gases|Biomass (EJ/yr)"] + x[,,"FE|Industry|Gases|Fossil (EJ/yr)"],"FE|Industry|Gases (EJ/yr)"))
x <- mbind(x,setNames(x[,,"FE|Transport|Gases|Biomass (EJ/yr)"] + x[,,"FE|Transport|Gases|Fossil (EJ/yr)"],"FE|Transport|Gases (EJ/yr)"))
x <- mbind(x,setNames(x[,,"FE|Buildings|Gases|Biomass (EJ/yr)"] +
x[,,"FE|Buildings|Gases|Fossil (EJ/yr)"], "FE|Buildings|Gases (EJ/yr)"))
x <- mbind(x,setNames(x[,,"FE|Industry|Gases|Biomass (EJ/yr)"] +
x[,,"FE|Industry|Gases|Fossil (EJ/yr)"], "FE|Industry|Gases (EJ/yr)"))
x <- mbind(x,setNames(x[,,"FE|Transport|Gases|Biomass (EJ/yr)"] +
x[,,"FE|Transport|Gases|Fossil (EJ/yr)"], "FE|Transport|Gases (EJ/yr)"))

x <- mbind(x,setNames(x[,,"FE|Buildings|Liquids|Biomass (EJ/yr)"] + x[,,"FE|Buildings|Liquids|Fossil (EJ/yr)"],"FE|Buildings|Liquids (EJ/yr)"))
x <- mbind(x,setNames(x[,,"FE|Industry|Liquids|Biomass (EJ/yr)"] + x[,,"FE|Industry|Liquids|Fossil (EJ/yr)"],"FE|Industry|Liquids (EJ/yr)"))
x <- mbind(x,setNames(x[,,"FE|Transport|Liquids|Biomass (EJ/yr)"] + x[,,"FE|Transport|Liquids|Fossil (EJ/yr)"],"FE|Transport|Liquids (EJ/yr)"))

x <- mbind(x,setNames(x[,,"FE|Buildings|Solids|Biomass (EJ/yr)"] + x[,,"FE|Buildings|Solids|Fossil (EJ/yr)"],"FE|Buildings|Solids (EJ/yr)"))
x <- mbind(x,setNames(x[,,"FE|Industry|Solids|Biomass (EJ/yr)"] + x[,,"FE|Industry|Solids|Fossil (EJ/yr)"],"FE|Industry|Solids (EJ/yr)"))

# add more variables
x <- mbind(x,setNames(dimSums(x[,,"FE|",pmatch=TRUE],dim=3),"FE (EJ/yr)"))
x <- mbind(x,setNames(dimSums(x[,,"FE|",pmatch=TRUE][,,"Electricity",pmatch=TRUE],dim=3),"FE|Electricity (EJ/yr)"))
x <- mbind(x,setNames(dimSums(x[,,"FE|",pmatch=TRUE][,,"Gases",pmatch=TRUE],dim=3),"FE|Gases (EJ/yr)"))
x <- mbind(x,setNames(dimSums(x[,,"FE|",pmatch=TRUE][,,"Heat",pmatch=TRUE],dim=3),"FE|Heat (EJ/yr)"))
x <- mbind(x,setNames(dimSums(x[,,"FE|",pmatch=TRUE][,,"Liquids",pmatch=TRUE],dim=3),"FE|Liquids (EJ/yr)"))
x <- mbind(x,setNames(dimSums(x[,,"FE|",pmatch=TRUE][,,"Solids",pmatch=TRUE],dim=3),"FE|Solids (EJ/yr)"))
x <- mbind(x,setNames(x[,,"FE|Buildings|Liquids|Biomass (EJ/yr)"] +
x[,,"FE|Buildings|Liquids|Fossil (EJ/yr)"], "FE|Buildings|Liquids (EJ/yr)"))
x <- mbind(x,setNames(x[,,"FE|Industry|Liquids|Biomass (EJ/yr)"] +
x[,,"FE|Industry|Liquids|Fossil (EJ/yr)"], "FE|Industry|Liquids (EJ/yr)"))
x <- mbind(x,setNames(x[,,"FE|Transport|Liquids|Biomass (EJ/yr)"] +
x[,,"FE|Transport|Liquids|Fossil (EJ/yr)"], "FE|Transport|Liquids (EJ/yr)"))

x <- mbind(x,setNames(x[,,"FE|Buildings|Solids|Biomass (EJ/yr)"] +
x[,,"FE|Buildings|Solids|Fossil (EJ/yr)"], "FE|Buildings|Solids (EJ/yr)"))
x <- mbind(x,setNames(x[,,"FE|Industry|Solids|Biomass (EJ/yr)"] +
x[,,"FE|Industry|Solids|Fossil (EJ/yr)"], "FE|Industry|Solids (EJ/yr)"))

# add stationary
x <- mbind(x,setNames(x[,,"FE|Buildings|Electricity (EJ/yr)"] + x[,,"FE|Industry|Electricity (EJ/yr)"],"FE|Stationary|Electricity (EJ/yr)"))
x <- mbind(x,setNames(x[,,"FE|Buildings|Gases (EJ/yr)"] + x[,,"FE|Industry|Gases (EJ/yr)"], "FE|Stationary|Gases (EJ/yr)"))
x <- mbind(x,setNames(x[,,"FE|Buildings|Heat (EJ/yr)"] + x[,,"FE|Industry|Heat (EJ/yr)"], "FE|Stationary|Heat (EJ/yr)"))
x <- mbind(x,setNames(x[,,"FE|Buildings|Liquids (EJ/yr)"] + x[,,"FE|Industry|Liquids (EJ/yr)"], "FE|Stationary|Liquids (EJ/yr)"))
x <- mbind(x,setNames(x[,,"FE|Buildings|Solids (EJ/yr)"] + x[,,"FE|Industry|Solids (EJ/yr)"], "FE|Stationary|Solids (EJ/yr)"))
x <- mbind(x,setNames(x[,,"FE|Buildings|Electricity (EJ/yr)"] +
x[,,"FE|Industry|Electricity (EJ/yr)"], "FE|Stationary|Electricity (EJ/yr)"))
x <- mbind(x,setNames(x[,,"FE|Buildings|Gases (EJ/yr)"] +
x[,,"FE|Industry|Gases (EJ/yr)"], "FE|Stationary|Gases (EJ/yr)"))
x <- mbind(x,setNames(x[,,"FE|Buildings|Heat (EJ/yr)"] +
x[,,"FE|Industry|Heat (EJ/yr)"], "FE|Stationary|Heat (EJ/yr)"))
x <- mbind(x,setNames(x[,,"FE|Buildings|Liquids (EJ/yr)"] +
x[,,"FE|Industry|Liquids (EJ/yr)"], "FE|Stationary|Liquids (EJ/yr)"))
x <- mbind(x,setNames(x[,,"FE|Buildings|Solids (EJ/yr)"] +
x[,,"FE|Industry|Solids (EJ/yr)"], "FE|Stationary|Solids (EJ/yr)"))

# add total for buildings
x <- mbind(x,setNames(x[,,"FE|Buildings|Liquids (EJ/yr)"]
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# MadRat REMIND Input Data Package

R package **mrremind**, version **0.90.3**
R package **mrremind**, version **0.91.1**

[![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://codecov.io/gh/pik-piam/mrremind) [![r-universe](https://pik-piam.r-universe.dev/badges/mrremind)](https://pik-piam.r-universe.dev/ui#builds)

Expand Down
29 changes: 29 additions & 0 deletions man/readMueller.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 6e36496

Please sign in to comment.