Example #1
0
    def _load_data(self):
        """ Interactively loads data from a data set. Adds
        as new layer """
        from glue.app.qt import GlueApplication

        layers = data_wizard()
        GlueApplication.add_datasets(self.data_collection, layers)
Example #2
0
 def setup_method(self, method):
     self.gapp = GlueApplication()
     self.viewer = self.gapp.new_data_viewer(TableViewer)
     self.data = Data(x=[1, 2, 3, 4], y=[2, 3, 4, 5])
     self.gapp.data_collection.append(self.data)
     self.viewer.add_data(self.data)
     self.model = DataTableModel(self.viewer)
Example #3
0
    def _load_data(self):
        """ Interactively loads data from a data set. Adds
        as new layer """
        from glue.app.qt import GlueApplication

        layers = data_wizard()
        GlueApplication.add_datasets(self.data_collection, layers)
Example #4
0
    def setup_method(self, method):

        # Set up simple spectral WCS
        wcs_1d = WCS(naxis=1)
        wcs_1d.wcs.ctype = ['VELO-LSR']
        wcs_1d.wcs.set()

        # Set up a spectral cube WCS
        wcs_3d = WCS(naxis=3)
        wcs_3d.wcs.ctype = ['RA---TAN', 'DEC--TAN', 'VELO-LSR']
        wcs_3d.wcs.set()

        # Set up glue Coordinates object
        coords_1d = WCSCoordinates(wcs=wcs_1d)
        coords_3d = WCSCoordinates(wcs=wcs_3d)

        self.data_1d = Data(label='spectrum', coords=coords_1d)
        self.data_3d = Data(label='spectrum', coords=coords_3d)

        # FIXME: there should be an easier way to do this in glue
        x = np.array([3.4, 2.3, -1.1, 0.3])
        y = np.array([3.2, 3.3, 3.4, 3.5])
        self.data_1d.add_component(Component(x, units='Jy'), 'x')
        self.data_1d.add_component(Component(y, units='Jy'), 'y')
        self.data_3d.add_component(Component(np.broadcast_to(x, (6, 5, 4)), units='Jy'), 'x')
        self.data_3d.add_component(Component(np.broadcast_to(x, (6, 5, 4))), 'y')

        self.app = GlueApplication()
        self.session = self.app.session
        self.hub = self.session.hub

        self.data_collection = self.session.data_collection
        self.data_collection.append(self.data_1d)
        self.data_collection.append(self.data_3d)
Example #5
0
class TestScatter3D:

    def setup_method(self, method):
        self.data = Data(x=[1, 2, 3], y=[4, 5, 6], z=[7, 8, 9], label='d1')
        self.app = GlueApplication()
        self.app.session.data_collection.append(self.data)
        self.viewer = self.app.new_data_viewer(VispyScatterViewer)
        self.viewer.add_data(self.data)
        for subtool in self.viewer.toolbar.tools['save'].subtools:
            if subtool.tool_id == 'save:plotly3d':
                self.tool = subtool
                break
        else:
            raise Exception("Could not find save:plotly2d tool in viewer")

    def teardown_method(self, method):
        self.viewer.close(warn=False)
        self.viewer = None
        self.app.close()
        self.app = None

    def test_default(self, tmpdir):
        output_file = tmpdir.join('test.html').strpath
        with patch('qtpy.compat.getsavefilename') as fd:
            fd.return_value = output_file, 'html'
            with patch.object(SaveHoverDialog, 'exec_', auto_accept()):
                self.tool.activate()
        assert os.path.exists(output_file)
Example #6
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() == ""
Example #7
0
def test_table_widget_session_no_subset(tmpdir):

    # Regression test for a bug that caused table viewers with no subsets to
    # not be restored correctly and instead raise an exception.

    app = get_qapp()  # noqa

    d = Data(a=[1, 2, 3, 4, 5],
             b=[3.2, 1.2, 4.5, 3.3, 2.2],
             c=['e', 'b', 'c', 'a', 'f'], label='test')

    dc = DataCollection([d])

    gapp = GlueApplication(dc)

    widget = gapp.new_data_viewer(TableViewer)
    widget.add_data(d)

    session_file = tmpdir.join('table.glu').strpath

    gapp.save_session(session_file)

    gapp2 = GlueApplication.restore_session(session_file)
    gapp2.show()

    gapp2.data_collection[0]
    gapp2.viewers[0][0]
Example #8
0
    def setup_method(self, method):

        self.coords = MyCoords()
        self.image1 = Data(label='image1', x=[[1, 2], [3, 4]], y=[[4, 5], [2, 3]])
        self.image2 = Data(label='image2', a=[[3, 3], [2, 2]], b=[[4, 4], [3, 2]],
                           coords=self.coords)
        self.catalog = Data(label='catalog', c=[1, 3, 2], d=[4, 3, 3])
        self.hypercube = Data(label='hypercube', x=np.arange(120).reshape((2, 3, 4, 5)))

        # Create data versions with WCS coordinates
        self.image1_wcs = Data(label='image1_wcs', x=self.image1['x'],
                               coords=WCSCoordinates(wcs=WCS(naxis=2)))
        self.hypercube_wcs = Data(label='hypercube_wcs', x=self.hypercube['x'],
                                  coords=WCSCoordinates(wcs=WCS(naxis=4)))

        self.application = GlueApplication()

        self.session = self.application.session

        self.hub = self.session.hub

        self.data_collection = self.session.data_collection
        self.data_collection.append(self.image1)
        self.data_collection.append(self.image2)
        self.data_collection.append(self.catalog)
        self.data_collection.append(self.hypercube)
        self.data_collection.append(self.image1_wcs)
        self.data_collection.append(self.hypercube_wcs)

        self.viewer = self.application.new_data_viewer(ImageViewer)

        self.data_collection.register_to_hub(self.hub)
        self.viewer.register_to_hub(self.hub)

        self.options_widget = self.viewer.options_widget()
