cube_collect() converts a deferred NetCDF-backed cube into an independent
in-memory <ocean_cube>. An object that already uses the memory backend is
validated and returned unchanged.
Details
Collecting a NetCDF cube reads its complete logical 5D array and preserves coordinates, variables, units, scientific metadata, and prior provenance. The result no longer depends on the source file and can be modified with memory-backend operations; the NetCDF source remains read-only. In particular, UTC POSIXct values, sub-day precision, calendar, CF units, origin, decoder, and normalization provenance are preserved. Raw numeric source time remains a source-backend concern and is not redundantly copied into the collected cube.
Before reading, cube_collect() estimates the minimum memory occupied by the
materialized double array as prod(.cube_shape(x)) * 8. This estimate does
not include R object overhead, dimnames, coordinates, or metadata.
Examples
values <- array(1, dim = c(1, 1, 1, 1, 1))
cube <- ocean_cube(
lon = -80,
lat = -12,
depth = 0,
time = as.Date("2020-01-01"),
vars = "temperature",
data = values
)
collected <- cube_collect(cube)
identical(collected, cube)
#> [1] TRUE