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

132

133

134

135

136

137

138

139

140

141

142

143

144

145

146

147

148

149

150

151

152

153

154

155

156

157

158

159

160

161

162

163

164

165

166

167

168

169

170

171

172

173

174

175

176

177

178

179

180

181

182

183

184

185

186

187

188

189

190

191

192

193

194

195

196

197

198

199

200

201

202

203

204

205

206

207

208

209

210

from builtins import zip 

import matplotlib 

matplotlib.use("Agg") 

import numpy as np 

import unittest 

import lsst.sims.maf.metrics as metrics 

import lsst.sims.maf.stackers as stackers 

import lsst.utils.tests 

from builtins import str 

 

 

class TestCalibrationMetrics(unittest.TestCase): 

 

def testParallaxMetric(self): 

""" 

Test the parallax metric. 

""" 

names = ['observationStartMJD', 'finSeeing', 'fiveSigmaDepth', 'fieldRA', 'fieldDec', 'filter'] 

types = [float, float, float, float, float, (np.str_, 1)] 

data = np.zeros(700, dtype=list(zip(names, types))) 

slicePoint = {'sid': 0} 

data['observationStartMJD'] = np.arange(700)+56762 

data['finSeeing'] = 0.7 

data['filter'][0:100] = str('r') 

data['filter'][100:200] = str('u') 

data['filter'][200:] = str('g') 

data['fiveSigmaDepth'] = 24. 

stacker = stackers.ParallaxFactorStacker() 

data = stacker.run(data) 

normFlags = [False, True] 

for flag in normFlags: 

data['finSeeing'] = 0.7 

data['fiveSigmaDepth'] = 24. 

baseline = metrics.ParallaxMetric(normalize=flag, seeingCol='finSeeing').run(data, slicePoint) 

data['finSeeing'] = data['finSeeing']+.3 

worse1 = metrics.ParallaxMetric(normalize=flag, seeingCol='finSeeing').run(data, slicePoint) 

worse2 = metrics.ParallaxMetric(normalize=flag, rmag=22., 

seeingCol='finSeeing').run(data, slicePoint) 

worse3 = metrics.ParallaxMetric(normalize=flag, rmag=22., 

seeingCol='finSeeing').run(data[0:300], slicePoint) 

data['fiveSigmaDepth'] = data['fiveSigmaDepth']-1. 

worse4 = metrics.ParallaxMetric(normalize=flag, rmag=22., 

seeingCol='finSeeing').run(data[0:300], slicePoint) 

# Make sure the RMS increases as seeing increases, the star gets fainter, 

# the background gets brighter, or the baseline decreases. 

if flag: 

pass 

else: 

assert(worse1 > baseline) 

assert(worse2 > worse1) 

assert(worse3 > worse2) 

assert(worse4 > worse3) 

 

def testProperMotionMetric(self): 

""" 

Test the ProperMotion metric. 

""" 

names = ['observationStartMJD', 'finSeeing', 'fiveSigmaDepth', 'fieldRA', 'fieldDec', 'filter'] 

types = [float, float, float, float, float, (np.str_, 1)] 

data = np.zeros(700, dtype=list(zip(names, types))) 

slicePoint = [0] 

stacker = stackers.ParallaxFactorStacker() 

normFlags = [False, True] 

data['observationStartMJD'] = np.arange(700)+56762 

data['finSeeing'] = 0.7 

data['filter'][0:100] = str('r') 

data['filter'][100:200] = str('u') 

data['filter'][200:] = str('g') 

data['fiveSigmaDepth'] = 24. 

data = stacker.run(data) 

for flag in normFlags: 

data['finSeeing'] = 0.7 

data['fiveSigmaDepth'] = 24 

baseline = metrics.ProperMotionMetric(normalize=flag, seeingCol='finSeeing').run(data, slicePoint) 

data['finSeeing'] = data['finSeeing']+.3 

worse1 = metrics.ProperMotionMetric(normalize=flag, seeingCol='finSeeing').run(data, slicePoint) 

worse2 = metrics.ProperMotionMetric(normalize=flag, rmag=22., 

seeingCol='finSeeing').run(data, slicePoint) 

worse3 = metrics.ProperMotionMetric(normalize=flag, rmag=22., 

seeingCol='finSeeing').run(data[0:300], slicePoint) 

data['fiveSigmaDepth'] = data['fiveSigmaDepth']-1. 

worse4 = metrics.ProperMotionMetric(normalize=flag, rmag=22., 

seeingCol='finSeeing').run(data[0:300], slicePoint) 

# Make sure the RMS increases as seeing increases, the star gets fainter, 

# the background gets brighter, or the baseline decreases. 

if flag: 

# When normalized, mag of star and m5 don't matter (just scheduling). 

self.assertAlmostEqual(worse2, worse1) 

self.assertAlmostEqual(worse4, worse3) 

# But using fewer points should make proper motion worse. 

