Skip to content

Commit

Permalink
Read district heating prices
Browse files Browse the repository at this point in the history
  • Loading branch information
robinhasse committed Jun 29, 2023
1 parent 348472b commit 4da9a32
Show file tree
Hide file tree
Showing 11 changed files with 87 additions and 24 deletions.
2 changes: 1 addition & 1 deletion .buildlibrary
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
ValidationKey: '585930'
ValidationKey: '586110'
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 @@ -3,7 +3,7 @@ message: If you use this software, please cite it using the metadata from this f
type: software
title: 'mredgebuildings: Prepare data to be used by the EDGE-Buildings model'
version: 0.3.0
date-released: '2023-06-23'
date-released: '2023-06-29'
abstract: Prepare data to be used by the EDGE-Buildings model.
authors:
- family-names: Hasse
Expand Down
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ Type: Package
Package: mredgebuildings
Title: Prepare data to be used by the EDGE-Buildings model
Version: 0.3.0
Date: 2023-06-23
Date: 2023-06-29
Authors@R: c(
person("Robin", "Hasse", , "[email protected]", role = c("aut", "cre"),
comment = c(ORCID = "0000-0003-1818-3186")),
Expand Down
3 changes: 3 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export(convertCensusHub)
export(convertDaioglou)
export(convertEEAfloorspace)
export(convertEUBuildingsDB)
export(convertEnergiforsk2016)
export(convertEurObservER)
export(convertEuropeanCommissionRenovation)
export(convertEurostatBuildings)
Expand All @@ -29,6 +30,7 @@ export(readDaioglou)
export(readEEAfloorspace)
export(readEHI)
export(readEUBuildingsDB)
export(readEnergiforsk2016)
export(readEurObservER)
export(readEuropeanCommissionRenovation)
export(readEurostatBuildings)
Expand Down Expand Up @@ -113,6 +115,7 @@ importFrom(stats,predict)
importFrom(stats,pweibull)
importFrom(tidyr,complete)
importFrom(tidyr,gather)
importFrom(tidyr,pivot_longer)
importFrom(tidyr,replace_na)
importFrom(tidyr,separate)
importFrom(tidyr,spread)
Expand Down
3 changes: 2 additions & 1 deletion R/calcBuildingStock.R
Original file line number Diff line number Diff line change
Expand Up @@ -726,7 +726,8 @@ calcBuildingStock <- function(subtype = c("residential", "commercial")) {
group_by(across(all_of(c("region", "period")))) %>%
mutate(value = proportions(.data[["value"]]))
stock <- stock %>%
left_join(heatingShares, by = c("region", "period")) %>%
left_join(heatingShares, by = c("region", "period"),
relationship = "many-to-many") %>%
mutate(value = .data[["value.x"]] * .data[["value.y"]]) %>%
select(-"value.x", -"value.y") %>%
rename(heating = "carrier")
Expand Down
26 changes: 26 additions & 0 deletions R/convertEnergiforsk2016.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#' Convert European district heating prices
#'
#' We should consider prper extrapolation
#'
#' @author Robin Hasse
#'
#'@param x MAgPIE object with original district heating prices
#'
#' @importFrom madrat toolCountry2isocode toolCountryFill
#' @importFrom magclass getItems<- getItems collapseDim
#' @export

convertEnergiforsk2016 <- function(x) {

data <- x

# rename regions: ISO2 -> ISO3
getItems(data, 1) <- toolCountry2isocode(getItems(data, 1))

# fill missing countries with NA
data <- data %>%
collapseDim() %>%
toolCountryFill(verbosity = 2)

return(data)
}
9 changes: 0 additions & 9 deletions R/readEHI.R
Original file line number Diff line number Diff line change
@@ -1,14 +1,5 @@
#' Read EHI Heating Market Report
#'
#' PDF market reports on Renewables in Europe
#'
#' @source https://www.eurobserv-er.org/
#' @note I download the report and snip a png of the table. Then I extract the
#' data with [this online tool](https://extracttable.com/) and save it as a
#' tabular csv in the source folder. The Tool is not fully reliable. This
#' function throws an error if values don't sum up. You then have to correct the
#' csv file manually.
#'
#' @param subtype <report series>.<variable>
#' @returns magpie object
#'
Expand Down
21 changes: 21 additions & 0 deletions R/readEnergiforsk2016.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#' Read European district heating prices
#'
#' @author Robin Hasse
#'
#' @importFrom utils read.csv
#' @importFrom tidyr pivot_longer
#' @importFrom dplyr select matches mutate rename
#' @importFrom quitte as.quitte
#' @importFrom magclass as.magpie
#' @export

readEnergiforsk2016 <- function() {
file <- "european-district-heating-price-series-energiforskrapport-2016-316.csv"
read.csv(file, skip = 1) %>%
select(-matches("All\\.countries")) %>%
pivot_longer(-"Year", names_to = "region", values_to = "value") %>%
mutate(region = gsub("\\.", " ", .data[["region"]])) %>%
rename(period = "Year") %>%
as.quitte() %>%
as.magpie()
}
17 changes: 17 additions & 0 deletions man/convertEnergiforsk2016.Rd

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

12 changes: 1 addition & 11 deletions man/readEHI.Rd

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

14 changes: 14 additions & 0 deletions man/readEnergiforsk2016.Rd

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

0 comments on commit 4da9a32

Please sign in to comment.