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

Commit

Permalink
Fix get_transform for non-celestial WCS input that matches axes WCS
Browse files Browse the repository at this point in the history
  • Loading branch information
astrofrog committed Aug 19, 2015
1 parent 9b0c2fc commit 4fa4ecc
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 8 deletions.
31 changes: 23 additions & 8 deletions wcsaxes/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
CoordinateTransform)
from .coordinates_map import CoordinatesMap
from .utils import get_coord_meta
from .wcs_utils import wcs_to_celestial_frame
from .wcs_utils import wcs_to_celestial_frame, wcs_is_identical_world_system
from .frame import RectangularFrame
import numpy as np

Expand Down Expand Up @@ -298,19 +298,34 @@ def _get_transform_no_transdata(self, frame):

if isinstance(frame, WCS):

coord_in = wcs_to_celestial_frame(self.wcs)
coord_out = wcs_to_celestial_frame(frame)
if frame.is_celestial:

if coord_in == coord_out:
coord_in = wcs_to_celestial_frame(self.wcs)
coord_out = wcs_to_celestial_frame(frame)

return (WCSPixel2WorldTransform(self.wcs, slice=self.slices)
if coord_in == coord_out:

return (WCSPixel2WorldTransform(self.wcs, slice=self.slices)
+ WCSWorld2PixelTransform(frame))

else:

return (WCSPixel2WorldTransform(self.wcs, slice=self.slices)
+ CoordinateTransform(self.wcs, frame)
+ WCSWorld2PixelTransform(frame))

elif wcs_is_identical_world_system(self.wcs, frame):

return (WCSPixel2WorldTransform(self.wcs)
+ WCSWorld2PixelTransform(frame))

else:

return (WCSPixel2WorldTransform(self.wcs, slice=self.slices)
+ CoordinateTransform(self.wcs, frame)
+ WCSWorld2PixelTransform(frame))
raise ValueError("Could not determine conversion between the"
"WCS object specified and the WCS associated"
"with the axes")



elif frame == 'pixel':

Expand Down
40 changes: 40 additions & 0 deletions wcsaxes/wcs_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,3 +139,43 @@ def wcs_to_celestial_frame(wcs):
return frame
raise ValueError("Could not determine celestial frame corresponding to "
"the specified WCS object")


def wcs_is_identical_world_system(wcs1, wcs2):
"""
Determine whether two WCS objects have the same world coordinate system.
This helps us understand if we can go pixel1 -> world -> pixel2 by chaining
the two WCS objects.
"""

if wcs1.naxis != wcs2.naxis:
return False

for i in range(wcs1.naxis):

if wcs1.wcs.ctype[i] != wcs2.wcs.ctype[i]:
return False

if wcs1.wcs.axis_types[i] != wcs2.wcs.axis_types[i]:
return False

if wcs1.wcs.specsys != wcs2.wcs.specsys:
return False

if wcs1.wcs.radesys != wcs2.wcs.radesys:
return False

if (wcs1.wcs.equinox != wcs2.wcs.equinox and
np.isnan(wcs1.wcs.equinox) is not np.isnan(wcs2.wcs.equinox)):
return False

if (wcs1.wcs.restfrq != wcs2.wcs.restfrq and
np.isnan(wcs1.wcs.restfrq) is not np.isnan(wcs2.wcs.restfrq)):
return False

if (wcs1.wcs.restwav != wcs2.wcs.restwav and
np.isnan(wcs1.wcs.restwav) is not np.isnan(wcs2.wcs.restwav)):
return False

return True

0 comments on commit 4fa4ecc

Please sign in to comment.