|
Size: 5282
Comment:
|
← Revision 14 as of 2016-01-22 11:47:09 ⇥
Size: 1512
Comment:
|
| Deletions are marked like this. | Additions are marked like this. |
| Line 2: | Line 2: |
| Line 7: | Line 6: |
| In order to use MNE-Python at the CBU, type | In order to use the latest MNE-Python version at the CBU, type |
| Line 12: | Line 11: |
| in your Linux command window, which will run it in the iPython environment on one of the linux boxes 43-56. This might take a while to start - please be patient. | |
| Line 13: | Line 13: |
| in your Linux command window, which will run it in the iPython environment on one of the linux boxes 43-56. This might take a while to start. In order to check whether you've got access to the MNE Python tools, type |
In order to use a specific version, type for example |
| Line 18: | Line 16: |
| mne. <tab> }}} |
mne_python -v 0.10 }}} The best way to learn MNE-Python is to check out the [[http://martinos.org/mne/stable/tutorials.html|tutorials]] and [[https://martinos.org/mne/stable/auto_examples/index.html|examples]]. |
| Line 21: | Line 20: |
| (where <tab> means pressing your tab key, not enter), and you'll see a list of MNE commands. | If you are new to programming and scripting, you may want to look for some [[http://imaging.mrc-cbu.cam.ac.uk/meg/Beginners|general tutorials]]. |
| Line 23: | Line 22: |
| 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. | They provide a sample data set, and a large number of example analysis scripts that can be directly applied to those data. |
| Line 25: | Line 24: |
| 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') }}} |
It's all quite new and exciting, so any comments or feedback would be welcome! Please contact OlafHauk. |
Using MNE Python at the CBU
MNE is a software developed for EEG/MEG analysis at the Martinos Centre for Biomedical Imaging. It was originally developed for use under Linux (see e.g. MNE examples, and MNE at the CBU.
Recently, MNE has been integrated into Python for optimization and automatization, as described on the MNE-Python intro pages.
In order to use the latest MNE-Python version 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. This might take a while to start - please be patient.
In order to use a specific version, type for example
mne_python -v 0.10
The best way to learn MNE-Python is to check out the tutorials and examples.
If you are new to programming and scripting, you may want to look for some general tutorials.
They provide a sample data set, and a large number of example analysis scripts that can be directly applied to those data.
It's all quite new and exciting, so any comments or feedback would be welcome! Please contact OlafHauk.
