Coverage for tests/test_metrics.py: 24%
52 statements
« prev ^ index » next coverage.py v7.2.7, created at 2023-06-06 04:05 -0700
« prev ^ index » next coverage.py v7.2.7, created at 2023-06-06 04:05 -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 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)
45 tester.finalize()
47 keys = list(k[0] for k in tester.getInputSchema())
48 self.assertGreater(len(keys), 0)
49 self.assertGreater(len(list(tester.configureMetrics())), 0)
50 data = {key.format(band=self.band_default): np.arange(5) for key in keys}
51 self.assertGreater(len(tester(data)), 0)
53 def testMatchedRefCoaddMetric(self):
54 kwargs = {key: "" for key in ("unit", "name_prefix")}
55 for kwarg in kwargs:
56 kwargs_init = {kwarg: ""}
57 tester = MatchedRefCoaddMetric(**kwargs_init)
58 # Validation will fail because configureMetrics hasn't been called
59 with self.assertRaises(ValueError):
60 tester.validate()
61 # Failing to find any of the required keys
62 with self.assertRaises(KeyError):
63 tester({})
64 tester = MatchedRefCoaddMetric(**kwargs)
65 with self.assertRaises(ValueError):
66 tester.validate()
68 tester.finalize()
69 # This works, although it leaves none keys in the schema
70 # Should maybe be caught in populatePrepFromProcess
71 inputs = list(tester.getInputSchema())
72 n_input = len(inputs)
73 self.assertGreater(n_input, 0)
74 self.assertGreater(len(list(tester.configureMetrics())), 0)
76 tester.finalize()
77 # No more None key
78 self.assertEquals(len(list(tester.getInputSchema())), n_input - 1)
80 def testMatchedRefCoaddCModelFluxMetric(self):
81 self._testMatchedRefCoaddMetricDerived(MatchedRefCoaddCModelFluxMetric)
83 def testMatchedRefCoaddPositionMetric(self):
84 for variable in ("x", "y"):
85 self._testMatchedRefCoaddMetricDerived(MatchedRefCoaddPositionMetric, variable=variable)
88class MyMemoryTestCase(lsst.utils.tests.MemoryTestCase):
89 pass
92def setup_module(module):
93 lsst.utils.tests.init()
96if __name__ == "__main__": 96 ↛ 97line 96 didn't jump to line 97, because the condition on line 96 was never true
97 lsst.utils.tests.init()
98 main()