rmf_as_tibble: Generic function to convert RMODFLOW objects to tibbles

View source: R/utils.R

rmf_as_tibbleR Documentation

Generic function to convert RMODFLOW objects to tibbles

Description

Generic function to convert RMODFLOW objects to tibbles

Usage

rmf_as_tibble(...)

## S3 method for class 'cbc'
rmf_as_tibble(
  cbc,
  dis,
  i = NULL,
  j = NULL,
  k = NULL,
  l = NULL,
  mask = array(1, dim = c(dis$nrow, dis$ncol, dis$nlay)),
  ijk = NULL,
  prj = rmf_get_prj(dis),
  crs = NULL,
  as_points = FALSE,
  id = "r",
  fluxes = "all",
  ts_time = TRUE,
  ...
)

## S3 method for class 'ddn'
rmf_as_tibble(
  ddn,
  dis,
  i = NULL,
  j = NULL,
  k = NULL,
  l = NULL,
  as_points = FALSE,
  ...
)

## S3 method for class 'hed'
rmf_as_tibble(
  hed,
  dis,
  i = NULL,
  j = NULL,
  k = NULL,
  l = NULL,
  as_points = FALSE,
  ...
)

## S3 method for class 'rmf_2d_array'
rmf_as_tibble(
  array,
  dis,
  mask = array(1, dim = dim(array)),
  prj = rmf_get_prj(dis),
  crs = NULL,
  as_points = FALSE,
  id = "r",
  ...
)

## S3 method for class 'rmf_3d_array'
rmf_as_tibble(
  array,
  dis,
  i = NULL,
  j = NULL,
  k = NULL,
  mask = array * 0 + 1,
  prj = rmf_get_prj(dis),
  crs = NULL,
  as_points = FALSE,
  id = "r",
  ...
)

## S3 method for class 'rmf_4d_array'
rmf_as_tibble(
  array,
  dis,
  i = NULL,
  j = NULL,
  k = NULL,
  l = NULL,
  mask = array(1, dim = dim(array)[1:3]),
  prj = rmf_get_prj(dis),
  crs = NULL,
  as_points = FALSE,
  id = "r",
  ts_time = TRUE,
  ...
)

## S3 method for class 'rmf_list'
rmf_as_tibble(
  obj,
  dis,
  ijk = NULL,
  prj = rmf_get_prj(dis),
  crs = NULL,
  as_points = FALSE,
  id = "r",
  ...
)

Arguments

...

arguments passed to rmf_as_tibble.rmf_4d_array for hed & ddn. Otherwise ignored.

cbc

RMODFLOW cbc object

dis

RMODFLOW dis object

i

optional row number to subset

j

optional column number to subset

k

optional layer number to subset

l

optional time step number to subet. Set negative to subset the final time step.

mask

a 3d array with 0 or FALSE indicating inactive cells; defaults to having all cells active

ijk

optional; a data.frame with i, j and k columns used to select the cells in the final tibble.

prj

optional; a projection object

crs

optional; a crs object

as_points

logical, should cell-centered nodal values be returned or 4 values per cell representing the corners. Defaults to FALSE.

id

either 'r' (default) or 'modflow' specifying the type of cell id to use. MODFLOW uses row-major array ordering whereas R uses column-major ordering.

fluxes

character; denotes which fluxes to read. Defaults to reading all fluxes. See details.

ts_time

logical; should the returned time column represent the cumulative modelled time or the time step numbers. See details. Defaults to TRUE (cumulative modelled time)

ddn

RMODFLOW ddn object

hed

RMODFLOW hed object

array

a rmf_3d_array object

obj

RMODFLOW rmf_list object

Details

Fluxes include 'constant_head', 'storage', 'flow_right_face', 'flow_front_face', 'flow_lower_face', 'wells', 'river_leakage', 'recharge', 'drains', 'head_dep_bounds' or any other description as written by MODFLOW.

The time steps (nstp column) are numbered from 1 to dim(array)[4]. Since in some cases, the rmf_4d_array does not represent all time steps of the simulation, (e.g. output is only written during certain time steps), the nstp value might not correspond to the true time step number for which output was written. In those cases, the time column might not give the correct cumulative time values if ts_time = TRUE. A warning will be thrown and the user should consider setting ts_time = FALSE and calculate the exact cumulative modelled time with e.g. rmf_time_steps.

Value

rmf_as_tibble.cbc returns a tibble of with the fluxes components of the cbc object

