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 6b4485af5f8cfc50eeca842673c7875d19d8bfd5 Author: Alexandre Gramfort <[email protected]> Date: Fri Jan 21 21:03:52 2011 -0500 bug fix + doc on command line + baseline correction ... --- doc/source/contents.rst | 2 + doc/source/tutorial.rst | 96 +++++++++++++++++++++++++++++++++++- examples/plot_compute_mne_inverse.py | 14 +++++- examples/plot_read_epochs.py | 10 ++-- examples/plot_read_evoked.py | 17 ++++++- examples/plot_read_raw_data.py | 4 +- examples/read_events.py | 4 +- mne/epochs.py | 32 +++++++++++- mne/fiff/evoked.py | 34 +++++++++++-- mne/fiff/raw.py | 8 +-- mne/inverse.py | 12 ++++- 11 files changed, 212 insertions(+), 21 deletions(-) diff --git a/doc/source/contents.rst b/doc/source/contents.rst index b2e5aa7..8ef1ff9 100644 --- a/doc/source/contents.rst +++ b/doc/source/contents.rst @@ -9,3 +9,5 @@ Documentation Contents getting_started.rst auto_examples/index.rst + tutorial.rst + diff --git a/doc/source/tutorial.rst b/doc/source/tutorial.rst index 12be396..1b406a6 100644 --- a/doc/source/tutorial.rst +++ b/doc/source/tutorial.rst @@ -1,6 +1,100 @@ .. _example_config: -TODO +====================================== +Getting starting with MNE command line +====================================== + +The quick start guide shows how to run a standard processing of the +sample data set provided with MNE. XXX add link to data set download + +First define your subject:: + + export SUBJECT=sample + +Build your source space:: + + # MRI (this is not really needed for anything) + mne_setup_mri --overwrite + + # Source space + mne_setup_source_space --ico -6 --overwrite + +Prepare for forward computation:: + + # For homegenious volume conductor + mne_setup_forward_model --homog --surf --ico 4 + + # or for XXX + mne_setup_forward_model --surf --ico 4 + +List your bad channels in a file. Example sample_bads.bad contains:: + + MEG 2443 + EEG 053 + +Mark bad channels:: + + mne_mark_bad_channels --bad sample_bads.bad sample_audvis_raw.fif + +Compute averaging:: + + mne_process_raw --raw sample_audvis_raw.fif --lowpass 40 --projoff \ + --saveavetag -ave --ave audvis.ave + +Compute the noise covariance matrix:: + + mne_process_raw --raw sample_audvis_raw.fif --lowpass 40 --projoff \ + --savecovtag -cov --cov audvis.cov + +Compute forward solution a.k.a. lead field:: + + # for MEG only + mne_do_forward_solution --mindist 5 --spacing oct-6 \ + --meas sample_audvis_raw.fif --bem sample-5120 --megonly --overwrite \ + --fwd sample_audvis-meg-oct-6-fwd.fif + + # for EEG only + mne_do_forward_solution --mindist 5 --spacing oct-6 \ + --meas sample_audvis_raw.fif --bem sample-5120-5120-5120 --eegonly \ + --fwd sample_audvis-eeg-oct-6-fwd.fif + + # for both EEG and MEG + mne_do_forward_solution --mindist 5 --spacing oct-6 \ + --meas sample_audvis_raw.fif --bem sample-5120-5120-5120 \ + --fwd sample_audvis-meg-eeg-oct-6-fwd.fif + +Compute MNE inverse operators:: + + # Note: The MEG/EEG forward solution could be used for all + mne_do_inverse_operator --fwd sample_audvis-meg-oct-6-fwd.fif \ + --depth --loose 0.2 --meg + + mne_do_inverse_operator --fwd sample_audvis-eeg-oct-6-fwd.fif \ + --depth --loose 0.2 --eeg + + mne_do_inverse_operator --fwd sample_audvis-meg-eeg-oct-6-fwd.fif \ + --depth --loose 0.2 --eeg --meg + +Produce stc files (activation files):: + + # for MEG + mne_make_movie --inv sample_audvis-meg-oct-6-${mod}-inv.fif \ + --meas sample_audvis-ave.fif \ + --tmin 0 --tmax 250 --tstep 10 --spm \ + --smooth 5 --bmin -100 --bmax 0 --stc sample_audvis-meg + + # for EEG + mne_make_movie --inv sample_audvis-eeg-oct-6-${mod}-inv.fif \ + --meas sample_audvis-ave.fif \ + --tmin 0 --tmax 250 --tstep 10 --spm \ + --smooth 5 --bmin -100 --bmax 0 --stc sample_audvis-eeg + + # for MEG and EEG combined + mne_make_movie --inv sample_audvis-meg-eeg-oct-6-${mod}-inv.fif \ + --meas sample_audvis-ave.fif \ + --tmin 0 --tmax 250 --tstep 10 --spm \ + --smooth 5 --bmin -100 --bmax 0 --stc sample_audvis-meg-eeg And, we're done! +You can now get started with the `examples <auto_examples/index.html>`_. diff --git a/examples/plot_compute_mne_inverse.py b/examples/plot_compute_mne_inverse.py index 99e9d2c..f4aa043 100644 --- a/examples/plot_compute_mne_inverse.py +++ b/examples/plot_compute_mne_inverse.py @@ -23,7 +23,19 @@ snr = 3.0 lambda2 = 1.0 / snr**2 dSPM = True -res = mne.compute_inverse(fname_data, setno, fname_inv, lambda2, dSPM) +res = mne.compute_inverse(fname_data, setno, fname_inv, lambda2, dSPM, + baseline=(None, 0)) + +# XXX : kind of ugly +import numpy as np +res['vertices'] = np.r_[res['inv']['src'][0]['vertno']] +# res['vertices'] = np.r_[res['inv']['src'][0]['vertno'], +# res['inv']['src'][1]['vertno']] +# res['data'] = res['sol'] +res['data'] = res['sol'][:len(res['vertices'])] + +# Save result in stc file +mne.write_stc('mne_dSPM_inverse-lh.stc', res) import pylab as pl pl.plot(res['sol'][::100,:].T) diff --git a/examples/plot_read_epochs.py b/examples/plot_read_epochs.py index cbf28b9..d04489d 100644 --- a/examples/plot_read_epochs.py +++ b/examples/plot_read_epochs.py @@ -24,9 +24,11 @@ from mne import fiff ############################################################################### # Set parameters raw_fname = os.environ['MNE_SAMPLE_DATASET_PATH'] -raw_fname += '/MEG/sample/sample_audvis_raw.fif' +# raw_fname += '/MEG/sample/sample_audvis_raw.fif' +raw_fname += '/MEG/sample/sample_audvis_filt-0-40_raw.fif' event_fname = os.environ['MNE_SAMPLE_DATASET_PATH'] -event_fname += '/MEG/sample/sample_audvis_raw-eve.fif' +# event_fname += '/MEG/sample/sample_audvis_raw-eve.fif' +event_fname += '/MEG/sample/sample_audvis_filt-0-40_raw-eve.fif' event_id = 1 tmin = -0.2 tmax = 0.5 @@ -43,7 +45,7 @@ exclude = raw['info']['bads'] + ['MEG 2443', 'EEG 053'] # bads + 2 more meg_picks = fiff.pick_types(raw['info'], meg=True, eeg=False, stim=False, include=include, exclude=exclude) meg_data, times, channel_names = mne.read_epochs(raw, events, event_id, - tmin, tmax, picks=meg_picks) + tmin, tmax, picks=meg_picks, baseline=(None, 0)) meg_epochs = np.array([d['epoch'] for d in meg_data]) # build 3D matrix meg_evoked_data = np.mean(meg_epochs, axis=0) # compute evoked fields @@ -51,7 +53,7 @@ meg_evoked_data = np.mean(meg_epochs, axis=0) # compute evoked fields eeg_picks = fiff.pick_types(raw['info'], meg=False, eeg=True, stim=False, include=include, exclude=exclude) eeg_data, times, channel_names = mne.read_epochs(raw, events, event_id, - tmin, tmax, picks=eeg_picks) + tmin, tmax, picks=eeg_picks, baseline=(None, 0)) eeg_epochs = np.array([d['epoch'] for d in eeg_data]) # build 3D matrix eeg_evoked_data = np.mean(eeg_epochs, axis=0) # compute evoked potentials diff --git a/examples/plot_read_evoked.py b/examples/plot_read_evoked.py index d7d0c4c..f9aeba2 100644 --- a/examples/plot_read_evoked.py +++ b/examples/plot_read_evoked.py @@ -17,7 +17,7 @@ fname = os.environ['MNE_SAMPLE_DATASET_PATH'] fname += '/MEG/sample/sample_audvis-ave.fif' # Reading -data = fiff.read_evoked(fname) +data = fiff.read_evoked(fname, baseline=(None, 0)) # Writing fiff.write_evoked('evoked.fif', data) @@ -26,7 +26,20 @@ fiff.write_evoked('evoked.fif', data) # Show result import pylab as pl -pl.plot(data['evoked']['times'], data['evoked']['epochs'][:306,:].T) +pl.subplot(3, 1, 1) +pl.plot(data['evoked']['times'], data['evoked']['epochs'][0:306:3,:].T) +pl.title('Planar Gradiometers') +pl.xlabel('time (s)') +pl.ylabel('MEG data (T / m)') +pl.subplot(3, 1, 2) +pl.plot(data['evoked']['times'], data['evoked']['epochs'][1:306:3,:].T) +pl.title('Axial Gradiometers') +pl.xlabel('time (s)') +pl.ylabel('MEG data (T / m)') +pl.subplot(3, 1, 3) +pl.plot(data['evoked']['times'], data['evoked']['epochs'][2:306:3,:].T) +pl.title('Magnetometers') pl.xlabel('time (s)') pl.ylabel('MEG data (T)') +pl.subplots_adjust(0.175, 0.08, 0.94, 0.94, 0.2, 0.63) pl.show() diff --git a/examples/plot_read_raw_data.py b/examples/plot_read_raw_data.py index 8074f84..b0305fa 100644 --- a/examples/plot_read_raw_data.py +++ b/examples/plot_read_raw_data.py @@ -17,7 +17,9 @@ fname += '/MEG/sample/sample_audvis_raw.fif' raw = fiff.setup_read_raw(fname) -meg_channels_idx = fiff.pick_types(raw['info'], meg=True) +exclude = ['MEG 2443', 'EEG 053'] # bad channels + +meg_channels_idx = fiff.pick_types(raw['info'], meg=True, exclude=exclude) meg_channels_idx = meg_channels_idx[:5] # take 5 first start, stop = raw.time_to_index(100, 115) # 100 s to 115 s data segment diff --git a/examples/read_events.py b/examples/read_events.py index 211c3c9..fcd941f 100644 --- a/examples/read_events.py +++ b/examples/read_events.py @@ -9,9 +9,11 @@ Reading an event file print __doc__ +import os import mne -fname = 'MNE-sample-data/MEG/sample/sample_audvis_raw-eve.fif' +fname = os.environ['MNE_SAMPLE_DATASET_PATH'] +fname += '/MEG/sample/sample_audvis_raw-eve.fif' # Reading events events = mne.read_events(fname) diff --git a/mne/epochs.py b/mne/epochs.py index ca3b9ac..010b2c1 100644 --- a/mne/epochs.py +++ b/mne/epochs.py @@ -8,7 +8,7 @@ import fiff def read_epochs(raw, events, event_id, tmin, tmax, picks=None, - keep_comp=False, dest_comp=0): + keep_comp=False, dest_comp=0, baseline=None): """Read epochs from a raw dataset Parameters @@ -28,6 +28,18 @@ def read_epochs(raw, events, event_id, tmin, tmax, picks=None, tmax : float End time after event + keep_comp : boolean + Apply CTF gradient compensation + + baseline: None (default) or tuple of length 2 + The time interval to apply baseline correction. + If None do not apply it. If baseline is (a, b) + the interval is between "a (s)" and "b (s)". + If a is None the beginning of the data is used + and if b is None then b is set to the end of the interval. + If baseline is equal ot (None, None) all the time + interval is used. + Returns ------- data : list of epochs @@ -147,6 +159,23 @@ def read_epochs(raw, events, event_id, tmin, tmax, picks=None, times = np.arange(start - event_samp, stop - event_samp, dtype=np.float) / sfreq + # Run baseline correction + if baseline is not None: + print "Applying baseline correction ..." + bmin = baseline[0] + bmax = baseline[1] + if bmin is None: + imin = 0 + else: + imin = int(np.where(times >= bmin)[0][0]) + if bmax is None: + imax = len(times) + else: + imax = int(np.where(times <= bmax)[0][-1]) + 1 + epoch -= np.mean(epoch[:, imin:imax], axis=1)[:,None] + else: + print "No baseline correction applied..." + d = dict() d['epoch'] = epoch d['event'] = event_id @@ -154,6 +183,7 @@ def read_epochs(raw, events, event_id, tmin, tmax, picks=None, d['tmax'] = (float(stop) - float(raw['first_samp'])) / sfreq data.append(d) + print 'Read %d epochs, %d samples each.' % (len(data), data[0]['epoch'].shape[1]) diff --git a/mne/fiff/evoked.py b/mne/fiff/evoked.py index f45272c..fb7611a 100644 --- a/mne/fiff/evoked.py +++ b/mne/fiff/evoked.py @@ -12,7 +12,7 @@ from .tree import dir_tree_find from .meas_info import read_meas_info -def read_evoked(fname, setno=0): +def read_evoked(fname, setno=0, baseline=None): """Read an evoked dataset Parameters @@ -24,6 +24,15 @@ def read_evoked(fname, setno=0): The index of the evoked dataset to read. FIF file can contain multiple datasets. + baseline: None (default) or tuple of length 2 + The time interval to apply baseline correction. + If None do not apply it. If baseline is (a, b) + the interval is between "a (s)" and "b (s)". + If a is None the beginning of the data is used + and if b is None then b is set to the end of the interval. + If baseline is equal ot (None, None) all the time + interval is used. + Returns ------- data: dict @@ -52,7 +61,6 @@ def read_evoked(fname, setno=0): raise ValueError, 'Could not find evoked data' # Identify the aspects - # naspect = 0 is_smsh = None sets = [] @@ -209,13 +217,31 @@ def read_evoked(fname, setno=0): cals = np.array([info['chs'][k].cal for k in range(info['nchan'])]) all_data = np.dot(np.diag(cals.ravel()), all_data) + times = np.arange(first, last+1, dtype=np.float) / info['sfreq'] + + # Run baseline correction + if baseline is not None: + print "Applying baseline correction ..." + bmin = baseline[0] + bmax = baseline[1] + if bmin is None: + imin = 0 + else: + imin = int(np.where(times >= bmin)[0][0]) + if bmax is None: + imax = len(times) + else: + imax = int(np.where(times <= bmax)[0][-1]) + 1 + all_data -= np.mean(all_data[:, imin:imax], axis=1)[:,None] + else: + print "No baseline correction applied..." + # Put it all together data = dict(info=info, evoked=dict(aspect_kind=aspect_kind, is_smsh=is_smsh[setno], nave=nave, first=first, last=last, comment=comment, - times=np.arange(first, last+1, - dtype=np.float) / info['sfreq'], + times=times, epochs=all_data)) fid.close() diff --git a/mne/fiff/raw.py b/mne/fiff/raw.py index a62ae86..100dbe7 100644 --- a/mne/fiff/raw.py +++ b/mne/fiff/raw.py @@ -76,14 +76,14 @@ def setup_read_raw(fname, allow_maxshield=False): # Locate the data of interest raw = dir_tree_find(meas, FIFF.FIFFB_RAW_DATA) - if raw is None: + if len(raw) == 0: raw = dir_tree_find(meas, FIFF.FIFFB_CONTINUOUS_DATA) if allow_maxshield: raw = dir_tree_find(meas, FIFF.FIFFB_SMSH_RAW_DATA) - if raw is None: + if len(raw) == 0: raise ValueError, 'No raw data in %s' % fname else: - if raw is None: + if len(raw) == 0: raise ValueError, 'No raw data in %s' % fname if len(raw) == 1: @@ -618,7 +618,7 @@ def _make_compensator(info, kind): def make_compensator(info, from_, to, exclude_comp_chs=False): - """ + """ XXX : bug !!! 2 make_compensator functions % % [comp] = mne_make_compensator(info,from,to,exclude_comp_chs) % diff --git a/mne/inverse.py b/mne/inverse.py index 6886ee4..ffb6665 100644 --- a/mne/inverse.py +++ b/mne/inverse.py @@ -402,7 +402,7 @@ def prepare_inverse_operator(orig, nave, lambda2, dSPM): def compute_inverse(fname_data, setno, fname_inv, lambda2, dSPM=True, - nave=None): + nave=None, baseline=None): """Compute inverse solution Computes a L2-norm inverse solution @@ -424,6 +424,14 @@ def compute_inverse(fname_data, setno, fname_inv, lambda2, dSPM=True, The regularization parameter dSPM: bool do dSPM ? + baseline: None (default) or tuple of length 2 + The time interval to apply baseline correction. + If None do not apply it. If baseline is (a, b) + the interval is between "a ms" and "b ms". + If a is None the beginning of the data is used + and if b is None then b is set to the end of the interval. + If baseline is equal ot (None, None) all the time + interval is used. Returns ------- @@ -434,7 +442,7 @@ def compute_inverse(fname_data, setno, fname_inv, lambda2, dSPM=True, # # Read the data first # - data = read_evoked(fname_data, setno) + data = read_evoked(fname_data, setno, baseline=baseline) # # Then the inverse operator # -- 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
