vol_payload: Write the browser payload of a field

View source: R/payload.R

vol_payloadR Documentation

Write the browser payload of a field

Description

Writes the directory the renderer reads: one image per depth level holding the quantised field, the image of the opaque sheet, the colour lookup image, and a manifest recording the grid, the transfer, the display defaults and a SHA-256 of every file written.

Usage

vol_payload(
  field,
  dir,
  transfer = "auto",
  display = NULL,
  step = 1L,
  resample = TRUE,
  dz = NULL,
  created = NULL,
  title = NULL,
  subtitle = NULL,
  axes = NULL,
  geographic = NULL,
  depth_unit = NULL
)

Arguments

field

A vol_field.

dir

Directory to write into. Created when absent.

transfer

Name of the transfer, passed to vol_encode(). The default takes the square root for a non-negative field and the linear ramp for any other.

display

Named list of the defaults the viewer opens with: vmin and vmax, the ends of the colour scale; cmap, a name from vol_colormaps(); gamma; od, the opacity a ray accumulates across the full depth; and ow, how far that opacity follows the intensity. Any element left out takes its default, which is the 1st and 99th percentiles (rounded to integers when they lie ten or more units apart, and to three significant digits otherwise), "matter", a gamma of 1, an opacity of 12, which is the top of the slider, and 0.

step

Horizontal decimation. 1 keeps the native grid.

resample

Logical. Put the depth axis on a uniform grid first, when it is not already uniform.

dz

Spacing of that grid, passed to vol_resample().

created

Timestamp written into the manifest. Defaults to the current time in UTC. Pin it to make two builds of one field give one set of bytes.

title

Heading the viewer shows. Defaults to the name of the field.

subtitle

Line under the heading. Defaults to the name of the field and the depth span.

axes

Named list with x, y and z, the axis titles. Defaults to longitude, latitude and depth.

geographic

Logical. When TRUE, tick labels carry the compass letters; when FALSE, they are plain numbers. Taken from the field when left NULL.

depth_unit

Unit of the vertical axis, used in the readouts. Defaults to metres for a geographic field and to none for any other.

Details

Write the browser payload of a field

Every level is written as an 8-bit greyscale PNG, because a browser decodes PNG natively, the format is lossless, and one image per level lets the loader build a three-dimensional texture without any custom container. The whole cube of the case study at its native grid, 1016 by 380 by 21, travels in about 1.5 MB this way (vol_example_payload()).

The horizontal grid is not reduced by default, and step exists for the cases where it must be. A block mean to half the resolution already costs an error comparable with the width of a plotted colour band, whereas the transfer into 8 bits costs a small fraction of one; spending the bits on the vertical and on the value range rather than on the horizontal grid is what keeps the payload both small and faithful.

The manifest records the SHA-256 of every file it names, and carries through the digests of the arrays the field came from when the field carries them, so a rendering can be traced back to its inputs.

Value

An object of class vol_payload: a list with dir, manifest, files, encoding and field.

See Also

vol_field() for the input, vol_encode() for the transfer, vol_standalone() to carry the payload inside one HTML file, vol_widget() to render it in shiny or R Markdown, print.vol_payload(), summary.vol_payload() and plot.vol_payload() for the methods.

Examples

data(med_mhw)
p <- vol_payload(med_mhw, tempfile("payload"))
p
summary(p)
plot(p)
plot(p, type = "level", depth = 50)
vol_standalone(p, path = tempfile(fileext = ".html"))

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