diff --git a/.buildlibrary b/.buildlibrary index f1f4899d0..0a4be0679 100644 --- a/.buildlibrary +++ b/.buildlibrary @@ -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' diff --git a/.zenodo.json b/.zenodo.json index 627eecd0c..7805469c6 100644 --- a/.zenodo.json +++ b/.zenodo.json @@ -1,6 +1,6 @@ { "title": "mrmagpie: madrat based MAgPIE Input Data Library", - "version": "0.29.1", + "version": "0.29.2", "description": "
Provides functions for MAgPIE country and cellular input data generation.<\/p>",
"creators": [
{
diff --git a/DESCRIPTION b/DESCRIPTION
index cec50cf9f..13dbffe53 100644
--- a/DESCRIPTION
+++ b/DESCRIPTION
@@ -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 = "karstens@pik-potsdam.de", role = c("aut","cre")),
person("Jan Philipp", "Dietrich", email = "dietrich@pik-potsdam.de", role = "aut"),
diff --git a/NAMESPACE b/NAMESPACE
index 589b2957c..fdc93b203 100644
--- a/NAMESPACE
+++ b/NAMESPACE
@@ -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)
@@ -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)
diff --git a/R/readIPCCClimate.R b/R/readIPCCClimate.R
index 47f2d42da..9f1984243 100644
--- a/R/readIPCCClimate.R
+++ b/R/readIPCCClimate.R
@@ -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)
diff --git a/README.md b/README.md
index dcfc0d99b..501ad2a3a 100644
--- a/README.md
+++ b/README.md
@@ -1,6 +1,6 @@
# madrat based MAgPIE Input Data Library
-R package **mrmagpie**, version **0.29.1**
+R package **mrmagpie**, version **0.29.2**
@@ -39,7 +39,7 @@ In case of questions / problems please contact Kristine Karstens