[med-svn] [python-mne] 39/52: ENH : raise exception when channels in inv op and data do not match
Yaroslav Halchenko
debian at onerussian.com
Fri Nov 27 17:23:48 UTC 2015
This is an automated email from the git hooks/post-receive script.
yoh pushed a commit to annotated tag v0.2
in repository python-mne.
commit aa0ef524bc86b2a011e668a41a3d94c72b6e4ba4
Author: Alexandre Gramfort <alexandre.gramfort at inria.fr>
Date: Sat Oct 29 11:25:47 2011 -0400
ENH : raise exception when channels in inv op and data do not match
---
mne/minimum_norm/inverse.py | 28 +++++++++++++++++++++++++++-
1 file changed, 27 insertions(+), 1 deletion(-)
diff --git a/mne/minimum_norm/inverse.py b/mne/minimum_norm/inverse.py
index e99235d..3e2760f 100644
--- a/mne/minimum_norm/inverse.py
+++ b/mne/minimum_norm/inverse.py
@@ -286,6 +286,26 @@ def _combine_ori(sol, inverse_operator, pick_normal):
return sol
+def _chech_ch_names(inv, info):
+ """Check that channels in inverse operator are measurements"""
+
+ inv_ch_names = inv['eigen_fields']['col_names']
+
+ if inv['noise_cov']['names'] != inv_ch_names:
+ raise ValueError('Channels in inverse operator eigen fields do not '
+ 'match noise covariance channels.')
+ data_ch_names = info['ch_names']
+
+ missing_ch_names = list()
+ for ch_name in inv_ch_names:
+ if ch_name not in data_ch_names:
+ missing_ch_names.append(ch_name)
+ n_missing = len(missing_ch_names)
+ if n_missing > 0:
+ raise ValueError('%d channels in inverse operator ' % n_missing +
+ 'are not present in the data (%s)' % missing_ch_names)
+
+
def prepare_inverse_operator(orig, nave, lambda2, dSPM):
"""Prepare an inverse operator for actually computing the inverse
@@ -529,6 +549,8 @@ def apply_inverse(evoked, inverse_operator, lambda2, dSPM=True,
#
nave = evoked.nave
+ _chech_ch_names(inverse_operator, evoked.info)
+
inv = prepare_inverse_operator(inverse_operator, nave, lambda2, dSPM)
#
# Pick the correct channels from the data
@@ -594,6 +616,8 @@ def apply_inverse_raw(raw, inverse_operator, lambda2, dSPM=True,
stc: SourceEstimate
The source estimates
"""
+ _chech_ch_names(inverse_operator, raw.info)
+
#
# Set up the inverse according to the parameters
#
@@ -657,6 +681,8 @@ def apply_inverse_epochs(epochs, inverse_operator, lambda2, dSPM=True,
stc: list of SourceEstimate
The source estimates for all epochs
"""
+ _chech_ch_names(inverse_operator, epochs.info)
+
#
# Set up the inverse according to the parameters
#
@@ -848,7 +874,7 @@ def make_inverse_operator(info, forward, noise_cov, loose=0.2, depth=0.8):
print 'Computing SVD of whitened and weighted lead field matrix.'
eigen_fields, sing, eigen_leads = linalg.svd(gain, full_matrices=False)
- eigen_fields = dict(data=eigen_fields.T)
+ eigen_fields = dict(data=eigen_fields.T, col_names=ch_names)
eigen_leads = dict(data=eigen_leads.T, nrow=eigen_leads.shape[1])
depth_prior = dict(data=depth_prior)
orient_prior = dict(data=orient_prior)
--
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