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

211

212

213

214

215

216

217

218

219

220

221

222

223

224

225

226

227

228

229

230

231

232

233

234

235

236

237

238

239

240

241

242

243

244

245

246

247

248

249

# LSST Data Management System 

# Copyright 2015-2017 AURA/LSST. 

# 

# This product includes software developed by the 

# LSST Project (http://www.lsst.org/). 

# 

# 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 LSST License Statement and 

# the GNU General Public License along with this program. If not, 

# see <https://www.lsstcorp.org/LegalNotices/>. 

 

import operator 

 

import astropy.units as u 

from matplotlib import pyplot as plt 

import numpy as np 

import treecorr 

 

from lsst.verify import Measurement, Datum, ThresholdSpecification 

 

from ..util import (averageRaFromCat, averageDecFromCat, 

medianEllipticity1ResidualsFromCat, 

medianEllipticity2ResidualsFromCat) 

 

 

def measureTEx(metric, matchedDataset, D, bin_range_operator, verbose=False): 

"""Measurement of TEx (x=1,2): Correlation of PSF residual ellipticity 

on scales of D=(1, 5) arcmin. 

 

Parameters 

---------- 

metric : `lsst.verify.Metric` 

An TE1 or TE2 `~lsst.verify.Metric` instance. 

matchedDataset : lsst.verify.Blob 

The matched catalogs to analyze. 

D : `astropy.units.Quantity` 

Radial size of annulus in arcmin 

bin_range_operator : str 

String representation to use in comparisons 

verbose : `bool`, optional 

Output additional information on the analysis steps. 

 

Returns 

------- 

measurement : `lsst.verify.Measurement` 

Measurement of TEx (x=1,2) and associated metadata. 

 

Notes 

----- 

The TEx table below is provided in ``validate_drp``\ 's :file:`metrics.yaml`. 

 

LPM-17 dated 2011-07-06 

 

Specification: 

Using the full survey data, the E1, E2, and EX residual PSF ellipticity 

correlations averaged over an arbitrary FOV must have the median 

less than TE1 for theta <= 1 arcmin, and less than TE2 for theta >= 5 arcmin. 

 

The residual ellipticity correlations vary smoothly so it is sufficient to 

specify limits in these two angular ranges. On 1 arcmin to 5 arcmin scales, 

these residual ellipticity correlations put LSST systematics a factor of a 

few below the weak lensing shot noise, i.e., statistical errors will 

dominate over systematics. On larger scales, the noise level imposed by 

nature due to shot noise plus cosmic variance is almost scale-independent, 

whereas the atmospheric contribution to systematics becomes negligible. 

Therefore the specifications on 5 arcmin scales apply to all larger scales 

as well (as per section 2.1.1). On scales larger than the field of view, 

sources of systematic error have less to do with the instrumentation than 

with the operations (due to the seeing distribution), software, and algorithms. 

 

========================= ====== ======= ======= 

PSF Ellipticity Residuals Specification 

------------------------- ---------------------- 

Metric Design Minimum Stretch 

========================= ====== ======= ======= 

TE1 () 2e-5 3e-5 1e-5 

TE2 (%) 1e-7 3e-7 5e-8 

TEF (%) 15 15 10 

TE3 () 4e-5 6e-5 2e-5 

TE4 () 2e-7 5e-7 1e-7 

========================= ====== ======= ======= 

 

 

Table 27: These residual PSF ellipticity correlations apply to the r and i bands. 

""" 

 

matches = matchedDataset.safeMatches 

 

datums = {} 

datums['D'] = Datum(quantity=D, description="Separation distance") 

 

radius, xip, xip_err = correlation_function_ellipticity_from_matches(matches, verbose=verbose) 

datums['radius'] = Datum(quantity=radius, description="Correlation radius") 

datums['xip'] = Datum(quantity=xip, description="Correlation strength") 

datums['xip_err'] = Datum(quantity=xip_err, description="Correlation strength uncertainty") 

datums['bin_range_operator'] = Datum(quantity=bin_range_operator, description="Bin range operator string") 

 

operator = ThresholdSpecification.convert_operator_str(bin_range_operator) 

corr, corr_err = select_bin_from_corr(radius, xip, xip_err, radius=D, operator=operator) 

quantity = np.abs(corr) * u.Unit('') 

return Measurement(metric, quantity, extras=datums) 

 

 

def correlation_function_ellipticity_from_matches(matches, **kwargs): 

"""Compute shear-shear correlation function for ellipticity residual from a 'MatchedMultiVisitDataset' object. 

 

Convenience function for calling correlation_function_ellipticity. 

 

Parameters 

---------- 

matches : `lsst.verify.Blob` 

- The matched catalogs to analyze. 

 

Returns 

------- 

r, xip, xip_err : each a np.array(dtype=float) 

- The bin centers, two-point correlation, and uncertainty. 

""" 

