Apply forward model and return data, times, ch_names.
(
fwd, stc, start=None, stop=None, on_missing="raise", use_cps=True, verbose=None
)
| 1547 | |
| 1548 | @verbose |
| 1549 | def _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 |
no test coverage detected