Example #9
0
def qglue(**kwargs):
    """
    Quickly send python variables to Glue for visualization.

    The generic calling sequence is::

      qglue(label1=data1, label2=data2, ..., [links=links])

    The kewyords label1, label2, ... can be named anything besides ``links``

    data1, data2, ... can be in many formats:
      * A pandas data frame
      * A path to a file
      * A numpy array, or python list
      * A numpy rec array
      * A dictionary of numpy arrays with the same shape
      * An astropy Table

    ``Links`` is an optional list of link descriptions, each of which has
    the format: ([left_ids], [right_ids], forward, backward)

    Each ``left_id``/``right_id`` is a string naming a component in a dataset
    (i.e., ``data1.x``). ``forward`` and ``backward`` are functions which
    map quantities on the left to quantities on the right, and vice
    versa. `backward` is optional

    Examples::

        balls = {'kg': [1, 2, 3], 'radius_cm': [10, 15, 30]}
        cones = {'lbs': [5, 3, 3, 1]}
        def lb2kg(lb):
            return lb / 2.2
        def kg2lb(kg):
            return kg * 2.2

        links = [(['balls.kg'], ['cones.lbs'], lb2kg, kg2lb)]
        qglue(balls=balls, cones=cones, links=links)

    :returns: A :class:`~glue.app.qt.application.GlueApplication` object
    """
    from glue.core import DataCollection
    from glue.app.qt import GlueApplication
    from glue.dialogs.autolinker.qt import run_autolinker

    links = kwargs.pop('links', None)

    dc = DataCollection()
    for label, data in kwargs.items():
        dc.extend(parse_data(data, label))

    if links is not None:
        dc.add_link(parse_links(dc, links))

    with restore_io():
        ga = GlueApplication(dc)
        run_autolinker(dc)
        ga.start()

    return ga
Example #10
0
def test_state_save_with_data_layers():
    app = GlueApplication()
    dc = app.data_collection
    d = Data(x=[1, 2, 3], label='test')
    dc.append(d)
    w = app.new_data_viewer(viewer._widget_cls)
    w.add_data(d)
    check_clone_app(app)
Example #11
0
def _create_glue_app(data_collection, hub):
    session = glue.core.Session(data_collection=data_collection, hub=hub)
    ga = GlueApplication(session=session)
    ga.setWindowTitle('cubeviz ({})'.format(cubeviz_version))
    qapp = QtWidgets.QApplication.instance()
    qapp.setWindowIcon(QtGui.QIcon(CUBEVIZ_ICON_PATH))
    ga.setWindowIcon(QtGui.QIcon(CUBEVIZ_ICON_PATH))
    return ga
Example #12
0
def test_state_save_with_data_layers():
    app = GlueApplication()
    dc = app.data_collection
    d = Data(x=[1, 2, 3], label='test')
    dc.append(d)
    w = app.new_data_viewer(viewer._widget_cls)
    w.add_data(d)
    check_clone_app(app)
Example #13
0
def _create_glue_app(data_collection, hub):
    session = glue.core.Session(data_collection=data_collection, hub=hub)
    ga = GlueApplication(session=session)
    qapp = QtWidgets.QApplication.instance()
    ga.setWindowTitle('MOSViz v{0}'.format(__version__))
    qapp.setWindowIcon(QtGui.QIcon(MOSVIZ_ICON_PATH))
    ga.setWindowIcon(QtGui.QIcon(MOSVIZ_ICON_PATH))
    return ga
 def setup_method(self, method):
     self.d = Data(x=[1, 2, 3], y=[2, 3, 4], z=[4, 5, 6])
     self.application = GlueApplication()
     self.dc = self.application.data_collection
     self.dc.append(self.d)
     self.hub = self.dc.hub
     self.session = self.application.session
     self.viewer = self.application.new_data_viewer(WWTDataViewer)
     self.options = self.viewer.options_widget()
Example #15
0
def qglue(**kwargs):
    """
    Quickly send python variables to Glue for visualization.

    The generic calling sequence is::

      qglue(label1=data1, label2=data2, ..., [links=links])

    The kewyords label1, label2, ... can be named anything besides ``links``

    data1, data2, ... can be in many formats:
      * A pandas data frame
      * A path to a file
      * A numpy array, or python list
      * A numpy rec array
      * A dictionary of numpy arrays with the same shape
      * An astropy Table

    ``Links`` is an optional list of link descriptions, each of which has
    the format: ([left_ids], [right_ids], forward, backward)

    Each ``left_id``/``right_id`` is a string naming a component in a dataset
    (i.e., ``data1.x``). ``forward`` and ``backward`` are functions which
    map quantities on the left to quantities on the right, and vice
    versa. `backward` is optional

    Examples::

        balls = {'kg': [1, 2, 3], 'radius_cm': [10, 15, 30]}
        cones = {'lbs': [5, 3, 3, 1]}
        def lb2kg(lb):
            return lb / 2.2
        def kg2lb(kg):
            return kg * 2.2

        links = [(['balls.kg'], ['cones.lbs'], lb2kg, kg2lb)]
        qglue(balls=balls, cones=cones, links=links)

    :returns: A :class:`~glue.app.qt.application.GlueApplication` object
    """
    from glue.core import DataCollection
    from glue.app.qt import GlueApplication

    links = kwargs.pop('links', None)

    dc = DataCollection()
    for label, data in kwargs.items():
        dc.extend(parse_data(data, label))

    if links is not None:
        dc.add_link(parse_links(dc, links))

    with restore_io():
        ga = GlueApplication(dc)
        ga.start()

    return ga
