Skip to content

Commit

Permalink
Merge pull request #535 from fbenke-pik/cleanup
Browse files Browse the repository at this point in the history
remove ppc and pco from inputdata generation
  • Loading branch information
fbenke-pik authored Sep 3, 2024
2 parents f4893c2 + 19e3a01 commit 5cf8202
Show file tree
Hide file tree
Showing 24 changed files with 1,070 additions and 472 deletions.
2 changes: 1 addition & 1 deletion .buildlibrary
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
ValidationKey: '37340160'
ValidationKey: '37361999'
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.187.0
date-released: '2024-09-02'
version: 0.187.1
date-released: '2024-09-03'
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.187.0
Date: 2024-09-02
Version: 0.187.1
Date: 2024-09-03
Authors@R: c(
person("Lavinia", "Baumstark", , "lavinia@pik-potsdam.de", role = c("aut", "cre")),
person("Renato", "Rodrigues", role = "aut"),
Expand Down
3 changes: 2 additions & 1 deletion R/calcCapacityFactor.R
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ calcCapacityFactor <- function() {
global <- readSource("REMIND_11Regi", subtype = "capacityFactorGlobal", convert = FALSE)

# remove no longer used items
notUsed <- c("apcarelt", "aptrnelt", "apcarh2t", "apcarpet", "apcardit", "apcardiefft", "apcardieffH2t")
notUsed <- c("apcarelt", "aptrnelt", "apcarh2t", "apcarpet", "apcardit",
"apcardiefft", "apcardieffH2t", "pcc", "pco")
global <- global[, , notUsed, invert = TRUE]

# Set coal plant capacity factor long-term assumption to 50% (down from 60%)
Expand Down
67 changes: 35 additions & 32 deletions R/calcCoolingSharesAll.R
Original file line number Diff line number Diff line change
@@ -1,55 +1,58 @@
#' Calculate Cooling Type Shares
#'
#'
#' This function merges the output of two other functions that calculate REMIND
#' input data for the shares of cooling types per electricity technology and
#' REMIND region, using as initial information the Davies (2013) data per
#' electricity technology and GCAM region. The two other functions separately
#' calculate data for the base year and for future time steps. The source data
#' provide most required information but some assumptions on missing data are
#' also made.
#'
#'
#'
#'
#' @return MAgPIE object on cooling type shares per elecricity technology and
#' REMIND region
#' @author Ioanna Mouratiadou
#' @seealso \code{\link{calcOutput}}, \code{\link{readDaviesCooling}},
#' \code{\link{convertDaviesCooling}},
#' \code{\link{calcCoolingSharesBase}},\code{\link{calcCoolingSharesFuture}}
#' @examples
#'
#' \dontrun{
#'
#' \dontrun{
#'
#' a <- calcOutput("CoolingSharesAll")
#'
#' }
#'
#'
calcCoolingSharesAll <- function() {
cooloutputBase <- calcOutput("CoolingSharesBase", aggregate = FALSE)
cooloutputFuture <- calcOutput("CoolingSharesFuture", aggregate = FALSE)

cooloutputBase <- calcOutput("CoolingSharesBase", aggregate=FALSE)
cooloutputFuture <- calcOutput("CoolingSharesFuture",aggregate=FALSE)

# merge two datasets
outputAll <- mbind(cooloutputBase,cooloutputFuture)

#assign aggregation weight
weight <- dimSums(calcOutput("IO",subtype="output",aggregate=FALSE)[,2010,c("feelb","feeli")],dim=3)

#set weights to zero for countries that were not contained in the GCAM2ISO mapping
weight["ALA",,] <- 0
weight["ATA",,] <- 0
weight["BES",,] <- 0
weight["BLM",,] <- 0
weight["CUW",,] <- 0
weight["GGY",,] <- 0
weight["IMN",,] <- 0
weight["JEY",,] <- 0
weight["MAF",,] <- 0
weight["PSE",,] <- 0
weight["SSD",,] <- 0
weight["SXM",,] <- 0
outputAll <- mbind(cooloutputBase, cooloutputFuture)

return(list(x=outputAll, weight=weight,
unit="% of cooling type technologies",
description="Cooling shares for different cooling technologies based on Davies et al. (2013) publication and using electricity use weights (aggregated based on IEA World Energy Balances, 2014) for regional mapping"
# assign aggregation weight
weight <- dimSums(calcOutput("IO", subtype = "output", aggregate = FALSE)[, 2010, c("feelb", "feeli")], dim = 3)

# set weights to zero for countries that were not contained in the GCAM2ISO mapping
weight["ALA", , ] <- 0
weight["ATA", , ] <- 0
weight["BES", , ] <- 0
weight["BLM", , ] <- 0
weight["CUW", , ] <- 0
weight["GGY", , ] <- 0
weight["IMN", , ] <- 0
weight["JEY", , ] <- 0
weight["MAF", , ] <- 0
weight["PSE", , ] <- 0
weight["SSD", , ] <- 0
weight["SXM", , ] <- 0

return(list(
x = outputAll,
weight = weight,
unit = "% of cooling type technologies",
description = c(
"Cooling shares for different cooling technologies based on ",
"Davies et al. (2013) publication and using electricity use weights (aggregated ",
"based on IEA World Energy Balances, 2014) for regional mapping"
)
))
}
166 changes: 86 additions & 80 deletions R/calcCoolingSharesBase.R
Original file line number Diff line number Diff line change
@@ -1,118 +1,124 @@
#' Calculate Cooling Type Shares for the Base Year
#'
#'
#' This function calculates REMIND input data for the shares of cooling types
#' per electricity technology and REMIND region in 2005, using as initial
#' information the Davies (2013) data per electricity technology and GCAM
#' region. The source data provide most required information but some
#' assumptions on missing data are also made.
#'
#'
#'
#'
#' @return MAgPIE object on cooling type shares per elecricity technology and
#' REMIND region
#' @author Lavinia Baumstark, Ioanna Mouratiadou
#' @seealso \code{\link{calcOutput}}, \code{\link{readDaviesCooling}},
#' \code{\link{convertDaviesCooling}},
#' \code{\link{calcCoolingSharesAll}},\code{\link{calcCoolingSharesFuture}}
#' @examples
#'
#' \dontrun{
#' \dontrun{
#' a <- calcOutput("CoolingSharesBase")
#' }
#' @importFrom readxl read_excel



calcCoolingSharesBase <- function() {

# read in data
data <- readSource("DaviesCooling", subtype="dataBase")
getNames(data)[grepl("^Sea",getNames(data))] <- "Sea.NA"
data <- readSource("DaviesCooling", subtype = "dataBase")
getNames(data)[grepl("^Sea", getNames(data))] <- "Sea.NA"

# seperate data for Sea water
Sea <- data[,,"Sea"]
data <- data[,,-which(getNames(data)=="Sea.NA")]
id <- getNames(data,dim=1)
Sea <- data[, , "Sea"]
data <- data[, , -which(getNames(data) == "Sea.NA")]

id <- getNames(data, dim = 1)

# calculate pond
pond <- new.magpie(getRegions(data),getYears(data),id)
pond <- new.magpie(getRegions(data), getYears(data), id)
for (i in id) {
pond[,,i] <- 100 - dimSums(data[,,i],dim=3.2)
pond[, , i] <- 100 - dimSums(data[, , i], dim = 3.2)
}
getNames(pond) <- paste(getNames(pond),"Pond",sep=".")
getNames(pond) <- paste(getNames(pond), "Pond", sep = ".")

# add pond to data
data <- mbind(data,pond)
data <- mbind(data, pond)

# calculate sea water
sea_new <- new.magpie(getRegions(data),getYears(data),id)
sea_new <- new.magpie(getRegions(data), getYears(data), id)
for (i in id) {
sea_new[,,i] <- data[,,paste(i,"1-thru",sep=".")] * Sea/100
sea_new[, , i] <- data[, , paste(i, "1-thru", sep = ".")] * Sea / 100
}
getNames(sea_new) <- paste(getNames(sea_new),"Sea",sep=".")
getNames(sea_new) <- paste(getNames(sea_new), "Sea", sep = ".")

# correct 1-thru-data
data[,,"1-thru"] <- data[,,"1-thru"] * (1 - Sea/100)
data[, , "1-thru"] <- data[, , "1-thru"] * (1 - Sea / 100)
# add sea data to data
data <- mbind(data,sea_new)
data <- mbind(data, sea_new)

# check if all categories sum up to 100%
check <- new.magpie(getRegions(data),getYears(data),id)
check <- new.magpie(getRegions(data), getYears(data), id)
for (i in id) {
check[,,i] <- dimSums(data[,,i],dim=3.2)
check[, , i] <- dimSums(data[, , i], dim = 3.2)
}
if(!all(check==100)) { stop("sum of categorie XXX is not 100%")}

if (!all(check == 100)) {
stop("sum of categorie XXX is not 100%")
}

# read in mapping to REMIND technologies
map_table <- read_excel(toolGetMapping(type = "sectoral",
name = "TechnologyMappingDavies2REMIND.xlsx",
returnPathOnly = TRUE, where = "mappingfolder"))
map_table <- toolGetMapping(
type = "sectoral",
name = "techmappingDaviesToREMIND.csv",
where = "mrremind"
)
map <- list()
map$davies <- paste(map_table$'Davies Source/Technology',map_table$'Davies Cooling',sep=".")
map$remind <- paste(map_table$'REMIND Technology',map_table$'REMIND Cooling',sep=".")
map$davies <- paste(map_table$Davies.Source.Technology, map_table$Davies.Cooling, sep = ".")
map$remind <- paste(map_table$REMIND.Technology, map_table$REMIND.Cooling, sep = ".")

# calculate REMIND input in REMIND categories
output <- new.magpie(getRegions(data),getYears(data),map$remind)
output[,,] <- 0
for(d in 1:length(map$davies)){
if( !map$davies[d] == "-.-"){
output[,,map$remind[d]] <- data[,,map$davies[d]]
output <- new.magpie(getRegions(data), getYears(data), map$remind)
output[, , ] <- 0
for (d in 1:length(map$davies)) {
if (!map$davies[d] == "-.-") {
output[, , map$remind[d]] <- data[, , map$davies[d]]
}
}


# remove no longer used technologies pcc and pco
output <- output[, , c("pcc", "pco"), invert = TRUE]

# add assumed data
output[,,"geohdr.tower"] <- 70
output[,,"geohdr.dry"] <- 20
output[,,"geohdr.hybrid"] <- 10
output[,,"hydro.default"] <- 100
output[,,"wind.default"] <- 100
output[,,"spv.default"] <- 100
output[,,"csp.tower"] <- 70
output[,,"csp.dry"] <- 20
output[,,"csp.hybrid"] <- 10

outputBase <- new.magpie(getRegions(output),c(2005),getNames(output))
outputBase[,,] <- output[,,]

#assign aggregation weight
weight <- dimSums(calcOutput("IO",subtype="output",aggregate=FALSE)[,2010,c("feelb","feeli")],dim=3)

#set weights to zero for countries that were not contained in the GCAM2ISO mapping
weight["ALA",,] <- 0
weight["ATA",,] <- 0
weight["BES",,] <- 0
weight["BLM",,] <- 0
weight["CUW",,] <- 0
weight["GGY",,] <- 0
weight["IMN",,] <- 0
weight["JEY",,] <- 0
weight["MAF",,] <- 0
weight["PSE",,] <- 0
weight["SSD",,] <- 0
weight["SXM",,] <- 0

return(list(x=outputBase,weight=weight,
unit="% of cooling type technologies",
description="Cooling shares for different cooling technologies based on Davies et al. (2013) publication and using electricity use weights (aggregated based on IEA World Energy Balances, 2014) for regional mapping"
output[, , "geohdr.tower"] <- 70
output[, , "geohdr.dry"] <- 20
output[, , "geohdr.hybrid"] <- 10
output[, , "hydro.default"] <- 100
output[, , "wind.default"] <- 100
output[, , "spv.default"] <- 100
output[, , "csp.tower"] <- 70
output[, , "csp.dry"] <- 20
output[, , "csp.hybrid"] <- 10

outputBase <- new.magpie(getRegions(output), c(2005), getNames(output))
outputBase[, , ] <- output[, , ]

# assign aggregation weight
weight <- dimSums(calcOutput("IO", subtype = "output", aggregate = FALSE)[, 2010, c("feelb", "feeli")], dim = 3)

# set weights to zero for countries that were not contained in the GCAM2ISO mapping
weight["ALA", , ] <- 0
weight["ATA", , ] <- 0
weight["BES", , ] <- 0
weight["BLM", , ] <- 0
weight["CUW", , ] <- 0
weight["GGY", , ] <- 0
weight["IMN", , ] <- 0
weight["JEY", , ] <- 0
weight["MAF", , ] <- 0
weight["PSE", , ] <- 0
weight["SSD", , ] <- 0
weight["SXM", , ] <- 0

return(list(
x = outputBase, weight = weight,
unit = "% of cooling type technologies",
description = c(
"Cooling shares for different cooling technologies based on Davies et al. (2013) ",
"publication and using electricity use weights (aggregated based on IEA World ",
"Energy Balances, 2014) for regional mapping"
)
))
}
Loading

0 comments on commit 5cf8202

Please sign in to comment.