Skip to content

Commit

Permalink
Merge pull request #74 from craddm/use_new_summary
Browse files Browse the repository at this point in the history
Use new summary
  • Loading branch information
craddm committed Feb 21, 2021
2 parents 65ac6ad + 1e07eae commit 72787e0
Show file tree
Hide file tree
Showing 135 changed files with 3,227 additions and 1,038 deletions.
28 changes: 0 additions & 28 deletions .travis.yml

This file was deleted.

8 changes: 5 additions & 3 deletions DESCRIPTION
Expand Up @@ -5,7 +5,8 @@ Version: 0.6.0
Date: 2021-01-27
Authors@R: c(
person("Matt", "Craddock", role = c("aut", "cre", "cph"), email = "matt@mattcraddock.com"),
person("Matti", "Vuorre", role = "ctb", email = "mv2521@columbia.edu"))
person("Matti", "Vuorre", role = "ctb", email = "mv2521@columbia.edu"),
person("ggplot2 authors", role = c("ctb", "cph"), comment = "Routines borrowed from ggplot2 to allow countours to be drawn on topoplots"))
Maintainer: Matt Craddock <matt@mattcraddock.com>
Description: EEG processing and visualization tools. Includes import
functions for 'BioSemi' (.BDF), 'Neuroscan' (.CNT), 'Brain Vision Analyzer' (.VHDR),
Expand All @@ -17,7 +18,7 @@ Encoding: UTF-8
LazyData: true
Imports:
ggplot2,
dplyr,
dplyr (>= 1.0.0),
scales,
mgcv,
purrr,
Expand All @@ -36,7 +37,8 @@ Imports:
data.table,
plotly,
future.apply,
Rcpp
Rcpp,
isoband
Depends:
R (>= 3.3.0)
RoxygenNote: 7.1.1
Expand Down
5 changes: 5 additions & 0 deletions NAMESPACE
Expand Up @@ -41,8 +41,10 @@ S3method(compute_csd,eeg_epochs)
S3method(compute_psd,eeg_data)
S3method(compute_psd,eeg_epochs)
S3method(compute_psd,eeg_evoked)
S3method(compute_psd,eeg_group)
S3method(compute_tfr,default)
S3method(compute_tfr,eeg_epochs)
S3method(compute_tfr,eeg_group)
S3method(eeg_average,default)
S3method(eeg_average,eeg_epochs)
S3method(eeg_average,eeg_evoked)
Expand Down Expand Up @@ -119,6 +121,7 @@ S3method(plot_psd,eeg_ICA)
S3method(plot_psd,eeg_data)
S3method(plot_psd,eeg_epochs)
S3method(plot_psd,eeg_evoked)
S3method(plot_psd,eeg_group)
S3method(plot_timecourse,data.frame)
S3method(plot_timecourse,default)
S3method(plot_timecourse,eeg_ICA)
Expand Down Expand Up @@ -176,6 +179,7 @@ S3method(topoplot,eeg_tfr)
export("channels<-")
export("epochs<-")
export("events<-")
export(StatScalpContours)
export(StatScalpmap)
export(apply_ica)
export(ar_FASTER)
Expand Down Expand Up @@ -251,6 +255,7 @@ export(select_elecs)
export(select_epochs)
export(select_freqs)
export(select_times)
export(stat_scalpcontours)
export(stat_scalpmap)
export(tag_epochs)
export(tag_events)
Expand Down
22 changes: 21 additions & 1 deletion NEWS.md
@@ -1,9 +1,29 @@
# eegUtils 0.6.0.9999

### Function changes

- `ar_eogcor` now has a `bipolarize` argument which can be set to false when the HEOG/VEOG channels are already bipolarized.
- added some new `ggplot2` based functions for topoplotting and adding contours
- `stat_scalpcontours()`
- `geom_topo()` now has contours
- added errors with when attempting to use `compute_psd` or `compute_tfr` on `eeg_group` objects.


### Internal changes / bug fixes

