Skip to content

Commit

Permalink
fix reporting after REMIND run tests
Browse files Browse the repository at this point in the history
  • Loading branch information
johannah-pik committed Oct 29, 2024
1 parent 0ec44c8 commit 2bb86ce
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 38 deletions.
6 changes: 3 additions & 3 deletions R/aggregateVariables.R
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ aggregateVariables <- function(vars, mapAggregation, weight = NULL) {
# Exclude vars that are not aggregated and create solely the variable entry
exclude <- c("Load factor", "Load factor raw", "Preference|FV", "Preference|S1S", "Preference|S2S1",
"Preference|S3S2", "Preference|VS3", "TCO sales Operating costs (total non-fuel)", "TCO sales Fuel costs", "TCO sales Capital costs", "Time value costs",
"Annual mileage", "Energy intensity sales", "Energy intensity sales raw", "Purchase Price")
"Annual mileage", "Energy intensity sales", "Energy intensity (raw)", "Purchase Price", "Load factor (raw)")

aggregatedvars <- createVariableEntry(vars[variable %in% exclude | grepl(".*Iteration.*", variable)], aggrOrder)
vars <- vars[!(variable %in% exclude | grepl(".*Iteration.*", variable))]
Expand Down Expand Up @@ -292,8 +292,8 @@ aggregateVariables <- function(vars, mapAggregation, weight = NULL) {
aggregatedvars <- rbind(aggregatedvars, aggrvars)

if (anyNA(aggregatedvars)) stop("Output variable contains NAs.
Please check reportAndAggregatedMIF()")
Please check aggregateVariables()")
if (anyDuplicated(aggregatedvars[, c("region", "period", "variable")])) stop("Output variable contains Duplicates.
Please check reportAndAggregatedMIF()")
Please check aggregateVariables()")
return(aggregatedvars)
}
10 changes: 7 additions & 3 deletions R/convertToMIF.R
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ convertToMIF <- function(vars, GDPMER, helpers, scenario, model, gdx, isTranspo
return(varsNew)
}

noAggregationvars <- rbindlist(vars$int[c("GDPpcPPP", "GDPpcMER")], fill = TRUE, use.names = TRUE)
varsToMIFint <- rbindlist(vars$int[!names(vars$int) %in% c("GDPpcPPP", "GDPpcMER")], fill = TRUE, use.names = TRUE)
varsToMIFext <- rbindlist(vars$ext[!names(vars$ext) %in% c("GDPppp", "population", "GDPMER")], fill = TRUE, use.names = TRUE)

# Regional aggregation----------------------------------------------------------------------
## Aggregation to world is always supplied
mapWorld <- unique(vars$ext[[1]][, c("region")])[, aggrReg := "World"]
Expand Down Expand Up @@ -120,18 +124,18 @@ convertToMIF <- function(vars, GDPMER, helpers, scenario, model, gdx, isTranspo
setnames(regSubsetDataInt, "aggrReg", "region")
return(regSubsetDataInt)}, regSubsetMap, weight)

noAggregationvars <- rbind(rbindlist(vars$int[c("GDPpcPPP", "GDPpcMER")], fill = TRUE, use.names = TRUE),
noAggregationvars <- rbind(noAggregationvars,
rbindlist(regSubsetDataInt[c("GDPpcPPP", "GDPpcMER")], fill = TRUE, use.names = TRUE),
rbindlist(worldDataInt[c("GDPpcPPP", "GDPpcMER")], fill = TRUE, use.names = TRUE),
rbindlist(vars$ext[c("GDPppp", "population", "GDPMER")], fill = TRUE, use.names = TRUE),
rbindlist(regSubsetDataExt[c("GDPppp", "population", "GDPMER")], fill = TRUE, use.names = TRUE),
rbindlist(worldDataExt[c("GDPppp", "population", "GDPMER")], fill = TRUE, use.names = TRUE))

varsToMIFint <- rbind(rbindlist(vars$int[!names(vars$int) %in% c("GDPpcPPP", "GDPpcMER")], fill = TRUE, use.names = TRUE),
varsToMIFint <- rbind(varsToMIFint,
rbindlist(regSubsetDataInt[!names(regSubsetDataInt) %in% c("GDPpcPPP", "GDPpcMER")], fill = TRUE, use.names = TRUE),
rbindlist(worldDataInt[!names(worldDataInt) %in% c("GDPpcPPP", "GDPpcMER")], fill = TRUE, use.names = TRUE))

varsToMIFext <- rbind(rbindlist(vars$ext[!names(vars$ext) %in% c("GDPppp", "population", "GDPMER")], fill = TRUE, use.names = TRUE),
varsToMIFext <- rbind(varsToMIFext,
rbindlist(regSubsetDataExt[!names(regSubsetDataExt) %in% c("GDPppp", "population", "GDPMER")], fill = TRUE, use.names = TRUE),
rbindlist(worldDataExt[!names(worldDataExt) %in% c("GDPppp", "population", "GDPMER")], fill = TRUE, use.names = TRUE))
}
Expand Down
65 changes: 39 additions & 26 deletions R/reportExtendedTransportVarSet.R
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ reportExtendedTransportVarSet <- function(data, baseVarSet, timeResReporting) {

constrYear <- variable <- period <- . <- value <- NULL

outputVarsExt <- list()
outputVarsInt <- list()

# Report useful energy-----------------------------------------------------------------------
fleetUEdemand <- reportUE(FEdemand = baseVarSet$ext$fleetFEdemand,
helpers = data$helpers)
Expand All @@ -36,41 +39,51 @@ reportExtendedTransportVarSet <- function(data, baseVarSet, timeResReporting) {
names(data$helpers$decisionTree)))
combinedCAPEXandOPEX[, variable := paste0("TCO sales ", variable)]

data$GDPppp[, variable := "GDP|PPP"][, value := value * 1e-3][, unit := "billion constant 2017 Int$PPP"]
data$population[, variable := "Population"][, unit := "million"]
data$GDPpcPPP[, variable := "GDPpc|PPP"][, value := value * 1e-3][, unit := "billion constant 2017 Int$PPP"]
data$GDPMER[, variable := "GDP|MER"][, value := value * 1e-3][, unit := "billion constant 2017 Int$MER"]
data$GDPpcMER[, variable := "GDPpc|MER"][, value := value * 1e-3][, unit := "billion constant 2017 Int$MER"]
if (!is.null(data$GDPppp)) {
data$GDPppp[grepl("mil\\..*", unit), value := value * 1e-3][, unit := gsub("mil\\.", "billion", unit)]
outputVarsExt <- c(outputVarsExt, list(GDPppp = data$GDPppp))
}
if (!is.null(data$GDPpcPPP)) {
data$GDPpcPPP[grepl("mil\\..*", unit), value := value * 1e-3][, unit := gsub("mil\\.", "billion", unit)]
outputVarsInt <- c(outputVarsInt, list(GDPpcPPP = data$GDPpcPPP))
}
if (!is.null(data$GDPMER)) {
data$GDPMER[grepl("mil\\..*", unit), value := value * 1e-3][, unit := gsub("mil\\.", "billion", unit)]
outputVarsExt <- c(outputVarsExt, list(GDPMER = data$GDPMER))
}
if (!is.null(data$GDPpcMER)) {
data$GDPpcMER[grepl("mil\\..*", unit), value := value * 1e-3][, unit := gsub("mil\\.", "billion", unit)]
outputVarsInt <- c(outputVarsInt, list(GDPpcMER = data$GDPpcMER))
}
if (!is.null(data$population)) {
outputVarsExt <- c(outputVarsExt, list(population = data$population))
}

# Report transport input data if available
inputData <- c("CAPEXother", "nonFuelOPEXtrackedFleet", "subsidies", "timeValueCosts", "annualMileage", "scenSpecLoadFactor",
inputData <- c("timeValueCosts", "annualMileage", "scenSpecLoadFactor",
"loadFactorRaw", "scenSpecEnIntensity", "energyIntensityRaw")
inputData <- inputData[inputData %in% names(data)]
inputData <- lapply(copy(data[inputData]), function(item, decisionTree) {item <- merge(item, decisionTree,

if (!is.null(inputData)) {
inputData <- lapply(copy(data[inputData]), function(item, decisionTree) {item <- merge(item, decisionTree,
by = intersect(names(item),
names(decisionTree)), allow.cartesian = TRUE)},
data$helpers$decisionTree)
inputData$loadFactorRaw[, variable := paste0(variable, " raw")]
inputData$energyIntensityRaw[, variable := paste0(variable, " raw")]
outputVarsInt <- c(outputVarsInt, inputData)
}



# Split extensive and intensive variables ---------------------------------------------------
outputVarsExt <- list(fleetUEdemand = fleetUEdemand,
vintages = vintages,
GDPppp = data$GDPppp,
GDPMER = data$GDPMER,
population = data$population)
outputVarsInt <- list(scenScpecPrefTrends = data$scenSpecPrefTrends[, level := NULL],
combinedCAPEXandOPEX = combinedCAPEXandOPEX,
CAPEXother = inputData$CAPEXother,
nonFuelOPEXtrackedFleet = inputData$nonFuelOPEXtrackedFleet,
timeValueCosts = inputData$timeValueCosts,
annualMileage = inputData$annualMileage,
loadFactor = inputData$scenSpecLoadFactor,
loadFactorRaw = inputData$loadFactorRaw,
energyIntensity = inputData$scenSpecEnIntensity,
energyIntensityRaw = inputData$energyIntensityRaw,
GDPpcPPP = data$GDPpcPPP,
GDPpcMER = data$GDPpcMER)
outputVarsExt <- c(outputVarsExt,
list(fleetUEdemand = fleetUEdemand,
vintages = vintages)
)

outputVarsInt <- c(outputVarsInt,
list(scenScpecPrefTrends = data$scenSpecPrefTrends[, level := NULL],
combinedCAPEXandOPEX = combinedCAPEXandOPEX)
)
outputVars <- list(ext = outputVarsExt,
int = outputVarsInt)
return(outputVars)
Expand Down
4 changes: 2 additions & 2 deletions R/reportTransportVarSet.R
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,8 @@ reportTransportVarSet <- function(data, baseVarSet) {
sales = sales,
stock = data$fleetSizeAndComposition$fleetVehNumbers,
fleetYrlCosts = fleetYrlCosts)
outputVarsInt <- list(upfrontCAPEXtrackedFleet = upfrontCAPEXtrackedFleet,
fleetEnergyIntensity = baseVarSet$int$fleetEnergyIntensity)
outputVarsInt <- list(fleetEnergyIntensity = baseVarSet$int$fleetEnergyIntensity)
if (!is.null(data$upfrontCAPEXtrackedFleet)) outputVarsInt <- c(outputVarsInt, list(upfrontCAPEXtrackedFleet = upfrontCAPEXtrackedFleet))
outputVars <- list(ext = outputVarsExt,
int = outputVarsInt)

Expand Down
8 changes: 4 additions & 4 deletions inst/compareScenarios/cs_06_input_parameters.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ showTransportInputMultiLinePlots <- function(data, vars, scales = "free_y", nrow
#### Pass other
```{r}
vars <- as.character(unique(data$variable))
items <- vars[grepl("Load factor raw\\|.*", vars)]
items <- vars[grepl("Load factor (raw)\\|.*", vars)]
itemsSplit <- items[grepl(".*Pass.*", items) & !grepl(".*Four Wheelers.*|.*Two Wheelers.*|.*Non-motorized.*", items)]
plotData <- data %>%
filter(variable %in% itemsSplit) %>%
Expand Down Expand Up @@ -114,11 +114,11 @@ showTransportInputMultiLinePlots(plotData, itemsSplit, nrowNum = ceiling(length(
### Energy intensity
#### Pass other
```{r}
items <- vars[grepl("Energy intensity sales raw\\|.*", vars)]
items <- vars[grepl("Energy intensity (raw)\\|.*", vars)]
itemsSplit <- items[grepl(".*Pass.*", items) & !grepl(".*Four Wheelers.*|.*Two Wheelers.*|.*Non-motorized.*", items)]
plotData <- data %>%
filter(variable %in% itemsSplit) %>%
mutate(variable = gsub("(Energy intensity raw|\\|Transport|\\|Pass\\||\\|Bunkers)", "", variable))
mutate(variable = gsub("(Energy intensity (raw)|\\|Transport|\\|Pass\\||\\|Bunkers)", "", variable))
itemsSplit <- unique(plotData$variable)
showTransportInputMultiLinePlots(plotData, itemsSplit, nrowNum = ceiling(length(itemsSplit) / 5))
```
Expand Down Expand Up @@ -451,7 +451,7 @@ showTransportInputMultiLinePlots(plotData, itemsSplit, nrowNum = ceiling(length(
```{r}
items <- vars[grepl("Energy intensity sales\\|.*", vars)]
itemsSplit <- items[grepl(".*Pass.*", items) & !grepl(".*Four Wheelers.*", items) & !grepl(".*Two Wheelers.*", items)& !grepl(".*Non-motorized.*", items)]
plotData <- data %>% filter(variable %in% itemsSplit) %>% mutate(variable = gsub("(Energy intensity|\\|Transport|\\|Pass\\||\\|Bunkers)", "", variable))
plotData <- data %>% filter(variable %in% itemsSplit) %>% mutate(variable = gsub("(Energy intensity sales|\\|Transport|\\|Pass\\||\\|Bunkers)", "", variable))
itemsSplit <- as.character(unique(plotData$variable))
showTransportInputMultiLinePlots(plotData, itemsSplit, nrowNum = ceiling(length(itemsSplit )/5))
```
Expand Down

0 comments on commit 2bb86ce

Please sign in to comment.