diff --git a/schainpy/controller.py b/schainpy/controller.py index 2cb4d36..db56e71 100644 --- a/schainpy/controller.py +++ b/schainpy/controller.py @@ -9,6 +9,11 @@ from xml.dom import minidom #import datetime from model import * +try: + from gevent import sleep +except: + from time import sleep + import ast def prettify(elem): @@ -42,7 +47,7 @@ class ParameterConf(): if self.__formated_value != None: return self.__formated_value - + value = self.value if self.format == 'bool': @@ -731,6 +736,11 @@ class Project(): return procUnitConfObj + def removeProcUnit(self, id): + + if id in self.procUnitConfObjDict.keys(): + self.procUnitConfObjDict.pop(id) + def getReadUnitId(self): readUnitConfObj = self.getReadUnitObj() @@ -886,7 +896,7 @@ class Project(): print "Process suspended" while True: - time.sleep(0.1) + sleep(0.1) if not self.control['pause']: break @@ -896,7 +906,7 @@ class Project(): print "Process reinitialized" if self.control['stop']: - print "Stopping process" + print "Process stopped" break #Closing every process @@ -904,7 +914,7 @@ class Project(): procUnitConfObj = self.procUnitConfObjDict[procKey] procUnitConfObj.close() - print "Process stopped" + print "Process finished" def start(self, filename): diff --git a/schainpy/gui/viewcontroller/basicwindow.py b/schainpy/gui/viewcontroller/basicwindow.py index 301a3af..94a428e 100644 --- a/schainpy/gui/viewcontroller/basicwindow.py +++ b/schainpy/gui/viewcontroller/basicwindow.py @@ -24,6 +24,11 @@ from os.path import expanduser #from CodeWarrior.Standard_Suite import file from comm import * +try: + from gevent import sleep +except: + from time import sleep + from schainpy.gui.figures import tools import numpy @@ -80,9 +85,6 @@ class BasicWindow(QMainWindow, Ui_BasicWindow): self.create = False self.selectedItemTree = None self.commCtrlPThread = None - self.setParameter() - self.create_comm() -# self.create_timers() # self.create_figure() self.temporalFTP = ftpBuffer() self.projectProperCaracteristica = [] @@ -106,7 +108,12 @@ class BasicWindow(QMainWindow, Ui_BasicWindow): self.__ftpProcUnitAdded = False self.__ftpProcUnitId = None - + self.__initialized = False + + self.create_comm() + self.create_updating_timer() + self.setParameter() + @pyqtSignature("") def on_actionOpen_triggered(self): """ @@ -527,7 +534,12 @@ class BasicWindow(QMainWindow, Ui_BasicWindow): if self.volOpCebChannels.isChecked(): - value = self.volOpChannel.text() + value = str(self.volOpChannel.text()) + + if value == "": + print "Please fill channel list" + return 0 + format = 'intlist' if self.volOpComChannels.currentIndex() == 0: name_operation = "selectChannels" @@ -540,7 +552,12 @@ class BasicWindow(QMainWindow, Ui_BasicWindow): opObj.addParameter(name=name_parameter, value=value, format=format) if self.volOpCebHeights.isChecked(): - value = self.volOpHeights.text() + value = str(self.volOpHeights.text()) + + if value == "": + print "Please fill height range" + return 0 + valueList = value.split(',') format = 'float' if self.volOpComHeights.currentIndex() == 0: @@ -551,12 +568,17 @@ class BasicWindow(QMainWindow, Ui_BasicWindow): name_operation = 'selectHeightsByIndex' name_parameter1 = 'minIndex' name_parameter2 = 'maxIndex' + opObj = puObj.addOperation(name=name_operation) opObj.addParameter(name=name_parameter1, value=valueList[0], format=format) opObj.addParameter(name=name_parameter2, value=valueList[1], format=format) if self.volOpCebFilter.isChecked(): - value = self.volOpFilter.text() + value = str(self.volOpFilter.text()) + if value == "": + print "Please fill filter value" + return 0 + format = 'int' name_operation = 'filterByHeights' name_parameter = 'window' @@ -564,7 +586,12 @@ class BasicWindow(QMainWindow, Ui_BasicWindow): opObj.addParameter(name=name_parameter, value=value, format=format) if self.volOpCebProfile.isChecked(): - value = self.volOpProfile.text() + value = str(self.volOpProfile.text()) + + if value == "": + print "Please fill profile value" + return 0 + format = 'intlist' optype = 'other' name_operation = 'ProfileSelector' @@ -1097,7 +1124,12 @@ class BasicWindow(QMainWindow, Ui_BasicWindow): puObj.addParameter(name=name_parameter, value=value2, format=format) if self.specOpCebHeights.isChecked(): - value = self.specOpHeights.text() + value = str(self.specOpHeights.text()) + + if value == "": + print "Please fill height range" + return 0 + valueList = value.split(',') format = 'float' value0 = valueList[0] @@ -1116,7 +1148,12 @@ class BasicWindow(QMainWindow, Ui_BasicWindow): opObj.addParameter(name=name_parameter2, value=value1, format=format) if self.specOpCebChannel.isChecked(): - value = self.specOpChannel.text() + value = str(self.specOpChannel.text()) + + if value == "": + print "Please fill channel list" + return 0 + format = 'intlist' if self.specOpComChannel.currentIndex() == 0: name_operation = "selectChannels" @@ -1124,11 +1161,16 @@ class BasicWindow(QMainWindow, Ui_BasicWindow): else: name_operation = "selectChannelsByIndex" name_parameter = 'channelIndexList' - opObj = puObj.addOperation(name="selectChannels") + opObj = puObj.addOperation(name=name_operation) opObj.addParameter(name=name_parameter, value=value, format=format) if self.specOpCebIncoherent.isChecked(): - value = self.specOpIncoherent.text() + value = str(self.specOpIncoherent.text()) + + if value == "": + print "Please fill Incoherent integration value" + return 0 + name_operation = 'IncohInt' optype = 'other' if self.specOpCobIncInt.currentIndex() == 0: @@ -2300,8 +2342,7 @@ class BasicWindow(QMainWindow, Ui_BasicWindow): self.specHeisGraphPath.setEnabled(True) self.specHeisGraphPrefix.setEnabled(True) self.specHeisGraphToolPath.setEnabled(True) - - #-------ftp-----# + @pyqtSignature("int") def on_specHeisGraphftpSpectra_stateChanged(self, p0): """ @@ -2445,10 +2486,10 @@ class BasicWindow(QMainWindow, Ui_BasicWindow): def on_right_click(self, pos): self.menu = QtGui.QMenu() - quitAction0 = self.menu.addAction("NewProject") - quitAction1 = self.menu.addAction("NewProcessingUnit") - quitAction2 = self.menu.addAction("Delete") - quitAction3 = self.menu.addAction("Exit") + quitAction0 = self.menu.addAction("Create a new project") + quitAction1 = self.menu.addAction("Create a new processing unit") + quitAction2 = self.menu.addAction("Delete selected unit") + quitAction3 = self.menu.addAction("Quit") if len(self.__itemTreeDict) == 0: quitAction2.setEnabled(False) @@ -2493,7 +2534,8 @@ class BasicWindow(QMainWindow, Ui_BasicWindow): # print i.row() if action == quitAction3: - return + self.close() + return 0 def refreshProjectWindow(self, project_name, description, datatype, data_path, startDate, endDate, startTime, endTime, online, delay, set): @@ -2545,18 +2587,36 @@ class BasicWindow(QMainWindow, Ui_BasicWindow): opObj = puObj.getOperationObj(name="selectChannels") + + if opObj == None: + opObj = puObj.getOperationObj(name="selectChannelsByIndex") + if opObj == None: self.volOpChannel.clear() self.volOpCebChannels.setCheckState(0) - else: - value = opObj.getParameterValue(parameterName='channelList') - value = str(value)[1:-1] - self.volOpChannel.setText(value) - self.volOpChannel.setEnabled(True) - self.volOpCebChannels.setCheckState(QtCore.Qt.Checked) - - + channelEnabled = False + try: + value = opObj.getParameterValue(parameterName='channelList') + value = str(value)[1:-1] + channelEnabled = True + channelMode = 0 + except: + pass + try: + value = opObj.getParameterValue(parameterName='channelIndexList') + value = str(value)[1:-1] + channelEnabled = True + channelMode = 1 + except: + pass + + if channelEnabled: + self.volOpChannel.setText(value) + self.volOpChannel.setEnabled(True) + self.volOpCebChannels.setCheckState(QtCore.Qt.Checked) + self.VOLOpComChannel.setCurrentIndex(channelMode) + opObj = puObj.getOperationObj(name="selectHeights") if opObj == None: self.volOpHeights.clear() @@ -2811,15 +2871,35 @@ class BasicWindow(QMainWindow, Ui_BasicWindow): self.specOpCebCrossSpectra.setCheckState(QtCore.Qt.Checked) opObj = puObj.getOperationObj(name="selectChannels") + + if opObj == None: + opObj = puObj.getOperationObj(name="selectChannelsByIndex") + if opObj == None: self.specOpChannel.clear() self.specOpCebChannel.setCheckState(0) - else: - value = opObj.getParameterValue(parameterName='channelList') - value = str(value)[1:-1] - self.specOpChannel.setText(value) - self.specOpChannel.setEnabled(True) - self.specOpCebChannel.setCheckState(QtCore.Qt.Checked) + else: + channelEnabled = False + try: + value = opObj.getParameterValue(parameterName='channelList') + value = str(value)[1:-1] + channelEnabled = True + channelMode = 0 + except: + pass + try: + value = opObj.getParameterValue(parameterName='channelIndexList') + value = str(value)[1:-1] + channelEnabled = True + channelMode = 1 + except: + pass + + if channelEnabled: + self.specOpChannel.setText(value) + self.specOpChannel.setEnabled(True) + self.specOpCebChannel.setCheckState(QtCore.Qt.Checked) + self.specOpComChannel.setCurrentIndex(channelMode) opObj = puObj.getOperationObj(name="selectHeights") if opObj == None: @@ -3556,13 +3636,14 @@ class BasicWindow(QMainWindow, Ui_BasicWindow): self.specGgraphChannelList.clear() def create_comm(self): + self.commCtrlPThread = CommCtrlProcessThread() self.commCtrlPThread.start() - def create_timers(self): + def create_updating_timer(self): self.comm_data_timer = QtCore.QTimer(self) - self.comm_data_timer.timeout.connect(self.on_comm_data_timer) - self.comm_data_timer.start(10) + self.comm_data_timer.timeout.connect(self.on_comm_updating_timer) + self.comm_data_timer.start(1000) def create_figure(self): self.queue_plot = Queue.Queue() @@ -3580,15 +3661,15 @@ class BasicWindow(QMainWindow, Ui_BasicWindow): if not self.running: app.quit() - def on_comm_data_timer(self): - # lee el data_queue y la coloca en el queue de ploteo - try: - reply = self.commCtrlPThread.data_q.get(block=False) - self.queue_plot.put(reply.data) - - except Queue.Empty: - pass - +# def on_comm_data_timer(self): +# # lee el data_queue y la coloca en el queue de ploteo +# try: +# reply = self.commCtrlPThread.data_q.get(block=False) +# self.queue_plot.put(reply.data) +# +# except Queue.Empty: +# pass + def createProjectView(self, id): self.create = False @@ -3812,7 +3893,10 @@ class BasicWindow(QMainWindow, Ui_BasicWindow): if not procUnitConfObj: return - procUnitConfObj.removeOperations() + projectObj.removeProcUnit(procUnitConfObj.getId()) + + if procUnitConfObj.getId() not in self.__puObjDict.keys(): + return self.__puObjDict.pop(procUnitConfObj.getId()) @@ -3935,8 +4019,15 @@ class BasicWindow(QMainWindow, Ui_BasicWindow): channel = value self.bufferVoltage("Processing Unit", "Select Channel", channel) - - + opObj = puObj.getOperationObj(name="selectChannelsByIndex") + if opObj == None: + channel = None + else: + value = opObj.getParameterValue(parameterName='channelIndexList') + value = str(value)#[1:-1] + channel = value + self.bufferVoltage("Processing Unit", "Select Channel by Index", channel) + opObj = puObj.getOperationObj(name="selectHeights") if opObj == None: heights = None @@ -4201,11 +4292,23 @@ class BasicWindow(QMainWindow, Ui_BasicWindow): opObj = puObj.getOperationObj(name="selectChannels") if opObj == None: channel = None - else: - value = opObj.getParameterValue(parameterName='channelList') - value = str(value)[1:-1] - channel = value - self.bufferSpectra("Processing Unit", "Channel", channel) + else: + try: + value = opObj.getParameterValue(parameterName='channelList') + value = str(value)[1:-1] + channel = value + + self.bufferSpectra("Processing Unit", "Channel List", channel) + except: + pass + try: + value = opObj.getParameterValue(parameterName='channelIndexList') + value = str(value)[1:-1] + channel = value + + self.bufferSpectra("Processing Unit", "Channel Index List", channel) + except: + pass opObj = puObj.getOperationObj(name="selectHeights") if opObj == None: @@ -5262,6 +5365,9 @@ class BasicWindow(QMainWindow, Ui_BasicWindow): def openProject(self): + self.actionStart.setEnabled(False) + self.actionStarToolbar.setEnabled(False) + self.create = False self.frame_2.setEnabled(True) home = expanduser("~") @@ -5345,6 +5451,18 @@ class BasicWindow(QMainWindow, Ui_BasicWindow): self.console.append("The selected xml file has been loaded successfully") # self.refreshPUWindow(datatype=datatype,puObj=puObj) + self.actionStart.setEnabled(True) + self.actionStarToolbar.setEnabled(True) + + def on_comm_updating_timer(self): + # Verifica si algun proceso ha sido inicializado y sigue ejecutandose + + if not self.__initialized: + return + + if not self.commCtrlPThread.isRunning(): + self.stopProject() + def playProject(self, ext=".xml"): projectObj = self.getSelectedProjectObj() @@ -5369,21 +5487,14 @@ class BasicWindow(QMainWindow, Ui_BasicWindow): self.actionStopToolbar.setEnabled(True) self.console.append("Please Wait...") -# try: self.commCtrlPThread.cmd_q.put(ProcessCommand(ProcessCommand.PROCESS, filename)) -# # -# except: -# self.console.append("Error............................................!") -# self.actionStarToolbar.setEnabled(True) -# self.actionPauseToolbar.setEnabled(False) -# self.actionStopToolbar.setEnabled(False) - -# filename = '/home/dsuarez/workspace_signalchain/schain_guiJune04/test/ewdrifts3.xml' -# data = filename -# self.commCtrlPThread.cmd_q.put(ProcessCommand(ProcessCommand.PROCESS, data)) + sleep(0.5) + self.__initialized = True def stopProject(self): + self.__initialized = False + self.commCtrlPThread.cmd_q.put(ProcessCommand(ProcessCommand.STOP, True)) self.actionStart.setEnabled(True) @@ -6029,15 +6140,23 @@ class BasicWindow(QMainWindow, Ui_BasicWindow): sys.stderr = sys.__stderr__ def normalOutputWritten(self, text): - self.console.append(text) + color_black = QtGui.QColor(0,0,0) + self.console.setTextColor(color_black) + self.console.append(text) + + def errorOutputWritten(self, text): + color_red = QtGui.QColor(255,0,0) + color_black = QtGui.QColor(0,0,0) + + self.console.setTextColor(color_red) + self.console.append(text) + self.console.setTextColor(color_black) - def setParameter(self): self.setWindowTitle("ROJ-Signal Chain") self.setWindowIcon(QtGui.QIcon( os.path.join(FIGURES_PATH,"adn.jpg") )) - sys.stdout = ShowMeConsole(textWritten=self.normalOutputWritten) - # sys.stderr = ShowMeConsole(textWritten=self.normalOutputWritten) + self.tabWidgetProject.setEnabled(False) self.tabVoltage.setEnabled(False) self.tabSpectra.setEnabled(False) @@ -6204,6 +6323,9 @@ class BasicWindow(QMainWindow, Ui_BasicWindow): self.specGgraphDbsrange.setToolTip('Example: 30,170') self.specGraphPrefix.setToolTip('Example: EXPERIMENT_NAME') + + sys.stdout = ShowMeConsole(textWritten=self.normalOutputWritten) + sys.stderr = ShowMeConsole(textWritten=self.errorOutputWritten) class UnitProcessWindow(QMainWindow, Ui_UnitProcess): diff --git a/schainpy/gui/viewcontroller/comm.py b/schainpy/gui/viewcontroller/comm.py index d1567cc..d7b16fc 100644 --- a/schainpy/gui/viewcontroller/comm.py +++ b/schainpy/gui/viewcontroller/comm.py @@ -1,6 +1,9 @@ import threading import Queue -from time import sleep +try: + from gevent import sleep +except: + from time import sleep from schainpy.controller import Project from command import * @@ -49,6 +52,7 @@ class CommCtrlProcessThread(threading.Thread): self.socketIO = None self.mySocket = None + self.controllerObj = None self.handlers = { ProcessCommand.PROCESS: self._handle_ioPROCESSTHREAD, @@ -68,7 +72,16 @@ class CommCtrlProcessThread(threading.Thread): sleep(0.1) continue - + def isRunning(self): + + if self.controllerObj == None: + return False + + if self.controllerObj.isAlive(): + return True + + return False + def _handle_ioPROCESSTHREAD(self, cmd): filename = cmd.data self.controllerObj = ControllerThread(filename=filename) @@ -79,6 +92,8 @@ class CommCtrlProcessThread(threading.Thread): def _handle_ioSTOP(self, cmd): self.controllerObj.stop() + self.controllerObj.join() +# print "Process thread finished" def _handle_ioDATA(self, cmd): self.reply_q.put(self._success_reply_data(data=cmd.data)) diff --git a/schainpy/model/data/jroamisr.py b/schainpy/model/data/jroamisr.py index 3ccf9ce..630da15 100644 --- a/schainpy/model/data/jroamisr.py +++ b/schainpy/model/data/jroamisr.py @@ -79,5 +79,12 @@ class AMISR: def isEmpty(self): return self.flagNoData + + def getTimeInterval(self): + + timeInterval = self.ippSeconds * self.nCohInt + + return timeInterval + timeInterval = property(getTimeInterval, "I'm the 'timeInterval' property") nHeights = property(getNHeights, "I'm the 'nHeights' property.") \ No newline at end of file diff --git a/schainpy/model/data/jrodata.py b/schainpy/model/data/jrodata.py index 9b24b7d..961af38 100644 --- a/schainpy/model/data/jrodata.py +++ b/schainpy/model/data/jrodata.py @@ -659,6 +659,8 @@ class SpectraHeis(Spectra): pairsList = None + nCohInt = None + nIncohInt = None def __init__(self): @@ -694,6 +696,10 @@ class SpectraHeis(Spectra): self.blocksize = None self.profileIndex = 0 + + self.nCohInt = 1 + + self.nIncohInt = 1 def getNormFactor(self): pwcode = 1 @@ -713,7 +719,7 @@ class SpectraHeis(Spectra): normFactor = property(getNormFactor, "I'm the 'getNormFactor' property.") timeInterval = property(getTimeInterval, "I'm the 'timeInterval' property") -class Fits: +class Fits(JROData): heightList = None @@ -765,9 +771,9 @@ class Fits: self.utctime = None - self.nCohInt = None + self.nCohInt = 1 - self.nIncohInt = None + self.nIncohInt = 1 self.useLocalTime = True @@ -852,7 +858,9 @@ class Fits: def getTimeInterval(self): - raise ValueError, "This method is not implemented yet" + timeInterval = self.ippSeconds * self.nCohInt * self.nIncohInt + + return timeInterval datatime = property(getDatatime, "I'm the 'datatime' property") nHeights = property(getNHeights, "I'm the 'nHeights' property.") @@ -1026,7 +1034,14 @@ class Correlation(JROData): noise = jspectra0[:,freq_dc,:] - jspectra[:,freq_dc,:] return noise + + def getTimeInterval(self): + + timeInterval = self.ippSeconds * self.nCohInt * self.nPoints + + return timeInterval + timeInterval = property(getTimeInterval, "I'm the 'timeInterval' property") # pairsList = property(getPairsList, "I'm the 'pairsList' property.") # nPoints = property(getNPoints, "I'm the 'nPoints' property.") calculateVelocity = property(getCalculateVelocity, "I'm the 'calculateVelocity' property.") @@ -1060,7 +1075,7 @@ class Parameters(JROData): noise = None #Noise Potency - initUtcTime = None #Initial UTC time +# initUtcTime = None #Initial UTC time paramInterval = None #Time interval to calculate Parameters in seconds @@ -1078,8 +1093,6 @@ class Parameters(JROData): data_output = None #Out signal - - def __init__(self): ''' Constructor @@ -1089,13 +1102,13 @@ class Parameters(JROData): self.systemHeaderObj = SystemHeader() self.type = "Parameters" - + def getTimeRange1(self): datatime = [] - datatime.append(self.initUtcTime) - datatime.append(self.initUtcTime + self.outputInterval - 1) + datatime.append(self.ltctime) + datatime.append(self.ltctime + self.outputInterval - 1) datatime = numpy.array(datatime) diff --git a/schainpy/model/graphics/figure.py b/schainpy/model/graphics/figure.py index fb8889f..6ff47e4 100644 --- a/schainpy/model/graphics/figure.py +++ b/schainpy/model/graphics/figure.py @@ -102,42 +102,6 @@ class Figure(Operation): xmax_sec = time.mktime(maxdt.timetuple()) return xmin_sec, xmax_sec - - - - - -# if timerange != None: -# txmin = x[0] - x[0]%timerange -# else: -# txmin = numpy.min(x) -# -# thisdatetime = datetime.datetime.utcfromtimestamp(txmin) -# thisdate = datetime.datetime.combine(thisdatetime.date(), datetime.time(0,0,0)) -# -# #################################################### -# #If the x is out of xrange -# if xmax != None: -# if xmax < (thisdatetime - thisdate).seconds/(60*60.): -# xmin = None -# xmax = None -# -# if xmin == None: -# td = thisdatetime - thisdate -# xmin = td.seconds/(60*60.) -# -# if xmax == None: -# xmax = xmin + self.timerange/(60*60.) -# -# mindt = thisdate + datetime.timedelta(hours=xmin) - datetime.timedelta(seconds=time.timezone) -# tmin = time.mktime(mindt.timetuple()) -# -# maxdt = thisdate + datetime.timedelta(hours=xmax) - datetime.timedelta(seconds=time.timezone) -# tmax = time.mktime(maxdt.timetuple()) -# -# #self.timerange = tmax - tmin -# -# return tmin, tmax def init(self, id, nplots, wintitle): @@ -284,9 +248,9 @@ class Figure(Operation): raise ValueError, "This method is not implemented" - def close(self): + def close(self, show=False): - self.__driver.closeFigure() + self.__driver.closeFigure(show=show, fig=self.fig) axesList = property(getAxesObjList) diff --git a/schainpy/model/graphics/jroplot_spectra.py b/schainpy/model/graphics/jroplot_spectra.py index 8d495cb..c7b6ce6 100644 --- a/schainpy/model/graphics/jroplot_spectra.py +++ b/schainpy/model/graphics/jroplot_spectra.py @@ -294,11 +294,12 @@ class CrossSpectraPlot(Figure): raise ValueError, "Pair %s is not in dataOut.pairsList" %str(pair) pairsIndexList.append(dataOut.pairsList.index(pair)) - if pairsIndexList == []: + if not pairsIndexList: return if len(pairsIndexList) > 4: pairsIndexList = pairsIndexList[0:4] + factor = dataOut.normFactor x = dataOut.getVelRange(1) y = dataOut.getHeiRange() diff --git a/schainpy/model/graphics/mpldriver.py b/schainpy/model/graphics/mpldriver.py index e742987..3091b6a 100644 --- a/schainpy/model/graphics/mpldriver.py +++ b/schainpy/model/graphics/mpldriver.py @@ -30,13 +30,23 @@ def createFigure(id, wintitle, width, height, facecolor="w", show=True): return fig -def closeFigure(show=False): +def closeFigure(show=False, fig=None): matplotlib.pyplot.ioff() + matplotlib.pyplot.pause(0.1) + if show: matplotlib.pyplot.show() - - matplotlib.pyplot.close() + + if fig != None: + matplotlib.pyplot.close(fig) + matplotlib.pyplot.pause(0.1) + matplotlib.pyplot.ion() + return + + matplotlib.pyplot.close("all") + matplotlib.pyplot.pause(0.1) + matplotlib.pyplot.ion() return def saveFigure(fig, filename): @@ -420,6 +430,6 @@ def polar(iplot, x, y, xlabel='', ylabel='', title=''): def draw(fig): if type(fig) == 'int': - raise ValueError, "This parameter should be of tpye matplotlib figure" + raise ValueError, "Error drawing: Fig parameter should be a matplotlib figure object figure" fig.canvas.draw() diff --git a/schainpy/model/io/jroIO_amisr.py b/schainpy/model/io/jroIO_amisr.py index edb45e4..234296b 100644 --- a/schainpy/model/io/jroIO_amisr.py +++ b/schainpy/model/io/jroIO_amisr.py @@ -15,6 +15,11 @@ import numpy from schainpy.model.proc.jroproc_base import ProcessingUnit, Operation from schainpy.model.data.jroamisr import AMISR +try: + from gevent import sleep +except: + from time import sleep + class RadacHeader(): def __init__(self, fp): header = 'Raw11/Data/RadacHeader' @@ -337,7 +342,7 @@ class AMISRReader(ProcessingUnit): filename = self.filenameList[0] while self.__filename_online == filename: print 'waiting %d seconds to get a new file...'%(self.__waitForNewFile) - time.sleep(self.__waitForNewFile) + sleep(self.__waitForNewFile) self.__selectDataForTimes(online=True) filename = self.filenameList[0] diff --git a/schainpy/model/io/jroIO_heispectra.py b/schainpy/model/io/jroIO_heispectra.py index addaea8..d8b66de 100644 --- a/schainpy/model/io/jroIO_heispectra.py +++ b/schainpy/model/io/jroIO_heispectra.py @@ -384,6 +384,21 @@ class FitsReader(ProcessingUnit): return 1 + def __setValuesFromHeader(self): + + self.dataOut.header = self.header_dict + self.dataOut.expName = self.expName + self.dataOut.nChannels = self.nChannels + self.dataOut.timeZone = self.timeZone + self.dataOut.dataBlocksPerFile = self.dataBlocksPerFile + self.dataOut.comments = self.comments +# self.dataOut.timeInterval = self.timeInterval + self.dataOut.channelList = self.channelList + self.dataOut.heightList = self.heightList + + self.dataOut.nCohInt = self.nCohInt + self.dataOut.nIncohInt = self.nIncohInt + def readHeader(self): headerObj = self.fitsObj[0] @@ -438,7 +453,7 @@ class FitsReader(ProcessingUnit): return 0 self.readHeader() - + self.__setValuesFromHeader() self.nReadBlocks = 0 # self.blockIndex = 1 return 1 @@ -695,15 +710,15 @@ class FitsReader(ProcessingUnit): self.dataOut.data_header = self.data_header_dict self.dataOut.utctime = self.utc - self.dataOut.header = self.header_dict - self.dataOut.expName = self.expName - self.dataOut.nChannels = self.nChannels - self.dataOut.timeZone = self.timeZone - self.dataOut.dataBlocksPerFile = self.dataBlocksPerFile - self.dataOut.comments = self.comments - self.dataOut.timeInterval = self.timeInterval - self.dataOut.channelList = self.channelList - self.dataOut.heightList = self.heightList +# self.dataOut.header = self.header_dict +# self.dataOut.expName = self.expName +# self.dataOut.nChannels = self.nChannels +# self.dataOut.timeZone = self.timeZone +# self.dataOut.dataBlocksPerFile = self.dataBlocksPerFile +# self.dataOut.comments = self.comments +# # self.dataOut.timeInterval = self.timeInterval +# self.dataOut.channelList = self.channelList +# self.dataOut.heightList = self.heightList self.dataOut.flagNoData = False return self.dataOut.data diff --git a/schainpy/model/io/jroIO_hf.py b/schainpy/model/io/jroIO_hf.py index ff01e22..35c6957 100644 --- a/schainpy/model/io/jroIO_hf.py +++ b/schainpy/model/io/jroIO_hf.py @@ -16,6 +16,10 @@ from model.data.jroheaderIO import RadarControllerHeader, SystemHeader from model.data.jrodata import Voltage from model.proc.jroproc_base import ProcessingUnit, Operation +try: + from gevent import sleep +except: + from time import sleep def isNumber(str): """ @@ -506,7 +510,7 @@ class HFReader(ProcessingUnit): filename = self.filenameList[0] while self.filename_online == filename: print 'waiting %d seconds to get a new file...'%(self.__waitForNewFile) - time.sleep(self.__waitForNewFile) + sleep(self.__waitForNewFile) #self.__findDataForDates(online=True) self.__selectDataForTimes(online=True) filename = self.filenameList[0] @@ -518,12 +522,12 @@ class HFReader(ProcessingUnit): print "%s is not the rigth size"%filename delay=2 print 'waiting %d seconds for delay...'%(delay) - time.sleep(delay) + sleep(delay) sizeoffile=os.path.getsize(filename) if sizeoffile<1670240: delay print 'waiting %d more seconds for delay...'%(delay) - time.sleep(delay) + sleep(delay) diff --git a/schainpy/model/proc/jroproc_correlation.py b/schainpy/model/proc/jroproc_correlation.py index f39312e..dda51f2 100644 --- a/schainpy/model/proc/jroproc_correlation.py +++ b/schainpy/model/proc/jroproc_correlation.py @@ -15,7 +15,7 @@ class CorrelationProc(ProcessingUnit): self.profIndex = 0 self.dataOut = Correlation() - def __updateObjFromInput(self): + def __updateObjFromVoltage(self): self.dataOut.timeZone = self.dataIn.timeZone self.dataOut.dstFlag = self.dataIn.dstFlag @@ -42,7 +42,7 @@ class CorrelationProc(ProcessingUnit): self.dataOut.ippSeconds = self.dataIn.ippSeconds # self.dataOut.windowOfFilter = self.dataIn.windowOfFilter - self.dataOut.timeInterval = self.dataIn.timeInterval*self.dataOut.nPoints +# self.dataOut.timeInterval = self.dataIn.timeInterval*self.dataOut.nPoints def removeDC(self, jspectra): @@ -189,7 +189,7 @@ class CorrelationProc(ProcessingUnit): self.buffer = self.removeDC(self.buffer) #--------------------------------------------- self.dataOut.data_volts = self.buffer - self.__updateObjFromInput() + self.__updateObjFromVoltage() self.dataOut.data_corr = numpy.zeros((len(pairsList), len(lagT),len(lagR), self.dataIn.nHeights), diff --git a/schainpy/model/proc/jroproc_heispectra.py b/schainpy/model/proc/jroproc_heispectra.py index 6e6d604..2f8b69d 100644 --- a/schainpy/model/proc/jroproc_heispectra.py +++ b/schainpy/model/proc/jroproc_heispectra.py @@ -14,7 +14,7 @@ class SpectraHeisProc(ProcessingUnit): # self.profIndex = 0 self.dataOut = SpectraHeis() - def __updateObjFromInput(self): + def __updateObjFromVoltage(self): self.dataOut.timeZone = self.dataIn.timeZone self.dataOut.dstFlag = self.dataIn.dstFlag @@ -48,19 +48,23 @@ class SpectraHeisProc(ProcessingUnit): # self.dataOut.ippSeconds= self.dataIn.ippSeconds self.dataOut.windowOfFilter = self.dataIn.windowOfFilter - self.dataOut.timeInterval = self.dataIn.timeInterval*self.dataOut.nIncohInt +# self.dataOut.timeInterval = self.dataIn.timeInterval*self.dataOut.nIncohInt # self.dataOut.set=self.dataIn.set # self.dataOut.deltaHeight=self.dataIn.deltaHeight def __updateObjFromFits(self): + self.dataOut.utctime = self.dataIn.utctime self.dataOut.channelIndexList = self.dataIn.channelIndexList self.dataOut.channelList = self.dataIn.channelList self.dataOut.heightList = self.dataIn.heightList self.dataOut.data_spc = self.dataIn.data - self.dataOut.timeInterval = self.dataIn.timeInterval + self.dataOut.ippSeconds = self.dataIn.ippSeconds + self.dataOut.nCohInt = self.dataIn.nCohInt + self.dataOut.nIncohInt = self.dataIn.nIncohInt +# self.dataOut.timeInterval = self.dataIn.timeInterval self.dataOut.timeZone = self.dataIn.timeZone self.dataOut.useLocalTime = True # self.dataOut. @@ -87,7 +91,7 @@ class SpectraHeisProc(ProcessingUnit): return if self.dataIn.type == "Voltage": - self.__updateObjFromInput() + self.__updateObjFromVoltage() self.__getFft() self.dataOut.flagNoData = False diff --git a/schainpy/model/proc/jroproc_parameters.py b/schainpy/model/proc/jroproc_parameters.py index f5fe63b..b64eb73 100644 --- a/schainpy/model/proc/jroproc_parameters.py +++ b/schainpy/model/proc/jroproc_parameters.py @@ -1327,6 +1327,7 @@ class WindProfiler(Operation): return A1 def __correctValues(self, heiRang, phi, velRadial, SNR): + listPhi = phi.tolist() maxid = listPhi.index(max(listPhi)) minid = listPhi.index(min(listPhi)) @@ -1615,14 +1616,19 @@ class WindProfiler(Operation): else: correctFactor = 1 if kwargs.has_key('channelList'): channelList = kwargs['channelList'] - if len(channelList) == 2: - horizontalOnly = True arrayChannel = numpy.array(channelList) param = param[arrayChannel,:,:] theta_x = theta_x[arrayChannel] theta_y = theta_y[arrayChannel] velRadial0 = param[:,1,:] #Radial velocity + + if velRadial0.shape[0] != theta_x.shape[0] or velRadial0.shape[0] != theta_y.shape[0]: + raise ValueError, "The max number of channels is %d, and the length of cosine director is %d. Please check: dirCosX, dirCosY, elevation or azimuth arguments" %(velRadial0.shape[0], theta_x.shape[0]) + + if theta_x.shape[0] == 2: + horizontalOnly = True + dataOut.data_output, dataOut.heightList, dataOut.data_SNR = self.techniqueDBS(velRadial0, theta_x, theta_y, azimuth, correctFactor, horizontalOnly, heightList, SNR) #DBS Function dataOut.utctimeInit = dataOut.utctime dataOut.outputInterval = dataOut.timeInterval diff --git a/schainpy/model/proc/jroproc_spectra.py b/schainpy/model/proc/jroproc_spectra.py index 3e9be20..b651cf7 100644 --- a/schainpy/model/proc/jroproc_spectra.py +++ b/schainpy/model/proc/jroproc_spectra.py @@ -90,6 +90,11 @@ class SpectraProc(ProcessingUnit): #calculo de cross-spectra cspc = numpy.zeros((self.dataOut.nPairs, self.dataOut.nFFTPoints, self.dataOut.nHeights), dtype='complex') for pair in self.dataOut.pairsList: + if pair[0] not in self.dataOut.channelList: + raise ValueError, "Error getting CrossSpectra: pair 0 of (%s) is not in channelList=%s" %(str(pair), str(self.dataOut.channelList)) + if pair[1] not in self.dataOut.channelList: + raise ValueError, "Error getting CrossSpectra: pair 1 of (%s) is not in channelList=%s" %(str(pair), str(self.dataOut.channelList)) + cspc[pairIndex,:,:] = fft_volt[pair[0],:,:] * numpy.conjugate(fft_volt[pair[1],:,:]) pairIndex += 1 blocksize += cspc.size @@ -166,7 +171,33 @@ class SpectraProc(ProcessingUnit): return True - raise ValueError, "The type object %s is not valid"%(self.dataIn.type) + raise ValueError, "The type of input object '%s' is not valid"%(self.dataIn.type) + + def __selectPairs(self, channelList=None): + + if channelList == None: + return + + pairsIndexListSelected = [] + for pairIndex in self.dataOut.pairsIndexList: + #First pair + if self.dataOut.pairsList[pairIndex][0] not in channelList: + continue + #Second pair + if self.dataOut.pairsList[pairIndex][1] not in channelList: + continue + + pairsIndexListSelected.append(pairIndex) + + if not pairsIndexListSelected: + self.dataOut.data_cspc = None + self.dataOut.pairsList = [] + return + + self.dataOut.data_cspc = self.dataOut.data_cspc[pairsIndexListSelected] + self.dataOut.pairsList = self.dataOut.pairsList[pairsIndexListSelected] + + return def selectChannels(self, channelList): @@ -174,7 +205,8 @@ class SpectraProc(ProcessingUnit): for channel in channelList: if channel not in self.dataOut.channelList: - continue + raise ValueError, "Error selecting channels: The value %d in channelList is not valid.\nAvailable channels = %s" %(channel, str(self.dataOut.channelList)) + index = self.dataOut.channelList.index(channel) channelIndexList.append(index) @@ -198,17 +230,21 @@ class SpectraProc(ProcessingUnit): for channelIndex in channelIndexList: if channelIndex not in self.dataOut.channelIndexList: - print channelIndexList - raise ValueError, "The value %d in channelIndexList is not valid" %channelIndex + raise ValueError, "Error selecting channels: The value %d in channelIndexList is not valid.\nAvailable channel indexes = " %(channelIndex, self.dataOut.channelIndexList) # nChannels = len(channelIndexList) data_spc = self.dataOut.data_spc[channelIndexList,:] + data_dc = self.dataOut.data_dc[channelIndexList,:] self.dataOut.data_spc = data_spc + self.dataOut.data_dc = data_dc + self.dataOut.channelList = [self.dataOut.channelList[i] for i in channelIndexList] # self.dataOut.nChannels = nChannels + self.__selectPairs(self.dataOut.channelList) + return 1 def selectHeights(self, minHei, maxHei): @@ -226,8 +262,12 @@ class SpectraProc(ProcessingUnit): Return: 1 si el metodo se ejecuto con exito caso contrario devuelve 0 """ - if (minHei < self.dataOut.heightList[0]) or (minHei > maxHei): - raise ValueError, "some value in (%d,%d) is not valid" % (minHei, maxHei) + + if (minHei > maxHei): + raise ValueError, "Error selecting heights: Height range (%d,%d) is not valid" % (minHei, maxHei) + + if (minHei < self.dataOut.heightList[0]): + minHei = self.dataOut.heightList[0] if (maxHei > self.dataOut.heightList[-1]): maxHei = self.dataOut.heightList[-1] @@ -314,7 +354,7 @@ class SpectraProc(ProcessingUnit): """ if (minIndex < 0) or (minIndex > maxIndex): - raise ValueError, "some value in (%d,%d) is not valid" % (minIndex, maxIndex) + raise ValueError, "Error selecting heights by index: Index range in (%d,%d) is not valid" % (minIndex, maxIndex) if (maxIndex >= self.dataOut.nHeights): maxIndex = self.dataOut.nHeights-1 diff --git a/schainpy/model/proc/jroproc_voltage.py b/schainpy/model/proc/jroproc_voltage.py index 0f84647..8c6cc59 100644 --- a/schainpy/model/proc/jroproc_voltage.py +++ b/schainpy/model/proc/jroproc_voltage.py @@ -34,7 +34,7 @@ class VoltageProc(ProcessingUnit): self.dataOut.data = self.dataIn.data self.dataOut.utctime = self.dataIn.utctime self.dataOut.channelList = self.dataIn.channelList - self.dataOut.timeInterval = self.dataIn.timeInterval +# self.dataOut.timeInterval = self.dataIn.timeInterval self.dataOut.heightList = self.dataIn.heightList self.dataOut.nProfiles = self.dataIn.nProfiles @@ -68,7 +68,7 @@ class VoltageProc(ProcessingUnit): for channel in channelList: if channel not in self.dataOut.channelList: - continue + raise ValueError, "Channel %d is not in %s" %(channel, str(self.dataOut.channelList)) index = self.dataOut.channelList.index(channel) channelIndexList.append(index) @@ -255,7 +255,7 @@ class VoltageProc(ProcessingUnit): flip = self.flip profileList = range(self.dataOut.nProfiles) - if channelList == []: + if not channelList: for thisProfile in profileList: data[:,thisProfile,:] = data[:,thisProfile,:]*flip flip *= -1.0 @@ -271,7 +271,7 @@ class VoltageProc(ProcessingUnit): self.flip = flip else: - if channelList == []: + if not channelList: data[:,:] = data[:,:]*self.flip else: for thisChannel in channelList: