From 308fc529f6b237a7f581f45a6b65b04d5506e3c4 Mon Sep 17 00:00:00 2001 From: dipterix Date: Wed, 18 Dec 2024 18:11:19 -0500 Subject: [PATCH] Using single-sided selections when getting channels with `end` specified --- R/bci2000-cache.R | 2 +- R/brainvis-cache.R | 2 +- R/edf-cache.R | 2 +- R/edf.R | 6 +++--- R/nsx-cache.R | 2 +- 5 files changed, 7 insertions(+), 7 deletions(-) diff --git a/R/bci2000-cache.R b/R/bci2000-cache.R index 13126de..d6afe18 100644 --- a/R/bci2000-cache.R +++ b/R/bci2000-cache.R @@ -79,7 +79,7 @@ BCI2000Cache <- R6::R6Class( arr <- private$.filearray signals <- subset(arr, Time ~ Time >= begin & - Time <= end, + Time < end, ChannelOrder ~ ChannelOrder == x, drop = FALSE) time <- as.numeric(rownames(signals)) diff --git a/R/brainvis-cache.R b/R/brainvis-cache.R index 94edf05..d577fae 100644 --- a/R/brainvis-cache.R +++ b/R/brainvis-cache.R @@ -82,7 +82,7 @@ BrainVisionCache <- R6::R6Class( arr <- private$.filearray signals <- subset(arr, Time ~ Time >= begin & - Time <= end, + Time < end, ChannelOrder ~ ChannelOrder == x, drop = FALSE) time <- as.numeric(rownames(signals)) diff --git a/R/edf-cache.R b/R/edf-cache.R index fcc9ea5..8b035a4 100644 --- a/R/edf-cache.R +++ b/R/edf-cache.R @@ -62,7 +62,7 @@ EBDFCache <- R6::R6Class( arr <- filearray::filearray_load(file_path(private$.root_path, sprintf("Ch%d", chan)), mode = "readonly") # select time time <- arr[, 2] - sel <- time >= begin & time <= end + sel <- time >= begin & time < end # load data time <- time[sel] diff --git a/R/edf.R b/R/edf.R index 28cabbf..298e9f8 100644 --- a/R/edf.R +++ b/R/edf.R @@ -567,7 +567,7 @@ internal_read_edf_signal <- function(con, channels, begin = 0, end = Inf, conver # trying to obtain the timestamp # estimate earliest start earliest_start <- env$previous_finish - if( earliest_start > end ) { return() } + if( earliest_start >= end ) { return() } record <- read_next_record() @@ -636,7 +636,7 @@ internal_read_edf_signal <- function(con, channels, begin = 0, end = Inf, conver slice_finish <- slice_start + record_duration env$previous_finish <- slice_finish - if( slice_finish < begin || slice_start > end ) { return() } + if( slice_finish < begin || slice_start >= end ) { return() } # annot$duration <- slice_duration @@ -688,7 +688,7 @@ internal_read_edf_signal <- function(con, channels, begin = 0, end = Inf, conver time <- seg_start + time_0 # cut time later - # if( time[[1]] < begin || time[[length(time)]] > end ) { + # if( time[[1]] < begin || time[[length(time)]] >= end ) { # sel <- time >= begin & time < end # seg <- seg[sel] # time <- time[sel] diff --git a/R/nsx-cache.R b/R/nsx-cache.R index a075439..bac7440 100644 --- a/R/nsx-cache.R +++ b/R/nsx-cache.R @@ -75,7 +75,7 @@ NSXCache <- R6::R6Class( slen <- length(part$data) time <- seq(part$meta$relative_time, length.out = slen, by = 1 / sample_rate) - sel <- time >= begin & time <= end + sel <- time >= begin & time < end if(!any(sel)) { return() }