forked from astropy/reproject
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
110 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import numpy as np | ||
|
||
from astropy.tests.helper import pytest | ||
from astropy.coordinates import FK5, Galactic, ICRS | ||
from astropy.io import fits | ||
|
||
from ..utils import parse_coord_system, parse_input_healpix_data | ||
|
||
def test_parse_coord_system(): | ||
|
||
frame = parse_coord_system(Galactic()) | ||
assert isinstance(frame, Galactic) | ||
|
||
frame = parse_coord_system('fk5') | ||
assert isinstance(frame, FK5) | ||
|
||
with pytest.raises(ValueError) as exc: | ||
frame = parse_coord_system('e') | ||
assert exc.value.args[0] == "Ecliptic coordinate frame not yet supported" | ||
|
||
frame = parse_coord_system('g') | ||
assert isinstance(frame, Galactic) | ||
|
||
with pytest.raises(ValueError) as exc: | ||
frame = parse_coord_system('spam') | ||
assert exc.value.args[0] == "Could not determine frame for system=spam" | ||
|
||
|
||
def test_parse_input_healpix_data(tmpdir): | ||
|
||
data = np.arange(3072) | ||
|
||
col = fits.Column(array=data, name='flux', format="E") | ||
hdu = fits.BinTableHDU.from_columns([col]) | ||
hdu.header['NSIDE'] = 512 | ||
hdu.header['COORDSYS'] = "G" | ||
|
||
# As HDU | ||
array, coordinate_system = parse_input_healpix_data(hdu) | ||
np.testing.assert_allclose(array, data) | ||
|
||
# As filename | ||
filename = tmpdir.join('test.fits').strpath | ||
hdu.writeto(filename) | ||
array, coordinate_system = parse_input_healpix_data(filename) | ||
np.testing.assert_allclose(array, data) | ||
|
||
# As array | ||
array, coordinate_system = parse_input_healpix_data((data, "galactic")) | ||
np.testing.assert_allclose(array, data) | ||
|
||
# Invalid | ||
with pytest.raises(TypeError) as exc: | ||
parse_input_healpix_data(data) | ||
assert exc.value.args[0] == "input_data should either be an HDU object or a tuple of (array, frame)" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
# Licensed under a 3-clause BSD style license - see LICENSE.rst | ||
from __future__ import (absolute_import, division, print_function, | ||
unicode_literals) | ||
|
||
import numpy as np | ||
from astropy.io import fits | ||
from astropy.wcs import WCS | ||
from astropy.utils.data import get_pkg_data_filename | ||
from astropy.tests.helper import pytest | ||
|
||
from ..high_level import reproject_exact | ||
|
||
|
||
class TestReprojectExact(object): | ||
|
||
def setup_class(self): | ||
|
||
self.header_in = fits.Header.fromtextfile(get_pkg_data_filename('../../tests/data/gc_ga.hdr')) | ||
self.header_out = fits.Header.fromtextfile(get_pkg_data_filename('../../tests/data/gc_eq.hdr')) | ||
|
||
self.header_out['NAXIS'] = 2 | ||
self.header_out['NAXIS1'] = 600 | ||
self.header_out['NAXIS2'] = 550 | ||
|
||
self.array_in = np.ones((100, 100)) | ||
|
||
self.wcs_in = WCS(self.header_in) | ||
self.wcs_out = WCS(self.header_out) | ||
|
||
def test_array_wcs(self): | ||
reproject_exact((self.array_in, self.wcs_in), self.wcs_out, shape_out=(200, 200)) | ||
|
||
def test_array_header(self): | ||
reproject_exact((self.array_in, self.header_in), self.header_out) | ||
|
||
def test_parallel_option(self): | ||
|
||
reproject_exact((self.array_in, self.header_in), self.header_out, parallel=1) | ||
|
||
with pytest.raises(ValueError) as exc: | ||
reproject_exact((self.array_in, self.header_in), self.header_out, parallel=-1) | ||
assert exc.value.args[0] == "The number of processors to use must be strictly positive" |