Coverage for tests/test_astromKPM.py: 30%
58 statements
« prev ^ index » next coverage.py v7.2.5, created at 2023-05-09 03:07 -0700
« prev ^ index » next coverage.py v7.2.5, created at 2023-05-09 03:07 -0700
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: AMx.
23"""
25import unittest
26import yaml
27import os
28import astropy.units as u
30from lsst.afw.table import SimpleCatalog
31from lsst.faro.measurement import AMxTask, ADxTask, AFxTask, AB1Task
33TESTDIR = os.path.abspath(os.path.dirname(__file__))
34DATADIR = os.path.join(TESTDIR, 'data')
37class AmxTest(unittest.TestCase):
39 def load_data(self, key):
40 '''Helper to load data to process and the expected value.'''
41 cat_file, expected_file = self.file_map[key]
42 catalog = SimpleCatalog.readFits(os.path.join(DATADIR, cat_file))
43 with open(os.path.join(DATADIR, expected_file), 'r') as fh:
44 expected = yaml.load(fh, Loader=yaml.FullLoader)
45 return catalog, expected
47 @classmethod
48 def setUpClass(cls):
49 '''This gets called once so can be used to set up
50 state that is used by all test methods.'''
51 super().setUpClass()
52 cls.file_map = {('AM1', 'i'): ('matchedCatalogTract_0_i.fits.gz', 'AM1_expected_0_i.yaml'),
53 ('AM1', 'r'): ('matchedCatalogTract_0_r.fits.gz', 'AM1_expected_0_r.yaml'),
54 ('AD1', 'i'): ('matchedCatalogTract_0_i.fits.gz', 'AD1_design_expected_0_i.yaml'),
55 ('AD1', 'r'): ('matchedCatalogTract_0_r.fits.gz', 'AD1_design_expected_0_r.yaml'),
56 ('AF1', 'i'): ('matchedCatalogTract_0_i.fits.gz', 'AF1_design_expected_0_i.yaml'),
57 ('AF1', 'r'): ('matchedCatalogTract_0_r.fits.gz', 'AF1_design_expected_0_r.yaml'),
58 ('AB1', 'i'): ('matchedCatalogMulti_0_70.fits.gz',
59 'AB1_design_expected_0_70_i.yaml'),
60 ('AB1', 'r'): ('matchedCatalogMulti_0_70.fits.gz',
61 'AB1_design_expected_0_70_r.yaml')}
63 @classmethod
64 def tearDownClass(cls):
65 '''Delete any variables set in setUpClass.'''
66 del cls.file_map
67 super().tearDownClass()
69 def test_am1(self):
70 """Test calculation of am1 on a known catalog."""
71 config = AMxTask.ConfigClass()
72 config.annulus_r = 5.0 # This is what makes it AM1
73 task = AMxTask(config=config)
74 for band in ('i', 'r'):
75 catalog, expected = self.load_data(('AM1', band))
76 result = task.run('AM1', catalog)
77 self.assertEqual(result.measurement, expected)
78 self.assertTrue(u.allclose(result.measurement.extras['values'].quantity,
79 expected.extras['values'].quantity))
81 def test_af1(self):
82 """Test calculation of af1 on a known catalog."""
83 config = AFxTask.ConfigClass()
84 config.annulus_r = 5.0 # This is what makes it AF1
85 task = AFxTask(config=config)
86 for band in ('i', 'r'):
87 catalog, expected = self.load_data(('AF1', band))
88 result = task.run('AF1_design', catalog)
89 self.assertEqual(result.measurement, expected)
91 def test_ad1(self):
92 """Test calculation of ad1 on a known catalog."""
93 config = ADxTask.ConfigClass()
94 config.annulus_r = 5.0 # This is what makes it AD1
95 task = ADxTask(config=config)
96 for band in ('i', 'r'):
97 catalog, expected = self.load_data(('AD1', band))
98 result = task.run('AD1_design', catalog)
99 self.assertEqual(result.measurement, expected)
101 def test_ab1(self):
102 """Test calculation of ab1 on a known catalog."""
103 config = AB1Task.ConfigClass()
104 task = AB1Task(config=config)
105 for band in ('i', 'r'):
106 catalog, expected = self.load_data(('AB1', band))
107 result = task.run('AB1_design', catalog, in_id={'this': 'is ignored'},
108 out_id={'band': band})
109 self.assertEqual(result.measurement, expected)
112if __name__ == "__main__": 112 ↛ 113line 112 didn't jump to line 113, because the condition on line 112 was never true
113 unittest.main()