Skip to content

Commit

Permalink
Merge pull request #451 from katarkow/EW_costs
Browse files Browse the repository at this point in the history
Migrate enhanced weathering costs from REMIND
  • Loading branch information
katarkow authored Dec 1, 2023
2 parents 6e59361 + 133dbfc commit b5760cc
Show file tree
Hide file tree
Showing 12 changed files with 154 additions and 22 deletions.
2 changes: 1 addition & 1 deletion .buildlibrary
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
ValidationKey: '33856480'
ValidationKey: '34065430'
AcceptedWarnings:
- 'Warning: package ''.*'' was built under R version'
- 'Warning: namespace ''.*'' is not available and has been replaced'
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: 'mrremind: MadRat REMIND Input Data Package'
version: 0.172.0
date-released: '2023-11-23'
version: 0.173.0
date-released: '2023-11-30'
abstract: The mrremind packages contains data preprocessing for the REMIND model.
authors:
- family-names: Baumstark
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: mrremind
Title: MadRat REMIND Input Data Package
Version: 0.172.0
Date: 2023-11-23
Version: 0.173.0
Date: 2023-11-30
Authors@R: c(
person("Lavinia", "Baumstark", , "lavinia@pik-potsdam.de", role = c("aut", "cre")),
person("Renato", "Rodrigues", role = "aut"),
Expand Down
23 changes: 23 additions & 0 deletions R/calcCostsWeathering.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#' Calculate costs of transport of enahnced weathering
#'
#' @return transport costs of spreading rock on the fields
#' @seealso \code{\link{calcOutput}}
#' @examples
#'
#' \dontrun{
#' calcOutput("CostsWeathering")
#' }
#'

calcCostsWeathering <- function() {

costs <- readSource("Strefler", subtype = "weathering_costs")
weight <- costs # get the same dimensions of the data
weight[, , ] <- 1 # this will take the average of the countries to get the regional resolution

return(list(x = costs,
weight = weight,
unit = "T$/Gt stone",
description = "Transport costs for spreading rocks on the fields. The first rlf corresponds to climate regions (1 - warm, 2 - temperate). The second rlf are the distances of fields from the sources of the material."
))
}
2 changes: 1 addition & 1 deletion R/calcPotentialWeathering.R
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
calcPotentialWeathering <- function() {

# read weathering data
pot <- readSource("Strefler")
pot <- readSource("Strefler", subtype = "weathering_graderegi")

# change the unit: 10^6 km^2 -> kg/m^2 = Gt / 10^6 km^2
pot <- pot * 15
Expand Down
28 changes: 23 additions & 5 deletions R/convertStrefler.R
Original file line number Diff line number Diff line change
@@ -1,7 +1,25 @@
convertStrefler <- function(x) {

w <- calcOutput("FAOLand",aggregate=FALSE)[,,"6620",pmatch = TRUE][,2005,]
y <- toolAggregate(x, "regionmappingGEC.csv", weight=w)

#' @title convertStrefler
#' @description Converts data on enhanced weathering
#' @param x unconverted magpie object from read-script
#'
#' @return magpie object with a completed dataset
#'

convertStrefler <- function(x, subtype) {

if (subtype == "weathering_graderegi") {
w <- calcOutput("FAOLand", aggregate = FALSE)[, , "6620", pmatch = TRUE][, 2005, ]
y <- toolAggregate(x, "regionmappingGEC.csv", weight = w)
return(y)
}

if (subtype == "weathering_costs") {
reg_rel <- toolGetMapping("regionmappingH12.csv", type = "regional",
where = "mappingfolder") # get H12 regionmapping
# assign the same cost for each country in a given region
y <- toolAggregate(x, reg_rel)
return(y)
}

stop("Not a valid subtype in convertStrefler")
}
2 changes: 1 addition & 1 deletion R/fullREMIND.R
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ fullREMIND <- function(rev = 0) {
calcOutput("PotentialWindOff", round = 3, file = "f_maxProdGradeRegiWindOff.cs3r")
calcOutput("PotentialGeothermal", round = 3, file = "f_maxProdGeothermal.cs3r")
calcOutput("PotentialWeathering", round = 3, file = "f33_maxProdGradeRegiWeathering.cs3r")
calcOutput("PotentialWeathering", round = 3, file = "f33_maxProdGradeRegiWeathering.cs3r")
calcOutput("CostsWeathering", round = 8, file = "p33_transportCostsWeathering.cs4r")
calcOutput("CostsTrade", round = 5, file = "pm_costsPEtradeMp.cs4r")
calcOutput("CostsTradePeFinancial", round = 5, file = "pm_costsTradePeFinancial.cs3r")
calcOutput("ShareCHP", round = 3, file = "f32_shCHP.cs4r")
Expand Down
38 changes: 31 additions & 7 deletions R/readStrefler.R
Original file line number Diff line number Diff line change
@@ -1,8 +1,32 @@
readStrefler <- function(){
x <- read.csv("f33_data_weathering_graderegi.csv", sep=";", header=TRUE, row.names = 1)
x <- as.magpie(x,spatial=1)
getSets(x)[1] <- "region"
getSets(x)[2] <- "year"
getSets(x)[3] <- "data1"
return(x)
#' Get data on enhanced weathering
#'
#' @param subtype type of data, one of "weathering_graderegi", "weathering_costs"
#' @return magpie object of region dependent data
#' @seealso \code{\link{readSource}}
#' @examples
#'
#' \dontrun{
#' a <- readSource(type="Strefler", subtype="weathering_graderegi")
#' }

readStrefler <- function(subtype) {

# weathering potential
if (subtype == "weathering_graderegi") {
x <- read.csv("f33_data_weathering_graderegi.csv", sep = ";", header = TRUE, row.names = 1)
x <- as.magpie(x, spatial = 1)
getSets(x)[1] <- "region"
getSets(x)[2] <- "year"
getSets(x)[3] <- "data1"
return(x)
}

# transport costs of spreading rock for weathering on the fields
if (subtype == "weathering_costs") {
x <- read.csv("p33_weathering_transport_costs.csv", sep = ";", header = TRUE)
x <- as.magpie(x, tidy = "true")
return(x)
}

stop("Not a valid subtype provided to readStrefler")
}
6 changes: 3 additions & 3 deletions 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.172.0**
R package **mrremind**, version **0.173.0**

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

Expand Down Expand Up @@ -39,7 +39,7 @@ In case of questions / problems please contact Lavinia Baumstark <lavinia@pik-po

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

Baumstark L, Rodrigues R, Levesque A, Oeser J, Bertram C, Mouratiadou I, Malik A, Schreyer F, Soergel B, Rottoli M, Mishra A, Dirnaichner A, Pehl M, Giannousakis A, Klein D, Strefler J, Feldhaus L, Brecha R, Rauner S, Dietrich J, Bi S, Benke F, Weigmann P, Richters O, Hasse R, Fuchs S, Mandaroux R (2023). _mrremind: MadRat REMIND Input Data Package_. R package version 0.172.0, <URL: https://github.com/pik-piam/mrremind>.
Baumstark L, Rodrigues R, Levesque A, Oeser J, Bertram C, Mouratiadou I, Malik A, Schreyer F, Soergel B, Rottoli M, Mishra A, Dirnaichner A, Pehl M, Giannousakis A, Klein D, Strefler J, Feldhaus L, Brecha R, Rauner S, Dietrich J, Bi S, Benke F, Weigmann P, Richters O, Hasse R, Fuchs S, Mandaroux R (2023). _mrremind: MadRat REMIND Input Data Package_. R package version 0.173.0, <URL: https://github.com/pik-piam/mrremind>.

A BibTeX entry for LaTeX users is

Expand All @@ -48,7 +48,7 @@ A BibTeX entry for LaTeX users is
title = {mrremind: MadRat REMIND Input Data Package},
author = {Lavinia Baumstark and Renato Rodrigues and Antoine Levesque and Julian Oeser and Christoph Bertram and Ioanna Mouratiadou and Aman Malik and Felix Schreyer and Bjoern Soergel and Marianna Rottoli and Abhijeet Mishra and Alois Dirnaichner and Michaja Pehl and Anastasis Giannousakis and David Klein and Jessica Strefler and Lukas Feldhaus and Regina Brecha and Sebastian Rauner and Jan Philipp Dietrich and Stephen Bi and Falk Benke and Pascal Weigmann and Oliver Richters and Robin Hasse and Sophie Fuchs and Rahel Mandaroux},
year = {2023},
note = {R package version 0.172.0},
note = {R package version 0.173.0},
url = {https://github.com/pik-piam/mrremind},
}
```
24 changes: 24 additions & 0 deletions man/calcCostsWeathering.Rd

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

17 changes: 17 additions & 0 deletions man/convertStrefler.Rd

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

26 changes: 26 additions & 0 deletions man/readStrefler.Rd

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

0 comments on commit b5760cc

Please sign in to comment.