Reciprocal of the sum of the reciprocals of conductance Transition* objects

sumReciprocal(x1, x2)

Arguments

x1

TransitionLayer object

x2

TransitionLayer object

Value

TransitionLayer object containing conductance values.

Details

To calculate the total resistance of two resistors that are serially connected, we should add their resistance values. However, if we work with conductance values, we need to take the reciprocal of the summed reciprocals of the conductance values. This function does that when adding two TransitionLayers with conductance values (matrixValues(tr) == "conductance").

For a TransitionLayer with resistance values (matrixValues(tr) == "resistance"), the function will not take reciprocals for that object, but will still take a reciprocal for the final product (which will consequently have conductance values).

Examples

#Create a new raster and set all its values to unity.
raster <- raster(nrows=18, ncols=36)
raster <- setValues(raster,rep(1,ncell(raster)))

#Create TransitionLayer objects
tr1 <- transition(raster,mean,4)
#> The extent and CRS indicate this raster is a global lat/lon raster. This means that transitions going off of the East or West edges will 'wrap' to the opposite edge.
#> Global lat/lon rasters are not supported under new optimizations for 4 and 8 directions with custom transition functions. Falling back to old method.
tr2 <- tr1
matrixValues(tr1)
#> [1] "conductance"

#Set one to resistance
matrixValues(tr2) <- "resistance"

#Sum the two objects
sumReciprocal(tr1,tr2)
#> class      : TransitionLayer 
#> dimensions : 18, 36, 648  (nrow, ncol, ncell)
#> resolution : 10, 10  (x, y)
#> extent     : -180, 180, -90, 90  (xmin, xmax, ymin, ymax)
#> crs        : +proj=longlat +datum=WGS84 +no_defs 
#> values      : conductance 
#> matrix class: dsCMatrix