Skip to content

Commit

Permalink
improve IPCCClimate by using modal of all non-zero cells for aggregation
Browse files Browse the repository at this point in the history
  • Loading branch information
k4rst3ns committed Dec 13, 2020
1 parent 0797bb7 commit 0e03dd0
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 11 deletions.
2 changes: 1 addition & 1 deletion .buildlibrary
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
ValidationKey: '5415219'
ValidationKey: '5433828'
AcceptedWarnings:
- 'Warning: package ''.*'' was built under R version'
- 'Warning: namespace ''.*'' is not available and has been replaced'
Expand Down
2 changes: 1 addition & 1 deletion .zenodo.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"title": "mrmagpie: madrat based MAgPIE Input Data Library",
"version": "0.29.1",
"version": "0.29.2",
"description": "<p>Provides functions for MAgPIE country and cellular input data generation.<\/p>",
"creators": [
{
Expand Down
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: mrmagpie
Type: Package
Title: madrat based MAgPIE Input Data Library
Version: 0.29.1
Version: 0.29.2
Date: 2020-12-13
Authors@R: c(person("Kristine", "Karstens", email = "[email protected]", role = c("aut","cre")),
person("Jan Philipp", "Dietrich", email = "[email protected]", role = "aut"),
Expand Down
2 changes: 2 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ importFrom(ncdf4,nc_open)
importFrom(ncdf4,ncatt_get)
importFrom(ncdf4,ncvar_get)
importFrom(raster,"extent<-")
importFrom(raster,"values<-")
importFrom(raster,aggregate)
importFrom(raster,area)
importFrom(raster,as.matrix)
Expand All @@ -85,6 +86,7 @@ importFrom(raster,raster)
importFrom(raster,rasterToPoints)
importFrom(raster,subset)
importFrom(raster,t)
importFrom(raster,values)
importFrom(raster,writeRaster)
importFrom(readxl,read_xls)
importFrom(stats,cutree)
Expand Down
11 changes: 6 additions & 5 deletions R/readIPCCClimate.R
Original file line number Diff line number Diff line change
Expand Up @@ -9,27 +9,28 @@
#' readSource("IPCCClimate", convert="onlycorrect")
#' }
#'
#' @importFrom raster raster aggregate extract levels
#' @importFrom raster raster aggregate extract levels values values<-

readIPCCClimate <- function(){

raster_1d12 <- raster("CLIMATE_ZONE.rst")
values(raster_1d12)[values(raster_1d12) == 0] <- NA
zone_names <- as.character(levels(raster_1d12)[[1]]$Class_name)
raster_1d2 <- raster::aggregate(raster_1d12, fact=6, fun=max) # to avoid gaps (since 0 is NA)
raster_1d2 <- raster::aggregate(raster_1d12, fact=6, fun="modal", na.rm=TRUE)

map <- as.data.frame(magpie_coord)
mag <- clean_magpie(as.magpie(raster::extract(raster_1d2,map), spatial=1))
#map[mag==0] <- 6
cellNames <- toolMappingFile(type="cell",name="CountryToCellMapping.csv",readcsv=TRUE)$celliso
getNames(mag) <- "NA"
getYears(mag) <- NULL
getCells(mag) <- cellNames
getSets(mag) <- c("country.cell","t","climatezone")
getSets(mag) <- c("country.cell","t","climatezone")
mag[is.na(mag)] <- 0

out <- add_columns(mag, dim=3.1, addnm=zone_names)
out[] <- 0
for(zone in c(zone_names)){out[,,zone][which(mag==which(zone_names==zone))] <- 1}
out[,,"NA"][which(dimSums(out, dim=3)==0)] <- 1
out[,,"NA"][which(dimSums(out[,,"NA",invert=TRUE], dim=3)==0)] <- 1
out <- mbind(out[,,zone_names],out[,,"NA"])

return(out)
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# madrat based MAgPIE Input Data Library

R package **mrmagpie**, version **0.29.1**
R package **mrmagpie**, version **0.29.2**



Expand Down Expand Up @@ -39,7 +39,7 @@ In case of questions / problems please contact Kristine Karstens <karstens@pik-p
To cite package **mrmagpie** in publications use:

Karstens K, Dietrich J, Chen D, Windisch M, Alves M, Beier F, v. Jeetze P, Mishra A, Humpenoeder F (2020). _mrmagpie: madrat based
MAgPIE Input Data Library_. R package version 0.29.1.
MAgPIE Input Data Library_. R package version 0.29.2.

A BibTeX entry for LaTeX users is

Expand All @@ -48,7 +48,7 @@ A BibTeX entry for LaTeX users is
title = {mrmagpie: madrat based MAgPIE Input Data Library},
author = {Kristine Karstens and Jan Philipp Dietrich and David Chen and Michael Windisch and Marcos Alves and Felicitas Beier and Patrick {v. Jeetze} and Abhijeet Mishra and Florian Humpenoeder},
year = {2020},
note = {R package version 0.29.1},
note = {R package version 0.29.2},
}
```

0 comments on commit 0e03dd0

Please sign in to comment.