Coverage for tests/test_phot_util.py: 44%

28 statements  

« prev     ^ index     » next       coverage.py v6.5.0, created at 2023-01-19 03:06 -0800

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. 

23""" 

24 

25import unittest 

26import os 

27import numpy as np 

28import astropy.units as u 

29 

30from lsst.afw.table import SimpleCatalog, GroupView 

31from lsst.faro.utils.phot_repeat import calcPhotRepeat 

32 

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

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

35 

36 

37class PhotUtilTest(unittest.TestCase): 

38 """Test photometric utility functions.""" 

39 

40 def load_data(self): 

41 '''Helper to load data to process.''' 

42 cat_file = 'matchedCatalogTract_0_i.fits.gz' 

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

44 matches = GroupView.build(catalog) 

45 

46 magKey = matches.schema.find('slot_PsfFlux_mag').key 

47 nMatchesRequired = 2 

48 

49 def nMatchFilter(cat): 

50 if len(cat) < nMatchesRequired: 

51 return False 

52 return np.isfinite(cat.get(magKey)).all() 

53 

54 return matches.where(nMatchFilter), magKey 

55 

56 def test_calcPhotRepeat(self): 

57 """Test photometric repeatability for multiple realizations 

58 of random pairs of visits.""" 

59 

60 expected = 56.069125538189226 * u.mmag 

61 matches, magKey = self.load_data() 

62 result = calcPhotRepeat(matches, magKey) 

63 self.assertEqual(result['repeatability'], expected) 

64 

65 

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

67 unittest.main()