Example #16
0
 def test_save_load(self):
     app = GlueApplication(session=self.session)
     w = app.new_data_viewer(self.viewer._viewer_cls)
     v = w._coordinator
     roi = None
     s = CustomSubsetState(v, roi)
     app.data_collection.new_subset_group(subset_state=s, label='test')
     app2 = clone(app)
     s2 = app2.data_collection[0].subsets[0].subset_state
     assert_array_equal(s2.to_mask(self.data), [False, True, True])
Example #17
0
 def test_save_load(self):
     app = GlueApplication(session=self.session)
     w = app.new_data_viewer(self.viewer._viewer_cls)
     v = w._coordinator
     roi = None
     s = CustomSubsetState(v, roi)
     app.data_collection.new_subset_group(subset_state=s, label='test')
     app2 = clone(app)
     s2 = app2.data_collection[0].subsets[0].subset_state
     assert_array_equal(s2.to_mask(self.data), [False, True, True])
Example #18
0
    def test_cube(self):
        d = core.Data(label='cube', x=np.zeros((2, 2, 2)))
        dc = core.DataCollection([d])
        app = GlueApplication(dc)
        w = app.new_data_viewer(ImageWidget, d)
        w.slice = ('x', 'y', 1)
        assert w.slice == ('x', 'y', 1)

        c = self.check_clone(app)
        w2 = c.viewers[0][0]
        assert w2.ui.slice.slice == w.slice
Example #19
0
    def setup_method(self, method):

        self.data = Data(label='d1', x=[3.4, 2.3, -1.1, 0.3], y=['a', 'b', 'c', 'a'])

        self.app = GlueApplication()
        self.session = self.app.session
        self.hub = self.session.hub

        self.data_collection = self.session.data_collection
        self.data_collection.append(self.data)

        self.viewer = self.app.new_data_viewer(HistogramViewer)
Example #20
0
 def setup_method(self, method):
     self.data = Data(x=[1, 2, 3], y=[4, 5, 6], z=[7, 8, 9], label='d1')
     self.app = GlueApplication()
     self.app.session.data_collection.append(self.data)
     self.viewer = self.app.new_data_viewer(VispyScatterViewer)
     self.viewer.add_data(self.data)
     for subtool in self.viewer.toolbar.tools['save'].subtools:
         if subtool.tool_id == 'save:plotly3d':
             self.tool = subtool
             break
     else:
         raise Exception("Could not find save:plotly2d tool in viewer")
Example #21
0
    def test_cube(self):
        d = core.Data(label='cube',
                      x=np.zeros((2, 2, 2)))
        dc = core.DataCollection([d])
        app = GlueApplication(dc)
        w = app.new_data_viewer(ImageWidget, d)
        w.slice = ('x', 'y', 1)
        assert w.slice == ('x', 'y', 1)

        c = self.check_clone(app)
        w2 = c.viewers[0][0]
        assert w2.ui.slice.slice == w.slice
Example #22
0
def start_glue(gluefile=None, config=None, datafiles=None, maximized=True):
    """Run a glue session and exit

    Parameters
    ----------
    gluefile : str
        An optional ``.glu`` file to restore.

    config : str
        An optional configuration file to use.

    datafiles : str
        An optional list of data files to load.

    maximized : bool
        Maximize screen on startup. Otherwise, use default size.

    """
    import glue
    from glue.app.qt import GlueApplication

    # Start off by loading plugins. We need to do this before restoring
    # the session or loading the configuration since these may use existing
    # plugins.
    load_plugins()

    datafiles = datafiles or []

    hub = None

    if gluefile is not None:
        app = restore_session(gluefile)
        return app.start()

    if config is not None:
        glue.env = glue.config.load_configuration(search_path=[config])

    data_collection = glue.core.DataCollection()
    hub = data_collection.hub

    session = glue.core.Session(data_collection=data_collection, hub=hub)
    ga = GlueApplication(session=session, maximized=maximized)

    if datafiles:
        datasets = load_data_files(datafiles)
        ga.add_datasets(data_collection, datasets)

    # ga.show()
    # splash.close()
    # ga.raise_()
    # QApplication.instance().processEvents()
    return ga.start()
Example #23
0
def start_glue(gluefile=None, config=None, datafiles=None, maximized=True):
    """Run a glue session and exit

    Parameters
    ----------
    gluefile : str
        An optional ``.glu`` file to restore.

    config : str
        An optional configuration file to use.

    datafiles : str
        An optional list of data files to load.

    maximized : bool
        Maximize screen on startup. Otherwise, use default size.

    """
    import glue
    from glue.app.qt import GlueApplication

    # Start off by loading plugins. We need to do this before restoring
    # the session or loading the configuration since these may use existing
    # plugins.
    load_plugins()

    datafiles = datafiles or []

    hub = None

    if gluefile is not None:
        app = restore_session(gluefile)
        return app.start()

    if config is not None:
        glue.env = glue.config.load_configuration(search_path=[config])

    data_collection = glue.core.DataCollection()
    hub = data_collection.hub

    session = glue.core.Session(data_collection=data_collection, hub=hub)
    ga = GlueApplication(session=session, maximized=maximized)

    if datafiles:
        datasets = load_data_files(datafiles)
        ga.add_datasets(data_collection, datasets)

    # ga.show()
    # splash.close()
    # ga.raise_()
    # QApplication.instance().processEvents()
    return ga.start()
