Convert a stars object to rmf_array

# S3 method for stars
rmf_as_array(
  obj,
  dis,
  prj = rmf_get_prj(dis),
  select = 1,
  resample = TRUE,
  method = "bilinear",
  kper = attr(obj, "kper"),
  ...
)

Arguments

obj

stars object

dis

RMODFLOW dis object

prj

RMODFLOW prj object

select

integer or character specifying which variable from obj to select

resample

logical specifying if obj should be resampled to the MODFLOW grid. Defaults to TRUE.

method

character specifying the resampling method when resample = TRUE. Defaults to 'bilinear'. See details.

kper

optional integers specifying the stress-periods during which this array is active

...

ignored

Value

a rmf_2d_array, rmf_3d_array or rmf_4d_array depending on the number of dimensions in obj

Details

If resample = TRUE, stars::st_warp is called with the specified method. For possible method values, see ?stars::st_warp. If resample = FALSE, the array is pulled directly from obj. The latter will fail when the dimensions and crs of obj and the MODFLOW grid are not exactly the same. In that case, the user should consider setting resample = TRUE.

rmf_as_array currently can not handle obj or prj without defined crs.

This function is intended for use with 2D stars objects with dimensions X & Y, 3D stars objects with dimensions X, Y and dis$nlay or 4D stars objects with dimensions X, Y, dis$nlay and sum(dis$nstp).

Examples

dis <- rmf_create_dis() r <- rmf_create_array(1:prod(dis$nrow, dis$ncol), dim = c(dis$nrow, dis$ncol)) s <- rmf_as_stars(r, dis = dis) rmf_as_array(s, dis = dis, resample = FALSE)
#> RMODFLOW 2d array with 10 rows and 10 columns, representing the i & j dimensions. #> Not representing stress period data #> [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10] #> [1,] 1 11 21 31 41 51 61 71 81 91 #> [2,] 2 12 22 32 42 52 62 72 82 92 #> [3,] 3 13 23 33 43 53 63 73 83 93 #> [4,] 4 14 24 34 44 54 64 74 84 94 #> [5,] 5 15 25 35 45 55 65 75 85 95 #> [6,] 6 16 26 36 46 56 66 76 86 96 #> [7,] 7 17 27 37 47 57 67 77 87 97 #> [8,] 8 18 28 38 48 58 68 78 88 98 #> [9,] 9 19 29 39 49 59 69 79 89 99 #> [10,] 10 20 30 40 50 60 70 80 90 100