Skip to content

Commit

Permalink
flexibilize multicropping function to test different settings
Browse files Browse the repository at this point in the history
  • Loading branch information
FelicitasBeier committed Oct 31, 2023
1 parent a233aa8 commit 9b19f8e
Show file tree
Hide file tree
Showing 7 changed files with 71 additions and 21 deletions.
2 changes: 1 addition & 1 deletion .buildlibrary
Original file line number Diff line number Diff line change
@@ -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'
Expand Down
4 changes: 2 additions & 2 deletions CITATION.cff
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -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 = "[email protected]", role = c("aut","cre")),
person("Jens", "Heinke", email = "[email protected]", role = "aut"),
person("Kristine", "Karstens", email = "[email protected]", role = "aut"),
Expand Down
16 changes: 10 additions & 6 deletions R/fullMULTICROPPING.R
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand All @@ -26,18 +35,13 @@ 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"

# 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
Expand Down
44 changes: 38 additions & 6 deletions R/fullPREPROCESSING.R
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -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)

Expand Down Expand Up @@ -50,7 +50,7 @@ In case of questions / problems please contact Felicitas Beier <beier@pik-potsda

To cite package **mrwater** in publications use:

Beier F, Heinke J, Karstens K, Bodirsky B, Dietrich J (2023). _mrwater: madrat based MAgPIE water Input Data Library_. R package version 1.10.0, <https://github.com/pik-piam/mrwater>.
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, <https://github.com/pik-piam/mrwater>.

A BibTeX entry for LaTeX users is

Expand All @@ -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},
}
```
16 changes: 15 additions & 1 deletion man/fullMULTICROPPING.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 9b19f8e

Please sign in to comment.