rmf_as_stars: Functions to convert rmf_array and rmf_list objects to stars...

View source: R/spatial.R

rmf_as_starsR Documentation

Functions to convert rmf_array and rmf_list objects to stars objects

Description

Functions to convert rmf_array and rmf_list objects to stars objects

Usage

rmf_as_stars(...)

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

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

## S3 method for class '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 class '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.

Details

The crs is taken from the prj argument. Note that in MODFLOW, row indices (i) increase with decreasing Y coordinates, i.e. row 1 - column 1 corresponds to the upperleft cell.

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').

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)

# 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')

# 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)

# 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')


rogiersbart/RMODFLOW documentation built on Jan. 14, 2023, 4:21 a.m.