Title: | R Analysis and Visualization of 'ECOG/iEEG' Data |
---|---|
Description: | R Analysis and Visualization of 'ECOG/iEEG' Data RAVE provides cross-platform analysis and visualizations for neuroscience 'ECoG/iEEG' data by "just clicking buttons". This package include: (a) pre-processing of 'ECoG/iEEG' raw data into 'HDF5' format (a cross-platform data format that can be used for R, Matlab, Python, Java and C/C++); (b) 'ECoG/iEEG' epoch and visualizations in real time; (c) Users can write customized analysis as R packages and easily insert into RAVE for interactive visualizations. (d) 3D viewers driven by 'WebGL'. |
Authors: | Zhengjia Wang [cph, aut, cre], John Magnotti [aut], Michael S. Beauchamp [aut, fnd], Beauchamp lab [cph, fnd] |
Maintainer: | Zhengjia Wang <[email protected]> |
License: | GPL-3 |
Version: | 1.0.3.3 |
Built: | 2024-12-12 04:28:09 UTC |
Source: | https://github.com/beauchamplab/rave |
Function to check if data repository has data
any_subject_loaded(rave_data = getDefaultDataRepository())
any_subject_loaded(rave_data = getDefaultDataRepository())
rave_data |
internally used |
Save subject data, including brain imaging files into a zipped file. Notice this function does not guarantee every file is in. Please always double check what's inside.
archive_subject( project_name, subject_code, include_cache = FALSE, include_fs = TRUE, include_raw = FALSE, save_to = tempdir() )
archive_subject( project_name, subject_code, include_cache = FALSE, include_fs = TRUE, include_raw = FALSE, save_to = tempdir() )
project_name |
project name |
subject_code |
subject code |
include_cache |
whether to include cache for faster loading. Default is false |
include_fs |
whether to include 'FreeSurfer' and 'AFNI/SUMA' files |
include_raw |
whether to include raw data |
save_to |
directory to save file to |
Initialize data repository
arrange_data_dir(first_time = FALSE, reset = FALSE)
arrange_data_dir(first_time = FALSE, reset = FALSE)
first_time |
will create data repositories for you |
reset |
reset to default data directory |
Update (optional), and check validity of modules
arrange_modules(refresh = FALSE, reset = FALSE, quiet = FALSE)
arrange_modules(refresh = FALSE, reset = FALSE, quiet = FALSE)
refresh |
check and updates file |
reset |
same as first_time, check module updates, ignored |
quiet |
no overwrite messages |
Make new subject object from character
as_subject(subject, strict = TRUE, reference = "default")
as_subject(subject, strict = TRUE, reference = "default")
subject |
characters in format |
strict |
logical indication whether preprocess folder is needed |
reference |
what reference file the subject is using |
Attach subject data
attachDefaultDataRepository( unload = TRUE, rave_data = getDefaultDataRepository() )
attachDefaultDataRepository( unload = TRUE, rave_data = getDefaultDataRepository() )
unload |
TRUE if you want to detach |
rave_data |
internally used |
Baseline signals
baseline( el, from, to, method = "mean", unit = "%", data_only = FALSE, hybrid = TRUE, swap_file = tempfile(), mem_optimize = TRUE, same_dimension = unit %in% c("%", "dB"), preop = NULL, op, data_env = getDefaultDataRepository() )
baseline( el, from, to, method = "mean", unit = "%", data_only = FALSE, hybrid = TRUE, swap_file = tempfile(), mem_optimize = TRUE, same_dimension = unit %in% c("%", "dB"), preop = NULL, op, data_env = getDefaultDataRepository() )
el |
|
from |
baseline start time |
to |
baseline end time |
method |
mean or median, default is mean |
unit |
"%" percent signal change or "dB" decibel unit |
data_only |
return array or tensor object? |
hybrid |
if return tensor object, swap cache? useful for large dataset |
swap_file |
by default |
mem_optimize |
optimize for large dataset? default is TRUE |
same_dimension |
logical, true if |
preop |
function before baseline |
op |
function for baseline |
data_env |
internally used |
Import Subject "Matlab" File and Create "HDF5" files
cache_raw_voltage(project_name, subject_code, blocks, electrodes, ...)
cache_raw_voltage(project_name, subject_code, blocks, electrodes, ...)
project_name |
project name |
subject_code |
subject code |
blocks |
blocks to be imported |
electrodes |
to be imported (please check file existence before calling this function) |
... |
ignored |
Check if default data environment has object
check_data_repo( var = c("subject"), any = FALSE, data_repo = getDefaultDataRepository() )
check_data_repo( var = c("subject"), any = FALSE, data_repo = getDefaultDataRepository() )
var |
variable name |
any |
whether all variables should be present of any variables should exist |
data_repo |
internally used |
Logical TRUE
or FALSE
indicating the existence of the
variables
Check and Install RAVE Dependencies
check_dependencies( update_rave = TRUE, restart = TRUE, nightly = FALSE, demo_data = FALSE, ... )
check_dependencies( update_rave = TRUE, restart = TRUE, nightly = FALSE, demo_data = FALSE, ... )
update_rave |
logical, whether to update RAVE |
restart |
logical, whether to restart 'RStudio' after installation |
nightly |
logical, whether to install develop version |
demo_data |
logical, whether to check demo data |
... |
for compatibility purpose, ignored |
Check if epoch file is valid
check_epoch(subject, epoch_name)
check_epoch(subject, epoch_name)
subject |
subject object or string |
epoch_name |
epoch name to check |
Complete validity check a RAVE subject
check_subject(subject, stop_on_error = FALSE)
check_subject(subject, stop_on_error = FALSE)
subject |
character, must be |
stop_on_error |
logical, whether stop when error occurs |
None
check subject validity tools (use check_subjects2)
check_subjects_old( project_name, subject_code, check = TRUE, folders = c("Subject Folder", "RAVE Folder", "Preprocessing Folder", "Meta Folder", "Channel Folder"), preprocess = c("Started Preprocess", "Notch Filter", "Wavelet"), Meta = c("Electrode File", "Time point File", "Frequency File", "Epoch File") )
check_subjects_old( project_name, subject_code, check = TRUE, folders = c("Subject Folder", "RAVE Folder", "Preprocessing Folder", "Meta Folder", "Channel Folder"), preprocess = c("Started Preprocess", "Notch Filter", "Wavelet"), Meta = c("Electrode File", "Time point File", "Frequency File", "Epoch File") )
project_name |
project_name |
subject_code |
subject_code |
check |
check is internally used |
folders |
folders to check |
preprocess |
preprocess to check |
Meta |
Meta to check |
check subject validity tools
check_subjects2(project_name, subject_code, quiet = FALSE)
check_subjects2(project_name, subject_code, quiet = FALSE)
project_name |
project_name |
subject_code |
subject_code |
quiet |
logical |
Create local cache to speed up loading speed
create_local_cache(project_name, subject_code, epoch, time_range)
create_local_cache(project_name, subject_code, epoch, time_range)
project_name |
project name |
subject_code |
subject code |
epoch |
epoch name |
time_range |
time range to cache |
Customized Shiny Elements
customizedUI(inputId, width = 12L, ...)
customizedUI(inputId, width = 12L, ...)
inputId |
character, input id |
width |
integer from 1-12 |
... |
passed to |
FIR
FiltersDecimate or Down-sample a Signal using FIR
Filters
decimate_fir(x, q, n = 30)
decimate_fir(x, q, n = 30)
x |
signal to be decimated |
q |
integer factor to decimated by |
n |
filter order used for down-sample procedure, default is 30 |
Down-sampled signal
define_input
to define UI initialization
actions once a subject is loaded.Defines 'RAVE' Module Initialization
Defines the global variables for the module. Called along with
define_input
to define UI initialization
actions once a subject is loaded.
define_initialization(expr) ## Default S3 method: define_initialization(expr) ## S3 method for class 'rave_module_debug' define_initialization(expr) ## S3 method for class 'rave_running' define_initialization(expr) ## S3 method for class 'rave_running_local' define_initialization(expr)
define_initialization(expr) ## Default S3 method: define_initialization(expr) ## S3 method for class 'rave_module_debug' define_initialization(expr) ## S3 method for class 'rave_running' define_initialization(expr) ## S3 method for class 'rave_running_local' define_initialization(expr)
expr |
R expression to run after subject is loaded |
None
## Not run: # Requires to install R package beauchamplab/ravebuiltins # Enable debug mode ravebuiltins::dev_ravebuiltins(reload = FALSE) # Check data define_initialization({ rave_checks('power') power <- module_tools$get_power(referenced = TRUE) }) # Initialize global variables for modules ravebuiltins::dev_ravebuiltins(reload = FALSE) define_initialization({ print(subject$info()) time_points = preload_info$time_points }) define_input( shiny::sliderInput('time_range', 'Time-Range', min=0, max=1, value = c(0,1)), init_args = c('min', 'max', 'value'), init_expr = { min = min(time_points) max = max(time_points) value = c(0, max) } ) ## End(Not run)
## Not run: # Requires to install R package beauchamplab/ravebuiltins # Enable debug mode ravebuiltins::dev_ravebuiltins(reload = FALSE) # Check data define_initialization({ rave_checks('power') power <- module_tools$get_power(referenced = TRUE) }) # Initialize global variables for modules ravebuiltins::dev_ravebuiltins(reload = FALSE) define_initialization({ print(subject$info()) time_points = preload_info$time_points }) define_input( shiny::sliderInput('time_range', 'Time-Range', min=0, max=1, value = c(0,1)), init_args = c('min', 'max', 'value'), init_expr = { min = min(time_points) max = max(time_points) value = c(0, max) } ) ## End(Not run)
Defines 'RAVE' Module Inputs
define_input( definition, init_args, init_expr, keyword = "inputId", update_level = 2, ... ) ## Default S3 method: define_input( definition, init_args, init_expr, keyword = "inputId", update_level = 2, ... ) ## S3 method for class 'rave_module_debug' define_input(definition, init_args, init_expr, ...) ## S3 method for class 'rave_running_local' define_input( definition, init_args, init_expr, keyword = "inputId", update_level = 2, ... ) ## S3 method for class 'rave_running' define_input( definition, init_args, init_expr, keyword = "inputId", update_level = 2, ... )
define_input( definition, init_args, init_expr, keyword = "inputId", update_level = 2, ... ) ## Default S3 method: define_input( definition, init_args, init_expr, keyword = "inputId", update_level = 2, ... ) ## S3 method for class 'rave_module_debug' define_input(definition, init_args, init_expr, ...) ## S3 method for class 'rave_running_local' define_input( definition, init_args, init_expr, keyword = "inputId", update_level = 2, ... ) ## S3 method for class 'rave_running' define_input( definition, init_args, init_expr, keyword = "inputId", update_level = 2, ... )
definition |
R expression to define UI elements without |
init_args |
arguments to change once a subject is loaded |
init_expr |
expression to evaluate with subject loaded |
keyword |
what identifies the input element |
update_level |
update action code: see details. |
... |
ignored or passed to other methods. |
This function behaves differently in different contexts. By default,
it returns the result of definition
. When debugging modules (
"rave_module_debug"
), it assigns a variable to the global environment
with the variable name defined as input ID. In other contexts it parse
the definition and returns a list for 'RAVE' to use internally to compile
the module.
If update_level
is '0' then the input is defined as manual inputs,
which will not trigger re-calculate if changed. If '1' is set, then the
input is a render's input, and only update render functions. If '2' is
used, then once user change an input, then the whole module is re-calculated.
init_args
must be argument names of the definition. Once subject is
loaded, init_expr
will be evaluated in a local environment, then
variables in init_args
will be used to update the input widgets.
See details
Define 'RAVE' Module Output
define_output( definition, title = "", width = 12L, order = Inf, keyword = "outputId", ... ) ## Default S3 method: define_output( definition, title = "", width = 12L, order = Inf, keyword = "outputId", ... )
define_output( definition, title = "", width = 12L, order = Inf, keyword = "outputId", ... ) ## Default S3 method: define_output( definition, title = "", width = 12L, order = Inf, keyword = "outputId", ... )
definition |
R expression of output, such as |
title |
Title to show |
width |
integer from 1 to 12, similar to "width" in
|
order |
the order of output, smaller order will be displayed first |
keyword |
keyword for the output ID |
... |
ignored or passed to other methods |
In default or debug context, it returns HTML tags, but when 'RAVE' is running, the result will be parse list for internal use.
Check all packages to for new RAVE module packages
detect_modules(packages, as_module = TRUE, ...)
detect_modules(packages, as_module = TRUE, ...)
packages |
array of packages to search for, default is all packages |
as_module |
logical, try to return module instances or just a list of modules |
... |
ignored for compatibility purpose |
Plot and Inspect Signals in Trace, Periodogram, and Histogram
diagnose_signal( s1, s2 = NULL, sc = NULL, srate, name = "", try_compress = TRUE, max_freq = 300, window = ceiling(srate * 2), noverlap = window/2, std = 3, cex = 1.5, lwd = 0.5, flim = NULL, nclass = 100, main = "Channel Inspection", col = c("black", "red"), which = NULL, start_time = 0, boundary = NULL, mar = c(5.2, 5.1, 4.1, 2.1), ... )
diagnose_signal( s1, s2 = NULL, sc = NULL, srate, name = "", try_compress = TRUE, max_freq = 300, window = ceiling(srate * 2), noverlap = window/2, std = 3, cex = 1.5, lwd = 0.5, flim = NULL, nclass = 100, main = "Channel Inspection", col = c("black", "red"), which = NULL, start_time = 0, boundary = NULL, mar = c(5.2, 5.1, 4.1, 2.1), ... )
s1 |
Signal for inspection |
s2 |
Signal to compare, default NULL |
sc |
compressed signal to speedup the trace plot, if not provided, then
either the original |
srate |
Sample rate of s1, note that |
name |
Analysis name, for e.g. "CAR", "Notch", etc. |
try_compress |
If length of |
max_freq |
Max frequency to plot, should be no larger than half of the sampling rate. |
window |
Window length to draw the Periodogram |
noverlap |
Number of data points that each adjacent windows overlap |
std |
Error bar (red line) be drawn at standard deviations, by default is 3, meaning the error bars represent 3 standard deviations. |
cex , lwd , mar , ...
|
passed to |
flim |
|
nclass |
Number of classes for histogram |
main |
Plot title |
col |
Color for two signals, length of 2. |
which |
Which sub-plot to plot |
start_time |
When does signal starts |
boundary |
Boundary for signal plot, default is 1 standard deviation |
library(stats) time <- seq(0, 100, by = 1/200) s2 <- sin(2 * pi * 60 * time) + rnorm(length(time)) diagnose_signal(s2, srate = 200) # Apply notch filter s1 = notch_filter(s2, 200, 58,62) diagnose_signal(s1, s2, srate = 200)
library(stats) time <- seq(0, 100, by = 1/200) s2 <- sin(2 * pi * 60 * time) + rnorm(length(time)) diagnose_signal(s2, srate = 200) # Apply notch filter s1 = notch_filter(s2, 200, 58,62) diagnose_signal(s1, s2, srate = 200)
Function to download demo data to data repository
download_sample_data(subject, version = "v0.1.8-beta", ...)
download_sample_data(subject, version = "v0.1.8-beta", ...)
subject |
demo subject |
version |
rave release version |
... |
other parameters passed to |
Nothing
Function to download subjects from internet/local
download_subject_data( con, replace_if_exists = FALSE, override_project = NULL, override_subject = NULL, temp_dir = tempdir(), remove_zipfile = TRUE, subject_settings = NULL, mode = "wb", ... )
download_subject_data( con, replace_if_exists = FALSE, override_project = NULL, override_subject = NULL, temp_dir = tempdir(), remove_zipfile = TRUE, subject_settings = NULL, mode = "wb", ... )
con |
an url or local file path |
replace_if_exists |
Automatically replace current subject if subject files exist (default FALSE) |
override_project |
if not null, project will be renamed to this value |
override_subject |
if not null, subject will be renamed to this value |
temp_dir |
temp directory to store downloaded zip files and extracted files |
remove_zipfile |
clear downloaded zip files? if |
subject_settings |
override |
mode , ...
|
passed to |
Each downloaded zip file should have a "subject.yaml"
file indicating
default project name, subject code, data directory and raw data directory.
If you want to override subject settings, you need to implement your own
subject_settings
. See examples.
## Not run: # Normal example download.file( 'https://s3-us-west-2.amazonaws.com/rave-demo-subject/sfn-demo/data-large.zip', destfile = "~/rave_data/data-small.zip", mode = "wb") download_subject_data(con = "~/rave_data/data-small.zip") # or the following # download_subject_data( # 'https://s3-us-west-2.amazonaws.com/rave-demo-subject/sfn-demo/data-large.zip' # ) # rename project to demo_junk download_subject_data(con = "~/rave_data/data-small.zip", override_project = 'demo_junk') # override settings download_subject_data( con = "~/rave_data/data-small.zip", subject_settings = list( # subject conf 'demo_project/demo_subject' = list( data_dir = 'data 2/data_dir/demo/sub1', raw_dir = 'data 2/raw_dir/sub1' ) ) ) ## End(Not run)
## Not run: # Normal example download.file( 'https://s3-us-west-2.amazonaws.com/rave-demo-subject/sfn-demo/data-large.zip', destfile = "~/rave_data/data-small.zip", mode = "wb") download_subject_data(con = "~/rave_data/data-small.zip") # or the following # download_subject_data( # 'https://s3-us-west-2.amazonaws.com/rave-demo-subject/sfn-demo/data-large.zip' # ) # rename project to demo_junk download_subject_data(con = "~/rave_data/data-small.zip", override_project = 'demo_junk') # override settings download_subject_data( con = "~/rave_data/data-small.zip", subject_settings = list( # subject conf 'demo_project/demo_subject' = list( data_dir = 'data 2/data_dir/demo/sub1', raw_dir = 'data 2/raw_dir/sub1' ) ) ) ## End(Not run)
iEEG/ECoG
data RepositoryA repository to keep subject information, including electrode instances, reference information, epoch data, and offers method to epoch data.
subject
Subject
instance
raw
dictionary to store Electrode
instances
reference
dictionary to store references for electrodes
epochs
dictionary to store epoch data
raw_volt
environment, stores pre-referenced analog traces
raw_power
environment, stores pre-referenced power spectrum
raw_phase
environment, stores pre-referenced phase data
volt
environment, stores referenced analog traces
power
environment, stores referenced power spectrum
phase
environment, stores referenced phase data
info()
obtain the information
ECoGRepository$info(print = TRUE)
print
logical, whether to print the information, default is true
character of the information
print()
print memory address
ECoGRepository$print(...)
...
ignored
none
new()
constructor
ECoGRepository$new(subject, reference = "default", autoload = TRUE)
subject
character such as "project/subject"
or
Subject
instance
reference
character, reference name, default is "default"
,
which refers to "reference_default.csv"
in subject meta folder
autoload
logical, whether to auto-load reference for all electrodes, default is yes.
An ECoGRepository
instance
get_electrode()
get Electrode
instances
ECoGRepository$get_electrode(electrode, name = "raw")
electrode
integers, referring to electrode numbers
name
character, "raw"
, "power"
, "raw_phase"
,
etc.
list of environments containing electrode instances
load_electrodes()
load electrodes; usually don't need to directly call this
method if autoload
is true when initializing the repository
ECoGRepository$load_electrodes(electrodes, reference = "default")
electrodes
electrode number (integer)
reference
name of reference
none
epoch()
slice the data according to epoch table
ECoGRepository$epoch( epoch_name, pre, post, electrodes = NULL, frequency_range = NULL, data_type = "power", referenced = TRUE, func = NULL, quiet = FALSE )
epoch_name
the name of epoch; for example, "YABa"
refers
to "epoch_YABa.csv"
in subject meta folder.
pre
positive number in seconds, how long should the time be kept before the onset
post
positive number in seconds, how long should the time be kept after onset
electrodes
integers, electrode numbers
frequency_range
experimental, frequency range to include
data_type
data types to epoch; default is "power"
, which
is power spectrum, or amplitude. Other choices are "phase"
for phase data and "volt"
for voltage or analog signal traces.
referenced
whether to load data referenced or without reference
func
experimental, function to apply to each electrodes
quiet
whether to suppress output messages, default is no
none. However the results are stored in public fields.
load_reference()
load references
ECoGRepository$load_reference(ref_name, electrodes = NULL)
ref_name
reference name
electrodes
electrode numbers
none
baseline()
baseline signals (deprecated)
ECoGRepository$baseline(from, to, electrodes = NULL, print.time = FALSE)
from, to, electrodes, print.time
internally used
data after baseline. Please use baseline
instead
Zhengjia Wang
## Not run: # Two ways to create instances repo <- ECoGRepository$new('demo/YAB') subject <- Subject$new(project_name = 'demo', subject_code = 'YAB') repo <- ECoGRepository$new(subject) # Create an instance without auto collecting references, only load # interesting electrodes repo <- ECoGRepository$new('demo/YAB', autoload = FALSE) repo$load_electrodes(c(14,15)) # Create an instance with non-default reference repo <- ECoGRepository$new('demo/YAB', reference = 'bipolar') # Epoch data according to epoch file "epoch_YABaOutlier.csv" in meta folder # epoch_name should be "epoch_(name).csv" repo$epoch(epoch_name = 'YABaOutlier', pre = 1, post = 2, electrodes = 14, referenced = TRUE, data_type = "power") repo$power #> Dimension: 287 x 16 x 301 x 1 #> - Trial: 1, 2, 3, 4, 5, 6,... #> - Frequency: 2, 12, 22, 32, 42... #> - Time: -1, -0.99, -0.98,... #> - Electrode: 14 ## End(Not run)
## Not run: # Two ways to create instances repo <- ECoGRepository$new('demo/YAB') subject <- Subject$new(project_name = 'demo', subject_code = 'YAB') repo <- ECoGRepository$new(subject) # Create an instance without auto collecting references, only load # interesting electrodes repo <- ECoGRepository$new('demo/YAB', autoload = FALSE) repo$load_electrodes(c(14,15)) # Create an instance with non-default reference repo <- ECoGRepository$new('demo/YAB', reference = 'bipolar') # Epoch data according to epoch file "epoch_YABaOutlier.csv" in meta folder # epoch_name should be "epoch_(name).csv" repo$epoch(epoch_name = 'YABaOutlier', pre = 1, post = 2, electrodes = 14, referenced = TRUE, data_type = "power") repo$power #> Dimension: 287 x 16 x 301 x 1 #> - Trial: 1, 2, 3, 4, 5, 6,... #> - Frequency: 2, 12, 22, 32, 42... #> - Time: -1, -0.99, -0.98,... #> - Electrode: 14 ## End(Not run)
Stores single electrode or reference signals
electrode
electrode number in integer
raw_power
stores pre-epoch power spectrum with no reference
raw_phase
stores pre-epoch phase with no reference
raw_volt
stores pre-epoch analog traces with no reference
phase
stores pre-epoch phase after reference
power
stores pre-epoch power spectrum after reference
volt
stores pre-epoch analog traces after reference
preload
which of the three data are pre-loaded
reference
character or Electrode
instance indicating the
reference for current electrode
has_power, has_phase, has_volt
whether power, phase, or voltage data exist in file system before and after reference
has_power, has_phase, has_volt
whether power, phase, or voltage data exist in file system before and after reference
blocks
character vector of block names (read-only)
subject_id
character of subject ID (read-only)
reference_electrode
whether this is a reference (read-only)
info()
print electrode information
Electrode$info()
none
print()
overrides default print method
Electrode$print(...)
...
ignored
none
switch_reference()
switch reference (experimental)
Electrode$switch_reference(new_reference)
new_reference
An electrode instance
none
referenced()
get referenced data
Electrode$referenced(type = "power", ram = TRUE)
type
which data to reference, default is power
ram
whether to load data to memory
If ram
is true, then returns a list of matrices. The
length of the list equals the number of blocks, and each matrix is
frequency by time points. If ram
is false, then returns an
environment with each element a LazyH5
or
LazyFST
instance.
clean()
remove data from memory
Electrode$clean(types = c("power", "phase", "volt"), force = FALSE)
types
data types to clean
force
whether to remove pre-loaded data types
none
new()
constructor
Electrode$new( subject, electrode, reference_by = "noref", preload = NULL, is_reference = FALSE )
subject
Subject
instance or characters like
"proj/sub"
electrode
number, integer
reference_by
reference signals, choices are character, or
Electrode
instance; default is "noref"
,
meaning no reference to the electrode
preload
data to load along with constructor
is_reference
is current instance a reference?
An Electrode
instance
epoch()
epoch electrode
Electrode$epoch( epoch_name, pre, post, types = c("volt", "power", "phase"), raw = FALSE, hybrid = TRUE )
epoch_name
epoch name, for example, epoch_name="default"
refers to epoch file "epoch_default.csv"
in subject meta folder
pre
seconds before trial onset to load
post
seconds after trial onset to load
types
characters, data types to load; choices are "volt"
,
"power"
, and "phase"
raw
whether epoch pre-referenced data?
hybrid
whether to fast-cache the data on hard-drive? See also
Tensor
list of data after epoch
Zhengjia Wang
## Not run: # Electrode with no reference e1 <- Electrode$new('demo/YAB', electrode = 14, reference_by = 'noref') e1$reference #> Subject: demo/YAB #> Electrode: noref (Reference) # Add Common Average Reference in rave/data/reference/ref_13-63,65-84.h5 e2 <- Electrode$new('demo/YAB', electrode = 14, reference_by = 'ref_13-63,65-84') # Electrode with bipolar reference by another electrode e3 <- Electrode$new('demo/YAB', electrode = 14, reference_by = 'ref_15') # Alternative way reference <- Electrode$new('demo/YAB', electrode = 15, is_reference = TRUE) e4 <- Electrode$new('demo/YAB', electrode = 14, reference_by = reference) # e3, e4 are the same in scientific meaning. To test it, epoch them power3 <- e3$epoch('YABaOutlier', 1, 2, 'power', raw = FALSE, hybrid = FALSE)$power power4 <- e4$epoch('YABaOutlier', 1, 2, 'power', raw = FALSE, hybrid = TRUE)$power # Compare e3 and e4, result difference should be 0 range(power3$get_data() - power4$get_data()) #> 0 # With or without hybrid, the size will be different # No hybrid, totally in memory lobstr::obj_size(power3) #> 12 MB # Hybrid, data is swapped to hard-drive lobstr::obj_size(power4) #> 908 kB ## End(Not run)
## Not run: # Electrode with no reference e1 <- Electrode$new('demo/YAB', electrode = 14, reference_by = 'noref') e1$reference #> Subject: demo/YAB #> Electrode: noref (Reference) # Add Common Average Reference in rave/data/reference/ref_13-63,65-84.h5 e2 <- Electrode$new('demo/YAB', electrode = 14, reference_by = 'ref_13-63,65-84') # Electrode with bipolar reference by another electrode e3 <- Electrode$new('demo/YAB', electrode = 14, reference_by = 'ref_15') # Alternative way reference <- Electrode$new('demo/YAB', electrode = 15, is_reference = TRUE) e4 <- Electrode$new('demo/YAB', electrode = 14, reference_by = reference) # e3, e4 are the same in scientific meaning. To test it, epoch them power3 <- e3$epoch('YABaOutlier', 1, 2, 'power', raw = FALSE, hybrid = FALSE)$power power4 <- e4$epoch('YABaOutlier', 1, 2, 'power', raw = FALSE, hybrid = TRUE)$power # Compare e3 and e4, result difference should be 0 range(power3$get_data() - power4$get_data()) #> 0 # With or without hybrid, the size will be different # No hybrid, totally in memory lobstr::obj_size(power3) #> 12 MB # Hybrid, data is swapped to hard-drive lobstr::obj_size(power4) #> 908 kB ## End(Not run)
Electrode localization
electrode_localization(subject_code, freesurfer_path, ct_path, ...)
electrode_localization(subject_code, freesurfer_path, ct_path, ...)
subject_code |
'RAVE' subject code |
freesurfer_path |
'FreeSurfer' folder path that points to reconstructed subject brain |
ct_path |
'CT' path (in 'Nifti' format). The 'CT' has to be aligned to 'T1-MRI'. Please check this tutorial. |
... |
other parameters passing to |
This function will launch a shiny application.
Usually contains reactive functions that requires shiny reactive context
eval_when_ready(FUN)
eval_when_ready(FUN)
FUN |
function that takes an environment (runtime environment) as arguments. |
where all the module functions are executed. It's rarely created
manually, use get_module
to create module, run with
start_app(m, test.mode=TRUE)
, and then inspect modules.
.__rave_context__.
context string for current instance, indicating whether the module is running locally (public, but internally used)
.__rave_package__.
current package name to run (public, but internally used)
.__rave_module__.
module ID (public, but internally used)
.__rave_module_instance__.
self instance (public, but internally used)
module_env
ModuleEnvir
instance
cache_env
cache environment to store key-value pairs locally
parent_env
the parent/top environment of the module, usually global environment or some name-space if the module is implemented as an R package
wrapper_env
stores all the utility functions. Some functions are
overridden there such as observe
,
rave_checks
, or eval_when_ready
. These functions behave
differently inside or outside of shiny context, and with or without data
loaded. The environment will be locked once the module is initialized.
The parent environment is parent_env
static_env
stores module static functions. These functions are
evaluated under parse_env
and then moved here. The environment
is locked after initialization. Its parent environment is
wrapper_env
param_env
stores parameters and most of the user inputs. It can
also serve as a repository for global variables. Unlike the previous
environments, param_env
is unlocked, but module creators do not
have access to this environment directly. The parent environment is
static_env
runtime_env
where the main part of module is running. All shiny
observe
and observeEvent
are
redirected to this environment by default (unless using
shiny::observe
). All functions in static_env
have access
to this environment. The parent environment is param_env
async_env
where asynchronous codes run
parse_env
environment where modules are parsed. The parent
environment is runtime_env
. Once all functions are evaluated,
this environment is not used. However, module creators don't directly
access this environment once the module is initialized.
ns
shiny name-space functions, is equivalent to
shiny::NS(module_id)
. The goal is to add prefixes to module inputs
so that two modules with the same input ID are named differently
auto_execute
(Deprecated) whether to auto-calculate results
manual_inputIds
character vector; name list of manually input IDs. Used when the algorithm takes long to run
rendering_inputIds
character vector; name list of input IDs that
when one of the corresponding inputs is changed, then rave_execute
will not get evaluated. Only the outputs are changed.
input_update
expressions to update inputs
register_output_events
expressions to register outputs
register_input_events
expressions to register inputs
execute
module main function. The function is dynamically generated. Don't call directly.
async_module
(experimental) whether the module contains any asynchronous part
global_reactives
shiny global reactives
, internal use only
local_reactives
shiny local reactives
, internal use only
internal_reactives
internal reactive values to control some elements, internal use only
ready_functions
functions to run when the module is ready. The
functions are called at the last step of shinirize
.
Usually it's used along with eval_when_ready
, to make sure
global_reactives
and local_reactives
getting registered
before functions calls
input_ids
vector of input IDs (read-only)
input_labels
vector of input labels (read-only)
output_labels
vector of output labels (read-only)
output_ids
vector of output IDs (read-only)
reload()
(experimental) signal the modules to reload
ExecEnvir$reload()
none
finalize()
garbage collection
ExecEnvir$finalize()
none
info()
print variables in different layers (environment)
ExecEnvir$info()
none
print()
print the memory address
ExecEnvir$print(...)
...
ignored
memory address
clean()
clean the environments to release the resource
ExecEnvir$clean()
none
new()
constructor
ExecEnvir$new(session = getDefaultReactiveDomain(), parent_env = NULL)
session
shiny session instance
parent_env
parent environment of this instance: package name space or global environment
reset()
reset the runtime environment, rarely used
ExecEnvir$reset(inputs)
inputs
reactive value list
none
copy()
(deprecated) copy the instance locally
ExecEnvir$copy( session_id = "__fake_runtime_env__", data_env = getDefaultDataRepository() )
session_id
character
data_env
where the data is stored, default is the environment
returned by getDefaultDataRepository
a copied instance
execute_with()
(deprecated) execute module with given parameter
ExecEnvir$execute_with(param, async = FALSE, plan = NULL)
param
named list
async
whether to run the whole module
plan
future plan
runtime environment
names()
returns names of a list, if names are null, returns blank characters
ExecEnvir$names(x)
x
a list
the names of the list
register_module()
register ModuleEnvir
instance
ExecEnvir$register_module(module_env)
module_env
ModuleEnvir
instance. The modules
are shared across different sessions, but to run the module, we need
to create runtime environment, which is ExecEnvir
none
register_context()
Register 'RAVE' context for current environment (internally used)
ExecEnvir$register_context(context = c("rave_running", "rave_running_local"))
context
context string to indicate whether the module is running locally
None
rave_inputs()
parse input components
ExecEnvir$rave_inputs( ..., .input_panels = list(), .tabsets = list(), .env = NULL, .manual_inputs = NULL, .render_inputs = NULL )
...
shiny input calls, such as textInput('id', 'Name', ...)
.input_panels, .tabsets
together define the input layouts
.env
ignored, debug only
.manual_inputs
input IDs that won't cause module re-calculate when inputs are updated
.render_inputs
input IDs that only trigger render functions when updated
none
rave_outputs()
parse output components
ExecEnvir$rave_outputs( ..., .output_tabsets = list(), .tabsets = list(), .env = NULL )
...
shiny output calls, such as plotOutput('id', 'Title')
.output_tabsets, .tabsets
together define the output layouts
.env
debug use
none
rave_updates()
input initialization when iEEG/ECoG
data are imported
ExecEnvir$rave_updates(..., .env = NULL)
...
R expressions
.env
for debug use
rave_execute()
parse, and compile to main function
ExecEnvir$rave_execute(..., auto = TRUE, .env = NULL, async_vars = NULL)
...
R expressions
auto
whether the module should run automatically
.env
debug use
async_vars
variables further passed to async
module
none, but ExecEnvir$execute
will be generated.
set_browser()
(experimental) cache R expression in browser
localStorage
ExecEnvir$set_browser(expr, session = getDefaultReactiveDomain())
expr
R expression
session
shiny session instance
generate_input_ui()
generate input panels according to parsed rave_inputs
ExecEnvir$generate_input_ui(sidebar_width = 3L)
sidebar_width
integer from 1 to 11, the width of the input panels
HTML tags
generate_output_ui()
generate outputs labels according to parsed
rave_outputs
ExecEnvir$generate_output_ui(sidebar_width = 3L)
sidebar_width
integer from 1 to 11, the width of the input panels,
the output panel width is calculated as 12-sidebar_width
HTML tags
is_global()
(deprecated) check if variable is shared across modules.
Please use cache_input
instead to get variable values.
ExecEnvir$is_global(inputId)
inputId
input ID
clone()
The objects of this class are cloneable with this method.
ExecEnvir$clone(deep = FALSE)
deep
Whether to make a deep clone.
Zhengjia Wang
## Not run: # Load module module <- get_module('ravebuiltins', 'power_explorer') # Create execute environmen execenv <- module$get_or_new_exec_env() execenv$info() ## End(Not run)
## Not run: # Load module module <- get_module('ravebuiltins', 'power_explorer') # Create execute environmen execenv <- module$get_or_new_exec_env() execenv$info() ## End(Not run)
You must import subject through rave_preprocess()
and
then run this function
export_diagnose_voltage( subject, electrodes, blocks, save_dir = "./export", width = 12, height = 7, useDingbats = FALSE, onefile = TRUE, winlen, freq_lim, nclass = 50, fore_col = "black", back_col = "grey80", ... )
export_diagnose_voltage( subject, electrodes, blocks, save_dir = "./export", width = 12, height = 7, useDingbats = FALSE, onefile = TRUE, winlen, freq_lim, nclass = 50, fore_col = "black", back_col = "grey80", ... )
subject |
character with the following format:
|
electrodes |
a integer vector. For example: |
blocks |
the blocks to include. Default is all blocks of this subject |
save_dir |
the directory you want to save the files |
width , height , useDingbats
|
passed to |
onefile |
collect images within one file? |
winlen |
window length, default is twice of the subject sampling rate |
freq_lim |
default is half of voltage sampling rate |
nclass |
number of classes in histogram plot, default is 50 |
fore_col |
Periodogram color for Notch filtered signals |
back_col |
Periodogram color for raw signals |
... |
All other parameters passed to |
Fake 'shiny' Session for Debug Purpose
fake_session(rave_id = "__fake_session__", id = NULL)
fake_session(rave_id = "__fake_session__", id = NULL)
rave_id |
internally used |
id |
module ID, used to create scope, will passed to |
Fake shiny session for debug purpose
download demo data
finalize_installation( packages, upgrade = c("ask", "config-only", "always", "never", "data-only"), async = FALSE )
finalize_installation( packages, upgrade = c("ask", "config-only", "always", "never", "data-only"), async = FALSE )
packages |
package name to finalize. 'rave' to only update base demo
data, or |
upgrade |
whether to ask. Default is |
async |
whether to run scripts in parallel; default is true. |
Parse 'RAVE' Module Contents
get_content(content, env, evaluate = TRUE, chunks = FALSE)
get_content(content, env, evaluate = TRUE, chunks = FALSE)
content |
characters, R code to parse into expressions |
env |
environment to parse the code into, please specify the context |
evaluate |
whether to evaluate parse expression into |
chunks |
whether to respect code notations and chunk the code into separate parts |
If "evaluate=TRUE"
, then the parse code will be evaluated
within env
and returns a logical value: TRUE
means the content has
something, otherwise returns FALSE
If "evaluate=FALSE"
, returns the parsed expression and add attributes
about the names of each chunk and whether they are asynchronous
See details.
Get Directories in 'RAVE'
get_dir( subject_code, project_name, block_num, mkdirs = NULL, subject_id, relative = FALSE )
get_dir( subject_code, project_name, block_num, mkdirs = NULL, subject_id, relative = FALSE )
subject_code |
subject code; can be ignored when |
project_name |
project name; can be ignored when |
block_num |
block name (optional) |
mkdirs |
internally used |
subject_id |
subject ID; can be omitted if |
relative |
whether to return relative path or absolute to root directory |
internally used for debugging functions
get_fake_updated_message(..., .args = list(), .func = NULL)
get_fake_updated_message(..., .args = list(), .func = NULL)
... |
see with_fake_session |
.args |
same as ... |
.func |
function to pass to with_fake_session |
Get RAM usage
get_mem_usage( modules = list(), data_envir = getDefaultDataRepository(), session = getDefaultReactiveDomain() )
get_mem_usage( modules = list(), data_envir = getDefaultDataRepository(), session = getDefaultReactiveDomain() )
modules |
which module(s) |
data_envir |
default uses |
session |
shiny session instance |
Function to find modules in packages
get_module(package, module_id, local = FALSE, ...)
get_module(package, module_id, local = FALSE, ...)
package |
package name to search for modules |
module_id |
(optional) module ID if the package contains multiple modules |
local |
run module locally? |
... |
ignored for compatibility purpose |
Safe Way to Access Module Package Files Using Relative Path
get_path(..., mustWork = FALSE, is_directory = FALSE)
get_path(..., mustWork = FALSE, is_directory = FALSE)
... |
relative path to the file |
mustWork |
whether the file must exists |
is_directory |
whether required file is a directory |
If you are developing the package, get_path
returns the
absolute file path, otherwise it uses system.file
to
get the file from package library.
Get RAVE Theme from Package Settings
packages |
packages to check |
type |
characters, |
theme |
|
session |
shiny session |
A list contains all palettes found in the packages.
pal = get_rave_theme('rave', type = c('continuous', 'discrete'), theme='light') print(pal, plot=TRUE) pal = get_rave_theme('rave', type = c('continuous', 'discrete'), theme='dark') print(pal, plot=TRUE)
pal = get_rave_theme('rave', type = c('continuous', 'discrete'), theme='light') print(pal, plot=TRUE) pal = get_rave_theme('rave', type = c('continuous', 'discrete'), theme='dark') print(pal, plot=TRUE)
Get all subjects within project
get_subjects(project_name, check_subfolders = TRUE, check_rawdata = FALSE)
get_subjects(project_name, check_subfolders = TRUE, check_rawdata = FALSE)
project_name |
project |
check_subfolders |
logical, check whether folder 'rave' exists in subject folder, default true |
check_rawdata |
logical, whether raw subject folder exists, default false |
Get Value or Default
get_val(x, key = NULL, ..., .invalids = c("null", "na"))
get_val(x, key = NULL, ..., .invalids = c("null", "na"))
x |
a list, or environment, or just any R object |
key |
the name to obtain from |
... |
if the value is invalid, the default value to return |
.invalids |
what counts as invalid? Default is |
Get environment where subject data is loaded
getDefaultDataRepository( session = getDefaultReactiveDomain(), session_id, session_based = NULL )
getDefaultDataRepository( session = getDefaultReactiveDomain(), session_id, session_based = NULL )
session |
shiny session, default is NULL |
session_id |
internal use |
session_based |
internal use |
Get Module Runtime Environment from Current Context
getExecEnvirFromContext()
getExecEnvirFromContext()
An ExecEnvir
instance
Get Module Instance from Current Context
getModuleEnvirFromContext()
getModuleEnvirFromContext()
An ModuleEnvir
instance
.csv
files that contain electrode informationThe table to import must contains a column 'Electrode'
that is consistent with the corresponding subject.
import_electrodes(path, subject, use_fs = NA, ...)
import_electrodes(path, subject, use_fs = NA, ...)
path |
path to the electrode file to import |
subject |
'RAVE' project-subject combination |
use_fs |
whether to use 'FreeSurfer', default is to auto-detect |
... |
passed to |
Initialize main application for debugging purpose
init_app( modules = NULL, active_module = NULL, launch.browser = TRUE, theme = "red", disable_sidebar = FALSE, simplify_header = FALSE, ..., data_repo = getDefaultDataRepository() )
init_app( modules = NULL, active_module = NULL, launch.browser = TRUE, theme = "red", disable_sidebar = FALSE, simplify_header = FALSE, ..., data_repo = getDefaultDataRepository() )
modules |
which modules to show. See |
active_module |
which module to focus at start up (use module ID) |
launch.browser |
launch browsers, default is on |
theme |
color theme for the website |
disable_sidebar |
hide sidebar at startup? |
simplify_header |
hide header at startup? |
... |
other parameters like |
data_repo |
internally used |
Initialize 'RAVE' module for debug purpose
init_module( module_id, debug = FALSE, parse_context = c("rave_running", "rave_running_local") )
init_module( module_id, debug = FALSE, parse_context = c("rave_running", "rave_running_local") )
module_id |
module ID |
debug |
whether to expose all functions to the global environment |
parse_context |
parsing context, for internal use |
lapply
using future package in asynchronous waylapply
using future package in asynchronous way
lapply_async( x, fun, ..., .ncores = 0, .call_back = NULL, .packages = NULL, .envir = environment(), .globals = TRUE, .gc = TRUE, .as_datatable = FALSE, .nrows = 0 ) lapply_async3( x, fun, ..., .globals = TRUE, .gc = TRUE, .callback = NULL, .ncores = 0 )
lapply_async( x, fun, ..., .ncores = 0, .call_back = NULL, .packages = NULL, .envir = environment(), .globals = TRUE, .gc = TRUE, .as_datatable = FALSE, .nrows = 0 ) lapply_async3( x, fun, ..., .globals = TRUE, .gc = TRUE, .callback = NULL, .ncores = 0 )
x , fun , ...
|
(See |
.ncores |
Number of cores to use. If the value is 0, the number of cores will be determined by rave_options('max_worker'). |
.call_back |
A function takes current iteration number as argument, can be NULL. |
.packages |
NULL be default, then the function will detect attached packages automatically. Otherwise you have to specify the packages that you want to load. |
.envir |
internally used |
.globals |
Automatically detect variables. See ?future::future |
.gc |
Clean up environment after each iterations? Recommended for large datasets. |
.as_datatable |
logical, return result as |
.nrows |
integer, if |
.callback |
function or |
## Not run: lapply_async(1:10, function(x){ Sys.sleep(2) # Run for 1 secs Sys.getpid() }, .ncores = 3, .call_back = function(i){ cat('Running iteration -', i, '\n') }) ## End(Not run)
## Not run: lapply_async(1:10, function(x){ Sys.sleep(2) # Run for 1 secs Sys.getpid() }, .ncores = 3, .call_back = function(i){ cat('Running iteration -', i, '\n') }) ## End(Not run)
Load local cache for fast importing voltage, power, and phase
load_local_cache( project_name, subject_code, epoch, time_range, frequency_range = NULL, electrodes, referenced = FALSE, data_type = "voltage" )
load_local_cache( project_name, subject_code, epoch, time_range, frequency_range = NULL, electrodes, referenced = FALSE, data_type = "voltage" )
project_name |
project name |
subject_code |
subject code |
epoch |
epoch name |
time_range |
time range to cache |
frequency_range |
frequency range to cache |
electrodes |
electrodes to cache |
referenced |
which reference to be used |
data_type |
which type(s) of data to cache |
Load subject meta data
load_meta(meta_type, project_name, subject_code, subject_id, meta_name)
load_meta(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 |
Load RAVE Modules
load_modules(legacy = FALSE)
load_modules(legacy = FALSE)
legacy |
for internal debug use |
called internally by init_module
or
other module packages
load_rave_module_package( env, parse_context = c("rave_module_debug", "rave_running", "rave_running_local") )
load_rave_module_package( env, parse_context = c("rave_module_debug", "rave_running", "rave_running_local") )
env |
environment to load tools |
parse_context |
parsing context |
Use in comp.R
to load scripts that cannot be put into
package "R/"
folder. Usually the scripts contains shiny reactive
values that changes dynamically.
load_scripts(..., asis = FALSE)
load_scripts(..., asis = FALSE)
... |
script files that are wrapped by |
asis |
if the scripts to be loaded is a file, whether to copy to a
temporary directory when launching 'RAVE'. Usually we set this to be true
to save loading time. However, if your scripts also source other scripts
in relative path, we recommend setting |
This function raises error when running in default contexts, and requires debug mode, or run inside of 'RAVE' instance.
None, but will source, or run whatever code provided.
Find module analysis names
module_analysis_names( module_id, project_name, data_env = getDefaultDataRepository() )
module_analysis_names( module_id, project_name, data_env = getDefaultDataRepository() )
module_id |
module id |
project_name |
project name |
data_env |
internally used |
contains module data, functions, etc.
cache_env
cache environment for module
module_id
module ID, unique
label_name
corresponding module name
script_path
compiled module scripts
script
if script_path
not exists, alternative script
author
who wrote the module not often used
version
module version
packages
the packages to be loaded for the module
rmd_path
deprecated
parent_env
parent environment of the module, usually global environment or package environment
from_package
whether the module is compiled from another R
package. This value is required to be true since "rave-0.1.9"
.
package_name
which package does the module belong to?
sidebar_width
input panel width, from 1 to 11
info()
print module information
ModuleEnvir$info()
none
print()
print module information and returns memory address
ModuleEnvir$print(...)
...
ignored
new()
constructor
ModuleEnvir$new( module_id, label_name, script_path, author = NULL, version = "0", packages = NULL, .script_content = NULL, rmd_path = NULL, parent_env = globalenv() )
module_id, label_name, script_path, author, version
see fields
packages, parent_env, rmd_path
see fields
.script_content
internal use
get_or_new_exec_env()
get the corresponding ExecEnvir
with
shiny session
ModuleEnvir$get_or_new_exec_env( session = getDefaultReactiveDomain(), ..., new = FALSE )
session
shiny session; see shiny domains
...
ignored
new
whether to force creating a new runtime environment if previous one already exists
an ExecEnvir
instance associated with
current module and given session
load_script()
load and compile script into registered
ExecEnvir
ModuleEnvir$load_script(session = getDefaultReactiveDomain())
session
shiny session; see shiny domains
none
render_ui()
generate 'HTML' tags
ModuleEnvir$render_ui(session = getDefaultReactiveDomain())
session
shiny session; see shiny domains
'HTML' tags
clean()
clean the module environment
ModuleEnvir$clean(session = getDefaultReactiveDomain(), session_id)
session
shiny session; see shiny domains
session_id
shiny 'RAVE' ID, default is auto-generated
## Not run: module <- get_module('ravebuiltins', 'power_explorer') module #> Module Name: Power Explorer #> Version: 0 #> Script Path: ... #> Author(s): ## End(Not run)
## Not run: module <- get_module('ravebuiltins', 'power_explorer') module #> Module Name: Power Explorer #> Version: 0 #> Script Path: ... #> Author(s): ## End(Not run)
Load Demo Subject According to Package Configuration File
mount_demo_subject( subject_code, project_name, force_reload_subject = FALSE, ..., download_url ) ## S3 method for class 'rave_module_debug' mount_demo_subject( subject_code, project_name, force_reload_subject = FALSE, ..., download_url ) ## S3 method for class 'rave_running' mount_demo_subject(...) ## S3 method for class 'rave_running_local' mount_demo_subject(...)
mount_demo_subject( subject_code, project_name, force_reload_subject = FALSE, ..., download_url ) ## S3 method for class 'rave_module_debug' mount_demo_subject( subject_code, project_name, force_reload_subject = FALSE, ..., download_url ) ## S3 method for class 'rave_running' mount_demo_subject(...) ## S3 method for class 'rave_running_local' mount_demo_subject(...)
subject_code |
optional, subject code |
project_name |
optional, project name |
force_reload_subject |
logical, whether to force reload subject even if another subject is loaded |
... |
further passed to |
download_url |
optional, web link to subject archive |
When debugging the 'RAVE' modules, it loads demo subject for
debugging from according to settings file "inst/rave.yaml"
.
This function only function properly in 'rave_module_debug'
mode.
This means by default it raises errors. In other mode, for example
'rave_running'
, it does nothing.
None
Filter line noise out from ECoG channels
notch_channel(s, sample_rate, bands = c(60, 120, 180), width = c(1, 2, 2))
notch_channel(s, sample_rate, bands = c(60, 120, 180), width = c(1, 2, 2))
s |
signal, time domain |
sample_rate |
signal sample rate |
bands |
bands that will be filtered out |
width |
along with bands, half of the filter width. For example,if bands is 60Hz and width is 1Hz, then the notch filter lower bound is 60-1=59Hz and upper bound is 60+1=61Hz. |
Apply Notch Filter to Analog Trace Data
notch_filter(s, sample_rate, lb, ub, domain = 1)
notch_filter(s, sample_rate, lb, ub, domain = 1)
s |
signal in time or frequency domain |
sample_rate |
signal sample rate |
lb |
filter lower bound (Hz) |
ub |
filter upper bound (Hz) |
domain |
1 if the input signal is in the time domain, 0 if it is in the frequency domain |
This function is alternative R version of notch filter
filtered signal in time domain
Plot signals line by line
plot_signals( signals, sample_rate = 1, col = 1, space = 0.995, space_mode = "quantile", start_time = 0, duration = NULL, compress = TRUE, channel_names = NULL, ylab = "Channel", time_shift = 0, lwd = 0.5, cex = 2, new_plot = TRUE, plot = "base", xlim = NULL, ... )
plot_signals( signals, sample_rate = 1, col = 1, space = 0.995, space_mode = "quantile", start_time = 0, duration = NULL, compress = TRUE, channel_names = NULL, ylab = "Channel", time_shift = 0, lwd = 0.5, cex = 2, new_plot = TRUE, plot = "base", xlim = NULL, ... )
signals |
signals to plot, with each row one signal |
sample_rate |
sample rate |
col |
Color, either length of 1 or number of signals. Can be numeric or color name |
space |
space between to signals. If |
start_time |
Time in seconds at which time point the signal should be drawn |
duration |
length of 1. Time in seconds the duration of time to be drawn. Default is NULL (Total time range) |
compress |
FALSE means no compression for signals, TRUE is auto-detection, 2, 3, 4,... means compress signals by x and then plot. (usually compress signal to save time) |
channel_names |
Names for each signals. Will be Y tick labels |
ylab |
Y axis label |
plot , xlim , space_mode , time_shift , lwd , cex , new_plot
|
Deprecated |
... |
pass to |
A wrapper for shiny Progress object
progress( title, max = 1, session = getDefaultReactiveDomain(), quiet = FALSE, ... )
progress( title, max = 1, session = getDefaultReactiveDomain(), quiet = FALSE, ... )
title |
Main title for progress bar |
max |
How many steps you have for this process |
session |
shiny session, default is |
quiet |
nonreactive-only mode? default is FALSE. If TRUE, then progress bar will be hidden in shiny app |
... |
other parameters passing to |
shiny::Progress class cannot be used under non-reactive environment. rave::progress function wrap it up so that you can use it in non-reactive settings.
Plot "Welch" Periodogram
pwelch( x, fs, window = 64, noverlap = 8, nfft = 256, col = "black", xlim = NULL, ylim = NULL, main = "Welch periodogram", plot = TRUE, log = "xy", spec_func = stats::spectrum, cex = 1, ... )
pwelch( x, fs, window = 64, noverlap = 8, nfft = 256, col = "black", xlim = NULL, ylim = NULL, main = "Welch periodogram", plot = TRUE, log = "xy", spec_func = stats::spectrum, cex = 1, ... )
x |
signal |
fs |
sample rate |
window |
window length, default 128 |
noverlap |
overlap between two adjacent windows, by default is 8 |
nfft |
number of basis functions |
col , xlim , ylim , main , cex , ...
|
will be passed to plot |
plot |
logical, plot the result or not |
log |
indicates which axis should be |
spec_func |
deprecated |
Convert subject to python object
r_to_py.Subject(obj, convert = FALSE)
r_to_py.Subject(obj, convert = FALSE)
obj |
Subject class |
convert |
pass to |
Tools to load and view brain in 3D viewer
rave_brain2( subject, surfaces = "pial", use_141 = TRUE, recache = FALSE, clean_before_cache = FALSE, compute_template = FALSE, usetemplateifmissing = FALSE )
rave_brain2( subject, surfaces = "pial", use_141 = TRUE, recache = FALSE, clean_before_cache = FALSE, compute_template = FALSE, usetemplateifmissing = FALSE )
subject |
character or 'RAVE' subject instance |
surfaces |
one or more from |
use_141 |
logical, whether to use standard 141 brain |
recache |
whether to force cache data, default is false |
clean_before_cache |
whether to clean cache before redo cache, default is false |
compute_template |
logical whether to compute nearest 141 node. Please
also check |
usetemplateifmissing |
whether logical, to display template brain if subject brain not found, default is false |
Check if data is loaded for current module
rave_checks( ..., data = NULL, .raise_error = TRUE, rave_data = getDefaultDataRepository() )
rave_checks( ..., data = NULL, .raise_error = TRUE, rave_data = getDefaultDataRepository() )
... |
see details |
data |
same as |
.raise_error |
whether to raise error if data is missing |
rave_data |
internally used |
This function checks whether "ECoG" data is loaded. The format is:
"DATA+(blankspace)+TYPE"
. "DATA"
can be "power" (wavelet
transform amplitude), "phase" (complex angle), or "volt"/"voltage" (Before
wavelet). "TYPE"
can be "raw" (no reference), "referenced"
(referenced by common average reference, white matter reference, or
bipolar reference). For voltage data, there is one more special type
"full" which loads voltage data for all electrodes.
'RAVE' Context: Read and Set Context of Environments
rave_context( context, require_contexts, disallowed_context, error_msg, spos = 2L, senv, tpos = 1L, tenv )
rave_context( context, require_contexts, disallowed_context, error_msg, spos = 2L, senv, tpos = 1L, tenv )
context |
context string for target environment, optional, see ‘Details’ |
require_contexts |
characters, (optional): required context for current function. If any context is missing, the function will raise errors |
disallowed_context |
characters, (optional): defines the contexts that don't work for the function. If running within such contexts, the function will raise errors |
error_msg |
characters, (optional): if running in improper contexts, the
message to display, will passed to |
spos |
levels to go up to search for |
senv |
environment to read 'RAVE' contexts |
tpos |
levels to go up to search for |
tenv |
environment to set 'RAVE' contexts |
Context strings tells the function which context it's running,
and it will affect the behaviors of functions within its environment.
Because 'RAVE' modules are usually R packages, the context strings help
the module writers determine where the function is running. For example,
running locally, or in 'RAVE' container, or debug mode. A typical example
would be get_path
function. All external scripts used
in R packages require to be obtained using system.file
.
However, because the files are subject to change, using system file function
requires re-compile the package, which is time-consuming. Function
get_path
returns the file path relative to current
working directory during the development (in "default" context), and it
calls system.file
when 'RAVE' instance is running.
There are four contexts: "default"
, "rave_module_debug"
,
"rave_running"
, and "rave_running_local"
.
default
Default context: this means the function is running without any additional information.
rave_module_debug
Debug mode: used to develop and debug modules locally. Under the context, the function will be aware of the package that module belongs to
rave_running
If the function is running under this context,
this means it's running inside of shiny application (usually within
start_rave
). The function will be able to get more
contexts such as module ID, and current runtime environment
(ExecEnvir
)
rave_running_local
Similar to "rave_running"
, but
without run-time environment. Under this context, the module is
running locally without shiny. All reactive observers are disabled, and
the modules will be compiled into a function with all the inputs defined
by define_input
as arguments, and code within
"main.R"
as the main body of the function.
Function rave_context
uses reserved variables in the environment:
.__rave_context__.
, .__rave_package__.
,
.__rave_module__.
, and .__rave_module_instance__.
. Please
don't use these variables for other purposes. See ‘Examples’ for how to
set and read the context.
A list of current context, including the package name, module ID,
and current ExecEnvir
instance if running under "rave_running"
context.
# ------- 1. Read/Set Context --------- library(dipsaus) library(rave) # Reset context for current environment rave_context('default') # Read from current caller's environment fun <- function(...){ ctx <- rave_context() cat2('The function is running under context - ', ctx$context) cat2('The package under the context - ', ctx$package) cat2('Module ID is - ', ctx$module_id) cat2('Running instance is - ', ctx$instance) } fun() ## The function is running under context - default ## The package under the context - ## ... # Set debug context debug_env <- new.env() rave_context('rave_module_debug', tenv = debug_env) debug_env$.__rave_package__. <- 'ravebuiltins' # With debug_env, the function is aware of the package it's under with(debug_env, { fun() }) ## The function is running under context - rave_module_debug ## The package under the context - ravebuiltins ## ... # To set context within the function and affect the functions inide fun2 <- function(module_id){ # Run rave_context and then set module ID rave_context('rave_running_local') .__rave_module__. <- module_id fun() } with(debug_env, { fun2('power_explorer') }) ## The function is running under context - rave_running_local ## The package under the context - ravebuiltins ## Module ID is - power_explorer ## ... # Let's see what we can do with rave_module_debug with(debug_env, { get_path('inst/rave.yaml') }) # When I develop the package, it returns: ## "/Users/beauchamplab/.../ravebuiltins/inst/settings.yaml" # When I run in other places, it returns ## "/Users/beauchamplab/Library/R/3.6/library/ravebuiltins/rave.yaml" # ------- 2. Setting behaviors for context --------- # One way to set different behaviors is to using `ctx` ## Not run: fun <- function(){ ctx <- rave_context() switch(ctx$context, ...) } ## End(Not run) # The other way is to use S3 generics provided by R syntax fun <- rave_context_generics('fun', function(module_id, ...){}) # action for default fun.default <- function(...){ cat2('Function is not supposed to run under default context...', level = 'ERROR') } # for debug, set module ID and run with rave_running_local fun.rave_module_debug <- function(module_id, ...){ cat2('Debug mode... loading a test subject') # Do something ... like automatically mount_demo_subject # by running mount_demo_subject() rave_context('rave_running_local') .__rave_module__. <- module_id # Recall the function under rave_running_local context fun(module_id, ...) } # When running within RAVE container, local and with shiny fun.rave_running_local <- function(...){ ctx <- rave_context() cat2('Yay, running ', ctx$module_id, ' under context ', ctx$context, level='INFO') } fun.rave_running <- fun.rave_running_local # Run in default mode, expect error message fun('power_explorer') # Run in debug mode debug_env <- new.env() rave_context('rave_module_debug', tenv = debug_env) debug_env$.__rave_package__. <- 'ravebuiltins' # The function will run in debug mode, then rave_running_local with(debug_env, { fun('power_explorer') })
# ------- 1. Read/Set Context --------- library(dipsaus) library(rave) # Reset context for current environment rave_context('default') # Read from current caller's environment fun <- function(...){ ctx <- rave_context() cat2('The function is running under context - ', ctx$context) cat2('The package under the context - ', ctx$package) cat2('Module ID is - ', ctx$module_id) cat2('Running instance is - ', ctx$instance) } fun() ## The function is running under context - default ## The package under the context - ## ... # Set debug context debug_env <- new.env() rave_context('rave_module_debug', tenv = debug_env) debug_env$.__rave_package__. <- 'ravebuiltins' # With debug_env, the function is aware of the package it's under with(debug_env, { fun() }) ## The function is running under context - rave_module_debug ## The package under the context - ravebuiltins ## ... # To set context within the function and affect the functions inide fun2 <- function(module_id){ # Run rave_context and then set module ID rave_context('rave_running_local') .__rave_module__. <- module_id fun() } with(debug_env, { fun2('power_explorer') }) ## The function is running under context - rave_running_local ## The package under the context - ravebuiltins ## Module ID is - power_explorer ## ... # Let's see what we can do with rave_module_debug with(debug_env, { get_path('inst/rave.yaml') }) # When I develop the package, it returns: ## "/Users/beauchamplab/.../ravebuiltins/inst/settings.yaml" # When I run in other places, it returns ## "/Users/beauchamplab/Library/R/3.6/library/ravebuiltins/rave.yaml" # ------- 2. Setting behaviors for context --------- # One way to set different behaviors is to using `ctx` ## Not run: fun <- function(){ ctx <- rave_context() switch(ctx$context, ...) } ## End(Not run) # The other way is to use S3 generics provided by R syntax fun <- rave_context_generics('fun', function(module_id, ...){}) # action for default fun.default <- function(...){ cat2('Function is not supposed to run under default context...', level = 'ERROR') } # for debug, set module ID and run with rave_running_local fun.rave_module_debug <- function(module_id, ...){ cat2('Debug mode... loading a test subject') # Do something ... like automatically mount_demo_subject # by running mount_demo_subject() rave_context('rave_running_local') .__rave_module__. <- module_id # Recall the function under rave_running_local context fun(module_id, ...) } # When running within RAVE container, local and with shiny fun.rave_running_local <- function(...){ ctx <- rave_context() cat2('Yay, running ', ctx$module_id, ' under context ', ctx$context, level='INFO') } fun.rave_running <- fun.rave_running_local # Run in default mode, expect error message fun('power_explorer') # Run in debug mode debug_env <- new.env() rave_context('rave_module_debug', tenv = debug_env) debug_env$.__rave_package__. <- 'ravebuiltins' # The function will run in debug mode, then rave_running_local with(debug_env, { fun('power_explorer') })
Create S3 Generics that Respects 'RAVE' Context
rave_context_generics( fun_name, fun = function() { } )
rave_context_generics( fun_name, fun = function() { } )
fun_name |
generic function name |
fun |
function that set the arguments of the generic |
A generic function
RAVE Failure Message
rave_failure(message, level = "ERROR", call = NULL, .stop = TRUE)
rave_failure(message, level = "ERROR", call = NULL, .stop = TRUE)
message |
error message, character |
level |
level of error message; can be chosen from |
call |
call expression |
.stop |
stop or just return the condition |
Error condition or stop
Functions for development use
rave_ignore(...)
rave_ignore(...)
... |
Expressions |
Import Raw Signal from Non-standard Formats
rave_import_rawdata(subject_code, project_name, launch_preprocess = TRUE)
rave_import_rawdata(subject_code, project_name, launch_preprocess = TRUE)
subject_code |
subject code to search for in the raw folder |
project_name |
project name to create |
launch_preprocess |
whether to launch preprocess app, default is true |
Tools for module writers
rave_module_tools( env = NULL, data_env = getDefaultDataRepository(), quiet = FALSE )
rave_module_tools( env = NULL, data_env = getDefaultDataRepository(), quiet = FALSE )
env |
environment to save tools in |
data_env |
rave data repository returned by rave_prepare, internally used |
quiet |
logical |
Function to change rave-options
rave_options( ..., .save = TRUE, launch_gui = TRUE, host = "127.0.0.1", port = NULL )
rave_options( ..., .save = TRUE, launch_gui = TRUE, host = "127.0.0.1", port = NULL )
... |
Key-Value option pairs |
.save |
save to disk? ignored most of the time |
launch_gui |
launch shiny app? |
host |
IP address of host |
port |
Port number |
iEEG/ECoG
Data EnvironmentLoads subject data along with iEEG/ECoG
data into memory.
rave_prepare( subject, electrodes, epoch, time_range, frequency_range, data_types = c("power"), reference = "default", attach = "r", data_env = getDefaultDataRepository(), strict = FALSE, ... )
rave_prepare( subject, electrodes, epoch, time_range, frequency_range, data_types = c("power"), reference = "default", attach = "r", data_env = getDefaultDataRepository(), strict = FALSE, ... )
subject |
characters, format: |
electrodes |
integer vector, which electrodes to be loaded |
epoch |
characters, name for epoch data. For example, |
time_range |
vector of length 2. |
frequency_range |
vector of length 2 - lowest and highest frequencies. By default is all frequencies. Only applied to power and phase data. |
data_types |
vector of characters, data to be pre-loaded.
|
reference |
name of reference data. For example, |
attach |
characters or |
data_env |
environment to load data into. |
strict |
whether to check if raw data exists. Default is no (suggested) |
... |
ignored |
RAVE Preprocess Function
rave_preprocess( sidebar_width = 3, launch.browser = TRUE, host = "127.0.0.1", port = NULL, quiet = TRUE, beta = FALSE, test.mode = FALSE, modules, ver = "3", theme = "purple", ... )
rave_preprocess( sidebar_width = 3, launch.browser = TRUE, host = "127.0.0.1", port = NULL, quiet = TRUE, beta = FALSE, test.mode = FALSE, modules, ver = "3", theme = "purple", ... )
sidebar_width |
sidebar width from 1 to 11. |
launch.browser |
whether to launch browser, default is on |
host |
default is |
port |
integer port of the app |
quiet |
soft deprecated |
beta |
whether to load experimental modules, default is false |
test.mode |
passed to |
modules |
preprocess modules to load, reserved |
ver |
internally used please don't change |
theme |
color theme |
... |
used for other functions for configuration and debug only |
Function to create RAVE preprocess tools
rave_preprocess_tools(env = new.env(), ...)
rave_preprocess_tools(env = new.env(), ...)
env |
environment to save tools to |
... |
ignored |
Cache R Objects with Different levels
cache( key, val, name, replace = FALSE, global = FALSE, persist = FALSE, test = FALSE, temporary = FALSE, ... ) ## S3 method for class 'rave_running' cache( key, val, name, replace = FALSE, global = FALSE, persist = FALSE, test = FALSE, temporary = FALSE, ... ) ## S3 method for class 'rave_running_local' cache(..., global = TRUE) ## Default S3 method: cache(..., global = TRUE) cache_input( inputId, val = NULL, read_only = TRUE, ..., session = getDefaultReactiveDomain() ) clear_cache(levels = 1)
cache( key, val, name, replace = FALSE, global = FALSE, persist = FALSE, test = FALSE, temporary = FALSE, ... ) ## S3 method for class 'rave_running' cache( key, val, name, replace = FALSE, global = FALSE, persist = FALSE, test = FALSE, temporary = FALSE, ... ) ## S3 method for class 'rave_running_local' cache(..., global = TRUE) ## Default S3 method: cache(..., global = TRUE) cache_input( inputId, val = NULL, read_only = TRUE, ..., session = getDefaultReactiveDomain() ) clear_cache(levels = 1)
key |
any R object, a named list would be the best. |
val |
value to cache, if key exists, then value will not be evaluated nor saved |
name , inputId
|
character name of the dataset or input |
replace |
if true, force replace the cached object with current one |
global |
whether to cache the variable in global environment. If true, then the variable will be accessible from other instances and modules. |
persist |
logical, whether persist on the hard-disk, only used when
|
test , read_only
|
whether not to save the value if cache is not found |
temporary |
whether to use temporary map to cache, used internally. |
... |
ignored |
session |
shiny session instance |
levels |
levels when clear the cache |
Cached value, or val
. If cache and val
are both
missing, then return NULL
.
# global can be set to false within RAVE modules print(cache('a', 1, name = 'data', global = TRUE)) # returns 1 print(cache('a', 2, name = 'data', global = TRUE)) # still returns 1 # clear cache (for global=TRUE) clear_cache(levels = 1:3) print(cache('a', 2, name = 'data', global = TRUE)) # Now returns 2 # Not run `Sys.sleep` because a is cached print(cache('a', 2, name = 'data', global = TRUE)) print(cache('a', {Sys.sleep(10); 1}, name = 'data', global = TRUE)) # get data without key cache(name = 'data', global = TRUE) # clear cache that is global-only clear_cache(levels = 2) # Test (test=TRUE) if cache exists, if not, return value but no save cache(name = 'abracadabra', val = 'no cache', global = TRUE, test = TRUE) cache(name = 'abracadabra', global = TRUE) # cache module inputs ## Not run: # Need to run in package module environment cache_input('abracadabra', 'no-magic', read_only = TRUE) ## End(Not run)
# global can be set to false within RAVE modules print(cache('a', 1, name = 'data', global = TRUE)) # returns 1 print(cache('a', 2, name = 'data', global = TRUE)) # still returns 1 # clear cache (for global=TRUE) clear_cache(levels = 1:3) print(cache('a', 2, name = 'data', global = TRUE)) # Now returns 2 # Not run `Sys.sleep` because a is cached print(cache('a', 2, name = 'data', global = TRUE)) print(cache('a', {Sys.sleep(10); 1}, name = 'data', global = TRUE)) # get data without key cache(name = 'data', global = TRUE) # clear cache that is global-only clear_cache(levels = 2) # Test (test=TRUE) if cache exists, if not, return value but no save cache(name = 'abracadabra', val = 'no cache', global = TRUE, test = TRUE) cache(name = 'abracadabra', global = TRUE) # cache module inputs ## Not run: # Need to run in package module environment cache_input('abracadabra', 'no-magic', read_only = TRUE) ## End(Not run)
Open/Close a tab in RAVE main application
close_tab(module_id, tabname) open_tab(module_id, tabname)
close_tab(module_id, tabname) open_tab(module_id, tabname)
module_id |
character, module ID |
tabname |
character, tab box title |
iElvis
mgrid
fileMake iElvis
mgrid
file
read_mgrid(con, raw = FALSE)
read_mgrid(con, raw = FALSE)
con |
|
raw |
raw file or processed I guess |
John Magnotti
For debugging module packages. In all other contexts it will raise error.
reload_module_package(expose = FALSE, clear_env = FALSE)
reload_module_package(expose = FALSE, clear_env = FALSE)
expose |
whether to expose development tools to the global environment; default is no |
clear_env |
whether to clear the global environment before reloading; default is no |
Save data to "CSV", if file exists, rename old file
safe_write_csv(data, file, ..., quiet = FALSE)
safe_write_csv(data, file, ..., quiet = FALSE)
data |
data frame |
file |
"CSV" file to save |
... |
pass to |
quiet |
suppress overwrite message |
Function to save meta data to subject
save_meta(data, meta_type, project_name, subject_code)
save_meta(data, meta_type, project_name, subject_code)
data |
data table |
meta_type |
see load meta |
project_name |
project name |
subject_code |
subject code |
Function to locally save options (deprecated)
save_options()
save_options()
Get ‘shiny’ "input" and "output" objects under current context
getDefaultReactiveInput(session) ## Default S3 method: getDefaultReactiveInput(session) ## S3 method for class 'rave_module_debug' getDefaultReactiveInput(session) ## S3 method for class 'rave_running' getDefaultReactiveInput(session = shiny::getDefaultReactiveDomain()) ## S3 method for class 'rave_running_local' getDefaultReactiveInput(session) getDefaultReactiveOutput(session = shiny::getDefaultReactiveDomain()) ## Default S3 method: getDefaultReactiveOutput(session = shiny::getDefaultReactiveDomain()) ## S3 method for class 'rave_module_debug' getDefaultReactiveOutput(session = shiny::getDefaultReactiveDomain()) ## S3 method for class 'rave_running' getDefaultReactiveOutput(session = shiny::getDefaultReactiveDomain()) ## S3 method for class 'rave_running_local' getDefaultReactiveOutput(session = shiny::getDefaultReactiveDomain())
getDefaultReactiveInput(session) ## Default S3 method: getDefaultReactiveInput(session) ## S3 method for class 'rave_module_debug' getDefaultReactiveInput(session) ## S3 method for class 'rave_running' getDefaultReactiveInput(session = shiny::getDefaultReactiveDomain()) ## S3 method for class 'rave_running_local' getDefaultReactiveInput(session) getDefaultReactiveOutput(session = shiny::getDefaultReactiveDomain()) ## Default S3 method: getDefaultReactiveOutput(session = shiny::getDefaultReactiveDomain()) ## S3 method for class 'rave_module_debug' getDefaultReactiveOutput(session = shiny::getDefaultReactiveDomain()) ## S3 method for class 'rave_running' getDefaultReactiveOutput(session = shiny::getDefaultReactiveDomain()) ## S3 method for class 'rave_running_local' getDefaultReactiveOutput(session = shiny::getDefaultReactiveDomain())
session |
shiny session instance |
In shiny context, returns special reactiveValues
that refers to the inputs and outputs of shiny applications. In non-shiny
contexts, returns a fake environment related to current fake session,
for debug purpose.
Set and Return RAVE theme
set_rave_theme( theme, .set_default = FALSE, session = shiny::getDefaultReactiveDomain() )
set_rave_theme( theme, .set_default = FALSE, session = shiny::getDefaultReactiveDomain() )
theme |
|
.set_default |
whether to save current theme as default, default is no. |
session |
shiny session |
RAVE support two themes: "light" mode and "dark" mode. In "light" mode, the web application background will be light gray and white. In "dark" mode, the application background will be gray and foreground will be white.
If theme
is missing and RAVE is running as web application, then
it is set from current session, otherwise, the default theme is retrieved
from rave_options('default_theme')
. If option "default_theme"
is missing, then it defaults to "light".
theme
under current context.
# Retrieve current theme get_val(rave_options('default_theme'), default = 'light') # Set light mode set_rave_theme('light') plot(1:10, main = 'test light mode') # Set dark mode set_rave_theme('dark') plot(1:10, main = 'test dark mode')
# Retrieve current theme get_val(rave_options('default_theme'), default = 'light') # Set light mode set_rave_theme('light') plot(1:10, main = 'test light mode') # Set dark mode set_rave_theme('dark') plot(1:10, main = 'test dark mode')
Convert module to objects used in shiny
shinirize( module, session = getDefaultReactiveDomain(), test.mode = TRUE, data_env = getDefaultDataRepository() )
shinirize( module, session = getDefaultReactiveDomain(), test.mode = TRUE, data_env = getDefaultDataRepository() )
module |
|
session |
shiny session, default is current shiny session |
test.mode |
passed by |
data_env |
internally used |
Start RAVE main application
start_rave( modules = NULL, active_module = NULL, launch.browser = TRUE, theme = "purple", disable_sidebar = FALSE, simplify_header = FALSE, token = NULL, data_repo = getDefaultDataRepository(), ... ) launch_demo( modules = "power_explorer", launch.browser = TRUE, theme = "green", disable_sidebar = TRUE, simplify_header = FALSE, ... ) start_rave2( host = "127.0.0.1", port = NULL, launch.browser = TRUE, jupyter = FALSE, as_job = FALSE, ... )
start_rave( modules = NULL, active_module = NULL, launch.browser = TRUE, theme = "purple", disable_sidebar = FALSE, simplify_header = FALSE, token = NULL, data_repo = getDefaultDataRepository(), ... ) launch_demo( modules = "power_explorer", launch.browser = TRUE, theme = "green", disable_sidebar = TRUE, simplify_header = FALSE, ... ) start_rave2( host = "127.0.0.1", port = NULL, launch.browser = TRUE, jupyter = FALSE, as_job = FALSE, ... )
modules |
character vector, modules modules to load before starting application. |
active_module |
character, which module to show as default. |
launch.browser |
logical, whether to launch browser. |
theme |
character, color theme, default is |
disable_sidebar |
logical, whether to hide sidebar. |
simplify_header |
logical, whether to show simplified header. |
token |
character vector, default is |
data_repo |
internally used. |
... |
other parameters. See details. |
host , port , jupyter , as_job
|
'RAVE' 2.0 related arguments; see
|
Start 'YAEL' electrode localization
start_yael( host = "127.0.0.1", port = NULL, launch.browser = TRUE, as_job = FALSE, ... )
start_yael( host = "127.0.0.1", port = NULL, launch.browser = TRUE, as_job = FALSE, ... )
host |
host IP address |
port |
integer port number; default is random |
launch.browser |
whether to launch browsers |
as_job |
whether to launch in background; available only in 'RStudio' |
... |
passed to |
contains subject meta information after preprocessing.
meta
environment stores subject meta data
subject_id
character, subject ID, generated from project name
and subject code. For example, project name is "congruency"
and
subject code is "YAB"
, then the subject_id="congruency/YAB"
subject_code
identifier for subject
project_name
project name
dirs
stores folder paths for subject data
is_strict
whether preprocess directory is checked when initializing the instance
electrodes
electrode table (read-only)
frequencies
frequency table (read-only)
time_points
time-point table (read-only)
time_excluded
(deprecated) excluded time-point table (read-only)
sample_rate
time-point table (read-only, for compatibility issues)
volt_sample_rate
voltage (trace) sampling rate in Hertz (read-only)
power_sample_rate
power (amplitude) sampling rate in Hertz (read-only)
phase_sample_rate
phase sampling rate in Hertz (read-only)
valid_electrodes
all valid electrodes in current reference scheme (read-only)
id
read-only version of subject ID
info()
print the information of the subject
Subject$info()
none
print()
override of default print method
Subject$print(...)
...
ignored
default memory address of the environment
finalize()
called when garbage collected
Subject$finalize()
new()
constructor
Subject$new(project_name, subject_code, reference = NULL, strict = TRUE)
project_name
project name
subject_code
subject code
reference
what kind of reference is default for the subject,
default is "default", referring to "reference_default.csv"
in
subject meta folder
strict
whether to check if the raw folder exists
preprocess_info()
Obtain preprocessing information. This methods is rarely directly called, I wrap up most commonly used fields in other functions
Subject$preprocess_info(key, default = NULL, customized = FALSE)
key
the fields or items store in SubjectInfo2
instance
default
default value if the key is not found
customized
indicates whether the key refers to additional items
or fields in SubjectInfo2
. Default is false, meaning
the key is the fields.
the preprocess information correspond to the key
filter_all_electrodes()
filter, and returns existing electrodes
Subject$filter_all_electrodes(electrodes)
electrodes
integer vector
the electrodes that the subject has, including bad, or invalid electrodes.
filter_valid_electrodes()
filter, and returns valid electrodes
Subject$filter_valid_electrodes(electrodes)
electrodes
integer vector
the valid electrodes. Invalid electrodes refers to bad
electrodes, or the end of bipolar reference. If "Reference"
column is blank in the reference file, then the electrode is invalid.
has_bad_time_point()
(deprecated) check whether the selected time is excluded
Subject$has_bad_time_point(block, electrode, start, end)
block
block name
electrode
electrode number
start
start time
end
end time
clone()
The objects of this class are cloneable with this method.
Subject$clone(deep = FALSE)
deep
Whether to make a deep clone.
Zhengjia Wang
## Not run: # Load subject, use `strict=FALSE` if not sure the existence of raw files subject <- Subject$new(project_name = 'demo', 'YAB', strict = FALSE) # Filter 1:14 to see which numbers refer to the valid electrodes subject$filter_valid_electrodes(1:14) #> [1] 13 14 ## End(Not run)
## Not run: # Load subject, use `strict=FALSE` if not sure the existence of raw files subject <- Subject$new(project_name = 'demo', 'YAB', strict = FALSE) # Filter 1:14 to see which numbers refer to the valid electrodes subject$filter_valid_electrodes(1:14) #> [1] 13 14 ## End(Not run)
Create temp file in subject module folder
subject_tmpfile( module_id, fun_name = "", project_name, subject_code, pattern = "file_", data_env = getDefaultDataRepository() )
subject_tmpfile( module_id, fun_name = "", project_name, subject_code, pattern = "file_", data_env = getDefaultDataRepository() )
module_id |
module id |
fun_name |
function name (usually export_"function_name" in the module) |
project_name |
project name |
subject_code |
subject code |
pattern |
passed to |
data_env |
internally used |
SUMA
spec
fileParse SUMA
spec
file
suma_spec_parse(subject, spec_file)
suma_spec_parse(subject, spec_file)
subject |
either characters in format like |
spec_file |
default decided by |
## Not run: subject = 'Demo/YAB' # or create subject object subject = Subject$new('Demo', 'YAB') # Please download sample subjects first to run suma_spec_parse(subject) ## End(Not run)
## Not run: subject = 'Demo/YAB' # or create subject object subject = Subject$new('Demo', 'YAB') # Please download sample subjects first to run suma_spec_parse(subject) ## End(Not run)
AFNI
BRIK/HEAD
fileParse AFNI
BRIK/HEAD
file
suma_surface_volume_parse(file_path)
suma_surface_volume_parse(file_path)
file_path |
path to |
Parse 'RAVE' Module and Returns Parsed Content in Environments
to_module( module_id, sidebar_width = 3, parse_context = c("rave_running_local", "rave_running") )
to_module( module_id, sidebar_width = 3, parse_context = c("rave_running_local", "rave_running") )
module_id |
module ID |
sidebar_width |
input sidebar width |
parse_context |
parse context, default is |
Debug-use only, reload package, mount demo subject, and launch shiny app
view_layout( module_id, sidebar_width = 3, launch.browser = TRUE, reload = TRUE, ... )
view_layout( module_id, sidebar_width = 3, launch.browser = TRUE, reload = TRUE, ... )
module_id |
module ID to debug |
sidebar_width |
input width, from 1 to 11, default is 3 |
launch.browser |
whether to launch browser, default is true, other
options are |
reload |
whether to reload package first. default is true, |
... |
passed to |
The code was translated from Matlab script written by Brett Foster, Stanford Memory Lab, 2015 with permission to use in 'RAVE'.
wavelet(data, freqs, srate, wave_num, demean = TRUE)
wavelet(data, freqs, srate, wave_num, demean = TRUE)
data |
- vector of time series to be decomposed |
freqs |
- vector of center frequencies for decomposition |
srate |
- sample rate (in Hz) |
wave_num |
- desired number of cycles in wavelet (typically 3-20 for frequencies 2-200). |
demean |
- whether to remove the mean of data first? |
Decompose time series data into time-frequency representation (spectral decomposition) using wavelet transform. Employs "Morlet" wavelet method (gaussian taper sine wave) to obtain the analytic signal for specified frequencies (via convolution).
Returns wavelets to be used for wavelet function
wavelet_kernels(freqs, srate, wave_num)
wavelet_kernels(freqs, srate, wave_num)
freqs |
vector of center frequencies for decomposition |
srate |
sample rate (in Hz) |
wave_num |
desired number of cycles in wavelet (typically 3-20 for frequencies 2-200). |