Example #24
0
    def setup_method(self, method):

        self.data = Data(label='d1')
        self.data['x'] = np.arange(24).reshape((3, 4, 2)).astype(float)

        self.app = GlueApplication()
        self.session = self.app.session
        self.hub = self.session.hub

        self.data_collection = self.session.data_collection
        self.data_collection.append(self.data)

        self.viewer = self.app.new_data_viewer(ImageViewer)
Example #25
0
    def test_close_on_last_layer_remove(self):
        # regression test for 391

        d1 = Data(x=np.random.random((2,) * self.ndim))
        d2 = Data(y=np.random.random((2,) * self.ndim))
        dc = DataCollection([d1, d2])
        app = GlueApplication(dc)
        with patch.object(self.widget_cls, 'close') as close:
            w = app.new_data_viewer(self.widget_cls, data=d1)
            w.add_data(d2)
            dc.remove(d1)
            dc.remove(d2)
        assert close.call_count >= 1
Example #26
0
    def test_close_on_last_layer_remove(self):
        # regression test for 391

        d1 = Data(x=np.random.random((2,) * self.ndim))
        d2 = Data(y=np.random.random((2,) * self.ndim))
        dc = DataCollection([d1, d2])
        app = GlueApplication(dc)
        with patch.object(self.widget_cls, 'close') as close:
            w = app.new_data_viewer(self.widget_cls, data=d1)
            w.add_data(d2)
            dc.remove(d1)
            dc.remove(d2)
        assert close.call_count >= 1
Example #27
0
    def setup_class(self):

        data = Data(x=[1, 2, 3], y=[2, 3, 4], label='data')
        dc = DataCollection([data])
        app = GlueApplication(dc)

        data.style.color = '#000000'
        v = app.new_data_viewer(HistogramWidget, data=data)
        v.component = data.id['y']
        v.xmin = 0
        v.xmax = 10
        v.bins = 20

        self.args, self.kwargs = build_plotly_call(app)
Example #28
0
    def setup_method(self, method):

        self.data1 = Data(label='d1', x=[3.4, 2.3, -1.1, 0.3],
                          y=[3.2, 3.3, 3.4, 3.5], z=['a', 'b', 'c', 'a'])
        self.data2 = Data(label='d1', x=[3.4, 2.3, -1.1, 0.3],
                          y=[3.2, 3.3, 3.4, 3.5], z=['a', 'b', 'c', 'a'])

        self.app = GlueApplication()

        self.data_collection = self.app.session.data_collection
        self.data_collection.append(self.data1)
        self.data_collection.append(self.data2)

        self.viewer = self.app.new_data_viewer(OpenSpaceDataViewer)
Example #29
0
    def setup_method(self, method):

        self.data = Data(label='d1')
        self.data.coords = SimpleCoordinates()
        self.data['x'] = np.arange(24).reshape((3, 4, 2))

        self.app = GlueApplication()
        self.session = self.app.session
        self.hub = self.session.hub

        self.data_collection = self.session.data_collection
        self.data_collection.append(self.data)

        self.viewer = self.app.new_data_viewer(ProfileViewer)
Example #30
0
    def setup_class(self):

        data = Data(x=[1, 2, 3], y=[2, 3, 4], label='data')
        dc = DataCollection([data])
        self.app = GlueApplication(dc)

        data.style.color = '#000000'
        v = self.app.new_data_viewer(HistogramViewer, data=data)
        v.component = data.id['y']
        v.xmin = 0
        v.xmax = 10
        v.bins = 20

        self.args, self.kwargs = build_plotly_call(self.app)
Example #31
0
class TestDataTableModel():

    def setup_method(self, method):
        self.gapp = GlueApplication()
        self.viewer = self.gapp.new_data_viewer(TableViewer)
        self.data = Data(x=[1, 2, 3, 4], y=[2, 3, 4, 5])
        self.gapp.data_collection.append(self.data)
        self.viewer.add_data(self.data)
        self.model = DataTableModel(self.viewer)

    def teardown_method(self, method):
        self.gapp.close()
        self.gapp = None

    def test_column_count(self):
        assert self.model.columnCount() == 2

    def test_column_count_hidden(self):
        self.model.show_coords = True
        assert self.model.columnCount() == 3

    def test_header_data(self):
        for i, c in enumerate(self.data.main_components):
            result = self.model.headerData(i, Qt.Horizontal, Qt.DisplayRole)
            assert result == c.label

        for i in range(self.data.size):
            result = self.model.headerData(i, Qt.Vertical, Qt.DisplayRole)
            assert result == str(i)

    def test_row_count(self):
        assert self.model.rowCount() == 4

    def test_data(self):
        for i, c in enumerate(self.data.main_components):
            for j in range(self.data.size):
                idx = self.model.index(j, i)
                result = self.model.data(idx, Qt.DisplayRole)
                assert float(result) == self.data[c, j]

    @pytest.mark.xfail
    def test_data_2d(self):
        self.data = Data(x=[[1, 2], [3, 4]], y=[[2, 3], [4, 5]])
        self.model = DataTableModel(self.data)
        for i, c in enumerate(self.data.main_components):
            for j in range(self.data.size):
                idx = self.model.index(j, i)
                result = self.model.data(idx, Qt.DisplayRole)
                assert float(result) == self.data[c].ravel()[j]
