Coverage for tests / test_utilsCalculations.py: 29%

31 statements  

« prev     ^ index     » next       coverage.py v7.13.5, created at 2026-04-24 08:35 +0000

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/>. 

21 

22from astropy.stats import gaussian_sigma_to_fwhm 

23import numpy as np 

24 

25import lsst.geom 

26from lsst.ip.diffim.utils import angleMean, getPsfFwhm 

27import lsst.meas.algorithms as measAlg 

28import lsst.utils.tests 

29 

30 

31class UtilsCalculationsTest(lsst.utils.tests.TestCase): 

32 

33 """Unit tests for calculations in utils. 

34 """ 

35 

36 def test_angleMean(self): 

37 """Function for averages of angles. 

38 """ 

39 seed = 5 

40 nSrc = 100 

41 angleOffset = 30 

42 rng = np.random.RandomState(seed) 

43 angles = np.radians((rng.rand(nSrc) - 0.5)*20 + angleOffset) 

44 self.assertFloatsAlmostEqual(angleOffset, angleMean(angles).asDegrees(), rtol=0.01) 

45 

46 def test_getPsfFwhm(self): 

47 """Calculation of FWHM from a realization of the PSF 

48 """ 

49 

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(gaussian_sigma_to_fwhm*sigma, psfSize, rtol=0.01) 

55 self.assertFloatsAlmostEqual(psfSize, psfSize2d[0], rtol=0.01) 

56 self.assertFloatsAlmostEqual(psfSize, psfSize2d[1], rtol=0.01) 

57 

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) 

62 

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) 

67 

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)