From 9b19f8e338b38d6e552fc05bf10470634e7d0ddb Mon Sep 17 00:00:00 2001 From: Felicitas Date: Tue, 31 Oct 2023 12:24:16 +0100 Subject: [PATCH] flexibilize multicropping function to test different settings --- .buildlibrary | 2 +- CITATION.cff | 4 ++-- DESCRIPTION | 4 ++-- R/fullMULTICROPPING.R | 16 +++++++++------ R/fullPREPROCESSING.R | 44 ++++++++++++++++++++++++++++++++++------ README.md | 6 +++--- man/fullMULTICROPPING.Rd | 16 ++++++++++++++- 7 files changed, 71 insertions(+), 21 deletions(-) diff --git a/.buildlibrary b/.buildlibrary index 9722464d..166a5cc3 100644 --- a/.buildlibrary +++ b/.buildlibrary @@ -1,4 +1,4 @@ -ValidationKey: '21622700' +ValidationKey: '21646761' 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 e5f69fa5..b27965e4 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.10.0 -date-released: '2023-10-27' +version: 1.10.1 +date-released: '2023-10-31' abstract: Provides functions for MAgPIE cellular input data generation and stand-alone water calculations. authors: diff --git a/DESCRIPTION b/DESCRIPTION index fb0d8865..4bc77f70 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,11 +1,11 @@ Type: Package Package: mrwater Title: madrat based MAgPIE water Input Data Library -Version: 1.10.0 +Version: 1.10.1 URL: https://github.com/pik-piam/mrwater, https: //doi.org/10.5281/zenodo.5801680 License: LGPL-3 | file LICENSE -Date: 2023-10-27 +Date: 2023-10-31 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/fullMULTICROPPING.R b/R/fullMULTICROPPING.R index f6124670..575f9e3a 100644 --- a/R/fullMULTICROPPING.R +++ b/R/fullMULTICROPPING.R @@ -3,13 +3,22 @@ #' irrigation potentials on current cropland #' at cellular resolution. #' +#' @param allocationrule Rule to be applied for river basin discharge allocation +#' across cells of river basin ("optimization", "upstreamfirst", "equality") +#' @param fossilGW If TRUE: non-renewable groundwater can be used. +#' If FALSE: non-renewable groundwater cannot be used. +#' @param transDist Water transport distance allowed to fulfill locally +#' unfulfilled water demand by surrounding cell water availability +#' #' @author Felicitas Beier #' #' @importFrom stringr str_split #' #' @export -fullMULTICROPPING <- function() { +fullMULTICROPPING <- function(allocationrule = "optimization", + fossilGW = TRUE, + transDist = 100) { # scenarios for paper: landScen <- "currCropland:NA", "currIrrig:NA" @@ -26,7 +35,6 @@ fullMULTICROPPING <- function() { # Settings for optimization algorithm accessibilityrule <- "CV:2" - allocationrule <- "optimization" # JENS/BENNI: "optimization" #### or "upstreamfirst"? rankmethod <- "USD_m3:GLO:TRUE" ssp <- "ssp2" efp <- "off" @@ -34,10 +42,6 @@ fullMULTICROPPING <- function() { # Assumption in this study: # only technical potential is reported for the purpose of this analysis: gtrange <- gainthreshold <- 0 - # default transport distance is 100 km (sensitivity is provided in SI) - transDist <- 100 - # fossil groundwater use is activated - fossilGW <- TRUE # potential yields from LPJmL to derive multiple cropping potentials yieldcalib <- "TRUE:TRUE:actual:irrig_crop" # FALSE # reserve already irrigated areas for irrigation diff --git a/R/fullPREPROCESSING.R b/R/fullPREPROCESSING.R index d000eae4..b7afdaec 100644 --- a/R/fullPREPROCESSING.R +++ b/R/fullPREPROCESSING.R @@ -57,13 +57,32 @@ fullPREPROCESSING <- function(protectLand = "HalfEarth", allocationrule <- "optimization" rankmethod <- "USD_m3:GLO:TRUE" - # To DO: distinguish sustainable and unsustainable scenarios - fossilGW <- TRUE - ################ # MAIN RESULTS # ################ - # Potentially irrigated area (PIA) + # Multiple cropping factor (spatially explicit) from LandInG + # does this have to be capped? + + # Crop-specific irrigation water requirements + # (a) single cropping + # (b) multiple cropping + + # Areas equipped for irrigation + # -> committed irrigated areas (from calcIrrigAreaCommitted!) + + # Potentially irrigated areas (PIA) + # -> including groundwater + # for potCropland + # How to include protection scenarios? Additional scenario dimension or separate files? + # in MAgPIE: for past time steps: EFP off; scenarios start in 2020 + # How to ensure fade-in of EFP? diff between (EFP-off and EFP-on) * fader? + + # Water availability (PIWW, PIWC) + # From renewable sources + # From fossil groundwater + + + # Potentially irrigated area from renewable water sources (PIA) calcOutput("IrrigAreaPotential", cropAggregation = TRUE, lpjml = lpjml, climatetype = climatetype, selectyears = lpjYears, iniyear = iniyear, @@ -74,10 +93,23 @@ fullPREPROCESSING <- function(protectLand = "HalfEarth", landScen = landScen, cropmix = cropmix, comAg = TRUE, multicropping = multicropping, - transDist = transDist, fossilGW = fossilGW, + transDist = transDist, fossilGW = FALSE, aggregate = FALSE, file = "potIrrigArea.mz") + calcOutput("IrrigAreaPotential", cropAggregation = TRUE, + lpjml = lpjml, climatetype = climatetype, + selectyears = lpjYears, iniyear = iniyear, + efrMethod = efrMethod, accessibilityrule = accessibilityrule, + rankmethod = rankmethod, yieldcalib = yieldcalib, + allocationrule = allocationrule, + gainthreshold = gt, irrigationsystem = irrigationsystem, + landScen = landScen, + cropmix = cropmix, comAg = TRUE, + multicropping = multicropping, + transDist = transDist, fossilGW = TRUE, + aggregate = FALSE, file = "potIrrigArea_fossilGW.mz") ## To Do - # Note: switch to aggregate = "cluster" (but need to switch to different clustering first) + # (1) return PIA, PIWC, PIWW for renewable water sources & PIA, PIWC, PIWW from fossil groundwater (i.e. diff between with GW and without GW) --> separate function! + # (1) switch to aggregate = "cluster" (but need to switch to different clustering first) # make function that combines all required scenarios: # GW on and off; EFP on and off; different SSPs diff --git a/README.md b/README.md index fe3fb9ec..d32cffb5 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # madrat based MAgPIE water Input Data Library -R package **mrwater**, version **1.10.0** +R package **mrwater**, version **1.10.1** [![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) @@ -50,7 +50,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.10.1, . A BibTeX entry for LaTeX users is @@ -59,7 +59,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.10.0}, + note = {R package version 1.10.1}, url = {https://github.com/pik-piam/mrwater}, } ``` diff --git a/man/fullMULTICROPPING.Rd b/man/fullMULTICROPPING.Rd index 264d42ea..b2940b1f 100644 --- a/man/fullMULTICROPPING.Rd +++ b/man/fullMULTICROPPING.Rd @@ -4,7 +4,21 @@ \alias{fullMULTICROPPING} \title{fullMULTICROPPING} \usage{ -fullMULTICROPPING() +fullMULTICROPPING( + allocationrule = "optimization", + fossilGW = TRUE, + transDist = 100 +) +} +\arguments{ +\item{allocationrule}{Rule to be applied for river basin discharge allocation +across cells of river basin ("optimization", "upstreamfirst", "equality")} + +\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} } \description{ Function that produces output for multiple cropping and