Coverage for tests/test_metrics.py: 30%
42 statements
« prev ^ index » next coverage.py v7.2.3, created at 2023-04-21 10:05 +0000
« prev ^ index » next coverage.py v7.2.3, created at 2023-04-21 10:05 +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.analysisMetrics.diffMatchedMetrics import (
28 MatchedRefCoaddCModelFluxMetric,
29 MatchedRefCoaddMetric,
30 MatchedRefCoaddPositionMetric,
31)
32from lsst.analysis.tools.contexts import MatchedRefChiContext, MatchedRefDiffContext
35class TestDiffMatched(TestCase):
36 def setUp(self) -> None:
37 super().setUp()
38 self.band_default = "analysisTools"
39 self.contexts = (MatchedRefChiContext, MatchedRefDiffContext)
41 def _testMatchedRefCoaddMetricDerived(self, type_metric: type[MatchedRefCoaddMetric], **kwargs):
42 for context in self.contexts:
43 tester = type_metric(**kwargs)
44 tester.applyContext(context)
46 keys = list(k[0] for k in tester.getInputSchema())
47 self.assertGreater(len(keys), 0)
48 self.assertGreater(len(list(tester.configureMetrics())), 0)
49 data = {key.format(band=self.band_default): np.arange(5) for key in keys}
50 self.assertGreater(len(tester(data)), 0)
52 def testMatchedRefCoaddMetric(self):
53 tester = MatchedRefCoaddMetric(unit="")
54 with self.assertRaises(ValueError):
55 tester({})
56 tester = MatchedRefCoaddMetric(name_prefix="")
57 with self.assertRaises(ValueError):
58 tester({})
59 tester = MatchedRefCoaddMetric(unit="", name_prefix="")
60 self.assertGreater(len(list(tester.getInputSchema())), 0)
61 self.assertGreater(len(list(tester.configureMetrics())), 0)
63 def testMatchedRefCoaddCModelFluxMetric(self):
64 self._testMatchedRefCoaddMetricDerived(MatchedRefCoaddCModelFluxMetric)
66 def testMatchedRefCoaddPositionMetric(self):
67 for variable in ("x", "y"):
68 self._testMatchedRefCoaddMetricDerived(MatchedRefCoaddPositionMetric, variable=variable)
71class MyMemoryTestCase(lsst.utils.tests.MemoryTestCase):
72 pass
75def setup_module(module):
76 lsst.utils.tests.init()
79if __name__ == "__main__": 79 ↛ 80line 79 didn't jump to line 80, because the condition on line 79 was never true
80 lsst.utils.tests.init()
81 main()