Example #32
0
class TestDataTableModel():

    def setup_method(self, method):
        self.gapp = GlueApplication()
        self.viewer = self.gapp.new_data_viewer(TableViewer)
        self.data = Data(x=[1, 2, 3, 4], y=[2, 3, 4, 5])
        self.gapp.data_collection.append(self.data)
        self.viewer.add_data(self.data)
        self.model = DataTableModel(self.viewer)

    def teardown_method(self, method):
        self.gapp.close()
        self.gapp = None

    def test_column_count(self):
        assert self.model.columnCount() == 2

    def test_column_count_hidden(self):
        self.model.show_coords = True
        assert self.model.columnCount() == 4

    def test_header_data(self):
        for i, c in enumerate(self.data.main_components):
            result = self.model.headerData(i, Qt.Horizontal, Qt.DisplayRole)
            assert result == c.label

        for i in range(self.data.size):
            result = self.model.headerData(i, Qt.Vertical, Qt.DisplayRole)
            assert result == str(i)

    def test_row_count(self):
        assert self.model.rowCount() == 4

    def test_data(self):
        for i, c in enumerate(self.data.main_components):
            for j in range(self.data.size):
                idx = self.model.index(j, i)
                result = self.model.data(idx, Qt.DisplayRole)
                assert float(result) == self.data[c, j]

    @pytest.mark.xfail
    def test_data_2d(self):
        self.data = Data(x=[[1, 2], [3, 4]], y=[[2, 3], [4, 5]])
        self.model = DataTableModel(self.data)
        for i, c in enumerate(self.data.main_components):
            for j in range(self.data.size):
                idx = self.model.index(j, i)
                result = self.model.data(idx, Qt.DisplayRole)
                assert float(result) == self.data[c].ravel()[j]
Example #33
0
    def setup_method(self, method):

        self.data = Data(label='d1', parent=[-1, 0, 1, 1], height=[1.3, 2.2, 3.2, 4.4])

        self.app = GlueApplication()
        self.session = self.app.session
        self.hub = self.session.hub

        self.data_collection = self.session.data_collection
        self.data_collection.append(self.data)

        self.viewer = self.app.new_data_viewer(DendrogramViewer)

        self.data_collection.register_to_hub(self.hub)
        self.viewer.register_to_hub(self.hub)
Example #34
0
def test_rotate(capsys):

    app = GlueApplication()
    viewer = app.new_data_viewer(VispyScatterViewer)

    viewer.toolbar.actions['vispy:rotate'].toggle()
    assert viewer.toolbar.active_tool.tool_id == 'vispy:rotate'

    viewer.toolbar.actions['vispy:rotate'].toggle()
    assert viewer.toolbar.active_tool is None

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

    app.close()
Example #35
0
 def setup_method(self, method):
     self.gapp = GlueApplication()
     self.viewer = self.gapp.new_data_viewer(TableViewer)
     self.data = Data(x=[1, 2, 3, 4], y=[2, 3, 4, 5])
     self.gapp.data_collection.append(self.data)
     self.viewer.add_data(self.data)
     self.model = DataTableModel(self.viewer)
Example #36
0
    def setup_method(self, method):

        self.coords = MyCoords()
        self.image1 = Data(label='image1', x=[[1, 2], [3, 4]], y=[[4, 5], [2, 3]])
        self.image2 = Data(label='image2', a=[[3, 3], [2, 2]], b=[[4, 4], [3, 2]],
                           coords=self.coords)
        self.catalog = Data(label='catalog', c=[1, 3, 2], d=[4, 3, 3])
        self.hypercube = Data(label='hypercube', x=np.arange(120).reshape((2, 3, 4, 5)))

        # Create data versions with WCS coordinates
        self.image1_wcs = Data(label='image1_wcs', x=self.image1['x'],
                               coords=WCSCoordinates(wcs=WCS(naxis=2)))
        self.hypercube_wcs = Data(label='hypercube_wcs', x=self.hypercube['x'],
                                  coords=WCSCoordinates(wcs=WCS(naxis=4)))

        self.application = GlueApplication()

        self.session = self.application.session

        self.hub = self.session.hub

        self.data_collection = self.session.data_collection
        self.data_collection.append(self.image1)
        self.data_collection.append(self.image2)
        self.data_collection.append(self.catalog)
        self.data_collection.append(self.hypercube)
        self.data_collection.append(self.image1_wcs)
        self.data_collection.append(self.hypercube_wcs)

        self.viewer = self.application.new_data_viewer(ImageViewer)

        self.data_collection.register_to_hub(self.hub)
        self.viewer.register_to_hub(self.hub)

        self.options_widget = self.viewer.options_widget()
Example #37
0
    def setup_method(self, method):

        self.data = Data(label='d1', x=[3.4, 2.3, -1.1, 0.3],
                         y=[3.2, 3.3, 3.4, 3.5], z=['a', 'b', 'c', 'a'])
        self.data_2d = Data(label='d2', a=[[1, 2], [3, 4]], b=[[5, 6], [7, 8]],
                            x=[[3, 5], [5.4, 1]], y=[[1.2, 4], [7, 8]])

        self.app = GlueApplication()
        self.session = self.app.session
        self.hub = self.session.hub

        self.data_collection = self.session.data_collection
        self.data_collection.append(self.data)
        self.data_collection.append(self.data_2d)

        self.viewer = self.app.new_data_viewer(ScatterViewer)
