Coverage for tests/test_MomentsClassifier.py: 28%
50 statements
« prev ^ index » next coverage.py v7.4.4, created at 2024-04-06 04:20 -0700
« prev ^ index » next coverage.py v7.4.4, created at 2024-04-06 04:20 -0700
1# This file is part of meas_base.
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 unittest
24import lsst.meas.base as measBase
25import lsst.meas.base.tests
26import lsst.utils.tests
27import numpy as np
30class MomentsClassificationTestCase(lsst.meas.base.tests.AlgorithmTestCase, lsst.utils.tests.TestCase):
32 def setUp(self):
33 self.bbox = lsst.geom.Box2I(lsst.geom.Point2I(-20, -20),
34 lsst.geom.Extent2I(250, 150))
35 self.dataset = lsst.meas.base.tests.TestDataset(self.bbox)
37 self.n_stars = 1
38 self.n_gals = 1
39 # First 10 sources are point sources
40 self.dataset.addSource(1000.0, lsst.geom.Point2D(50.1, 49.8))
41 # Following 10 sources are extended sources
42 self.dataset.addSource(5000.0, lsst.geom.Point2D(149.9, 50.3),
43 lsst.afw.geom.Quadrupole(1, 1.2, 0.3))
45 def tearDown(self):
46 del self.bbox
47 del self.dataset
49 def testSingleFramePlugin(self):
50 config = measBase.SingleFrameMeasurementConfig()
51 task = self.makeSingleFrameMeasurementTask(config=config)
52 exposure, catalog = self.dataset.realize(10.0, task.schema, randomSeed=3)
53 task.run(catalog, exposure)
54 for ii in range(self.n_stars):
55 self.assertLess(catalog[ii].get("base_ClassificationSizeExtendedness_value"), 0.1)
56 for ii in range(self.n_stars, self.n_stars + self.n_gals):
57 self.assertGreater(catalog[ii].get("base_ClassificationSizeExtendedness_value"), 0.02)
59 @lsst.utils.tests.methodParameters(noise=(0.001, 0.01))
60 def testMonteCarlo(self, noise: float, n_trials: int = 100):
61 """Test an ideal simulation, with no noise.
63 Demonstrate that:
65 - We get exactly the right answer, and
66 - The reported uncertainty agrees with a Monte Carlo test of the noise.
68 Parameters
69 ----------
70 noise : float
71 Noise level to use in the simulation.
72 n_trials : int
73 Number of trials to use in the Monte Carlo test.
74 """
75 config = measBase.SingleFrameMeasurementConfig()
76 task = self.makeSingleFrameMeasurementTask(config=config)
78 star_measures, galaxy_measures = [], []
79 for ii in range(n_trials):
80 exposure, catalog = self.dataset.realize(1000.0*noise, task.schema, randomSeed=ii)
81 task.run(catalog, exposure)
82 for ii in range(self.n_stars):
83 star_measures.append(catalog[ii].get("base_ClassificationSizeExtendedness_value"))
84 for ii in range(self.n_stars, self.n_stars + self.n_gals):
85 galaxy_measures.append(catalog[ii].get("base_ClassificationSizeExtendedness_value"))
87 # Mapping noise level to thresholds for stars and galaxies
88 star_threshold = {
89 0.001: 0.01,
90 0.01: 0.1
91 }
92 galaxy_threshold = {
93 0.001: 0.25,
94 0.01: 0.25,
95 }
96 self.assertLess(np.mean(star_measures), star_threshold[noise])
97 self.assertLess(np.percentile(star_measures, 50), star_threshold[noise])
98 self.assertGreater(np.mean(galaxy_measures), galaxy_threshold[noise])
99 self.assertGreater(np.percentile(galaxy_measures, 50), galaxy_threshold[noise])
102class TestMemory(lsst.utils.tests.MemoryTestCase):
103 pass
106def setup_module(module):
107 lsst.utils.tests.init()
110if __name__ == "__main__": 110 ↛ 111line 110 didn't jump to line 111, because the condition on line 110 was never true
111 lsst.utils.tests.init()
112 unittest.main()