Format the input data and generate the configuration file required for ANUSPLIN interpolation.

anusplin_make_param(
  dat,
  basename,
  range,
  res = 0.25,
  order = 3L,
  unit = 0L,
  width = 9,
  missing = -9999L,
  file.alt = NULL,
  alt = c("cov", "spl"),
  type.alt = "arcinfo_grid",
  type.grd = "xyz",
  type.mask = "none",
  file.mask = NULL,
  cvt.lon = c(0, 5),
  cvt.lat = c(0, 5),
  cvt.alt = c(1, 1),
  cvt.coef = 1000,
  trans.dep = 0,
  err.wgt = 0,
  optimize = 1,
  smooth = 1,
  ...,
  err.cov = 2,
  grid.pos = 1,
  essential = TRUE
)

Arguments

dat

A data.frame or data.table to interpolate, for the colnames, lon, lat must be included, site and alt are optional, the others are variable names.

basename

Basename for all output files, extensions should not be included.

range

Range of interpolation grid (xmin, xmax, ymin, ymax).

res

The grid resolution (degree).

order

(default 3L), order of spline, a positive integer.

unit

The unit of dat, a non-negative integer, possible values are:

  • 0: undefined (default)

  • 1: meteres

  • 2: feet

  • 3: kilometers

  • 4: miles

  • 5: degrees

  • 6: radians

  • 7: millimetres

  • 8: megajoules

width

The fixed width of numbers in formatted data.

missing

Filling of missing values.

file.alt

file path of alt

  • type.alt != "none": file.alt is file path

  • type.alt == "none": file.alt is a const real number

alt

Type of elevation was treated, possible values are:

  • cov : considered as independent covariates (default)

  • spl : considered as independent spline variables

type.alt

type of grid, one of c("const", "generic_grid", "arcinfo_grid", "idrisi_img"), default arcinfo_grid

type.grd

type of grid, one of c("xyz", "generic_grid", "arcinfo_grid", "idrisi_img"), default arcinfo_grid

type.mask

type of file.mask, one of c("none", "generic_grid", "arcinfo_grid", "idrisi_img"), default arcinfo_grid`.

file.mask

Filename of mask grid, only valid if type.mask set to positive integer.

cvt.lon

Transformation and scale factor (default is 1) of longitude.
Real Value = (Table Value) * (Scale Factor)

The possible transformations are:

  • 0: no transformation (default)

  • 1: x/a

  • 2: ax

  • 3: a·log(x+b)

  • 4: (x/b)^a

  • 5: a·exp(x/b)

  • 6: a·tanh(x/b)

  • 7: anisotropy angle in degrees

  • 8: anisotropy factor - in the direction specified by the anisotropy angle

cvt.lat

Same as cvt.lon, but for latitude.

cvt.alt

Same as cvt.lon, but for altitude.

cvt.coef

Parameters used for transformation, one or two real numbers.

trans.dep

Dependent variable transformation, possible values are:

  • 0: no transformation (default)

  • 1: fit surface to natural logarithm of the data values

  • 2: fit surface to the square root of the data values

  • 5: occurrence – transform data values by setting all positive value to 1.0 and ignoring all negative values

err.wgt

Number of relative error variances, a non-negative integer, possible values are:

  • 0: data points uniformly weighted for each surface (default)

  • 1: the same weighting is applied to each surface

  • Number of surfaces: a different weighting is applied to each surface

optimize

Optimization directive, a non-negative integer, possible values are:

  • 0: common smoothing parameter for all surfaces

  • 1: common smoothing directive for all surfaces (default)

  • 2: different smoothing directive for each surface

smooth

Smoothing directive for each surface, a non-negative integer, possible values are:

  • 0: fixed smoothing parameter - supply value

  • 1: minimise GCV (default)

  • 2: minimise true mean square error using supplied error standard deviation estimate

  • 3: fixed signal - supply value

  • 4: minimise GML

...

ignored.

err.cov

test

grid.pos

Grid position option, a non-negative integer, possible values are:

  • 0: grid points at cell corners

  • 1: grid points at cell centres (default)

essential

If True, only export essential process files, large residual file, optimisation parameters file, data list file and validation data file are ignored.

lim.lon

A vector containing lower and upper limits, auto (default) meant to use the minimum and maximum values in the data, or set manually. Data points outside these limits, augmented by margins, are ignored.

lim.lat

Same as lim.lon, but for longitude.

lim.alt

Same as lim.lon, but for altitude.

Value

a list with three components:

  • data : formatted data.table of dat

  • splina : a vector containing splina parameters

  • lapgrd : a vector containing lapgrd parameters

grid_type

  • none : not provided

  • xyz : grid written in X,Y,Z format

  • generic_grid : generic grid written by rows

  • arcinfo_grid : Arc/Info grid

  • idrisi_img : Idrisi image

Examples

if (FALSE) {
dat <- dat_RH[, .(lon, lat, alt, RH)]
X <- dat[, .(lon, lat, alt)] %>% as.matrix()
Y <- dat[, .(RH)] %>% as.matrix()

res <- 1
range <- c(70, 140, 15, 55)
r_dem <- get_chinadem(res = res) %>% round(1)
f_dem <- "output/dem.asc"
write_dem(r_dem, f_dem, digits = 1)

outdir <- "output"

anusplin_make_param(dat, "RH", range, res, file.alt = f_dem, cvt.coef = 1e3) -> param
anusplin_write_setting(param, outdir, is.run = TRUE, overwrite = TRUE)
anusplin_read_output(param$lapgrd, outdir) -> ans

ans
}