-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
IPCC climate class source + enable calcClimateClass to process it
- Loading branch information
Showing
13 changed files
with
207 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,8 @@ | ||
Package: mrmagpie | ||
Type: Package | ||
Title: madrat based MAgPIE Input Data Library | ||
Version: 0.28.0 | ||
Date: 2020-12-11 | ||
Version: 0.29.0 | ||
Date: 2020-12-12 | ||
Authors@R: c(person("Kristine", "Karstens", email = "[email protected]", role = c("aut","cre")), | ||
person("Jan Philipp", "Dietrich", email = "[email protected]", role = "aut"), | ||
person("David", "Chen", role = "aut"), | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
#' @title correctIPCCClimate | ||
#' @description Correct IPCC climate classification | ||
#' | ||
#' @return Magpie object with results on cellular level for 12 IPCC climate zone types | ||
#' @param x magpie object provided by the read function | ||
#' @author Kristine Karstens | ||
#' @examples | ||
#' | ||
#' \dontrun{ | ||
#' readSource("IPCCClimate", convert="onlycorrect") | ||
#' } | ||
|
||
correctIPCCClimate <- function(x){ | ||
|
||
### determine gaps on iso level | ||
iso <- unique(substring(where(setYears(x[,,"NA"], "y2010")==1)$true$reg,1,3)) | ||
|
||
## move unknown cells to most common country values | ||
nmax <- rep(0,length(iso)) | ||
names(nmax) <- iso | ||
for(i in iso){ | ||
nmax[i] <- which.max(dimSums((x[i,,]), dim=1)) | ||
x[i,,nmax[i]] <- x[i,,nmax[i]] + x[i,,"NA"] | ||
} | ||
|
||
if(any(x[,,"NA"]==1)) vcat(2,"Still grid cells without climate zone") | ||
out <- x[,,"NA",invert=TRUE] | ||
|
||
return(out) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
#' @title downloadIPCCClimate | ||
#' @description Download IPCC climate classification | ||
#' | ||
#' @return Meta information on downloaded data | ||
#' @author Kristine Karstens | ||
#' @examples | ||
#' | ||
#' \dontrun{ | ||
#' readSource("IPCCClimate", convert="onlycorrect") | ||
#' } | ||
#' | ||
#' @importFrom utils download.file unzip | ||
|
||
downloadIPCCClimate <- function() { | ||
|
||
# Define meta data | ||
meta <- list(title = "Thematic Data Layers for Commission Decision of [10 June 2010] on guidelines for the calculation of land carbon stocks for the purpose of Annex V to Directive 2009/28/EC", | ||
url = "https://esdac.jrc.ec.europa.eu/projects/RenewableEnergy/Data/Climate_Zone.zip") | ||
|
||
download.file(meta$url, destfile = "ipccclimate.zip") | ||
unzip("ipccclimate.zip") | ||
unlink("ipccclimate.zip") | ||
|
||
# Compose meta data by adding elements that are the same for all subtypes. | ||
return(list(url = meta$url, | ||
doi = NULL, | ||
title = meta$title, | ||
author = NULL, | ||
version = NULL, | ||
release_date = NULL, | ||
license = NULL, | ||
reference = NULL) | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
#' @title readIPCCClimate | ||
#' @description Read IPCC climate classification | ||
#' | ||
#' @return Magpie object with results on cellular level for 12 IPCC climate zone types | ||
#' @author Kristine Karstens | ||
#' @examples | ||
#' | ||
#' \dontrun{ | ||
#' readSource("IPCCClimate", convert="onlycorrect") | ||
#' } | ||
#' | ||
#' @importFrom raster raster aggregate extract | ||
|
||
readIPCCClimate <- function(){ | ||
|
||
raster_1d12 <- raster("CLIMATE_ZONE.rst") | ||
zone_names <- as.character(levels(raster_1d12)[[1]]$Class_name) | ||
raster_1d2 <- aggregate(raster_1d12, fact=6, fun=max) # to avoid gaps (since 0 is NA) | ||
|
||
map <- as.data.frame(magpie_coord) | ||
mag <- clean_magpie(as.magpie(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") | ||
|
||
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 <- mbind(out[,,zone_names],out[,,"NA"]) | ||
|
||
return(out) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.