Skip to content
This repository has been archived by the owner on Jun 16, 2018. It is now read-only.

Commit

Permalink
Remove unused keywords and allow frame instances to be used for ``get…
Browse files Browse the repository at this point in the history
…_transform``
  • Loading branch information
astrofrog committed Dec 15, 2014
1 parent 56d54a8 commit b2eaf0d
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 7 deletions.
11 changes: 6 additions & 5 deletions wcsaxes/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ def get_xlabel(self):
def get_ylabel(self):
return self.coords[self._y_index].get_axislabel()

def get_coords_overlay(self, frame, equinox=None, obstime=None, coord_meta=None):
def get_coords_overlay(self, frame, coord_meta=None):

# Here we can't use get_transform because that deals with
# pixel-to-pixel transformations when passing a WCS object.
Expand All @@ -186,7 +186,7 @@ def get_coords_overlay(self, frame, equinox=None, obstime=None, coord_meta=None)
else:
if coord_meta is None:
coord_meta = get_coord_meta(frame)
transform = self._get_transform_no_transdata(frame, equinox=equinox, obstime=obstime)
transform = self._get_transform_no_transdata(frame)
coords = CoordinatesMap(self, transform=transform, coord_meta=coord_meta, frame_class=self.frame_class)

self._all_coords.append(coords)
Expand All @@ -201,7 +201,7 @@ def get_coords_overlay(self, frame, equinox=None, obstime=None, coord_meta=None)

return coords

def get_transform(self, frame, equinox=None, obstime=None):
def get_transform(self, frame):
"""
Return a transform from the specified frame to display coordinates.
Expand Down Expand Up @@ -230,10 +230,11 @@ def get_transform(self, frame, equinox=None, obstime=None):
``WCSAxes`` instance).
* ``'fk5'`` or ``'galactic'``: return a transformation from
the specified frame to the pixel/data coordinates.
* :class:`~astropy.coordinates.BaseCoordinateFrame` instance.
"""
return self._get_transform_no_transdata(frame, equinox=equinox, obstime=obstime).inverted() + self.transData
return self._get_transform_no_transdata(frame).inverted() + self.transData

def _get_transform_no_transdata(self, frame, equinox=None, obstime=None):
def _get_transform_no_transdata(self, frame):
"""
Return a transform from data to the specified frame
"""
Expand Down
36 changes: 36 additions & 0 deletions wcsaxes/tests/test_display_world_coordinates.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
from astropy.wcs import WCS
from astropy.extern import six
from astropy.tests.helper import pytest
from astropy.coordinates import FK5
from astropy.time import Time

from .test_images import BaseImageTests

Expand Down Expand Up @@ -58,6 +60,40 @@ def test_overlay_coords(self, tmpdir):

assert string_world3 == six.u('267.176 -28\xb045\'56" (world, overlay 1)')

overlay = ax.get_coords_overlay(FK5())

# Regression test for bug that caused format to always be taken from
# main world coordinates.
overlay[0].set_major_formatter('d.ddd')

# On some systems, fig.canvas.draw is not enough to force a draw, so we
# save to a temporary file.
fig.savefig(tmpdir.join('test3.png').strpath)

event5 = KeyEvent('test_pixel_coords', canvas, 'w')
fig.canvas.key_press_event(event4.key, guiEvent=event4)
# Test that it displays the overlay world coordinates
string_world4 = ax._display_world_coords(0.523412, 0.518311)

assert string_world4 == six.u('267.176 -28\xb045\'56" (world, overlay 2)')

overlay = ax.get_coords_overlay(FK5(equinox=Time("J2030")))

# Regression test for bug that caused format to always be taken from
# main world coordinates.
overlay[0].set_major_formatter('d.ddd')

# On some systems, fig.canvas.draw is not enough to force a draw, so we
# save to a temporary file.
fig.savefig(tmpdir.join('test4.png').strpath)

event6 = KeyEvent('test_pixel_coords', canvas, 'w')
fig.canvas.key_press_event(event5.key, guiEvent=event4)
# Test that it displays the overlay world coordinates
string_world5 = ax._display_world_coords(0.523412, 0.518311)

assert string_world5 == six.u('267.652 -28\xb046\'23" (world, overlay 3)')

def test_cube_coords(self, tmpdir):
wcs = WCS(self.cube_header)

Expand Down
13 changes: 12 additions & 1 deletion wcsaxes/transforms.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@
from astropy.wcs import WCS
from astropy.extern import six
from astropy.coordinates import (SkyCoord, frame_transform_graph,
SphericalRepresentation, UnitSphericalRepresentation)
SphericalRepresentation,
UnitSphericalRepresentation,
BaseCoordinateFrame)

from .wcs_utils import wcs_to_celestial_frame

Expand Down Expand Up @@ -173,6 +175,7 @@ def inverted(self):


class CoordinateTransform(CurvedTransform):

def __init__(self, input_system, output_system):
super(CoordinateTransform, self).__init__()
self._input_system_name = input_system
Expand All @@ -184,13 +187,21 @@ def __init__(self, input_system, output_system):
self.input_system = frame_transform_graph.lookup_name(self._input_system_name)
if self.input_system is None:
raise ValueError("Frame {0} not found".format(self._input_system_name))
elif isinstance(self._input_system_name, BaseCoordinateFrame):
self.input_system = self._input_system_name
else:
raise TypeError("input_system should be a WCS instance, string, or a coordinate frame instance")

if isinstance(self._output_system_name, WCS):
self.output_system = wcs_to_celestial_frame(self._output_system_name)
elif isinstance(self._output_system_name, six.string_types):
self.output_system = frame_transform_graph.lookup_name(self._output_system_name)
if self.output_system is None:
raise ValueError("Frame {0} not found".format(self._output_system_name))
elif isinstance(self._output_system_name, BaseCoordinateFrame):
self.output_system = self._output_system_name
else:
raise TypeError("output_system should be a WCS instance, string, or a coordinate frame instance")

if self.output_system == self.input_system:
self.same_frames = True
Expand Down
6 changes: 5 additions & 1 deletion wcsaxes/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

from astropy import units as u
from astropy.extern import six
from astropy.coordinates import BaseCoordinateFrame

# Modified from axis_artist, supports astropy.units

Expand Down Expand Up @@ -107,7 +108,10 @@ def get_coord_meta(frame):
if isinstance(frame, six.string_types):
frame = frame_transform_graph.lookup_name(frame)

names = list(frame().representation_component_names.keys())
if not isinstance(frame, BaseCoordinateFrame):
frame = frame()

names = list(frame.representation_component_names.keys())
coord_meta['name'] = names[:2]

except ImportError:
Expand Down

0 comments on commit b2eaf0d

Please sign in to comment.