Skip to content

Commit

Permalink
reorder functions to have most computationally expensive in the end i…
Browse files Browse the repository at this point in the history
…n fullSIMPLE
  • Loading branch information
FelicitasBeier committed Sep 15, 2023
1 parent fd9619c commit ec536df
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 66 deletions.
2 changes: 1 addition & 1 deletion .buildlibrary
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
ValidationKey: '37778490'
ValidationKey: '37798105'
AcceptedWarnings:
- 'Warning: package ''.*'' was built under R version'
- 'Warning: namespace ''.*'' is not available and has been replaced'
Expand Down
2 changes: 1 addition & 1 deletion CITATION.cff
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ 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.26
version: 1.9.27
date-released: '2023-09-15'
abstract: Provides functions for MAgPIE cellular input data generation and stand-alone
water calculations.
Expand Down
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Type: Package
Package: mrwater
Title: madrat based MAgPIE water Input Data Library
Version: 1.9.26
Version: 1.9.27
URL: https://github.com/pik-piam/mrwater,
https: //doi.org/10.5281/zenodo.5801680
License: LGPL-3 | file LICENSE
Expand Down
121 changes: 61 additions & 60 deletions R/fullSIMPLE.R
Original file line number Diff line number Diff line change
Expand Up @@ -76,66 +76,6 @@ fullSIMPLE <- function(transDist = 100, fossilGW = TRUE,
aggregate = FALSE,
file = "EFRshare.mz")

# To derive the country-/basin-level transformation elasticity
# for the CET function, PIA is calculated for different thresholds
calcOutput("EconOfIrrig", scenario = ssp, output = "IrrigArea",
gtrange = seq(0, 3000, 100),
selectyears = selectyears, iniyear = iniyear,
lpjml = lpjml, climatetype = climatetype,
efrMethod = efrMethod, accessibilityrule = accessibilityrule,
rankmethod = rankmethod, yieldcalib = yieldcalib,
allocationrule = allocationrule,
irrigationsystem = irrigationsystem, cropmix = cropmix,
landScen = "currCropland:NULL",
comAg = FALSE, transDist = transDist, fossilGW = fossilGW,
multicropping = multicropping, aggregate = FALSE,
file = paste0("IrrigArea", "EconCUR.mz"))

# Current cropland area
calcOutput("CropareaAdjusted",
iniyear = iniyear, dataset = "Toolbox",
aggregate = FALSE,
file = "croparea.mz")

calcOutput("CropAreaShare", iniyear = iniyear, cropmix = "hist_rainf",
aggregate = FALSE, file = "cropmix_rf.mz")
calcOutput("CropAreaShare", iniyear = iniyear, cropmix = "hist_irrig",
aggregate = FALSE, file = "cropmix_ir.mz")
calcOutput("CropAreaShare", iniyear = iniyear, cropmix = "hist_total",
aggregate = FALSE, file = "cropmix_tot.mz")

# Crop yields (in USD/ha)
calcOutput("YieldsValued", lpjml = lpjml, climatetype = climatetype,
iniyear = iniyear, selectyears = selectyears,
yieldcalib = yieldcalib,
priceAgg = str_split(rankmethod, pattern = ":")[[1]][2],
multicropping = FALSE, aggregate = FALSE,
file = "yields.mz")

# Yield gain through irrigation (in )
# Cellular yield improvement potential for all crops (in USD/ha)
calcOutput("IrrigYieldImprovementPotential",
selectyears = selectyears, iniyear = iniyear,
lpjml = lpjml, climatetype = climatetype, cropmix = cropmix,
unit = thresholdtype, yieldcalib = yieldcalib,
comagyear = NULL, efrMethod = NULL, transDist = NULL,
irrigationsystem = irrigationsystem,
landScen = "currCropland:NA",
multicropping = as.logical(stringr::str_split(multicropping, ":")[[1]][1]),
aggregate = FALSE,
file = "yieldgainCUR.mz")

