MNE Commands

See the MEG homepage "MNE analysis manual" for more detail on the standard stuff.
Described below are quick reference items.



Table O' Contents:


Movie Making
    Detailed How To Make A Movie
    Streamlined Instructions
    Cookbook MNE Stream
    Daniel Stream
Misc. Useful Tricks
    How to generate .pri files
    How to figure out why movies don't show anything
    How to convert .fiff files to matlab
    How to get BEM into XFIT
    How to change nave
    How to read nave
    How to fix EEG channels
    How to read sampling frequency
    How to copy SSP info
    How to get head position info
    How to get the MRI-MEG transform
    How to convert a stc file to a w file
    How to convert raw data to MNE
    How to identify bad channels from a fwd fif file
    How to create a head.fif file for mne_analyze


Detailed How To Make A Movie:
http://www.nmr.mgh.harvard.edu/~daniel/links/how/how_to_make_movies.html


Streamlined instructions for MEG movies:

mne_setup
setenv SUBJECTS_DIR <subjects-dir>
setenv SUBJECT <subjectname>
mne_setup_mri
mne_setup_source_space

** Make a BEM with Seglab **

MEG ONLY kind:
mne_setup_forward_model --homog [--noswap]
The noswap command is needed if the BEM was made with Seglab.

mne_fix_stim14_cal <filename>
fiff_downsample <factor> <infile> <outfile>

How to downsample a whole directory:
~/scripts/batch_downsample <num>
This generates a file called runme.
Call it like this:
./runme

* filtering
off-line averaging (make filenames that end in _raw.fif)
align coordinate frames of MRI

At this point you are ready. Select either the cookbook stream or the Daniel stream.



"COOKBOOK" STREAM....

(This is the usual stuff that Matti's cookbook describes. I no longer use these commands directly, since I have scripts to automate and connect these commands. See my "Daniel's Stream" below.
MEG/EEG:
mne_setup_forward_model

MEG ONLY kind:
mne_do_forward_solution --megonly --meas <MEG-.fif-file>
MEG/EEG:
mne_do_forward_solution --meas <MEG-.fif-file>

* make noise covariance matrix *
* copy .w file to .pri for fmri constraint *
mne_do_inverse_operator --fwd <forward-solution-name>
    [--fmri <.pri file> --fmrithresh <value> --fmrioff <value>]
(See below for generating .pri files)



Daniel's Stream

These scripts must be downloaded from my tools. You must also set up an environment variable called MEG_SCRIPTS.

NEW DISCLAIMER: Matti has added additional tools to his MNE stream. These tools allow users a much more user friendly and flexible method for making MNE solutions. The stream described here was much more useful prior to his new tools being released.

$MEG_SCRIPTS/meg_ave_script
This will run the meg averager with all the options that I specifically need.
In particular, I generate a .lst file, which I then modify with matlab, and
then run meg_average again to use the changes to the .lst file. The reason I
do all that is so that I can get a "correct response" average.

$MEG_SCRIPTS/batch_average
This will run the meg_ave_script for an entire directory.

$MEG_SCRIPTS/make_MNE
This command is documented. Run it with no options. It basically will do the entire
movie, picture and montage series. It can do fMRI weighting or not, it can do part
or all of the Cookbook stream. It is super flexible.

$MEG_SCRIPTS/batch_MNE
This command will run make_MNE for a directory with some simple options.


How to generate .pri files:
First, you need to generate surfaces with the paint-sess command (or my own me_draw commands.
This generates files that have  the form t-0-subj009-lh.w and  t-0-subj009-rh.w. They are found in bold/<studyname>/<contrastname> or in bold/<studyname>/sph/<contrastname>, depending on if you paint the surface to spherical coordinates or not. According to Thomas, .pri files can be generated either way. I wrote a script to make a set of .pri files per subject, called drawOneSet.



How to figure out why your movies don't show anything...
1.Open the stc folder
2.run mne_process_stc --stc <filename>  to find out maximum F value
Now check what fthreshold you used in preparing the movie. If it was too high, you cut everything out!


<>Commands to convert fiif files to matlab
fiff2asc -TVst *.fif
matlab &
asc2mat('08')
or...
mne_convert_mne_data

or...
mne_raw2mat

How to take BEM made with Seglab into XFIT...
---------------------------------------------
1. Prepare the BEM using the MNE stream, i.e., do
mne_setup_forward_model as you would do for movies. Be sure you did NOT
use the --nosol option.

2. Before starting xfit

setenv BEM_MODEL_DIR $SUBJECTS_DIR/$SUBJECT/bem

3. You can then directly use the BEM without another preparation step.
The head <-> MRI coordinate transform should be loaded from the MRI
description file, prepared with MRIlab. The location is
$SUBJECTS_DIR/$SUBJECT/mri/T1-neuromag/sets 


How To Change the Number of Iterations (nave) in an average .fif:
mne_change_nave --nave <number> <file>


How to read fiff info to find number of trials averaged (called nave):
show_fiff -vt 207 <filename.fif> | cut -f 2


How to read fiff info to find sampling frequency:
show_fiff -vt 201
<filename.fif>


How to fix EEG channels:
If you are using OLD EEG data for any kind of forward modeling or
inverse modeling (this includes MNE movies), it is *POSSIBLE* that your
data file does not have the correct number of EEG channels listed in the
header.

IF and ONLY IF that happened to you, you can run the following command
to fix the problem:

apply_eeg_locations <filename1.fif> <filename2.fif>

If you have a raw data file, filename1  = filename2.
If you have an evoked data file computed with meg_average, filename1 is
the original raw data file, and filenam2 is the evoked file.


How to copy SSP info for 4Dtoolbox generated files:
goto dipole
copy_trans [-f] <src> <dest>


How to get the head position info:
fiff2ascii -p <filename>


How to get the transformation from a MRI in fiff format:
show_fiff -t 222 -v -T <filename.fif> | head -5

The result of that will be 4 x 4 matrix which is:
T =    [ Rxx Rxy Rxz  0 ]
       [ Ryx Ryy Ryz  0 ]
       [ Rzx Rzy Rzz  0 ]
       [ x0  y0  z0  1 ]
the units are mm.
If a coordinate vector Rhead was in MEG coordinate system, and you want a coordinate vector Rmri in MRI coordinates, then you could write:
Rmri = [ Xhead Yhead Zhead 1] * T
Also, if you ONLY want the numbers, type:
show_fiff -t 222 -v -T <filename.fif> | head -5 | tail -4


How to convert stc data to a w file
stc2w -s <starttime> -e <endtime> -stc <stcfile>
    note: this command is a script I wrote. You will need to download it from my tools.



How to convert a raw (not-averaged) MEG data file into MNE:
mne_compute_raw_inverse --in <raw_filename> --inv <inv_filename>
--snr <snrvalue> --picknormalcomp --spm --label <labelname> --align_z
the align z command will help to distinguish two sides of a sulcus based on the sign of the currents

That function will take a raw data file, after getting a fwd and inv files from it, will act similar to the mne_compute_mne, except that in this case it makes a fiff file which contains ROI time courses for an entire raw data file.

Warning: This function has not been thoroughly tested yet. Use at your own risk.


   How to identify bad channels from a fwd .fif file:
show_fiff -v -t 3507 <fwd-filename.fif> | more



How to make a head.fif file for mne_analyze
(pretend your subject is bob)
cd bob/bem
mne_surf2bem --surf outer_skin-5120.surf --id 4 --fif bob-head.fif