Test realigning raw.
(ratio_other, start_raw, start_other, stop_raw, stop_other)
| 16 | @pytest.mark.parametrize("start_raw, start_other", [(0, 0), (0, 3), (3, 0)]) |
| 17 | @pytest.mark.parametrize("stop_raw, stop_other", [(0, 0), (0, 3), (3, 0)]) |
| 18 | def test_realign(ratio_other, start_raw, start_other, stop_raw, stop_other): |
| 19 | """Test realigning raw.""" |
| 20 | # construct a true signal |
| 21 | sfreq = 100.0 |
| 22 | duration = 50 |
| 23 | stop_raw = duration - stop_raw |
| 24 | stop_other = duration - stop_other |
| 25 | signal_len = 0.2 |
| 26 | box_len = 0.5 |
| 27 | signal = np.zeros(int(round((duration + 1) * sfreq))) |
| 28 | orig_events = np.round( |
| 29 | np.arange(max(start_raw, start_other) + 2, min(stop_raw, stop_other) - 2) |
| 30 | * sfreq |
| 31 | ).astype(int) |
| 32 | signal[orig_events] = 1.0 |
| 33 | n_events = len(orig_events) |
| 34 | times = np.arange(len(signal)) / sfreq |
| 35 | stim = np.convolve(signal, np.ones(int(round(box_len * sfreq))))[: len(times)] |
| 36 | signal = np.convolve(signal, np.hanning(int(round(signal_len * sfreq))))[ |
| 37 | : len(times) |
| 38 | ] |
| 39 | |
| 40 | # construct our sampled versions of these signals (linear interp is fine) |
| 41 | sfreq_raw = sfreq |
| 42 | sfreq_other = ratio_other * sfreq |
| 43 | raw_times = np.arange(start_raw, stop_raw, 1.0 / sfreq_raw) |
| 44 | other_times = np.arange(start_other, stop_other, 1.0 / sfreq_other) |
| 45 | assert raw_times[0] >= times[0] |
| 46 | assert raw_times[-1] <= times[-1] |
| 47 | assert other_times[0] >= times[0] |
| 48 | assert other_times[-1] <= times[-1] |
| 49 | data_raw = np.array( |
| 50 | [ |
| 51 | interp1d(times, d, kind)(raw_times) |
| 52 | for d, kind in ( |
| 53 | (stim, "nearest"), |
| 54 | (signal, "linear"), |
| 55 | ) |
| 56 | ] |
| 57 | ) |
| 58 | data_other = np.array( |
| 59 | [ |
| 60 | interp1d(times, d, kind)(other_times) |
| 61 | for d, kind in ( |
| 62 | (stim, "nearest"), |
| 63 | (signal, "linear"), |
| 64 | ) |
| 65 | ] |
| 66 | ) |
| 67 | info_raw = create_info(["raw_stim", "raw_signal"], sfreq, ["stim", "eeg"]) |
| 68 | info_other = create_info(["other_stim", "other_signal"], sfreq, ["stim", "eeg"]) |
| 69 | raw = RawArray(data_raw, info_raw, first_samp=111) # first_samp shouldn't matter |
| 70 | other = RawArray(data_other, info_other, first_samp=222) |
| 71 | raw.set_meas_date((0, 0)) # meas_date shouldn't matter |
| 72 | other.set_meas_date((100, 0)) |
| 73 | |
| 74 | # find events and do basic checks |
| 75 | evoked_raw, events_raw, _, events_other = _assert_similarity( |
nothing calls this directly
no test coverage detected