Coverage for tests/test_trailedSourceFilter.py: 32%

46 statements  

« prev     ^ index     » next       coverage.py v7.3.2, created at 2023-10-11 11:00 +0000

1# This file is part of ap_association. 

2# 

3# Developed for the LSST Data Management System. 

4# This product includes software developed by the LSST Project 

5# (https://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 <https://www.gnu.org/licenses/>. 

21 

22import unittest 

23from lsst.ap.association import TrailedSourceFilterTask 

24import numpy as np 

25import pandas as pd 

26import lsst.utils.tests 

27 

28 

29class TestTrailedSourceFilterTask(unittest.TestCase): 

30 

31 def setUp(self): 

32 """Create sets of diaSources. 

33 

34 The trail lengths of the dia sources are 0, 5.5, 11, 16.5, 21.5 

35 arcseconds. 

36 """ 

37 rng = np.random.default_rng(1234) 

38 scatter = 0.1 / 3600 

39 self.nSources = 5 

40 self.diaSources = pd.DataFrame(data=[ 

41 {"ra": 0.04*idx + scatter*rng.uniform(-1, 1), 

42 "dec": 0.04*idx + scatter*rng.uniform(-1, 1), 

43 "diaSourceId": idx, "diaObjectId": 0, "trailLength": 5.5*idx} 

44 for idx in range(self.nSources)]) 

45 self.exposure_time = 30.0 

46 

47 def test_run(self): 

48 """Run trailedSourceFilterTask with the default max distance. 

49 

50 With the default settings and an exposure of 30 seconds, the max trail 

51 length is 12.5 arcseconds. Two out of five of the diaSources will be 

52 filtered out of the final results and put into results.trailedSources. 

53 """ 

54 trailedSourceFilterTask = TrailedSourceFilterTask() 

55 results = trailedSourceFilterTask.run(self.diaSources, self.exposure_time) 

56 

57 self.assertEqual(len(results.diaSources), 3) 

58 np.testing.assert_array_equal(results.diaSources['diaSourceId'].values, [0, 1, 2]) 

59 np.testing.assert_array_equal(results.trailedDiaSources['diaSourceId'].values, [3, 4]) 

60 

61 def test_run_short_max_trail(self): 

62 """Run trailedSourceFilterTask with aggressive trail length cutoff 

63 

64 With a max_trail_length config of 0.01 arcseconds/second and an 

65 exposure of 30 seconds,the max trail length is 0.3 arcseconds. Only the 

66 source with a trail of 0 stays in the catalog and the rest are filtered 

67 out and put into results.trailedSources. 

68 """ 

69 config = TrailedSourceFilterTask.ConfigClass() 

70 config.max_trail_length = 0.01 

71 trailedSourceFilterTask = TrailedSourceFilterTask(config=config) 

72 results = trailedSourceFilterTask.run(self.diaSources, self.exposure_time) 

73 

74 self.assertEqual(len(results.diaSources), 1) 

75 np.testing.assert_array_equal(results.diaSources['diaSourceId'].values, [0]) 

76 np.testing.assert_array_equal(results.trailedDiaSources['diaSourceId'].values, [1, 2, 3, 4]) 

77 

78 def test_run_no_trails(self): 

79 """Run trailedSourceFilterTask with a long trail length so that 

80 every source in the catalog is in the final diaSource catalog. 

81 

82 With a max_trail_length config of 10 arcseconds/second and an 

83 exposure of 30 seconds,the max trail length is 300 arcseconds. All 

84 sources in the initial catalog should be in the final diaSource 

85 catalog. 

86 """ 

87 config = TrailedSourceFilterTask.ConfigClass() 

88 config.max_trail_length = 10.00 

89 trailedSourceFilterTask = TrailedSourceFilterTask(config=config) 

90 results = trailedSourceFilterTask.run(self.diaSources, self.exposure_time) 

91 

92 self.assertEqual(len(results.diaSources), 5) 

93 self.assertEqual(len(results.trailedDiaSources), 0) 

94 np.testing.assert_array_equal(results.diaSources["diaSourceId"].values, [0, 1, 2, 3, 4]) 

95 np.testing.assert_array_equal(results.trailedDiaSources["diaSourceId"].values, []) 

96 

97 def test_check_dia_source_trail(self): 

98 """Test the source trail mask filter. 

99 

100 Test that the mask filter returns the expected mask array. 

101 """ 

102 trailedSourceFilterTask = TrailedSourceFilterTask() 

103 mask = trailedSourceFilterTask._check_dia_source_trail(self.diaSources, self.exposure_time) 

104 np.testing.assert_array_equal(mask, [False, False, False, True, True]) 

105 

106 

107class MemoryTester(lsst.utils.tests.MemoryTestCase): 

108 pass 

109 

110 

111def setup_module(module): 

112 lsst.utils.tests.init() 

113 

114 

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

116 lsst.utils.tests.init() 

117 unittest.main()