Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add subset by single slice option #5

Open
wants to merge 55 commits into
base: refactor-scatter-image
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
55 commits
Select commit Hold shift + click to select a range
8334f6e
Started refactoring scatter viewer
astrofrog May 5, 2017
dba4c09
Added more tests
astrofrog May 5, 2017
e14dd09
Add a few more viewer tests
astrofrog May 5, 2017
96b6d27
Removed old scatter viewer
astrofrog May 5, 2017
2a814e0
Added SVG regression test
astrofrog May 5, 2017
b025e22
Move new scatter code into place
astrofrog May 5, 2017
c7bf374
Fix renaming of scatter viewer class, and remove debug print statements
astrofrog May 5, 2017
eabdb42
Add test for 2D datasets in scatter plot viewer
astrofrog May 7, 2017
46d4b97
Moved code common to Matplotlib viewers into glue/viewers/matplotlib …
astrofrog May 7, 2017
34e8085
Fix loading old session files for scatter plot
astrofrog May 7, 2017
0a6f825
Avoid duplicated code for session loading/saving for Matplotlib viewers
astrofrog May 16, 2017
85bd400
Added preliminary refactored image viewer
astrofrog May 19, 2017
92b24e8
Make it so that ComponentIDComboHelper can show specifically pixel or…
astrofrog May 19, 2017
300234c
Add a convenience 'selected_layer' property for DataViewer
astrofrog May 19, 2017
583eeff
Remove unused file
astrofrog May 19, 2017
eafb860
Fix selections and subsets
astrofrog May 19, 2017
5cdcf09
echo: add support for priorities
astrofrog May 19, 2017
916a517
Improvements to where CompositeArray is set up and fix display of sub…
astrofrog May 19, 2017
62fd5a3
Keep reference to keep_in_sync to make sure link is persistent
astrofrog May 19, 2017
6f32a4d
Added files needed for subset viewing
astrofrog May 19, 2017
d1dfb2c
Remove debug print statements
astrofrog Jun 16, 2017
b4a1355
Added CompositeArray.size
astrofrog Jun 16, 2017
2c56f33
Enable/disable color/colormaps selector depending on current mode
astrofrog Jun 16, 2017
88ef355
Implement different stretch functions
astrofrog Jun 16, 2017
2528f58
Use proper slice widgets with play/stop/etc buttons
astrofrog Jun 16, 2017
470ad0f
Make sure CompositeArray returns zeros if no layers are visible (rath…
astrofrog Jun 16, 2017
b1e9573
Set WCS when appropriate in image viewer
astrofrog Jun 16, 2017
ce5f25f
Show world coordinates in combo boxes and use pixel coordinates inter…
astrofrog Jun 16, 2017
e174e33
Added changelog entry
astrofrog Jun 16, 2017
adb5d7d
Implement overlay of scatter points on images
astrofrog Jun 16, 2017
0217caf
Reorder code
astrofrog Jun 16, 2017
b548721
Removed duplicate file
astrofrog Jun 16, 2017
f1900dc
Fix mistake in _layer_state_cls
astrofrog Jun 16, 2017
7ff212e
Refer to stretch by name until the very end
astrofrog Jun 16, 2017
b254afd
Added standard viewer tests
astrofrog Jun 16, 2017
486a4ae
TEMP
astrofrog Jun 16, 2017
94f3ea3
Make keep_in_sync use weak references to avoid circular references
astrofrog Jun 16, 2017
df7fbae
WIP
astrofrog Jun 16, 2017
91a2f94
Allow multiple data layers to be present for a single dataset, which …
astrofrog Jun 16, 2017
1190b03
echo: fixes
astrofrog Jun 16, 2017
1bf8d1c
Make it possible to disable syncing of layer color and alpha with glo…
astrofrog Jun 16, 2017
d5ed6a1
Fix reading of old session files with non-RGB and non-cube datasets (…
astrofrog Jun 16, 2017
0fc5e0d
Add test and fix backward compatibility for viewing cubes
astrofrog Jun 16, 2017
3d627c7
Fix backward-compatibility with RGB images
astrofrog Jun 16, 2017
6d29c3b
Fix remaining image tests
astrofrog Jun 16, 2017
a85dc69
Spectrum tool is mostly fixed, but at the moment will just use the fi…
astrofrog Jun 18, 2017
c3055ad
Patch PV slicer so that it works at a basic level
astrofrog Jun 18, 2017
8363ee0
Make viewers have the same default size as before, and move over a re…
astrofrog Jun 18, 2017
08586a2
Allow negative default_index in update_combobox (count from end as in…
astrofrog Jun 18, 2017
b944892
Make it possible to initialize coords when initializing Data
astrofrog Jun 18, 2017
6f47ead
Added some tests for the new ImageViewer
astrofrog Jun 18, 2017
0a0dd52
Added a test for when x_att_world and y_att_world are set to the same…
astrofrog Jun 18, 2017
c2d4b79
Fix some warnings that occurred during tests
astrofrog Jun 18, 2017
d8f01d9
Fix all existing image tests
astrofrog Jun 18, 2017
594b079
Add subset by single slice option
AnnaBeers Jun 19, 2017
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ v0.11.0 (unreleased)
references, which in turn caused some callback functions to not be
cleaned up. [#1281]

* Rewrote the histogram viewer to use the new state infrastructure. This
significantly simplifies the actual histogram viewer code both in terms
of number of lines and in terms of the number of connections/callbacks
that need to be set up manually. [#1278]
* Rewrote the histogram, scatter, and image viewers to use the new state
infrastructure. This significantly simplifies the actual histogram viewer code
both in terms of number of lines and in terms of the number of
connections/callbacks that need to be set up manually. [#1278, #1289]

v0.10.4 (2017-05-23)
--------------------
Expand Down
2 changes: 1 addition & 1 deletion doc/customizing_guide/toolbar.rst
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ we defined above). There are currently two main classes available for toolbars:
* :class:`~glue.viewers.common.qt.toolbar.BasicToolbar`: this is the most basic
kind of toolbar - it comes with no tools by default.

* :class:`~glue.viewers.common.qt.mpl_toolbar.MatplotlibViewerToolbar`: this is
* :class:`~glue.viewers.matplotlib.qt.toolbar.MatplotlibViewerToolbar`: this is
a subclass of :class:`~glue.viewers.common.qt.toolbar.BasicToolbar` that
includes the standard Matplotlib buttons by default (home, zoom, pan, etc.).
This toolbar can only be used if your data viewer includes a Matplotlib canvas
Expand Down
2 changes: 1 addition & 1 deletion doc/developer_guide/api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ Viewers
:no-inheritance-diagram:
:inherited-members:

.. automodapi:: glue.viewers.common.qt.mpl_toolbar
.. automodapi:: glue.viewers.matplotlib.qt.toolbar
:no-inheritance-diagram:
:inherited-members:

Expand Down
28 changes: 14 additions & 14 deletions doc/python_guide/data_viewer_options.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ For example::

from glue.core import Data, DataCollection
from glue.app.qt.application import GlueApplication
from glue.viewers.scatter.qt import ScatterWidget
from glue.viewers.scatter.qt import ScatterViewer
import numpy as np

# create some data
Expand All @@ -20,7 +20,7 @@ For example::
ga = GlueApplication(dc)

# plot x vs y, flip the x axis, log-scale y axis
scatter = ga.new_data_viewer(ScatterWidget)
scatter = ga.new_data_viewer(ScatterViewer)
scatter.add_data(d)
scatter.xatt = d.id['x']
scatter.yatt = d.id['y']
Expand All @@ -38,21 +38,21 @@ Here are the settings associated with each data viewer:

.. currentmodule:: glue.viewers.scatter.qt.viewer_widget

:class:`Scatter Plots <ScatterWidget>`
:class:`Scatter Plots <ScatterViewer>`
--------------------------------------

.. autosummary::
~ScatterWidget.xlog
~ScatterWidget.ylog
~ScatterWidget.xflip
~ScatterWidget.yflip
~ScatterWidget.xmin
~ScatterWidget.xmax
~ScatterWidget.ymin
~ScatterWidget.ymax
~ScatterWidget.hidden
~ScatterWidget.xatt
~ScatterWidget.yatt
~ScatterViewer.xlog
~ScatterViewer.ylog
~ScatterViewer.xflip
~ScatterViewer.yflip
~ScatterViewer.xmin
~ScatterViewer.xmax
~ScatterViewer.ymin
~ScatterViewer.ymax
~ScatterViewer.hidden
~ScatterViewer.xatt
~ScatterViewer.yatt

.. currentmodule:: glue.viewers.image.qt.viewer_widget

Expand Down
14 changes: 7 additions & 7 deletions glue/app/qt/application.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@
from glue.app.qt.mdi_area import GlueMdiArea, GlueMdiSubWindow
from glue.app.qt.layer_tree_widget import PlotAction, LayerTreeWidget
from glue.app.qt.preferences import PreferencesDialog
from glue.viewers.common.qt.mpl_widget import defer_draw
from glue.viewers.matplotlib.qt.widget import defer_draw
from glue.viewers.common.qt.data_viewer import DataViewer
from glue.viewers.image.qt import ImageWidget
from glue.viewers.scatter.qt import ScatterWidget
from glue.viewers.scatter.qt import ScatterViewer
from glue.viewers.image_new.qt import ImageViewer
from glue.utils import nonpartial
from glue.utils.qt import (pick_class, GlueTabBar,
set_cursor_cm, messagebox_on_error, load_ui)
Expand Down Expand Up @@ -675,10 +675,10 @@ def choose_new_data_viewer(self, data=None):

from glue.config import qt_client

if data and data.ndim == 1 and ScatterWidget in qt_client.members:
default = ScatterWidget
elif data and data.ndim > 1 and ImageWidget in qt_client.members:
default = ImageWidget
if data and data.ndim == 1 and ScatterViewer in qt_client.members:
default = ScatterViewer
elif data and data.ndim > 1 and ImageViewer in qt_client.members:
default = ImageViewer
else:
default = None

Expand Down
12 changes: 6 additions & 6 deletions glue/app/qt/tests/test_application.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
from glue.tests.helpers import requires_ipython
from glue.utils.qt import process_dialog
from glue.viewers.image.qt import ImageWidget
from glue.viewers.scatter.qt import ScatterWidget
from glue.viewers.scatter.qt import ScatterViewer
from glue.viewers.histogram.qt import HistogramViewer


Expand Down Expand Up @@ -136,20 +136,20 @@ def test_new_data_viewer_cancel(self):
def test_new_data_viewer(self):
with patch('glue.app.qt.application.pick_class') as pc:

pc.return_value = ScatterWidget
pc.return_value = ScatterViewer

ct = len(self.app.current_tab.subWindowList())

self.app.choose_new_data_viewer()
assert len(self.app.current_tab.subWindowList()) == ct + 1

def test_move(self):
viewer = self.app.new_data_viewer(ScatterWidget)
viewer = self.app.new_data_viewer(ScatterViewer)
viewer.move(10, 20)
assert viewer.position == (10, 20)

def test_resize(self):
viewer = self.app.new_data_viewer(ScatterWidget)
viewer = self.app.new_data_viewer(ScatterViewer)
viewer.viewer_size = (100, 200)
assert viewer.viewer_size == (100, 200)

Expand All @@ -164,7 +164,7 @@ def test_new_data_defaults(self):

self.app.choose_new_data_viewer(data=d1)
args, kwargs = pc.call_args
assert kwargs['default'] is ScatterWidget
assert kwargs['default'] is ScatterViewer

self.app.choose_new_data_viewer(data=d2)
args, kwargs = pc.call_args
Expand Down Expand Up @@ -297,7 +297,7 @@ def test_scatter_viewer(self):
d = Data(label='x', x=[1, 2, 3, 4, 5], y=[2, 3, 4, 5, 6])
dc = DataCollection([d])
app = GlueApplication(dc)
w = app.new_data_viewer(ScatterWidget, data=d)
w = app.new_data_viewer(ScatterViewer, data=d)
self.check_clone(app)

s1 = dc.new_subset_group()
Expand Down
6 changes: 3 additions & 3 deletions glue/app/qt/tests/test_preferences.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from qtpy import QtWidgets
from glue.app.qt.preferences import PreferencesDialog
from glue.app.qt import GlueApplication
from glue.viewers.scatter.qt import ScatterWidget
from glue.viewers.scatter.qt import ScatterViewer
from glue.viewers.image.qt import ImageWidget
from glue.viewers.histogram.qt import HistogramViewer
from glue.plugins.dendro_viewer.qt.viewer_widget import DendroWidget
Expand Down Expand Up @@ -307,7 +307,7 @@ def test_foreground_background_settings():
# Make sure that settings change existing viewers, so we create a bunch of
# viewers here.

scatter1 = app.new_data_viewer(ScatterWidget)
scatter1 = app.new_data_viewer(ScatterViewer)
scatter1.add_data(d_1d)

image1 = app.new_data_viewer(ImageWidget)
Expand Down Expand Up @@ -354,7 +354,7 @@ def test_foreground_background_settings():

# Now make sure that new viewers also inherit these settings

scatter2 = app.new_data_viewer(ScatterWidget)
scatter2 = app.new_data_viewer(ScatterViewer)
scatter2.add_data(d_1d)

image2 = app.new_data_viewer(ImageWidget)
Expand Down
2 changes: 1 addition & 1 deletion glue/core/component_id.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from glue.core.subset import InequalitySubsetState


__all__ = ['PixelComponentID', 'ComponentID', 'PixelComponentID', 'ComponentIDDict', 'ComponentIDList']
__all__ = ['ComponentID', 'PixelComponentID', 'ComponentIDDict', 'ComponentIDList']

# access to ComponentIDs via .item[name]

Expand Down
4 changes: 2 additions & 2 deletions glue/core/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ class Data(object):
See also: :ref:`data_tutorial`
"""

def __init__(self, label="", **kwargs):
def __init__(self, label="", coords=None, **kwargs):
"""

:param label: label for data
Expand All @@ -72,7 +72,7 @@ def __init__(self, label="", **kwargs):
Extra array-like keywords are extracted into components
"""
# Coordinate conversion object
self.coords = Coordinates()
self.coords = coords or Coordinates()
self._shape = ()

# Components
Expand Down
7 changes: 0 additions & 7 deletions glue/core/layer_artist.py
Original file line number Diff line number Diff line change
Expand Up @@ -294,15 +294,8 @@ def _duplicate(self, artist):
return True
return False

def _check_duplicate(self, artist):
"""Raise an error if this artist is a duplicate"""
if self._duplicate(artist):
raise ValueError("Already have an artist for this type "
"and data")

def append(self, artist):
"""Add a LayerArtist to this collection"""
self._check_duplicate(artist)
self.artists.append(artist)
artist.zorder = max(a.zorder for a in self.artists) + 1
self._notify()
Expand Down
32 changes: 30 additions & 2 deletions glue/core/qt/data_combo_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,16 +41,23 @@ class ComponentIDComboHelper(HubListener):
Show numeric components
categorical : bool, optional
Show categorical components
pixel_coord : bool, optional
Show pixel coordinate components
world_coord : bool, optional
Show world coordinate components
"""

def __init__(self, component_id_combo, data_collection=None, data=None,
visible=True, numeric=True, categorical=True, default_index=0):
visible=True, numeric=True, categorical=True,
pixel_coord=False, world_coord=False, default_index=0,):

super(ComponentIDComboHelper, self).__init__()

self._visible = visible
self._numeric = numeric
self._categorical = categorical
self._pixel_coord = pixel_coord
self._world_coord = world_coord
self._component_id_combo = component_id_combo

if data is None:
Expand Down Expand Up @@ -103,6 +110,24 @@ def categorical(self, value):
self._categorical = value
self.refresh()

@property
def pixel_coord(self):
return self._pixel_coord

@pixel_coord.setter
def pixel_coord(self, value):
self._pixel_coord = value
self.refresh()

@property
def world_coord(self):
return self._world_coord

@world_coord.setter
def world_coord(self, value):
self._world_coord = value
self.refresh()

def append_data(self, data, refresh=True):

if self._manual_data:
Expand Down Expand Up @@ -187,7 +212,10 @@ def refresh(self):
component_ids = []
for cid in all_component_ids:
comp = data.get_component(cid)
if (comp.numeric and self.numeric) or (comp.categorical and self.categorical):
if ((comp.numeric and self.numeric) or
(comp.categorical and self.categorical) or
(cid in data.pixel_component_ids and self.pixel_coord) or
(cid in data.world_component_ids and self.world_coord)):
component_ids.append(cid)

label_data.extend([(cid.label, cid) for cid in component_ids])
Expand Down
2 changes: 0 additions & 2 deletions glue/core/qt/layer_artist_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,6 @@ def on_selection_change(self, layer_artist):
self.layer_options_layout.setCurrentWidget(self.empty)



class QtLayerArtistContainer(LayerArtistContainer):

"""A subclass of LayerArtistContainer that dispatches to a
Expand All @@ -351,7 +350,6 @@ def __init__(self):
self.model.modelReset.connect(nonpartial(self._notify))

def append(self, artist):
self._check_duplicate(artist)
self.model.add_artist(0, artist)
artist.zorder = max(a.zorder for a in self.artists) + 1
assert self.artists[0] is artist
Expand Down
4 changes: 1 addition & 3 deletions glue/core/state_objects.py
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ def update_values(self, use_default_modifiers=False, **properties):
percentile = self.percentile or 100
log = self.log or False

if percentile == 'Custom' or self.data is None:
if percentile == 'Custom' or not hasattr(self, 'data') or self.data is None:

self.set(percentile=percentile, log=log)

Expand Down Expand Up @@ -359,8 +359,6 @@ def __init__(self, *args, **kwargs):
else:
self._common_n_bin = None

print(self._cache)

def _apply_common_n_bin(self):
for att in self._cache:
cmp = self.data.get_component(att)
Expand Down
7 changes: 6 additions & 1 deletion glue/core/state_path_patches.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,14 @@ glue.clients.layer_artist.ScatterLayerArtist -> glue.viewers.scatter.layer_artis
glue.clients.layer_artist.ImageLayerArtist -> glue.viewers.image.layer_artist.ImageLayerArtist
glue.clients.layer_artist.HistogramLayerArtist -> glue.viewers.histogram.layer_artist.HistogramLayerArtist
glue.clients.ds9norm.DS9Normalize -> glue.viewers.image.ds9norm.DS9Normalize
glue.qt.widgets.scatter_widget.ScatterWidget -> glue.viewers.scatter.qt.ScatterWidget
glue.qt.widgets.scatter_widget.ScatterWidget -> glue.viewers.scatter.qt.ScatterViewer
glue.qt.widgets.image_widget.ImageWidget -> glue.viewers.image.qt.ImageWidget
glue.qt.widgets.histogram_widget.HistogramWidget -> glue.viewers.histogram.qt.data_viewer.HistogramViewer
glue.qt.glue_application.GlueApplication -> glue.app.qt.application.GlueApplication
glue_vispy_viewers.common.toolbar.PatchedElementSubsetState -> glue.core.subset.ElementSubsetState
glue.viewers.histogram.qt.viewer_widget.HistogramWidget -> glue.viewers.histogram.qt.data_viewer.HistogramViewer
glue.viewers.scatter.qt.viewer_widget.ScatterWidget -> glue.viewers.scatter.qt.data_viewer.ScatterViewer
glue.viewers.image.qt.viewer_widget.ImageWidget -> glue.viewers.image_new.qt.data_viewer.ImageViewer
glue.viewers.image.layer_artist.ImageLayerArtist -> glue.viewers.image_new.layer_artist.ImageLayerArtist
glue.viewers.image.layer_artist.SubsetImageLayerArtist -> glue.viewers.image_new.layer_artist.ImageSubsetLayerArtist
glue.viewers.image.ds9norm.DS9Normalize -> glue.viewers.image_new.compat.DS9Compat
Loading