MCPcopy
hub / github.com/mne-tools/mne-python / test_realign

Function test_realign

mne/preprocessing/tests/test_realign.py:18–146  ·  view source on GitHub ↗

Test realigning raw.

(ratio_other, start_raw, start_other, stop_raw, stop_other)

Source from the content-addressed store, hash-verified

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)])
18def 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(

Callers

nothing calls this directly

Calls 11

create_infoFunction · 0.90
RawArrayClass · 0.90
AnnotationsClass · 0.90
realign_rawFunction · 0.90
_assert_similarityFunction · 0.85
_annot_to_onset_durFunction · 0.85
set_meas_dateMethod · 0.80
set_annotationsMethod · 0.45
copyMethod · 0.45
get_dataMethod · 0.45

Tested by

no test coverage detected