Coverage for tests/test_tasks.py: 32%
Shortcuts on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
Shortcuts on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
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,)
35TESTDIR = os.path.abspath(os.path.dirname(__file__))
36DATADIR = os.path.join(TESTDIR, 'data')
39class TaskTest(unittest.TestCase):
41 def load_data(self, key):
42 cat_file = self.file_map[key]
43 catalog = SimpleCatalog.readFits(os.path.join(DATADIR, cat_file))
44 return catalog
46 def setUp(self):
47 """This is called immediately before calling each test method."""
48 self.file_map = {'CatalogMeasurementBaseTask':
49 'src_HSC_i_HSC-I_903986_0_31_HSC_runs_ci_hsc_20210407T021858Z.fits'}
51 def testCatalogMeasurementBaseTask(self):
52 """Test run method of CatalogMeasurementBaseTask."""
53 catalog = self.load_data('CatalogMeasurementBaseTask')
54 config = CatalogMeasurementBaseConfig()
55 t = CatalogMeasurementBaseTask(config)
56 outputs = t.run(catalog=catalog)
57 expected = 771 * u.count
58 self.assertEqual(outputs.measurement.quantity, expected)
60 def testVisitTableMeasurementTask(self):
61 """Test run method of VisitTableMeasurementTask."""
62 catalog = self.load_data('CatalogMeasurementBaseTask')
63 config = VisitTableMeasurementConfig()
64 t = VisitTableMeasurementTask(config)
65 outputs = t.run(catalog=catalog)
66 expected = 771 * u.count
67 self.assertEqual(outputs.measurement.quantity, expected)
69 def testDetectorTableMeasurementTask(self):
70 """Test run method of VisitTableMeasurementTask."""
71 catalog = self.load_data('CatalogMeasurementBaseTask')
72 config = DetectorTableMeasurementConfig()
73 t = DetectorTableMeasurementTask(config)
74 outputs = t.run(catalog=catalog)
75 expected = 771 * u.count
76 self.assertEqual(outputs.measurement.quantity, expected)
78 def testTractMeasurementTask(self):
79 """Test run method of TractMeasurementTask."""
80 catalog = self.load_data('CatalogMeasurementBaseTask')
81 config = TractMeasurementConfig()
82 config.measure.retarget(NumSourcesMergeTask)
83 t = TractMeasurementTask(config)
84 outputs = t.run(
85 catalogs=[catalog, ],
86 photoCalibs=[None, ],
87 astromCalibs=[None, ],
88 dataIds=[{'band': 'r'}, ],
89 )
90 expected = 771 * u.count
91 self.assertEqual(outputs.measurement.quantity, expected)
93 def testVisitMeasurementTask(self):
94 """Test run method of VisitMeasurementTask."""
95 catalog = self.load_data('CatalogMeasurementBaseTask')
96 config = VisitMeasurementConfig()
97 config.measure.retarget(NumSourcesMergeTask)
98 t = VisitMeasurementTask(config)
99 outputs = t.run(
100 catalogs=[catalog, ],
101 photoCalibs=[None, ],
102 astromCalibs=[None, ],
103 dataIds=[{'band': 'r'}, ],
104 )
105 print(outputs)
106 expected = 771 * u.count
107 self.assertEqual(outputs.measurement.quantity, expected)
109 def testDetectorMeasurementTask(self):
110 """Test run method of DetectorMeasurementTask."""
111 catalog = self.load_data('CatalogMeasurementBaseTask')
112 config = DetectorMeasurementConfig()
113 t = DetectorMeasurementTask(config)
114 outputs = t.run(catalog=catalog)
115 expected = 771 * u.count
116 self.assertEqual(outputs.measurement.quantity, expected)
119if __name__ == "__main__": 119 ↛ 120line 119 didn't jump to line 120, because the condition on line 119 was never true
120 unittest.main()