Skip to content

Commit

Permalink
wip py3k
Browse files Browse the repository at this point in the history
  • Loading branch information
warrd authored and agramfort committed Dec 10, 2013
1 parent f311096 commit 3418ed4
Show file tree
Hide file tree
Showing 95 changed files with 505 additions and 406 deletions.
7 changes: 4 additions & 3 deletions mne/beamformer/_dics.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
from ..source_estimate import SourceEstimate
from ..time_frequency import CrossSpectralDensity, compute_epochs_csd
from ._lcmv import _prepare_beamformer_input
import six


@verbose
Expand Down Expand Up @@ -77,7 +78,7 @@ def _apply_dics(data, info, tmin, forward, noise_csd, data_csd, reg,
n_orient = 3 if is_free_ori else 1
n_sources = G.shape[1] // n_orient

for k in xrange(n_sources):
for k in range(n_sources):
Wk = W[n_orient * k: n_orient * k + n_orient]
Gk = G[:, n_orient * k: n_orient * k + n_orient]
Ck = np.dot(Wk, Gk)
Expand Down Expand Up @@ -191,7 +192,7 @@ def dics(evoked, forward, noise_csd, data_csd, reg=0.01, label=None,

stc = _apply_dics(data, info, tmin, forward, noise_csd, data_csd, reg=reg,
label=label, pick_ori=pick_ori)
return stc.next()
return six.advance_iterator(stc)


@verbose
Expand Down Expand Up @@ -372,7 +373,7 @@ def dics_source_power(info, forward, noise_csds, data_csds, reg=0.01,

# Compute spatial filters
W = np.dot(G.T, Cm_inv)
for k in xrange(n_sources):
for k in range(n_sources):
Wk = W[n_orient * k: n_orient * k + n_orient]
Gk = G[:, n_orient * k: n_orient * k + n_orient]
Ck = np.dot(Wk, Gk)
Expand Down
9 changes: 5 additions & 4 deletions mne/beamformer/_lcmv.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
from ..source_space import label_src_vertno_sel
from ..utils import logger, verbose
from .. import Epochs
import six


@verbose
Expand Down Expand Up @@ -289,8 +290,8 @@ def lcmv(evoked, forward, noise_cov, data_cov, reg=0.01, label=None,
data = evoked.data
tmin = evoked.times[0]

stc = _apply_lcmv(data, info, tmin, forward, noise_cov, data_cov, reg,
label, pick_ori=pick_ori).next()
stc = six.advance_iterator(_apply_lcmv(data, info, tmin, forward, noise_cov, data_cov, reg,
label, pick_ori=pick_ori))

return stc

Expand Down Expand Up @@ -431,8 +432,8 @@ def lcmv_raw(raw, forward, noise_cov, data_cov, reg=0.01, label=None,
data, times = raw[picks, start:stop]
tmin = times[0]

stc = _apply_lcmv(data, info, tmin, forward, noise_cov, data_cov, reg,
label, picks, pick_ori).next()
stc = six.advance_iterator(_apply_lcmv(data, info, tmin, forward, noise_cov, data_cov, reg,
label, picks, pick_ori))

return stc

Expand Down
5 changes: 3 additions & 2 deletions mne/beamformer/tests/test_dics.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from __future__ import print_function
import warnings
import os.path as op
import copy as cp
Expand Down Expand Up @@ -206,7 +207,7 @@ def test_dics_source_power():
for freq, data_csd in zip(frequencies, data_csds):
data_csd.frequencies = [freq]
noise_csds = data_csds
with warnings.catch_warnings(True) as w:
with warnings.catch_warnings(record=True) as w:
dics_source_power(epochs.info, forward, noise_csds, data_csds)
assert len(w) == 1

Expand Down Expand Up @@ -235,7 +236,7 @@ def test_tf_dics():
freq_bins, reg=reg, label=label)

assert_true(len(stcs) == len(freq_bins))
print stcs[0].shape
print(stcs[0].shape)
assert_true(stcs[0].shape[1] == 4)

# Manually calculating source power in several time windows to compare
Expand Down
6 changes: 3 additions & 3 deletions mne/beamformer/tests/test_lcmv.py
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ def test_tf_lcmv():
raw_band.filter(l_freq, h_freq, method='iir', n_jobs=1, picks=picks)
epochs_band = mne.Epochs(raw_band, epochs.events, epochs.event_id,
tmin=tmin, tmax=tmax, proj=True)
with warnings.catch_warnings(True): # not enough samples
with warnings.catch_warnings(record=True): # not enough samples
noise_cov = compute_covariance(epochs_band, tmin=tmin, tmax=tmin +
win_length)
noise_cov = mne.cov.regularize(noise_cov, epochs_band.info, mag=reg,
Expand All @@ -311,7 +311,7 @@ def test_tf_lcmv():
# time windows to compare to tf_lcmv results and test overlapping
if (l_freq, h_freq) == freq_bins[0]:
for time_window in time_windows:
with warnings.catch_warnings(True):
with warnings.catch_warnings(record=True):
data_cov = compute_covariance(epochs_band,
tmin=time_window[0],
tmax=time_window[1])
Expand Down Expand Up @@ -360,7 +360,7 @@ def test_tf_lcmv():
assert_raises(ValueError, tf_lcmv, epochs_preloaded, forward, noise_covs,
tmin, tmax, tstep, win_lengths, freq_bins)

with warnings.catch_warnings(True): # not enough samples
with warnings.catch_warnings(record=True): # not enough samples
# Pass only one epoch to test if subtracting evoked
# responses yields zeros
stcs = tf_lcmv(epochs[0], forward, noise_covs, tmin, tmax, tstep,
Expand Down
27 changes: 14 additions & 13 deletions mne/commands/mne_clean_eog_ecg.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#!/usr/bin/env python
"""Clean a raw file from EOG and ECG artifacts with PCA (ie SSP)
"""
from __future__ import print_function

# Authors : Dr Engr. Sheraz Khan, P.Eng, Ph.D.
# Engr. Nandita Shetty, MS.
Expand Down Expand Up @@ -55,14 +56,14 @@ def clean_ecg_eog(in_fif_fname, out_fif_fname=None, eog=True, ecg=True,
if eog_event_fname is None:
eog_event_fname = prefix + '_eog-eve.fif'

print 'Implementing ECG and EOG artifact rejection on data'
print('Implementing ECG and EOG artifact rejection on data')

if ecg:
ecg_events, _, _ = mne.preprocessing.find_ecg_events(raw_in)
print "Writing ECG events in %s" % ecg_event_fname
print("Writing ECG events in %s" % ecg_event_fname)
mne.write_events(ecg_event_fname, ecg_events)

print 'Computing ECG projector'
print('Computing ECG projector')

command = ('mne_process_raw --cd %s --raw %s --events %s --makeproj '
'--projtmin -0.08 --projtmax 0.08 --saveprojtag _ecg_proj '
Expand All @@ -72,48 +73,48 @@ def clean_ecg_eog(in_fif_fname, out_fif_fname=None, eog=True, ecg=True,
st = os.system(command)

if st != 0:
print "Error while running : %s" % command
print("Error while running : %s" % command)

if eog:
eog_events = mne.preprocessing.find_eog_events(raw_in)
print "Writing EOG events in %s" % eog_event_fname
print("Writing EOG events in %s" % eog_event_fname)
mne.write_events(eog_event_fname, eog_events)

print 'Computing EOG projector'
print('Computing EOG projector')

command = ('mne_process_raw --cd %s --raw %s --events %s --makeproj '
'--projtmin -0.15 --projtmax 0.15 --saveprojtag _eog_proj '
'--projnmag 2 --projngrad 2 --projevent 998 --lowpass 35 '
'--projmagrej 4000 --projgradrej 3000' % (in_path,
in_fif_fname, eog_event_fname))

print 'Running : %s' % command
print('Running : %s' % command)

st = os.system(command)
if st != 0:
raise ValueError('Problem while running : %s' % command)

if out_fif_fname is not None:
# Applying the ECG EOG projector
print 'Applying ECG EOG projector'
print('Applying ECG EOG projector')

command = ('mne_process_raw --cd %s --raw %s '
'--proj %s --projoff --save %s --filteroff'
% (in_path, in_fif_fname, in_fif_fname, out_fif_fname))
command += ' --proj %s --proj %s' % (ecg_proj_fname, eog_proj_fname)

print 'Command executed: %s' % command
print('Command executed: %s' % command)

st = os.system(command)

if st != 0:
raise ValueError('Pb while running : %s' % command)

print 'Done removing artifacts.'
print "Cleaned raw data saved in: %s" % out_fif_fname
print 'IMPORTANT : Please eye-ball the data !!'
print('Done removing artifacts.')
print("Cleaned raw data saved in: %s" % out_fif_fname)
print('IMPORTANT : Please eye-ball the data !!')
else:
print 'Projection not applied to raw data.'
print('Projection not applied to raw data.')


if __name__ == '__main__':
Expand Down
12 changes: 7 additions & 5 deletions mne/commands/mne_compute_proj_ecg.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@
$ mne compute_proj_ecg -i sample_audvis_raw.fif -c "MEG 1531" --l-freq 1 --h-freq 100 --rej-grad 3000 --rej-mag 4000 --rej-eeg 100
"""
from __future__ import print_function

# Authors : Alexandre Gramfort, Ph.D.
# Martin Luessi, Ph.D.

from six import string_types
import os
import sys
import mne
Expand Down Expand Up @@ -154,7 +156,7 @@

if bad_fname is not None:
bads = [w.rstrip().split()[0] for w in open(bad_fname).readlines()]
print 'Bad channels read : %s' % bads
print('Bad channels read : %s' % bads)
else:
bads = []

Expand Down Expand Up @@ -191,15 +193,15 @@
raw_event.close()

if proj_fname is not None:
print 'Including SSP projections from : %s' % proj_fname
print('Including SSP projections from : %s' % proj_fname)
# append the ecg projs, so they are last in the list
projs = mne.read_proj(proj_fname) + projs

if isinstance(preload, basestring) and os.path.exists(preload):
if isinstance(preload, string_types) and os.path.exists(preload):
os.remove(preload)

print "Writing ECG projections in %s" % ecg_proj_fname
print("Writing ECG projections in %s" % ecg_proj_fname)
mne.write_proj(ecg_proj_fname, projs)

print "Writing ECG events in %s" % ecg_event_fname
print("Writing ECG events in %s" % ecg_event_fname)
mne.write_events(ecg_event_fname, events)
12 changes: 7 additions & 5 deletions mne/commands/mne_compute_proj_eog.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,12 @@
to exclude ECG artifacts from projection computation.
"""
from __future__ import print_function

# Authors : Alexandre Gramfort, Ph.D.
# Martin Luessi, Ph.D.

from six import string_types
import os
import sys
import mne
Expand Down Expand Up @@ -137,7 +139,7 @@

if bad_fname is not None:
bads = [w.rstrip().split()[0] for w in open(bad_fname).readlines()]
print 'Bad channels read : %s' % bads
print('Bad channels read : %s' % bads)
else:
bads = []

Expand Down Expand Up @@ -176,15 +178,15 @@
raw_event.close()

if proj_fname is not None:
print 'Including SSP projections from : %s' % proj_fname
print('Including SSP projections from : %s' % proj_fname)
# append the eog projs, so they are last in the list
projs = mne.read_proj(proj_fname) + projs

if isinstance(preload, basestring) and os.path.exists(preload):
if isinstance(preload, string_types) and os.path.exists(preload):
os.remove(preload)

print "Writing EOG projections in %s" % eog_proj_fname
print("Writing EOG projections in %s" % eog_proj_fname)
mne.write_proj(eog_proj_fname, projs)

print "Writing EOG events in %s" % eog_event_fname
print("Writing EOG events in %s" % eog_event_fname)
mne.write_events(eog_event_fname, events)
9 changes: 5 additions & 4 deletions mne/commands/mne_flash_bem_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
directory.
"""
from __future__ import print_function

# Authors: Rey Rene Ramirez, Ph.D. e-mail: rrramir at uw.edu
# Alexandre Gramfort, Ph.D.
Expand Down Expand Up @@ -71,19 +72,19 @@ def make_flash_bem(subject, subjects_dir, flash05, flash30, show=False):
# flash_dir = os.getcwd()
if not os.path.exists('parameter_maps'):
os.mkdir("parameter_maps")
print "--- Converting Flash 5"
print("--- Converting Flash 5")
os.system('mri_convert -flip_angle %s -tr 25 %s mef05.mgz' %
(5 * math.pi / 180, flash05))
print "--- Converting Flash 30"
print("--- Converting Flash 30")
os.system('mri_convert -flip_angle %s -tr 25 %s mef30.mgz' %
(30 * math.pi / 180, flash30))
print "--- Running mne_flash_bem"
print("--- Running mne_flash_bem")
os.system('mne_flash_bem --noconvert')
os.chdir(os.path.join(subjects_dir, subject, 'bem'))
if not os.path.exists('flash'):
os.mkdir("flash")
os.chdir("flash")
print "[done]"
print("[done]")

if show:
fnames = ['outer_skin.surf', 'outer_skull.surf', 'inner_skull.surf']
Expand Down
Loading

0 comments on commit 3418ed4

Please sign in to comment.