Coverage for tests/test_ellipKPM.py: 49%

41 statements  

« prev     ^ index     » next       coverage.py v7.4.4, created at 2024-04-04 04:01 -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/>. 

21 

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

23""" 

24 

25import unittest 

26import yaml 

27import os 

28import logging 

29import numpy as np 

30 

31from lsst.afw.table import SimpleCatalog 

32from lsst.faro.measurement import TExTask 

33from lsst.faro.utils.calibrated_catalog import CalibratedCatalog 

34 

35log = logging.getLogger(__name__) 

36 

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

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

39 

40 

41class Te1Test(unittest.TestCase): 

42 

43 def load_data(self, key): 

44 """Load data to process along with the expected value.""" 

45 cat_file, expected_file = self.file_map[key] 

46 catalog = SimpleCatalog.readFits(os.path.join(DATADIR, cat_file)) 

47 with open(os.path.join(DATADIR, expected_file), 'r') as fh: 

48 expected = yaml.load(fh, Loader=yaml.FullLoader) 

49 return catalog, expected 

50 

51 @classmethod 

52 def setUpClass(cls): 

53 """Setup initial state that is used by all test methods.""" 

54 super().setUpClass() 

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

56 ('src_HSC_i_HSC-I_903986_0_31_HSC_runs_ci_hsc_20210407T021858Z.fits', 

57 'TE1_expected_0_i.yaml')} 

58 

59 @classmethod 

60 def tearDownClass(cls): 

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

62 del cls.file_map 

63 super().tearDownClass() 

64 

65 def test_te1(self): 

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

67 config = TExTask.ConfigClass() 

68 # This is what makes it TE1 

69 config.minSep = 0.25 

70 config.maxSep = 1.0 

71 config.brute = True 

72 task = TExTask(config=config) 

73 for band in ('i',): 

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

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

76 log.debug('result: %s', result.measurement) 

77 log.debug('expected: %s', expected) 

78 np.testing.assert_almost_equal(result.measurement.quantity, expected.quantity, decimal=5) 

79 

80 

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

82 unittest.main()