Skip to content

Commit 20b9784

Browse files
Fix bug when 2 signals in a pair are not perfectly aligned for wavelet coherence (#232)
Add length of signal to the wavelet caching key. There are cases where 2 signals in a pair are not exactly the same length (one sample of difference). In these cases the longest signal is cropped. But when computing intra, we reuse the same signal (not from the pair), so we should load a cropped cached signal.
1 parent 6789b00 commit 20b9784

1 file changed

Lines changed: 4 additions & 1 deletion

File tree

hypyp/wavelet/base_wavelet.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -424,9 +424,12 @@ def _get_cache_key_pair(self, pair: PairSignals, subject_idx: int, obj_id: str,
424424
if subject_idx == 0:
425425
subject_label = pair.label_s1
426426
ch_name = pair.label_ch1
427+
# include signal length in key because it might have been croped to align y1 and y2
428+
n = len(pair.y1)
427429
elif subject_idx == 1:
428430
subject_label = pair.label_s2
429431
ch_name = pair.label_ch2
432+
n = len(pair.y2)
430433
else:
431434
raise RuntimeError(f'subject_idx must be 0 or 1')
432435

@@ -437,7 +440,7 @@ def _get_cache_key_pair(self, pair: PairSignals, subject_idx: int, obj_id: str,
437440
raise RuntimeError(f'must have task to have unique identifiers in caching')
438441

439442
time_range_str = f'{pair.x[0]}-{pair.x[-1]}'
440-
key = f'[{subject_label}][{ch_name}][{pair.label_task}][{pair.epoch_idx}][{pair.x[0]}-{pair.x[-1]}][{time_range_str}][{obj_id}]'
443+
key = f'[{subject_label}][{ch_name}][{pair.label_task}][{pair.epoch_idx}][{n}][{pair.x[0]}-{pair.x[-1]}][{time_range_str}][{obj_id}]'
441444
if cache_suffix != '':
442445
key += f'_{cache_suffix}'
443446

0 commit comments

Comments
 (0)