Functions to convert rmf_array and rmf_list objects to stars objects

rmf_as_stars(...)

# S3 method for rmf_2d_array
rmf_as_stars(
  array,
  dis,
  mask = array * 0 + 1,
  prj = rmf_get_prj(dis),
  name = "value",
  id = "r",
  ...
)

# S3 method for rmf_3d_array
rmf_as_stars(
  array,
  dis,
  mask = array * 0 + 1,
  prj = rmf_get_prj(dis),
  name = "value",
  id = "r",
  ...
)

# S3 method for rmf_4d_array
rmf_as_stars(
  array,
  dis,
  mask = array(1, dim = dim(array)[1:3]),
  prj = rmf_get_prj(dis),
  name = "value",
  id = "r",
  ...
)

# S3 method for rmf_list
rmf_as_stars(
  obj,
  dis,
  select,
  prj = rmf_get_prj(dis),
  name = "value",
  id = "r",
  ...
)

Arguments

...

additional arguments passed to rmf_as_array when converting a rmf_list object. Otherwise, ignored.

array

rmf_2d_array, rmf_3d_array or rmf_4d_array object

dis

RMODFLOW dis 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 specify which cells to convert. Defaults to all cells.

prj

RMODFLOW prj object

name

character specifying the name of the resulting variable in the stars object. Defaults to 'value'

id

either 'r' (default) or 'modflow'. Specifies which type of cell id is returned. R uses column-major array ordering whereas MODFLOW uses row-major ordering.

obj

rmf_list object

select

integer or character specifying which column of the rmf_list object to convert to stars variable.

Value

a stars object with x and y dimensions when array is 2d, x, y and layer (integer representing MODFLOW layer; similar to bands) when array is 3d, x, y, layer and time dimensions when array is 4d. When converting a rmf_list object, it is first converted to a rmf_array using rmf_as_array. Two variables are present in the returned stars object, one with the array values and on with the cell id (when id is 'r' or 'modflow').

Details

The crs is taken from the prj argument.

Examples

dis <- rmf_create_dis() # 2d array r <- rmf_create_array(1:prod(dis$nrow, dis$ncol), dim = c(dis$nrow, dis$ncol)) rmf_as_stars(r, dis = dis)
#> stars object with 2 dimensions and 2 attributes #> attribute(s): #> Min. 1st Qu. Median Mean 3rd Qu. Max. #> value 1 25.75 50.5 50.5 75.25 100 #> id 1 25.75 50.5 50.5 75.25 100 #> dimension(s): #> from to offset delta refsys point values x/y #> x 1 10 0 100 NA FALSE NULL [x] #> y 1 10 0 100 NA FALSE NULL [y]
# 3d array r <- rmf_create_array(1:prod(dis$nrow, dis$ncol, dis$nlay), dim = c(dis$nrow, dis$ncol, dis$nlay)) rmf_as_stars(r, dis = dis, id = 'modflow')
#> stars object with 3 dimensions and 2 attributes #> attribute(s): #> Min. 1st Qu. Median Mean 3rd Qu. Max. #> value 1 75.75 150.5 150.5 225.25 300 #> id 1 75.75 150.5 150.5 225.25 300 #> dimension(s): #> from to offset delta refsys point values x/y #> x 1 10 0 100 NA FALSE NULL [x] #> y 1 10 0 100 NA FALSE NULL [y] #> layer 1 3 NA NA NA NA layer_1, layer_2, layer_3
# 4d array r <- rmf_create_array(1:prod(dis$nrow, dis$ncol, dis$nlay, 2), dim = c(dis$nrow, dis$ncol, dis$nlay, 2)) rmf_as_stars(r, dis = dis, id = FALSE)
#> stars object with 4 dimensions and 1 attribute #> attribute(s): #> Min. 1st Qu. Median Mean 3rd Qu. Max. #> value 1 150.75 300.5 300.5 450.25 600 #> dimension(s): #> from to offset delta refsys point values x/y #> x 1 10 0 100 NA FALSE NULL [x] #> y 1 10 0 100 NA FALSE NULL [y] #> layer 1 3 NA NA NA NA layer_1, layer_2, layer_3 #> time 1 2 1 1 NA NA NULL
# rmf_list l <- rmf_create_list(data.frame(i = 1, j = 1:2, k = c(3, 2), q = c(-500, -400), d = 35)) rmf_as_stars(l, dis = dis, select = 'q')
#> stars object with 3 dimensions and 2 attributes #> attribute(s): #> Min. 1st Qu. Median Mean 3rd Qu. Max. #> value -500 0.00 0.0 -3.0 0.00 0 #> id 1 75.75 150.5 150.5 225.25 300 #> dimension(s): #> from to offset delta refsys point values x/y #> x 1 10 0 100 NA FALSE NULL [x] #> y 1 10 0 100 NA FALSE NULL [y] #> layer 1 3 NA NA NA NA layer_1, layer_2, layer_3