Skip to content

Commit

Permalink
Fixed time slice (begin+end) issue
Browse files Browse the repository at this point in the history
  • Loading branch information
dipterix committed Dec 18, 2024
1 parent 308fc52 commit ba47053
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -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:
Expand Down
15 changes: 8 additions & 7 deletions R/edf.R
Original file line number Diff line number Diff line change
Expand Up @@ -628,16 +628,16 @@ 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

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) {
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit ba47053

Please sign in to comment.