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

from __future__ import with_statement 

import xml.etree.ElementTree as ET 

 

 

def read_and_divide(uri): 

 

""" 

Takes the file outputted by the receiver 

(lsst.sims.alertsim.broadcast.receivers.rec_tcp) 

and divides it to a list of VOEvents 

""" 

 

voevent_list = [] 

voevent = "" 

voevent_flag = False 

 

with open (uri, 'r') as voevents_file: 

 

for line in voevents_file: 

 

if not voevent_flag: 

phrase = "<?xml" 

index = line.find(phrase) 

if index != -1: 

voevent += line[index:] 

voevent_flag = True 

 

else: 

phrase = "</voe:VOEvent>" 

index = line.find(phrase) 

if index != -1: 

voevent += line[:index+len(phrase)] 

voevent_list.append(voevent) 

voevent = "" 

voevent_flag = False 

else: 

voevent += line 

 

return voevent_list 

 

def parse_parameters(ucds, voevent_list): 

 

""" 

Returns a list which contains dicts of values for each ucd 

that was matched in the VOEvent 

""" 

 

data_list = [] 

for voevent in voevent_list: 

data_dict = {} 

root = ET.fromstring(voevent) 

for ucd in ucds: 

#XPATH expression for matching given ucd 

lines = root.findall("What//Param[@ucd='%s']" % (ucd,)) 

for line in lines: 

value = line.attrib["value"] 

name = line.attrib["name"] 

data_dict[name] = value 

#XPATH expression for matching ISOTime 

isoTime = root.findtext("*//ISOTime") 

data_dict['isoTime'] = root.findtext("*//ISOTime") 

data_list.append(data_dict) 

 

return data_list