- `eeg_reference` now handles multiple reference channels better on rereferencing
- `get_scalpmap` handles `eeg_ICA` components better when there are channels with no locations
- Travis-CI removed.
- `cart_to_spherical` coord flipping bug fixed (hopefully...)
- `filter` now converts to tibble internally and does not coerce `signals` to a vector when there is only one channel.
- added copyright info to `summary_contour` file

# eegUtils 0.6.0

IMPORTANT: There have been some changes to the logic of the `topoplot()` that may make their appearance quite different. Specifically, these changes are to the way the underlying interpolation grid is calculated and to how things like the diameter of the cartoon head is calculated. These changes often lead to different minimum or maximum amplitudes across the image, and thus changes in the appearance of the plot due to different scales- don't be alarmed!

### Function changes
- `epoch_data` baseline correction no defaults to *no* baseline correction
- `epoch_data` baseline correction now defaults to *no* baseline correction
- Added `filter` method for `eeg_tfr` objects
- `fit_glm()` overhauled. Now far faster and allows specification of models using standard R formulae.
- New `eeg_lm` class introduced for output of `fit_glm()`.
Expand Down
12 changes: 9 additions & 3 deletions R/artefact_rejection.R
Expand Up @@ -283,6 +283,7 @@ ar_eogcor <- function(decomp,
#' @param threshold Threshold for correlation (r). Defaults to NULL,
#' automatically determining a threshold.
#' @param plot Plot correlation coefficient for all components
#' @param bipolarize Bipolarize the HEOG and VEOG channels?
#' @describeIn ar_eogcor Method for eeg_ICA objects.
#' @export
ar_eogcor.eeg_ICA <- function(decomp,
Expand All @@ -291,6 +292,7 @@ ar_eogcor.eeg_ICA <- function(decomp,
VEOG,
threshold = NULL,
plot = TRUE,
bipolarize = TRUE,
...) {

if (!is.null(threshold)) {
Expand All @@ -302,9 +304,13 @@ ar_eogcor.eeg_ICA <- function(decomp,
}

EOG_corrs <- abs(stats::cor(decomp$signals,
bip_EOG(data$signals,
HEOG,
VEOG)))
if (bipolarize) {
bip_EOG(data$signals,
HEOG,
VEOG)
} else {
data$signals[,c("HEOG", "VEOG")]
}))

if (is.null(threshold)) {
mean_corrs <- colMeans(EOG_corrs)
Expand Down
2 changes: 1 addition & 1 deletion R/channel_management.R
Expand Up @@ -741,7 +741,7 @@ cart_to_spherical <- function(xyz_coords) {
phi <- rad2deg(atan(xyz_coords$cart_y / xyz_coords$cart_x))
theta <- rad2deg(acos(xyz_coords$cart_z / radius))
theta <- ifelse(xyz_coords$cart_x >= 0, theta, -theta)
phi <- ifelse(xyz_coords$cart_x == 0, -phi, phi)
#phi <- ifelse(xyz_coords$cart_x == 0, -phi, phi) why is this here?
phi <- ifelse(is.nan(phi), 0, phi)
data.frame(radius = 1,
theta = round(theta),
Expand Down
6 changes: 3 additions & 3 deletions R/current_source_density.R
Expand Up @@ -96,9 +96,9 @@ interp_elecs.eeg_data <- function(data,
xyz_coords)

data$signals <- interp_chans(data$signals,
bad_elecs,
missing_coords = missing_coords,
weights)
bad_elecs,
missing_coords = missing_coords,
weights)
data
}

Expand Down
15 changes: 9 additions & 6 deletions R/data_averaging.R
Expand Up @@ -47,12 +47,15 @@ eeg_average.eeg_epochs <- function(data,
data$signals <- dplyr::left_join(cbind(data$signals,
data$timings),
data$epochs, by = "epoch")

if (!is.null(cols)) {
if ("participant_id" %in% cols) {
col_names <- cols
if (identical(cols, "everything")) {
col_names <- "participant_id"
} else {
col_names <- c("participant_id", cols)
if ("participant_id" %in% cols) {
col_names <- cols
} else {
col_names <- c("participant_id", cols)
}
}
} else {
col_names <- names(data$epochs)
Expand All @@ -72,8 +75,8 @@ eeg_average.eeg_epochs <- function(data,

epochs <- dplyr::select(timings,
epoch,
!!col_names) %>%
dplyr::distinct()
!!col_names)
epochs <- dplyr::distinct(epochs)

class(epochs) <- c("epoch_info",
"tbl_df",
Expand Down
2 changes: 1 addition & 1 deletion R/data_modifiers.R
Expand Up @@ -99,7 +99,7 @@ do_referencing <- function(data,

existing_ref <- data$reference$ref_chans

if (ref_chans %in% existing_ref) {
if (any(ref_chans %in% existing_ref)) {
if (verbose) {
message(paste0("You have used the existing reference channel(s), ",
paste(existing_ref, collapse = " & "),
Expand Down
2 changes: 1 addition & 1 deletion R/dplyr-extensions.R
Expand Up @@ -14,7 +14,7 @@ filter.eeg_epochs <- function(.data,
# labels etc. filter out anything that matches the criteria then return to
# original format. May want to recode this?

.data$signals <- as.data.frame(.data)
.data$signals <- tibble::as_tibble(.data)
.data$signals <- dplyr::filter(.data$signals,
...)
.data$signals <- .data$signals[, orig_cols]
Expand Down
92 changes: 51 additions & 41 deletions R/frequency_analysis.R
Expand Up @@ -130,7 +130,7 @@ compute_psd.eeg_epochs <- function(data,
} else if (noverlap >= seg_length) {
stop("noverlap should not be larger than seg_length.")
}
if (method == "Welch") {
if (identical(method, "Welch")) {
final_output <-
lapply(data$signals,
function(x) welch_fft(x,
Expand Down Expand Up @@ -170,43 +170,57 @@ compute_psd.eeg_evoked <- function(data,
demean = TRUE,
verbose = TRUE,
...) {
if (demean) {
data <- rm_baseline(data, verbose = verbose)
}
srate <- data$srate

if (is.null(seg_length)) {
seg_length <- n_fft
}

if (seg_length > n_fft) {
stop("seg_length cannot be greater than n_fft")
}

n_times <- nrow(data$signals)
if (n_times < seg_length) {
seg_length <- n_times
}

if (is.null(noverlap)) {
noverlap <- seg_length %/% 8
} else if (noverlap >= seg_length) {
stop("noverlap should not be larger than seg_length.")
}

if (method == "Welch") {
final_output <-
welch_fft(data$signals,
seg_length,
noverlap = noverlap,
n_fft = n_fft,
srate = srate,
n_sig = n_times)
} else {
stop("Welch is the only available method at this time.")
}
NextMethod("compute_psd", data)
# if (demean) {
# data <- rm_baseline(data, verbose = verbose)
# }
# srate <- data$srate
#
# if (is.null(seg_length)) {
# seg_length <- n_fft
# }
#
# if (seg_length > n_fft) {
# stop("seg_length cannot be greater than n_fft")
# }
#
# n_times <- nrow(data$signals)
# if (n_times < seg_length) {
# seg_length <- n_times
# }
#
# if (is.null(noverlap)) {
# noverlap <- seg_length %/% 8
# } else if (noverlap >= seg_length) {
# stop("noverlap should not be larger than seg_length.")
# }
#
# if (identical(method, "Welch")) {
# final_output <-
# welch_fft(data$signals,
# seg_length,
# noverlap = noverlap,
# n_fft = n_fft,
# srate = srate,
# n_sig = n_times)
# } else {
# stop("Welch is the only available method at this time.")
# }
#
# final_output
}

final_output
#' @noRd
#' @export
compute_psd.eeg_group <- function(data,
seg_length = NULL,
noverlap = NULL,
n_fft = 256,
method = "Welch",
demean = TRUE,
verbose = TRUE,
...) {
stop("Cannot compute psd for `eeg_group` objects.")
}

#' Welch fft
Expand Down Expand Up @@ -335,7 +349,3 @@ split_vec <- function(vec,
segs

}




0 comments on commit 72787e0

Please sign in to comment.