⇤ ← Revision 1 as of 2011-08-11 14:46:30
Size: 5002
Comment:
|
Size: 5224
Comment:
|
Deletions are marked like this. | Additions are marked like this. |
Line 25: | Line 25: |
For your convenience, the example data set has already been downloaded to '''/imaging/olaf/MEG/MNE_Python/MNE-sample-data'''. Apparently, the folder "/MEG/sample/labels" is missing, so one part of the example won't work. Below, I've copied the commands from the [http://mne-tools.github.com/mne-python-intro/ MNE-Python intro page] into a text file, and removed any unnecessary text. You may use it to copy/paste sections of it into your Python window and play around with it. | For your convenience, the example data set has already been downloaded to '''/imaging/olaf/MEG/MNE_Python/MNE-sample-data''' (but feel free to download it yourself - this may take a while though). If you want to use it, you have to change the data_path variable "data_path = /imaging/olaf/MEG/MNE_Python/MNE-sample-data" at the top of the example (see below). The folder "/MEG/sample/labels" is missing, so one part of the example won't work. Below, I've copied the commands from the [http://mne-tools.github.com/mne-python-intro/ MNE-Python intro page] into a text file, and removed any unnecessary text. You may use it to copy/paste sections of it into your Python window and play around with it. |
Using MNE Python at the CBU
MNE is a software developed for EEG/MEG analysis at the [http://www.nmr.mgh.harvard.edu/martinos/userInfo/data/sofMNE.php Martinos Centre for Biomedical Imaging]. It was originally developed for use under Linux (see e.g. [http://www.martinos.org/mne/ MNE examples], and [http://imaging.mrc-cbu.cam.ac.uk/meg/AnalyzingData/MNE_overview MNE at the CBU].
Recently, MNE has been integrated into [http://www.python.org/ Python] for optimization and automatization, as described on the [http://mne-tools.github.com/mne-python-intro/ MNE-Python intro pages].
In order to use MNE-Python at the CBU, type
mne_python
in your Linux command window, which will run it in the iPython environment on one of the linux boxes 43-56.
In order to check whether you've got access to the MNE Python tools, type
mne. <tab>
(where <tab> means pressing your tab key, not enter), and you'll see a list of MNE commands.
You are ready to go, and you might want to start with the example on the [http://mne-tools.github.com/mne-python-intro/ MNE-Python intro] site.
For your convenience, the example data set has already been downloaded to /imaging/olaf/MEG/MNE_Python/MNE-sample-data (but feel free to download it yourself - this may take a while though). If you want to use it, you have to change the data_path variable "data_path = /imaging/olaf/MEG/MNE_Python/MNE-sample-data" at the top of the example (see below). The folder "/MEG/sample/labels" is missing, so one part of the example won't work. Below, I've copied the commands from the [http://mne-tools.github.com/mne-python-intro/ MNE-Python intro page] into a text file, and removed any unnecessary text. You may use it to copy/paste sections of it into your Python window and play around with it.
It's all quite new and exciting, so any comments or feedback would be welcome!
import mne # Access raw data from mne.datasets import sample data_path = sample.data_path() raw_fname = data_path + '/MEG/sample/sample_audvis_filt-0-40_raw.fif' print raw_fname # Read data from file raw = mne.fiff.Raw(raw_fname) print raw # Read and plot a segment of raw data start, stop = raw.time_to_index(100, 115) # 100 s to 115 s data segment data, times = raw[:, start:stop] print data.shape print times.shape data, times = raw[2:20:3, start:stop] # take some Magnetometers # Save a segment of 150s of raw data (MEG only): picks = mne.fiff.pick_types(raw.info, meg=True, eeg=False, stim=True) raw.save('sample_audvis_meg_raw.fif', tmin=0, tmax=150, picks=picks) #First extract events: events = mne.find_events(raw, stim_channel='STI 014') print events[:5] # Define epochs parameters: event_id = 1 tmin = -0.2 tmax = 0.5 # Exclude some channels (bads + 2 more): exclude = raw.info['bads'] + ['MEG 2443', 'EEG 053'] # Pick the good channels: picks = mne.fiff.pick_types(raw.info, meg=True, eeg=True, eog=True, stim=False, exclude=exclude) # Define the baseline period: baseline = (None, 0) # means from the first instant to t = 0 # Define peak-to-peak rejection parameters for gradiometers, magnetometers and EOG: reject = dict(grad=4000e-13, mag=4e-12, eog=150e-6) # Read epochs: epochs = mne.Epochs(raw, events, event_id, tmin, tmax, proj=True, picks=picks, baseline=baseline, preload=False, reject=reject) print epochs # Compute evoked responses by averaging and plot it: evoked = epochs.average() print evoked from mne.viz import plot_evoked plot_evoked(evoked) # Extract the max value of each epoch max_in_each_epoch = [e.max() for e in epochs] print max_in_each_epoch[:4] ## Time-Frequency: Induced power and phase-locking values # Define parameters: import numpy as np n_cycles = 2 # number of cycles in Morlet wavelet frequencies = np.arange(7, 30, 3) # frequencies of interest Fs = raw.info['sfreq'] # sampling in Hz # Compute induced power and phase-locking values: data = epochs.get_data() from mne.time_frequency import induced_power power, phase_lock = induced_power(data, Fs=Fs, frequencies=frequencies, n_cycles=2, n_jobs=1) ## Inverse modeling: MNE and dSPM on evoked and raw data # Import the required functions: from mne.minimum_norm import apply_inverse, read_inverse_operator # Read the inverse operator: fname_inv = data_path + '/MEG/sample/sample_audvis-meg-oct-6-meg-inv.fif' inverse_operator = read_inverse_operator(fname_inv) # Define the inverse parameters: snr = 3.0 lambda2 = 1.0 / snr ** 2 dSPM = True # Compute the inverse solution: stc = apply_inverse(evoked, inverse_operator, lambda2, dSPM) # Save the source time courses to disk: stc.save('mne_dSPM_inverse') # Now, let’s compute dSPM on a raw file within a label: fname_label = data_path + '/MEG/sample/labels/Aud-lh.label' label = mne.read_label(fname_label) # Compute inverse solution during the first 15s: from mne.minimum_norm import apply_inverse_raw start, stop = raw.time_to_index(0, 15) # read the first 15s of data stc = apply_inverse_raw(raw, inverse_operator, lambda2, dSPM, label, start, stop) # Save result in stc files: stc.save('mne_dSPM_raw_inverse_Aud')