-
Notifications
You must be signed in to change notification settings - Fork 41
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
use explicit gdx_refprices in convGDX2MIF, ignore LDV variables with NA unit #410
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,26 +5,28 @@ | |
#' | ||
#' | ||
#' @param gdx a GDX as created by readGDX, or the file name of a gdx | ||
#' @param gdx_ref reference-gdx for policy costs, a GDX as created by readGDX, or the file name of a gdx | ||
#' @param gdx_ref reference-gdx for < cm_startyear, used for fixing the prices to this scenario | ||
#' @param file name of the mif file which will be written, if no name is | ||
#' provided a magpie object containing all the reporting information is | ||
#' returned | ||
#' @param scenario scenario name that is used in the *.mif reporting | ||
#' @param t temporal resolution of the reporting, default: | ||
#' t=c(seq(2005,2060,5),seq(2070,2110,10),2130,2150) | ||
#' @param gdx_refpolicycost reference-gdx for policy costs, a GDX as created by readGDX, or the file name of a gdx | ||
#' @author Lavinia Baumstark | ||
#' @examples | ||
#' | ||
#' \dontrun{convGDX2MIF(gdx,gdx_ref,file="REMIND_generic_default.csv",scenario="default")} | ||
#' \dontrun{convGDX2MIF(gdx,gdx_refpolicycost,file="REMIND_generic_default.csv",scenario="default")} | ||
#' | ||
#' @export | ||
#' @importFrom gdx readGDX | ||
#' @importFrom magclass mbind write.report | ||
|
||
convGDX2MIF <- function(gdx, gdx_ref = NULL, file = NULL, scenario = "default", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why do we need gdx_ref still for price correction? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Because prices are Moving Averages, and if There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ah, thanks |
||
t = c(seq(2005, 2060, 5), seq(2070, 2110, 10), | ||
2130, 2150)) { | ||
# Define region subsets | ||
t = c(seq(2005, 2060, 5), seq(2070, 2110, 10), 2130, 2150), | ||
gdx_refpolicycost = gdx_ref) { | ||
|
||
# Define region subsets | ||
regionSubsetList <- toolRegionSubsets(gdx) | ||
# ADD EU-27 region aggregation if possible | ||
if("EUR" %in% names(regionSubsetList)){ | ||
|
@@ -80,22 +82,22 @@ convGDX2MIF <- function(gdx, gdx_ref = NULL, file = NULL, scenario = "default", | |
output <- mbind(output,reportCrossVariables(gdx,output,regionSubsetList,t)[,t,]) | ||
|
||
# Report policy costs, if possible and sensible | ||
if(!is.null(gdx_ref)) { | ||
if (file.exists(gdx_ref)) { | ||
if(!is.null(gdx_refpolicycost)) { | ||
if (file.exists(gdx_refpolicycost)) { | ||
gdp_scen <- try(readGDX(gdx,"cm_GDPscen",react ="error"),silent=T) | ||
gdp_scen_ref <- try(readGDX(gdx_ref,"cm_GDPscen",react = "error"),silent=T) | ||
gdp_scen_ref <- try(readGDX(gdx_refpolicycost,"cm_GDPscen",react = "error"),silent=T) | ||
if(!inherits(gdp_scen,"try-error") && !inherits(gdp_scen_ref,"try-error")){ | ||
if(gdp_scen[1]==gdp_scen_ref[1]){ | ||
message("running reportPolicyCosts, comparing to ", basename(dirname(gdx_ref)), "/", basename(gdx_ref), "...") | ||
output <- mbind(output,reportPolicyCosts(gdx,gdx_ref,regionSubsetList,t)[,t,]) | ||
message("running reportPolicyCosts, comparing to ", basename(dirname(gdx_refpolicycost)), "/", basename(gdx_refpolicycost), "...") | ||
output <- mbind(output,reportPolicyCosts(gdx,gdx_refpolicycost,regionSubsetList,t)[,t,]) | ||
} else { | ||
warning(paste0("The GDP scenario differs from that of the reference run. Did not execute 'reportPolicyCosts'! If a policy costs reporting is desired, please use the 'policyCosts' output.R script.")) | ||
} | ||
} else { | ||
warning(paste0("A comparison of the GDP scenarios between this run and its reference run wasn't possible (old remind version). Therefore to avoid reporting unsensible policy costs, 'reportPolicyCosts' was not executed. If a policy costs reporting is required, please use the 'policyCosts' output.R script.")) | ||
} | ||
} else { | ||
warning(paste0("File ",gdx_ref," not found. Did not execute 'reportPolicyCosts'! If a policy costs reporting is desired, please use the 'policyCosts' output.R script.")) | ||
warning(paste0("File ",gdx_refpolicycost," not found. Did not execute 'reportPolicyCosts'! If a policy costs reporting is desired, please use the 'policyCosts' output.R script.")) | ||
} | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -691,15 +691,17 @@ reportPrices <- function(gdx, output=NULL, regionSubsetList=NULL, | |
out.reporting <- pmax(out, 0) # avoid negative prices | ||
|
||
# for cm_startyear and non-SSP2, replace price by average of period before and after | ||
# this is a workaround to avoid spikes caused by https://github.com/remindmodel/remind/issues/1068 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. but this it not used in default reporting in REMIND, right? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is used for all non-SSP2 scenarios at the moment, as long as this remind issue is not fixed. Please discuss that with @soergel. |
||
if (! grepl("gdp_SSP2", readGDX(gdx, "cm_GDPscen", format = "simplest")) | ||
&& cm_startyear > min(getYears(out, as.integer = TRUE))) { | ||
out.reporting[, cm_startyear, ] <- 0.5 * (out[, cm_startyear - 5, ] + out[, cm_startyear + 5, ]) | ||
} | ||
out.reporting <- lowpass(out.reporting) | ||
# reset values for years smaller than cm_startyear to avoid inconsistencies in cm_startyear - 5 | ||
if (! is.null(gdx_ref)) { | ||
message("reportPrices loads price for < cm_startyear from gdx_ref.") | ||
priceRef <- try(reportPrices(gdx_ref, output = NULL, regionSubsetList = regionSubsetList, t = t)) | ||
fixedyears <- getYears(out)[getYears(out, as.integer = TRUE) < as.integer(cm_startyear)] | ||
fixedyears <- getYears(out)[getYears(out, as.integer = TRUE) < cm_startyear] | ||
if (! inherits(priceRef, "try-error") && length(fixedyears) > 0) { | ||
out.reporting[, fixedyears, ] <- priceRef[getRegions(out), fixedyears, getNames(out)] | ||
} | ||
|
@@ -918,12 +920,22 @@ reportPrices <- function(gdx, output=NULL, regionSubsetList=NULL, | |
"Price|Final Energy|Industry|Solids (US$2005/GJ)" = "FE|Industry|Solids (EJ/yr)" | ||
) | ||
|
||
# transport-specific mappings depending on realization | ||
if (module2realisation["transport",2] == "complex") { | ||
int2ext <- c(int2ext, | ||
"Price|Final Energy|Transport|Liquids|HDV (US$2005/GJ)" = "FE|Transport|non-LDV|Liquids (EJ/yr)", | ||
"Price|Final Energy|Transport|Liquids|LDV (US$2005/GJ)" = "FE|Transport|LDV|Liquids (EJ/yr)") | ||
} else if (module2realisation["transport",2] == "edge_esm") { | ||
int2ext <- c(int2ext, | ||
"Price|Final Energy|Transport|Liquids|HDV (US$2005/GJ)" = "FE|Transport|Diesel Liquids (EJ/yr)", | ||
"Price|Final Energy|Transport|Liquids|LDV (US$2005/GJ)" = "FE|Transport|Pass|Liquids (EJ/yr)") | ||
} | ||
|
||
## weights definition for FE prices region aggregation | ||
## add weights definition for region aggregation for FE prices that were added automatically | ||
if(length(pm_FEPrice_by_FE) > 0) { | ||
margPriceVars <- getItems(out,3)[grep("Price|Final Energy|", getItems(out,3), fixed = TRUE)] | ||
margPriceVars <- grep("Price|Final Energy|", getItems(out,3), fixed = TRUE, value = TRUE) | ||
margPriceVars <- setdiff(margPriceVars, names(int2ext)) | ||
vars <- gsub("US\\$2005/GJ","EJ/yr",gsub("Price\\|Final Energy\\|","FE|",margPriceVars)) | ||
vars <- gsub("US\\$2005/GJ", "EJ/yr", gsub("Price\\|Final Energy\\|","FE|",margPriceVars)) | ||
names(vars) <- margPriceVars | ||
vars <- gsub("Efuel","Hydrogen",vars) ###warning FE variable should be renamed and this line should be removed in the future | ||
# for(var in vars){ # display price variables with no matching FE weight | ||
|
@@ -935,21 +947,6 @@ reportPrices <- function(gdx, output=NULL, regionSubsetList=NULL, | |
int2ext <- c(int2ext, vars) | ||
} | ||
|
||
# transport-specific mappings depending on realization | ||
|
||
if (module2realisation["transport",2] == "complex") { | ||
int2ext <- c(int2ext, | ||
"Price|Final Energy|Transport|Liquids|HDV (US$2005/GJ)" = "FE|Transport|non-LDV|Liquids (EJ/yr)", | ||
"Price|Final Energy|Transport|Liquids|LDV (US$2005/GJ)" = "FE|Transport|LDV|Liquids (EJ/yr)") | ||
} else if (module2realisation["transport",2] == "edge_esm") { | ||
int2ext <- c(int2ext, | ||
"Price|Final Energy|Transport|Liquids|HDV (US$2005/GJ)" = "FE|Transport|Diesel Liquids (EJ/yr)", | ||
"Price|Final Energy|Transport|Liquids|LDV (US$2005/GJ)" = "FE|Transport|Pass|Liquids (EJ/yr)", | ||
"Price|Final Energy|Transport|Gases (US$2005/GJ)" = "FE|Transport|Gases (EJ/yr)") | ||
} | ||
|
||
|
||
|
||
## moving averages and rawdata | ||
avgs <- getNames(out.lowpass) | ||
rawdata <- getNames(out.rawdata) | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
there is no
gdx_ref
argument anymoreThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
that is not correct, we still need
gdx_ref
…