Learn R Programming

neuroim2 (version 0.8.5)

BigNeuroVec: Create a Memory-Mapped Neuroimaging Vector

Description

Creates a BigNeuroVec object, which represents a large neuroimaging vector using memory-mapped file storage. This allows working with neuroimaging data that is too large to fit in memory.

Usage

BigNeuroVec(
  data,
  space,
  mask,
  label = "",
  type = c("double", "float", "integer"),
  backingfile = tempfile()
)

Value

A new BigNeuroVec object that provides memory-efficient access to large neuroimaging data through memory mapping. The object contains the spatial properties, mask, and memory-mapped data storage.

Arguments

data

The input data to be stored

space

A NeuroSpace object defining the spatial properties

mask

A logical mask indicating which voxels contain data

label

Optional character string label for the vector

type

Storage type, one of "double", "float", or "integer"

backingfile

Path to the file used for memory mapping (defaults to tempfile())

Examples

Run this code
# \donttest{
# Load an example 4D brain image
example_file <- system.file("extdata", "global_mask_v4.nii", package = "neuroim2")
example_4d_image <- read_vec(example_file)

# Create a mask (e.g., selecting voxels with values > 0)
mask <- array(as.vector(example_4d_image[,,,1]) > 0,
             dim = dim(example_4d_image)[1:3])

if(requireNamespace("bigstatsr", quietly = TRUE)) {
  # Create a BigNeuroVec with memory mapping
  big_vec <- BigNeuroVec(data = example_4d_image@.Data,
                         space = space(example_4d_image),
                         mask = mask,
                         label = "Example BigNeuroVec")
  print(big_vec)
}
# }

Run the code above in your browser using DataLab