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

250

251

252

253

254

255

256

257

258

259

260

261

262

263

264

265

266

267

268

269

270

271

272

273

274

275

276

277

278

279

280

281

282

283

284

285

286

287

288

289

290

291

292

293

294

295

296

297

298

299

300

301

302

303

304

305

306

307

308

309

310

311

312

""" 

This file contains coordinate transformations that rely on both 

palpy and the contents of AstrometryUtils.py (basically, coordinate 

transformations that need to transform between observed geocentric RA, DEC 

and ICRS RA, Dec) 

""" 

from __future__ import division 

 

import numpy as np 

import palpy 

from lsst.sims.utils.CodeUtilities import _validate_inputs 

from lsst.sims.utils import _icrsFromObserved, _observedFromICRS, calcLmstLast 

 

__all__ = ["_altAzPaFromRaDec", "altAzPaFromRaDec", 

"_raDecFromAltAz", "raDecFromAltAz", 

"getRotTelPos", "_getRotTelPos", 

"getRotSkyPos", "_getRotSkyPos"] 

 

 

def altAzPaFromRaDec(ra, dec, obs, includeRefraction=True): 

""" 

Convert RA, Dec, longitude, latitude and MJD into altitude, azimuth 

and parallactic angle using PALPY 

 

@param [in] ra is RA in degrees. Can be a numpy array or a single value. 

Assumed to be in the International Celestial Reference System. 

 

@param [in] dec is Dec in degrees. Can be a numpy array or a single value. 

Assumed to be in the International Celestial Reference System. 

 

@param [in] obs is an ObservationMetaData characterizing 

the site of the telescope and the MJD of the observation 

 

@param [in] includeRefraction is a boolean that turns refraction on and off 

(default True) 

 

@param [out] altitude in degrees 

 

@param [out] azimuth in degrees 

 

@param [out] parallactic angle in degrees 

 

WARNING: This method does not account for apparent motion due to parallax. 

This method is only useful for mapping positions on a theoretical celestial 

sphere. 

""" 

 

alt, az, pa = _altAzPaFromRaDec(np.radians(ra), np.radians(dec), 

obs, includeRefraction=includeRefraction) 

 

return np.degrees(alt), np.degrees(az), np.degrees(pa) 

 

 

def _altAzPaFromRaDec(raRad, decRad, obs, includeRefraction=True): 

""" 

Convert RA, Dec, longitude, latitude and MJD into altitude, azimuth 

and parallactic angle using PALPY 

 

@param [in] raRad is RA in radians. Can be a numpy array or a single value. 

Assumed to be in the International Celestial Reference System. 

 

@param [in] decRad is Dec in radians. Can be a numpy array or a single value. 

Assumed to be in the International Celestial Reference System. 

 

@param [in] obs is an ObservationMetaData characterizing 

the site of the telescope and the MJD of the observation 

 

@param [in] includeRefraction is a boolean that turns refraction on and off 

(default True) 

 

@param [out] altitude in radians 

 

@param [out] azimuth in radians 

 

@param [out] parallactic angle in radians 

 

WARNING: This method does not account for apparent motion due to parallax. 

This method is only useful for mapping positions on a theoretical focal plan 

to positions on the celestial sphere. 

""" 

 

are_arrays = _validate_inputs([raRad, decRad], ['ra', 'dec'], 

"altAzPaFromRaDec") 

 

raObs, decObs = \ 

_observedFromICRS(raRad, decRad, obs_metadata=obs, 

epoch=2000.0, includeRefraction=includeRefraction) 

 

lst = calcLmstLast(obs.mjd.UT1, obs.site.longitude_rad) 

last = lst[1] 

haRad = np.radians(last * 15.0) - raObs 

 

if are_arrays: 

az, azd, azdd, \ 

alt, altd, altdd, \ 

pa, pad, padd = palpy.altazVector( 

haRad, decObs, obs.site.latitude_rad) 

else: 

az, azd, azdd, \ 

alt, altd, altdd, \ 

pa, pad, padd = palpy.altaz(haRad, decObs, obs.site.latitude_rad) 

 

return alt, az, pa 

 

 

def raDecFromAltAz(alt, az, obs, includeRefraction=True): 