class TestOpenSpaceViewer:
    def setup_method(self, method):

        self.data1 = Data(label='d1',
                          x=[3.4, 2.3, -1.1, 0.3],
                          y=[3.2, 3.3, 3.4, 3.5],
                          z=['a', 'b', 'c', 'a'])
        self.data2 = Data(label='d1',
                          x=[3.4, 2.3, -1.1, 0.3],
                          y=[3.2, 3.3, 3.4, 3.5],
                          z=['a', 'b', 'c', 'a'])

        self.app = GlueApplication()

        self.data_collection = self.app.session.data_collection
        self.data_collection.append(self.data1)
        self.data_collection.append(self.data2)

        self.viewer = self.app.new_data_viewer(OpenSpaceDataViewer)

    def test_add_single_data(self, websocket_server):
        self.viewer.connect_to_openspace()
        assert len(websocket_server.messages) == 0
        self.viewer.add_data(self.data1)
        assert len(websocket_server.messages) == 1
Example #39
0
def start_glue(gluefile=None, config=None, datafiles=None):
    """Run a glue session and exit

    :param gluefile: An optional .glu file to restore
    :type gluefile: str

    :param config: An optional configuration file to use
    :type config: str

    :param datafiles: An optional list of data files to load
    :type datafiles: list of str
    """
    import glue
    from glue.app.qt import GlueApplication

    # Start off by loading plugins. We need to do this before restoring
    # the session or loading the configuration since these may use existing
    # plugins.
    load_plugins()

    datafiles = datafiles or []

    data, hub = None, None

    if gluefile is not None:
        app = restore_session(gluefile)
        return app.start()

    if config is not None:
        glue.env = glue.config.load_configuration(search_path=[config])

    data_collection = glue.core.DataCollection()
    hub = data_collection.hub

    session = glue.core.Session(data_collection=data_collection, hub=hub)
    ga = GlueApplication(session=session)

    if datafiles:
        datasets = load_data_files(datafiles)
        ga.add_datasets(data_collection, datasets)

    # ga.show()
    # splash.close()
    # ga.raise_()
    # QApplication.instance().processEvents()
    return ga.start()
Example #40
0
    def test_single_draw_call_on_create(self):
        d = Data(x=np.random.random((2,) * self.ndim))
        dc = DataCollection([d])
        app = GlueApplication(dc)

        try:
            from glue.viewers.common.qt.mpl_widget import MplCanvas
            draw = MplCanvas.draw
            MplCanvas.draw = MagicMock()

            app.new_data_viewer(self.widget_cls, data=d)

            # each Canvas instance gives at most 1 draw call
            selfs = [c[0][0] for c in MplCanvas.draw.call_arg_list]
            assert len(set(selfs)) == len(selfs)
        finally:
            MplCanvas.draw = draw
Example #41
0
def start_glue(gluefile=None, config=None, datafiles=None):
    """Run a glue session and exit

    :param gluefile: An optional .glu file to restore
    :type gluefile: str

    :param config: An optional configuration file to use
    :type config: str

    :param datafiles: An optional list of data files to load
    :type datafiles: list of str
    """
    import glue
    from glue.app.qt import GlueApplication

    # Start off by loading plugins. We need to do this before restoring
    # the session or loading the configuration since these may use existing
    # plugins.
    load_plugins()

    datafiles = datafiles or []

    data, hub = None, None

    if gluefile is not None:
        app = restore_session(gluefile)
        return app.start()

    if config is not None:
        glue.env = glue.config.load_configuration(search_path=[config])

    data_collection = glue.core.DataCollection()
    hub = data_collection.hub

    session = glue.core.Session(data_collection=data_collection, hub=hub)
    ga = GlueApplication(session=session)

    if datafiles:
        datasets = load_data_files(datafiles)
        ga.add_datasets(data_collection, datasets)

    # ga.show()
    # splash.close()
    # ga.raise_()
    # QApplication.instance().processEvents()
    return ga.start()
Example #42
0
    def test_single_draw_call_on_create(self):
        d = Data(x=np.random.random((2,) * self.ndim))
        dc = DataCollection([d])
        app = GlueApplication(dc)

        try:
            from glue.viewers.matplotlib.qt.widget import MplCanvas
            draw = MplCanvas.draw
            MplCanvas.draw = MagicMock()

            app.new_data_viewer(self.widget_cls, data=d)

            # each Canvas instance gives at most 1 draw call
            selfs = [c[0][0] for c in MplCanvas.draw.call_arg_list]
            assert len(set(selfs)) == len(selfs)
        finally:
            MplCanvas.draw = draw
Example #43
0
 def setup_method(self, method):
     self.d = Data(x=[1, 2, 3], y=[2, 3, 4], z=[4, 5, 6])
     self.application = GlueApplication()
     self.dc = self.application.data_collection
     self.dc.append(self.d)
     self.hub = self.dc.hub
     self.session = self.application.session
     self.viewer = self.application.new_data_viewer(WWTDataViewer)
     self.options = self.viewer.options_widget()
    def test_options_widget(self):
        d1 = Data(x=np.random.random((2, ) * self.ndim))
        d2 = Data(x=np.random.random((2, ) * self.ndim))
        dc = DataCollection([d1, d2])
        app = GlueApplication(dc)
        w = app.new_data_viewer(self.widget_cls, data=d1)

        w.state.x_stretch = 0.5
        w.state.y_stretch = 1.0
        w.state.z_stretch = 2.0

        w.state.x_min = -0.1
        w.state.x_max = 10.1
        w.state.y_min = 0.1
        w.state.y_max = 10.9
        w.state.z_min = 0.2
        w.state.z_max = 10.8

        w.state.visible_axes = False
