diff --git a/schainpy/model/jroplot.py b/schainpy/model/jroplot.py index eb09afa..d9b89b1 100644 --- a/schainpy/model/jroplot.py +++ b/schainpy/model/jroplot.py @@ -1001,4 +1001,308 @@ class RTIfromNoise(Figure): self.__isConfig = False del self.xdata del self.ydata + + +class SpectraHeisScope(Figure): + + + __isConfig = None + __nsubplots = None + + WIDTHPROF = None + HEIGHTPROF = None + PREFIX = 'spc' + + def __init__(self): + + self.__isConfig = False + self.__nsubplots = 1 + + self.WIDTH = 230 + self.HEIGHT = 250 + self.WIDTHPROF = 120 + self.HEIGHTPROF = 0 + + def getSubplots(self): + + ncol = int(numpy.sqrt(self.nplots)+0.9) + nrow = int(self.nplots*1./ncol + 0.9) + + return nrow, ncol + + def setup(self, idfigure, nplots, wintitle): + + showprofile = False + self.__showprofile = showprofile + self.nplots = nplots + + ncolspan = 1 + colspan = 1 + if showprofile: + ncolspan = 3 + colspan = 2 + self.__nsubplots = 2 + + self.createFigure(idfigure = idfigure, + wintitle = wintitle, + widthplot = self.WIDTH + self.WIDTHPROF, + heightplot = self.HEIGHT + self.HEIGHTPROF) + + nrow, ncol = self.getSubplots() + + counter = 0 + for y in range(nrow): + for x in range(ncol): + + if counter >= self.nplots: + break + + self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1) + + if showprofile: + self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1) + + counter += 1 + +# __isConfig = None +# def __init__(self): +# +# self.__isConfig = False +# self.WIDTH = 600 +# self.HEIGHT = 200 +# +# def getSubplots(self): +# +# nrow = self.nplots +# ncol = 3 +# return nrow, ncol +# +# def setup(self, idfigure, nplots, wintitle): +# +# self.nplots = nplots +# +# self.createFigure(idfigure, wintitle) +# +# nrow,ncol = self.getSubplots() +# colspan = 3 +# rowspan = 1 +# +# for i in range(nplots): +# self.addAxes(nrow, ncol, i, 0, colspan, rowspan) + + def run(self, dataOut, idfigure, wintitle="", channelList=None, + xmin=None, xmax=None, ymin=None, ymax=None, save=False, + figpath='./', figfile=None): + + """ + + Input: + dataOut : + idfigure : + wintitle : + channelList : + xmin : None, + xmax : None, + ymin : None, + ymax : None, + """ + + if channelList == None: + channelIndexList = dataOut.channelIndexList + else: + channelIndexList = [] + for channel in channelList: + if channel not in dataOut.channelList: + raise ValueError, "Channel %d is not in dataOut.channelList" + channelIndexList.append(dataOut.channelList.index(channel)) + +# x = dataOut.heightList + c = 3E8 + deltaHeight = dataOut.heightList[1] - dataOut.heightList[0] + #deberia cambiar para el caso de 1Mhz y 100KHz + x = numpy.arange(-1*dataOut.nHeights/2.,dataOut.nHeights/2.)*(c/(2*deltaHeight*dataOut.nHeights*1000)) + x= x/(10000.0) +# y = dataOut.data[channelIndexList,:] * numpy.conjugate(dataOut.data[channelIndexList,:]) +# y = y.real + datadB = 10.*numpy.log10(dataOut.data_spc) + y = datadB + + thisDatetime = dataOut.datatime + title = "Scope: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) + xlabel = "Frequency" + ylabel = "Intensity (dB)" + + if not self.__isConfig: + nplots = len(channelIndexList) + + self.setup(idfigure=idfigure, + nplots=nplots, + wintitle=wintitle) + + 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) + + self.__isConfig = True + + self.setWinTitle(title) + + for i in range(len(self.axesList)): + title = "Channel %d" %(i) + axes = self.axesList[i] + ychannel = y[i,:] + axes.pline(x, ychannel, + xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, + xlabel=xlabel, ylabel=ylabel, title=title) + + self.draw() + + if save: + date = thisDatetime.strftime("%Y%m%d_%H%M%S") + if figfile == None: + figfile = self.getFilename(name = date) + + self.saveFigure(figpath, figfile) + + +class RTIfromSpectraHeis(Figure): + + __isConfig = None + __nsubplots = None + + PREFIX = 'rtinoise' + + def __init__(self): + + self.timerange = 24*60*60 + self.__isConfig = False + self.__nsubplots = 1 + + self.WIDTH = 820 + self.HEIGHT = 200 + self.WIDTHPROF = 120 + self.HEIGHTPROF = 0 + self.xdata = None + self.ydata = None + + def getSubplots(self): + + ncol = 1 + nrow = 1 + + return nrow, ncol + + def setup(self, idfigure, nplots, wintitle, showprofile=True): + + self.__showprofile = showprofile + self.nplots = nplots + + ncolspan = 7 + colspan = 6 + self.__nsubplots = 2 + + self.createFigure(idfigure = idfigure, + wintitle = wintitle, + widthplot = self.WIDTH+self.WIDTHPROF, + heightplot = self.HEIGHT+self.HEIGHTPROF) + + nrow, ncol = self.getSubplots() + + self.addAxes(nrow, ncol*ncolspan, 0, 0, colspan, 1) + + + def run(self, dataOut, idfigure, wintitle="", channelList=None, showprofile='True', + xmin=None, xmax=None, ymin=None, ymax=None, + timerange=None, + save=False, figpath='./', figfile=None): + + if channelList == None: + channelIndexList = dataOut.channelIndexList + channelList = dataOut.channelList + else: + channelIndexList = [] + for channel in channelList: + if channel not in dataOut.channelList: + 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() + + factor = 1 + data = dataOut.data_spc/factor + data = numpy.average(data,axis=1) + datadB = 10*numpy.log10(data) + +# factor = dataOut.normFactor +# noise = dataOut.getNoise()/factor +# noisedB = 10*numpy.log10(noise) + + thisDatetime = dataOut.datatime + title = "RTI: %s" %(thisDatetime.strftime("%d-%b-%Y")) + xlabel = "Local Time" + ylabel = "Intensity (dB)" + + if not self.__isConfig: + + nplots = 1 + + self.setup(idfigure=idfigure, + nplots=nplots, + wintitle=wintitle, + showprofile=showprofile) + + tmin, tmax = self.getTimeLim(x, xmin, xmax) + if ymin == None: ymin = numpy.nanmin(datadB) + if ymax == None: ymax = numpy.nanmax(datadB) + + self.name = thisDatetime.strftime("%Y%m%d_%H%M%S") + self.__isConfig = True + + self.xdata = numpy.array([]) + self.ydata = numpy.array([]) + + self.setWinTitle(title) + + + title = "RTI Noise %s" %(thisDatetime.strftime("%d-%b-%Y")) + + legendlabels = ["channel %d"%idchannel for idchannel in channelList] + axes = self.axesList[0] + + self.xdata = numpy.hstack((self.xdata, x[0:1])) + + if len(self.ydata)==0: + self.ydata = datadB[channelIndexList].reshape(-1,1) + else: + self.ydata = numpy.hstack((self.ydata, datadB[channelIndexList].reshape(-1,1))) + + + axes.pmultilineyaxis(x=self.xdata, y=self.ydata, + xmin=tmin, xmax=tmax, ymin=ymin, ymax=ymax, + xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels, marker='x', markersize=8, linestyle="solid", + XAxisAsTime=True + ) + + self.draw() + + if save: + + if figfile == None: + figfile = self.getFilename(name = self.name) + + self.saveFigure(figpath, figfile) + + if x[1] + (x[1]-x[0]) >= self.axesList[0].xmax: + self.__isConfig = False + del self.xdata + del self.ydata + + \ No newline at end of file diff --git a/schainpy/model/jroprocessing.py b/schainpy/model/jroprocessing.py index 267e187..71230d5 100644 --- a/schainpy/model/jroprocessing.py +++ b/schainpy/model/jroprocessing.py @@ -1308,3 +1308,309 @@ class ProfileSelector(Operation): return 0 +class SpectraHeisProc(ProcessingUnit): + def __init__(self): + self.objectDict = {} +# self.buffer = None +# self.firstdatatime = None +# self.profIndex = 0 + self.dataOut = SpectraHeis() + + def __updateObjFromInput(self): + self.dataOut.radarControllerHeaderObj = self.dataIn.radarControllerHeaderObj.copy()# + self.dataOut.systemHeaderObj = self.dataIn.systemHeaderObj.copy()# + self.dataOut.channelList = self.dataIn.channelList + self.dataOut.heightList = self.dataIn.heightList +# self.dataOut.dtype = self.dataIn.dtype + self.dataOut.dtype = numpy.dtype([('real',' change this line + self.n = 9999 + self.__byTime = True + + if overlapping: + self.__withOverapping = True + self.__buffer = None + else: + self.__withOverapping = False + self.__buffer = 0 + + self.__profIndex = 0 + + def putData(self, data): + + """ + Add a profile to the __buffer and increase in one the __profileIndex + + """ + + if not self.__withOverapping: + self.__buffer += data.copy() + self.__profIndex += 1 + return + + #Overlapping data + nChannels, nHeis = data.shape + data = numpy.reshape(data, (1, nChannels, nHeis)) + + #If the buffer is empty then it takes the data value + if self.__buffer == None: + self.__buffer = data + self.__profIndex += 1 + return + + #If the buffer length is lower than n then stakcing the data value + if self.__profIndex < self.n: + self.__buffer = numpy.vstack((self.__buffer, data)) + self.__profIndex += 1 + return + + #If the buffer length is equal to n then replacing the last buffer value with the data value + self.__buffer = numpy.roll(self.__buffer, -1, axis=0) + self.__buffer[self.n-1] = data + self.__profIndex = self.n + return + + + def pushData(self): + """ + Return the sum of the last profiles and the profiles used in the sum. + + Affected: + + self.__profileIndex + + """ + + if not self.__withOverapping: + data = self.__buffer + n = self.__profIndex + + self.__buffer = 0 + self.__profIndex = 0 + + return data, n + + #Integration with Overlapping + data = numpy.sum(self.__buffer, axis=0) + n = self.__profIndex + + return data, n + + def byProfiles(self, data): + + self.__dataReady = False + avgdata = None + n = None + + self.putData(data) + + if self.__profIndex == self.n: + + avgdata, n = self.pushData() + self.__dataReady = True + + return avgdata + + def byTime(self, data, datatime): + + self.__dataReady = False + avgdata = None + n = None + + self.putData(data) + + if (datatime - self.__initime) >= self.__integrationtime: + avgdata, n = self.pushData() + self.n = n + self.__dataReady = True + + return avgdata + + def integrate(self, data, datatime=None): + + if self.__initime == None: + self.__initime = datatime + + if self.__byTime: + avgdata = self.byTime(data, datatime) + else: + avgdata = self.byProfiles(data) + + + self.__lastdatatime = datatime + + if avgdata == None: + return None, None + + avgdatatime = self.__initime + + deltatime = datatime -self.__lastdatatime + + if not self.__withOverapping: + self.__initime = datatime + else: + self.__initime += deltatime + + return avgdata, avgdatatime + + def run(self, dataOut, **kwargs): + + if not self.__isConfig: + self.setup(**kwargs) + self.__isConfig = True + + avgdata, avgdatatime = self.integrate(dataOut.data_spc, dataOut.utctime) + +# dataOut.timeInterval *= n + dataOut.flagNoData = True + + if self.__dataReady: + dataOut.data_spc = avgdata + dataOut.nIncohInt *= self.n +# dataOut.nCohInt *= self.n + dataOut.utctime = avgdatatime + dataOut.timeInterval = dataOut.ippSeconds * dataOut.nIncohInt +# dataOut.timeInterval = self.__timeInterval*self.n + dataOut.flagNoData = False \ No newline at end of file diff --git a/schainpy/test/SunExperiment.py b/schainpy/test/SunExperiment.py new file mode 100644 index 0000000..944c92c --- /dev/null +++ b/schainpy/test/SunExperiment.py @@ -0,0 +1,66 @@ +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='/Volumes/data_e/PaseDelSol/Raw/100KHZ', + startDate='2013/02/06', + endDate='2013/12/31', + startTime='17:30:00', + endTime='17:40:59', + online=0, + walk=1) + +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='idfigure', 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='figpath', value='/Users/dsuarez/Pictures/sun_pics', format='str') + + +#opObj11 = procUnitConfObj1.addOperation(name='RTIfromSpectraHeis', optype='other') +#opObj11.addParameter(name='idfigure', value='6', format='int') +#opObj11.addParameter(name='wintitle', value='RTIPLot', format='str') +##opObj11.addParameter(name='zmin', value='10', format='int') +##opObj11.addParameter(name='zmax', value='40', format='int') +#opObj11.addParameter(name='ymin', value='60', format='int') +#opObj11.addParameter(name='ymax', value='130', 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='figpath', value='/Users/dsuarez/Pictures/sun_pics', 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