rmf_as_tibble.ddn returns a tibble with columns id, value, x, y, z, top, botm, time, nstp representing the cell id's (either MODFLOW or R style; see the id argument), array value, x, y, z coordinates, cell top & bottom and MODFLOW time and time step. Possible additional columns might include totim, pertim, kper & kstp. If as_points = FALSE, the coordinates represent the 2D cell corners (bottomleft, topleft, topright, bottomright on the XY plane), otherwise the cell center.

rmf_as_tibble.hed returns a tibble with columns id, value, x, y, z, top, botm, time, nstp representing the cell id's (either MODFLOW or R style; see the id argument), array value, x, y, z coordinates, cell top & bottom and MODFLOW time and time step. Possible additional columns might include totim, pertim, kper & kstp. If as_points = FALSE, the coordinates represent the 2D cell corners (bottomleft, topleft, topright, bottomright on the XY plane), otherwise the cell center.

rmf_as_tibble.rmf_2d_array returns a tibble with columns id, value, x, y representing the cell id's (either MODFLOW or R style; see the id argument), array value and x & y coordinates. If as_points = FALSE, the coordinates represent the cell corners (bottomleft, topleft, topright, bottomright on the XY plane), otherwise the cell center.

rmf_as_tibble.rmf_3d_array returns a tibble with columns id, value, x, y, z, top, botm representing the cell id's (either MODFLOW or R style; see the id argument), array value, x, y, z coordinates and cell top & bottom. If as_points = FALSE, the coordinates represent the 2D cell corners (bottomleft, topleft, topright, bottomright on the XY plane), otherwise the cell center.

Providing either i, j & k can be used to subset the array. If none are supplied, no subsetting is performed and the entire array is converted to a tibble. If as_points = FALSE and i or j are not provided , no z column is returned since in that case it is ambiguous what z should represent (cell center, top or bottom of the layer). Providing i or j can be used for subsetting a cross-section through the array.

rmf_as_tibble.rmf_4d_array tibble with columns id, value, x, y, z, top, botm, time, nstp representing the cell id's (either MODFLOW or R style; see the id argument), array value, x, y, z coordinates, cell top & bottom and MODFLOW time and time step. If as_points = FALSE, the coordinates represent the 2D cell corners (bottomleft, topleft, topright, bottomright on the XY plane), otherwise the cell center.

Providing either i, j, k or l can be used to subset the array. If none are supplied, no subsetting is performed and the entire array is converted to a tibble. If as_points = FALSE and i or j are not provided , no z column is returned since in that case it is ambiguous what z should represent (cell center, top or bottom of the layer). Providing i or j can be used for subsetting a cross-section through the array.

If i, j and k are provided, a tibble of a single cell time series is returned. If l is not provided but i, j or k is, a tibble with a time series of the subsetted array according to i, j or k is returned.

rmf_as_tibble.rmf_list returns a tibble with the columns of obj except i, j, k and columns id, x, y, top, botm representing the cell id's (either MODFLOW or R style; see the id argument), x, y coordinates and cell top & bottom. If as_points = FALSE, the coordinates represent the 2D cell corners (bottomleft, topleft, topright, bottomright on the XY plane), otherwise the cell center. Furthermore, if as_points = TRUE, an additional z column is added representing the cell centers z coordinates.

Examples

m <- rmf_read(rmf_example_file('example-model.nam'), output = TRUE, verbose = FALSE)

# cbc
rmf_as_tibble(m$cbc, m$dis, fluxes = c('wells', 'flow_right_face'))

# ddn
rmf_as_tibble(m$drawdown, m$dis, k = 1)

# hed
rmf_as_tibble(m$head, m$dis, i = 2, as_points = TRUE)
rmf_as_tibble(m$head, m$dis, l = 1)
rmf_as_tibble(m$head, m$dis, l = 1, j = 5, mask = m$bas$ibound)
# 2d array
rmf_as_tibble(m$dis$top, m$dis, id = FALSE)

# 3d array
rmf_as_tibble(m$lpf$hk, m$dis)
rmf_as_tibble(m$lpf$hk, m$dis, as_points = TRUE, i = 5)

# 4d array
r <- rmf_create_array(1:prod(dim(m$head)), dim = dim(m$head))
rmf_as_tibble(r, m$dis)
rmf_as_tibble(r, m$dis, l = 1)
rmf_as_tibble(r, m$dis, j = 5)
# rmf_list
l <- m$chd$data
rmf_as_tibble(l, m$dis)
rmf_as_tibble(l, m$dis, as_points = TRUE)


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