Learn R Programming

sensors4plumes (version 0.9.3)

spatialSpread: Cost function based on sensor locations only

Description

This is a wrapper function to compute cost of a set of sensors based on their coordinates only. It takes as parameter fun an actual function to compute such cost for each location of the provided simulations and can summarise it with a function fun_R

Usage

spatialSpread(simulations, locations, weightByArea = TRUE, fun, fun_R)

Arguments

simulations

Simulations object or SpatialDataFrame to compute local cost in each location (values are ignored)

locations

indices of locations of sensors

weightByArea

if cost in the locations has to be multiplied by the area associated to them before summary; for "SpatialPointsDataFrame" the factor is 0.

fun

function to compute location-wise cost, for examples see spatialSpreadFunctions; needs the parameters allLocations, locations; can be the result of replaceDefault with type = "fun.spatialSpread"; result must have length number of locations

fun_R

function to summarise the result of fun; must have parameter x, generate by replaceDefault with type = "funR.spatialSpread"

Value

List

cost

result of fun_R, missing if no fun_R given

costLocations

result of fun, length equals number of locations in simulations

Details

The function itself is only a wrapper to turn simulations and locations into the correct form and apply the functions.

Examples

Run this code
# NOT RUN {
# prepare data and functions
data(radioactivePlumes)
data(medianVariogram)

krigingVarianceMedian = 
  replaceDefault(krigingVariance, newDefaults = list(model = medianVariogram))[["fun"]]

meanFun = function(x){mean(x, na.rm = TRUE)}

locationsSensors = sample.int(nLocations(radioactivePlumes), 50)

spatialSpread_minDist = spatialSpread(
    simulations = radioactivePlumes,
    locations = locationsSensors, 
    weightByArea = TRUE,
    fun = minimalDistance,
    fun_R = meanFun
)
spatialSpread_krigingVar = spatialSpread(
    simulations = radioactivePlumes,
    locations = locationsSensors, 
    weightByArea = TRUE,
    fun = krigingVarianceMedian,
    fun_R = meanFun
  )

# plot maps
# }
# NOT RUN {
## takes some seconds
y = radioactivePlumes@locations
y@data$minDist = spatialSpread_minDist[["costLocations"]]
y@data$krigVar = spatialSpread_krigingVar[["costLocations"]]
yPoints = as(y, "SpatialPointsDataFrame")

# distance to next sensor
spplot(y, zcol = "minDist", 
       sp.layout = list("sp.points", yPoints[locationsSensors,], 
                          col = 3))
# kriging variance
spplot(y, zcol = "krigVar", 
       sp.layout = list("sp.points", yPoints[locationsSensors,], 
                          col = 3))
# }

Run the code above in your browser using DataLab