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