Пример #1
0
    def setup_class(self):
        self.viewer = custom_viewer('CustomSelectViewer',
                                    x='att(x)', flip=False)

        @self.viewer.select
        def select(roi, x, flip):
            if flip:
                return x <= 1
            return x > 1
Пример #2
0
    def setup_class(self):
        self.viewer = custom_viewer('CustomSelectViewer',
                                    x='att(x)',
                                    flip=False)

        @self.viewer.select
        def select(roi, x, flip):
            if flip:
                return x <= 1
            return x > 1
Пример #3
0
def _generate_custom_viewer():

    example = custom_viewer('Test Plot', x='att(x)', y='att(y)')

    @example.plot_data
    def plot_data(axes, x, y, style):
        axes.plot(x, y)

    @example.plot_subset
    def plot_subset(axes, x, y, style):
        axes.plot(x, y)

    @example.setup
    def setup(axes):
        pass

    from glue.config import qt_client
    for viewer in qt_client.members:
        if viewer.LABEL == 'Test Plot':
            return viewer

    raise Exception("Failed to find custom viewer in qt_client")
Пример #4
0
def _generate_custom_viewer():

    example = custom_viewer('Test Plot', x='att(x)', y='att(y)')

    @example.plot_data
    def plot_data(axes, x, y, style):
        axes.plot(x, y)

    @example.plot_subset
    def plot_subset(axes, x, y, style):
        axes.plot(x, y)

    @example.setup
    def setup(axes):
        pass

    from glue.config import qt_client
    for viewer in qt_client.members:
        if viewer.LABEL == 'Test Plot':
            return viewer

    raise Exception("Failed to find custom viewer in qt_client")
Пример #5
0
from glue import custom_viewer

from matplotlib.colors import LogNorm
from matplotlib.patches import Circle, Rectangle, Arc
from matplotlib.lines import Line2D
import numpy as np

bball = custom_viewer('Shot Plot',
                      x='att(x)',
                      y='att(y)',
                      bins=(10, 100),
                      hitrate=False,
                      color=['Reds', 'Purples'],
                      hit='att(shot_made)')


@bball.plot_data
def show_hexbin(axes, x, y, style,
                hit, hitrate, color, bins):
    if hitrate:
        axes.hexbin(x, y, hit,
                    reduce_C_function=lambda x: np.array(x).mean(),
                    cmap=color,
                    gridsize=bins,
                    mincnt=5)
    else:
        axes.hexbin(x, y,
                    cmap=color,
                    gridsize=bins,
                    norm=LogNorm(),
                    mincnt=1)
Пример #6
0
from glue import custom_viewer

from matplotlib.colors import LogNorm
from matplotlib.patches import Circle, Rectangle, Arc
from matplotlib.lines import Line2D
import numpy as np

bball = custom_viewer('Shot Plot',
                      x='att(x)',
                      y='att(y)',
                      bins=(10, 100),
                      hitrate=False,
                      color=['Reds', 'Purples'],
                      hit='att(shot_made)')


@bball.select
def select(roi, x, y):
    return roi.contains(x, y)


@bball.plot_data
def show_hexbin(axes, x, y, hit, hitrate, color, bins):
    if hitrate:
        axes.hexbin(x,
                    y,
                    hit,
                    reduce_C_function=lambda x: np.array(x).mean(),
                    cmap=color,
                    gridsize=bins,
                    mincnt=5)
Пример #7
0
from glue import custom_viewer

from matplotlib.colors import LogNorm
from matplotlib.patches import Circle, Rectangle, Arc
from matplotlib.lines import Line2D

bball = custom_viewer('Shot Plot',
                      x='att(x)',
                      y='att(y)')


@bball.plot_data
def show_hexbin(axes, x, y):
    return axes.hexbin(x.values, y.values,
                       cmap='Purples',
                       gridsize=40,
                       norm=LogNorm(),
                       mincnt=1)


