Coverage for tests / test_singleColumnMagnitudeScatterPlot.py: 32%
39 statements
« prev ^ index » next coverage.py v7.13.5, created at 2026-05-06 09:07 +0000
« prev ^ index » next coverage.py v7.13.5, created at 2026-05-06 09:07 +0000
1# This file is part of analysis_tools.
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 <http://www.gnu.org/licenses/>.
22from unittest import TestCase, main
24import numpy as np
26import lsst.utils.tests
27from lsst.analysis.tools.atools.actionMagnitudeScatterPlot import SingleColumnMagnitudeScatterPlot
28from lsst.analysis.tools.math import sqrt
31class SingleColumnMagnitudeScatterPlotTestCase(TestCase):
32 """Test the generic quantity vs magnitude scatter plot"""
34 def setUp(self) -> None:
35 super().setUp()
37 # Set up a quasi-plausible measurement catalog
38 band = "i"
39 mag = 12.5 + 2.5 * np.log10(np.arange(10, 100000))
40 flux = 10 ** (-0.4 * (mag - (mag[-1] + 1)))
41 rng = np.random.default_rng(0)
42 extendedness = 0.0 + (rng.uniform(size=len(mag)) < 0.99 * (mag - mag[0]) / (mag[-1] - mag[0]))
43 flux_meas = flux + rng.normal(scale=sqrt(flux * (1 + extendedness)))
44 flux_err = sqrt(flux_meas * (1 + extendedness))
45 good = (flux_meas / sqrt(flux * (1 + extendedness))) > 3
46 n_good = np.sum(good)
47 extendedness = extendedness[good]
48 flux_meas = flux_meas[good]
49 flux_err = flux_err[good]
50 key_flux = f"{band}_cModelFlux"
52 data = {
53 "objectId": np.arange(n_good),
54 key_flux: flux_meas,
55 f"{key_flux}Err": flux_err,
56 "detect_isPrimary": np.ones(n_good, dtype=bool),
57 "refExtendedness": extendedness,
58 "y": np.arange(n_good),
59 }
61 self.action = SingleColumnMagnitudeScatterPlot(
62 key_y="y",
63 mag_x="cmodel_err",
64 )
65 self.action.finalize()
66 self.band = band
67 self.data = data
68 plotInfo = {key: "test" for key in ("plotName", "run", "tableName")}
69 plotInfo["bands"] = [band]
70 self.plotInfo = plotInfo
72 def testAction(self) -> None:
73 results = self.action(
74 self.data,
75 band=self.band,
76 # skymap=None,
77 plotInfo=self.plotInfo,
78 )
79 assert tuple(results.keys()) == ("ScatterPlotWithTwoHists",)
82class MyMemoryTestCase(lsst.utils.tests.MemoryTestCase):
83 pass
86def setup_module(module):
87 lsst.utils.tests.init()
90if __name__ == "__main__": 90 ↛ 91line 90 didn't jump to line 91 because the condition on line 90 was never true
91 lsst.utils.tests.init()
92 main()