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

DM-22234: Remove python_future dependencies and some extra cleanup #10

Merged
merged 9 commits into from
Nov 22, 2019
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
_build.*
.coverage
*.pyc
.sconf_temp
.sconsign.dblite
Expand Down
8 changes: 8 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
sudo: false
language: python
matrix:
include:
- python: '3.7'
install:
- pip install flake8
script: flake8
2 changes: 1 addition & 1 deletion SConstruct
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# -*- python -*-
from lsst.sconsUtils import scripts
scripts.BasicSConstruct("display_matplotlib")
scripts.BasicSConstruct("display_matplotlib", disableCc=True)
1 change: 0 additions & 1 deletion python/lsst/display/matplotlib/SConscript

This file was deleted.

84 changes: 48 additions & 36 deletions python/lsst/display/matplotlib/matplotlib.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,8 @@

#
# \file
# \brief Definitions to talk to matplotlib from python using the "afwDisplay" interface

from __future__ import absolute_import, division, print_function
# \brief Definitions to talk to matplotlib from python using the "afwDisplay"
# interface

import math
import sys
Expand All @@ -49,7 +48,6 @@

import lsst.afw.geom as afwGeom

# -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
#
# Set the list of backends which support _getEvent and thus interact()
#
Expand All @@ -66,7 +64,7 @@
matplotlibCtypes
except NameError:
matplotlibCtypes = {
afwDisplay.GREEN : "#00FF00", # noqa: ignore=E203
afwDisplay.GREEN: "#00FF00",
}

def mapCtype(ctype):
Expand Down Expand Up @@ -94,17 +92,19 @@ class DisplayImpl(virtualDevice.DisplayImpl):
or
%matplotlib osx

Apparently only qt supports Display.interact(); the list of interactive backends
is given by lsst.display.matplotlib.interactiveBackends
Apparently only qt supports Display.interact(); the list of interactive
backends is given by lsst.display.matplotlib.interactiveBackends
"""
def __init__(self, display, verbose=False,
interpretMaskBits=True, mtvOrigin=afwImage.PARENT, fastMaskDisplay=True,
reopenPlot=False, *args, **kwargs):
"""
Initialise a matplotlib display