@bball.plot_subset
def show_points(axes, x, y, style):
    return axes.plot(x.values, y.values, 'o',
                     alpha=style.alpha,
                     mec=style.color,
                     mfc=style.color,
                     ms=style.markersize)


@bball.setup
def draw_court(axes):
Пример #8
0
from glue import custom_viewer

GREEN = (229 / 255., 245 / 255., 224 / 255.)
BLUE = (222 / 255., 235 / 255., 247 / 255.)

earthquake_map = custom_viewer('Earthquake Map',
                               longitude='att(longitude)',
                               latitude='att(latitude)',
                               magnitude='att(mag)')


@earthquake_map.plot_data
def show_data(longitude, latitude, magnitude, style, state):
    x, y = state.m(longitude, latitude)
    return state.m.scatter(x,
                           y,
                           c=style.color,
                           s=magnitude**3,
                           alpha=0.5,
                           edgecolor='none')


@earthquake_map.plot_subset
def show_subset(longitude, latitude, magnitude, style, state):
    x, y = state.m(longitude, latitude)
    return state.m.scatter(x,
                           y,
                           c=style.color,
                           s=magnitude**3,
                           alpha=1.0,
                           edgecolor='none')
Пример #9
0
		self.plot_output = lasagna.glueviz.FijiViewer.plot_data(self, axes, source, y, contours, bounds)

	def plot_subset(self, axes, source, y, contours, style):
		self.subset_output = lasagna.glueviz.FijiViewer.plot_subset(self, axes, source, y, contours, style)


	def make_selector(self, roi, source, y):
		self.select_state = lasagna.glueviz.FijiViewer.make_selector(self, roi, source, y)
		return self.select_state
		

grid = custom_viewer('Grid Viewer',
                      Fiji = False,
                      show_nuclei = False,
                      source='att(file)',
                      contours='att(contour)',
                      bounds = 'att(bounds)',
                      sort_by = 'att',
                      padding = 50,
                      limit = 256)

@grid.setup
def a(self, axes):
	self.setup_output = lasagna.glueviz.FijiGridViewer.setup(self, axes)

@grid.plot_data
def b(self, axes):
	# set up ImagePlus
	self.plot_output = lasagna.glueviz.FijiGridViewer.plot_data(self, axes)

@grid.plot_subset
from glue import custom_viewer

GREEN = (229 / 255., 245 / 255., 224 / 255.)
BLUE = (222 / 255., 235 / 255., 247 / 255.)

earthquake_map = custom_viewer('Earthquake Map',
                               longitude='att(longitude)',
                               latitude='att(latitude)',
                               magnitude='att(mag)')


@earthquake_map.plot_data
def show_data(longitude, latitude, magnitude, style, state):
    x, y = state.m(longitude, latitude)
    return state.m.scatter(x, y, c=style.color, s=magnitude ** 3,
                           alpha=0.5, edgecolor='none')


@earthquake_map.plot_subset
def show_subset(longitude, latitude, magnitude, style, state):
    x, y = state.m(longitude, latitude)
    return state.m.scatter(x, y, c=style.color, s=magnitude ** 3,
                           alpha=1.0, edgecolor='none')