ra = matches.aggregate(averageRaFromCat) * u.radian 

dec = matches.aggregate(averageDecFromCat) * u.radian 

 

e1_res = matches.aggregate(medianEllipticity1ResidualsFromCat) 

e2_res = matches.aggregate(medianEllipticity2ResidualsFromCat) 

 

return correlation_function_ellipticity(ra, dec, e1_res, e2_res, **kwargs) 

 

 

def correlation_function_ellipticity(ra, dec, e1_res, e2_res, 

nbins=20, min_sep=0.25, max_sep=20, 

sep_units='arcmin', verbose=False): 

"""Compute shear-shear correlation function from ra, dec, g1, g2. 

 

Default parameters for nbins, min_sep, max_sep chosen to cover 

an appropriate range to calculate TE1 (<=1 arcmin) and TE2 (>=5 arcmin). 

Parameters 

---------- 

ra : numpy.array 

Right ascension of points [radians] 

dec : numpy.array 

Declination of points [radians] 

e1_res : numpy.array 

Residual ellipticity 1st component 

e2_res : numpy.array 

Residual ellipticity 2nd component 

nbins : float, optional 

Number of bins over which to analyze the two-point correlation 

min_sep : float, optional 

Minimum separation over which to analyze the two-point correlation 

max_sep : float, optional 

Maximum separation over which to analyze the two-point correlation 

sep_units : str, optional 

Specify the units of min_sep and max_sep 

verbose : bool 

Request verbose output from `treecorr`. 

verbose=True will use verbose=2 for `treecorr.GGCorrelation`. 

 

Returns 

------- 

r, xip, xip_err : each a np.array(dtype=float) 

- The bin centers, two-point correlation, and uncertainty. 

""" 

# Translate to 'verbose_level' here to refer to the integer levels in TreeCorr 

# While 'verbose' is more generically what is being passed around 

# for verbosity within 'validate_drp' 

if verbose: 

verbose_level = 2 

else: 

verbose_level = 0 

 

catTree = treecorr.Catalog(ra=ra, dec=dec, g1=e1_res, g2=e2_res, 

dec_units='radian', ra_units='radian') 

gg = treecorr.GGCorrelation(nbins=nbins, min_sep=min_sep, max_sep=max_sep, 

sep_units=sep_units, 

verbose=verbose_level) 

gg.process(catTree) 

r = np.exp(gg.meanlogr) * u.arcmin 

xip = gg.xip * u.Unit('') 

xip_err = np.sqrt(gg.varxi) * u.Unit('') 

 

return (r, xip, xip_err) 

 

 

def select_bin_from_corr(r, xip, xip_err, radius=1*u.arcmin, operator=operator.le): 

"""Aggregate measurements for r less than (or greater than) radius. 

 

Returns aggregate measurement for all entries where operator(r, radius). 

E.g., 

* Passing radius=5, operator=operator.le will return averages for r<=5 

* Passing radius=2, operator=operator.gt will return averages for r >2 

 

Written with the use of correlation functions in mind, thus the naming 

but generically just returns averages of the arrays xip and xip_err 

where the condition is satsified 

 

Parameters 

---------- 

r : numpy.array 

radius 

xip : numpy.array 

correlation 

xip_err : numpy.array 

correlation uncertainty 

operator : Operation in the 'operator' module: le, ge, lt, gt 

 

Returns 

------- 

avg_xip, avg_xip_err : (float, float) 

""" 

w, = np.where(operator(r, radius)) 

 

avg_xip = np.average(xip[w]) 

avg_xip_err = np.average(xip_err[w]) 

 

return avg_xip, avg_xip_err 

 

 

def plot_correlation_function_ellipticity(r, xip, xip_err, 

plotfile='ellipticity_corr.png'): 

""" 

Parameters 

---------- 

r : numpy.array 

Correlation average radius in each bin 

xip : numpy.array 

Two-point correlation 

xip_err : numpy.array 

Uncertainty on two-point correlation 

plotfile : Str 

Name of file to save the figure in. 

 

Effects 

------- 

Creates a plot file in the local filesystem: 'ellipticty_corr.png' 

""" 

fig = plt.figure() 

ax = fig.add_subplot(111) 

ax.errorbar(r.value, xip, yerr=xip_err) 

ax.set_xlabel('Separation (arcmin)', size=19) 

ax.set_ylabel('Median Residual Ellipticity Correlation', size=19) 

fig.savefig(plotfile)