jroplot_spectra.py
1542 lines
| 48.6 KiB
| text/x-python
|
PythonLexer
|
r487 | ''' | ||
|
r568 | Created on Jul 9, 2014 | ||
@author: roj-idl71 | ||||
|
r487 | ''' | ||
import os | ||||
import datetime | ||||
import numpy | ||||
|
r760 | from figure import Figure, isRealtime, isTimeInHourRange | ||
|
r573 | from plotting_codes import * | ||
|
r487 | |||
|
r953 | |||
|
r487 | class SpectraPlot(Figure): | ||
|
r858 | |||
|
r487 | isConfig = None | ||
__nsubplots = None | ||||
|
r858 | |||
|
r487 | WIDTHPROF = None | ||
HEIGHTPROF = None | ||||
PREFIX = 'spc' | ||||
|
r858 | |||
|
r897 | def __init__(self, **kwargs): | ||
Figure.__init__(self, **kwargs) | ||||
|
r487 | self.isConfig = False | ||
self.__nsubplots = 1 | ||||
|
r858 | |||
r1136 | self.WIDTH = 250 | |||
self.HEIGHT = 250 | ||||
|
r487 | self.WIDTHPROF = 120 | ||
self.HEIGHTPROF = 0 | ||||
self.counter_imagwr = 0 | ||||
|
r858 | |||
|
r573 | self.PLOT_CODE = SPEC_CODE | ||
|
r858 | |||
|
r487 | self.FTP_WEI = None | ||
self.EXP_CODE = None | ||||
self.SUB_EXP_CODE = None | ||||
self.PLOT_POS = None | ||||
|
r858 | |||
|
r568 | self.__xfilter_ena = False | ||
self.__yfilter_ena = False | ||||
|
r858 | |||
|
r487 | def getSubplots(self): | ||
|
r858 | |||
|
r487 | ncol = int(numpy.sqrt(self.nplots)+0.9) | ||
nrow = int(self.nplots*1./ncol + 0.9) | ||||
|
r858 | |||
|
r487 | return nrow, ncol | ||
|
r858 | |||
|
r487 | def setup(self, id, nplots, wintitle, showprofile=True, show=True): | ||
|
r858 | |||
|
r487 | self.__showprofile = showprofile | ||
self.nplots = nplots | ||||
|
r858 | |||
|
r487 | ncolspan = 1 | ||
colspan = 1 | ||||
if showprofile: | ||||
ncolspan = 3 | ||||
colspan = 2 | ||||
self.__nsubplots = 2 | ||||
|
r858 | |||
|
r487 | self.createFigure(id = id, | ||
wintitle = wintitle, | ||||
widthplot = self.WIDTH + self.WIDTHPROF, | ||||
heightplot = self.HEIGHT + self.HEIGHTPROF, | ||||
show=show) | ||||
|
r858 | |||
|
r487 | nrow, ncol = self.getSubplots() | ||
|
r858 | |||
|
r487 | counter = 0 | ||
for y in range(nrow): | ||||
for x in range(ncol): | ||||
|
r858 | |||
|
r487 | if counter >= self.nplots: | ||
break | ||||
|
r858 | |||
|
r487 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1) | ||
|
r858 | |||
|
r487 | if showprofile: | ||
self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1) | ||||
|
r858 | |||
|
r487 | counter += 1 | ||
|
r858 | |||
|
r487 | def run(self, dataOut, id, wintitle="", channelList=None, showprofile=True, | ||
xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None, | ||||
|
r568 | save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1, | ||
|
r487 | server=None, folder=None, username=None, password=None, | ||
|
r777 | ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0, realtime=False, | ||
|
r965 | xaxis="frequency", colormap='jet', normFactor=None): | ||
|
r858 | |||
|
r487 | """ | ||
|
r858 | |||
|
r487 | Input: | ||
dataOut : | ||||
id : | ||||
wintitle : | ||||
channelList : | ||||
showProfile : | ||||
xmin : None, | ||||
xmax : None, | ||||
ymin : None, | ||||
ymax : None, | ||||
zmin : None, | ||||
zmax : None | ||||
""" | ||||
if realtime: | ||||
if not(isRealtime(utcdatatime = dataOut.utctime)): | ||||
print 'Skipping this plot function' | ||||
return | ||||
|
r858 | |||
|
r487 | if channelList == None: | ||
channelIndexList = dataOut.channelIndexList | ||||
else: | ||||
channelIndexList = [] | ||||
for channel in channelList: | ||||
if channel not in dataOut.channelList: | ||||
|
r731 | raise ValueError, "Channel %d is not in dataOut.channelList" %channel | ||
|
r487 | channelIndexList.append(dataOut.channelList.index(channel)) | ||
|
r858 | |||
|
r965 | if normFactor is None: | ||
factor = dataOut.normFactor | ||||
else: | ||||
factor = normFactor | ||||
|
r777 | if xaxis == "frequency": | ||
x = dataOut.getFreqRange(1)/1000. | ||||
|
r825 | xlabel = "Frequency (kHz)" | ||
|
r858 | |||
|
r777 | elif xaxis == "time": | ||
x = dataOut.getAcfRange(1) | ||||
xlabel = "Time (ms)" | ||||
|
r858 | |||
|
r777 | else: | ||
x = dataOut.getVelRange(1) | ||||
xlabel = "Velocity (m/s)" | ||||
|
r858 | |||
|
r777 | ylabel = "Range (Km)" | ||
|
r858 | |||
|
r487 | y = dataOut.getHeiRange() | ||
|
r858 | |||
|
r731 | z = dataOut.data_spc/factor | ||
|
r858 | z = numpy.where(numpy.isfinite(z), z, numpy.NAN) | ||
|
r487 | zdB = 10*numpy.log10(z) | ||
|
r568 | |||
|
r583 | avg = numpy.average(z, axis=1) | ||
|
r487 | avgdB = 10*numpy.log10(avg) | ||
|
r858 | |||
|
r568 | noise = dataOut.getNoise()/factor | ||
|
r487 | noisedB = 10*numpy.log10(noise) | ||
|
r858 | |||
|
r568 | thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0]) | ||
|
r858 | title = wintitle + " Spectra" | ||
|
r499 | if ((dataOut.azimuth!=None) and (dataOut.zenith!=None)): | ||
title = title + '_' + 'azimuth,zenith=%2.2f,%2.2f'%(dataOut.azimuth, dataOut.zenith) | ||||
|
r858 | |||
|
r487 | if not self.isConfig: | ||
|
r858 | |||
|
r487 | nplots = len(channelIndexList) | ||
|
r858 | |||
|
r487 | self.setup(id=id, | ||
nplots=nplots, | ||||
wintitle=wintitle, | ||||
showprofile=showprofile, | ||||
show=show) | ||||
|
r858 | |||
|
r487 | 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) | ||||
|
r568 | if zmin == None: zmin = numpy.floor(numpy.nanmin(noisedB)) - 3 | ||
if zmax == None: zmax = numpy.ceil(numpy.nanmax(avgdB)) + 3 | ||||
|
r858 | |||
|
r487 | self.FTP_WEI = ftp_wei | ||
self.EXP_CODE = exp_code | ||||
self.SUB_EXP_CODE = sub_exp_code | ||||
self.PLOT_POS = plot_pos | ||||
|
r858 | |||
|
r487 | self.isConfig = True | ||
|
r858 | |||
|
r487 | self.setWinTitle(title) | ||
|
r858 | |||
|
r487 | for i in range(self.nplots): | ||
|
r731 | index = channelIndexList[i] | ||
|
r487 | str_datetime = '%s %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S")) | ||
|
r731 | title = "Channel %d: %4.2fdB: %s" %(dataOut.channelList[index], noisedB[index], str_datetime) | ||
|
r501 | if len(dataOut.beam.codeList) != 0: | ||
|
r731 | title = "Ch%d:%4.2fdB,%2.2f,%2.2f:%s" %(dataOut.channelList[index], noisedB[index], dataOut.beam.azimuthList[index], dataOut.beam.zenithList[index], str_datetime) | ||
|
r501 | |||
|
r487 | axes = self.axesList[i*self.__nsubplots] | ||
|
r731 | axes.pcolor(x, y, zdB[index,:,:], | ||
|
r487 | xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax, | ||
|
r858 | xlabel=xlabel, ylabel=ylabel, title=title, colormap=colormap, | ||
|
r487 | ticksize=9, cblabel='') | ||
|
r858 | |||
|
r487 | if self.__showprofile: | ||
axes = self.axesList[i*self.__nsubplots +1] | ||||
|
r731 | axes.pline(avgdB[index,:], y, | ||
|
r487 | xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax, | ||
xlabel='dB', ylabel='', title='', | ||||
ytick_visible=False, | ||||
grid='x') | ||||
|
r858 | |||
|
r731 | noiseline = numpy.repeat(noisedB[index], len(y)) | ||
|
r487 | axes.addpline(noiseline, y, idline=1, color="black", linestyle="dashed", lw=2) | ||
|
r858 | |||
|
r487 | self.draw() | ||
|
r858 | |||
|
r573 | if figfile == None: | ||
str_datetime = thisDatetime.strftime("%Y%m%d_%H%M%S") | ||||
name = str_datetime | ||||
if ((dataOut.azimuth!=None) and (dataOut.zenith!=None)): | ||||
|
r858 | name = name + '_az' + '_%2.2f'%(dataOut.azimuth) + '_zn' + '_%2.2f'%(dataOut.zenith) | ||
|
r573 | figfile = self.getFilename(name) | ||
|
r858 | |||
|
r573 | self.save(figpath=figpath, | ||
figfile=figfile, | ||||
save=save, | ||||
ftp=ftp, | ||||
wr_period=wr_period, | ||||
thisDatetime=thisDatetime) | ||||
|
r488 | |||
|
r487 | class CrossSpectraPlot(Figure): | ||
|
r858 | |||
|
r487 | isConfig = None | ||
__nsubplots = None | ||||
|
r858 | |||
|
r487 | WIDTH = None | ||
HEIGHT = None | ||||
WIDTHPROF = None | ||||
HEIGHTPROF = None | ||||
PREFIX = 'cspc' | ||||
|
r858 | |||
|
r897 | def __init__(self, **kwargs): | ||
Figure.__init__(self, **kwargs) | ||||
|
r487 | self.isConfig = False | ||
self.__nsubplots = 4 | ||||
self.counter_imagwr = 0 | ||||
self.WIDTH = 250 | ||||
self.HEIGHT = 250 | ||||
self.WIDTHPROF = 0 | ||||
self.HEIGHTPROF = 0 | ||||
|
r858 | |||
|
r573 | self.PLOT_CODE = CROSS_CODE | ||
|
r487 | self.FTP_WEI = None | ||
self.EXP_CODE = None | ||||
self.SUB_EXP_CODE = None | ||||
self.PLOT_POS = None | ||||
|
r858 | |||
|
r487 | def getSubplots(self): | ||
|
r858 | |||
|
r487 | ncol = 4 | ||
nrow = self.nplots | ||||
|
r858 | |||
|
r487 | return nrow, ncol | ||
|
r858 | |||
|
r487 | def setup(self, id, nplots, wintitle, showprofile=True, show=True): | ||
|
r858 | |||
|
r487 | self.__showprofile = showprofile | ||
self.nplots = nplots | ||||
|
r858 | |||
|
r487 | ncolspan = 1 | ||
colspan = 1 | ||||
|
r858 | |||
|
r487 | self.createFigure(id = id, | ||
wintitle = wintitle, | ||||
widthplot = self.WIDTH + self.WIDTHPROF, | ||||
heightplot = self.HEIGHT + self.HEIGHTPROF, | ||||
show=True) | ||||
|
r858 | |||
|
r487 | nrow, ncol = self.getSubplots() | ||
|
r858 | |||
|
r487 | counter = 0 | ||
for y in range(nrow): | ||||
|
r858 | for x in range(ncol): | ||
|
r487 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1) | ||
|
r858 | |||
|
r487 | counter += 1 | ||
|
r858 | |||
def run(self, dataOut, id, wintitle="", pairsList=None, | ||||
|
r487 | xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None, | ||
|
r600 | coh_min=None, coh_max=None, phase_min=None, phase_max=None, | ||
|
r568 | save=False, figpath='./', figfile=None, ftp=False, wr_period=1, | ||
|
r487 | power_cmap='jet', coherence_cmap='jet', phase_cmap='RdBu_r', show=True, | ||
server=None, folder=None, username=None, password=None, | ||||
|
r965 | ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0, normFactor=None, | ||
|
r825 | xaxis='frequency'): | ||
|
r858 | |||
|
r487 | """ | ||
|
r858 | |||
|
r487 | Input: | ||
dataOut : | ||||
id : | ||||
wintitle : | ||||
channelList : | ||||
showProfile : | ||||
xmin : None, | ||||
xmax : None, | ||||
ymin : None, | ||||
ymax : None, | ||||
zmin : None, | ||||
zmax : None | ||||
""" | ||||
|
r858 | |||
|
r487 | if pairsList == None: | ||
pairsIndexList = dataOut.pairsIndexList | ||||
else: | ||||
pairsIndexList = [] | ||||
for pair in pairsList: | ||||
if pair not in dataOut.pairsList: | ||||
|
r568 | raise ValueError, "Pair %s is not in dataOut.pairsList" %str(pair) | ||
|
r487 | pairsIndexList.append(dataOut.pairsList.index(pair)) | ||
|
r858 | |||
|
r587 | if not pairsIndexList: | ||
|
r487 | return | ||
|
r858 | |||
|
r487 | if len(pairsIndexList) > 4: | ||
pairsIndexList = pairsIndexList[0:4] | ||||
|
r965 | |||
if normFactor is None: | ||||
factor = dataOut.normFactor | ||||
else: | ||||
factor = normFactor | ||||
|
r487 | x = dataOut.getVelRange(1) | ||
y = dataOut.getHeiRange() | ||||
z = dataOut.data_spc[:,:,:]/factor | ||||
|
r568 | z = numpy.where(numpy.isfinite(z), z, numpy.NAN) | ||
|
r858 | |||
|
r525 | noise = dataOut.noise/factor | ||
|
r858 | |||
|
r487 | zdB = 10*numpy.log10(z) | ||
noisedB = 10*numpy.log10(noise) | ||||
|
r858 | |||
|
r600 | if coh_min == None: | ||
coh_min = 0.0 | ||||
if coh_max == None: | ||||
coh_max = 1.0 | ||||
|
r858 | |||
|
r600 | if phase_min == None: | ||
phase_min = -180 | ||||
if phase_max == None: | ||||
phase_max = 180 | ||||
|
r858 | |||
|
r487 | #thisDatetime = dataOut.datatime | ||
|
r568 | thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0]) | ||
|
r487 | title = wintitle + " Cross-Spectra: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) | ||
|
r825 | # xlabel = "Velocity (m/s)" | ||
|
r487 | ylabel = "Range (Km)" | ||
|
r858 | |||
|
r825 | if xaxis == "frequency": | ||
x = dataOut.getFreqRange(1)/1000. | ||||
xlabel = "Frequency (kHz)" | ||||
|
r858 | |||
|
r825 | elif xaxis == "time": | ||
x = dataOut.getAcfRange(1) | ||||
xlabel = "Time (ms)" | ||||
|
r858 | |||
|
r825 | else: | ||
x = dataOut.getVelRange(1) | ||||
xlabel = "Velocity (m/s)" | ||||
|
r858 | |||
|
r487 | if not self.isConfig: | ||
|
r858 | |||
|
r487 | nplots = len(pairsIndexList) | ||
|
r858 | |||
|
r487 | self.setup(id=id, | ||
nplots=nplots, | ||||
wintitle=wintitle, | ||||
showprofile=False, | ||||
show=show) | ||||
|
r858 | |||
|
r568 | avg = numpy.abs(numpy.average(z, axis=1)) | ||
avgdB = 10*numpy.log10(avg) | ||||
|
r858 | |||
|
r487 | 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) | ||||
|
r568 | if zmin == None: zmin = numpy.floor(numpy.nanmin(noisedB)) - 3 | ||
if zmax == None: zmax = numpy.ceil(numpy.nanmax(avgdB)) + 3 | ||||
|
r858 | |||
|
r487 | self.FTP_WEI = ftp_wei | ||
self.EXP_CODE = exp_code | ||||
self.SUB_EXP_CODE = sub_exp_code | ||||
self.PLOT_POS = plot_pos | ||||
|
r858 | |||
|
r487 | self.isConfig = True | ||
|
r858 | |||
|
r487 | self.setWinTitle(title) | ||
|
r858 | |||
|
r487 | for i in range(self.nplots): | ||
pair = dataOut.pairsList[pairsIndexList[i]] | ||||
|
r858 | |||
|
r766 | chan_index0 = dataOut.channelList.index(pair[0]) | ||
chan_index1 = dataOut.channelList.index(pair[1]) | ||||
|
r858 | |||
|
r487 | str_datetime = '%s %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S")) | ||
|
r766 | title = "Ch%d: %4.2fdB: %s" %(pair[0], noisedB[chan_index0], str_datetime) | ||
zdB = 10.*numpy.log10(dataOut.data_spc[chan_index0,:,:]/factor) | ||||
|
r487 | axes0 = self.axesList[i*self.__nsubplots] | ||
axes0.pcolor(x, y, zdB, | ||||
xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax, | ||||
xlabel=xlabel, ylabel=ylabel, title=title, | ||||
ticksize=9, colormap=power_cmap, cblabel='') | ||||
|
r858 | |||
|
r766 | title = "Ch%d: %4.2fdB: %s" %(pair[1], noisedB[chan_index1], str_datetime) | ||
zdB = 10.*numpy.log10(dataOut.data_spc[chan_index1,:,:]/factor) | ||||
|
r487 | axes0 = self.axesList[i*self.__nsubplots+1] | ||
axes0.pcolor(x, y, zdB, | ||||
xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax, | ||||
xlabel=xlabel, ylabel=ylabel, title=title, | ||||
ticksize=9, colormap=power_cmap, cblabel='') | ||||
|
r766 | coherenceComplex = dataOut.data_cspc[pairsIndexList[i],:,:]/numpy.sqrt(dataOut.data_spc[chan_index0,:,:]*dataOut.data_spc[chan_index1,:,:]) | ||
|
r487 | coherence = numpy.abs(coherenceComplex) | ||
# phase = numpy.arctan(-1*coherenceComplex.imag/coherenceComplex.real)*180/numpy.pi | ||||
phase = numpy.arctan2(coherenceComplex.imag, coherenceComplex.real)*180/numpy.pi | ||||
|
r858 | |||
|
r760 | title = "Coherence Ch%d * Ch%d" %(pair[0], pair[1]) | ||
|
r487 | axes0 = self.axesList[i*self.__nsubplots+2] | ||
axes0.pcolor(x, y, coherence, | ||||
|
r600 | xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=coh_min, zmax=coh_max, | ||
|
r487 | xlabel=xlabel, ylabel=ylabel, title=title, | ||
ticksize=9, colormap=coherence_cmap, cblabel='') | ||||
|
r858 | |||
|
r760 | title = "Phase Ch%d * Ch%d" %(pair[0], pair[1]) | ||
|
r487 | axes0 = self.axesList[i*self.__nsubplots+3] | ||
axes0.pcolor(x, y, phase, | ||||
|
r600 | xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=phase_min, zmax=phase_max, | ||
|
r487 | xlabel=xlabel, ylabel=ylabel, title=title, | ||
ticksize=9, colormap=phase_cmap, cblabel='') | ||||
|
r858 | |||
|
r487 | self.draw() | ||
|
r858 | |||
|
r573 | self.save(figpath=figpath, | ||
figfile=figfile, | ||||
save=save, | ||||
ftp=ftp, | ||||
wr_period=wr_period, | ||||
|
r858 | thisDatetime=thisDatetime) | ||
|
r487 | |||
|
r494 | |||
|
r487 | class RTIPlot(Figure): | ||
|
r858 | |||
|
r509 | __isConfig = None | ||
|
r487 | __nsubplots = None | ||
|
r858 | |||
|
r487 | WIDTHPROF = None | ||
HEIGHTPROF = None | ||||
PREFIX = 'rti' | ||||
|
r858 | |||
|
r897 | def __init__(self, **kwargs): | ||
|
r858 | |||
|
r897 | Figure.__init__(self, **kwargs) | ||
|
r577 | self.timerange = None | ||
|
r760 | self.isConfig = False | ||
|
r487 | self.__nsubplots = 1 | ||
|
r858 | |||
|
r487 | self.WIDTH = 800 | ||
|
r731 | self.HEIGHT = 180 | ||
|
r487 | self.WIDTHPROF = 120 | ||
self.HEIGHTPROF = 0 | ||||
self.counter_imagwr = 0 | ||||
|
r858 | |||
|
r573 | self.PLOT_CODE = RTI_CODE | ||
|
r858 | |||
|
r487 | self.FTP_WEI = None | ||
self.EXP_CODE = None | ||||
self.SUB_EXP_CODE = None | ||||
self.PLOT_POS = None | ||||
|
r858 | self.tmin = None | ||
|
r487 | self.tmax = None | ||
|
r858 | |||
|
r487 | self.xmin = None | ||
self.xmax = None | ||||
|
r858 | |||
|
r490 | self.figfile = None | ||
|
r858 | |||
|
r487 | def getSubplots(self): | ||
|
r858 | |||
|
r487 | ncol = 1 | ||
nrow = self.nplots | ||||
|
r858 | |||
|
r487 | return nrow, ncol | ||
|
r858 | |||
|
r487 | def setup(self, id, nplots, wintitle, showprofile=True, show=True): | ||
|
r858 | |||
|
r487 | self.__showprofile = showprofile | ||
self.nplots = nplots | ||||
|
r858 | |||
|
r487 | ncolspan = 1 | ||
colspan = 1 | ||||
if showprofile: | ||||
ncolspan = 7 | ||||
colspan = 6 | ||||
self.__nsubplots = 2 | ||||
|
r858 | |||
|
r487 | self.createFigure(id = id, | ||
wintitle = wintitle, | ||||
widthplot = self.WIDTH + self.WIDTHPROF, | ||||
heightplot = self.HEIGHT + self.HEIGHTPROF, | ||||
show=show) | ||||
|
r858 | |||
|
r487 | nrow, ncol = self.getSubplots() | ||
|
r858 | |||
|
r487 | counter = 0 | ||
for y in range(nrow): | ||||
for x in range(ncol): | ||||
|
r858 | |||
|
r487 | if counter >= self.nplots: | ||
break | ||||
|
r858 | |||
|
r487 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1) | ||
|
r858 | |||
|
r487 | if showprofile: | ||
self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1) | ||||
|
r858 | |||
|
r487 | counter += 1 | ||
|
r858 | |||
|
r487 | def run(self, dataOut, id, wintitle="", channelList=None, showprofile='True', | ||
xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None, | ||||
|
r965 | timerange=None, colormap='jet', | ||
|
r568 | save=False, figpath='./', lastone=0,figfile=None, ftp=False, wr_period=1, show=True, | ||
|
r487 | server=None, folder=None, username=None, password=None, | ||
|
r1001 | ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0, normFactor=None, HEIGHT=None): | ||
|
r858 | |||
|
r487 | """ | ||
|
r858 | |||
|
r487 | Input: | ||
dataOut : | ||||
id : | ||||
wintitle : | ||||
channelList : | ||||
showProfile : | ||||
xmin : None, | ||||
xmax : None, | ||||
ymin : None, | ||||
ymax : None, | ||||
zmin : None, | ||||
zmax : None | ||||
""" | ||||
|
r858 | |||
|
r1001 | #colormap = kwargs.get('colormap', 'jet') | ||
if HEIGHT is not None: | ||||
self.HEIGHT = HEIGHT | ||||
|
r760 | if not isTimeInHourRange(dataOut.datatime, xmin, xmax): | ||
return | ||||
|
r858 | |||
|
r487 | 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)) | ||||
|
r858 | |||
|
r965 | if normFactor is None: | ||
|
r832 | factor = dataOut.normFactor | ||
else: | ||||
|
r965 | factor = normFactor | ||
|
r858 | |||
|
r832 | # factor = dataOut.normFactor | ||
|
r487 | x = dataOut.getTimeRange() | ||
y = dataOut.getHeiRange() | ||||
|
r858 | |||
|
r965 | z = dataOut.data_spc/factor | ||
z = numpy.where(numpy.isfinite(z), z, numpy.NAN) | ||||
avg = numpy.average(z, axis=1) | ||||
avgdB = 10.*numpy.log10(avg) | ||||
# avgdB = dataOut.getPower() | ||||
|
r858 | |||
|
r760 | thisDatetime = dataOut.datatime | ||
# thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0]) | ||||
|
r487 | title = wintitle + " RTI" #: %s" %(thisDatetime.strftime("%d-%b-%Y")) | ||
xlabel = "" | ||||
ylabel = "Range (Km)" | ||||
|
r858 | |||
|
r760 | update_figfile = False | ||
|
r858 | |||
|
r816 | if dataOut.ltctime >= self.xmax: | ||
self.counter_imagwr = wr_period | ||||
self.isConfig = False | ||||
update_figfile = True | ||||
|
r858 | |||
|
r760 | if not self.isConfig: | ||
|
r858 | |||
|
r487 | nplots = len(channelIndexList) | ||
|
r858 | |||
|
r487 | self.setup(id=id, | ||
nplots=nplots, | ||||
wintitle=wintitle, | ||||
showprofile=showprofile, | ||||
show=show) | ||||
|
r858 | |||
|
r568 | if timerange != None: | ||
self.timerange = timerange | ||||
|
r858 | |||
|
r568 | self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange) | ||
|
r858 | |||
|
r568 | noise = dataOut.noise/factor | ||
noisedB = 10*numpy.log10(noise) | ||||
|
r858 | |||
|
r487 | if ymin == None: ymin = numpy.nanmin(y) | ||
if ymax == None: ymax = numpy.nanmax(y) | ||||
|
r568 | if zmin == None: zmin = numpy.floor(numpy.nanmin(noisedB)) - 3 | ||
if zmax == None: zmax = numpy.ceil(numpy.nanmax(avgdB)) + 3 | ||||
|
r858 | |||
|
r487 | self.FTP_WEI = ftp_wei | ||
self.EXP_CODE = exp_code | ||||
self.SUB_EXP_CODE = sub_exp_code | ||||
self.PLOT_POS = plot_pos | ||||
|
r858 | |||
|
r487 | self.name = thisDatetime.strftime("%Y%m%d_%H%M%S") | ||
|
r760 | self.isConfig = True | ||
|
r490 | self.figfile = figfile | ||
|
r760 | update_figfile = True | ||
|
r858 | |||
|
r487 | self.setWinTitle(title) | ||
|
r858 | |||
|
r487 | for i in range(self.nplots): | ||
|
r731 | index = channelIndexList[i] | ||
title = "Channel %d: %s" %(dataOut.channelList[index], thisDatetime.strftime("%Y/%m/%d %H:%M:%S")) | ||||
|
r499 | if ((dataOut.azimuth!=None) and (dataOut.zenith!=None)): | ||
title = title + '_' + 'azimuth,zenith=%2.2f,%2.2f'%(dataOut.azimuth, dataOut.zenith) | ||||
|
r487 | axes = self.axesList[i*self.__nsubplots] | ||
|
r731 | zdB = avgdB[index].reshape((1,-1)) | ||
|
r487 | axes.pcolorbuffer(x, y, zdB, | ||
xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax, | ||||
xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True, | ||||
|
r858 | ticksize=9, cblabel='', cbsize="1%", colormap=colormap) | ||
|
r487 | if self.__showprofile: | ||
axes = self.axesList[i*self.__nsubplots +1] | ||||
|
r731 | axes.pline(avgdB[index], y, | ||
|
r487 | xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax, | ||
xlabel='dB', ylabel='', title='', | ||||
ytick_visible=False, | ||||
grid='x') | ||||
|
r858 | |||
|
r760 | self.draw() | ||
|
r858 | |||
|
r573 | self.save(figpath=figpath, | ||
figfile=figfile, | ||||
save=save, | ||||
ftp=ftp, | ||||
wr_period=wr_period, | ||||
thisDatetime=thisDatetime, | ||||
|
r760 | update_figfile=update_figfile) | ||
|
r487 | |||
class CoherenceMap(Figure): | ||||
isConfig = None | ||||
__nsubplots = None | ||||
|
r858 | |||
|
r487 | WIDTHPROF = None | ||
HEIGHTPROF = None | ||||
PREFIX = 'cmap' | ||||
|
r897 | def __init__(self, **kwargs): | ||
Figure.__init__(self, **kwargs) | ||||
|
r487 | self.timerange = 2*60*60 | ||
self.isConfig = False | ||||
self.__nsubplots = 1 | ||||
|
r858 | |||
|
r487 | self.WIDTH = 800 | ||
|
r731 | self.HEIGHT = 180 | ||
|
r487 | self.WIDTHPROF = 120 | ||
self.HEIGHTPROF = 0 | ||||
self.counter_imagwr = 0 | ||||
|
r858 | |||
|
r573 | self.PLOT_CODE = COH_CODE | ||
|
r858 | |||
|
r487 | self.FTP_WEI = None | ||
self.EXP_CODE = None | ||||
self.SUB_EXP_CODE = None | ||||
self.PLOT_POS = None | ||||
self.counter_imagwr = 0 | ||||
|
r858 | |||
|
r487 | self.xmin = None | ||
self.xmax = None | ||||
|
r858 | |||
|
r487 | def getSubplots(self): | ||
ncol = 1 | ||||
nrow = self.nplots*2 | ||||
|
r858 | |||
|
r487 | return nrow, ncol | ||
|
r858 | |||
|
r487 | def setup(self, id, nplots, wintitle, showprofile=True, show=True): | ||
self.__showprofile = showprofile | ||||
self.nplots = nplots | ||||
|
r858 | |||
|
r487 | ncolspan = 1 | ||
colspan = 1 | ||||
if showprofile: | ||||
ncolspan = 7 | ||||
colspan = 6 | ||||
self.__nsubplots = 2 | ||||
|
r858 | |||
|
r487 | self.createFigure(id = id, | ||
wintitle = wintitle, | ||||
widthplot = self.WIDTH + self.WIDTHPROF, | ||||
heightplot = self.HEIGHT + self.HEIGHTPROF, | ||||
show=True) | ||||
|
r858 | |||
|
r487 | nrow, ncol = self.getSubplots() | ||
|
r858 | |||
|
r487 | for y in range(nrow): | ||
for x in range(ncol): | ||||
|
r858 | |||
|
r487 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1) | ||
|
r858 | |||
|
r487 | if showprofile: | ||
self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1) | ||||
|
r858 | |||
|
r487 | def run(self, dataOut, id, wintitle="", pairsList=None, showprofile='True', | ||
xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None, | ||||
|
r731 | timerange=None, phase_min=None, phase_max=None, | ||
|
r568 | save=False, figpath='./', figfile=None, ftp=False, wr_period=1, | ||
|
r487 | 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): | ||||
|
r858 | |||
|
r760 | if not isTimeInHourRange(dataOut.datatime, xmin, xmax): | ||
return | ||||
|
r858 | |||
|
r487 | if pairsList == None: | ||
pairsIndexList = dataOut.pairsIndexList | ||||
else: | ||||
pairsIndexList = [] | ||||
for pair in pairsList: | ||||
if pair not in dataOut.pairsList: | ||||
raise ValueError, "Pair %s is not in dataOut.pairsList" %(pair) | ||||
pairsIndexList.append(dataOut.pairsList.index(pair)) | ||||
|
r858 | |||
|
r487 | if pairsIndexList == []: | ||
return | ||||
|
r858 | |||
|
r487 | if len(pairsIndexList) > 4: | ||
pairsIndexList = pairsIndexList[0:4] | ||||
|
r858 | |||
|
r731 | if phase_min == None: | ||
phase_min = -180 | ||||
if phase_max == None: | ||||
phase_max = 180 | ||||
|
r858 | |||
|
r487 | x = dataOut.getTimeRange() | ||
y = dataOut.getHeiRange() | ||||
|
r858 | |||
|
r760 | thisDatetime = dataOut.datatime | ||
|
r858 | |||
|
r487 | title = wintitle + " CoherenceMap" #: %s" %(thisDatetime.strftime("%d-%b-%Y")) | ||
xlabel = "" | ||||
ylabel = "Range (Km)" | ||||
|
r760 | update_figfile = False | ||
|
r858 | |||
if not self.isConfig: | ||||
|
r487 | nplots = len(pairsIndexList) | ||
self.setup(id=id, | ||||
nplots=nplots, | ||||
wintitle=wintitle, | ||||
showprofile=showprofile, | ||||
show=show) | ||||
|
r858 | |||
|
r568 | if timerange != None: | ||
self.timerange = timerange | ||||
|
r858 | |||
|
r567 | self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange) | ||
|
r858 | |||
|
r487 | if ymin == None: ymin = numpy.nanmin(y) | ||
if ymax == None: ymax = numpy.nanmax(y) | ||||
if zmin == None: zmin = 0. | ||||
if zmax == None: zmax = 1. | ||||
|
r858 | |||
|
r487 | self.FTP_WEI = ftp_wei | ||
self.EXP_CODE = exp_code | ||||
self.SUB_EXP_CODE = sub_exp_code | ||||
self.PLOT_POS = plot_pos | ||||
|
r858 | |||
|
r487 | self.name = thisDatetime.strftime("%Y%m%d_%H%M%S") | ||
|
r858 | |||
|
r487 | self.isConfig = True | ||
|
r760 | update_figfile = True | ||
|
r858 | |||
|
r487 | self.setWinTitle(title) | ||
|
r858 | |||
|
r487 | for i in range(self.nplots): | ||
|
r858 | |||
|
r487 | pair = dataOut.pairsList[pairsIndexList[i]] | ||
|
r858 | |||
|
r487 | ccf = numpy.average(dataOut.data_cspc[pairsIndexList[i],:,:],axis=0) | ||
powa = numpy.average(dataOut.data_spc[pair[0],:,:],axis=0) | ||||
powb = numpy.average(dataOut.data_spc[pair[1],:,:],axis=0) | ||||
|
r858 | |||
|
r487 | avgcoherenceComplex = ccf/numpy.sqrt(powa*powb) | ||
coherence = numpy.abs(avgcoherenceComplex) | ||||
|
r858 | |||
|
r487 | z = coherence.reshape((1,-1)) | ||
counter = 0 | ||||
|
r858 | |||
|
r760 | title = "Coherence Ch%d * Ch%d: %s" %(pair[0], pair[1], thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) | ||
|
r487 | axes = self.axesList[i*self.__nsubplots*2] | ||
axes.pcolorbuffer(x, y, z, | ||||
xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax, | ||||
xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True, | ||||
ticksize=9, cblabel='', colormap=coherence_cmap, cbsize="1%") | ||||
|
r858 | |||
|
r487 | if self.__showprofile: | ||
counter += 1 | ||||
axes = self.axesList[i*self.__nsubplots*2 + counter] | ||||
axes.pline(coherence, y, | ||||
xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax, | ||||
xlabel='', ylabel='', title='', ticksize=7, | ||||
ytick_visible=False, nxticks=5, | ||||
grid='x') | ||||
|
r858 | |||
|
r487 | counter += 1 | ||
|
r488 | |||
|
r487 | phase = numpy.arctan2(avgcoherenceComplex.imag, avgcoherenceComplex.real)*180/numpy.pi | ||
|
r488 | |||
|
r487 | z = phase.reshape((1,-1)) | ||
|
r858 | |||
|
r760 | title = "Phase Ch%d * Ch%d: %s" %(pair[0], pair[1], thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) | ||
|
r487 | axes = self.axesList[i*self.__nsubplots*2 + counter] | ||
axes.pcolorbuffer(x, y, z, | ||||
|
r731 | xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=phase_min, zmax=phase_max, | ||
|
r487 | xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True, | ||
ticksize=9, cblabel='', colormap=phase_cmap, cbsize="1%") | ||||
|
r858 | |||
|
r487 | if self.__showprofile: | ||
counter += 1 | ||||
axes = self.axesList[i*self.__nsubplots*2 + counter] | ||||
axes.pline(phase, y, | ||||
|
r731 | xmin=phase_min, xmax=phase_max, ymin=ymin, ymax=ymax, | ||
|
r487 | xlabel='', ylabel='', title='', ticksize=7, | ||
ytick_visible=False, nxticks=4, | ||||
grid='x') | ||||
|
r858 | |||
|
r487 | self.draw() | ||
|
r858 | |||
|
r760 | if dataOut.ltctime >= self.xmax: | ||
|
r488 | self.counter_imagwr = wr_period | ||
|
r760 | self.isConfig = False | ||
update_figfile = True | ||||
|
r858 | |||
|
r573 | self.save(figpath=figpath, | ||
figfile=figfile, | ||||
save=save, | ||||
ftp=ftp, | ||||
wr_period=wr_period, | ||||
thisDatetime=thisDatetime, | ||||
|
r760 | update_figfile=update_figfile) | ||
|
r487 | |||
|
r577 | class PowerProfilePlot(Figure): | ||
|
r858 | |||
|
r487 | isConfig = None | ||
__nsubplots = None | ||||
|
r858 | |||
|
r487 | WIDTHPROF = None | ||
HEIGHTPROF = None | ||||
PREFIX = 'spcprofile' | ||||
|
r858 | |||
|
r897 | def __init__(self, **kwargs): | ||
Figure.__init__(self, **kwargs) | ||||
|
r487 | self.isConfig = False | ||
self.__nsubplots = 1 | ||||
|
r858 | |||
|
r573 | self.PLOT_CODE = POWER_CODE | ||
|
r858 | |||
|
r487 | self.WIDTH = 300 | ||
self.HEIGHT = 500 | ||||
self.counter_imagwr = 0 | ||||
|
r858 | |||
|
r487 | def getSubplots(self): | ||
ncol = 1 | ||||
nrow = 1 | ||||
|
r858 | |||
|
r487 | return nrow, ncol | ||
|
r858 | |||
|
r487 | def setup(self, id, nplots, wintitle, show): | ||
|
r858 | |||
|
r487 | self.nplots = nplots | ||
|
r858 | |||
|
r487 | ncolspan = 1 | ||
colspan = 1 | ||||
|
r858 | |||
|
r487 | self.createFigure(id = id, | ||
wintitle = wintitle, | ||||
widthplot = self.WIDTH, | ||||
heightplot = self.HEIGHT, | ||||
show=show) | ||||
|
r858 | |||
|
r487 | nrow, ncol = self.getSubplots() | ||
|
r858 | |||
|
r487 | counter = 0 | ||
for y in range(nrow): | ||||
|
r858 | for x in range(ncol): | ||
|
r487 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1) | ||
|
r858 | |||
|
r487 | def run(self, dataOut, id, wintitle="", channelList=None, | ||
xmin=None, xmax=None, ymin=None, ymax=None, | ||||
|
r568 | save=False, figpath='./', figfile=None, show=True, | ||
ftp=False, wr_period=1, server=None, | ||||
folder=None, username=None, password=None): | ||||
|
r858 | |||
|
r487 | 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)) | ||||
|
r858 | |||
|
r568 | factor = dataOut.normFactor | ||
|
r858 | |||
|
r487 | y = dataOut.getHeiRange() | ||
|
r858 | |||
|
r487 | #for voltage | ||
if dataOut.type == 'Voltage': | ||||
x = dataOut.data[channelIndexList,:] * numpy.conjugate(dataOut.data[channelIndexList,:]) | ||||
x = x.real | ||||
x = numpy.where(numpy.isfinite(x), x, numpy.NAN) | ||||
|
r858 | |||
|
r487 | #for spectra | ||
if dataOut.type == 'Spectra': | ||||
x = dataOut.data_spc[channelIndexList,:,:]/factor | ||||
|
r858 | x = numpy.where(numpy.isfinite(x), x, numpy.NAN) | ||
|
r487 | x = numpy.average(x, axis=1) | ||
|
r858 | |||
|
r487 | xdB = 10*numpy.log10(x) | ||
|
r858 | |||
|
r568 | thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0]) | ||
|
r487 | title = wintitle + " Power Profile %s" %(thisDatetime.strftime("%d-%b-%Y")) | ||
xlabel = "dB" | ||||
ylabel = "Range (Km)" | ||||
|
r858 | |||
|
r487 | if not self.isConfig: | ||
|
r858 | |||
|
r487 | nplots = 1 | ||
|
r858 | |||
|
r487 | self.setup(id=id, | ||
nplots=nplots, | ||||
wintitle=wintitle, | ||||
show=show) | ||||
|
r858 | |||
|
r487 | if ymin == None: ymin = numpy.nanmin(y) | ||
if ymax == None: ymax = numpy.nanmax(y) | ||||
if xmin == None: xmin = numpy.nanmin(xdB)*0.9 | ||||
|
r568 | if xmax == None: xmax = numpy.nanmax(xdB)*1.1 | ||
|
r858 | |||
|
r760 | self.isConfig = True | ||
|
r858 | |||
|
r487 | self.setWinTitle(title) | ||
|
r858 | |||
|
r487 | title = "Power Profile: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) | ||
axes = self.axesList[0] | ||||
|
r858 | |||
|
r487 | legendlabels = ["channel %d"%x for x in channelList] | ||
axes.pmultiline(xdB, y, | ||||
xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, | ||||
xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels, | ||||
ytick_visible=True, nxticks=5, | ||||
grid='x') | ||||
|
r858 | |||
|
r487 | self.draw() | ||
|
r858 | |||
|
r573 | self.save(figpath=figpath, | ||
figfile=figfile, | ||||
save=save, | ||||
ftp=ftp, | ||||
wr_period=wr_period, | ||||
thisDatetime=thisDatetime) | ||||
|
r487 | |||
|
r766 | class SpectraCutPlot(Figure): | ||
|
r858 | |||
|
r766 | isConfig = None | ||
__nsubplots = None | ||||
|
r858 | |||
|
r766 | WIDTHPROF = None | ||
HEIGHTPROF = None | ||||
PREFIX = 'spc_cut' | ||||
|
r858 | |||
|
r897 | def __init__(self, **kwargs): | ||
Figure.__init__(self, **kwargs) | ||||
|
r766 | self.isConfig = False | ||
self.__nsubplots = 1 | ||||
|
r858 | |||
|
r766 | self.PLOT_CODE = POWER_CODE | ||
|
r858 | |||
|
r766 | self.WIDTH = 700 | ||
self.HEIGHT = 500 | ||||
self.counter_imagwr = 0 | ||||
|
r858 | |||
|
r766 | def getSubplots(self): | ||
ncol = 1 | ||||
nrow = 1 | ||||
|
r858 | |||
|
r766 | return nrow, ncol | ||
|
r858 | |||
|
r766 | def setup(self, id, nplots, wintitle, show): | ||
|
r858 | |||
|
r766 | self.nplots = nplots | ||
|
r858 | |||
|
r766 | ncolspan = 1 | ||
colspan = 1 | ||||
|
r858 | |||
|
r766 | self.createFigure(id = id, | ||
wintitle = wintitle, | ||||
widthplot = self.WIDTH, | ||||
heightplot = self.HEIGHT, | ||||
show=show) | ||||
|
r858 | |||
|
r766 | nrow, ncol = self.getSubplots() | ||
|
r858 | |||
|
r766 | counter = 0 | ||
for y in range(nrow): | ||||
|
r858 | for x in range(ncol): | ||
|
r766 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1) | ||
|
r858 | |||
|
r766 | def run(self, dataOut, id, wintitle="", channelList=None, | ||
xmin=None, xmax=None, ymin=None, ymax=None, | ||||
save=False, figpath='./', figfile=None, show=True, | ||||
ftp=False, wr_period=1, server=None, | ||||
|
r777 | folder=None, username=None, password=None, | ||
|
r825 | xaxis="frequency"): | ||
|
r858 | |||
|
r766 | 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)) | ||||
|
r858 | |||
|
r766 | factor = dataOut.normFactor | ||
|
r858 | |||
|
r766 | y = dataOut.getHeiRange() | ||
|
r858 | |||
|
r766 | z = dataOut.data_spc/factor | ||
|
r858 | z = numpy.where(numpy.isfinite(z), z, numpy.NAN) | ||
|
r788 | hei_index = numpy.arange(25)*3 + 20 | ||
|
r858 | |||
|
r777 | if xaxis == "frequency": | ||
x = dataOut.getFreqRange()/1000. | ||||
zdB = 10*numpy.log10(z[0,:,hei_index]) | ||||
|
r788 | xlabel = "Frequency (kHz)" | ||
|
r777 | ylabel = "Power (dB)" | ||
|
r858 | |||
|
r777 | elif xaxis == "time": | ||
x = dataOut.getAcfRange() | ||||
zdB = z[0,:,hei_index] | ||||
xlabel = "Time (ms)" | ||||
ylabel = "ACF" | ||||
|
r858 | |||
|
r777 | else: | ||
x = dataOut.getVelRange() | ||||
zdB = 10*numpy.log10(z[0,:,hei_index]) | ||||
xlabel = "Velocity (m/s)" | ||||
ylabel = "Power (dB)" | ||||
|
r858 | |||
|
r766 | thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0]) | ||
|
r777 | title = wintitle + " Range Cuts %s" %(thisDatetime.strftime("%d-%b-%Y")) | ||
|
r858 | |||
|
r766 | if not self.isConfig: | ||
|
r858 | |||
|
r766 | nplots = 1 | ||
|
r858 | |||
|
r766 | self.setup(id=id, | ||
nplots=nplots, | ||||
wintitle=wintitle, | ||||
show=show) | ||||
|
r858 | |||
|
r766 | if xmin == None: xmin = numpy.nanmin(x)*0.9 | ||
if xmax == None: xmax = numpy.nanmax(x)*1.1 | ||||
if ymin == None: ymin = numpy.nanmin(zdB) | ||||
if ymax == None: ymax = numpy.nanmax(zdB) | ||||
|
r858 | |||
|
r766 | self.isConfig = True | ||
|
r858 | |||
|
r766 | self.setWinTitle(title) | ||
|
r858 | |||
|
r766 | title = "Spectra Cuts: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) | ||
axes = self.axesList[0] | ||||
|
r858 | |||
|
r766 | legendlabels = ["Range = %dKm" %y[i] for i in hei_index] | ||
|
r858 | |||
|
r766 | axes.pmultilineyaxis( x, zdB, | ||
xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, | ||||
xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels, | ||||
ytick_visible=True, nxticks=5, | ||||
grid='x') | ||||
|
r858 | |||
|
r766 | self.draw() | ||
|
r858 | |||
|
r766 | self.save(figpath=figpath, | ||
figfile=figfile, | ||||
save=save, | ||||
ftp=ftp, | ||||
wr_period=wr_period, | ||||
thisDatetime=thisDatetime) | ||||
|
r858 | |||
|
r487 | class Noise(Figure): | ||
|
r858 | |||
|
r487 | isConfig = None | ||
__nsubplots = None | ||||
PREFIX = 'noise' | ||||
|
r858 | |||
|
r965 | |||
|
r897 | def __init__(self, **kwargs): | ||
Figure.__init__(self, **kwargs) | ||||
|
r487 | self.timerange = 24*60*60 | ||
self.isConfig = False | ||||
self.__nsubplots = 1 | ||||
self.counter_imagwr = 0 | ||||
|
r760 | self.WIDTH = 800 | ||
self.HEIGHT = 400 | ||||
|
r487 | self.WIDTHPROF = 120 | ||
self.HEIGHTPROF = 0 | ||||
self.xdata = None | ||||
self.ydata = None | ||||
|
r858 | |||
|
r573 | self.PLOT_CODE = NOISE_CODE | ||
|
r858 | |||
|
r487 | self.FTP_WEI = None | ||
self.EXP_CODE = None | ||||
self.SUB_EXP_CODE = None | ||||
self.PLOT_POS = None | ||||
|
r494 | self.figfile = None | ||
|
r858 | |||
|
r568 | self.xmin = None | ||
self.xmax = None | ||||
|
r858 | |||
|
r487 | def getSubplots(self): | ||
|
r858 | |||
|
r487 | ncol = 1 | ||
nrow = 1 | ||||
|
r858 | |||
|
r487 | return nrow, ncol | ||
|
r858 | |||
|
r487 | def openfile(self, filename): | ||
|
r577 | dirname = os.path.dirname(filename) | ||
|
r858 | |||
|
r577 | if not os.path.exists(dirname): | ||
os.mkdir(dirname) | ||||
|
r858 | |||
f = open(filename,'w+') | ||||
|
r487 | f.write('\n\n') | ||
f.write('JICAMARCA RADIO OBSERVATORY - Noise \n') | ||||
|
r858 | f.write('DD MM YYYY HH MM SS Channel0 Channel1 Channel2 Channel3\n\n' ) | ||
|
r487 | f.close() | ||
def save_data(self, filename_phase, data, data_datetime): | ||||
|
r858 | |||
|
r487 | f=open(filename_phase,'a') | ||
|
r858 | |||
|
r487 | timetuple_data = data_datetime.timetuple() | ||
day = str(timetuple_data.tm_mday) | ||||
month = str(timetuple_data.tm_mon) | ||||
year = str(timetuple_data.tm_year) | ||||
hour = str(timetuple_data.tm_hour) | ||||
minute = str(timetuple_data.tm_min) | ||||
second = str(timetuple_data.tm_sec) | ||||
|
r858 | |||
|
r577 | data_msg = '' | ||
for i in range(len(data)): | ||||
data_msg += str(data[i]) + ' ' | ||||
|
r858 | |||
|
r577 | f.write(day+' '+month+' '+year+' '+hour+' '+minute+' '+second+' ' + data_msg + '\n') | ||
|
r487 | f.close() | ||
|
r858 | |||
|
r487 | def setup(self, id, nplots, wintitle, showprofile=True, show=True): | ||
|
r858 | |||
|
r487 | self.__showprofile = showprofile | ||
self.nplots = nplots | ||||
|
r858 | |||
|
r487 | ncolspan = 7 | ||
colspan = 6 | ||||
self.__nsubplots = 2 | ||||
|
r858 | |||
|
r487 | self.createFigure(id = id, | ||
wintitle = wintitle, | ||||
widthplot = self.WIDTH+self.WIDTHPROF, | ||||
heightplot = self.HEIGHT+self.HEIGHTPROF, | ||||
show=show) | ||||
|
r858 | |||
|
r487 | nrow, ncol = self.getSubplots() | ||
|
r858 | |||
|
r487 | self.addAxes(nrow, ncol*ncolspan, 0, 0, colspan, 1) | ||
|
r858 | |||
|
r487 | def run(self, dataOut, id, wintitle="", channelList=None, showprofile='True', | ||
xmin=None, xmax=None, ymin=None, ymax=None, | ||||
timerange=None, | ||||
|
r568 | save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1, | ||
|
r487 | server=None, folder=None, username=None, password=None, | ||
ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0): | ||||
|
r858 | |||
|
r760 | if not isTimeInHourRange(dataOut.datatime, xmin, xmax): | ||
return | ||||
|
r858 | |||
|
r487 | 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)) | ||||
|
r858 | |||
|
r487 | x = dataOut.getTimeRange() | ||
|
r568 | #y = dataOut.getHeiRange() | ||
|
r487 | factor = dataOut.normFactor | ||
|
r731 | noise = dataOut.noise[channelIndexList]/factor | ||
|
r487 | noisedB = 10*numpy.log10(noise) | ||
|
r858 | |||
|
r760 | thisDatetime = dataOut.datatime | ||
|
r858 | |||
|
r487 | title = wintitle + " Noise" # : %s" %(thisDatetime.strftime("%d-%b-%Y")) | ||
xlabel = "" | ||||
ylabel = "Intensity (dB)" | ||||
|
r760 | update_figfile = False | ||
|
r858 | |||
|
r487 | if not self.isConfig: | ||
|
r858 | |||
|
r487 | nplots = 1 | ||
|
r858 | |||
|
r487 | self.setup(id=id, | ||
nplots=nplots, | ||||
wintitle=wintitle, | ||||
showprofile=showprofile, | ||||
show=show) | ||||
|
r858 | |||
|
r568 | if timerange != None: | ||
self.timerange = timerange | ||||
|
r858 | |||
|
r568 | self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange) | ||
|
r858 | |||
|
r568 | if ymin == None: ymin = numpy.floor(numpy.nanmin(noisedB)) - 10.0 | ||
|
r487 | if ymax == None: ymax = numpy.nanmax(noisedB) + 10.0 | ||
|
r858 | |||
|
r487 | self.FTP_WEI = ftp_wei | ||
self.EXP_CODE = exp_code | ||||
self.SUB_EXP_CODE = sub_exp_code | ||||
self.PLOT_POS = plot_pos | ||||
|
r858 | |||
|
r487 | self.name = thisDatetime.strftime("%Y%m%d_%H%M%S") | ||
self.isConfig = True | ||||
|
r494 | self.figfile = figfile | ||
|
r487 | self.xdata = numpy.array([]) | ||
self.ydata = numpy.array([]) | ||||
|
r858 | |||
|
r760 | update_figfile = True | ||
|
r858 | |||
|
r487 | #open file beacon phase | ||
path = '%s%03d' %(self.PREFIX, self.id) | ||||
noise_file = os.path.join(path,'%s.txt'%self.name) | ||||
self.filename_noise = os.path.join(figpath,noise_file) | ||||
|
r647 | |||
|
r487 | self.setWinTitle(title) | ||
|
r858 | |||
|
r487 | title = "Noise %s" %(thisDatetime.strftime("%Y/%m/%d %H:%M:%S")) | ||
|
r858 | |||
|
r713 | legendlabels = ["channel %d"%(idchannel) for idchannel in channelList] | ||
|
r487 | axes = self.axesList[0] | ||
|
r858 | |||
|
r487 | self.xdata = numpy.hstack((self.xdata, x[0:1])) | ||
|
r858 | |||
|
r487 | if len(self.ydata)==0: | ||
|
r731 | self.ydata = noisedB.reshape(-1,1) | ||
|
r487 | else: | ||
|
r731 | self.ydata = numpy.hstack((self.ydata, noisedB.reshape(-1,1))) | ||
|
r858 | |||
|
r487 | axes.pmultilineyaxis(x=self.xdata, y=self.ydata, | ||
|
r568 | xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, | ||
|
r487 | xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels, marker='x', markersize=8, linestyle="solid", | ||
XAxisAsTime=True, grid='both' | ||||
) | ||||
|
r858 | |||
|
r487 | self.draw() | ||
|
r858 | |||
|
r760 | if dataOut.ltctime >= self.xmax: | ||
|
r494 | self.counter_imagwr = wr_period | ||
|
r760 | self.isConfig = False | ||
update_figfile = True | ||||
|
r858 | |||
|
r573 | self.save(figpath=figpath, | ||
figfile=figfile, | ||||
save=save, | ||||
ftp=ftp, | ||||
wr_period=wr_period, | ||||
thisDatetime=thisDatetime, | ||||
|
r760 | update_figfile=update_figfile) | ||
|
r858 | |||
|
r647 | #store data beacon phase | ||
if save: | ||||
self.save_data(self.filename_noise, noisedB, thisDatetime) | ||||
|
r858 | |||
|
r494 | class BeaconPhase(Figure): | ||
|
r858 | |||
|
r494 | __isConfig = None | ||
__nsubplots = None | ||||
PREFIX = 'beacon_phase' | ||||
|
r858 | |||
|
r897 | def __init__(self, **kwargs): | ||
Figure.__init__(self, **kwargs) | ||||
|
r494 | self.timerange = 24*60*60 | ||
|
r760 | self.isConfig = False | ||
|
r494 | self.__nsubplots = 1 | ||
self.counter_imagwr = 0 | ||||
|
r760 | self.WIDTH = 800 | ||
self.HEIGHT = 400 | ||||
|
r494 | self.WIDTHPROF = 120 | ||
self.HEIGHTPROF = 0 | ||||
self.xdata = None | ||||
self.ydata = None | ||||
|
r858 | |||
|
r573 | self.PLOT_CODE = BEACON_CODE | ||
|
r858 | |||
|
r494 | self.FTP_WEI = None | ||
self.EXP_CODE = None | ||||
self.SUB_EXP_CODE = None | ||||
self.PLOT_POS = None | ||||
|
r858 | |||
|
r494 | self.filename_phase = None | ||
|
r858 | |||
|
r494 | self.figfile = None | ||
|
r858 | |||
|
r568 | self.xmin = None | ||
self.xmax = None | ||||
|
r858 | |||
|
r494 | def getSubplots(self): | ||
|
r858 | |||
|
r494 | ncol = 1 | ||
nrow = 1 | ||||
|
r858 | |||
|
r494 | return nrow, ncol | ||
|
r858 | |||
|
r494 | def setup(self, id, nplots, wintitle, showprofile=True, show=True): | ||
|
r858 | |||
|
r494 | self.__showprofile = showprofile | ||
self.nplots = nplots | ||||
|
r858 | |||
|
r494 | ncolspan = 7 | ||
colspan = 6 | ||||
self.__nsubplots = 2 | ||||
|
r858 | |||
|
r494 | self.createFigure(id = id, | ||
wintitle = wintitle, | ||||
widthplot = self.WIDTH+self.WIDTHPROF, | ||||
heightplot = self.HEIGHT+self.HEIGHTPROF, | ||||
show=show) | ||||
|
r858 | |||
|
r494 | nrow, ncol = self.getSubplots() | ||
|
r858 | |||
|
r494 | self.addAxes(nrow, ncol*ncolspan, 0, 0, colspan, 1) | ||
def save_phase(self, filename_phase): | ||||
|
r858 | f = open(filename_phase,'w+') | ||
|
r494 | f.write('\n\n') | ||
f.write('JICAMARCA RADIO OBSERVATORY - Beacon Phase \n') | ||||
|
r858 | f.write('DD MM YYYY HH MM SS pair(2,0) pair(2,1) pair(2,3) pair(2,4)\n\n' ) | ||
|
r494 | f.close() | ||
def save_data(self, filename_phase, data, data_datetime): | ||||
f=open(filename_phase,'a') | ||||
timetuple_data = data_datetime.timetuple() | ||||
day = str(timetuple_data.tm_mday) | ||||
month = str(timetuple_data.tm_mon) | ||||
year = str(timetuple_data.tm_year) | ||||
hour = str(timetuple_data.tm_hour) | ||||
minute = str(timetuple_data.tm_min) | ||||
second = str(timetuple_data.tm_sec) | ||||
f.write(day+' '+month+' '+year+' '+hour+' '+minute+' '+second+' '+str(data[0])+' '+str(data[1])+' '+str(data[2])+' '+str(data[3])+'\n') | ||||
f.close() | ||||
def run(self, dataOut, id, wintitle="", pairsList=None, showprofile='True', | ||||
|
r760 | xmin=None, xmax=None, ymin=None, ymax=None, hmin=None, hmax=None, | ||
|
r494 | timerange=None, | ||
|
r568 | save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1, | ||
|
r494 | server=None, folder=None, username=None, password=None, | ||
ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0): | ||||
|
r858 | |||
|
r760 | if not isTimeInHourRange(dataOut.datatime, xmin, xmax): | ||
return | ||||
|
r858 | |||
|
r494 | if pairsList == None: | ||
|
r760 | pairsIndexList = dataOut.pairsIndexList[:10] | ||
|
r494 | else: | ||
pairsIndexList = [] | ||||
for pair in pairsList: | ||||
if pair not in dataOut.pairsList: | ||||
raise ValueError, "Pair %s is not in dataOut.pairsList" %(pair) | ||||
pairsIndexList.append(dataOut.pairsList.index(pair)) | ||||
|
r858 | |||
|
r494 | if pairsIndexList == []: | ||
return | ||||
|
r858 | |||
|
r494 | # if len(pairsIndexList) > 4: | ||
# pairsIndexList = pairsIndexList[0:4] | ||||
|
r760 | |||
hmin_index = None | ||||
hmax_index = None | ||||
|
r858 | |||
|
r760 | if hmin != None and hmax != None: | ||
indexes = numpy.arange(dataOut.nHeights) | ||||
hmin_list = indexes[dataOut.heightList >= hmin] | ||||
hmax_list = indexes[dataOut.heightList <= hmax] | ||||
|
r858 | |||
|
r760 | if hmin_list.any(): | ||
hmin_index = hmin_list[0] | ||||
|
r858 | |||
|
r760 | if hmax_list.any(): | ||
hmax_index = hmax_list[-1]+1 | ||||
|
r858 | |||
|
r494 | x = dataOut.getTimeRange() | ||
|
r568 | #y = dataOut.getHeiRange() | ||
|
r494 | |||
|
r858 | |||
|
r760 | thisDatetime = dataOut.datatime | ||
|
r858 | |||
|
r760 | title = wintitle + " Signal Phase" # : %s" %(thisDatetime.strftime("%d-%b-%Y")) | ||
|
r494 | xlabel = "Local Time" | ||
|
r760 | ylabel = "Phase (degrees)" | ||
|
r858 | |||
|
r760 | update_figfile = False | ||
|
r858 | |||
|
r494 | nplots = len(pairsIndexList) | ||
#phase = numpy.zeros((len(pairsIndexList),len(dataOut.beacon_heiIndexList))) | ||||
phase_beacon = numpy.zeros(len(pairsIndexList)) | ||||
for i in range(nplots): | ||||
pair = dataOut.pairsList[pairsIndexList[i]] | ||||
|
r760 | ccf = numpy.average(dataOut.data_cspc[pairsIndexList[i], :, hmin_index:hmax_index], axis=0) | ||
powa = numpy.average(dataOut.data_spc[pair[0], :, hmin_index:hmax_index], axis=0) | ||||
powb = numpy.average(dataOut.data_spc[pair[1], :, hmin_index:hmax_index], axis=0) | ||||
|
r494 | avgcoherenceComplex = ccf/numpy.sqrt(powa*powb) | ||
phase = numpy.arctan2(avgcoherenceComplex.imag, avgcoherenceComplex.real)*180/numpy.pi | ||||
|
r858 | |||
|
r494 | #print "Phase %d%d" %(pair[0], pair[1]) | ||
#print phase[dataOut.beacon_heiIndexList] | ||||
|
r858 | |||
|
r760 | if dataOut.beacon_heiIndexList: | ||
phase_beacon[i] = numpy.average(phase[dataOut.beacon_heiIndexList]) | ||||
else: | ||||
phase_beacon[i] = numpy.average(phase) | ||||
|
r858 | |||
|
r760 | if not self.isConfig: | ||
|
r858 | |||
|
r494 | nplots = len(pairsIndexList) | ||
|
r858 | |||
|
r494 | self.setup(id=id, | ||
nplots=nplots, | ||||
wintitle=wintitle, | ||||
showprofile=showprofile, | ||||
show=show) | ||||
|
r858 | |||
|
r568 | if timerange != None: | ||
self.timerange = timerange | ||||
|
r858 | |||
|
r568 | self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange) | ||
|
r858 | |||
|
r760 | if ymin == None: ymin = 0 | ||
if ymax == None: ymax = 360 | ||||
|
r858 | |||
|
r494 | self.FTP_WEI = ftp_wei | ||
self.EXP_CODE = exp_code | ||||
self.SUB_EXP_CODE = sub_exp_code | ||||
self.PLOT_POS = plot_pos | ||||
|
r858 | |||
|
r494 | self.name = thisDatetime.strftime("%Y%m%d_%H%M%S") | ||
|
r760 | self.isConfig = True | ||
|
r494 | self.figfile = figfile | ||
self.xdata = numpy.array([]) | ||||
self.ydata = numpy.array([]) | ||||
|
r858 | |||
|
r760 | update_figfile = True | ||
|
r858 | |||
|
r494 | #open file beacon phase | ||
path = '%s%03d' %(self.PREFIX, self.id) | ||||
beacon_file = os.path.join(path,'%s.txt'%self.name) | ||||
self.filename_phase = os.path.join(figpath,beacon_file) | ||||
#self.save_phase(self.filename_phase) | ||||
|
r858 | |||
|
r494 | #store data beacon phase | ||
#self.save_data(self.filename_phase, phase_beacon, thisDatetime) | ||||
|
r858 | |||
|
r494 | self.setWinTitle(title) | ||
|
r858 | |||
|
r760 | title = "Phase Plot %s" %(thisDatetime.strftime("%Y/%m/%d %H:%M:%S")) | ||
|
r858 | |||
|
r760 | legendlabels = ["Pair (%d,%d)"%(pair[0], pair[1]) for pair in dataOut.pairsList] | ||
|
r858 | |||
|
r494 | axes = self.axesList[0] | ||
|
r858 | |||
|
r494 | self.xdata = numpy.hstack((self.xdata, x[0:1])) | ||
|
r858 | |||
|
r494 | if len(self.ydata)==0: | ||
self.ydata = phase_beacon.reshape(-1,1) | ||||
else: | ||||
self.ydata = numpy.hstack((self.ydata, phase_beacon.reshape(-1,1))) | ||||
|
r858 | |||
|
r494 | axes.pmultilineyaxis(x=self.xdata, y=self.ydata, | ||
|
r568 | xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, | ||
|
r494 | xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels, marker='x', markersize=8, linestyle="solid", | ||
XAxisAsTime=True, grid='both' | ||||
) | ||||
|
r858 | |||
|
r494 | self.draw() | ||
|
r858 | |||
|
r760 | if dataOut.ltctime >= self.xmax: | ||
|
r494 | self.counter_imagwr = wr_period | ||
|
r760 | self.isConfig = False | ||
update_figfile = True | ||||
|
r858 | |||
|
r573 | self.save(figpath=figpath, | ||
figfile=figfile, | ||||
save=save, | ||||
ftp=ftp, | ||||
wr_period=wr_period, | ||||
thisDatetime=thisDatetime, | ||||
|
r760 | update_figfile=update_figfile) | ||