@param fastMaskDisplay If True, only show the first bitplane that's set in each pixel
(e.g. if (SATURATED & DETECTED), ignore DETECTED)
@param fastMaskDisplay If True, only show the first bitplane
that's set in each pixel
(e.g. if (SATURATED & DETECTED), ignore
DETECTED)
Not really what we want, but a bit faster
@param interpretMaskBits Interpret the mask value under the cursor
@param mtvOrigin Display pixel coordinates with LOCAL origin
Expand All @@ -118,7 +118,7 @@ def __init__(self, display, verbose=False,
pyplot.close(display.frame)
self._figure = pyplot.figure(display.frame)
self._display = display
self._maskTransparency = {None : 0.7} # noqa: ignore=E203
self._maskTransparency = {None: 0.7}
self._interpretMaskBits = interpretMaskBits # interpret mask bits in mtv
self._fastMaskDisplay = fastMaskDisplay
self._mtvOrigin = mtvOrigin
Expand All @@ -133,7 +133,8 @@ def __init__(self, display, verbose=False,
self._scaleArgs = dict()
self._normalize = None
#
# Support self._erase(), reporting pixel/mask values, and zscale/minmax; set in mtv
# Support self._erase(), reporting pixel/mask values, and
# zscale/minmax; set in mtv
#
self._i_setImage(None)
#
Expand Down Expand Up @@ -191,7 +192,8 @@ def wait(self, prompt="[c(ontinue) p(db)] :", allowPdb=True):
Returns the string you entered

Useful when plotting from a programme that exits such as a processCcd
Any key except 'p' continues; 'p' puts you into pdb (unless allowPdb is False)
Any key except 'p' continues; 'p' puts you into pdb (unless allowPdb
is False)
"""
while True:
s = input(prompt)
Expand Down Expand Up @@ -220,12 +222,13 @@ def _mtv(self, image, mask=None, wcs=None, title=""):
title = str(title) if title else ""

#
# Save a reference to the image as it makes erase() easy and permits printing cursor values
# and minmax/zscale stretches. We also save XY0
# Save a reference to the image as it makes erase() easy and permits
# printing cursor values and minmax/zscale stretches. We also save XY0
#
self._i_setImage(image, mask, wcs)

# We need to know the pixel values to support e.g. 'zscale' and 'minmax', so do the scaling now
# We need to know the pixel values to support e.g. 'zscale' and
# 'minmax', so do the scaling now
if self._scaleArgs.get('algorithm'): # someone called self.scale()
self._i_scale(self._scaleArgs['algorithm'], self._scaleArgs['minval'], self._scaleArgs['maxval'],
self._scaleArgs['unit'], *self._scaleArgs['args'], **self._scaleArgs['kwargs'])
Expand Down Expand Up @@ -270,7 +273,8 @@ def format_coord(x, y, wcs=self._wcs, x0=self._xy0[0], y0=self._xy0[1],
return msg

ax.format_coord = format_coord
# Stop images from reporting their value as we've already printed it nicely
# Stop images from reporting their value as we've already printed it
# nicely
from matplotlib.image import AxesImage
for a in ax.mouseover_set:
if isinstance(a, AxesImage):
Expand Down Expand Up @@ -309,11 +313,12 @@ def _i_mtv(self, data, wcs, title, isMask):

colorNames.append(color)
#
# Convert those colours to RGBA so we can have per-mask-plane transparency
# and build a colour map
# Convert those colours to RGBA so we can have per-mask-plane
# transparency and build a colour map
#
# Pixels equal to 0 don't get set (as no bits are set), so leave them transparent
# and start our colours at [1] -- hence "i + 1" below
# Pixels equal to 0 don't get set (as no bits are set), so leave
# them transparent and start our colours at [1] --
# hence "i + 1" below
#
colors = mpColors.to_rgba_array(colorNames)
alphaChannel = 3 # the alpha channel; the A in RGBA
Expand Down Expand Up @@ -383,8 +388,8 @@ def _i_setImage(self, image, mask=None, wcs=None):
def _setImageColormap(self, cmap):
"""Set the colormap used for the image

cmap should be either the name of an attribute of pyplot.cm or an mpColors.Colormap
(e.g. "gray" or pyplot.cm.gray)
cmap should be either the name of an attribute of pyplot.cm or an
mpColors.Colormap (e.g. "gray" or pyplot.cm.gray)

"""
if not isinstance(cmap, mpColors.Colormap):
Expand Down Expand Up @@ -432,14 +437,18 @@ def _dot(self, symb, c, r, size, ctype,
fontFamily="helvetica", textAngle=None):
"""Draw a symbol at (col,row) = (c,r) [0-based coordinates]
Possible values are:
+ Draw a +
x Draw an x
* Draw a *
o Draw a circle
@:Mxx,Mxy,Myy Draw an ellipse with moments (Mxx, Mxy, Myy) (argument size is ignored)
An afwGeom.ellipses.Axes Draw the ellipse (argument size is ignored)
Any other value is interpreted as a string to be drawn. Strings obey the fontFamily (which may be extended
with other characteristics, e.g. "times bold italic". Text will be drawn rotated by textAngle
+ Draw a +
x Draw an x
* Draw a *
o Draw a circle
@:Mxx,Mxy,Myy Draw an ellipse with moments
(Mxx, Mxy, Myy) (argument size is ignored)
An afwGeom.ellipses.Axes Draw the ellipse (argument size is
timj marked this conversation as resolved.
Show resolved Hide resolved
ignored)

Any other value is interpreted as a string to be drawn. Strings obey the
fontFamily (which may be extended with other characteristics, e.g.
"times bold italic". Text will be drawn rotated by textAngle
(textAngle is ignored otherwise).
"""
if not ctype:
Expand All @@ -451,8 +460,9 @@ def _dot(self, symb, c, r, size, ctype,
if isinstance(symb, afwGeom.ellipses.Axes):
from matplotlib.patches import Ellipse

# Following matplotlib.patches.Ellipse documentation 'width' and 'height' are diameters while
# 'angle' is rotation in degrees (anti-clockwise)
# Following matplotlib.patches.Ellipse documentation 'width' and
# 'height' are diameters while 'angle' is rotation in degrees
# (anti-clockwise)
axis.add_artist(Ellipse((c + x0, r + y0), height=2*symb.getA(), width=2*symb.getB(),
angle=90.0 + math.degrees(symb.getTheta()),
edgecolor=mapCtype(ctype), facecolor='none'))
Expand All @@ -466,7 +476,6 @@ def _dot(self, symb, c, r, size, ctype,
for ds9Cmd in ds9Regions.dot(symb, c + x0, r + y0, size, fontFamily="helvetica", textAngle=None):
tmp = ds9Cmd.split('#')
cmd = tmp.pop(0).split()
comment = tmp.pop(0) if tmp else "" # noqa: ignore=F581

cmd, args = cmd[0], cmd[1:]

Expand Down Expand Up @@ -664,7 +673,8 @@ def __init__(self, minimum=0, dataRange=1, Q=8):
"""Initialise an object able to carry out an asinh mapping

@param minimum Minimum pixel value (default: 0)
@param dataRange Range of values for stretch if Q=0; roughly the linear part (default: 1)
@param dataRange Range of values for stretch if Q=0; roughly the
linear part (default: 1)
@param Q Softening parameter (default: 8)

See Lupton et al., PASP 116, 133
Expand All @@ -680,7 +690,8 @@ class AsinhZScaleNormalize(Normalize):
def __init__(self, image=None, Q=8):
"""Initialise an object able to carry out an asinh mapping

@param image image to use estimate minimum and dataRange using zscale (see AsinhNormalize)
@param image image to use estimate minimum and dataRange using zscale
(see AsinhNormalize)
@param Q Softening parameter (default: 8)

See Lupton et al., PASP 116, 133
Expand All @@ -698,7 +709,8 @@ def __init__(self, image=None, nSamples=1000, contrast=0.25):

@param image to be used to estimate the stretch
@param nSamples Number of data points to use (default: 1000)
@param contrast Control the range of pixels to display around the median (default: 0.25)
@param contrast Control the range of pixels to display around the
median (default: 0.25)
"""

Normalize.__init__(self)
Expand Down
9 changes: 9 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[flake8]
max-line-length = 110
max-doc-length = 79
ignore = E133, E226, E228, N802, N803, N806, N812, N815, N816, W504
exclude = __init__.py

[tool:pytest]
addopts = --flake8
flake8-ignore = E133 E226 E228 N802 N803 N806 N812 N815 N816 W504
2 changes: 1 addition & 1 deletion tests/SConscript
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# -*- python -*-
from lsst.sconsUtils import scripts
scripts.BasicSConscript.tests()
scripts.BasicSConscript.tests(pyList=[])
4 changes: 3 additions & 1 deletion tests/test_display_matplotlib.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@ def testSetAfwDisplayBackend(self):
afwDisplay.setDefaultBackend("matplotlib")

def testSetImageColormap(self):
"""This is a stand-in for an eventual testcase for changing image colormap
"""This is a stand-in for an eventual testcase for changing image
colormap.

The basic outline should look something like:

afwDisplay.setDefaultBackend("matplotlib")
Expand Down
1 change: 0 additions & 1 deletion ups/display_matplotlib.table
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
setupRequired(afw)
setupRequired(matplotlib)
setupRequired(python_future)

envPrepend(PYTHONPATH, ${PRODUCT_DIR}/python)