Пример #1
0
def test_graceful_close_after_invalid(capsys):

    # Regression test for a bug that caused an error if an invalid dataset
    # was added to the viewer after the user had acknowledged the error.

    d = Data(a=[[1, 2], [3, 4]], label='test')

    dc = DataCollection([d])

    gapp = GlueApplication(dc)

    viewer = gapp.new_data_viewer(TableViewer)
    gapp.show()

    process_events()

    with pytest.raises(ValueError,
                       match='Can only use Table widget for 1D data'):
        viewer.add_data(d)

    viewer.close()

    process_events()

    #  We use capsys here because the # error is otherwise only apparent in stderr.
    out, err = capsys.readouterr()
    assert out.strip() == ""
    assert err.strip() == ""
Пример #2
0
def test_reset(tmpdir, capsys):

    app = GlueApplication()
    viewer = app.new_data_viewer(VispyScatterViewer)
    data = Data(x=[1, 2, 3], label='Data')
    app.data_collection.append(data)
    app.show()
    viewer.add_data(data)

    assert viewer.state.x_min == 1.
    assert viewer.state.y_min == 1.
    assert viewer.state.z_min == 1.

    assert viewer.state.x_max == 3.
    assert viewer.state.y_max == 3.
    assert viewer.state.z_max == 3.

    viewer.state.x_min = 2
    viewer.state.y_min = 3
    viewer.state.z_min = 5

    viewer.state.x_max = 6
    viewer.state.y_max = 7
    viewer.state.z_max = 8

    viewer.toolbar.actions['vispy:reset'].trigger()

    assert viewer.state.x_min == 1.
    assert viewer.state.y_min == 1.
    assert viewer.state.z_min == 1.

    assert viewer.state.x_max == 3.
    assert viewer.state.y_max == 3.
    assert viewer.state.z_max == 3.

    out, err = capsys.readouterr()
    assert out.strip() == ""
    assert err.strip() == ""

    app.close()
Пример #3
0
def test_save(tmpdir, capsys):

    app = GlueApplication()
    viewer = app.new_data_viewer(VispyScatterViewer)
    data = Data(x=[1, 2, 3], label='Data')
    app.data_collection.append(data)
    app.show()
    viewer.add_data(data)

    filename = tmpdir.join('test.png').strpath

    with patch('qtpy.compat.getsavefilename') as fd:
        fd.return_value = filename, 'png'
        viewer.toolbar.tools['save'].subtools[0].activate()

    assert os.path.exists(filename)

    out, err = capsys.readouterr()
    assert out.strip() == ""
    assert err.strip() == ""

    app.close()
Пример #4
0
def test_incompatible_subset():

    # Regression test for a bug that caused the table to be refreshed in an
    # infinite loop if incompatible subsets were present.

    data1 = Data(a=[1, 2, 3, 4, 5], label='test1')
    data2 = Data(a=[1, 2, 3, 4, 5], label='test2')
    dc = DataCollection([data1, data2])

    gapp = GlueApplication(dc)

    viewer = gapp.new_data_viewer(TableViewer)
    viewer.add_data(data1)

    dc.new_subset_group('test subset', data2.id['a'] > 2)
    gapp.show()
    process_events(0.5)

    with patch.object(viewer.layers[0], '_refresh') as refresh1:
        with patch.object(viewer.layers[1], '_refresh') as refresh2:
            process_events(0.5)

    assert refresh1.call_count == 0
    assert refresh2.call_count == 0
