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

import numpy as np 

import unittest 

import lsst.sims.featureScheduler.basis_functions as bf 

from lsst.sims.featureScheduler.utils import standard_goals, calc_norm_factor 

from lsst.sims.featureScheduler.surveys import (generate_dd_surveys, Greedy_survey, 

Blob_survey, Pairs_survey_scripted) 

from lsst.sims.featureScheduler.schedulers import Core_scheduler 

import lsst.utils.tests 

import healpy as hp 

from lsst.sims.featureScheduler import sim_runner 

from lsst.sims.featureScheduler.modelObservatory import Model_observatory 

 

 

def gen_greedy_surveys(nside): 

""" 

Make a quick set of greedy surveys 

""" 

target_map = standard_goals(nside=nside) 

filters = ['g', 'r', 'i', 'z', 'y'] 

surveys = [] 

 

for filtername in filters: 

bfs = [] 

bfs.append(bf.M5_diff_basis_function(filtername=filtername, nside=nside)) 

bfs.append(bf.Target_map_basis_function(filtername=filtername, 

target_map=target_map[filtername], 

out_of_bounds_val=np.nan, nside=nside)) 

bfs.append(bf.Slewtime_basis_function(filtername=filtername, nside=nside)) 

bfs.append(bf.Strict_filter_basis_function(filtername=filtername)) 

# Masks, give these 0 weight 

bfs.append(bf.Zenith_shadow_mask_basis_function(nside=nside, shadow_minutes=60., max_alt=76.)) 

bfs.append(bf.Moon_avoidance_basis_function(nside=nside, moon_distance=30.)) 

bfs.append(bf.Clouded_out_basis_function()) 

 

bfs.append(bf.Filter_loaded_basis_function(filternames=filtername)) 

 

weights = np.array([3.0, 0.3, 3., 3., 0., 0., 0., 0.]) 

surveys.append(Greedy_survey(bfs, weights, block_size=1, filtername=filtername, 

dither=True, nside=nside)) 

return surveys 

 

 

def gen_blob_surveys(nside): 

""" 

make a quick set of blob surveys 

""" 

target_map = standard_goals(nside=nside) 

norm_factor = calc_norm_factor(target_map) 

 

filter1s = ['u', 'g'] # , 'r', 'i', 'z', 'y'] 

filter2s = [None, 'g'] # , 'r', 'i', None, None] 

filter1s = ['g'] # , 'r', 'i', 'z', 'y'] 

filter2s = ['g'] # , 'r', 'i', None, None] 

 

pair_surveys = [] 

for filtername, filtername2 in zip(filter1s, filter2s): 

bfs = [] 

bfs.append(bf.M5_diff_basis_function(filtername=filtername, nside=nside)) 

if filtername2 is not None: 

bfs.append(bf.M5_diff_basis_function(filtername=filtername2, nside=nside)) 

bfs.append(bf.Target_map_basis_function(filtername=filtername, 

target_map=target_map[filtername], 

out_of_bounds_val=np.nan, nside=nside, 

norm_factor=norm_factor)) 

if filtername2 is not None: 

bfs.append(bf.Target_map_basis_function(filtername=filtername2, 

target_map=target_map[filtername2], 

out_of_bounds_val=np.nan, nside=nside, 

norm_factor=norm_factor)) 

bfs.append(bf.Slewtime_basis_function(filtername=filtername, nside=nside)) 

bfs.append(bf.Strict_filter_basis_function(filtername=filtername)) 

# Masks, give these 0 weight 

bfs.append(bf.Zenith_shadow_mask_basis_function(nside=nside, shadow_minutes=60., max_alt=76.)) 

bfs.append(bf.Moon_avoidance_basis_function(nside=nside, moon_distance=30.)) 

bfs.append(bf.Clouded_out_basis_function()) 

# feasibility basis fucntions. Also give zero weight. 

filternames = [fn for fn in [filtername, filtername2] if fn is not None] 

bfs.append(bf.Filter_loaded_basis_function(filternames=filternames)) 

bfs.append(bf.Time_to_twilight_basis_function(time_needed=22.)) 

bfs.append(bf.Not_twilight_basis_function()) 

 

weights = np.array([3.0, 3.0, .3, .3, 3., 3., 0., 0., 0., 0., 0., 0.]) 

if filtername2 is None: 

# Need to scale weights up so filter balancing still works properly. 

weights = np.array([6.0, 0.6, 3., 3., 0., 0., 0., 0., 0., 0.]) 

if filtername2 is None: 

survey_name = 'blob, %s' % filtername 

else: 

survey_name = 'blob, %s%s' % (filtername, filtername2) 

pair_surveys.append(Blob_survey(bfs, weights, filtername1=filtername, filtername2=filtername2, 

survey_note=survey_name, ignore_obs='DD')) 

return pair_surveys 

 

 

class TestFeatures(unittest.TestCase): 

 

def testGreedy(self): 

""" 

Set up a greedy survey and run for a few days. A crude way to touch lots of code. 

""" 

nside = 32 

survey_length = 2.0 # days 

 

surveys = gen_greedy_surveys(nside) 

surveys.append(Pairs_survey_scripted(None, ignore_obs='DD')) 

 

# Set up the DD 

dd_surveys = generate_dd_surveys(nside=nside) 

surveys.extend(dd_surveys) 

 

scheduler = Core_scheduler(surveys, nside=nside) 

observatory = Model_observatory(nside=nside) 

observatory, scheduler, observations = sim_runner(observatory, scheduler, 

survey_length=survey_length, 

filename=None) 

 

# Check that a second part of a pair was taken 

assert('pair(scripted)' in observations['note']) 

# Check that the a DD was observed 

assert('DD:ECDFS' in observations['note']) 

# Make sure a few different filters were observed 

assert(len(np.unique(observations['filter'])) > 3) 

# Make sure lots of observations executed 

assert(observations.size > 1000) 

# Make sure nothing tried to look through the earth 

assert(np.min(observations['alt']) > 0) 

 

def testBlobs(self): 

""" 

Set up a blob selection survey 

""" 

nside = 32 

survey_length = 2.0 # days 

 

surveys = [] 

# Set up the DD 

dd_surveys = generate_dd_surveys(nside=nside) 

surveys.append(dd_surveys) 

 

surveys.append(gen_blob_surveys(nside)) 

surveys.append(gen_greedy_surveys(nside)) 

 

scheduler = Core_scheduler(surveys, nside=nside) 

observatory = Model_observatory(nside=nside) 

observatory, scheduler, observations = sim_runner(observatory, scheduler, 

survey_length=survey_length, 

filename=None) 

 

# Make sure some blobs executed 

assert('blob, gg, a' in observations['note']) 

assert('blob, gg, b' in observations['note']) 

# assert('blob, u' in observations['note']) 

 

# Make sure some greedy executed 

assert('' in observations['note']) 

# Check that the a DD was observed 

assert('DD:ECDFS' in observations['note']) 

# Make sure a few different filters were observed 

assert(len(np.unique(observations['filter'])) > 3) 

# Make sure lots of observations executed 

assert(observations.size > 1000) 

# Make sure nothing tried to look through the earth 

assert(np.min(observations['alt']) > 0) 

 

 

class TestMemory(lsst.utils.tests.MemoryTestCase): 

pass 

 

 

def setup_module(module): 

lsst.utils.tests.init() 

 

 

174 ↛ 175line 174 didn't jump to line 175, because the condition on line 174 was never trueif __name__ == "__main__": 

lsst.utils.tests.init() 

unittest.main()