Coverage for tests/test_defaultZeroPoint.py: 41%
33 statements
« prev ^ index » next coverage.py v6.5.0, created at 2022-11-15 02:30 -0800
« prev ^ index » next coverage.py v6.5.0, created at 2022-11-15 02:30 -0800
1#
2# LSST Data Management System
3#
4# Copyright 2008-2016 AURA/LSST.
5#
6# This product includes software developed by the
7# LSST Project (http://www.lsst.org/).
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 LSST License Statement and
20# the GNU General Public License along with this program. If not,
21# see <https://www.lsstcorp.org/LegalNotices/>.
22#
23import unittest
24import numpy as np
26import lsst.afw.image as afwImage
27import lsst.afw.geom as afwGeom
28import lsst.geom as geom
29import lsst.meas.modelfit as measModel
30import lsst.utils
33class DefaultZeroPointTestCase(lsst.utils.tests.TestCase):
34 '''Test that photoCalib objects containing invalid calibrations are replaced with a default having a
35 zero-point of magnitude 27.
36 '''
38 def setUp(self):
39 '''Create two calibs, one with a valid zero-point and one without. Use these to create two UnitSystem
40 objects.
41 '''
42 self.mag2Flux = lambda m: 10.0**(m/2.5)
43 self.flux2Mag = lambda f: 2.5*np.log10(f)
45 photoCalibNoZero = afwImage.PhotoCalib()
46 photoCalibWithZero = afwImage.makePhotoCalibFromCalibZeroPoint(self.mag2Flux(25))
48 scale = 0.2 * geom.arcseconds
49 wcs = afwGeom.makeSkyWcs(crpix=geom.Point2D(),
50 crval=geom.SpherePoint(45.0, 45.0, geom.degrees),
51 cdMatrix=afwGeom.makeCdMatrix(scale=scale))
53 self.unitNoZero = measModel.UnitSystem(wcs, photoCalibNoZero)
54 self.unitWithZero = measModel.UnitSystem(wcs, photoCalibWithZero)
56 def testZeroPoint(self):
57 '''Verify that the UnitSystem with an invalid photoCalib gets populated with a valid photoCalib, and that
58 nothing happens to the UnitSystem with a valid photoCalib.
59 '''
60 magNoZero = self.flux2Mag(self.unitNoZero.photoCalib.getInstFluxAtZeroMagnitude())
61 magWithZero = self.flux2Mag(self.unitWithZero.photoCalib.getInstFluxAtZeroMagnitude())
63 print((magNoZero, magWithZero))
65 self.assertAlmostEqual(magNoZero, 27, 6)
66 self.assertAlmostEqual(magWithZero, 25, 6)
68 def tearDown(self):
69 del self.unitNoZero
70 del self.unitWithZero
73class TestMemory(lsst.utils.tests.MemoryTestCase):
74 pass
77def setup_module(module):
78 lsst.utils.tests.init()
81if __name__ == "__main__": 81 ↛ 82line 81 didn't jump to line 82, because the condition on line 81 was never true
82 lsst.utils.tests.init()
83 unittest.main()