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

Handle missing periods from report functions #13

Merged
merged 1 commit into from
Oct 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .buildlibrary
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
ValidationKey: '1400280'
ValidationKey: '1420426'
AutocreateReadme: yes
AcceptedWarnings:
- 'Warning: package ''.*'' was built under R version'
Expand Down
4 changes: 2 additions & 2 deletions CITATION.cff
Original file line number Diff line number Diff line change
Expand Up @@ -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: 'reportbrick: Reporting package for BRICK'
version: 0.7.0
date-released: '2024-10-08'
version: 0.7.1
date-released: '2024-10-10'
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.
authors:
Expand Down
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
Type: Package
Package: reportbrick
Title: Reporting package for BRICK
Version: 0.7.0
Date: 2024-10-08
Version: 0.7.1
Date: 2024-10-10
Authors@R: c(
person("Robin", "Hasse", , "robin.hasse@pik-potsdam.de",
role = c("aut", "cre"),
Expand Down
2 changes: 2 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,11 @@ importFrom(magclass,dimSums)
importFrom(magclass,getItems)
importFrom(magclass,getNames)
importFrom(magclass,getSets)
importFrom(magclass,getYears)
importFrom(magclass,mbind)
importFrom(magclass,mselect)
importFrom(magclass,ndim)
importFrom(magclass,new.magpie)
importFrom(magclass,setNames)
importFrom(magclass,write.report)
importFrom(piamutils,getSystemFile)
Expand Down
10 changes: 5 additions & 5 deletions R/convGDX2MIF.R
Original file line number Diff line number Diff line change
Expand Up @@ -50,23 +50,23 @@ convGDX2MIF <- function(gdx,

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

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

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

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

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


# FINISH ---------------------------------------------------------------------
Expand Down
19 changes: 19 additions & 0 deletions R/extendPeriods.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#' Crop MagPIE object to given periods and fill missing periods
#'
#' @param x MagPIE object
#' @param periods numeric vector with target periods
#' @param fill value to fill missing period values
#' @returns MagPIE object with given periods in temporal dimension
#'
#' @author Robin Hasse
#'
#' @importFrom magclass getYears new.magpie getItems getNames

extendPeriods <- function(x, periods, fill = NA) {
r <- getItems(x, dim = 1)
n <- getNames(x)
t <- intersect(getYears(x, as.integer = TRUE), periods)
out <- new.magpie(cells_and_regions = r, years = periods, names = n, fill = fill)
out[r, t, ] <- x[r, t, ]
return(out)
}
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Reporting package for BRICK

R package **reportbrick**, version **0.7.0**
R package **reportbrick**, version **0.7.1**

[![CRAN status](https://www.r-pkg.org/badges/version/reportbrick)](https://cran.r-project.org/package=reportbrick) [![R build status](https://github.com/pik-piam/reportbrick/workflows/check/badge.svg)](https://github.com/pik-piam/reportbrick/actions) [![codecov](https://codecov.io/gh/pik-piam/reportbrick/branch/master/graph/badge.svg)](https://app.codecov.io/gh/pik-piam/reportbrick) [![r-universe](https://pik-piam.r-universe.dev/badges/reportbrick)](https://pik-piam.r-universe.dev/builds)

Expand Down Expand Up @@ -38,7 +38,7 @@ In case of questions / problems please contact Robin Hasse <robin.hasse@pik-pots

To cite package **reportbrick** in publications use:

Hasse R, Rosemann R (2024). _reportbrick: Reporting package for BRICK_. R package version 0.7.0, <https://github.com/pik-piam/reportbrick>.
Hasse R, Rosemann R (2024). _reportbrick: Reporting package for BRICK_. R package version 0.7.1, <https://github.com/pik-piam/reportbrick>.

A BibTeX entry for LaTeX users is

Expand All @@ -47,7 +47,7 @@ A BibTeX entry for LaTeX users is
title = {reportbrick: Reporting package for BRICK},
author = {Robin Hasse and Ricarda Rosemann},
year = {2024},
note = {R package version 0.7.0},
note = {R package version 0.7.1},
url = {https://github.com/pik-piam/reportbrick},
}
```
24 changes: 24 additions & 0 deletions man/extendPeriods.Rd

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

Loading