##// END OF EJS Templates
marzo update
avaldez -
r1347:98dd11910247
parent child
Show More
@@ -0,0 +1,37
1 import os,sys
2 import datetime
3 import time
4 from schainpy.controller import Project
5 #path = '/home/alex/Downloads/hdf5_testPP2'
6 #path = '/home/alex/Downloads/hdf5_test'
7 #path='/home/alex/Downloads/hdf5_wr'
8 path='/home/developer/Downloads/HDF5_WR'
9 figpath = path
10 desc = "Simulator Test"
11
12 controllerObj = Project()
13
14 controllerObj.setup(id='10',name='Test Simulator',description=desc)
15
16 readUnitConfObj = controllerObj.addReadUnit(datatype='HDFReader',
17 path=path,
18 startDate="2021/01/01", #"2020/01/01",#today,
19 endDate= "2021/12/01", #"2020/12/30",#today,
20 startTime='00:00:00',
21 endTime='23:59:59',
22 delay=0,
23 #set=0,
24 online=0,
25 walk=0)#1
26
27 procUnitConfObjA = controllerObj.addProcUnit(datatype='ParametersProc',inputId=readUnitConfObj.getId())
28 opObj11 = procUnitConfObjA.addOperation(name='Block360')
29 opObj11.addParameter(name='n', value='10', format='int')
30
31 opObj11= procUnitConfObjA.addOperation(name='WeatherPlot',optype='other')
32 #opObj11.addParameter(name='save', value=figpath)
33 #opObj11.addParameter(name='save_period', value=1)
34 #opObj11 = procUnitConfObjA.addOperation(name='PowerPlot', optype='other')#PulsepairPowerPlot
35 #opObj11 = procUnitConfObjA.addOperation(name='PPSignalPlot', optype='other')
36
37 controllerObj.start()
@@ -5,6 +5,7 import numpy
5 from schainpy.model.graphics.jroplot_base import Plot, plt
5 from schainpy.model.graphics.jroplot_base import Plot, plt
6 from schainpy.model.graphics.jroplot_spectra import SpectraPlot, RTIPlot, CoherencePlot
6 from schainpy.model.graphics.jroplot_spectra import SpectraPlot, RTIPlot, CoherencePlot
7 from schainpy.utils import log
7 from schainpy.utils import log
8 import wradlib as wrl
8
9
9 EARTH_RADIUS = 6.3710e3
10 EARTH_RADIUS = 6.3710e3
10
11
@@ -50,7 +51,7 class SnrPlot(RTIPlot):
50 def update(self, dataOut):
51 def update(self, dataOut):
51
52
52 data = {
53 data = {
53 'snr': 10*numpy.log10(dataOut.data_snr)
54 'snr': 10*numpy.log10(dataOut.data_snr)
54 }
55 }
55
56
56 return data, {}
57 return data, {}
@@ -66,7 +67,7 class DopplerPlot(RTIPlot):
66 def update(self, dataOut):
67 def update(self, dataOut):
67
68
68 data = {
69 data = {
69 'dop': 10*numpy.log10(dataOut.data_dop)
70 'dop': 10*numpy.log10(dataOut.data_dop)
70 }
71 }
71
72
72 return data, {}
73 return data, {}
@@ -82,7 +83,7 class PowerPlot(RTIPlot):
82 def update(self, dataOut):
83 def update(self, dataOut):
83
84
84 data = {
85 data = {
85 'pow': 10*numpy.log10(dataOut.data_pow)
86 'pow': 10*numpy.log10(dataOut.data_pow)
86 }
87 }
87
88
88 return data, {}
89 return data, {}
@@ -166,7 +167,7 class GenericRTIPlot(Plot):
166 self.nrows = self.data.shape(self.attr_data)[0]
167 self.nrows = self.data.shape(self.attr_data)[0]
167 self.nplots = self.nrows
168 self.nplots = self.nrows
168 self.plots_adjust.update({'hspace':0.8, 'left': 0.1, 'bottom': 0.08, 'right':0.95, 'top': 0.95})
169 self.plots_adjust.update({'hspace':0.8, 'left': 0.1, 'bottom': 0.08, 'right':0.95, 'top': 0.95})
169
170
170 if not self.xlabel:
171 if not self.xlabel:
171 self.xlabel = 'Time'
172 self.xlabel = 'Time'
172
173
@@ -184,7 +185,7 class GenericRTIPlot(Plot):
184 meta = {}
185 meta = {}
185
186
186 return data, meta
187 return data, meta
187
188
188 def plot(self):
189 def plot(self):
189 # self.data.normalize_heights()
190 # self.data.normalize_heights()
190 self.x = self.data.times
191 self.x = self.data.times
@@ -356,3 +357,209 class PolarMapPlot(Plot):
356 self.titles = ['{} {}'.format(
357 self.titles = ['{} {}'.format(
357 self.data.parameters[x], title) for x in self.channels]
358 self.data.parameters[x], title) for x in self.channels]
358
359
360 class WeatherPlot(Plot):
361 CODE = 'weather'
362 plot_name = 'weather'
363 plot_type = 'ppistyle'
364 buffering = False
365
366 def setup(self):
367 self.ncols = 1
368 self.nrows = 1
369 self.nplots= 1
370 self.ylabel= 'Range [Km]'
371 self.titles= ['Weather']
372 self.colorbar=False
373 self.width =8
374 self.height =8
375 self.ini =0
376 self.len_azi =0
377 self.buffer_ini = None
378 self.buffer_azi = None
379 self.plots_adjust.update({'wspace': 0.4, 'hspace':0.4, 'left': 0.1, 'right': 0.9, 'bottom': 0.08})
380 self.flag =0
381 self.indicador= 0
382
383 def update(self, dataOut):
384
385 data = {}
386 meta = {}
387 data['weather'] = 10*numpy.log10(dataOut.data_360/(650**2))
388 data['azi'] = dataOut.data_azi
389
390 return data, meta
391
392 def plot(self):
393 stoprange = float(33*1.5)
394 rangestep = float(0.15)
395 r = numpy.arange(0, stoprange, rangestep)
396 self.y = 2*r
397 data = self.data[-1]
398
399 tmp_v = data['weather']
400 tmp_z = data['azi']
401 res = 1
402 step = (360/(res*tmp_v.shape[0]))
403 mode = 1
404 if mode==0:
405 print("self.ini",self.ini)
406 val = numpy.mean(tmp_v[:,0])
407 self.len_azi = len(tmp_z)
408 ones = numpy.ones([(360-tmp_v.shape[0]),tmp_v.shape[1]])*val
409 self.buffer_ini = numpy.vstack((tmp_v,ones))
410
411 n = ((360/res)-len(tmp_z))
412 start = tmp_z[-1]+res
413 end = tmp_z[0]-res
414 if start>end:
415 end = end+360
416 azi_zeros = numpy.linspace(start,end,int(n))
417 azi_zeros = numpy.where(azi_zeros>360,azi_zeros-360,azi_zeros)
418 self.buffer_ini_azi = numpy.hstack((tmp_z,azi_zeros))
419 self.ini = self.ini+1
420
421 if mode==1:
422 print("self.ini",self.ini)
423 if self.ini==0:
424 res = 1
425 step = (360/(res*tmp_v.shape[0]))
426 val = numpy.mean(tmp_v[:,0])
427 self.len_azi = len(tmp_z)
428 self.buf_tmp = tmp_v
429 ones = numpy.ones([(360-tmp_v.shape[0]),tmp_v.shape[1]])*val
430 self.buffer_ini = numpy.vstack((tmp_v,ones))
431
432 n = ((360/res)-len(tmp_z))
433 start = tmp_z[-1]+res
434 end = tmp_z[0]-res
435 if start>end:
436 end =end+360
437 azi_zeros = numpy.linspace(start,end,int(n))
438 azi_zeros = numpy.where(azi_zeros>360,azi_zeros-360,azi_zeros)
439 self.buf_azi = tmp_z
440 self.buffer_ini_azi = numpy.hstack((tmp_z,azi_zeros))
441 self.ini = self.ini+1
442 elif 0<self.ini<step:
443 '''
444 if self.ini>31:
445 start= tmp_z[0]
446 end =tmp_z[-1]
447 print("start","end",start,end)
448 if self.ini==32:
449 tmp_v=tmp_v+20
450 if self.ini==33:
451 tmp_v=tmp_v+10
452 if self.ini==34:
453 tmp_v=tmp_v+20
454 if self.ini==35:
455 tmp_v=tmp_v+20
456 '''
457 self.buf_tmp= numpy.vstack((self.buf_tmp,tmp_v))
458 if self.buf_tmp.shape[0]==360:
459 self.buffer_ini=self.buf_tmp
460 else:
461 val=30.0
462 ones = numpy.ones([(360-self.buf_tmp.shape[0]),self.buf_tmp.shape[1]])*val
463 self.buffer_ini = numpy.vstack((self.buf_tmp,ones))
464
465 self.buf_azi = numpy.hstack((self.buf_azi,tmp_z))
466 n = ((360/res)-len(self.buf_azi))
467 if n==0:
468 self.buffer_ini_azi = self.buf_azi
469 else:
470 start = self.buf_azi[-1]+res
471 end = self.buf_azi[0]-res
472 if start>end:
473 end =end+360
474 azi_zeros = numpy.linspace(start,end,int(n))
475 azi_zeros = numpy.where(azi_zeros>360,azi_zeros-360,azi_zeros)
476 if tmp_z[0]<self.buf_azi[0] <tmp_z[-1]:
477 self.indicador=1
478 if self.indicador==1:
479 azi_zeros = numpy.ones(360-len(self.buf_azi))*(tmp_z[-1]+res)
480 # self.indicador = True
481 #if self.indicador==True:
482 # azi_zeros = numpy.ones(360-len(self.buf_azi))*(tmp_z[-1]+res)
483
484 #self.buf_azi = tmp_z
485 self.buffer_ini_azi = numpy.hstack((self.buf_azi,azi_zeros))
486
487 if self.ini==step-1:
488 start= tmp_z[0]
489 end = tmp_z[-1]
490 print("start","end",start,end)
491 print(self.buffer_ini_azi[:80])
492 self.ini = self.ini+1
493
494 else:
495 step = (360/(res*tmp_v.shape[0]))
496 tmp_v=tmp_v+5+(self.ini-step)*1
497
498 start= tmp_z[0]
499 end = tmp_z[-1]
500 print("start","end",start,end)
501 print(self.buffer_ini_azi[:120])
502
503 if step>=2:
504 if self.flag<step-1:
505 limit_i=self.buf_azi[len(tmp_z)*(self.flag+1)]
506 limit_s=self.buf_azi[len(tmp_z)*(self.flag+2)-1]
507 print("flag",self.flag,limit_i,limit_s)
508 if limit_i< tmp_z[-1]< limit_s:
509 index_i=int(numpy.where(tmp_z<=self.buf_azi[len(tmp_z)*(self.flag+1)])[0][-1])
510 tmp_r =int(numpy.where(self.buf_azi[(self.flag+1)*len(tmp_z):(self.flag+2)*len(tmp_z)]>=tmp_z[-1])[0][0])
511 print("tmp_r",tmp_r)
512 index_f=(self.flag+1)*len(tmp_z)+tmp_r
513
514 if len(tmp_z[index_i:])>len(self.buf_azi[len(tmp_z)*(self.flag+1):index_f]):
515 final = len(self.buf_azi[len(tmp_z)*(self.flag+1):index_f])
516 else:
517 final= len(tmp_z[index_i:])
518 self.buf_azi[len(tmp_z)*(self.flag+1):index_f]=tmp_z[index_i:index_i+final]
519 self.buf_tmp[len(tmp_z)*(self.flag+1):index_f,:]=tmp_v[index_i:index_i+final,:]
520 if limit_i<tmp_z[0]<limit_s:
521 index_f =int(numpy.where(self.buf_azi>=tmp_z[-1])[0][0])
522 n_p =index_f-len(tmp_z)*(self.flag+1)
523 if n_p>0:
524 self.buf_azi[len(tmp_z)*(self.flag+1):index_f]=tmp_z[-1]*numpy.ones(n_p)
525 self.buf_tmp[len(tmp_z)*(self.flag+1):index_f,:]=tmp_v[-1,:]*numpy.ones([n_p,tmp_v.shape[1]])
526
527 '''
528 if self.buf_azi[len(tmp_z)]<tmp_z[-1]<self.buf_azi[2*len(tmp_z)-1]:
529 index_i= int(numpy.where(tmp_z <= self.buf_azi[len(tmp_z)])[0][-1])
530 index_f= int(numpy.where(self.buf_azi>=tmp_z[-1])[0][0])
531 #print("index",index_i,index_f)
532 if len(tmp_z[index_i:])>len(self.buf_azi[len(tmp_z):index_f]):
533 final = len(self.buf_azi[len(tmp_z):index_f])
534 else:
535 final = len(tmp_z[index_i:])
536 self.buf_azi[len(tmp_z):index_f]=tmp_z[index_i:index_i+final]
537 self.buf_tmp[len(tmp_z):index_f,:]=tmp_v[index_i:index_i+final,:]
538 '''
539 self.buf_tmp[len(tmp_z)*(self.flag):len(tmp_z)*(self.flag+1),:]=tmp_v
540 self.buf_azi[len(tmp_z)*(self.flag):len(tmp_z)*(self.flag+1)] = tmp_z
541 self.buffer_ini=self.buf_tmp
542 self.buffer_ini_azi = self.buf_azi
543 print("--------salida------------")
544 start= tmp_z[0]
545 end = tmp_z[-1]
546 print("start","end",start,end)
547 print(self.buffer_ini_azi[:120])
548 self.ini= self.ini+1
549 self.flag = self.flag +1
550 if self.flag==step:
551 self.flag=0
552
553 for i,ax in enumerate(self.axes):
554 if ax.firsttime:
555 plt.clf()
556 cgax, pm = wrl.vis.plot_ppi(self.buffer_ini,r=r,az=self.buffer_ini_azi,fig=self.figures[0], proj='cg', vmin=30, vmax=70)
557 else:
558 plt.clf()
559 cgax, pm = wrl.vis.plot_ppi(self.buffer_ini,r=r,az=self.buffer_ini_azi,fig=self.figures[0], proj='cg', vmin=30, vmax=70)
560 caax = cgax.parasites[0]
561 paax = cgax.parasites[1]
562 cbar = plt.gcf().colorbar(pm, pad=0.075)
563 caax.set_xlabel('x_range [km]')
564 caax.set_ylabel('y_range [km]')
565 plt.text(1.0, 1.05, 'azimuth', transform=caax.transAxes, va='bottom',ha='right')
@@ -46,9 +46,9 class SpectraPlot(Plot):
46 meta['xrange'] = (dataOut.getFreqRange(1)/1000., dataOut.getAcfRange(1), dataOut.getVelRange(1))
46 meta['xrange'] = (dataOut.getFreqRange(1)/1000., dataOut.getAcfRange(1), dataOut.getVelRange(1))
47 if self.CODE == 'spc_moments':
47 if self.CODE == 'spc_moments':
48 data['moments'] = dataOut.moments
48 data['moments'] = dataOut.moments
49
49
50 return data, meta
50 return data, meta
51
51
52 def plot(self):
52 def plot(self):
53 if self.xaxis == "frequency":
53 if self.xaxis == "frequency":
54 x = self.data.xrange[0]
54 x = self.data.xrange[0]
@@ -146,8 +146,8 class CrossSpectraPlot(Plot):
146
146
147 data['cspc'] = numpy.array(tmp)
147 data['cspc'] = numpy.array(tmp)
148
148
149 return data, meta
149 return data, meta
150
150
151 def plot(self):
151 def plot(self):
152
152
153 if self.xaxis == "frequency":
153 if self.xaxis == "frequency":
@@ -159,7 +159,7 class CrossSpectraPlot(Plot):
159 else:
159 else:
160 x = self.data.xrange[2]
160 x = self.data.xrange[2]
161 self.xlabel = "Velocity (m/s)"
161 self.xlabel = "Velocity (m/s)"
162
162
163 self.titles = []
163 self.titles = []
164
164
165 y = self.data.yrange
165 y = self.data.yrange
@@ -183,13 +183,13 class CrossSpectraPlot(Plot):
183 ax.plt.set_array(coh.T.ravel())
183 ax.plt.set_array(coh.T.ravel())
184 self.titles.append(
184 self.titles.append(
185 'Coherence Ch{} * Ch{}'.format(pair[0], pair[1]))
185 'Coherence Ch{} * Ch{}'.format(pair[0], pair[1]))
186
186
187 ax = self.axes[2 * n + 1]
187 ax = self.axes[2 * n + 1]
188 if ax.firsttime:
188 if ax.firsttime:
189 ax.plt = ax.pcolormesh(x, y, phase.T,
189 ax.plt = ax.pcolormesh(x, y, phase.T,
190 vmin=-180,
190 vmin=-180,
191 vmax=180,
191 vmax=180,
192 cmap=plt.get_cmap(self.colormap_phase)
192 cmap=plt.get_cmap(self.colormap_phase)
193 )
193 )
194 else:
194 else:
195 ax.plt.set_array(phase.T.ravel())
195 ax.plt.set_array(phase.T.ravel())
@@ -317,7 +317,7 class PhasePlot(CoherencePlot):
317
317
318 class NoisePlot(Plot):
318 class NoisePlot(Plot):
319 '''
319 '''
320 Plot for noise
320 Plot for noise
321 '''
321 '''
322
322
323 CODE = 'noise'
323 CODE = 'noise'
@@ -362,7 +362,7 class NoisePlot(Plot):
362 y = Y[ch]
362 y = Y[ch]
363 self.axes[0].lines[ch].set_data(x, y)
363 self.axes[0].lines[ch].set_data(x, y)
364
364
365
365
366 class PowerProfilePlot(Plot):
366 class PowerProfilePlot(Plot):
367
367
368 CODE = 'pow_profile'
368 CODE = 'pow_profile'
@@ -394,10 +394,10 class PowerProfilePlot(Plot):
394 self.y = y
394 self.y = y
395
395
396 x = self.data[-1][self.CODE]
396 x = self.data[-1][self.CODE]
397
397
398 if self.xmin is None: self.xmin = numpy.nanmin(x)*0.9
398 if self.xmin is None: self.xmin = numpy.nanmin(x)*0.9
399 if self.xmax is None: self.xmax = numpy.nanmax(x)*1.1
399 if self.xmax is None: self.xmax = numpy.nanmax(x)*1.1
400
400
401 if self.axes[0].firsttime:
401 if self.axes[0].firsttime:
402 for ch in self.data.channels:
402 for ch in self.data.channels:
403 self.axes[0].plot(x[ch], y, lw=1, label='Ch{}'.format(ch))
403 self.axes[0].plot(x[ch], y, lw=1, label='Ch{}'.format(ch))
@@ -559,7 +559,7 class BeaconPhase(Plot):
559 server=None, folder=None, username=None, password=None,
559 server=None, folder=None, username=None, password=None,
560 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0):
560 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0):
561
561
562 if dataOut.flagNoData:
562 if dataOut.flagNoData:
563 return dataOut
563 return dataOut
564
564
565 if not isTimeInHourRange(dataOut.datatime, xmin, xmax):
565 if not isTimeInHourRange(dataOut.datatime, xmin, xmax):
@@ -699,4 +699,91 class BeaconPhase(Plot):
699 thisDatetime=thisDatetime,
699 thisDatetime=thisDatetime,
700 update_figfile=update_figfile)
700 update_figfile=update_figfile)
701
701
702 return dataOut No newline at end of file
702 return dataOut
703
704 class WeatherPlot(Plot):
705 CODE = 'weather'
706 plot_name = 'weather'
707 plot_type = 'ppistyle'
708 buffering = False
709
710 def setup(self):
711 self.nplots = len(self.data.channels)
712 self.ncols = int(numpy.sqrt(self.nplots) + 0.9)
713 self.nrows = int((1.0 * self.nplots / self.ncols) + 0.9)
714 self.height = 2.6 * self.nrows
715 self.cb_label = 'dB'
716 if self.showprofile:
717 self.width = 4 * self.ncols
718 else:
719 self.width = 3.5 * self.ncols
720 self.plots_adjust.update({'wspace': 0.4, 'hspace':0.4, 'left': 0.1, 'right': 0.9, 'bottom': 0.08})
721 self.ylabel = 'Range [km]'
722
723 def update(self, dataOut):
724
725 data = {}
726 meta = {}
727 spc = 10*numpy.log10(dataOut.data_spc/dataOut.normFactor)
728 data['spc'] = spc
729 data['rti'] = dataOut.getPower()
730 data['noise'] = 10*numpy.log10(dataOut.getNoise()/dataOut.normFactor)
731 meta['xrange'] = (dataOut.getFreqRange(1)/1000., dataOut.getAcfRange(1), dataOut.getVelRange(1))
732 if self.CODE == 'spc_moments':
733 data['moments'] = dataOut.moments
734
735 return data, meta
736
737 def plot(self):
738 if self.xaxis == "frequency":
739 x = self.data.xrange[0]
740 self.xlabel = "Frequency (kHz)"
741 elif self.xaxis == "time":
742 x = self.data.xrange[1]
743 self.xlabel = "Time (ms)"
744 else:
745 x = self.data.xrange[2]
746 self.xlabel = "Velocity (m/s)"
747
748 if self.CODE == 'spc_moments':
749 x = self.data.xrange[2]
750 self.xlabel = "Velocity (m/s)"
751
752 self.titles = []
753
754 y = self.data.yrange
755 self.y = y
756
757 data = self.data[-1]
758 z = data['spc']
759
760 for n, ax in enumerate(self.axes):
761 noise = data['noise'][n]
762 if self.CODE == 'spc_moments':
763 mean = data['moments'][n, 2]
764 if ax.firsttime:
765 self.xmax = self.xmax if self.xmax else numpy.nanmax(x)
766 self.xmin = self.xmin if self.xmin else -self.xmax
767 self.zmin = self.zmin if self.zmin else numpy.nanmin(z)
768 self.zmax = self.zmax if self.zmax else numpy.nanmax(z)
769 ax.plt = ax.pcolormesh(x, y, z[n].T,
770 vmin=self.zmin,
771 vmax=self.zmax,
772 cmap=plt.get_cmap(self.colormap)
773 )
774
775 if self.showprofile:
776 ax.plt_profile = self.pf_axes[n].plot(
777 data['rti'][n], y)[0]
778 ax.plt_noise = self.pf_axes[n].plot(numpy.repeat(noise, len(y)), y,
779 color="k", linestyle="dashed", lw=1)[0]
780 if self.CODE == 'spc_moments':
781 ax.plt_mean = ax.plot(mean, y, color='k')[0]
782 else:
783 ax.plt.set_array(z[n].T.ravel())
784 if self.showprofile:
785 ax.plt_profile.set_data(data['rti'][n], y)
786 ax.plt_noise.set_data(numpy.repeat(noise, len(y)), y)
787 if self.CODE == 'spc_moments':
788 ax.plt_mean.set_data(mean, y)
789 self.titles.append('CH {}: {:3.2f}dB'.format(n, noise))
@@ -384,7 +384,7 def isRadarFolder(folder):
384
384
385
385
386 def isRadarFile(file):
386 def isRadarFile(file):
387 try:
387 try:
388 year = int(file[1:5])
388 year = int(file[1:5])
389 doy = int(file[5:8])
389 doy = int(file[5:8])
390 set = int(file[8:11])
390 set = int(file[8:11])
@@ -395,10 +395,10 def isRadarFile(file):
395
395
396
396
397 def getDateFromRadarFile(file):
397 def getDateFromRadarFile(file):
398 try:
398 try:
399 year = int(file[1:5])
399 year = int(file[1:5])
400 doy = int(file[5:8])
400 doy = int(file[5:8])
401 set = int(file[8:11])
401 set = int(file[8:11])
402 except:
402 except:
403 return None
403 return None
404
404
@@ -417,7 +417,7 def getDateFromRadarFolder(folder):
417 return thisDate
417 return thisDate
418
418
419 def parse_format(s, fmt):
419 def parse_format(s, fmt):
420
420
421 for i in range(fmt.count('%')):
421 for i in range(fmt.count('%')):
422 x = fmt.index('%')
422 x = fmt.index('%')
423 d = DT_DIRECTIVES[fmt[x:x+2]]
423 d = DT_DIRECTIVES[fmt[x:x+2]]
@@ -484,7 +484,7 class Reader(object):
484
484
485 def run(self):
485 def run(self):
486
486
487 raise NotImplementedError
487 raise NotImplementedError
488
488
489 def getAllowedArgs(self):
489 def getAllowedArgs(self):
490 if hasattr(self, '__attrs__'):
490 if hasattr(self, '__attrs__'):
@@ -496,19 +496,19 class Reader(object):
496
496
497 for key, value in kwargs.items():
497 for key, value in kwargs.items():
498 setattr(self, key, value)
498 setattr(self, key, value)
499
499
500 def find_folders(self, path, startDate, endDate, folderfmt, last=False):
500 def find_folders(self, path, startDate, endDate, folderfmt, last=False):
501
501
502 folders = [x for f in path.split(',')
502 folders = [x for f in path.split(',')
503 for x in os.listdir(f) if os.path.isdir(os.path.join(f, x))]
503 for x in os.listdir(f) if os.path.isdir(os.path.join(f, x))]
504 folders.sort()
504 folders.sort()
505
505
506 if last:
506 if last:
507 folders = [folders[-1]]
507 folders = [folders[-1]]
508
508
509 for folder in folders:
509 for folder in folders:
510 try:
510 try:
511 dt = datetime.datetime.strptime(parse_format(folder, folderfmt), folderfmt).date()
511 dt = datetime.datetime.strptime(parse_format(folder, folderfmt), folderfmt).date()
512 if dt >= startDate and dt <= endDate:
512 if dt >= startDate and dt <= endDate:
513 yield os.path.join(path, folder)
513 yield os.path.join(path, folder)
514 else:
514 else:
@@ -517,38 +517,38 class Reader(object):
517 log.log('Skiping folder {}'.format(folder), self.name)
517 log.log('Skiping folder {}'.format(folder), self.name)
518 continue
518 continue
519 return
519 return
520
520
521 def find_files(self, folders, ext, filefmt, startDate=None, endDate=None,
521 def find_files(self, folders, ext, filefmt, startDate=None, endDate=None,
522 expLabel='', last=False):
522 expLabel='', last=False):
523
523
524 for path in folders:
524 for path in folders:
525 files = glob.glob1(path, '*{}'.format(ext))
525 files = glob.glob1(path, '*{}'.format(ext))
526 files.sort()
526 files.sort()
527 if last:
527 if last:
528 if files:
528 if files:
529 fo = files[-1]
529 fo = files[-1]
530 try:
530 try:
531 dt = datetime.datetime.strptime(parse_format(fo, filefmt), filefmt).date()
531 dt = datetime.datetime.strptime(parse_format(fo, filefmt), filefmt).date()
532 yield os.path.join(path, expLabel, fo)
532 yield os.path.join(path, expLabel, fo)
533 except Exception as e:
533 except Exception as e:
534 pass
534 pass
535 return
535 return
536 else:
536 else:
537 return
537 return
538
538
539 for fo in files:
539 for fo in files:
540 try:
540 try:
541 dt = datetime.datetime.strptime(parse_format(fo, filefmt), filefmt).date()
541 dt = datetime.datetime.strptime(parse_format(fo, filefmt), filefmt).date()
542 if dt >= startDate and dt <= endDate:
542 if dt >= startDate and dt <= endDate:
543 yield os.path.join(path, expLabel, fo)
543 yield os.path.join(path, expLabel, fo)
544 else:
544 else:
545 log.log('Skiping file {}'.format(fo), self.name)
545 log.log('Skiping file {}'.format(fo), self.name)
546 except Exception as e:
546 except Exception as e:
547 log.log('Skiping file {}'.format(fo), self.name)
547 log.log('Skiping file {}'.format(fo), self.name)
548 continue
548 continue
549
549
550 def searchFilesOffLine(self, path, startDate, endDate,
550 def searchFilesOffLine(self, path, startDate, endDate,
551 expLabel, ext, walk,
551 expLabel, ext, walk,
552 filefmt, folderfmt):
552 filefmt, folderfmt):
553 """Search files in offline mode for the given arguments
553 """Search files in offline mode for the given arguments
554
554
@@ -561,12 +561,12 class Reader(object):
561 path, startDate, endDate, folderfmt)
561 path, startDate, endDate, folderfmt)
562 else:
562 else:
563 folders = path.split(',')
563 folders = path.split(',')
564
564
565 return self.find_files(
565 return self.find_files(
566 folders, ext, filefmt, startDate, endDate, expLabel)
566 folders, ext, filefmt, startDate, endDate, expLabel)
567
567
568 def searchFilesOnLine(self, path, startDate, endDate,
568 def searchFilesOnLine(self, path, startDate, endDate,
569 expLabel, ext, walk,
569 expLabel, ext, walk,
570 filefmt, folderfmt):
570 filefmt, folderfmt):
571 """Search for the last file of the last folder
571 """Search for the last file of the last folder
572
572
@@ -579,13 +579,13 class Reader(object):
579 Return:
579 Return:
580 generator with the full path of last filename
580 generator with the full path of last filename
581 """
581 """
582
582
583 if walk:
583 if walk:
584 folders = self.find_folders(
584 folders = self.find_folders(
585 path, startDate, endDate, folderfmt, last=True)
585 path, startDate, endDate, folderfmt, last=True)
586 else:
586 else:
587 folders = path.split(',')
587 folders = path.split(',')
588
588
589 return self.find_files(
589 return self.find_files(
590 folders, ext, filefmt, startDate, endDate, expLabel, last=True)
590 folders, ext, filefmt, startDate, endDate, expLabel, last=True)
591
591
@@ -594,13 +594,13 class Reader(object):
594
594
595 while True:
595 while True:
596 if self.fp != None:
596 if self.fp != None:
597 self.fp.close()
597 self.fp.close()
598
598
599 if self.online:
599 if self.online:
600 newFile = self.setNextFileOnline()
600 newFile = self.setNextFileOnline()
601 else:
601 else:
602 newFile = self.setNextFileOffline()
602 newFile = self.setNextFileOffline()
603
603
604 if not(newFile):
604 if not(newFile):
605 if self.online:
605 if self.online:
606 raise schainpy.admin.SchainError('Time to wait for new files reach')
606 raise schainpy.admin.SchainError('Time to wait for new files reach')
@@ -609,10 +609,10 class Reader(object):
609 raise schainpy.admin.SchainWarning('No files found in the given path')
609 raise schainpy.admin.SchainWarning('No files found in the given path')
610 else:
610 else:
611 raise schainpy.admin.SchainWarning('No more files to read')
611 raise schainpy.admin.SchainWarning('No more files to read')
612
612
613 if self.verifyFile(self.filename):
613 if self.verifyFile(self.filename):
614 break
614 break
615
615
616 log.log('Opening file: %s' % self.filename, self.name)
616 log.log('Opening file: %s' % self.filename, self.name)
617
617
618 self.readFirstHeader()
618 self.readFirstHeader()
@@ -625,7 +625,7 class Reader(object):
625 self.filename
625 self.filename
626 self.fp
626 self.fp
627 self.filesize
627 self.filesize
628
628
629 Return:
629 Return:
630 boolean
630 boolean
631
631
@@ -633,7 +633,7 class Reader(object):
633 nextFile = True
633 nextFile = True
634 nextDay = False
634 nextDay = False
635
635
636 for nFiles in range(self.nFiles+1):
636 for nFiles in range(self.nFiles+1):
637 for nTries in range(self.nTries):
637 for nTries in range(self.nTries):
638 fullfilename, filename = self.checkForRealPath(nextFile, nextDay)
638 fullfilename, filename = self.checkForRealPath(nextFile, nextDay)
639 if fullfilename is not None:
639 if fullfilename is not None:
@@ -643,18 +643,18 class Reader(object):
643 self.name)
643 self.name)
644 time.sleep(self.delay)
644 time.sleep(self.delay)
645 nextFile = False
645 nextFile = False
646 continue
646 continue
647
647
648 if fullfilename is not None:
648 if fullfilename is not None:
649 break
649 break
650
650
651 self.nTries = 1
651 self.nTries = 1
652 nextFile = True
652 nextFile = True
653
653
654 if nFiles == (self.nFiles - 1):
654 if nFiles == (self.nFiles - 1):
655 log.log('Trying with next day...', self.name)
655 log.log('Trying with next day...', self.name)
656 nextDay = True
656 nextDay = True
657 self.nTries = 3
657 self.nTries = 3
658
658
659 if fullfilename:
659 if fullfilename:
660 self.fileSize = os.path.getsize(fullfilename)
660 self.fileSize = os.path.getsize(fullfilename)
@@ -666,18 +666,18 class Reader(object):
666 self.flagNoMoreFiles = 0
666 self.flagNoMoreFiles = 0
667 self.fileIndex += 1
667 self.fileIndex += 1
668 return 1
668 return 1
669 else:
669 else:
670 return 0
670 return 0
671
671
672 def setNextFileOffline(self):
672 def setNextFileOffline(self):
673 """Open the next file to be readed in offline mode"""
673 """Open the next file to be readed in offline mode"""
674
674
675 try:
675 try:
676 filename = next(self.filenameList)
676 filename = next(self.filenameList)
677 self.fileIndex +=1
677 self.fileIndex +=1
678 except StopIteration:
678 except StopIteration:
679 self.flagNoMoreFiles = 1
679 self.flagNoMoreFiles = 1
680 return 0
680 return 0
681
681
682 self.filename = filename
682 self.filename = filename
683 self.fileSize = os.path.getsize(filename)
683 self.fileSize = os.path.getsize(filename)
@@ -685,22 +685,22 class Reader(object):
685 self.flagIsNewFile = 1
685 self.flagIsNewFile = 1
686
686
687 return 1
687 return 1
688
688
689 @staticmethod
689 @staticmethod
690 def isDateTimeInRange(dt, startDate, endDate, startTime, endTime):
690 def isDateTimeInRange(dt, startDate, endDate, startTime, endTime):
691 """Check if the given datetime is in range"""
691 """Check if the given datetime is in range"""
692
692
693 if startDate <= dt.date() <= endDate:
693 if startDate <= dt.date() <= endDate:
694 if startTime <= dt.time() <= endTime:
694 if startTime <= dt.time() <= endTime:
695 return True
695 return True
696 return False
696 return False
697
697
698 def verifyFile(self, filename):
698 def verifyFile(self, filename):
699 """Check for a valid file
699 """Check for a valid file
700
700
701 Arguments:
701 Arguments:
702 filename -- full path filename
702 filename -- full path filename
703
703
704 Return:
704 Return:
705 boolean
705 boolean
706 """
706 """
@@ -711,7 +711,7 class Reader(object):
711 """Check if the next file to be readed exists"""
711 """Check if the next file to be readed exists"""
712
712
713 raise NotImplementedError
713 raise NotImplementedError
714
714
715 def readFirstHeader(self):
715 def readFirstHeader(self):
716 """Parse the file header"""
716 """Parse the file header"""
717
717
@@ -783,8 +783,8 class JRODataReader(Reader):
783 Return:
783 Return:
784 str -- fullpath of the file
784 str -- fullpath of the file
785 """
785 """
786
786
787
787
788 if nextFile:
788 if nextFile:
789 self.set += 1
789 self.set += 1
790 if nextDay:
790 if nextDay:
@@ -796,7 +796,7 class JRODataReader(Reader):
796 prefixFileList = ['d', 'D']
796 prefixFileList = ['d', 'D']
797 elif self.ext.lower() == ".pdata": # spectra
797 elif self.ext.lower() == ".pdata": # spectra
798 prefixFileList = ['p', 'P']
798 prefixFileList = ['p', 'P']
799
799
800 # barrido por las combinaciones posibles
800 # barrido por las combinaciones posibles
801 for prefixDir in prefixDirList:
801 for prefixDir in prefixDirList:
802 thispath = self.path
802 thispath = self.path
@@ -816,9 +816,9 class JRODataReader(Reader):
816
816
817 if os.path.exists(fullfilename):
817 if os.path.exists(fullfilename):
818 return fullfilename, filename
818 return fullfilename, filename
819
819
820 return None, filename
820 return None, filename
821
821
822 def __waitNewBlock(self):
822 def __waitNewBlock(self):
823 """
823 """
824 Return 1 si se encontro un nuevo bloque de datos, 0 de otra forma.
824 Return 1 si se encontro un nuevo bloque de datos, 0 de otra forma.
@@ -860,9 +860,9 class JRODataReader(Reader):
860 def __setNewBlock(self):
860 def __setNewBlock(self):
861
861
862 if self.fp == None:
862 if self.fp == None:
863 return 0
863 return 0
864
864
865 if self.flagIsNewFile:
865 if self.flagIsNewFile:
866 self.lastUTTime = self.basicHeaderObj.utc
866 self.lastUTTime = self.basicHeaderObj.utc
867 return 1
867 return 1
868
868
@@ -875,12 +875,12 class JRODataReader(Reader):
875
875
876 currentSize = self.fileSize - self.fp.tell()
876 currentSize = self.fileSize - self.fp.tell()
877 neededSize = self.processingHeaderObj.blockSize + self.basicHeaderSize
877 neededSize = self.processingHeaderObj.blockSize + self.basicHeaderSize
878
878
879 if (currentSize >= neededSize):
879 if (currentSize >= neededSize):
880 self.basicHeaderObj.read(self.fp)
880 self.basicHeaderObj.read(self.fp)
881 self.lastUTTime = self.basicHeaderObj.utc
881 self.lastUTTime = self.basicHeaderObj.utc
882 return 1
882 return 1
883
883
884 if self.__waitNewBlock():
884 if self.__waitNewBlock():
885 self.lastUTTime = self.basicHeaderObj.utc
885 self.lastUTTime = self.basicHeaderObj.utc
886 return 1
886 return 1
@@ -966,10 +966,10 class JRODataReader(Reader):
966 except IOError:
966 except IOError:
967 log.error("File {} can't be opened".format(filename), self.name)
967 log.error("File {} can't be opened".format(filename), self.name)
968 return False
968 return False
969
969
970 if self.online and self.waitDataBlock(0):
970 if self.online and self.waitDataBlock(0):
971 pass
971 pass
972
972
973 basicHeaderObj = BasicHeader(LOCALTIME)
973 basicHeaderObj = BasicHeader(LOCALTIME)
974 systemHeaderObj = SystemHeader()
974 systemHeaderObj = SystemHeader()
975 radarControllerHeaderObj = RadarControllerHeader()
975 radarControllerHeaderObj = RadarControllerHeader()
@@ -996,7 +996,7 class JRODataReader(Reader):
996 dt2 = basicHeaderObj.datatime
996 dt2 = basicHeaderObj.datatime
997 if not self.isDateTimeInRange(dt1, self.startDate, self.endDate, self.startTime, self.endTime) and not \
997 if not self.isDateTimeInRange(dt1, self.startDate, self.endDate, self.startTime, self.endTime) and not \
998 self.isDateTimeInRange(dt2, self.startDate, self.endDate, self.startTime, self.endTime):
998 self.isDateTimeInRange(dt2, self.startDate, self.endDate, self.startTime, self.endTime):
999 flag = False
999 flag = False
1000
1000
1001 fp.close()
1001 fp.close()
1002 return flag
1002 return flag
@@ -1105,11 +1105,11 class JRODataReader(Reader):
1105 return dateList
1105 return dateList
1106
1106
1107 def setup(self, **kwargs):
1107 def setup(self, **kwargs):
1108
1108
1109 self.set_kwargs(**kwargs)
1109 self.set_kwargs(**kwargs)
1110 if not self.ext.startswith('.'):
1110 if not self.ext.startswith('.'):
1111 self.ext = '.{}'.format(self.ext)
1111 self.ext = '.{}'.format(self.ext)
1112
1112
1113 if self.server is not None:
1113 if self.server is not None:
1114 if 'tcp://' in self.server:
1114 if 'tcp://' in self.server:
1115 address = server
1115 address = server
@@ -1131,36 +1131,36 class JRODataReader(Reader):
1131
1131
1132 for nTries in range(self.nTries):
1132 for nTries in range(self.nTries):
1133 fullpath = self.searchFilesOnLine(self.path, self.startDate,
1133 fullpath = self.searchFilesOnLine(self.path, self.startDate,
1134 self.endDate, self.expLabel, self.ext, self.walk,
1134 self.endDate, self.expLabel, self.ext, self.walk,
1135 self.filefmt, self.folderfmt)
1135 self.filefmt, self.folderfmt)
1136
1136
1137 try:
1137 try:
1138 fullpath = next(fullpath)
1138 fullpath = next(fullpath)
1139 except:
1139 except:
1140 fullpath = None
1140 fullpath = None
1141
1141
1142 if fullpath:
1142 if fullpath:
1143 break
1143 break
1144
1144
1145 log.warning(
1145 log.warning(
1146 'Waiting {} sec for a valid file in {}: try {} ...'.format(
1146 'Waiting {} sec for a valid file in {}: try {} ...'.format(
1147 self.delay, self.path, nTries + 1),
1147 self.delay, self.path, nTries + 1),
1148 self.name)
1148 self.name)
1149 time.sleep(self.delay)
1149 time.sleep(self.delay)
1150
1150
1151 if not(fullpath):
1151 if not(fullpath):
1152 raise schainpy.admin.SchainError(
1152 raise schainpy.admin.SchainError(
1153 'There isn\'t any valid file in {}'.format(self.path))
1153 'There isn\'t any valid file in {}'.format(self.path))
1154
1154
1155 pathname, filename = os.path.split(fullpath)
1155 pathname, filename = os.path.split(fullpath)
1156 self.year = int(filename[1:5])
1156 self.year = int(filename[1:5])
1157 self.doy = int(filename[5:8])
1157 self.doy = int(filename[5:8])
1158 self.set = int(filename[8:11]) - 1
1158 self.set = int(filename[8:11]) - 1
1159 else:
1159 else:
1160 log.log("Searching files in {}".format(self.path), self.name)
1160 log.log("Searching files in {}".format(self.path), self.name)
1161 self.filenameList = self.searchFilesOffLine(self.path, self.startDate,
1161 self.filenameList = self.searchFilesOffLine(self.path, self.startDate,
1162 self.endDate, self.expLabel, self.ext, self.walk, self.filefmt, self.folderfmt)
1162 self.endDate, self.expLabel, self.ext, self.walk, self.filefmt, self.folderfmt)
1163
1163
1164 self.setNextFile()
1164 self.setNextFile()
1165
1165
1166 return
1166 return
@@ -1181,7 +1181,7 class JRODataReader(Reader):
1181 self.dataOut.useLocalTime = self.basicHeaderObj.useLocalTime
1181 self.dataOut.useLocalTime = self.basicHeaderObj.useLocalTime
1182
1182
1183 self.dataOut.ippSeconds = self.radarControllerHeaderObj.ippSeconds / self.nTxs
1183 self.dataOut.ippSeconds = self.radarControllerHeaderObj.ippSeconds / self.nTxs
1184
1184
1185 def getFirstHeader(self):
1185 def getFirstHeader(self):
1186
1186
1187 raise NotImplementedError
1187 raise NotImplementedError
@@ -1214,8 +1214,8 class JRODataReader(Reader):
1214 """
1214 """
1215
1215
1216 Arguments:
1216 Arguments:
1217 path :
1217 path :
1218 startDate :
1218 startDate :
1219 endDate :
1219 endDate :
1220 startTime :
1220 startTime :
1221 endTime :
1221 endTime :
@@ -1284,7 +1284,7 class JRODataWriter(Reader):
1284 dtype_width = get_dtype_width(dtype_index)
1284 dtype_width = get_dtype_width(dtype_index)
1285
1285
1286 return dtype_width
1286 return dtype_width
1287
1287
1288 def getProcessFlags(self):
1288 def getProcessFlags(self):
1289
1289
1290 processFlags = 0
1290 processFlags = 0
@@ -1322,9 +1322,9 class JRODataWriter(Reader):
1322
1322
1323 self.basicHeaderObj.size = self.basicHeaderSize # bytes
1323 self.basicHeaderObj.size = self.basicHeaderSize # bytes
1324 self.basicHeaderObj.version = self.versionFile
1324 self.basicHeaderObj.version = self.versionFile
1325 self.basicHeaderObj.dataBlock = self.nTotalBlocks
1325 self.basicHeaderObj.dataBlock = self.nTotalBlocks
1326 utc = numpy.floor(self.dataOut.utctime)
1326 utc = numpy.floor(self.dataOut.utctime)
1327 milisecond = (self.dataOut.utctime - utc) * 1000.0
1327 milisecond = (self.dataOut.utctime - utc) * 1000.0
1328 self.basicHeaderObj.utc = utc
1328 self.basicHeaderObj.utc = utc
1329 self.basicHeaderObj.miliSecond = milisecond
1329 self.basicHeaderObj.miliSecond = milisecond
1330 self.basicHeaderObj.timeZone = self.dataOut.timeZone
1330 self.basicHeaderObj.timeZone = self.dataOut.timeZone
@@ -1465,9 +1465,9 class JRODataWriter(Reader):
1465 if self.dataOut.datatime.date() > self.fileDate:
1465 if self.dataOut.datatime.date() > self.fileDate:
1466 setFile = 0
1466 setFile = 0
1467 self.nTotalBlocks = 0
1467 self.nTotalBlocks = 0
1468
1468
1469 filen = '{}{:04d}{:03d}{:03d}{}'.format(
1469 filen = '{}{:04d}{:03d}{:03d}{}'.format(
1470 self.optchar, timeTuple.tm_year, timeTuple.tm_yday, setFile, ext)
1470 self.optchar, timeTuple.tm_year, timeTuple.tm_yday, setFile, ext)
1471
1471
1472 filename = os.path.join(path, subfolder, filen)
1472 filename = os.path.join(path, subfolder, filen)
1473
1473
@@ -1515,11 +1515,11 class JRODataWriter(Reader):
1515 self.ext = ext.lower()
1515 self.ext = ext.lower()
1516
1516
1517 self.path = path
1517 self.path = path
1518
1518
1519 if set is None:
1519 if set is None:
1520 self.setFile = -1
1520 self.setFile = -1
1521 else:
1521 else:
1522 self.setFile = set - 1
1522 self.setFile = set - 1
1523
1523
1524 self.blocksPerFile = blocksPerFile
1524 self.blocksPerFile = blocksPerFile
1525 self.profilesPerBlock = profilesPerBlock
1525 self.profilesPerBlock = profilesPerBlock
@@ -17,7 +17,7 class HDFReader(Reader, ProcessingUnit):
17
17
18 This unit reads HDF5 files created with `HDFWriter` operation contains
18 This unit reads HDF5 files created with `HDFWriter` operation contains
19 by default two groups Data and Metadata all variables would be saved as `dataOut`
19 by default two groups Data and Metadata all variables would be saved as `dataOut`
20 attributes.
20 attributes.
21 It is possible to read any HDF5 file by given the structure in the `description`
21 It is possible to read any HDF5 file by given the structure in the `description`
22 parameter, also you can add extra values to metadata with the parameter `extras`.
22 parameter, also you can add extra values to metadata with the parameter `extras`.
23
23
@@ -37,10 +37,10 class HDFReader(Reader, ProcessingUnit):
37 Dictionary with the description of the HDF5 file
37 Dictionary with the description of the HDF5 file
38 extras : dict, optional
38 extras : dict, optional
39 Dictionary with extra metadata to be be added to `dataOut`
39 Dictionary with extra metadata to be be added to `dataOut`
40
40
41 Examples
41 Examples
42 --------
42 --------
43
43
44 desc = {
44 desc = {
45 'Data': {
45 'Data': {
46 'data_output': ['u', 'v', 'w'],
46 'data_output': ['u', 'v', 'w'],
@@ -64,7 +64,7 class HDFReader(Reader, ProcessingUnit):
64 extras = {
64 extras = {
65 'timeZone': 300
65 'timeZone': 300
66 }
66 }
67
67
68 reader = project.addReadUnit(
68 reader = project.addReadUnit(
69 name='HDFReader',
69 name='HDFReader',
70 path='/path/to/files',
70 path='/path/to/files',
@@ -95,45 +95,43 class HDFReader(Reader, ProcessingUnit):
95 self.folderfmt = "*%Y%j"
95 self.folderfmt = "*%Y%j"
96
96
97 def setup(self, **kwargs):
97 def setup(self, **kwargs):
98
99 self.set_kwargs(**kwargs)
98 self.set_kwargs(**kwargs)
100 if not self.ext.startswith('.'):
99 if not self.ext.startswith('.'):
101 self.ext = '.{}'.format(self.ext)
100 self.ext = '.{}'.format(self.ext)
102
101
103 if self.online:
102 if self.online:
104 log.log("Searching files in online mode...", self.name)
103 log.log("Searching files in online mode...", self.name)
105
104
106 for nTries in range(self.nTries):
105 for nTries in range(self.nTries):
107 fullpath = self.searchFilesOnLine(self.path, self.startDate,
106 fullpath = self.searchFilesOnLine(self.path, self.startDate,
108 self.endDate, self.expLabel, self.ext, self.walk,
107 self.endDate, self.expLabel, self.ext, self.walk,
109 self.filefmt, self.folderfmt)
108 self.filefmt, self.folderfmt)
110 try:
109 try:
111 fullpath = next(fullpath)
110 fullpath = next(fullpath)
112 except:
111 except:
113 fullpath = None
112 fullpath = None
114
113
115 if fullpath:
114 if fullpath:
116 break
115 break
117
116
118 log.warning(
117 log.warning(
119 'Waiting {} sec for a valid file in {}: try {} ...'.format(
118 'Waiting {} sec for a valid file in {}: try {} ...'.format(
120 self.delay, self.path, nTries + 1),
119 self.delay, self.path, nTries + 1),
121 self.name)
120 self.name)
122 time.sleep(self.delay)
121 time.sleep(self.delay)
123
122
124 if not(fullpath):
123 if not(fullpath):
125 raise schainpy.admin.SchainError(
124 raise schainpy.admin.SchainError(
126 'There isn\'t any valid file in {}'.format(self.path))
125 'There isn\'t any valid file in {}'.format(self.path))
127
126
128 pathname, filename = os.path.split(fullpath)
127 pathname, filename = os.path.split(fullpath)
129 self.year = int(filename[1:5])
128 self.year = int(filename[1:5])
130 self.doy = int(filename[5:8])
129 self.doy = int(filename[5:8])
131 self.set = int(filename[8:11]) - 1
130 self.set = int(filename[8:11]) - 1
132 else:
131 else:
133 log.log("Searching files in {}".format(self.path), self.name)
132 log.log("Searching files in {}".format(self.path), self.name)
134 self.filenameList = self.searchFilesOffLine(self.path, self.startDate,
133 self.filenameList = self.searchFilesOffLine(self.path, self.startDate,
135 self.endDate, self.expLabel, self.ext, self.walk, self.filefmt, self.folderfmt)
134 self.endDate, self.expLabel, self.ext, self.walk, self.filefmt, self.folderfmt)
136
137 self.setNextFile()
135 self.setNextFile()
138
136
139 return
137 return
@@ -141,18 +139,18 class HDFReader(Reader, ProcessingUnit):
141 def readFirstHeader(self):
139 def readFirstHeader(self):
142 '''Read metadata and data'''
140 '''Read metadata and data'''
143
141
144 self.__readMetadata()
142 self.__readMetadata()
145 self.__readData()
143 self.__readData()
146 self.__setBlockList()
144 self.__setBlockList()
147
145
148 if 'type' in self.meta:
146 if 'type' in self.meta:
149 self.dataOut = eval(self.meta['type'])()
147 self.dataOut = eval(self.meta['type'])()
150
148
151 for attr in self.meta:
149 for attr in self.meta:
152 setattr(self.dataOut, attr, self.meta[attr])
150 setattr(self.dataOut, attr, self.meta[attr])
153
151
154 self.blockIndex = 0
152 self.blockIndex = 0
155
153
156 return
154 return
157
155
158 def __setBlockList(self):
156 def __setBlockList(self):
@@ -194,13 +192,29 class HDFReader(Reader, ProcessingUnit):
194
192
195 meta = {}
193 meta = {}
196
194
195 desc = {
196 'Data': {
197 'dataPP_POW': 'Data/dataPP_POW/table00',
198 'utctime':'Data/utctime'
199 },
200 'Metadata': {
201 'azimuth' :'Metadata/azimuth',
202 'heightList' :'Metadata/heightList',
203 'flagDataAsBlock':'Metadata/flagDataAsBlock'
204 }
205 }
206
207 self.description = desc
197 if self.description:
208 if self.description:
198 for key, value in self.description['Metadata'].items():
209 for key, value in self.description['Metadata'].items():
199 meta[key] = self.fp[value].value
210 try:
211 meta[key] = self.fp[value].value
212 except:
213 meta[key] = self.fp[value][()]
200 else:
214 else:
201 grp = self.fp['Metadata']
215 grp = self.fp['Metadata']
202 for name in grp:
216 for name in grp:
203 meta[name] = grp[name].value
217 meta[name] = grp[name].value
204
218
205 if self.extras:
219 if self.extras:
206 for key, value in self.extras.items():
220 for key, value in self.extras.items():
@@ -212,12 +226,19 class HDFReader(Reader, ProcessingUnit):
212 def __readData(self):
226 def __readData(self):
213
227
214 data = {}
228 data = {}
215
229
216 if self.description:
230 if self.description:
217 for key, value in self.description['Data'].items():
231 for key, value in self.description['Data'].items():
218 if isinstance(value, str):
232 if isinstance(value, str):
219 if isinstance(self.fp[value], h5py.Dataset):
233 if isinstance(self.fp[value], h5py.Dataset):
220 data[key] = self.fp[value].value
234 try:
235 data[key] = self.fp[value].value
236 except:
237 ndim= self.fp[value][()].ndim
238 if ndim==2:
239 data[key] = numpy.swapaxes(self.fp[value][()],0,1)
240 if ndim==1:
241 data[key] = self.fp[value][()]
221 elif isinstance(self.fp[value], h5py.Group):
242 elif isinstance(self.fp[value], h5py.Group):
222 array = []
243 array = []
223 for ch in self.fp[value]:
244 for ch in self.fp[value]:
@@ -240,7 +261,7 class HDFReader(Reader, ProcessingUnit):
240 array = numpy.array(array)
261 array = numpy.array(array)
241 else:
262 else:
242 log.warning('Unknown type: {}'.format(name))
263 log.warning('Unknown type: {}'.format(name))
243
264
244 if name in self.description:
265 if name in self.description:
245 key = self.description[name]
266 key = self.description[name]
246 else:
267 else:
@@ -249,7 +270,7 class HDFReader(Reader, ProcessingUnit):
249
270
250 self.data = data
271 self.data = data
251 return
272 return
252
273
253 def getData(self):
274 def getData(self):
254
275
255 for attr in self.data:
276 for attr in self.data:
@@ -288,8 +309,8 class HDFWriter(Operation):
288 The HDF5 file contains by default two groups Data and Metadata where
309 The HDF5 file contains by default two groups Data and Metadata where
289 you can save any `dataOut` attribute specified by `dataList` and `metadataList`
310 you can save any `dataOut` attribute specified by `dataList` and `metadataList`
290 parameters, data attributes are normaly time dependent where the metadata
311 parameters, data attributes are normaly time dependent where the metadata
291 are not.
312 are not.
292 It is possible to customize the structure of the HDF5 file with the
313 It is possible to customize the structure of the HDF5 file with the
293 optional description parameter see the examples.
314 optional description parameter see the examples.
294
315
295 Parameters:
316 Parameters:
@@ -306,10 +327,10 class HDFWriter(Operation):
306 If True the name of the files corresponds to the timestamp of the data
327 If True the name of the files corresponds to the timestamp of the data
307 description : dict, optional
328 description : dict, optional
308 Dictionary with the desired description of the HDF5 file
329 Dictionary with the desired description of the HDF5 file
309
330
310 Examples
331 Examples
311 --------
332 --------
312
333
313 desc = {
334 desc = {
314 'data_output': {'winds': ['z', 'w', 'v']},
335 'data_output': {'winds': ['z', 'w', 'v']},
315 'utctime': 'timestamps',
336 'utctime': 'timestamps',
@@ -329,7 +350,7 class HDFWriter(Operation):
329 'heightList': 'heights'
350 'heightList': 'heights'
330 }
351 }
331 }
352 }
332
353
333 writer = proc_unit.addOperation(name='HDFWriter')
354 writer = proc_unit.addOperation(name='HDFWriter')
334 writer.addParameter(name='path', value='/path/to/file')
355 writer.addParameter(name='path', value='/path/to/file')
335 writer.addParameter(name='blocksPerFile', value='32')
356 writer.addParameter(name='blocksPerFile', value='32')
@@ -357,7 +378,7 class HDFWriter(Operation):
357 lastTime = None
378 lastTime = None
358
379
359 def __init__(self):
380 def __init__(self):
360
381
361 Operation.__init__(self)
382 Operation.__init__(self)
362 return
383 return
363
384
@@ -393,7 +414,7 class HDFWriter(Operation):
393 dsDict['shape'] = dataAux.shape
414 dsDict['shape'] = dataAux.shape
394 dsDict['dsNumber'] = dataAux.shape[0]
415 dsDict['dsNumber'] = dataAux.shape[0]
395 dsDict['dtype'] = dataAux.dtype
416 dsDict['dtype'] = dataAux.dtype
396
417
397 dsList.append(dsDict)
418 dsList.append(dsDict)
398
419
399 self.dsList = dsList
420 self.dsList = dsList
@@ -408,7 +429,7 class HDFWriter(Operation):
408 self.lastTime = currentTime
429 self.lastTime = currentTime
409 self.currentDay = dataDay
430 self.currentDay = dataDay
410 return False
431 return False
411
432
412 timeDiff = currentTime - self.lastTime
433 timeDiff = currentTime - self.lastTime
413
434
414 #Si el dia es diferente o si la diferencia entre un dato y otro supera la hora
435 #Si el dia es diferente o si la diferencia entre un dato y otro supera la hora
@@ -427,7 +448,7 class HDFWriter(Operation):
427
448
428 self.dataOut = dataOut
449 self.dataOut = dataOut
429 if not(self.isConfig):
450 if not(self.isConfig):
430 self.setup(path=path, blocksPerFile=blocksPerFile,
451 self.setup(path=path, blocksPerFile=blocksPerFile,
431 metadataList=metadataList, dataList=dataList,
452 metadataList=metadataList, dataList=dataList,
432 setType=setType, description=description)
453 setType=setType, description=description)
433
454
@@ -436,9 +457,9 class HDFWriter(Operation):
436
457
437 self.putData()
458 self.putData()
438 return
459 return
439
460
440 def setNextFile(self):
461 def setNextFile(self):
441
462
442 ext = self.ext
463 ext = self.ext
443 path = self.path
464 path = self.path
444 setFile = self.setFile
465 setFile = self.setFile
@@ -523,7 +544,7 class HDFWriter(Operation):
523 return 'pair{:02d}'.format(x)
544 return 'pair{:02d}'.format(x)
524 else:
545 else:
525 return 'channel{:02d}'.format(x)
546 return 'channel{:02d}'.format(x)
526
547
527 def writeMetadata(self, fp):
548 def writeMetadata(self, fp):
528
549
529 if self.description:
550 if self.description:
@@ -548,7 +569,7 class HDFWriter(Operation):
548 return
569 return
549
570
550 def writeData(self, fp):
571 def writeData(self, fp):
551
572
552 if self.description:
573 if self.description:
553 if 'Data' in self.description:
574 if 'Data' in self.description:
554 grp = fp.create_group('Data')
575 grp = fp.create_group('Data')
@@ -559,13 +580,13 class HDFWriter(Operation):
559
580
560 dtsets = []
581 dtsets = []
561 data = []
582 data = []
562
583
563 for dsInfo in self.dsList:
584 for dsInfo in self.dsList:
564 if dsInfo['nDim'] == 0:
585 if dsInfo['nDim'] == 0:
565 ds = grp.create_dataset(
586 ds = grp.create_dataset(
566 self.getLabel(dsInfo['variable']),
587 self.getLabel(dsInfo['variable']),
567 (self.blocksPerFile, ),
588 (self.blocksPerFile, ),
568 chunks=True,
589 chunks=True,
569 dtype=numpy.float64)
590 dtype=numpy.float64)
570 dtsets.append(ds)
591 dtsets.append(ds)
571 data.append((dsInfo['variable'], -1))
592 data.append((dsInfo['variable'], -1))
@@ -577,7 +598,7 class HDFWriter(Operation):
577 sgrp = grp
598 sgrp = grp
578 for i in range(dsInfo['dsNumber']):
599 for i in range(dsInfo['dsNumber']):
579 ds = sgrp.create_dataset(
600 ds = sgrp.create_dataset(
580 self.getLabel(dsInfo['variable'], i),
601 self.getLabel(dsInfo['variable'], i),
581 (self.blocksPerFile, ) + dsInfo['shape'][1:],
602 (self.blocksPerFile, ) + dsInfo['shape'][1:],
582 chunks=True,
603 chunks=True,
583 dtype=dsInfo['dtype'])
604 dtype=dsInfo['dtype'])
@@ -586,7 +607,7 class HDFWriter(Operation):
586 fp.flush()
607 fp.flush()
587
608
588 log.log('Creating file: {}'.format(fp.filename), self.name)
609 log.log('Creating file: {}'.format(fp.filename), self.name)
589
610
590 self.ds = dtsets
611 self.ds = dtsets
591 self.data = data
612 self.data = data
592 self.firsttime = True
613 self.firsttime = True
@@ -109,6 +109,13 class ParametersProc(ProcessingUnit):
109 self.dataOut.flagNoData = False
109 self.dataOut.flagNoData = False
110 self.dataOut.utctimeInit = self.dataIn.utctime
110 self.dataOut.utctimeInit = self.dataIn.utctime
111 self.dataOut.paramInterval = self.dataIn.nProfiles*self.dataIn.nCohInt*self.dataIn.ippSeconds
111 self.dataOut.paramInterval = self.dataIn.nProfiles*self.dataIn.nCohInt*self.dataIn.ippSeconds
112
113 if hasattr(self.dataIn, 'flagDataAsBlock'):
114 self.dataOut.flagDataAsBlock = self.dataIn.flagDataAsBlock
115
116 if hasattr(self.dataIn, 'profileIndex'):
117 self.dataOut.profileIndex = self.dataIn.profileIndex
118
112 if hasattr(self.dataIn, 'dataPP_POW'):
119 if hasattr(self.dataIn, 'dataPP_POW'):
113 self.dataOut.dataPP_POW = self.dataIn.dataPP_POW
120 self.dataOut.dataPP_POW = self.dataIn.dataPP_POW
114
121
@@ -3998,3 +4005,134 class SMOperations():
3998 # error[indInvalid1] = 13
4005 # error[indInvalid1] = 13
3999 #
4006 #
4000 # return heights, error
4007 # return heights, error
4008
4009 class Block360(Operation):
4010 '''
4011 '''
4012 isConfig = False
4013 __profIndex = 0
4014 __initime = None
4015 __lastdatatime = None
4016 __buffer = None
4017 __dataReady = False
4018 n = None
4019 __nch = 0
4020 __nHeis = 0
4021 index = 0
4022
4023 def __init__(self,**kwargs):
4024 Operation.__init__(self,**kwargs)
4025
4026 def setup(self, dataOut, n = None):
4027 '''
4028 n= Numero de PRF's de entrada
4029 '''
4030 self.__initime = None
4031 self.__lastdatatime = 0
4032 self.__dataReady = False
4033 self.__buffer = 0
4034 self.__buffer_1D = 0
4035 self.__profIndex = 0
4036 self.index = 0
4037
4038
4039 #print("ELVALOR DE n es:", n)
4040 if n == None:
4041 raise ValueError("n should be specified.")
4042
4043 if n != None:
4044 if n<2:
4045 raise ValueError("n should be greater than 2")
4046
4047 self.n = n
4048 #print("nHeights")
4049 self.__buffer = numpy.zeros(( n, dataOut.nHeights))
4050 self.__buffer2= numpy.zeros(n)
4051
4052 def putData(self,data):
4053 '''
4054 Add a profile to he __buffer and increase in one the __profiel Index
4055 '''
4056 #print("line 4049",data.dataPP_POW.shape,data.dataPP_POW[:10])
4057 #print("line 4049",data.azimuth.shape,data.azimuth)
4058 self.__buffer[self.__profIndex,:]= data.dataPP_POW
4059 #print("me casi",self.index,data.azimuth[self.index])
4060 #print(self.__profIndex, self.index , data.azimuth[self.index] )
4061 #print("magic",data.profileIndex)
4062 #print(data.azimuth[self.index])
4063 #print("index",self.index)
4064
4065 self.__buffer2[self.__profIndex] = data.azimuth[self.index]
4066 #print("q pasa")
4067 self.index+=1
4068 #print("index",self.index,data.azimuth[:10])
4069 self.__profIndex += 1
4070 return #Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β· Remove DCΒ·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·
4071
4072 def pushData(self,data):
4073 '''
4074 Return the PULSEPAIR and the profiles used in the operation
4075 Affected : self.__profileIndex
4076 '''
4077 #print("pushData")
4078
4079 data_360 = self.__buffer
4080 data_p = self.__buffer2
4081 n = self.__profIndex
4082
4083 self.__buffer = numpy.zeros(( self.n,330))
4084 self.__buffer2 = numpy.zeros(self.n)
4085 self.__profIndex = 0
4086 #print("pushData")
4087 return data_360,n,data_p
4088
4089
4090 def byProfiles(self,dataOut):
4091
4092 self.__dataReady = False
4093 data_360 = None
4094 data_p = None
4095 #print("dataOu",dataOut.dataPP_POW)
4096 self.putData(data=dataOut)
4097 #print("profIndex",self.__profIndex)
4098 if self.__profIndex == self.n:
4099 data_360,n,data_p = self.pushData(data=dataOut)
4100 self.__dataReady = True
4101
4102 return data_360,data_p
4103
4104
4105 def blockOp(self, dataOut, datatime= None):
4106 if self.__initime == None:
4107 self.__initime = datatime
4108 data_360,data_p = self.byProfiles(dataOut)
4109 self.__lastdatatime = datatime
4110
4111 if data_360 is None:
4112 return None, None,None
4113
4114 avgdatatime = self.__initime
4115 deltatime = datatime - self.__lastdatatime
4116 self.__initime = datatime
4117 #print(data_360.shape,avgdatatime,data_p.shape)
4118 return data_360,avgdatatime,data_p
4119
4120 def run(self, dataOut,n = None,**kwargs):
4121
4122 if not self.isConfig:
4123 self.setup(dataOut = dataOut, n = n , **kwargs)
4124 self.index = 0
4125 #print("comova",self.isConfig)
4126 self.isConfig = True
4127 if self.index==dataOut.azimuth.shape[0]:
4128 self.index=0
4129 data_360, avgdatatime,data_p = self.blockOp(dataOut, dataOut.utctime)
4130 dataOut.flagNoData = True
4131
4132 if self.__dataReady:
4133 dataOut.data_360 = data_360 # S
4134 dataOut.data_azi = data_p
4135 #print("jroproc_parameters",data_p[0],data_p[-1])#,data_360.shape,avgdatatime)
4136 dataOut.utctime = avgdatatime
4137 dataOut.flagNoData = False
4138 return dataOut
@@ -1287,7 +1287,7 class CombineProfiles(Operation):
1287
1287
1288 return dataOut
1288 return dataOut
1289
1289
1290 class PulsePairVoltage(Operation):
1290 class PulsePair(Operation):
1291 '''
1291 '''
1292 Function PulsePair(Signal Power, Velocity)
1292 Function PulsePair(Signal Power, Velocity)
1293 The real component of Lag[0] provides Intensity Information
1293 The real component of Lag[0] provides Intensity Information
@@ -1318,18 +1318,21 class PulsePairVoltage(Operation):
1318 lambda_ = 0
1318 lambda_ = 0
1319
1319
1320 def __init__(self,**kwargs):
1320 def __init__(self,**kwargs):
1321
1321 Operation.__init__(self,**kwargs)
1322 Operation.__init__(self,**kwargs)
1322
1323
1323 def setup(self, dataOut, n = None, removeDC=False):
1324 def setup(self, dataOut, n = None, removeDC=False):
1324 '''
1325 '''
1325 n= Numero de PRF's de entrada
1326 n= Numero de PRF's de entrada
1326 '''
1327 '''
1328 print("[INICIO]-setup del METODO PULSE PAIR")
1327 self.__initime = None
1329 self.__initime = None
1328 self.__lastdatatime = 0
1330 self.__lastdatatime = 0
1329 self.__dataReady = False
1331 self.__dataReady = False
1330 self.__buffer = 0
1332 self.__buffer = 0
1331 self.__profIndex = 0
1333 self.__profIndex = 0
1332 self.noise = None
1334 self.noise = None
1335
1333 self.__nch = dataOut.nChannels
1336 self.__nch = dataOut.nChannels
1334 self.__nHeis = dataOut.nHeights
1337 self.__nHeis = dataOut.nHeights
1335 self.removeDC = removeDC
1338 self.removeDC = removeDC
@@ -1367,17 +1370,17 class PulsePairVoltage(Operation):
1367 Return the PULSEPAIR and the profiles used in the operation
1370 Return the PULSEPAIR and the profiles used in the operation
1368 Affected : self.__profileIndex
1371 Affected : self.__profileIndex
1369 '''
1372 '''
1370 #----------------- Remove DC-----------------------------------
1373 #Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β· Remove DCΒ·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·
1371 if self.removeDC==True:
1374 if self.removeDC==True:
1372 mean = numpy.mean(self.__buffer,1)
1375 mean = numpy.mean(self.__buffer,1)
1373 tmp = mean.reshape(self.__nch,1,self.__nHeis)
1376 tmp = mean.reshape(self.__nch,1,self.__nHeis)
1374 dc= numpy.tile(tmp,[1,self.__nProf,1])
1377 dc= numpy.tile(tmp,[1,self.__nProf,1])
1375 self.__buffer = self.__buffer - dc
1378 self.__buffer = self.__buffer - dc
1376 #------------------Calculo de Potencia ------------------------
1379 #Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Calculo de Potencia Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·
1377 pair0 = self.__buffer*numpy.conj(self.__buffer)
1380 pair0 = self.__buffer*numpy.conj(self.__buffer)
1378 pair0 = pair0.real
1381 pair0 = pair0.real
1379 lag_0 = numpy.sum(pair0,1)
1382 lag_0 = numpy.sum(pair0,1)
1380 #------------------Calculo de Ruido x canal--------------------
1383 #Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Calculo de Ruido x canalΒ·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·
1381 self.noise = numpy.zeros(self.__nch)
1384 self.noise = numpy.zeros(self.__nch)
1382 for i in range(self.__nch):
1385 for i in range(self.__nch):
1383 daux = numpy.sort(pair0[i,:,:],axis= None)
1386 daux = numpy.sort(pair0[i,:,:],axis= None)
@@ -1387,11 +1390,11 class PulsePairVoltage(Operation):
1387 self.noise = numpy.tile(self.noise,[1,self.__nHeis])
1390 self.noise = numpy.tile(self.noise,[1,self.__nHeis])
1388 noise_buffer = self.noise.reshape(self.__nch,1,self.__nHeis)
1391 noise_buffer = self.noise.reshape(self.__nch,1,self.__nHeis)
1389 noise_buffer = numpy.tile(noise_buffer,[1,self.__nProf,1])
1392 noise_buffer = numpy.tile(noise_buffer,[1,self.__nProf,1])
1390 #------------------ Potencia recibida= P , Potencia senal = S , Ruido= N--
1393 #Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β· Potencia recibida= P , Potencia senal = S , Ruido= NΒ·Β·
1391 #------------------ P= S+N ,P=lag_0/N ---------------------------------
1394 #Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β· P= S+N ,P=lag_0/N Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·
1392 #-------------------- Power --------------------------------------------------
1395 #Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β· Power Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·
1393 data_power = lag_0/(self.n*self.nCohInt)
1396 data_power = lag_0/(self.n*self.nCohInt)
1394 #------------------ Senal ---------------------------------------------------
1397 #------------------ Senal Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·
1395 data_intensity = pair0 - noise_buffer
1398 data_intensity = pair0 - noise_buffer
1396 data_intensity = numpy.sum(data_intensity,axis=1)*(self.n*self.nCohInt)#*self.nCohInt)
1399 data_intensity = numpy.sum(data_intensity,axis=1)*(self.n*self.nCohInt)#*self.nCohInt)
1397 #data_intensity = (lag_0-self.noise*self.n)*(self.n*self.nCohInt)
1400 #data_intensity = (lag_0-self.noise*self.n)*(self.n*self.nCohInt)
@@ -1400,28 +1403,28 class PulsePairVoltage(Operation):
1400 if data_intensity[i][j] < 0:
1403 if data_intensity[i][j] < 0:
1401 data_intensity[i][j] = numpy.min(numpy.absolute(data_intensity[i][j]))
1404 data_intensity[i][j] = numpy.min(numpy.absolute(data_intensity[i][j]))
1402
1405
1403 #----------------- Calculo de Frecuencia y Velocidad doppler--------
1406 #Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β· Calculo de Frecuencia y Velocidad dopplerΒ·Β·Β·Β·Β·Β·Β·Β·
1404 pair1 = self.__buffer[:,:-1,:]*numpy.conjugate(self.__buffer[:,1:,:])
1407 pair1 = self.__buffer[:,:-1,:]*numpy.conjugate(self.__buffer[:,1:,:])
1405 lag_1 = numpy.sum(pair1,1)
1408 lag_1 = numpy.sum(pair1,1)
1406 data_freq = (-1/(2.0*math.pi*self.ippSec*self.nCohInt))*numpy.angle(lag_1)
1409 data_freq = (-1/(2.0*math.pi*self.ippSec*self.nCohInt))*numpy.angle(lag_1)
1407 data_velocity = (self.lambda_/2.0)*data_freq
1410 data_velocity = (self.lambda_/2.0)*data_freq
1408
1411
1409 #---------------- Potencia promedio estimada de la Senal-----------
1412 #Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β· Potencia promedio estimada de la SenalΒ·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·
1410 lag_0 = lag_0/self.n
1413 lag_0 = lag_0/self.n
1411 S = lag_0-self.noise
1414 S = lag_0-self.noise
1412
1415
1413 #---------------- Frecuencia Doppler promedio ---------------------
1416 #Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β· Frecuencia Doppler promedio Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·
1414 lag_1 = lag_1/(self.n-1)
1417 lag_1 = lag_1/(self.n-1)
1415 R1 = numpy.abs(lag_1)
1418 R1 = numpy.abs(lag_1)
1416
1419
1417 #---------------- Calculo del SNR----------------------------------
1420 #Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β· Calculo del SNRΒ·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·
1418 data_snrPP = S/self.noise
1421 data_snrPP = S/self.noise
1419 for i in range(self.__nch):
1422 for i in range(self.__nch):
1420 for j in range(self.__nHeis):
1423 for j in range(self.__nHeis):
1421 if data_snrPP[i][j] < 1.e-20:
1424 if data_snrPP[i][j] < 1.e-20:
1422 data_snrPP[i][j] = 1.e-20
1425 data_snrPP[i][j] = 1.e-20
1423
1426
1424 #----------------- Calculo del ancho espectral ----------------------
1427 #Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β· Calculo del ancho espectral Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·
1425 L = S/R1
1428 L = S/R1
1426 L = numpy.where(L<0,1,L)
1429 L = numpy.where(L<0,1,L)
1427 L = numpy.log(L)
1430 L = numpy.log(L)
@@ -1466,10 +1469,10 class PulsePairVoltage(Operation):
1466
1469
1467 return data_power, data_intensity, data_velocity, data_snrPP, data_specwidth, avgdatatime
1470 return data_power, data_intensity, data_velocity, data_snrPP, data_specwidth, avgdatatime
1468
1471
1469 def run(self, dataOut,n = None,removeDC= False, overlapping= False,**kwargs):
1472 def run(self, dataOut,n = None,removeDC= False,**kwargs):
1470
1473
1471 if not self.isConfig:
1474 if not self.isConfig:
1472 self.setup(dataOut = dataOut, n = n , removeDC=removeDC , **kwargs)
1475 self.setup( dataOut, n = n , removeDC=removeDC , **kwargs)
1473 self.isConfig = True
1476 self.isConfig = True
1474 data_power, data_intensity, data_velocity,data_snrPP,data_specwidth, avgdatatime = self.pulsePairOp(dataOut, dataOut.utctime)
1477 data_power, data_intensity, data_velocity,data_snrPP,data_specwidth, avgdatatime = self.pulsePairOp(dataOut, dataOut.utctime)
1475 dataOut.flagNoData = True
1478 dataOut.flagNoData = True
@@ -1482,12 +1485,12 class PulsePairVoltage(Operation):
1482 dataOut.dataPP_SNR = data_snrPP
1485 dataOut.dataPP_SNR = data_snrPP
1483 dataOut.dataPP_WIDTH = data_specwidth
1486 dataOut.dataPP_WIDTH = data_specwidth
1484 dataOut.PRFbyAngle = self.n #numero de PRF*cada angulo rotado que equivale a un tiempo.
1487 dataOut.PRFbyAngle = self.n #numero de PRF*cada angulo rotado que equivale a un tiempo.
1488 dataOut.nProfiles = int(dataOut.nProfiles/n)
1485 dataOut.utctime = avgdatatime
1489 dataOut.utctime = avgdatatime
1486 dataOut.flagNoData = False
1490 dataOut.flagNoData = False
1487 return dataOut
1491 return dataOut
1488
1492
1489
1493
1490
1491 # import collections
1494 # import collections
1492 # from scipy.stats import mode
1495 # from scipy.stats import mode
1493 #
1496 #
General Comments 0
You need to be logged in to leave comments. Login now