Interpolation of points on a rmf_2d/3d/4d_array

rmf_interpolate(...)

# S3 method for rmf_2d_array
rmf_interpolate(
  array,
  dis,
  xout,
  yout,
  obj = NULL,
  method = "linear",
  outside = "nearest",
  prj = rmf_get_prj(dis),
  mask = array * 0 + 1
)

# S3 method for rmf_3d_array
rmf_interpolate(
  array,
  dis,
  xout,
  yout,
  zout,
  obj = NULL,
  method = "linear",
  outside = "nearest",
  prj = rmf_get_prj(dis),
  mask = array * 0 + 1
)

# S3 method for rmf_4d_array
rmf_interpolate(
  array,
  dis,
  xout,
  yout,
  zout,
  tout,
  obj = NULL,
  method = "linear",
  outside = "nearest",
  time = "step",
  prj = rmf_get_prj(dis),
  mask = array(1, dim = dim(array)[1:3])
)

Arguments

array

numeric rmf_2d/3d/4d_array

dis

RMODFLOW dis object

xout

x coordinates of points to interpolate to

yout

y coordinates of points to interpolate to

obj

sf or sfc point or multipoint object to obtain the point locations from. Overrides xout, yout and zout. Needs to be of XYZ dimension when array is 3d or 4d.

method

interpolation method. Possible methods are 'nearest' for nearest-neighbor or 'linear' (default) for bi/trilinear interpolation.

outside

'nearest' or 'drop'. Defines how interpolated points outside the convex hull described by the cell nodes should be handled for method = 'linear'. 'nearest' (default) sets the values equal to the nearest nodal value, 'drop' sets them to NA.

prj

RMODFLOW prj object

mask

a 2d array when array is 2d or a 3d array when array is 3d or 4d that can be coerced to logical. Used to set inactive cells to NA. Defaults to all cells active.

zout

z coordinates of points to interpolate to when the array is 3d or 4d.

tout

time instances to interpolate to when the array is 4d. Either as a fractional time step or as total simulated time, depending on the time argument.

time

either 'step' (default) or 'totim'. Defines if tout is a time step fraction (i.e. index for the 4th dimension) or the absolute time. If totim, the array should have a totim attribute, e.g. as returned from rmf_read_head

Value

a vector with the interpolated values for each point.

Details

Users must make sure that the projection of xout, yout, zout or obj are the same as the one described by the prj argument. Function assumes the 2d array is not a cross-section. Consider using a 3d array if the vertical dimension is of any concern. Extrapolation is not supported: values outside the grid are set to NA. Values inside the grid but outside the convex hull described by the cell nodes depend on the 'outside' argument when method = 'linear'.

Interpolation of a point on a 4d array is performed by 3d interpolation at the nearest time steps followed by a interpolation of the obtained values using the specified method.

Examples

