Skip to contents

Perform simple operations (sum, sub, mult, div) on one or multiple landscapes (see details for use cases)

Usage

sum_lscps(lscps, num = NULL, average = TRUE)
mult_lscps(lscps, num = NULL)
sub_lscps(lscps, binary = FALSE)
div_lscps(lscps, binary = FALSE)

Arguments

lscps

A named list containing datasets of spatial data to apply operations (see details).

num

Optional. Defaults to NULL. A vector containing a single numeric scalar or numeric vector with length = lscps to scale by when using sum_lscps and mult_lscps(). If NULL, these functions will operate between lscps. If num is provided, these functions will operate between lscps and num.

binary

If subracting or dividing landscapes, binarize result to obtain logical [0,1] result (see details for use case)

average

if summation is performed, should the result be averaged for the number of landscapes

Details

Simple operations are applied to one or more landscapes depending on use case. Spatial datasets can be supplied in an XYZ dataframe, or as any landscape output from Morphoscape.

sum - sum a single spatial dataset/landscape with a single scalar (lscp1 + num1); sum two or more spatial datasets/landscapes together (lscp1 + lscp2 ... lscpN); or sum multiple landscapes with multiple scalars ((lscp1, lscp2 ... lscpN) + (num1, num2, ..., numN))

mult - multiply a single spatial dataset/landscape with a single scalar (lscp1 * num1); multiply two or more spatial datasets/landscapes together (lscp1 * lscp2 ... lscpN); or multiply multiple landscapes with multiple scalars ((lscp1, lscp2 ... lscpN) * (num1, num2, ..., numN))

sub - substract one spatial dataset/landscape from another (lscp1 - lscp2). If numeric subtraction is desired, use sum_lscps with negative num values.

div - divide one spatial dataset by another (lscp1 / lscp2).

sub_lscps() and div_lscps can be used to construct transition landscapes per (Dickson et al 2020) which can compare performance between two adaptive regimes. If binary = T is used, the result will be a spatial representation of which parent landscape dominates. However, it is recommended to use trans_lscps or adpt_regions to calculate transtional landscapes or adaptive regions (not yet implemented).

Value

An object of class "combined.surface" containing XYZ spatial data.

Author

Blake V. Dickson

See also

krige_surf, calcGrpWprime, calc_lscp, calcPoly, trans_lscps, adpt_regions

Examples

require("Morphoscape")

data("turtles")
data("warps")

fnc_df <- as_fnc_df(warps, 
                       func.names = c("hydro", "curve", "mech", "fea"))

kr_surf <- krige_surf(fnc_df, new_data = turtles)
#> [using ordinary kriging]
#> [using ordinary kriging]
#> [using ordinary kriging]
#> [using ordinary kriging]
#> [using ordinary kriging]
#> [using ordinary kriging]
#> [using ordinary kriging]
#> [using ordinary kriging]

grid_weights <- generate_weights(n = 10, data = kr_surf)
#> 286 rows generated

all_lscps <- calc_all_lscps(kr_surf,
                            grid_weights = grid_weights)

wprime_S <- calcGrpWprime(all_lscps,
                          index = Ecology == "S")

wprime_T <- calcGrpWprime(all_lscps,
                          index = Ecology == "T")
                          
lscps <- list(wprimeS = wprime_S, wprime_T = wprime_T)
                       
# summing multiple landscapes together

summed_surfs <- sum_lscps(lscps, average = TRUE)

# summing landscapes by one or more numeric scalars

summed_surfs <- sum_lscps(lscps, num = c(1.5, -1.15)) # multiple numeric, with subtraction

# multiplying mutliple landscapes together
mult_surfs <- mult_lscps(lscps) # multiply landscapes together

# multiplying landscapes by one or more numeric scalars
mult_surfs <- mult_lscps(lscps, num = 2) # apply numeric multiplier to all landscapes
mult_surfs <- mult_lscps(lscps, num = c(1.2, 0.8)) # apply numeric elements to each landscape

# substract or divide two landscapes

sub_surf <- sub_lscps(lscps)
div_surf <- div_lscps(lscps)

# with binary result

sub_surf <- sub_lscps(lscps, binary = TRUE)
div_surf <- div_lscps(lscps, binary = TRUE)