tradeoff_mod: Spatial tradeoffs model

Description Usage Arguments Details Value Note Examples

View source: R/tradeoff_mod.R

Description

Master module that calls four major modules and associated helper functions, to create a single land use tradeoff scenario.

Usage

1
2
tradeoff_mod(prod_targ, ybetas, cbetas, input_key = "ZA", ybeta_update = 1,
  exist_list = NULL, ctype = "+", silent = TRUE)

Arguments

prod_targ

Production targets passed as list. See examples for format.

ybetas

list of 2 rasters or 2 vectors providing yield modifications

cbetas

Vector of constraints to apply to land use. See examples.

input_key

Country/location code indicating input data to load.

ybeta_update

1 (default) or 0 - determines whether yield_mod_* is run.

ctype

Specific multiplicative ("X") or additive ("+") constraints

silent

Silent or verbose mode (TRUE [default] or FALSE)

Details

Much of the detail of running the model, and examples that help to illustrate it, are in the examples for the individual model components, including checks for consistency between "D" and "R" versions.

Value

Data.frame of impacts, and data.table referencing conversions.

Note

The impacts module has to be fixed still to not double-count impacts resulting from multi-season cropping in converted pixels.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# Some inputs
load("data/cropnames.rda")
rc <- run_code(input_key = "ZA")

# # dummy climate/irrigation modifiers
# dfact <- c(0.9, 1.2)
# ybetas <- lapply(1:2, function(x) {
#   m <- brick("external/ext_data/ZA-crop-areas.tif")
#   r <- m
#   r <- setValues(r, values = rnorm(n = ncell(r) * nlayers(r), mean = dfact[x],
#                  sd = 0.05))
# nm_up(mask(r, m, maskvalue = 0), cropnames)
# })

ybetas <- list(1, 1)
prod_targ <- c("maize" = 4, "cassava" = 2, "ground" = 2, "cotton" = 2,
               "soy" = 2, "pulse" = 2, "sunflower" = 2, "sugarcane" = 2,
               "wheat" = 2)

# cbeta vector
cbetas <- c(0.5, 0.5, 0, 0)
names(cbetas) <- c("Ag", "C", "bd", "cost")

# Comparing the two versions
system.time(tdt <- tradeoff_mod(prod_targ, ybetas, cbetas))  # 2.5 seconds
system.time(tdr <- tradeoff_mod(prod_targ, ybetas, cbetas, input = "R"))  # 6
identical(tdt$impacts, tdr$impacts)  # check output stats for consistency

CRSobj <- projection(raster("external/ext_data/ZA-carbon-priorities.tif"))
plot(dt_to_raster(tdt$conv, CRSobj = CRSobj) - tdr$conv)  # check maps

marcusspiegel/agroEcoTradeoff documentation built on May 21, 2019, 11:44 a.m.