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

# LSST Data Management System 

# Copyright 2016 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/>. 

"""Analytic astrometric accuracy model. 

""" 

 

__all__ = ['astromErrModel', 'fitAstromErrModel', 'build_astrometric_error_model'] 

 

import astropy.units as u 

import numpy as np 

from scipy.optimize import curve_fit 

 

from lsst.verify import Blob, Datum 

 

 

def astromErrModel(snr, theta=1000, sigmaSys=10, C=1, **kwargs): 

"""Calculate expected astrometric uncertainty based on SNR. 

 

mas = C*theta/SNR + sigmaSys 

 

Parameters 

---------- 

snr : `numpy.ndarray` or `astropy.unit.Quantity` 

S/N of photometric measurements (dimensionless). 

theta : `float`, `numpy.ndarray` or `astropy.unit.Quantity`, optional 

Seeing (default: milliarcsec). 

sigmaSys : `astropy.unit.Quantity` 

Systematic error floor (default: milliarcsec). 

C : `float` 

Scaling factor (dimensionless) 

 

Returns 

------- 

sigma : `astropy.unit.Quantity` 

Expected astrometric uncertainty with the same dimensions as ``snr``. 

Units will be those of theta and sigmaSys. 

 

Notes 

----- 

``theta`` and ``sigmaSys`` must be given in the same units. 

Typically choices might be any of arcsec, milli-arcsec, or radians. 

The default values are reasonable astronominal values in milliarcsec. 

But the only thing that matters is that they're the same. 

""" 

return C*theta/snr + sigmaSys 

 

 

def fitAstromErrModel(snr, dist): 

"""Fit model of astrometric error from the LSST Overview paper: 

 

http://arxiv.org/abs/0805.2366v4 

 

Parameters 

---------- 

snr : `np.ndarray` or `astropy.unit.Quantity` 

Signal-to-noise ratio of photometric observations (dimensionless). 

dist : `np.ndarray` or `astropy.unit.Quantity` 

Scatter in measured positions (default: millarcsec) 

 

Returns 

------- 

params : `dict` 

Fitted model parameters. Fields are: 

 

- ``C``: Model scale factor (dimensionless). 

- ``theta``: Seeing (default: milliarcsec). 

- ``sigmaSys``: Systematic astrometric uncertainty 

(default: milliarcsec). 

""" 

# Note that C is fixed to 1. 

p0 = [1, # theta 

0.01] # sigmaSys 

if isinstance(dist, u.Quantity): 

dist = dist.to(u.marcsec).value 

if isinstance(snr, u.Quantity): 

snr = snr.value 

fit_params, fit_param_covariance = curve_fit(astromErrModel, snr, dist, 

p0=p0) 

 

params = {'C': 1 * u.Unit(''), 

'theta': fit_params[0] * u.marcsec, 

'sigmaSys': fit_params[1] * u.marcsec} 

return params 

 

 

def build_astrometric_error_model(matchedMultiVisitDataset, brightSnr=100, 

medianRef=100, matchRef=500): 

r"""Serializable model of astrometry errors across multiple visits. 

 

.. math:: 

 

\mathrm{astromRms} = C \theta / \mathrm{SNR} + \sigma_\mathrm{sys} 

 

Parameters 

---------- 

matchedMultiVisitDataset : `MatchedMultiVisitDataset` 

A dataset containing matched statistics for stars across multiple 

visits. 

brightSnr : `float` or `astropy.unit.Quantity`, optional 

Minimum SNR for a star to be considered "bright" (dimensionless). 

medianRef : `float` or `astropy.unit.Quantity`, optional 

Median reference astrometric scatter (default: milliarcsecond). 

matchRef : int, optional 

Should match at least matchRef number of stars (dimensionless). 

 

Returns 

------- 

blob : `lsst.verify.Blob` 

Blob with datums: 

 

- ``brightSnr``: Threshold SNR for bright sources used in this model. 

- ``C``: Model scaling factor. 

- ``theta``: Seeing (milliarcsecond). 

- ``sigmaSys``: Systematic error floor (milliarcsecond). 

- ``astromRms``: Astrometric scatter (RMS) for good stars (milliarcsecond). 

 

Notes 

----- 

The scatter and match defaults appropriate to SDSS are the defaults 

for ``medianRef`` and ``matchRef``. 

 

For SDSS, stars with mag < 19.5 should be completely well measured. 

""" 

 

blob = Blob('AnalyticAstrometryModel') 

 

# FIXME add description field to blobs 

# _doc['doc'] \ 

# = "Astrometric astrometry model: mas = C*theta/SNR + sigmaSys" 

 

if not isinstance(brightSnr, u.Quantity): 

brightSnr = brightSnr * u.Unit('') 

if not isinstance(medianRef, u.Quantity): 

medianRef = medianRef * u.marcsec 

 

_compute(blob, 

matchedMultiVisitDataset['snr'].quantity, 

matchedMultiVisitDataset['dist'].quantity, 

len(matchedMultiVisitDataset.goodMatches), 

brightSnr, medianRef, matchRef) 

return blob 

 

 

def _compute(blob, snr, dist, nMatch, brightSnr, medianRef, matchRef): 

median_dist = np.median(dist) 

msg = 'Median value of the astrometric scatter - all magnitudes: ' \ 

'{0:.3f}' 

print(msg.format(median_dist)) 

 

bright = np.where(snr > brightSnr) 

astromScatter = np.median(dist[bright]) 

msg = 'Astrometric scatter (median) - snr > {0:.1f} : {1:.1f}' 

print(msg.format(brightSnr, astromScatter)) 

 

fit_params = fitAstromErrModel(snr[bright], dist[bright]) 

 

if astromScatter > medianRef: 

msg = 'Median astrometric scatter {0:.1f} is larger than ' \ 

'reference : {1:.1f}' 

print(msg.format(astromScatter, medianRef)) 

if nMatch < matchRef: 

msg = 'Number of matched sources {0:d} is too small ' \ 

'(should be > {1:d})' 

print(msg.format(nMatch, matchRef)) 

 

blob['brightSnr'] = Datum(quantity=brightSnr, 

label='Bright SNR', 

description='Threshold in SNR for bright sources used in this ' 

'model') 

blob['C'] = Datum(quantity=fit_params['C'], 

description='Scaling factor') 

blob['theta'] = Datum(quantity=fit_params['theta'], 

label='theta', 

description='Seeing') 

blob['sigmaSys'] = Datum(quantity=fit_params['sigmaSys'], 

label='sigma(sys)', 

description='Systematic error floor') 

blob['astromRms'] = Datum(quantity=astromScatter, 

label='RMS', 

description='Astrometric scatter (RMS) for good stars')