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

Commit

Permalink
Implement a function to do offset coordinates
Browse files Browse the repository at this point in the history
  • Loading branch information
astrofrog committed Jun 2, 2015
1 parent 95bf428 commit ceb746e
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions wcsaxes/offset.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
from astropy.wcs import WCS
from astropy.wcs.utils import skycoord_to_pixel, proj_plane_pixel_scales


def linear_offset_coords(wcs, center):
"""
Returns a locally linear offset coordinate system.
Given a 2-d celestial WCS object and a central coordinate, return a WCS
that describes an 'offset' coordinate system, assuming that the
coordinates are locally linear (that is, the grid lines of this offset
coordinate system are always aligned with the pixel coordinates, and
distortions from spherical projections and distortion terms are not taken
into account)
Parameters
----------
wcs : `~astropy.wcs.WCS`
The original WCS, which should be a 2-d celestial WCS
center : `~astropy.coordinates.SkyCoord`
The coordinates on which the offset coordinate system should be
centered.
"""

# Convert center to pixel coordinates
xp, yp = skycoord_to_pixel(center, wcs)

# Set up new WCS
new_wcs = WCS(naxis=2)
new_wcs.wcs.crpix = xp + 1, yp + 1
new_wcs.wcs.crval = 0., 0.
new_wcs.wcs.cdelt = proj_plane_pixel_scales(wcs)
new_wcs.wcs.ctype = 'XOFFSET', 'YOFFSET'
new_wcs.wcs.cunit = 'deg', 'deg'

return new_wcs

0 comments on commit ceb746e

Please sign in to comment.