Description Usage Arguments Details Value Examples
This function determines the per pixel probability of a field being converted for a crop as a function of that crop's yield, as well as any constraints related to carbon, biodiversity, and travel costs, factoring in any prior yield modifications made (e.g. due to climate change or added irrigation). This version uses data.tables rather than raster and reframes the constraints as per yield potential.
1 | constraints(inlist, cbetas, silent = TRUE)
|
inlist |
A list of data.tables for the four constraints |
cbetas |
4 element vector (values 0-1, summing to 1) of land use weights |
silent |
TRUE, otherwise FALSE gives verbose mode |
code |
Unique simulation code resulting from run_code function |
cropnames |
Vector of crop names in analysis |
For inlist, the input should be a named list, with the first element named "Y, then "C", "BD", and "COST". The weights must sum to 1, regardless of how they are apportioned. For weights of 1/3, write them to at least the third decimal place (code tolerates summing to 0.999)
data.table of conversion probabilities for each crop
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 | rc <- run_code(input_key = "ZA")
il <- fetch_inputs(input_key = "ZA") # fetch all necessary inputs
# ybetas <- list(1, 1)
# ybeta <- yield_mod(inlist = il_dt[[2]][c("p_yield")],
# ybetas = ybetas, code = rc, cropnames = il$cropnames)
inlist <- list("y_std" = il$y_std, "C" = il$carbon_p, "bd" = il$cons_p,
"cost" = il$cost_p)
CRSobj <- spatial_meta("ZA")$crs
# Checking case where yields are excluded
cbetas <- c("y_std" = 0, "C" = 0.333, "bd" = 0.333, "cost" = 0.333)
con1 <- constraints(inlist = inlist, cbetas = cbetas, code = rc,
cropnames = il$cropnames)
#con1[, lapply(.SD, max, na.rm = TRUE)]
# all four constraints
cbetas <- c("Y" = 0.25, "C" = 0.25, "BD" = 0.25, "COST" = 0.25)
con2 <- constraints(inlist = inlist, cbetas = cbetas, code = rc,
cropnames = il$cropnames)
con2r <- dt_list_to_raster(base = il$mask, inlist = list(con2),
CRSobj = CRSobj)[[1]]
plot(con2r)
# current function versus shorter code (current version much faster)
system.time(con2 <- constraints(inlist = inlist, cbetas = cbetas, code = rc,
cropnames = il$cropnames))
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.