diff --git a/schainpy/controller.py b/schainpy/controller.py index 04aa977..242e389 100644 --- a/schainpy/controller.py +++ b/schainpy/controller.py @@ -2,11 +2,11 @@ Created on September , 2012 @author: ''' -from xml.etree.ElementTree import Element, SubElement, ElementTree +from xml.etree.ElementTree import Element, SubElement from xml.etree import ElementTree as ET from xml.dom import minidom -import datetime +#import datetime from model import * import ast @@ -153,8 +153,12 @@ class ParameterConf(): self.id = parmElement.get('id') self.name = parmElement.get('name') self.value = parmElement.get('value') - self.format = parmElement.get('format') + self.format = str.lower(parmElement.get('format')) + #Compatible with old signal chain version + if self.format == 'int' and self.name == 'idfigure': + self.name = 'id' + def printattr(self): print "Parameter[%s]: name = %s, value = %s, format = %s" %(self.id, self.name, self.value, self.format) @@ -172,10 +176,10 @@ class OperationConf(): def __init__(self): - id = 0 - name = None - priority = None - type = 'self' + self.id = 0 + self.name = None + self.priority = None + self.type = 'self' def __getNewId(self): @@ -228,6 +232,11 @@ class OperationConf(): self.type = opElement.get('type') self.priority = opElement.get('priority') + #Compatible with old signal chain version + #Use of 'run' method instead 'init' + if self.type == 'self' and self.name == 'init': + self.name = 'run' + self.parmConfObjList = [] parmElementList = opElement.getiterator(ParameterConf().getElementName()) @@ -235,8 +244,16 @@ class OperationConf(): for parmElement in parmElementList: parmConfObj = ParameterConf() parmConfObj.readXml(parmElement) - self.parmConfObjList.append(parmConfObj) + + #Compatible with old signal chain version + #If an 'plot' OPERATION is found, changes name operation by the value of its type PARAMETER + if self.type != 'self' and self.name == 'Plot': + if parmConfObj.format == 'str' and parmConfObj.name == 'type': + self.name = parmConfObj.value + continue + self.parmConfObjList.append(parmConfObj) + def printattr(self): print "%s[%s]: name = %s, type = %s, priority = %s" %(self.ELEMENTNAME, @@ -361,7 +378,16 @@ class ProcUnitConf(): self.name = upElement.get('name') self.datatype = upElement.get('datatype') self.inputId = upElement.get('inputId') - + + #Compatible with old signal chain version + if self.ELEMENTNAME == ReadUnitConf().getElementName(): + if 'Reader' not in self.name: + self.name += 'Reader' + + if self.ELEMENTNAME == ProcUnitConf().getElementName(): + if 'Proc' not in self.name: + self.name += 'Proc' + self.opConfObjList = [] opElementList = upElement.getiterator(OperationConf().getElementName()) @@ -509,10 +535,22 @@ class Project(): self.name = name self.description = description - def addReadUnit(self, datatype, **kwargs): + def addReadUnit(self, datatype=None, name=None, **kwargs): + #Compatible with old signal chain version + if datatype==None and name==None: + raise ValueError, "datatype or name should be defined" + + if name==None: + if 'Reader' in datatype: + name = datatype + else: + name = '%sReader' %(datatype) + + if datatype==None: + datatype = name.replace('Reader','') + id = self.__getNewId() - name = '%s' %(datatype) readUnitConfObj = ReadUnitConf() readUnitConfObj.setup(id, name, datatype, **kwargs) @@ -521,10 +559,22 @@ class Project(): return readUnitConfObj - def addProcUnit(self, datatype, inputId): + def addProcUnit(self, inputId, datatype=None, name=None): + + #Compatible with old signal chain version + if datatype==None and name==None: + raise ValueError, "datatype or name should be defined" + + if name==None: + if 'Proc' in datatype: + name = datatype + else: + name = '%sProc' %(datatype) + + if datatype==None: + datatype = name.replace('Proc','') id = self.__getNewId() - name = '%s' %(datatype) procUnitConfObj = ProcUnitConf() procUnitConfObj.setup(id, name, datatype, inputId) @@ -552,7 +602,7 @@ class Project(): self.makeXml() - print prettify(self.projectElement) + #print prettify(self.projectElement) ElementTree(self.projectElement).write(filename, method='xml') @@ -633,19 +683,29 @@ class Project(): # for readUnitConfObj in self.readUnitConfObjList: # readUnitConfObj.run() - + print + print "*"*40 + print " Starting SIGNAL CHAIN PROCESSING " + print "*"*40 + print + + keyList = self.procUnitConfObjDict.keys() + keyList.sort() + while(True): finalSts = False - for procUnitConfObj in self.procUnitConfObjDict.values(): - #print "Running the '%s' process with %s" %(procUnitConfObj.name, procUnitConfObj.id) + for procKey in keyList: +# print "Running the '%s' process with %s" %(procUnitConfObj.name, procUnitConfObj.id) + + procUnitConfObj = self.procUnitConfObjDict[procKey] sts = procUnitConfObj.run() finalSts = finalSts or sts #If every process unit finished so end process if not(finalSts): - print "Every process units have finished" + print "Every process unit have finished" break if __name__ == '__main__': diff --git a/schainpy/model/__init__.py b/schainpy/model/__init__.py index a93f393..6dea354 100644 --- a/schainpy/model/__init__.py +++ b/schainpy/model/__init__.py @@ -1,5 +1,12 @@ -from model.data.jrodata import * -from model.io.jrodataIO import * -from model.proc.jroprocessing import * -from model.graphics.jroplot import * -from model.utils.jroutils import * \ No newline at end of file +#from schainpy.model.data.jrodata import * +# from schainpy.model.io.jrodataIO import * +# from schainpy.model.proc.jroprocessing import * +# from schainpy.model.graphics.jroplot import * +# from schainpy.model.utils.jroutils import * +# from schainpy.serializer import * + +from data import * +from io import * +from proc import * +from graphics import * +from utils import * diff --git a/schainpy/model/data/__init__.py b/schainpy/model/data/__init__.py index e69de29..6052841 100644 --- a/schainpy/model/data/__init__.py +++ b/schainpy/model/data/__init__.py @@ -0,0 +1,3 @@ +from jrodata import * +from jroheaderIO import * +from jroamisr import * \ No newline at end of file diff --git a/schainpy/model/data/jroamisr.py b/schainpy/model/data/jroamisr.py index c675433..3ccf9ce 100644 --- a/schainpy/model/data/jroamisr.py +++ b/schainpy/model/data/jroamisr.py @@ -1,4 +1,5 @@ import numpy +import copy class Beam: def __init__(self): @@ -25,7 +26,7 @@ class AMISR: self.channelList = [0]#self.dataIn.channelList esto solo aplica para el caso de AMISR self.dtype = numpy.dtype([('real',' 0: @@ -419,6 +430,7 @@ class ProcessingHeader(Header): flag_cspc = None def __init__(self): + self.size = 0 self.dtype = 0 self.blockSize = 0 @@ -430,8 +442,6 @@ class ProcessingHeader(Header): self.nIncohInt = 0 self.totalSpectra = 0 - self.samplingWindow = 0 - self.nHeights = 0 self.firstHeight = 0 self.deltaHeight = 0 @@ -458,12 +468,12 @@ class ProcessingHeader(Header): self.nIncohInt = int(header['nIncoherentIntegrations'][0]) self.totalSpectra = int(header['nTotalSpectra'][0]) - self.samplingWindow = numpy.fromfile(fp,SAMPLING_STRUCTURE,self.nWindows) + samplingWindow = numpy.fromfile(fp,SAMPLING_STRUCTURE,self.nWindows) - self.nHeights = int(numpy.sum(self.samplingWindow['nsa'])) - self.firstHeight = float(self.samplingWindow['h0'][0]) - self.deltaHeight = float(self.samplingWindow['dh'][0]) - self.samplesWin = self.samplingWindow['nsa'][0] + self.nHeights = int(numpy.sum(samplingWindow['nsa'])) + self.firstHeight = float(samplingWindow['h0'][0]) + self.deltaHeight = float(samplingWindow['dh'][0]) + self.samplesWin = samplingWindow['nsa'][0] self.spectraComb = numpy.fromfile(fp,'u1',2*self.totalSpectra) # if ((self.processFlags & PROCFLAG.DEFINE_PROCESS_CODE) == PROCFLAG.DEFINE_PROCESS_CODE): @@ -501,6 +511,7 @@ class ProcessingHeader(Header): return 1 def write(self, fp): + headerTuple = (self.size, self.dtype, self.blockSize, diff --git a/schainpy/model/graphics/__init__.py b/schainpy/model/graphics/__init__.py index e69de29..b298167 100644 --- a/schainpy/model/graphics/__init__.py +++ b/schainpy/model/graphics/__init__.py @@ -0,0 +1,5 @@ +from jroplot_voltage import * +from jroplot_spectra import * +from jroplot_heispectra import * +from jroplot_correlation import * +from jroplot_parameters import * \ No newline at end of file diff --git a/schainpy/model/graphics/figure.py b/schainpy/model/graphics/figure.py index 66d36fb..c50b3fc 100644 --- a/schainpy/model/graphics/figure.py +++ b/schainpy/model/graphics/figure.py @@ -45,7 +45,7 @@ class Figure: def __del__(self): - self.__driver.closeFigure() + self.__driver.closeFigure(True) def getFilename(self, name, ext='.png'): @@ -70,7 +70,7 @@ class Figure: return widthscreen, heightscreen - def getTimeLim(self, x, xmin=None, xmax=None, timerange=None, timezone=0): + def getTimeLim(self, x, xmin=None, xmax=None, timerange=None): if self.xmin != None and self.xmax != None: if timerange == None: @@ -80,17 +80,18 @@ class Figure: return xmin, xmax - - if timerange != None and self.xmin == None and self.xmax == None: - txmin = x[0] - x[0]%timerange + if timerange == None and (xmin==None or xmax==None): + raise ValueError, "timerange or xmin+xmax should be defined" + + if timerange != None: + txmin = x[0] - x[0] % min(timerange/10, 10*60) else: - txmin = numpy.min(x) - timerange = self.timerange + txmin = x[0] - x[0] % 10*60 thisdatetime = datetime.datetime.utcfromtimestamp(txmin) thisdate = datetime.datetime.combine(thisdatetime.date(), datetime.time(0,0,0)) - if xmin == None and xmax == None: + if timerange != None: xmin = (thisdatetime - thisdate).seconds/(60*60.) xmax = xmin + timerange/(60*60.) diff --git a/schainpy/model/graphics/jroplot_correlation.py b/schainpy/model/graphics/jroplot_correlation.py index 08c845e..5334cca 100644 --- a/schainpy/model/graphics/jroplot_correlation.py +++ b/schainpy/model/graphics/jroplot_correlation.py @@ -75,7 +75,7 @@ class CorrelationPlot(Figure): def run(self, dataOut, id, wintitle="", channelList=None, showprofile=False, xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None, - save=False, figpath='', figfile=None, show=True, ftp=False, wr_period=1, + save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1, server=None, folder=None, username=None, password=None, ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0, realtime=False): @@ -127,7 +127,7 @@ class CorrelationPlot(Figure): # noise = dataOut.noise/factor #thisDatetime = dataOut.datatime - thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[1]) + thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0]) title = wintitle + " Correlation" xlabel = "Lag T (s)" ylabel = "Range (Km)" @@ -180,17 +180,19 @@ class CorrelationPlot(Figure): self.draw() - if figfile == None: - str_datetime = thisDatetime.strftime("%Y%m%d_%H%M%S") - figfile = self.getFilename(name = str_datetime) - - if figpath != '': + if save: + + if figfile == None: + str_datetime = thisDatetime.strftime("%Y%m%d_%H%M%S") + figfile = self.getFilename(name = str_datetime) + self.counter_imagwr += 1 if (self.counter_imagwr>=wr_period): # store png plot to local folder self.saveFigure(figpath, figfile) - # store png plot to FTP server according to RT-Web format - name = self.getNameToFtp(thisDatetime, self.FTP_WEI, self.EXP_CODE, self.SUB_EXP_CODE, self.PLOT_CODE, self.PLOT_POS) - ftp_filename = os.path.join(figpath, name) - self.saveFigure(figpath, ftp_filename) + # store png plot to FTP server according to RT-Web format + if ftp: + name = self.getNameToFtp(thisDatetime, self.FTP_WEI, self.EXP_CODE, self.SUB_EXP_CODE, self.PLOT_CODE, self.PLOT_POS) + ftp_filename = os.path.join(figpath, name) + self.saveFigure(figpath, ftp_filename) self.counter_imagwr = 0 diff --git a/schainpy/model/graphics/jroplot_heispectra.py b/schainpy/model/graphics/jroplot_heispectra.py index 03b88a9..82b52cf 100644 --- a/schainpy/model/graphics/jroplot_heispectra.py +++ b/schainpy/model/graphics/jroplot_heispectra.py @@ -1,8 +1,8 @@ ''' +Created on Jul 9, 2014 -@author: Daniel Suarez +@author: roj-idl71 ''' - import os import datetime import numpy @@ -75,7 +75,7 @@ class SpectraHeisScope(Figure): def run(self, dataOut, id, wintitle="", channelList=None, xmin=None, xmax=None, ymin=None, ymax=None, save=False, - figpath='', figfile=None, ftp=False, wr_period=1, show=True, + figpath='./', figfile=None, ftp=False, wr_period=1, show=True, server=None, folder=None, username=None, password=None): """ @@ -120,7 +120,7 @@ class SpectraHeisScope(Figure): y = datadB #thisDatetime = dataOut.datatime - thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[1]) + thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0]) title = wintitle + " Scope: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) xlabel = "" #para 1Mhz descomentar la siguiente linea @@ -155,12 +155,13 @@ class SpectraHeisScope(Figure): self.draw() - - if figfile == None: - str_datetime = thisDatetime.strftime("%Y%m%d_%H%M%S") - figfile = self.getFilename(name = str_datetime) - if figpath != '': + if save: + + if figfile == None: + str_datetime = thisDatetime.strftime("%Y%m%d_%H%M%S") + figfile = self.getFilename(name = str_datetime) + self.counter_imagwr += 1 if (self.counter_imagwr>=wr_period): # store png plot to local folder @@ -223,7 +224,7 @@ class RTIfromSpectraHeis(Figure): def run(self, dataOut, id, wintitle="", channelList=None, showprofile='True', xmin=None, xmax=None, ymin=None, ymax=None, timerange=None, - save=False, figpath='', figfile=None, ftp=False, wr_period=1, show=True, + save=False, figpath='./', figfile=None, ftp=False, wr_period=1, show=True, server=None, folder=None, username=None, password=None): if channelList == None: @@ -254,7 +255,7 @@ class RTIfromSpectraHeis(Figure): # noisedB = 10*numpy.log10(noise) #thisDatetime = dataOut.datatime - thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[1]) + thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0]) title = wintitle + " RTI: %s" %(thisDatetime.strftime("%d-%b-%Y")) xlabel = "Local Time" ylabel = "Intensity (dB)" @@ -310,11 +311,12 @@ class RTIfromSpectraHeis(Figure): del self.ydata self.__isConfig = False - if self.figfile == None: - str_datetime = thisDatetime.strftime("%Y%m%d_%H%M%S") - self.figfile = self.getFilename(name = str_datetime) - - if figpath != '': + if save: + + if self.figfile == None: + str_datetime = thisDatetime.strftime("%Y%m%d_%H%M%S") + self.figfile = self.getFilename(name = str_datetime) + self.counter_imagwr += 1 if (self.counter_imagwr>=wr_period): # store png plot to local folder diff --git a/schainpy/model/graphics/jroplot_parameters.py b/schainpy/model/graphics/jroplot_parameters.py index f502fcc..0545fdc 100644 --- a/schainpy/model/graphics/jroplot_parameters.py +++ b/schainpy/model/graphics/jroplot_parameters.py @@ -73,7 +73,7 @@ class MomentsPlot(Figure): def run(self, dataOut, id, wintitle="", channelList=None, showprofile=True, xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None, - save=False, figpath='', figfile=None, show=True, ftp=False, wr_period=1, + save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1, server=None, folder=None, username=None, password=None, ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0, realtime=False): @@ -124,7 +124,7 @@ class MomentsPlot(Figure): noisedB = 10*numpy.log10(noise) #thisDatetime = dataOut.datatime - thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[1]) + thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0]) title = wintitle + " Parameters" xlabel = "Velocity (m/s)" ylabel = "Range (Km)" @@ -180,20 +180,24 @@ class MomentsPlot(Figure): self.draw() - if figfile == None: - str_datetime = thisDatetime.strftime("%Y%m%d_%H%M%S") - figfile = self.getFilename(name = str_datetime) - - if figpath != '': + if save: + + if figfile == None: + str_datetime = thisDatetime.strftime("%Y%m%d_%H%M%S") + figfile = self.getFilename(name = str_datetime) + self.counter_imagwr += 1 if (self.counter_imagwr>=wr_period): # store png plot to local folder self.saveFigure(figpath, figfile) - # store png plot to FTP server according to RT-Web format - name = self.getNameToFtp(thisDatetime, self.FTP_WEI, self.EXP_CODE, self.SUB_EXP_CODE, self.PLOT_CODE, self.PLOT_POS) - ftp_filename = os.path.join(figpath, name) - self.saveFigure(figpath, ftp_filename) self.counter_imagwr = 0 + # store png plot to FTP server according to RT-Web format + if ftp: + name = self.getNameToFtp(thisDatetime, self.FTP_WEI, self.EXP_CODE, self.SUB_EXP_CODE, self.PLOT_CODE, self.PLOT_POS) + ftp_filename = os.path.join(figpath, name) + self.saveFigure(figpath, ftp_filename) + + class SkyMapPlot(Figure): @@ -284,7 +288,7 @@ class SkyMapPlot(Figure): #thisDatetime = dataOut.datatime - thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[1]) + thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0]) title = wintitle + " Parameters" xlabel = "Zonal Zenith Angle (deg) " ylabel = "Meridional Zenith Angle (deg)" @@ -328,7 +332,9 @@ class SkyMapPlot(Figure): if figfile == None: figfile = self.getFilename(name = self.name) + self.saveFigure(figpath, figfile) + self.counter_imagwr = 0 if ftp: #provisionalmente envia archivos en el formato de la web en tiempo real @@ -345,7 +351,7 @@ class SkyMapPlot(Figure): self.counter_imagwr = 0 raise ValueError, 'Error FTP' - self.counter_imagwr = 0 + class WindProfilerPlot(Figure): @@ -417,7 +423,7 @@ class WindProfilerPlot(Figure): xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None, zmax_ver = None, zmin_ver = None, SNRmin = None, SNRmax = None, timerange=None, SNRthresh = None, - save=False, figpath='', lastone=0,figfile=None, ftp=False, wr_period=1, show=True, + save=False, figpath='./', lastone=0,figfile=None, ftp=False, wr_period=1, show=True, server=None, folder=None, username=None, password=None, ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0): """ @@ -477,7 +483,7 @@ class WindProfilerPlot(Figure): showprofile = False # thisDatetime = dataOut.datatime - thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[1]) + thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0]) title = wintitle + "Wind" xlabel = "" ylabel = "Range (Km)" @@ -553,22 +559,26 @@ class WindProfilerPlot(Figure): self.draw() - if self.figfile == None: - str_datetime = thisDatetime.strftime("%Y%m%d_%H%M%S") - self.figfile = self.getFilename(name = str_datetime) - - if figpath != '': + if save: + if self.figfile == None: + str_datetime = thisDatetime.strftime("%Y%m%d_%H%M%S") + self.figfile = self.getFilename(name = str_datetime) + self.counter_imagwr += 1 + if (self.counter_imagwr>=wr_period): # store png plot to local folder self.saveFigure(figpath, self.figfile) - # store png plot to FTP server according to RT-Web format - name = self.getNameToFtp(thisDatetime, self.FTP_WEI, self.EXP_CODE, self.SUB_EXP_CODE, self.PLOT_CODE, self.PLOT_POS) - ftp_filename = os.path.join(figpath, name) - self.saveFigure(figpath, ftp_filename) - self.counter_imagwr = 0 + + if ftp: + # store png plot to FTP server according to RT-Web format + name = self.getNameToFtp(thisDatetime, self.FTP_WEI, self.EXP_CODE, self.SUB_EXP_CODE, self.PLOT_CODE, self.PLOT_POS) + ftp_filename = os.path.join(figpath, name) + self.saveFigure(figpath, ftp_filename) + + if x[1] >= self.axesList[0].xmax: self.counter_imagwr = wr_period @@ -651,9 +661,8 @@ class ParametersPlot(Figure): xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,timerange=None, parameterIndex = None, onlyPositive = False, SNRthresh = -numpy.inf, SNR = True, SNRmin = None, SNRmax = None, - zlabel = "", parameterName = "", parameterObject = "data_param", - save=False, figpath='', lastone=0,figfile=None, ftp=False, wr_period=1, show=True, + save=False, figpath='./', lastone=0,figfile=None, ftp=False, wr_period=1, show=True, server=None, folder=None, username=None, password=None, ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0): @@ -704,7 +713,7 @@ class ParametersPlot(Figure): ind = numpy.where(SNRdB < 10**(SNRthresh/10)) z[ind] = numpy.nan - thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[1]) + thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0]) title = wintitle + " Parameters Plot" #: %s" %(thisDatetime.strftime("%d-%b-%Y")) xlabel = "" ylabel = "Range (Km)" @@ -775,25 +784,27 @@ class ParametersPlot(Figure): - self.draw() - - if self.figfile == None: - str_datetime = thisDatetime.strftime("%Y%m%d_%H%M%S") - self.figfile = self.getFilename(name = str_datetime) + self.draw() - if figpath != '': + if save: + if self.figfile == None: + str_datetime = thisDatetime.strftime("%Y%m%d_%H%M%S") + self.figfile = self.getFilename(name = str_datetime) + self.counter_imagwr += 1 + if (self.counter_imagwr>=wr_period): - # store png plot to local folder + # store png plot to local folder self.saveFigure(figpath, self.figfile) - # store png plot to FTP server according to RT-Web format - name = self.getNameToFtp(thisDatetime, self.FTP_WEI, self.EXP_CODE, self.SUB_EXP_CODE, self.PLOT_CODE, self.PLOT_POS) - ftp_filename = os.path.join(figpath, name) - self.saveFigure(figpath, ftp_filename) - self.counter_imagwr = 0 - + + if ftp: + # store png plot to FTP server according to RT-Web format + name = self.getNameToFtp(thisDatetime, self.FTP_WEI, self.EXP_CODE, self.SUB_EXP_CODE, self.PLOT_CODE, self.PLOT_POS) + ftp_filename = os.path.join(figpath, name) + self.saveFigure(figpath, ftp_filename) + if x[1] >= self.axesList[0].xmax: self.counter_imagwr = wr_period self.__isConfig = False @@ -923,7 +934,7 @@ class SpectralFittingPlot(Figure): zdB = 10*numpy.log10(z) #thisDatetime = dataOut.datatime - thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[1]) + thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0]) title = wintitle + " Doppler Spectra: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) xlabel = "Velocity (m/s)" ylabel = "Spectrum" @@ -1044,7 +1055,7 @@ class EWDriftsPlot(Figure): xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None, zmaxVertical = None, zminVertical = None, zmaxZonal = None, zminZonal = None, timerange=None, SNRthresh = -numpy.inf, SNRmin = None, SNRmax = None, SNR_1 = False, - save=False, figpath='', lastone=0,figfile=None, ftp=False, wr_period=1, show=True, + save=False, figpath='./', lastone=0,figfile=None, ftp=False, wr_period=1, show=True, server=None, folder=None, username=None, password=None, ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0): """ @@ -1171,23 +1182,25 @@ class EWDriftsPlot(Figure): ticksize=9, cblabel='', cbsize="1%", colormap="jet") self.draw() - - if self.figfile == None: - str_datetime = thisDatetime.strftime("%Y%m%d_%H%M%S") - self.figfile = self.getFilename(name = str_datetime) - if figpath != '': + if save: + if self.figfile == None: + str_datetime = thisDatetime.strftime("%Y%m%d_%H%M%S") + self.figfile = self.getFilename(name = str_datetime) + self.counter_imagwr += 1 + if (self.counter_imagwr>=wr_period): - # store png plot to local folder + # store png plot to local folder self.saveFigure(figpath, self.figfile) - # store png plot to FTP server according to RT-Web format - name = self.getNameToFtp(thisDatetime, self.FTP_WEI, self.EXP_CODE, self.SUB_EXP_CODE, self.PLOT_CODE, self.PLOT_POS) - ftp_filename = os.path.join(figpath, name) - self.saveFigure(figpath, ftp_filename) - self.counter_imagwr = 0 + + if ftp: + # store png plot to FTP server according to RT-Web format + name = self.getNameToFtp(thisDatetime, self.FTP_WEI, self.EXP_CODE, self.SUB_EXP_CODE, self.PLOT_CODE, self.PLOT_POS) + ftp_filename = os.path.join(figpath, name) + self.saveFigure(figpath, ftp_filename) if x[1] >= self.axesList[0].xmax: self.counter_imagwr = wr_period diff --git a/schainpy/model/graphics/jroplot_spectra.py b/schainpy/model/graphics/jroplot_spectra.py index 4201b03..26b09ac 100644 --- a/schainpy/model/graphics/jroplot_spectra.py +++ b/schainpy/model/graphics/jroplot_spectra.py @@ -1,5 +1,7 @@ ''' -@author: Daniel Suarez +Created on Jul 9, 2014 + +@author: roj-idl71 ''' import os import datetime @@ -33,6 +35,9 @@ class SpectraPlot(Figure): self.SUB_EXP_CODE = None self.PLOT_POS = None + self.__xfilter_ena = False + self.__yfilter_ena = False + def getSubplots(self): ncol = int(numpy.sqrt(self.nplots)+0.9) @@ -76,7 +81,7 @@ class SpectraPlot(Figure): def run(self, dataOut, id, wintitle="", channelList=None, showprofile=True, xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None, - save=False, figpath='', figfile=None, show=True, ftp=False, wr_period=1, + save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1, server=None, folder=None, username=None, password=None, ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0, realtime=False): @@ -96,9 +101,6 @@ class SpectraPlot(Figure): zmax : None """ - if dataOut.flagNoData: - return None - if realtime: if not(isRealtime(utcdatatime = dataOut.utctime)): print 'Skipping this plot function' @@ -120,16 +122,15 @@ class SpectraPlot(Figure): z = dataOut.data_spc[channelIndexList,:,:]/factor z = numpy.where(numpy.isfinite(z), z, numpy.NAN) - avg = numpy.average(z, axis=1) - #avg = numpy.nanmean(z, axis=1) - noise = dataOut.noise/factor - zdB = 10*numpy.log10(z) + + avg = numpy.nanmean(z, axis=1) avgdB = 10*numpy.log10(avg) + + noise = dataOut.getNoise()/factor noisedB = 10*numpy.log10(noise) - #thisDatetime = dataOut.datatime - thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[1]) + thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0]) title = wintitle + " Spectra" if ((dataOut.azimuth!=None) and (dataOut.zenith!=None)): title = title + '_' + 'azimuth,zenith=%2.2f,%2.2f'%(dataOut.azimuth, dataOut.zenith) @@ -151,9 +152,9 @@ class SpectraPlot(Figure): if xmax == None: xmax = numpy.nanmax(x) if ymin == None: ymin = numpy.nanmin(y) if ymax == None: ymax = numpy.nanmax(y) - if zmin == None: zmin = numpy.nanmin(avgdB)*0.9 - if zmax == None: zmax = numpy.nanmax(avgdB)*0.9 - + if zmin == None: zmin = numpy.floor(numpy.nanmin(noisedB)) - 3 + if zmax == None: zmax = numpy.ceil(numpy.nanmax(avgdB)) + 3 + self.FTP_WEI = ftp_wei self.EXP_CODE = exp_code self.SUB_EXP_CODE = sub_exp_code @@ -177,7 +178,7 @@ class SpectraPlot(Figure): if self.__showprofile: axes = self.axesList[i*self.__nsubplots +1] - axes.pline(avgdB[i], y, + axes.pline(avgdB[i,:], y, xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax, xlabel='dB', ylabel='', title='', ytick_visible=False, @@ -187,24 +188,30 @@ class SpectraPlot(Figure): axes.addpline(noiseline, y, idline=1, color="black", linestyle="dashed", lw=2) self.draw() - - if figfile == None: - str_datetime = thisDatetime.strftime("%Y%m%d_%H%M%S") - figfile = self.getFilename(name = str_datetime) - name = str_datetime - if ((dataOut.azimuth!=None) and (dataOut.zenith!=None)): - name = name + '_az' + '_%2.2f'%(dataOut.azimuth) + '_zn' + '_%2.2f'%(dataOut.zenith) - figfile = self.getFilename(name) - if figpath != '': + + if save: + + if figfile == None: + str_datetime = thisDatetime.strftime("%Y%m%d_%H%M%S") + figfile = self.getFilename(name = str_datetime) + name = str_datetime + if ((dataOut.azimuth!=None) and (dataOut.zenith!=None)): + name = name + '_az' + '_%2.2f'%(dataOut.azimuth) + '_zn' + '_%2.2f'%(dataOut.zenith) + figfile = self.getFilename(name) + self.counter_imagwr += 1 + if (self.counter_imagwr>=wr_period): - # store png plot to local folder + # store png plot to local folder self.saveFigure(figpath, figfile) - # store png plot to FTP server according to RT-Web format - name = self.getNameToFtp(thisDatetime, self.FTP_WEI, self.EXP_CODE, self.SUB_EXP_CODE, self.PLOT_CODE, self.PLOT_POS) - ftp_filename = os.path.join(figpath, name) - self.saveFigure(figpath, ftp_filename) self.counter_imagwr = 0 + + if ftp: + # store png plot to FTP server according to RT-Web format + name = self.getNameToFtp(thisDatetime, self.FTP_WEI, self.EXP_CODE, self.SUB_EXP_CODE, self.PLOT_CODE, self.PLOT_POS) + ftp_filename = os.path.join(figpath, name) + self.saveFigure(figpath, ftp_filename) + class CrossSpectraPlot(Figure): @@ -266,7 +273,7 @@ class CrossSpectraPlot(Figure): def run(self, dataOut, id, wintitle="", pairsList=None, xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None, - save=False, figpath='', figfile=None, ftp=False, wr_period=1, + save=False, figpath='./', figfile=None, ftp=False, wr_period=1, power_cmap='jet', coherence_cmap='jet', phase_cmap='RdBu_r', show=True, server=None, folder=None, username=None, password=None, ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0): @@ -293,7 +300,7 @@ class CrossSpectraPlot(Figure): pairsIndexList = [] for pair in pairsList: if pair not in dataOut.pairsList: - raise ValueError, "Pair %s is not in dataOut.pairsList" %(pair) + raise ValueError, "Pair %s is not in dataOut.pairsList" %str(pair) pairsIndexList.append(dataOut.pairsList.index(pair)) if pairsIndexList == []: @@ -305,17 +312,16 @@ class CrossSpectraPlot(Figure): x = dataOut.getVelRange(1) y = dataOut.getHeiRange() z = dataOut.data_spc[:,:,:]/factor -# z = numpy.where(numpy.isfinite(z), z, numpy.NAN) - avg = numpy.abs(numpy.average(z, axis=1)) + z = numpy.where(numpy.isfinite(z), z, numpy.NAN) + noise = dataOut.noise/factor zdB = 10*numpy.log10(z) - avgdB = 10*numpy.log10(avg) noisedB = 10*numpy.log10(noise) #thisDatetime = dataOut.datatime - thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[1]) + thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0]) title = wintitle + " Cross-Spectra: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) xlabel = "Velocity (m/s)" ylabel = "Range (Km)" @@ -330,12 +336,15 @@ class CrossSpectraPlot(Figure): showprofile=False, show=show) + avg = numpy.abs(numpy.average(z, axis=1)) + avgdB = 10*numpy.log10(avg) + if xmin == None: xmin = numpy.nanmin(x) if xmax == None: xmax = numpy.nanmax(x) if ymin == None: ymin = numpy.nanmin(y) if ymax == None: ymax = numpy.nanmax(y) - if zmin == None: zmin = numpy.nanmin(avgdB)*0.9 - if zmax == None: zmax = numpy.nanmax(avgdB)*0.9 + if zmin == None: zmin = numpy.floor(numpy.nanmin(noisedB)) - 3 + if zmax == None: zmax = numpy.ceil(numpy.nanmax(avgdB)) + 3 self.FTP_WEI = ftp_wei self.EXP_CODE = exp_code @@ -388,20 +397,24 @@ class CrossSpectraPlot(Figure): self.draw() - if figfile == None: - str_datetime = thisDatetime.strftime("%Y%m%d_%H%M%S") - figfile = self.getFilename(name = str_datetime) - - if figpath != '': + if save != '': + + if figfile == None: + str_datetime = thisDatetime.strftime("%Y%m%d_%H%M%S") + figfile = self.getFilename(name = str_datetime) + self.counter_imagwr += 1 + if (self.counter_imagwr>=wr_period): - # store png plot to local folder + # store png plot to local folder self.saveFigure(figpath, figfile) - # store png plot to FTP server according to RT-Web format - name = self.getNameToFtp(thisDatetime, self.FTP_WEI, self.EXP_CODE, self.SUB_EXP_CODE, self.PLOT_CODE, self.PLOT_POS) - ftp_filename = os.path.join(figpath, name) - self.saveFigure(figpath, ftp_filename) self.counter_imagwr = 0 + + if ftp: + # store png plot to FTP server according to RT-Web format + name = self.getNameToFtp(thisDatetime, self.FTP_WEI, self.EXP_CODE, self.SUB_EXP_CODE, self.PLOT_CODE, self.PLOT_POS) + ftp_filename = os.path.join(figpath, name) + self.saveFigure(figpath, ftp_filename) class RTIPlot(Figure): @@ -482,7 +495,7 @@ class RTIPlot(Figure): def run(self, dataOut, id, wintitle="", channelList=None, showprofile='True', xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None, timerange=None, - save=False, figpath='', lastone=0,figfile=None, ftp=False, wr_period=1, show=True, + save=False, figpath='./', lastone=0,figfile=None, ftp=False, wr_period=1, show=True, server=None, folder=None, username=None, password=None, ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0): @@ -511,8 +524,8 @@ class RTIPlot(Figure): raise ValueError, "Channel %d is not in dataOut.channelList" channelIndexList.append(dataOut.channelList.index(channel)) - if timerange != None: - self.timerange = timerange +# if timerange != None: +# self.timerange = timerange #tmin = None #tmax = None @@ -528,7 +541,7 @@ class RTIPlot(Figure): # thisDatetime = dataOut.datatime - thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[1]) + thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0]) title = wintitle + " RTI" #: %s" %(thisDatetime.strftime("%d-%b-%Y")) xlabel = "" ylabel = "Range (Km)" @@ -543,18 +556,18 @@ class RTIPlot(Figure): showprofile=showprofile, show=show) - self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange) - -# if timerange != None: -# self.timerange = timerange -# self.xmin, self.tmax = self.getTimeLim(x, xmin, xmax, timerange) + if timerange != None: + self.timerange = timerange + self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange) + noise = dataOut.noise/factor + noisedB = 10*numpy.log10(noise) if ymin == None: ymin = numpy.nanmin(y) if ymax == None: ymax = numpy.nanmax(y) - if zmin == None: zmin = numpy.nanmin(avgdB)*0.9 - if zmax == None: zmax = numpy.nanmax(avgdB)*0.9 + if zmin == None: zmin = numpy.floor(numpy.nanmin(noisedB)) - 3 + if zmax == None: zmax = numpy.ceil(numpy.nanmax(avgdB)) + 3 self.FTP_WEI = ftp_wei self.EXP_CODE = exp_code @@ -591,22 +604,24 @@ class RTIPlot(Figure): self.draw() - if self.figfile == None: - str_datetime = thisDatetime.strftime("%Y%m%d_%H%M%S") - self.figfile = self.getFilename(name = str_datetime) - - if figpath != '': + if save: + + if self.figfile == None: + str_datetime = thisDatetime.strftime("%Y%m%d_%H%M%S") + self.figfile = self.getFilename(name = str_datetime) self.counter_imagwr += 1 + if (self.counter_imagwr>=wr_period): - # store png plot to local folder + # store png plot to local folder self.saveFigure(figpath, self.figfile) - # store png plot to FTP server according to RT-Web format - name = self.getNameToFtp(thisDatetime, self.FTP_WEI, self.EXP_CODE, self.SUB_EXP_CODE, self.PLOT_CODE, self.PLOT_POS) - ftp_filename = os.path.join(figpath, name) - self.saveFigure(figpath, ftp_filename) - self.counter_imagwr = 0 + + if ftp: + # store png plot to FTP server according to RT-Web format + name = self.getNameToFtp(thisDatetime, self.FTP_WEI, self.EXP_CODE, self.SUB_EXP_CODE, self.PLOT_CODE, self.PLOT_POS) + ftp_filename = os.path.join(figpath, name) + self.saveFigure(figpath, ftp_filename) if x[1] >= self.axesList[0].xmax: self.counter_imagwr = wr_period @@ -678,7 +693,7 @@ class CoherenceMap(Figure): def run(self, dataOut, id, wintitle="", pairsList=None, showprofile='True', xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None, timerange=None, - save=False, figpath='', figfile=None, ftp=False, wr_period=1, + save=False, figpath='./', figfile=None, ftp=False, wr_period=1, coherence_cmap='jet', phase_cmap='RdBu_r', show=True, server=None, folder=None, username=None, password=None, ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0): @@ -692,9 +707,6 @@ class CoherenceMap(Figure): raise ValueError, "Pair %s is not in dataOut.pairsList" %(pair) pairsIndexList.append(dataOut.pairsList.index(pair)) - if timerange != None: - self.timerange = timerange - if pairsIndexList == []: return @@ -707,7 +719,7 @@ class CoherenceMap(Figure): y = dataOut.getHeiRange() #thisDatetime = dataOut.datatime - thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[1]) + thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0]) title = wintitle + " CoherenceMap" #: %s" %(thisDatetime.strftime("%d-%b-%Y")) xlabel = "" ylabel = "Range (Km)" @@ -720,7 +732,8 @@ class CoherenceMap(Figure): showprofile=showprofile, show=show) - #tmin, tmax = self.getTimeLim(x, xmin, xmax) + if timerange != None: + self.timerange = timerange self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange) @@ -803,22 +816,24 @@ class CoherenceMap(Figure): self.counter_imagwr = wr_period self.__isConfig = False - if figfile == None: - str_datetime = thisDatetime.strftime("%Y%m%d_%H%M%S") - figfile = self.getFilename(name = str_datetime) - - if figpath != '': - + if save: + + if figfile == None: + str_datetime = thisDatetime.strftime("%Y%m%d_%H%M%S") + figfile = self.getFilename(name = str_datetime) + self.counter_imagwr += 1 + if (self.counter_imagwr>=wr_period): - # store png plot to local folder + # store png plot to local folder self.saveFigure(figpath, figfile) - # store png plot to FTP server according to RT-Web format - name = self.getNameToFtp(thisDatetime, self.FTP_WEI, self.EXP_CODE, self.SUB_EXP_CODE, self.PLOT_CODE, self.PLOT_POS) - ftp_filename = os.path.join(figpath, name) - self.saveFigure(figpath, ftp_filename) - self.counter_imagwr = 0 + + if ftp: + # store png plot to FTP server according to RT-Web format + name = self.getNameToFtp(thisDatetime, self.FTP_WEI, self.EXP_CODE, self.SUB_EXP_CODE, self.PLOT_CODE, self.PLOT_POS) + ftp_filename = os.path.join(figpath, name) + self.saveFigure(figpath, ftp_filename) class PowerProfile(Figure): isConfig = None @@ -864,11 +879,10 @@ class PowerProfile(Figure): def run(self, dataOut, id, wintitle="", channelList=None, xmin=None, xmax=None, ymin=None, ymax=None, - save=False, figpath='', figfile=None, show=True, wr_period=1, - server=None, folder=None, username=None, password=None,): + save=False, figpath='./', figfile=None, show=True, + ftp=False, wr_period=1, server=None, + folder=None, username=None, password=None): - if dataOut.flagNoData: - return None if channelList == None: channelIndexList = dataOut.channelIndexList @@ -880,10 +894,7 @@ class PowerProfile(Figure): raise ValueError, "Channel %d is not in dataOut.channelList" channelIndexList.append(dataOut.channelList.index(channel)) - try: - factor = dataOut.normFactor - except: - factor = 1 + factor = dataOut.normFactor y = dataOut.getHeiRange() @@ -902,7 +913,7 @@ class PowerProfile(Figure): xdB = 10*numpy.log10(x) - thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[1]) + thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0]) title = wintitle + " Power Profile %s" %(thisDatetime.strftime("%d-%b-%Y")) xlabel = "dB" ylabel = "Range (Km)" @@ -919,7 +930,7 @@ class PowerProfile(Figure): if ymin == None: ymin = numpy.nanmin(y) if ymax == None: ymax = numpy.nanmax(y) if xmin == None: xmin = numpy.nanmin(xdB)*0.9 - if xmax == None: xmax = numpy.nanmax(xdB)*0.9 + if xmax == None: xmax = numpy.nanmax(xdB)*1.1 self.__isConfig = True @@ -937,23 +948,19 @@ class PowerProfile(Figure): self.draw() - if figfile == None: - str_datetime = thisDatetime.strftime("%Y%m%d_%H%M%S") - figfile = self.getFilename(name = str_datetime) - - if figpath != '': + if save: + + if figfile == None: + str_datetime = thisDatetime.strftime("%Y%m%d_%H%M%S") + figfile = self.getFilename(name = str_datetime) + self.counter_imagwr += 1 + if (self.counter_imagwr>=wr_period): - # store png plot to local folder + # store png plot to local folder self.saveFigure(figpath, figfile) - # store png plot to FTP server according to RT-Web format - #name = self.getNameToFtp(thisDatetime, self.FTP_WEI, self.EXP_CODE, self.SUB_EXP_CODE, self.PLOT_CODE, self.PLOT_POS) - #ftp_filename = os.path.join(figpath, name) - #self.saveFigure(figpath, ftp_filename) self.counter_imagwr = 0 - - class Noise(Figure): isConfig = None @@ -981,6 +988,9 @@ class Noise(Figure): self.PLOT_POS = None self.figfile = None + self.xmin = None + self.xmax = None + def getSubplots(self): ncol = 1 @@ -1031,7 +1041,7 @@ class Noise(Figure): def run(self, dataOut, id, wintitle="", channelList=None, showprofile='True', xmin=None, xmax=None, ymin=None, ymax=None, timerange=None, - save=False, figpath='', figfile=None, show=True, ftp=False, wr_period=1, + save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1, server=None, folder=None, username=None, password=None, ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0): @@ -1045,19 +1055,14 @@ class Noise(Figure): raise ValueError, "Channel %d is not in dataOut.channelList" channelIndexList.append(dataOut.channelList.index(channel)) - if timerange != None: - self.timerange = timerange - - tmin = None - tmax = None x = dataOut.getTimeRange() - y = dataOut.getHeiRange() + #y = dataOut.getHeiRange() factor = dataOut.normFactor noise = dataOut.noise/factor noisedB = 10*numpy.log10(noise) #thisDatetime = dataOut.datatime - thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[1]) + thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0]) title = wintitle + " Noise" # : %s" %(thisDatetime.strftime("%d-%b-%Y")) xlabel = "" ylabel = "Intensity (dB)" @@ -1072,8 +1077,12 @@ class Noise(Figure): showprofile=showprofile, show=show) - tmin, tmax = self.getTimeLim(x, xmin, xmax) - if ymin == None: ymin = numpy.nanmin(noisedB) - 10.0 + if timerange != None: + self.timerange = timerange + + self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange) + + if ymin == None: ymin = numpy.floor(numpy.nanmin(noisedB)) - 10.0 if ymax == None: ymax = numpy.nanmax(noisedB) + 10.0 self.FTP_WEI = ftp_wei @@ -1116,7 +1125,7 @@ class Noise(Figure): axes.pmultilineyaxis(x=self.xdata, y=self.ydata, - xmin=tmin, xmax=tmax, ymin=ymin, ymax=ymax, + xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels, marker='x', markersize=8, linestyle="solid", XAxisAsTime=True, grid='both' ) @@ -1129,20 +1138,24 @@ class Noise(Figure): del self.ydata self.__isConfig = False - if self.figfile == None: - str_datetime = thisDatetime.strftime("%Y%m%d_%H%M%S") - self.figfile = self.getFilename(name = str_datetime) - - if figpath != '': + if save != '': + + if self.figfile == None: + str_datetime = thisDatetime.strftime("%Y%m%d_%H%M%S") + self.figfile = self.getFilename(name = str_datetime) + self.counter_imagwr += 1 + if (self.counter_imagwr>=wr_period): - # store png plot to local folder + # store png plot to local folder self.saveFigure(figpath, self.figfile) - # store png plot to FTP server according to RT-Web format - name = self.getNameToFtp(thisDatetime, self.FTP_WEI, self.EXP_CODE, self.SUB_EXP_CODE, self.PLOT_CODE, self.PLOT_POS) - ftp_filename = os.path.join(figpath, name) - self.saveFigure(figpath, ftp_filename) self.counter_imagwr = 0 + + if ftp: + # store png plot to FTP server according to RT-Web format + name = self.getNameToFtp(thisDatetime, self.FTP_WEI, self.EXP_CODE, self.SUB_EXP_CODE, self.PLOT_CODE, self.PLOT_POS) + ftp_filename = os.path.join(figpath, name) + self.saveFigure(figpath, ftp_filename) class BeaconPhase(Figure): @@ -1175,6 +1188,9 @@ class BeaconPhase(Figure): self.figfile = None + self.xmin = None + self.xmax = None + def getSubplots(self): ncol = 1 @@ -1224,7 +1240,7 @@ class BeaconPhase(Figure): def run(self, dataOut, id, wintitle="", pairsList=None, showprofile='True', xmin=None, xmax=None, ymin=None, ymax=None, timerange=None, - save=False, figpath='', figfile=None, show=True, ftp=False, wr_period=1, + save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1, server=None, folder=None, username=None, password=None, ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0): @@ -1242,18 +1258,13 @@ class BeaconPhase(Figure): # if len(pairsIndexList) > 4: # pairsIndexList = pairsIndexList[0:4] - - if timerange != None: - self.timerange = timerange - tmin = None - tmax = None x = dataOut.getTimeRange() - y = dataOut.getHeiRange() + #y = dataOut.getHeiRange() #thisDatetime = dataOut.datatime - thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[1]) + thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0]) title = wintitle + " Phase of Beacon Signal" # : %s" %(thisDatetime.strftime("%d-%b-%Y")) xlabel = "Local Time" ylabel = "Phase" @@ -1284,7 +1295,11 @@ class BeaconPhase(Figure): showprofile=showprofile, show=show) - tmin, tmax = self.getTimeLim(x, xmin, xmax) + if timerange != None: + self.timerange = timerange + + self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange) + if ymin == None: ymin = numpy.nanmin(phase_beacon) - 10.0 if ymax == None: ymax = numpy.nanmax(phase_beacon) + 10.0 @@ -1327,7 +1342,7 @@ class BeaconPhase(Figure): axes.pmultilineyaxis(x=self.xdata, y=self.ydata, - xmin=tmin, xmax=tmax, ymin=ymin, ymax=ymax, + xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels, marker='x', markersize=8, linestyle="solid", XAxisAsTime=True, grid='both' ) @@ -1340,17 +1355,21 @@ class BeaconPhase(Figure): del self.ydata self.__isConfig = False - if self.figfile == None: - str_datetime = thisDatetime.strftime("%Y%m%d_%H%M%S") - self.figfile = self.getFilename(name = str_datetime) - - if figpath != '': + if save: + + if self.figfile == None: + str_datetime = thisDatetime.strftime("%Y%m%d_%H%M%S") + self.figfile = self.getFilename(name = str_datetime) + self.counter_imagwr += 1 + if (self.counter_imagwr>=wr_period): - # store png plot to local folder + # store png plot to local folder self.saveFigure(figpath, self.figfile) - # store png plot to FTP server according to RT-Web format - name = self.getNameToFtp(thisDatetime, self.FTP_WEI, self.EXP_CODE, self.SUB_EXP_CODE, self.PLOT_CODE, self.PLOT_POS) - ftp_filename = os.path.join(figpath, name) - self.saveFigure(figpath, ftp_filename) self.counter_imagwr = 0 + + if ftp: + # store png plot to FTP server according to RT-Web format + name = self.getNameToFtp(thisDatetime, self.FTP_WEI, self.EXP_CODE, self.SUB_EXP_CODE, self.PLOT_CODE, self.PLOT_POS) + ftp_filename = os.path.join(figpath, name) + self.saveFigure(figpath, ftp_filename) diff --git a/schainpy/model/graphics/jroplot_voltage.py b/schainpy/model/graphics/jroplot_voltage.py index 4860eb2..2fcc09e 100644 --- a/schainpy/model/graphics/jroplot_voltage.py +++ b/schainpy/model/graphics/jroplot_voltage.py @@ -1,7 +1,9 @@ ''' -@author: Daniel Suarez -''' +Created on Jul 9, 2014 +@author: roj-idl71 +''' +import os import datetime import numpy @@ -111,7 +113,7 @@ class Scope(Figure): def run(self, dataOut, id, wintitle="", channelList=None, xmin=None, xmax=None, ymin=None, ymax=None, save=False, figpath='./', figfile=None, show=True, wr_period=1, - server=None, folder=None, username=None, password=None, type='power'): + ftp=False, server=None, folder=None, username=None, password=None, type='power'): """ @@ -125,8 +127,6 @@ class Scope(Figure): ymin : None, ymax : None, """ - if dataOut.flagNoData: - return None if channelList == None: channelIndexList = dataOut.channelIndexList @@ -141,7 +141,7 @@ class Scope(Figure): y = dataOut.data[channelIndexList,:] * numpy.conjugate(dataOut.data[channelIndexList,:]) y = y.real - thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[1]) + thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0]) if type == "power": self.plot_power(dataOut.heightList, diff --git a/schainpy/model/graphics/mpldriver.py b/schainpy/model/graphics/mpldriver.py index a8b1e3d..97306d9 100644 --- a/schainpy/model/graphics/mpldriver.py +++ b/schainpy/model/graphics/mpldriver.py @@ -216,11 +216,8 @@ def createPcolor(ax, x, y, z, xmin, xmax, ymin, ymax, zmin, zmax, def pcolor(imesh, z, xlabel='', ylabel='', title=''): z = z.T - ax = imesh.get_axes() - printLabels(ax, xlabel, ylabel, title) - imesh.set_array(z.ravel()) def addpcolor(ax, x, y, z, zmin, zmax, xlabel='', ylabel='', title='', colormap='jet'): diff --git a/schainpy/model/io/__init__.py b/schainpy/model/io/__init__.py index e69de29..93f0ed6 100644 --- a/schainpy/model/io/__init__.py +++ b/schainpy/model/io/__init__.py @@ -0,0 +1,30 @@ +''' + +$Author: murco $ +$Id: JRODataIO.py 169 2012-11-19 21:57:03Z murco $ +''' + +from jroIO_voltage import * +from jroIO_spectra import * +from jroIO_heispectra import * +from jroIO_usrp import * + +try: + from jroIO_usrp_api import * +except: + print "jroIO_usrp_api could not be imported" + +try: + from jroIO_amisr import * +except: + print "jroIO_amisr could not be imported" + +try: + from jroIO_HDF5 import * +except: + print "jroIO_HDF5 could not be imported" + +try: + from jroIO_hf import * +except: + print "jroIO_hf could not be imported" \ No newline at end of file diff --git a/schainpy/model/io/jroIO_HDF5.py b/schainpy/model/io/jroIO_HDF5.py index 78e280b..cfd195f 100644 --- a/schainpy/model/io/jroIO_HDF5.py +++ b/schainpy/model/io/jroIO_HDF5.py @@ -4,9 +4,9 @@ import os import h5py import re -from model.data.jrodata import * -from model.proc.jroproc_base import ProcessingUnit, Operation -from model.io.jroIO_base import * +from schainpy.model.data.jrodata import * +from schainpy.model.proc.jroproc_base import ProcessingUnit, Operation +from schainpy.model.io.jroIO_base import * class HDF5Reader(ProcessingUnit): diff --git a/schainpy/model/io/jroIO_amisr.py b/schainpy/model/io/jroIO_amisr.py index adb7a9b..edb45e4 100644 --- a/schainpy/model/io/jroIO_amisr.py +++ b/schainpy/model/io/jroIO_amisr.py @@ -12,8 +12,8 @@ import re import h5py import numpy -from model.proc.jroproc_base import ProcessingUnit, Operation -from model.data.jroamisr import AMISR +from schainpy.model.proc.jroproc_base import ProcessingUnit, Operation +from schainpy.model.data.jroamisr import AMISR class RadacHeader(): def __init__(self, fp): diff --git a/schainpy/model/io/jroIO_base.py b/schainpy/model/io/jroIO_base.py index 3681fe8..f706f76 100644 --- a/schainpy/model/io/jroIO_base.py +++ b/schainpy/model/io/jroIO_base.py @@ -1,5 +1,7 @@ ''' +Created on Jul 2, 2014 +@author: roj-idl71 ''' import os import sys @@ -11,24 +13,16 @@ import time, datetime #import h5py import traceback -#try: -# import pyfits -#except: -# print "pyfits module has not been imported, it should be installed to save files in fits format" - -#from jrodata import * -#from jroheaderIO import * -#from jroprocessing import * - -#import re -#from xml.etree.ElementTree import Element, SubElement, ElementTree - - -LOCALTIME = True #-18000 +try: + from gevent import sleep +except: + from time import sleep + +from schainpy.model.data.jroheaderIO import PROCFLAG, BasicHeader, SystemHeader, RadarControllerHeader, ProcessingHeader -from model.data.jroheaderIO import PROCFLAG, BasicHeader, SystemHeader, RadarControllerHeader, ProcessingHeader +LOCALTIME = True -def isNumber(str): +def isNumber(cad): """ Chequea si el conjunto de caracteres que componen un string puede ser convertidos a un numero. @@ -42,7 +36,7 @@ def isNumber(str): False : no es un string numerico """ try: - float( str ) + float( cad ) return True except: return False @@ -308,7 +302,7 @@ class JRODataIO: flagIsNewFile = 1 - flagTimeBlock = 0 + flagDiscontinuousBlock = 0 flagIsNewBlock = 0 @@ -469,7 +463,6 @@ class JRODataReader(JRODataIO): fileList = glob.glob1(thisPath, "*%s" %ext) if len(fileList) < 1: continue - fileList.sort() pathDict.setdefault(fileList[0]) pathDict[fileList[0]] = i @@ -658,7 +651,7 @@ class JRODataReader(JRODataIO): for nTries in range( tries ): if firstTime_flag: print "\tWaiting %0.2f sec for the file \"%s\" , try %03d ..." % ( self.delay, filename, nTries+1 ) - time.sleep( self.delay ) + sleep( self.delay ) else: print "\tSearching next \"%s%04d%03d%03d%s\" file ..." % (self.optchar, self.year, self.doy, self.set, self.ext) @@ -748,8 +741,8 @@ class JRODataReader(JRODataIO): # self.flagEoF = True return 0 - print "\tWaiting %0.2f seconds for the next block, try %03d ..." % (self.delay, nTries+1) - time.sleep( self.delay ) + print "[Reading] Waiting %0.2f seconds for the next block, try %03d ..." % (self.delay, nTries+1) + sleep( self.delay ) return 0 @@ -771,8 +764,8 @@ class JRODataReader(JRODataIO): if ( currentSize >= neededSize ): return 1 - print "\tWaiting %0.2f seconds for the next block, try %03d ..." % (self.delay, nTries+1) - time.sleep( self.delay ) + print "[Reading] Waiting %0.2f seconds for the next block, try %03d ..." % (self.delay, nTries+1) + sleep( self.delay ) return 0 @@ -836,10 +829,10 @@ class JRODataReader(JRODataIO): deltaTime = self.basicHeaderObj.utc - self.lastUTTime # - self.flagTimeBlock = 0 + self.flagDiscontinuousBlock = 0 if deltaTime > self.maxTimeStep: - self.flagTimeBlock = 1 + self.flagDiscontinuousBlock = 1 return 1 @@ -892,7 +885,7 @@ class JRODataReader(JRODataIO): except IOError: traceback.print_exc() if msgFlag: - print "The file %s can't be opened" % (filename) + print "[Reading] The file %s can't be opened" % (filename) return False neededSize = self.processingHeaderObj.blockSize + self.firstHeaderSize @@ -915,12 +908,12 @@ class JRODataReader(JRODataIO): except IOError: traceback.print_exc() if msgFlag: - print "\tThe file %s is empty or it hasn't enough data" % filename + print "[Reading] The file %s is empty or it hasn't enough data" % filename fp.close() return False else: - msg = "\tSkipping the file %s due to it hasn't enough data" %filename + msg = "[Reading] Skipping the file %s due to it hasn't enough data" %filename fp.close() fileSize = os.path.getsize(filename) @@ -948,13 +941,13 @@ class JRODataReader(JRODataIO): nTxs = 1): if path == None: - raise ValueError, "The path is not valid" + raise ValueError, "[Reading] The path is not valid" if ext == None: ext = self.ext if online: - print "Searching files in online mode..." + print "[Reading] Searching files in online mode..." for nTries in range( self.nTries ): fullpath, foldercounter, file, year, doy, set = self.__searchFilesOnLine(path=path, expLabel=expLabel, ext=ext, walk=walk, set=set) @@ -962,11 +955,11 @@ class JRODataReader(JRODataIO): if fullpath: break - print '\tWaiting %0.2f sec for an valid file in %s: try %02d ...' % (self.delay, path, nTries+1) - time.sleep( self.delay ) + print '[Reading] Waiting %0.2f sec for an valid file in %s: try %02d ...' % (self.delay, path, nTries+1) + sleep( self.delay ) if not(fullpath): - print "There 'isn't valied files in %s" % path + print "There 'isn't any valid file in %s" % path return None self.year = year @@ -977,14 +970,14 @@ class JRODataReader(JRODataIO): last_set = None else: - print "Searching files in offline mode ..." + print "[Reading] Searching files in offline mode ..." pathList, filenameList = self.__searchFilesOffLine(path, startDate=startDate, endDate=endDate, startTime=startTime, endTime=endTime, set=set, expLabel=expLabel, ext=ext, walk=walk) if not(pathList): - print "No *%s files into the folder %s \nfor the range: %s - %s"%(ext, path, + print "[Reading] No *%s files into the folder %s \nfor the range: %s - %s"%(ext, path, datetime.datetime.combine(startDate,startTime).ctime(), datetime.datetime.combine(endDate,endTime).ctime()) @@ -1007,11 +1000,11 @@ class JRODataReader(JRODataIO): if not(self.setNextFile()): if (startDate!=None) and (endDate!=None): - print "No files in range: %s - %s" %(datetime.datetime.combine(startDate,startTime).ctime(), datetime.datetime.combine(endDate,endTime).ctime()) + print "[Reading] No files in range: %s - %s" %(datetime.datetime.combine(startDate,startTime).ctime(), datetime.datetime.combine(endDate,endTime).ctime()) elif startDate != None: - print "No files in range: %s" %(datetime.datetime.combine(startDate,startTime).ctime()) + print "[Reading] No files in range: %s" %(datetime.datetime.combine(startDate,startTime).ctime()) else: - print "No files" + print "[Reading] No files" sys.exit(-1) @@ -1024,7 +1017,7 @@ class JRODataReader(JRODataIO): self.dataOut.utctime = self.basicHeaderObj.utc + self.basicHeaderObj.miliSecond/1000. + self.profileIndex * self.radarControllerHeaderObj.ippSeconds - self.dataOut.flagTimeBlock = self.flagTimeBlock + self.dataOut.flagDiscontinuousBlock = self.flagDiscontinuousBlock self.dataOut.timeZone = self.basicHeaderObj.timeZone @@ -1061,16 +1054,16 @@ class JRODataReader(JRODataIO): def printReadBlocks(self): - print "Number of read blocks per file %04d" %self.nReadBlocks + print "[Reading] Number of read blocks per file %04d" %self.nReadBlocks def printTotalBlocks(self): - print "Number of read blocks %04d" %self.nTotalBlocks + print "[Reading] Number of read blocks %04d" %self.nTotalBlocks def printNumberOfBlock(self): if self.flagIsNewBlock: - print "Block No. %04d, Total blocks %04d -> %s" %(self.basicHeaderObj.dataBlock, self.nTotalBlocks, self.dataOut.datatime.ctime()) + print "[Reading] Block No. %04d, Total blocks %04d -> %s" %(self.basicHeaderObj.dataBlock, self.nTotalBlocks, self.dataOut.datatime.ctime()) self.dataOut.blocknow = self.basicHeaderObj.dataBlock def printInfo(self): @@ -1275,13 +1268,13 @@ class JRODataWriter(JRODataIO): setFile = self.setFile setFile += 1 - file = '%s%4.4d%3.3d%3.3d%s' % (self.optchar, + filen = '%s%4.4d%3.3d%3.3d%s' % (self.optchar, timeTuple.tm_year, timeTuple.tm_yday, setFile, ext ) - filename = os.path.join( path, subfolder, file ) + filename = os.path.join( path, subfolder, filen ) fp = open( filename,'wb' ) @@ -1296,7 +1289,7 @@ class JRODataWriter(JRODataIO): self.setFirstHeader() - print 'Writing the file: %s'%self.filename + print '[Writing] file: %s'%self.filename self.__writeFirstHeader() @@ -1334,7 +1327,7 @@ class JRODataWriter(JRODataIO): self.dataOut = dataOut if not(self.setNextFile()): - print "There isn't a next file" + print "[Writing] There isn't a next file" return 0 self.setBlockDimension() diff --git a/schainpy/model/io/jroIO_example.py b/schainpy/model/io/jroIO_example.py index a26a393..e97f4b6 100644 --- a/schainpy/model/io/jroIO_example.py +++ b/schainpy/model/io/jroIO_example.py @@ -21,10 +21,6 @@ class Reader(ProcessingUnit): ProcessingUnit.__init__(self) -# self.dataIn = None -# -# self.isConfig = False - #Is really necessary create the output object in the initializer self.dataOut = Voltage() @@ -44,6 +40,10 @@ class Reader(ProcessingUnit): ''' + ''' + Add code + ''' + self.isConfig = True def run(self, **kwargs): @@ -54,6 +54,10 @@ class Reader(ProcessingUnit): if not self.isConfig: self.setup(**kwargs) + ''' + Add code + ''' + class Writer(Operation): ''' classdocs diff --git a/schainpy/model/io/jroIO_heispectra.py b/schainpy/model/io/jroIO_heispectra.py index e439075..addaea8 100644 --- a/schainpy/model/io/jroIO_heispectra.py +++ b/schainpy/model/io/jroIO_heispectra.py @@ -1,5 +1,7 @@ ''' +Created on Jul 3, 2014 +@author: roj-idl71 ''' import os, sys @@ -9,15 +11,84 @@ import fnmatch import glob try: + from gevent import sleep +except: + from time import sleep + +try: import pyfits except: """ """ - + from xml.etree.ElementTree import ElementTree from jroIO_base import isDoyFolder, isNumber -from model.proc.jroproc_base import Operation, ProcessingUnit +from schainpy.model.proc.jroproc_base import Operation, ProcessingUnit + +class Fits: + name=None + format=None + array =None + data =None + thdulist=None + prihdr=None + hdu=None + + def __init__(self): + + pass + + def setColF(self,name,format,array): + self.name=name + self.format=format + self.array=array + a1=numpy.array([self.array],dtype=numpy.float32) + self.col1 = pyfits.Column(name=self.name, format=self.format, array=a1) + return self.col1 + +# def setColP(self,name,format,data): +# self.name=name +# self.format=format +# self.data=data +# a2=numpy.array([self.data],dtype=numpy.float32) +# self.col2 = pyfits.Column(name=self.name, format=self.format, array=a2) +# return self.col2 + + + def writeData(self,name,format,data): + self.name=name + self.format=format + self.data=data + a2=numpy.array([self.data],dtype=numpy.float32) + self.col2 = pyfits.Column(name=self.name, format=self.format, array=a2) + return self.col2 + + def cFImage(self,idblock,year,month,day,hour,minute,second): + self.hdu= pyfits.PrimaryHDU(idblock) + self.hdu.header.set("Year",year) + self.hdu.header.set("Month",month) + self.hdu.header.set("Day",day) + self.hdu.header.set("Hour",hour) + self.hdu.header.set("Minute",minute) + self.hdu.header.set("Second",second) + return self.hdu + + + def Ctable(self,colList): + self.cols=pyfits.ColDefs(colList) + self.tbhdu = pyfits.new_table(self.cols) + return self.tbhdu + + + def CFile(self,hdu,tbhdu): + self.thdulist=pyfits.HDUList([hdu,tbhdu]) + + def wFile(self,filename): + if os.path.isfile(filename): + os.remove(filename) + self.thdulist.writeto(filename) + class ParameterConf: ELEMENTNAME = 'Parameter' @@ -165,13 +236,13 @@ class FitsWriter(Operation): setFile = self.setFile setFile += 1 - file = '%s%4.4d%3.3d%3.3d%s' % (self.optchar, + thisFile = '%s%4.4d%3.3d%3.3d%s' % (self.optchar, timeTuple.tm_year, timeTuple.tm_yday, setFile, ext ) - filename = os.path.join( path, subfolder, file ) + filename = os.path.join( path, subfolder, thisFile ) self.blockIndex = 0 self.filename = filename @@ -242,7 +313,7 @@ class FitsReader(ProcessingUnit): self.setFile = 0 self.flagNoMoreFiles = 0 self.flagIsNewFile = 1 - self.flagTimeBlock = None + self.flagDiscontinuousBlock = None self.fileIndex = None self.filename = None self.fileSize = None @@ -432,9 +503,9 @@ class FitsReader(ProcessingUnit): fileList = glob.glob1(thisPath, "*%s" %ext) fileList.sort() - for file in fileList: + for thisFile in fileList: - filename = os.path.join(thisPath,file) + filename = os.path.join(thisPath,thisFile) thisDatetime = self.isFileinThisTime(filename, startTime, endTime) if not(thisDatetime): @@ -558,7 +629,7 @@ class FitsReader(ProcessingUnit): return 1 print "\tWaiting %0.2f seconds for the next block, try %03d ..." % (self.delay, nTries+1) - time.sleep( self.delay ) + sleep( self.delay ) return 0 @@ -585,10 +656,10 @@ class FitsReader(ProcessingUnit): deltaTime = self.utc - self.lastUTTime - self.flagTimeBlock = 0 + self.flagDiscontinuousBlock = 0 if deltaTime > self.maxTimeStep: - self.flagTimeBlock = 1 + self.flagDiscontinuousBlock = 1 return 1 @@ -610,7 +681,7 @@ class FitsReader(ProcessingUnit): print 'Process finished' return 0 - self.flagTimeBlock = 0 + self.flagDiscontinuousBlock = 0 self.flagIsNewBlock = 0 if not(self.readNextBlock()): @@ -653,7 +724,7 @@ class SpectraHeisWriter(Operation): subfolder = None def __init__(self): - self.wrObj = FITS() + self.wrObj = Fits() # self.dataOut = dataOut self.nTotalBlocks=0 # self.set = None @@ -709,9 +780,9 @@ class SpectraHeisWriter(Operation): # self.setFile = 0 #make the filename - file = 'D%4.4d%3.3d_%3.3d%s' % (name.tm_year,name.tm_yday,self.setFile,ext) + thisFile = 'D%4.4d%3.3d_%3.3d%s' % (name.tm_year,name.tm_yday,self.setFile,ext) - filename = os.path.join(self.wrpath,self.subfolder, file) + filename = os.path.join(self.wrpath,self.subfolder, thisFile) idblock = numpy.array([self.idblock],dtype="int64") header=self.wrObj.cFImage(idblock=idblock, diff --git a/schainpy/model/io/jroIO_spectra.py b/schainpy/model/io/jroIO_spectra.py index 1b60216..1a99839 100644 --- a/schainpy/model/io/jroIO_spectra.py +++ b/schainpy/model/io/jroIO_spectra.py @@ -1,12 +1,14 @@ ''' -''' +Created on Jul 2, 2014 +@author: roj-idl71 +''' import numpy from jroIO_base import LOCALTIME, JRODataReader, JRODataWriter -from model.proc.jroproc_base import ProcessingUnit, Operation -from model.data.jroheaderIO import PROCFLAG, BasicHeader, SystemHeader, RadarControllerHeader, ProcessingHeader -from model.data.jrodata import Spectra +from schainpy.model.proc.jroproc_base import ProcessingUnit, Operation +from schainpy.model.data.jroheaderIO import PROCFLAG, BasicHeader, SystemHeader, RadarControllerHeader, ProcessingHeader +from schainpy.model.data.jrodata import Spectra class SpectraReader(JRODataReader, ProcessingUnit): """ @@ -158,7 +160,7 @@ class SpectraReader(JRODataReader, ProcessingUnit): # self.ippSeconds = 0 - self.flagTimeBlock = 0 + self.flagDiscontinuousBlock = 0 self.flagIsNewBlock = 0 @@ -328,15 +330,15 @@ class SpectraReader(JRODataReader, ProcessingUnit): self.dataOut.flagDecodeData = False #asumo q la data no esta decodificada - self.dataOut.flagDeflipData = True #asumo q la data no esta sin flip + self.dataOut.flagDeflipData = False #asumo q la data esta sin flip if self.radarControllerHeaderObj.code != None: - self.dataOut.nCode = self.radarControllerHeaderObj.nCode - - self.dataOut.nBaud = self.radarControllerHeaderObj.nBaud - - self.dataOut.code = self.radarControllerHeaderObj.code +# self.dataOut.nCode = self.radarControllerHeaderObj.nCode +# +# self.dataOut.nBaud = self.radarControllerHeaderObj.nBaud +# +# self.dataOut.code = self.radarControllerHeaderObj.code self.dataOut.flagDecodeData = True @@ -355,7 +357,7 @@ class SpectraReader(JRODataReader, ProcessingUnit): Affected: self.dataOut - self.flagTimeBlock + self.flagDiscontinuousBlock self.flagIsNewBlock """ @@ -364,7 +366,7 @@ class SpectraReader(JRODataReader, ProcessingUnit): print 'Process finished' return 0 - self.flagTimeBlock = 0 + self.flagDiscontinuousBlock = 0 self.flagIsNewBlock = 0 if self.__hasNotDataInBuffer(): @@ -555,6 +557,7 @@ class SpectraWriter(JRODataWriter, Operation): self.nWriteBlocks += 1 self.blockIndex += 1 + print "[Writing] Block = ", self.blockIndex def putData(self): """ @@ -575,7 +578,7 @@ class SpectraWriter(JRODataWriter, Operation): self.flagIsNewBlock = 0 - if self.dataOut.flagTimeBlock: + if self.dataOut.flagDiscontinuousBlock: self.data_spc.fill(0) self.data_cspc.fill(0) self.data_dc.fill(0) diff --git a/schainpy/model/io/jroIO_usrp.py b/schainpy/model/io/jroIO_usrp.py new file mode 100644 index 0000000..a38cb3d --- /dev/null +++ b/schainpy/model/io/jroIO_usrp.py @@ -0,0 +1,517 @@ +''' +Created on Jul 3, 2014 + +@author: roj-idl71 +''' +import datetime +import numpy + +try: + from gevent import sleep +except: + from time import sleep + +from schainpy.model.data.jroheaderIO import RadarControllerHeader, SystemHeader +from schainpy.model.data.jrodata import Voltage +from schainpy.model.proc.jroproc_base import ProcessingUnit, Operation + +try: + import digital_rf_hdf5 +except: + print 'You should install "digital_rf_hdf5" module if you want to read USRP data' + +class USRPReader(ProcessingUnit): + ''' + classdocs + ''' + + def __init__(self): + ''' + Constructor + ''' + + ProcessingUnit.__init__(self) + + self.dataOut = Voltage() + self.__printInfo = True + self.__flagDiscontinuousBlock = False + self.__bufferIndex = 9999999 + + self.__ippKm = None + self.__codeType = 0 + self.__nCode = None + self.__nBaud = None + self.__code = None + + def __getCurrentSecond(self): + + return self.__thisUnixSample/self.__sample_rate + + thisSecond = property(__getCurrentSecond, "I'm the 'thisSecond' property.") + + def __setFileHeader(self): + ''' + In this method will be initialized every parameter of dataOut object (header, no data) + ''' + + self.dataOut.radarControllerHeaderObj = RadarControllerHeader(ippKm=self.__ippKm, + txA=0, + txB=0, + nWindows=1, + nHeights=self.__nSamples, + firstHeight=self.__firstHeigth, + deltaHeight=self.__deltaHeigth, + codeType=self.__codeType, + nCode=self.__nCode, nBaud=self.__nBaud, + code = self.__code) + + self.dataOut.systemHeaderObj = SystemHeader(nSamples=self.__nSamples, + nProfiles=1024, + nChannels=len(self.__channelList), + adcResolution=14) + + self.dataOut.type = "Voltage" + + self.dataOut.data = None + + self.dataOut.dtype = numpy.dtype([('real',' startUTCSecond*self.__sample_rate: + startUTCSecond = start_index/self.__sample_rate + + if not endUTCSecond: + endUTCSecond = end_index/self.__sample_rate + + if end_index < endUTCSecond*self.__sample_rate: + endUTCSecond = end_index/self.__sample_rate + + if not nSamples: + if not ippKm: + raise ValueError, "[Reading] nSamples or ippKm should be defined" + + nSamples = ippKm / (1e6*0.15/self.__sample_rate) + + channelBoundList = [] + channelNameListFiltered = [] + + for thisIndexChannel in channelList: + thisChannelName = channelNameList[thisIndexChannel] + start_index, end_index = self.digitalReadObj.get_bounds(thisChannelName) + channelBoundList.append((start_index, end_index)) + channelNameListFiltered.append(thisChannelName) + + self.profileIndex = 0 + + self.__ippKm = ippKm + self.__codeType = codeType + self.__nCode = nCode + self.__nBaud = nBaud + self.__code = code + + self.__datapath = path + self.__online = online + self.__channelList = channelList + self.__channelNameList = channelNameListFiltered + self.__channelBoundList = channelBoundList + self.__nSamples = nSamples + self.__samples_to_read = nbuffer*nSamples + self.__nChannels = len(self.__channelList) + + self.__startUTCSecond = startUTCSecond + self.__endUTCSecond = endUTCSecond + + self.__timeInterval = 1.0 * self.__samples_to_read/self.__sample_rate #Time interval + + if online: +# self.__thisUnixSample = int(endUTCSecond*self.__sample_rate - 4*self.__samples_to_read) + startUTCSecond = numpy.floor(endUTCSecond) + + self.__thisUnixSample = int(startUTCSecond*self.__sample_rate) - self.__samples_to_read + + self.__data_buffer = numpy.zeros((self.__nChannels, self.__samples_to_read), dtype = numpy.complex) + + self.__setFileHeader() + self.isConfig = True + + print "[Reading] USRP Data was found from %s to %s " %( + datetime.datetime.utcfromtimestamp(self.__startUTCSecond - self.__timezone), + datetime.datetime.utcfromtimestamp(self.__endUTCSecond - self.__timezone) + ) + + print "[Reading] Starting process from ", datetime.datetime.utcfromtimestamp(startUTCSecond - self.__timezone), " to ", datetime.datetime.utcfromtimestamp(endUTCSecond - self.__timezone) + + def __reload(self): + + if not self.__online: + return + +# print +# print "%s not in range [%s, %s]" %( +# datetime.datetime.utcfromtimestamp(self.thisSecond - self.__timezone), +# datetime.datetime.utcfromtimestamp(self.__startUTCSecond - self.__timezone), +# datetime.datetime.utcfromtimestamp(self.__endUTCSecond - self.__timezone) +# ) + print "[Reading] reloading metadata ..." + + self.digitalReadObj.reload(complete_update=True) + + start_index, end_index = self.digitalReadObj.get_bounds(self.__channelNameList[self.__channelList[0]]) + + if start_index > self.__startUTCSecond*self.__sample_rate: + self.__startUTCSecond = 1.0*start_index/self.__sample_rate + + if end_index > self.__endUTCSecond*self.__sample_rate: + self.__endUTCSecond = 1.0*end_index/self.__sample_rate + print + print "[Reading] New timerange found [%s, %s] " %( + datetime.datetime.utcfromtimestamp(self.__startUTCSecond - self.__timezone), + datetime.datetime.utcfromtimestamp(self.__endUTCSecond - self.__timezone) + ) + + return True + + return False + + def __readNextBlock(self, seconds=30, volt_scale = 218776): + ''' + ''' + + #Set the next data + self.__flagDiscontinuousBlock = False + self.__thisUnixSample += self.__samples_to_read + + if self.__thisUnixSample + 2*self.__samples_to_read > self.__endUTCSecond*self.__sample_rate: + print "[Reading] There are no more data into selected timerange" + + self.__reload() + + if self.__thisUnixSample + 2*self.__samples_to_read > self.__endUTCSecond*self.__sample_rate: + self.__thisUnixSample -= self.__samples_to_read + return False + + indexChannel = 0 + + dataOk = False + + for thisChannelName in self.__channelNameList: + + try: + result = self.digitalReadObj.read_vector_c81d(self.__thisUnixSample, + self.__samples_to_read, + thisChannelName) + + except IOError, e: + #read next profile + self.__flagDiscontinuousBlock = True + print e + break + + if result.shape[0] != self.__samples_to_read: + self.__flagDiscontinuousBlock = True + print "[Reading] %s: Too few samples were found, just %d samples" %(datetime.datetime.utcfromtimestamp(self.thisSecond - self.__timezone), + result.shape[0]) + break + + self.__data_buffer[indexChannel,:] = result*volt_scale + + indexChannel += 1 + + dataOk = True + + self.__utctime = self.__thisUnixSample/self.__sample_rate + + if not dataOk: + return False + + print "[Reading] %s: %d samples <> %f sec" %(datetime.datetime.utcfromtimestamp(self.thisSecond - self.__timezone), + self.__samples_to_read, + self.__timeInterval) + + self.__bufferIndex = 0 + + return True + + def __isBufferEmpty(self): + + if self.__bufferIndex <= self.__samples_to_read - self.__nSamples: + return False + + return True + + def getData(self, seconds=30, nTries=5): + + ''' + This method gets the data from files and put the data into the dataOut object + + In addition, increase el the buffer counter in one. + + Return: + data : retorna un perfil de voltages (alturas * canales) copiados desde el + buffer. Si no hay mas archivos a leer retorna None. + + Affected: + self.dataOut + self.profileIndex + self.flagDiscontinuousBlock + self.flagIsNewBlock + ''' + + err_counter = 0 + self.dataOut.flagNoData = True + + if self.__isBufferEmpty(): + + self.__flagDiscontinuousBlock = False + + while True: + if self.__readNextBlock(): + break + + if self.__thisUnixSample > self.__endUTCSecond*self.__sample_rate: + return False + + if self.__flagDiscontinuousBlock: + print '[Reading] discontinuous block found ... continue with the next block' + continue + + if not self.__online: + return False + + err_counter += 1 + if err_counter > nTries: + return False + + print '[Reading] waiting %d seconds to read a new block' %seconds + sleep(seconds) + + self.dataOut.data = self.__data_buffer[:,self.__bufferIndex:self.__bufferIndex+self.__nSamples] + self.dataOut.utctime = (self.__thisUnixSample + self.__bufferIndex)/self.__sample_rate + self.dataOut.flagNoData = False + self.dataOut.flagDiscontinuousBlock = self.__flagDiscontinuousBlock + + self.__bufferIndex += self.__nSamples + self.profileIndex += 1 + + return True + + def printInfo(self): + ''' + ''' + if self.__printInfo == False: + return + +# self.systemHeaderObj.printInfo() +# self.radarControllerHeaderObj.printInfo() + + self.__printInfo = False + + def printNumberOfBlock(self): + ''' + ''' + + print self.profileIndex + + def run(self, **kwargs): + ''' + This method will be called many times so here you should put all your code + ''' + + if not self.isConfig: + self.setup(**kwargs) + + self.getData() + + return + +class USRPWriter(Operation): + ''' + classdocs + ''' + + def __init__(self): + ''' + Constructor + ''' + self.dataOut = None + + def setup(self, dataIn, path, blocksPerFile, set=0, ext=None): + ''' + In this method we should set all initial parameters. + + Input: + dataIn : Input data will also be outputa data + + ''' + self.dataOut = dataIn + + + + + + self.isConfig = True + + return + + def run(self, dataIn, **kwargs): + ''' + This method will be called many times so here you should put all your code + + Inputs: + + dataIn : object with the data + + ''' + + if not self.isConfig: + self.setup(dataIn, **kwargs) + + +if __name__ == '__main__': + + readObj = USRPReader() + + while True: + readObj.run(path='/Volumes/DATA/haystack/passive_radar/') +# readObj.printInfo() + readObj.printNumberOfBlock() + + \ No newline at end of file diff --git a/schainpy/model/io/jroIO_usrp_api.py b/schainpy/model/io/jroIO_usrp_api.py new file mode 100644 index 0000000..ab9c0ca --- /dev/null +++ b/schainpy/model/io/jroIO_usrp_api.py @@ -0,0 +1,135 @@ +''' +Created on Jul 15, 2014 + +@author: roj-idl71 +''' +import time +import threading +import cPickle + +try: + from gevent import sleep +except: + from time import sleep + +SERIALIZER = cPickle + +# from schainpy.serializer import DynamicSerializer +from schainpy.model.io.jroIO_usrp import USRPReader +from schainpy.serializer.DataTranslate import obj2Serial + +class USRPReaderAPI(USRPReader, threading.Thread): + +# __isBufferEmpty = True + + __DATAKEYLIST = ['data','utctime','flagNoData'] + + def __init__(self, serializer='msgpack'): + + threading.Thread.__init__(self) + USRPReader.__init__(self) + +# self.__serializerObj = DynamicSerializer.DynamicSerializer('msgpack') + self.__mySerial = None + self.__isBufferEmpty = True + + self.setSerializer(serializer) + + def setSerializer(self, serializer): + + self.__serializer = serializer + + def getSerializer(self): + + return self.__serializer + + def getProfileIndex(self): + + return self.profileIndex + + def getSerialMetaData(self): + + if self.__isBufferEmpty: + ini = time.time() + + while True: + + if not self.__isBufferEmpty: + break + + if time.time() - ini > 20: + break + + sleep(1e-12) + + +# if not self.getData(): +# self.__isBufferEmpty = False +# return None + + if self.dataOut.flagNoData: + return None + + myMetadataSerial = obj2Serial(self.dataOut, + serializer = self.__serializer) + + return myMetadataSerial + + def getSerialData(self): + + if self.__isBufferEmpty: + ini = time.time() + + while True: + + if not self.__isBufferEmpty: + break + + if time.time() - ini > 20: + break + + sleep(1e-12) + + +# if not self.getData(): +# self.__isBufferEmpty = False +# return None + + if self.dataOut.flagNoData: + return None + + self.__isBufferEmpty = True + + return self.__mySerial + + def run(self): + + ''' + This method will be called many times so here you should put all your code + ''' + + if not self.isConfig: + raise IOError, 'setup() method has to be called before start()' + + while True: + + if not self.__isBufferEmpty: + sleep(1e-12) + continue + + if not self.getData(): + break + + print ".", + + self.__mySerial = obj2Serial(self.dataOut, + keyList = self.__DATAKEYLIST, + serializer = self.__serializer) + self.__isBufferEmpty = False + +# print self.profileIndex +# print 'wait 1 second' + +# sleep(0.1) + + return \ No newline at end of file diff --git a/schainpy/model/io/jroIO_voltage.py b/schainpy/model/io/jroIO_voltage.py index 3698ef2..266157c 100644 --- a/schainpy/model/io/jroIO_voltage.py +++ b/schainpy/model/io/jroIO_voltage.py @@ -1,12 +1,15 @@ ''' +Created on Jul 2, 2014 +@author: roj-idl71 ''' + import numpy from jroIO_base import LOCALTIME, JRODataReader, JRODataWriter -from model.proc.jroproc_base import ProcessingUnit, Operation -from model.data.jroheaderIO import PROCFLAG, BasicHeader, SystemHeader, RadarControllerHeader, ProcessingHeader -from model.data.jrodata import Voltage +from schainpy.model.proc.jroproc_base import ProcessingUnit, Operation +from schainpy.model.data.jroheaderIO import PROCFLAG, BasicHeader, SystemHeader, RadarControllerHeader, ProcessingHeader +from schainpy.model.data.jrodata import Voltage class VoltageReader(JRODataReader, ProcessingUnit): """ @@ -144,7 +147,7 @@ class VoltageReader(JRODataReader, ProcessingUnit): # self.ippSeconds = 0 - self.flagTimeBlock = 0 + self.flagDiscontinuousBlock = 0 self.flagIsNewBlock = 0 @@ -245,14 +248,14 @@ class VoltageReader(JRODataReader, ProcessingUnit): self.dataOut.radarControllerHeaderObj.ippSeconds = self.radarControllerHeaderObj.ippSeconds/self.nTxs # self.dataOut.timeInterval = self.radarControllerHeaderObj.ippSeconds * self.processingHeaderObj.nCohInt - - if self.radarControllerHeaderObj.code != None: - - self.dataOut.nCode = self.radarControllerHeaderObj.nCode - - self.dataOut.nBaud = self.radarControllerHeaderObj.nBaud - - self.dataOut.code = self.radarControllerHeaderObj.code +# +# if self.radarControllerHeaderObj.code != None: +# +# self.dataOut.nCode = self.radarControllerHeaderObj.nCode +# +# self.dataOut.nBaud = self.radarControllerHeaderObj.nBaud +# +# self.dataOut.code = self.radarControllerHeaderObj.code self.dataOut.dtype = self.dtype @@ -310,7 +313,7 @@ class VoltageReader(JRODataReader, ProcessingUnit): Affected: self.dataOut self.profileIndex - self.flagTimeBlock + self.flagDiscontinuousBlock self.flagIsNewBlock """ @@ -319,7 +322,7 @@ class VoltageReader(JRODataReader, ProcessingUnit): print 'Process finished' return 0 - self.flagTimeBlock = 0 + self.flagDiscontinuousBlock = 0 self.flagIsNewBlock = 0 if self.__hasNotDataInBuffer(): @@ -462,7 +465,6 @@ class VoltageWriter(JRODataWriter, Operation): self.processingHeaderObj.profilesPerBlock, self.processingHeaderObj.nHeights), dtype=numpy.dtype('complex64')) - def writeBlock(self): """ @@ -497,6 +499,8 @@ class VoltageWriter(JRODataWriter, Operation): self.blockIndex += 1 self.nTotalBlocks += 1 + print "[Writing] Block = ", self.blockIndex + def putData(self): """ Setea un bloque de datos y luego los escribe en un file @@ -514,8 +518,7 @@ class VoltageWriter(JRODataWriter, Operation): self.flagIsNewBlock = 0 - if self.dataOut.flagTimeBlock: - + if self.dataOut.flagDiscontinuousBlock: self.datablock.fill(0) self.profileIndex = 0 self.setNextFile() diff --git a/schainpy/model/io/jrodataIO.py b/schainpy/model/io/jrodataIO.py deleted file mode 100644 index 498f2f2..0000000 --- a/schainpy/model/io/jrodataIO.py +++ /dev/null @@ -1,9 +0,0 @@ -from jroIO_voltage import * -from jroIO_spectra import * -from jroIO_heispectra import * -from jroIO_amisr import * -from jroIO_HDF5 import * -try: - from jroIO_hf import * -except: - pass \ No newline at end of file diff --git a/schainpy/model/proc/__init__.py b/schainpy/model/proc/__init__.py index e69de29..bd9cf2e 100644 --- a/schainpy/model/proc/__init__.py +++ b/schainpy/model/proc/__init__.py @@ -0,0 +1,12 @@ +''' + +$Author: murco $ +$Id: Processor.py 1 2012-11-12 18:56:07Z murco $ +''' + +from jroproc_voltage import * +from jroproc_spectra import * +from jroproc_heispectra import * +from jroproc_amisr import * +from jroproc_correlation import * +from jroproc_parameters import * \ No newline at end of file diff --git a/schainpy/model/cfunctions.pyx b/schainpy/model/proc/cfunctions.pyx similarity index 87% rename from schainpy/model/cfunctions.pyx rename to schainpy/model/proc/cfunctions.pyx index bd9062f..a3b3c24 100644 --- a/schainpy/model/cfunctions.pyx +++ b/schainpy/model/proc/cfunctions.pyx @@ -1,4 +1,4 @@ -import numpy +# import numpy cimport numpy def decoder(numpy.ndarray[numpy.complex_t, ndim=2] fft_code, numpy.ndarray[numpy.complex_t, ndim=2] data): diff --git a/schainpy/model/proc/jroproc_amisr.py b/schainpy/model/proc/jroproc_amisr.py index 1377126..f7b235c 100644 --- a/schainpy/model/proc/jroproc_amisr.py +++ b/schainpy/model/proc/jroproc_amisr.py @@ -3,7 +3,7 @@ ''' import numpy from jroproc_base import ProcessingUnit, Operation -from model.data.jroamisr import AMISR +from schainpy.model.data.jroamisr import AMISR class AMISRProc(ProcessingUnit): def __init__(self): diff --git a/schainpy/model/proc/jroproc_base.py b/schainpy/model/proc/jroproc_base.py index 747e6ca..007bd1e 100644 --- a/schainpy/model/proc/jroproc_base.py +++ b/schainpy/model/proc/jroproc_base.py @@ -1,7 +1,10 @@ ''' + +$Author: murco $ +$Id: jroproc_base.py 1 2012-11-12 18:56:07Z murco $ ''' -class ProcessingUnit: +class ProcessingUnit(object): """ Esta es la clase base para el procesamiento de datos. @@ -78,6 +81,8 @@ class ProcessingUnit: **kwargs : diccionario con los nombres y valores de la funcion a ejecutar. """ + + #Checking the inputs if name == 'run': if not self.checkInputs(): @@ -137,26 +142,35 @@ class ProcessingUnit: def call(self, opType, opName=None, opId=None, **kwargs): """ - Return True si ejecuta la operacion "operationConf.name" con los - argumentos "**kwargs". False si la operacion no se ha ejecutado. - La operacion puede ser de dos tipos: + Return True si ejecuta la operacion interna nombrada "opName" o la operacion externa + identificada con el id "opId"; con los argumentos "**kwargs". - 1. Un metodo propio de esta clase: - - operation.type = "self" + False si la operacion no se ha ejecutado. + + Input: + + opType : Puede ser "self" o "external" + + La operacion puede ser de dos tipos (callMethod or callObject): - 2. El metodo "run" de un objeto del tipo Operation o de un derivado de ella: - operation.type = "other". + 1. Un metodo propio de esta clase: + + opType = "self" - Este objeto de tipo Operation debe de haber sido agregado antes con el metodo: - "addOperation" e identificado con el operation.id - + 2. El metodo "run" de un objeto del tipo Operation o de un derivado de ella: + + opType = "other" or "external". - con el id de la operacion. - - Input: + opName : Si la operacion es interna (opType = 'self'), entonces el "opName" sera + usada para llamar a un metodo interno de la clase Processing + + opId : Si la operacion es externa (opType = 'other'), entonces el "opId" sera + usada para llamar al metodo "run" de la clase Operation registrada con ese Id - Operation : Objeto del tipo operacion con los atributos: name, type y id. + Exception: + Este objeto de tipo Operation debe de haber sido agregado antes con el metodo: + "addOperation" e identificado con el valor "opId" = el id de la operacion. + De lo contrario retornara un error del tipo IOError """ @@ -205,7 +219,7 @@ class ProcessingUnit: raise ValueError, "Not implemented" -class Operation(): +class Operation(object): """ Clase base para definir las operaciones adicionales que se pueden agregar a la clase ProcessingUnit @@ -233,7 +247,8 @@ class Operation(): def run(self, dataIn, **kwargs): """ - Realiza las operaciones necesarias sobre la dataIn.data y actualiza los atributos del objeto dataIn. + Realiza las operaciones necesarias sobre la dataIn.data y actualiza los + atributos del objeto dataIn. Input: diff --git a/schainpy/model/proc/jroproc_correlation.py b/schainpy/model/proc/jroproc_correlation.py index b608adb..f39312e 100644 --- a/schainpy/model/proc/jroproc_correlation.py +++ b/schainpy/model/proc/jroproc_correlation.py @@ -1,7 +1,7 @@ import numpy from jroproc_base import ProcessingUnit, Operation -from model.data.jrodata import Correlation +from schainpy.model.data.jrodata import Correlation class CorrelationProc(ProcessingUnit): @@ -33,7 +33,7 @@ class CorrelationProc(ProcessingUnit): self.dataOut.nCode = self.dataIn.nCode self.dataOut.code = self.dataIn.code # self.dataOut.nProfiles = self.dataOut.nFFTPoints - self.dataOut.flagTimeBlock = self.dataIn.flagTimeBlock + self.dataOut.flagDiscontinuousBlock = self.dataIn.flagDiscontinuousBlock self.dataOut.utctime = self.firstdatatime self.dataOut.flagDecodeData = self.dataIn.flagDecodeData #asumo q la data esta decodificada self.dataOut.flagDeflipData = self.dataIn.flagDeflipData #asumo q la data esta sin flip diff --git a/schainpy/model/proc/jroproc_heispectra.py b/schainpy/model/proc/jroproc_heispectra.py index 1758045..6e6d604 100644 --- a/schainpy/model/proc/jroproc_heispectra.py +++ b/schainpy/model/proc/jroproc_heispectra.py @@ -1,7 +1,7 @@ import numpy from jroproc_base import ProcessingUnit, Operation -from model.data.jrodata import SpectraHeis +from schainpy.model.data.jrodata import SpectraHeis class SpectraHeisProc(ProcessingUnit): @@ -37,7 +37,7 @@ class SpectraHeisProc(ProcessingUnit): self.dataOut.nFFTPoints = self.dataIn.nHeights # self.dataOut.channelIndexList = self.dataIn.channelIndexList # self.dataOut.flagNoData = self.dataIn.flagNoData - self.dataOut.flagTimeBlock = self.dataIn.flagTimeBlock + self.dataOut.flagDiscontinuousBlock = self.dataIn.flagDiscontinuousBlock self.dataOut.utctime = self.dataIn.utctime # self.dataOut.utctime = self.firstdatatime self.dataOut.flagDecodeData = self.dataIn.flagDecodeData #asumo q la data esta decodificada diff --git a/schainpy/model/proc/jroproc_parameters.py b/schainpy/model/proc/jroproc_parameters.py index bfd74b1..f5fe63b 100644 --- a/schainpy/model/proc/jroproc_parameters.py +++ b/schainpy/model/proc/jroproc_parameters.py @@ -12,7 +12,7 @@ import importlib import itertools from jroproc_base import ProcessingUnit, Operation -from model.data.jrodata import Parameters +from schainpy.model.data.jrodata import Parameters class ParametersProc(ProcessingUnit): @@ -48,7 +48,7 @@ class ParametersProc(ProcessingUnit): self.dataOut.nCode = self.dataIn.nCode self.dataOut.code = self.dataIn.code # self.dataOut.nProfiles = self.dataOut.nFFTPoints - self.dataOut.flagTimeBlock = self.dataIn.flagTimeBlock + self.dataOut.flagDiscontinuousBlock = self.dataIn.flagDiscontinuousBlock self.dataOut.utctime = self.firstdatatime self.dataOut.flagDecodeData = self.dataIn.flagDecodeData #asumo q la data esta decodificada self.dataOut.flagDeflipData = self.dataIn.flagDeflipData #asumo q la data esta sin flip diff --git a/schainpy/model/proc/jroproc_spectra.py b/schainpy/model/proc/jroproc_spectra.py index 10524f4..fe1f9c9 100644 --- a/schainpy/model/proc/jroproc_spectra.py +++ b/schainpy/model/proc/jroproc_spectra.py @@ -2,8 +2,8 @@ import numpy import math from jroproc_base import ProcessingUnit, Operation -from model.data.jrodata import Spectra -from model.data.jrodata import hildebrand_sekhon +from schainpy.model.data.jrodata import Spectra +from schainpy.model.data.jrodata import hildebrand_sekhon class SpectraProc(ProcessingUnit): @@ -37,7 +37,7 @@ class SpectraProc(ProcessingUnit): self.dataOut.code = self.dataIn.code self.dataOut.nProfiles = self.dataOut.nFFTPoints # self.dataOut.channelIndexList = self.dataIn.channelIndexList - self.dataOut.flagTimeBlock = self.dataIn.flagTimeBlock + self.dataOut.flagDiscontinuousBlock = self.dataIn.flagDiscontinuousBlock self.dataOut.utctime = self.firstdatatime self.dataOut.flagDecodeData = self.dataIn.flagDecodeData #asumo q la data esta decodificada self.dataOut.flagDeflipData = self.dataIn.flagDeflipData #asumo q la data esta sin flip @@ -114,7 +114,8 @@ class SpectraProc(ProcessingUnit): raise ValueError, "This SpectraProc.run() need nFFTPoints input variable" if nProfiles == None: - raise ValueError, "This SpectraProc.run() need nProfiles input variable" + nProfiles = nFFTPoints +# raise ValueError, "This SpectraProc.run() need nProfiles input variable" if ippFactor == None: diff --git a/schainpy/model/proc/jroproc_voltage.py b/schainpy/model/proc/jroproc_voltage.py index 1014d0a..27a6d89 100644 --- a/schainpy/model/proc/jroproc_voltage.py +++ b/schainpy/model/proc/jroproc_voltage.py @@ -1,8 +1,7 @@ import numpy from jroproc_base import ProcessingUnit, Operation -from model.data.jrodata import Voltage - +from schainpy.model.data.jrodata import Voltage class VoltageProc(ProcessingUnit): @@ -207,7 +206,7 @@ class VoltageProc(ProcessingUnit): return 1 - def filterByHeights(self, window, axis=2): + def filterByHeights(self, window): deltaHeight = self.dataOut.heightList[1] - self.dataOut.heightList[0] @@ -233,8 +232,17 @@ class VoltageProc(ProcessingUnit): self.dataOut.data = buffer.copy() self.dataOut.heightList = numpy.arange(self.dataOut.heightList[0],newdelta*(self.dataOut.nHeights-r)/window,newdelta) self.dataOut.windowOfFilter = window + + def setH0(self, h0, deltaHeight = None): - return 1 + if not deltaHeight: + deltaHeight = self.dataOut.heightList[1] - self.dataOut.heightList[0] + + nHeights = self.dataOut.nHeights + + newHeiRange = h0 + numpy.arange(nHeights)*deltaHeight + + self.dataOut.heightList = newHeiRange def deFlip(self, channelList = []): @@ -267,8 +275,6 @@ class VoltageProc(ProcessingUnit): self.dataOut.data = data - - def setRadarFrequency(self, frequency=None): if frequency != None: @@ -571,13 +577,15 @@ class Decoder(Operation): def convolutionInFreqOpt(self, data): - fft_code = self.fft_code[self.__profIndex].reshape(1,-1) - - data = cfunctions.decoder(fft_code, data) - - datadec = data#[:,:] - - return datadec + raise NotImplementedError + +# fft_code = self.fft_code[self.__profIndex].reshape(1,-1) +# +# data = cfunctions.decoder(fft_code, data) +# +# datadec = data#[:,:] +# +# return datadec def convolutionInTime(self, data): @@ -887,4 +895,140 @@ class Reshaper(Operation): dataOut.nProfiles = dataOut.data.shape[1] - dataOut.ippSeconds *= factor \ No newline at end of file + dataOut.ippSeconds *= factor + +import collections +from scipy.stats import mode + +class Synchronize(Operation): + + isConfig = False + __profIndex = 0 + + def __init__(self): + + Operation.__init__(self) +# self.isConfig = False + self.__powBuffer = None + self.__startIndex = 0 + self.__pulseFound = False + + def __findTxPulse(self, dataOut, channel=0, pulse_with = None): + + #Read data + + powerdB = dataOut.getPower(channel = channel) + noisedB = dataOut.getNoise(channel = channel)[0] + + self.__powBuffer.extend(powerdB.flatten()) + + dataArray = numpy.array(self.__powBuffer) + + filteredPower = numpy.correlate(dataArray, dataArray[0:self.__nSamples], "same") + + maxValue = numpy.nanmax(filteredPower) + + if maxValue < noisedB + 10: + #No se encuentra ningun pulso de transmision + return None + + maxValuesIndex = numpy.where(filteredPower > maxValue - 0.1*abs(maxValue))[0] + + if len(maxValuesIndex) < 2: + #Solo se encontro un solo pulso de transmision de un baudio, esperando por el siguiente TX + return None + + phasedMaxValuesIndex = maxValuesIndex - self.__nSamples + + #Seleccionar solo valores con un espaciamiento de nSamples + pulseIndex = numpy.intersect1d(maxValuesIndex, phasedMaxValuesIndex) + + if len(pulseIndex) < 2: + #Solo se encontro un pulso de transmision con ancho mayor a 1 + return None + + spacing = pulseIndex[1:] - pulseIndex[:-1] + + #remover senales que se distancien menos de 10 unidades o muestras + #(No deberian existir IPP menor a 10 unidades) + + realIndex = numpy.where(spacing > 10 )[0] + + if len(realIndex) < 2: + #Solo se encontro un pulso de transmision con ancho mayor a 1 + return None + + #Eliminar pulsos anchos (deja solo la diferencia entre IPPs) + realPulseIndex = pulseIndex[realIndex] + + period = mode(realPulseIndex[1:] - realPulseIndex[:-1])[0][0] + + print "IPP = %d samples" %period + + self.__newNSamples = dataOut.nHeights #int(period) + self.__startIndex = int(realPulseIndex[0]) + + return 1 + + + def setup(self, nSamples, nChannels, buffer_size = 4): + + self.__powBuffer = collections.deque(numpy.zeros( buffer_size*nSamples,dtype=numpy.float), + maxlen = buffer_size*nSamples) + + bufferList = [] + + for i in range(nChannels): + bufferByChannel = collections.deque(numpy.zeros( buffer_size*nSamples, dtype=numpy.complex) + numpy.NAN, + maxlen = buffer_size*nSamples) + + bufferList.append(bufferByChannel) + + self.__nSamples = nSamples + self.__nChannels = nChannels + self.__bufferList = bufferList + + def run(self, dataOut, channel = 0): + + if not self.isConfig: + nSamples = dataOut.nHeights + nChannels = dataOut.nChannels + self.setup(nSamples, nChannels) + self.isConfig = True + + #Append new data to internal buffer + for thisChannel in range(self.__nChannels): + bufferByChannel = self.__bufferList[thisChannel] + bufferByChannel.extend(dataOut.data[thisChannel]) + + if self.__pulseFound: + self.__startIndex -= self.__nSamples + + #Finding Tx Pulse + if not self.__pulseFound: + indexFound = self.__findTxPulse(dataOut, channel) + + if indexFound == None: + dataOut.flagNoData = True + return + + self.__arrayBuffer = numpy.zeros((self.__nChannels, self.__newNSamples), dtype = numpy.complex) + self.__pulseFound = True + self.__startIndex = indexFound + + #If pulse was found ... + for thisChannel in range(self.__nChannels): + bufferByChannel = self.__bufferList[thisChannel] + #print self.__startIndex + x = numpy.array(bufferByChannel) + self.__arrayBuffer[thisChannel] = x[self.__startIndex:self.__startIndex+self.__newNSamples] + + deltaHeight = dataOut.heightList[1] - dataOut.heightList[0] + dataOut.heightList = numpy.arange(self.__newNSamples)*deltaHeight +# dataOut.ippSeconds = (self.__newNSamples / deltaHeight)/1e6 + + dataOut.data = self.__arrayBuffer + + self.__startIndex += self.__newNSamples + + return \ No newline at end of file diff --git a/schainpy/model/proc/jroprocessing.py b/schainpy/model/proc/jroprocessing.py deleted file mode 100644 index 00333fc..0000000 --- a/schainpy/model/proc/jroprocessing.py +++ /dev/null @@ -1,6 +0,0 @@ -from jroproc_voltage import * -from jroproc_spectra import * -from jroproc_heispectra import * -from jroproc_amisr import * -from jroproc_correlation import * -from jroproc_parameters import * \ No newline at end of file diff --git a/schainpy/model/utils/__init__.py b/schainpy/model/utils/__init__.py index e69de29..12809e0 100644 --- a/schainpy/model/utils/__init__.py +++ b/schainpy/model/utils/__init__.py @@ -0,0 +1,7 @@ +''' + +$Author: murco $ +$Id: Processor.py 1 2012-11-12 18:56:07Z murco $ +''' + +from jroutils_ftp import * \ No newline at end of file diff --git a/schainpy/model/utils/jroutils.py b/schainpy/model/utils/jroutils.py deleted file mode 100644 index 842d53a..0000000 --- a/schainpy/model/utils/jroutils.py +++ /dev/null @@ -1 +0,0 @@ -from jroutils_ftp import * \ No newline at end of file diff --git a/schainpy/model/utils/jroutils_ftp.py b/schainpy/model/utils/jroutils_ftp.py index 4201adc..a5b9ee6 100644 --- a/schainpy/model/utils/jroutils_ftp.py +++ b/schainpy/model/utils/jroutils_ftp.py @@ -5,7 +5,7 @@ import os import glob import ftplib import multiprocessing -from model.proc.jroproc_base import ProcessingUnit, Operation +from schainpy.model.proc.jroproc_base import ProcessingUnit, Operation class FTP(object): """ diff --git a/schainpy/serializer/DataTranslate.py b/schainpy/serializer/DataTranslate.py new file mode 100644 index 0000000..ec9530b --- /dev/null +++ b/schainpy/serializer/DataTranslate.py @@ -0,0 +1,115 @@ +''' +Created on Jul 15, 2014 + +@author: Miguel Urco +''' +from JROSerializer import DynamicSerializer + +PICKLE_SERIALIZER = DynamicSerializer('cPickle') +MSGPACK_SERIALIZER = DynamicSerializer('msgpack') + +from schainpy.model.data.jrodata import * + +CLASSNAME_KEY = 'classname__' + +def isNotClassVar(myObj): + + return not hasattr(myObj,'__dict__') + +def isDictFormat(thisValue): + + if type(thisValue) != type({}): + return False + + if CLASSNAME_KEY not in thisValue.keys(): + return False + + return True + +def obj2Dict(myObj, keyList=[]): + + if not keyList: + keyList = myObj.__dict__.keys() + + myDict = {} + + myDict[CLASSNAME_KEY] = myObj.__class__.__name__ + + for thisKey, thisValue in myObj.__dict__.items(): + + if thisKey not in keyList: + continue + + if isNotClassVar(thisValue): + myDict[thisKey] = thisValue + continue + + ## If this value is another class instance + myNewDict = obj2Dict(thisValue) + myDict[thisKey] = myNewDict + + return myDict + +def dict2Obj(myDict): + ''' + ''' + + if CLASSNAME_KEY not in myDict.keys(): + return None + + className = eval(myDict[CLASSNAME_KEY]) + + myObj = className() + + for thisKey, thisValue in myDict.items(): + + if thisKey == CLASSNAME_KEY: + continue + + if not isDictFormat(thisValue): + setattr(myObj, thisKey, thisValue) + continue + + myNewObj = dict2Obj(thisValue) + setattr(myObj, thisKey, myNewObj) + + return myObj + +def obj2Serial(myObj, serializer='msgpack', **kwargs): + + if serializer == 'cPickle': + SERIALIZER = PICKLE_SERIALIZER + else: + SERIALIZER = MSGPACK_SERIALIZER + + myDict = obj2Dict(myObj, **kwargs) + mySerial = SERIALIZER.dumps(myDict) + + return mySerial + +def serial2Dict(mySerial, serializer='msgpack'): + + if serializer == 'cPickle': + SERIALIZER = PICKLE_SERIALIZER + else: + SERIALIZER = MSGPACK_SERIALIZER + + return SERIALIZER.loads(mySerial) + +def serial2Obj(mySerial, metadataDict = {}, serializer='msgpack'): + + if serializer == 'cPickle': + SERIALIZER = PICKLE_SERIALIZER + else: + SERIALIZER = MSGPACK_SERIALIZER + + myDataDict = SERIALIZER.loads(mySerial) + + if not metadataDict: + myObj = dict2Obj(myDataDict) + return myObj + + metadataDict.update(myDataDict) + myObj = dict2Obj(metadataDict) + + return myObj \ No newline at end of file diff --git a/schainpy/serializer/JROSerializer.py b/schainpy/serializer/JROSerializer.py new file mode 100644 index 0000000..a3e6827 --- /dev/null +++ b/schainpy/serializer/JROSerializer.py @@ -0,0 +1,93 @@ +''' +Created on Jul 17, 2014 + +@author: roj-idl71 +''' + +import cPickle +import msgpack_numpy +import jsonpickle +import yaml + +# import JROMsgpack +# import JROJsonpickle + +class Serializer(object): + + def __init__(self): + + self.serializer = None + + def dumps(self, obj, **kwargs): + + return self.serializer.dumps(obj, **kwargs) + + def loads(self, obj, **kwargs): + return self.serializer.loads(obj, **kwargs) + +class cPickleSerializer(Serializer): + + def __init__(self): + self.serializer = cPickle + + def dumps(self, obj, **kwargs): + return self.serializer.dumps(obj, 2) + + def loads(self, obj, **kwargs): + return self.serializer.loads(obj) + +class msgpackSerializer(Serializer): + + def __init__(self): + + self.serializer = msgpack_numpy + + def dumps(self, obj, **kwargs): + return self.serializer.packb(obj) + + def loads(self, obj, **kwargs): + return self.serializer.unpackb(obj) + +class jsonpickleSerializer(Serializer): + + def __init__(self): + + self.serializer = jsonpickle + + def dumps(self, obj, **kwargs): + return self.serializer.encode(obj, **kwargs) + + def loads(self, obj, **kwargs): + return self.serializer.decode(obj, **kwargs) + +class yamlSerializer(Serializer): + + def __init__(self): + + self.serializer = yaml + + def dumps(self, obj, **kwargs): + return self.serializer.dump(obj, **kwargs) + + def loads(self, obj, **kwargs): + return self.serializer.load(obj, **kwargs) + +class DynamicSerializer(Serializer): + + def __init__(self, mode = 'cPickle'): + + if mode == 'cPickle': + self.serializer = cPickleSerializer() + + if mode == 'jsonpickle': + self.serializer = jsonpickleSerializer() + + if mode == 'yaml': + self.serializer = yamlSerializer() + + if mode == 'msgpack': + self.serializer = msgpackSerializer() + + +if __name__ == '__main__': + pass \ No newline at end of file diff --git a/schainpy/serializer/__init__.py b/schainpy/serializer/__init__.py new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/schainpy/serializer/__init__.py diff --git a/schainpy/serializer/test/DynamicObject.py b/schainpy/serializer/test/DynamicObject.py new file mode 100644 index 0000000..5045e1f --- /dev/null +++ b/schainpy/serializer/test/DynamicObject.py @@ -0,0 +1,816 @@ +''' +The DynamicObject module supports dynamic loading of YAML +defined objects into Python class objects. Object can +be sub-classed to allow direct binding of methods having +matching signatures. + +$Id$ +''' + +import urllib +import os +import re +import yaml # YAML Ain't Markup Language +import numpy as np +import copy +import inspect +import PrecisionTime +import time +import sys +import datetime +import collections + +# Replacement Loader for PyYAML to keep dictionaries in-order: +import OrderedYAML +#OrderedYAML.collections + +class Object(object): + """ Loads a YAML defined python class dynamically using the supplied URI, + which may be a file, directory, web hyper-link, or hyper-linked directory. """ + + # Dictionary containing all known Object class names and corresponding class objects + dynamicClasses = collections.OrderedDict() + + def __init__(self, object_uri=None, revision=None, recursive=False): + if isinstance(object_uri, file): + # URI is a yaml file - read it. + self.yaml = file.read() + elif object_uri == None: + self.yaml = None + elif isinstance(object_uri, str): + if object_uri.endswith('.yml'): + # URI is a web hyper-linked yaml file - read it. + self.yaml = urllib.urlopen(object_uri).read() + else: + # URI is a (hyper-linked?) directory - try reading it. + #print "URI is a directory." + try: + self.files = self.__parseLink(object_uri, recursive) + except IOError: + # URI is a local directory - get a list of YAML files in it + self.files = self.__getYamlFiles(object_uri, recursive) + + # For each YAML file found, create a new DynamicObject of it: + self.yaml = [] + for fn in self.files: + self.yaml.append(Object(fn)) + else: + print "Invalid URI supplied: %s"%(object_uri,) + + def __parseLink(self, object_uri, recursive): + """ Returns a listing of all YAML files located in the + hyper-link directory given by page. """ + page = urllib.urlopen(object_uri).read() + #print "URI is a URL directory: %s"%(object_uri,) + pattern = re.compile(r'') + + # List of files contained in the directory at the given URL, ignoring + # any "?" / GET query-string locations given: + files = [x[9:-2] for x in pattern.findall(page) if not x[9:-2].startswith('?')] + #print files + + yamlFiles = [] + dirs = [] + for fn in files: + if not fn.startswith('/'): # Ignore absolute paths... + path = os.path.join(object_uri, fn) + #print path + + # Keep list of YAML files found... + if fn.endswith('.yml'): + yamlFiles.append(path) + + # Keep list of directories found... + elif recursive and fn.endswith('/'): + dirs.append(path) + + if recursive: + #print dirs + for path in dirs: + yamlFiles += self.__parseLink(path,recursive) + + return yamlFiles + + def __getYamlFiles(self, local_dir, recursive): + """ Returns a listing of all YAML files located in the given + directory, recursing if requested. """ + yamlFiles = [] + dirs = [] + for fn in os.listdir(local_dir): + path = os.path.join(local_dir, fn) + + # List of YAML files found... + if fn.endswith('.yml'): + yamlFiles.append(path) + + # List of directories found... + elif recursive and os.path.isdir(path): + dirs.append(path) + + # Recurse if desired: + if recursive: + for path in dirs: + yamlFiles += self.__getYamlFiles(path,recursive) + + return yamlFiles + + def equals(self, obj, compare_time_created=True): + """ Returns True iff self has identical attributes + (numerically) to obj (no extras) """ + + if not isinstance(obj, Object): return False + + self_keys = self.__dict__.keys() + obj_keys = obj.__dict__.keys() + if not self_keys == obj_keys: + return False + for key in self_keys: + obj_keys.remove(key) + + self_value, obj_value = self.__dict__[key], obj.__dict__[key] + if isinstance(self_value, Object): + if not self_value.equals(obj_value, compare_time_created): + return False + elif isinstance(self_value, np.ndarray): + m1 = map(repr,self_value.flat) + m2 = map(repr,obj_value.flat) + ret = m1 == m2 + if not ret: + return False + else: + if not self_value == obj_value: + # Return False iff the different times are important + return key == '__time_created' and not compare_time_created + + return obj_keys == [] # no more keys --> the objects are identical + + def sizeof(self): + """ Recursively computes the size in bytes of the given Dynamic Object """ + sz = 0 + values = self.__dict__.values() + for val in values: + if isinstance(val, Object): sz += val.sizeof() + elif isinstance(val, np.ndarray): sz += val.nbytes + elif hasattr(val, 'dtype') and hasattr(val.dtype, 'itemsize'): sz += val.dtype.itemsize + else: sz += sys.getsizeof(val) + return sz + + # Automatic methods for accessing meta-data + getters = ['__object_name', '__revision_number', '__revision_id', '__revision_source', '__revision_tag', '__time_created'] + def getObjectName(self): return self.__class__.meta_attributes['__object_name'] + def getRevisionNumber(self): return self.__class__.meta_attributes['__revision_number'] + def getRevisionId(self): return self.__class__.meta_attributes['__revision_id'] + def getRevisionSource(self): return self.__class__.meta_attributes['__revision_source'] + def getRevisionTag(self): return self.__class__.meta_attributes['__revision_tag'] + def getTimeCreated(self): return getattr(self, "__time_created") + + """ + __getters = [('ObjectName', getObjectName), ('RevisionNumber', getRevisionNumber), + ('RevisionId', getRevisionId), ('RevisionSource', getRevisionSource), + ('RevisionTag', getRevisionTag)] + def __repr__(self): + meta_atts = repr([(x[0], x[1](self)) for x in Object.__getters]) + atts = repr(self.__dict__) + return "Object(%s, %s)"%(atts, meta_atts) + """ + + +class SignatureException(Exception): + """ Exception thrown when a data or method signature is unknown or invalid + for a particular Object. """ + def __init__(self, value): self.value = value + def __str__(self): return repr(self.value) + +class _IDLTag(object): + """ IDLTag (aka Interface Definition Language Tag) is an abstract helper class + used by the Factory to define built-in tags used + specifically for our IDL """ + def __init__(self, yamlString): + self.yamlString = yamlString + def __repr__(self): + return self.yamlString + +class _Reference(_IDLTag): + """ Helper class for Factory: Objects can be composed + of other objects, requiring a Reference to the other object. """ + def __repr__(self): + return "Ref(%s)"%(self.yamlString,) + +class _Method(_IDLTag): + """ Helper class for Factory: Objects have methods + associated with them - this tag tells the Factory that a method + signature follows (in dict format) """ + def __repr__(self): + return "Method(%r)"%(self.yamlString,) + +class Binary(Object): + def __init__(self, binary_type, value=None): + self.binary_type = binary_type + self.value = value + +import Lookup + +class BuiltinDtype(_IDLTag): + """ Helper class for Factory: Object parameters each + have a certain data type (either dtype.xxxx for numpy compatible data + types, or one of the generic python data types (i.e. int, bool, str...) + + __addYamlConstructor in Factory registers all of the tags + listed as keys in the dtypes dictionary.""" + + def __init__(self, yamlString, tag=None): + self.tag = tag[1:] + super(BuiltinDtype, self).__init__(yamlString) + #print self.tag + try: self.dtype = Lookup.numpy_dtypes[self.tag] + except KeyError: self.dtype = Lookup.builtin_objects[self.tag] + + def __repr__(self): + return "_BuiltinType(%s,%s)"%(self.yamlString, self.tag) + +# Register hexadecimal representation of numpy dtypes in YAML + +class _Parameter: + """ Helper class for Factory: Contains the name, default + value, and length (if an array) of an object initialization parameter. """ + + def __init__(self, name, hasDefault=False, default=None, length=None, classType=None): + self.name = name + self.hasDefault = hasDefault + self.default = default + self.length = length + if isinstance(classType, None.__class__) and not isinstance(default, None.__class__): + self.classType = default.__class__ + else: + self.classType = classType + +class _UnresolvedType: + """ Used to indicate a data type which has not yet been parsed (i.e. for + recursive data-types. """ + + def __init__(self, yamlObject): + # Either the name of the class we couldn't resolve, or a dictionary + # containing the name and a default value + self.yamlObject = yamlObject + +class UnresolvedTypeException(Exception): + """ Raised when a !ref tag is used, but the reference cannot be resolved """ + pass + +def get_class(kls): + """ Returns a pointer to the class instance with the name kls + Function acquired from http://stackoverflow.com/questions/452969/ """ + parts = kls.split('.') + module = ".".join(parts[:-1]) + m = __import__( module ) + for comp in parts[1:]: + m = getattr(m, comp) + return m + +# Aliased constructor & representer adders for easily swapping between Ordered and non-Ordered: +def add_constructor(tag, constructor): + #yaml.add_constructor(tag, constructor) + OrderedYAML.Loader.add_constructor(tag, constructor) +def add_representer(cls, representer): + #yaml.add_representer(cls, representer) + OrderedYAML.Dumper.add_representer(cls, representer) + +# Implicit constructor for _Reference objects using the !ref tag: +def __ref_constructor(loader, node): + if isinstance(node, yaml.nodes.MappingNode): + return _Reference(loader.construct_mapping(node)) + else: + return _Reference(loader.construct_scalar(node)) +add_constructor(u'!ref', __ref_constructor) + +# Method constructor using !method tag: +def __method_constructor(loader, node): + if isinstance(node, yaml.nodes.MappingNode): + return _Method(loader.construct_mapping(node)) + else: + return _Method(loader.construct_scalar(node)) +add_constructor(u'!method', __method_constructor) + +# Generic constructor for any _BuiltinDtype +def __dtype_constructor(loader, node): + if isinstance(node, yaml.nodes.SequenceNode): + ret = BuiltinDtype(loader.construct_sequence(node), tag=node.tag) + elif isinstance(node, yaml.nodes.MappingNode): + ret = BuiltinDtype(loader.construct_mapping(node), tag=node.tag) + else: + ret = BuiltinDtype(loader.construct_scalar(node), tag=node.tag) + return ret + +# Register YAML constructors for each builtin type: +for dtype in Lookup.numpy_dtypes.keys() + Lookup.builtin_objects.keys(): + add_constructor(u'!%s'%(dtype,), __dtype_constructor) + +class FactoryLoader(OrderedYAML.Loader): + """ A YAML Loader specifically designed to load YAML object definitions + (as opposed to actual instances of the objects) """ + + def construct_yaml_timestamp(self, node): + """ Make empty timestamps (None/null) acceptable, otherwise parse the timestamp """ + if node.value == u'': + name = 'YAML_DEFN_LOADED_INCORRECTLY' # in case we forget to fix the name... + return _Parameter(name, hasDefault=False, classType=datetime.datetime) + else: + return yaml.constructor.SafeConstructor.construct_yaml_timestamp(self, node) + +# Override default timestamp constructor: +FactoryLoader.add_constructor( + u'tag:yaml.org,2002:timestamp', + FactoryLoader.construct_yaml_timestamp +) + +import DynamicYAML +class Factory: + """ Load a YAML defined python class and create a class with initialization + provided by this factory. This is intended as an abstract class to be sub-classed + to enable complex initialization on object instantiation. + + Factory subclasses should override __buildClass().""" + + def __init__(self, dynamic_object=None, yaml=None, typeCheck='strong', parse=True, revision_dict=None): + if revision_dict != None: self.revision_dict = revision_dict # Remember for when we build each individual class + else: + self.revision_dict = {\ + "__revision_number": 0, + "__revision_id": 'unknown', + "__revision_source": 'unknown', + "__revision_tag": 'unknown'} + if parse: + if dynamic_object: + self.parse(dynamic_object, typeCheck=typeCheck) + else: + dyno = Object() + dyno.yaml = yaml + self.parse(dyno, typeCheck=typeCheck) + + def parse(self, dynamic_object, typeCheck='strong'): + """ + Initializer for a Factory, converting the given dynamic_object + containing a (text) YAML object definition into the corresponding class-type + with initializer. + + typeCheck parameter can be one of 'strong' or 'cast': + 'strong': Class initializer should raise a TypeError when given + anything but the correct type + 'cast': Class initializer should attempt to cast any input to the correct type + """ + + # Remember what kind of type-checking to do: + if typeCheck not in ['strong', 'cast']: + raise Exception('Incorrect input for typeCheck: %s\nExpected "strong" or "cast"'%(typeCheck)) + self.typeCheck = typeCheck + + # Get a list of the objects to build: + if isinstance(dynamic_object.yaml, list): + objects = dynamic_object.yaml + else: + objects = [dynamic_object] + + # Generate a dictionary of classes from the DynamicObjects given: + self.classes = dict() + for obj in objects: + + # This loader breaks nothing anymore #everything currently + loader = FactoryLoader(obj.yaml) + #loader = yaml.Loader(obj.yaml) + + # Dictionary with method and data signatures for the current object: + objDefn = [] + while loader.check_data(): + objDefn.append(loader.get_data()) + loader.dispose() + + # Parse the dictionary into a class definition: + objClass = self.__buildClass(objDefn) + self.classes.update(objClass) + + def parseMethodSignature(self, sigName, methDict): + """ Returns the python method corresponding to the given signature + (given signature should be in the loaded YAML dict format. + + Override this method for recognizing complex method signatures. """ + + raise SignatureException("Object abstract base class doesn't support any method signatures.") + + def parseDataSignature(self, sigName, sig): + """ Returns the Parameter object corresponding to the given signature. + + This method should be overridden for recognizing complex data signatures + (don't forget to call super(sig) for built-in data types though!) """ + + # Is the object an array with explicit default elements?: + if isinstance(sig.yamlString, list): + #length = len(sig.yamlString) + if 'dtype' in sig.tag: + default = np.array(sig.yamlString, dtype=sig.dtype) + elif 'binary' == sig.tag: + default = Binary(sig.yamlString["type"]) + else: + default = sig.yamlString + return _Parameter(sigName, True, default, length=None) + + # Is the object an array with length and default value given?: + if isinstance(sig.yamlString, dict) and "len" in sig.yamlString.keys(): + length = sig.yamlString["len"] + + # Shape is given as something like [[],[]], not [2,2] - convert + if isinstance(length, list): + + def get_shape(lst): + """ Gets the shape of a list recursively filled with empty lists """ + if lst == []: return [0] + return [len(lst)] + get_shape(lst[0]) + + if len(length) > 0: + if isinstance(length[0], list): + length = get_shape(length) + else: + pass + else: + length = [0] # convert [] to [0] (numpy interprets [] as [1] for shapes) + + + if 'complex' in sig.tag: + imag = sig.yamlString["default"]["imag"] + real = sig.yamlString["default"]["real"] + default = sig.dtype(real) + sig.dtype(imag*1j) + elif 'binary' == sig.tag: + default = Binary(sig.yamlString["type"]) + else: + default = sig.dtype(sig.yamlString["default"]) + + return _Parameter(sigName, True, default, length) + + # The object is singular, with a given value: + if 'complex' in sig.tag: + imag = sig.yamlString["imag"] + real = sig.yamlString["real"] + default = sig.dtype(real) + sig.dtype(imag*1j) + return _Parameter(sigName, True, default) + elif 'binary' == sig.tag: + default = Binary(sig.yamlString["type"]) + return _Parameter(sigName, False, default, classType=Binary) + elif 'timestamp' in sig.tag: + if isinstance(sig.yamlString, dict): + if sig.tag in ['timestamp_picosecond', 'timestamp_ps']: + try: s = sig.yamlString['second'] + except KeyError: s = sig.yamlString['s'] + try: ps = sig.yamlString['picosecond'] + except KeyError: ps = sig.yamlString['ps'] + return _Parameter(sigName, True, PrecisionTime.psTime(s, ps)) + elif sig.tag in ['timestamp_nanosecond', 'timestamp_ns']: + try: s = sig.yamlString['second'] + except KeyError: s = sig.yamlString['s'] + try: ns = sig.yamlString['nanosecond'] + except KeyError: ns = sig.yamlString['ns'] + return _Parameter(sigName, True, PrecisionTime.nsTime(s, ns)) + else: + if sig.tag in ['timestamp_picosecond', 'timestamp_ps']: + return _Parameter(sigName, False, classType=PrecisionTime.psTime) + elif sig.tag in ['timestamp_nanosecond', 'timestamp_ns']: + return _Parameter(sigName, False, classType=PrecisionTime.nsTime) + else: + default = sig.dtype(sig.yamlString) + return _Parameter(sigName, True, default) # not binary + + + + def __parsePythonType(self, sigName, sig): + """ Returns a _Parameter object, similar to parseDataSignature, but + for a basic python type. """ + + if isinstance(sig, collections.OrderedDict): + default = dict(sig) # Type-check user-defined !!maps as dicts, not OrderedDicts. + else: + default = sig # The signature sig is the default value itself + return _Parameter(sigName, True, default) + + def __parseReferenceSignature(self, sigName, ref_object, objClasses): + """ Takes a reference object ref_object to be named sigName, and + produces a _Parameter object with default value of None. """ + + # List of names of classes we've created so far: + #print [x for x in objClasses] + names = objClasses.keys() + + if ref_object.yamlString in names: + defaultType = objClasses[ref_object.yamlString] + return _Parameter(sigName, classType=defaultType) + else: + try: + # Try to find the class type in globals: + className = objClasses[str(ref_object.yamlString)] + defaultType = get_class(className) + except (ValueError, KeyError): + defaultType = _UnresolvedType(ref_object.yamlString) + #raise NameError("Invalid reference to module %s"%(className,)) + + return _Parameter(sigName, classType=defaultType) + + def __buildInitializer(self, className, classData): + """ Constructs the initializer for an object which expects parameters + listed in classData as input upon initialization. """ + + # Type of type-checking to use: + strong = (self.typeCheck == 'strong') + #cast = (self.typeCheck == 'cast') + + def typeCheck(param, arg): + """ + Checks to see if the type of arg matches that of the corresponding param, + casting arg to the correct type if desired. + """ + if isinstance(arg, param.classType): return arg + if isinstance(arg, np.ndarray) and arg.dtype.type == param.classType: + if not param.hasDefault: return arg + if param.default.shape == (): return arg + if param.default.shape[-1] == 0: return arg + if arg.shape == param.default.shape: return arg + if isinstance(arg, None.__class__): return arg + if strong: + raise TypeError("Incorrect input type on strong type-checking."+\ + " Expected %s - got %s"%(param.classType,arg.__class__)) + else: + # If the parameter corresponding to the given argument has a non-NoneType default + # value, then attempt to cast the argument into the correct parameter type + if param.hasDefault and param.default != None: + if isinstance(param.default, np.ndarray): + return np.array(arg, dtype=param.default.dtype) + else: + return param.default.__class__(arg) + else: + return param.classType(arg) + + """ + attributes = {"__object_name": className, + "__revision_number": self.svn_revision_number, + "__revision_id": 'unknown', + "__revision_source": 'unknown', + "__revision_tag": 'unknown'} + """ + attributes = {} # Create new attributes dict for this particular class object + attributes.update(self.revision_dict) # Revision info now passed into the factory + attributes['__object_name'] = className + + def init(_self, *args, **kwargs): + """ Dynamically generated initializer. """ + + # meta-data goes in the class, not the objects (commented the following out): + """ + # Initialize automatic class data + for attr,value in attributes.items(): + try: + value = kwargs[attr] # Are we given a value to over-ride with? + del kwargs[attr] # Ignore the meta attribute later + except KeyError: + pass + setattr(_self, attr, value) + """ + + # Set default values first (assume no parameters): + for param in classData: + if param.length: + if isinstance(param.length, int): param.length = [param.length] + default = np.empty(param.length, dtype=param.classType) + if param.hasDefault: + # Initialize array with default array value given: + flatIter = default.flat + for i in range(len(flatIter)): + flatIter[i] = copy.deepcopy(param.default) + else: + # Initialize to None if no default given: + default.fill(None) + else: + default = param.default + setattr(_self, param.name, copy.deepcopy(default)) + + # Set attributes given by standard args: + for i in range(len(args)): + arg = typeCheck(classData[i], args[i]) + setattr(_self, classData[i].name, arg) + + # Set named attributes (given by dictionary kwargs): + for key,value in kwargs.items(): + + try: keyIndex = [param.name for param in classData].index(key) + except ValueError: + raise TypeError("'%s' is an invalid keyword argument"%(key,)) + arg = typeCheck(classData[keyIndex],value) + #setattr(_self, key, value) + setattr(_self, key, arg) + + + # Object instantiation / creation time (if not already present): + if not kwargs.has_key('__time_created'): + setattr(_self, "__time_created", np.float64(time.time())) + + return init, attributes + + def __findClass(self, className, localClasses): + """ Looks for the given className first in the given dictionary of localClasses + then in the global definitions, returning the corresponding class object. Raises + a KeyError if the class cannot be found. """ + + # If class definition was in the YAML file, extend that one: + if className in localClasses.keys(): + return localClasses[className] + + # Else try finding the class definition in our global scope: + try: classObj = get_class(className) + except KeyError: + raise KeyError("Class '%s' not found in given YAML scope or global scope."%(className,)) + return classObj + + def __buildClass(self, objDefn): + """ Takes an object definition list / dictionary objDefn (loaded from a YAML + object definition file) and creates a class, dynamically binding + method and data signatures to the new class. + + This method only performs a basic binding of method and data signatures to + the new class. Object(s) having more complex initialization requirements + should be given their own Factory subclass, overriding this + and other methods.""" + + # objDefn is a list of dictionaries found in the YAML file - build each one... + objClasses = dict() + objClassesRev = dict() + + # A list of all _Parameter objects created, used to resolve recursive + # or "tangled" data structures + allClassData = [] + + for document in objDefn: + # Each document can contain multiple objects - build each one. + # (NOTE: objects can cross reference each other in the same document + # need to resolve Reference objects as last step) + for objClassName in document.keys(): + + # The dictionary containing method & data signatures: + objDict = document[objClassName] + + # Extract data / attribute definitions (signatures) from the YAML dictionary + # as well as method signatures and which classes this class extends: + classData = [] + classMethods = dict() + classBases = [Object] + + # List structured documents result in a list of dicts each with one key: + if isinstance(objDict, list): keys = [param.keys()[0] for param in objDict] + # Otherwise the parameter names are just the keys of the dict + else: keys = objDict.keys() # if key not found, raises AttributeError + + for sigName in keys: + #print sigName + sig = objDict[sigName] + #for f in _BuiltinDtype.python_dtypes: print f.__class__ + if sigName == '__extends': + if isinstance(sig, str): + sig = [sig] + if isinstance(sig, list): + for className in sig: + newBase = self.__findClass(className, objClasses) + + # Remove Object extension if newBase extends it already: + if Object in classBases and Object in inspect.getmro(newBase): + classBases.remove(Object) + classBases += [newBase] + else: + raise TypeError("Incorrect format for extending classes - %s"%(sig,)) + elif isinstance(sig, BuiltinDtype): + classData.append(self.parseDataSignature(sigName, sig)) + elif isinstance(sig, Lookup.python_dtypes): + classData.append(self.__parsePythonType(sigName, sig)) + elif isinstance(sig, _Reference): + classData.append(self.__parseReferenceSignature(sigName, sig, objClasses)) + elif isinstance(sig, _Method): + classMethods[sigName] = self.parseMethodSignature(sigName, sig.yamlString) + elif isinstance(sig, (PrecisionTime.nsTime, PrecisionTime.psTime)): + classData.append(_Parameter(sigName, True, sig)) + elif isinstance(sig, _Parameter): # sig is already a parameter (we skipped a step) + sig.name = sigName # we didn't know the name during load time - fill that in now + classData.append(sig) + else: + msg = "Factory abstract base class doesn't " +\ + "support the following signature: %r \"%s\""%(sig.__class__,str(sig)) + print sig.__class__ + raise SignatureException(msg) + + # Built-in attribute for all Dynamic Objects: + classData.append(_Parameter('__time_created', classType=np.float64)) + + # Turn the object data / attributes into a usable __init__ method: + classMethods["__init__"], meta_attributes = self.__buildInitializer(objClassName, classData) + + # Keep a record of the _Parameters created for later type resolution + allClassData.extend(classData) + + """ + __automaticMethods = { + "getObjectName": lambda _self: getattr(_self, '__object_name'), + "getRevisionNumber": lambda _self: getattr(_self, '__revision_number'), + "getRevisionId": lambda _self: getattr(_self, '__revision_id'), + "getRevisionSource": lambda _self: getattr(_self, '__revision_source'), + "getRevisionTag": lambda _self: getattr(_self, '__revision_tag') + } + classMethods.update(__automaticMethods) + """ + + # Put the method signatures into a namespace for the new class, + # then dynamically build the class from this namespace. + classNamespace = classMethods + classNamespace["meta_attributes"] = meta_attributes + cls = type(str(objClassName), tuple(classBases), classNamespace) + objClasses[objClassName] = cls + objClassesRev['%s.%s'%(objClassName,cls.meta_attributes["__revision_number"])] = cls + + # Create and register a constructor (loading) and representer (dumping) for the new class cls + def construct_dynamic_object(loader, node): + kwargs = loader.construct_mapping(node) + # Remove revision control from loaded objects (info is in the class object!) + for arg in kwargs.keys(): + if arg in getattr(Object, 'getters') and arg != '__time_created': + del kwargs[arg] + return cls(**kwargs) + revision = cls.meta_attributes["__revision_number"] + DynamicYAML.Loader.add_constructor(u'!%s.%s'%(str(objClassName),revision), construct_dynamic_object) + + represent_dynamic_object = DynamicYAML.Dumper.represent_dynamic_object + DynamicYAML.Dumper.add_representer(cls, represent_dynamic_object) + + def findClass(className): + """ Search for the most recently added class object with given className """ + try: + return objClasses[className] # Look for reference to object in same YAML defn file: + except KeyError: + # Now look for reference to class object loaded from any YAML defn file, loading the + # most recent version / revision (number) of the definition + for dynClass in Object.dynamicClasses.keys()[::-1]: + if dynClass.startswith(className): + return Object.dynamicClasses[dynClass] + + # Still unresolved - raise exception: + allDynamicClasses = repr(objClasses.keys() + Object.dynamicClasses.keys()) + raise UnresolvedTypeException("Cannot resolve type '%s': Name not found in %s"%(className,allDynamicClasses)) + + + def resolve(param): + + # Reference is just a string - that's the class name: + if isinstance(param.classType.yamlObject, (str, unicode)): + className = str(param.classType.yamlObject) + param.classType = findClass(className) + return + + # Reference is a dict containing class name and / or default values: + if not isinstance(param.classType.yamlObject, dict): + raise UnresolvedTypeException("Cannot resolve reference of type '%s'"%(param.classType.yamlObject.__class__,)) + + # Definitely a dict: + refDict = param.classType.yamlObject + + # Determine the name of the class being referenced + try: + className = refDict["type"] + except KeyError: + raise KeyError("No 'type' key in reference dictionary for parameter '%s'"%(param.name,)) + + # Determine the class object corresponding to the class name + param.classType = findClass(className) + + try: + defaultParams = refDict["default"] + except KeyError: + defaultParams = None + + if defaultParams != None: + for sub_param in defaultParams: + if isinstance(sub_param.classType, _UnresolvedType): + resolve(sub_param) + param.default = param.classType( **defaultParams ) # Create the default object + param.hasDefault = True + else: + param.hasDefault = False # for good measure + + # Is it an object array?: + if "len" in refDict.keys(): + param.length = refDict["len"] + + # Resolve any unresolved data-types: + for param in allClassData: + if isinstance(param.classType, _UnresolvedType): + resolve(param) + + Object.dynamicClasses.update(objClassesRev) + return objClasses + +def load_defn(yaml): + """ Shortcut for producing a single DynamicObject class object from + the provided yaml definition in string format """ + return Factory(yaml=yaml).classes.values()[0] + + + diff --git a/schainpy/serializer/test/DynamicSerializer.py b/schainpy/serializer/test/DynamicSerializer.py new file mode 100644 index 0000000..34b0444 --- /dev/null +++ b/schainpy/serializer/test/DynamicSerializer.py @@ -0,0 +1,69 @@ +# +# rps 6/9/2014 +# mit haystack obs +# +# wrapper for Karl's code + +import DynamicObject # used for serial/deserial of complex python objects +import Serializer # used for serial/deserial of complex python + +# +class DynamicSerializer: + # + #------------------------------------------------------ + # + def __init__(self,which='yaml'): + # + # choices are: yaml, msgpack, hdf5, json + # + self.err_f = False + self.whichList = ['yaml', 'msgpack', 'hdf5', 'json'] # from Serialzer.py + self.err_f,self.serializer = self.initSerializer(which) + # + #------------------------------------------------------ + # + def initSerializer(self,which): + # + # calls REU student code that works but hasn't been walked-through + # it's a dynamic serializer not strictly a yaml serializer + # + err_f = False + match_f = False + serializer = None + ii = 0 + while ii < len(self.whichList): + if (self.whichList[ii] == which): + match_f = True + break + ii = ii + 1 + # end while + if not match_f: + err_f = True + else: + serializer = which + serializer = Serializer.serializers[serializer]() + + return err_f,serializer + # end initSerializer + # + # -------------------------------------------------- + # + def loads(self,element): # borrows name from json module (json - to - python) + retval = self.serializer.fromSerial(element) # de-serialize + return retval + # end loads + # + # -------------------------------------------------- + # + def dumps(self,element): # borrows name from json module (python - to - json) + retval = self.serializer.toSerial(element) # serialize + return retval + # end dumps + # + # -------------------------------------------------- + # +# end class DynamicSerializer + +if __name__ == "__main__": + DynamicSerializer() + print "DynamicSerializer ran" \ No newline at end of file diff --git a/schainpy/serializer/test/DynamicYAML.py b/schainpy/serializer/test/DynamicYAML.py new file mode 100644 index 0000000..f74cf98 --- /dev/null +++ b/schainpy/serializer/test/DynamicYAML.py @@ -0,0 +1,221 @@ +''' +Module containing YAML Loader and Dumper for DynamicObjects +as well as built-in data types (numpy, PrecisionTime, datetime, Binary, ...) + +$Id$ +''' + +import yaml +import OrderedYAML +import DynamicObject +import binascii +import numpy as np +import PrecisionTime +import Lookup +import pysvn + +def load_defn(source, rev='head', repo=""): + """ Import YAML definition(s) from given 'source' SVN location + with specific revision number 'rev'. Returns a dict of the object + names -> class object instances. + + NOTE: Object defns with same name & revision number will conflict / + cause issues (regardless of svn location). """ + client = pysvn.Client() + + if rev == 'head': + #yaml = client.cat(source) + rev = client.info(repo).revision.number + + if source.startswith('http'): + yaml = client.cat("%s?p=%d"%(source, rev)) + else: + pysvn_rev = pysvn.Revision(pysvn.opt_revision_kind.number, rev) + yaml = client.cat(source, pysvn_rev) + + revision_dict = {\ + "__revision_number": rev, + "__revision_id": 'unknown', + "__revision_source": source, + "__revision_tag": 'unknown'} + + return DynamicObject.Factory(yaml=yaml, revision_dict=revision_dict).classes + +class Loader(OrderedYAML.Loader): + + def __init__(self, stream): + OrderedYAML.Loader.__init__(self, stream) + + def construct_object(self, node, deep=False): + """ Unresolved tags on mapping nodes come from un-imported YAML definitions - import it """ + resolved = node.tag in self.yaml_constructors + resolved = resolved or any([node.tag.startswith(x) for x in self.yaml_multi_constructors]) + if isinstance(node, yaml.nodes.MappingNode) and not resolved: + data = self.construct_mapping(self, node) + self.constructed_objects[node] = data + del self.recursive_objects[node] + if data.has_key('__revision_source'): + # TODO: Handle password authentication + client = pysvn.Client() + source = data['__revision_source'] + if source.startswith('http'): + rev = data['__revision_number'] + defn = client.cat("%s?p=%d"%(source, rev)) + else: + rev = pysvn.Revision(pysvn.opt_revision_kind.number, data['__revision_number']) + defn = client.cat(source, revision=rev) + DynamicObject.Factory(yaml=defn) # Register the object + + constructor = self.yaml_constructors["%s.%s"%(data['__revision_name'], data['__revision_number'])] + return constructor(node) + else: + raise Exception("Cannot load object with tag '%s' - cannot find YAML object definition (no __revision_source included)") + else: + return yaml.Loader.construct_object(self, node, deep=deep) + +class Dumper(OrderedYAML.Dumper): + + def __init__(self, stream, *args, **kwargs): + OrderedYAML.Dumper.__init__(self, stream, *args, **kwargs) + + def represent_dynamic_object(self, obj): + """ + Override the !!python/object:__main__.xxx syntax with + !ObjectName.zzz where zzz is the revision number of the Object obj + """ + + state = {} + state.update(obj.__dict__.items()) + state.update(obj.__class__.meta_attributes.items()) + name = obj.getObjectName() # obj.__class__.__name__ + revision = obj.getRevisionNumber() + return self.represent_mapping(u'!%s.%s' % (name, revision), state) + +# Dtypes to be stored as hex in YAML streams / strings +hex_dtypes = ['float', 'complex', 'half', 'single', 'double'] + +# Register hex constructors for the numpy / built-in dtypes: +dtypes = Lookup.numpy_dtypes + +# Inverse lookup for accessing tags given a class instance: +cls_dtypes = dict([(v,k) for (k,v) in dtypes.items()]) + +# Representer for numpy arrays: +def ndarray_representer(dumper, obj): + #if isinstance(obj, np.ndarray): + tag = 'dtype.'+obj.dtype.type.__name__ + hexlify = any([x in tag for x in hex_dtypes]) + np_ary = obj + #hex_ary = np.empty(np_ary.shape, dtype=yaml.nodes.ScalarNode) + np_flat, hex_flat = np_ary.flat, [] #hex_ary.flat + hex_flat.append(dumper.represent_sequence(u'tag:yaml.org,2002:seq', list(np_ary.shape), flow_style=True)) + if hexlify: + lst = [] + for i in range(len(np_flat)): + value = u'%s'%(np_flat[i],) + node = dumper.represent_scalar(u'tag:yaml.org,2002:str', value, style='') + lst.append(node) + hex_flat.append(yaml.nodes.SequenceNode(u'tag:yaml.org,2002:seq', lst, flow_style=True)) + lst = [] + for i in range(len(np_flat)): + if hexlify: value = u'%s'%(binascii.hexlify(np_flat[i]),) + else: value = u'%s'%(np_flat[i],) + node = dumper.represent_scalar(u'tag:yaml.org,2002:str', value, style='') + if hexlify: lst.append(node) + else: hex_flat.append(node) + if hexlify: hex_flat.append(yaml.nodes.SequenceNode(u'tag:yaml.org,2002:seq', lst, flow_style=True)) + return yaml.nodes.SequenceNode(u'!%s'%(tag,), hex_flat, flow_style=True) +Dumper.add_representer(np.ndarray, ndarray_representer) + +# Constructor for ndarrays with arbitrary (specified) dtype: +def ndarray_constructor(loader, node, dtype, hexlify=False): + shape = loader.construct_sequence(node.value.pop(0)) + np_ary = np.empty(shape, dtype=dtype) + np_flat = np_ary.flat # Flat iterator + if hexlify: + node.value[1].tag = node.tag + node = node.value[1] # only look at hexlified values + for i in range(len(node.value)): + # Over-ride the 'tag:yaml.org,2002:str' tag with correct data type + node.value[i].tag = node.tag + value = loader.construct_object(node.value[i]) + #if hexlify: + # value = binascii.unhexlify(value) + # value = np.frombuffer(value, dtype=dtype) + np_flat[i] = value + return np_ary + +class __dtype_con: + + def __init__(self, tag): + # Whether or not to convert to hex: + hexlify = any([x in tag for x in hex_dtypes]) + dtype = dtypes[tag] + + # Mutable list containing constructor & representer info + self.fncn_attributes = [tag, hexlify, dtype] + + def dtype_constructor(loader, node): + tag, hexlify, dtype = self.fncn_attributes + if isinstance(node, yaml.nodes.SequenceNode): + return ndarray_constructor(loader, node, dtype, hexlify=hexlify) + else: # isinstance(node, yaml.nodes.ScalarNode): + value = loader.construct_scalar(node) + dtype = dtypes[node.tag[1:]] + if hexlify: + value = binascii.unhexlify(value) + value = np.frombuffer(value, dtype=dtype)[0] + else: + value = dtype(value) + return value + + def dtype_representer(dumper, obj): + tag, hexlify, dtype = self.fncn_attributes + if isinstance(obj, float): obj = np.float64(obj) + if hexlify: value = u'%s'%(binascii.hexlify(obj),) + else: value = u'%s'%(obj,) + try: tag = u'!%s'%(cls_dtypes[obj.__class__]) # 'dtype.'+obj.__class__.__name__ # bullshit... + except KeyError: tag = '' + node = dumper.represent_scalar(tag, value, style='') + return node + + self.dtype_constructor = dtype_constructor + self.dtype_representer = dtype_representer + +keys = [x for x in dtypes.keys() if x != 'dtype.int' and x != 'dtype.bool'] +print keys + +n = len(keys) +print n +i=0 + +for tag in keys: + dtype = __dtype_con(tag) + dtype_constructor = dtype.dtype_constructor + dtype_representer = dtype.dtype_representer + Loader.add_constructor(u'!%s'%(tag,), dtype_constructor) + Dumper.add_representer(dtypes[tag], dtype_representer) + +# Precision time constructors & representers: +def ns_rep(dumper, obj): + state = {'second': obj.__dict__['second'], 'nanosecond': obj.__dict__['nanosecond']} + return dumper.represent_mapping(u'!timestamp_ns', state) +def ps_rep(dumper, obj): + state = {'second': obj.__dict__['second'], 'picosecond': obj.__dict__['picosecond']} + return dumper.represent_mapping(u'!timestamp_ps', state) +def ns_con(loader, node): return PrecisionTime.nsTime(**loader.construct_mapping(node)) +def ps_con(loader, node): return PrecisionTime.psTime(**loader.construct_mapping(node)) + +Dumper.add_representer(PrecisionTime.nsTime, ns_rep) +Dumper.add_representer(PrecisionTime.psTime, ps_rep) +Loader.add_constructor(u'!timestamp_ns', ns_con) +Loader.add_constructor(u'!timestamp_nanosecond', ns_con) +Loader.add_constructor(u'!timestamp_ps', ps_con) +Loader.add_constructor(u'!timestamp_picosecond', ps_con) + +# Binary object constructor & representer: +def bin_rep(dumper, obj): return dumper.represent_mapping(u'!binary', obj.__dict__) +def bin_con(loader, node): return DynamicObject.Binary(**loader.construct_mapping(node)) +Dumper.add_representer(DynamicObject.Binary, bin_rep) +Loader.add_constructor(u'!binary', bin_con) + diff --git a/schainpy/serializer/test/Lookup.py b/schainpy/serializer/test/Lookup.py new file mode 100644 index 0000000..53ab278 --- /dev/null +++ b/schainpy/serializer/test/Lookup.py @@ -0,0 +1,62 @@ +''' +Helper module for DynamicObject module - contains dictionaries +of data types built-in to our YAML IDL, converting backing and forth between +strings / YAML tags and python class instances. + +$Id$ +''' + +import datetime +import numpy as np +import PrecisionTime +import DynamicObject +Binary = DynamicObject.Binary +import platform +import collections + +# Implicit Types: +python_dtypes = tuple([bool,int,long,float,str,datetime.datetime,list, + set,dict,tuple,unicode]) + +# Numpy Data-types: +numpy_dtypes = {'dtype.bool': bool, 'dtype.int': np.int, 'dtype.int8': np.int8, + 'dtype.int16': np.int16, 'dtype.int32': np.int32, 'dtype.int64': np.int64, + 'dtype.uint8': np.uint8, 'dtype.uint16': np.uint16, 'dtype.uint32': np.uint32, + 'dtype.uint64': np.uint64, 'dtype.float': np.float, 'dtype.float16': np.float16, + 'dtype.float32': np.float32, 'dtype.float64': np.float64, 'dtype.complex': np.complex, + 'dtype.complex64': np.complex64, 'dtype.complex128': np.complex128, + 'dtype.byte': np.byte, 'dtype.short': np.short, 'dtype.intc': np.intc, + 'dtype.longlong': np.longlong, 'dtype.intp': np.intp, 'dtype.ubyte': np.ubyte, + 'dtype.ushort': np.ushort, 'dtype.uintc': np.uintc, 'dtype.uint': np.uint, + 'dtype.uintc': np.uintc, 'dtype.uint': np.uint, 'dtype.ulonglong': np.ulonglong, + 'dtype.uintp': np.uintp, 'dtype.half': np.half, 'dtype.single': np.single, + 'dtype.double': np.double, 'dtype.longfloat': np.longfloat, + 'dtype.csingle': np.csingle, 'dtype.clongfloat': np.clongfloat, 'dtype.long': np.long} + +if platform.architecture()[0] != '32bit': # 64bit - certain numpy types exist + numpy_dtypes.update({'dtype.float128': np.float128, 'dtype.complex256': np.complex256}) + bit32 = False +else: + bit32 = True +#else: # 32 bit - fix 32 bit integer issue. +# np.int32 = np.int +# bit32 = True + +# Built-in objects: +builtin_objects = {'binary': Binary, 'nsTime': PrecisionTime.nsTime, 'psTime': PrecisionTime.psTime, + 'timestamp_ns': PrecisionTime.nsTime, 'timestamp_ps': PrecisionTime.psTime, + 'timestamp_nanosecond': PrecisionTime.nsTime, 'timestamp_picosecond': PrecisionTime.psTime, + 'datetime': datetime.datetime, 'Binary': Binary} + +builtin_objects_simple = {'nsTime': PrecisionTime.nsTime, 'psTime': PrecisionTime.psTime, + 'binary': Binary, 'datetime': datetime.datetime, + 'Binary': Binary} + +# Inverse lookup for accessing tags given a class instance: +cls_dtypes = dict([(v,k) for (k,v) in numpy_dtypes.items()]) +obj_dtypes = dict([(v,k) for (k,v) in builtin_objects_simple.items()]) + +# Pointer to the list of all Object classes created, as located in the Object module / class: +dynamicClasses = DynamicObject.Object.dynamicClasses + + diff --git a/schainpy/serializer/test/OrderedYAML.py b/schainpy/serializer/test/OrderedYAML.py new file mode 100644 index 0000000..711fd4f --- /dev/null +++ b/schainpy/serializer/test/OrderedYAML.py @@ -0,0 +1,89 @@ +''' +A YAML Loader and Dumper which provide ordered dictionaries in place +of dictionaries (to keep the order of attributes as +found in the original YAML object file). + +This module is modified from a submission on pyyaml.org: +http://pyyaml.org/attachment/ticket/161/use_ordered_dict.py + +$Id$ +''' + +import yaml +import collections + +class Loader(yaml.loader.Loader): + """ YAML Loader producing OrderedDicts in place of dicts """ + + def __init__(self, stream): + yaml.loader.Loader.__init__(self, stream) + + def construct_ordered_mapping(self, node, deep=False): + """ Replacement mapping constructor producing an OrderedDict """ + if not isinstance(node, yaml.MappingNode): + raise yaml.constructor.ConstructorError(None, None, + "expected a mapping node, but found %s" % node.id, + node.start_mark) + mapping = collections.OrderedDict() + for key_node, value_node in node.value: + key = self.construct_object(key_node, deep=deep) + if not isinstance(key, collections.Hashable): + raise yaml.constructor.ConstructorError("while constructing a mapping", node.start_mark, + "found unhashable key", key_node.start_mark) + value = self.construct_object(value_node, deep=deep) + mapping[key] = value + return mapping + # yaml.constructor.BaseConstructor.construct_mapping = construct_ordered_mapping + + def construct_mapping(self, node, deep=False): + return self.construct_ordered_mapping(node, deep=deep) + + def construct_yaml_map_with_ordered_dict(self, node): + data = collections.OrderedDict() + yield data + value = self.construct_mapping(node) + data.update(value) + +class Dumper(yaml.dumper.Dumper): + """ YAML Dumper producing documents from OrderedDicts """ + + def __init__(self, stream, *args, **kwargs): + yaml.dumper.Dumper.__init__(self, stream, *args, **kwargs) + + def represent_ordered_mapping(self, tag, mapping, flow_style=None): + """ Replacement mapping representer for OrderedDicts """ + value = [] + node = yaml.MappingNode(tag, value, flow_style=flow_style) + if self.alias_key is not None: + self.represented_objects[self.alias_key] = node + best_style = True + if hasattr(mapping, 'items'): + mapping = list(mapping.items()) + for item_key, item_value in mapping: + node_key = self.represent_data(item_key) + node_value = self.represent_data(item_value) + if not (isinstance(node_key, yaml.ScalarNode) and not node_key.style): + best_style = False + if not (isinstance(node_value, yaml.ScalarNode) and not node_value.style): + best_style = False + value.append((node_key, node_value)) + if flow_style is None: + if self.default_flow_style is not None: + node.flow_style = self.default_flow_style + else: + node.flow_style = best_style + return node + # yaml.representer.BaseRepresenter.represent_mapping = represent_ordered_mapping + + def represent_mapping(self, tag, mapping, flow_style=None): + return self.represent_ordered_mapping(tag, mapping, flow_style=flow_style) + +# Loader.add_constructor( +# u'tag:yaml.org,2002:map', +# Loader.construct_yaml_map_with_ordered_dict +# ) +# +# Dumper.add_representer( +# collections.OrderedDict, +# yaml.representer.SafeRepresenter.represent_dict +# ) diff --git a/schainpy/serializer/test/PrecisionTime.py b/schainpy/serializer/test/PrecisionTime.py new file mode 100644 index 0000000..205cf5b --- /dev/null +++ b/schainpy/serializer/test/PrecisionTime.py @@ -0,0 +1,211 @@ +#!/usr/local/midas/bin/python + +"""PrecisionTime.py is a collection of python classes to manipulate times with high +precision using integer logic. + +Written by "Bill Rideout":mailto:wrideout@haystack.mit.edu May 24, 2007 + +$Id$ +""" +import types + +class nsTime: + """nsTime is a class to handle times given as UT second (integer) and nanosecond (integer) + + If nanosecond > 1E9, seconds will be added to second + """ + + def __init__(self, second, nanosecond): + self.second = int(second) + if self.second < 0: + raise ValueError, 'seconds must be greater than 0, not %i' % (self.second) + nanosecond = long(nanosecond) + if nanosecond < 0: + raise ValueError, 'nanoseconds must be greater 0, not %i' % (nanosecond) + addSec = nanosecond / 1000000000 + if addSec > 0: + self.second += addSec + self.nanosecond = nanosecond % 1000000000 + self.totalNS = long(self.nanosecond) + long(self.second) * 1000000000 + + + def __add__(self, other): + """__add__ another nsTime to this one and return a new one as result + """ + nsResult = self.nanosecond + other.nanosecond + addSec = int(nsResult / 1000000000) + newSec = self.second + other.second + addSec + newNS = nsResult % 1000000000 + return(nsTime(newSec, newNS)) + + + def increase(self, other): + """increase adds other to self, changing self (rather than creating a new object) + """ + nsResult = self.nanosecond + other.nanosecond + addSec = int(nsResult / 1000000000) + self.second = self.second + other.second + addSec + self.nanosecond = nsResult % 1000000000 + self.totalNS = long(self.nanosecond) + long(self.second) * 1000000000 + + + def __sub__(self, other): + """__sub__ another nsTime from this one and return a new one as result + """ + nsResult = self.nanosecond - other.nanosecond + if nsResult < 0: + addSec = 1 + nsResult += 1000000000 + else: + addSec = 0 + newSec = (self.second - other.second) - addSec + return(nsTime(newSec, nsResult)) + + + def multiply(self, factor): + """multiply this nsTime times an integer + """ + if type(factor) not in (types.IntType, types.LongType): + raise ValueError, 'Illegal type %s passed into nsTime.multiply' % (str(type(factor))) + newTotalNS = self.totalNS * factor + newSeconds = int(newTotalNS / 1000000000) + newNanoseconds = int(newTotalNS - (newSeconds * 1000000000)) + return(nsTime(newSeconds, newNanoseconds)) + + + def integerDivision(self, other): + """integerDivision returns the total number of other nsTimes that fit in self + """ + return(int(self.totalNS / other.totalNS)) + + def getUnixTime(self): + """ getUnixTime() returns a Unix style time as a float. """ + return(float(self.second) + float(self.nanosecond)/1.0e9) + + def __mod__(self, other): + """__mod__ implements self % other. + """ + if type(other) in (types.IntType, types.LongType): + return self.totalNS % other + else: + return self.totalNS % other.totalNS + + def __eq__(self, other): + """ equality of two nsTime objects """ + if not (hasattr(other, 'second') and hasattr(other, 'nanosecond')): return False + return self.__cmp__(other) == 0 + + def __cmp__(self, other): + """compare two nsTime objects + """ + result = cmp(self.second, other.second) + if result != 0: + return(result) + + return(cmp(self.nanosecond, other.nanosecond)) + + + def __str__(self): + return '%d.%09d' % (self.second, self.nanosecond) + + +class psTime: + """psTime is a class to handle times given as UT second (integer) and picosecond (integer) + + If picosecond > 1E12, seconds will be added to second + """ + + def __init__(self, second, picosecond): + self.second = int(second) + if self.second < 0: + raise ValueError, 'seconds must be greater than 0, not %i' % (self.second) + picosecond = long(picosecond) + if picosecond < 0: + raise ValueError, 'picoseconds must be greater 0, not %i' % (picosecond) + addSec = picosecond / 1000000000000 + if addSec > 0: + self.second += addSec + self.picosecond = picosecond % 1000000000000 + self.totalPS = long(self.picosecond) + long(self.second) * 1000000000000 + + + def __add__(self, other): + """__add__ another psTime to this one and return a new one as result + """ + psResult = self.picosecond + other.picosecond + addSec = int(psResult / 1000000000000) + newSec = self.second + other.second + addSec + newPS = psResult % 1000000000000 + return(psTime(newSec, newPS)) + + + def increase(self, other): + """increase adds other to self, changing self (rather than creating a new object) + """ + psResult = self.picosecond + other.picosecond + addSec = int(psResult / 1000000000000) + self.second = self.second + other.second + addSec + self.picosecond = psResult % 1000000000000 + self.totalPS = long(self.picosecond) + long(self.second) * 1000000000000 + + + def __sub__(self, other): + """__sub__ another psTime from this one and return a new one as result + """ + psResult = self.picosecond - other.picosecond + if psResult < 0: + addSec = 1 + psResult += 1000000000000 + else: + addSec = 0 + newSec = (self.second - other.second) - addSec + return(psTime(newSec, psResult)) + + + def multiply(self, factor): + """multiply this psTime times an integer + """ + if type(factor) not in (types.IntType, types.LongType): + raise ValueError, 'Illegal type %s passed into psTime.multiply' % (str(type(factor))) + newTotalPS = self.totalPS * factor + newSeconds = int(newTotalPS / 1000000000000) + newPicoseconds = int(newTotalPS - (newSeconds * 1000000000000)) + return(psTime(newSeconds, newPicoseconds)) + + + def integerDivision(self, other): + """integerDivision returns the total number of other psTimes that fit in self + """ + return(int(self.totalPS / other.totalPS)) + + def getUnixTime(self): + """ getUnixTime() returns a Unix style time as a float. """ + return(float(self.second) + float(self.picosecond)/1.0e12) + + def __mod__(self, other): + """__mod__ implements self % other. + """ + if type(other) in (types.IntType, types.LongType): + return self.totalPS % other + else: + return self.totalPS % other.totalPS + + def __eq__(self, other): + """ equality of two psTime objects """ + if not (hasattr(other, 'second') and hasattr(other, 'picosecond')): return False + return self.__cmp__(other) == 0 + + def __cmp__(self, other): + """compare two psTime objects + """ + result = cmp(self.second, other.second) + if result != 0: + return(result) + + return(cmp(self.picosecond, other.picosecond)) + + + def __str__(self): + return '%d.%12d' % (self.second, self.picosecond) + + diff --git a/schainpy/serializer/test/Serializer.py b/schainpy/serializer/test/Serializer.py new file mode 100644 index 0000000..9201f6c --- /dev/null +++ b/schainpy/serializer/test/Serializer.py @@ -0,0 +1,373 @@ +''' +Module containing classes with serialization and de-serialization services. + +$Id$ +''' + +import Lookup +import numpy as np +import zlib +import binascii +import yaml +import DynamicObject +import DynamicYAML +import PrecisionTime +import datetime +import re +import os +#import json +import jsonpickle +import jpickle +import h5py +import msgpack + +class CompressionException(Exception): pass + +class Serializer: + """ Base class for pickle-like serialization + of DynamicObjects (with compression available) """ + + def __init__(self): + pass + + def dump(self, obj, file_name, compression=None): + """ Dumps obj to file_name, serializing the obj with toSerial() """ + string = self.dumps(obj, compression) + open(file_name, 'w').write(string) + + def dumps(self, obj, compression=None): + """ Returns serialized string representing obj, using toSerial() to serialize """ + if compression == 'gzip': + return zlib.compress(self.toSerial(obj)) + elif compression in [None, '']: + return self.toSerial(obj) + else: + raise CompressionException("Invalid decompression type '%r'"%(compression,)) + + def load(self, file_name, compression=None): + """ Returns the Object located in file_name, using fromSerial() to deserialize """ + string = open(file_name, 'r').read() + return self.loads(string, compression) + + def loads(self, string, compression=None): + """ Returns the Object serialized as the given string """ + if compression == 'gzip': + return self.fromSerial(zlib.decompress(string)) + elif compression in [None, '']: + return self.fromSerial(string) + else: + raise CompressionException("Invalid compression type '%r'"%(compression,)) + + def fromSerial(self, string): + """ Deserializes the given string """ + return string + + def toSerial(self, obj): + """ Serializes the given object """ + return repr(obj) + +class YAMLSerializer(Serializer): + """ Serializes a Object to/from YAML format """ + + def __init__(self): + Serializer.__init__(self) + + def fromSerial(self, string): + loader = DynamicYAML.Loader + return yaml.load(string, Loader=loader) + + def toSerial(self, obj): + dumper = DynamicYAML.Dumper + return yaml.dump(obj, Dumper=dumper) + +# Regular expression taken from yaml.constructor.py +timestamp_regexp_str = str(\ + ur'^(?P[0-9][0-9][0-9][0-9])' + ur'-(?P[0-9][0-9]?)' + ur'-(?P[0-9][0-9]?)' + ur'(?:(?:[Tt]|[ \t]+)' + ur'(?P[0-9][0-9]?)' + ur':(?P[0-9][0-9])' + ur':(?P[0-9][0-9])' + ur'(?:\.(?P[0-9]*))?' + ur'(?:[ \t]*(?PZ|(?P[-+])(?P[0-9][0-9]?)' + ur'(?::(?P[0-9][0-9]))?))?)?$') +timestamp_regexp = re.compile(timestamp_regexp_str, re.X) + +def construct_timestamp(value): + """ Taken & modified from yaml.constructor.py """ + + match = timestamp_regexp.match(value) + #print "&%s&"%(value,) + #print timestamp_regexp_str + values = match.groupdict() + year = int(values['year']) + month = int(values['month']) + day = int(values['day']) + if not values['hour']: + return datetime.date(year, month, day) + hour = int(values['hour']) + minute = int(values['minute']) + second = int(values['second']) + fraction = 0 + if values['fraction']: + fraction = values['fraction'][:6] + while len(fraction) < 6: + fraction += '0' + fraction = int(fraction) + delta = None + if values['tz_sign']: + tz_hour = int(values['tz_hour']) + tz_minute = int(values['tz_minute'] or 0) + delta = datetime.timedelta(hours=tz_hour, minutes=tz_minute) + if values['tz_sign'] == '-': + delta = -delta + data = datetime.datetime(year, month, day, hour, minute, second, fraction) + if delta: + data -= delta + return data + +class MessagePackSerializer(Serializer): + """ Serializes a Object to/from MessagePack format """ + + def __fromSerial(self, msg_dict): + if not isinstance(msg_dict, (dict, list, tuple)): + return msg_dict # msg_dict is a value - return it + if isinstance(msg_dict, dict) and msg_dict.has_key('__meta_attributes'): + meta_attr = msg_dict['__meta_attributes'] + msg_dict.pop('__meta_attributes') + if meta_attr.has_key('type'): + if meta_attr['type'] == 'datetime': + return construct_timestamp(str(msg_dict['ts'])) + elif meta_attr['type'] == 'nsTime': + msg_dict.pop('totalNS') + elif meta_attr['type'] == 'psTime': + msg_dict.pop('totalPS') + try: dtype = Lookup.cls_dtypes[meta_attr['type']] + except KeyError: dtype = Lookup.builtin_objects[meta_attr['type']] + return dtype(**msg_dict) + else: + for key in msg_dict.keys(): + msg_dict[key] = self.__fromSerial(msg_dict[key]) + cls = Lookup.dynamicClasses['%s.%s'%(meta_attr['__object_name'],meta_attr['__revision_number'])] + return cls(**msg_dict) + elif msg_dict == (): + return [] + elif isinstance(msg_dict[0], str) and msg_dict[1] in Lookup.numpy_dtypes and\ + isinstance(msg_dict, tuple) and len(msg_dict) == 2: + value = binascii.unhexlify(msg_dict[0]) + return np.frombuffer(value, dtype=Lookup.numpy_dtypes[msg_dict[1]])[0] + + tup = isinstance(msg_dict, tuple) + if tup and len(msg_dict) > 1 and msg_dict[0] in Lookup.numpy_dtypes.keys(): + msg_flat = list(msg_dict) + dtypeName = msg_flat.pop(0) + dtype = Lookup.numpy_dtypes[dtypeName] + shape = msg_flat.pop(0) + obj = np.empty(shape, dtype=dtype) + np_flat = obj.flat + for i in range(len(np_flat)): + if isinstance(msg_flat[i], float): + value = msg_flat[i] + else: + value = self.__fromSerial((msg_flat[i], dtypeName)) + np_flat[i] = value + return obj + else: + return msg_dict + + def fromSerial(self, string): + msg_dict = msgpack.unpackb(string) + return self.__fromSerial(msg_dict) + + def __toSerial(self, obj): + + if isinstance(obj, (PrecisionTime.nsTime, PrecisionTime.psTime, DynamicObject.Binary, datetime.datetime)): + msg_dict = {} + if isinstance(obj, datetime.datetime): + msg_dict['ts'] = obj.isoformat(' ') + else: + msg_dict.update(obj.__dict__) + msg_dict['__meta_attributes'] = {'type': obj.__class__.__name__} + return msg_dict + elif isinstance(obj, DynamicObject.Object): + msg_dict = {} + for key, value in obj.__dict__.items(): + msg_dict[key] = self.__toSerial(value) + + msg_dict['__meta_attributes'] = obj.__class__.meta_attributes + return msg_dict + elif isinstance(obj, np.ndarray): + np_flat = obj.flat + msg_flat = [] + msg_flat.append(Lookup.cls_dtypes[obj.dtype.type]) # dtype is first element + msg_flat.append(obj.shape) # shape of array is second element + for i in range(len(np_flat)): + toSer = self.__toSerial(np_flat[i]) + if isinstance(toSer, tuple): + msg_flat.append(toSer[0]) + else: + msg_flat.append(toSer) + return list(msg_flat) + + is_builtin = obj.__class__ in Lookup.numpy_dtypes.values() + #is_python = isinstance(obj, Lookup.python_dtypes) + if is_builtin: # and not is_python: + try: + #print obj.__class__ + msg_dict = (binascii.hexlify(obj), Lookup.cls_dtypes[obj.__class__]) + return msg_dict + except TypeError: # numpy dtype is a built-in python type... force the hexlify: + if not Lookup.bit32: + if obj.__class__ == int: return (binascii.hexlify(np.int64(obj)), 'dtype.int64') + elif obj.__class__ == float: return (binascii.hexlify(np.float64(obj)), 'dtype.float64') + else: + #print np.int32(obj).__class__, obj.__class__ + if obj.__class__ == int: return (binascii.hexlify(np.int32(obj)), 'dtype.int32') + elif obj.__class__ == float: return (binascii.hexlify(np.float32(obj)), 'dtype.float32') + raise + else: + return obj + + def toSerial(self, obj): + #if Lookup.bit32 and np.int32 != np.int: np.int32 = np.int + toSer = self.__toSerial(obj) + #print toSer + value = msgpack.packb(toSer) + return value + +class HDF5Serializer(Serializer): + """ Serializes a Object to/from HDF5 format """ + + tmp_num = 0 + + def __fromSerial(self, grp): + + if isinstance(grp, h5py.Dataset): + return grp.value + + elif isinstance(grp, h5py.Group) and '__type' in grp.keys(): + typ = grp['__type'].value + if typ == 'datetime': + return construct_timestamp(str(grp['ts'].value)) + elif typ == '_null': + return None + elif typ == 'tuple': + return tuple(grp['tuple']) + elif typ == 'empty_list': + return [] + try: cls = Lookup.builtin_objects_simple[typ] + except KeyError: cls = Lookup.dynamicClasses[typ] + args = [] + for key in grp.keys(): + fromSer = self.__fromSerial(grp[key]) + args.append((key, fromSer)) + kwargs = dict(args) + kwargs.pop('__type') + return cls(**kwargs) + #else: + # return grp.value + + + def fromSerial(self, string): + HDF5Serializer.tmp_num += 1 + fn = 'tmp%d.hdf5'%(HDF5Serializer.tmp_num-1,) + fp = open(fn, 'wb') + fp.write(string) + fp.flush(), fp.close() + + root = h5py.File(fn, driver='core') + try: + fromSer = self.__fromSerial(root['dataset']) + except: + root.flush(), root.close() + os.remove(fn) + raise + + root.flush(), root.close() + os.remove(fn) + + return fromSer + + def __toSerial(self, obj, grp, name): + + if isinstance(obj, datetime.datetime): + sub_grp = grp.create_group(name) + sub_grp['__type'] = 'datetime' + sub_grp['ts'] = obj.isoformat(' ') + + elif isinstance(obj, tuple(Lookup.builtin_objects_simple.values())): + sub_grp = grp.create_group(name) + sub_grp['__type'] = Lookup.obj_dtypes[obj.__class__] + for key, value in obj.__dict__.items(): + if value != None and key not in ['totalNS', 'totalPS']: + sub_grp[key] = value + + elif obj == None: + sub_grp = grp.create_group(name) + sub_grp['__type'] = '_null' + + elif isinstance(obj, DynamicObject.Object): + # Create the new group and assign unique identifier for this type of DynamicObject + sub_grp = grp.create_group(name) + tag = '%s.%s'%(obj.getObjectName(), obj.getRevisionNumber()) + sub_grp['__type'] = tag + # Put all of the DynamicObject's attributes into the new h5py group + for key, value in obj.__dict__.items(): + self.__toSerial(value, sub_grp, key) + + elif isinstance(obj, tuple): + sub_grp = grp.create_group(name) + sub_grp['__type'] = 'tuple' + sub_grp['tuple'] = obj + + elif isinstance(obj, list) and len(obj) == 0: + sub_grp = grp.create_group(name) + sub_grp['__type'] = 'empty_list' + + else: + grp[name] = obj + + def toSerial(self, obj): + HDF5Serializer.tmp_num += 1 + fn = 'tmp%d.hdf5'%(HDF5Serializer.tmp_num,) + root = h5py.File(fn, driver='core') + try: + self.__toSerial(obj, root, 'dataset') + except: + root.flush(), root.close() + os.remove(fn) + raise + root.flush(), root.close() + + fp = open(fn, 'rb') + msg = fp.read() + fp.close() + os.remove(fn) + + return msg + +# Alias for the standard json serializer: +class jsonSerializer(Serializer): + def fromSerial(self, string): + #return json.loads(string) + return jsonpickle.decode(string) + def toSerial(self, string): + #return json.dumps(string) + return jsonpickle.encode(string, max_depth=500) + +# Dict mapping from serializer type to corresponding class object: +serializers = {'yaml': YAMLSerializer, + 'msgpack': MessagePackSerializer, + 'hdf5': HDF5Serializer, + 'json': jsonSerializer} + +instances = {'yaml': YAMLSerializer(), + 'msgpack': MessagePackSerializer(), + 'hdf5': HDF5Serializer(), + 'json': jsonSerializer()} + +serial_types = dict([(v,u) for u,v in serializers.items()]) + +compression_types = ['gzip', ''] + diff --git a/schainpy/serializer/test/__init__.py b/schainpy/serializer/test/__init__.py new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/schainpy/serializer/test/__init__.py diff --git a/schainpy/serializer/test/serialtest.py b/schainpy/serializer/test/serialtest.py new file mode 100644 index 0000000..0b8ded6 --- /dev/null +++ b/schainpy/serializer/test/serialtest.py @@ -0,0 +1,187 @@ + +# +# when Serializer is imported alone, fault indicates this package is +# dependent on lookup, but don't import Lookup, instead: +# +import DynamicObject # dependent on pysvn +import Serializer # dependent on Dynamic Object + +import msgpack +import redis + +import numpy as np + +class NamedObject(): + + #--------------------------------------------- + @staticmethod + def indexListMatch(list_of_lists, name, value, name2=None, value2=None, unique_f=False): + # + # for each list's attribute compare with value + # if match, return True plus list + # else return False plus empty list + # + # search needs to be named part of class for object else . is unrecognized + # + # unique_f finds non-uniqueness + + + index = [] # return empty indices + list_data = [] # return empty list + ii = 0 + for theList in list_of_lists: + + cmd0 = "theList.%s == value" % (name) + cmd1 = "isInlist(theList.%s,value)" % name + # if name is valid then + # match name against value + # match name (as list) against value + if (eval(cmd0) or eval(cmd1)): + if (name2 != None): + cmd2 = "theList.%s == value2" % name2 + cmd3 = "isInlist(theList.%s,value2)" % name2 + if (eval(cmd2) or eval(cmd3)): + if (unique_f): + index = index + [ii] + list_data = list_data + [theList] # save list of lists if non-unique + # don't exit on match, may be non-unique + else: + list_data = theList # save the list + index = [ii] + break + else: + if (unique_f): + index = index + [ii] + list_data = list_data + [theList] # list of lists if non-unique + else: + list_data = theList + index = [ii] + break # exit on match + #endif + ii = ii + 1 + #end for + + return index, list_data # return indices of matches and list (or list of lists) + + #end indexListMatch + + #--------------------------------------------- + @staticmethod + def namedListMatch(list_of_lists, name, value, name2=None, value2=None, unique_f=None): + # + # for each list's attribute compare with value + # if match, return True plus list + # else return False plus empty list + # + # search needs to be named part of class for object else . is unrecognized + # + # unique_f finds non-uniqueness ('None' is same as False) + + match_f = False + list_data = [] # initialize + + for theList in list_of_lists: + + cmd0 = "theList.%s == value" % (name) + cmd1 = "isInlist(theList.%s,value)" % name + # if name is valid then + # match name against value + # match name (as list) against value + if (eval(cmd0) or eval(cmd1)): + if (name2 != None): + cmd2 = "theList.%s == value2" % name2 + cmd3 = "isInlist(theList.%s,value2)" % name2 + if (eval(cmd2) or eval(cmd3)): + match_f = True + if (unique_f): + list_data = list_data + [theList] # save list of lists if non-unique + # don't exit on match, may be non-unique + else: + list_data = theList # save the list + break + else: + match_f = True + if (unique_f): + list_data = list_data + [theList] # list of lists if non-unique + else: + list_data = theList + break # exit on match + #endif + #end for + + return match_f, list_data # return match, and list (or list of lists) + + #end namedListMatch + + #--------------------------------------------- + @staticmethod + def combineLists(object): + # + # used for dumping elements in list of lists for debugging + # + ret_list =[] + ii = 0 + while ii < len(object): + ret_list = ret_list + [object[ii].list] # not a real list, so can't use built-in list iterator + ii = ii + 1 + return ret_list + + # end combineLists + + + +class StateListObject(NamedObject): + def __init__(self, concurrent=None, hierarchical=None, history=None, state=None): + self.concurrent = concurrent + self.hierarchical = hierarchical + self.history = history + self.state = state + self.list = [self.concurrent, self.hierarchical, self.history, self.state ] +#end class StateListObject + +source_object = "my test string" + +serializer = "yaml" +# +# python versioning issue (ver 2.7 -> else path) +# +if isinstance(serializer,Serializer.Serializer): + serial_type = Serializer.serial_types[serializer] +else: + serial_type = serializer + serializer = Serializer.serializers[serializer]() + + + +datastr = serializer.toSerial(source_object) + +dest_object = serializer.fromSerial(datastr) + +print "dest_object=",dest_object + +myObject = StateListObject(hierarchical="yes",state=np.array([1,2,3.0])) + +datastr = serializer.toSerial(myObject) + +packed = msgpack.packb(datastr) + +try: + r= redis.StrictRedis(host='localhost',port=6379,db=0) +except Exception as eobj: + print "is the redis server running?",eobj +else: + + r.set('baz',packed) # converts to string + x = r.get('baz') + +unpacked = msgpack.unpackb(x) + +dest_object = serializer.fromSerial(unpacked) + +print "val1=",dest_object.hierarchical +val2 = dest_object.state +print "val2=",val2 +# can numpy array be used as array? +print val2.shape + + diff --git a/schainpy/serializer/test/test _serializer_speed.py b/schainpy/serializer/test/test _serializer_speed.py new file mode 100644 index 0000000..5b891d3 --- /dev/null +++ b/schainpy/serializer/test/test _serializer_speed.py @@ -0,0 +1,175 @@ +''' +Created on Jul 16, 2014 + +@author: roj-idl71 +''' +""" +Dependencies: + + pip install tabulate simplejson python-cjson ujson yajl msgpack-python + +""" + +from timeit import timeit +from tabulate import tabulate + +setup = '''d = { + 'words': """ + Lorem ipsum dolor sit amet, consectetur adipiscing + elit. Mauris adipiscing adipiscing placerat. + Vestibulum augue augue, + pellentesque quis sollicitudin id, adipiscing. + """, + 'boolean' : False, + 'list': range(10), + 'dict': dict((str(i),'a') for i in xrange(10)), + 'int': 100, + 'float': 100.123456, +}''' + +setup = '''import numpy; +import datetime; +d = { + 'words': """ + Lorem ipsum dolor sit amet, consectetur adipiscing + elit. Mauris adipiscing adipiscing placerat. + Vestibulum augue augue, + pellentesque quis sollicitudin id, adipiscing. + """, + 'boolean' : False, + 'list': range(10), + 'dict': dict((str(i),'a') for i in xrange(10)), + 'int': 100, + 'float': 100.123456, + 'datetime' : datetime.datetime(2001,1,1,10,10,10) +}''' + + +setup_pickle = '%s ; import pickle ; src = pickle.dumps(d)' % setup +setup_pickle2 = '%s ; import pickle ; src = pickle.dumps(d, 2)' % setup +setup_cpickle = '%s ; import cPickle ; src = cPickle.dumps(d)' % setup +setup_cpickle2 = '%s ; import cPickle ; src = cPickle.dumps(d, 2)' % setup +setup_json = '%s ; import json; src = json.dumps(d)' % setup +setup_ujson = '%s ; import ujson; src = ujson.encode(d)' % setup +setup_cjson = '%s ; import cjson; src = cjson.encode(d)' % setup +setup_simplejson = '%s ; import simplejson; src = simplejson.dump(d)' % setup +setup_jsonpickle = '%s ; import jsonpickle; src = jsonpickle.encode(d)' % setup +setup_yaml = '%s ; import yaml; src = yaml.dump(d)' % setup +setup_msgpack = '%s ; import msgpack; src = msgpack.dumps(d)' % setup +setup_msgpack_np = '%s; import msgpack_numpy as msgpack; src = msgpack.dumps(d)' % setup + +tests = [ + # (title, setup, enc_test, dec_test, result) + ('cPickle (binary)', 'import cPickle; %s' % setup_cpickle2, 'cPickle.dumps(d, 2)', 'r = cPickle.loads(src)', 'print r'), + ('cPickle (ascii)', 'import cPickle; %s' % setup_cpickle, 'cPickle.dumps(d, 0)', 'r = cPickle.loads(src)', 'print r'), + ('pickle (binary)', 'import pickle; %s' % setup_pickle2, 'pickle.dumps(d, 2)', 'r = pickle.loads(src)', 'print r'), + ('pickle (ascii)', 'import pickle; %s' % setup_pickle, 'pickle.dumps(d, 0)', 'r = pickle.loads(src)', 'print r'), + ('jsonpickle', 'import jsonpickle; %s' % setup_jsonpickle, 'jsonpickle.encode(d)', 'r = jsonpickle.decode(src)', 'print r'), +# ('msgpack-numpy-python', '%s' % setup_msgpack_np, 'msgpack.dumps(d)', 'r = msgpack.loads(src)', 'print r'), + ('ujson', 'import ujson; %s' % setup_ujson, 'ujson.encode(d)', 'r = ujson.decode(src)', 'print r'), +# ('msgpack-python', 'import msgpack; %s' % setup_msgpack, 'msgpack.dumps(d)', 'r = msgpack.loads(src)', 'print r'), +# ('json', 'import json; %s' % setup_json, 'json.dumps(d)', 'r = json.loads(src)', 'print r'), +# ('python-cjson-1.0.5', 'import cjson; %s' % setup_cjson, 'cjson.encode(d)', 'r = cjson.decode(src)', 'print r'), +# ('simplejson-3.3.1', 'import simplejson; %s' % setup_json, 'simplejson.dumps(d)', 'r = simplejson.loads(src)', 'print r'), + ('yaml', 'import yaml; %s' % setup_yaml, 'yaml.dump(d)', 'r = yaml.load(src)', 'print r'), +] + +loops = 1 +enc_table = [] +dec_table = [] + +print "Running tests (%d loops each)" % loops + +for title, mod, enc, dec, msg in tests: + print title + + ### Getting the package size + exec mod + size = len("".join(src)) + + print " [Encode]", enc + result = timeit(enc, mod, number=loops) + enc_table.append([title, result, size]) + + print " [Decode]", dec + result = timeit(dec, mod, number=loops) + dec_table.append([title, result]) + + print " Result" + result = timeit(msg, mod+';'+dec, number=1) + +enc_table.sort(key=lambda x: x[1]) +enc_table.insert(0, ['Package', 'Seconds', 'Size']) + +dec_table.sort(key=lambda x: x[1]) +dec_table.insert(0, ['Package', 'Seconds']) + +print "\nEncoding Test (%d loops)" % loops +print tabulate(enc_table, headers="firstrow") + +print "\nDecoding Test (%d loops)" % loops +print tabulate(dec_table, headers="firstrow") + +""" +OUTPUT: + +Running tests (15000 loops each) +pickle (ascii) + [Encode] pickle.dumps(d, 0) + [Decode] pickle.loads(src) +pickle (binary) + [Encode] pickle.dumps(d, 2) + [Decode] pickle.loads(src) +cPickle (ascii) + [Encode] cPickle.dumps(d, 0) + [Decode] cPickle.loads(src) +cPickle (binary) + [Encode] cPickle.dumps(d, 2) + [Decode] cPickle.loads(src) +json + [Encode] json.dumps(d) + [Decode] json.loads(src) +simplejson-3.3.1 + [Encode] simplejson.dumps(d) + [Decode] simplejson.loads(src) +python-cjson-1.0.5 + [Encode] cjson.encode(d) + [Decode] cjson.decode(src) +ujson-1.33 + [Encode] ujson.dumps(d) + [Decode] ujson.loads(src) +yajl 0.3.5 + [Encode] yajl.dumps(d) + [Decode] yajl.loads(src) +msgpack-python-0.3.0 + [Encode] msgpack.dumps(d) + [Decode] msgpack.loads(src) + +Encoding Test (15000 loops) +Package Seconds +-------------------- --------- +ujson-1.33 0.232215 +msgpack-python-0.3.0 0.241945 +cPickle (binary) 0.305273 +yajl 0.3.5 0.634148 +python-cjson-1.0.5 0.680604 +json 0.780438 +simplejson-3.3.1 1.04763 +cPickle (ascii) 1.62062 +pickle (ascii) 14.0497 +pickle (binary) 15.4712 + +Decoding Test (15000 loops) +Package Seconds +-------------------- --------- +msgpack-python-0.3.0 0.240885 +cPickle (binary) 0.393152 +ujson-1.33 0.396875 +python-cjson-1.0.5 0.694321 +yajl 0.3.5 0.748369 +simplejson-3.3.1 0.780531 +cPickle (ascii) 1.38561 +json 1.65921 +pickle (binary) 5.20554 +pickle (ascii) 17.8767 +""" \ No newline at end of file diff --git a/schainpy/test/EWDriftsApp.py b/schainpy/test/EWDriftsApp.py deleted file mode 100644 index 8a520d3..0000000 --- a/schainpy/test/EWDriftsApp.py +++ /dev/null @@ -1,117 +0,0 @@ -import os, sys - -path = os.path.split(os.getcwd())[0] -sys.path.append(path) - -from controller import * - -desc = "EWDrifts Experiment Test" -filename = "ewdrifts2.xml" - -controllerObj = Project() - -controllerObj.setup(id = '191', name='test01', description=desc) - -path='/remote/ewdrifts/RAW_EXP/EW_DRIFT_FARADAY/EW_Drift' - - -path = '/home/signalchain/Puma/2014_07/EW_Drift' - -readUnitConfObj = controllerObj.addReadUnit(datatype='VoltageReader', - path=path, - startDate='2014/07/01', - endDate='2014/07/30', - startTime='00:00:00', - endTime='23:59:59', - online=0, - delay=5, - walk=0) - -opObj11 = readUnitConfObj.addOperation(name='printNumberOfBlock') - -procUnitConfObj0 = controllerObj.addProcUnit(datatype='VoltageProc', inputId=readUnitConfObj.getId()) - -opObj11 = procUnitConfObj0.addOperation(name='ProfileSelector', optype='other') -opObj11.addParameter(name='profileRangeList', value='0,127', format='intlist') - -opObj11 = procUnitConfObj0.addOperation(name='filterByHeights') -opObj11.addParameter(name='window', value='3', format='int') - -opObj11 = procUnitConfObj0.addOperation(name='Decoder', optype='other') - -procUnitConfObj1 = controllerObj.addProcUnit(datatype='SpectraProc', inputId=procUnitConfObj0.getId()) -procUnitConfObj1.addParameter(name='nFFTPoints', value='128', format='int') -procUnitConfObj1.addParameter(name='nProfiles', value='128', format='int') - - -opObj11 = procUnitConfObj1.addOperation(name='IncohInt', optype='other') -opObj11.addParameter(name='timeInterval', value='60', format='float') - -opObj11 = procUnitConfObj1.addOperation(name='SpectraPlot', optype='other') -opObj11.addParameter(name='id', value='100', format='int') -opObj11.addParameter(name='wintitle', value='SpectraPlot', format='str') -# #opObj11.addParameter(name='channelList', value='0,1,2,3', format='intlist') -# # opObj11.addParameter(name='zmin', value='0', format='int') -# # opObj11.addParameter(name='zmax', value='100', format='int') -# opObj11.addParameter(name='showprofile', value='0', format='int') -# opObj11.addParameter(name='save', value='1', format='bool') -# opObj11.addParameter(name='figpath', value='/Users/dsuarez/Pictures/tr', format='str') -# -# -# opObj11 = procUnitConfObj1.addOperation(name='Noise', optype='other') -# opObj11.addParameter(name='id', value='101', format='int') -# opObj11.addParameter(name='wintitle', value='TR800KW', format='str') -# opObj11.addParameter(name='xmin', value='10', format='float') -# opObj11.addParameter(name='xmax', value='11.5', format='float') -# opObj11.addParameter(name='ymin', value='55', format='float') -# opObj11.addParameter(name='ymax', value='65', format='float') -# opObj11.addParameter(name='save', value='1', format='bool') -# opObj11.addParameter(name='figpath', value='/Users/dsuarez/Pictures/tr', format='str') - -# -#opObj11 = procUnitConfObj1.addOperation(name='PowerProfilePlot', optype='other') -#opObj11.addParameter(name='id', value='2', format='int') -#opObj11.addParameter(name='channelList', value='0,1,2,3', format='intlist') -#opObj11.addParameter(name='save', value='1', format='bool') -#opObj11.addParameter(name='figpath', value='/home/dsuarez/Pictures/EW_DRIFTS_2012_DEC', format='str') -##opObj11.addParameter(name='xmin', value='10', format='int') -##opObj11.addParameter(name='xmax', value='40', format='int') -# -# opObj11 = procUnitConfObj1.addOperation(name='CrossSpectraPlot', optype='other') -# opObj11.addParameter(name='id', value='3', format='int') -# opObj11.addParameter(name='wintitle', value='CrossSpectraPlot', format='str') -# #opObj11.addParameter(name='save', value='1', format='bool') -# #opObj11.addParameter(name='figpath', value='/home/dsuarez/Pictures/EW_DRIFTS_2012_DEC', format='str') -# ##opObj11.addParameter(name='zmin', value='10', format='int') -# ##opObj11.addParameter(name='zmax', value='40', format='int') -# ##opObj11.addParameter(name='save', value='1', format='bool') -# ##opObj11.addParameter(name='figpath', value='/home/dsuarez/Pictures/cross_spc', format='str') -# opObj11.addParameter(name='zmin', value='20', format='int') -# opObj11.addParameter(name='zmax', value='40', format='int') -# opObj11.addParameter(name='save', value='1', format='bool') -# opObj11.addParameter(name='figpath', value='/home/dsuarez/Pictures/ew_drifts_mz', format='str') -# -# # -# opObj11 = procUnitConfObj1.addOperation(name='RTIPlot', optype='other') -# opObj11.addParameter(name='id', value='102', format='int') -# opObj11.addParameter(name='wintitle', value='RTIPLot', format='str') -# opObj11.addParameter(name='xmin', value='10', format='float') -# opObj11.addParameter(name='xmax', value='11.5', format='float') -# # opObj11.addParameter(name='zmin', value='20', format='int') -# # opObj11.addParameter(name='zmax', value='40', format='int') -# # #opObj11.addParameter(name='channelList', value='0,1,2,3', format='intlist') -# # #opObj11.addParameter(name='timerange', value='86400', format='int') -# opObj11.addParameter(name='showprofile', value='0', format='int') -# opObj11.addParameter(name='save', value='1', format='bool') -# opObj11.addParameter(name='figpath', value='/Users/dsuarez/Pictures/tr', format='str') - -print "Escribiendo el archivo XML" -controllerObj.writeXml(filename) -print "Leyendo el archivo XML" -controllerObj.readXml(filename) - -controllerObj.createObjects() -controllerObj.connectObjects() -controllerObj.run() - - diff --git a/schainpy/test/FaradayApp.py b/schainpy/test/FaradayApp.py deleted file mode 100644 index 25b6032..0000000 --- a/schainpy/test/FaradayApp.py +++ /dev/null @@ -1,62 +0,0 @@ -import os, sys - -path = os.path.split(os.getcwd())[0] -sys.path.append(path) - -from controller import * - -desc = "Faraday Experiment Test" -filename = "faraday.xml" - -controllerObj = Project() - -controllerObj.setup(id = '191', name='test01', description=desc) - -path = '' - -readUnitConfObj = controllerObj.addReadUnit(datatype='Voltage', - path=path, - startDate='2011/01/01', - endDate='2012/12/31', - startTime='00:00:00', - endTime='23:59:59', - online=0, - walk=0) - -procUnitConfObj0 = controllerObj.addProcUnit(datatype='Voltage', inputId=readUnitConfObj.getId()) - -opObj11 = procUnitConfObj0.addOperation(name='ProfileSelector', optype='other') -opObj11.addParameter(name='profileRangeList', value='0,127', format='intlist') - -opObj11 = procUnitConfObj0.addOperation(name='filterByHeights') -opObj11.addParameter(name='window', value='3', format='int') - -opObj11 = procUnitConfObj0.addOperation(name='Decoder', optype='other') - -opObj11 = procUnitConfObj0.addOperation(name='deFlip') - -procUnitConfObj1 = controllerObj.addProcUnit(datatype='Spectra', inputId=procUnitConfObj0.getId()) -procUnitConfObj1.addParameter(name='nFFTPoints', value='128', format='int') -procUnitConfObj1.addParameter(name='pairsList', value='(0,1)', format='pairslist') - -opObj11 = procUnitConfObj1.addOperation(name='IncohInt', optype='other') -opObj11.addParameter(name='n', value='10', format='float') -#opObj11.addParameter(name='timeInterval', value='0.33', format='float') - -opObj11 = procUnitConfObj1.addOperation(name='SpectraPlot', optype='other') -opObj11.addParameter(name='idfigure', value='1', format='int') -opObj11.addParameter(name='wintitle', value='SpectraPlot', format='str') -opObj11.addParameter(name='zmin', value='30', format='int') -opObj11.addParameter(name='zmax', value='120', format='int') -opObj11.addParameter(name='showprofile', value='1', format='int') - - -print "Escribiendo el archivo XML" -controllerObj.writeXml(filename) -print "Leyendo el archivo XML" -controllerObj.readXml(filename) - -controllerObj.createObjects() -controllerObj.connectObjects() -controllerObj.run() - diff --git a/schainpy/test/FaradayPw.py b/schainpy/test/FaradayPw.py deleted file mode 100644 index adde5c6..0000000 --- a/schainpy/test/FaradayPw.py +++ /dev/null @@ -1,151 +0,0 @@ -import os, sys - -path = os.path.split(os.getcwd())[0] -sys.path.append(path) - -from controller import * - -desc = "Faraday Experiment Test" -filename = "faraday.xml" - -controllerObj = Project() - -controllerObj.setup(id = '191', name='test01', description=desc) - -path = '/home/dsuarez/.gvfs/data_f on 10.10.20.2/RAW_EXP/LP_FARADAY' - -readUnitConfObj = controllerObj.addReadUnit(datatype='Voltage', - path=path, - startDate='2013/01/01', - endDate='2013/12/31', - startTime='00:00:00', - endTime='23:59:59', - online=1, - delay=5, - walk=0) -################ FARADAY LONG PULSE #################################### -procUnitConfObj0 = controllerObj.addProcUnit(datatype='Voltage', inputId=readUnitConfObj.getId()) - -opObj11 = procUnitConfObj0.addOperation(name='ProfileSelector', optype='other') -opObj11.addParameter(name='profileRangeList', value='0,127', format='intlist') - -opObj11 = procUnitConfObj0.addOperation(name='selectHeightsByIndex') -opObj11.addParameter(name='minIndex', value='0', format='float') -opObj11.addParameter(name='maxIndex', value='790', format='float') - -opObj11 = procUnitConfObj0.addOperation(name='selectChannels') -opObj11.addParameter(name='channelList', value='0', format='intlist') - -procUnitConfObj1 = controllerObj.addProcUnit(datatype='Spectra', inputId=procUnitConfObj0.getId()) -procUnitConfObj1.addParameter(name='nFFTPoints', value='16', format='int') - -opObj11 = procUnitConfObj1.addOperation(name='IncohInt', optype='other') -opObj11.addParameter(name='timeInterval', value='3', format='float') - -opObj11 = procUnitConfObj1.addOperation(name='RTIPlot', optype='other') -opObj11.addParameter(name='idfigure', value='1', format='int') -opObj11.addParameter(name='wintitle', value='FaradayLP', format='str') -opObj11.addParameter(name='zmin', value='0', format='int') -opObj11.addParameter(name='zmax', value='90', format='int') -opObj11.addParameter(name='xmin', value='0', format='float') -opObj11.addParameter(name='xmax', value='24', format='float') -opObj11.addParameter(name='showprofile', value='1', format='int') -opObj11.addParameter(name='save', value='1', format='int') -opObj11.addParameter(name='figfile', value='rti0.png', format='str') -opObj11.addParameter(name='figpath', value='/home/dsuarez/Pictures', format='str') -opObj11.addParameter(name='ftp', value='1', format='int') -opObj11.addParameter(name='ftpratio', value='5', format='int') - - -opObj11 = procUnitConfObj1.addOperation(name='RTIPlot', optype='other') -opObj11.addParameter(name='idfigure', value='19', format='int') -opObj11.addParameter(name='wintitle', value='FaradayLP', format='str') -opObj11.addParameter(name='zmin', value='0', format='int') -opObj11.addParameter(name='zmax', value='90', format='int') -opObj11.addParameter(name='xmin', value='0', format='float') -opObj11.addParameter(name='xmax', value='24', format='float') -opObj11.addParameter(name='showprofile', value='1', format='int') -opObj11.addParameter(name='save', value='1', format='int') -#opObj11.addParameter(name='figfile', value='rti0.png', format='str') -opObj11.addParameter(name='figpath', value='/home/dsuarez/Pictures', format='str') -opObj11.addParameter(name='show', value='0', format='int') -#opObj11.addParameter(name='ftp', value='1', format='int') -#opObj11.addParameter(name='ftpratio', value='5', format='int') - - - -################ FARADAY DOUBLE PULSE PARTE 1#################################### -#procUnitConfObjDP1 = controllerObj.addProcUnit(datatype='Voltage', inputId=readUnitConfObj.getId()) -# -#opObj11 = procUnitConfObjDP1.addOperation(name='ProfileSelector', optype='other') -#opObj11.addParameter(name='profileRangeList', value='0,0', format='intlist') -# -#opObj11 = procUnitConfObjDP1.addOperation(name='selectHeightsByIndex') -#opObj11.addParameter(name='minIndex', value='801', format='float') -#opObj11.addParameter(name='maxIndex', value='1065', format='float') -# -#opObj11 = procUnitConfObjDP1.addOperation(name='selectChannels') -#opObj11.addParameter(name='channelList', value='0', format='intlist') -# -#procUnitConfObjSpDP1 = controllerObj.addProcUnit(datatype='Spectra', inputId=procUnitConfObjDP1.getId()) -#procUnitConfObjSpDP1.addParameter(name='nFFTPoints', value='16', format='int') -# -#opObj11 = procUnitConfObjSpDP1.addOperation(name='IncohInt', optype='other') -#opObj11.addParameter(name='timeInterval', value='3', format='float') -# -#opObj11 = procUnitConfObjSpDP1.addOperation(name='RTIPlot', optype='other') -#opObj11.addParameter(name='idfigure', value='2', format='int') -#opObj11.addParameter(name='wintitle', value='FaradayDP1', format='str') -#opObj11.addParameter(name='zmin', value='0', format='int') -#opObj11.addParameter(name='zmax', value='90', format='int') -#opObj11.addParameter(name='xmin', value='0', format='float') -#opObj11.addParameter(name='xmax', value='24', format='float') -##opObj11.addParameter(name='save', value='1', format='int') -##opObj11.addParameter(name='figfile', value='rti-imaging.png', format='str') -##opObj11.addParameter(name='figpath', value='/media/datos/IMAGING/IMAGING/graphs', format='str') -##opObj11.addParameter(name='ftp', value='1', format='int') -##opObj11.addParameter(name='ftpratio', value='3', format='int') - - -################ FARADAY DOUBLE PULSE PARTE 2#################################### - -#procUnitConfObjDP2 = controllerObj.addProcUnit(datatype='Voltage', inputId=readUnitConfObj.getId()) -# -#opObj11 = procUnitConfObjDP2.addOperation(name='ProfileSelector', optype='other') -#opObj11.addParameter(name='profileRangeList', value='0,0', format='intlist') -# -#opObj11 = procUnitConfObjDP2.addOperation(name='selectHeightsByIndex') -#opObj11.addParameter(name='minIndex', value='1069', format='float') -#opObj11.addParameter(name='maxIndex', value='1337', format='float') -# -#opObj11 = procUnitConfObjDP2.addOperation(name='selectChannels') -#opObj11.addParameter(name='channelList', value='0', format='intlist') -# -#procUnitConfObjSpDP2 = controllerObj.addProcUnit(datatype='Spectra', inputId=procUnitConfObjDP2.getId()) -#procUnitConfObjSpDP2.addParameter(name='nFFTPoints', value='16', format='int') -# -#opObj11 = procUnitConfObjSpDP2.addOperation(name='IncohInt', optype='other') -#opObj11.addParameter(name='timeInterval', value='3', format='float') -# -#opObj11 = procUnitConfObjSpDP2.addOperation(name='RTIPlot', optype='other') -#opObj11.addParameter(name='idfigure', value='3', format='int') -#opObj11.addParameter(name='wintitle', value='FaradayDP2', format='str') -#opObj11.addParameter(name='zmin', value='0', format='int') -#opObj11.addParameter(name='zmax', value='90', format='int') -#opObj11.addParameter(name='xmin', value='0', format='float') -#opObj11.addParameter(name='xmax', value='24', format='float') -##opObj11.addParameter(name='save', value='1', format='int') -##opObj11.addParameter(name='figfile', value='rti-imaging.png', format='str') -##opObj11.addParameter(name='figpath', value='/media/datos/IMAGING/IMAGING/graphs', format='str') -##opObj11.addParameter(name='ftp', value='1', format='int') -##opObj11.addParameter(name='ftpratio', value='3', format='int') - - -print "Escribiendo el archivo XML" -controllerObj.writeXml(filename) -print "Leyendo el archivo XML" -controllerObj.readXml(filename) - -controllerObj.createObjects() -controllerObj.connectObjects() -controllerObj.run() \ No newline at end of file diff --git a/schainpy/test/FitsExp.py b/schainpy/test/FitsExp.py deleted file mode 100644 index 72c5720..0000000 --- a/schainpy/test/FitsExp.py +++ /dev/null @@ -1,45 +0,0 @@ -import os, sys - -path = os.path.split(os.getcwd())[0] -sys.path.append(path) - -from controller import * - -desc = "FITS Test" -filename = "fitsexp.xml" - -controllerObj = Project() - -controllerObj.setup(id = '191', name='test01', description=desc) - -readUnitConfObj = controllerObj.addReadUnit(datatype='Fits', - path='/Users/dsuarez/Remote/d2013043', - startDate='2013/02/06', - endDate='2013/12/31', - startTime='00:30:00', - endTime='17:40:59', - online=0, - delay=3, - walk=0) - -#procUnitConfObj0 = controllerObj.addProcUnit(datatype='Voltage', inputId=readUnitConfObj.getId()) - -#procUnitConfObj1 = controllerObj.addProcUnit(datatype='SpectraHeis', inputId=procUnitConfObj0.getId()) -#procUnitConfObj1.addParameter(name='timeInterval', value='5', format='int') - -#opObj11 = procUnitConfObj1.addOperation(name='IncohInt4SpectraHeis', optype='other') -#opObj11.addParameter(name='timeInterval', value='1', format='float') - - - - -print "Escribiendo el archivo XML" -controllerObj.writeXml(filename) -print "Leyendo el archivo XML" -controllerObj.readXml(filename) - -controllerObj.createObjects() -controllerObj.connectObjects() -controllerObj.run() - - \ No newline at end of file diff --git a/schainpy/test/ImagingApp.py b/schainpy/test/ImagingApp.py deleted file mode 100644 index e741c26..0000000 --- a/schainpy/test/ImagingApp.py +++ /dev/null @@ -1,83 +0,0 @@ -import sys - -from controller import * - -desc = "Imaging Experiment Test" -filename = "imaging.xml" - -controllerObj = Project() - -controllerObj.setup(id = '191', name='test01', description=desc) - -readUnitConfObj = controllerObj.addReadUnit(datatype='Spectra', - path='/Users/dsuarez/Remote/IMAGING/D2012080', - startDate='2011/01/01', - endDate='2012/12/31', - startTime='00:00:00', - endTime='23:59:59', - online=0, - walk=0) - -procUnitConfObj1 = controllerObj.addProcUnit(datatype='Spectra', inputId=readUnitConfObj.getId()) - -#opObj11 = procUnitConfObj0.addOperation(name='selectChannels') -#opObj11.addParameter(name='channelList', value='0,2,6', format='intlist') - - -## -#procUnitConfObj1 = controllerObj.addProcUnit(datatype='Spectra', inputId=procUnitConfObj0.getId()) -#procUnitConfObj1.addParameter(name='nFFTPoints', value='32', format='int') -#procUnitConfObj1.addParameter(name='pairsList', value='(0,1)', format='pairslist') - -opObj11 = procUnitConfObj1.addOperation(name='IncohInt', optype='other') -opObj11.addParameter(name='n', value='2', format='int') - -opObj11 = procUnitConfObj1.addOperation(name='SpectraPlot', optype='other') -opObj11.addParameter(name='idfigure', value='1', format='int') -opObj11.addParameter(name='wintitle', value='SpectraPlot', format='str') -#opObj11.addParameter(name='channelList', value='0,6', format='intlist') -opObj11.addParameter(name='zmin', value='30', format='int') -opObj11.addParameter(name='zmax', value='120', format='int') -opObj11.addParameter(name='showprofile', value='1', format='int') - -opObj11 = procUnitConfObj1.addOperation(name='ProfilePlot', optype='other') -opObj11.addParameter(name='idfigure', value='2', format='int') -opObj11.addParameter(name='wintitle', value='O', format='str') -opObj11.addParameter(name='xmin', value='30', format='int') -opObj11.addParameter(name='xmax', value='120', format='int') - - - -#opObj11 = procUnitConfObj0.addOperation(name='CrossSpectraPlot', optype='other') -#opObj11.addParameter(name='idfigure', value='3', format='int') -#opObj11.addParameter(name='wintitle', value='CrossSpectraPlot', format='str') -#opObj11.addParameter(name='zmin', value='30', format='int') -#opObj11.addParameter(name='zmax', value='120', format='int') -#opObj11.addParameter(name='pairsList', value='(0,2)', format='pairslist') - -#opObj11 = procUnitConfObj1.addOperation(name='RTIPlot', optype='other') -#opObj11.addParameter(name='idfigure', value='4', format='int') -#opObj11.addParameter(name='wintitle', value='RTIPLot', format='str') -#opObj11.addParameter(name='zmin', value='30', format='int') -#opObj11.addParameter(name='zmax', value='120', format='int') -#opObj11.addParameter(name='timerange', value='3600', format='int') -#opObj11.addParameter(name='showprofile', value='1', format='int') -#opObj11.addParameter(name='save', value='1', format='bool') -#opObj11.addParameter(name='figpath', value='/Users/dsuarez/Pictures', format='str') - -#opObj11 = procUnitConfObj0.addOperation(name='CoherencePlot', optype='other') -#opObj11.addParameter(name='idfigure', value='5', format='int') -#opObj11.addParameter(name='pairsList', value='(0,2)', format='pairslist') -#opObj11.addParameter(name='timerange', value='300', format='int') -#opObj11.addParameter(name='showprofile', value='1', format='int') - -print "Escribiendo el archivo XML" -controllerObj.writeXml(filename) -print "Leyendo el archivo XML" -controllerObj.readXml(filename) - -controllerObj.createObjects() -controllerObj.connectObjects() -controllerObj.run() - - \ No newline at end of file diff --git a/schainpy/test/Imaging_EwDrifts.py b/schainpy/test/Imaging_EwDrifts.py deleted file mode 100644 index 7e63a50..0000000 --- a/schainpy/test/Imaging_EwDrifts.py +++ /dev/null @@ -1,187 +0,0 @@ -import os, sys - -path = os.path.split(os.getcwd())[0] -sys.path.append(path) - -from controller import * - -desc = "EWDrifts Experiment Test" -filename = "ewdrifts.xml" - -controllerObj = Project() - -controllerObj.setup(id = '191', name='test01', description=desc) - -readUnitConfObj = controllerObj.addReadUnit(datatype='Voltage', - path='/remote/puma/2012_12/EW_Drifts+Faraday+Imaging/Imaging', - startDate='2012/12/19', - endDate='2012/12/21', - startTime='17:00:00', - endTime='23:59:59', - online=0, - walk=1) - -opObj11 = readUnitConfObj.addOperation(name='printNumberOfBlock') - -######################## IMAGING ############################################# -#procUnitConfObj0 = controllerObj.addProcUnit(datatype='Voltage', inputId=readUnitConfObj.getId()) -# -#opObj11 = procUnitConfObj0.addOperation(name='ProfileSelector', optype='other') -#opObj11.addParameter(name='profileRangeList', value='0,39', format='intlist') -# -#opObj11 = procUnitConfObj0.addOperation(name='Decoder', optype='other') - -#opObj11 = procUnitConfObj0.addOperation(name='selectHeights') -#opObj11.addParameter(name='minHei', value='300', format='float') -#opObj11.addParameter(name='maxHei', value='600', format='float') - -#procUnitConfObj1 = controllerObj.addProcUnit(datatype='Spectra', inputId=procUnitConfObj0.getId()) -#procUnitConfObj1.addParameter(name='nFFTPoints', value='8', format='int') -#procUnitConfObj1.addParameter(name='pairsList', value='(0,1),(0,2),(0,3),(0,4),(0,5),(0,6),(0,7), \ -# (1,2),(1,3),(1,4),(1,5),(1,6),(1,7), \ -# (2,3),(2,4),(2,5),(2,6),(2,7), \ -# (3,4),(3,5),(3,6),(3,7), \ -# (4,5),(4,6),(4,7), \ -# (5,6),(5,7), \ -# (6,7)', \ -# format='pairslist') - -#opObj11 = procUnitConfObj1.addOperation(name='IncohInt', optype='other') -#opObj11.addParameter(name='n', value='5', format='float') - -#opObj11 = procUnitConfObj1.addOperation(name='SpectraPlot', optype='other') -#opObj11.addParameter(name='idfigure', value='10', format='int') -#opObj11.addParameter(name='wintitle', value='SpectraPlot', format='str') -#opObj11.addParameter(name='zmin', value='30', format='int') -#opObj11.addParameter(name='zmax', value='50', format='int') -#opObj11.addParameter(name='showprofile', value='1', format='int') - -#opObj11 = procUnitConfObj1.addOperation(name='IncohInt', optype='other') -#opObj11.addParameter(name='n', value='10', format='float') - -#opObj11 = procUnitConfObj1.addOperation(name='SpectraPlot', optype='other') -#opObj11.addParameter(name='idfigure', value='11', format='int') -#opObj11.addParameter(name='wintitle', value='SpectraPlot', format='str') -#opObj11.addParameter(name='zmin', value='30', format='int') -#opObj11.addParameter(name='zmax', value='50', format='int') -#opObj11.addParameter(name='showprofile', value='1', format='int') -#opObj11.addParameter(name='save', value='1', format='int') -#opObj11.addParameter(name='figpath', value='/media/datos/IMAGING/IMAGING/graphs', format='str') - -#opObj11 = procUnitConfObj1.addOperation(name='RTIPlot', optype='other') -#opObj11.addParameter(name='idfigure', value='100', format='int') -#opObj11.addParameter(name='wintitle', value='RTIPLot', format='str') -#opObj11.addParameter(name='zmin', value='30', format='int') -#opObj11.addParameter(name='zmax', value='50', format='int') -#opObj11.addParameter(name='xmin', value='17', format='float') -#opObj11.addParameter(name='xmax', value='22', format='float') -#opObj11.addParameter(name='save', value='1', format='int') -#opObj11.addParameter(name='figfile', value='rti-imaging.png', format='str') -#opObj11.addParameter(name='figpath', value='/media/datos/IMAGING/IMAGING/graphs', format='str') -#opObj11.addParameter(name='ftp', value='1', format='int') -#opObj11.addParameter(name='ftpratio', value='3', format='int') - -#opObj11 = procUnitConfObj1.addOperation(name='CrossSpectraPlot', optype='other') -#opObj11.addParameter(name='idfigure', value='13', format='int') -#opObj11.addParameter(name='wintitle', value='CrossSpectraPlot', format='str') -#opObj11.addParameter(name='zmin', value='30', format='int') -#opObj11.addParameter(name='zmax', value='50', format='int') -#opObj11.addParameter(name='save', value='1', format='bool') -#opObj11.addParameter(name='figpath', value='/media/datos/IMAGING/IMAGING/graphs', format='str') - -#opObj11 = procUnitConfObj1.addOperation(name='CoherenceMap', optype='other') -#opObj11.addParameter(name='idfigure', value='101', format='int') -#opObj11.addParameter(name='wintitle', value='Coherence', format='str') -#opObj11.addParameter(name='zmin', value='30', format='int') -#opObj11.addParameter(name='zmax', value='50', format='int') -#opObj11.addParameter(name='xmin', value='17', format='float') -#opObj11.addParameter(name='xmax', value='22', format='float') -#opObj11.addParameter(name='save', value='1', format='int') -#opObj11.addParameter(name='figfile', value='coherence-imaging.png', format='str') -#opObj11.addParameter(name='figpath', value='/media/datos/IMAGING/IMAGING/graphs', format='str') -#opObj11.addParameter(name='ftp', value='1', format='int') -#opObj11.addParameter(name='ftpratio', value='3', format='int') - -#opObj11 = procUnitConfObj1.addOperation(name='SpectraWriter', optype='other') -#opObj11.addParameter(name='path', value='/media/datos/IMAGING/IMAGING2') -#opObj11.addParameter(name='blocksPerFile', value='10', format='int') - -##################### EW - DRIFT ############################################## -procUnitConfObj0 = controllerObj.addProcUnit(datatype='Voltage', inputId=readUnitConfObj.getId()) - -opObj11 = procUnitConfObj0.addOperation(name='ProfileSelector', optype='other') -opObj11.addParameter(name='profileRangeList', value='40,167', format='intlist') - -opObj11 = procUnitConfObj0.addOperation(name='filterByHeights') -opObj11.addParameter(name='window', value='36', format='int') - -#opObj11 = procUnitConfObj0.addOperation(name='selectHeights') -#opObj11.addParameter(name='minHei', value='200', format='float') -#opObj11.addParameter(name='maxHei', value='700', format='float') - -opObj11 = procUnitConfObj0.addOperation(name='Decoder', optype='other') -opObj11.addParameter(name='code', value='1,1,-1,-1,-1,1', format='floatlist') -opObj11.addParameter(name='nCode', value='2', format='int') -opObj11.addParameter(name='nBaud', value='3', format='int') - -#opObj11 = procUnitConfObj0.addOperation(name='CohInt', optype='other') -#opObj11.addParameter(name='n', value='1', format='float') - -procUnitConfObj1 = controllerObj.addProcUnit(datatype='Spectra', inputId=procUnitConfObj0.getId()) -procUnitConfObj1.addParameter(name='nFFTPoints', value='8', format='int') -procUnitConfObj1.addParameter(name='pairsList', value='(0,1),(0,2),(0,3),(0,4),(0,5),(0,6),(0,7), \ - (1,2),(1,3),(1,4),(1,5),(1,6),(1,7), \ - (2,3),(2,4),(2,5),(2,6),(2,7), \ - (3,4),(3,5),(3,6),(3,7), \ - (4,5),(4,6),(4,7), \ - (5,6),(5,7), \ - (6,7)', \ - format='pairslist') - -opObj11 = procUnitConfObj1.addOperation(name='IncohInt', optype='other') -opObj11.addParameter(name='n', value='16', format='float') - -#opObj11 = procUnitConfObj1.addOperation(name='SpectraPlot', optype='other') -#opObj11.addParameter(name='idfigure', value='30', format='int') -#opObj11.addParameter(name='wintitle', value='SpectraPlot', format='str') -#opObj11.addParameter(name='zmin', value='40', format='int') -#opObj11.addParameter(name='zmax', value='100', format='int') -#opObj11.addParameter(name='channelList', value='0,1,2', format='intlist') -#opObj11.addParameter(name='showprofile', value='1', format='int') -#opObj11.addParameter(name='save', value='1', format='bool') -#opObj11.addParameter(name='figpath', value='/mnt/Datos/PROCDATA/IMAGING/EW-DRIFT/graphs', format='str') - -#opObj11 = procUnitConfObj1.addOperation(name='CrossSpectraPlot', optype='other') -#opObj11.addParameter(name='idfigure', value='3', format='int') -#opObj11.addParameter(name='wintitle', value='CrossSpectraPlot', format='str') -#opObj11.addParameter(name='zmin', value='45', format='int') -#opObj11.addParameter(name='zmax', value='100', format='int') -#opObj11.addParameter(name='save', value='1', format='bool') -#opObj11.addParameter(name='figpath', value='/mnt/Datos/PROCDATA/IMAGING/EW-DRIFT/graphs', format='str') - -#opObj11 = procUnitConfObj1.addOperation(name='RTIPlot', optype='other') -#opObj11.addParameter(name='idfigure', value='20', format='int') -#opObj11.addParameter(name='wintitle', value='RTIPLot', format='str') -#opObj11.addParameter(name='zmin', value='40', format='int') -#opObj11.addParameter(name='zmax', value='100', format='int') -#opObj11.addParameter(name='xmin', value='17', format='int') -#opObj11.addParameter(name='xmax', value='22', format='int') -#opObj11.addParameter(name='channelList', value='0', format='intlist') -#opObj11.addParameter(name='showprofile', value='0', format='int') -#opObj11.addParameter(name='save', value='1', format='int') -#opObj11.addParameter(name='figpath', value='/mnt/Datos/PROCDATA/IMAGING/EW-DRIFT/graphs', format='str') - -opObj11 = procUnitConfObj1.addOperation(name='SpectraWriter', optype='other') -opObj11.addParameter(name='path', value='/mnt/Datos/PROCDATA/IMAGING/EW-DRIFT') -opObj11.addParameter(name='blocksPerFile', value='200', format='int') - -print "Escribiendo el archivo XML" -controllerObj.writeXml(filename) -print "Leyendo el archivo XML" -controllerObj.readXml(filename) - -controllerObj.createObjects() -controllerObj.connectObjects() -controllerObj.run() - - diff --git a/schainpy/test/Imaging_Plots.py b/schainpy/test/Imaging_Plots.py deleted file mode 100644 index 979155b..0000000 --- a/schainpy/test/Imaging_Plots.py +++ /dev/null @@ -1,79 +0,0 @@ -import os, sys - -path = os.path.split(os.getcwd())[0] -sys.path.append(path) - -from controller import * - -desc = "EWDrifts+Imaging+Faraday Experiments" -filename = "imaging_plots.xml" - -controllerObj = Project() - -controllerObj.setup(id = '191', name='test01', description=desc) - -path = '/media/signalchain/datos/IMAGING/IMAGING/setiembre2014' - -readUnitConfObj = controllerObj.addReadUnit(datatype='SpectraReader', - path=path, - startDate='2014/09/22', - endDate='2014/09/22', - startTime='00:30:00', - endTime='23:59:59', - delay=5, - online=0, - walk=1) - -opObj11 = readUnitConfObj.addOperation(name='printNumberOfBlock') - -######################## IMAGING ############################################# - -procUnitConfObj1 = controllerObj.addProcUnit(datatype='SpectraProc', inputId=readUnitConfObj.getId()) - -opObj11 = procUnitConfObj1.addOperation(name='SpectraPlot', optype='other') -opObj11.addParameter(name='id', value='2000', format='int') -opObj11.addParameter(name='wintitle', value='Imaging', format='str') -opObj11.addParameter(name='zmin', value='15', format='int') -opObj11.addParameter(name='zmax', value='45', format='int') -opObj11.addParameter(name='figpath', value='/home/signalchain/Pictures/imaging', format='str') -opObj11.addParameter(name='exp_code', value='13', format='int') - -opObj11 = procUnitConfObj1.addOperation(name='RTIPlot', optype='other') -opObj11.addParameter(name='id', value='3001', format='int') -opObj11.addParameter(name='wintitle', value='Imaging', format='str') -opObj11.addParameter(name='xmin', value='20.5', format='float') -opObj11.addParameter(name='xmax', value='24', format='float') -opObj11.addParameter(name='zmin', value='15', format='int') -opObj11.addParameter(name='zmax', value='45', format='int') -opObj11.addParameter(name='channelList', value='0,1,2,3', format='intlist') -opObj11.addParameter(name='showprofile', value='0', format='int') -opObj11.addParameter(name='figpath', value='/home/signalchain/Pictures/imaging', format='str') -opObj11.addParameter(name='exp_code', value='13', format='int') - -opObj11 = procUnitConfObj1.addOperation(name='CoherenceMap', optype='other') -opObj11.addParameter(name='id', value='2001', format='int') -opObj11.addParameter(name='wintitle', value='Imaging', format='str') -opObj11.addParameter(name='xmin', value='20.5', format='float') -opObj11.addParameter(name='xmax', value='24', format='float') -opObj11.addParameter(name='figpath', value='/home/signalchain/Pictures/imaging', format='str') -opObj11.addParameter(name='exp_code', value='13', format='int') - -opObj11 = procUnitConfObj1.addOperation(name='SendByFTP', optype='other') -opObj11.addParameter(name='ext', value='*.png', format='str') -opObj11.addParameter(name='localfolder', value='/home/signalchain/Pictures/imaging', format='str') -opObj11.addParameter(name='remotefolder', value='/home/wmaster/graficos', format='str') -opObj11.addParameter(name='server', value='jro-app.igp.gob.pe', format='str') -opObj11.addParameter(name='username', value='wmaster', format='str') -opObj11.addParameter(name='password', value='mst2010vhf', format='str') - - -print "Escribiendo el archivo XML" -controllerObj.writeXml(filename) -print "Leyendo el archivo XML" -controllerObj.readXml(filename) - -controllerObj.createObjects() -controllerObj.connectObjects() -controllerObj.run() - - diff --git a/schainpy/test/Imaging_Proc.py b/schainpy/test/Imaging_Proc.py deleted file mode 100644 index 9e3f4a7..0000000 --- a/schainpy/test/Imaging_Proc.py +++ /dev/null @@ -1,71 +0,0 @@ -import os, sys - -path = os.path.split(os.getcwd())[0] -sys.path.append(path) - -from controller import * - -desc = "EWDrifts+Imaging+Faraday Experiment" -filename = "imaging_proc.xml" - -controllerObj = Project() - -controllerObj.setup(id = '191', name='test01', description=desc) - -path = '/home/signalchain/Documents/remote_data/EW_Faraday_imaging' - -readUnitConfObj = controllerObj.addReadUnit(datatype='VoltageReader', - path=path, - startDate='2014/09/21', - endDate='2014/09/30', - startTime='16:00:00', - endTime='23:59:59', - delay=5, - online=1, - walk=1) - -opObj11 = readUnitConfObj.addOperation(name='printNumberOfBlock') - -######################## IMAGING ############################################# -procUnitConfObj0 = controllerObj.addProcUnit(datatype='VoltageProc', inputId=readUnitConfObj.getId()) -# -opObj11 = procUnitConfObj0.addOperation(name='ProfileSelector', optype='other') -opObj11.addParameter(name='profileRangeList', value='0,39', format='intlist') -# opObj11.addParameter(name='profileRangeList', value='40,167', format='intlist') - - -opObj11 = procUnitConfObj0.addOperation(name='Decoder', optype='other') -# opObj11.addParameter(name='code', value='1,0,0,1,0,0,-1,0,0,-1,0,0,-1,0,0,1,0,0', format='floatlist') -# opObj11.addParameter(name='nCode', value='2', format='int') -# opObj11.addParameter(name='nBaud', value='9', format='int') - -procUnitConfObj1 = controllerObj.addProcUnit(datatype='SpectraProc', inputId=procUnitConfObj0.getId()) -procUnitConfObj1.addParameter(name='nProfiles', value='40', format='int') -procUnitConfObj1.addParameter(name='nFFTPoints', value='40', format='int') - -procUnitConfObj1.addParameter(name='pairsList', value='(0,1),(0,2),(0,3),(0,4),(0,5),(0,6),(0,7), \ - (1,2),(1,3),(1,4),(1,5),(1,6),(1,7), \ - (2,3),(2,4),(2,5),(2,6),(2,7), \ - (3,4),(3,5),(3,6),(3,7), \ - (4,5),(4,6),(4,7), \ - (5,6),(5,7), \ - (6,7)', \ - format='pairsList') - -opObj11 = procUnitConfObj1.addOperation(name='IncohInt', optype='other') -opObj11.addParameter(name='timeInterval', value='5', format='float') - - -opObj11 = procUnitConfObj1.addOperation(name='SpectraWriter', optype='other') -opObj11.addParameter(name='path', value='/media/signalchain/datos/IMAGING/IMAGING/setiembre2014') -opObj11.addParameter(name='blocksPerFile', value='10', format='int') - - -print "Escribiendo el archivo XML" -controllerObj.writeXml(filename) -print "Leyendo el archivo XML" -controllerObj.readXml(filename) - -controllerObj.createObjects() -controllerObj.connectObjects() -controllerObj.run() diff --git a/schainpy/test/Imaging_Proc_Driver4.py b/schainpy/test/Imaging_Proc_Driver4.py deleted file mode 100644 index feb45f4..0000000 --- a/schainpy/test/Imaging_Proc_Driver4.py +++ /dev/null @@ -1,170 +0,0 @@ -import os, sys - -path = os.path.split(os.getcwd())[0] -sys.path.append(path) - -from controller import * - -def verifyCmdArguments(): - import getopt - arglist = '' - path = None - startDate = None - startTime = None - endDate = None - endTime = None - xmin = None - xmax = None - zmin = None - zmax = None - gpath = None - wpath = None - save_figure = None - save_pdata = None - id_rti = None - - longarglist = ['path=', - 'startDate=', - 'startTime=', - 'endDate=', - 'endTime=', - 'xmin=', - 'xmax=', - 'zmin=', - 'zmax=', - 'gpath=', - 'wpath=', - 'save_figure=', - 'id_rti=', - 'save_pdata=' - ] - - optlist, args = getopt.getopt(sys.argv[1:], arglist, longarglist) - - for opt in optlist: - if opt[0] == '--path': - path = opt[1] - elif opt[0] == '--startDate': - startDate = opt[1] - elif opt[0] == '--startTime': - startTime = opt[1] - elif opt[0] == '--endDate': - endDate = opt[1] - elif opt[0] == '--endTime': - endTime = opt[1] - elif opt[0] == '--xmin': - xmin = opt[1] - elif opt[0] == '--xmax': - xmax = opt[1] - elif opt[0] == '--zmin': - zmin = opt[1] - elif opt[0] == '--zmax': - zmax = opt[1] - elif opt[0] == '--gpath': - gpath = opt[1] - elif opt[0] == '--wpath': - wpath = opt[1] - elif opt[0] == '--id_rti': - id_rti = opt[1] - elif opt[0] == '--save_figure': - save_figure = bool(int(opt[1])) - elif opt[0] == '--save_pdata': - save_pdata = bool(int(opt[1])) - - else: - print 'Illegal option %s\n%s%s' % (opt[0], usage, expId.keys()) - sys.exit(-1) - - #print path,startDate,startTime,endDate,endTime,xmin,xmax,zmin,zmax - return path,startDate,startTime,endDate,endTime,xmin,xmax,zmin,zmax,gpath,save_figure,id_rti,wpath,save_pdata - - -desc = "EWDrifts+Imaging+Faraday Experiment" -filename = "imaging_proc.xml" - -controllerObj = Project() - -controllerObj.setup(id = '191', name='test01', description=desc) - -path = '/remote' -path = '/home/dsuarez/.gvfs/data on 10.10.20.13/EW_Faraday_imaging/d2013270' -path = '/home/dsuarez/.gvfs/data on 10.10.20.13/EW_Faraday_imaging/d2013267' -path = '/home/dsuarez/.gvfs/data on 10.10.20.13/Imaging_Driver4' - -path,startDate,startTime,endDate,endTime,xmin,xmax,zmin,zmax,gpath,save_figure,id_rti,wpath,save_pdata = verifyCmdArguments() - - -readUnitConfObj = controllerObj.addReadUnit(datatype='Voltage', - path=path, - startDate=startDate, - endDate=endDate, - startTime=startTime, - endTime=endTime, - delay=20, - online=0, - walk=1) - -opObj11 = readUnitConfObj.addOperation(name='printNumberOfBlock') - -######################## IMAGING ############################################# -procUnitConfObj0 = controllerObj.addProcUnit(datatype='Voltage', inputId=readUnitConfObj.getId()) - - -opObj11 = procUnitConfObj0.addOperation(name='Decoder', optype='other') - - -procUnitConfObj1 = controllerObj.addProcUnit(datatype='Spectra', inputId=procUnitConfObj0.getId()) -procUnitConfObj1.addParameter(name='nProfiles', value='16', format='int') -procUnitConfObj1.addParameter(name='nFFTPoints', value='16', format='int') - -procUnitConfObj1.addParameter(name='pairsList', value='(0,1),(0,2),(0,3),(0,4),(0,5),(0,6),(0,7), \ - (1,2),(1,3),(1,4),(1,5),(1,6),(1,7), \ - (2,3),(2,4),(2,5),(2,6),(2,7), \ - (3,4),(3,5),(3,6),(3,7), \ - (4,5),(4,6),(4,7), \ - (5,6),(5,7), \ - (6,7)', \ - format='pairslist') - -opObj11 = procUnitConfObj1.addOperation(name='IncohInt', optype='other') -opObj11.addParameter(name='timeInterval', value='5', format='float') - - -# opObj11 = procUnitConfObj1.addOperation(name='SpectraPlot', optype='other') -# opObj11.addParameter(name='id', value='2000', format='int') -# opObj11.addParameter(name='wintitle', value='Imaging', format='str') -# opObj11.addParameter(name='zmin', value='25', format='int') -# opObj11.addParameter(name='zmax', value='40', format='int') - - - -opObj11 = procUnitConfObj1.addOperation(name='RTIPlot', optype='other') -opObj11.addParameter(name='id', value=id_rti, format='int') -opObj11.addParameter(name='wintitle', value='Imaging', format='str') -opObj11.addParameter(name='showprofile', value='0', format='int') -opObj11.addParameter(name='xmin', value=xmin, format='float') -opObj11.addParameter(name='xmax', value=xmax, format='float') -opObj11.addParameter(name='zmin', value=zmin, format='float') -opObj11.addParameter(name='zmax', value=zmax, format='float') - -if save_figure: - opObj11.addParameter(name='save', value='1', format='int') - opObj11.addParameter(name='figpath', value=gpath, format='str') - #opObj11.addParameter(name='figpath', value='/home/dsuarez/Pictures/Imaging_Driver4', format='str') - opObj11.addParameter(name='wr_period', value='5', format='int') - -if save_pdata: - opObj11 = procUnitConfObj1.addOperation(name='SpectraWriter', optype='other') - opObj11.addParameter(name='path', value=wpath) - #opObj11.addParameter(name='path', value='/media/datos/IMAGING/IMAGING/Driver4/') - opObj11.addParameter(name='blocksPerFile', value='10', format='int') - - -# print "Escribiendo el archivo XML" -# controllerObj.writeXml(filename) -# print "Leyendo el archivo XML" -# controllerObj.readXml(filename) - -controllerObj.createObjects() -controllerObj.connectObjects() -controllerObj.run() diff --git a/schainpy/test/MeteorApp.py b/schainpy/test/MeteorApp.py deleted file mode 100644 index db063c4..0000000 --- a/schainpy/test/MeteorApp.py +++ /dev/null @@ -1,121 +0,0 @@ -import os, sys - -path = os.path.split(os.getcwd())[0] -sys.path.append(path) - -from controller import * - -desc = "Meteor Experiment Test" -filename = "meteor20130812.xml" - -controllerObj = Project() -controllerObj.setup(id = '191', name='meteor_test01', description=desc) - -# path = '/home/dsuarez/.gvfs/datos on 10.10.20.2/High_Power_Meteor' -# -# path = '/Volumes/FREE_DISK/meteor_data' -# -# path = '/Users/dsuarez/Movies/meteor' - -path = '/home/dsuarez/.gvfs/datos on 10.10.20.2/High_Power_Meteor_Jasmet' - -readUnitConfObj = controllerObj.addReadUnit(datatype='Voltage', - path=path, - startDate='2013/08/01', - endDate='2013/08/30', - startTime='00:00:00', - endTime='23:59:59', - online=1, - delay=5, - walk=0) - -opObj11 = readUnitConfObj.addOperation(name='printNumberOfBlock') - -procUnitConfObj0 = controllerObj.addProcUnit(datatype='Voltage', inputId=readUnitConfObj.getId()) - -opObj11 = procUnitConfObj0.addOperation(name='ProfileSelector', optype='other') -opObj11.addParameter(name='profileList', - value='1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, \ - 25, 27, 29, 31, 33, 35, 37, 39, 41, 43, 45, 47, 49, \ - 51, 53, 55, 57, 59, 61, 63, 65, 67, 69, 71, 73, 75, \ - 77, 79, 81, 83, 85, 87, 89, 91, 93, 95, 97, 99, 101, \ - 103, 105, 107, 109, 111, 113, 115, 117, 119, 121, 123, \ - 125, 127, 129, 131, 133, 135, 137, 139, 141, 143, 145, \ - 147, 149, 151, 153, 155, 157, 159, 161, 163, 165, 167, \ - 169, 171, 173, 175, 177, 179, 181, 183, 185, 187, 189, \ - 191, 193, 195, 197, 199, 201, 203, 205, 207, 209, 211, \ - 213, 215, 217, 219, 221, 223, 225, 227, 229, 231, 233, \ - 235, 237, 239, 241, 243, 245, 247, 249, 251, 253, 255, \ - 257, 259, 261, 263, 265, 267, 269, 271, 273, 275, 277, \ - 279, 281, 283, 285, 287, 289, 291, 293, 295, 297, 299, \ - 301, 303, 305, 307, 309, 311, 313, 315, 317, 319, 321, \ - 323, 325, 327, 329, 331, 333, 335, 337, 339, 341, 343, \ - 345, 347, 349, 351, 353, 355, 357, 359, 361, 363, 365, \ - 367, 369, 371, 373, 375, 377, 379, 381, 383, 385, 387, \ - 389, 391, 393, 395, 397, 399, 401, 403, 405, 407, 409, \ - 411, 413, 415, 417, 419, 421, 423, 425, 427, 429, 431, \ - 433, 435, 437, 439, 441, 443, 445, 447, 449, 451, 453, \ - 455, 457, 459, 461, 463, 465, 467, 469, 471, 473, 475, \ - 477, 479, 481, 483, 485, 487, 489, 491, 493, 495, 497, \ - 499, 501, 503, 505, 507, 509, 511, 513, 515, 517, 519, \ - 521, 523, 525, 527, 529, 531, 533, 535, 537, 539, 541, \ - 543, 545, 547, 549, 551, 553, 555, 557, 559, 561, 563, \ - 565, 567, 569, 571, 573, 575, 577, 579, 581, 583, 585, \ - 587, 589, 591, 593, 595, 597, 599, 601, 603, 605, 607, \ - 609, 611, 613, 615, 617, 619, 621, 623, 625, 627, 629, \ - 631, 633, 635, 637, 639, 641, 643, 645, 647, 649, 651, \ - 653, 655, 657, 659, 661, 663, 665, 667, 669, 671, 673, \ - 675, 677, 679, 681, 683, 685, 687, 689, 691, 693, 695, \ - 697, 699, 701, 703, 705, 707, 709, 711, 713, 715, 717, \ - 719, 721, 723, 725, 727, 729, 731, 733, 735, 737, 739, \ - 741, 743, 745, 747, 749, 751, 753, 755, 757, 759, 761, \ - 763, 765, 767, 769, 771, 773, 775, 777, 779, 781, 783, \ - 785, 787, 789, 791, 793, 795, 797, 799', format='intlist') - -# opObj11 = procUnitConfObj0.addOperation(name='filterByHeights') -# opObj11.addParameter(name='window', value='3', format='int') - -opObj11 = procUnitConfObj0.addOperation(name='Decoder', optype='other') -opObj11.addParameter(name='code', value='1,1,1,1,1,-1,-1,1,1,-1,1,-1,1', format='floatlist') -opObj11.addParameter(name='nCode', value='1', format='int') -opObj11.addParameter(name='nBaud', value='13', format='int') - -procUnitConfObj1 = controllerObj.addProcUnit(datatype='Spectra', inputId=procUnitConfObj0.getId()) -procUnitConfObj1.addParameter(name='nFFTPoints', value='400', format='int') - -opObj11 = procUnitConfObj1.addOperation(name='IncohInt', optype='other') -opObj11.addParameter(name='n', value='5', format='int') - -opObj11 = procUnitConfObj1.addOperation(name='SpectraPlot', optype='other') -opObj11.addParameter(name='id', value='100', format='int') -opObj11.addParameter(name='wintitle', value='MeteorSpectra', format='str') -opObj11.addParameter(name='zmin', value='10', format='float') -opObj11.addParameter(name='zmax', value='40', format='float') -opObj11.addParameter(name='save', value='1', format='int') -opObj11.addParameter(name='figpath', value='/home/dsuarez/Pictures/meteor_root', format='str') -opObj11.addParameter(name='ftp', value='1', format='int') -opObj11.addParameter(name='wr_period', value='1', format='int') -opObj11.addParameter(name='exp_code', value='15', format='int') - -opObj11 = procUnitConfObj1.addOperation(name='RTIPlot', optype='other') -opObj11.addParameter(name='id', value='101', format='int') -opObj11.addParameter(name='wintitle', value='MeteorRTI', format='str') -opObj11.addParameter(name='xmin', value='0', format='float') -opObj11.addParameter(name='xmax', value='24', format='float') -opObj11.addParameter(name='zmin', value='10', format='float') -opObj11.addParameter(name='zmax', value='40', format='float') -opObj11.addParameter(name='save', value='1', format='int') -opObj11.addParameter(name='figpath', value='/home/dsuarez/Pictures/meteor_root', format='str') -opObj11.addParameter(name='ftp', value='1', format='int') -opObj11.addParameter(name='wr_period', value='1', format='int') -opObj11.addParameter(name='exp_code', value='15', format='int') - - -print "Escribiendo el archivo XML" -controllerObj.writeXml(filename) -print "Leyendo el archivo XML" -controllerObj.readXml(filename) - -controllerObj.createObjects() -controllerObj.connectObjects() -controllerObj.run() diff --git a/schainpy/test/Meteor_JARS.py b/schainpy/test/Meteor_JARS.py deleted file mode 100644 index a4c1497..0000000 --- a/schainpy/test/Meteor_JARS.py +++ /dev/null @@ -1,93 +0,0 @@ -import os, sys - -path = os.path.split(os.getcwd())[0] -sys.path.append(path) - -from controller import * - -desc = "Meteor Experiment Test" -filename = "meteor20130812.xml" - -controllerObj = Project() -controllerObj.setup(id = '191', name='meteor_test01', description=desc) - -# path = '/home/dsuarez/.gvfs/datos on 10.10.20.2/High_Power_Meteor' -# -# path = '/Volumes/FREE_DISK/meteor_data' -# -# path = '/Users/dsuarez/Movies/meteor' - -path = '/home/dsuarez/.gvfs/data on 10.10.20.6/RAW_EXP' -path = '/home/dsuarez/.gvfs/data on 10.10.20.13/DataJasmet' - - -readUnitConfObj = controllerObj.addReadUnit(datatype='Voltage', - path=path, - startDate='2013/08/01', - endDate='2013/08/30', - startTime='00:00:00', - endTime='23:59:59', - online=1, - delay=2, - walk=1) - -opObj11 = readUnitConfObj.addOperation(name='printNumberOfBlock') - -procUnitConfObj0 = controllerObj.addProcUnit(datatype='Voltage', inputId=readUnitConfObj.getId()) - - -opObj11 = procUnitConfObj0.addOperation(name='Decoder', optype='other') - - -opObj11 = procUnitConfObj0.addOperation(name='CohInt', optype='other') -opObj11.addParameter(name='n', value='2', format='int') - - -procUnitConfObj1 = controllerObj.addProcUnit(datatype='Spectra', inputId=procUnitConfObj0.getId()) -procUnitConfObj1.addParameter(name='nProfiles', value='200', format='int') -# procUnitConfObj1.addParameter(name='nFFTPoints', value='50', format='int') -procUnitConfObj1.addParameter(name='nFFTPoints', value='100', format='int') - - -opObj11 = procUnitConfObj1.addOperation(name='IncohInt', optype='other') -opObj11.addParameter(name='n', value='4', format='int') - - - -opObj11 = procUnitConfObj1.addOperation(name='RTIPlot', optype='other') -opObj11.addParameter(name='id', value='3000', format='int') -opObj11.addParameter(name='wintitle', value='JASMET-JARS', format='str') -opObj11.addParameter(name='timerange', value='300', format='int') -opObj11.addParameter(name='zmin', value='20', format='float') -opObj11.addParameter(name='zmax', value='45', format='float') -# opObj11.addParameter(name='xmin', value='18', format='float') -# opObj11.addParameter(name='xmax', value='', format='float') - -opObj11.addParameter(name='save', value='1', format='int') -opObj11.addParameter(name='figpath', value='/home/dsuarez/Pictures/meteor_jasmet_online', format='str') -opObj11.addParameter(name='ftp', value='1', format='int') -opObj11.addParameter(name='wr_period', value='10', format='int') -opObj11.addParameter(name='exp_code', value='15', format='int') - - -opObj11 = procUnitConfObj1.addOperation(name='SpectraPlot', optype='other') -opObj11.addParameter(name='id', value='3001', format='int') -opObj11.addParameter(name='wintitle', value='JASMET-JARS', format='str') -opObj11.addParameter(name='zmin', value='20', format='float') -opObj11.addParameter(name='zmax', value='45', format='float') - -opObj11.addParameter(name='save', value='1', format='int') -opObj11.addParameter(name='figpath', value='/home/dsuarez/Pictures/meteor_jasmet_online', format='str') -opObj11.addParameter(name='ftp', value='1', format='int') -opObj11.addParameter(name='wr_period', value='10', format='int') -opObj11.addParameter(name='exp_code', value='15', format='int') - - -print "Escribiendo el archivo XML" -controllerObj.writeXml(filename) -print "Leyendo el archivo XML" -controllerObj.readXml(filename) - -controllerObj.createObjects() -controllerObj.connectObjects() -controllerObj.run() diff --git a/schainpy/test/Meteor_Jasmet.py b/schainpy/test/Meteor_Jasmet.py deleted file mode 100644 index 72d6469..0000000 --- a/schainpy/test/Meteor_Jasmet.py +++ /dev/null @@ -1,111 +0,0 @@ - -import os, sys - -path = os.path.split(os.getcwd())[0] -sys.path.append(path) - -from controller import * - -desc = "Meteor Experiment Test" -filename = "meteor20130812.xml" - -controllerObj = Project() -controllerObj.setup(id = '191', name='meteor_test01', description=desc) - -# path = '/home/dsuarez/.gvfs/datos on 10.10.20.2/High_Power_Meteor' -# -# path = '/Volumes/FREE_DISK/meteor_data' -# -# path = '/Users/dsuarez/Movies/meteor' - -path = '/home/dsuarez/.gvfs/data on 10.10.20.6/RAW_EXP' - - - -readUnitConfObj = controllerObj.addReadUnit(datatype='Voltage', - path=path, - startDate='2013/08/01', - endDate='2013/08/30', - startTime='00:00:00', - endTime='23:59:59', - online=0, - delay=2, - walk=0) - -opObj11 = readUnitConfObj.addOperation(name='printNumberOfBlock') - -procUnitConfObj0 = controllerObj.addProcUnit(datatype='Voltage', inputId=readUnitConfObj.getId()) - -# opObj11 = procUnitConfObj0.addOperation(name='ProfileSelector', optype='other') -# opObj11.addParameter(name='profileList', -# value='1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, \ -# 25, 27, 29, 31, 33, 35, 37, 39, 41, 43, 45, 47, 49, \ -# 51, 53, 55, 57, 59, 61, 63, 65, 67, 69, 71, 73, 75, \ -# 77, 79, 81, 83, 85, 87, 89, 91, 93, 95, 97, 99, 101, \ -# 103, 105, 107, 109, 111, 113, 115, 117, 119, 121, 123, \ -# 125, 127, 129, 131, 133, 135, 137, 139, 141, 143, 145, \ -# 147, 149, 151, 153, 155, 157, 159, 161, 163, 165, 167, \ -# 169, 171, 173, 175, 177, 179, 181, 183, 185, 187, 189, \ -# 191, 193, 195, 197, 199', format='intlist') - -# opObj11 = procUnitConfObj0.addOperation(name='filterByHeights') -# opObj11.addParameter(name='window', value='3', format='int') - -opObj11 = procUnitConfObj0.addOperation(name='Decoder', optype='other') -# opObj11.addParameter(name='code', value='1,1,1,0,1,1,0,1,1,1,1,0,0,0,1,0,1,1,1,0,1,1,0,1,0,0,0,1,1,1,0,1', format='floatlist') -# opObj11.addParameter(name='nCode', value='2', format='int') -# opObj11.addParameter(name='nBaud', value='16', format='int') - -opObj11 = procUnitConfObj0.addOperation(name='CohInt', optype='other') -opObj11.addParameter(name='n', value='2', format='int') - - - - -procUnitConfObj1 = controllerObj.addProcUnit(datatype='Spectra', inputId=procUnitConfObj0.getId()) -procUnitConfObj1.addParameter(name='nProfiles', value='200', format='int') -procUnitConfObj1.addParameter(name='nFFTPoints', value='200', format='int') - - -opObj11 = procUnitConfObj1.addOperation(name='IncohInt', optype='other') -opObj11.addParameter(name='n', value='4', format='int') - - - -opObj11 = procUnitConfObj1.addOperation(name='RTIPlot', optype='other') -opObj11.addParameter(name='id', value='100', format='int') -opObj11.addParameter(name='wintitle', value='JASMET', format='str') -opObj11.addParameter(name='timerange', value='300', format='int') -opObj11.addParameter(name='zmin', value='20', format='float') -opObj11.addParameter(name='zmax', value='50', format='float') -#opObj11.addParameter(name='xmin', value='18', format='float') -# opObj11.addParameter(name='xmax', value='', format='float') -# opObj11.addParameter(name='show', value='0', format='bool') -opObj11.addParameter(name='save', value='1', format='int') -opObj11.addParameter(name='figpath', value='/home/dsuarez/Pictures/meteor_jasmet_offline', format='str') -#opObj11.addParameter(name='ftp', value='1', format='int') -# opObj11.addParameter(name='wr_period', value='60', format='int') -# opObj11.addParameter(name='exp_code', value='10', format='int') - - -opObj11 = procUnitConfObj1.addOperation(name='SpectraPlot', optype='other') -opObj11.addParameter(name='id', value='101', format='int') -opObj11.addParameter(name='wintitle', value='JASMET', format='str') -opObj11.addParameter(name='zmin', value='20', format='float') -opObj11.addParameter(name='zmax', value='50', format='float') -# opObj11.addParameter(name='show', value='0', format='bool') -opObj11.addParameter(name='save', value='1', format='int') -opObj11.addParameter(name='figpath', value='/home/dsuarez/Pictures/meteor_jasmet_offline', format='str') -# opObj11.addParameter(name='ftp', value='1', format='int') -# opObj11.addParameter(name='wr_period', value='60', format='int') -# opObj11.addParameter(name='exp_code', value='10', format='int') - - -print "Escribiendo el archivo XML" -controllerObj.writeXml(filename) -print "Leyendo el archivo XML" -controllerObj.readXml(filename) - -controllerObj.createObjects() -controllerObj.connectObjects() -controllerObj.run() diff --git a/schainpy/test/Meteor_Jasmet_Plot.py b/schainpy/test/Meteor_Jasmet_Plot.py deleted file mode 100644 index e86db30..0000000 --- a/schainpy/test/Meteor_Jasmet_Plot.py +++ /dev/null @@ -1,72 +0,0 @@ -import os, sys - -path = os.path.split(os.getcwd())[0] -sys.path.append(path) - -from controller import * - -desc = "Meteor Experiment Test" -filename = "meteor20130812.xml" - -controllerObj = Project() -controllerObj.setup(id = '191', name='meteor_test01', description=desc) - -# path = '/home/dsuarez/.gvfs/datos on 10.10.20.2/High_Power_Meteor' -# -# path = '/Volumes/FREE_DISK/meteor_data' -# -# path = '/Users/dsuarez/Movies/meteor' - -path = '/media/datos/JASMET' - -readUnitConfObj = controllerObj.addReadUnit(datatype='Spectra', - path=path, - startDate='2013/08/01', - endDate='2013/08/30', - startTime='00:00:00', - endTime='23:59:59', - online=0, - delay=1, - walk=1) - -opObj11 = readUnitConfObj.addOperation(name='printNumberOfBlock') - -procUnitConfObj1 = controllerObj.addProcUnit(datatype='Spectra', inputId=readUnitConfObj.getId()) - -opObj11 = procUnitConfObj1.addOperation(name='RTIPlot', optype='other') -opObj11.addParameter(name='id', value='1000', format='int') -opObj11.addParameter(name='wintitle', value='JASMET', format='str') -# opObj11.addParameter(name='timerange', value='60', format='int') -# # opObj11.addParameter(name='zmin', value='15', format='float') -# # opObj11.addParameter(name='zmax', value='40', format='float') -# # opObj11.addParameter(name='xmin', value='0', format='float') -# # opObj11.addParameter(name='xmax', value='24', format='float') -# opObj11.addParameter(name='save', value='1', format='int') -# opObj11.addParameter(name='figpath', value='/home/dsuarez/Pictures/meteor_jasmet', format='str') -# opObj11.addParameter(name='ftp', value='1', format='int') -# opObj11.addParameter(name='wr_period', value='1', format='int') -# opObj11.addParameter(name='exp_code', value='15', format='int') - - -# opObj11 = procUnitConfObj1.addOperation(name='SpectraPlot', optype='other') -# opObj11.addParameter(name='id', value='1001', format='int') -# opObj11.addParameter(name='wintitle', value='JASMET', format='str') -# opObj11.addParameter(name='zmin', value='15', format='float') -# opObj11.addParameter(name='zmax', value='40', format='float') - -# opObj11.addParameter(name='save', value='1', format='int') -# opObj11.addParameter(name='figpath', value='/home/dsuarez/Pictures/meteor_jasmet', format='str') -# # opObj11.addParameter(name='ftp', value='1', format='int') -# opObj11.addParameter(name='wr_period', value='5', format='int') -# opObj11.addParameter(name='exp_code', value='15', format='int') - - - -print "Escribiendo el archivo XML" -controllerObj.writeXml(filename) -print "Leyendo el archivo XML" -controllerObj.readXml(filename) - -controllerObj.createObjects() -controllerObj.connectObjects() -controllerObj.run() diff --git a/schainpy/test/Meteor_Jasmet_Proc.py b/schainpy/test/Meteor_Jasmet_Proc.py deleted file mode 100644 index a7f31d5..0000000 --- a/schainpy/test/Meteor_Jasmet_Proc.py +++ /dev/null @@ -1,64 +0,0 @@ -import os, sys - -path = os.path.split(os.getcwd())[0] -sys.path.append(path) - -from controller import * - -desc = "Meteor Experiment Test" -filename = "meteor20130812.xml" - -controllerObj = Project() -controllerObj.setup(id = '191', name='meteor_test01', description=desc) - -# path = '/home/dsuarez/.gvfs/datos on 10.10.20.2/High_Power_Meteor' -# -# path = '/Volumes/FREE_DISK/meteor_data' -# -# path = '/Users/dsuarez/Movies/meteor' - -path = '/home/dsuarez/.gvfs/data on 10.10.20.6/RAW_EXP' - -readUnitConfObj = controllerObj.addReadUnit(datatype='Voltage', - path=path, - startDate='2013/08/01', - endDate='2013/08/30', - startTime='00:00:00', - endTime='23:59:59', - online=0, - delay=1, - walk=0) - -opObj11 = readUnitConfObj.addOperation(name='printNumberOfBlock') - -procUnitConfObj0 = controllerObj.addProcUnit(datatype='Voltage', inputId=readUnitConfObj.getId()) - -opObj11 = procUnitConfObj0.addOperation(name='Decoder', optype='other') -# opObj11.addParameter(name='code', value='1,1,1,0,1,1,0,1,1,1,1,0,0,0,1,0,1,1,1,0,1,1,0,1,0,0,0,1,1,1,0,1', format='floatlist') -# opObj11.addParameter(name='nCode', value='2', format='int') -# opObj11.addParameter(name='nBaud', value='16', format='int') - -opObj11 = procUnitConfObj0.addOperation(name='CohInt', optype='other') -opObj11.addParameter(name='n', value='2', format='int') - - -procUnitConfObj1 = controllerObj.addProcUnit(datatype='Spectra', inputId=procUnitConfObj0.getId()) -procUnitConfObj1.addParameter(name='nFFTPoints', value='200', format='int') - -# opObj11 = procUnitConfObj1.addOperation(name='IncohInt', optype='other') -# opObj11.addParameter(name='n', value='1', format='int') - - -opObj11 = procUnitConfObj1.addOperation(name='SpectraWriter', optype='other') -opObj11.addParameter(name='path', value='/media/datos/JASMET') -opObj11.addParameter(name='blocksPerFile', value='30', format='int') - - -print "Escribiendo el archivo XML" -controllerObj.writeXml(filename) -print "Leyendo el archivo XML" -controllerObj.readXml(filename) - -controllerObj.createObjects() -controllerObj.connectObjects() -controllerObj.run() diff --git a/schainpy/test/SunExperiment.py b/schainpy/test/SunExperiment.py deleted file mode 100644 index f507c97..0000000 --- a/schainpy/test/SunExperiment.py +++ /dev/null @@ -1,87 +0,0 @@ -import os, sys - -path = os.path.split(os.getcwd())[0] -sys.path.append(path) - -from controller import * - -desc = "Sun Experiment Test" -filename = "sunexp.xml" - -controllerObj = Project() - -controllerObj.setup(id = '191', name='test01', description=desc) -#/Users/dsuarez/Documents/RadarData/SunExperiment -#/Volumes/data_e/PaseDelSol/Raw/100KHZ - -path = '/Volumes/New Volume/data/PaseDelSol/Raw/1MHz/d2014044' -path = '/Users/dsuarez/Documents/pasedelsol/100KHz' -readUnitConfObj = controllerObj.addReadUnit(datatype='Voltage', - path=path, - startDate='2014/02/01', - endDate='2014/02/27', - startTime='00:00:00', - endTime='23:59:59', - online=0, - delay=3, - walk=0) - -opObj11 = readUnitConfObj.addOperation(name='printNumberOfBlock') - -procUnitConfObj0 = controllerObj.addProcUnit(datatype='Voltage', inputId=readUnitConfObj.getId()) - -procUnitConfObj1 = controllerObj.addProcUnit(datatype='SpectraHeis', inputId=procUnitConfObj0.getId()) - -opObj11 = procUnitConfObj1.addOperation(name='IncohInt4SpectraHeis', optype='other') -opObj11.addParameter(name='timeInterval', value='5', format='float') - -opObj11 = procUnitConfObj1.addOperation(name='SpectraHeisScope', optype='other') -opObj11.addParameter(name='id', value='10', format='int') -opObj11.addParameter(name='wintitle', value='SpectraHeisPlot', format='str') -#opObj11.addParameter(name='ymin', value='125', format='int') -#opObj11.addParameter(name='ymax', value='140', format='int') -#opObj11.addParameter(name='channelList', value='0,1,2', format='intlist') -#opObj11.addParameter(name='showprofile', value='1', format='int') -#opObj11.addParameter(name='save', value='1', format='bool') -#opObj11.addParameter(name='figfile', value='spc-noise.png', format='str') -#opObj11.addParameter(name='figpath', value='/Users/dsuarez/Pictures/sun_pics', format='str') -#opObj11.addParameter(name='ftp', value='1', format='int') -#opObj11.addParameter(name='ftpratio', value='10', format='int') - -opObj11 = procUnitConfObj1.addOperation(name='RTIfromSpectraHeis', optype='other') -opObj11.addParameter(name='id', value='6', format='int') -opObj11.addParameter(name='wintitle', value='RTIPLot', format='str') -# opObj11.addParameter(name='xmin', value='11.5', format='float') -# opObj11.addParameter(name='xmax', value='12.5', format='float') -# opObj11.addParameter(name='ymin', value='60', format='int') -# opObj11.addParameter(name='ymax', value='85', format='int') -# opObj11.addParameter(name='channelList', value='0,1,2,3', format='intlist') -#opObj11.addParameter(name='timerange', value='600', format='int') -#opObj11.addParameter(name='showprofile', value='0', format='int') -#opObj11.addParameter(name='save', value='1', format='bool') -#opObj11.addParameter(name='figfile', value='rti-noise.png', format='str') -#opObj11.addParameter(name='figpath', value='/Users/dsuarez/Pictures/sun_pics', format='str') -#opObj11.addParameter(name='ftp', value='1', format='int') -#opObj11.addParameter(name='ftpratio', value='10', format='int') -# opObj11.addParameter(name='useLocalTime', value='1', format='bool') -# opObj11.addParameter(name='timezone', value='300', format='int') - -#opObj11 = procUnitConfObj1.addOperation(name='SpectraHeisWriter', optype='other') -#opObj11.addParameter(name='wrpath', value='/Users/dsuarez/Remote', format='str') -##opObj11.addParameter(name='blocksPerFile', value='200', format='int') - -opObj11 = procUnitConfObj1.addOperation(name='FitsWriter', optype='other') -opObj11.addParameter(name='path', value='/Users/dsuarez/Documents/fits_rev', format='str') -opObj11.addParameter(name='dataBlocksPerFile', value='10', format='int') -opObj11.addParameter(name='metadatafile', value='/Users/dsuarez/Downloads/metadata_fits_201402.xml', format='str') - -print "Escribiendo el archivo XML" -controllerObj.writeXml(filename) -print "Leyendo el archivo XML" -controllerObj.readXml(filename) - -controllerObj.createObjects() -controllerObj.connectObjects() -controllerObj.run() - - \ No newline at end of file diff --git a/schainpy/test/__init__.py b/schainpy/test/__init__.py new file mode 100644 index 0000000..8feaeca --- /dev/null +++ b/schainpy/test/__init__.py @@ -0,0 +1,5 @@ +''' +Created on Jul 2, 2014 + +@author: roj-idl71 +''' diff --git a/schainpy/test/hydra.py b/schainpy/test/hydra.py deleted file mode 100644 index f459b31..0000000 --- a/schainpy/test/hydra.py +++ /dev/null @@ -1,127 +0,0 @@ -import os, sys - -path = os.path.split(os.getcwd())[0] -sys.path.append(path) - -from controller import * - -desc = "Meteor Experiment Test" -filename = "meteor20130812.xml" - -controllerObj = Project() -controllerObj.setup(id = '191', name='meteor_test01', description=desc) - -# path = '/home/dsuarez/.gvfs/datos on 10.10.20.2/High_Power_Meteor' -# -# path = '/Volumes/FREE_DISK/meteor_data' -# -# path = '/Users/dsuarez/Movies/meteor' - -path = '/home/dsuarez/.gvfs/data on 10.10.20.6/RAW_EXP' -path = '/home/dsuarez/.gvfs/data on 10.10.20.13/DataJasmet' -path = '/home/dsuarez/.gvfs/data on 10.10.20.13/hydra/d2013248' -path = '/media/New Volume/data/hydra/d2013248' -# path = '/home/dsuarez/Documents/jasmet30_rawdata_proc/d2013234' - -readUnitConfObj = controllerObj.addReadUnit(datatype='Spectra', - path=path, - startDate='2013/08/01', - endDate='2013/08/30', - startTime='08:00:00', - endTime='08:59:59', - online=0, - delay=2, - walk=0) - -opObj11 = readUnitConfObj.addOperation(name='printNumberOfBlock') - -procUnitConfObj0 = controllerObj.addProcUnit(datatype='Spectra', inputId=readUnitConfObj.getId()) - - -opObj11 = procUnitConfObj0.addOperation(name='selectChannels') -opObj11.addParameter(name='channelList', value='0,7', format='intlist') -# -# -# opObj11 = procUnitConfObj0.addOperation(name='Decoder', optype='other') -# -# -# opObj11 = procUnitConfObj0.addOperation(name='CohInt', optype='other') -# opObj11.addParameter(name='n', value='2', format='int') - - -# # opObj11 = procUnitConfObj0.addOperation(name='VoltageWriter', optype='other') -# # opObj11.addParameter(name='path', value='/home/dsuarez/Documents/jasmet50_rawdata_proc_rev') -# # opObj11.addParameter(name='blocksPerFile', value='100', format='int') -# # opObj11.addParameter(name='profilesPerBlock', value='200', format='int') - -# -# procUnitConfObj1 = controllerObj.addProcUnit(datatype='Spectra', inputId=procUnitConfObj0.getId()) -# procUnitConfObj1.addParameter(name='nProfiles', value='200', format='int') -# # procUnitConfObj1.addParameter(name='nFFTPoints', value='50', format='int') -# procUnitConfObj1.addParameter(name='nFFTPoints', value='100', format='int') -# -# -# opObj11 = procUnitConfObj1.addOperation(name='IncohInt', optype='other') -# opObj11.addParameter(name='n', value='4', format='int') - -# -# -# opObj11 = procUnitConfObj1.addOperation(name='RTIPlot', optype='other') -# opObj11.addParameter(name='id', value='3000', format='int') -# opObj11.addParameter(name='wintitle', value='JASMET-JARS', format='str') -# opObj11.addParameter(name='timerange', value='300', format='int') -# opObj11.addParameter(name='zmin', value='20', format='float') -# opObj11.addParameter(name='zmax', value='45', format='float') -# # opObj11.addParameter(name='xmin', value='18', format='float') -# # opObj11.addParameter(name='xmax', value='', format='float') -# -# opObj11.addParameter(name='save', value='1', format='int') -# opObj11.addParameter(name='figpath', value='/home/dsuarez/Pictures/meteor_jasmet_online', format='str') -# opObj11.addParameter(name='ftp', value='1', format='int') -# opObj11.addParameter(name='wr_period', value='10', format='int') -# opObj11.addParameter(name='exp_code', value='15', format='int') -# -# - - -opObj11 = procUnitConfObj0.addOperation(name='SpectraPlot', optype='other') -opObj11.addParameter(name='id', value='101', format='int') -opObj11.addParameter(name='zmin', value='35', format='float') -opObj11.addParameter(name='zmax', value='40', format='float') -# opObj11.addParameter(name='save', value='1', format='int') -# opObj11.addParameter(name='figpath', value='/home/dsuarez/Pictures/hydra/20130905', format='str') -# opObj11.addParameter(name='wr_period', value='1', format='int') - - -# opObj11 = procUnitConfObj0.addOperation(name='Noise', optype='other') -# opObj11.addParameter(name='id', value='100', format='int') -# opObj11.addParameter(name='wintitle', value='Hydra', format='str') -# opObj11.addParameter(name='xmin', value='8', format='float') -# opObj11.addParameter(name='xmax', value='9', format='float') -# opObj11.addParameter(name='ymin', value='35', format='float') -# opObj11.addParameter(name='ymax', value='43', format='float') -# # opObj11.addParameter(name='timerange', value='600', format='int') -# opObj11.addParameter(name='save', value='1', format='int') -# opObj11.addParameter(name='figpath', value='/home/dsuarez/Pictures/hydra/20130905', format='str') -# opObj11.addParameter(name='wr_period', value='1', format='int') - -# opObj11 = procUnitConfObj0.addOperation(name='SpectraPlot', optype='other') -# opObj11.addParameter(name='id', value='3001', format='int') -# opObj11.addParameter(name='wintitle', value='JASMET-JARS', format='str') - -# -# opObj11.addParameter(name='save', value='1', format='int') -# opObj11.addParameter(name='figpath', value='/home/dsuarez/Pictures/meteor_jasmet_online', format='str') -# opObj11.addParameter(name='ftp', value='1', format='int') -# opObj11.addParameter(name='wr_period', value='10', format='int') -# opObj11.addParameter(name='exp_code', value='15', format='int') - - -print "Escribiendo el archivo XML" -controllerObj.writeXml(filename) -print "Leyendo el archivo XML" -controllerObj.readXml(filename) - -controllerObj.createObjects() -controllerObj.connectObjects() -controllerObj.run() diff --git a/schainpy/test/isrproc.py b/schainpy/test/isrproc.py deleted file mode 100644 index 29acb6a..0000000 --- a/schainpy/test/isrproc.py +++ /dev/null @@ -1,114 +0,0 @@ -import os, sys - -path = os.path.split(os.getcwd())[0] -sys.path.append(path) - -from controller import * - -desc = "EWDrifts Experiment Test" -filename = "ewdrifts2.xml" - -controllerObj = Project() - -controllerObj.setup(id = '191', name='test01', description=desc) - -path='/remote/ewdrifts/RAW_EXP/EW_DRIFT_FARADAY/EW_Drift' - -path = '/media/New Volume/DATA/MST_ISR' - -readUnitConfObj = controllerObj.addReadUnit(datatype='Voltage', - path=path, - startDate='2014/01/10', - endDate='2014/01/10', - startTime='00:00:00', - endTime='23:59:59', - online=0, - delay=10, - walk=1) - -opObj11 = readUnitConfObj.addOperation(name='printNumberOfBlock') - -################ ISR #################################### -procUnitConfObjISR = controllerObj.addProcUnit(datatype='Voltage', inputId=readUnitConfObj.getId()) - -opObj11 = procUnitConfObjISR.addOperation(name='ProfileSelector', optype='other') -profileIndex = '20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99' -opObj11.addParameter(name='profileList', value=profileIndex, format='intlist') - -opObj11 = procUnitConfObjISR.addOperation(name='ProfileConcat', optype='other') -opObj11.addParameter(name='m', value='5', format='int') - -opObj11 = procUnitConfObjISR.addOperation(name='filterByHeights') -opObj11.addParameter(name='window', value='20', format='int') - -barker3x1 = '1,1,-1,-1,-1,1' -barker3x5 = '1,1,1,1,1, 1,1,1,1,1,-1,-1,-1,-1,-1,' + \ - '-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,1,1,1,1,1' - - -opObj11 = procUnitConfObjISR.addOperation(name='Decoder', optype='other') -opObj11.addParameter(name='code', value=barker3x5, format='floatlist') -opObj11.addParameter(name='nCode', value='2', format='int') -opObj11.addParameter(name='nBaud', value='15', format='int') - -# opObj11 = procUnitConfObjISR.addOperation(name='VoltageWriter', optype='other') -# opObj11.addParameter(name='path', value='/media/datos/mstisr_only_isr') -# opObj11.addParameter(name='blocksPerFile', value='600', format='int') -# opObj11.addParameter(name='profilesPerBlock', value='16', format='int') - -procUnitConfObjISRSpectra = controllerObj.addProcUnit(datatype='Spectra', inputId=procUnitConfObjISR.getId()) -procUnitConfObjISRSpectra.addParameter(name='nFFTPoints', value='16', format='int') -procUnitConfObjISRSpectra.addParameter(name='nProfiles', value='16', format='int') - -opObj11 = procUnitConfObjISRSpectra.addOperation(name='IncohInt', optype='other') -opObj11.addParameter(name='timeInterval', value='60', format='float') - -# opObj11 = procUnitConfObjISRSpectra.addOperation(name='SpectraPlot', optype='other') -# opObj11.addParameter(name='id', value='300', format='int') -# opObj11.addParameter(name='wintitle', value='ISR', format='str') -# opObj11.addParameter(name='zmin', value='30', format='int') -# opObj11.addParameter(name='zmax', value='65', format='int') -# opObj11.addParameter(name='save', value='1', format='int') -# opObj11.addParameter(name='figpath', value='/home/operaciones/Pictures/MST-ISR', format='str') -# opObj11.addParameter(name='wr_period', value='1', format='int') -# opObj11.addParameter(name='ftp', value='1', format='int') -# opObj11.addParameter(name='server', value='jro-app.igp.gob.pe', format='str') -# opObj11.addParameter(name='folder', value='/home/wmaster/graficos', format='str') -# opObj11.addParameter(name='username', value='wmaster', format='str') -# opObj11.addParameter(name='password', value='mst2010vhf', format='str') -# opObj11.addParameter(name='ftp_wei', value='0', format='int') -# opObj11.addParameter(name='exp_code', value='20', format='int') -# opObj11.addParameter(name='sub_exp_code', value='0', format='int') -# opObj11.addParameter(name='plot_pos', value='0', format='int') - -opObj11 = procUnitConfObjISRSpectra.addOperation(name='RTIPlot', optype='other') -opObj11.addParameter(name='id', value='301', format='int') -opObj11.addParameter(name='wintitle', value='ISR', format='str') -opObj11.addParameter(name='showprofile', value='0', format='int') -opObj11.addParameter(name='xmin', value='0', format='int') -opObj11.addParameter(name='xmax', value='24', format='int') -opObj11.addParameter(name='zmin', value='30', format='int') -opObj11.addParameter(name='zmax', value='65', format='int') -opObj11.addParameter(name='save', value='1', format='int') -#opObj11.addParameter(name='lastone', value='1', format='int') -opObj11.addParameter(name='figpath', value='/home/dsuarez/Pictures/isr', format='str') -opObj11.addParameter(name='wr_period', value='2', format='int') -# opObj11.addParameter(name='ftp', value='1', format='int') -# opObj11.addParameter(name='server', value='jro-app.igp.gob.pe', format='str') -# opObj11.addParameter(name='folder', value='/home/wmaster/graficos', format='str') -# opObj11.addParameter(name='username', value='wmaster', format='str') -# opObj11.addParameter(name='password', value='mst2010vhf', format='str') -# opObj11.addParameter(name='ftp_wei', value='0', format='int') -# opObj11.addParameter(name='exp_code', value='20', format='int') -# opObj11.addParameter(name='sub_exp_code', value='0', format='int') -# opObj11.addParameter(name='plot_pos', value='0', format='int') - - -print "Escribiendo el archivo XML" -controllerObj.writeXml(filename) -print "Leyendo el archivo XML" -controllerObj.readXml(filename) - -controllerObj.createObjects() -controllerObj.connectObjects() -controllerObj.run() \ No newline at end of file diff --git a/schainpy/test/mst_eej_isr.py b/schainpy/test/mst_eej_isr.py deleted file mode 100644 index 246ab72..0000000 --- a/schainpy/test/mst_eej_isr.py +++ /dev/null @@ -1,258 +0,0 @@ -import os, sys - -path = os.path.split(os.getcwd())[0] -sys.path.append(path) - -from controller import * - -desc = "EWDrifts Experiment Test" -filename = "mstisr3.xml" - -controllerObj = Project() - -controllerObj.setup(id = '191', name='test01', description=desc) - -path='/remote/ewdrifts/RAW_EXP/EW_DRIFT_FARADAY/EW_Drift' - -path = '/home/operaciones/.gvfs/data on 10.10.20.13/MST_ISR/d2014007' - -path = '/home/cluster/remote/MST_ISR/d2014009' - -path = '/media/data/Data/MST_ISR JAN 2014' -readUnitConfObj = controllerObj.addReadUnit(datatype='Voltage', - path=path, - startDate='2014/01/07', - endDate='2014/01/07', - startTime='14:35:00', - endTime='15:00:00', - online=0, - delay=10, - walk=1) - -opObj11 = readUnitConfObj.addOperation(name='printNumberOfBlock') - -################ EEJ #################################### -# procUnitConfObjEEJ = controllerObj.addProcUnit(datatype='Voltage', inputId=readUnitConfObj.getId()) -# -# opObj11 = procUnitConfObjEEJ.addOperation(name='ProfileSelector', optype='other') -# opObj11.addParameter(name='profileRangeList', value='120,183', format='intlist') -# -# opObj11 = procUnitConfObjEEJ.addOperation(name='Decoder', optype='other') -# opObj11.addParameter(name='code', value='1,-1', format='floatlist') -# opObj11.addParameter(name='nCode', value='2', format='int') -# opObj11.addParameter(name='nBaud', value='1', format='int') -# -# # opObj11 = procUnitConfObjEEJ.addOperation(name='CohInt', optype='other') -# # opObj11.addParameter(name='n', value='2', format='int') -# -# procUnitConfObjEEJSpecta = controllerObj.addProcUnit(datatype='Spectra', inputId=procUnitConfObjEEJ.getId()) -# procUnitConfObjEEJSpecta.addParameter(name='nFFTPoints', value='64', format='int') -# procUnitConfObjEEJSpecta.addParameter(name='nProfiles', value='64', format='int') -# -# opObj11 = procUnitConfObjEEJSpecta.addOperation(name='IncohInt', optype='other') -# opObj11.addParameter(name='timeInterval', value='10', format='float') -# -# opObj11 = procUnitConfObjEEJSpecta.addOperation(name='SpectraPlot', optype='other') -# opObj11.addParameter(name='id', value='100', format='int') -# opObj11.addParameter(name='wintitle', value='EEJ', format='str') -# opObj11.addParameter(name='zmin', value='15', format='int') -# opObj11.addParameter(name='zmax', value='40', format='int')# opObj11.addParameter(name='ftp', value='1', format='int') -# opObj11.addParameter(name='save', value='1', format='int') -# opObj11.addParameter(name='figpath', value='/home/cluster/Pictures/mst_isr_day3', format='str') -# opObj11.addParameter(name='wr_period', value='1', format='int') -# # opObj11.addParameter(name='ftp', value='1', format='int') -# # opObj11.addParameter(name='server', value='jro-app.igp.gob.pe', format='str') -# # opObj11.addParameter(name='folder', value='/home/wmaster/graficos', format='str') -# # opObj11.addParameter(name='username', value='wmaster', format='str') -# # opObj11.addParameter(name='password', value='mst2010vhf', format='str') -# # opObj11.addParameter(name='ftp_wei', value='0', format='int') -# # opObj11.addParameter(name='exp_code', value='22', format='int') -# # opObj11.addParameter(name='sub_exp_code', value='0', format='int') -# # opObj11.addParameter(name='plot_pos', value='0', format='int') -# -# -# opObj11 = procUnitConfObjEEJSpecta.addOperation(name='RTIPlot', optype='other') -# opObj11.addParameter(name='id', value='101', format='int') -# opObj11.addParameter(name='wintitle', value='EEJ', format='str') -# opObj11.addParameter(name='showprofile', value='0', format='int') -# opObj11.addParameter(name='xmin', value='0', format='int') -# opObj11.addParameter(name='xmax', value='24', format='int') -# opObj11.addParameter(name='zmin', value='15', format='int') -# opObj11.addParameter(name='zmax', value='40', format='int')# opObj11.addParameter(name='ftp', value='1', format='int') -# opObj11.addParameter(name='save', value='1', format='int') -# opObj11.addParameter(name='figpath', value='/home/cluster/Pictures/mst_isr_day3', format='str') -# opObj11.addParameter(name='wr_period', value='1', format='int') - -# opObj11.addParameter(name='ftp', value='1', format='int') -# opObj11.addParameter(name='server', value='jro-app.igp.gob.pe', format='str') -# opObj11.addParameter(name='folder', value='/home/wmaster/graficos', format='str') -# opObj11.addParameter(name='username', value='wmaster', format='str') -# opObj11.addParameter(name='password', value='mst2010vhf', format='str') -# opObj11.addParameter(name='ftp_wei', value='0', format='int') -# opObj11.addParameter(name='exp_code', value='22', format='int') -# opObj11.addParameter(name='sub_exp_code', value='0', format='int') -# opObj11.addParameter(name='plot_pos', value='0', format='int') - -################ MST #################################### -procUnitConfObjMST = controllerObj.addProcUnit(datatype='Voltage', inputId=readUnitConfObj.getId()) - -opObj11 = procUnitConfObjMST.addOperation(name='ProfileSelector', optype='other') -profileIndex = '0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19,100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119' - -profileIndex = '0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 14, 15, 16, 17, 18, 19,100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 114, 115, 116, 117, 118, 119' - -#profileIndex = '0, 1, 2, 3,100,101,102,103' - -#profileIndex = '4, 5, 6, 7, 104, 105, 106, 107' - -#profileIndex = '8, 9, 10, 11,108, 109, 110, 111 ' - - -#profileIndex = ' 12, 13, 14, 15,112, 113, 114, 115 ' # -#profileIndex = '14, 15, 114, 115' -#profileIndex = '12, 13, 112, 113' # eliminar estos perfiles -# -#profileIndex = '16, 17, 18, 19, 116, 117, 118, 119' # - - -# -# profileIndex = '0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11,100,101,102,103,104, 105, 106, 107,108, 109, 110, 111' - -opObj11.addParameter(name='profileList', value=profileIndex, format='intlist') - -code = '1, 1, 1, -1, 1, 1, -1, 1, 1, 1, 1, -1, -1, -1, 1, -1, 1, 1, 1, -1, 1, 1, -1, 1, -1, -1, -1, 1, 1, 1, -1, 1, 1, 1, 1, -1, 1, 1, -1, 1, 1, 1, 1, -1, -1, -1, 1, -1, -1, -1, -1, 1, -1, -1, 1, -1, 1, 1, 1, -1, -1, -1, 1, -1,' \ -'1, 1, 1, -1, 1, 1, -1, 1, 1, 1, 1, -1, -1, -1, 1, -1, 1, 1, 1, -1, 1, 1, -1, 1, -1, -1, -1, 1, 1, 1, -1, 1, -1, -1, -1, 1, -1, -1, 1, -1, -1, -1, -1, 1, 1, 1, -1, 1, 1, 1, 1, -1, 1, 1, -1, 1, -1, -1, -1, 1, 1, 1, -1, 1,' \ -'-1, -1, -1, 1, -1, -1, 1, -1, -1, -1, -1, 1, 1, 1, -1, 1, -1, -1, -1, 1, -1, -1, 1, -1, 1, 1, 1, -1, -1, -1, 1, -1, -1, -1, -1, 1, -1, -1, 1, -1, -1, -1, -1, 1, 1, 1, -1, 1, 1, 1, 1, -1, 1, 1, -1, 1, -1, -1, -1, 1, 1, 1, -1, 1,' \ -'-1, -1, -1, 1, -1, -1, 1, -1, -1, -1, -1, 1, 1, 1, -1, 1, -1, -1, -1, 1, -1, -1, 1, -1, 1, 1, 1, -1, -1, -1, 1, -1, 1, 1, 1, -1, 1, 1, -1, 1, 1, 1, 1, -1, -1, -1, 1, -1, -1, -1, -1, 1, -1, -1, 1, -1, 1, 1, 1, -1, -1, -1, 1, -1' - -codeA = '1, 1, 1, -1, 1, 1, -1, 1, 1, 1, 1, -1, -1, -1, 1, -1, 1, 1, 1, -1, 1, 1, -1, 1, -1, -1, -1, 1, 1, 1, -1, 1, 1, 1, 1, -1, 1, 1, -1, 1, 1, 1, 1, -1, -1, -1, 1, -1, -1, -1, -1, 1, -1, -1, 1, -1, 1, 1, 1, -1, -1, -1, 1, -1' -codeB = '1, 1, 1, -1, 1, 1, -1, 1, 1, 1, 1, -1, -1, -1, 1, -1, 1, 1, 1, -1, 1, 1, -1, 1, -1, -1, -1, 1, 1, 1, -1, 1, -1, -1, -1, 1, -1, -1, 1, -1, -1, -1, -1, 1, 1, 1, -1, 1, 1, 1, 1, -1, 1, 1, -1, 1, -1, -1, -1, 1, 1, 1, -1, 1' -codeAn = '-1, -1, -1, 1, -1, -1, 1, -1, -1, -1, -1, 1, 1, 1, -1, 1, -1, -1, -1, 1, -1, -1, 1, -1, 1, 1, 1, -1, -1, -1, 1, -1, -1, -1, -1, 1, -1, -1, 1, -1, -1, -1, -1, 1, 1, 1, -1, 1, 1, 1, 1, -1, 1, 1, -1, 1, -1, -1, -1, 1, 1, 1, -1, 1' -codeBn = '-1, -1, -1, 1, -1, -1, 1, -1, -1, -1, -1, 1, 1, 1, -1, 1, -1, -1, -1, 1, -1, -1, 1, -1, 1, 1, 1, -1, -1, -1, 1, -1, 1, 1, 1, -1, 1, 1, -1, 1, 1, 1, 1, -1, -1, -1, 1, -1, -1, -1, -1, 1, -1, -1, 1, -1, 1, 1, 1, -1, -1, -1, 1, -1' - -div = ',' - -codex = codeA + div + codeB + div + codeAn + div + codeBn + div +\ -codeA + div + codeB + div + codeAn + div + codeBn + div +\ -codeA + div + codeB + div + codeAn + div + codeBn + div +\ -codeBn + div + codeA + div + codeB + div + codeAn + div + codeBn + div + codeA - -#codex = codeA + div + codeB + div + codeBn + div + codeA - -#codex = codeBn + div + codeA -#codex = codeB + div + codeA -#codex = codeA + div + codeBn -#codex = codeAn + div + codeBn -# codex = codeB + div + codeAn + div + codeBn + div + codeA - -opObj11 = procUnitConfObjMST.addOperation(name='Decoder', optype='other') -opObj11.addParameter(name='code', value=codex, format='floatlist') -opObj11.addParameter(name='nCode', value='18', format='int') -opObj11.addParameter(name='nBaud', value='64', format='int') - - - -opObj11 = procUnitConfObjMST.addOperation(name='CohInt', optype='other') -# opObj11.addParameter(name='n', value='20', format='int') -opObj11.addParameter(name='n', value='18', format='int') - - -procUnitConfObjMSTSpectra = controllerObj.addProcUnit(datatype='Spectra', inputId=procUnitConfObjMST.getId()) -procUnitConfObjMSTSpectra.addParameter(name='nFFTPoints', value='64', format='int') -procUnitConfObjMSTSpectra.addParameter(name='nProfiles', value='64', format='int') - -opObj11 = procUnitConfObjMSTSpectra.addOperation(name='IncohInt', optype='other') -opObj11.addParameter(name='n', value='2', format='float') - -opObj11 = procUnitConfObjMSTSpectra.addOperation(name='SpectraPlot', optype='other') -opObj11.addParameter(name='id', value='215', format='int') -opObj11.addParameter(name='wintitle', value='MST', format='str') -opObj11.addParameter(name='ymin', value='120', format='int') -opObj11.addParameter(name='ymax', value='170', format='int') -opObj11.addParameter(name='zmin', value='38', format='int') -opObj11.addParameter(name='zmax', value='72', format='int') -opObj11.addParameter(name='save', value='1', format='int') -opObj11.addParameter(name='figpath', value='/home/dsuarez/Pictures/', format='str') -# opObj11.addParameter(name='wr_period', value='1', format='int') -# opObj11.addParameter(name='ftp', value='1', format='int') -# opObj11.addParameter(name='server', value='jro-app.igp.gob.pe', format='str') -# opObj11.addParameter(name='folder', value='/home/wmaster/graficos', format='str') -# opObj11.addParameter(name='username', value='wmaster', format='str') -# opObj11.addParameter(name='password', value='mst2010vhf', format='str') -# opObj11.addParameter(name='ftp_wei', value='0', format='int') -# opObj11.addParameter(name='exp_code', value='19', format='int') -# opObj11.addParameter(name='sub_exp_code', value='0', format='int') -# opObj11.addParameter(name='plot_pos', value='0', format='int') - -# opObj11 = procUnitConfObjMSTSpectra.addOperation(name='RTIPlot', optype='other') -# opObj11.addParameter(name='id', value='201', format='int') -# opObj11.addParameter(name='wintitle', value='MST', format='str') -# opObj11.addParameter(name='showprofile', value='0', format='int') -# opObj11.addParameter(name='xmin', value='0', format='int') -# opObj11.addParameter(name='xmax', value='24', format='int') -# opObj11.addParameter(name='zmin', value='35', format='int') -# opObj11.addParameter(name='zmax', value='55', format='int') -# opObj11.addParameter(name='save', value='1', format='int') -# opObj11.addParameter(name='figpath', value='/home/cluster/Pictures/mst_isr_day3', format='str') -# opObj11.addParameter(name='wr_period', value='1', format='int') - -################ ISR #################################### - -# procUnitConfObjISR = controllerObj.addProcUnit(datatype='Voltage', inputId=readUnitConfObj.getId()) -# -# opObj11 = procUnitConfObjISR.addOperation(name='ProfileSelector', optype='other') -# profileIndex = '20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99' -# opObj11.addParameter(name='profileList', value=profileIndex, format='intlist') -# -# opObj11 = procUnitConfObjISR.addOperation(name='ProfileConcat', optype='other') -# opObj11.addParameter(name='m', value='5', format='int') -# -# opObj11 = procUnitConfObjISR.addOperation(name='filterByHeights') -# opObj11.addParameter(name='window', value='20', format='int') -# -# barker3x1 = '1,1,-1,-1,-1,1' -# barker3x5 = '1,1,1,1,1, 1,1,1,1,1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,1,1,1,1,1' -# -# opObj11 = procUnitConfObjISR.addOperation(name='Decoder', optype='other') -# opObj11.addParameter(name='code', value=barker3x5, format='floatlist') -# opObj11.addParameter(name='nCode', value='2', format='int') -# opObj11.addParameter(name='nBaud', value='15', format='int') -# -# procUnitConfObjISRSpectra = controllerObj.addProcUnit(datatype='Spectra', inputId=procUnitConfObjISR.getId()) -# procUnitConfObjISRSpectra.addParameter(name='nFFTPoints', value='16', format='int') -# procUnitConfObjISRSpectra.addParameter(name='nProfiles', value='16', format='int') -# -# opObj11 = procUnitConfObjISRSpectra.addOperation(name='IncohInt', optype='other') -# opObj11.addParameter(name='timeInterval', value='60', format='float') -# -# opObj11 = procUnitConfObjISRSpectra.addOperation(name='SpectraPlot', optype='other') -# opObj11.addParameter(name='id', value='300', format='int') -# opObj11.addParameter(name='wintitle', value='ISR', format='str') -# opObj11.addParameter(name='zmin', value='45', format='int') -# opObj11.addParameter(name='zmax', value='55', format='int') -# opObj11.addParameter(name='save', value='1', format='int') -# opObj11.addParameter(name='figpath', value='/home/cluster/Pictures/mst_isr_day3', format='str') -# opObj11.addParameter(name='wr_period', value='1', format='int') -# -# -# opObj11 = procUnitConfObjISRSpectra.addOperation(name='RTIPlot', optype='other') -# opObj11.addParameter(name='id', value='301', format='int') -# opObj11.addParameter(name='wintitle', value='ISR', format='str') -# opObj11.addParameter(name='showprofile', value='0', format='int') -# opObj11.addParameter(name='xmin', value='0', format='int') -# opObj11.addParameter(name='xmax', value='24', format='int') -# opObj11.addParameter(name='zmin', value='45', format='int') -# opObj11.addParameter(name='zmax', value='55', format='int') -# opObj11.addParameter(name='save', value='1', format='int') -# opObj11.addParameter(name='figpath', value='/home/cluster/Pictures/mst_isr_day3', format='str') -# opObj11.addParameter(name='wr_period', value='1', format='int') - - -print "Escribiendo el archivo XML" -controllerObj.writeXml(filename) -print "Leyendo el archivo XML" -controllerObj.readXml(filename) - -controllerObj.createObjects() -controllerObj.connectObjects() -controllerObj.run() \ No newline at end of file diff --git a/schainpy/test/mstisr.py b/schainpy/test/mstisr.py deleted file mode 100644 index 2e92aa4..0000000 --- a/schainpy/test/mstisr.py +++ /dev/null @@ -1,186 +0,0 @@ -import os, sys - -path = os.path.split(os.getcwd())[0] -sys.path.append(path) - -from controller import * - -desc = "EWDrifts Experiment Test" -filename = "ewdrifts2.xml" - -controllerObj = Project() - -controllerObj.setup(id = '191', name='test01', description=desc) - -path='/remote/ewdrifts/RAW_EXP/EW_DRIFT_FARADAY/EW_Drift' - -path = '/home/operaciones/.gvfs/data on 10.10.20.13/MST_ISR/d2014007' - -readUnitConfObj = controllerObj.addReadUnit(datatype='Voltage', - path=path, - startDate='2013/01/11', - endDate='2013/12/12', - startTime='00:00:00', - endTime='23:59:59', - online=1, - delay=10, - walk=0) - - -################ EEJ #################################### -procUnitConfObjEEJ = controllerObj.addProcUnit(datatype='Voltage', inputId=readUnitConfObj.getId()) - -opObj11 = procUnitConfObjEEJ.addOperation(name='ProfileSelector', optype='other') -opObj11.addParameter(name='profileRangeList', value='120,183', format='intlist') - -opObj11 = procUnitConfObjEEJ.addOperation(name='Decoder', optype='other') -opObj11.addParameter(name='code', value='1,-1', format='floatlist') -opObj11.addParameter(name='nCode', value='2', format='int') -opObj11.addParameter(name='nBaud', value='1', format='int') - -# opObj11 = procUnitConfObjEEJ.addOperation(name='CohInt', optype='other') -# opObj11.addParameter(name='n', value='2', format='int') - -procUnitConfObjEEJSpecta = controllerObj.addProcUnit(datatype='Spectra', inputId=procUnitConfObjEEJ.getId()) -procUnitConfObjEEJSpecta.addParameter(name='nFFTPoints', value='64', format='int') -procUnitConfObjEEJSpecta.addParameter(name='nProfiles', value='64', format='int') - -opObj11 = procUnitConfObjEEJSpecta.addOperation(name='IncohInt', optype='other') -opObj11.addParameter(name='timeInterval', value='10', format='float') - -opObj11 = procUnitConfObjEEJSpecta.addOperation(name='SpectraPlot', optype='other') -opObj11.addParameter(name='id', value='100', format='int') -opObj11.addParameter(name='wintitle', value='EEJ', format='str') -opObj11.addParameter(name='zmin', value='20', format='int') -opObj11.addParameter(name='zmax', value='60', format='int')# opObj11.addParameter(name='ftp', value='1', format='int') -opObj11.addParameter(name='save', value='1', format='int') -opObj11.addParameter(name='figpath', value='/home/operaciones/Pictures/MST-ISR', format='str') -opObj11.addParameter(name='wr_period', value='15', format='int') -opObj11.addParameter(name='ftp', value='1', format='int') -opObj11.addParameter(name='server', value='jro-app.igp.gob.pe', format='str') -opObj11.addParameter(name='folder', value='/home/wmaster/graficos', format='str') -opObj11.addParameter(name='username', value='wmaster', format='str') -opObj11.addParameter(name='password', value='mst2010vhf', format='str') -opObj11.addParameter(name='ftp_wei', value='0', format='int') -opObj11.addParameter(name='exp_code', value='22', format='int') -opObj11.addParameter(name='sub_exp_code', value='0', format='int') -opObj11.addParameter(name='plot_pos', value='0', format='int') - - -opObj11 = procUnitConfObjEEJSpecta.addOperation(name='RTIPlot', optype='other') -opObj11.addParameter(name='id', value='101', format='int') -opObj11.addParameter(name='wintitle', value='EEJ', format='str') -opObj11.addParameter(name='showprofile', value='0', format='int') -opObj11.addParameter(name='xmin', value='0', format='int') -opObj11.addParameter(name='xmax', value='24', format='int') -opObj11.addParameter(name='save', value='1', format='int') -opObj11.addParameter(name='figpath', value='/home/operaciones/Pictures/MST-ISR', format='str') -opObj11.addParameter(name='wr_period', value='15', format='int') -opObj11.addParameter(name='ftp', value='1', format='int') -opObj11.addParameter(name='server', value='jro-app.igp.gob.pe', format='str') -opObj11.addParameter(name='folder', value='/home/wmaster/graficos', format='str') -opObj11.addParameter(name='username', value='wmaster', format='str') -opObj11.addParameter(name='password', value='mst2010vhf', format='str') -opObj11.addParameter(name='ftp_wei', value='0', format='int') -opObj11.addParameter(name='exp_code', value='22', format='int') -opObj11.addParameter(name='sub_exp_code', value='0', format='int') -opObj11.addParameter(name='plot_pos', value='0', format='int') - -################ MST #################################### -procUnitConfObjMST = controllerObj.addProcUnit(datatype='Voltage', inputId=readUnitConfObj.getId()) - -opObj11 = procUnitConfObjMST.addOperation(name='ProfileSelector', optype='other') -profileIndex = '0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19,100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119' -opObj11.addParameter(name='profileList', value=profileIndex, format='intlist') - - -opObj11 = procUnitConfObjMST.addOperation(name='Decoder', optype='other') - -opObj11 = procUnitConfObjMST.addOperation(name='CohInt', optype='other') -opObj11.addParameter(name='n', value='20', format='int') - - -procUnitConfObjMSTSpectra = controllerObj.addProcUnit(datatype='Spectra', inputId=procUnitConfObjMST.getId()) -procUnitConfObjMSTSpectra.addParameter(name='nFFTPoints', value='64', format='int') -procUnitConfObjMSTSpectra.addParameter(name='nProfiles', value='64', format='int') - -opObj11 = procUnitConfObjMSTSpectra.addOperation(name='IncohInt', optype='other') -opObj11.addParameter(name='n', value='5', format='float') - -opObj11 = procUnitConfObjMSTSpectra.addOperation(name='SpectraPlot', optype='other') -opObj11.addParameter(name='id', value='200', format='int') -opObj11.addParameter(name='wintitle', value='MST', format='str') -opObj11.addParameter(name='zmin', value='35', format='int') -opObj11.addParameter(name='zmax', value='60', format='int') -opObj11.addParameter(name='save', value='1', format='int') -opObj11.addParameter(name='figpath', value='/home/operaciones/Pictures/MST-ISR', format='str') -opObj11.addParameter(name='wr_period', value='5', format='int') -opObj11.addParameter(name='ftp', value='1', format='int') -opObj11.addParameter(name='server', value='jro-app.igp.gob.pe', format='str') -opObj11.addParameter(name='folder', value='/home/wmaster/graficos', format='str') -opObj11.addParameter(name='username', value='wmaster', format='str') -opObj11.addParameter(name='password', value='mst2010vhf', format='str') -opObj11.addParameter(name='ftp_wei', value='0', format='int') -opObj11.addParameter(name='exp_code', value='19', format='int') -opObj11.addParameter(name='sub_exp_code', value='0', format='int') -opObj11.addParameter(name='plot_pos', value='0', format='int') - -opObj11 = procUnitConfObjMSTSpectra.addOperation(name='RTIPlot', optype='other') -opObj11.addParameter(name='id', value='201', format='int') -opObj11.addParameter(name='wintitle', value='MST', format='str') -opObj11.addParameter(name='showprofile', value='0', format='int') -opObj11.addParameter(name='xmin', value='0', format='int') -opObj11.addParameter(name='xmax', value='24', format='int') -opObj11.addParameter(name='zmin', value='35', format='int') -opObj11.addParameter(name='zmax', value='60', format='int') -opObj11.addParameter(name='save', value='1', format='int') -opObj11.addParameter(name='figpath', value='/home/operaciones/Pictures/MST-ISR', format='str') -opObj11.addParameter(name='wr_period', value='5', format='int') -opObj11.addParameter(name='ftp', value='1', format='int') -opObj11.addParameter(name='server', value='jro-app.igp.gob.pe', format='str') -opObj11.addParameter(name='folder', value='/home/wmaster/graficos', format='str') -opObj11.addParameter(name='username', value='wmaster', format='str') -opObj11.addParameter(name='password', value='mst2010vhf', format='str') -opObj11.addParameter(name='ftp_wei', value='0', format='int') -opObj11.addParameter(name='exp_code', value='19', format='int') -opObj11.addParameter(name='sub_exp_code', value='0', format='int') -opObj11.addParameter(name='plot_pos', value='0', format='int') - -################ ISR #################################### -# procUnitConfObjISR = controllerObj.addProcUnit(datatype='Voltage', inputId=readUnitConfObj.getId()) -# -# opObj11 = procUnitConfObjISR.addOperation(name='ProfileSelector', optype='other') -# profileIndex = '20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99' -# opObj11.addParameter(name='profileList', value=profileIndex, format='intlist') -# -# opObj11 = procUnitConfObjISR.addOperation(name='ProfileConcat', optype='other') -# opObj11.addParameter(name='m', value='5', format='int') -# -# opObj11 = procUnitConfObjISR.addOperation(name='filterByHeights') -# opObj11.addParameter(name='window', value='5', format='int') -# -# barker3x1 = '1,1,-1,-1,-1,1' -# barker3x5 = '1,1,1,1,1, 1,1,1,1,1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,1,1,1,1,1' -# -# opObj11 = procUnitConfObjISR.addOperation(name='Decoder', optype='other') -# opObj11.addParameter(name='code', value=barker3x5, format='floatlist') -# opObj11.addParameter(name='nCode', value='2', format='int') -# opObj11.addParameter(name='nBaud', value='15', format='int') -# -# procUnitConfObjISR = controllerObj.addProcUnit(datatype='Spectra', inputId=procUnitConfObjMST.getId()) -# procUnitConfObjISR.addParameter(name='nFFTPoints', value='16', format='int') -# procUnitConfObjISR.addParameter(name='nProfiles', value='16', format='int') -# -# opObj11 = procUnitConfObjISRSpectra.addOperation(name='SpectraPlot', optype='other') -# opObj11.addParameter(name='id', value='300', format='int') -# opObj11.addParameter(name='wintitle', value='ISR', format='str') - - -print "Escribiendo el archivo XML" -controllerObj.writeXml(filename) -print "Leyendo el archivo XML" -controllerObj.readXml(filename) - -controllerObj.createObjects() -controllerObj.connectObjects() -controllerObj.run() \ No newline at end of file diff --git a/schainpy/test/testMeteors.py b/schainpy/test/testMeteors.py deleted file mode 100644 index cb45c11..0000000 --- a/schainpy/test/testMeteors.py +++ /dev/null @@ -1,166 +0,0 @@ -from controller import * - -def meteors(): - - desc = "Segundo Test" - filename = "schain.xml" - - controllerObj = Project() - - controllerObj.setup(id = '191', name='test01', description=desc) - - readUnitConfObj = controllerObj.addReadUnit(datatype='Voltage', - path='/Data/Data/RAWDATA/Meteors', - startDate='2012/06/20', - endDate='2012/06/20', - startTime='04:00:00', - endTime='06:00:00', - online=0, - walk=1) - - ## if you want to look at the coded data, process only channels 0, 1, 2 - ## and ranges between 80 and 130 km. Then you need to input the code we are using for proper decoding. - -# procUnitConfObj0 = controllerObj.addProcUnit(datatype='Voltage', inputId=readUnitConfObj.getId()) -# -# opObj10 = procUnitConfObj0.addOperation(name='selectChannels') -# opObj10.addParameter(name='channelList', value='0,1,2', format='intlist') -# -# opObj10 = procUnitConfObj0.addOperation(name='selectHeights') -# opObj10.addParameter(name='minHei', value='80', format='float') -# opObj10.addParameter(name='maxHei', value='130', format='float') -# -# opObj12 = procUnitConfObj0.addOperation(name='Decoder', optype='other') -# -# opObj12 = procUnitConfObj0.addOperation(name='CohInt', optype='other') -# opObj12.addParameter(name='n', value='4', format='int') -# -# procUnitConfObj1 = controllerObj.addProcUnit(datatype='Spectra', inputId=procUnitConfObj0.getId()) -# procUnitConfObj1.addParameter(name='nFFTPoints', value='16', format='int') -# procUnitConfObj1.addParameter(name='pairsList', value='(0,1),(0,2),(1,2)', format='pairslist') -# -# opObj12 = procUnitConfObj1.addOperation(name='IncohInt', optype='other') -# opObj12.addParameter(name='n', value='10', format='int') - -# opObj11 = procUnitConfObj1.addOperation(name='SpectraPlot', optype='other') -# opObj11.addParameter(name='idfigure', value='1', format='int') -# opObj11.addParameter(name='wintitle', value='LongPulse', format='str') -# opObj11.addParameter(name='zmin', value='35', format='int') -# opObj11.addParameter(name='zmax', value='90', format='int') -# opObj11.addParameter(name='showprofile', value='1', format='int') -# opObj11.addParameter(name='figpath', value='/home/roj-idl71/Data/RAWDATA/Meteors/graphs') -# opObj11.addParameter(name='save', value='1', format='int') -# -# opObj11 = procUnitConfObj1.addOperation(name='CrossSpectraPlot', optype='other') -# opObj11.addParameter(name='idfigure', value='2', format='int') -# opObj11.addParameter(name='wintitle', value='LongPulse', format='str') -# opObj11.addParameter(name='zmin', value='35', format='int') -# opObj11.addParameter(name='zmax', value='90', format='int') -# opObj11.addParameter(name='figpath', value='/home/roj-idl71/Data/RAWDATA/Meteors/graphs') -# opObj11.addParameter(name='save', value='1', format='int') - -# opObj11 = procUnitConfObj1.addOperation(name='CoherenceMap', optype='other') -# opObj11.addParameter(name='idfigure', value='3', format='int') -# opObj11.addParameter(name='wintitle', value='LongPulse', format='str') -# opObj11.addParameter(name='zmin', value='10', format='int') -# opObj11.addParameter(name='zmax', value='90', format='int') -# opObj11.addParameter(name='figpath', value='/home/roj-idl71/Data/RAWDATA/Meteors/graphs') -# opObj11.addParameter(name='save', value='1', format='int') -# opObj11.addParameter(name='timerange', value=2*60*60, format='int') -# -# opObj11 = procUnitConfObj1.addOperation(name='RTIPlot', optype='other') -# opObj11.addParameter(name='idfigure', value='4', format='int') -# opObj11.addParameter(name='wintitle', value='LongPulse', format='str') -# opObj11.addParameter(name='zmin', value='10', format='int') -# opObj11.addParameter(name='zmax', value='90', format='int') -# opObj11.addParameter(name='figpath', value='/home/roj-idl71/Data/RAWDATA/Meteors/graphs') -# opObj11.addParameter(name='save', value='1', format='int') -# opObj11.addParameter(name='timerange', value=2*60*60, format='int') - - ## - ## For the narrow pulse data, process channels 3,4 and 5 and ranges 140 km and above (remember - ## this pulse was shifted 60 km). In this processing you don't need to add a code. - ## - - procUnitConfObj0 = controllerObj.addProcUnit(datatype='Voltage', inputId=readUnitConfObj.getId()) - -# opObj10 = procUnitConfObj0.addOperation(name='selectChannels') -# opObj10.addParameter(name='channelList', value='3,4,5', format='intlist') - - opObj10 = procUnitConfObj0.addOperation(name='selectHeights') - opObj10.addParameter(name='minHei', value='140', format='float') - opObj10.addParameter(name='maxHei', value='180', format='float') - - opObj12 = procUnitConfObj0.addOperation(name='CohInt', optype='other') - opObj12.addParameter(name='n', value='4', format='int') - - procUnitConfObj1 = controllerObj.addProcUnit(datatype='Spectra', inputId=procUnitConfObj0.getId()) - procUnitConfObj1.addParameter(name='nFFTPoints', value='16', format='int') - procUnitConfObj1.addParameter(name='pairsList', value='(0,1),(0,2),(1,2)', format='pairslist') - - opObj12 = procUnitConfObj1.addOperation(name='IncohInt', optype='other') - opObj12.addParameter(name='n', value='10', format='int') - -# opObj11 = procUnitConfObj1.addOperation(name='SpectraPlot', optype='other') -# opObj11.addParameter(name='idfigure', value='11', format='int') -# opObj11.addParameter(name='wintitle', value='NarrowPulse', format='str') -# opObj11.addParameter(name='zmin', value='35', format='int') -# opObj11.addParameter(name='zmax', value='90', format='int') -# opObj11.addParameter(name='showprofile', value='1', format='int') -# opObj11.addParameter(name='figpath', value='/home/roj-idl71/Data/RAWDATA/Meteors/graphs') -# opObj11.addParameter(name='save', value='1', format='int') -# - opObj11 = procUnitConfObj1.addOperation(name='CrossSpectraPlot', optype='other') - opObj11.addParameter(name='idfigure', value='12', format='int') - opObj11.addParameter(name='wintitle', value='NarrowPulse', format='str') -# opObj11.addParameter(name='zmin', value='15', format='int') -# opObj11.addParameter(name='zmax', value='60', format='int') - opObj11.addParameter(name='figpath', value='/home/roj-idl71/Data/RAWDATA/Meteors/graphs') - opObj11.addParameter(name='save', value='1', format='int') -# - opObj11 = procUnitConfObj1.addOperation(name='CoherenceMap', optype='other') - opObj11.addParameter(name='idfigure', value='13', format='int') - opObj11.addParameter(name='wintitle', value='NarrowPulse', format='str') - opObj11.addParameter(name='figpath', value='/home/roj-idl71/Data/RAWDATA/Meteors/graphs') - opObj11.addParameter(name='zmin', value='0', format='int') - opObj11.addParameter(name='zmax', value='50', format='int') - opObj11.addParameter(name='save', value='1', format='int') - opObj11.addParameter(name='xmin', value='4', format='int') - opObj11.addParameter(name='xmax', value='6', format='int') -# opObj11.addParameter(name='timerange', value=60, format='int') -# -# - opObj11 = procUnitConfObj1.addOperation(name='RTIPlot', optype='other') - opObj11.addParameter(name='idfigure', value='14', format='int') - opObj11.addParameter(name='wintitle', value='NarrowPulse', format='str') - opObj11.addParameter(name='zmin', value='0', format='int') - opObj11.addParameter(name='zmax', value='50', format='int') - opObj11.addParameter(name='figpath', value='/home/roj-idl71/Data/RAWDATA/Meteors/graphs') - opObj11.addParameter(name='save', value='1', format='int') - opObj11.addParameter(name='xmin', value='4', format='int') - opObj11.addParameter(name='xmax', value='6', format='int') -# opObj11.addParameter(name='timerange', value=2*60*60, format='int') - - print "Escribiendo el archivo XML" - - controllerObj.writeXml(filename) - - print "Leyendo el archivo XML" - controllerObj.readXml(filename) - #controllerObj.printattr() - - controllerObj.createObjects() - controllerObj.connectObjects() - controllerObj.run() - -if __name__=='__main__': - - meteors() - - """ - from timeit import Timer - - t = Timer("meteors()", "from __main__ import meteors") - - print t.timeit() - """ \ No newline at end of file diff --git a/schainpy/test/testProcData.py b/schainpy/test/testProcData.py deleted file mode 100644 index e87e238..0000000 --- a/schainpy/test/testProcData.py +++ /dev/null @@ -1,151 +0,0 @@ -import os, sys - -path = os.path.split(os.getcwd())[0] -sys.path.append(path) - -from controller import * - -if __name__ == '__main__': - - desc = "Segundo Test" - filename = "schain.xml" - - controllerObj = Project() - - controllerObj.setup(id = '191', name='test01', description=desc) - - readUnitConfObj = controllerObj.addReadUnit(datatype='SpectraReader', - path='/remote/puma/JULIA_EW_IMAGING/JULIA_EW/D2015', - startDate='2015/01/18', - endDate='2015/01/22', - startTime='00:00:00', - endTime='23:59:59', - online=0, - walk=1, - expLabel='ESF_EW') - - opObj00 = readUnitConfObj.addOperation(name='printInfo') - opObj00 = readUnitConfObj.addOperation(name='printNumberOfBlock') - - procUnitConfObj1 = controllerObj.addProcUnit(datatype='SpectraProc', inputId=readUnitConfObj.getId()) - -# opObj10 = procUnitConfObj0.addOperation(name='selectChannels') -# opObj10.addParameter(name='channelList', value='3,4,5', format='intlist') - -# opObj10 = procUnitConfObj0.addOperation(name='selectHeights') -# opObj10.addParameter(name='minHei', value='90', format='float') -# opObj10.addParameter(name='maxHei', value='180', format='float') - -# opObj12 = procUnitConfObj1.addOperation(name='IncohInt', optype='other') -# opObj12.addParameter(name='n', value='10', format='int') - -# procUnitConfObj1 = controllerObj.addProcUnit(datatype='Spectra', inputId=procUnitConfObj0.getId()) -# procUnitConfObj1.addParameter(name='nFFTPoints', value='32', format='int') -# procUnitConfObj1.addParameter(name='pairList', value='(0,1),(0,2),(1,2)', format='') - - - opObj11 = procUnitConfObj1.addOperation(name='SpectraPlot', optype='other') - opObj11.addParameter(name='id', value='1', format='int') - opObj11.addParameter(name='wintitle', value='SpectraPlot0', format='str') -# opObj11.addParameter(name='zmin', value='30', format='int') -# opObj11.addParameter(name='zmax', value='70', format='int') - opObj11.addParameter(name='showprofile', value='1', format='int') -# opObj11.addParameter(name='save', value='1', format='int') -# opObj11.addParameter(name='figpath', value='/home/roj-idl71/tmp/graphs') -## -# opObj11 = procUnitConfObj1.addOperation(name='CrossSpectraPlot', optype='other') -# opObj11.addParameter(name='idfigure', value='2', format='int') -# opObj11.addParameter(name='wintitle', value='CrossSpectraPlot', format='str') -## opObj11.addParameter(name='zmin', value='30', format='int') -## opObj11.addParameter(name='zmax', value='70', format='int') -# opObj11.addParameter(name='save', value='1', format='int') -# opObj11.addParameter(name='figpath', value='/home/roj-idl71/tmp/graphs') - - -# opObj11 = procUnitConfObj1.addOperation(name='CoherenceMap', optype='other') -# opObj11.addParameter(name='idfigure', value='3', format='int') -# opObj11.addParameter(name='wintitle', value='CrossSpectraPlot', format='str') -# opObj11.addParameter(name='zmin', value='40', format='int') -# opObj11.addParameter(name='zmax', value='90', format='int') - -# procUnitConfObj2 = controllerObj.addProcUnit(datatype='Voltage', inputId=procUnitConfObj0.getId()) -# -# opObj12 = procUnitConfObj2.addOperation(name='CohInt', optype='other') -# opObj12.addParameter(name='n', value='2', format='int') -# opObj12.addParameter(name='overlapping', value='1', format='int') -# -# procUnitConfObj3 = controllerObj.addProcUnit(datatype='Spectra', inputId=procUnitConfObj2.getId()) -# procUnitConfObj3.addParameter(name='nFFTPoints', value='32', format='int') -# -# opObj11 = procUnitConfObj3.addOperation(name='SpectraPlot', optype='other') -# opObj11.addParameter(name='idfigure', value='2', format='int') -# opObj11.addParameter(name='wintitle', value='SpectraPlot1', format='str') -# opObj11.addParameter(name='zmin', value='40', format='int') -# opObj11.addParameter(name='zmax', value='90', format='int') -# opObj11.addParameter(name='showprofile', value='1', format='int') - - opObj11 = procUnitConfObj1.addOperation(name='RTIPlot', optype='other') - opObj11.addParameter(name='id', value='10', format='int') - opObj11.addParameter(name='wintitle', value='RTI', format='str') -# opObj11.addParameter(name='xmin', value='0', format='float') -# opObj11.addParameter(name='xmax', value='10', format='float') -# opObj11.addParameter(name='zmin', value='40', format='int') -# opObj11.addParameter(name='zmax', value='90', format='int') - opObj11.addParameter(name='showprofile', value='1', format='int') - opObj11.addParameter(name='timerange', value=str(2*60*60), format='int') - -# opObj10 = procUnitConfObj1.addOperation(name='selectChannels') -# opObj10.addParameter(name='channelList', value='0,2,4,6', format='intlist') -# -# opObj12 = procUnitConfObj1.addOperation(name='IncohInt', optype='other') -# opObj12.addParameter(name='n', value='2', format='int') -# -# opObj11 = procUnitConfObj1.addOperation(name='SpectraPlot', optype='other') -# opObj11.addParameter(name='idfigure', value='2', format='int') -# opObj11.addParameter(name='wintitle', value='SpectraPlot10', format='str') -# opObj11.addParameter(name='zmin', value='70', format='int') -# opObj11.addParameter(name='zmax', value='90', format='int') -# -# opObj10 = procUnitConfObj1.addOperation(name='selectChannels') -# opObj10.addParameter(name='channelList', value='2,6', format='intlist') -# -# opObj12 = procUnitConfObj1.addOperation(name='IncohInt', optype='other') -# opObj12.addParameter(name='n', value='2', format='int') -# -# opObj11 = procUnitConfObj1.addOperation(name='SpectraPlot', optype='other') -# opObj11.addParameter(name='idfigure', value='3', format='int') -# opObj11.addParameter(name='wintitle', value='SpectraPlot10', format='str') -# opObj11.addParameter(name='zmin', value='70', format='int') -# opObj11.addParameter(name='zmax', value='90', format='int') - - -# opObj12 = procUnitConfObj1.addOperation(name='decoder') -# opObj12.addParameter(name='ncode', value='2', format='int') -# opObj12.addParameter(name='nbauds', value='8', format='int') -# opObj12.addParameter(name='code0', value='001110011', format='int') -# opObj12.addParameter(name='code1', value='001110011', format='int') - - - -# procUnitConfObj2 = controllerObj.addProcUnit(datatype='Spectra', inputId=procUnitConfObj1.getId()) -# -# opObj21 = procUnitConfObj2.addOperation(name='IncohInt', optype='other') -# opObj21.addParameter(name='n', value='2', format='int') -# -# opObj11 = procUnitConfObj2.addOperation(name='SpectraPlot', optype='other') -# opObj11.addParameter(name='idfigure', value='4', format='int') -# opObj11.addParameter(name='wintitle', value='SpectraPlot OBJ 2', format='str') -# opObj11.addParameter(name='zmin', value='70', format='int') -# opObj11.addParameter(name='zmax', value='90', format='int') - - print "Escribiendo el archivo XML" - - controllerObj.writeXml(filename) - - print "Leyendo el archivo XML" - controllerObj.readXml(filename) - #controllerObj.printattr() - - controllerObj.createObjects() - controllerObj.connectObjects() - controllerObj.run() \ No newline at end of file diff --git a/schainpy/test/testRawData.py b/schainpy/test/testRawData.py index 0e15470..2a2280a 100644 --- a/schainpy/test/testRawData.py +++ b/schainpy/test/testRawData.py @@ -1,3 +1,8 @@ +import os, sys + +path = os.path.split(os.getcwd())[0] +sys.path.append(path) + from controller import * if __name__ == '__main__': @@ -9,148 +14,86 @@ if __name__ == '__main__': controllerObj.setup(id = '191', name='test01', description=desc) - readUnitConfObj = controllerObj.addReadUnit(datatype='Voltage', - path='/remote/puma/2012_06/Meteors', - startDate='2012/06/21', - endDate='2012/06/21', - startTime='04:00:00', - endTime='05:59:59', + readUnitConfObj = controllerObj.addReadUnit(datatype='VoltageReader', + path='/Volumes/SOUSY/', + startDate='2014/10/28', + endDate='2014/10/28', + startTime='15:40:00', + endTime='16:20:00', online=0, walk=1) -# opObj00 = readUnitConfObj.addOperation(name='printInfo') - - procUnitConfObj0 = controllerObj.addProcUnit(datatype='Voltage', inputId=readUnitConfObj.getId()) + opObj00 = readUnitConfObj.addOperation(name='printNumberOfBlock') - opObj10 = procUnitConfObj0.addOperation(name='selectChannels') - opObj10.addParameter(name='channelList', value='0,1,2', format='intlist') -# - opObj10 = procUnitConfObj0.addOperation(name='selectHeights') - opObj10.addParameter(name='minHei', value='140', format='float') - opObj10.addParameter(name='maxHei', value='180', format='float') + procUnitConfObj0 = controllerObj.addProcUnit(datatype='VoltageProc', + inputId=readUnitConfObj.getId()) - opObj12 = procUnitConfObj0.addOperation(name='Decoder', optype='other') - - opObj12 = procUnitConfObj0.addOperation(name='CohInt', optype='other') - opObj12.addParameter(name='n', value='4', format='int') +# opObj10 = procUnitConfObj0.addOperation(name='Synchronize', optype='external') -# opObj11 = procUnitConfObj0.addOperation(name='Scope', optype='other') -# opObj11.addParameter(name='idfigure', value='10', format='int') -# opObj11.addParameter(name='wintitle', value='Voltage', format='str') -# opObj11.addParameter(name='zmin', value='40', format='int') -# opObj11.addParameter(name='zmax', value='90', format='int') - - procUnitConfObj1 = controllerObj.addProcUnit(datatype='Spectra', inputId=procUnitConfObj0.getId()) - procUnitConfObj1.addParameter(name='nFFTPoints', value='16', format='int') - procUnitConfObj1.addParameter(name='pairsList', value='(0,1),(0,2),(1,2)', format='pairslist') - + opObj10 = procUnitConfObj0.addOperation(name='selectHeights') + opObj10.addParameter(name='minHei', value='0', format='float') + opObj10.addParameter(name='maxHei', value='8', format='float') - opObj12 = procUnitConfObj1.addOperation(name='IncohInt', optype='other') - opObj12.addParameter(name='n', value='10', format='int') - - opObj11 = procUnitConfObj1.addOperation(name='SpectraPlot', optype='other') - opObj11.addParameter(name='idfigure', value='1', format='int') - opObj11.addParameter(name='wintitle', value='SpectraPlot0', format='str') - opObj11.addParameter(name='zmin', value='35', format='int') - opObj11.addParameter(name='zmax', value='90', format='int') - opObj11.addParameter(name='showprofile', value='1', format='int') - opObj11.addParameter(name='figpath', value='/home/roj-idl71/Data/RAWDATA/BIESTATIC/RAWDATA_8CH/graphs') - opObj11.addParameter(name='save', value='1', format='int') + opObj10 = procUnitConfObj0.addOperation(name='filterByHeights') + opObj10.addParameter(name='window', value='2', format='float') + + opObj10 = procUnitConfObj0.addOperation(name='Decoder', optype='external') + opObj10.addParameter(name='code', value='1,-1', format='intlist') + opObj10.addParameter(name='nCode', value='2', format='float') + opObj10.addParameter(name='nBaud', value='1', format='float') + - opObj11 = procUnitConfObj1.addOperation(name='CrossSpectraPlot', optype='other') - opObj11.addParameter(name='idfigure', value='2', format='int') - opObj11.addParameter(name='wintitle', value='CrossSpectraPlot', format='str') - opObj11.addParameter(name='zmin', value='35', format='int') - opObj11.addParameter(name='zmax', value='90', format='int') - opObj11.addParameter(name='figpath', value='/home/roj-idl71/Data/RAWDATA/BIESTATIC/RAWDATA_8CH/graphs') - opObj11.addParameter(name='save', value='1', format='int') - + opObj10 = procUnitConfObj0.addOperation(name='CohInt', optype='external') + opObj10.addParameter(name='n', value='1296', format='float') - opObj11 = procUnitConfObj1.addOperation(name='CoherenceMap', optype='other') - opObj11.addParameter(name='idfigure', value='3', format='int') - opObj11.addParameter(name='wintitle', value='CoherenciaMap', format='str') -# opObj11.addParameter(name='timerange', value=str(60), format='int') - opObj11.addParameter(name='figpath', value='/home/roj-idl71/Data/RAWDATA/BIESTATIC/RAWDATA_8CH/graphs') + procUnitConfObj1 = controllerObj.addProcUnit(datatype='SpectraProc', + inputId=procUnitConfObj0.getId()) + + #Creating a processing object with its parameters + #schainpy.model.proc.jroproc_spectra.SpectraProc.run() + #If you need to add more parameters can use the "addParameter method" + procUnitConfObj1.addParameter(name='nFFTPoints', value='128', format='int') + + opObj10 = procUnitConfObj1.addOperation(name='IncohInt', optype='external') + opObj10.addParameter(name='n', value='2', format='float') + + #Using internal methods + #schainpy.model.proc.jroproc_spectra.SpectraProc.selectChannels() +# opObj10 = procUnitConfObj1.addOperation(name='selectChannels') +# opObj10.addParameter(name='channelList', value='0,1', format='intlist') + + #Using internal methods + #schainpy.model.proc.jroproc_spectra.SpectraProc.selectHeights() +# opObj10 = procUnitConfObj1.addOperation(name='selectHeights') +# opObj10.addParameter(name='minHei', value='90', format='float') +# opObj10.addParameter(name='maxHei', value='180', format='float') + + #Using external methods (new modules) +# #schainpy.model.proc.jroproc_spectra.IncohInt.setup() +# opObj12 = procUnitConfObj1.addOperation(name='IncohInt', optype='other') +# opObj12.addParameter(name='n', value='1', format='int') + + #Using external methods (new modules) + #schainpy.model.graphics.jroplot_spectra.SpectraPlot.setup() + opObj11 = procUnitConfObj1.addOperation(name='SpectraPlot', optype='external') + opObj11.addParameter(name='id', value='11', format='int') + opObj11.addParameter(name='wintitle', value='SpectraPlot', format='str') + opObj11.addParameter(name='zmin', value='-60', format='int') + opObj11.addParameter(name='zmax', value='10', format='int') opObj11.addParameter(name='save', value='1', format='int') + #Using external methods (new modules) + #schainpy.model.graphics.jroplot_spectra.RTIPlot.setup() opObj11 = procUnitConfObj1.addOperation(name='RTIPlot', optype='other') - opObj11.addParameter(name='idfigure', value='4', format='int') + opObj11.addParameter(name='id', value='30', format='int') opObj11.addParameter(name='wintitle', value='RTI', format='str') -# opObj11.addParameter(name='timerange', value=str(60*60), format='int') - opObj11.addParameter(name='zmin', value='35', format='int') - opObj11.addParameter(name='zmax', value='90', format='int') - opObj11.addParameter(name='figpath', value='/home/roj-idl71/Data/RAWDATA/BIESTATIC/RAWDATA_8CH/graphs') + opObj11.addParameter(name='zmin', value='-60', format='int') + opObj11.addParameter(name='zmax', value='-10', format='int') + opObj11.addParameter(name='showprofile', value='1', format='int') +# opObj11.addParameter(name='timerange', value=str(5*60*60*60), format='int') + opObj11.addParameter(name='xmin', value='14', format='float') + opObj11.addParameter(name='xmax', value='23.9', format='float') opObj11.addParameter(name='save', value='1', format='int') - -# procUnitConfObj2 = controllerObj.addProcUnit(datatype='Voltage', inputId=procUnitConfObj0.getId()) -# -# opObj12 = procUnitConfObj2.addOperation(name='CohInt', optype='other') -# opObj12.addParameter(name='n', value='2', format='int') -# opObj12.addParameter(name='overlapping', value='1', format='int') -# -# procUnitConfObj3 = controllerObj.addProcUnit(datatype='Spectra', inputId=procUnitConfObj2.getId()) -# procUnitConfObj3.addParameter(name='nFFTPoints', value='32', format='int') -# -# opObj11 = procUnitConfObj3.addOperation(name='SpectraPlot', optype='other') -# opObj11.addParameter(name='idfigure', value='2', format='int') -# opObj11.addParameter(name='wintitle', value='SpectraPlot1', format='str') -# opObj11.addParameter(name='zmin', value='40', format='int') -# opObj11.addParameter(name='zmax', value='90', format='int') -# opObj11.addParameter(name='showprofile', value='1', format='int') - -# opObj11 = procUnitConfObj1.addOperation(name='RTIPlot', optype='other') -# opObj11.addParameter(name='idfigure', value='10', format='int') -# opObj11.addParameter(name='wintitle', value='RTI', format='str') -## opObj11.addParameter(name='xmin', value='21', format='float') -## opObj11.addParameter(name='xmax', value='22', format='float') -# opObj11.addParameter(name='zmin', value='40', format='int') -# opObj11.addParameter(name='zmax', value='90', format='int') -# opObj11.addParameter(name='showprofile', value='1', format='int') -# opObj11.addParameter(name='timerange', value=str(60), format='int') - -# opObj10 = procUnitConfObj1.addOperation(name='selectChannels') -# opObj10.addParameter(name='channelList', value='0,2,4,6', format='intlist') -# -# opObj12 = procUnitConfObj1.addOperation(name='IncohInt', optype='other') -# opObj12.addParameter(name='n', value='2', format='int') -# -# opObj11 = procUnitConfObj1.addOperation(name='SpectraPlot', optype='other') -# opObj11.addParameter(name='idfigure', value='2', format='int') -# opObj11.addParameter(name='wintitle', value='SpectraPlot10', format='str') -# opObj11.addParameter(name='zmin', value='70', format='int') -# opObj11.addParameter(name='zmax', value='90', format='int') -# -# opObj10 = procUnitConfObj1.addOperation(name='selectChannels') -# opObj10.addParameter(name='channelList', value='2,6', format='intlist') -# -# opObj12 = procUnitConfObj1.addOperation(name='IncohInt', optype='other') -# opObj12.addParameter(name='n', value='2', format='int') -# -# opObj11 = procUnitConfObj1.addOperation(name='SpectraPlot', optype='other') -# opObj11.addParameter(name='idfigure', value='3', format='int') -# opObj11.addParameter(name='wintitle', value='SpectraPlot10', format='str') -# opObj11.addParameter(name='zmin', value='70', format='int') -# opObj11.addParameter(name='zmax', value='90', format='int') - - -# opObj12 = procUnitConfObj1.addOperation(name='decoder') -# opObj12.addParameter(name='ncode', value='2', format='int') -# opObj12.addParameter(name='nbauds', value='8', format='int') -# opObj12.addParameter(name='code0', value='001110011', format='int') -# opObj12.addParameter(name='code1', value='001110011', format='int') - - - -# procUnitConfObj2 = controllerObj.addProcUnit(datatype='Spectra', inputId=procUnitConfObj1.getId()) -# -# opObj21 = procUnitConfObj2.addOperation(name='IncohInt', optype='other') -# opObj21.addParameter(name='n', value='2', format='int') -# -# opObj11 = procUnitConfObj2.addOperation(name='SpectraPlot', optype='other') -# opObj11.addParameter(name='idfigure', value='4', format='int') -# opObj11.addParameter(name='wintitle', value='SpectraPlot OBJ 2', format='str') -# opObj11.addParameter(name='zmin', value='70', format='int') -# opObj11.addParameter(name='zmax', value='90', format='int') print "Escribiendo el archivo XML" diff --git a/schainpy/test/testcode.py b/schainpy/test/testcode.py deleted file mode 100644 index cd57b78..0000000 --- a/schainpy/test/testcode.py +++ /dev/null @@ -1,146 +0,0 @@ -import numpy -import scipy.signal -import matplotlib -matplotlib.use("TKAgg") -import pylab as pl - -import time - -def getInverseFilter(code, lenfilter=8*28): - - nBauds = len(code) - - if lenfilter == None: - lenfilter = 10*nBauds - - codeBuffer = numpy.zeros((lenfilter), dtype=numpy.float32) - codeBuffer[0:nBauds] = code - - inverse_filter = numpy.real(numpy.fft.ifft(1.0/numpy.fft.fft(codeBuffer))) - inverse_filter = numpy.roll(inverse_filter, shift=120) - -# pl.plot(codeBuffer) -# pl.plot(inverse_filter) -# pl.show() - - return inverse_filter - -def getSignal(nChannels, nHeis): - - u = numpy.complex(1,2) - u /= numpy.abs(u) - - signal = numpy.random.rand(nChannels, nHeis) - signal = signal.astype(numpy.complex) - - signal *= u - - return signal - -def time_decoding(signal, code): - - ini = time.time() - - nBauds = len(code) - nChannels, nHeis = signal.shape - datadec = numpy.zeros((nChannels, nHeis - nBauds + 1), dtype=numpy.complex) - - tmpcode = code.astype(numpy.complex) - ####################################### - ini = time.time() - - for i in range(nChannels): - datadec[i,:] = numpy.correlate(signal[i,:], code, mode='valid')/nBauds - - print time.time() - ini - - return datadec - -def freq_decoding(signal, code): - - ini = time.time() - - nBauds = len(code) - nChannels, nHeis = signal.shape - - codeBuffer = numpy.zeros((nHeis), dtype=numpy.float32) - - codeBuffer[0:nBauds] = code - - fft_code = numpy.conj(numpy.fft.fft(codeBuffer)).reshape(1, -1) - - ###################################### - ini = time.time() - - fft_data = numpy.fft.fft(signal, axis=1) - - conv = fft_data*fft_code - - data = numpy.fft.ifft(conv, axis=1)/nBauds - - datadec = data[:,:-nBauds+1] - - print time.time() - ini - - return datadec - -def fftconvol_decoding(signal, code): - - ini = time.time() - - nBauds = len(code) - nChannels, nHeis = signal.shape - datadec = numpy.zeros((nChannels, nHeis - nBauds + 1), dtype=numpy.complex) - - tmpcode = code.astype(numpy.complex) - ####################################### - ini = time.time() - - for i in range(nChannels): - datadec[i,:] = scipy.signal.fftconvolve(signal[i,:], code[-1::-1], mode='valid')/nBauds - - print time.time() - ini - - return datadec - -def filter_decoding(signal, code): - - ini = time.time() - - nBauds = len(code) - nChannels, nHeis = signal.shape - - inverse_filter = getInverseFilter(code) - - datadec = numpy.zeros((nChannels, nHeis + len(inverse_filter) - 1), dtype=numpy.complex) - ####################################### - ini = time.time() - - for i in range(nChannels): - datadec[i,:] = numpy.convolve(signal[i,:], inverse_filter, mode='full') - - datadec = datadec[:,120:120+nHeis] - - print time.time() - ini - - return datadec - -nChannels, nHeis = 8, 3900 -index = 300 -code = numpy.array([1, 1, -1, -1, -1, 1, 1, 1, -1, -1, -1, -1, -1, -1, -1, 1, -1, 1, -1, 1, 1, -1, 1, 1, -1, -1, 1, -1]) -signal = getSignal(nChannels, nHeis) -signal[0,index:index+len(code)] = code*10 - -signalout = time_decoding(signal, code) -signalout1 = freq_decoding(signal, code) -signalout2 = fftconvol_decoding(signal, code) -signalout3 = filter_decoding(signal, code) - -#pl.plot(numpy.abs(signal[0])) -pl.plot(numpy.abs(signalout[0])) -#pl.plot(numpy.abs(signalout1[0])) -#pl.plot(numpy.abs(signalout2[0])) -pl.plot(numpy.abs(signalout3[0])+0.5) -pl.show() - - \ No newline at end of file diff --git a/schainpy/zerorpc/MyClient01.py b/schainpy/zerorpc/MyClient01.py new file mode 100644 index 0000000..0babed8 --- /dev/null +++ b/schainpy/zerorpc/MyClient01.py @@ -0,0 +1,147 @@ +''' +Created on Jul 11, 2014 + +@author: roj-idl71 +''' +import time +from gevent import sleep + +import zerorpc +from schainpy.model import * +from schainpy.serializer.DataTranslate import serial2Obj, serial2Dict +# import schainpy.model.io.jroIO_usrp + +def createObjVolt(): + ''' + This function creates a processing object "VoltProc" with some operations. + such as: "CohInt", "Scope", etc + These class are found inside schainpy.model.proc and schainpy.model.graphics + ''' + procObj = VoltageProc() + + opObj = CohInt() + procObj.addOperation(opObj, 1) + + opObj = Scope() + procObj.addOperation(opObj, 2) + + return procObj + +def createObjSpec(): + ''' + This function creates a processing object "SpecProc" with some operation objects + such as: "IncohInt", "SpectraPlot", "RTIPlot", etc + These class are found inside schainpy.model.proc and schainpy.model.graphics + ''' + + procObj = SpectraProc() + + opObj = IncohInt() + procObj.addOperation(opObj, objId = 1) + + opObj = SpectraPlot() + procObj.addOperation(opObj, objId = 2) + + opObj = RTIPlot() + procObj.addOperation(opObj, objId = 3) + + opObj = SpectraPlot() + procObj.addOperation(opObj, objId = 4) + + opObj = RTIPlot() + procObj.addOperation(opObj, objId = 5) + + return procObj + +def processingSpec(procObj, dataInObj): + + procObj.setInput(dataInObj) + procObj.run(nFFTPoints = 16) + + procObj.call(opType = "external", + opId = 1, + n=1) + + procObj.call(opType = "external", + opId = 2, + id=191, + zmin=-100, + zmax=-40) + + procObj.call(opType = "external", + opId = 3, + id=192, + zmin=-100, + zmax=-40, + timerange=10*60) + +# procObj.call(opType = "self", +# opName = "selectChannels", +# channelList = [0,1]) +# +# procObj.call(opType = "self", +# opName = "selectHeights", +# minHei = 300, +# maxHei = 400) +# +# procObj.call(opType = "external", +# opId = 4, +# id=193, +# zmin=-100, +# zmax=-40) +# +# procObj.call(opType = "external", +# opId = 5, +# id=194, +# zmin=-100, +# zmax=-40, +# timerange=10*60) + +def printSpeed(deltaTime, mySerial): + + #################### + size = len(mySerial)/1024. + vel = 1.0*size / deltaTime + + print "Index [", replayerObj.getProfileIndex(), "]: ", + print "Total time %5.2f ms, Data size %5.2f KB, Speed %5.2f MB/s" %(deltaTime, size, vel) + #################### + +if __name__ == '__main__': + + procObj = createObjSpec() + + replayerObj = zerorpc.Client() + replayerObj.connect("tcp://127.0.0.1:4242") + + serializer = replayerObj.getSerializer() + + ini = time.time() + mySerialMetadata = replayerObj.getSerialMetaData() + deltaTime = (time.time() - ini)*1024 + + printSpeed(deltaTime, mySerialMetadata) + + myMetaDict = serial2Dict(mySerialMetadata, + serializer = serializer) +# print myMetaDict + while True: + ini = time.time() + mySerialData = replayerObj.getSerialData() + deltaTime = (time.time() - ini)*1024 + + if not mySerialData: + print "No more data" + break + +# myDataDict = SERIALIZER.loads(mySerialData) +# print myDataDict +# continue + + printSpeed(deltaTime, mySerialData) + + dataInObj = serial2Obj(mySerialData, + metadataDict=myMetaDict, + serializer = serializer) + processingSpec(procObj, dataInObj) + sleep(1e-1) \ No newline at end of file diff --git a/schainpy/zerorpc/MyClient02.py b/schainpy/zerorpc/MyClient02.py new file mode 100644 index 0000000..dffb82f --- /dev/null +++ b/schainpy/zerorpc/MyClient02.py @@ -0,0 +1,13 @@ +''' +Created on Jul 11, 2014 + +@author: roj-idl71 +''' + +import zerorpc + +if __name__ == '__main__': + c = zerorpc.Client() + c.connect("tcp://127.0.0.1:4242") + c.load("file2") # AAAHH! The previously loaded model gets overwritten here! + print c.getModelName() \ No newline at end of file diff --git a/schainpy/zerorpc/MyServer.py b/schainpy/zerorpc/MyServer.py new file mode 100644 index 0000000..5d8ad2e --- /dev/null +++ b/schainpy/zerorpc/MyServer.py @@ -0,0 +1,33 @@ +''' +Created on Jul 11, 2014 + +@author: roj-idl71 +''' +# import sys +import datetime +import zerorpc + +from schainpy.model.io.jrodataIO import USRPReaderAPI +# from schainpy.serializer.DataTranslate import serial2Obj + +if __name__ == '__main__': + + replayerObj = USRPReaderAPI(serializer='msgpack') + + replayerObj.setup(path='/Volumes/DATA/haystack/passive_radar/', + startDate=datetime.date(2000,1,1), + endDate=datetime.date(2015,1,1), + startTime=datetime.time(0,0,0), + endTime=datetime.time(23,59,59), + online=1, + nSamples=500, + channelList = [0,1,2,3,4,5,6,7]) + + replayerObj.start() + + print "Initializing 'zerorpc' server" + s = zerorpc.Server(replayerObj) + s.bind("tcp://0.0.0.0:4242") + s.run() + + print "End" \ No newline at end of file diff --git a/schainpy/zerorpc/__init__.py b/schainpy/zerorpc/__init__.py new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/schainpy/zerorpc/__init__.py diff --git a/schainpy/zerorpc/test/testServer.py b/schainpy/zerorpc/test/testServer.py new file mode 100644 index 0000000..0f81f86 --- /dev/null +++ b/schainpy/zerorpc/test/testServer.py @@ -0,0 +1,177 @@ +''' +Created on Jul 15, 2014 + +@author: roj-idl71 +''' + +import sys +import yaml +import numpy +import jsonpickle + +# import schainpy.serializer.DynamicSerializer as DynamicSerializer + + + +def isNotClassVar(myObj): + + return not hasattr(myObj,'__dict__') + +def isDictFormat(thisValue): + + if type(thisValue) != type({}): + return False + + if '__name__' not in thisValue.keys(): + return False + + return True + +def obj2Dict(myObj): + + myDict = {} + + myDict['__name__'] = myObj.__class__.__name__ + + for thisKey, thisValue in myObj.__dict__.items(): + + if isNotClassVar(thisValue): + myDict[thisKey] = thisValue + continue + + ## If this value is another class instance + myNewDict = obj2Dict(thisValue) + myDict[thisKey] = myNewDict + + return myDict + +def dict2Obj(myDict): + ''' + ''' + + if '__name__' not in myDict.keys(): + return None + + className = eval(myDict['__name__']) + + myObj = className() + + for thisKey, thisValue in myDict.items(): + + if thisKey == '__name__': + continue + + if not isDictFormat(thisValue): + setattr(myObj, thisKey, thisValue) + continue + + myNewObj = dict2Obj(thisValue) + setattr(myObj, thisKey, myNewObj) + + return myObj + +class myTestClass3(object): + + def __init__(self): + ''' + ''' + self.y1 = 'y1' + self.y2 = 'y2' + +class myTestClass2(object): + + def __init__(self): + ''' + ''' + self.x1 = 'x1' + self.x2 = 'x2' + self.otherObj = myTestClass3() + + +class myTestClass(object): + + flagNoData = True + value1 = 1 + value2 = 2 + myObj = None + + def __init__(self): + + ''' + ''' + self.flagNoData = True + self.value1 = 1 + self.value2 = 2 + self.myObj = myTestClass2() + + def get_dtype(self): + + ''' + ''' + return self.value1 + + def set_dtype(self, value): + + ''' + ''' + + self.value1 = value + + dtype = property(get_dtype, set_dtype) + +def myMsgPackTest(): + + import msgpack + import msgpack_numpy as m + import numpy as np + + x = np.random.rand(5) + x_enc = m.encode(x) + x_rec = m.decode(x_enc) + + print x_rec +# +# x_enc = msgpack.packb(x, default=m.encoder) +# x_rec = msgpack.unpackb(x_enc, object_hook=m.decoder) + +if __name__ == '__main__': + + myMsgPackTest() + + sys.exit() + + serializerObj = DynamicSerializer.DynamicSerializer('json') + serializerObj = jsonpickle + + myTestObj = myTestClass() + + myTestObj.flagNoData = False + myTestObj.value1 = [1+3.4j,4,'5',] + myTestObj.value2 = {'x2': numpy.complex(1,2),'x1': 'x1'} +# myTestObj.myObj.x2 = numpy.arange(15, dtype=numpy.complex) + + myDict = obj2Dict(myTestObj) + + myNewObj = dict2Obj(myDict) + +# print myDict +# print myTestObj.__dict__ +# print myNewObj.__dict__ + +# sys.exit() + print myDict + + newSerial = serializerObj.encode(myDict) +# print newSerial + + newDict = serializerObj.decode(newSerial) + print newDict + + myNewObj = dict2Obj(newDict) + + print + print + print 50*'###' + print myTestObj.__dict__ + print myNewObj.__dict__ + \ No newline at end of file diff --git a/schainpy/zerorpc/test/testServer_Voltage.py b/schainpy/zerorpc/test/testServer_Voltage.py new file mode 100644 index 0000000..4ce04bd --- /dev/null +++ b/schainpy/zerorpc/test/testServer_Voltage.py @@ -0,0 +1,46 @@ +''' +Created on Jul 15, 2014 + +@author: roj-idl71 +''' + +import sys +import cPickle + +from schainpy.model.data.jrodata import Voltage +# from schainpy.model.io.jrodataIO import USRPReaderMP +from schainpy.serializer.DynamicSerializer import DynamicSerializer +from schainpy.serializer.DataTranslate import obj2Dict, dict2Obj + + +if __name__ == "__main__": + + serializerObj = DynamicSerializer('yaml') + + myTestObj = Voltage() + + myDict = obj2Dict(myTestObj) + + myNewObj = dict2Obj(myDict) + +# print myDict +# print myTestObj.__dict__ +# print myNewObj.__dict__ +# +# print +# print '#############################' +# print +# newValue = serializerObj.dumps(myDict) +# print newValue +# +# newValue = serializerObj.loads(newValue) +# print newValue + + + print '###########CPICKLE##################' + print myDict + newSerialized = cPickle.dumps(myDict, 2) +# print newValue + + newDict = cPickle.loads(newSerialized) + print newDict \ No newline at end of file diff --git a/setup.py b/setup.py new file mode 100644 index 0000000..c477f94 --- /dev/null +++ b/setup.py @@ -0,0 +1,22 @@ +''' +Created on Jul 16, 2014 + +@author: roj-idl71 +''' + +from distutils.core import setup, Extension + +setup(name="schainpy", + version="1.0", + description="Python tools to read, write and process Jicamarca data", + author="Miguel Urco", + author_email="miguel.urco@jro.igp.gob.pe", + url="http://jro.igp.gob.pe", + packages = {'schainpy', 'schainpy.model', + 'schainpy.model.data', + 'schainpy.model.graphics', + 'schainpy.model.io', + 'schainpy.model.proc', + 'schainpy.model.utils'}, + py_modules=['schainpy.serializer.DataTranslate', + 'schainpy.serializer.JROSerializer']) \ No newline at end of file