jroplot_correlation.py
187 lines
| 5.9 KiB
| text/x-python
|
PythonLexer
|
r502 | import os | ||
import datetime | ||||
import numpy | ||||
import copy | ||||
|
r1285 | from schainpy.model.graphics.jroplot_base import Plot | ||
|
r502 | |||
|
r1285 | |||
class CorrelationPlot(Plot): | ||||
|
r502 | isConfig = None | ||
__nsubplots = None | ||||
|
r897 | |||
|
r502 | WIDTHPROF = None | ||
HEIGHTPROF = None | ||||
PREFIX = 'corr' | ||||
|
r897 | |||
def __init__(self, **kwargs): | ||||
Figure.__init__(self, **kwargs) | ||||
|
r502 | self.isConfig = False | ||
self.__nsubplots = 1 | ||||
|
r897 | |||
|
r502 | self.WIDTH = 280 | ||
self.HEIGHT = 250 | ||||
self.WIDTHPROF = 120 | ||||
self.HEIGHTPROF = 0 | ||||
self.counter_imagwr = 0 | ||||
|
r897 | |||
|
r502 | self.PLOT_CODE = 1 | ||
self.FTP_WEI = None | ||||
self.EXP_CODE = None | ||||
self.SUB_EXP_CODE = None | ||||
self.PLOT_POS = None | ||||
|
r897 | |||
|
r502 | def getSubplots(self): | ||
|
r897 | |||
r1396 | ncol = int(numpy.sqrt(self.nplots) + 0.9) | |||
nrow = int(self.nplots * 1. / ncol + 0.9) | ||||
|
r897 | |||
|
r502 | return nrow, ncol | ||
|
r897 | |||
|
r502 | def setup(self, id, nplots, wintitle, showprofile=False, show=True): | ||
|
r897 | |||
showprofile = False | ||||
|
r502 | self.__showprofile = showprofile | ||
self.nplots = nplots | ||||
|
r897 | |||
|
r502 | ncolspan = 1 | ||
colspan = 1 | ||||
if showprofile: | ||||
ncolspan = 3 | ||||
colspan = 2 | ||||
self.__nsubplots = 2 | ||||
|
r897 | |||
r1396 | self.createFigure(id=id, | |||
wintitle=wintitle, | ||||
widthplot=self.WIDTH + self.WIDTHPROF, | ||||
heightplot=self.HEIGHT + self.HEIGHTPROF, | ||||
|
r502 | show=show) | ||
|
r897 | |||
|
r502 | nrow, ncol = self.getSubplots() | ||
|
r897 | |||
|
r502 | counter = 0 | ||
for y in range(nrow): | ||||
for x in range(ncol): | ||||
|
r897 | |||
|
r502 | if counter >= self.nplots: | ||
break | ||||
|
r897 | |||
r1396 | self.addAxes(nrow, ncol * ncolspan, y, x * ncolspan, colspan, 1) | |||
|
r897 | |||
|
r502 | if showprofile: | ||
r1396 | self.addAxes(nrow, ncol * ncolspan, y, x * ncolspan + colspan, 1, 1) | |||
|
r897 | |||
|
r502 | counter += 1 | ||
|
r897 | |||
|
r502 | def run(self, dataOut, id, wintitle="", channelList=None, showprofile=False, | ||
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, | ||
|
r502 | server=None, folder=None, username=None, password=None, | ||
ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0, realtime=False): | ||||
|
r897 | |||
|
r502 | """ | ||
|
r897 | |||
|
r502 | Input: | ||
dataOut : | ||||
id : | ||||
wintitle : | ||||
channelList : | ||||
showProfile : | ||||
xmin : None, | ||||
xmax : None, | ||||
ymin : None, | ||||
ymax : None, | ||||
zmin : None, | ||||
zmax : None | ||||
""" | ||||
|
r897 | |||
|
r502 | if dataOut.flagNoData: | ||
return None | ||||
|
r897 | |||
|
r502 | if realtime: | ||
r1396 | if not(isRealtime(utcdatatime=dataOut.utctime)): | |||
|
r1167 | print('Skipping this plot function') | ||
|
r502 | return | ||
|
r897 | |||
|
r502 | if channelList == None: | ||
channelIndexList = dataOut.channelIndexList | ||||
else: | ||||
channelIndexList = [] | ||||
for channel in channelList: | ||||
if channel not in dataOut.channelList: | ||||
|
r1167 | raise ValueError("Channel %d is not in dataOut.channelList") | ||
|
r502 | channelIndexList.append(dataOut.channelList.index(channel)) | ||
|
r897 | |||
|
r502 | factor = dataOut.normFactor | ||
lenfactor = factor.shape[1] | ||||
x = dataOut.getLagTRange(1) | ||||
r1336 | y = dataOut.heightList | |||
|
r897 | |||
r1396 | z = copy.copy(dataOut.data_corr[:, :, 0, :]) | |||
|
r502 | for i in range(dataOut.data_corr.shape[0]): | ||
r1396 | z[i, :, :] = z[i, :, :] / factor[i, :] | |||
|
r502 | zdB = numpy.abs(z) | ||
|
r897 | |||
|
r502 | avg = numpy.average(z, axis=1) | ||
# avg = numpy.nanmean(z, axis=1) | ||||
# noise = dataOut.noise/factor | ||||
|
r897 | |||
r1396 | # thisDatetime = dataOut.datatime | |||
|
r568 | thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0]) | ||
|
r897 | title = wintitle + " Correlation" | ||
|
r502 | xlabel = "Lag T (s)" | ||
ylabel = "Range (Km)" | ||||
|
r897 | |||
|
r502 | if not self.isConfig: | ||
|
r897 | |||
nplots = dataOut.data_corr.shape[0] | ||||
|
r502 | self.setup(id=id, | ||
nplots=nplots, | ||||
wintitle=wintitle, | ||||
showprofile=showprofile, | ||||
show=show) | ||||
|
r897 | |||
|
r502 | if xmin == None: xmin = numpy.nanmin(x) | ||
if xmax == None: xmax = numpy.nanmax(x) | ||||
if ymin == None: ymin = numpy.nanmin(y) | ||||
if ymax == None: ymax = numpy.nanmax(y) | ||||
if zmin == None: zmin = 0 | ||||
if zmax == None: zmax = 1 | ||||
|
r897 | |||
|
r502 | self.FTP_WEI = ftp_wei | ||
self.EXP_CODE = exp_code | ||||
self.SUB_EXP_CODE = sub_exp_code | ||||
self.PLOT_POS = plot_pos | ||||
|
r897 | |||
|
r502 | self.isConfig = True | ||
|
r897 | |||
|
r502 | self.setWinTitle(title) | ||
|
r897 | |||
|
r502 | for i in range(self.nplots): | ||
r1396 | str_datetime = '%s %s' % (thisDatetime.strftime("%Y/%m/%d"), thisDatetime.strftime("%H:%M:%S")) | |||
title = "Channel %d and %d: : %s" % (dataOut.pairsList[i][0], dataOut.pairsList[i][1] , str_datetime) | ||||
axes = self.axesList[i * self.__nsubplots] | ||||
axes.pcolor(x, y, zdB[i, :, :], | ||||
|
r502 | xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax, | ||
xlabel=xlabel, ylabel=ylabel, title=title, | ||||
ticksize=9, cblabel='') | ||||
|
r897 | |||
|
r502 | # if self.__showprofile: | ||
# axes = self.axesList[i*self.__nsubplots +1] | ||||
# axes.pline(avgdB[i], y, | ||||
# xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax, | ||||
# xlabel='dB', ylabel='', title='', | ||||
# ytick_visible=False, | ||||
# grid='x') | ||||
|
r897 | # | ||
|
r502 | # noiseline = numpy.repeat(noisedB[i], len(y)) | ||
# axes.addpline(noiseline, y, idline=1, color="black", linestyle="dashed", lw=2) | ||||
|
r897 | |||
|
r502 | self.draw() | ||
|
r897 | |||
|
r573 | self.save(figpath=figpath, | ||
figfile=figfile, | ||||
save=save, | ||||
ftp=ftp, | ||||
wr_period=wr_period, | ||||
r1396 | thisDatetime=thisDatetime) | |||