def jglue(*args, **kwargs): """ Create a new Jupyter-based glue application. It is typically easiest to call this function without arguments and load data and add links separately in subsequent calls. However, this function can also take the same inputs as the `~glue.qglue.qglue` function. Once this function is called, it will return a `~glue_jupyter.JupyterApplication` object, which can then be used to load data, set up links, and create visualizations. See the documentation for that class for more details. """ show = kwargs.pop('show', False) from glue.core import DataCollection from glue.qglue import parse_data, parse_links from glue.core.data_factories import load_data links = kwargs.pop('links', None) dc = DataCollection() for label, data in kwargs.items(): if isinstance(data, str): data = load_data(data) dc.extend(parse_data(data, label)) for data in args: dc.append(data) if links is not None: dc.add_link(parse_links(dc, links)) japp = JupyterApplication(dc) if show: display(app) return japp
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
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
def jglue(*args, **kwargs): from glue.core import DataCollection from glue.app.qt import GlueApplication from glue.qglue import parse_data, parse_links from glue.core.data_factories import load_data links = kwargs.pop('links', None) dc = DataCollection() for label, data in kwargs.items(): if isinstance(data, six.string_types): data = load_data(data) dc.extend(parse_data(data, label)) for data in args: dc.append(data) if links is not None: dc.add_link(parse_links(dc, links)) japp = JupyterApplication(dc) return japp
class LabeledDelegate(QtWidgets.QStyledItemDelegate): """ Add placeholder text to default delegate """ def setEditorData(self, editor, index): super(LabeledDelegate, self).setEditorData(editor, index) label = index.model().data(index, role=Qt.DisplayRole) editor.selectAll() editor.setText(label) if __name__ == "__main__": from glue.utils.qt import get_qapp from qtpy import QtWidgets from glue.core import Data, DataCollection app = get_qapp() dc = DataCollection() dc.append(Data(label='w')) view = DataCollectionView() view.set_data_collection(dc) view.show() view.raise_() dc.extend([Data(label='x', x=[1, 2, 3]), Data(label='y', y=[1, 2, 3]), Data(label='z', z=[1, 2, 3])]) app.exec_()