-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Updated AEI validation data and lintering some functions
- Loading branch information
1 parent
4d78416
commit 038c158
Showing
10 changed files
with
88 additions
and
105 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 @@ | ||
Type: Package | ||
Package: mrvalidation | ||
Title: madrat data preparation for validation purposes | ||
Version: 2.56.12 | ||
Date: 2024-04-17 | ||
Version: 2.56.13 | ||
Date: 2024-04-25 | ||
Authors@R: c( | ||
person("Benjamin Leon", "Bodirsky", , "[email protected]", role = c("aut", "cre")), | ||
person("Stephen", "Wirth", 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,66 +1,57 @@ | ||
#'@title calcGMIA | ||
#' | ||
#' @title calcGMIA | ||
#' | ||
#' @description Filling gaps in the Historical area equipped for irrigation from GMIA. | ||
#' | ||
#' | ||
#' @return list of magpie object with data and weight | ||
#' @author Stephen Wirth, Anne Biewald | ||
#' @examples | ||
#' | ||
#' \dontrun{ | ||
#' a <- calcOutput("GMIA",aggregate="regglo") | ||
#' \dontrun{ | ||
#' a <- calcOutput("GMIA", aggregate = "regglo") | ||
#' } | ||
calcGMIA <- function(){ | ||
calcGMIA <- function() { | ||
x <- readSource("GMIA", "all_data_national", convert = TRUE) | ||
small_island_states <- c("ATG","BRB", "COK","NRU", "TUV","NIU", "MDV", "MLT", "GRD", | ||
"VCT","PLW", "LCA", "SGP", "FSM", "BHR", "DMA", "TON", | ||
"KIR", "STP", "SYC") | ||
antarctica_or_arctic <- c("ATA", "ATF", "GRL", "SJM") | ||
desserts_no_agg <- c("ESH", "GIB") | ||
x[antarctica_or_arctic,,] <- 0 | ||
x[desserts_no_agg,,] <- 0 | ||
|
||
smallIslandStates <- c("ATG", "BRB", "COK", "NRU", "TUV", "NIU", "MDV", "MLT", "GRD", | ||
"VCT", "PLW", "LCA", "SGP", "FSM", "BHR", "DMA", "TON", | ||
"KIR", "STP", "SYC") | ||
|
||
antarcticORarctic <- c("ATA", "ATF", "GRL", "SJM") | ||
desertNoAgg <- c("ESH", "GIB") | ||
|
||
x[antarcticORarctic, , ] <- 0 | ||
x[desertNoAgg, , ] <- 0 | ||
|
||
area <- readSource("FAO_online", "Land") | ||
sudan <- area[c("SDN","SSD"),1,"6600|Country area.Area_(1000_ha)"] | ||
proportion_sudan <- sudan/as.numeric(as.numeric(sudan["SDN",,]) + as.numeric(sudan["SSD",,])) | ||
x["SSD",,] <- as.numeric(x["SDN",,])*as.numeric(proportion_sudan["SSD",,]) | ||
x["SDN",,] <- as.numeric(x["SDN",,])*as.numeric(proportion_sudan["SDN",,]) | ||
sudan <- area[c("SDN", "SSD"), 1, "6600|Country area.Area_(1000_ha)"] | ||
sudanRatio <- sudan / as.numeric(as.numeric(sudan["SDN", , ]) + as.numeric(sudan["SSD", , ])) | ||
x["SSD", , ] <- as.numeric(x["SDN", , ]) * as.numeric(sudanRatio["SSD", , ]) | ||
x["SDN", , ] <- as.numeric(x["SDN", , ]) * as.numeric(sudanRatio["SDN", , ]) | ||
|
||
# Disaggregate values for China: Mainland, Hong Kong, Taiwan, and Macao | ||
# Based on AEI shares the information from (http://www.fao.org/nr/water/aquastat/irrigationmap/CHN/index.stm) | ||
x["HKG", , ] <- as.numeric(x["CHN", , ]) * 0.00003 | ||
x["TWN", , ] <- as.numeric(x["CHN", , ]) * 0.0078 | ||
x["CHN", , ] <- as.numeric(x["CHN", , ]) * 0.992 | ||
x["MAC", , ] <- 0 | ||
|
||
#Dissaggregate values for China: Mainland, Hong Kong, Tiwan, and Macao | ||
#Based on AEI shares the information from (http://www.fao.org/nr/water/aquastat/irrigationmap/CHN/index.stm) | ||
x["HKG",,] <- as.numeric(x["CHN",,]) * 0.00003 | ||
x["TWN",,] <- as.numeric(x["CHN",,]) * 0.0078 | ||
x["CHN",,] <- as.numeric(x["CHN",,]) * 0.992 | ||
x["MAC",,] <- 0 | ||
|
||
|
||
value_small_islands <- as.magpie(apply(x[small_island_states,,],MARGIN = c(2,3),FUN = "mean")) | ||
|
||
for(i in getRegions(x)) | ||
{ | ||
tmp <- dimSums(x[i,,], dim=c(2,3)) | ||
if(is.na(tmp)) | ||
{ | ||
area_tmp <- area[i,length(getYears(area)),"6600|Country area.Area_(1000_ha)"] | ||
if(area_tmp!=0) | ||
{ | ||
x[i,,] <- value_small_islands | ||
} | ||
else | ||
{ | ||
x[i,,] <- 0 | ||
|
||
valSmallIslands <- as.magpie(apply(x[smallIslandStates, , ], MARGIN = c(2, 3), FUN = "mean")) | ||
|
||
for (i in getItems(x, dim = 1.1)) { | ||
tmp <- dimSums(x[i, , ], dim = c(2, 3)) | ||
if (is.na(tmp)) { | ||
areaTMP <- area[i, length(getYears(area)), "6600|Country area.Area_(1000_ha)"] | ||
if (areaTMP != 0) { | ||
x[i, , ] <- valSmallIslands | ||
} else { | ||
x[i, , ] <- 0 | ||
} | ||
} | ||
} | ||
|
||
return(list(x=x, | ||
weight=NULL, | ||
unit="ha", | ||
min=0, | ||
description="Area equipped for Irrigation in ha") | ||
) | ||
|
||
} | ||
|
||
return(list(x = x, | ||
weight = NULL, | ||
unit = "ha", | ||
min = 0, | ||
description = "Area equipped for irrigation in ha")) | ||
} |
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
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.