Skip to content

Commit

Permalink
Merge pull request #30 from ahagen-pik/moveSubsidies
Browse files Browse the repository at this point in the history
move preparation of subsidies data to mrtransport
  • Loading branch information
ahagen-pik authored Jan 8, 2025
2 parents 07b76d2 + 4a7ecae commit f5f2b49
Show file tree
Hide file tree
Showing 7 changed files with 71 additions and 9 deletions.
2 changes: 1 addition & 1 deletion .buildlibrary
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
ValidationKey: '2027575'
ValidationKey: '2047752'
AutocreateReadme: yes
AcceptedWarnings:
- 'Warning: package ''.*'' was built under R version'
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: 'mrtransport: Input data generation for the EDGE-Transport model'
version: 0.10.1
date-released: '2024-12-18'
version: 0.10.2
date-released: '2024-12-19'
abstract: The mrtransport package contains data preprocessing for the EDGE-Transport
model.
authors:
Expand Down
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: mrtransport
Title: Input data generation for the EDGE-Transport model
Version: 0.10.1
Version: 0.10.2
Authors@R: c(
person("Johanna", "Hoppe", , "[email protected]", role = c("aut", "cre"),
comment = c(ORCID = "0009-0004-6753-5090")),
Expand Down Expand Up @@ -33,4 +33,4 @@ Imports:
tidyselect,
utils,
zoo
Date: 2024-12-18
Date: 2024-12-19
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export(toolPrepareEurostatEnergyCountryDataSheets)
export(toolPrepareGCAM)
export(toolPreparePSI)
export(toolPreparePurchasePriceSubsidies)
export(toolPrepareTransportSubsidies)
export(toolPrepareUCD)
import(GDPuc)
import(data.table)
Expand Down
40 changes: 40 additions & 0 deletions R/toolPrepareTransportSubsidies.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#' Prepare subsidies data
#' @param helpers list containg several helpers used throughout the model.
#' It includes dtTimeRes, a data.table containing the temporal
#' resolution for different univocalNames
#' @returns list of data.tables containing mrremind input data
#' @importFrom rmndt magpie2dt
#' @export

toolPrepareTransportSubsidies <- function(helpers) {
# bind variables locally to prevent NSE notes in R CMD CHECK
period <- value <- subsectorL3 <- variable <- unit <- . <- NULL

yrs <- unique(helpers$dtTimeRes$period)

subsidies <- magpie2dt(readSource(type = "TransportSubsidies"))
setnames(subsidies, "variable", "technology")
# average between legal and private entities
subsidies <- subsidies[, .(value = mean(value)), by = c("region", "period", "technology")]
subsidies[, value := -value] # count subsidies negative
completeSub <- unique(subsidies[, c("region", "technology")])[, temporal := "all"]
temporal <- data.table(period = yrs)[, temporal := "all"]
completeSub <- merge(completeSub, temporal, by = "temporal", allow.cartesian = TRUE)[, temporal := NULL]
subsidies <- merge(subsidies, completeSub, all.y = TRUE, by = c("region", "technology", "period"))

## year where complete phase-out incentives occurs
yearOut <- 2030
## attribute first (to the countries that have them) the same incentives value until the phase out year
subsidies[, value := ifelse(period >= 2020 & period <= yearOut, value[period == 2020], 0),
by = c("region", "technology")]

# map on decision tree, apply only on 4 wheelers
subsidies <- merge(unique(helpers$decisionTree[subsectorL3 == "trn_pass_road_LDV_4W",
c("region", "univocalName", "technology")]), subsidies,
by = c("region", "technology"), all.x = TRUE, allow.cartesian = TRUE)
monUnit <- gsub(".*?(\\d{4}).*", "US$\\1", mrdrivers::toolGetUnitDollar())
subsidies <- subsidies[!is.na(value)][, variable := "Capital costs subsidy"][, unit := paste0(monUnit, "/veh")]
# Q: How to include phase out of the incentives? Is that needed at all?

return(subsidies)
}
10 changes: 6 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Input data generation for the EDGE-Transport model

R package **mrtransport**, version **0.10.1**
R package **mrtransport**, version **0.10.2**

[![CRAN status](https://www.r-pkg.org/badges/version/mrtransport)](https://cran.r-project.org/package=mrtransport) [![R build status](https://github.com/pik-piam/mrtransport/workflows/check/badge.svg)](https://github.com/pik-piam/mrtransport/actions) [![codecov](https://codecov.io/gh/pik-piam/mrtransport/branch/master/graph/badge.svg)](https://app.codecov.io/gh/pik-piam/mrtransport) [![r-universe](https://pik-piam.r-universe.dev/badges/mrtransport)](https://pik-piam.r-universe.dev/builds)

Expand Down Expand Up @@ -39,15 +39,17 @@ In case of questions / problems please contact Johanna Hoppe <johanna.hoppe@pik-

To cite package **mrtransport** in publications use:

Hoppe J, Muessel J, Dirnaichner A (2024). "mrtransport: Input data generation for the EDGE-Transport model - Version 0.10.1."
Hoppe J, Muessel J, Dirnaichner A (2024). "mrtransport: Input data generation for the EDGE-Transport model." Version: 0.10.2, <https://github.com/pik-piam/mrtransport>.

A BibTeX entry for LaTeX users is

```latex
@Misc{,
title = {mrtransport: Input data generation for the EDGE-Transport model - Version 0.10.1},
title = {mrtransport: Input data generation for the EDGE-Transport model},
author = {Johanna Hoppe and Jarusch Muessel and Alois Dirnaichner},
date = {2024-12-18},
date = {2024-12-19},
year = {2024},
url = {https://github.com/pik-piam/mrtransport},
note = {Version: 0.10.2},
}
```
19 changes: 19 additions & 0 deletions man/toolPrepareTransportSubsidies.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit f5f2b49

Please sign in to comment.