""" 

Convert altitude and azimuth to RA and Dec 

 

@param [in] alt is the altitude in degrees. Can be a numpy array or a single value. 

 

@param [in] az is the azimuth in degrees. Cant be a numpy array or a single value. 

 

@param [in] obs is an ObservationMetaData characterizing 

the site of the telescope and the MJD of the observation 

 

@param [in] includeRefraction is a boolean that turns refraction on and off 

(default True) 

 

@param [out] RA in degrees (in the International Celestial Reference System) 

 

@param [out] Dec in degrees (in the International Celestial Reference System) 

 

Note: This method is only accurate to within 0.01 arcsec near azimuth = 0 or pi 

""" 

 

ra, dec = _raDecFromAltAz(np.radians(alt), np.radians(az), obs, 

includeRefraction=includeRefraction) 

 

return np.degrees(ra), np.degrees(dec) 

 

 

def _raDecFromAltAz(altRad, azRad, obs, includeRefraction=True): 

""" 

Convert altitude and azimuth to RA and Dec 

 

@param [in] altRad is the altitude in radians. Can be a numpy array or a single value. 

 

@param [in] azRad is the azimuth in radians. Cant be a numpy array or a single value. 

 

@param [in] obs is an ObservationMetaData characterizing 

the site of the telescope and the MJD of the observation 

 

@param [in] includeRefraction is a boolean that turns refraction on and off 

(default True) 

 

@param [out] RA in radians (in the International Celestial Reference System) 

 

@param [out] Dec in radians (in the International Celestial Reference System) 

 

Note: This method is only accurate to within 0.01 arcsec near azimuth = 0 or pi 

""" 

 

are_arrays = _validate_inputs( 

[altRad, azRad], ['altRad', 'azRad'], "raDecFromAltAz") 

 

lst = calcLmstLast(obs.mjd.UT1, obs.site.longitude_rad) 

last = lst[1] 

sinAlt = np.sin(altRad) 

cosLat = np.cos(obs.site.latitude_rad) 

sinLat = np.sin(obs.site.latitude_rad) 

decObs = np.arcsin(sinLat * sinAlt + cosLat * 

np.cos(altRad) * np.cos(azRad)) 

costheta = (sinAlt - np.sin(decObs) * sinLat) / (np.cos(decObs) * cosLat) 

if are_arrays: 

haRad0 = np.arccos(costheta) 

# Make sure there were no NaNs 

nanSpots = np.where(np.isnan(haRad0))[0] 

if np.size(nanSpots) > 0: 

haRad0[nanSpots] = 0.5 * np.pi * \ 

(1.0 - np.sign(costheta[nanSpots])) 

else: 

haRad0 = np.arccos(costheta) 

if np.isnan(haRad0): 

if np.sign(costheta) > 0.0: 

haRad0 = 0.0 

else: 

haRad0 = np.pi 

 

haRad = np.where(np.sin(azRad) >= 0.0, -1.0 * haRad0, haRad0) 

raObs = np.radians(last * 15.) - haRad 

 

raRad, decRad = _icrsFromObserved(raObs, decObs, 

obs_metadata=obs, epoch=2000.0, 

includeRefraction=includeRefraction) 

 

return raRad, decRad 

 

 

def getRotSkyPos(ra, dec, obs, rotTel): 

""" 

@param [in] ra is the RA in degrees. Can be a numpy array or a single value. 

(In the International Celestial Reference System) 

 

@param [in] dec is Dec in degrees. Can be a numpy array or a single value. 

(In the International Celestial Reference System) 

 

@param [in] obs is an ObservationMetaData characterizing the telescope pointing 

and site. 

 

@param [in] rotTel is rotTelPos in degrees 

(the angle of the camera rotator). Can be a numpy array or a single value. 

If a numpy array, should have the same length as ra and dec. In this case, 

each rotTel will be associated with the corresponding ra, dec pair. 

 

@param [out] rotSkyPos in degrees 

 

WARNING: As of 13 April 2015, this method does not agree with OpSim on 

the relationship between rotSkyPos and rotTelPos. This is due to a 

discrepancy between the time that OpSim uses as the MJD when calculating 

rotTelPos and the time that OpSim reports as being the actual expmjd 

of the exposure (rotTelPos is calculated at the beginning of the exposure; 

expmjd is reckoned at the middle of the exposure). 

""" 

 

