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