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

Function _make_stc

mne/source_estimate.py:422–472  ·  view source on GitHub ↗

Generate a surface, vector-surface, volume or mixed source estimate.

(
    data,
    vertices,
    src_type=None,
    tmin=None,
    tstep=None,
    subject=None,
    vector=False,
    source_nn=None,
    warn_text=None,
)

Source from the content-addressed store, hash-verified

420
421
422def _make_stc(
423 data,
424 vertices,
425 src_type=None,
426 tmin=None,
427 tstep=None,
428 subject=None,
429 vector=False,
430 source_nn=None,
431 warn_text=None,
432):
433 """Generate a surface, vector-surface, volume or mixed source estimate."""
434
435 def guess_src_type():
436 return _get_src_type(src=None, vertices=vertices, warn_text=warn_text)
437
438 src_type = guess_src_type() if src_type is None else src_type
439
440 if vector and src_type == "surface" and source_nn is None:
441 raise RuntimeError("No source vectors supplied.")
442
443 # infer Klass from src_type
444 if src_type == "surface":
445 Klass = VectorSourceEstimate if vector else SourceEstimate
446 elif src_type in ("volume", "discrete"):
447 Klass = VolVectorSourceEstimate if vector else VolSourceEstimate
448 elif src_type == "mixed":
449 Klass = MixedVectorSourceEstimate if vector else MixedSourceEstimate
450 else:
451 raise ValueError(
452 "vertices has to be either a list with one or more arrays or an array"
453 )
454
455 # Rotate back for vector source estimates
456 if vector:
457 n_vertices = sum(len(v) for v in vertices)
458 assert data.shape[0] in (n_vertices, n_vertices * 3)
459 if len(data) == n_vertices:
460 assert src_type == "surface" # should only be possible for this
461 assert source_nn.shape == (n_vertices, 3)
462 data = data[:, np.newaxis] * source_nn[:, :, np.newaxis]
463 else:
464 data = data.reshape((-1, 3, data.shape[-1]))
465 assert source_nn.shape in ((n_vertices, 3, 3), (n_vertices * 3, 3))
466 # This will be an identity transform for volumes, but let's keep
467 # the code simple and general and just do the matrix mult
468 data = np.matmul(
469 np.transpose(source_nn.reshape(n_vertices, 3, 3), axes=[0, 2, 1]), data
470 )
471
472 return Klass(data=data, vertices=vertices, tmin=tmin, tstep=tstep, subject=subject)
473
474
475def _verify_source_estimate_compat(a, b):

Callers 2

test_apply_function_stcFunction · 0.90
sensitivity_mapFunction · 0.70

Calls 1

guess_src_typeFunction · 0.85

Tested by 1

test_apply_function_stcFunction · 0.72