[med-svn] [python-mne] 130/376: increase coverage in cov.py + bug fix in read_forward_solution when surf_ori=True

Yaroslav Halchenko debian at onerussian.com
Fri Nov 27 17:22:20 UTC 2015


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

yoh pushed a commit to annotated tag v0.1
in repository python-mne.

commit 9f006784ab3e6bec45f31a0efa42a466a96ae08a
Author: Alexandre Gramfort <alexandre.gramfort at inria.fr>
Date:   Sat Mar 12 18:36:19 2011 -0500

    increase coverage in cov.py + bug fix in read_forward_solution when surf_ori=True
---
 examples/plot_read_forward.py        |   2 +-
 mne/fiff/evoked.py                   |   1 -
 mne/fiff/write.py                    |  31 ++++----
 mne/forward.py                       |  18 +++--
 mne/tests/test_cov.py                |  24 +++++-
 mne/tests/test_forward.py            |   1 +
 mne/time_frequency/tests/test_tfr.py |   9 ++-
 mne/transforms.py                    | 146 +++++++++++++++++------------------
 8 files changed, 133 insertions(+), 99 deletions(-)

diff --git a/examples/plot_read_forward.py b/examples/plot_read_forward.py
index 24c2144..308f3b9 100644
--- a/examples/plot_read_forward.py
+++ b/examples/plot_read_forward.py
@@ -15,7 +15,7 @@ data_path = sample.data_path('.')
 
 fname = data_path + '/MEG/sample/sample_audvis-meg-oct-6-fwd.fif'
 
-fwd = mne.read_forward_solution(fname)
+fwd = mne.read_forward_solution(fname, surf_ori=True)
 leadfield = fwd['sol']['data']
 
 print "Leadfield size : %d x %d" % leadfield.shape
diff --git a/mne/fiff/evoked.py b/mne/fiff/evoked.py
index 0652b91..46ce122 100644
--- a/mne/fiff/evoked.py
+++ b/mne/fiff/evoked.py
@@ -116,7 +116,6 @@ class Evoked(object):
             raise ValueError, 'Data set selector out of range'
 
         #   Next locate the evoked data set
-        #
         p = 0
         goon = True
         for k in range(len(evoked_node)):
