[med-svn] [python-mne] 209/376: ENH : source_induced_power and SourceEstimate + 3D source viewer
Yaroslav Halchenko
debian at onerussian.com
Fri Nov 27 17:22:39 UTC 2015
This is an automated email from the git hooks/post-receive script.
yoh pushed a commit to annotated tag v0.1
in repository python-mne.
commit 7bccdfce9226acfffc1abf2e17df8e1520d81f77
Author: Alexandre Gramfort <alexandre.gramfort at inria.fr>
Date: Tue Apr 19 17:45:03 2011 -0400
ENH : source_induced_power and SourceEstimate + 3D source viewer
---
examples/plot_compute_mne_inverse.py | 5 +
.../plot_source_space_time_frequency.py | 4 +
mne/minimum_norm/time_frequency.py | 24 +++-
mne/stc.py | 9 +-
mne/viz.py | 130 ++++++++++++++-------
5 files changed, 115 insertions(+), 57 deletions(-)
diff --git a/examples/plot_compute_mne_inverse.py b/examples/plot_compute_mne_inverse.py
index 48f9be3..47b7eed 100755
--- a/examples/plot_compute_mne_inverse.py
+++ b/examples/plot_compute_mne_inverse.py
@@ -20,6 +20,8 @@ import mne
from mne.datasets import sample
from mne.fiff import Evoked
from mne.minimum_norm import apply_inverse, read_inverse_operator
+from mne.viz import plot_source_estimate
+
data_path = sample.data_path('.')
fname_inv = data_path + '/MEG/sample/sample_audvis-meg-oct-6-meg-inv.fif'
@@ -46,3 +48,6 @@ pl.plot(1e3 * stc.times, stc.data[::100, :].T)
pl.xlabel('time (ms)')
pl.ylabel('dSPM value')
pl.show()
+
+# View in 3D
+plot_source_estimate(inverse_operator['src'], stc)
diff --git a/examples/time_frequency/plot_source_space_time_frequency.py b/examples/time_frequency/plot_source_space_time_frequency.py
index 3e04be1..b3a3418 100644
--- a/examples/time_frequency/plot_source_space_time_frequency.py
+++ b/examples/time_frequency/plot_source_space_time_frequency.py
@@ -16,6 +16,7 @@ import mne
from mne import fiff
from mne.datasets import sample
from mne.minimum_norm import read_inverse_operator, source_induced_power
+from mne.viz import plot_source_estimate
###############################################################################
# Set parameters
@@ -51,3 +52,6 @@ stcs = source_induced_power(epochs, inverse_operator, bands, n_cycles=2,
for b, stc in stcs.iteritems():
stc.save('induced_power_%s' % b)
+
+# View sources
+plot_source_estimate(inverse_operator['src'], stcs['alpha'])
diff --git a/mne/minimum_norm/time_frequency.py b/mne/minimum_norm/time_frequency.py
index 9998bda..1392e5e 100644
--- a/mne/minimum_norm/time_frequency.py
+++ b/mne/minimum_norm/time_frequency.py
@@ -12,11 +12,27 @@ from .inverse import combine_xyz, prepare_inverse_operator
def source_induced_power(epochs, inverse_operator, bands, lambda2=1.0 / 9.0,
dSPM=True, n_cycles=5, df=1, use_fft=False,
- baseline=None, baseline_mode='ratio'):
- """XXX for source_induced_power
+ baseline=None, baseline_mode='logratio'):
+ """Compute source space induced power
Parameters
----------
+ epochs: instance of Epochs
+ The epochs
+ inverse_operator: instance of inverse operator
+ The inverse operator
+ bands: dict
+ Example : bands = dict(alpha=[8, 9])
+ lambda2: float
+ The regularization parameter of the minimum norm
+ dSPM: bool
+ Do dSPM or not?
+ n_cycles: int
+ Number of cycles
+ df: float
+ delta frequency within bands
+ use_fft: bool
+ Do convolutions in time or frequency domain with FFT
baseline: None (default) or tuple of length 2
The time interval to apply baseline correction.
If None do not apply it. If baseline is (a, b)
@@ -25,13 +41,11 @@ def source_induced_power(epochs, inverse_operator, bands, lambda2=1.0 / 9.0,
and if b is None then b is set to the end of the interval.
If baseline is equal ot (None, None) all the time
interval is used.
- baseline_mode : None | 'ratio' | 'zscore'
+ baseline_mode : None | 'logratio' | 'zscore'
Do baseline correction with ratio (power is divided by mean
power during baseline) or zscore (power is divided by standard
deviatio of power during baseline after substracting the mean,
power = [power - mean(power_baseline)] / std(power_baseline))
-
-
"""
#
diff --git a/mne/stc.py b/mne/stc.py
index e698418..13919d9 100755
--- a/mne/stc.py
+++ b/mne/stc.py
@@ -119,7 +119,7 @@ class SourceEstimate(object):
def __init__(self, fname):
if fname is not None:
lh = read_stc(fname + '-lh.stc')
- rh = read_stc(fname + '-lh.stc')
+ rh = read_stc(fname + '-rh.stc')
self.data = np.r_[lh['data'], rh['data']]
assert lh['tmin'] == rh['tmin']
assert lh['tstep'] == rh['tstep']
@@ -144,10 +144,3 @@ class SourceEstimate(object):
write_stc(fname + '-rh.stc', tmin=self.tmin, tstep=self.tstep,
vertices=self.rh_vertno, data=rh_data)
print '[done]'
-
- # def view(self, src, t, n_smooth=200, colorbar=True):
- # """View in source space
- # """
- # idx = np.where(evoked.times > 1e-3*t)[0][0]
- # plot_sources(src, self.data[:,idx], text='%d ms' % t,
- # colorbar=colorbar, n_smooth=n_smooth)
diff --git a/mne/viz.py b/mne/viz.py
index 01a2325..acb80b6 100755
--- a/mne/viz.py
+++ b/mne/viz.py
@@ -7,6 +7,7 @@
import numpy as np
import pylab as pl
+
from .fiff.pick import channel_type
@@ -78,49 +79,90 @@ def plot_evoked(evoked, picks=None, unit=True, show=True):
pl.show()
-def plot_sources(src, data, text=None, n_smooth=200, colorbar=True,
- cmap="jet"):
- """Source space data
+def plot_source_estimate(src, stc, n_smooth=200, cmap='jet'):
+ """Plot source estimates
"""
- from enthought.mayavi import mlab
from enthought.tvtk.api import tvtk
- lh_points = src[0]['rr']
- rh_points = src[1]['rr']
- # lh_faces = src[0]['tris']
- # rh_faces = src[1]['tris']
- lh_faces = src[0]['use_tris']
- rh_faces = src[1]['use_tris']
- points = np.r_[lh_points, rh_points]
- points *= 200
- faces = np.r_[lh_faces, lh_points.shape[0] + rh_faces]
-
- lh_idx = np.where(src[0]['inuse'])[0]
- rh_idx = np.where(src[1]['inuse'])[0]
- use_idx = np.r_[lh_idx, lh_points.shape[0] + rh_idx]
-
- points = points[use_idx]
- faces = np.searchsorted(use_idx, faces)
-
- mlab.test_quiver3d()
- mlab.clf()
- mlab.options.offscreen = True
- f = mlab.figure(512, bgcolor=(.05, 0, .1), size=(800, 800))
- mlab.clf()
- f.scene.disable_render = True
- surface_mesh = mlab.pipeline.triangular_mesh_source(points[:, 0],
- points[:, 1], points[:, 2], faces,
- scalars=data)
- smooth_ = tvtk.SmoothPolyDataFilter(number_of_iterations=n_smooth,
- relaxation_factor=0.18,
- feature_angle=70,
- feature_edge_smoothing=False,
- boundary_smoothing=False,
- convergence=0.)
- surface_mesh_smooth = mlab.pipeline.user_defined(surface_mesh,
- filter=smooth_)
- mlab.pipeline.surface(surface_mesh_smooth, colormap=cmap)
- bar = mlab.scalarbar()
- if text is not None:
- mlab.text(0.7, 0.9, text, width=0.2)
- if not colorbar:
- bar.visible = False
+ from enthought.traits.api import HasTraits, Range, Instance, \
+ on_trait_change
+ from enthought.traits.ui.api import View, Item, Group
+
+ from enthought.mayavi.core.api import PipelineBase
+ from enthought.mayavi.core.ui.api import MayaviScene, SceneEditor, \
+ MlabSceneModel
+
+ class SurfaceViewer(HasTraits):
+ n_times = Range(0, 100, 0, )
+
+ scene = Instance(MlabSceneModel, ())
+ surf = Instance(PipelineBase)
+ text = Instance(PipelineBase)
+
+ def __init__(self, src, data, times, n_smooth=20, cmap='jet'):
+ super(SurfaceViewer, self).__init__()
+ self.src = src
+ self.data = data
+ self.times = times
+ self.n_smooth = n_smooth
+ self.cmap = cmap
+
+ lh_points = src[0]['rr']
+ rh_points = src[1]['rr']
+ # lh_faces = src[0]['tris']
+ # rh_faces = src[1]['tris']
+ lh_faces = src[0]['use_tris']
+ rh_faces = src[1]['use_tris']
+ points = np.r_[lh_points, rh_points]
+ points *= 200
+ faces = np.r_[lh_faces, lh_points.shape[0] + rh_faces]
+
+ lh_idx = np.where(src[0]['inuse'])[0]
+ rh_idx = np.where(src[1]['inuse'])[0]
+ use_idx = np.r_[lh_idx, lh_points.shape[0] + rh_idx]
+
+ self.points = points[use_idx]
+ self.faces = np.searchsorted(use_idx, faces)
+
+ # When the scene is activated, or when the parameters are changed, we
+ # update the plot.
+ @on_trait_change('n_times,scene.activated')
+ def update_plot(self):
+ idx = int(self.n_times * len(self.times) / 100)
+ t = self.times[idx]
+ d = self.data[:, idx].astype(np.float) # 8bits for mayavi
+ points = self.points
+ faces = self.faces
+ info_time = "%d ms" % (1e3 * t)
+ if self.surf is None:
+ surface_mesh = self.scene.mlab.pipeline.triangular_mesh_source(
+ points[:, 0], points[:, 1], points[:, 2],
+ faces, scalars=d)
+ smooth_ = tvtk.SmoothPolyDataFilter(
+ number_of_iterations=self.n_smooth,
+ relaxation_factor=0.18,
+ feature_angle=70,
+ feature_edge_smoothing=False,
+ boundary_smoothing=False,
+ convergence=0.)
+ surface_mesh_smooth = self.scene.mlab.pipeline.user_defined(
+ surface_mesh, filter=smooth_)
+ self.surf = self.scene.mlab.pipeline.surface(
+ surface_mesh_smooth, colormap=self.cmap)
+
+ self.scene.mlab.colorbar()
+ self.text = self.scene.mlab.text(0.7, 0.9, info_time,
+ width=0.2)
+ self.scene.background = (.05, 0, .1)
+ else:
+ self.surf.mlab_source.set(scalars=d)
+ self.text.set(text=info_time)
+
+ # The layout of the dialog created
+ view = View(Item('scene', editor=SceneEditor(scene_class=MayaviScene),
+ height=800, width=800, show_label=False),
+ Group('_', 'n_times',),
+ resizable=True,)
+
+ viewer = SurfaceViewer(src, stc.data, stc.times, n_smooth=200)
+ viewer.configure_traits()
+ return viewer
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/debian-med/python-mne.git
More information about the debian-med-commit
mailing list