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

Function _apply_morph_data

mne/morph.py:1470–1565  ·  view source on GitHub ↗

Morph a source estimate from one subject to another.

(morph, stc_from)

Source from the content-addressed store, hash-verified

1468
1469
1470def _apply_morph_data(morph, stc_from):
1471 """Morph a source estimate from one subject to another."""
1472 if stc_from.subject is not None and stc_from.subject != morph.subject_from:
1473 raise ValueError(
1474 f"stc.subject ({stc_from.subject}) != morph.subject_from "
1475 f"({morph.subject_from})"
1476 )
1477 _check_option("morph.kind", morph.kind, ("surface", "volume", "mixed"))
1478 if morph.kind == "surface":
1479 _validate_type(
1480 stc_from,
1481 _BaseSurfaceSourceEstimate,
1482 "stc_from",
1483 "volume source estimate when using a surface morph",
1484 )
1485 elif morph.kind == "volume":
1486 _validate_type(
1487 stc_from,
1488 _BaseVolSourceEstimate,
1489 "stc_from",
1490 "surface source estimate when using a volume morph",
1491 )
1492 else:
1493 assert morph.kind == "mixed" # can handle any
1494 _validate_type(
1495 stc_from,
1496 _BaseSourceEstimate,
1497 "stc_from",
1498 "source estimate when using a mixed source morph",
1499 )
1500
1501 # figure out what to actually morph
1502 do_vol = not isinstance(stc_from, _BaseSurfaceSourceEstimate)
1503 do_surf = not isinstance(stc_from, _BaseVolSourceEstimate)
1504
1505 vol_src_offset = 2 if do_surf else 0
1506 from_surf_stop = sum(len(v) for v in stc_from.vertices[:vol_src_offset])
1507 to_surf_stop = sum(len(v) for v in morph.vertices_to[:vol_src_offset])
1508 from_vol_stop = stc_from.data.shape[0]
1509 vertices_to = morph.vertices_to
1510 if morph.kind == "mixed":
1511 vertices_to = vertices_to[0 if do_surf else 2 : None if do_vol else 2]
1512 to_vol_stop = sum(len(v) for v in vertices_to)
1513
1514 mesg = "Ori × Time" if stc_from.data.ndim == 3 else "Time"
1515 data_from = np.reshape(stc_from.data, (stc_from.data.shape[0], -1))
1516 n_times = data_from.shape[1] # oris treated as times
1517 data = np.empty((to_vol_stop, n_times), stc_from.data.dtype)
1518 to_used = np.zeros(data.shape[0], bool)
1519 from_used = np.zeros(data_from.shape[0], bool)
1520 if do_vol:
1521 stc_from_vertices = stc_from.vertices[vol_src_offset:]
1522 vertices_from = morph._vol_vertices_from
1523 for ii, (v1, v2) in enumerate(zip(vertices_from, stc_from_vertices)):
1524 _check_vertices_match(v1, v2, f"volume[{ii}]")
1525 from_sl = slice(from_surf_stop, from_vol_stop)
1526 assert not from_used[from_sl].any()
1527 from_used[from_sl] = True

Callers 1

applyMethod · 0.85

Calls 7

_check_optionFunction · 0.85
_validate_typeFunction · 0.85
_check_vertices_matchFunction · 0.85
warnFunction · 0.85
_reshape_viewFunction · 0.85
compute_vol_morph_matMethod · 0.80
_morph_volsMethod · 0.80

Tested by

no test coverage detected