Coverage for tests/test_metrics.py: 18%
63 statements
« prev ^ index » next coverage.py v7.4.4, created at 2024-04-05 04:13 -0700
« prev ^ index » next coverage.py v7.4.4, created at 2024-04-05 04:13 -0700
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 = {}
52 n_data = 10
53 for key in keys:
54 if key.endswith("xtendedness"):
55 values = np.linspace(0.0, 1.0, n_data)
56 else:
57 values = np.linspace(0.1, 15.0, n_data)
58 data[key.format(band=self.band_default)] = values
60 output = tester(data, skymap=None, plotInfo=plotInfo)
61 self.assertGreater(len(output), 0)
63 def testMatchedRefCoaddMetric(self):
64 kwargs = {key: "" for key in ("unit", "name_prefix")}
65 # The metric can now be set up with default kwargs
66 # Pass one at a time to test
67 for kwarg in kwargs:
68 kwargs_init = {kwarg: ""}
69 tester = MatchedRefCoaddDiffTool(**kwargs_init)
70 tester.validate()
71 with self.assertRaises(KeyError):
72 tester.configureMetrics()
73 tester.finalize()
74 tester.configureMetrics()
75 # Failing to find any of the required keys
76 with self.assertRaises(KeyError):
77 tester({})
78 tester = MatchedRefCoaddDiffTool(**kwargs)
79 tester.validate()
80 with self.assertRaises(KeyError):
81 tester.configureMetrics()
82 tester.finalize()
83 inputs = list(tester.getInputSchema())
84 n_input = len(inputs)
85 self.assertGreater(n_input, 0)
86 self.assertGreater(len(list(tester.configureMetrics())), 0)
88 self.assertEqual(len(inputs), n_input)
89 data = {key.format(band="analysisTools"): np.array([0.0]) for key, *_ in inputs}
90 # There's no metric or plot so it just returns an empty dict
91 self.assertEqual(len(tester(data)), 0)
93 def testMatchedRefCoaddDiffMagMetric(self):
94 self._testMatchedRefCoaddMetricDerived(
95 MatchedRefCoaddDiffMagTool,
96 fluxes={"cmodel": MagnitudeTool.fluxes_default.cmodel_err},
97 mag_y="cmodel",
98 name_prefix="",
99 unit="",
100 )
102 def testMatchedRefCoaddDiffPositionTool(self):
103 for variable in ("x", "y"):
104 self._testMatchedRefCoaddMetricDerived(
105 MatchedRefCoaddDiffPositionTool,
106 coord_meas=variable,
107 coord_ref=variable,
108 )
111class MyMemoryTestCase(lsst.utils.tests.MemoryTestCase):
112 pass
115def setup_module(module):
116 lsst.utils.tests.init()
119if __name__ == "__main__": 119 ↛ 120line 119 didn't jump to line 120, because the condition on line 119 was never true
120 lsst.utils.tests.init()
121 main()