Пример #5
0
def test_foreground_background_settings():

    d_1d = Data(x=np.random.random(100),
                y=np.random.random(100),
                label='Data 1d')
    d_2d = Data(x=np.random.random((100, 100)),
                y=np.random.random((100, 100)),
                label='Data 2d')

    dc = DataCollection([d_1d, d_2d])

    app = GlueApplication(dc)

    # Make sure that settings change existing viewers, so we create a bunch of
    # viewers here.

    scatter1 = app.new_data_viewer(ScatterViewer)
    scatter1.add_data(d_1d)

    image1 = app.new_data_viewer(ImageViewer)
    image1.add_data(d_2d)

    histogram1 = app.new_data_viewer(HistogramViewer)
    histogram1.add_data(d_1d)

    dendrogram1 = app.new_data_viewer(DendroWidget)

    example_custom = _generate_custom_viewer()

    custom1 = app.new_data_viewer(example_custom)

    RED = (1, 0, 0, 0.5)
    GREEN = (0, 1, 0, 0.6)

    app.show()

    with patch('glue.config.settings') as settings:

        settings.FOREGROUND_COLOR = 'black'
        settings.BACKGROUND_COLOR = 'white'
        settings.DATA_COLOR = '0.5'
        settings.DATA_ALPHA = 0.5

        dialog = PreferencesDialog(app)
        dialog.show()
        dialog.background = RED
        dialog.foreground = GREEN
        dialog.accept()

        assert_axes_background(scatter1.axes, RED)
        assert_axes_background(image1.axes, RED)
        assert_axes_background(histogram1.axes, RED)
        assert_axes_background(dendrogram1.axes, RED)
        assert_axes_background(custom1.axes, RED)

        assert_axes_foreground(scatter1.axes, GREEN)
        assert_axes_foreground(image1.axes, GREEN)
        assert_axes_foreground(histogram1.axes, GREEN)
        assert_axes_foreground(dendrogram1.axes, GREEN)
        assert_axes_foreground(custom1.axes, GREEN)

        # Now make sure that new viewers also inherit these settings

        scatter2 = app.new_data_viewer(ScatterViewer)
        scatter2.add_data(d_1d)

        image2 = app.new_data_viewer(ImageViewer)
        image2.add_data(d_2d)

        histogram2 = app.new_data_viewer(HistogramViewer)
        histogram2.add_data(d_1d)

        dendrogram2 = app.new_data_viewer(DendroWidget)
        custom2 = app.new_data_viewer(example_custom)

        assert_axes_background(scatter2.axes, RED)
        assert_axes_background(image2.axes, RED)
        assert_axes_background(histogram2.axes, RED)
        assert_axes_background(dendrogram2.axes, RED)
        assert_axes_background(custom2.axes, RED)

        assert_axes_foreground(scatter2.axes, GREEN)
        assert_axes_foreground(image2.axes, GREEN)
        assert_axes_foreground(histogram2.axes, GREEN)
        assert_axes_foreground(dendrogram2.axes, GREEN)
        assert_axes_foreground(custom2.axes, GREEN)
