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

Function make_stc_from_dipoles

mne/inverse_sparse/mxne_inverse.py:292–341  ·  view source on GitHub ↗

Convert a list of spatio-temporal dipoles into a SourceEstimate. Parameters ---------- dipoles : Dipole | list of instances of Dipole The dipoles to convert. src : instance of SourceSpaces The source space used to generate the forward operator. %(verbose)s R

(dipoles, src, verbose=None)

Source from the content-addressed store, hash-verified

290
291@verbose
292def make_stc_from_dipoles(dipoles, src, verbose=None):
293 """Convert a list of spatio-temporal dipoles into a SourceEstimate.
294
295 Parameters
296 ----------
297 dipoles : Dipole | list of instances of Dipole
298 The dipoles to convert.
299 src : instance of SourceSpaces
300 The source space used to generate the forward operator.
301 %(verbose)s
302
303 Returns
304 -------
305 stc : SourceEstimate
306 The source estimate.
307 """
308 logger.info("Converting dipoles into a SourceEstimate.")
309 if isinstance(dipoles, Dipole):
310 dipoles = [dipoles]
311 if not isinstance(dipoles, list):
312 raise ValueError(
313 "Dipoles must be an instance of Dipole or "
314 "a list of instances of Dipole. "
315 f"Got {type(dipoles)}!"
316 )
317 tmin = dipoles[0].times[0]
318 tstep = dipoles[0].times[1] - tmin
319 X = np.zeros((len(dipoles), len(dipoles[0].times)))
320 source_rr = np.concatenate([_src["rr"][_src["vertno"], :] for _src in src], axis=0)
321 n_lh_points = len(src[0]["vertno"])
322 lh_vertno = list()
323 rh_vertno = list()
324 for i in range(len(dipoles)):
325 if not np.all(dipoles[i].pos == dipoles[i].pos[0]):
326 raise ValueError(
327 "Only dipoles with fixed position over time are supported!"
328 )
329 X[i] = dipoles[i].amplitude
330 idx = np.all(source_rr == dipoles[i].pos[0], axis=1)
331 idx = np.where(idx)[0][0]
332 if idx < n_lh_points:
333 lh_vertno.append(src[0]["vertno"][idx])
334 else:
335 rh_vertno.append(src[1]["vertno"][idx - n_lh_points])
336 vertices = [np.array(lh_vertno).astype(int), np.array(rh_vertno).astype(int)]
337 stc = SourceEstimate(
338 X, vertices=vertices, tmin=tmin, tstep=tstep, subject=src._subject
339 )
340 logger.info("[done]")
341 return stc
342
343
344@verbose

Calls 3

SourceEstimateClass · 0.85
infoMethod · 0.80
appendMethod · 0.45

Tested by 2

test_gamma_map_standardFunction · 0.72