| Title: | File-System Toolbox for RAVE Project |
|---|---|
| Description: | Includes multiple cross-platform read/write interfaces for 'RAVE' project. 'RAVE' stands for "R analysis and visualization of human intracranial electroencephalography data". The whole project aims at providing powerful free-source package that analyze brain recordings from patients with electrodes placed on the cortical surface or inserted into the brain. 'raveio' as part of this project provides tools to read/write neurophysiology data from/to 'RAVE' file structure, as well as several popular formats including 'EDF(+)', 'Matlab', 'BIDS-iEEG', and 'HDF5', etc. Documentation and examples about 'RAVE' project are provided at <https://rave.wiki>, and the paper by John F. Magnotti, Zhengjia Wang, Michael S. Beauchamp (2020) <doi:10.1016/j.neuroimage.2020.117341>. For applications such as electrode localization, please check Zhengjia Wang, John F. Magnotti, Xiang Zhang, Michael S. Beauchamp (2023) <doi:10.1523/ENEURO.0328-23.2023>, or see 'citation("raveio")' for details. |
| Authors: | Zhengjia Wang [aut, cre], John Magnotti [aut], Michael Beauchamp [aut], University of Pennsylvania [cph] |
| Maintainer: | Zhengjia Wang <[email protected]> |
| License: | MIT + file LICENSE |
| Version: | 0.9.0.101 |
| Built: | 2026-06-02 18:55:09 UTC |
| Source: | https://github.com/beauchamplab/raveio |
'ANTs'
ants_coreg aligns 'CT' to 'MR' images; ants_mri_to_template
aligns native 'MR' images to group templates
ants_coreg( ct_path, mri_path, coreg_path = NULL, reg_type = c("DenseRigid", "Rigid", "SyN", "Affine", "TRSAA", "SyNCC", "SyNOnly"), aff_metric = c("mattes", "meansquares", "GC"), syn_metric = c("mattes", "meansquares", "demons", "CC"), verbose = TRUE, ... ) cmd_run_ants_coreg( subject, ct_path, mri_path, reg_type = c("DenseRigid", "Rigid", "SyN", "Affine", "TRSAA", "SyNCC", "SyNOnly"), aff_metric = c("mattes", "meansquares", "GC"), syn_metric = c("mattes", "meansquares", "demons", "CC"), verbose = TRUE, dry_run = FALSE ) ants_mri_to_template( subject, template_subject = getOption("threeBrain.template_subject", "N27"), preview = FALSE, verbose = TRUE, ... ) cmd_run_ants_mri_to_template( subject, template_subject = getOption("threeBrain.template_subject", "N27"), verbose = TRUE, dry_run = FALSE ) ants_morph_electrode(subject, preview = FALSE, dry_run = FALSE)ants_coreg( ct_path, mri_path, coreg_path = NULL, reg_type = c("DenseRigid", "Rigid", "SyN", "Affine", "TRSAA", "SyNCC", "SyNOnly"), aff_metric = c("mattes", "meansquares", "GC"), syn_metric = c("mattes", "meansquares", "demons", "CC"), verbose = TRUE, ... ) cmd_run_ants_coreg( subject, ct_path, mri_path, reg_type = c("DenseRigid", "Rigid", "SyN", "Affine", "TRSAA", "SyNCC", "SyNOnly"), aff_metric = c("mattes", "meansquares", "GC"), syn_metric = c("mattes", "meansquares", "demons", "CC"), verbose = TRUE, dry_run = FALSE ) ants_mri_to_template( subject, template_subject = getOption("threeBrain.template_subject", "N27"), preview = FALSE, verbose = TRUE, ... ) cmd_run_ants_mri_to_template( subject, template_subject = getOption("threeBrain.template_subject", "N27"), verbose = TRUE, dry_run = FALSE ) ants_morph_electrode(subject, preview = FALSE, dry_run = FALSE)
ct_path, mri_path
|
absolute paths to 'CT' and 'MR' image files |
coreg_path |
registration path, where to save results; default is
the parent folder of |
reg_type |
registration type, choices are |
aff_metric |
cost function to use for linear or 'affine' transform |
syn_metric |
cost function to use for |
verbose |
whether to verbose command; default is true |
... |
other arguments passed to |
subject |
'RAVE' subject |
dry_run |
whether to dry-run the script and to print out the command instead of executing the code; default is false |
template_subject |
template to map 'MR' images |
preview |
whether to preview results; default is false |
Aligned 'CT' will be generated at the coreg_path path:
'ct_in_t1.nii.gz'aligned 'CT' image; the image is also re-sampled into 'MRI' space
'transform.yaml'transform settings and outputs
'CT_IJK_to_MR_RAS.txt'transform matrix from volume 'IJK' space in the original 'CT' to the 'RAS' anatomical coordinate in 'MR' scanner; 'affine' transforms only
'CT_RAS_to_MR_RAS.txt'transform matrix from scanner 'RAS' space in the original 'CT' to 'RAS' in 'MR' scanner space; 'affine' transforms only
'ANTs'
This function is soft-deprecated. Use yael_preprocess instead.
ants_preprocessing( work_path, image_path, resample = FALSE, verbose = TRUE, template_subject = raveio_getopt("threeBrain_template_subject") )ants_preprocessing( work_path, image_path, resample = FALSE, verbose = TRUE, template_subject = raveio_getopt("threeBrain_template_subject") )
work_path |
working directory, all intermediate images will be stored here |
image_path |
input image path |
resample |
whether to resample the input image before processing |
verbose |
whether to verbose the processing details |
template_subject |
template mapping, default is derived from
|
Nothing. All images are saved to work_path
Archive and share a subject
archive_subject( subject, path, includes = c("orignal_signals", "processed_data", "rave_imaging", "pipelines", "notes", "user_generated"), config = list(), work_path = NULL, zip_flags = NULL )archive_subject( subject, path, includes = c("orignal_signals", "processed_data", "rave_imaging", "pipelines", "notes", "user_generated"), config = list(), work_path = NULL, zip_flags = NULL )
subject |
'RAVE' subject to archive |
path |
path to a zip file to store; if missing or empty, then the path will be automatically created |
includes |
data to include in the archive; default includes all ( original raw signals, processed signals, imaging files, stored pipelines, notes, and user-generated exports) |
config |
a list of configurations, including changing subject code, project name, or to exclude cache data; see examples |
work_path |
temporary working path where files are copied; default is temporary path. Set this variable explicitly when temporary path is on external drives (for example, users have limited storage on local drives and cannot hold the entire subject) |
zip_flags |
|
# This example requires you to install demo subject ## Not run: # Basic usage path <- archive_subject('demo/DemoSubject') # clean up unlink(path) # Advanced usage: include all the original signals # and processed data, no cache data, re-name to # demo/DemoSubjectLite path <- archive_subject( 'demo/DemoSubject', includes = c("orignal_signals", "processed_data"), config = list( rename = list( project_name = "demo", subject_code = "DemoSubjectLite" ), orignal_signals = list( # include all raw signals include_all = TRUE ), processed_data = list( include_cache = FALSE ) ) ) # Clean up temporary zip file unlink(path) ## End(Not run)# This example requires you to install demo subject ## Not run: # Basic usage path <- archive_subject('demo/DemoSubject') # clean up unlink(path) # Advanced usage: include all the original signals # and processed data, no cache data, re-name to # demo/DemoSubjectLite path <- archive_subject( 'demo/DemoSubject', includes = c("orignal_signals", "processed_data"), config = list( rename = list( project_name = "demo", subject_code = "DemoSubjectLite" ), orignal_signals = list( # include all raw signals include_all = TRUE ), processed_data = list( include_cache = FALSE ) ) ) # Clean up temporary zip file unlink(path) ## End(Not run)
RAVEProject instanceConvert character to RAVEProject instance
as_rave_project(project, ...)as_rave_project(project, ...)
project |
character project name |
... |
passed to other methods |
A RAVEProject instance
RAVESubject instance from characterGet RAVESubject instance from character
as_rave_subject(subject_id, strict = TRUE, reload = TRUE)as_rave_subject(subject_id, strict = TRUE, reload = TRUE)
subject_id |
character in format |
strict |
whether to check if subject directories exist or not |
reload |
whether to reload (update) subject information, default is true |
RAVESubject instance
Convert numeric number into print-friendly format
as_rave_unit(x, unit, label = "")as_rave_unit(x, unit, label = "")
x |
numeric or numeric vector |
unit |
the unit of |
label |
prefix when printing |
Still numeric, but print-friendly class
sp <- as_rave_unit(1024, 'GB', 'Hard-disk space is ') print(sp, digits = 0) sp - 12 as.character(sp) as.numeric(sp) # Vectorize sp <- as_rave_unit(c(500,200), 'MB/s', c('Writing: ', 'Reading: ')) print(sp, digits = 0, collapse = '\n')sp <- as_rave_unit(1024, 'GB', 'Hard-disk space is ') print(sp, digits = 0) sp - 12 as.character(sp) as.numeric(sp) # Vectorize sp <- as_rave_unit(c(500,200), 'MB/s', c('Writing: ', 'Reading: ')) print(sp, digits = 0, collapse = '\n')
Image registration across different modals. Normalize brain 'T1'-weighted 'MRI' to template brain and generate subject-level atlas files.
as_yael_process(subject)as_yael_process(subject)
subject |
character (subject code, or project name with subject code),
or |
A processing instance, see YAELProcess
library(raveio) process <- as_yael_process("testtest2") # This example requires extra demo data & settings. ## Not run: # Import and set original T1w MRI and CT process$set_input_image("/path/to/T1w_MRI.nii", type = "T1w") process$set_input_image("/path/to/CT.nii.gz", type = "CT") # Co-register CT to MRI process$register_to_T1w(image_type = "CT") # Morph T1w MRI to 0.5 mm^3 MNI152 template process$map_to_template( template_name = "mni_icbm152_nlin_asym_09b", native_type = "T1w" ) ## End(Not run)library(raveio) process <- as_yael_process("testtest2") # This example requires extra demo data & settings. ## Not run: # Import and set original T1w MRI and CT process$set_input_image("/path/to/T1w_MRI.nii", type = "T1w") process$set_input_image("/path/to/CT.nii.gz", type = "CT") # Co-register CT to MRI process$register_to_T1w(image_type = "CT") # Morph T1w MRI to 0.5 mm^3 MNI152 template process$map_to_template( template_name = "mni_icbm152_nlin_asym_09b", native_type = "T1w" ) ## End(Not run)
Class definition for auxiliary channels
Class definition for auxiliary channels
If simplify is enabled, and only one block is loaded,
then the result will be a vector (type="voltage") or a matrix
(others), otherwise the result will be a named list where the names
are the blocks.
raveio::RAVEAbstarctElectrode -> Auxiliary_electrode
h5_fname'HDF5' file name
validwhether current electrode is valid: subject exists and contains current electrode or reference; subject electrode type matches with current electrode type
raw_sample_ratevoltage sample rate
preprocess_infopreprocess information
voltage_filepath to voltage 'HDF5' file
print()
print electrode summary
Auxiliary_electrode$print()
set_reference()
set reference for current electrode
Auxiliary_electrode$set_reference(reference)
referenceeither NULL or LFP_electrode instance
new()
constructor
Auxiliary_electrode$new(subject, number, quiet = FALSE)
subject, number, quietsee constructor in
RAVEAbstarctElectrode
.load_noref_voltage()
load non-referenced voltage (internally used)
Auxiliary_electrode$.load_noref_voltage(reload = FALSE)
reloadwhether to reload cache
sratevoltage signal sample rate
.load_raw_voltage()
load raw voltage (no process)
Auxiliary_electrode$.load_raw_voltage(reload = FALSE)
reloadwhether to reload cache
load_data()
method to load electrode data
Auxiliary_electrode$load_data(type = c("raw-voltage", "voltage"))typedata type such as "power", "phase",
"voltage", "wavelet-coefficient", and
"raw-voltage". For "power", "phase",
and "wavelet-coefficient", 'Wavelet' transforms are required.
For "voltage", 'Notch' filters must be applied. All these
types except for "raw-voltage" will be referenced.
For "raw-voltage", no reference will be performed since the data
will be the "raw" signal (no processing).
load_blocks()
load electrode block-wise data (with no reference), useful when epoch is absent
Auxiliary_electrode$load_blocks(
blocks,
type = c("raw-voltage", "voltage"),
simplify = TRUE
)blockssession blocks
typedata type such as "power", "phase",
"voltage", "raw-voltage" (with no filters applied, as-is
from imported), "wavelet-coefficient". Note that if type
is "raw-voltage", then the data only needs to be imported;
for "voltage" data, 'Notch' filters must be applied; for
all other types, 'Wavelet' transforms are required.
simplifywhether to simplify the result
clear_cache()
method to clear cache on hard drive
Auxiliary_electrode$clear_cache(...)
...ignored
clear_memory()
method to clear memory
Auxiliary_electrode$clear_memory(...)
...ignored
clone()
The objects of this class are cloneable with this method.
Auxiliary_electrode$clone(deep = FALSE)
deepWhether to make a deep clone.
Back up and rename the file or directory
backup_file(path, remove = FALSE, quiet = FALSE)backup_file(path, remove = FALSE, quiet = FALSE)
path |
path to a file or a directory |
remove |
whether to remove the original path; default is false |
quiet |
whether not to verbose the messages; default is false |
FALSE if nothing to back up, or the back-up path
if path exists
path <- tempfile() file.create(path) path2 <- backup_file(path, remove = TRUE) file.exists(c(path, path2)) unlink(path2)path <- tempfile() file.create(path) path2 <- backup_file(path, remove = TRUE) file.exists(c(path, path2)) unlink(path2)
Currently only supports minimum file specification version
2.3. Please contact the package maintainer or 'RAVE' team
if older specifications are needed
absolute file path
absolute file paths
nothing
a data frame
a list of spike 'waveform' (without normalization)
a normalized numeric vector (analog signals with 'uV'
as the unit)
blockcharacter, session block ID
base_pathabsolute base path to the file
version'NEV' specification version
electrode_tableelectrode table
sample_rate_nev_timestampsample rate of 'NEV' data packet time-stamps
has_nsxnamed vector of 'NSx' availability
recording_durationrecording duration of each 'NSx'
sample_ratessampling frequencies of each 'NSx' file
print()
print user-friendly messages
BlackrockFile$print()
new()
constructor
BlackrockFile$new(path, block, nev_data = TRUE)
paththe path to 'BlackRock' file, can be with or without file extensions
blocksession block ID; default is the file name
nev_datawhether to load comments and 'waveforms'
nev_path()
get 'NEV' file path
BlackrockFile$nev_path()
nsx_paths()
get 'NSx' file paths
BlackrockFile$nsx_paths(which = NULL)
whichwhich signal file to get, or NULL to return all
available paths, default is NULL; must be integers
refresh_data()
refresh and load 'NSx' data
BlackrockFile$refresh_data(force = FALSE, verbose = TRUE, nev_data = FALSE)
forcewhether to force reload data even if the data has been loaded and cached before
verbosewhether to print out messages when loading
nev_datawhether to refresh 'NEV' extended data; default is false
get_epoch()
get epoch table from the 'NEV' comment data packet
BlackrockFile$get_epoch()
get_waveform()
get 'waveform' of the spike data
BlackrockFile$get_waveform()
get_electrode()
get electrode data
BlackrockFile$get_electrode(electrode, nstype = NULL)
electrodeinteger, must be a length of one
nstypewhich signal bank, for example, 'ns3', 'ns5'
clone()
The objects of this class are cloneable with this method.
BlackrockFile$clone(deep = FALSE)
deepWhether to make a deep clone.
Manipulate cached data on the file systems
cache_root(check = FALSE) clear_cached_files(subject_code, quiet = FALSE)cache_root(check = FALSE) clear_cached_files(subject_code, quiet = FALSE)
check |
whether to ensure the cache root path |
subject_code |
subject code to remove; default is missing. If
|
quiet |
whether to suppress the message |
'RAVE' intensively uses cache files. If running on personal
computers, the disk space might be filled up very quickly. These cache
files are safe to remove if there is no 'RAVE' instance running.
Function clear_cached_files is designed to remove these cache files.
To run this function, please make sure that all 'RAVE' instances
are shutdown.
cache_root returns the root path that stores the 'RAVE'
cache data; clear_cached_files returns nothing
cache_root()cache_root()
Avoid repeating yourself
cache_to_filearray( fun, filebase, globals, dimension, type = "auto", partition_size = 1L, verbose = FALSE, ... )cache_to_filearray( fun, filebase, globals, dimension, type = "auto", partition_size = 1L, verbose = FALSE, ... )
fun |
function that can be called with no mandatory arguments; the result should be in a matrix or an array |
filebase |
where to store the array |
globals |
names of variables such that any changes
should trigger a new evaluation of |
dimension |
what is the supposed dimension, default is automatically calculated from array. If specified explicitly and the file array dimension is inconsistent, a new calculation will be triggered. |
type |
file array type, default is |
partition_size |
file array partition size; default is |
verbose |
whether to verbose debug information |
... |
passed to |
c <- 2 b <- list(d = matrix(1:9,3)) filebase <- tempfile() f <- function() { message("New calculation") re <- c + b$d dimnames(re) <- list(A=1:3, B = 11:13) # `extra` attribute will be saved attr(re, "extra") <- "extra meta data" re } # first time running arr <- cache_to_filearray( f, filebase = filebase ) # cached, no re-run arr <- cache_to_filearray( f, filebase = filebase ) # file array object arr # read into memory arr[] # read extra data arr$get_header("extra") # get digest results arr$get_header("raveio::filearray_cache") ## Clean up this example unlink(filebase, recursive = TRUE)c <- 2 b <- list(d = matrix(1:9,3)) filebase <- tempfile() f <- function() { message("New calculation") re <- c + b$d dimnames(re) <- list(A=1:3, B = 11:13) # `extra` attribute will be saved attr(re, "extra") <- "extra meta data" re } # first time running arr <- cache_to_filearray( f, filebase = filebase ) # cached, no re-run arr <- cache_to_filearray( f, filebase = filebase ) # file array object arr # read into memory arr[] # read extra data arr$get_header("extra") # get digest results arr$get_header("raveio::filearray_cache") ## Clean up this example unlink(filebase, recursive = TRUE)
Print colored messages
catgl(..., .envir = parent.frame(), level = "DEBUG", .pal, .capture = FALSE)catgl(..., .envir = parent.frame(), level = "DEBUG", .pal, .capture = FALSE)
..., .envir
|
passed to |
level |
passed to |
.pal |
see |
.capture |
logical, whether to capture message and return it without printing |
The level has order that sorted from low to high: "DEBUG",
"DEFAULT", "INFO", "WARNING", "ERROR",
"FATAL". Each different level will display different colors and
icons before the message. You can suppress messages with certain levels
by setting 'raveio' options via
raveio_setopt('verbose_level', <level>). Messages with levels lower
than the threshold will be muffled. See examples.
The message as characters
# ------------------ Basic Styles --------------------- # Temporarily change verbose level for example raveio_setopt('verbose_level', 'DEBUG', FALSE) # debug catgl('Debug message', level = 'DEBUG') # default catgl('Default message', level = 'DEFAULT') # info catgl('Info message', level = 'INFO') # warning catgl('Warning message', level = 'WARNING') # error catgl('Error message', level = 'ERROR') try({ # fatal, will call stop and raise error catgl('Error message', level = 'FATAL') }, silent = TRUE) # ------------------ Muffle messages --------------------- # Temporarily change verbose level to 'WARNING' raveio_setopt('verbose_level', 'WARNING', FALSE) # default, muffled catgl('Default message') # message printed for level >= Warning catgl('Default message', level = 'WARNING') catgl('Default message', level = 'ERROR')# ------------------ Basic Styles --------------------- # Temporarily change verbose level for example raveio_setopt('verbose_level', 'DEBUG', FALSE) # debug catgl('Debug message', level = 'DEBUG') # default catgl('Default message', level = 'DEFAULT') # info catgl('Info message', level = 'INFO') # warning catgl('Warning message', level = 'WARNING') # error catgl('Error message', level = 'ERROR') try({ # fatal, will call stop and raise error catgl('Error message', level = 'FATAL') }, silent = TRUE) # ------------------ Muffle messages --------------------- # Temporarily change verbose level to 'WARNING' raveio_setopt('verbose_level', 'WARNING', FALSE) # default, muffled catgl('Default message') # message printed for level >= Warning catgl('Default message', level = 'WARNING') catgl('Default message', level = 'ERROR')
These shell commands are for importing 'DICOM' images to 'Nifti' format, reconstructing cortical surfaces, and align' the CT' to 'MRI'. The commands are only tested on 'MacOS' and 'Linux'. On 'Windows' machines, please use the 'WSL2' system.
cmd_run_3dAllineate( subject, mri_path, ct_path, overwrite = FALSE, command_path = NULL, dry_run = FALSE, verbose = dry_run ) cmd_execute( script, script_path, command = "bash", dry_run = FALSE, backup = TRUE, args = NULL, ... ) cmd_run_r( expr, quoted = FALSE, verbose = TRUE, dry_run = FALSE, log_file = tempfile(), script_path = tempfile(), ... ) cmd_run_dcm2niix( subject, src_path, type = c("MRI", "CT"), merge = c("Auto", "No", "Yes"), float = c("Yes", "No"), crop = c("No", "Yes", "Ignore"), overwrite = FALSE, command_path = NULL, dry_run = FALSE, verbose = dry_run ) cmd_run_flirt( subject, mri_path, ct_path, dof = 6, cost = c("mutualinfo", "leastsq", "normcorr", "corratio", "normmi", "labeldiff", "bbr"), search = 90, searchcost = c("mutualinfo", "leastsq", "normcorr", "corratio", "normmi", "labeldiff", "bbr"), overwrite = FALSE, command_path = NULL, dry_run = FALSE, verbose = dry_run ) cmd_run_recon_all( subject, mri_path, args = c("-all", "-autorecon1", "-autorecon2", "-autorecon3", "-autorecon2-cp", "-autorecon2-wm", "-autorecon2-pial"), work_path = NULL, overwrite = FALSE, command_path = NULL, dry_run = FALSE, verbose = dry_run ) cmd_run_recon_all_clinical( subject, mri_path, work_path = NULL, overwrite = FALSE, command_path = NULL, dry_run = FALSE, verbose = dry_run, ... )cmd_run_3dAllineate( subject, mri_path, ct_path, overwrite = FALSE, command_path = NULL, dry_run = FALSE, verbose = dry_run ) cmd_execute( script, script_path, command = "bash", dry_run = FALSE, backup = TRUE, args = NULL, ... ) cmd_run_r( expr, quoted = FALSE, verbose = TRUE, dry_run = FALSE, log_file = tempfile(), script_path = tempfile(), ... ) cmd_run_dcm2niix( subject, src_path, type = c("MRI", "CT"), merge = c("Auto", "No", "Yes"), float = c("Yes", "No"), crop = c("No", "Yes", "Ignore"), overwrite = FALSE, command_path = NULL, dry_run = FALSE, verbose = dry_run ) cmd_run_flirt( subject, mri_path, ct_path, dof = 6, cost = c("mutualinfo", "leastsq", "normcorr", "corratio", "normmi", "labeldiff", "bbr"), search = 90, searchcost = c("mutualinfo", "leastsq", "normcorr", "corratio", "normmi", "labeldiff", "bbr"), overwrite = FALSE, command_path = NULL, dry_run = FALSE, verbose = dry_run ) cmd_run_recon_all( subject, mri_path, args = c("-all", "-autorecon1", "-autorecon2", "-autorecon3", "-autorecon2-cp", "-autorecon2-wm", "-autorecon2-pial"), work_path = NULL, overwrite = FALSE, command_path = NULL, dry_run = FALSE, verbose = dry_run ) cmd_run_recon_all_clinical( subject, mri_path, work_path = NULL, overwrite = FALSE, command_path = NULL, dry_run = FALSE, verbose = dry_run, ... )
subject |
characters or a |
mri_path |
the absolute to 'MRI' volume; must in 'Nifti' format |
ct_path |
the absolute to 'CT' volume; must in 'Nifti' format |
overwrite |
whether to overwrite existing files; default is false |
command_path |
command line path if 'RAVE' cannot find the command binary files |
dry_run |
whether to run in dry-run mode; under such mode, the shell command will not execute. This is useful for debugging scripts; default is false |
verbose |
whether to print out the command script; default is true under dry-run mode, and false otherwise |
script |
the shell script |
script_path |
path to run the script |
command |
which command to invoke; default is |
backup |
whether to back up the script file immediately; default is true |
args |
further arguments in the shell command, especially the 'FreeSurfer' reconstruction command |
... |
passed to |
expr |
expression to run as command |
quoted |
whether |
log_file |
where should log file be stored |
src_path |
source of the 'DICOM' or 'Nifti' image (absolute path) |
type |
type of the 'DICOM' or 'Nifti' image; choices are |
merge, float, crop
|
|
dof, cost, search, searchcost
|
parameters used by 'FSL' |
work_path |
work path for 'FreeSurfer' command; |
A list of data containing the script details:
scriptscript details
script_pathwhere the script should/will be saved
dry_runwhether dry-run mode is turned on
log_filepath to the log file
executea function to execute the script
'YAEL'
Aligns 'T1w' with other image types; normalizes 'T1w'
'MRI' to 'MNI152' templates via symmetric non-linear morphs. Create brain
custom atlases from templates.
cmd_run_yael_preprocess( subject_code, t1w_path = NULL, ct_path = NULL, t2w_path = NULL, fgatir_path = NULL, preopct_path = NULL, flair_path = NULL, t1w_contrast_path = NULL, register_reversed = FALSE, normalize_template = "mni_icbm152_nlin_asym_09b", run_recon_all = TRUE, dry_run = FALSE, verbose = TRUE ) yael_preprocess( subject_code, t1w_path = NULL, ct_path = NULL, t2w_path = NULL, fgatir_path = NULL, preopct_path = NULL, flair_path = NULL, t1w_contrast_path = NULL, register_policy = c("auto", "all"), register_reversed = FALSE, normalize_template = "mni_icbm152_nlin_asym_09a", normalize_policy = c("auto", "all"), normalize_back = ifelse(length(normalize_template) >= 1, normalize_template[[1]], NA), atlases = list(), add_surfaces = FALSE, verbose = TRUE )cmd_run_yael_preprocess( subject_code, t1w_path = NULL, ct_path = NULL, t2w_path = NULL, fgatir_path = NULL, preopct_path = NULL, flair_path = NULL, t1w_contrast_path = NULL, register_reversed = FALSE, normalize_template = "mni_icbm152_nlin_asym_09b", run_recon_all = TRUE, dry_run = FALSE, verbose = TRUE ) yael_preprocess( subject_code, t1w_path = NULL, ct_path = NULL, t2w_path = NULL, fgatir_path = NULL, preopct_path = NULL, flair_path = NULL, t1w_contrast_path = NULL, register_policy = c("auto", "all"), register_reversed = FALSE, normalize_template = "mni_icbm152_nlin_asym_09a", normalize_policy = c("auto", "all"), normalize_back = ifelse(length(normalize_template) >= 1, normalize_template[[1]], NA), atlases = list(), add_surfaces = FALSE, verbose = TRUE )
subject_code |
'RAVE' subject code |
t1w_path |
(required) 'T1' weighted 'MRI' path |
ct_path |
(optional in general but mandatory for electrode localization) post-surgery 'CT' path |
t2w_path |
(optional) 'T2' weighted 'MRI' path |
fgatir_path |
(optional) 'fGATIR' (fast gray-matter acquisition 'T1' inversion recovery) image path |
preopct_path |
(optional) pre-surgery 'CT' path |
flair_path |
(optional) 'FLAIR' (fluid-attenuated inversion recovery) image path |
t1w_contrast_path |
(optional) 'T1' weighted 'MRI' with contrast (usually used to show the blood vessels) |
register_reversed |
direction of the registration; |
normalize_template |
names of the templates which the native 'T1' images will be normalized into |
run_recon_all |
whether to run |
dry_run |
whether to dry-run the script and check if error exists before actually execute the scripts. |
verbose |
whether to print out the progress; default is |
register_policy |
whether images should be registered with |
normalize_policy |
normalization policy; similar to
|
normalize_back |
length of one (select from |
atlases |
a named list: the names must be template names from
|
add_surfaces |
Whether to add surfaces for the subject; default is
|
Nothing, a subject imaging folder will be created under 'RAVE' raw folder
## Not run: # For T1 preprocessing only yael_preprocess( subject_code = "patient01", t1w_path = "/path/to/T1.nii or T1.nii.gz", # normalize T1 to all 2009 MNI152-Asym brains (a,b,c) normalize_template = c( "mni_icbm152_nlin_asym_09b" ), # only normalize if not exists normalize_policy = "auto", # use MNI152b to create native processing folder normalize_back = "mni_icbm152_nlin_asym_09b", # Atlases generated from different templates have different # coordinates, hence both folder path and template names must be # provided atlases = list( mni_icbm152_nlin_asym_09b = "/path/to/atlas/folder1", mni_icbm152_nlin_asym_09c = "/path/to/atlas/folder2" ) ) # For T1 and postop CT coregistration only yael_preprocess( subject_code = "patient01", t1w_path = "/path/to/T1.nii or T1.nii.gz", ct_path = "/path/to/CT.nii or CT.nii.gz", # No normalization normalize_template = NULL, normalize_back = NA ) # For both T1 and postop CT coregistration and T1 normalization yael_preprocess( subject_code = "patient01", t1w_path = "/path/to/T1.nii or T1.nii.gz", ct_path = "/path/to/CT.nii or CT.nii.gz", normalize_template = c( "mni_icbm152_nlin_asym_09a", "mni_icbm152_nlin_asym_09b", "mni_icbm152_nlin_asym_09c" ), normalize_policy = "auto", normalize_back = "mni_icbm152_nlin_asym_09b", atlases = list( mni_icbm152_nlin_asym_09b = "/path/to/atlas/folder1", mni_icbm152_nlin_asym_09c = "/path/to/atlas/folder2" ) ) ## End(Not run)## Not run: # For T1 preprocessing only yael_preprocess( subject_code = "patient01", t1w_path = "/path/to/T1.nii or T1.nii.gz", # normalize T1 to all 2009 MNI152-Asym brains (a,b,c) normalize_template = c( "mni_icbm152_nlin_asym_09b" ), # only normalize if not exists normalize_policy = "auto", # use MNI152b to create native processing folder normalize_back = "mni_icbm152_nlin_asym_09b", # Atlases generated from different templates have different # coordinates, hence both folder path and template names must be # provided atlases = list( mni_icbm152_nlin_asym_09b = "/path/to/atlas/folder1", mni_icbm152_nlin_asym_09c = "/path/to/atlas/folder2" ) ) # For T1 and postop CT coregistration only yael_preprocess( subject_code = "patient01", t1w_path = "/path/to/T1.nii or T1.nii.gz", ct_path = "/path/to/CT.nii or CT.nii.gz", # No normalization normalize_template = NULL, normalize_back = NA ) # For both T1 and postop CT coregistration and T1 normalization yael_preprocess( subject_code = "patient01", t1w_path = "/path/to/T1.nii or T1.nii.gz", ct_path = "/path/to/CT.nii or CT.nii.gz", normalize_template = c( "mni_icbm152_nlin_asym_09a", "mni_icbm152_nlin_asym_09b", "mni_icbm152_nlin_asym_09c" ), normalize_policy = "auto", normalize_back = "mni_icbm152_nlin_asym_09b", atlases = list( mni_icbm152_nlin_asym_09b = "/path/to/atlas/folder1", mni_icbm152_nlin_asym_09c = "/path/to/atlas/folder2" ) ) ## End(Not run)
Collapse power array with given analysis cubes
collapse_power(x, analysis_index_cubes) ## S3 method for class 'array' collapse_power(x, analysis_index_cubes) ## S3 method for class 'FileArray' collapse_power(x, analysis_index_cubes)collapse_power(x, analysis_index_cubes) ## S3 method for class 'array' collapse_power(x, analysis_index_cubes) ## S3 method for class 'FileArray' collapse_power(x, analysis_index_cubes)
x |
a |
analysis_index_cubes |
a list of analysis indices for each mode |
a list of collapsed (mean) results
freq_trial_eleccollapsed over time-points
freq_time_eleccollapsed over trials
time_trial_eleccollapsed over frequencies
freq_timecollapsed over trials and electrodes
freq_eleccollapsed over trials and time-points
freq_trialcollapsed over time-points and electrodes
time_trialcollapsed over frequencies and electrodes
time_eleccollapsed over frequencies and trials
trial_eleccollapsed over frequencies and time-points
freqpower per frequency, averaged over other modes
timepower per time-point, averaged over other modes
trialpower per trial, averaged over other modes
if(!is_on_cran()) { # Generate a 4-mode tensor array x <- filearray::filearray_create( tempfile(), dimension = c(16, 100, 20, 5), partition_size = 1 ) x[] <- rnorm(160000) dnames <- list( Frequency = 1:16, Time = seq(0, 1, length.out = 100), Trial = 1:20, Electrode = 1:5 ) dimnames(x) <- dnames # Collapse array results <- collapse_power(x, list( overall = list(), A = list(Trial = 1:5, Frequency = 1:6), B = list(Trial = 6:10, Time = 1:50) )) # Plot power over frequency and time groupB_result <- results$B image(t(groupB_result$freq_time), x = dnames$Time[groupB_result$cube_index$Time], y = dnames$Frequency[groupB_result$cube_index$Frequency], xlab = "Time (s)", ylab = "Frequency (Hz)", xlim = range(dnames$Time)) x$delete(force = TRUE) }if(!is_on_cran()) { # Generate a 4-mode tensor array x <- filearray::filearray_create( tempfile(), dimension = c(16, 100, 20, 5), partition_size = 1 ) x[] <- rnorm(160000) dnames <- list( Frequency = 1:16, Time = seq(0, 1, length.out = 100), Trial = 1:20, Electrode = 1:5 ) dimnames(x) <- dnames # Collapse array results <- collapse_power(x, list( overall = list(), A = list(Trial = 1:5, Frequency = 1:6), B = list(Trial = 6:10, Time = 1:50) )) # Plot power over frequency and time groupB_result <- results$B image(t(groupB_result$freq_time), x = dnames$Time[groupB_result$cube_index$Time], y = dnames$Frequency[groupB_result$cube_index$Frequency], xlab = "Time (s)", ylab = "Frequency (Hz)", xlim = range(dnames$Time)) x$delete(force = TRUE) }
Collapse high-dimensional tensor array
collapse2(x, keep, method = c("mean", "sum"), ...) ## S3 method for class 'FileArray' collapse2(x, keep, method = c("mean", "sum"), ...) ## S3 method for class 'Tensor' collapse2(x, keep, method = c("mean", "sum"), ...) ## S3 method for class 'array' collapse2(x, keep, method = c("mean", "sum"), ...)collapse2(x, keep, method = c("mean", "sum"), ...) ## S3 method for class 'FileArray' collapse2(x, keep, method = c("mean", "sum"), ...) ## S3 method for class 'Tensor' collapse2(x, keep, method = c("mean", "sum"), ...) ## S3 method for class 'array' collapse2(x, keep, method = c("mean", "sum"), ...)
x |
R array, |
keep |
integer vector, the margins to keep |
method |
character, calculates mean or sum of the array when collapsing |
... |
passed to other methods |
A collapsed array (or a vector or matrix), depending on keep
x <- array(1:16, rep(2, 4)) collapse2(x, c(3, 2)) # Alternative method, but slower when `x` is a large array apply(x, c(3, 2), mean) # filearray y <- filearray::as_filearray(x) collapse2(y, c(3, 2)) collapse2(y, c(3, 2), "sum") # clean up y$delete(force = TRUE)x <- array(1:16, rep(2, 4)) collapse2(x, c(3, 2)) # Alternative method, but slower when `x` is a large array apply(x, c(3, 2), mean) # filearray y <- filearray::as_filearray(x) collapse2(y, c(3, 2)) collapse2(y, c(3, 2), "sum") # clean up y$delete(force = TRUE)
In some cases, for example, deep-brain stimulation ('DBS'),
it is often needed to analyze averaged electrode channels from segmented
'DBS' leads, or create bipolar contrast between electrode channels, or
to generate non-equally weighted channel averages for 'Laplacian' reference.
compose_channel allows users to generate a phantom channel that does
not physically exist, but is treated as a normal electrode channel in 'RAVE'.
compose_channel( subject, number, from, weights = rep(1/length(from), length(from)), normalize = FALSE, force = FALSE, label = sprintf("Composed-%s", number), signal_type = c("auto", "LFP", "Spike", "EKG", "Auxiliary", "Unknown") )compose_channel( subject, number, from, weights = rep(1/length(from), length(from)), normalize = FALSE, force = FALSE, label = sprintf("Composed-%s", number), signal_type = c("auto", "LFP", "Spike", "EKG", "Auxiliary", "Unknown") )
subject |
'RAVE' subject |
number |
new channel number, must be positive integer, cannot be existing electrode channel numbers |
from |
a vector of electrode channels that is used to compose this
new channel, must be non-empty; see |
weights |
numerical weights used on each |
normalize |
whether to normalize the weights such that the composed
channel has the same variance as |
force |
whether to overwrite existing composed channel if it exists;
default is false. By specifying |
label |
the label for the composed channel; will be stored at
|
signal_type |
signal type of the composed channel; default is
|
Nothing
library(raveio) # Make sure demo subject exists in this example, just want to make # sure the example does not error out if( interactive() && "demo" %in% get_projects() && "DemoSubject" %in% as_rave_project('demo')$subjects() && local({ subject <- as_rave_subject("demo/DemoSubject") !100 %in% subject$electrodes }) ) { # the actual example code: # new channel 100 = 2 x channel 14 - (channe 15 + 16) compose_channel( subject = "demo/DemoSubject", number = 100, from = c(14, 15, 16), weights = c(2, -1, -1), normalize = FALSE ) }library(raveio) # Make sure demo subject exists in this example, just want to make # sure the example does not error out if( interactive() && "demo" %in% get_projects() && "DemoSubject" %in% as_rave_project('demo')$subjects() && local({ subject <- as_rave_subject("demo/DemoSubject") !100 %in% subject$electrodes }) ) { # the actual example code: # new channel 100 = 2 x channel 14 - (channe 15 + 16) compose_channel( subject = "demo/DemoSubject", number = 100, from = c(14, 15, 16), weights = c(2, -1, -1), normalize = FALSE ) }
Convert 'BlackRock' 'NEV/NSx' files
convert_blackrock( file, block = NULL, subject = NULL, to = NULL, epoch = c("comment", "digital_inputs", "recording", "configuration", "log", "button_trigger", "tracking", "video_sync"), format = c("mat", "hdf5"), header_only = FALSE, ... )convert_blackrock( file, block = NULL, subject = NULL, to = NULL, epoch = c("comment", "digital_inputs", "recording", "configuration", "log", "button_trigger", "tracking", "video_sync"), format = c("mat", "hdf5"), header_only = FALSE, ... )
file |
path to any 'NEV/NSx' file |
block |
the block name, default is file name |
subject |
subject code to save the files; default is |
to |
save to path, must be a directory; default is under the file path.
If |
epoch |
what type of events should be included in epoch file; default include comment, digital inputs, recording trigger, configuration change, log comment, button trigger, tracking, and video trigger. |
format |
output format, choices are |
header_only |
whether just to generate channel and epoch table; default is false |
... |
ignored for enhanced backward compatibility |
The results will be stored in directory specified by to.
Please read the output message carefully.
Convert electrode table
convert_electrode_table_to_bids( subject, space = c("ScanRAS", "MNI305", "fsnative") )convert_electrode_table_to_bids( subject, space = c("ScanRAS", "MNI305", "fsnative") )
subject |
'RAVE' subject |
space |
suggested coordinate space, notice this argument might not be
supported when |
A list of table in data frame and a list of meta information
Force creating directory with checks
dir_create2(x, showWarnings = FALSE, recursive = TRUE, check = TRUE, ...)dir_create2(x, showWarnings = FALSE, recursive = TRUE, check = TRUE, ...)
x |
path to create |
showWarnings, recursive, ...
|
passed to |
check |
whether to check the directory after creation |
Normalized path
path <- file.path(tempfile(), 'a', 'b', 'c') # The following are equivalent dir.create(path, showWarnings = FALSE, recursive = TRUE) dir_create2(path)path <- file.path(tempfile(), 'a', 'b', 'c') # The following are equivalent dir.create(path, showWarnings = FALSE, recursive = TRUE) dir_create2(path)
Tensor
Four-mode tensor (array) especially designed for
'iEEG/ECoG' data. The Dimension names are: Trial,
Frequency, Time, and Electrode.
a data frame with the dimension names as index columns and
value_name as value column
an ECoGTensor instance
raveio::Tensor -> ECoGTensor
flatten()
converts tensor (array) to a table (data frame)
ECoGTensor$flatten(include_index = TRUE, value_name = "value")
include_indexlogical, whether to include dimension names
value_namecharacter, column name of the value
new()
constructor
ECoGTensor$new( data, dim, dimnames, varnames, hybrid = FALSE, swap_file = temp_tensor_file(), temporary = TRUE, multi_files = FALSE, use_index = TRUE, ... )
dataarray or vector
dimdimension of data, mush match with data
dimnameslist of dimension names, equal length as dim
varnamesnames of dimnames, recommended names are:
Trial, Frequency, Time, and Electrode
hybridwhether to enable hybrid mode to reduce RAM usage
swap_fileif hybrid mode, where to store the data; default
stores in raveio_getopt('tensor_temp_path')
temporarywhether to clean up the space when exiting R session
multi_fileslogical, whether to use multiple files instead of one giant file to store data
use_indexlogical, when multi_files is true, whether use
index dimension as partition number
...further passed to Tensor constructor
Zhengjia Wang
Stores and load data in various of data format. See 'Details' for limitations.
export_table( x, file, format = c("auto", "csv", "csv.zip", "h5", "fst", "json", "rds", "yaml"), ... ) import_table( file, format = c("auto", "csv", "csv.zip", "h5", "fst", "json", "rds", "yaml"), ... )export_table( x, file, format = c("auto", "csv", "csv.zip", "h5", "fst", "json", "rds", "yaml"), ... ) import_table( file, format = c("auto", "csv", "csv.zip", "h5", "fst", "json", "rds", "yaml"), ... )
x |
data table to be saved to |
file |
file to store the data |
format |
data storage format, default is |
... |
parameters passed to other functions |
The format 'rds', 'h5', 'fst', 'json', and
'yaml' try to preserve the first-level column attributes. Factors
will be preserved in these formats. Such property does not exist in
'csv', 'csv.zip' formats.
Open-data formats are 'h5', 'csv', 'csv.zip',
'json', 'yaml'. These formats require the table elements to
be native types (numeric, character, factor, etc.).
'rds', 'h5', and 'fst' can store large data sets.
'fst' is the best choice is performance and file size are the major
concerns. 'rds' preserves all the properties of the table.
The normalized path for export_table, and a
data.table for import_table
x <- data.table::data.table( a = rnorm(10), b = letters[1:10], c = 1:10, d = factor(LETTERS[1:10]) ) f <- tempfile(fileext = ".csv.zip") export_table(x = x, file = f) y <- import_table(file = f) str(x) str(y) # clean up unlink(f)x <- data.table::data.table( a = rnorm(10), b = letters[1:10], c = 1:10, d = factor(LETTERS[1:10]) ) f <- tempfile(fileext = ".csv.zip") export_table(x = x, file = f) y <- import_table(file = f) str(x) str(y) # clean up unlink(f)
Try to find path under root directory even
if the original path is missing; see examples.
find_path(path, root_dir, all = FALSE)find_path(path, root_dir, all = FALSE)
path |
file path |
root_dir |
top directory of the search path |
all |
return all possible paths, default is false |
When file is missing, find_path concatenates the
root directory and path combined to find the file. For example,
if path is "a/b/c/d",
the function first seek for existence of "a/b/c/d". If failed,
then "b/c/d", and then "~/c/d" until reaching
root directory. If all=TRUE, then all files/directories found
along the search path will be returned
The absolute path of file if exists, or NULL if
missing/failed.
root <- tempdir() # ------ Case 1: basic use case ------- # Create a path in root dir_create2(file.path(root, 'a')) # find path even it's missing. The search path will be # root/ins/cd/a - missing # root/cd/a - missing # root/a - exists! find_path('ins/cd/a', root) # ------ Case 2: priority ------- # Create two paths in root dir_create2(file.path(root, 'cc/a')) dir_create2(file.path(root, 'a')) # If two paths exist, return the first path found # root/ins/cd/a - missing # root/cd/a - exists - returned # root/a - exists, but ignored find_path('ins/cc/a', root) # ------ Case 3: find all ------- # Create two paths in root dir_create2(file.path(root, 'cc/a')) dir_create2(file.path(root, 'a')) # If two paths exist, return the first path found # root/ins/cd/a - missing # root/cd/a - exists - returned # root/a - exists - returned find_path('ins/cc/a', root, all = TRUE)root <- tempdir() # ------ Case 1: basic use case ------- # Create a path in root dir_create2(file.path(root, 'a')) # find path even it's missing. The search path will be # root/ins/cd/a - missing # root/cd/a - missing # root/a - exists! find_path('ins/cd/a', root) # ------ Case 2: priority ------- # Create two paths in root dir_create2(file.path(root, 'cc/a')) dir_create2(file.path(root, 'a')) # If two paths exist, return the first path found # root/ins/cd/a - missing # root/cd/a - exists - returned # root/a - exists, but ignored find_path('ins/cc/a', root) # ------ Case 3: find all ------- # Create two paths in root dir_create2(file.path(root, 'cc/a')) dir_create2(file.path(root, 'a')) # If two paths exist, return the first path found # root/ins/cd/a - missing # root/cd/a - exists - returned # root/a - exists - returned find_path('ins/cc/a', root, all = TRUE)
To properly run this function, please install ravetools
package.
generate_reference(subject, electrodes)generate_reference(subject, electrodes)
subject |
subject ID or |
electrodes |
electrodes to calculate the common average; these electrodes must run through 'Wavelet' first |
The goal of generating common average signals is to capture the common movement from all the channels and remove them out from electrode signals.
The common average signals will be stored at subject reference
directories. Two exact same copies will be stored: one in 'HDF5'
format such that the data can be read universally by other programming
languages; one in filearray format that can be
read in R with super fast speed.
A reference instance returned by new_reference with
signal type determined automatically.
Get all possible projects in 'RAVE' directory
get_projects(refresh = TRUE)get_projects(refresh = TRUE)
refresh |
whether to refresh the cache; default is true |
characters of project names
Get value or return default if invalid
get_val2(x, key = NA, default = NULL, na = FALSE, min_len = 1L, ...)get_val2(x, key = NA, default = NULL, na = FALSE, min_len = 1L, ...)
x |
a list, or environment, or just any R object |
key |
the name to obtain from |
default |
default value if |
na, min_len, ...
|
passed to |
values of the keys or default is invalid
x <- list(a=1, b = NA, c = character(0)) # ------------------------ Basic usage ------------------------ # no key, returns x if x is valid get_val2(x) get_val2(x, 'a', default = 'invalid') # get 'b', NA is not filtered out get_val2(x, 'b', default = 'invalid') # get 'b', NA is considered invalid get_val2(x, 'b', default = 'invalid', na = TRUE) # get 'c', length 0 is allowed get_val2(x, 'c', default = 'invalid', min_len = 0) # length 0 is forbidden get_val2(x, 'c', default = 'invalid', min_len = 1)x <- list(a=1, b = NA, c = character(0)) # ------------------------ Basic usage ------------------------ # no key, returns x if x is valid get_val2(x) get_val2(x, 'a', default = 'invalid') # get 'b', NA is not filtered out get_val2(x, 'b', default = 'invalid') # get 'b', NA is considered invalid get_val2(x, 'b', default = 'invalid', na = TRUE) # get 'c', length 0 is allowed get_val2(x, 'c', default = 'invalid', min_len = 0) # length 0 is forbidden get_val2(x, 'c', default = 'invalid', min_len = 1)
Returns all names contained in 'HDF5' file
h5_names(file)h5_names(file)
file |
'HDF5' file path |
characters, data set names
Check whether a 'HDF5' file can be opened for read/write
h5_valid(file, mode = c("r", "w"), close_all = FALSE)h5_valid(file, mode = c("r", "w"), close_all = FALSE)
file |
path to file |
mode |
|
close_all |
whether to close all connections or just close current
connection; default is false. Set this to |
logical whether the file can be opened.
x <- array(1:27, c(3,3,3)) f <- tempfile() # No data written to the file, hence invalid h5_valid(f, 'r') save_h5(x, f, 'dset') h5_valid(f, 'w') # TRUE h5_valid(f, 'r') # TRUEx <- array(1:27, c(3,3,3)) f <- tempfile() # No data written to the file, hence invalid h5_valid(f, 'r') save_h5(x, f, 'dset') h5_valid(f, 'w') # TRUE h5_valid(f, 'r') # TRUE
Import electrode table into subject meta folder
import_electrode_table(path, subject, use_fs = NA, dry_run = FALSE, ...)import_electrode_table(path, subject, use_fs = NA, dry_run = FALSE, ...)
path |
path of table file, must be a |
subject |
'RAVE' subject ID or instance |
use_fs |
whether to use 'FreeSurfer' files to calculate other coordinates |
dry_run |
whether to dry-run the process; if true, then the table will be generated but not saved to subject's meta folder |
... |
passed to |
Nothing, the electrode information will be written directly to the subject's meta directory
Ingest signals according to 'RAVE' repository epoch
ingest_regressor( repository, source, source_type = c("channel", "file", "r_object"), filter = NULL, ... )ingest_regressor( repository, source, source_type = c("channel", "file", "r_object"), filter = NULL, ... )
repository |
'RAVE' repository, for example, generated from
|
source |
data source, see |
source_type |
type of the data source, choices are
|
filter |
|
... |
passed to internal functions. |
A matrix of time by trial
Install a subject from the internet, a zip file or a directory
install_subject( path = ".", ask = interactive(), overwrite = FALSE, backup = TRUE, use_cache = TRUE, dry_run = FALSE, force_project = NA, force_subject = NA, ... )install_subject( path = ".", ask = interactive(), overwrite = FALSE, backup = TRUE, use_cache = TRUE, dry_run = FALSE, force_project = NA, force_subject = NA, ... )
path |
path to subject archive, can be a path to directory, a zip file,
or an internet address (must starts with |
ask |
when |
overwrite |
whether to overwrite existing subject, see argument
|
backup |
whether to back-up the subject when overwriting the data; default is true, which will rename the old subject folders instead of removing; set to true to remove existing subject. |
use_cache |
whether to use cached extraction directory; default is
true. Set it to |
dry_run |
whether to dry-run the process instead of actually installing; this rehearsal can help you see the progress and prevent you from losing data |
force_project, force_subject
|
force set the project or subject; will raise a warning as this might mess up some pipelines |
... |
passed to |
# Please run 2nd example of function archive_subject ## Not run: install_subject(path) ## End(Not run)# Please run 2nd example of function archive_subject ## Not run: install_subject(path) ## End(Not run)
Use this function only for examples and test. The goal is to comply with the 'CRAN' policy. Do not use it in normal functions to cheat. Violating 'CRAN' policy will introduce instability to your code. Make sure reading Section 'Details' before using this function.
is_on_cran(if_interactive = FALSE, verbose = FALSE)is_on_cran(if_interactive = FALSE, verbose = FALSE)
if_interactive |
whether interactive session will be considered as
on 'CRAN'; default is |
verbose |
whether to print out reason of return; default is no |
According to 'CRAN' policy, package examples and test functions may only
use maximum 2 'CPU' cores. Examples running too long should be suppressed.
Normally package developers will use interactive() to avoid running
examples or parallel code on 'CRAN'. However, when checked locally, these
examples will be skipped too. Coding bug in those examples will not be
reported.
The objective is to allow 'RAVE' package developers to write and test examples locally or on integrated development environment (such as 'Github'), while suppressing them on 'CRAN'. In such way, bugs in the examples will be revealed and fixed promptly.
Do not use this function inside of the package functions to cheat or slip illegal code under the eyes of 'CRAN' folks. This will increase their work load and introduce instability to your code. Also this function is subject to deletion in the future.
A logical whether current environment should be considered as on 'CRAN'.
Check if data is close to “valid"
is_valid_ish( x, min_len = 1, max_len = Inf, mode = NA, na = TRUE, blank = FALSE, all = FALSE )is_valid_ish( x, min_len = 1, max_len = Inf, mode = NA, na = TRUE, blank = FALSE, all = FALSE )
x |
data to check |
min_len, max_len
|
minimal and maximum length |
mode |
which storage mode (see |
na |
whether |
blank |
whether blank string considered invalid? |
all |
if |
logicals whether input x is valid
# length checks is_valid_ish(NULL) # FALSE is_valid_ish(integer(0)) # FALSE is_valid_ish(integer(0), min_len = 0) # TRUE is_valid_ish(1:10, max_len = 9) # FALSE # mode check is_valid_ish(1:10) # TRUE is_valid_ish(1:10, mode = 'numeric') # TRUE is_valid_ish(1:10, mode = 'character') # FALSE # NA or blank checks is_valid_ish(NA) # FALSE is_valid_ish(c(1,2,NA), all = FALSE) # FALSE is_valid_ish(c(1,2,NA), all = TRUE) # TRUE as not all elements are NA is_valid_ish(c('1',''), all = FALSE) # TRUE is_valid_ish(1:3, all = FALSE) # TRUE as 1:3 are not characters# length checks is_valid_ish(NULL) # FALSE is_valid_ish(integer(0)) # FALSE is_valid_ish(integer(0), min_len = 0) # TRUE is_valid_ish(1:10, max_len = 9) # FALSE # mode check is_valid_ish(1:10) # TRUE is_valid_ish(1:10, mode = 'numeric') # TRUE is_valid_ish(1:10, mode = 'character') # FALSE # NA or blank checks is_valid_ish(NA) # FALSE is_valid_ish(c(1,2,NA), all = FALSE) # FALSE is_valid_ish(c(1,2,NA), all = TRUE) # TRUE as not all elements are NA is_valid_ish(c('1',''), all = FALSE) # TRUE is_valid_ish(1:3, all = FALSE) # TRUE as 1:3 are not characters
Check If Input Has Blank String
is.blank(x)is.blank(x)
x |
input data: a vector or an array |
x == ""
Check If Input Has Zero Length
is.zerolenth(x)is.zerolenth(x)
x |
input data: a vector, list, or array |
whether x has zero length
Join Multiple Tensors into One Tensor
join_tensors(tensors, temporary = TRUE)join_tensors(tensors, temporary = TRUE)
tensors |
list of |
temporary |
whether to garbage collect space when exiting R session |
Merges multiple tensors. Each tensor must share the same dimension
with the last one dimension as 1, for example, 100x100x1. Join 3
tensors like this will result in a 100x100x3 tensor. This function
is handy when each sub-tensors are generated separately. However, it does no
validation test. Use with cautions.
A new Tensor instance with the last dimension
Zhengjia Wang
tensor1 <- Tensor$new(data = 1:9, c(3,3,1), dimnames = list( A = 1:3, B = 1:3, C = 1 ), varnames = c('A', 'B', 'C')) tensor2 <- Tensor$new(data = 10:18, c(3,3,1), dimnames = list( A = 1:3, B = 1:3, C = 2 ), varnames = c('A', 'B', 'C')) merged <- join_tensors(list(tensor1, tensor2)) merged$get_data()tensor1 <- Tensor$new(data = 1:9, c(3,3,1), dimnames = list( A = 1:3, B = 1:3, C = 1 ), varnames = c('A', 'B', 'C')) tensor2 <- Tensor$new(data = 10:18, c(3,3,1), dimnames = list( A = 1:3, B = 1:3, C = 2 ), varnames = c('A', 'B', 'C')) merged <- join_tensors(list(tensor1, tensor2)) merged$get_data()
lapply in parallelUses lapply_async2, but allows better parallel
scheduling via with_future_parallel. On 'Unix', the function
will fork processes. On 'Windows', the function uses strategies specified
by on_failure
lapply_async( x, FUN, FUN.args = list(), callback = NULL, ncores = NULL, on_failure = "multisession", ... )lapply_async( x, FUN, FUN.args = list(), callback = NULL, ncores = NULL, on_failure = "multisession", ... )
x |
iterative elements |
FUN |
function to apply to each element of |
FUN.args |
named list that will be passed to |
callback |
callback function or |
ncores |
number of cores to use, constraint by the |
on_failure |
alternative strategy if fork process is disallowed (set by users or on 'Windows') |
... |
passed to |
if(!is_on_cran()) { library(raveio) # ---- Basic example ---------------------------- lapply_async(1:16, function(x) { # function that takes long to fun Sys.sleep(1) x }) # With callback lapply_async(1:16, function(x){ Sys.sleep(1) x + 1 }, callback = function(x) { sprintf("Calculating|%s", x) }) # With ncores pids <- lapply_async(1:16, function(x){ Sys.sleep(0.5) Sys.getpid() }, ncores = 2) # Unique number of PIDs (cores) unique(unlist(pids)) # ---- With scheduler ---------------------------- # Scheduler pre-initialize parallel workers and temporary # switches parallel context. The workers ramp-up # time can be saved by reusing the workers. # with_future_parallel({ # lapply_async block 1 pids <- lapply_async(1:16, function(x){ Sys.sleep(1) Sys.getpid() }, callback = function(x) { sprintf("lapply_async without ncores|%s", x) }) print(unique(unlist(pids))) # lapply_async block 2 pids <- lapply_async(1:16, function(x){ Sys.sleep(1) Sys.getpid() }, callback = function(x) { sprintf("lapply_async with ncores|%s", x) }, ncores = 4) print(unique(unlist(pids))) }) }if(!is_on_cran()) { library(raveio) # ---- Basic example ---------------------------- lapply_async(1:16, function(x) { # function that takes long to fun Sys.sleep(1) x }) # With callback lapply_async(1:16, function(x){ Sys.sleep(1) x + 1 }, callback = function(x) { sprintf("Calculating|%s", x) }) # With ncores pids <- lapply_async(1:16, function(x){ Sys.sleep(0.5) Sys.getpid() }, ncores = 2) # Unique number of PIDs (cores) unique(unlist(pids)) # ---- With scheduler ---------------------------- # Scheduler pre-initialize parallel workers and temporary # switches parallel context. The workers ramp-up # time can be saved by reusing the workers. # with_future_parallel({ # lapply_async block 1 pids <- lapply_async(1:16, function(x){ Sys.sleep(1) Sys.getpid() }, callback = function(x) { sprintf("lapply_async without ncores|%s", x) }) print(unique(unlist(pids))) # lapply_async block 2 pids <- lapply_async(1:16, function(x){ Sys.sleep(1) Sys.getpid() }, callback = function(x) { sprintf("lapply_async with ncores|%s", x) }, ncores = 4) print(unique(unlist(pids))) }) }
Please use a safer new_electrode function to
create instances. This documentation is to describe the member methods
of the electrode class LFP_electrode
if the reference number if NULL or 'noref', then
returns 0, otherwise returns a FileArray-class
If simplify is enabled, and only one block is loaded,
then the result will be a vector (type="voltage") or a matrix
(others), otherwise the result will be a named list where the names
are the blocks.
raveio::RAVEAbstarctElectrode -> LFP_electrode
h5_fname'HDF5' file name
validwhether current electrode is valid: subject exists and contains current electrode or reference; subject electrode type matches with current electrode type
raw_sample_ratevoltage sample rate
power_sample_ratepower/phase sample rate
preprocess_infopreprocess information
power_filepath to power 'HDF5' file
phase_filepath to phase 'HDF5' file
voltage_filepath to voltage 'HDF5' file
print()
print electrode summary
LFP_electrode$print()
set_reference()
set reference for current electrode
LFP_electrode$set_reference(reference)
referenceeither NULL or LFP_electrode instance
new()
constructor
LFP_electrode$new(subject, number, quiet = FALSE)
subject, number, quietsee constructor in
RAVEAbstarctElectrode
.load_noref_wavelet()
load non-referenced wavelet coefficients (internally used)
LFP_electrode$.load_noref_wavelet(reload = FALSE)
reloadwhether to reload cache
.load_noref_voltage()
load non-referenced voltage (internally used)
LFP_electrode$.load_noref_voltage(reload = FALSE)
reloadwhether to reload cache
sratevoltage signal sample rate
.load_wavelet()
load referenced wavelet coefficients (internally used)
LFP_electrode$.load_wavelet(
type = c("power", "phase", "wavelet-coefficient"),
reload = FALSE
)typetype of data to load
reloadwhether to reload cache
.load_voltage()
load referenced voltage (internally used)
LFP_electrode$.load_voltage(reload = FALSE)
reloadwhether to reload cache
.load_raw_voltage()
load raw voltage (no process)
LFP_electrode$.load_raw_voltage(reload = FALSE)
reloadwhether to reload cache
load_data()
method to load electrode data
LFP_electrode$load_data(
type = c("power", "phase", "voltage", "wavelet-coefficient", "raw-voltage")
)typedata type such as "power", "phase",
"voltage", "wavelet-coefficient", and
"raw-voltage". For "power", "phase",
and "wavelet-coefficient", 'Wavelet' transforms are required.
For "voltage", 'Notch' filters must be applied. All these
types except for "raw-voltage" will be referenced.
For "raw-voltage", no reference will be performed since the data
will be the "raw" signal (no processing).
load_blocks()
load electrode block-wise data (with no reference), useful when epoch is absent
LFP_electrode$load_blocks(
blocks,
type = c("power", "phase", "voltage", "wavelet-coefficient", "raw-voltage"),
simplify = TRUE
)blockssession blocks
typedata type such as "power", "phase",
"voltage", "raw-voltage" (with no filters applied, as-is
from imported), "wavelet-coefficient". Note that if type
is "raw-voltage", then the data only needs to be imported;
for "voltage" data, 'Notch' filters must be applied; for
all other types, 'Wavelet' transforms are required.
simplifywhether to simplify the result
clear_cache()
method to clear cache on hard drive
LFP_electrode$clear_cache(...)
...ignored
clear_memory()
method to clear memory
LFP_electrode$clear_memory(...)
...ignored
clone()
The objects of this class are cloneable with this method.
LFP_electrode$clone(deep = FALSE)
deepWhether to make a deep clone.
# Download subject demo/DemoSubject subject <- as_rave_subject("demo/DemoSubject", strict = FALSE) if(dir.exists(subject$path)) { # Electrode 14 in demo/DemoSubject e <- new_electrode(subject = subject, number = 14, signal_type = "LFP") # Load CAR reference "ref_13-16,24" ref <- new_reference(subject = subject, number = "ref_13-16,24", signal_type = "LFP") e$set_reference(ref) # Set epoch e$set_epoch(epoch = 'auditory_onset') # Set loading window e$trial_intervals <- list(c(-1, 2)) # Preview print(e) # Now epoch power power <- e$load_data("power") names(dimnames(power)) # Subset power subset(power, Time ~ Time < 0, Electrode ~ Electrode == 14) # Draw baseline tempfile <- tempfile() bl <- power_baseline(power, baseline_windows = c(-1, 0), method = "decibel", filebase = tempfile) collapsed_power <- collapse2(bl, keep = c(2,1)) # Visualize dname <- dimnames(bl) image(collapsed_power, x = dname$Time, y = dname$Frequency, xlab = "Time (s)", ylab = "Frequency (Hz)", main = "Mean power over trial (Baseline: -1~0 seconds)", sub = glue('Electrode {e$number} (Reference: {ref$number})')) abline(v = 0, lty = 2, col = 'blue') text(x = 0, y = 20, "Audio onset", col = "blue", cex = 0.6) # clear cache on hard disk e$clear_cache() ref$clear_cache() }# Download subject demo/DemoSubject subject <- as_rave_subject("demo/DemoSubject", strict = FALSE) if(dir.exists(subject$path)) { # Electrode 14 in demo/DemoSubject e <- new_electrode(subject = subject, number = 14, signal_type = "LFP") # Load CAR reference "ref_13-16,24" ref <- new_reference(subject = subject, number = "ref_13-16,24", signal_type = "LFP") e$set_reference(ref) # Set epoch e$set_epoch(epoch = 'auditory_onset') # Set loading window e$trial_intervals <- list(c(-1, 2)) # Preview print(e) # Now epoch power power <- e$load_data("power") names(dimnames(power)) # Subset power subset(power, Time ~ Time < 0, Electrode ~ Electrode == 14) # Draw baseline tempfile <- tempfile() bl <- power_baseline(power, baseline_windows = c(-1, 0), method = "decibel", filebase = tempfile) collapsed_power <- collapse2(bl, keep = c(2,1)) # Visualize dname <- dimnames(bl) image(collapsed_power, x = dname$Time, y = dname$Frequency, xlab = "Time (s)", ylab = "Frequency (Hz)", main = "Mean power over trial (Baseline: -1~0 seconds)", sub = glue('Electrode {e$number} (Reference: {ref$number})')) abline(v = 0, lty = 2, col = 'blue') text(x = 0, y = 20, "Audio onset", col = "blue", cex = 0.6) # clear cache on hard disk e$clear_cache() ref$clear_cache() }
Please use a safer new_reference function to
create instances. This documentation is to describe the member methods
of the electrode class LFP_reference
if the reference number if NULL or 'noref', then
returns 0, otherwise returns a FileArray-class
If simplify is enabled, and only one block is loaded,
then the result will be a vector (type="voltage") or a matrix
(others), otherwise the result will be a named list where the names
are the blocks.
raveio::RAVEAbstarctElectrode -> LFP_reference
existswhether electrode exists in subject
h5_fname'HDF5' file name
validwhether current electrode is valid: subject exists and contains current electrode or reference; subject electrode type matches with current electrode type
raw_sample_ratevoltage sample rate
power_sample_ratepower/phase sample rate
preprocess_infopreprocess information
power_filepath to power 'HDF5' file
phase_filepath to phase 'HDF5' file
voltage_filepath to voltage 'HDF5' file
print()
print reference summary
LFP_reference$print()
set_reference()
set reference for current electrode
LFP_reference$set_reference(reference)
referenceeither NULL or LFP_electrode instance
new()
constructor
LFP_reference$new(subject, number, quiet = FALSE)
subject, number, quietsee constructor in
RAVEAbstarctElectrode
.load_noref_wavelet()
load non-referenced wavelet coefficients (internally used)
LFP_reference$.load_noref_wavelet(reload = FALSE)
reloadwhether to reload cache
.load_noref_voltage()
load non-referenced voltage (internally used)
LFP_reference$.load_noref_voltage(reload = FALSE)
reloadwhether to reload cache
sratevoltage signal sample rate
.load_wavelet()
load referenced wavelet coefficients (internally used)
LFP_reference$.load_wavelet(
type = c("power", "phase", "wavelet-coefficient"),
reload = FALSE
)typetype of data to load
reloadwhether to reload cache
.load_voltage()
load referenced voltage (internally used)
LFP_reference$.load_voltage(reload = FALSE)
reloadwhether to reload cache
load_data()
method to load electrode data
LFP_reference$load_data(
type = c("power", "phase", "voltage", "wavelet-coefficient")
)typedata type such as "power", "phase",
"voltage", "wavelet-coefficient".
load_blocks()
load electrode block-wise data (with reference), useful when epoch is absent
LFP_reference$load_blocks(
blocks,
type = c("power", "phase", "voltage", "wavelet-coefficient"),
simplify = TRUE
)blockssession blocks
typedata type such as "power", "phase",
"voltage", "wavelet-coefficient". Note that if type
is voltage, then 'Notch' filters must be applied; otherwise 'Wavelet'
transforms are required.
simplifywhether to simplify the result
clear_cache()
method to clear cache on hard drive
LFP_reference$clear_cache(...)
...ignored
clear_memory()
method to clear memory
LFP_reference$clear_memory(...)
...ignored
clone()
The objects of this class are cloneable with this method.
LFP_reference$clone(deep = FALSE)
deepWhether to make a deep clone.
## Not run: # Download subject demo/DemoSubject subject <- as_rave_subject("demo/DemoSubject") # Electrode 14 as reference electrode (Bipolar referencing) e <- new_reference(subject = subject, number = "ref_14", signal_type = "LFP") # Reference "ref_13-16,24" (CAR or white-matter reference) ref <- new_reference(subject = subject, number = "ref_13-16,24", signal_type = "LFP") ref # Set epoch e$set_epoch(epoch = 'auditory_onset') # Set loading window e$trial_intervals <- list(c(-1, 2)) # Preview print(e) # Now epoch power power <- e$load_data("power") names(dimnames(power)) # Subset power subset(power, Time ~ Time < 0, Electrode ~ Electrode == 14) # clear cache on hard disk e$clear_cache() ## End(Not run)## Not run: # Download subject demo/DemoSubject subject <- as_rave_subject("demo/DemoSubject") # Electrode 14 as reference electrode (Bipolar referencing) e <- new_reference(subject = subject, number = "ref_14", signal_type = "LFP") # Reference "ref_13-16,24" (CAR or white-matter reference) ref <- new_reference(subject = subject, number = "ref_13-16,24", signal_type = "LFP") ref # Set epoch e$set_epoch(epoch = 'auditory_onset') # Set loading window e$trial_intervals <- list(c(-1, 2)) # Preview print(e) # Now epoch power power <- e$load_data("power") names(dimnames(power)) # Subset power subset(power, Time ~ Time < 0, Electrode ~ Electrode == 14) # clear cache on hard disk e$clear_cache() ## End(Not run)
Analyze file structures and import all json and
tsv files. File specification can be found at
https://bids-specification.readthedocs.io/en/stable/, chapter
"Modality specific files", section "Intracranial Electroencephalography"
(doi:10.1038/s41597-019-0105-7). Please note that this function has
very limited support on BIDS format.
load_bids_ieeg_header(bids_root, project_name, subject_code, folder = "ieeg")load_bids_ieeg_header(bids_root, project_name, subject_code, folder = "ieeg")
bids_root |
'BIDS' root directory |
project_name |
project folder name |
subject_code |
subject code, do not include |
folder |
folder name corresponding to 'iEEG' data. It's possible to
analyze other folders. However, by default, the function is designed for
|
A list containing the information below:
subject_code |
character, removed leading |
project_name |
character, project name |
has_session |
whether session/block names are indicated by the file structure |
session_names |
session/block names indicated by file structure. If missing, then session name will be "default" |
paths |
a list containing path information |
stimuli_path |
stimuli path, not used for now |
sessions |
A named list containing meta information for each session/block. The names of the list is task name, and the items corresponding to the task contains events and channel information. Miscellaneous files are stored in "others" variable. |
# Download https://github.com/bids-standard/bids-examples/ # extract to directory ~/rave_data/bids_dir/ bids_root <- '~/rave_data/bids_dir/' project_name <- 'ieeg_visual' if(dir.exists(bids_root) && dir.exists(file.path(bids_root, project_name, 'sub-01'))){ header <- load_bids_ieeg_header(bids_root, project_name, '01') print(header) # sessions names(header$sessions) # electrodes head(header$sessions$`01`$spaces$unknown_space$table) # visual task channel settings head(header$sessions$`01`$tasks$`01-visual-01`$channels) # event table head(header$sessions$`01`$tasks$`01-visual-01`$channels) }# Download https://github.com/bids-standard/bids-examples/ # extract to directory ~/rave_data/bids_dir/ bids_root <- '~/rave_data/bids_dir/' project_name <- 'ieeg_visual' if(dir.exists(bids_root) && dir.exists(file.path(bids_root, project_name, 'sub-01'))){ header <- load_bids_ieeg_header(bids_root, project_name, '01') print(header) # sessions names(header$sessions) # electrodes head(header$sessions$`01`$spaces$unknown_space$table) # visual task channel settings head(header$sessions$`01`$tasks$`01-visual-01`$channels) # event table head(header$sessions$`01`$tasks$`01-visual-01`$channels) }
Function try to load 'fst' arrays, if not found, read 'HDF5' arrays
load_fst_or_h5( fst_path, h5_path, h5_name, fst_need_transpose = FALSE, fst_need_drop = FALSE, ram = FALSE )load_fst_or_h5( fst_path, h5_path, h5_name, fst_need_transpose = FALSE, fst_need_drop = FALSE, ram = FALSE )
fst_path |
'fst' file cache path |
h5_path |
alternative 'HDF5' file path |
h5_name |
'HDF5' data name |
fst_need_transpose |
does 'fst' data need transpose? |
fst_need_drop |
drop dimensions |
ram |
whether to load to memory directly or perform lazy loading |
RAVE stores data with redundancy. One electrode data
is usually saved with two copies in different formats: 'HDF5' and
'fst', where 'HDF5' is cross-platform and supported by multiple
languages such as Matlab, Python, etc, while 'fst'
format is supported by R only, with super high read/write speed.
load_fst_or_h5 checks whether the presence of 'fst' file,
if failed, then it reads data from persistent 'HDF5' file.
If 'fst' cache file exists, returns LazyFST object,
otherwise returns LazyH5 instance
io_read_h5
Wrapper for class LazyH5, which load data
with "lazy" mode - only read part of dataset when needed.
load_h5(file, name, read_only = TRUE, ram = FALSE, quiet = FALSE)load_h5(file, name, read_only = TRUE, ram = FALSE, quiet = FALSE)
file |
'HDF5' file |
name |
|
read_only |
only used if |
ram |
load data to memory immediately, default is false |
quiet |
whether to suppress messages |
If ram is true, then return data as arrays, otherwise return
a LazyH5 instance.
file <- tempfile() x <- array(1:120, dim = c(4,5,6)) # save x to file with name /group/dataset/1 save_h5(x, file, '/group/dataset/1', quiet = TRUE) # read data y <- load_h5(file, '/group/dataset/1', ram = TRUE) class(y) # array z <- load_h5(file, '/group/dataset/1', ram = FALSE) class(z) # LazyH5 dim(z)file <- tempfile() x <- array(1:120, dim = c(4,5,6)) # save x to file with name /group/dataset/1 save_h5(x, file, '/group/dataset/1', quiet = TRUE) # read data y <- load_h5(file, '/group/dataset/1', ram = TRUE) class(y) # array z <- load_h5(file, '/group/dataset/1', ram = FALSE) class(z) # LazyH5 dim(z)
Load 'RAVE' subject meta data
load_meta2(meta_type, project_name, subject_code, subject_id, meta_name)load_meta2(meta_type, project_name, subject_code, subject_id, meta_name)
meta_type |
electrodes, epochs, time_points, frequencies, references ... |
project_name |
project name |
subject_code |
subject code |
subject_id |
"project_name/subject_code" |
meta_name |
only used if meta_type is epochs or references |
A data frame of the specified meta type or NULL is no meta
data is found.
read_yaml
For more examples, see save_yaml.
load_yaml(file, ..., map = NULL)load_yaml(file, ..., map = NULL)
file, ...
|
passed to |
map |
|
A fastmap2. If map is provided
then return map, otherwise return newly created one
fastmap2, save_yaml,
read_yaml, write_yaml
'mgh' to 'Nifti'Convert 'FreeSurfer' 'mgh' to 'Nifti'
mgh_to_nii(from, to)mgh_to_nii(from, to)
from |
path to 'FreeSurfer' |
to |
path to 'Nifti' file, must ends with |
Nothing; the file will be created to path specified by to
Create new electrode channel instance or a reference signal instance
new_electrode(subject, number, signal_type, ...) new_reference(subject, number, signal_type, ...)new_electrode(subject, number, signal_type, ...) new_reference(subject, number, signal_type, ...)
subject |
characters, or a |
number |
integer in |
signal_type |
signal type of the electrode or reference; can be
automatically inferred, but it is highly recommended to specify a value;
see |
... |
other parameters passed to class constructors, respectively |
In new_electrode, number should be a positive
valid integer indicating the electrode number. In new_reference,
number can be one of the followings:
'noref', or NULL
no reference is needed
'ref_X'where 'X' is a single number, then the
reference is another existing electrode; this could occur in
bipolar-reference cases
'ref_XXX''XXX' is a combination of multiple
electrodes that can be parsed by parse_svec. This
could occur in common average reference, or white matter reference. One
example is 'ref_13-16,24', meaning the reference signal is an
average of electrode 13, 14, 15, 16, and 24.
Electrode or reference instances that inherit
RAVEAbstarctElectrode class
## Not run: # Download subject demo/DemoSubject (~500 MB) # Electrode 14 in demo/DemoSubject subject <- as_rave_subject("demo/DemoSubject") e <- new_electrode(subject = subject, number = 14, signal_type = "LFP") # Load CAR reference "ref_13-16,24" ref <- new_reference(subject = subject, number = "ref_13-16,24", signal_type = "LFP") e$set_reference(ref) # Set epoch e$set_epoch(epoch = 'auditory_onset') # Set loading window e$trial_intervals <- list(c(-1, 2)) # Preview print(e) # Now epoch power power <- e$load_data("power") names(dimnames(power)) # Subset power subset(power, Time ~ Time < 0, Electrode ~ Electrode == 14) # Draw baseline tempfile <- tempfile() bl <- power_baseline(power, baseline_windows = c(-1, 0), method = "decibel", filebase = tempfile) collapsed_power <- collapse2(bl, keep = c(2,1)) # Visualize dname <- dimnames(bl) image(collapsed_power, x = dname$Time, y = dname$Frequency, xlab = "Time (s)", ylab = "Frequency (Hz)", main = "Mean power over trial (Baseline: -1~0 seconds)", sub = glue('Electrode {e$number} (Reference: {ref$number})')) abline(v = 0, lty = 2, col = 'blue') text(x = 0, y = 20, "Audio onset", col = "blue", cex = 0.6) # clear cache on hard disk e$clear_cache() ref$clear_cache() ## End(Not run)## Not run: # Download subject demo/DemoSubject (~500 MB) # Electrode 14 in demo/DemoSubject subject <- as_rave_subject("demo/DemoSubject") e <- new_electrode(subject = subject, number = 14, signal_type = "LFP") # Load CAR reference "ref_13-16,24" ref <- new_reference(subject = subject, number = "ref_13-16,24", signal_type = "LFP") e$set_reference(ref) # Set epoch e$set_epoch(epoch = 'auditory_onset') # Set loading window e$trial_intervals <- list(c(-1, 2)) # Preview print(e) # Now epoch power power <- e$load_data("power") names(dimnames(power)) # Subset power subset(power, Time ~ Time < 0, Electrode ~ Electrode == 14) # Draw baseline tempfile <- tempfile() bl <- power_baseline(power, baseline_windows = c(-1, 0), method = "decibel", filebase = tempfile) collapsed_power <- collapse2(bl, keep = c(2,1)) # Visualize dname <- dimnames(bl) image(collapsed_power, x = dname$Time, y = dname$Frequency, xlab = "Time (s)", ylab = "Frequency (Hz)", main = "Mean power over trial (Baseline: -1~0 seconds)", sub = glue('Electrode {e$number} (Reference: {ref$number})')) abline(v = 0, lty = 2, col = 'blue') text(x = 0, y = 20, "Audio onset", col = "blue", cex = 0.6) # clear cache on hard disk e$clear_cache() ref$clear_cache() ## End(Not run)
'NiftyReg'
Supports 'Rigid', 'affine', or 'non-linear' transformation
niftyreg_coreg( ct_path, mri_path, coreg_path = NULL, reg_type = c("rigid", "affine", "nonlinear"), interp = c("trilinear", "cubic", "nearest"), verbose = TRUE, ... ) cmd_run_niftyreg_coreg( subject, ct_path, mri_path, reg_type = c("rigid", "affine", "nonlinear"), interp = c("trilinear", "cubic", "nearest"), verbose = TRUE, dry_run = FALSE, ... )niftyreg_coreg( ct_path, mri_path, coreg_path = NULL, reg_type = c("rigid", "affine", "nonlinear"), interp = c("trilinear", "cubic", "nearest"), verbose = TRUE, ... ) cmd_run_niftyreg_coreg( subject, ct_path, mri_path, reg_type = c("rigid", "affine", "nonlinear"), interp = c("trilinear", "cubic", "nearest"), verbose = TRUE, dry_run = FALSE, ... )
ct_path, mri_path
|
absolute paths to 'CT' and 'MR' image files |
coreg_path |
registration path, where to save results; default is
the parent folder of |
reg_type |
registration type, choices are |
interp |
how to interpolate when sampling volumes, choices are
|
verbose |
whether to verbose command; default is true |
... |
other arguments passed to |
subject |
'RAVE' subject |
dry_run |
whether to dry-run the script and to print out the command instead of executing the code; default is false |
Nothing is returned from the function. However, several files will be generated at the 'CT' path:
'ct_in_t1.nii'aligned 'CT' image; the image is also re-sampled into 'MRI' space
'CT_IJK_to_MR_RAS.txt'transform matrix from volume 'IJK' space in the original 'CT' to the 'RAS' anatomical coordinate in 'MR' scanner
'CT_RAS_to_MR_RAS.txt'transform matrix from scanner 'RAS' space in the original 'CT' to 'RAS' in 'MR' scanner space
Calculate power baseline
power_baseline( x, baseline_windows, method = c("percentage", "sqrt_percentage", "decibel", "zscore", "sqrt_zscore"), units = c("Trial", "Frequency", "Electrode"), ... ) ## S3 method for class 'rave_prepare_power' power_baseline( x, baseline_windows, method = c("percentage", "sqrt_percentage", "decibel", "zscore", "sqrt_zscore"), units = c("Frequency", "Trial", "Electrode"), electrodes, ... ) ## S3 method for class 'FileArray' power_baseline( x, baseline_windows, method = c("percentage", "sqrt_percentage", "decibel", "zscore", "sqrt_zscore"), units = c("Frequency", "Trial", "Electrode"), filebase = NULL, ... ) ## S3 method for class 'array' power_baseline( x, baseline_windows, method = c("percentage", "sqrt_percentage", "decibel", "zscore", "sqrt_zscore"), units = c("Trial", "Frequency", "Electrode"), ... ) ## S3 method for class 'ECoGTensor' power_baseline( x, baseline_windows, method = c("percentage", "sqrt_percentage", "decibel", "zscore", "sqrt_zscore"), units = c("Trial", "Frequency", "Electrode"), filebase = NULL, hybrid = TRUE, ... )power_baseline( x, baseline_windows, method = c("percentage", "sqrt_percentage", "decibel", "zscore", "sqrt_zscore"), units = c("Trial", "Frequency", "Electrode"), ... ) ## S3 method for class 'rave_prepare_power' power_baseline( x, baseline_windows, method = c("percentage", "sqrt_percentage", "decibel", "zscore", "sqrt_zscore"), units = c("Frequency", "Trial", "Electrode"), electrodes, ... ) ## S3 method for class 'FileArray' power_baseline( x, baseline_windows, method = c("percentage", "sqrt_percentage", "decibel", "zscore", "sqrt_zscore"), units = c("Frequency", "Trial", "Electrode"), filebase = NULL, ... ) ## S3 method for class 'array' power_baseline( x, baseline_windows, method = c("percentage", "sqrt_percentage", "decibel", "zscore", "sqrt_zscore"), units = c("Trial", "Frequency", "Electrode"), ... ) ## S3 method for class 'ECoGTensor' power_baseline( x, baseline_windows, method = c("percentage", "sqrt_percentage", "decibel", "zscore", "sqrt_zscore"), units = c("Trial", "Frequency", "Electrode"), filebase = NULL, hybrid = TRUE, ... )
x |
R array, |
baseline_windows |
list of baseline window (intervals) |
method |
baseline method; choices are |
units |
the unit of the baseline; see 'Details' |
... |
passed to other methods |
electrodes |
the electrodes to be included in baseline calculation;
for power repository object produced by |
filebase |
where to store the output; default is |
hybrid |
whether the array will be |
The arrays must be four-mode tensor and must have valid named
dimnames. The dimension names must be 'Trial',
'Frequency', 'Time', 'Electrode', case sensitive.
The baseline_windows determines the baseline windows that are used to
calculate time-points of baseline to be included. This can be one
or more intervals and must pass the validation function
validate_time_window.
The units determines the unit of the baseline. It can be one or
more of 'Trial', 'Frequency', 'Electrode'. The default
value is all of them, i.e., baseline for each combination of trial,
frequency, and electrode. To share the baseline across trials, please
remove 'Trial' from units. To calculate baseline that should
be shared across electrodes (e.g. in some mini-electrodes), remove
'Electrode' from the units.
Usually the same type as the input: for arrays,
filearray,
or ECoGTensor, the outputs are
also the same type with the same dimensions; for 'rave_prepare_power'
repositories, the results will be stored in its 'baselined' element;
see 'Examples'.
## Not run: # The following code need to download additional demo data # Please see https://rave.wiki/ for more details library(raveio) repo <- prepare_subject_power( subject = "demo/DemoSubject", time_windows = c(-1, 3), electrodes = c(14, 15)) ##### Direct baseline on the repository power_baseline(x = repo, method = "decibel", baseline_windows = list(c(-1, 0), c(2, 3))) power_mean <- repo$power$baselined$collapse( keep = c(2,1), method = "mean") image(power_mean, x = repo$time_points, y = repo$frequency, xlab = "Time (s)", ylab = "Frequency (Hz)", main = "Mean power over trial (Baseline: -1~0 & 2~3)") abline(v = 0, lty = 2, col = 'blue') text(x = 0, y = 20, "Aud-Onset", col = "blue", cex = 0.6) ##### Alternatively, baseline on electrode instances baselined <- lapply(repo$power$data_list, function(inst) { re <- power_baseline(inst, method = "decibel", baseline_windows = list(c(-1, 0), c(2, 3))) collapse2(re, keep = c(2,1), method = "mean") }) power_mean2 <- (baselined[[1]] + baselined[[2]]) / 2 # Same with precision difference max(abs(power_mean2 - power_mean)) < 1e-6 ## End(Not run)## Not run: # The following code need to download additional demo data # Please see https://rave.wiki/ for more details library(raveio) repo <- prepare_subject_power( subject = "demo/DemoSubject", time_windows = c(-1, 3), electrodes = c(14, 15)) ##### Direct baseline on the repository power_baseline(x = repo, method = "decibel", baseline_windows = list(c(-1, 0), c(2, 3))) power_mean <- repo$power$baselined$collapse( keep = c(2,1), method = "mean") image(power_mean, x = repo$time_points, y = repo$frequency, xlab = "Time (s)", ylab = "Frequency (Hz)", main = "Mean power over trial (Baseline: -1~0 & 2~3)") abline(v = 0, lty = 2, col = 'blue') text(x = 0, y = 20, "Aud-Onset", col = "blue", cex = 0.6) ##### Alternatively, baseline on electrode instances baselined <- lapply(repo$power$data_list, function(inst) { re <- power_baseline(inst, method = "decibel", baseline_windows = list(c(-1, 0), c(2, 3))) collapse2(re, keep = c(2,1), method = "mean") }) power_mean2 <- (baselined[[1]] + baselined[[2]]) / 2 # Same with precision difference max(abs(power_mean2 - power_mean)) < 1e-6 ## End(Not run)
Prepare 'RAVE' single-subject data
prepare_subject_bare0( subject, electrodes, reference_name, ..., quiet = TRUE, repository_id = NULL ) prepare_subject_bare( subject, electrodes, reference_name, ..., repository_id = NULL ) prepare_subject_with_epoch( subject, electrodes, reference_name, epoch_name, time_windows, stitch_events = NULL, env = parent.frame(), ... ) prepare_subject_with_blocks( subject, electrodes, reference_name, blocks, raw = FALSE, signal_type = "LFP", time_frequency = (!raw && signal_type == "LFP"), quiet = raw, env = parent.frame(), repository_id = NULL, ... ) prepare_subject_phase( subject, electrodes, reference_name, epoch_name, time_windows, stitch_events = NULL, signal_type = c("LFP"), env = parent.frame(), verbose = TRUE, ... ) prepare_subject_power( subject, electrodes, reference_name, epoch_name, time_windows, stitch_events = NULL, signal_type = c("LFP"), env = parent.frame(), verbose = TRUE, ... ) prepare_subject_wavelet( subject, electrodes, reference_name, epoch_name, time_windows, stitch_events = NULL, signal_type = c("LFP"), env = parent.frame(), verbose = TRUE, ... ) prepare_subject_raw_voltage_with_epoch( subject, electrodes, epoch_name, time_windows, stitch_events = NULL, ..., quiet = TRUE, repository_id = NULL ) prepare_subject_voltage_with_epoch( subject, electrodes, epoch_name, time_windows, reference_name, stitch_events = NULL, ..., quiet = TRUE, repository_id = NULL )prepare_subject_bare0( subject, electrodes, reference_name, ..., quiet = TRUE, repository_id = NULL ) prepare_subject_bare( subject, electrodes, reference_name, ..., repository_id = NULL ) prepare_subject_with_epoch( subject, electrodes, reference_name, epoch_name, time_windows, stitch_events = NULL, env = parent.frame(), ... ) prepare_subject_with_blocks( subject, electrodes, reference_name, blocks, raw = FALSE, signal_type = "LFP", time_frequency = (!raw && signal_type == "LFP"), quiet = raw, env = parent.frame(), repository_id = NULL, ... ) prepare_subject_phase( subject, electrodes, reference_name, epoch_name, time_windows, stitch_events = NULL, signal_type = c("LFP"), env = parent.frame(), verbose = TRUE, ... ) prepare_subject_power( subject, electrodes, reference_name, epoch_name, time_windows, stitch_events = NULL, signal_type = c("LFP"), env = parent.frame(), verbose = TRUE, ... ) prepare_subject_wavelet( subject, electrodes, reference_name, epoch_name, time_windows, stitch_events = NULL, signal_type = c("LFP"), env = parent.frame(), verbose = TRUE, ... ) prepare_subject_raw_voltage_with_epoch( subject, electrodes, epoch_name, time_windows, stitch_events = NULL, ..., quiet = TRUE, repository_id = NULL ) prepare_subject_voltage_with_epoch( subject, electrodes, epoch_name, time_windows, reference_name, stitch_events = NULL, ..., quiet = TRUE, repository_id = NULL )
subject |
character of project and subject, such as |
electrodes |
integer vector of electrodes, or a character that can be
parsed by |
reference_name |
reference name to be loaded |
... |
ignored |
quiet |
whether to quietly load the data |
repository_id |
used internally |
epoch_name |
epoch name to be loaded, or a
|
time_windows |
a list of time windows that are relative to epoch onset
time; need to pass the validation |
stitch_events |
events to stitch, default is |
env |
environment to evaluate |
blocks |
one or more session blocks to load |
raw |
whether to load from original (before processing) data; if true, then time-frequency data will not be loaded. |
signal_type |
electrode signal type (length of one) to be considered;
default is 'LFP'. This option rarely needs to change unless you really want
to check the power data from other types. For other signal types, check
|
time_frequency |
whether to load time-frequency data when preparing block data |
verbose |
whether to show progress |
A fastmap2 (basically a list) of objects.
Depending on the functions called, the following items may exist in the list:
subjectA RAVESubject instance
epoch_nameSame as input epoch_name
epochA RAVEEpoch instance
reference_nameSame as input reference_name
reference_tableA data frame of reference
electrode_tableA data frame of electrode information
frequencyA vector of frequencies
time_pointsA vector of time-points
power_listA list of power data of the electrodes
power_dimnamesA list of trial indices, frequencies, time points, and electrodes that are loaded
For best performance, please install 'ravedash'. This
function can replace progress2.
progress_with_logger( title, max = 1, ..., quiet = FALSE, session = shiny::getDefaultReactiveDomain(), shiny_auto_close = FALSE, outputId = NULL, log )progress_with_logger( title, max = 1, ..., quiet = FALSE, session = shiny::getDefaultReactiveDomain(), shiny_auto_close = FALSE, outputId = NULL, log )
title, max, ..., quiet, session, shiny_auto_close
|
see
|
outputId |
will be used if package |
log |
function, |
A list, see progress2
'nipy' scriptAlign 'CT' using
nipy.algorithms.registration.histogram_registration.
py_nipy_coreg( ct_path, mri_path, clean_source = TRUE, inverse_target = TRUE, precenter_source = TRUE, smooth = 0, reg_type = c("rigid", "affine"), interp = c("pv", "tri"), similarity = c("crl1", "cc", "cr", "mi", "nmi", "slr"), optimizer = c("powell", "steepest", "cg", "bfgs", "simplex"), tol = 1e-04, dry_run = FALSE ) cmd_run_nipy_coreg( subject, ct_path, mri_path, clean_source = TRUE, inverse_target = TRUE, precenter_source = TRUE, reg_type = c("rigid", "affine"), interp = c("pv", "tri"), similarity = c("crl1", "cc", "cr", "mi", "nmi", "slr"), optimizer = c("powell", "steepest", "cg", "bfgs", "simplex"), dry_run = FALSE, verbose = FALSE )py_nipy_coreg( ct_path, mri_path, clean_source = TRUE, inverse_target = TRUE, precenter_source = TRUE, smooth = 0, reg_type = c("rigid", "affine"), interp = c("pv", "tri"), similarity = c("crl1", "cc", "cr", "mi", "nmi", "slr"), optimizer = c("powell", "steepest", "cg", "bfgs", "simplex"), tol = 1e-04, dry_run = FALSE ) cmd_run_nipy_coreg( subject, ct_path, mri_path, clean_source = TRUE, inverse_target = TRUE, precenter_source = TRUE, reg_type = c("rigid", "affine"), interp = c("pv", "tri"), similarity = c("crl1", "cc", "cr", "mi", "nmi", "slr"), optimizer = c("powell", "steepest", "cg", "bfgs", "simplex"), dry_run = FALSE, verbose = FALSE )
ct_path, mri_path
|
absolute paths to 'CT' and 'MR' image files |
clean_source |
whether to replace negative 'CT' values with zeros; default is true |
inverse_target |
whether to inverse 'MRI' color intensity; default is true |
precenter_source |
whether to adjust the 'CT' transform matrix before alignment, such that the origin of 'CT' is at the center of the volume; default is true. This option may avoid the case that 'CT' is too far-away from the 'MR' volume at the beginning of the optimization |
smooth, interp, optimizer, tol
|
optimization parameters, see
|
reg_type |
registration type, choices are |
similarity |
the cost function of the alignment; choices are
|
dry_run |
whether to dry-run the script and to print out the command instead of executing the code; default is false |
subject |
'RAVE' subject |
verbose |
whether to verbose command; default is false |
Nothing is returned from the function. However, several files will be generated at the 'CT' path:
'ct_in_t1.nii'aligned 'CT' image; the image is also re-sampled into 'MRI' space
'CT_IJK_to_MR_RAS.txt'transform matrix from volume 'IJK' space in the original 'CT' to the 'RAS' anatomical coordinate in 'MR' scanner
'CT_RAS_to_MR_RAS.txt'transform matrix from scanner 'RAS' space in the original 'CT' to 'RAS' in 'MR' scanner space
Create 3D visualization of the brain and visualize with modern web browsers
rave_brain( subject, surfaces = "pial", overlays = "aparc.a2009s+aseg", annotations = "label/aparc.a2009s", ..., usetemplateifmissing = FALSE, include_electrodes = TRUE )rave_brain( subject, surfaces = "pial", overlays = "aparc.a2009s+aseg", annotations = "label/aparc.a2009s", ..., usetemplateifmissing = FALSE, include_electrodes = TRUE )
subject |
character, list, or |
surfaces |
one or more brain surface types from |
overlays |
volumes to overlay; default is |
annotations |
surface annotation or curvature data to load;
default is |
... |
ignored, reserved for legacy code |
usetemplateifmissing |
whether to use template brain when the subject
brain files are missing. If set to true, then a template (usually 'N27')
brain will be displayed as an alternative solution, and electrodes will be
rendered according to their |
include_electrodes |
whether to include electrode in the model; default is true |
A 'threeBrain' instance if brain is found or
usetemplateifmissing is set to true; otherwise returns NULL
# Please make sure DemoSubject is correctly installed # The subject is ~1GB from Github if(interactive()){ brain <- rave_brain("demo/DemoSubject") if( !is.null(brain) ) { brain$plot() } }# Please make sure DemoSubject is correctly installed # The subject is ~1GB from Github if(interactive()){ brain <- rave_brain("demo/DemoSubject") if( !is.null(brain) ) { brain$plot() } }
Find and execute external command-line tools
normalize_commandline_path( path, type = c("dcm2niix", "freesurfer", "fsl", "afni", "others"), unset = NA ) cmd_dcm2niix(error_on_missing = TRUE, unset = NA) cmd_freesurfer_home(error_on_missing = TRUE, unset = NA) cmd_fsl_home(error_on_missing = TRUE, unset = NA) cmd_afni_home(error_on_missing = TRUE, unset = NA) cmd_homebrew(error_on_missing = TRUE, unset = NA) is_dry_run()normalize_commandline_path( path, type = c("dcm2niix", "freesurfer", "fsl", "afni", "others"), unset = NA ) cmd_dcm2niix(error_on_missing = TRUE, unset = NA) cmd_freesurfer_home(error_on_missing = TRUE, unset = NA) cmd_fsl_home(error_on_missing = TRUE, unset = NA) cmd_afni_home(error_on_missing = TRUE, unset = NA) cmd_homebrew(error_on_missing = TRUE, unset = NA) is_dry_run()
path |
path to normalize |
type |
type of command |
unset |
default to return if the command is not found |
error_on_missing |
whether to raise errors if command is missing |
Normalized path to the command, or unset if command is
missing.
This function is internally used and should not be called directly.
rave_directories( subject_code, project_name, blocks = NULL, .force_format = c("", "native", "BIDS") )rave_directories( subject_code, project_name, blocks = NULL, .force_format = c("", "native", "BIDS") )
subject_code |
'RAVE' subject code |
project_name |
'RAVE' project name |
blocks |
session or block names, optional |
.force_format |
format of the data, default is automatically detected. |
A list of directories
Export portable data for custom analyses.
rave_export(x, path, ...) ## Default S3 method: rave_export(x, path, format = c("rds", "yaml", "json"), ...) ## S3 method for class 'rave_prepare_subject_raw_voltage_with_epoch' rave_export(x, path, zip = FALSE, ...) ## S3 method for class 'rave_prepare_subject_voltage_with_epoch' rave_export(x, path, zip = FALSE, ...) ## S3 method for class 'rave_prepare_power' rave_export(x, path, zip = FALSE, ...)rave_export(x, path, ...) ## Default S3 method: rave_export(x, path, format = c("rds", "yaml", "json"), ...) ## S3 method for class 'rave_prepare_subject_raw_voltage_with_epoch' rave_export(x, path, zip = FALSE, ...) ## S3 method for class 'rave_prepare_subject_voltage_with_epoch' rave_export(x, path, zip = FALSE, ...) ## S3 method for class 'rave_prepare_power' rave_export(x, path, zip = FALSE, ...)
x |
R object or 'RAVE' repositories |
path |
path to save to |
... |
passed to other methods |
format |
export format |
zip |
whether to zip the files |
Exported data path
x <- "my data" path <- tempfile() rave_export(x, path) readRDS(path) ## Not run: # Needs demo subject path <- tempfile() x <- prepare_subject_power("demo/DemoSubject") # Export power data to path rave_export(x, path) ## End(Not run)x <- "my data" path <- tempfile() rave_export(x, path) readRDS(path) ## Not run: # Needs demo subject path <- tempfile() x <- prepare_subject_power("demo/DemoSubject") # Export power data to path rave_export(x, path) ## End(Not run)
Import files with predefined structures. Supported file
formats include 'Matlab', 'HDF5', 'EDF(+)', 'BrainVision'
('.eeg/.dat/.vhdr'). Supported file structures include 'rave' native
structure and 'BIDS' (very limited) format. Please see
https://openwetware.org/wiki/RAVE:ravepreprocess for tutorials.
rave_import( project_name, subject_code, blocks, electrodes, format, sample_rate, conversion = NA, data_type = "LFP", task_runs = NULL, add = FALSE, ... )rave_import( project_name, subject_code, blocks, electrodes, format, sample_rate, conversion = NA, data_type = "LFP", task_runs = NULL, add = FALSE, ... )
project_name |
project name, for 'rave' native structure, this can be any character; for 'BIDS' format, this must be consistent with 'BIDS' project name. For subjects with multiple tasks, see Section "'RAVE' Project" |
subject_code |
subject code in character. For 'rave' native structure,
this is a folder name under raw directory. For 'BIDS', this is subject
label without |
blocks |
characters, for 'rave' native format, this is the folder names
subject directory; for 'BIDS', this is session name with |
electrodes |
integers electrode numbers |
format |
integer from 1 to 6, or character. For characters, you can get
options by running |
sample_rate |
sample frequency, must be positive |
conversion |
physical unit conversion, choices are |
data_type |
electrode signal type; see |
task_runs |
for 'BIDS' formats only, see Section "Block vs. Session" |
add |
whether to add electrodes. If set to true, then only new electrodes are allowed to be imported, blocks will be ignored and trying to import electrodes that have been imported will still result in error. |
... |
other parameters |
None
A 'rave' project can be very flexible. A project can refer to a task, a
research objective, or "arbitrarily" as long as you find common research
interests among subjects. One subject can appear in multiple projects with
different blocks, hence project_name should be
objective-based. There is no concept of "project" in 'rave' raw directory.
When importing data, you choose subset of blocks from subjects forming
a project.
When importing 'BIDS' data into 'rave', project_name must be
consistent with 'BIDS' project name as a compromise. Once imported,
you may change the project folder name in imported rave data
directory to other names. Because once raw traces are imported,
'rave' data will become self-contained
and 'BIDS' data are no longer required for analysis.
This naming inconsistency will also be ignored.
'rave' and 'BIDS' have different definitions for a "chunk" of signals.
In 'rave', we use "block". it means
combination of session (days), task, and run, i.e. a block of continuous
signals captured. Raw data files are supposed to be stored in file
hierarchy of <raw-root>/<subject_code>/<block>/<datafiles>.
In 'BIDS', sessions, tasks, and runs are separated, and only session names
are indicated under subject folder. Because some previous compatibility
issues, argument 'block' refers to direct folder names under
subject directories.
This means when importing data from 'BIDS' format, block argument
needs to be session names to comply with 'subject/block' structure,
and there is an additional mandatory argument task_runs
especially designed for 'BIDS' format.
For 'rave' native raw data format, block will be as-is once imported.
For 'BIDS' format, task_runs will be treated as blocks once imported.
Following file structure. Here use project "demo" and subject
"YAB" and block "008"), electrode 14 as an example.
format=1, or ".mat/.h5 file per electrode per block"
folder <raw>/YAB/008 contains 'Matlab' or 'HDF5' files per electrode.
Data file name should look like "xxx_14.mat"
format=2, or "Single .mat/.h5 file per block"
<raw>/YAB/008 contains only one 'Matlab' or 'HDF5' file. Data within
the file should be a 2-dimensional matrix, where the column 14 is
signal recorded from electrode 14
format=3, or "Single EDF(+) file per block"
<raw>/YAB/008 contains only one 'edf' file
format=4, or
"Single BrainVision file (.vhdr+.eeg, .vhdr+.dat) per block"
<raw>/YAB/008 contains only one 'vhdr' file, and
the data file must be inferred from the header file
format=5, or "BIDS & EDF(+)"
<bids>/demo/sub-YAB/ses-008/ must contains *_electrodes.tsv,
each run must have channel file. The channel files and electrode file
must be consistent in names.
Argument task_runs is mandatory, characters, combination of session,
task name, and run number. For example, a task header file in BIDS with name
'sub-YAB_ses-008_task-visual_run-01_ieeg.edf' has task_runs
name as '008-visual-01', where the first '008' refers
to session, 'visual' is task name, and the second '01' is
run number.
format=6, or
"BIDS & BrainVision (.vhdr+.eeg, .vhdr+.dat)"
Same as previous format "BIDS & EDF(+)", but data files have
'BrainVision' formats.
Convert 'RAVE' subject generated by 2.0 pipeline such that 1.0 modules can use the data. The subject must have valid electrodes. The data must be imported, with time-frequency transformed to pass the validation before converting.
rave_subject_format_conversion(subject, verbose = TRUE, ...)rave_subject_format_conversion(subject, verbose = TRUE, ...)
subject |
'RAVE' subject characters, such as |
verbose |
whether to verbose the messages |
... |
ignored, reserved for future use |
Nothing
Validate subjects and returns whether the subject can be imported into 'rave'
validate_raw_file( subject_code, blocks, electrodes, format, data_type = c("continuous"), ... ) IMPORT_FORMATSvalidate_raw_file( subject_code, blocks, electrodes, format, data_type = c("continuous"), ... ) IMPORT_FORMATS
subject_code |
subject code, direct folder under 'rave' raw data path |
blocks |
block character, direct folder under subject folder. For raw files following 'BIDS' convention, see details |
electrodes |
electrodes to verify |
format |
integer or character. For characters, run
|
data_type |
currently only support continuous type of signals |
... |
other parameters used if validating |
An object of class list of length 7.
Six types of raw file structures are supported. They can be basically classified into two categories: 'rave' native raw structure and 'BIDS-iEEG' structure.
In 'rave' native structure, subject folders
are stored within the root directory, which can be obtained via
raveio_getopt('raw_data_dir'). Subject directory is the subject code.
Inside of subject folder are block files. In 'rave', term 'block'
is the combination of session, task, and run. Within each block, there
should be 'iEEG' data files.
In 'BIDS-iEEG' format, the root directory can be obtained via
raveio_getopt('bids_data_dir'). 'BIDS' root folder contains
project folders. This is unlike 'rave' native raw data format.
Subject folders are stored within the project directories.
The subject folders start with 'sub-'. Within subject
folder, there are session folders with prefix 'ses-'. Session
folders are optional. 'iEEG' data is stored in 'ieeg' folder under
the session/subject folder. 'ieeg' folder should contain at least
sub-<label>*_electrodes.tsv
sub-<label>*_task-<label>_run-<index>_ieeg.json
sub-<label>*_task-<label>_run-<index>_ieeg.<ext>, in current
'rave', only extensions '.vhdr+.eeg/.dat' ('BrainVision') or 'EDF'
(or plus) are supported.
When format is 'BIDS', project_name must be specified.
The following formats are supported:
'.mat/.h5 file per electrode per block''rave' native raw format, each block folder contains multiple
'Matlab' or 'HDF5' files. Each file corresponds to a channel/electrode.
File names should follow 'xxx001.mat' or 'xxx001.h5'. The
numbers before the extension are channel numbers.
'Single .mat/.h5 file per block''rave' native raw format, each block folder contains only one
'Matlab' or 'HDF5' file. The file name can be arbitrary, but extension
must be either '.mat' or '.h5'. Within the file there should
be a matrix containing all the data. The short dimension of the matrix
will be channels, and larger side of the dimension corresponds to the
time points.
'Single EDF(+) file per block''rave' native raw format, each block folder contains only one
'.edf' file.
'Single BrainVision file (.vhdr+.eeg, .vhdr+.dat) per block''rave' native raw format, each block folder contains only two
files. The first file is header '.vhdr' file. It contains
all meta information. The second is either '.eeg' or '.dat'
file containing the body, i.e. signal entries.
'BIDS & EDF(+)''BIDS' format. The data file should have '.edf' extension
'BIDS & BrainVision (.vhdr+.eeg, .vhdr+.dat)''BIDS' format. The data file should have '.vhdr'+'.eeg/.dat'
extensions
logical true or false whether the directory is valid. Attributes containing error reasons or snapshot of the data. The attributes might be:
snapshot |
description of data found if passing the validation |
valid_run_names |
For 'BIDS' format, valid
|
reason |
named list where the names are the reason why validation fails and values are corresponding sessions or electrodes or both. |
Works on 'Linux' and 'Mac' only.
rave_server_install( url = "https://github.com/rstudio/shiny-server/archive/refs/tags/v1.5.18.987.zip" ) rave_server_configure( ports = 17283, user = Sys.info()[["user"]], rave_version = c("1", "2") )rave_server_install( url = "https://github.com/rstudio/shiny-server/archive/refs/tags/v1.5.18.987.zip" ) rave_server_configure( ports = 17283, user = Sys.info()[["user"]], rave_version = c("1", "2") )
url |
'URL' to shiny-server 'ZIP' file to download |
ports |
integer vectors or character, indicating the port numbers to host 'RAVE' instances a valid port must be within the range from 1024 to 65535. |
user |
user to run the service as; default is the login user |
rave_version |
internally used; might be deprecated in the future |
nothing
## Not run: # OS-specific. Please install R package `rpymat` first # Install rave-server rave_server_install() # Let port 17283-17290 to host RAVE instance rave_server_configure(ports = "17283-17290") ## End(Not run)## Not run: # OS-specific. Please install R package `rpymat` first # Install rave-server rave_server_install() # Let port 17283-17290 to host RAVE instance rave_server_configure(ports = "17283-17290") ## End(Not run)
This class is not intended for direct use. Please create new child classes and implement some key methods.
If simplify is enabled, and only one block is loaded,
then the result will be a vector (type="voltage") or a matrix
(others), otherwise the result will be a named list where the names
are the blocks.
subjectsubject instance (RAVESubject)
numberinteger stands for electrode number or reference ID
referencereference electrode, either NULL for no reference
or an electrode instance inherits RAVEAbstarctElectrode
epocha RAVEEpoch instance
stitch_eventsevents to stitch, when loading window is not default
to trial onset; must be NULL or a character vector of length 2
typesignal type of the electrode, such as 'LFP', 'Spike', and 'EKG'; default is 'Unknown'
power_enabledwhether the electrode can be used in power analyses
such as frequency, or frequency-time analyses;
this usually requires transforming the electrode raw voltage signals
using signal processing methods such as 'Fourier', 'wavelet', 'Hilbert',
'multi-taper', etc. If an electrode has power data, then it's power data
can be loaded via prepare_subject_power method.
is_referencewhether this instance is a reference electrode
locationlocation type of the electrode, see
LOCATION_TYPES for details
existswhether electrode exists in subject
preprocess_filepath to preprocess 'HDF5' file
power_filepath to power 'HDF5' file
phase_filepath to phase 'HDF5' file
voltage_filepath to voltage 'HDF5' file
reference_namereference electrode name
epoch_namecurrent epoch name
cache_rootrun-time cache path; NA if epoch or trial
intervals are missing
trial_intervalstrial intervals relative to epoch onset
new()
constructor
RAVEAbstarctElectrode$new(subject, number, quiet = FALSE)
subjectcharacter or RAVESubject instance
numbercurrent electrode number or reference ID
quietreserved, whether to suppress warning messages
set_reference()
set reference for instance
RAVEAbstarctElectrode$set_reference(reference)
referenceNULL or RAVEAbstarctElectrode instance
instance
set_epoch()
set epoch instance for the electrode
RAVEAbstarctElectrode$set_epoch(epoch, stitch_events = NULL)
epochcharacters or RAVEEpoch instance. For
characters, make sure "epoch_<name>.csv" is in meta folder.
stitch_eventsevents to stitch, default is NULL, meaning
when loading data, the time is relative to the trial onset (column
"Time" in the epoch file); set to a character of length 2,
representing the events if time is not relative to trial onset. Please
remove the prefix. For example, for a column named "Event_name",
the event name is "name".
clear_cache()
method to clear cache on hard drive
RAVEAbstarctElectrode$clear_cache(...)
...implemented by child instances
clear_memory()
method to clear memory
RAVEAbstarctElectrode$clear_memory(...)
...implemented by child instances
load_data()
method to load electrode data
RAVEAbstarctElectrode$load_data(type)
typedata type such as "power", "phase",
"voltage", "wavelet-coefficient", or others
depending on child class implementations
load_blocks()
load electrode block-wise data (with reference), useful when epoch is absent
RAVEAbstarctElectrode$load_blocks(blocks, type, simplify = TRUE)
blockssession blocks
typedata type such as "power", "phase",
"voltage", "wavelet-coefficient".
simplifywhether to simplify the result
clone()
The objects of this class are cloneable with this method.
RAVEAbstarctElectrode$clone(deep = FALSE)
deepWhether to make a deep clone.
## Not run: # To run this example, please download demo subject (~700 MB) from # https://github.com/beauchamplab/rave/releases/tag/v0.1.9-beta generator <- RAVEAbstarctElectrode # load demo subject electrode 14 e <- generator$new("demo/DemoSubject", number = 14) # set epoch e$subject$epoch_names e$set_epoch("auditory_onset") head(e$epoch$table) # set epoch range (-1 to 2 seconds relative to onset) e$trial_intervals <- c(-1,2) # or to set multiple ranges e$trial_intervals <- list(c(-2,-1), c(0, 2)) # set reference e$subject$reference_names reference_table <- e$subject$meta_data( meta_type = "reference", meta_name = "default") ref_name <- subset(reference_table, Electrode == 14)[["Reference"]] # the reference is CAR type, mean of electrode 13-16,24 ref_name # load & set reference ref <- generator$new(e$subject, ref_name) e$set_reference(ref) ## End(Not run)## Not run: # To run this example, please download demo subject (~700 MB) from # https://github.com/beauchamplab/rave/releases/tag/v0.1.9-beta generator <- RAVEAbstarctElectrode # load demo subject electrode 14 e <- generator$new("demo/DemoSubject", number = 14) # set epoch e$subject$epoch_names e$set_epoch("auditory_onset") head(e$epoch$table) # set epoch range (-1 to 2 seconds relative to onset) e$trial_intervals <- c(-1,2) # or to set multiple ranges e$trial_intervals <- list(c(-2,-1), c(0, 2)) # set reference e$subject$reference_names reference_table <- e$subject$meta_data( meta_type = "reference", meta_name = "default") ref_name <- subset(reference_table, Electrode == 14)[["Reference"]] # the reference is CAR type, mean of electrode 13-16,24 ref_name # load & set reference ref <- generator$new(e$subject, ref_name) e$set_reference(ref) ## End(Not run)
Trial epoch, contains the following information: Block
experiment block/session string; Time trial onset within that block;
Trial trial number; Condition trial condition. Other optional
columns are Event_xxx (starts with "Event"). See
https://openwetware.org/wiki/RAVE:Epoching or more details.
self$table
If event is one of "trial onset",
"default", "", or NULL, then the result will be
"Time" column; if the event is found, then return will be the
corresponding event column. When the event is not found and
missing is "error", error will be raised; default is
to return "Time" column, as it's trial onset and is mandatory.
If condition_type is one of
"default", "", or NULL, then the result will be
"Condition" column; if the condition type is found, then return
will be the corresponding condition type column. When the condition type
is not found and missing is "error", error will be raised;
default is to return "Condition" column, as it's the default
and is mandatory.
nameepoch name, character
subjectRAVESubject instance
dataa list of trial information, internally used
tabletrial epoch table
.columnsepoch column names, internally used
columnscolumns of trial table
n_trialstotal number of trials
trialstrial numbers
available_eventsavailable events other than trial onset
available_condition_typeavailable condition type other than the default
new()
constructor
RAVEEpoch$new(subject, name)
subjectRAVESubject instance or character
namecharacter, make sure "epoch_<name>.csv" is in meta
folder
trial_at()
get ith trial
RAVEEpoch$trial_at(i, df = TRUE)
itrial number
dfwhether to return as data frame or a list
update_table()
manually update table field
RAVEEpoch$update_table()
set_trial()
set one trial
RAVEEpoch$set_trial(Block, Time, Trial, Condition, ...)
Blockblock string
Timetime in second
Trialpositive integer, trial number
Conditioncharacter, trial condition
...other key-value pairs corresponding to other optional columns
get_event_colname()
Get epoch column name that represents the desired event
RAVEEpoch$get_event_colname(
event = "",
missing = c("warning", "error", "none")
)eventa character string of the event, see
$available_events for all available events; set to
"trial onset", "default", or blank to use the default
missingwhat to do if event is missing; default is to warn
get_condition_colname()
Get condition column name that represents the desired condition type
RAVEEpoch$get_condition_colname(
condition_type,
missing = c("warning", "error", "none")
)condition_typea character string of the condition type, see
$available_condition_type for all available condition types;
set to "default" or blank to use the default
missingwhat to do if condition type is missing; default is to warn if the condition column is not found.
clone()
The objects of this class are cloneable with this method.
RAVEEpoch$clone(deep = FALSE)
deepWhether to make a deep clone.
# Please download DemoSubject ~700MB from # https://github.com/beauchamplab/rave/releases/tag/v0.1.9-beta ## Not run: # Load meta/epoch_auditory_onset.csv from subject demo/DemoSubject epoch <-RAVEEpoch$new(subject = 'demo/DemoSubject', name = 'auditory_onset') # first several trials head(epoch$table) # query specific trial old_trial1 <- epoch$trial_at(1) # Create new trial or change existing trial epoch$set_trial(Block = '008', Time = 10, Trial = 1, Condition = 'AknownVmeant') new_trial1 <- epoch$trial_at(1) # Compare new and old trial 1 rbind(old_trial1, new_trial1) # To get updated trial table, must update first epoch$update_table() head(epoch$table) ## End(Not run)# Please download DemoSubject ~700MB from # https://github.com/beauchamplab/rave/releases/tag/v0.1.9-beta ## Not run: # Load meta/epoch_auditory_onset.csv from subject demo/DemoSubject epoch <-RAVEEpoch$new(subject = 'demo/DemoSubject', name = 'auditory_onset') # first several trials head(epoch$table) # query specific trial old_trial1 <- epoch$trial_at(1) # Create new trial or change existing trial epoch$set_trial(Block = '008', Time = 10, Trial = 1, Condition = 'AknownVmeant') new_trial1 <- epoch$trial_at(1) # Compare new and old trial 1 rbind(old_trial1, new_trial1) # To get updated trial table, must update first epoch$update_table() head(epoch$table) ## End(Not run)
The constant variables
SIGNAL_TYPES LOCATION_TYPES MNI305_to_MNI152 YAEL_IMAGE_TYPESSIGNAL_TYPES LOCATION_TYPES MNI305_to_MNI152 YAEL_IMAGE_TYPES
An object of class character of length 5.
An object of class character of length 5.
An object of class matrix (inherits from array) with 4 rows and 4 columns.
An object of class character of length 10.
SIGNAL_TYPES has the following options: 'LFP', 'Spike',
'EKG', 'Auxiliary', or 'Unknown'. As
of 'raveio' 0.0.6, only 'LFP' (see LFP_electrode)
signal type is supported.
LOCATION_TYPES is a list of the electrode location types:
'iEEG' (this includes the next two), 'sEEG' (stereo),
'ECoG' (surface), 'EEG' (scalp),
'Others'. See field 'location' in
RAVEAbstarctElectrode
MNI305_to_MNI152 is a 4-by-4 matrix converting 'MNI305'
coordinates to 'MNI152' space. The difference of these two
spaces is: 'MNI305' is an average of 305 human subjects,
while 'MNI152' is the average of 152 people. These two coordinates
differs slightly. While most of the 'MNI' coordinates reported by
'RAVE' and 'FreeSurfer' are in the 'MNI305' space, many other
programs are expecting 'MNI152' coordinates.
R6 class definition
data frame
raveio::RAVESubject -> RAVEMetaSubject
projectproject instance of current subject; see
RAVEProject
project_namecharacter string of project name
subject_codecharacter string of subject code
subject_idsubject ID: "project/subject"
pathsubject root path
rave_path'rave' directory under subject root path
meta_pathmeta data directory for current subject
freesurfer_path'FreeSurfer' directory for current subject. If
no path exists, values will be NA
preprocess_pathpreprocess directory under subject 'rave' path
data_pathdata directory under subject 'rave' path
cache_pathpath to 'FST' copies under subject 'data' path
pipeline_pathpath to pipeline scripts under subject's folder
note_pathpath that stores 'RAVE' related subject notes
epoch_namespossible epoch names
reference_namespossible reference names
reference_pathreference path under 'rave' folder
preprocess_settingspreprocess instance; see
RAVEPreprocessSettings
blockssubject experiment blocks in current project
electrodesall electrodes, no matter excluded or not
raw_sample_ratesvoltage sample rate
power_sample_ratepower spectrum sample rate
has_waveletwhether electrodes have wavelet transforms
notch_filteredwhether electrodes are Notch-filtered
electrode_typeselectrode signal types
raveio::RAVESubject$get_default()raveio::RAVESubject$get_electrode_table()raveio::RAVESubject$get_epoch()raveio::RAVESubject$get_frequency()raveio::RAVESubject$get_note_summary()raveio::RAVESubject$get_reference()raveio::RAVESubject$initialize_paths()raveio::RAVESubject$list_pipelines()raveio::RAVESubject$load_pipeline()raveio::RAVESubject$set_default()raveio::RAVESubject$valid_electrodes()print()
override print method
RAVEMetaSubject$print(...)
...ignored
new()
constructor
RAVEMetaSubject$new(project_name, subject_code = NULL, strict = FALSE)
project_namecharacter project name
subject_codecharacter subject code
strictwhether to check if subject folders exist
meta_data()
get subject meta data located in "meta/" folder
RAVEMetaSubject$meta_data(
meta_type = c("electrodes", "frequencies", "time_points", "epoch", "references"),
meta_name = "default"
)meta_typechoices are 'electrodes', 'frequencies', 'time_points', 'epoch', 'references'
meta_nameif meta_type='epoch', read in
'epoch_<meta_name>.csv'; if meta_type='references',
read in 'reference_<meta_name>.csv'.
clone()
The objects of this class are cloneable with this method.
RAVEMetaSubject$clone(deep = FALSE)
deepWhether to make a deep clone.
R6 class definition
list of electrode type, number, etc.
NULL when no channel is composed.
When flat is TRUE, a data frame of weights with
the columns composing electrode channel numbers, composed channel
number, and corresponding weights; if flat is FALSE,
then a weight matrix;
current_versioncurrent configuration setting version
pathsettings file path
backup_pathalternative back up path for redundancy checks
datalist of raw configurations, internally used only
subjectRAVESubject instance
read_onlywhether the configuration should be read-only, not yet implemented
versionconfigure version of currently stored files
old_versionwhether settings file is old format
blocksexperiment blocks
electrodeselectrode numbers
sample_ratesvoltage data sample rate
notch_filteredwhether electrodes are notch filtered
has_waveletwhether each electrode has wavelet transforms
data_importedwhether electrodes are imported
data_lockedwhether electrode, blocks and sample rate are locked? usually when an electrode is imported into 'rave', that electrode is locked
electrode_lockedwhether electrode is imported and locked
electrode_composedcomposed electrode channels, not actual physically contacts, but is generated from those physically ones
wavelet_paramswavelet parameters
notch_paramsNotch filter parameters
electrode_typeselectrode signal types
@freeze_blockswhether to free block, internally used
@freeze_lfp_ecogwhether to freeze electrodes that record 'LFP' signals, internally used
@lfp_ecog_sample_rate'LFP' sample rates, internally used
all_blockscharacters, all possible blocks even not included in some projects
raw_pathraw data path
raw_path_typeraw data path type, 'native' or 'bids'
new()
constructor
RAVEPreprocessSettings$new(subject, read_only = TRUE)
subjectcharacter or RAVESubject instance
read_onlywhether subject should be read-only (not yet implemented)
valid()
whether configuration is valid or not
RAVEPreprocessSettings$valid()
has_raw()
whether raw data folder exists
RAVEPreprocessSettings$has_raw()
set_blocks()
set blocks
RAVEPreprocessSettings$set_blocks(blocks, force = FALSE)
blockscharacter, combination of session task and run
forcewhether to ignore checking. Only used when data structure is not native, for example, 'BIDS' format
set_electrodes()
set electrodes
RAVEPreprocessSettings$set_electrodes( electrodes, type = SIGNAL_TYPES, add = FALSE )
electrodesinteger vectors
typesignal type of electrodes, see SIGNAL_TYPES
addwhether to add to current settings
set_sample_rates()
set sample frequency
RAVEPreprocessSettings$set_sample_rates(srate, type = SIGNAL_TYPES)
sratesample rate, must be positive number
typeelectrode type to set sample rate. In 'rave', all electrodes with the same signal type must have the same sample rate.
migrate()
convert old format to new formats
RAVEPreprocessSettings$migrate(force = FALSE)
forcewhether to force migrate and save settings
electrode_info()
get electrode information
RAVEPreprocessSettings$electrode_info(electrode)
electrodeinteger
save()
save settings to hard disk
RAVEPreprocessSettings$save()
get_compose_weights()
get weights of each composed channels
RAVEPreprocessSettings$get_compose_weights(flat = TRUE)
flatwhether to flatten the data frame; default is true
# The following example require downloading demo subject (~700 MB) from # https://github.com/beauchamplab/rave/releases/tag/v0.1.9-beta ## Not run: conf <- RAVEPreprocessSettings$new(subject = 'demo/DemoSubject') conf$blocks # "008" "010" "011" "012" conf$electrodes # 5 electrodes # Electrode 14 information conf$electrode_info(electrode = 14) conf$data_imported # All 5 electrodes are imported conf$data_locked # Whether block, sample rates should be locked ## End(Not run)# The following example require downloading demo subject (~700 MB) from # https://github.com/beauchamplab/rave/releases/tag/v0.1.9-beta ## Not run: conf <- RAVEPreprocessSettings$new(subject = 'demo/DemoSubject') conf$blocks # "008" "010" "011" "012" conf$electrodes # 5 electrodes # Electrode 14 information conf$electrode_info(electrode = 14) conf$data_imported # All 5 electrodes are imported conf$data_locked # Whether block, sample rates should be locked ## End(Not run)
Definition for 'RAVE' project class
Definition for 'RAVE' project class
character vector
true or false whether subject is in the project
A data table of pipeline time-stamps and directories
pathproject folder, absolute path
nameproject name, character
pipeline_pathpath to pipeline scripts under project's folder
print()
override print method
RAVEProject$print(...)
...ignored
new()
constructor
RAVEProject$new(project_name, strict = TRUE)
project_namecharacter
strictwhether to check project path
subjects()
get all imported subjects within project
RAVEProject$subjects()
has_subject()
whether a specific subject exists in this project
RAVEProject$has_subject(subject_code)
subject_codecharacter, subject name
group_path()
get group data path for 'rave' module
RAVEProject$group_path(module_id, must_work = FALSE)
module_idcharacter, 'rave' module ID
must_workwhether the directory must exist; if not exists, should a new one be created?
subject_pipelines()
list saved pipelines
RAVEProject$subject_pipelines( pipeline_name, cache = FALSE, check = TRUE, all = FALSE )
pipeline_namename of the pipeline
cachewhether to use cached registry
checkwhether to check if the pipelines exist as directories
allwhether to list all pipelines; default is false; pipelines with the same label but older time-stamps will be hidden
clone()
The objects of this class are cloneable with this method.
RAVEProject$clone(deep = FALSE)
deepWhether to make a deep clone.
R6 class definition
data frame
integer vector of valid electrodes
The same as value
A named list of key-value pairs, or if one key is specified and
simplify=TRUE, then only the value will be returned.
A data frame with four columns: 'namespace' for the group
name of the entry (entries within the same namespace usually share same
module), 'timestamp' for when the entry was registered.
'entry_name' is the name of the entry. If include_history
is true, then multiple entries with the same 'entry_name' might
appear since the obsolete entries are included. 'entry_value'
is the value of the corresponding entry.
If as_table is FALSE, then returns as
RAVEEpoch instance; otherwise returns epoch table; will
raise errors when file is missing or the epoch is invalid.
If simplify is true, returns a vector of reference
electrode names, otherwise returns the whole table; will
raise errors when file is missing or the reference is invalid.
If simplify is true, returns a vector of electrodes
that are valid (or won't be excluded) under given reference; otherwise
returns a table. If subset is true, then the table will be
subset and only rows with electrodes to be loaded will be kept.
If simplify is true, returns a vector of frequencies;
otherwise returns a table.
A table of pipeline registry
A PipelineTools instance
projectproject instance of current subject; see
RAVEProject
project_namecharacter string of project name
subject_codecharacter string of subject code
subject_idsubject ID: "project/subject"
pathsubject root path
rave_path'rave' directory under subject root path
meta_pathmeta data directory for current subject
imaging_pathroot path to imaging processing folder
freesurfer_path'FreeSurfer' directory for current subject. If
no path exists, values will be NA
preprocess_pathpreprocess directory under subject 'rave' path
data_pathdata directory under subject 'rave' path
cache_pathpath to 'FST' copies under subject 'data' path
pipeline_pathpath to pipeline scripts under subject's folder
note_pathpath that stores 'RAVE' related subject notes
epoch_namespossible epoch names
reference_namespossible reference names
reference_pathreference path under 'rave' folder
preprocess_settingspreprocess instance; see
RAVEPreprocessSettings
blockssubject experiment blocks in current project
electrodesall electrodes, no matter excluded or not
raw_sample_ratesvoltage sample rate
power_sample_ratepower spectrum sample rate
has_waveletwhether electrodes have wavelet transforms
notch_filteredwhether electrodes are Notch-filtered
electrode_typeselectrode signal types
electrode_composedcomposed electrode channels, not actual physically contacts, but is generated from those physically ones
print()
override print method
RAVESubject$print(...)
...ignored
new()
constructor
RAVESubject$new(project_name, subject_code = NULL, strict = TRUE)
project_namecharacter project name
subject_codecharacter subject code
strictwhether to check if subject folders exist
meta_data()
get subject meta data located in "meta/" folder
RAVESubject$meta_data(
meta_type = c("electrodes", "frequencies", "time_points", "epoch", "references"),
meta_name = "default"
)meta_typechoices are 'electrodes', 'frequencies', 'time_points', 'epoch', 'references'
meta_nameif meta_type='epoch', read in
'epoch_<meta_name>.csv'; if meta_type='references',
read in 'reference_<meta_name>.csv'.
valid_electrodes()
get valid electrode numbers
RAVESubject$valid_electrodes(reference_name, refresh = FALSE)
reference_namecharacter, reference name, see meta_name
in self$meta_data or load_meta2 when
meta_type is 'reference'
refreshwhether to reload reference table before obtaining data, default is false
initialize_paths()
create subject's directories on hard disk
RAVESubject$initialize_paths(include_freesurfer = TRUE)
include_freesurferwhether to create 'FreeSurfer' path
set_default()
set default key-value pair for the subject, used by 'RAVE' modules
RAVESubject$set_default(key, value, namespace = "default")
keycharacter
valuevalue of the key
namespacefile name of the note (without post-fix)
get_default()
get default key-value pairs for the subject, used by 'RAVE' modules
RAVESubject$get_default( ..., default_if_missing = NULL, simplify = TRUE, namespace = "default" )
...single key, or a vector of character keys
default_if_missingdefault value is any key is missing
simplifywhether to simplify the results if there is only one key
to fetch; default is TRUE
namespacefile name of the note (without post-fix)
get_note_summary()
get summary table of all the key-value pairs used by 'RAVE' modules for the subject
RAVESubject$get_note_summary(namespaces, include_history = FALSE)
namespacesnamespaces for the entries; see method
get_default or set_default. Default is all possible
namespaces
include_historywhether to include history entries; default is false
get_epoch()
check and get subject's epoch information
RAVESubject$get_epoch(epoch_name, as_table = FALSE, trial_starts = 0)
epoch_nameepoch name, depending on the subject's meta files
as_tablewhether to convert to data.frame; default
is false
trial_startsthe start of the trial relative to epoch time; default is 0
get_reference()
check and get subject's reference information
RAVESubject$get_reference(reference_name, simplify = FALSE)
reference_namereference name, depending on the subject's meta file settings
simplifywhether to only return the reference column
get_electrode_table()
check and get subject's electrode table with electrodes that are load-able
RAVESubject$get_electrode_table( electrodes, reference_name, subset = FALSE, simplify = FALSE )
electrodescharacters indicating integers such as
"1-14,20-30", or integer vector of electrode numbers
reference_namesee method get_reference
subsetwhether to subset the resulting data table
simplifywhether to only return electrodes
get_frequency()
check and get subject's frequency table, time-frequency decomposition is needed.
RAVESubject$get_frequency(simplify = TRUE)
simplifywhether to simplify as vector
list_pipelines()
list saved pipelines
RAVESubject$list_pipelines( pipeline_name, cache = FALSE, check = TRUE, all = FALSE )
pipeline_namepipeline ID
cachewhether to use cache registry to speed up
checkwhether to check if the pipelines exist
allwhether to list all pipelines; default is false; pipelines with the same label but older time-stamps will be hidden
load_pipeline()
load saved pipeline
RAVESubject$load_pipeline(directory)
directorypipeline directory name
clone()
The objects of this class are cloneable with this method.
RAVESubject$clone(deep = FALSE)
deepWhether to make a deep clone.
Resolved some irregular 'iEEG' format where the header could be missing.
read_csv_ieeg(file, nrows = Inf, drop = NULL)read_csv_ieeg(file, nrows = Inf, drop = NULL)
file |
comma separated value file to read from. The file must contains all numerical values |
nrows |
number of rows to read |
drop |
passed to |
The function checks the first two rows of comma separated value file
If the first row has different storage.mode than
the second row, then the first row is considered header, otherwise
header is treated missing. Note file must have at least two
rows.
Wrapper of readEdfHeader, but added
some information
read_edf_header(path)read_edf_header(path)
path |
file path, passed to |
The added names are: isAnnot2, sampleRate2, and
unit2. To avoid conflict with other names, there is a "2" appended
to each names. isAnnot2 indicates whether each channel is annotation
channel or recorded signals. sampleRate2 is a vector of sample rates
for each channels. unit2 is physical unit of recorded signals.
For 'iEEG' data, this is electric potential unit, and choices are 'V'
for volt, 'mV' for millivolt, and 'uV' for micro-volt.
For more details, see https://www.edfplus.info/specs/edftexts.html
A list is header information of an 'EDF/BDF' file.
Read 'EDF(+)' or 'BDF(+)' file signals
read_edf_signal( path, signal_numbers = NULL, convert_volt = c("NA", "V", "mV", "uV") )read_edf_signal( path, signal_numbers = NULL, convert_volt = c("NA", "V", "mV", "uV") )
path |
file path, passed to |
signal_numbers |
channel/electrode numbers |
convert_volt |
convert voltage (electric potential) to a new unit,
|
A list containing header information, signal lists, and
channel/electrode names. If signal_numbers is specified,
the corresponding names should appear as selected_signal_names.
get_signal() can get physical signals after unit conversion.
A compatible reader that can read both 'Matlab' files prior and after version 6.0
read_mat(file, ram = TRUE, engine = c("r", "py")) read_mat2(file, ram = TRUE, engine = c("r", "py"))read_mat(file, ram = TRUE, engine = c("r", "py")) read_mat2(file, ram = TRUE, engine = c("r", "py"))
file |
path to a 'Matlab' file |
ram |
whether to load data into memory. Only available when the file is in 'HDF5' format. Default is false and will load arrays, if set to true, then lazy-load data. This is useful when array is very large. |
engine |
method to read the file, choices are |
io_read_mat can only read 'Matlab' files
prior to version 6. After version 6, 'Matlab' uses 'HDF5' format
to store its data, and read_mat can handle both cases.
The performance of read_mat can be limited when
the file is too big or has many datasets as it reads all the
data contained in 'Matlab' file into memory.
A list of All the data stored in the file
# Matlab .mat <= v7.3 x <- matrix(1:16, 4) f <- tempfile() ieegio::io_write_mat(list(x = x), con = f) read_mat(f) # Matlab .mat >= v7.3, using hdf5 # Make sure you have installed hdf5r if( dipsaus::package_installed('hdf5r') ){ f <- tempfile() save_h5(x, file = f, name = 'x') read_mat(f) # For v7.3, you don't have to load all data into RAM dat <- read_mat(f, ram = FALSE) dat dat$x[] }# Matlab .mat <= v7.3 x <- matrix(1:16, 4) f <- tempfile() ieegio::io_write_mat(list(x = x), con = f) read_mat(f) # Matlab .mat >= v7.3, using hdf5 # Make sure you have installed hdf5r if( dipsaus::package_installed('hdf5r') ){ f <- tempfile() save_h5(x, file = f, name = 'x') read_mat(f) # For v7.3, you don't have to load all data into RAM dat <- read_mat(f, ram = FALSE) dat dat$x[] }
Current implementation supports minimum 2.3 file specification version. Please contact the package maintainer to add specification configurations if you want us to support older versions.
read_nsx_nev( paths, nev_path = NULL, header_only = FALSE, nev_data = TRUE, verbose = TRUE, ram = FALSE, force_update = FALSE, temp_path = file.path(tempdir(), "blackrock-temp") )read_nsx_nev( paths, nev_path = NULL, header_only = FALSE, nev_data = TRUE, verbose = TRUE, ram = FALSE, force_update = FALSE, temp_path = file.path(tempdir(), "blackrock-temp") )
paths |
'NSx' signal files, usually with file extensions such as
|
nev_path |
'NEV' event files, with file extension |
header_only |
whether to load header information only and avoid reading signal arrays |
nev_data |
whether to load |
verbose |
whether to print out progress when loading signal array |
ram |
whether to load signals into the memory rather than storing
with |
force_update |
force updating the channel data even if the headers haven't changed |
temp_path |
temporary directory to store the channel data |
Read in 'eeg' or 'ieeg' data from 'BrainVision'
files with .eeg or .dat extensions.
read_eeg_header(file) read_eeg_marker(file) read_eeg_data(header, path = NULL)read_eeg_header(file) read_eeg_marker(file) read_eeg_data(header, path = NULL)
file |
path to |
header |
header object returned by |
path |
optional, path to data file if original data file is missing or renamed; must be absolute path. |
A 'BrainVision' dataset is usually stored separately in header
file (.vhdr), marker file (.vmrk, optional) and
data file (.eeg or .dat). These files must store under a
same folder to be read into R.
Header data contains channel information. Data "channel" contains
channel name, reference, resolution and physical unit. "resolution"
times digital data values is the physical value of the recorded data.
read_eeg_data makes this conversion internally .
"unit" is the physical unit of recordings. By default 'uV' means
micro-volts.
Marker file that ends with .vmrk is optional. If the file is
indicated by header file and exists, then a marker table will be included
when reading headers. A marker table contains six columns: marker number,
type, description, start position (in data point), size (duration in
data points), and target channel (0 means applied for all channels).
Signal file name is usually contained within header file. Therefore it is
desired that the signal file name never changed once created. However,
in some cases when the signal files are renamed and cannot be indexed
by header files, please specify path to force load signals from
a different file.
read_eeg_header returns a list containing information below:
raw |
raw header contents |
common |
a list of descriptors of header |
channels |
table of channels, including number, reference, resolution and unit |
sample_rate |
sampling frequency |
root_path |
directory to where the data is stored |
channel_counts |
total channel counts |
markers |
|
read_eeg_data returns header, signal data and data description:
data |
a matrix of signal values. Each row is a channel and each column is a time point. |
header_file <- 'sub-01_ses-01_task-visual_run-01_ieeg.vhdr' if( file.exists(header_file) ){ # load a subject header header <- read_eeg_header(header_file) # load entire signal data <- read_eeg_data(header) data$description }header_file <- 'sub-01_ses-01_task-visual_run-01_ieeg.vhdr' if( file.exists(header_file) ){ # load a subject header header <- read_eeg_header(header_file) # load entire signal data <- read_eeg_data(header) data$description }
Read a 'fst' file
save_fst(x, path, ...) load_fst(path, ..., as.data.table = TRUE)save_fst(x, path, ...) load_fst(path, ..., as.data.table = TRUE)
x |
data frame to write to path |
path |
path to 'fst' file: must not be connection. |
... |
passed to |
as.data.table |
passed to |
Read comma separated value files with given column classes
safe_read_csv( file, header = TRUE, sep = ",", colClasses = NA, skip = 0, quote = "\"", ..., stringsAsFactors = FALSE )safe_read_csv( file, header = TRUE, sep = ",", colClasses = NA, skip = 0, quote = "\"", ..., stringsAsFactors = FALSE )
file, header, sep, colClasses, skip, quote, stringsAsFactors, ...
|
passed to |
Reading a comma separated value file using builtin function
read.csv might result in some unexpected
behavior. safe_read_csv does some preprocessing on the
format so that it take cares of the following cases.
1. If skip exceeds the maximum rows of the data, return
a blank data frame instead of raising error.
2. If row names are included in the file, colClasses
automatically skip that column and starts from the second column
3. If length of colClasses does not equal to the number of
columns, instead of cycling the class types, we set those columns
to be NA type and let read.csv decide
the default types.
4. stringsAsFactors is by default FALSE to be
consistent with R 4.0, if the function is called in R 3.x.
A data frame
f <- tempfile() x <- data.frame(a = letters[1:10], b = 1:10, c = 2:11) # ------------------ Auto-detect row names ------------------ # Write with rownames utils::write.csv(x, f, row.names = LETTERS[2:11]) # read csv with base library utils table1 <- utils::read.csv(f, colClasses = c('character', 'character')) # 4 columns including row names str(table1) # read csv via safe_read_csv table2 <- safe_read_csv(f, colClasses = c('character', 'character')) # row names are automatically detected, hence 3 columns # Only first columns are characters, the third column is auto # detected as numeric str(table2) # read table without row names utils::write.csv(x, f, row.names = FALSE) table2 <- safe_read_csv(f, colClasses = c('character', 'character')) # still 3 columns, and row names are 1:nrow str(table2) # --------------- Blank data frame when nrow too large --------------- # instead of raising errors, return blank data frame safe_read_csv(f, skip = 1000)f <- tempfile() x <- data.frame(a = letters[1:10], b = 1:10, c = 2:11) # ------------------ Auto-detect row names ------------------ # Write with rownames utils::write.csv(x, f, row.names = LETTERS[2:11]) # read csv with base library utils table1 <- utils::read.csv(f, colClasses = c('character', 'character')) # 4 columns including row names str(table1) # read csv via safe_read_csv table2 <- safe_read_csv(f, colClasses = c('character', 'character')) # row names are automatically detected, hence 3 columns # Only first columns are characters, the third column is auto # detected as numeric str(table2) # read table without row names utils::write.csv(x, f, row.names = FALSE) table2 <- safe_read_csv(f, colClasses = c('character', 'character')) # still 3 columns, and row names are 1:nrow str(table2) # --------------- Blank data frame when nrow too large --------------- # instead of raising errors, return blank data frame safe_read_csv(f, skip = 1000)
Save comma separated value files, if file exists, backup original file.
safe_write_csv(x, file, ..., quiet = FALSE)safe_write_csv(x, file, ..., quiet = FALSE)
x, file, ...
|
pass to |
quiet |
whether to suppress overwrite message |
Normalized path of file
f <- tempfile() x <- data.frame(a = 1:10) # File not exists, same as write file, returns normalized `f` safe_write_csv(x, f) # Check whether file exists file.exists(f) # write again, and the old file will be copied safe_write_csv(x, f)f <- tempfile() x <- data.frame(a = 1:10) # File not exists, same as write file, returns normalized `f` safe_write_csv(x, f) # Check whether file exists file.exists(f) # write again, and the old file will be copied safe_write_csv(x, f)
Save objects to 'HDF5' file without trivial checks
save_h5( x, file, name, chunk = "auto", level = 4, replace = TRUE, new_file = FALSE, ctype = NULL, quiet = FALSE, ... )save_h5( x, file, name, chunk = "auto", level = 4, replace = TRUE, new_file = FALSE, ctype = NULL, quiet = FALSE, ... )
x |
an array, a matrix, or a vector |
file |
path to 'HDF5' file |
name |
path/name of the data; for example, |
chunk |
chunk size |
level |
compress level from 0 - no compression to 10 - max compression |
replace |
should data be replaced if exists |
new_file |
should removing the file if old one exists |
ctype |
data type such as "character", "integer", or "numeric". If
set to |
quiet |
whether to suppress messages, default is false |
... |
passed to other |
Absolute path of the file saved
file <- tempfile() x <- array(1:120, dim = 2:5) # save x to file with name /group/dataset/1 save_h5(x, file, '/group/dataset/1', chunk = dim(x)) # read data y <- load_h5(file, '/group/dataset/1') y[]file <- tempfile() x <- array(1:120, dim = 2:5) # save x to file with name /group/dataset/1 save_h5(x, file, '/group/dataset/1', chunk = dim(x)) # read data y <- load_h5(file, '/group/dataset/1') y[]
Save or load R object in 'JSON' format
save_json( x, con = stdout(), ..., digits = ceiling(-log10(.Machine$double.eps)), pretty = TRUE, serialize = TRUE ) load_json(con, ..., map = NULL)save_json( x, con = stdout(), ..., digits = ceiling(-log10(.Machine$double.eps)), pretty = TRUE, serialize = TRUE ) load_json(con, ..., map = NULL)
x |
R object to save |
con |
file or connection |
... |
|
digits |
number of digits to save |
pretty |
whether the output should be pretty |
serialize |
whether to save a serialized version of |
map |
a map to save the results |
save_json returns nothing; load_json returns an
R object.
# Serialize save_json(list(a = 1, b = function(){})) # use toJSON save_json(list(a = 1, b = function(){}), serialize = FALSE) # Demo of using serializer f1 <- tempfile(fileext = ".json") save_json(x ~ y + 1, f1) load_json(f1) unlink(f1)# Serialize save_json(list(a = 1, b = function(){})) # use toJSON save_json(list(a = 1, b = function(){}), serialize = FALSE) # Demo of using serializer f1 <- tempfile(fileext = ".json") save_json(x ~ y + 1, f1) load_json(f1) unlink(f1)
Function to save meta data to 'RAVE' subject
save_meta2(data, meta_type, project_name, subject_code)save_meta2(data, meta_type, project_name, subject_code)
data |
data table |
meta_type |
see load meta |
project_name |
project name |
subject_code |
subject code |
Either none if no meta matched or the absolute path of file saved.
Write named list to file
save_yaml(x, file, ..., sorted = FALSE)save_yaml(x, file, ..., sorted = FALSE)
x |
a named list, |
file, ...
|
passed to |
sorted |
whether to sort the results by name; default is false |
Normalized file path
fastmap2, load_yaml,
read_yaml, write_yaml
x <- list(a = 1, b = 2) f <- tempfile() save_yaml(x, f) load_yaml(f) map <- dipsaus::fastmap2(missing_default = NA) map$c <- 'lol' load_yaml(f, map = map) map$a map$dx <- list(a = 1, b = 2) f <- tempfile() save_yaml(x, f) load_yaml(f) map <- dipsaus::fastmap2(missing_default = NA) map$c <- 'lol' load_yaml(f, map = map) map$a map$d
Class definition for micro-wire spike channels
Class definition for micro-wire spike channels
If simplify is enabled, and only one block is loaded,
then the result will be a vector (type="voltage") or a matrix
(others), otherwise the result will be a named list where the names
are the blocks.
raveio::RAVEAbstarctElectrode -> Spike_electrode
h5_fname'HDF5' file name
validwhether current electrode is valid: subject exists and contains current electrode or reference; subject electrode type matches with current electrode type
raw_sample_ratevoltage sample rate
power_sample_ratepower/phase sample rate
preprocess_infopreprocess information
voltage_filepath to voltage 'HDF5' file
print()
print electrode summary
Spike_electrode$print()
set_reference()
set reference for current electrode
Spike_electrode$set_reference(reference)
referenceeither NULL or LFP_electrode instance
new()
constructor
Spike_electrode$new(subject, number, quiet = FALSE)
subject, number, quietsee constructor in
RAVEAbstarctElectrode
.load_noref_voltage()
load non-referenced voltage (internally used)
Spike_electrode$.load_noref_voltage(reload = FALSE)
reloadwhether to reload cache
sratevoltage signal sample rate
.load_raw_voltage()
load raw voltage (no process)
Spike_electrode$.load_raw_voltage(reload = FALSE)
reloadwhether to reload cache
load_data()
method to load electrode data
Spike_electrode$load_data(type = c("raw-voltage", "voltage"))typedata type such as "power", "phase",
"voltage", "wavelet-coefficient", and
"raw-voltage". For "power", "phase",
and "wavelet-coefficient", 'Wavelet' transforms are required.
For "voltage", 'Notch' filters must be applied. All these
types except for "raw-voltage" will be referenced.
For "raw-voltage", no reference will be performed since the data
will be the "raw" signal (no processing).
load_blocks()
load electrode block-wise data (with no reference), useful when epoch is absent
Spike_electrode$load_blocks(
blocks,
type = c("raw-voltage", "voltage"),
simplify = TRUE
)blockssession blocks
typedata type such as "power", "phase",
"voltage", "raw-voltage" (with no filters applied, as-is
from imported), "wavelet-coefficient". Note that if type
is "raw-voltage", then the data only needs to be imported;
for "voltage" data, 'Notch' filters must be applied; for
all other types, 'Wavelet' transforms are required.
simplifywhether to simplify the result
clear_cache()
method to clear cache on hard drive
Spike_electrode$clear_cache(...)
...ignored
clear_memory()
method to clear memory
Spike_electrode$clear_memory(...)
...ignored
clone()
The objects of this class are cloneable with this method.
Spike_electrode$clone(deep = FALSE)
deepWhether to make a deep clone.
can store on hard drive, and read slices of GB-level data in seconds
self
the sliced data
a data frame with the dimension names as index columns and
value_name as value column
original array
the collapsed data
dimdimension of the array
dimnamesdimension names of the array
use_indexwhether to use one dimension as index when storing data as multiple files
hybridwhether to allow data to be written to disk
last_usedtimestamp of the object was read
temporarywhether to remove the files once garbage collected
varnamesdimension names (read-only)
read_onlywhether to protect the swap files from being changed
swap_filefile or files to save data to
do_finalize()
release resource and remove files for temporary instances
Tensor$do_finalize()
print()
print out the data dimensions and snapshot
Tensor$print(...)
...ignored
.use_multi_files()
Internally used, whether to use multiple files to cache data instead of one
Tensor$.use_multi_files(mult)
multlogical
new()
constructor
Tensor$new( data, dim, dimnames, varnames, hybrid = FALSE, use_index = FALSE, swap_file = temp_tensor_file(), temporary = TRUE, multi_files = FALSE )
datanumeric array
dimdimension of the array
dimnamesdimension names of the array
varnamescharacters, names of dimnames
hybridwhether to enable hybrid mode
use_indexwhether to use the last dimension for indexing
swap_filewhere to store the data in hybrid mode
files to save data by index; default stores in
raveio_getopt('tensor_temp_path')
temporarywhether to remove temporary files when existing
multi_filesif use_index is true, whether to use multiple
subset()
subset tensor
Tensor$subset(..., drop = FALSE, data_only = FALSE, .env = parent.frame())
...dimension slices
dropwhether to apply drop on subset data
data_onlywhether just return the data value, or wrap them as a
Tensor instance
.envenvironment where ... is evaluated
flatten()
converts tensor (array) to a table (data frame)
Tensor$flatten(include_index = FALSE, value_name = "value")
include_indexlogical, whether to include dimension names
value_namecharacter, column name of the value
to_swap()
Serialize tensor to a file and store it via
write_fst
Tensor$to_swap(use_index = FALSE, delay = 0)
use_indexwhether to use one of the dimension as index for faster loading
delayif greater than 0, then check when last used, if not long
ago, then do not swap to hard drive. If the difference of time is
greater than delay in seconds, then swap immediately.
to_swap_now()
Serialize tensor to a file and store it via
write_fst immediately
Tensor$to_swap_now(use_index = FALSE)
use_indexwhether to use one of the dimension as index for faster loading
get_data()
restore data from hard drive to memory
Tensor$get_data(drop = FALSE, gc_delay = 3)
dropwhether to apply drop to the data
gc_delayseconds to delay the garbage collection
set_data()
set/replace data with given array
Tensor$set_data(v)
vthe value to replace the old one, must have the same dimension
noticethe a tensor is an environment. If you change at one place, the data from all other places will change. So use it carefully.
collapse()
apply mean, sum, or median to collapse data
Tensor$collapse(keep, method = "mean")
keepwhich dimensions to keep
method"mean", "sum", or "median"
operate()
apply the tensor by anything along given dimension
Tensor$operate(
by,
fun = .Primitive("/"),
match_dim,
mem_optimize = FALSE,
same_dimension = FALSE
)byR object
funfunction to apply
match_dimwhich dimensions to match with the data
mem_optimizeoptimize memory
same_dimensionwhether the return value has the same dimension as the original instance
if(!is_on_cran()){ # Create a tensor ts <- Tensor$new( data = 1:18000000, c(3000,300,20), dimnames = list(A = 1:3000, B = 1:300, C = 1:20), varnames = c('A', 'B', 'C')) # Size of tensor when in memory is usually large # `lobstr::obj_size(ts)` -> 8.02 MB # Enable hybrid mode ts$to_swap_now() # Hybrid mode, usually less than 1 MB # `lobstr::obj_size(ts)` -> 814 kB # Subset data start1 <- Sys.time() subset(ts, C ~ C < 10 & C > 5, A ~ A < 10) #> Dimension: 9 x 300 x 4 #> - A: 1, 2, 3, 4, 5, 6,... #> - B: 1, 2, 3, 4, 5, 6,... #> - C: 6, 7, 8, 9 end1 <- Sys.time(); end1 - start1 #> Time difference of 0.188035 secs # Join tensors ts <- lapply(1:20, function(ii){ Tensor$new( data = 1:9000, c(30,300,1), dimnames = list(A = 1:30, B = 1:300, C = ii), varnames = c('A', 'B', 'C'), use_index = 2) }) ts <- join_tensors(ts, temporary = TRUE) }if(!is_on_cran()){ # Create a tensor ts <- Tensor$new( data = 1:18000000, c(3000,300,20), dimnames = list(A = 1:3000, B = 1:300, C = 1:20), varnames = c('A', 'B', 'C')) # Size of tensor when in memory is usually large # `lobstr::obj_size(ts)` -> 8.02 MB # Enable hybrid mode ts$to_swap_now() # Hybrid mode, usually less than 1 MB # `lobstr::obj_size(ts)` -> 814 kB # Subset data start1 <- Sys.time() subset(ts, C ~ C < 10 & C > 5, A ~ A < 10) #> Dimension: 9 x 300 x 4 #> - A: 1, 2, 3, 4, 5, 6,... #> - B: 1, 2, 3, 4, 5, 6,... #> - C: 6, 7, 8, 9 end1 <- Sys.time(); end1 - start1 #> Time difference of 0.188035 secs # Join tensors ts <- lapply(1:20, function(ii){ Tensor$new( data = 1:9000, c(30,300,1), dimnames = list(A = 1:30, B = 1:300, C = ii), varnames = c('A', 'B', 'C'), use_index = 2) }) ts <- join_tensors(ts, temporary = TRUE) }
Simple hard disk speed test
test_hdspeed( path = tempdir(), file_size = 1e+06, quiet = FALSE, abort_if_slow = TRUE, use_cache = FALSE )test_hdspeed( path = tempdir(), file_size = 1e+06, quiet = FALSE, abort_if_slow = TRUE, use_cache = FALSE )
path |
an existing directory where to test speed, default is temporary local directory. |
file_size |
in bytes, default is 1 MB. |
quiet |
should verbose messages be suppressed? |
abort_if_slow |
abort test if hard drive is too slow. This usually happens when the hard drive is connected via slow internet: if the write speed is less than 0.1 MB per second. |
use_cache |
if hard drive speed was tested before, abort testing and return cached results or not; default is false. |
A vector of two: writing and reading speed in MB per seconds.
Calculate time difference in seconds
time_diff2(start, end, units = "secs", label = "")time_diff2(start, end, units = "secs", label = "")
start, end
|
start and end of timer |
units |
passed to |
label |
|
A number inherits rave-units class.
start <- Sys.time() Sys.sleep(0.1) end <- Sys.time() dif <- time_diff2(start, end, label = 'Running ') print(dif, digits = 4) is.numeric(dif) dif + 1start <- Sys.time() Sys.sleep(0.1) end <- Sys.time() dif <- time_diff2(start, end, label = 'Running ') print(dif, digits = 4) is.numeric(dif) dif + 1
Calculate template 'MNI' coordinates for points on native brain
transform_point_to_template( subject, positions, space = c("scannerRAS", "tkrRAS"), mapping_method = c("volumetric", "surface"), flip_hemisphere = FALSE, verbose = TRUE, project_surface = "pial", volumetric_transform = c("auto", "affine", "nonlinear"), ... ) transform_thinfilm_to_mni152( subject, flip_hemisphere = FALSE, interpolator = 0.3, n_segments = c(16, 16), group_labels = NULL, project_surface = "pial", volumetric_transform = c("auto", "affine", "nonlinear"), template_subject = c("cvs_avg35_inMNI152", "fsaverage", "bert", "MNI152") )transform_point_to_template( subject, positions, space = c("scannerRAS", "tkrRAS"), mapping_method = c("volumetric", "surface"), flip_hemisphere = FALSE, verbose = TRUE, project_surface = "pial", volumetric_transform = c("auto", "affine", "nonlinear"), ... ) transform_thinfilm_to_mni152( subject, flip_hemisphere = FALSE, interpolator = 0.3, n_segments = c(16, 16), group_labels = NULL, project_surface = "pial", volumetric_transform = c("auto", "affine", "nonlinear"), template_subject = c("cvs_avg35_inMNI152", "fsaverage", "bert", "MNI152") )
subject |
'RAVE' subject |
positions |
optional matrix of 3 columns, either in scanner or surface
space (specified by |
space |
if |
mapping_method |
whether the mapping is |
flip_hemisphere |
whether to flip the hemisphere; default is
|
verbose |
whether to verbose the mapping progress; default is true |
project_surface |
for surface mapping only, which surface to project
electrodes onto; default is |
volumetric_transform |
for volume mapping only, which type of transform
to use; default is |
... |
ignored |
interpolator |
whether the transform lean towards volume mapping
( |
n_segments |
positive integers with length of two: resolution of the mapping; default segments the thin-film array into 16 by 16 segments |
group_labels |
|
template_subject |
template subject to be mapped to; default is
|
A table of electrode 'MNI' coordinates.
if(interactive()) { transform_point_to_template('demo/DemoSubject', mapping_method = "volumetric") }if(interactive()) { transform_point_to_template('demo/DemoSubject', mapping_method = "volumetric") }
Get 'Neurosynth' website address using 'MNI152' coordinates
url_neurosynth(x, y, z)url_neurosynth(x, y, z)
x, y, z
|
numerical values: the right-anterior-superior 'RAS'
coordinates in |
'Neurosynth' website address
Check against existence, validity, and consistency
subject |
subject ID (character), or |
method |
validation method, choices are |
verbose |
whether to print out the validation messages |
version |
data version, choices are |
A list of nested validation results. The validation process consists of the following parts in order:
paths)paththe subject's root folder
paththe subject's 'RAVE' folder (the 'rave' folder under the root directory)
raw_paththe subject's raw data folder
data_patha directory storing all the voltage, power, phase data (before reference)
meta_pathmeta directory containing all the electrode coordinates, reference table, epoch information, etc.
reference_patha directory storing calculated reference signals
preprocess_patha directory storing all the preprocessing information
cache_path (low priority)data caching path
freesurfer_path (low priority)subject's 'FreeSurfer' directory
note_path (low priority)subject's notes
pipeline_path (low priority)a folder containing all saved pipelines for this subject
preprocess)electrodes_setwhether the subject has a non-empty electrode set
blocks_setwhether the session block length is non-zero
sample_rate_setwhether the raw sampling frequency is set to a valid, proper positive number
data_importedwhether all the assigning electrodes have been imported
notch_filteredwhether all the 'LFP' and 'EKG' signals have been 'Notch' filtered
has_waveletwhether all the 'LFP' signals are wavelet-transformed
has_referenceat least one reference has been generated in the meta folder
has_epochat least one epoch file has been generated in the meta folder
has_electrode_filemeta folder has electrodes.csv file
meta)meta_data_validthis item only exists when the previous preprocess validation is failed or incomplete
meta_electrode_tablethe electrodes.csv file in the meta folder has correct format and consistent electrodes numbers to the preprocess information
meta_reference_xxx(xxx will be replaced with actual reference names) checks whether the reference table contains all electrodes and whether each reference data exists
meta_epoch_xxx(xxx will be replaced with actual epoch names) checks whether the epoch table has the correct formats and whether there are missing blocks indicated in the epoch files
voltage_data*)voltage_preprocessingwhether the raw preprocessing voltage data are valid. This includes data lengths are the same within the same blocks for each signal type
voltage_datawhether the voltage data (after 'Notch' filters) exist and readable. Besides, the lengths of the data must be consistent with the raw signals
power_phase_data*)power_datawhether the power data exists for all 'LFP' signals. Besides, to pass the validation process, the frequency and time-point lengths must be consistent with the preprocess record
power_datasame as power_data but for the phase data
epoch_tables*)One or more sub-items depending on the number of epoch tables. To pass the validation, the event time for each session block must not exceed the actual signal duration. For example, if one session lasts for 200 seconds, it will invalidate the result if a trial onset time is later than 200 seconds.
reference_tables*)One or more sub-items depending on the number of reference tables. To pass the validation, the reference data must be valid. The inconsistencies, for example, missing file, wrong frequency size, invalid time-point lengths will result in failure
Make sure the time windows are valid intervals and returns a reshaped window list
validate_time_window(time_windows)validate_time_window(time_windows)
time_windows |
vectors or a list of time intervals |
A list of time intervals (ordered, length of 2)
# Simple time window validate_time_window(c(-1, 2)) # Multiple windows validate_time_window(c(-1, 2, 3, 5)) # alternatively validate_time_window(list(c(-1, 2), c(3, 5))) validate_time_window(list(list(-1, 2), list(3, 5))) ## Not run: # Incorrect usage (will raise errors) # Invalid interval (length must be two for each intervals) validate_time_window(list(c(-1, 2, 3, 5))) # Time intervals must be in ascending order validate_time_window(c(2, 1)) ## End(Not run)# Simple time window validate_time_window(c(-1, 2)) # Multiple windows validate_time_window(c(-1, 2, 3, 5)) # alternatively validate_time_window(list(c(-1, 2), c(3, 5))) validate_time_window(list(list(-1, 2), list(3, 5))) ## Not run: # Incorrect usage (will raise errors) # Invalid interval (length must be two for each intervals) validate_time_window(list(c(-1, 2, 3, 5))) # Time intervals must be in ascending order validate_time_window(c(2, 1)) ## End(Not run)
Calculate voltage baseline
voltage_baseline( x, baseline_windows, method = c("percentage", "zscore", "subtract_mean"), units = c("Trial", "Electrode"), ... ) ## S3 method for class 'rave_prepare_subject_raw_voltage_with_epoch' voltage_baseline( x, baseline_windows, method = c("percentage", "zscore", "subtract_mean"), units = c("Trial", "Electrode"), electrodes, baseline_mean, baseline_sd, ... ) ## S3 method for class 'rave_prepare_subject_voltage_with_epoch' voltage_baseline( x, baseline_windows, method = c("percentage", "zscore", "subtract_mean"), units = c("Trial", "Electrode"), electrodes, baseline_mean, baseline_sd, ... ) ## S3 method for class 'FileArray' voltage_baseline( x, baseline_windows, method = c("percentage", "zscore", "subtract_mean"), units = c("Trial", "Electrode"), filebase = NULL, ... ) ## S3 method for class 'array' voltage_baseline( x, baseline_windows, method = c("percentage", "zscore", "subtract_mean"), units = c("Trial", "Electrode"), ... )voltage_baseline( x, baseline_windows, method = c("percentage", "zscore", "subtract_mean"), units = c("Trial", "Electrode"), ... ) ## S3 method for class 'rave_prepare_subject_raw_voltage_with_epoch' voltage_baseline( x, baseline_windows, method = c("percentage", "zscore", "subtract_mean"), units = c("Trial", "Electrode"), electrodes, baseline_mean, baseline_sd, ... ) ## S3 method for class 'rave_prepare_subject_voltage_with_epoch' voltage_baseline( x, baseline_windows, method = c("percentage", "zscore", "subtract_mean"), units = c("Trial", "Electrode"), electrodes, baseline_mean, baseline_sd, ... ) ## S3 method for class 'FileArray' voltage_baseline( x, baseline_windows, method = c("percentage", "zscore", "subtract_mean"), units = c("Trial", "Electrode"), filebase = NULL, ... ) ## S3 method for class 'array' voltage_baseline( x, baseline_windows, method = c("percentage", "zscore", "subtract_mean"), units = c("Trial", "Electrode"), ... )
x |
R array, |
baseline_windows |
list of baseline window (intervals) |
method |
baseline method; choices are |
units |
the unit of the baseline; see 'Details' |
... |
passed to other methods |
electrodes |
the electrodes to be included in baseline calculation;
for power repository object produced by |
baseline_mean, baseline_sd
|
internally used by 'RAVE' repository, provided baseline is not contained in the data. This is useful for calculating the baseline with data from other blocks. |
filebase |
where to store the output; default is |
The arrays must be three-mode tensor and must have valid named
dimnames. The dimension names must be 'Trial',
'Time', 'Electrode', case sensitive.
The baseline_windows determines the baseline windows that are used to
calculate time-points of baseline to be included. This can be one
or more intervals and must pass the validation function
validate_time_window.
The units determines the unit of the baseline. It can be either or
both of 'Trial', 'Electrode'. The default
value is both, i.e., baseline for each combination of trial and electrode.
The same type as the inputs
## Not run: # The following code need to download additional demo data # Please see https://rave.wiki/ for more details library(raveio) repo <- prepare_subject_raw_voltage_with_epoch( subject = "demo/DemoSubject", time_windows = c(-1, 3), electrodes = c(14, 15)) ##### Direct baseline on repository voltage_baseline( x = repo, method = "zscore", baseline_windows = list(c(-1, 0), c(2, 3)) ) voltage_mean <- repo$raw_voltage$baselined$collapse( keep = c(1,3), method = "mean") matplot(voltage_mean, type = "l", lty = 1, x = repo$raw_voltage$dimnames$Time, xlab = "Time (s)", ylab = "Voltage (z-scored)", main = "Mean coltage over trial (Baseline: -1~0 & 2~3)") abline(v = 0, lty = 2, col = 'darkgreen') text(x = 0, y = -0.5, "Aud-Onset ", col = "darkgreen", cex = 0.6, adj = c(1,1)) ##### Alternatively, baseline on each electrode channel voltage_mean2 <- sapply(repo$raw_voltage$data_list, function(inst) { re <- voltage_baseline( x = inst, method = "zscore", baseline_windows = list(c(-1, 0), c(2, 3))) rowMeans(re[]) }) # Same with floating difference max(abs(voltage_mean - voltage_mean2)) < 1e-8 ## End(Not run)## Not run: # The following code need to download additional demo data # Please see https://rave.wiki/ for more details library(raveio) repo <- prepare_subject_raw_voltage_with_epoch( subject = "demo/DemoSubject", time_windows = c(-1, 3), electrodes = c(14, 15)) ##### Direct baseline on repository voltage_baseline( x = repo, method = "zscore", baseline_windows = list(c(-1, 0), c(2, 3)) ) voltage_mean <- repo$raw_voltage$baselined$collapse( keep = c(1,3), method = "mean") matplot(voltage_mean, type = "l", lty = 1, x = repo$raw_voltage$dimnames$Time, xlab = "Time (s)", ylab = "Voltage (z-scored)", main = "Mean coltage over trial (Baseline: -1~0 & 2~3)") abline(v = 0, lty = 2, col = 'darkgreen') text(x = 0, y = -0.5, "Aud-Onset ", col = "darkgreen", cex = 0.6, adj = c(1,1)) ##### Alternatively, baseline on each electrode channel voltage_mean2 <- sapply(repo$raw_voltage$data_list, function(inst) { re <- voltage_baseline( x = inst, method = "zscore", baseline_windows = list(c(-1, 0), c(2, 3))) rowMeans(re[]) }) # Same with floating difference max(abs(voltage_mean - voltage_mean2)) < 1e-8 ## End(Not run)
Enable parallel computing provided by 'future' package within the context
with_future_parallel( expr, env = parent.frame(), quoted = FALSE, on_failure = "multisession", max_workers = NA, ... )with_future_parallel( expr, env = parent.frame(), quoted = FALSE, on_failure = "multisession", max_workers = NA, ... )
expr |
the expression to be evaluated |
env |
environment of the |
quoted |
whether |
on_failure |
alternative 'future' plan to use if forking a process is disallowed; this usually occurs on 'Windows' machines; see details. |
max_workers |
maximum of workers; default is automatically set by
|
... |
additional parameters passing into
|
Some 'RAVE' functions such as prepare_subject_power
support parallel computing to speed up. However, the parallel computing is
optional. You can enable it by wrapping the function calls within
with_future_parallel (see examples).
The default plan is to use 'forked' R sessions. This is a convenient, fast,
and relative simple way to create multiple R processes that share the same
memories. However, on some machines such as 'Windows' the support has not
yet been implemented. In such cases, the plan fall backs to a back-up
specified by on_failure. By default, on_failure is
'multisession', a heavier implementation than forking the process, and
slightly longer ramp-up time.
However, the difference should be marginal for most of the functions.
When parallel computing is enabled, the number of parallel workers is
specified by the option raveio_getopt("max_worker", 1L).
The evaluation results of expr
library(raveio) demo_subject <- as_rave_subject("demo/DemoSubject", strict = FALSE) if(dir.exists(demo_subject$path)) { with_future_parallel({ prepare_subject_power("demo/DemoSubject") }) }library(raveio) demo_subject <- as_rave_subject("demo/DemoSubject", strict = FALSE) if(dir.exists(demo_subject$path)) { with_future_parallel({ prepare_subject_power("demo/DemoSubject") }) }
'YAEL' image pipelineRigid-registration across multiple types of images, non-linear normalization
from native brain to common templates, and map template atlas or 'ROI' back
to native brain. See examples at as_yael_process
whether the image has been set (or replaced)
Absolute path if the image
'RAVE' subject instance
Nothing
A list of moving and fixing images, with rigid transformations from different formats.
See method get_template_mapping
A list of input, output images, with forward and inverse
transform files (usually two 'Affine' with one displacement field)
transformed image in 'ANTs' format
transformed image in 'ANTs' format
Nothing
A matrix of 3 columns, each row is a transformed points (
invalid rows will be filled with NA)
A matrix of 3 columns, each row is a transformed points (
invalid rows will be filled with NA)
subject_code'RAVE' subject code
image_typesallowed image types
work_pathWorking directory ('RAVE' imaging path)
new()
Constructor to instantiate the class
YAELProcess$new(subject_code, image_types)
subject_codecharacter code representing the subject
image_typesvector of image types, such as 'T1w',
'CT', 'fGATIR'. All images except 'CT' will be
considered 'preop' (before electrode implantation). Please
use 'postop' to indicate if an image is taken after the
implantation (for example, 'postopT1w')
set_input_image()
Set the raw input for different image types
YAELProcess$set_input_image(
path,
type = YAEL_IMAGE_TYPES,
overwrite = FALSE,
on_error = c("warning", "error", "ignore")
)pathpath to the image files in 'NIfTI' format
typetype of the image
overwritewhether to overwrite existing images if the same type has been imported before; default is false
on_errorwhen the file exists and overwrite is false,
how should this error be reported; choices are 'warning' (default),
'error' (throw error and abort), or 'ignore'.
get_input_image()
Get image path
YAELProcess$get_input_image(type = YAEL_IMAGE_TYPES)
typetype of the image
get_subject()
Get 'RAVE' subject instance
YAELProcess$get_subject(project_name = "YAEL", strict = FALSE)
project_nameproject name; default is 'YAEL'
strictpassed to as_rave_subject
register_to_T1w()
Register other images to 'T1' weighted 'MRI'
YAELProcess$register_to_T1w(image_type = "CT", reverse = FALSE, verbose = TRUE)
image_typetype of the image to register, must be set via
process$set_input_image first.
reversewhether to reverse the registration; default is false,
meaning the fixed (reference) image is the 'T1'. When setting to
true, then the 'T1' 'MRI' will become the moving image
verbosewhether to print out the process; default is true
get_native_mapping()
Get the mapping configurations used by register_to_T1w
YAELProcess$get_native_mapping(image_type = YAEL_IMAGE_TYPES, relative = FALSE)
image_typetype of the image registered to 'T1' weighted 'MRI'
relativewhether to use relative path (to the work_path field)
map_to_template()
Normalize native brain to 'MNI152' template
YAELProcess$map_to_template(
template_name = rpyants_builtin_templates(),
use_images = c("T1w", "T2w", "T1wContrast", "fGATIR", "preopCT"),
native_type = "T1w",
verbose = TRUE,
...
)template_namewhich template to use, choices are
'mni_icbm152_nlin_asym_09a', 'mni_icbm152_nlin_asym_09b',
'mni_icbm152_nlin_asym_09c', and 'fsaverage'.
use_imagesa vector of image types to use for normalization;
default types are 'T1w', 'T2w', 'T1wContrast',
'fGATIR', and 'preopCT'. To use all available images
for normalization, use wildcard "all"
native_typewhich type of image should be used to map to template;
default is 'T1w'
verbosewhether to print out the process; default is true
...additional tuning parameters passed to internal 'Python' code.
get_template_mapping()
Get configurations used for normalization
YAELProcess$get_template_mapping( template_name = rpyants_builtin_templates(), native_type = "T1w", relative = FALSE )
template_namewhich template is used
native_typewhich native image is mapped to template
relativewhether the paths should be relative or absolute; default is false (absolute paths)
transform_image_from_template()
Apply transform from images (usually an atlas or 'ROI') on template to native space
YAELProcess$transform_image_from_template(
template_roi_path,
template_name = rpyants_builtin_templates(),
native_type = "T1w",
interpolator = c("auto", "nearestNeighbor", "linear", "gaussian", "bSpline",
"cosineWindowedSinc", "welchWindowedSinc", "hammingWindowedSinc",
"lanczosWindowedSinc", "genericLabel"),
verbose = TRUE
)template_roi_pathpath to the template image file which will be transformed into individuals' image
template_nametemplates to use
native_typewhich type of native image to use for calculating
the coordinates (default 'T1w')
interpolatorhow to interpolate the 'voxels'; default is
"auto": 'linear' for probabilistic map and 'nearestNeighbor'
otherwise.
verbosewhether the print out the progress
transform_image_to_template()
Apply transform to images (usually an atlas or 'ROI') from native space to template
YAELProcess$transform_image_to_template(
native_roi_path,
template_name = rpyants_builtin_templates(),
native_type = "T1w",
interpolator = c("auto", "nearestNeighbor", "linear", "gaussian", "bSpline",
"cosineWindowedSinc", "welchWindowedSinc", "hammingWindowedSinc",
"lanczosWindowedSinc", "genericLabel"),
verbose = TRUE
)native_roi_pathpath to the native image file that will be transformed into template
template_nametemplates to use
native_typewhich type of native image to use for calculating
the coordinates (default 'T1w')
interpolatorhow to interpolate the 'voxels'; default is
"auto": 'linear' for probabilistic map and 'nearestNeighbor'
otherwise.
verbosewhether the print out the progress
generate_atlas_from_template()
Generate atlas maps from template and morph to native brain
YAELProcess$generate_atlas_from_template( template_name = rpyants_builtin_templates(), atlas_folder = NULL, surfaces = NA, verbose = TRUE )
template_namewhich template to use
atlas_folderpath to the atlas folder (that contains the atlas files)
surfaceswhether to generate surfaces (triangle mesh); default is
NA (generate if not existed). Other choices are TRUE
for always generating and overwriting surface files, or FALSE
to disable this function. The generated surfaces will stay in native
'T1' space.
verbosewhether the print out the progress
transform_points_to_template()
Transform points from native images to template
YAELProcess$transform_points_to_template( native_ras, template_name = rpyants_builtin_templates(), native_type = "T1w", verbose = TRUE )
native_rasmatrix or data frame with 3 columns indicating points
sitting on native images in right-anterior-superior ('RAS')
coordinate system.
template_nametemplate to use for mapping
native_typenative image type where the points sit on
verbosewhether the print out the progress
transform_points_from_template()
Transform points from template images to native
YAELProcess$transform_points_from_template( template_ras, template_name = rpyants_builtin_templates(), native_type = "T1w", verbose = TRUE )
template_rasmatrix or data frame with 3 columns indicating points
sitting on template images in right-anterior-superior ('RAS')
coordinate system.
template_nametemplate to use for mapping
native_typenative image type where the points sit on
verbosewhether the print out the progress
construct_ants_folder_from_template()
Create a reconstruction folder (as an alternative option) that
is generated from template brain to facilitate the '3D' viewer.
Please make sure method map_to_template is called before using
this method (or the program will fail)
YAELProcess$construct_ants_folder_from_template( template_name = rpyants_builtin_templates(), add_surfaces = TRUE )
template_nametemplate to use for mapping
add_surfaceswhether to create surfaces that is morphed from
template to local; default is TRUE. Please enable this option
only if the cortical surfaces are not critical (for example,
you are studying the deep brain structures). Always use
'FreeSurfer' if cortical information is used.
get_brain()
Get '3D' brain model
YAELProcess$get_brain(
electrodes = TRUE,
project_name = "YAEL",
coord_sys = c("scannerRAS", "tkrRAS", "MNI152", "MNI305"),
...
)electrodeswhether to add electrodes to the viewers; can be
logical, data frame, or a character (path to electrode table). When
the value is TRUE, the electrode file under project_name
will be loaded; when electrodes is a data.frame,
or path to a 'csv' file, then please specify coord_sys
on what is the coordinate system used for columns "x", "y",
and "z".
project_nameproject name under which the electrode table should
be queried, if electrodes=TRUE
coord_syscoordinate system if electrodes is a data frame
with columns "x", "y", and "z", available choices
are 'scannerRAS' (defined by 'T1' weighted native 'MRI' image),
'tkrRAS' ('FreeSurfer' defined native 'TK-registered'),
'MNI152' (template 'MNI' coordinate system averaged over 152
subjects; this is the common "'MNI' coordinate space" we often refer to),
and 'MNI305' (template 'MNI' coordinate system averaged over 305
subjects; this coordinate system used by templates such as
'fsaverage')
...passed to threeBrain
clone()
The objects of this class are cloneable with this method.
YAELProcess$clone(deep = FALSE)
deepWhether to make a deep clone.