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

import numpy as np 

import ephem 

from lsst.sims.utils import _galacticFromEquatorial, calcLmstLast 

 

from .baseStacker import BaseStacker 

from .ditherStackers import wrapRA 

 

__all__ = ['mjd2djd', 'raDec2AltAz', 'GalacticStacker', 'EclipticStacker'] 

 

 

def mjd2djd(mjd): 

"""Convert MJD to the Dublin Julian date used by ephem. 

 

Parameters 

---------- 

mjd : float or numpy.ndarray 

The modified julian date. 

Returns 

------- 

float or numpy.ndarray 

The dublin julian date. 

""" 

doff = ephem.Date(0)-ephem.Date('1858/11/17') 

djd = mjd-doff 

return djd 

 

 

def raDec2AltAz(ra, dec, lat, lon, mjd, altonly=False): 

"""Convert RA/Dec (and telescope site lat/lon) to alt/az. 

 

This uses simple equations and ignores aberation, precession, nutation, 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. 

altonly : bool, opt 

Calculate altitude only. 

 

Returns 

------- 

alt : numpy.array 

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

az : numpy.array 

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

""" 

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) 

# make sure sinalt is in the expected range. 

sinalt = np.where(sinalt < -1, -1, sinalt) 

sinalt = np.where(sinalt > 1, 1, sinalt) 

alt = np.arcsin(sinalt) 

if altonly: 

az = None 

else: 

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

cosaz = np.where(cosaz < -1, -1, cosaz) 

cosaz = np.where(cosaz > 1, 1, cosaz) 

az = np.arccos(cosaz) 

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

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

return alt, az 

 

 

class GalacticStacker(BaseStacker): 

"""Add the galactic coordinates of each RA/Dec pointing: gall, galb 

 

Parameters 

---------- 

raCol : str, opt 

Name of the RA column. Default fieldRA. 

decCol : str, opt 

Name of the Dec column. Default fieldDec. 

""" 

def __init__(self, raCol='fieldRA', decCol='fieldDec', degrees=True): 

self.colsReq = [raCol, decCol] 

self.colsAdded = ['gall', 'galb'] 

self.units = ['radians', 'radians'] 

self.raCol = raCol 

self.decCol = decCol 

self.degrees = degrees 

 

def _run(self, simData, cols_present=False): 

# raCol and DecCol in radians, gall/b in radians. 

98 ↛ 100line 98 didn't jump to line 100, because the condition on line 98 was never true if cols_present: 

# Column already present in data; assume it is correct and does not need recalculating. 

return simData 

101 ↛ 105line 101 didn't jump to line 105, because the condition on line 101 was never false if self.degrees: 

simData['gall'], simData['galb'] = _galacticFromEquatorial(np.radians(simData[self.raCol]), 

np.radians(simData[self.decCol])) 

else: 

simData['gall'], simData['galb'] = _galacticFromEquatorial(simData[self.raCol], 

simData[self.decCol]) 

return simData 

 

 

class EclipticStacker(BaseStacker): 

"""Add the ecliptic coordinates of each RA/Dec pointing: eclipLat, eclipLon 

Optionally subtract off the sun's ecliptic longitude and wrap. 

 

Parameters 

---------- 

mjdCol : str, opt 

Name of the MJD column. Default expMJD. 

raCol : str, opt 

Name of the RA column. Default fieldRA. 

decCol : str, opt 

Name of the Dec column. Default fieldDec. 

subtractSunLon : bool, opt 

Flag to subtract the sun's ecliptic longitude. Default False. 

""" 

def __init__(self, mjdCol='observationStartMJD', raCol='fieldRA', decCol='fieldDec', degrees=True, 

subtractSunLon=False): 

 

self.colsReq = [mjdCol, raCol, decCol] 

self.subtractSunLon = subtractSunLon 

self.colsAdded = ['eclipLat', 'eclipLon'] 

self.degrees = degrees 

132 ↛ 135line 132 didn't jump to line 135, because the condition on line 132 was never false if self.degrees: 

self.units = ['degrees', 'degrees'] 

else: 

self.units = ['radians', 'radians'] 

self.mjdCol = mjdCol 

self.raCol = raCol 

self.decCol = decCol 

 

def _run(self, simData, cols_present=False): 

if cols_present: 

# Column already present in data; assume it is correct and does not need recalculating. 

return simData 

for i in np.arange(simData.size): 

if self.degrees: 

coord = ephem.Equatorial(np.radians(simData[self.raCol][i]), 

np.radians(simData[self.decCol][i]), epoch=2000) 

else: 

coord = ephem.Equatorial(simData[self.raCol][i], 

simData[self.decCol][i], epoch=2000) 

ecl = ephem.Ecliptic(coord) 

simData['eclipLat'][i] = ecl.lat 

if self.subtractSunLon: 

djd = mjd2djd(simData[self.mjdCol][i]) 

sun = ephem.Sun(djd) 

sunEcl = ephem.Ecliptic(sun) 

lon = wrapRA(ecl.lon - sunEcl.lon) 

simData['eclipLon'][i] = lon 

else: 

simData['eclipLon'][i] = ecl.lon 

if self.degrees: 

simData['eclipLon'] = np.degrees(simData['eclipLon']) 

simData['eclipLat'] = np.degrees(simData['eclipLat']) 

return simData