Hide keyboard shortcuts

Hot-keys 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 <REPLACE WHEN RENAMED>. 

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/>. 

21 

22"""Unit tests for the metrics measurement system: PA1, PA2, PF1. 

23""" 

24 

25import unittest 

26import yaml 

27import os 

28import random 

29 

30from lsst.utils import getPackageDir 

31from lsst.afw.table import SimpleCatalog 

32from lsst.faro.measurement import PA1Task, PA2Task, PF1Task 

33 

34# Make sure measurements are deterministic 

35random.seed(8675309) 

36 

37DATADIR = os.path.join(getPackageDir('faro'), 'tests', 'data') 

38 

39 

40class Pa1Test(unittest.TestCase): 

41 

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 

49 

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 ('PA2', 'i'): ('matchedCatalogTract_0_i.fits.gz', 

58 'PA2_expected_0_i.yaml'), 

59 ('PA2', 'r'): ('matchedCatalogTract_0_r.fits.gz', 

60 'PA2_expected_0_r.yaml'), 

61 ('PF1', 'i'): ('matchedCatalogTract_0_i.fits.gz', 

62 'PF1_expected_0_i.yaml'), 

63 ('PF1', 'r'): ('matchedCatalogTract_0_r.fits.gz', 

64 'PF1_expected_0_r.yaml')} 

65 

66 @classmethod 

67 def tearDownClass(cls): 

68 '''Delete any variables set in setUpClass.''' 

69 del cls.file_map 

70 super().tearDownClass() 

71 

72 def test_pa1(self): 

73 """Test calculation of pa1 on a known catalog.""" 

74 config = PA1Task.ConfigClass() 

75 task = PA1Task(config=config) 

76 for band in ('i', 'r'): 

77 catalog, expected = self.load_data(('PA1', band)) 

78 result = task.run(catalog, 'PA1') 

79 self.assertEqual(result.measurement, expected) 

80 

81 def test_pa2(self): 

82 """Test calculation of pa2 on a known catalog.""" 

83 config = PA2Task.ConfigClass() 

84 task = PA2Task(config=config) 

85 for band in ('i', 'r'): 

86 catalog, expected = self.load_data(('PA2', band)) 

87 result = task.run(catalog, 'PA2') 

88 self.assertEqual(result.measurement, expected) 

89 

90 def test_pf1(self): 

91 """Test calculation of pf1 on a known catalog.""" 

92 config = PF1Task.ConfigClass() 

93 task = PF1Task(config=config) 

94 for band in ('i', 'r'): 

95 catalog, expected = self.load_data(('PF1', band)) 

96 result = task.run(catalog, 'PF1') 

97 self.assertEqual(result.measurement, expected) 

98 

99 

100if __name__ == "__main__": 100 ↛ 101line 100 didn't jump to line 101, because the condition on line 100 was never true

101 unittest.main()