Coverage for tests/test_metrics.py: 20%
57 statements
« prev ^ index » next coverage.py v7.3.2, created at 2023-11-30 14:27 +0000
« prev ^ index » next coverage.py v7.3.2, created at 2023-11-30 14:27 +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/>.
21from __future__ import annotations
23from unittest import TestCase, main
25import lsst.utils.tests
26import numpy as np
27from lsst.analysis.tools.atools import (
28 MagnitudeTool,
29 MatchedRefCoaddDiffMagTool,
30 MatchedRefCoaddDiffPositionTool,
31 MatchedRefCoaddDiffTool,
32)
35class TestDiffMatched(TestCase):
36 def setUp(self) -> None:
37 super().setUp()
38 self.band_default = "analysisTools"
40 def _testMatchedRefCoaddMetricDerived(self, type_metric: type[MatchedRefCoaddDiffTool], **kwargs):
41 plotInfo = {key: "" for key in ("plotName", "run", "tableName")}
42 plotInfo["bands"] = []
43 for compute_chi in (False, True):
44 tester = type_metric(**kwargs, compute_chi=compute_chi)
45 # tester.getInputSchema won't work properly before finalizing
46 tester.finalize()
48 keys = set(k[0] for k in tester.getInputSchema())
49 self.assertGreater(len(keys), 0)
50 self.assertGreater(len(list(tester.configureMetrics())), 0)
51 data = {key.format(band=self.band_default): np.arange(5) for key in keys}
52 output = tester(data, skymap=None, plotInfo=plotInfo)
53 self.assertGreater(len(output), 0)
55 def testMatchedRefCoaddMetric(self):
56 kwargs = {key: "" for key in ("unit", "name_prefix")}
57 # The metric can now be set up with default kwargs
58 # Pass one at a time to test
59 for kwarg in kwargs:
60 kwargs_init = {kwarg: ""}
61 tester = MatchedRefCoaddDiffTool(**kwargs_init)
62 tester.validate()
63 with self.assertRaises(KeyError):
64 tester.configureMetrics()
65 tester.finalize()
66 tester.configureMetrics()
67 # Failing to find any of the required keys
68 with self.assertRaises(KeyError):
69 tester({})
70 tester = MatchedRefCoaddDiffTool(**kwargs)
71 tester.validate()
72 with self.assertRaises(KeyError):
73 tester.configureMetrics()
74 tester.finalize()
75 inputs = list(tester.getInputSchema())
76 n_input = len(inputs)
77 self.assertGreater(n_input, 0)
78 self.assertGreater(len(list(tester.configureMetrics())), 0)
80 self.assertEqual(len(inputs), n_input)
81 data = {key.format(band="analysisTools"): np.array([0.0]) for key, *_ in inputs}
82 # There's no metric or plot so it just returns an empty dict
83 self.assertEqual(len(tester(data)), 0)
85 def testMatchedRefCoaddDiffMagMetric(self):
86 self._testMatchedRefCoaddMetricDerived(
87 MatchedRefCoaddDiffMagTool,
88 fluxes={"cmodel": MagnitudeTool.fluxes_default.cmodel_err},
89 mag_y="cmodel",
90 name_prefix="",
91 unit="",
92 )
94 def testMatchedRefCoaddDiffPositionTool(self):
95 for variable in ("x", "y"):
96 self._testMatchedRefCoaddMetricDerived(
97 MatchedRefCoaddDiffPositionTool,
98 coord_meas=variable,
99 coord_ref=variable,
100 )
103class MyMemoryTestCase(lsst.utils.tests.MemoryTestCase):
104 pass
107def setup_module(module):
108 lsst.utils.tests.init()
111if __name__ == "__main__": 111 ↛ 112line 111 didn't jump to line 112, because the condition on line 111 was never true
112 lsst.utils.tests.init()
113 main()