From ba47053cdd41ac5b9f23df591934f0f0476c1012 Mon Sep 17 00:00:00 2001 From: dipterix Date: Wed, 18 Dec 2024 18:57:19 -0500 Subject: [PATCH] Fixed time slice (begin+end) issue --- DESCRIPTION | 2 +- R/edf.R | 15 ++++++++------- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 66bdacc..7f5f6f4 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: ieegio Title: File IO for Intracranial Electroencephalography -Version: 0.0.2.9001 +Version: 0.0.2.9002 Language: en-US Encoding: UTF-8 Authors@R: diff --git a/R/edf.R b/R/edf.R index 298e9f8..9f28b83 100644 --- a/R/edf.R +++ b/R/edf.R @@ -628,9 +628,6 @@ internal_read_edf_signal <- function(con, channels, begin = 0, end = Inf, conver warning("EDF file annotations: the first annotation in the first 'EDF Annotations' signal must have timestamp.") } - annots$add(annot) - timestamps$add(timestamp) - slice_start <- timestamp slice_finish <- slice_start + record_duration @@ -638,6 +635,9 @@ internal_read_edf_signal <- function(con, channels, begin = 0, end = Inf, conver env$previous_finish <- slice_finish if( slice_finish < begin || slice_start >= end ) { return() } + annots$add(annot) + timestamps$add(timestamp) + # annot$duration <- slice_duration lapply(seq_len(n_channels), function(ii) { @@ -686,7 +686,6 @@ internal_read_edf_signal <- function(con, channels, begin = 0, end = Inf, conver seg <- c(seg, rep(0.0, samples_per_record - slen)) } time <- seg_start + time_0 - # cut time later # if( time[[1]] < begin || time[[length(time)]] >= end ) { # sel <- time >= begin & time < end @@ -867,16 +866,18 @@ read_edf <- function( filebase <- file_path(extract_path, sprintf("Ch%d", chn)) channel_data <- data$results[[ii]] - signal_length <- length(channel_data$value) + sel <- channel_data$time >= begin & channel_data$time < end + signal_length <- sum(sel) + farr <- filearray::filearray_load_or_create( filebase, dimension = c(signal_length, 2L), - type = "double", + type = "float", partition_size = 2L, mode = "readwrite", symlink_ok = FALSE ) - farr[] <- cbind(channel_data$value, channel_data$time) + farr[] <- cbind(channel_data$value[sel], channel_data$time[sel]) farr$set_header(key = "source_header", value = data$header, save = FALSE)