Skip to content

Commit

Permalink
Enhance non-silent mode of mif reporting.
Browse files Browse the repository at this point in the history
  • Loading branch information
robinhasse committed May 28, 2024
1 parent c1caad1 commit 99e1214
Show file tree
Hide file tree
Showing 17 changed files with 137 additions and 54 deletions.
2 changes: 1 addition & 1 deletion .buildlibrary
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
ValidationKey: '794840'
ValidationKey: '814711'
AutocreateReadme: yes
AcceptedWarnings:
- 'Warning: package ''.*'' was built under R version'
Expand Down
2 changes: 1 addition & 1 deletion CITATION.cff
Original file line number Diff line number Diff line change
Expand Up @@ -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: 'reportbrick: Reporting package for BRICK'
version: 0.4.0
version: 0.4.1
date-released: '2024-05-28'
abstract: This package contains BRICK-specific routines to report model results. The
main functionality is to generate a mif-file from a given BRICK model run folder.
Expand Down
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Type: Package
Package: reportbrick
Title: Reporting package for BRICK
Version: 0.4.0
Version: 0.4.1
Date: 2024-05-28
Authors@R: c(
person("Robin", "Hasse", , "[email protected]",
Expand Down
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ importFrom(piamutils,getSystemFile)
importFrom(rmarkdown,render)
importFrom(tidyr,crossing)
importFrom(tidyr,replace_na)
importFrom(utils,capture.output)
importFrom(utils,tail)
importFrom(utils,write.csv)
importFrom(yaml,read_yaml)
12 changes: 7 additions & 5 deletions R/convGDX2MIF.R
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#' returned
#' @param scenario scenario name that is used in the *.mif reporting
#' @param t numeric vector of reporting periods (years)
#' @param silent boolean, suppress warnings and printing of dimension mapping
#'
#' @author Robin Hasse
#'
Expand All @@ -22,7 +23,8 @@ convGDX2MIF <- function(gdx,
tmpl = NULL,
file = NULL,
scenario = "default",
t = NULL) {
t = NULL,
silent = TRUE) {

# PREPARE --------------------------------------------------------------------

Expand Down Expand Up @@ -53,19 +55,19 @@ convGDX2MIF <- function(gdx,

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

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

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

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


# FINISH ---------------------------------------------------------------------
Expand Down
18 changes: 14 additions & 4 deletions R/reportAgg.R
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
#' @author Robin Hasse
#'
#' @importFrom magclass getSets
#' @importFrom utils tail
#' @importFrom utils tail capture.output

reportAgg <- function(x,
name,
Expand Down Expand Up @@ -63,8 +63,18 @@ reportAgg <- function(x,
# list with dimension elements to consider for aggregation and reporting
map <- .constructDimMapping(agg, rprt, brickSets, silent)

nullInMap <- unlist(lapply(map, function(x) unlist(lapply(x, is.null))))
if (any(nullInMap)) {
if (isFALSE(silent)) {
message("Can't report '", name, "' as mapping can't be constructed for ",
paste(names(nullInMap)[nullInMap], collapse = ", "), ".")
}
return(NULL)
}

if (isFALSE(silent)) {
message(map)
message("For the variable '", name, "' using this map:\n ",
paste(capture.output(map), collapse = "\n "))
}


Expand Down Expand Up @@ -141,8 +151,8 @@ reportAgg <- function(x,
return(brickSets[[d]][["subsets"]][[val]])
} else {
if (isFALSE(silent)) {
warning("No correspondant for '", val, "' as an element of'"
, d, " in brick sets file: ", attr(brickSets, "file"))
message("No correspondant for '", val, "' as an element of '", d,
"' in brick sets file: ", attr(brickSets, "file"))
}
return(list(NULL))
}
Expand Down
27 changes: 18 additions & 9 deletions R/reportBuildingStock.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@
#'
#' @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 Robin Hasse
#'
#' @importFrom magclass mbind setNames dimSums mselect collapseDim

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

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

Expand All @@ -31,48 +32,56 @@ reportBuildingStock <- function(gdx, brickSets = NULL) {
## Total ====
reportAgg(v_stock,
"Stock|Buildings (bn m2)", brickSets,
agg = c(bs = "all", hs = "all", vin = "all", loc = "all", typ = "resCom", inc = "all")),
agg = c(bs = "all", hs = "all", vin = "all", loc = "all", typ = "resCom", inc = "all"),
silent = silent),
reportAgg(v_stock,
"Stock|Residential (bn m2)", brickSets,
agg = c(bs = "all", hs = "all", vin = "all", loc = "all", typ = "res", inc = "all")),
agg = c(bs = "all", hs = "all", vin = "all", loc = "all", typ = "res", inc = "all"),
silent = silent),
reportAgg(v_stock,
"Stock|Commercial (bn m2)", brickSets,
agg = c(bs = "all", hs = "all", vin = "all", loc = "all", typ = "com", inc = "all")),
agg = c(bs = "all", hs = "all", vin = "all", loc = "all", typ = "com", inc = "all"),
silent = silent),


## by building type ====
reportAgg(v_stock,
"Stock|Residential|{typ} (bn m2)", brickSets,
agg = c(bs = "all", hs = "all", vin = "all", loc = "all", inc = "all"),
rprt = c(typ = "res")),
rprt = c(typ = "res"),
silent = silent),


## by location ====
reportAgg(v_stock,
"Stock|Residential|{loc} (bn m2)", brickSets,
agg = c(bs = "all", hs = "all", vin = "all", typ = "res", inc = "all"),
rprt = c(loc = "all")),
rprt = c(loc = "all"),
silent = silent),


## by vintage ====
reportAgg(v_stock,
"Stock|Residential|{vin} (bn m2)", brickSets,
agg = c(bs = "all", hs = "all", loc = "all", typ = "res", inc = "all"),
rprt = c(vin = "all")),
rprt = c(vin = "all"),
silent = silent),


## by heating system ====
reportAgg(v_stock,
"Stock|Residential|{hs} (bn m2)", brickSets,
agg = c(bs = "all", vin = "all", loc = "all", typ = "res", inc = "all"),
rprt = c(hs = "all")),
rprt = c(hs = "all"),
silent = silent),


