Skip to content
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

edgeTransport 2.0 release #524

Merged
merged 40 commits into from
Jul 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
ed9ceee
EDGETrewrite
johannah-pik May 13, 2024
c1fd142
adjust timesteps weight
johannah-pik May 13, 2024
62c17b6
Delete calcEDGETrData.R
johannah-pik May 13, 2024
817539a
Update calcEDGETransport.R
johannah-pik May 13, 2024
fc6bc15
updates
johannah-pik May 21, 2024
813f86a
Merge branch 'master' of https://github.com/pik-piam/mrremind into ED…
johannah-pik May 21, 2024
f46081c
buildlib
johannah-pik May 22, 2024
ae3979a
add loadfactor + reduce set of scenarios for calibration
johannah-pik May 24, 2024
9cbd39f
Add missing files
johannah-pik May 24, 2024
32e2210
Merge branch 'master' of https://github.com/pik-piam/mrremind into ED…
johannah-pik May 24, 2024
aa8b46a
buildlib
johannah-pik May 24, 2024
622b457
add demScen selection to LDV_shares_transport
johannah-pik May 25, 2024
3262b6d
Update readEDGETransport.R
johannah-pik May 25, 2024
10738a0
Merge branch 'master' of https://github.com/pik-piam/mrremind into ED…
johannah-pik Jun 4, 2024
2ad620c
call madrat wrapper for edgeT SA
johannah-pik Jun 4, 2024
c22df94
buildlib
johannah-pik Jun 4, 2024
70dce97
bugfix calcOutput call
johannah-pik Jun 5, 2024
56f176a
add missing edget file to fullREMIND
Jun 6, 2024
cccad9c
Merge branch 'master' of https://github.com/pik-piam/mrremind into ED…
johannah-pik Jun 8, 2024
aebd5de
Merge branch 'EDGETrefactoring' of github.com:johannah-pik/mrremind i…
Jun 8, 2024
7331967
Merge branch 'master' of https://github.com/pik-piam/mrremind into ED…
johannah-pik Jun 10, 2024
74bcda9
buildlib
johannah-pik Jun 10, 2024
b9cb5ea
Merge branch 'EDGETrefactoring' of github.com:johannah-pik/mrremind i…
Jun 10, 2024
1109cee
Update calcIO.R
johannah-pik Jun 12, 2024
52b6411
translate demscen
johannah-pik Jun 12, 2024
64b8c79
bugfix + change fix to adjust RUS rather than AZE
johannah-pik Jun 13, 2024
78ddd87
buildlib
johannah-pik Jun 13, 2024
d0b840d
Change weights for aggregation to real reference variable
johannah-pik Jun 20, 2024
186123a
Merge branch 'master' of https://github.com/pik-piam/mrremind into ED…
johannah-pik Jun 20, 2024
67f3168
buildib
johannah-pik Jun 20, 2024
bef91bb
Merge branch 'master' of https://github.com/pik-piam/mrremind into ED…
johannah-pik Jul 7, 2024
888aace
Adjust call for reg mapping
johannah-pik Jul 8, 2024
31dd401
bugfix gdp
johannah-pik Jul 8, 2024
9233842
bugfix weight dimensions
johannah-pik Jul 9, 2024
474b103
Merge branch 'master' of https://github.com/pik-piam/mrremind into ED…
johannah-pik Jul 9, 2024
8302195
buildlib
johannah-pik Jul 9, 2024
bd3a1f0
Merge branch 'master' of https://github.com/pik-piam/mrremind into ED…
johannah-pik Jul 17, 2024
b89588a
Fix calibration issues
johannah-pik Jul 17, 2024
e890f32
buildlib
johannah-pik Jul 17, 2024
00356c5
bugfix unit eu reference scenario
johannah-pik Jul 17, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .buildlibrary
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
ValidationKey: '362724990'
ValidationKey: '36475351'
AcceptedWarnings:
- 'Warning: package ''.*'' was built under R version'
- 'Warning: namespace ''.*'' is not available and has been replaced'
Expand All @@ -10,6 +10,7 @@ AcceptedNotes:
- unable to verify current time
- Imports includes .* non-default packages.
- installed size is
- 'Undefined global functions or variables:'
AutocreateReadme: yes
allowLinterWarnings: yes
enforceVersionUpdate: yes
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.182.10
date-released: '2024-07-15'
version: 0.183.1
date-released: '2024-07-17'
abstract: The mrremind packages contains data preprocessing for the REMIND model.
authors:
- family-names: Baumstark
Expand Down
7 changes: 3 additions & 4 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.182.10
Date: 2024-07-15
Version: 0.183.1
Date: 2024-07-17
Authors@R: c(
person("Lavinia", "Baumstark", , "[email protected]", role = c("aut", "cre")),
person("Renato", "Rodrigues", role = "aut"),
Expand Down Expand Up @@ -38,7 +38,7 @@ Description: The mrremind packages contains data preprocessing for the
License: LGPL-3 | file LICENSE
URL: https://github.com/pik-piam/mrremind
Depends:
edgeTransport (>= 0.17.0),
edgeTransport (>= 1.5.5),
madrat (>= 3.7.1),
magclass (>= 6.16.1),
mrcommons (>= 1.38.0),
Expand All @@ -64,7 +64,6 @@ Imports:
readxl,
reshape2,
rlang,
rmndt,
tibble,
tidyr,
tidyselect,
Expand Down
5 changes: 2 additions & 3 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -84,12 +84,9 @@ importFrom(assertr,not_na)
importFrom(assertr,verify)
importFrom(assertr,within_bounds)
importFrom(data.table,":=")
importFrom(data.table,as.data.table)
importFrom(data.table,data.table)
importFrom(data.table,fread)
importFrom(data.table,rbindlist)
importFrom(data.table,setDT)
importFrom(data.table,setcolorder)
importFrom(data.table,setkeyv)
importFrom(data.table,setnames)
importFrom(dplyr,across)
Expand Down Expand Up @@ -151,6 +148,8 @@ importFrom(ggplot2,scale_linetype_manual)
importFrom(ggplot2,scale_shape_manual)
importFrom(ggplot2,theme)
importFrom(ggplot2,theme_minimal)
importFrom(madrat,madratAttach)
importFrom(madrat,toolAggregate)
importFrom(magclass,matchDim)
importFrom(magrittr,"%>%")
importFrom(quitte,add_countrycode_)
Expand Down
79 changes: 0 additions & 79 deletions R/calcEDGETrData.R

This file was deleted.

190 changes: 82 additions & 108 deletions R/calcEDGETransport.R
Original file line number Diff line number Diff line change
@@ -1,132 +1,106 @@
#' @title Prepare EDGETransport inputs
#'
#' @return magpie object of EDGEtransport iterative inputs
#' @author Alois Dirnaichner, Marianna Rottoli
#' @author Johanna Hoppe
#' @seealso \code{\link{readSource}}
#' @param subtype refer to the code for a list of allowed subtypes.
#'
#' @param subtype REMIND/iterative EDGE-T input data subtypes
#' @return REMIND/iterative EDGE-T input data for all scenario combinations
#' @examples
#' \dontrun{ a <- calcOutput(type="EDGETransport", subtype="logit_exponent", aggregate=F)
#' \dontrun{ a <- calcOutput(type = "EDGETransport", subtype = "CAPEXandNonFuelOPEX", aggregate = F)
#' }
#'
#'@importFrom data.table as.data.table
calcEDGETransport <- function(subtype = "logit_exponent") {
value <- i.value <- NULL

if (subtype %in% c("logit_exponent", "ptab4W")) {
conv = FALSE
} else {
conv = TRUE
}
calcEDGETransport <- function(subtype) {

weightInt <- calcOutput("GDP", aggregate = F)
get_weight <- function(data, weightInt) {
year_inter = getYears(data)
## define weight for intensive entries (for weighted average)
weightInt <- time_interpolate(
weightInt,
year_inter,
extrapolation_type="constant")[,, getNames(data, dim=1)]
## create an empty object that has the same dimensions as data
weight <- new.magpie(cells_and_regions = getRegions(data), years = getYears(data), names = getNames(data), fill = 0)
## use the GPD for each SSP in data to fill up the empty weight (it needs as many repetitions as SSP* is called in data)
regions <- getRegions(weightInt)
years <- getYears(weightInt)
for (gdpscen in getNames(weightInt)) {
mselect(weight, region=regions, year=years, data=gdpscen) <- weightInt[regions, years, gdpscen]
}
getSets(weight, fulldim=F)[3] <- getSets(data, fulldim=F)[3]
return(weight)
}

if(subtype == "pm_trp_demand"){
fe_dem <- as.data.table(as.quitte(readSource("EDGETransport", "fe_demand_tech")))[
, c("model", "scenario", "variable", "unit") := NULL
]
fe2es <- as.data.table(as.quitte(readSource("EDGETransport", "fe2es")))[
, c("model", "scenario", "variable", "unit") := NULL
]
es_dem <- fe_dem[fe2es, on=c("period", "region", "GDP_scenario", "DEM_scenario", "EDGE_scenario", "all_teEs")][
, sum(value * i.value), by=c("period", "region", "GDP_scenario", "DEM_scenario", "EDGE_scenario", "all_in")
]
data <- as.magpie(es_dem, spatial=2, temporal=1, datacol=7)
}else{
data <- readSource("EDGETransport", subtype, convert = conv)
}
x <- readSource("EDGETransport", subtype)

switch(subtype,
"logit_exponent" = {
weight = NULL
unit = "[-]"
description = "Logit exponent values for transport alternatives"
"f35_esCapCost" = {
weight <- readSource("EDGETransport", subtype = "weightESdemand")
#Rule out numerical errors after disaggregating very small numbers
weight[weight < 1e-5] <- 0
#check whether weightsum is zero for some cases
#if so, the values should just be aggregated equally in order to prevent zeros in the results
weight <- magpie2dt(weight)
regMap <- toolGetMapping(getConfig("regionmapping"), type = "regional", where = "mappingfolder")
setnames(regMap, "CountryCode", "all_regi")
weight <- merge(weight, regMap[, c("all_regi", "RegionCode")], by = "all_regi")
weight[, weightSum := sum(value), by = c("RegionCode", "GDP_scenario", "DEM_scenario", "EDGE_scenario", "all_teEs", "tall")]
weight[weightSum == 0, value := 1]
weight[, c("RegionCode", "weightSum") := NULL]
weight <- as.magpie(weight)
unit = "2005US$/(p|t)km"
description = "Capital cost (purchase) per energy service demand on CES level."
},
"harmonized_intensities" = {
weight = get_weight(data, weightInt)
unit = "Passenger transport: [EJ/Mpkm]; freight transport: [EJ/Mtkm]"
description = "Energy intensity for transport modes and fuel, harmonized on IEA balances"
"f35_fe2es" = {
weight = readSource("EDGETransport", "f35_demByTech")
weight[weight < 1e-5] <- 0
#check whether weightsum is zero for some cases
#if so, the values should just be aggregated equally in order to prevent zeros in the results
weight <- magpie2dt(weight)
regMap <- toolGetMapping(getConfig("regionmapping"), type = "regional", where = "mappingfolder")
setnames(regMap, "CountryCode", "all_regi")
weight <- merge(weight, regMap[, c("all_regi", "RegionCode")], by = "all_regi")
weight[, weightSum := sum(value), by = c("RegionCode", "GDP_scenario", "DEM_scenario", "EDGE_scenario", "all_enty", "all_in", "all_teEs", "tall")]
weight[weightSum == 0, value := 1]
weight[, c("RegionCode", "weightSum", "all_enty", "all_in") := NULL]
weight <- as.magpie(weight)
unit = "trn (p|t)km/Twa"
description = "Energy efficiency on CES level."
},
"value_time" = {
weight = get_weight(data, weightInt)
unit = "Passenger transport: [2005US$/pkm]; freight transport: [2005US$/tkm]"
description = "Value of time for passenger transport modes"
},
"pref" = {
weight = get_weight(data, weightInt)
unit = "LDVs 4wheelers: inconvenience cost [2005US$/pkm]; all other modes: [-] share weight, a dimensionless parameter reflecting consumer preferences"
description = "Inconvenience cost reflecting availability of infrastructure"
},
"ptab4W" = {
"f35_demByTech" = {
weight = NULL
unit = "[-]"
description = "LDVs 4wheelers: factors for the inconvenience costs."
},
"price_nonmot" = {
weight = get_weight(data, weightInt)
unit = "Passenger transport: [2005US$/pkm]; freight transport: [2005US$/tkm]"
description = "Price for non motorized transport modes (Walking; Cycling)"
unit = "TWa"
description = "Final energy demand on CES level."
},
"UCD_NEC_iso" = {
weight = get_weight(data, weightInt)
unit = "Passenger transport: [2005US$/pkm]; freight transport: [2005US$/tkm]"
description = "Non energy costs for all motorized transport modes, both total and purchase for LDVs"
"f29_trpdemand" = {
weight = NULL
unit = "trillion pkm/trillion tkm"
description = "Energy service demand on CES level."
},
"loadFactor" = {
weight = get_weight(data, weightInt)
unit = "Passenger transport: [pass/veh]; freight transport: [ton/veh]"
description = "Load factor for all motorized transport modes"
"CAPEXandNonFuelOPEX" = {
gdp <- calcOutput("GDP", aggregate = FALSE)[,,"gdp_SSP2"]
weight = gdp |> time_interpolate(getYears(x))
unit = "2005US$/(p|t)km"
description = "Capital cost (purchase) and non-fuel operational costs on technology level."
},
"annual_mileage" = {
weight = get_weight(data, weightInt)
unit = "km/veh/year"
description = "Annual mileage for selected transport modes"
"scenSpecPrefTrends" = {
gdp <- calcOutput("GDP", aggregate = FALSE)[,,"gdp_SSP2"]
weight = gdp |> time_interpolate(getYears(x))
unit = "-"
description = "Scenario specific preference trends on technology level."
},
"esCapCost" = {
weight = get_weight(data, weightInt)
unit = "Passenger transport [2005US$/pkm]; freight transport: [2005US$/tkm]"
description = "Transport ES demand trajectories for the CES tree."
"scenSpecLoadFactor" = {
gdp <- calcOutput("GDP", aggregate = FALSE)[,,"gdp_SSP2"]
weight = gdp |> time_interpolate(getYears(x))
unit = "-"
description = "Scenario specific load factor on technology level."
},
"fe2es" = {
weight = get_weight(data, weightInt)
unit = "Passenger transport [trn pkm/Twa], freight transport [trn tkm/Twa]"
description = "Energy efficiency of CES level nodes for Transport."
"scenSpecEnIntensity" = {
gdp <- calcOutput("GDP", aggregate = FALSE)[,,"gdp_SSP2"]
weight = gdp |> time_interpolate(getYears(x))
unit = "MJ/vehkm"
description = "Scenario specific energy intensity on technology level."
},
"pm_trp_demand" = {
weight = NULL
unit = "Passenger transport [trn pkm], freight transport [trn tkm]"
description = "CES level transport demand."
"initialIncoCosts" = {
gdp <- calcOutput("GDP", aggregate = FALSE)[,,"gdp_SSP2"]
weight = gdp |> time_interpolate(getYears(x))
unit = "2005US$/(p|t)km"
description = "Initial inconvenience cost values."
},
"fe_demand_tech" = {
weight = NULL
unit = "TWa"
description = "FE demand divided by technologies for different ES on the CES level."
"annualMileage" = {
gdp <- calcOutput("GDP", aggregate = FALSE)[,,"gdp_SSP2"]
weight = gdp |> time_interpolate(getYears(x))
unit = "vehkm/yr"
description = "Annual vehicle km traveled."
},
"pm_fe_demand_EDGETbased" = {
weight = NULL
unit = "EJ"
description = "UE demand divided by technologies for different ES on the CES level."
})
"timeValueCosts" = {
gdp <- calcOutput("GDP", aggregate = FALSE)[,,"gdp_SSP2"]
weight = gdp |> time_interpolate(getYears(x))
unit = "2005US$/(p|t)km"
description = "Value of time cost equivalent."
}
)

return(list(x = data,
return(list(x = x,
weight = weight,
unit = unit,
description = description))
Expand Down
2 changes: 1 addition & 1 deletion R/calcEU_ReferenceScenario.R
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ calcEU_ReferenceScenario <- function() {

weights <- x
weights[, , ] <- NA
weights[, , "Price|Secondary Energy|Electricity (US$2005/GJ)"] <- 1
weights[, , "Price|Secondary Energy|Electricity (EUR2013/GJ)"] <- 1
fbenke-pik marked this conversation as resolved.
Show resolved Hide resolved

return(list(
x = x, weight = weights, mixed_aggregation = TRUE,
Expand Down
9 changes: 9 additions & 0 deletions R/calcIO.R
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,15 @@ calcIO <- function(subtype = c("input", "output", "output_biomass", "trade",
# read in data and convert from ktoe to EJ
data <- readSource("IEA", subtype = ieaSubtype) * 4.1868e-5

# Correct transport reporting issue in IEA data for NONBIODIES.MARBUNK in RUS
# FE is reported in 1990 and 2010 but not in the years in between. This cause problems in the harmonization of EDGE-Transport
# and the IEA data in 2005 as there is no MARBUNK demand at all for REF regions.
data["RUS", seq(1990, 2010, 1), "NONBIODIES.MARBUNK"] <-
data["RUS", c(1990, 2010),"NONBIODIES.MARBUNK"]|> time_interpolate(seq(1990, 2010, 1))
#Adjust totals
data["RUS", seq(1991, 2009, 1),"TOTAL.MARBUNK"] <-
data["RUS", seq(1991, 2009, 1),"TOTAL.MARBUNK"] + data["RUS", seq(1991, 2009, 1), "NONBIODIES.MARBUNK"]

ieamatch <- read.csv2(mapping, stringsAsFactors = FALSE, na.strings = "")

# add total buildings electricity demand (feelb = feelcb + feelhpb + feelrhb)
Expand Down
Loading
Loading