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'): 

53 ('src_HSC_i_HSC-I_903986_0_31_HSC_runs_ci_hsc_20210407T021858Z.fits', 

54 'TE1_expected_0_i.yaml')} 

55 

56 @classmethod 

57 def tearDownClass(cls): 

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

59 del cls.file_map 

60 super().tearDownClass() 

61 

62 def test_te1(self): 

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

64 config = TExTask.ConfigClass() 

65 # This is what makes it TE1 

66 config.minSep = 0.25 

67 config.maxSep = 1.0 

68 task = TExTask(config=config) 

69 for band in ('i'): 

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

71 result = task.run('TE1', [catalog]) 

72 print('result', result) 

73 print('expected', expected) 

74 self.assertEqual(result.measurement, expected) 

75 

76 

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

78 unittest.main()