calcOutput("IrrigYieldImprovementPotential",
selectyears = selectyears, iniyear = iniyear,
lpjml = lpjml, climatetype = climatetype, cropmix = cropmix,
unit = thresholdtype, yieldcalib = yieldcalib,
comagyear = NULL, efrMethod = NULL, transDist = NULL,
irrigationsystem = irrigationsystem,
landScen = "potCropland:NA",
multicropping = as.logical(stringr::str_split(multicropping, ":")[[1]][1]),
aggregate = FALSE,
file = "yieldgainPOT.mz")

# The transformation elasticity between rainfed and irrigated area (tau_Li)
# is calculated based on currently irrigated area and the maximum
# potentially irrigated area
Expand Down Expand Up @@ -317,4 +257,65 @@ fullSIMPLE <- function(transDist = 100, fossilGW = TRUE,
fossilGW = fossilGW, transDist = transDist,
aggregate = FALSE,
file = "comAgWat.mz")

# Current cropland area
calcOutput("CropareaAdjusted",
iniyear = iniyear, dataset = "Toolbox",
aggregate = FALSE,
file = "croparea.mz")

calcOutput("CropAreaShare", iniyear = iniyear, cropmix = "hist_rainf",
aggregate = FALSE, file = "cropmix_rf.mz")
calcOutput("CropAreaShare", iniyear = iniyear, cropmix = "hist_irrig",
aggregate = FALSE, file = "cropmix_ir.mz")
calcOutput("CropAreaShare", iniyear = iniyear, cropmix = "hist_total",
aggregate = FALSE, file = "cropmix_tot.mz")

# Crop yields (in USD/ha)
calcOutput("YieldsValued", lpjml = lpjml, climatetype = climatetype,
iniyear = iniyear, selectyears = selectyears,
yieldcalib = yieldcalib,
priceAgg = str_split(rankmethod, pattern = ":")[[1]][2],
multicropping = FALSE, aggregate = FALSE,
file = "yields.mz")

# Yield gain through irrigation (in )
# Cellular yield improvement potential for all crops (in USD/ha)
calcOutput("IrrigYieldImprovementPotential",
selectyears = selectyears, iniyear = iniyear,
lpjml = lpjml, climatetype = climatetype, cropmix = cropmix,
unit = thresholdtype, yieldcalib = yieldcalib,
comagyear = NULL, efrMethod = NULL, transDist = NULL,
irrigationsystem = irrigationsystem,
landScen = "currCropland:NA",
multicropping = as.logical(stringr::str_split(multicropping, ":")[[1]][1]),
aggregate = FALSE,
file = "yieldgainCUR.mz")

calcOutput("IrrigYieldImprovementPotential",
selectyears = selectyears, iniyear = iniyear,
lpjml = lpjml, climatetype = climatetype, cropmix = cropmix,
unit = thresholdtype, yieldcalib = yieldcalib,
comagyear = NULL, efrMethod = NULL, transDist = NULL,
irrigationsystem = irrigationsystem,
landScen = "potCropland:NA",
multicropping = as.logical(stringr::str_split(multicropping, ":")[[1]][1]),
aggregate = FALSE,
file = "yieldgainPOT.mz")

# To derive the country-/basin-level transformation elasticity
# for the CET function, PIA is calculated for different thresholds
calcOutput("EconOfIrrig", scenario = ssp, output = "IrrigArea",
gtrange = seq(0, 3000, 100),
selectyears = selectyears, iniyear = iniyear,
lpjml = lpjml, climatetype = climatetype,
efrMethod = efrMethod, accessibilityrule = accessibilityrule,
rankmethod = rankmethod, yieldcalib = yieldcalib,
allocationrule = allocationrule,
irrigationsystem = irrigationsystem, cropmix = cropmix,
landScen = "currCropland:NULL",
comAg = FALSE, transDist = transDist, fossilGW = fossilGW,
multicropping = multicropping, aggregate = FALSE,
file = paste0("IrrigArea", "EconCUR.mz"))

}
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.26**
R package **mrwater**, version **1.9.27**

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

0 comments on commit ec536df

Please sign in to comment.