| Title: | Unified Container for fMRI Datasets |
|---|---|
| Description: | Provides a unified S3 class 'fmri_dataset' for representing functional magnetic resonance imaging (fMRI) data from various sources including raw NIfTI files, BIDS projects, pre-loaded NeuroVec objects, and in-memory matrices. Features lazy loading, flexible data access patterns, and integration with neuroimaging analysis workflows. |
| Authors: | Bradley Buchsbaum [aut, cre] (ORCID: <https://orcid.org/0000-0001-5800-9890>) |
| Maintainer: | Bradley Buchsbaum <[email protected]> |
| License: | GPL (>= 3) |
| Version: | 0.8.9 |
| Built: | 2026-05-11 14:10:14 UTC |
| Source: | https://github.com/bbuchsbaum/fmridataset |
Select all voxels in the dataset mask.
all_selector()all_selector()
An object of class all_selector
# Select all voxels sel <- all_selector()# Select all voxels sel <- all_selector()
Provides a lightweight S3 interface that defers materialization of backend
data. The returned object is compatible with delarr::collect() as well as
base as.matrix() for realization.
as_delarr(backend, ...) ## S3 method for class 'matrix_backend' as_delarr(backend, ...) ## S3 method for class 'nifti_backend' as_delarr(backend, ...) ## S3 method for class 'study_backend' as_delarr(backend, ...) ## Default S3 method: as_delarr(backend, ...)as_delarr(backend, ...) ## S3 method for class 'matrix_backend' as_delarr(backend, ...) ## S3 method for class 'nifti_backend' as_delarr(backend, ...) ## S3 method for class 'study_backend' as_delarr(backend, ...) ## Default S3 method: as_delarr(backend, ...)
backend |
A storage backend object |
... |
Passed to methods |
A delarr lazy matrix
Provides a DelayedArray interface for storage backends. The returned object lazily retrieves data via the backend when subsets of the array are accessed.
as_delayed_array(backend, sparse_ok = FALSE, ...) ## S3 method for class 'nifti_backend' as_delayed_array(backend, sparse_ok = FALSE, ...) ## S3 method for class 'matrix_backend' as_delayed_array(backend, sparse_ok = FALSE, ...) ## S3 method for class 'study_backend' as_delayed_array(backend, sparse_ok = FALSE, ...) ## Default S3 method: as_delayed_array(backend, sparse_ok = FALSE, ...)as_delayed_array(backend, sparse_ok = FALSE, ...) ## S3 method for class 'nifti_backend' as_delayed_array(backend, sparse_ok = FALSE, ...) ## S3 method for class 'matrix_backend' as_delayed_array(backend, sparse_ok = FALSE, ...) ## S3 method for class 'study_backend' as_delayed_array(backend, sparse_ok = FALSE, ...) ## Default S3 method: as_delayed_array(backend, sparse_ok = FALSE, ...)
backend |
A storage backend object |
sparse_ok |
Logical, allow sparse representation when possible |
... |
Additional arguments passed to methods |
A DelayedArray object
## Not run: b <- matrix_backend(matrix(rnorm(20), nrow = 5)) da <- as_delayed_array(b) dim(da) ## End(Not run)## Not run: b <- matrix_backend(matrix(rnorm(20), nrow = 5)) da <- as_delayed_array(b) dim(da) ## End(Not run)
Provides DelayedArray interface for dataset objects. These methods convert fmri_dataset and matrix_dataset objects to DelayedArrays for memory-efficient operations.
## S4 method for signature 'matrix_dataset' as_delayed_array(backend, sparse_ok = FALSE) ## S4 method for signature 'fmri_file_dataset' as_delayed_array(backend, sparse_ok = FALSE) ## S4 method for signature 'fmri_mem_dataset' as_delayed_array(backend, sparse_ok = FALSE)## S4 method for signature 'matrix_dataset' as_delayed_array(backend, sparse_ok = FALSE) ## S4 method for signature 'fmri_file_dataset' as_delayed_array(backend, sparse_ok = FALSE) ## S4 method for signature 'fmri_mem_dataset' as_delayed_array(backend, sparse_ok = FALSE)
backend |
A storage backend object |
sparse_ok |
Logical, allow sparse representation when possible |
Coerce a data frame into an fmri_group
as_fmri_group( subjects, id, dataset_col = "dataset", space = NULL, mask_strategy = c("subject_specific", "intersect", "union") )as_fmri_group( subjects, id, dataset_col = "dataset", space = NULL, mask_strategy = c("subject_specific", "intersect", "union") )
subjects |
A |
id |
Character scalar giving the name of the subject identifier column. |
dataset_col |
Character scalar naming the list column that stores the per-subject dataset handles. |
space |
Optional character string describing the nominal common space for all subjects (e.g., "MNI152NLin2009cAsym"). |
mask_strategy |
One of "subject_specific", "intersect", or "union" describing how masks should be handled when combining subjects. This is a declarative flag only; no resampling is performed by the constructor. |
An fmri_group object.
The returned tibble contains one row per voxel/timepoint
combination with metadata columns from temporal_info
and voxel_info and a signal column with the data
values.
## S3 method for class 'fmri_series' as_tibble(x, ...)## S3 method for class 'fmri_series' as_tibble(x, ...)
x |
An |
... |
Additional arguments (ignored) |
A tibble with columns from temporal_info, voxel_info, and a signal column containing the fMRI signal values
fmri_series for the class definition,
as.matrix.fmri_series for matrix conversion
# Create small example mat <- matrix(rnorm(12), nrow = 3, ncol = 4) backend <- matrix_backend(mat, mask = rep(TRUE, ncol(mat))) dataset <- fmri_dataset(backend, TR = 1, run_length = nrow(mat)) fs <- fmri_series(dataset) # Convert to tibble tbl_result <- tibble::as_tibble(fs) # Result has 12 rows (3 timepoints x 4 voxels) # with columns: time, voxel, signal# Create small example mat <- matrix(rnorm(12), nrow = 3, ncol = 4) backend <- matrix_backend(mat, mask = rep(TRUE, ncol(mat))) dataset <- fmri_dataset(backend, TR = 1, run_length = nrow(mat)) fs <- fmri_series(dataset) # Convert to tibble tbl_result <- tibble::as_tibble(fs) # Result has 12 rows (3 timepoints x 4 voxels) # with columns: time, voxel, signal
Primary data access method for study-level datasets. By default this
returns a lazy matrix (typically a delarr object) with row-wise
metadata attached. When
materialise = TRUE, the data matrix is materialised and returned as
a tibble with metadata columns prepended.
## S3 method for class 'fmri_study_dataset' as_tibble(x, materialise = FALSE, ...)## S3 method for class 'fmri_study_dataset' as_tibble(x, materialise = FALSE, ...)
x |
An |
materialise |
Logical; return a materialised tibble? Default |
... |
Additional arguments (unused) |
Either a lazy matrix with metadata attributes or a tibble
when materialise = TRUE.
Generic function to convert various fMRI dataset types to matrix_dataset objects. Provides a unified interface for getting matrix-based representations.
as.matrix_dataset(x, ...)as.matrix_dataset(x, ...)
x |
An fMRI dataset object |
... |
Additional arguments passed to methods |
This function converts different dataset representations to the standard matrix_dataset format, which stores data as a matrix with timepoints in rows and voxels in columns. This is useful for algorithms that require matrix operations or when a consistent data format is needed.
A matrix_dataset object with the same data as the input
matrix_dataset for creating matrix datasets,
get_data_matrix for extracting data as matrix
# Convert various dataset types to matrix_dataset # (example requires actual dataset object) # mat_ds <- as.matrix_dataset(some_dataset)# Convert various dataset types to matrix_dataset # (example requires actual dataset object) # mat_ds <- as.matrix_dataset(some_dataset)
This method realizes the underlying lazy matrix and returns an ordinary matrix with timepoints in rows and voxels in columns.
## S3 method for class 'fmri_series' as.matrix(x, ...)## S3 method for class 'fmri_series' as.matrix(x, ...)
x |
An |
... |
Additional arguments (ignored) |
A matrix with timepoints as rows and voxels as columns
fmri_series for the class definition,
as_tibble.fmri_series for tibble conversion
# Create small example mat <- matrix(rnorm(20), nrow = 4, ncol = 5) backend <- matrix_backend(mat, mask = rep(TRUE, ncol(mat))) dataset <- fmri_dataset(backend, TR = 1, run_length = nrow(mat)) fs <- fmri_series(dataset) # Convert to matrix mat_result <- as.matrix(fs) dim(mat_result) # 4 x 5# Create small example mat <- matrix(rnorm(20), nrow = 4, ncol = 5) backend <- matrix_backend(mat, mask = rep(TRUE, ncol(mat))) dataset <- fmri_dataset(backend, TR = 1, run_length = nrow(mat)) fs <- fmri_series(dataset) # Convert to matrix mat_result <- as.matrix(fs) dim(mat_result) # 4 x 5
Opens a BIDS HDF5 archive created by compress_bids_study() and
returns a bids_h5_study_dataset that is a subclass of
fmri_study_dataset. All standard fmridataset methods
(get_data_matrix, data_chunks, as_delarr, etc.) work
on the returned object.
bids_h5_dataset(file, preload = FALSE)bids_h5_dataset(file, preload = FALSE)
file |
Character string. Path to the |
preload |
Logical. Reserved for future use (ignored in Phase 1). |
A bids_h5_study_dataset object (subclass of
fmri_study_dataset).
compress_bids_study, subset_bids_h5,
participants, tasks, sessions
Generates a vector of block/run identifiers for each timepoint.
blockids(x, ...) ## S3 method for class 'fmri_dataset' blockids(x, ...) ## S3 method for class 'sampling_frame' blockids(x, ...)blockids(x, ...) ## S3 method for class 'fmri_dataset' blockids(x, ...) ## S3 method for class 'sampling_frame' blockids(x, ...)
x |
An object containing temporal structure (e.g., sampling_frame, fmri_dataset) |
... |
Additional arguments passed to methods |
This function creates a vector where each element indicates which run/block the corresponding timepoint belongs to. This is useful for run-wise analyses or modeling run effects.
Integer vector of length equal to total timepoints, with values indicating run membership (1 for first run, 2 for second, etc.)
get_run_lengths for run lengths,
samples for timepoint indices
# Create a sampling frame with 2 runs of different lengths sf <- fmrihrf::sampling_frame(blocklens = c(3, 4), TR = 2) blockids(sf) # Returns: c(1, 1, 1, 2, 2, 2, 2)# Create a sampling frame with 2 runs of different lengths sf <- fmrihrf::sampling_frame(blocklens = c(3, 4), TR = 2) blockids(sf) # Returns: c(1, 1, 1, 2, 2, 2, 2)
Generic function to extract block/run lengths from various objects. Extends the sampling_frame generic to work with dataset objects.
blocklens(x, ...) ## S3 method for class 'fmri_dataset' blocklens(x, ...) ## S3 method for class 'sampling_frame' blocklens(x, ...)blocklens(x, ...) ## S3 method for class 'fmri_dataset' blocklens(x, ...) ## S3 method for class 'sampling_frame' blocklens(x, ...)
x |
An object with block structure (e.g., sampling_frame, fmri_dataset) |
... |
Additional arguments passed to methods |
In fMRI experiments, data is often collected in multiple runs or blocks. This function extracts the length (number of timepoints) of each run. The sum of block lengths equals the total number of timepoints.
Integer vector where each element represents the number of timepoints in the corresponding run/block
n_runs for number of runs,
n_timepoints for total timepoints,
get_run_lengths for alternative function name
# Create a dataset with 3 runs sf <- fmrihrf::sampling_frame(blocklens = c(100, 120, 110), TR = 2) blocklens(sf) # c(100, 120, 110) # Create dataset with multiple runs mat <- matrix(rnorm(330 * 50), nrow = 330, ncol = 50) ds <- matrix_dataset(mat, TR = 2, run_length = c(100, 120, 110)) blocklens(ds) # c(100, 120, 110)# Create a dataset with 3 runs sf <- fmrihrf::sampling_frame(blocklens = c(100, 120, 110), TR = 2) blocklens(sf) # c(100, 120, 110) # Create dataset with multiple runs mat <- matrix(rnorm(330 * 50), nrow = 330, ncol = 50) ds <- matrix_dataset(mat, TR = 2, run_length = c(100, 120, 110)) blocklens(ds) # c(100, 120, 110)
This function collects all chunks from a chunk iterator into a list.
collect_chunks(chunk_iter)collect_chunks(chunk_iter)
chunk_iter |
A chunk iterator object created by chunk_iter() |
A list containing all chunks from the iterator
Converts a BIDS directory (or bidser::bids_project) into a single
compressed HDF5 file containing compressed fMRI data, events, confounds, and
study metadata. The output file can be opened with bids_h5_dataset.
compress_bids_study( x, file, mode = c("parcellated", "latent"), clusters = NULL, summary_fun = mean, encoding = NULL, n_components = NULL, template = NULL, mask = NULL, space = "MNI152NLin2009cAsym", tasks = NULL, subjects = NULL, sessions = NULL, confounds = NULL, compression = 4L, verbose = TRUE )compress_bids_study( x, file, mode = c("parcellated", "latent"), clusters = NULL, summary_fun = mean, encoding = NULL, n_components = NULL, template = NULL, mask = NULL, space = "MNI152NLin2009cAsym", tasks = NULL, subjects = NULL, sessions = NULL, confounds = NULL, compression = 4L, verbose = TRUE )
x |
A |
file |
Character. Path for the output |
mode |
Character. Compression strategy: |
clusters |
A |
summary_fun |
Function applied to voxel time-series within each parcel
to produce a scalar summary (default: |
encoding |
A |
n_components |
Integer. Shorthand for latent PCA with K components.
If |
template |
Optional |
mask |
A |
space |
Character. Template space name stored as metadata
(default: |
tasks |
Character vector. Task filter; |
subjects |
Character vector. Subject filter; |
sessions |
Character vector. Session filter; |
confounds |
A confound specification passed to
|
compression |
Integer 0–9. HDF5 gzip compression level (default 4). |
verbose |
Logical. If |
The writer streams scans one at a time — only one NIfTI image is held in memory at a time. For each scan it:
Reads the NIfTI via neuroim2::read_vec().
For parcellated mode: computes parcel averages via
fmristore::summarize_by_clusters() and writes [T, K]
to /scans/<name>/data/summary_data.
For latent mode: encodes via fmrilatent::encode()
and writes basis [T, K], loadings [V, K], and
(optionally) offset [V] to /scans/<name>/data/.
Writes events, confounds, censor, and metadata sub-groups.
Releases the NIfTI from memory.
After all scans are written the /scan_index/ lookup table is
populated and the function returns a bids_h5_dataset reader object.
A bids_h5_dataset object (reader for the newly created file).
If the reader is not yet available the file path is returned invisibly.
See bids_plan.md in the package source for the full v1.0 schema.
The root compression_mode attribute reflects the chosen mode.
## Not run: library(bidser) library(neuroim2) library(fmristore) bids_dir <- system.file("extdata", "ds001", package = "bidser") atlas <- fmristore::get_schaefer_atlas(100) # example atlas # Parcellated mode study <- compress_bids_study( x = bids_dir, file = tempfile(fileext = ".h5"), clusters = atlas, tasks = "nback", verbose = TRUE ) # Latent mode (PCA with 50 components) study_lat <- compress_bids_study( x = bids_dir, file = tempfile(fileext = ".h5"), mode = "latent", n_components = 50L, mask = brain_mask, tasks = "nback", verbose = TRUE ) ## End(Not run)## Not run: library(bidser) library(neuroim2) library(fmristore) bids_dir <- system.file("extdata", "ds001", package = "bidser") atlas <- fmristore::get_schaefer_atlas(100) # example atlas # Parcellated mode study <- compress_bids_study( x = bids_dir, file = tempfile(fileext = ".h5"), clusters = atlas, tasks = "nback", verbose = TRUE ) # Latent mode (PCA with 50 components) study_lat <- compress_bids_study( x = bids_dir, file = tempfile(fileext = ".h5"), mode = "latent", n_components = 50L, mask = brain_mask, tasks = "nback", verbose = TRUE ) ## End(Not run)
Creates a backend instance using the registered factory function. This is the main interface for creating backends by name.
create_backend(name, ..., validate = TRUE)create_backend(name, ..., validate = TRUE)
name |
Character string, name of registered backend type |
... |
Arguments passed to the backend factory function |
validate |
Logical, whether to validate the created backend (default: TRUE) |
A storage backend object
## Not run: # Create a NIfTI backend (assuming it's registered) backend <- create_backend("nifti", source = "data.nii", mask_source = "mask.nii" ) # Create with validation disabled (faster, but riskier) backend <- create_backend("nifti", source = "data.nii", mask_source = "mask.nii", validate = FALSE ) ## End(Not run)## Not run: # Create a NIfTI backend (assuming it's registered) backend <- create_backend("nifti", source = "data.nii", mask_source = "mask.nii" ) # Create with validation disabled (faster, but riskier) backend <- create_backend("nifti", source = "data.nii", mask_source = "mask.nii", validate = FALSE ) ## End(Not run)
Creates a data chunk object that represents a subset of data from an fMRI dataset. A data chunk contains the data matrix along with indices indicating which voxels and time points (rows) are included in the chunk.
data_chunk(mat, voxel_ind, row_ind, chunk_num)data_chunk(mat, voxel_ind, row_ind, chunk_num)
mat |
A matrix containing the chunk data (rows = time points, columns = voxels) |
voxel_ind |
Integer vector of voxel indices included in this chunk |
row_ind |
Integer vector of row (time point) indices included in this chunk |
chunk_num |
Integer indicating the chunk number |
A data_chunk object containing:
The data matrix for this chunk
Indices of voxels in this chunk
Indices of rows (time points) in this chunk
The chunk number
# Create a simple data chunk mat <- matrix(rnorm(100), nrow = 10, ncol = 10) chunk <- data_chunk(mat, voxel_ind = 1:10, row_ind = 1:10, chunk_num = 1) print(chunk)# Create a simple data chunk mat <- matrix(rnorm(100), nrow = 10, ncol = 10) chunk <- data_chunk(mat, voxel_ind = 1:10, row_ind = 1:10, chunk_num = 1) print(chunk)
Generic function to create data chunks for parallel processing from various fMRI dataset types. Supports different chunking strategies.
data_chunks(x, nchunks = 1, runwise = FALSE, ...)data_chunks(x, nchunks = 1, runwise = FALSE, ...)
x |
An fMRI dataset object |
nchunks |
Number of chunks to create (default: 1) |
runwise |
If TRUE, create run-wise chunks (default: FALSE) |
... |
Additional arguments passed to methods |
Large fMRI datasets can be processed more efficiently by dividing them into chunks. This function creates an iterator that yields data chunks for parallel or sequential processing. Two chunking strategies are supported:
Equal-sized chunks: Divides voxels into approximately equal groups
Run-wise chunks: Each chunk contains all voxels from one or more complete runs
A chunk iterator object that yields data chunks when iterated
iter for iteration concepts
# Create a dataset mat <- matrix(rnorm(100 * 1000), nrow = 100, ncol = 1000) ds <- matrix_dataset(mat, TR = 2, run_length = 100) # Create 4 chunks for parallel processing chunks <- data_chunks(ds, nchunks = 4) # Process chunks (example) # results <- foreach(chunk = chunks) %dopar% { # process_chunk(chunk) # }# Create a dataset mat <- matrix(rnorm(100 * 1000), nrow = 100, ncol = 1000) ds <- matrix_dataset(mat, TR = 2, run_length = 100) # Create 4 chunks for parallel processing chunks <- data_chunks(ds, nchunks = 4) # Process chunks (example) # results <- foreach(chunk = chunks) %dopar% { # process_chunk(chunk) # }
This function creates data chunks for fmri_file_dataset objects. It allows for the retrieval of run-wise or sequence-wise data chunks, as well as arbitrary chunks.
## S3 method for class 'fmri_file_dataset' data_chunks(x, nchunks = 1, runwise = FALSE, ...)## S3 method for class 'fmri_file_dataset' data_chunks(x, nchunks = 1, runwise = FALSE, ...)
x |
An object of class 'fmri_file_dataset'. |
nchunks |
The number of data chunks to create. Default is 1. |
runwise |
If TRUE, the data chunks are created run-wise. Default is FALSE. |
... |
Additional arguments. |
A list of data chunks, with each chunk containing the data, voxel indices, row indices, and chunk number.
This function creates data chunks for fmri_mem_dataset objects. It allows for the retrieval of run-wise or sequence-wise data chunks, as well as arbitrary chunks.
## S3 method for class 'fmri_mem_dataset' data_chunks(x, nchunks = 1, runwise = FALSE, ...)## S3 method for class 'fmri_mem_dataset' data_chunks(x, nchunks = 1, runwise = FALSE, ...)
x |
An object of class 'fmri_mem_dataset'. |
nchunks |
The number of data chunks to create. Default is 1. |
runwise |
If TRUE, the data chunks are created run-wise. Default is FALSE. |
... |
Additional arguments. |
A list of data chunks, with each chunk containing the data, voxel indices, row indices, and chunk number.
## Not run: # Create a simple fmri_mem_dataset for demonstration d <- c(10, 10, 10, 10) nvec <- neuroim2::NeuroVec(array(rnorm(prod(d)), d), space = neuroim2::NeuroSpace(d)) mask <- neuroim2::LogicalNeuroVol(array(TRUE, d[1:3]), neuroim2::NeuroSpace(d[1:3])) dset <- fmri_mem_dataset(list(nvec), mask, TR = 2) # Create an iterator with 5 chunks iter <- data_chunks(dset, nchunks = 5) `%do%` <- foreach::`%do%` y <- foreach::foreach(chunk = iter) %do% { colMeans(chunk$data) } length(y) == 5 # Create an iterator with 100 chunks iter <- data_chunks(dset, nchunks = 100) y <- foreach::foreach(chunk = iter) %do% { colMeans(chunk$data) } length(y) == 100 # Create a "runwise" iterator iter <- data_chunks(dset, runwise = TRUE) y <- foreach::foreach(chunk = iter) %do% { colMeans(chunk$data) } length(y) == 1 ## End(Not run)## Not run: # Create a simple fmri_mem_dataset for demonstration d <- c(10, 10, 10, 10) nvec <- neuroim2::NeuroVec(array(rnorm(prod(d)), d), space = neuroim2::NeuroSpace(d)) mask <- neuroim2::LogicalNeuroVol(array(TRUE, d[1:3]), neuroim2::NeuroSpace(d[1:3])) dset <- fmri_mem_dataset(list(nvec), mask, TR = 2) # Create an iterator with 5 chunks iter <- data_chunks(dset, nchunks = 5) `%do%` <- foreach::`%do%` y <- foreach::foreach(chunk = iter) %do% { colMeans(chunk$data) } length(y) == 5 # Create an iterator with 100 chunks iter <- data_chunks(dset, nchunks = 100) y <- foreach::foreach(chunk = iter) %do% { colMeans(chunk$data) } length(y) == 100 # Create a "runwise" iterator iter <- data_chunks(dset, runwise = TRUE) y <- foreach::foreach(chunk = iter) %do% { colMeans(chunk$data) } length(y) == 1 ## End(Not run)
This function creates data chunks for multi-subject study datasets.
## S3 method for class 'fmri_study_dataset' data_chunks(x, nchunks = 1, runwise = FALSE, ...)## S3 method for class 'fmri_study_dataset' data_chunks(x, nchunks = 1, runwise = FALSE, ...)
x |
An object of class 'fmri_study_dataset' |
nchunks |
The number of chunks to split the data into. Default is 1. |
runwise |
If TRUE, creates run-wise chunks instead of arbitrary chunks |
... |
Additional arguments passed to methods |
A list of data chunks, each containing data, indices and chunk number
This function creates data chunks for matrix_dataset objects. It allows for the retrieval of run-wise or sequence-wise data chunks, as well as arbitrary chunks.
## S3 method for class 'matrix_dataset' data_chunks(x, nchunks = 1, runwise = FALSE, ...)## S3 method for class 'matrix_dataset' data_chunks(x, nchunks = 1, runwise = FALSE, ...)
x |
An object of class 'matrix_dataset' |
nchunks |
The number of chunks to split the data into. Default is 1. |
runwise |
If TRUE, creates run-wise chunks instead of arbitrary chunks |
... |
Additional arguments passed to methods |
A list of data chunks, each containing data, indices and chunk number
Dimensions of fmri_series
## S3 method for class 'fmri_series' dim(x)## S3 method for class 'fmri_series' dim(x)
x |
An fmri_series object |
Integer vector of length 2 (timepoints, voxels)
Returns encoding metadata (family, parameters, number of components) stored
in the /latent_meta/ group of a latent-mode BIDS HDF5 archive.
Returns NULL for parcellated-mode archives.
encoding_info(x, ...) ## S3 method for class 'bids_h5_study_dataset' encoding_info(x, ...)encoding_info(x, ...) ## S3 method for class 'bids_h5_study_dataset' encoding_info(x, ...)
x |
A |
... |
Additional arguments passed to methods. |
A named list with elements encoding_family,
encoding_params, and n_components, or NULL.
This function creates an execution strategy that can be used to process fMRI datasets in different ways: voxelwise, runwise, or chunkwise.
exec_strategy( strategy = c("voxelwise", "runwise", "chunkwise"), nchunks = NULL )exec_strategy( strategy = c("voxelwise", "runwise", "chunkwise"), nchunks = NULL )
strategy |
Character string specifying the processing strategy. Options are "voxelwise", "runwise", or "chunkwise". |
nchunks |
Number of chunks to use for "chunkwise" strategy. Ignored for other strategies. |
A function that takes a dataset and returns a chunk iterator configured according to the specified strategy.
Expressions are evaluated in the context of subjects(gd) and may refer to
its columns directly. Multiple expressions are combined with logical AND.
filter_subjects(gd, ...)filter_subjects(gd, ...)
gd |
An |
... |
Logical expressions used to filter rows. |
An updated fmri_group containing only the rows that satisfy all
predicates.
Returns information about the current state of the fmridataset cache, including size, number of objects, hit/miss rates, and memory usage.
fmri_cache_info()fmri_cache_info()
Named list with cache statistics
## Not run: # Get cache information cache_info <- fmri_cache_info() print(cache_info) ## End(Not run)## Not run: # Get cache information cache_info <- fmri_cache_info() print(cache_info) ## End(Not run)
Changes the maximum size of the cache. This will immediately evict objects if the new size is smaller than the current cache contents.
fmri_cache_resize(size_mb)fmri_cache_resize(size_mb)
size_mb |
Numeric cache size in megabytes |
NULL (invisibly)
## Not run: # Resize cache to 1GB fmri_cache_resize(1024) # Check new size fmri_cache_info() ## End(Not run)## Not run: # Resize cache to 1GB fmri_cache_resize(1024) # Check new size fmri_cache_info() ## End(Not run)
Clears the internal cache used by fmridataset for memoized file operations. This can be useful to free memory or force re-reading of files.
fmri_clear_cache()fmri_clear_cache()
NULL (invisibly)
## Not run: # Clear the cache to free memory fmri_clear_cache() ## End(Not run)## Not run: # Clear the cache to free memory fmri_clear_cache() ## End(Not run)
This function creates an fMRI dataset object from a set of scans, design information, and other data. The new implementation uses a pluggable backend architecture.
fmri_dataset( scans, mask = NULL, TR, run_length, event_table = data.frame(), base_path = ".", censor = NULL, preload = FALSE, mode = c("normal", "bigvec", "mmap", "filebacked"), backend = NULL, dummy_mode = FALSE )fmri_dataset( scans, mask = NULL, TR, run_length, event_table = data.frame(), base_path = ".", censor = NULL, preload = FALSE, mode = c("normal", "bigvec", "mmap", "filebacked"), backend = NULL, dummy_mode = FALSE )
scans |
A vector of one or more file names of the images comprising the dataset, or a pre-created storage backend object. |
mask |
Name of the binary mask file indicating the voxels to include in the analysis. Ignored if scans is a backend object. |
TR |
The repetition time in seconds of the scan-to-scan interval. |
run_length |
A vector of one or more integers indicating the number of scans in each run. |
event_table |
A data.frame containing the event onsets and experimental variables. Default is an empty data.frame. |
base_path |
Base directory for relative file names. Absolute paths are used as-is. |
censor |
A binary vector indicating which scans to remove. Default is NULL. |
preload |
Read image scans eagerly rather than on first access. Default is FALSE. |
mode |
The type of storage mode ('normal', 'bigvec', 'mmap', filebacked'). Default is 'normal'. Ignored if scans is a backend object. |
backend |
Deprecated. Use scans parameter to pass a backend object. |
dummy_mode |
Logical, if TRUE allows non-existent files (for testing purposes only). Default is FALSE. |
An fMRI dataset object of class c("fmri_file_dataset", "volumetric_dataset", "fmri_dataset", "list").
## Not run: # Create an fMRI dataset with 3 scans and a mask dset <- fmri_dataset(c("scan1.nii", "scan2.nii", "scan3.nii"), mask = "mask.nii", TR = 2, run_length = rep(300, 3), event_table = data.frame( onsets = c(3, 20, 99, 3, 20, 99, 3, 20, 99), run = c(1, 1, 1, 2, 2, 2, 3, 3, 3) ) ) # Create an fMRI dataset with 1 scan and a mask dset <- fmri_dataset("scan1.nii", mask = "mask.nii", TR = 2, run_length = 300, event_table = data.frame(onsets = c(3, 20, 99), run = rep(1, 3)) ) # Create an fMRI dataset with a backend backend <- nifti_backend(c("scan1.nii", "scan2.nii"), mask_source = "mask.nii") dset <- fmri_dataset(backend, TR = 2, run_length = c(150, 150)) # Create a dummy dataset for testing (files don't need to exist) dset_dummy <- fmri_dataset( scans = c("dummy1.nii", "dummy2.nii"), mask = "dummy_mask.nii", TR = 2, run_length = c(100, 100), dummy_mode = TRUE # Enable dummy mode for testing ) ## End(Not run)## Not run: # Create an fMRI dataset with 3 scans and a mask dset <- fmri_dataset(c("scan1.nii", "scan2.nii", "scan3.nii"), mask = "mask.nii", TR = 2, run_length = rep(300, 3), event_table = data.frame( onsets = c(3, 20, 99, 3, 20, 99, 3, 20, 99), run = c(1, 1, 1, 2, 2, 2, 3, 3, 3) ) ) # Create an fMRI dataset with 1 scan and a mask dset <- fmri_dataset("scan1.nii", mask = "mask.nii", TR = 2, run_length = 300, event_table = data.frame(onsets = c(3, 20, 99), run = rep(1, 3)) ) # Create an fMRI dataset with a backend backend <- nifti_backend(c("scan1.nii", "scan2.nii"), mask_source = "mask.nii") dset <- fmri_dataset(backend, TR = 2, run_length = c(150, 150)) # Create a dummy dataset for testing (files don't need to exist) dset_dummy <- fmri_dataset( scans = c("dummy1.nii", "dummy2.nii"), mask = "dummy_mask.nii", TR = 2, run_length = c(100, 100), dummy_mode = TRUE # Enable dummy mode for testing ) ## End(Not run)
Backward compatibility wrapper for fmri_dataset. This function provides the same interface as the original fmri_dataset function.
fmri_dataset_legacy(scans, mask, TR, run_length, preload = FALSE, ...)fmri_dataset_legacy(scans, mask, TR, run_length, preload = FALSE, ...)
scans |
Either a character vector of file paths to scans or a list of NeuroVec objects |
mask |
Either a character file path to a mask or a NeuroVol mask object |
TR |
The repetition time |
run_length |
Numeric vector of run lengths |
preload |
Whether to preload data into memory |
... |
Additional arguments passed to fmri_dataset |
An fmri_dataset object
## Not run: # Create dataset from files dset <- fmri_dataset_legacy( scans = c("scan1.nii", "scan2.nii"), mask = "mask.nii", TR = 2, run_length = c(100, 100) ) ## End(Not run)## Not run: # Create dataset from files dset <- fmri_dataset_legacy( scans = c("scan1.nii", "scan2.nii"), mask = "mask.nii", TR = 2, run_length = c(100, 100) ) ## End(Not run)
Create an fmri_group (one row per subject)
fmri_group( subjects, id, dataset_col = "dataset", space = NULL, mask_strategy = c("subject_specific", "intersect", "union") )fmri_group( subjects, id, dataset_col = "dataset", space = NULL, mask_strategy = c("subject_specific", "intersect", "union") )
subjects |
A |
id |
Character scalar giving the name of the subject identifier column. |
dataset_col |
Character scalar naming the list column that stores the per-subject dataset handles. |
space |
Optional character string describing the nominal common space for all subjects (e.g., "MNI152NLin2009cAsym"). |
mask_strategy |
One of "subject_specific", "intersect", or "union" describing how masks should be handled when combining subjects. This is a declarative flag only; no resampling is performed by the constructor. |
An object of class fmri_group that wraps the input table.
This function creates an fMRI dataset object specifically from H5 files using the fmristore package. Each scan is stored as an H5 file that loads to an H5NeuroVec object.
fmri_h5_dataset( h5_files, mask_source, TR, run_length, event_table = data.frame(), base_path = ".", censor = NULL, preload = FALSE, mask_dataset = "data/elements", data_dataset = "data" )fmri_h5_dataset( h5_files, mask_source, TR, run_length, event_table = data.frame(), base_path = ".", censor = NULL, preload = FALSE, mask_dataset = "data/elements", data_dataset = "data" )
h5_files |
A vector of one or more file paths to H5 files containing the fMRI data. |
mask_source |
File path to H5 mask file, regular mask file, or in-memory NeuroVol object. |
TR |
The repetition time in seconds of the scan-to-scan interval. |
run_length |
A vector of one or more integers indicating the number of scans in each run. |
event_table |
A data.frame containing the event onsets and experimental variables. Default is an empty data.frame. |
base_path |
Base directory for relative file names. Absolute paths are used as-is. |
censor |
A binary vector indicating which scans to remove. Default is NULL. |
preload |
Read H5NeuroVec objects eagerly rather than on first access. Default is FALSE. |
mask_dataset |
Character string specifying the dataset path within H5 file for mask (default: "data/elements"). |
data_dataset |
Character string specifying the dataset path within H5 files for data (default: "data"). |
An fMRI dataset object of class c("fmri_file_dataset", "volumetric_dataset", "fmri_dataset", "list").
## Not run: # Create an fMRI dataset with H5NeuroVec files (standard fmristore format) dset <- fmri_h5_dataset( h5_files = c("scan1.h5", "scan2.h5", "scan3.h5"), mask_source = "mask.h5", TR = 2, run_length = c(150, 150, 150) ) # Create an fMRI dataset with H5 files and NIfTI mask dset <- fmri_h5_dataset( h5_files = "single_scan.h5", mask_source = "mask.nii", TR = 2, run_length = 300 ) # Custom dataset paths (if using non-standard H5 structure) dset <- fmri_h5_dataset( h5_files = "custom_scan.h5", mask_source = "custom_mask.h5", TR = 2, run_length = 200, data_dataset = "my_data_path", mask_dataset = "my_mask_path" ) ## End(Not run)## Not run: # Create an fMRI dataset with H5NeuroVec files (standard fmristore format) dset <- fmri_h5_dataset( h5_files = c("scan1.h5", "scan2.h5", "scan3.h5"), mask_source = "mask.h5", TR = 2, run_length = c(150, 150, 150) ) # Create an fMRI dataset with H5 files and NIfTI mask dset <- fmri_h5_dataset( h5_files = "single_scan.h5", mask_source = "mask.nii", TR = 2, run_length = 300 ) # Custom dataset paths (if using non-standard H5 structure) dset <- fmri_h5_dataset( h5_files = "custom_scan.h5", mask_source = "custom_mask.h5", TR = 2, run_length = 200, data_dataset = "my_data_path", mask_dataset = "my_mask_path" ) ## End(Not run)
This function is deprecated. Please use latent_dataset() instead,
which provides a proper interface for latent space data.
fmri_latent_dataset( latent_files, mask_source = NULL, TR, run_length, event_table = data.frame(), base_path = ".", censor = NULL, preload = FALSE )fmri_latent_dataset( latent_files, mask_source = NULL, TR, run_length, event_table = data.frame(), base_path = ".", censor = NULL, preload = FALSE )
latent_files |
Source files or objects |
mask_source |
Ignored |
TR |
The repetition time in seconds |
run_length |
Vector of run lengths |
event_table |
Event table |
base_path |
Base path for files |
censor |
Censor vector |
preload |
Whether to preload data |
A latent_dataset object
## Not run: # Use latent_dataset() instead: dset <- latent_dataset( source = c("run1.lv.h5", "run2.lv.h5", "run3.lv.h5"), TR = 2, run_length = c(150, 150, 150) ) ## End(Not run)## Not run: # Use latent_dataset() instead: dset <- latent_dataset( source = c("run1.lv.h5", "run2.lv.h5", "run3.lv.h5"), TR = 2, run_length = c(150, 150, 150) ) ## End(Not run)
This function creates an fMRI memory dataset object, which is a list containing information about the scans, mask, TR, number of runs, event table, base path, sampling frame, and censor.
fmri_mem_dataset( scans, mask, TR, run_length = sapply(scans, function(x) dim(x)[4]), event_table = data.frame(), base_path = ".", censor = NULL )fmri_mem_dataset( scans, mask, TR, run_length = sapply(scans, function(x) dim(x)[4]), event_table = data.frame(), base_path = ".", censor = NULL )
scans |
A list of objects of class |
mask |
A binary mask of class |
TR |
Repetition time (TR) of the fMRI acquisition. |
run_length |
A numeric vector specifying the length of each run in the dataset. Default is the length of the scans. |
event_table |
An optional data frame containing event information. Default is an empty data frame. |
base_path |
Base directory for relative file names. Absolute paths are used as-is. |
censor |
An optional numeric vector specifying which time points to censor. Default is NULL. |
An fMRI memory dataset object of class c("fmri_mem_dataset", "volumetric_dataset", "fmri_dataset", "list").
# Create a NeuroVec object d <- c(10, 10, 10, 10) nvec <- neuroim2::NeuroVec(array(rnorm(prod(d)), d), space = neuroim2::NeuroSpace(d)) # Create a NeuroVol mask mask <- neuroim2::NeuroVol(array(rnorm(10 * 10 * 10), d[1:3]), space = neuroim2::NeuroSpace(d[1:3])) mask[mask < .5] <- 0 # Create an fmri_mem_dataset dset <- fmri_mem_dataset(list(nvec), mask, TR = 2)# Create a NeuroVec object d <- c(10, 10, 10, 10) nvec <- neuroim2::NeuroVec(array(rnorm(prod(d)), d), space = neuroim2::NeuroSpace(d)) # Create a NeuroVol mask mask <- neuroim2::NeuroVol(array(rnorm(10 * 10 * 10), d[1:3]), space = neuroim2::NeuroSpace(d[1:3])) mask[mask < .5] <- 0 # Create an fmri_mem_dataset dset <- fmri_mem_dataset(list(nvec), mask, TR = 2)
An S3 class representing lazily accessed fMRI time series data. The
underlying data is stored in a lazy matrix (typically a delarr
object) with rows corresponding to timepoints and columns
corresponding to voxels.
Core interface for retrieving voxel time series from fMRI datasets.
fmri_series( dataset, selector = NULL, timepoints = NULL, output = c("fmri_series", "DelayedMatrix"), event_window = NULL, ... )fmri_series( dataset, selector = NULL, timepoints = NULL, output = c("fmri_series", "DelayedMatrix"), event_window = NULL, ... )
dataset |
An |
selector |
Spatial selector or |
timepoints |
Optional temporal subset or |
output |
Return type - "FmriSeries" (default) or "DelayedMatrix". |
event_window |
Reserved for future use. |
... |
Additional arguments passed to methods. |
An fmri_series object contains:
data: A lazy matrix with timepoints as rows and voxels as columns
voxel_info: A data.frame containing spatial metadata for each voxel
temporal_info: A data.frame containing metadata for each timepoint
selection_info: A list describing how the data were selected
dataset_info: A list describing the source dataset and backend
An object of class fmri_series
An fmri_series (with a delarr lazy matrix payload) or a
DelayedMatrix when output = "DelayedMatrix".
as.matrix.fmri_series for converting to standard matrix,
as_tibble.fmri_series for converting to tibble format
# Create example fmri_series object mat <- matrix(rnorm(100 * 50), nrow = 100, ncol = 50) backend <- matrix_backend(mat, mask = rep(TRUE, ncol(mat))) dataset <- fmri_dataset(backend, TR = 1, run_length = rep(25, 4)) fs <- fmri_series(dataset) fs# Create example fmri_series object mat <- matrix(rnorm(100 * 50), nrow = 100, ncol = 50) backend <- matrix_backend(mat, mask = rep(TRUE, ncol(mat))) dataset <- fmri_dataset(backend, TR = 1, run_length = rep(25, 4)) fs <- fmri_series(dataset) fs
These functions convert user-facing selectors into numeric indices used by the fmri_series implementation. They are not exported to users directly.
High level constructor that combines multiple fmri_dataset objects
into a single study-level dataset using study_backend.
fmri_study_dataset(datasets, subject_ids = NULL)fmri_study_dataset(datasets, subject_ids = NULL)
datasets |
A list of |
subject_ids |
Optional vector of subject identifiers |
An object of class fmri_study_dataset
Creates an fMRI dataset object from Zarr array files. Zarr is a cloud-native array format that supports chunked, compressed storage and is ideal for large neuroimaging datasets.
fmri_zarr_dataset( zarr_source, TR, run_length, event_table = data.frame(), censor = NULL, preload = FALSE )fmri_zarr_dataset( zarr_source, TR, run_length, event_table = data.frame(), censor = NULL, preload = FALSE )
zarr_source |
Path to Zarr store (directory or URL) |
TR |
The repetition time in seconds |
run_length |
Vector of integers indicating the number of scans in each run |
event_table |
Optional data.frame containing event onsets and experimental variables |
censor |
Optional binary vector indicating which scans to remove |
preload |
Whether to load all data into memory (default: FALSE) |
The Zarr backend expects data organized as a 4D array with dimensions (x, y, z, time). The data is accessed lazily by default, loading only the requested chunks into memory.
Zarr stores should contain a single 4D array. For mask data, provide it separately through the fmri_dataset interface if needed.
An fMRI dataset object of class c("fmri_file_dataset", "volumetric_dataset", "fmri_dataset", "list")
This function uses the CRAN zarr package which is relatively new (v0.1.1, Dec 2025). It supports Zarr v3 format only - Zarr v2 stores cannot be read. Please report any issues to help improve the package.
## Not run: # Local Zarr store dataset <- fmri_zarr_dataset( "path/to/data.zarr", TR = 2, run_length = c(150, 150, 150) ) # Remote store dataset <- fmri_zarr_dataset( "https://example.com/subject01.zarr", TR = 1.5, run_length = 300 ) # Preload small dataset into memory dataset <- fmri_zarr_dataset( "small_data.zarr", TR = 2, run_length = 100, preload = TRUE ) ## End(Not run)## Not run: # Local Zarr store dataset <- fmri_zarr_dataset( "path/to/data.zarr", TR = 2, run_length = c(150, 150, 150) ) # Remote store dataset <- fmri_zarr_dataset( "https://example.com/subject01.zarr", TR = 1.5, run_length = 300 ) # Preload small dataset into memory dataset <- fmri_zarr_dataset( "small_data.zarr", TR = 2, run_length = 100, preload = TRUE ) ## End(Not run)
This file contains all generic function declarations for the refactored fmridataset package. These establish the interface contracts that are implemented by dataset-specific methods in other files.
Retrieves information about a registered backend or lists all registered backends.
get_backend_registry(name = NULL)get_backend_registry(name = NULL)
name |
Character string, name of backend to query. If NULL, returns all registrations. |
For a specific backend: a list with registration details. For all backends: a named list where each element contains registration details.
# List all registered backends get_backend_registry() # Get specific backend info get_backend_registry("nifti")# List all registered backends get_backend_registry() # Get specific backend info get_backend_registry("nifti")
Get metadata about the latent components in the dataset.
get_component_info(x, ...)get_component_info(x, ...)
x |
A latent_dataset object |
... |
Additional arguments |
A list containing component metadata
Other latent_data:
get_latent_scores(),
get_spatial_loadings(),
latent_dataset(),
reconstruct_voxels()
Generic function to retrieve confound regressor matrices stored in a BIDS HDF5 dataset.
get_confounds(x, ...) ## S3 method for class 'bids_h5_study_dataset' get_confounds(x, scan_name = NULL, subject = NULL, task = NULL, ...)get_confounds(x, ...) ## S3 method for class 'bids_h5_study_dataset' get_confounds(x, scan_name = NULL, subject = NULL, task = NULL, ...)
x |
A BIDS H5 study dataset object |
... |
Additional arguments passed to methods |
scan_name |
Character. Scan name key (exact match), or |
subject |
Character. Subject ID filter, or |
task |
Character. Task filter, or |
A tibble (single scan) or named list of tibbles (multiple scans)
Generic function to extract data from various fMRI dataset types. Returns the underlying data in its native format (NeuroVec, matrix, etc.).
get_data(x, ...)get_data(x, ...)
x |
An fMRI dataset object (e.g., fmri_dataset, matrix_dataset) |
... |
Additional arguments passed to methods |
This function extracts the raw data from dataset objects, preserving the original data type. For NeuroVec-based datasets, returns a NeuroVec object. For matrix-based datasets, returns a matrix.
Dataset-specific data object:
For fmri_dataset: Returns the underlying NeuroVec or matrix
For matrix_dataset: Returns the data matrix
get_data_matrix for extracting data as a matrix,
get_mask for extracting the mask
# Create a matrix dataset mat <- matrix(rnorm(100 * 50), nrow = 100, ncol = 50) ds <- matrix_dataset(mat, TR = 2, run_length = 100) # Extract the data data <- get_data(ds) identical(data, mat) # TRUE# Create a matrix dataset mat <- matrix(rnorm(100 * 50), nrow = 100, ncol = 50) ds <- matrix_dataset(mat, TR = 2, run_length = 100) # Extract the data data <- get_data(ds) identical(data, mat) # TRUE
Generic function to extract data as a matrix from various fMRI dataset types. Always returns a matrix with timepoints as rows and voxels as columns.
get_data_matrix(x, ...)get_data_matrix(x, ...)
x |
An fMRI dataset object (e.g., fmri_dataset, matrix_dataset) |
... |
Additional arguments passed to methods |
This function provides a unified interface for accessing fMRI data as a matrix, regardless of the underlying storage format. The returned matrix always has timepoints in rows and voxels in columns, matching the conventional fMRI data organization.
A numeric matrix with dimensions:
Rows: Number of timepoints
Columns: Number of voxels (within mask)
get_data for extracting data in native format,
as.matrix_dataset for converting to matrix dataset
# Create a matrix dataset mat <- matrix(rnorm(100 * 50), nrow = 100, ncol = 50) ds <- matrix_dataset(mat, TR = 2, run_length = 100) # Extract as matrix data_mat <- get_data_matrix(ds) dim(data_mat) # 100 x 50# Create a matrix dataset mat <- matrix(rnorm(100 * 50), nrow = 100, ncol = 50) ds <- matrix_dataset(mat, TR = 2, run_length = 100) # Extract as matrix data_mat <- get_data_matrix(ds) dim(data_mat) # 100 x 50
Extract the latent scores (temporal components) from a latent dataset. This is the primary data access method for latent datasets.
get_latent_scores(x, rows = NULL, cols = NULL, ...)get_latent_scores(x, rows = NULL, cols = NULL, ...)
x |
A latent_dataset object |
rows |
Optional row indices (timepoints) to extract |
cols |
Optional column indices (components) to extract |
... |
Additional arguments |
Matrix of latent scores (time × components)
Other latent_data:
get_component_info(),
get_spatial_loadings(),
latent_dataset(),
reconstruct_voxels()
Retrieves the spatial loadings matrix (or matrices) from a latent-mode
BIDS HDF5 archive. Only available when compression_mode = "latent".
get_loadings(x, scan_name = NULL, ...) ## S3 method for class 'bids_h5_study_dataset' get_loadings(x, scan_name = NULL, ...)get_loadings(x, scan_name = NULL, ...) ## S3 method for class 'bids_h5_study_dataset' get_loadings(x, scan_name = NULL, ...)
x |
A |
scan_name |
Character. Name of a specific scan, or |
... |
Additional arguments passed to methods. |
A numeric matrix [V, K] for a single scan, or a named list of
such matrices when scan_name = NULL.
Generic function to extract masks from various fMRI dataset types. Returns the mask in its appropriate format for the dataset type.
get_mask(x, ...)get_mask(x, ...)
x |
An fMRI dataset object (e.g., fmri_dataset, matrix_dataset) |
... |
Additional arguments passed to methods |
The mask defines which voxels are included in the analysis. Different dataset types may store masks in different formats (logical vectors, NeuroVol objects, etc.). This function provides a unified interface for mask extraction.
Mask object appropriate for the dataset type:
For matrix_dataset: Logical vector
For fmri_dataset: NeuroVol or logical vector
get_data for extracting data,
get_data_matrix for extracting data as matrix
# Create a matrix dataset (matrix_dataset creates default mask internally) mat <- matrix(rnorm(100 * 50), nrow = 100, ncol = 50) ds <- matrix_dataset(mat, TR = 2, run_length = 100) # Extract the mask (matrix_dataset creates all TRUE mask by default) extracted_mask <- get_mask(ds) sum(extracted_mask) # 50 (all TRUE values)# Create a matrix dataset (matrix_dataset creates default mask internally) mat <- matrix(rnorm(100 * 50), nrow = 100, ncol = 50) ds <- matrix_dataset(mat, TR = 2, run_length = 100) # Extract the mask (matrix_dataset creates all TRUE mask by default) extracted_mask <- get_mask(ds) sum(extracted_mask) # 50 (all TRUE values)
Calculates the duration of each run in seconds.
get_run_duration(x, ...) ## S3 method for class 'fmri_dataset' get_run_duration(x, ...) ## S3 method for class 'sampling_frame' get_run_duration(x, ...)get_run_duration(x, ...) ## S3 method for class 'fmri_dataset' get_run_duration(x, ...) ## S3 method for class 'sampling_frame' get_run_duration(x, ...)
x |
An object containing temporal structure (e.g., sampling_frame, fmri_dataset) |
... |
Additional arguments passed to methods |
Numeric vector where each element represents the duration of the corresponding run in seconds
get_total_duration for total duration,
get_run_lengths for run lengths in timepoints
# Create a sampling frame with different run lengths sf <- fmrihrf::sampling_frame(blocklens = c(100, 120), TR = 2) get_run_duration(sf) # Returns: c(200, 240) seconds# Create a sampling frame with different run lengths sf <- fmrihrf::sampling_frame(blocklens = c(100, 120), TR = 2) get_run_duration(sf) # Returns: c(200, 240) seconds
Extracts the lengths of individual runs/blocks from objects containing temporal structure information.
get_run_lengths(x, ...) ## S3 method for class 'fmri_dataset' get_run_lengths(x, ...) ## S3 method for class 'sampling_frame' get_run_lengths(x, ...)get_run_lengths(x, ...) ## S3 method for class 'fmri_dataset' get_run_lengths(x, ...) ## S3 method for class 'sampling_frame' get_run_lengths(x, ...)
x |
An object containing temporal structure (e.g., sampling_frame, fmri_dataset) |
... |
Additional arguments passed to methods |
This function is synonymous with blocklens but uses
terminology more common in fMRI analysis. Each run represents a
continuous acquisition period, and the run length is the number
of timepoints (volumes) in that run.
Integer vector where each element represents the number of timepoints in the corresponding run
blocklens for equivalent function,
n_runs for number of runs,
n_timepoints for total timepoints
# Create a sampling frame with 3 runs sf <- fmrihrf::sampling_frame(blocklens = c(100, 120, 110), TR = 2) get_run_lengths(sf) # Returns: c(100, 120, 110)# Create a sampling frame with 3 runs sf <- fmrihrf::sampling_frame(blocklens = c(100, 120, 110), TR = 2) get_run_lengths(sf) # Returns: c(100, 120, 110)
Extract the spatial loadings (spatial components) from a latent dataset.
get_spatial_loadings(x, components = NULL, ...)get_spatial_loadings(x, components = NULL, ...)
x |
A latent_dataset object |
components |
Optional component indices to extract |
... |
Additional arguments |
Matrix or sparse matrix of spatial loadings (voxels × components)
Other latent_data:
get_component_info(),
get_latent_scores(),
latent_dataset(),
reconstruct_voxels()
Calculates the total duration of the fMRI acquisition in seconds across all runs.
get_total_duration(x, ...) ## S3 method for class 'fmri_dataset' get_total_duration(x, ...) ## S3 method for class 'sampling_frame' get_total_duration(x, ...)get_total_duration(x, ...) ## S3 method for class 'fmri_dataset' get_total_duration(x, ...) ## S3 method for class 'sampling_frame' get_total_duration(x, ...)
x |
An object containing temporal structure (e.g., sampling_frame, fmri_dataset) |
... |
Additional arguments passed to methods |
Numeric value representing total duration in seconds
get_run_duration for individual run durations,
get_TR for repetition time
# Create a sampling frame: 220 timepoints with TR = 2 seconds sf <- fmrihrf::sampling_frame(blocklens = c(100, 120), TR = 2) get_total_duration(sf) # Returns: 440 seconds# Create a sampling frame: 220 timepoints with TR = 2 seconds sf <- fmrihrf::sampling_frame(blocklens = c(100, 120), TR = 2) get_total_duration(sf) # Returns: 440 seconds
Extracts the repetition time (TR) in seconds from objects containing temporal information about fMRI acquisitions.
get_TR(x, ...) ## S3 method for class 'fmri_dataset' get_TR(x, ...) ## S3 method for class 'sampling_frame' get_TR(x, ...)get_TR(x, ...) ## S3 method for class 'fmri_dataset' get_TR(x, ...) ## S3 method for class 'sampling_frame' get_TR(x, ...)
x |
An object containing temporal information (e.g., sampling_frame, fmri_dataset) |
... |
Additional arguments passed to methods |
The TR (repetition time) is the time between successive acquisitions of the same slice in an fMRI scan, typically measured in seconds. This parameter is crucial for temporal analyses and hemodynamic modeling.
Numeric value representing TR in seconds
fmrihrf::sampling_frame() for creating temporal structures,
get_total_duration for total scan duration
# Create a sampling frame with TR = 2 seconds sf <- fmrihrf::sampling_frame(blocklens = c(100, 120), TR = 2) get_TR(sf) # Returns: 2# Create a sampling frame with TR = 2 seconds sf <- fmrihrf::sampling_frame(blocklens = c(100, 120), TR = 2) get_TR(sf) # Returns: 2
Map a function over subjects in an fmri_group
group_map( gd, .f, ..., out = c("list", "bind_rows"), order_by = NULL, on_error = c("stop", "warn", "skip") )group_map( gd, .f, ..., out = c("list", "bind_rows"), order_by = NULL, on_error = c("stop", "warn", "skip") )
gd |
An |
.f |
A function with signature |
... |
Additional arguments passed through to |
out |
Either "list" (default) or "bind_rows" describing how to collect outputs. |
order_by |
Optional column name used to define iteration order. |
on_error |
One of "stop", "warn", or "skip" describing how to handle
errors raised by |
Either a list (for out = "list") or a bound table (for
out = "bind_rows").
Reduce over subjects in a single pass
group_reduce( gd, .map, .reduce, .init, order_by = NULL, on_error = c("stop", "warn", "skip"), ... )group_reduce( gd, .map, .reduce, .init, order_by = NULL, on_error = c("stop", "warn", "skip"), ... )
gd |
An |
.map |
Function applied to each subject row. Should return an object that
can be combined by |
.reduce |
Binary function combining the accumulator and the mapped value. |
.init |
Initial accumulator value. |
order_by |
Optional ordering column. |
on_error |
Error handling policy: "stop", "warn", or "skip". |
... |
Additional arguments passed to |
The reduced value after visiting all subjects.
Select voxels by their direct indices in the masked data.
index_selector(indices)index_selector(indices)
indices |
Integer vector of voxel indices |
An object of class index_selector
# Select first 10 voxels sel <- index_selector(1:10) # Select specific voxels sel <- index_selector(c(1, 5, 10, 20))# Select first 10 voxels sel <- index_selector(1:10) # Select specific voxels sel <- index_selector(c(1, 5, 10, 20))
Tests whether a backend type is registered in the system.
is_backend_registered(name)is_backend_registered(name)
name |
Character string, name of backend to check |
Logical, TRUE if backend is registered
is_backend_registered("nifti") # TRUE (built-in) is_backend_registered("custom") # FALSE (unless registered)is_backend_registered("nifti") # TRUE (built-in) is_backend_registered("custom") # FALSE (unless registered)
Check if object is an fmri_series
is.fmri_series(x)is.fmri_series(x)
x |
An object to test |
Logical TRUE if x is an fmri_series object
This function tests whether an object is of class 'sampling_frame'.
is.sampling_frame(x)is.sampling_frame(x)
x |
An object to test |
TRUE if x is a sampling_frame object, FALSE otherwise
Iterate subjects one-by-one (streaming)
iter_subjects(gd, order_by = NULL)iter_subjects(gd, order_by = NULL)
gd |
An |
order_by |
Optional character scalar giving the column used to order
iteration. If supplied, subjects are iterated in ascending order of this
column (with |
A list with a single element next that yields a one-row
data.frame for each subject when called repeatedly. The dataset column is
automatically flattened to the underlying fmri_dataset object.
A specialized dataset interface for working with latent space representations of fMRI data. Unlike traditional fMRI datasets that work with voxel-space data, latent datasets operate on compressed representations using basis functions.
This interface is designed for data that has been decomposed into temporal components (basis functions) and spatial loadings, such as from PCA, ICA, or dictionary learning methods.
Creates a dataset object for working with latent space representations of fMRI data. This is the primary constructor for latent datasets.
latent_dataset( source, TR, run_length, event_table = data.frame(), base_path = ".", censor = NULL, preload = FALSE )latent_dataset( source, TR, run_length, event_table = data.frame(), base_path = ".", censor = NULL, preload = FALSE )
source |
Character vector of file paths to LatentNeuroVec HDF5 files (.lv.h5), or a list of LatentNeuroVec objects from the fmristore or fmrilatent packages. File paths require the fmristore package; in-memory objects do not. |
TR |
The repetition time in seconds. |
run_length |
Vector of integers indicating the number of scans in each run. |
event_table |
Optional data.frame containing event onsets and experimental variables. |
base_path |
Base directory for relative file paths. |
censor |
Optional binary vector indicating which scans to remove. |
preload |
Logical indicating whether to preload all data into memory. |
Data Access: Returns latent scores (time × components) instead of voxel data
Mask: Represents active components, not spatial voxels
Dimensions: Component space rather than voxel space
Reconstruction: Can optionally reconstruct to voxel space on demand
Latent representations store data as:
basis: Temporal components (n_timepoints × k_components)
loadings: Spatial components (n_voxels × k_components)
offset: Optional per-voxel offset terms
Reconstruction: data = basis %*% t(loadings) + offset
A latent_dataset object with class c("latent_dataset", "fmri_dataset").
Other latent_data:
get_component_info(),
get_latent_scores(),
get_spatial_loadings(),
reconstruct_voxels()
Other latent_data:
get_component_info(),
get_latent_scores(),
get_spatial_loadings(),
reconstruct_voxels()
## Not run: # From LatentNeuroVec files dataset <- latent_dataset( source = c("run1.lv.h5", "run2.lv.h5"), TR = 2, run_length = c(100, 100) ) # From pre-loaded objects lvec1 <- fmristore::read_vec("run1.lv.h5") lvec2 <- fmristore::read_vec("run2.lv.h5") dataset <- latent_dataset( source = list(lvec1, lvec2), TR = 2, run_length = c(100, 100) ) # Access latent scores scores <- get_latent_scores(dataset) # Get component metadata comp_info <- get_component_info(dataset) ## End(Not run)## Not run: # From LatentNeuroVec files dataset <- latent_dataset( source = c("run1.lv.h5", "run2.lv.h5"), TR = 2, run_length = c(100, 100) ) # From pre-loaded objects lvec1 <- fmristore::read_vec("run1.lv.h5") lvec2 <- fmristore::read_vec("run2.lv.h5") dataset <- latent_dataset( source = list(lvec1, lvec2), TR = 2, run_length = c(100, 100) ) # Access latent scores scores <- get_latent_scores(dataset) # Get component metadata comp_info <- get_component_info(dataset) ## End(Not run)
Left join additional subject metadata
left_join_subjects(gd, y, by = NULL, ...)left_join_subjects(gd, y, by = NULL, ...)
gd |
An |
y |
A data frame containing additional subject-level columns. |
by |
Character vector of join keys (defaults to the group id column). |
... |
Additional arguments passed to |
An fmri_group with metadata from y attached.
Returns a character vector of all registered backend names.
list_backend_names()list_backend_names()
Character vector of backend names
list_backend_names()list_backend_names()
Select voxels that are TRUE in a binary mask.
mask_selector(mask)mask_selector(mask)
mask |
A logical vector matching the dataset's mask length, or a 3D logical array |
An object of class mask_selector
## Not run: # Using a logical vector mask_vec <- backend_get_mask(dataset$backend) sel <- mask_selector(mask_vec > 0.5) ## End(Not run)## Not run: # Using a logical vector mask_vec <- backend_get_mask(dataset$backend) sel <- mask_selector(mask_vec > 0.5) ## End(Not run)
This function creates a matrix dataset object, which is a list containing information about the data matrix, TR, number of runs, event table, sampling frame, and mask.
matrix_dataset(datamat, TR, run_length, event_table = data.frame())matrix_dataset(datamat, TR, run_length, event_table = data.frame())
datamat |
A matrix where each column is a voxel time-series. |
TR |
Repetition time (TR) of the fMRI acquisition. |
run_length |
A numeric vector specifying the length of each run in the dataset. |
event_table |
An optional data frame containing event information. Default is an empty data frame. |
A matrix dataset object of class c("matrix_dataset", "fmri_dataset", "list").
# A matrix with 100 rows and 100 columns (voxels) X <- matrix(rnorm(100 * 100), 100, 100) dset <- matrix_dataset(X, TR = 2, run_length = 100)# A matrix with 100 rows and 100 columns (voxels) X <- matrix(rnorm(100 * 100), 100, 100) dset <- matrix_dataset(X, TR = 2, run_length = 100)
Adds or modifies columns on the underlying subjects table. Expressions are evaluated sequentially so newly created columns are available to later expressions.
mutate_subjects(gd, ...)mutate_subjects(gd, ...)
gd |
An |
... |
Logical expressions used to filter rows. |
An updated fmri_group with modified subject attributes.
Extracts the total number of runs/blocks from objects containing temporal structure information.
n_runs(x, ...) ## S3 method for class 'fmri_dataset' n_runs(x, ...) ## S3 method for class 'fmri_study_dataset' n_runs(x, ...) ## S3 method for class 'sampling_frame' n_runs(x, ...)n_runs(x, ...) ## S3 method for class 'fmri_dataset' n_runs(x, ...) ## S3 method for class 'fmri_study_dataset' n_runs(x, ...) ## S3 method for class 'sampling_frame' n_runs(x, ...)
x |
An object containing temporal structure (e.g., sampling_frame, fmri_dataset) |
... |
Additional arguments passed to methods |
Integer representing the total number of runs
get_run_lengths for individual run lengths,
n_timepoints for total timepoints
# Create a sampling frame with 3 runs sf <- fmrihrf::sampling_frame(blocklens = c(100, 120, 110), TR = 2) n_runs(sf) # Returns: 3# Create a sampling frame with 3 runs sf <- fmrihrf::sampling_frame(blocklens = c(100, 120, 110), TR = 2) n_runs(sf) # Returns: 3
Number of subjects in a group
n_subjects(gd)n_subjects(gd)
gd |
An |
Integer number of subjects.
Extracts the total number of timepoints (volumes) across all runs from objects containing temporal structure information.
n_timepoints(x, ...) ## S3 method for class 'fmri_dataset' n_timepoints(x, ...) ## S3 method for class 'sampling_frame' n_timepoints(x, ...)n_timepoints(x, ...) ## S3 method for class 'fmri_dataset' n_timepoints(x, ...) ## S3 method for class 'sampling_frame' n_timepoints(x, ...)
x |
An object containing temporal structure (e.g., sampling_frame, fmri_dataset) |
... |
Additional arguments passed to methods |
Integer representing the total number of timepoints
n_runs for number of runs,
get_run_lengths for individual run lengths
# Create a sampling frame with 3 runs sf <- fmrihrf::sampling_frame(blocklens = c(100, 120, 110), TR = 2) n_timepoints(sf) # Returns: 330 (sum of run lengths)# Create a sampling frame with 3 runs sf <- fmrihrf::sampling_frame(blocklens = c(100, 120, 110), TR = 2) n_timepoints(sf) # Returns: 330 (sum of run lengths)
Number of columns in fmri_series
## S3 method for class 'fmri_series' ncol(x)## S3 method for class 'fmri_series' ncol(x)
x |
An fmri_series object |
Number of voxels
Number of rows in fmri_series
## S3 method for class 'fmri_series' nrow(x)## S3 method for class 'fmri_series' nrow(x)
x |
An fmri_series object |
Number of timepoints
Generic function to retrieve parcellation metadata from a BIDS HDF5 dataset stored in parcellated mode.
parcellation_info(x, ...) ## S3 method for class 'bids_h5_study_dataset' parcellation_info(x, ...)parcellation_info(x, ...) ## S3 method for class 'bids_h5_study_dataset' parcellation_info(x, ...)
x |
A BIDS H5 study dataset object |
... |
Additional arguments passed to methods |
A list with elements: cluster_ids, cluster_map, labels, n_parcels
Generic function to extract participant/subject identifiers from study-level fMRI dataset objects. Defined here in fmridataset so methods work without requiring bidser to be installed.
participants(x, ...) ## S3 method for class 'bids_h5_study_dataset' participants(x, ...)participants(x, ...) ## S3 method for class 'bids_h5_study_dataset' participants(x, ...)
x |
A study dataset object (e.g., bids_h5_study_dataset) |
... |
Additional arguments passed to methods |
Character vector of participant identifiers
Display formatted summaries of fmridataset objects including datasets, chunk iterators, and data chunks.
This function prints a summary of a chunk iterator.
This function prints a summary of a data chunk.
## S3 method for class 'fmri_dataset' print(x, full = FALSE, ...) ## S3 method for class 'fmri_dataset' summary(object, ...) ## S3 method for class 'chunkiter' print(x, ...) ## S3 method for class 'data_chunk' print(x, ...) ## S3 method for class 'matrix_dataset' print(x, ...)## S3 method for class 'fmri_dataset' print(x, full = FALSE, ...) ## S3 method for class 'fmri_dataset' summary(object, ...) ## S3 method for class 'chunkiter' print(x, ...) ## S3 method for class 'data_chunk' print(x, ...) ## S3 method for class 'matrix_dataset' print(x, ...)
x |
A data_chunk object. |
full |
Logical; if TRUE, print additional details for datasets (default: FALSE) |
... |
Additional arguments (ignored). |
object |
An object to summarize (for summary methods) |
The object invisibly
# Print dataset summary # dataset <- fmri_dataset(...) # print(dataset) # print(dataset, full = TRUE) # More details# Print dataset summary # dataset <- fmri_dataset(...) # print(dataset) # print(dataset, full = TRUE) # More details
Prints a formatted summary of registered backends.
## S3 method for class 'backend_registry' print(x, ...)## S3 method for class 'backend_registry' print(x, ...)
x |
Result from |
... |
Additional arguments (ignored) |
Invisibly returns the input
Display a concise summary of an fmri_series object, including dimensions, selector type, backend, and data orientation.
## S3 method for class 'fmri_series' print(x, ...)## S3 method for class 'fmri_series' print(x, ...)
x |
An |
... |
Additional arguments (unused) |
Returns x invisibly. Called for its side effect of
printing to the console.
# This method is called automatically when printing # Create example object (see fmri_series documentation) # fs <- new_fmri_series(...) # fs # Automatically calls print method# This method is called automatically when printing # Create example object (see fmri_series documentation) # fs <- new_fmri_series(...) # fs # Automatically calls print method
Display formatted summaries of series selector objects.
## S3 method for class 'series_selector' print(x, ...)## S3 method for class 'series_selector' print(x, ...)
x |
A series selector object |
... |
Additional arguments (currently unused) |
The object invisibly
# Print different selector types sel1 <- index_selector(1:10) print(sel1) sel2 <- voxel_selector(c(10, 20, 15)) print(sel2)# Print different selector types sel1 <- index_selector(1:10) print(sel1) sel2 <- voxel_selector(c(10, 20, 15)) print(sel2)
Reads a fMRI configuration file in YAML or JSON format. This replaces the previous implementation that used source() for security reasons.
read_fmri_config(file_name, base_path = NULL)read_fmri_config(file_name, base_path = NULL)
file_name |
name of configuration file (YAML or JSON format) |
base_path |
the file path to be prepended to relative file names |
a fmri_config instance
Reconstructs full voxel-space time series for a scan by computing
basis %*% t(loadings) + offset. Only available when
compression_mode = "latent".
Reconstruct the full voxel-space data from the latent representation. This is computationally expensive and should be used sparingly.
reconstruct_voxels(x, scan_name = NULL, rows = NULL, voxels = NULL, ...) ## S3 method for class 'bids_h5_study_dataset' reconstruct_voxels(x, scan_name, rows = NULL, voxels = NULL, ...) ## S3 method for class 'latent_dataset' reconstruct_voxels(x, scan_name = NULL, rows = NULL, voxels = NULL, ...)reconstruct_voxels(x, scan_name = NULL, rows = NULL, voxels = NULL, ...) ## S3 method for class 'bids_h5_study_dataset' reconstruct_voxels(x, scan_name, rows = NULL, voxels = NULL, ...) ## S3 method for class 'latent_dataset' reconstruct_voxels(x, scan_name = NULL, rows = NULL, voxels = NULL, ...)
x |
A |
scan_name |
Character. Name of the scan to reconstruct. |
rows |
Integer vector of timepoint indices to return, or |
voxels |
Integer vector of voxel indices to return, or |
... |
Additional arguments passed to methods. |
A numeric matrix [T, V] (or subset thereof).
Other latent_data:
get_component_info(),
get_latent_scores(),
get_spatial_loadings(),
latent_dataset()
Registers a new storage backend type in the global registry. External packages can use this function to add custom backend support.
register_backend( name, factory, description = NULL, validate_function = NULL, overwrite = FALSE )register_backend( name, factory, description = NULL, validate_function = NULL, overwrite = FALSE )
name |
Character string, unique name for the backend type |
factory |
Function that creates backend instances, must accept |
description |
Optional character string describing the backend |
validate_function |
Optional function to validate backend instances beyond the standard contract |
overwrite |
Logical, whether to overwrite existing registration (default: FALSE) |
The factory function should:
Accept all necessary parameters to create a backend instance
Return an object that inherits from "storage_backend"
Implement all required storage backend methods
The validate_function should:
Accept a backend object as first argument
Return TRUE if valid, or throw informative error if invalid
Perform any backend-specific validation beyond the standard contract
Invisibly returns TRUE on successful registration
## Not run: # Register a custom backend my_backend_factory <- function(source, ...) { # Create and return backend instance backend <- list(source = source, ...) class(backend) <- c("my_backend", "storage_backend") backend } register_backend( name = "my_backend", factory = my_backend_factory, description = "Custom backend for my data format" ) ## End(Not run)## Not run: # Register a custom backend my_backend_factory <- function(source, ...) { # Create and return backend instance backend <- list(source = source, ...) class(backend) <- c("my_backend", "storage_backend") backend } register_backend( name = "my_backend", factory = my_backend_factory, description = "Custom backend for my data format" ) ## End(Not run)
Converts a series selector specification into actual voxel indices within the dataset mask.
resolve_indices(selector, dataset, ...)resolve_indices(selector, dataset, ...)
selector |
A series selector object (e.g., index_selector, voxel_selector) |
dataset |
An fMRI dataset object providing spatial context |
... |
Additional arguments passed to methods |
Series selectors provide various ways to specify spatial subsets of fMRI data. This generic function resolves these specifications into actual indices that can be used to extract data. Different selector types support different selection methods:
index_selector: Direct indices into masked data
voxel_selector: 3D coordinates
roi_selector: Region of interest masks
sphere_selector: Spherical regions
Integer vector of indices into the masked data
series_selector for selector types,
fmri_series for using selectors to extract data
# Example with index selector sel <- index_selector(1:10) # indices <- resolve_indices(sel, dataset) # Example with voxel coordinates sel <- voxel_selector(cbind(x = 10, y = 20, z = 15)) # indices <- resolve_indices(sel, dataset)# Example with index selector sel <- index_selector(1:10) # indices <- resolve_indices(sel, dataset) # Example with voxel coordinates sel <- voxel_selector(cbind(x = 10, y = 20, z = 15)) # indices <- resolve_indices(sel, dataset)
Select voxels within a region of interest (ROI) volume or mask.
roi_selector(roi)roi_selector(roi)
roi |
A 3D array, ROIVol, LogicalNeuroVol, or similar mask object |
An object of class roi_selector
## Not run: # Using a binary mask mask <- array(FALSE, dim = c(64, 64, 30)) mask[30:40, 30:40, 15:20] <- TRUE sel <- roi_selector(mask) ## End(Not run)## Not run: # Using a binary mask mask <- array(FALSE, dim = c(64, 64, 30)) mask[30:40, 30:40, 15:20] <- TRUE sel <- roi_selector(mask) ## End(Not run)
Sample subjects from an fmri_group
sample_subjects(gd, n, replace = FALSE, strata = NULL)sample_subjects(gd, n, replace = FALSE, strata = NULL)
gd |
An |
n |
Number of subjects to sample. When |
replace |
Logical indicating whether to sample with replacement. |
strata |
Optional column name used to stratify the sampling. |
A sampled fmri_group.
Generates a vector of timepoint indices, typically used for time series analysis or indexing operations.
samples(x, ...) ## S3 method for class 'fmri_dataset' samples(x, ...) ## S3 method for class 'sampling_frame' samples(x, ...)samples(x, ...) ## S3 method for class 'fmri_dataset' samples(x, ...) ## S3 method for class 'sampling_frame' samples(x, ...)
x |
An object containing temporal structure (e.g., sampling_frame, fmri_dataset) |
... |
Additional arguments passed to methods |
Integer vector from 1 to the total number of timepoints
n_timepoints for total number of samples,
blockids for run membership
# Create a sampling frame sf <- fmrihrf::sampling_frame(blocklens = c(100, 120), TR = 2) s <- samples(sf) length(s) # 220 range(s) # c(1, 220)# Create a sampling frame sf <- fmrihrf::sampling_frame(blocklens = c(100, 120), TR = 2) s <- samples(sf) length(s) # 220 range(s) # c(1, 220)
Generic function to extract the per-scan metadata table from a BIDS HDF5 study dataset.
scan_manifest(x, ...) ## S3 method for class 'bids_h5_study_dataset' scan_manifest(x, ...)scan_manifest(x, ...) ## S3 method for class 'bids_h5_study_dataset' scan_manifest(x, ...)
x |
A BIDS H5 study dataset object |
... |
Additional arguments passed to methods |
A tibble with columns: scan_name, subject, task, session, run, n_time, has_events, has_confounds
fmri_series
series() forwards to fmri_series() for backward compatibility.
A deprecation warning is emitted once per session.
series( dataset, selector = NULL, timepoints = NULL, output = c("fmri_series", "DelayedMatrix"), event_window = NULL, ... )series( dataset, selector = NULL, timepoints = NULL, output = c("fmri_series", "DelayedMatrix"), event_window = NULL, ... )
dataset |
An |
selector |
Spatial selector or |
timepoints |
Optional temporal subset or |
output |
Return type - "FmriSeries" (default) or "DelayedMatrix". |
event_window |
Reserved for future use. |
... |
Additional arguments passed to methods. |
See fmri_series()
A family of S3 classes for specifying spatial selections in fMRI datasets.
These selectors provide a type-safe, explicit interface for selecting voxels
in fmri_series() and related functions.
Generic function to extract session names from study-level fMRI dataset objects. Defined here in fmridataset so methods work without requiring bidser to be installed.
sessions(x, ...) ## S3 method for class 'bids_h5_study_dataset' sessions(x, ...)sessions(x, ...) ## S3 method for class 'bids_h5_study_dataset' sessions(x, ...)
x |
A study dataset object (e.g., bids_h5_study_dataset) |
... |
Additional arguments passed to methods |
Character vector of session names, or NULL if no sessions
Select voxels within a spherical region.
sphere_selector(center, radius)sphere_selector(center, radius)
center |
Numeric vector of length 3 (x, y, z) specifying sphere center |
radius |
Numeric radius in voxel units |
An object of class sphere_selector
# Select 10-voxel radius sphere around voxel (30, 30, 20) sel <- sphere_selector(center = c(30, 30, 20), radius = 10)# Select 10-voxel radius sphere around voxel (30, 30, 20) sel <- sphere_selector(center = c(30, 30, 20), radius = 10)
Stream subjects with optional ordering
stream_subjects(gd, prefetch = 1L, order_by = NULL)stream_subjects(gd, prefetch = 1L, order_by = NULL)
gd |
An |
prefetch |
Number of subjects to prefetch. Currently only |
order_by |
Optional column name used to order subjects. |
An iterator identical to iter_subjects().
Composite backend that lazily combines multiple subject-level backends.
study_backend( backends, subject_ids = NULL, strict = getOption("fmridataset.mask_check", "identical") )study_backend( backends, subject_ids = NULL, strict = getOption("fmridataset.mask_check", "identical") )
backends |
list of storage_backend objects |
subject_ids |
vector of subject identifiers matching |
strict |
mask validation mode. "identical" or "intersect" |
A study_backend object
Converts a bids_h5_study_dataset (or any fmri_study_dataset)
to an fmri_group object with one row per subject. Use this when you
need per-subject group operations via group_map().
study_to_group(x, ...) ## S3 method for class 'bids_h5_study_dataset' study_to_group(x, ...) ## S3 method for class 'fmri_study_dataset' study_to_group(x, ...)study_to_group(x, ...) ## S3 method for class 'bids_h5_study_dataset' study_to_group(x, ...) ## S3 method for class 'fmri_study_dataset' study_to_group(x, ...)
x |
A |
... |
Currently unused. |
An fmri_group with columns subject_id and dataset.
Generic function to extract subject identifiers from multi-subject fMRI dataset objects.
subject_ids(x, ...) ## S3 method for class 'fmri_study_dataset' subject_ids(x, ...)subject_ids(x, ...) ## S3 method for class 'fmri_study_dataset' subject_ids(x, ...)
x |
A multi-subject dataset object (e.g., fmri_study_dataset) |
... |
Additional arguments passed to methods |
Multi-subject datasets contain data from multiple participants. This function extracts the subject identifiers associated with each dataset. The order of subject IDs corresponds to the order of datasets.
Character vector of subject identifiers
Access the subjects tibble stored inside an fmri_group
subjects(x) subjects(x) <- valuesubjects(x) subjects(x) <- value
x |
An |
value |
A replacement table containing the dataset column used by the group. |
The underlying data.frame with one row per subject.
An updated fmri_group.
Filters a bids_h5_study_dataset by task, subject, session, and/or
run using standard (non-NSE) evaluation. Returns a new
bids_h5_study_dataset built from the matching scans, sharing the
same underlying HDF5 file handle.
subset_bids_h5(x, task = NULL, subject = NULL, session = NULL, run = NULL)subset_bids_h5(x, task = NULL, subject = NULL, session = NULL, run = NULL)
x |
A |
task |
Character vector of task names to keep, or |
subject |
Character vector of subject IDs to keep, or |
session |
Character vector of session names to keep, or |
run |
Character vector of BIDS run labels to keep, or |
A new bids_h5_study_dataset containing only the matching scans.
Generic function to extract task names from study-level fMRI dataset objects. Defined here in fmridataset so methods work without requiring bidser to be installed.
tasks(x, ...) ## S3 method for class 'bids_h5_study_dataset' tasks(x, ...)tasks(x, ...) ## S3 method for class 'bids_h5_study_dataset' tasks(x, ...)
x |
A study dataset object (e.g., bids_h5_study_dataset) |
... |
Additional arguments passed to methods |
Character vector of task names present in the dataset
Removes a backend from the registry. Use with caution as this may break code that depends on the backend.
unregister_backend(name)unregister_backend(name)
name |
Character string, name of backend to remove |
Invisibly returns TRUE if backend was removed, FALSE if it wasn't registered
## Not run: # Remove a custom backend unregister_backend("my_custom_backend") ## End(Not run)## Not run: # Remove a custom backend unregister_backend("my_custom_backend") ## End(Not run)
Validate an fmri_group object
validate_fmri_group(x)validate_fmri_group(x)
x |
Object to validate. |
The validated fmri_group (invisibly).
Select voxels by their 3D coordinates in the image space.
voxel_selector(coords)voxel_selector(coords)
coords |
Matrix with 3 columns (x, y, z) or vector of length 3 |
An object of class voxel_selector
# Select single voxel sel <- voxel_selector(c(10, 20, 15)) # Select multiple voxels coords <- cbind(x = c(10, 20), y = c(20, 30), z = c(15, 15)) sel <- voxel_selector(coords)# Select single voxel sel <- voxel_selector(c(10, 20, 15)) # Select multiple voxels coords <- cbind(x = c(10, 20), y = c(20, 30), z = c(15, 15)) sel <- voxel_selector(coords)
Helper for reattaching metadata after DelayedMatrixStats operations.
with_rowData(x, rowData)with_rowData(x, rowData)
x |
A lazy matrix or matrix-like object |
rowData |
A data.frame of row-wise metadata |
x with rowData attribute set
Writes a fMRI configuration to a YAML file for easy editing and sharing.
write_fmri_config(config, file_name)write_fmri_config(config, file_name)
config |
A fmri_config object or list with configuration parameters |
file_name |
Output file name (should end in .yaml or .yml) |