Coverage for tests/test_utilsCalculations.py: 26%
31 statements
« prev ^ index » next coverage.py v7.5.0, created at 2024-04-27 03:53 -0700
« prev ^ index » next coverage.py v7.5.0, created at 2024-04-27 03:53 -0700
1# This file is part of ip_diffim.
2#
3# Developed for the LSST Data Management System.
4# This product includes software developed by the LSST Project
5# (https://www.lsst.org).
6# See the COPYRIGHT file at the top-level directory of this distribution
7# for details of code ownership.
8#
9# This program is free software: you can redistribute it and/or modify
10# it under the terms of the GNU General Public License as published by
11# the Free Software Foundation, either version 3 of the License, or
12# (at your option) any later version.
13#
14# This program is distributed in the hope that it will be useful,
15# but WITHOUT ANY WARRANTY; without even the implied warranty of
16# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17# GNU General Public License for more details.
18#
19# You should have received a copy of the GNU General Public License
20# along with this program. If not, see <https://www.gnu.org/licenses/>.
22import numpy as np
24import lsst.geom
25from lsst.ip.diffim.utils import angleMean, getPsfFwhm
26import lsst.meas.algorithms as measAlg
27import lsst.utils.tests
30class UtilsCalculationsTest(lsst.utils.tests.TestCase):
32 """Unit tests for calculations in utils.
33 """
35 def test_angleMean(self):
36 """Function for averages of angles.
37 """
38 seed = 5
39 nSrc = 100
40 angleOffset = 30
41 rng = np.random.RandomState(seed)
42 angles = (rng.rand(nSrc) - 0.5)*20 + angleOffset
43 self.assertFloatsAlmostEqual(angleOffset, angleMean(angles).asDegrees(), rtol=0.01)
45 def test_getPsfFwhm(self):
46 """Calculation of FWHM from a realization of the PSF
47 """
48 sigmaToFwhm = 2*np.log(2*np.sqrt(2))
50 def make_and_check_psf(xKsize, yKsize, sigma):
51 psf = measAlg.SingleGaussianPsf(xKsize, yKsize, sigma)
52 psfSize = getPsfFwhm(psf)
53 psfSize2d = getPsfFwhm(psf, average=False)
54 self.assertFloatsAlmostEqual(sigma*sigmaToFwhm, psfSize, rtol=0.01)
55 self.assertFloatsAlmostEqual(psfSize, psfSize2d[0], rtol=0.01)
56 self.assertFloatsAlmostEqual(psfSize, psfSize2d[1], rtol=0.01)
58 # Test equal and unequal axes with a narrow PSF
59 make_and_check_psf(23, 23, 1)
60 make_and_check_psf(23, 25, 1)
61 make_and_check_psf(23, 21, 1)
63 # Test equal and unequal axes with a narrow PSF
64 make_and_check_psf(23, 23, 1.23456)
65 make_and_check_psf(23, 25, 1.23456)
66 make_and_check_psf(23, 21, 1.23456)
68 # Test equal and unequal axes with a wide PSF
69 make_and_check_psf(23, 23, 2.1)
70 make_and_check_psf(23, 25, 2.1)
71 make_and_check_psf(23, 21, 2.1)