/usr/lib/python3/dist-packages/reproject/healpix/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 | import tempfile
import numpy as np
from astropy.io.fits import TableHDU, BinTableHDU
from astropy.extern import six
from astropy.coordinates import BaseCoordinateFrame, frame_transform_graph, Galactic, ICRS
FRAMES = {
'g': Galactic(),
'c': ICRS()
}
def parse_coord_system(system):
if isinstance(system, BaseCoordinateFrame):
return system
elif isinstance(system, six.string_types):
system = system.lower()
if system == 'e':
raise ValueError("Ecliptic coordinate frame not yet supported")
elif system in FRAMES:
return FRAMES[system]
else:
system_new = frame_transform_graph.lookup_name(system)
if system_new is None:
raise ValueError("Could not determine frame for system={0}".format(system))
else:
return system_new()
def parse_input_healpix_data(input_data, field=0, hdu_in=None):
"""
Parse input HEALPIX data to return a Numpy array and coordinate frame object.
"""
if isinstance(input_data, (TableHDU, BinTableHDU)):
# TODO: for now we have to write out to a temporary file. A pull
# request to healpy has been merged to allow ``read_map`` to take
# HDUList objects and HDUs, but we have to wait for a stable release
# before we can use that:
#
# https://github.com/healpy/healpy/pull/249
filename = tempfile.mktemp()
input_data.writeto(filename)
input_data = filename
if isinstance(input_data, six.string_types):
from healpy import read_map
array_in, header = read_map(input_data, verbose=False, h=True, field=field, hdu=1 if hdu_in is None else hdu_in)
coordinate_system_in = parse_coord_system(dict(header)['COORDSYS'])
elif isinstance(input_data, tuple) and isinstance(input_data[0], np.ndarray):
array_in = input_data[0]
coordinate_system_in = parse_coord_system(input_data[1])
else:
raise TypeError("input_data should either be an HDU object or a tuple of (array, frame)")
return array_in, coordinate_system_in
|