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 12b029ae872ad3a06118ec3299147093a5a18ef2 Author: Alexandre Gramfort <[email protected]> Date: Fri Mar 11 12:52:40 2011 -0500 increasing coverage + bug fix in read_source_spaces when add_geom = True --- examples/plot_read_source_space.py | 30 ++++++++++++++++++++++++++++++ mne/source_space.py | 18 ++++++++---------- mne/tests/test_cov.py | 31 ++++++++++++++++++++++++++++--- mne/tests/test_event.py | 16 ++++++++++++++-- mne/tests/test_source_space.py | 23 +++++++++++++++++++++++ 5 files changed, 103 insertions(+), 15 deletions(-) diff --git a/examples/plot_read_source_space.py b/examples/plot_read_source_space.py new file mode 100644 index 0000000..eb216ef --- /dev/null +++ b/examples/plot_read_source_space.py @@ -0,0 +1,30 @@ +""" +============================================== +Reading a source space from a forward operator +============================================== +""" +# Author: Alexandre Gramfort <[email protected]> +# +# License: BSD (3-clause) + +print __doc__ + +import os.path as op + +import mne +from mne.datasets import sample + +data_path = sample.data_path('.') +fname = op.join(data_path, 'MEG', 'sample', 'sample_audvis-eeg-oct-6-fwd.fif') + +add_geom = True # include high resolution source space +src = mne.read_source_spaces(fname, add_geom=add_geom) + +# 3D source space (high sampling) +lh_points = src[0]['rr'] +lh_faces = src[0]['tris'] +rh_points = src[1]['rr'] +rh_faces = src[1]['tris'] +from enthought.mayavi import mlab +mlab.triangular_mesh(lh_points[:,0], lh_points[:,1], lh_points[:,2], lh_faces) +mlab.triangular_mesh(rh_points[:,0], rh_points[:,1], rh_points[:,2], rh_faces) diff --git a/mne/source_space.py b/mne/source_space.py index 121018c..fceb24a 100644 --- a/mne/source_space.py +++ b/mne/source_space.py @@ -172,16 +172,16 @@ def _read_one_source_space(fid, this, open_here): fid.close() raise ValueError, 'Triangulation not found' else: - res['tris'] = tag.data + res['tris'] = tag.data - 1 # index start at 0 in Python else: - res['tris'] = tag.data + res['tris'] = tag.data - 1 # index start at 0 in Python if res['tris'].shape[0] != res['ntri']: if open_here: fid.close() raise ValueError, 'Triangulation information is incorrect' - else: - res['tris'] = None + else: + res['tris'] = None # Which vertices are active tag = find_tag(fid, this, FIFF.FIFF_MNE_SOURCE_SPACE_NUSE) @@ -238,7 +238,7 @@ def complete_source_space_info(this): """Add more info on surface """ # Main triangulation - print '\tCompleting triangulation info...' + print '\tCompleting triangulation info...', this['tri_area'] = np.zeros(this['ntri']) r1 = this['rr'][this['tris'][:, 0], :] r2 = this['rr'][this['tris'][:, 1], :] @@ -247,23 +247,21 @@ def complete_source_space_info(this): this['tri_nn'] = np.cross((r2-r1), (r3-r1)) for p in range(this['ntri']): # XXX : can do better - size = sqrt(np.sum(this['tri_nn'][p,:] * this['tri_nn'][p,:])) + size = sqrt(np.sum(this['tri_nn'][p,:]**2)) this['tri_area'][p] = size / 2.0 this['tri_nn'][p,:] = this['tri_nn'][p,:] / size print '[done]' # Selected triangles - print '\tCompleting selection triangulation info...' + print '\tCompleting selection triangulation info...', if this['nuse_tri'] > 0: r1 = this['rr'][this['use_tris'][:, 0],:] r2 = this['rr'][this['use_tris'][:, 1],:] r3 = this['rr'][this['use_tris'][:, 2],:] this['use_tri_cent'] = (r1 + r2 + r3) / 3.0 this['use_tri_nn'] = np.cross((r2-r1), (r3-r1)) - for p in range(this['nuse_tri']): # XXX can do better - this['use_tri_area'][p] = sqrt(np.sum(this['use_tri_nn'][p,:] - * this['use_tri_nn'][p,:])) / 2.0 + this['use_tri_area'] = np.sqrt(np.sum(this['use_tri_nn']**2, axis=1)) / 2.0 print '[done]' diff --git a/mne/tests/test_cov.py b/mne/tests/test_cov.py index 3613fa3..c9e4436 100644 --- a/mne/tests/test_cov.py +++ b/mne/tests/test_cov.py @@ -3,9 +3,12 @@ import os.path as op from numpy.testing import assert_array_almost_equal import mne -from ..fiff import fiff_open +from ..fiff import fiff_open, read_evoked +from ..datasets import sample + +fname = op.join(op.dirname(__file__), '..', 'fiff', 'tests', 'data', + 'test-cov.fif') -fname = op.join(op.dirname(__file__), '..', 'fiff', 'tests', 'data', 'test-cov.fif') def test_io_cov(): """Test IO for noise covariance matrices @@ -21,4 +24,26 @@ def test_io_cov(): cov2 = mne.read_cov(fid, tree, cov_type) fid.close() - print assert_array_almost_equal(cov['data'], cov2['data']) \ No newline at end of file + assert_array_almost_equal(cov['data'], cov2['data']) + + +def test_whitening_cov(): + """Whitening of evoked data and leadfields + """ + data_path = sample.data_path('.') + fwd_fname = op.join(data_path, 'MEG', 'sample', + 'sample_audvis-meg-eeg-oct-6-fwd.fif') + ave_fname = op.join(data_path, 'MEG', 'sample', + 'sample_audvis-ave.fif') + cov_fname = op.join(data_path, 'MEG', 'sample', + 'sample_audvis-cov.fif') + + # Reading + ave = read_evoked(ave_fname, setno=0, baseline=(None, 0)) + fwd = mne.read_forward_solution(fwd_fname) + + cov = mne.Covariance() + cov.load(cov_fname) + + ave_whiten, fwd_whiten, W = cov.whiten_evoked_and_forward(ave, fwd) + # XXX : test something diff --git a/mne/tests/test_event.py b/mne/tests/test_event.py index 3e9680b..b902a6d 100644 --- a/mne/tests/test_event.py +++ b/mne/tests/test_event.py @@ -8,11 +8,23 @@ import mne fname = op.join(op.dirname(__file__), '..', 'fiff', 'tests', 'data', 'test-eve.fif') +raw_fname = op.join(op.dirname(__file__), '..', 'fiff', 'tests', 'data', + 'test_raw.fif') -def test_io_cov(): - """Test IO for noise covariance matrices + +def test_io_events(): + """Test IO for events """ events = mne.read_events(fname) mne.write_events('events.fif', events) events2 = mne.read_events(fname) assert_array_almost_equal(events, events2) + + +def test_find_events(): + """Test find events in raw file + """ + events = mne.read_events(fname) + raw = mne.fiff.Raw(raw_fname) + events2 = mne.find_events(raw) + assert_array_almost_equal(events, events2) diff --git a/mne/tests/test_source_space.py b/mne/tests/test_source_space.py new file mode 100644 index 0000000..46d8193 --- /dev/null +++ b/mne/tests/test_source_space.py @@ -0,0 +1,23 @@ +import os.path as op + +# from numpy.testing import assert_array_almost_equal + +import mne +from mne.datasets import sample + +examples_folder = op.join(op.dirname(__file__), '..', '..', 'examples') +data_path = sample.data_path(examples_folder) +fname = op.join(data_path, 'MEG', 'sample', 'sample_audvis-eeg-oct-6-fwd.fif') + +def test_read_source_spaces(): + """Testing reading of source space meshes + """ + src = mne.read_source_spaces(fname, add_geom=False) + src = mne.read_source_spaces(fname, add_geom=True) + + # 3D source space + lh_points = src[0]['rr'] + lh_faces = src[0]['use_tris'] + rh_points = src[1]['rr'] + rh_faces = src[1]['use_tris'] + # XXX : test something -- Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/debian-med/python-mne.git _______________________________________________ debian-med-commit mailing list [email protected] http://lists.alioth.debian.org/cgi-bin/mailman/listinfo/debian-med-commit
