regrid: Regrid ir/regular data

View source: R/EFDR_functions.R

regridR Documentation

Regrid ir/regular data

Description

Given a data frame with fields x, y and z, regrid returns a data frame with fields x, y and z, this time with x, y arranged on a regular grid of size n2 by n1.

Usage

regrid(
  df,
  n1 = 128,
  n2 = n1,
  method = "idw",
  idp = 0.5,
  nmax = 7,
  model = "Exp"
)

Arguments

df

data frame with fields x, y and z

n1

image length in pixels

n2

image height in pixels

method

method to be used, see details

idp

inverse distance power

nmax

when using inverse distance weighting, the number of nearest neighbours to consider when interpolating using idw. When using conditional simulation, the number of nearest observations to used for a kriging simulation

model

the model type when using conditional simulation (use gstat::vgm() to list all possible models)

Details

There are three supported methods for regridding. The first, "idw", is the inverse-distance-weighting method. The function overlays a grid over the data. The cells are constructed evenly within the bounding box of the data and filled with interpolated values using the inverse weighting distance metric with power idp. nmax determines the maximum number of neighbours when using the distance weighting. With this method, interpolation uses the inverse distance weight function gstat in the gstat package. Refer to the package gstat for more details and formulae.

The second method "cond_sim" uses conditional simulation to generate a realisation of the unobserved process at the grid points. This is a model-based approach, and the variogram model may be selected through the parameter model. The exponential variogram is used by default. For a complete list of possible models use gstat::vgm(). For a tutorial on how the conditional simulation is carried out see the gstat vignette.

The third method "median_polishing" applies a median polish to the data. First, a grid is overlayed. If more than one data point is present in each grid box, the mean of the data is taken. Where there is no data, the grid box is assigned a value of NA. This gridded image is then passed to the function medpolish which carried out Tukey's median polish procedure to obtain an interpolant of the form z(s) = \mu + a(s1) + b(s2) where s1 is the x-axis and s2 is the y-axis. Missing points in the gridded image are then replaced with z(s) evaluated at these points. This method cannot be used if all rows and columns do not contain at least one data point.

Value

data frame with fields x,y,z

Examples

df <- data.frame(x = runif(200),y = runif(200),z=rnorm(200))
df.gridded <- regrid(df, n1=10)

EFDR documentation built on Aug. 23, 2023, 1:07 a.m.