vol_field: Wrap a gridded three-dimensional field

View source: R/field.R

vol_fieldR Documentation

Wrap a gridded three-dimensional field

Description

Builds the object every other function in the package takes: a scalar field on a regular longitude, latitude and depth grid, with the coordinate vectors, the units and the provenance carried alongside the values.

Usage

vol_field(
  values,
  lon,
  lat,
  depth,
  name = "value",
  unit = "",
  mask = NULL,
  source = NULL,
  geographic = TRUE
)

Arguments

values

Numeric array of dimension c(nz, ny, nx), indexed by depth, then latitude, then longitude. Missing cells are NA.

lon

Numeric vector of nx longitudes, strictly increasing.

lat

Numeric vector of ny latitudes, strictly increasing from south to north.

depth

Numeric vector of nz positions along the third axis, strictly increasing. For a marine field these are depths in metres, positive downward, with the surface at or near zero; an axis measured upward is negated before it gets here, so the values may be negative.

name

Short name of the quantity, used in labels.

unit

Unit of the quantity, used in labels.

mask

Optional logical matrix of dimension c(ny, nx), TRUE where an opaque sheet is drawn at zero depth. Land, for a marine field.

source

Optional named list of provenance strings, carried into the payload manifest.

geographic

Logical. TRUE when the first two axes are longitude and latitude, which decides the axis names and the tick labels the viewer draws. FALSE for any other pair, which are then reported as X and Y.

Details

Wrap a gridded three-dimensional field

The index order is fixed and is not a matter of taste. A browser payload is one image per depth level, and an image is a matrix of rows by columns, so a level of the field has to be contiguous as values[k, , ] with latitude down the rows and longitude across the columns. Row one of a level is the southernmost latitude and column one the westernmost longitude, which is the orientation the renderer assumes and the manifest records.

The constructor checks that the three coordinate vectors match the three dimensions of values, that each is numeric, complete and strictly increasing, and that mask, when given, matches the horizontal grid. It does not require the depth axis to be uniform: vol_resample() does that, and the browser payload needs it because the GPU samples a texture on a regular grid.

The value range may be anything the transfer of vol_encode() can carry. For a strictly positive and strongly skewed field, the square-root transfer spends its 254 codes where the data are.

Value

An object of class vol_field: a list with the elements values, lon, lat, depth, name, unit, mask, source and geographic.

See Also

print.vol_field(), summary.vol_field() and plot.vol_field() for the methods, vol_resample() to put the depth axis on a uniform grid, vol_encode() for the transfer into 8 bits, vol_payload() to write the browser payload, vol_read_npy() and vol_read_netcdf() to read a field from a file.

Examples

v <- array(NA_real_, c(4, 20, 30))
for (k in 1:4) v[k, , ] <- outer(1:20, 1:30, function(i, j) exp(-k / 3) * (i + j))
f <- vol_field(v, lon = seq(10, 12.9, by = 0.1), lat = seq(40, 41.9, by = 0.1),
               depth = c(0, 10, 25, 50), name = "Tracer", unit = "mg/l")
f
summary(f)
plot(f)
plot(f, type = "profile")
plot(f, type = "coverage")

volumr documentation built on Dec. 2, 2026, 5:07 p.m.