# survey assumed to have same seeing and limiting mags. 

assert(worse3 < worse2) 

else: 

assert(worse1 > baseline) 

assert(worse2 > worse1) 

assert(worse3 > worse2) 

assert(worse4 > worse3) 

 

def testParallaxCoverageMetric(self): 

""" 

Test the parallax coverage 

""" 

names = ['observationStartMJD', 'finSeeing', 'fiveSigmaDepth', 'fieldRA', 'fieldDec', 

'filter', 'ra_pi_amp', 'dec_pi_amp'] 

types = [float, float, float, float, float, '<U1', float, float] 

data = np.zeros(100, dtype=list(zip(names, types))) 

data['filter'] = 'r' 

data['fiveSigmaDepth'] = 25. 

data['ra_pi_amp'] = 1. 

data['dec_pi_amp'] = 1. 

 

# All the parallax amplitudes are the same, should return zero 

metric = metrics.ParallaxCoverageMetric(seeingCol='finSeeing') 

val = metric.run(data) 

assert(val == 0) 

 

# Half at (1,1), half at (0.5,0.5) 

data['ra_pi_amp'][0:50] = 1 

data['dec_pi_amp'][0:50] = 1 

data['ra_pi_amp'][50:] = -1 

data['dec_pi_amp'][50:] = -1 

val = metric.run(data) 

self.assertAlmostEqual(val, 2.**0.5) 

 

data['ra_pi_amp'][0:50] = 0.5 

data['dec_pi_amp'][0:50] = 0.5 

data['ra_pi_amp'][50:] = -0.5 

data['dec_pi_amp'][50:] = -0.5 

val = metric.run(data) 

self.assertAlmostEqual(val, 0.5*2**0.5) 

 

data['ra_pi_amp'][0:50] = 1 

data['dec_pi_amp'][0:50] = 0 

data['ra_pi_amp'][50:] = -1 

data['dec_pi_amp'][50:] = 0 

val = metric.run(data) 

assert(val == 1) 

 

def testParallaxDcrDegenMetric(self): 

""" 

Test the parallax-DCR degeneracy metric 

""" 

names = ['observationStartMJD', 'finSeeing', 'fiveSigmaDepth', 'fieldRA', 'fieldDec', 

'filter', 'ra_pi_amp', 'dec_pi_amp', 'ra_dcr_amp', 'dec_dcr_amp'] 

types = [float, float, float, float, float, '<U1', float, 

float, float, float] 

data = np.zeros(100, dtype=list(zip(names, types))) 

data['filter'] = 'r' 

data['fiveSigmaDepth'] = 25. 

 

# Set so ra is perfecly correlated 

data['ra_pi_amp'] = 1. 

data['dec_pi_amp'] = 0.01 

data['ra_dcr_amp'] = 0.2 

 

metric = metrics.ParallaxDcrDegenMetric(seeingCol='finSeeing') 

val = metric.run(data) 

np.testing.assert_almost_equal(np.abs(val), 1., decimal=2) 

 

# set so the offsets are always nearly perpendicular 

data['ra_pi_amp'] = 0.001 

data['dec_pi_amp'] = 1. 

data['ra_dcr_amp'] = 0.2 

 

metric = metrics.ParallaxDcrDegenMetric(seeingCol='finSeeing') 

val = metric.run(data) 

np.testing.assert_almost_equal(val, 0., decimal=2) 

 

# Generate a random distribution that should have little or no correlation 

rng = np.random.RandomState(42) 

 

data['ra_pi_amp'] = rng.rand(100)*2-1. 

data['dec_pi_amp'] = rng.rand(100)*2-1. 

data['ra_dcr_amp'] = rng.rand(100)*2-1. 

data['dec_dcr_amp'] = rng.rand(100)*2-1. 

 

val = metric.run(data) 

assert(np.abs(val) < 0.2) 

 

def testRadiusObsMetric(self): 

""" 

Test the RadiusObsMetric 

""" 

 

names = ['fieldRA', 'fieldDec'] 

dt = ['float']*2 

data = np.zeros(3, dtype=list(zip(names, dt))) 

data['fieldDec'] = [-.1, 0, .1] 

slicePoint = {'ra': 0., 'dec': 0.} 

metric = metrics.RadiusObsMetric() 

result = metric.run(data, slicePoint) 

for i, r in enumerate(result): 

np.testing.assert_almost_equal(r, abs(data['fieldDec'][i])) 

assert(metric.reduceMean(result) == np.mean(result)) 

assert(metric.reduceRMS(result) == np.std(result)) 

np.testing.assert_almost_equal(metric.reduceFullRange(result), 

np.max(np.abs(data['fieldDec']))-np.min(np.abs(data['fieldDec']))) 

 

 

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

pass 

 

 

def setup_module(module): 

lsst.utils.tests.init() 

 

 

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

lsst.utils.tests.init() 

unittest.main()