Skip to content

Commit

Permalink
introduced new river routing run between committed agriculture and po…
Browse files Browse the repository at this point in the history
…tential irrigation: intensification to full multiple cropping on currently irrigated areas
  • Loading branch information
FelicitasBeier committed Nov 3, 2023
1 parent 9b19f8e commit affe8d0
Show file tree
Hide file tree
Showing 23 changed files with 512 additions and 123 deletions.
2 changes: 1 addition & 1 deletion .buildlibrary
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
ValidationKey: '21646761'
ValidationKey: '21669728'
AcceptedWarnings:
- 'Warning: package ''.*'' was built under R version'
- 'Warning: namespace ''.*'' is not available and has been replaced'
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/check.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ jobs:
- uses: r-lib/actions/setup-r-dependencies@v2
with:
extra-packages: |
gamstransfer=?ignore
any::lucode2
any::covr
any::madrat
Expand Down
4 changes: 2 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
exclude: '^tests/testthat/_snaps/.*$'
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
rev: v4.5.0
hooks:
- id: check-case-conflict
- id: check-json
Expand All @@ -15,7 +15,7 @@ repos:
- id: mixed-line-ending

- repo: https://github.com/lorenzwalthert/precommit
rev: v0.3.2.9021
rev: v0.3.2.9025
hooks:
- id: parsable-R
- id: deps-in-desc
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.1
date-released: '2023-10-31'
version: 1.10.2
date-released: '2023-11-03'
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.1
Version: 1.10.2
URL: https://github.com/pik-piam/mrwater,
https: //doi.org/10.5281/zenodo.5801680
License: LGPL-3 | file LICENSE
Date: 2023-10-31
Date: 2023-11-03
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
8 changes: 4 additions & 4 deletions R/calcActualIrrigWatRequirements.R
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,9 @@ calcActualIrrigWatRequirements <- function(selectyears, iniyear,
return(list(x = irrigReq,
weight = irrigArea,
unit = "m^3 per ha per yr",
description = "Irrigation water requirements
for different crop types
under selected irrigation system share
per cell and crop",
description = paste0("Irrigation water requirements ",
"for different crop types ",
"under selected irrigation system share ",
"per cell and crop"),
isocountries = FALSE))
}
12 changes: 6 additions & 6 deletions R/calcBlueWaterConsumption.R
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ calcBlueWaterConsumption <- function(selectyears, lpjml, climatetype,

# Water requirements for multiple cropping case are only calculated for areas
# where multiple cropping is possible in case of irrigation
suitMC <- collapseNames(calcOutput("MulticroppingCells",
suitMC <- collapseNames(calcOutput("MulticroppingCells", sectoral = "lpj",
scenario = "potential:endogenous",
selectyears = selectyears,
lpjml = lpjml, climatetype = climatetype,
Expand All @@ -95,7 +95,7 @@ calcBlueWaterConsumption <- function(selectyears, lpjml, climatetype,
# Special case: current multicropping according to LandInG
if (grepl(pattern = "actual", x = areaMask)) {
# Cropping intensity
ci <- collapseNames(calcOutput("MulticroppingIntensity",
ci <- collapseNames(calcOutput("MulticroppingIntensity", sectoral = "lpj",
scenario = strsplit(areaMask, split = ":")[[1]][2],
selectyears = selectyears,
aggregate = FALSE)[, , "irrigated"][, , crops])
Expand Down Expand Up @@ -182,22 +182,22 @@ calcBlueWaterConsumption <- function(selectyears, lpjml, climatetype,
if (output == "crops:main") {
# main season BWC for crops (single cropping case)
out <- bwc1st[, , crops]
description <- paste0(description, " crops in LPJmL growing period")
description <- paste0(description, "crops in LPJmL growing period")

} else if (output == "grass:main") {

out <- grperBWCgrass
description <- paste0(description, " grass in LPJmL growing period of crops")
description <- paste0(description, "grass in LPJmL growing period of crops")

} else if (output == "crops:year") {
# whole year BWC for crops (multiple cropping case)
out <- bwcTotal[, , crops]
description <- paste0(description, " crops throughout the entire year")
description <- paste0(description, "crops throughout the entire year")

} else if (output == "grass:year") {

out <- annualBWCgrass
description <- paste0(description, " grass throughout the entire year")
description <- paste0(description, "grass throughout the entire year")

} else {
stop("Please select valid output type for calcBlueWaterConsumption:
Expand Down
46 changes: 20 additions & 26 deletions R/calcCropAreaPotIrrig.R
Original file line number Diff line number Diff line change
Expand Up @@ -36,51 +36,45 @@ calcCropAreaPotIrrig <- function(selectyears, comagyear, iniyear,

# Setting selection for historical period
if (grepl("hist", cropmix)) {
# To ensure that the crop-specific areas match,
# the cropmix argument has to be adjusted
# depending on the chosen setting
if (grepl("currIrrig", landScen)) {
# When only currently irrigated areas are considered
# the irrigated cropmix must be chosen
cropmix <- "hist_irrig"
} else {
# When no committed agricultural areas are reserved
# the total historical cropmix must be chosen
cropmix <- "hist_total"
# Special treatment of committed agricultural case
# takes place further down
}
cropmix <- "hist_total"
} else {
warning("Please note: when proxy crops are selected as cropmix,
there are most likely mismatches in the area accounting of the historical period.
For analyses focusing on historical periods: please choose the historical cropmix.
For analyses focusing on historical periods: please choose the historical cropmix
and as long as there is still committed irrigation area left (not fully depreciated).
For future analysis that are supposed to meet the initialization year,
choose a wise setting (check: calcCropAreaPotIrrig)") # To Do
}

### Read in data ###
# Land area that can potentially be used for irrigated agriculture
# given assumptions set in the arguments including reservation
# (i.e. subtracting) already committed agriculture [in Mha]
# given assumptions set in the arguments [in Mha]
land <- calcOutput("AreaPotIrrig",
selectyears = selectyears, iniyear = iniyear,
comagyear = comagyear, landScen = landScen,
comagyear = NULL, landScen = landScen,
aggregate = FALSE)

if (!is.null(comagyear)) {
# committed agricultural areas have already been subtracted
# remaining areas are rainfed (i.e. rainfed cropmix)
cropmix <- "hist_rainf"
}

# share of crop area by crop type
cropareaShr <- setYears(calcOutput("CropAreaShare",
iniyear = iniyear, cropmix = cropmix,
aggregate = FALSE),
NULL)

# crop-specific area available for potential irrigation
out <- cropareaShr * land

# Areas that are already irrigated (by committed agricultural uses)
if (!is.null(comagyear)) {

# subtract physical area already reserved for irrigation with renewable water resources
# by committed agricultural uses in water allocation algorithm
# (to avoid double accounting)
comIrrigArea <- collapseNames(calcOutput("IrrigAreaCommitted",
selectyears = selectyears, iniyear = comagyear,
aggregate = FALSE))
out <- out - comIrrigArea
}

# Checks
if (any(is.na(out))) {
stop("Function calcCropAreaPotIrrig produced NA values")
Expand All @@ -93,7 +87,7 @@ calcCropAreaPotIrrig <- function(selectyears, comagyear, iniyear,
return(list(x = out,
weight = NULL,
unit = "Mha",
description = paste0("croparea potentially available for irrigated",
"agriculture per crop types"),
description = paste0("Croparea potentially available for irrigated ",
"agriculture per crop type"),
isocountries = FALSE))
}
16 changes: 3 additions & 13 deletions R/calcIrrigAreaActuallyCommitted.R
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,6 @@
#' unfulfilled water demand by surrounding cell water availability
#' @param fossilGW If TRUE: non-renewable groundwater can be used.
#' If FALSE: non-renewable groundwater cannot be used.
#' @param iteration Default: "committed_agriculture",
#' Special case: "committed_agriculture_fullPotential".
#' Special case should only be used for calculation of
#' full multicropping potential committed agricultural area
#' for case of Current Irrigation.
#'
#' @return magpie object in cellular resolution
#' @author Felicitas Beier
Expand All @@ -44,19 +39,14 @@
#' @importFrom madrat calcOutput
#' @importFrom magclass collapseNames collapseDim new.magpie getCells getNames

calcIrrigAreaActuallyCommitted <- function(iteration = "committed_agriculture",
lpjml, climatetype,
calcIrrigAreaActuallyCommitted <- function(lpjml, climatetype,
selectyears, iniyear,
efrMethod, fossilGW,
multicropping, transDist) {

## Current Uses
if (as.logical(stringr::str_split(multicropping, ":")[[1]][1])) {
if (grepl(pattern = "fullPotential", x = iteration)) {
m <- multicropping
} else {
m <- "TRUE:actual:irrig_crop"
}
m <- "TRUE:actual:irrig_crop"
} else {
m <- FALSE
}
Expand All @@ -79,7 +69,7 @@ calcIrrigAreaActuallyCommitted <- function(iteration = "committed_agriculture",

# Water already committed to irrigation (in mio. m^3)
comWater <- calcOutput("RiverHumanUseAccounting",
iteration = iteration,
iteration = "committed_agriculture",
lpjml = lpjml, climatetype = climatetype,
transDist = transDist, comAg = NULL,
efrMethod = efrMethod, multicropping = m,
Expand Down
30 changes: 30 additions & 0 deletions R/calcIrrigAreaPotential.R
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,17 @@ calcIrrigAreaPotential <- function(cropAggregation,
Please double-check!")
}

# To Do: split areas:
# committed:
# -> irrigArea * shrMC
# additional (beyond committed):
# -> irrigArea * (1-shrMC) where enough water available from committed_agriculture_fullMulticropping run
# -> rainfedArea where enough water available for additonal irrigation

# Note: need to consider shrPotMC! (new function: calcPotentialMulticroppingArea)

# total avlWat (i.e. from all three runs and GW) / reqWat = shr fulfilled --> doesn't necessarily add up because of cropmix (therefore, split calculation as above)

## Read in (renewable and non-renewable) water available for irrigation (in mio. m^3)
# including committed agricultural water (if activated)
avlWat <- calcOutput("WaterUsePotential", selectyears = selectyears,
Expand Down Expand Up @@ -156,6 +167,25 @@ calcIrrigAreaPotential <- function(cropAggregation,
comWatWW <- collapseNames(dimSums(comWatAct, dim = "crop")[, , "withdrawal"])
comWatWC <- collapseNames(dimSums(comWatAct, dim = "crop")[, , "consumption"])

# Water committed to intensify currently irrigated areas to full multiple
# cropping potential (in mio. m^3)
if (as.logical(stringr::str_split(multicropping, ":")[[1]][1])) {
# water required to expand multiple cropping in already irrigated areas and can
# be fulfilled by renewable water resources
currHumanAdd <- calcOutput("RiverHumanUseAccounting",
iteration = "committed_agriculture_fullMulticropping",
lpjml = lpjml, climatetype = climatetype,
transDist = transDist, comAg = NULL,
efrMethod = efrMethod, multicropping = multicropping,
selectyears = selectyears, iniyear = iniyear,
accessibilityrule = NULL,
rankmethod = NULL, gainthreshold = NULL,
cropmix = NULL, yieldcalib = NULL,
irrigationsystem = NULL, landScen = NULL,
aggregate = FALSE)
comWatWC <- comWatWC + collapseNames(currHumanAdd[, , "currHumanWCtotal"])
comWatWW <- comWatWW + collapseNames(currHumanAdd[, , "currHumanWWtotal"])
}
} else {
comagyear <- NULL

Expand Down
Loading

0 comments on commit affe8d0

Please sign in to comment.