| 1 |
import numpy as np |
| 2 |
|
| 3 |
import pytest |
| 4 |
from astropy.coordinates import FK5, Galactic |
| 5 |
from astropy.io import fits |
| 6 |
|
| 7 |
from ..utils import parse_coord_system, parse_input_healpix_data |
| 8 |
|
| 9 |
|
| 10 |
def test_parse_coord_system(): |
| 11 |
|
| 12 |
frame = parse_coord_system(Galactic()) |
| 13 |
assert isinstance(frame, Galactic) |
| 14 |
|
| 15 |
frame = parse_coord_system('fk5') |
| 16 |
assert isinstance(frame, FK5) |
| 17 |
|
| 18 |
with pytest.raises(ValueError) as exc: |
| 19 |
frame = parse_coord_system('e') |
| 20 |
assert exc.value.args[0] == "Ecliptic coordinate frame not yet supported" |
| 21 |
|
| 22 |
frame = parse_coord_system('g') |
| 23 |
assert isinstance(frame, Galactic) |
| 24 |
|
| 25 |
with pytest.raises(ValueError) as exc: |
| 26 |
frame = parse_coord_system('spam') |
| 27 |
assert exc.value.args[0] == "Could not determine frame for system=spam" |
| 28 |
|
| 29 |
|
| 30 |
def test_parse_input_healpix_data(tmpdir): |
| 31 |
|
| 32 |
data = np.arange(3072) |
| 33 |
|
| 34 |
col = fits.Column(array=data, name='flux', format="E") |
| 35 |
hdu = fits.BinTableHDU.from_columns([col]) |
| 36 |
hdu.header['NSIDE'] = 512 |
| 37 |
hdu.header['COORDSYS'] = "G" |
| 38 |
|
| 39 |
# As HDU |
| 40 |
array, coordinate_system, nested = parse_input_healpix_data(hdu) |
| 41 |
np.testing.assert_allclose(array, data) |
| 42 |
|
| 43 |
# As filename |
| 44 |
filename = tmpdir.join('test.fits').strpath |
| 45 |
hdu.writeto(filename) |
| 46 |
array, coordinate_system, nested = parse_input_healpix_data(filename) |
| 47 |
np.testing.assert_allclose(array, data) |
| 48 |
|
| 49 |
# As array |
| 50 |
array, coordinate_system, nested = parse_input_healpix_data((data, "galactic")) |
| 51 |
np.testing.assert_allclose(array, data) |
| 52 |
|
| 53 |
# Invalid |
| 54 |
with pytest.raises(TypeError) as exc: |
| 55 |
parse_input_healpix_data(data) |
| 56 |
assert exc.value.args[0] == ("input_data should either be an HDU object or " |
| 57 |
"a tuple of (array, frame)") |