Coverage for tests/test_taskConfigs.py: 14%
101 statements
« prev ^ index » next coverage.py v6.5.0, created at 2023-03-04 02:56 -0800
« prev ^ index » next coverage.py v6.5.0, created at 2023-03-04 02:56 -0800
1# This file is part of faro.
2#
3# Developed for the LSST Data Management System.
4# This product includes software developed by the LSST Project
5# (http://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/>.
22"""Unit tests for the metrics measurement system: configs.
23"""
25import unittest
27from lsst.faro.measurement import (AMxTask, ADxTask, AFxTask,
28 PA1Task, PF1Task,
29 TExTask, AB1Task, WPerpTask)
32class ConfigTest(unittest.TestCase):
34 def check_config(self, task, expected, default, check_fields):
35 """This checks both that there are attributes on the task
36 that match the expected configuration as well as that the
37 configuration is different than the default config.
38 """
39 for field in check_fields:
40 self.assertEqual(getattr(task.config, field), getattr(expected, field))
41 self.assertNotEqual(getattr(task.config, field), getattr(default, field))
43 # AMxTask, ADxTask, and AFxTask share a config so we are really only testing
44 # how the tasks apply the config
45 def test_amx_config(self):
46 """Test application of config for AMx task"""
47 default = AMxTask.ConfigClass()
48 expected = AMxTask.ConfigClass()
49 field_list = ['annulus_r', 'width', 'bright_mag_cut', 'faint_mag_cut',
50 'threshAD', 'threshAF', 'bins']
51 expected.annulus_r = 11.7
52 expected.width = 3.33
53 expected.bright_mag_cut = 20.0
54 expected.faint_mag_cut = 23.8
55 expected.threshAD = 19.63
56 expected.threshAF = 11.55
57 expected.bins = [0.5, 1.6, 2.8, 3.1]
58 task = AMxTask(config=expected)
59 self.check_config(task, expected, default, field_list)
61 def test_adx_config(self):
62 """Test application of config for ADx task"""
63 default = ADxTask.ConfigClass()
64 expected = ADxTask.ConfigClass()
65 field_list = ['annulus_r', 'width', 'bright_mag_cut', 'faint_mag_cut',
66 'threshAD', 'threshAF', 'bins']
67 expected.annulus_r = 11.7
68 expected.width = 3.33
69 expected.bright_mag_cut = 20.0
70 expected.faint_mag_cut = 23.8
71 expected.threshAD = 19.63
72 expected.threshAF = 11.55
73 expected.bins = [0.5, 1.6, 2.8, 3.1]
74 task = ADxTask(config=expected)
75 self.check_config(task, expected, default, field_list)
77 def test_afx_config(self):
78 """Test application of config for AFx task"""
79 default = AFxTask.ConfigClass()
80 expected = AFxTask.ConfigClass()
81 field_list = ['annulus_r', 'width', 'bright_mag_cut', 'faint_mag_cut',
82 'threshAD', 'threshAF', 'bins']
83 expected.annulus_r = 11.7
84 expected.width = 3.33
85 expected.bright_mag_cut = 20.0
86 expected.faint_mag_cut = 23.8
87 expected.threshAD = 19.63
88 expected.threshAF = 11.55
89 expected.bins = [0.5, 1.6, 2.8, 3.1]
90 task = AFxTask(config=expected)
91 self.check_config(task, expected, default, field_list)
93 def test_pa1_config(self):
94 """Test application of config for PA1 task"""
95 default = PA1Task.ConfigClass()
96 expected = PA1Task.ConfigClass()
97 field_list = ['brightSnrMin', 'brightSnrMax']
98 expected.brightSnrMin = 100.0
99 expected.brightSnrMax = 31415.9
100 task = PA1Task(config=expected)
101 # Some config attriutes are also used to populate task attriubtes
102 self.assertEqual(task.config.brightSnrMin, expected.brightSnrMin)
103 self.assertEqual(task.config.brightSnrMax, expected.brightSnrMax)
104 self.check_config(task, expected, default, field_list)
106 def test_pf1_config(self):
107 """Test application of config for PF1 task"""
108 default = PF1Task.ConfigClass()
109 expected = PF1Task.ConfigClass()
110 field_list = ['brightSnrMin', 'brightSnrMax', 'threshPA2']
111 expected.brightSnrMin = 100.0
112 expected.brightSnrMax = 31415.9
113 expected.threshPA2 = 17.47
114 task = PF1Task(config=expected)
115 # Some config attriutes are also used to populate task attriubtes
116 self.assertEqual(task.config.brightSnrMin, expected.brightSnrMin)
117 self.assertEqual(task.config.brightSnrMax, expected.brightSnrMax)
118 self.assertEqual(task.config.threshPA2, expected.threshPA2)
119 self.check_config(task, expected, default, field_list)
121 def test_tex_config(self):
122 """Test application of config for TEx task"""
123 default = TExTask.ConfigClass()
124 expected = TExTask.ConfigClass()
125 field_list = ['minSep', 'maxSep', 'nbins',
126 'rhoStat', 'shearConvention', 'columnPsf', 'column']
127 expected.minSep = 5.
128 expected.maxSep = 20.
129 expected.nbins = 100
130 expected.rhoStat = 2
131 expected.shearConvention = True
132 expected.columnPsf = 'ext_shapeHSM_HsmPsfMoments'
133 expected.column = 'ext_shapeHSM_HsmSourceMoments'
134 task = TExTask(config=expected)
135 self.check_config(task, expected, default, field_list)
137 def test_ab1_config(self):
138 """Test application of config for AB1 task"""
139 default = AB1Task.ConfigClass()
140 expected = AB1Task.ConfigClass()
141 field_list = ['bright_mag_cut', 'faint_mag_cut', 'ref_filter']
142 expected.bright_mag_cut = 25.3
143 expected.faint_mag_cut = 38.2
144 expected.ref_filter = 'p'
145 task = AB1Task(config=expected)
146 self.check_config(task, expected, default, field_list)
148 def test_wperp_config(self):
149 """Test application of config for wPerp task"""
150 default = WPerpTask.ConfigClass()
151 expected = WPerpTask.ConfigClass()
152 field_list = ['bright_rmag_cut', 'faint_rmag_cut']
153 expected.bright_rmag_cut = 25.3
154 expected.faint_rmag_cut = 38.2
155 task = WPerpTask(config=expected)
156 self.check_config(task, expected, default, field_list)
159if __name__ == "__main__": 159 ↛ 160line 159 didn't jump to line 160, because the condition on line 159 was never true
160 unittest.main()