interpolate: Interpolate many maps at once - even if they do not fit into...

Description Usage Arguments Value Author(s) Examples

View source: R/interpolate.R

Description

interpolate is a wrapper for idw0 and krige0 to interpolate several maps at once if locations of input values and desired output agree, even if output and maybe even input does not fit into memory. Works by writing output (and maybe input and intermediate results) to raster files.

fitMedianVariogram is a wrapper of autofitVariogram: fits variograms to a sample of plumes of a simulations object and generates a variogram with the median parameters.

Usage

1
2
3
4
interpolate(simulations, locations, kinds = 1, fun_interpolation, 
  tmpfile = "tmp_interpolate", overwrite = FALSE, chunksize = 1e+7)
fitMedianVariogram(simulations, plumes, locations, kinds = 1)
idw0z(formula = z ~ 1, data, newdata, y, idp = 2)

Arguments

simulations

Simulations

locations

indices of locations to be used as input; multiple and invalid values are ignored

plumes

indices of plumes to fit variograms to

kinds

layer of the values of simulations to be used; interpolation can only be applied to one layer: if values is a vector, only the first entry is used in both functions.

fun_interpolation

interpolation function, must have the parameters y, data, newdata (form as for krige0). All other parameters need default values, e.g. the model of krige0 that can be set by replaceDefault with
type = "interpolation_fun.interpolate".

tmpfile

filename for the raster file in case the result does not fit into memory; if FALSE the function stops with a warning and does not create a file

overwrite

boolean, if the file at tmpfile may be overwritten

chunksize

maximal number of cells to be processed at once – forwarded to blockSize inside

formula

formula that defines the dependent variable as linear model of independent variables, forwarded to idw0 – see also there, default is no independent variables

data

data frame with dependent variable and coordinates, forwarded to idw0 – see also there

newdata

data frame or Spatial object with prediction locations, forwarded to idw0 – see also there

y

matrix, forwarded to idw0 – see also there

idp

, forwarded to idw0 – see also there

Value

interpolate returns a RasterLayer-class with the interpolations; it has the same size as the values of the input simulations and belongs to the same locations and plumes. Also projection is the same, so they can be combined by stack. If it does not fit into memory it is saved at tmpfile with the extension "_interpolated.grd". The function may produce intermediate files at tmpfile (with name extensions) that are deleted in the end.

fitMedianVariogram returns a variogram model (vgm).

idw0z is idw0 with one extra default parameter: formula = z ~ 1. This way it can directly be used as fun_interpolation in interpolate.

Author(s)

Kristina B. Helle, kristina.helle@uni-muenster.de

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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
## Not run: 
## takes some time
# get data
data(radioactivePlumes)

# generate median variogram from plumes
\dontrun{
## takes some seconds
medianVariogram = fitMedianVariogram(simulations = radioactivePlumes, 
                              plumes = 1:nPlumes(radioactivePlumes),
                              kinds = 1)
}
## the result is in:
data(medianVariogram)

# prepare interpolation function 
krige0var = replaceDefault(krige0, newDefaults = list(
  formula = z ~ 1, model = medianVariogram, beta = NA, ... = NA),
  type = "fun_interpolation.interpolate")[[1]]

# sample locations: proposed sensors
sampleLocations = sample.int(nLocations(radioactivePlumes), 50)

# interpolate
interpolated = interpolate(
  simulations = radioactivePlumes,
  kinds = 1,
  locations = sampleLocations,
  fun_interpolation = krige0var)
  
# combine plot original and interpolated
originalAndInterpolated = radioactivePlumes
originalAndInterpolated@values = stack(
  originalAndInterpolated@values[[1]], interpolated)

OriginalAndInterpolated = extractSpatialDataFrame(
  originalAndInterpolated, plumes = 1:4)

samplePoints = 
  as(OriginalAndInterpolated, "SpatialPointsDataFrame")[sampleLocations,]
spplotLog(OriginalAndInterpolated,
  sp.layout = list("sp.points", 
    samplePoints, col = 3))
spplot(OriginalAndInterpolated,
  sp.layout = list("sp.points", 
    samplePoints, col = 3))


## End(Not run)

sensors4plumes documentation built on May 1, 2019, 10:27 p.m.