Beispiel #1
0
 def plot(self):
     err = self.plot_solution()
     self.plot_weights()
     mlab.process_ui_events()
     if sys.platform.startswith('linux'):
         self.plt1.scene._lift()
     return err
Beispiel #2
0
def anim():
    x,y = np.mgrid[0:3:1,0:3:1]
    s = mlab.surf(x,y,x*0.01,representation='wireframe')
    fig = mlab.gcf()
    while True:
        for i in range(5):
            s1 = slice(0,3,1/(i+2))
            x,y = np.mgrid[s1,s1]
            sc = x*x*0.05*(i+1)
            s.mlab_source.reset(x=x,y=y,scalars = sc)
            fig.scene.reset_zoom()
            mlab.process_ui_events()
            time.sleep(0.02)
            yield
Beispiel #3
0
def plot(x, y, z, nx, ny):
    from mayavi import mlab
    mlab.figure(size=(600, 600))
    xmin, xmax = np.min(x.data), np.max(x.data)
    ymin, ymax = np.min(y.data), np.max(y.data)
    s = mlab.imshow(z.data.reshape((nx, ny)),
                    extent=[xmin, xmax, ymin, ymax, 0, 0],
                    colormap='jet')
    s.scene.z_plus_view()
    n = 2000
    dt = 4 * np.pi / n
    for i in range(n):
        julia(z, x, y, -dt * i)
        z.pull()
        s.mlab_source.scalars = z.data.reshape((nx, ny))
        if i % 3 == 0:
            mlab.process_ui_events()
    mlab.show()
Beispiel #4
0
def test_coreg_gui_display(tmpdir):
    """Test CoregFrame."""
    _check_ci()
    from mayavi import mlab
    from tvtk.api import tvtk
    home_dir = str(tmpdir)
    with modified_env(**{'_MNE_GUI_TESTING_MODE': 'true',
                         '_MNE_FAKE_HOME_DIR': home_dir}):
        with pytest.raises(ValueError, match='not a valid subject'):
            mne.gui.coregistration(subject='Elvis', subjects_dir=subjects_dir)

        # avoid modal dialog if SUBJECTS_DIR is set to a directory that
        # does not contain valid subjects
        ui, frame = mne.gui.coregistration(subjects_dir='')
        mlab.process_ui_events()
        ui.dispose()
        mlab.process_ui_events()

        ui, frame = mne.gui.coregistration(subjects_dir=subjects_dir,
                                           subject='sample')
        mlab.process_ui_events()

        assert not frame.model.mri.fid_ok
        frame.model.mri.lpa = [[-0.06, 0, 0]]
        frame.model.mri.nasion = [[0, 0.05, 0]]
        frame.model.mri.rpa = [[0.08, 0, 0]]
        assert (frame.model.mri.fid_ok)
        frame.data_panel.raw_src.file = raw_path
        assert isinstance(frame.eeg_obj.glyph.glyph.glyph_source.glyph_source,
                          tvtk.SphereSource)
        frame.data_panel.view_options_panel.eeg_obj.project_to_surface = True
        assert isinstance(frame.eeg_obj.glyph.glyph.glyph_source.glyph_source,
                          tvtk.CylinderSource)
        mlab.process_ui_events()

        # grow hair (faster for low-res)
        assert frame.data_panel.view_options_panel.head_high_res
        frame.data_panel.view_options_panel.head_high_res = False
        frame.model.grow_hair = 40.

        # scale
        frame.coreg_panel.n_scale_params = 3
        frame.coreg_panel.scale_x_inc = True
        assert frame.model.scale_x == 101.
        frame.coreg_panel.scale_y_dec = True
        assert frame.model.scale_y == 99.

        # reset parameters
        frame.coreg_panel.reset_params = True
        assert_equal(frame.model.grow_hair, 0)
        assert not frame.data_panel.view_options_panel.head_high_res

        # configuration persistence
        assert (frame.model.prepare_bem_model)
        frame.model.prepare_bem_model = False
        frame.save_config(home_dir)
        ui.dispose()
        mlab.process_ui_events()

        ui, frame = mne.gui.coregistration(subjects_dir=subjects_dir)
        assert not frame.model.prepare_bem_model
        assert not frame.data_panel.view_options_panel.head_high_res
        ui.dispose()
        mlab.process_ui_events()
