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 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()
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 # 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 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 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()
interpolation='nearest') pv_viewer = app.add_widget(pvwidget, label="Orbit PV Slice") ax2 = pvwidget.axes dl = (table['l'][1:] - table['l'][:-1]) db = (table['b'][1:] - table['b'][:-1]) dist = (dl**2 + db**2)**0.5 cdist = np.zeros(dist.size + 1) * u.deg cdist[1:] = dist.cumsum() * u.deg #pixscale = ((x[1]-x[0])**2+(y[1]-y[0])**2)**0.5 pixscale = wcs.utils.celestial_pixel_scale(cube.data.coords.wcs) spwcs = cube.data.coords.wcs.sub([wcs.WCSSUB_SPECTRAL]) spax = spwcs.wcs_world2pix(table["v'los"] * 1e3, 0)[0] ax2.plot(cdist / pixscale, spax, 'r-', linewidth=2, alpha=0.5) ax2.set_axis_bgcolor('black') # SERIOUSLY, DO IT ax.axis([x.min(), x.max(), y.min(), y.max()]) dc.new_subset_group(label='T < 60', subset_state=subset_tem_lt_60) dc.new_subset_group(label='T > 60', subset_state=subset_tem_gt_60) dc.subset_groups[0].style.markersize = 15 dc.subset_groups[0].style.marker = '+' dc.subset_groups[0].style.color = 'blue' dc.subset_groups[1].style.markersize = 15 dc.subset_groups[1].style.marker = '*' dc.subset_groups[1].style.color = 'orange' app.start()
pv_viewer = app.add_widget(pvwidget, label="Orbit PV Slice") ax2 = pvwidget.axes dl = (table['l'][1:]-table['l'][:-1]) db = (table['b'][1:]-table['b'][:-1]) dist = (dl**2+db**2)**0.5 cdist = np.zeros(dist.size+1) * u.deg cdist[1:] = dist.cumsum() * u.deg #pixscale = ((x[1]-x[0])**2+(y[1]-y[0])**2)**0.5 pixscale = wcs.utils.celestial_pixel_scale(cube.data.coords.wcs) spwcs = cube.data.coords.wcs.sub([wcs.WCSSUB_SPECTRAL]) spax = spwcs.wcs_world2pix(table["v'los"]*1e3, 0)[0] ax2.plot(cdist/pixscale, spax, 'r-', linewidth=2, alpha=0.5) ax2.set_axis_bgcolor('black') # SERIOUSLY, DO IT ax.axis([x.min(),x.max(),y.min(),y.max()]) dc.new_subset_group(label='T < 60', subset_state=subset_tem_lt_60) dc.new_subset_group(label='T > 60', subset_state=subset_tem_gt_60) dc.subset_groups[0].style.markersize=15 dc.subset_groups[0].style.marker='+' dc.subset_groups[0].style.color='blue' dc.subset_groups[1].style.markersize=15 dc.subset_groups[1].style.marker='*' dc.subset_groups[1].style.color='orange' 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()