sk_rescale {snapKrig} | R Documentation |
Up or down-scale a sk grid by an integer factor
Description
Changes the resolution of a sk grid by a factor of up
or down
. For down-scaling, this
introduces NA
s at unobserved grid points (and does no interpolation).
Usage
sk_rescale(g, up = NULL, down = NULL)
Arguments
g |
a sk grid or any grid object accepted by |
up |
integer > 0, or vector of two, the up-scaling factors |
down |
integer > 0, or vector of two, the down-scaling factors |
Details
Users should specify a sk grid g
to re-scale and an integer scaling factor; either up
or down
(and not both). This effects the scaling of resolution (g[['gres']]
) by up
or 1/down
.
up
(or down
) should be a vector of two positive integers, the desired re-scaling
factors in the y and x dimensions, in that order, or a single value to be used for both.
When up
is supplied, a lower resolution grid is returned comprising every up
th grid
line of g
along each dimension. All other grid lines, and any data values lying on them,
are ignored. up
should be no greater than dim(g) - 1
. Note that if up
does not
evenly divide this number, the bounding box will shrink slightly.
When down
is supplied, the function returns a higher resolution grid (say g_fine
) with
the same bounding box as g
. Along each dimension, every down
th grid line of g_fine
coincides with a grid line of g
. Any non-NA values found in g[]
are copied to g_fine
,
and g
can be recovered from g_fine
with sk_rescale(g_fine, up=down)
.
Value
a sk grid of the requested resolution
See Also
sk sk_cmean
Other indexing functions:
sk_mat2vec()
,
sk_sub_find()
,
sk_sub_idx()
,
sk_vec2mat()
Other sk constructors:
sk_snap()
,
sk_sub()
,
sk()
Examples
# example data
gdim = c(50, 53)
pars = utils::modifyList(sk_pars(gdim), list(eps=1e-2))
g = sk_sim(gdim, pars)
plot(g)
# upscale
plot(sk_rescale(g, up=1)) # does nothing
plot(sk_rescale(g, up=2))
# downscale
sk_plot(sk_rescale(g, down=1)) # does nothing
sk_plot(sk_rescale(g, down=2))
# length-2 vectors to rescale differently in x and y directions
plot(sk_rescale(g, up=c(2,3)))
plot(sk_rescale(g, down=c(2,3)))
# invert a down-scaling
g_compare = sk_rescale(sk_rescale(g, down=c(5,3)), up=c(5,3))
all.equal(g, g_compare)
# multi-layer example with about 50% of points missing
idx_miss = sample.int(length(g), round(0.5*length(g)))
g_multi = sk_sim(gdim, pars, n_layer=3)
g_multi[idx_miss,] = NA
# plot third layer, then down-scaled and up-scaled versions
sk_plot(g_multi, layer=3)
sk_plot(sk_rescale(g=g_multi, down=2), layer=3)
sk_plot(sk_rescale(g=g_multi, up=2), layer=3)