Skip to content

Commit

Permalink
Merge pull request #445 from fbenke-pik/refactoring
Browse files Browse the repository at this point in the history
move calc functions from calcHistorical to appropriate retrieve function
  • Loading branch information
fbenke-pik authored Nov 13, 2023
2 parents 9f76aea + 3287687 commit 510d6b0
Show file tree
Hide file tree
Showing 22 changed files with 246 additions and 226 deletions.
2 changes: 1 addition & 1 deletion .buildlibrary
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
ValidationKey: '33623730'
ValidationKey: '33681888'
AcceptedWarnings:
- 'Warning: package ''.*'' was built under R version'
- 'Warning: namespace ''.*'' is not available and has been replaced'
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/check.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ jobs:
- uses: r-lib/actions/setup-r-dependencies@v2
with:
extra-packages: |
gamstransfer=?ignore
any::lucode2
any::covr
any::madrat
Expand Down
4 changes: 2 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
exclude: '^tests/testthat/_snaps/.*$'
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
rev: v4.5.0
hooks:
- id: check-case-conflict
- id: check-json
Expand All @@ -15,7 +15,7 @@ repos:
- id: mixed-line-ending

- repo: https://github.com/lorenzwalthert/precommit
rev: v0.3.2.9021
rev: v0.3.2.9025
hooks:
- id: parsable-R
- id: deps-in-desc
Expand Down
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.171.0
date-released: '2023-11-02'
version: 0.171.2
date-released: '2023-11-13'
abstract: The mrremind packages contains data preprocessing for the REMIND model.
authors:
- family-names: Baumstark
Expand Down
8 changes: 4 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.171.0
Date: 2023-11-02
Version: 0.171.2
Date: 2023-11-13
Authors@R: c(
person("Lavinia", "Baumstark", , "[email protected]", role = c("aut", "cre")),
person("Renato", "Rodrigues", role = "aut"),
Expand Down Expand Up @@ -38,8 +38,8 @@ License: LGPL-3 | file LICENSE
URL: https://github.com/pik-piam/mrremind
Depends:
R (>= 2.10.0),
madrat (>= 2.5.1),
magclass (>= 3.17),
madrat (>= 3.7.1),
magclass (>= 6.11.3),
mrdrivers (>= 1.0.0),
mrcommons (>= 1.33.3),
edgeTransport (>= 0.17.0)
Expand Down
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ export(readworldsteel)
export(toolBiomassSupplyAggregate)
export(toolCubicFunctionAggregate)
export(toolCubicFunctionDisaggregate)
export(toolFillEU34Countries)
export(toolSolarFunctionAggregate)
export(tool_expand_tibble)
import(edgeTransport)
Expand Down
4 changes: 0 additions & 4 deletions R/UNIDO.R
Original file line number Diff line number Diff line change
Expand Up @@ -308,10 +308,6 @@ calcUNIDO <- function(subtype = 'INDSTAT2')

getNames(x) <- variable_names[match(getNames(x), subsector_names)]

x <- x %>%
add_dimension(dim = 3.1, add = 'model', nm = 'INDSTAT2') %>%
add_dimension(dim = 3.2, add = 'scenario', nm = 'historical')

return(list(x = x,
weight = NULL,
unit = 'billion US$2005/yr',
Expand Down
3 changes: 0 additions & 3 deletions R/calcAGEB.R
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,6 @@ calcAGEB <- function(subtype = "balances") {
as.magpie() %>%
toolCountryFill(fill = NA, verbosity = 2)

x <- add_dimension(x, dim = 3.1, add = "scenario", nm = "historical")
x <- add_dimension(x, dim = 3.2, add = "model", nm = "AGEB")

return(list(
x = x, weight = NULL, unit = "EJ/yr",
description = "Historical AGEB values as REMIND variables"
Expand Down
20 changes: 10 additions & 10 deletions R/calcBP.R
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,14 @@ calcBP <- function() {
) %>%
return()
}

# Emission
data <- .convert(readSource("BP", subtype = "Emission"))

# Capacity
data <- rbind(data, .convert(readSource("BP", subtype = "Capacity")))
# Generation

# Generation
data <- rbind(data, .convert(readSource("BP", subtype = "Generation")))

# Consumption
Expand All @@ -62,7 +62,7 @@ calcBP <- function() {
as.magpie() %>%
dimReduce()
renewables.vars <- c("Solar Consumption (EJ)", "Wind Consumption (EJ)", "Nuclear Consumption (EJ)", "Hydro Consumption (EJ)")

# recalculate renewables to direct equivalent accounting
consumption.renewables <- consumption[, , renewables.vars] * renewables.factors

Expand All @@ -86,21 +86,21 @@ calcBP <- function() {
.convert(consumption.renewables),
.convert(consumption.pe)
)

# Trade

# calculate net oil trade
trade.oil <- readSource("BP", subtype = "Trade Oil")
trade.oil.net <- trade.oil[, , "Trade|Export|Oil (kb/d)"] - trade.oil[, , "Trade|Import|Oil (kb/d)"]
getNames(trade.oil.net) <- c("Net Trade|Oil (kb/d)")
getSets(trade.oil.net) <- c("region", "year", "data")

# calculate net coal trade
trade.coal <- readSource("BP", subtype = "Trade Coal")
trade.coal.net <- trade.coal[, , "Trade|Export|Coal (EJ)"] - trade.coal[, , "Trade|Import|Coal (EJ)"]
getNames(trade.coal.net) <- c("Net Trade|Coal (EJ)")
getSets(trade.coal.net) <- c("region", "year", "data")

# calculate net gas trade
trade.gas <- readSource("BP", subtype = "Trade Gas")
trade.gas.net <- trade.gas[, , "Trade|Export|Gas (bcm)"] - trade.gas[, , "Trade|Import|Gas (bcm)"]
Expand All @@ -118,7 +118,7 @@ calcBP <- function() {
)

# Trade

p <- readSource("BP", subtype = "Price")
data <- rbind(data, .convert(p))

Expand All @@ -143,9 +143,9 @@ calcBP <- function() {
weights[,,"US$2005/GJ", pmatch = T] <- 1

return(list(
x = x,
x = x,
weight = weights,
mixed_aggregation = T,
mixed_aggregation = T,
unit = c("Mt CO2/yr", "GW", "EJ/yr", "US$2005/GJ"),
description = "Historical BP values as REMIND variables"
))
Expand Down
1 change: 0 additions & 1 deletion R/calcGlobalEnergyMonitor.R
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
calcGlobalEnergyMonitor <- function() {

x <- readSource("GlobalEnergyMonitor")
x <- add_dimension(x, dim = 3.1, add = "scenario", nm = "historical")

return(list(
x = x,
Expand Down
Loading

0 comments on commit 510d6b0

Please sign in to comment.