Skip to content

Commit 2b0432f

Browse files
committed
update annot
1 parent 6a9bac5 commit 2b0432f

2 files changed

Lines changed: 115 additions & 101 deletions

File tree

pyneon/epochs.py

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ def __init__(self, source: Stream | Events, epochs_info: pd.DataFrame):
102102
self.sf = None
103103

104104
# Create epochs
105-
self.data = _annotate_epochs(source, epochs_info)
105+
self.annot = _annotate_epochs(source, epochs_info)
106106

107107
def __len__(self):
108108
return self.epochs_info.shape[0]
@@ -400,17 +400,19 @@ def _fit_and_subtract(epoch_df: pd.DataFrame, chan_cols: list[str]) -> None:
400400

401401
def _annotate_epochs(
402402
source: Stream | Events, epochs_info: pd.DataFrame
403-
) -> list[list[int]]:
403+
) -> dict:
404404
"""
405-
Create timestamp-wise annotations of epoch indices for the source data.
405+
Create index-wise annotations of epoch indices for the source data.
406406
"""
407407
# _check_overlap(epochs_info)
408408

409409
# Timestamps from the source
410410
ts = source.ts if isinstance(source, Stream) else source.start_ts
411-
annot = [[] for _ in range(len(ts))]
411+
source_index = source.data.index
412+
annot = {i: [] for i in source_index} # Initialize empty lists for each index
412413

413414
# Iterate over each event time to create epochs
415+
empty_epochs = []
414416
for i, row in epochs_info.iterrows():
415417
t_ref_i, t_before_i, t_after_i = row[["t_ref", "t_before", "t_after"]].to_list()
416418

@@ -419,13 +421,15 @@ def _annotate_epochs(
419421
mask = np.logical_and(ts >= start_time, ts <= end_time)
420422

421423
if not mask.any():
422-
warnings.warn(f"No data found for epoch {i}.", RuntimeWarning)
423-
continue
424-
425-
# Append the epoch index to the list for each matching row
426-
for sub_list in annot[mask]:
427-
sub_list.append(i)
428-
424+
empty_epochs.append(i)
425+
426+
# Annotate the data with the epoch index
427+
for idx in source_index[mask]:
428+
annot[idx].append(i)
429+
430+
if empty_epochs:
431+
warnings.warn(f"No data found for epoch(s): {empty_epochs}.", RuntimeWarning)
432+
429433
return annot
430434

431435

@@ -478,7 +482,7 @@ def events_to_epochs_info(
478482
else:
479483
matching_events = events.filter_by_name(event_name)
480484
t_ref = matching_events.start_ts
481-
description = matching_events["name"].to_numpy()
485+
description = matching_events.data["name"].to_numpy()
482486

483487
epochs_info = construct_epochs_info(
484488
t_ref,

0 commit comments

Comments
 (0)