vol_resample: Resample a field onto a uniform depth grid

View source: R/resample.R

vol_resampleR Documentation

Resample a field onto a uniform depth grid

Description

Interpolates the field linearly onto depths spaced evenly from the shallowest measured depth, which is what the browser payload needs, because the GPU samples a three-dimensional texture on a regular grid.

Usage

vol_resample(field, dz = NULL, zmax = NULL, check = TRUE)

Arguments

field

A vol_field.

dz

Spacing of the target grid, in metres. Defaults to the largest spacing that reproduces every measured depth exactly, when one exists, and otherwise to the smallest spacing of the input.

zmax

Deepest level of the target grid, no shallower than the first measured depth. Defaults to the deepest level of the input.

check

Logical. When TRUE, stop if a measured depth is absent from the target grid, so that no measured level is silently smoothed away.

Details

Resample a field onto a uniform depth grid

The interpolation is

v(z) = \frac{v_{hi} - v_{lo}}{z_{hi} - z_{lo}}\,(z - z_{lo}) + v_{lo},

with z_{lo} and z_{hi} the measured depths that bracket z, so an interpolated level holds no value where either of the two measured levels around it holds none. A target depth that coincides with a measured depth, to within 10^{-9}, takes that measured level unchanged, so a cell keeps its value at a measured depth whatever its neighbours hold; at the first level this keeps the cells of a column that ends above the second measured depth.

The default dz is chosen so that measured levels survive. For the case study the fifteen measured depths are 0, 12.5, 25, 37.5, 50, 62.5, 75, 87.5, 100, 125, 150, 175, 200 and 225 and 250 m, every one of them a multiple of 12.5 m, so a grid of 12.5 m reproduces all fifteen exactly and interpolates only the six levels that lie between 100 and 250 m.

The target grid starts at the shallowest measured depth, so the interpolation never reaches outside the measured column. Resampling a field that is already uniform at the requested spacing is a copy, not a smoothing pass, and a field with a single level is returned unchanged.

Value

A vol_field on the uniform grid, with the other elements carried over unchanged.

See Also

vol_field() for the object, vol_encode() for the step that follows, vol_payload(), which calls this when the depth axis is not already uniform, plot.vol_field() to see the profile before and after.

Examples

data(med_mhw)
med_mhw$depth
u <- vol_resample(med_mhw)
u$depth
summary(u)$grid

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