sub_vector-methods: Generic function to extract a sub-vector from a 'NeuroVec'...

sub_vectorR Documentation

Generic function to extract a sub-vector from a NeuroVec object.

Description

Extracts a subset of volumes from a file-backed neuroimaging vector and returns them as a dense (in-memory) vector.

Extracts a subsequence of volumes from a NeuroVecSeq object.

Usage

sub_vector(x, i, ...)

## S4 method for signature 'FileBackedNeuroVec,numeric'
sub_vector(x, i)

## S4 method for signature 'NeuroVec,numeric'
sub_vector(x, i)

## S4 method for signature 'NeuroVecSeq,numeric'
sub_vector(x, i)

## S4 method for signature 'NeuroVecSeq,numeric'
sub_vector(x, i)

Arguments

x

A NeuroVecSeq object

i

Numeric vector of indices specifying the time points to extract

...

additional arguments

Details

This method efficiently reads only the requested volumes from disk, converting them to an in-memory representation. The spatial metadata is preserved but adjusted to reflect the new number of volumes.

Memory usage is proportional to the number of volumes requested, not the size of the full dataset.

Value

a NeuroVec object that is a sub-sequence of the supplied object.

A DenseNeuroVec object containing the extracted volumes.

A NeuroVecSeq object containing the extracted subsequence

Examples

bvec <- NeuroVec(array(rnorm(24*24*24*24), c(24,24,24,24)), NeuroSpace(c(24,24,24,24), c(1,1,1)))
vec <- sub_vector(bvec,1:2)
all.equal(2, dim(vec)[4])

vec <- sub_vector(bvec, c(1,3,5,7))
all.equal(4, dim(vec)[4])

mask <- LogicalNeuroVol(rep(TRUE, 24*24*24), NeuroSpace(c(24,24,24), c(1,1,1)))
svec <- SparseNeuroVec(array(rnorm(24*24*24*24), c(24,24,24,24)),
NeuroSpace(c(24,24,24,24), c(1,1,1)), mask)
vec <- sub_vector(svec, c(1,3,5))
all.equal(3, dim(vec)[4])
## Not run: 
fbvec <- FileBackedNeuroVec("fmri_data.nii")

# Extract first 10 volumes
subset <- sub_vector(fbvec, 1:10)

# Extract specific timepoints
volumes <- sub_vector(fbvec, c(1, 5, 10))

## End(Not run)


bbuchsbaum/neuroim2 documentation built on Jan. 2, 2025, 3:38 p.m.