Coverage for tests/test_fluxFromABMag.py: 35%
42 statements
« prev ^ index » next coverage.py v6.4.1, created at 2022-06-14 02:44 -0700
« prev ^ index » next coverage.py v6.4.1, created at 2022-06-14 02:44 -0700
1#
2# LSST Data Management System
3# Copyright 2014 LSST Corporation.
4#
5# This product includes software developed by the
6# LSST Project (http://www.lsst.org/).
7#
8# This program is free software: you can redistribute it and/or modify
9# it under the terms of the GNU General Public License as published by
10# the Free Software Foundation, either version 3 of the License, or
11# (at your option) any later version.
12#
13# This program is distributed in the hope that it will be useful,
14# but WITHOUT ANY WARRANTY; without even the implied warranty of
15# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16# GNU General Public License for more details.
17#
18# You should have received a copy of the LSST License Statement and
19# the GNU General Public License along with this program. If not,
20# see <http://www.lsstcorp.org/LegalNotices/>.
21#
22"""
23Tests for lsst.afw.table.FluxFromABMagTable, etc.
24"""
25import unittest
27import numpy as np
29import lsst.utils.tests
30import lsst.afw.image as afwImage
33def refABMagFromFlux(flux):
34 return -(5.0/2.0) * np.log10(flux/3631.0)
37def refABMagErrFromFluxErr(fluxErr, flux):
38 return np.fabs(fluxErr/(-0.4*flux*np.log(10)))
41class FluxFromABMagTableTestCase(lsst.utils.tests.TestCase):
43 def testBasics(self):
44 for flux in (1, 210, 3210, 43210, 543210):
45 abMag = afwImage.abMagFromFlux(flux)
46 self.assertAlmostEqual(abMag, refABMagFromFlux(flux))
47 fluxRoundTrip = afwImage.fluxFromABMag(abMag)
48 self.assertAlmostEqual(flux, fluxRoundTrip)
50 for fluxErrFrac in (0.001, 0.01, 0.1):
51 fluxErr = flux * fluxErrFrac
52 abMagErr = afwImage.abMagErrFromFluxErr(fluxErr, flux)
53 self.assertAlmostEqual(
54 abMagErr, refABMagErrFromFluxErr(fluxErr, flux))
55 fluxErrRoundTrip = afwImage.fluxErrFromABMagErr(
56 abMagErr, abMag)
57 self.assertAlmostEqual(fluxErr, fluxErrRoundTrip)
59 def testVector(self):
60 flux = np.array([1.0, 210.0, 3210.0, 43210.0, 543210.0])
61 flux.flags.writeable = False # Put the 'const' into ndarray::Array<double const, 1, 0>
62 abMag = afwImage.abMagFromFlux(flux)
63 self.assertFloatsAlmostEqual(abMag, refABMagFromFlux(flux))
64 fluxRoundTrip = afwImage.fluxFromABMag(abMag)
65 self.assertFloatsAlmostEqual(flux, fluxRoundTrip, rtol=1.0e-15)
67 for fluxErrFrac in (0.001, 0.01, 0.1):
68 fluxErr = flux * fluxErrFrac
69 abMagErr = afwImage.abMagErrFromFluxErr(fluxErr, flux)
70 self.assertFloatsAlmostEqual(abMagErr, refABMagErrFromFluxErr(fluxErr, flux))
71 fluxErrRoundTrip = afwImage.fluxErrFromABMagErr(abMagErr, abMag)
72 self.assertFloatsAlmostEqual(fluxErr, fluxErrRoundTrip, rtol=1.0e-15)
75class MemoryTester(lsst.utils.tests.MemoryTestCase):
76 pass
79def setup_module(module):
80 lsst.utils.tests.init()
83if __name__ == "__main__": 83 ↛ 84line 83 didn't jump to line 84, because the condition on line 83 was never true
84 lsst.utils.tests.init()
85 unittest.main()