jroplot_voltage.py
400 lines
| 13.6 KiB
| text/x-python
|
PythonLexer
|
r487 | ''' | ||
|
r568 | Created on Jul 9, 2014 | ||
|
r487 | |||
|
r568 | @author: roj-idl71 | ||
''' | ||||
import os | ||||
|
r487 | import datetime | ||
import numpy | ||||
from figure import Figure | ||||
r1262 | from plotting_codes import * | |||
|
r487 | |||
class Scope(Figure): | ||||
r1274 | ||||
|
r487 | isConfig = None | ||
r1274 | ||||
|
r973 | def __init__(self, **kwargs): | ||
Figure.__init__(self, **kwargs) | ||||
|
r487 | self.isConfig = False | ||
self.WIDTH = 300 | ||||
self.HEIGHT = 200 | ||||
self.counter_imagwr = 0 | ||||
r1274 | ||||
|
r487 | def getSubplots(self): | ||
r1274 | ||||
|
r487 | nrow = self.nplots | ||
ncol = 3 | ||||
return nrow, ncol | ||||
r1274 | ||||
|
r487 | def setup(self, id, nplots, wintitle, show): | ||
r1274 | ||||
|
r487 | self.nplots = nplots | ||
r1274 | ||||
self.createFigure(id=id, | ||||
wintitle=wintitle, | ||||
|
r487 | show=show) | ||
r1274 | ||||
|
r487 | nrow,ncol = self.getSubplots() | ||
colspan = 3 | ||||
rowspan = 1 | ||||
r1274 | ||||
|
r487 | for i in range(nplots): | ||
self.addAxes(nrow, ncol, i, 0, colspan, rowspan) | ||||
r1274 | ||||
|
r487 | def plot_iq(self, x, y, id, channelIndexList, thisDatetime, wintitle, show, xmin, xmax, ymin, ymax): | ||
yreal = y[channelIndexList,:].real | ||||
yimag = y[channelIndexList,:].imag | ||||
r1274 | ||||
|
r487 | title = wintitle + " Scope: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) | ||
xlabel = "Range (Km)" | ||||
ylabel = "Intensity - IQ" | ||||
r1274 | ||||
|
r487 | if not self.isConfig: | ||
nplots = len(channelIndexList) | ||||
r1274 | ||||
|
r487 | self.setup(id=id, | ||
nplots=nplots, | ||||
wintitle='', | ||||
show=show) | ||||
r1274 | ||||
|
r487 | if xmin == None: xmin = numpy.nanmin(x) | ||
if xmax == None: xmax = numpy.nanmax(x) | ||||
if ymin == None: ymin = min(numpy.nanmin(yreal),numpy.nanmin(yimag)) | ||||
if ymax == None: ymax = max(numpy.nanmax(yreal),numpy.nanmax(yimag)) | ||||
r1274 | ||||
|
r487 | self.isConfig = True | ||
r1274 | ||||
|
r487 | self.setWinTitle(title) | ||
r1274 | ||||
|
r487 | for i in range(len(self.axesList)): | ||
title = "Channel %d" %(i) | ||||
axes = self.axesList[i] | ||||
axes.pline(x, yreal[i,:], | ||||
xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, | ||||
xlabel=xlabel, ylabel=ylabel, title=title) | ||||
axes.addpline(x, yimag[i,:], idline=1, color="red", linestyle="solid", lw=2) | ||||
r1274 | ||||
|
r487 | def plot_power(self, x, y, id, channelIndexList, thisDatetime, wintitle, show, xmin, xmax, ymin, ymax): | ||
y = y[channelIndexList,:] * numpy.conjugate(y[channelIndexList,:]) | ||||
yreal = y.real | ||||
r1274 | ||||
|
r487 | title = wintitle + " Scope: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) | ||
xlabel = "Range (Km)" | ||||
ylabel = "Intensity" | ||||
r1274 | ||||
|
r487 | if not self.isConfig: | ||
nplots = len(channelIndexList) | ||||
r1274 | ||||
|
r487 | self.setup(id=id, | ||
nplots=nplots, | ||||
wintitle='', | ||||
show=show) | ||||
r1274 | ||||
|
r487 | if xmin == None: xmin = numpy.nanmin(x) | ||
if xmax == None: xmax = numpy.nanmax(x) | ||||
if ymin == None: ymin = numpy.nanmin(yreal) | ||||
if ymax == None: ymax = numpy.nanmax(yreal) | ||||
r1274 | ||||
|
r487 | self.isConfig = True | ||
r1274 | ||||
|
r487 | self.setWinTitle(title) | ||
r1274 | ||||
|
r487 | for i in range(len(self.axesList)): | ||
title = "Channel %d" %(i) | ||||
axes = self.axesList[i] | ||||
ychannel = yreal[i,:] | ||||
axes.pline(x, ychannel, | ||||
xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, | ||||
xlabel=xlabel, ylabel=ylabel, title=title) | ||||
r1274 | ||||
|
r487 | def run(self, dataOut, id, wintitle="", channelList=None, | ||
xmin=None, xmax=None, ymin=None, ymax=None, save=False, | ||||
figpath='./', figfile=None, show=True, wr_period=1, | ||||
|
r973 | ftp=False, server=None, folder=None, username=None, password=None, type='power', **kwargs): | ||
r1274 | ||||
|
r487 | """ | ||
r1274 | ||||
|
r487 | Input: | ||
dataOut : | ||||
id : | ||||
wintitle : | ||||
channelList : | ||||
xmin : None, | ||||
xmax : None, | ||||
ymin : None, | ||||
ymax : None, | ||||
""" | ||||
r1274 | ||||
|
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)) | ||||
r1274 | ||||
|
r568 | thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0]) | ||
r1274 | ||||
|
r742 | if dataOut.flagDataAsBlock: | ||
r1274 | ||||
|
r742 | for i in range(dataOut.nProfiles): | ||
r1274 | ||||
|
r742 | wintitle1 = wintitle + " [Profile = %d] " %i | ||
r1274 | ||||
|
r742 | if type == "power": | ||
r1274 | self.plot_power(dataOut.heightList, | |||
|
r742 | dataOut.data[:,i,:], | ||
r1274 | id, | |||
channelIndexList, | ||||
|
r742 | thisDatetime, | ||
wintitle1, | ||||
show, | ||||
xmin, | ||||
xmax, | ||||
ymin, | ||||
ymax) | ||||
r1274 | ||||
|
r742 | if type == "iq": | ||
r1274 | self.plot_iq(dataOut.heightList, | |||
|
r742 | dataOut.data[:,i,:], | ||
r1274 | id, | |||
channelIndexList, | ||||
|
r742 | thisDatetime, | ||
wintitle1, | ||||
show, | ||||
xmin, | ||||
xmax, | ||||
ymin, | ||||
ymax) | ||||
r1274 | ||||
|
r742 | self.draw() | ||
r1274 | ||||
|
r774 | str_datetime = thisDatetime.strftime("%Y%m%d_%H%M%S") | ||
figfile = self.getFilename(name = str_datetime) + "_" + str(i) | ||||
r1274 | ||||
|
r774 | self.save(figpath=figpath, | ||
figfile=figfile, | ||||
save=save, | ||||
ftp=ftp, | ||||
wr_period=wr_period, | ||||
thisDatetime=thisDatetime) | ||||
r1274 | ||||
|
r742 | else: | ||
wintitle += " [Profile = %d] " %dataOut.profileIndex | ||||
r1274 | ||||
|
r742 | if type == "power": | ||
r1274 | self.plot_power(dataOut.heightList, | |||
|
r742 | dataOut.data, | ||
r1274 | id, | |||
channelIndexList, | ||||
|
r742 | thisDatetime, | ||
wintitle, | ||||
show, | ||||
xmin, | ||||
xmax, | ||||
ymin, | ||||
ymax) | ||||
r1274 | ||||
|
r742 | if type == "iq": | ||
r1274 | self.plot_iq(dataOut.heightList, | |||
|
r742 | dataOut.data, | ||
r1274 | id, | |||
channelIndexList, | ||||
|
r742 | thisDatetime, | ||
wintitle, | ||||
show, | ||||
xmin, | ||||
xmax, | ||||
ymin, | ||||
ymax) | ||||
r1274 | ||||
|
r487 | self.draw() | ||
r1274 | ||||
|
r774 | str_datetime = thisDatetime.strftime("%Y%m%d_%H%M%S") + "_" + str(dataOut.profileIndex) | ||
r1274 | figfile = self.getFilename(name = str_datetime) | |||
|
r573 | self.save(figpath=figpath, | ||
figfile=figfile, | ||||
save=save, | ||||
ftp=ftp, | ||||
wr_period=wr_period, | ||||
thisDatetime=thisDatetime) | ||||
r1262 | ||||
class VoltACFPLot(Figure): | ||||
isConfig = None | ||||
__nsubplots = None | ||||
PREFIX = 'voltacf' | ||||
def __init__(self, **kwargs): | ||||
r1274 | Figure.__init__(self,**kwargs) | |||
self.isConfig = False | ||||
self.__nsubplots = 1 | ||||
self.PLOT_CODE = VOLT_ACF_CODE | ||||
self.WIDTH = 900 | ||||
self.HEIGHT = 700 | ||||
self.counter_imagwr= 0 | ||||
self.FTP_WEI = None | ||||
self.EXP_CODE = None | ||||
self.SUB_EXP_CODE = None | ||||
self.PLOT_POS = None | ||||
r1262 | ||||
def getSubplots(self) : | ||||
r1274 | ncol = 1 | |||
nrow = 1 | ||||
return nrow, ncol | ||||
r1262 | ||||
def setup(self,id, nplots,wintitle,show): | ||||
r1274 | self.nplots = nplots | |||
ncolspan = 1 | ||||
colspan = 1 | ||||
self.createFigure(id=id, | ||||
wintitle = wintitle, | ||||
widthplot = self.WIDTH, | ||||
heightplot = self.HEIGHT, | ||||
show = show) | ||||
nrow, ncol = self.getSubplots() | ||||
counter = 0 | ||||
for y in range(nrow): | ||||
for x in range(ncol): | ||||
self.addAxes(nrow, ncol*ncolspan,y, x*ncolspan, colspan, 1) | ||||
r1262 | ||||
def run(self,dataOut, id, wintitle="",channelList = None , channel =None, nSamples = None, | ||||
nSampleList= None, resolutionFactor=None, xmin= None, xmax = None, ymin=None, ymax=None, | ||||
save= False, figpath='./', figfile= None,show= True, ftp= False, wr_period=1, server= None, | ||||
folder= None, username =None, password= None, ftp_wei=0 , exp_code=0,sub_exp_code=0,plot_pos=0, | ||||
xaxis="time"): | ||||
r1274 | ||||
channel0 = channel | ||||
nSamples = nSamples | ||||
resFactor = resolutionFactor | ||||
if nSamples == None: | ||||
nSamples = 20 | ||||
if resFactor == None: | ||||
resFactor = 5 | ||||
if channel0 == None: | ||||
channel0 = 0 | ||||
else: | ||||
if channel0 not in dataOut.channelList: | ||||
raise ValueError, "Channel %d is not in %s dataOut.channelList"%(channel0, dataOut.channelList) | ||||
if channelList == None: | ||||
channelIndexList = dataOut.channelIndexList | ||||
channelList = dataOut.channelList | ||||
else: | ||||
r1262 | 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)) | ||||
#factor = dataOut.normFactor | ||||
y = dataOut.getHeiRange() | ||||
r1274 | #print y, dataOut.heightList[0] | |||
#print "pause" | ||||
#import time | ||||
#time.sleep(10) | ||||
r1262 | deltaHeight = dataOut.heightList[1]-dataOut.heightList[0] | |||
r1274 | z = dataOut.data_acfLag | |||
r1262 | ||||
r1274 | shape = dataOut.data_acfLag.shape | |||
hei_index = numpy.arange(shape[2]) | ||||
hei_plot = numpy.arange(nSamples)*resFactor | ||||
r1262 | ||||
if nSampleList is not None: | ||||
for nsample in nSampleList: | ||||
if nsample not in dataOut.heightList/deltaHeight: | ||||
r1274 | print "Lista available : %s "%(dataOut.heightList/deltaHeight) | |||
r1262 | raise ValueError, "nsample %d is not in %s dataOut.heightList"%(nsample,dataOut.heightList) | |||
if nSampleList is not None: | ||||
hei_plot = numpy.array(nSampleList)*resFactor | ||||
if hei_plot[-1] >= hei_index[-1]: | ||||
print ("La cantidad de puntos en altura es %d y la resolucion es %f Km"%(hei_plot.shape[0],deltaHeight*resFactor )) | ||||
raise ValueError, "resFactor %d multiplicado por el valor de %d nSamples es mayor a %d cantidad total de puntos"%(resFactor,nSamples,hei_index[-1]) | ||||
r1274 | #escalamiento -1 a 1 a resolucion (factor de resolucion en altura)* deltaHeight | |||
r1262 | #min = numpy.min(z[0,:,0]) | |||
#max =numpy.max(z[0,:,0]) | ||||
r1274 | #print shape[0] | |||
r1262 | for i in range(shape[0]): | |||
r1274 | #print "amigo i",i | |||
r1262 | for j in range(shape[2]): | |||
r1274 | min = numpy.min(z[i,:,j]) | |||
max = numpy.max(z[i,:,j]) | ||||
r1262 | z[i,:,j]= (((z[i,:,j]-min)/(max-min))*deltaHeight*resFactor + j*deltaHeight+dataOut.heightList[0]) | |||
r1274 | if xaxis == "time": | |||
x = dataOut.getAcfRange()*1000 | ||||
zdB = z[channel0,:,hei_plot] | ||||
xlabel = "Time (ms)" | ||||
ylabel = "VOLT_ACF" | ||||
thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0]) | ||||
title = wintitle + "VOLT ACF Plot Ch %s %s" %(channel0,thisDatetime.strftime("%d-%b-%Y")) | ||||
r1262 | ||||
r1274 | if not self.isConfig: | |||
r1262 | ||||
r1274 | nplots = 1 | |||
r1262 | ||||
r1274 | self.setup(id=id, | |||
nplots=nplots, | ||||
wintitle=wintitle, | ||||
show=show) | ||||
r1262 | ||||
r1274 | 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) | ||||
r1262 | ||||
r1274 | print ("El parametro resFactor es %d y la resolucion en altura es %f"%(resFactor,deltaHeight )) | |||
print ("La cantidad de puntos en altura es %d y la nueva resolucion es %f Km"%(hei_plot.shape[0],deltaHeight*resFactor )) | ||||
print ("La altura maxima es %d Km"%(hei_plot[-1]*deltaHeight )) | ||||
r1262 | ||||
r1274 | self.FTP_WEI = ftp_wei | |||
self.EXP_CODE = exp_code | ||||
self.SUB_EXP_CODE = sub_exp_code | ||||
self.PLOT_POS = plot_pos | ||||
r1262 | ||||
r1274 | self.isConfig = True | |||
r1262 | ||||
r1274 | self.setWinTitle(title) | |||
title = "VOLT ACF Plot: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) | ||||
axes = self.axesList[0] | ||||
r1262 | ||||
r1274 | legendlabels = ["Range = %dKm" %y[i] for i in hei_plot] | |||
r1262 | ||||
r1274 | 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') | ||||
r1262 | ||||
r1274 | self.draw() | |||
r1262 | ||||
r1274 | if figfile == None: | |||
str_datetime = thisDatetime.strftime("%Y%m%d_%H%M%S") | ||||
name = str_datetime | ||||
if ((dataOut.azimuth!=None) and (dataOut.zenith!=None)): | ||||
name = name + '_az' + '_%2.2f'%(dataOut.azimuth) + '_zn' + '_%2.2f'%(dataOut.zenith) | ||||
figfile = self.getFilename(name) | ||||
self.save(figpath=figpath, | ||||
figfile=figfile, | ||||
save=save, | ||||
ftp=ftp, | ||||
wr_period=wr_period, | ||||
thisDatetime=thisDatetime) | ||||