Skip to content

Commit

Permalink
Merge pull request #475 from magpiemodel/revert-474-develop
Browse files Browse the repository at this point in the history
Revert "Clean the coupling interface (remove deletePlus, clean code)"
  • Loading branch information
pfuehrlich-pik committed Nov 10, 2022
2 parents a5cc7b6 + 92bc016 commit 0cabd35
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 45 deletions.
2 changes: 1 addition & 1 deletion .zenodo.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"title": "MAgPIE - An Open Source land-use modeling framework",
"version": "4.6.0dev",
"version": "4.6.0",
"creators": [
{
"name": "Dietrich, Jan Philipp",
Expand Down
15 changes: 0 additions & 15 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,6 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).


## Unreleased

### changed
-

### added
-

### removed
- **scripts** removed remind2::deletePlus in coupling interface of start_function

### fixed
-


## [4.6.0] - 2022-11-09

### changed
Expand Down
2 changes: 1 addition & 1 deletion CITATION.cff
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ authors:
email: popp@pik-potsdam.de

title: MAgPIE - An Open Source land-use modeling framework
version: 4.6.0dev
version: 4.6.0
date-released: 2022-11-09
repository-code: https://github.com/magpiemodel/magpie
keywords:
Expand Down
61 changes: 33 additions & 28 deletions scripts/start_functions.R
Original file line number Diff line number Diff line change
Expand Up @@ -382,12 +382,12 @@ start_run <- function(cfg, scenario = NULL, codeCheck = TRUE, lock_model = TRUE)
if(cfg$recalibrate=="ifneeded") {
if(!file.exists(calib_file)) {
# recalibrate if file does not exist
cfg$recalibrate <- TRUE
cfg$recalibrate <- TRUE
} else {
# recalibrate if all calibration factors are 1, otherwise don't
cfg$recalibrate <- all(magclass::read.magpie(calib_file)==1)
}
}
}

if(cfg$recalibrate){
cat("Starting yield calibration factor calculation!\n")
Expand Down Expand Up @@ -494,7 +494,7 @@ getReportData <- function(path_to_report_bioenergy, mute_ghgprices_until = "y201
call. = FALSE)
}

.bioenergyDemand <- function(mag){
.bioenergy_demand <- function(mag){
notGLO <- getRegions(mag)[!(getRegions(mag)=="GLO")]
out <- mag[,,"Primary Energy Production|Biomass|Energy Crops (EJ/yr)"]*10^3
dimnames(out)[[3]] <- NULL
Expand All @@ -504,7 +504,7 @@ getReportData <- function(path_to_report_bioenergy, mute_ghgprices_until = "y201
write.magpie(out[notGLO,,],f)
}

.emissionPrices <- function(mag, mute_ghgprices_until){
.emission_prices <- function(mag, mute_ghgprices_until){
out_c <- mag[,,"Price|Carbon (US$2005/t CO2)"]*44/12 # US$2005/tCO2 -> US$2005/tC
dimnames(out_c)[[3]] <- "co2_c"

Expand All @@ -531,35 +531,40 @@ getReportData <- function(path_to_report_bioenergy, mute_ghgprices_until = "y201
write.magpie(out[notGLO,,],f)
}

.readAndPrepare <- function(mifPath) {
rep <- read.report(mifPath, as.list = FALSE)
if (length(getNames(rep, dim = "scenario")) != 1) stop("getReportData: report contains more or less than 1 scenario.")
mag <- collapseNames(rep) # get rid of scenario and model dimension if they exist

if(!("y1995" %in% getYears(mag))){
empty95 <- mag[, 1,]
empty95[,,] <- 0
dimnames(empty95)[[2]] <- "y1995"
mag <- mbind(empty95, mag)
}
years <- 1990 + 5 * seq_len(32)
mag <- time_interpolate(mag, years)
return(mag)
}

# read REMIND report
message("Reading bioenergy_demand from ", path_to_report_bioenergy)
mag <- .readAndPrepare(path_to_report_bioenergy)
message("Reading bioenergy_demand from ",path_to_report_bioenergy)
rep <- read.report(path_to_report_bioenergy, as.list = FALSE)
if (length(getNames(rep,dim="scenario"))!=1) stop("getReportData: REMIND report contains more or less than 1 scenario.")
rep <- collapseNames(rep) # get rid of scenrio and model dimension if they exist
mag <- deletePlus(rep) #delete "+" and "++" from variable names

if(!("y1995" %in% getYears(mag))){
empty95<-mag[,1,];empty95[,,]<-0;dimnames(empty95)[[2]] <- "y1995"
mag <- mbind(empty95,mag)
}
years <- 1990+5*(1:32)
mag <- time_interpolate(mag,years)

.bioenergyDemand(mag)
.bioenergy_demand(mag)

# write emission files, if specified use path_to_report_ghgprices instead of the bioenergy report
if (is.na(path_to_report_ghgprices)) {
message("Reading ghg prices from the same file (", path_to_report_bioenergy, ")")
.emissionPrices(mag, mute_ghgprices_until)
message("Reading ghg prices from ",path_to_report_bioenergy)
.emission_prices(mag, mute_ghgprices_until)
} else {
message("Reading ghg prices from ", path_to_report_ghgprices)
ghgmag <- .readAndPrepare(path_to_report_ghgprices)
.emissionPrices(ghgmag, mute_ghgprices_until)
message("Reading ghg prices from ",path_to_report_ghgprices)
ghgrep <- read.report(path_to_report_ghgprices, as.list = FALSE)
ghgrep <- collapseNames(ghgrep)
ghgmag <- deletePlus(ghgrep) #delete "+" and "++" from variable names
if(!("y1995" %in% getYears(ghgmag))){
empty95 <- ghgmag[,1,]
empty95[,,] <- 0
dimnames(empty95)[[2]] <- "y1995"
ghgmag <- mbind(empty95,ghgmag)
}
years <- 1990+5*(1:32)
ghgmag <- time_interpolate(ghgmag,years)

.emission_prices(ghgmag, mute_ghgprices_until)
}
}

0 comments on commit 0cabd35

Please sign in to comment.