rotSky = _getRotSkyPos(np.radians(ra), np.radians(dec), 

obs, np.radians(rotTel)) 

 

return np.degrees(rotSky) 

 

 

def _getRotSkyPos(raRad, decRad, obs, rotTelRad): 

""" 

@param [in] raRad is the RA in radians. Can be a numpy array or a single value. 

(In the International Celestial Reference System) 

 

@param [in] decRad is Dec in radians. Can be a numpy array or a single value. 

(In the International Celestial Reference System) 

 

@param [in] obs is an ObservationMetaData characterizing the telescope pointing 

and site. 

 

@param [in] rotTelRad is rotTelPos in radians 

(the angle of the camera rotator). Can be a numpy array or a single value. 

If a numpy array, should have the same length as raRad and decRad. In this case, 

each rotTelRad will be associated with the corresponding raRad, decRad pair. 

 

@param [out] rotSkyPos in radians 

 

WARNING: As of 13 April 2015, this method does not agree with OpSim on 

the relationship between rotSkyPos and rotTelPos. This is due to a 

discrepancy between the time that OpSim uses as the MJD when calculating 

rotTelPos and the time that OpSim reports as being the actual expmjd 

of the exposure (rotTelPos is calculated at the beginning of the exposure; 

expmjd is reckoned at the middle of the exposure). 

""" 

altRad, azRad, paRad = _altAzPaFromRaDec(raRad, decRad, obs) 

 

return (rotTelRad - paRad) % (2. * np.pi) 

 

 

def getRotTelPos(ra, dec, obs, rotSky): 

""" 

@param [in] ra is RA in degrees. Can be a numpy array or a single value. 

(In the International Celestial Reference System) 

 

@param [in] dec is Dec in degrees. Can be a numpy array or a single value. 

(In the International Celestial Reference System) 

 

@param [in] obs is an ObservationMetaData characterizing the telescope pointing 

and site. 

 

@param [in] rotSky is rotSkyPos in degrees 

(the angle of the field of view relative to the South pole given a 

rotator angle). Can be a numpy array or a single value. If a numpy array, should 

have the same length as ra and dec. In this case, each rotSkyPos 

will be associated with the corresponding ra, dec pair. 

 

@param [out] rotTelPos in degrees. 

 

WARNING: As of 13 April 2015, this method does not agree with OpSim on 

the relationship between rotSkyPos and rotTelPos. This is due to a 

discrepancy between the time that OpSim uses as the MJD when calculating 

rotTelPos and the time that OpSim reports as being the actual expmjd 

of the exposure (rotTelPos is calculated at the beginning of the exposure; 

expmjd is reckoned at the middle of the exposure). 

""" 

rotTel = _getRotTelPos(np.radians(ra), np.radians(dec), 

obs, np.radians(rotSky)) 

 

return np.degrees(rotTel) 

 

 

def _getRotTelPos(raRad, decRad, obs, rotSkyRad): 

""" 

@param [in] raRad is RA in radians. Can be a numpy array or a single value. 

(In the International Celestial Reference System) 

 

@param [in] decRad is Dec in radians. Can be a numpy array or a single value. 

(In the International Celestial Reference System) 

 

@param [in] obs is an ObservationMetaData characterizing the telescope pointing 

and site. 

 

@param [in] rotSkyRad is rotSkyPos in radians 

(the angle of the field of view relative to the South pole given a 

rotator angle). Can be a numpy array or a single value. If a numpy array, should 

have the same length as raRad and decRad. In this case, each rotSkyPos 

will be associated with the corresponding raRad, decRad pair. 

 

@param [out] rotTelPos in radians. 

 

WARNING: As of 13 April 2015, this method does not agree with OpSim on 

the relationship between rotSkyPos and rotTelPos. This is due to a 

discrepancy between the time that OpSim uses as the MJD when calculating 

rotTelPos and the time that OpSim reports as being the actual expmjd 

of the exposure (rotTelPos is calculated at the beginning of the exposure; 

expmjd is reckoned at the middle of the exposure). 

""" 

altRad, azRad, paRad = _altAzPaFromRaDec(raRad, decRad, obs) 

 

return (rotSkyRad + paRad) % (2. * np.pi)