diff --git a/mne/fiff/write.py b/mne/fiff/write.py
index 645a603..254a8a3 100644
--- a/mne/fiff/write.py
+++ b/mne/fiff/write.py
@@ -424,19 +424,20 @@ def write_named_matrix(fid, kind, mat):
     %     mat           The data matrix
     %
     """
-
-    start_block(fid, FIFF.FIFFB_MNE_NAMED_MATRIX)
-    write_int(fid, FIFF.FIFF_MNE_NROW, mat['nrow'])
-    write_int(fid, FIFF.FIFF_MNE_NCOL, mat['ncol'])
-
-    if len(mat['row_names']) > 0:
-        write_name_list(fid, FIFF.FIFF_MNE_ROW_NAMES, mat['row_names'])
-
-    if len(mat['col_names']) > 0:
-        write_name_list(fid, FIFF.FIFF_MNE_COL_NAMES, mat['col_names'])
-
-    write_float_matrix(fid,kind, mat.data)
-    end_block(fid, FIFF.FIFFB_MNE_NAMED_MATRIX)
-
-    return;
+    raise NotImplementedError, "CTF data processing is not supported yet"
+
+    # start_block(fid, FIFF.FIFFB_MNE_NAMED_MATRIX)
+    # write_int(fid, FIFF.FIFF_MNE_NROW, mat['nrow'])
+    # write_int(fid, FIFF.FIFF_MNE_NCOL, mat['ncol'])
+    # 
+    # if len(mat['row_names']) > 0:
+    #     write_name_list(fid, FIFF.FIFF_MNE_ROW_NAMES, mat['row_names'])
+    # 
+    # if len(mat['col_names']) > 0:
+    #     write_name_list(fid, FIFF.FIFF_MNE_COL_NAMES, mat['col_names'])
+    # 
+    # write_float_matrix(fid,kind, mat.data)
+    # end_block(fid, FIFF.FIFFB_MNE_NAMED_MATRIX)
+    # 
+    # return;
 
diff --git a/mne/forward.py b/mne/forward.py
index 2389fc4..d5ba2ce 100644
--- a/mne/forward.py
+++ b/mne/forward.py
@@ -360,10 +360,12 @@ def read_forward_solution(fname, force_fixed=False, surf_ori=False,
             #   Rotate the local source coordinate systems
             print '\tConverting to surface-based source orientations...'
             nuse = 0
-            pp = 1
-            fwd['source_rr'] = np.zeros(fwd['nsource'], 3)
+            pp = 0
+            nuse_total = sum([s['nuse'] for s in src])
+            fwd['source_rr'] = np.zeros((fwd['nsource'], 3))
+            fwd['source_nn'] = np.empty((3*nuse_total, 3), dtype=np.float)
             for s in src:
-                fwd['source_rr'][nuse+1:nuse + s['nuse'],:] = \
+                fwd['source_rr'][nuse:nuse + s['nuse'],:] = \
                                                     s['rr'][s['vertno'],:]
                 for p in range(s['nuse']):
                     #  Project out the surface normal and compute SVD
@@ -373,12 +375,14 @@ def read_forward_solution(fname, force_fixed=False, surf_ori=False,
                     #  Make sure that ez is in the direction of nn
                     if np.sum(nn*U[:,2]) < 0:
                         U *= -1
-                        fwd['source_nn'][pp:pp+2,:] = U.T
-                        pp += 3
-                    nuse += s['nuse']
+
+                    fwd['source_nn'][pp:pp+3,:] = U.T
+                    pp += 3
+
+                nuse += s['nuse']
 
             surf_rot = _block_diag(fwd['source_nn'].T, 3)
-            fwd['sol']['data'] = np.dot(fwd['sol']['data'], surf_rot)
+            fwd['sol']['data'] = fwd['sol']['data'] * surf_rot
             if fwd['sol_grad'] is not None:
                 fwd['sol_grad']['data'] = np.dot(fwd['sol_grad']['data'] * \
                                                  np.kron(surf_rot, np.eye(3)))
diff --git a/mne/tests/test_cov.py b/mne/tests/test_cov.py
index c9e4436..b25ab50 100644
--- a/mne/tests/test_cov.py
+++ b/mne/tests/test_cov.py
@@ -3,11 +3,13 @@ import os.path as op
 from numpy.testing import assert_array_almost_equal
 
 import mne
-from ..fiff import fiff_open, read_evoked
+from ..fiff import fiff_open, read_evoked, pick_types
 from ..datasets import sample
 
 fname = op.join(op.dirname(__file__), '..', 'fiff', 'tests', 'data',
                 'test-cov.fif')
+raw_fname = op.join(op.dirname(__file__), '..', 'fiff', 'tests', 'data',
+                'test_raw.fif')
 
 
 def test_io_cov():
@@ -27,6 +29,26 @@ def test_io_cov():
     assert_array_almost_equal(cov['data'], cov2['data'])
 
 
+def test_cov_estimation():
+    """Test estimation of noise covariance from raw data
+    """
+    raw = mne.fiff.Raw(raw_fname)
+    # Set up pick list: MEG + STI 014 - bad channels
+    want_meg = True
+    want_eeg = False
+    want_stim = False
+
+    picks = pick_types(raw.info, meg=want_meg, eeg=want_eeg,
+                            stim=want_stim, exclude=raw.info['bads'])
+
+    full_cov = mne.Covariance(kind='full')
+    full_cov.estimate_from_raw(raw, picks=picks)
+
+    diagonal_cov = mne.Covariance(kind='diagonal')
+    diagonal_cov.estimate_from_raw(raw, picks=picks)
+    # XXX : test something
+
+
 def test_whitening_cov():
     """Whitening of evoked data and leadfields
     """
diff --git a/mne/tests/test_forward.py b/mne/tests/test_forward.py
index 6c074b6..4fc6bda 100644
--- a/mne/tests/test_forward.py
+++ b/mne/tests/test_forward.py
@@ -15,5 +15,6 @@ def test_io_forward():
     """
     fwd = mne.read_forward_solution(fname)
     fwd = mne.read_forward_solution(fname, force_fixed=True)
+    fwd = mne.read_forward_solution(fname, surf_ori=True)
     leadfield = fwd['sol']['data']
     # XXX : test something
diff --git a/mne/time_frequency/tests/test_tfr.py b/mne/time_frequency/tests/test_tfr.py
index 5df188d..145d8fb 100644
--- a/mne/time_frequency/tests/test_tfr.py
+++ b/mne/time_frequency/tests/test_tfr.py
@@ -1,9 +1,10 @@
 import numpy as np
 import os.path as op
+from numpy.testing import assert_array_almost_equal
 
 import mne
 from mne import fiff
