Skip to content

Commit

Permalink
Added (hacky) pixellated PSF tests, fixed a bug in pixellated() method
Browse files Browse the repository at this point in the history
  • Loading branch information
Anthony Horton committed Apr 11, 2018
1 parent ec58716 commit b339773
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 3 deletions.
1 change: 0 additions & 1 deletion docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,6 @@ Reference/API
:skip: discretize_model
:skip: Fittable2DModel
:skip: Moffat2D
:skip: utils

.. automodapi:: gunagala.sky
:skip: interp1d
Expand Down
2 changes: 1 addition & 1 deletion gunagala/psf.py
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,7 @@ def pixellated(self, size=21, offsets=(0.0, 0.0)):
pixellated PSF will be somewhat less due to truncation of the
PSF wings by the edge of the image.
"""
resampled_size = size * self._oversampling
resampled_size = int(size) * self._oversampling
# Arrays of pixel coordinates relative to array centre
resampled_coordinates = np.mgrid[-(resampled_size - 1) / 2:resampled_size / 2,
-(resampled_size - 1) / 2:resampled_size / 2]
Expand Down
50 changes: 49 additions & 1 deletion gunagala/tests/test_psf.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import numpy as np
import astropy.units as u

from gunagala.psf import PSF, MoffatPSF
from gunagala.psf import PSF, MoffatPSF, PixellatedPSF


@pytest.fixture(scope='module')
Expand All @@ -11,6 +11,21 @@ def psf():
return psf


@pytest.fixture(scope='module')
def pix_psf():
psf_data = np.array([[0.0, 0.0, 0.1, 0.0, 0.0],
[0.0, 0.3, 0.7, 0.4, 0.0],
[0.1, 0.8, 1.0, 0.6, 0.1],
[0.0, 0.2, 0.7, 0.3, 0.0],
[0.0, 0.0, 0.1, 0.0, 0.0]])
psf = PixellatedPSF(psf_data=psf_data,
psf_sampling=1 * u.arcsecond / u.pixel,
psf_centre=(2, 2),
oversampling=10,
pixel_scale=(2 / 3) * u.arcsecond / u.pixel)
return psf


def test_base():
with pytest.raises(TypeError):
# Try to instantiate abstract base class, should fail
Expand All @@ -22,6 +37,11 @@ def test_moffat(psf):
assert isinstance(psf, PSF)


def test_pix(pix_psf):
assert isinstance(pix_psf, PixellatedPSF)
assert isinstance(pix_psf, PSF)


def test_FWHM(psf):
assert psf.FWHM == 2 * u.arcsecond
psf.FWHM = 4 * u.arcsecond
Expand All @@ -36,14 +56,28 @@ def test_pixel_scale(psf):
assert psf.pixel_scale == 2.85 * u.arcsecond / u.pixel


def test_pixel_scale_pix(pix_psf):
pix_psf.pixel_scale = (1 / 3) * u.arcsecond / u.pixel
assert pix_psf.pixel_scale == (1 / 3) * u.arcsecond / u.pixel
pix_psf.pixel_scale = (2 / 3) * u.arcsecond / u.pixel


def test_n_pix(psf):
assert psf.n_pix == 4.25754067000986 * u.pixel


def test_n_pix_pix(pix_psf):
assert pix_psf.n_pix / u.pixel == pytest.approx(21.01351017)


def test_peak(psf):
assert psf.peak == 0.7134084656751443 / u.pixel


def test_peak_pix(pix_psf):
assert pix_psf.peak * u.pixel == pytest.approx(0.08073066)


def test_shape(psf):
assert psf.shape == 4.7
psf.shape = 2.5
Expand All @@ -65,3 +99,17 @@ def test_pixellated(psf):
assert pixellated.shape == (21, 21)
with pytest.raises(ValueError):
psf.pixellated(size=-1.3)


def test_pixellated(pix_psf):
pixellated = pix_psf.pixellated()
assert isinstance(pixellated, np.ndarray)
assert pixellated.shape == (21, 21)
pixellated = pix_psf.pixellated(size=7.2)
assert isinstance(pixellated, np.ndarray)
assert pixellated.shape == (7, 7)
pixellated = pix_psf.pixellated(offsets=(0.3, -0.7))
assert isinstance(pixellated, np.ndarray)
assert pixellated.shape == (21, 21)
with pytest.raises(ValueError):
pix_psf.pixellated(size=-1.3)

0 comments on commit b339773

Please sign in to comment.