def _load_data(self): """ Interactively loads data from a data set. Adds as new layer """ from glue.qt.glue_application import GlueApplication layers = qtutil.data_wizard() GlueApplication.add_datasets(self.data_collection, layers)
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.qt.glue_application.GlueApplication` object """ from .core import DataCollection from glue.qt.glue_application 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
def test_multi_tab(self): d = core.Data(label="hist", x=[[1, 2], [2, 3]]) dc = core.DataCollection([d]) app = GlueApplication(dc) w1 = app.new_data_viewer(HistogramWidget, data=d) app.new_tab() w2 = app.new_data_viewer(HistogramWidget, data=d) assert app.viewers == ((w1,), (w2,)) self.check_clone(app)
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
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
def export_glue(ds, data, name): from glue.core import Data, DataCollection from glue.qt.glue_application import GlueApplication import numpy as np d = Data(label=name) d.add_component(ytComponent(data, ds, name), label='x') dc = DataCollection(d) ga = GlueApplication(dc) ga.start()
class TestGlueApplication(unittest.TestCase): def setUp(self): self.qapp = QApplication([""]) self.app = GlueApplication() def tearDown(self): self.app.close() del self.app del self.qapp def test_new_tabs(self): t0 = tab_count(self.app) self.app._new_tab() self.assertEquals(t0 + 1, tab_count(self.app))
def test_histogram(self): d = core.Data(label="hist", x=[[1, 2], [2, 3]]) dc = core.DataCollection([d]) app = GlueApplication(dc) w = app.new_data_viewer(HistogramWidget, data=d) self.check_clone(app) dc.new_subset_group() assert len(w.layers) == 2 self.check_clone(app) w.nbins = 7 self.check_clone(app)
def test_scatter_viewer(self): d = core.Data(label="x", x=[1, 2, 3, 4, 5], y=[2, 3, 4, 5, 6]) dc = core.DataCollection([d]) app = GlueApplication(dc) w = app.new_data_viewer(ScatterWidget, data=d) self.check_clone(app) s1 = dc.new_subset_group() s2 = dc.new_subset_group() assert len(w.layers) == 3 l1, l2, l3 = w.layers l1.zorder, l2.zorder = l2.zorder, l1.zorder l3.visible = False assert l3.visible is False copy = self.check_clone(app) assert copy.viewers[0][0].layers[-1].visible is False
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.qt.glue_application 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]) if datafiles: data = load_data_files(datafiles) if not data: data = glue.core.DataCollection() hub = data.hub session = glue.core.Session(data_collection=data, hub=hub) ga = GlueApplication(session=session) #ga.show() #splash.close() #ga.raise_() #QApplication.instance().processEvents() return ga.start()
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 ..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
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 """ #from PyQt4.QtGui import QApplication #app = QApplication.instance() or QApplication(sys.argv) #splash = get_splash() import glue from glue.qt.glue_application import GlueApplication datafiles = datafiles or [] data, hub = None, None if gluefile is not None: data, hub = restore_session(gluefile) if config is not None: glue.env = glue.config.load_configuration(search_path=[config]) if datafiles: data = load_data_files(datafiles) if not hub: if data: hub = glue.core.Hub(data) else: hub = glue.core.Hub() ga = GlueApplication(data_collection=data, hub=hub) #ga.show() #splash.close() #ga.raise_() #QApplication.instance().processEvents() return ga.start()
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
def to_glue(self, label="yt", data_collection=None): """ Takes the data in the FITSImageData instance and exports it to Glue (http://www.glueviz.org) for interactive analysis. Optionally add a *label*. If you are already within the Glue environment, you can pass a *data_collection* object, otherwise Glue will be started. """ from glue.core import DataCollection, Data from glue.core.coordinates import coordinates_from_header from glue.qt.glue_application import GlueApplication image = Data(label=label) image.coords = coordinates_from_header(self.wcs.to_header()) for k,f in self.items(): image.add_component(f.data, k) if data_collection is None: dc = DataCollection([image]) app = GlueApplication(dc) app.start() else: data_collection.append(image)
def to_glue(self, label="yt", data_collection=None): """ Takes the data in the FITSImageData instance and exports it to Glue (http://www.glueviz.org) for interactive analysis. Optionally add a *label*. If you are already within the Glue environment, you can pass a *data_collection* object, otherwise Glue will be started. """ from glue.core import DataCollection, Data from glue.core.coordinates import coordinates_from_header from glue.qt.glue_application import GlueApplication image = Data(label=label) image.coords = coordinates_from_header(self.wcs.to_header()) for k, f in self.items(): image.add_component(f.data, k) if data_collection is None: dc = DataCollection([image]) app = GlueApplication(dc) app.start() else: data_collection.append(image)
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.qt.glue_application import GlueApplication datafiles = datafiles or [] data, hub = None, None if gluefile is not None: data, hub = restore_session(gluefile) if config is not None: glue.env = glue.config.load_configuration(search_path=[config]) if datafiles: data = load_data_files(datafiles) if not hub: if data: hub = glue.core.Hub(data) else: hub = glue.core.Hub() ga = GlueApplication(data_collection=data, hub=hub) #ga.show() #splash.close() #ga.raise_() #QApplication.instance().processEvents() return ga.start()
def test_viewer_size(self, tmpdir): # regression test for #781 # viewers were not restored with the right size 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) for viewer in app2.viewers: assert viewer[0].viewer_size == (300, 400) app.close() app2.close()
h2cocube.label='H2CO 303202 Cube' catalog = astropy_tabular_data(hpath('PPV_H2CO_Temperature.ipac'), format='ipac') catalog.label='Fitted Catalog' h2cocube.add_component(dendcube.get_component('structure'), 'structure') dc = DataCollection(dendrogram) dc.append(h2cocube) dc.append(catalog) dc.append(dendcube) dc.merge(h2cocube,dendcube) dc.merge(dendro, catalog) app = GlueApplication(dc) cube_viewer = app.new_data_viewer(ImageWidget) cube_viewer.add_data(h2cocube) h2cocube.join_on_key(dendro, 'structure', dendro.pixel_component_ids[0]) scatter = app.new_data_viewer(ScatterWidget) scatter.add_data(dendro) scatter.yatt = dendro.id['temperature_chi2'] scatter.xatt = catalog.id['r321303'] dendview = app.new_data_viewer(DendroWidget) dendview.add_data(dendro) subset_tem_bt_40_60 = ((catalog.id['temperature_chi2'] < 60) &
from glue.core.data_factories import load_data from glue.core import DataCollection from glue.core.link_helpers import LinkSame from glue.qt.glue_application import GlueApplication #load 2 datasets from files image = load_data('w5.fits') catalog = load_data('w5_psc.vot') dc = DataCollection([image, catalog]) # link positional information dc.add_link(LinkSame(image.id['World x: RA---TAN'], catalog.id['RAJ2000'])) dc.add_link(LinkSame(image.id['World y: DEC--TAN'], catalog.id['DEJ2000'])) #start Glue app = GlueApplication(dc) app.start()
from glue.core import Component from glue.core import Data, DataCollection from glue.qt.glue_application import GlueApplication import numpy as np import yt from simple_fullres import ytSliceComponent ds = yt.load("GasSloshing/sloshing_nomag2_hdf5_plt_cnt_0150") d = Data(label=str(ds)) for field in ("density", "temperature", "velocity_x", "velocity_y", "velocity_z"): d.add_component(ytSliceComponent(ds, field), label=field) dc = DataCollection(d) ga = GlueApplication(dc) ga.start()
'variables': ('B40', 'B30',), 'dimensions': {'X': {'range': (147.875, 148.125)}, 'Y': {'range': (-37.0 + 0.875, -36.0 + 0.125)}, # 'T': {'range': (start_date, end_date), # 'array_range': (0, 4) # 'crs': 'SSE', # Seconds since epoch # 'grouping_function': g.null_grouping # } } } # In[6]: d = g.get_data(data_request_descriptor) print "d shape: ", d['arrays']['B30'].shape # plotContourf(d, 'B30') # plotImages(d['arrays']['B30']) # In[ ]: from glue.core import Data, DataCollection from glue.qt.glue_application import GlueApplication 44 # In[ ]: my_data1 = Data(x=d['arrays']['B40'], label='B40') collection = DataCollection([my_data1, ]) # collection.merge(my_data1,my_data2,my_data3) app = GlueApplication(collection) app.start()
def restore_session(gluefile): """Load a .glu file and return a DataCollection, Hub tuple""" from glue.qt.glue_application import GlueApplication return GlueApplication.restore(gluefile)
def setUp(self): self.qapp = QApplication([""]) self.app = GlueApplication()
def kms_to_ms(x): return x * 1e3 dc.add_link( LinkTwoWay(cube.id['Vrad'], catalog.id['center'], ms_to_kms, kms_to_ms)) subset_tem_lt_60 = (catalog.id['temperature_chi2'] < 60) & ( catalog.id['temperature_chi2'] > 10) & (catalog.id['area'] < 0.015) subset_tem_gt_60 = (catalog.id['temperature_chi2'] > 60) & (catalog.id['area'] < 0.015) app = GlueApplication(dc) # plot x vs y, flip the x axis, log-scale y axis scatter = app.new_data_viewer(ScatterWidget) scatter.add_data(catalog) scatter.yatt = catalog.id['temperature_chi2'] scatter.xatt = catalog.id['higaldusttem'] #scatter.xflip = True #scatter.ylog = True cube_viewer = app.new_data_viewer(ImageWidget) cube_viewer.add_data(cube) #cube_viewer.add_subset(subset_tem_lt_60) #cube_viewer.add_subset(subset_tem_gt_60) #cube_viewer.add_data(catalog)
dc = DataCollection([cube, catalog, cube2, cube3, higaltem]) dc.merge(cube,cube2,cube3) dc.add_link(LinkSame(cube.id['Galactic Longitude'], catalog.id['GLON'])) dc.add_link(LinkSame(cube.id['Galactic Latitude'], catalog.id['GLAT'])) def ms_to_kms(x): return x/1e3 def kms_to_ms(x): return x*1e3 dc.add_link(LinkTwoWay(cube.id['Vrad'], catalog.id['center'], ms_to_kms, kms_to_ms)) subset_tem_lt_60 = (catalog.id['temperature_chi2'] < 60) & (catalog.id['temperature_chi2'] > 10) & (catalog.id['area'] < 0.015) subset_tem_gt_60 = (catalog.id['temperature_chi2'] > 60) & (catalog.id['area'] < 0.015) app = GlueApplication(dc) # plot x vs y, flip the x axis, log-scale y axis scatter = app.new_data_viewer(ScatterWidget) scatter.add_data(catalog) scatter.yatt = catalog.id['temperature_chi2'] scatter.xatt = catalog.id['higaldusttem'] #scatter.xflip = True #scatter.ylog = True cube_viewer = app.new_data_viewer(ImageWidget) cube_viewer.add_data(cube) #cube_viewer.add_subset(subset_tem_lt_60) #cube_viewer.add_subset(subset_tem_gt_60) #cube_viewer.add_data(catalog)
nc = Component.autotyped(cc, units=uu) catalog.add_component(nc, column_name) # if column_name != 'parent' else '_flarent_' catalog.join_on_key(dendro, '_idx', dendro.pixel_component_ids[0]) dc = DataCollection(dendrogram) #dc = DataCollection([cube, dendrogram, catalog]) #dc.merge(cube,sncube) #sncube.join_on_key(dendro, 'structure', dendro.pixel_component_ids[0]) #dc.merge(catalog, dendro) # UNCOMMENT THIS LINE TO BREAK THE VIEWER dc.append(catalog) app = GlueApplication(dc) cube_viewer = app.new_data_viewer(ImageWidget) cube_viewer.add_data(sncube) # link positional information dc.add_link(LinkSame(sncube.id['structure'], catalog.id['_idx'])) #dc.add_link(LinkSame(image.id['World y: DEC--TAN'], catalog.id['DEJ2000'])) dc.add_link(LinkSame(cube.id['Galactic Longitude'], catalog.id['x_cen'])) dc.add_link(LinkSame(cube.id['Galactic Latitude'], catalog.id['y_cen'])) def ms_to_kms(x): return x / 1e3