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

Function test_simulate_stc

mne/simulation/tests/test_source.py:50–121  ·  view source on GitHub ↗

Test generation of source estimate.

(_get_fwd_labels)

Source from the content-addressed store, hash-verified

48
49
50def test_simulate_stc(_get_fwd_labels):
51 """Test generation of source estimate."""
52 fwd, labels = _get_fwd_labels
53 mylabels = []
54 for i, label in enumerate(labels):
55 new_label = Label(
56 vertices=label.vertices,
57 pos=label.pos,
58 values=2 * i * np.ones(len(label.values)),
59 hemi=label.hemi,
60 comment=label.comment,
61 )
62 mylabels.append(new_label)
63
64 n_times = 10
65 tmin = 0
66 tstep = 1e-3
67
68 stc_data = np.ones((len(labels), n_times))
69 stc = simulate_stc(fwd["src"], mylabels, stc_data, tmin, tstep)
70 assert_equal(stc.subject, "sample")
71
72 for label in labels:
73 idx = _get_idx_label_stc(label, stc)
74 assert np.all(stc.data[idx] == 1.0)
75 assert stc.data[idx].shape[1] == n_times
76
77 # test with function
78 def fun(x):
79 return x**2
80
81 stc = simulate_stc(fwd["src"], mylabels, stc_data, tmin, tstep, fun)
82
83 # the first label has value 0, the second value 2, the third value 6
84
85 for i, label in enumerate(labels):
86 idx = _get_idx_label_stc(label, stc)
87 res = ((2.0 * i) ** 2.0) * np.ones((len(idx), n_times))
88 assert_array_almost_equal(stc.data[idx], res)
89
90 # degenerate conditions
91 label_subset = mylabels[:2]
92 data_subset = stc_data[:2]
93 stc = simulate_stc(fwd["src"], label_subset, data_subset, tmin, tstep, fun)
94
95 pytest.raises(
96 ValueError,
97 simulate_stc,
98 fwd["src"],
99 label_subset,
100 data_subset[:-1],
101 tmin,
102 tstep,
103 fun,
104 )
105 pytest.raises(
106 RuntimeError,
107 simulate_stc,

Callers

nothing calls this directly

Calls 4

LabelClass · 0.90
simulate_stcFunction · 0.90
_get_idx_label_stcFunction · 0.85
appendMethod · 0.45

Tested by

no test coverage detected