##// END OF EJS Templates
Version 2.2.5 Fixed several bugs, add jro colormap for spectra/rti, add ParamWriter, TODO: Fix decimation currently disabled
Juan C. Valdez -
r860:5c2852893069
parent child
Show More
@@ -1,29 +1,12
1 Prerequisites:
2
3 Core:
4 -numpy 1.8.0
5 -scipy
6 -math
7 -matplotlib
8 -h5py
9 -ftplib
10 -paramiko (optional for SendTFilesToServer)
11 -stuffr (optional for jroIO_hf)
12 -pyfits (Fits data)
13
14 GUI:
15 -PyQt4
16 -wxPython
17
18 Signal Chain Installation:
1 Signal Chain Installation:
19
2
20 1. Install numpy, matplotlib, TKAgg
3 1. Install system dependencies: python-pip python-dev gfortran libpng-dev freetype* libblas-dev liblapack-dev libatlas-base-dev python-qt4
21 2. Install digital_rf_hdf5 module (developed by Haystack Observatory)
4 2. Install digital_rf_hdf5 module (developed by Haystack Observatory)
22 if you want to use USRP data
5 if you want to use USRP data
23 3. untar schainpy-x.x.x.tar.gz
6 3. untar schainpy-x.x.x.tar.gz
24 4. cd schainpy-x.x.x
7 4. cd schainpy-x.x.x
25 5. execute:
8 5. execute:
26 [hostname]$ sudo pyhon setup.py install
9 [hostname]$ sudo pip install ./
27 6. testing gui:
10 6. testing gui:
28 [hostname]$ schainGUI (enter)
11 [hostname]$ schainGUI (enter)
29
12
@@ -343,7 +343,7 class OperationConf():
343
343
344 self.parmConfObjList = []
344 self.parmConfObjList = []
345
345
346 parmElementList = opElement.getiterator(ParameterConf().getElementName())
346 parmElementList = opElement.iter(ParameterConf().getElementName())
347
347
348 for parmElement in parmElementList:
348 for parmElement in parmElementList:
349 parmConfObj = ParameterConf()
349 parmConfObj = ParameterConf()
@@ -568,7 +568,7 class ProcUnitConf():
568
568
569 self.opConfObjList = []
569 self.opConfObjList = []
570
570
571 opElementList = upElement.getiterator(OperationConf().getElementName())
571 opElementList = upElement.iter(OperationConf().getElementName())
572
572
573 for opElement in opElementList:
573 for opElement in opElementList:
574 opConfObj = OperationConf()
574 opConfObj = OperationConf()
@@ -798,7 +798,7 class ReadUnitConf(ProcUnitConf):
798
798
799 self.opConfObjList = []
799 self.opConfObjList = []
800
800
801 opElementList = upElement.getiterator(OperationConf().getElementName())
801 opElementList = upElement.iter(OperationConf().getElementName())
802
802
803 for opElement in opElementList:
803 for opElement in opElementList:
804 opConfObj = OperationConf()
804 opConfObj = OperationConf()
@@ -1026,7 +1026,7 class Project():
1026 self.name = self.projectElement.get('name')
1026 self.name = self.projectElement.get('name')
1027 self.description = self.projectElement.get('description')
1027 self.description = self.projectElement.get('description')
1028
1028
1029 readUnitElementList = self.projectElement.getiterator(ReadUnitConf().getElementName())
1029 readUnitElementList = self.projectElement.iter(ReadUnitConf().getElementName())
1030
1030
1031 for readUnitElement in readUnitElementList:
1031 for readUnitElement in readUnitElementList:
1032 readUnitConfObj = ReadUnitConf()
1032 readUnitConfObj = ReadUnitConf()
@@ -1037,7 +1037,7 class Project():
1037
1037
1038 self.procUnitConfObjDict[readUnitConfObj.getId()] = readUnitConfObj
1038 self.procUnitConfObjDict[readUnitConfObj.getId()] = readUnitConfObj
1039
1039
1040 procUnitElementList = self.projectElement.getiterator(ProcUnitConf().getElementName())
1040 procUnitElementList = self.projectElement.iter(ProcUnitConf().getElementName())
1041
1041
1042 for procUnitElement in procUnitElementList:
1042 for procUnitElement in procUnitElementList:
1043 procUnitConfObj = ProcUnitConf()
1043 procUnitConfObj = ProcUnitConf()
@@ -312,7 +312,7 class Axes:
312 decimationy = None
312 decimationy = None
313
313
314 __MAXNUMX = 200
314 __MAXNUMX = 200
315 __MAXNUMY = 400
315 __MAXNUMY = 100
316
316
317 __MAXNUMTIME = 500
317 __MAXNUMTIME = 500
318
318
@@ -501,13 +501,15 class Axes:
501 xlen = len(x)
501 xlen = len(x)
502 ylen = len(y)
502 ylen = len(y)
503
503
504 decimationx = numpy.floor(xlen/self.__MAXNUMX) - 1 if numpy.floor(xlen/self.__MAXNUMX)>1 else 1
504 decimationx = int(xlen/self.__MAXNUMX)+1 \
505 decimationy = numpy.floor(ylen/self.__MAXNUMY) + 1
505 if int(xlen/self.__MAXNUMX)>1 else 1
506
506 decimationy = int(ylen/self.__MAXNUMY) \
507 if int(ylen/self.__MAXNUMY)>1 else 1
508
509 x_buffer = x#[::decimationx]
510 y_buffer = y#[::decimationy]
511 z_buffer = z#[::decimationx, ::decimationy]
507
512
508 x_buffer = x[::decimationx]
509 y_buffer = y[::decimationy]
510 z_buffer = z[::decimationx, ::decimationy]
511 #===================================================
513 #===================================================
512
514
513 if self.__firsttime:
515 if self.__firsttime:
@@ -563,9 +565,9 class Axes:
563 maxNumX = self.__MAXNUMTIME
565 maxNumX = self.__MAXNUMTIME
564
566
565 if maxNumY == None:
567 if maxNumY == None:
566 maxNumY = self.__MAXNUMY
568 maxNumY = self.__MAXNUMY
567
569
568 if self.__firsttime:
570 if self.__firsttime:
569 self.z_buffer = z
571 self.z_buffer = z
570 self.x_buffer = numpy.hstack((self.x_buffer, x))
572 self.x_buffer = numpy.hstack((self.x_buffer, x))
571
573
@@ -604,12 +606,14 class Axes:
604 xlen = len(self.x_buffer)
606 xlen = len(self.x_buffer)
605 ylen = len(y)
607 ylen = len(y)
606
608
607 decimationx = numpy.floor(xlen/maxNumX) + 1
609 decimationx = int(xlen/self.__MAXNUMX) \
608 decimationy = numpy.floor(ylen/maxNumY) + 1
610 if int(xlen/self.__MAXNUMX)>1 else 1
611 decimationy = int(ylen/self.__MAXNUMY) \
612 if int(ylen/self.__MAXNUMY)>1 else 1
609
613
610 x_buffer = self.x_buffer[::decimationx]
614 x_buffer = self.x_buffer#[::decimationx]
611 y_buffer = y[::decimationy]
615 y_buffer = y#[::decimationy]
612 z_buffer = z_buffer[::decimationx, ::decimationy]
616 z_buffer = z_buffer#[::decimationx, ::decimationy]
613 #===================================================
617 #===================================================
614
618
615 x_buffer, y_buffer, z_buffer = self.__fillGaps(x_buffer, y_buffer, z_buffer)
619 x_buffer, y_buffer, z_buffer = self.__fillGaps(x_buffer, y_buffer, z_buffer)
@@ -5,6 +5,8 import numpy
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 import matplotlib.pyplot as plt
9
8 class MomentsPlot(Figure):
10 class MomentsPlot(Figure):
9
11
10 isConfig = None
12 isConfig = None
@@ -446,11 +448,10 class WindProfilerPlot(Figure):
446 # tmax = None
448 # tmax = None
447
449
448 x = dataOut.getTimeRange1(dataOut.outputInterval)
450 x = dataOut.getTimeRange1(dataOut.outputInterval)
449 # y = dataOut.heightList
450 y = dataOut.heightList
451 y = dataOut.heightList
451
452 z = dataOut.data_output.copy()
452 z = dataOut.data_output.copy()
453 nplots = z.shape[0] #Number of wind dimensions estimated
453 nplots = z.shape[0] #Number of wind dimensions estimated
454
454 nplotsw = nplots
455 nplotsw = nplots
455
456
456 #If there is a SNR function defined
457 #If there is a SNR function defined
@@ -458,20 +459,21 class WindProfilerPlot(Figure):
458 nplots += 1
459 nplots += 1
459 SNR = dataOut.data_SNR
460 SNR = dataOut.data_SNR
460 SNRavg = numpy.average(SNR, axis=0)
461 SNRavg = numpy.average(SNR, axis=0)
461
462
462 SNRdB = 10*numpy.log10(SNR)
463 SNRdB = 10*numpy.log10(SNR)
463 SNRavgdB = 10*numpy.log10(SNRavg)
464 SNRavgdB = 10*numpy.log10(SNRavg)
464
465
465 if SNRthresh == None: SNRthresh = -5.0
466 if SNRthresh == None: SNRthresh = -5.0
466 ind = numpy.where(SNRavg < 10**(SNRthresh/10))[0]
467 ind = numpy.where(SNRavg < 10**(SNRthresh/10))[0]
467
468
468 for i in range(nplotsw):
469 for i in range(nplotsw):
469 z[i,ind] = numpy.nan
470 z[i,ind] = numpy.nan
470
471
471
472
472 # showprofile = False
473 # showprofile = False
473 # thisDatetime = dataOut.datatime
474 # thisDatetime = dataOut.datatime
474 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.ltctime)
475 #thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.ltctime)
476 thisDatetime = datetime.datetime.now()
475 title = wintitle + "Wind"
477 title = wintitle + "Wind"
476 xlabel = ""
478 xlabel = ""
477 ylabel = "Height (km)"
479 ylabel = "Height (km)"
@@ -490,8 +492,8 class WindProfilerPlot(Figure):
490
492
491 self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange)
493 self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange)
492
494
493 if ymin == None: ymin = numpy.nanmin(y)
495 #if ymin == None: ymin = numpy.nanmin(y)
494 if ymax == None: ymax = numpy.nanmax(y)
496 #if ymax == None: ymax = numpy.nanmax(y)
495
497
496 if zmax == None: zmax = numpy.nanmax(abs(z[range(2),:]))
498 if zmax == None: zmax = numpy.nanmax(abs(z[range(2),:]))
497 #if numpy.isnan(zmax): zmax = 50
499 #if numpy.isnan(zmax): zmax = 50
@@ -501,9 +503,9 class WindProfilerPlot(Figure):
501 if zmax_ver == None: zmax_ver = numpy.nanmax(abs(z[2,:]))
503 if zmax_ver == None: zmax_ver = numpy.nanmax(abs(z[2,:]))
502 if zmin_ver == None: zmin_ver = -zmax_ver
504 if zmin_ver == None: zmin_ver = -zmax_ver
503
505
504 if dataOut.data_SNR is not None:
506 # if dataOut.data_SNR is not None:
505 if SNRmin == None: SNRmin = numpy.nanmin(SNRavgdB)
507 # if SNRmin == None: SNRmin = numpy.nanmin(SNRavgdB)
506 if SNRmax == None: SNRmax = numpy.nanmax(SNRavgdB)
508 # if SNRmax == None: SNRmax = numpy.nanmax(SNRavgdB)
507
509
508
510
509 self.FTP_WEI = ftp_wei
511 self.FTP_WEI = ftp_wei
@@ -518,8 +520,8 class WindProfilerPlot(Figure):
518
520
519 self.setWinTitle(title)
521 self.setWinTitle(title)
520
522
521 if ((self.xmax - x[1]) < (x[1]-x[0])):
523 #if ((self.xmax - x[1]) < (x[1]-x[0])):
522 x[1] = self.xmax
524 # x[1] = self.xmax
523
525
524 strWind = ['Zonal', 'Meridional', 'Vertical']
526 strWind = ['Zonal', 'Meridional', 'Vertical']
525 strCb = ['Velocity (m/s)','Velocity (m/s)','Velocity (cm/s)']
527 strCb = ['Velocity (m/s)','Velocity (m/s)','Velocity (cm/s)']
@@ -533,7 +535,7 class WindProfilerPlot(Figure):
533 axes = self.axesList[i*self.__nsubplots]
535 axes = self.axesList[i*self.__nsubplots]
534
536
535 z1 = z[i,:].reshape((1,-1))*windFactor[i]
537 z1 = z[i,:].reshape((1,-1))*windFactor[i]
536
538
537 axes.pcolorbuffer(x, y, z1,
539 axes.pcolorbuffer(x, y, z1,
538 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=zminVector[i], zmax=zmaxVector[i],
540 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,
541 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
@@ -543,9 +545,9 class WindProfilerPlot(Figure):
543 i += 1
545 i += 1
544 title = "Signal Noise Ratio (SNR): %s" %(thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
546 title = "Signal Noise Ratio (SNR): %s" %(thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
545 axes = self.axesList[i*self.__nsubplots]
547 axes = self.axesList[i*self.__nsubplots]
546
548
547 SNRavgdB = SNRavgdB.reshape((1,-1))
549 SNRavgdB = SNRavgdB.reshape((1,-1))
548
550
549 axes.pcolorbuffer(x, y, SNRavgdB,
551 axes.pcolorbuffer(x, y, SNRavgdB,
550 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=SNRmin, zmax=SNRmax,
552 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=SNRmin, zmax=SNRmax,
551 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
553 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
@@ -561,8 +563,8 class WindProfilerPlot(Figure):
561 thisDatetime=thisDatetime,
563 thisDatetime=thisDatetime,
562 update_figfile=update_figfile)
564 update_figfile=update_figfile)
563
565
564 if dataOut.ltctime + dataOut.outputInterval >= self.xmax:
566 if False and dataOut.ltctime + dataOut.outputInterval >= self.xmax:
565 self.counter_imagwr = wr_period
567 self.counter_imagwr = wr_period
566 self.isConfig = False
568 self.isConfig = False
567 update_figfile = True
569 update_figfile = True
568
570
@@ -778,7 +780,7 class ParametersPlot(Figure):
778
780
779
781
780
782
781 class Parameters1Plot(Figure):
783 class ParametersPlot(Figure):
782
784
783 __isConfig = None
785 __isConfig = None
784 __nsubplots = None
786 __nsubplots = None
@@ -86,7 +86,7 class SpectraPlot(Figure):
86 save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1,
86 save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1,
87 server=None, folder=None, username=None, password=None,
87 server=None, folder=None, username=None, password=None,
88 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0, realtime=False,
88 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0, realtime=False,
89 xaxis="frequency", colormap='jet'):
89 xaxis="velocity", **kwargs):
90
90
91 """
91 """
92
92
@@ -104,6 +104,8 class SpectraPlot(Figure):
104 zmax : None
104 zmax : None
105 """
105 """
106
106
107 colormap = kwargs.get('colormap','jet')
108
107 if realtime:
109 if realtime:
108 if not(isRealtime(utcdatatime = dataOut.utctime)):
110 if not(isRealtime(utcdatatime = dataOut.utctime)):
109 print 'Skipping this plot function'
111 print 'Skipping this plot function'
@@ -514,10 +516,10 class RTIPlot(Figure):
514
516
515 def run(self, dataOut, id, wintitle="", channelList=None, showprofile='True',
517 def run(self, dataOut, id, wintitle="", channelList=None, showprofile='True',
516 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
518 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
517 timerange=None, colormap='jet',
519 timerange=None,
518 save=False, figpath='./', lastone=0,figfile=None, ftp=False, wr_period=1, show=True,
520 save=False, figpath='./', lastone=0,figfile=None, ftp=False, wr_period=1, show=True,
519 server=None, folder=None, username=None, password=None,
521 server=None, folder=None, username=None, password=None,
520 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0):
522 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0, **kwargs):
521
523
522 """
524 """
523
525
@@ -535,6 +537,7 class RTIPlot(Figure):
535 zmax : None
537 zmax : None
536 """
538 """
537
539
540 colormap = kwargs.get('colormap', 'jet')
538 if not isTimeInHourRange(dataOut.datatime, xmin, xmax):
541 if not isTimeInHourRange(dataOut.datatime, xmin, xmax):
539 return
542 return
540
543
@@ -18,6 +18,8 from matplotlib.ticker import FuncFormatter, LinearLocator
18 #Actualizacion de las funciones del driver
18 #Actualizacion de las funciones del driver
19 ###########################################
19 ###########################################
20
20
21 # create jro colormap
22
21 jet_values = matplotlib.pyplot.get_cmap("jet", 100)(numpy.arange(100))[10:90]
23 jet_values = matplotlib.pyplot.get_cmap("jet", 100)(numpy.arange(100))[10:90]
22 blu_values = matplotlib.pyplot.get_cmap("seismic_r", 20)(numpy.arange(20))[10:15]
24 blu_values = matplotlib.pyplot.get_cmap("seismic_r", 20)(numpy.arange(20))[10:15]
23 ncmap = matplotlib.colors.LinearSegmentedColormap.from_list("jro", numpy.vstack((blu_values, jet_values)))
25 ncmap = matplotlib.colors.LinearSegmentedColormap.from_list("jro", numpy.vstack((blu_values, jet_values)))
@@ -202,7 +204,7 def createPcolor(ax, x, y, z, xmin, xmax, ymin, ymax, zmin, zmax,
202
204
203 z = numpy.ma.masked_invalid(z)
205 z = numpy.ma.masked_invalid(z)
204 cmap=matplotlib.pyplot.get_cmap(colormap)
206 cmap=matplotlib.pyplot.get_cmap(colormap)
205 cmap.set_bad('white',1.)
207 cmap.set_bad('white', 1.)
206 imesh = ax.pcolormesh(x,y,z.T, vmin=zmin, vmax=zmax, cmap=cmap)
208 imesh = ax.pcolormesh(x,y,z.T, vmin=zmin, vmax=zmax, cmap=cmap)
207 cb = matplotlib.pyplot.colorbar(imesh, cax=ax_cb)
209 cb = matplotlib.pyplot.colorbar(imesh, cax=ax_cb)
208 cb.set_label(cblabel)
210 cb.set_label(cblabel)
@@ -262,7 +264,7 def addpcolorbuffer(ax, x, y, z, zmin, zmax, xlabel='', ylabel='', title='', col
262 z = numpy.ma.masked_invalid(z)
264 z = numpy.ma.masked_invalid(z)
263
265
264 cmap=matplotlib.pyplot.get_cmap(colormap)
266 cmap=matplotlib.pyplot.get_cmap(colormap)
265 cmap.set_bad('white',1.)
267 cmap.set_bad('white', 1.)
266
268
267
269
268 ax.pcolormesh(x,y,z.T,vmin=zmin,vmax=zmax, cmap=cmap)
270 ax.pcolormesh(x,y,z.T,vmin=zmin,vmax=zmax, cmap=cmap)
@@ -11,4 +11,4 from jroIO_usrp import *
11
11
12 from jroIO_kamisr import *
12 from jroIO_kamisr import *
13 from jroIO_param import *
13 from jroIO_param import *
14 from jroIO_hf import * No newline at end of file
14 from jroIO_hf import *
@@ -399,70 +399,7 class ParamReader(ProcessingUnit):
399 self.listData = listdata
399 self.listData = listdata
400 return
400 return
401
401
402 def __setDataArray(self, dataset, shapes):
403
404 nDims = shapes[0]
405
406 nDim2 = shapes[1] #Dimension 0
407
402
408 nDim1 = shapes[2] #Dimension 1, number of Points or Parameters
409
410 nDim0 = shapes[3] #Dimension 2, number of samples or ranges
411
412 mode = shapes[4] #Mode of storing
413
414 blockList = self.blockList
415
416 blocksPerFile = self.blocksPerFile
417
418 #Depending on what mode the data was stored
419 if mode == 0: #Divided in channels
420 arrayData = dataset.value.astype(numpy.float)[0][blockList]
421 if mode == 1: #Divided in parameter
422 strds = 'table'
423 nDatas = nDim1
424 newShapes = (blocksPerFile,nDim2,nDim0)
425 elif mode==2: #Concatenated in a table
426 strds = 'table0'
427 arrayData = dataset[strds].value
428 #Selecting part of the dataset
429 utctime = arrayData[:,0]
430 u, indices = numpy.unique(utctime, return_index=True)
431
432 if blockList.size != indices.size:
433 indMin = indices[blockList[0]]
434 if blockList[-1] + 1 >= indices.size:
435 arrayData = arrayData[indMin:,:]
436 else:
437 indMax = indices[blockList[-1] + 1]
438 arrayData = arrayData[indMin:indMax,:]
439 return arrayData
440
441 #------- One dimension ---------------
442 if nDims == 0:
443 arrayData = dataset.value.astype(numpy.float)[0][blockList]
444
445 #------- Two dimensions -----------
446 elif nDims == 2:
447 arrayData = numpy.zeros((blocksPerFile,nDim1,nDim0))
448 newShapes = (blocksPerFile,nDim0)
449 nDatas = nDim1
450
451 for i in range(nDatas):
452 data = dataset[strds + str(i)].value
453 arrayData[:,i,:] = data[blockList,:]
454
455 #------- Three dimensions ---------
456 else:
457 arrayData = numpy.zeros((blocksPerFile,nDim2,nDim1,nDim0))
458 for i in range(nDatas):
459
460 data = dataset[strds + str(i)].value
461
462 for b in range(blockList.size):
463 arrayData[b,:,i,:] = data[:,:,blockList[b]]
464
465 return arrayData
466
403
467 def __setDataOut(self):
404 def __setDataOut(self):
468 listMeta = self.listMeta
405 listMeta = self.listMeta
@@ -571,8 +571,10 class SpectraWriter(JRODataWriter, Operation):
571
571
572 if self.dataOut.flagDiscontinuousBlock:
572 if self.dataOut.flagDiscontinuousBlock:
573 self.data_spc.fill(0)
573 self.data_spc.fill(0)
574 self.data_cspc.fill(0)
574 if self.dataOut.data_cspc is not None:
575 self.data_dc.fill(0)
575 self.data_cspc.fill(0)
576 if self.dataOut.data_dc is not None:
577 self.data_dc.fill(0)
576 self.setNextFile()
578 self.setNextFile()
577
579
578 if self.flagIsNewFile == 0:
580 if self.flagIsNewFile == 0:
@@ -5,93 +5,93 $Id: jroproc_base.py 1 2012-11-12 18:56:07Z murco $
5 '''
5 '''
6
6
7 class ProcessingUnit(object):
7 class ProcessingUnit(object):
8
8
9 """
9 """
10 Esta es la clase base para el procesamiento de datos.
10 Esta es la clase base para el procesamiento de datos.
11
11
12 Contiene el metodo "call" para llamar operaciones. Las operaciones pueden ser:
12 Contiene el metodo "call" para llamar operaciones. Las operaciones pueden ser:
13 - Metodos internos (callMethod)
13 - Metodos internos (callMethod)
14 - Objetos del tipo Operation (callObject). Antes de ser llamados, estos objetos
14 - Objetos del tipo Operation (callObject). Antes de ser llamados, estos objetos
15 tienen que ser agreagados con el metodo "add".
15 tienen que ser agreagados con el metodo "add".
16
16
17 """
17 """
18 # objeto de datos de entrada (Voltage, Spectra o Correlation)
18 # objeto de datos de entrada (Voltage, Spectra o Correlation)
19 dataIn = None
19 dataIn = None
20 dataInList = []
20 dataInList = []
21
21
22 # objeto de datos de entrada (Voltage, Spectra o Correlation)
22 # objeto de datos de entrada (Voltage, Spectra o Correlation)
23 dataOut = None
23 dataOut = None
24
24
25 operations2RunDict = None
25 operations2RunDict = None
26
26
27 isConfig = False
27 isConfig = False
28
28
29
29
30 def __init__(self):
30 def __init__(self):
31
31
32 self.dataIn = None
32 self.dataIn = None
33 self.dataInList = []
33 self.dataInList = []
34
34
35 self.dataOut = None
35 self.dataOut = None
36
36
37 self.operations2RunDict = {}
37 self.operations2RunDict = {}
38
38
39 self.isConfig = False
39 self.isConfig = False
40
40
41 def addOperation(self, opObj, objId):
41 def addOperation(self, opObj, objId):
42
42
43 """
43 """
44 Agrega un objeto del tipo "Operation" (opObj) a la lista de objetos "self.objectList" y retorna el
44 Agrega un objeto del tipo "Operation" (opObj) a la lista de objetos "self.objectList" y retorna el
45 identificador asociado a este objeto.
45 identificador asociado a este objeto.
46
46
47 Input:
47 Input:
48
48
49 object : objeto de la clase "Operation"
49 object : objeto de la clase "Operation"
50
50
51 Return:
51 Return:
52
52
53 objId : identificador del objeto, necesario para ejecutar la operacion
53 objId : identificador del objeto, necesario para ejecutar la operacion
54 """
54 """
55
55
56 self.operations2RunDict[objId] = opObj
56 self.operations2RunDict[objId] = opObj
57
57
58 return objId
58 return objId
59
59
60 def getOperationObj(self, objId):
60 def getOperationObj(self, objId):
61
61
62 if objId not in self.operations2RunDict.keys():
62 if objId not in self.operations2RunDict.keys():
63 return None
63 return None
64
64
65 return self.operations2RunDict[objId]
65 return self.operations2RunDict[objId]
66
66
67 def operation(self, **kwargs):
67 def operation(self, **kwargs):
68
68
69 """
69 """
70 Operacion directa sobre la data (dataOut.data). Es necesario actualizar los valores de los
70 Operacion directa sobre la data (dataOut.data). Es necesario actualizar los valores de los
71 atributos del objeto dataOut
71 atributos del objeto dataOut
72
72
73 Input:
73 Input:
74
74
75 **kwargs : Diccionario de argumentos de la funcion a ejecutar
75 **kwargs : Diccionario de argumentos de la funcion a ejecutar
76 """
76 """
77
77
78 raise NotImplementedError
78 raise NotImplementedError
79
79
80 def callMethod(self, name, **kwargs):
80 def callMethod(self, name, **kwargs):
81
81
82 """
82 """
83 Ejecuta el metodo con el nombre "name" y con argumentos **kwargs de la propia clase.
83 Ejecuta el metodo con el nombre "name" y con argumentos **kwargs de la propia clase.
84
84
85 Input:
85 Input:
86 name : nombre del metodo a ejecutar
86 name : nombre del metodo a ejecutar
87
87
88 **kwargs : diccionario con los nombres y valores de la funcion a ejecutar.
88 **kwargs : diccionario con los nombres y valores de la funcion a ejecutar.
89
89
90 """
90 """
91
91
92 #Checking the inputs
92 #Checking the inputs
93 if name == 'run':
93 if name == 'run':
94
94
95 if not self.checkInputs():
95 if not self.checkInputs():
96 self.dataOut.flagNoData = True
96 self.dataOut.flagNoData = True
97 return False
97 return False
@@ -99,196 +99,196 class ProcessingUnit(object):
99 #Si no es un metodo RUN la entrada es la misma dataOut (interna)
99 #Si no es un metodo RUN la entrada es la misma dataOut (interna)
100 if self.dataOut.isEmpty():
100 if self.dataOut.isEmpty():
101 return False
101 return False
102
102
103 #Getting the pointer to method
103 #Getting the pointer to method
104 methodToCall = getattr(self, name)
104 methodToCall = getattr(self, name)
105
105
106 #Executing the self method
106 #Executing the self method
107 methodToCall(**kwargs)
107 methodToCall(**kwargs)
108
108
109 #Checkin the outputs
109 #Checkin the outputs
110
110
111 # if name == 'run':
111 # if name == 'run':
112 # pass
112 # pass
113 # else:
113 # else:
114 # pass
114 # pass
115 #
115 #
116 # if name != 'run':
116 # if name != 'run':
117 # return True
117 # return True
118
118
119 if self.dataOut is None:
119 if self.dataOut is None:
120 return False
120 return False
121
121
122 if self.dataOut.isEmpty():
122 if self.dataOut.isEmpty():
123 return False
123 return False
124
124
125 return True
125 return True
126
126
127 def callObject(self, objId, **kwargs):
127 def callObject(self, objId, **kwargs):
128
128
129 """
129 """
130 Ejecuta la operacion asociada al identificador del objeto "objId"
130 Ejecuta la operacion asociada al identificador del objeto "objId"
131
131
132 Input:
132 Input:
133
133
134 objId : identificador del objeto a ejecutar
134 objId : identificador del objeto a ejecutar
135
135
136 **kwargs : diccionario con los nombres y valores de la funcion a ejecutar.
136 **kwargs : diccionario con los nombres y valores de la funcion a ejecutar.
137
137
138 Return:
138 Return:
139
139
140 None
140 None
141 """
141 """
142
142
143 if self.dataOut.isEmpty():
143 if self.dataOut.isEmpty():
144 return False
144 return False
145
145
146 externalProcObj = self.operations2RunDict[objId]
146 externalProcObj = self.operations2RunDict[objId]
147
147
148 externalProcObj.run(self.dataOut, **kwargs)
148 externalProcObj.run(self.dataOut, **kwargs)
149
149
150 return True
150 return True
151
151
152 def call(self, opType, opName=None, opId=None, **kwargs):
152 def call(self, opType, opName=None, opId=None, **kwargs):
153
153
154 """
154 """
155 Return True si ejecuta la operacion interna nombrada "opName" o la operacion externa
155 Return True si ejecuta la operacion interna nombrada "opName" o la operacion externa
156 identificada con el id "opId"; con los argumentos "**kwargs".
156 identificada con el id "opId"; con los argumentos "**kwargs".
157
157
158 False si la operacion no se ha ejecutado.
158 False si la operacion no se ha ejecutado.
159
159
160 Input:
160 Input:
161
161
162 opType : Puede ser "self" o "external"
162 opType : Puede ser "self" o "external"
163
163
164 Depende del tipo de operacion para llamar a:callMethod or callObject:
164 Depende del tipo de operacion para llamar a:callMethod or callObject:
165
165
166 1. If opType = "self": Llama a un metodo propio de esta clase:
166 1. If opType = "self": Llama a un metodo propio de esta clase:
167
167
168 name_method = getattr(self, name)
168 name_method = getattr(self, name)
169 name_method(**kwargs)
169 name_method(**kwargs)
170
170
171
171
172 2. If opType = "other" o"external": Llama al metodo "run()" de una instancia de la
172 2. If opType = "other" o"external": Llama al metodo "run()" de una instancia de la
173 clase "Operation" o de un derivado de ella:
173 clase "Operation" o de un derivado de ella:
174
174
175 instanceName = self.operationList[opId]
175 instanceName = self.operationList[opId]
176 instanceName.run(**kwargs)
176 instanceName.run(**kwargs)
177
177
178 opName : Si la operacion es interna (opType = 'self'), entonces el "opName" sera
178 opName : Si la operacion es interna (opType = 'self'), entonces el "opName" sera
179 usada para llamar a un metodo interno de la clase Processing
179 usada para llamar a un metodo interno de la clase Processing
180
180
181 opId : Si la operacion es externa (opType = 'other' o 'external), entonces el
181 opId : Si la operacion es externa (opType = 'other' o 'external), entonces el
182 "opId" sera usada para llamar al metodo "run" de la clase Operation
182 "opId" sera usada para llamar al metodo "run" de la clase Operation
183 registrada anteriormente con ese Id
183 registrada anteriormente con ese Id
184
184
185 Exception:
185 Exception:
186 Este objeto de tipo Operation debe de haber sido agregado antes con el metodo:
186 Este objeto de tipo Operation debe de haber sido agregado antes con el metodo:
187 "addOperation" e identificado con el valor "opId" = el id de la operacion.
187 "addOperation" e identificado con el valor "opId" = el id de la operacion.
188 De lo contrario retornara un error del tipo ValueError
188 De lo contrario retornara un error del tipo ValueError
189
189
190 """
190 """
191
191
192 if opType == 'self':
192 if opType == 'self':
193
193
194 if not opName:
194 if not opName:
195 raise ValueError, "opName parameter should be defined"
195 raise ValueError, "opName parameter should be defined"
196
196
197 sts = self.callMethod(opName, **kwargs)
197 sts = self.callMethod(opName, **kwargs)
198
198
199 elif opType == 'other' or opType == 'external' or opType == 'plotter':
199 elif opType == 'other' or opType == 'external' or opType == 'plotter':
200
200
201 if not opId:
201 if not opId:
202 raise ValueError, "opId parameter should be defined"
202 raise ValueError, "opId parameter should be defined"
203
203
204 if opId not in self.operations2RunDict.keys():
204 if opId not in self.operations2RunDict.keys():
205 raise ValueError, "Any operation with id=%s has been added" %str(opId)
205 raise ValueError, "Any operation with id=%s has been added" %str(opId)
206
206
207 sts = self.callObject(opId, **kwargs)
207 sts = self.callObject(opId, **kwargs)
208
208
209 else:
209 else:
210 raise ValueError, "opType should be 'self', 'external' or 'plotter'; and not '%s'" %opType
210 raise ValueError, "opType should be 'self', 'external' or 'plotter'; and not '%s'" %opType
211
211
212 return sts
212 return sts
213
213
214 def setInput(self, dataIn):
214 def setInput(self, dataIn):
215
215
216 self.dataIn = dataIn
216 self.dataIn = dataIn
217 self.dataInList.append(dataIn)
217 self.dataInList.append(dataIn)
218
218
219 def getOutputObj(self):
219 def getOutputObj(self):
220
220
221 return self.dataOut
221 return self.dataOut
222
222
223 def checkInputs(self):
223 def checkInputs(self):
224
224
225 for thisDataIn in self.dataInList:
225 for thisDataIn in self.dataInList:
226
226
227 if thisDataIn.isEmpty():
227 if thisDataIn.isEmpty():
228 return False
228 return False
229
229
230 return True
230 return True
231
231
232 def setup(self):
232 def setup(self):
233
233
234 raise NotImplementedError
234 raise NotImplementedError
235
235
236 def run(self):
236 def run(self):
237
237
238 raise NotImplementedError
238 raise NotImplementedError
239
239
240 def close(self):
240 def close(self):
241 #Close every thread, queue or any other object here is it is neccesary.
241 #Close every thread, queue or any other object here is it is neccesary.
242 return
242 return
243
243
244 class Operation(object):
244 class Operation(object):
245
245
246 """
246 """
247 Clase base para definir las operaciones adicionales que se pueden agregar a la clase ProcessingUnit
247 Clase base para definir las operaciones adicionales que se pueden agregar a la clase ProcessingUnit
248 y necesiten acumular informacion previa de los datos a procesar. De preferencia usar un buffer de
248 y necesiten acumular informacion previa de los datos a procesar. De preferencia usar un buffer de
249 acumulacion dentro de esta clase
249 acumulacion dentro de esta clase
250
250
251 Ejemplo: Integraciones coherentes, necesita la informacion previa de los n perfiles anteriores (bufffer)
251 Ejemplo: Integraciones coherentes, necesita la informacion previa de los n perfiles anteriores (bufffer)
252
252
253 """
253 """
254
254
255 __buffer = None
255 __buffer = None
256 isConfig = False
256 isConfig = False
257
257
258 def __init__(self):
258 def __init__(self):
259
259
260 self.__buffer = None
260 self.__buffer = None
261 self.isConfig = False
261 self.isConfig = False
262
262
263 def setup(self):
263 def setup(self):
264
264
265 self.isConfig = True
265 self.isConfig = True
266
266
267 raise NotImplementedError
267 raise NotImplementedError
268
268
269 def run(self, dataIn, **kwargs):
269 def run(self, dataIn, **kwargs):
270
270
271 """
271 """
272 Realiza las operaciones necesarias sobre la dataIn.data y actualiza los
272 Realiza las operaciones necesarias sobre la dataIn.data y actualiza los
273 atributos del objeto dataIn.
273 atributos del objeto dataIn.
274
274
275 Input:
275 Input:
276
276
277 dataIn : objeto del tipo JROData
277 dataIn : objeto del tipo JROData
278
278
279 Return:
279 Return:
280
280
281 None
281 None
282
282
283 Affected:
283 Affected:
284 __buffer : buffer de recepcion de datos.
284 __buffer : buffer de recepcion de datos.
285
285
286 """
286 """
287 if not self.isConfig:
287 if not self.isConfig:
288 self.setup(**kwargs)
288 self.setup(**kwargs)
289
289
290 raise NotImplementedError
290 raise NotImplementedError
291
291
292 def close(self):
292 def close(self):
293
293
294 pass No newline at end of file
294 pass
@@ -33,6 +33,8 class SpectraHeisProc(ProcessingUnit):
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
37 self.dataOut.noise_estimation = None
36 # self.dataOut.nProfiles = self.dataOut.nFFTPoints
38 # self.dataOut.nProfiles = self.dataOut.nFFTPoints
37 self.dataOut.nFFTPoints = self.dataIn.nHeights
39 self.dataOut.nFFTPoints = self.dataIn.nHeights
38 # self.dataOut.channelIndexList = self.dataIn.channelIndexList
40 # self.dataOut.channelIndexList = self.dataIn.channelIndexList
@@ -5,4 +5,4 $Id: Processor.py 1 2012-11-12 18:56:07Z murco $
5 '''
5 '''
6
6
7 from jroutils_ftp import *
7 from jroutils_ftp import *
8 from jroutils_publish import PublishData No newline at end of file
8 from jroutils_publish import *
@@ -9,94 +9,144 import paho.mqtt.client as mqtt
9
9
10 from schainpy.model.proc.jroproc_base import Operation
10 from schainpy.model.proc.jroproc_base import Operation
11
11
12
13 class PrettyFloat(float):
12 class PrettyFloat(float):
14 def __repr__(self):
13 def __repr__(self):
15 return '%.2f' % self
14 return '%.2f' % self
16
15
16
17 def pretty_floats(obj):
17 def pretty_floats(obj):
18 if isinstance(obj, float):
18 if isinstance(obj, float):
19 return PrettyFloat(obj)
19 return PrettyFloat(obj)
20 elif isinstance(obj, dict):
20 elif isinstance(obj, dict):
21 return dict((k, pretty_floats(v)) for k, v in obj.items())
21 return dict((k, pretty_floats(v)) for k, v in obj.items())
22 elif isinstance(obj, (list, tuple)):
22 elif isinstance(obj, (list, tuple)):
23 return map(pretty_floats, obj)
23 return map(pretty_floats, obj)
24 return obj
24 return obj
25
25
26
26 class PublishData(Operation):
27 class PublishData(Operation):
27
28 """Clase publish."""
29
28 __MAXNUMX = 80
30 __MAXNUMX = 80
29 __MAXNUMY = 80
31 __MAXNUMY = 80
30
32
31 def __init__(self):
33 def __init__(self):
32
34 """Inicio."""
33 Operation.__init__(self)
35 Operation.__init__(self)
34
35 self.isConfig = False
36 self.isConfig = False
36 self.client = None
37 self.client = None
37
38
38 @staticmethod
39 def on_disconnect(self, client, userdata, rc):
39 def on_disconnect(client, userdata, rc):
40 if rc != 0:
40 if rc != 0:
41 print("Unexpected disconnection.")
41 print("Unexpected disconnection.")
42
42 self.connect()
43 def setup(self, host, port=1883, username=None, password=None, **kwargs):
43
44
44 def connect(self):
45 self.client = mqtt.Client()
45 print 'trying to connect'
46 try:
46 try:
47 self.client.connect(host=host, port=port, keepalive=60*10, bind_address='')
47 self.client.connect(
48 host=self.host,
49 port=self.port,
50 keepalive=60*10,
51 bind_address='')
52 print "connected"
53 self.client.loop_start()
54 # self.client.publish(
55 # self.topic + 'SETUP',
56 # json.dumps(setup),
57 # retain=True
58 # )
48 except:
59 except:
60 print "MQTT Conection error."
49 self.client = False
61 self.client = False
62
63 def setup(self, host, port=1883, username=None, password=None, **kwargs):
64
50 self.topic = kwargs.get('topic', 'schain')
65 self.topic = kwargs.get('topic', 'schain')
51 self.delay = kwargs.get('delay', 0)
66 self.delay = kwargs.get('delay', 0)
67 self.plottype = kwargs.get('plottype', 'spectra')
52 self.host = host
68 self.host = host
53 self.port = port
69 self.port = port
54 self.cnt = 0
70 self.cnt = 0
55
71 setup = []
56 def run(self, dataOut, host, datatype='data_spc', **kwargs):
72 for plot in self.plottype:
57
73 setup.append({
58 if not self.isConfig:
74 'plot': plot,
75 'topic': self.topic + plot,
76 'title': getattr(self, plot + '_' + 'title', False),
77 'xlabel': getattr(self, plot + '_' + 'xlabel', False),
78 'ylabel': getattr(self, plot + '_' + 'ylabel', False),
79 'xrange': getattr(self, plot + '_' + 'xrange', False),
80 'yrange': getattr(self, plot + '_' + 'yrange', False),
81 'zrange': getattr(self, plot + '_' + 'zrange', False),
82 })
83 self.client = mqtt.Client(
84 client_id='jc'+self.topic + 'SCHAIN',
85 clean_session=True)
86 self.client.on_disconnect = self.on_disconnect
87 self.connect()
88
89 def publish_data(self, plottype):
90 data = getattr(self.dataOut, 'data_spc')
91 if plottype == 'spectra':
92 z = data/self.dataOut.normFactor
93 zdB = 10*numpy.log10(z)
94 xlen, ylen = zdB[0].shape
95 dx = numpy.floor(xlen/self.__MAXNUMX) + 1
96 dy = numpy.floor(ylen/self.__MAXNUMY) + 1
97 Z = [0 for i in self.dataOut.channelList]
98 for i in self.dataOut.channelList:
99 Z[i] = zdB[i][::dx, ::dy].tolist()
100 payload = {
101 'timestamp': self.dataOut.utctime,
102 'data': pretty_floats(Z),
103 'channels': ['Ch %s' % ch for ch in self.dataOut.channelList],
104 'interval': self.dataOut.getTimeInterval(),
105 'xRange': [0, 80]
106 }
107
108 elif plottype in ('rti', 'power'):
109 z = data/self.dataOut.normFactor
110 avg = numpy.average(z, axis=1)
111 avgdB = 10*numpy.log10(avg)
112 xlen, ylen = z[0].shape
113 dy = numpy.floor(ylen/self.__MAXNUMY) + 1
114 AVG = [0 for i in self.dataOut.channelList]
115 for i in self.dataOut.channelList:
116 AVG[i] = avgdB[i][::dy].tolist()
117 payload = {
118 'timestamp': self.dataOut.utctime,
119 'data': pretty_floats(AVG),
120 'channels': ['Ch %s' % ch for ch in self.dataOut.channelList],
121 'interval': self.dataOut.getTimeInterval(),
122 'xRange': [0, 80]
123 }
124 elif plottype == 'noise':
125 noise = self.dataOut.getNoise()/self.dataOut.normFactor
126 noisedB = 10*numpy.log10(noise)
127 payload = {
128 'timestamp': self.dataOut.utctime,
129 'data': pretty_floats(noisedB.reshape(-1, 1).tolist()),
130 'channels': ['Ch %s' % ch for ch in self.dataOut.channelList],
131 'interval': self.dataOut.getTimeInterval(),
132 'xRange': [0, 80]
133 }
134
135 print 'Publishing data to {}'.format(self.host)
136 print '*************************'
137 self.client.publish(self.topic + plottype, json.dumps(payload), qos=0)
138
139
140 def run(self, dataOut, host, **kwargs):
141 self.dataOut = dataOut
142 if not self.isConfig:
59 self.setup(host, **kwargs)
143 self.setup(host, **kwargs)
60 self.isConfig = True
144 self.isConfig = True
61
145
62 data = getattr(dataOut, datatype)
146 map(self.publish_data, self.plottype)
63
147 time.sleep(self.delay)
64 z = data/dataOut.normFactor
148
65 zdB = 10*numpy.log10(z)
66 avg = numpy.average(z, axis=1)
67 avgdB = 10*numpy.log10(avg)
68
69 xlen ,ylen = zdB[0].shape
70
71
72 dx = numpy.floor(xlen/self.__MAXNUMX) + 1
73 dy = numpy.floor(ylen/self.__MAXNUMY) + 1
74
75 Z = [0 for i in dataOut.channelList]
76 AVG = [0 for i in dataOut.channelList]
77
78 for i in dataOut.channelList:
79 Z[i] = zdB[i][::dx, ::dy].tolist()
80 AVG[i] = avgdB[i][::dy].tolist()
81
82 payload = {'timestamp':dataOut.utctime,
83 'data':pretty_floats(Z),
84 'data_profile':pretty_floats(AVG),
85 'channels': ['Ch %s' % ch for ch in dataOut.channelList],
86 'interval': dataOut.getTimeInterval(),
87 }
88
89
90 #if self.cnt==self.interval and self.client:
91 print 'Publishing data to {}'.format(self.host)
92 self.client.publish(self.topic, json.dumps(payload), qos=0)
93 time.sleep(self.delay)
94 #self.cnt = 0
95 #else:
96 # self.cnt += 1
97
98
99 def close(self):
149 def close(self):
100
150 if self.client:
101 if self.client:
151 self.client.loop_stop()
102 self.client.disconnect() No newline at end of file
152 self.client.disconnect()
@@ -33,8 +33,12 setup(name="schainpy",
33 include_package_data=False,
33 include_package_data=False,
34 scripts =['schainpy/gui/schainGUI',
34 scripts =['schainpy/gui/schainGUI',
35 'schainpy/scripts/schain'],
35 'schainpy/scripts/schain'],
36 install_requires=["numpy >= 1.6.0",
36 install_requires=[
37 "scipy >= 0.9.0",
37 "scipy >= 0.9.0",
38 "h5py >= 2.0.1",
38 "matplotlib >= 1.0.0",
39 "matplotlib >= 1.0.0",
40 "pyfits >= 2.0.0",
41 "numpy >= 1.6.0",
42 "paramiko",
39 ],
43 ],
40 ) No newline at end of file
44 )
General Comments 0
You need to be logged in to leave comments. Login now