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

import numpy as np 

from lsst.sims.featureScheduler.surveys import Blob_survey, BaseSurvey 

import healpy as hp 

import copy 

 

 

__all__ = ['ToO_master', 'ToO_survey'] 

 

 

class ToO_master(BaseSurvey): 

""" 

A target of opportunity class. Every time a new ToO comes in, it will spawn a new sub-survey. 

 

Parameters 

---------- 

example_ToO_survey : lsst.sims.featureScheduler.surveys.ToO_survey object 

A survey object that will be coppied and have a new target map set 

for each incoming ToO. 

""" 

 

def __init__(self, example_ToO_survey): 

self.example_ToO_survey = example_ToO_survey 

self.surveys = [] 

self.highest_reward = -np.inf 

 

def add_observation(self, observation, indx=None): 

if len(self.surveys) > 0: 

for survey in self.surveys: 

survey.add_observation(observation, indx=indx) 

 

 

def _spawn_new_survey(self, too): 

"""Create a new survey object for a ToO we haven't seen before. 

 

Parameters 

---------- 

too : lsst.sims.featureScheduler.utils.TargetoO object 

""" 

new_survey = copy.deepcopy(self.example_ToO_survey) 

new_survey.set_id(too.id) 

new_survey.set_target_map(too.footprint) 

 

return new_survey 

 

def _check_survey_list(self, conditions): 

"""There is a current ToO in the conditions. 

""" 

 

running_ids = [survey.too_id for survey in self.surveys] 

current_ids = [too.id for too in conditions.targets_of_opportunity] 

 

# delete any ToO surveys that are no longer relevant 

self.surveys = [survey for survey in self.surveys if survey.too_id in current_ids] 

 

# Spawn new surveys that are needed 

new_surveys = [] 

for too in conditions.targets_of_opportunity: 

if too.id not in running_ids: 

new_surveys.append(self._spawn_new_survey(too)) 

self.surveys.extend(new_surveys) 

 

def calc_reward_function(self, conditions): 

# Catch if a new ToO has happened 

if conditions.targets_of_opportunity is not None: 

self._check_survey_list(conditions) 

 

if len(self.surveys) > 0: 

rewards = [np.nanmax(survey.calc_reward_function(conditions)) for survey in self.surveys] 

self.reward = np.nanmax(rewards) 

self.highest_reward = np.min(np.where(rewards == self.reward)) 

else: 

self.reward = -np.inf 

self.highest_reward = None 

return self.reward 

 

def generate_observations(self, conditions): 

if self.reward > -np.inf: 

result = self.surveys[self.highest_reward].generate_observations(conditions) 

return result 

 

 

class ToO_survey(Blob_survey): 

"""Survey class to catch incoming target of opportunity anouncements and try to observe them. 

 

The idea is that we can dynamically update the target footprint basis function, and add new features as more ToOs come in. 

 

Parameters 

---------- 

too_id : int (None) 

A unique integer ID for the ToO getting observed 

""" 

def __init__(self, basis_functions, basis_weights, 

filtername1='r', filtername2=None, 

slew_approx=7.5, filter_change_approx=140., 

read_approx=2., exptime=30., nexp=2, 

ideal_pair_time=22., min_pair_time=15., 

search_radius=30., alt_max=85., az_range=180., 

flush_time=30., 

smoothing_kernel=None, nside=None, 

dither=True, seed=42, ignore_obs=None, 

survey_note='ToO', detailers=None, camera='LSST', 

too_id=None): 

super(ToO_survey, self).__init__(basis_functions=basis_functions, basis_weights=basis_weights, 

filtername1=filtername1, filtername2=filtername2, slew_approx=slew_approx, 

filter_change_approx=filter_change_approx, read_approx=read_approx, exptime=exptime, 

nexp=nexp, ideal_pair_time=ideal_pair_time, min_pair_time=min_pair_time, search_radius=search_radius, 

alt_max=alt_max, az_range=az_range, flush_time=flush_time, smoothing_kernel=smoothing_kernel, nside=nside, 

dither=dither, seed=seed, ignore_obs=ignore_obs, survey_note=survey_note, detailers=detailers, camera=camera) 

# Include the ToO id in the note 

self.survey_note_base = self.survey_note 

self.set_id(too_id) 

 

def set_id(self, newid): 

"""Set the id 

""" 

self.too_id = newid 

self.survey_note = self.survey_note_base + ', ' + str(newid) 

 

def set_target_map(self, newmap): 

""" 

Expect one of the basis functions to be Footprint_nvis_basis_function 

""" 

for basis_func in self.basis_functions: 

if hasattr(basis_func, 'footprint'): 

basis_func.footprint = newmap 

 

def generate_observations_rough(self, conditions): 

# Always spin the tesselation before generating a new block. 

if self.dither: 

self._spin_fields() 

result = super(ToO_survey, self).generate_observations_rough(conditions) 

return result