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 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 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 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)