Coverage for tests/test_tasks.py: 29%
71 statements
« prev ^ index » next coverage.py v6.4.4, created at 2022-09-03 09:33 +0000
« prev ^ index » next coverage.py v6.4.4, created at 2022-09-03 09:33 +0000
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# (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 <https://www.gnu.org/licenses/>.
22import os
23import unittest
24import astropy.units as u
26from lsst.afw.table import SimpleCatalog
28from lsst.faro.base import CatalogMeasurementBaseConfig, CatalogMeasurementBaseTask, NumSourcesMergeTask
29from lsst.faro.measurement import (VisitTableMeasurementConfig, VisitTableMeasurementTask,
30 DetectorTableMeasurementConfig, DetectorTableMeasurementTask,
31 VisitMeasurementConfig, VisitMeasurementTask,
32 DetectorMeasurementConfig, DetectorMeasurementTask,
33 TractMeasurementConfig, TractMeasurementTask,
34 TractTableValueMeasurementConfig, TractTableValueMeasurementTask,
35 )
37TESTDIR = os.path.abspath(os.path.dirname(__file__))
38DATADIR = os.path.join(TESTDIR, 'data')
41class TaskTest(unittest.TestCase):
43 def load_data(self, key):
44 cat_file = self.file_map[key]
45 catalog = SimpleCatalog.readFits(os.path.join(DATADIR, cat_file))
46 return catalog
48 def setUp(self):
49 """This is called immediately before calling each test method."""
50 self.file_map = {'CatalogMeasurementBaseTask':
51 'src_HSC_i_HSC-I_903986_0_31_HSC_runs_ci_hsc_20210407T021858Z.fits'}
53 def testCatalogMeasurementBaseTask(self):
54 """Test run method of CatalogMeasurementBaseTask."""
55 catalog = self.load_data('CatalogMeasurementBaseTask')
56 config = CatalogMeasurementBaseConfig()
57 t = CatalogMeasurementBaseTask(config)
58 outputs = t.run(catalog=catalog)
59 expected = 771 * u.count
60 self.assertEqual(outputs.measurement.quantity, expected)
62 def testVisitTableMeasurementTask(self):
63 """Test run method of VisitTableMeasurementTask."""
64 catalog = self.load_data('CatalogMeasurementBaseTask')
65 config = VisitTableMeasurementConfig()
66 t = VisitTableMeasurementTask(config)
67 outputs = t.run(catalog=catalog)
68 expected = 771 * u.count
69 self.assertEqual(outputs.measurement.quantity, expected)
71 def testDetectorTableMeasurementTask(self):
72 """Test run method of VisitTableMeasurementTask."""
73 catalog = self.load_data('CatalogMeasurementBaseTask')
74 config = DetectorTableMeasurementConfig()
75 # For this test, we don't care that this is not a real detector column.
76 config.measure.columns = {"detector": "id"}
77 t = DetectorTableMeasurementTask(config)
78 outputs = t.run(catalog=catalog)
79 expected = 771 * u.count
80 self.assertEqual(outputs.measurement.quantity, expected)
82 def testTractMeasurementTask(self):
83 """Test run method of TractMeasurementTask."""
84 catalog = self.load_data('CatalogMeasurementBaseTask')
85 config = TractMeasurementConfig()
86 config.measure.retarget(NumSourcesMergeTask)
87 t = TractMeasurementTask(config)
88 outputs = t.run(
89 catalogs=[catalog, ],
90 photoCalibs=[None, ],
91 astromCalibs=[None, ],
92 dataIds=[{'band': 'r'}, ],
93 )
94 expected = 771 * u.count
95 self.assertEqual(outputs.measurement.quantity, expected)
97 def testTractTableValueMeasurementTask(self):
98 table = self.load_data('CatalogMeasurementBaseTask').asAstropy().to_pandas()
99 config = TractTableValueMeasurementConfig(
100 band_order=[''],
101 format_column='{band}{column}',
102 prefixes_column=[''],
103 row=0,
104 )
105 config.action.column = 'parent'
106 t = TractTableValueMeasurementTask(config=config)
107 outputs = t.run(table=table, bands=[''], name_metric='parent')
108 expected = 0 * u.Unit('')
109 self.assertEqual(outputs.measurement[0].quantity, expected)
111 def testVisitMeasurementTask(self):
112 """Test run method of VisitMeasurementTask."""
113 catalog = self.load_data('CatalogMeasurementBaseTask')
114 config = VisitMeasurementConfig()
115 config.measure.retarget(NumSourcesMergeTask)
116 t = VisitMeasurementTask(config)
117 outputs = t.run(
118 catalogs=[catalog, ],
119 photoCalibs=[None, ],
120 astromCalibs=[None, ],
121 dataIds=[{'band': 'r'}, ],
122 )
123 print(outputs)
124 expected = 771 * u.count
125 self.assertEqual(outputs.measurement.quantity, expected)
127 def testDetectorMeasurementTask(self):
128 """Test run method of DetectorMeasurementTask."""
129 catalog = self.load_data('CatalogMeasurementBaseTask')
130 config = DetectorMeasurementConfig()
131 t = DetectorMeasurementTask(config)
132 outputs = t.run(catalog=catalog)
133 expected = 771 * u.count
134 self.assertEqual(outputs.measurement.quantity, expected)
137if __name__ == "__main__": 137 ↛ 138line 137 didn't jump to line 138, because the condition on line 137 was never true
138 unittest.main()