dis <- rmf_create_dis() n <- 50 xout <- runif(n, min = -10, max = 1010) yout <- runif(n, min = -10, max = 1010) zout <- runif(n, min = -31, max = 1) # 2d array <- rmf_create_array(1:prod(dis$nrow, dis$ncol), dim = c(dis$nrow, dis$ncol)) rmf_interpolate(array, dis, xout, yout)
#> [1] 7.340616 86.717436 63.459305 15.857311 NA 43.921085 #> [7] 53.255913 27.232911 77.819167 78.810103 86.026301 19.036890 #> [13] 5.000000 34.503679 39.519361 22.311807 38.587910 6.426769 #> [19] 39.602489 98.000000 30.525379 69.384218 74.466435 19.140656 #> [25] 97.000000 74.773672 7.000000 52.192782 66.116288 70.557771 #> [31] 5.000000 21.533881 31.750730 66.278004 48.157271 39.865525 #> [37] 72.543597 98.000000 15.646576 23.061656 NA 54.802414 #> [43] 65.140571 62.379428 7.520815 80.952620 78.486672 NA #> [49] 100.000000 38.884361
rmf_interpolate(array, dis, xout, yout, outside = 'drop')
#> [1] 7.340616 86.717436 63.459305 15.857311 NA 43.921085 53.255913 #> [8] 27.232911 77.819167 78.810103 86.026301 19.036890 NA 34.503679 #> [15] 39.519361 22.311807 38.587910 6.426769 39.602489 NA 30.525379 #> [22] 69.384218 74.466435 19.140656 NA 74.773672 NA 52.192782 #> [29] 66.116288 70.557771 NA 21.533881 31.750730 66.278004 48.157271 #> [36] 39.865525 72.543597 NA 15.646576 23.061656 NA 54.802414 #> [43] 65.140571 62.379428 7.520815 80.952620 78.486672 NA NA #> [50] 38.884361
rmf_interpolate(array, dis, xout, yout, method = 'nearest')
#> [1] 6 87 69 15 NA 43 49 23 80 77 82 18 5 37 45 19 41 5 35 #> [20] 98 26 67 80 16 97 80 7 55 62 67 5 24 28 68 46 41 77 98 #> [39] 14 30 NA 49 65 62 3 78 75 NA 100 36
# 3d array <- rmf_create_array(1:prod(dis$nrow, dis$ncol, dis$nlay), dim = c(dis$nrow, dis$ncol, dis$nlay)) rmf_interpolate(array, dis, xout, yout, zout, outside = 'drop')
#> [1] 90.61378 NA 186.02914 135.00724 NA 101.06881 97.44132 #> [8] 81.61518 208.53074 NA 153.68535 NA NA NA #> [15] NA 60.77438 188.87199 102.53076 72.39708 -52.14701 NA #> [22] 122.05501 268.44213 NA 31.51838 277.07728 63.12768 56.34215 #> [29] NA 253.39482 185.81059 68.64878 NA NA 91.34176 #> [36] 71.07080 118.31124 NA NA NA NA NA #> [43] 108.83295 NA NA NA 114.06304 NA -48.14874 #> [50] NA
pts <- sf::st_sfc(list(sf::st_point(c(150, 312, -12.5)), sf::st_point(c(500, 500, -22)), sf::st_point(c(850, 566, -16.3)))) rmf_interpolate(array, dis, obj = pts)
#> [1] 57.6350 209.8500 92.0024
# 4d array <- rmf_create_array(1:prod(dis$nrow, dis$ncol, dis$nlay, 4), dim = c(dis$nrow, dis$ncol, dis$nlay, 4)) attr(array, 'totim') <- c(100, 200, 500, 780) tout <- runif(n, min = 0.85, max = 4.2) # tout as fractional time step rmf_interpolate(array, dis, xout, yout, zout, tout)
#> [1] 622.79128 263.10033 758.48494 308.26427 NA 388.13944 #> [7] 747.22274 289.45148 948.62975 954.24881 NA 796.17786 #> [13] NA 576.27287 NA NA 858.76711 273.12058 #> [19] 322.48691 -367.42161 851.94878 345.52672 NA NA #> [25] 79.99145 1203.82047 682.87405 231.08350 570.00506 1140.06947 #> [31] 803.61155 108.69909 843.41282 100.36824 1012.05245 138.42205 #> [37] 533.12381 501.45521 859.00206 149.44131 NA NA #> [43] 453.73893 1109.16203 790.15449 334.15974 981.39995 NA #> [49] -290.21884 NA
tout <- runif(n, min = 90, max = 800) # tout as total time rmf_interpolate(array, dis, xout, yout, zout, tout, time = 'totim')
#> [1] 444.6847 968.3528 472.3534 173.3840 NA 905.0231 518.9467 #> [8] 419.9096 303.6997 956.4180 510.4004 772.9254 NA 863.6116 #> [15] NA NA 798.6200 838.9024 875.1391 -395.5184 512.2616 #> [22] 425.2667 449.1153 675.7296 107.3762 1139.9923 482.6053 NA #> [29] 966.7666 1302.6408 NA 408.7294 694.2318 534.5905 168.5663 #> [36] 756.7990 696.1084 776.8661 1027.6568 587.5536 NA NA #> [43] 838.0088 715.6016 862.0581 954.4619 782.1201 NA -457.4809 #> [50] 395.8945