##// END OF EJS Templates
merge con cli
José Chávez -
r1035:b65644e03ac2 merge
parent child
Show More
@@ -0,0 +1,94
1 import argparse
2
3 from schainpy.controller import Project, multiSchain
4
5 desc = "HF_EXAMPLE"
6
7 def fiber(cursor, skip, q, dt):
8
9 controllerObj = Project()
10
11 controllerObj.setup(id='191', name='test01', description=desc)
12
13 readUnitConfObj = controllerObj.addReadUnit(datatype='SpectraReader',
14 path='/home/nanosat/data/julia',
15 startDate=dt,
16 endDate=dt,
17 startTime="00:00:00",
18 endTime="23:59:59",
19 online=0,
20 #set=1426485881,
21 delay=10,
22 walk=1,
23 queue=q,
24 cursor=cursor,
25 skip=skip,
26 #timezone=-5*3600
27 )
28
29 # #opObj11 = readUnitConfObj.addOperation(name='printNumberOfBlock')
30 #
31 procUnitConfObj2 = controllerObj.addProcUnit(datatype='Spectra', inputId=readUnitConfObj.getId())
32 # procUnitConfObj2.addParameter(name='nipp', value='5', format='int')
33
34 # procUnitConfObj3 = controllerObj.addProcUnit(datatype='ParametersProc', inputId=readUnitConfObj.getId())
35 # opObj11 = procUnitConfObj3.addOperation(name='SpectralMoments', optype='other')
36
37 #
38 opObj11 = procUnitConfObj2.addOperation(name='RTIPlot', optype='other')
39 opObj11.addParameter(name='id', value='1000', format='int')
40 opObj11.addParameter(name='wintitle', value='HF_Jicamarca_Spc', format='str')
41 opObj11.addParameter(name='xmin', value='0', format='int')
42 opObj11.addParameter(name='xmax', value='24', format='int')
43
44 # opObj11 = procUnitConfObj3.addOperation(name='Parameters1Plot', optype='other')
45 # opObj11.addParameter(name='channelList', value='0', format='intList')
46 #
47 # opObj11.addParameter(name='id', value='2000', format='int')
48 # # opObj11.addParameter(name='colormap', value='0', format='bool')
49 # opObj11.addParameter(name='onlySNR', value='1', format='bool')
50 # opObj11.addParameter(name='DOP', value='0', format='bool')
51 # opObj11.addParameter(name='showSNR', value='1', format='bool')
52 # opObj11.addParameter(name='SNRthresh', value='0', format='int')
53 # opObj11.addParameter(name='SNRmin', value='-10', format='int')
54 # opObj11.addParameter(name='SNRmax', value='30', format='int')
55
56 # opObj11.addParameter(name='showSNR', value='1', format='int')
57 # # opObj11.addParameter(name='channelList', value='0', format='intlist')
58 # # opObj11.addParameter(name='xmin', value='0', format='float')
59 # opObj11.addParameter(name='xmin', value='0', format='float')
60 # opObj11.addParameter(name='xmax', value='24', format='float')
61
62 # opObj11.addParameter(name='zmin', value='-110', format='float')
63 # opObj11.addParameter(name='zmax', value='-70', format='float')
64 # opObj11.addParameter(name='save', value='0', format='int')
65 # # opObj11.addParameter(name='figpath', value='/tmp/', format='str')
66 #
67 # opObj12 = procUnitConfObj2.addOperation(name='PublishData', optype='other')
68 # opObj12.addParameter(name='zeromq', value=1, format='int')
69 # opObj12.addParameter(name='server', value='tcp://10.10.10.82:7000', format='str')
70
71
72 # opObj13 = procUnitConfObj3.addOperation(name='PublishData', optype='other')
73 # opObj13.addParameter(name='zeromq', value=1, format='int')
74 # opObj13.addParameter(name='server', value="juanca", format='str')
75
76 # opObj12.addParameter(name='delay', value=1, format='int')
77
78
79 # print "Escribiendo el archivo XML"
80 # controllerObj.writeXml(filename)
81 # print "Leyendo el archivo XML"
82 # controllerObj.readXml(filename)
83
84
85 # timeit.timeit('controllerObj.run()', number=2)
86
87 controllerObj.start()
88
89
90 if __name__ == '__main__':
91 parser = argparse.ArgumentParser(description='Set number of parallel processes')
92 parser.add_argument('--nProcess', default=1, type=int)
93 args = parser.parse_args()
94 multiSchain(fiber, nProcess=args.nProcess, startDate='2016/08/19', endDate='2016/08/19')
@@ -0,0 +1,6
1 [Desktop Entry]
2 Encoding=UTF-8
3 Name=Link to
4 Type=Link
5 URL=file:///home/nanosat/schain/schainpy/utils/parameters.txt
6 Icon=text-plain
This diff has been collapsed as it changes many lines, (1177 lines changed) Show them Hide them
@@ -0,0 +1,1177
1
2 global_type_string = 'string'
3 global_type_integer = 'int'
4 global_type_floatList = 'floatList'
5 global_type_pairsList = 'pairsList'
6 global_type_boolean = 'bolean'
7 global_type_float = 'float'
8 global_type_colormap = 'colormap'
9 global_type_list = 'list'
10 global_type_integer_or_list = 'integer_or_list'
11
12 #BeaconPhase
13 parameters = {
14 'id': global_type_string,
15 'wintitle': global_type_string,
16 'pairsList': global_type_pairsList,
17 'showprofile': global_type_boolean,
18 'xmin': global_type_float,
19 'xmax': global_type_float,
20 'ymin': global_type_float,
21 'ymax': global_type_float,
22 'hmin': global_type_float,
23 'hmax': global_type_float,
24 'timerange': global_type_float,
25 'save': global_type_boolean,
26 'figpath': global_type_string,
27 'figfile': global_type_string,
28 'show': global_type_boolean,
29 'ftp': global_type_boolean,
30 'wr_period': global_type_integer,
31 'server': global_type_string,
32 'folder': global_type_string,
33 'username': global_type_string,
34 'password': global_type_string,
35 'ftp_wei': global_type_integer,
36 'exp_code': global_type_integer,
37 'sub_exp_code': global_type_integer,
38 'plot_pos': global_type_integer,
39 }
40
41
42 #BeamSelector
43 parameters = {
44 'beam': global_type_string,
45 }
46
47
48 #CohInt
49 parameters = {
50 'n': global_type_integer,
51 'timeInterval': global_type_float,
52 'overlapping': global_type_boolean,
53 'byblock': global_type_boolean
54 }
55
56
57 #CoherenceMap
58 parameters = {
59 'id': global_type_string,
60 'wintitle': global_type_string,
61 'pairsList': global_type_pairsList,
62 'showprofile': global_type_boolean,
63 'xmin': global_type_float,
64 'xmax': global_type_float,
65 'ymin': global_type_float,
66 'ymax': global_type_float,
67 'zmin': global_type_float,
68 'zmax': global_type_float,
69 'timerange': global_type_float,
70 'phase_min': global_type_float,
71 'phase_max': global_type_float,
72 'save': global_type_boolean,
73 'figpath': global_type_string,
74 'figfile': global_type_string,
75 'ftp': global_type_boolean,
76 'wr_period': global_type_integer,
77 'coherence_cmap': global_type_colormap,
78 'phase_cmap': global_type_colormap,
79 'show': global_type_boolean,
80 'server': global_type_string,
81 'folder': global_type_string,
82 'username': global_type_string,
83 'password': global_type_string,
84 'ftp_wei': global_type_integer,
85 'exp_code': global_type_integer,
86 'sub_exp_code': global_type_integer,
87 'plot_pos': global_type_integer,
88 }
89
90
91 #CombineProfiles
92 parameters = {
93 'n': global_type_integer,
94 }
95
96
97 #CorrectSMPhases
98 parameters = {
99 'phaseOffsets': global_type_pairsList,
100 'hmin': global_type_float,
101 'hmax': global_type_float,
102 'azimuth': global_type_float,
103 'channelPositions': global_type_pairsList,
104 }
105
106
107 #CorrelationPlot
108 parameters = {
109 'id': global_type_string,
110 'wintitle': global_type_string,
111 'channelList': global_type_list,
112 'showprofile': global_type_boolean,
113 'xmin': global_type_float,
114 'xmax': global_type_float,
115 'ymin': global_type_float,
116 'ymax': global_type_float,
117 'zmin': global_type_float,
118 'zmax': global_type_float,
119 'save': global_type_boolean,
120 'figpath': global_type_string,
121 'figfile': global_type_string,
122 'show': global_type_boolean,
123 'ftp': global_type_boolean,
124 'wr_period': global_type_integer,
125 'server': global_type_string,
126 'folder': global_type_string,
127 'username': global_type_string,
128 'password': global_type_string,
129 'ftp_wei': global_type_integer,
130 'exp_code': global_type_integer,
131 'sub_exp_code': global_type_integer,
132 'plot_pos': global_type_integer,
133 'realtime': global_type_boolean,
134 }
135
136
137 #CrossSpectraPlot
138 parameters = {
139 'id': global_type_string,
140 'wintitle': global_type_string,
141 'pairsList': global_type_pairsList,
142 'xmin': global_type_float,
143 'xmax': global_type_float,
144 'ymin': global_type_float,
145 'ymax': global_type_float,
146 'zmin': global_type_float,
147 'zmax': global_type_float,
148 'coh_min': global_type_float,
149 'coh_max': global_type_float,
150 'phase_min': global_type_float,
151 'phase_max': global_type_float,
152 'save': global_type_boolean,
153 'figpath': global_type_string,
154 'figfile': global_type_string,
155 'ftp': global_type_boolean,
156 'wr_period': global_type_integer,
157 'power_cmap': global_type_colormap,
158 'coherence_cmap': global_type_colormap,
159 'phase_cmap': global_type_colormap,
160 'show': global_type_boolean,
161 'server': global_type_string,
162 'folder': global_type_string,
163 'username': global_type_string,
164 'password': global_type_string,
165 'ftp_wei': global_type_integer,
166 'exp_code': global_type_integer,
167 'sub_exp_code': global_type_integer,
168 'plot_pos': global_type_integer,
169 'xaxis': global_type_string,
170 }
171
172
173 #Decoder
174 parameters = {
175 'code': global_type_list,
176 'nCode': global_type_integer,
177 'nBaud': global_type_integer,
178 'mode': global_type_integer,
179 'osamp': global_type_float,
180 }
181
182
183 #EWDriftsEstimation
184 parameters = {
185 'zenith': global_type_list,
186 'zenithCorrection': global_type_float,
187 }
188
189
190 #EWDriftsPlot
191 parameters = {
192 'id': global_type_string,
193 'wintitle': global_type_string,
194 'channelList': global_type_list,
195 'xmin': global_type_float,
196 'xmax': global_type_float,
197 'ymin': global_type_float,
198 'ymax': global_type_float,
199 'zmin': global_type_float,
200 'zmax': global_type_float,
201 'zmaxVertfloat': global_type_float,
202 'zminVertfloat': global_type_float,
203 'zmaxZonafloat': global_type_float,
204 'zminZonafloat': global_type_float,
205 'timerange': global_type_float,
206 'SNRthresh': global_type_float,
207 'SNRmin': global_type_float,
208 'SNRmax': global_type_float,
209 'SNR_1': global_type_boolean,
210 'save': global_type_boolean,
211 'figpath': global_type_string,
212 'lastone': global_type_float,
213 'figfile': global_type_string,
214 'ftp': global_type_string,
215 'wr_period': global_type_integer,
216 'show': global_type_string,
217 'server': global_type_string,
218 'folder': global_type_string,
219 'username': global_type_string,
220 'password': global_type_string,
221 'ftp_wei': global_type_integer,
222 'exp_code': global_type_integer,
223 'sub_exp_code': global_type_integer,
224 'plot_pos': global_type_integer,
225 }
226
227
228 Figure
229 # parameters = {
230 # : global_type_string,
231 # }
232
233
234 #FitsWriter
235 parameters = {
236 'path': global_type_string,
237 'dataBlocksPerFile': global_type_integer,
238 'metadatafile': global_type_string,
239 }
240
241
242 #IncohInt
243 parameters = {
244 'n': global_type_float,
245 'timeInterval': global_type_integer,
246 'overlapping': global_type_boolean,
247 }
248
249
250 #IncohInt4SpectraHeis
251 parameters = {
252 'n': global_type_float,
253 'timeInterval': global_type_integer,
254 'overlapping': global_type_boolean,
255 }
256
257
258 #MomentsPlot
259 parameters = {
260 'id': global_type_string,
261 'wintitle': global_type_string,
262 'channelList': global_type_list,
263 'showprofile': global_type_boolean,
264 'xmin': global_type_float,
265 'xmax': global_type_float,
266 'ymin': global_type_float,
267 'ymax': global_type_float,
268 'zmin': global_type_float,
269 'zmax': global_type_float,
270 'save': global_type_boolean,
271 'figpath': global_type_string,
272 'figfile': global_type_string,
273 'show': global_type_boolean,
274 'ftp': global_type_boolean,
275 'wr_period': global_type_integer,
276 'server': global_type_string,
277 'folder': global_type_string,
278 'username': global_type_string,
279 'password': global_type_string,
280 'ftp_wei': global_type_string,
281 'exp_code': global_type_integer,
282 'sub_exp_code': global_type_integer,
283 'plot_pos': global_type_integer,
284 'realtime': global_type_boolean,
285 }
286
287
288 #NSMeteorDetection1Plot
289 parameters = {
290 'id': global_type_string,
291 'wintitle': global_type_string,
292 'channelList': global_type_list,
293 'showprofile': global_type_boolean,
294 'xmin': global_type_float,
295 'xmax': global_type_float,
296 'ymin': global_type_float,
297 'ymax': global_type_float,
298 'SNRmin': global_type_float,
299 'SNRmax': global_type_float,
300 'vmin': global_type_float,
301 'vmax': global_type_float,
302 'wmin': global_type_float,
303 'wmax': global_type_float,
304 'mode': global_type_string,
305 'save': global_type_boolean,
306 'figpath': global_type_string,
307 'figfile': global_type_string,
308 'show': global_type_boolean,
309 'ftp': global_type_string,
310 'wr_period': global_type_integer,
311 'server': global_type_string,
312 'folder': global_type_string,
313 'username': global_type_string,
314 'password': global_type_string,
315 'ftp_wei': global_type_integer,
316 'exp_code': global_type_integer,
317 'sub_exp_code': global_type_integer,
318 'plot_pos': global_type_integer,
319 'realtime': global_type_boolean,
320 'xaxis': global_type_string,
321 }
322
323
324 #NSMeteorDetection2Plot
325 parameters = {
326 'id': global_type_string,
327 'wintitle': global_type_string,
328 'channelList': global_type_list,
329 'showprofile': global_type_boolean,
330 'xmin': global_type_float,
331 'xmax': global_type_float,
332 'ymin': global_type_float,
333 'ymax': global_type_float,
334 'SNRmin': global_type_float,
335 'SNRmax': global_type_float,
336 'vmin': global_type_float,
337 'vmax': global_type_float,
338 'wmin': global_type_float,
339 'wmax': global_type_float,
340 'mode': global_type_string,
341 'save': global_type_boolean,
342 'figpath': global_type_string,
343 'figfile': global_type_string,
344 'show': global_type_string,
345 'ftp': global_type_boolean,
346 'wr_period': global_type_integer,
347 'server': global_type_string,
348 'folder': global_type_string,
349 'username': global_type_string,
350 'password': global_type_string,
351 'ftp_wei': global_type_integer,
352 'exp_code': global_type_integer,
353 'sub_exp_code': global_type_integer,
354 'plot_pos': global_type_integer,
355 'realtime': global_type_boolean,
356 'xaxis': global_type_string,
357 }
358
359
360 #Noise
361 parameters = {
362 'id': global_type_string,
363 'wintitle': global_type_string,
364 'channelList': global_type_list,
365 'showprofile': global_type_boolean,
366 'xmin': global_type_float,
367 'xmax': global_type_float,
368 'ymin': global_type_float,
369 'ymax': global_type_float,
370 'timerange': global_type_float,
371 'save': global_type_boolean,
372 'figpath': global_type_string,
373 'figfile': global_type_string,
374 'show': global_type_boolean,
375 'ftp': global_type_boolean,
376 'wr_period': global_type_integer,
377 'server': global_type_string,
378 'folder': global_type_string,
379 'username': global_type_string,
380 'password': global_type_string,
381 'ftp_wei': global_type_integer,
382 'exp_code': global_type_integer,
383 'sub_exp_code': global_type_integer,
384 'plot_pos': global_type_integer,
385 }
386
387
388 #NonSpecularMeteorDetection
389 parameters = {
390 'mode': global_type_string,
391 'SNRthresh': global_type_float,
392 'phaseDerThresh': global_type_float,
393 'cohThresh': global_type_float,
394 'allData': global_type_boolean,
395 }
396
397
398 Operation
399 parameters = {
400 'dataIn': global_type_string,
401 }
402
403
404 #ParamWriter
405 parameters = {
406 'path': global_type_string,
407 'blocksPerFile':global_type_integer,
408 'metadataList': global_type_list,
409 'dataList': global_type_list,
410 'mode': global_type_integer,
411 }
412
413
414 #Parameters1Plot
415 parameters = {
416 'id': global_type_string,
417 'wintitle': global_type_string,
418 'channelList': global_type_list,
419 'showprofile': global_type_boolean,
420 'xmin': global_type_float,
421 'xmax': global_type_float,
422 'ymin': global_type_float,
423 'ymax': global_type_float,
424 'zmin': global_type_float,
425 'zmax': global_type_float,
426 'timerange': global_type_float,
427 'parameterIndex': global_type_float,
428 'onlyPositive': global_type_boolean,
429 'SNRthresh': global_type_float,
430 'SNR': global_type_boolean,
431 'SNRmin': global_type_float,
432 'SNRmax': global_type_float,
433 'onlySNR': global_type_boolean,
434 'DOP': global_type_boolean,
435 'zlabel': global_type_string,
436 'parameterName': global_type_string,
437 'parameterObject': global_type_string,
438 'save': global_type_boolean,
439 'figpath': global_type_string,
440 'lastone': global_type_integer,
441 'figfile': global_type_string,
442 'ftp': global_type_boolean,
443 'wr_period': global_type_integer,
444 'show': global_type_string,
445 'server': global_type_string,
446 'folder': global_type_string,
447 'username': global_type_string,
448 'password': global_type_string,
449 'ftp_wei': global_type_integer,
450 'exp_code': global_type_integer,
451 'sub_exp_code': global_type_integer,
452 'plot_pos': global_type_integer,
453 }
454
455
456 #ParametersPlot
457 parameters = {
458 'id': global_type_string,
459 'wintitle': global_type_string,
460 'channelList': global_type_list,
461 'paramIndex': global_type_integer,
462 'colormap': global_type_colormap,
463 'xmin': global_type_float,
464 'xmax': global_type_float,
465 'ymin': global_type_float,
466 'ymax': global_type_float,
467 'zmin': global_type_float,
468 'zmax': global_type_float,
469 'timerange': global_type_float,
470 'showSNR': global_type_boolean,
471 'SNRthresh': global_type_float,
472 'SNRmin': global_type_float,
473 'SNRmax': global_type_float,
474 'save': global_type_boolean,
475 'figpath': global_type_string,
476 'lastone': global_type_integer,
477 'figfile': global_type_string,
478 'ftp': global_type_boolean,
479 'wr_period': global_type_integer,
480 'show': global_type_boolean,
481 'server': global_type_string,
482 'folder': global_type_string,
483 'username': global_type_string,
484 'password': global_type_string,
485 'ftp_wei': global_type_integer,
486 'exp_code': global_type_integer,
487 'sub_exp_code': global_type_integer,
488 'plot_pos': global_type_integer,
489 }
490
491
492 #PhasePlot
493 parameters = {
494 'id': global_type_string,
495 'wintitle': global_type_string,
496 'pairsList': global_type_pairsList,
497 'showprofile': global_type_boolean,
498 'xmin': global_type_float,
499 'xmax': global_type_float,
500 'ymin': global_type_float,
501 'ymax': global_type_float,
502 'timerange': global_type_float,
503 'save': global_type_boolean,
504 'figpath': global_type_string,
505 'figfile': global_type_string,
506 'show': global_type_boolean,
507 'ftp': global_type_boolean,
508 'wr_period': global_type_integer,
509 'server': global_type_string,
510 'folder': global_type_string,
511 'username': global_type_string,
512 'password': global_type_string,
513 'ftp_wei': global_type_integer,
514 'exp_code': global_type_integer,
515 'sub_exp_code': global_type_integer,
516 'plot_pos': global_type_integer,
517 }
518
519
520 PlotCOHData
521 parameters = {
522 : global_type_string,
523 }
524
525
526 PlotCrossSpectraData
527 parameters = {
528 : global_type_string,
529 }
530
531
532 PlotDOPData
533 parameters = {
534 : global_type_string,
535 }
536
537
538 PlotData
539 parameters = {
540 : global_type_string,
541 }
542
543
544 PlotNoiseData
545 parameters = {
546 : global_type_string,
547 }
548
549
550 PlotPHASEData
551 parameters = {
552 : global_type_string,
553 }
554
555
556 PlotRTIData
557 parameters = {
558 : global_type_string,
559 }
560
561
562 PlotSNRData
563 parameters = {
564 : global_type_string,
565 }
566
567
568 PlotSpectraData
569 parameters = {
570 : global_type_string,
571 }
572
573
574 PlotSpectraMeanData
575 parameters = {
576 : global_type_string,
577 }
578
579
580 PlotWindProfilerData
581 parameters = {
582 : global_type_string,
583 }
584
585
586 PowerProfilePlot
587 parameters = {
588 'id': global_type_string,
589 'wintitle': global_type_string,
590 'channelList': global_type_list,
591 'xmin': global_type_float,
592 'xmax': global_type_float,
593 'ymin': global_type_float,
594 'ymax': global_type_float,
595 'save': global_type_boolean,
596 'figpath': global_type_string,
597 'figfile': global_type_string,
598 'show': global_type_boolean,
599 'ftp': global_type_boolean,
600 'wr_period': global_type_integer,
601 'server': global_type_string,
602 'folder': global_type_string,
603 'username': global_type_string,
604 'password': global_type_string,
605 }
606
607
608 PrintInfo
609 parameters = {
610 : global_type_string,
611 }
612
613
614 ProfileConcat
615 parameters = {
616 'm': global_type_string,
617 }
618
619
620 ProfileSelector
621 parameters = {
622 'profileList': global_type_string,
623 'profileRangeList': global_type_string,
624 'beam': global_type_string,
625 'byblock': global_type_string,
626 'rangeList': global_type_string,
627 'nProfiles': global_type_string,
628 }
629
630
631 ProfileToChannels
632 parameters = {
633 : global_type_string,
634 }
635
636
637 PublishData
638 parameters = {
639 : global_type_string,
640 }
641
642
643 RTIPlot
644 parameters = {
645 'id': global_type_string,
646 'wintitle': global_type_string,
647 'channelList': global_type_list,
648 'showprofile': global_type_boolean,
649 'xmin': global_type_float,
650 'xmax': global_type_float,
651 'ymin': global_type_float,
652 'ymax': global_type_float,
653 'zmin': global_type_float,
654 'zmax': global_type_float,
655 'timerange': global_type_float,
656 'save': global_type_boolean,
657 'figpath': global_type_string,
658 'lastone': global_type_string,
659 'figfile': global_type_string,
660 'ftp': global_type_boolean,
661 'wr_period': global_type_integer,
662 'show': global_type_boolean,
663 'server': global_type_string,
664 'folder': global_type_string,
665 'username': global_type_string,
666 'password': global_type_string,
667 'ftp_wei': global_type_integer,
668 'exp_code': global_type_integer,
669 'sub_exp_code': global_type_integer,
670 'plot_pos': global_type_integer,
671 }
672
673
674 RTIfromSpectraHeis
675 parameters = {
676 'id': global_type_string,
677 'wintitle': global_type_string,
678 'channelList': global_type_list,
679 'showprofile': global_type_boolean,
680 'xmin': global_type_float,
681 'xmax': global_type_float,
682 'ymin': global_type_float,
683 'ymax': global_type_float,
684 'timerange': global_type_float,
685 'save': global_type_boolean,
686 'figpath': global_type_string,
687 'figfile': global_type_string,
688 'ftp': global_type_boolean,
689 'wr_period': global_type_integer,
690 'show': global_type_boolean,
691 'server': global_type_string,
692 'folder': global_type_string,
693 'username': global_type_string,
694 'password': global_type_string,
695 'ftp_wei': global_type_integer,
696 'exp_code': global_type_integer,
697 'sub_exp_code': global_type_integer,
698 'plot_pos': global_type_integer,
699 }
700
701
702 Reshaper
703 parameters = {
704 'shape': global_type_string,
705 'nTxs': global_type_string,
706 }
707
708
709 SALags
710 parameters = {
711 : global_type_string,
712 }
713
714
715 SMDetection
716 parameters = {
717 'hei_ref': global_type_string,
718 'tauindex': global_type_string,
719 'phaseOffsets': global_type_string,
720 'cohDetection': global_type_string,
721 'cohDet_timeStep': global_type_string,
722 'cohDet_thresh': global_type_string,
723 'noise_timeStep': global_type_string,
724 'noise_multiple': global_type_string,
725 'multDet_timeLimit': global_type_string,
726 'multDet_rangeLimit': global_type_string,
727 'phaseThresh': global_type_string,
728 'SNRThresh': global_type_string,
729 'hmin': global_type_string,
730 'hmax': global_type_string,
731 'azimuth': global_type_string,
732 'channelPositions': global_type_string,
733 }
734
735
736 SMPhaseCalibration
737 parameters = {
738 'hmin': global_type_string,
739 'hmax': global_type_string,
740 'channelPositions': global_type_string,
741 'nHours': global_type_string,
742 }
743
744
745 Scope
746 parameters = {
747 'id': global_type_string,
748 'wintitle': global_type_string,
749 'channelList': global_type_list,
750 'xmin': global_type_float,
751 'xmax': global_type_float,
752 'ymin': global_type_float,
753 'ymax': global_type_float,
754 'save': global_type_boolean,
755 'figpath': global_type_string,
756 'figfile': global_type_string,
757 'show': global_type_boolean,
758 'wr_period': global_type_integer,
759 'ftp': global_type_boolean,
760 'server': global_type_string,
761 'folder': global_type_string,
762 'username': global_type_string,
763 'password': global_type_string,
764 'type': global_type_string,
765 }
766
767
768 SendByFTP
769 parameters = {
770 'ext': global_type_string,
771 'localfolder': global_type_string,
772 'remotefolder': global_type_string,
773 'server': global_type_string,
774 'username': global_type_string,
775 'password': global_type_string,
776 'period': global_type_string,
777 }
778
779
780 SkyMapPlot
781 parameters = {
782 'id': global_type_string,
783 'wintitle': global_type_string,
784 'channelList': global_type_list,
785 'showprofile': global_type_boolean,
786 'tmin': global_type_string,
787 'tmax': global_type_string,
788 'timerange': global_type_float,
789 'save': global_type_boolean,
790 'figpath': global_type_string,
791 'figfile': global_type_string,
792 'show': global_type_boolean,
793 'ftp': global_type_boolean,
794 'wr_period': global_type_integer,
795 'server': global_type_string,
796 'folder': global_type_string,
797 'username': global_type_string,
798 'password': global_type_string,
799 'ftp_wei': global_type_integer,
800 'exp_code': global_type_integer,
801 'sub_exp_code': global_type_integer,
802 'plot_pos': global_type_integer,
803 'realtime': global_type_boolean,
804 }
805
806
807 SpectraCutPlot
808 parameters = {
809 'id': global_type_string,
810 'wintitle': global_type_string,
811 'channelList': global_type_list,
812 'xmin': global_type_float,
813 'xmax': global_type_float,
814 'ymin': global_type_float,
815 'ymax': global_type_float,
816 'save': global_type_boolean,
817 'figpath': global_type_string,
818 'figfile': global_type_string,
819 'show': global_type_boolean,
820 'ftp': global_type_boolean,
821 'wr_period': global_type_integer,
822 'server': global_type_string,
823 'folder': global_type_string,
824 'username': global_type_string,
825 'password': global_type_string,
826 'xaxis': global_type_string,
827 }
828
829
830 SpectraHeisScope
831 parameters = {
832 'id': global_type_string,
833 'wintitle': global_type_string,
834 'channelList': global_type_list,
835 'xmin': global_type_float,
836 'xmax': global_type_float,
837 'ymin': global_type_float,
838 'ymax': global_type_float,
839 'save': global_type_boolean,
840 'figpath': global_type_string,
841 'figfile': global_type_string,
842 'ftp': global_type_boolean,
843 'wr_period': global_type_integer,
844 'show': global_type_boolean,
845 'server': global_type_string,
846 'folder': global_type_string,
847 'username': global_type_string,
848 'password': global_type_string,
849 'ftp_wei': global_type_integer,
850 'exp_code': global_type_integer,
851 'sub_exp_code': global_type_integer,
852 'plot_pos': global_type_integer,
853 }
854
855
856 SpectraHeisWriter
857 parameters = {
858 : global_type_string,
859 }
860
861
862 SpectraPlot
863 parameters = {
864 'id': global_type_string,
865 'wintitle': global_type_string,
866 'channelList': global_type_list,
867 'showprofile': global_type_boolean,
868 'xmin': global_type_float,
869 'xmax': global_type_float,
870 'ymin': global_type_float,
871 'ymax': global_type_float,
872 'zmin': global_type_float,
873 'zmax': global_type_float,
874 'save': global_type_boolean,
875 'figpath': global_type_string,
876 'figfile': global_type_string,
877 'show': global_type_boolean,
878 'ftp': global_type_boolean,
879 'wr_period': global_type_integer,
880 'server': global_type_string,
881 'folder': global_type_string,
882 'username': global_type_string,
883 'password': global_type_string,
884 'ftp_wei': global_type_integer,
885 'exp_code': global_type_integer,
886 'sub_exp_code': global_type_integer,
887 'plot_pos': global_type_integer,
888 'realtime': global_type_boolean,
889 'xaxis': global_type_string,
890 }
891
892
893 SpectraWriter
894 parameters = {
895 'path': global_type_string,
896 'blocksPerFile': global_type_string,
897 'profilesPerBlock': global_type_string,
898 'set': global_type_string,
899 'ext': global_type_string,
900 'datatype': global_type_string,
901 }
902
903
904 SpectralFitting
905 parameters = {
906 'getSNR': global_type_string,
907 'path': global_type_string,
908 'file': global_type_string,
909 'groupList': global_type_string,
910 }
911
912
913 SpectralFittingPlot
914 parameters = {
915 'id': global_type_string,
916 'cutHeight': global_type_string,
917 'fit': global_type_string,
918 'wintitle': global_type_string,
919 'channelList': global_type_list,
920 'showprofile': global_type_boolean,
921 'xmin': global_type_float,
922 'xmax': global_type_float,
923 'ymin': global_type_float,
924 'ymax': global_type_float,
925 'save': global_type_boolean,
926 'figpath': global_type_string,
927 'figfile': global_type_string,
928 'show': global_type_boolean,
929 }
930
931
932 SpectralMoments
933 parameters = {
934 : global_type_string,
935 }
936
937
938 SplitProfiles
939 parameters = {
940 'n': global_type_string,
941 }
942
943
944 USRPWriter
945 parameters = {
946 'dataIn': global_type_string,
947 }
948
949
950 VoltageWriter
951 parameters = {
952 'path': global_type_string,
953 'blocksPerFile': global_type_string,
954 'profilesPerBlock': global_type_string,
955 'set': global_type_string,
956 'ext': global_type_string,
957 'datatype': global_type_string,
958 }
959
960
961 WindProfiler
962 parameters = {
963 'technique': global_type_string,
964 }
965
966
967 WindProfilerPlot
968 parameters = {
969 'id': global_type_string,
970 'wintitle': global_type_string,
971 'channelList': global_type_list,
972 'showprofile': global_type_boolean,
973 'xmin': global_type_float,
974 'xmax': global_type_float,
975 'ymin': global_type_float,
976 'ymax': global_type_float,
977 'zmin': global_type_float,
978 'zmax': global_type_float,
979 'zmax_ver': global_type_string,
980 'zmin_ver': global_type_string,
981 'SNRmin': global_type_float,
982 'SNRmax': global_type_float,
983 'timerange': global_type_float,
984 'SNRthresh': global_type_string,
985 'save': global_type_boolean,
986 'figpath': global_type_string,
987 'lastone': global_type_string,
988 'figfile': global_type_string,
989 'ftp': global_type_boolean,
990 'wr_period': global_type_integer,
991 'show': global_type_boolean,
992 'server': global_type_string,
993 'folder': global_type_string,
994 'username': global_type_string,
995 'password': global_type_string,
996 'ftp_wei': global_type_integer,
997 'exp_code': global_type_integer,
998 'sub_exp_code': global_type_integer,
999 'plot_pos': global_type_integer,
1000 }
1001
1002
1003 Writer
1004 parameters = {
1005 'dataIn': global_type_string,
1006 }
1007
1008
1009 AMISRProc
1010 parameters = {
1011 : global_type_string,
1012 }
1013
1014
1015 AMISRReader
1016 parameters = {
1017 : global_type_string,
1018 }
1019
1020
1021 CorrelationProc
1022 parameters = {
1023 'lags': global_type_string,
1024 'mode': global_type_string,
1025 'pairsList': 'pairsLists',
1026 'fullBuffer': global_type_string,
1027 'nAvg': global_type_string,
1028 'removeDC': global_type_string,
1029 'splitCF': global_type_string,
1030 }
1031
1032
1033 FitsReader
1034 parameters = {
1035 : global_type_string,
1036 }
1037
1038
1039 HFReader
1040 parameters = {
1041 : global_type_string,
1042 }
1043
1044
1045 ParamReader
1046 parameters = {
1047 : global_type_string,
1048 }
1049
1050
1051 ParametersProc
1052 parameters = {
1053 : global_type_string,
1054 }
1055
1056
1057 ProcessingUnit
1058 parameters = {
1059 : global_type_string,
1060 }
1061
1062
1063 ReceiverData
1064 parameters = {
1065 : global_type_string,
1066 }
1067
1068
1069 SendToServer
1070 parameters = {
1071 : global_type_string,
1072 }
1073
1074
1075 SpectraAFCProc
1076 parameters = {
1077 'nProfiles': global_type_string,
1078 'nFFTPoints': global_type_string,
1079 'pairsList': 'pairsLists',
1080 'code': global_type_string,
1081 'nCode': global_type_string,
1082 'nBaud': global_type_string,
1083 }
1084
1085
1086 SpectraHeisProc
1087 parameters = {
1088 : global_type_string,
1089 }
1090
1091
1092 SpectraLagsProc
1093 parameters = {
1094 'nProfiles': global_type_string,
1095 'nFFTPoints': global_type_string,
1096 'pairsList': 'pairsLists',
1097 'code': global_type_string,
1098 'nCode': global_type_string,
1099 'nBaud': global_type_string,
1100 'codeFromHeader': global_type_string,
1101 'pulseIndex': global_type_string,
1102 }
1103
1104
1105 SpectraProc
1106 parameters = {
1107 'nProfiles': global_type_string,
1108 'nFFTPoints': global_type_string,
1109 'pairsList': 'pairsLists',
1110 'ippFactor': global_type_string,
1111 }
1112
1113
1114 SpectraReader
1115 parameters = {
1116 'path': global_type_string,
1117 'startDate': global_type_string,
1118 'endDate': global_type_string,
1119 'startTime': global_type_string,
1120 'endTime': global_type_string,
1121 'set': global_type_string,
1122 'expLabel': global_type_string,
1123 'ext': global_type_string,
1124 'online': global_type_string,
1125 'delay': global_type_string,
1126 'walk': global_type_string,
1127 'getblock': global_type_string,
1128 'nTxs': global_type_string,
1129 'realtime': global_type_boolean,
1130 'blocksize': global_type_string,
1131 'blocktime': global_type_string,
1132 'queue': global_type_string,
1133 'skip': global_type_string,
1134 'cursor': global_type_string,
1135 'warnings': global_type_string,
1136 'verbose': global_type_string,
1137 }
1138
1139
1140 USRPReader
1141 parameters = {
1142 : global_type_string,
1143 }
1144
1145
1146 VoltageProc
1147 parameters = {
1148 : global_type_string,
1149 }
1150
1151
1152 VoltageReader
1153 parameters = {
1154 'path': global_type_string,
1155 'startDate': global_type_string,
1156 'endDate': global_type_string,
1157 'startTime': global_type_string,
1158 'endTime': global_type_string,
1159 'set': global_type_string,
1160 'expLabel': global_type_string,
1161 'ext': global_type_string,
1162 'online': global_type_string,
1163 'delay': global_type_string,
1164 'walk': global_type_string,
1165 'getblock': global_type_string,
1166 'nTxs': global_type_string,
1167 'realtime': global_type_boolean,
1168 'blocksize': global_type_string,
1169 'blocktime': global_type_string,
1170 'queue': global_type_string,
1171 'skip': global_type_string,
1172 'cursor': global_type_string,
1173 'warnings': global_type_string,
1174 'verbose': global_type_string,
1175 }
1176
1177
@@ -0,0 +1,81
1 import schainpy
2 from schainpy.model import Operation, ProcessingUnit
3 from importlib import import_module
4 from pydoc import locate
5
6 def clean_modules(module):
7 noEndsUnder = [x for x in module if not x.endswith('__')]
8 noStartUnder = [x for x in noEndsUnder if not x.startswith('__')]
9 noFullUpper = [x for x in noStartUnder if not x.isupper()]
10 return noFullUpper
11
12 def check_module(possible, instance):
13 def check(x):
14 try:
15 instancia = locate('schainpy.model.{}'.format(x))
16 return isinstance(instancia(), instance)
17 except Exception as e:
18 return False
19 clean = clean_modules(possible)
20 return [x for x in clean if check(x)]
21
22
23 def getProcs():
24 module = dir(import_module('schainpy.model'))
25 procs = check_module(module, ProcessingUnit)
26 try:
27 procs.remove('ProcessingUnit')
28 except Exception as e:
29 pass
30 return procs
31
32 def getOperations():
33 module = dir(import_module('schainpy.model'))
34 noProcs = [x for x in module if not x.endswith('Proc')]
35 operations = check_module(noProcs, Operation)
36 try:
37 operations.remove('Operation')
38 except Exception as e:
39 pass
40 return operations
41
42 def getArgs(op):
43 module = locate('schainpy.model.{}'.format(op))
44 args = module().getAllowedArgs()
45 try:
46 args.remove('self')
47 except Exception as e:
48 pass
49 try:
50 args.remove('dataOut')
51 except Exception as e:
52 pass
53 return args
54
55 def getAll():
56 allModules = dir(import_module('schainpy.model'))
57 modules = check_module(allModules, Operation)
58 modules.extend(check_module(allModules, ProcessingUnit))
59 return modules
60
61 def formatArgs(op):
62 args = getArgs(op)
63
64 argsAsKey = ["\t'{}'".format(x) for x in args]
65 argsFormatted = ": 'string',\n".join(argsAsKey)
66
67 print op
68 print "parameters = { \n" + argsFormatted + ": 'string',\n }"
69 print '\n'
70
71
72 if __name__ == "__main__":
73 getAll()
74 [formatArgs(x) for x in getAll()]
75
76 '''
77 parameters = {
78 'id': ,
79 'wintitle': ,
80 }
81 ''' No newline at end of file
@@ -0,0 +1,1
1 You should install "digital_rf_hdf5" module if you want to read USRP data
@@ -1,188 +1,167
1 import click
1 import click
2 import schainpy
2 import schainpy
3 import subprocess
3 import subprocess
4 import os
4 import os
5 import sys
5 import sys
6 import glob
6 import glob
7 save_stdout = sys.stdout
7 save_stdout = sys.stdout
8 sys.stdout = open('trash', 'w')
8 sys.stdout = open('trash', 'w')
9 from multiprocessing import cpu_count
9 from multiprocessing import cpu_count
10 from schaincli import templates
10 from schaincli import templates
11 from schainpy import controller_api
11 from schainpy import controller_api
12 from schainpy.model import Operation, ProcessingUnit
12 from schainpy.model import Operation, ProcessingUnit
13 from schainpy.utils import log
13 from schainpy.utils import log
14 from importlib import import_module
14 from importlib import import_module
15 from pydoc import locate
15 from pydoc import locate
16 from fuzzywuzzy import process
16 from fuzzywuzzy import process
17 from schainpy.utils import paramsFinder
17 sys.stdout = save_stdout
18 sys.stdout = save_stdout
18
19
19
20
20 def print_version(ctx, param, value):
21 def print_version(ctx, param, value):
21 if not value or ctx.resilient_parsing:
22 if not value or ctx.resilient_parsing:
22 return
23 return
23 click.echo(schainpy.__version__)
24 click.echo(schainpy.__version__)
24 ctx.exit()
25 ctx.exit()
25
26
26
27
27 cliLogger = log.makelogger('schain cli')
28 cliLogger = log.makelogger('schain cli')
28 PREFIX = 'experiment'
29 PREFIX = 'experiment'
29
30
30
31
31 @click.command()
32 @click.command()
32 @click.option('--version', '-v', is_flag=True, callback=print_version, help='SChain version', type=str)
33 @click.option('--version', '-v', is_flag=True, callback=print_version, help='SChain version', type=str)
33 @click.option('--xml', '-x', default=None, help='run an XML file', type=click.Path(exists=True, resolve_path=True))
34 @click.option('--xml', '-x', default=None, help='run an XML file', type=click.Path(exists=True, resolve_path=True))
34 @click.argument('command', default='run', required=True)
35 @click.argument('command', default='run', required=True)
35 @click.argument('nextcommand', default=None, required=False, type=str)
36 @click.argument('nextcommand', default=None, required=False, type=str)
36 def main(command, nextcommand, version, xml):
37 def main(command, nextcommand, version, xml):
37 """COMMAND LINE INTERFACE FOR SIGNAL CHAIN - JICAMARCA RADIO OBSERVATORY \n
38 """COMMAND LINE INTERFACE FOR SIGNAL CHAIN - JICAMARCA RADIO OBSERVATORY \n
38 Available commands.\n
39 Available commands.\n
39 --xml: runs a schain XML generated file\n
40 --xml: runs a schain XML generated file\n
40 run: runs any python script starting 'experiment_'\n
41 run: runs any python script starting 'experiment_'\n
41 generate: generates a template schain script\n
42 generate: generates a template schain script\n
42 search: return avilable operations, procs or arguments of the give operation/proc\n"""
43 search: return avilable operations, procs or arguments of the give operation/proc\n"""
43 if xml is not None:
44 if xml is not None:
44 runFromXML(xml)
45 runFromXML(xml)
45 elif command == 'generate':
46 elif command == 'generate':
46 generate()
47 generate()
47 elif command == 'test':
48 elif command == 'test':
48 test()
49 test()
49 elif command == 'run':
50 elif command == 'run':
50 runschain(nextcommand)
51 runschain(nextcommand)
51 elif command == 'search':
52 elif command == 'search':
52 search(nextcommand)
53 search(nextcommand)
53 else:
54 else:
54 log.error('Command {} is not defined'.format(command))
55 log.error('Command {} is not defined'.format(command))
55
56
56 def check_module(possible, instance):
57 def check_module(possible, instance):
57 def check(x):
58 def check(x):
58 try:
59 try:
59 instancia = locate('schainpy.model.{}'.format(x))
60 instancia = locate('schainpy.model.{}'.format(x))
60 return isinstance(instancia(), instance)
61 return isinstance(instancia(), instance)
61 except Exception as e:
62 except Exception as e:
62 return False
63 return False
63 clean = clean_modules(possible)
64 clean = clean_modules(possible)
64 return [x for x in clean if check(x)]
65 return [x for x in clean if check(x)]
65
66
66
67
67 def clean_modules(module):
68 def clean_modules(module):
68 noEndsUnder = [x for x in module if not x.endswith('__')]
69 noEndsUnder = [x for x in module if not x.endswith('__')]
69 noStartUnder = [x for x in noEndsUnder if not x.startswith('__')]
70 noStartUnder = [x for x in noEndsUnder if not x.startswith('__')]
70 noFullUpper = [x for x in noStartUnder if not x.isupper()]
71 noFullUpper = [x for x in noStartUnder if not x.isupper()]
71 return noFullUpper
72 return noFullUpper
72
73
73
74
74 def search(nextcommand):
75 def search(nextcommand):
75 if nextcommand is None:
76 if nextcommand is None:
76 log.error('There is no Operation/ProcessingUnit to search')
77 log.error('There is no Operation/ProcessingUnit to search')
77 elif nextcommand == 'procs':
78 elif nextcommand == 'procs':
78 module = dir(import_module('schainpy.model'))
79 procs = paramsFinder.getProcs()
79 procs = check_module(module, ProcessingUnit)
80 try:
81 procs.remove('ProcessingUnit')
82 except Exception as e:
83 pass
84 log.success('Current ProcessingUnits are:\n\033[1m{}\033[0m'.format('\n'.join(procs)))
80 log.success('Current ProcessingUnits are:\n\033[1m{}\033[0m'.format('\n'.join(procs)))
85
81
86 elif nextcommand == 'operations':
82 elif nextcommand == 'operations':
87 module = dir(import_module('schainpy.model'))
83 operations = paramsFinder.getOperations()
88 noProcs = [x for x in module if not x.endswith('Proc')]
89 operations = check_module(noProcs, Operation)
90 try:
91 operations.remove('Operation')
92 except Exception as e:
93 pass
94 log.success('Current Operations are:\n\033[1m{}\033[0m'.format('\n'.join(operations)))
84 log.success('Current Operations are:\n\033[1m{}\033[0m'.format('\n'.join(operations)))
95 else:
85 else:
96 try:
86 try:
97 module = locate('schainpy.model.{}'.format(nextcommand))
87 args = paramsFinder.getArgs(nextcommand)
98 args = module().getAllowedArgs()
99 log.warning('Use this feature with caution. It may not return all the allowed arguments')
88 log.warning('Use this feature with caution. It may not return all the allowed arguments')
100 try:
101 args.remove('self')
102 except Exception as e:
103 pass
104 try:
105 args.remove('dataOut')
106 except Exception as e:
107 pass
108 if len(args) == 0:
89 if len(args) == 0:
109 log.success('{} has no arguments'.format(nextcommand))
90 log.success('{} has no arguments'.format(nextcommand))
110 else:
91 else:
111 log.success('Showing arguments of {} are:\n\033[1m{}\033[0m'.format(nextcommand, '\n'.join(args)))
92 log.success('Showing arguments of {} are:\n\033[1m{}\033[0m'.format(nextcommand, '\n'.join(args)))
112 except Exception as e:
93 except Exception as e:
113 log.error('Module {} does not exists'.format(nextcommand))
94 log.error('Module {} does not exists'.format(nextcommand))
114 allModules = dir(import_module('schainpy.model'))
95 allModules = paramsFinder.getAll()
115 module = check_module(allModules, Operation)
96 similar = process.extractOne(nextcommand, allModules)[0]
116 module.extend(check_module(allModules, ProcessingUnit))
97 log.success('Showing {} instead'.format(similar))
117 similar = process.extractOne(nextcommand, module)[0]
118 log.success('Searching {} instead'.format(similar))
119 search(similar)
98 search(similar)
120
99
121
100
122 def runschain(nextcommand):
101 def runschain(nextcommand):
123 if nextcommand is None:
102 if nextcommand is None:
124 currentfiles = glob.glob('./{}_*.py'.format(PREFIX))
103 currentfiles = glob.glob('./{}_*.py'.format(PREFIX))
125 numberfiles = len(currentfiles)
104 numberfiles = len(currentfiles)
126 if numberfiles > 1:
105 if numberfiles > 1:
127 log.error('There is more than one file to run')
106 log.error('There is more than one file to run')
128 elif numberfiles == 1:
107 elif numberfiles == 1:
129 subprocess.call(['python ' + currentfiles[0]], shell=True)
108 subprocess.call(['python ' + currentfiles[0]], shell=True)
130 else:
109 else:
131 log.error('There is no file to run')
110 log.error('There is no file to run')
132 else:
111 else:
133 try:
112 try:
134 subprocess.call(['python ' + nextcommand], shell=True)
113 subprocess.call(['python ' + nextcommand], shell=True)
135 except Exception as e:
114 except Exception as e:
136 log.error("I cannot run the file. Does it exists?")
115 log.error("I cannot run the file. Does it exists?")
137
116
138
117
139 def basicInputs():
118 def basicInputs():
140 inputs = {}
119 inputs = {}
141 inputs['desc'] = click.prompt('Enter a description', default="A schain project", type=str)
120 inputs['desc'] = click.prompt('Enter a description', default="A schain project", type=str)
142 inputs['name'] = click.prompt('Name of the project', default="project", type=str)
121 inputs['name'] = click.prompt('Name of the project', default="project", type=str)
143 inputs['path'] = click.prompt('Data path', default=os.getcwd(), type=click.Path(exists=True, resolve_path=True))
122 inputs['path'] = click.prompt('Data path', default=os.getcwd(), type=click.Path(exists=True, resolve_path=True))
144 inputs['startDate'] = click.prompt('Start date', default='1970/01/01', type=str)
123 inputs['startDate'] = click.prompt('Start date', default='1970/01/01', type=str)
145 inputs['endDate'] = click.prompt('End date', default='2017/12/31', type=str)
124 inputs['endDate'] = click.prompt('End date', default='2017/12/31', type=str)
146 inputs['startHour'] = click.prompt('Start hour', default='00:00:00', type=str)
125 inputs['startHour'] = click.prompt('Start hour', default='00:00:00', type=str)
147 inputs['endHour'] = click.prompt('End hour', default='23:59:59', type=str)
126 inputs['endHour'] = click.prompt('End hour', default='23:59:59', type=str)
148 inputs['figpath'] = inputs['path'] + '/figs'
127 inputs['figpath'] = inputs['path'] + '/figs'
149 return inputs
128 return inputs
150
129
151
130
152 def generate():
131 def generate():
153 inputs = basicInputs()
132 inputs = basicInputs()
154 inputs['multiprocess'] = click.confirm('Is this a multiprocess script?')
133 inputs['multiprocess'] = click.confirm('Is this a multiprocess script?')
155 if inputs['multiprocess']:
134 if inputs['multiprocess']:
156 inputs['nProcess'] = click.prompt('How many process?', default=cpu_count(), type=int)
135 inputs['nProcess'] = click.prompt('How many process?', default=cpu_count(), type=int)
157 current = templates.multiprocess.format(**inputs)
136 current = templates.multiprocess.format(**inputs)
158 else:
137 else:
159 current = templates.basic.format(**inputs)
138 current = templates.basic.format(**inputs)
160 scriptname = '{}_{}.py'.format(PREFIX, inputs['name'])
139 scriptname = '{}_{}.py'.format(PREFIX, inputs['name'])
161 script = open(scriptname, 'w')
140 script = open(scriptname, 'w')
162 try:
141 try:
163 script.write(current)
142 script.write(current)
164 log.success('Script {} generated'.format(scriptname))
143 log.success('Script {} generated'.format(scriptname))
165 except Exception as e:
144 except Exception as e:
166 log.error('I cannot create the file. Do you have writing permissions?')
145 log.error('I cannot create the file. Do you have writing permissions?')
167
146
168
147
169 def test():
148 def test():
170 log.warning('testing')
149 log.warning('testing')
171
150
172
151
173 def runFromXML(filename):
152 def runFromXML(filename):
174 controller = controller_api.ControllerThread()
153 controller = controller_api.ControllerThread()
175 if not controller.readXml(filename):
154 if not controller.readXml(filename):
176 return
155 return
177
156
178 plotterObj = controller.useExternalPlotter()
157 plotterObj = controller.useExternalPlotter()
179
158
180 controller.start()
159 controller.start()
181 plotterObj.start()
160 plotterObj.start()
182
161
183 cliLogger("Finishing all processes")
162 cliLogger("Finishing all processes")
184
163
185 controller.join(5)
164 controller.join(5)
186
165
187 cliLogger("End of script")
166 cliLogger("End of script")
188 return
167 return
@@ -1,12 +1,22
1 #from schainpy.model.data.jrodata import *
1 #from schainpy.model.data.jrodata import *
2 # from schainpy.model.io.jrodataIO import *
2 # from schainpy.model.io.jrodataIO import *
3 # from schainpy.model.proc.jroprocessing import *
3 # from schainpy.model.proc.jroprocessing import *
4 # from schainpy.model.graphics.jroplot import *
4 # from schainpy.model.graphics.jroplot import *
5 # from schainpy.model.utils.jroutils import *
5 # from schainpy.model.utils.jroutils import *
6 # from schainpy.serializer import *
6 # from schainpy.serializer import *
7
7
8 from data import *
8 from data import *
9 from io import *
9 from io import *
10 from proc import *
10 from proc import *
11 from graphics import *
11 from graphics import *
12 from utils import *
12 from utils import *
13
14 global_type_string = 'string'
15 global_type_integer = 'int'
16 global_type_floatList = 'floatList'
17 global_type_pairsList = 'pairsList'
18 global_type_boolean = 'bolean'
19 global_type_float = 'float'
20 global_type_colormap = 'colormap'
21 global_type_list = 'list'
22 global_type_float = 'float'
@@ -1,657 +1,657
1 import os
1 import os
2 import numpy
2 import numpy
3 import time, datetime
3 import time, datetime
4 import mpldriver
4 import mpldriver
5
5
6 from schainpy.model.proc.jroproc_base import Operation
6 from schainpy.model.proc.jroproc_base import Operation
7
7
8 def isTimeInHourRange(datatime, xmin, xmax):
8 def isTimeInHourRange(datatime, xmin, xmax):
9
9
10 if xmin == None or xmax == None:
10 if xmin == None or xmax == None:
11 return 1
11 return 1
12 hour = datatime.hour + datatime.minute/60.0
12 hour = datatime.hour + datatime.minute/60.0
13
13
14 if xmin < (xmax % 24):
14 if xmin < (xmax % 24):
15
15
16 if hour >= xmin and hour <= xmax:
16 if hour >= xmin and hour <= xmax:
17 return 1
17 return 1
18 else:
18 else:
19 return 0
19 return 0
20
20
21 else:
21 else:
22
22
23 if hour >= xmin or hour <= (xmax % 24):
23 if hour >= xmin or hour <= (xmax % 24):
24 return 1
24 return 1
25 else:
25 else:
26 return 0
26 return 0
27
27
28 return 0
28 return 0
29
29
30 def isRealtime(utcdatatime):
30 def isRealtime(utcdatatime):
31
31
32 utcnow = time.mktime(time.localtime())
32 utcnow = time.mktime(time.localtime())
33 delta = abs(utcnow - utcdatatime) # abs
33 delta = abs(utcnow - utcdatatime) # abs
34 if delta >= 30.:
34 if delta >= 30.:
35 return False
35 return False
36 return True
36 return True
37
37
38 class Figure(Operation):
38 class Figure(Operation):
39
39
40 __driver = mpldriver
40 __driver = mpldriver
41 fig = None
41 fig = None
42
42
43 id = None
43 id = None
44 wintitle = None
44 wintitle = None
45 width = None
45 width = None
46 height = None
46 height = None
47 nplots = None
47 nplots = None
48 timerange = None
48 timerange = None
49
49
50 axesObjList = []
50 axesObjList = []
51
51
52 WIDTH = 300
52 WIDTH = 300
53 HEIGHT = 200
53 HEIGHT = 200
54 PREFIX = 'fig'
54 PREFIX = 'fig'
55
55
56 xmin = None
56 xmin = None
57 xmax = None
57 xmax = None
58
58
59 counter_imagwr = 0
59 counter_imagwr = 0
60
60
61 figfile = None
61 figfile = None
62
62
63 created = False
63 created = False
64
64 parameters = {}
65 def __init__(self, **kwargs):
65 def __init__(self, **kwargs):
66
66
67 Operation.__init__(self, **kwargs)
67 Operation.__init__(self, **kwargs)
68
68
69 def __del__(self):
69 def __del__(self):
70
70
71 self.__driver.closeFigure()
71 self.__driver.closeFigure()
72
72
73 def getFilename(self, name, ext='.png'):
73 def getFilename(self, name, ext='.png'):
74
74
75 path = '%s%03d' %(self.PREFIX, self.id)
75 path = '%s%03d' %(self.PREFIX, self.id)
76 filename = '%s_%s%s' %(self.PREFIX, name, ext)
76 filename = '%s_%s%s' %(self.PREFIX, name, ext)
77 return os.path.join(path, filename)
77 return os.path.join(path, filename)
78
78
79 def getAxesObjList(self):
79 def getAxesObjList(self):
80
80
81 return self.axesObjList
81 return self.axesObjList
82
82
83 def getSubplots(self):
83 def getSubplots(self):
84
84
85 raise NotImplementedError
85 raise NotImplementedError
86
86
87 def getScreenDim(self, widthplot, heightplot):
87 def getScreenDim(self, widthplot, heightplot):
88
88
89 nrow, ncol = self.getSubplots()
89 nrow, ncol = self.getSubplots()
90
90
91 widthscreen = widthplot*ncol
91 widthscreen = widthplot*ncol
92 heightscreen = heightplot*nrow
92 heightscreen = heightplot*nrow
93
93
94 return widthscreen, heightscreen
94 return widthscreen, heightscreen
95
95
96 def getTimeLim(self, x, xmin=None, xmax=None, timerange=None):
96 def getTimeLim(self, x, xmin=None, xmax=None, timerange=None):
97
97
98 # if self.xmin != None and self.xmax != None:
98 # if self.xmin != None and self.xmax != None:
99 # if timerange == None:
99 # if timerange == None:
100 # timerange = self.xmax - self.xmin
100 # timerange = self.xmax - self.xmin
101 # xmin = self.xmin + timerange
101 # xmin = self.xmin + timerange
102 # xmax = self.xmax + timerange
102 # xmax = self.xmax + timerange
103 #
103 #
104 # return xmin, xmax
104 # return xmin, xmax
105
105
106 if timerange == None and (xmin==None or xmax==None):
106 if timerange == None and (xmin==None or xmax==None):
107 timerange = 14400 #seconds
107 timerange = 14400 #seconds
108
108
109 if timerange != None:
109 if timerange != None:
110 txmin = x[0] #- x[0] % min(timerange/10, 10*60)
110 txmin = x[0] #- x[0] % min(timerange/10, 10*60)
111 else:
111 else:
112 txmin = x[0] #- x[0] % 10*60
112 txmin = x[0] #- x[0] % 10*60
113
113
114 thisdatetime = datetime.datetime.utcfromtimestamp(txmin)
114 thisdatetime = datetime.datetime.utcfromtimestamp(txmin)
115 thisdate = datetime.datetime.combine(thisdatetime.date(), datetime.time(0,0,0))
115 thisdate = datetime.datetime.combine(thisdatetime.date(), datetime.time(0,0,0))
116
116
117 if timerange != None:
117 if timerange != None:
118 xmin = (thisdatetime - thisdate).seconds/(60*60.)
118 xmin = (thisdatetime - thisdate).seconds/(60*60.)
119 xmax = xmin + timerange/(60*60.)
119 xmax = xmin + timerange/(60*60.)
120
120
121 d1970 = datetime.datetime(1970,1,1)
121 d1970 = datetime.datetime(1970,1,1)
122
122
123 mindt = thisdate + datetime.timedelta(hours=xmin) #- datetime.timedelta(seconds=time.timezone)
123 mindt = thisdate + datetime.timedelta(hours=xmin) #- datetime.timedelta(seconds=time.timezone)
124 xmin_sec = (mindt - d1970).total_seconds() #time.mktime(mindt.timetuple()) - time.timezone
124 xmin_sec = (mindt - d1970).total_seconds() #time.mktime(mindt.timetuple()) - time.timezone
125
125
126 maxdt = thisdate + datetime.timedelta(hours=xmax) #- datetime.timedelta(seconds=time.timezone)
126 maxdt = thisdate + datetime.timedelta(hours=xmax) #- datetime.timedelta(seconds=time.timezone)
127 xmax_sec = (maxdt - d1970).total_seconds() #time.mktime(maxdt.timetuple()) - time.timezone
127 xmax_sec = (maxdt - d1970).total_seconds() #time.mktime(maxdt.timetuple()) - time.timezone
128
128
129 return xmin_sec, xmax_sec
129 return xmin_sec, xmax_sec
130
130
131 def init(self, id, nplots, wintitle):
131 def init(self, id, nplots, wintitle):
132
132
133 raise NotImplementedError, "This method has been replaced by createFigure"
133 raise NotImplementedError, "This method has been replaced by createFigure"
134
134
135 def createFigure(self, id, wintitle, widthplot=None, heightplot=None, show=True):
135 def createFigure(self, id, wintitle, widthplot=None, heightplot=None, show=True):
136
136
137 """
137 """
138 Crea la figura de acuerdo al driver y parametros seleccionados seleccionados.
138 Crea la figura de acuerdo al driver y parametros seleccionados seleccionados.
139 Las dimensiones de la pantalla es calculada a partir de los atributos self.WIDTH
139 Las dimensiones de la pantalla es calculada a partir de los atributos self.WIDTH
140 y self.HEIGHT y el numero de subplots (nrow, ncol)
140 y self.HEIGHT y el numero de subplots (nrow, ncol)
141
141
142 Input:
142 Input:
143 id : Los parametros necesarios son
143 id : Los parametros necesarios son
144 wintitle :
144 wintitle :
145
145
146 """
146 """
147
147
148 if widthplot == None:
148 if widthplot == None:
149 widthplot = self.WIDTH
149 widthplot = self.WIDTH
150
150
151 if heightplot == None:
151 if heightplot == None:
152 heightplot = self.HEIGHT
152 heightplot = self.HEIGHT
153
153
154 self.id = id
154 self.id = id
155
155
156 self.wintitle = wintitle
156 self.wintitle = wintitle
157
157
158 self.widthscreen, self.heightscreen = self.getScreenDim(widthplot, heightplot)
158 self.widthscreen, self.heightscreen = self.getScreenDim(widthplot, heightplot)
159
159
160 # if self.created:
160 # if self.created:
161 # self.__driver.closeFigure(self.fig)
161 # self.__driver.closeFigure(self.fig)
162
162
163 if not self.created:
163 if not self.created:
164 self.fig = self.__driver.createFigure(id=self.id,
164 self.fig = self.__driver.createFigure(id=self.id,
165 wintitle=self.wintitle,
165 wintitle=self.wintitle,
166 width=self.widthscreen,
166 width=self.widthscreen,
167 height=self.heightscreen,
167 height=self.heightscreen,
168 show=show)
168 show=show)
169 else:
169 else:
170 self.__driver.clearFigure(self.fig)
170 self.__driver.clearFigure(self.fig)
171
171
172 self.axesObjList = []
172 self.axesObjList = []
173 self.counter_imagwr = 0
173 self.counter_imagwr = 0
174
174
175 self.created = True
175 self.created = True
176
176
177 def setDriver(self, driver=mpldriver):
177 def setDriver(self, driver=mpldriver):
178
178
179 self.__driver = driver
179 self.__driver = driver
180
180
181 def setTitle(self, title):
181 def setTitle(self, title):
182
182
183 self.__driver.setTitle(self.fig, title)
183 self.__driver.setTitle(self.fig, title)
184
184
185 def setWinTitle(self, title):
185 def setWinTitle(self, title):
186
186
187 self.__driver.setWinTitle(self.fig, title=title)
187 self.__driver.setWinTitle(self.fig, title=title)
188
188
189 def setTextFromAxes(self, text):
189 def setTextFromAxes(self, text):
190
190
191 raise NotImplementedError, "This method has been replaced with Axes.setText"
191 raise NotImplementedError, "This method has been replaced with Axes.setText"
192
192
193 def makeAxes(self, nrow, ncol, xpos, ypos, colspan, rowspan):
193 def makeAxes(self, nrow, ncol, xpos, ypos, colspan, rowspan):
194
194
195 raise NotImplementedError, "This method has been replaced with Axes.addAxes"
195 raise NotImplementedError, "This method has been replaced with Axes.addAxes"
196
196
197 def addAxes(self, *args):
197 def addAxes(self, *args):
198 """
198 """
199
199
200 Input:
200 Input:
201 *args : Los parametros necesarios son
201 *args : Los parametros necesarios son
202 nrow, ncol, xpos, ypos, colspan, rowspan
202 nrow, ncol, xpos, ypos, colspan, rowspan
203 """
203 """
204
204
205 axesObj = Axes(self.fig, *args)
205 axesObj = Axes(self.fig, *args)
206 self.axesObjList.append(axesObj)
206 self.axesObjList.append(axesObj)
207
207
208 def saveFigure(self, figpath, figfile, *args):
208 def saveFigure(self, figpath, figfile, *args):
209
209
210 filename = os.path.join(figpath, figfile)
210 filename = os.path.join(figpath, figfile)
211
211
212 fullpath = os.path.split(filename)[0]
212 fullpath = os.path.split(filename)[0]
213
213
214 if not os.path.exists(fullpath):
214 if not os.path.exists(fullpath):
215 subpath = os.path.split(fullpath)[0]
215 subpath = os.path.split(fullpath)[0]
216
216
217 if not os.path.exists(subpath):
217 if not os.path.exists(subpath):
218 os.mkdir(subpath)
218 os.mkdir(subpath)
219
219
220 os.mkdir(fullpath)
220 os.mkdir(fullpath)
221
221
222 self.__driver.saveFigure(self.fig, filename, *args)
222 self.__driver.saveFigure(self.fig, filename, *args)
223
223
224 def save(self, figpath, figfile=None, save=True, ftp=False, wr_period=1, thisDatetime=None, update_figfile=True):
224 def save(self, figpath, figfile=None, save=True, ftp=False, wr_period=1, thisDatetime=None, update_figfile=True):
225
225
226 self.counter_imagwr += 1
226 self.counter_imagwr += 1
227 if self.counter_imagwr < wr_period:
227 if self.counter_imagwr < wr_period:
228 return
228 return
229
229
230 self.counter_imagwr = 0
230 self.counter_imagwr = 0
231
231
232 if save:
232 if save:
233
233
234 if not figfile:
234 if not figfile:
235
235
236 if not thisDatetime:
236 if not thisDatetime:
237 raise ValueError, "Saving figure: figfile or thisDatetime should be defined"
237 raise ValueError, "Saving figure: figfile or thisDatetime should be defined"
238 return
238 return
239
239
240 str_datetime = thisDatetime.strftime("%Y%m%d_%H%M%S")
240 str_datetime = thisDatetime.strftime("%Y%m%d_%H%M%S")
241 figfile = self.getFilename(name = str_datetime)
241 figfile = self.getFilename(name = str_datetime)
242
242
243 if self.figfile == None:
243 if self.figfile == None:
244 self.figfile = figfile
244 self.figfile = figfile
245
245
246 if update_figfile:
246 if update_figfile:
247 self.figfile = figfile
247 self.figfile = figfile
248
248
249 # store png plot to local folder
249 # store png plot to local folder
250 self.saveFigure(figpath, self.figfile)
250 self.saveFigure(figpath, self.figfile)
251
251
252
252
253 if not ftp:
253 if not ftp:
254 return
254 return
255
255
256 if not thisDatetime:
256 if not thisDatetime:
257 return
257 return
258
258
259 # store png plot to FTP server according to RT-Web format
259 # store png plot to FTP server according to RT-Web format
260 ftp_filename = self.getNameToFtp(thisDatetime, self.FTP_WEI, self.EXP_CODE, self.SUB_EXP_CODE, self.PLOT_CODE, self.PLOT_POS)
260 ftp_filename = self.getNameToFtp(thisDatetime, self.FTP_WEI, self.EXP_CODE, self.SUB_EXP_CODE, self.PLOT_CODE, self.PLOT_POS)
261 # ftp_filename = os.path.join(figpath, name)
261 # ftp_filename = os.path.join(figpath, name)
262 self.saveFigure(figpath, ftp_filename)
262 self.saveFigure(figpath, ftp_filename)
263
263
264 def getNameToFtp(self, thisDatetime, FTP_WEI, EXP_CODE, SUB_EXP_CODE, PLOT_CODE, PLOT_POS):
264 def getNameToFtp(self, thisDatetime, FTP_WEI, EXP_CODE, SUB_EXP_CODE, PLOT_CODE, PLOT_POS):
265 YEAR_STR = '%4.4d'%thisDatetime.timetuple().tm_year
265 YEAR_STR = '%4.4d'%thisDatetime.timetuple().tm_year
266 DOY_STR = '%3.3d'%thisDatetime.timetuple().tm_yday
266 DOY_STR = '%3.3d'%thisDatetime.timetuple().tm_yday
267 FTP_WEI = '%2.2d'%FTP_WEI
267 FTP_WEI = '%2.2d'%FTP_WEI
268 EXP_CODE = '%3.3d'%EXP_CODE
268 EXP_CODE = '%3.3d'%EXP_CODE
269 SUB_EXP_CODE = '%2.2d'%SUB_EXP_CODE
269 SUB_EXP_CODE = '%2.2d'%SUB_EXP_CODE
270 PLOT_CODE = '%2.2d'%PLOT_CODE
270 PLOT_CODE = '%2.2d'%PLOT_CODE
271 PLOT_POS = '%2.2d'%PLOT_POS
271 PLOT_POS = '%2.2d'%PLOT_POS
272 name = YEAR_STR + DOY_STR + FTP_WEI + EXP_CODE + SUB_EXP_CODE + PLOT_CODE + PLOT_POS
272 name = YEAR_STR + DOY_STR + FTP_WEI + EXP_CODE + SUB_EXP_CODE + PLOT_CODE + PLOT_POS
273 return name
273 return name
274
274
275 def draw(self):
275 def draw(self):
276
276
277 self.__driver.draw(self.fig)
277 self.__driver.draw(self.fig)
278
278
279 def run(self):
279 def run(self):
280
280
281 raise NotImplementedError
281 raise NotImplementedError
282
282
283 def close(self, show=False):
283 def close(self, show=False):
284
284
285 self.__driver.closeFigure(show=show, fig=self.fig)
285 self.__driver.closeFigure(show=show, fig=self.fig)
286
286
287 axesList = property(getAxesObjList)
287 axesList = property(getAxesObjList)
288
288
289
289
290 class Axes:
290 class Axes:
291
291
292 __driver = mpldriver
292 __driver = mpldriver
293 fig = None
293 fig = None
294 ax = None
294 ax = None
295 plot = None
295 plot = None
296 __missing = 1E30
296 __missing = 1E30
297 __firsttime = None
297 __firsttime = None
298
298
299 __showprofile = False
299 __showprofile = False
300
300
301 xmin = None
301 xmin = None
302 xmax = None
302 xmax = None
303 ymin = None
303 ymin = None
304 ymax = None
304 ymax = None
305 zmin = None
305 zmin = None
306 zmax = None
306 zmax = None
307
307
308 x_buffer = None
308 x_buffer = None
309 z_buffer = None
309 z_buffer = None
310
310
311 decimationx = None
311 decimationx = None
312 decimationy = None
312 decimationy = None
313
313
314 __MAXNUMX = 200
314 __MAXNUMX = 200
315 __MAXNUMY = 400
315 __MAXNUMY = 400
316
316
317 __MAXNUMTIME = 500
317 __MAXNUMTIME = 500
318
318
319 def __init__(self, *args):
319 def __init__(self, *args):
320
320
321 """
321 """
322
322
323 Input:
323 Input:
324 *args : Los parametros necesarios son
324 *args : Los parametros necesarios son
325 fig, nrow, ncol, xpos, ypos, colspan, rowspan
325 fig, nrow, ncol, xpos, ypos, colspan, rowspan
326 """
326 """
327
327
328 ax = self.__driver.createAxes(*args)
328 ax = self.__driver.createAxes(*args)
329 self.fig = args[0]
329 self.fig = args[0]
330 self.ax = ax
330 self.ax = ax
331 self.plot = None
331 self.plot = None
332
332
333 self.__firsttime = True
333 self.__firsttime = True
334 self.idlineList = []
334 self.idlineList = []
335
335
336 self.x_buffer = numpy.array([])
336 self.x_buffer = numpy.array([])
337 self.z_buffer = numpy.array([])
337 self.z_buffer = numpy.array([])
338
338
339 def setText(self, text):
339 def setText(self, text):
340
340
341 self.__driver.setAxesText(self.ax, text)
341 self.__driver.setAxesText(self.ax, text)
342
342
343 def setXAxisAsTime(self):
343 def setXAxisAsTime(self):
344 pass
344 pass
345
345
346 def pline(self, x, y,
346 def pline(self, x, y,
347 xmin=None, xmax=None,
347 xmin=None, xmax=None,
348 ymin=None, ymax=None,
348 ymin=None, ymax=None,
349 xlabel='', ylabel='',
349 xlabel='', ylabel='',
350 title='',
350 title='',
351 **kwargs):
351 **kwargs):
352
352
353 """
353 """
354
354
355 Input:
355 Input:
356 x :
356 x :
357 y :
357 y :
358 xmin :
358 xmin :
359 xmax :
359 xmax :
360 ymin :
360 ymin :
361 ymax :
361 ymax :
362 xlabel :
362 xlabel :
363 ylabel :
363 ylabel :
364 title :
364 title :
365 **kwargs : Los parametros aceptados son
365 **kwargs : Los parametros aceptados son
366
366
367 ticksize
367 ticksize
368 ytick_visible
368 ytick_visible
369 """
369 """
370
370
371 if self.__firsttime:
371 if self.__firsttime:
372
372
373 if xmin == None: xmin = numpy.nanmin(x)
373 if xmin == None: xmin = numpy.nanmin(x)
374 if xmax == None: xmax = numpy.nanmax(x)
374 if xmax == None: xmax = numpy.nanmax(x)
375 if ymin == None: ymin = numpy.nanmin(y)
375 if ymin == None: ymin = numpy.nanmin(y)
376 if ymax == None: ymax = numpy.nanmax(y)
376 if ymax == None: ymax = numpy.nanmax(y)
377
377
378 self.plot = self.__driver.createPline(self.ax, x, y,
378 self.plot = self.__driver.createPline(self.ax, x, y,
379 xmin, xmax,
379 xmin, xmax,
380 ymin, ymax,
380 ymin, ymax,
381 xlabel=xlabel,
381 xlabel=xlabel,
382 ylabel=ylabel,
382 ylabel=ylabel,
383 title=title,
383 title=title,
384 **kwargs)
384 **kwargs)
385
385
386 self.idlineList.append(0)
386 self.idlineList.append(0)
387 self.__firsttime = False
387 self.__firsttime = False
388 return
388 return
389
389
390 self.__driver.pline(self.plot, x, y, xlabel=xlabel,
390 self.__driver.pline(self.plot, x, y, xlabel=xlabel,
391 ylabel=ylabel,
391 ylabel=ylabel,
392 title=title)
392 title=title)
393
393
394 # self.__driver.pause()
394 # self.__driver.pause()
395
395
396 def addpline(self, x, y, idline, **kwargs):
396 def addpline(self, x, y, idline, **kwargs):
397 lines = self.ax.lines
397 lines = self.ax.lines
398
398
399 if idline in self.idlineList:
399 if idline in self.idlineList:
400 self.__driver.set_linedata(self.ax, x, y, idline)
400 self.__driver.set_linedata(self.ax, x, y, idline)
401
401
402 if idline not in(self.idlineList):
402 if idline not in(self.idlineList):
403 self.__driver.addpline(self.ax, x, y, **kwargs)
403 self.__driver.addpline(self.ax, x, y, **kwargs)
404 self.idlineList.append(idline)
404 self.idlineList.append(idline)
405
405
406 return
406 return
407
407
408 def pmultiline(self, x, y,
408 def pmultiline(self, x, y,
409 xmin=None, xmax=None,
409 xmin=None, xmax=None,
410 ymin=None, ymax=None,
410 ymin=None, ymax=None,
411 xlabel='', ylabel='',
411 xlabel='', ylabel='',
412 title='',
412 title='',
413 **kwargs):
413 **kwargs):
414
414
415 if self.__firsttime:
415 if self.__firsttime:
416
416
417 if xmin == None: xmin = numpy.nanmin(x)
417 if xmin == None: xmin = numpy.nanmin(x)
418 if xmax == None: xmax = numpy.nanmax(x)
418 if xmax == None: xmax = numpy.nanmax(x)
419 if ymin == None: ymin = numpy.nanmin(y)
419 if ymin == None: ymin = numpy.nanmin(y)
420 if ymax == None: ymax = numpy.nanmax(y)
420 if ymax == None: ymax = numpy.nanmax(y)
421
421
422 self.plot = self.__driver.createPmultiline(self.ax, x, y,
422 self.plot = self.__driver.createPmultiline(self.ax, x, y,
423 xmin, xmax,
423 xmin, xmax,
424 ymin, ymax,
424 ymin, ymax,
425 xlabel=xlabel,
425 xlabel=xlabel,
426 ylabel=ylabel,
426 ylabel=ylabel,
427 title=title,
427 title=title,
428 **kwargs)
428 **kwargs)
429 self.__firsttime = False
429 self.__firsttime = False
430 return
430 return
431
431
432 self.__driver.pmultiline(self.plot, x, y, xlabel=xlabel,
432 self.__driver.pmultiline(self.plot, x, y, xlabel=xlabel,
433 ylabel=ylabel,
433 ylabel=ylabel,
434 title=title)
434 title=title)
435
435
436 # self.__driver.pause()
436 # self.__driver.pause()
437
437
438 def pmultilineyaxis(self, x, y,
438 def pmultilineyaxis(self, x, y,
439 xmin=None, xmax=None,
439 xmin=None, xmax=None,
440 ymin=None, ymax=None,
440 ymin=None, ymax=None,
441 xlabel='', ylabel='',
441 xlabel='', ylabel='',
442 title='',
442 title='',
443 **kwargs):
443 **kwargs):
444
444
445 if self.__firsttime:
445 if self.__firsttime:
446
446
447 if xmin == None: xmin = numpy.nanmin(x)
447 if xmin == None: xmin = numpy.nanmin(x)
448 if xmax == None: xmax = numpy.nanmax(x)
448 if xmax == None: xmax = numpy.nanmax(x)
449 if ymin == None: ymin = numpy.nanmin(y)
449 if ymin == None: ymin = numpy.nanmin(y)
450 if ymax == None: ymax = numpy.nanmax(y)
450 if ymax == None: ymax = numpy.nanmax(y)
451
451
452 self.plot = self.__driver.createPmultilineYAxis(self.ax, x, y,
452 self.plot = self.__driver.createPmultilineYAxis(self.ax, x, y,
453 xmin, xmax,
453 xmin, xmax,
454 ymin, ymax,
454 ymin, ymax,
455 xlabel=xlabel,
455 xlabel=xlabel,
456 ylabel=ylabel,
456 ylabel=ylabel,
457 title=title,
457 title=title,
458 **kwargs)
458 **kwargs)
459 if self.xmin == None: self.xmin = xmin
459 if self.xmin == None: self.xmin = xmin
460 if self.xmax == None: self.xmax = xmax
460 if self.xmax == None: self.xmax = xmax
461 if self.ymin == None: self.ymin = ymin
461 if self.ymin == None: self.ymin = ymin
462 if self.ymax == None: self.ymax = ymax
462 if self.ymax == None: self.ymax = ymax
463
463
464 self.__firsttime = False
464 self.__firsttime = False
465 return
465 return
466
466
467 self.__driver.pmultilineyaxis(self.plot, x, y, xlabel=xlabel,
467 self.__driver.pmultilineyaxis(self.plot, x, y, xlabel=xlabel,
468 ylabel=ylabel,
468 ylabel=ylabel,
469 title=title)
469 title=title)
470
470
471 # self.__driver.pause()
471 # self.__driver.pause()
472
472
473 def pcolor(self, x, y, z,
473 def pcolor(self, x, y, z,
474 xmin=None, xmax=None,
474 xmin=None, xmax=None,
475 ymin=None, ymax=None,
475 ymin=None, ymax=None,
476 zmin=None, zmax=None,
476 zmin=None, zmax=None,
477 xlabel='', ylabel='',
477 xlabel='', ylabel='',
478 title='', colormap='jet',
478 title='', colormap='jet',
479 **kwargs):
479 **kwargs):
480
480
481 """
481 """
482 Input:
482 Input:
483 x :
483 x :
484 y :
484 y :
485 x :
485 x :
486 xmin :
486 xmin :
487 xmax :
487 xmax :
488 ymin :
488 ymin :
489 ymax :
489 ymax :
490 zmin :
490 zmin :
491 zmax :
491 zmax :
492 xlabel :
492 xlabel :
493 ylabel :
493 ylabel :
494 title :
494 title :
495 **kwargs : Los parametros aceptados son
495 **kwargs : Los parametros aceptados son
496 ticksize=9,
496 ticksize=9,
497 cblabel=''
497 cblabel=''
498 """
498 """
499
499
500 #Decimating data
500 #Decimating data
501 xlen = len(x)
501 xlen = len(x)
502 ylen = len(y)
502 ylen = len(y)
503
503
504 decimationx = int(xlen/self.__MAXNUMX) + 1
504 decimationx = int(xlen/self.__MAXNUMX) + 1
505 decimationy = int(ylen/self.__MAXNUMY) + 1
505 decimationy = int(ylen/self.__MAXNUMY) + 1
506
506
507
507
508 x_buffer = x#[::decimationx]
508 x_buffer = x#[::decimationx]
509 y_buffer = y#[::decimationy]
509 y_buffer = y#[::decimationy]
510 z_buffer = z#[::decimationx, ::decimationy]
510 z_buffer = z#[::decimationx, ::decimationy]
511 #===================================================
511 #===================================================
512
512
513 if self.__firsttime:
513 if self.__firsttime:
514
514
515 if xmin == None: xmin = numpy.nanmin(x)
515 if xmin == None: xmin = numpy.nanmin(x)
516 if xmax == None: xmax = numpy.nanmax(x)
516 if xmax == None: xmax = numpy.nanmax(x)
517 if ymin == None: ymin = numpy.nanmin(y)
517 if ymin == None: ymin = numpy.nanmin(y)
518 if ymax == None: ymax = numpy.nanmax(y)
518 if ymax == None: ymax = numpy.nanmax(y)
519 if zmin == None: zmin = numpy.nanmin(z)
519 if zmin == None: zmin = numpy.nanmin(z)
520 if zmax == None: zmax = numpy.nanmax(z)
520 if zmax == None: zmax = numpy.nanmax(z)
521
521
522
522
523 self.plot = self.__driver.createPcolor(self.ax, x_buffer,
523 self.plot = self.__driver.createPcolor(self.ax, x_buffer,
524 y_buffer,
524 y_buffer,
525 z_buffer,
525 z_buffer,
526 xmin, xmax,
526 xmin, xmax,
527 ymin, ymax,
527 ymin, ymax,
528 zmin, zmax,
528 zmin, zmax,
529 xlabel=xlabel,
529 xlabel=xlabel,
530 ylabel=ylabel,
530 ylabel=ylabel,
531 title=title,
531 title=title,
532 colormap=colormap,
532 colormap=colormap,
533 **kwargs)
533 **kwargs)
534
534
535 if self.xmin == None: self.xmin = xmin
535 if self.xmin == None: self.xmin = xmin
536 if self.xmax == None: self.xmax = xmax
536 if self.xmax == None: self.xmax = xmax
537 if self.ymin == None: self.ymin = ymin
537 if self.ymin == None: self.ymin = ymin
538 if self.ymax == None: self.ymax = ymax
538 if self.ymax == None: self.ymax = ymax
539 if self.zmin == None: self.zmin = zmin
539 if self.zmin == None: self.zmin = zmin
540 if self.zmax == None: self.zmax = zmax
540 if self.zmax == None: self.zmax = zmax
541
541
542 self.__firsttime = False
542 self.__firsttime = False
543 return
543 return
544
544
545 self.__driver.pcolor(self.plot,
545 self.__driver.pcolor(self.plot,
546 z_buffer,
546 z_buffer,
547 xlabel=xlabel,
547 xlabel=xlabel,
548 ylabel=ylabel,
548 ylabel=ylabel,
549 title=title)
549 title=title)
550
550
551 # self.__driver.pause()
551 # self.__driver.pause()
552
552
553 def pcolorbuffer(self, x, y, z,
553 def pcolorbuffer(self, x, y, z,
554 xmin=None, xmax=None,
554 xmin=None, xmax=None,
555 ymin=None, ymax=None,
555 ymin=None, ymax=None,
556 zmin=None, zmax=None,
556 zmin=None, zmax=None,
557 xlabel='', ylabel='',
557 xlabel='', ylabel='',
558 title='', rti = True, colormap='jet',
558 title='', rti = True, colormap='jet',
559 maxNumX = None, maxNumY = None,
559 maxNumX = None, maxNumY = None,
560 **kwargs):
560 **kwargs):
561
561
562 if maxNumX == None:
562 if maxNumX == None:
563 maxNumX = self.__MAXNUMTIME
563 maxNumX = self.__MAXNUMTIME
564
564
565 if maxNumY == None:
565 if maxNumY == None:
566 maxNumY = self.__MAXNUMY
566 maxNumY = self.__MAXNUMY
567
567
568 if self.__firsttime:
568 if self.__firsttime:
569 self.z_buffer = z
569 self.z_buffer = z
570 self.x_buffer = numpy.hstack((self.x_buffer, x))
570 self.x_buffer = numpy.hstack((self.x_buffer, x))
571
571
572 if xmin == None: xmin = numpy.nanmin(x)
572 if xmin == None: xmin = numpy.nanmin(x)
573 if xmax == None: xmax = numpy.nanmax(x)
573 if xmax == None: xmax = numpy.nanmax(x)
574 if ymin == None: ymin = numpy.nanmin(y)
574 if ymin == None: ymin = numpy.nanmin(y)
575 if ymax == None: ymax = numpy.nanmax(y)
575 if ymax == None: ymax = numpy.nanmax(y)
576 if zmin == None: zmin = numpy.nanmin(z)
576 if zmin == None: zmin = numpy.nanmin(z)
577 if zmax == None: zmax = numpy.nanmax(z)
577 if zmax == None: zmax = numpy.nanmax(z)
578
578
579 self.plot = self.__driver.createPcolor(self.ax, self.x_buffer, y, z,
579 self.plot = self.__driver.createPcolor(self.ax, self.x_buffer, y, z,
580 xmin, xmax,
580 xmin, xmax,
581 ymin, ymax,
581 ymin, ymax,
582 zmin, zmax,
582 zmin, zmax,
583 xlabel=xlabel,
583 xlabel=xlabel,
584 ylabel=ylabel,
584 ylabel=ylabel,
585 title=title,
585 title=title,
586 colormap=colormap,
586 colormap=colormap,
587 **kwargs)
587 **kwargs)
588
588
589 if self.xmin == None: self.xmin = xmin
589 if self.xmin == None: self.xmin = xmin
590 if self.xmax == None: self.xmax = xmax
590 if self.xmax == None: self.xmax = xmax
591 if self.ymin == None: self.ymin = ymin
591 if self.ymin == None: self.ymin = ymin
592 if self.ymax == None: self.ymax = ymax
592 if self.ymax == None: self.ymax = ymax
593 if self.zmin == None: self.zmin = zmin
593 if self.zmin == None: self.zmin = zmin
594 if self.zmax == None: self.zmax = zmax
594 if self.zmax == None: self.zmax = zmax
595
595
596 self.__firsttime = False
596 self.__firsttime = False
597 return
597 return
598
598
599 self.x_buffer = numpy.hstack((self.x_buffer[:-1], x[0], x[-1]))
599 self.x_buffer = numpy.hstack((self.x_buffer[:-1], x[0], x[-1]))
600 self.z_buffer = numpy.hstack((self.z_buffer, z))
600 self.z_buffer = numpy.hstack((self.z_buffer, z))
601 z_buffer = self.z_buffer.reshape(-1,len(y))
601 z_buffer = self.z_buffer.reshape(-1,len(y))
602
602
603 #Decimating data
603 #Decimating data
604 xlen = len(self.x_buffer)
604 xlen = len(self.x_buffer)
605 ylen = len(y)
605 ylen = len(y)
606
606
607 decimationx = int(xlen/maxNumX) + 1
607 decimationx = int(xlen/maxNumX) + 1
608 decimationy = int(ylen/maxNumY) + 1
608 decimationy = int(ylen/maxNumY) + 1
609
609
610 x_buffer = self.x_buffer#[::decimationx]
610 x_buffer = self.x_buffer#[::decimationx]
611 y_buffer = y#[::decimationy]
611 y_buffer = y#[::decimationy]
612 z_buffer = z_buffer#[::decimationx, ::decimationy]
612 z_buffer = z_buffer#[::decimationx, ::decimationy]
613 #===================================================
613 #===================================================
614
614
615 x_buffer, y_buffer, z_buffer = self.__fillGaps(x_buffer, y_buffer, z_buffer)
615 x_buffer, y_buffer, z_buffer = self.__fillGaps(x_buffer, y_buffer, z_buffer)
616
616
617 self.__driver.addpcolorbuffer(self.ax, x_buffer, y_buffer, z_buffer, self.zmin, self.zmax,
617 self.__driver.addpcolorbuffer(self.ax, x_buffer, y_buffer, z_buffer, self.zmin, self.zmax,
618 xlabel=xlabel,
618 xlabel=xlabel,
619 ylabel=ylabel,
619 ylabel=ylabel,
620 title=title,
620 title=title,
621 colormap=colormap)
621 colormap=colormap)
622
622
623 # self.__driver.pause()
623 # self.__driver.pause()
624
624
625 def polar(self, x, y,
625 def polar(self, x, y,
626 title='', xlabel='',ylabel='',**kwargs):
626 title='', xlabel='',ylabel='',**kwargs):
627
627
628 if self.__firsttime:
628 if self.__firsttime:
629 self.plot = self.__driver.createPolar(self.ax, x, y, title = title, xlabel = xlabel, ylabel = ylabel)
629 self.plot = self.__driver.createPolar(self.ax, x, y, title = title, xlabel = xlabel, ylabel = ylabel)
630 self.__firsttime = False
630 self.__firsttime = False
631 self.x_buffer = x
631 self.x_buffer = x
632 self.y_buffer = y
632 self.y_buffer = y
633 return
633 return
634
634
635 self.x_buffer = numpy.hstack((self.x_buffer,x))
635 self.x_buffer = numpy.hstack((self.x_buffer,x))
636 self.y_buffer = numpy.hstack((self.y_buffer,y))
636 self.y_buffer = numpy.hstack((self.y_buffer,y))
637 self.__driver.polar(self.plot, self.x_buffer, self.y_buffer, xlabel=xlabel,
637 self.__driver.polar(self.plot, self.x_buffer, self.y_buffer, xlabel=xlabel,
638 ylabel=ylabel,
638 ylabel=ylabel,
639 title=title)
639 title=title)
640
640
641 # self.__driver.pause()
641 # self.__driver.pause()
642
642
643 def __fillGaps(self, x_buffer, y_buffer, z_buffer):
643 def __fillGaps(self, x_buffer, y_buffer, z_buffer):
644
644
645 if x_buffer.shape[0] < 2:
645 if x_buffer.shape[0] < 2:
646 return x_buffer, y_buffer, z_buffer
646 return x_buffer, y_buffer, z_buffer
647
647
648 deltas = x_buffer[1:] - x_buffer[0:-1]
648 deltas = x_buffer[1:] - x_buffer[0:-1]
649 x_median = numpy.median(deltas)
649 x_median = numpy.median(deltas)
650
650
651 index = numpy.where(deltas > 5*x_median)
651 index = numpy.where(deltas > 5*x_median)
652
652
653 if len(index[0]) != 0:
653 if len(index[0]) != 0:
654 z_buffer[index[0],::] = self.__missing
654 z_buffer[index[0],::] = self.__missing
655 z_buffer = numpy.ma.masked_inside(z_buffer,0.99*self.__missing,1.01*self.__missing)
655 z_buffer = numpy.ma.masked_inside(z_buffer,0.99*self.__missing,1.01*self.__missing)
656
656
657 return x_buffer, y_buffer, z_buffer
657 return x_buffer, y_buffer, z_buffer
@@ -1,188 +1,215
1 import os
1 import os
2 import datetime
2 import datetime
3 import numpy
3 import numpy
4 import copy
4 import copy
5
5 from schainpy.model import *
6 from figure import Figure, isRealtime
6 from figure import Figure, isRealtime
7
7
8 class CorrelationPlot(Figure):
8 class CorrelationPlot(Figure):
9 parameters = {
10 'id': global_type_string,
11 'wintitle': global_type_string,
12 'channelList': global_type_list,
13 'showprofile': global_type_string,
14 'xmin': global_type_float,
15 'xmax': global_type_float,
16 'ymin': global_type_float,
17 'ymax': global_type_float,
18 'zmin': global_type_float,
19 'zmax': global_type_float,
20 'save': global_type_boolean,
21 'figpath': global_type_string,
22 'figfile': global_type_string,
23 'show': global_type_boolean,
24 'ftp': global_type_boolean,
25 'wr_period': global_type_integer,
26 'server': global_type_string,
27 'folder': global_type_string,
28 'username': global_type_string,
29 'password': global_type_string,
30 'ftp_wei': global_type_integer,
31 'exp_code': global_type_integer,
32 'sub_exp_code': global_type_integer,
33 'plot_pos': global_type_integer,
34 'realtime': global_type_boolean,
35 }
9
36
10 isConfig = None
37 isConfig = None
11 __nsubplots = None
38 __nsubplots = None
12
39
13 WIDTHPROF = None
40 WIDTHPROF = None
14 HEIGHTPROF = None
41 HEIGHTPROF = None
15 PREFIX = 'corr'
42 PREFIX = 'corr'
16
43
17 def __init__(self, **kwargs):
44 def __init__(self, **kwargs):
18 Figure.__init__(self, **kwargs)
45 Figure.__init__(self, **kwargs)
19 self.isConfig = False
46 self.isConfig = False
20 self.__nsubplots = 1
47 self.__nsubplots = 1
21
48
22 self.WIDTH = 280
49 self.WIDTH = 280
23 self.HEIGHT = 250
50 self.HEIGHT = 250
24 self.WIDTHPROF = 120
51 self.WIDTHPROF = 120
25 self.HEIGHTPROF = 0
52 self.HEIGHTPROF = 0
26 self.counter_imagwr = 0
53 self.counter_imagwr = 0
27
54
28 self.PLOT_CODE = 1
55 self.PLOT_CODE = 1
29 self.FTP_WEI = None
56 self.FTP_WEI = None
30 self.EXP_CODE = None
57 self.EXP_CODE = None
31 self.SUB_EXP_CODE = None
58 self.SUB_EXP_CODE = None
32 self.PLOT_POS = None
59 self.PLOT_POS = None
33
60
34 def getSubplots(self):
61 def getSubplots(self):
35
62
36 ncol = int(numpy.sqrt(self.nplots)+0.9)
63 ncol = int(numpy.sqrt(self.nplots)+0.9)
37 nrow = int(self.nplots*1./ncol + 0.9)
64 nrow = int(self.nplots*1./ncol + 0.9)
38
65
39 return nrow, ncol
66 return nrow, ncol
40
67
41 def setup(self, id, nplots, wintitle, showprofile=False, show=True):
68 def setup(self, id, nplots, wintitle, showprofile=False, show=True):
42
69
43 showprofile = False
70 showprofile = False
44 self.__showprofile = showprofile
71 self.__showprofile = showprofile
45 self.nplots = nplots
72 self.nplots = nplots
46
73
47 ncolspan = 1
74 ncolspan = 1
48 colspan = 1
75 colspan = 1
49 if showprofile:
76 if showprofile:
50 ncolspan = 3
77 ncolspan = 3
51 colspan = 2
78 colspan = 2
52 self.__nsubplots = 2
79 self.__nsubplots = 2
53
80
54 self.createFigure(id = id,
81 self.createFigure(id = id,
55 wintitle = wintitle,
82 wintitle = wintitle,
56 widthplot = self.WIDTH + self.WIDTHPROF,
83 widthplot = self.WIDTH + self.WIDTHPROF,
57 heightplot = self.HEIGHT + self.HEIGHTPROF,
84 heightplot = self.HEIGHT + self.HEIGHTPROF,
58 show=show)
85 show=show)
59
86
60 nrow, ncol = self.getSubplots()
87 nrow, ncol = self.getSubplots()
61
88
62 counter = 0
89 counter = 0
63 for y in range(nrow):
90 for y in range(nrow):
64 for x in range(ncol):
91 for x in range(ncol):
65
92
66 if counter >= self.nplots:
93 if counter >= self.nplots:
67 break
94 break
68
95
69 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
96 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
70
97
71 if showprofile:
98 if showprofile:
72 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1)
99 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1)
73
100
74 counter += 1
101 counter += 1
75
102
76 def run(self, dataOut, id, wintitle="", channelList=None, showprofile=False,
103 def run(self, dataOut, id, wintitle="", channelList=None, showprofile=False,
77 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
104 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
78 save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1,
105 save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1,
79 server=None, folder=None, username=None, password=None,
106 server=None, folder=None, username=None, password=None,
80 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0, realtime=False):
107 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0, realtime=False):
81
108
82 """
109 """
83
110
84 Input:
111 Input:
85 dataOut :
112 dataOut :
86 id :
113 id :
87 wintitle :
114 wintitle :
88 channelList :
115 channelList :
89 showProfile :
116 showProfile :
90 xmin : None,
117 xmin : None,
91 xmax : None,
118 xmax : None,
92 ymin : None,
119 ymin : None,
93 ymax : None,
120 ymax : None,
94 zmin : None,
121 zmin : None,
95 zmax : None
122 zmax : None
96 """
123 """
97
124
98 if dataOut.flagNoData:
125 if dataOut.flagNoData:
99 return None
126 return None
100
127
101 if realtime:
128 if realtime:
102 if not(isRealtime(utcdatatime = dataOut.utctime)):
129 if not(isRealtime(utcdatatime = dataOut.utctime)):
103 print 'Skipping this plot function'
130 print 'Skipping this plot function'
104 return
131 return
105
132
106 if channelList == None:
133 if channelList == None:
107 channelIndexList = dataOut.channelIndexList
134 channelIndexList = dataOut.channelIndexList
108 else:
135 else:
109 channelIndexList = []
136 channelIndexList = []
110 for channel in channelList:
137 for channel in channelList:
111 if channel not in dataOut.channelList:
138 if channel not in dataOut.channelList:
112 raise ValueError, "Channel %d is not in dataOut.channelList"
139 raise ValueError, "Channel %d is not in dataOut.channelList"
113 channelIndexList.append(dataOut.channelList.index(channel))
140 channelIndexList.append(dataOut.channelList.index(channel))
114
141
115 factor = dataOut.normFactor
142 factor = dataOut.normFactor
116 lenfactor = factor.shape[1]
143 lenfactor = factor.shape[1]
117 x = dataOut.getLagTRange(1)
144 x = dataOut.getLagTRange(1)
118 y = dataOut.getHeiRange()
145 y = dataOut.getHeiRange()
119
146
120 z = copy.copy(dataOut.data_corr[:,:,0,:])
147 z = copy.copy(dataOut.data_corr[:,:,0,:])
121 for i in range(dataOut.data_corr.shape[0]):
148 for i in range(dataOut.data_corr.shape[0]):
122 z[i,:,:] = z[i,:,:]/factor[i,:]
149 z[i,:,:] = z[i,:,:]/factor[i,:]
123 zdB = numpy.abs(z)
150 zdB = numpy.abs(z)
124
151
125 avg = numpy.average(z, axis=1)
152 avg = numpy.average(z, axis=1)
126 # avg = numpy.nanmean(z, axis=1)
153 # avg = numpy.nanmean(z, axis=1)
127 # noise = dataOut.noise/factor
154 # noise = dataOut.noise/factor
128
155
129 #thisDatetime = dataOut.datatime
156 #thisDatetime = dataOut.datatime
130 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0])
157 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0])
131 title = wintitle + " Correlation"
158 title = wintitle + " Correlation"
132 xlabel = "Lag T (s)"
159 xlabel = "Lag T (s)"
133 ylabel = "Range (Km)"
160 ylabel = "Range (Km)"
134
161
135 if not self.isConfig:
162 if not self.isConfig:
136
163
137 nplots = dataOut.data_corr.shape[0]
164 nplots = dataOut.data_corr.shape[0]
138
165
139 self.setup(id=id,
166 self.setup(id=id,
140 nplots=nplots,
167 nplots=nplots,
141 wintitle=wintitle,
168 wintitle=wintitle,
142 showprofile=showprofile,
169 showprofile=showprofile,
143 show=show)
170 show=show)
144
171
145 if xmin == None: xmin = numpy.nanmin(x)
172 if xmin == None: xmin = numpy.nanmin(x)
146 if xmax == None: xmax = numpy.nanmax(x)
173 if xmax == None: xmax = numpy.nanmax(x)
147 if ymin == None: ymin = numpy.nanmin(y)
174 if ymin == None: ymin = numpy.nanmin(y)
148 if ymax == None: ymax = numpy.nanmax(y)
175 if ymax == None: ymax = numpy.nanmax(y)
149 if zmin == None: zmin = 0
176 if zmin == None: zmin = 0
150 if zmax == None: zmax = 1
177 if zmax == None: zmax = 1
151
178
152 self.FTP_WEI = ftp_wei
179 self.FTP_WEI = ftp_wei
153 self.EXP_CODE = exp_code
180 self.EXP_CODE = exp_code
154 self.SUB_EXP_CODE = sub_exp_code
181 self.SUB_EXP_CODE = sub_exp_code
155 self.PLOT_POS = plot_pos
182 self.PLOT_POS = plot_pos
156
183
157 self.isConfig = True
184 self.isConfig = True
158
185
159 self.setWinTitle(title)
186 self.setWinTitle(title)
160
187
161 for i in range(self.nplots):
188 for i in range(self.nplots):
162 str_datetime = '%s %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S"))
189 str_datetime = '%s %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S"))
163 title = "Channel %d and %d: : %s" %(dataOut.pairsList[i][0],dataOut.pairsList[i][1] , str_datetime)
190 title = "Channel %d and %d: : %s" %(dataOut.pairsList[i][0],dataOut.pairsList[i][1] , str_datetime)
164 axes = self.axesList[i*self.__nsubplots]
191 axes = self.axesList[i*self.__nsubplots]
165 axes.pcolor(x, y, zdB[i,:,:],
192 axes.pcolor(x, y, zdB[i,:,:],
166 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
193 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
167 xlabel=xlabel, ylabel=ylabel, title=title,
194 xlabel=xlabel, ylabel=ylabel, title=title,
168 ticksize=9, cblabel='')
195 ticksize=9, cblabel='')
169
196
170 # if self.__showprofile:
197 # if self.__showprofile:
171 # axes = self.axesList[i*self.__nsubplots +1]
198 # axes = self.axesList[i*self.__nsubplots +1]
172 # axes.pline(avgdB[i], y,
199 # axes.pline(avgdB[i], y,
173 # xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax,
200 # xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax,
174 # xlabel='dB', ylabel='', title='',
201 # xlabel='dB', ylabel='', title='',
175 # ytick_visible=False,
202 # ytick_visible=False,
176 # grid='x')
203 # grid='x')
177 #
204 #
178 # noiseline = numpy.repeat(noisedB[i], len(y))
205 # noiseline = numpy.repeat(noisedB[i], len(y))
179 # axes.addpline(noiseline, y, idline=1, color="black", linestyle="dashed", lw=2)
206 # axes.addpline(noiseline, y, idline=1, color="black", linestyle="dashed", lw=2)
180
207
181 self.draw()
208 self.draw()
182
209
183 self.save(figpath=figpath,
210 self.save(figpath=figpath,
184 figfile=figfile,
211 figfile=figfile,
185 save=save,
212 save=save,
186 ftp=ftp,
213 ftp=ftp,
187 wr_period=wr_period,
214 wr_period=wr_period,
188 thisDatetime=thisDatetime)
215 thisDatetime=thisDatetime)
@@ -1,1945 +1,2177
1 import os
1 import os
2 import datetime
2 import datetime
3 import numpy
3 import numpy
4 import inspect
4 import inspect
5 from figure import Figure, isRealtime, isTimeInHourRange
5 from figure import Figure, isRealtime, isTimeInHourRange
6 from plotting_codes import *
6 from plotting_codes import *
7
7
8
8
9 class MomentsPlot(Figure):
9 class MomentsPlot(Figure):
10
10
11 isConfig = None
11 isConfig = None
12 __nsubplots = None
12 __nsubplots = None
13
13
14 WIDTHPROF = None
14 WIDTHPROF = None
15 HEIGHTPROF = None
15 HEIGHTPROF = None
16 PREFIX = 'prm'
16 PREFIX = 'prm'
17
17
18 parameters = {
19 'id': global_type_string,
20 'wintitle': global_type_string,
21 'channelList': global_type_list,
22 'showprofile': global_type_boolean,
23 'xmin': global_type_float,
24 'xmax': global_type_float,
25 'ymin': global_type_float,
26 'ymax': global_type_float,
27 'zmin': global_type_float,
28 'zmax': global_type_float,
29 'save': global_type_boolean,
30 'figpath': global_type_string,
31 'figfile': global_type_string,
32 'show': global_type_boolean,
33 'ftp': global_type_boolean,
34 'wr_period': global_type_integer,
35 'server': global_type_string,
36 'folder': global_type_string,
37 'username': global_type_string,
38 'password': global_type_string,
39 'ftp_wei': global_type_string,
40 'exp_code': global_type_integer,
41 'sub_exp_code': global_type_integer,
42 'plot_pos': global_type_integer,
43 'realtime': global_type_boolean,
44 }
45
18 def __init__(self, **kwargs):
46 def __init__(self, **kwargs):
19 Figure.__init__(self, **kwargs)
47 Figure.__init__(self, **kwargs)
20 self.isConfig = False
48 self.isConfig = False
21 self.__nsubplots = 1
49 self.__nsubplots = 1
22
50
23 self.WIDTH = 280
51 self.WIDTH = 280
24 self.HEIGHT = 250
52 self.HEIGHT = 250
25 self.WIDTHPROF = 120
53 self.WIDTHPROF = 120
26 self.HEIGHTPROF = 0
54 self.HEIGHTPROF = 0
27 self.counter_imagwr = 0
55 self.counter_imagwr = 0
28
56
29 self.PLOT_CODE = MOMENTS_CODE
57 self.PLOT_CODE = MOMENTS_CODE
30
58
31 self.FTP_WEI = None
59 self.FTP_WEI = None
32 self.EXP_CODE = None
60 self.EXP_CODE = None
33 self.SUB_EXP_CODE = None
61 self.SUB_EXP_CODE = None
34 self.PLOT_POS = None
62 self.PLOT_POS = None
35
63
36 def getSubplots(self):
64 def getSubplots(self):
37
65
38 ncol = int(numpy.sqrt(self.nplots)+0.9)
66 ncol = int(numpy.sqrt(self.nplots)+0.9)
39 nrow = int(self.nplots*1./ncol + 0.9)
67 nrow = int(self.nplots*1./ncol + 0.9)
40
68
41 return nrow, ncol
69 return nrow, ncol
42
70
43 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
71 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
44
72
45 self.__showprofile = showprofile
73 self.__showprofile = showprofile
46 self.nplots = nplots
74 self.nplots = nplots
47
75
48 ncolspan = 1
76 ncolspan = 1
49 colspan = 1
77 colspan = 1
50 if showprofile:
78 if showprofile:
51 ncolspan = 3
79 ncolspan = 3
52 colspan = 2
80 colspan = 2
53 self.__nsubplots = 2
81 self.__nsubplots = 2
54
82
55 self.createFigure(id = id,
83 self.createFigure(id = id,
56 wintitle = wintitle,
84 wintitle = wintitle,
57 widthplot = self.WIDTH + self.WIDTHPROF,
85 widthplot = self.WIDTH + self.WIDTHPROF,
58 heightplot = self.HEIGHT + self.HEIGHTPROF,
86 heightplot = self.HEIGHT + self.HEIGHTPROF,
59 show=show)
87 show=show)
60
88
61 nrow, ncol = self.getSubplots()
89 nrow, ncol = self.getSubplots()
62
90
63 counter = 0
91 counter = 0
64 for y in range(nrow):
92 for y in range(nrow):
65 for x in range(ncol):
93 for x in range(ncol):
66
94
67 if counter >= self.nplots:
95 if counter >= self.nplots:
68 break
96 break
69
97
70 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
98 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
71
99
72 if showprofile:
100 if showprofile:
73 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1)
101 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1)
74
102
75 counter += 1
103 counter += 1
76
104
77 def run(self, dataOut, id, wintitle="", channelList=None, showprofile=True,
105 def run(self, dataOut, id, wintitle="", channelList=None, showprofile=True,
78 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
106 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
79 save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1,
107 save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1,
80 server=None, folder=None, username=None, password=None,
108 server=None, folder=None, username=None, password=None,
81 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0, realtime=False):
109 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0, realtime=False):
82
110
83 """
111 """
84
112
85 Input:
113 Input:
86 dataOut :
114 dataOut :
87 id :
115 id :
88 wintitle :
116 wintitle :
89 channelList :
117 channelList :
90 showProfile :
118 showProfile :
91 xmin : None,
119 xmin : None,
92 xmax : None,
120 xmax : None,
93 ymin : None,
121 ymin : None,
94 ymax : None,
122 ymax : None,
95 zmin : None,
123 zmin : None,
96 zmax : None
124 zmax : None
97 """
125 """
98
126
99 if dataOut.flagNoData:
127 if dataOut.flagNoData:
100 return None
128 return None
101
129
102 if realtime:
130 if realtime:
103 if not(isRealtime(utcdatatime = dataOut.utctime)):
131 if not(isRealtime(utcdatatime = dataOut.utctime)):
104 print 'Skipping this plot function'
132 print 'Skipping this plot function'
105 return
133 return
106
134
107 if channelList == None:
135 if channelList == None:
108 channelIndexList = dataOut.channelIndexList
136 channelIndexList = dataOut.channelIndexList
109 else:
137 else:
110 channelIndexList = []
138 channelIndexList = []
111 for channel in channelList:
139 for channel in channelList:
112 if channel not in dataOut.channelList:
140 if channel not in dataOut.channelList:
113 raise ValueError, "Channel %d is not in dataOut.channelList"
141 raise ValueError, "Channel %d is not in dataOut.channelList"
114 channelIndexList.append(dataOut.channelList.index(channel))
142 channelIndexList.append(dataOut.channelList.index(channel))
115
143
116 factor = dataOut.normFactor
144 factor = dataOut.normFactor
117 x = dataOut.abscissaList
145 x = dataOut.abscissaList
118 y = dataOut.heightList
146 y = dataOut.heightList
119
147
120 z = dataOut.data_pre[channelIndexList,:,:]/factor
148 z = dataOut.data_pre[channelIndexList,:,:]/factor
121 z = numpy.where(numpy.isfinite(z), z, numpy.NAN)
149 z = numpy.where(numpy.isfinite(z), z, numpy.NAN)
122 avg = numpy.average(z, axis=1)
150 avg = numpy.average(z, axis=1)
123 noise = dataOut.noise/factor
151 noise = dataOut.noise/factor
124
152
125 zdB = 10*numpy.log10(z)
153 zdB = 10*numpy.log10(z)
126 avgdB = 10*numpy.log10(avg)
154 avgdB = 10*numpy.log10(avg)
127 noisedB = 10*numpy.log10(noise)
155 noisedB = 10*numpy.log10(noise)
128
156
129 #thisDatetime = dataOut.datatime
157 #thisDatetime = dataOut.datatime
130 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0])
158 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0])
131 title = wintitle + " Parameters"
159 title = wintitle + " Parameters"
132 xlabel = "Velocity (m/s)"
160 xlabel = "Velocity (m/s)"
133 ylabel = "Range (Km)"
161 ylabel = "Range (Km)"
134
162
135 update_figfile = False
163 update_figfile = False
136
164
137 if not self.isConfig:
165 if not self.isConfig:
138
166
139 nplots = len(channelIndexList)
167 nplots = len(channelIndexList)
140
168
141 self.setup(id=id,
169 self.setup(id=id,
142 nplots=nplots,
170 nplots=nplots,
143 wintitle=wintitle,
171 wintitle=wintitle,
144 showprofile=showprofile,
172 showprofile=showprofile,
145 show=show)
173 show=show)
146
174
147 if xmin == None: xmin = numpy.nanmin(x)
175 if xmin == None: xmin = numpy.nanmin(x)
148 if xmax == None: xmax = numpy.nanmax(x)
176 if xmax == None: xmax = numpy.nanmax(x)
149 if ymin == None: ymin = numpy.nanmin(y)
177 if ymin == None: ymin = numpy.nanmin(y)
150 if ymax == None: ymax = numpy.nanmax(y)
178 if ymax == None: ymax = numpy.nanmax(y)
151 if zmin == None: zmin = numpy.nanmin(avgdB)*0.9
179 if zmin == None: zmin = numpy.nanmin(avgdB)*0.9
152 if zmax == None: zmax = numpy.nanmax(avgdB)*0.9
180 if zmax == None: zmax = numpy.nanmax(avgdB)*0.9
153
181
154 self.FTP_WEI = ftp_wei
182 self.FTP_WEI = ftp_wei
155 self.EXP_CODE = exp_code
183 self.EXP_CODE = exp_code
156 self.SUB_EXP_CODE = sub_exp_code
184 self.SUB_EXP_CODE = sub_exp_code
157 self.PLOT_POS = plot_pos
185 self.PLOT_POS = plot_pos
158
186
159 self.isConfig = True
187 self.isConfig = True
160 update_figfile = True
188 update_figfile = True
161
189
162 self.setWinTitle(title)
190 self.setWinTitle(title)
163
191
164 for i in range(self.nplots):
192 for i in range(self.nplots):
165 str_datetime = '%s %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S"))
193 str_datetime = '%s %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S"))
166 title = "Channel %d: %4.2fdB: %s" %(dataOut.channelList[i], noisedB[i], str_datetime)
194 title = "Channel %d: %4.2fdB: %s" %(dataOut.channelList[i], noisedB[i], str_datetime)
167 axes = self.axesList[i*self.__nsubplots]
195 axes = self.axesList[i*self.__nsubplots]
168 axes.pcolor(x, y, zdB[i,:,:],
196 axes.pcolor(x, y, zdB[i,:,:],
169 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
197 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
170 xlabel=xlabel, ylabel=ylabel, title=title,
198 xlabel=xlabel, ylabel=ylabel, title=title,
171 ticksize=9, cblabel='')
199 ticksize=9, cblabel='')
172 #Mean Line
200 #Mean Line
173 mean = dataOut.data_param[i, 1, :]
201 mean = dataOut.data_param[i, 1, :]
174 axes.addpline(mean, y, idline=0, color="black", linestyle="solid", lw=1)
202 axes.addpline(mean, y, idline=0, color="black", linestyle="solid", lw=1)
175
203
176 if self.__showprofile:
204 if self.__showprofile:
177 axes = self.axesList[i*self.__nsubplots +1]
205 axes = self.axesList[i*self.__nsubplots +1]
178 axes.pline(avgdB[i], y,
206 axes.pline(avgdB[i], y,
179 xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax,
207 xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax,
180 xlabel='dB', ylabel='', title='',
208 xlabel='dB', ylabel='', title='',
181 ytick_visible=False,
209 ytick_visible=False,
182 grid='x')
210 grid='x')
183
211
184 noiseline = numpy.repeat(noisedB[i], len(y))
212 noiseline = numpy.repeat(noisedB[i], len(y))
185 axes.addpline(noiseline, y, idline=1, color="black", linestyle="dashed", lw=2)
213 axes.addpline(noiseline, y, idline=1, color="black", linestyle="dashed", lw=2)
186
214
187 self.draw()
215 self.draw()
188
216
189 self.save(figpath=figpath,
217 self.save(figpath=figpath,
190 figfile=figfile,
218 figfile=figfile,
191 save=save,
219 save=save,
192 ftp=ftp,
220 ftp=ftp,
193 wr_period=wr_period,
221 wr_period=wr_period,
194 thisDatetime=thisDatetime)
222 thisDatetime=thisDatetime)
195
223
196
224
197
225
198 class SkyMapPlot(Figure):
226 class SkyMapPlot(Figure):
199
227
200 __isConfig = None
228 __isConfig = None
201 __nsubplots = None
229 __nsubplots = None
202
230
203 WIDTHPROF = None
231 WIDTHPROF = None
204 HEIGHTPROF = None
232 HEIGHTPROF = None
205 PREFIX = 'mmap'
233 PREFIX = 'mmap'
206
234
207 def __init__(self, **kwargs):
235 def __init__(self, **kwargs):
208 Figure.__init__(self, **kwargs)
236 Figure.__init__(self, **kwargs)
209 self.isConfig = False
237 self.isConfig = False
210 self.__nsubplots = 1
238 self.__nsubplots = 1
211
239
212 # self.WIDTH = 280
240 # self.WIDTH = 280
213 # self.HEIGHT = 250
241 # self.HEIGHT = 250
214 self.WIDTH = 600
242 self.WIDTH = 600
215 self.HEIGHT = 600
243 self.HEIGHT = 600
216 self.WIDTHPROF = 120
244 self.WIDTHPROF = 120
217 self.HEIGHTPROF = 0
245 self.HEIGHTPROF = 0
218 self.counter_imagwr = 0
246 self.counter_imagwr = 0
219
247
220 self.PLOT_CODE = MSKYMAP_CODE
248 self.PLOT_CODE = MSKYMAP_CODE
221
249
222 self.FTP_WEI = None
250 self.FTP_WEI = None
223 self.EXP_CODE = None
251 self.EXP_CODE = None
224 self.SUB_EXP_CODE = None
252 self.SUB_EXP_CODE = None
225 self.PLOT_POS = None
253 self.PLOT_POS = None
226
254
227 def getSubplots(self):
255 def getSubplots(self):
228
256
229 ncol = int(numpy.sqrt(self.nplots)+0.9)
257 ncol = int(numpy.sqrt(self.nplots)+0.9)
230 nrow = int(self.nplots*1./ncol + 0.9)
258 nrow = int(self.nplots*1./ncol + 0.9)
231
259
232 return nrow, ncol
260 return nrow, ncol
233
261
234 def setup(self, id, nplots, wintitle, showprofile=False, show=True):
262 def setup(self, id, nplots, wintitle, showprofile=False, show=True):
235
263
236 self.__showprofile = showprofile
264 self.__showprofile = showprofile
237 self.nplots = nplots
265 self.nplots = nplots
238
266
239 ncolspan = 1
267 ncolspan = 1
240 colspan = 1
268 colspan = 1
241
269
242 self.createFigure(id = id,
270 self.createFigure(id = id,
243 wintitle = wintitle,
271 wintitle = wintitle,
244 widthplot = self.WIDTH, #+ self.WIDTHPROF,
272 widthplot = self.WIDTH, #+ self.WIDTHPROF,
245 heightplot = self.HEIGHT,# + self.HEIGHTPROF,
273 heightplot = self.HEIGHT,# + self.HEIGHTPROF,
246 show=show)
274 show=show)
247
275
248 nrow, ncol = 1,1
276 nrow, ncol = 1,1
249 counter = 0
277 counter = 0
250 x = 0
278 x = 0
251 y = 0
279 y = 0
252 self.addAxes(1, 1, 0, 0, 1, 1, True)
280 self.addAxes(1, 1, 0, 0, 1, 1, True)
253
281
254 def run(self, dataOut, id, wintitle="", channelList=None, showprofile=False,
282 def run(self, dataOut, id, wintitle="", channelList=None, showprofile=False,
255 tmin=0, tmax=24, timerange=None,
283 tmin=0, tmax=24, timerange=None,
256 save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1,
284 save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1,
257 server=None, folder=None, username=None, password=None,
285 server=None, folder=None, username=None, password=None,
258 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0, realtime=False):
286 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0, realtime=False):
259
287
260 """
288 """
261
289
262 Input:
290 Input:
263 dataOut :
291 dataOut :
264 id :
292 id :
265 wintitle :
293 wintitle :
266 channelList :
294 channelList :
267 showProfile :
295 showProfile :
268 xmin : None,
296 xmin : None,
269 xmax : None,
297 xmax : None,
270 ymin : None,
298 ymin : None,
271 ymax : None,
299 ymax : None,
272 zmin : None,
300 zmin : None,
273 zmax : None
301 zmax : None
274 """
302 """
275
303
276 arrayParameters = dataOut.data_param
304 arrayParameters = dataOut.data_param
277 error = arrayParameters[:,-1]
305 error = arrayParameters[:,-1]
278 indValid = numpy.where(error == 0)[0]
306 indValid = numpy.where(error == 0)[0]
279 finalMeteor = arrayParameters[indValid,:]
307 finalMeteor = arrayParameters[indValid,:]
280 finalAzimuth = finalMeteor[:,3]
308 finalAzimuth = finalMeteor[:,3]
281 finalZenith = finalMeteor[:,4]
309 finalZenith = finalMeteor[:,4]
282
310
283 x = finalAzimuth*numpy.pi/180
311 x = finalAzimuth*numpy.pi/180
284 y = finalZenith
312 y = finalZenith
285 x1 = [dataOut.ltctime, dataOut.ltctime]
313 x1 = [dataOut.ltctime, dataOut.ltctime]
286
314
287 #thisDatetime = dataOut.datatime
315 #thisDatetime = dataOut.datatime
288 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.ltctime)
316 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.ltctime)
289 title = wintitle + " Parameters"
317 title = wintitle + " Parameters"
290 xlabel = "Zonal Zenith Angle (deg) "
318 xlabel = "Zonal Zenith Angle (deg) "
291 ylabel = "Meridional Zenith Angle (deg)"
319 ylabel = "Meridional Zenith Angle (deg)"
292 update_figfile = False
320 update_figfile = False
293
321
294 if not self.isConfig:
322 if not self.isConfig:
295
323
296 nplots = 1
324 nplots = 1
297
325
298 self.setup(id=id,
326 self.setup(id=id,
299 nplots=nplots,
327 nplots=nplots,
300 wintitle=wintitle,
328 wintitle=wintitle,
301 showprofile=showprofile,
329 showprofile=showprofile,
302 show=show)
330 show=show)
303
331
304 if self.xmin is None and self.xmax is None:
332 if self.xmin is None and self.xmax is None:
305 self.xmin, self.xmax = self.getTimeLim(x1, tmin, tmax, timerange)
333 self.xmin, self.xmax = self.getTimeLim(x1, tmin, tmax, timerange)
306
334
307 if timerange != None:
335 if timerange != None:
308 self.timerange = timerange
336 self.timerange = timerange
309 else:
337 else:
310 self.timerange = self.xmax - self.xmin
338 self.timerange = self.xmax - self.xmin
311
339
312 self.FTP_WEI = ftp_wei
340 self.FTP_WEI = ftp_wei
313 self.EXP_CODE = exp_code
341 self.EXP_CODE = exp_code
314 self.SUB_EXP_CODE = sub_exp_code
342 self.SUB_EXP_CODE = sub_exp_code
315 self.PLOT_POS = plot_pos
343 self.PLOT_POS = plot_pos
316 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
344 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
317 self.firstdate = '%s %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S"))
345 self.firstdate = '%s %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S"))
318 self.isConfig = True
346 self.isConfig = True
319 update_figfile = True
347 update_figfile = True
320
348
321 self.setWinTitle(title)
349 self.setWinTitle(title)
322
350
323 i = 0
351 i = 0
324 str_datetime = '%s %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S"))
352 str_datetime = '%s %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S"))
325
353
326 axes = self.axesList[i*self.__nsubplots]
354 axes = self.axesList[i*self.__nsubplots]
327 nevents = axes.x_buffer.shape[0] + x.shape[0]
355 nevents = axes.x_buffer.shape[0] + x.shape[0]
328 title = "Meteor Detection Sky Map\n %s - %s \n Number of events: %5.0f\n" %(self.firstdate,str_datetime,nevents)
356 title = "Meteor Detection Sky Map\n %s - %s \n Number of events: %5.0f\n" %(self.firstdate,str_datetime,nevents)
329 axes.polar(x, y,
357 axes.polar(x, y,
330 title=title, xlabel=xlabel, ylabel=ylabel,
358 title=title, xlabel=xlabel, ylabel=ylabel,
331 ticksize=9, cblabel='')
359 ticksize=9, cblabel='')
332
360
333 self.draw()
361 self.draw()
334
362
335 self.save(figpath=figpath,
363 self.save(figpath=figpath,
336 figfile=figfile,
364 figfile=figfile,
337 save=save,
365 save=save,
338 ftp=ftp,
366 ftp=ftp,
339 wr_period=wr_period,
367 wr_period=wr_period,
340 thisDatetime=thisDatetime,
368 thisDatetime=thisDatetime,
341 update_figfile=update_figfile)
369 update_figfile=update_figfile)
342
370
343 if dataOut.ltctime >= self.xmax:
371 if dataOut.ltctime >= self.xmax:
344 self.isConfigmagwr = wr_period
372 self.isConfigmagwr = wr_period
345 self.isConfig = False
373 self.isConfig = False
346 update_figfile = True
374 update_figfile = True
347 axes.__firsttime = True
375 axes.__firsttime = True
348 self.xmin += self.timerange
376 self.xmin += self.timerange
349 self.xmax += self.timerange
377 self.xmax += self.timerange
350
378
351
379
352
380
353
381
354 class WindProfilerPlot(Figure):
382 class WindProfilerPlot(Figure):
355
383
356 __isConfig = None
384 __isConfig = None
357 __nsubplots = None
385 __nsubplots = None
358
386
359 WIDTHPROF = None
387 WIDTHPROF = None
360 HEIGHTPROF = None
388 HEIGHTPROF = None
361 PREFIX = 'wind'
389 PREFIX = 'wind'
362
390
363 def __init__(self, **kwargs):
391 def __init__(self, **kwargs):
364 Figure.__init__(self, **kwargs)
392 Figure.__init__(self, **kwargs)
365 self.timerange = None
393 self.timerange = None
366 self.isConfig = False
394 self.isConfig = False
367 self.__nsubplots = 1
395 self.__nsubplots = 1
368
396
369 self.WIDTH = 800
397 self.WIDTH = 800
370 self.HEIGHT = 300
398 self.HEIGHT = 300
371 self.WIDTHPROF = 120
399 self.WIDTHPROF = 120
372 self.HEIGHTPROF = 0
400 self.HEIGHTPROF = 0
373 self.counter_imagwr = 0
401 self.counter_imagwr = 0
374
402
375 self.PLOT_CODE = WIND_CODE
403 self.PLOT_CODE = WIND_CODE
376
404
377 self.FTP_WEI = None
405 self.FTP_WEI = None
378 self.EXP_CODE = None
406 self.EXP_CODE = None
379 self.SUB_EXP_CODE = None
407 self.SUB_EXP_CODE = None
380 self.PLOT_POS = None
408 self.PLOT_POS = None
381 self.tmin = None
409 self.tmin = None
382 self.tmax = None
410 self.tmax = None
383
411
384 self.xmin = None
412 self.xmin = None
385 self.xmax = None
413 self.xmax = None
386
414
387 self.figfile = None
415 self.figfile = None
388
416
389 def getSubplots(self):
417 def getSubplots(self):
390
418
391 ncol = 1
419 ncol = 1
392 nrow = self.nplots
420 nrow = self.nplots
393
421
394 return nrow, ncol
422 return nrow, ncol
395
423
396 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
424 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
397
425
398 self.__showprofile = showprofile
426 self.__showprofile = showprofile
399 self.nplots = nplots
427 self.nplots = nplots
400
428
401 ncolspan = 1
429 ncolspan = 1
402 colspan = 1
430 colspan = 1
403
431
404 self.createFigure(id = id,
432 self.createFigure(id = id,
405 wintitle = wintitle,
433 wintitle = wintitle,
406 widthplot = self.WIDTH + self.WIDTHPROF,
434 widthplot = self.WIDTH + self.WIDTHPROF,
407 heightplot = self.HEIGHT + self.HEIGHTPROF,
435 heightplot = self.HEIGHT + self.HEIGHTPROF,
408 show=show)
436 show=show)
409
437
410 nrow, ncol = self.getSubplots()
438 nrow, ncol = self.getSubplots()
411
439
412 counter = 0
440 counter = 0
413 for y in range(nrow):
441 for y in range(nrow):
414 if counter >= self.nplots:
442 if counter >= self.nplots:
415 break
443 break
416
444
417 self.addAxes(nrow, ncol*ncolspan, y, 0, colspan, 1)
445 self.addAxes(nrow, ncol*ncolspan, y, 0, colspan, 1)
418 counter += 1
446 counter += 1
419
447
420 def run(self, dataOut, id, wintitle="", channelList=None, showprofile='False',
448 def run(self, dataOut, id, wintitle="", channelList=None, showprofile='False',
421 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
449 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
422 zmax_ver = None, zmin_ver = None, SNRmin = None, SNRmax = None,
450 zmax_ver = None, zmin_ver = None, SNRmin = None, SNRmax = None,
423 timerange=None, SNRthresh = None,
451 timerange=None, SNRthresh = None,
424 save=False, figpath='./', lastone=0,figfile=None, ftp=False, wr_period=1, show=True,
452 save=False, figpath='./', lastone=0,figfile=None, ftp=False, wr_period=1, show=True,
425 server=None, folder=None, username=None, password=None,
453 server=None, folder=None, username=None, password=None,
426 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0):
454 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0):
427 """
455 """
428
456
429 Input:
457 Input:
430 dataOut :
458 dataOut :
431 id :
459 id :
432 wintitle :
460 wintitle :
433 channelList :
461 channelList :
434 showProfile :
462 showProfile :
435 xmin : None,
463 xmin : None,
436 xmax : None,
464 xmax : None,
437 ymin : None,
465 ymin : None,
438 ymax : None,
466 ymax : None,
439 zmin : None,
467 zmin : None,
440 zmax : None
468 zmax : None
441 """
469 """
442
470
443 # if timerange is not None:
471 # if timerange is not None:
444 # self.timerange = timerange
472 # self.timerange = timerange
445 #
473 #
446 # tmin = None
474 # tmin = None
447 # tmax = None
475 # tmax = None
448
476
449
477
450 x = dataOut.getTimeRange1(dataOut.outputInterval)
478 x = dataOut.getTimeRange1(dataOut.outputInterval)
451 y = dataOut.heightList
479 y = dataOut.heightList
452 z = dataOut.data_output.copy()
480 z = dataOut.data_output.copy()
453 nplots = z.shape[0] #Number of wind dimensions estimated
481 nplots = z.shape[0] #Number of wind dimensions estimated
454 nplotsw = nplots
482 nplotsw = nplots
455
483
456
484
457 #If there is a SNR function defined
485 #If there is a SNR function defined
458 if dataOut.data_SNR is not None:
486 if dataOut.data_SNR is not None:
459 nplots += 1
487 nplots += 1
460 SNR = dataOut.data_SNR
488 SNR = dataOut.data_SNR
461 SNRavg = numpy.average(SNR, axis=0)
489 SNRavg = numpy.average(SNR, axis=0)
462
490
463 SNRdB = 10*numpy.log10(SNR)
491 SNRdB = 10*numpy.log10(SNR)
464 SNRavgdB = 10*numpy.log10(SNRavg)
492 SNRavgdB = 10*numpy.log10(SNRavg)
465
493
466 if SNRthresh == None: SNRthresh = -5.0
494 if SNRthresh == None: SNRthresh = -5.0
467 ind = numpy.where(SNRavg < 10**(SNRthresh/10))[0]
495 ind = numpy.where(SNRavg < 10**(SNRthresh/10))[0]
468
496
469 for i in range(nplotsw):
497 for i in range(nplotsw):
470 z[i,ind] = numpy.nan
498 z[i,ind] = numpy.nan
471
499
472 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.ltctime)
500 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.ltctime)
473 #thisDatetime = datetime.datetime.now()
501 #thisDatetime = datetime.datetime.now()
474 title = wintitle + "Wind"
502 title = wintitle + "Wind"
475 xlabel = ""
503 xlabel = ""
476 ylabel = "Height (km)"
504 ylabel = "Height (km)"
477 update_figfile = False
505 update_figfile = False
478
506
479 if not self.isConfig:
507 if not self.isConfig:
480
508
481 self.setup(id=id,
509 self.setup(id=id,
482 nplots=nplots,
510 nplots=nplots,
483 wintitle=wintitle,
511 wintitle=wintitle,
484 showprofile=showprofile,
512 showprofile=showprofile,
485 show=show)
513 show=show)
486
514
487 if timerange is not None:
515 if timerange is not None:
488 self.timerange = timerange
516 self.timerange = timerange
489
517
490 self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange)
518 self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange)
491
519
492 if ymin == None: ymin = numpy.nanmin(y)
520 if ymin == None: ymin = numpy.nanmin(y)
493 if ymax == None: ymax = numpy.nanmax(y)
521 if ymax == None: ymax = numpy.nanmax(y)
494
522
495 if zmax == None: zmax = numpy.nanmax(abs(z[range(2),:]))
523 if zmax == None: zmax = numpy.nanmax(abs(z[range(2),:]))
496 #if numpy.isnan(zmax): zmax = 50
524 #if numpy.isnan(zmax): zmax = 50
497 if zmin == None: zmin = -zmax
525 if zmin == None: zmin = -zmax
498
526
499 if nplotsw == 3:
527 if nplotsw == 3:
500 if zmax_ver == None: zmax_ver = numpy.nanmax(abs(z[2,:]))
528 if zmax_ver == None: zmax_ver = numpy.nanmax(abs(z[2,:]))
501 if zmin_ver == None: zmin_ver = -zmax_ver
529 if zmin_ver == None: zmin_ver = -zmax_ver
502
530
503 if dataOut.data_SNR is not None:
531 if dataOut.data_SNR is not None:
504 if SNRmin == None: SNRmin = numpy.nanmin(SNRavgdB)
532 if SNRmin == None: SNRmin = numpy.nanmin(SNRavgdB)
505 if SNRmax == None: SNRmax = numpy.nanmax(SNRavgdB)
533 if SNRmax == None: SNRmax = numpy.nanmax(SNRavgdB)
506
534
507
535
508 self.FTP_WEI = ftp_wei
536 self.FTP_WEI = ftp_wei
509 self.EXP_CODE = exp_code
537 self.EXP_CODE = exp_code
510 self.SUB_EXP_CODE = sub_exp_code
538 self.SUB_EXP_CODE = sub_exp_code
511 self.PLOT_POS = plot_pos
539 self.PLOT_POS = plot_pos
512
540
513 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
541 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
514 self.isConfig = True
542 self.isConfig = True
515 self.figfile = figfile
543 self.figfile = figfile
516 update_figfile = True
544 update_figfile = True
517
545
518 self.setWinTitle(title)
546 self.setWinTitle(title)
519
547
520 if ((self.xmax - x[1]) < (x[1]-x[0])):
548 if ((self.xmax - x[1]) < (x[1]-x[0])):
521 x[1] = self.xmax
549 x[1] = self.xmax
522
550
523 strWind = ['Zonal', 'Meridional', 'Vertical']
551 strWind = ['Zonal', 'Meridional', 'Vertical']
524 strCb = ['Velocity (m/s)','Velocity (m/s)','Velocity (cm/s)']
552 strCb = ['Velocity (m/s)','Velocity (m/s)','Velocity (cm/s)']
525 zmaxVector = [zmax, zmax, zmax_ver]
553 zmaxVector = [zmax, zmax, zmax_ver]
526 zminVector = [zmin, zmin, zmin_ver]
554 zminVector = [zmin, zmin, zmin_ver]
527 windFactor = [1,1,100]
555 windFactor = [1,1,100]
528
556
529 for i in range(nplotsw):
557 for i in range(nplotsw):
530
558
531 title = "%s Wind: %s" %(strWind[i], thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
559 title = "%s Wind: %s" %(strWind[i], thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
532 axes = self.axesList[i*self.__nsubplots]
560 axes = self.axesList[i*self.__nsubplots]
533
561
534 z1 = z[i,:].reshape((1,-1))*windFactor[i]
562 z1 = z[i,:].reshape((1,-1))*windFactor[i]
535 #z1=numpy.ma.masked_where(z1==0.,z1)
563 #z1=numpy.ma.masked_where(z1==0.,z1)
536
564
537 axes.pcolorbuffer(x, y, z1,
565 axes.pcolorbuffer(x, y, z1,
538 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=zminVector[i], zmax=zmaxVector[i],
566 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=zminVector[i], zmax=zmaxVector[i],
539 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
567 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
540 ticksize=9, cblabel=strCb[i], cbsize="1%", colormap="seismic" )
568 ticksize=9, cblabel=strCb[i], cbsize="1%", colormap="seismic" )
541
569
542 if dataOut.data_SNR is not None:
570 if dataOut.data_SNR is not None:
543 i += 1
571 i += 1
544 title = "Signal Noise Ratio (SNR): %s" %(thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
572 title = "Signal Noise Ratio (SNR): %s" %(thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
545 axes = self.axesList[i*self.__nsubplots]
573 axes = self.axesList[i*self.__nsubplots]
546 SNRavgdB = SNRavgdB.reshape((1,-1))
574 SNRavgdB = SNRavgdB.reshape((1,-1))
547 axes.pcolorbuffer(x, y, SNRavgdB,
575 axes.pcolorbuffer(x, y, SNRavgdB,
548 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=SNRmin, zmax=SNRmax,
576 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=SNRmin, zmax=SNRmax,
549 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
577 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
550 ticksize=9, cblabel='', cbsize="1%", colormap="jet")
578 ticksize=9, cblabel='', cbsize="1%", colormap="jet")
551
579
552 self.draw()
580 self.draw()
553
581
554 self.save(figpath=figpath,
582 self.save(figpath=figpath,
555 figfile=figfile,
583 figfile=figfile,
556 save=save,
584 save=save,
557 ftp=ftp,
585 ftp=ftp,
558 wr_period=wr_period,
586 wr_period=wr_period,
559 thisDatetime=thisDatetime,
587 thisDatetime=thisDatetime,
560 update_figfile=update_figfile)
588 update_figfile=update_figfile)
561
589
562 if dataOut.ltctime + dataOut.outputInterval >= self.xmax:
590 if dataOut.ltctime + dataOut.outputInterval >= self.xmax:
563 self.counter_imagwr = wr_period
591 self.counter_imagwr = wr_period
564 self.isConfig = False
592 self.isConfig = False
565 update_figfile = True
593 update_figfile = True
566
594
567
595
568 class ParametersPlot(Figure):
596 class ParametersPlot(Figure):
569
597
570 __isConfig = None
598 __isConfig = None
571 __nsubplots = None
599 __nsubplots = None
572
600
573 WIDTHPROF = None
601 WIDTHPROF = None
574 HEIGHTPROF = None
602 HEIGHTPROF = None
575 PREFIX = 'param'
603 PREFIX = 'param'
576
604
577 nplots = None
605 nplots = None
578 nchan = None
606 nchan = None
579
607
608 parameters = {
609 'id': global_type_string,
610 'wintitle': global_type_string,
611 'channelList': global_type_list,
612 'paramIndex': global_type_integer,
613 'colormap': global_type_colormap,
614 'xmin': global_type_float,
615 'xmax': global_type_float,
616 'ymin': global_type_float,
617 'ymax': global_type_float,
618 'zmin': global_type_float,
619 'zmax': global_type_float,
620 'timerange': global_type_float,
621 'showSNR': global_type_boolean,
622 'SNRthresh': global_type_float,
623 'SNRmin': global_type_float,
624 'SNRmax': global_type_float,
625 'save': global_type_boolean,
626 'figpath': global_type_string,
627 'lastone': global_type_integer,
628 'figfile': global_type_string,
629 'ftp': global_type_boolean,
630 'wr_period': global_type_integer,
631 'show': global_type_boolean,
632 'server': global_type_string,
633 'folder': global_type_string,
634 'username': global_type_string,
635 'password': global_type_string,
636 'ftp_wei': global_type_integer,
637 'exp_code': global_type_integer,
638 'sub_exp_code': global_type_integer,
639 'plot_pos': global_type_integer,
640 }
641
580 def __init__(self, **kwargs):
642 def __init__(self, **kwargs):
581 Figure.__init__(self, **kwargs)
643 Figure.__init__(self, **kwargs)
582 self.timerange = None
644 self.timerange = None
583 self.isConfig = False
645 self.isConfig = False
584 self.__nsubplots = 1
646 self.__nsubplots = 1
585
647
586 self.WIDTH = 800
648 self.WIDTH = 800
587 self.HEIGHT = 180
649 self.HEIGHT = 180
588 self.WIDTHPROF = 120
650 self.WIDTHPROF = 120
589 self.HEIGHTPROF = 0
651 self.HEIGHTPROF = 0
590 self.counter_imagwr = 0
652 self.counter_imagwr = 0
591
653
592 self.PLOT_CODE = RTI_CODE
654 self.PLOT_CODE = RTI_CODE
593
655
594 self.FTP_WEI = None
656 self.FTP_WEI = None
595 self.EXP_CODE = None
657 self.EXP_CODE = None
596 self.SUB_EXP_CODE = None
658 self.SUB_EXP_CODE = None
597 self.PLOT_POS = None
659 self.PLOT_POS = None
598 self.tmin = None
660 self.tmin = None
599 self.tmax = None
661 self.tmax = None
600
662
601 self.xmin = None
663 self.xmin = None
602 self.xmax = None
664 self.xmax = None
603
665
604 self.figfile = None
666 self.figfile = None
605
667
606 def getSubplots(self):
668 def getSubplots(self):
607
669
608 ncol = 1
670 ncol = 1
609 nrow = self.nplots
671 nrow = self.nplots
610
672
611 return nrow, ncol
673 return nrow, ncol
612
674
613 def setup(self, id, nplots, wintitle, show=True):
675 def setup(self, id, nplots, wintitle, show=True):
614
676
615 self.nplots = nplots
677 self.nplots = nplots
616
678
617 ncolspan = 1
679 ncolspan = 1
618 colspan = 1
680 colspan = 1
619
681
620 self.createFigure(id = id,
682 self.createFigure(id = id,
621 wintitle = wintitle,
683 wintitle = wintitle,
622 widthplot = self.WIDTH + self.WIDTHPROF,
684 widthplot = self.WIDTH + self.WIDTHPROF,
623 heightplot = self.HEIGHT + self.HEIGHTPROF,
685 heightplot = self.HEIGHT + self.HEIGHTPROF,
624 show=show)
686 show=show)
625
687
626 nrow, ncol = self.getSubplots()
688 nrow, ncol = self.getSubplots()
627
689
628 counter = 0
690 counter = 0
629 for y in range(nrow):
691 for y in range(nrow):
630 for x in range(ncol):
692 for x in range(ncol):
631
693
632 if counter >= self.nplots:
694 if counter >= self.nplots:
633 break
695 break
634
696
635 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
697 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
636
698
637 counter += 1
699 counter += 1
638
700
639 def run(self, dataOut, id, wintitle="", channelList=None, paramIndex = 0, colormap=True,
701 def run(self, dataOut, id, wintitle="", channelList=None, paramIndex = 0, colormap=True,
640 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None, timerange=None,
702 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None, timerange=None,
641 showSNR=False, SNRthresh = -numpy.inf, SNRmin=None, SNRmax=None,
703 showSNR=False, SNRthresh = -numpy.inf, SNRmin=None, SNRmax=None,
642 save=False, figpath='./', lastone=0,figfile=None, ftp=False, wr_period=1, show=True,
704 save=False, figpath='./', lastone=0,figfile=None, ftp=False, wr_period=1, show=True,
643 server=None, folder=None, username=None, password=None,
705 server=None, folder=None, username=None, password=None,
644 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0):
706 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0):
645 """
707 """
646
708
647 Input:
709 Input:
648 dataOut :
710 dataOut :
649 id :
711 id :
650 wintitle :
712 wintitle :
651 channelList :
713 channelList :
652 showProfile :
714 showProfile :
653 xmin : None,
715 xmin : None,
654 xmax : None,
716 xmax : None,
655 ymin : None,
717 ymin : None,
656 ymax : None,
718 ymax : None,
657 zmin : None,
719 zmin : None,
658 zmax : None
720 zmax : None
659 """
721 """
660
722
661 if colormap:
723 if colormap:
662 colormap="jet"
724 colormap="jet"
663 else:
725 else:
664 colormap="RdBu_r"
726 colormap="RdBu_r"
665
727
666 if not isTimeInHourRange(dataOut.datatime, xmin, xmax):
728 if not isTimeInHourRange(dataOut.datatime, xmin, xmax):
667 return
729 return
668
730
669 if channelList == None:
731 if channelList == None:
670 channelIndexList = range(dataOut.data_param.shape[0])
732 channelIndexList = range(dataOut.data_param.shape[0])
671 else:
733 else:
672 channelIndexList = []
734 channelIndexList = []
673 for channel in channelList:
735 for channel in channelList:
674 if channel not in dataOut.channelList:
736 if channel not in dataOut.channelList:
675 raise ValueError, "Channel %d is not in dataOut.channelList"
737 raise ValueError, "Channel %d is not in dataOut.channelList"
676 channelIndexList.append(dataOut.channelList.index(channel))
738 channelIndexList.append(dataOut.channelList.index(channel))
677
739
678 x = dataOut.getTimeRange1(dataOut.paramInterval)
740 x = dataOut.getTimeRange1(dataOut.paramInterval)
679 y = dataOut.getHeiRange()
741 y = dataOut.getHeiRange()
680
742
681 if dataOut.data_param.ndim == 3:
743 if dataOut.data_param.ndim == 3:
682 z = dataOut.data_param[channelIndexList,paramIndex,:]
744 z = dataOut.data_param[channelIndexList,paramIndex,:]
683 else:
745 else:
684 z = dataOut.data_param[channelIndexList,:]
746 z = dataOut.data_param[channelIndexList,:]
685
747
686 if showSNR:
748 if showSNR:
687 #SNR data
749 #SNR data
688 SNRarray = dataOut.data_SNR[channelIndexList,:]
750 SNRarray = dataOut.data_SNR[channelIndexList,:]
689 SNRdB = 10*numpy.log10(SNRarray)
751 SNRdB = 10*numpy.log10(SNRarray)
690 ind = numpy.where(SNRdB < SNRthresh)
752 ind = numpy.where(SNRdB < SNRthresh)
691 z[ind] = numpy.nan
753 z[ind] = numpy.nan
692
754
693 thisDatetime = dataOut.datatime
755 thisDatetime = dataOut.datatime
694 # thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0])
756 # thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0])
695 title = wintitle + " Parameters Plot" #: %s" %(thisDatetime.strftime("%d-%b-%Y"))
757 title = wintitle + " Parameters Plot" #: %s" %(thisDatetime.strftime("%d-%b-%Y"))
696 xlabel = ""
758 xlabel = ""
697 ylabel = "Range (Km)"
759 ylabel = "Range (Km)"
698
760
699 update_figfile = False
761 update_figfile = False
700
762
701 if not self.isConfig:
763 if not self.isConfig:
702
764
703 nchan = len(channelIndexList)
765 nchan = len(channelIndexList)
704 self.nchan = nchan
766 self.nchan = nchan
705 self.plotFact = 1
767 self.plotFact = 1
706 nplots = nchan
768 nplots = nchan
707
769
708 if showSNR:
770 if showSNR:
709 nplots = nchan*2
771 nplots = nchan*2
710 self.plotFact = 2
772 self.plotFact = 2
711 if SNRmin == None: SNRmin = numpy.nanmin(SNRdB)
773 if SNRmin == None: SNRmin = numpy.nanmin(SNRdB)
712 if SNRmax == None: SNRmax = numpy.nanmax(SNRdB)
774 if SNRmax == None: SNRmax = numpy.nanmax(SNRdB)
713
775
714 self.setup(id=id,
776 self.setup(id=id,
715 nplots=nplots,
777 nplots=nplots,
716 wintitle=wintitle,
778 wintitle=wintitle,
717 show=show)
779 show=show)
718
780
719 if timerange != None:
781 if timerange != None:
720 self.timerange = timerange
782 self.timerange = timerange
721
783
722 self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange)
784 self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange)
723
785
724 if ymin == None: ymin = numpy.nanmin(y)
786 if ymin == None: ymin = numpy.nanmin(y)
725 if ymax == None: ymax = numpy.nanmax(y)
787 if ymax == None: ymax = numpy.nanmax(y)
726 if zmin == None: zmin = numpy.nanmin(z)
788 if zmin == None: zmin = numpy.nanmin(z)
727 if zmax == None: zmax = numpy.nanmax(z)
789 if zmax == None: zmax = numpy.nanmax(z)
728
790
729 self.FTP_WEI = ftp_wei
791 self.FTP_WEI = ftp_wei
730 self.EXP_CODE = exp_code
792 self.EXP_CODE = exp_code
731 self.SUB_EXP_CODE = sub_exp_code
793 self.SUB_EXP_CODE = sub_exp_code
732 self.PLOT_POS = plot_pos
794 self.PLOT_POS = plot_pos
733
795
734 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
796 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
735 self.isConfig = True
797 self.isConfig = True
736 self.figfile = figfile
798 self.figfile = figfile
737 update_figfile = True
799 update_figfile = True
738
800
739 self.setWinTitle(title)
801 self.setWinTitle(title)
740
802
741 for i in range(self.nchan):
803 for i in range(self.nchan):
742 index = channelIndexList[i]
804 index = channelIndexList[i]
743 title = "Channel %d: %s" %(dataOut.channelList[index], thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
805 title = "Channel %d: %s" %(dataOut.channelList[index], thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
744 axes = self.axesList[i*self.plotFact]
806 axes = self.axesList[i*self.plotFact]
745 z1 = z[i,:].reshape((1,-1))
807 z1 = z[i,:].reshape((1,-1))
746 axes.pcolorbuffer(x, y, z1,
808 axes.pcolorbuffer(x, y, z1,
747 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
809 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
748 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
810 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
749 ticksize=9, cblabel='', cbsize="1%",colormap=colormap)
811 ticksize=9, cblabel='', cbsize="1%",colormap=colormap)
750
812
751 if showSNR:
813 if showSNR:
752 title = "Channel %d SNR: %s" %(dataOut.channelList[index], thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
814 title = "Channel %d SNR: %s" %(dataOut.channelList[index], thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
753 axes = self.axesList[i*self.plotFact + 1]
815 axes = self.axesList[i*self.plotFact + 1]
754 SNRdB1 = SNRdB[i,:].reshape((1,-1))
816 SNRdB1 = SNRdB[i,:].reshape((1,-1))
755 axes.pcolorbuffer(x, y, SNRdB1,
817 axes.pcolorbuffer(x, y, SNRdB1,
756 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=SNRmin, zmax=SNRmax,
818 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=SNRmin, zmax=SNRmax,
757 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
819 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
758 ticksize=9, cblabel='', cbsize="1%",colormap='jet')
820 ticksize=9, cblabel='', cbsize="1%",colormap='jet')
759
821
760
822
761 self.draw()
823 self.draw()
762
824
763 if dataOut.ltctime >= self.xmax:
825 if dataOut.ltctime >= self.xmax:
764 self.counter_imagwr = wr_period
826 self.counter_imagwr = wr_period
765 self.isConfig = False
827 self.isConfig = False
766 update_figfile = True
828 update_figfile = True
767
829
768 self.save(figpath=figpath,
830 self.save(figpath=figpath,
769 figfile=figfile,
831 figfile=figfile,
770 save=save,
832 save=save,
771 ftp=ftp,
833 ftp=ftp,
772 wr_period=wr_period,
834 wr_period=wr_period,
773 thisDatetime=thisDatetime,
835 thisDatetime=thisDatetime,
774 update_figfile=update_figfile)
836 update_figfile=update_figfile)
775
837
776
838
777
839
778 class Parameters1Plot(Figure):
840 class Parameters1Plot(Figure):
779
841
780 __isConfig = None
842 __isConfig = None
781 __nsubplots = None
843 __nsubplots = None
782
844
783 WIDTHPROF = None
845 WIDTHPROF = None
784 HEIGHTPROF = None
846 HEIGHTPROF = None
785 PREFIX = 'prm'
847 PREFIX = 'prm'
786
848
849 parameters = {
850 'id': global_type_string,
851 'wintitle': global_type_string,
852 'channelList': global_type_list,
853 'showprofile': global_type_boolean,
854 'xmin': global_type_float,
855 'xmax': global_type_float,
856 'ymin': global_type_float,
857 'ymax': global_type_float,
858 'zmin': global_type_float,
859 'zmax': global_type_float,
860 'timerange': global_type_float,
861 'parameterIndex': global_type_float,
862 'onlyPositive': global_type_boolean,
863 'SNRthresh': global_type_float,
864 'SNR': global_type_boolean,
865 'SNRmin': global_type_float,
866 'SNRmax': global_type_float,
867 'onlySNR': global_type_boolean,
868 'DOP': global_type_boolean,
869 'zlabel': global_type_string,
870 'parameterName': global_type_string,
871 'parameterObject': global_type_string,
872 'save': global_type_boolean,
873 'figpath': global_type_string,
874 'lastone': global_type_integer,
875 'figfile': global_type_string,
876 'ftp': global_type_boolean,
877 'wr_period': global_type_integer,
878 'show': global_type_string,
879 'server': global_type_string,
880 'folder': global_type_string,
881 'username': global_type_string,
882 'password': global_type_string,
883 'ftp_wei': global_type_integer,
884 'exp_code': global_type_integer,
885 'sub_exp_code': global_type_integer,
886 'plot_pos': global_type_integer,
887 }
888
787 def __init__(self, **kwargs):
889 def __init__(self, **kwargs):
788 Figure.__init__(self, **kwargs)
890 Figure.__init__(self, **kwargs)
789 self.timerange = 2*60*60
891 self.timerange = 2*60*60
790 self.isConfig = False
892 self.isConfig = False
791 self.__nsubplots = 1
893 self.__nsubplots = 1
792
894
793 self.WIDTH = 800
895 self.WIDTH = 800
794 self.HEIGHT = 180
896 self.HEIGHT = 180
795 self.WIDTHPROF = 120
897 self.WIDTHPROF = 120
796 self.HEIGHTPROF = 0
898 self.HEIGHTPROF = 0
797 self.counter_imagwr = 0
899 self.counter_imagwr = 0
798
900
799 self.PLOT_CODE = PARMS_CODE
901 self.PLOT_CODE = PARMS_CODE
800
902
801 self.FTP_WEI = None
903 self.FTP_WEI = None
802 self.EXP_CODE = None
904 self.EXP_CODE = None
803 self.SUB_EXP_CODE = None
905 self.SUB_EXP_CODE = None
804 self.PLOT_POS = None
906 self.PLOT_POS = None
805 self.tmin = None
907 self.tmin = None
806 self.tmax = None
908 self.tmax = None
807
909
808 self.xmin = None
910 self.xmin = None
809 self.xmax = None
911 self.xmax = None
810
912
811 self.figfile = None
913 self.figfile = None
812
914
813 def getSubplots(self):
915 def getSubplots(self):
814
916
815 ncol = 1
917 ncol = 1
816 nrow = self.nplots
918 nrow = self.nplots
817
919
818 return nrow, ncol
920 return nrow, ncol
819
921
820 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
922 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
821
923
822 self.__showprofile = showprofile
924 self.__showprofile = showprofile
823 self.nplots = nplots
925 self.nplots = nplots
824
926
825 ncolspan = 1
927 ncolspan = 1
826 colspan = 1
928 colspan = 1
827
929
828 self.createFigure(id = id,
930 self.createFigure(id = id,
829 wintitle = wintitle,
931 wintitle = wintitle,
830 widthplot = self.WIDTH + self.WIDTHPROF,
932 widthplot = self.WIDTH + self.WIDTHPROF,
831 heightplot = self.HEIGHT + self.HEIGHTPROF,
933 heightplot = self.HEIGHT + self.HEIGHTPROF,
832 show=show)
934 show=show)
833
935
834 nrow, ncol = self.getSubplots()
936 nrow, ncol = self.getSubplots()
835
937
836 counter = 0
938 counter = 0
837 for y in range(nrow):
939 for y in range(nrow):
838 for x in range(ncol):
940 for x in range(ncol):
839
941
840 if counter >= self.nplots:
942 if counter >= self.nplots:
841 break
943 break
842
944
843 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
945 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
844
946
845 if showprofile:
947 if showprofile:
846 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1)
948 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1)
847
949
848 counter += 1
950 counter += 1
849
951
850 def run(self, dataOut, id, wintitle="", channelList=None, showprofile=False,
952 def run(self, dataOut, id, wintitle="", channelList=None, showprofile=False,
851 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,timerange=None,
953 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,timerange=None,
852 parameterIndex = None, onlyPositive = False,
954 parameterIndex = None, onlyPositive = False,
853 SNRthresh = -numpy.inf, SNR = True, SNRmin = None, SNRmax = None, onlySNR = False,
955 SNRthresh = -numpy.inf, SNR = True, SNRmin = None, SNRmax = None, onlySNR = False,
854 DOP = True,
956 DOP = True,
855 zlabel = "", parameterName = "", parameterObject = "data_param",
957 zlabel = "", parameterName = "", parameterObject = "data_param",
856 save=False, figpath='./', lastone=0,figfile=None, ftp=False, wr_period=1, show=True,
958 save=False, figpath='./', lastone=0,figfile=None, ftp=False, wr_period=1, show=True,
857 server=None, folder=None, username=None, password=None,
959 server=None, folder=None, username=None, password=None,
858 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0):
960 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0):
859 #print inspect.getargspec(self.run).args
961 #print inspect.getargspec(self.run).args
860 """
962 """
861
963
862 Input:
964 Input:
863 dataOut :
965 dataOut :
864 id :
966 id :
865 wintitle :
967 wintitle :
866 channelList :
968 channelList :
867 showProfile :
969 showProfile :
868 xmin : None,
970 xmin : None,
869 xmax : None,
971 xmax : None,
870 ymin : None,
972 ymin : None,
871 ymax : None,
973 ymax : None,
872 zmin : None,
974 zmin : None,
873 zmax : None
975 zmax : None
874 """
976 """
875
977
876 data_param = getattr(dataOut, parameterObject)
978 data_param = getattr(dataOut, parameterObject)
877
979
878 if channelList == None:
980 if channelList == None:
879 channelIndexList = numpy.arange(data_param.shape[0])
981 channelIndexList = numpy.arange(data_param.shape[0])
880 else:
982 else:
881 channelIndexList = numpy.array(channelList)
983 channelIndexList = numpy.array(channelList)
882
984
883 nchan = len(channelIndexList) #Number of channels being plotted
985 nchan = len(channelIndexList) #Number of channels being plotted
884
986
885 if nchan < 1:
987 if nchan < 1:
886 return
988 return
887
989
888 nGraphsByChannel = 0
990 nGraphsByChannel = 0
889
991
890 if SNR:
992 if SNR:
891 nGraphsByChannel += 1
993 nGraphsByChannel += 1
892 if DOP:
994 if DOP:
893 nGraphsByChannel += 1
995 nGraphsByChannel += 1
894
996
895 if nGraphsByChannel < 1:
997 if nGraphsByChannel < 1:
896 return
998 return
897
999
898 nplots = nGraphsByChannel*nchan
1000 nplots = nGraphsByChannel*nchan
899
1001
900 if timerange is not None:
1002 if timerange is not None:
901 self.timerange = timerange
1003 self.timerange = timerange
902
1004
903 #tmin = None
1005 #tmin = None
904 #tmax = None
1006 #tmax = None
905 if parameterIndex == None:
1007 if parameterIndex == None:
906 parameterIndex = 1
1008 parameterIndex = 1
907
1009
908 x = dataOut.getTimeRange1(dataOut.paramInterval)
1010 x = dataOut.getTimeRange1(dataOut.paramInterval)
909 y = dataOut.heightList
1011 y = dataOut.heightList
910 z = data_param[channelIndexList,parameterIndex,:].copy()
1012 z = data_param[channelIndexList,parameterIndex,:].copy()
911
1013
912 zRange = dataOut.abscissaList
1014 zRange = dataOut.abscissaList
913 # nChannels = z.shape[0] #Number of wind dimensions estimated
1015 # nChannels = z.shape[0] #Number of wind dimensions estimated
914 # thisDatetime = dataOut.datatime
1016 # thisDatetime = dataOut.datatime
915
1017
916 if dataOut.data_SNR is not None:
1018 if dataOut.data_SNR is not None:
917 SNRarray = dataOut.data_SNR[channelIndexList,:]
1019 SNRarray = dataOut.data_SNR[channelIndexList,:]
918 SNRdB = 10*numpy.log10(SNRarray)
1020 SNRdB = 10*numpy.log10(SNRarray)
919 # SNRavgdB = 10*numpy.log10(SNRavg)
1021 # SNRavgdB = 10*numpy.log10(SNRavg)
920 ind = numpy.where(SNRdB < 10**(SNRthresh/10))
1022 ind = numpy.where(SNRdB < 10**(SNRthresh/10))
921 z[ind] = numpy.nan
1023 z[ind] = numpy.nan
922
1024
923 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0])
1025 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0])
924 title = wintitle + " Parameters Plot" #: %s" %(thisDatetime.strftime("%d-%b-%Y"))
1026 title = wintitle + " Parameters Plot" #: %s" %(thisDatetime.strftime("%d-%b-%Y"))
925 xlabel = ""
1027 xlabel = ""
926 ylabel = "Range (Km)"
1028 ylabel = "Range (Km)"
927
1029
928 if (SNR and not onlySNR): nplots = 2*nplots
1030 if (SNR and not onlySNR): nplots = 2*nplots
929
1031
930 if onlyPositive:
1032 if onlyPositive:
931 colormap = "jet"
1033 colormap = "jet"
932 zmin = 0
1034 zmin = 0
933 else: colormap = "RdBu_r"
1035 else: colormap = "RdBu_r"
934
1036
935 if not self.isConfig:
1037 if not self.isConfig:
936
1038
937 self.setup(id=id,
1039 self.setup(id=id,
938 nplots=nplots,
1040 nplots=nplots,
939 wintitle=wintitle,
1041 wintitle=wintitle,
940 showprofile=showprofile,
1042 showprofile=showprofile,
941 show=show)
1043 show=show)
942
1044
943 self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange)
1045 self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange)
944
1046
945 if ymin == None: ymin = numpy.nanmin(y)
1047 if ymin == None: ymin = numpy.nanmin(y)
946 if ymax == None: ymax = numpy.nanmax(y)
1048 if ymax == None: ymax = numpy.nanmax(y)
947 if zmin == None: zmin = numpy.nanmin(zRange)
1049 if zmin == None: zmin = numpy.nanmin(zRange)
948 if zmax == None: zmax = numpy.nanmax(zRange)
1050 if zmax == None: zmax = numpy.nanmax(zRange)
949
1051
950 if SNR:
1052 if SNR:
951 if SNRmin == None: SNRmin = numpy.nanmin(SNRdB)
1053 if SNRmin == None: SNRmin = numpy.nanmin(SNRdB)
952 if SNRmax == None: SNRmax = numpy.nanmax(SNRdB)
1054 if SNRmax == None: SNRmax = numpy.nanmax(SNRdB)
953
1055
954 self.FTP_WEI = ftp_wei
1056 self.FTP_WEI = ftp_wei
955 self.EXP_CODE = exp_code
1057 self.EXP_CODE = exp_code
956 self.SUB_EXP_CODE = sub_exp_code
1058 self.SUB_EXP_CODE = sub_exp_code
957 self.PLOT_POS = plot_pos
1059 self.PLOT_POS = plot_pos
958
1060
959 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
1061 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
960 self.isConfig = True
1062 self.isConfig = True
961 self.figfile = figfile
1063 self.figfile = figfile
962
1064
963 self.setWinTitle(title)
1065 self.setWinTitle(title)
964
1066
965 if ((self.xmax - x[1]) < (x[1]-x[0])):
1067 if ((self.xmax - x[1]) < (x[1]-x[0])):
966 x[1] = self.xmax
1068 x[1] = self.xmax
967
1069
968 for i in range(nchan):
1070 for i in range(nchan):
969
1071
970 if (SNR and not onlySNR): j = 2*i
1072 if (SNR and not onlySNR): j = 2*i
971 else: j = i
1073 else: j = i
972
1074
973 j = nGraphsByChannel*i
1075 j = nGraphsByChannel*i
974
1076
975 if ((dataOut.azimuth!=None) and (dataOut.zenith!=None)):
1077 if ((dataOut.azimuth!=None) and (dataOut.zenith!=None)):
976 title = title + '_' + 'azimuth,zenith=%2.2f,%2.2f'%(dataOut.azimuth, dataOut.zenith)
1078 title = title + '_' + 'azimuth,zenith=%2.2f,%2.2f'%(dataOut.azimuth, dataOut.zenith)
977
1079
978 if not onlySNR:
1080 if not onlySNR:
979 axes = self.axesList[j*self.__nsubplots]
1081 axes = self.axesList[j*self.__nsubplots]
980 z1 = z[i,:].reshape((1,-1))
1082 z1 = z[i,:].reshape((1,-1))
981 axes.pcolorbuffer(x, y, z1,
1083 axes.pcolorbuffer(x, y, z1,
982 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
1084 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
983 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,colormap=colormap,
1085 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,colormap=colormap,
984 ticksize=9, cblabel=zlabel, cbsize="1%")
1086 ticksize=9, cblabel=zlabel, cbsize="1%")
985
1087
986 if DOP:
1088 if DOP:
987 title = "%s Channel %d: %s" %(parameterName, channelIndexList[i], thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
1089 title = "%s Channel %d: %s" %(parameterName, channelIndexList[i], thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
988
1090
989 if ((dataOut.azimuth!=None) and (dataOut.zenith!=None)):
1091 if ((dataOut.azimuth!=None) and (dataOut.zenith!=None)):
990 title = title + '_' + 'azimuth,zenith=%2.2f,%2.2f'%(dataOut.azimuth, dataOut.zenith)
1092 title = title + '_' + 'azimuth,zenith=%2.2f,%2.2f'%(dataOut.azimuth, dataOut.zenith)
991 axes = self.axesList[j]
1093 axes = self.axesList[j]
992 z1 = z[i,:].reshape((1,-1))
1094 z1 = z[i,:].reshape((1,-1))
993 axes.pcolorbuffer(x, y, z1,
1095 axes.pcolorbuffer(x, y, z1,
994 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
1096 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
995 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,colormap=colormap,
1097 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,colormap=colormap,
996 ticksize=9, cblabel=zlabel, cbsize="1%")
1098 ticksize=9, cblabel=zlabel, cbsize="1%")
997
1099
998 if SNR:
1100 if SNR:
999 title = "Channel %d Signal Noise Ratio (SNR): %s" %(channelIndexList[i], thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
1101 title = "Channel %d Signal Noise Ratio (SNR): %s" %(channelIndexList[i], thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
1000 axes = self.axesList[(j)*self.__nsubplots]
1102 axes = self.axesList[(j)*self.__nsubplots]
1001 if not onlySNR:
1103 if not onlySNR:
1002 axes = self.axesList[(j + 1)*self.__nsubplots]
1104 axes = self.axesList[(j + 1)*self.__nsubplots]
1003
1105
1004 axes = self.axesList[(j + nGraphsByChannel-1)]
1106 axes = self.axesList[(j + nGraphsByChannel-1)]
1005
1107
1006 z1 = SNRdB[i,:].reshape((1,-1))
1108 z1 = SNRdB[i,:].reshape((1,-1))
1007 axes.pcolorbuffer(x, y, z1,
1109 axes.pcolorbuffer(x, y, z1,
1008 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=SNRmin, zmax=SNRmax,
1110 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=SNRmin, zmax=SNRmax,
1009 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,colormap="jet",
1111 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,colormap="jet",
1010 ticksize=9, cblabel=zlabel, cbsize="1%")
1112 ticksize=9, cblabel=zlabel, cbsize="1%")
1011
1113
1012
1114
1013
1115
1014 self.draw()
1116 self.draw()
1015
1117
1016 if x[1] >= self.axesList[0].xmax:
1118 if x[1] >= self.axesList[0].xmax:
1017 self.counter_imagwr = wr_period
1119 self.counter_imagwr = wr_period
1018 self.isConfig = False
1120 self.isConfig = False
1019 self.figfile = None
1121 self.figfile = None
1020
1122
1021 self.save(figpath=figpath,
1123 self.save(figpath=figpath,
1022 figfile=figfile,
1124 figfile=figfile,
1023 save=save,
1125 save=save,
1024 ftp=ftp,
1126 ftp=ftp,
1025 wr_period=wr_period,
1127 wr_period=wr_period,
1026 thisDatetime=thisDatetime,
1128 thisDatetime=thisDatetime,
1027 update_figfile=False)
1129 update_figfile=False)
1028
1130
1029 class SpectralFittingPlot(Figure):
1131 class SpectralFittingPlot(Figure):
1030
1132
1031 __isConfig = None
1133 __isConfig = None
1032 __nsubplots = None
1134 __nsubplots = None
1033
1135
1034 WIDTHPROF = None
1136 WIDTHPROF = None
1035 HEIGHTPROF = None
1137 HEIGHTPROF = None
1036 PREFIX = 'prm'
1138 PREFIX = 'prm'
1037
1139
1038
1140
1039 N = None
1141 N = None
1040 ippSeconds = None
1142 ippSeconds = None
1041
1143
1042 def __init__(self, **kwargs):
1144 def __init__(self, **kwargs):
1043 Figure.__init__(self, **kwargs)
1145 Figure.__init__(self, **kwargs)
1044 self.isConfig = False
1146 self.isConfig = False
1045 self.__nsubplots = 1
1147 self.__nsubplots = 1
1046
1148
1047 self.PLOT_CODE = SPECFIT_CODE
1149 self.PLOT_CODE = SPECFIT_CODE
1048
1150
1049 self.WIDTH = 450
1151 self.WIDTH = 450
1050 self.HEIGHT = 250
1152 self.HEIGHT = 250
1051 self.WIDTHPROF = 0
1153 self.WIDTHPROF = 0
1052 self.HEIGHTPROF = 0
1154 self.HEIGHTPROF = 0
1053
1155
1054 def getSubplots(self):
1156 def getSubplots(self):
1055
1157
1056 ncol = int(numpy.sqrt(self.nplots)+0.9)
1158 ncol = int(numpy.sqrt(self.nplots)+0.9)
1057 nrow = int(self.nplots*1./ncol + 0.9)
1159 nrow = int(self.nplots*1./ncol + 0.9)
1058
1160
1059 return nrow, ncol
1161 return nrow, ncol
1060
1162
1061 def setup(self, id, nplots, wintitle, showprofile=False, show=True):
1163 def setup(self, id, nplots, wintitle, showprofile=False, show=True):
1062
1164
1063 showprofile = False
1165 showprofile = False
1064 self.__showprofile = showprofile
1166 self.__showprofile = showprofile
1065 self.nplots = nplots
1167 self.nplots = nplots
1066
1168
1067 ncolspan = 5
1169 ncolspan = 5
1068 colspan = 4
1170 colspan = 4
1069 if showprofile:
1171 if showprofile:
1070 ncolspan = 5
1172 ncolspan = 5
1071 colspan = 4
1173 colspan = 4
1072 self.__nsubplots = 2
1174 self.__nsubplots = 2
1073
1175
1074 self.createFigure(id = id,
1176 self.createFigure(id = id,
1075 wintitle = wintitle,
1177 wintitle = wintitle,
1076 widthplot = self.WIDTH + self.WIDTHPROF,
1178 widthplot = self.WIDTH + self.WIDTHPROF,
1077 heightplot = self.HEIGHT + self.HEIGHTPROF,
1179 heightplot = self.HEIGHT + self.HEIGHTPROF,
1078 show=show)
1180 show=show)
1079
1181
1080 nrow, ncol = self.getSubplots()
1182 nrow, ncol = self.getSubplots()
1081
1183
1082 counter = 0
1184 counter = 0
1083 for y in range(nrow):
1185 for y in range(nrow):
1084 for x in range(ncol):
1186 for x in range(ncol):
1085
1187
1086 if counter >= self.nplots:
1188 if counter >= self.nplots:
1087 break
1189 break
1088
1190
1089 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
1191 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
1090
1192
1091 if showprofile:
1193 if showprofile:
1092 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1)
1194 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1)
1093
1195
1094 counter += 1
1196 counter += 1
1095
1197
1096 def run(self, dataOut, id, cutHeight=None, fit=False, wintitle="", channelList=None, showprofile=True,
1198 def run(self, dataOut, id, cutHeight=None, fit=False, wintitle="", channelList=None, showprofile=True,
1097 xmin=None, xmax=None, ymin=None, ymax=None,
1199 xmin=None, xmax=None, ymin=None, ymax=None,
1098 save=False, figpath='./', figfile=None, show=True):
1200 save=False, figpath='./', figfile=None, show=True):
1099
1201
1100 """
1202 """
1101
1203
1102 Input:
1204 Input:
1103 dataOut :
1205 dataOut :
1104 id :
1206 id :
1105 wintitle :
1207 wintitle :
1106 channelList :
1208 channelList :
1107 showProfile :
1209 showProfile :
1108 xmin : None,
1210 xmin : None,
1109 xmax : None,
1211 xmax : None,
1110 zmin : None,
1212 zmin : None,
1111 zmax : None
1213 zmax : None
1112 """
1214 """
1113
1215
1114 if cutHeight==None:
1216 if cutHeight==None:
1115 h=270
1217 h=270
1116 heightindex = numpy.abs(cutHeight - dataOut.heightList).argmin()
1218 heightindex = numpy.abs(cutHeight - dataOut.heightList).argmin()
1117 cutHeight = dataOut.heightList[heightindex]
1219 cutHeight = dataOut.heightList[heightindex]
1118
1220
1119 factor = dataOut.normFactor
1221 factor = dataOut.normFactor
1120 x = dataOut.abscissaList[:-1]
1222 x = dataOut.abscissaList[:-1]
1121 #y = dataOut.getHeiRange()
1223 #y = dataOut.getHeiRange()
1122
1224
1123 z = dataOut.data_pre[:,:,heightindex]/factor
1225 z = dataOut.data_pre[:,:,heightindex]/factor
1124 z = numpy.where(numpy.isfinite(z), z, numpy.NAN)
1226 z = numpy.where(numpy.isfinite(z), z, numpy.NAN)
1125 avg = numpy.average(z, axis=1)
1227 avg = numpy.average(z, axis=1)
1126 listChannels = z.shape[0]
1228 listChannels = z.shape[0]
1127
1229
1128 #Reconstruct Function
1230 #Reconstruct Function
1129 if fit==True:
1231 if fit==True:
1130 groupArray = dataOut.groupList
1232 groupArray = dataOut.groupList
1131 listChannels = groupArray.reshape((groupArray.size))
1233 listChannels = groupArray.reshape((groupArray.size))
1132 listChannels.sort()
1234 listChannels.sort()
1133 spcFitLine = numpy.zeros(z.shape)
1235 spcFitLine = numpy.zeros(z.shape)
1134 constants = dataOut.constants
1236 constants = dataOut.constants
1135
1237
1136 nGroups = groupArray.shape[0]
1238 nGroups = groupArray.shape[0]
1137 nChannels = groupArray.shape[1]
1239 nChannels = groupArray.shape[1]
1138 nProfiles = z.shape[1]
1240 nProfiles = z.shape[1]
1139
1241
1140 for f in range(nGroups):
1242 for f in range(nGroups):
1141 groupChann = groupArray[f,:]
1243 groupChann = groupArray[f,:]
1142 p = dataOut.data_param[f,:,heightindex]
1244 p = dataOut.data_param[f,:,heightindex]
1143 # p = numpy.array([ 89.343967,0.14036615,0.17086219,18.89835291,1.58388365,1.55099167])
1245 # p = numpy.array([ 89.343967,0.14036615,0.17086219,18.89835291,1.58388365,1.55099167])
1144 fitLineAux = dataOut.library.modelFunction(p, constants)*nProfiles
1246 fitLineAux = dataOut.library.modelFunction(p, constants)*nProfiles
1145 fitLineAux = fitLineAux.reshape((nChannels,nProfiles))
1247 fitLineAux = fitLineAux.reshape((nChannels,nProfiles))
1146 spcFitLine[groupChann,:] = fitLineAux
1248 spcFitLine[groupChann,:] = fitLineAux
1147 # spcFitLine = spcFitLine/factor
1249 # spcFitLine = spcFitLine/factor
1148
1250
1149 z = z[listChannels,:]
1251 z = z[listChannels,:]
1150 spcFitLine = spcFitLine[listChannels,:]
1252 spcFitLine = spcFitLine[listChannels,:]
1151 spcFitLinedB = 10*numpy.log10(spcFitLine)
1253 spcFitLinedB = 10*numpy.log10(spcFitLine)
1152
1254
1153 zdB = 10*numpy.log10(z)
1255 zdB = 10*numpy.log10(z)
1154 #thisDatetime = dataOut.datatime
1256 #thisDatetime = dataOut.datatime
1155 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0])
1257 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0])
1156 title = wintitle + " Doppler Spectra: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
1258 title = wintitle + " Doppler Spectra: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
1157 xlabel = "Velocity (m/s)"
1259 xlabel = "Velocity (m/s)"
1158 ylabel = "Spectrum"
1260 ylabel = "Spectrum"
1159
1261
1160 if not self.isConfig:
1262 if not self.isConfig:
1161
1263
1162 nplots = listChannels.size
1264 nplots = listChannels.size
1163
1265
1164 self.setup(id=id,
1266 self.setup(id=id,
1165 nplots=nplots,
1267 nplots=nplots,
1166 wintitle=wintitle,
1268 wintitle=wintitle,
1167 showprofile=showprofile,
1269 showprofile=showprofile,
1168 show=show)
1270 show=show)
1169
1271
1170 if xmin == None: xmin = numpy.nanmin(x)
1272 if xmin == None: xmin = numpy.nanmin(x)
1171 if xmax == None: xmax = numpy.nanmax(x)
1273 if xmax == None: xmax = numpy.nanmax(x)
1172 if ymin == None: ymin = numpy.nanmin(zdB)
1274 if ymin == None: ymin = numpy.nanmin(zdB)
1173 if ymax == None: ymax = numpy.nanmax(zdB)+2
1275 if ymax == None: ymax = numpy.nanmax(zdB)+2
1174
1276
1175 self.isConfig = True
1277 self.isConfig = True
1176
1278
1177 self.setWinTitle(title)
1279 self.setWinTitle(title)
1178 for i in range(self.nplots):
1280 for i in range(self.nplots):
1179 # title = "Channel %d: %4.2fdB" %(dataOut.channelList[i]+1, noisedB[i])
1281 # title = "Channel %d: %4.2fdB" %(dataOut.channelList[i]+1, noisedB[i])
1180 title = "Height %4.1f km\nChannel %d:" %(cutHeight, listChannels[i])
1282 title = "Height %4.1f km\nChannel %d:" %(cutHeight, listChannels[i])
1181 axes = self.axesList[i*self.__nsubplots]
1283 axes = self.axesList[i*self.__nsubplots]
1182 if fit == False:
1284 if fit == False:
1183 axes.pline(x, zdB[i,:],
1285 axes.pline(x, zdB[i,:],
1184 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax,
1286 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax,
1185 xlabel=xlabel, ylabel=ylabel, title=title
1287 xlabel=xlabel, ylabel=ylabel, title=title
1186 )
1288 )
1187 if fit == True:
1289 if fit == True:
1188 fitline=spcFitLinedB[i,:]
1290 fitline=spcFitLinedB[i,:]
1189 y=numpy.vstack([zdB[i,:],fitline] )
1291 y=numpy.vstack([zdB[i,:],fitline] )
1190 legendlabels=['Data','Fitting']
1292 legendlabels=['Data','Fitting']
1191 axes.pmultilineyaxis(x, y,
1293 axes.pmultilineyaxis(x, y,
1192 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax,
1294 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax,
1193 xlabel=xlabel, ylabel=ylabel, title=title,
1295 xlabel=xlabel, ylabel=ylabel, title=title,
1194 legendlabels=legendlabels, marker=None,
1296 legendlabels=legendlabels, marker=None,
1195 linestyle='solid', grid='both')
1297 linestyle='solid', grid='both')
1196
1298
1197 self.draw()
1299 self.draw()
1198
1300
1199 self.save(figpath=figpath,
1301 self.save(figpath=figpath,
1200 figfile=figfile,
1302 figfile=figfile,
1201 save=save,
1303 save=save,
1202 ftp=ftp,
1304 ftp=ftp,
1203 wr_period=wr_period,
1305 wr_period=wr_period,
1204 thisDatetime=thisDatetime)
1306 thisDatetime=thisDatetime)
1205
1307
1206
1308
1207 class EWDriftsPlot(Figure):
1309 class EWDriftsPlot(Figure):
1208
1310
1209 __isConfig = None
1311 __isConfig = None
1210 __nsubplots = None
1312 __nsubplots = None
1211
1313
1212 WIDTHPROF = None
1314 WIDTHPROF = None
1213 HEIGHTPROF = None
1315 HEIGHTPROF = None
1214 PREFIX = 'drift'
1316 PREFIX = 'drift'
1215
1317
1318 parameters = {
1319 'id': global_type_string,
1320 'wintitle': global_type_string,
1321 'channelList': global_type_string,
1322 'xmin': global_type_float,
1323 'xmax': global_type_float,
1324 'ymin': global_type_float,
1325 'ymax': global_type_float,
1326 'zmin': global_type_float,
1327 'zmax': global_type_float,
1328 'zmaxVertfloat': global_type_float,
1329 'zminVertfloat': global_type_float,
1330 'zmaxZonafloat': global_type_float,
1331 'zminZonafloat': global_type_float,
1332 'timerange': global_type_float,
1333 'SNRthresh': global_type_float,
1334 'SNRmin': global_type_float,
1335 'SNRmax': global_type_float,
1336 'SNR_1': global_type_boolean,
1337 'save': global_type_boolean,
1338 'figpath': global_type_string,
1339 'lastone': global_type_float,
1340 'figfile': global_type_string,
1341 'ftp': global_type_string,
1342 'wr_period': global_type_integer,
1343 'show': global_type_string,
1344 'server': global_type_string,
1345 'folder': global_type_string,
1346 'username': global_type_string,
1347 'password': global_type_string,
1348 'ftp_wei': global_type_integer,
1349 'exp_code': global_type_integer,
1350 'sub_exp_code': global_type_integer,
1351 'plot_pos': global_type_integer,
1352 }
1353
1216 def __init__(self, **kwargs):
1354 def __init__(self, **kwargs):
1217 Figure.__init__(self, **kwargs)
1355 Figure.__init__(self, **kwargs)
1218 self.timerange = 2*60*60
1356 self.timerange = 2*60*60
1219 self.isConfig = False
1357 self.isConfig = False
1220 self.__nsubplots = 1
1358 self.__nsubplots = 1
1221
1359
1222 self.WIDTH = 800
1360 self.WIDTH = 800
1223 self.HEIGHT = 150
1361 self.HEIGHT = 150
1224 self.WIDTHPROF = 120
1362 self.WIDTHPROF = 120
1225 self.HEIGHTPROF = 0
1363 self.HEIGHTPROF = 0
1226 self.counter_imagwr = 0
1364 self.counter_imagwr = 0
1227
1365
1228 self.PLOT_CODE = EWDRIFT_CODE
1366 self.PLOT_CODE = EWDRIFT_CODE
1229
1367
1230 self.FTP_WEI = None
1368 self.FTP_WEI = None
1231 self.EXP_CODE = None
1369 self.EXP_CODE = None
1232 self.SUB_EXP_CODE = None
1370 self.SUB_EXP_CODE = None
1233 self.PLOT_POS = None
1371 self.PLOT_POS = None
1234 self.tmin = None
1372 self.tmin = None
1235 self.tmax = None
1373 self.tmax = None
1236
1374
1237 self.xmin = None
1375 self.xmin = None
1238 self.xmax = None
1376 self.xmax = None
1239
1377
1240 self.figfile = None
1378 self.figfile = None
1241
1379
1242 def getSubplots(self):
1380 def getSubplots(self):
1243
1381
1244 ncol = 1
1382 ncol = 1
1245 nrow = self.nplots
1383 nrow = self.nplots
1246
1384
1247 return nrow, ncol
1385 return nrow, ncol
1248
1386
1249 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
1387 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
1250
1388
1251 self.__showprofile = showprofile
1389 self.__showprofile = showprofile
1252 self.nplots = nplots
1390 self.nplots = nplots
1253
1391
1254 ncolspan = 1
1392 ncolspan = 1
1255 colspan = 1
1393 colspan = 1
1256
1394
1257 self.createFigure(id = id,
1395 self.createFigure(id = id,
1258 wintitle = wintitle,
1396 wintitle = wintitle,
1259 widthplot = self.WIDTH + self.WIDTHPROF,
1397 widthplot = self.WIDTH + self.WIDTHPROF,
1260 heightplot = self.HEIGHT + self.HEIGHTPROF,
1398 heightplot = self.HEIGHT + self.HEIGHTPROF,
1261 show=show)
1399 show=show)
1262
1400
1263 nrow, ncol = self.getSubplots()
1401 nrow, ncol = self.getSubplots()
1264
1402
1265 counter = 0
1403 counter = 0
1266 for y in range(nrow):
1404 for y in range(nrow):
1267 if counter >= self.nplots:
1405 if counter >= self.nplots:
1268 break
1406 break
1269
1407
1270 self.addAxes(nrow, ncol*ncolspan, y, 0, colspan, 1)
1408 self.addAxes(nrow, ncol*ncolspan, y, 0, colspan, 1)
1271 counter += 1
1409 counter += 1
1272
1410
1273 def run(self, dataOut, id, wintitle="", channelList=None,
1411 def run(self, dataOut, id, wintitle="", channelList=None,
1274 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
1412 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
1275 zmaxVertical = None, zminVertical = None, zmaxZonal = None, zminZonal = None,
1413 zmaxVertical = None, zminVertical = None, zmaxZonal = None, zminZonal = None,
1276 timerange=None, SNRthresh = -numpy.inf, SNRmin = None, SNRmax = None, SNR_1 = False,
1414 timerange=None, SNRthresh = -numpy.inf, SNRmin = None, SNRmax = None, SNR_1 = False,
1277 save=False, figpath='./', lastone=0,figfile=None, ftp=False, wr_period=1, show=True,
1415 save=False, figpath='./', lastone=0,figfile=None, ftp=False, wr_period=1, show=True,
1278 server=None, folder=None, username=None, password=None,
1416 server=None, folder=None, username=None, password=None,
1279 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0):
1417 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0):
1280 """
1418 """
1281
1419
1282 Input:
1420 Input:
1283 dataOut :
1421 dataOut :
1284 id :
1422 id :
1285 wintitle :
1423 wintitle :
1286 channelList :
1424 channelList :
1287 showProfile :
1425 showProfile :
1288 xmin : None,
1426 xmin : None,
1289 xmax : None,
1427 xmax : None,
1290 ymin : None,
1428 ymin : None,
1291 ymax : None,
1429 ymax : None,
1292 zmin : None,
1430 zmin : None,
1293 zmax : None
1431 zmax : None
1294 """
1432 """
1295
1433
1296 if timerange is not None:
1434 if timerange is not None:
1297 self.timerange = timerange
1435 self.timerange = timerange
1298
1436
1299 tmin = None
1437 tmin = None
1300 tmax = None
1438 tmax = None
1301
1439
1302 x = dataOut.getTimeRange1(dataOut.outputInterval)
1440 x = dataOut.getTimeRange1(dataOut.outputInterval)
1303 # y = dataOut.heightList
1441 # y = dataOut.heightList
1304 y = dataOut.heightList
1442 y = dataOut.heightList
1305
1443
1306 z = dataOut.data_output
1444 z = dataOut.data_output
1307 nplots = z.shape[0] #Number of wind dimensions estimated
1445 nplots = z.shape[0] #Number of wind dimensions estimated
1308 nplotsw = nplots
1446 nplotsw = nplots
1309
1447
1310 #If there is a SNR function defined
1448 #If there is a SNR function defined
1311 if dataOut.data_SNR is not None:
1449 if dataOut.data_SNR is not None:
1312 nplots += 1
1450 nplots += 1
1313 SNR = dataOut.data_SNR
1451 SNR = dataOut.data_SNR
1314
1452
1315 if SNR_1:
1453 if SNR_1:
1316 SNR += 1
1454 SNR += 1
1317
1455
1318 SNRavg = numpy.average(SNR, axis=0)
1456 SNRavg = numpy.average(SNR, axis=0)
1319
1457
1320 SNRdB = 10*numpy.log10(SNR)
1458 SNRdB = 10*numpy.log10(SNR)
1321 SNRavgdB = 10*numpy.log10(SNRavg)
1459 SNRavgdB = 10*numpy.log10(SNRavg)
1322
1460
1323 ind = numpy.where(SNRavg < 10**(SNRthresh/10))[0]
1461 ind = numpy.where(SNRavg < 10**(SNRthresh/10))[0]
1324
1462
1325 for i in range(nplotsw):
1463 for i in range(nplotsw):
1326 z[i,ind] = numpy.nan
1464 z[i,ind] = numpy.nan
1327
1465
1328
1466
1329 showprofile = False
1467 showprofile = False
1330 # thisDatetime = dataOut.datatime
1468 # thisDatetime = dataOut.datatime
1331 thisDatetime = datetime.datetime.utcfromtimestamp(x[1])
1469 thisDatetime = datetime.datetime.utcfromtimestamp(x[1])
1332 title = wintitle + " EW Drifts"
1470 title = wintitle + " EW Drifts"
1333 xlabel = ""
1471 xlabel = ""
1334 ylabel = "Height (Km)"
1472 ylabel = "Height (Km)"
1335
1473
1336 if not self.isConfig:
1474 if not self.isConfig:
1337
1475
1338 self.setup(id=id,
1476 self.setup(id=id,
1339 nplots=nplots,
1477 nplots=nplots,
1340 wintitle=wintitle,
1478 wintitle=wintitle,
1341 showprofile=showprofile,
1479 showprofile=showprofile,
1342 show=show)
1480 show=show)
1343
1481
1344 self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange)
1482 self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange)
1345
1483
1346 if ymin == None: ymin = numpy.nanmin(y)
1484 if ymin == None: ymin = numpy.nanmin(y)
1347 if ymax == None: ymax = numpy.nanmax(y)
1485 if ymax == None: ymax = numpy.nanmax(y)
1348
1486
1349 if zmaxZonal == None: zmaxZonal = numpy.nanmax(abs(z[0,:]))
1487 if zmaxZonal == None: zmaxZonal = numpy.nanmax(abs(z[0,:]))
1350 if zminZonal == None: zminZonal = -zmaxZonal
1488 if zminZonal == None: zminZonal = -zmaxZonal
1351 if zmaxVertical == None: zmaxVertical = numpy.nanmax(abs(z[1,:]))
1489 if zmaxVertical == None: zmaxVertical = numpy.nanmax(abs(z[1,:]))
1352 if zminVertical == None: zminVertical = -zmaxVertical
1490 if zminVertical == None: zminVertical = -zmaxVertical
1353
1491
1354 if dataOut.data_SNR is not None:
1492 if dataOut.data_SNR is not None:
1355 if SNRmin == None: SNRmin = numpy.nanmin(SNRavgdB)
1493 if SNRmin == None: SNRmin = numpy.nanmin(SNRavgdB)
1356 if SNRmax == None: SNRmax = numpy.nanmax(SNRavgdB)
1494 if SNRmax == None: SNRmax = numpy.nanmax(SNRavgdB)
1357
1495
1358 self.FTP_WEI = ftp_wei
1496 self.FTP_WEI = ftp_wei
1359 self.EXP_CODE = exp_code
1497 self.EXP_CODE = exp_code
1360 self.SUB_EXP_CODE = sub_exp_code
1498 self.SUB_EXP_CODE = sub_exp_code
1361 self.PLOT_POS = plot_pos
1499 self.PLOT_POS = plot_pos
1362
1500
1363 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
1501 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
1364 self.isConfig = True
1502 self.isConfig = True
1365
1503
1366
1504
1367 self.setWinTitle(title)
1505 self.setWinTitle(title)
1368
1506
1369 if ((self.xmax - x[1]) < (x[1]-x[0])):
1507 if ((self.xmax - x[1]) < (x[1]-x[0])):
1370 x[1] = self.xmax
1508 x[1] = self.xmax
1371
1509
1372 strWind = ['Zonal','Vertical']
1510 strWind = ['Zonal','Vertical']
1373 strCb = 'Velocity (m/s)'
1511 strCb = 'Velocity (m/s)'
1374 zmaxVector = [zmaxZonal, zmaxVertical]
1512 zmaxVector = [zmaxZonal, zmaxVertical]
1375 zminVector = [zminZonal, zminVertical]
1513 zminVector = [zminZonal, zminVertical]
1376
1514
1377 for i in range(nplotsw):
1515 for i in range(nplotsw):
1378
1516
1379 title = "%s Drifts: %s" %(strWind[i], thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
1517 title = "%s Drifts: %s" %(strWind[i], thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
1380 axes = self.axesList[i*self.__nsubplots]
1518 axes = self.axesList[i*self.__nsubplots]
1381
1519
1382 z1 = z[i,:].reshape((1,-1))
1520 z1 = z[i,:].reshape((1,-1))
1383
1521
1384 axes.pcolorbuffer(x, y, z1,
1522 axes.pcolorbuffer(x, y, z1,
1385 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=zminVector[i], zmax=zmaxVector[i],
1523 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=zminVector[i], zmax=zmaxVector[i],
1386 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
1524 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
1387 ticksize=9, cblabel=strCb, cbsize="1%", colormap="RdBu_r")
1525 ticksize=9, cblabel=strCb, cbsize="1%", colormap="RdBu_r")
1388
1526
1389 if dataOut.data_SNR is not None:
1527 if dataOut.data_SNR is not None:
1390 i += 1
1528 i += 1
1391 if SNR_1:
1529 if SNR_1:
1392 title = "Signal Noise Ratio + 1 (SNR+1): %s" %(thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
1530 title = "Signal Noise Ratio + 1 (SNR+1): %s" %(thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
1393 else:
1531 else:
1394 title = "Signal Noise Ratio (SNR): %s" %(thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
1532 title = "Signal Noise Ratio (SNR): %s" %(thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
1395 axes = self.axesList[i*self.__nsubplots]
1533 axes = self.axesList[i*self.__nsubplots]
1396 SNRavgdB = SNRavgdB.reshape((1,-1))
1534 SNRavgdB = SNRavgdB.reshape((1,-1))
1397
1535
1398 axes.pcolorbuffer(x, y, SNRavgdB,
1536 axes.pcolorbuffer(x, y, SNRavgdB,
1399 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=SNRmin, zmax=SNRmax,
1537 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=SNRmin, zmax=SNRmax,
1400 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
1538 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
1401 ticksize=9, cblabel='', cbsize="1%", colormap="jet")
1539 ticksize=9, cblabel='', cbsize="1%", colormap="jet")
1402
1540
1403 self.draw()
1541 self.draw()
1404
1542
1405 if x[1] >= self.axesList[0].xmax:
1543 if x[1] >= self.axesList[0].xmax:
1406 self.counter_imagwr = wr_period
1544 self.counter_imagwr = wr_period
1407 self.isConfig = False
1545 self.isConfig = False
1408 self.figfile = None
1546 self.figfile = None
1409
1547
1410
1548
1411
1549
1412
1550
1413 class PhasePlot(Figure):
1551 class PhasePlot(Figure):
1414
1552
1415 __isConfig = None
1553 __isConfig = None
1416 __nsubplots = None
1554 __nsubplots = None
1417
1555
1418 PREFIX = 'mphase'
1556 PREFIX = 'mphase'
1419
1557
1558 parameters = {
1559 'id': global_type_string,
1560 'wintitle': global_type_string,
1561 'pairsList': global_type_pairsList,
1562 'showprofile': global_type_boolean,
1563 'xmin': global_type_float,
1564 'xmax': global_type_float,
1565 'ymin': global_type_float,
1566 'ymax': global_type_float,
1567 'timerange': global_type_float,
1568 'save': global_type_boolean,
1569 'figpath': global_type_string,
1570 'figfile': global_type_string,
1571 'show': global_type_boolean,
1572 'ftp': global_type_boolean,
1573 'wr_period': global_type_integer,
1574 'server': global_type_string,
1575 'folder': global_type_string,
1576 'username': global_type_string,
1577 'password': global_type_string,
1578 'ftp_wei': global_type_integer,
1579 'exp_code': global_type_integer,
1580 'sub_exp_code': global_type_integer,
1581 'plot_pos': global_type_integer,
1582 }
1583
1420 def __init__(self, **kwargs):
1584 def __init__(self, **kwargs):
1421 Figure.__init__(self, **kwargs)
1585 Figure.__init__(self, **kwargs)
1422 self.timerange = 24*60*60
1586 self.timerange = 24*60*60
1423 self.isConfig = False
1587 self.isConfig = False
1424 self.__nsubplots = 1
1588 self.__nsubplots = 1
1425 self.counter_imagwr = 0
1589 self.counter_imagwr = 0
1426 self.WIDTH = 600
1590 self.WIDTH = 600
1427 self.HEIGHT = 300
1591 self.HEIGHT = 300
1428 self.WIDTHPROF = 120
1592 self.WIDTHPROF = 120
1429 self.HEIGHTPROF = 0
1593 self.HEIGHTPROF = 0
1430 self.xdata = None
1594 self.xdata = None
1431 self.ydata = None
1595 self.ydata = None
1432
1596
1433 self.PLOT_CODE = MPHASE_CODE
1597 self.PLOT_CODE = MPHASE_CODE
1434
1598
1435 self.FTP_WEI = None
1599 self.FTP_WEI = None
1436 self.EXP_CODE = None
1600 self.EXP_CODE = None
1437 self.SUB_EXP_CODE = None
1601 self.SUB_EXP_CODE = None
1438 self.PLOT_POS = None
1602 self.PLOT_POS = None
1439
1603
1440
1604
1441 self.filename_phase = None
1605 self.filename_phase = None
1442
1606
1443 self.figfile = None
1607 self.figfile = None
1444
1608
1445 def getSubplots(self):
1609 def getSubplots(self):
1446
1610
1447 ncol = 1
1611 ncol = 1
1448 nrow = 1
1612 nrow = 1
1449
1613
1450 return nrow, ncol
1614 return nrow, ncol
1451
1615
1452 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
1616 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
1453
1617
1454 self.__showprofile = showprofile
1618 self.__showprofile = showprofile
1455 self.nplots = nplots
1619 self.nplots = nplots
1456
1620
1457 ncolspan = 7
1621 ncolspan = 7
1458 colspan = 6
1622 colspan = 6
1459 self.__nsubplots = 2
1623 self.__nsubplots = 2
1460
1624
1461 self.createFigure(id = id,
1625 self.createFigure(id = id,
1462 wintitle = wintitle,
1626 wintitle = wintitle,
1463 widthplot = self.WIDTH+self.WIDTHPROF,
1627 widthplot = self.WIDTH+self.WIDTHPROF,
1464 heightplot = self.HEIGHT+self.HEIGHTPROF,
1628 heightplot = self.HEIGHT+self.HEIGHTPROF,
1465 show=show)
1629 show=show)
1466
1630
1467 nrow, ncol = self.getSubplots()
1631 nrow, ncol = self.getSubplots()
1468
1632
1469 self.addAxes(nrow, ncol*ncolspan, 0, 0, colspan, 1)
1633 self.addAxes(nrow, ncol*ncolspan, 0, 0, colspan, 1)
1470
1634
1471
1635
1472 def run(self, dataOut, id, wintitle="", pairsList=None, showprofile='True',
1636 def run(self, dataOut, id, wintitle="", pairsList=None, showprofile='True',
1473 xmin=None, xmax=None, ymin=None, ymax=None,
1637 xmin=None, xmax=None, ymin=None, ymax=None,
1474 timerange=None,
1638 timerange=None,
1475 save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1,
1639 save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1,
1476 server=None, folder=None, username=None, password=None,
1640 server=None, folder=None, username=None, password=None,
1477 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0):
1641 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0):
1478
1642
1479
1643
1480 tmin = None
1644 tmin = None
1481 tmax = None
1645 tmax = None
1482 x = dataOut.getTimeRange1(dataOut.outputInterval)
1646 x = dataOut.getTimeRange1(dataOut.outputInterval)
1483 y = dataOut.getHeiRange()
1647 y = dataOut.getHeiRange()
1484
1648
1485
1649
1486 #thisDatetime = dataOut.datatime
1650 #thisDatetime = dataOut.datatime
1487 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.ltctime)
1651 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.ltctime)
1488 title = wintitle + " Phase of Beacon Signal" # : %s" %(thisDatetime.strftime("%d-%b-%Y"))
1652 title = wintitle + " Phase of Beacon Signal" # : %s" %(thisDatetime.strftime("%d-%b-%Y"))
1489 xlabel = "Local Time"
1653 xlabel = "Local Time"
1490 ylabel = "Phase"
1654 ylabel = "Phase"
1491
1655
1492
1656
1493 #phase = numpy.zeros((len(pairsIndexList),len(dataOut.beacon_heiIndexList)))
1657 #phase = numpy.zeros((len(pairsIndexList),len(dataOut.beacon_heiIndexList)))
1494 phase_beacon = dataOut.data_output
1658 phase_beacon = dataOut.data_output
1495 update_figfile = False
1659 update_figfile = False
1496
1660
1497 if not self.isConfig:
1661 if not self.isConfig:
1498
1662
1499 self.nplots = phase_beacon.size
1663 self.nplots = phase_beacon.size
1500
1664
1501 self.setup(id=id,
1665 self.setup(id=id,
1502 nplots=self.nplots,
1666 nplots=self.nplots,
1503 wintitle=wintitle,
1667 wintitle=wintitle,
1504 showprofile=showprofile,
1668 showprofile=showprofile,
1505 show=show)
1669 show=show)
1506
1670
1507 if timerange is not None:
1671 if timerange is not None:
1508 self.timerange = timerange
1672 self.timerange = timerange
1509
1673
1510 self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange)
1674 self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange)
1511
1675
1512 if ymin == None: ymin = numpy.nanmin(phase_beacon) - 10.0
1676 if ymin == None: ymin = numpy.nanmin(phase_beacon) - 10.0
1513 if ymax == None: ymax = numpy.nanmax(phase_beacon) + 10.0
1677 if ymax == None: ymax = numpy.nanmax(phase_beacon) + 10.0
1514
1678
1515 self.FTP_WEI = ftp_wei
1679 self.FTP_WEI = ftp_wei
1516 self.EXP_CODE = exp_code
1680 self.EXP_CODE = exp_code
1517 self.SUB_EXP_CODE = sub_exp_code
1681 self.SUB_EXP_CODE = sub_exp_code
1518 self.PLOT_POS = plot_pos
1682 self.PLOT_POS = plot_pos
1519
1683
1520 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
1684 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
1521 self.isConfig = True
1685 self.isConfig = True
1522 self.figfile = figfile
1686 self.figfile = figfile
1523 self.xdata = numpy.array([])
1687 self.xdata = numpy.array([])
1524 self.ydata = numpy.array([])
1688 self.ydata = numpy.array([])
1525
1689
1526 #open file beacon phase
1690 #open file beacon phase
1527 path = '%s%03d' %(self.PREFIX, self.id)
1691 path = '%s%03d' %(self.PREFIX, self.id)
1528 beacon_file = os.path.join(path,'%s.txt'%self.name)
1692 beacon_file = os.path.join(path,'%s.txt'%self.name)
1529 self.filename_phase = os.path.join(figpath,beacon_file)
1693 self.filename_phase = os.path.join(figpath,beacon_file)
1530 update_figfile = True
1694 update_figfile = True
1531
1695
1532
1696
1533 #store data beacon phase
1697 #store data beacon phase
1534 #self.save_data(self.filename_phase, phase_beacon, thisDatetime)
1698 #self.save_data(self.filename_phase, phase_beacon, thisDatetime)
1535
1699
1536 self.setWinTitle(title)
1700 self.setWinTitle(title)
1537
1701
1538
1702
1539 title = "Phase Offset %s" %(thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
1703 title = "Phase Offset %s" %(thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
1540
1704
1541 legendlabels = ["phase %d"%(chan) for chan in numpy.arange(self.nplots)]
1705 legendlabels = ["phase %d"%(chan) for chan in numpy.arange(self.nplots)]
1542
1706
1543 axes = self.axesList[0]
1707 axes = self.axesList[0]
1544
1708
1545 self.xdata = numpy.hstack((self.xdata, x[0:1]))
1709 self.xdata = numpy.hstack((self.xdata, x[0:1]))
1546
1710
1547 if len(self.ydata)==0:
1711 if len(self.ydata)==0:
1548 self.ydata = phase_beacon.reshape(-1,1)
1712 self.ydata = phase_beacon.reshape(-1,1)
1549 else:
1713 else:
1550 self.ydata = numpy.hstack((self.ydata, phase_beacon.reshape(-1,1)))
1714 self.ydata = numpy.hstack((self.ydata, phase_beacon.reshape(-1,1)))
1551
1715
1552
1716
1553 axes.pmultilineyaxis(x=self.xdata, y=self.ydata,
1717 axes.pmultilineyaxis(x=self.xdata, y=self.ydata,
1554 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax,
1718 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax,
1555 xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels, marker='x', markersize=8, linestyle="solid",
1719 xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels, marker='x', markersize=8, linestyle="solid",
1556 XAxisAsTime=True, grid='both'
1720 XAxisAsTime=True, grid='both'
1557 )
1721 )
1558
1722
1559 self.draw()
1723 self.draw()
1560
1724
1561 self.save(figpath=figpath,
1725 self.save(figpath=figpath,
1562 figfile=figfile,
1726 figfile=figfile,
1563 save=save,
1727 save=save,
1564 ftp=ftp,
1728 ftp=ftp,
1565 wr_period=wr_period,
1729 wr_period=wr_period,
1566 thisDatetime=thisDatetime,
1730 thisDatetime=thisDatetime,
1567 update_figfile=update_figfile)
1731 update_figfile=update_figfile)
1568
1732
1569 if dataOut.ltctime + dataOut.outputInterval >= self.xmax:
1733 if dataOut.ltctime + dataOut.outputInterval >= self.xmax:
1570 self.counter_imagwr = wr_period
1734 self.counter_imagwr = wr_period
1571 self.isConfig = False
1735 self.isConfig = False
1572 update_figfile = True
1736 update_figfile = True
1573
1737
1574
1738
1575
1739
1576 class NSMeteorDetection1Plot(Figure):
1740 class NSMeteorDetection1Plot(Figure):
1577
1741
1578 isConfig = None
1742 isConfig = None
1579 __nsubplots = None
1743 __nsubplots = None
1580
1744
1581 WIDTHPROF = None
1745 WIDTHPROF = None
1582 HEIGHTPROF = None
1746 HEIGHTPROF = None
1583 PREFIX = 'nsm'
1747 PREFIX = 'nsm'
1584
1748
1585 zminList = None
1749 zminList = None
1586 zmaxList = None
1750 zmaxList = None
1587 cmapList = None
1751 cmapList = None
1588 titleList = None
1752 titleList = None
1589 nPairs = None
1753 nPairs = None
1590 nChannels = None
1754 nChannels = None
1591 nParam = None
1755 nParam = None
1592
1756
1757 parameters = {
1758 'id': global_type_string,
1759 'wintitle': global_type_string,
1760 'channelList': global_type_list,
1761 'showprofile': global_type_boolean,
1762 'xmin': global_type_float,
1763 'xmax': global_type_float,
1764 'ymin': global_type_float,
1765 'ymax': global_type_float,
1766 'SNRmin': global_type_float,
1767 'SNRmax': global_type_float,
1768 'vmin': global_type_float,
1769 'vmax': global_type_float,
1770 'wmin': global_type_float,
1771 'wmax': global_type_float,
1772 'mode': global_type_string,
1773 'save': global_type_boolean,
1774 'figpath': global_type_string,
1775 'figfile': global_type_string,
1776 'show': global_type_boolean,
1777 'ftp': global_type_string,
1778 'wr_period': global_type_integer,
1779 'server': global_type_string,
1780 'folder': global_type_string,
1781 'username': global_type_string,
1782 'password': global_type_string,
1783 'ftp_wei': global_type_integer,
1784 'exp_code': global_type_integer,
1785 'sub_exp_code': global_type_integer,
1786 'plot_pos': global_type_integer,
1787 'realtime': global_type_boolean,
1788 'xaxis': global_type_string,
1789 }
1790
1593 def __init__(self, **kwargs):
1791 def __init__(self, **kwargs):
1594 Figure.__init__(self, **kwargs)
1792 Figure.__init__(self, **kwargs)
1595 self.isConfig = False
1793 self.isConfig = False
1596 self.__nsubplots = 1
1794 self.__nsubplots = 1
1597
1795
1598 self.WIDTH = 750
1796 self.WIDTH = 750
1599 self.HEIGHT = 250
1797 self.HEIGHT = 250
1600 self.WIDTHPROF = 120
1798 self.WIDTHPROF = 120
1601 self.HEIGHTPROF = 0
1799 self.HEIGHTPROF = 0
1602 self.counter_imagwr = 0
1800 self.counter_imagwr = 0
1603
1801
1604 self.PLOT_CODE = SPEC_CODE
1802 self.PLOT_CODE = SPEC_CODE
1605
1803
1606 self.FTP_WEI = None
1804 self.FTP_WEI = None
1607 self.EXP_CODE = None
1805 self.EXP_CODE = None
1608 self.SUB_EXP_CODE = None
1806 self.SUB_EXP_CODE = None
1609 self.PLOT_POS = None
1807 self.PLOT_POS = None
1610
1808
1611 self.__xfilter_ena = False
1809 self.__xfilter_ena = False
1612 self.__yfilter_ena = False
1810 self.__yfilter_ena = False
1613
1811
1614 def getSubplots(self):
1812 def getSubplots(self):
1615
1813
1616 ncol = 3
1814 ncol = 3
1617 nrow = int(numpy.ceil(self.nplots/3.0))
1815 nrow = int(numpy.ceil(self.nplots/3.0))
1618
1816
1619 return nrow, ncol
1817 return nrow, ncol
1620
1818
1621 def setup(self, id, nplots, wintitle, show=True):
1819 def setup(self, id, nplots, wintitle, show=True):
1622
1820
1623 self.nplots = nplots
1821 self.nplots = nplots
1624
1822
1625 ncolspan = 1
1823 ncolspan = 1
1626 colspan = 1
1824 colspan = 1
1627
1825
1628 self.createFigure(id = id,
1826 self.createFigure(id = id,
1629 wintitle = wintitle,
1827 wintitle = wintitle,
1630 widthplot = self.WIDTH + self.WIDTHPROF,
1828 widthplot = self.WIDTH + self.WIDTHPROF,
1631 heightplot = self.HEIGHT + self.HEIGHTPROF,
1829 heightplot = self.HEIGHT + self.HEIGHTPROF,
1632 show=show)
1830 show=show)
1633
1831
1634 nrow, ncol = self.getSubplots()
1832 nrow, ncol = self.getSubplots()
1635
1833
1636 counter = 0
1834 counter = 0
1637 for y in range(nrow):
1835 for y in range(nrow):
1638 for x in range(ncol):
1836 for x in range(ncol):
1639
1837
1640 if counter >= self.nplots:
1838 if counter >= self.nplots:
1641 break
1839 break
1642
1840
1643 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
1841 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
1644
1842
1645 counter += 1
1843 counter += 1
1646
1844
1647 def run(self, dataOut, id, wintitle="", channelList=None, showprofile=True,
1845 def run(self, dataOut, id, wintitle="", channelList=None, showprofile=True,
1648 xmin=None, xmax=None, ymin=None, ymax=None, SNRmin=None, SNRmax=None,
1846 xmin=None, xmax=None, ymin=None, ymax=None, SNRmin=None, SNRmax=None,
1649 vmin=None, vmax=None, wmin=None, wmax=None, mode = 'SA',
1847 vmin=None, vmax=None, wmin=None, wmax=None, mode = 'SA',
1650 save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1,
1848 save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1,
1651 server=None, folder=None, username=None, password=None,
1849 server=None, folder=None, username=None, password=None,
1652 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0, realtime=False,
1850 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0, realtime=False,
1653 xaxis="frequency"):
1851 xaxis="frequency"):
1654
1852
1655 """
1853 """
1656
1854
1657 Input:
1855 Input:
1658 dataOut :
1856 dataOut :
1659 id :
1857 id :
1660 wintitle :
1858 wintitle :
1661 channelList :
1859 channelList :
1662 showProfile :
1860 showProfile :
1663 xmin : None,
1861 xmin : None,
1664 xmax : None,
1862 xmax : None,
1665 ymin : None,
1863 ymin : None,
1666 ymax : None,
1864 ymax : None,
1667 zmin : None,
1865 zmin : None,
1668 zmax : None
1866 zmax : None
1669 """
1867 """
1670 #SEPARAR EN DOS PLOTS
1868 #SEPARAR EN DOS PLOTS
1671 nParam = dataOut.data_param.shape[1] - 3
1869 nParam = dataOut.data_param.shape[1] - 3
1672
1870
1673 utctime = dataOut.data_param[0,0]
1871 utctime = dataOut.data_param[0,0]
1674 tmet = dataOut.data_param[:,1].astype(int)
1872 tmet = dataOut.data_param[:,1].astype(int)
1675 hmet = dataOut.data_param[:,2].astype(int)
1873 hmet = dataOut.data_param[:,2].astype(int)
1676
1874
1677 x = dataOut.abscissaList
1875 x = dataOut.abscissaList
1678 y = dataOut.heightList
1876 y = dataOut.heightList
1679
1877
1680 z = numpy.zeros((nParam, y.size, x.size - 1))
1878 z = numpy.zeros((nParam, y.size, x.size - 1))
1681 z[:,:] = numpy.nan
1879 z[:,:] = numpy.nan
1682 z[:,hmet,tmet] = dataOut.data_param[:,3:].T
1880 z[:,hmet,tmet] = dataOut.data_param[:,3:].T
1683 z[0,:,:] = 10*numpy.log10(z[0,:,:])
1881 z[0,:,:] = 10*numpy.log10(z[0,:,:])
1684
1882
1685 xlabel = "Time (s)"
1883 xlabel = "Time (s)"
1686 ylabel = "Range (km)"
1884 ylabel = "Range (km)"
1687
1885
1688 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.ltctime)
1886 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.ltctime)
1689
1887
1690 if not self.isConfig:
1888 if not self.isConfig:
1691
1889
1692 nplots = nParam
1890 nplots = nParam
1693
1891
1694 self.setup(id=id,
1892 self.setup(id=id,
1695 nplots=nplots,
1893 nplots=nplots,
1696 wintitle=wintitle,
1894 wintitle=wintitle,
1697 show=show)
1895 show=show)
1698
1896
1699 if xmin is None: xmin = numpy.nanmin(x)
1897 if xmin is None: xmin = numpy.nanmin(x)
1700 if xmax is None: xmax = numpy.nanmax(x)
1898 if xmax is None: xmax = numpy.nanmax(x)
1701 if ymin is None: ymin = numpy.nanmin(y)
1899 if ymin is None: ymin = numpy.nanmin(y)
1702 if ymax is None: ymax = numpy.nanmax(y)
1900 if ymax is None: ymax = numpy.nanmax(y)
1703 if SNRmin is None: SNRmin = numpy.nanmin(z[0,:])
1901 if SNRmin is None: SNRmin = numpy.nanmin(z[0,:])
1704 if SNRmax is None: SNRmax = numpy.nanmax(z[0,:])
1902 if SNRmax is None: SNRmax = numpy.nanmax(z[0,:])
1705 if vmax is None: vmax = numpy.nanmax(numpy.abs(z[1,:]))
1903 if vmax is None: vmax = numpy.nanmax(numpy.abs(z[1,:]))
1706 if vmin is None: vmin = -vmax
1904 if vmin is None: vmin = -vmax
1707 if wmin is None: wmin = 0
1905 if wmin is None: wmin = 0
1708 if wmax is None: wmax = 50
1906 if wmax is None: wmax = 50
1709
1907
1710 pairsList = dataOut.groupList
1908 pairsList = dataOut.groupList
1711 self.nPairs = len(dataOut.groupList)
1909 self.nPairs = len(dataOut.groupList)
1712
1910
1713 zminList = [SNRmin, vmin, cmin] + [pmin]*self.nPairs
1911 zminList = [SNRmin, vmin, cmin] + [pmin]*self.nPairs
1714 zmaxList = [SNRmax, vmax, cmax] + [pmax]*self.nPairs
1912 zmaxList = [SNRmax, vmax, cmax] + [pmax]*self.nPairs
1715 titleList = ["SNR","Radial Velocity","Coherence"]
1913 titleList = ["SNR","Radial Velocity","Coherence"]
1716 cmapList = ["jet","RdBu_r","jet"]
1914 cmapList = ["jet","RdBu_r","jet"]
1717
1915
1718 for i in range(self.nPairs):
1916 for i in range(self.nPairs):
1719 strAux1 = "Phase Difference "+ str(pairsList[i][0]) + str(pairsList[i][1])
1917 strAux1 = "Phase Difference "+ str(pairsList[i][0]) + str(pairsList[i][1])
1720 titleList = titleList + [strAux1]
1918 titleList = titleList + [strAux1]
1721 cmapList = cmapList + ["RdBu_r"]
1919 cmapList = cmapList + ["RdBu_r"]
1722
1920
1723 self.zminList = zminList
1921 self.zminList = zminList
1724 self.zmaxList = zmaxList
1922 self.zmaxList = zmaxList
1725 self.cmapList = cmapList
1923 self.cmapList = cmapList
1726 self.titleList = titleList
1924 self.titleList = titleList
1727
1925
1728 self.FTP_WEI = ftp_wei
1926 self.FTP_WEI = ftp_wei
1729 self.EXP_CODE = exp_code
1927 self.EXP_CODE = exp_code
1730 self.SUB_EXP_CODE = sub_exp_code
1928 self.SUB_EXP_CODE = sub_exp_code
1731 self.PLOT_POS = plot_pos
1929 self.PLOT_POS = plot_pos
1732
1930
1733 self.isConfig = True
1931 self.isConfig = True
1734
1932
1735 str_datetime = '%s %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S"))
1933 str_datetime = '%s %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S"))
1736
1934
1737 for i in range(nParam):
1935 for i in range(nParam):
1738 title = self.titleList[i] + ": " +str_datetime
1936 title = self.titleList[i] + ": " +str_datetime
1739 axes = self.axesList[i]
1937 axes = self.axesList[i]
1740 axes.pcolor(x, y, z[i,:].T,
1938 axes.pcolor(x, y, z[i,:].T,
1741 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=self.zminList[i], zmax=self.zmaxList[i],
1939 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=self.zminList[i], zmax=self.zmaxList[i],
1742 xlabel=xlabel, ylabel=ylabel, title=title, colormap=self.cmapList[i],ticksize=9, cblabel='')
1940 xlabel=xlabel, ylabel=ylabel, title=title, colormap=self.cmapList[i],ticksize=9, cblabel='')
1743 self.draw()
1941 self.draw()
1744
1942
1745 if figfile == None:
1943 if figfile == None:
1746 str_datetime = thisDatetime.strftime("%Y%m%d_%H%M%S")
1944 str_datetime = thisDatetime.strftime("%Y%m%d_%H%M%S")
1747 name = str_datetime
1945 name = str_datetime
1748 if ((dataOut.azimuth!=None) and (dataOut.zenith!=None)):
1946 if ((dataOut.azimuth!=None) and (dataOut.zenith!=None)):
1749 name = name + '_az' + '_%2.2f'%(dataOut.azimuth) + '_zn' + '_%2.2f'%(dataOut.zenith)
1947 name = name + '_az' + '_%2.2f'%(dataOut.azimuth) + '_zn' + '_%2.2f'%(dataOut.zenith)
1750 figfile = self.getFilename(name)
1948 figfile = self.getFilename(name)
1751
1949
1752 self.save(figpath=figpath,
1950 self.save(figpath=figpath,
1753 figfile=figfile,
1951 figfile=figfile,
1754 save=save,
1952 save=save,
1755 ftp=ftp,
1953 ftp=ftp,
1756 wr_period=wr_period,
1954 wr_period=wr_period,
1757 thisDatetime=thisDatetime)
1955 thisDatetime=thisDatetime)
1758
1956
1759
1957
1760 class NSMeteorDetection2Plot(Figure):
1958 class NSMeteorDetection2Plot(Figure):
1761
1959
1762 isConfig = None
1960 isConfig = None
1763 __nsubplots = None
1961 __nsubplots = None
1764
1962
1765 WIDTHPROF = None
1963 WIDTHPROF = None
1766 HEIGHTPROF = None
1964 HEIGHTPROF = None
1767 PREFIX = 'nsm'
1965 PREFIX = 'nsm'
1768
1966
1769 zminList = None
1967 zminList = None
1770 zmaxList = None
1968 zmaxList = None
1771 cmapList = None
1969 cmapList = None
1772 titleList = None
1970 titleList = None
1773 nPairs = None
1971 nPairs = None
1774 nChannels = None
1972 nChannels = None
1775 nParam = None
1973 nParam = None
1776
1974
1975 parameters = {
1976 'id': global_type_string,
1977 'wintitle': global_type_string,
1978 'channelList': global_type_list,
1979 'showprofile': global_type_boolean,
1980 'xmin': global_type_float,
1981 'xmax': global_type_float,
1982 'ymin': global_type_float,
1983 'ymax': global_type_float,
1984 'SNRmin': global_type_float,
1985 'SNRmax': global_type_float,
1986 'vmin': global_type_float,
1987 'vmax': global_type_float,
1988 'wmin': global_type_float,
1989 'wmax': global_type_float,
1990 'mode': global_type_string,
1991 'save': global_type_boolean,
1992 'figpath': global_type_string,
1993 'figfile': global_type_string,
1994 'show': global_type_string,
1995 'ftp': global_type_boolean,
1996 'wr_period': global_type_integer,
1997 'server': global_type_string,
1998 'folder': global_type_string,
1999 'username': global_type_string,
2000 'password': global_type_string,
2001 'ftp_wei': global_type_integer,
2002 'exp_code': global_type_integer,
2003 'sub_exp_code': global_type_integer,
2004 'plot_pos': global_type_integer,
2005 'realtime': global_type_boolean,
2006 'xaxis': global_type_string,
2007 }
2008
1777 def __init__(self, **kwargs):
2009 def __init__(self, **kwargs):
1778 Figure.__init__(self, **kwargs)
2010 Figure.__init__(self, **kwargs)
1779 self.isConfig = False
2011 self.isConfig = False
1780 self.__nsubplots = 1
2012 self.__nsubplots = 1
1781
2013
1782 self.WIDTH = 750
2014 self.WIDTH = 750
1783 self.HEIGHT = 250
2015 self.HEIGHT = 250
1784 self.WIDTHPROF = 120
2016 self.WIDTHPROF = 120
1785 self.HEIGHTPROF = 0
2017 self.HEIGHTPROF = 0
1786 self.counter_imagwr = 0
2018 self.counter_imagwr = 0
1787
2019
1788 self.PLOT_CODE = SPEC_CODE
2020 self.PLOT_CODE = SPEC_CODE
1789
2021
1790 self.FTP_WEI = None
2022 self.FTP_WEI = None
1791 self.EXP_CODE = None
2023 self.EXP_CODE = None
1792 self.SUB_EXP_CODE = None
2024 self.SUB_EXP_CODE = None
1793 self.PLOT_POS = None
2025 self.PLOT_POS = None
1794
2026
1795 self.__xfilter_ena = False
2027 self.__xfilter_ena = False
1796 self.__yfilter_ena = False
2028 self.__yfilter_ena = False
1797
2029
1798 def getSubplots(self):
2030 def getSubplots(self):
1799
2031
1800 ncol = 3
2032 ncol = 3
1801 nrow = int(numpy.ceil(self.nplots/3.0))
2033 nrow = int(numpy.ceil(self.nplots/3.0))
1802
2034
1803 return nrow, ncol
2035 return nrow, ncol
1804
2036
1805 def setup(self, id, nplots, wintitle, show=True):
2037 def setup(self, id, nplots, wintitle, show=True):
1806
2038
1807 self.nplots = nplots
2039 self.nplots = nplots
1808
2040
1809 ncolspan = 1
2041 ncolspan = 1
1810 colspan = 1
2042 colspan = 1
1811
2043
1812 self.createFigure(id = id,
2044 self.createFigure(id = id,
1813 wintitle = wintitle,
2045 wintitle = wintitle,
1814 widthplot = self.WIDTH + self.WIDTHPROF,
2046 widthplot = self.WIDTH + self.WIDTHPROF,
1815 heightplot = self.HEIGHT + self.HEIGHTPROF,
2047 heightplot = self.HEIGHT + self.HEIGHTPROF,
1816 show=show)
2048 show=show)
1817
2049
1818 nrow, ncol = self.getSubplots()
2050 nrow, ncol = self.getSubplots()
1819
2051
1820 counter = 0
2052 counter = 0
1821 for y in range(nrow):
2053 for y in range(nrow):
1822 for x in range(ncol):
2054 for x in range(ncol):
1823
2055
1824 if counter >= self.nplots:
2056 if counter >= self.nplots:
1825 break
2057 break
1826
2058
1827 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
2059 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
1828
2060
1829 counter += 1
2061 counter += 1
1830
2062
1831 def run(self, dataOut, id, wintitle="", channelList=None, showprofile=True,
2063 def run(self, dataOut, id, wintitle="", channelList=None, showprofile=True,
1832 xmin=None, xmax=None, ymin=None, ymax=None, SNRmin=None, SNRmax=None,
2064 xmin=None, xmax=None, ymin=None, ymax=None, SNRmin=None, SNRmax=None,
1833 vmin=None, vmax=None, wmin=None, wmax=None, mode = 'SA',
2065 vmin=None, vmax=None, wmin=None, wmax=None, mode = 'SA',
1834 save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1,
2066 save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1,
1835 server=None, folder=None, username=None, password=None,
2067 server=None, folder=None, username=None, password=None,
1836 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0, realtime=False,
2068 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0, realtime=False,
1837 xaxis="frequency"):
2069 xaxis="frequency"):
1838
2070
1839 """
2071 """
1840
2072
1841 Input:
2073 Input:
1842 dataOut :
2074 dataOut :
1843 id :
2075 id :
1844 wintitle :
2076 wintitle :
1845 channelList :
2077 channelList :
1846 showProfile :
2078 showProfile :
1847 xmin : None,
2079 xmin : None,
1848 xmax : None,
2080 xmax : None,
1849 ymin : None,
2081 ymin : None,
1850 ymax : None,
2082 ymax : None,
1851 zmin : None,
2083 zmin : None,
1852 zmax : None
2084 zmax : None
1853 """
2085 """
1854 #Rebuild matrix
2086 #Rebuild matrix
1855 utctime = dataOut.data_param[0,0]
2087 utctime = dataOut.data_param[0,0]
1856 cmet = dataOut.data_param[:,1].astype(int)
2088 cmet = dataOut.data_param[:,1].astype(int)
1857 tmet = dataOut.data_param[:,2].astype(int)
2089 tmet = dataOut.data_param[:,2].astype(int)
1858 hmet = dataOut.data_param[:,3].astype(int)
2090 hmet = dataOut.data_param[:,3].astype(int)
1859
2091
1860 nParam = 3
2092 nParam = 3
1861 nChan = len(dataOut.groupList)
2093 nChan = len(dataOut.groupList)
1862 x = dataOut.abscissaList
2094 x = dataOut.abscissaList
1863 y = dataOut.heightList
2095 y = dataOut.heightList
1864
2096
1865 z = numpy.full((nChan, nParam, y.size, x.size - 1),numpy.nan)
2097 z = numpy.full((nChan, nParam, y.size, x.size - 1),numpy.nan)
1866 z[cmet,:,hmet,tmet] = dataOut.data_param[:,4:]
2098 z[cmet,:,hmet,tmet] = dataOut.data_param[:,4:]
1867 z[:,0,:,:] = 10*numpy.log10(z[:,0,:,:]) #logarithmic scale
2099 z[:,0,:,:] = 10*numpy.log10(z[:,0,:,:]) #logarithmic scale
1868 z = numpy.reshape(z, (nChan*nParam, y.size, x.size-1))
2100 z = numpy.reshape(z, (nChan*nParam, y.size, x.size-1))
1869
2101
1870 xlabel = "Time (s)"
2102 xlabel = "Time (s)"
1871 ylabel = "Range (km)"
2103 ylabel = "Range (km)"
1872
2104
1873 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.ltctime)
2105 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.ltctime)
1874
2106
1875 if not self.isConfig:
2107 if not self.isConfig:
1876
2108
1877 nplots = nParam*nChan
2109 nplots = nParam*nChan
1878
2110
1879 self.setup(id=id,
2111 self.setup(id=id,
1880 nplots=nplots,
2112 nplots=nplots,
1881 wintitle=wintitle,
2113 wintitle=wintitle,
1882 show=show)
2114 show=show)
1883
2115
1884 if xmin is None: xmin = numpy.nanmin(x)
2116 if xmin is None: xmin = numpy.nanmin(x)
1885 if xmax is None: xmax = numpy.nanmax(x)
2117 if xmax is None: xmax = numpy.nanmax(x)
1886 if ymin is None: ymin = numpy.nanmin(y)
2118 if ymin is None: ymin = numpy.nanmin(y)
1887 if ymax is None: ymax = numpy.nanmax(y)
2119 if ymax is None: ymax = numpy.nanmax(y)
1888 if SNRmin is None: SNRmin = numpy.nanmin(z[0,:])
2120 if SNRmin is None: SNRmin = numpy.nanmin(z[0,:])
1889 if SNRmax is None: SNRmax = numpy.nanmax(z[0,:])
2121 if SNRmax is None: SNRmax = numpy.nanmax(z[0,:])
1890 if vmax is None: vmax = numpy.nanmax(numpy.abs(z[1,:]))
2122 if vmax is None: vmax = numpy.nanmax(numpy.abs(z[1,:]))
1891 if vmin is None: vmin = -vmax
2123 if vmin is None: vmin = -vmax
1892 if wmin is None: wmin = 0
2124 if wmin is None: wmin = 0
1893 if wmax is None: wmax = 50
2125 if wmax is None: wmax = 50
1894
2126
1895 self.nChannels = nChan
2127 self.nChannels = nChan
1896
2128
1897 zminList = []
2129 zminList = []
1898 zmaxList = []
2130 zmaxList = []
1899 titleList = []
2131 titleList = []
1900 cmapList = []
2132 cmapList = []
1901 for i in range(self.nChannels):
2133 for i in range(self.nChannels):
1902 strAux1 = "SNR Channel "+ str(i)
2134 strAux1 = "SNR Channel "+ str(i)
1903 strAux2 = "Radial Velocity Channel "+ str(i)
2135 strAux2 = "Radial Velocity Channel "+ str(i)
1904 strAux3 = "Spectral Width Channel "+ str(i)
2136 strAux3 = "Spectral Width Channel "+ str(i)
1905
2137
1906 titleList = titleList + [strAux1,strAux2,strAux3]
2138 titleList = titleList + [strAux1,strAux2,strAux3]
1907 cmapList = cmapList + ["jet","RdBu_r","jet"]
2139 cmapList = cmapList + ["jet","RdBu_r","jet"]
1908 zminList = zminList + [SNRmin,vmin,wmin]
2140 zminList = zminList + [SNRmin,vmin,wmin]
1909 zmaxList = zmaxList + [SNRmax,vmax,wmax]
2141 zmaxList = zmaxList + [SNRmax,vmax,wmax]
1910
2142
1911 self.zminList = zminList
2143 self.zminList = zminList
1912 self.zmaxList = zmaxList
2144 self.zmaxList = zmaxList
1913 self.cmapList = cmapList
2145 self.cmapList = cmapList
1914 self.titleList = titleList
2146 self.titleList = titleList
1915
2147
1916 self.FTP_WEI = ftp_wei
2148 self.FTP_WEI = ftp_wei
1917 self.EXP_CODE = exp_code
2149 self.EXP_CODE = exp_code
1918 self.SUB_EXP_CODE = sub_exp_code
2150 self.SUB_EXP_CODE = sub_exp_code
1919 self.PLOT_POS = plot_pos
2151 self.PLOT_POS = plot_pos
1920
2152
1921 self.isConfig = True
2153 self.isConfig = True
1922
2154
1923 str_datetime = '%s %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S"))
2155 str_datetime = '%s %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S"))
1924
2156
1925 for i in range(self.nplots):
2157 for i in range(self.nplots):
1926 title = self.titleList[i] + ": " +str_datetime
2158 title = self.titleList[i] + ": " +str_datetime
1927 axes = self.axesList[i]
2159 axes = self.axesList[i]
1928 axes.pcolor(x, y, z[i,:].T,
2160 axes.pcolor(x, y, z[i,:].T,
1929 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=self.zminList[i], zmax=self.zmaxList[i],
2161 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=self.zminList[i], zmax=self.zmaxList[i],
1930 xlabel=xlabel, ylabel=ylabel, title=title, colormap=self.cmapList[i],ticksize=9, cblabel='')
2162 xlabel=xlabel, ylabel=ylabel, title=title, colormap=self.cmapList[i],ticksize=9, cblabel='')
1931 self.draw()
2163 self.draw()
1932
2164
1933 if figfile == None:
2165 if figfile == None:
1934 str_datetime = thisDatetime.strftime("%Y%m%d_%H%M%S")
2166 str_datetime = thisDatetime.strftime("%Y%m%d_%H%M%S")
1935 name = str_datetime
2167 name = str_datetime
1936 if ((dataOut.azimuth!=None) and (dataOut.zenith!=None)):
2168 if ((dataOut.azimuth!=None) and (dataOut.zenith!=None)):
1937 name = name + '_az' + '_%2.2f'%(dataOut.azimuth) + '_zn' + '_%2.2f'%(dataOut.zenith)
2169 name = name + '_az' + '_%2.2f'%(dataOut.azimuth) + '_zn' + '_%2.2f'%(dataOut.zenith)
1938 figfile = self.getFilename(name)
2170 figfile = self.getFilename(name)
1939
2171
1940 self.save(figpath=figpath,
2172 self.save(figpath=figpath,
1941 figfile=figfile,
2173 figfile=figfile,
1942 save=save,
2174 save=save,
1943 ftp=ftp,
2175 ftp=ftp,
1944 wr_period=wr_period,
2176 wr_period=wr_period,
1945 thisDatetime=thisDatetime)
2177 thisDatetime=thisDatetime)
@@ -1,1534 +1,1655
1 '''
1 '''
2 Created on Jul 9, 2014
2 Created on Jul 9, 2014
3
3
4 @author: roj-idl71
4 @author: roj-idl71
5 '''
5 '''
6 import os
6 import os
7 import datetime
7 import datetime
8 import numpy
8 import numpy
9
9
10 from figure import Figure, isRealtime, isTimeInHourRange
10 from figure import Figure, isRealtime, isTimeInHourRange
11 from plotting_codes import *
11 from plotting_codes import *
12
12
13
13 class SpectraPlot(Figure):
14 class SpectraPlot(Figure):
14
15
15 isConfig = None
16 isConfig = None
16 __nsubplots = None
17 __nsubplots = None
17
18
18 WIDTHPROF = None
19 WIDTHPROF = None
19 HEIGHTPROF = None
20 HEIGHTPROF = None
20 PREFIX = 'spc'
21 PREFIX = 'spc'
21
22
22 def __init__(self, **kwargs):
23 def __init__(self, **kwargs):
23 Figure.__init__(self, **kwargs)
24 Figure.__init__(self, **kwargs)
24 self.isConfig = False
25 self.isConfig = False
25 self.__nsubplots = 1
26 self.__nsubplots = 1
26
27
27 self.WIDTH = 250
28 self.WIDTH = 250
28 self.HEIGHT = 250
29 self.HEIGHT = 250
29 self.WIDTHPROF = 120
30 self.WIDTHPROF = 120
30 self.HEIGHTPROF = 0
31 self.HEIGHTPROF = 0
31 self.counter_imagwr = 0
32 self.counter_imagwr = 0
32
33
33 self.PLOT_CODE = SPEC_CODE
34 self.PLOT_CODE = SPEC_CODE
34
35
35 self.FTP_WEI = None
36 self.FTP_WEI = None
36 self.EXP_CODE = None
37 self.EXP_CODE = None
37 self.SUB_EXP_CODE = None
38 self.SUB_EXP_CODE = None
38 self.PLOT_POS = None
39 self.PLOT_POS = None
39
40
40 self.__xfilter_ena = False
41 self.__xfilter_ena = False
41 self.__yfilter_ena = False
42 self.__yfilter_ena = False
42
43
43 def getSubplots(self):
44 def getSubplots(self):
44
45
45 ncol = int(numpy.sqrt(self.nplots)+0.9)
46 ncol = int(numpy.sqrt(self.nplots)+0.9)
46 nrow = int(self.nplots*1./ncol + 0.9)
47 nrow = int(self.nplots*1./ncol + 0.9)
47
48
48 return nrow, ncol
49 return nrow, ncol
49
50
50 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
51 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
51
52
52 self.__showprofile = showprofile
53 self.__showprofile = showprofile
53 self.nplots = nplots
54 self.nplots = nplots
54
55
55 ncolspan = 1
56 ncolspan = 1
56 colspan = 1
57 colspan = 1
57 if showprofile:
58 if showprofile:
58 ncolspan = 3
59 ncolspan = 3
59 colspan = 2
60 colspan = 2
60 self.__nsubplots = 2
61 self.__nsubplots = 2
61
62
62 self.createFigure(id = id,
63 self.createFigure(id = id,
63 wintitle = wintitle,
64 wintitle = wintitle,
64 widthplot = self.WIDTH + self.WIDTHPROF,
65 widthplot = self.WIDTH + self.WIDTHPROF,
65 heightplot = self.HEIGHT + self.HEIGHTPROF,
66 heightplot = self.HEIGHT + self.HEIGHTPROF,
66 show=show)
67 show=show)
67
68
68 nrow, ncol = self.getSubplots()
69 nrow, ncol = self.getSubplots()
69
70
70 counter = 0
71 counter = 0
71 for y in range(nrow):
72 for y in range(nrow):
72 for x in range(ncol):
73 for x in range(ncol):
73
74
74 if counter >= self.nplots:
75 if counter >= self.nplots:
75 break
76 break
76
77
77 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
78 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
78
79
79 if showprofile:
80 if showprofile:
80 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1)
81 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1)
81
82
82 counter += 1
83 counter += 1
83
84
84 def run(self, dataOut, id, wintitle="", channelList=None, showprofile=True,
85 def run(self, dataOut, id, wintitle="", channelList=None, showprofile=True,
85 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
86 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
86 save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1,
87 save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1,
87 server=None, folder=None, username=None, password=None,
88 server=None, folder=None, username=None, password=None,
88 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0, realtime=False,
89 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0, realtime=False,
89 xaxis="velocity", **kwargs):
90 xaxis="velocity", **kwargs):
90
91
91 """
92 """
92
93
93 Input:
94 Input:
94 dataOut :
95 dataOut :
95 id :
96 id :
96 wintitle :
97 wintitle :
97 channelList :
98 channelList :
98 showProfile :
99 showProfile :
99 xmin : None,
100 xmin : None,
100 xmax : None,
101 xmax : None,
101 ymin : None,
102 ymin : None,
102 ymax : None,
103 ymax : None,
103 zmin : None,
104 zmin : None,
104 zmax : None
105 zmax : None
105 """
106 """
106
107
107 colormap = kwargs.get('colormap','jet')
108 colormap = kwargs.get('colormap','jet')
108
109
109 if realtime:
110 if realtime:
110 if not(isRealtime(utcdatatime = dataOut.utctime)):
111 if not(isRealtime(utcdatatime = dataOut.utctime)):
111 print 'Skipping this plot function'
112 print 'Skipping this plot function'
112 return
113 return
113
114
114 if channelList == None:
115 if channelList == None:
115 channelIndexList = dataOut.channelIndexList
116 channelIndexList = dataOut.channelIndexList
116 else:
117 else:
117 channelIndexList = []
118 channelIndexList = []
118 for channel in channelList:
119 for channel in channelList:
119 if channel not in dataOut.channelList:
120 if channel not in dataOut.channelList:
120 raise ValueError, "Channel %d is not in dataOut.channelList" %channel
121 raise ValueError, "Channel %d is not in dataOut.channelList" %channel
121 channelIndexList.append(dataOut.channelList.index(channel))
122 channelIndexList.append(dataOut.channelList.index(channel))
122
123
123 factor = dataOut.normFactor
124 factor = dataOut.normFactor
124
125
125 if xaxis == "frequency":
126 if xaxis == "frequency":
126 x = dataOut.getFreqRange(1)/1000.
127 x = dataOut.getFreqRange(1)/1000.
127 xlabel = "Frequency (kHz)"
128 xlabel = "Frequency (kHz)"
128
129
129 elif xaxis == "time":
130 elif xaxis == "time":
130 x = dataOut.getAcfRange(1)
131 x = dataOut.getAcfRange(1)
131 xlabel = "Time (ms)"
132 xlabel = "Time (ms)"
132
133
133 else:
134 else:
134 x = dataOut.getVelRange(1)
135 x = dataOut.getVelRange(1)
135 xlabel = "Velocity (m/s)"
136 xlabel = "Velocity (m/s)"
136
137
137 ylabel = "Range (Km)"
138 ylabel = "Range (Km)"
138
139
139 y = dataOut.getHeiRange()
140 y = dataOut.getHeiRange()
140
141
141 z = dataOut.data_spc/factor
142 z = dataOut.data_spc/factor
142 z = numpy.where(numpy.isfinite(z), z, numpy.NAN)
143 z = numpy.where(numpy.isfinite(z), z, numpy.NAN)
143 zdB = 10*numpy.log10(z)
144 zdB = 10*numpy.log10(z)
144
145
145 avg = numpy.average(z, axis=1)
146 avg = numpy.average(z, axis=1)
146 avgdB = 10*numpy.log10(avg)
147 avgdB = 10*numpy.log10(avg)
147
148
148 noise = dataOut.getNoise()/factor
149 noise = dataOut.getNoise()/factor
149 noisedB = 10*numpy.log10(noise)
150 noisedB = 10*numpy.log10(noise)
150
151
151 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0])
152 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0])
152 title = wintitle + " Spectra"
153 title = wintitle + " Spectra"
153 if ((dataOut.azimuth!=None) and (dataOut.zenith!=None)):
154 if ((dataOut.azimuth!=None) and (dataOut.zenith!=None)):
154 title = title + '_' + 'azimuth,zenith=%2.2f,%2.2f'%(dataOut.azimuth, dataOut.zenith)
155 title = title + '_' + 'azimuth,zenith=%2.2f,%2.2f'%(dataOut.azimuth, dataOut.zenith)
155
156
156 if not self.isConfig:
157 if not self.isConfig:
157
158
158 nplots = len(channelIndexList)
159 nplots = len(channelIndexList)
159
160
160 self.setup(id=id,
161 self.setup(id=id,
161 nplots=nplots,
162 nplots=nplots,
162 wintitle=wintitle,
163 wintitle=wintitle,
163 showprofile=showprofile,
164 showprofile=showprofile,
164 show=show)
165 show=show)
165
166
166 if xmin == None: xmin = numpy.nanmin(x)
167 if xmin == None: xmin = numpy.nanmin(x)
167 if xmax == None: xmax = numpy.nanmax(x)
168 if xmax == None: xmax = numpy.nanmax(x)
168 if ymin == None: ymin = numpy.nanmin(y)
169 if ymin == None: ymin = numpy.nanmin(y)
169 if ymax == None: ymax = numpy.nanmax(y)
170 if ymax == None: ymax = numpy.nanmax(y)
170 if zmin == None: zmin = numpy.floor(numpy.nanmin(noisedB)) - 3
171 if zmin == None: zmin = numpy.floor(numpy.nanmin(noisedB)) - 3
171 if zmax == None: zmax = numpy.ceil(numpy.nanmax(avgdB)) + 3
172 if zmax == None: zmax = numpy.ceil(numpy.nanmax(avgdB)) + 3
172
173
173 self.FTP_WEI = ftp_wei
174 self.FTP_WEI = ftp_wei
174 self.EXP_CODE = exp_code
175 self.EXP_CODE = exp_code
175 self.SUB_EXP_CODE = sub_exp_code
176 self.SUB_EXP_CODE = sub_exp_code
176 self.PLOT_POS = plot_pos
177 self.PLOT_POS = plot_pos
177
178
178 self.isConfig = True
179 self.isConfig = True
179
180
180 self.setWinTitle(title)
181 self.setWinTitle(title)
181
182
182 for i in range(self.nplots):
183 for i in range(self.nplots):
183 index = channelIndexList[i]
184 index = channelIndexList[i]
184 str_datetime = '%s %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S"))
185 str_datetime = '%s %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S"))
185 title = "Channel %d: %4.2fdB: %s" %(dataOut.channelList[index], noisedB[index], str_datetime)
186 title = "Channel %d: %4.2fdB: %s" %(dataOut.channelList[index], noisedB[index], str_datetime)
186 if len(dataOut.beam.codeList) != 0:
187 if len(dataOut.beam.codeList) != 0:
187 title = "Ch%d:%4.2fdB,%2.2f,%2.2f:%s" %(dataOut.channelList[index], noisedB[index], dataOut.beam.azimuthList[index], dataOut.beam.zenithList[index], str_datetime)
188 title = "Ch%d:%4.2fdB,%2.2f,%2.2f:%s" %(dataOut.channelList[index], noisedB[index], dataOut.beam.azimuthList[index], dataOut.beam.zenithList[index], str_datetime)
188
189
189 axes = self.axesList[i*self.__nsubplots]
190 axes = self.axesList[i*self.__nsubplots]
190 axes.pcolor(x, y, zdB[index,:,:],
191 axes.pcolor(x, y, zdB[index,:,:],
191 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
192 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
192 xlabel=xlabel, ylabel=ylabel, title=title, colormap=colormap,
193 xlabel=xlabel, ylabel=ylabel, title=title, colormap=colormap,
193 ticksize=9, cblabel='')
194 ticksize=9, cblabel='')
194
195
195 if self.__showprofile:
196 if self.__showprofile:
196 axes = self.axesList[i*self.__nsubplots +1]
197 axes = self.axesList[i*self.__nsubplots +1]
197 axes.pline(avgdB[index,:], y,
198 axes.pline(avgdB[index,:], y,
198 xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax,
199 xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax,
199 xlabel='dB', ylabel='', title='',
200 xlabel='dB', ylabel='', title='',
200 ytick_visible=False,
201 ytick_visible=False,
201 grid='x')
202 grid='x')
202
203
203 noiseline = numpy.repeat(noisedB[index], len(y))
204 noiseline = numpy.repeat(noisedB[index], len(y))
204 axes.addpline(noiseline, y, idline=1, color="black", linestyle="dashed", lw=2)
205 axes.addpline(noiseline, y, idline=1, color="black", linestyle="dashed", lw=2)
205
206
206 self.draw()
207 self.draw()
207
208
208 if figfile == None:
209 if figfile == None:
209 str_datetime = thisDatetime.strftime("%Y%m%d_%H%M%S")
210 str_datetime = thisDatetime.strftime("%Y%m%d_%H%M%S")
210 name = str_datetime
211 name = str_datetime
211 if ((dataOut.azimuth!=None) and (dataOut.zenith!=None)):
212 if ((dataOut.azimuth!=None) and (dataOut.zenith!=None)):
212 name = name + '_az' + '_%2.2f'%(dataOut.azimuth) + '_zn' + '_%2.2f'%(dataOut.zenith)
213 name = name + '_az' + '_%2.2f'%(dataOut.azimuth) + '_zn' + '_%2.2f'%(dataOut.zenith)
213 figfile = self.getFilename(name)
214 figfile = self.getFilename(name)
214
215
215 self.save(figpath=figpath,
216 self.save(figpath=figpath,
216 figfile=figfile,
217 figfile=figfile,
217 save=save,
218 save=save,
218 ftp=ftp,
219 ftp=ftp,
219 wr_period=wr_period,
220 wr_period=wr_period,
220 thisDatetime=thisDatetime)
221 thisDatetime=thisDatetime)
221
222
222 class CrossSpectraPlot(Figure):
223 class CrossSpectraPlot(Figure):
223
224
224 isConfig = None
225 isConfig = None
225 __nsubplots = None
226 __nsubplots = None
226
227
227 WIDTH = None
228 WIDTH = None
228 HEIGHT = None
229 HEIGHT = None
229 WIDTHPROF = None
230 WIDTHPROF = None
230 HEIGHTPROF = None
231 HEIGHTPROF = None
231 PREFIX = 'cspc'
232 PREFIX = 'cspc'
232
233
234 parameters = {
235 'id': global_type_string,
236 'wintitle': global_type_string,
237 'pairsList': global_type_pairsList,
238 'xmin': global_type_float,
239 'xmax': global_type_float,
240 'ymin': global_type_float,
241 'ymax': global_type_float,
242 'zmin': global_type_float,
243 'zmax': global_type_float,
244 'coh_min': global_type_float,
245 'coh_max': global_type_float,
246 'phase_min': global_type_float,
247 'phase_max': global_type_float,
248 'save': global_type_boolean,
249 'figpath': global_type_string,
250 'figfile': global_type_string,
251 'ftp': global_type_boolean,
252 'wr_period': global_type_integer,
253 'power_cmap': global_type_colormap,
254 'coherence_cmap': global_type_colormap,
255 'phase_cmap': global_type_colormap,
256 'show': global_type_boolean,
257 'server': global_type_string,
258 'folder': global_type_string,
259 'username': global_type_string,
260 'password': global_type_string,
261 'ftp_wei': global_type_integer,
262 'exp_code': global_type_integer,
263 'sub_exp_code': global_type_integer,
264 'plot_pos': global_type_integer,
265 'xaxis': global_type_string,
266 }
267
233 def __init__(self, **kwargs):
268 def __init__(self, **kwargs):
234 Figure.__init__(self, **kwargs)
269 Figure.__init__(self, **kwargs)
235 self.isConfig = False
270 self.isConfig = False
236 self.__nsubplots = 4
271 self.__nsubplots = 4
237 self.counter_imagwr = 0
272 self.counter_imagwr = 0
238 self.WIDTH = 250
273 self.WIDTH = 250
239 self.HEIGHT = 250
274 self.HEIGHT = 250
240 self.WIDTHPROF = 0
275 self.WIDTHPROF = 0
241 self.HEIGHTPROF = 0
276 self.HEIGHTPROF = 0
242
277
243 self.PLOT_CODE = CROSS_CODE
278 self.PLOT_CODE = CROSS_CODE
244 self.FTP_WEI = None
279 self.FTP_WEI = None
245 self.EXP_CODE = None
280 self.EXP_CODE = None
246 self.SUB_EXP_CODE = None
281 self.SUB_EXP_CODE = None
247 self.PLOT_POS = None
282 self.PLOT_POS = None
248
283
249 def getSubplots(self):
284 def getSubplots(self):
250
285
251 ncol = 4
286 ncol = 4
252 nrow = self.nplots
287 nrow = self.nplots
253
288
254 return nrow, ncol
289 return nrow, ncol
255
290
256 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
291 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
257
292
258 self.__showprofile = showprofile
293 self.__showprofile = showprofile
259 self.nplots = nplots
294 self.nplots = nplots
260
295
261 ncolspan = 1
296 ncolspan = 1
262 colspan = 1
297 colspan = 1
263
298
264 self.createFigure(id = id,
299 self.createFigure(id = id,
265 wintitle = wintitle,
300 wintitle = wintitle,
266 widthplot = self.WIDTH + self.WIDTHPROF,
301 widthplot = self.WIDTH + self.WIDTHPROF,
267 heightplot = self.HEIGHT + self.HEIGHTPROF,
302 heightplot = self.HEIGHT + self.HEIGHTPROF,
268 show=True)
303 show=True)
269
304
270 nrow, ncol = self.getSubplots()
305 nrow, ncol = self.getSubplots()
271
306
272 counter = 0
307 counter = 0
273 for y in range(nrow):
308 for y in range(nrow):
274 for x in range(ncol):
309 for x in range(ncol):
275 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
310 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
276
311
277 counter += 1
312 counter += 1
278
313
279 def run(self, dataOut, id, wintitle="", pairsList=None,
314 def run(self, dataOut, id, wintitle="", pairsList=None,
280 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
315 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
281 coh_min=None, coh_max=None, phase_min=None, phase_max=None,
316 coh_min=None, coh_max=None, phase_min=None, phase_max=None,
282 save=False, figpath='./', figfile=None, ftp=False, wr_period=1,
317 save=False, figpath='./', figfile=None, ftp=False, wr_period=1,
283 power_cmap='jet', coherence_cmap='jet', phase_cmap='RdBu_r', show=True,
318 power_cmap='jet', coherence_cmap='jet', phase_cmap='RdBu_r', show=True,
284 server=None, folder=None, username=None, password=None,
319 server=None, folder=None, username=None, password=None,
285 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0,
320 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0,
286 xaxis='frequency'):
321 xaxis='frequency'):
287
322
288 """
323 """
289
324
290 Input:
325 Input:
291 dataOut :
326 dataOut :
292 id :
327 id :
293 wintitle :
328 wintitle :
294 channelList :
329 channelList :
295 showProfile :
330 showProfile :
296 xmin : None,
331 xmin : None,
297 xmax : None,
332 xmax : None,
298 ymin : None,
333 ymin : None,
299 ymax : None,
334 ymax : None,
300 zmin : None,
335 zmin : None,
301 zmax : None
336 zmax : None
302 """
337 """
303
338
304 if pairsList == None:
339 if pairsList == None:
305 pairsIndexList = dataOut.pairsIndexList
340 pairsIndexList = dataOut.pairsIndexList
306 else:
341 else:
307 pairsIndexList = []
342 pairsIndexList = []
308 for pair in pairsList:
343 for pair in pairsList:
309 if pair not in dataOut.pairsList:
344 if pair not in dataOut.pairsList:
310 raise ValueError, "Pair %s is not in dataOut.pairsList" %str(pair)
345 raise ValueError, "Pair %s is not in dataOut.pairsList" %str(pair)
311 pairsIndexList.append(dataOut.pairsList.index(pair))
346 pairsIndexList.append(dataOut.pairsList.index(pair))
312
347
313 if not pairsIndexList:
348 if not pairsIndexList:
314 return
349 return
315
350
316 if len(pairsIndexList) > 4:
351 if len(pairsIndexList) > 4:
317 pairsIndexList = pairsIndexList[0:4]
352 pairsIndexList = pairsIndexList[0:4]
318
353
319 factor = dataOut.normFactor
354 factor = dataOut.normFactor
320 x = dataOut.getVelRange(1)
355 x = dataOut.getVelRange(1)
321 y = dataOut.getHeiRange()
356 y = dataOut.getHeiRange()
322 z = dataOut.data_spc[:,:,:]/factor
357 z = dataOut.data_spc[:,:,:]/factor
323 z = numpy.where(numpy.isfinite(z), z, numpy.NAN)
358 z = numpy.where(numpy.isfinite(z), z, numpy.NAN)
324
359
325 noise = dataOut.noise/factor
360 noise = dataOut.noise/factor
326
361
327 zdB = 10*numpy.log10(z)
362 zdB = 10*numpy.log10(z)
328 noisedB = 10*numpy.log10(noise)
363 noisedB = 10*numpy.log10(noise)
329
364
330 if coh_min == None:
365 if coh_min == None:
331 coh_min = 0.0
366 coh_min = 0.0
332 if coh_max == None:
367 if coh_max == None:
333 coh_max = 1.0
368 coh_max = 1.0
334
369
335 if phase_min == None:
370 if phase_min == None:
336 phase_min = -180
371 phase_min = -180
337 if phase_max == None:
372 if phase_max == None:
338 phase_max = 180
373 phase_max = 180
339
374
340 #thisDatetime = dataOut.datatime
375 #thisDatetime = dataOut.datatime
341 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0])
376 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0])
342 title = wintitle + " Cross-Spectra: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
377 title = wintitle + " Cross-Spectra: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
343 # xlabel = "Velocity (m/s)"
378 # xlabel = "Velocity (m/s)"
344 ylabel = "Range (Km)"
379 ylabel = "Range (Km)"
345
380
346 if xaxis == "frequency":
381 if xaxis == "frequency":
347 x = dataOut.getFreqRange(1)/1000.
382 x = dataOut.getFreqRange(1)/1000.
348 xlabel = "Frequency (kHz)"
383 xlabel = "Frequency (kHz)"
349
384
350 elif xaxis == "time":
385 elif xaxis == "time":
351 x = dataOut.getAcfRange(1)
386 x = dataOut.getAcfRange(1)
352 xlabel = "Time (ms)"
387 xlabel = "Time (ms)"
353
388
354 else:
389 else:
355 x = dataOut.getVelRange(1)
390 x = dataOut.getVelRange(1)
356 xlabel = "Velocity (m/s)"
391 xlabel = "Velocity (m/s)"
357
392
358 if not self.isConfig:
393 if not self.isConfig:
359
394
360 nplots = len(pairsIndexList)
395 nplots = len(pairsIndexList)
361
396
362 self.setup(id=id,
397 self.setup(id=id,
363 nplots=nplots,
398 nplots=nplots,
364 wintitle=wintitle,
399 wintitle=wintitle,
365 showprofile=False,
400 showprofile=False,
366 show=show)
401 show=show)
367
402
368 avg = numpy.abs(numpy.average(z, axis=1))
403 avg = numpy.abs(numpy.average(z, axis=1))
369 avgdB = 10*numpy.log10(avg)
404 avgdB = 10*numpy.log10(avg)
370
405
371 if xmin == None: xmin = numpy.nanmin(x)
406 if xmin == None: xmin = numpy.nanmin(x)
372 if xmax == None: xmax = numpy.nanmax(x)
407 if xmax == None: xmax = numpy.nanmax(x)
373 if ymin == None: ymin = numpy.nanmin(y)
408 if ymin == None: ymin = numpy.nanmin(y)
374 if ymax == None: ymax = numpy.nanmax(y)
409 if ymax == None: ymax = numpy.nanmax(y)
375 if zmin == None: zmin = numpy.floor(numpy.nanmin(noisedB)) - 3
410 if zmin == None: zmin = numpy.floor(numpy.nanmin(noisedB)) - 3
376 if zmax == None: zmax = numpy.ceil(numpy.nanmax(avgdB)) + 3
411 if zmax == None: zmax = numpy.ceil(numpy.nanmax(avgdB)) + 3
377
412
378 self.FTP_WEI = ftp_wei
413 self.FTP_WEI = ftp_wei
379 self.EXP_CODE = exp_code
414 self.EXP_CODE = exp_code
380 self.SUB_EXP_CODE = sub_exp_code
415 self.SUB_EXP_CODE = sub_exp_code
381 self.PLOT_POS = plot_pos
416 self.PLOT_POS = plot_pos
382
417
383 self.isConfig = True
418 self.isConfig = True
384
419
385 self.setWinTitle(title)
420 self.setWinTitle(title)
386
421
387 for i in range(self.nplots):
422 for i in range(self.nplots):
388 pair = dataOut.pairsList[pairsIndexList[i]]
423 pair = dataOut.pairsList[pairsIndexList[i]]
389
424
390 chan_index0 = dataOut.channelList.index(pair[0])
425 chan_index0 = dataOut.channelList.index(pair[0])
391 chan_index1 = dataOut.channelList.index(pair[1])
426 chan_index1 = dataOut.channelList.index(pair[1])
392
427
393 str_datetime = '%s %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S"))
428 str_datetime = '%s %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S"))
394 title = "Ch%d: %4.2fdB: %s" %(pair[0], noisedB[chan_index0], str_datetime)
429 title = "Ch%d: %4.2fdB: %s" %(pair[0], noisedB[chan_index0], str_datetime)
395 zdB = 10.*numpy.log10(dataOut.data_spc[chan_index0,:,:]/factor)
430 zdB = 10.*numpy.log10(dataOut.data_spc[chan_index0,:,:]/factor)
396 axes0 = self.axesList[i*self.__nsubplots]
431 axes0 = self.axesList[i*self.__nsubplots]
397 axes0.pcolor(x, y, zdB,
432 axes0.pcolor(x, y, zdB,
398 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
433 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
399 xlabel=xlabel, ylabel=ylabel, title=title,
434 xlabel=xlabel, ylabel=ylabel, title=title,
400 ticksize=9, colormap=power_cmap, cblabel='')
435 ticksize=9, colormap=power_cmap, cblabel='')
401
436
402 title = "Ch%d: %4.2fdB: %s" %(pair[1], noisedB[chan_index1], str_datetime)
437 title = "Ch%d: %4.2fdB: %s" %(pair[1], noisedB[chan_index1], str_datetime)
403 zdB = 10.*numpy.log10(dataOut.data_spc[chan_index1,:,:]/factor)
438 zdB = 10.*numpy.log10(dataOut.data_spc[chan_index1,:,:]/factor)
404 axes0 = self.axesList[i*self.__nsubplots+1]
439 axes0 = self.axesList[i*self.__nsubplots+1]
405 axes0.pcolor(x, y, zdB,
440 axes0.pcolor(x, y, zdB,
406 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
441 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
407 xlabel=xlabel, ylabel=ylabel, title=title,
442 xlabel=xlabel, ylabel=ylabel, title=title,
408 ticksize=9, colormap=power_cmap, cblabel='')
443 ticksize=9, colormap=power_cmap, cblabel='')
409
444
410 coherenceComplex = dataOut.data_cspc[pairsIndexList[i],:,:]/numpy.sqrt(dataOut.data_spc[chan_index0,:,:]*dataOut.data_spc[chan_index1,:,:])
445 coherenceComplex = dataOut.data_cspc[pairsIndexList[i],:,:]/numpy.sqrt(dataOut.data_spc[chan_index0,:,:]*dataOut.data_spc[chan_index1,:,:])
411 coherence = numpy.abs(coherenceComplex)
446 coherence = numpy.abs(coherenceComplex)
412 # phase = numpy.arctan(-1*coherenceComplex.imag/coherenceComplex.real)*180/numpy.pi
447 # phase = numpy.arctan(-1*coherenceComplex.imag/coherenceComplex.real)*180/numpy.pi
413 phase = numpy.arctan2(coherenceComplex.imag, coherenceComplex.real)*180/numpy.pi
448 phase = numpy.arctan2(coherenceComplex.imag, coherenceComplex.real)*180/numpy.pi
414
449
415 title = "Coherence Ch%d * Ch%d" %(pair[0], pair[1])
450 title = "Coherence Ch%d * Ch%d" %(pair[0], pair[1])
416 axes0 = self.axesList[i*self.__nsubplots+2]
451 axes0 = self.axesList[i*self.__nsubplots+2]
417 axes0.pcolor(x, y, coherence,
452 axes0.pcolor(x, y, coherence,
418 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=coh_min, zmax=coh_max,
453 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=coh_min, zmax=coh_max,
419 xlabel=xlabel, ylabel=ylabel, title=title,
454 xlabel=xlabel, ylabel=ylabel, title=title,
420 ticksize=9, colormap=coherence_cmap, cblabel='')
455 ticksize=9, colormap=coherence_cmap, cblabel='')
421
456
422 title = "Phase Ch%d * Ch%d" %(pair[0], pair[1])
457 title = "Phase Ch%d * Ch%d" %(pair[0], pair[1])
423 axes0 = self.axesList[i*self.__nsubplots+3]
458 axes0 = self.axesList[i*self.__nsubplots+3]
424 axes0.pcolor(x, y, phase,
459 axes0.pcolor(x, y, phase,
425 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=phase_min, zmax=phase_max,
460 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=phase_min, zmax=phase_max,
426 xlabel=xlabel, ylabel=ylabel, title=title,
461 xlabel=xlabel, ylabel=ylabel, title=title,
427 ticksize=9, colormap=phase_cmap, cblabel='')
462 ticksize=9, colormap=phase_cmap, cblabel='')
428
463
429
464
430
465
431 self.draw()
466 self.draw()
432
467
433 self.save(figpath=figpath,
468 self.save(figpath=figpath,
434 figfile=figfile,
469 figfile=figfile,
435 save=save,
470 save=save,
436 ftp=ftp,
471 ftp=ftp,
437 wr_period=wr_period,
472 wr_period=wr_period,
438 thisDatetime=thisDatetime)
473 thisDatetime=thisDatetime)
439
474
440
475
441 class RTIPlot(Figure):
476 class RTIPlot(Figure):
442
477
443 __isConfig = None
478 __isConfig = None
444 __nsubplots = None
479 __nsubplots = None
445
480
446 WIDTHPROF = None
481 WIDTHPROF = None
447 HEIGHTPROF = None
482 HEIGHTPROF = None
448 PREFIX = 'rti'
483 PREFIX = 'rti'
449
484
450 def __init__(self, **kwargs):
485 def __init__(self, **kwargs):
451
486
452 Figure.__init__(self, **kwargs)
487 Figure.__init__(self, **kwargs)
453 self.timerange = None
488 self.timerange = None
454 self.isConfig = False
489 self.isConfig = False
455 self.__nsubplots = 1
490 self.__nsubplots = 1
456
491
457 self.WIDTH = 800
492 self.WIDTH = 800
458 self.HEIGHT = 180
493 self.HEIGHT = 180
459 self.WIDTHPROF = 120
494 self.WIDTHPROF = 120
460 self.HEIGHTPROF = 0
495 self.HEIGHTPROF = 0
461 self.counter_imagwr = 0
496 self.counter_imagwr = 0
462
497
463 self.PLOT_CODE = RTI_CODE
498 self.PLOT_CODE = RTI_CODE
464
499
465 self.FTP_WEI = None
500 self.FTP_WEI = None
466 self.EXP_CODE = None
501 self.EXP_CODE = None
467 self.SUB_EXP_CODE = None
502 self.SUB_EXP_CODE = None
468 self.PLOT_POS = None
503 self.PLOT_POS = None
469 self.tmin = None
504 self.tmin = None
470 self.tmax = None
505 self.tmax = None
471
506
472 self.xmin = None
507 self.xmin = None
473 self.xmax = None
508 self.xmax = None
474
509
475 self.figfile = None
510 self.figfile = None
476
511
477 def getSubplots(self):
512 def getSubplots(self):
478
513
479 ncol = 1
514 ncol = 1
480 nrow = self.nplots
515 nrow = self.nplots
481
516
482 return nrow, ncol
517 return nrow, ncol
483
518
484 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
519 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
485
520
486 self.__showprofile = showprofile
521 self.__showprofile = showprofile
487 self.nplots = nplots
522 self.nplots = nplots
488
523
489 ncolspan = 1
524 ncolspan = 1
490 colspan = 1
525 colspan = 1
491 if showprofile:
526 if showprofile:
492 ncolspan = 7
527 ncolspan = 7
493 colspan = 6
528 colspan = 6
494 self.__nsubplots = 2
529 self.__nsubplots = 2
495
530
496 self.createFigure(id = id,
531 self.createFigure(id = id,
497 wintitle = wintitle,
532 wintitle = wintitle,
498 widthplot = self.WIDTH + self.WIDTHPROF,
533 widthplot = self.WIDTH + self.WIDTHPROF,
499 heightplot = self.HEIGHT + self.HEIGHTPROF,
534 heightplot = self.HEIGHT + self.HEIGHTPROF,
500 show=show)
535 show=show)
501
536
502 nrow, ncol = self.getSubplots()
537 nrow, ncol = self.getSubplots()
503
538
504 counter = 0
539 counter = 0
505 for y in range(nrow):
540 for y in range(nrow):
506 for x in range(ncol):
541 for x in range(ncol):
507
542
508 if counter >= self.nplots:
543 if counter >= self.nplots:
509 break
544 break
510
545
511 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
546 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
512
547
513 if showprofile:
548 if showprofile:
514 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1)
549 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1)
515
550
516 counter += 1
551 counter += 1
517
552
518 def run(self, dataOut, id, wintitle="", channelList=None, showprofile='True',
553 def run(self, dataOut, id, wintitle="", channelList=None, showprofile='True',
519 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
554 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
520 timerange=None,
555 timerange=None,
521 save=False, figpath='./', lastone=0,figfile=None, ftp=False, wr_period=1, show=True,
556 save=False, figpath='./', lastone=0,figfile=None, ftp=False, wr_period=1, show=True,
522 server=None, folder=None, username=None, password=None,
557 server=None, folder=None, username=None, password=None,
523 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0, **kwargs):
558 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0, **kwargs):
524
559
525 """
560 """
526
561
527 Input:
562 Input:
528 dataOut :
563 dataOut :
529 id :
564 id :
530 wintitle :
565 wintitle :
531 channelList :
566 channelList :
532 showProfile :
567 showProfile :
533 xmin : None,
568 xmin : None,
534 xmax : None,
569 xmax : None,
535 ymin : None,
570 ymin : None,
536 ymax : None,
571 ymax : None,
537 zmin : None,
572 zmin : None,
538 zmax : None
573 zmax : None
539 """
574 """
540
575
541 colormap = kwargs.get('colormap', 'jet')
576 colormap = kwargs.get('colormap', 'jet')
542 if not isTimeInHourRange(dataOut.datatime, xmin, xmax):
577 if not isTimeInHourRange(dataOut.datatime, xmin, xmax):
543 return
578 return
544
579
545 if channelList == None:
580 if channelList == None:
546 channelIndexList = dataOut.channelIndexList
581 channelIndexList = dataOut.channelIndexList
547 else:
582 else:
548 channelIndexList = []
583 channelIndexList = []
549 for channel in channelList:
584 for channel in channelList:
550 if channel not in dataOut.channelList:
585 if channel not in dataOut.channelList:
551 raise ValueError, "Channel %d is not in dataOut.channelList"
586 raise ValueError, "Channel %d is not in dataOut.channelList"
552 channelIndexList.append(dataOut.channelList.index(channel))
587 channelIndexList.append(dataOut.channelList.index(channel))
553
588
554 if hasattr(dataOut, 'normFactor'):
589 if hasattr(dataOut, 'normFactor'):
555 factor = dataOut.normFactor
590 factor = dataOut.normFactor
556 else:
591 else:
557 factor = 1
592 factor = 1
558
593
559 # factor = dataOut.normFactor
594 # factor = dataOut.normFactor
560 x = dataOut.getTimeRange()
595 x = dataOut.getTimeRange()
561 y = dataOut.getHeiRange()
596 y = dataOut.getHeiRange()
562
597
563 # z = dataOut.data_spc/factor
598 # z = dataOut.data_spc/factor
564 # z = numpy.where(numpy.isfinite(z), z, numpy.NAN)
599 # z = numpy.where(numpy.isfinite(z), z, numpy.NAN)
565 # avg = numpy.average(z, axis=1)
600 # avg = numpy.average(z, axis=1)
566 # avgdB = 10.*numpy.log10(avg)
601 # avgdB = 10.*numpy.log10(avg)
567 avgdB = dataOut.getPower()
602 avgdB = dataOut.getPower()
568
603
569 thisDatetime = dataOut.datatime
604 thisDatetime = dataOut.datatime
570 # thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0])
605 # thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0])
571 title = wintitle + " RTI" #: %s" %(thisDatetime.strftime("%d-%b-%Y"))
606 title = wintitle + " RTI" #: %s" %(thisDatetime.strftime("%d-%b-%Y"))
572 xlabel = ""
607 xlabel = ""
573 ylabel = "Range (Km)"
608 ylabel = "Range (Km)"
574
609
575 update_figfile = False
610 update_figfile = False
576
611
577 if dataOut.ltctime >= self.xmax:
612 if dataOut.ltctime >= self.xmax:
578 self.counter_imagwr = wr_period
613 self.counter_imagwr = wr_period
579 self.isConfig = False
614 self.isConfig = False
580 update_figfile = True
615 update_figfile = True
581
616
582 if not self.isConfig:
617 if not self.isConfig:
583
618
584 nplots = len(channelIndexList)
619 nplots = len(channelIndexList)
585
620
586 self.setup(id=id,
621 self.setup(id=id,
587 nplots=nplots,
622 nplots=nplots,
588 wintitle=wintitle,
623 wintitle=wintitle,
589 showprofile=showprofile,
624 showprofile=showprofile,
590 show=show)
625 show=show)
591
626
592 if timerange != None:
627 if timerange != None:
593 self.timerange = timerange
628 self.timerange = timerange
594
629
595 self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange)
630 self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange)
596
631
597 noise = dataOut.noise/factor
632 noise = dataOut.noise/factor
598 noisedB = 10*numpy.log10(noise)
633 noisedB = 10*numpy.log10(noise)
599
634
600 if ymin == None: ymin = numpy.nanmin(y)
635 if ymin == None: ymin = numpy.nanmin(y)
601 if ymax == None: ymax = numpy.nanmax(y)
636 if ymax == None: ymax = numpy.nanmax(y)
602 if zmin == None: zmin = numpy.floor(numpy.nanmin(noisedB)) - 3
637 if zmin == None: zmin = numpy.floor(numpy.nanmin(noisedB)) - 3
603 if zmax == None: zmax = numpy.ceil(numpy.nanmax(avgdB)) + 3
638 if zmax == None: zmax = numpy.ceil(numpy.nanmax(avgdB)) + 3
604
639
605 self.FTP_WEI = ftp_wei
640 self.FTP_WEI = ftp_wei
606 self.EXP_CODE = exp_code
641 self.EXP_CODE = exp_code
607 self.SUB_EXP_CODE = sub_exp_code
642 self.SUB_EXP_CODE = sub_exp_code
608 self.PLOT_POS = plot_pos
643 self.PLOT_POS = plot_pos
609
644
610 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
645 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
611 self.isConfig = True
646 self.isConfig = True
612 self.figfile = figfile
647 self.figfile = figfile
613 update_figfile = True
648 update_figfile = True
614
649
615 self.setWinTitle(title)
650 self.setWinTitle(title)
616
651
617 for i in range(self.nplots):
652 for i in range(self.nplots):
618 index = channelIndexList[i]
653 index = channelIndexList[i]
619 title = "Channel %d: %s" %(dataOut.channelList[index], thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
654 title = "Channel %d: %s" %(dataOut.channelList[index], thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
620 if ((dataOut.azimuth!=None) and (dataOut.zenith!=None)):
655 if ((dataOut.azimuth!=None) and (dataOut.zenith!=None)):
621 title = title + '_' + 'azimuth,zenith=%2.2f,%2.2f'%(dataOut.azimuth, dataOut.zenith)
656 title = title + '_' + 'azimuth,zenith=%2.2f,%2.2f'%(dataOut.azimuth, dataOut.zenith)
622 axes = self.axesList[i*self.__nsubplots]
657 axes = self.axesList[i*self.__nsubplots]
623 zdB = avgdB[index].reshape((1,-1))
658 zdB = avgdB[index].reshape((1,-1))
624 axes.pcolorbuffer(x, y, zdB,
659 axes.pcolorbuffer(x, y, zdB,
625 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
660 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
626 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
661 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
627 ticksize=9, cblabel='', cbsize="1%", colormap=colormap)
662 ticksize=9, cblabel='', cbsize="1%", colormap=colormap)
628
663
629 if self.__showprofile:
664 if self.__showprofile:
630 axes = self.axesList[i*self.__nsubplots +1]
665 axes = self.axesList[i*self.__nsubplots +1]
631 axes.pline(avgdB[index], y,
666 axes.pline(avgdB[index], y,
632 xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax,
667 xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax,
633 xlabel='dB', ylabel='', title='',
668 xlabel='dB', ylabel='', title='',
634 ytick_visible=False,
669 ytick_visible=False,
635 grid='x')
670 grid='x')
636
671
637 self.draw()
672 self.draw()
638
673
639 self.save(figpath=figpath,
674 self.save(figpath=figpath,
640 figfile=figfile,
675 figfile=figfile,
641 save=save,
676 save=save,
642 ftp=ftp,
677 ftp=ftp,
643 wr_period=wr_period,
678 wr_period=wr_period,
644 thisDatetime=thisDatetime,
679 thisDatetime=thisDatetime,
645 update_figfile=update_figfile)
680 update_figfile=update_figfile)
646
681
647 class CoherenceMap(Figure):
682 class CoherenceMap(Figure):
648 isConfig = None
683 isConfig = None
649 __nsubplots = None
684 __nsubplots = None
650
685
651 WIDTHPROF = None
686 WIDTHPROF = None
652 HEIGHTPROF = None
687 HEIGHTPROF = None
653 PREFIX = 'cmap'
688 PREFIX = 'cmap'
654
689
690 parameters = {
691 'id': 'string',
692 'wintitle': 'string',
693 'pairsList': 'pairsLists',
694 'showprofile': 'boolean',
695 'xmin': 'float',
696 'xmax': 'float',
697 'ymin': 'float',
698 'ymax': 'float',
699 'zmin': 'float',
700 'zmax': 'float',
701 'timerange': 'float',
702 'phase_min': 'float',
703 'phase_max': 'float',
704 'save': 'boolean',
705 'figpath': 'string',
706 'figfile': 'string',
707 'ftp': 'boolean',
708 'wr_period': 'int',
709 'coherence_cmap': 'colormap',
710 'phase_cmap': 'colormap',
711 'show': 'boolean',
712 'server': 'string',
713 'folder': 'string',
714 'username': 'string',
715 'password': 'string',
716 'ftp_wei': 'int',
717 'exp_code': 'int',
718 'sub_exp_code': 'int',
719 'plot_pos': 'int',
720 }
721
655 def __init__(self, **kwargs):
722 def __init__(self, **kwargs):
656 Figure.__init__(self, **kwargs)
723 Figure.__init__(self, **kwargs)
657 self.timerange = 2*60*60
724 self.timerange = 2*60*60
658 self.isConfig = False
725 self.isConfig = False
659 self.__nsubplots = 1
726 self.__nsubplots = 1
660
727
661 self.WIDTH = 800
728 self.WIDTH = 800
662 self.HEIGHT = 180
729 self.HEIGHT = 180
663 self.WIDTHPROF = 120
730 self.WIDTHPROF = 120
664 self.HEIGHTPROF = 0
731 self.HEIGHTPROF = 0
665 self.counter_imagwr = 0
732 self.counter_imagwr = 0
666
733
667 self.PLOT_CODE = COH_CODE
734 self.PLOT_CODE = COH_CODE
668
735
669 self.FTP_WEI = None
736 self.FTP_WEI = None
670 self.EXP_CODE = None
737 self.EXP_CODE = None
671 self.SUB_EXP_CODE = None
738 self.SUB_EXP_CODE = None
672 self.PLOT_POS = None
739 self.PLOT_POS = None
673 self.counter_imagwr = 0
740 self.counter_imagwr = 0
674
741
675 self.xmin = None
742 self.xmin = None
676 self.xmax = None
743 self.xmax = None
677
744
678 def getSubplots(self):
745 def getSubplots(self):
679 ncol = 1
746 ncol = 1
680 nrow = self.nplots*2
747 nrow = self.nplots*2
681
748
682 return nrow, ncol
749 return nrow, ncol
683
750
684 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
751 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
685 self.__showprofile = showprofile
752 self.__showprofile = showprofile
686 self.nplots = nplots
753 self.nplots = nplots
687
754
688 ncolspan = 1
755 ncolspan = 1
689 colspan = 1
756 colspan = 1
690 if showprofile:
757 if showprofile:
691 ncolspan = 7
758 ncolspan = 7
692 colspan = 6
759 colspan = 6
693 self.__nsubplots = 2
760 self.__nsubplots = 2
694
761
695 self.createFigure(id = id,
762 self.createFigure(id = id,
696 wintitle = wintitle,
763 wintitle = wintitle,
697 widthplot = self.WIDTH + self.WIDTHPROF,
764 widthplot = self.WIDTH + self.WIDTHPROF,
698 heightplot = self.HEIGHT + self.HEIGHTPROF,
765 heightplot = self.HEIGHT + self.HEIGHTPROF,
699 show=True)
766 show=True)
700
767
701 nrow, ncol = self.getSubplots()
768 nrow, ncol = self.getSubplots()
702
769
703 for y in range(nrow):
770 for y in range(nrow):
704 for x in range(ncol):
771 for x in range(ncol):
705
772
706 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
773 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
707
774
708 if showprofile:
775 if showprofile:
709 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1)
776 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1)
710
777
711 def run(self, dataOut, id, wintitle="", pairsList=None, showprofile='True',
778 def run(self, dataOut, id, wintitle="", pairsList=None, showprofile='True',
712 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
779 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
713 timerange=None, phase_min=None, phase_max=None,
780 timerange=None, phase_min=None, phase_max=None,
714 save=False, figpath='./', figfile=None, ftp=False, wr_period=1,
781 save=False, figpath='./', figfile=None, ftp=False, wr_period=1,
715 coherence_cmap='jet', phase_cmap='RdBu_r', show=True,
782 coherence_cmap='jet', phase_cmap='RdBu_r', show=True,
716 server=None, folder=None, username=None, password=None,
783 server=None, folder=None, username=None, password=None,
717 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0):
784 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0):
718
785
719 if not isTimeInHourRange(dataOut.datatime, xmin, xmax):
786 if not isTimeInHourRange(dataOut.datatime, xmin, xmax):
720 return
787 return
721
788
722 if pairsList == None:
789 if pairsList == None:
723 pairsIndexList = dataOut.pairsIndexList
790 pairsIndexList = dataOut.pairsIndexList
724 else:
791 else:
725 pairsIndexList = []
792 pairsIndexList = []
726 for pair in pairsList:
793 for pair in pairsList:
727 if pair not in dataOut.pairsList:
794 if pair not in dataOut.pairsList:
728 raise ValueError, "Pair %s is not in dataOut.pairsList" %(pair)
795 raise ValueError, "Pair %s is not in dataOut.pairsList" %(pair)
729 pairsIndexList.append(dataOut.pairsList.index(pair))
796 pairsIndexList.append(dataOut.pairsList.index(pair))
730
797
731 if pairsIndexList == []:
798 if pairsIndexList == []:
732 return
799 return
733
800
734 if len(pairsIndexList) > 4:
801 if len(pairsIndexList) > 4:
735 pairsIndexList = pairsIndexList[0:4]
802 pairsIndexList = pairsIndexList[0:4]
736
803
737 if phase_min == None:
804 if phase_min == None:
738 phase_min = -180
805 phase_min = -180
739 if phase_max == None:
806 if phase_max == None:
740 phase_max = 180
807 phase_max = 180
741
808
742 x = dataOut.getTimeRange()
809 x = dataOut.getTimeRange()
743 y = dataOut.getHeiRange()
810 y = dataOut.getHeiRange()
744
811
745 thisDatetime = dataOut.datatime
812 thisDatetime = dataOut.datatime
746
813
747 title = wintitle + " CoherenceMap" #: %s" %(thisDatetime.strftime("%d-%b-%Y"))
814 title = wintitle + " CoherenceMap" #: %s" %(thisDatetime.strftime("%d-%b-%Y"))
748 xlabel = ""
815 xlabel = ""
749 ylabel = "Range (Km)"
816 ylabel = "Range (Km)"
750 update_figfile = False
817 update_figfile = False
751
818
752 if not self.isConfig:
819 if not self.isConfig:
753 nplots = len(pairsIndexList)
820 nplots = len(pairsIndexList)
754 self.setup(id=id,
821 self.setup(id=id,
755 nplots=nplots,
822 nplots=nplots,
756 wintitle=wintitle,
823 wintitle=wintitle,
757 showprofile=showprofile,
824 showprofile=showprofile,
758 show=show)
825 show=show)
759
826
760 if timerange != None:
827 if timerange != None:
761 self.timerange = timerange
828 self.timerange = timerange
762
829
763 self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange)
830 self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange)
764
831
765 if ymin == None: ymin = numpy.nanmin(y)
832 if ymin == None: ymin = numpy.nanmin(y)
766 if ymax == None: ymax = numpy.nanmax(y)
833 if ymax == None: ymax = numpy.nanmax(y)
767 if zmin == None: zmin = 0.
834 if zmin == None: zmin = 0.
768 if zmax == None: zmax = 1.
835 if zmax == None: zmax = 1.
769
836
770 self.FTP_WEI = ftp_wei
837 self.FTP_WEI = ftp_wei
771 self.EXP_CODE = exp_code
838 self.EXP_CODE = exp_code
772 self.SUB_EXP_CODE = sub_exp_code
839 self.SUB_EXP_CODE = sub_exp_code
773 self.PLOT_POS = plot_pos
840 self.PLOT_POS = plot_pos
774
841
775 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
842 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
776
843
777 self.isConfig = True
844 self.isConfig = True
778 update_figfile = True
845 update_figfile = True
779
846
780 self.setWinTitle(title)
847 self.setWinTitle(title)
781
848
782 for i in range(self.nplots):
849 for i in range(self.nplots):
783
850
784 pair = dataOut.pairsList[pairsIndexList[i]]
851 pair = dataOut.pairsList[pairsIndexList[i]]
785
852
786 ccf = numpy.average(dataOut.data_cspc[pairsIndexList[i],:,:],axis=0)
853 ccf = numpy.average(dataOut.data_cspc[pairsIndexList[i],:,:],axis=0)
787 powa = numpy.average(dataOut.data_spc[pair[0],:,:],axis=0)
854 powa = numpy.average(dataOut.data_spc[pair[0],:,:],axis=0)
788 powb = numpy.average(dataOut.data_spc[pair[1],:,:],axis=0)
855 powb = numpy.average(dataOut.data_spc[pair[1],:,:],axis=0)
789
856
790
857
791 avgcoherenceComplex = ccf/numpy.sqrt(powa*powb)
858 avgcoherenceComplex = ccf/numpy.sqrt(powa*powb)
792 coherence = numpy.abs(avgcoherenceComplex)
859 coherence = numpy.abs(avgcoherenceComplex)
793
860
794 z = coherence.reshape((1,-1))
861 z = coherence.reshape((1,-1))
795
862
796 counter = 0
863 counter = 0
797
864
798 title = "Coherence Ch%d * Ch%d: %s" %(pair[0], pair[1], thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
865 title = "Coherence Ch%d * Ch%d: %s" %(pair[0], pair[1], thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
799 axes = self.axesList[i*self.__nsubplots*2]
866 axes = self.axesList[i*self.__nsubplots*2]
800 axes.pcolorbuffer(x, y, z,
867 axes.pcolorbuffer(x, y, z,
801 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
868 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
802 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
869 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
803 ticksize=9, cblabel='', colormap=coherence_cmap, cbsize="1%")
870 ticksize=9, cblabel='', colormap=coherence_cmap, cbsize="1%")
804
871
805 if self.__showprofile:
872 if self.__showprofile:
806 counter += 1
873 counter += 1
807 axes = self.axesList[i*self.__nsubplots*2 + counter]
874 axes = self.axesList[i*self.__nsubplots*2 + counter]
808 axes.pline(coherence, y,
875 axes.pline(coherence, y,
809 xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax,
876 xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax,
810 xlabel='', ylabel='', title='', ticksize=7,
877 xlabel='', ylabel='', title='', ticksize=7,
811 ytick_visible=False, nxticks=5,
878 ytick_visible=False, nxticks=5,
812 grid='x')
879 grid='x')
813
880
814 counter += 1
881 counter += 1
815
882
816 phase = numpy.arctan2(avgcoherenceComplex.imag, avgcoherenceComplex.real)*180/numpy.pi
883 phase = numpy.arctan2(avgcoherenceComplex.imag, avgcoherenceComplex.real)*180/numpy.pi
817
884
818 z = phase.reshape((1,-1))
885 z = phase.reshape((1,-1))
819
886
820 title = "Phase Ch%d * Ch%d: %s" %(pair[0], pair[1], thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
887 title = "Phase Ch%d * Ch%d: %s" %(pair[0], pair[1], thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
821 axes = self.axesList[i*self.__nsubplots*2 + counter]
888 axes = self.axesList[i*self.__nsubplots*2 + counter]
822 axes.pcolorbuffer(x, y, z,
889 axes.pcolorbuffer(x, y, z,
823 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=phase_min, zmax=phase_max,
890 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=phase_min, zmax=phase_max,
824 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
891 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
825 ticksize=9, cblabel='', colormap=phase_cmap, cbsize="1%")
892 ticksize=9, cblabel='', colormap=phase_cmap, cbsize="1%")
826
893
827 if self.__showprofile:
894 if self.__showprofile:
828 counter += 1
895 counter += 1
829 axes = self.axesList[i*self.__nsubplots*2 + counter]
896 axes = self.axesList[i*self.__nsubplots*2 + counter]
830 axes.pline(phase, y,
897 axes.pline(phase, y,
831 xmin=phase_min, xmax=phase_max, ymin=ymin, ymax=ymax,
898 xmin=phase_min, xmax=phase_max, ymin=ymin, ymax=ymax,
832 xlabel='', ylabel='', title='', ticksize=7,
899 xlabel='', ylabel='', title='', ticksize=7,
833 ytick_visible=False, nxticks=4,
900 ytick_visible=False, nxticks=4,
834 grid='x')
901 grid='x')
835
902
836 self.draw()
903 self.draw()
837
904
838 if dataOut.ltctime >= self.xmax:
905 if dataOut.ltctime >= self.xmax:
839 self.counter_imagwr = wr_period
906 self.counter_imagwr = wr_period
840 self.isConfig = False
907 self.isConfig = False
841 update_figfile = True
908 update_figfile = True
842
909
843 self.save(figpath=figpath,
910 self.save(figpath=figpath,
844 figfile=figfile,
911 figfile=figfile,
845 save=save,
912 save=save,
846 ftp=ftp,
913 ftp=ftp,
847 wr_period=wr_period,
914 wr_period=wr_period,
848 thisDatetime=thisDatetime,
915 thisDatetime=thisDatetime,
849 update_figfile=update_figfile)
916 update_figfile=update_figfile)
850
917
851 class PowerProfilePlot(Figure):
918 class PowerProfilePlot(Figure):
852
919
853 isConfig = None
920 isConfig = None
854 __nsubplots = None
921 __nsubplots = None
855
922
856 WIDTHPROF = None
923 WIDTHPROF = None
857 HEIGHTPROF = None
924 HEIGHTPROF = None
858 PREFIX = 'spcprofile'
925 PREFIX = 'spcprofile'
859
926
860 def __init__(self, **kwargs):
927 def __init__(self, **kwargs):
861 Figure.__init__(self, **kwargs)
928 Figure.__init__(self, **kwargs)
862 self.isConfig = False
929 self.isConfig = False
863 self.__nsubplots = 1
930 self.__nsubplots = 1
864
931
865 self.PLOT_CODE = POWER_CODE
932 self.PLOT_CODE = POWER_CODE
866
933
867 self.WIDTH = 300
934 self.WIDTH = 300
868 self.HEIGHT = 500
935 self.HEIGHT = 500
869 self.counter_imagwr = 0
936 self.counter_imagwr = 0
870
937
871 def getSubplots(self):
938 def getSubplots(self):
872 ncol = 1
939 ncol = 1
873 nrow = 1
940 nrow = 1
874
941
875 return nrow, ncol
942 return nrow, ncol
876
943
877 def setup(self, id, nplots, wintitle, show):
944 def setup(self, id, nplots, wintitle, show):
878
945
879 self.nplots = nplots
946 self.nplots = nplots
880
947
881 ncolspan = 1
948 ncolspan = 1
882 colspan = 1
949 colspan = 1
883
950
884 self.createFigure(id = id,
951 self.createFigure(id = id,
885 wintitle = wintitle,
952 wintitle = wintitle,
886 widthplot = self.WIDTH,
953 widthplot = self.WIDTH,
887 heightplot = self.HEIGHT,
954 heightplot = self.HEIGHT,
888 show=show)
955 show=show)
889
956
890 nrow, ncol = self.getSubplots()
957 nrow, ncol = self.getSubplots()
891
958
892 counter = 0
959 counter = 0
893 for y in range(nrow):
960 for y in range(nrow):
894 for x in range(ncol):
961 for x in range(ncol):
895 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
962 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
896
963
897 def run(self, dataOut, id, wintitle="", channelList=None,
964 def run(self, dataOut, id, wintitle="", channelList=None,
898 xmin=None, xmax=None, ymin=None, ymax=None,
965 xmin=None, xmax=None, ymin=None, ymax=None,
899 save=False, figpath='./', figfile=None, show=True,
966 save=False, figpath='./', figfile=None, show=True,
900 ftp=False, wr_period=1, server=None,
967 ftp=False, wr_period=1, server=None,
901 folder=None, username=None, password=None):
968 folder=None, username=None, password=None):
902
969
903
970
904 if channelList == None:
971 if channelList == None:
905 channelIndexList = dataOut.channelIndexList
972 channelIndexList = dataOut.channelIndexList
906 channelList = dataOut.channelList
973 channelList = dataOut.channelList
907 else:
974 else:
908 channelIndexList = []
975 channelIndexList = []
909 for channel in channelList:
976 for channel in channelList:
910 if channel not in dataOut.channelList:
977 if channel not in dataOut.channelList:
911 raise ValueError, "Channel %d is not in dataOut.channelList"
978 raise ValueError, "Channel %d is not in dataOut.channelList"
912 channelIndexList.append(dataOut.channelList.index(channel))
979 channelIndexList.append(dataOut.channelList.index(channel))
913
980
914 factor = dataOut.normFactor
981 factor = dataOut.normFactor
915
982
916 y = dataOut.getHeiRange()
983 y = dataOut.getHeiRange()
917
984
918 #for voltage
985 #for voltage
919 if dataOut.type == 'Voltage':
986 if dataOut.type == 'Voltage':
920 x = dataOut.data[channelIndexList,:] * numpy.conjugate(dataOut.data[channelIndexList,:])
987 x = dataOut.data[channelIndexList,:] * numpy.conjugate(dataOut.data[channelIndexList,:])
921 x = x.real
988 x = x.real
922 x = numpy.where(numpy.isfinite(x), x, numpy.NAN)
989 x = numpy.where(numpy.isfinite(x), x, numpy.NAN)
923
990
924 #for spectra
991 #for spectra
925 if dataOut.type == 'Spectra':
992 if dataOut.type == 'Spectra':
926 x = dataOut.data_spc[channelIndexList,:,:]/factor
993 x = dataOut.data_spc[channelIndexList,:,:]/factor
927 x = numpy.where(numpy.isfinite(x), x, numpy.NAN)
994 x = numpy.where(numpy.isfinite(x), x, numpy.NAN)
928 x = numpy.average(x, axis=1)
995 x = numpy.average(x, axis=1)
929
996
930
997
931 xdB = 10*numpy.log10(x)
998 xdB = 10*numpy.log10(x)
932
999
933 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0])
1000 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0])
934 title = wintitle + " Power Profile %s" %(thisDatetime.strftime("%d-%b-%Y"))
1001 title = wintitle + " Power Profile %s" %(thisDatetime.strftime("%d-%b-%Y"))
935 xlabel = "dB"
1002 xlabel = "dB"
936 ylabel = "Range (Km)"
1003 ylabel = "Range (Km)"
937
1004
938 if not self.isConfig:
1005 if not self.isConfig:
939
1006
940 nplots = 1
1007 nplots = 1
941
1008
942 self.setup(id=id,
1009 self.setup(id=id,
943 nplots=nplots,
1010 nplots=nplots,
944 wintitle=wintitle,
1011 wintitle=wintitle,
945 show=show)
1012 show=show)
946
1013
947 if ymin == None: ymin = numpy.nanmin(y)
1014 if ymin == None: ymin = numpy.nanmin(y)
948 if ymax == None: ymax = numpy.nanmax(y)
1015 if ymax == None: ymax = numpy.nanmax(y)
949 if xmin == None: xmin = numpy.nanmin(xdB)*0.9
1016 if xmin == None: xmin = numpy.nanmin(xdB)*0.9
950 if xmax == None: xmax = numpy.nanmax(xdB)*1.1
1017 if xmax == None: xmax = numpy.nanmax(xdB)*1.1
951
1018
952 self.isConfig = True
1019 self.isConfig = True
953
1020
954 self.setWinTitle(title)
1021 self.setWinTitle(title)
955
1022
956 title = "Power Profile: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
1023 title = "Power Profile: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
957 axes = self.axesList[0]
1024 axes = self.axesList[0]
958
1025
959 legendlabels = ["channel %d"%x for x in channelList]
1026 legendlabels = ["channel %d"%x for x in channelList]
960 axes.pmultiline(xdB, y,
1027 axes.pmultiline(xdB, y,
961 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax,
1028 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax,
962 xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels,
1029 xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels,
963 ytick_visible=True, nxticks=5,
1030 ytick_visible=True, nxticks=5,
964 grid='x')
1031 grid='x')
965
1032
966 self.draw()
1033 self.draw()
967
1034
968 self.save(figpath=figpath,
1035 self.save(figpath=figpath,
969 figfile=figfile,
1036 figfile=figfile,
970 save=save,
1037 save=save,
971 ftp=ftp,
1038 ftp=ftp,
972 wr_period=wr_period,
1039 wr_period=wr_period,
973 thisDatetime=thisDatetime)
1040 thisDatetime=thisDatetime)
974
1041
975 class SpectraCutPlot(Figure):
1042 class SpectraCutPlot(Figure):
976
1043
977 isConfig = None
1044 isConfig = None
978 __nsubplots = None
1045 __nsubplots = None
979
1046
980 WIDTHPROF = None
1047 WIDTHPROF = None
981 HEIGHTPROF = None
1048 HEIGHTPROF = None
982 PREFIX = 'spc_cut'
1049 PREFIX = 'spc_cut'
983
1050
984 def __init__(self, **kwargs):
1051 def __init__(self, **kwargs):
985 Figure.__init__(self, **kwargs)
1052 Figure.__init__(self, **kwargs)
986 self.isConfig = False
1053 self.isConfig = False
987 self.__nsubplots = 1
1054 self.__nsubplots = 1
988
1055
989 self.PLOT_CODE = POWER_CODE
1056 self.PLOT_CODE = POWER_CODE
990
1057
991 self.WIDTH = 700
1058 self.WIDTH = 700
992 self.HEIGHT = 500
1059 self.HEIGHT = 500
993 self.counter_imagwr = 0
1060 self.counter_imagwr = 0
994
1061
995 def getSubplots(self):
1062 def getSubplots(self):
996 ncol = 1
1063 ncol = 1
997 nrow = 1
1064 nrow = 1
998
1065
999 return nrow, ncol
1066 return nrow, ncol
1000
1067
1001 def setup(self, id, nplots, wintitle, show):
1068 def setup(self, id, nplots, wintitle, show):
1002
1069
1003 self.nplots = nplots
1070 self.nplots = nplots
1004
1071
1005 ncolspan = 1
1072 ncolspan = 1
1006 colspan = 1
1073 colspan = 1
1007
1074
1008 self.createFigure(id = id,
1075 self.createFigure(id = id,
1009 wintitle = wintitle,
1076 wintitle = wintitle,
1010 widthplot = self.WIDTH,
1077 widthplot = self.WIDTH,
1011 heightplot = self.HEIGHT,
1078 heightplot = self.HEIGHT,
1012 show=show)
1079 show=show)
1013
1080
1014 nrow, ncol = self.getSubplots()
1081 nrow, ncol = self.getSubplots()
1015
1082
1016 counter = 0
1083 counter = 0
1017 for y in range(nrow):
1084 for y in range(nrow):
1018 for x in range(ncol):
1085 for x in range(ncol):
1019 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
1086 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
1020
1087
1021 def run(self, dataOut, id, wintitle="", channelList=None,
1088 def run(self, dataOut, id, wintitle="", channelList=None,
1022 xmin=None, xmax=None, ymin=None, ymax=None,
1089 xmin=None, xmax=None, ymin=None, ymax=None,
1023 save=False, figpath='./', figfile=None, show=True,
1090 save=False, figpath='./', figfile=None, show=True,
1024 ftp=False, wr_period=1, server=None,
1091 ftp=False, wr_period=1, server=None,
1025 folder=None, username=None, password=None,
1092 folder=None, username=None, password=None,
1026 xaxis="frequency"):
1093 xaxis="frequency"):
1027
1094
1028
1095
1029 if channelList == None:
1096 if channelList == None:
1030 channelIndexList = dataOut.channelIndexList
1097 channelIndexList = dataOut.channelIndexList
1031 channelList = dataOut.channelList
1098 channelList = dataOut.channelList
1032 else:
1099 else:
1033 channelIndexList = []
1100 channelIndexList = []
1034 for channel in channelList:
1101 for channel in channelList:
1035 if channel not in dataOut.channelList:
1102 if channel not in dataOut.channelList:
1036 raise ValueError, "Channel %d is not in dataOut.channelList"
1103 raise ValueError, "Channel %d is not in dataOut.channelList"
1037 channelIndexList.append(dataOut.channelList.index(channel))
1104 channelIndexList.append(dataOut.channelList.index(channel))
1038
1105
1039 factor = dataOut.normFactor
1106 factor = dataOut.normFactor
1040
1107
1041 y = dataOut.getHeiRange()
1108 y = dataOut.getHeiRange()
1042
1109
1043 z = dataOut.data_spc/factor
1110 z = dataOut.data_spc/factor
1044 z = numpy.where(numpy.isfinite(z), z, numpy.NAN)
1111 z = numpy.where(numpy.isfinite(z), z, numpy.NAN)
1045
1112
1046 hei_index = numpy.arange(25)*3 + 20
1113 hei_index = numpy.arange(25)*3 + 20
1047
1114
1048 if xaxis == "frequency":
1115 if xaxis == "frequency":
1049 x = dataOut.getFreqRange()/1000.
1116 x = dataOut.getFreqRange()/1000.
1050 zdB = 10*numpy.log10(z[0,:,hei_index])
1117 zdB = 10*numpy.log10(z[0,:,hei_index])
1051 xlabel = "Frequency (kHz)"
1118 xlabel = "Frequency (kHz)"
1052 ylabel = "Power (dB)"
1119 ylabel = "Power (dB)"
1053
1120
1054 elif xaxis == "time":
1121 elif xaxis == "time":
1055 x = dataOut.getAcfRange()
1122 x = dataOut.getAcfRange()
1056 zdB = z[0,:,hei_index]
1123 zdB = z[0,:,hei_index]
1057 xlabel = "Time (ms)"
1124 xlabel = "Time (ms)"
1058 ylabel = "ACF"
1125 ylabel = "ACF"
1059
1126
1060 else:
1127 else:
1061 x = dataOut.getVelRange()
1128 x = dataOut.getVelRange()
1062 zdB = 10*numpy.log10(z[0,:,hei_index])
1129 zdB = 10*numpy.log10(z[0,:,hei_index])
1063 xlabel = "Velocity (m/s)"
1130 xlabel = "Velocity (m/s)"
1064 ylabel = "Power (dB)"
1131 ylabel = "Power (dB)"
1065
1132
1066 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0])
1133 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0])
1067 title = wintitle + " Range Cuts %s" %(thisDatetime.strftime("%d-%b-%Y"))
1134 title = wintitle + " Range Cuts %s" %(thisDatetime.strftime("%d-%b-%Y"))
1068
1135
1069 if not self.isConfig:
1136 if not self.isConfig:
1070
1137
1071 nplots = 1
1138 nplots = 1
1072
1139
1073 self.setup(id=id,
1140 self.setup(id=id,
1074 nplots=nplots,
1141 nplots=nplots,
1075 wintitle=wintitle,
1142 wintitle=wintitle,
1076 show=show)
1143 show=show)
1077
1144
1078 if xmin == None: xmin = numpy.nanmin(x)*0.9
1145 if xmin == None: xmin = numpy.nanmin(x)*0.9
1079 if xmax == None: xmax = numpy.nanmax(x)*1.1
1146 if xmax == None: xmax = numpy.nanmax(x)*1.1
1080 if ymin == None: ymin = numpy.nanmin(zdB)
1147 if ymin == None: ymin = numpy.nanmin(zdB)
1081 if ymax == None: ymax = numpy.nanmax(zdB)
1148 if ymax == None: ymax = numpy.nanmax(zdB)
1082
1149
1083 self.isConfig = True
1150 self.isConfig = True
1084
1151
1085 self.setWinTitle(title)
1152 self.setWinTitle(title)
1086
1153
1087 title = "Spectra Cuts: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
1154 title = "Spectra Cuts: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
1088 axes = self.axesList[0]
1155 axes = self.axesList[0]
1089
1156
1090 legendlabels = ["Range = %dKm" %y[i] for i in hei_index]
1157 legendlabels = ["Range = %dKm" %y[i] for i in hei_index]
1091
1158
1092 axes.pmultilineyaxis( x, zdB,
1159 axes.pmultilineyaxis( x, zdB,
1093 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax,
1160 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax,
1094 xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels,
1161 xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels,
1095 ytick_visible=True, nxticks=5,
1162 ytick_visible=True, nxticks=5,
1096 grid='x')
1163 grid='x')
1097
1164
1098 self.draw()
1165 self.draw()
1099
1166
1100 self.save(figpath=figpath,
1167 self.save(figpath=figpath,
1101 figfile=figfile,
1168 figfile=figfile,
1102 save=save,
1169 save=save,
1103 ftp=ftp,
1170 ftp=ftp,
1104 wr_period=wr_period,
1171 wr_period=wr_period,
1105 thisDatetime=thisDatetime)
1172 thisDatetime=thisDatetime)
1106
1173
1107 class Noise(Figure):
1174 class Noise(Figure):
1108
1175
1109 isConfig = None
1176 isConfig = None
1110 __nsubplots = None
1177 __nsubplots = None
1111
1178
1112 PREFIX = 'noise'
1179 PREFIX = 'noise'
1180
1181 parameters = {
1182 'id': global_type_string,
1183 'wintitle': global_type_string,
1184 'channelList': global_type_list,
1185 'showprofile': global_type_boolean,
1186 'xmin': global_type_float,
1187 'xmax': global_type_float,
1188 'ymin': global_type_float,
1189 'ymax': global_type_float,
1190 'timerange': global_type_float,
1191 'save': global_type_boolean,
1192 'figpath': global_type_string,
1193 'figfile': global_type_string,
1194 'show': global_type_boolean,
1195 'ftp': global_type_boolean,
1196 'wr_period': global_type_integer,
1197 'server': global_type_string,
1198 'folder': global_type_string,
1199 'username': global_type_string,
1200 'password': global_type_string,
1201 'ftp_wei': global_type_integer,
1202 'exp_code': global_type_integer,
1203 'sub_exp_code': global_type_integer,
1204 'plot_pos': global_type_integer,
1205 }
1113
1206
1114 def __init__(self, **kwargs):
1207 def __init__(self, **kwargs):
1115 Figure.__init__(self, **kwargs)
1208 Figure.__init__(self, **kwargs)
1116 self.timerange = 24*60*60
1209 self.timerange = 24*60*60
1117 self.isConfig = False
1210 self.isConfig = False
1118 self.__nsubplots = 1
1211 self.__nsubplots = 1
1119 self.counter_imagwr = 0
1212 self.counter_imagwr = 0
1120 self.WIDTH = 800
1213 self.WIDTH = 800
1121 self.HEIGHT = 400
1214 self.HEIGHT = 400
1122 self.WIDTHPROF = 120
1215 self.WIDTHPROF = 120
1123 self.HEIGHTPROF = 0
1216 self.HEIGHTPROF = 0
1124 self.xdata = None
1217 self.xdata = None
1125 self.ydata = None
1218 self.ydata = None
1126
1219
1127 self.PLOT_CODE = NOISE_CODE
1220 self.PLOT_CODE = NOISE_CODE
1128
1221
1129 self.FTP_WEI = None
1222 self.FTP_WEI = None
1130 self.EXP_CODE = None
1223 self.EXP_CODE = None
1131 self.SUB_EXP_CODE = None
1224 self.SUB_EXP_CODE = None
1132 self.PLOT_POS = None
1225 self.PLOT_POS = None
1133 self.figfile = None
1226 self.figfile = None
1134
1227
1135 self.xmin = None
1228 self.xmin = None
1136 self.xmax = None
1229 self.xmax = None
1137
1230
1138 def getSubplots(self):
1231 def getSubplots(self):
1139
1232
1140 ncol = 1
1233 ncol = 1
1141 nrow = 1
1234 nrow = 1
1142
1235
1143 return nrow, ncol
1236 return nrow, ncol
1144
1237
1145 def openfile(self, filename):
1238 def openfile(self, filename):
1146 dirname = os.path.dirname(filename)
1239 dirname = os.path.dirname(filename)
1147
1240
1148 if not os.path.exists(dirname):
1241 if not os.path.exists(dirname):
1149 os.mkdir(dirname)
1242 os.mkdir(dirname)
1150
1243
1151 f = open(filename,'w+')
1244 f = open(filename,'w+')
1152 f.write('\n\n')
1245 f.write('\n\n')
1153 f.write('JICAMARCA RADIO OBSERVATORY - Noise \n')
1246 f.write('JICAMARCA RADIO OBSERVATORY - Noise \n')
1154 f.write('DD MM YYYY HH MM SS Channel0 Channel1 Channel2 Channel3\n\n' )
1247 f.write('DD MM YYYY HH MM SS Channel0 Channel1 Channel2 Channel3\n\n' )
1155 f.close()
1248 f.close()
1156
1249
1157 def save_data(self, filename_phase, data, data_datetime):
1250 def save_data(self, filename_phase, data, data_datetime):
1158
1251
1159 f=open(filename_phase,'a')
1252 f=open(filename_phase,'a')
1160
1253
1161 timetuple_data = data_datetime.timetuple()
1254 timetuple_data = data_datetime.timetuple()
1162 day = str(timetuple_data.tm_mday)
1255 day = str(timetuple_data.tm_mday)
1163 month = str(timetuple_data.tm_mon)
1256 month = str(timetuple_data.tm_mon)
1164 year = str(timetuple_data.tm_year)
1257 year = str(timetuple_data.tm_year)
1165 hour = str(timetuple_data.tm_hour)
1258 hour = str(timetuple_data.tm_hour)
1166 minute = str(timetuple_data.tm_min)
1259 minute = str(timetuple_data.tm_min)
1167 second = str(timetuple_data.tm_sec)
1260 second = str(timetuple_data.tm_sec)
1168
1261
1169 data_msg = ''
1262 data_msg = ''
1170 for i in range(len(data)):
1263 for i in range(len(data)):
1171 data_msg += str(data[i]) + ' '
1264 data_msg += str(data[i]) + ' '
1172
1265
1173 f.write(day+' '+month+' '+year+' '+hour+' '+minute+' '+second+' ' + data_msg + '\n')
1266 f.write(day+' '+month+' '+year+' '+hour+' '+minute+' '+second+' ' + data_msg + '\n')
1174 f.close()
1267 f.close()
1175
1268
1176
1269
1177 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
1270 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
1178
1271
1179 self.__showprofile = showprofile
1272 self.__showprofile = showprofile
1180 self.nplots = nplots
1273 self.nplots = nplots
1181
1274
1182 ncolspan = 7
1275 ncolspan = 7
1183 colspan = 6
1276 colspan = 6
1184 self.__nsubplots = 2
1277 self.__nsubplots = 2
1185
1278
1186 self.createFigure(id = id,
1279 self.createFigure(id = id,
1187 wintitle = wintitle,
1280 wintitle = wintitle,
1188 widthplot = self.WIDTH+self.WIDTHPROF,
1281 widthplot = self.WIDTH+self.WIDTHPROF,
1189 heightplot = self.HEIGHT+self.HEIGHTPROF,
1282 heightplot = self.HEIGHT+self.HEIGHTPROF,
1190 show=show)
1283 show=show)
1191
1284
1192 nrow, ncol = self.getSubplots()
1285 nrow, ncol = self.getSubplots()
1193
1286
1194 self.addAxes(nrow, ncol*ncolspan, 0, 0, colspan, 1)
1287 self.addAxes(nrow, ncol*ncolspan, 0, 0, colspan, 1)
1195
1288
1196
1289
1197 def run(self, dataOut, id, wintitle="", channelList=None, showprofile='True',
1290 def run(self, dataOut, id, wintitle="", channelList=None, showprofile='True',
1198 xmin=None, xmax=None, ymin=None, ymax=None,
1291 xmin=None, xmax=None, ymin=None, ymax=None,
1199 timerange=None,
1292 timerange=None,
1200 save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1,
1293 save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1,
1201 server=None, folder=None, username=None, password=None,
1294 server=None, folder=None, username=None, password=None,
1202 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0):
1295 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0):
1203
1296
1204 if not isTimeInHourRange(dataOut.datatime, xmin, xmax):
1297 if not isTimeInHourRange(dataOut.datatime, xmin, xmax):
1205 return
1298 return
1206
1299
1207 if channelList == None:
1300 if channelList == None:
1208 channelIndexList = dataOut.channelIndexList
1301 channelIndexList = dataOut.channelIndexList
1209 channelList = dataOut.channelList
1302 channelList = dataOut.channelList
1210 else:
1303 else:
1211 channelIndexList = []
1304 channelIndexList = []
1212 for channel in channelList:
1305 for channel in channelList:
1213 if channel not in dataOut.channelList:
1306 if channel not in dataOut.channelList:
1214 raise ValueError, "Channel %d is not in dataOut.channelList"
1307 raise ValueError, "Channel %d is not in dataOut.channelList"
1215 channelIndexList.append(dataOut.channelList.index(channel))
1308 channelIndexList.append(dataOut.channelList.index(channel))
1216
1309
1217 x = dataOut.getTimeRange()
1310 x = dataOut.getTimeRange()
1218 #y = dataOut.getHeiRange()
1311 #y = dataOut.getHeiRange()
1219 factor = dataOut.normFactor
1312 factor = dataOut.normFactor
1220 noise = dataOut.noise[channelIndexList]/factor
1313 noise = dataOut.noise[channelIndexList]/factor
1221 noisedB = 10*numpy.log10(noise)
1314 noisedB = 10*numpy.log10(noise)
1222
1315
1223 thisDatetime = dataOut.datatime
1316 thisDatetime = dataOut.datatime
1224
1317
1225 title = wintitle + " Noise" # : %s" %(thisDatetime.strftime("%d-%b-%Y"))
1318 title = wintitle + " Noise" # : %s" %(thisDatetime.strftime("%d-%b-%Y"))
1226 xlabel = ""
1319 xlabel = ""
1227 ylabel = "Intensity (dB)"
1320 ylabel = "Intensity (dB)"
1228 update_figfile = False
1321 update_figfile = False
1229
1322
1230 if not self.isConfig:
1323 if not self.isConfig:
1231
1324
1232 nplots = 1
1325 nplots = 1
1233
1326
1234 self.setup(id=id,
1327 self.setup(id=id,
1235 nplots=nplots,
1328 nplots=nplots,
1236 wintitle=wintitle,
1329 wintitle=wintitle,
1237 showprofile=showprofile,
1330 showprofile=showprofile,
1238 show=show)
1331 show=show)
1239
1332
1240 if timerange != None:
1333 if timerange != None:
1241 self.timerange = timerange
1334 self.timerange = timerange
1242
1335
1243 self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange)
1336 self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange)
1244
1337
1245 if ymin == None: ymin = numpy.floor(numpy.nanmin(noisedB)) - 10.0
1338 if ymin == None: ymin = numpy.floor(numpy.nanmin(noisedB)) - 10.0
1246 if ymax == None: ymax = numpy.nanmax(noisedB) + 10.0
1339 if ymax == None: ymax = numpy.nanmax(noisedB) + 10.0
1247
1340
1248 self.FTP_WEI = ftp_wei
1341 self.FTP_WEI = ftp_wei
1249 self.EXP_CODE = exp_code
1342 self.EXP_CODE = exp_code
1250 self.SUB_EXP_CODE = sub_exp_code
1343 self.SUB_EXP_CODE = sub_exp_code
1251 self.PLOT_POS = plot_pos
1344 self.PLOT_POS = plot_pos
1252
1345
1253
1346
1254 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
1347 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
1255 self.isConfig = True
1348 self.isConfig = True
1256 self.figfile = figfile
1349 self.figfile = figfile
1257 self.xdata = numpy.array([])
1350 self.xdata = numpy.array([])
1258 self.ydata = numpy.array([])
1351 self.ydata = numpy.array([])
1259
1352
1260 update_figfile = True
1353 update_figfile = True
1261
1354
1262 #open file beacon phase
1355 #open file beacon phase
1263 path = '%s%03d' %(self.PREFIX, self.id)
1356 path = '%s%03d' %(self.PREFIX, self.id)
1264 noise_file = os.path.join(path,'%s.txt'%self.name)
1357 noise_file = os.path.join(path,'%s.txt'%self.name)
1265 self.filename_noise = os.path.join(figpath,noise_file)
1358 self.filename_noise = os.path.join(figpath,noise_file)
1266
1359
1267 self.setWinTitle(title)
1360 self.setWinTitle(title)
1268
1361
1269 title = "Noise %s" %(thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
1362 title = "Noise %s" %(thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
1270
1363
1271 legendlabels = ["channel %d"%(idchannel) for idchannel in channelList]
1364 legendlabels = ["channel %d"%(idchannel) for idchannel in channelList]
1272 axes = self.axesList[0]
1365 axes = self.axesList[0]
1273
1366
1274 self.xdata = numpy.hstack((self.xdata, x[0:1]))
1367 self.xdata = numpy.hstack((self.xdata, x[0:1]))
1275
1368
1276 if len(self.ydata)==0:
1369 if len(self.ydata)==0:
1277 self.ydata = noisedB.reshape(-1,1)
1370 self.ydata = noisedB.reshape(-1,1)
1278 else:
1371 else:
1279 self.ydata = numpy.hstack((self.ydata, noisedB.reshape(-1,1)))
1372 self.ydata = numpy.hstack((self.ydata, noisedB.reshape(-1,1)))
1280
1373
1281
1374
1282 axes.pmultilineyaxis(x=self.xdata, y=self.ydata,
1375 axes.pmultilineyaxis(x=self.xdata, y=self.ydata,
1283 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax,
1376 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax,
1284 xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels, marker='x', markersize=8, linestyle="solid",
1377 xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels, marker='x', markersize=8, linestyle="solid",
1285 XAxisAsTime=True, grid='both'
1378 XAxisAsTime=True, grid='both'
1286 )
1379 )
1287
1380
1288 self.draw()
1381 self.draw()
1289
1382
1290 if dataOut.ltctime >= self.xmax:
1383 if dataOut.ltctime >= self.xmax:
1291 self.counter_imagwr = wr_period
1384 self.counter_imagwr = wr_period
1292 self.isConfig = False
1385 self.isConfig = False
1293 update_figfile = True
1386 update_figfile = True
1294
1387
1295 self.save(figpath=figpath,
1388 self.save(figpath=figpath,
1296 figfile=figfile,
1389 figfile=figfile,
1297 save=save,
1390 save=save,
1298 ftp=ftp,
1391 ftp=ftp,
1299 wr_period=wr_period,
1392 wr_period=wr_period,
1300 thisDatetime=thisDatetime,
1393 thisDatetime=thisDatetime,
1301 update_figfile=update_figfile)
1394 update_figfile=update_figfile)
1302
1395
1303 #store data beacon phase
1396 #store data beacon phase
1304 if save:
1397 if save:
1305 self.save_data(self.filename_noise, noisedB, thisDatetime)
1398 self.save_data(self.filename_noise, noisedB, thisDatetime)
1306
1399
1307 class BeaconPhase(Figure):
1400 class BeaconPhase(Figure):
1308
1401
1309 __isConfig = None
1402 __isConfig = None
1310 __nsubplots = None
1403 __nsubplots = None
1311
1404
1312 PREFIX = 'beacon_phase'
1405 PREFIX = 'beacon_phase'
1406
1407 parameters = {
1408 'id': global_type_string,
1409 'wintitle': global_type_string,
1410 'pairsList': global_type_pairsList,
1411 'showprofile': global_type_boolean,
1412 'xmin': global_type_float,
1413 'xmax': global_type_float,
1414 'ymin': global_type_float,
1415 'ymax': global_type_float,
1416 'hmin': global_type_float,
1417 'hmax': global_type_float,
1418 'timerange': global_type_float,
1419 'save': global_type_boolean,
1420 'figpath': global_type_string,
1421 'figfile': global_type_string,
1422 'show': global_type_boolean,
1423 'ftp': global_type_boolean,
1424 'wr_period': global_type_integer,
1425 'server': global_type_string,
1426 'folder': global_type_string,
1427 'username': global_type_string,
1428 'password': global_type_string,
1429 'ftp_wei': global_type_integer,
1430 'exp_code': global_type_integer,
1431 'sub_exp_code': global_type_integer,
1432 'plot_pos': global_type_integer,
1433 }
1313
1434
1314 def __init__(self, **kwargs):
1435 def __init__(self, **kwargs):
1315 Figure.__init__(self, **kwargs)
1436 Figure.__init__(self, **kwargs)
1316 self.timerange = 24*60*60
1437 self.timerange = 24*60*60
1317 self.isConfig = False
1438 self.isConfig = False
1318 self.__nsubplots = 1
1439 self.__nsubplots = 1
1319 self.counter_imagwr = 0
1440 self.counter_imagwr = 0
1320 self.WIDTH = 800
1441 self.WIDTH = 800
1321 self.HEIGHT = 400
1442 self.HEIGHT = 400
1322 self.WIDTHPROF = 120
1443 self.WIDTHPROF = 120
1323 self.HEIGHTPROF = 0
1444 self.HEIGHTPROF = 0
1324 self.xdata = None
1445 self.xdata = None
1325 self.ydata = None
1446 self.ydata = None
1326
1447
1327 self.PLOT_CODE = BEACON_CODE
1448 self.PLOT_CODE = BEACON_CODE
1328
1449
1329 self.FTP_WEI = None
1450 self.FTP_WEI = None
1330 self.EXP_CODE = None
1451 self.EXP_CODE = None
1331 self.SUB_EXP_CODE = None
1452 self.SUB_EXP_CODE = None
1332 self.PLOT_POS = None
1453 self.PLOT_POS = None
1333
1454
1334 self.filename_phase = None
1455 self.filename_phase = None
1335
1456
1336 self.figfile = None
1457 self.figfile = None
1337
1458
1338 self.xmin = None
1459 self.xmin = None
1339 self.xmax = None
1460 self.xmax = None
1340
1461
1341 def getSubplots(self):
1462 def getSubplots(self):
1342
1463
1343 ncol = 1
1464 ncol = 1
1344 nrow = 1
1465 nrow = 1
1345
1466
1346 return nrow, ncol
1467 return nrow, ncol
1347
1468
1348 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
1469 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
1349
1470
1350 self.__showprofile = showprofile
1471 self.__showprofile = showprofile
1351 self.nplots = nplots
1472 self.nplots = nplots
1352
1473
1353 ncolspan = 7
1474 ncolspan = 7
1354 colspan = 6
1475 colspan = 6
1355 self.__nsubplots = 2
1476 self.__nsubplots = 2
1356
1477
1357 self.createFigure(id = id,
1478 self.createFigure(id = id,
1358 wintitle = wintitle,
1479 wintitle = wintitle,
1359 widthplot = self.WIDTH+self.WIDTHPROF,
1480 widthplot = self.WIDTH+self.WIDTHPROF,
1360 heightplot = self.HEIGHT+self.HEIGHTPROF,
1481 heightplot = self.HEIGHT+self.HEIGHTPROF,
1361 show=show)
1482 show=show)
1362
1483
1363 nrow, ncol = self.getSubplots()
1484 nrow, ncol = self.getSubplots()
1364
1485
1365 self.addAxes(nrow, ncol*ncolspan, 0, 0, colspan, 1)
1486 self.addAxes(nrow, ncol*ncolspan, 0, 0, colspan, 1)
1366
1487
1367 def save_phase(self, filename_phase):
1488 def save_phase(self, filename_phase):
1368 f = open(filename_phase,'w+')
1489 f = open(filename_phase,'w+')
1369 f.write('\n\n')
1490 f.write('\n\n')
1370 f.write('JICAMARCA RADIO OBSERVATORY - Beacon Phase \n')
1491 f.write('JICAMARCA RADIO OBSERVATORY - Beacon Phase \n')
1371 f.write('DD MM YYYY HH MM SS pair(2,0) pair(2,1) pair(2,3) pair(2,4)\n\n' )
1492 f.write('DD MM YYYY HH MM SS pair(2,0) pair(2,1) pair(2,3) pair(2,4)\n\n' )
1372 f.close()
1493 f.close()
1373
1494
1374 def save_data(self, filename_phase, data, data_datetime):
1495 def save_data(self, filename_phase, data, data_datetime):
1375 f=open(filename_phase,'a')
1496 f=open(filename_phase,'a')
1376 timetuple_data = data_datetime.timetuple()
1497 timetuple_data = data_datetime.timetuple()
1377 day = str(timetuple_data.tm_mday)
1498 day = str(timetuple_data.tm_mday)
1378 month = str(timetuple_data.tm_mon)
1499 month = str(timetuple_data.tm_mon)
1379 year = str(timetuple_data.tm_year)
1500 year = str(timetuple_data.tm_year)
1380 hour = str(timetuple_data.tm_hour)
1501 hour = str(timetuple_data.tm_hour)
1381 minute = str(timetuple_data.tm_min)
1502 minute = str(timetuple_data.tm_min)
1382 second = str(timetuple_data.tm_sec)
1503 second = str(timetuple_data.tm_sec)
1383 f.write(day+' '+month+' '+year+' '+hour+' '+minute+' '+second+' '+str(data[0])+' '+str(data[1])+' '+str(data[2])+' '+str(data[3])+'\n')
1504 f.write(day+' '+month+' '+year+' '+hour+' '+minute+' '+second+' '+str(data[0])+' '+str(data[1])+' '+str(data[2])+' '+str(data[3])+'\n')
1384 f.close()
1505 f.close()
1385
1506
1386
1507
1387 def run(self, dataOut, id, wintitle="", pairsList=None, showprofile='True',
1508 def run(self, dataOut, id, wintitle="", pairsList=None, showprofile='True',
1388 xmin=None, xmax=None, ymin=None, ymax=None, hmin=None, hmax=None,
1509 xmin=None, xmax=None, ymin=None, ymax=None, hmin=None, hmax=None,
1389 timerange=None,
1510 timerange=None,
1390 save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1,
1511 save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1,
1391 server=None, folder=None, username=None, password=None,
1512 server=None, folder=None, username=None, password=None,
1392 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0):
1513 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0):
1393
1514
1394 if not isTimeInHourRange(dataOut.datatime, xmin, xmax):
1515 if not isTimeInHourRange(dataOut.datatime, xmin, xmax):
1395 return
1516 return
1396
1517
1397 if pairsList == None:
1518 if pairsList == None:
1398 pairsIndexList = dataOut.pairsIndexList[:10]
1519 pairsIndexList = dataOut.pairsIndexList[:10]
1399 else:
1520 else:
1400 pairsIndexList = []
1521 pairsIndexList = []
1401 for pair in pairsList:
1522 for pair in pairsList:
1402 if pair not in dataOut.pairsList:
1523 if pair not in dataOut.pairsList:
1403 raise ValueError, "Pair %s is not in dataOut.pairsList" %(pair)
1524 raise ValueError, "Pair %s is not in dataOut.pairsList" %(pair)
1404 pairsIndexList.append(dataOut.pairsList.index(pair))
1525 pairsIndexList.append(dataOut.pairsList.index(pair))
1405
1526
1406 if pairsIndexList == []:
1527 if pairsIndexList == []:
1407 return
1528 return
1408
1529
1409 # if len(pairsIndexList) > 4:
1530 # if len(pairsIndexList) > 4:
1410 # pairsIndexList = pairsIndexList[0:4]
1531 # pairsIndexList = pairsIndexList[0:4]
1411
1532
1412 hmin_index = None
1533 hmin_index = None
1413 hmax_index = None
1534 hmax_index = None
1414
1535
1415 if hmin != None and hmax != None:
1536 if hmin != None and hmax != None:
1416 indexes = numpy.arange(dataOut.nHeights)
1537 indexes = numpy.arange(dataOut.nHeights)
1417 hmin_list = indexes[dataOut.heightList >= hmin]
1538 hmin_list = indexes[dataOut.heightList >= hmin]
1418 hmax_list = indexes[dataOut.heightList <= hmax]
1539 hmax_list = indexes[dataOut.heightList <= hmax]
1419
1540
1420 if hmin_list.any():
1541 if hmin_list.any():
1421 hmin_index = hmin_list[0]
1542 hmin_index = hmin_list[0]
1422
1543
1423 if hmax_list.any():
1544 if hmax_list.any():
1424 hmax_index = hmax_list[-1]+1
1545 hmax_index = hmax_list[-1]+1
1425
1546
1426 x = dataOut.getTimeRange()
1547 x = dataOut.getTimeRange()
1427 #y = dataOut.getHeiRange()
1548 #y = dataOut.getHeiRange()
1428
1549
1429
1550
1430 thisDatetime = dataOut.datatime
1551 thisDatetime = dataOut.datatime
1431
1552
1432 title = wintitle + " Signal Phase" # : %s" %(thisDatetime.strftime("%d-%b-%Y"))
1553 title = wintitle + " Signal Phase" # : %s" %(thisDatetime.strftime("%d-%b-%Y"))
1433 xlabel = "Local Time"
1554 xlabel = "Local Time"
1434 ylabel = "Phase (degrees)"
1555 ylabel = "Phase (degrees)"
1435
1556
1436 update_figfile = False
1557 update_figfile = False
1437
1558
1438 nplots = len(pairsIndexList)
1559 nplots = len(pairsIndexList)
1439 #phase = numpy.zeros((len(pairsIndexList),len(dataOut.beacon_heiIndexList)))
1560 #phase = numpy.zeros((len(pairsIndexList),len(dataOut.beacon_heiIndexList)))
1440 phase_beacon = numpy.zeros(len(pairsIndexList))
1561 phase_beacon = numpy.zeros(len(pairsIndexList))
1441 for i in range(nplots):
1562 for i in range(nplots):
1442 pair = dataOut.pairsList[pairsIndexList[i]]
1563 pair = dataOut.pairsList[pairsIndexList[i]]
1443 ccf = numpy.average(dataOut.data_cspc[pairsIndexList[i], :, hmin_index:hmax_index], axis=0)
1564 ccf = numpy.average(dataOut.data_cspc[pairsIndexList[i], :, hmin_index:hmax_index], axis=0)
1444 powa = numpy.average(dataOut.data_spc[pair[0], :, hmin_index:hmax_index], axis=0)
1565 powa = numpy.average(dataOut.data_spc[pair[0], :, hmin_index:hmax_index], axis=0)
1445 powb = numpy.average(dataOut.data_spc[pair[1], :, hmin_index:hmax_index], axis=0)
1566 powb = numpy.average(dataOut.data_spc[pair[1], :, hmin_index:hmax_index], axis=0)
1446 avgcoherenceComplex = ccf/numpy.sqrt(powa*powb)
1567 avgcoherenceComplex = ccf/numpy.sqrt(powa*powb)
1447 phase = numpy.arctan2(avgcoherenceComplex.imag, avgcoherenceComplex.real)*180/numpy.pi
1568 phase = numpy.arctan2(avgcoherenceComplex.imag, avgcoherenceComplex.real)*180/numpy.pi
1448
1569
1449 #print "Phase %d%d" %(pair[0], pair[1])
1570 #print "Phase %d%d" %(pair[0], pair[1])
1450 #print phase[dataOut.beacon_heiIndexList]
1571 #print phase[dataOut.beacon_heiIndexList]
1451
1572
1452 if dataOut.beacon_heiIndexList:
1573 if dataOut.beacon_heiIndexList:
1453 phase_beacon[i] = numpy.average(phase[dataOut.beacon_heiIndexList])
1574 phase_beacon[i] = numpy.average(phase[dataOut.beacon_heiIndexList])
1454 else:
1575 else:
1455 phase_beacon[i] = numpy.average(phase)
1576 phase_beacon[i] = numpy.average(phase)
1456
1577
1457 if not self.isConfig:
1578 if not self.isConfig:
1458
1579
1459 nplots = len(pairsIndexList)
1580 nplots = len(pairsIndexList)
1460
1581
1461 self.setup(id=id,
1582 self.setup(id=id,
1462 nplots=nplots,
1583 nplots=nplots,
1463 wintitle=wintitle,
1584 wintitle=wintitle,
1464 showprofile=showprofile,
1585 showprofile=showprofile,
1465 show=show)
1586 show=show)
1466
1587
1467 if timerange != None:
1588 if timerange != None:
1468 self.timerange = timerange
1589 self.timerange = timerange
1469
1590
1470 self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange)
1591 self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange)
1471
1592
1472 if ymin == None: ymin = 0
1593 if ymin == None: ymin = 0
1473 if ymax == None: ymax = 360
1594 if ymax == None: ymax = 360
1474
1595
1475 self.FTP_WEI = ftp_wei
1596 self.FTP_WEI = ftp_wei
1476 self.EXP_CODE = exp_code
1597 self.EXP_CODE = exp_code
1477 self.SUB_EXP_CODE = sub_exp_code
1598 self.SUB_EXP_CODE = sub_exp_code
1478 self.PLOT_POS = plot_pos
1599 self.PLOT_POS = plot_pos
1479
1600
1480 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
1601 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
1481 self.isConfig = True
1602 self.isConfig = True
1482 self.figfile = figfile
1603 self.figfile = figfile
1483 self.xdata = numpy.array([])
1604 self.xdata = numpy.array([])
1484 self.ydata = numpy.array([])
1605 self.ydata = numpy.array([])
1485
1606
1486 update_figfile = True
1607 update_figfile = True
1487
1608
1488 #open file beacon phase
1609 #open file beacon phase
1489 path = '%s%03d' %(self.PREFIX, self.id)
1610 path = '%s%03d' %(self.PREFIX, self.id)
1490 beacon_file = os.path.join(path,'%s.txt'%self.name)
1611 beacon_file = os.path.join(path,'%s.txt'%self.name)
1491 self.filename_phase = os.path.join(figpath,beacon_file)
1612 self.filename_phase = os.path.join(figpath,beacon_file)
1492 #self.save_phase(self.filename_phase)
1613 #self.save_phase(self.filename_phase)
1493
1614
1494
1615
1495 #store data beacon phase
1616 #store data beacon phase
1496 #self.save_data(self.filename_phase, phase_beacon, thisDatetime)
1617 #self.save_data(self.filename_phase, phase_beacon, thisDatetime)
1497
1618
1498 self.setWinTitle(title)
1619 self.setWinTitle(title)
1499
1620
1500
1621
1501 title = "Phase Plot %s" %(thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
1622 title = "Phase Plot %s" %(thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
1502
1623
1503 legendlabels = ["Pair (%d,%d)"%(pair[0], pair[1]) for pair in dataOut.pairsList]
1624 legendlabels = ["Pair (%d,%d)"%(pair[0], pair[1]) for pair in dataOut.pairsList]
1504
1625
1505 axes = self.axesList[0]
1626 axes = self.axesList[0]
1506
1627
1507 self.xdata = numpy.hstack((self.xdata, x[0:1]))
1628 self.xdata = numpy.hstack((self.xdata, x[0:1]))
1508
1629
1509 if len(self.ydata)==0:
1630 if len(self.ydata)==0:
1510 self.ydata = phase_beacon.reshape(-1,1)
1631 self.ydata = phase_beacon.reshape(-1,1)
1511 else:
1632 else:
1512 self.ydata = numpy.hstack((self.ydata, phase_beacon.reshape(-1,1)))
1633 self.ydata = numpy.hstack((self.ydata, phase_beacon.reshape(-1,1)))
1513
1634
1514
1635
1515 axes.pmultilineyaxis(x=self.xdata, y=self.ydata,
1636 axes.pmultilineyaxis(x=self.xdata, y=self.ydata,
1516 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax,
1637 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax,
1517 xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels, marker='x', markersize=8, linestyle="solid",
1638 xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels, marker='x', markersize=8, linestyle="solid",
1518 XAxisAsTime=True, grid='both'
1639 XAxisAsTime=True, grid='both'
1519 )
1640 )
1520
1641
1521 self.draw()
1642 self.draw()
1522
1643
1523 if dataOut.ltctime >= self.xmax:
1644 if dataOut.ltctime >= self.xmax:
1524 self.counter_imagwr = wr_period
1645 self.counter_imagwr = wr_period
1525 self.isConfig = False
1646 self.isConfig = False
1526 update_figfile = True
1647 update_figfile = True
1527
1648
1528 self.save(figpath=figpath,
1649 self.save(figpath=figpath,
1529 figfile=figfile,
1650 figfile=figfile,
1530 save=save,
1651 save=save,
1531 ftp=ftp,
1652 ftp=ftp,
1532 wr_period=wr_period,
1653 wr_period=wr_period,
1533 thisDatetime=thisDatetime,
1654 thisDatetime=thisDatetime,
1534 update_figfile=update_figfile)
1655 update_figfile=update_figfile)
@@ -1,849 +1,853
1 '''
1 '''
2 Created on Jul 3, 2014
2 Created on Jul 3, 2014
3
3
4 @author: roj-idl71
4 @author: roj-idl71
5 '''
5 '''
6
6
7 import os, sys
7 import os, sys
8 import time, datetime
8 import time, datetime
9 import numpy
9 import numpy
10 import fnmatch
10 import fnmatch
11 import glob
11 import glob
12 from time import sleep
12 from time import sleep
13
13
14 try:
14 try:
15 import pyfits
15 import pyfits
16 except ImportError, e:
16 except ImportError, e:
17 print "Fits data cannot be used. Install pyfits module"
17 print "Fits data cannot be used. Install pyfits module"
18
18
19 from xml.etree.ElementTree import ElementTree
19 from xml.etree.ElementTree import ElementTree
20
20
21 from jroIO_base import isRadarFolder, isNumber
21 from jroIO_base import isRadarFolder, isNumber
22 from schainpy.model.data.jrodata import Fits
22 from schainpy.model.data.jrodata import Fits
23 from schainpy.model.proc.jroproc_base import Operation, ProcessingUnit
23 from schainpy.model.proc.jroproc_base import Operation, ProcessingUnit
24
24
25 class PyFits(object):
25 class PyFits(object):
26 name=None
26 name=None
27 format=None
27 format=None
28 array =None
28 array =None
29 data =None
29 data =None
30 thdulist=None
30 thdulist=None
31 prihdr=None
31 prihdr=None
32 hdu=None
32 hdu=None
33
33
34 def __init__(self):
34 def __init__(self):
35
35
36 pass
36 pass
37
37
38 def setColF(self,name,format,array):
38 def setColF(self,name,format,array):
39 self.name=name
39 self.name=name
40 self.format=format
40 self.format=format
41 self.array=array
41 self.array=array
42 a1=numpy.array([self.array],dtype=numpy.float32)
42 a1=numpy.array([self.array],dtype=numpy.float32)
43 self.col1 = pyfits.Column(name=self.name, format=self.format, array=a1)
43 self.col1 = pyfits.Column(name=self.name, format=self.format, array=a1)
44 return self.col1
44 return self.col1
45
45
46 # def setColP(self,name,format,data):
46 # def setColP(self,name,format,data):
47 # self.name=name
47 # self.name=name
48 # self.format=format
48 # self.format=format
49 # self.data=data
49 # self.data=data
50 # a2=numpy.array([self.data],dtype=numpy.float32)
50 # a2=numpy.array([self.data],dtype=numpy.float32)
51 # self.col2 = pyfits.Column(name=self.name, format=self.format, array=a2)
51 # self.col2 = pyfits.Column(name=self.name, format=self.format, array=a2)
52 # return self.col2
52 # return self.col2
53
53
54
54
55 def writeData(self,name,format,data):
55 def writeData(self,name,format,data):
56 self.name=name
56 self.name=name
57 self.format=format
57 self.format=format
58 self.data=data
58 self.data=data
59 a2=numpy.array([self.data],dtype=numpy.float32)
59 a2=numpy.array([self.data],dtype=numpy.float32)
60 self.col2 = pyfits.Column(name=self.name, format=self.format, array=a2)
60 self.col2 = pyfits.Column(name=self.name, format=self.format, array=a2)
61 return self.col2
61 return self.col2
62
62
63 def cFImage(self,idblock,year,month,day,hour,minute,second):
63 def cFImage(self,idblock,year,month,day,hour,minute,second):
64 self.hdu= pyfits.PrimaryHDU(idblock)
64 self.hdu= pyfits.PrimaryHDU(idblock)
65 self.hdu.header.set("Year",year)
65 self.hdu.header.set("Year",year)
66 self.hdu.header.set("Month",month)
66 self.hdu.header.set("Month",month)
67 self.hdu.header.set("Day",day)
67 self.hdu.header.set("Day",day)
68 self.hdu.header.set("Hour",hour)
68 self.hdu.header.set("Hour",hour)
69 self.hdu.header.set("Minute",minute)
69 self.hdu.header.set("Minute",minute)
70 self.hdu.header.set("Second",second)
70 self.hdu.header.set("Second",second)
71 return self.hdu
71 return self.hdu
72
72
73
73
74 def Ctable(self,colList):
74 def Ctable(self,colList):
75 self.cols=pyfits.ColDefs(colList)
75 self.cols=pyfits.ColDefs(colList)
76 self.tbhdu = pyfits.new_table(self.cols)
76 self.tbhdu = pyfits.new_table(self.cols)
77 return self.tbhdu
77 return self.tbhdu
78
78
79
79
80 def CFile(self,hdu,tbhdu):
80 def CFile(self,hdu,tbhdu):
81 self.thdulist=pyfits.HDUList([hdu,tbhdu])
81 self.thdulist=pyfits.HDUList([hdu,tbhdu])
82
82
83 def wFile(self,filename):
83 def wFile(self,filename):
84 if os.path.isfile(filename):
84 if os.path.isfile(filename):
85 os.remove(filename)
85 os.remove(filename)
86 self.thdulist.writeto(filename)
86 self.thdulist.writeto(filename)
87
87
88
88
89 class ParameterConf:
89 class ParameterConf:
90 ELEMENTNAME = 'Parameter'
90 ELEMENTNAME = 'Parameter'
91 def __init__(self):
91 def __init__(self):
92 self.name = ''
92 self.name = ''
93 self.value = ''
93 self.value = ''
94
94
95 def readXml(self, parmElement):
95 def readXml(self, parmElement):
96 self.name = parmElement.get('name')
96 self.name = parmElement.get('name')
97 self.value = parmElement.get('value')
97 self.value = parmElement.get('value')
98
98
99 def getElementName(self):
99 def getElementName(self):
100 return self.ELEMENTNAME
100 return self.ELEMENTNAME
101
101
102 class Metadata(object):
102 class Metadata(object):
103
103
104 def __init__(self, filename):
104 def __init__(self, filename):
105 self.parmConfObjList = []
105 self.parmConfObjList = []
106 self.readXml(filename)
106 self.readXml(filename)
107
107
108 def readXml(self, filename):
108 def readXml(self, filename):
109 self.projectElement = None
109 self.projectElement = None
110 self.procUnitConfObjDict = {}
110 self.procUnitConfObjDict = {}
111 self.projectElement = ElementTree().parse(filename)
111 self.projectElement = ElementTree().parse(filename)
112 self.project = self.projectElement.tag
112 self.project = self.projectElement.tag
113
113
114 parmElementList = self.projectElement.getiterator(ParameterConf().getElementName())
114 parmElementList = self.projectElement.getiterator(ParameterConf().getElementName())
115
115
116 for parmElement in parmElementList:
116 for parmElement in parmElementList:
117 parmConfObj = ParameterConf()
117 parmConfObj = ParameterConf()
118 parmConfObj.readXml(parmElement)
118 parmConfObj.readXml(parmElement)
119 self.parmConfObjList.append(parmConfObj)
119 self.parmConfObjList.append(parmConfObj)
120
120
121 class FitsWriter(Operation):
121 class FitsWriter(Operation):
122
122 parameters = {
123 'path': global_type_string,
124 'dataBlocksPerFile': global_type_integer,
125 'metadatafile': global_type_string,
126 }
123 def __init__(self, **kwargs):
127 def __init__(self, **kwargs):
124 Operation.__init__(self, **kwargs)
128 Operation.__init__(self, **kwargs)
125 self.isConfig = False
129 self.isConfig = False
126 self.dataBlocksPerFile = None
130 self.dataBlocksPerFile = None
127 self.blockIndex = 0
131 self.blockIndex = 0
128 self.flagIsNewFile = 1
132 self.flagIsNewFile = 1
129 self.fitsObj = None
133 self.fitsObj = None
130 self.optchar = 'P'
134 self.optchar = 'P'
131 self.ext = '.fits'
135 self.ext = '.fits'
132 self.setFile = 0
136 self.setFile = 0
133
137
134 def setFitsHeader(self, dataOut, metadatafile=None):
138 def setFitsHeader(self, dataOut, metadatafile=None):
135
139
136 header_data = pyfits.PrimaryHDU()
140 header_data = pyfits.PrimaryHDU()
137
141
138 header_data.header['EXPNAME'] = "RADAR DATA"
142 header_data.header['EXPNAME'] = "RADAR DATA"
139 header_data.header['DATATYPE'] = "SPECTRA"
143 header_data.header['DATATYPE'] = "SPECTRA"
140 header_data.header['COMMENT'] = ""
144 header_data.header['COMMENT'] = ""
141
145
142 if metadatafile:
146 if metadatafile:
143
147
144 metadata4fits = Metadata(metadatafile)
148 metadata4fits = Metadata(metadatafile)
145
149
146 for parameter in metadata4fits.parmConfObjList:
150 for parameter in metadata4fits.parmConfObjList:
147 parm_name = parameter.name
151 parm_name = parameter.name
148 parm_value = parameter.value
152 parm_value = parameter.value
149
153
150 header_data.header[parm_name] = parm_value
154 header_data.header[parm_name] = parm_value
151
155
152 header_data.header['DATETIME'] = time.strftime("%b %d %Y %H:%M:%S", dataOut.datatime.timetuple())
156 header_data.header['DATETIME'] = time.strftime("%b %d %Y %H:%M:%S", dataOut.datatime.timetuple())
153 header_data.header['CHANNELLIST'] = str(dataOut.channelList)
157 header_data.header['CHANNELLIST'] = str(dataOut.channelList)
154 header_data.header['NCHANNELS'] = dataOut.nChannels
158 header_data.header['NCHANNELS'] = dataOut.nChannels
155 #header_data.header['HEIGHTS'] = dataOut.heightList
159 #header_data.header['HEIGHTS'] = dataOut.heightList
156 header_data.header['NHEIGHTS'] = dataOut.nHeights
160 header_data.header['NHEIGHTS'] = dataOut.nHeights
157
161
158 header_data.header['IPPSECONDS'] = dataOut.ippSeconds
162 header_data.header['IPPSECONDS'] = dataOut.ippSeconds
159 header_data.header['NCOHINT'] = dataOut.nCohInt
163 header_data.header['NCOHINT'] = dataOut.nCohInt
160 header_data.header['NINCOHINT'] = dataOut.nIncohInt
164 header_data.header['NINCOHINT'] = dataOut.nIncohInt
161 header_data.header['TIMEZONE'] = dataOut.timeZone
165 header_data.header['TIMEZONE'] = dataOut.timeZone
162 header_data.header['NBLOCK'] = self.blockIndex
166 header_data.header['NBLOCK'] = self.blockIndex
163
167
164 header_data.writeto(self.filename)
168 header_data.writeto(self.filename)
165
169
166 self.addExtension(dataOut.heightList,'HEIGHTLIST')
170 self.addExtension(dataOut.heightList,'HEIGHTLIST')
167
171
168
172
169 def setup(self, dataOut, path, dataBlocksPerFile=100, metadatafile=None):
173 def setup(self, dataOut, path, dataBlocksPerFile=100, metadatafile=None):
170
174
171 self.path = path
175 self.path = path
172 self.dataOut = dataOut
176 self.dataOut = dataOut
173 self.metadatafile = metadatafile
177 self.metadatafile = metadatafile
174 self.dataBlocksPerFile = dataBlocksPerFile
178 self.dataBlocksPerFile = dataBlocksPerFile
175
179
176 def open(self):
180 def open(self):
177 self.fitsObj = pyfits.open(self.filename, mode='update')
181 self.fitsObj = pyfits.open(self.filename, mode='update')
178
182
179
183
180 def addExtension(self, data, tagname):
184 def addExtension(self, data, tagname):
181 self.open()
185 self.open()
182 extension = pyfits.ImageHDU(data=data, name=tagname)
186 extension = pyfits.ImageHDU(data=data, name=tagname)
183 #extension.header['TAG'] = tagname
187 #extension.header['TAG'] = tagname
184 self.fitsObj.append(extension)
188 self.fitsObj.append(extension)
185 self.write()
189 self.write()
186
190
187 def addData(self, data):
191 def addData(self, data):
188 self.open()
192 self.open()
189 extension = pyfits.ImageHDU(data=data, name=self.fitsObj[0].header['DATATYPE'])
193 extension = pyfits.ImageHDU(data=data, name=self.fitsObj[0].header['DATATYPE'])
190 extension.header['UTCTIME'] = self.dataOut.utctime
194 extension.header['UTCTIME'] = self.dataOut.utctime
191 self.fitsObj.append(extension)
195 self.fitsObj.append(extension)
192 self.blockIndex += 1
196 self.blockIndex += 1
193 self.fitsObj[0].header['NBLOCK'] = self.blockIndex
197 self.fitsObj[0].header['NBLOCK'] = self.blockIndex
194
198
195 self.write()
199 self.write()
196
200
197 def write(self):
201 def write(self):
198
202
199 self.fitsObj.flush(verbose=True)
203 self.fitsObj.flush(verbose=True)
200 self.fitsObj.close()
204 self.fitsObj.close()
201
205
202
206
203 def setNextFile(self):
207 def setNextFile(self):
204
208
205 ext = self.ext
209 ext = self.ext
206 path = self.path
210 path = self.path
207
211
208 timeTuple = time.localtime( self.dataOut.utctime)
212 timeTuple = time.localtime( self.dataOut.utctime)
209 subfolder = 'd%4.4d%3.3d' % (timeTuple.tm_year,timeTuple.tm_yday)
213 subfolder = 'd%4.4d%3.3d' % (timeTuple.tm_year,timeTuple.tm_yday)
210
214
211 fullpath = os.path.join( path, subfolder )
215 fullpath = os.path.join( path, subfolder )
212 if not( os.path.exists(fullpath) ):
216 if not( os.path.exists(fullpath) ):
213 os.mkdir(fullpath)
217 os.mkdir(fullpath)
214 self.setFile = -1 #inicializo mi contador de seteo
218 self.setFile = -1 #inicializo mi contador de seteo
215 else:
219 else:
216 filesList = os.listdir( fullpath )
220 filesList = os.listdir( fullpath )
217 if len( filesList ) > 0:
221 if len( filesList ) > 0:
218 filesList = sorted( filesList, key=str.lower )
222 filesList = sorted( filesList, key=str.lower )
219 filen = filesList[-1]
223 filen = filesList[-1]
220
224
221 if isNumber( filen[8:11] ):
225 if isNumber( filen[8:11] ):
222 self.setFile = int( filen[8:11] ) #inicializo mi contador de seteo al seteo del ultimo file
226 self.setFile = int( filen[8:11] ) #inicializo mi contador de seteo al seteo del ultimo file
223 else:
227 else:
224 self.setFile = -1
228 self.setFile = -1
225 else:
229 else:
226 self.setFile = -1 #inicializo mi contador de seteo
230 self.setFile = -1 #inicializo mi contador de seteo
227
231
228 setFile = self.setFile
232 setFile = self.setFile
229 setFile += 1
233 setFile += 1
230
234
231 thisFile = '%s%4.4d%3.3d%3.3d%s' % (self.optchar,
235 thisFile = '%s%4.4d%3.3d%3.3d%s' % (self.optchar,
232 timeTuple.tm_year,
236 timeTuple.tm_year,
233 timeTuple.tm_yday,
237 timeTuple.tm_yday,
234 setFile,
238 setFile,
235 ext )
239 ext )
236
240
237 filename = os.path.join( path, subfolder, thisFile )
241 filename = os.path.join( path, subfolder, thisFile )
238
242
239 self.blockIndex = 0
243 self.blockIndex = 0
240 self.filename = filename
244 self.filename = filename
241 self.setFile = setFile
245 self.setFile = setFile
242 self.flagIsNewFile = 1
246 self.flagIsNewFile = 1
243
247
244 print 'Writing the file: %s'%self.filename
248 print 'Writing the file: %s'%self.filename
245
249
246 self.setFitsHeader(self.dataOut, self.metadatafile)
250 self.setFitsHeader(self.dataOut, self.metadatafile)
247
251
248 return 1
252 return 1
249
253
250 def writeBlock(self):
254 def writeBlock(self):
251 self.addData(self.dataOut.data_spc)
255 self.addData(self.dataOut.data_spc)
252 self.flagIsNewFile = 0
256 self.flagIsNewFile = 0
253
257
254
258
255 def __setNewBlock(self):
259 def __setNewBlock(self):
256
260
257 if self.flagIsNewFile:
261 if self.flagIsNewFile:
258 return 1
262 return 1
259
263
260 if self.blockIndex < self.dataBlocksPerFile:
264 if self.blockIndex < self.dataBlocksPerFile:
261 return 1
265 return 1
262
266
263 if not( self.setNextFile() ):
267 if not( self.setNextFile() ):
264 return 0
268 return 0
265
269
266 return 1
270 return 1
267
271
268 def writeNextBlock(self):
272 def writeNextBlock(self):
269 if not( self.__setNewBlock() ):
273 if not( self.__setNewBlock() ):
270 return 0
274 return 0
271 self.writeBlock()
275 self.writeBlock()
272 return 1
276 return 1
273
277
274 def putData(self):
278 def putData(self):
275 if self.flagIsNewFile:
279 if self.flagIsNewFile:
276 self.setNextFile()
280 self.setNextFile()
277 self.writeNextBlock()
281 self.writeNextBlock()
278
282
279 def run(self, dataOut, **kwargs):
283 def run(self, dataOut, path, dataBlocksPerFile=100, metadatafile=None, **kwargs):
280 if not(self.isConfig):
284 if not(self.isConfig):
281 self.setup(dataOut, **kwargs)
285 self.setup(dataOut, path, dataBlocksPerFile=dataBlocksPerFile, metadatafile=metadatafile, **kwargs)
282 self.isConfig = True
286 self.isConfig = True
283 self.putData()
287 self.putData()
284
288
285
289
286 class FitsReader(ProcessingUnit):
290 class FitsReader(ProcessingUnit):
287
291
288 # __TIMEZONE = time.timezone
292 # __TIMEZONE = time.timezone
289
293
290 expName = None
294 expName = None
291 datetimestr = None
295 datetimestr = None
292 utc = None
296 utc = None
293 nChannels = None
297 nChannels = None
294 nSamples = None
298 nSamples = None
295 dataBlocksPerFile = None
299 dataBlocksPerFile = None
296 comments = None
300 comments = None
297 lastUTTime = None
301 lastUTTime = None
298 header_dict = None
302 header_dict = None
299 data = None
303 data = None
300 data_header_dict = None
304 data_header_dict = None
301
305
302 def __init__(self, **kwargs):
306 def __init__(self, **kwargs):
303 ProcessingUnit.__init__(self, **kwargs)
307 ProcessingUnit.__init__(self, **kwargs)
304 self.isConfig = False
308 self.isConfig = False
305 self.ext = '.fits'
309 self.ext = '.fits'
306 self.setFile = 0
310 self.setFile = 0
307 self.flagNoMoreFiles = 0
311 self.flagNoMoreFiles = 0
308 self.flagIsNewFile = 1
312 self.flagIsNewFile = 1
309 self.flagDiscontinuousBlock = None
313 self.flagDiscontinuousBlock = None
310 self.fileIndex = None
314 self.fileIndex = None
311 self.filename = None
315 self.filename = None
312 self.fileSize = None
316 self.fileSize = None
313 self.fitsObj = None
317 self.fitsObj = None
314 self.timeZone = None
318 self.timeZone = None
315 self.nReadBlocks = 0
319 self.nReadBlocks = 0
316 self.nTotalBlocks = 0
320 self.nTotalBlocks = 0
317 self.dataOut = self.createObjByDefault()
321 self.dataOut = self.createObjByDefault()
318 self.maxTimeStep = 10# deberia ser definido por el usuario usando el metodo setup()
322 self.maxTimeStep = 10# deberia ser definido por el usuario usando el metodo setup()
319 self.blockIndex = 1
323 self.blockIndex = 1
320
324
321 def createObjByDefault(self):
325 def createObjByDefault(self):
322
326
323 dataObj = Fits()
327 dataObj = Fits()
324
328
325 return dataObj
329 return dataObj
326
330
327 def isFileinThisTime(self, filename, startTime, endTime, useLocalTime=False):
331 def isFileinThisTime(self, filename, startTime, endTime, useLocalTime=False):
328 try:
332 try:
329 fitsObj = pyfits.open(filename,'readonly')
333 fitsObj = pyfits.open(filename,'readonly')
330 except:
334 except:
331 print "File %s can't be opened" %(filename)
335 print "File %s can't be opened" %(filename)
332 return None
336 return None
333
337
334 header = fitsObj[0].header
338 header = fitsObj[0].header
335 struct_time = time.strptime(header['DATETIME'], "%b %d %Y %H:%M:%S")
339 struct_time = time.strptime(header['DATETIME'], "%b %d %Y %H:%M:%S")
336 utc = time.mktime(struct_time) - time.timezone #TIMEZONE debe ser un parametro del header FITS
340 utc = time.mktime(struct_time) - time.timezone #TIMEZONE debe ser un parametro del header FITS
337
341
338 ltc = utc
342 ltc = utc
339 if useLocalTime:
343 if useLocalTime:
340 ltc -= time.timezone
344 ltc -= time.timezone
341 thisDatetime = datetime.datetime.utcfromtimestamp(ltc)
345 thisDatetime = datetime.datetime.utcfromtimestamp(ltc)
342 thisTime = thisDatetime.time()
346 thisTime = thisDatetime.time()
343
347
344 if not ((startTime <= thisTime) and (endTime > thisTime)):
348 if not ((startTime <= thisTime) and (endTime > thisTime)):
345 return None
349 return None
346
350
347 return thisDatetime
351 return thisDatetime
348
352
349 def __setNextFileOnline(self):
353 def __setNextFileOnline(self):
350 raise NotImplementedError
354 raise NotImplementedError
351
355
352 def __setNextFileOffline(self):
356 def __setNextFileOffline(self):
353 idFile = self.fileIndex
357 idFile = self.fileIndex
354
358
355 while (True):
359 while (True):
356 idFile += 1
360 idFile += 1
357 if not(idFile < len(self.filenameList)):
361 if not(idFile < len(self.filenameList)):
358 self.flagNoMoreFiles = 1
362 self.flagNoMoreFiles = 1
359 print "No more Files"
363 print "No more Files"
360 return 0
364 return 0
361
365
362 filename = self.filenameList[idFile]
366 filename = self.filenameList[idFile]
363
367
364 # if not(self.__verifyFile(filename)):
368 # if not(self.__verifyFile(filename)):
365 # continue
369 # continue
366
370
367 fileSize = os.path.getsize(filename)
371 fileSize = os.path.getsize(filename)
368 fitsObj = pyfits.open(filename,'readonly')
372 fitsObj = pyfits.open(filename,'readonly')
369 break
373 break
370
374
371 self.flagIsNewFile = 1
375 self.flagIsNewFile = 1
372 self.fileIndex = idFile
376 self.fileIndex = idFile
373 self.filename = filename
377 self.filename = filename
374 self.fileSize = fileSize
378 self.fileSize = fileSize
375 self.fitsObj = fitsObj
379 self.fitsObj = fitsObj
376 self.blockIndex = 0
380 self.blockIndex = 0
377 print "Setting the file: %s"%self.filename
381 print "Setting the file: %s"%self.filename
378
382
379 return 1
383 return 1
380
384
381 def __setValuesFromHeader(self):
385 def __setValuesFromHeader(self):
382
386
383 self.dataOut.header = self.header_dict
387 self.dataOut.header = self.header_dict
384 self.dataOut.expName = self.expName
388 self.dataOut.expName = self.expName
385
389
386 self.dataOut.timeZone = self.timeZone
390 self.dataOut.timeZone = self.timeZone
387 self.dataOut.dataBlocksPerFile = self.dataBlocksPerFile
391 self.dataOut.dataBlocksPerFile = self.dataBlocksPerFile
388 self.dataOut.comments = self.comments
392 self.dataOut.comments = self.comments
389 # self.dataOut.timeInterval = self.timeInterval
393 # self.dataOut.timeInterval = self.timeInterval
390 self.dataOut.channelList = self.channelList
394 self.dataOut.channelList = self.channelList
391 self.dataOut.heightList = self.heightList
395 self.dataOut.heightList = self.heightList
392
396
393 self.dataOut.nCohInt = self.nCohInt
397 self.dataOut.nCohInt = self.nCohInt
394 self.dataOut.nIncohInt = self.nIncohInt
398 self.dataOut.nIncohInt = self.nIncohInt
395
399
396 self.dataOut.ippSeconds = self.ippSeconds
400 self.dataOut.ippSeconds = self.ippSeconds
397
401
398 def readHeader(self):
402 def readHeader(self):
399 headerObj = self.fitsObj[0]
403 headerObj = self.fitsObj[0]
400
404
401 self.header_dict = headerObj.header
405 self.header_dict = headerObj.header
402 if 'EXPNAME' in headerObj.header.keys():
406 if 'EXPNAME' in headerObj.header.keys():
403 self.expName = headerObj.header['EXPNAME']
407 self.expName = headerObj.header['EXPNAME']
404
408
405 if 'DATATYPE' in headerObj.header.keys():
409 if 'DATATYPE' in headerObj.header.keys():
406 self.dataType = headerObj.header['DATATYPE']
410 self.dataType = headerObj.header['DATATYPE']
407
411
408 self.datetimestr = headerObj.header['DATETIME']
412 self.datetimestr = headerObj.header['DATETIME']
409 channelList = headerObj.header['CHANNELLIST']
413 channelList = headerObj.header['CHANNELLIST']
410 channelList = channelList.split('[')
414 channelList = channelList.split('[')
411 channelList = channelList[1].split(']')
415 channelList = channelList[1].split(']')
412 channelList = channelList[0].split(',')
416 channelList = channelList[0].split(',')
413 channelList = [int(ch) for ch in channelList]
417 channelList = [int(ch) for ch in channelList]
414 self.channelList = channelList
418 self.channelList = channelList
415 self.nChannels = headerObj.header['NCHANNELS']
419 self.nChannels = headerObj.header['NCHANNELS']
416 self.nHeights = headerObj.header['NHEIGHTS']
420 self.nHeights = headerObj.header['NHEIGHTS']
417 self.ippSeconds = headerObj.header['IPPSECONDS']
421 self.ippSeconds = headerObj.header['IPPSECONDS']
418 self.nCohInt = headerObj.header['NCOHINT']
422 self.nCohInt = headerObj.header['NCOHINT']
419 self.nIncohInt = headerObj.header['NINCOHINT']
423 self.nIncohInt = headerObj.header['NINCOHINT']
420 self.dataBlocksPerFile = headerObj.header['NBLOCK']
424 self.dataBlocksPerFile = headerObj.header['NBLOCK']
421 self.timeZone = headerObj.header['TIMEZONE']
425 self.timeZone = headerObj.header['TIMEZONE']
422
426
423 # self.timeInterval = self.ippSeconds * self.nCohInt * self.nIncohInt
427 # self.timeInterval = self.ippSeconds * self.nCohInt * self.nIncohInt
424
428
425 if 'COMMENT' in headerObj.header.keys():
429 if 'COMMENT' in headerObj.header.keys():
426 self.comments = headerObj.header['COMMENT']
430 self.comments = headerObj.header['COMMENT']
427
431
428 self.readHeightList()
432 self.readHeightList()
429
433
430 def readHeightList(self):
434 def readHeightList(self):
431 self.blockIndex = self.blockIndex + 1
435 self.blockIndex = self.blockIndex + 1
432 obj = self.fitsObj[self.blockIndex]
436 obj = self.fitsObj[self.blockIndex]
433 self.heightList = obj.data
437 self.heightList = obj.data
434 self.blockIndex = self.blockIndex + 1
438 self.blockIndex = self.blockIndex + 1
435
439
436 def readExtension(self):
440 def readExtension(self):
437 obj = self.fitsObj[self.blockIndex]
441 obj = self.fitsObj[self.blockIndex]
438 self.heightList = obj.data
442 self.heightList = obj.data
439 self.blockIndex = self.blockIndex + 1
443 self.blockIndex = self.blockIndex + 1
440
444
441 def setNextFile(self):
445 def setNextFile(self):
442
446
443 if self.online:
447 if self.online:
444 newFile = self.__setNextFileOnline()
448 newFile = self.__setNextFileOnline()
445 else:
449 else:
446 newFile = self.__setNextFileOffline()
450 newFile = self.__setNextFileOffline()
447
451
448 if not(newFile):
452 if not(newFile):
449 return 0
453 return 0
450
454
451 self.readHeader()
455 self.readHeader()
452 self.__setValuesFromHeader()
456 self.__setValuesFromHeader()
453 self.nReadBlocks = 0
457 self.nReadBlocks = 0
454 # self.blockIndex = 1
458 # self.blockIndex = 1
455 return 1
459 return 1
456
460
457 def __searchFilesOffLine(self,
461 def __searchFilesOffLine(self,
458 path,
462 path,
459 startDate,
463 startDate,
460 endDate,
464 endDate,
461 startTime=datetime.time(0,0,0),
465 startTime=datetime.time(0,0,0),
462 endTime=datetime.time(23,59,59),
466 endTime=datetime.time(23,59,59),
463 set=None,
467 set=None,
464 expLabel='',
468 expLabel='',
465 ext='.fits',
469 ext='.fits',
466 walk=True):
470 walk=True):
467
471
468 pathList = []
472 pathList = []
469
473
470 if not walk:
474 if not walk:
471 pathList.append(path)
475 pathList.append(path)
472
476
473 else:
477 else:
474 dirList = []
478 dirList = []
475 for thisPath in os.listdir(path):
479 for thisPath in os.listdir(path):
476 if not os.path.isdir(os.path.join(path,thisPath)):
480 if not os.path.isdir(os.path.join(path,thisPath)):
477 continue
481 continue
478 if not isRadarFolder(thisPath):
482 if not isRadarFolder(thisPath):
479 continue
483 continue
480
484
481 dirList.append(thisPath)
485 dirList.append(thisPath)
482
486
483 if not(dirList):
487 if not(dirList):
484 return None, None
488 return None, None
485
489
486 thisDate = startDate
490 thisDate = startDate
487
491
488 while(thisDate <= endDate):
492 while(thisDate <= endDate):
489 year = thisDate.timetuple().tm_year
493 year = thisDate.timetuple().tm_year
490 doy = thisDate.timetuple().tm_yday
494 doy = thisDate.timetuple().tm_yday
491
495
492 matchlist = fnmatch.filter(dirList, '?' + '%4.4d%3.3d' % (year,doy) + '*')
496 matchlist = fnmatch.filter(dirList, '?' + '%4.4d%3.3d' % (year,doy) + '*')
493 if len(matchlist) == 0:
497 if len(matchlist) == 0:
494 thisDate += datetime.timedelta(1)
498 thisDate += datetime.timedelta(1)
495 continue
499 continue
496 for match in matchlist:
500 for match in matchlist:
497 pathList.append(os.path.join(path,match,expLabel))
501 pathList.append(os.path.join(path,match,expLabel))
498
502
499 thisDate += datetime.timedelta(1)
503 thisDate += datetime.timedelta(1)
500
504
501 if pathList == []:
505 if pathList == []:
502 print "Any folder was found for the date range: %s-%s" %(startDate, endDate)
506 print "Any folder was found for the date range: %s-%s" %(startDate, endDate)
503 return None, None
507 return None, None
504
508
505 print "%d folder(s) was(were) found for the date range: %s - %s" %(len(pathList), startDate, endDate)
509 print "%d folder(s) was(were) found for the date range: %s - %s" %(len(pathList), startDate, endDate)
506
510
507 filenameList = []
511 filenameList = []
508 datetimeList = []
512 datetimeList = []
509
513
510 for i in range(len(pathList)):
514 for i in range(len(pathList)):
511
515
512 thisPath = pathList[i]
516 thisPath = pathList[i]
513
517
514 fileList = glob.glob1(thisPath, "*%s" %ext)
518 fileList = glob.glob1(thisPath, "*%s" %ext)
515 fileList.sort()
519 fileList.sort()
516
520
517 for thisFile in fileList:
521 for thisFile in fileList:
518
522
519 filename = os.path.join(thisPath,thisFile)
523 filename = os.path.join(thisPath,thisFile)
520 thisDatetime = self.isFileinThisTime(filename, startTime, endTime)
524 thisDatetime = self.isFileinThisTime(filename, startTime, endTime)
521
525
522 if not(thisDatetime):
526 if not(thisDatetime):
523 continue
527 continue
524
528
525 filenameList.append(filename)
529 filenameList.append(filename)
526 datetimeList.append(thisDatetime)
530 datetimeList.append(thisDatetime)
527
531
528 if not(filenameList):
532 if not(filenameList):
529 print "Any file was found for the time range %s - %s" %(startTime, endTime)
533 print "Any file was found for the time range %s - %s" %(startTime, endTime)
530 return None, None
534 return None, None
531
535
532 print "%d file(s) was(were) found for the time range: %s - %s" %(len(filenameList), startTime, endTime)
536 print "%d file(s) was(were) found for the time range: %s - %s" %(len(filenameList), startTime, endTime)
533 print
537 print
534
538
535 for i in range(len(filenameList)):
539 for i in range(len(filenameList)):
536 print "%s -> [%s]" %(filenameList[i], datetimeList[i].ctime())
540 print "%s -> [%s]" %(filenameList[i], datetimeList[i].ctime())
537
541
538 self.filenameList = filenameList
542 self.filenameList = filenameList
539 self.datetimeList = datetimeList
543 self.datetimeList = datetimeList
540
544
541 return pathList, filenameList
545 return pathList, filenameList
542
546
543 def setup(self, path=None,
547 def setup(self, path=None,
544 startDate=None,
548 startDate=None,
545 endDate=None,
549 endDate=None,
546 startTime=datetime.time(0,0,0),
550 startTime=datetime.time(0,0,0),
547 endTime=datetime.time(23,59,59),
551 endTime=datetime.time(23,59,59),
548 set=0,
552 set=0,
549 expLabel = "",
553 expLabel = "",
550 ext = None,
554 ext = None,
551 online = False,
555 online = False,
552 delay = 60,
556 delay = 60,
553 walk = True):
557 walk = True):
554
558
555 if path == None:
559 if path == None:
556 raise ValueError, "The path is not valid"
560 raise ValueError, "The path is not valid"
557
561
558 if ext == None:
562 if ext == None:
559 ext = self.ext
563 ext = self.ext
560
564
561 if not(online):
565 if not(online):
562 print "Searching files in offline mode ..."
566 print "Searching files in offline mode ..."
563 pathList, filenameList = self.__searchFilesOffLine(path, startDate=startDate, endDate=endDate,
567 pathList, filenameList = self.__searchFilesOffLine(path, startDate=startDate, endDate=endDate,
564 startTime=startTime, endTime=endTime,
568 startTime=startTime, endTime=endTime,
565 set=set, expLabel=expLabel, ext=ext,
569 set=set, expLabel=expLabel, ext=ext,
566 walk=walk)
570 walk=walk)
567
571
568 if not(pathList):
572 if not(pathList):
569 print "No *%s files into the folder %s \nfor the range: %s - %s"%(ext, path,
573 print "No *%s files into the folder %s \nfor the range: %s - %s"%(ext, path,
570 datetime.datetime.combine(startDate,startTime).ctime(),
574 datetime.datetime.combine(startDate,startTime).ctime(),
571 datetime.datetime.combine(endDate,endTime).ctime())
575 datetime.datetime.combine(endDate,endTime).ctime())
572
576
573 sys.exit(-1)
577 sys.exit(-1)
574
578
575 self.fileIndex = -1
579 self.fileIndex = -1
576 self.pathList = pathList
580 self.pathList = pathList
577 self.filenameList = filenameList
581 self.filenameList = filenameList
578
582
579 self.online = online
583 self.online = online
580 self.delay = delay
584 self.delay = delay
581 ext = ext.lower()
585 ext = ext.lower()
582 self.ext = ext
586 self.ext = ext
583
587
584 if not(self.setNextFile()):
588 if not(self.setNextFile()):
585 if (startDate!=None) and (endDate!=None):
589 if (startDate!=None) and (endDate!=None):
586 print "No files in range: %s - %s" %(datetime.datetime.combine(startDate,startTime).ctime(), datetime.datetime.combine(endDate,endTime).ctime())
590 print "No files in range: %s - %s" %(datetime.datetime.combine(startDate,startTime).ctime(), datetime.datetime.combine(endDate,endTime).ctime())
587 elif startDate != None:
591 elif startDate != None:
588 print "No files in range: %s" %(datetime.datetime.combine(startDate,startTime).ctime())
592 print "No files in range: %s" %(datetime.datetime.combine(startDate,startTime).ctime())
589 else:
593 else:
590 print "No files"
594 print "No files"
591
595
592 sys.exit(-1)
596 sys.exit(-1)
593
597
594
598
595
599
596 def readBlock(self):
600 def readBlock(self):
597 dataObj = self.fitsObj[self.blockIndex]
601 dataObj = self.fitsObj[self.blockIndex]
598
602
599 self.data = dataObj.data
603 self.data = dataObj.data
600 self.data_header_dict = dataObj.header
604 self.data_header_dict = dataObj.header
601 self.utc = self.data_header_dict['UTCTIME']
605 self.utc = self.data_header_dict['UTCTIME']
602
606
603 self.flagIsNewFile = 0
607 self.flagIsNewFile = 0
604 self.blockIndex += 1
608 self.blockIndex += 1
605 self.nTotalBlocks += 1
609 self.nTotalBlocks += 1
606 self.nReadBlocks += 1
610 self.nReadBlocks += 1
607
611
608 return 1
612 return 1
609
613
610 def __jumpToLastBlock(self):
614 def __jumpToLastBlock(self):
611 raise NotImplementedError
615 raise NotImplementedError
612
616
613 def __waitNewBlock(self):
617 def __waitNewBlock(self):
614 """
618 """
615 Return 1 si se encontro un nuevo bloque de datos, 0 de otra forma.
619 Return 1 si se encontro un nuevo bloque de datos, 0 de otra forma.
616
620
617 Si el modo de lectura es OffLine siempre retorn 0
621 Si el modo de lectura es OffLine siempre retorn 0
618 """
622 """
619 if not self.online:
623 if not self.online:
620 return 0
624 return 0
621
625
622 if (self.nReadBlocks >= self.dataBlocksPerFile):
626 if (self.nReadBlocks >= self.dataBlocksPerFile):
623 return 0
627 return 0
624
628
625 currentPointer = self.fp.tell()
629 currentPointer = self.fp.tell()
626
630
627 neededSize = self.processingHeaderObj.blockSize + self.basicHeaderSize
631 neededSize = self.processingHeaderObj.blockSize + self.basicHeaderSize
628
632
629 for nTries in range( self.nTries ):
633 for nTries in range( self.nTries ):
630
634
631 self.fp.close()
635 self.fp.close()
632 self.fp = open( self.filename, 'rb' )
636 self.fp = open( self.filename, 'rb' )
633 self.fp.seek( currentPointer )
637 self.fp.seek( currentPointer )
634
638
635 self.fileSize = os.path.getsize( self.filename )
639 self.fileSize = os.path.getsize( self.filename )
636 currentSize = self.fileSize - currentPointer
640 currentSize = self.fileSize - currentPointer
637
641
638 if ( currentSize >= neededSize ):
642 if ( currentSize >= neededSize ):
639 self.__rdBasicHeader()
643 self.__rdBasicHeader()
640 return 1
644 return 1
641
645
642 print "\tWaiting %0.2f seconds for the next block, try %03d ..." % (self.delay, nTries+1)
646 print "\tWaiting %0.2f seconds for the next block, try %03d ..." % (self.delay, nTries+1)
643 sleep( self.delay )
647 sleep( self.delay )
644
648
645
649
646 return 0
650 return 0
647
651
648 def __setNewBlock(self):
652 def __setNewBlock(self):
649
653
650 if self.online:
654 if self.online:
651 self.__jumpToLastBlock()
655 self.__jumpToLastBlock()
652
656
653 if self.flagIsNewFile:
657 if self.flagIsNewFile:
654 return 1
658 return 1
655
659
656 self.lastUTTime = self.utc
660 self.lastUTTime = self.utc
657
661
658 if self.online:
662 if self.online:
659 if self.__waitNewBlock():
663 if self.__waitNewBlock():
660 return 1
664 return 1
661
665
662 if self.nReadBlocks < self.dataBlocksPerFile:
666 if self.nReadBlocks < self.dataBlocksPerFile:
663 return 1
667 return 1
664
668
665 if not(self.setNextFile()):
669 if not(self.setNextFile()):
666 return 0
670 return 0
667
671
668 deltaTime = self.utc - self.lastUTTime
672 deltaTime = self.utc - self.lastUTTime
669
673
670 self.flagDiscontinuousBlock = 0
674 self.flagDiscontinuousBlock = 0
671
675
672 if deltaTime > self.maxTimeStep:
676 if deltaTime > self.maxTimeStep:
673 self.flagDiscontinuousBlock = 1
677 self.flagDiscontinuousBlock = 1
674
678
675 return 1
679 return 1
676
680
677
681
678 def readNextBlock(self):
682 def readNextBlock(self):
679 if not(self.__setNewBlock()):
683 if not(self.__setNewBlock()):
680 return 0
684 return 0
681
685
682 if not(self.readBlock()):
686 if not(self.readBlock()):
683 return 0
687 return 0
684
688
685 return 1
689 return 1
686
690
687 def printInfo(self):
691 def printInfo(self):
688
692
689 pass
693 pass
690
694
691 def getData(self):
695 def getData(self):
692
696
693 if self.flagNoMoreFiles:
697 if self.flagNoMoreFiles:
694 self.dataOut.flagNoData = True
698 self.dataOut.flagNoData = True
695 print 'Process finished'
699 print 'Process finished'
696 return 0
700 return 0
697
701
698 self.flagDiscontinuousBlock = 0
702 self.flagDiscontinuousBlock = 0
699 self.flagIsNewBlock = 0
703 self.flagIsNewBlock = 0
700
704
701 if not(self.readNextBlock()):
705 if not(self.readNextBlock()):
702 return 0
706 return 0
703
707
704 if self.data is None:
708 if self.data is None:
705 self.dataOut.flagNoData = True
709 self.dataOut.flagNoData = True
706 return 0
710 return 0
707
711
708 self.dataOut.data = self.data
712 self.dataOut.data = self.data
709 self.dataOut.data_header = self.data_header_dict
713 self.dataOut.data_header = self.data_header_dict
710 self.dataOut.utctime = self.utc
714 self.dataOut.utctime = self.utc
711
715
712 # self.dataOut.header = self.header_dict
716 # self.dataOut.header = self.header_dict
713 # self.dataOut.expName = self.expName
717 # self.dataOut.expName = self.expName
714 # self.dataOut.nChannels = self.nChannels
718 # self.dataOut.nChannels = self.nChannels
715 # self.dataOut.timeZone = self.timeZone
719 # self.dataOut.timeZone = self.timeZone
716 # self.dataOut.dataBlocksPerFile = self.dataBlocksPerFile
720 # self.dataOut.dataBlocksPerFile = self.dataBlocksPerFile
717 # self.dataOut.comments = self.comments
721 # self.dataOut.comments = self.comments
718 # # self.dataOut.timeInterval = self.timeInterval
722 # # self.dataOut.timeInterval = self.timeInterval
719 # self.dataOut.channelList = self.channelList
723 # self.dataOut.channelList = self.channelList
720 # self.dataOut.heightList = self.heightList
724 # self.dataOut.heightList = self.heightList
721 self.dataOut.flagNoData = False
725 self.dataOut.flagNoData = False
722
726
723 return self.dataOut.data
727 return self.dataOut.data
724
728
725 def run(self, **kwargs):
729 def run(self, **kwargs):
726
730
727 if not(self.isConfig):
731 if not(self.isConfig):
728 self.setup(**kwargs)
732 self.setup(**kwargs)
729 self.isConfig = True
733 self.isConfig = True
730
734
731 self.getData()
735 self.getData()
732
736
733 class SpectraHeisWriter(Operation):
737 class SpectraHeisWriter(Operation):
734 # set = None
738 # set = None
735 setFile = None
739 setFile = None
736 idblock = None
740 idblock = None
737 doypath = None
741 doypath = None
738 subfolder = None
742 subfolder = None
739
743
740 def __init__(self, **kwargs):
744 def __init__(self, **kwargs):
741 Operation.__init__(self, **kwargs)
745 Operation.__init__(self, **kwargs)
742 self.wrObj = PyFits()
746 self.wrObj = PyFits()
743 # self.dataOut = dataOut
747 # self.dataOut = dataOut
744 self.nTotalBlocks=0
748 self.nTotalBlocks=0
745 # self.set = None
749 # self.set = None
746 self.setFile = None
750 self.setFile = None
747 self.idblock = 0
751 self.idblock = 0
748 self.wrpath = None
752 self.wrpath = None
749 self.doypath = None
753 self.doypath = None
750 self.subfolder = None
754 self.subfolder = None
751 self.isConfig = False
755 self.isConfig = False
752
756
753 def isNumber(str):
757 def isNumber(str):
754 """
758 """
755 Chequea si el conjunto de caracteres que componen un string puede ser convertidos a un numero.
759 Chequea si el conjunto de caracteres que componen un string puede ser convertidos a un numero.
756
760
757 Excepciones:
761 Excepciones:
758 Si un determinado string no puede ser convertido a numero
762 Si un determinado string no puede ser convertido a numero
759 Input:
763 Input:
760 str, string al cual se le analiza para determinar si convertible a un numero o no
764 str, string al cual se le analiza para determinar si convertible a un numero o no
761
765
762 Return:
766 Return:
763 True : si el string es uno numerico
767 True : si el string es uno numerico
764 False : no es un string numerico
768 False : no es un string numerico
765 """
769 """
766 try:
770 try:
767 float( str )
771 float( str )
768 return True
772 return True
769 except:
773 except:
770 return False
774 return False
771
775
772 def setup(self, dataOut, wrpath):
776 def setup(self, dataOut, wrpath):
773
777
774 if not(os.path.exists(wrpath)):
778 if not(os.path.exists(wrpath)):
775 os.mkdir(wrpath)
779 os.mkdir(wrpath)
776
780
777 self.wrpath = wrpath
781 self.wrpath = wrpath
778 # self.setFile = 0
782 # self.setFile = 0
779 self.dataOut = dataOut
783 self.dataOut = dataOut
780
784
781 def putData(self):
785 def putData(self):
782 name= time.localtime( self.dataOut.utctime)
786 name= time.localtime( self.dataOut.utctime)
783 ext=".fits"
787 ext=".fits"
784
788
785 if self.doypath == None:
789 if self.doypath == None:
786 self.subfolder = 'F%4.4d%3.3d_%d' % (name.tm_year,name.tm_yday,time.mktime(datetime.datetime.now().timetuple()))
790 self.subfolder = 'F%4.4d%3.3d_%d' % (name.tm_year,name.tm_yday,time.mktime(datetime.datetime.now().timetuple()))
787 self.doypath = os.path.join( self.wrpath, self.subfolder )
791 self.doypath = os.path.join( self.wrpath, self.subfolder )
788 os.mkdir(self.doypath)
792 os.mkdir(self.doypath)
789
793
790 if self.setFile == None:
794 if self.setFile == None:
791 # self.set = self.dataOut.set
795 # self.set = self.dataOut.set
792 self.setFile = 0
796 self.setFile = 0
793 # if self.set != self.dataOut.set:
797 # if self.set != self.dataOut.set:
794 ## self.set = self.dataOut.set
798 ## self.set = self.dataOut.set
795 # self.setFile = 0
799 # self.setFile = 0
796
800
797 #make the filename
801 #make the filename
798 thisFile = 'D%4.4d%3.3d_%3.3d%s' % (name.tm_year,name.tm_yday,self.setFile,ext)
802 thisFile = 'D%4.4d%3.3d_%3.3d%s' % (name.tm_year,name.tm_yday,self.setFile,ext)
799
803
800 filename = os.path.join(self.wrpath,self.subfolder, thisFile)
804 filename = os.path.join(self.wrpath,self.subfolder, thisFile)
801
805
802 idblock = numpy.array([self.idblock],dtype="int64")
806 idblock = numpy.array([self.idblock],dtype="int64")
803 header=self.wrObj.cFImage(idblock=idblock,
807 header=self.wrObj.cFImage(idblock=idblock,
804 year=time.gmtime(self.dataOut.utctime).tm_year,
808 year=time.gmtime(self.dataOut.utctime).tm_year,
805 month=time.gmtime(self.dataOut.utctime).tm_mon,
809 month=time.gmtime(self.dataOut.utctime).tm_mon,
806 day=time.gmtime(self.dataOut.utctime).tm_mday,
810 day=time.gmtime(self.dataOut.utctime).tm_mday,
807 hour=time.gmtime(self.dataOut.utctime).tm_hour,
811 hour=time.gmtime(self.dataOut.utctime).tm_hour,
808 minute=time.gmtime(self.dataOut.utctime).tm_min,
812 minute=time.gmtime(self.dataOut.utctime).tm_min,
809 second=time.gmtime(self.dataOut.utctime).tm_sec)
813 second=time.gmtime(self.dataOut.utctime).tm_sec)
810
814
811 c=3E8
815 c=3E8
812 deltaHeight = self.dataOut.heightList[1] - self.dataOut.heightList[0]
816 deltaHeight = self.dataOut.heightList[1] - self.dataOut.heightList[0]
813 freq=numpy.arange(-1*self.dataOut.nHeights/2.,self.dataOut.nHeights/2.)*(c/(2*deltaHeight*1000))
817 freq=numpy.arange(-1*self.dataOut.nHeights/2.,self.dataOut.nHeights/2.)*(c/(2*deltaHeight*1000))
814
818
815 colList = []
819 colList = []
816
820
817 colFreq=self.wrObj.setColF(name="freq", format=str(self.dataOut.nFFTPoints)+'E', array=freq)
821 colFreq=self.wrObj.setColF(name="freq", format=str(self.dataOut.nFFTPoints)+'E', array=freq)
818
822
819 colList.append(colFreq)
823 colList.append(colFreq)
820
824
821 nchannel=self.dataOut.nChannels
825 nchannel=self.dataOut.nChannels
822
826
823 for i in range(nchannel):
827 for i in range(nchannel):
824 col = self.wrObj.writeData(name="PCh"+str(i+1),
828 col = self.wrObj.writeData(name="PCh"+str(i+1),
825 format=str(self.dataOut.nFFTPoints)+'E',
829 format=str(self.dataOut.nFFTPoints)+'E',
826 data=10*numpy.log10(self.dataOut.data_spc[i,:]))
830 data=10*numpy.log10(self.dataOut.data_spc[i,:]))
827
831
828 colList.append(col)
832 colList.append(col)
829
833
830 data=self.wrObj.Ctable(colList=colList)
834 data=self.wrObj.Ctable(colList=colList)
831
835
832 self.wrObj.CFile(header,data)
836 self.wrObj.CFile(header,data)
833
837
834 self.wrObj.wFile(filename)
838 self.wrObj.wFile(filename)
835
839
836 #update the setFile
840 #update the setFile
837 self.setFile += 1
841 self.setFile += 1
838 self.idblock += 1
842 self.idblock += 1
839
843
840 return 1
844 return 1
841
845
842 def run(self, dataOut, **kwargs):
846 def run(self, dataOut, **kwargs):
843
847
844 if not(self.isConfig):
848 if not(self.isConfig):
845
849
846 self.setup(dataOut, **kwargs)
850 self.setup(dataOut, **kwargs)
847 self.isConfig = True
851 self.isConfig = True
848
852
849 self.putData()
853 self.putData()
@@ -1,1105 +1,1103
1 import numpy
1 import numpy
2 import time
2 import time
3 import os
3 import os
4 import h5py
4 import h5py
5 import re
5 import re
6 import datetime
6 import datetime
7
7
8 from schainpy.model.data.jrodata import *
8 from schainpy.model.data.jrodata import *
9 from schainpy.model.proc.jroproc_base import ProcessingUnit, Operation
9 from schainpy.model.proc.jroproc_base import ProcessingUnit, Operation
10 # from jroIO_base import *
10 # from jroIO_base import *
11 from schainpy.model.io.jroIO_base import *
11 from schainpy.model.io.jroIO_base import *
12 import schainpy
12 import schainpy
13
13
14
14
15 class ParamReader(ProcessingUnit):
15 class ParamReader(ProcessingUnit):
16 '''
16 '''
17 Reads HDF5 format files
17 Reads HDF5 format files
18
18
19 path
19 path
20
20
21 startDate
21 startDate
22
22
23 endDate
23 endDate
24
24
25 startTime
25 startTime
26
26
27 endTime
27 endTime
28 '''
28 '''
29
29
30 ext = ".hdf5"
30 ext = ".hdf5"
31
31
32 optchar = "D"
32 optchar = "D"
33
33
34 timezone = None
34 timezone = None
35
35
36 startTime = None
36 startTime = None
37
37
38 endTime = None
38 endTime = None
39
39
40 fileIndex = None
40 fileIndex = None
41
41
42 utcList = None #To select data in the utctime list
42 utcList = None #To select data in the utctime list
43
43
44 blockList = None #List to blocks to be read from the file
44 blockList = None #List to blocks to be read from the file
45
45
46 blocksPerFile = None #Number of blocks to be read
46 blocksPerFile = None #Number of blocks to be read
47
47
48 blockIndex = None
48 blockIndex = None
49
49
50 path = None
50 path = None
51
51
52 #List of Files
52 #List of Files
53
53
54 filenameList = None
54 filenameList = None
55
55
56 datetimeList = None
56 datetimeList = None
57
57
58 #Hdf5 File
58 #Hdf5 File
59
59
60 listMetaname = None
60 listMetaname = None
61
61
62 listMeta = None
62 listMeta = None
63
63
64 listDataname = None
64 listDataname = None
65
65
66 listData = None
66 listData = None
67
67
68 listShapes = None
68 listShapes = None
69
69
70 fp = None
70 fp = None
71
71
72 #dataOut reconstruction
72 #dataOut reconstruction
73
73
74 dataOut = None
74 dataOut = None
75
75
76
76
77 def __init__(self, **kwargs):
77 def __init__(self, **kwargs):
78 ProcessingUnit.__init__(self, **kwargs)
78 ProcessingUnit.__init__(self, **kwargs)
79 self.dataOut = Parameters()
79 self.dataOut = Parameters()
80 return
80 return
81
81
82 def setup(self, **kwargs):
82 def setup(self, **kwargs):
83
83
84 path = kwargs['path']
84 path = kwargs['path']
85 startDate = kwargs['startDate']
85 startDate = kwargs['startDate']
86 endDate = kwargs['endDate']
86 endDate = kwargs['endDate']
87 startTime = kwargs['startTime']
87 startTime = kwargs['startTime']
88 endTime = kwargs['endTime']
88 endTime = kwargs['endTime']
89 walk = kwargs['walk']
89 walk = kwargs['walk']
90 if kwargs.has_key('ext'):
90 if kwargs.has_key('ext'):
91 ext = kwargs['ext']
91 ext = kwargs['ext']
92 else:
92 else:
93 ext = '.hdf5'
93 ext = '.hdf5'
94 if kwargs.has_key('timezone'):
94 if kwargs.has_key('timezone'):
95 self.timezone = kwargs['timezone']
95 self.timezone = kwargs['timezone']
96 else:
96 else:
97 self.timezone = 'lt'
97 self.timezone = 'lt'
98
98
99 print "[Reading] Searching files in offline mode ..."
99 print "[Reading] Searching files in offline mode ..."
100 pathList, filenameList = self.__searchFilesOffLine(path, startDate=startDate, endDate=endDate,
100 pathList, filenameList = self.__searchFilesOffLine(path, startDate=startDate, endDate=endDate,
101 startTime=startTime, endTime=endTime,
101 startTime=startTime, endTime=endTime,
102 ext=ext, walk=walk)
102 ext=ext, walk=walk)
103
103
104 if not(filenameList):
104 if not(filenameList):
105 print "There is no files into the folder: %s"%(path)
105 print "There is no files into the folder: %s"%(path)
106 sys.exit(-1)
106 sys.exit(-1)
107
107
108 self.fileIndex = -1
108 self.fileIndex = -1
109 self.startTime = startTime
109 self.startTime = startTime
110 self.endTime = endTime
110 self.endTime = endTime
111
111
112 self.__readMetadata()
112 self.__readMetadata()
113
113
114 self.__setNextFileOffline()
114 self.__setNextFileOffline()
115
115
116 return
116 return
117
117
118 def __searchFilesOffLine(self,
118 def __searchFilesOffLine(self,
119 path,
119 path,
120 startDate=None,
120 startDate=None,
121 endDate=None,
121 endDate=None,
122 startTime=datetime.time(0,0,0),
122 startTime=datetime.time(0,0,0),
123 endTime=datetime.time(23,59,59),
123 endTime=datetime.time(23,59,59),
124 ext='.hdf5',
124 ext='.hdf5',
125 walk=True):
125 walk=True):
126
126
127 expLabel = ''
127 expLabel = ''
128 self.filenameList = []
128 self.filenameList = []
129 self.datetimeList = []
129 self.datetimeList = []
130
130
131 pathList = []
131 pathList = []
132
132
133 JRODataObj = JRODataReader()
133 JRODataObj = JRODataReader()
134 dateList, pathList = JRODataObj.findDatafiles(path, startDate, endDate, expLabel, ext, walk, include_path=True)
134 dateList, pathList = JRODataObj.findDatafiles(path, startDate, endDate, expLabel, ext, walk, include_path=True)
135
135
136 if dateList == []:
136 if dateList == []:
137 print "[Reading] No *%s files in %s from %s to %s)"%(ext, path,
137 print "[Reading] No *%s files in %s from %s to %s)"%(ext, path,
138 datetime.datetime.combine(startDate,startTime).ctime(),
138 datetime.datetime.combine(startDate,startTime).ctime(),
139 datetime.datetime.combine(endDate,endTime).ctime())
139 datetime.datetime.combine(endDate,endTime).ctime())
140
140
141 return None, None
141 return None, None
142
142
143 if len(dateList) > 1:
143 if len(dateList) > 1:
144 print "[Reading] %d days were found in date range: %s - %s" %(len(dateList), startDate, endDate)
144 print "[Reading] %d days were found in date range: %s - %s" %(len(dateList), startDate, endDate)
145 else:
145 else:
146 print "[Reading] data was found for the date %s" %(dateList[0])
146 print "[Reading] data was found for the date %s" %(dateList[0])
147
147
148 filenameList = []
148 filenameList = []
149 datetimeList = []
149 datetimeList = []
150
150
151 #----------------------------------------------------------------------------------
151 #----------------------------------------------------------------------------------
152
152
153 for thisPath in pathList:
153 for thisPath in pathList:
154 # thisPath = pathList[pathDict[file]]
154 # thisPath = pathList[pathDict[file]]
155
155
156 fileList = glob.glob1(thisPath, "*%s" %ext)
156 fileList = glob.glob1(thisPath, "*%s" %ext)
157 fileList.sort()
157 fileList.sort()
158
158
159 for file in fileList:
159 for file in fileList:
160
160
161 filename = os.path.join(thisPath,file)
161 filename = os.path.join(thisPath,file)
162
162
163 if not isFileInDateRange(filename, startDate, endDate):
163 if not isFileInDateRange(filename, startDate, endDate):
164 continue
164 continue
165
165
166 thisDatetime = self.__isFileInTimeRange(filename, startDate, endDate, startTime, endTime)
166 thisDatetime = self.__isFileInTimeRange(filename, startDate, endDate, startTime, endTime)
167
167
168 if not(thisDatetime):
168 if not(thisDatetime):
169 continue
169 continue
170
170
171 filenameList.append(filename)
171 filenameList.append(filename)
172 datetimeList.append(thisDatetime)
172 datetimeList.append(thisDatetime)
173
173
174 if not(filenameList):
174 if not(filenameList):
175 print "[Reading] Any file was found int time range %s - %s" %(datetime.datetime.combine(startDate,startTime).ctime(), datetime.datetime.combine(endDate,endTime).ctime())
175 print "[Reading] Any file was found int time range %s - %s" %(datetime.datetime.combine(startDate,startTime).ctime(), datetime.datetime.combine(endDate,endTime).ctime())
176 return None, None
176 return None, None
177
177
178 print "[Reading] %d file(s) was(were) found in time range: %s - %s" %(len(filenameList), startTime, endTime)
178 print "[Reading] %d file(s) was(were) found in time range: %s - %s" %(len(filenameList), startTime, endTime)
179 print
179 print
180
180
181 for i in range(len(filenameList)):
181 for i in range(len(filenameList)):
182 print "[Reading] %s -> [%s]" %(filenameList[i], datetimeList[i].ctime())
182 print "[Reading] %s -> [%s]" %(filenameList[i], datetimeList[i].ctime())
183
183
184 self.filenameList = filenameList
184 self.filenameList = filenameList
185 self.datetimeList = datetimeList
185 self.datetimeList = datetimeList
186
186
187 return pathList, filenameList
187 return pathList, filenameList
188
188
189 def __isFileInTimeRange(self,filename, startDate, endDate, startTime, endTime):
189 def __isFileInTimeRange(self,filename, startDate, endDate, startTime, endTime):
190
190
191 """
191 """
192 Retorna 1 si el archivo de datos se encuentra dentro del rango de horas especificado.
192 Retorna 1 si el archivo de datos se encuentra dentro del rango de horas especificado.
193
193
194 Inputs:
194 Inputs:
195 filename : nombre completo del archivo de datos en formato Jicamarca (.r)
195 filename : nombre completo del archivo de datos en formato Jicamarca (.r)
196
196
197 startDate : fecha inicial del rango seleccionado en formato datetime.date
197 startDate : fecha inicial del rango seleccionado en formato datetime.date
198
198
199 endDate : fecha final del rango seleccionado en formato datetime.date
199 endDate : fecha final del rango seleccionado en formato datetime.date
200
200
201 startTime : tiempo inicial del rango seleccionado en formato datetime.time
201 startTime : tiempo inicial del rango seleccionado en formato datetime.time
202
202
203 endTime : tiempo final del rango seleccionado en formato datetime.time
203 endTime : tiempo final del rango seleccionado en formato datetime.time
204
204
205 Return:
205 Return:
206 Boolean : Retorna True si el archivo de datos contiene datos en el rango de
206 Boolean : Retorna True si el archivo de datos contiene datos en el rango de
207 fecha especificado, de lo contrario retorna False.
207 fecha especificado, de lo contrario retorna False.
208
208
209 Excepciones:
209 Excepciones:
210 Si el archivo no existe o no puede ser abierto
210 Si el archivo no existe o no puede ser abierto
211 Si la cabecera no puede ser leida.
211 Si la cabecera no puede ser leida.
212
212
213 """
213 """
214
214
215 try:
215 try:
216 fp = h5py.File(filename,'r')
216 fp = h5py.File(filename,'r')
217 grp1 = fp['Data']
217 grp1 = fp['Data']
218
218
219 except IOError:
219 except IOError:
220 traceback.print_exc()
220 traceback.print_exc()
221 raise IOError, "The file %s can't be opened" %(filename)
221 raise IOError, "The file %s can't be opened" %(filename)
222 #chino rata
222 #chino rata
223 #In case has utctime attribute
223 #In case has utctime attribute
224 grp2 = grp1['utctime']
224 grp2 = grp1['utctime']
225 # thisUtcTime = grp2.value[0] - 5*3600 #To convert to local time
225 # thisUtcTime = grp2.value[0] - 5*3600 #To convert to local time
226 thisUtcTime = grp2.value[0]
226 thisUtcTime = grp2.value[0]
227
227
228 fp.close()
228 fp.close()
229
229
230 if self.timezone == 'lt':
230 if self.timezone == 'lt':
231 thisUtcTime -= 5*3600
231 thisUtcTime -= 5*3600
232
232
233 thisDatetime = datetime.datetime.fromtimestamp(thisUtcTime[0] + 5*3600)
233 thisDatetime = datetime.datetime.fromtimestamp(thisUtcTime[0] + 5*3600)
234 # thisDatetime = datetime.datetime.fromtimestamp(thisUtcTime[0])
234 # thisDatetime = datetime.datetime.fromtimestamp(thisUtcTime[0])
235 thisDate = thisDatetime.date()
235 thisDate = thisDatetime.date()
236 thisTime = thisDatetime.time()
236 thisTime = thisDatetime.time()
237
237
238 startUtcTime = (datetime.datetime.combine(thisDate,startTime)- datetime.datetime(1970, 1, 1)).total_seconds()
238 startUtcTime = (datetime.datetime.combine(thisDate,startTime)- datetime.datetime(1970, 1, 1)).total_seconds()
239 endUtcTime = (datetime.datetime.combine(thisDate,endTime)- datetime.datetime(1970, 1, 1)).total_seconds()
239 endUtcTime = (datetime.datetime.combine(thisDate,endTime)- datetime.datetime(1970, 1, 1)).total_seconds()
240
240
241 #General case
241 #General case
242 # o>>>>>>>>>>>>>><<<<<<<<<<<<<<o
242 # o>>>>>>>>>>>>>><<<<<<<<<<<<<<o
243 #-----------o----------------------------o-----------
243 #-----------o----------------------------o-----------
244 # startTime endTime
244 # startTime endTime
245
245
246 if endTime >= startTime:
246 if endTime >= startTime:
247 thisUtcLog = numpy.logical_and(thisUtcTime > startUtcTime, thisUtcTime < endUtcTime)
247 thisUtcLog = numpy.logical_and(thisUtcTime > startUtcTime, thisUtcTime < endUtcTime)
248 if numpy.any(thisUtcLog): #If there is one block between the hours mentioned
248 if numpy.any(thisUtcLog): #If there is one block between the hours mentioned
249 return thisDatetime
249 return thisDatetime
250 return None
250 return None
251
251
252 #If endTime < startTime then endTime belongs to the next day
252 #If endTime < startTime then endTime belongs to the next day
253 #<<<<<<<<<<<o o>>>>>>>>>>>
253 #<<<<<<<<<<<o o>>>>>>>>>>>
254 #-----------o----------------------------o-----------
254 #-----------o----------------------------o-----------
255 # endTime startTime
255 # endTime startTime
256
256
257 if (thisDate == startDate) and numpy.all(thisUtcTime < startUtcTime):
257 if (thisDate == startDate) and numpy.all(thisUtcTime < startUtcTime):
258 return None
258 return None
259
259
260 if (thisDate == endDate) and numpy.all(thisUtcTime > endUtcTime):
260 if (thisDate == endDate) and numpy.all(thisUtcTime > endUtcTime):
261 return None
261 return None
262
262
263 if numpy.all(thisUtcTime < startUtcTime) and numpy.all(thisUtcTime > endUtcTime):
263 if numpy.all(thisUtcTime < startUtcTime) and numpy.all(thisUtcTime > endUtcTime):
264 return None
264 return None
265
265
266 return thisDatetime
266 return thisDatetime
267
267
268 def __setNextFileOffline(self):
268 def __setNextFileOffline(self):
269
269
270 self.fileIndex += 1
270 self.fileIndex += 1
271 idFile = self.fileIndex
271 idFile = self.fileIndex
272
272
273 if not(idFile < len(self.filenameList)):
273 if not(idFile < len(self.filenameList)):
274 print "No more Files"
274 print "No more Files"
275 return 0
275 return 0
276
276
277 filename = self.filenameList[idFile]
277 filename = self.filenameList[idFile]
278
278
279 filePointer = h5py.File(filename,'r')
279 filePointer = h5py.File(filename,'r')
280
280
281 self.filename = filename
281 self.filename = filename
282
282
283 self.fp = filePointer
283 self.fp = filePointer
284
284
285 print "Setting the file: %s"%self.filename
285 print "Setting the file: %s"%self.filename
286
286
287 # self.__readMetadata()
287 # self.__readMetadata()
288 self.__setBlockList()
288 self.__setBlockList()
289 self.__readData()
289 self.__readData()
290 # self.nRecords = self.fp['Data'].attrs['blocksPerFile']
290 # self.nRecords = self.fp['Data'].attrs['blocksPerFile']
291 # self.nRecords = self.fp['Data'].attrs['nRecords']
291 # self.nRecords = self.fp['Data'].attrs['nRecords']
292 self.blockIndex = 0
292 self.blockIndex = 0
293 return 1
293 return 1
294
294
295 def __setBlockList(self):
295 def __setBlockList(self):
296 '''
296 '''
297 Selects the data within the times defined
297 Selects the data within the times defined
298
298
299 self.fp
299 self.fp
300 self.startTime
300 self.startTime
301 self.endTime
301 self.endTime
302
302
303 self.blockList
303 self.blockList
304 self.blocksPerFile
304 self.blocksPerFile
305
305
306 '''
306 '''
307 fp = self.fp
307 fp = self.fp
308 startTime = self.startTime
308 startTime = self.startTime
309 endTime = self.endTime
309 endTime = self.endTime
310
310
311 grp = fp['Data']
311 grp = fp['Data']
312 thisUtcTime = grp['utctime'].value.astype(numpy.float)[0]
312 thisUtcTime = grp['utctime'].value.astype(numpy.float)[0]
313
313
314 #ERROOOOR
314 #ERROOOOR
315 if self.timezone == 'lt':
315 if self.timezone == 'lt':
316 thisUtcTime -= 5*3600
316 thisUtcTime -= 5*3600
317
317
318 thisDatetime = datetime.datetime.fromtimestamp(thisUtcTime[0] + 5*3600)
318 thisDatetime = datetime.datetime.fromtimestamp(thisUtcTime[0] + 5*3600)
319
319
320 thisDate = thisDatetime.date()
320 thisDate = thisDatetime.date()
321 thisTime = thisDatetime.time()
321 thisTime = thisDatetime.time()
322
322
323 startUtcTime = (datetime.datetime.combine(thisDate,startTime) - datetime.datetime(1970, 1, 1)).total_seconds()
323 startUtcTime = (datetime.datetime.combine(thisDate,startTime) - datetime.datetime(1970, 1, 1)).total_seconds()
324 endUtcTime = (datetime.datetime.combine(thisDate,endTime) - datetime.datetime(1970, 1, 1)).total_seconds()
324 endUtcTime = (datetime.datetime.combine(thisDate,endTime) - datetime.datetime(1970, 1, 1)).total_seconds()
325
325
326 ind = numpy.where(numpy.logical_and(thisUtcTime >= startUtcTime, thisUtcTime < endUtcTime))[0]
326 ind = numpy.where(numpy.logical_and(thisUtcTime >= startUtcTime, thisUtcTime < endUtcTime))[0]
327
327
328 self.blockList = ind
328 self.blockList = ind
329 self.blocksPerFile = len(ind)
329 self.blocksPerFile = len(ind)
330
330
331 return
331 return
332
332
333 def __readMetadata(self):
333 def __readMetadata(self):
334 '''
334 '''
335 Reads Metadata
335 Reads Metadata
336
336
337 self.pathMeta
337 self.pathMeta
338
338
339 self.listShapes
339 self.listShapes
340 self.listMetaname
340 self.listMetaname
341 self.listMeta
341 self.listMeta
342
342
343 '''
343 '''
344
344
345 # grp = self.fp['Data']
345 # grp = self.fp['Data']
346 # pathMeta = os.path.join(self.path, grp.attrs['metadata'])
346 # pathMeta = os.path.join(self.path, grp.attrs['metadata'])
347 #
347 #
348 # if pathMeta == self.pathMeta:
348 # if pathMeta == self.pathMeta:
349 # return
349 # return
350 # else:
350 # else:
351 # self.pathMeta = pathMeta
351 # self.pathMeta = pathMeta
352 #
352 #
353 # filePointer = h5py.File(self.pathMeta,'r')
353 # filePointer = h5py.File(self.pathMeta,'r')
354 # groupPointer = filePointer['Metadata']
354 # groupPointer = filePointer['Metadata']
355
355
356 filename = self.filenameList[0]
356 filename = self.filenameList[0]
357
357
358 fp = h5py.File(filename,'r')
358 fp = h5py.File(filename,'r')
359
359
360 gp = fp['Metadata']
360 gp = fp['Metadata']
361
361
362 listMetaname = []
362 listMetaname = []
363 listMetadata = []
363 listMetadata = []
364 for item in gp.items():
364 for item in gp.items():
365 name = item[0]
365 name = item[0]
366
366
367 if name=='array dimensions':
367 if name=='array dimensions':
368 table = gp[name][:]
368 table = gp[name][:]
369 listShapes = {}
369 listShapes = {}
370 for shapes in table:
370 for shapes in table:
371 listShapes[shapes[0]] = numpy.array([shapes[1],shapes[2],shapes[3],shapes[4],shapes[5]])
371 listShapes[shapes[0]] = numpy.array([shapes[1],shapes[2],shapes[3],shapes[4],shapes[5]])
372 else:
372 else:
373 data = gp[name].value
373 data = gp[name].value
374 listMetaname.append(name)
374 listMetaname.append(name)
375 listMetadata.append(data)
375 listMetadata.append(data)
376
376
377 # if name=='type':
377 # if name=='type':
378 # self.__initDataOut(data)
378 # self.__initDataOut(data)
379
379
380 self.listShapes = listShapes
380 self.listShapes = listShapes
381 self.listMetaname = listMetaname
381 self.listMetaname = listMetaname
382 self.listMeta = listMetadata
382 self.listMeta = listMetadata
383
383
384 fp.close()
384 fp.close()
385 return
385 return
386
386
387 def __readData(self):
387 def __readData(self):
388 grp = self.fp['Data']
388 grp = self.fp['Data']
389 listdataname = []
389 listdataname = []
390 listdata = []
390 listdata = []
391
391
392 for item in grp.items():
392 for item in grp.items():
393 name = item[0]
393 name = item[0]
394 listdataname.append(name)
394 listdataname.append(name)
395
395
396 array = self.__setDataArray(grp[name],self.listShapes[name])
396 array = self.__setDataArray(grp[name],self.listShapes[name])
397 listdata.append(array)
397 listdata.append(array)
398
398
399 self.listDataname = listdataname
399 self.listDataname = listdataname
400 self.listData = listdata
400 self.listData = listdata
401 return
401 return
402
402
403 def __setDataArray(self, dataset, shapes):
403 def __setDataArray(self, dataset, shapes):
404
404
405 nDims = shapes[0]
405 nDims = shapes[0]
406
406
407 nDim2 = shapes[1] #Dimension 0
407 nDim2 = shapes[1] #Dimension 0
408
408
409 nDim1 = shapes[2] #Dimension 1, number of Points or Parameters
409 nDim1 = shapes[2] #Dimension 1, number of Points or Parameters
410
410
411 nDim0 = shapes[3] #Dimension 2, number of samples or ranges
411 nDim0 = shapes[3] #Dimension 2, number of samples or ranges
412
412
413 mode = shapes[4] #Mode of storing
413 mode = shapes[4] #Mode of storing
414
414
415 blockList = self.blockList
415 blockList = self.blockList
416
416
417 blocksPerFile = self.blocksPerFile
417 blocksPerFile = self.blocksPerFile
418
418
419 #Depending on what mode the data was stored
419 #Depending on what mode the data was stored
420 if mode == 0: #Divided in channels
420 if mode == 0: #Divided in channels
421 arrayData = dataset.value.astype(numpy.float)[0][blockList]
421 arrayData = dataset.value.astype(numpy.float)[0][blockList]
422 if mode == 1: #Divided in parameter
422 if mode == 1: #Divided in parameter
423 strds = 'table'
423 strds = 'table'
424 nDatas = nDim1
424 nDatas = nDim1
425 newShapes = (blocksPerFile,nDim2,nDim0)
425 newShapes = (blocksPerFile,nDim2,nDim0)
426 elif mode==2: #Concatenated in a table
426 elif mode==2: #Concatenated in a table
427 strds = 'table0'
427 strds = 'table0'
428 arrayData = dataset[strds].value
428 arrayData = dataset[strds].value
429 #Selecting part of the dataset
429 #Selecting part of the dataset
430 utctime = arrayData[:,0]
430 utctime = arrayData[:,0]
431 u, indices = numpy.unique(utctime, return_index=True)
431 u, indices = numpy.unique(utctime, return_index=True)
432
432
433 if blockList.size != indices.size:
433 if blockList.size != indices.size:
434 indMin = indices[blockList[0]]
434 indMin = indices[blockList[0]]
435 if blockList[1] + 1 >= indices.size:
435 if blockList[1] + 1 >= indices.size:
436 arrayData = arrayData[indMin:,:]
436 arrayData = arrayData[indMin:,:]
437 else:
437 else:
438 indMax = indices[blockList[1] + 1]
438 indMax = indices[blockList[1] + 1]
439 arrayData = arrayData[indMin:indMax,:]
439 arrayData = arrayData[indMin:indMax,:]
440 return arrayData
440 return arrayData
441
441
442 # One dimension
442 # One dimension
443 if nDims == 0:
443 if nDims == 0:
444 arrayData = dataset.value.astype(numpy.float)[0][blockList]
444 arrayData = dataset.value.astype(numpy.float)[0][blockList]
445
445
446 # Two dimensions
446 # Two dimensions
447 elif nDims == 2:
447 elif nDims == 2:
448 arrayData = numpy.zeros((blocksPerFile,nDim1,nDim0))
448 arrayData = numpy.zeros((blocksPerFile,nDim1,nDim0))
449 newShapes = (blocksPerFile,nDim0)
449 newShapes = (blocksPerFile,nDim0)
450 nDatas = nDim1
450 nDatas = nDim1
451
451
452 for i in range(nDatas):
452 for i in range(nDatas):
453 data = dataset[strds + str(i)].value
453 data = dataset[strds + str(i)].value
454 arrayData[:,i,:] = data[blockList,:]
454 arrayData[:,i,:] = data[blockList,:]
455
455
456 # Three dimensions
456 # Three dimensions
457 else:
457 else:
458 arrayData = numpy.zeros((blocksPerFile,nDim2,nDim1,nDim0))
458 arrayData = numpy.zeros((blocksPerFile,nDim2,nDim1,nDim0))
459 for i in range(nDatas):
459 for i in range(nDatas):
460
460
461 data = dataset[strds + str(i)].value
461 data = dataset[strds + str(i)].value
462
462
463 for b in range(blockList.size):
463 for b in range(blockList.size):
464 arrayData[b,:,i,:] = data[:,:,blockList[b]]
464 arrayData[b,:,i,:] = data[:,:,blockList[b]]
465
465
466 return arrayData
466 return arrayData
467
467
468 def __setDataOut(self):
468 def __setDataOut(self):
469 listMeta = self.listMeta
469 listMeta = self.listMeta
470 listMetaname = self.listMetaname
470 listMetaname = self.listMetaname
471 listDataname = self.listDataname
471 listDataname = self.listDataname
472 listData = self.listData
472 listData = self.listData
473 listShapes = self.listShapes
473 listShapes = self.listShapes
474
474
475 blockIndex = self.blockIndex
475 blockIndex = self.blockIndex
476 # blockList = self.blockList
476 # blockList = self.blockList
477
477
478 for i in range(len(listMeta)):
478 for i in range(len(listMeta)):
479 setattr(self.dataOut,listMetaname[i],listMeta[i])
479 setattr(self.dataOut,listMetaname[i],listMeta[i])
480
480
481 for j in range(len(listData)):
481 for j in range(len(listData)):
482 nShapes = listShapes[listDataname[j]][0]
482 nShapes = listShapes[listDataname[j]][0]
483 mode = listShapes[listDataname[j]][4]
483 mode = listShapes[listDataname[j]][4]
484 if nShapes == 1:
484 if nShapes == 1:
485 setattr(self.dataOut,listDataname[j],listData[j][blockIndex])
485 setattr(self.dataOut,listDataname[j],listData[j][blockIndex])
486 elif nShapes > 1:
486 elif nShapes > 1:
487 setattr(self.dataOut,listDataname[j],listData[j][blockIndex,:])
487 setattr(self.dataOut,listDataname[j],listData[j][blockIndex,:])
488 elif mode==0:
488 elif mode==0:
489 setattr(self.dataOut,listDataname[j],listData[j][blockIndex])
489 setattr(self.dataOut,listDataname[j],listData[j][blockIndex])
490 #Mode Meteors
490 #Mode Meteors
491 elif mode ==2:
491 elif mode ==2:
492 selectedData = self.__selectDataMode2(listData[j], blockIndex)
492 selectedData = self.__selectDataMode2(listData[j], blockIndex)
493 setattr(self.dataOut, listDataname[j], selectedData)
493 setattr(self.dataOut, listDataname[j], selectedData)
494 return
494 return
495
495
496 def __selectDataMode2(self, data, blockIndex):
496 def __selectDataMode2(self, data, blockIndex):
497 utctime = data[:,0]
497 utctime = data[:,0]
498 aux, indices = numpy.unique(utctime, return_inverse=True)
498 aux, indices = numpy.unique(utctime, return_inverse=True)
499 selInd = numpy.where(indices == blockIndex)[0]
499 selInd = numpy.where(indices == blockIndex)[0]
500 selData = data[selInd,:]
500 selData = data[selInd,:]
501
501
502 return selData
502 return selData
503
503
504 def getData(self):
504 def getData(self):
505
505
506 # if self.flagNoMoreFiles:
506 # if self.flagNoMoreFiles:
507 # self.dataOut.flagNoData = True
507 # self.dataOut.flagNoData = True
508 # print 'Process finished'
508 # print 'Process finished'
509 # return 0
509 # return 0
510 #
510 #
511 if self.blockIndex==self.blocksPerFile:
511 if self.blockIndex==self.blocksPerFile:
512 if not( self.__setNextFileOffline() ):
512 if not( self.__setNextFileOffline() ):
513 self.dataOut.flagNoData = True
513 self.dataOut.flagNoData = True
514 return 0
514 return 0
515
515
516 # if self.datablock == None: # setear esta condicion cuando no hayan datos por leers
516 # if self.datablock == None: # setear esta condicion cuando no hayan datos por leers
517 # self.dataOut.flagNoData = True
517 # self.dataOut.flagNoData = True
518 # return 0
518 # return 0
519 # self.__readData()
519 # self.__readData()
520 self.__setDataOut()
520 self.__setDataOut()
521 self.dataOut.flagNoData = False
521 self.dataOut.flagNoData = False
522
522
523 self.blockIndex += 1
523 self.blockIndex += 1
524
524
525 return
525 return
526
526
527 def run(self, **kwargs):
527 def run(self, **kwargs):
528
528
529 if not(self.isConfig):
529 if not(self.isConfig):
530 self.setup(**kwargs)
530 self.setup(**kwargs)
531 # self.setObjProperties()
531 # self.setObjProperties()
532 self.isConfig = True
532 self.isConfig = True
533
533
534 self.getData()
534 self.getData()
535
535
536 return
536 return
537
537
538 class ParamWriter(Operation):
538 class ParamWriter(Operation):
539 '''
539 '''
540 HDF5 Writer, stores parameters data in HDF5 format files
540 HDF5 Writer, stores parameters data in HDF5 format files
541
541
542 path: path where the files will be stored
542 path: path where the files will be stored
543
543
544 blocksPerFile: number of blocks that will be saved in per HDF5 format file
544 blocksPerFile: number of blocks that will be saved in per HDF5 format file
545
545
546 mode: selects the data stacking mode: '0' channels, '1' parameters, '3' table (for meteors)
546 mode: selects the data stacking mode: '0' channels, '1' parameters, '3' table (for meteors)
547
547
548 metadataList: list of attributes that will be stored as metadata
548 metadataList: list of attributes that will be stored as metadata
549
549
550 dataList: list of attributes that will be stores as data
550 dataList: list of attributes that will be stores as data
551
551
552 '''
552 '''
553
553
554
554
555 ext = ".hdf5"
555 ext = ".hdf5"
556
556
557 optchar = "D"
557 optchar = "D"
558
558
559 metaoptchar = "M"
559 metaoptchar = "M"
560
560
561 metaFile = None
561 metaFile = None
562
562
563 filename = None
563 filename = None
564
564
565 path = None
565 path = None
566
566
567 setFile = None
567 setFile = None
568
568
569 fp = None
569 fp = None
570
570
571 grp = None
571 grp = None
572
572
573 ds = None
573 ds = None
574
574
575 firsttime = True
575 firsttime = True
576
576
577 #Configurations
577 #Configurations
578
578
579 blocksPerFile = None
579 blocksPerFile = None
580
580
581 blockIndex = None
581 blockIndex = None
582
582
583 dataOut = None
583 dataOut = None
584
584
585 #Data Arrays
585 #Data Arrays
586
586
587 dataList = None
587 dataList = None
588
588
589 metadataList = None
589 metadataList = None
590
590
591 # arrayDim = None
591 # arrayDim = None
592
592
593 dsList = None #List of dictionaries with dataset properties
593 dsList = None #List of dictionaries with dataset properties
594
594
595 tableDim = None
595 tableDim = None
596
596
597 # dtype = [('arrayName', 'S20'),('nChannels', 'i'), ('nPoints', 'i'), ('nSamples', 'i'),('mode', 'b')]
597 # dtype = [('arrayName', 'S20'),('nChannels', 'i'), ('nPoints', 'i'), ('nSamples', 'i'),('mode', 'b')]
598
598
599 dtype = [('arrayName', 'S20'),('nDimensions', 'i'), ('dim2', 'i'), ('dim1', 'i'),('dim0', 'i'),('mode', 'b')]
599 dtype = [('arrayName', 'S20'),('nDimensions', 'i'), ('dim2', 'i'), ('dim1', 'i'),('dim0', 'i'),('mode', 'b')]
600
600
601 currentDay = None
601 currentDay = None
602
602
603 lastTime = None
603 lastTime = None
604
604
605 parameters = {
606 'path': global_type_string,
607 'blocksPerFile':global_type_integer,
608 'metadataList': global_type_list,
609 'dataList': global_type_list,
610 'mode': global_type_integer,
611 }
612
605 def __init__(self, **kwargs):
613 def __init__(self, **kwargs):
606 Operation.__init__(self, **kwargs)
614 Operation.__init__(self, **kwargs)
607 self.isConfig = False
615 self.isConfig = False
608 return
616 return
609
617
610 def setup(self, dataOut, **kwargs):
618 def setup(self, dataOut, path=None, blocksPerFile=10, metadataList=None, dataList=None, mode=None, **kwargs):
611
619 self.path = path
612 self.path = kwargs['path']
620 self.blocksPerFile = blocksPerFile
613 self.setType = kwargs.get('setType', None)
621 self.metadataList = metadataList
614
622 self.dataList = dataList
615 if kwargs.has_key('blocksPerFile'):
616 self.blocksPerFile = kwargs['blocksPerFile']
617 else:
618 self.blocksPerFile = 10
619
620 self.metadataList = kwargs['metadataList']
621 self.dataList = kwargs['dataList']
622 self.dataOut = dataOut
623 self.dataOut = dataOut
623
624 if kwargs.has_key('mode'):
625 mode = kwargs['mode']
626
627 if type(mode) == int:
628 mode = numpy.zeros(len(self.dataList)) + mode
629 else:
630 mode = numpy.ones(len(self.dataList))
631
632 self.mode = mode
624 self.mode = mode
625
626 if self.mode is not None:
627 self.mode = numpy.zeros(len(self.dataList)) + mode
628 else:
629 self.mode = numpy.ones(len(self.dataList))
633
630
634 arrayDim = numpy.zeros((len(self.dataList),5))
631 arrayDim = numpy.zeros((len(self.dataList),5))
635
632
636 #Table dimensions
633 #Table dimensions
637 dtype0 = self.dtype
634 dtype0 = self.dtype
638 tableList = []
635 tableList = []
639
636
640 #Dictionary and list of tables
637 #Dictionary and list of tables
641 dsList = []
638 dsList = []
642
639
643 for i in range(len(self.dataList)):
640 for i in range(len(self.dataList)):
644 dsDict = {}
641 dsDict = {}
645 dataAux = getattr(self.dataOut, self.dataList[i])
642 dataAux = getattr(self.dataOut, self.dataList[i])
646 dsDict['variable'] = self.dataList[i]
643 dsDict['variable'] = self.dataList[i]
647 #--------------------- Conditionals ------------------------
644 #--------------------- Conditionals ------------------------
648 #There is no data
645 #There is no data
649 if dataAux is None:
646 if dataAux is None:
650 return 0
647 return 0
651
648
652 #Not array, just a number
649 #Not array, just a number
653 #Mode 0
650 #Mode 0
654 if type(dataAux)==float or type(dataAux)==int:
651 if type(dataAux)==float or type(dataAux)==int:
655 dsDict['mode'] = 0
652 dsDict['mode'] = 0
656 dsDict['nDim'] = 0
653 dsDict['nDim'] = 0
657 arrayDim[i,0] = 0
654 arrayDim[i,0] = 0
658 dsList.append(dsDict)
655 dsList.append(dsDict)
659
656
660 #Mode 2: meteors
657 #Mode 2: meteors
661 elif mode[i] == 2:
658 elif mode[i] == 2:
662 # dsDict['nDim'] = 0
659 # dsDict['nDim'] = 0
663 dsDict['dsName'] = 'table0'
660 dsDict['dsName'] = 'table0'
664 dsDict['mode'] = 2 # Mode meteors
661 dsDict['mode'] = 2 # Mode meteors
665 dsDict['shape'] = dataAux.shape[-1]
662 dsDict['shape'] = dataAux.shape[-1]
666 dsDict['nDim'] = 0
663 dsDict['nDim'] = 0
667 dsDict['dsNumber'] = 1
664 dsDict['dsNumber'] = 1
668
665
669 arrayDim[i,3] = dataAux.shape[-1]
666 arrayDim[i,3] = dataAux.shape[-1]
670 arrayDim[i,4] = mode[i] #Mode the data was stored
667 arrayDim[i,4] = mode[i] #Mode the data was stored
671
668
672 dsList.append(dsDict)
669 dsList.append(dsDict)
673
670
674 #Mode 1
671 #Mode 1
675 else:
672 else:
676 arrayDim0 = dataAux.shape #Data dimensions
673 arrayDim0 = dataAux.shape #Data dimensions
677 arrayDim[i,0] = len(arrayDim0) #Number of array dimensions
674 arrayDim[i,0] = len(arrayDim0) #Number of array dimensions
678 arrayDim[i,4] = mode[i] #Mode the data was stored
675 arrayDim[i,4] = mode[i] #Mode the data was stored
679
676
680 strtable = 'table'
677 strtable = 'table'
681 dsDict['mode'] = 1 # Mode parameters
678 dsDict['mode'] = 1 # Mode parameters
682
679
683 # Three-dimension arrays
680 # Three-dimension arrays
684 if len(arrayDim0) == 3:
681 if len(arrayDim0) == 3:
685 arrayDim[i,1:-1] = numpy.array(arrayDim0)
682 arrayDim[i,1:-1] = numpy.array(arrayDim0)
686 nTables = int(arrayDim[i,2])
683 nTables = int(arrayDim[i,2])
687 dsDict['dsNumber'] = nTables
684 dsDict['dsNumber'] = nTables
688 dsDict['shape'] = arrayDim[i,2:4]
685 dsDict['shape'] = arrayDim[i,2:4]
689 dsDict['nDim'] = 3
686 dsDict['nDim'] = 3
690
687
691 for j in range(nTables):
688 for j in range(nTables):
692 dsDict = dsDict.copy()
689 dsDict = dsDict.copy()
693 dsDict['dsName'] = strtable + str(j)
690 dsDict['dsName'] = strtable + str(j)
694 dsList.append(dsDict)
691 dsList.append(dsDict)
695
692
696 # Two-dimension arrays
693 # Two-dimension arrays
697 elif len(arrayDim0) == 2:
694 elif len(arrayDim0) == 2:
698 arrayDim[i,2:-1] = numpy.array(arrayDim0)
695 arrayDim[i,2:-1] = numpy.array(arrayDim0)
699 nTables = int(arrayDim[i,2])
696 nTables = int(arrayDim[i,2])
700 dsDict['dsNumber'] = nTables
697 dsDict['dsNumber'] = nTables
701 dsDict['shape'] = arrayDim[i,3]
698 dsDict['shape'] = arrayDim[i,3]
702 dsDict['nDim'] = 2
699 dsDict['nDim'] = 2
703
700
704 for j in range(nTables):
701 for j in range(nTables):
705 dsDict = dsDict.copy()
702 dsDict = dsDict.copy()
706 dsDict['dsName'] = strtable + str(j)
703 dsDict['dsName'] = strtable + str(j)
707 dsList.append(dsDict)
704 dsList.append(dsDict)
708
705
709 # One-dimension arrays
706 # One-dimension arrays
710 elif len(arrayDim0) == 1:
707 elif len(arrayDim0) == 1:
711 arrayDim[i,3] = arrayDim0[0]
708 arrayDim[i,3] = arrayDim0[0]
712 dsDict['shape'] = arrayDim0[0]
709 dsDict['shape'] = arrayDim0[0]
713 dsDict['dsNumber'] = 1
710 dsDict['dsNumber'] = 1
714 dsDict['dsName'] = strtable + str(0)
711 dsDict['dsName'] = strtable + str(0)
715 dsDict['nDim'] = 1
712 dsDict['nDim'] = 1
716 dsList.append(dsDict)
713 dsList.append(dsDict)
717
714
718 table = numpy.array((self.dataList[i],) + tuple(arrayDim[i,:]),dtype = dtype0)
715 table = numpy.array((self.dataList[i],) + tuple(arrayDim[i,:]),dtype = dtype0)
719 tableList.append(table)
716 tableList.append(table)
720
717
721 # self.arrayDim = arrayDim
718 # self.arrayDim = arrayDim
722 self.dsList = dsList
719 self.dsList = dsList
723 self.tableDim = numpy.array(tableList, dtype = dtype0)
720 self.tableDim = numpy.array(tableList, dtype = dtype0)
724 self.blockIndex = 0
721 self.blockIndex = 0
725
722
726 timeTuple = time.localtime(dataOut.utctime)
723 timeTuple = time.localtime(dataOut.utctime)
727 self.currentDay = timeTuple.tm_yday
724 self.currentDay = timeTuple.tm_yday
728 return 1
725 return 1
729
726
730 def putMetadata(self):
727 def putMetadata(self):
731
728
732 fp = self.createMetadataFile()
729 fp = self.createMetadataFile()
733 self.writeMetadata(fp)
730 self.writeMetadata(fp)
734 fp.close()
731 fp.close()
735 return
732 return
736
733
737 def createMetadataFile(self):
734 def createMetadataFile(self):
738 ext = self.ext
735 ext = self.ext
739 path = self.path
736 path = self.path
740 setFile = self.setFile
737 setFile = self.setFile
741
738
742 timeTuple = time.localtime(self.dataOut.utctime)
739 timeTuple = time.localtime(self.dataOut.utctime)
743
740
744 subfolder = ''
741 subfolder = ''
745 fullpath = os.path.join( path, subfolder )
742 fullpath = os.path.join( path, subfolder )
746
743
747 if not( os.path.exists(fullpath) ):
744 if not( os.path.exists(fullpath) ):
748 os.mkdir(fullpath)
745 os.mkdir(fullpath)
749 setFile = -1 #inicializo mi contador de seteo
746 setFile = -1 #inicializo mi contador de seteo
750
747
751 subfolder = 'd%4.4d%3.3d' % (timeTuple.tm_year,timeTuple.tm_yday)
748 subfolder = 'd%4.4d%3.3d' % (timeTuple.tm_year,timeTuple.tm_yday)
752 fullpath = os.path.join( path, subfolder )
749 fullpath = os.path.join( path, subfolder )
753
750
754 if not( os.path.exists(fullpath) ):
751 if not( os.path.exists(fullpath) ):
755 os.mkdir(fullpath)
752 os.mkdir(fullpath)
756 setFile = -1 #inicializo mi contador de seteo
753 setFile = -1 #inicializo mi contador de seteo
757
754
758 else:
755 else:
759 filesList = os.listdir( fullpath )
756 filesList = os.listdir( fullpath )
760 filesList = sorted( filesList, key=str.lower )
757 filesList = sorted( filesList, key=str.lower )
761 if len( filesList ) > 0:
758 if len( filesList ) > 0:
762 filesList = [k for k in filesList if 'M' in k]
759 filesList = [k for k in filesList if 'M' in k]
763 filen = filesList[-1]
760 filen = filesList[-1]
764 # el filename debera tener el siguiente formato
761 # el filename debera tener el siguiente formato
765 # 0 1234 567 89A BCDE (hex)
762 # 0 1234 567 89A BCDE (hex)
766 # x YYYY DDD SSS .ext
763 # x YYYY DDD SSS .ext
767 if isNumber( filen[8:11] ):
764 if isNumber( filen[8:11] ):
768 setFile = int( filen[8:11] ) #inicializo mi contador de seteo al seteo del ultimo file
765 setFile = int( filen[8:11] ) #inicializo mi contador de seteo al seteo del ultimo file
769 else:
766 else:
770 setFile = -1
767 setFile = -1
771 else:
768 else:
772 setFile = -1 #inicializo mi contador de seteo
769 setFile = -1 #inicializo mi contador de seteo
773
770
774 if self.setType is None:
771 if self.setType is None:
775 setFile += 1
772 setFile += 1
776 file = '%s%4.4d%3.3d%03d%s' % (self.metaoptchar,
773 file = '%s%4.4d%3.3d%03d%s' % (self.metaoptchar,
777 timeTuple.tm_year,
774 timeTuple.tm_year,
778 timeTuple.tm_yday,
775 timeTuple.tm_yday,
779 setFile,
776 setFile,
780 ext )
777 ext )
781 else:
778 else:
782 setFile = timeTuple.tm_hour*60+timeTuple.tm_min
779 setFile = timeTuple.tm_hour*60+timeTuple.tm_min
783 file = '%s%4.4d%3.3d%04d%s' % (self.metaoptchar,
780 file = '%s%4.4d%3.3d%04d%s' % (self.metaoptchar,
784 timeTuple.tm_year,
781 timeTuple.tm_year,
785 timeTuple.tm_yday,
782 timeTuple.tm_yday,
786 setFile,
783 setFile,
787 ext )
784 ext )
788
785
789 filename = os.path.join( path, subfolder, file )
786 filename = os.path.join( path, subfolder, file )
790 self.metaFile = file
787 self.metaFile = file
791 #Setting HDF5 File
788 #Setting HDF5 File
792 fp = h5py.File(filename,'w')
789 fp = h5py.File(filename,'w')
793
790
794 return fp
791 return fp
795
792
796 def writeMetadata(self, fp):
793 def writeMetadata(self, fp):
797
794
798 grp = fp.create_group("Metadata")
795 grp = fp.create_group("Metadata")
799 grp.create_dataset('array dimensions', data = self.tableDim, dtype = self.dtype)
796 grp.create_dataset('array dimensions', data = self.tableDim, dtype = self.dtype)
800
797
801 for i in range(len(self.metadataList)):
798 for i in range(len(self.metadataList)):
802 grp.create_dataset(self.metadataList[i], data=getattr(self.dataOut, self.metadataList[i]))
799 grp.create_dataset(self.metadataList[i], data=getattr(self.dataOut, self.metadataList[i]))
803 return
800 return
804
801
805 def timeFlag(self):
802 def timeFlag(self):
806 currentTime = self.dataOut.utctime
803 currentTime = self.dataOut.utctime
807
804
808 if self.lastTime is None:
805 if self.lastTime is None:
809 self.lastTime = currentTime
806 self.lastTime = currentTime
810
807
811 #Day
808 #Day
812 timeTuple = time.localtime(currentTime)
809 timeTuple = time.localtime(currentTime)
813 dataDay = timeTuple.tm_yday
810 dataDay = timeTuple.tm_yday
814
811
815 #Time
812 #Time
816 timeDiff = currentTime - self.lastTime
813 timeDiff = currentTime - self.lastTime
817
814
818 #Si el dia es diferente o si la diferencia entre un dato y otro supera la hora
815 #Si el dia es diferente o si la diferencia entre un dato y otro supera la hora
819 if dataDay != self.currentDay:
816 if dataDay != self.currentDay:
820 self.currentDay = dataDay
817 self.currentDay = dataDay
821 return True
818 return True
822 elif timeDiff > 3*60*60:
819 elif timeDiff > 3*60*60:
823 self.lastTime = currentTime
820 self.lastTime = currentTime
824 return True
821 return True
825 else:
822 else:
826 self.lastTime = currentTime
823 self.lastTime = currentTime
827 return False
824 return False
828
825
829 def setNextFile(self):
826 def setNextFile(self):
830
827
831 ext = self.ext
828 ext = self.ext
832 path = self.path
829 path = self.path
833 setFile = self.setFile
830 setFile = self.setFile
834 mode = self.mode
831 mode = self.mode
835
832
836 timeTuple = time.localtime(self.dataOut.utctime)
833 timeTuple = time.localtime(self.dataOut.utctime)
837 subfolder = 'd%4.4d%3.3d' % (timeTuple.tm_year,timeTuple.tm_yday)
834 subfolder = 'd%4.4d%3.3d' % (timeTuple.tm_year,timeTuple.tm_yday)
838
835
839 fullpath = os.path.join( path, subfolder )
836 fullpath = os.path.join( path, subfolder )
840
837
841 if os.path.exists(fullpath):
838 if os.path.exists(fullpath):
842 filesList = os.listdir( fullpath )
839 filesList = os.listdir( fullpath )
843 filesList = [k for k in filesList if 'D' in k]
840 filesList = [k for k in filesList if 'D' in k]
844 if len( filesList ) > 0:
841 if len( filesList ) > 0:
845 filesList = sorted( filesList, key=str.lower )
842 filesList = sorted( filesList, key=str.lower )
846 filen = filesList[-1]
843 filen = filesList[-1]
847 # el filename debera tener el siguiente formato
844 # el filename debera tener el siguiente formato
848 # 0 1234 567 89A BCDE (hex)
845 # 0 1234 567 89A BCDE (hex)
849 # x YYYY DDD SSS .ext
846 # x YYYY DDD SSS .ext
850 if isNumber( filen[8:11] ):
847 if isNumber( filen[8:11] ):
851 setFile = int( filen[8:11] ) #inicializo mi contador de seteo al seteo del ultimo file
848 setFile = int( filen[8:11] ) #inicializo mi contador de seteo al seteo del ultimo file
852 else:
849 else:
853 setFile = -1
850 setFile = -1
854 else:
851 else:
855 setFile = -1 #inicializo mi contador de seteo
852 setFile = -1 #inicializo mi contador de seteo
856 else:
853 else:
857 os.makedirs(fullpath)
854 os.makedirs(fullpath)
858 setFile = -1 #inicializo mi contador de seteo
855 setFile = -1 #inicializo mi contador de seteo
859
856
860 if self.setType is None:
857 if self.setType is None:
861 setFile += 1
858 setFile += 1
862 file = '%s%4.4d%3.3d%03d%s' % (self.metaoptchar,
859 file = '%s%4.4d%3.3d%03d%s' % (self.metaoptchar,
863 timeTuple.tm_year,
860 timeTuple.tm_year,
864 timeTuple.tm_yday,
861 timeTuple.tm_yday,
865 setFile,
862 setFile,
866 ext )
863 ext )
867 else:
864 else:
868 setFile = timeTuple.tm_hour*60+timeTuple.tm_min
865 setFile = timeTuple.tm_hour*60+timeTuple.tm_min
869 file = '%s%4.4d%3.3d%04d%s' % (self.metaoptchar,
866 file = '%s%4.4d%3.3d%04d%s' % (self.metaoptchar,
870 timeTuple.tm_year,
867 timeTuple.tm_year,
871 timeTuple.tm_yday,
868 timeTuple.tm_yday,
872 setFile,
869 setFile,
873 ext )
870 ext )
874
871
875 filename = os.path.join( path, subfolder, file )
872 filename = os.path.join( path, subfolder, file )
876
873
877 #Setting HDF5 File
874 #Setting HDF5 File
878 fp = h5py.File(filename,'w')
875 fp = h5py.File(filename,'w')
879 #write metadata
876 #write metadata
880 self.writeMetadata(fp)
877 self.writeMetadata(fp)
881 #Write data
878 #Write data
882 grp = fp.create_group("Data")
879 grp = fp.create_group("Data")
883 # grp.attrs['metadata'] = self.metaFile
880 # grp.attrs['metadata'] = self.metaFile
884
881
885 # grp.attrs['blocksPerFile'] = 0
882 # grp.attrs['blocksPerFile'] = 0
886 ds = []
883 ds = []
887 data = []
884 data = []
888 dsList = self.dsList
885 dsList = self.dsList
889 i = 0
886 i = 0
890 while i < len(dsList):
887 while i < len(dsList):
891 dsInfo = dsList[i]
888 dsInfo = dsList[i]
892 #One-dimension data
889 #One-dimension data
893 if dsInfo['mode'] == 0:
890 if dsInfo['mode'] == 0:
894 # ds0 = grp.create_dataset(self.dataList[i], (1,1), maxshape=(1,self.blocksPerFile) , chunks = True, dtype='S20')
891 # ds0 = grp.create_dataset(self.dataList[i], (1,1), maxshape=(1,self.blocksPerFile) , chunks = True, dtype='S20')
895 ds0 = grp.create_dataset(dsInfo['variable'], (1,1), maxshape=(1,self.blocksPerFile) , chunks = True, dtype=numpy.float64)
892 ds0 = grp.create_dataset(dsInfo['variable'], (1,1), maxshape=(1,self.blocksPerFile) , chunks = True, dtype=numpy.float64)
896 ds.append(ds0)
893 ds.append(ds0)
897 data.append([])
894 data.append([])
898 i += 1
895 i += 1
899 continue
896 continue
900 # nDimsForDs.append(nDims[i])
897 # nDimsForDs.append(nDims[i])
901
898
902 elif dsInfo['mode'] == 2:
899 elif dsInfo['mode'] == 2:
903 grp0 = grp.create_group(dsInfo['variable'])
900 grp0 = grp.create_group(dsInfo['variable'])
904 ds0 = grp0.create_dataset(dsInfo['dsName'], (1,dsInfo['shape']), data = numpy.zeros((1,dsInfo['shape'])) , maxshape=(None,dsInfo['shape']), chunks=True)
901 ds0 = grp0.create_dataset(dsInfo['dsName'], (1,dsInfo['shape']), data = numpy.zeros((1,dsInfo['shape'])) , maxshape=(None,dsInfo['shape']), chunks=True)
905 ds.append(ds0)
902 ds.append(ds0)
906 data.append([])
903 data.append([])
907 i += 1
904 i += 1
908 continue
905 continue
909
906
910 elif dsInfo['mode'] == 1:
907 elif dsInfo['mode'] == 1:
911 grp0 = grp.create_group(dsInfo['variable'])
908 grp0 = grp.create_group(dsInfo['variable'])
912
909
913 for j in range(dsInfo['dsNumber']):
910 for j in range(dsInfo['dsNumber']):
914 dsInfo = dsList[i]
911 dsInfo = dsList[i]
915 tableName = dsInfo['dsName']
912 tableName = dsInfo['dsName']
916 shape = int(dsInfo['shape'])
913 shape = int(dsInfo['shape'])
917
914
918 if dsInfo['nDim'] == 3:
915 if dsInfo['nDim'] == 3:
919 ds0 = grp0.create_dataset(tableName, (shape[0],shape[1],1) , data = numpy.zeros((shape[0],shape[1],1)), maxshape = (None,shape[1],None), chunks=True)
916 ds0 = grp0.create_dataset(tableName, (shape[0],shape[1],1) , data = numpy.zeros((shape[0],shape[1],1)), maxshape = (None,shape[1],None), chunks=True)
920 else:
917 else:
921 ds0 = grp0.create_dataset(tableName, (1,shape), data = numpy.zeros((1,shape)) , maxshape=(None,shape), chunks=True)
918 ds0 = grp0.create_dataset(tableName, (1,shape), data = numpy.zeros((1,shape)) , maxshape=(None,shape), chunks=True)
922
919
923 ds.append(ds0)
920 ds.append(ds0)
924 data.append([])
921 data.append([])
925 i += 1
922 i += 1
926 # nDimsForDs.append(nDims[i])
923 # nDimsForDs.append(nDims[i])
927
924
928 fp.flush()
925 fp.flush()
929 fp.close()
926 fp.close()
930
927
931 # self.nDatas = nDatas
928 # self.nDatas = nDatas
932 # self.nDims = nDims
929 # self.nDims = nDims
933 # self.nDimsForDs = nDimsForDs
930 # self.nDimsForDs = nDimsForDs
934 #Saving variables
931 #Saving variables
935 print 'Writing the file: %s'%filename
932 print 'Writing the file: %s'%filename
936 self.filename = filename
933 self.filename = filename
937 # self.fp = fp
934 # self.fp = fp
938 # self.grp = grp
935 # self.grp = grp
939 # self.grp.attrs.modify('nRecords', 1)
936 # self.grp.attrs.modify('nRecords', 1)
940 self.ds = ds
937 self.ds = ds
941 self.data = data
938 self.data = data
942 # self.setFile = setFile
939 # self.setFile = setFile
943 self.firsttime = True
940 self.firsttime = True
944 self.blockIndex = 0
941 self.blockIndex = 0
945 return
942 return
946
943
947 def putData(self):
944 def putData(self):
948
945
949 if self.blockIndex == self.blocksPerFile or self.timeFlag():
946 if self.blockIndex == self.blocksPerFile or self.timeFlag():
950 self.setNextFile()
947 self.setNextFile()
951
948
952 # if not self.firsttime:
949 # if not self.firsttime:
953 self.readBlock()
950 self.readBlock()
954 self.setBlock() #Prepare data to be written
951 self.setBlock() #Prepare data to be written
955 self.writeBlock() #Write data
952 self.writeBlock() #Write data
956
953
957 return
954 return
958
955
959 def readBlock(self):
956 def readBlock(self):
960
957
961 '''
958 '''
962 data Array configured
959 data Array configured
963
960
964
961
965 self.data
962 self.data
966 '''
963 '''
967 dsList = self.dsList
964 dsList = self.dsList
968 ds = self.ds
965 ds = self.ds
969 #Setting HDF5 File
966 #Setting HDF5 File
970 fp = h5py.File(self.filename,'r+')
967 fp = h5py.File(self.filename,'r+')
971 grp = fp["Data"]
968 grp = fp["Data"]
972 ind = 0
969 ind = 0
973
970
974 # grp.attrs['blocksPerFile'] = 0
971 # grp.attrs['blocksPerFile'] = 0
975 while ind < len(dsList):
972 while ind < len(dsList):
976 dsInfo = dsList[ind]
973 dsInfo = dsList[ind]
977
974
978 if dsInfo['mode'] == 0:
975 if dsInfo['mode'] == 0:
979 ds0 = grp[dsInfo['variable']]
976 ds0 = grp[dsInfo['variable']]
980 ds[ind] = ds0
977 ds[ind] = ds0
981 ind += 1
978 ind += 1
982 else:
979 else:
983
980
984 grp0 = grp[dsInfo['variable']]
981 grp0 = grp[dsInfo['variable']]
985
982
986 for j in range(dsInfo['dsNumber']):
983 for j in range(dsInfo['dsNumber']):
987 dsInfo = dsList[ind]
984 dsInfo = dsList[ind]
988 ds0 = grp0[dsInfo['dsName']]
985 ds0 = grp0[dsInfo['dsName']]
989 ds[ind] = ds0
986 ds[ind] = ds0
990 ind += 1
987 ind += 1
991
988
992 self.fp = fp
989 self.fp = fp
993 self.grp = grp
990 self.grp = grp
994 self.ds = ds
991 self.ds = ds
995
992
996 return
993 return
997
994
998 def setBlock(self):
995 def setBlock(self):
999 '''
996 '''
1000 data Array configured
997 data Array configured
1001
998
1002
999
1003 self.data
1000 self.data
1004 '''
1001 '''
1005 #Creating Arrays
1002 #Creating Arrays
1006 dsList = self.dsList
1003 dsList = self.dsList
1007 data = self.data
1004 data = self.data
1008 ind = 0
1005 ind = 0
1009
1006
1010 while ind < len(dsList):
1007 while ind < len(dsList):
1011 dsInfo = dsList[ind]
1008 dsInfo = dsList[ind]
1012 dataAux = getattr(self.dataOut, dsInfo['variable'])
1009 dataAux = getattr(self.dataOut, dsInfo['variable'])
1013
1010
1014 mode = dsInfo['mode']
1011 mode = dsInfo['mode']
1015 nDim = dsInfo['nDim']
1012 nDim = dsInfo['nDim']
1016
1013
1017 if mode == 0 or mode == 2 or nDim == 1:
1014 if mode == 0 or mode == 2 or nDim == 1:
1018 data[ind] = dataAux
1015 data[ind] = dataAux
1019 ind += 1
1016 ind += 1
1020 # elif nDim == 1:
1017 # elif nDim == 1:
1021 # data[ind] = numpy.reshape(dataAux,(numpy.size(dataAux),1))
1018 # data[ind] = numpy.reshape(dataAux,(numpy.size(dataAux),1))
1022 # ind += 1
1019 # ind += 1
1023 elif nDim == 2:
1020 elif nDim == 2:
1024 for j in range(dsInfo['dsNumber']):
1021 for j in range(dsInfo['dsNumber']):
1025 data[ind] = dataAux[j,:]
1022 data[ind] = dataAux[j,:]
1026 ind += 1
1023 ind += 1
1027 elif nDim == 3:
1024 elif nDim == 3:
1028 for j in range(dsInfo['dsNumber']):
1025 for j in range(dsInfo['dsNumber']):
1029 data[ind] = dataAux[:,j,:]
1026 data[ind] = dataAux[:,j,:]
1030 ind += 1
1027 ind += 1
1031
1028
1032 self.data = data
1029 self.data = data
1033 return
1030 return
1034
1031
1035 def writeBlock(self):
1032 def writeBlock(self):
1036 '''
1033 '''
1037 Saves the block in the HDF5 file
1034 Saves the block in the HDF5 file
1038 '''
1035 '''
1039 dsList = self.dsList
1036 dsList = self.dsList
1040
1037
1041 for i in range(len(self.ds)):
1038 for i in range(len(self.ds)):
1042 dsInfo = dsList[i]
1039 dsInfo = dsList[i]
1043 nDim = dsInfo['nDim']
1040 nDim = dsInfo['nDim']
1044 mode = dsInfo['mode']
1041 mode = dsInfo['mode']
1045
1042
1046 # First time
1043 # First time
1047 if self.firsttime:
1044 if self.firsttime:
1048 # self.ds[i].resize(self.data[i].shape)
1045 # self.ds[i].resize(self.data[i].shape)
1049 # self.ds[i][self.blockIndex,:] = self.data[i]
1046 # self.ds[i][self.blockIndex,:] = self.data[i]
1050 if type(self.data[i]) == numpy.ndarray:
1047 if type(self.data[i]) == numpy.ndarray:
1051
1048
1052 if nDim == 3:
1049 if nDim == 3:
1053 self.data[i] = self.data[i].reshape((self.data[i].shape[0],self.data[i].shape[1],1))
1050 self.data[i] = self.data[i].reshape((self.data[i].shape[0],self.data[i].shape[1],1))
1054 self.ds[i].resize(self.data[i].shape)
1051 self.ds[i].resize(self.data[i].shape)
1055 if mode == 2:
1052 if mode == 2:
1056 self.ds[i].resize(self.data[i].shape)
1053 self.ds[i].resize(self.data[i].shape)
1057 self.ds[i][:] = self.data[i]
1054 self.ds[i][:] = self.data[i]
1058 else:
1055 else:
1059
1056
1060 # From second time
1057 # From second time
1061 # Meteors!
1058 # Meteors!
1062 if mode == 2:
1059 if mode == 2:
1063 dataShape = self.data[i].shape
1060 dataShape = self.data[i].shape
1064 dsShape = self.ds[i].shape
1061 dsShape = self.ds[i].shape
1065 self.ds[i].resize((self.ds[i].shape[0] + dataShape[0],self.ds[i].shape[1]))
1062 self.ds[i].resize((self.ds[i].shape[0] + dataShape[0],self.ds[i].shape[1]))
1066 self.ds[i][dsShape[0]:,:] = self.data[i]
1063 self.ds[i][dsShape[0]:,:] = self.data[i]
1067 # No dimension
1064 # No dimension
1068 elif mode == 0:
1065 elif mode == 0:
1069 self.ds[i].resize((self.ds[i].shape[0], self.ds[i].shape[1] + 1))
1066 self.ds[i].resize((self.ds[i].shape[0], self.ds[i].shape[1] + 1))
1070 self.ds[i][0,-1] = self.data[i]
1067 self.ds[i][0,-1] = self.data[i]
1071 # One dimension
1068 # One dimension
1072 elif nDim == 1:
1069 elif nDim == 1:
1073 self.ds[i].resize((self.ds[i].shape[0] + 1, self.ds[i].shape[1]))
1070 self.ds[i].resize((self.ds[i].shape[0] + 1, self.ds[i].shape[1]))
1074 self.ds[i][-1,:] = self.data[i]
1071 self.ds[i][-1,:] = self.data[i]
1075 # Two dimension
1072 # Two dimension
1076 elif nDim == 2:
1073 elif nDim == 2:
1077 self.ds[i].resize((self.ds[i].shape[0] + 1,self.ds[i].shape[1]))
1074 self.ds[i].resize((self.ds[i].shape[0] + 1,self.ds[i].shape[1]))
1078 self.ds[i][self.blockIndex,:] = self.data[i]
1075 self.ds[i][self.blockIndex,:] = self.data[i]
1079 # Three dimensions
1076 # Three dimensions
1080 elif nDim == 3:
1077 elif nDim == 3:
1081 self.ds[i].resize((self.ds[i].shape[0],self.ds[i].shape[1],self.ds[i].shape[2]+1))
1078 self.ds[i].resize((self.ds[i].shape[0],self.ds[i].shape[1],self.ds[i].shape[2]+1))
1082 self.ds[i][:,:,-1] = self.data[i]
1079 self.ds[i][:,:,-1] = self.data[i]
1083
1080
1084 self.firsttime = False
1081 self.firsttime = False
1085 self.blockIndex += 1
1082 self.blockIndex += 1
1086
1083
1087 #Close to save changes
1084 #Close to save changes
1088 self.fp.flush()
1085 self.fp.flush()
1089 self.fp.close()
1086 self.fp.close()
1090 return
1087 return
1091
1088
1092 def run(self, dataOut, **kwargs):
1089 def run(self, dataOut, path=None, blocksPerFile=10, metadataList=None, dataList=None, mode=None, **kwargs):
1093
1090
1094 if not(self.isConfig):
1091 if not(self.isConfig):
1095 flagdata = self.setup(dataOut, **kwargs)
1092 flagdata = self.setup(dataOut, path=path, blocksPerFile=blocksPerFile,
1093 metadataList=metadataList, dataList=dataList, mode=mode, **kwargs)
1096
1094
1097 if not(flagdata):
1095 if not(flagdata):
1098 return
1096 return
1099
1097
1100 self.isConfig = True
1098 self.isConfig = True
1101 # self.putMetadata()
1099 # self.putMetadata()
1102 self.setNextFile()
1100 self.setNextFile()
1103
1101
1104 self.putData()
1102 self.putData()
1105 return
1103 return
@@ -1,141 +1,144
1 '''
1 '''
2 @author: Daniel Suarez
2 @author: Daniel Suarez
3 '''
3 '''
4 import numpy
4 import numpy
5 from jroproc_base import ProcessingUnit, Operation
5 from jroproc_base import ProcessingUnit, Operation
6 from schainpy.model.data.jroamisr import AMISR
6 from schainpy.model.data.jroamisr import AMISR
7
7
8 class AMISRProc(ProcessingUnit):
8 class AMISRProc(ProcessingUnit):
9 def __init__(self):
9 def __init__(self):
10 ProcessingUnit.__init__(self)
10 ProcessingUnit.__init__(self)
11 self.objectDict = {}
11 self.objectDict = {}
12 self.dataOut = AMISR()
12 self.dataOut = AMISR()
13
13
14 def run(self):
14 def run(self):
15 if self.dataIn.type == 'AMISR':
15 if self.dataIn.type == 'AMISR':
16 self.dataOut.copy(self.dataIn)
16 self.dataOut.copy(self.dataIn)
17
17
18
18
19 class PrintInfo(Operation):
19 class PrintInfo(Operation):
20 def __init__(self):
20 def __init__(self):
21 self.__isPrinted = False
21 self.__isPrinted = False
22
22
23 def run(self, dataOut):
23 def run(self, dataOut):
24
24
25 if not self.__isPrinted:
25 if not self.__isPrinted:
26 print 'Number of Records by File: %d'%dataOut.nRecords
26 print 'Number of Records by File: %d'%dataOut.nRecords
27 print 'Number of Pulses: %d'%dataOut.nProfiles
27 print 'Number of Pulses: %d'%dataOut.nProfiles
28 print 'Number of Pulses by Frame: %d'%dataOut.npulseByFrame
28 print 'Number of Pulses by Frame: %d'%dataOut.npulseByFrame
29 print 'Number of Samples by Pulse: %d'%len(dataOut.heightList)
29 print 'Number of Samples by Pulse: %d'%len(dataOut.heightList)
30 print 'Ipp Seconds: %f'%dataOut.ippSeconds
30 print 'Ipp Seconds: %f'%dataOut.ippSeconds
31 print 'Number of Beams: %d'%dataOut.nBeams
31 print 'Number of Beams: %d'%dataOut.nBeams
32 print 'BeamCodes:'
32 print 'BeamCodes:'
33 beamStrList = ['Beam %d -> Code=%d, azimuth=%2.2f, zenith=%2.2f, gain=%2.2f'%(k,v[0],v[1],v[2],v[3]) for k,v in dataOut.beamCodeDict.items()]
33 beamStrList = ['Beam %d -> Code=%d, azimuth=%2.2f, zenith=%2.2f, gain=%2.2f'%(k,v[0],v[1],v[2],v[3]) for k,v in dataOut.beamCodeDict.items()]
34 for b in beamStrList:
34 for b in beamStrList:
35 print b
35 print b
36 self.__isPrinted = True
36 self.__isPrinted = True
37
37
38 return
38 return
39
39
40
40
41 class BeamSelector(Operation):
41 class BeamSelector(Operation):
42 profileIndex = None
42 profileIndex = None
43 nProfiles = None
43 nProfiles = None
44 parameters = {
45 'beam': global_type_string,
46 }
44
47
45 def __init__(self):
48 def __init__(self):
46
49
47 self.profileIndex = 0
50 self.profileIndex = 0
48 self.__isConfig = False
51 self.__isConfig = False
49
52
50 def incIndex(self):
53 def incIndex(self):
51 self.profileIndex += 1
54 self.profileIndex += 1
52
55
53 if self.profileIndex >= self.nProfiles:
56 if self.profileIndex >= self.nProfiles:
54 self.profileIndex = 0
57 self.profileIndex = 0
55
58
56 def isProfileInRange(self, minIndex, maxIndex):
59 def isProfileInRange(self, minIndex, maxIndex):
57
60
58 if self.profileIndex < minIndex:
61 if self.profileIndex < minIndex:
59 return False
62 return False
60
63
61 if self.profileIndex > maxIndex:
64 if self.profileIndex > maxIndex:
62 return False
65 return False
63
66
64 return True
67 return True
65
68
66 def isProfileInList(self, profileList):
69 def isProfileInList(self, profileList):
67
70
68 if self.profileIndex not in profileList:
71 if self.profileIndex not in profileList:
69 return False
72 return False
70
73
71 return True
74 return True
72
75
73 def run(self, dataOut, beam=None):
76 def run(self, dataOut, beam=None):
74
77
75 dataOut.flagNoData = True
78 dataOut.flagNoData = True
76
79
77 if not(self.__isConfig):
80 if not(self.__isConfig):
78
81
79 self.nProfiles = dataOut.nProfiles
82 self.nProfiles = dataOut.nProfiles
80 self.profileIndex = dataOut.profileIndex
83 self.profileIndex = dataOut.profileIndex
81 self.__isConfig = True
84 self.__isConfig = True
82
85
83 if beam != None:
86 if beam != None:
84 if self.isProfileInList(dataOut.beamRangeDict[beam]):
87 if self.isProfileInList(dataOut.beamRangeDict[beam]):
85 beamInfo = dataOut.beamCodeDict[beam]
88 beamInfo = dataOut.beamCodeDict[beam]
86 dataOut.azimuth = beamInfo[1]
89 dataOut.azimuth = beamInfo[1]
87 dataOut.zenith = beamInfo[2]
90 dataOut.zenith = beamInfo[2]
88 dataOut.gain = beamInfo[3]
91 dataOut.gain = beamInfo[3]
89 dataOut.flagNoData = False
92 dataOut.flagNoData = False
90
93
91 self.incIndex()
94 self.incIndex()
92 return 1
95 return 1
93
96
94 else:
97 else:
95 raise ValueError, "BeamSelector needs beam value"
98 raise ValueError, "BeamSelector needs beam value"
96
99
97 return 0
100 return 0
98
101
99 class ProfileToChannels(Operation):
102 class ProfileToChannels(Operation):
100
103
101 def __init__(self):
104 def __init__(self):
102 self.__isConfig = False
105 self.__isConfig = False
103 self.__counter_chan = 0
106 self.__counter_chan = 0
104 self.buffer = None
107 self.buffer = None
105
108
106 def isProfileInList(self, profileList):
109 def isProfileInList(self, profileList):
107
110
108 if self.profileIndex not in profileList:
111 if self.profileIndex not in profileList:
109 return False
112 return False
110
113
111 return True
114 return True
112
115
113 def run(self, dataOut):
116 def run(self, dataOut):
114
117
115 dataOut.flagNoData = True
118 dataOut.flagNoData = True
116
119
117 if not(self.__isConfig):
120 if not(self.__isConfig):
118 nchannels = len(dataOut.beamRangeDict.keys())
121 nchannels = len(dataOut.beamRangeDict.keys())
119 nsamples = dataOut.nHeights
122 nsamples = dataOut.nHeights
120 self.buffer = numpy.zeros((nchannels, nsamples), dtype = 'complex128')
123 self.buffer = numpy.zeros((nchannels, nsamples), dtype = 'complex128')
121 dataOut.beam.codeList = [dataOut.beamCodeDict[x][0] for x in range(nchannels)]
124 dataOut.beam.codeList = [dataOut.beamCodeDict[x][0] for x in range(nchannels)]
122 dataOut.beam.azimuthList = [dataOut.beamCodeDict[x][1] for x in range(nchannels)]
125 dataOut.beam.azimuthList = [dataOut.beamCodeDict[x][1] for x in range(nchannels)]
123 dataOut.beam.zenithList = [dataOut.beamCodeDict[x][2] for x in range(nchannels)]
126 dataOut.beam.zenithList = [dataOut.beamCodeDict[x][2] for x in range(nchannels)]
124 self.__isConfig = True
127 self.__isConfig = True
125
128
126 for i in range(self.buffer.shape[0]):
129 for i in range(self.buffer.shape[0]):
127 if dataOut.profileIndex in dataOut.beamRangeDict[i]:
130 if dataOut.profileIndex in dataOut.beamRangeDict[i]:
128 self.buffer[i,:] = dataOut.data
131 self.buffer[i,:] = dataOut.data
129 break
132 break
130
133
131
134
132 self.__counter_chan += 1
135 self.__counter_chan += 1
133
136
134 if self.__counter_chan >= self.buffer.shape[0]:
137 if self.__counter_chan >= self.buffer.shape[0]:
135 self.__counter_chan = 0
138 self.__counter_chan = 0
136 dataOut.data = self.buffer.copy()
139 dataOut.data = self.buffer.copy()
137 dataOut.channelList = range(self.buffer.shape[0])
140 dataOut.channelList = range(self.buffer.shape[0])
138 self.__isConfig = False
141 self.__isConfig = False
139 dataOut.flagNoData = False
142 dataOut.flagNoData = False
140 pass
143 pass
141 No newline at end of file
144
@@ -1,345 +1,350
1 import numpy
1 import numpy
2
2
3 from jroproc_base import ProcessingUnit, Operation
3 from jroproc_base import ProcessingUnit, Operation
4 from schainpy.model.data.jrodata import SpectraHeis
4 from schainpy.model.data.jrodata import SpectraHeis
5
5
6 class SpectraHeisProc(ProcessingUnit):
6 class SpectraHeisProc(ProcessingUnit):
7
7
8 def __init__(self, **kwargs):
8 def __init__(self, **kwargs):
9
9
10 ProcessingUnit.__init__(self, **kwargs)
10 ProcessingUnit.__init__(self, **kwargs)
11
11
12 # self.buffer = None
12 # self.buffer = None
13 # self.firstdatatime = None
13 # self.firstdatatime = None
14 # self.profIndex = 0
14 # self.profIndex = 0
15 self.dataOut = SpectraHeis()
15 self.dataOut = SpectraHeis()
16
16
17 def __updateObjFromVoltage(self):
17 def __updateObjFromVoltage(self):
18
18
19 self.dataOut.timeZone = self.dataIn.timeZone
19 self.dataOut.timeZone = self.dataIn.timeZone
20 self.dataOut.dstFlag = self.dataIn.dstFlag
20 self.dataOut.dstFlag = self.dataIn.dstFlag
21 self.dataOut.errorCount = self.dataIn.errorCount
21 self.dataOut.errorCount = self.dataIn.errorCount
22 self.dataOut.useLocalTime = self.dataIn.useLocalTime
22 self.dataOut.useLocalTime = self.dataIn.useLocalTime
23
23
24 self.dataOut.radarControllerHeaderObj = self.dataIn.radarControllerHeaderObj.copy()#
24 self.dataOut.radarControllerHeaderObj = self.dataIn.radarControllerHeaderObj.copy()#
25 self.dataOut.systemHeaderObj = self.dataIn.systemHeaderObj.copy()#
25 self.dataOut.systemHeaderObj = self.dataIn.systemHeaderObj.copy()#
26 self.dataOut.channelList = self.dataIn.channelList
26 self.dataOut.channelList = self.dataIn.channelList
27 self.dataOut.heightList = self.dataIn.heightList
27 self.dataOut.heightList = self.dataIn.heightList
28 # self.dataOut.dtype = self.dataIn.dtype
28 # self.dataOut.dtype = self.dataIn.dtype
29 self.dataOut.dtype = numpy.dtype([('real','<f4'),('imag','<f4')])
29 self.dataOut.dtype = numpy.dtype([('real','<f4'),('imag','<f4')])
30 # self.dataOut.nHeights = self.dataIn.nHeights
30 # self.dataOut.nHeights = self.dataIn.nHeights
31 # self.dataOut.nChannels = self.dataIn.nChannels
31 # self.dataOut.nChannels = self.dataIn.nChannels
32 self.dataOut.nBaud = self.dataIn.nBaud
32 self.dataOut.nBaud = self.dataIn.nBaud
33 self.dataOut.nCode = self.dataIn.nCode
33 self.dataOut.nCode = self.dataIn.nCode
34 self.dataOut.code = self.dataIn.code
34 self.dataOut.code = self.dataIn.code
35 # self.dataOut.nProfiles = 1
35 # self.dataOut.nProfiles = 1
36 self.dataOut.ippFactor = 1
36 self.dataOut.ippFactor = 1
37 self.dataOut.noise_estimation = None
37 self.dataOut.noise_estimation = None
38 # self.dataOut.nProfiles = self.dataOut.nFFTPoints
38 # self.dataOut.nProfiles = self.dataOut.nFFTPoints
39 self.dataOut.nFFTPoints = self.dataIn.nHeights
39 self.dataOut.nFFTPoints = self.dataIn.nHeights
40 # self.dataOut.channelIndexList = self.dataIn.channelIndexList
40 # self.dataOut.channelIndexList = self.dataIn.channelIndexList
41 # self.dataOut.flagNoData = self.dataIn.flagNoData
41 # self.dataOut.flagNoData = self.dataIn.flagNoData
42 self.dataOut.flagDiscontinuousBlock = self.dataIn.flagDiscontinuousBlock
42 self.dataOut.flagDiscontinuousBlock = self.dataIn.flagDiscontinuousBlock
43 self.dataOut.utctime = self.dataIn.utctime
43 self.dataOut.utctime = self.dataIn.utctime
44 # self.dataOut.utctime = self.firstdatatime
44 # self.dataOut.utctime = self.firstdatatime
45 self.dataOut.flagDecodeData = self.dataIn.flagDecodeData #asumo q la data esta decodificada
45 self.dataOut.flagDecodeData = self.dataIn.flagDecodeData #asumo q la data esta decodificada
46 self.dataOut.flagDeflipData = self.dataIn.flagDeflipData #asumo q la data esta sin flip
46 self.dataOut.flagDeflipData = self.dataIn.flagDeflipData #asumo q la data esta sin flip
47 # self.dataOut.flagShiftFFT = self.dataIn.flagShiftFFT
47 # self.dataOut.flagShiftFFT = self.dataIn.flagShiftFFT
48 self.dataOut.nCohInt = self.dataIn.nCohInt
48 self.dataOut.nCohInt = self.dataIn.nCohInt
49 self.dataOut.nIncohInt = 1
49 self.dataOut.nIncohInt = 1
50 # self.dataOut.ippSeconds= self.dataIn.ippSeconds
50 # self.dataOut.ippSeconds= self.dataIn.ippSeconds
51 self.dataOut.windowOfFilter = self.dataIn.windowOfFilter
51 self.dataOut.windowOfFilter = self.dataIn.windowOfFilter
52
52
53 # self.dataOut.timeInterval = self.dataIn.timeInterval*self.dataOut.nIncohInt
53 # self.dataOut.timeInterval = self.dataIn.timeInterval*self.dataOut.nIncohInt
54 # self.dataOut.set=self.dataIn.set
54 # self.dataOut.set=self.dataIn.set
55 # self.dataOut.deltaHeight=self.dataIn.deltaHeight
55 # self.dataOut.deltaHeight=self.dataIn.deltaHeight
56
56
57
57
58 def __updateObjFromFits(self):
58 def __updateObjFromFits(self):
59
59
60 self.dataOut.utctime = self.dataIn.utctime
60 self.dataOut.utctime = self.dataIn.utctime
61 # self.dataOut.channelIndexList = self.dataIn.channelIndexList
61 # self.dataOut.channelIndexList = self.dataIn.channelIndexList
62
62
63 self.dataOut.channelList = self.dataIn.channelList
63 self.dataOut.channelList = self.dataIn.channelList
64 self.dataOut.heightList = self.dataIn.heightList
64 self.dataOut.heightList = self.dataIn.heightList
65 self.dataOut.data_spc = self.dataIn.data
65 self.dataOut.data_spc = self.dataIn.data
66 self.dataOut.ippSeconds = self.dataIn.ippSeconds
66 self.dataOut.ippSeconds = self.dataIn.ippSeconds
67 self.dataOut.nCohInt = self.dataIn.nCohInt
67 self.dataOut.nCohInt = self.dataIn.nCohInt
68 self.dataOut.nIncohInt = self.dataIn.nIncohInt
68 self.dataOut.nIncohInt = self.dataIn.nIncohInt
69 # self.dataOut.timeInterval = self.dataIn.timeInterval
69 # self.dataOut.timeInterval = self.dataIn.timeInterval
70 self.dataOut.timeZone = self.dataIn.timeZone
70 self.dataOut.timeZone = self.dataIn.timeZone
71 self.dataOut.useLocalTime = True
71 self.dataOut.useLocalTime = True
72 # self.dataOut.
72 # self.dataOut.
73 # self.dataOut.
73 # self.dataOut.
74
74
75 def __getFft(self):
75 def __getFft(self):
76
76
77 fft_volt = numpy.fft.fft(self.dataIn.data, axis=1)
77 fft_volt = numpy.fft.fft(self.dataIn.data, axis=1)
78 fft_volt = numpy.fft.fftshift(fft_volt,axes=(1,))
78 fft_volt = numpy.fft.fftshift(fft_volt,axes=(1,))
79 spc = numpy.abs(fft_volt * numpy.conjugate(fft_volt))/(self.dataOut.nFFTPoints)
79 spc = numpy.abs(fft_volt * numpy.conjugate(fft_volt))/(self.dataOut.nFFTPoints)
80 self.dataOut.data_spc = spc
80 self.dataOut.data_spc = spc
81
81
82 def run(self):
82 def run(self):
83
83
84 self.dataOut.flagNoData = True
84 self.dataOut.flagNoData = True
85
85
86 if self.dataIn.type == "Fits":
86 if self.dataIn.type == "Fits":
87 self.__updateObjFromFits()
87 self.__updateObjFromFits()
88 self.dataOut.flagNoData = False
88 self.dataOut.flagNoData = False
89 return
89 return
90
90
91 if self.dataIn.type == "SpectraHeis":
91 if self.dataIn.type == "SpectraHeis":
92 self.dataOut.copy(self.dataIn)
92 self.dataOut.copy(self.dataIn)
93 return
93 return
94
94
95 if self.dataIn.type == "Voltage":
95 if self.dataIn.type == "Voltage":
96 self.__updateObjFromVoltage()
96 self.__updateObjFromVoltage()
97 self.__getFft()
97 self.__getFft()
98 self.dataOut.flagNoData = False
98 self.dataOut.flagNoData = False
99
99
100 return
100 return
101
101
102 raise ValueError, "The type object %s is not valid"%(self.dataIn.type)
102 raise ValueError, "The type object %s is not valid"%(self.dataIn.type)
103
103
104
104
105 def selectChannels(self, channelList):
105 def selectChannels(self, channelList):
106
106
107 channelIndexList = []
107 channelIndexList = []
108
108
109 for channel in channelList:
109 for channel in channelList:
110 index = self.dataOut.channelList.index(channel)
110 index = self.dataOut.channelList.index(channel)
111 channelIndexList.append(index)
111 channelIndexList.append(index)
112
112
113 self.selectChannelsByIndex(channelIndexList)
113 self.selectChannelsByIndex(channelIndexList)
114
114
115 def selectChannelsByIndex(self, channelIndexList):
115 def selectChannelsByIndex(self, channelIndexList):
116 """
116 """
117 Selecciona un bloque de datos en base a canales segun el channelIndexList
117 Selecciona un bloque de datos en base a canales segun el channelIndexList
118
118
119 Input:
119 Input:
120 channelIndexList : lista sencilla de canales a seleccionar por ej. [2,3,7]
120 channelIndexList : lista sencilla de canales a seleccionar por ej. [2,3,7]
121
121
122 Affected:
122 Affected:
123 self.dataOut.data
123 self.dataOut.data
124 self.dataOut.channelIndexList
124 self.dataOut.channelIndexList
125 self.dataOut.nChannels
125 self.dataOut.nChannels
126 self.dataOut.m_ProcessingHeader.totalSpectra
126 self.dataOut.m_ProcessingHeader.totalSpectra
127 self.dataOut.systemHeaderObj.numChannels
127 self.dataOut.systemHeaderObj.numChannels
128 self.dataOut.m_ProcessingHeader.blockSize
128 self.dataOut.m_ProcessingHeader.blockSize
129
129
130 Return:
130 Return:
131 None
131 None
132 """
132 """
133
133
134 for channelIndex in channelIndexList:
134 for channelIndex in channelIndexList:
135 if channelIndex not in self.dataOut.channelIndexList:
135 if channelIndex not in self.dataOut.channelIndexList:
136 print channelIndexList
136 print channelIndexList
137 raise ValueError, "The value %d in channelIndexList is not valid" %channelIndex
137 raise ValueError, "The value %d in channelIndexList is not valid" %channelIndex
138
138
139 # nChannels = len(channelIndexList)
139 # nChannels = len(channelIndexList)
140
140
141 data_spc = self.dataOut.data_spc[channelIndexList,:]
141 data_spc = self.dataOut.data_spc[channelIndexList,:]
142
142
143 self.dataOut.data_spc = data_spc
143 self.dataOut.data_spc = data_spc
144 self.dataOut.channelList = [self.dataOut.channelList[i] for i in channelIndexList]
144 self.dataOut.channelList = [self.dataOut.channelList[i] for i in channelIndexList]
145
145
146 return 1
146 return 1
147
147
148 class IncohInt4SpectraHeis(Operation):
148 class IncohInt4SpectraHeis(Operation):
149
149
150 isConfig = False
150 isConfig = False
151
151
152 __profIndex = 0
152 __profIndex = 0
153 __withOverapping = False
153 __withOverapping = False
154
154
155 __byTime = False
155 __byTime = False
156 __initime = None
156 __initime = None
157 __lastdatatime = None
157 __lastdatatime = None
158 __integrationtime = None
158 __integrationtime = None
159
159
160 __buffer = None
160 __buffer = None
161
161
162 __dataReady = False
162 __dataReady = False
163
163
164 n = None
164 n = None
165 parameters = {
166 'n': global_type_float,
167 'timeInterval': global_type_integer,
168 'overlapping': global_type_boolean,
169 }
165
170
166
171
167 def __init__(self, **kwargs):
172 def __init__(self, **kwargs):
168
173
169 Operation.__init__(self, **kwargs)
174 Operation.__init__(self, **kwargs)
170 # self.isConfig = False
175 # self.isConfig = False
171
176
172 def setup(self, n=None, timeInterval=None, overlapping=False):
177 def setup(self, n=None, timeInterval=None, overlapping=False):
173 """
178 """
174 Set the parameters of the integration class.
179 Set the parameters of the integration class.
175
180
176 Inputs:
181 Inputs:
177
182
178 n : Number of coherent integrations
183 n : Number of coherent integrations
179 timeInterval : Time of integration. If the parameter "n" is selected this one does not work
184 timeInterval : Time of integration. If the parameter "n" is selected this one does not work
180 overlapping :
185 overlapping :
181
186
182 """
187 """
183
188
184 self.__initime = None
189 self.__initime = None
185 self.__lastdatatime = 0
190 self.__lastdatatime = 0
186 self.__buffer = None
191 self.__buffer = None
187 self.__dataReady = False
192 self.__dataReady = False
188
193
189
194
190 if n == None and timeInterval == None:
195 if n == None and timeInterval == None:
191 raise ValueError, "n or timeInterval should be specified ..."
196 raise ValueError, "n or timeInterval should be specified ..."
192
197
193 if n != None:
198 if n != None:
194 self.n = n
199 self.n = n
195 self.__byTime = False
200 self.__byTime = False
196 else:
201 else:
197 self.__integrationtime = timeInterval #* 60. #if (type(timeInterval)!=integer) -> change this line
202 self.__integrationtime = timeInterval #* 60. #if (type(timeInterval)!=integer) -> change this line
198 self.n = 9999
203 self.n = 9999
199 self.__byTime = True
204 self.__byTime = True
200
205
201 if overlapping:
206 if overlapping:
202 self.__withOverapping = True
207 self.__withOverapping = True
203 self.__buffer = None
208 self.__buffer = None
204 else:
209 else:
205 self.__withOverapping = False
210 self.__withOverapping = False
206 self.__buffer = 0
211 self.__buffer = 0
207
212
208 self.__profIndex = 0
213 self.__profIndex = 0
209
214
210 def putData(self, data):
215 def putData(self, data):
211
216
212 """
217 """
213 Add a profile to the __buffer and increase in one the __profileIndex
218 Add a profile to the __buffer and increase in one the __profileIndex
214
219
215 """
220 """
216
221
217 if not self.__withOverapping:
222 if not self.__withOverapping:
218 self.__buffer += data.copy()
223 self.__buffer += data.copy()
219 self.__profIndex += 1
224 self.__profIndex += 1
220 return
225 return
221
226
222 #Overlapping data
227 #Overlapping data
223 nChannels, nHeis = data.shape
228 nChannels, nHeis = data.shape
224 data = numpy.reshape(data, (1, nChannels, nHeis))
229 data = numpy.reshape(data, (1, nChannels, nHeis))
225
230
226 #If the buffer is empty then it takes the data value
231 #If the buffer is empty then it takes the data value
227 if self.__buffer is None:
232 if self.__buffer is None:
228 self.__buffer = data
233 self.__buffer = data
229 self.__profIndex += 1
234 self.__profIndex += 1
230 return
235 return
231
236
232 #If the buffer length is lower than n then stakcing the data value
237 #If the buffer length is lower than n then stakcing the data value
233 if self.__profIndex < self.n:
238 if self.__profIndex < self.n:
234 self.__buffer = numpy.vstack((self.__buffer, data))
239 self.__buffer = numpy.vstack((self.__buffer, data))
235 self.__profIndex += 1
240 self.__profIndex += 1
236 return
241 return
237
242
238 #If the buffer length is equal to n then replacing the last buffer value with the data value
243 #If the buffer length is equal to n then replacing the last buffer value with the data value
239 self.__buffer = numpy.roll(self.__buffer, -1, axis=0)
244 self.__buffer = numpy.roll(self.__buffer, -1, axis=0)
240 self.__buffer[self.n-1] = data
245 self.__buffer[self.n-1] = data
241 self.__profIndex = self.n
246 self.__profIndex = self.n
242 return
247 return
243
248
244
249
245 def pushData(self):
250 def pushData(self):
246 """
251 """
247 Return the sum of the last profiles and the profiles used in the sum.
252 Return the sum of the last profiles and the profiles used in the sum.
248
253
249 Affected:
254 Affected:
250
255
251 self.__profileIndex
256 self.__profileIndex
252
257
253 """
258 """
254
259
255 if not self.__withOverapping:
260 if not self.__withOverapping:
256 data = self.__buffer
261 data = self.__buffer
257 n = self.__profIndex
262 n = self.__profIndex
258
263
259 self.__buffer = 0
264 self.__buffer = 0
260 self.__profIndex = 0
265 self.__profIndex = 0
261
266
262 return data, n
267 return data, n
263
268
264 #Integration with Overlapping
269 #Integration with Overlapping
265 data = numpy.sum(self.__buffer, axis=0)
270 data = numpy.sum(self.__buffer, axis=0)
266 n = self.__profIndex
271 n = self.__profIndex
267
272
268 return data, n
273 return data, n
269
274
270 def byProfiles(self, data):
275 def byProfiles(self, data):
271
276
272 self.__dataReady = False
277 self.__dataReady = False
273 avgdata = None
278 avgdata = None
274 # n = None
279 # n = None
275
280
276 self.putData(data)
281 self.putData(data)
277
282
278 if self.__profIndex == self.n:
283 if self.__profIndex == self.n:
279
284
280 avgdata, n = self.pushData()
285 avgdata, n = self.pushData()
281 self.__dataReady = True
286 self.__dataReady = True
282
287
283 return avgdata
288 return avgdata
284
289
285 def byTime(self, data, datatime):
290 def byTime(self, data, datatime):
286
291
287 self.__dataReady = False
292 self.__dataReady = False
288 avgdata = None
293 avgdata = None
289 n = None
294 n = None
290
295
291 self.putData(data)
296 self.putData(data)
292
297
293 if (datatime - self.__initime) >= self.__integrationtime:
298 if (datatime - self.__initime) >= self.__integrationtime:
294 avgdata, n = self.pushData()
299 avgdata, n = self.pushData()
295 self.n = n
300 self.n = n
296 self.__dataReady = True
301 self.__dataReady = True
297
302
298 return avgdata
303 return avgdata
299
304
300 def integrate(self, data, datatime=None):
305 def integrate(self, data, datatime=None):
301
306
302 if self.__initime == None:
307 if self.__initime == None:
303 self.__initime = datatime
308 self.__initime = datatime
304
309
305 if self.__byTime:
310 if self.__byTime:
306 avgdata = self.byTime(data, datatime)
311 avgdata = self.byTime(data, datatime)
307 else:
312 else:
308 avgdata = self.byProfiles(data)
313 avgdata = self.byProfiles(data)
309
314
310
315
311 self.__lastdatatime = datatime
316 self.__lastdatatime = datatime
312
317
313 if avgdata is None:
318 if avgdata is None:
314 return None, None
319 return None, None
315
320
316 avgdatatime = self.__initime
321 avgdatatime = self.__initime
317
322
318 deltatime = datatime -self.__lastdatatime
323 deltatime = datatime -self.__lastdatatime
319
324
320 if not self.__withOverapping:
325 if not self.__withOverapping:
321 self.__initime = datatime
326 self.__initime = datatime
322 else:
327 else:
323 self.__initime += deltatime
328 self.__initime += deltatime
324
329
325 return avgdata, avgdatatime
330 return avgdata, avgdatatime
326
331
327 def run(self, dataOut, **kwargs):
332 def run(self, dataOut, n=None, timeInterval=None, overlapping=False, **kwargs):
328
333
329 if not self.isConfig:
334 if not self.isConfig:
330 self.setup(**kwargs)
335 self.setup(n=n, timeInterval=timeInterval, overlapping=overlapping)
331 self.isConfig = True
336 self.isConfig = True
332
337
333 avgdata, avgdatatime = self.integrate(dataOut.data_spc, dataOut.utctime)
338 avgdata, avgdatatime = self.integrate(dataOut.data_spc, dataOut.utctime)
334
339
335 # dataOut.timeInterval *= n
340 # dataOut.timeInterval *= n
336 dataOut.flagNoData = True
341 dataOut.flagNoData = True
337
342
338 if self.__dataReady:
343 if self.__dataReady:
339 dataOut.data_spc = avgdata
344 dataOut.data_spc = avgdata
340 dataOut.nIncohInt *= self.n
345 dataOut.nIncohInt *= self.n
341 # dataOut.nCohInt *= self.n
346 # dataOut.nCohInt *= self.n
342 dataOut.utctime = avgdatatime
347 dataOut.utctime = avgdatatime
343 # dataOut.timeInterval = dataOut.ippSeconds * dataOut.nIncohInt
348 # dataOut.timeInterval = dataOut.ippSeconds * dataOut.nIncohInt
344 # dataOut.timeInterval = self.__timeInterval*self.n
349 # dataOut.timeInterval = self.__timeInterval*self.n
345 dataOut.flagNoData = False
350 dataOut.flagNoData = False
@@ -1,2805 +1,2812
1 import numpy
1 import numpy
2 import math
2 import math
3 from scipy import optimize, interpolate, signal, stats, ndimage
3 from scipy import optimize, interpolate, signal, stats, ndimage
4 import re
4 import re
5 import datetime
5 import datetime
6 import copy
6 import copy
7 import sys
7 import sys
8 import importlib
8 import importlib
9 import itertools
9 import itertools
10
10
11 from jroproc_base import ProcessingUnit, Operation
11 from jroproc_base import ProcessingUnit, Operation
12 from schainpy.model.data.jrodata import Parameters, hildebrand_sekhon
12 from schainpy.model.data.jrodata import Parameters, hildebrand_sekhon
13
13
14
14
15 class ParametersProc(ProcessingUnit):
15 class ParametersProc(ProcessingUnit):
16
16
17 nSeconds = None
17 nSeconds = None
18
18
19 def __init__(self):
19 def __init__(self):
20 ProcessingUnit.__init__(self)
20 ProcessingUnit.__init__(self)
21
21
22 # self.objectDict = {}
22 # self.objectDict = {}
23 self.buffer = None
23 self.buffer = None
24 self.firstdatatime = None
24 self.firstdatatime = None
25 self.profIndex = 0
25 self.profIndex = 0
26 self.dataOut = Parameters()
26 self.dataOut = Parameters()
27
27
28 def __updateObjFromInput(self):
28 def __updateObjFromInput(self):
29
29
30 self.dataOut.inputUnit = self.dataIn.type
30 self.dataOut.inputUnit = self.dataIn.type
31
31
32 self.dataOut.timeZone = self.dataIn.timeZone
32 self.dataOut.timeZone = self.dataIn.timeZone
33 self.dataOut.dstFlag = self.dataIn.dstFlag
33 self.dataOut.dstFlag = self.dataIn.dstFlag
34 self.dataOut.errorCount = self.dataIn.errorCount
34 self.dataOut.errorCount = self.dataIn.errorCount
35 self.dataOut.useLocalTime = self.dataIn.useLocalTime
35 self.dataOut.useLocalTime = self.dataIn.useLocalTime
36
36
37 self.dataOut.radarControllerHeaderObj = self.dataIn.radarControllerHeaderObj.copy()
37 self.dataOut.radarControllerHeaderObj = self.dataIn.radarControllerHeaderObj.copy()
38 self.dataOut.systemHeaderObj = self.dataIn.systemHeaderObj.copy()
38 self.dataOut.systemHeaderObj = self.dataIn.systemHeaderObj.copy()
39 self.dataOut.channelList = self.dataIn.channelList
39 self.dataOut.channelList = self.dataIn.channelList
40 self.dataOut.heightList = self.dataIn.heightList
40 self.dataOut.heightList = self.dataIn.heightList
41 self.dataOut.dtype = numpy.dtype([('real','<f4'),('imag','<f4')])
41 self.dataOut.dtype = numpy.dtype([('real','<f4'),('imag','<f4')])
42 # self.dataOut.nHeights = self.dataIn.nHeights
42 # self.dataOut.nHeights = self.dataIn.nHeights
43 # self.dataOut.nChannels = self.dataIn.nChannels
43 # self.dataOut.nChannels = self.dataIn.nChannels
44 self.dataOut.nBaud = self.dataIn.nBaud
44 self.dataOut.nBaud = self.dataIn.nBaud
45 self.dataOut.nCode = self.dataIn.nCode
45 self.dataOut.nCode = self.dataIn.nCode
46 self.dataOut.code = self.dataIn.code
46 self.dataOut.code = self.dataIn.code
47 # self.dataOut.nProfiles = self.dataOut.nFFTPoints
47 # self.dataOut.nProfiles = self.dataOut.nFFTPoints
48 self.dataOut.flagDiscontinuousBlock = self.dataIn.flagDiscontinuousBlock
48 self.dataOut.flagDiscontinuousBlock = self.dataIn.flagDiscontinuousBlock
49 # self.dataOut.utctime = self.firstdatatime
49 # self.dataOut.utctime = self.firstdatatime
50 self.dataOut.utctime = self.dataIn.utctime
50 self.dataOut.utctime = self.dataIn.utctime
51 self.dataOut.flagDecodeData = self.dataIn.flagDecodeData #asumo q la data esta decodificada
51 self.dataOut.flagDecodeData = self.dataIn.flagDecodeData #asumo q la data esta decodificada
52 self.dataOut.flagDeflipData = self.dataIn.flagDeflipData #asumo q la data esta sin flip
52 self.dataOut.flagDeflipData = self.dataIn.flagDeflipData #asumo q la data esta sin flip
53 self.dataOut.nCohInt = self.dataIn.nCohInt
53 self.dataOut.nCohInt = self.dataIn.nCohInt
54 # self.dataOut.nIncohInt = 1
54 # self.dataOut.nIncohInt = 1
55 self.dataOut.ippSeconds = self.dataIn.ippSeconds
55 self.dataOut.ippSeconds = self.dataIn.ippSeconds
56 # self.dataOut.windowOfFilter = self.dataIn.windowOfFilter
56 # self.dataOut.windowOfFilter = self.dataIn.windowOfFilter
57 self.dataOut.timeInterval1 = self.dataIn.timeInterval
57 self.dataOut.timeInterval1 = self.dataIn.timeInterval
58 self.dataOut.heightList = self.dataIn.getHeiRange()
58 self.dataOut.heightList = self.dataIn.getHeiRange()
59 self.dataOut.frequency = self.dataIn.frequency
59 self.dataOut.frequency = self.dataIn.frequency
60 #self.dataOut.noise = self.dataIn.noise
60 #self.dataOut.noise = self.dataIn.noise
61
61
62 def run(self):
62 def run(self):
63
63
64 #---------------------- Voltage Data ---------------------------
64 #---------------------- Voltage Data ---------------------------
65
65
66 if self.dataIn.type == "Voltage":
66 if self.dataIn.type == "Voltage":
67
67
68 self.__updateObjFromInput()
68 self.__updateObjFromInput()
69 self.dataOut.data_pre = self.dataIn.data.copy()
69 self.dataOut.data_pre = self.dataIn.data.copy()
70 self.dataOut.flagNoData = False
70 self.dataOut.flagNoData = False
71 self.dataOut.utctimeInit = self.dataIn.utctime
71 self.dataOut.utctimeInit = self.dataIn.utctime
72 self.dataOut.paramInterval = self.dataIn.nProfiles*self.dataIn.nCohInt*self.dataIn.ippSeconds
72 self.dataOut.paramInterval = self.dataIn.nProfiles*self.dataIn.nCohInt*self.dataIn.ippSeconds
73 return
73 return
74
74
75 #---------------------- Spectra Data ---------------------------
75 #---------------------- Spectra Data ---------------------------
76
76
77 if self.dataIn.type == "Spectra":
77 if self.dataIn.type == "Spectra":
78
78
79 self.dataOut.data_pre = (self.dataIn.data_spc, self.dataIn.data_cspc)
79 self.dataOut.data_pre = (self.dataIn.data_spc, self.dataIn.data_cspc)
80 self.dataOut.data_spc = self.dataIn.data_spc
80 self.dataOut.data_spc = self.dataIn.data_spc
81 self.dataOut.data_cspc = self.dataIn.data_cspc
81 self.dataOut.data_cspc = self.dataIn.data_cspc
82 self.dataOut.nProfiles = self.dataIn.nProfiles
82 self.dataOut.nProfiles = self.dataIn.nProfiles
83 self.dataOut.nIncohInt = self.dataIn.nIncohInt
83 self.dataOut.nIncohInt = self.dataIn.nIncohInt
84 self.dataOut.nFFTPoints = self.dataIn.nFFTPoints
84 self.dataOut.nFFTPoints = self.dataIn.nFFTPoints
85 self.dataOut.ippFactor = self.dataIn.ippFactor
85 self.dataOut.ippFactor = self.dataIn.ippFactor
86 #self.dataOut.normFactor = self.dataIn.getNormFactor()
86 #self.dataOut.normFactor = self.dataIn.getNormFactor()
87 self.dataOut.pairsList = self.dataIn.pairsList
87 self.dataOut.pairsList = self.dataIn.pairsList
88 self.dataOut.groupList = self.dataIn.pairsList
88 self.dataOut.groupList = self.dataIn.pairsList
89 self.dataOut.abscissaList = self.dataIn.getVelRange(1)
89 self.dataOut.abscissaList = self.dataIn.getVelRange(1)
90 self.dataOut.flagNoData = False
90 self.dataOut.flagNoData = False
91
91
92 #---------------------- Correlation Data ---------------------------
92 #---------------------- Correlation Data ---------------------------
93
93
94 if self.dataIn.type == "Correlation":
94 if self.dataIn.type == "Correlation":
95 acf_ind, ccf_ind, acf_pairs, ccf_pairs, data_acf, data_ccf = self.dataIn.splitFunctions()
95 acf_ind, ccf_ind, acf_pairs, ccf_pairs, data_acf, data_ccf = self.dataIn.splitFunctions()
96
96
97 self.dataOut.data_pre = (self.dataIn.data_cf[acf_ind,:], self.dataIn.data_cf[ccf_ind,:,:])
97 self.dataOut.data_pre = (self.dataIn.data_cf[acf_ind,:], self.dataIn.data_cf[ccf_ind,:,:])
98 self.dataOut.normFactor = (self.dataIn.normFactor[acf_ind,:], self.dataIn.normFactor[ccf_ind,:])
98 self.dataOut.normFactor = (self.dataIn.normFactor[acf_ind,:], self.dataIn.normFactor[ccf_ind,:])
99 self.dataOut.groupList = (acf_pairs, ccf_pairs)
99 self.dataOut.groupList = (acf_pairs, ccf_pairs)
100
100
101 self.dataOut.abscissaList = self.dataIn.lagRange
101 self.dataOut.abscissaList = self.dataIn.lagRange
102 self.dataOut.noise = self.dataIn.noise
102 self.dataOut.noise = self.dataIn.noise
103 self.dataOut.data_SNR = self.dataIn.SNR
103 self.dataOut.data_SNR = self.dataIn.SNR
104 self.dataOut.flagNoData = False
104 self.dataOut.flagNoData = False
105 self.dataOut.nAvg = self.dataIn.nAvg
105 self.dataOut.nAvg = self.dataIn.nAvg
106
106
107 #---------------------- Parameters Data ---------------------------
107 #---------------------- Parameters Data ---------------------------
108
108
109 if self.dataIn.type == "Parameters":
109 if self.dataIn.type == "Parameters":
110 self.dataOut.copy(self.dataIn)
110 self.dataOut.copy(self.dataIn)
111 self.dataOut.utctimeInit = self.dataIn.utctime
111 self.dataOut.utctimeInit = self.dataIn.utctime
112 self.dataOut.flagNoData = False
112 self.dataOut.flagNoData = False
113
113
114 return True
114 return True
115
115
116 self.__updateObjFromInput()
116 self.__updateObjFromInput()
117 self.dataOut.utctimeInit = self.dataIn.utctime
117 self.dataOut.utctimeInit = self.dataIn.utctime
118 self.dataOut.paramInterval = self.dataIn.timeInterval
118 self.dataOut.paramInterval = self.dataIn.timeInterval
119
119
120 return
120 return
121
121
122 class SpectralMoments(Operation):
122 class SpectralMoments(Operation):
123
123
124 '''
124 '''
125 Function SpectralMoments()
125 Function SpectralMoments()
126
126
127 Calculates moments (power, mean, standard deviation) and SNR of the signal
127 Calculates moments (power, mean, standard deviation) and SNR of the signal
128
128
129 Type of dataIn: Spectra
129 Type of dataIn: Spectra
130
130
131 Configuration Parameters:
131 Configuration Parameters:
132
132
133 dirCosx : Cosine director in X axis
133 dirCosx : Cosine director in X axis
134 dirCosy : Cosine director in Y axis
134 dirCosy : Cosine director in Y axis
135
135
136 elevation :
136 elevation :
137 azimuth :
137 azimuth :
138
138
139 Input:
139 Input:
140 channelList : simple channel list to select e.g. [2,3,7]
140 channelList : simple channel list to select e.g. [2,3,7]
141 self.dataOut.data_pre : Spectral data
141 self.dataOut.data_pre : Spectral data
142 self.dataOut.abscissaList : List of frequencies
142 self.dataOut.abscissaList : List of frequencies
143 self.dataOut.noise : Noise level per channel
143 self.dataOut.noise : Noise level per channel
144
144
145 Affected:
145 Affected:
146 self.dataOut.data_param : Parameters per channel
146 self.dataOut.data_param : Parameters per channel
147 self.dataOut.data_SNR : SNR per channel
147 self.dataOut.data_SNR : SNR per channel
148
148
149 '''
149 '''
150
150
151 def run(self, dataOut):
151 def run(self, dataOut):
152
152
153 #dataOut.data_pre = dataOut.data_pre[0]
153 #dataOut.data_pre = dataOut.data_pre[0]
154 data = dataOut.data_pre[0]
154 data = dataOut.data_pre[0]
155 absc = dataOut.abscissaList[:-1]
155 absc = dataOut.abscissaList[:-1]
156 noise = dataOut.noise
156 noise = dataOut.noise
157 nChannel = data.shape[0]
157 nChannel = data.shape[0]
158 data_param = numpy.zeros((nChannel, 4, data.shape[2]))
158 data_param = numpy.zeros((nChannel, 4, data.shape[2]))
159
159
160 for ind in range(nChannel):
160 for ind in range(nChannel):
161 data_param[ind,:,:] = self.__calculateMoments(data[ind,:,:], absc, noise[ind])
161 data_param[ind,:,:] = self.__calculateMoments(data[ind,:,:], absc, noise[ind])
162
162
163 dataOut.data_param = data_param[:,1:,:]
163 dataOut.data_param = data_param[:,1:,:]
164 dataOut.data_SNR = data_param[:,0]
164 dataOut.data_SNR = data_param[:,0]
165 dataOut.data_DOP = data_param[:,1]
165 dataOut.data_DOP = data_param[:,1]
166 dataOut.data_MEAN = data_param[:,2]
166 dataOut.data_MEAN = data_param[:,2]
167 dataOut.data_STD = data_param[:,3]
167 dataOut.data_STD = data_param[:,3]
168 return
168 return
169
169
170 def __calculateMoments(self, oldspec, oldfreq, n0, nicoh = None, graph = None, smooth = None, type1 = None, fwindow = None, snrth = None, dc = None, aliasing = None, oldfd = None, wwauto = None):
170 def __calculateMoments(self, oldspec, oldfreq, n0, nicoh = None, graph = None, smooth = None, type1 = None, fwindow = None, snrth = None, dc = None, aliasing = None, oldfd = None, wwauto = None):
171
171
172 if (nicoh is None): nicoh = 1
172 if (nicoh is None): nicoh = 1
173 if (graph is None): graph = 0
173 if (graph is None): graph = 0
174 if (smooth is None): smooth = 0
174 if (smooth is None): smooth = 0
175 elif (self.smooth < 3): smooth = 0
175 elif (self.smooth < 3): smooth = 0
176
176
177 if (type1 is None): type1 = 0
177 if (type1 is None): type1 = 0
178 if (fwindow is None): fwindow = numpy.zeros(oldfreq.size) + 1
178 if (fwindow is None): fwindow = numpy.zeros(oldfreq.size) + 1
179 if (snrth is None): snrth = -3
179 if (snrth is None): snrth = -3
180 if (dc is None): dc = 0
180 if (dc is None): dc = 0
181 if (aliasing is None): aliasing = 0
181 if (aliasing is None): aliasing = 0
182 if (oldfd is None): oldfd = 0
182 if (oldfd is None): oldfd = 0
183 if (wwauto is None): wwauto = 0
183 if (wwauto is None): wwauto = 0
184
184
185 if (n0 < 1.e-20): n0 = 1.e-20
185 if (n0 < 1.e-20): n0 = 1.e-20
186
186
187 freq = oldfreq
187 freq = oldfreq
188 vec_power = numpy.zeros(oldspec.shape[1])
188 vec_power = numpy.zeros(oldspec.shape[1])
189 vec_fd = numpy.zeros(oldspec.shape[1])
189 vec_fd = numpy.zeros(oldspec.shape[1])
190 vec_w = numpy.zeros(oldspec.shape[1])
190 vec_w = numpy.zeros(oldspec.shape[1])
191 vec_snr = numpy.zeros(oldspec.shape[1])
191 vec_snr = numpy.zeros(oldspec.shape[1])
192
192
193 for ind in range(oldspec.shape[1]):
193 for ind in range(oldspec.shape[1]):
194
194
195 spec = oldspec[:,ind]
195 spec = oldspec[:,ind]
196 aux = spec*fwindow
196 aux = spec*fwindow
197 max_spec = aux.max()
197 max_spec = aux.max()
198 m = list(aux).index(max_spec)
198 m = list(aux).index(max_spec)
199
199
200 #Smooth
200 #Smooth
201 if (smooth == 0): spec2 = spec
201 if (smooth == 0): spec2 = spec
202 else: spec2 = scipy.ndimage.filters.uniform_filter1d(spec,size=smooth)
202 else: spec2 = scipy.ndimage.filters.uniform_filter1d(spec,size=smooth)
203
203
204 # Calculo de Momentos
204 # Calculo de Momentos
205 bb = spec2[range(m,spec2.size)]
205 bb = spec2[range(m,spec2.size)]
206 bb = (bb<n0).nonzero()
206 bb = (bb<n0).nonzero()
207 bb = bb[0]
207 bb = bb[0]
208
208
209 ss = spec2[range(0,m + 1)]
209 ss = spec2[range(0,m + 1)]
210 ss = (ss<n0).nonzero()
210 ss = (ss<n0).nonzero()
211 ss = ss[0]
211 ss = ss[0]
212
212
213 if (bb.size == 0):
213 if (bb.size == 0):
214 bb0 = spec.size - 1 - m
214 bb0 = spec.size - 1 - m
215 else:
215 else:
216 bb0 = bb[0] - 1
216 bb0 = bb[0] - 1
217 if (bb0 < 0):
217 if (bb0 < 0):
218 bb0 = 0
218 bb0 = 0
219
219
220 if (ss.size == 0): ss1 = 1
220 if (ss.size == 0): ss1 = 1
221 else: ss1 = max(ss) + 1
221 else: ss1 = max(ss) + 1
222
222
223 if (ss1 > m): ss1 = m
223 if (ss1 > m): ss1 = m
224
224
225 valid = numpy.asarray(range(int(m + bb0 - ss1 + 1))) + ss1
225 valid = numpy.asarray(range(int(m + bb0 - ss1 + 1))) + ss1
226 power = ((spec2[valid] - n0)*fwindow[valid]).sum()
226 power = ((spec2[valid] - n0)*fwindow[valid]).sum()
227 fd = ((spec2[valid]- n0)*freq[valid]*fwindow[valid]).sum()/power
227 fd = ((spec2[valid]- n0)*freq[valid]*fwindow[valid]).sum()/power
228 w = math.sqrt(((spec2[valid] - n0)*fwindow[valid]*(freq[valid]- fd)**2).sum()/power)
228 w = math.sqrt(((spec2[valid] - n0)*fwindow[valid]*(freq[valid]- fd)**2).sum()/power)
229 snr = (spec2.mean()-n0)/n0
229 snr = (spec2.mean()-n0)/n0
230
230
231 if (snr < 1.e-20) :
231 if (snr < 1.e-20) :
232 snr = 1.e-20
232 snr = 1.e-20
233
233
234 vec_power[ind] = power
234 vec_power[ind] = power
235 vec_fd[ind] = fd
235 vec_fd[ind] = fd
236 vec_w[ind] = w
236 vec_w[ind] = w
237 vec_snr[ind] = snr
237 vec_snr[ind] = snr
238
238
239 moments = numpy.vstack((vec_snr, vec_power, vec_fd, vec_w))
239 moments = numpy.vstack((vec_snr, vec_power, vec_fd, vec_w))
240 return moments
240 return moments
241
241
242 #------------------ Get SA Parameters --------------------------
242 #------------------ Get SA Parameters --------------------------
243
243
244 def GetSAParameters(self):
244 def GetSAParameters(self):
245 #SA en frecuencia
245 #SA en frecuencia
246 pairslist = self.dataOut.groupList
246 pairslist = self.dataOut.groupList
247 num_pairs = len(pairslist)
247 num_pairs = len(pairslist)
248
248
249 vel = self.dataOut.abscissaList
249 vel = self.dataOut.abscissaList
250 spectra = self.dataOut.data_pre[0]
250 spectra = self.dataOut.data_pre[0]
251 cspectra = self.dataOut.data_pre[1]
251 cspectra = self.dataOut.data_pre[1]
252 delta_v = vel[1] - vel[0]
252 delta_v = vel[1] - vel[0]
253
253
254 #Calculating the power spectrum
254 #Calculating the power spectrum
255 spc_pow = numpy.sum(spectra, 3)*delta_v
255 spc_pow = numpy.sum(spectra, 3)*delta_v
256 #Normalizing Spectra
256 #Normalizing Spectra
257 norm_spectra = spectra/spc_pow
257 norm_spectra = spectra/spc_pow
258 #Calculating the norm_spectra at peak
258 #Calculating the norm_spectra at peak
259 max_spectra = numpy.max(norm_spectra, 3)
259 max_spectra = numpy.max(norm_spectra, 3)
260
260
261 #Normalizing Cross Spectra
261 #Normalizing Cross Spectra
262 norm_cspectra = numpy.zeros(cspectra.shape)
262 norm_cspectra = numpy.zeros(cspectra.shape)
263
263
264 for i in range(num_chan):
264 for i in range(num_chan):
265 norm_cspectra[i,:,:] = cspectra[i,:,:]/numpy.sqrt(spc_pow[pairslist[i][0],:]*spc_pow[pairslist[i][1],:])
265 norm_cspectra[i,:,:] = cspectra[i,:,:]/numpy.sqrt(spc_pow[pairslist[i][0],:]*spc_pow[pairslist[i][1],:])
266
266
267 max_cspectra = numpy.max(norm_cspectra,2)
267 max_cspectra = numpy.max(norm_cspectra,2)
268 max_cspectra_index = numpy.argmax(norm_cspectra, 2)
268 max_cspectra_index = numpy.argmax(norm_cspectra, 2)
269
269
270 for i in range(num_pairs):
270 for i in range(num_pairs):
271 cspc_par[i,:,:] = __calculateMoments(norm_cspectra)
271 cspc_par[i,:,:] = __calculateMoments(norm_cspectra)
272 #------------------- Get Lags ----------------------------------
272 #------------------- Get Lags ----------------------------------
273
273
274 class SALags(Operation):
274 class SALags(Operation):
275 '''
275 '''
276 Function GetMoments()
276 Function GetMoments()
277
277
278 Input:
278 Input:
279 self.dataOut.data_pre
279 self.dataOut.data_pre
280 self.dataOut.abscissaList
280 self.dataOut.abscissaList
281 self.dataOut.noise
281 self.dataOut.noise
282 self.dataOut.normFactor
282 self.dataOut.normFactor
283 self.dataOut.data_SNR
283 self.dataOut.data_SNR
284 self.dataOut.groupList
284 self.dataOut.groupList
285 self.dataOut.nChannels
285 self.dataOut.nChannels
286
286
287 Affected:
287 Affected:
288 self.dataOut.data_param
288 self.dataOut.data_param
289
289
290 '''
290 '''
291 def run(self, dataOut):
291 def run(self, dataOut):
292 data_acf = dataOut.data_pre[0]
292 data_acf = dataOut.data_pre[0]
293 data_ccf = dataOut.data_pre[1]
293 data_ccf = dataOut.data_pre[1]
294 normFactor_acf = dataOut.normFactor[0]
294 normFactor_acf = dataOut.normFactor[0]
295 normFactor_ccf = dataOut.normFactor[1]
295 normFactor_ccf = dataOut.normFactor[1]
296 pairs_acf = dataOut.groupList[0]
296 pairs_acf = dataOut.groupList[0]
297 pairs_ccf = dataOut.groupList[1]
297 pairs_ccf = dataOut.groupList[1]
298
298
299 nHeights = dataOut.nHeights
299 nHeights = dataOut.nHeights
300 absc = dataOut.abscissaList
300 absc = dataOut.abscissaList
301 noise = dataOut.noise
301 noise = dataOut.noise
302 SNR = dataOut.data_SNR
302 SNR = dataOut.data_SNR
303 nChannels = dataOut.nChannels
303 nChannels = dataOut.nChannels
304 # pairsList = dataOut.groupList
304 # pairsList = dataOut.groupList
305 # pairsAutoCorr, pairsCrossCorr = self.__getPairsAutoCorr(pairsList, nChannels)
305 # pairsAutoCorr, pairsCrossCorr = self.__getPairsAutoCorr(pairsList, nChannels)
306
306
307 for l in range(len(pairs_acf)):
307 for l in range(len(pairs_acf)):
308 data_acf[l,:,:] = data_acf[l,:,:]/normFactor_acf[l,:]
308 data_acf[l,:,:] = data_acf[l,:,:]/normFactor_acf[l,:]
309
309
310 for l in range(len(pairs_ccf)):
310 for l in range(len(pairs_ccf)):
311 data_ccf[l,:,:] = data_ccf[l,:,:]/normFactor_ccf[l,:]
311 data_ccf[l,:,:] = data_ccf[l,:,:]/normFactor_ccf[l,:]
312
312
313 dataOut.data_param = numpy.zeros((len(pairs_ccf)*2 + 1, nHeights))
313 dataOut.data_param = numpy.zeros((len(pairs_ccf)*2 + 1, nHeights))
314 dataOut.data_param[:-1,:] = self.__calculateTaus(data_acf, data_ccf, absc)
314 dataOut.data_param[:-1,:] = self.__calculateTaus(data_acf, data_ccf, absc)
315 dataOut.data_param[-1,:] = self.__calculateLag1Phase(data_acf, absc)
315 dataOut.data_param[-1,:] = self.__calculateLag1Phase(data_acf, absc)
316 return
316 return
317
317
318 # def __getPairsAutoCorr(self, pairsList, nChannels):
318 # def __getPairsAutoCorr(self, pairsList, nChannels):
319 #
319 #
320 # pairsAutoCorr = numpy.zeros(nChannels, dtype = 'int')*numpy.nan
320 # pairsAutoCorr = numpy.zeros(nChannels, dtype = 'int')*numpy.nan
321 #
321 #
322 # for l in range(len(pairsList)):
322 # for l in range(len(pairsList)):
323 # firstChannel = pairsList[l][0]
323 # firstChannel = pairsList[l][0]
324 # secondChannel = pairsList[l][1]
324 # secondChannel = pairsList[l][1]
325 #
325 #
326 # #Obteniendo pares de Autocorrelacion
326 # #Obteniendo pares de Autocorrelacion
327 # if firstChannel == secondChannel:
327 # if firstChannel == secondChannel:
328 # pairsAutoCorr[firstChannel] = int(l)
328 # pairsAutoCorr[firstChannel] = int(l)
329 #
329 #
330 # pairsAutoCorr = pairsAutoCorr.astype(int)
330 # pairsAutoCorr = pairsAutoCorr.astype(int)
331 #
331 #
332 # pairsCrossCorr = range(len(pairsList))
332 # pairsCrossCorr = range(len(pairsList))
333 # pairsCrossCorr = numpy.delete(pairsCrossCorr,pairsAutoCorr)
333 # pairsCrossCorr = numpy.delete(pairsCrossCorr,pairsAutoCorr)
334 #
334 #
335 # return pairsAutoCorr, pairsCrossCorr
335 # return pairsAutoCorr, pairsCrossCorr
336
336
337 def __calculateTaus(self, data_acf, data_ccf, lagRange):
337 def __calculateTaus(self, data_acf, data_ccf, lagRange):
338
338
339 lag0 = data_acf.shape[1]/2
339 lag0 = data_acf.shape[1]/2
340 #Funcion de Autocorrelacion
340 #Funcion de Autocorrelacion
341 mean_acf = stats.nanmean(data_acf, axis = 0)
341 mean_acf = stats.nanmean(data_acf, axis = 0)
342
342
343 #Obtencion Indice de TauCross
343 #Obtencion Indice de TauCross
344 ind_ccf = data_ccf.argmax(axis = 1)
344 ind_ccf = data_ccf.argmax(axis = 1)
345 #Obtencion Indice de TauAuto
345 #Obtencion Indice de TauAuto
346 ind_acf = numpy.zeros(ind_ccf.shape,dtype = 'int')
346 ind_acf = numpy.zeros(ind_ccf.shape,dtype = 'int')
347 ccf_lag0 = data_ccf[:,lag0,:]
347 ccf_lag0 = data_ccf[:,lag0,:]
348
348
349 for i in range(ccf_lag0.shape[0]):
349 for i in range(ccf_lag0.shape[0]):
350 ind_acf[i,:] = numpy.abs(mean_acf - ccf_lag0[i,:]).argmin(axis = 0)
350 ind_acf[i,:] = numpy.abs(mean_acf - ccf_lag0[i,:]).argmin(axis = 0)
351
351
352 #Obtencion de TauCross y TauAuto
352 #Obtencion de TauCross y TauAuto
353 tau_ccf = lagRange[ind_ccf]
353 tau_ccf = lagRange[ind_ccf]
354 tau_acf = lagRange[ind_acf]
354 tau_acf = lagRange[ind_acf]
355
355
356 Nan1, Nan2 = numpy.where(tau_ccf == lagRange[0])
356 Nan1, Nan2 = numpy.where(tau_ccf == lagRange[0])
357
357
358 tau_ccf[Nan1,Nan2] = numpy.nan
358 tau_ccf[Nan1,Nan2] = numpy.nan
359 tau_acf[Nan1,Nan2] = numpy.nan
359 tau_acf[Nan1,Nan2] = numpy.nan
360 tau = numpy.vstack((tau_ccf,tau_acf))
360 tau = numpy.vstack((tau_ccf,tau_acf))
361
361
362 return tau
362 return tau
363
363
364 def __calculateLag1Phase(self, data, lagTRange):
364 def __calculateLag1Phase(self, data, lagTRange):
365 data1 = stats.nanmean(data, axis = 0)
365 data1 = stats.nanmean(data, axis = 0)
366 lag1 = numpy.where(lagTRange == 0)[0][0] + 1
366 lag1 = numpy.where(lagTRange == 0)[0][0] + 1
367
367
368 phase = numpy.angle(data1[lag1,:])
368 phase = numpy.angle(data1[lag1,:])
369
369
370 return phase
370 return phase
371
371
372 class SpectralFitting(Operation):
372 class SpectralFitting(Operation):
373 '''
373 '''
374 Function GetMoments()
374 Function GetMoments()
375
375
376 Input:
376 Input:
377 Output:
377 Output:
378 Variables modified:
378 Variables modified:
379 '''
379 '''
380
380
381 def run(self, dataOut, getSNR = True, path=None, file=None, groupList=None):
381 def run(self, dataOut, getSNR = True, path=None, file=None, groupList=None):
382
382
383
383
384 if path != None:
384 if path != None:
385 sys.path.append(path)
385 sys.path.append(path)
386 self.dataOut.library = importlib.import_module(file)
386 self.dataOut.library = importlib.import_module(file)
387
387
388 #To be inserted as a parameter
388 #To be inserted as a parameter
389 groupArray = numpy.array(groupList)
389 groupArray = numpy.array(groupList)
390 # groupArray = numpy.array([[0,1],[2,3]])
390 # groupArray = numpy.array([[0,1],[2,3]])
391 self.dataOut.groupList = groupArray
391 self.dataOut.groupList = groupArray
392
392
393 nGroups = groupArray.shape[0]
393 nGroups = groupArray.shape[0]
394 nChannels = self.dataIn.nChannels
394 nChannels = self.dataIn.nChannels
395 nHeights=self.dataIn.heightList.size
395 nHeights=self.dataIn.heightList.size
396
396
397 #Parameters Array
397 #Parameters Array
398 self.dataOut.data_param = None
398 self.dataOut.data_param = None
399
399
400 #Set constants
400 #Set constants
401 constants = self.dataOut.library.setConstants(self.dataIn)
401 constants = self.dataOut.library.setConstants(self.dataIn)
402 self.dataOut.constants = constants
402 self.dataOut.constants = constants
403 M = self.dataIn.normFactor
403 M = self.dataIn.normFactor
404 N = self.dataIn.nFFTPoints
404 N = self.dataIn.nFFTPoints
405 ippSeconds = self.dataIn.ippSeconds
405 ippSeconds = self.dataIn.ippSeconds
406 K = self.dataIn.nIncohInt
406 K = self.dataIn.nIncohInt
407 pairsArray = numpy.array(self.dataIn.pairsList)
407 pairsArray = numpy.array(self.dataIn.pairsList)
408
408
409 #List of possible combinations
409 #List of possible combinations
410 listComb = itertools.combinations(numpy.arange(groupArray.shape[1]),2)
410 listComb = itertools.combinations(numpy.arange(groupArray.shape[1]),2)
411 indCross = numpy.zeros(len(list(listComb)), dtype = 'int')
411 indCross = numpy.zeros(len(list(listComb)), dtype = 'int')
412
412
413 if getSNR:
413 if getSNR:
414 listChannels = groupArray.reshape((groupArray.size))
414 listChannels = groupArray.reshape((groupArray.size))
415 listChannels.sort()
415 listChannels.sort()
416 noise = self.dataIn.getNoise()
416 noise = self.dataIn.getNoise()
417 self.dataOut.data_SNR = self.__getSNR(self.dataIn.data_spc[listChannels,:,:], noise[listChannels])
417 self.dataOut.data_SNR = self.__getSNR(self.dataIn.data_spc[listChannels,:,:], noise[listChannels])
418
418
419 for i in range(nGroups):
419 for i in range(nGroups):
420 coord = groupArray[i,:]
420 coord = groupArray[i,:]
421
421
422 #Input data array
422 #Input data array
423 data = self.dataIn.data_spc[coord,:,:]/(M*N)
423 data = self.dataIn.data_spc[coord,:,:]/(M*N)
424 data = data.reshape((data.shape[0]*data.shape[1],data.shape[2]))
424 data = data.reshape((data.shape[0]*data.shape[1],data.shape[2]))
425
425
426 #Cross Spectra data array for Covariance Matrixes
426 #Cross Spectra data array for Covariance Matrixes
427 ind = 0
427 ind = 0
428 for pairs in listComb:
428 for pairs in listComb:
429 pairsSel = numpy.array([coord[x],coord[y]])
429 pairsSel = numpy.array([coord[x],coord[y]])
430 indCross[ind] = int(numpy.where(numpy.all(pairsArray == pairsSel, axis = 1))[0][0])
430 indCross[ind] = int(numpy.where(numpy.all(pairsArray == pairsSel, axis = 1))[0][0])
431 ind += 1
431 ind += 1
432 dataCross = self.dataIn.data_cspc[indCross,:,:]/(M*N)
432 dataCross = self.dataIn.data_cspc[indCross,:,:]/(M*N)
433 dataCross = dataCross**2/K
433 dataCross = dataCross**2/K
434
434
435 for h in range(nHeights):
435 for h in range(nHeights):
436 # print self.dataOut.heightList[h]
436 # print self.dataOut.heightList[h]
437
437
438 #Input
438 #Input
439 d = data[:,h]
439 d = data[:,h]
440
440
441 #Covariance Matrix
441 #Covariance Matrix
442 D = numpy.diag(d**2/K)
442 D = numpy.diag(d**2/K)
443 ind = 0
443 ind = 0
444 for pairs in listComb:
444 for pairs in listComb:
445 #Coordinates in Covariance Matrix
445 #Coordinates in Covariance Matrix
446 x = pairs[0]
446 x = pairs[0]
447 y = pairs[1]
447 y = pairs[1]
448 #Channel Index
448 #Channel Index
449 S12 = dataCross[ind,:,h]
449 S12 = dataCross[ind,:,h]
450 D12 = numpy.diag(S12)
450 D12 = numpy.diag(S12)
451 #Completing Covariance Matrix with Cross Spectras
451 #Completing Covariance Matrix with Cross Spectras
452 D[x*N:(x+1)*N,y*N:(y+1)*N] = D12
452 D[x*N:(x+1)*N,y*N:(y+1)*N] = D12
453 D[y*N:(y+1)*N,x*N:(x+1)*N] = D12
453 D[y*N:(y+1)*N,x*N:(x+1)*N] = D12
454 ind += 1
454 ind += 1
455 Dinv=numpy.linalg.inv(D)
455 Dinv=numpy.linalg.inv(D)
456 L=numpy.linalg.cholesky(Dinv)
456 L=numpy.linalg.cholesky(Dinv)
457 LT=L.T
457 LT=L.T
458
458
459 dp = numpy.dot(LT,d)
459 dp = numpy.dot(LT,d)
460
460
461 #Initial values
461 #Initial values
462 data_spc = self.dataIn.data_spc[coord,:,h]
462 data_spc = self.dataIn.data_spc[coord,:,h]
463
463
464 if (h>0)and(error1[3]<5):
464 if (h>0)and(error1[3]<5):
465 p0 = self.dataOut.data_param[i,:,h-1]
465 p0 = self.dataOut.data_param[i,:,h-1]
466 else:
466 else:
467 p0 = numpy.array(self.dataOut.library.initialValuesFunction(data_spc, constants, i))
467 p0 = numpy.array(self.dataOut.library.initialValuesFunction(data_spc, constants, i))
468
468
469 try:
469 try:
470 #Least Squares
470 #Least Squares
471 minp,covp,infodict,mesg,ier = optimize.leastsq(self.__residFunction,p0,args=(dp,LT,constants),full_output=True)
471 minp,covp,infodict,mesg,ier = optimize.leastsq(self.__residFunction,p0,args=(dp,LT,constants),full_output=True)
472 # minp,covp = optimize.leastsq(self.__residFunction,p0,args=(dp,LT,constants))
472 # minp,covp = optimize.leastsq(self.__residFunction,p0,args=(dp,LT,constants))
473 #Chi square error
473 #Chi square error
474 error0 = numpy.sum(infodict['fvec']**2)/(2*N)
474 error0 = numpy.sum(infodict['fvec']**2)/(2*N)
475 #Error with Jacobian
475 #Error with Jacobian
476 error1 = self.dataOut.library.errorFunction(minp,constants,LT)
476 error1 = self.dataOut.library.errorFunction(minp,constants,LT)
477 except:
477 except:
478 minp = p0*numpy.nan
478 minp = p0*numpy.nan
479 error0 = numpy.nan
479 error0 = numpy.nan
480 error1 = p0*numpy.nan
480 error1 = p0*numpy.nan
481
481
482 #Save
482 #Save
483 if self.dataOut.data_param is None:
483 if self.dataOut.data_param is None:
484 self.dataOut.data_param = numpy.zeros((nGroups, p0.size, nHeights))*numpy.nan
484 self.dataOut.data_param = numpy.zeros((nGroups, p0.size, nHeights))*numpy.nan
485 self.dataOut.data_error = numpy.zeros((nGroups, p0.size + 1, nHeights))*numpy.nan
485 self.dataOut.data_error = numpy.zeros((nGroups, p0.size + 1, nHeights))*numpy.nan
486
486
487 self.dataOut.data_error[i,:,h] = numpy.hstack((error0,error1))
487 self.dataOut.data_error[i,:,h] = numpy.hstack((error0,error1))
488 self.dataOut.data_param[i,:,h] = minp
488 self.dataOut.data_param[i,:,h] = minp
489 return
489 return
490
490
491 def __residFunction(self, p, dp, LT, constants):
491 def __residFunction(self, p, dp, LT, constants):
492
492
493 fm = self.dataOut.library.modelFunction(p, constants)
493 fm = self.dataOut.library.modelFunction(p, constants)
494 fmp=numpy.dot(LT,fm)
494 fmp=numpy.dot(LT,fm)
495
495
496 return dp-fmp
496 return dp-fmp
497
497
498 def __getSNR(self, z, noise):
498 def __getSNR(self, z, noise):
499
499
500 avg = numpy.average(z, axis=1)
500 avg = numpy.average(z, axis=1)
501 SNR = (avg.T-noise)/noise
501 SNR = (avg.T-noise)/noise
502 SNR = SNR.T
502 SNR = SNR.T
503 return SNR
503 return SNR
504
504
505 def __chisq(p,chindex,hindex):
505 def __chisq(p,chindex,hindex):
506 #similar to Resid but calculates CHI**2
506 #similar to Resid but calculates CHI**2
507 [LT,d,fm]=setupLTdfm(p,chindex,hindex)
507 [LT,d,fm]=setupLTdfm(p,chindex,hindex)
508 dp=numpy.dot(LT,d)
508 dp=numpy.dot(LT,d)
509 fmp=numpy.dot(LT,fm)
509 fmp=numpy.dot(LT,fm)
510 chisq=numpy.dot((dp-fmp).T,(dp-fmp))
510 chisq=numpy.dot((dp-fmp).T,(dp-fmp))
511 return chisq
511 return chisq
512
512
513 class WindProfiler(Operation):
513 class WindProfiler(Operation):
514
514
515 __isConfig = False
515 __isConfig = False
516
516
517 __initime = None
517 __initime = None
518 __lastdatatime = None
518 __lastdatatime = None
519 __integrationtime = None
519 __integrationtime = None
520
520
521 __buffer = None
521 __buffer = None
522
522
523 __dataReady = False
523 __dataReady = False
524
524
525 __firstdata = None
525 __firstdata = None
526
526
527 n = None
527 n = None
528
528
529 def __calculateCosDir(self, elev, azim):
529 def __calculateCosDir(self, elev, azim):
530 zen = (90 - elev)*numpy.pi/180
530 zen = (90 - elev)*numpy.pi/180
531 azim = azim*numpy.pi/180
531 azim = azim*numpy.pi/180
532 cosDirX = numpy.sqrt((1-numpy.cos(zen)**2)/((1+numpy.tan(azim)**2)))
532 cosDirX = numpy.sqrt((1-numpy.cos(zen)**2)/((1+numpy.tan(azim)**2)))
533 cosDirY = numpy.sqrt(1-numpy.cos(zen)**2-cosDirX**2)
533 cosDirY = numpy.sqrt(1-numpy.cos(zen)**2-cosDirX**2)
534
534
535 signX = numpy.sign(numpy.cos(azim))
535 signX = numpy.sign(numpy.cos(azim))
536 signY = numpy.sign(numpy.sin(azim))
536 signY = numpy.sign(numpy.sin(azim))
537
537
538 cosDirX = numpy.copysign(cosDirX, signX)
538 cosDirX = numpy.copysign(cosDirX, signX)
539 cosDirY = numpy.copysign(cosDirY, signY)
539 cosDirY = numpy.copysign(cosDirY, signY)
540 return cosDirX, cosDirY
540 return cosDirX, cosDirY
541
541
542 def __calculateAngles(self, theta_x, theta_y, azimuth):
542 def __calculateAngles(self, theta_x, theta_y, azimuth):
543
543
544 dir_cosw = numpy.sqrt(1-theta_x**2-theta_y**2)
544 dir_cosw = numpy.sqrt(1-theta_x**2-theta_y**2)
545 zenith_arr = numpy.arccos(dir_cosw)
545 zenith_arr = numpy.arccos(dir_cosw)
546 azimuth_arr = numpy.arctan2(theta_x,theta_y) + azimuth*math.pi/180
546 azimuth_arr = numpy.arctan2(theta_x,theta_y) + azimuth*math.pi/180
547
547
548 dir_cosu = numpy.sin(azimuth_arr)*numpy.sin(zenith_arr)
548 dir_cosu = numpy.sin(azimuth_arr)*numpy.sin(zenith_arr)
549 dir_cosv = numpy.cos(azimuth_arr)*numpy.sin(zenith_arr)
549 dir_cosv = numpy.cos(azimuth_arr)*numpy.sin(zenith_arr)
550
550
551 return azimuth_arr, zenith_arr, dir_cosu, dir_cosv, dir_cosw
551 return azimuth_arr, zenith_arr, dir_cosu, dir_cosv, dir_cosw
552
552
553 def __calculateMatA(self, dir_cosu, dir_cosv, dir_cosw, horOnly):
553 def __calculateMatA(self, dir_cosu, dir_cosv, dir_cosw, horOnly):
554
554
555 #
555 #
556 if horOnly:
556 if horOnly:
557 A = numpy.c_[dir_cosu,dir_cosv]
557 A = numpy.c_[dir_cosu,dir_cosv]
558 else:
558 else:
559 A = numpy.c_[dir_cosu,dir_cosv,dir_cosw]
559 A = numpy.c_[dir_cosu,dir_cosv,dir_cosw]
560 A = numpy.asmatrix(A)
560 A = numpy.asmatrix(A)
561 A1 = numpy.linalg.inv(A.transpose()*A)*A.transpose()
561 A1 = numpy.linalg.inv(A.transpose()*A)*A.transpose()
562
562
563 return A1
563 return A1
564
564
565 def __correctValues(self, heiRang, phi, velRadial, SNR):
565 def __correctValues(self, heiRang, phi, velRadial, SNR):
566 listPhi = phi.tolist()
566 listPhi = phi.tolist()
567 maxid = listPhi.index(max(listPhi))
567 maxid = listPhi.index(max(listPhi))
568 minid = listPhi.index(min(listPhi))
568 minid = listPhi.index(min(listPhi))
569
569
570 rango = range(len(phi))
570 rango = range(len(phi))
571 # rango = numpy.delete(rango,maxid)
571 # rango = numpy.delete(rango,maxid)
572
572
573 heiRang1 = heiRang*math.cos(phi[maxid])
573 heiRang1 = heiRang*math.cos(phi[maxid])
574 heiRangAux = heiRang*math.cos(phi[minid])
574 heiRangAux = heiRang*math.cos(phi[minid])
575 indOut = (heiRang1 < heiRangAux[0]).nonzero()
575 indOut = (heiRang1 < heiRangAux[0]).nonzero()
576 heiRang1 = numpy.delete(heiRang1,indOut)
576 heiRang1 = numpy.delete(heiRang1,indOut)
577
577
578 velRadial1 = numpy.zeros([len(phi),len(heiRang1)])
578 velRadial1 = numpy.zeros([len(phi),len(heiRang1)])
579 SNR1 = numpy.zeros([len(phi),len(heiRang1)])
579 SNR1 = numpy.zeros([len(phi),len(heiRang1)])
580
580
581 for i in rango:
581 for i in rango:
582 x = heiRang*math.cos(phi[i])
582 x = heiRang*math.cos(phi[i])
583 y1 = velRadial[i,:]
583 y1 = velRadial[i,:]
584 f1 = interpolate.interp1d(x,y1,kind = 'cubic')
584 f1 = interpolate.interp1d(x,y1,kind = 'cubic')
585
585
586 x1 = heiRang1
586 x1 = heiRang1
587 y11 = f1(x1)
587 y11 = f1(x1)
588
588
589 y2 = SNR[i,:]
589 y2 = SNR[i,:]
590 f2 = interpolate.interp1d(x,y2,kind = 'cubic')
590 f2 = interpolate.interp1d(x,y2,kind = 'cubic')
591 y21 = f2(x1)
591 y21 = f2(x1)
592
592
593 velRadial1[i,:] = y11
593 velRadial1[i,:] = y11
594 SNR1[i,:] = y21
594 SNR1[i,:] = y21
595
595
596 return heiRang1, velRadial1, SNR1
596 return heiRang1, velRadial1, SNR1
597
597
598 def __calculateVelUVW(self, A, velRadial):
598 def __calculateVelUVW(self, A, velRadial):
599
599
600 #Operacion Matricial
600 #Operacion Matricial
601 # velUVW = numpy.zeros((velRadial.shape[1],3))
601 # velUVW = numpy.zeros((velRadial.shape[1],3))
602 # for ind in range(velRadial.shape[1]):
602 # for ind in range(velRadial.shape[1]):
603 # velUVW[ind,:] = numpy.dot(A,velRadial[:,ind])
603 # velUVW[ind,:] = numpy.dot(A,velRadial[:,ind])
604 # velUVW = velUVW.transpose()
604 # velUVW = velUVW.transpose()
605 velUVW = numpy.zeros((A.shape[0],velRadial.shape[1]))
605 velUVW = numpy.zeros((A.shape[0],velRadial.shape[1]))
606 velUVW[:,:] = numpy.dot(A,velRadial)
606 velUVW[:,:] = numpy.dot(A,velRadial)
607
607
608
608
609 return velUVW
609 return velUVW
610
610
611 # def techniqueDBS(self, velRadial0, dirCosx, disrCosy, azimuth, correct, horizontalOnly, heiRang, SNR0):
611 # def techniqueDBS(self, velRadial0, dirCosx, disrCosy, azimuth, correct, horizontalOnly, heiRang, SNR0):
612
612
613 def techniqueDBS(self, kwargs):
613 def techniqueDBS(self, kwargs):
614 """
614 """
615 Function that implements Doppler Beam Swinging (DBS) technique.
615 Function that implements Doppler Beam Swinging (DBS) technique.
616
616
617 Input: Radial velocities, Direction cosines (x and y) of the Beam, Antenna azimuth,
617 Input: Radial velocities, Direction cosines (x and y) of the Beam, Antenna azimuth,
618 Direction correction (if necessary), Ranges and SNR
618 Direction correction (if necessary), Ranges and SNR
619
619
620 Output: Winds estimation (Zonal, Meridional and Vertical)
620 Output: Winds estimation (Zonal, Meridional and Vertical)
621
621
622 Parameters affected: Winds, height range, SNR
622 Parameters affected: Winds, height range, SNR
623 """
623 """
624 velRadial0 = kwargs['velRadial']
624 velRadial0 = kwargs['velRadial']
625 heiRang = kwargs['heightList']
625 heiRang = kwargs['heightList']
626 SNR0 = kwargs['SNR']
626 SNR0 = kwargs['SNR']
627
627
628 if kwargs.has_key('dirCosx') and kwargs.has_key('dirCosy'):
628 if kwargs.has_key('dirCosx') and kwargs.has_key('dirCosy'):
629 theta_x = numpy.array(kwargs['dirCosx'])
629 theta_x = numpy.array(kwargs['dirCosx'])
630 theta_y = numpy.array(kwargs['dirCosy'])
630 theta_y = numpy.array(kwargs['dirCosy'])
631 else:
631 else:
632 elev = numpy.array(kwargs['elevation'])
632 elev = numpy.array(kwargs['elevation'])
633 azim = numpy.array(kwargs['azimuth'])
633 azim = numpy.array(kwargs['azimuth'])
634 theta_x, theta_y = self.__calculateCosDir(elev, azim)
634 theta_x, theta_y = self.__calculateCosDir(elev, azim)
635 azimuth = kwargs['correctAzimuth']
635 azimuth = kwargs['correctAzimuth']
636 if kwargs.has_key('horizontalOnly'):
636 if kwargs.has_key('horizontalOnly'):
637 horizontalOnly = kwargs['horizontalOnly']
637 horizontalOnly = kwargs['horizontalOnly']
638 else: horizontalOnly = False
638 else: horizontalOnly = False
639 if kwargs.has_key('correctFactor'):
639 if kwargs.has_key('correctFactor'):
640 correctFactor = kwargs['correctFactor']
640 correctFactor = kwargs['correctFactor']
641 else: correctFactor = 1
641 else: correctFactor = 1
642 if kwargs.has_key('channelList'):
642 if kwargs.has_key('channelList'):
643 channelList = kwargs['channelList']
643 channelList = kwargs['channelList']
644 if len(channelList) == 2:
644 if len(channelList) == 2:
645 horizontalOnly = True
645 horizontalOnly = True
646 arrayChannel = numpy.array(channelList)
646 arrayChannel = numpy.array(channelList)
647 param = param[arrayChannel,:,:]
647 param = param[arrayChannel,:,:]
648 theta_x = theta_x[arrayChannel]
648 theta_x = theta_x[arrayChannel]
649 theta_y = theta_y[arrayChannel]
649 theta_y = theta_y[arrayChannel]
650
650
651 azimuth_arr, zenith_arr, dir_cosu, dir_cosv, dir_cosw = self.__calculateAngles(theta_x, theta_y, azimuth)
651 azimuth_arr, zenith_arr, dir_cosu, dir_cosv, dir_cosw = self.__calculateAngles(theta_x, theta_y, azimuth)
652 heiRang1, velRadial1, SNR1 = self.__correctValues(heiRang, zenith_arr, correctFactor*velRadial0, SNR0)
652 heiRang1, velRadial1, SNR1 = self.__correctValues(heiRang, zenith_arr, correctFactor*velRadial0, SNR0)
653 A = self.__calculateMatA(dir_cosu, dir_cosv, dir_cosw, horizontalOnly)
653 A = self.__calculateMatA(dir_cosu, dir_cosv, dir_cosw, horizontalOnly)
654
654
655 #Calculo de Componentes de la velocidad con DBS
655 #Calculo de Componentes de la velocidad con DBS
656 winds = self.__calculateVelUVW(A,velRadial1)
656 winds = self.__calculateVelUVW(A,velRadial1)
657
657
658 return winds, heiRang1, SNR1
658 return winds, heiRang1, SNR1
659
659
660 def __calculateDistance(self, posx, posy, pairs_ccf, azimuth = None):
660 def __calculateDistance(self, posx, posy, pairs_ccf, azimuth = None):
661
661
662 nPairs = len(pairs_ccf)
662 nPairs = len(pairs_ccf)
663 posx = numpy.asarray(posx)
663 posx = numpy.asarray(posx)
664 posy = numpy.asarray(posy)
664 posy = numpy.asarray(posy)
665
665
666 #Rotacion Inversa para alinear con el azimuth
666 #Rotacion Inversa para alinear con el azimuth
667 if azimuth!= None:
667 if azimuth!= None:
668 azimuth = azimuth*math.pi/180
668 azimuth = azimuth*math.pi/180
669 posx1 = posx*math.cos(azimuth) + posy*math.sin(azimuth)
669 posx1 = posx*math.cos(azimuth) + posy*math.sin(azimuth)
670 posy1 = -posx*math.sin(azimuth) + posy*math.cos(azimuth)
670 posy1 = -posx*math.sin(azimuth) + posy*math.cos(azimuth)
671 else:
671 else:
672 posx1 = posx
672 posx1 = posx
673 posy1 = posy
673 posy1 = posy
674
674
675 #Calculo de Distancias
675 #Calculo de Distancias
676 distx = numpy.zeros(nPairs)
676 distx = numpy.zeros(nPairs)
677 disty = numpy.zeros(nPairs)
677 disty = numpy.zeros(nPairs)
678 dist = numpy.zeros(nPairs)
678 dist = numpy.zeros(nPairs)
679 ang = numpy.zeros(nPairs)
679 ang = numpy.zeros(nPairs)
680
680
681 for i in range(nPairs):
681 for i in range(nPairs):
682 distx[i] = posx1[pairs_ccf[i][1]] - posx1[pairs_ccf[i][0]]
682 distx[i] = posx1[pairs_ccf[i][1]] - posx1[pairs_ccf[i][0]]
683 disty[i] = posy1[pairs_ccf[i][1]] - posy1[pairs_ccf[i][0]]
683 disty[i] = posy1[pairs_ccf[i][1]] - posy1[pairs_ccf[i][0]]
684 dist[i] = numpy.sqrt(distx[i]**2 + disty[i]**2)
684 dist[i] = numpy.sqrt(distx[i]**2 + disty[i]**2)
685 ang[i] = numpy.arctan2(disty[i],distx[i])
685 ang[i] = numpy.arctan2(disty[i],distx[i])
686
686
687 return distx, disty, dist, ang
687 return distx, disty, dist, ang
688 #Calculo de Matrices
688 #Calculo de Matrices
689 # nPairs = len(pairs)
689 # nPairs = len(pairs)
690 # ang1 = numpy.zeros((nPairs, 2, 1))
690 # ang1 = numpy.zeros((nPairs, 2, 1))
691 # dist1 = numpy.zeros((nPairs, 2, 1))
691 # dist1 = numpy.zeros((nPairs, 2, 1))
692 #
692 #
693 # for j in range(nPairs):
693 # for j in range(nPairs):
694 # dist1[j,0,0] = dist[pairs[j][0]]
694 # dist1[j,0,0] = dist[pairs[j][0]]
695 # dist1[j,1,0] = dist[pairs[j][1]]
695 # dist1[j,1,0] = dist[pairs[j][1]]
696 # ang1[j,0,0] = ang[pairs[j][0]]
696 # ang1[j,0,0] = ang[pairs[j][0]]
697 # ang1[j,1,0] = ang[pairs[j][1]]
697 # ang1[j,1,0] = ang[pairs[j][1]]
698 #
698 #
699 # return distx,disty, dist1,ang1
699 # return distx,disty, dist1,ang1
700
700
701
701
702 def __calculateVelVer(self, phase, lagTRange, _lambda):
702 def __calculateVelVer(self, phase, lagTRange, _lambda):
703
703
704 Ts = lagTRange[1] - lagTRange[0]
704 Ts = lagTRange[1] - lagTRange[0]
705 velW = -_lambda*phase/(4*math.pi*Ts)
705 velW = -_lambda*phase/(4*math.pi*Ts)
706
706
707 return velW
707 return velW
708
708
709 def __calculateVelHorDir(self, dist, tau1, tau2, ang):
709 def __calculateVelHorDir(self, dist, tau1, tau2, ang):
710 nPairs = tau1.shape[0]
710 nPairs = tau1.shape[0]
711 nHeights = tau1.shape[1]
711 nHeights = tau1.shape[1]
712 vel = numpy.zeros((nPairs,3,nHeights))
712 vel = numpy.zeros((nPairs,3,nHeights))
713 dist1 = numpy.reshape(dist, (dist.size,1))
713 dist1 = numpy.reshape(dist, (dist.size,1))
714
714
715 angCos = numpy.cos(ang)
715 angCos = numpy.cos(ang)
716 angSin = numpy.sin(ang)
716 angSin = numpy.sin(ang)
717
717
718 vel0 = dist1*tau1/(2*tau2**2)
718 vel0 = dist1*tau1/(2*tau2**2)
719 vel[:,0,:] = (vel0*angCos).sum(axis = 1)
719 vel[:,0,:] = (vel0*angCos).sum(axis = 1)
720 vel[:,1,:] = (vel0*angSin).sum(axis = 1)
720 vel[:,1,:] = (vel0*angSin).sum(axis = 1)
721
721
722 ind = numpy.where(numpy.isinf(vel))
722 ind = numpy.where(numpy.isinf(vel))
723 vel[ind] = numpy.nan
723 vel[ind] = numpy.nan
724
724
725 return vel
725 return vel
726
726
727 # def __getPairsAutoCorr(self, pairsList, nChannels):
727 # def __getPairsAutoCorr(self, pairsList, nChannels):
728 #
728 #
729 # pairsAutoCorr = numpy.zeros(nChannels, dtype = 'int')*numpy.nan
729 # pairsAutoCorr = numpy.zeros(nChannels, dtype = 'int')*numpy.nan
730 #
730 #
731 # for l in range(len(pairsList)):
731 # for l in range(len(pairsList)):
732 # firstChannel = pairsList[l][0]
732 # firstChannel = pairsList[l][0]
733 # secondChannel = pairsList[l][1]
733 # secondChannel = pairsList[l][1]
734 #
734 #
735 # #Obteniendo pares de Autocorrelacion
735 # #Obteniendo pares de Autocorrelacion
736 # if firstChannel == secondChannel:
736 # if firstChannel == secondChannel:
737 # pairsAutoCorr[firstChannel] = int(l)
737 # pairsAutoCorr[firstChannel] = int(l)
738 #
738 #
739 # pairsAutoCorr = pairsAutoCorr.astype(int)
739 # pairsAutoCorr = pairsAutoCorr.astype(int)
740 #
740 #
741 # pairsCrossCorr = range(len(pairsList))
741 # pairsCrossCorr = range(len(pairsList))
742 # pairsCrossCorr = numpy.delete(pairsCrossCorr,pairsAutoCorr)
742 # pairsCrossCorr = numpy.delete(pairsCrossCorr,pairsAutoCorr)
743 #
743 #
744 # return pairsAutoCorr, pairsCrossCorr
744 # return pairsAutoCorr, pairsCrossCorr
745
745
746 # def techniqueSA(self, pairsSelected, pairsList, nChannels, tau, azimuth, _lambda, position_x, position_y, lagTRange, correctFactor):
746 # def techniqueSA(self, pairsSelected, pairsList, nChannels, tau, azimuth, _lambda, position_x, position_y, lagTRange, correctFactor):
747 def techniqueSA(self, kwargs):
747 def techniqueSA(self, kwargs):
748
748
749 """
749 """
750 Function that implements Spaced Antenna (SA) technique.
750 Function that implements Spaced Antenna (SA) technique.
751
751
752 Input: Radial velocities, Direction cosines (x and y) of the Beam, Antenna azimuth,
752 Input: Radial velocities, Direction cosines (x and y) of the Beam, Antenna azimuth,
753 Direction correction (if necessary), Ranges and SNR
753 Direction correction (if necessary), Ranges and SNR
754
754
755 Output: Winds estimation (Zonal, Meridional and Vertical)
755 Output: Winds estimation (Zonal, Meridional and Vertical)
756
756
757 Parameters affected: Winds
757 Parameters affected: Winds
758 """
758 """
759 position_x = kwargs['positionX']
759 position_x = kwargs['positionX']
760 position_y = kwargs['positionY']
760 position_y = kwargs['positionY']
761 azimuth = kwargs['azimuth']
761 azimuth = kwargs['azimuth']
762
762
763 if kwargs.has_key('correctFactor'):
763 if kwargs.has_key('correctFactor'):
764 correctFactor = kwargs['correctFactor']
764 correctFactor = kwargs['correctFactor']
765 else:
765 else:
766 correctFactor = 1
766 correctFactor = 1
767
767
768 groupList = kwargs['groupList']
768 groupList = kwargs['groupList']
769 pairs_ccf = groupList[1]
769 pairs_ccf = groupList[1]
770 tau = kwargs['tau']
770 tau = kwargs['tau']
771 _lambda = kwargs['_lambda']
771 _lambda = kwargs['_lambda']
772
772
773 #Cross Correlation pairs obtained
773 #Cross Correlation pairs obtained
774 # pairsAutoCorr, pairsCrossCorr = self.__getPairsAutoCorr(pairssList, nChannels)
774 # pairsAutoCorr, pairsCrossCorr = self.__getPairsAutoCorr(pairssList, nChannels)
775 # pairsArray = numpy.array(pairsList)[pairsCrossCorr]
775 # pairsArray = numpy.array(pairsList)[pairsCrossCorr]
776 # pairsSelArray = numpy.array(pairsSelected)
776 # pairsSelArray = numpy.array(pairsSelected)
777 # pairs = []
777 # pairs = []
778 #
778 #
779 # #Wind estimation pairs obtained
779 # #Wind estimation pairs obtained
780 # for i in range(pairsSelArray.shape[0]/2):
780 # for i in range(pairsSelArray.shape[0]/2):
781 # ind1 = numpy.where(numpy.all(pairsArray == pairsSelArray[2*i], axis = 1))[0][0]
781 # ind1 = numpy.where(numpy.all(pairsArray == pairsSelArray[2*i], axis = 1))[0][0]
782 # ind2 = numpy.where(numpy.all(pairsArray == pairsSelArray[2*i + 1], axis = 1))[0][0]
782 # ind2 = numpy.where(numpy.all(pairsArray == pairsSelArray[2*i + 1], axis = 1))[0][0]
783 # pairs.append((ind1,ind2))
783 # pairs.append((ind1,ind2))
784
784
785 indtau = tau.shape[0]/2
785 indtau = tau.shape[0]/2
786 tau1 = tau[:indtau,:]
786 tau1 = tau[:indtau,:]
787 tau2 = tau[indtau:-1,:]
787 tau2 = tau[indtau:-1,:]
788 # tau1 = tau1[pairs,:]
788 # tau1 = tau1[pairs,:]
789 # tau2 = tau2[pairs,:]
789 # tau2 = tau2[pairs,:]
790 phase1 = tau[-1,:]
790 phase1 = tau[-1,:]
791
791
792 #---------------------------------------------------------------------
792 #---------------------------------------------------------------------
793 #Metodo Directo
793 #Metodo Directo
794 distx, disty, dist, ang = self.__calculateDistance(position_x, position_y, pairs_ccf,azimuth)
794 distx, disty, dist, ang = self.__calculateDistance(position_x, position_y, pairs_ccf,azimuth)
795 winds = self.__calculateVelHorDir(dist, tau1, tau2, ang)
795 winds = self.__calculateVelHorDir(dist, tau1, tau2, ang)
796 winds = stats.nanmean(winds, axis=0)
796 winds = stats.nanmean(winds, axis=0)
797 #---------------------------------------------------------------------
797 #---------------------------------------------------------------------
798 #Metodo General
798 #Metodo General
799 # distx, disty, dist = self.calculateDistance(position_x,position_y,pairsCrossCorr, pairsList, azimuth)
799 # distx, disty, dist = self.calculateDistance(position_x,position_y,pairsCrossCorr, pairsList, azimuth)
800 # #Calculo Coeficientes de Funcion de Correlacion
800 # #Calculo Coeficientes de Funcion de Correlacion
801 # F,G,A,B,H = self.calculateCoef(tau1,tau2,distx,disty,n)
801 # F,G,A,B,H = self.calculateCoef(tau1,tau2,distx,disty,n)
802 # #Calculo de Velocidades
802 # #Calculo de Velocidades
803 # winds = self.calculateVelUV(F,G,A,B,H)
803 # winds = self.calculateVelUV(F,G,A,B,H)
804
804
805 #---------------------------------------------------------------------
805 #---------------------------------------------------------------------
806 winds[2,:] = self.__calculateVelVer(phase1, lagTRange, _lambda)
806 winds[2,:] = self.__calculateVelVer(phase1, lagTRange, _lambda)
807 winds = correctFactor*winds
807 winds = correctFactor*winds
808 return winds
808 return winds
809
809
810 def __checkTime(self, currentTime, paramInterval, outputInterval):
810 def __checkTime(self, currentTime, paramInterval, outputInterval):
811
811
812 dataTime = currentTime + paramInterval
812 dataTime = currentTime + paramInterval
813 deltaTime = dataTime - self.__initime
813 deltaTime = dataTime - self.__initime
814
814
815 if deltaTime >= outputInterval or deltaTime < 0:
815 if deltaTime >= outputInterval or deltaTime < 0:
816 self.__dataReady = True
816 self.__dataReady = True
817 return
817 return
818
818
819 def techniqueMeteors(self, arrayMeteor, meteorThresh, heightMin, heightMax, binkm=2):
819 def techniqueMeteors(self, arrayMeteor, meteorThresh, heightMin, heightMax, binkm=2):
820 '''
820 '''
821 Function that implements winds estimation technique with detected meteors.
821 Function that implements winds estimation technique with detected meteors.
822
822
823 Input: Detected meteors, Minimum meteor quantity to wind estimation
823 Input: Detected meteors, Minimum meteor quantity to wind estimation
824
824
825 Output: Winds estimation (Zonal and Meridional)
825 Output: Winds estimation (Zonal and Meridional)
826
826
827 Parameters affected: Winds
827 Parameters affected: Winds
828 '''
828 '''
829 # print arrayMeteor.shape
829 # print arrayMeteor.shape
830 #Settings
830 #Settings
831 nInt = (heightMax - heightMin)/binkm
831 nInt = (heightMax - heightMin)/binkm
832 # print nInt
832 # print nInt
833 nInt = int(nInt)
833 nInt = int(nInt)
834 # print nInt
834 # print nInt
835 winds = numpy.zeros((2,nInt))*numpy.nan
835 winds = numpy.zeros((2,nInt))*numpy.nan
836
836
837 #Filter errors
837 #Filter errors
838 error = numpy.where(arrayMeteor[:,-1] == 0)[0]
838 error = numpy.where(arrayMeteor[:,-1] == 0)[0]
839 finalMeteor = arrayMeteor[error,:]
839 finalMeteor = arrayMeteor[error,:]
840
840
841 #Meteor Histogram
841 #Meteor Histogram
842 finalHeights = finalMeteor[:,2]
842 finalHeights = finalMeteor[:,2]
843 hist = numpy.histogram(finalHeights, bins = nInt, range = (heightMin,heightMax))
843 hist = numpy.histogram(finalHeights, bins = nInt, range = (heightMin,heightMax))
844 nMeteorsPerI = hist[0]
844 nMeteorsPerI = hist[0]
845 heightPerI = hist[1]
845 heightPerI = hist[1]
846
846
847 #Sort of meteors
847 #Sort of meteors
848 indSort = finalHeights.argsort()
848 indSort = finalHeights.argsort()
849 finalMeteor2 = finalMeteor[indSort,:]
849 finalMeteor2 = finalMeteor[indSort,:]
850
850
851 # Calculating winds
851 # Calculating winds
852 ind1 = 0
852 ind1 = 0
853 ind2 = 0
853 ind2 = 0
854
854
855 for i in range(nInt):
855 for i in range(nInt):
856 nMet = nMeteorsPerI[i]
856 nMet = nMeteorsPerI[i]
857 ind1 = ind2
857 ind1 = ind2
858 ind2 = ind1 + nMet
858 ind2 = ind1 + nMet
859
859
860 meteorAux = finalMeteor2[ind1:ind2,:]
860 meteorAux = finalMeteor2[ind1:ind2,:]
861
861
862 if meteorAux.shape[0] >= meteorThresh:
862 if meteorAux.shape[0] >= meteorThresh:
863 vel = meteorAux[:, 6]
863 vel = meteorAux[:, 6]
864 zen = meteorAux[:, 4]*numpy.pi/180
864 zen = meteorAux[:, 4]*numpy.pi/180
865 azim = meteorAux[:, 3]*numpy.pi/180
865 azim = meteorAux[:, 3]*numpy.pi/180
866
866
867 n = numpy.cos(zen)
867 n = numpy.cos(zen)
868 # m = (1 - n**2)/(1 - numpy.tan(azim)**2)
868 # m = (1 - n**2)/(1 - numpy.tan(azim)**2)
869 # l = m*numpy.tan(azim)
869 # l = m*numpy.tan(azim)
870 l = numpy.sin(zen)*numpy.sin(azim)
870 l = numpy.sin(zen)*numpy.sin(azim)
871 m = numpy.sin(zen)*numpy.cos(azim)
871 m = numpy.sin(zen)*numpy.cos(azim)
872
872
873 A = numpy.vstack((l, m)).transpose()
873 A = numpy.vstack((l, m)).transpose()
874 A1 = numpy.dot(numpy.linalg.inv( numpy.dot(A.transpose(),A) ),A.transpose())
874 A1 = numpy.dot(numpy.linalg.inv( numpy.dot(A.transpose(),A) ),A.transpose())
875 windsAux = numpy.dot(A1, vel)
875 windsAux = numpy.dot(A1, vel)
876
876
877 winds[0,i] = windsAux[0]
877 winds[0,i] = windsAux[0]
878 winds[1,i] = windsAux[1]
878 winds[1,i] = windsAux[1]
879
879
880 return winds, heightPerI[:-1]
880 return winds, heightPerI[:-1]
881
881
882 def techniqueNSM_SA(self, **kwargs):
882 def techniqueNSM_SA(self, **kwargs):
883 metArray = kwargs['metArray']
883 metArray = kwargs['metArray']
884 heightList = kwargs['heightList']
884 heightList = kwargs['heightList']
885 timeList = kwargs['timeList']
885 timeList = kwargs['timeList']
886
886
887 rx_location = kwargs['rx_location']
887 rx_location = kwargs['rx_location']
888 groupList = kwargs['groupList']
888 groupList = kwargs['groupList']
889 azimuth = kwargs['azimuth']
889 azimuth = kwargs['azimuth']
890 dfactor = kwargs['dfactor']
890 dfactor = kwargs['dfactor']
891 k = kwargs['k']
891 k = kwargs['k']
892
892
893 azimuth1, dist = self.__calculateAzimuth1(rx_location, groupList, azimuth)
893 azimuth1, dist = self.__calculateAzimuth1(rx_location, groupList, azimuth)
894 d = dist*dfactor
894 d = dist*dfactor
895 #Phase calculation
895 #Phase calculation
896 metArray1 = self.__getPhaseSlope(metArray, heightList, timeList)
896 metArray1 = self.__getPhaseSlope(metArray, heightList, timeList)
897
897
898 metArray1[:,-2] = metArray1[:,-2]*metArray1[:,2]*1000/(k*d[metArray1[:,1].astype(int)]) #angles into velocities
898 metArray1[:,-2] = metArray1[:,-2]*metArray1[:,2]*1000/(k*d[metArray1[:,1].astype(int)]) #angles into velocities
899
899
900 velEst = numpy.zeros((heightList.size,2))*numpy.nan
900 velEst = numpy.zeros((heightList.size,2))*numpy.nan
901 azimuth1 = azimuth1*numpy.pi/180
901 azimuth1 = azimuth1*numpy.pi/180
902
902
903 for i in range(heightList.size):
903 for i in range(heightList.size):
904 h = heightList[i]
904 h = heightList[i]
905 indH = numpy.where((metArray1[:,2] == h)&(numpy.abs(metArray1[:,-2]) < 100))[0]
905 indH = numpy.where((metArray1[:,2] == h)&(numpy.abs(metArray1[:,-2]) < 100))[0]
906 metHeight = metArray1[indH,:]
906 metHeight = metArray1[indH,:]
907 if metHeight.shape[0] >= 2:
907 if metHeight.shape[0] >= 2:
908 velAux = numpy.asmatrix(metHeight[:,-2]).T #Radial Velocities
908 velAux = numpy.asmatrix(metHeight[:,-2]).T #Radial Velocities
909 iazim = metHeight[:,1].astype(int)
909 iazim = metHeight[:,1].astype(int)
910 azimAux = numpy.asmatrix(azimuth1[iazim]).T #Azimuths
910 azimAux = numpy.asmatrix(azimuth1[iazim]).T #Azimuths
911 A = numpy.hstack((numpy.cos(azimAux),numpy.sin(azimAux)))
911 A = numpy.hstack((numpy.cos(azimAux),numpy.sin(azimAux)))
912 A = numpy.asmatrix(A)
912 A = numpy.asmatrix(A)
913 A1 = numpy.linalg.pinv(A.transpose()*A)*A.transpose()
913 A1 = numpy.linalg.pinv(A.transpose()*A)*A.transpose()
914 velHor = numpy.dot(A1,velAux)
914 velHor = numpy.dot(A1,velAux)
915
915
916 velEst[i,:] = numpy.squeeze(velHor)
916 velEst[i,:] = numpy.squeeze(velHor)
917 return velEst
917 return velEst
918
918
919 def __getPhaseSlope(self, metArray, heightList, timeList):
919 def __getPhaseSlope(self, metArray, heightList, timeList):
920 meteorList = []
920 meteorList = []
921 #utctime sec1 height SNR velRad ph0 ph1 ph2 coh0 coh1 coh2
921 #utctime sec1 height SNR velRad ph0 ph1 ph2 coh0 coh1 coh2
922 #Putting back together the meteor matrix
922 #Putting back together the meteor matrix
923 utctime = metArray[:,0]
923 utctime = metArray[:,0]
924 uniqueTime = numpy.unique(utctime)
924 uniqueTime = numpy.unique(utctime)
925
925
926 phaseDerThresh = 0.5
926 phaseDerThresh = 0.5
927 ippSeconds = timeList[1] - timeList[0]
927 ippSeconds = timeList[1] - timeList[0]
928 sec = numpy.where(timeList>1)[0][0]
928 sec = numpy.where(timeList>1)[0][0]
929 nPairs = metArray.shape[1] - 6
929 nPairs = metArray.shape[1] - 6
930 nHeights = len(heightList)
930 nHeights = len(heightList)
931
931
932 for t in uniqueTime:
932 for t in uniqueTime:
933 metArray1 = metArray[utctime==t,:]
933 metArray1 = metArray[utctime==t,:]
934 # phaseDerThresh = numpy.pi/4 #reducir Phase thresh
934 # phaseDerThresh = numpy.pi/4 #reducir Phase thresh
935 tmet = metArray1[:,1].astype(int)
935 tmet = metArray1[:,1].astype(int)
936 hmet = metArray1[:,2].astype(int)
936 hmet = metArray1[:,2].astype(int)
937
937
938 metPhase = numpy.zeros((nPairs, heightList.size, timeList.size - 1))
938 metPhase = numpy.zeros((nPairs, heightList.size, timeList.size - 1))
939 metPhase[:,:] = numpy.nan
939 metPhase[:,:] = numpy.nan
940 metPhase[:,hmet,tmet] = metArray1[:,6:].T
940 metPhase[:,hmet,tmet] = metArray1[:,6:].T
941
941
942 #Delete short trails
942 #Delete short trails
943 metBool = ~numpy.isnan(metPhase[0,:,:])
943 metBool = ~numpy.isnan(metPhase[0,:,:])
944 heightVect = numpy.sum(metBool, axis = 1)
944 heightVect = numpy.sum(metBool, axis = 1)
945 metBool[heightVect<sec,:] = False
945 metBool[heightVect<sec,:] = False
946 metPhase[:,heightVect<sec,:] = numpy.nan
946 metPhase[:,heightVect<sec,:] = numpy.nan
947
947
948 #Derivative
948 #Derivative
949 metDer = numpy.abs(metPhase[:,:,1:] - metPhase[:,:,:-1])
949 metDer = numpy.abs(metPhase[:,:,1:] - metPhase[:,:,:-1])
950 phDerAux = numpy.dstack((numpy.full((nPairs,nHeights,1), False, dtype=bool),metDer > phaseDerThresh))
950 phDerAux = numpy.dstack((numpy.full((nPairs,nHeights,1), False, dtype=bool),metDer > phaseDerThresh))
951 metPhase[phDerAux] = numpy.nan
951 metPhase[phDerAux] = numpy.nan
952
952
953 #--------------------------METEOR DETECTION -----------------------------------------
953 #--------------------------METEOR DETECTION -----------------------------------------
954 indMet = numpy.where(numpy.any(metBool,axis=1))[0]
954 indMet = numpy.where(numpy.any(metBool,axis=1))[0]
955
955
956 for p in numpy.arange(nPairs):
956 for p in numpy.arange(nPairs):
957 phase = metPhase[p,:,:]
957 phase = metPhase[p,:,:]
958 phDer = metDer[p,:,:]
958 phDer = metDer[p,:,:]
959
959
960 for h in indMet:
960 for h in indMet:
961 height = heightList[h]
961 height = heightList[h]
962 phase1 = phase[h,:] #82
962 phase1 = phase[h,:] #82
963 phDer1 = phDer[h,:]
963 phDer1 = phDer[h,:]
964
964
965 phase1[~numpy.isnan(phase1)] = numpy.unwrap(phase1[~numpy.isnan(phase1)]) #Unwrap
965 phase1[~numpy.isnan(phase1)] = numpy.unwrap(phase1[~numpy.isnan(phase1)]) #Unwrap
966
966
967 indValid = numpy.where(~numpy.isnan(phase1))[0]
967 indValid = numpy.where(~numpy.isnan(phase1))[0]
968 initMet = indValid[0]
968 initMet = indValid[0]
969 endMet = 0
969 endMet = 0
970
970
971 for i in range(len(indValid)-1):
971 for i in range(len(indValid)-1):
972
972
973 #Time difference
973 #Time difference
974 inow = indValid[i]
974 inow = indValid[i]
975 inext = indValid[i+1]
975 inext = indValid[i+1]
976 idiff = inext - inow
976 idiff = inext - inow
977 #Phase difference
977 #Phase difference
978 phDiff = numpy.abs(phase1[inext] - phase1[inow])
978 phDiff = numpy.abs(phase1[inext] - phase1[inow])
979
979
980 if idiff>sec or phDiff>numpy.pi/4 or inext==indValid[-1]: #End of Meteor
980 if idiff>sec or phDiff>numpy.pi/4 or inext==indValid[-1]: #End of Meteor
981 sizeTrail = inow - initMet + 1
981 sizeTrail = inow - initMet + 1
982 if sizeTrail>3*sec: #Too short meteors
982 if sizeTrail>3*sec: #Too short meteors
983 x = numpy.arange(initMet,inow+1)*ippSeconds
983 x = numpy.arange(initMet,inow+1)*ippSeconds
984 y = phase1[initMet:inow+1]
984 y = phase1[initMet:inow+1]
985 ynnan = ~numpy.isnan(y)
985 ynnan = ~numpy.isnan(y)
986 x = x[ynnan]
986 x = x[ynnan]
987 y = y[ynnan]
987 y = y[ynnan]
988 slope, intercept, r_value, p_value, std_err = stats.linregress(x,y)
988 slope, intercept, r_value, p_value, std_err = stats.linregress(x,y)
989 ylin = x*slope + intercept
989 ylin = x*slope + intercept
990 rsq = r_value**2
990 rsq = r_value**2
991 if rsq > 0.5:
991 if rsq > 0.5:
992 vel = slope#*height*1000/(k*d)
992 vel = slope#*height*1000/(k*d)
993 estAux = numpy.array([utctime,p,height, vel, rsq])
993 estAux = numpy.array([utctime,p,height, vel, rsq])
994 meteorList.append(estAux)
994 meteorList.append(estAux)
995 initMet = inext
995 initMet = inext
996 metArray2 = numpy.array(meteorList)
996 metArray2 = numpy.array(meteorList)
997
997
998 return metArray2
998 return metArray2
999
999
1000 def __calculateAzimuth1(self, rx_location, pairslist, azimuth0):
1000 def __calculateAzimuth1(self, rx_location, pairslist, azimuth0):
1001
1001
1002 azimuth1 = numpy.zeros(len(pairslist))
1002 azimuth1 = numpy.zeros(len(pairslist))
1003 dist = numpy.zeros(len(pairslist))
1003 dist = numpy.zeros(len(pairslist))
1004
1004
1005 for i in range(len(rx_location)):
1005 for i in range(len(rx_location)):
1006 ch0 = pairslist[i][0]
1006 ch0 = pairslist[i][0]
1007 ch1 = pairslist[i][1]
1007 ch1 = pairslist[i][1]
1008
1008
1009 diffX = rx_location[ch0][0] - rx_location[ch1][0]
1009 diffX = rx_location[ch0][0] - rx_location[ch1][0]
1010 diffY = rx_location[ch0][1] - rx_location[ch1][1]
1010 diffY = rx_location[ch0][1] - rx_location[ch1][1]
1011 azimuth1[i] = numpy.arctan2(diffY,diffX)*180/numpy.pi
1011 azimuth1[i] = numpy.arctan2(diffY,diffX)*180/numpy.pi
1012 dist[i] = numpy.sqrt(diffX**2 + diffY**2)
1012 dist[i] = numpy.sqrt(diffX**2 + diffY**2)
1013
1013
1014 azimuth1 -= azimuth0
1014 azimuth1 -= azimuth0
1015 return azimuth1, dist
1015 return azimuth1, dist
1016
1016
1017 def techniqueNSM_DBS(self, **kwargs):
1017 def techniqueNSM_DBS(self, **kwargs):
1018 metArray = kwargs['metArray']
1018 metArray = kwargs['metArray']
1019 heightList = kwargs['heightList']
1019 heightList = kwargs['heightList']
1020 timeList = kwargs['timeList']
1020 timeList = kwargs['timeList']
1021 azimuth = kwargs['azimuth']
1021 azimuth = kwargs['azimuth']
1022 theta_x = numpy.array(kwargs['theta_x'])
1022 theta_x = numpy.array(kwargs['theta_x'])
1023 theta_y = numpy.array(kwargs['theta_y'])
1023 theta_y = numpy.array(kwargs['theta_y'])
1024
1024
1025 utctime = metArray[:,0]
1025 utctime = metArray[:,0]
1026 cmet = metArray[:,1].astype(int)
1026 cmet = metArray[:,1].astype(int)
1027 hmet = metArray[:,3].astype(int)
1027 hmet = metArray[:,3].astype(int)
1028 SNRmet = metArray[:,4]
1028 SNRmet = metArray[:,4]
1029 vmet = metArray[:,5]
1029 vmet = metArray[:,5]
1030 spcmet = metArray[:,6]
1030 spcmet = metArray[:,6]
1031
1031
1032 nChan = numpy.max(cmet) + 1
1032 nChan = numpy.max(cmet) + 1
1033 nHeights = len(heightList)
1033 nHeights = len(heightList)
1034
1034
1035 azimuth_arr, zenith_arr, dir_cosu, dir_cosv, dir_cosw = self.__calculateAngles(theta_x, theta_y, azimuth)
1035 azimuth_arr, zenith_arr, dir_cosu, dir_cosv, dir_cosw = self.__calculateAngles(theta_x, theta_y, azimuth)
1036 hmet = heightList[hmet]
1036 hmet = heightList[hmet]
1037 h1met = hmet*numpy.cos(zenith_arr[cmet]) #Corrected heights
1037 h1met = hmet*numpy.cos(zenith_arr[cmet]) #Corrected heights
1038
1038
1039 velEst = numpy.zeros((heightList.size,2))*numpy.nan
1039 velEst = numpy.zeros((heightList.size,2))*numpy.nan
1040
1040
1041 for i in range(nHeights - 1):
1041 for i in range(nHeights - 1):
1042 hmin = heightList[i]
1042 hmin = heightList[i]
1043 hmax = heightList[i + 1]
1043 hmax = heightList[i + 1]
1044
1044
1045 thisH = (h1met>=hmin) & (h1met<hmax) & (cmet!=2) & (SNRmet>8) & (vmet<50) & (spcmet<10)
1045 thisH = (h1met>=hmin) & (h1met<hmax) & (cmet!=2) & (SNRmet>8) & (vmet<50) & (spcmet<10)
1046 indthisH = numpy.where(thisH)
1046 indthisH = numpy.where(thisH)
1047
1047
1048 if numpy.size(indthisH) > 3:
1048 if numpy.size(indthisH) > 3:
1049
1049
1050 vel_aux = vmet[thisH]
1050 vel_aux = vmet[thisH]
1051 chan_aux = cmet[thisH]
1051 chan_aux = cmet[thisH]
1052 cosu_aux = dir_cosu[chan_aux]
1052 cosu_aux = dir_cosu[chan_aux]
1053 cosv_aux = dir_cosv[chan_aux]
1053 cosv_aux = dir_cosv[chan_aux]
1054 cosw_aux = dir_cosw[chan_aux]
1054 cosw_aux = dir_cosw[chan_aux]
1055
1055
1056 nch = numpy.size(numpy.unique(chan_aux))
1056 nch = numpy.size(numpy.unique(chan_aux))
1057 if nch > 1:
1057 if nch > 1:
1058 A = self.__calculateMatA(cosu_aux, cosv_aux, cosw_aux, True)
1058 A = self.__calculateMatA(cosu_aux, cosv_aux, cosw_aux, True)
1059 velEst[i,:] = numpy.dot(A,vel_aux)
1059 velEst[i,:] = numpy.dot(A,vel_aux)
1060
1060
1061 return velEst
1061 return velEst
1062
1062
1063 def run(self, dataOut, technique, nHours=1, hmin=70, hmax=110, **kwargs):
1063 def run(self, dataOut, technique, nHours=1, hmin=70, hmax=110, **kwargs):
1064
1064
1065 param = dataOut.data_param
1065 param = dataOut.data_param
1066 if dataOut.abscissaList != None:
1066 if dataOut.abscissaList != None:
1067 absc = dataOut.abscissaList[:-1]
1067 absc = dataOut.abscissaList[:-1]
1068 # noise = dataOut.noise
1068 # noise = dataOut.noise
1069 heightList = dataOut.heightList
1069 heightList = dataOut.heightList
1070 SNR = dataOut.data_SNR
1070 SNR = dataOut.data_SNR
1071
1071
1072 if technique == 'DBS':
1072 if technique == 'DBS':
1073
1073
1074 kwargs['velRadial'] = param[:,1,:] #Radial velocity
1074 kwargs['velRadial'] = param[:,1,:] #Radial velocity
1075 kwargs['heightList'] = heightList
1075 kwargs['heightList'] = heightList
1076 kwargs['SNR'] = SNR
1076 kwargs['SNR'] = SNR
1077
1077
1078 dataOut.data_output, dataOut.heightList, dataOut.data_SNR = self.techniqueDBS(kwargs) #DBS Function
1078 dataOut.data_output, dataOut.heightList, dataOut.data_SNR = self.techniqueDBS(kwargs) #DBS Function
1079 dataOut.utctimeInit = dataOut.utctime
1079 dataOut.utctimeInit = dataOut.utctime
1080 dataOut.outputInterval = dataOut.paramInterval
1080 dataOut.outputInterval = dataOut.paramInterval
1081
1081
1082 elif technique == 'SA':
1082 elif technique == 'SA':
1083
1083
1084 #Parameters
1084 #Parameters
1085 # position_x = kwargs['positionX']
1085 # position_x = kwargs['positionX']
1086 # position_y = kwargs['positionY']
1086 # position_y = kwargs['positionY']
1087 # azimuth = kwargs['azimuth']
1087 # azimuth = kwargs['azimuth']
1088 #
1088 #
1089 # if kwargs.has_key('crosspairsList'):
1089 # if kwargs.has_key('crosspairsList'):
1090 # pairs = kwargs['crosspairsList']
1090 # pairs = kwargs['crosspairsList']
1091 # else:
1091 # else:
1092 # pairs = None
1092 # pairs = None
1093 #
1093 #
1094 # if kwargs.has_key('correctFactor'):
1094 # if kwargs.has_key('correctFactor'):
1095 # correctFactor = kwargs['correctFactor']
1095 # correctFactor = kwargs['correctFactor']
1096 # else:
1096 # else:
1097 # correctFactor = 1
1097 # correctFactor = 1
1098
1098
1099 # tau = dataOut.data_param
1099 # tau = dataOut.data_param
1100 # _lambda = dataOut.C/dataOut.frequency
1100 # _lambda = dataOut.C/dataOut.frequency
1101 # pairsList = dataOut.groupList
1101 # pairsList = dataOut.groupList
1102 # nChannels = dataOut.nChannels
1102 # nChannels = dataOut.nChannels
1103
1103
1104 kwargs['groupList'] = dataOut.groupList
1104 kwargs['groupList'] = dataOut.groupList
1105 kwargs['tau'] = dataOut.data_param
1105 kwargs['tau'] = dataOut.data_param
1106 kwargs['_lambda'] = dataOut.C/dataOut.frequency
1106 kwargs['_lambda'] = dataOut.C/dataOut.frequency
1107 # dataOut.data_output = self.techniqueSA(pairs, pairsList, nChannels, tau, azimuth, _lambda, position_x, position_y, absc, correctFactor)
1107 # dataOut.data_output = self.techniqueSA(pairs, pairsList, nChannels, tau, azimuth, _lambda, position_x, position_y, absc, correctFactor)
1108 dataOut.data_output = self.techniqueSA(kwargs)
1108 dataOut.data_output = self.techniqueSA(kwargs)
1109 dataOut.utctimeInit = dataOut.utctime
1109 dataOut.utctimeInit = dataOut.utctime
1110 dataOut.outputInterval = dataOut.timeInterval
1110 dataOut.outputInterval = dataOut.timeInterval
1111
1111
1112 elif technique == 'Meteors':
1112 elif technique == 'Meteors':
1113 dataOut.flagNoData = True
1113 dataOut.flagNoData = True
1114 self.__dataReady = False
1114 self.__dataReady = False
1115
1115
1116 if kwargs.has_key('nHours'):
1116 if kwargs.has_key('nHours'):
1117 nHours = kwargs['nHours']
1117 nHours = kwargs['nHours']
1118 else:
1118 else:
1119 nHours = 1
1119 nHours = 1
1120
1120
1121 if kwargs.has_key('meteorsPerBin'):
1121 if kwargs.has_key('meteorsPerBin'):
1122 meteorThresh = kwargs['meteorsPerBin']
1122 meteorThresh = kwargs['meteorsPerBin']
1123 else:
1123 else:
1124 meteorThresh = 6
1124 meteorThresh = 6
1125
1125
1126 if kwargs.has_key('hmin'):
1126 if kwargs.has_key('hmin'):
1127 hmin = kwargs['hmin']
1127 hmin = kwargs['hmin']
1128 else: hmin = 70
1128 else: hmin = 70
1129 if kwargs.has_key('hmax'):
1129 if kwargs.has_key('hmax'):
1130 hmax = kwargs['hmax']
1130 hmax = kwargs['hmax']
1131 else: hmax = 110
1131 else: hmax = 110
1132
1132
1133 if kwargs.has_key('BinKm'):
1133 if kwargs.has_key('BinKm'):
1134 binkm = kwargs['BinKm']
1134 binkm = kwargs['BinKm']
1135 else:
1135 else:
1136 binkm = 2
1136 binkm = 2
1137
1137
1138 dataOut.outputInterval = nHours*3600
1138 dataOut.outputInterval = nHours*3600
1139
1139
1140 if self.__isConfig == False:
1140 if self.__isConfig == False:
1141 # self.__initime = dataOut.datatime.replace(minute = 0, second = 0, microsecond = 03)
1141 # self.__initime = dataOut.datatime.replace(minute = 0, second = 0, microsecond = 03)
1142 #Get Initial LTC time
1142 #Get Initial LTC time
1143 self.__initime = datetime.datetime.utcfromtimestamp(dataOut.utctime)
1143 self.__initime = datetime.datetime.utcfromtimestamp(dataOut.utctime)
1144 self.__initime = (self.__initime.replace(minute = 0, second = 0, microsecond = 0) - datetime.datetime(1970, 1, 1)).total_seconds()
1144 self.__initime = (self.__initime.replace(minute = 0, second = 0, microsecond = 0) - datetime.datetime(1970, 1, 1)).total_seconds()
1145
1145
1146 self.__isConfig = True
1146 self.__isConfig = True
1147
1147
1148 if self.__buffer is None:
1148 if self.__buffer is None:
1149 self.__buffer = dataOut.data_param
1149 self.__buffer = dataOut.data_param
1150 self.__firstdata = copy.copy(dataOut)
1150 self.__firstdata = copy.copy(dataOut)
1151
1151
1152 else:
1152 else:
1153 self.__buffer = numpy.vstack((self.__buffer, dataOut.data_param))
1153 self.__buffer = numpy.vstack((self.__buffer, dataOut.data_param))
1154
1154
1155 self.__checkTime(dataOut.utctime, dataOut.paramInterval, dataOut.outputInterval) #Check if the buffer is ready
1155 self.__checkTime(dataOut.utctime, dataOut.paramInterval, dataOut.outputInterval) #Check if the buffer is ready
1156
1156
1157 if self.__dataReady:
1157 if self.__dataReady:
1158 dataOut.utctimeInit = self.__initime
1158 dataOut.utctimeInit = self.__initime
1159
1159
1160 self.__initime += dataOut.outputInterval #to erase time offset
1160 self.__initime += dataOut.outputInterval #to erase time offset
1161
1161
1162 dataOut.data_output, dataOut.heightList = self.techniqueMeteors(self.__buffer, meteorThresh, hmin, hmax, binkm)
1162 dataOut.data_output, dataOut.heightList = self.techniqueMeteors(self.__buffer, meteorThresh, hmin, hmax, binkm)
1163 dataOut.flagNoData = False
1163 dataOut.flagNoData = False
1164 self.__buffer = None
1164 self.__buffer = None
1165
1165
1166 elif technique == 'Meteors1':
1166 elif technique == 'Meteors1':
1167 dataOut.flagNoData = True
1167 dataOut.flagNoData = True
1168 self.__dataReady = False
1168 self.__dataReady = False
1169
1169
1170 if kwargs.has_key('nMins'):
1170 if kwargs.has_key('nMins'):
1171 nMins = kwargs['nMins']
1171 nMins = kwargs['nMins']
1172 else: nMins = 20
1172 else: nMins = 20
1173 if kwargs.has_key('rx_location'):
1173 if kwargs.has_key('rx_location'):
1174 rx_location = kwargs['rx_location']
1174 rx_location = kwargs['rx_location']
1175 else: rx_location = [(0,1),(1,1),(1,0)]
1175 else: rx_location = [(0,1),(1,1),(1,0)]
1176 if kwargs.has_key('azimuth'):
1176 if kwargs.has_key('azimuth'):
1177 azimuth = kwargs['azimuth']
1177 azimuth = kwargs['azimuth']
1178 else: azimuth = 51.06
1178 else: azimuth = 51.06
1179 if kwargs.has_key('dfactor'):
1179 if kwargs.has_key('dfactor'):
1180 dfactor = kwargs['dfactor']
1180 dfactor = kwargs['dfactor']
1181 if kwargs.has_key('mode'):
1181 if kwargs.has_key('mode'):
1182 mode = kwargs['mode']
1182 mode = kwargs['mode']
1183 if kwargs.has_key('theta_x'):
1183 if kwargs.has_key('theta_x'):
1184 theta_x = kwargs['theta_x']
1184 theta_x = kwargs['theta_x']
1185 if kwargs.has_key('theta_y'):
1185 if kwargs.has_key('theta_y'):
1186 theta_y = kwargs['theta_y']
1186 theta_y = kwargs['theta_y']
1187 else: mode = 'SA'
1187 else: mode = 'SA'
1188
1188
1189 #Borrar luego esto
1189 #Borrar luego esto
1190 if dataOut.groupList is None:
1190 if dataOut.groupList is None:
1191 dataOut.groupList = [(0,1),(0,2),(1,2)]
1191 dataOut.groupList = [(0,1),(0,2),(1,2)]
1192 groupList = dataOut.groupList
1192 groupList = dataOut.groupList
1193 C = 3e8
1193 C = 3e8
1194 freq = 50e6
1194 freq = 50e6
1195 lamb = C/freq
1195 lamb = C/freq
1196 k = 2*numpy.pi/lamb
1196 k = 2*numpy.pi/lamb
1197
1197
1198 timeList = dataOut.abscissaList
1198 timeList = dataOut.abscissaList
1199 heightList = dataOut.heightList
1199 heightList = dataOut.heightList
1200
1200
1201 if self.__isConfig == False:
1201 if self.__isConfig == False:
1202 dataOut.outputInterval = nMins*60
1202 dataOut.outputInterval = nMins*60
1203 # self.__initime = dataOut.datatime.replace(minute = 0, second = 0, microsecond = 03)
1203 # self.__initime = dataOut.datatime.replace(minute = 0, second = 0, microsecond = 03)
1204 #Get Initial LTC time
1204 #Get Initial LTC time
1205 initime = datetime.datetime.utcfromtimestamp(dataOut.utctime)
1205 initime = datetime.datetime.utcfromtimestamp(dataOut.utctime)
1206 minuteAux = initime.minute
1206 minuteAux = initime.minute
1207 minuteNew = int(numpy.floor(minuteAux/nMins)*nMins)
1207 minuteNew = int(numpy.floor(minuteAux/nMins)*nMins)
1208 self.__initime = (initime.replace(minute = minuteNew, second = 0, microsecond = 0) - datetime.datetime(1970, 1, 1)).total_seconds()
1208 self.__initime = (initime.replace(minute = minuteNew, second = 0, microsecond = 0) - datetime.datetime(1970, 1, 1)).total_seconds()
1209
1209
1210 self.__isConfig = True
1210 self.__isConfig = True
1211
1211
1212 if self.__buffer is None:
1212 if self.__buffer is None:
1213 self.__buffer = dataOut.data_param
1213 self.__buffer = dataOut.data_param
1214 self.__firstdata = copy.copy(dataOut)
1214 self.__firstdata = copy.copy(dataOut)
1215
1215
1216 else:
1216 else:
1217 self.__buffer = numpy.vstack((self.__buffer, dataOut.data_param))
1217 self.__buffer = numpy.vstack((self.__buffer, dataOut.data_param))
1218
1218
1219 self.__checkTime(dataOut.utctime, dataOut.paramInterval, dataOut.outputInterval) #Check if the buffer is ready
1219 self.__checkTime(dataOut.utctime, dataOut.paramInterval, dataOut.outputInterval) #Check if the buffer is ready
1220
1220
1221 if self.__dataReady:
1221 if self.__dataReady:
1222 dataOut.utctimeInit = self.__initime
1222 dataOut.utctimeInit = self.__initime
1223 self.__initime += dataOut.outputInterval #to erase time offset
1223 self.__initime += dataOut.outputInterval #to erase time offset
1224
1224
1225 metArray = self.__buffer
1225 metArray = self.__buffer
1226 if mode == 'SA':
1226 if mode == 'SA':
1227 dataOut.data_output = self.techniqueNSM_SA(rx_location=rx_location, groupList=groupList, azimuth=azimuth, dfactor=dfactor, k=k,metArray=metArray, heightList=heightList,timeList=timeList)
1227 dataOut.data_output = self.techniqueNSM_SA(rx_location=rx_location, groupList=groupList, azimuth=azimuth, dfactor=dfactor, k=k,metArray=metArray, heightList=heightList,timeList=timeList)
1228 elif mode == 'DBS':
1228 elif mode == 'DBS':
1229 dataOut.data_output = self.techniqueNSM_DBS(metArray=metArray,heightList=heightList,timeList=timeList, azimuth=azimuth, theta_x=theta_x, theta_y=theta_y)
1229 dataOut.data_output = self.techniqueNSM_DBS(metArray=metArray,heightList=heightList,timeList=timeList, azimuth=azimuth, theta_x=theta_x, theta_y=theta_y)
1230 dataOut.data_output = dataOut.data_output.T
1230 dataOut.data_output = dataOut.data_output.T
1231 dataOut.flagNoData = False
1231 dataOut.flagNoData = False
1232 self.__buffer = None
1232 self.__buffer = None
1233
1233
1234 return
1234 return
1235
1235
1236 class EWDriftsEstimation(Operation):
1236 class EWDriftsEstimation(Operation):
1237
1237
1238
1238
1239 def __correctValues(self, heiRang, phi, velRadial, SNR):
1239 def __correctValues(self, heiRang, phi, velRadial, SNR):
1240 listPhi = phi.tolist()
1240 listPhi = phi.tolist()
1241 maxid = listPhi.index(max(listPhi))
1241 maxid = listPhi.index(max(listPhi))
1242 minid = listPhi.index(min(listPhi))
1242 minid = listPhi.index(min(listPhi))
1243
1243
1244 rango = range(len(phi))
1244 rango = range(len(phi))
1245 # rango = numpy.delete(rango,maxid)
1245 # rango = numpy.delete(rango,maxid)
1246
1246
1247 heiRang1 = heiRang*math.cos(phi[maxid])
1247 heiRang1 = heiRang*math.cos(phi[maxid])
1248 heiRangAux = heiRang*math.cos(phi[minid])
1248 heiRangAux = heiRang*math.cos(phi[minid])
1249 indOut = (heiRang1 < heiRangAux[0]).nonzero()
1249 indOut = (heiRang1 < heiRangAux[0]).nonzero()
1250 heiRang1 = numpy.delete(heiRang1,indOut)
1250 heiRang1 = numpy.delete(heiRang1,indOut)
1251
1251
1252 velRadial1 = numpy.zeros([len(phi),len(heiRang1)])
1252 velRadial1 = numpy.zeros([len(phi),len(heiRang1)])
1253 SNR1 = numpy.zeros([len(phi),len(heiRang1)])
1253 SNR1 = numpy.zeros([len(phi),len(heiRang1)])
1254
1254
1255 for i in rango:
1255 for i in rango:
1256 x = heiRang*math.cos(phi[i])
1256 x = heiRang*math.cos(phi[i])
1257 y1 = velRadial[i,:]
1257 y1 = velRadial[i,:]
1258 f1 = interpolate.interp1d(x,y1,kind = 'cubic')
1258 f1 = interpolate.interp1d(x,y1,kind = 'cubic')
1259
1259
1260 x1 = heiRang1
1260 x1 = heiRang1
1261 y11 = f1(x1)
1261 y11 = f1(x1)
1262
1262
1263 y2 = SNR[i,:]
1263 y2 = SNR[i,:]
1264 f2 = interpolate.interp1d(x,y2,kind = 'cubic')
1264 f2 = interpolate.interp1d(x,y2,kind = 'cubic')
1265 y21 = f2(x1)
1265 y21 = f2(x1)
1266
1266
1267 velRadial1[i,:] = y11
1267 velRadial1[i,:] = y11
1268 SNR1[i,:] = y21
1268 SNR1[i,:] = y21
1269
1269
1270 return heiRang1, velRadial1, SNR1
1270 return heiRang1, velRadial1, SNR1
1271
1271
1272 def run(self, dataOut, zenith, zenithCorrection):
1272 def run(self, dataOut, zenith, zenithCorrection):
1273 heiRang = dataOut.heightList
1273 heiRang = dataOut.heightList
1274 velRadial = dataOut.data_param[:,3,:]
1274 velRadial = dataOut.data_param[:,3,:]
1275 SNR = dataOut.data_SNR
1275 SNR = dataOut.data_SNR
1276
1276
1277 zenith = numpy.array(zenith)
1277 zenith = numpy.array(zenith)
1278 zenith -= zenithCorrection
1278 zenith -= zenithCorrection
1279 zenith *= numpy.pi/180
1279 zenith *= numpy.pi/180
1280
1280
1281 heiRang1, velRadial1, SNR1 = self.__correctValues(heiRang, numpy.abs(zenith), velRadial, SNR)
1281 heiRang1, velRadial1, SNR1 = self.__correctValues(heiRang, numpy.abs(zenith), velRadial, SNR)
1282
1282
1283 alp = zenith[0]
1283 alp = zenith[0]
1284 bet = zenith[1]
1284 bet = zenith[1]
1285
1285
1286 w_w = velRadial1[0,:]
1286 w_w = velRadial1[0,:]
1287 w_e = velRadial1[1,:]
1287 w_e = velRadial1[1,:]
1288
1288
1289 w = (w_w*numpy.sin(bet) - w_e*numpy.sin(alp))/(numpy.cos(alp)*numpy.sin(bet) - numpy.cos(bet)*numpy.sin(alp))
1289 w = (w_w*numpy.sin(bet) - w_e*numpy.sin(alp))/(numpy.cos(alp)*numpy.sin(bet) - numpy.cos(bet)*numpy.sin(alp))
1290 u = (w_w*numpy.cos(bet) - w_e*numpy.cos(alp))/(numpy.sin(alp)*numpy.cos(bet) - numpy.sin(bet)*numpy.cos(alp))
1290 u = (w_w*numpy.cos(bet) - w_e*numpy.cos(alp))/(numpy.sin(alp)*numpy.cos(bet) - numpy.sin(bet)*numpy.cos(alp))
1291
1291
1292 winds = numpy.vstack((u,w))
1292 winds = numpy.vstack((u,w))
1293
1293
1294 dataOut.heightList = heiRang1
1294 dataOut.heightList = heiRang1
1295 dataOut.data_output = winds
1295 dataOut.data_output = winds
1296 dataOut.data_SNR = SNR1
1296 dataOut.data_SNR = SNR1
1297
1297
1298 dataOut.utctimeInit = dataOut.utctime
1298 dataOut.utctimeInit = dataOut.utctime
1299 dataOut.outputInterval = dataOut.timeInterval
1299 dataOut.outputInterval = dataOut.timeInterval
1300 return
1300 return
1301
1301
1302 #--------------- Non Specular Meteor ----------------
1302 #--------------- Non Specular Meteor ----------------
1303
1303
1304 class NonSpecularMeteorDetection(Operation):
1304 class NonSpecularMeteorDetection(Operation):
1305
1305
1306 def run(self, dataOut, mode, SNRthresh=8, phaseDerThresh=0.5, cohThresh=0.8, allData = False):
1306 def run(self, dataOut, mode, SNRthresh=8, phaseDerThresh=0.5, cohThresh=0.8, allData = False):
1307 data_acf = dataOut.data_pre[0]
1307 data_acf = dataOut.data_pre[0]
1308 data_ccf = dataOut.data_pre[1]
1308 data_ccf = dataOut.data_pre[1]
1309 pairsList = dataOut.groupList[1]
1309 pairsList = dataOut.groupList[1]
1310
1310
1311 lamb = dataOut.C/dataOut.frequency
1311 lamb = dataOut.C/dataOut.frequency
1312 tSamp = dataOut.ippSeconds*dataOut.nCohInt
1312 tSamp = dataOut.ippSeconds*dataOut.nCohInt
1313 paramInterval = dataOut.paramInterval
1313 paramInterval = dataOut.paramInterval
1314
1314
1315 nChannels = data_acf.shape[0]
1315 nChannels = data_acf.shape[0]
1316 nLags = data_acf.shape[1]
1316 nLags = data_acf.shape[1]
1317 nProfiles = data_acf.shape[2]
1317 nProfiles = data_acf.shape[2]
1318 nHeights = dataOut.nHeights
1318 nHeights = dataOut.nHeights
1319 nCohInt = dataOut.nCohInt
1319 nCohInt = dataOut.nCohInt
1320 sec = numpy.round(nProfiles/dataOut.paramInterval)
1320 sec = numpy.round(nProfiles/dataOut.paramInterval)
1321 heightList = dataOut.heightList
1321 heightList = dataOut.heightList
1322 ippSeconds = dataOut.ippSeconds*dataOut.nCohInt*dataOut.nAvg
1322 ippSeconds = dataOut.ippSeconds*dataOut.nCohInt*dataOut.nAvg
1323 utctime = dataOut.utctime
1323 utctime = dataOut.utctime
1324
1324
1325 dataOut.abscissaList = numpy.arange(0,paramInterval+ippSeconds,ippSeconds)
1325 dataOut.abscissaList = numpy.arange(0,paramInterval+ippSeconds,ippSeconds)
1326
1326
1327 #------------------------ SNR --------------------------------------
1327 #------------------------ SNR --------------------------------------
1328 power = data_acf[:,0,:,:].real
1328 power = data_acf[:,0,:,:].real
1329 noise = numpy.zeros(nChannels)
1329 noise = numpy.zeros(nChannels)
1330 SNR = numpy.zeros(power.shape)
1330 SNR = numpy.zeros(power.shape)
1331 for i in range(nChannels):
1331 for i in range(nChannels):
1332 noise[i] = hildebrand_sekhon(power[i,:], nCohInt)
1332 noise[i] = hildebrand_sekhon(power[i,:], nCohInt)
1333 SNR[i] = (power[i]-noise[i])/noise[i]
1333 SNR[i] = (power[i]-noise[i])/noise[i]
1334 SNRm = numpy.nanmean(SNR, axis = 0)
1334 SNRm = numpy.nanmean(SNR, axis = 0)
1335 SNRdB = 10*numpy.log10(SNR)
1335 SNRdB = 10*numpy.log10(SNR)
1336
1336
1337 if mode == 'SA':
1337 if mode == 'SA':
1338 dataOut.groupList = dataOut.groupList[1]
1338 dataOut.groupList = dataOut.groupList[1]
1339 nPairs = data_ccf.shape[0]
1339 nPairs = data_ccf.shape[0]
1340 #---------------------- Coherence and Phase --------------------------
1340 #---------------------- Coherence and Phase --------------------------
1341 phase = numpy.zeros(data_ccf[:,0,:,:].shape)
1341 phase = numpy.zeros(data_ccf[:,0,:,:].shape)
1342 # phase1 = numpy.copy(phase)
1342 # phase1 = numpy.copy(phase)
1343 coh1 = numpy.zeros(data_ccf[:,0,:,:].shape)
1343 coh1 = numpy.zeros(data_ccf[:,0,:,:].shape)
1344
1344
1345 for p in range(nPairs):
1345 for p in range(nPairs):
1346 ch0 = pairsList[p][0]
1346 ch0 = pairsList[p][0]
1347 ch1 = pairsList[p][1]
1347 ch1 = pairsList[p][1]
1348 ccf = data_ccf[p,0,:,:]/numpy.sqrt(data_acf[ch0,0,:,:]*data_acf[ch1,0,:,:])
1348 ccf = data_ccf[p,0,:,:]/numpy.sqrt(data_acf[ch0,0,:,:]*data_acf[ch1,0,:,:])
1349 phase[p,:,:] = ndimage.median_filter(numpy.angle(ccf), size = (5,1)) #median filter
1349 phase[p,:,:] = ndimage.median_filter(numpy.angle(ccf), size = (5,1)) #median filter
1350 # phase1[p,:,:] = numpy.angle(ccf) #median filter
1350 # phase1[p,:,:] = numpy.angle(ccf) #median filter
1351 coh1[p,:,:] = ndimage.median_filter(numpy.abs(ccf), 5) #median filter
1351 coh1[p,:,:] = ndimage.median_filter(numpy.abs(ccf), 5) #median filter
1352 # coh1[p,:,:] = numpy.abs(ccf) #median filter
1352 # coh1[p,:,:] = numpy.abs(ccf) #median filter
1353 coh = numpy.nanmax(coh1, axis = 0)
1353 coh = numpy.nanmax(coh1, axis = 0)
1354 # struc = numpy.ones((5,1))
1354 # struc = numpy.ones((5,1))
1355 # coh = ndimage.morphology.grey_dilation(coh, size=(10,1))
1355 # coh = ndimage.morphology.grey_dilation(coh, size=(10,1))
1356 #---------------------- Radial Velocity ----------------------------
1356 #---------------------- Radial Velocity ----------------------------
1357 phaseAux = numpy.mean(numpy.angle(data_acf[:,1,:,:]), axis = 0)
1357 phaseAux = numpy.mean(numpy.angle(data_acf[:,1,:,:]), axis = 0)
1358 velRad = phaseAux*lamb/(4*numpy.pi*tSamp)
1358 velRad = phaseAux*lamb/(4*numpy.pi*tSamp)
1359
1359
1360 if allData:
1360 if allData:
1361 boolMetFin = ~numpy.isnan(SNRm)
1361 boolMetFin = ~numpy.isnan(SNRm)
1362 # coh[:-1,:] = numpy.nanmean(numpy.abs(phase[:,1:,:] - phase[:,:-1,:]),axis=0)
1362 # coh[:-1,:] = numpy.nanmean(numpy.abs(phase[:,1:,:] - phase[:,:-1,:]),axis=0)
1363 else:
1363 else:
1364 #------------------------ Meteor mask ---------------------------------
1364 #------------------------ Meteor mask ---------------------------------
1365 # #SNR mask
1365 # #SNR mask
1366 # boolMet = (SNRdB>SNRthresh)#|(~numpy.isnan(SNRdB))
1366 # boolMet = (SNRdB>SNRthresh)#|(~numpy.isnan(SNRdB))
1367 #
1367 #
1368 # #Erase small objects
1368 # #Erase small objects
1369 # boolMet1 = self.__erase_small(boolMet, 2*sec, 5)
1369 # boolMet1 = self.__erase_small(boolMet, 2*sec, 5)
1370 #
1370 #
1371 # auxEEJ = numpy.sum(boolMet1,axis=0)
1371 # auxEEJ = numpy.sum(boolMet1,axis=0)
1372 # indOver = auxEEJ>nProfiles*0.8 #Use this later
1372 # indOver = auxEEJ>nProfiles*0.8 #Use this later
1373 # indEEJ = numpy.where(indOver)[0]
1373 # indEEJ = numpy.where(indOver)[0]
1374 # indNEEJ = numpy.where(~indOver)[0]
1374 # indNEEJ = numpy.where(~indOver)[0]
1375 #
1375 #
1376 # boolMetFin = boolMet1
1376 # boolMetFin = boolMet1
1377 #
1377 #
1378 # if indEEJ.size > 0:
1378 # if indEEJ.size > 0:
1379 # boolMet1[:,indEEJ] = False #Erase heights with EEJ
1379 # boolMet1[:,indEEJ] = False #Erase heights with EEJ
1380 #
1380 #
1381 # boolMet2 = coh > cohThresh
1381 # boolMet2 = coh > cohThresh
1382 # boolMet2 = self.__erase_small(boolMet2, 2*sec,5)
1382 # boolMet2 = self.__erase_small(boolMet2, 2*sec,5)
1383 #
1383 #
1384 # #Final Meteor mask
1384 # #Final Meteor mask
1385 # boolMetFin = boolMet1|boolMet2
1385 # boolMetFin = boolMet1|boolMet2
1386
1386
1387 #Coherence mask
1387 #Coherence mask
1388 boolMet1 = coh > 0.75
1388 boolMet1 = coh > 0.75
1389 struc = numpy.ones((30,1))
1389 struc = numpy.ones((30,1))
1390 boolMet1 = ndimage.morphology.binary_dilation(boolMet1, structure=struc)
1390 boolMet1 = ndimage.morphology.binary_dilation(boolMet1, structure=struc)
1391
1391
1392 #Derivative mask
1392 #Derivative mask
1393 derPhase = numpy.nanmean(numpy.abs(phase[:,1:,:] - phase[:,:-1,:]),axis=0)
1393 derPhase = numpy.nanmean(numpy.abs(phase[:,1:,:] - phase[:,:-1,:]),axis=0)
1394 boolMet2 = derPhase < 0.2
1394 boolMet2 = derPhase < 0.2
1395 # boolMet2 = ndimage.morphology.binary_opening(boolMet2)
1395 # boolMet2 = ndimage.morphology.binary_opening(boolMet2)
1396 # boolMet2 = ndimage.morphology.binary_closing(boolMet2, structure = numpy.ones((10,1)))
1396 # boolMet2 = ndimage.morphology.binary_closing(boolMet2, structure = numpy.ones((10,1)))
1397 boolMet2 = ndimage.median_filter(boolMet2,size=5)
1397 boolMet2 = ndimage.median_filter(boolMet2,size=5)
1398 boolMet2 = numpy.vstack((boolMet2,numpy.full((1,nHeights), True, dtype=bool)))
1398 boolMet2 = numpy.vstack((boolMet2,numpy.full((1,nHeights), True, dtype=bool)))
1399 # #Final mask
1399 # #Final mask
1400 # boolMetFin = boolMet2
1400 # boolMetFin = boolMet2
1401 boolMetFin = boolMet1&boolMet2
1401 boolMetFin = boolMet1&boolMet2
1402 # boolMetFin = ndimage.morphology.binary_dilation(boolMetFin)
1402 # boolMetFin = ndimage.morphology.binary_dilation(boolMetFin)
1403 #Creating data_param
1403 #Creating data_param
1404 coordMet = numpy.where(boolMetFin)
1404 coordMet = numpy.where(boolMetFin)
1405
1405
1406 tmet = coordMet[0]
1406 tmet = coordMet[0]
1407 hmet = coordMet[1]
1407 hmet = coordMet[1]
1408
1408
1409 data_param = numpy.zeros((tmet.size, 6 + nPairs))
1409 data_param = numpy.zeros((tmet.size, 6 + nPairs))
1410 data_param[:,0] = utctime
1410 data_param[:,0] = utctime
1411 data_param[:,1] = tmet
1411 data_param[:,1] = tmet
1412 data_param[:,2] = hmet
1412 data_param[:,2] = hmet
1413 data_param[:,3] = SNRm[tmet,hmet]
1413 data_param[:,3] = SNRm[tmet,hmet]
1414 data_param[:,4] = velRad[tmet,hmet]
1414 data_param[:,4] = velRad[tmet,hmet]
1415 data_param[:,5] = coh[tmet,hmet]
1415 data_param[:,5] = coh[tmet,hmet]
1416 data_param[:,6:] = phase[:,tmet,hmet].T
1416 data_param[:,6:] = phase[:,tmet,hmet].T
1417
1417
1418 elif mode == 'DBS':
1418 elif mode == 'DBS':
1419 dataOut.groupList = numpy.arange(nChannels)
1419 dataOut.groupList = numpy.arange(nChannels)
1420
1420
1421 #Radial Velocities
1421 #Radial Velocities
1422 phase = numpy.angle(data_acf[:,1,:,:])
1422 phase = numpy.angle(data_acf[:,1,:,:])
1423 # phase = ndimage.median_filter(numpy.angle(data_acf[:,1,:,:]), size = (1,5,1))
1423 # phase = ndimage.median_filter(numpy.angle(data_acf[:,1,:,:]), size = (1,5,1))
1424 velRad = phase*lamb/(4*numpy.pi*tSamp)
1424 velRad = phase*lamb/(4*numpy.pi*tSamp)
1425
1425
1426 #Spectral width
1426 #Spectral width
1427 # acf1 = ndimage.median_filter(numpy.abs(data_acf[:,1,:,:]), size = (1,5,1))
1427 # acf1 = ndimage.median_filter(numpy.abs(data_acf[:,1,:,:]), size = (1,5,1))
1428 # acf2 = ndimage.median_filter(numpy.abs(data_acf[:,2,:,:]), size = (1,5,1))
1428 # acf2 = ndimage.median_filter(numpy.abs(data_acf[:,2,:,:]), size = (1,5,1))
1429 acf1 = data_acf[:,1,:,:]
1429 acf1 = data_acf[:,1,:,:]
1430 acf2 = data_acf[:,2,:,:]
1430 acf2 = data_acf[:,2,:,:]
1431
1431
1432 spcWidth = (lamb/(2*numpy.sqrt(6)*numpy.pi*tSamp))*numpy.sqrt(numpy.log(acf1/acf2))
1432 spcWidth = (lamb/(2*numpy.sqrt(6)*numpy.pi*tSamp))*numpy.sqrt(numpy.log(acf1/acf2))
1433 # velRad = ndimage.median_filter(velRad, size = (1,5,1))
1433 # velRad = ndimage.median_filter(velRad, size = (1,5,1))
1434 if allData:
1434 if allData:
1435 boolMetFin = ~numpy.isnan(SNRdB)
1435 boolMetFin = ~numpy.isnan(SNRdB)
1436 else:
1436 else:
1437 #SNR
1437 #SNR
1438 boolMet1 = (SNRdB>SNRthresh) #SNR mask
1438 boolMet1 = (SNRdB>SNRthresh) #SNR mask
1439 boolMet1 = ndimage.median_filter(boolMet1, size=(1,5,5))
1439 boolMet1 = ndimage.median_filter(boolMet1, size=(1,5,5))
1440
1440
1441 #Radial velocity
1441 #Radial velocity
1442 boolMet2 = numpy.abs(velRad) < 20
1442 boolMet2 = numpy.abs(velRad) < 20
1443 boolMet2 = ndimage.median_filter(boolMet2, (1,5,5))
1443 boolMet2 = ndimage.median_filter(boolMet2, (1,5,5))
1444
1444
1445 #Spectral Width
1445 #Spectral Width
1446 boolMet3 = spcWidth < 30
1446 boolMet3 = spcWidth < 30
1447 boolMet3 = ndimage.median_filter(boolMet3, (1,5,5))
1447 boolMet3 = ndimage.median_filter(boolMet3, (1,5,5))
1448 # boolMetFin = self.__erase_small(boolMet1, 10,5)
1448 # boolMetFin = self.__erase_small(boolMet1, 10,5)
1449 boolMetFin = boolMet1&boolMet2&boolMet3
1449 boolMetFin = boolMet1&boolMet2&boolMet3
1450
1450
1451 #Creating data_param
1451 #Creating data_param
1452 coordMet = numpy.where(boolMetFin)
1452 coordMet = numpy.where(boolMetFin)
1453
1453
1454 cmet = coordMet[0]
1454 cmet = coordMet[0]
1455 tmet = coordMet[1]
1455 tmet = coordMet[1]
1456 hmet = coordMet[2]
1456 hmet = coordMet[2]
1457
1457
1458 data_param = numpy.zeros((tmet.size, 7))
1458 data_param = numpy.zeros((tmet.size, 7))
1459 data_param[:,0] = utctime
1459 data_param[:,0] = utctime
1460 data_param[:,1] = cmet
1460 data_param[:,1] = cmet
1461 data_param[:,2] = tmet
1461 data_param[:,2] = tmet
1462 data_param[:,3] = hmet
1462 data_param[:,3] = hmet
1463 data_param[:,4] = SNR[cmet,tmet,hmet].T
1463 data_param[:,4] = SNR[cmet,tmet,hmet].T
1464 data_param[:,5] = velRad[cmet,tmet,hmet].T
1464 data_param[:,5] = velRad[cmet,tmet,hmet].T
1465 data_param[:,6] = spcWidth[cmet,tmet,hmet].T
1465 data_param[:,6] = spcWidth[cmet,tmet,hmet].T
1466
1466
1467 # self.dataOut.data_param = data_int
1467 # self.dataOut.data_param = data_int
1468 if len(data_param) == 0:
1468 if len(data_param) == 0:
1469 dataOut.flagNoData = True
1469 dataOut.flagNoData = True
1470 else:
1470 else:
1471 dataOut.data_param = data_param
1471 dataOut.data_param = data_param
1472
1472
1473 def __erase_small(self, binArray, threshX, threshY):
1473 def __erase_small(self, binArray, threshX, threshY):
1474 labarray, numfeat = ndimage.measurements.label(binArray)
1474 labarray, numfeat = ndimage.measurements.label(binArray)
1475 binArray1 = numpy.copy(binArray)
1475 binArray1 = numpy.copy(binArray)
1476
1476
1477 for i in range(1,numfeat + 1):
1477 for i in range(1,numfeat + 1):
1478 auxBin = (labarray==i)
1478 auxBin = (labarray==i)
1479 auxSize = auxBin.sum()
1479 auxSize = auxBin.sum()
1480
1480
1481 x,y = numpy.where(auxBin)
1481 x,y = numpy.where(auxBin)
1482 widthX = x.max() - x.min()
1482 widthX = x.max() - x.min()
1483 widthY = y.max() - y.min()
1483 widthY = y.max() - y.min()
1484
1484
1485 #width X: 3 seg -> 12.5*3
1485 #width X: 3 seg -> 12.5*3
1486 #width Y:
1486 #width Y:
1487
1487
1488 if (auxSize < 50) or (widthX < threshX) or (widthY < threshY):
1488 if (auxSize < 50) or (widthX < threshX) or (widthY < threshY):
1489 binArray1[auxBin] = False
1489 binArray1[auxBin] = False
1490
1490
1491 return binArray1
1491 return binArray1
1492
1492
1493 #--------------- Specular Meteor ----------------
1493 #--------------- Specular Meteor ----------------
1494
1494
1495 class SMDetection(Operation):
1495 class SMDetection(Operation):
1496 '''
1496 '''
1497 Function DetectMeteors()
1497 Function DetectMeteors()
1498 Project developed with paper:
1498 Project developed with paper:
1499 HOLDSWORTH ET AL. 2004
1499 HOLDSWORTH ET AL. 2004
1500
1500
1501 Input:
1501 Input:
1502 self.dataOut.data_pre
1502 self.dataOut.data_pre
1503
1503
1504 centerReceiverIndex: From the channels, which is the center receiver
1504 centerReceiverIndex: From the channels, which is the center receiver
1505
1505
1506 hei_ref: Height reference for the Beacon signal extraction
1506 hei_ref: Height reference for the Beacon signal extraction
1507 tauindex:
1507 tauindex:
1508 predefinedPhaseShifts: Predefined phase offset for the voltge signals
1508 predefinedPhaseShifts: Predefined phase offset for the voltge signals
1509
1509
1510 cohDetection: Whether to user Coherent detection or not
1510 cohDetection: Whether to user Coherent detection or not
1511 cohDet_timeStep: Coherent Detection calculation time step
1511 cohDet_timeStep: Coherent Detection calculation time step
1512 cohDet_thresh: Coherent Detection phase threshold to correct phases
1512 cohDet_thresh: Coherent Detection phase threshold to correct phases
1513
1513
1514 noise_timeStep: Noise calculation time step
1514 noise_timeStep: Noise calculation time step
1515 noise_multiple: Noise multiple to define signal threshold
1515 noise_multiple: Noise multiple to define signal threshold
1516
1516
1517 multDet_timeLimit: Multiple Detection Removal time limit in seconds
1517 multDet_timeLimit: Multiple Detection Removal time limit in seconds
1518 multDet_rangeLimit: Multiple Detection Removal range limit in km
1518 multDet_rangeLimit: Multiple Detection Removal range limit in km
1519
1519
1520 phaseThresh: Maximum phase difference between receiver to be consider a meteor
1520 phaseThresh: Maximum phase difference between receiver to be consider a meteor
1521 SNRThresh: Minimum SNR threshold of the meteor signal to be consider a meteor
1521 SNRThresh: Minimum SNR threshold of the meteor signal to be consider a meteor
1522
1522
1523 hmin: Minimum Height of the meteor to use it in the further wind estimations
1523 hmin: Minimum Height of the meteor to use it in the further wind estimations
1524 hmax: Maximum Height of the meteor to use it in the further wind estimations
1524 hmax: Maximum Height of the meteor to use it in the further wind estimations
1525 azimuth: Azimuth angle correction
1525 azimuth: Azimuth angle correction
1526
1526
1527 Affected:
1527 Affected:
1528 self.dataOut.data_param
1528 self.dataOut.data_param
1529
1529
1530 Rejection Criteria (Errors):
1530 Rejection Criteria (Errors):
1531 0: No error; analysis OK
1531 0: No error; analysis OK
1532 1: SNR < SNR threshold
1532 1: SNR < SNR threshold
1533 2: angle of arrival (AOA) ambiguously determined
1533 2: angle of arrival (AOA) ambiguously determined
1534 3: AOA estimate not feasible
1534 3: AOA estimate not feasible
1535 4: Large difference in AOAs obtained from different antenna baselines
1535 4: Large difference in AOAs obtained from different antenna baselines
1536 5: echo at start or end of time series
1536 5: echo at start or end of time series
1537 6: echo less than 5 examples long; too short for analysis
1537 6: echo less than 5 examples long; too short for analysis
1538 7: echo rise exceeds 0.3s
1538 7: echo rise exceeds 0.3s
1539 8: echo decay time less than twice rise time
1539 8: echo decay time less than twice rise time
1540 9: large power level before echo
1540 9: large power level before echo
1541 10: large power level after echo
1541 10: large power level after echo
1542 11: poor fit to amplitude for estimation of decay time
1542 11: poor fit to amplitude for estimation of decay time
1543 12: poor fit to CCF phase variation for estimation of radial drift velocity
1543 12: poor fit to CCF phase variation for estimation of radial drift velocity
1544 13: height unresolvable echo: not valid height within 70 to 110 km
1544 13: height unresolvable echo: not valid height within 70 to 110 km
1545 14: height ambiguous echo: more then one possible height within 70 to 110 km
1545 14: height ambiguous echo: more then one possible height within 70 to 110 km
1546 15: radial drift velocity or projected horizontal velocity exceeds 200 m/s
1546 15: radial drift velocity or projected horizontal velocity exceeds 200 m/s
1547 16: oscilatory echo, indicating event most likely not an underdense echo
1547 16: oscilatory echo, indicating event most likely not an underdense echo
1548
1548
1549 17: phase difference in meteor Reestimation
1549 17: phase difference in meteor Reestimation
1550
1550
1551 Data Storage:
1551 Data Storage:
1552 Meteors for Wind Estimation (8):
1552 Meteors for Wind Estimation (8):
1553 Utc Time | Range Height
1553 Utc Time | Range Height
1554 Azimuth Zenith errorCosDir
1554 Azimuth Zenith errorCosDir
1555 VelRad errorVelRad
1555 VelRad errorVelRad
1556 Phase0 Phase1 Phase2 Phase3
1556 Phase0 Phase1 Phase2 Phase3
1557 TypeError
1557 TypeError
1558
1558
1559 '''
1559 '''
1560
1560
1561 def run(self, dataOut, hei_ref = None, tauindex = 0,
1561 def run(self, dataOut, hei_ref = None, tauindex = 0,
1562 phaseOffsets = None,
1562 phaseOffsets = None,
1563 cohDetection = False, cohDet_timeStep = 1, cohDet_thresh = 25,
1563 cohDetection = False, cohDet_timeStep = 1, cohDet_thresh = 25,
1564 noise_timeStep = 4, noise_multiple = 4,
1564 noise_timeStep = 4, noise_multiple = 4,
1565 multDet_timeLimit = 1, multDet_rangeLimit = 3,
1565 multDet_timeLimit = 1, multDet_rangeLimit = 3,
1566 phaseThresh = 20, SNRThresh = 5,
1566 phaseThresh = 20, SNRThresh = 5,
1567 hmin = 50, hmax=150, azimuth = 0,
1567 hmin = 50, hmax=150, azimuth = 0,
1568 channelPositions = None) :
1568 channelPositions = None) :
1569
1569
1570
1570
1571 #Getting Pairslist
1571 #Getting Pairslist
1572 if channelPositions is None:
1572 if channelPositions is None:
1573 # channelPositions = [(2.5,0), (0,2.5), (0,0), (0,4.5), (-2,0)] #T
1573 # channelPositions = [(2.5,0), (0,2.5), (0,0), (0,4.5), (-2,0)] #T
1574 channelPositions = [(4.5,2), (2,4.5), (2,2), (2,0), (0,2)] #Estrella
1574 channelPositions = [(4.5,2), (2,4.5), (2,2), (2,0), (0,2)] #Estrella
1575 meteorOps = SMOperations()
1575 meteorOps = SMOperations()
1576 pairslist0, distances = meteorOps.getPhasePairs(channelPositions)
1576 pairslist0, distances = meteorOps.getPhasePairs(channelPositions)
1577 heiRang = dataOut.getHeiRange()
1577 heiRang = dataOut.getHeiRange()
1578 #Get Beacon signal - No Beacon signal anymore
1578 #Get Beacon signal - No Beacon signal anymore
1579 # newheis = numpy.where(self.dataOut.heightList>self.dataOut.radarControllerHeaderObj.Taus[tauindex])
1579 # newheis = numpy.where(self.dataOut.heightList>self.dataOut.radarControllerHeaderObj.Taus[tauindex])
1580 #
1580 #
1581 # if hei_ref != None:
1581 # if hei_ref != None:
1582 # newheis = numpy.where(self.dataOut.heightList>hei_ref)
1582 # newheis = numpy.where(self.dataOut.heightList>hei_ref)
1583 #
1583 #
1584
1584
1585
1585
1586 #****************REMOVING HARDWARE PHASE DIFFERENCES***************
1586 #****************REMOVING HARDWARE PHASE DIFFERENCES***************
1587 # see if the user put in pre defined phase shifts
1587 # see if the user put in pre defined phase shifts
1588 voltsPShift = dataOut.data_pre.copy()
1588 voltsPShift = dataOut.data_pre.copy()
1589
1589
1590 # if predefinedPhaseShifts != None:
1590 # if predefinedPhaseShifts != None:
1591 # hardwarePhaseShifts = numpy.array(predefinedPhaseShifts)*numpy.pi/180
1591 # hardwarePhaseShifts = numpy.array(predefinedPhaseShifts)*numpy.pi/180
1592 #
1592 #
1593 # # elif beaconPhaseShifts:
1593 # # elif beaconPhaseShifts:
1594 # # #get hardware phase shifts using beacon signal
1594 # # #get hardware phase shifts using beacon signal
1595 # # hardwarePhaseShifts = self.__getHardwarePhaseDiff(self.dataOut.data_pre, pairslist, newheis, 10)
1595 # # hardwarePhaseShifts = self.__getHardwarePhaseDiff(self.dataOut.data_pre, pairslist, newheis, 10)
1596 # # hardwarePhaseShifts = numpy.insert(hardwarePhaseShifts,centerReceiverIndex,0)
1596 # # hardwarePhaseShifts = numpy.insert(hardwarePhaseShifts,centerReceiverIndex,0)
1597 #
1597 #
1598 # else:
1598 # else:
1599 # hardwarePhaseShifts = numpy.zeros(5)
1599 # hardwarePhaseShifts = numpy.zeros(5)
1600 #
1600 #
1601 # voltsPShift = numpy.zeros((self.dataOut.data_pre.shape[0],self.dataOut.data_pre.shape[1],self.dataOut.data_pre.shape[2]), dtype = 'complex')
1601 # voltsPShift = numpy.zeros((self.dataOut.data_pre.shape[0],self.dataOut.data_pre.shape[1],self.dataOut.data_pre.shape[2]), dtype = 'complex')
1602 # for i in range(self.dataOut.data_pre.shape[0]):
1602 # for i in range(self.dataOut.data_pre.shape[0]):
1603 # voltsPShift[i,:,:] = self.__shiftPhase(self.dataOut.data_pre[i,:,:], hardwarePhaseShifts[i])
1603 # voltsPShift[i,:,:] = self.__shiftPhase(self.dataOut.data_pre[i,:,:], hardwarePhaseShifts[i])
1604
1604
1605 #******************END OF REMOVING HARDWARE PHASE DIFFERENCES*********
1605 #******************END OF REMOVING HARDWARE PHASE DIFFERENCES*********
1606
1606
1607 #Remove DC
1607 #Remove DC
1608 voltsDC = numpy.mean(voltsPShift,1)
1608 voltsDC = numpy.mean(voltsPShift,1)
1609 voltsDC = numpy.mean(voltsDC,1)
1609 voltsDC = numpy.mean(voltsDC,1)
1610 for i in range(voltsDC.shape[0]):
1610 for i in range(voltsDC.shape[0]):
1611 voltsPShift[i] = voltsPShift[i] - voltsDC[i]
1611 voltsPShift[i] = voltsPShift[i] - voltsDC[i]
1612
1612
1613 #Don't considerate last heights, theyre used to calculate Hardware Phase Shift
1613 #Don't considerate last heights, theyre used to calculate Hardware Phase Shift
1614 # voltsPShift = voltsPShift[:,:,:newheis[0][0]]
1614 # voltsPShift = voltsPShift[:,:,:newheis[0][0]]
1615
1615
1616 #************ FIND POWER OF DATA W/COH OR NON COH DETECTION (3.4) **********
1616 #************ FIND POWER OF DATA W/COH OR NON COH DETECTION (3.4) **********
1617 #Coherent Detection
1617 #Coherent Detection
1618 if cohDetection:
1618 if cohDetection:
1619 #use coherent detection to get the net power
1619 #use coherent detection to get the net power
1620 cohDet_thresh = cohDet_thresh*numpy.pi/180
1620 cohDet_thresh = cohDet_thresh*numpy.pi/180
1621 voltsPShift = self.__coherentDetection(voltsPShift, cohDet_timeStep, dataOut.timeInterval, pairslist0, cohDet_thresh)
1621 voltsPShift = self.__coherentDetection(voltsPShift, cohDet_timeStep, dataOut.timeInterval, pairslist0, cohDet_thresh)
1622
1622
1623 #Non-coherent detection!
1623 #Non-coherent detection!
1624 powerNet = numpy.nansum(numpy.abs(voltsPShift[:,:,:])**2,0)
1624 powerNet = numpy.nansum(numpy.abs(voltsPShift[:,:,:])**2,0)
1625 #********** END OF COH/NON-COH POWER CALCULATION**********************
1625 #********** END OF COH/NON-COH POWER CALCULATION**********************
1626
1626
1627 #********** FIND THE NOISE LEVEL AND POSSIBLE METEORS ****************
1627 #********** FIND THE NOISE LEVEL AND POSSIBLE METEORS ****************
1628 #Get noise
1628 #Get noise
1629 noise, noise1 = self.__getNoise(powerNet, noise_timeStep, dataOut.timeInterval)
1629 noise, noise1 = self.__getNoise(powerNet, noise_timeStep, dataOut.timeInterval)
1630 # noise = self.getNoise1(powerNet, noise_timeStep, self.dataOut.timeInterval)
1630 # noise = self.getNoise1(powerNet, noise_timeStep, self.dataOut.timeInterval)
1631 #Get signal threshold
1631 #Get signal threshold
1632 signalThresh = noise_multiple*noise
1632 signalThresh = noise_multiple*noise
1633 #Meteor echoes detection
1633 #Meteor echoes detection
1634 listMeteors = self.__findMeteors(powerNet, signalThresh)
1634 listMeteors = self.__findMeteors(powerNet, signalThresh)
1635 #******* END OF NOISE LEVEL AND POSSIBLE METEORS CACULATION **********
1635 #******* END OF NOISE LEVEL AND POSSIBLE METEORS CACULATION **********
1636
1636
1637 #************** REMOVE MULTIPLE DETECTIONS (3.5) ***************************
1637 #************** REMOVE MULTIPLE DETECTIONS (3.5) ***************************
1638 #Parameters
1638 #Parameters
1639 heiRange = dataOut.getHeiRange()
1639 heiRange = dataOut.getHeiRange()
1640 rangeInterval = heiRange[1] - heiRange[0]
1640 rangeInterval = heiRange[1] - heiRange[0]
1641 rangeLimit = multDet_rangeLimit/rangeInterval
1641 rangeLimit = multDet_rangeLimit/rangeInterval
1642 timeLimit = multDet_timeLimit/dataOut.timeInterval
1642 timeLimit = multDet_timeLimit/dataOut.timeInterval
1643 #Multiple detection removals
1643 #Multiple detection removals
1644 listMeteors1 = self.__removeMultipleDetections(listMeteors, rangeLimit, timeLimit)
1644 listMeteors1 = self.__removeMultipleDetections(listMeteors, rangeLimit, timeLimit)
1645 #************ END OF REMOVE MULTIPLE DETECTIONS **********************
1645 #************ END OF REMOVE MULTIPLE DETECTIONS **********************
1646
1646
1647 #********************* METEOR REESTIMATION (3.7, 3.8, 3.9, 3.10) ********************
1647 #********************* METEOR REESTIMATION (3.7, 3.8, 3.9, 3.10) ********************
1648 #Parameters
1648 #Parameters
1649 phaseThresh = phaseThresh*numpy.pi/180
1649 phaseThresh = phaseThresh*numpy.pi/180
1650 thresh = [phaseThresh, noise_multiple, SNRThresh]
1650 thresh = [phaseThresh, noise_multiple, SNRThresh]
1651 #Meteor reestimation (Errors N 1, 6, 12, 17)
1651 #Meteor reestimation (Errors N 1, 6, 12, 17)
1652 listMeteors2, listMeteorsPower, listMeteorsVolts = self.__meteorReestimation(listMeteors1, voltsPShift, pairslist0, thresh, noise, dataOut.timeInterval, dataOut.frequency)
1652 listMeteors2, listMeteorsPower, listMeteorsVolts = self.__meteorReestimation(listMeteors1, voltsPShift, pairslist0, thresh, noise, dataOut.timeInterval, dataOut.frequency)
1653 # listMeteors2, listMeteorsPower, listMeteorsVolts = self.meteorReestimation3(listMeteors2, listMeteorsPower, listMeteorsVolts, voltsPShift, pairslist, thresh, noise)
1653 # listMeteors2, listMeteorsPower, listMeteorsVolts = self.meteorReestimation3(listMeteors2, listMeteorsPower, listMeteorsVolts, voltsPShift, pairslist, thresh, noise)
1654 #Estimation of decay times (Errors N 7, 8, 11)
1654 #Estimation of decay times (Errors N 7, 8, 11)
1655 listMeteors3 = self.__estimateDecayTime(listMeteors2, listMeteorsPower, dataOut.timeInterval, dataOut.frequency)
1655 listMeteors3 = self.__estimateDecayTime(listMeteors2, listMeteorsPower, dataOut.timeInterval, dataOut.frequency)
1656 #******************* END OF METEOR REESTIMATION *******************
1656 #******************* END OF METEOR REESTIMATION *******************
1657
1657
1658 #********************* METEOR PARAMETERS CALCULATION (3.11, 3.12, 3.13) **************************
1658 #********************* METEOR PARAMETERS CALCULATION (3.11, 3.12, 3.13) **************************
1659 #Calculating Radial Velocity (Error N 15)
1659 #Calculating Radial Velocity (Error N 15)
1660 radialStdThresh = 10
1660 radialStdThresh = 10
1661 listMeteors4 = self.__getRadialVelocity(listMeteors3, listMeteorsVolts, radialStdThresh, pairslist0, dataOut.timeInterval)
1661 listMeteors4 = self.__getRadialVelocity(listMeteors3, listMeteorsVolts, radialStdThresh, pairslist0, dataOut.timeInterval)
1662
1662
1663 if len(listMeteors4) > 0:
1663 if len(listMeteors4) > 0:
1664 #Setting New Array
1664 #Setting New Array
1665 date = dataOut.utctime
1665 date = dataOut.utctime
1666 arrayParameters = self.__setNewArrays(listMeteors4, date, heiRang)
1666 arrayParameters = self.__setNewArrays(listMeteors4, date, heiRang)
1667
1667
1668 #Correcting phase offset
1668 #Correcting phase offset
1669 if phaseOffsets != None:
1669 if phaseOffsets != None:
1670 phaseOffsets = numpy.array(phaseOffsets)*numpy.pi/180
1670 phaseOffsets = numpy.array(phaseOffsets)*numpy.pi/180
1671 arrayParameters[:,8:12] = numpy.unwrap(arrayParameters[:,8:12] + phaseOffsets)
1671 arrayParameters[:,8:12] = numpy.unwrap(arrayParameters[:,8:12] + phaseOffsets)
1672
1672
1673 #Second Pairslist
1673 #Second Pairslist
1674 pairsList = []
1674 pairsList = []
1675 pairx = (0,1)
1675 pairx = (0,1)
1676 pairy = (2,3)
1676 pairy = (2,3)
1677 pairsList.append(pairx)
1677 pairsList.append(pairx)
1678 pairsList.append(pairy)
1678 pairsList.append(pairy)
1679
1679
1680 jph = numpy.array([0,0,0,0])
1680 jph = numpy.array([0,0,0,0])
1681 h = (hmin,hmax)
1681 h = (hmin,hmax)
1682 arrayParameters = meteorOps.getMeteorParams(arrayParameters, azimuth, h, pairsList, distances, jph)
1682 arrayParameters = meteorOps.getMeteorParams(arrayParameters, azimuth, h, pairsList, distances, jph)
1683
1683
1684 # #Calculate AOA (Error N 3, 4)
1684 # #Calculate AOA (Error N 3, 4)
1685 # #JONES ET AL. 1998
1685 # #JONES ET AL. 1998
1686 # error = arrayParameters[:,-1]
1686 # error = arrayParameters[:,-1]
1687 # AOAthresh = numpy.pi/8
1687 # AOAthresh = numpy.pi/8
1688 # phases = -arrayParameters[:,9:13]
1688 # phases = -arrayParameters[:,9:13]
1689 # arrayParameters[:,4:7], arrayParameters[:,-1] = meteorOps.getAOA(phases, pairsList, error, AOAthresh, azimuth)
1689 # arrayParameters[:,4:7], arrayParameters[:,-1] = meteorOps.getAOA(phases, pairsList, error, AOAthresh, azimuth)
1690 #
1690 #
1691 # #Calculate Heights (Error N 13 and 14)
1691 # #Calculate Heights (Error N 13 and 14)
1692 # error = arrayParameters[:,-1]
1692 # error = arrayParameters[:,-1]
1693 # Ranges = arrayParameters[:,2]
1693 # Ranges = arrayParameters[:,2]
1694 # zenith = arrayParameters[:,5]
1694 # zenith = arrayParameters[:,5]
1695 # arrayParameters[:,3], arrayParameters[:,-1] = meteorOps.getHeights(Ranges, zenith, error, hmin, hmax)
1695 # arrayParameters[:,3], arrayParameters[:,-1] = meteorOps.getHeights(Ranges, zenith, error, hmin, hmax)
1696 # error = arrayParameters[:,-1]
1696 # error = arrayParameters[:,-1]
1697 #********************* END OF PARAMETERS CALCULATION **************************
1697 #********************* END OF PARAMETERS CALCULATION **************************
1698
1698
1699 #***************************+ PASS DATA TO NEXT STEP **********************
1699 #***************************+ PASS DATA TO NEXT STEP **********************
1700 # arrayFinal = arrayParameters.reshape((1,arrayParameters.shape[0],arrayParameters.shape[1]))
1700 # arrayFinal = arrayParameters.reshape((1,arrayParameters.shape[0],arrayParameters.shape[1]))
1701 dataOut.data_param = arrayParameters
1701 dataOut.data_param = arrayParameters
1702
1702
1703 if arrayParameters is None:
1703 if arrayParameters is None:
1704 dataOut.flagNoData = True
1704 dataOut.flagNoData = True
1705 else:
1705 else:
1706 dataOut.flagNoData = True
1706 dataOut.flagNoData = True
1707
1707
1708 return
1708 return
1709
1709
1710 def __getHardwarePhaseDiff(self, voltage0, pairslist, newheis, n):
1710 def __getHardwarePhaseDiff(self, voltage0, pairslist, newheis, n):
1711
1711
1712 minIndex = min(newheis[0])
1712 minIndex = min(newheis[0])
1713 maxIndex = max(newheis[0])
1713 maxIndex = max(newheis[0])
1714
1714
1715 voltage = voltage0[:,:,minIndex:maxIndex+1]
1715 voltage = voltage0[:,:,minIndex:maxIndex+1]
1716 nLength = voltage.shape[1]/n
1716 nLength = voltage.shape[1]/n
1717 nMin = 0
1717 nMin = 0
1718 nMax = 0
1718 nMax = 0
1719 phaseOffset = numpy.zeros((len(pairslist),n))
1719 phaseOffset = numpy.zeros((len(pairslist),n))
1720
1720
1721 for i in range(n):
1721 for i in range(n):
1722 nMax += nLength
1722 nMax += nLength
1723 phaseCCF = -numpy.angle(self.__calculateCCF(voltage[:,nMin:nMax,:], pairslist, [0]))
1723 phaseCCF = -numpy.angle(self.__calculateCCF(voltage[:,nMin:nMax,:], pairslist, [0]))
1724 phaseCCF = numpy.mean(phaseCCF, axis = 2)
1724 phaseCCF = numpy.mean(phaseCCF, axis = 2)
1725 phaseOffset[:,i] = phaseCCF.transpose()
1725 phaseOffset[:,i] = phaseCCF.transpose()
1726 nMin = nMax
1726 nMin = nMax
1727 # phaseDiff, phaseArrival = self.estimatePhaseDifference(voltage, pairslist)
1727 # phaseDiff, phaseArrival = self.estimatePhaseDifference(voltage, pairslist)
1728
1728
1729 #Remove Outliers
1729 #Remove Outliers
1730 factor = 2
1730 factor = 2
1731 wt = phaseOffset - signal.medfilt(phaseOffset,(1,5))
1731 wt = phaseOffset - signal.medfilt(phaseOffset,(1,5))
1732 dw = numpy.std(wt,axis = 1)
1732 dw = numpy.std(wt,axis = 1)
1733 dw = dw.reshape((dw.size,1))
1733 dw = dw.reshape((dw.size,1))
1734 ind = numpy.where(numpy.logical_or(wt>dw*factor,wt<-dw*factor))
1734 ind = numpy.where(numpy.logical_or(wt>dw*factor,wt<-dw*factor))
1735 phaseOffset[ind] = numpy.nan
1735 phaseOffset[ind] = numpy.nan
1736 phaseOffset = stats.nanmean(phaseOffset, axis=1)
1736 phaseOffset = stats.nanmean(phaseOffset, axis=1)
1737
1737
1738 return phaseOffset
1738 return phaseOffset
1739
1739
1740 def __shiftPhase(self, data, phaseShift):
1740 def __shiftPhase(self, data, phaseShift):
1741 #this will shift the phase of a complex number
1741 #this will shift the phase of a complex number
1742 dataShifted = numpy.abs(data) * numpy.exp((numpy.angle(data)+phaseShift)*1j)
1742 dataShifted = numpy.abs(data) * numpy.exp((numpy.angle(data)+phaseShift)*1j)
1743 return dataShifted
1743 return dataShifted
1744
1744
1745 def __estimatePhaseDifference(self, array, pairslist):
1745 def __estimatePhaseDifference(self, array, pairslist):
1746 nChannel = array.shape[0]
1746 nChannel = array.shape[0]
1747 nHeights = array.shape[2]
1747 nHeights = array.shape[2]
1748 numPairs = len(pairslist)
1748 numPairs = len(pairslist)
1749 # phaseCCF = numpy.zeros((nChannel, 5, nHeights))
1749 # phaseCCF = numpy.zeros((nChannel, 5, nHeights))
1750 phaseCCF = numpy.angle(self.__calculateCCF(array, pairslist, [-2,-1,0,1,2]))
1750 phaseCCF = numpy.angle(self.__calculateCCF(array, pairslist, [-2,-1,0,1,2]))
1751
1751
1752 #Correct phases
1752 #Correct phases
1753 derPhaseCCF = phaseCCF[:,1:,:] - phaseCCF[:,0:-1,:]
1753 derPhaseCCF = phaseCCF[:,1:,:] - phaseCCF[:,0:-1,:]
1754 indDer = numpy.where(numpy.abs(derPhaseCCF) > numpy.pi)
1754 indDer = numpy.where(numpy.abs(derPhaseCCF) > numpy.pi)
1755
1755
1756 if indDer[0].shape[0] > 0:
1756 if indDer[0].shape[0] > 0:
1757 for i in range(indDer[0].shape[0]):
1757 for i in range(indDer[0].shape[0]):
1758 signo = -numpy.sign(derPhaseCCF[indDer[0][i],indDer[1][i],indDer[2][i]])
1758 signo = -numpy.sign(derPhaseCCF[indDer[0][i],indDer[1][i],indDer[2][i]])
1759 phaseCCF[indDer[0][i],indDer[1][i]+1:,:] += signo*2*numpy.pi
1759 phaseCCF[indDer[0][i],indDer[1][i]+1:,:] += signo*2*numpy.pi
1760
1760
1761 # for j in range(numSides):
1761 # for j in range(numSides):
1762 # phaseCCFAux = self.calculateCCF(arrayCenter, arraySides[j,:,:], [-2,1,0,1,2])
1762 # phaseCCFAux = self.calculateCCF(arrayCenter, arraySides[j,:,:], [-2,1,0,1,2])
1763 # phaseCCF[j,:,:] = numpy.angle(phaseCCFAux)
1763 # phaseCCF[j,:,:] = numpy.angle(phaseCCFAux)
1764 #
1764 #
1765 #Linear
1765 #Linear
1766 phaseInt = numpy.zeros((numPairs,1))
1766 phaseInt = numpy.zeros((numPairs,1))
1767 angAllCCF = phaseCCF[:,[0,1,3,4],0]
1767 angAllCCF = phaseCCF[:,[0,1,3,4],0]
1768 for j in range(numPairs):
1768 for j in range(numPairs):
1769 fit = stats.linregress([-2,-1,1,2],angAllCCF[j,:])
1769 fit = stats.linregress([-2,-1,1,2],angAllCCF[j,:])
1770 phaseInt[j] = fit[1]
1770 phaseInt[j] = fit[1]
1771 #Phase Differences
1771 #Phase Differences
1772 phaseDiff = phaseInt - phaseCCF[:,2,:]
1772 phaseDiff = phaseInt - phaseCCF[:,2,:]
1773 phaseArrival = phaseInt.reshape(phaseInt.size)
1773 phaseArrival = phaseInt.reshape(phaseInt.size)
1774
1774
1775 #Dealias
1775 #Dealias
1776 phaseArrival = numpy.angle(numpy.exp(1j*phaseArrival))
1776 phaseArrival = numpy.angle(numpy.exp(1j*phaseArrival))
1777 # indAlias = numpy.where(phaseArrival > numpy.pi)
1777 # indAlias = numpy.where(phaseArrival > numpy.pi)
1778 # phaseArrival[indAlias] -= 2*numpy.pi
1778 # phaseArrival[indAlias] -= 2*numpy.pi
1779 # indAlias = numpy.where(phaseArrival < -numpy.pi)
1779 # indAlias = numpy.where(phaseArrival < -numpy.pi)
1780 # phaseArrival[indAlias] += 2*numpy.pi
1780 # phaseArrival[indAlias] += 2*numpy.pi
1781
1781
1782 return phaseDiff, phaseArrival
1782 return phaseDiff, phaseArrival
1783
1783
1784 def __coherentDetection(self, volts, timeSegment, timeInterval, pairslist, thresh):
1784 def __coherentDetection(self, volts, timeSegment, timeInterval, pairslist, thresh):
1785 #this function will run the coherent detection used in Holdworth et al. 2004 and return the net power
1785 #this function will run the coherent detection used in Holdworth et al. 2004 and return the net power
1786 #find the phase shifts of each channel over 1 second intervals
1786 #find the phase shifts of each channel over 1 second intervals
1787 #only look at ranges below the beacon signal
1787 #only look at ranges below the beacon signal
1788 numProfPerBlock = numpy.ceil(timeSegment/timeInterval)
1788 numProfPerBlock = numpy.ceil(timeSegment/timeInterval)
1789 numBlocks = int(volts.shape[1]/numProfPerBlock)
1789 numBlocks = int(volts.shape[1]/numProfPerBlock)
1790 numHeights = volts.shape[2]
1790 numHeights = volts.shape[2]
1791 nChannel = volts.shape[0]
1791 nChannel = volts.shape[0]
1792 voltsCohDet = volts.copy()
1792 voltsCohDet = volts.copy()
1793
1793
1794 pairsarray = numpy.array(pairslist)
1794 pairsarray = numpy.array(pairslist)
1795 indSides = pairsarray[:,1]
1795 indSides = pairsarray[:,1]
1796 # indSides = numpy.array(range(nChannel))
1796 # indSides = numpy.array(range(nChannel))
1797 # indSides = numpy.delete(indSides, indCenter)
1797 # indSides = numpy.delete(indSides, indCenter)
1798 #
1798 #
1799 # listCenter = numpy.array_split(volts[indCenter,:,:], numBlocks, 0)
1799 # listCenter = numpy.array_split(volts[indCenter,:,:], numBlocks, 0)
1800 listBlocks = numpy.array_split(volts, numBlocks, 1)
1800 listBlocks = numpy.array_split(volts, numBlocks, 1)
1801
1801
1802 startInd = 0
1802 startInd = 0
1803 endInd = 0
1803 endInd = 0
1804
1804
1805 for i in range(numBlocks):
1805 for i in range(numBlocks):
1806 startInd = endInd
1806 startInd = endInd
1807 endInd = endInd + listBlocks[i].shape[1]
1807 endInd = endInd + listBlocks[i].shape[1]
1808
1808
1809 arrayBlock = listBlocks[i]
1809 arrayBlock = listBlocks[i]
1810 # arrayBlockCenter = listCenter[i]
1810 # arrayBlockCenter = listCenter[i]
1811
1811
1812 #Estimate the Phase Difference
1812 #Estimate the Phase Difference
1813 phaseDiff, aux = self.__estimatePhaseDifference(arrayBlock, pairslist)
1813 phaseDiff, aux = self.__estimatePhaseDifference(arrayBlock, pairslist)
1814 #Phase Difference RMS
1814 #Phase Difference RMS
1815 arrayPhaseRMS = numpy.abs(phaseDiff)
1815 arrayPhaseRMS = numpy.abs(phaseDiff)
1816 phaseRMSaux = numpy.sum(arrayPhaseRMS < thresh,0)
1816 phaseRMSaux = numpy.sum(arrayPhaseRMS < thresh,0)
1817 indPhase = numpy.where(phaseRMSaux==4)
1817 indPhase = numpy.where(phaseRMSaux==4)
1818 #Shifting
1818 #Shifting
1819 if indPhase[0].shape[0] > 0:
1819 if indPhase[0].shape[0] > 0:
1820 for j in range(indSides.size):
1820 for j in range(indSides.size):
1821 arrayBlock[indSides[j],:,indPhase] = self.__shiftPhase(arrayBlock[indSides[j],:,indPhase], phaseDiff[j,indPhase].transpose())
1821 arrayBlock[indSides[j],:,indPhase] = self.__shiftPhase(arrayBlock[indSides[j],:,indPhase], phaseDiff[j,indPhase].transpose())
1822 voltsCohDet[:,startInd:endInd,:] = arrayBlock
1822 voltsCohDet[:,startInd:endInd,:] = arrayBlock
1823
1823
1824 return voltsCohDet
1824 return voltsCohDet
1825
1825
1826 def __calculateCCF(self, volts, pairslist ,laglist):
1826 def __calculateCCF(self, volts, pairslist ,laglist):
1827
1827
1828 nHeights = volts.shape[2]
1828 nHeights = volts.shape[2]
1829 nPoints = volts.shape[1]
1829 nPoints = volts.shape[1]
1830 voltsCCF = numpy.zeros((len(pairslist), len(laglist), nHeights),dtype = 'complex')
1830 voltsCCF = numpy.zeros((len(pairslist), len(laglist), nHeights),dtype = 'complex')
1831
1831
1832 for i in range(len(pairslist)):
1832 for i in range(len(pairslist)):
1833 volts1 = volts[pairslist[i][0]]
1833 volts1 = volts[pairslist[i][0]]
1834 volts2 = volts[pairslist[i][1]]
1834 volts2 = volts[pairslist[i][1]]
1835
1835
1836 for t in range(len(laglist)):
1836 for t in range(len(laglist)):
1837 idxT = laglist[t]
1837 idxT = laglist[t]
1838 if idxT >= 0:
1838 if idxT >= 0:
1839 vStacked = numpy.vstack((volts2[idxT:,:],
1839 vStacked = numpy.vstack((volts2[idxT:,:],
1840 numpy.zeros((idxT, nHeights),dtype='complex')))
1840 numpy.zeros((idxT, nHeights),dtype='complex')))
1841 else:
1841 else:
1842 vStacked = numpy.vstack((numpy.zeros((-idxT, nHeights),dtype='complex'),
1842 vStacked = numpy.vstack((numpy.zeros((-idxT, nHeights),dtype='complex'),
1843 volts2[:(nPoints + idxT),:]))
1843 volts2[:(nPoints + idxT),:]))
1844 voltsCCF[i,t,:] = numpy.sum((numpy.conjugate(volts1)*vStacked),axis=0)
1844 voltsCCF[i,t,:] = numpy.sum((numpy.conjugate(volts1)*vStacked),axis=0)
1845
1845
1846 vStacked = None
1846 vStacked = None
1847 return voltsCCF
1847 return voltsCCF
1848
1848
1849 def __getNoise(self, power, timeSegment, timeInterval):
1849 def __getNoise(self, power, timeSegment, timeInterval):
1850 numProfPerBlock = numpy.ceil(timeSegment/timeInterval)
1850 numProfPerBlock = numpy.ceil(timeSegment/timeInterval)
1851 numBlocks = int(power.shape[0]/numProfPerBlock)
1851 numBlocks = int(power.shape[0]/numProfPerBlock)
1852 numHeights = power.shape[1]
1852 numHeights = power.shape[1]
1853
1853
1854 listPower = numpy.array_split(power, numBlocks, 0)
1854 listPower = numpy.array_split(power, numBlocks, 0)
1855 noise = numpy.zeros((power.shape[0], power.shape[1]))
1855 noise = numpy.zeros((power.shape[0], power.shape[1]))
1856 noise1 = numpy.zeros((power.shape[0], power.shape[1]))
1856 noise1 = numpy.zeros((power.shape[0], power.shape[1]))
1857
1857
1858 startInd = 0
1858 startInd = 0
1859 endInd = 0
1859 endInd = 0
1860
1860
1861 for i in range(numBlocks): #split por canal
1861 for i in range(numBlocks): #split por canal
1862 startInd = endInd
1862 startInd = endInd
1863 endInd = endInd + listPower[i].shape[0]
1863 endInd = endInd + listPower[i].shape[0]
1864
1864
1865 arrayBlock = listPower[i]
1865 arrayBlock = listPower[i]
1866 noiseAux = numpy.mean(arrayBlock, 0)
1866 noiseAux = numpy.mean(arrayBlock, 0)
1867 # noiseAux = numpy.median(noiseAux)
1867 # noiseAux = numpy.median(noiseAux)
1868 # noiseAux = numpy.mean(arrayBlock)
1868 # noiseAux = numpy.mean(arrayBlock)
1869 noise[startInd:endInd,:] = noise[startInd:endInd,:] + noiseAux
1869 noise[startInd:endInd,:] = noise[startInd:endInd,:] + noiseAux
1870
1870
1871 noiseAux1 = numpy.mean(arrayBlock)
1871 noiseAux1 = numpy.mean(arrayBlock)
1872 noise1[startInd:endInd,:] = noise1[startInd:endInd,:] + noiseAux1
1872 noise1[startInd:endInd,:] = noise1[startInd:endInd,:] + noiseAux1
1873
1873
1874 return noise, noise1
1874 return noise, noise1
1875
1875
1876 def __findMeteors(self, power, thresh):
1876 def __findMeteors(self, power, thresh):
1877 nProf = power.shape[0]
1877 nProf = power.shape[0]
1878 nHeights = power.shape[1]
1878 nHeights = power.shape[1]
1879 listMeteors = []
1879 listMeteors = []
1880
1880
1881 for i in range(nHeights):
1881 for i in range(nHeights):
1882 powerAux = power[:,i]
1882 powerAux = power[:,i]
1883 threshAux = thresh[:,i]
1883 threshAux = thresh[:,i]
1884
1884
1885 indUPthresh = numpy.where(powerAux > threshAux)[0]
1885 indUPthresh = numpy.where(powerAux > threshAux)[0]
1886 indDNthresh = numpy.where(powerAux <= threshAux)[0]
1886 indDNthresh = numpy.where(powerAux <= threshAux)[0]
1887
1887
1888 j = 0
1888 j = 0
1889
1889
1890 while (j < indUPthresh.size - 2):
1890 while (j < indUPthresh.size - 2):
1891 if (indUPthresh[j + 2] == indUPthresh[j] + 2):
1891 if (indUPthresh[j + 2] == indUPthresh[j] + 2):
1892 indDNAux = numpy.where(indDNthresh > indUPthresh[j])
1892 indDNAux = numpy.where(indDNthresh > indUPthresh[j])
1893 indDNthresh = indDNthresh[indDNAux]
1893 indDNthresh = indDNthresh[indDNAux]
1894
1894
1895 if (indDNthresh.size > 0):
1895 if (indDNthresh.size > 0):
1896 indEnd = indDNthresh[0] - 1
1896 indEnd = indDNthresh[0] - 1
1897 indInit = indUPthresh[j] if isinstance(indUPthresh[j], (int, float)) else indUPthresh[j][0] ##CHECK!!!!
1897 indInit = indUPthresh[j] if isinstance(indUPthresh[j], (int, float)) else indUPthresh[j][0] ##CHECK!!!!
1898
1898
1899 meteor = powerAux[indInit:indEnd + 1]
1899 meteor = powerAux[indInit:indEnd + 1]
1900 indPeak = meteor.argmax() + indInit
1900 indPeak = meteor.argmax() + indInit
1901 FLA = sum(numpy.conj(meteor)*numpy.hstack((meteor[1:],0)))
1901 FLA = sum(numpy.conj(meteor)*numpy.hstack((meteor[1:],0)))
1902
1902
1903 listMeteors.append(numpy.array([i,indInit,indPeak,indEnd,FLA])) #CHEQUEAR!!!!!
1903 listMeteors.append(numpy.array([i,indInit,indPeak,indEnd,FLA])) #CHEQUEAR!!!!!
1904 j = numpy.where(indUPthresh == indEnd)[0] + 1
1904 j = numpy.where(indUPthresh == indEnd)[0] + 1
1905 else: j+=1
1905 else: j+=1
1906 else: j+=1
1906 else: j+=1
1907
1907
1908 return listMeteors
1908 return listMeteors
1909
1909
1910 def __removeMultipleDetections(self,listMeteors, rangeLimit, timeLimit):
1910 def __removeMultipleDetections(self,listMeteors, rangeLimit, timeLimit):
1911
1911
1912 arrayMeteors = numpy.asarray(listMeteors)
1912 arrayMeteors = numpy.asarray(listMeteors)
1913 listMeteors1 = []
1913 listMeteors1 = []
1914
1914
1915 while arrayMeteors.shape[0] > 0:
1915 while arrayMeteors.shape[0] > 0:
1916 FLAs = arrayMeteors[:,4]
1916 FLAs = arrayMeteors[:,4]
1917 maxFLA = FLAs.argmax()
1917 maxFLA = FLAs.argmax()
1918 listMeteors1.append(arrayMeteors[maxFLA,:])
1918 listMeteors1.append(arrayMeteors[maxFLA,:])
1919
1919
1920 MeteorInitTime = arrayMeteors[maxFLA,1]
1920 MeteorInitTime = arrayMeteors[maxFLA,1]
1921 MeteorEndTime = arrayMeteors[maxFLA,3]
1921 MeteorEndTime = arrayMeteors[maxFLA,3]
1922 MeteorHeight = arrayMeteors[maxFLA,0]
1922 MeteorHeight = arrayMeteors[maxFLA,0]
1923
1923
1924 #Check neighborhood
1924 #Check neighborhood
1925 maxHeightIndex = MeteorHeight + rangeLimit
1925 maxHeightIndex = MeteorHeight + rangeLimit
1926 minHeightIndex = MeteorHeight - rangeLimit
1926 minHeightIndex = MeteorHeight - rangeLimit
1927 minTimeIndex = MeteorInitTime - timeLimit
1927 minTimeIndex = MeteorInitTime - timeLimit
1928 maxTimeIndex = MeteorEndTime + timeLimit
1928 maxTimeIndex = MeteorEndTime + timeLimit
1929
1929
1930 #Check Heights
1930 #Check Heights
1931 indHeight = numpy.logical_and(arrayMeteors[:,0] >= minHeightIndex, arrayMeteors[:,0] <= maxHeightIndex)
1931 indHeight = numpy.logical_and(arrayMeteors[:,0] >= minHeightIndex, arrayMeteors[:,0] <= maxHeightIndex)
1932 indTime = numpy.logical_and(arrayMeteors[:,3] >= minTimeIndex, arrayMeteors[:,1] <= maxTimeIndex)
1932 indTime = numpy.logical_and(arrayMeteors[:,3] >= minTimeIndex, arrayMeteors[:,1] <= maxTimeIndex)
1933 indBoth = numpy.where(numpy.logical_and(indTime,indHeight))
1933 indBoth = numpy.where(numpy.logical_and(indTime,indHeight))
1934
1934
1935 arrayMeteors = numpy.delete(arrayMeteors, indBoth, axis = 0)
1935 arrayMeteors = numpy.delete(arrayMeteors, indBoth, axis = 0)
1936
1936
1937 return listMeteors1
1937 return listMeteors1
1938
1938
1939 def __meteorReestimation(self, listMeteors, volts, pairslist, thresh, noise, timeInterval,frequency):
1939 def __meteorReestimation(self, listMeteors, volts, pairslist, thresh, noise, timeInterval,frequency):
1940 numHeights = volts.shape[2]
1940 numHeights = volts.shape[2]
1941 nChannel = volts.shape[0]
1941 nChannel = volts.shape[0]
1942
1942
1943 thresholdPhase = thresh[0]
1943 thresholdPhase = thresh[0]
1944 thresholdNoise = thresh[1]
1944 thresholdNoise = thresh[1]
1945 thresholdDB = float(thresh[2])
1945 thresholdDB = float(thresh[2])
1946
1946
1947 thresholdDB1 = 10**(thresholdDB/10)
1947 thresholdDB1 = 10**(thresholdDB/10)
1948 pairsarray = numpy.array(pairslist)
1948 pairsarray = numpy.array(pairslist)
1949 indSides = pairsarray[:,1]
1949 indSides = pairsarray[:,1]
1950
1950
1951 pairslist1 = list(pairslist)
1951 pairslist1 = list(pairslist)
1952 pairslist1.append((0,4))
1952 pairslist1.append((0,4))
1953 pairslist1.append((1,3))
1953 pairslist1.append((1,3))
1954
1954
1955 listMeteors1 = []
1955 listMeteors1 = []
1956 listPowerSeries = []
1956 listPowerSeries = []
1957 listVoltageSeries = []
1957 listVoltageSeries = []
1958 #volts has the war data
1958 #volts has the war data
1959
1959
1960 if frequency == 30.175e6:
1960 if frequency == 30.175e6:
1961 timeLag = 45*10**-3
1961 timeLag = 45*10**-3
1962 else:
1962 else:
1963 timeLag = 15*10**-3
1963 timeLag = 15*10**-3
1964 lag = int(numpy.ceil(timeLag/timeInterval))
1964 lag = int(numpy.ceil(timeLag/timeInterval))
1965
1965
1966 for i in range(len(listMeteors)):
1966 for i in range(len(listMeteors)):
1967
1967
1968 ###################### 3.6 - 3.7 PARAMETERS REESTIMATION #########################
1968 ###################### 3.6 - 3.7 PARAMETERS REESTIMATION #########################
1969 meteorAux = numpy.zeros(16)
1969 meteorAux = numpy.zeros(16)
1970
1970
1971 #Loading meteor Data (mHeight, mStart, mPeak, mEnd)
1971 #Loading meteor Data (mHeight, mStart, mPeak, mEnd)
1972 mHeight = int(listMeteors[i][0])
1972 mHeight = int(listMeteors[i][0])
1973 mStart = int(listMeteors[i][1])
1973 mStart = int(listMeteors[i][1])
1974 mPeak = int(listMeteors[i][2])
1974 mPeak = int(listMeteors[i][2])
1975 mEnd = int(listMeteors[i][3])
1975 mEnd = int(listMeteors[i][3])
1976
1976
1977 #get the volt data between the start and end times of the meteor
1977 #get the volt data between the start and end times of the meteor
1978 meteorVolts = volts[:,mStart:mEnd+1,mHeight]
1978 meteorVolts = volts[:,mStart:mEnd+1,mHeight]
1979 meteorVolts = meteorVolts.reshape(meteorVolts.shape[0], meteorVolts.shape[1], 1)
1979 meteorVolts = meteorVolts.reshape(meteorVolts.shape[0], meteorVolts.shape[1], 1)
1980
1980
1981 #3.6. Phase Difference estimation
1981 #3.6. Phase Difference estimation
1982 phaseDiff, aux = self.__estimatePhaseDifference(meteorVolts, pairslist)
1982 phaseDiff, aux = self.__estimatePhaseDifference(meteorVolts, pairslist)
1983
1983
1984 #3.7. Phase difference removal & meteor start, peak and end times reestimated
1984 #3.7. Phase difference removal & meteor start, peak and end times reestimated
1985 #meteorVolts0.- all Channels, all Profiles
1985 #meteorVolts0.- all Channels, all Profiles
1986 meteorVolts0 = volts[:,:,mHeight]
1986 meteorVolts0 = volts[:,:,mHeight]
1987 meteorThresh = noise[:,mHeight]*thresholdNoise
1987 meteorThresh = noise[:,mHeight]*thresholdNoise
1988 meteorNoise = noise[:,mHeight]
1988 meteorNoise = noise[:,mHeight]
1989 meteorVolts0[indSides,:] = self.__shiftPhase(meteorVolts0[indSides,:], phaseDiff) #Phase Shifting
1989 meteorVolts0[indSides,:] = self.__shiftPhase(meteorVolts0[indSides,:], phaseDiff) #Phase Shifting
1990 powerNet0 = numpy.nansum(numpy.abs(meteorVolts0)**2, axis = 0) #Power
1990 powerNet0 = numpy.nansum(numpy.abs(meteorVolts0)**2, axis = 0) #Power
1991
1991
1992 #Times reestimation
1992 #Times reestimation
1993 mStart1 = numpy.where(powerNet0[:mPeak] < meteorThresh[:mPeak])[0]
1993 mStart1 = numpy.where(powerNet0[:mPeak] < meteorThresh[:mPeak])[0]
1994 if mStart1.size > 0:
1994 if mStart1.size > 0:
1995 mStart1 = mStart1[-1] + 1
1995 mStart1 = mStart1[-1] + 1
1996
1996
1997 else:
1997 else:
1998 mStart1 = mPeak
1998 mStart1 = mPeak
1999
1999
2000 mEnd1 = numpy.where(powerNet0[mPeak:] < meteorThresh[mPeak:])[0][0] + mPeak - 1
2000 mEnd1 = numpy.where(powerNet0[mPeak:] < meteorThresh[mPeak:])[0][0] + mPeak - 1
2001 mEndDecayTime1 = numpy.where(powerNet0[mPeak:] < meteorNoise[mPeak:])[0]
2001 mEndDecayTime1 = numpy.where(powerNet0[mPeak:] < meteorNoise[mPeak:])[0]
2002 if mEndDecayTime1.size == 0:
2002 if mEndDecayTime1.size == 0:
2003 mEndDecayTime1 = powerNet0.size
2003 mEndDecayTime1 = powerNet0.size
2004 else:
2004 else:
2005 mEndDecayTime1 = mEndDecayTime1[0] + mPeak - 1
2005 mEndDecayTime1 = mEndDecayTime1[0] + mPeak - 1
2006 # mPeak1 = meteorVolts0[mStart1:mEnd1 + 1].argmax()
2006 # mPeak1 = meteorVolts0[mStart1:mEnd1 + 1].argmax()
2007
2007
2008 #meteorVolts1.- all Channels, from start to end
2008 #meteorVolts1.- all Channels, from start to end
2009 meteorVolts1 = meteorVolts0[:,mStart1:mEnd1 + 1]
2009 meteorVolts1 = meteorVolts0[:,mStart1:mEnd1 + 1]
2010 meteorVolts2 = meteorVolts0[:,mPeak + lag:mEnd1 + 1]
2010 meteorVolts2 = meteorVolts0[:,mPeak + lag:mEnd1 + 1]
2011 if meteorVolts2.shape[1] == 0:
2011 if meteorVolts2.shape[1] == 0:
2012 meteorVolts2 = meteorVolts0[:,mPeak:mEnd1 + 1]
2012 meteorVolts2 = meteorVolts0[:,mPeak:mEnd1 + 1]
2013 meteorVolts1 = meteorVolts1.reshape(meteorVolts1.shape[0], meteorVolts1.shape[1], 1)
2013 meteorVolts1 = meteorVolts1.reshape(meteorVolts1.shape[0], meteorVolts1.shape[1], 1)
2014 meteorVolts2 = meteorVolts2.reshape(meteorVolts2.shape[0], meteorVolts2.shape[1], 1)
2014 meteorVolts2 = meteorVolts2.reshape(meteorVolts2.shape[0], meteorVolts2.shape[1], 1)
2015 ##################### END PARAMETERS REESTIMATION #########################
2015 ##################### END PARAMETERS REESTIMATION #########################
2016
2016
2017 ##################### 3.8 PHASE DIFFERENCE REESTIMATION ########################
2017 ##################### 3.8 PHASE DIFFERENCE REESTIMATION ########################
2018 # if mEnd1 - mStart1 > 4: #Error Number 6: echo less than 5 samples long; too short for analysis
2018 # if mEnd1 - mStart1 > 4: #Error Number 6: echo less than 5 samples long; too short for analysis
2019 if meteorVolts2.shape[1] > 0:
2019 if meteorVolts2.shape[1] > 0:
2020 #Phase Difference re-estimation
2020 #Phase Difference re-estimation
2021 phaseDiff1, phaseDiffint = self.__estimatePhaseDifference(meteorVolts2, pairslist1) #Phase Difference Estimation
2021 phaseDiff1, phaseDiffint = self.__estimatePhaseDifference(meteorVolts2, pairslist1) #Phase Difference Estimation
2022 # phaseDiff1, phaseDiffint = self.estimatePhaseDifference(meteorVolts2, pairslist)
2022 # phaseDiff1, phaseDiffint = self.estimatePhaseDifference(meteorVolts2, pairslist)
2023 meteorVolts2 = meteorVolts2.reshape(meteorVolts2.shape[0], meteorVolts2.shape[1])
2023 meteorVolts2 = meteorVolts2.reshape(meteorVolts2.shape[0], meteorVolts2.shape[1])
2024 phaseDiff11 = numpy.reshape(phaseDiff1, (phaseDiff1.shape[0],1))
2024 phaseDiff11 = numpy.reshape(phaseDiff1, (phaseDiff1.shape[0],1))
2025 meteorVolts2[indSides,:] = self.__shiftPhase(meteorVolts2[indSides,:], phaseDiff11[0:4]) #Phase Shifting
2025 meteorVolts2[indSides,:] = self.__shiftPhase(meteorVolts2[indSides,:], phaseDiff11[0:4]) #Phase Shifting
2026
2026
2027 #Phase Difference RMS
2027 #Phase Difference RMS
2028 phaseRMS1 = numpy.sqrt(numpy.mean(numpy.square(phaseDiff1)))
2028 phaseRMS1 = numpy.sqrt(numpy.mean(numpy.square(phaseDiff1)))
2029 powerNet1 = numpy.nansum(numpy.abs(meteorVolts1[:,:])**2,0)
2029 powerNet1 = numpy.nansum(numpy.abs(meteorVolts1[:,:])**2,0)
2030 #Data from Meteor
2030 #Data from Meteor
2031 mPeak1 = powerNet1.argmax() + mStart1
2031 mPeak1 = powerNet1.argmax() + mStart1
2032 mPeakPower1 = powerNet1.max()
2032 mPeakPower1 = powerNet1.max()
2033 noiseAux = sum(noise[mStart1:mEnd1 + 1,mHeight])
2033 noiseAux = sum(noise[mStart1:mEnd1 + 1,mHeight])
2034 mSNR1 = (sum(powerNet1)-noiseAux)/noiseAux
2034 mSNR1 = (sum(powerNet1)-noiseAux)/noiseAux
2035 Meteor1 = numpy.array([mHeight, mStart1, mPeak1, mEnd1, mPeakPower1, mSNR1, phaseRMS1])
2035 Meteor1 = numpy.array([mHeight, mStart1, mPeak1, mEnd1, mPeakPower1, mSNR1, phaseRMS1])
2036 Meteor1 = numpy.hstack((Meteor1,phaseDiffint))
2036 Meteor1 = numpy.hstack((Meteor1,phaseDiffint))
2037 PowerSeries = powerNet0[mStart1:mEndDecayTime1 + 1]
2037 PowerSeries = powerNet0[mStart1:mEndDecayTime1 + 1]
2038 #Vectorize
2038 #Vectorize
2039 meteorAux[0:7] = [mHeight, mStart1, mPeak1, mEnd1, mPeakPower1, mSNR1, phaseRMS1]
2039 meteorAux[0:7] = [mHeight, mStart1, mPeak1, mEnd1, mPeakPower1, mSNR1, phaseRMS1]
2040 meteorAux[7:11] = phaseDiffint[0:4]
2040 meteorAux[7:11] = phaseDiffint[0:4]
2041
2041
2042 #Rejection Criterions
2042 #Rejection Criterions
2043 if phaseRMS1 > thresholdPhase: #Error Number 17: Phase variation
2043 if phaseRMS1 > thresholdPhase: #Error Number 17: Phase variation
2044 meteorAux[-1] = 17
2044 meteorAux[-1] = 17
2045 elif mSNR1 < thresholdDB1: #Error Number 1: SNR < threshold dB
2045 elif mSNR1 < thresholdDB1: #Error Number 1: SNR < threshold dB
2046 meteorAux[-1] = 1
2046 meteorAux[-1] = 1
2047
2047
2048
2048
2049 else:
2049 else:
2050 meteorAux[0:4] = [mHeight, mStart, mPeak, mEnd]
2050 meteorAux[0:4] = [mHeight, mStart, mPeak, mEnd]
2051 meteorAux[-1] = 6 #Error Number 6: echo less than 5 samples long; too short for analysis
2051 meteorAux[-1] = 6 #Error Number 6: echo less than 5 samples long; too short for analysis
2052 PowerSeries = 0
2052 PowerSeries = 0
2053
2053
2054 listMeteors1.append(meteorAux)
2054 listMeteors1.append(meteorAux)
2055 listPowerSeries.append(PowerSeries)
2055 listPowerSeries.append(PowerSeries)
2056 listVoltageSeries.append(meteorVolts1)
2056 listVoltageSeries.append(meteorVolts1)
2057
2057
2058 return listMeteors1, listPowerSeries, listVoltageSeries
2058 return listMeteors1, listPowerSeries, listVoltageSeries
2059
2059
2060 def __estimateDecayTime(self, listMeteors, listPower, timeInterval, frequency):
2060 def __estimateDecayTime(self, listMeteors, listPower, timeInterval, frequency):
2061
2061
2062 threshError = 10
2062 threshError = 10
2063 #Depending if it is 30 or 50 MHz
2063 #Depending if it is 30 or 50 MHz
2064 if frequency == 30.175e6:
2064 if frequency == 30.175e6:
2065 timeLag = 45*10**-3
2065 timeLag = 45*10**-3
2066 else:
2066 else:
2067 timeLag = 15*10**-3
2067 timeLag = 15*10**-3
2068 lag = int(numpy.ceil(timeLag/timeInterval))
2068 lag = int(numpy.ceil(timeLag/timeInterval))
2069
2069
2070 listMeteors1 = []
2070 listMeteors1 = []
2071
2071
2072 for i in range(len(listMeteors)):
2072 for i in range(len(listMeteors)):
2073 meteorPower = listPower[i]
2073 meteorPower = listPower[i]
2074 meteorAux = listMeteors[i]
2074 meteorAux = listMeteors[i]
2075
2075
2076 if meteorAux[-1] == 0:
2076 if meteorAux[-1] == 0:
2077
2077
2078 try:
2078 try:
2079 indmax = meteorPower.argmax()
2079 indmax = meteorPower.argmax()
2080 indlag = indmax + lag
2080 indlag = indmax + lag
2081
2081
2082 y = meteorPower[indlag:]
2082 y = meteorPower[indlag:]
2083 x = numpy.arange(0, y.size)*timeLag
2083 x = numpy.arange(0, y.size)*timeLag
2084
2084
2085 #first guess
2085 #first guess
2086 a = y[0]
2086 a = y[0]
2087 tau = timeLag
2087 tau = timeLag
2088 #exponential fit
2088 #exponential fit
2089 popt, pcov = optimize.curve_fit(self.__exponential_function, x, y, p0 = [a, tau])
2089 popt, pcov = optimize.curve_fit(self.__exponential_function, x, y, p0 = [a, tau])
2090 y1 = self.__exponential_function(x, *popt)
2090 y1 = self.__exponential_function(x, *popt)
2091 #error estimation
2091 #error estimation
2092 error = sum((y - y1)**2)/(numpy.var(y)*(y.size - popt.size))
2092 error = sum((y - y1)**2)/(numpy.var(y)*(y.size - popt.size))
2093
2093
2094 decayTime = popt[1]
2094 decayTime = popt[1]
2095 riseTime = indmax*timeInterval
2095 riseTime = indmax*timeInterval
2096 meteorAux[11:13] = [decayTime, error]
2096 meteorAux[11:13] = [decayTime, error]
2097
2097
2098 #Table items 7, 8 and 11
2098 #Table items 7, 8 and 11
2099 if (riseTime > 0.3): #Number 7: Echo rise exceeds 0.3s
2099 if (riseTime > 0.3): #Number 7: Echo rise exceeds 0.3s
2100 meteorAux[-1] = 7
2100 meteorAux[-1] = 7
2101 elif (decayTime < 2*riseTime) : #Number 8: Echo decay time less than than twice rise time
2101 elif (decayTime < 2*riseTime) : #Number 8: Echo decay time less than than twice rise time
2102 meteorAux[-1] = 8
2102 meteorAux[-1] = 8
2103 if (error > threshError): #Number 11: Poor fit to amplitude for estimation of decay time
2103 if (error > threshError): #Number 11: Poor fit to amplitude for estimation of decay time
2104 meteorAux[-1] = 11
2104 meteorAux[-1] = 11
2105
2105
2106
2106
2107 except:
2107 except:
2108 meteorAux[-1] = 11
2108 meteorAux[-1] = 11
2109
2109
2110
2110
2111 listMeteors1.append(meteorAux)
2111 listMeteors1.append(meteorAux)
2112
2112
2113 return listMeteors1
2113 return listMeteors1
2114
2114
2115 #Exponential Function
2115 #Exponential Function
2116
2116
2117 def __exponential_function(self, x, a, tau):
2117 def __exponential_function(self, x, a, tau):
2118 y = a*numpy.exp(-x/tau)
2118 y = a*numpy.exp(-x/tau)
2119 return y
2119 return y
2120
2120
2121 def __getRadialVelocity(self, listMeteors, listVolts, radialStdThresh, pairslist, timeInterval):
2121 def __getRadialVelocity(self, listMeteors, listVolts, radialStdThresh, pairslist, timeInterval):
2122
2122
2123 pairslist1 = list(pairslist)
2123 pairslist1 = list(pairslist)
2124 pairslist1.append((0,4))
2124 pairslist1.append((0,4))
2125 pairslist1.append((1,3))
2125 pairslist1.append((1,3))
2126 numPairs = len(pairslist1)
2126 numPairs = len(pairslist1)
2127 #Time Lag
2127 #Time Lag
2128 timeLag = 45*10**-3
2128 timeLag = 45*10**-3
2129 c = 3e8
2129 c = 3e8
2130 lag = numpy.ceil(timeLag/timeInterval)
2130 lag = numpy.ceil(timeLag/timeInterval)
2131 freq = 30.175e6
2131 freq = 30.175e6
2132
2132
2133 listMeteors1 = []
2133 listMeteors1 = []
2134
2134
2135 for i in range(len(listMeteors)):
2135 for i in range(len(listMeteors)):
2136 meteorAux = listMeteors[i]
2136 meteorAux = listMeteors[i]
2137 if meteorAux[-1] == 0:
2137 if meteorAux[-1] == 0:
2138 mStart = listMeteors[i][1]
2138 mStart = listMeteors[i][1]
2139 mPeak = listMeteors[i][2]
2139 mPeak = listMeteors[i][2]
2140 mLag = mPeak - mStart + lag
2140 mLag = mPeak - mStart + lag
2141
2141
2142 #get the volt data between the start and end times of the meteor
2142 #get the volt data between the start and end times of the meteor
2143 meteorVolts = listVolts[i]
2143 meteorVolts = listVolts[i]
2144 meteorVolts = meteorVolts.reshape(meteorVolts.shape[0], meteorVolts.shape[1], 1)
2144 meteorVolts = meteorVolts.reshape(meteorVolts.shape[0], meteorVolts.shape[1], 1)
2145
2145
2146 #Get CCF
2146 #Get CCF
2147 allCCFs = self.__calculateCCF(meteorVolts, pairslist1, [-2,-1,0,1,2])
2147 allCCFs = self.__calculateCCF(meteorVolts, pairslist1, [-2,-1,0,1,2])
2148
2148
2149 #Method 2
2149 #Method 2
2150 slopes = numpy.zeros(numPairs)
2150 slopes = numpy.zeros(numPairs)
2151 time = numpy.array([-2,-1,1,2])*timeInterval
2151 time = numpy.array([-2,-1,1,2])*timeInterval
2152 angAllCCF = numpy.angle(allCCFs[:,[0,4,2,3],0])
2152 angAllCCF = numpy.angle(allCCFs[:,[0,4,2,3],0])
2153
2153
2154 #Correct phases
2154 #Correct phases
2155 derPhaseCCF = angAllCCF[:,1:] - angAllCCF[:,0:-1]
2155 derPhaseCCF = angAllCCF[:,1:] - angAllCCF[:,0:-1]
2156 indDer = numpy.where(numpy.abs(derPhaseCCF) > numpy.pi)
2156 indDer = numpy.where(numpy.abs(derPhaseCCF) > numpy.pi)
2157
2157
2158 if indDer[0].shape[0] > 0:
2158 if indDer[0].shape[0] > 0:
2159 for i in range(indDer[0].shape[0]):
2159 for i in range(indDer[0].shape[0]):
2160 signo = -numpy.sign(derPhaseCCF[indDer[0][i],indDer[1][i]])
2160 signo = -numpy.sign(derPhaseCCF[indDer[0][i],indDer[1][i]])
2161 angAllCCF[indDer[0][i],indDer[1][i]+1:] += signo*2*numpy.pi
2161 angAllCCF[indDer[0][i],indDer[1][i]+1:] += signo*2*numpy.pi
2162
2162
2163 # fit = scipy.stats.linregress(numpy.array([-2,-1,1,2])*timeInterval, numpy.array([phaseLagN2s[i],phaseLagN1s[i],phaseLag1s[i],phaseLag2s[i]]))
2163 # fit = scipy.stats.linregress(numpy.array([-2,-1,1,2])*timeInterval, numpy.array([phaseLagN2s[i],phaseLagN1s[i],phaseLag1s[i],phaseLag2s[i]]))
2164 for j in range(numPairs):
2164 for j in range(numPairs):
2165 fit = stats.linregress(time, angAllCCF[j,:])
2165 fit = stats.linregress(time, angAllCCF[j,:])
2166 slopes[j] = fit[0]
2166 slopes[j] = fit[0]
2167
2167
2168 #Remove Outlier
2168 #Remove Outlier
2169 # indOut = numpy.argmax(numpy.abs(slopes - numpy.mean(slopes)))
2169 # indOut = numpy.argmax(numpy.abs(slopes - numpy.mean(slopes)))
2170 # slopes = numpy.delete(slopes,indOut)
2170 # slopes = numpy.delete(slopes,indOut)
2171 # indOut = numpy.argmax(numpy.abs(slopes - numpy.mean(slopes)))
2171 # indOut = numpy.argmax(numpy.abs(slopes - numpy.mean(slopes)))
2172 # slopes = numpy.delete(slopes,indOut)
2172 # slopes = numpy.delete(slopes,indOut)
2173
2173
2174 radialVelocity = -numpy.mean(slopes)*(0.25/numpy.pi)*(c/freq)
2174 radialVelocity = -numpy.mean(slopes)*(0.25/numpy.pi)*(c/freq)
2175 radialError = numpy.std(slopes)*(0.25/numpy.pi)*(c/freq)
2175 radialError = numpy.std(slopes)*(0.25/numpy.pi)*(c/freq)
2176 meteorAux[-2] = radialError
2176 meteorAux[-2] = radialError
2177 meteorAux[-3] = radialVelocity
2177 meteorAux[-3] = radialVelocity
2178
2178
2179 #Setting Error
2179 #Setting Error
2180 #Number 15: Radial Drift velocity or projected horizontal velocity exceeds 200 m/s
2180 #Number 15: Radial Drift velocity or projected horizontal velocity exceeds 200 m/s
2181 if numpy.abs(radialVelocity) > 200:
2181 if numpy.abs(radialVelocity) > 200:
2182 meteorAux[-1] = 15
2182 meteorAux[-1] = 15
2183 #Number 12: Poor fit to CCF variation for estimation of radial drift velocity
2183 #Number 12: Poor fit to CCF variation for estimation of radial drift velocity
2184 elif radialError > radialStdThresh:
2184 elif radialError > radialStdThresh:
2185 meteorAux[-1] = 12
2185 meteorAux[-1] = 12
2186
2186
2187 listMeteors1.append(meteorAux)
2187 listMeteors1.append(meteorAux)
2188 return listMeteors1
2188 return listMeteors1
2189
2189
2190 def __setNewArrays(self, listMeteors, date, heiRang):
2190 def __setNewArrays(self, listMeteors, date, heiRang):
2191
2191
2192 #New arrays
2192 #New arrays
2193 arrayMeteors = numpy.array(listMeteors)
2193 arrayMeteors = numpy.array(listMeteors)
2194 arrayParameters = numpy.zeros((len(listMeteors), 13))
2194 arrayParameters = numpy.zeros((len(listMeteors), 13))
2195
2195
2196 #Date inclusion
2196 #Date inclusion
2197 # date = re.findall(r'\((.*?)\)', date)
2197 # date = re.findall(r'\((.*?)\)', date)
2198 # date = date[0].split(',')
2198 # date = date[0].split(',')
2199 # date = map(int, date)
2199 # date = map(int, date)
2200 #
2200 #
2201 # if len(date)<6:
2201 # if len(date)<6:
2202 # date.append(0)
2202 # date.append(0)
2203 #
2203 #
2204 # date = [date[0]*10000 + date[1]*100 + date[2], date[3]*10000 + date[4]*100 + date[5]]
2204 # date = [date[0]*10000 + date[1]*100 + date[2], date[3]*10000 + date[4]*100 + date[5]]
2205 # arrayDate = numpy.tile(date, (len(listMeteors), 1))
2205 # arrayDate = numpy.tile(date, (len(listMeteors), 1))
2206 arrayDate = numpy.tile(date, (len(listMeteors)))
2206 arrayDate = numpy.tile(date, (len(listMeteors)))
2207
2207
2208 #Meteor array
2208 #Meteor array
2209 # arrayMeteors[:,0] = heiRang[arrayMeteors[:,0].astype(int)]
2209 # arrayMeteors[:,0] = heiRang[arrayMeteors[:,0].astype(int)]
2210 # arrayMeteors = numpy.hstack((arrayDate, arrayMeteors))
2210 # arrayMeteors = numpy.hstack((arrayDate, arrayMeteors))
2211
2211
2212 #Parameters Array
2212 #Parameters Array
2213 arrayParameters[:,0] = arrayDate #Date
2213 arrayParameters[:,0] = arrayDate #Date
2214 arrayParameters[:,1] = heiRang[arrayMeteors[:,0].astype(int)] #Range
2214 arrayParameters[:,1] = heiRang[arrayMeteors[:,0].astype(int)] #Range
2215 arrayParameters[:,6:8] = arrayMeteors[:,-3:-1] #Radial velocity and its error
2215 arrayParameters[:,6:8] = arrayMeteors[:,-3:-1] #Radial velocity and its error
2216 arrayParameters[:,8:12] = arrayMeteors[:,7:11] #Phases
2216 arrayParameters[:,8:12] = arrayMeteors[:,7:11] #Phases
2217 arrayParameters[:,-1] = arrayMeteors[:,-1] #Error
2217 arrayParameters[:,-1] = arrayMeteors[:,-1] #Error
2218
2218
2219
2219
2220 return arrayParameters
2220 return arrayParameters
2221
2221
2222 class CorrectSMPhases(Operation):
2222 class CorrectSMPhases(Operation):
2223 parameters = {
2224 'phaseOffsets': global_type_pairsList,
2225 'hmin': global_type_float,
2226 'hmax': global_type_float,
2227 'azimuth': global_type_float,
2228 'channelPositions': global_type_pairsList,
2229 }
2223
2230
2224 def run(self, dataOut, phaseOffsets, hmin = 50, hmax = 150, azimuth = 45, channelPositions = None):
2231 def run(self, dataOut, phaseOffsets, hmin = 50, hmax = 150, azimuth = 45, channelPositions = None):
2225
2232
2226 arrayParameters = dataOut.data_param
2233 arrayParameters = dataOut.data_param
2227 pairsList = []
2234 pairsList = []
2228 pairx = (0,1)
2235 pairx = (0,1)
2229 pairy = (2,3)
2236 pairy = (2,3)
2230 pairsList.append(pairx)
2237 pairsList.append(pairx)
2231 pairsList.append(pairy)
2238 pairsList.append(pairy)
2232 jph = numpy.zeros(4)
2239 jph = numpy.zeros(4)
2233
2240
2234 phaseOffsets = numpy.array(phaseOffsets)*numpy.pi/180
2241 phaseOffsets = numpy.array(phaseOffsets)*numpy.pi/180
2235 # arrayParameters[:,8:12] = numpy.unwrap(arrayParameters[:,8:12] + phaseOffsets)
2242 # arrayParameters[:,8:12] = numpy.unwrap(arrayParameters[:,8:12] + phaseOffsets)
2236 arrayParameters[:,8:12] = numpy.angle(numpy.exp(1j*(arrayParameters[:,8:12] + phaseOffsets)))
2243 arrayParameters[:,8:12] = numpy.angle(numpy.exp(1j*(arrayParameters[:,8:12] + phaseOffsets)))
2237
2244
2238 meteorOps = SMOperations()
2245 meteorOps = SMOperations()
2239 if channelPositions is None:
2246 if channelPositions is None:
2240 # channelPositions = [(2.5,0), (0,2.5), (0,0), (0,4.5), (-2,0)] #T
2247 # channelPositions = [(2.5,0), (0,2.5), (0,0), (0,4.5), (-2,0)] #T
2241 channelPositions = [(4.5,2), (2,4.5), (2,2), (2,0), (0,2)] #Estrella
2248 channelPositions = [(4.5,2), (2,4.5), (2,2), (2,0), (0,2)] #Estrella
2242
2249
2243 pairslist0, distances = meteorOps.getPhasePairs(channelPositions)
2250 pairslist0, distances = meteorOps.getPhasePairs(channelPositions)
2244 h = (hmin,hmax)
2251 h = (hmin,hmax)
2245
2252
2246 arrayParameters = meteorOps.getMeteorParams(arrayParameters, azimuth, h, pairsList, distances, jph)
2253 arrayParameters = meteorOps.getMeteorParams(arrayParameters, azimuth, h, pairsList, distances, jph)
2247
2254
2248 dataOut.data_param = arrayParameters
2255 dataOut.data_param = arrayParameters
2249 return
2256 return
2250
2257
2251 class SMPhaseCalibration(Operation):
2258 class SMPhaseCalibration(Operation):
2252
2259
2253 __buffer = None
2260 __buffer = None
2254
2261
2255 __initime = None
2262 __initime = None
2256
2263
2257 __dataReady = False
2264 __dataReady = False
2258
2265
2259 __isConfig = False
2266 __isConfig = False
2260
2267
2261 def __checkTime(self, currentTime, initTime, paramInterval, outputInterval):
2268 def __checkTime(self, currentTime, initTime, paramInterval, outputInterval):
2262
2269
2263 dataTime = currentTime + paramInterval
2270 dataTime = currentTime + paramInterval
2264 deltaTime = dataTime - initTime
2271 deltaTime = dataTime - initTime
2265
2272
2266 if deltaTime >= outputInterval or deltaTime < 0:
2273 if deltaTime >= outputInterval or deltaTime < 0:
2267 return True
2274 return True
2268
2275
2269 return False
2276 return False
2270
2277
2271 def __getGammas(self, pairs, d, phases):
2278 def __getGammas(self, pairs, d, phases):
2272 gammas = numpy.zeros(2)
2279 gammas = numpy.zeros(2)
2273
2280
2274 for i in range(len(pairs)):
2281 for i in range(len(pairs)):
2275
2282
2276 pairi = pairs[i]
2283 pairi = pairs[i]
2277
2284
2278 phip3 = phases[:,pairi[0]]
2285 phip3 = phases[:,pairi[0]]
2279 d3 = d[pairi[0]]
2286 d3 = d[pairi[0]]
2280 phip2 = phases[:,pairi[1]]
2287 phip2 = phases[:,pairi[1]]
2281 d2 = d[pairi[1]]
2288 d2 = d[pairi[1]]
2282 #Calculating gamma
2289 #Calculating gamma
2283 # jdcos = alp1/(k*d1)
2290 # jdcos = alp1/(k*d1)
2284 # jgamma = numpy.angle(numpy.exp(1j*(d0*alp1/d1 - alp0)))
2291 # jgamma = numpy.angle(numpy.exp(1j*(d0*alp1/d1 - alp0)))
2285 jgamma = -phip2*d3/d2 - phip3
2292 jgamma = -phip2*d3/d2 - phip3
2286 jgamma = numpy.angle(numpy.exp(1j*jgamma))
2293 jgamma = numpy.angle(numpy.exp(1j*jgamma))
2287 # jgamma[jgamma>numpy.pi] -= 2*numpy.pi
2294 # jgamma[jgamma>numpy.pi] -= 2*numpy.pi
2288 # jgamma[jgamma<-numpy.pi] += 2*numpy.pi
2295 # jgamma[jgamma<-numpy.pi] += 2*numpy.pi
2289
2296
2290 #Revised distribution
2297 #Revised distribution
2291 jgammaArray = numpy.hstack((jgamma,jgamma+0.5*numpy.pi,jgamma-0.5*numpy.pi))
2298 jgammaArray = numpy.hstack((jgamma,jgamma+0.5*numpy.pi,jgamma-0.5*numpy.pi))
2292
2299
2293 #Histogram
2300 #Histogram
2294 nBins = 64
2301 nBins = 64
2295 rmin = -0.5*numpy.pi
2302 rmin = -0.5*numpy.pi
2296 rmax = 0.5*numpy.pi
2303 rmax = 0.5*numpy.pi
2297 phaseHisto = numpy.histogram(jgammaArray, bins=nBins, range=(rmin,rmax))
2304 phaseHisto = numpy.histogram(jgammaArray, bins=nBins, range=(rmin,rmax))
2298
2305
2299 meteorsY = phaseHisto[0]
2306 meteorsY = phaseHisto[0]
2300 phasesX = phaseHisto[1][:-1]
2307 phasesX = phaseHisto[1][:-1]
2301 width = phasesX[1] - phasesX[0]
2308 width = phasesX[1] - phasesX[0]
2302 phasesX += width/2
2309 phasesX += width/2
2303
2310
2304 #Gaussian aproximation
2311 #Gaussian aproximation
2305 bpeak = meteorsY.argmax()
2312 bpeak = meteorsY.argmax()
2306 peak = meteorsY.max()
2313 peak = meteorsY.max()
2307 jmin = bpeak - 5
2314 jmin = bpeak - 5
2308 jmax = bpeak + 5 + 1
2315 jmax = bpeak + 5 + 1
2309
2316
2310 if jmin<0:
2317 if jmin<0:
2311 jmin = 0
2318 jmin = 0
2312 jmax = 6
2319 jmax = 6
2313 elif jmax > meteorsY.size:
2320 elif jmax > meteorsY.size:
2314 jmin = meteorsY.size - 6
2321 jmin = meteorsY.size - 6
2315 jmax = meteorsY.size
2322 jmax = meteorsY.size
2316
2323
2317 x0 = numpy.array([peak,bpeak,50])
2324 x0 = numpy.array([peak,bpeak,50])
2318 coeff = optimize.leastsq(self.__residualFunction, x0, args=(meteorsY[jmin:jmax], phasesX[jmin:jmax]))
2325 coeff = optimize.leastsq(self.__residualFunction, x0, args=(meteorsY[jmin:jmax], phasesX[jmin:jmax]))
2319
2326
2320 #Gammas
2327 #Gammas
2321 gammas[i] = coeff[0][1]
2328 gammas[i] = coeff[0][1]
2322
2329
2323 return gammas
2330 return gammas
2324
2331
2325 def __residualFunction(self, coeffs, y, t):
2332 def __residualFunction(self, coeffs, y, t):
2326
2333
2327 return y - self.__gauss_function(t, coeffs)
2334 return y - self.__gauss_function(t, coeffs)
2328
2335
2329 def __gauss_function(self, t, coeffs):
2336 def __gauss_function(self, t, coeffs):
2330
2337
2331 return coeffs[0]*numpy.exp(-0.5*((t - coeffs[1]) / coeffs[2])**2)
2338 return coeffs[0]*numpy.exp(-0.5*((t - coeffs[1]) / coeffs[2])**2)
2332
2339
2333 def __getPhases(self, azimuth, h, pairsList, d, gammas, meteorsArray):
2340 def __getPhases(self, azimuth, h, pairsList, d, gammas, meteorsArray):
2334 meteorOps = SMOperations()
2341 meteorOps = SMOperations()
2335 nchan = 4
2342 nchan = 4
2336 pairx = pairsList[0] #x es 0
2343 pairx = pairsList[0] #x es 0
2337 pairy = pairsList[1] #y es 1
2344 pairy = pairsList[1] #y es 1
2338 center_xangle = 0
2345 center_xangle = 0
2339 center_yangle = 0
2346 center_yangle = 0
2340 range_angle = numpy.array([10*numpy.pi,numpy.pi,numpy.pi/2,numpy.pi/4])
2347 range_angle = numpy.array([10*numpy.pi,numpy.pi,numpy.pi/2,numpy.pi/4])
2341 ntimes = len(range_angle)
2348 ntimes = len(range_angle)
2342
2349
2343 nstepsx = 20
2350 nstepsx = 20
2344 nstepsy = 20
2351 nstepsy = 20
2345
2352
2346 for iz in range(ntimes):
2353 for iz in range(ntimes):
2347 min_xangle = -range_angle[iz]/2 + center_xangle
2354 min_xangle = -range_angle[iz]/2 + center_xangle
2348 max_xangle = range_angle[iz]/2 + center_xangle
2355 max_xangle = range_angle[iz]/2 + center_xangle
2349 min_yangle = -range_angle[iz]/2 + center_yangle
2356 min_yangle = -range_angle[iz]/2 + center_yangle
2350 max_yangle = range_angle[iz]/2 + center_yangle
2357 max_yangle = range_angle[iz]/2 + center_yangle
2351
2358
2352 inc_x = (max_xangle-min_xangle)/nstepsx
2359 inc_x = (max_xangle-min_xangle)/nstepsx
2353 inc_y = (max_yangle-min_yangle)/nstepsy
2360 inc_y = (max_yangle-min_yangle)/nstepsy
2354
2361
2355 alpha_y = numpy.arange(nstepsy)*inc_y + min_yangle
2362 alpha_y = numpy.arange(nstepsy)*inc_y + min_yangle
2356 alpha_x = numpy.arange(nstepsx)*inc_x + min_xangle
2363 alpha_x = numpy.arange(nstepsx)*inc_x + min_xangle
2357 penalty = numpy.zeros((nstepsx,nstepsy))
2364 penalty = numpy.zeros((nstepsx,nstepsy))
2358 jph_array = numpy.zeros((nchan,nstepsx,nstepsy))
2365 jph_array = numpy.zeros((nchan,nstepsx,nstepsy))
2359 jph = numpy.zeros(nchan)
2366 jph = numpy.zeros(nchan)
2360
2367
2361 # Iterations looking for the offset
2368 # Iterations looking for the offset
2362 for iy in range(int(nstepsy)):
2369 for iy in range(int(nstepsy)):
2363 for ix in range(int(nstepsx)):
2370 for ix in range(int(nstepsx)):
2364 d3 = d[pairsList[1][0]]
2371 d3 = d[pairsList[1][0]]
2365 d2 = d[pairsList[1][1]]
2372 d2 = d[pairsList[1][1]]
2366 d5 = d[pairsList[0][0]]
2373 d5 = d[pairsList[0][0]]
2367 d4 = d[pairsList[0][1]]
2374 d4 = d[pairsList[0][1]]
2368
2375
2369 alp2 = alpha_y[iy] #gamma 1
2376 alp2 = alpha_y[iy] #gamma 1
2370 alp4 = alpha_x[ix] #gamma 0
2377 alp4 = alpha_x[ix] #gamma 0
2371
2378
2372 alp3 = -alp2*d3/d2 - gammas[1]
2379 alp3 = -alp2*d3/d2 - gammas[1]
2373 alp5 = -alp4*d5/d4 - gammas[0]
2380 alp5 = -alp4*d5/d4 - gammas[0]
2374 # jph[pairy[1]] = alpha_y[iy]
2381 # jph[pairy[1]] = alpha_y[iy]
2375 # jph[pairy[0]] = -gammas[1] - alpha_y[iy]*d[pairy[1]]/d[pairy[0]]
2382 # jph[pairy[0]] = -gammas[1] - alpha_y[iy]*d[pairy[1]]/d[pairy[0]]
2376
2383
2377 # jph[pairx[1]] = alpha_x[ix]
2384 # jph[pairx[1]] = alpha_x[ix]
2378 # jph[pairx[0]] = -gammas[0] - alpha_x[ix]*d[pairx[1]]/d[pairx[0]]
2385 # jph[pairx[0]] = -gammas[0] - alpha_x[ix]*d[pairx[1]]/d[pairx[0]]
2379 jph[pairsList[0][1]] = alp4
2386 jph[pairsList[0][1]] = alp4
2380 jph[pairsList[0][0]] = alp5
2387 jph[pairsList[0][0]] = alp5
2381 jph[pairsList[1][0]] = alp3
2388 jph[pairsList[1][0]] = alp3
2382 jph[pairsList[1][1]] = alp2
2389 jph[pairsList[1][1]] = alp2
2383 jph_array[:,ix,iy] = jph
2390 jph_array[:,ix,iy] = jph
2384 # d = [2.0,2.5,2.5,2.0]
2391 # d = [2.0,2.5,2.5,2.0]
2385 #falta chequear si va a leer bien los meteoros
2392 #falta chequear si va a leer bien los meteoros
2386 meteorsArray1 = meteorOps.getMeteorParams(meteorsArray, azimuth, h, pairsList, d, jph)
2393 meteorsArray1 = meteorOps.getMeteorParams(meteorsArray, azimuth, h, pairsList, d, jph)
2387 error = meteorsArray1[:,-1]
2394 error = meteorsArray1[:,-1]
2388 ind1 = numpy.where(error==0)[0]
2395 ind1 = numpy.where(error==0)[0]
2389 penalty[ix,iy] = ind1.size
2396 penalty[ix,iy] = ind1.size
2390
2397
2391 i,j = numpy.unravel_index(penalty.argmax(), penalty.shape)
2398 i,j = numpy.unravel_index(penalty.argmax(), penalty.shape)
2392 phOffset = jph_array[:,i,j]
2399 phOffset = jph_array[:,i,j]
2393
2400
2394 center_xangle = phOffset[pairx[1]]
2401 center_xangle = phOffset[pairx[1]]
2395 center_yangle = phOffset[pairy[1]]
2402 center_yangle = phOffset[pairy[1]]
2396
2403
2397 phOffset = numpy.angle(numpy.exp(1j*jph_array[:,i,j]))
2404 phOffset = numpy.angle(numpy.exp(1j*jph_array[:,i,j]))
2398 phOffset = phOffset*180/numpy.pi
2405 phOffset = phOffset*180/numpy.pi
2399 return phOffset
2406 return phOffset
2400
2407
2401
2408
2402 def run(self, dataOut, hmin, hmax, channelPositions=None, nHours = 1):
2409 def run(self, dataOut, hmin, hmax, channelPositions=None, nHours = 1):
2403
2410
2404 dataOut.flagNoData = True
2411 dataOut.flagNoData = True
2405 self.__dataReady = False
2412 self.__dataReady = False
2406 dataOut.outputInterval = nHours*3600
2413 dataOut.outputInterval = nHours*3600
2407
2414
2408 if self.__isConfig == False:
2415 if self.__isConfig == False:
2409 # self.__initime = dataOut.datatime.replace(minute = 0, second = 0, microsecond = 03)
2416 # self.__initime = dataOut.datatime.replace(minute = 0, second = 0, microsecond = 03)
2410 #Get Initial LTC time
2417 #Get Initial LTC time
2411 self.__initime = datetime.datetime.utcfromtimestamp(dataOut.utctime)
2418 self.__initime = datetime.datetime.utcfromtimestamp(dataOut.utctime)
2412 self.__initime = (self.__initime.replace(minute = 0, second = 0, microsecond = 0) - datetime.datetime(1970, 1, 1)).total_seconds()
2419 self.__initime = (self.__initime.replace(minute = 0, second = 0, microsecond = 0) - datetime.datetime(1970, 1, 1)).total_seconds()
2413
2420
2414 self.__isConfig = True
2421 self.__isConfig = True
2415
2422
2416 if self.__buffer is None:
2423 if self.__buffer is None:
2417 self.__buffer = dataOut.data_param.copy()
2424 self.__buffer = dataOut.data_param.copy()
2418
2425
2419 else:
2426 else:
2420 self.__buffer = numpy.vstack((self.__buffer, dataOut.data_param))
2427 self.__buffer = numpy.vstack((self.__buffer, dataOut.data_param))
2421
2428
2422 self.__dataReady = self.__checkTime(dataOut.utctime, self.__initime, dataOut.paramInterval, dataOut.outputInterval) #Check if the buffer is ready
2429 self.__dataReady = self.__checkTime(dataOut.utctime, self.__initime, dataOut.paramInterval, dataOut.outputInterval) #Check if the buffer is ready
2423
2430
2424 if self.__dataReady:
2431 if self.__dataReady:
2425 dataOut.utctimeInit = self.__initime
2432 dataOut.utctimeInit = self.__initime
2426 self.__initime += dataOut.outputInterval #to erase time offset
2433 self.__initime += dataOut.outputInterval #to erase time offset
2427
2434
2428 freq = dataOut.frequency
2435 freq = dataOut.frequency
2429 c = dataOut.C #m/s
2436 c = dataOut.C #m/s
2430 lamb = c/freq
2437 lamb = c/freq
2431 k = 2*numpy.pi/lamb
2438 k = 2*numpy.pi/lamb
2432 azimuth = 0
2439 azimuth = 0
2433 h = (hmin, hmax)
2440 h = (hmin, hmax)
2434 # pairs = ((0,1),(2,3)) #Estrella
2441 # pairs = ((0,1),(2,3)) #Estrella
2435 # pairs = ((1,0),(2,3)) #T
2442 # pairs = ((1,0),(2,3)) #T
2436
2443
2437 if channelPositions is None:
2444 if channelPositions is None:
2438 # channelPositions = [(2.5,0), (0,2.5), (0,0), (0,4.5), (-2,0)] #T
2445 # channelPositions = [(2.5,0), (0,2.5), (0,0), (0,4.5), (-2,0)] #T
2439 channelPositions = [(4.5,2), (2,4.5), (2,2), (2,0), (0,2)] #Estrella
2446 channelPositions = [(4.5,2), (2,4.5), (2,2), (2,0), (0,2)] #Estrella
2440 meteorOps = SMOperations()
2447 meteorOps = SMOperations()
2441 pairslist0, distances = meteorOps.getPhasePairs(channelPositions)
2448 pairslist0, distances = meteorOps.getPhasePairs(channelPositions)
2442
2449
2443 #Checking correct order of pairs
2450 #Checking correct order of pairs
2444 pairs = []
2451 pairs = []
2445 if distances[1] > distances[0]:
2452 if distances[1] > distances[0]:
2446 pairs.append((1,0))
2453 pairs.append((1,0))
2447 else:
2454 else:
2448 pairs.append((0,1))
2455 pairs.append((0,1))
2449
2456
2450 if distances[3] > distances[2]:
2457 if distances[3] > distances[2]:
2451 pairs.append((3,2))
2458 pairs.append((3,2))
2452 else:
2459 else:
2453 pairs.append((2,3))
2460 pairs.append((2,3))
2454 # distances1 = [-distances[0]*lamb, distances[1]*lamb, -distances[2]*lamb, distances[3]*lamb]
2461 # distances1 = [-distances[0]*lamb, distances[1]*lamb, -distances[2]*lamb, distances[3]*lamb]
2455
2462
2456 meteorsArray = self.__buffer
2463 meteorsArray = self.__buffer
2457 error = meteorsArray[:,-1]
2464 error = meteorsArray[:,-1]
2458 boolError = (error==0)|(error==3)|(error==4)|(error==13)|(error==14)
2465 boolError = (error==0)|(error==3)|(error==4)|(error==13)|(error==14)
2459 ind1 = numpy.where(boolError)[0]
2466 ind1 = numpy.where(boolError)[0]
2460 meteorsArray = meteorsArray[ind1,:]
2467 meteorsArray = meteorsArray[ind1,:]
2461 meteorsArray[:,-1] = 0
2468 meteorsArray[:,-1] = 0
2462 phases = meteorsArray[:,8:12]
2469 phases = meteorsArray[:,8:12]
2463
2470
2464 #Calculate Gammas
2471 #Calculate Gammas
2465 gammas = self.__getGammas(pairs, distances, phases)
2472 gammas = self.__getGammas(pairs, distances, phases)
2466 # gammas = numpy.array([-21.70409463,45.76935864])*numpy.pi/180
2473 # gammas = numpy.array([-21.70409463,45.76935864])*numpy.pi/180
2467 #Calculate Phases
2474 #Calculate Phases
2468 phasesOff = self.__getPhases(azimuth, h, pairs, distances, gammas, meteorsArray)
2475 phasesOff = self.__getPhases(azimuth, h, pairs, distances, gammas, meteorsArray)
2469 phasesOff = phasesOff.reshape((1,phasesOff.size))
2476 phasesOff = phasesOff.reshape((1,phasesOff.size))
2470 dataOut.data_output = -phasesOff
2477 dataOut.data_output = -phasesOff
2471 dataOut.flagNoData = False
2478 dataOut.flagNoData = False
2472 dataOut.channelList = pairslist0
2479 dataOut.channelList = pairslist0
2473 self.__buffer = None
2480 self.__buffer = None
2474
2481
2475
2482
2476 return
2483 return
2477
2484
2478 class SMOperations():
2485 class SMOperations():
2479
2486
2480 def __init__(self):
2487 def __init__(self):
2481
2488
2482 return
2489 return
2483
2490
2484 def getMeteorParams(self, arrayParameters0, azimuth, h, pairsList, distances, jph):
2491 def getMeteorParams(self, arrayParameters0, azimuth, h, pairsList, distances, jph):
2485
2492
2486 arrayParameters = arrayParameters0.copy()
2493 arrayParameters = arrayParameters0.copy()
2487 hmin = h[0]
2494 hmin = h[0]
2488 hmax = h[1]
2495 hmax = h[1]
2489
2496
2490 #Calculate AOA (Error N 3, 4)
2497 #Calculate AOA (Error N 3, 4)
2491 #JONES ET AL. 1998
2498 #JONES ET AL. 1998
2492 AOAthresh = numpy.pi/8
2499 AOAthresh = numpy.pi/8
2493 error = arrayParameters[:,-1]
2500 error = arrayParameters[:,-1]
2494 phases = -arrayParameters[:,8:12] + jph
2501 phases = -arrayParameters[:,8:12] + jph
2495 # phases = numpy.unwrap(phases)
2502 # phases = numpy.unwrap(phases)
2496 arrayParameters[:,3:6], arrayParameters[:,-1] = self.__getAOA(phases, pairsList, distances, error, AOAthresh, azimuth)
2503 arrayParameters[:,3:6], arrayParameters[:,-1] = self.__getAOA(phases, pairsList, distances, error, AOAthresh, azimuth)
2497
2504
2498 #Calculate Heights (Error N 13 and 14)
2505 #Calculate Heights (Error N 13 and 14)
2499 error = arrayParameters[:,-1]
2506 error = arrayParameters[:,-1]
2500 Ranges = arrayParameters[:,1]
2507 Ranges = arrayParameters[:,1]
2501 zenith = arrayParameters[:,4]
2508 zenith = arrayParameters[:,4]
2502 arrayParameters[:,2], arrayParameters[:,-1] = self.__getHeights(Ranges, zenith, error, hmin, hmax)
2509 arrayParameters[:,2], arrayParameters[:,-1] = self.__getHeights(Ranges, zenith, error, hmin, hmax)
2503
2510
2504 #----------------------- Get Final data ------------------------------------
2511 #----------------------- Get Final data ------------------------------------
2505 # error = arrayParameters[:,-1]
2512 # error = arrayParameters[:,-1]
2506 # ind1 = numpy.where(error==0)[0]
2513 # ind1 = numpy.where(error==0)[0]
2507 # arrayParameters = arrayParameters[ind1,:]
2514 # arrayParameters = arrayParameters[ind1,:]
2508
2515
2509 return arrayParameters
2516 return arrayParameters
2510
2517
2511 def __getAOA(self, phases, pairsList, directions, error, AOAthresh, azimuth):
2518 def __getAOA(self, phases, pairsList, directions, error, AOAthresh, azimuth):
2512
2519
2513 arrayAOA = numpy.zeros((phases.shape[0],3))
2520 arrayAOA = numpy.zeros((phases.shape[0],3))
2514 cosdir0, cosdir = self.__getDirectionCosines(phases, pairsList,directions)
2521 cosdir0, cosdir = self.__getDirectionCosines(phases, pairsList,directions)
2515
2522
2516 arrayAOA[:,:2] = self.__calculateAOA(cosdir, azimuth)
2523 arrayAOA[:,:2] = self.__calculateAOA(cosdir, azimuth)
2517 cosDirError = numpy.sum(numpy.abs(cosdir0 - cosdir), axis = 1)
2524 cosDirError = numpy.sum(numpy.abs(cosdir0 - cosdir), axis = 1)
2518 arrayAOA[:,2] = cosDirError
2525 arrayAOA[:,2] = cosDirError
2519
2526
2520 azimuthAngle = arrayAOA[:,0]
2527 azimuthAngle = arrayAOA[:,0]
2521 zenithAngle = arrayAOA[:,1]
2528 zenithAngle = arrayAOA[:,1]
2522
2529
2523 #Setting Error
2530 #Setting Error
2524 indError = numpy.where(numpy.logical_or(error == 3, error == 4))[0]
2531 indError = numpy.where(numpy.logical_or(error == 3, error == 4))[0]
2525 error[indError] = 0
2532 error[indError] = 0
2526 #Number 3: AOA not fesible
2533 #Number 3: AOA not fesible
2527 indInvalid = numpy.where(numpy.logical_and((numpy.logical_or(numpy.isnan(zenithAngle), numpy.isnan(azimuthAngle))),error == 0))[0]
2534 indInvalid = numpy.where(numpy.logical_and((numpy.logical_or(numpy.isnan(zenithAngle), numpy.isnan(azimuthAngle))),error == 0))[0]
2528 error[indInvalid] = 3
2535 error[indInvalid] = 3
2529 #Number 4: Large difference in AOAs obtained from different antenna baselines
2536 #Number 4: Large difference in AOAs obtained from different antenna baselines
2530 indInvalid = numpy.where(numpy.logical_and(cosDirError > AOAthresh,error == 0))[0]
2537 indInvalid = numpy.where(numpy.logical_and(cosDirError > AOAthresh,error == 0))[0]
2531 error[indInvalid] = 4
2538 error[indInvalid] = 4
2532 return arrayAOA, error
2539 return arrayAOA, error
2533
2540
2534 def __getDirectionCosines(self, arrayPhase, pairsList, distances):
2541 def __getDirectionCosines(self, arrayPhase, pairsList, distances):
2535
2542
2536 #Initializing some variables
2543 #Initializing some variables
2537 ang_aux = numpy.array([-8,-7,-6,-5,-4,-3,-2,-1,0,1,2,3,4,5,6,7,8])*2*numpy.pi
2544 ang_aux = numpy.array([-8,-7,-6,-5,-4,-3,-2,-1,0,1,2,3,4,5,6,7,8])*2*numpy.pi
2538 ang_aux = ang_aux.reshape(1,ang_aux.size)
2545 ang_aux = ang_aux.reshape(1,ang_aux.size)
2539
2546
2540 cosdir = numpy.zeros((arrayPhase.shape[0],2))
2547 cosdir = numpy.zeros((arrayPhase.shape[0],2))
2541 cosdir0 = numpy.zeros((arrayPhase.shape[0],2))
2548 cosdir0 = numpy.zeros((arrayPhase.shape[0],2))
2542
2549
2543
2550
2544 for i in range(2):
2551 for i in range(2):
2545 ph0 = arrayPhase[:,pairsList[i][0]]
2552 ph0 = arrayPhase[:,pairsList[i][0]]
2546 ph1 = arrayPhase[:,pairsList[i][1]]
2553 ph1 = arrayPhase[:,pairsList[i][1]]
2547 d0 = distances[pairsList[i][0]]
2554 d0 = distances[pairsList[i][0]]
2548 d1 = distances[pairsList[i][1]]
2555 d1 = distances[pairsList[i][1]]
2549
2556
2550 ph0_aux = ph0 + ph1
2557 ph0_aux = ph0 + ph1
2551 ph0_aux = numpy.angle(numpy.exp(1j*ph0_aux))
2558 ph0_aux = numpy.angle(numpy.exp(1j*ph0_aux))
2552 # ph0_aux[ph0_aux > numpy.pi] -= 2*numpy.pi
2559 # ph0_aux[ph0_aux > numpy.pi] -= 2*numpy.pi
2553 # ph0_aux[ph0_aux < -numpy.pi] += 2*numpy.pi
2560 # ph0_aux[ph0_aux < -numpy.pi] += 2*numpy.pi
2554 #First Estimation
2561 #First Estimation
2555 cosdir0[:,i] = (ph0_aux)/(2*numpy.pi*(d0 - d1))
2562 cosdir0[:,i] = (ph0_aux)/(2*numpy.pi*(d0 - d1))
2556
2563
2557 #Most-Accurate Second Estimation
2564 #Most-Accurate Second Estimation
2558 phi1_aux = ph0 - ph1
2565 phi1_aux = ph0 - ph1
2559 phi1_aux = phi1_aux.reshape(phi1_aux.size,1)
2566 phi1_aux = phi1_aux.reshape(phi1_aux.size,1)
2560 #Direction Cosine 1
2567 #Direction Cosine 1
2561 cosdir1 = (phi1_aux + ang_aux)/(2*numpy.pi*(d0 + d1))
2568 cosdir1 = (phi1_aux + ang_aux)/(2*numpy.pi*(d0 + d1))
2562
2569
2563 #Searching the correct Direction Cosine
2570 #Searching the correct Direction Cosine
2564 cosdir0_aux = cosdir0[:,i]
2571 cosdir0_aux = cosdir0[:,i]
2565 cosdir0_aux = cosdir0_aux.reshape(cosdir0_aux.size,1)
2572 cosdir0_aux = cosdir0_aux.reshape(cosdir0_aux.size,1)
2566 #Minimum Distance
2573 #Minimum Distance
2567 cosDiff = (cosdir1 - cosdir0_aux)**2
2574 cosDiff = (cosdir1 - cosdir0_aux)**2
2568 indcos = cosDiff.argmin(axis = 1)
2575 indcos = cosDiff.argmin(axis = 1)
2569 #Saving Value obtained
2576 #Saving Value obtained
2570 cosdir[:,i] = cosdir1[numpy.arange(len(indcos)),indcos]
2577 cosdir[:,i] = cosdir1[numpy.arange(len(indcos)),indcos]
2571
2578
2572 return cosdir0, cosdir
2579 return cosdir0, cosdir
2573
2580
2574 def __calculateAOA(self, cosdir, azimuth):
2581 def __calculateAOA(self, cosdir, azimuth):
2575 cosdirX = cosdir[:,0]
2582 cosdirX = cosdir[:,0]
2576 cosdirY = cosdir[:,1]
2583 cosdirY = cosdir[:,1]
2577
2584
2578 zenithAngle = numpy.arccos(numpy.sqrt(1 - cosdirX**2 - cosdirY**2))*180/numpy.pi
2585 zenithAngle = numpy.arccos(numpy.sqrt(1 - cosdirX**2 - cosdirY**2))*180/numpy.pi
2579 azimuthAngle = numpy.arctan2(cosdirX,cosdirY)*180/numpy.pi + azimuth#0 deg north, 90 deg east
2586 azimuthAngle = numpy.arctan2(cosdirX,cosdirY)*180/numpy.pi + azimuth#0 deg north, 90 deg east
2580 angles = numpy.vstack((azimuthAngle, zenithAngle)).transpose()
2587 angles = numpy.vstack((azimuthAngle, zenithAngle)).transpose()
2581
2588
2582 return angles
2589 return angles
2583
2590
2584 def __getHeights(self, Ranges, zenith, error, minHeight, maxHeight):
2591 def __getHeights(self, Ranges, zenith, error, minHeight, maxHeight):
2585
2592
2586 Ramb = 375 #Ramb = c/(2*PRF)
2593 Ramb = 375 #Ramb = c/(2*PRF)
2587 Re = 6371 #Earth Radius
2594 Re = 6371 #Earth Radius
2588 heights = numpy.zeros(Ranges.shape)
2595 heights = numpy.zeros(Ranges.shape)
2589
2596
2590 R_aux = numpy.array([0,1,2])*Ramb
2597 R_aux = numpy.array([0,1,2])*Ramb
2591 R_aux = R_aux.reshape(1,R_aux.size)
2598 R_aux = R_aux.reshape(1,R_aux.size)
2592
2599
2593 Ranges = Ranges.reshape(Ranges.size,1)
2600 Ranges = Ranges.reshape(Ranges.size,1)
2594
2601
2595 Ri = Ranges + R_aux
2602 Ri = Ranges + R_aux
2596 hi = numpy.sqrt(Re**2 + Ri**2 + (2*Re*numpy.cos(zenith*numpy.pi/180)*Ri.transpose()).transpose()) - Re
2603 hi = numpy.sqrt(Re**2 + Ri**2 + (2*Re*numpy.cos(zenith*numpy.pi/180)*Ri.transpose()).transpose()) - Re
2597
2604
2598 #Check if there is a height between 70 and 110 km
2605 #Check if there is a height between 70 and 110 km
2599 h_bool = numpy.sum(numpy.logical_and(hi > minHeight, hi < maxHeight), axis = 1)
2606 h_bool = numpy.sum(numpy.logical_and(hi > minHeight, hi < maxHeight), axis = 1)
2600 ind_h = numpy.where(h_bool == 1)[0]
2607 ind_h = numpy.where(h_bool == 1)[0]
2601
2608
2602 hCorr = hi[ind_h, :]
2609 hCorr = hi[ind_h, :]
2603 ind_hCorr = numpy.where(numpy.logical_and(hi > minHeight, hi < maxHeight))
2610 ind_hCorr = numpy.where(numpy.logical_and(hi > minHeight, hi < maxHeight))
2604
2611
2605 hCorr = hi[ind_hCorr][:len(ind_h)]
2612 hCorr = hi[ind_hCorr][:len(ind_h)]
2606 heights[ind_h] = hCorr
2613 heights[ind_h] = hCorr
2607
2614
2608 #Setting Error
2615 #Setting Error
2609 #Number 13: Height unresolvable echo: not valid height within 70 to 110 km
2616 #Number 13: Height unresolvable echo: not valid height within 70 to 110 km
2610 #Number 14: Height ambiguous echo: more than one possible height within 70 to 110 km
2617 #Number 14: Height ambiguous echo: more than one possible height within 70 to 110 km
2611 indError = numpy.where(numpy.logical_or(error == 13, error == 14))[0]
2618 indError = numpy.where(numpy.logical_or(error == 13, error == 14))[0]
2612 error[indError] = 0
2619 error[indError] = 0
2613 indInvalid2 = numpy.where(numpy.logical_and(h_bool > 1, error == 0))[0]
2620 indInvalid2 = numpy.where(numpy.logical_and(h_bool > 1, error == 0))[0]
2614 error[indInvalid2] = 14
2621 error[indInvalid2] = 14
2615 indInvalid1 = numpy.where(numpy.logical_and(h_bool == 0, error == 0))[0]
2622 indInvalid1 = numpy.where(numpy.logical_and(h_bool == 0, error == 0))[0]
2616 error[indInvalid1] = 13
2623 error[indInvalid1] = 13
2617
2624
2618 return heights, error
2625 return heights, error
2619
2626
2620 def getPhasePairs(self, channelPositions):
2627 def getPhasePairs(self, channelPositions):
2621 chanPos = numpy.array(channelPositions)
2628 chanPos = numpy.array(channelPositions)
2622 listOper = list(itertools.combinations(range(5),2))
2629 listOper = list(itertools.combinations(range(5),2))
2623
2630
2624 distances = numpy.zeros(4)
2631 distances = numpy.zeros(4)
2625 axisX = []
2632 axisX = []
2626 axisY = []
2633 axisY = []
2627 distX = numpy.zeros(3)
2634 distX = numpy.zeros(3)
2628 distY = numpy.zeros(3)
2635 distY = numpy.zeros(3)
2629 ix = 0
2636 ix = 0
2630 iy = 0
2637 iy = 0
2631
2638
2632 pairX = numpy.zeros((2,2))
2639 pairX = numpy.zeros((2,2))
2633 pairY = numpy.zeros((2,2))
2640 pairY = numpy.zeros((2,2))
2634
2641
2635 for i in range(len(listOper)):
2642 for i in range(len(listOper)):
2636 pairi = listOper[i]
2643 pairi = listOper[i]
2637
2644
2638 posDif = numpy.abs(chanPos[pairi[0],:] - chanPos[pairi[1],:])
2645 posDif = numpy.abs(chanPos[pairi[0],:] - chanPos[pairi[1],:])
2639
2646
2640 if posDif[0] == 0:
2647 if posDif[0] == 0:
2641 axisY.append(pairi)
2648 axisY.append(pairi)
2642 distY[iy] = posDif[1]
2649 distY[iy] = posDif[1]
2643 iy += 1
2650 iy += 1
2644 elif posDif[1] == 0:
2651 elif posDif[1] == 0:
2645 axisX.append(pairi)
2652 axisX.append(pairi)
2646 distX[ix] = posDif[0]
2653 distX[ix] = posDif[0]
2647 ix += 1
2654 ix += 1
2648
2655
2649 for i in range(2):
2656 for i in range(2):
2650 if i==0:
2657 if i==0:
2651 dist0 = distX
2658 dist0 = distX
2652 axis0 = axisX
2659 axis0 = axisX
2653 else:
2660 else:
2654 dist0 = distY
2661 dist0 = distY
2655 axis0 = axisY
2662 axis0 = axisY
2656
2663
2657 side = numpy.argsort(dist0)[:-1]
2664 side = numpy.argsort(dist0)[:-1]
2658 axis0 = numpy.array(axis0)[side,:]
2665 axis0 = numpy.array(axis0)[side,:]
2659 chanC = int(numpy.intersect1d(axis0[0,:], axis0[1,:])[0])
2666 chanC = int(numpy.intersect1d(axis0[0,:], axis0[1,:])[0])
2660 axis1 = numpy.unique(numpy.reshape(axis0,4))
2667 axis1 = numpy.unique(numpy.reshape(axis0,4))
2661 side = axis1[axis1 != chanC]
2668 side = axis1[axis1 != chanC]
2662 diff1 = chanPos[chanC,i] - chanPos[side[0],i]
2669 diff1 = chanPos[chanC,i] - chanPos[side[0],i]
2663 diff2 = chanPos[chanC,i] - chanPos[side[1],i]
2670 diff2 = chanPos[chanC,i] - chanPos[side[1],i]
2664 if diff1<0:
2671 if diff1<0:
2665 chan2 = side[0]
2672 chan2 = side[0]
2666 d2 = numpy.abs(diff1)
2673 d2 = numpy.abs(diff1)
2667 chan1 = side[1]
2674 chan1 = side[1]
2668 d1 = numpy.abs(diff2)
2675 d1 = numpy.abs(diff2)
2669 else:
2676 else:
2670 chan2 = side[1]
2677 chan2 = side[1]
2671 d2 = numpy.abs(diff2)
2678 d2 = numpy.abs(diff2)
2672 chan1 = side[0]
2679 chan1 = side[0]
2673 d1 = numpy.abs(diff1)
2680 d1 = numpy.abs(diff1)
2674
2681
2675 if i==0:
2682 if i==0:
2676 chanCX = chanC
2683 chanCX = chanC
2677 chan1X = chan1
2684 chan1X = chan1
2678 chan2X = chan2
2685 chan2X = chan2
2679 distances[0:2] = numpy.array([d1,d2])
2686 distances[0:2] = numpy.array([d1,d2])
2680 else:
2687 else:
2681 chanCY = chanC
2688 chanCY = chanC
2682 chan1Y = chan1
2689 chan1Y = chan1
2683 chan2Y = chan2
2690 chan2Y = chan2
2684 distances[2:4] = numpy.array([d1,d2])
2691 distances[2:4] = numpy.array([d1,d2])
2685 # axisXsides = numpy.reshape(axisX[ix,:],4)
2692 # axisXsides = numpy.reshape(axisX[ix,:],4)
2686 #
2693 #
2687 # channelCentX = int(numpy.intersect1d(pairX[0,:], pairX[1,:])[0])
2694 # channelCentX = int(numpy.intersect1d(pairX[0,:], pairX[1,:])[0])
2688 # channelCentY = int(numpy.intersect1d(pairY[0,:], pairY[1,:])[0])
2695 # channelCentY = int(numpy.intersect1d(pairY[0,:], pairY[1,:])[0])
2689 #
2696 #
2690 # ind25X = numpy.where(pairX[0,:] != channelCentX)[0][0]
2697 # ind25X = numpy.where(pairX[0,:] != channelCentX)[0][0]
2691 # ind20X = numpy.where(pairX[1,:] != channelCentX)[0][0]
2698 # ind20X = numpy.where(pairX[1,:] != channelCentX)[0][0]
2692 # channel25X = int(pairX[0,ind25X])
2699 # channel25X = int(pairX[0,ind25X])
2693 # channel20X = int(pairX[1,ind20X])
2700 # channel20X = int(pairX[1,ind20X])
2694 # ind25Y = numpy.where(pairY[0,:] != channelCentY)[0][0]
2701 # ind25Y = numpy.where(pairY[0,:] != channelCentY)[0][0]
2695 # ind20Y = numpy.where(pairY[1,:] != channelCentY)[0][0]
2702 # ind20Y = numpy.where(pairY[1,:] != channelCentY)[0][0]
2696 # channel25Y = int(pairY[0,ind25Y])
2703 # channel25Y = int(pairY[0,ind25Y])
2697 # channel20Y = int(pairY[1,ind20Y])
2704 # channel20Y = int(pairY[1,ind20Y])
2698
2705
2699 # pairslist = [(channelCentX, channel25X),(channelCentX, channel20X),(channelCentY,channel25Y),(channelCentY, channel20Y)]
2706 # pairslist = [(channelCentX, channel25X),(channelCentX, channel20X),(channelCentY,channel25Y),(channelCentY, channel20Y)]
2700 pairslist = [(chanCX, chan1X),(chanCX, chan2X),(chanCY,chan1Y),(chanCY, chan2Y)]
2707 pairslist = [(chanCX, chan1X),(chanCX, chan2X),(chanCY,chan1Y),(chanCY, chan2Y)]
2701
2708
2702 return pairslist, distances
2709 return pairslist, distances
2703 # def __getAOA(self, phases, pairsList, error, AOAthresh, azimuth):
2710 # def __getAOA(self, phases, pairsList, error, AOAthresh, azimuth):
2704 #
2711 #
2705 # arrayAOA = numpy.zeros((phases.shape[0],3))
2712 # arrayAOA = numpy.zeros((phases.shape[0],3))
2706 # cosdir0, cosdir = self.__getDirectionCosines(phases, pairsList)
2713 # cosdir0, cosdir = self.__getDirectionCosines(phases, pairsList)
2707 #
2714 #
2708 # arrayAOA[:,:2] = self.__calculateAOA(cosdir, azimuth)
2715 # arrayAOA[:,:2] = self.__calculateAOA(cosdir, azimuth)
2709 # cosDirError = numpy.sum(numpy.abs(cosdir0 - cosdir), axis = 1)
2716 # cosDirError = numpy.sum(numpy.abs(cosdir0 - cosdir), axis = 1)
2710 # arrayAOA[:,2] = cosDirError
2717 # arrayAOA[:,2] = cosDirError
2711 #
2718 #
2712 # azimuthAngle = arrayAOA[:,0]
2719 # azimuthAngle = arrayAOA[:,0]
2713 # zenithAngle = arrayAOA[:,1]
2720 # zenithAngle = arrayAOA[:,1]
2714 #
2721 #
2715 # #Setting Error
2722 # #Setting Error
2716 # #Number 3: AOA not fesible
2723 # #Number 3: AOA not fesible
2717 # indInvalid = numpy.where(numpy.logical_and((numpy.logical_or(numpy.isnan(zenithAngle), numpy.isnan(azimuthAngle))),error == 0))[0]
2724 # indInvalid = numpy.where(numpy.logical_and((numpy.logical_or(numpy.isnan(zenithAngle), numpy.isnan(azimuthAngle))),error == 0))[0]
2718 # error[indInvalid] = 3
2725 # error[indInvalid] = 3
2719 # #Number 4: Large difference in AOAs obtained from different antenna baselines
2726 # #Number 4: Large difference in AOAs obtained from different antenna baselines
2720 # indInvalid = numpy.where(numpy.logical_and(cosDirError > AOAthresh,error == 0))[0]
2727 # indInvalid = numpy.where(numpy.logical_and(cosDirError > AOAthresh,error == 0))[0]
2721 # error[indInvalid] = 4
2728 # error[indInvalid] = 4
2722 # return arrayAOA, error
2729 # return arrayAOA, error
2723 #
2730 #
2724 # def __getDirectionCosines(self, arrayPhase, pairsList):
2731 # def __getDirectionCosines(self, arrayPhase, pairsList):
2725 #
2732 #
2726 # #Initializing some variables
2733 # #Initializing some variables
2727 # ang_aux = numpy.array([-8,-7,-6,-5,-4,-3,-2,-1,0,1,2,3,4,5,6,7,8])*2*numpy.pi
2734 # ang_aux = numpy.array([-8,-7,-6,-5,-4,-3,-2,-1,0,1,2,3,4,5,6,7,8])*2*numpy.pi
2728 # ang_aux = ang_aux.reshape(1,ang_aux.size)
2735 # ang_aux = ang_aux.reshape(1,ang_aux.size)
2729 #
2736 #
2730 # cosdir = numpy.zeros((arrayPhase.shape[0],2))
2737 # cosdir = numpy.zeros((arrayPhase.shape[0],2))
2731 # cosdir0 = numpy.zeros((arrayPhase.shape[0],2))
2738 # cosdir0 = numpy.zeros((arrayPhase.shape[0],2))
2732 #
2739 #
2733 #
2740 #
2734 # for i in range(2):
2741 # for i in range(2):
2735 # #First Estimation
2742 # #First Estimation
2736 # phi0_aux = arrayPhase[:,pairsList[i][0]] + arrayPhase[:,pairsList[i][1]]
2743 # phi0_aux = arrayPhase[:,pairsList[i][0]] + arrayPhase[:,pairsList[i][1]]
2737 # #Dealias
2744 # #Dealias
2738 # indcsi = numpy.where(phi0_aux > numpy.pi)
2745 # indcsi = numpy.where(phi0_aux > numpy.pi)
2739 # phi0_aux[indcsi] -= 2*numpy.pi
2746 # phi0_aux[indcsi] -= 2*numpy.pi
2740 # indcsi = numpy.where(phi0_aux < -numpy.pi)
2747 # indcsi = numpy.where(phi0_aux < -numpy.pi)
2741 # phi0_aux[indcsi] += 2*numpy.pi
2748 # phi0_aux[indcsi] += 2*numpy.pi
2742 # #Direction Cosine 0
2749 # #Direction Cosine 0
2743 # cosdir0[:,i] = -(phi0_aux)/(2*numpy.pi*0.5)
2750 # cosdir0[:,i] = -(phi0_aux)/(2*numpy.pi*0.5)
2744 #
2751 #
2745 # #Most-Accurate Second Estimation
2752 # #Most-Accurate Second Estimation
2746 # phi1_aux = arrayPhase[:,pairsList[i][0]] - arrayPhase[:,pairsList[i][1]]
2753 # phi1_aux = arrayPhase[:,pairsList[i][0]] - arrayPhase[:,pairsList[i][1]]
2747 # phi1_aux = phi1_aux.reshape(phi1_aux.size,1)
2754 # phi1_aux = phi1_aux.reshape(phi1_aux.size,1)
2748 # #Direction Cosine 1
2755 # #Direction Cosine 1
2749 # cosdir1 = -(phi1_aux + ang_aux)/(2*numpy.pi*4.5)
2756 # cosdir1 = -(phi1_aux + ang_aux)/(2*numpy.pi*4.5)
2750 #
2757 #
2751 # #Searching the correct Direction Cosine
2758 # #Searching the correct Direction Cosine
2752 # cosdir0_aux = cosdir0[:,i]
2759 # cosdir0_aux = cosdir0[:,i]
2753 # cosdir0_aux = cosdir0_aux.reshape(cosdir0_aux.size,1)
2760 # cosdir0_aux = cosdir0_aux.reshape(cosdir0_aux.size,1)
2754 # #Minimum Distance
2761 # #Minimum Distance
2755 # cosDiff = (cosdir1 - cosdir0_aux)**2
2762 # cosDiff = (cosdir1 - cosdir0_aux)**2
2756 # indcos = cosDiff.argmin(axis = 1)
2763 # indcos = cosDiff.argmin(axis = 1)
2757 # #Saving Value obtained
2764 # #Saving Value obtained
2758 # cosdir[:,i] = cosdir1[numpy.arange(len(indcos)),indcos]
2765 # cosdir[:,i] = cosdir1[numpy.arange(len(indcos)),indcos]
2759 #
2766 #
2760 # return cosdir0, cosdir
2767 # return cosdir0, cosdir
2761 #
2768 #
2762 # def __calculateAOA(self, cosdir, azimuth):
2769 # def __calculateAOA(self, cosdir, azimuth):
2763 # cosdirX = cosdir[:,0]
2770 # cosdirX = cosdir[:,0]
2764 # cosdirY = cosdir[:,1]
2771 # cosdirY = cosdir[:,1]
2765 #
2772 #
2766 # zenithAngle = numpy.arccos(numpy.sqrt(1 - cosdirX**2 - cosdirY**2))*180/numpy.pi
2773 # zenithAngle = numpy.arccos(numpy.sqrt(1 - cosdirX**2 - cosdirY**2))*180/numpy.pi
2767 # azimuthAngle = numpy.arctan2(cosdirX,cosdirY)*180/numpy.pi + azimuth #0 deg north, 90 deg east
2774 # azimuthAngle = numpy.arctan2(cosdirX,cosdirY)*180/numpy.pi + azimuth #0 deg north, 90 deg east
2768 # angles = numpy.vstack((azimuthAngle, zenithAngle)).transpose()
2775 # angles = numpy.vstack((azimuthAngle, zenithAngle)).transpose()
2769 #
2776 #
2770 # return angles
2777 # return angles
2771 #
2778 #
2772 # def __getHeights(self, Ranges, zenith, error, minHeight, maxHeight):
2779 # def __getHeights(self, Ranges, zenith, error, minHeight, maxHeight):
2773 #
2780 #
2774 # Ramb = 375 #Ramb = c/(2*PRF)
2781 # Ramb = 375 #Ramb = c/(2*PRF)
2775 # Re = 6371 #Earth Radius
2782 # Re = 6371 #Earth Radius
2776 # heights = numpy.zeros(Ranges.shape)
2783 # heights = numpy.zeros(Ranges.shape)
2777 #
2784 #
2778 # R_aux = numpy.array([0,1,2])*Ramb
2785 # R_aux = numpy.array([0,1,2])*Ramb
2779 # R_aux = R_aux.reshape(1,R_aux.size)
2786 # R_aux = R_aux.reshape(1,R_aux.size)
2780 #
2787 #
2781 # Ranges = Ranges.reshape(Ranges.size,1)
2788 # Ranges = Ranges.reshape(Ranges.size,1)
2782 #
2789 #
2783 # Ri = Ranges + R_aux
2790 # Ri = Ranges + R_aux
2784 # hi = numpy.sqrt(Re**2 + Ri**2 + (2*Re*numpy.cos(zenith*numpy.pi/180)*Ri.transpose()).transpose()) - Re
2791 # hi = numpy.sqrt(Re**2 + Ri**2 + (2*Re*numpy.cos(zenith*numpy.pi/180)*Ri.transpose()).transpose()) - Re
2785 #
2792 #
2786 # #Check if there is a height between 70 and 110 km
2793 # #Check if there is a height between 70 and 110 km
2787 # h_bool = numpy.sum(numpy.logical_and(hi > minHeight, hi < maxHeight), axis = 1)
2794 # h_bool = numpy.sum(numpy.logical_and(hi > minHeight, hi < maxHeight), axis = 1)
2788 # ind_h = numpy.where(h_bool == 1)[0]
2795 # ind_h = numpy.where(h_bool == 1)[0]
2789 #
2796 #
2790 # hCorr = hi[ind_h, :]
2797 # hCorr = hi[ind_h, :]
2791 # ind_hCorr = numpy.where(numpy.logical_and(hi > minHeight, hi < maxHeight))
2798 # ind_hCorr = numpy.where(numpy.logical_and(hi > minHeight, hi < maxHeight))
2792 #
2799 #
2793 # hCorr = hi[ind_hCorr]
2800 # hCorr = hi[ind_hCorr]
2794 # heights[ind_h] = hCorr
2801 # heights[ind_h] = hCorr
2795 #
2802 #
2796 # #Setting Error
2803 # #Setting Error
2797 # #Number 13: Height unresolvable echo: not valid height within 70 to 110 km
2804 # #Number 13: Height unresolvable echo: not valid height within 70 to 110 km
2798 # #Number 14: Height ambiguous echo: more than one possible height within 70 to 110 km
2805 # #Number 14: Height ambiguous echo: more than one possible height within 70 to 110 km
2799 #
2806 #
2800 # indInvalid2 = numpy.where(numpy.logical_and(h_bool > 1, error == 0))[0]
2807 # indInvalid2 = numpy.where(numpy.logical_and(h_bool > 1, error == 0))[0]
2801 # error[indInvalid2] = 14
2808 # error[indInvalid2] = 14
2802 # indInvalid1 = numpy.where(numpy.logical_and(h_bool == 0, error == 0))[0]
2809 # indInvalid1 = numpy.where(numpy.logical_and(h_bool == 0, error == 0))[0]
2803 # error[indInvalid1] = 13
2810 # error[indInvalid1] = 13
2804 #
2811 #
2805 # return heights, error
2812 # return heights, error
@@ -1,904 +1,910
1 import numpy
1 import numpy
2
2
3 from jroproc_base import ProcessingUnit, Operation
3 from jroproc_base import ProcessingUnit, Operation
4 from schainpy.model.data.jrodata import Spectra
4 from schainpy.model.data.jrodata import Spectra
5 from schainpy.model.data.jrodata import hildebrand_sekhon
5 from schainpy.model.data.jrodata import hildebrand_sekhon
6
6
7 class SpectraProc(ProcessingUnit):
7 class SpectraProc(ProcessingUnit):
8
8
9 def __init__(self, **kwargs):
9 def __init__(self, **kwargs):
10
10
11 ProcessingUnit.__init__(self, **kwargs)
11 ProcessingUnit.__init__(self, **kwargs)
12
12
13 self.buffer = None
13 self.buffer = None
14 self.firstdatatime = None
14 self.firstdatatime = None
15 self.profIndex = 0
15 self.profIndex = 0
16 self.dataOut = Spectra()
16 self.dataOut = Spectra()
17 self.id_min = None
17 self.id_min = None
18 self.id_max = None
18 self.id_max = None
19
19
20 def __updateSpecFromVoltage(self):
20 def __updateSpecFromVoltage(self):
21
21
22 self.dataOut.timeZone = self.dataIn.timeZone
22 self.dataOut.timeZone = self.dataIn.timeZone
23 self.dataOut.dstFlag = self.dataIn.dstFlag
23 self.dataOut.dstFlag = self.dataIn.dstFlag
24 self.dataOut.errorCount = self.dataIn.errorCount
24 self.dataOut.errorCount = self.dataIn.errorCount
25 self.dataOut.useLocalTime = self.dataIn.useLocalTime
25 self.dataOut.useLocalTime = self.dataIn.useLocalTime
26
26
27 self.dataOut.radarControllerHeaderObj = self.dataIn.radarControllerHeaderObj.copy()
27 self.dataOut.radarControllerHeaderObj = self.dataIn.radarControllerHeaderObj.copy()
28 self.dataOut.systemHeaderObj = self.dataIn.systemHeaderObj.copy()
28 self.dataOut.systemHeaderObj = self.dataIn.systemHeaderObj.copy()
29 self.dataOut.channelList = self.dataIn.channelList
29 self.dataOut.channelList = self.dataIn.channelList
30 self.dataOut.heightList = self.dataIn.heightList
30 self.dataOut.heightList = self.dataIn.heightList
31 self.dataOut.dtype = numpy.dtype([('real','<f4'),('imag','<f4')])
31 self.dataOut.dtype = numpy.dtype([('real','<f4'),('imag','<f4')])
32
32
33 self.dataOut.nBaud = self.dataIn.nBaud
33 self.dataOut.nBaud = self.dataIn.nBaud
34 self.dataOut.nCode = self.dataIn.nCode
34 self.dataOut.nCode = self.dataIn.nCode
35 self.dataOut.code = self.dataIn.code
35 self.dataOut.code = self.dataIn.code
36 self.dataOut.nProfiles = self.dataOut.nFFTPoints
36 self.dataOut.nProfiles = self.dataOut.nFFTPoints
37
37
38 self.dataOut.flagDiscontinuousBlock = self.dataIn.flagDiscontinuousBlock
38 self.dataOut.flagDiscontinuousBlock = self.dataIn.flagDiscontinuousBlock
39 self.dataOut.utctime = self.firstdatatime
39 self.dataOut.utctime = self.firstdatatime
40 self.dataOut.flagDecodeData = self.dataIn.flagDecodeData #asumo q la data esta decodificada
40 self.dataOut.flagDecodeData = self.dataIn.flagDecodeData #asumo q la data esta decodificada
41 self.dataOut.flagDeflipData = self.dataIn.flagDeflipData #asumo q la data esta sin flip
41 self.dataOut.flagDeflipData = self.dataIn.flagDeflipData #asumo q la data esta sin flip
42 self.dataOut.flagShiftFFT = False
42 self.dataOut.flagShiftFFT = False
43
43
44 self.dataOut.nCohInt = self.dataIn.nCohInt
44 self.dataOut.nCohInt = self.dataIn.nCohInt
45 self.dataOut.nIncohInt = 1
45 self.dataOut.nIncohInt = 1
46
46
47 self.dataOut.windowOfFilter = self.dataIn.windowOfFilter
47 self.dataOut.windowOfFilter = self.dataIn.windowOfFilter
48
48
49 self.dataOut.frequency = self.dataIn.frequency
49 self.dataOut.frequency = self.dataIn.frequency
50 self.dataOut.realtime = self.dataIn.realtime
50 self.dataOut.realtime = self.dataIn.realtime
51
51
52 self.dataOut.azimuth = self.dataIn.azimuth
52 self.dataOut.azimuth = self.dataIn.azimuth
53 self.dataOut.zenith = self.dataIn.zenith
53 self.dataOut.zenith = self.dataIn.zenith
54
54
55 self.dataOut.beam.codeList = self.dataIn.beam.codeList
55 self.dataOut.beam.codeList = self.dataIn.beam.codeList
56 self.dataOut.beam.azimuthList = self.dataIn.beam.azimuthList
56 self.dataOut.beam.azimuthList = self.dataIn.beam.azimuthList
57 self.dataOut.beam.zenithList = self.dataIn.beam.zenithList
57 self.dataOut.beam.zenithList = self.dataIn.beam.zenithList
58
58
59 def __getFft(self):
59 def __getFft(self):
60 """
60 """
61 Convierte valores de Voltaje a Spectra
61 Convierte valores de Voltaje a Spectra
62
62
63 Affected:
63 Affected:
64 self.dataOut.data_spc
64 self.dataOut.data_spc
65 self.dataOut.data_cspc
65 self.dataOut.data_cspc
66 self.dataOut.data_dc
66 self.dataOut.data_dc
67 self.dataOut.heightList
67 self.dataOut.heightList
68 self.profIndex
68 self.profIndex
69 self.buffer
69 self.buffer
70 self.dataOut.flagNoData
70 self.dataOut.flagNoData
71 """
71 """
72 fft_volt = numpy.fft.fft(self.buffer,n=self.dataOut.nFFTPoints,axis=1)
72 fft_volt = numpy.fft.fft(self.buffer,n=self.dataOut.nFFTPoints,axis=1)
73 fft_volt = fft_volt.astype(numpy.dtype('complex'))
73 fft_volt = fft_volt.astype(numpy.dtype('complex'))
74 dc = fft_volt[:,0,:]
74 dc = fft_volt[:,0,:]
75
75
76 #calculo de self-spectra
76 #calculo de self-spectra
77 fft_volt = numpy.fft.fftshift(fft_volt,axes=(1,))
77 fft_volt = numpy.fft.fftshift(fft_volt,axes=(1,))
78 spc = fft_volt * numpy.conjugate(fft_volt)
78 spc = fft_volt * numpy.conjugate(fft_volt)
79 spc = spc.real
79 spc = spc.real
80
80
81 blocksize = 0
81 blocksize = 0
82 blocksize += dc.size
82 blocksize += dc.size
83 blocksize += spc.size
83 blocksize += spc.size
84
84
85 cspc = None
85 cspc = None
86 pairIndex = 0
86 pairIndex = 0
87 if self.dataOut.pairsList != None:
87 if self.dataOut.pairsList != None:
88 #calculo de cross-spectra
88 #calculo de cross-spectra
89 cspc = numpy.zeros((self.dataOut.nPairs, self.dataOut.nFFTPoints, self.dataOut.nHeights), dtype='complex')
89 cspc = numpy.zeros((self.dataOut.nPairs, self.dataOut.nFFTPoints, self.dataOut.nHeights), dtype='complex')
90 for pair in self.dataOut.pairsList:
90 for pair in self.dataOut.pairsList:
91 if pair[0] not in self.dataOut.channelList:
91 if pair[0] not in self.dataOut.channelList:
92 raise ValueError, "Error getting CrossSpectra: pair 0 of %s is not in channelList = %s" %(str(pair), str(self.dataOut.channelList))
92 raise ValueError, "Error getting CrossSpectra: pair 0 of %s is not in channelList = %s" %(str(pair), str(self.dataOut.channelList))
93 if pair[1] not in self.dataOut.channelList:
93 if pair[1] not in self.dataOut.channelList:
94 raise ValueError, "Error getting CrossSpectra: pair 1 of %s is not in channelList = %s" %(str(pair), str(self.dataOut.channelList))
94 raise ValueError, "Error getting CrossSpectra: pair 1 of %s is not in channelList = %s" %(str(pair), str(self.dataOut.channelList))
95
95
96 cspc[pairIndex,:,:] = fft_volt[pair[0],:,:] * numpy.conjugate(fft_volt[pair[1],:,:])
96 cspc[pairIndex,:,:] = fft_volt[pair[0],:,:] * numpy.conjugate(fft_volt[pair[1],:,:])
97 pairIndex += 1
97 pairIndex += 1
98 blocksize += cspc.size
98 blocksize += cspc.size
99
99
100 self.dataOut.data_spc = spc
100 self.dataOut.data_spc = spc
101 self.dataOut.data_cspc = cspc
101 self.dataOut.data_cspc = cspc
102 self.dataOut.data_dc = dc
102 self.dataOut.data_dc = dc
103 self.dataOut.blockSize = blocksize
103 self.dataOut.blockSize = blocksize
104 self.dataOut.flagShiftFFT = True
104 self.dataOut.flagShiftFFT = True
105
105
106 def run(self, nProfiles=None, nFFTPoints=None, pairsList=[], ippFactor=None):
106 def run(self, nProfiles=None, nFFTPoints=None, pairsList=[], ippFactor=None):
107
107
108 self.dataOut.flagNoData = True
108 self.dataOut.flagNoData = True
109
109
110 if self.dataIn.type == "Spectra":
110 if self.dataIn.type == "Spectra":
111 self.dataOut.copy(self.dataIn)
111 self.dataOut.copy(self.dataIn)
112 # self.__selectPairs(pairsList)
112 # self.__selectPairs(pairsList)
113 return True
113 return True
114
114
115 if self.dataIn.type == "Voltage":
115 if self.dataIn.type == "Voltage":
116
116
117 if nFFTPoints == None:
117 if nFFTPoints == None:
118 raise ValueError, "This SpectraProc.run() need nFFTPoints input variable"
118 raise ValueError, "This SpectraProc.run() need nFFTPoints input variable"
119
119
120 if nProfiles == None:
120 if nProfiles == None:
121 nProfiles = nFFTPoints
121 nProfiles = nFFTPoints
122
122
123 if ippFactor == None:
123 if ippFactor == None:
124 ippFactor = 1
124 ippFactor = 1
125
125
126 self.dataOut.ippFactor = ippFactor
126 self.dataOut.ippFactor = ippFactor
127
127
128 self.dataOut.nFFTPoints = nFFTPoints
128 self.dataOut.nFFTPoints = nFFTPoints
129 self.dataOut.pairsList = pairsList
129 self.dataOut.pairsList = pairsList
130
130
131 if self.buffer is None:
131 if self.buffer is None:
132 self.buffer = numpy.zeros( (self.dataIn.nChannels,
132 self.buffer = numpy.zeros( (self.dataIn.nChannels,
133 nProfiles,
133 nProfiles,
134 self.dataIn.nHeights),
134 self.dataIn.nHeights),
135 dtype='complex')
135 dtype='complex')
136
136
137 if self.dataIn.flagDataAsBlock:
137 if self.dataIn.flagDataAsBlock:
138 #data dimension: [nChannels, nProfiles, nSamples]
138 #data dimension: [nChannels, nProfiles, nSamples]
139 nVoltProfiles = self.dataIn.data.shape[1]
139 nVoltProfiles = self.dataIn.data.shape[1]
140 # nVoltProfiles = self.dataIn.nProfiles
140 # nVoltProfiles = self.dataIn.nProfiles
141
141
142 if nVoltProfiles == nProfiles:
142 if nVoltProfiles == nProfiles:
143 self.buffer = self.dataIn.data.copy()
143 self.buffer = self.dataIn.data.copy()
144 self.profIndex = nVoltProfiles
144 self.profIndex = nVoltProfiles
145
145
146 elif nVoltProfiles < nProfiles:
146 elif nVoltProfiles < nProfiles:
147
147
148 if self.profIndex == 0:
148 if self.profIndex == 0:
149 self.id_min = 0
149 self.id_min = 0
150 self.id_max = nVoltProfiles
150 self.id_max = nVoltProfiles
151
151
152 self.buffer[:,self.id_min:self.id_max,:] = self.dataIn.data
152 self.buffer[:,self.id_min:self.id_max,:] = self.dataIn.data
153 self.profIndex += nVoltProfiles
153 self.profIndex += nVoltProfiles
154 self.id_min += nVoltProfiles
154 self.id_min += nVoltProfiles
155 self.id_max += nVoltProfiles
155 self.id_max += nVoltProfiles
156 else:
156 else:
157 raise ValueError, "The type object %s has %d profiles, it should just has %d profiles"%(self.dataIn.type,self.dataIn.data.shape[1],nProfiles)
157 raise ValueError, "The type object %s has %d profiles, it should just has %d profiles"%(self.dataIn.type,self.dataIn.data.shape[1],nProfiles)
158 self.dataOut.flagNoData = True
158 self.dataOut.flagNoData = True
159 return 0
159 return 0
160 else:
160 else:
161 self.buffer[:,self.profIndex,:] = self.dataIn.data.copy()
161 self.buffer[:,self.profIndex,:] = self.dataIn.data.copy()
162 self.profIndex += 1
162 self.profIndex += 1
163
163
164 if self.firstdatatime == None:
164 if self.firstdatatime == None:
165 self.firstdatatime = self.dataIn.utctime
165 self.firstdatatime = self.dataIn.utctime
166
166
167 if self.profIndex == nProfiles:
167 if self.profIndex == nProfiles:
168 self.__updateSpecFromVoltage()
168 self.__updateSpecFromVoltage()
169 self.__getFft()
169 self.__getFft()
170
170
171 self.dataOut.flagNoData = False
171 self.dataOut.flagNoData = False
172 self.firstdatatime = None
172 self.firstdatatime = None
173 self.profIndex = 0
173 self.profIndex = 0
174
174
175 return True
175 return True
176
176
177 raise ValueError, "The type of input object '%s' is not valid"%(self.dataIn.type)
177 raise ValueError, "The type of input object '%s' is not valid"%(self.dataIn.type)
178
178
179 def __selectPairs(self, pairsList):
179 def __selectPairs(self, pairsList):
180
180
181 if channelList == None:
181 if channelList == None:
182 return
182 return
183
183
184 pairsIndexListSelected = []
184 pairsIndexListSelected = []
185
185
186 for thisPair in pairsList:
186 for thisPair in pairsList:
187
187
188 if thisPair not in self.dataOut.pairsList:
188 if thisPair not in self.dataOut.pairsList:
189 continue
189 continue
190
190
191 pairIndex = self.dataOut.pairsList.index(thisPair)
191 pairIndex = self.dataOut.pairsList.index(thisPair)
192
192
193 pairsIndexListSelected.append(pairIndex)
193 pairsIndexListSelected.append(pairIndex)
194
194
195 if not pairsIndexListSelected:
195 if not pairsIndexListSelected:
196 self.dataOut.data_cspc = None
196 self.dataOut.data_cspc = None
197 self.dataOut.pairsList = []
197 self.dataOut.pairsList = []
198 return
198 return
199
199
200 self.dataOut.data_cspc = self.dataOut.data_cspc[pairsIndexListSelected]
200 self.dataOut.data_cspc = self.dataOut.data_cspc[pairsIndexListSelected]
201 self.dataOut.pairsList = [self.dataOut.pairsList[i] for i in pairsIndexListSelected]
201 self.dataOut.pairsList = [self.dataOut.pairsList[i] for i in pairsIndexListSelected]
202
202
203 return
203 return
204
204
205 def __selectPairsByChannel(self, channelList=None):
205 def __selectPairsByChannel(self, channelList=None):
206
206
207 if channelList == None:
207 if channelList == None:
208 return
208 return
209
209
210 pairsIndexListSelected = []
210 pairsIndexListSelected = []
211 for pairIndex in self.dataOut.pairsIndexList:
211 for pairIndex in self.dataOut.pairsIndexList:
212 #First pair
212 #First pair
213 if self.dataOut.pairsList[pairIndex][0] not in channelList:
213 if self.dataOut.pairsList[pairIndex][0] not in channelList:
214 continue
214 continue
215 #Second pair
215 #Second pair
216 if self.dataOut.pairsList[pairIndex][1] not in channelList:
216 if self.dataOut.pairsList[pairIndex][1] not in channelList:
217 continue
217 continue
218
218
219 pairsIndexListSelected.append(pairIndex)
219 pairsIndexListSelected.append(pairIndex)
220
220
221 if not pairsIndexListSelected:
221 if not pairsIndexListSelected:
222 self.dataOut.data_cspc = None
222 self.dataOut.data_cspc = None
223 self.dataOut.pairsList = []
223 self.dataOut.pairsList = []
224 return
224 return
225
225
226 self.dataOut.data_cspc = self.dataOut.data_cspc[pairsIndexListSelected]
226 self.dataOut.data_cspc = self.dataOut.data_cspc[pairsIndexListSelected]
227 self.dataOut.pairsList = [self.dataOut.pairsList[i] for i in pairsIndexListSelected]
227 self.dataOut.pairsList = [self.dataOut.pairsList[i] for i in pairsIndexListSelected]
228
228
229 return
229 return
230
230
231 def selectChannels(self, channelList):
231 def selectChannels(self, channelList):
232
232
233 channelIndexList = []
233 channelIndexList = []
234
234
235 for channel in channelList:
235 for channel in channelList:
236 if channel not in self.dataOut.channelList:
236 if channel not in self.dataOut.channelList:
237 raise ValueError, "Error selecting channels, Channel %d is not valid.\nAvailable channels = %s" %(channel, str(self.dataOut.channelList))
237 raise ValueError, "Error selecting channels, Channel %d is not valid.\nAvailable channels = %s" %(channel, str(self.dataOut.channelList))
238
238
239 index = self.dataOut.channelList.index(channel)
239 index = self.dataOut.channelList.index(channel)
240 channelIndexList.append(index)
240 channelIndexList.append(index)
241
241
242 self.selectChannelsByIndex(channelIndexList)
242 self.selectChannelsByIndex(channelIndexList)
243
243
244 def selectChannelsByIndex(self, channelIndexList):
244 def selectChannelsByIndex(self, channelIndexList):
245 """
245 """
246 Selecciona un bloque de datos en base a canales segun el channelIndexList
246 Selecciona un bloque de datos en base a canales segun el channelIndexList
247
247
248 Input:
248 Input:
249 channelIndexList : lista sencilla de canales a seleccionar por ej. [2,3,7]
249 channelIndexList : lista sencilla de canales a seleccionar por ej. [2,3,7]
250
250
251 Affected:
251 Affected:
252 self.dataOut.data_spc
252 self.dataOut.data_spc
253 self.dataOut.channelIndexList
253 self.dataOut.channelIndexList
254 self.dataOut.nChannels
254 self.dataOut.nChannels
255
255
256 Return:
256 Return:
257 None
257 None
258 """
258 """
259
259
260 for channelIndex in channelIndexList:
260 for channelIndex in channelIndexList:
261 if channelIndex not in self.dataOut.channelIndexList:
261 if channelIndex not in self.dataOut.channelIndexList:
262 raise ValueError, "Error selecting channels: The value %d in channelIndexList is not valid.\nAvailable channel indexes = " %(channelIndex, self.dataOut.channelIndexList)
262 raise ValueError, "Error selecting channels: The value %d in channelIndexList is not valid.\nAvailable channel indexes = " %(channelIndex, self.dataOut.channelIndexList)
263
263
264 # nChannels = len(channelIndexList)
264 # nChannels = len(channelIndexList)
265
265
266 data_spc = self.dataOut.data_spc[channelIndexList,:]
266 data_spc = self.dataOut.data_spc[channelIndexList,:]
267 data_dc = self.dataOut.data_dc[channelIndexList,:]
267 data_dc = self.dataOut.data_dc[channelIndexList,:]
268
268
269 self.dataOut.data_spc = data_spc
269 self.dataOut.data_spc = data_spc
270 self.dataOut.data_dc = data_dc
270 self.dataOut.data_dc = data_dc
271
271
272 self.dataOut.channelList = [self.dataOut.channelList[i] for i in channelIndexList]
272 self.dataOut.channelList = [self.dataOut.channelList[i] for i in channelIndexList]
273 # self.dataOut.nChannels = nChannels
273 # self.dataOut.nChannels = nChannels
274
274
275 self.__selectPairsByChannel(self.dataOut.channelList)
275 self.__selectPairsByChannel(self.dataOut.channelList)
276
276
277 return 1
277 return 1
278
278
279 def selectHeights(self, minHei, maxHei):
279 def selectHeights(self, minHei, maxHei):
280 """
280 """
281 Selecciona un bloque de datos en base a un grupo de valores de alturas segun el rango
281 Selecciona un bloque de datos en base a un grupo de valores de alturas segun el rango
282 minHei <= height <= maxHei
282 minHei <= height <= maxHei
283
283
284 Input:
284 Input:
285 minHei : valor minimo de altura a considerar
285 minHei : valor minimo de altura a considerar
286 maxHei : valor maximo de altura a considerar
286 maxHei : valor maximo de altura a considerar
287
287
288 Affected:
288 Affected:
289 Indirectamente son cambiados varios valores a travez del metodo selectHeightsByIndex
289 Indirectamente son cambiados varios valores a travez del metodo selectHeightsByIndex
290
290
291 Return:
291 Return:
292 1 si el metodo se ejecuto con exito caso contrario devuelve 0
292 1 si el metodo se ejecuto con exito caso contrario devuelve 0
293 """
293 """
294
294
295 if (minHei > maxHei):
295 if (minHei > maxHei):
296 raise ValueError, "Error selecting heights: Height range (%d,%d) is not valid" % (minHei, maxHei)
296 raise ValueError, "Error selecting heights: Height range (%d,%d) is not valid" % (minHei, maxHei)
297
297
298 if (minHei < self.dataOut.heightList[0]):
298 if (minHei < self.dataOut.heightList[0]):
299 minHei = self.dataOut.heightList[0]
299 minHei = self.dataOut.heightList[0]
300
300
301 if (maxHei > self.dataOut.heightList[-1]):
301 if (maxHei > self.dataOut.heightList[-1]):
302 maxHei = self.dataOut.heightList[-1]
302 maxHei = self.dataOut.heightList[-1]
303
303
304 minIndex = 0
304 minIndex = 0
305 maxIndex = 0
305 maxIndex = 0
306 heights = self.dataOut.heightList
306 heights = self.dataOut.heightList
307
307
308 inda = numpy.where(heights >= minHei)
308 inda = numpy.where(heights >= minHei)
309 indb = numpy.where(heights <= maxHei)
309 indb = numpy.where(heights <= maxHei)
310
310
311 try:
311 try:
312 minIndex = inda[0][0]
312 minIndex = inda[0][0]
313 except:
313 except:
314 minIndex = 0
314 minIndex = 0
315
315
316 try:
316 try:
317 maxIndex = indb[0][-1]
317 maxIndex = indb[0][-1]
318 except:
318 except:
319 maxIndex = len(heights)
319 maxIndex = len(heights)
320
320
321 self.selectHeightsByIndex(minIndex, maxIndex)
321 self.selectHeightsByIndex(minIndex, maxIndex)
322
322
323 return 1
323 return 1
324
324
325 def getBeaconSignal(self, tauindex = 0, channelindex = 0, hei_ref=None):
325 def getBeaconSignal(self, tauindex = 0, channelindex = 0, hei_ref=None):
326 newheis = numpy.where(self.dataOut.heightList>self.dataOut.radarControllerHeaderObj.Taus[tauindex])
326 newheis = numpy.where(self.dataOut.heightList>self.dataOut.radarControllerHeaderObj.Taus[tauindex])
327
327
328 if hei_ref != None:
328 if hei_ref != None:
329 newheis = numpy.where(self.dataOut.heightList>hei_ref)
329 newheis = numpy.where(self.dataOut.heightList>hei_ref)
330
330
331 minIndex = min(newheis[0])
331 minIndex = min(newheis[0])
332 maxIndex = max(newheis[0])
332 maxIndex = max(newheis[0])
333 data_spc = self.dataOut.data_spc[:,:,minIndex:maxIndex+1]
333 data_spc = self.dataOut.data_spc[:,:,minIndex:maxIndex+1]
334 heightList = self.dataOut.heightList[minIndex:maxIndex+1]
334 heightList = self.dataOut.heightList[minIndex:maxIndex+1]
335
335
336 # determina indices
336 # determina indices
337 nheis = int(self.dataOut.radarControllerHeaderObj.txB/(self.dataOut.heightList[1]-self.dataOut.heightList[0]))
337 nheis = int(self.dataOut.radarControllerHeaderObj.txB/(self.dataOut.heightList[1]-self.dataOut.heightList[0]))
338 avg_dB = 10*numpy.log10(numpy.sum(data_spc[channelindex,:,:],axis=0))
338 avg_dB = 10*numpy.log10(numpy.sum(data_spc[channelindex,:,:],axis=0))
339 beacon_dB = numpy.sort(avg_dB)[-nheis:]
339 beacon_dB = numpy.sort(avg_dB)[-nheis:]
340 beacon_heiIndexList = []
340 beacon_heiIndexList = []
341 for val in avg_dB.tolist():
341 for val in avg_dB.tolist():
342 if val >= beacon_dB[0]:
342 if val >= beacon_dB[0]:
343 beacon_heiIndexList.append(avg_dB.tolist().index(val))
343 beacon_heiIndexList.append(avg_dB.tolist().index(val))
344
344
345 #data_spc = data_spc[:,:,beacon_heiIndexList]
345 #data_spc = data_spc[:,:,beacon_heiIndexList]
346 data_cspc = None
346 data_cspc = None
347 if self.dataOut.data_cspc is not None:
347 if self.dataOut.data_cspc is not None:
348 data_cspc = self.dataOut.data_cspc[:,:,minIndex:maxIndex+1]
348 data_cspc = self.dataOut.data_cspc[:,:,minIndex:maxIndex+1]
349 #data_cspc = data_cspc[:,:,beacon_heiIndexList]
349 #data_cspc = data_cspc[:,:,beacon_heiIndexList]
350
350
351 data_dc = None
351 data_dc = None
352 if self.dataOut.data_dc is not None:
352 if self.dataOut.data_dc is not None:
353 data_dc = self.dataOut.data_dc[:,minIndex:maxIndex+1]
353 data_dc = self.dataOut.data_dc[:,minIndex:maxIndex+1]
354 #data_dc = data_dc[:,beacon_heiIndexList]
354 #data_dc = data_dc[:,beacon_heiIndexList]
355
355
356 self.dataOut.data_spc = data_spc
356 self.dataOut.data_spc = data_spc
357 self.dataOut.data_cspc = data_cspc
357 self.dataOut.data_cspc = data_cspc
358 self.dataOut.data_dc = data_dc
358 self.dataOut.data_dc = data_dc
359 self.dataOut.heightList = heightList
359 self.dataOut.heightList = heightList
360 self.dataOut.beacon_heiIndexList = beacon_heiIndexList
360 self.dataOut.beacon_heiIndexList = beacon_heiIndexList
361
361
362 return 1
362 return 1
363
363
364
364
365 def selectHeightsByIndex(self, minIndex, maxIndex):
365 def selectHeightsByIndex(self, minIndex, maxIndex):
366 """
366 """
367 Selecciona un bloque de datos en base a un grupo indices de alturas segun el rango
367 Selecciona un bloque de datos en base a un grupo indices de alturas segun el rango
368 minIndex <= index <= maxIndex
368 minIndex <= index <= maxIndex
369
369
370 Input:
370 Input:
371 minIndex : valor de indice minimo de altura a considerar
371 minIndex : valor de indice minimo de altura a considerar
372 maxIndex : valor de indice maximo de altura a considerar
372 maxIndex : valor de indice maximo de altura a considerar
373
373
374 Affected:
374 Affected:
375 self.dataOut.data_spc
375 self.dataOut.data_spc
376 self.dataOut.data_cspc
376 self.dataOut.data_cspc
377 self.dataOut.data_dc
377 self.dataOut.data_dc
378 self.dataOut.heightList
378 self.dataOut.heightList
379
379
380 Return:
380 Return:
381 1 si el metodo se ejecuto con exito caso contrario devuelve 0
381 1 si el metodo se ejecuto con exito caso contrario devuelve 0
382 """
382 """
383
383
384 if (minIndex < 0) or (minIndex > maxIndex):
384 if (minIndex < 0) or (minIndex > maxIndex):
385 raise ValueError, "Error selecting heights: Index range (%d,%d) is not valid" % (minIndex, maxIndex)
385 raise ValueError, "Error selecting heights: Index range (%d,%d) is not valid" % (minIndex, maxIndex)
386
386
387 if (maxIndex >= self.dataOut.nHeights):
387 if (maxIndex >= self.dataOut.nHeights):
388 maxIndex = self.dataOut.nHeights-1
388 maxIndex = self.dataOut.nHeights-1
389
389
390 #Spectra
390 #Spectra
391 data_spc = self.dataOut.data_spc[:,:,minIndex:maxIndex+1]
391 data_spc = self.dataOut.data_spc[:,:,minIndex:maxIndex+1]
392
392
393 data_cspc = None
393 data_cspc = None
394 if self.dataOut.data_cspc is not None:
394 if self.dataOut.data_cspc is not None:
395 data_cspc = self.dataOut.data_cspc[:,:,minIndex:maxIndex+1]
395 data_cspc = self.dataOut.data_cspc[:,:,minIndex:maxIndex+1]
396
396
397 data_dc = None
397 data_dc = None
398 if self.dataOut.data_dc is not None:
398 if self.dataOut.data_dc is not None:
399 data_dc = self.dataOut.data_dc[:,minIndex:maxIndex+1]
399 data_dc = self.dataOut.data_dc[:,minIndex:maxIndex+1]
400
400
401 self.dataOut.data_spc = data_spc
401 self.dataOut.data_spc = data_spc
402 self.dataOut.data_cspc = data_cspc
402 self.dataOut.data_cspc = data_cspc
403 self.dataOut.data_dc = data_dc
403 self.dataOut.data_dc = data_dc
404
404
405 self.dataOut.heightList = self.dataOut.heightList[minIndex:maxIndex+1]
405 self.dataOut.heightList = self.dataOut.heightList[minIndex:maxIndex+1]
406
406
407 return 1
407 return 1
408
408
409 def removeDC(self, mode = 2):
409 def removeDC(self, mode = 2):
410 jspectra = self.dataOut.data_spc
410 jspectra = self.dataOut.data_spc
411 jcspectra = self.dataOut.data_cspc
411 jcspectra = self.dataOut.data_cspc
412
412
413
413
414 num_chan = jspectra.shape[0]
414 num_chan = jspectra.shape[0]
415 num_hei = jspectra.shape[2]
415 num_hei = jspectra.shape[2]
416
416
417 if jcspectra is not None:
417 if jcspectra is not None:
418 jcspectraExist = True
418 jcspectraExist = True
419 num_pairs = jcspectra.shape[0]
419 num_pairs = jcspectra.shape[0]
420 else: jcspectraExist = False
420 else: jcspectraExist = False
421
421
422 freq_dc = jspectra.shape[1]/2
422 freq_dc = jspectra.shape[1]/2
423 ind_vel = numpy.array([-2,-1,1,2]) + freq_dc
423 ind_vel = numpy.array([-2,-1,1,2]) + freq_dc
424
424
425 if ind_vel[0]<0:
425 if ind_vel[0]<0:
426 ind_vel[range(0,1)] = ind_vel[range(0,1)] + self.num_prof
426 ind_vel[range(0,1)] = ind_vel[range(0,1)] + self.num_prof
427
427
428 if mode == 1:
428 if mode == 1:
429 jspectra[:,freq_dc,:] = (jspectra[:,ind_vel[1],:] + jspectra[:,ind_vel[2],:])/2 #CORRECCION
429 jspectra[:,freq_dc,:] = (jspectra[:,ind_vel[1],:] + jspectra[:,ind_vel[2],:])/2 #CORRECCION
430
430
431 if jcspectraExist:
431 if jcspectraExist:
432 jcspectra[:,freq_dc,:] = (jcspectra[:,ind_vel[1],:] + jcspectra[:,ind_vel[2],:])/2
432 jcspectra[:,freq_dc,:] = (jcspectra[:,ind_vel[1],:] + jcspectra[:,ind_vel[2],:])/2
433
433
434 if mode == 2:
434 if mode == 2:
435
435
436 vel = numpy.array([-2,-1,1,2])
436 vel = numpy.array([-2,-1,1,2])
437 xx = numpy.zeros([4,4])
437 xx = numpy.zeros([4,4])
438
438
439 for fil in range(4):
439 for fil in range(4):
440 xx[fil,:] = vel[fil]**numpy.asarray(range(4))
440 xx[fil,:] = vel[fil]**numpy.asarray(range(4))
441
441
442 xx_inv = numpy.linalg.inv(xx)
442 xx_inv = numpy.linalg.inv(xx)
443 xx_aux = xx_inv[0,:]
443 xx_aux = xx_inv[0,:]
444
444
445 for ich in range(num_chan):
445 for ich in range(num_chan):
446 yy = jspectra[ich,ind_vel,:]
446 yy = jspectra[ich,ind_vel,:]
447 jspectra[ich,freq_dc,:] = numpy.dot(xx_aux,yy)
447 jspectra[ich,freq_dc,:] = numpy.dot(xx_aux,yy)
448
448
449 junkid = jspectra[ich,freq_dc,:]<=0
449 junkid = jspectra[ich,freq_dc,:]<=0
450 cjunkid = sum(junkid)
450 cjunkid = sum(junkid)
451
451
452 if cjunkid.any():
452 if cjunkid.any():
453 jspectra[ich,freq_dc,junkid.nonzero()] = (jspectra[ich,ind_vel[1],junkid] + jspectra[ich,ind_vel[2],junkid])/2
453 jspectra[ich,freq_dc,junkid.nonzero()] = (jspectra[ich,ind_vel[1],junkid] + jspectra[ich,ind_vel[2],junkid])/2
454
454
455 if jcspectraExist:
455 if jcspectraExist:
456 for ip in range(num_pairs):
456 for ip in range(num_pairs):
457 yy = jcspectra[ip,ind_vel,:]
457 yy = jcspectra[ip,ind_vel,:]
458 jcspectra[ip,freq_dc,:] = numpy.dot(xx_aux,yy)
458 jcspectra[ip,freq_dc,:] = numpy.dot(xx_aux,yy)
459
459
460
460
461 self.dataOut.data_spc = jspectra
461 self.dataOut.data_spc = jspectra
462 self.dataOut.data_cspc = jcspectra
462 self.dataOut.data_cspc = jcspectra
463
463
464 return 1
464 return 1
465
465
466 def removeInterference(self, interf = 2,hei_interf = None, nhei_interf = None, offhei_interf = None):
466 def removeInterference(self, interf = 2,hei_interf = None, nhei_interf = None, offhei_interf = None):
467
467
468 jspectra = self.dataOut.data_spc
468 jspectra = self.dataOut.data_spc
469 jcspectra = self.dataOut.data_cspc
469 jcspectra = self.dataOut.data_cspc
470 jnoise = self.dataOut.getNoise()
470 jnoise = self.dataOut.getNoise()
471 num_incoh = self.dataOut.nIncohInt
471 num_incoh = self.dataOut.nIncohInt
472
472
473 num_channel = jspectra.shape[0]
473 num_channel = jspectra.shape[0]
474 num_prof = jspectra.shape[1]
474 num_prof = jspectra.shape[1]
475 num_hei = jspectra.shape[2]
475 num_hei = jspectra.shape[2]
476
476
477 #hei_interf
477 #hei_interf
478 if hei_interf is None:
478 if hei_interf is None:
479 count_hei = num_hei/2 #Como es entero no importa
479 count_hei = num_hei/2 #Como es entero no importa
480 hei_interf = numpy.asmatrix(range(count_hei)) + num_hei - count_hei
480 hei_interf = numpy.asmatrix(range(count_hei)) + num_hei - count_hei
481 hei_interf = numpy.asarray(hei_interf)[0]
481 hei_interf = numpy.asarray(hei_interf)[0]
482 #nhei_interf
482 #nhei_interf
483 if (nhei_interf == None):
483 if (nhei_interf == None):
484 nhei_interf = 5
484 nhei_interf = 5
485 if (nhei_interf < 1):
485 if (nhei_interf < 1):
486 nhei_interf = 1
486 nhei_interf = 1
487 if (nhei_interf > count_hei):
487 if (nhei_interf > count_hei):
488 nhei_interf = count_hei
488 nhei_interf = count_hei
489 if (offhei_interf == None):
489 if (offhei_interf == None):
490 offhei_interf = 0
490 offhei_interf = 0
491
491
492 ind_hei = range(num_hei)
492 ind_hei = range(num_hei)
493 # mask_prof = numpy.asarray(range(num_prof - 2)) + 1
493 # mask_prof = numpy.asarray(range(num_prof - 2)) + 1
494 # mask_prof[range(num_prof/2 - 1,len(mask_prof))] += 1
494 # mask_prof[range(num_prof/2 - 1,len(mask_prof))] += 1
495 mask_prof = numpy.asarray(range(num_prof))
495 mask_prof = numpy.asarray(range(num_prof))
496 num_mask_prof = mask_prof.size
496 num_mask_prof = mask_prof.size
497 comp_mask_prof = [0, num_prof/2]
497 comp_mask_prof = [0, num_prof/2]
498
498
499
499
500 #noise_exist: Determina si la variable jnoise ha sido definida y contiene la informacion del ruido de cada canal
500 #noise_exist: Determina si la variable jnoise ha sido definida y contiene la informacion del ruido de cada canal
501 if (jnoise.size < num_channel or numpy.isnan(jnoise).any()):
501 if (jnoise.size < num_channel or numpy.isnan(jnoise).any()):
502 jnoise = numpy.nan
502 jnoise = numpy.nan
503 noise_exist = jnoise[0] < numpy.Inf
503 noise_exist = jnoise[0] < numpy.Inf
504
504
505 #Subrutina de Remocion de la Interferencia
505 #Subrutina de Remocion de la Interferencia
506 for ich in range(num_channel):
506 for ich in range(num_channel):
507 #Se ordena los espectros segun su potencia (menor a mayor)
507 #Se ordena los espectros segun su potencia (menor a mayor)
508 power = jspectra[ich,mask_prof,:]
508 power = jspectra[ich,mask_prof,:]
509 power = power[:,hei_interf]
509 power = power[:,hei_interf]
510 power = power.sum(axis = 0)
510 power = power.sum(axis = 0)
511 psort = power.ravel().argsort()
511 psort = power.ravel().argsort()
512
512
513 #Se estima la interferencia promedio en los Espectros de Potencia empleando
513 #Se estima la interferencia promedio en los Espectros de Potencia empleando
514 junkspc_interf = jspectra[ich,:,hei_interf[psort[range(offhei_interf, nhei_interf + offhei_interf)]]]
514 junkspc_interf = jspectra[ich,:,hei_interf[psort[range(offhei_interf, nhei_interf + offhei_interf)]]]
515
515
516 if noise_exist:
516 if noise_exist:
517 # tmp_noise = jnoise[ich] / num_prof
517 # tmp_noise = jnoise[ich] / num_prof
518 tmp_noise = jnoise[ich]
518 tmp_noise = jnoise[ich]
519 junkspc_interf = junkspc_interf - tmp_noise
519 junkspc_interf = junkspc_interf - tmp_noise
520 #junkspc_interf[:,comp_mask_prof] = 0
520 #junkspc_interf[:,comp_mask_prof] = 0
521
521
522 jspc_interf = junkspc_interf.sum(axis = 0) / nhei_interf
522 jspc_interf = junkspc_interf.sum(axis = 0) / nhei_interf
523 jspc_interf = jspc_interf.transpose()
523 jspc_interf = jspc_interf.transpose()
524 #Calculando el espectro de interferencia promedio
524 #Calculando el espectro de interferencia promedio
525 noiseid = numpy.where(jspc_interf <= tmp_noise/ numpy.sqrt(num_incoh))
525 noiseid = numpy.where(jspc_interf <= tmp_noise/ numpy.sqrt(num_incoh))
526 noiseid = noiseid[0]
526 noiseid = noiseid[0]
527 cnoiseid = noiseid.size
527 cnoiseid = noiseid.size
528 interfid = numpy.where(jspc_interf > tmp_noise/ numpy.sqrt(num_incoh))
528 interfid = numpy.where(jspc_interf > tmp_noise/ numpy.sqrt(num_incoh))
529 interfid = interfid[0]
529 interfid = interfid[0]
530 cinterfid = interfid.size
530 cinterfid = interfid.size
531
531
532 if (cnoiseid > 0): jspc_interf[noiseid] = 0
532 if (cnoiseid > 0): jspc_interf[noiseid] = 0
533
533
534 #Expandiendo los perfiles a limpiar
534 #Expandiendo los perfiles a limpiar
535 if (cinterfid > 0):
535 if (cinterfid > 0):
536 new_interfid = (numpy.r_[interfid - 1, interfid, interfid + 1] + num_prof)%num_prof
536 new_interfid = (numpy.r_[interfid - 1, interfid, interfid + 1] + num_prof)%num_prof
537 new_interfid = numpy.asarray(new_interfid)
537 new_interfid = numpy.asarray(new_interfid)
538 new_interfid = {x for x in new_interfid}
538 new_interfid = {x for x in new_interfid}
539 new_interfid = numpy.array(list(new_interfid))
539 new_interfid = numpy.array(list(new_interfid))
540 new_cinterfid = new_interfid.size
540 new_cinterfid = new_interfid.size
541 else: new_cinterfid = 0
541 else: new_cinterfid = 0
542
542
543 for ip in range(new_cinterfid):
543 for ip in range(new_cinterfid):
544 ind = junkspc_interf[:,new_interfid[ip]].ravel().argsort()
544 ind = junkspc_interf[:,new_interfid[ip]].ravel().argsort()
545 jspc_interf[new_interfid[ip]] = junkspc_interf[ind[nhei_interf/2],new_interfid[ip]]
545 jspc_interf[new_interfid[ip]] = junkspc_interf[ind[nhei_interf/2],new_interfid[ip]]
546
546
547
547
548 jspectra[ich,:,ind_hei] = jspectra[ich,:,ind_hei] - jspc_interf #Corregir indices
548 jspectra[ich,:,ind_hei] = jspectra[ich,:,ind_hei] - jspc_interf #Corregir indices
549
549
550 #Removiendo la interferencia del punto de mayor interferencia
550 #Removiendo la interferencia del punto de mayor interferencia
551 ListAux = jspc_interf[mask_prof].tolist()
551 ListAux = jspc_interf[mask_prof].tolist()
552 maxid = ListAux.index(max(ListAux))
552 maxid = ListAux.index(max(ListAux))
553
553
554
554
555 if cinterfid > 0:
555 if cinterfid > 0:
556 for ip in range(cinterfid*(interf == 2) - 1):
556 for ip in range(cinterfid*(interf == 2) - 1):
557 ind = (jspectra[ich,interfid[ip],:] < tmp_noise*(1 + 1/numpy.sqrt(num_incoh))).nonzero()
557 ind = (jspectra[ich,interfid[ip],:] < tmp_noise*(1 + 1/numpy.sqrt(num_incoh))).nonzero()
558 cind = len(ind)
558 cind = len(ind)
559
559
560 if (cind > 0):
560 if (cind > 0):
561 jspectra[ich,interfid[ip],ind] = tmp_noise*(1 + (numpy.random.uniform(cind) - 0.5)/numpy.sqrt(num_incoh))
561 jspectra[ich,interfid[ip],ind] = tmp_noise*(1 + (numpy.random.uniform(cind) - 0.5)/numpy.sqrt(num_incoh))
562
562
563 ind = numpy.array([-2,-1,1,2])
563 ind = numpy.array([-2,-1,1,2])
564 xx = numpy.zeros([4,4])
564 xx = numpy.zeros([4,4])
565
565
566 for id1 in range(4):
566 for id1 in range(4):
567 xx[:,id1] = ind[id1]**numpy.asarray(range(4))
567 xx[:,id1] = ind[id1]**numpy.asarray(range(4))
568
568
569 xx_inv = numpy.linalg.inv(xx)
569 xx_inv = numpy.linalg.inv(xx)
570 xx = xx_inv[:,0]
570 xx = xx_inv[:,0]
571 ind = (ind + maxid + num_mask_prof)%num_mask_prof
571 ind = (ind + maxid + num_mask_prof)%num_mask_prof
572 yy = jspectra[ich,mask_prof[ind],:]
572 yy = jspectra[ich,mask_prof[ind],:]
573 jspectra[ich,mask_prof[maxid],:] = numpy.dot(yy.transpose(),xx)
573 jspectra[ich,mask_prof[maxid],:] = numpy.dot(yy.transpose(),xx)
574
574
575
575
576 indAux = (jspectra[ich,:,:] < tmp_noise*(1-1/numpy.sqrt(num_incoh))).nonzero()
576 indAux = (jspectra[ich,:,:] < tmp_noise*(1-1/numpy.sqrt(num_incoh))).nonzero()
577 jspectra[ich,indAux[0],indAux[1]] = tmp_noise * (1 - 1/numpy.sqrt(num_incoh))
577 jspectra[ich,indAux[0],indAux[1]] = tmp_noise * (1 - 1/numpy.sqrt(num_incoh))
578
578
579 #Remocion de Interferencia en el Cross Spectra
579 #Remocion de Interferencia en el Cross Spectra
580 if jcspectra is None: return jspectra, jcspectra
580 if jcspectra is None: return jspectra, jcspectra
581 num_pairs = jcspectra.size/(num_prof*num_hei)
581 num_pairs = jcspectra.size/(num_prof*num_hei)
582 jcspectra = jcspectra.reshape(num_pairs, num_prof, num_hei)
582 jcspectra = jcspectra.reshape(num_pairs, num_prof, num_hei)
583
583
584 for ip in range(num_pairs):
584 for ip in range(num_pairs):
585
585
586 #-------------------------------------------
586 #-------------------------------------------
587
587
588 cspower = numpy.abs(jcspectra[ip,mask_prof,:])
588 cspower = numpy.abs(jcspectra[ip,mask_prof,:])
589 cspower = cspower[:,hei_interf]
589 cspower = cspower[:,hei_interf]
590 cspower = cspower.sum(axis = 0)
590 cspower = cspower.sum(axis = 0)
591
591
592 cspsort = cspower.ravel().argsort()
592 cspsort = cspower.ravel().argsort()
593 junkcspc_interf = jcspectra[ip,:,hei_interf[cspsort[range(offhei_interf, nhei_interf + offhei_interf)]]]
593 junkcspc_interf = jcspectra[ip,:,hei_interf[cspsort[range(offhei_interf, nhei_interf + offhei_interf)]]]
594 junkcspc_interf = junkcspc_interf.transpose()
594 junkcspc_interf = junkcspc_interf.transpose()
595 jcspc_interf = junkcspc_interf.sum(axis = 1)/nhei_interf
595 jcspc_interf = junkcspc_interf.sum(axis = 1)/nhei_interf
596
596
597 ind = numpy.abs(jcspc_interf[mask_prof]).ravel().argsort()
597 ind = numpy.abs(jcspc_interf[mask_prof]).ravel().argsort()
598
598
599 median_real = numpy.median(numpy.real(junkcspc_interf[mask_prof[ind[range(3*num_prof/4)]],:]))
599 median_real = numpy.median(numpy.real(junkcspc_interf[mask_prof[ind[range(3*num_prof/4)]],:]))
600 median_imag = numpy.median(numpy.imag(junkcspc_interf[mask_prof[ind[range(3*num_prof/4)]],:]))
600 median_imag = numpy.median(numpy.imag(junkcspc_interf[mask_prof[ind[range(3*num_prof/4)]],:]))
601 junkcspc_interf[comp_mask_prof,:] = numpy.complex(median_real, median_imag)
601 junkcspc_interf[comp_mask_prof,:] = numpy.complex(median_real, median_imag)
602
602
603 for iprof in range(num_prof):
603 for iprof in range(num_prof):
604 ind = numpy.abs(junkcspc_interf[iprof,:]).ravel().argsort()
604 ind = numpy.abs(junkcspc_interf[iprof,:]).ravel().argsort()
605 jcspc_interf[iprof] = junkcspc_interf[iprof, ind[nhei_interf/2]]
605 jcspc_interf[iprof] = junkcspc_interf[iprof, ind[nhei_interf/2]]
606
606
607 #Removiendo la Interferencia
607 #Removiendo la Interferencia
608 jcspectra[ip,:,ind_hei] = jcspectra[ip,:,ind_hei] - jcspc_interf
608 jcspectra[ip,:,ind_hei] = jcspectra[ip,:,ind_hei] - jcspc_interf
609
609
610 ListAux = numpy.abs(jcspc_interf[mask_prof]).tolist()
610 ListAux = numpy.abs(jcspc_interf[mask_prof]).tolist()
611 maxid = ListAux.index(max(ListAux))
611 maxid = ListAux.index(max(ListAux))
612
612
613 ind = numpy.array([-2,-1,1,2])
613 ind = numpy.array([-2,-1,1,2])
614 xx = numpy.zeros([4,4])
614 xx = numpy.zeros([4,4])
615
615
616 for id1 in range(4):
616 for id1 in range(4):
617 xx[:,id1] = ind[id1]**numpy.asarray(range(4))
617 xx[:,id1] = ind[id1]**numpy.asarray(range(4))
618
618
619 xx_inv = numpy.linalg.inv(xx)
619 xx_inv = numpy.linalg.inv(xx)
620 xx = xx_inv[:,0]
620 xx = xx_inv[:,0]
621
621
622 ind = (ind + maxid + num_mask_prof)%num_mask_prof
622 ind = (ind + maxid + num_mask_prof)%num_mask_prof
623 yy = jcspectra[ip,mask_prof[ind],:]
623 yy = jcspectra[ip,mask_prof[ind],:]
624 jcspectra[ip,mask_prof[maxid],:] = numpy.dot(yy.transpose(),xx)
624 jcspectra[ip,mask_prof[maxid],:] = numpy.dot(yy.transpose(),xx)
625
625
626 #Guardar Resultados
626 #Guardar Resultados
627 self.dataOut.data_spc = jspectra
627 self.dataOut.data_spc = jspectra
628 self.dataOut.data_cspc = jcspectra
628 self.dataOut.data_cspc = jcspectra
629
629
630 return 1
630 return 1
631
631
632 def setRadarFrequency(self, frequency=None):
632 def setRadarFrequency(self, frequency=None):
633
633
634 if frequency != None:
634 if frequency != None:
635 self.dataOut.frequency = frequency
635 self.dataOut.frequency = frequency
636
636
637 return 1
637 return 1
638
638
639 def getNoise(self, minHei=None, maxHei=None, minVel=None, maxVel=None):
639 def getNoise(self, minHei=None, maxHei=None, minVel=None, maxVel=None):
640 #validacion de rango
640 #validacion de rango
641 if minHei == None:
641 if minHei == None:
642 minHei = self.dataOut.heightList[0]
642 minHei = self.dataOut.heightList[0]
643
643
644 if maxHei == None:
644 if maxHei == None:
645 maxHei = self.dataOut.heightList[-1]
645 maxHei = self.dataOut.heightList[-1]
646
646
647 if (minHei < self.dataOut.heightList[0]) or (minHei > maxHei):
647 if (minHei < self.dataOut.heightList[0]) or (minHei > maxHei):
648 print 'minHei: %.2f is out of the heights range'%(minHei)
648 print 'minHei: %.2f is out of the heights range'%(minHei)
649 print 'minHei is setting to %.2f'%(self.dataOut.heightList[0])
649 print 'minHei is setting to %.2f'%(self.dataOut.heightList[0])
650 minHei = self.dataOut.heightList[0]
650 minHei = self.dataOut.heightList[0]
651
651
652 if (maxHei > self.dataOut.heightList[-1]) or (maxHei < minHei):
652 if (maxHei > self.dataOut.heightList[-1]) or (maxHei < minHei):
653 print 'maxHei: %.2f is out of the heights range'%(maxHei)
653 print 'maxHei: %.2f is out of the heights range'%(maxHei)
654 print 'maxHei is setting to %.2f'%(self.dataOut.heightList[-1])
654 print 'maxHei is setting to %.2f'%(self.dataOut.heightList[-1])
655 maxHei = self.dataOut.heightList[-1]
655 maxHei = self.dataOut.heightList[-1]
656
656
657 # validacion de velocidades
657 # validacion de velocidades
658 velrange = self.dataOut.getVelRange(1)
658 velrange = self.dataOut.getVelRange(1)
659
659
660 if minVel == None:
660 if minVel == None:
661 minVel = velrange[0]
661 minVel = velrange[0]
662
662
663 if maxVel == None:
663 if maxVel == None:
664 maxVel = velrange[-1]
664 maxVel = velrange[-1]
665
665
666 if (minVel < velrange[0]) or (minVel > maxVel):
666 if (minVel < velrange[0]) or (minVel > maxVel):
667 print 'minVel: %.2f is out of the velocity range'%(minVel)
667 print 'minVel: %.2f is out of the velocity range'%(minVel)
668 print 'minVel is setting to %.2f'%(velrange[0])
668 print 'minVel is setting to %.2f'%(velrange[0])
669 minVel = velrange[0]
669 minVel = velrange[0]
670
670
671 if (maxVel > velrange[-1]) or (maxVel < minVel):
671 if (maxVel > velrange[-1]) or (maxVel < minVel):
672 print 'maxVel: %.2f is out of the velocity range'%(maxVel)
672 print 'maxVel: %.2f is out of the velocity range'%(maxVel)
673 print 'maxVel is setting to %.2f'%(velrange[-1])
673 print 'maxVel is setting to %.2f'%(velrange[-1])
674 maxVel = velrange[-1]
674 maxVel = velrange[-1]
675
675
676 # seleccion de indices para rango
676 # seleccion de indices para rango
677 minIndex = 0
677 minIndex = 0
678 maxIndex = 0
678 maxIndex = 0
679 heights = self.dataOut.heightList
679 heights = self.dataOut.heightList
680
680
681 inda = numpy.where(heights >= minHei)
681 inda = numpy.where(heights >= minHei)
682 indb = numpy.where(heights <= maxHei)
682 indb = numpy.where(heights <= maxHei)
683
683
684 try:
684 try:
685 minIndex = inda[0][0]
685 minIndex = inda[0][0]
686 except:
686 except:
687 minIndex = 0
687 minIndex = 0
688
688
689 try:
689 try:
690 maxIndex = indb[0][-1]
690 maxIndex = indb[0][-1]
691 except:
691 except:
692 maxIndex = len(heights)
692 maxIndex = len(heights)
693
693
694 if (minIndex < 0) or (minIndex > maxIndex):
694 if (minIndex < 0) or (minIndex > maxIndex):
695 raise ValueError, "some value in (%d,%d) is not valid" % (minIndex, maxIndex)
695 raise ValueError, "some value in (%d,%d) is not valid" % (minIndex, maxIndex)
696
696
697 if (maxIndex >= self.dataOut.nHeights):
697 if (maxIndex >= self.dataOut.nHeights):
698 maxIndex = self.dataOut.nHeights-1
698 maxIndex = self.dataOut.nHeights-1
699
699
700 # seleccion de indices para velocidades
700 # seleccion de indices para velocidades
701 indminvel = numpy.where(velrange >= minVel)
701 indminvel = numpy.where(velrange >= minVel)
702 indmaxvel = numpy.where(velrange <= maxVel)
702 indmaxvel = numpy.where(velrange <= maxVel)
703 try:
703 try:
704 minIndexVel = indminvel[0][0]
704 minIndexVel = indminvel[0][0]
705 except:
705 except:
706 minIndexVel = 0
706 minIndexVel = 0
707
707
708 try:
708 try:
709 maxIndexVel = indmaxvel[0][-1]
709 maxIndexVel = indmaxvel[0][-1]
710 except:
710 except:
711 maxIndexVel = len(velrange)
711 maxIndexVel = len(velrange)
712
712
713 #seleccion del espectro
713 #seleccion del espectro
714 data_spc = self.dataOut.data_spc[:,minIndexVel:maxIndexVel+1,minIndex:maxIndex+1]
714 data_spc = self.dataOut.data_spc[:,minIndexVel:maxIndexVel+1,minIndex:maxIndex+1]
715 #estimacion de ruido
715 #estimacion de ruido
716 noise = numpy.zeros(self.dataOut.nChannels)
716 noise = numpy.zeros(self.dataOut.nChannels)
717
717
718 for channel in range(self.dataOut.nChannels):
718 for channel in range(self.dataOut.nChannels):
719 daux = data_spc[channel,:,:]
719 daux = data_spc[channel,:,:]
720 noise[channel] = hildebrand_sekhon(daux, self.dataOut.nIncohInt)
720 noise[channel] = hildebrand_sekhon(daux, self.dataOut.nIncohInt)
721
721
722 self.dataOut.noise_estimation = noise.copy()
722 self.dataOut.noise_estimation = noise.copy()
723
723
724 return 1
724 return 1
725
725
726 class IncohInt(Operation):
726 class IncohInt(Operation):
727
727
728
728
729 __profIndex = 0
729 __profIndex = 0
730 __withOverapping = False
730 __withOverapping = False
731
731
732 __byTime = False
732 __byTime = False
733 __initime = None
733 __initime = None
734 __lastdatatime = None
734 __lastdatatime = None
735 __integrationtime = None
735 __integrationtime = None
736
736
737 __buffer_spc = None
737 __buffer_spc = None
738 __buffer_cspc = None
738 __buffer_cspc = None
739 __buffer_dc = None
739 __buffer_dc = None
740
740
741 __dataReady = False
741 __dataReady = False
742
742
743 __timeInterval = None
743 __timeInterval = None
744
744
745 parameters = {
746 'n': global_type_float,
747 'timeInterval': global_type_integer,
748 'overlapping': global_type_boolean,
749 }
750
745 n = None
751 n = None
746
752
747
753
748
754
749 def __init__(self, **kwargs):
755 def __init__(self, **kwargs):
750
756
751 Operation.__init__(self, **kwargs)
757 Operation.__init__(self, **kwargs)
752 # self.isConfig = False
758 # self.isConfig = False
753
759
754 def setup(self, n=None, timeInterval=None, overlapping=False):
760 def setup(self, n=None, timeInterval=None, overlapping=False):
755 """
761 """
756 Set the parameters of the integration class.
762 Set the parameters of the integration class.
757
763
758 Inputs:
764 Inputs:
759
765
760 n : Number of coherent integrations
766 n : Number of coherent integrations
761 timeInterval : Time of integration. If the parameter "n" is selected this one does not work
767 timeInterval : Time of integration. If the parameter "n" is selected this one does not work
762 overlapping :
768 overlapping :
763
769
764 """
770 """
765
771
766 self.__initime = None
772 self.__initime = None
767 self.__lastdatatime = 0
773 self.__lastdatatime = 0
768
774
769 self.__buffer_spc = 0
775 self.__buffer_spc = 0
770 self.__buffer_cspc = 0
776 self.__buffer_cspc = 0
771 self.__buffer_dc = 0
777 self.__buffer_dc = 0
772
778
773 self.__profIndex = 0
779 self.__profIndex = 0
774 self.__dataReady = False
780 self.__dataReady = False
775 self.__byTime = False
781 self.__byTime = False
776
782
777 if n is None and timeInterval is None:
783 if n is None and timeInterval is None:
778 raise ValueError, "n or timeInterval should be specified ..."
784 raise ValueError, "n or timeInterval should be specified ..."
779
785
780 if n is not None:
786 if n is not None:
781 self.n = int(n)
787 self.n = int(n)
782 else:
788 else:
783 self.__integrationtime = int(timeInterval) #if (type(timeInterval)!=integer) -> change this line
789 self.__integrationtime = int(timeInterval) #if (type(timeInterval)!=integer) -> change this line
784 self.n = None
790 self.n = None
785 self.__byTime = True
791 self.__byTime = True
786
792
787 def putData(self, data_spc, data_cspc, data_dc):
793 def putData(self, data_spc, data_cspc, data_dc):
788
794
789 """
795 """
790 Add a profile to the __buffer_spc and increase in one the __profileIndex
796 Add a profile to the __buffer_spc and increase in one the __profileIndex
791
797
792 """
798 """
793
799
794 self.__buffer_spc += data_spc
800 self.__buffer_spc += data_spc
795
801
796 if data_cspc is None:
802 if data_cspc is None:
797 self.__buffer_cspc = None
803 self.__buffer_cspc = None
798 else:
804 else:
799 self.__buffer_cspc += data_cspc
805 self.__buffer_cspc += data_cspc
800
806
801 if data_dc is None:
807 if data_dc is None:
802 self.__buffer_dc = None
808 self.__buffer_dc = None
803 else:
809 else:
804 self.__buffer_dc += data_dc
810 self.__buffer_dc += data_dc
805
811
806 self.__profIndex += 1
812 self.__profIndex += 1
807
813
808 return
814 return
809
815
810 def pushData(self):
816 def pushData(self):
811 """
817 """
812 Return the sum of the last profiles and the profiles used in the sum.
818 Return the sum of the last profiles and the profiles used in the sum.
813
819
814 Affected:
820 Affected:
815
821
816 self.__profileIndex
822 self.__profileIndex
817
823
818 """
824 """
819
825
820 data_spc = self.__buffer_spc
826 data_spc = self.__buffer_spc
821 data_cspc = self.__buffer_cspc
827 data_cspc = self.__buffer_cspc
822 data_dc = self.__buffer_dc
828 data_dc = self.__buffer_dc
823 n = self.__profIndex
829 n = self.__profIndex
824
830
825 self.__buffer_spc = 0
831 self.__buffer_spc = 0
826 self.__buffer_cspc = 0
832 self.__buffer_cspc = 0
827 self.__buffer_dc = 0
833 self.__buffer_dc = 0
828 self.__profIndex = 0
834 self.__profIndex = 0
829
835
830 return data_spc, data_cspc, data_dc, n
836 return data_spc, data_cspc, data_dc, n
831
837
832 def byProfiles(self, *args):
838 def byProfiles(self, *args):
833
839
834 self.__dataReady = False
840 self.__dataReady = False
835 avgdata_spc = None
841 avgdata_spc = None
836 avgdata_cspc = None
842 avgdata_cspc = None
837 avgdata_dc = None
843 avgdata_dc = None
838
844
839 self.putData(*args)
845 self.putData(*args)
840
846
841 if self.__profIndex == self.n:
847 if self.__profIndex == self.n:
842
848
843 avgdata_spc, avgdata_cspc, avgdata_dc, n = self.pushData()
849 avgdata_spc, avgdata_cspc, avgdata_dc, n = self.pushData()
844 self.n = n
850 self.n = n
845 self.__dataReady = True
851 self.__dataReady = True
846
852
847 return avgdata_spc, avgdata_cspc, avgdata_dc
853 return avgdata_spc, avgdata_cspc, avgdata_dc
848
854
849 def byTime(self, datatime, *args):
855 def byTime(self, datatime, *args):
850
856
851 self.__dataReady = False
857 self.__dataReady = False
852 avgdata_spc = None
858 avgdata_spc = None
853 avgdata_cspc = None
859 avgdata_cspc = None
854 avgdata_dc = None
860 avgdata_dc = None
855
861
856 self.putData(*args)
862 self.putData(*args)
857
863
858 if (datatime - self.__initime) >= self.__integrationtime:
864 if (datatime - self.__initime) >= self.__integrationtime:
859 avgdata_spc, avgdata_cspc, avgdata_dc, n = self.pushData()
865 avgdata_spc, avgdata_cspc, avgdata_dc, n = self.pushData()
860 self.n = n
866 self.n = n
861 self.__dataReady = True
867 self.__dataReady = True
862
868
863 return avgdata_spc, avgdata_cspc, avgdata_dc
869 return avgdata_spc, avgdata_cspc, avgdata_dc
864
870
865 def integrate(self, datatime, *args):
871 def integrate(self, datatime, *args):
866
872
867 if self.__profIndex == 0:
873 if self.__profIndex == 0:
868 self.__initime = datatime
874 self.__initime = datatime
869
875
870 if self.__byTime:
876 if self.__byTime:
871 avgdata_spc, avgdata_cspc, avgdata_dc = self.byTime(datatime, *args)
877 avgdata_spc, avgdata_cspc, avgdata_dc = self.byTime(datatime, *args)
872 else:
878 else:
873 avgdata_spc, avgdata_cspc, avgdata_dc = self.byProfiles(*args)
879 avgdata_spc, avgdata_cspc, avgdata_dc = self.byProfiles(*args)
874
880
875 if not self.__dataReady:
881 if not self.__dataReady:
876 return None, None, None, None
882 return None, None, None, None
877
883
878 return self.__initime, avgdata_spc, avgdata_cspc, avgdata_dc
884 return self.__initime, avgdata_spc, avgdata_cspc, avgdata_dc
879
885
880 def run(self, dataOut, n=None, timeInterval=None, overlapping=False):
886 def run(self, dataOut, n=None, timeInterval=None, overlapping=False):
881
887
882 if n==1:
888 if n==1:
883 return
889 return
884
890
885 dataOut.flagNoData = True
891 dataOut.flagNoData = True
886
892
887 if not self.isConfig:
893 if not self.isConfig:
888 self.setup(n, timeInterval, overlapping)
894 self.setup(n, timeInterval, overlapping)
889 self.isConfig = True
895 self.isConfig = True
890
896
891 avgdatatime, avgdata_spc, avgdata_cspc, avgdata_dc = self.integrate(dataOut.utctime,
897 avgdatatime, avgdata_spc, avgdata_cspc, avgdata_dc = self.integrate(dataOut.utctime,
892 dataOut.data_spc,
898 dataOut.data_spc,
893 dataOut.data_cspc,
899 dataOut.data_cspc,
894 dataOut.data_dc)
900 dataOut.data_dc)
895
901
896 if self.__dataReady:
902 if self.__dataReady:
897
903
898 dataOut.data_spc = avgdata_spc
904 dataOut.data_spc = avgdata_spc
899 dataOut.data_cspc = avgdata_cspc
905 dataOut.data_cspc = avgdata_cspc
900 dataOut.data_dc = avgdata_dc
906 dataOut.data_dc = avgdata_dc
901
907
902 dataOut.nIncohInt *= self.n
908 dataOut.nIncohInt *= self.n
903 dataOut.utctime = avgdatatime
909 dataOut.utctime = avgdatatime
904 dataOut.flagNoData = False
910 dataOut.flagNoData = False
@@ -1,1310 +1,1349
1 import sys
1 import sys
2 import numpy
2 import numpy
3 from profilehooks import profile
3 from profilehooks import profile
4 from scipy import interpolate
4 from scipy import interpolate
5 from schainpy import cSchain
5 from schainpy import cSchain
6 from jroproc_base import ProcessingUnit, Operation
6 from jroproc_base import ProcessingUnit, Operation
7 from schainpy.model.data.jrodata import Voltage
7 from schainpy.model.data.jrodata import Voltage
8 from time import time
8 from time import time
9
9
10 class VoltageProc(ProcessingUnit):
10 class VoltageProc(ProcessingUnit):
11
11
12
12
13 def __init__(self, **kwargs):
13 def __init__(self, **kwargs):
14
14
15 ProcessingUnit.__init__(self, **kwargs)
15 ProcessingUnit.__init__(self, **kwargs)
16
16
17 # self.objectDict = {}
17 # self.objectDict = {}
18 self.dataOut = Voltage()
18 self.dataOut = Voltage()
19 self.flip = 1
19 self.flip = 1
20
20
21 def run(self):
21 def run(self):
22 if self.dataIn.type == 'AMISR':
22 if self.dataIn.type == 'AMISR':
23 self.__updateObjFromAmisrInput()
23 self.__updateObjFromAmisrInput()
24
24
25 if self.dataIn.type == 'Voltage':
25 if self.dataIn.type == 'Voltage':
26 self.dataOut.copy(self.dataIn)
26 self.dataOut.copy(self.dataIn)
27
27
28 # self.dataOut.copy(self.dataIn)
28 # self.dataOut.copy(self.dataIn)
29
29
30 def __updateObjFromAmisrInput(self):
30 def __updateObjFromAmisrInput(self):
31
31
32 self.dataOut.timeZone = self.dataIn.timeZone
32 self.dataOut.timeZone = self.dataIn.timeZone
33 self.dataOut.dstFlag = self.dataIn.dstFlag
33 self.dataOut.dstFlag = self.dataIn.dstFlag
34 self.dataOut.errorCount = self.dataIn.errorCount
34 self.dataOut.errorCount = self.dataIn.errorCount
35 self.dataOut.useLocalTime = self.dataIn.useLocalTime
35 self.dataOut.useLocalTime = self.dataIn.useLocalTime
36
36
37 self.dataOut.flagNoData = self.dataIn.flagNoData
37 self.dataOut.flagNoData = self.dataIn.flagNoData
38 self.dataOut.data = self.dataIn.data
38 self.dataOut.data = self.dataIn.data
39 self.dataOut.utctime = self.dataIn.utctime
39 self.dataOut.utctime = self.dataIn.utctime
40 self.dataOut.channelList = self.dataIn.channelList
40 self.dataOut.channelList = self.dataIn.channelList
41 # self.dataOut.timeInterval = self.dataIn.timeInterval
41 # self.dataOut.timeInterval = self.dataIn.timeInterval
42 self.dataOut.heightList = self.dataIn.heightList
42 self.dataOut.heightList = self.dataIn.heightList
43 self.dataOut.nProfiles = self.dataIn.nProfiles
43 self.dataOut.nProfiles = self.dataIn.nProfiles
44
44
45 self.dataOut.nCohInt = self.dataIn.nCohInt
45 self.dataOut.nCohInt = self.dataIn.nCohInt
46 self.dataOut.ippSeconds = self.dataIn.ippSeconds
46 self.dataOut.ippSeconds = self.dataIn.ippSeconds
47 self.dataOut.frequency = self.dataIn.frequency
47 self.dataOut.frequency = self.dataIn.frequency
48
48
49 self.dataOut.azimuth = self.dataIn.azimuth
49 self.dataOut.azimuth = self.dataIn.azimuth
50 self.dataOut.zenith = self.dataIn.zenith
50 self.dataOut.zenith = self.dataIn.zenith
51
51
52 self.dataOut.beam.codeList = self.dataIn.beam.codeList
52 self.dataOut.beam.codeList = self.dataIn.beam.codeList
53 self.dataOut.beam.azimuthList = self.dataIn.beam.azimuthList
53 self.dataOut.beam.azimuthList = self.dataIn.beam.azimuthList
54 self.dataOut.beam.zenithList = self.dataIn.beam.zenithList
54 self.dataOut.beam.zenithList = self.dataIn.beam.zenithList
55 #
55 #
56 # pass#
56 # pass#
57 #
57 #
58 # def init(self):
58 # def init(self):
59 #
59 #
60 #
60 #
61 # if self.dataIn.type == 'AMISR':
61 # if self.dataIn.type == 'AMISR':
62 # self.__updateObjFromAmisrInput()
62 # self.__updateObjFromAmisrInput()
63 #
63 #
64 # if self.dataIn.type == 'Voltage':
64 # if self.dataIn.type == 'Voltage':
65 # self.dataOut.copy(self.dataIn)
65 # self.dataOut.copy(self.dataIn)
66 # # No necesita copiar en cada init() los atributos de dataIn
66 # # No necesita copiar en cada init() los atributos de dataIn
67 # # la copia deberia hacerse por cada nuevo bloque de datos
67 # # la copia deberia hacerse por cada nuevo bloque de datos
68
68
69 def selectChannels(self, channelList):
69 def selectChannels(self, channelList):
70
70
71 channelIndexList = []
71 channelIndexList = []
72
72
73 for channel in channelList:
73 for channel in channelList:
74 if channel not in self.dataOut.channelList:
74 if channel not in self.dataOut.channelList:
75 raise ValueError, "Channel %d is not in %s" %(channel, str(self.dataOut.channelList))
75 raise ValueError, "Channel %d is not in %s" %(channel, str(self.dataOut.channelList))
76
76
77 index = self.dataOut.channelList.index(channel)
77 index = self.dataOut.channelList.index(channel)
78 channelIndexList.append(index)
78 channelIndexList.append(index)
79
79
80 self.selectChannelsByIndex(channelIndexList)
80 self.selectChannelsByIndex(channelIndexList)
81
81
82 def selectChannelsByIndex(self, channelIndexList):
82 def selectChannelsByIndex(self, channelIndexList):
83 """
83 """
84 Selecciona un bloque de datos en base a canales segun el channelIndexList
84 Selecciona un bloque de datos en base a canales segun el channelIndexList
85
85
86 Input:
86 Input:
87 channelIndexList : lista sencilla de canales a seleccionar por ej. [2,3,7]
87 channelIndexList : lista sencilla de canales a seleccionar por ej. [2,3,7]
88
88
89 Affected:
89 Affected:
90 self.dataOut.data
90 self.dataOut.data
91 self.dataOut.channelIndexList
91 self.dataOut.channelIndexList
92 self.dataOut.nChannels
92 self.dataOut.nChannels
93 self.dataOut.m_ProcessingHeader.totalSpectra
93 self.dataOut.m_ProcessingHeader.totalSpectra
94 self.dataOut.systemHeaderObj.numChannels
94 self.dataOut.systemHeaderObj.numChannels
95 self.dataOut.m_ProcessingHeader.blockSize
95 self.dataOut.m_ProcessingHeader.blockSize
96
96
97 Return:
97 Return:
98 None
98 None
99 """
99 """
100
100
101 for channelIndex in channelIndexList:
101 for channelIndex in channelIndexList:
102 if channelIndex not in self.dataOut.channelIndexList:
102 if channelIndex not in self.dataOut.channelIndexList:
103 print channelIndexList
103 print channelIndexList
104 raise ValueError, "The value %d in channelIndexList is not valid" %channelIndex
104 raise ValueError, "The value %d in channelIndexList is not valid" %channelIndex
105
105
106 if self.dataOut.flagDataAsBlock:
106 if self.dataOut.flagDataAsBlock:
107 """
107 """
108 Si la data es obtenida por bloques, dimension = [nChannels, nProfiles, nHeis]
108 Si la data es obtenida por bloques, dimension = [nChannels, nProfiles, nHeis]
109 """
109 """
110 data = self.dataOut.data[channelIndexList,:,:]
110 data = self.dataOut.data[channelIndexList,:,:]
111 else:
111 else:
112 data = self.dataOut.data[channelIndexList,:]
112 data = self.dataOut.data[channelIndexList,:]
113
113
114 self.dataOut.data = data
114 self.dataOut.data = data
115 self.dataOut.channelList = [self.dataOut.channelList[i] for i in channelIndexList]
115 self.dataOut.channelList = [self.dataOut.channelList[i] for i in channelIndexList]
116 # self.dataOut.nChannels = nChannels
116 # self.dataOut.nChannels = nChannels
117
117
118 return 1
118 return 1
119
119
120 def selectHeights(self, minHei=None, maxHei=None):
120 def selectHeights(self, minHei=None, maxHei=None):
121 """
121 """
122 Selecciona un bloque de datos en base a un grupo de valores de alturas segun el rango
122 Selecciona un bloque de datos en base a un grupo de valores de alturas segun el rango
123 minHei <= height <= maxHei
123 minHei <= height <= maxHei
124
124
125 Input:
125 Input:
126 minHei : valor minimo de altura a considerar
126 minHei : valor minimo de altura a considerar
127 maxHei : valor maximo de altura a considerar
127 maxHei : valor maximo de altura a considerar
128
128
129 Affected:
129 Affected:
130 Indirectamente son cambiados varios valores a travez del metodo selectHeightsByIndex
130 Indirectamente son cambiados varios valores a travez del metodo selectHeightsByIndex
131
131
132 Return:
132 Return:
133 1 si el metodo se ejecuto con exito caso contrario devuelve 0
133 1 si el metodo se ejecuto con exito caso contrario devuelve 0
134 """
134 """
135
135
136 if minHei == None:
136 if minHei == None:
137 minHei = self.dataOut.heightList[0]
137 minHei = self.dataOut.heightList[0]
138
138
139 if maxHei == None:
139 if maxHei == None:
140 maxHei = self.dataOut.heightList[-1]
140 maxHei = self.dataOut.heightList[-1]
141
141
142 if (minHei < self.dataOut.heightList[0]):
142 if (minHei < self.dataOut.heightList[0]):
143 minHei = self.dataOut.heightList[0]
143 minHei = self.dataOut.heightList[0]
144
144
145 if (maxHei > self.dataOut.heightList[-1]):
145 if (maxHei > self.dataOut.heightList[-1]):
146 maxHei = self.dataOut.heightList[-1]
146 maxHei = self.dataOut.heightList[-1]
147
147
148 minIndex = 0
148 minIndex = 0
149 maxIndex = 0
149 maxIndex = 0
150 heights = self.dataOut.heightList
150 heights = self.dataOut.heightList
151
151
152 inda = numpy.where(heights >= minHei)
152 inda = numpy.where(heights >= minHei)
153 indb = numpy.where(heights <= maxHei)
153 indb = numpy.where(heights <= maxHei)
154
154
155 try:
155 try:
156 minIndex = inda[0][0]
156 minIndex = inda[0][0]
157 except:
157 except:
158 minIndex = 0
158 minIndex = 0
159
159
160 try:
160 try:
161 maxIndex = indb[0][-1]
161 maxIndex = indb[0][-1]
162 except:
162 except:
163 maxIndex = len(heights)
163 maxIndex = len(heights)
164
164
165 self.selectHeightsByIndex(minIndex, maxIndex)
165 self.selectHeightsByIndex(minIndex, maxIndex)
166
166
167 return 1
167 return 1
168
168
169
169
170 def selectHeightsByIndex(self, minIndex, maxIndex):
170 def selectHeightsByIndex(self, minIndex, maxIndex):
171 """
171 """
172 Selecciona un bloque de datos en base a un grupo indices de alturas segun el rango
172 Selecciona un bloque de datos en base a un grupo indices de alturas segun el rango
173 minIndex <= index <= maxIndex
173 minIndex <= index <= maxIndex
174
174
175 Input:
175 Input:
176 minIndex : valor de indice minimo de altura a considerar
176 minIndex : valor de indice minimo de altura a considerar
177 maxIndex : valor de indice maximo de altura a considerar
177 maxIndex : valor de indice maximo de altura a considerar
178
178
179 Affected:
179 Affected:
180 self.dataOut.data
180 self.dataOut.data
181 self.dataOut.heightList
181 self.dataOut.heightList
182
182
183 Return:
183 Return:
184 1 si el metodo se ejecuto con exito caso contrario devuelve 0
184 1 si el metodo se ejecuto con exito caso contrario devuelve 0
185 """
185 """
186
186
187 if (minIndex < 0) or (minIndex > maxIndex):
187 if (minIndex < 0) or (minIndex > maxIndex):
188 raise ValueError, "Height index range (%d,%d) is not valid" % (minIndex, maxIndex)
188 raise ValueError, "Height index range (%d,%d) is not valid" % (minIndex, maxIndex)
189
189
190 if (maxIndex >= self.dataOut.nHeights):
190 if (maxIndex >= self.dataOut.nHeights):
191 maxIndex = self.dataOut.nHeights
191 maxIndex = self.dataOut.nHeights
192
192
193 #voltage
193 #voltage
194 if self.dataOut.flagDataAsBlock:
194 if self.dataOut.flagDataAsBlock:
195 """
195 """
196 Si la data es obtenida por bloques, dimension = [nChannels, nProfiles, nHeis]
196 Si la data es obtenida por bloques, dimension = [nChannels, nProfiles, nHeis]
197 """
197 """
198 data = self.dataOut.data[:,:, minIndex:maxIndex]
198 data = self.dataOut.data[:,:, minIndex:maxIndex]
199 else:
199 else:
200 data = self.dataOut.data[:, minIndex:maxIndex]
200 data = self.dataOut.data[:, minIndex:maxIndex]
201
201
202 # firstHeight = self.dataOut.heightList[minIndex]
202 # firstHeight = self.dataOut.heightList[minIndex]
203
203
204 self.dataOut.data = data
204 self.dataOut.data = data
205 self.dataOut.heightList = self.dataOut.heightList[minIndex:maxIndex]
205 self.dataOut.heightList = self.dataOut.heightList[minIndex:maxIndex]
206
206
207 if self.dataOut.nHeights <= 1:
207 if self.dataOut.nHeights <= 1:
208 raise ValueError, "selectHeights: Too few heights. Current number of heights is %d" %(self.dataOut.nHeights)
208 raise ValueError, "selectHeights: Too few heights. Current number of heights is %d" %(self.dataOut.nHeights)
209
209
210 return 1
210 return 1
211
211
212
212
213 def filterByHeights(self, window):
213 def filterByHeights(self, window):
214
214
215 deltaHeight = self.dataOut.heightList[1] - self.dataOut.heightList[0]
215 deltaHeight = self.dataOut.heightList[1] - self.dataOut.heightList[0]
216
216
217 if window == None:
217 if window == None:
218 window = (self.dataOut.radarControllerHeaderObj.txA/self.dataOut.radarControllerHeaderObj.nBaud) / deltaHeight
218 window = (self.dataOut.radarControllerHeaderObj.txA/self.dataOut.radarControllerHeaderObj.nBaud) / deltaHeight
219
219
220 newdelta = deltaHeight * window
220 newdelta = deltaHeight * window
221 r = self.dataOut.nHeights % window
221 r = self.dataOut.nHeights % window
222 newheights = (self.dataOut.nHeights-r)/window
222 newheights = (self.dataOut.nHeights-r)/window
223
223
224 if newheights <= 1:
224 if newheights <= 1:
225 raise ValueError, "filterByHeights: Too few heights. Current number of heights is %d and window is %d" %(self.dataOut.nHeights, window)
225 raise ValueError, "filterByHeights: Too few heights. Current number of heights is %d and window is %d" %(self.dataOut.nHeights, window)
226
226
227 if self.dataOut.flagDataAsBlock:
227 if self.dataOut.flagDataAsBlock:
228 """
228 """
229 Si la data es obtenida por bloques, dimension = [nChannels, nProfiles, nHeis]
229 Si la data es obtenida por bloques, dimension = [nChannels, nProfiles, nHeis]
230 """
230 """
231 buffer = self.dataOut.data[:, :, 0:self.dataOut.nHeights-r]
231 buffer = self.dataOut.data[:, :, 0:self.dataOut.nHeights-r]
232 buffer = buffer.reshape(self.dataOut.nChannels,self.dataOut.nProfiles,self.dataOut.nHeights/window,window)
232 buffer = buffer.reshape(self.dataOut.nChannels,self.dataOut.nProfiles,self.dataOut.nHeights/window,window)
233 buffer = numpy.sum(buffer,3)
233 buffer = numpy.sum(buffer,3)
234
234
235 else:
235 else:
236 buffer = self.dataOut.data[:,0:self.dataOut.nHeights-r]
236 buffer = self.dataOut.data[:,0:self.dataOut.nHeights-r]
237 buffer = buffer.reshape(self.dataOut.nChannels,self.dataOut.nHeights/window,window)
237 buffer = buffer.reshape(self.dataOut.nChannels,self.dataOut.nHeights/window,window)
238 buffer = numpy.sum(buffer,2)
238 buffer = numpy.sum(buffer,2)
239
239
240 self.dataOut.data = buffer
240 self.dataOut.data = buffer
241 self.dataOut.heightList = self.dataOut.heightList[0] + numpy.arange( newheights )*newdelta
241 self.dataOut.heightList = self.dataOut.heightList[0] + numpy.arange( newheights )*newdelta
242 self.dataOut.windowOfFilter = window
242 self.dataOut.windowOfFilter = window
243
243
244 def setH0(self, h0, deltaHeight = None):
244 def setH0(self, h0, deltaHeight = None):
245
245
246 if not deltaHeight:
246 if not deltaHeight:
247 deltaHeight = self.dataOut.heightList[1] - self.dataOut.heightList[0]
247 deltaHeight = self.dataOut.heightList[1] - self.dataOut.heightList[0]
248
248
249 nHeights = self.dataOut.nHeights
249 nHeights = self.dataOut.nHeights
250
250
251 newHeiRange = h0 + numpy.arange(nHeights)*deltaHeight
251 newHeiRange = h0 + numpy.arange(nHeights)*deltaHeight
252
252
253 self.dataOut.heightList = newHeiRange
253 self.dataOut.heightList = newHeiRange
254
254
255 def deFlip(self, channelList = []):
255 def deFlip(self, channelList = []):
256
256
257 data = self.dataOut.data.copy()
257 data = self.dataOut.data.copy()
258
258
259 if self.dataOut.flagDataAsBlock:
259 if self.dataOut.flagDataAsBlock:
260 flip = self.flip
260 flip = self.flip
261 profileList = range(self.dataOut.nProfiles)
261 profileList = range(self.dataOut.nProfiles)
262
262
263 if not channelList:
263 if not channelList:
264 for thisProfile in profileList:
264 for thisProfile in profileList:
265 data[:,thisProfile,:] = data[:,thisProfile,:]*flip
265 data[:,thisProfile,:] = data[:,thisProfile,:]*flip
266 flip *= -1.0
266 flip *= -1.0
267 else:
267 else:
268 for thisChannel in channelList:
268 for thisChannel in channelList:
269 if thisChannel not in self.dataOut.channelList:
269 if thisChannel not in self.dataOut.channelList:
270 continue
270 continue
271
271
272 for thisProfile in profileList:
272 for thisProfile in profileList:
273 data[thisChannel,thisProfile,:] = data[thisChannel,thisProfile,:]*flip
273 data[thisChannel,thisProfile,:] = data[thisChannel,thisProfile,:]*flip
274 flip *= -1.0
274 flip *= -1.0
275
275
276 self.flip = flip
276 self.flip = flip
277
277
278 else:
278 else:
279 if not channelList:
279 if not channelList:
280 data[:,:] = data[:,:]*self.flip
280 data[:,:] = data[:,:]*self.flip
281 else:
281 else:
282 for thisChannel in channelList:
282 for thisChannel in channelList:
283 if thisChannel not in self.dataOut.channelList:
283 if thisChannel not in self.dataOut.channelList:
284 continue
284 continue
285
285
286 data[thisChannel,:] = data[thisChannel,:]*self.flip
286 data[thisChannel,:] = data[thisChannel,:]*self.flip
287
287
288 self.flip *= -1.
288 self.flip *= -1.
289
289
290 self.dataOut.data = data
290 self.dataOut.data = data
291
291
292 def setRadarFrequency(self, frequency=None):
292 def setRadarFrequency(self, frequency=None):
293
293
294 if frequency != None:
294 if frequency != None:
295 self.dataOut.frequency = frequency
295 self.dataOut.frequency = frequency
296
296
297 return 1
297 return 1
298
298
299 def interpolateHeights(self, topLim, botLim):
299 def interpolateHeights(self, topLim, botLim):
300 #69 al 72 para julia
300 #69 al 72 para julia
301 #82-84 para meteoros
301 #82-84 para meteoros
302 if len(numpy.shape(self.dataOut.data))==2:
302 if len(numpy.shape(self.dataOut.data))==2:
303 sampInterp = (self.dataOut.data[:,botLim-1] + self.dataOut.data[:,topLim+1])/2
303 sampInterp = (self.dataOut.data[:,botLim-1] + self.dataOut.data[:,topLim+1])/2
304 sampInterp = numpy.transpose(numpy.tile(sampInterp,(topLim-botLim + 1,1)))
304 sampInterp = numpy.transpose(numpy.tile(sampInterp,(topLim-botLim + 1,1)))
305 #self.dataOut.data[:,botLim:limSup+1] = sampInterp
305 #self.dataOut.data[:,botLim:limSup+1] = sampInterp
306 self.dataOut.data[:,botLim:topLim+1] = sampInterp
306 self.dataOut.data[:,botLim:topLim+1] = sampInterp
307 else:
307 else:
308 nHeights = self.dataOut.data.shape[2]
308 nHeights = self.dataOut.data.shape[2]
309 x = numpy.hstack((numpy.arange(botLim),numpy.arange(topLim+1,nHeights)))
309 x = numpy.hstack((numpy.arange(botLim),numpy.arange(topLim+1,nHeights)))
310 y = self.dataOut.data[:,:,range(botLim)+range(topLim+1,nHeights)]
310 y = self.dataOut.data[:,:,range(botLim)+range(topLim+1,nHeights)]
311 f = interpolate.interp1d(x, y, axis = 2)
311 f = interpolate.interp1d(x, y, axis = 2)
312 xnew = numpy.arange(botLim,topLim+1)
312 xnew = numpy.arange(botLim,topLim+1)
313 ynew = f(xnew)
313 ynew = f(xnew)
314
314
315 self.dataOut.data[:,:,botLim:topLim+1] = ynew
315 self.dataOut.data[:,:,botLim:topLim+1] = ynew
316
316
317 # import collections
317 # import collections
318
318
319 class CohInt(Operation):
319 class CohInt(Operation):
320
320
321 isConfig = False
321 isConfig = False
322
322
323 __profIndex = 0
323 __profIndex = 0
324 __withOverapping = False
324 __withOverapping = False
325
325
326 __byTime = False
326 __byTime = False
327 __initime = None
327 __initime = None
328 __lastdatatime = None
328 __lastdatatime = None
329 __integrationtime = None
329 __integrationtime = None
330
330
331 __buffer = None
331 __buffer = None
332
332
333 __dataReady = False
333 __dataReady = False
334
334
335 n = None
335 n = None
336
336
337 parameters = {
338 'id': global_type_string,
339 'wintitle': global_type_string,
340 'pairsList': global_type_pairsList,
341 'showprofile': global_type_boolean,
342 'xmin': global_type_float,
343 'xmax': global_type_float,
344 'ymin': global_type_float,
345 'ymax': global_type_float,
346 'zmin': global_type_float,
347 'zmax': global_type_float,
348 'timerange': global_type_float,
349 'phase_min': global_type_float,
350 'phase_max': global_type_float,
351 'save': global_type_boolean,
352 'figpath': global_type_string,
353 'figfile': global_type_string,
354 'ftp': global_type_boolean,
355 'wr_period': global_type_integer,
356 'coherence_cmap': global_type_colormap,
357 'phase_cmap': global_type_colormap,
358 'show': global_type_boolean,
359 'server': global_type_string,
360 'folder': global_type_string,
361 'username': global_type_string,
362 'password': global_type_string,
363 'ftp_wei': global_type_integer,
364 'exp_code': global_type_integer,
365 'sub_exp_code': global_type_integer,
366 'plot_pos': global_type_integer,
367 }
337
368
338 def __init__(self, **kwargs):
369 def __init__(self, **kwargs):
339
370
340 Operation.__init__(self, **kwargs)
371 Operation.__init__(self, **kwargs)
341
372
342 # self.isConfig = False
373 # self.isConfig = False
343
374
344 def setup(self, n=None, timeInterval=None, overlapping=False, byblock=False):
375 def setup(self, n=None, timeInterval=None, overlapping=False, byblock=False):
345 """
376 """
346 Set the parameters of the integration class.
377 Set the parameters of the integration class.
347
378
348 Inputs:
379 Inputs:
349
380
350 n : Number of coherent integrations
381 n : Number of coherent integrations
351 timeInterval : Time of integration. If the parameter "n" is selected this one does not work
382 timeInterval : Time of integration. If the parameter "n" is selected this one does not work
352 overlapping :
383 overlapping :
353
354 """
384 """
355
385
356 self.__initime = None
386 self.__initime = None
357 self.__lastdatatime = 0
387 self.__lastdatatime = 0
358 self.__buffer = None
388 self.__buffer = None
359 self.__dataReady = False
389 self.__dataReady = False
360 self.byblock = byblock
390 self.byblock = byblock
361
391
362 if n == None and timeInterval == None:
392 if n == None and timeInterval == None:
363 raise ValueError, "n or timeInterval should be specified ..."
393 raise ValueError, "n or timeInterval should be specified ..."
364
394
365 if n != None:
395 if n != None:
366 self.n = n
396 self.n = n
367 self.__byTime = False
397 self.__byTime = False
368 else:
398 else:
369 self.__integrationtime = timeInterval #* 60. #if (type(timeInterval)!=integer) -> change this line
399 self.__integrationtime = timeInterval #* 60. #if (type(timeInterval)!=integer) -> change this line
370 self.n = 9999
400 self.n = 9999
371 self.__byTime = True
401 self.__byTime = True
372
402
373 if overlapping:
403 if overlapping:
374 self.__withOverapping = True
404 self.__withOverapping = True
375 self.__buffer = None
405 self.__buffer = None
376 else:
406 else:
377 self.__withOverapping = False
407 self.__withOverapping = False
378 self.__buffer = 0
408 self.__buffer = 0
379
409
380 self.__profIndex = 0
410 self.__profIndex = 0
381
411
382 def putData(self, data):
412 def putData(self, data):
383
413
384 """
414 """
385 Add a profile to the __buffer and increase in one the __profileIndex
415 Add a profile to the __buffer and increase in one the __profileIndex
386
416
387 """
417 """
388
418
389 if not self.__withOverapping:
419 if not self.__withOverapping:
390 self.__buffer += data.copy()
420 self.__buffer += data.copy()
391 self.__profIndex += 1
421 self.__profIndex += 1
392 return
422 return
393
423
394 #Overlapping data
424 #Overlapping data
395 nChannels, nHeis = data.shape
425 nChannels, nHeis = data.shape
396 data = numpy.reshape(data, (1, nChannels, nHeis))
426 data = numpy.reshape(data, (1, nChannels, nHeis))
397
427
398 #If the buffer is empty then it takes the data value
428 #If the buffer is empty then it takes the data value
399 if self.__buffer is None:
429 if self.__buffer is None:
400 self.__buffer = data
430 self.__buffer = data
401 self.__profIndex += 1
431 self.__profIndex += 1
402 return
432 return
403
433
404 #If the buffer length is lower than n then stakcing the data value
434 #If the buffer length is lower than n then stakcing the data value
405 if self.__profIndex < self.n:
435 if self.__profIndex < self.n:
406 self.__buffer = numpy.vstack((self.__buffer, data))
436 self.__buffer = numpy.vstack((self.__buffer, data))
407 self.__profIndex += 1
437 self.__profIndex += 1
408 return
438 return
409
439
410 #If the buffer length is equal to n then replacing the last buffer value with the data value
440 #If the buffer length is equal to n then replacing the last buffer value with the data value
411 self.__buffer = numpy.roll(self.__buffer, -1, axis=0)
441 self.__buffer = numpy.roll(self.__buffer, -1, axis=0)
412 self.__buffer[self.n-1] = data
442 self.__buffer[self.n-1] = data
413 self.__profIndex = self.n
443 self.__profIndex = self.n
414 return
444 return
415
445
416
446
417 def pushData(self):
447 def pushData(self):
418 """
448 """
419 Return the sum of the last profiles and the profiles used in the sum.
449 Return the sum of the last profiles and the profiles used in the sum.
420
450
421 Affected:
451 Affected:
422
452
423 self.__profileIndex
453 self.__profileIndex
424
454
425 """
455 """
426
456
427 if not self.__withOverapping:
457 if not self.__withOverapping:
428 data = self.__buffer
458 data = self.__buffer
429 n = self.__profIndex
459 n = self.__profIndex
430
460
431 self.__buffer = 0
461 self.__buffer = 0
432 self.__profIndex = 0
462 self.__profIndex = 0
433
463
434 return data, n
464 return data, n
435
465
436 #Integration with Overlapping
466 #Integration with Overlapping
437 data = numpy.sum(self.__buffer, axis=0)
467 data = numpy.sum(self.__buffer, axis=0)
438 n = self.__profIndex
468 n = self.__profIndex
439
469
440 return data, n
470 return data, n
441
471
442 def byProfiles(self, data):
472 def byProfiles(self, data):
443
473
444 self.__dataReady = False
474 self.__dataReady = False
445 avgdata = None
475 avgdata = None
446 # n = None
476 # n = None
447
477
448 self.putData(data)
478 self.putData(data)
449
479
450 if self.__profIndex == self.n:
480 if self.__profIndex == self.n:
451
481
452 avgdata, n = self.pushData()
482 avgdata, n = self.pushData()
453 self.__dataReady = True
483 self.__dataReady = True
454
484
455 return avgdata
485 return avgdata
456
486
457 def byTime(self, data, datatime):
487 def byTime(self, data, datatime):
458
488
459 self.__dataReady = False
489 self.__dataReady = False
460 avgdata = None
490 avgdata = None
461 n = None
491 n = None
462
492
463 self.putData(data)
493 self.putData(data)
464
494
465 if (datatime - self.__initime) >= self.__integrationtime:
495 if (datatime - self.__initime) >= self.__integrationtime:
466 avgdata, n = self.pushData()
496 avgdata, n = self.pushData()
467 self.n = n
497 self.n = n
468 self.__dataReady = True
498 self.__dataReady = True
469
499
470 return avgdata
500 return avgdata
471
501
472 def integrate(self, data, datatime=None):
502 def integrate(self, data, datatime=None):
473
503
474 if self.__initime == None:
504 if self.__initime == None:
475 self.__initime = datatime
505 self.__initime = datatime
476
506
477 if self.__byTime:
507 if self.__byTime:
478 avgdata = self.byTime(data, datatime)
508 avgdata = self.byTime(data, datatime)
479 else:
509 else:
480 avgdata = self.byProfiles(data)
510 avgdata = self.byProfiles(data)
481
511
482
512
483 self.__lastdatatime = datatime
513 self.__lastdatatime = datatime
484
514
485 if avgdata is None:
515 if avgdata is None:
486 return None, None
516 return None, None
487
517
488 avgdatatime = self.__initime
518 avgdatatime = self.__initime
489
519
490 deltatime = datatime -self.__lastdatatime
520 deltatime = datatime -self.__lastdatatime
491
521
492 if not self.__withOverapping:
522 if not self.__withOverapping:
493 self.__initime = datatime
523 self.__initime = datatime
494 else:
524 else:
495 self.__initime += deltatime
525 self.__initime += deltatime
496
526
497 return avgdata, avgdatatime
527 return avgdata, avgdatatime
498
528
499 def integrateByBlock(self, dataOut):
529 def integrateByBlock(self, dataOut):
500
530
501 times = int(dataOut.data.shape[1]/self.n)
531 times = int(dataOut.data.shape[1]/self.n)
502 avgdata = numpy.zeros((dataOut.nChannels, times, dataOut.nHeights), dtype=numpy.complex)
532 avgdata = numpy.zeros((dataOut.nChannels, times, dataOut.nHeights), dtype=numpy.complex)
503
533
504 id_min = 0
534 id_min = 0
505 id_max = self.n
535 id_max = self.n
506
536
507 for i in range(times):
537 for i in range(times):
508 junk = dataOut.data[:,id_min:id_max,:]
538 junk = dataOut.data[:,id_min:id_max,:]
509 avgdata[:,i,:] = junk.sum(axis=1)
539 avgdata[:,i,:] = junk.sum(axis=1)
510 id_min += self.n
540 id_min += self.n
511 id_max += self.n
541 id_max += self.n
512
542
513 timeInterval = dataOut.ippSeconds*self.n
543 timeInterval = dataOut.ippSeconds*self.n
514 avgdatatime = (times - 1) * timeInterval + dataOut.utctime
544 avgdatatime = (times - 1) * timeInterval + dataOut.utctime
515 self.__dataReady = True
545 self.__dataReady = True
516 return avgdata, avgdatatime
546 return avgdata, avgdatatime
517
547
518
548
519 def run(self, dataOut, n=None, timeInterval=None, overlapping=False, byblock=False, **kwargs):
549 def run(self, dataOut, n=None, timeInterval=None, overlapping=False, byblock=False, **kwargs):
520 if not self.isConfig:
550 if not self.isConfig:
521 self.setup(n=n, timeInterval=timeInterval, overlapping=overlapping, byblock=byblock, **kwargs)
551 self.setup(n=n, timeInterval=timeInterval, overlapping=overlapping, byblock=byblock, **kwargs)
522 self.isConfig = True
552 self.isConfig = True
523
553
524 if dataOut.flagDataAsBlock:
554 if dataOut.flagDataAsBlock:
525 """
555 """
526 Si la data es leida por bloques, dimension = [nChannels, nProfiles, nHeis]
556 Si la data es leida por bloques, dimension = [nChannels, nProfiles, nHeis]
527 """
557 """
528 avgdata, avgdatatime = self.integrateByBlock(dataOut)
558 avgdata, avgdatatime = self.integrateByBlock(dataOut)
529 dataOut.nProfiles /= self.n
559 dataOut.nProfiles /= self.n
530 else:
560 else:
531 avgdata, avgdatatime = self.integrate(dataOut.data, dataOut.utctime)
561 avgdata, avgdatatime = self.integrate(dataOut.data, dataOut.utctime)
532
562
533 # dataOut.timeInterval *= n
563 # dataOut.timeInterval *= n
534 dataOut.flagNoData = True
564 dataOut.flagNoData = True
535
565
536 if self.__dataReady:
566 if self.__dataReady:
537 dataOut.data = avgdata
567 dataOut.data = avgdata
538 dataOut.nCohInt *= self.n
568 dataOut.nCohInt *= self.n
539 dataOut.utctime = avgdatatime
569 dataOut.utctime = avgdatatime
540 # dataOut.timeInterval = dataOut.ippSeconds * dataOut.nCohInt
570 # dataOut.timeInterval = dataOut.ippSeconds * dataOut.nCohInt
541 dataOut.flagNoData = False
571 dataOut.flagNoData = False
542
572
543 class Decoder(Operation):
573 class Decoder(Operation):
544
574
545 isConfig = False
575 isConfig = False
546 __profIndex = 0
576 __profIndex = 0
547
577
548 code = None
578 code = None
549
579
550 nCode = None
580 nCode = None
551 nBaud = None
581 nBaud = None
552
582
583 parameters = {
584 'code': global_type_list,
585 'nCode': global_type_integer,
586 'nBaud': global_type_integer,
587 'mode': global_type_integer,
588 'osamp': global_type_float,
589 }
553
590
554 def __init__(self, **kwargs):
591 def __init__(self, **kwargs):
555
592
556 Operation.__init__(self, **kwargs)
593 Operation.__init__(self, **kwargs)
557
594
558 self.times = None
595 self.times = None
559 self.osamp = None
596 self.osamp = None
560 # self.__setValues = False
597 # self.__setValues = False
561 self.isConfig = False
598 self.isConfig = False
562
599
563 def setup(self, code, osamp, dataOut):
600 def setup(self, code, osamp, dataOut):
564
601
565 self.__profIndex = 0
602 self.__profIndex = 0
566
603
567 self.code = code
604 self.code = code
568
605
569 self.nCode = len(code)
606 self.nCode = len(code)
570 self.nBaud = len(code[0])
607 self.nBaud = len(code[0])
571
608
572 if (osamp != None) and (osamp >1):
609 if (osamp != None) and (osamp >1):
573 self.osamp = osamp
610 self.osamp = osamp
574 self.code = numpy.repeat(code, repeats=self.osamp, axis=1)
611 self.code = numpy.repeat(code, repeats=self.osamp, axis=1)
575 self.nBaud = self.nBaud*self.osamp
612 self.nBaud = self.nBaud*self.osamp
576
613
577 self.__nChannels = dataOut.nChannels
614 self.__nChannels = dataOut.nChannels
578 self.__nProfiles = dataOut.nProfiles
615 self.__nProfiles = dataOut.nProfiles
579 self.__nHeis = dataOut.nHeights
616 self.__nHeis = dataOut.nHeights
580
617
581 if self.__nHeis < self.nBaud:
618 if self.__nHeis < self.nBaud:
582 raise ValueError, 'Number of heights (%d) should be greater than number of bauds (%d)' %(self.__nHeis, self.nBaud)
619 raise ValueError, 'Number of heights (%d) should be greater than number of bauds (%d)' %(self.__nHeis, self.nBaud)
583
620
584 #Frequency
621 #Frequency
585 __codeBuffer = numpy.zeros((self.nCode, self.__nHeis), dtype=numpy.complex)
622 __codeBuffer = numpy.zeros((self.nCode, self.__nHeis), dtype=numpy.complex)
586
623
587 __codeBuffer[:,0:self.nBaud] = self.code
624 __codeBuffer[:,0:self.nBaud] = self.code
588
625
589 self.fft_code = numpy.conj(numpy.fft.fft(__codeBuffer, axis=1))
626 self.fft_code = numpy.conj(numpy.fft.fft(__codeBuffer, axis=1))
590
627
591 if dataOut.flagDataAsBlock:
628 if dataOut.flagDataAsBlock:
592
629
593 self.ndatadec = self.__nHeis #- self.nBaud + 1
630 self.ndatadec = self.__nHeis #- self.nBaud + 1
594
631
595 self.datadecTime = numpy.zeros((self.__nChannels, self.__nProfiles, self.ndatadec), dtype=numpy.complex)
632 self.datadecTime = numpy.zeros((self.__nChannels, self.__nProfiles, self.ndatadec), dtype=numpy.complex)
596
633
597 else:
634 else:
598
635
599 #Time
636 #Time
600 self.ndatadec = self.__nHeis #- self.nBaud + 1
637 self.ndatadec = self.__nHeis #- self.nBaud + 1
601
638
602 self.datadecTime = numpy.zeros((self.__nChannels, self.ndatadec), dtype=numpy.complex)
639 self.datadecTime = numpy.zeros((self.__nChannels, self.ndatadec), dtype=numpy.complex)
603
640
604 def __convolutionInFreq(self, data):
641 def __convolutionInFreq(self, data):
605
642
606 fft_code = self.fft_code[self.__profIndex].reshape(1,-1)
643 fft_code = self.fft_code[self.__profIndex].reshape(1,-1)
607
644
608 fft_data = numpy.fft.fft(data, axis=1)
645 fft_data = numpy.fft.fft(data, axis=1)
609
646
610 conv = fft_data*fft_code
647 conv = fft_data*fft_code
611
648
612 data = numpy.fft.ifft(conv,axis=1)
649 data = numpy.fft.ifft(conv,axis=1)
613
650
614 return data
651 return data
615
652
616 def __convolutionInFreqOpt(self, data):
653 def __convolutionInFreqOpt(self, data):
617
654
618 raise NotImplementedError
655 raise NotImplementedError
619
656
620 def __convolutionInTime(self, data):
657 def __convolutionInTime(self, data):
621
658
622 code = self.code[self.__profIndex]
659 code = self.code[self.__profIndex]
623
660
624 for i in range(self.__nChannels):
661 for i in range(self.__nChannels):
625 self.datadecTime[i,:] = numpy.correlate(data[i,:], code, mode='full')[self.nBaud-1:]
662 self.datadecTime[i,:] = numpy.correlate(data[i,:], code, mode='full')[self.nBaud-1:]
626
663
627 return self.datadecTime
664 return self.datadecTime
628
665
629 #@profile
666 #@profile
630 def oldCorrelate(self, i, data, code_block):
667 def oldCorrelate(self, i, data, code_block):
631 profilesList = xrange(self.__nProfiles)
668 profilesList = xrange(self.__nProfiles)
632 for j in profilesList:
669 for j in profilesList:
633 self.datadecTime[i,j,:] = numpy.correlate(data[i,j,:], code_block[j,:], mode='full')[self.nBaud-1:]
670 self.datadecTime[i,j,:] = numpy.correlate(data[i,j,:], code_block[j,:], mode='full')[self.nBaud-1:]
634
671
635 #@profile
672 #@profile
636 def __convolutionByBlockInTime(self, data):
673 def __convolutionByBlockInTime(self, data):
637
674
638 repetitions = self.__nProfiles / self.nCode
675 repetitions = self.__nProfiles / self.nCode
639
676
640 junk = numpy.lib.stride_tricks.as_strided(self.code, (repetitions, self.code.size), (0, self.code.itemsize))
677 junk = numpy.lib.stride_tricks.as_strided(self.code, (repetitions, self.code.size), (0, self.code.itemsize))
641 junk = junk.flatten()
678 junk = junk.flatten()
642 code_block = numpy.reshape(junk, (self.nCode*repetitions, self.nBaud))
679 code_block = numpy.reshape(junk, (self.nCode*repetitions, self.nBaud))
643 profilesList = xrange(self.__nProfiles)
680 profilesList = xrange(self.__nProfiles)
644
681
645 # def toVectorize(a,b):
682 # def toVectorize(a,b):
646 # return numpy.correlate(a,b, mode='full')
683 # return numpy.correlate(a,b, mode='full')
647 # vectorized = numpy.vectorize(toVectorize, signature='(n),(m)->(k)')
684 # vectorized = numpy.vectorize(toVectorize, signature='(n),(m)->(k)')
648 for i in range(self.__nChannels):
685 for i in range(self.__nChannels):
649 # self.datadecTime[i,:,:] = numpy.array([numpy.correlate(data[i,j,:], code_block[j,:], mode='full')[self.nBaud-1:] for j in profilesList ])
686 # self.datadecTime[i,:,:] = numpy.array([numpy.correlate(data[i,j,:], code_block[j,:], mode='full')[self.nBaud-1:] for j in profilesList ])
650 # def func(i, j):
687 # def func(i, j):
651 # self.datadecTime[i,j,:] = numpy.correlate(data[i,j,:], code_block[j,:], mode='full')[self.nBaud-1:]
688 # self.datadecTime[i,j,:] = numpy.correlate(data[i,j,:], code_block[j,:], mode='full')[self.nBaud-1:]
652 # map(lambda j: func(i, j), range(self.__nProfiles))
689 # map(lambda j: func(i, j), range(self.__nProfiles))
653 #print data[i,:,:].shape
690 #print data[i,:,:].shape
654 # self.datadecTime[i,:,:] = vectorized(data[i,:,:], code_block[:,:])[:,self.nBaud-1:]
691 # self.datadecTime[i,:,:] = vectorized(data[i,:,:], code_block[:,:])[:,self.nBaud-1:]
655 for j in profilesList:
692 for j in profilesList:
656 self.datadecTime[i,j,:] = numpy.correlate(data[i,j,:], code_block[j,:], mode='full')[self.nBaud-1:]
693 self.datadecTime[i,j,:] = numpy.correlate(data[i,j,:], code_block[j,:], mode='full')[self.nBaud-1:]
657 # print data[i,:,:]
694 # print data[i,:,:]
658 # print cSchain.correlateByBlock(data[i,:,:], code_block, 2)
695 # print cSchain.correlateByBlock(data[i,:,:], code_block, 2)
659 # self.datadecTime[i,:,:] = cSchain.correlateByBlock(data[i,:,:], code_block, 2)
696 # self.datadecTime[i,:,:] = cSchain.correlateByBlock(data[i,:,:], code_block, 2)
660 # print self.datadecTime[i,:,:]
697 # print self.datadecTime[i,:,:]
661 #print self.datadecTime[i,:,:].shape
698 #print self.datadecTime[i,:,:].shape
662 return self.datadecTime
699 return self.datadecTime
663
700
664
701
665 def __convolutionByBlockInFreq(self, data):
702 def __convolutionByBlockInFreq(self, data):
666
703
667 raise NotImplementedError, "Decoder by frequency fro Blocks not implemented"
704 raise NotImplementedError, "Decoder by frequency fro Blocks not implemented"
668
705
669
706
670 fft_code = self.fft_code[self.__profIndex].reshape(1,-1)
707 fft_code = self.fft_code[self.__profIndex].reshape(1,-1)
671
708
672 fft_data = numpy.fft.fft(data, axis=2)
709 fft_data = numpy.fft.fft(data, axis=2)
673
710
674 conv = fft_data*fft_code
711 conv = fft_data*fft_code
675
712
676 data = numpy.fft.ifft(conv,axis=2)
713 data = numpy.fft.ifft(conv,axis=2)
677
714
678 return data
715 return data
679
716
680
717
681 def run(self, dataOut, code=None, nCode=None, nBaud=None, mode = 0, osamp=None, times=None):
718 def run(self, dataOut, code=None, nCode=None, nBaud=None, mode = 0, osamp=None, times=None):
682
719
683 if dataOut.flagDecodeData:
720 if dataOut.flagDecodeData:
684 print "This data is already decoded, recoding again ..."
721 print "This data is already decoded, recoding again ..."
685
722
686 if not self.isConfig:
723 if not self.isConfig:
687
724
688 if code is None:
725 if code is None:
689 if dataOut.code is None:
726 if dataOut.code is None:
690 raise ValueError, "Code could not be read from %s instance. Enter a value in Code parameter" %dataOut.type
727 raise ValueError, "Code could not be read from %s instance. Enter a value in Code parameter" %dataOut.type
691
728
692 code = dataOut.code
729 code = dataOut.code
693 else:
730 else:
694 code = numpy.array(code).reshape(nCode,nBaud)
731 code = numpy.array(code).reshape(nCode,nBaud)
695
732
696 self.setup(code, osamp, dataOut)
733 self.setup(code, osamp, dataOut)
697
734
698 self.isConfig = True
735 self.isConfig = True
699
736
700 if mode == 3:
737 if mode == 3:
701 sys.stderr.write("Decoder Warning: mode=%d is not valid, using mode=0\n" %mode)
738 sys.stderr.write("Decoder Warning: mode=%d is not valid, using mode=0\n" %mode)
702
739
703 if times != None:
740 if times != None:
704 sys.stderr.write("Decoder Warning: Argument 'times' in not used anymore\n")
741 sys.stderr.write("Decoder Warning: Argument 'times' in not used anymore\n")
705
742
706 if self.code is None:
743 if self.code is None:
707 print "Fail decoding: Code is not defined."
744 print "Fail decoding: Code is not defined."
708 return
745 return
709
746
710 self.__nProfiles = dataOut.nProfiles
747 self.__nProfiles = dataOut.nProfiles
711 datadec = None
748 datadec = None
712
749
713 if mode == 3:
750 if mode == 3:
714 mode = 0
751 mode = 0
715
752
716 if dataOut.flagDataAsBlock:
753 if dataOut.flagDataAsBlock:
717 """
754 """
718 Decoding when data have been read as block,
755 Decoding when data have been read as block,
719 """
756 """
720
757
721 if mode == 0:
758 if mode == 0:
722 datadec = self.__convolutionByBlockInTime(dataOut.data)
759 datadec = self.__convolutionByBlockInTime(dataOut.data)
723 if mode == 1:
760 if mode == 1:
724 datadec = self.__convolutionByBlockInFreq(dataOut.data)
761 datadec = self.__convolutionByBlockInFreq(dataOut.data)
725 else:
762 else:
726 """
763 """
727 Decoding when data have been read profile by profile
764 Decoding when data have been read profile by profile
728 """
765 """
729 if mode == 0:
766 if mode == 0:
730 datadec = self.__convolutionInTime(dataOut.data)
767 datadec = self.__convolutionInTime(dataOut.data)
731
768
732 if mode == 1:
769 if mode == 1:
733 datadec = self.__convolutionInFreq(dataOut.data)
770 datadec = self.__convolutionInFreq(dataOut.data)
734
771
735 if mode == 2:
772 if mode == 2:
736 datadec = self.__convolutionInFreqOpt(dataOut.data)
773 datadec = self.__convolutionInFreqOpt(dataOut.data)
737
774
738 if datadec is None:
775 if datadec is None:
739 raise ValueError, "Codification mode selected is not valid: mode=%d. Try selecting 0 or 1" %mode
776 raise ValueError, "Codification mode selected is not valid: mode=%d. Try selecting 0 or 1" %mode
740
777
741 dataOut.code = self.code
778 dataOut.code = self.code
742 dataOut.nCode = self.nCode
779 dataOut.nCode = self.nCode
743 dataOut.nBaud = self.nBaud
780 dataOut.nBaud = self.nBaud
744
781
745 dataOut.data = datadec
782 dataOut.data = datadec
746
783
747 dataOut.heightList = dataOut.heightList[0:datadec.shape[-1]]
784 dataOut.heightList = dataOut.heightList[0:datadec.shape[-1]]
748
785
749 dataOut.flagDecodeData = True #asumo q la data esta decodificada
786 dataOut.flagDecodeData = True #asumo q la data esta decodificada
750
787
751 if self.__profIndex == self.nCode-1:
788 if self.__profIndex == self.nCode-1:
752 self.__profIndex = 0
789 self.__profIndex = 0
753 return 1
790 return 1
754
791
755 self.__profIndex += 1
792 self.__profIndex += 1
756
793
757 return 1
794 return 1
758 # dataOut.flagDeflipData = True #asumo q la data no esta sin flip
795 # dataOut.flagDeflipData = True #asumo q la data no esta sin flip
759
796
760
797
761 class ProfileConcat(Operation):
798 class ProfileConcat(Operation):
762
799
763 isConfig = False
800 isConfig = False
764 buffer = None
801 buffer = None
765
802
766 def __init__(self, **kwargs):
803 def __init__(self, **kwargs):
767
804
768 Operation.__init__(self, **kwargs)
805 Operation.__init__(self, **kwargs)
769 self.profileIndex = 0
806 self.profileIndex = 0
770
807
771 def reset(self):
808 def reset(self):
772 self.buffer = numpy.zeros_like(self.buffer)
809 self.buffer = numpy.zeros_like(self.buffer)
773 self.start_index = 0
810 self.start_index = 0
774 self.times = 1
811 self.times = 1
775
812
776 def setup(self, data, m, n=1):
813 def setup(self, data, m, n=1):
777 self.buffer = numpy.zeros((data.shape[0],data.shape[1]*m),dtype=type(data[0,0]))
814 self.buffer = numpy.zeros((data.shape[0],data.shape[1]*m),dtype=type(data[0,0]))
778 self.nHeights = data.shape[1]#.nHeights
815 self.nHeights = data.shape[1]#.nHeights
779 self.start_index = 0
816 self.start_index = 0
780 self.times = 1
817 self.times = 1
781
818
782 def concat(self, data):
819 def concat(self, data):
783
820
784 self.buffer[:,self.start_index:self.nHeights*self.times] = data.copy()
821 self.buffer[:,self.start_index:self.nHeights*self.times] = data.copy()
785 self.start_index = self.start_index + self.nHeights
822 self.start_index = self.start_index + self.nHeights
786
823
787 def run(self, dataOut, m):
824 def run(self, dataOut, m):
788
825
789 dataOut.flagNoData = True
826 dataOut.flagNoData = True
790
827
791 if not self.isConfig:
828 if not self.isConfig:
792 self.setup(dataOut.data, m, 1)
829 self.setup(dataOut.data, m, 1)
793 self.isConfig = True
830 self.isConfig = True
794
831
795 if dataOut.flagDataAsBlock:
832 if dataOut.flagDataAsBlock:
796 raise ValueError, "ProfileConcat can only be used when voltage have been read profile by profile, getBlock = False"
833 raise ValueError, "ProfileConcat can only be used when voltage have been read profile by profile, getBlock = False"
797
834
798 else:
835 else:
799 self.concat(dataOut.data)
836 self.concat(dataOut.data)
800 self.times += 1
837 self.times += 1
801 if self.times > m:
838 if self.times > m:
802 dataOut.data = self.buffer
839 dataOut.data = self.buffer
803 self.reset()
840 self.reset()
804 dataOut.flagNoData = False
841 dataOut.flagNoData = False
805 # se deben actualizar mas propiedades del header y del objeto dataOut, por ejemplo, las alturas
842 # se deben actualizar mas propiedades del header y del objeto dataOut, por ejemplo, las alturas
806 deltaHeight = dataOut.heightList[1] - dataOut.heightList[0]
843 deltaHeight = dataOut.heightList[1] - dataOut.heightList[0]
807 xf = dataOut.heightList[0] + dataOut.nHeights * deltaHeight * m
844 xf = dataOut.heightList[0] + dataOut.nHeights * deltaHeight * m
808 dataOut.heightList = numpy.arange(dataOut.heightList[0], xf, deltaHeight)
845 dataOut.heightList = numpy.arange(dataOut.heightList[0], xf, deltaHeight)
809 dataOut.ippSeconds *= m
846 dataOut.ippSeconds *= m
810
847
811 class ProfileSelector(Operation):
848 class ProfileSelector(Operation):
812
849
813 profileIndex = None
850 profileIndex = None
814 # Tamanho total de los perfiles
851 # Tamanho total de los perfiles
815 nProfiles = None
852 nProfiles = None
816
853
817 def __init__(self, **kwargs):
854 def __init__(self, **kwargs):
818
855
819 Operation.__init__(self, **kwargs)
856 Operation.__init__(self, **kwargs)
820 self.profileIndex = 0
857 self.profileIndex = 0
821
858
822 def incProfileIndex(self):
859 def incProfileIndex(self):
823
860
824 self.profileIndex += 1
861 self.profileIndex += 1
825
862
826 if self.profileIndex >= self.nProfiles:
863 if self.profileIndex >= self.nProfiles:
827 self.profileIndex = 0
864 self.profileIndex = 0
828
865
829 def isThisProfileInRange(self, profileIndex, minIndex, maxIndex):
866 def isThisProfileInRange(self, profileIndex, minIndex, maxIndex):
830
867
831 if profileIndex < minIndex:
868 if profileIndex < minIndex:
832 return False
869 return False
833
870
834 if profileIndex > maxIndex:
871 if profileIndex > maxIndex:
835 return False
872 return False
836
873
837 return True
874 return True
838
875
839 def isThisProfileInList(self, profileIndex, profileList):
876 def isThisProfileInList(self, profileIndex, profileList):
840
877
841 if profileIndex not in profileList:
878 if profileIndex not in profileList:
842 return False
879 return False
843
880
844 return True
881 return True
845
882
846 def run(self, dataOut, profileList=None, profileRangeList=None, beam=None, byblock=False, rangeList = None, nProfiles=None):
883 def run(self, dataOut, profileList=None, profileRangeList=None, beam=None, byblock=False, rangeList = None, nProfiles=None):
847
884
848 """
885 """
849 ProfileSelector:
886 ProfileSelector:
850
887
851 Inputs:
888 Inputs:
852 profileList : Index of profiles selected. Example: profileList = (0,1,2,7,8)
889 profileList : Index of profiles selected. Example: profileList = (0,1,2,7,8)
853
890
854 profileRangeList : Minimum and maximum profile indexes. Example: profileRangeList = (4, 30)
891 profileRangeList : Minimum and maximum profile indexes. Example: profileRangeList = (4, 30)
855
892
856 rangeList : List of profile ranges. Example: rangeList = ((4, 30), (32, 64), (128, 256))
893 rangeList : List of profile ranges. Example: rangeList = ((4, 30), (32, 64), (128, 256))
857
894
858 """
895 """
859
896
860 if rangeList is not None:
897 if rangeList is not None:
861 if type(rangeList[0]) not in (tuple, list):
898 if type(rangeList[0]) not in (tuple, list):
862 rangeList = [rangeList]
899 rangeList = [rangeList]
863
900
864 dataOut.flagNoData = True
901 dataOut.flagNoData = True
865
902
866 if dataOut.flagDataAsBlock:
903 if dataOut.flagDataAsBlock:
867 """
904 """
868 data dimension = [nChannels, nProfiles, nHeis]
905 data dimension = [nChannels, nProfiles, nHeis]
869 """
906 """
870 if profileList != None:
907 if profileList != None:
871 dataOut.data = dataOut.data[:,profileList,:]
908 dataOut.data = dataOut.data[:,profileList,:]
872
909
873 if profileRangeList != None:
910 if profileRangeList != None:
874 minIndex = profileRangeList[0]
911 minIndex = profileRangeList[0]
875 maxIndex = profileRangeList[1]
912 maxIndex = profileRangeList[1]
876 profileList = range(minIndex, maxIndex+1)
913 profileList = range(minIndex, maxIndex+1)
877
914
878 dataOut.data = dataOut.data[:,minIndex:maxIndex+1,:]
915 dataOut.data = dataOut.data[:,minIndex:maxIndex+1,:]
879
916
880 if rangeList != None:
917 if rangeList != None:
881
918
882 profileList = []
919 profileList = []
883
920
884 for thisRange in rangeList:
921 for thisRange in rangeList:
885 minIndex = thisRange[0]
922 minIndex = thisRange[0]
886 maxIndex = thisRange[1]
923 maxIndex = thisRange[1]
887
924
888 profileList.extend(range(minIndex, maxIndex+1))
925 profileList.extend(range(minIndex, maxIndex+1))
889
926
890 dataOut.data = dataOut.data[:,profileList,:]
927 dataOut.data = dataOut.data[:,profileList,:]
891
928
892 dataOut.nProfiles = len(profileList)
929 dataOut.nProfiles = len(profileList)
893 dataOut.profileIndex = dataOut.nProfiles - 1
930 dataOut.profileIndex = dataOut.nProfiles - 1
894 dataOut.flagNoData = False
931 dataOut.flagNoData = False
895
932
896 return True
933 return True
897
934
898 """
935 """
899 data dimension = [nChannels, nHeis]
936 data dimension = [nChannels, nHeis]
900 """
937 """
901
938
902 if profileList != None:
939 if profileList != None:
903
940
904 if self.isThisProfileInList(dataOut.profileIndex, profileList):
941 if self.isThisProfileInList(dataOut.profileIndex, profileList):
905
942
906 self.nProfiles = len(profileList)
943 self.nProfiles = len(profileList)
907 dataOut.nProfiles = self.nProfiles
944 dataOut.nProfiles = self.nProfiles
908 dataOut.profileIndex = self.profileIndex
945 dataOut.profileIndex = self.profileIndex
909 dataOut.flagNoData = False
946 dataOut.flagNoData = False
910
947
911 self.incProfileIndex()
948 self.incProfileIndex()
912 return True
949 return True
913
950
914 if profileRangeList != None:
951 if profileRangeList != None:
915
952
916 minIndex = profileRangeList[0]
953 minIndex = profileRangeList[0]
917 maxIndex = profileRangeList[1]
954 maxIndex = profileRangeList[1]
918
955
919 if self.isThisProfileInRange(dataOut.profileIndex, minIndex, maxIndex):
956 if self.isThisProfileInRange(dataOut.profileIndex, minIndex, maxIndex):
920
957
921 self.nProfiles = maxIndex - minIndex + 1
958 self.nProfiles = maxIndex - minIndex + 1
922 dataOut.nProfiles = self.nProfiles
959 dataOut.nProfiles = self.nProfiles
923 dataOut.profileIndex = self.profileIndex
960 dataOut.profileIndex = self.profileIndex
924 dataOut.flagNoData = False
961 dataOut.flagNoData = False
925
962
926 self.incProfileIndex()
963 self.incProfileIndex()
927 return True
964 return True
928
965
929 if rangeList != None:
966 if rangeList != None:
930
967
931 nProfiles = 0
968 nProfiles = 0
932
969
933 for thisRange in rangeList:
970 for thisRange in rangeList:
934 minIndex = thisRange[0]
971 minIndex = thisRange[0]
935 maxIndex = thisRange[1]
972 maxIndex = thisRange[1]
936
973
937 nProfiles += maxIndex - minIndex + 1
974 nProfiles += maxIndex - minIndex + 1
938
975
939 for thisRange in rangeList:
976 for thisRange in rangeList:
940
977
941 minIndex = thisRange[0]
978 minIndex = thisRange[0]
942 maxIndex = thisRange[1]
979 maxIndex = thisRange[1]
943
980
944 if self.isThisProfileInRange(dataOut.profileIndex, minIndex, maxIndex):
981 if self.isThisProfileInRange(dataOut.profileIndex, minIndex, maxIndex):
945
982
946 self.nProfiles = nProfiles
983 self.nProfiles = nProfiles
947 dataOut.nProfiles = self.nProfiles
984 dataOut.nProfiles = self.nProfiles
948 dataOut.profileIndex = self.profileIndex
985 dataOut.profileIndex = self.profileIndex
949 dataOut.flagNoData = False
986 dataOut.flagNoData = False
950
987
951 self.incProfileIndex()
988 self.incProfileIndex()
952
989
953 break
990 break
954
991
955 return True
992 return True
956
993
957
994
958 if beam != None: #beam is only for AMISR data
995 if beam != None: #beam is only for AMISR data
959 if self.isThisProfileInList(dataOut.profileIndex, dataOut.beamRangeDict[beam]):
996 if self.isThisProfileInList(dataOut.profileIndex, dataOut.beamRangeDict[beam]):
960 dataOut.flagNoData = False
997 dataOut.flagNoData = False
961 dataOut.profileIndex = self.profileIndex
998 dataOut.profileIndex = self.profileIndex
962
999
963 self.incProfileIndex()
1000 self.incProfileIndex()
964
1001
965 return True
1002 return True
966
1003
967 raise ValueError, "ProfileSelector needs profileList, profileRangeList or rangeList parameter"
1004 raise ValueError, "ProfileSelector needs profileList, profileRangeList or rangeList parameter"
968
1005
969 return False
1006 return False
970
1007
971 class Reshaper(Operation):
1008 class Reshaper(Operation):
972
1009
973 def __init__(self, **kwargs):
1010 def __init__(self, **kwargs):
974
1011
975 Operation.__init__(self, **kwargs)
1012 Operation.__init__(self, **kwargs)
976
1013
977 self.__buffer = None
1014 self.__buffer = None
978 self.__nitems = 0
1015 self.__nitems = 0
979
1016
980 def __appendProfile(self, dataOut, nTxs):
1017 def __appendProfile(self, dataOut, nTxs):
981
1018
982 if self.__buffer is None:
1019 if self.__buffer is None:
983 shape = (dataOut.nChannels, int(dataOut.nHeights/nTxs) )
1020 shape = (dataOut.nChannels, int(dataOut.nHeights/nTxs) )
984 self.__buffer = numpy.empty(shape, dtype = dataOut.data.dtype)
1021 self.__buffer = numpy.empty(shape, dtype = dataOut.data.dtype)
985
1022
986 ini = dataOut.nHeights * self.__nitems
1023 ini = dataOut.nHeights * self.__nitems
987 end = ini + dataOut.nHeights
1024 end = ini + dataOut.nHeights
988
1025
989 self.__buffer[:, ini:end] = dataOut.data
1026 self.__buffer[:, ini:end] = dataOut.data
990
1027
991 self.__nitems += 1
1028 self.__nitems += 1
992
1029
993 return int(self.__nitems*nTxs)
1030 return int(self.__nitems*nTxs)
994
1031
995 def __getBuffer(self):
1032 def __getBuffer(self):
996
1033
997 if self.__nitems == int(1./self.__nTxs):
1034 if self.__nitems == int(1./self.__nTxs):
998
1035
999 self.__nitems = 0
1036 self.__nitems = 0
1000
1037
1001 return self.__buffer.copy()
1038 return self.__buffer.copy()
1002
1039
1003 return None
1040 return None
1004
1041
1005 def __checkInputs(self, dataOut, shape, nTxs):
1042 def __checkInputs(self, dataOut, shape, nTxs):
1006
1043
1007 if shape is None and nTxs is None:
1044 if shape is None and nTxs is None:
1008 raise ValueError, "Reshaper: shape of factor should be defined"
1045 raise ValueError, "Reshaper: shape of factor should be defined"
1009
1046
1010 if nTxs:
1047 if nTxs:
1011 if nTxs < 0:
1048 if nTxs < 0:
1012 raise ValueError, "nTxs should be greater than 0"
1049 raise ValueError, "nTxs should be greater than 0"
1013
1050
1014 if nTxs < 1 and dataOut.nProfiles % (1./nTxs) != 0:
1051 if nTxs < 1 and dataOut.nProfiles % (1./nTxs) != 0:
1015 raise ValueError, "nProfiles= %d is not divisibled by (1./nTxs) = %f" %(dataOut.nProfiles, (1./nTxs))
1052 raise ValueError, "nProfiles= %d is not divisibled by (1./nTxs) = %f" %(dataOut.nProfiles, (1./nTxs))
1016
1053
1017 shape = [dataOut.nChannels, dataOut.nProfiles*nTxs, dataOut.nHeights/nTxs]
1054 shape = [dataOut.nChannels, dataOut.nProfiles*nTxs, dataOut.nHeights/nTxs]
1018
1055
1019 return shape, nTxs
1056 return shape, nTxs
1020
1057
1021 if len(shape) != 2 and len(shape) != 3:
1058 if len(shape) != 2 and len(shape) != 3:
1022 raise ValueError, "shape dimension should be equal to 2 or 3. shape = (nProfiles, nHeis) or (nChannels, nProfiles, nHeis). Actually shape = (%d, %d, %d)" %(dataOut.nChannels, dataOut.nProfiles, dataOut.nHeights)
1059 raise ValueError, "shape dimension should be equal to 2 or 3. shape = (nProfiles, nHeis) or (nChannels, nProfiles, nHeis). Actually shape = (%d, %d, %d)" %(dataOut.nChannels, dataOut.nProfiles, dataOut.nHeights)
1023
1060
1024 if len(shape) == 2:
1061 if len(shape) == 2:
1025 shape_tuple = [dataOut.nChannels]
1062 shape_tuple = [dataOut.nChannels]
1026 shape_tuple.extend(shape)
1063 shape_tuple.extend(shape)
1027 else:
1064 else:
1028 shape_tuple = list(shape)
1065 shape_tuple = list(shape)
1029
1066
1030 nTxs = 1.0*shape_tuple[1]/dataOut.nProfiles
1067 nTxs = 1.0*shape_tuple[1]/dataOut.nProfiles
1031
1068
1032 return shape_tuple, nTxs
1069 return shape_tuple, nTxs
1033
1070
1034 def run(self, dataOut, shape=None, nTxs=None):
1071 def run(self, dataOut, shape=None, nTxs=None):
1035
1072
1036 shape_tuple, self.__nTxs = self.__checkInputs(dataOut, shape, nTxs)
1073 shape_tuple, self.__nTxs = self.__checkInputs(dataOut, shape, nTxs)
1037
1074
1038 dataOut.flagNoData = True
1075 dataOut.flagNoData = True
1039 profileIndex = None
1076 profileIndex = None
1040
1077
1041 if dataOut.flagDataAsBlock:
1078 if dataOut.flagDataAsBlock:
1042
1079
1043 dataOut.data = numpy.reshape(dataOut.data, shape_tuple)
1080 dataOut.data = numpy.reshape(dataOut.data, shape_tuple)
1044 dataOut.flagNoData = False
1081 dataOut.flagNoData = False
1045
1082
1046 profileIndex = int(dataOut.nProfiles*self.__nTxs) - 1
1083 profileIndex = int(dataOut.nProfiles*self.__nTxs) - 1
1047
1084
1048 else:
1085 else:
1049
1086
1050 if self.__nTxs < 1:
1087 if self.__nTxs < 1:
1051
1088
1052 self.__appendProfile(dataOut, self.__nTxs)
1089 self.__appendProfile(dataOut, self.__nTxs)
1053 new_data = self.__getBuffer()
1090 new_data = self.__getBuffer()
1054
1091
1055 if new_data is not None:
1092 if new_data is not None:
1056 dataOut.data = new_data
1093 dataOut.data = new_data
1057 dataOut.flagNoData = False
1094 dataOut.flagNoData = False
1058
1095
1059 profileIndex = dataOut.profileIndex*nTxs
1096 profileIndex = dataOut.profileIndex*nTxs
1060
1097
1061 else:
1098 else:
1062 raise ValueError, "nTxs should be greater than 0 and lower than 1, or use VoltageReader(..., getblock=True)"
1099 raise ValueError, "nTxs should be greater than 0 and lower than 1, or use VoltageReader(..., getblock=True)"
1063
1100
1064 deltaHeight = dataOut.heightList[1] - dataOut.heightList[0]
1101 deltaHeight = dataOut.heightList[1] - dataOut.heightList[0]
1065
1102
1066 dataOut.heightList = numpy.arange(dataOut.nHeights/self.__nTxs) * deltaHeight + dataOut.heightList[0]
1103 dataOut.heightList = numpy.arange(dataOut.nHeights/self.__nTxs) * deltaHeight + dataOut.heightList[0]
1067
1104
1068 dataOut.nProfiles = int(dataOut.nProfiles*self.__nTxs)
1105 dataOut.nProfiles = int(dataOut.nProfiles*self.__nTxs)
1069
1106
1070 dataOut.profileIndex = profileIndex
1107 dataOut.profileIndex = profileIndex
1071
1108
1072 dataOut.ippSeconds /= self.__nTxs
1109 dataOut.ippSeconds /= self.__nTxs
1073
1110
1074 class SplitProfiles(Operation):
1111 class SplitProfiles(Operation):
1075
1112
1076 def __init__(self, **kwargs):
1113 def __init__(self, **kwargs):
1077
1114
1078 Operation.__init__(self, **kwargs)
1115 Operation.__init__(self, **kwargs)
1079
1116
1080 def run(self, dataOut, n):
1117 def run(self, dataOut, n):
1081
1118
1082 dataOut.flagNoData = True
1119 dataOut.flagNoData = True
1083 profileIndex = None
1120 profileIndex = None
1084
1121
1085 if dataOut.flagDataAsBlock:
1122 if dataOut.flagDataAsBlock:
1086
1123
1087 #nchannels, nprofiles, nsamples
1124 #nchannels, nprofiles, nsamples
1088 shape = dataOut.data.shape
1125 shape = dataOut.data.shape
1089
1126
1090 if shape[2] % n != 0:
1127 if shape[2] % n != 0:
1091 raise ValueError, "Could not split the data, n=%d has to be multiple of %d" %(n, shape[2])
1128 raise ValueError, "Could not split the data, n=%d has to be multiple of %d" %(n, shape[2])
1092
1129
1093 new_shape = shape[0], shape[1]*n, shape[2]/n
1130 new_shape = shape[0], shape[1]*n, shape[2]/n
1094
1131
1095 dataOut.data = numpy.reshape(dataOut.data, new_shape)
1132 dataOut.data = numpy.reshape(dataOut.data, new_shape)
1096 dataOut.flagNoData = False
1133 dataOut.flagNoData = False
1097
1134
1098 profileIndex = int(dataOut.nProfiles/n) - 1
1135 profileIndex = int(dataOut.nProfiles/n) - 1
1099
1136
1100 else:
1137 else:
1101
1138
1102 raise ValueError, "Could not split the data when is read Profile by Profile. Use VoltageReader(..., getblock=True)"
1139 raise ValueError, "Could not split the data when is read Profile by Profile. Use VoltageReader(..., getblock=True)"
1103
1140
1104 deltaHeight = dataOut.heightList[1] - dataOut.heightList[0]
1141 deltaHeight = dataOut.heightList[1] - dataOut.heightList[0]
1105
1142
1106 dataOut.heightList = numpy.arange(dataOut.nHeights/n) * deltaHeight + dataOut.heightList[0]
1143 dataOut.heightList = numpy.arange(dataOut.nHeights/n) * deltaHeight + dataOut.heightList[0]
1107
1144
1108 dataOut.nProfiles = int(dataOut.nProfiles*n)
1145 dataOut.nProfiles = int(dataOut.nProfiles*n)
1109
1146
1110 dataOut.profileIndex = profileIndex
1147 dataOut.profileIndex = profileIndex
1111
1148
1112 dataOut.ippSeconds /= n
1149 dataOut.ippSeconds /= n
1113
1150
1114 class CombineProfiles(Operation):
1151 class CombineProfiles(Operation):
1115
1152 parameters = {
1153 'n': global_type_integer,
1154 }
1116 def __init__(self, **kwargs):
1155 def __init__(self, **kwargs):
1117
1156
1118 Operation.__init__(self, **kwargs)
1157 Operation.__init__(self, **kwargs)
1119
1158
1120 self.__remData = None
1159 self.__remData = None
1121 self.__profileIndex = 0
1160 self.__profileIndex = 0
1122
1161
1123 def run(self, dataOut, n):
1162 def run(self, dataOut, n):
1124
1163
1125 dataOut.flagNoData = True
1164 dataOut.flagNoData = True
1126 profileIndex = None
1165 profileIndex = None
1127
1166
1128 if dataOut.flagDataAsBlock:
1167 if dataOut.flagDataAsBlock:
1129
1168
1130 #nchannels, nprofiles, nsamples
1169 #nchannels, nprofiles, nsamples
1131 shape = dataOut.data.shape
1170 shape = dataOut.data.shape
1132 new_shape = shape[0], shape[1]/n, shape[2]*n
1171 new_shape = shape[0], shape[1]/n, shape[2]*n
1133
1172
1134 if shape[1] % n != 0:
1173 if shape[1] % n != 0:
1135 raise ValueError, "Could not split the data, n=%d has to be multiple of %d" %(n, shape[1])
1174 raise ValueError, "Could not split the data, n=%d has to be multiple of %d" %(n, shape[1])
1136
1175
1137 dataOut.data = numpy.reshape(dataOut.data, new_shape)
1176 dataOut.data = numpy.reshape(dataOut.data, new_shape)
1138 dataOut.flagNoData = False
1177 dataOut.flagNoData = False
1139
1178
1140 profileIndex = int(dataOut.nProfiles*n) - 1
1179 profileIndex = int(dataOut.nProfiles*n) - 1
1141
1180
1142 else:
1181 else:
1143
1182
1144 #nchannels, nsamples
1183 #nchannels, nsamples
1145 if self.__remData is None:
1184 if self.__remData is None:
1146 newData = dataOut.data
1185 newData = dataOut.data
1147 else:
1186 else:
1148 newData = numpy.concatenate((self.__remData, dataOut.data), axis=1)
1187 newData = numpy.concatenate((self.__remData, dataOut.data), axis=1)
1149
1188
1150 self.__profileIndex += 1
1189 self.__profileIndex += 1
1151
1190
1152 if self.__profileIndex < n:
1191 if self.__profileIndex < n:
1153 self.__remData = newData
1192 self.__remData = newData
1154 #continue
1193 #continue
1155 return
1194 return
1156
1195
1157 self.__profileIndex = 0
1196 self.__profileIndex = 0
1158 self.__remData = None
1197 self.__remData = None
1159
1198
1160 dataOut.data = newData
1199 dataOut.data = newData
1161 dataOut.flagNoData = False
1200 dataOut.flagNoData = False
1162
1201
1163 profileIndex = dataOut.profileIndex/n
1202 profileIndex = dataOut.profileIndex/n
1164
1203
1165
1204
1166 deltaHeight = dataOut.heightList[1] - dataOut.heightList[0]
1205 deltaHeight = dataOut.heightList[1] - dataOut.heightList[0]
1167
1206
1168 dataOut.heightList = numpy.arange(dataOut.nHeights*n) * deltaHeight + dataOut.heightList[0]
1207 dataOut.heightList = numpy.arange(dataOut.nHeights*n) * deltaHeight + dataOut.heightList[0]
1169
1208
1170 dataOut.nProfiles = int(dataOut.nProfiles/n)
1209 dataOut.nProfiles = int(dataOut.nProfiles/n)
1171
1210
1172 dataOut.profileIndex = profileIndex
1211 dataOut.profileIndex = profileIndex
1173
1212
1174 dataOut.ippSeconds *= n
1213 dataOut.ippSeconds *= n
1175
1214
1176 # import collections
1215 # import collections
1177 # from scipy.stats import mode
1216 # from scipy.stats import mode
1178 #
1217 #
1179 # class Synchronize(Operation):
1218 # class Synchronize(Operation):
1180 #
1219 #
1181 # isConfig = False
1220 # isConfig = False
1182 # __profIndex = 0
1221 # __profIndex = 0
1183 #
1222 #
1184 # def __init__(self, **kwargs):
1223 # def __init__(self, **kwargs):
1185 #
1224 #
1186 # Operation.__init__(self, **kwargs)
1225 # Operation.__init__(self, **kwargs)
1187 # # self.isConfig = False
1226 # # self.isConfig = False
1188 # self.__powBuffer = None
1227 # self.__powBuffer = None
1189 # self.__startIndex = 0
1228 # self.__startIndex = 0
1190 # self.__pulseFound = False
1229 # self.__pulseFound = False
1191 #
1230 #
1192 # def __findTxPulse(self, dataOut, channel=0, pulse_with = None):
1231 # def __findTxPulse(self, dataOut, channel=0, pulse_with = None):
1193 #
1232 #
1194 # #Read data
1233 # #Read data
1195 #
1234 #
1196 # powerdB = dataOut.getPower(channel = channel)
1235 # powerdB = dataOut.getPower(channel = channel)
1197 # noisedB = dataOut.getNoise(channel = channel)[0]
1236 # noisedB = dataOut.getNoise(channel = channel)[0]
1198 #
1237 #
1199 # self.__powBuffer.extend(powerdB.flatten())
1238 # self.__powBuffer.extend(powerdB.flatten())
1200 #
1239 #
1201 # dataArray = numpy.array(self.__powBuffer)
1240 # dataArray = numpy.array(self.__powBuffer)
1202 #
1241 #
1203 # filteredPower = numpy.correlate(dataArray, dataArray[0:self.__nSamples], "same")
1242 # filteredPower = numpy.correlate(dataArray, dataArray[0:self.__nSamples], "same")
1204 #
1243 #
1205 # maxValue = numpy.nanmax(filteredPower)
1244 # maxValue = numpy.nanmax(filteredPower)
1206 #
1245 #
1207 # if maxValue < noisedB + 10:
1246 # if maxValue < noisedB + 10:
1208 # #No se encuentra ningun pulso de transmision
1247 # #No se encuentra ningun pulso de transmision
1209 # return None
1248 # return None
1210 #
1249 #
1211 # maxValuesIndex = numpy.where(filteredPower > maxValue - 0.1*abs(maxValue))[0]
1250 # maxValuesIndex = numpy.where(filteredPower > maxValue - 0.1*abs(maxValue))[0]
1212 #
1251 #
1213 # if len(maxValuesIndex) < 2:
1252 # if len(maxValuesIndex) < 2:
1214 # #Solo se encontro un solo pulso de transmision de un baudio, esperando por el siguiente TX
1253 # #Solo se encontro un solo pulso de transmision de un baudio, esperando por el siguiente TX
1215 # return None
1254 # return None
1216 #
1255 #
1217 # phasedMaxValuesIndex = maxValuesIndex - self.__nSamples
1256 # phasedMaxValuesIndex = maxValuesIndex - self.__nSamples
1218 #
1257 #
1219 # #Seleccionar solo valores con un espaciamiento de nSamples
1258 # #Seleccionar solo valores con un espaciamiento de nSamples
1220 # pulseIndex = numpy.intersect1d(maxValuesIndex, phasedMaxValuesIndex)
1259 # pulseIndex = numpy.intersect1d(maxValuesIndex, phasedMaxValuesIndex)
1221 #
1260 #
1222 # if len(pulseIndex) < 2:
1261 # if len(pulseIndex) < 2:
1223 # #Solo se encontro un pulso de transmision con ancho mayor a 1
1262 # #Solo se encontro un pulso de transmision con ancho mayor a 1
1224 # return None
1263 # return None
1225 #
1264 #
1226 # spacing = pulseIndex[1:] - pulseIndex[:-1]
1265 # spacing = pulseIndex[1:] - pulseIndex[:-1]
1227 #
1266 #
1228 # #remover senales que se distancien menos de 10 unidades o muestras
1267 # #remover senales que se distancien menos de 10 unidades o muestras
1229 # #(No deberian existir IPP menor a 10 unidades)
1268 # #(No deberian existir IPP menor a 10 unidades)
1230 #
1269 #
1231 # realIndex = numpy.where(spacing > 10 )[0]
1270 # realIndex = numpy.where(spacing > 10 )[0]
1232 #
1271 #
1233 # if len(realIndex) < 2:
1272 # if len(realIndex) < 2:
1234 # #Solo se encontro un pulso de transmision con ancho mayor a 1
1273 # #Solo se encontro un pulso de transmision con ancho mayor a 1
1235 # return None
1274 # return None
1236 #
1275 #
1237 # #Eliminar pulsos anchos (deja solo la diferencia entre IPPs)
1276 # #Eliminar pulsos anchos (deja solo la diferencia entre IPPs)
1238 # realPulseIndex = pulseIndex[realIndex]
1277 # realPulseIndex = pulseIndex[realIndex]
1239 #
1278 #
1240 # period = mode(realPulseIndex[1:] - realPulseIndex[:-1])[0][0]
1279 # period = mode(realPulseIndex[1:] - realPulseIndex[:-1])[0][0]
1241 #
1280 #
1242 # print "IPP = %d samples" %period
1281 # print "IPP = %d samples" %period
1243 #
1282 #
1244 # self.__newNSamples = dataOut.nHeights #int(period)
1283 # self.__newNSamples = dataOut.nHeights #int(period)
1245 # self.__startIndex = int(realPulseIndex[0])
1284 # self.__startIndex = int(realPulseIndex[0])
1246 #
1285 #
1247 # return 1
1286 # return 1
1248 #
1287 #
1249 #
1288 #
1250 # def setup(self, nSamples, nChannels, buffer_size = 4):
1289 # def setup(self, nSamples, nChannels, buffer_size = 4):
1251 #
1290 #
1252 # self.__powBuffer = collections.deque(numpy.zeros( buffer_size*nSamples,dtype=numpy.float),
1291 # self.__powBuffer = collections.deque(numpy.zeros( buffer_size*nSamples,dtype=numpy.float),
1253 # maxlen = buffer_size*nSamples)
1292 # maxlen = buffer_size*nSamples)
1254 #
1293 #
1255 # bufferList = []
1294 # bufferList = []
1256 #
1295 #
1257 # for i in range(nChannels):
1296 # for i in range(nChannels):
1258 # bufferByChannel = collections.deque(numpy.zeros( buffer_size*nSamples, dtype=numpy.complex) + numpy.NAN,
1297 # bufferByChannel = collections.deque(numpy.zeros( buffer_size*nSamples, dtype=numpy.complex) + numpy.NAN,
1259 # maxlen = buffer_size*nSamples)
1298 # maxlen = buffer_size*nSamples)
1260 #
1299 #
1261 # bufferList.append(bufferByChannel)
1300 # bufferList.append(bufferByChannel)
1262 #
1301 #
1263 # self.__nSamples = nSamples
1302 # self.__nSamples = nSamples
1264 # self.__nChannels = nChannels
1303 # self.__nChannels = nChannels
1265 # self.__bufferList = bufferList
1304 # self.__bufferList = bufferList
1266 #
1305 #
1267 # def run(self, dataOut, channel = 0):
1306 # def run(self, dataOut, channel = 0):
1268 #
1307 #
1269 # if not self.isConfig:
1308 # if not self.isConfig:
1270 # nSamples = dataOut.nHeights
1309 # nSamples = dataOut.nHeights
1271 # nChannels = dataOut.nChannels
1310 # nChannels = dataOut.nChannels
1272 # self.setup(nSamples, nChannels)
1311 # self.setup(nSamples, nChannels)
1273 # self.isConfig = True
1312 # self.isConfig = True
1274 #
1313 #
1275 # #Append new data to internal buffer
1314 # #Append new data to internal buffer
1276 # for thisChannel in range(self.__nChannels):
1315 # for thisChannel in range(self.__nChannels):
1277 # bufferByChannel = self.__bufferList[thisChannel]
1316 # bufferByChannel = self.__bufferList[thisChannel]
1278 # bufferByChannel.extend(dataOut.data[thisChannel])
1317 # bufferByChannel.extend(dataOut.data[thisChannel])
1279 #
1318 #
1280 # if self.__pulseFound:
1319 # if self.__pulseFound:
1281 # self.__startIndex -= self.__nSamples
1320 # self.__startIndex -= self.__nSamples
1282 #
1321 #
1283 # #Finding Tx Pulse
1322 # #Finding Tx Pulse
1284 # if not self.__pulseFound:
1323 # if not self.__pulseFound:
1285 # indexFound = self.__findTxPulse(dataOut, channel)
1324 # indexFound = self.__findTxPulse(dataOut, channel)
1286 #
1325 #
1287 # if indexFound == None:
1326 # if indexFound == None:
1288 # dataOut.flagNoData = True
1327 # dataOut.flagNoData = True
1289 # return
1328 # return
1290 #
1329 #
1291 # self.__arrayBuffer = numpy.zeros((self.__nChannels, self.__newNSamples), dtype = numpy.complex)
1330 # self.__arrayBuffer = numpy.zeros((self.__nChannels, self.__newNSamples), dtype = numpy.complex)
1292 # self.__pulseFound = True
1331 # self.__pulseFound = True
1293 # self.__startIndex = indexFound
1332 # self.__startIndex = indexFound
1294 #
1333 #
1295 # #If pulse was found ...
1334 # #If pulse was found ...
1296 # for thisChannel in range(self.__nChannels):
1335 # for thisChannel in range(self.__nChannels):
1297 # bufferByChannel = self.__bufferList[thisChannel]
1336 # bufferByChannel = self.__bufferList[thisChannel]
1298 # #print self.__startIndex
1337 # #print self.__startIndex
1299 # x = numpy.array(bufferByChannel)
1338 # x = numpy.array(bufferByChannel)
1300 # self.__arrayBuffer[thisChannel] = x[self.__startIndex:self.__startIndex+self.__newNSamples]
1339 # self.__arrayBuffer[thisChannel] = x[self.__startIndex:self.__startIndex+self.__newNSamples]
1301 #
1340 #
1302 # deltaHeight = dataOut.heightList[1] - dataOut.heightList[0]
1341 # deltaHeight = dataOut.heightList[1] - dataOut.heightList[0]
1303 # dataOut.heightList = numpy.arange(self.__newNSamples)*deltaHeight
1342 # dataOut.heightList = numpy.arange(self.__newNSamples)*deltaHeight
1304 # # dataOut.ippSeconds = (self.__newNSamples / deltaHeight)/1e6
1343 # # dataOut.ippSeconds = (self.__newNSamples / deltaHeight)/1e6
1305 #
1344 #
1306 # dataOut.data = self.__arrayBuffer
1345 # dataOut.data = self.__arrayBuffer
1307 #
1346 #
1308 # self.__startIndex += self.__newNSamples
1347 # self.__startIndex += self.__newNSamples
1309 #
1348 #
1310 # return
1349 # return
General Comments 0
You need to be logged in to leave comments. Login now