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

import numpy as np 

import healpy as hp 

from lsst.sims.utils import _hpid2RaDec, Site, _angularSeparation 

import matplotlib.pylab as plt 

from lsst.sims.featureScheduler.basis_functions import Base_basis_function 

 

 

__all__ = ['Zenith_mask_basis_function', 'Zenith_shadow_mask_basis_function', 

'Moon_avoidance_basis_function', 'Map_cloud_basis_function'] 

 

 

class Zenith_mask_basis_function(Base_basis_function): 

"""Just remove the area near zenith. 

 

Parameters 

---------- 

min_alt : float (20.) 

The minimum possible altitude (degrees) 

max_alt : float (82.) 

The maximum allowed altitude (degrees) 

""" 

def __init__(self, min_alt=20., max_alt=82.): 

super(Zenith_mask_basis_function, self).__init__() 

self.update_on_newobs = False 

self.min_alt = np.radians(min_alt) 

self.max_alt = np.radians(max_alt) 

self.result = np.empty(hp.nside2npix(self.nside), dtype=float).fill(self.penalty) 

 

def _calc_value(self, conditions, indx=None): 

 

result = self.result.copy() 

alt_limit = np.where((conditions.alt > self.min_alt) & 

(conditions.alt < self.max_alt))[0] 

result[alt_limit] = 1 

return result 

 

 

class Zenith_shadow_mask_basis_function(Base_basis_function): 

"""Mask the zenith, and things that will soon pass near zenith. Useful for making sure 

observations will not be too close to zenith when they need to be observed again (e.g. for a pair). 

 

Parameters 

---------- 

min_alt : float (20.) 

The minimum alititude to alow. Everything lower is masked. (degrees) 

max_alt : float (82.) 

The maximum altitude to alow. Everything higher is masked. (degrees) 

shadow_minutes : float (40.) 

Mask anything that will pass through the max alt in the next shadow_minutes time. (minutes) 

""" 

def __init__(self, nside=None, min_alt=20., max_alt=82., 

shadow_minutes=40., penalty=np.nan, site='LSST'): 

super(Zenith_shadow_mask_basis_function, self).__init__(nside=nside) 

self.update_on_newobs = False 

 

self.penalty = penalty 

 

self.min_alt = np.radians(min_alt) 

self.max_alt = np.radians(max_alt) 

self.ra, self.dec = _hpid2RaDec(nside, np.arange(hp.nside2npix(nside))) 

self.shadow_minutes = np.radians(shadow_minutes/60. * 360./24.) 

# Compute the declination band where things could drift into zenith 

self.decband = np.zeros(self.dec.size, dtype=float) 

self.zenith_radius = np.radians(90.-max_alt)/2. 

site = Site(name=site) 

self.lat_rad = site.latitude_rad 

self.lon_rad = site.longitude_rad 

self.decband[np.where((self.dec < (self.lat_rad+self.zenith_radius)) & 

(self.dec > (self.lat_rad-self.zenith_radius)))] = 1 

 

self.result = np.empty(hp.nside2npix(self.nside), dtype=float) 

self.result.fill(self.penalty) 

 

def _calc_value(self, conditions, indx=None): 

 

result = self.result.copy() 

alt_limit = np.where((conditions.alt > self.min_alt) & 

(conditions.alt < self.max_alt))[0] 

result[alt_limit] = 1 

to_mask = np.where((conditions.HA > (2.*np.pi-self.shadow_minutes-self.zenith_radius)) & 

(self.decband == 1)) 

result[to_mask] = np.nan 

return result 

 

 

class Moon_avoidance_basis_function(Base_basis_function): 

"""Avoid looking too close to the moon. 

 

Parameters 

---------- 

moon_distance: float (30.) 

Minimum allowed moon distance. (degrees) 

 

XXX--TODO: This could be a more complicated function of filter and moon phase. 

""" 

def __init__(self, nside=None, moon_distance=30.): 

super(Moon_avoidance_basis_function, self).__init__(nside=nside) 

self.update_on_newobs = False 

 

self.moon_distance = np.radians(moon_distance) 

self.result = np.ones(hp.nside2npix(self.nside), dtype=float) 

 

def _calc_value(self, conditions, indx=None): 

result = self.result.copy() 

 

angular_distance = _angularSeparation(conditions.az, conditions.alt, 

conditions.moonAz, 

conditions.moonAlt) 

 

result[angular_distance < self.moon_distance] = np.nan 

 

return result 

 

 

class Bulk_cloud_basis_function(Base_basis_function): 

"""Mark healpixels on a map if their cloud values are greater than 

the same healpixels on a maximum cloud map. 

 

Parameters 

---------- 

nside: int (default_nside) 

The healpix resolution. 

max_cloud_map : numpy array (None) 

A healpix map showing the maximum allowed cloud values for all points on the sky 

out_of_bounds_val : float (10.) 

Point value to give regions where there are no observations requested 

""" 

 

def __init__(self, nside=None, max_cloud_map=None, max_val=0.7, 

out_of_bounds_val=np.nan): 

super(Bulk_cloud_basis_function, self).__init__(nside=nside) 

self.update_on_newobs = False 

 

if max_cloud_map is None: 

self.max_cloud_map = np.zeros(hp.nside2npix(nside), dtype=float) + max_val 

else: 

self.max_cloud_map = max_cloud_map 

self.out_of_bounds_area = np.where(self.max_cloud_map > 1.)[0] 

self.out_of_bounds_val = out_of_bounds_val 

self.result = np.ones(hp.nside2npix(self.nside)) 

 

def _calc_value(self, conditions, indx=None): 

""" 

Parameters 

---------- 

indx : list (None) 

Index values to compute, if None, full map is computed 

Returns 

------- 

Healpix map where pixels with a cloud value greater than the max_cloud_map 

value are marked as unseen. 

""" 

 

result = self.result.copy() 

 

clouded = np.where(self.max_cloud_map <= conditions.bulk_cloud) 

result[clouded] = self.out_of_bounds_val 

 

return result 

 

 

class Map_cloud_basis_function(Base_basis_function): 

"""Mark healpixels on a map if their cloud values are greater than 

the same healpixels on a maximum cloud map. Currently a placeholder for 

when the telemetry stream can include a full sky cloud map. 

 

Parameters 

---------- 

nside: int (default_nside) 

The healpix resolution. 

max_cloud_map : numpy array (None) 

A healpix map showing the maximum allowed cloud values for all points on the sky 

out_of_bounds_val : float (10.) 

Point value to give regions where there are no observations requested 

""" 

 

def __init__(self, nside=None, max_cloud_map=None, max_val=0.7, 

out_of_bounds_val=np.nan): 

super(Bulk_cloud_basis_function, self).__init__(nside=nside) 

self.update_on_newobs = False 

 

if max_cloud_map is None: 

self.max_cloud_map = np.zeros(hp.nside2npix(nside), dtype=float) + max_val 

else: 

self.max_cloud_map = max_cloud_map 

self.out_of_bounds_area = np.where(self.max_cloud_map > 1.)[0] 

self.out_of_bounds_val = out_of_bounds_val 

self.result = np.ones(hp.nside2npix(self.nside)) 

 

def _calc_value(self, conditions, indx=None): 

""" 

Parameters 

---------- 

indx : list (None) 

Index values to compute, if None, full map is computed 

Returns 

------- 

Healpix map where pixels with a cloud value greater than the max_cloud_map 

value are marked as unseen. 

""" 

 

result = self.result.copy() 

 

clouded = np.where(self.max_cloud_map <= conditions.bulk_cloud) 

result[clouded] = self.out_of_bounds_val 

 

return result