diff --git a/.buildlibrary b/.buildlibrary index 8563c8ec..fc3cafb7 100644 --- a/.buildlibrary +++ b/.buildlibrary @@ -1,4 +1,4 @@ -ValidationKey: '3441152' +ValidationKey: '3461235' AcceptedWarnings: - 'Warning: package ''.*'' was built under R version' - 'Warning: namespace ''.*'' is not available and has been replaced' diff --git a/CITATION.cff b/CITATION.cff index d3ced860..d2050ce0 100644 --- a/CITATION.cff +++ b/CITATION.cff @@ -2,8 +2,8 @@ cff-version: 1.2.0 message: If you use this software, please cite it using the metadata from this file. type: software title: 'mrwater: madrat based MAgPIE water Input Data Library' -version: 1.7.6 -date-released: '2023-07-14' +version: 1.7.7 +date-released: '2023-07-17' abstract: Provides functions for MAgPIE cellular input data generation and stand-alone water calculations. authors: diff --git a/DESCRIPTION b/DESCRIPTION index 4e7650f7..ff139417 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,11 +1,11 @@ Type: Package Package: mrwater Title: madrat based MAgPIE water Input Data Library -Version: 1.7.6 +Version: 1.7.7 URL: https://github.com/pik-piam/mrwater, https: //doi.org/10.5281/zenodo.5801680 License: LGPL-3 | file LICENSE -Date: 2023-07-14 +Date: 2023-07-17 Authors@R: c(person("Felicitas", "Beier", email = "beier@pik-potsdam.de", role = c("aut","cre")), person("Jens", "Heinke", email = "heinke@pik-potsdam.de", role = "aut"), person("Kristine", "Karstens", email = "karstens@pik-potsdam.de", role = "aut"), diff --git a/R/calcIrrigAreaActuallyCommitted.R b/R/calcIrrigAreaActuallyCommitted.R index a8fb0659..da8e0f8a 100644 --- a/R/calcIrrigAreaActuallyCommitted.R +++ b/R/calcIrrigAreaActuallyCommitted.R @@ -125,7 +125,7 @@ calcIrrigAreaActuallyCommitted <- function(iteration = "committed_agriculture", # Fossil groundwater use to fulfill committed agricultural water use if (fossilGW) { gw <- calcOutput("NonrenGroundwatUse", - output = "comAg", multicropping = m, + output = "comAg", lpjml = lpjml, climatetype = climatetype, selectyears = selectyears, iniyear = iniyear, aggregate = FALSE) @@ -148,7 +148,7 @@ calcIrrigAreaActuallyCommitted <- function(iteration = "committed_agriculture", Please make sure that the fulfilled ratio is the same for consumption and withdrawal") } - if (any(round(wcShr[, iniyear, "off"], digits = 4) > 1)) { + if (m != FALSE && any(round(wcShr[, iniyear, "off"], digits = 4) > 1)) { stop("In calcAreaActuallyCommitted: Water requirements are over-fulfilled. This should not be the case in the initialization year. Please double-check! A wild guess: it might be related to the fossil groundwater calculation.") @@ -156,6 +156,7 @@ calcIrrigAreaActuallyCommitted <- function(iteration = "committed_agriculture", # In future time steps (after initialization year) [because of depreciation of irrigated areas] # and under an environmental flow policy scenario, + # and in the single-cropping scenario [because default is current multiple cropping], # the irrigated area may be over-fulfilled by non-renewable groundwater. # These values are capped to 1: wcShr[wcShr > 1] <- 1 diff --git a/R/calcIrrigAreaPotential.R b/R/calcIrrigAreaPotential.R index 19164cfe..ee9d2375 100644 --- a/R/calcIrrigAreaPotential.R +++ b/R/calcIrrigAreaPotential.R @@ -88,7 +88,7 @@ calcIrrigAreaPotential <- function(cropAggregation, cropmix, comAg, fossilGW, multicropping, transDist) { - ## Read in water available for irrigation (in mio. m^3) + ## Read in (renewable and non-renewable) water available for irrigation (in mio. m^3) avlWat <- calcOutput("WaterUsePotential", selectyears = selectyears, lpjml = lpjml, climatetype = climatetype, efrMethod = efrMethod, accessibilityrule = accessibilityrule, rankmethod = rankmethod, @@ -124,30 +124,14 @@ calcIrrigAreaPotential <- function(cropAggregation, comAgArea <- collapseNames(dimOrder(comAgArea, perm = c(3, 4, 2, 1), dim = 3)) # Water actually committed to agriculture (in mio. m^3) - comWater <- calcOutput("RiverHumanUseAccounting", - iteration = "committed_agriculture", - lpjml = lpjml, climatetype = climatetype, - transDist = transDist, comAg = NULL, - efrMethod = efrMethod, multicropping = m, - selectyears = selectyears, iniyear = iniyear, - accessibilityrule = NULL, - rankmethod = NULL, gainthreshold = NULL, - cropmix = NULL, yieldcalib = NULL, - irrigationsystem = NULL, landScen = NULL, - aggregate = FALSE) - comWatWW <- collapseNames(comWater[, , "currHumanWWtotal"]) - comWatWC <- collapseNames(comWater[, , "currHumanWCtotal"]) - - # Fossil groundwater use - if (fossilGW) { - gw <- calcOutput("NonrenGroundwatUse", output = "comAg", - lpjml = lpjml, climatetype = climatetype, - selectyears = selectyears, iniyear = iniyear, - aggregate = FALSE) - comWatWW <- comWatWW + collapseNames(gw[, , "withdrawal"]) - comWatWC <- comWatWC + collapseNames(gw[, , "consumption"]) - } - + comWatAct <- calcOutput("WaterUseActuallyCommittedAg", + lpjml = lpjml, climatetype = climatetype, + selectyears = selectyears, iniyear = iniyear, + multicropping = m, efrMethod = efrMethod, + fossilGW = fossilGW, transDist = transDist, + aggregate = FALSE) + comWatWW <- collapseNames(dimSums(comWatAct, dim = "crop")[, , "withdrawal"]) + comWatWC <- collapseNames(dimSums(comWatAct, dim = "crop")[, , "consumption"]) } else { @@ -158,10 +142,18 @@ calcIrrigAreaPotential <- function(cropAggregation, comWatWC[, , ] <- 0 } - # Water available for potential additional irrigation (in mio. m^3) + # Water available for potential additional irrigation beyond committed ag. use (in mio. m^3) avlWatWW <- avlWatWW - comWatWW avlWatWC <- avlWatWC - comWatWC + # Check + if (avlWatWW < 0 || avlWatWC < 0) { + stop("In calcIrrigAreaPotential: available water for additional irrigation beyond + committed agricultural use became negative. This should not be the case. + Please double check. A wild guess: this may be related to the non-renewabled + groundwater implementation.") + } + # Irrigation water requirements for selected cropmix and irrigation system per cell (in mio. m^3) watReq <- calcOutput("FullIrrigationRequirement", selectyears = selectyears, lpjml = lpjml, climatetype = climatetype, iniyear = iniyear, diff --git a/R/calcWaterUseActuallyCommittedAg.R b/R/calcWaterUseActuallyCommittedAg.R new file mode 100644 index 00000000..1517af43 --- /dev/null +++ b/R/calcWaterUseActuallyCommittedAg.R @@ -0,0 +1,72 @@ +#' @title calcWaterUseActuallyCommittedAg +#' @description This function calculates committed agricultural water uses that +#' are used in the river routing algorithm for distributing +#' available water across the basin +#' +#' @param selectyears Years to be returned +#' @param iniyear Year of initialization for cropland area +#' @param lpjml LPJmL version required for respective inputs: natveg or crop +#' @param climatetype Switch between different climate scenarios or +#' historical baseline "GSWP3-W5E5:historical" +#' @param efrMethod EFR method used including selected strictness of EFRs (e.g. Smakhtin:good, VMF:fair) +#' @param fossilGW If TRUE: non-renewable groundwater can be used. +#' If FALSE: non-renewable groundwater cannot be used. +#' @param multicropping Multicropping activated (TRUE) or not (FALSE) and +#' Multiple Cropping Suitability mask selected +#' (mask can be: +#' "none": no mask applied (only for development purposes) +#' "actual:total": currently multicropped areas calculated from total harvested areas +#' and total physical areas per cell from readLanduseToolbox +#' "actual:crop" (crop-specific), "actual:irrigation" (irrigation-specific), +#' "actual:irrig_crop" (crop- and irrigation-specific) "total" +#' "potential:endogenous": potentially multicropped areas given +#' temperature and productivity limits +#' "potential:exogenous": potentially multicropped areas given +#' GAEZ suitability classification) +#' (e.g. TRUE:actual:total; TRUE:none; FALSE) +#' @param transDist Water transport distance allowed to fulfill locally +#' unfulfilled water demand by surrounding cell water availability +#' +#' @importFrom stringr str_split +#' @importFrom madrat calcOutput +#' +#' @return magpie object in cellular resolution +#' @author Felicitas Beier +#' +#' @examples +#' \dontrun{ +#' calcOutput("WaterUseActuallyCommittedAg", aggregate = FALSE) +#' } +#' +calcWaterUseActuallyCommittedAg <- function(lpjml, climatetype, + selectyears, iniyear, + multicropping, efrMethod, + fossilGW, transDist) { + + # Irrigation water requirements per cell per crop given irrigation + # system initialization (in m^3 per hectare per year) + irrigReq <- calcOutput("ActualIrrigWatRequirements", + irrigationsystem = "initialization", + selectyears = selectyears, iniyear = iniyear, + lpjml = lpjml, climatetype = climatetype, + multicropping = multicropping, aggregate = FALSE) + + # Read in cropland area (by crop) from crop area initialization (in mio. ha) + grownCrops <- calcOutput("IrrigAreaActuallyCommitted", iteration = "committed_agriculture", + selectyears = selectyears, iniyear = iniyear, + lpjml = lpjml, climatetype = climatetype, + efrMethod = efrMethod, multicropping = multicropping, + transDist = transDist, fossilGW = fossilGW, + aggregate = FALSE) + + # Committed agricultural uses (in mio. m^3 per year) + comAg <- irrigReq * grownCrops + + return(list(x = comAg, + weight = NULL, + unit = "mio. m^3 per year", + description = paste0("water use actually committed to agriculture ", + "per crop given currently irrigated area and ", + "(renewable and non-renewable) water availability"), + isocountries = FALSE)) +} diff --git a/README.md b/README.md index 5d068edb..6f327838 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # madrat based MAgPIE water Input Data Library -R package **mrwater**, version **1.7.6** +R package **mrwater**, version **1.7.7** [![CRAN status](https://www.r-pkg.org/badges/version/mrwater)](https://cran.r-project.org/package=mrwater) [![R build status](https://github.com/pik-piam/mrwater/workflows/check/badge.svg)](https://github.com/pik-piam/mrwater/actions) [![codecov](https://codecov.io/gh/pik-piam/mrwater/branch/master/graph/badge.svg)](https://app.codecov.io/gh/pik-piam/mrwater) [![r-universe](https://pik-piam.r-universe.dev/badges/mrwater)](https://pik-piam.r-universe.dev/builds) @@ -48,7 +48,7 @@ In case of questions / problems please contact Felicitas Beier . +Beier F, Heinke J, Karstens K, Bodirsky B, Dietrich J (2023). _mrwater: madrat based MAgPIE water Input Data Library_. R package version 1.7.7, . A BibTeX entry for LaTeX users is @@ -57,7 +57,7 @@ A BibTeX entry for LaTeX users is title = {mrwater: madrat based MAgPIE water Input Data Library}, author = {Felicitas Beier and Jens Heinke and Kristine Karstens and Benjamin Leon Bodirsky and Jan Philipp Dietrich}, year = {2023}, - note = {R package version 1.7.6}, + note = {R package version 1.7.7}, url = {https://github.com/pik-piam/mrwater}, } ``` diff --git a/man/calcWaterUseActuallyCommittedAg.Rd b/man/calcWaterUseActuallyCommittedAg.Rd new file mode 100644 index 00000000..cbfb08de --- /dev/null +++ b/man/calcWaterUseActuallyCommittedAg.Rd @@ -0,0 +1,66 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/calcWaterUseActuallyCommittedAg.R +\name{calcWaterUseActuallyCommittedAg} +\alias{calcWaterUseActuallyCommittedAg} +\title{calcWaterUseActuallyCommittedAg} +\usage{ +calcWaterUseActuallyCommittedAg( + lpjml, + climatetype, + selectyears, + iniyear, + multicropping, + efrMethod, + fossilGW, + transDist +) +} +\arguments{ +\item{lpjml}{LPJmL version required for respective inputs: natveg or crop} + +\item{climatetype}{Switch between different climate scenarios or +historical baseline "GSWP3-W5E5:historical"} + +\item{selectyears}{Years to be returned} + +\item{iniyear}{Year of initialization for cropland area} + +\item{multicropping}{Multicropping activated (TRUE) or not (FALSE) and +Multiple Cropping Suitability mask selected +(mask can be: +"none": no mask applied (only for development purposes) +"actual:total": currently multicropped areas calculated from total harvested areas + and total physical areas per cell from readLanduseToolbox +"actual:crop" (crop-specific), "actual:irrigation" (irrigation-specific), +"actual:irrig_crop" (crop- and irrigation-specific) "total" +"potential:endogenous": potentially multicropped areas given + temperature and productivity limits +"potential:exogenous": potentially multicropped areas given + GAEZ suitability classification) +(e.g. TRUE:actual:total; TRUE:none; FALSE)} + +\item{efrMethod}{EFR method used including selected strictness of EFRs (e.g. Smakhtin:good, VMF:fair)} + +\item{fossilGW}{If TRUE: non-renewable groundwater can be used. +If FALSE: non-renewable groundwater cannot be used.} + +\item{transDist}{Water transport distance allowed to fulfill locally +unfulfilled water demand by surrounding cell water availability} +} +\value{ +magpie object in cellular resolution +} +\description{ +This function calculates committed agricultural water uses that + are used in the river routing algorithm for distributing + available water across the basin +} +\examples{ +\dontrun{ +calcOutput("WaterUseActuallyCommittedAg", aggregate = FALSE) +} + +} +\author{ +Felicitas Beier +}