Example #45
0
    def test_close_on_last_layer_remove(self):

        # regression test for 391

        d1 = Data(x=np.random.random((2,) * self.ndim))
        d2 = Data(y=np.random.random((2,) * self.ndim))
        dc = DataCollection([d1, d2])
        app = GlueApplication(dc)
        w = app.new_data_viewer(self.widget_cls, data=d1)
        w.add_data(d2)
        process_events()
        assert len(app.viewers[0]) == 1
        dc.remove(d1)
        process_events()
        assert len(app.viewers[0]) == 1
        dc.remove(d2)
        process_events()
        assert len(app.viewers[0]) == 0
        app.close()
    def test_options_widget(self):
        d1 = Data(x=np.random.random((2,) * self.ndim))
        d2 = Data(x=np.random.random((2,) * self.ndim))
        dc = DataCollection([d1, d2])
        app = GlueApplication(dc)
        w = app.new_data_viewer(self.widget_cls, data=d1)

        w.state.x_stretch = 0.5
        w.state.y_stretch = 1.0
        w.state.z_stretch = 2.0

        w.state.x_min = -0.1
        w.state.x_max = 10.1
        w.state.y_min = 0.1
        w.state.y_max = 10.9
        w.state.z_min = 0.2
        w.state.z_max = 10.8

        w.state.visible_axes = False
Example #47
0
    def test_load_session_back_compat(self):

        # Make sure that old session files continue to work

        app = GlueApplication.restore_session(
            os.path.join(DATA, 'wwt_simple.glu'))
        viewer_state = app.viewers[0][0].state
        assert viewer_state.lon_att.label == 'a'
        assert viewer_state.lat_att.label == 'b'
        assert viewer_state.frame == 'Galactic'
Example #48
0
def test_add_subset():

    # Regression test for a bug that occurred when adding a subset
    # directly to the table viewer.

    data1 = Data(a=[1, 2, 3, 4, 5], label='test1')
    data2 = Data(a=[1, 2, 3, 4, 5], label='test2')
    dc = DataCollection([data1, data2])
    dc.new_subset_group('test subset 1', data1.id['a'] > 2)

    gapp = GlueApplication(dc)

    viewer = gapp.new_data_viewer(TableViewer)
    viewer.add_subset(data1.subsets[0])

    assert len(viewer.state.layers) == 2
    assert not viewer.state.layers[0].visible
    assert viewer.state.layers[1].visible

    dc.new_subset_group('test subset 2', data1.id['a'] <= 2)

    assert len(viewer.state.layers) == 3
    assert not viewer.state.layers[0].visible
    assert viewer.state.layers[1].visible
    assert viewer.state.layers[2].visible

    viewer.remove_subset(data1.subsets[1])

    assert len(viewer.state.layers) == 2
    assert not viewer.state.layers[0].visible
    assert viewer.state.layers[1].visible

    viewer.add_subset(data1.subsets[1])

    assert len(viewer.state.layers) == 3
    assert not viewer.state.layers[0].visible
    assert viewer.state.layers[1].visible
    assert viewer.state.layers[2].visible

    with pytest.raises(ValueError) as exc:
        viewer.add_subset(data2.subsets[1])
    assert exc.value.args[
        0] == 'subset parent data does not match existing table data'
Example #49
0
    def test_close_on_last_layer_remove(self):

        # regression test for 391

        d1 = Data(x=np.random.random((2, ) * self.ndim))
        d2 = Data(y=np.random.random((2, ) * self.ndim))
        dc = DataCollection([d1, d2])
        app = GlueApplication(dc)
        w = app.new_data_viewer(self.widget_cls, data=d1)
        w.add_data(d2)
        process_events()
        assert len(app.viewers[0]) == 1
        dc.remove(d1)
        process_events()
        assert len(app.viewers[0]) == 1
        dc.remove(d2)
        process_events()
        assert len(app.viewers[0]) == 0
        app.close()
Example #50
0
    def setup_method(self, method):
        LinkSame = core.link_helpers.LinkSame

        d = core.Data(label='im', x=[[1, 2], [2, 3]], y=[[2, 3], [4, 5]])
        d2 = core.Data(label='cat',
                       x=[0, 1, 0, 1],
                       y=[0, 0, 1, 1],
                       z=[1, 2, 3, 4])

        dc = core.DataCollection([d, d2])
        dc.add_link(LinkSame(d.get_pixel_component_id(0), d2.id['x']))
        dc.add_link(LinkSame(d.get_pixel_component_id(1), d2.id['y']))

        app = GlueApplication(dc)
        w = app.new_data_viewer(ImageWidget, data=d)
        self.d = d
        self.app = app
        self.w = w
        self.d2 = d2
        self.dc = dc
Example #51
0
def test_change_components():

    # Regression test for a bug that caused table viewers to not update when
    # adding/removing components. For now, this does not work with Qt 5.7.

    app = get_qapp()  # noqa

    d = Data(a=[1, 2, 3, 4, 5],
             b=[3.2, 1.2, 4.5, 3.3, 2.2],
             c=['e', 'b', 'c', 'a', 'f'], label='test')

    dc = DataCollection([d])

    gapp = GlueApplication(dc)

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

    data_changed = MagicMock()
    viewer.model.dataChanged.connect(data_changed)

    # layoutChanged needs to be emitted for the new/removed columns to be
    # registered (dataChanged is not enough)
    layout_changed = MagicMock()
    viewer.model.layoutChanged.connect(layout_changed)

    assert data_changed.call_count == 0
    assert layout_changed.call_count == 0
    viewer.model.columnCount() == 2

    d.add_component([3, 4, 5, 6, 2], 'z')

    assert data_changed.call_count == 1
    assert layout_changed.call_count == 1
    viewer.model.columnCount() == 3

    d.remove_component(d.id['z'])

    assert data_changed.call_count == 2
    assert layout_changed.call_count == 2
    viewer.model.columnCount() == 2
