Skip to content

Commit

Permalink
fix function calls in readEurostat
Browse files Browse the repository at this point in the history
  • Loading branch information
fbenke-pik committed Nov 8, 2024
1 parent c2641f5 commit f8e499d
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 527 deletions.
16 changes: 0 additions & 16 deletions R/convertUNFCCC.R

This file was deleted.

21 changes: 9 additions & 12 deletions R/readEurostat.R
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ readEurostat <- function(subtype = "emissions") {
"emissions" = readEurostatEmissions(),
"MACCemi" = readEurostatEmissions(),
"sectorEmi" = readEurostatEmissions(),
"latest" = readEurstatEmissionsLatest(),
"latest" = readEurostatEmissionsLatest(),
stop("Bad input for readEurostat. Invalid 'subtype' argument.")
)
}
Expand Down Expand Up @@ -54,14 +54,6 @@ readEurostatEmissions <- function() {
# Reading Eurostat latest historical emissions from 2024
readEurostatEmissionsLatest <- function() {

# read in GBR values from 2019 database ----
gbr <- readEurostatEmissions2019()["GBR", , ]
gbr <- add_columns(gbr, addnm = c("y2020", "y2021", "y2022"), dim = "period", fill = NA)

# convert CH4 and N2O to use AR5 GWP values instead of AR4
gbr[, , "CH4"] <- gbr[, , "CH4"] * 28 / 25
gbr[, , "N2O"] <- gbr[, , "N2O"] * 265 / 298

# read in latest Eurostat data from 2024 ----
df <- read.csv(file.path("2024", "env_air_gge_linear.csv")) %>%
filter(.data$unit == "MIO_T", .data$geo != "EU27_2020") %>%
Expand All @@ -79,9 +71,14 @@ readEurostatEmissionsLatest <- function() {
sectorMap <- sectorMap[match(getNames(x, dim = 2), sectorMap$crf), ]
getNames(x, dim = 2) <- sectorMap[, "label"]

for (i in sectorMap$crf) {
getNames(x[, , i], dim = 2) <- sectorMap[sectorMap$crf == i, "label"]
}
# read in GBR values from 2019 database ----
gbr <- readEurostatEmissions()["GBR", , ]
gbr <- add_columns(gbr, addnm = c("y2020", "y2021", "y2022"), dim = "period", fill = NA)

# convert CH4 and N2O to use AR5 GWP values instead of AR4
gbr[, , "CH4"] <- gbr[, , "CH4"] * 28 / 25
gbr[, , "N2O"] <- gbr[, , "N2O"] * 265 / 298

gbr <- magclass::matchDim(gbr, x, dim = 3)
return(mbind(x, gbr))
}
Loading

0 comments on commit f8e499d

Please sign in to comment.