Skip to content

Commit

Permalink
Merge b7df1d6 into 2be6a09
Browse files Browse the repository at this point in the history
  • Loading branch information
sosey committed Mar 1, 2017
2 parents 2be6a09 + b7df1d6 commit dc34c0d
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 14 deletions.
3 changes: 3 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
ersion 0.7.2dev (unreleased)
-----------------------------
- view method now supports loading cubes when there are 3 dimension in the given array
- logic bug in ds9 class init updated to warn when user specified target doesn't exist


version 0.7.1 (released)
-----------------------------
Expand Down
45 changes: 31 additions & 14 deletions imexam/ds9_viewer.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ class ds9(object):
_tmp_dir = ""
_process_list = list()

def __init__(self, target=None, path=None, wait_time=5,
def __init__(self, target="", path="", wait_time=5,
quit_ds9_on_del=True):
"""starter.
Expand Down Expand Up @@ -202,11 +202,10 @@ def __init__(self, target=None, path=None, wait_time=5,
self._ds9_process = None
self._ds9_path = None

if path is None:
if not target and not path:
self._ds9_path = util.find_ds9()
if not self._ds9_path:
if self._ds9_path is None:
raise OSError("Could not find ds9 executable on your path")

else:
self._ds9_path = path

Expand All @@ -228,8 +227,20 @@ def __init__(self, target=None, path=None, wait_time=5,
os.environ['XPA_METHOD'] = self._xpa_method

else:
# just register with the target the user provided
self._xpa_name = target
# check to see if the target exists
active = util.list_active_ds9()
if target in list(active):
self._xpa_name = target
else:
# see if they used a title and not the xpa_method
# the title is the first item in the tuple for each key
for window in active.values():
if target in window:
self._xpa_name = target
if not self._xpa_name:
print("\nDS9 target: {0:s} doesn't exist.\n{1}".format(target,
active))
raise ValueError("Please choose an existing target.")

# xpa_name sets the template for the get and set commands
self.xpa = XPA(self._xpa_name)
Expand Down Expand Up @@ -1703,9 +1714,17 @@ def view(self, img):
if img.dtype.type == np.bool8:
img = img.astype(np.uint8)

try:
img.shape = img.shape[-2:]
except:
# arrays of 1 through 3 dimensions
dim = img.ndim
if dim == 2:
(ydim, xdim) = img.shape
dims = "[xdim={0:d},ydim={1:d},".format(xdim, ydim)
elif dim == 3:
(zdim, ydim, xdim) = img.shape
dims = "[xdim={0:d},ydim={1:d},zdim={2:d},".format(xdim,
ydim,
zdim)
else:
raise UnsupportedImageShapeException(repr(img.shape))

if img.dtype.byteorder in ["=", "|"]:
Expand All @@ -1717,17 +1736,15 @@ def view(self, img):

endianness = {">": ",arch=bigendian",
"<": ",arch=littleendian"}[byteorder]
(ydim, xdim) = img.shape

arr_str = img.tostring()

try:
bitpix = self._ImgCode[img.dtype.name]
except KeyError as e:
raise UnsupportedDatatypeException(e)

option = ("[xdim={0:d},ydim={1:d},"
"bitpix={2:d}{3:s}]".format(xdim, ydim,
bitpix, endianness))
option = (dims + "bitpix={0:d}{1:s}]".format(bitpix, endianness))
try:
self.set("array " + option, arr_str)
self._set_frameinfo()
Expand Down Expand Up @@ -1769,7 +1786,7 @@ def zoom(self, par="to fit"):

def show_xpa_commands(self):
"""Print the available XPA commands."""
print(self.get()) # with no arguments supplied, XPA returns options
print(self.get('')) # with no arguments supplied, XPA returns options

def reopen(self):
"""Reopen a closed window."""
Expand Down

0 comments on commit dc34c0d

Please sign in to comment.