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

Fix bug that caused images to be over-pixellated when zooming in #1000

Merged
merged 5 commits into from
May 23, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
3 changes: 3 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ v0.8 (unreleased)
* Add the ability to change the foreground and background color for viewers.
[#988]

* Fixed a bug that caused images to appear over-pixellated on the edges when
zooming in. [#1000]

v0.7.3 (2016-05-04)
-------------------

Expand Down
6 changes: 5 additions & 1 deletion glue/tests/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ def make_skipper(module, label=None, version=None):
label='Astropy >= 0.4',
version='0.4')

MATPLOTLIB_GE_14_INSTALLED, requires_matplotlib_ge_14 = make_skipper('matplotlib',
label='Matplotlib >= 1.4',
version='1.4')

ASTRODENDRO_INSTALLED, requires_astrodendro = make_skipper('astrodendro')

SCIPY_INSTALLED, requires_scipy = make_skipper('scipy',
Expand Down Expand Up @@ -90,4 +94,4 @@ def make_file(contents, suffix, decompress=False):
try:
os.unlink(fname)
except WindowsError: # on Windows the unlink can fail
pass
pass
12 changes: 12 additions & 0 deletions glue/viewers/image/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -769,16 +769,28 @@ def check_update(self, *args):
For the Matplotlib client, see if the view window has changed enough
such that the images should be resampled
"""

logging.getLogger(__name__).debug("check update")

# We need to make sure we reapply the aspect ratio manually here,
# because at this point, if the user has zoomed in to a region with a
# different aspect ratio than the original view, Matplotlib has not yet
# enforced computed the final limits. This is an issue if we have
# requested square pixels.
self.axes.apply_aspect()

vw = _view_window(self._axes)

if vw != self._view_window:
logging.getLogger(__name__).debug("updating")
self._update_and_redraw()
self._view_window = vw

def _update_and_redraw(self):

self._update_data_plot()
self._update_subset_plots()

self._redraw()

@requires_data
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
38 changes: 38 additions & 0 deletions glue/viewers/image/qt/tests/test_regression.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# Miscellaneous regression tests for the image viewer

import pytest
import numpy as np

from glue.core import Data
from glue.viewers.image.qt import ImageWidget
from glue.core.tests.util import simple_session
from glue.tests.helpers import requires_matplotlib_ge_14


@requires_matplotlib_ge_14
@pytest.mark.mpl_image_compare(tolerance=1, savefig_kwargs={'dpi': 50})
def test_resample_on_zoom():

# For images where the aspect ratio of pixels is fixed to be square, when
# the user zooms in, the limits of the axes are actually changed twice by
# matplotlib - a second time when the aspect ratio is enforced. So we need
# to make sure that we update the modest_image when this is the case.

session = simple_session()

np.random.seed(12345)

data = Data(x=np.random.random((2048, 2048)), label='image')
session.data_collection.append(data)

image = ImageWidget(session=session)
image.add_data(data)

image.show()

image.axes.figure.canvas.key_press_event('o')
image.axes.figure.canvas.button_press_event(200, 200, 1)
image.axes.figure.canvas.motion_notify_event(400, 210)
image.axes.figure.canvas.button_release_event(400, 210, 1)

return image.axes.figure