Linear Access to Neuroimaging Data (Methods for neuroim2 Generic)
Source:R/all_generic.R
, R/cluster_array.R
, R/h5neurovec.R
, and 3 more
linear_access-methods.Rd
These methods provide 4D linear access to data for specific `fmristore` classes,
implementing the linear_access
generic function
from the neuroim2
package.
The `linear_access` generic allows direct access to data elements using a single
numeric index that spans the entire 4D space of the object (X, Y, Z, Time).
Refer to the documentation for linear_access
in the neuroim2
package
for general details about the generic concept.
Provides 4D linear access to data in an H5ParcellatedScan
object.
It reconstructs voxel values on the fly from the HDF5 file based on their cluster assignments.
Values for voxels outside the mask are returned as 0.
Usage
linear_access(x, i, ...)
# S4 method for class 'H5ParcellatedScan,numeric'
linear_access(x, i, ...)
# S4 method for class 'H5ParcellatedScanSummary,numeric'
linear_access(x, i, ...)
# S4 method for class 'H5NeuroVec,numeric'
linear_access(x, i)
# S4 method for class 'H5NeuroVec,integer'
linear_access(x, i)
# S4 method for class 'H5NeuroVol,numeric'
linear_access(x, i)
# S4 method for class 'H5NeuroVol,integer'
linear_access(x, i)
# S4 method for class 'LabeledVolumeSet,numeric'
linear_access(x, i)
# S4 method for class 'LatentNeuroVec,numeric'
linear_access(x, i)
# S4 method for class 'LatentNeuroVec,integer'
linear_access(x, i)
Value
A numeric vector of values corresponding to the provided linear indices. The order of values in the returned vector matches the order of indices in `i`.
A numeric vector of values corresponding to the provided linear indices.
See also
neuroim2::linear_access
, specific methods like
linear_access,H5ParcellatedScan,numeric-method
.
Other H5Cluster:
H5ParcellatedMultiScan-class
,
[,H5ParcellatedScan,ANY,ANY,ANY-method
,
[,H5ParcellatedScan,ANY,missing,ANY-method
,
as.data.frame()
,
as.matrix()
,
dim()
,
make_run_full()
,
make_run_summary()
,
series()
,
show,H5ParcellatedScan-method
Other H5Cluster:
H5ParcellatedMultiScan-class
,
[,H5ParcellatedScan,ANY,ANY,ANY-method
,
[,H5ParcellatedScan,ANY,missing,ANY-method
,
as.data.frame()
,
as.matrix()
,
dim()
,
make_run_full()
,
make_run_summary()
,
series()
,
show,H5ParcellatedScan-method
Examples
if (FALSE) { # \dontrun{
if (requireNamespace("neuroim2", quietly = TRUE) &&
requireNamespace("hdf5r", quietly = TRUE) &&
exists("H5ParcellatedMultiScan", where = "package:fmristore") &&
exists("linear_access", where = "package:neuroim2") &&
!is.null(fmristore:::create_minimal_h5_for_H5ParcellatedMultiScan)) {
temp_exp_file <- NULL
exp_obj <- NULL
run_full <- NULL
tryCatch({
# Create a minimal H5ParcellatedMultiScan
temp_exp_file <- fmristore:::create_minimal_h5_for_H5ParcellatedMultiScan(
master_mask_dims = c(3L, 3L, 2L), # Small dimensions
num_master_clusters = 2L,
n_time_run1 = 4L, # For Run1_Full
n_time_run2 = 0 # No need for Run2_Summary here
)
exp_obj <- fmristore::H5ParcellatedMultiScan(file_path = temp_exp_file)
# Access the H5ParcellatedScan object (helper creates "Run1_Full")
# The runs() method should give access to the list of runs
available_runs <- runs(exp_obj)
run_full <- available_runs[["Run1_Full"]] # Assuming helper creates this scan name
if (!is.null(run_full)) {
# Get dimensions: X, Y, Z, T
run_dims <- dim(run_full) # Should be c(3,3,2,4)
total_elements <- prod(run_dims)
# Example: Access first 5 linear indices and last 5
indices_to_access <- c(1:5, (total_elements - 4):total_elements)
# Ensure indices are within bounds if total_elements is small
indices_to_access <- indices_to_access[indices_to_access <= total_elements &
indices_to_access > 0]
indices_to_access <- unique(indices_to_access)
if (length(indices_to_access) > 0) {
accessed_values <- neuroim2::linear_access(run_full, indices_to_access)
cat("Accessed values for H5ParcellatedScan:\n")
print(accessed_values)
cat("Number of values accessed:", length(accessed_values), "\n")
} else {
message("No valid indices to access for linear_access example.")
}
} else {
message("Could not retrieve Run1_Full from the experiment for linear_access example.")
}
}, error = function(e) {
message("linear_access example for H5ParcellatedScan failed: ", e$message)
if (!is.null(temp_exp_file)) message("Temporary file was: ", temp_exp_file)
}, finally = {
if (!is.null(exp_obj)) try(close(exp_obj), silent = TRUE)
# run_full is part of exp_obj, its resources are managed by exp_obj$close()
if (!is.null(temp_exp_file) && file.exists(temp_exp_file)) {
unlink(temp_exp_file)
}
})
} else {
message("Skipping linear_access H5ParcellatedScan example: dependencies/helpers not available.")
}
} # }