Пример #6
0
def test_foreground_background_settings():

    d_1d = Data(x=np.random.random(100), y=np.random.random(100), label='Data 1d')
    d_2d = Data(x=np.random.random((100, 100)), y=np.random.random((100, 100)), label='Data 2d')

    dc = DataCollection([d_1d, d_2d])

    app = GlueApplication(dc)

    # Make sure that settings change existing viewers, so we create a bunch of
    # viewers here.

    scatter1 = app.new_data_viewer(ScatterWidget)
    scatter1.add_data(d_1d)

    image1 = app.new_data_viewer(ImageWidget)
    image1.add_data(d_2d)

    histogram1 = app.new_data_viewer(HistogramWidget)
    histogram1.add_data(d_1d)

    dendrogram1 = app.new_data_viewer(DendroWidget)

    example_custom = _generate_custom_viewer()

    custom1 = app.new_data_viewer(example_custom)

    RED = (1, 0, 0, 0.5)
    GREEN = (0, 1, 0, 0.6)

    app.show()

    with patch('glue.config.settings') as settings:

        settings.FOREGROUND_COLOR = 'black'
        settings.BACKGROUND_COLOR = 'white'
        settings.DATA_COLOR = '0.5'
        settings.DATA_ALPHA = 0.5

        dialog = PreferencesDialog(app)
        dialog.show()
        dialog.background = RED
        dialog.foreground = GREEN
        dialog.accept()

        assert_axes_background(scatter1.axes, RED)
        assert_axes_background(image1.axes, RED)
        assert_axes_background(histogram1.axes, RED)
        assert_axes_background(dendrogram1.axes, RED)
        assert_axes_background(custom1.axes, RED)

        assert_axes_foreground(scatter1.axes, GREEN)
        assert_axes_foreground(image1.axes, GREEN)
        assert_axes_foreground(histogram1.axes, GREEN)
        assert_axes_foreground(dendrogram1.axes, GREEN)
        assert_axes_foreground(custom1.axes, GREEN)

        # Now make sure that new viewers also inherit these settings

        scatter2 = app.new_data_viewer(ScatterWidget)
        scatter2.add_data(d_1d)

        image2 = app.new_data_viewer(ImageWidget)
        image2.add_data(d_2d)

        histogram2 = app.new_data_viewer(HistogramWidget)
        histogram2.add_data(d_1d)

        dendrogram2 = app.new_data_viewer(DendroWidget)
        custom2 = app.new_data_viewer(example_custom)

        assert_axes_background(scatter2.axes, RED)
        assert_axes_background(image2.axes, RED)
        assert_axes_background(histogram2.axes, RED)
        assert_axes_background(dendrogram2.axes, RED)
        assert_axes_background(custom2.axes, RED)

        assert_axes_foreground(scatter2.axes, GREEN)
        assert_axes_foreground(image2.axes, GREEN)
        assert_axes_foreground(histogram2.axes, GREEN)
        assert_axes_foreground(dendrogram2.axes, GREEN)
        assert_axes_foreground(custom2.axes, GREEN)
Пример #7
0
# This is a script that can be used to reproduce the screenshots for the
# Getting Started guide. The idea is that as we update glue, we can easily
# regenerate screenshots to make sure we include the latest ui.

from glue.app.qt import GlueApplication
from glue.viewers.image.qt import ImageViewer
from glue.viewers.histogram.qt import HistogramViewer
from glue.viewers.scatter.qt import ScatterViewer
from glue.core.edit_subset_mode import AndNotMode, ReplaceMode
from glue.core.link_helpers import LinkSame

ga = GlueApplication()
ga.resize(1230, 900)
ga.show()

ga.app.processEvents()
ga.screenshot('main_window1.png')

image = ga.load_data('w5.fits')
image.label = 'W5'

ga.app.processEvents()
ga.screenshot('data_open.png')

image_viewer = ga.new_data_viewer(ImageViewer, data=image)
image_viewer._mdi_wrapper.resize(450, 400)

image_viewer.state.layers[0].v_min = 440
image_viewer.state.layers[0].v_max = 900
image_viewer.state.layers[0].stretch = 'sqrt'
image_viewer.state.reset_limits()
Пример #8
0
# This is a script that can be used to reproduce the screenshots for the
# Getting Started guide. The idea is that as we update glue, we can easily
# regenerate screenshots to make sure we include the latest ui.

from glue.app.qt import GlueApplication
from glue.viewers.image.qt import ImageViewer
from glue.viewers.histogram.qt import HistogramViewer
from glue.viewers.scatter.qt import ScatterViewer
from glue.core.edit_subset_mode import AndNotMode, ReplaceMode
from glue.core.link_helpers import LinkSame

ga = GlueApplication()
ga.resize(1230, 900)
ga.show()

ga.app.processEvents()
ga.screenshot('main_window1.png')

image = ga.load_data('w5.fits')
image.label = 'W5'

ga.app.processEvents()
ga.screenshot('data_open.png')

image_viewer = ga.new_data_viewer(ImageViewer, data=image)
image_viewer._mdi_wrapper.resize(450, 400)

image_viewer.state.layers[0].v_min = 440
image_viewer.state.layers[0].v_max = 900
image_viewer.state.layers[0].stretch = 'sqrt'
image_viewer.state.reset_limits()