The hardware and bandwidth for this mirror is donated by dogado GmbH, the Webhosting and Full Service-Cloud Provider. Check out our Wordpress Tutorial.
If you wish to report a bug, or if you are interested in having us mirror your free-software or open-source project, please feel free to contact us at mirror[@]dogado.de.
Every conventional view of a three-dimensional field discards most of it: a map shows one level and hides the rest; a section shows one transect and hides the basin; an isosurface shows one value and thereby asserts that the value is the one worth showing. Volume rendering makes none of those choices, since it integrates along the line of sight instead of selecting a slice through it, and the price it pays is an image in which a bright region may be one intense cell or a long column of moderate ones. However, the ambiguity is separable, and the depth slab below is what separates it. This vignette follows the path from a gridded field to a volume that a browser renders, on the case study the package ships, and it measures at each step what that step costs.
med_mhw is marine heatwave cumulative intensity in the
Mediterranean Sea over the top 250 m, on fifteen measured depths, at an
eighth of a degree, which keeps every third point of the native grid of
the study. The provenance travels with it, which matters more than it
may appear, since a field detached from its source cannot be checked by
anyone downstream.
data(med_mhw)
med_mhw
#> ℹ Gridded field: MHW cumulative intensity (°C·days)
#> Grid = 339 by 127 by 15, longitude by latitude by depth
#> Longitude = -6.0000 to 36.2500, step 0.12500
#> Latitude = 30.1875 to 45.9375, step 0.12500
#> Depth = 0 to 250 over 15 levels, unevenly spaced
#> Values = 4.209 to 580.7, 33.4 % of cells present
#> Mask = 55.5 % of the surfaceThe array travels with its three coordinate vectors, and the constructor fixes the index order as depth, then latitude, then longitude, because a level of the field has to be contiguous as a matrix before it can become an image; the order is therefore a consequence of the output format and not a matter of taste. The summary reports the coverage of each level, which for a marine field falls with depth as the bathymetry rises to meet it.
s <- summary(med_mhw)
head(s$levels, 4)
#> depth coverage median q99
#> 1 0.0 0.3740738 25.10268 38.13451
#> 2 12.5 0.3711240 26.21018 47.65091
#> 3 25.0 0.3652243 27.04480 55.96598
#> 4 37.5 0.3594871 29.11196 65.31722That profile is the quickest check that the depth axis was read the right way up, and it is worth running before anything else, because an inverted axis produces a plausible picture of the wrong thing. Coverage cannot increase downward in a field bounded below by the sea floor; thus a profile that widens with depth is unlikely to be telling you about the ocean, and is probably telling you that the array arrived reversed.
The fifteen measured depths are not evenly spaced: the top hundred metres are sampled every 12.5 m and the rest every 25 m. A texture on a GPU is sampled on a regular grid, so the field has to be resampled before it can be rendered, and the spacing that does so without smoothing away a measured level is the largest one that reproduces all fifteen of them exactly.
u <- vol_resample(med_mhw)
u$depth
#> [1] 0.0 12.5 25.0 37.5 50.0 62.5 75.0 87.5 100.0 112.5 125.0 137.5
#> [13] 150.0 162.5 175.0 187.5 200.0 212.5 225.0 237.5 250.0Every measured depth is a multiple of 12.5 m, so all fifteen survive
and only six of the twenty-one levels are new. The interpolation is
linear and its arithmetic is stated in ?vol_resample; note
that a target depth coinciding with a measured depth is nonetheless
evaluated from the interval below it, and returns that measured value to
within one unit in the last place and not necessarily bit for bit.
Eight bits per cell is what lets the whole volume travel inside a page; the transfer decides where those bits are spent, and for a skewed field the choice is consequential. Cumulative intensity is positive and strongly skewed, with a median near 26 against a maximum above 500, so a linear ramp would spend most of its 254 codes on a tail that holds almost none of the cells.
e <- vol_encode(u)
e
#> ℹ Transfer into 8 bits: sqrt
#> Range = 4.209 to 580.7 over 254 codes, 0 reserved for no data
#> Error = 0.271 rms, 1.657 at worst °C·days
#> Cells = 294637 carrying a value of 904113The error is measured against the values the transfer started from and reported alongside the encoding, so that it is never an assumption a reader has to take on trust, and so that a transfer chosen badly announces itself in a number instead of in a picture that merely looks wrong. The figure that makes it interpretable is the width of a plotted colour band, which for the default scale is about two units; an error of a quarter of a unit therefore cannot move a cell into a neighbouring colour, although it would be visible on a scale ten times narrower.
The error grows with the value, and it grows slowly, because the square root is flattest at the top of its range and a flat transfer is where quantisation costs most. In contrast, a linear transfer on the same field distributes its error quite differently, and the comparison takes one line.
lin <- vol_encode(u, transfer = "linear")
c(sqrt = e$transfer$rms_error, linear = lin$transfer$rms_error)
#> sqrt linear
#> 0.2710050 0.6589072The payload is one image per level, together with an image of the opaque sheet drawn at zero depth, a lookup image holding the colour tables, and a manifest that records the grid, the transfer, the display defaults and a SHA-256 of every file it names.
dir <- file.path(tempdir(), "med_payload")
p <- vol_payload(med_mhw, dir, display = list(vmin = 15L, vmax = 60L,
cmap = "matter", gamma = 1),
title = "Mediterranean marine heatwaves",
subtitle = "Cumulative intensity, 0 to 250 m.")
p
#> ✔ Browser payload in /tmp/RtmpMs5tUz/med_payload
#> Grid = 339 x 127 x 21, depths 0 to 250 m
#> Transfer = sqrt, error 0.271 rms and 1.657 at worst
#> Files = 24, 0.23 MB in total
#> Display = matter from 15 to 60, gamma 1Indeed, compression is what keeps the payload small, and it does the work that decimation would otherwise have to do at a cost to the horizontal grid; a level whose cells are mostly absent costs almost nothing whatever its nominal dimensions, so the size of a level reads as the width of the basin at that depth.
The level the browser reads is the level the payload carries, decoded through the same transfer that wrote it; drawing that decoded level beside the source is therefore the end-to-end check that the chain from array to image has lost nothing it did not declare.
The payload directory is what a page fetches over http, one image at a time. A page opened from disk cannot fetch anything, because a browser refuses a cross-origin read from a local file, so the single-file build carries every image inside the page as a data URI.
page <- vol_standalone(p, path = file.path(tempdir(), "med_volume.html"))
sz <- c(payload = sum(file.size(file.path(p$dir, p$files))), page = file.size(page))
sz
#> payload page
#> 226153 362356That file opens by double-click, needs no server and no network, and travels as a single attachment. Note the asymmetry it rests on: the field occupies 5.4 MB in memory, whereas the payload built from it is 0.23 MB and the page 0.36 MB, because the values there travel in 8 bits and the images compress. The package also ships the payload of the field at the native grid of the study, nine times as many cells in 1.5 MB, so the picture at full resolution costs one line and no build.
The widget hosts the same page and not a second implementation of it; thus what a reader sees here, what an application shows and what the downloaded file contains are one renderer, and a change to any of them is a change to all three.
small <- vol_payload(med_mhw, file.path(tempdir(), "small"), step = 2L,
display = list(vmin = 15L, vmax = 60L, cmap = "matter",
gamma = 1))
vol_widget(small, height = 420,
options = list(slab = TRUE, slabT = 25, slabZ = 50, od = 9, ow = 0,
elev = 22, azim = -55))Drag to rotate, turn the wheel to zoom, hold shift and drag to pan, and hover to read the position and the value under the cursor, which is taken from the place along the line of sight where the accumulated opacity first passes a half. The box is drawn in the proportions the data has, with longitude scaled by the cosine of the latitude of the domain, so the shapes are the ones an atlas draws; the depth axis cannot be to scale against a basin thousands of kilometres wide, and the vertical exaggeration slider therefore reports the factor it implies, which for this field is about 5,200 at its default setting. The panel on the right carries the rest: the colour scale, the density, the depth slab that slides a window of fixed thickness through the column, the map view that looks straight down on a parallel projection, and the white background for a figure that will go into a printed document.
The slab resolves the ambiguity the introduction raised, and it does so by construction: a feature that survives a thin window is local to that depth, whereas one that fades as the window narrows was an accumulation along the ray all along. Sweeping the window down the column, which the panel does on a button, is thus the closest thing the viewer offers to a controlled experiment on what a bright region means.
The manifest records a digest of every file it names, and the packaged field carries a digest of every array it was built from, so a rendering can be traced back to its inputs without trusting a filename.
p$manifest$slices[[1]][c("file", "depth", "sha256")]
#> $file
#> [1] "slice_00.png"
#>
#> $depth
#> [1] 0
#>
#> $sha256
#> [1] "381c8075bc542784b80321f53ba0034b94017dce2c5a49727c19bf15eb822993"
substr(med_mhw$source$sha256[1:2], 1, 16)
#> 0m 12_5m
#> "7dd6ea259cb2800c" "dad55d6826661900"Note that two builds of one field give one set of bytes once the timestamp is pinned, that timestamp being the only field a rebuild would otherwise change.
a <- vol_payload(med_mhw, tempfile("a"), created = "2026-01-01T00:00:00+00:00")
b <- vol_payload(med_mhw, tempfile("b"), created = "2026-01-01T00:00:00+00:00")
identical(vapply(a$manifest$slices, function(s) s$sha256, ""),
vapply(b$manifest$slices, function(s) s$sha256, ""))
#> [1] TRUENothing above is specific to the case study; a field arrives as an array with three coordinate vectors, from whatever source produced it, and the rest follows unchanged.
f <- vol_field(values, lon = lon, lat = lat, depth = depth,
name = "temperature", unit = "degC")
vol_standalone(vol_payload(f, "payload"), path = "temperature.html")vol_read_netcdf() reads one variable of a NetCDF file
and infers the axes from their names, and vol_read_npy()
reads a NumPy array without calling Python. Indeed,
shinyVolumr() puts the whole workflow into an application
with an upload at the first step, so a reader may put their own file
through every stage above without writing a line of this down.
The colour scale saturates at both ends, and neither the volume nor the colour bar indicates how far past a limit a given cell may sit, so the tail is read by moving the limits and never by interpreting the image. The slab composites from the front, which means that at a high opacity its colour reports the shallow end of the window and not the mean over it; lowering the opacity lets the whole window contribute, at the cost of a fainter image. The vertical axis is exaggerated against the horizontal ones, so a distance read across the volume is not comparable with one read down it, except in the map view, where the exaggeration has no effect whatever. Finally, cells carrying no value are not drawn at all, and the shape of the volume is therefore the shape of the domain and not a contour of the quantity.
The field is marine heatwave cumulative intensity computed against a
1993 to 2022 reference period, following the definition of Hobday et
al. [1], from the Copernicus Marine Service
Mediterranean Sea physical reanalysis [2], product
MEDSEA_MULTIYEAR_PHY_006_004, described by Escudier et
al. [3]. The colour tables are those of Thyng et
al. [4].
[1] Hobday, A. J., et al. (2016). A hierarchical approach to defining marine heatwaves. Progress in Oceanography, 141, 227-238. doi:10.1016/j.pocean.2015.12.014
[2] Escudier, R., et al. (2020). Mediterranean Sea physical reanalysis (CMEMS MED-Currents, E3R1 system). Copernicus Monitoring Environment Marine Service. doi:10.25423/CMCC/MEDSEA_MULTIYEAR_PHY_006_004_E3R1
[3] Escudier, R., et al. (2021). A high resolution reanalysis for the Mediterranean Sea. Frontiers in Earth Science, 9, 702285. doi:10.3389/feart.2021.702285
[4] Thyng, K. M., et al. (2016). True colors of oceanography: guidelines for effective and accurate colormap selection. Oceanography, 29(3), 9-13. doi:10.5670/oceanog.2016.66
These binaries (installable software) and packages are in development.
They may not be fully stable and should be used with caution. We make no claims about them.
Health stats visible at Monitor.