Coverage for tests/test_photKPM.py: 44%
43 statements
« prev ^ index » next coverage.py v7.3.2, created at 2023-11-24 10:37 +0000
« prev ^ index » next coverage.py v7.3.2, created at 2023-11-24 10:37 +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# (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: PA1, PF1.
23"""
25import unittest
26import yaml
27import os
28import random
30from lsst.afw.table import SimpleCatalog
31from lsst.faro.measurement import PA1Task, PF1Task
33# Make sure measurements are deterministic
34random.seed(8675309)
36TESTDIR = os.path.abspath(os.path.dirname(__file__))
37DATADIR = os.path.join(TESTDIR, 'data')
40class Pa1Test(unittest.TestCase):
42 def load_data(self, key):
43 '''Helper to load data to process and the expected value.'''
44 cat_file, expected_file = self.file_map[key]
45 catalog = SimpleCatalog.readFits(os.path.join(DATADIR, cat_file))
46 with open(os.path.join(DATADIR, expected_file), 'r') as fh:
47 expected = yaml.load(fh, Loader=yaml.FullLoader)
48 return catalog, expected
50 @classmethod
51 def setUpClass(cls):
52 '''This gets called once so can be used to set up
53 state that is used by all test methods.'''
54 super().setUpClass()
55 cls.file_map = {('PA1', 'i'): ('matchedCatalogTract_0_i.fits.gz', 'PA1_expected_0_i.yaml'),
56 ('PA1', 'r'): ('matchedCatalogTract_0_r.fits.gz', 'PA1_expected_0_r.yaml'),
57 ('PF1', 'i'): ('matchedCatalogTract_0_i.fits.gz',
58 'PF1_expected_0_i.yaml'),
59 ('PF1', 'r'): ('matchedCatalogTract_0_r.fits.gz',
60 'PF1_expected_0_r.yaml')}
62 @classmethod
63 def tearDownClass(cls):
64 '''Delete any variables set in setUpClass.'''
65 del cls.file_map
66 super().tearDownClass()
68 def test_pa1(self):
69 """Test calculation of pa1 on a known catalog."""
70 config = PA1Task.ConfigClass()
71 config.nMinPhotRepeat = 10
72 task = PA1Task(config=config)
73 for band in ('i', 'r'):
74 catalog, expected = self.load_data(('PA1', band))
75 result = task.run('PA1', catalog)
76 self.assertEqual(result.measurement, expected)
78 def test_pf1(self):
79 """Test calculation of pf1 on a known catalog."""
80 config = PF1Task.ConfigClass()
81 config.nMinPhotRepeat = 10
82 task = PF1Task(config=config)
83 for band in ('i', 'r'):
84 catalog, expected = self.load_data(('PF1', band))
85 result = task.run('PF1', catalog)
86 self.assertEqual(result.measurement, expected)
89if __name__ == "__main__": 89 ↛ 90line 89 didn't jump to line 90, because the condition on line 89 was never true
90 unittest.main()