Example #52
0
    def setup_method(self, method):

        self.data = Data(label='d1', x=[3.4, 2.3, -1.1, 0.3], y=['a', 'b', 'c', 'a'])

        self.app = GlueApplication()
        self.session = self.app.session
        self.hub = self.session.hub

        self.data_collection = self.session.data_collection
        self.data_collection.append(self.data)

        self.viewer = self.app.new_data_viewer(HistogramViewer)
Example #53
0
def test_table_title():

    app = get_qapp()  # noqa

    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)

    assert viewer.windowTitle() == 'Table'

    viewer.add_data(data1)

    assert viewer.windowTitle() == 'Table: test1'

    viewer.add_data(data2)

    assert viewer.windowTitle() == 'Table: test2'
Example #54
0
    def test_close_on_last_layer_remove(self):

        # regression test for 391

        # Note: processEvents is needed for things to work correctly with PySide2
        qtapp = get_qapp()

        d1 = Data(x=np.random.random((2,) * self.ndim))
        d2 = Data(y=np.random.random((2,) * self.ndim))
        dc = DataCollection([d1, d2])
        app = GlueApplication(dc)
        w = app.new_data_viewer(self.widget_cls, data=d1)
        w.add_data(d2)
        qtapp.processEvents()
        assert len(app.viewers[0]) == 1
        dc.remove(d1)
        qtapp.processEvents()
        assert len(app.viewers[0]) == 1
        dc.remove(d2)
        qtapp.processEvents()
        assert len(app.viewers[0]) == 0
        app.close()
Example #55
0
def test_two_custom_viewer_classes():

    class MyWidget1(CustomViewer):

        text_box1_Widget1 = '_Hello'

        def setup(self, text_box1_Widget1):
            pass

    class MyWidget2(CustomViewer):

        text_box1_Widget2 = '_Hello'
        text_box2_Widget2 = '_world'

        def setup(self, text_box1_Widget2, text_box2_Widget2):
            pass

    app = GlueApplication()
    dc = app.data_collection
    d = Data(x=[1, 2, 3], label='test')
    dc.append(d)
    app.new_data_viewer(MyWidget1._widget_cls)
    app.new_data_viewer(MyWidget2._widget_cls)
Example #56
0
    def setup_method(self, method):

        self.data = Data(label='d1')
        self.data.coords = SimpleCoordinates()
        self.data['x'] = np.arange(24).reshape((3, 4, 2))

        self.app = GlueApplication()
        self.session = self.app.session
        self.hub = self.session.hub

        self.data_collection = self.session.data_collection
        self.data_collection.append(self.data)

        self.viewer = self.app.new_data_viewer(ProfileViewer)
Example #57
0
    def setup_method(self, method):

        self.data = Data(label='d1', parent=[-1, 0, 1, 1], height=[1.3, 2.2, 3.2, 4.4])

        self.app = GlueApplication()
        self.session = self.app.session
        self.hub = self.session.hub

        self.data_collection = self.session.data_collection
        self.data_collection.append(self.data)

        self.viewer = self.app.new_data_viewer(DendrogramViewer)

        self.data_collection.register_to_hub(self.hub)
        self.viewer.register_to_hub(self.hub)
Example #58
0
    def setup_method(self, method):

        self.data = Data(label='d1', x=[3.4, 2.3, -1.1, 0.3],
                         y=[3.2, 3.3, 3.4, 3.5], z=['a', 'b', 'c', 'a'])
        self.data_2d = Data(label='d2', a=[[1, 2], [3, 4]], b=[[5, 6], [7, 8]],
                            x=[[3, 5], [5.4, 1]], y=[[1.2, 4], [7, 8]])

        self.app = GlueApplication()
        self.session = self.app.session
        self.hub = self.session.hub

        self.data_collection = self.session.data_collection
        self.data_collection.append(self.data)
        self.data_collection.append(self.data_2d)

        self.viewer = self.app.new_data_viewer(ScatterViewer)
Example #59
0
    def setup_method(self, method):

        self.data = Data(label='d1')
        self.data.coords = SimpleCoordinates()
        self.data['x'] = np.arange(240).reshape((30, 4, 2)).astype(float)

        self.app = GlueApplication()
        self.session = self.app.session
        self.hub = self.session.hub

        self.data_collection = self.session.data_collection
        self.data_collection.append(self.data)

        self.viewer = self.app.new_data_viewer(ProfileViewer)
        self.viewer.state.function = 'mean'

        self.viewer.toolbar.active_tool = 'profile-analysis'

        self.profile_tools = self.viewer.toolbar.tools['profile-analysis']._profile_tools
    def test_add_viewer(self, tmpdir):

        d1 = Data(x=np.random.random((2,) * self.ndim))
        d2 = Data(x=np.random.random((2,) * self.ndim))
        dc = DataCollection([d1, d2])
        app = GlueApplication(dc)
        w = app.new_data_viewer(self.widget_cls, data=d1)
        w.viewer_size = (300, 400)

        filename = tmpdir.join('session.glu').strpath
        app.save_session(filename, include_data=True)

        app2 = GlueApplication.restore_session(filename)

        # test session is restored correctly
        for viewer in app2.viewers:
            assert viewer[0].viewer_size == (300, 400)

        app.close()
        app2.close()