-
Notifications
You must be signed in to change notification settings - Fork 17
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
fix warning: The naming option = 'indicator.scenario' is deprecated... #51
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 |
---|---|---|
@@ -1,8 +1,8 @@ | ||
Type: Package | ||
Package: mrland | ||
Title: MadRaT land data package | ||
Version: 0.65.0 | ||
Date: 2024-11-04 | ||
Version: 0.65.1 | ||
Date: 2024-11-18 | ||
Authors@R: c( | ||
person("Jan Philipp", "Dietrich", , "[email protected]", role = c("aut", "cre")), | ||
person("Abhijeet", "Mishra", role = "aut"), | ||
|
@@ -54,11 +54,8 @@ Imports: | |
Suggests: | ||
covr, | ||
ggplot2, | ||
knitr, | ||
rmarkdown, | ||
testthat | ||
VignetteBuilder: | ||
knitr | ||
Encoding: UTF-8 | ||
LazyData: no | ||
RoxygenNote: 7.3.2 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,90 +1,93 @@ | ||
#' @title readS4Nproject_input | ||
#' @description reads in total bioenergy (1st gen, 2nd gen and residues) demand and co2 prices from IMAGE model for Sim4Nexus project | ||
#' | ||
#' readS4Nproject_input | ||
#' | ||
#' reads in total bioenergy (1st gen, 2nd gen and residues) | ||
#' demand and co2 prices from IMAGE model for Sim4Nexus project | ||
#' | ||
#' @param subtype IMAGE input to be read in: co2prices or bioenergy | ||
#' | ||
#' @return magpie object at country-level resolution | ||
#' | ||
#' @author Felicitas Beier | ||
#' @seealso \code{\link{readSource}} | ||
#' @examples | ||
#' | ||
#' \dontrun{ a <- readSource("S4Nproject_input", convert="onlycorrect", aggregate=FALSE) | ||
#' \dontrun{ | ||
#' a <- readSource("S4Nproject_input", convert = "onlycorrect", aggregate = FALSE) | ||
#' } | ||
|
||
readS4Nproject_input <- function(subtype="co2prices") { | ||
|
||
readS4Nproject_input <- function(subtype = "co2prices") { # nolint: object_name_linter. | ||
# IMAGE-iso mapping file | ||
regionmapping <- read.csv("image_isocodes.csv") | ||
regionmapping <- data.frame(iso=regionmapping$ISO.code,Region=regionmapping$IMAGE.region.name) | ||
regionmapping <- as.data.frame(as.matrix(regionmapping),stringsAsFactors=F) | ||
regionmapping <- data.frame(iso = regionmapping$ISO.code, Region = regionmapping$IMAGE.region.name) | ||
regionmapping <- as.data.frame(as.matrix(regionmapping), stringsAsFactors = FALSE) | ||
|
||
# match IMAGE countries with all iso countries | ||
iso <- getISOlist(type = "all") | ||
mapping <- data.frame(iso=iso, stringsAsFactors=F) | ||
regionmapping <- merge(mapping, regionmapping, "iso", all.x=TRUE) | ||
mapping <- data.frame(iso = iso, stringsAsFactors = FALSE) | ||
regionmapping <- merge(mapping, regionmapping, "iso", all.x = TRUE) | ||
# missing matches: | ||
regionmapping$Region[regionmapping$iso=="SRB"] <- "Eastern Europe" | ||
regionmapping$Region[regionmapping$iso=="SSD"] <- "Eastern Africa" | ||
regionmapping$Region[regionmapping$iso=="PSE"] <- "Middle East" | ||
regionmapping$Region[regionmapping$iso=="SXM"] <- "Rest Centr America" | ||
regionmapping$Region[regionmapping$iso=="ALA"] <- "OECD Europe" | ||
regionmapping$Region[regionmapping$iso=="ATA"] <- "Oceania" | ||
regionmapping$Region[regionmapping$iso=="BES"] <- "OECD Europe" | ||
regionmapping$Region[regionmapping$iso=="BLM"] <- "OECD Europe" | ||
regionmapping$Region[regionmapping$iso=="CUW"] <- "Rest Centr America" | ||
regionmapping$Region[regionmapping$iso=="GGY"] <- "OECD Europe" | ||
regionmapping$Region[regionmapping$iso=="GRL"] <- "OECD Europe" | ||
regionmapping$Region[regionmapping$iso=="IMN"] <- "OECD Europe" | ||
regionmapping$Region[regionmapping$iso=="JEY"] <- "OECD Europe" | ||
regionmapping$Region[regionmapping$iso=="MAF"] <- "Rest Centr America" | ||
regionmapping$Region[regionmapping$iso=="MNE"] <- "Eastern Europe" | ||
regionmapping$Region[regionmapping$iso == "SRB"] <- "Eastern Europe" | ||
regionmapping$Region[regionmapping$iso == "SSD"] <- "Eastern Africa" | ||
regionmapping$Region[regionmapping$iso == "PSE"] <- "Middle East" | ||
regionmapping$Region[regionmapping$iso == "SXM"] <- "Rest Centr America" | ||
regionmapping$Region[regionmapping$iso == "ALA"] <- "OECD Europe" | ||
regionmapping$Region[regionmapping$iso == "ATA"] <- "Oceania" | ||
regionmapping$Region[regionmapping$iso == "BES"] <- "OECD Europe" | ||
regionmapping$Region[regionmapping$iso == "BLM"] <- "OECD Europe" | ||
regionmapping$Region[regionmapping$iso == "CUW"] <- "Rest Centr America" | ||
regionmapping$Region[regionmapping$iso == "GGY"] <- "OECD Europe" | ||
regionmapping$Region[regionmapping$iso == "GRL"] <- "OECD Europe" | ||
regionmapping$Region[regionmapping$iso == "IMN"] <- "OECD Europe" | ||
regionmapping$Region[regionmapping$iso == "JEY"] <- "OECD Europe" | ||
regionmapping$Region[regionmapping$iso == "MAF"] <- "Rest Centr America" | ||
regionmapping$Region[regionmapping$iso == "MNE"] <- "Eastern Europe" | ||
|
||
# read in data | ||
if (subtype=="co2prices") { | ||
data <- read.csv("IMAGE_data_26112020_co2price.csv", stringsAsFactors=F) | ||
} else if (subtype=="bioenergy") { | ||
data <- read.csv("IMAGE_data_26112020_bioenergy.csv", stringsAsFactors=F) | ||
if (subtype == "co2prices") { | ||
data <- read.csv("IMAGE_data_26112020_co2price.csv", stringsAsFactors = FALSE) | ||
} else if (subtype == "bioenergy") { | ||
data <- read.csv("IMAGE_data_26112020_bioenergy.csv", stringsAsFactors = FALSE) | ||
} else { | ||
stop("Specify subtype to be read in: co2prices or bioenergy (total bioenergy demand)") | ||
} | ||
|
||
# region name correction | ||
data$Region[data$Region=="Russia+"] <- "Russia +" | ||
data$Region[data$Region=="China+"] <- "China +" | ||
data$Region[data$Region=="Rest C. America"] <- "Rest Centr America" | ||
data$Region[data$Region=="Rest S. America"] <- "Rest South America" | ||
data$Region[data$Region=="Rest S. Asia"] <- "Rest South Asia" | ||
data$Region[data$Region=="Rest S. Africa"] <- "Rest Southern Africa" | ||
data$Region[data$Region == "Russia+"] <- "Russia +" | ||
data$Region[data$Region == "China+"] <- "China +" | ||
data$Region[data$Region == "Rest C. America"] <- "Rest Centr America" | ||
data$Region[data$Region == "Rest S. America"] <- "Rest South America" | ||
data$Region[data$Region == "Rest S. Asia"] <- "Rest South Asia" | ||
data$Region[data$Region == "Rest S. Africa"] <- "Rest Southern Africa" | ||
|
||
data <- merge(data, regionmapping, "Region") | ||
data <- data.frame(scenario=data$Scenario,year=data$Year,value=data$Value,iso=data$iso, stringsAsFactors=F) | ||
data$year <- paste0("y",data$year) | ||
data <- data.frame(scenario = data$Scenario, | ||
year = data$Year, | ||
value = data$Value, | ||
iso = data$iso, | ||
stringsAsFactors = FALSE) | ||
data$year <- paste0("y", data$year) | ||
x <- collapseNames(as.magpie(data)) | ||
if (subtype=="bioenergy"){ | ||
|
||
if (subtype == "bioenergy") { | ||
# Disaggregate regional bioenergy to country values using population weight | ||
# country population in SSP2 | ||
pop <- calcOutput("Population", | ||
naming = "indicator.scenario", | ||
extension2150 = "none", | ||
aggregate = FALSE, | ||
years = paste0("y", c(2005, seq(2010, 2100, by = 10))), | ||
round = 6) | ||
pop <- collapseNames(pop[,,"SSP2"]) | ||
pop <- collapseNames(calcOutput("Population", | ||
scenario = "SSP2", | ||
extension2150 = "none", | ||
aggregate = FALSE, | ||
years = paste0("y", c(2005, seq(2010, 2100, by = 10))), | ||
round = 6)) | ||
|
||
# regional population | ||
pop_reg <- toolAggregate(pop, rel=regionmapping, weight=NULL) | ||
pop_reg <- as.data.frame(pop_reg) | ||
pop_reg <- data.frame(Region=pop_reg$Region, year=as.character(pop_reg$Year), Value=pop_reg$Value, stringsAsFactors=F) | ||
pop_reg <- merge(pop_reg, regionmapping, "Region") | ||
pop_reg <- collapseNames(as.magpie(data.frame(iso=pop_reg$iso, year=pop_reg$year, Value=pop_reg$Value))) | ||
popReg <- toolAggregate(pop, rel = regionmapping, weight = NULL) | ||
popReg <- as.data.frame(popReg) | ||
popReg <- data.frame(Region = popReg$Region, | ||
year = as.character(popReg$Year), | ||
Value = popReg$Value, | ||
stringsAsFactors = FALSE) | ||
popReg <- merge(popReg, regionmapping, "Region") | ||
popReg <- collapseNames(as.magpie(data.frame(iso = popReg$iso, year = popReg$year, Value = popReg$Value))) | ||
|
||
# country population share | ||
pop_shr <- pop/pop_reg | ||
|
||
# bioenergy demand weighted by population | ||
x <- x * pop/pop_reg | ||
x <- x * pop / popReg | ||
Comment on lines
+79
to
+89
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. Just a comment, but can't one simply do 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. Seems reasonable, but I didn't want to change more than necessary (to fix the warning + linter), so I don't need to test more than necessary 😉 |
||
} | ||
|
||
return(x) | ||
} |
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.
You can drop "collapseNames" entirely :)
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.
No that would lead to different output:
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.
Did you run the comparison with
scenario = "SSP2"
?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.
Ok, I see... collapseNames deletes the data name, if only 1 data dimension exists.