Skip to content

Commit

Permalink
Groundwater now calculated based on single water requirements when si…
Browse files Browse the repository at this point in the history
…ngle cropping selected
  • Loading branch information
FelicitasBeier committed Aug 30, 2023
1 parent dbf7001 commit dc65d61
Show file tree
Hide file tree
Showing 9 changed files with 74 additions and 11 deletions.
2 changes: 1 addition & 1 deletion .buildlibrary
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
ValidationKey: '37436490'
ValidationKey: '37473288'
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.9.11
date-released: '2023-08-21'
version: 1.9.12
date-released: '2023-08-30'
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.9.11
Version: 1.9.12
URL: https://github.com/pik-piam/mrwater,
https: //doi.org/10.5281/zenodo.5801680
License: LGPL-3 | file LICENSE
Date: 2023-08-21
Date: 2023-08-30
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"),
Expand Down
3 changes: 3 additions & 0 deletions R/calcBlueWaterConsumption.R
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,9 @@ calcBlueWaterConsumption <- function(selectyears, lpjml, climatetype,
}
}

# leave negative in for fit;
# correct negative bwc in end (when for crop)

# crop blue water consumption in off season
bwc2nd <- grassBWC2nd * coeff
bwcTotal <- bwc1st[, , crops] + bwc2nd * shrMC
Expand Down
10 changes: 8 additions & 2 deletions R/calcIrrigAreaActuallyCommitted.R
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ calcIrrigAreaActuallyCommitted <- function(iteration = "committed_agriculture",
dim = "crop"))

