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

Function test_simulate_sparse_stc

mne/simulation/tests/test_source.py:124–224  ·  view source on GitHub ↗

Test generation of sparse source estimate.

(_get_fwd_labels)

Source from the content-addressed store, hash-verified

122
123
124def test_simulate_sparse_stc(_get_fwd_labels):
125 """Test generation of sparse source estimate."""
126 pytest.importorskip("nibabel")
127 fwd, labels = _get_fwd_labels
128 n_times = 10
129 tmin = 0
130 tstep = 1e-3
131 times = np.arange(n_times, dtype=np.float64) * tstep + tmin
132
133 pytest.raises(
134 ValueError,
135 simulate_sparse_stc,
136 fwd["src"],
137 len(labels),
138 times,
139 labels=labels,
140 location="center",
141 subject="sample",
142 subjects_dir=subjects_dir,
143 ) # no non-zero values
144
145 mylabels = []
146 for label in labels:
147 this_label = label.copy()
148 this_label.values.fill(1.0)
149 mylabels.append(this_label)
150
151 for location in ("random", "center"):
152 random_state = 0 if location == "random" else None
153 stc_1 = simulate_sparse_stc(
154 fwd["src"],
155 len(mylabels),
156 times,
157 labels=mylabels,
158 random_state=random_state,
159 location=location,
160 subjects_dir=subjects_dir,
161 )
162 assert_equal(stc_1.subject, "sample")
163
164 assert stc_1.data.shape[0] == len(mylabels)
165 assert stc_1.data.shape[1] == n_times
166
167 # make sure we get the same result when using the same seed
168 stc_2 = simulate_sparse_stc(
169 fwd["src"],
170 len(mylabels),
171 times,
172 labels=mylabels,
173 random_state=random_state,
174 location=location,
175 subjects_dir=subjects_dir,
176 )
177
178 assert_array_equal(stc_1.lh_vertno, stc_2.lh_vertno)
179 assert_array_equal(stc_1.rh_vertno, stc_2.rh_vertno)
180
181 # Degenerate cases

Callers

nothing calls this directly

Calls 4

simulate_sparse_stcFunction · 0.90
fillMethod · 0.80
copyMethod · 0.45
appendMethod · 0.45

Tested by

no test coverage detected