[med-svn] [python-mne] 71/353: ENH: adding function applY_forward() (not finished)

Yaroslav Halchenko debian at onerussian.com
Fri Nov 27 17:24:33 UTC 2015


This is an automated email from the git hooks/post-receive script.

yoh pushed a commit to tag 0.4
in repository python-mne.

commit 37d6f8e8ef125402d27add8f81d4d0d87c9a28fa
Author: Martin Luessi <mluessi at nmr.mgh.harvard.edu>
Date:   Tue Jan 31 17:03:44 2012 -0500

    ENH: adding function applY_forward() (not finished)
---
 mne/__init__.py |  2 +-
 mne/forward.py  | 40 ++++++++++++++++++++++++++++++++++++++++
 2 files changed, 41 insertions(+), 1 deletion(-)

diff --git a/mne/__init__.py b/mne/__init__.py
index 2b3539c..df79675 100644
--- a/mne/__init__.py
+++ b/mne/__init__.py
@@ -4,7 +4,7 @@ from .cov import read_cov, write_cov, write_cov_file, Covariance, \
                  compute_raw_data_covariance, compute_covariance
 from .event import read_events, write_events, find_events, merge_events, \
                    pick_events
-from .forward import read_forward_solution
+from .forward import read_forward_solution, apply_forward
 from .source_estimate import read_stc, write_stc, read_w, write_w, \
                              SourceEstimate, morph_data, \
                              spatio_temporal_src_connectivity, \
diff --git a/mne/forward.py b/mne/forward.py
index ab2520b..85bbd42 100644
--- a/mne/forward.py
+++ b/mne/forward.py
@@ -5,6 +5,7 @@
 
 import numpy as np
 from scipy import linalg
+import warnings
 
 from .fiff.constants import FIFF
 from .fiff.open import fiff_open
@@ -443,3 +444,42 @@ def compute_depth_prior_fixed(G, exp=0.8, limit=10.0):
     wp = np.minimum(w, wmax)
     depth_prior = (wp / wmax) ** exp
     return depth_prior
+
+
+def _stc_src_sel(src, stc):
+    """Select the vertex indices of a forward solution using a source estimate
+    """
+    src_sel_lh = np.intersect1d(src[0]['vertno'], stc.vertno[0])
+    src_sel_lh = np.searchsorted(src[0]['vertno'], src_sel_lh)
+
+    src_sel_rh = np.intersect1d(src[1]['vertno'], stc.vertno[1])
+    src_sel_rh = np.searchsorted(src[1]['vertno'], src_sel_rh)\
+                 + len(src[0]['vertno'])
+
+    src_sel = np.r_[src_sel_lh, src_sel_rh]
+
+    return src_sel
+
+
+def apply_forward(fwd, stc, start=None, stop=None, include=[], exclude=[]):
+
+    if fwd['source_ori'] != FIFF.FIFFV_MNE_FIXED_ORI:
+        raise ValueError('Only fixed-orientation forward operators are '
+                         'supported')
+
+    if np.all(stc.data > 0):
+        warnings.warn('Source estimate only contains currents with positive '
+                      'values. Use pick_normal=True when computing the '
+                      'inverse to compute currents not current magnitudes.')
+
+    fwd = pick_channels_forward(fwd, include=include, exclude=exclude)
+
+    src_sel = _stc_src_sel(fwd['src'], stc)
+
+    gain = fwd['sol']['data'][:, src_sel]
+
+    print 'Projecting source estimate to sensor space...',
+    sens_data = np.dot(gain, stc.data[:, start:stop])
+    print '[done]'
+
+    return sens_data

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/debian-med/python-mne.git



More information about the debian-med-commit mailing list