@@ -0,0 +1,87 | |||||
|
1 | import numpy | |||
|
2 | import sys | |||
|
3 | import zmq | |||
|
4 | import time | |||
|
5 | import h5py | |||
|
6 | import os | |||
|
7 | ||||
|
8 | path="/home/alex/Downloads/pedestal" | |||
|
9 | ext=".hdf5" | |||
|
10 | ||||
|
11 | port ="5556" | |||
|
12 | if len(sys.argv)>1: | |||
|
13 | port = sys.argv[1] | |||
|
14 | int(port) | |||
|
15 | ||||
|
16 | if len(sys.argv)>2: | |||
|
17 | port1 = sys.argv[2] | |||
|
18 | int(port1) | |||
|
19 | ||||
|
20 | #Socket to talk to server | |||
|
21 | context = zmq.Context() | |||
|
22 | socket = context.socket(zmq.SUB) | |||
|
23 | ||||
|
24 | print("Collecting updates from weather server...") | |||
|
25 | socket.connect("tcp://localhost:%s"%port) | |||
|
26 | ||||
|
27 | if len(sys.argv)>2: | |||
|
28 | socket.connect("tcp://localhost:%s"%port1) | |||
|
29 | ||||
|
30 | #Subscribe to zipcode, default is NYC,10001 | |||
|
31 | topicfilter = "10001" | |||
|
32 | socket.setsockopt_string(zmq.SUBSCRIBE,topicfilter) | |||
|
33 | #Process 5 updates | |||
|
34 | total_value=0 | |||
|
35 | count= -1 | |||
|
36 | azi= [] | |||
|
37 | elev=[] | |||
|
38 | time0=[] | |||
|
39 | #for update_nbr in range(250): | |||
|
40 | while(True): | |||
|
41 | string= socket.recv() | |||
|
42 | topic,ang_elev,ang_elev_dec,ang_azi,ang_azi_dec,seconds,seconds_dec= string.split() | |||
|
43 | ang_azi =float(ang_azi)+1e-3*float(ang_azi_dec) | |||
|
44 | ang_elev =float(ang_elev)+1e-3*float(ang_elev_dec) | |||
|
45 | seconds =float(seconds) +1e-6*float(seconds_dec) | |||
|
46 | azi.append(ang_azi) | |||
|
47 | elev.append(ang_elev) | |||
|
48 | time0.append(seconds) | |||
|
49 | count +=1 | |||
|
50 | if count == 100: | |||
|
51 | timetuple=time.localtime() | |||
|
52 | epoc = time.mktime(timetuple) | |||
|
53 | #print(epoc) | |||
|
54 | fullpath = path + ("/" if path[-1]!="/" else "") | |||
|
55 | ||||
|
56 | if not os.path.exists(fullpath): | |||
|
57 | os.mkdir(fullpath) | |||
|
58 | ||||
|
59 | azi_array = numpy.array(azi) | |||
|
60 | elev_array = numpy.array(elev) | |||
|
61 | time0_array= numpy.array(time0) | |||
|
62 | pedestal_array=numpy.array([azi,elev,time0]) | |||
|
63 | count=0 | |||
|
64 | azi= [] | |||
|
65 | elev=[] | |||
|
66 | time0=[] | |||
|
67 | #print(pedestal_array[0]) | |||
|
68 | #print(pedestal_array[1]) | |||
|
69 | ||||
|
70 | meta='PE' | |||
|
71 | filex="%s%4.4d%3.3d%10.4d%s"%(meta,timetuple.tm_year,timetuple.tm_yday,epoc,ext) | |||
|
72 | filename = os.path.join(fullpath,filex) | |||
|
73 | fp = h5py.File(filename,'w') | |||
|
74 | #print("Escribiendo HDF5...",epoc) | |||
|
75 | #·················· Data·....······································ | |||
|
76 | grp = fp.create_group("Data") | |||
|
77 | dset = grp.create_dataset("azimuth" , data=pedestal_array[0]) | |||
|
78 | dset = grp.create_dataset("elevacion", data=pedestal_array[1]) | |||
|
79 | dset = grp.create_dataset("utc" , data=pedestal_array[2]) | |||
|
80 | #·················· Metadata······································· | |||
|
81 | grp = fp.create_group("Metadata") | |||
|
82 | dset = grp.create_dataset("utctimeInit", data=pedestal_array[2][0]) | |||
|
83 | timeInterval = pedestal_array[2][1]-pedestal_array[2][0] | |||
|
84 | dset = grp.create_dataset("timeInterval", data=timeInterval) | |||
|
85 | fp.close() | |||
|
86 | ||||
|
87 | #print ("Average messagedata value for topic '%s' was %dF" % ( topicfilter,total_value / update_nbr)) |
General Comments 0
You need to be logged in to leave comments.
Login now