Coverage for tests/test_ellipKPM.py: 48%

Shortcuts 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

40 statements  

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

21 

22"""Unit tests for the metrics measurement system: TE1. 

23""" 

24 

25import unittest 

26import yaml 

27import os 

28import logging 

29 

30from lsst.afw.table import SimpleCatalog 

31from lsst.faro.measurement import TExTask 

32from lsst.faro.utils.calibrated_catalog import CalibratedCatalog 

33 

34log = logging.getLogger(__name__) 

35 

36TESTDIR = os.path.abspath(os.path.dirname(__file__)) 

37DATADIR = os.path.join(TESTDIR, 'data') 

38 

39 

40class Te1Test(unittest.TestCase): 

41 

42 def load_data(self, key): 

43 """Load data to process along with 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 """Setup initial state that is used by all test methods.""" 

53 super().setUpClass() 

54 cls.file_map = {('TE1', 'i'): 

55 ('src_HSC_i_HSC-I_903986_0_31_HSC_runs_ci_hsc_20210407T021858Z.fits', 

56 'TE1_expected_0_i.yaml')} 

57 

58 @classmethod 

59 def tearDownClass(cls): 

60 """Delete any variables set in setUpClass.""" 

61 del cls.file_map 

62 super().tearDownClass() 

63 

64 def test_te1(self): 

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

66 config = TExTask.ConfigClass() 

67 # This is what makes it TE1 

68 config.minSep = 0.25 

69 config.maxSep = 1.0 

70 config.brute = True 

71 task = TExTask(config=config) 

72 for band in ('i',): 

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

74 result = task.run('TE1', {'i': [CalibratedCatalog(catalog), ]}) 

75 log.debug('result: ', result) 

76 log.debug('expected: ', expected) 

77 self.assertAlmostEqual(result.measurement, expected, places=10) 

78 

79 

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

81 unittest.main()