Skip to content

Commit

Permalink
Bugfix: committed_agriculture_fullMulticropping hasn't been called in…
Browse files Browse the repository at this point in the history
… calcRiverRoutingInputs
  • Loading branch information
FelicitasBeier committed Jan 3, 2024
1 parent 711d182 commit 6e1a048
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 25 deletions.
2 changes: 1 addition & 1 deletion .buildlibrary
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
ValidationKey: '219192812'
ValidationKey: '219223650'
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.11.13
date-released: '2024-01-02'
version: 1.11.14
date-released: '2024-01-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.11.13
Version: 1.11.14
URL: https://github.com/pik-piam/mrwater,
https: //doi.org/10.5281/zenodo.5801680
License: LGPL-3 | file LICENSE
Date: 2024-01-02
Date: 2024-01-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
13 changes: 6 additions & 7 deletions R/calcPotMulticroppingShare.R
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@
#' ("surface", "sprinkler", "drip", "initialization")
#' @param landScen Land availability scenario consisting of two parts separated by ":":
#' 1. available land scenario (currCropland, currIrrig, potCropland)
#' 2. protection scenario (WDPA, or one of the scenarios available in calcConservationPriorities,
#' 2. protection scenario (WDPA, or one of the scenarios available
#' in calcConservationPriorities,
#' e.g., 30by20, BH, BH_IFL, PBL_HalfEarth,
#' or NA for no protection).
#' For case of no land protection select "NA" in second part of argument
Expand Down Expand Up @@ -89,7 +90,6 @@ calcPotMulticroppingShare <- function(scenario, lpjml, climatetype,
gainthreshold, irrigationsystem, landScen,
cropmix, comAg, fossilGW,
multicropping, transDist) {

# To Do: remove scenario dimension and return for all scenarios.

### Read in data ###
Expand Down Expand Up @@ -242,11 +242,6 @@ calcPotMulticroppingShare <- function(scenario, lpjml, climatetype,
outWW[, , nonMCcrops] <- 0
outWC[, , nonMCcrops] <- 0

# Crops that have no irrigaton water requirements in second season
# are not multiple cropped under irrigated conditions
outWW[noReqSecond] <- 0
outWC[noReqSecond] <- 0

if (any(round(outWW - outWC, digits = 6) != 0)) {
warning("outWW and outWC should be the same. check what's wrong")
}
Expand All @@ -260,6 +255,10 @@ calcPotMulticroppingShare <- function(scenario, lpjml, climatetype,
out[, , ] <- 0
}

# Crops that have no irrigaton water requirements in second season
# are not multiple cropped under irrigated conditions
out[noReqSecond, , "irrigated"] <- 0

# Checks
if (any(is.na(out))) {
stop("mrwater::calcPotMulticroppingShare produced NAs")
Expand Down
20 changes: 10 additions & 10 deletions R/calcRiverRoutingInputs.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#' (Note: does not affect years of harmonization or smoothing)
#' @param iteration Water use to be allocated in this river routing iteration
#' (non_agriculture, committed_agriculture, potential_irrigation,
#' special case (for current irrigated area analysis): "committed_agriculture_fullMulticropping").
#' committed_agriculture_fullMulticropping).
#' @param climatetype Switch between different climate scenarios
#' or historical baseline "GSWP3-W5E5:historical"
#' @param iniyear Initialization year of irrigation system
Expand Down Expand Up @@ -67,7 +67,8 @@
#' allocation algorithm ("surface", "sprinkler", "drip", "initialization")
#' @param landScen Land availability scenario consisting of two parts separated by ":":
#' 1. available land scenario (currCropland, currIrrig, potCropland)
#' 2. protection scenario (WDPA, or one of the scenarios available in calcConservationPriorities,
#' 2. protection scenario (WDPA, or one of the scenarios available
#' in calcConservationPriorities,
#' e.g., 30by20, BH, BH_IFL, PBL_HalfEarth,
#' or NA for no protection).
#' For case of no land protection select "NA" in second part of argument
Expand All @@ -92,7 +93,6 @@ calcRiverRoutingInputs <- function(lpjml, climatetype,
transDist, efrMethod, accessibilityrule,
multicropping, comAg, rankmethod, gainthreshold,
cropmix, yieldcalib, irrigationsystem, landScen) {

# Object dimensions
watNonAg <- calcOutput("WaterUseNonAg",
selectyears = selectyears, cells = "lpjcell",
Expand All @@ -119,7 +119,7 @@ calcRiverRoutingInputs <- function(lpjml, climatetype,
}

## Routing-iteration-specific inputs
if (grepl(pattern = "non_agriculture", x = iteration)) {
if (iteration == "non_agriculture") {
## Previous Uses
# Minimum flow requirements determined by natural flow river routing:
# (full) Environmental Flow Requirements (in mio. m^3 / yr) [long-term average]
Expand Down Expand Up @@ -149,7 +149,7 @@ calcRiverRoutingInputs <- function(lpjml, climatetype,
discharge <- .transformObject(x = discharge,
cells = cells, years = selectyears, scenarios = scenarios)

} else if (grepl(pattern = "committed_agriculture", x = iteration)) {
} else if (iteration == "committed_agriculture") {
## Previous Uses
# Non-agricultural withdrawals and consumption
previousHumanUse <- calcOutput("RiverHumanUseAccounting",
Expand Down Expand Up @@ -194,8 +194,7 @@ calcRiverRoutingInputs <- function(lpjml, climatetype,
## Discharge from previous routing
discharge <- collapseNames(previousHumanUse[, , "discharge"])

} else if (grepl(pattern = "committed_agriculture_fullMulticropping", x = iteration)) {

} else if (iteration == "committed_agriculture_fullMulticropping") {
# For case of multiple cropping, determine whether current multiple cropping can be
# expanded to full potential on committed agricultural areas
if (as.logical(stringr::str_split(multicropping, ":")[[1]][1])) {
Expand Down Expand Up @@ -270,7 +269,7 @@ calcRiverRoutingInputs <- function(lpjml, climatetype,
currRequestWClocal <- tmp[, , "currRequestWClocal"]
}

} else if (grepl(pattern = "potential_irrigation", x = iteration)) {
} else if (iteration == "potential_irrigation") {

if (comAg == TRUE) {
# accounting in potentials
Expand Down Expand Up @@ -341,9 +340,10 @@ calcRiverRoutingInputs <- function(lpjml, climatetype,
discharge <- collapseNames(prevRouting[, , "discharge"])

} else {
stop("Please specify iteration for which river routing inputs shall be calculated:
stop(paste0("Please specify iteration for which river routing inputs shall be calculated:
non_agriculture, committed_agriculture, potential_irrigation,
or committed_agriculture_fullMulticropping")
or committed_agriculture_fullMulticropping.
The iteration that you selected is ", iteration, "."))
}

###############
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.11.13**
R package **mrwater**, version **1.11.14**

[![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 (2024). _mrwater: madrat based MAgPIE water Input Data Library_. R package version 1.11.13, <https://github.com/pik-piam/mrwater>.
Beier F, Heinke J, Karstens K, Bodirsky B, Dietrich J (2024). _mrwater: madrat based MAgPIE water Input Data Library_. R package version 1.11.14, <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 = {2024},
note = {R package version 1.11.13},
note = {R package version 1.11.14},
url = {https://github.com/pik-piam/mrwater},
}
```

0 comments on commit 6e1a048

Please sign in to comment.