Skip to content

Commit

Permalink
rearranged order of calculation in fullMulticropping to create most o…
Browse files Browse the repository at this point in the history
…utputs despite error in calcCroprevenue
  • Loading branch information
FelicitasBeier committed Aug 9, 2023
1 parent 2e91b7e commit 24f09e4
Show file tree
Hide file tree
Showing 7 changed files with 172 additions and 154 deletions.
2 changes: 1 addition & 1 deletion .buildlibrary
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
ValidationKey: '3856669'
ValidationKey: '3876444'
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.7
date-released: '2023-08-08'
version: 1.9.8
date-released: '2023-08-09'
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.7
Version: 1.9.8
URL: https://github.com/pik-piam/mrwater,
https: //doi.org/10.5281/zenodo.5801680
License: LGPL-3 | file LICENSE
Date: 2023-08-08
Date: 2023-08-09
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
2 changes: 1 addition & 1 deletion R/calcAreaPotIrrig.R
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ calcAreaPotIrrig <- function(selectyears, comagyear, iniyear, landScen,
multicropping = multicropping, transDist = transDist,
aggregate = FALSE))
if (any(scenarios != unique(getItems(dimSums(comIrrigArea, dim = 3.1), dim = 3)))) {
stop("Apparently the number of scenarios or format has change.
stop("Apparently the number of scenarios or format has changed.
Please adjust default argument of mrwater::calcAreaPotIrrig accordingly.")
}
comIrrigArea <- collapseNames(dimSums(comIrrigArea, dim = 3.1))
Expand Down
4 changes: 3 additions & 1 deletion R/calcIrrigAreaPotential.R
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ calcIrrigAreaPotential <- function(cropAggregation,
multicropping, transDist) {

## 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,
lpjml = lpjml, climatetype = climatetype, efrMethod = efrMethod,
accessibilityrule = accessibilityrule, rankmethod = rankmethod,
Expand Down Expand Up @@ -228,7 +229,8 @@ calcIrrigAreaPotential <- function(cropAggregation,
# This is corrected here:
out <- pmin(out, comAgArea)
# Note: maybe same special treatment is required for different transport distances
# of groundwater and rest of algorithm
# of groundwater and rest of algorithm?
# Maybe this also applies for currCropland, but then cannot be solved via pmin with out object
}

# check for NAs and negative values
Expand Down
304 changes: 160 additions & 144 deletions R/fullMULTICROPPING.R
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,166 @@ fullMULTICROPPING <- function() {
file = "piaIRR_multPOT.mz")


### Yield Gain ###
# Single cropping yield gain
calcOutput("IrrigYieldImprovementPotential", unit = "USD_ha:GLO",
lpjml = lpjml, climatetype = climatetype,
selectyears = selectyears, iniyear = iniyear,
comagyear = NULL, efrMethod = efrMethod, transDist = 0,
irrigationsystem = irrigationsystem, landScen = paste0("potCropland:", "NULL"),
cropmix = "hist_irrig", yieldcalib = yieldcalib,
multicropping = FALSE, aggregate = FALSE,
file = "yieldgain_single.mz")

# Multiple cropping yield gain
calcOutput("IrrigYieldImprovementPotential", unit = "USD_ha:GLO",
lpjml = lpjml, climatetype = climatetype,
selectyears = selectyears, iniyear = iniyear,
comagyear = NULL, efrMethod = efrMethod, transDist = 0,
irrigationsystem = irrigationsystem, landScen = paste0("potCropland:", "NULL"),
cropmix = "hist_irrig", yieldcalib = yieldcalib,
multicropping = TRUE, aggregate = FALSE,
file = "yieldgain_multiple.mz")

# Agricultural Water Consumption (NOLIM) [in mio. m^3 per year]
calcOutput("WaterUseCommittedAg",
lpjml = lpjml, climatetype = climatetype,
selectyears = selectyears, iniyear = iniyear,
multicropping = FALSE, aggregate = FALSE,
file = "comAgWat_single_NOLIM.mz"
)
calcOutput("WaterUseCommittedAg",
lpjml = lpjml, climatetype = climatetype,
selectyears = selectyears, iniyear = iniyear,
multicropping = "TRUE:actual:irrig_crop", aggregate = FALSE,
file = "comAgWat_multipleACT_NOLIM.mz"
)
calcOutput("WaterUseCommittedAg",
lpjml = lpjml, climatetype = climatetype,
selectyears = selectyears, iniyear = iniyear,
multicropping = "TRUE:potential:endogenous", aggregate = FALSE,
file = "comAgWat_multiplePOT_NOLIM.mz"
)

for (t in c(0, 100, 200)) {
# Committed agricultural area
calcOutput("IrrigAreaActuallyCommitted",
fossilGW = FALSE,
lpjml = lpjml, climatetype = climatetype,
selectyears = selectyears, iniyear = iniyear,
efrMethod = efrMethod, transDist = t,
multicropping = FALSE, aggregate = FALSE,
file = paste0("comAgAreaACT_single_", t, ".mz")
)

calcOutput("IrrigAreaActuallyCommitted",
fossilGW = FALSE,
lpjml = lpjml, climatetype = climatetype,
selectyears = selectyears, iniyear = iniyear,
efrMethod = efrMethod, transDist = t,
multicropping = "TRUE:actual:irrig_crop",
aggregate = FALSE,
file = paste0("comAgAreaACT_multipleACT_", t, ".mz")
)

calcOutput("IrrigAreaActuallyCommitted",
fossilGW = FALSE,
lpjml = lpjml, climatetype = climatetype,
selectyears = selectyears, iniyear = iniyear,
efrMethod = efrMethod, transDist = t,
multicropping = "TRUE:potential:endogenous",
iteration = "committed_agriculture_fullPotential",
aggregate = FALSE,
file = paste0("comAgAreaACT_multiplePOT_", t, ".mz")
)


# Committed Agricultural water uses
calcOutput("RiverHumanUseAccounting",
iteration = "committed_agriculture",
lpjml = lpjml, climatetype = climatetype,
efrMethod = efrMethod,
selectyears = selectyears, iniyear = iniyear,
transDist = t, comAg = TRUE,
accessibilityrule = NULL,
rankmethod = NULL, gainthreshold = NULL,
cropmix = NULL, yieldcalib = NULL,
irrigationsystem = NULL, landScen = NULL,
multicropping = FALSE,
aggregate = FALSE,
file = paste0("comAgWatACT_single_", t, ".mz")
)
calcOutput("RiverHumanUseAccounting",
iteration = "committed_agriculture",
lpjml = lpjml, climatetype = climatetype,
efrMethod = efrMethod,
selectyears = selectyears, iniyear = iniyear,
transDist = t, comAg = TRUE,
accessibilityrule = NULL,
rankmethod = NULL, gainthreshold = NULL,
cropmix = NULL, yieldcalib = NULL,
irrigationsystem = NULL, landScen = NULL,
multicropping = "TRUE:actual:irrig_crop",
aggregate = FALSE,
file = paste0("comAgWatACT_multipleACT_", t, ".mz")
)
calcOutput("RiverHumanUseAccounting",
iteration = "committed_agriculture_fullPotential",
lpjml = lpjml, climatetype = climatetype,
efrMethod = efrMethod,
selectyears = selectyears, iniyear = iniyear,
transDist = t, comAg = TRUE,
accessibilityrule = NULL,
rankmethod = NULL, gainthreshold = NULL,
cropmix = NULL, yieldcalib = NULL,
irrigationsystem = NULL, landScen = NULL,
multicropping = "TRUE:potential:endogenous",
aggregate = FALSE,
file = paste0("comAgWatACT_multiplePOT_", t, ".mz")
)


# Share current irrigation water that can be fulfilled by available water resources
calcOutput("ShrHumanUsesFulfilled",
transDist = t,
lpjml = lpjml, climatetype = climatetype,
selectyears = selectyears, iniyear = iniyear,
efrMethod = efrMethod, aggregate = FALSE,
multicropping = "TRUE:actual:irrig_crop",
file = paste0("shrHumanUsesFulfilledMultiple_", t, ".mz")
)
calcOutput("ShrHumanUsesFulfilled",
transDist = t,
lpjml = lpjml, climatetype = climatetype,
selectyears = selectyears, iniyear = iniyear,
efrMethod = efrMethod, aggregate = FALSE,
multicropping = FALSE,
file = paste0("shrHumanUsesFulfilledSingle_", t, ".mz")
)
}

##############
# VALIDATION #
##############
# Multiple cropping suitability per crop calculated based on crop and grass productivity
# (for LPJmL crop types)
calcOutput("MulticroppingSuitability",
lpjml = lpjml, climatetype = climatetype,
selectyears = selectyears, suitability = "endogenous",
aggregate = FALSE, file = "suitMC_LPJmL.mz"
)

# Multiple cropping zones according to GAEZ
calcOutput("MultipleCroppingZones",
layers = 8,
aggregate = FALSE, file = "suitMC_GAEZ.mz"
)

# Inverted Growing Period Runs
# crop yields



###########
# Revenue #
###########
Expand Down Expand Up @@ -273,151 +433,7 @@ fullMULTICROPPING <- function() {



# ### Yield Gain ###
# # Single cropping yield gain
# calcOutput("IrrigYieldImprovementPotential", unit = "USD_ha:GLO",
# lpjml = lpjml, climatetype = climatetype,
# selectyears = selectyears, iniyear = iniyear,
# comagyear = NULL, efrMethod = efrMethod, transDist = 0,
# irrigationsystem = irrigationsystem, landScen = paste0("potCropland:", "NULL"),
# cropmix = "hist_irrig", yieldcalib = yieldcalib,
# multicropping = FALSE, aggregate = FALSE,
# file = "yieldgain_single.mz")
#
# # Multiple cropping yield gain
# calcOutput("IrrigYieldImprovementPotential", unit = "USD_ha:GLO",
# lpjml = lpjml, climatetype = climatetype,
# selectyears = selectyears, iniyear = iniyear,
# comagyear = NULL, efrMethod = efrMethod, transDist = 0,
# irrigationsystem = irrigationsystem, landScen = paste0("potCropland:", "NULL"),
# cropmix = "hist_irrig", yieldcalib = yieldcalib,
# multicropping = TRUE, aggregate = FALSE,
# file = "yieldgain_multiple.mz")

# Agricultural Water Consumption (NOLIM) [in mio. m^3 per year]
calcOutput("WaterUseCommittedAg",
lpjml = lpjml, climatetype = climatetype,
selectyears = selectyears, iniyear = iniyear,
multicropping = FALSE, aggregate = FALSE,
file = "comAgWat_single_NOLIM.mz")
calcOutput("WaterUseCommittedAg",
lpjml = lpjml, climatetype = climatetype,
selectyears = selectyears, iniyear = iniyear,
multicropping = "TRUE:actual:irrig_crop", aggregate = FALSE,
file = "comAgWat_multipleACT_NOLIM.mz")
calcOutput("WaterUseCommittedAg",
lpjml = lpjml, climatetype = climatetype,
selectyears = selectyears, iniyear = iniyear,
multicropping = "TRUE:potential:endogenous", aggregate = FALSE,
file = "comAgWat_multiplePOT_NOLIM.mz")

for (t in c(0, 100, 200)) {

# Committed agricultural area
calcOutput("IrrigAreaActuallyCommitted",
fossilGW = FALSE,
lpjml = lpjml, climatetype = climatetype,
selectyears = selectyears, iniyear = iniyear,
efrMethod = efrMethod, transDist = t,
multicropping = FALSE, aggregate = FALSE,
file = paste0("comAgAreaACT_single_", t, ".mz"))

calcOutput("IrrigAreaActuallyCommitted",
fossilGW = FALSE,
lpjml = lpjml, climatetype = climatetype,
selectyears = selectyears, iniyear = iniyear,
efrMethod = efrMethod, transDist = t,
multicropping = "TRUE:actual:irrig_crop",
aggregate = FALSE,
file = paste0("comAgAreaACT_multipleACT_", t, ".mz"))

calcOutput("IrrigAreaActuallyCommitted",
fossilGW = FALSE,
lpjml = lpjml, climatetype = climatetype,
selectyears = selectyears, iniyear = iniyear,
efrMethod = efrMethod, transDist = t,
multicropping = "TRUE:potential:endogenous",
iteration = "committed_agriculture_fullPotential",
aggregate = FALSE,
file = paste0("comAgAreaACT_multiplePOT_", t, ".mz"))


# Committed Agricultural water uses
calcOutput("RiverHumanUseAccounting",
iteration = "committed_agriculture",
lpjml = lpjml, climatetype = climatetype,
efrMethod = efrMethod,
selectyears = selectyears, iniyear = iniyear,
transDist = t, comAg = TRUE,
accessibilityrule = NULL,
rankmethod = NULL, gainthreshold = NULL,
cropmix = NULL, yieldcalib = NULL,
irrigationsystem = NULL, landScen = NULL,
multicropping = FALSE,
aggregate = FALSE,
file = paste0("comAgWatACT_single_", t, ".mz"))
calcOutput("RiverHumanUseAccounting",
iteration = "committed_agriculture",
lpjml = lpjml, climatetype = climatetype,
efrMethod = efrMethod,
selectyears = selectyears, iniyear = iniyear,
transDist = t, comAg = TRUE,
accessibilityrule = NULL,
rankmethod = NULL, gainthreshold = NULL,
cropmix = NULL, yieldcalib = NULL,
irrigationsystem = NULL, landScen = NULL,
multicropping = "TRUE:actual:irrig_crop",
aggregate = FALSE,
file = paste0("comAgWatACT_multipleACT_", t, ".mz"))
calcOutput("RiverHumanUseAccounting",
iteration = "committed_agriculture_fullPotential",
lpjml = lpjml, climatetype = climatetype,
efrMethod = efrMethod,
selectyears = selectyears, iniyear = iniyear,
transDist = t, comAg = TRUE,
accessibilityrule = NULL,
rankmethod = NULL, gainthreshold = NULL,
cropmix = NULL, yieldcalib = NULL,
irrigationsystem = NULL, landScen = NULL,
multicropping = "TRUE:potential:endogenous",
aggregate = FALSE,
file = paste0("comAgWatACT_multiplePOT_", t, ".mz"))


# Share current irrigation water that can be fulfilled by available water resources
calcOutput("ShrHumanUsesFulfilled",
transDist = t,
lpjml = lpjml, climatetype = climatetype,
selectyears = selectyears, iniyear = iniyear,
efrMethod = efrMethod, aggregate = FALSE,
multicropping = "TRUE:actual:irrig_crop",
file = paste0("shrHumanUsesFulfilledMultiple_", t, ".mz"))
calcOutput("ShrHumanUsesFulfilled",
transDist = t,
lpjml = lpjml, climatetype = climatetype,
selectyears = selectyears, iniyear = iniyear,
efrMethod = efrMethod, aggregate = FALSE,
multicropping = FALSE,
file = paste0("shrHumanUsesFulfilledSingle_", t, ".mz"))

}

##############
# VALIDATION #
##############
# Multiple cropping suitability per crop calculated based on crop and grass productivity
# (for LPJmL crop types)
calcOutput("MulticroppingSuitability",
lpjml = lpjml, climatetype = climatetype,
selectyears = selectyears, suitability = "endogenous",
aggregate = FALSE, file = "suitMC_LPJmL.mz")

# Multiple cropping zones according to GAEZ
calcOutput("MultipleCroppingZones", layers = 8,
aggregate = FALSE, file = "suitMC_GAEZ.mz")

# Inverted Growing Period Runs
# crop yields

}

Expand Down
Loading

0 comments on commit 24f09e4

Please sign in to comment.