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

from builtins import object 

from lsst.sims.alertsim.VOEventLib import (VOEvent, Who, Author, Citations, 

EventIVORN, What, Group, Param, 

makeWhereWhen, stringVOEvent) 

 

from astropy.time import Time as AstropyTime 

 

class VOEventGenerator(object): 

 

""" A class for generating VOEvent documents. 

Uses VOEventLib by Roy Williams 

""" 

 

schemaURL = "http://www.cacr.caltech.edu/~roy/VOEvent/VOEvent2-110220.xsd" 

voevent_version = "2.0" 

observatory = "LSST CatSim" 

 

def __init__(self, eventid, description="", role="test"): 

self.ra = self.dec = '' 

self._initVOEvent(description, role, eventid) 

self.setAuthor(contactName="", contactEmail="") 

self.setCitations() 

 

def _initVOEvent(self, description, role, eventid): 

############ VOEvent header ############################ 

self.voevent = VOEvent(version=self.voevent_version) 

self.voevent.set_ivorn("ivo://servo.aob.rs/alertsim#%s" % eventid) 

self.voevent.set_role(role) 

self.voevent.set_Description(description) 

 

def setAuthor(self, contactName, contactEmail): 

############ Who ############################ 

who = Who() 

author = Author() 

author.add_contactName(contactName) 

author.add_contactEmail(contactEmail) 

who.set_Author(author) 

self.voevent.set_Who(who) 

 

def setCitations(self): 

############ Citation ############################ 

#todo 

c = Citations() 

c.add_EventIVORN(EventIVORN(cite="followup", valueOf_="ivo:lsst.org/resource#89474")) 

c.add_EventIVORN(EventIVORN(cite="followup", valueOf_="ivo:lsst.org/resource#89475")) 

self.voevent.set_Citations(c) 

 

 

#def generateFromObjects(self, diaSourceData, diaObjectData, obsMetaData): 

def generateFromObjects(self, diaSourcesData, obsMetaData): 

 

for key, data_tuple in diaSourcesData[0].__dict__.items(): 

if data_tuple.ucd == 'pos.eq.ra': 

self.ra = data_tuple.value 

elif data_tuple.ucd == 'pos.eq.dec': 

self.dec = data_tuple.value 

 

############ What ############################ 

w = What() 

# 

for diaSourceData in diaSourcesData: 

g = Group(type_="DIASource", name="DIASource") 

for key, val in diaSourceData.__dict__.items(): 

if not key.startswith("__"): 

p = Param(name=key, ucd=val.ucd, value=val.value, unit = val.unit) 

g.add_Param(p) 

w.add_Group(g) 

 

""" 

g = Group(type_="DIAObject", name="DIAObject") 

for key, val in diaObjectData.__dict__.items(): 

if not key.startswith("__"): 

p = Param(name=key, ucd=val.ucd, value=val.value, unit = val.unit) 

g.add_Param(p) 

w.add_Group(g) 

# """ 

self.voevent.set_What(w) 

 

############ Wherewhen ############################ 

wwd = {'observatory': self.observatory, 

'coord_system': 'UTC-FK5-GEO', 

'time': self._convertToIso(obsMetaData.mjd.TAI), 

'timeError': 0.11, 

'longitude': self.ra, 

'latitude': self.dec, 

'positionalError': 0.01, 

} 

 

ww = makeWhereWhen(wwd) 

if ww: self.voevent.set_WhereWhen(ww) 

 

 

############ output the event ############################ 

xml = stringVOEvent(self.voevent, self.schemaURL) 

return xml 

 

def generateFromDicts(self, alert_dict): 

 

diaSource = alert_dict['diaSource'] 

 

self.ra = diaSource['ra'] 

self.dec = diaSource['decl'] 

 

############ What ############################ 

w = What() 

 

g = Group(type_="DIASource", name="DIASourceCurrent") 

for key, val in diaSource.items(): 

if type(val) is not dict: 

p = Param(name=key, ucd='', value=val, unit = '') 

g.add_Param(p) 

else: 

for nkey, nval in val.items(): 

p = Param(name=nkey, ucd='', value=nval, unit = '') 

g.add_Param(p) 

 

w.add_Group(g) 

 

if 'prv_diaSources' in alert_dict: 

diaSourceHistory = alert_dict['prv_diaSources'] 

for historicalDiaSource in diaSourceHistory: 

g = Group(type_="DIASource", name="DIASourceHistory") 

for key, val in historicalDiaSource.items(): 

if type(val) is not dict: 

p = Param(name=key, ucd='', value=val, unit = '') 

g.add_Param(p) 

else: 

for nkey, nval in val.items(): 

p = Param(name=nkey, ucd='', value=nval, unit = '') 

g.add_Param(p) 

 

 

 

w.add_Group(g) 

 

""" 

g = Group(type_="DIAObject", name="DIAObject") 

for key, val in diaObjectData.__dict__.items(): 

if not key.startswith("__"): 

p = Param(name=key, ucd=val.ucd, value=val.value, unit = val.unit) 

g.add_Param(p) 

w.add_Group(g) 

# """ 

self.voevent.set_What(w) 

 

############ Wherewhen ############################ 

wwd = {'observatory': self.observatory, 

'coord_system': 'UTC-FK5-GEO', 

'time': self._convertToIso(diaSource['midPointTai']), 

'timeError': 0.11, 

'longitude': self.ra, 

'latitude': self.dec, 

'positionalError': 0.01, 

} 

 

ww = makeWhereWhen(wwd) 

if ww: self.voevent.set_WhereWhen(ww) 

 

 

############ output the event ############################ 

xml = stringVOEvent(self.voevent, self.schemaURL) 

return xml 

 

 

def _convertToIso(self, mjd): 

t = AstropyTime(mjd, format='mjd', scale='tai') 

return t.iso