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.
Merge pull request astropy#77 from astrofrog/improve-coverage
Improve coverage
- Loading branch information
Showing
9 changed files
with
213 additions
and
27 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,62 @@ | ||
import numpy as np | ||
|
||
from astropy.tests.helper import pytest | ||
from astropy.coordinates import FK5, Galactic, ICRS | ||
from astropy.io import fits | ||
|
||
try: | ||
import healpy | ||
HAS_HEALPY = True | ||
except: | ||
HAS_HEALPY = False | ||
|
||
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" | ||
|
||
|
||
@pytest.mark.skipif('not HAS_HEALPY') | ||
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" |
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,76 @@ | ||
import numpy as np | ||
|
||
from astropy.tests.helper import pytest | ||
from astropy.coordinates import FK5, Galactic, ICRS | ||
from astropy.io import fits | ||
from astropy.wcs import WCS | ||
from astropy.utils.data import get_pkg_data_filename | ||
|
||
from ..utils import parse_input_data, parse_output_projection | ||
|
||
|
||
def test_parse_input_data(tmpdir): | ||
|
||
header = fits.Header.fromtextfile(get_pkg_data_filename('data/gc_ga.hdr')) | ||
|
||
data = np.arange(200).reshape((10,20)) | ||
|
||
hdu = fits.ImageHDU(data) | ||
|
||
# As HDU | ||
array, coordinate_system = parse_input_data(hdu) | ||
np.testing.assert_allclose(array, data) | ||
|
||
# As filename | ||
filename = tmpdir.join('test.fits').strpath | ||
hdu.writeto(filename) | ||
|
||
with pytest.raises(ValueError) as exc: | ||
array, coordinate_system = parse_input_data(filename) | ||
assert exc.value.args[0] == "More than one HDU is present, please specify HDU to use with ``hdu_in=`` option" | ||
|
||
array, coordinate_system = parse_input_data(filename, hdu_in=1) | ||
np.testing.assert_allclose(array, data) | ||
|
||
# As array, header | ||
array, coordinate_system = parse_input_data((data, header)) | ||
np.testing.assert_allclose(array, data) | ||
|
||
# As array, WCS | ||
wcs = WCS(hdu.header) | ||
array, coordinate_system = parse_input_data((data, wcs)) | ||
np.testing.assert_allclose(array, data) | ||
|
||
# Invalid | ||
with pytest.raises(TypeError) as exc: | ||
parse_input_data(data) | ||
assert exc.value.args[0] == "input_data should either be an HDU object or a tuple of (array, WCS) or (array, Header)" | ||
|
||
|
||
|
||
def test_parse_output_projection(tmpdir): | ||
|
||
header = fits.Header.fromtextfile(get_pkg_data_filename('data/gc_ga.hdr')) | ||
wcs = WCS(header) | ||
|
||
# As header | ||
|
||
with pytest.raises(ValueError) as exc: | ||
parse_output_projection(header) | ||
assert exc.value.args[0] == "Need to specify shape since output header does not contain complete shape information" | ||
|
||
parse_output_projection(header, shape_out=(200, 200)) | ||
|
||
header['NAXIS'] = 2 | ||
header['NAXIS1'] = 200 | ||
header['NAXIS2'] = 300 | ||
|
||
parse_output_projection(header) | ||
|
||
# As WCS | ||
|
||
with pytest.raises(ValueError) as exc: | ||
parse_output_projection(wcs) | ||
assert exc.value.args[0] == "Need to specify shape when specifying output_projection as WCS object" | ||
|
||
parse_output_projection(wcs, shape_out=(200, 200)) |
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