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

Function _apply_forward

mne/forward/forward.py:1549–1586  ·  view source on GitHub ↗

Apply forward model and return data, times, ch_names.

(
    fwd, stc, start=None, stop=None, on_missing="raise", use_cps=True, verbose=None
)

Source from the content-addressed store, hash-verified

1547
1548@verbose
1549def _apply_forward(
1550 fwd, stc, start=None, stop=None, on_missing="raise", use_cps=True, verbose=None
1551):
1552 """Apply forward model and return data, times, ch_names."""
1553 _validate_type(stc, _BaseSourceEstimate, "stc", "SourceEstimate")
1554 _validate_type(fwd, Forward, "fwd")
1555 if isinstance(stc, _BaseVectorSourceEstimate):
1556 vector = True
1557 fwd = convert_forward_solution(fwd, force_fixed=False, surf_ori=False)
1558 else:
1559 vector = False
1560 if not is_fixed_orient(fwd):
1561 fwd = convert_forward_solution(fwd, force_fixed=True, use_cps=use_cps)
1562
1563 if np.all(stc.data > 0):
1564 warn(
1565 "Source estimate only contains currents with positive values. "
1566 'Use pick_ori="normal" when computing the inverse to compute '
1567 "currents not current magnitudes."
1568 )
1569
1570 _check_stc_units(stc)
1571
1572 src_sel, stc_sel, _ = _stc_src_sel(fwd["src"], stc, on_missing=on_missing)
1573 gain = fwd["sol"]["data"]
1574 stc_sel = slice(None) if len(stc_sel) == len(stc.data) else stc_sel
1575 times = stc.times[start:stop].copy()
1576 stc_data = stc.data[stc_sel, ..., start:stop].reshape(-1, len(times))
1577 del stc
1578 if vector:
1579 gain = gain.reshape(len(gain), gain.shape[1] // 3, 3)
1580 gain = gain[:, src_sel].reshape(len(gain), -1)
1581 # save some memory if possible
1582
1583 logger.info("Projecting source estimate to sensor space...")
1584 data = np.dot(gain, stc_data)
1585 logger.info("[done]")
1586 return data, times
1587
1588
1589@verbose

Callers 2

apply_forwardFunction · 0.85
apply_forward_rawFunction · 0.85

Calls 8

_validate_typeFunction · 0.85
convert_forward_solutionFunction · 0.85
is_fixed_orientFunction · 0.85
warnFunction · 0.85
_check_stc_unitsFunction · 0.85
_stc_src_selFunction · 0.85
infoMethod · 0.80
copyMethod · 0.45

Tested by

no test coverage detected