Beispiel #5
0
def test_coreg_gui_display(tmpdir):
    """Test CoregFrame."""
    _check_ci()
    from mayavi import mlab
    from tvtk.api import tvtk
    home_dir = str(tmpdir)
    with modified_env(**{
            '_MNE_GUI_TESTING_MODE': 'true',
            '_MNE_FAKE_HOME_DIR': home_dir
    }):
        with pytest.raises(ValueError, match='not a valid subject'):
            mne.gui.coregistration(subject='Elvis', subjects_dir=subjects_dir)

        # avoid modal dialog if SUBJECTS_DIR is set to a directory that
        # does not contain valid subjects
        ui, frame = mne.gui.coregistration(subjects_dir='')
        mlab.process_ui_events()
        ui.dispose()
        mlab.process_ui_events()

        ui, frame = mne.gui.coregistration(subjects_dir=subjects_dir,
                                           subject='sample')
        mlab.process_ui_events()

        assert not frame.model.mri.fid_ok
        frame.model.mri.lpa = [[-0.06, 0, 0]]
        frame.model.mri.nasion = [[0, 0.05, 0]]
        frame.model.mri.rpa = [[0.08, 0, 0]]
        assert (frame.model.mri.fid_ok)
        frame.data_panel.raw_src.file = raw_path
        assert isinstance(frame.eeg_obj.glyph.glyph.glyph_source.glyph_source,
                          tvtk.SphereSource)
        frame.data_panel.view_options_panel.eeg_obj.project_to_surface = True
        assert isinstance(frame.eeg_obj.glyph.glyph.glyph_source.glyph_source,
                          tvtk.CylinderSource)
        mlab.process_ui_events()

        # grow hair (faster for low-res)
        assert frame.data_panel.view_options_panel.head_high_res
        frame.data_panel.view_options_panel.head_high_res = False
        frame.model.grow_hair = 40.

        # scale
        frame.coreg_panel.n_scale_params = 3
        frame.coreg_panel.scale_x_inc = True
        assert frame.model.scale_x == 101.
        frame.coreg_panel.scale_y_dec = True
        assert frame.model.scale_y == 99.

        # reset parameters
        frame.coreg_panel.reset_params = True
        assert_equal(frame.model.grow_hair, 0)
        assert not frame.data_panel.view_options_panel.head_high_res

        # configuration persistence
        assert (frame.model.prepare_bem_model)
        frame.model.prepare_bem_model = False
        frame.save_config(home_dir)
        ui.dispose()
        mlab.process_ui_events()

        ui, frame = mne.gui.coregistration(subjects_dir=subjects_dir)
        assert not frame.model.prepare_bem_model
        assert not frame.data_panel.view_options_panel.head_high_res
        ui.dispose()
        mlab.process_ui_events()
def test_coreg_gui_display(subjects_dir_tmp, check_gui_ci):
    """Test CoregFrame."""
    from mayavi import mlab
    from tvtk.api import tvtk
    home_dir = subjects_dir_tmp
    # Remove the two files that will make the fiducials okay via MNI estimation
    os.remove(
        op.join(subjects_dir_tmp, 'sample', 'bem', 'sample-fiducials.fif'))
    os.remove(
        op.join(subjects_dir_tmp, 'sample', 'mri', 'transforms',
                'talairach.xfm'))
    with modified_env(_MNE_GUI_TESTING_MODE='true',
                      _MNE_FAKE_HOME_DIR=home_dir):
        with pytest.raises(ValueError, match='not a valid subject'):
            mne.gui.coregistration(subject='Elvis',
                                   subjects_dir=subjects_dir_tmp)

        # avoid modal dialog if SUBJECTS_DIR is set to a directory that
        # does not contain valid subjects
        ui, frame = mne.gui.coregistration(subjects_dir='')
        mlab.process_ui_events()
        ui.dispose()
        mlab.process_ui_events()

        ui, frame = mne.gui.coregistration(subjects_dir=subjects_dir_tmp,
                                           subject='sample')
        mlab.process_ui_events()

        assert not frame.model.mri.fid_ok
        frame.model.mri.lpa = [[-0.06, 0, 0]]
        frame.model.mri.nasion = [[0, 0.05, 0]]
        frame.model.mri.rpa = [[0.08, 0, 0]]
        assert frame.model.mri.fid_ok
        frame.data_panel.raw_src.file = raw_path
        assert isinstance(frame.eeg_obj.glyph.glyph.glyph_source.glyph_source,
                          tvtk.SphereSource)
        frame.data_panel.view_options_panel.eeg_obj.project_to_surface = True
        assert isinstance(frame.eeg_obj.glyph.glyph.glyph_source.glyph_source,
                          tvtk.CylinderSource)
        mlab.process_ui_events()

        # grow hair (faster for low-res)
        assert frame.data_panel.view_options_panel.head_high_res
        frame.data_panel.view_options_panel.head_high_res = False
        frame.model.grow_hair = 40.

        # scale
        frame.coreg_panel.n_scale_params = 3
        frame.coreg_panel.scale_x_inc = True
        assert frame.model.scale_x == 101.
        frame.coreg_panel.scale_y_dec = True
        assert frame.model.scale_y == 99.

        # reset parameters
        frame.coreg_panel.reset_params = True
        assert frame.model.grow_hair == 0
        assert not frame.data_panel.view_options_panel.head_high_res

        # configuration persistence
        assert (frame.model.prepare_bem_model)
        frame.model.prepare_bem_model = False
        frame.save_config(home_dir)
        ui.dispose()
        mlab.process_ui_events()

        ui, frame = mne.gui.coregistration(subjects_dir=subjects_dir_tmp)
        assert not frame.model.prepare_bem_model
        assert not frame.data_panel.view_options_panel.head_high_res
        ui.dispose()
        mlab.process_ui_events()
Beispiel #7
0
import numpy as np
from mayavi import mlab
import time
x, y = np.mgrid[-3:3:100j,-3:3:100j]
z = np.sin(x*x + y*y)
s = mlab.surf(x, y, z)
for i in range(25):
    s.mlab_source.scalars = np.sin((x*x + y*y) + 8*np.pi*i/25)
    mlab.process_ui_events()
    mlab.savefig('/tmp/anim_%03d.png')
    time.sleep(0.05)