## by building type + heating system ====
reportAgg(v_stock,
"Stock|Residential|{typ}|{hs} (bn m2)", brickSets,
agg = c(bs = "all", vin = "all", loc = "all", inc = "all"),
rprt = c(hs = "all", typ = "res"))
rprt = c(hs = "all", typ = "res"),
silent = silent)

)

Expand Down
24 changes: 16 additions & 8 deletions R/reportConstruction.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@
#'
#' @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 Robin Hasse
#'
#' @importFrom magclass mbind setNames dimSums mselect collapseDim

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

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

Expand All @@ -31,41 +32,48 @@ reportConstruction <- function(gdx, brickSets = NULL) {
## Total ====
reportAgg(v_construction,
"Construction|Buildings (bn m2/yr)", brickSets,
agg = c(bs = "all", hs = "all", loc = "all", typ = "resCom", inc = "all")),
agg = c(bs = "all", hs = "all", loc = "all", typ = "resCom", inc = "all"),
silent = silent),
reportAgg(v_construction,
"Construction|Residential (bn m2/yr)", brickSets,
agg = c(bs = "all", hs = "all", loc = "all", typ = "res", inc = "all")),
agg = c(bs = "all", hs = "all", loc = "all", typ = "res", inc = "all"),
silent = silent),
reportAgg(v_construction,
"Construction|Commercial (bn m2/yr)", brickSets,
agg = c(bs = "all", hs = "all", loc = "all", typ = "com", inc = "all")),
agg = c(bs = "all", hs = "all", loc = "all", typ = "com", inc = "all"),
silent = silent),


## by building type ====
reportAgg(v_construction,
"Construction|Residential|{typ} (bn m2/yr)", brickSets,
agg = c(bs = "all", hs = "all", loc = "all", inc = "all"),
rprt = c(typ = "res")),
rprt = c(typ = "res"),
silent = silent),


## by location ====
reportAgg(v_construction,
"Construction|Residential|{loc} (bn m2/yr)", brickSets,
agg = c(bs = "all", hs = "all", typ = "res", inc = "all"),
rprt = c(loc = "all")),
rprt = c(loc = "all"),
silent = silent),


## by heating system ====
reportAgg(v_construction,
"Construction|Residential|{hs} (bn m2/yr)", brickSets,
agg = c(bs = "all", loc = "all", typ = "res", inc = "all"),
rprt = c(hs = "all")),
rprt = c(hs = "all"),
silent = silent),


## by building type + heating system ====
reportAgg(v_construction,
"Construction|Residential|{typ}|{hs} (bn m2/yr)", brickSets,
agg = c(bs = "all", loc = "all", inc = "all"),
rprt = c(hs = "all", typ = "res"))
rprt = c(hs = "all", typ = "res"),
silent = silent)

)

Expand Down
27 changes: 18 additions & 9 deletions R/reportDemolition.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@
#'
#' @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 Robin Hasse
#'
#' @importFrom magclass mbind setNames dimSums mselect collapseDim

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

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

Expand All @@ -31,48 +32,56 @@ reportDemolition <- function(gdx, brickSets = NULL) {
## Total ====
reportAgg(v_demolition,
"Demolition|Buildings (bn m2/yr)", brickSets,
agg = c(bs = "all", hs = "all", vin = "all", loc = "all", typ = "resCom", inc = "all")),
agg = c(bs = "all", hs = "all", vin = "all", loc = "all", typ = "resCom", inc = "all"),
silent = silent),
reportAgg(v_demolition,
"Demolition|Residential (bn m2/yr)", brickSets,
agg = c(bs = "all", hs = "all", vin = "all", loc = "all", typ = "res", inc = "all")),
agg = c(bs = "all", hs = "all", vin = "all", loc = "all", typ = "res", inc = "all"),
silent = silent),
reportAgg(v_demolition,
"Demolition|Commercial (bn m2/yr)", brickSets,
agg = c(bs = "all", hs = "all", vin = "all", loc = "all", typ = "com", inc = "all")),
agg = c(bs = "all", hs = "all", vin = "all", loc = "all", typ = "com", inc = "all"),
silent = silent),


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


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


## by vintage ====
reportAgg(v_demolition,
"Demolition|Residential|{vin} (bn m2/yr)", brickSets,
agg = c(bs = "all", hs = "all", loc = "all", typ = "res", inc = "all"),
rprt = c(vin = "all")),
rprt = c(vin = "all"),
silent = silent),


## by heating system ====
reportAgg(v_demolition,
"Demolition|Residential|{hs} (bn m2/yr)", brickSets,
agg = c(bs = "all", vin = "all", loc = "all", typ = "res", inc = "all"),
rprt = c(hs = "all")),
rprt = c(hs = "all"),
silent = silent),


## by building type + heating system ====
reportAgg(v_demolition,
"Demolition|Residential|{typ}|{hs} (bn m2/yr)", brickSets,
agg = c(bs = "all", vin = "all", loc = "all", inc = "all"),
rprt = c(hs = "all", typ = "res"))
rprt = c(hs = "all", typ = "res"),
silent = silent)

)

Expand Down
Loading

0 comments on commit 99e1214

Please sign in to comment.