data_chunks | R Documentation |
Split a dataset into manageable chunks for processing. This is particularly useful for parallel processing of large fMRI datasets. Chunks can be created either by run (runwise=TRUE) or by dividing the data into a specified number of pieces. Each chunk contains a subset of the data and metadata about its position in the full dataset.
data_chunks(x, nchunks, ...)
x |
The dataset to chunk (typically an fmri_dataset or matrix_dataset) |
... |
Additional arguments passed to methods. Common arguments include:
|
An iterator object that yields data chunks, where each chunk contains:
Matrix of data values for this chunk
Index of this chunk
Indices of voxels in this chunk
Indices of timepoints in this chunk
matrix_dataset()
, fmri_dataset()
, foreach::foreach()
# Create a simple matrix dataset
X <- matrix(rnorm(100 * 1000), 100, 1000) # 100 timepoints, 1000 voxels
dset <- matrix_dataset(
X,
TR = 2,
run_length = c(50, 50) # Two runs of 50 timepoints each
)
# Create chunks by run
run_chunks <- data_chunks(dset, runwise = TRUE)
# Process each run chunk
foreach::foreach(chunk = run_chunks) %do% {
# chunk$data contains the data for one run
# chunk$row_ind shows which timepoints are included
mean_signal <- colMeans(chunk$data)
}
# Create arbitrary number of chunks
vox_chunks <- data_chunks(dset, nchunks = 4)
# Process chunks in parallel
foreach::foreach(chunk = vox_chunks) %dopar% {
# chunk$data contains subset of voxels
# chunk$voxel_ind shows which voxels are included
apply(chunk$data, 2, sd)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.