/usr/lib/python3/dist-packages/reproject/wcs_utils.py is in python3-reproject 0.3.1-4.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 | # Licensed under a 3-clause BSD style license - see LICENSE.rst
"""
WCS-related utilities
"""
from __future__ import (absolute_import, division, print_function,
unicode_literals)
from astropy import units as u
from astropy.coordinates import UnitSphericalRepresentation
from astropy.wcs.utils import wcs_to_celestial_frame
from astropy.wcs import WCS
__all__ = ['convert_world_coordinates']
def convert_world_coordinates(lon_in, lat_in, wcs_in, wcs_out):
"""
Convert longitude/latitude coordinates from an input frame to an output
frame.
Parameters
----------
lon_in, lat_in : `~numpy.ndarray`
The longitude and latitude to convert
wcs_in, wcs_out : tuple or `~astropy.wcs.WCS`
The input and output frames, which can be passed either as a tuple of
``(frame, lon_unit, lat_unit)`` or as a `~astropy.wcs.WCS` instance.
Returns
-------
lon_out, lat_out : `~numpy.ndarray`
The output longitude and latitude
"""
if isinstance(wcs_in, WCS):
# Extract the celestial component of the WCS in (lon, lat) order
wcs_in = wcs_in.celestial
frame_in = wcs_to_celestial_frame(wcs_in)
lon_in_unit = u.Unit(wcs_in.wcs.cunit[0])
lat_in_unit = u.Unit(wcs_in.wcs.cunit[1])
else:
frame_in, lon_in_unit, lat_in_unit = wcs_in
if isinstance(wcs_out, WCS):
# Extract the celestial component of the WCS in (lon, lat) order
wcs_out = wcs_out.celestial
frame_out = wcs_to_celestial_frame(wcs_out)
lon_out_unit = u.Unit(wcs_out.wcs.cunit[0])
lat_out_unit = u.Unit(wcs_out.wcs.cunit[1])
else:
frame_out, lon_out_unit, lat_out_unit = wcs_out
data = UnitSphericalRepresentation(lon_in * lon_in_unit,
lat_in * lat_in_unit)
coords_in = frame_in.realize_frame(data)
coords_out = coords_in.transform_to(frame_out)
lon_out = coords_out.represent_as('unitspherical').lon.to(lon_out_unit).value
lat_out = coords_out.represent_as('unitspherical').lat.to(lat_out_unit).value
return lon_out, lat_out
|