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 9072d39629f84f6c107c66d9711d5be350264dc0 Author: Alexandre Gramfort <[email protected]> Date: Wed Dec 29 18:38:48 2010 -0500 reading stc files --- examples/read_cov.py | 12 ++++++++--- examples/read_events.py | 5 +---- examples/read_evoked.py | 3 +-- examples/read_raw.py | 1 - examples/read_stc.py | 18 +++++++++++++++++ fiff/__init__.py | 1 + fiff/stc.py | 53 +++++++++++++++++++++++++++++++++++++++++++++++++ 7 files changed, 83 insertions(+), 10 deletions(-) diff --git a/examples/read_cov.py b/examples/read_cov.py index ee771f1..30f2406 100644 --- a/examples/read_cov.py +++ b/examples/read_cov.py @@ -1,14 +1,20 @@ -import pylab as pl +"""Reading a noise covariance matrix +""" +print __doc__ + import fiff -fname = 'sm02a1-cov.fif' +fname = 'MNE-sample-data/MEG/sample/sample_audvis-cov.fif' fid, tree, _ = fiff.fiff_open(fname) cov_type = 1 cov = fiff.read_cov(fid, tree, cov_type) -print "cov size: %s x %s" % cov['data'].shape +print "covariance matrix size: %s x %s" % cov['data'].shape +############################################################################### +# Show covariance +import pylab as pl pl.matshow(cov['data']) pl.show() diff --git a/examples/read_events.py b/examples/read_events.py index 1bcab5f..4781ad1 100644 --- a/examples/read_events.py +++ b/examples/read_events.py @@ -2,19 +2,16 @@ """ print __doc__ -import pylab as pl import fiff fname = 'MNE-sample-data/MEG/sample/sample_audvis_raw-eve.fif' -# fname = 'sm02a5_raw.fif' event_list = fiff.read_events(fname) ############################################################################### # Show MEG data +import pylab as pl pl.plot(times, data.T) pl.xlabel('time (ms)') pl.ylabel('MEG data (T)') pl.show() - - diff --git a/examples/read_evoked.py b/examples/read_evoked.py index d26e4c2..8fe664f 100644 --- a/examples/read_evoked.py +++ b/examples/read_evoked.py @@ -4,8 +4,7 @@ print __doc__ import fiff -fname = 'sm02a1-ave.fif' -# fname = 'MNE-sample-data/MEG/sample/sample_audvis-ave.fif' +fname = 'MNE-sample-data/MEG/sample/sample_audvis-ave.fif' data = fiff.read_evoked(fname) diff --git a/examples/read_raw.py b/examples/read_raw.py index 08c135d..80666c9 100644 --- a/examples/read_raw.py +++ b/examples/read_raw.py @@ -6,7 +6,6 @@ import pylab as pl import fiff fname = 'MNE-sample-data/MEG/sample/sample_audvis_raw.fif' -# fname = 'sm02a5_raw.fif' raw = fiff.setup_read_raw(fname) diff --git a/examples/read_stc.py b/examples/read_stc.py new file mode 100644 index 0000000..f1a8573 --- /dev/null +++ b/examples/read_stc.py @@ -0,0 +1,18 @@ +"""Reading a raw file segment +""" +print __doc__ + +import fiff + +# fname = 'MNE-sample-data/MEG/sample/sample_audvis_raw.fif' +fname = 'hk_ret12_offl-7-meg-snr-3-spm-rh.stc' + +stc = fiff.read_stc(fname) + +n_vertices, n_samples = stc['data'].shape +print "tmin : %s (s)" % stc['tmin'] +print "tstep : %s" % stc['tstep'] +print "tmax : %s (s)" % (stc['tmin'] + stc['tstep'] * n_samples) +print "stc data size: %s (nb of vertices) x %s (nb of samples)" % ( + n_vertices, n_samples) + diff --git a/fiff/__init__.py b/fiff/__init__.py index a7c32eb..10b382e 100644 --- a/fiff/__init__.py +++ b/fiff/__init__.py @@ -7,4 +7,5 @@ from .cov import read_cov from .raw import setup_read_raw, read_raw_segment, read_raw_segment_times from .event import read_events from .forward import read_forward_solution +from .stc import read_stc diff --git a/fiff/stc.py b/fiff/stc.py new file mode 100644 index 0000000..9c10f24 --- /dev/null +++ b/fiff/stc.py @@ -0,0 +1,53 @@ +import numpy as np + + +def read_stc(filename): + """ + % + % [stc] = mne_read_stc_file(filename) + % + % Reads an stc file. The returned structure has the following fields + % + % tmin The first time point of the data in seconds + % tstep Time between frames in seconds + % vertices vertex indices (0 based) + % data The data matrix (nvert * ntime) + % + % + """ + + fid = open(filename, 'rb') + + stc = dict() + + fid.seek(0, 2) # go to end of file + file_length = fid.tell() + fid.seek(0, 0) # go to beginning of file + + # read tmin in ms + stc['tmin'] = float(np.fromfile(fid, dtype=">f4", count=1)) + stc['tmin'] /= 1000.0 + + # read sampling rate in ms + stc['tstep'] = float(np.fromfile(fid, dtype=">f4", count=1)) + stc['tstep'] /= 1000.0 + + # read number of vertices/sources + vertices_n = np.fromfile(fid, dtype=">I4", count=1) + + # read the source vector + stc['vertices'] = np.fromfile(fid, dtype=">I4", count=vertices_n) + + # read the number of timepts + data_n = np.fromfile(fid, dtype=">I4", count=1) + + if ((file_length/4 -4 - vertices_n) % (data_n*vertices_n)) != 0: + raise ValueError, 'incorrect stc file size' + + # read the data matrix + stc['data'] = np.fromfile(fid, dtype=">f4", count=vertices_n*data_n) + stc['data'] = stc['data'].reshape([data_n, vertices_n]).T + + # close the file + fid.close() + return stc -- 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
