Coverage for tests/test_metrics.py: 29%

44 statements  

« prev     ^ index     » next       coverage.py v7.2.5, created at 2023-05-02 11:55 -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 

22 

23from unittest import TestCase, main 

24 

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 

33 

34 

35class TestDiffMatched(TestCase): 

36 def setUp(self) -> None: 

37 super().setUp() 

38 self.band_default = "analysisTools" 

39 self.contexts = (MatchedRefChiContext, MatchedRefDiffContext) 

40 

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() 

46 

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) 

52 

53 def testMatchedRefCoaddMetric(self): 

54 tester = MatchedRefCoaddMetric(unit="") 

55 with self.assertRaises(ValueError): 

56 tester({}) 

57 tester = MatchedRefCoaddMetric(name_prefix="") 

58 with self.assertRaises(ValueError): 

59 tester({}) 

60 tester = MatchedRefCoaddMetric(unit="", name_prefix="") 

61 tester.finalize() 

62 self.assertGreater(len(list(tester.getInputSchema())), 0) 

63 self.assertGreater(len(list(tester.configureMetrics())), 0) 

64 

65 def testMatchedRefCoaddCModelFluxMetric(self): 

66 self._testMatchedRefCoaddMetricDerived(MatchedRefCoaddCModelFluxMetric) 

67 

68 def testMatchedRefCoaddPositionMetric(self): 

69 for variable in ("x", "y"): 

70 self._testMatchedRefCoaddMetricDerived(MatchedRefCoaddPositionMetric, variable=variable) 

71 

72 

73class MyMemoryTestCase(lsst.utils.tests.MemoryTestCase): 

74 pass 

75 

76 

77def setup_module(module): 

78 lsst.utils.tests.init() 

79 

80 

81if __name__ == "__main__": 81 ↛ 82line 81 didn't jump to line 82, because the condition on line 81 was never true

82 lsst.utils.tests.init() 

83 main()