@earthquake_map.setup
def show_world(axes, state):
    from mpl_toolkits.basemap import Basemap

    m = Basemap(projection='mill', llcrnrlat=-80, urcrnrlat=80,
                llcrnrlon=-180, urcrnrlon=180, lat_ts=20,
Пример #11
0
from ..custom_viewer import (FormElement, NumberElement, ChoiceElement,
                             CustomViewer, CustomSubsetState, AttributeInfo,
                             FloatElement, TextBoxElement, SettingsOracle,
                             MissingSettingError, FrozenSettings)


def _make_widget(viewer):
    s = simple_session()
    return viewer._widget_cls(s)


viewer = custom_viewer('Testing Custom Viewer',
                       a=(0, 100),
                       b='att',
                       c='att(x)',
                       d=True,
                       e=False,
                       f=['a', 'b', 'c'],
                       g=OrderedDict(a=1, b=2, c=3),
                       h=64)

setup = MagicMock()
settings_changed = MagicMock()
plot_subset = MagicMock()
plot_data = MagicMock()
make_selector = MagicMock()
make_selector.return_value = MagicMock(spec=SubsetState)
make_selector().copy.return_value = MagicMock(spec=SubsetState)
make_selector().copy().to_mask.return_value = np.array([False, True, True])

Пример #12
0
    def plot_data(self, axes, source, y, contours, bounds):
        self.plot_output = lasagna.glueviz.FijiViewer.plot_data(self, axes, source, y, contours, bounds)

    def plot_subset(self, axes, source, y, contours, style):
        self.subset_output = lasagna.glueviz.FijiViewer.plot_subset(self, axes, source, y, contours, style)

    def make_selector(self, roi, source, y):
        self.select_state = lasagna.glueviz.FijiViewer.make_selector(self, roi, source, y)
        return self.select_state


grid = custom_viewer('Grid Viewer',
                     Fiji=False,
                     show_nuclei=False,
                     source='att(file)',
                     contours='att(contour)',
                     bounds='att(bounds)',
                     sort_by='att',
                     padding=30,
                     limit=64)


@grid.setup
def a(self, axes):
    self.setup_output = lasagna.glueviz.FijiGridViewer.setup(self, axes)


@grid.plot_data
def b(self, axes):
    # set up ImagePlus
    self.plot_output = lasagna.glueviz.FijiGridViewer.plot_data(self, axes)
Пример #13
0
from __future__ import print_function

from glue import custom_viewer
from glue.clients.ds9norm import DS9Normalize

import numpy as np

# define the galfa-hi viewer
median_rgb_viewer = custom_viewer('MEDIAN RGB Viewer',  # name of viewer
                   data = 'att',
                   red_center = (3621, 10353, 9920),        # center of redwave in pixels
                   blue_center = (3621, 10353, 3880),       # center of bluewave in pixels
                   green_center = (3621, 10353, 6830),      # center of greenwave in pixels
                   red_width =(1, 20, 5),               # width of R channel in pixels
                   blue_width =(1, 20, 5),              # width of G channel in pixels
                   green_width =(1, 20, 5),             # width of B channel in pixels
                   redraw_on_settings_change = True   # rerender data if settings change
                  )


@median_rgb_viewer.plot_data
def draw(axes, data, red_center, blue_center, green_center, red_width, blue_width, green_width, layer):
    """
    Make a 3 color image showing a data slice (g), slice - width (r), slice + width (b)
    data: 3D numpy arrays
    ra, dec, vlsr: 1D array, showing the grid points on each of the axis
    """
    if data is None or data.size == 0 or data.ndim != 3:
        return

    wavelength = 1e10*layer['Wave', :, 0, 0]
import pandas as pd

from glue import custom_viewer
from glue.core.subset import RoiSubsetState, CategorySubsetState

timelines = pd.read_csv('timelines.csv').set_index(['run_id', 'time']).unstack()

mario = custom_viewer('Mario Plot',
                      time=(0, 1580),
                      run=(0, 110),
                      x='att(x)',
                      y='att(y)',
                      full_path=False)
mario.redraw_on_settings_change = False


@mario.setup
def setup(axes):
    from skimage.io import imread
    bg = imread('bg.png')
    axes.imshow(bg, origin='upper',
                extent=[0, bg.shape[1] / 16, bg.shape[0] / 16, 0])
    axes.set_aspect('equal', adjustable='datalim')


@mario.settings_changed
def settings_changed(axes, time, run):
    sub = timelines.iloc[run]
    axes.plot(sub.x, sub.y, 'r',
              [sub.x.values[time]], [sub.y.values[time]], 'ko',
              lw=3, ms=20)
Пример #15
0
    return c * 9. / 5. + 32


"""Data factories take a filename as input and return a Data object"""
#@data_factory('JPEG Image')
#def jpeg_reader(file_name):
#    ...
#    return data
"""Extra qt clients"""
#qt_client(ClientClass)

from glue import custom_viewer

from matplotlib.colors import LogNorm

bball = custom_viewer('Shot Plot', x='att(x)', y='att(y)')


@bball.plot_data
def show_hexbin(axes, x, y):
    axes.hexbin(x, y, cmap='Purples', gridsize=40, norm=LogNorm(), mincnt=1)


@bball.plot_subset
def show_points(axes, x, y, style):
    axes.plot(x,
              y,
              'o',
              alpha=style.alpha,
              mec=style.color,
              mfc=style.color,
Пример #16
0
from __future__ import print_function

from glue import custom_viewer
from glue.clients.ds9norm import DS9Normalize

import numpy as np

# define the galfa-hi viewer
galfa_rgb_viewer = custom_viewer('GALFA-HI RGB Viewer',  # name of viewer
                   data = 'att',
                   center = (-600, 600),          # center of velocity in km/s
                   width =(1, 50),                 # width of RGB channel in km/s
                   redraw_on_settings_change = True   # rerender data if settings change
                  )


@galfa_rgb_viewer.plot_data
def draw(axes, data, center, width, layer):
    """
    Make a 3 color image showing a data slice (g), slice - width (r), slice + width (b)
    data: 3D numpy arrays
    ra, dec, vlsr: 1D array, showing the grid points on each of the axis
    """
    if data is None or data.size == 0 or data.ndim != 3:
        return

    velocity = layer['Velocity', :, 0, 0]
    dec = layer['Declination', 0, :, 0]
    ra = layer['Right Ascension', 0, 0, :]

    velo_pix = velocity[1] - velocity[0]
Пример #17
0
from ..custom_viewer import (FormElement, NumberElement,
                             ChoiceElement, CustomViewer,
                             CustomSubsetState, AttributeInfo,
                             FloatElement, TextBoxElement, SettingsOracle,
                             MissingSettingError, FrozenSettings)


def _make_widget(viewer):
    s = simple_session()
    return viewer._widget_cls(s)

viewer = custom_viewer('Testing Custom Viewer',
                       a=(0, 100),
                       b='att',
                       c='att(x)',
                       d=True,
                       e=False,
                       f=['a', 'b', 'c'],
                       g=OrderedDict(a=1, b=2, c=3),
                       h=64
                       )


setup = MagicMock()
settings_changed = MagicMock()
plot_subset = MagicMock()
plot_data = MagicMock()
make_selector = MagicMock()
make_selector.return_value = MagicMock(spec=SubsetState)
make_selector().copy.return_value = MagicMock(spec=SubsetState)
make_selector().copy().to_mask.return_value = np.array([False])
Пример #18
0
def test_custom_classes_dont_share_methods():
    """Regression test for #479"""
    a = custom_viewer('a')
    b = custom_viewer('b')
    assert a._custom_functions is not b._custom_functions
Пример #19
0
def test_custom_classes_dont_share_methods():
    """Regression test for #479"""
    a = custom_viewer('a')
    b = custom_viewer('b')
    assert a._custom_functions is not b._custom_functions
Пример #20
0
import pandas as pd
import numpy as np

from glue import custom_viewer
from glue.core.subset import RoiSubsetState, CategorySubsetState

timelines = pd.read_csv('timelines.csv').set_index(['run_id',
                                                    'time']).unstack()

mario = custom_viewer('Mario Plot',
                      time=(0, 1580),
                      run=(0, 110),
                      x='att(x)',
                      y='att(y)',
                      runid='att(run_id)',
                      full_path=False)
mario.redraw_on_settings_change = False


@mario.setup
def setup(axes):
    from skimage.io import imread
    bg = imread('bg.png')
    axes.imshow(bg,
                origin='upper',
                extent=[0, bg.shape[1] / 16, bg.shape[0] / 16, 0])
    axes.set_aspect('equal', adjustable='datalim')


@mario.settings_changed
def settings_changed(axes, time, run):