# Share of Area that is irrigated given limited renewable water availability
# Note: Areas that are reported to be irrigated
# Note: Areas that are reported to be irrigated
wwShr <- ifelse(totalIrrigReqWW > 0,
comWatWW / totalIrrigReqWW,
1)
Expand All @@ -129,7 +129,7 @@ calcIrrigAreaActuallyCommitted <- function(iteration = "committed_agriculture",
# Fossil groundwater use to fulfill committed agricultural water use
if (fossilGW) {
gw <- calcOutput("NonrenGroundwatUse",
output = "comAg",
output = "comAg", multicropping = m,
lpjml = lpjml, climatetype = climatetype,
selectyears = selectyears, iniyear = iniyear,
aggregate = FALSE)
Expand All @@ -154,6 +154,8 @@ calcIrrigAreaActuallyCommitted <- function(iteration = "committed_agriculture",
wcShr[wcShr > 1] <- 1
wwShr[wwShr > 1] <- 1

### This could introduce a mismatch between wcShr and wwShr... where wcShr > 1 -> wwShr also needs to be > 1, right?

if (any(round(wwShr[, iniyear, "off"] - wcShr[, iniyear, "off"], digits = 4) != 0)) {
stop("There seems to be a mismatch in consumption and withdrawal
in calcIrrigAreaActuallyCommitted.
Expand All @@ -164,6 +166,10 @@ calcIrrigAreaActuallyCommitted <- function(iteration = "committed_agriculture",
# Area Actually Committed for Irrigation given available water (in Mha)
out[, , "off"] <- comArea * wcShr[, , "off"]
# Note: In an environmental flow scenario, non-renewable groundwater cannot be used

#### @JENS: Or should it be added to both EFR.on and off?
# --> Yes; for both "on" and "off" should be included

}

# check for NAs and negative values
Expand Down
1 change: 1 addition & 0 deletions R/calcIrrigWatRequirements.R
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ calcIrrigWatRequirements <- function(selectyears, lpjml, climatetype,
irrigReq[, , "oilpalm"] <- irrigReqProxy[, , "groundnut"]
irrigReq[, , "others"] <- irrigReqProxy[, , "maize"]
irrigReq[, , "cottn_pro"] <- irrigReqProxy[, , "groundnut"]
#@JENS (KRISTINE): Please double-check whether this makes sense
}
} else {

Expand Down
2 changes: 2 additions & 0 deletions R/calcWaterUsePotential.R
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ calcWaterUsePotential <- function(lpjml, selectyears, climatetype, efrMethod,
# Fossil groundwater use
if (fossilGW) {
gw <- calcOutput("NonrenGroundwatUse", output = "nonAg",
multicropping = multicropping,
lpjml = lpjml, climatetype = climatetype,
selectyears = selectyears, iniyear = iniyear,
aggregate = FALSE)
Expand All @@ -146,6 +147,7 @@ calcWaterUsePotential <- function(lpjml, selectyears, climatetype, efrMethod,
# Fossil groundwater use
if (fossilGW) {
gw <- calcOutput("NonrenGroundwatUse", output = "comAg",
multicropping = multicropping,
lpjml = lpjml, climatetype = climatetype,
selectyears = selectyears, iniyear = iniyear,
aggregate = FALSE)
Expand Down
53 changes: 52 additions & 1 deletion R/fullMULTICROPPING.R
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ fullMULTICROPPING <- function() {
if (comAg && grepl("hist", cropmix)) {
# If committed agricultural areas are reserved
# (based on the currently irrigated cropmix),
# the remaining (additional) irrigated areas
# the remaining (additional) irrigated areas
# have to be based on the rainfed cropmix
cropmix <- "hist_rainf"
}
Expand Down Expand Up @@ -199,6 +199,7 @@ fullMULTICROPPING <- function() {
#########################
# IRRIGATION POTENTIALS #
#########################
### (a) Areas ###
# potentially irrigated area on current cropland (under single cropping conditions)
calcOutput("IrrigAreaPotential", cropAggregation = FALSE,
lpjml = lpjml, climatetype = climatetype,
Expand Down Expand Up @@ -248,6 +249,56 @@ fullMULTICROPPING <- function() {
aggregate = FALSE,
file = "piaIRR_multPOT.mz")

### (B) Water Use ###
# potentially irrigation water on current cropland (under single cropping conditions)
calcOutput("WaterUsePotential", cropAggregation = FALSE,
lpjml = lpjml, climatetype = climatetype,
selectyears = selectyears, iniyear = iniyear,
efrMethod = efrMethod, accessibilityrule = accessibilityrule,
rankmethod = rankmethod, yieldcalib = yieldcalib, allocationrule = allocationrule,
gainthreshold = gainthreshold, irrigationsystem = irrigationsystem,
landScen = "currCropland:NULL",
cropmix = cropmix, comAg = comAg, fossilGW = fossilGW,
multicropping = FALSE, transDist = transDist,
aggregate = FALSE,
file = "piwCUR_single.mz")
# potentially irrigation water on current cropland (under current multiple cropping conditions)
calcOutput("WaterUsePotential", cropAggregation = FALSE,
lpjml = lpjml, climatetype = climatetype,
selectyears = selectyears, iniyear = iniyear,
efrMethod = efrMethod, accessibilityrule = accessibilityrule,
rankmethod = rankmethod, yieldcalib = yieldcalib, allocationrule = allocationrule,
gainthreshold = gainthreshold, irrigationsystem = irrigationsystem,
landScen = "currCropland:NULL",
cropmix = cropmix, comAg = comAg, fossilGW = fossilGW,
multicropping = "TRUE:actual:irrig_crop", transDist = transDist,
aggregate = FALSE,
file = "piwCUR_multACT.mz")
# potentially irrigation water on current cropland (under consideration of potential multiple cropping)
calcOutput("WaterUsePotential", cropAggregation = FALSE,
lpjml = lpjml, climatetype = climatetype,
selectyears = selectyears, iniyear = iniyear,
efrMethod = efrMethod, accessibilityrule = accessibilityrule,
rankmethod = rankmethod, yieldcalib = yieldcalib, allocationrule = allocationrule,
gainthreshold = gainthreshold, irrigationsystem = irrigationsystem,
landScen = "currCropland:NULL",
cropmix = cropmix, comAg = comAg, fossilGW = fossilGW,
multicropping = "TRUE:potential:endogenous", transDist = transDist,
aggregate = FALSE,
file = "piwCUR_multPOT.mz")
# potentially irrigation water on currently irrigated cropland (under consideration of potential multiple cropping)
calcOutput("WaterUsePotential", cropAggregation = FALSE,
lpjml = lpjml, climatetype = climatetype,
selectyears = selectyears, iniyear = iniyear,
efrMethod = efrMethod, accessibilityrule = accessibilityrule,
rankmethod = rankmethod, yieldcalib = yieldcalib, allocationrule = allocationrule,
gainthreshold = gainthreshold, irrigationsystem = irrigationsystem,
landScen = "currIrrig:NULL",
cropmix = cropmix, comAg = comAg, fossilGW = fossilGW,
multicropping = "TRUE:potential:endogenous", transDist = transDist,
aggregate = FALSE,
file = "piwIRR_multPOT.mz")


### Yield Gain ###
# Single cropping yield gain
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.9.11**
R package **mrwater**, version **1.9.12**

[![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.9.11, <URL: 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.9.12, <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.9.11},
note = {R package version 1.9.12},
url = {https://github.com/pik-piam/mrwater},
}
```

0 comments on commit dc65d61

Please sign in to comment.