Coverage for tests/test_computeExposureSummaryStats.py: 25%
66 statements
« prev ^ index » next coverage.py v6.5.0, created at 2022-10-18 09:19 +0000
« prev ^ index » next coverage.py v6.5.0, created at 2022-10-18 09:19 +0000
1# This file is part of pipe_tasks.
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/>.
22"""Test ComputeExposureSummaryStatsTask.
23"""
24import unittest
26import numpy as np
28import lsst.utils.tests
29from lsst.afw.detection import GaussianPsf
30import lsst.afw.image as afwImage
31import lsst.afw.math as afwMath
32from lsst.daf.base import DateTime
33from lsst.afw.coord import Observatory
34from lsst.afw.geom import makeCdMatrix, makeSkyWcs
35from lsst.pipe.tasks.computeExposureSummaryStats import ComputeExposureSummaryStatsTask
38class ComputeExposureSummaryTestCase(lsst.utils.tests.TestCase):
40 def testComputeExposureSummary(self):
41 """Make a fake exposure and background and compute summary.
42 """
43 np.random.seed(12345)
45 # Make an exposure with a noise image
46 exposure = afwImage.ExposureF(100, 100)
47 skySigma = 10.0
48 exposure.getImage().getArray()[:, :] = np.random.normal(0.0, skySigma, size=(100, 100))
49 exposure.getVariance().getArray()[:, :] = skySigma**2.
51 # Set the visitInfo
52 date = DateTime(date=59234.7083333334, system=DateTime.DateSystem.MJD)
53 observatory = Observatory(-70.7366*lsst.geom.degrees, -30.2407*lsst.geom.degrees,
54 2650.)
55 visitInfo = afwImage.VisitInfo(exposureTime=10.0,
56 date=date,
57 observatory=observatory)
58 exposure.getInfo().setVisitInfo(visitInfo)
60 # Install a Gaussian PSF
61 psfSize = 2.0
62 psf = GaussianPsf(5, 5, psfSize)
63 exposure.setPsf(psf)
65 # Install a simple WCS
66 scale = 0.2*lsst.geom.arcseconds
67 raCenter = 300.0*lsst.geom.degrees
68 decCenter = 0.0*lsst.geom.degrees
69 cdMatrix = makeCdMatrix(scale=scale)
70 skyWcs = makeSkyWcs(crpix=exposure.getBBox().getCenter(),
71 crval=lsst.geom.SpherePoint(raCenter, decCenter),
72 cdMatrix=cdMatrix)
73 exposure.setWcs(skyWcs)
75 # Install a simple photoCalib
76 photoCalib = afwImage.PhotoCalib(calibrationMean=0.3)
77 zp = 2.5*np.log10(photoCalib.getInstFluxAtZeroMagnitude())
78 exposure.setPhotoCalib(photoCalib)
80 # Compute the background image
81 bgGridSize = 10
82 bctrl = afwMath.BackgroundControl(afwMath.Interpolate.NATURAL_SPLINE)
83 bctrl.setNxSample(int(exposure.getMaskedImage().getWidth()/bgGridSize) + 1)
84 bctrl.setNySample(int(exposure.getMaskedImage().getHeight()/bgGridSize) + 1)
85 backobj = afwMath.makeBackground(exposure.getMaskedImage().getImage(), bctrl)
86 background = afwMath.BackgroundList()
87 background.append(backobj)
89 # Run the task
90 expSummaryTask = ComputeExposureSummaryStatsTask()
91 summary = expSummaryTask.run(exposure, None, background)
93 # Test the outputs
94 self.assertFloatsAlmostEqual(summary.psfSigma, psfSize)
95 self.assertFloatsAlmostEqual(summary.psfIxx, psfSize**2.)
96 self.assertFloatsAlmostEqual(summary.psfIyy, psfSize**2.)
97 self.assertFloatsAlmostEqual(summary.psfIxy, 0.0)
98 self.assertFloatsAlmostEqual(summary.psfArea, 23.088975164455444)
100 delta = (scale*50).asDegrees()
101 for a, b in zip(summary.raCorners,
102 [raCenter.asDegrees() + delta, raCenter.asDegrees() - delta,
103 raCenter.asDegrees() - delta, raCenter.asDegrees() + delta]):
104 self.assertFloatsAlmostEqual(a, b, atol=1e-10)
105 for a, b in zip(summary.decCorners,
106 [decCenter.asDegrees() - delta, decCenter.asDegrees() - delta,
107 decCenter.asDegrees() + delta, decCenter.asDegrees() + delta]):
108 self.assertFloatsAlmostEqual(a, b, atol=1e-10)
110 self.assertFloatsAlmostEqual(summary.ra, raCenter.asDegrees(), atol=1e-10)
111 self.assertFloatsAlmostEqual(summary.decl, decCenter.asDegrees(), atol=1e-10)
113 self.assertFloatsAlmostEqual(summary.zeroPoint, zp)
115 # Need to compare background level and noise
116 # These are only approximately 0+/-10 because of the small image
117 self.assertFloatsAlmostEqual(summary.skyBg, -0.079, atol=1e-3)
119 self.assertFloatsAlmostEqual(summary.meanVar, skySigma**2.)
121 self.assertFloatsAlmostEqual(summary.zenithDistance, 30.57112, atol=1e-5)
124class MyMemoryTestCase(lsst.utils.tests.MemoryTestCase):
125 pass
128def setup_module(module):
129 lsst.utils.tests.init()
132if __name__ == "__main__": 132 ↛ 133line 132 didn't jump to line 133, because the condition on line 132 was never true
133 lsst.utils.tests.init()
134 unittest.main()