-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' of https://github.com/pik-piam/mrmagpie
- Loading branch information
Showing
79 changed files
with
845 additions
and
563 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,3 +9,4 @@ | |
^.lintr$ | ||
^tests/.lintr$ | ||
^Makefile$ | ||
^.*CITATION.cff$ |
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 was deleted.
Oops, something went wrong.
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,39 @@ | ||
cff-version: 1.2.0 | ||
message: If you use this software, please cite it using the metadata from this file. | ||
type: software | ||
title: 'mrmagpie: madrat based MAgPIE Input Data Library' | ||
version: 1.35.7 | ||
date-released: '2023-07-06' | ||
abstract: Provides functions for MAgPIE country and cellular input data generation. | ||
authors: | ||
- family-names: Karstens | ||
given-names: Kristine | ||
email: [email protected] | ||
- family-names: Dietrich | ||
given-names: Jan Philipp | ||
email: [email protected] | ||
- family-names: Chen | ||
given-names: David | ||
- family-names: Windisch | ||
given-names: Michael | ||
- family-names: Alves | ||
given-names: Marcos | ||
- family-names: Beier | ||
given-names: Felicitas | ||
email: [email protected] | ||
- family-names: v. Jeetze | ||
given-names: Patrick | ||
email: [email protected] | ||
- family-names: Mishra | ||
given-names: Abhijeet | ||
email: [email protected] | ||
- family-names: Humpenoeder | ||
given-names: Florian | ||
email: [email protected] | ||
- family-names: Führlich | ||
given-names: Pascal | ||
email: [email protected] | ||
license: LGPL-3.0 | ||
repository-code: https://github.com/pik-piam/mrmagpie | ||
doi: 10.5281/zenodo.4319612 | ||
|
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 @@ | ||
Type: Package | ||
Package: mrmagpie | ||
Title: madrat based MAgPIE Input Data Library | ||
Version: 1.35.1 | ||
Date: 2023-03-15 | ||
Version: 1.35.7 | ||
Date: 2023-07-06 | ||
Authors@R: c( | ||
person("Kristine", "Karstens", , "[email protected]", role = c("aut", "cre")), | ||
person("Jan Philipp", "Dietrich", , "[email protected]", role = "aut"), | ||
|
@@ -45,7 +45,7 @@ Imports: | |
readxl, | ||
stats, | ||
stringr, | ||
terra, | ||
terra (>= 1.7.18), | ||
tidyr, | ||
withr | ||
Suggests: | ||
|
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
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,112 @@ | ||
#' @title calcAreaEquippedForIrrigation | ||
#' @description Calculates the area equipped for irrigation based on LU2v2 or | ||
#' Mehta data sets. | ||
#' For LUH2v2, it assumes, that all cropland irrigated in the last | ||
#' 20 years at least once is equipped for irrigation. | ||
#' Mehta et al. (2022) directly report Global Area Equipped for | ||
#' Irrigation for the years 1900-2015 | ||
#' | ||
#' @param cellular if TRUE: 0.5 degree resolution returned | ||
#' @param cells number of cells to be returned: magpiecell (59199), lpjcell (67420) | ||
#' @param selectyears default on "past" | ||
#' | ||
#' @return List of magpie objects with results on country/cellular level, | ||
#' weight on country level, unit and description. | ||
#' | ||
#' @author Benjamin Leon Bodirsky, Kristine Karstens, Felicitas Beier | ||
#' | ||
#' @seealso | ||
#' [calcLanduseInitialisation()] | ||
#' @examples | ||
#' \dontrun{ | ||
#' calcOutput("AreaEquippedForIrrigation", source = "LUH2v2", cellular = TRUE, aggregate = FALSE) | ||
#' } | ||
#' @importFrom magpiesets findset | ||
#' | ||
#' @export | ||
|
||
calcAreaEquippedForIrrigation <- function(cellular = FALSE, | ||
cells = "magpiecell", | ||
selectyears = "past") { | ||
|
||
selectyears <- sort(findset(selectyears, noset = "original")) | ||
|
||
########################################## | ||
### Read in LUH2v2 irrigated area data ### | ||
########################################## | ||
yearsNeeded <- as.integer(substring(selectyears, 2)) | ||
yearsNeeded <- (yearsNeeded[1] - 20):tail(yearsNeeded, 1) | ||
|
||
x <- collapseNames(calcOutput("LUH2v2", | ||
landuse_types = "magpie", | ||
irrigation = TRUE, | ||
cellular = TRUE, cells = "lpjcell", | ||
selectyears = yearsNeeded, | ||
aggregate = FALSE)[, , "irrigated"]) | ||
x <- dimSums(x, dim = 3) | ||
years <- as.numeric(substring(selectyears, 2)) | ||
luh <- NULL | ||
|
||
# Cropland that it is irrigated at least once in the last 20 years | ||
# is defined as "equipped for irrigation" | ||
for (year in years) { | ||
span <- (year - 20):year | ||
tmp <- setYears(as.magpie(apply(X = x[, span, ], FUN = max, MARGIN = 1), | ||
spatial = 1), | ||
paste0("y", year)) | ||
luh <- mbind(luh, tmp) | ||
} | ||
|
||
# Naming of first dimension: | ||
# Temporarily (until 67k preprocessing merged) | ||
mapping <- toolGetMappingCoord2Country(pretty = TRUE) | ||
getItems(luh, dim = 1, raw = TRUE) <- paste(mapping$coords, mapping$iso, sep = ".") | ||
# Temporarily (until 67k preprocessing merged) | ||
|
||
# rename sets | ||
getSets(luh) <- c("x", "y", "iso", "year", "data") | ||
|
||
# rename data dimension | ||
getItems(luh, dim = 3) <- "LUH2v2" | ||
|
||
######################################## | ||
### Read in Mehta et al. (2022) data ### | ||
######################################## | ||
mehta <- readSource("Mehta2022", convert = "onlycorrect") | ||
years <- intersect(getItems(mehta, dim = 2), selectyears) | ||
mehta <- mehta[, years, ] | ||
getItems(mehta, dim = 3) <- "Mehta2022" | ||
|
||
######################### | ||
### Combine data sets ### | ||
######################### | ||
years <- intersect(getItems(luh, dim = 2), getItems(mehta, dim = 2)) | ||
out <- mbind(luh[, years, ], mehta[, years, ]) | ||
|
||
############## | ||
### Output ### | ||
############## | ||
# reduce to 59k cells | ||
if (cells == "magpiecell") { | ||
out <- toolCoord2Isocell(out) | ||
} | ||
|
||
# aggregate to iso level | ||
if (!cellular) { | ||
if (length(getItems(out, dim = 1)) == 67420) { | ||
out <- dimSums(out, dim = c("x", "y")) | ||
} else { | ||
mapping <- toolGetMapping(name = "CountryToCellMapping.rds", | ||
where = "mrcommons") | ||
out <- toolAggregate(out, rel = mapping, | ||
from = "celliso", to = "iso", dim = 1) | ||
} | ||
out <- toolCountryFill(out, fill = 0) | ||
} | ||
|
||
return(list(x = out, | ||
weight = NULL, | ||
unit = "Million ha", | ||
description = "Area equipped for irrigation", | ||
isocountries = !cellular)) | ||
} |
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
Oops, something went wrong.