| Title: | IEEG (Intracranial Electroencephalography) Epoch Data Tools |
|---|---|
| Description: | Provides tools for working with iEEG matrix data, including downloading curated iEEG data from OSF (The Open Science Framework <https://osf.io/>) (EpochDownloader()), making new objects (Epoch()), processing (crop() and resample()), and visualizing the data (plot()). |
| Authors: | Jiefei Wang [aut, cre] |
| Maintainer: | Jiefei Wang <[email protected]> |
| License: | GPL (>= 3) |
| Version: | 1.0.7 |
| Built: | 2026-05-20 05:54:09 UTC |
| Source: | https://github.com/jiefei-wang/epoch |
Check and keep valid index only
.checkIndex(indices, names).checkIndex(indices, names)
indices |
Numeric or character index to check |
names |
Character. All names corresponding to the indices |
Standardize iEEG row data for plotting
.standardizeIEEG(data, standardize = TRUE, gap = 2).standardizeIEEG(data, standardize = TRUE, gap = 2)
data |
Matrix or data frame of iEEG data |
standardize |
Logical or numeric vector. If logical, indicates whether to standardize each row. If numeric, indicates the scaling factor for each row. |
gap |
Numeric. The gap to separate different electrodes in the plot. |
Standardized data matrix
Obtain the time points for the Epoch matrix
coltimes(x) ## S4 method for signature 'Epoch' coltimes(x)coltimes(x) ## S4 method for signature 'Epoch' coltimes(x)
x |
An Epoch object |
A numeric vector of time points, or column indices if time points are not defined
Other Epoch methods:
crop(),
plot,Epoch,missing-method,
resample(),
show,Epoch-method
# Create an Epoch object epoch_data <- matrix(rnorm(1000), nrow = 10) rownames(epoch_data) <- paste0("Electrode_", 1:10) epoch <- Epoch(epoch_data, startTime = 0, samplingRate = 100) # get the time points of an Epoch object coltimes(epoch)# Create an Epoch object epoch_data <- matrix(rnorm(1000), nrow = 10) rownames(epoch_data) <- paste0("Electrode_", 1:10) epoch <- Epoch(epoch_data, startTime = 0, samplingRate = 100) # get the time points of an Epoch object coltimes(epoch)
Truncating iEEG data to a specific time range.
crop(x, start, end, ...) ## S4 method for signature 'Epoch' crop(x, start, end, checkTimeRange = TRUE)crop(x, start, end, ...) ## S4 method for signature 'Epoch' crop(x, start, end, checkTimeRange = TRUE)
x |
An Epoch object |
start |
Numeric value specifying start of new time range |
end |
Numeric value specifying end of new time range |
... |
Not used |
checkTimeRange |
Logical, whether to check the validity of the time range. This includes checking if the time range is empty, if |
clip the time range of the Epoch object
Other Epoch methods:
coltimes(),
plot,Epoch,missing-method,
resample(),
show,Epoch-method
# Create an Epoch object epoch_data <- matrix(rnorm(1000), nrow = 10) rownames(epoch_data) <- paste0("Electrode_", 1:10) epoch <- Epoch(epoch_data, startTime = 0, samplingRate = 100) # crop the epoch crop(epoch, start = 0.5, end = 1.5)# Create an Epoch object epoch_data <- matrix(rnorm(1000), nrow = 10) rownames(epoch_data) <- paste0("Electrode_", 1:10) epoch <- Epoch(epoch_data, startTime = 0, samplingRate = 100) # crop the epoch crop(epoch, start = 0.5, end = 1.5)
Wrapper functions for calling TableContainer methods
## S4 method for signature 'Epoch' dim(x) ## S4 method for signature 'Epoch' dimnames(x) ## S4 method for signature 'Epoch' x[i, j, ..., drop = TRUE]## S4 method for signature 'Epoch' dim(x) ## S4 method for signature 'Epoch' dimnames(x) ## S4 method for signature 'Epoch' x[i, j, ..., drop = TRUE]
x |
An Epoch object |
i |
Row indices for subsetting. If only |
j |
Column indices for subsetting. |
... |
Additional arguments. |
drop |
Not used. |
[: A new Epoch object with the selected data.
# Create an Epoch object epoch_data <- matrix(rnorm(1000), nrow = 10) rownames(epoch_data) <- paste0("Electrode_", 1:10) epoch <- Epoch(epoch_data, startTime = 0, samplingRate = 100) # wrappers dim(epoch) dimnames(epoch) epoch[1]# Create an Epoch object epoch_data <- matrix(rnorm(1000), nrow = 10) rownames(epoch_data) <- paste0("Electrode_", 1:10) epoch <- Epoch(epoch_data, startTime = 0, samplingRate = 100) # wrappers dim(epoch) dimnames(epoch) epoch[1]
Constructor for Epoch class
Epoch( table, electrodes = NULL, times = NULL, startTime = NULL, samplingRate = NULL, rowData = NULL, colData = NULL, metaData = NULL )Epoch( table, electrodes = NULL, times = NULL, startTime = NULL, samplingRate = NULL, rowData = NULL, colData = NULL, metaData = NULL )
table |
Matrix containing epoch data (rows=electrodes, columns=time points) |
electrodes |
Optional character vector for electrode names, if not provided, row names of data are used. If row names are also not available, there will be no electrode names. |
times |
Optional numeric vector of time points. |
startTime |
Optional numeric value for start time, if provided, times will be calculated based on this and samplingRate. |
samplingRate |
Optional numeric value for sampling rate, if provided, times will be calculated based on this and startTime. |
rowData |
Optional data frame containing metadata for rows (electrodes). |
colData |
Optional data frame containing metadata for columns (time points). |
metaData |
Optional list containing metadata for the Epoch object. Element name "SamplingRate" is reserved by the Epoch class. |
An Epoch object
epoch_data <- matrix(rnorm(1000), nrow = 10) rownames(epoch_data) <- paste0("Electrode_", 1:10) epoch <- Epoch(epoch_data, startTime = 0, samplingRate = 100)epoch_data <- matrix(rnorm(1000), nrow = 10) rownames(epoch_data) <- paste0("Electrode_", 1:10) epoch <- Epoch(epoch_data, startTime = 0, samplingRate = 100)
S4 class to handle epoch data with electrodes and time points
tablea matrix containing iEEG data (columns=time points, rows=electrodes)
colDataa data frame containing metadata for columns (time points)
rowDataa data frame containing metadata for rows (electrodes)
metaDataa list containing metadata for the Epoch object
Manually update the project list from the remote repository. This function will attempt to download the latest configuration from the GitHub repository. If it fails, the current configuration will remain unchanged.
This function returns the list of available projects. If the configuration has not been fetched yet, it will automatically update the project list from the remote repository.
EpochDownloader(id = NULL, progress = TRUE, verbose = FALSE, path = NULL) ## S4 method for signature 'EpochDownloader' names(x) ## S4 method for signature 'EpochDownloader' x[i] ## S4 method for signature 'EpochDownloader' x$name ## S4 method for signature 'EpochDownloader' x[[i]] ## S4 method for signature 'EpochDownloader' show(object) ## S4 method for signature 'EpochDownloader' length(x) wiki(x, ...) ## S4 method for signature 'EpochDownloader' wiki(x) updateRepos(verbose = FALSE) EpochRepos(verbose = TRUE)EpochDownloader(id = NULL, progress = TRUE, verbose = FALSE, path = NULL) ## S4 method for signature 'EpochDownloader' names(x) ## S4 method for signature 'EpochDownloader' x[i] ## S4 method for signature 'EpochDownloader' x$name ## S4 method for signature 'EpochDownloader' x[[i]] ## S4 method for signature 'EpochDownloader' show(object) ## S4 method for signature 'EpochDownloader' length(x) wiki(x, ...) ## S4 method for signature 'EpochDownloader' wiki(x) updateRepos(verbose = FALSE) EpochRepos(verbose = TRUE)
id |
Either the ID of an OSF project or the name of an iEEG projects (case insensitive). Check the available projects using |
progress |
Logical indicating whether to show progress during download. |
verbose |
Logical indicating whether to show messages |
path |
The path to the temporary folder where the files will be downloaded. |
x |
An |
i |
Index or name of the files to be accessed. |
name |
The name of the file to be accessed. |
object |
An |
... |
Not used, for future extensibility |
EpochDownloader: An EpochDownloader object.
names: A character vector of file names.
[: A named list of Epoch objects. The names are the dataset names.
$: A single Epoch object.
[[: A single Epoch object.
show: Prints a summary of the EpochDownloader object.
length: Returns the number of files in the EpochDownloader object.
wiki: Opens the wiki page in the default browser
updateRepos: No return value, called for side effects.
EpochRepos: A list of project names and their corresponding OSF project IDs.
# list all available projects EpochRepos() # downloader for the fragility data dl <- EpochDownloader(id = "fragility") # list all Epoch objects in the downloader names(dl) # download the first Epoch object dl[1] # equivalent to (index by name) dl[names(dl)[1]] # download the multiple Epoch objects dl[c(1, 2)] # equivalent to (index by name) dl[names(dl)[c(1, 2)]] EpochRepos()# list all available projects EpochRepos() # downloader for the fragility data dl <- EpochDownloader(id = "fragility") # list all Epoch objects in the downloader names(dl) # download the first Epoch object dl[1] # equivalent to (index by name) dl[names(dl)[1]] # download the multiple Epoch objects dl[c(1, 2)] # equivalent to (index by name) dl[names(dl)[c(1, 2)]] EpochRepos()
EpochDownloader is a class that allows
downloading and accessing files from a OSF project.
idThe ID of the OSF project.
filesThe files in the OSF project.
dataNamesThe names of the files in the OSF project.
tmp_folderThe temporary folder where the files are downloaded.
progressLogical indicating whether to show progress during download.
Get configuration data from remote URL
get_config_data()get_config_data()
A list of project configurations
Plot method for Epoch objects
## S4 method for signature 'Epoch,missing' plot( x, y, gap = 2, groupIndex = NULL, timeResolution = 2048, maxLabels = 50, linewidth = 0.2, x.lab.size = 10, y.lab.size = 10, standardize = TRUE, ... )## S4 method for signature 'Epoch,missing' plot( x, y, gap = 2, groupIndex = NULL, timeResolution = 2048, maxLabels = 50, linewidth = 0.2, x.lab.size = 10, y.lab.size = 10, standardize = TRUE, ... )
x |
An Epoch object |
y |
Not used (for S4 method compatibility) |
gap |
Numeric value specifying the gap between electrode traces (default: 2) |
groupIndex |
Integer or string. A group of electrodes to show together in a different color. If NULL(default), all electrodes are shown in the same color. |
timeResolution |
Maximum number of time points to keep for each electrode (default: 2048) |
maxLabels |
Maximum number of electrode labels to display on the y-axis (default: 50) |
linewidth |
Line width for the electrode traces (default: 0.2) |
x.lab.size |
Size of the x-axis label text (default: 10) |
y.lab.size |
Size of the y-axis label text (default: 10) |
standardize |
If the parameter is a logical value, it indicates whether to standardize the iEEG data across time for each electrode. If it is a logical vector with length equal to the number of electrodes, it indicates whether to standardize each electrode individually. If it is a numeric vector with length equal to the number of electrodes, it indicates the standard deviation to use for standardization for each electrode. (default: TRUE). |
... |
Additional arguments (not currently used) |
plot: A ggplot object showing iEEG electrode traces
Other Epoch methods:
coltimes(),
crop(),
resample(),
show,Epoch-method
# Create an Epoch object epoch_data <- matrix(rnorm(1000), nrow = 10) rownames(epoch_data) <- paste0("Electrode_", 1:10) epoch <- Epoch(epoch_data, startTime = 0, samplingRate = 100) # Plot the epoch plot(epoch)# Create an Epoch object epoch_data <- matrix(rnorm(1000), nrow = 10) rownames(epoch_data) <- paste0("Electrode_", 1:10) epoch <- Epoch(epoch_data, startTime = 0, samplingRate = 100) # Plot the epoch plot(epoch)
This function allows you to resample an object to a different sampling frequency.
This function allows you to resample an Epoch object to a different sampling frequency.
resample(x, ...) ## S4 method for signature 'Epoch' resample(x, samplingRate, ...)resample(x, ...) ## S4 method for signature 'Epoch' resample(x, samplingRate, ...)
x |
An |
... |
Additional arguments passed to |
samplingRate |
The new sampling frequency (unit: Hertz). |
An Epoch object with the resampled data.
Other Epoch methods:
coltimes(),
crop(),
plot,Epoch,missing-method,
show,Epoch-method
# Create an Epoch object epoch_data <- matrix(rnorm(1000), nrow = 10) rownames(epoch_data) <- paste0("Electrode_", 1:10) epoch <- Epoch(epoch_data, startTime = 0, samplingRate = 100) # downsample the epoch to 50 Hz resample(epoch, samplingRate = 50) # upsample the epoch to 200 Hz resample(epoch, samplingRate = 200)# Create an Epoch object epoch_data <- matrix(rnorm(1000), nrow = 10) rownames(epoch_data) <- paste0("Electrode_", 1:10) epoch <- Epoch(epoch_data, startTime = 0, samplingRate = 100) # downsample the epoch to 50 Hz resample(epoch, samplingRate = 50) # upsample the epoch to 200 Hz resample(epoch, samplingRate = 200)
Print the Epoch Object
## S4 method for signature 'Epoch' show(object)## S4 method for signature 'Epoch' show(object)
object |
Epoch object |
returns an invisible NULL
Other Epoch methods:
coltimes(),
crop(),
plot,Epoch,missing-method,
resample()