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

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

70

71

72

73

74

75

76

77

78

79

80

81

82

83

84

85

86

87

88

89

90

91

92

93

94

95

96

97

98

99

100

101

102

103

104

105

106

107

108

109

110

111

112

113

114

115

116

117

118

119

120

121

122

123

124

125

126

127

128

129

130

131

# This file is part of pipe_tasks. 

# 

# Developed for the LSST Data Management System. 

# This product includes software developed by the LSST Project 

# (https://www.lsst.org). 

# See the COPYRIGHT file at the top-level directory of this distribution 

# for details of code ownership. 

# 

# This program is free software: you can redistribute it and/or modify 

# it under the terms of the GNU General Public License as published by 

# the Free Software Foundation, either version 3 of the License, or 

# (at your option) any later version. 

# 

# This program is distributed in the hope that it will be useful, 

# but WITHOUT ANY WARRANTY; without even the implied warranty of 

# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 

# GNU General Public License for more details. 

# 

# You should have received a copy of the GNU General Public License 

# along with this program. If not, see <https://www.gnu.org/licenses/>. 

 

import unittest 

 

import lsst.utils.tests 

 

from lsst.pipe.tasks.dcrAssembleCoadd import DcrAssembleCoaddTask, DcrAssembleCoaddConfig 

 

 

class DcrAssembleCoaddCalculateGainTestCase(lsst.utils.tests.TestCase): 

"""Tests of dcrAssembleCoaddTask.calculateGain().""" 

def setUp(self): 

self.baseGain = 0.5 

self.gainList = [self.baseGain, self.baseGain] 

self.convergenceList = [0.2] 

# Calculate the convergence we would expect if the model was converging perfectly, 

# so that the improvement is limited only by our conservative gain. 

for i in range(2): 

self.convergenceList.append(self.convergenceList[i]/(self.baseGain + 1)) 

self.nextGain = (1 + self.baseGain) / 2 

 

self.config = DcrAssembleCoaddConfig() 

self.task = DcrAssembleCoaddTask(config=self.config) 

 

def testUnbalancedLists(self): 

gainList = [1, 2, 3, 4] 

convergenceList = [1, 2] 

with self.assertRaises(ValueError): 

self.task.calculateGain(convergenceList, gainList) 

 

def testNoProgressiveGain(self): 

self.config.useProgressiveGain = False 

self.config.baseGain = self.baseGain 

expectGain = self.baseGain 

expectGainList = self.gainList + [expectGain] 

result = self.task.calculateGain(self.convergenceList, self.gainList) 

self.assertEqual(result, expectGain) 

self.assertEqual(self.gainList, expectGainList) 

 

def testBaseGainNone(self): 

"""If baseGain is None, gain is calculated from the default values.""" 

self.config.useProgressiveGain = False 

expectGain = 1 / (self.config.dcrNumSubfilters - 1) 

expectGainList = self.gainList + [expectGain] 

result = self.task.calculateGain(self.convergenceList, self.gainList) 

self.assertEqual(result, expectGain) 

self.assertEqual(self.gainList, expectGainList) 

 

def testProgressiveFirstStep(self): 

"""The first and second steps always return baseGain.""" 

convergenceList = self.convergenceList[:1] 

gainList = [] 

self.config.baseGain = self.baseGain 

expectGain = self.baseGain 

expectGainList = [expectGain] 

result = self.task.calculateGain(convergenceList, gainList) 

self.assertEqual(result, expectGain) 

self.assertEqual(gainList, expectGainList) 

 

def testProgressiveSecondStep(self): 

"""The first and second steps always return baseGain.""" 

convergenceList = self.convergenceList[:2] 

gainList = self.gainList[:1] 

self.config.baseGain = self.baseGain 

expectGain = self.baseGain 

expectGainList = gainList + [expectGain] 

result = self.task.calculateGain(convergenceList, gainList) 

self.assertEqual(result, expectGain) 

self.assertEqual(gainList, expectGainList) 

 

def testProgressiveGain(self): 

"""Test that gain follows the "perfect" situation defined in setUp.""" 

self.config.baseGain = self.baseGain 

expectGain = self.nextGain 

expectGainList = self.gainList + [expectGain] 

result = self.task.calculateGain(self.convergenceList, self.gainList) 

self.assertFloatsAlmostEqual(result, expectGain) 

self.assertEqual(self.gainList, expectGainList) 

 

def testProgressiveGainBadFit(self): 

"""Test that gain is reduced if the predicted convergence does not 

match the measured convergence (in this case, converging too quickly). 

""" 

wrongGain = 1.0 

gainList = [self.baseGain, self.baseGain] 

convergenceList = [0.2] 

for i in range(2): 

convergenceList.append(convergenceList[i]/(wrongGain + 1)) 

# The below math is a simplified version of the full algorithm, 

# assuming the predicted convergence is zero. 

# Note that in this case, nextGain is smaller than wrongGain. 

nextGain = (self.baseGain + (1 + self.baseGain) / (1 + wrongGain)) / 2 

 

self.config.baseGain = self.baseGain 

expectGain = nextGain 

expectGainList = self.gainList + [expectGain] 

result = self.task.calculateGain(convergenceList, gainList) 

self.assertFloatsAlmostEqual(result, nextGain) 

self.assertEqual(gainList, expectGainList) 

 

 

def setup_module(module): 

lsst.utils.tests.init() 

 

 

class MatchMemoryTestCase(lsst.utils.tests.MemoryTestCase): 

pass 

 

 

129 ↛ 130line 129 didn't jump to line 130, because the condition on line 129 was never trueif __name__ == "__main__": 

lsst.utils.tests.init() 

unittest.main()