-from mne.time_frequency import induced_power
+from mne.time_frequency import induced_power, single_trial_power
 from mne.time_frequency.tfr import cwt_morlet
 
 raw_fname = op.join(op.dirname(__file__), '..', '..', 'fiff', 'tests', 'data',
@@ -56,3 +57,9 @@ def test_time_frequency():
 
     tfr = cwt_morlet(data[0], Fs, frequencies, use_fft=True, n_cycles=2)
     assert tfr.shape == (len(picks), len(frequencies), len(times))
+
+    single_power = single_trial_power(data, Fs, frequencies, use_fft=False,
+                                      n_cycles=2)
+
+    assert_array_almost_equal(np.mean(single_power), power)
+
diff --git a/mne/transforms.py b/mne/transforms.py
index ba6323c..80912aa 100644
--- a/mne/transforms.py
+++ b/mne/transforms.py
@@ -50,76 +50,76 @@ def transform_source_space_to(src, dest, trans):
     return res
 
 
-def transform_meg_chs(chs, trans):
-    """
-    %
-    % [res, count] = fiff_transform_meg_chs(chs,trans)
-    %
-    % Move to another coordinate system in MEG channel channel info
-    % Count gives the number of channels transformed
-    %
-    % NOTE: Only the coil_trans field is modified by this routine, not
-    % loc which remains to reflect the original data read from the fif file
-    %
-    %
-
-    XXX
-    """
-
-    res = copy.copy(chs)
-
-    count = 0
-    t = trans['trans']
-    for ch in res:
-        if (ch['kind'] == FIFF.FIFFV_MEG_CH
-                                    or ch['kind'] == FIFF.FIFFV_REF_MEG_CH):
-            if (ch['coord_frame'] == trans['from_']
-                                            and ch['coil_trans'] is not None):
-                ch['coil_trans'] = np.dot(t, ch['coil_trans'])
-                ch['coord_frame'] = trans['to']
-                count += 1
-
-    if count > 0:
-        print '\t%d MEG channel locations transformed' % count
-
-    return res, count
-
-
-def transform_eeg_chs(chs, trans):
-    """
-    %
-    % [res, count] = fiff_transform_eeg_chs(chs,trans)
-    %
-    % Move to another coordinate system in EEG channel channel info
-    % Count gives the number of channels transformed
-    %
-    % NOTE: Only the eeg_loc field is modified by this routine, not
-    % loc which remains to reflect the original data read from the fif file
-    %
-
-    XXX
-    """
-    res = copy.copy(chs)
-
-    count = 0
-    #
-    #   Output unaugmented vectors from the transformation
-    #
-    t = trans['trans'][:3,:]
-    for ch in res:
-        if ch['kind'] == FIFF.FIFFV_EEG_CH:
-            if (ch['coord_frame'] == trans['from_']
-                                            and ch['eeg_loc'] is not None):
-                #
-                # Transform the augmented EEG location vectors
-                #
-                for p in range(ch['eeg_loc'].shape[1]):
-                    ch['eeg_loc'][:, p] = np.dot(t,
-                                                np.r_[ch['eeg_loc'][:,p], 1])
-                count += 1
-                ch['coord_frame'] = trans['to']
-
-    if count > 0:
-        print '\t%d EEG electrode locations transformed\n' % count
-
-    return res, count
+# def transform_meg_chs(chs, trans):
+#     """
+#     %
+#     % [res, count] = fiff_transform_meg_chs(chs,trans)
+#     %
+#     % Move to another coordinate system in MEG channel channel info
+#     % Count gives the number of channels transformed
+#     %
+#     % NOTE: Only the coil_trans field is modified by this routine, not
+#     % loc which remains to reflect the original data read from the fif file
+#     %
+#     %
+# 
+#     XXX
+#     """
+# 
+#     res = copy.copy(chs)
+# 
+#     count = 0
+#     t = trans['trans']
+#     for ch in res:
+#         if (ch['kind'] == FIFF.FIFFV_MEG_CH
+#                                     or ch['kind'] == FIFF.FIFFV_REF_MEG_CH):
+#             if (ch['coord_frame'] == trans['from_']
+#                                             and ch['coil_trans'] is not None):
+#                 ch['coil_trans'] = np.dot(t, ch['coil_trans'])
+#                 ch['coord_frame'] = trans['to']
+#                 count += 1
+# 
+#     if count > 0:
+#         print '\t%d MEG channel locations transformed' % count
+# 
+#     return res, count
+
+
+# def transform_eeg_chs(chs, trans):
+#     """
+#     %
+#     % [res, count] = fiff_transform_eeg_chs(chs,trans)
+#     %
+#     % Move to another coordinate system in EEG channel channel info
+#     % Count gives the number of channels transformed
+#     %
+#     % NOTE: Only the eeg_loc field is modified by this routine, not
+#     % loc which remains to reflect the original data read from the fif file
+#     %
+# 
+#     XXX
+#     """
+#     res = copy.copy(chs)
+# 
+#     count = 0
+#     #
+#     #   Output unaugmented vectors from the transformation
+#     #
+#     t = trans['trans'][:3,:]
+#     for ch in res:
+#         if ch['kind'] == FIFF.FIFFV_EEG_CH:
+#             if (ch['coord_frame'] == trans['from_']
+#                                             and ch['eeg_loc'] is not None):
+#                 #
+#                 # Transform the augmented EEG location vectors
+#                 #
+#                 for p in range(ch['eeg_loc'].shape[1]):
+#                     ch['eeg_loc'][:, p] = np.dot(t,
+#                                                 np.r_[ch['eeg_loc'][:,p], 1])
+#                 count += 1
+#                 ch['coord_frame'] = trans['to']
+# 
+#     if count > 0:
+#         print '\t%d EEG electrode locations transformed\n' % count
+# 
+#     return res, count

-- 
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