Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reporting and plots of renovation and construction flows #10

Merged
merged 6 commits into from
Oct 9, 2024
4 changes: 4 additions & 0 deletions R/convGDX2MIF.R
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@ convGDX2MIF <- function(gdx,
message("running reportConstruction ...")
output <- mbind(output, reportConstruction(gdx, brickSets, silent = silent)[, t, ])

## Renovation ====
message("running reportRenovation ...")
output <- mbind(output, reportRenovation(gdx, brickSets, silent = silent)[, t, ])

## Demolition ====
message("running reportDemolition ...")
output <- mbind(output, reportDemolition(gdx, brickSets, silent = silent)[, t, ])
Expand Down
105 changes: 105 additions & 0 deletions R/reportRenovation.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
#' Report renovation
#'
#' Report quantities describing the renovation of new buildings
#'
#' @param gdx gams transfer container of the BRICK GDX
#' @param brickSets character, BRICK reporting template
#' @param silent boolean, suppress warnings and printing of dimension mapping
#'
#' @author Ricarda Rosemann
#'
#' @importFrom magclass mbind setNames dimSums mselect collapseDim

reportRenovation <- function(gdx, brickSets = NULL, silent = TRUE) {

# READ -----------------------------------------------------------------------

# renovation variable
v_renovation <- readGdxSymbol(gdx, "v_renovation")

# unit conversion: million m2 / yr-> billion m2 / yr
v_renovation <- (v_renovation / 1000) %>%
mselect(qty = "area") %>%
collapseDim(dim = "qty")




# REPORT ---------------------------------------------------------------------

out <- mbind(

## Total ====
reportAgg(v_renovation,
"Renovation|Buildings (bn m2/yr)", brickSets,
agg = c(bs = "all", hs = "all", bsr = "all0", hsr = "all", vin = "all", loc = "all", typ = "resCom", inc = "all"),
silent = silent),
reportAgg(v_renovation,
"Renovation|Residential (bn m2/yr)", brickSets,
agg = c(bs = "all", hs = "all", bsr = "all0", hsr = "all", vin = "all", loc = "all", typ = "res", inc = "all"),
silent = silent),
ricardarosemann marked this conversation as resolved.
Show resolved Hide resolved
reportAgg(v_renovation,
"Renovation|Commercial (bn m2/yr)", brickSets,
agg = c(bs = "all", hs = "all", bsr = "all0", hsr = "all", vin = "all", loc = "all", typ = "com", inc = "all"),
silent = silent),


## by building type ====
reportAgg(v_renovation,
"Renovation|Residential|{typ} (bn m2/yr)", brickSets,
agg = c(bs = "all", hs = "all", bsr = "all0", hsr = "all", vin = "all", loc = "all", inc = "all"),
rprt = c(typ = "res"),
silent = silent),


## by location ====
reportAgg(v_renovation,
"Renovation|Residential|{loc} (bn m2/yr)", brickSets,
agg = c(bs = "all", hs = "all", bsr = "all0", hsr = "all", vin = "all", typ = "res", inc = "all"),
rprt = c(loc = "all"),
silent = silent),


## by initial heating system ====
reportAgg(v_renovation,
"Renovation|Residential|Initial|{hs} (bn m2/yr)", brickSets,
agg = c(bs = "all", bsr = "all0", hsr = "all", vin = "all", loc = "all", typ = "res", inc = "all"),
rprt = c(hs = "all"),
silent = silent),


## by building type + initial heating system ====
reportAgg(v_renovation,
"Renovation|Residential|{typ}|Initial|{hs} (bn m2/yr)", brickSets,
agg = c(bs = "all", bsr = "all0", hsr = "all", vin = "all", loc = "all", inc = "all"),
rprt = c(hs = "all", typ = "res"),
silent = silent),


## by final heating system ====
reportAgg(v_renovation,
"Renovation|Residential|Final|{hsr} (bn m2/yr)", brickSets,
agg = c(bs = "all", hs = "all", bsr = "all0", vin = "all", loc = "all", typ = "res", inc = "all"),
rprt = c(hsr = "all"),
silent = silent),


## by final heating system, without zero state ====
ricardarosemann marked this conversation as resolved.
Show resolved Hide resolved
reportAgg(v_renovation,
"Renovation|Residential|Final with zero|{hsr} (bn m2/yr)", brickSets,
agg = c(bs = "all", hs = "all", bsr = "all0", vin = "all", loc = "all", typ = "res", inc = "all"),
rprt = c(hsr = "all0"),
silent = silent),


robinhasse marked this conversation as resolved.
Show resolved Hide resolved
## by initial and final heating system ====
reportAgg(v_renovation,
"Renovation|Residential|{hs}|{hsr} (bn m2/yr)", brickSets,
agg = c(bs = "all", bsr = "all0", vin = "all", loc = "all", typ = "res", inc = "all"),
rprt = c(hs = "all", hsr = "all0"),
silent = silent)
ricardarosemann marked this conversation as resolved.
Show resolved Hide resolved

robinhasse marked this conversation as resolved.
Show resolved Hide resolved
)

return(out)
}
102 changes: 101 additions & 1 deletion inst/compareScenarios/cs_01_stockFlows.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ showAreaAndBarPlots(data, vars = locationRes, tot = tot, orderVars = "user", sca
walk(locationRes, showLinePlots, data = data)
```

#### by construction cohort
#### by Construction cohort
```{r Stock-Residential-(vintage)}
showAreaAndBarPlots(data, vars = rev(vintageRes), tot = tot, orderVars = "user", scales = "fixed")
```
Expand All @@ -47,3 +47,103 @@ walk(heatingRes, showLinePlots, data = data)
```

### Commercial

## Construction flow

```{r stock vars}
tot <- "Construction|Buildings"
subsec <- c("Construction|Residential",
"Construction|Commercial")
```

```{r ConstructionSubsector}
showAreaAndBarPlots(data, vars = subsec, tot = tot, orderVars = "user", scales = "fixed")
```

### All buildings

### Residential
```{r residential construction vars}
tot <- "Construction|Residential"
heatingRes <- paste(tot, heating, sep = "|")
typeRes <- paste(tot, type, sep = "|")
locationRes <- paste(tot, location, sep = "|")
```

#### by building type
```{r Construction-Residential-(type)}
showAreaAndBarPlots(data, vars = typeRes, tot = tot, orderVars = "user", scales = "fixed")
walk(typeRes, showLinePlots, data = data)
```

#### by location
```{r Construction-Residential-(location)}
showAreaAndBarPlots(data, vars = locationRes, tot = tot, orderVars = "user", scales = "fixed")
walk(locationRes, showLinePlots, data = data)
```

#### by Space heating
```{r Construction-Residential-(heating)}
showAreaAndBarPlots(data, vars = heatingRes, tot = tot, orderVars = "user", scales = "fixed")
walk(heatingRes, showLinePlots, data = data)
```

### Commercial

## Renovation flow

```{r stock vars}
tot <- "Renovation|Buildings"
subsec <- c("Renovation|Residential",
"Renovation|Commercial")
```

```{r RenovationSubsector}
showAreaAndBarPlots(data, vars = subsec, tot = tot, orderVars = "user", scales = "fixed")
```

### All buildings

### Residential
```{r residential Renovation vars}
tot <- "Renovation|Residential"
totBefore <- paste(tot, "Initial", sep = "|")
totAfter <- paste(tot, "Final", sep = "|") # for proper plotting
totAfterZero <- paste(tot, "Final with zero", sep = "|")
heatingResBefore <- paste(tot, "Initial", heating, sep = "|")
heatingResAfter <- paste(tot, "Final", heating0, sep = "|")
heatingResAfterZero <- paste(tot, "Final with zero", heating0, sep = "|")
typeRes <- paste(tot, type, sep = "|")
locationRes <- paste(tot, location, sep = "|")
```

#### by building type
```{r Renovation-Residential-(type)}
showAreaAndBarPlots(data, vars = typeRes, tot = tot, orderVars = "user", scales = "fixed")
walk(typeRes, showLinePlots, data = data)
```

#### by location
```{r Renovation-Residential-(location)}
showAreaAndBarPlots(data, vars = locationRes, tot = tot, orderVars = "user", scales = "fixed")
walk(locationRes, showLinePlots, data = data)
```

#### by Space heating (initial state)
```{r Renovation-Residential-(heatingBefore)}
showAreaAndBarPlots(data, vars = heatingResBefore, tot = totBefore, orderVars = "user", scales = "fixed")
walk(heatingResBefore, showLinePlots, data = data)
```

#### by Space heating (final state)
```{r Renovation-Residential-(heatingAfter)}
showAreaAndBarPlots(data, vars = heatingResAfter, tot = totAfter, orderVars = "user", scales = "fixed")
```

#### by Space heating (final state, with zero renovation)
```{r Renovation-Residential-(heatingAfter)}
showAreaAndBarPlots(data, vars = heatingResAfterZero, tot = totAfterZero, orderVars = "user", scales = "fixed")
walk(heatingResAfterZero, showLinePlots, data = data)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here the current variable naming means that the total is not shown in the plot, as the variables defined above actually do not exist. The total was still named in this way to preserve the coloring from mip.
Eventually this will require changes in mip to solve the issue:

  • either add the variable names of the form "Initial|{hs}" to the mip plotstyle.csv
  • or modify mip such that additional tags can be cut from the variable name - or such that the shared part of the variable name is removed (This can potentially change the behavior of mip for many other users!)

Copy link
Contributor Author

@ricardarosemann ricardarosemann Aug 23, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I found an easy (albeit not perfect) fix for this: If tot is not specified in the call to showAreaAndBarPlots, then the variable names are shortened by removing their common part, while said common part is considered to be the variable name of the total. However, the values of the total are computed simply as the sum of the plotted variables. So as a result, the area plots display the total and are colored correctly, but the total is not given by the variable Renovation|Residential. but computed as the sum of e.g. Renovation|Residential|Initial|{hs}

To obtain a solution where the variable naming is provided by removing the common part, but the total is given by the respective variable, we'd need a change in mip. The core problem here is that our variable name contains a tag (Initial or Final) that is meaningless without the tag following it (i.e. the specification of the heating system).

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Then let's go without the specific tot and let's see if RSE can look into a mip change.

```

### Commercial
1 change: 1 addition & 0 deletions inst/compareScenarios/preprocessing.R
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ heating <- c(
"Liquids heater",
"Coal heater"
)
heating0 <- c(heating, "No change")
carrier <- c(
"Biomass",
"Heat",
Expand Down