Making SSP files with python

Hi all,

I've been working with the python tools to build SSP projectors for EOG and
ECG. I had thought that it might be necessary to use make_projector after
compute_spatial_vectors, but write_proj seems to work perfectly well with
the output from compute_spatial_vectors. The output files are usable in
both MNE and Neuromag. As with projectors build using mne_process_raw,
xfit treats these projectors as if they had been applied explicitly to the
data. Using the sample data, what I'm doing is:

raw_fname = data_path + '/MEG/sample/sample_audvis_raw.fif'
raw = fiff.Raw(raw_fname)
exclude = raw.info['bads'] + ['MEG 2443', 'EEG 053']

# Make list of channel names into an array suitable for index
names = np.array(raw.info['ch_names'], dtype='S7')

# Do EOG
event_id = 998
eog_events = mne.artifacts.find_eog_events(raw, event_id)
picks = fiff.pick_types(raw.info, meg=True, eeg=False, eog=False,
ecg=False, stim=False, exclude=exclude)
ch_names = names[picks]
tmin, tmax = -0.5, 0.5
epochs = mne.Epochs(raw, eog_events, event_id, tmin, tmax,
baseline=(-0.5,-0.2), picks=picks, proj=False)
data = epochs.get_data()
EOGprojs = fiff.proj.compute_spatial_vectors(epochs, n_grad=1, n_mag=1,
n_eeg=0)

EOGprojfile = raw_fname[:-4] + '_EOG_auto-proj.fif'
fid = fiff.write.start_file(EOGprojfile)
fiff.proj.write_proj(fid, EOGprojs)
fiff.write.end_file(fid)

Am I skipping a step somewhere along the way, or does this seem reasonable?
  I've attached the complete script, in case it's helpful.

Thanks,

Jon Houck
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.nmr.mgh.harvard.edu/pipermail/mne_analysis/attachments/20120217/1de1092a/attachment.html
-------------- next part --------------
A non-text attachment was scrubbed...
Name: make_eog_ecg_ssp.py
Type: text/x-python
Size: 3484 bytes
Desc: not available
Url : http://mail.nmr.mgh.harvard.edu/pipermail/mne_analysis/attachments/20120217/1de1092a/attachment.py

hi jon,

I've been working with the python tools to build SSP projectors for EOG and
ECG. ? I had thought that it might be necessary to use make_projector after
compute_spatial_vectors, but?write_proj seems to work perfectly well with
the output from compute_spatial_vectors.

the make_projector function assembles the projection matrix while the structure
returned by compute_spatial_vectors contains what is stored in a fif files.
So what you describe is correct.

The output files are usable in both
MNE and Neuromag. ?As with projectors build using mne_process_raw, xfit
treats these projectors as if they had been applied explicitly to the data.
?Using the sample data, what I'm doing is:

raw_fname = data_path + '/MEG/sample/sample_audvis_raw.fif'
raw = fiff.Raw(raw_fname)
exclude = raw.info['bads'] + ['MEG 2443', 'EEG 053']

# Make list of channel names into an array suitable for index
names = np.array(raw.info['ch_names'], dtype='S7')

# Do EOG
event_id = 998
eog_events = mne.artifacts.find_eog_events(raw, event_id)
picks = fiff.pick_types(raw.info, meg=True, eeg=False, eog=False, ecg=False,
stim=False, exclude=exclude)
ch_names = names[picks]
tmin, tmax = -0.5, 0.5
epochs = mne.Epochs(raw, eog_events, event_id, tmin, tmax,
baseline=(-0.5,-0.2), picks=picks, proj=False)
data = epochs.get_data()
EOGprojs = fiff.proj.compute_spatial_vectors(epochs, n_grad=1, n_mag=1,
n_eeg=0)

EOGprojfile = ?raw_fname[:-4] + '_EOG_auto-proj.fif'
fid = fiff.write.start_file(EOGprojfile)
fiff.proj.write_proj(fid, EOGprojs)
fiff.write.end_file(fid)

Am I skipping a step somewhere along the way, or does this seem reasonable?

yes it does.

we might however need to do something so you don't need to manually
start end end the fif files.

if you think it could be written in a smaller/cleaner way let me know.

Alex