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: TE1. 

23""" 

24 

25import unittest 

26import yaml 

27import os 

28 

29from lsst.utils import getPackageDir 

30from lsst.afw.table import SimpleCatalog 

31from lsst.faro.measurement import TExTask 

32 

33 

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

35 

36 

37class Te1Test(unittest.TestCase): 

38 

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 

46 

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 = {('TE1', 'i'): ('matchedCatalogTract_0_i.fits.gz', 'TE1_expected_0_i.yaml'), 

53 ('TE1', 'r'): ('matchedCatalogTract_0_r.fits.gz', 'TE1_expected_0_r.yaml')} 

54 

55 @classmethod 

56 def tearDownClass(cls): 

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

58 del cls.file_map 

59 super().tearDownClass() 

60 

61 def test_te1(self): 

62 """Test calculation of TE1 on a known catalog.""" 

63 config = TExTask.ConfigClass() 

64 # This is what makes it TE1 

65 config.annulus_r = 1.0 

66 config.comparison_operator = '<=' 

67 task = TExTask(config=config) 

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

69 catalog, expected = self.load_data(('TE1', band)) 

70 result = task.run(catalog, 'TE1') 

71 self.assertEqual(result.measurement, expected) 

72 

73 

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

75 unittest.main()