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

import numpy as np 

from lsst.sims.utils import calcLmstLast 

 

__all__ = ['_approx_altAz2RaDec', '_approx_RaDec2AltAz', 'approx_altAz2RaDec', 'approx_RaDec2AltAz'] 

 

 

def approx_altAz2RaDec(alt, az, lat, lon, mjd, lmst=None): 

""" 

Convert alt, az to RA, Dec without taking into account aberration, precession, diffraction, etc. 

 

Parameters 

---------- 

alt : numpy.array 

Altitude, same length as `ra` and `dec`. Degrees. 

az : numpy.array 

Azimuth, same length as `ra` and `dec`. Must be same length as `alt`. Degrees. 

lat : float 

Latitude of the observatory in degrees. 

lon : float 

Longitude of the observatory in degrees. 

mjd : float 

Modified Julian Date. 

lmst : float (None) 

The local mean sidereal time (computed if not given). (hours) 

 

Returns 

------- 

ra : array_like 

RA, in degrees. 

dec : array_like 

Dec, in degrees. 

""" 

ra, dec = _approx_altAz2RaDec(np.radians(alt), np.radians(az), np.radians(lat), 

np.radians(lon), mjd, lmst=lmst) 

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

 

 

def _approx_altAz2RaDec(alt, az, lat, lon, mjd, lmst=None): 

""" 

Convert alt, az to RA, Dec without taking into account aberration, precession, diffraction, etc. 

 

Parameters 

---------- 

alt : numpy.array 

Altitude, same length as `ra` and `dec`. Radians. 

az : numpy.array 

Azimuth, same length as `ra` and `dec`. Must be same length as `alt`. Radians. 

lat : float 

Latitude of the observatory in radians. 

lon : float 

Longitude of the observatory in radians. 

mjd : float 

Modified Julian Date. 

lmst : float (None) 

The local mean sidereal time (computed if not given). (hours) 

 

Returns 

------- 

ra : array_like 

RA, in radians. 

dec : array_like 

Dec, in radians. 

""" 

if lmst is None: 

lmst, last = calcLmstLast(mjd, lon) 

lmst = lmst/12.*np.pi # convert to rad 

sindec = np.sin(lat)*np.sin(alt) + np.cos(lat)*np.cos(alt)*np.cos(az) 

sindec = np.clip(sindec, -1, 1) 

dec = np.arcsin(sindec) 

ha = np.arctan2(-np.sin(az)*np.cos(alt), -np.cos(az)*np.sin(lat)*np.cos(alt)+np.sin(alt)*np.cos(lat)) 

ra = (lmst-ha) 

raneg = np.where(ra < 0) 

ra[raneg] = ra[raneg] + 2.*np.pi 

raover = np.where(ra > 2.*np.pi) 

ra[raover] -= 2.*np.pi 

return ra, dec 

 

 

def approx_RaDec2AltAz(ra, dec, lat, lon, mjd, lmst=None): 

""" 

Convert Ra,Dec to Altitude and Azimuth. 

 

Coordinate transformation is killing performance. Just use simple equations to speed it up 

and ignore aberration, precession, nutation, nutrition, etc. 

 

Parameters 

---------- 

ra : array_like 

RA, in degrees. 

dec : array_like 

Dec, in degrees. Must be same length as `ra`. 

lat : float 

Latitude of the observatory in degrees. 

lon : float 

Longitude of the observatory in degrees. 

mjd : float 

Modified Julian Date. 

lmst : float (None) 

The local mean sidereal time (computed if not given). (hours) 

 

Returns 

------- 

alt : numpy.array 

Altitude, same length as `ra` and `dec`. degrees. 

az : numpy.array 

Azimuth, same length as `ra` and `dec`. degrees. 

""" 

alt, az = _approx_RaDec2AltAz(np.radians(ra), np.radians(dec), np.radians(lat), 

np.radians(lon), mjd, lmst=lmst) 

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

 

 

def _approx_RaDec2AltAz(ra, dec, lat, lon, mjd, lmst=None): 

""" 

Convert Ra,Dec to Altitude and Azimuth. 

 

Coordinate transformation is killing performance. Just use simple equations to speed it up 

and ignore aberration, precession, nutation, nutrition, etc. 

 

Parameters 

---------- 

ra : array_like 

RA, in radians. 

dec : array_like 

Dec, in radians. Must be same length as `ra`. 

lat : float 

Latitude of the observatory in radians. 

lon : float 

Longitude of the observatory in radians. 

mjd : float 

Modified Julian Date. 

lmst : float (None) 

The local mean sidereal time (computed if not given). (hours) 

 

Returns 

------- 

alt : numpy.array 

Altitude, same length as `ra` and `dec`. Radians. 

az : numpy.array 

Azimuth, same length as `ra` and `dec`. Radians. 

""" 

if lmst is None: 

lmst, last = calcLmstLast(mjd, lon) 

lmst = lmst/12.*np.pi # convert to rad 

ha = lmst-ra 

sindec = np.sin(dec) 

sinlat = np.sin(lat) 

coslat = np.cos(lat) 

sinalt = sindec*sinlat+np.cos(dec)*coslat*np.cos(ha) 

sinalt = np.clip(sinalt, -1, 1) 

alt = np.arcsin(sinalt) 

cosaz = (sindec-np.sin(alt)*sinlat)/(np.cos(alt)*coslat) 

cosaz = np.clip(cosaz, -1, 1) 

az = np.arccos(cosaz) 

signflip = np.where(np.sin(ha) > 0) 

az[signflip] = 2.*np.pi-az[signflip] 

return alt, az