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-7250: Port to Python 3 #2

Merged
merged 2 commits into from
Aug 19, 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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion python/lsst/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
import pkgutil, lsstimport
import pkgutil
import lsstimport
__path__ = pkgutil.extend_path(__path__, __name__)
3 changes: 2 additions & 1 deletion python/lsst/display/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
import pkgutil, lsstimport
import pkgutil
import lsstimport
__path__ = pkgutil.extend_path(__path__, __name__)
12 changes: 6 additions & 6 deletions python/lsst/display/ds9/__init__.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
#
#
# LSST Data Management System
# Copyright 2008, 2009, 2010 LSST Corporation.
#
#
# This product includes software developed by the
# LSST Project (http://www.lsst.org/).
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the LSST License Statement and
# the GNU General Public License along with this program. If not,
#
# You should have received a copy of the LSST License Statement and
# the GNU General Public License along with this program. If not,
# see <http://www.lsstcorp.org/LegalNotices/>.
#
from .version import *
Expand Down
32 changes: 27 additions & 5 deletions python/lsst/display/ds9/ds9.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@
## \brief Definitions to talk to ds9 from python

from __future__ import absolute_import, division, print_function
from builtins import str
from builtins import next
from builtins import range
from builtins import object
from past.builtins import long

import os
import re
Expand All @@ -46,9 +51,11 @@
try:
needShow
except NameError:
needShow = True; # Used to avoid a bug in ds9 5.4
needShow = True # Used to avoid a bug in ds9 5.4

## An error talking to ds9


class Ds9Error(IOError):
"""Some problem talking to ds9"""

Expand All @@ -59,6 +66,7 @@ class Ds9Error(IOError):

#-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-


def getXpaAccessPoint():
"""Parse XPA_PORT and send return an identifier to send ds9 commands there, instead of "ds9"
If you don't have XPA_PORT set, the usual xpans tricks will be played when we return "ds9".
Expand All @@ -75,6 +83,7 @@ def getXpaAccessPoint():

return "ds9"


def ds9Version():
"""Return the version of ds9 in use, as a string"""
try:
Expand Down Expand Up @@ -115,7 +124,7 @@ def set(self, size, silent=True):
size = XPA_SZ_LINE - 5

if size > XPA_SZ_LINE:
print ("xpa silently hardcodes a limit of %d for buffer sizes (you asked for %d) " %
print ("xpa silently hardcodes a limit of %d for buffer sizes (you asked for %d) " %
(XPA_SZ_LINE, size), file=sys.stderr)
self.set(-1) # use max buffersize
return
Expand Down Expand Up @@ -151,9 +160,11 @@ def flush(self, silent=True):

cmdBuffer = Buffer(0)


def selectFrame(frame):
return "frame %d" % (frame)


def ds9Cmd(cmd=None, trap=True, flush=False, silent=True, frame=None, get=False):
"""Issue a ds9 command, raising errors as appropriate"""

Expand Down Expand Up @@ -193,6 +204,7 @@ def ds9Cmd(cmd=None, trap=True, flush=False, silent=True, frame=None, get=False)
elif not silent:
print("Caught ds9 exception processing command \"%s\": %s" % (cmd, e), file=sys.stderr)


def initDS9(execDs9=True):
try:
xpa.reset()
Expand Down Expand Up @@ -239,14 +251,18 @@ def initDS9(execDs9=True):

raise Ds9Error


class Ds9Event(interface.Event):
"""An event generated by a mouse or key click on the display"""

def __init__(self, k, x, y):
interface.Event.__init__(self, k, x, y)

#-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-


class DisplayImpl(virtualDevice.DisplayImpl):

def __init__(self, display, verbose=False, *args, **kwargs):
virtualDevice.DisplayImpl.__init__(self, display, verbose)

Expand Down Expand Up @@ -307,7 +323,7 @@ def _mtv(self, image, mask=None, wcs=None, title=""):
planeList = range(nMaskPlanes)
usedPlanes = long(afwMath.makeStatistics(mask, afwMath.SUM).getValue())
mask1 = mask.Factory(mask.getDimensions()) # Mask containing just one bitplane

colorGenerator = self.display.maskColorGenerator(omitBW=True)
for p in planeList:
if planes.get(p):
Expand All @@ -331,6 +347,7 @@ def _mtv(self, image, mask=None, wcs=None, title=""):
#
# Graphics commands
#

def _buffer(self, enable=True):
if enable:
cmdBuffer.pushSize()
Expand Down Expand Up @@ -377,6 +394,7 @@ def _drawLines(self, points, ctype):
#
# Set gray scale
#

def _scale(self, algorithm, min, max, unit, *args, **kwargs):
if algorithm:
ds9Cmd("scale %s" % algorithm, frame=self.display.frame)
Expand All @@ -391,6 +409,7 @@ def _scale(self, algorithm, min, max, unit, *args, **kwargs):
#
# Zoom and Pan
#

def _zoom(self, zoomfac):
"""Zoom frame by specified amount"""

Expand Down Expand Up @@ -420,9 +439,11 @@ def _getEvent(self):

k = vals.pop(0)
try:
x = float(vals[0]); y = float(vals[1])
x = float(vals[0])
y = float(vals[1])
except:
x = float("NaN"); y = float("NaN")
x = float("NaN")
y = float("NaN")

return Ds9Event(k, x, y)

Expand All @@ -433,6 +454,7 @@ def _getEvent(self):
except NameError:
haveGzip = not os.system("gzip < /dev/null > /dev/null 2>&1") # does gzip work?


def _i_mtv(data, wcs, title, isMask):
"""Internal routine to display an Image or Mask on a DS9 display"""

Expand Down