From a455424d10b061ca89b26848349dae60248299e8 2021-03-02 17:07:11 From: Danny Scipión Date: 2021-03-02 17:07:11 Subject: [PATCH] Merge branch 'master' of http://jro-dev.igp.gob.pe/rhodecode/schain --- diff --git a/schainpy/__init__.py b/schainpy/__init__.py index ce6e1df..6b50397 100644 --- a/schainpy/__init__.py +++ b/schainpy/__init__.py @@ -5,4 +5,4 @@ try: except: pass -__version__ = '3.0.0b5' +__version__ = '3.0.0b6' diff --git a/schainpy/model/data/jrodata.py b/schainpy/model/data/jrodata.py index c927057..912286a 100644 --- a/schainpy/model/data/jrodata.py +++ b/schainpy/model/data/jrodata.py @@ -907,12 +907,10 @@ class PlotterData(object): MAXNUMX = 200 MAXNUMY = 200 - def __init__(self, code, throttle_value, exp_code, localtime=True, buffering=True, snr=False): + def __init__(self, code, exp_code, localtime=True): self.key = code - self.throttle = throttle_value self.exp_code = exp_code - self.buffering = buffering self.ready = False self.flagNoData = False self.localtime = localtime @@ -920,46 +918,24 @@ class PlotterData(object): self.meta = {} self.__heights = [] - if 'snr' in code: - self.plottypes = ['snr'] - elif code == 'spc': - self.plottypes = ['spc', 'noise', 'rti'] - elif code == 'cspc': - self.plottypes = ['cspc', 'spc', 'noise', 'rti'] - elif code == 'rti': - self.plottypes = ['noise', 'rti'] - else: - self.plottypes = [code] - - if 'snr' not in self.plottypes and snr: - self.plottypes.append('snr') - - for plot in self.plottypes: - self.data[plot] = {} - def __str__(self): dum = ['{}{}'.format(key, self.shape(key)) for key in self.data] return 'Data[{}][{}]'.format(';'.join(dum), len(self.times)) def __len__(self): - return len(self.data[self.key]) + return len(self.data) def __getitem__(self, key): - - if key not in self.data: - raise KeyError(log.error('Missing key: {}'.format(key))) - if 'spc' in key or not self.buffering: - ret = self.data[key][self.tm] - elif 'scope' in key: - ret = numpy.array(self.data[key][float(self.tm)]) - else: - ret = numpy.array([self.data[key][x] for x in self.times]) + if isinstance(key, int): + return self.data[self.times[key]] + elif isinstance(key, str): + ret = numpy.array([self.data[x][key] for x in self.times]) if ret.ndim > 1: ret = numpy.swapaxes(ret, 0, 1) - return ret + return ret def __contains__(self, key): - return key in self.data + return key in self.data[self.min_time] def setup(self): ''' @@ -971,125 +947,25 @@ class PlotterData(object): self.data = {} self.__heights = [] self.__all_heights = set() - for plot in self.plottypes: - if 'snr' in plot: - plot = 'snr' - elif 'spc_moments' == plot: - plot = 'moments' - self.data[plot] = {} - - if 'spc' in self.data or 'rti' in self.data or 'cspc' in self.data or 'moments' in self.data: - self.data['noise'] = {} - self.data['rti'] = {} - if 'noise' not in self.plottypes: - self.plottypes.append('noise') - if 'rti' not in self.plottypes: - self.plottypes.append('rti') def shape(self, key): ''' Get the shape of the one-element data for the given key ''' - if len(self.data[key]): - if 'spc' in key or not self.buffering: - return self.data[key].shape - return self.data[key][self.times[0]].shape + if len(self.data[self.min_time][key]): + return self.data[self.min_time][key].shape return (0,) - def update(self, dataOut, tm): + def update(self, data, tm, meta={}): ''' Update data object with new dataOut ''' - self.profileIndex = dataOut.profileIndex - self.tm = tm - self.type = dataOut.type - self.parameters = getattr(dataOut, 'parameters', []) - - if hasattr(dataOut, 'meta'): - self.meta.update(dataOut.meta) - - if hasattr(dataOut, 'pairsList'): - self.pairs = dataOut.pairsList - - self.interval = dataOut.timeInterval - if True in ['spc' in ptype for ptype in self.plottypes]: - self.xrange = (dataOut.getFreqRange(1)/1000., - dataOut.getAcfRange(1), dataOut.getVelRange(1)) - self.__heights.append(dataOut.heightList) - self.__all_heights.update(dataOut.heightList) - - for plot in self.plottypes: - if plot in ('spc', 'spc_moments', 'spc_cut'): - z = dataOut.data_spc/dataOut.normFactor - buffer = 10*numpy.log10(z) - if plot == 'cspc': - buffer = (dataOut.data_spc, dataOut.data_cspc) - if plot == 'noise': - buffer = 10*numpy.log10(dataOut.getNoise()/dataOut.normFactor) - if plot in ('rti', 'spcprofile'): - buffer = dataOut.getPower() - if plot == 'snr_db': - buffer = dataOut.data_SNR - if plot == 'snr': - buffer = 10*numpy.log10(dataOut.data_SNR) - if plot == 'dop': - buffer = dataOut.data_DOP - if plot == 'pow': - buffer = 10*numpy.log10(dataOut.data_POW) - if plot == 'width': - buffer = dataOut.data_WIDTH - if plot == 'coh': - buffer = dataOut.getCoherence() - if plot == 'phase': - buffer = dataOut.getCoherence(phase=True) - if plot == 'output': - buffer = dataOut.data_output - if plot == 'param': - buffer = dataOut.data_param - if plot == 'scope': - buffer = dataOut.data - self.flagDataAsBlock = dataOut.flagDataAsBlock - self.nProfiles = dataOut.nProfiles - if plot == 'pp_power': - buffer = dataOut.dataPP_POWER - self.flagDataAsBlock = dataOut.flagDataAsBlock - self.nProfiles = dataOut.nProfiles - if plot == 'pp_signal': - buffer = dataOut.dataPP_POW - self.flagDataAsBlock = dataOut.flagDataAsBlock - self.nProfiles = dataOut.nProfiles - if plot == 'pp_velocity': - buffer = dataOut.dataPP_DOP - self.flagDataAsBlock = dataOut.flagDataAsBlock - self.nProfiles = dataOut.nProfiles - if plot == 'pp_specwidth': - buffer = dataOut.dataPP_WIDTH - self.flagDataAsBlock = dataOut.flagDataAsBlock - self.nProfiles = dataOut.nProfiles - - if plot == 'spc': - self.data['spc'][tm] = buffer - elif plot == 'cspc': - self.data['cspc'][tm] = buffer - elif plot == 'spc_moments': - self.data['spc'][tm] = buffer - self.data['moments'][tm] = dataOut.moments - else: - if self.buffering: - self.data[plot][tm] = buffer - else: - self.data[plot][tm] = buffer - - if dataOut.channelList is None: - self.channels = range(buffer.shape[0]) - else: - self.channels = dataOut.channelList - - if buffer is None: - self.flagNoData = True - raise schainpy.admin.SchainWarning('Attribute data_{} is empty'.format(self.key)) + self.data[tm] = data + + for key, value in meta.items(): + setattr(self, key, value) def normalize_heights(self): ''' @@ -1119,18 +995,21 @@ class PlotterData(object): Convert data to json ''' - dy = int(self.heights.size/self.MAXNUMY) + 1 - if self.key in ('spc', 'cspc'): - dx = int(self.data[self.key][tm].shape[1]/self.MAXNUMX) + 1 + meta = {} + meta['xrange'] = [] + dy = int(len(self.yrange)/self.MAXNUMY) + 1 + tmp = self.data[tm][self.key] + shape = tmp.shape + if len(shape) == 2: + data = self.roundFloats(self.data[tm][self.key][::, ::dy].tolist()) + elif len(shape) == 3: + dx = int(self.data[tm][self.key].shape[1]/self.MAXNUMX) + 1 data = self.roundFloats( - self.data[self.key][tm][::, ::dx, ::dy].tolist()) + self.data[tm][self.key][::, ::dx, ::dy].tolist()) + meta['xrange'] = self.roundFloats(self.xrange[2][::dx].tolist()) else: - if self.key is 'noise': - data = [[x] for x in self.roundFloats(self.data[self.key][tm].tolist())] - else: - data = self.roundFloats(self.data[self.key][tm][::, ::dy].tolist()) - - meta = {} + data = self.roundFloats(self.data[tm][self.key].tolist()) + ret = { 'plot': plot_name, 'code': self.exp_code, @@ -1140,12 +1019,7 @@ class PlotterData(object): meta['type'] = plot_type meta['interval'] = float(self.interval) meta['localtime'] = self.localtime - meta['yrange'] = self.roundFloats(self.heights[::dy].tolist()) - if 'spc' in self.data or 'cspc' in self.data: - meta['xrange'] = self.roundFloats(self.xrange[2][::dx].tolist()) - else: - meta['xrange'] = [] - + meta['yrange'] = self.roundFloats(self.yrange[::dy].tolist()) meta.update(self.meta) ret['metadata'] = meta return json.dumps(ret) @@ -1156,10 +1030,9 @@ class PlotterData(object): Return the list of times of the current data ''' - ret = numpy.array([t for t in self.data[self.key]]) - if self: - ret.sort() - return ret + ret = [t for t in self.data] + ret.sort() + return numpy.array(ret) @property def min_time(self): @@ -1177,13 +1050,13 @@ class PlotterData(object): return self.times[-1] - @property - def heights(self): - ''' - Return the list of heights of the current data - ''' + # @property + # def heights(self): + # ''' + # Return the list of heights of the current data + # ''' - return numpy.array(self.__heights[-1]) + # return numpy.array(self.__heights[-1]) @staticmethod def roundFloats(obj): diff --git a/schainpy/model/data/jroheaderIO.py b/schainpy/model/data/jroheaderIO.py index 4d1eeca..168790a 100644 --- a/schainpy/model/data/jroheaderIO.py +++ b/schainpy/model/data/jroheaderIO.py @@ -302,7 +302,7 @@ class RadarControllerHeader(Header): nWindows=None, nHeights=None, firstHeight=None, deltaHeight=None, numTaus=0, line6Function=0, line5Function=0, fClock=None, prePulseBefore=0, prePulseAfter=0, - codeType=0, nCode=0, nBaud=0, code=None, + codeType=0, nCode=0, nBaud=0, code=[], flip1=0, flip2=0): # self.size = 116 diff --git a/schainpy/model/graphics/jroplot_base.py b/schainpy/model/graphics/jroplot_base.py index 2525faf..fd2eca7 100644 --- a/schainpy/model/graphics/jroplot_base.py +++ b/schainpy/model/graphics/jroplot_base.py @@ -12,7 +12,7 @@ import zmq import time import numpy import datetime -from multiprocessing import Queue +from collections import deque from functools import wraps from threading import Thread import matplotlib @@ -22,7 +22,7 @@ if 'BACKEND' in os.environ: elif 'linux' in sys.platform: matplotlib.use("TkAgg") elif 'darwin' in sys.platform: - matplotlib.use('WxAgg') + matplotlib.use('MacOSX') else: from schainpy.utils import log log.warning('Using default Backend="Agg"', 'INFO') @@ -83,7 +83,6 @@ def figpause(interval): pass return - def popup(message): ''' ''' @@ -186,7 +185,7 @@ class Plot(Operation): self.sender_time = 0 self.data = None self.firsttime = True - self.sender_queue = Queue(maxsize=60) + self.sender_queue = deque(maxlen=10) self.plots_adjust = {'left': 0.125, 'right': 0.9, 'bottom': 0.15, 'top': 0.9, 'wspace': 0.2, 'hspace': 0.2} def __fmtTime(self, x, pos): @@ -230,6 +229,7 @@ class Plot(Operation): self.yscale = kwargs.get('yscale', None) self.xlabel = kwargs.get('xlabel', None) self.attr_time = kwargs.get('attr_time', 'utctime') + self.attr_data = kwargs.get('attr_data', 'data_param') self.decimation = kwargs.get('decimation', None) self.showSNR = kwargs.get('showSNR', False) self.oneFigure = kwargs.get('oneFigure', True) @@ -251,8 +251,8 @@ class Plot(Operation): self.tag = kwargs.get('tag', '') self.height_index = kwargs.get('height_index', None) self.__throttle_plot = apply_throttle(self.throttle) - self.data = PlotterData( - self.CODE, self.throttle, self.exp_code, self.localtime, self.buffering, snr=self.showSNR) + code = self.attr_data if self.attr_data else self.CODE + self.data = PlotterData(self.CODE, self.exp_code, self.localtime) if self.server: if not self.server.startswith('tcp://'): @@ -385,8 +385,8 @@ class Plot(Operation): xmax = self.tmin + self.xrange*60*60 ax.xaxis.set_major_formatter(FuncFormatter(self.__fmtTime)) ax.xaxis.set_major_locator(LinearLocator(9)) - ymin = self.ymin if self.ymin else numpy.nanmin(self.y) - ymax = self.ymax if self.ymax else numpy.nanmax(self.y) + ymin = self.ymin if self.ymin is not None else numpy.nanmin(self.y[numpy.isfinite(self.y)]) + ymax = self.ymax if self.ymax is not None else numpy.nanmax(self.y[numpy.isfinite(self.y)]) ax.set_facecolor(self.bgcolor) if self.xscale: ax.xaxis.set_major_formatter(FuncFormatter( @@ -478,14 +478,28 @@ class Plot(Operation): if self.server: self.send_to_server() + def __update(self, dataOut, timestamp): + ''' + ''' + + metadata = { + 'yrange': dataOut.heightList, + 'interval': dataOut.timeInterval, + 'channels': dataOut.channelList + } + + data, meta = self.update(dataOut) + metadata.update(meta) + self.data.update(data, timestamp, metadata) + def save_figure(self, n): ''' ''' - if (self.data.tm - self.save_time) <= self.save_period: + if (self.data.max_time - self.save_time) <= self.save_period: return - self.save_time = self.data.tm + self.save_time = self.data.max_time fig = self.figures[n] @@ -520,11 +534,15 @@ class Plot(Operation): ''' ''' - interval = self.data.tm - self.sender_time + if self.exp_code == None: + log.warning('Missing `exp_code` skipping sending to server...') + + last_time = self.data.max_time + interval = last_time - self.sender_time if interval < self.sender_period: return - self.sender_time = self.data.tm + self.sender_time = last_time attrs = ['titles', 'zmin', 'zmax', 'tag', 'ymin', 'ymax'] for attr in attrs: @@ -541,27 +559,21 @@ class Plot(Operation): self.data.meta['colormap'] = 'Viridis' self.data.meta['interval'] = int(interval) - try: - self.sender_queue.put(self.data.tm, block=False) - except: - tm = self.sender_queue.get() - self.sender_queue.put(self.data.tm) + self.sender_queue.append(last_time) while True: - if self.sender_queue.empty(): - break - tm = self.sender_queue.get() try: - msg = self.data.jsonify(tm, self.save_code, self.plot_type) - except: - continue + tm = self.sender_queue.popleft() + except IndexError: + break + msg = self.data.jsonify(tm, self.save_code, self.plot_type) self.socket.send_string(msg) - socks = dict(self.poll.poll(5000)) + socks = dict(self.poll.poll(2000)) if socks.get(self.socket) == zmq.POLLIN: reply = self.socket.recv_string() if reply == 'ok': log.log("Response from server ok", self.name) - time.sleep(0.2) + time.sleep(0.1) continue else: log.warning( @@ -569,11 +581,10 @@ class Plot(Operation): else: log.warning( "No response from server, retrying...", self.name) - self.sender_queue.put(self.data.tm) + self.sender_queue.appendleft(tm) self.socket.setsockopt(zmq.LINGER, 0) self.socket.close() self.poll.unregister(self.socket) - time.sleep(0.1) self.socket = self.context.socket(zmq.REQ) self.socket.connect(self.server) self.poll.register(self.socket, zmq.POLLIN) @@ -595,9 +606,21 @@ class Plot(Operation): def plot(self): ''' - Must be defined in the child class + Must be defined in the child class, the actual plotting method ''' raise NotImplementedError + + def update(self, dataOut): + ''' + Must be defined in the child class, update self.data with new data + ''' + + data = { + self.CODE: getattr(dataOut, 'data_{}'.format(self.CODE)) + } + meta = {} + + return data, meta def run(self, dataOut, **kwargs): ''' @@ -623,14 +646,14 @@ class Plot(Operation): tm = getattr(dataOut, self.attr_time) - if self.data and 'time' in self.xaxis and (tm - self.tmin) >= self.xrange*60*60: + if self.data and 'time' in self.xaxis and (tm - self.tmin) >= self.xrange*60*60: self.save_time = tm self.__plot() self.tmin += self.xrange*60*60 self.data.setup() self.clear_figures() - self.data.update(dataOut, tm) + self.__update(dataOut, tm) if self.isPlotConfig is False: self.__setup_plot() @@ -658,7 +681,7 @@ class Plot(Operation): def close(self): if self.data and not self.data.flagNoData: - self.save_time = self.data.tm + self.save_time = self.data.max_time self.__plot() if self.data and not self.data.flagNoData and self.pause: figpause(10) diff --git a/schainpy/model/graphics/jroplot_heispectra.py b/schainpy/model/graphics/jroplot_heispectra.py index d1fc927..a98a5cd 100644 --- a/schainpy/model/graphics/jroplot_heispectra.py +++ b/schainpy/model/graphics/jroplot_heispectra.py @@ -1,342 +1,101 @@ -''' -Created on Jul 9, 2014 +# Copyright (c) 2012-2020 Jicamarca Radio Observatory +# All rights reserved. +# +# Distributed under the terms of the BSD 3-clause license. +"""Classes to plo Specra Heis data -@author: roj-idl71 -''' -import os -import datetime -import numpy - -from schainpy.model.graphics.jroplot_base import Plot - - -class SpectraHeisScope(Plot): - - - isConfig = None - __nsubplots = None - - WIDTHPROF = None - HEIGHTPROF = None - PREFIX = 'spc' - - def __init__(self):#, **kwargs): - - Plot.__init__(self)#, **kwargs) - self.isConfig = False - self.__nsubplots = 1 - - self.WIDTH = 230 - self.HEIGHT = 250 - self.WIDTHPROF = 120 - self.HEIGHTPROF = 0 - self.counter_imagwr = 0 - - self.PLOT_CODE = SPEC_CODE - - 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, id, nplots, wintitle, show): - - showprofile = False - self.__showprofile = showprofile - self.nplots = nplots - - ncolspan = 1 - colspan = 1 - if showprofile: - ncolspan = 3 - colspan = 2 - self.__nsubplots = 2 - - self.createFigure(id = id, - wintitle = wintitle, - widthplot = self.WIDTH + self.WIDTHPROF, - heightplot = self.HEIGHT + self.HEIGHTPROF, - show = show) - - 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 - - - def run(self, dataOut, id, wintitle="", channelList=None, - xmin=None, xmax=None, ymin=None, ymax=None, save=False, - figpath='./', figfile=None, ftp=False, wr_period=1, show=True, - server=None, folder=None, username=None, password=None, - ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0): - - """ - - Input: - dataOut : - id : - wintitle : - channelList : - xmin : None, - xmax : None, - ymin : None, - ymax : None, - """ - - if dataOut.flagNoData: - return dataOut - - if dataOut.realtime: - if not(isRealtime(utcdatatime = dataOut.utctime)): - print('Skipping this plot function') - return - - 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)) - #para 1Mhz descomentar la siguiente linea - #x= x/(10000.0) -# y = dataOut.data[channelIndexList,:] * numpy.conjugate(dataOut.data[channelIndexList,:]) -# y = y.real - factor = dataOut.normFactor - data = dataOut.data_spc / factor - datadB = 10.*numpy.log10(data) - y = datadB - - #thisDatetime = dataOut.datatime - thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0]) - title = wintitle + " Scope: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) - xlabel = "" - #para 1Mhz descomentar la siguiente linea - #xlabel = "Frequency x 10000" - ylabel = "Intensity (dB)" - - if not self.isConfig: - nplots = len(channelIndexList) - - self.setup(id=id, - nplots=nplots, - wintitle=wintitle, - show=show) - - 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.FTP_WEI = ftp_wei - self.EXP_CODE = exp_code - self.SUB_EXP_CODE = sub_exp_code - self.PLOT_POS = plot_pos - - self.isConfig = True - - self.setWinTitle(title) - - for i in range(len(self.axesList)): - ychannel = y[i,:] - str_datetime = '%s %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S")) - title = "Channel %d: %4.2fdB: %s" %(dataOut.channelList[channelIndexList[i]], numpy.max(ychannel), str_datetime) - axes = self.axesList[i] - axes.pline(x, ychannel, - xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, - xlabel=xlabel, ylabel=ylabel, title=title, grid='both') - - - self.draw() - - self.save(figpath=figpath, - figfile=figfile, - save=save, - ftp=ftp, - wr_period=wr_period, - thisDatetime=thisDatetime) - - return dataOut - - -class RTIfromSpectraHeis(Plot): - - isConfig = None - __nsubplots = None - - PREFIX = 'rtinoise' - - def __init__(self):#, **kwargs): - Plot.__init__(self)#, **kwargs) - self.timerange = 24*60*60 - self.isConfig = False - self.__nsubplots = 1 - - self.WIDTH = 820 - self.HEIGHT = 200 - self.WIDTHPROF = 120 - self.HEIGHTPROF = 0 - self.counter_imagwr = 0 - self.xdata = None - self.ydata = None - self.figfile = None - - self.PLOT_CODE = RTI_CODE - - def getSubplots(self): - - ncol = 1 - nrow = 1 - - return nrow, ncol - - def setup(self, id, nplots, wintitle, showprofile=True, show=True): - - self.__showprofile = showprofile - self.nplots = nplots - - ncolspan = 7 - colspan = 6 - self.__nsubplots = 2 - - self.createFigure(id = id, - wintitle = wintitle, - widthplot = self.WIDTH+self.WIDTHPROF, - heightplot = self.HEIGHT+self.HEIGHTPROF, - show = show) - - nrow, ncol = self.getSubplots() - - self.addAxes(nrow, ncol*ncolspan, 0, 0, colspan, 1) +""" +import numpy - def run(self, dataOut, id, wintitle="", channelList=None, showprofile='True', - xmin=None, xmax=None, ymin=None, ymax=None, - timerange=None, - save=False, figpath='./', figfile=None, ftp=False, wr_period=1, show=True, - server=None, folder=None, username=None, password=None, - ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0): +from schainpy.model.graphics.jroplot_base import Plot, plt - if dataOut.flagNoData: - return dataOut +class SpectraHeisPlot(Plot): - 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)) + CODE = 'spc_heis' - if timerange != None: - self.timerange = timerange + def setup(self): - x = dataOut.getTimeRange() - y = dataOut.heightList + self.nplots = len(self.data.channels) + self.ncols = int(numpy.sqrt(self.nplots) + 0.9) + self.nrows = int((1.0 * self.nplots / self.ncols) + 0.9) + self.height = 2.6 * self.nrows + self.width = 3.5 * self.ncols + self.plots_adjust.update({'wspace': 0.4, 'hspace':0.4, 'left': 0.1, 'right': 0.95, 'bottom': 0.08}) + self.ylabel = 'Intensity [dB]' + self.xlabel = 'Frequency [KHz]' + self.colorbar = False - factor = dataOut.normFactor - data = dataOut.data_spc / factor - data = numpy.average(data,axis=1) - datadB = 10*numpy.log10(data) + def update(self, dataOut): -# factor = dataOut.normFactor -# noise = dataOut.getNoise()/factor -# noisedB = 10*numpy.log10(noise) + data = {} + meta = {} + spc = 10*numpy.log10(dataOut.data_spc / dataOut.normFactor) + data['spc_heis'] = spc + + return data, meta - #thisDatetime = dataOut.datatime - thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0]) - title = wintitle + " RTI: %s" %(thisDatetime.strftime("%d-%b-%Y")) - xlabel = "Local Time" - ylabel = "Intensity (dB)" + def plot(self): - if not self.isConfig: + c = 3E8 + deltaHeight = self.data.yrange[1] - self.data.yrange[0] + x = numpy.arange(-1*len(self.data.yrange)/2., len(self.data.yrange)/2.)*(c/(2*deltaHeight*len(self.data.yrange)*1000)) + self.y = self.data[-1]['spc_heis'] + self.titles = [] - nplots = 1 + for n, ax in enumerate(self.axes): + ychannel = self.y[n,:] + if ax.firsttime: + self.xmin = min(x) if self.xmin is None else self.xmin + self.xmax = max(x) if self.xmax is None else self.xmax + ax.plt = ax.plot(x, ychannel, lw=1, color='b')[0] + else: + ax.plt.set_data(x, ychannel) - self.setup(id=id, - nplots=nplots, - wintitle=wintitle, - showprofile=showprofile, - show=show) + self.titles.append("Channel {}: {:4.2f}dB".format(n, numpy.max(ychannel))) - self.tmin, self.tmax = self.getTimeLim(x, xmin, xmax) - if ymin == None: ymin = numpy.nanmin(datadB) - if ymax == None: ymax = numpy.nanmax(datadB) +class RTIHeisPlot(Plot): - self.name = thisDatetime.strftime("%Y%m%d_%H%M%S") - self.isConfig = True - self.figfile = figfile - self.xdata = numpy.array([]) - self.ydata = numpy.array([]) + CODE = 'rti_heis' - self.FTP_WEI = ftp_wei - self.EXP_CODE = exp_code - self.SUB_EXP_CODE = sub_exp_code - self.PLOT_POS = plot_pos + def setup(self): - self.setWinTitle(title) + self.xaxis = 'time' + self.ncols = 1 + self.nrows = 1 + self.nplots = 1 + self.ylabel = 'Intensity [dB]' + self.xlabel = 'Time' + self.titles = ['RTI'] + self.colorbar = False + self.height = 4 + self.plots_adjust.update({'right': 0.85 }) + def update(self, dataOut): -# title = "RTI %s" %(thisDatetime.strftime("%d-%b-%Y")) - title = "RTI - %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) + data = {} + meta = {} + spc = dataOut.data_spc / dataOut.normFactor + spc = 10*numpy.log10(numpy.average(spc, axis=1)) + data['rti_heis'] = spc + + return data, meta - legendlabels = ["channel %d"%idchannel for idchannel in channelList] - axes = self.axesList[0] + def plot(self): - self.xdata = numpy.hstack((self.xdata, x[0:1])) + x = self.data.times + Y = self.data['rti_heis'] - if len(self.ydata)==0: - self.ydata = datadB[channelIndexList].reshape(-1,1) + if self.axes[0].firsttime: + self.ymin = numpy.nanmin(Y) - 5 if self.ymin == None else self.ymin + self.ymax = numpy.nanmax(Y) + 5 if self.ymax == None else self.ymax + for ch in self.data.channels: + y = Y[ch] + self.axes[0].plot(x, y, lw=1, label='Ch{}'.format(ch)) + plt.legend(bbox_to_anchor=(1.18, 1.0)) else: - self.ydata = numpy.hstack((self.ydata, datadB[channelIndexList].reshape(-1,1))) - - - axes.pmultilineyaxis(x=self.xdata, y=self.ydata, - xmin=self.tmin, xmax=self.tmax, ymin=ymin, ymax=ymax, - xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels, marker='.', markersize=8, linestyle="solid", grid='both', - XAxisAsTime=True - ) - - self.draw() - - update_figfile = False - - if dataOut.ltctime >= self.tmax: - self.counter_imagwr = wr_period - self.isConfig = False - update_figfile = True - - self.save(figpath=figpath, - figfile=figfile, - save=save, - ftp=ftp, - wr_period=wr_period, - thisDatetime=thisDatetime, - update_figfile=update_figfile) - - - return dataOut \ No newline at end of file + for ch in self.data.channels: + y = Y[ch] + self.axes[0].lines[ch].set_data(x, y) diff --git a/schainpy/model/graphics/jroplot_parameters.py b/schainpy/model/graphics/jroplot_parameters.py index f2311aa..3f022a0 100644 --- a/schainpy/model/graphics/jroplot_parameters.py +++ b/schainpy/model/graphics/jroplot_parameters.py @@ -47,6 +47,13 @@ class SnrPlot(RTIPlot): CODE = 'snr' colormap = 'jet' + def update(self, dataOut): + + data = { + 'snr': 10*numpy.log10(dataOut.data_snr) + } + + return data, {} class DopplerPlot(RTIPlot): ''' @@ -56,6 +63,13 @@ class DopplerPlot(RTIPlot): CODE = 'dop' colormap = 'jet' + def update(self, dataOut): + + data = { + 'dop': 10*numpy.log10(dataOut.data_dop) + } + + return data, {} class PowerPlot(RTIPlot): ''' @@ -65,6 +79,13 @@ class PowerPlot(RTIPlot): CODE = 'pow' colormap = 'jet' + def update(self, dataOut): + + data = { + 'pow': 10*numpy.log10(dataOut.data_pow) + } + + return data, {} class SpectralWidthPlot(RTIPlot): ''' @@ -74,6 +95,13 @@ class SpectralWidthPlot(RTIPlot): CODE = 'width' colormap = 'jet' + def update(self, dataOut): + + data = { + 'width': dataOut.data_width + } + + return data, {} class SkyMapPlot(Plot): ''' @@ -123,45 +151,45 @@ class SkyMapPlot(Plot): self.titles[0] = title -class ParametersPlot(RTIPlot): +class GenericRTIPlot(Plot): ''' - Plot for data_param object + Plot for data_xxxx object ''' CODE = 'param' - colormap = 'seismic' + colormap = 'viridis' + plot_type = 'pcolorbuffer' def setup(self): self.xaxis = 'time' self.ncols = 1 - self.nrows = self.data.shape(self.CODE)[0] + self.nrows = self.data.shape(self.attr_data)[0] self.nplots = self.nrows self.plots_adjust.update({'hspace':0.8, 'left': 0.1, 'bottom': 0.08, 'right':0.95, 'top': 0.95}) if not self.xlabel: self.xlabel = 'Time' - - if self.showSNR: - self.nrows += 1 - self.nplots += 1 self.ylabel = 'Height [km]' if not self.titles: self.titles = self.data.parameters \ if self.data.parameters else ['Param {}'.format(x) for x in range(self.nrows)] - if self.showSNR: - self.titles.append('SNR') + def update(self, dataOut): + + data = { + self.attr_data : getattr(dataOut, self.attr_data) + } + + meta = {} + + return data, meta + def plot(self): - self.data.normalize_heights() + # self.data.normalize_heights() self.x = self.data.times - self.y = self.data.heights - if self.showSNR: - self.z = numpy.concatenate( - (self.data[self.CODE], self.data['snr']) - ) - else: - self.z = self.data[self.CODE] + self.y = self.data.yrange + self.z = self.data[self.attr_data] self.z = numpy.ma.masked_invalid(self.z) @@ -197,15 +225,6 @@ class ParametersPlot(RTIPlot): ) -class OutputPlot(ParametersPlot): - ''' - Plot data_output object - ''' - - CODE = 'output' - colormap = 'seismic' - - class PolarMapPlot(Plot): ''' Plot for weather radar @@ -251,14 +270,14 @@ class PolarMapPlot(Plot): zeniths = numpy.linspace( 0, self.data.meta['max_range'], data.shape[1]) if self.mode == 'E': - azimuths = -numpy.radians(self.data.heights)+numpy.pi/2 + azimuths = -numpy.radians(self.data.yrange)+numpy.pi/2 r, theta = numpy.meshgrid(zeniths, azimuths) x, y = r*numpy.cos(theta)*numpy.cos(numpy.radians(self.data.meta['elevation'])), r*numpy.sin( theta)*numpy.cos(numpy.radians(self.data.meta['elevation'])) x = km2deg(x) + self.lon y = km2deg(y) + self.lat else: - azimuths = numpy.radians(self.data.heights) + azimuths = numpy.radians(self.data.yrange) r, theta = numpy.meshgrid(zeniths, azimuths) x, y = r*numpy.cos(theta), r*numpy.sin(theta) self.y = zeniths diff --git a/schainpy/model/graphics/jroplot_spectra.py b/schainpy/model/graphics/jroplot_spectra.py index df9ce3b..28b72ec 100644 --- a/schainpy/model/graphics/jroplot_spectra.py +++ b/schainpy/model/graphics/jroplot_spectra.py @@ -1,15 +1,15 @@ -''' -Created on Jul 9, 2014 -Modified on May 10, 2020 +# Copyright (c) 2012-2020 Jicamarca Radio Observatory +# All rights reserved. +# +# Distributed under the terms of the BSD 3-clause license. +"""Classes to plot Spectra data -@author: Juan C. Espinoza -''' +""" import os -import datetime import numpy -from schainpy.model.graphics.jroplot_base import Plot, plt +from schainpy.model.graphics.jroplot_base import Plot, plt, log class SpectraPlot(Plot): @@ -20,6 +20,7 @@ class SpectraPlot(Plot): CODE = 'spc' colormap = 'jet' plot_type = 'pcolor' + buffering = False def setup(self): self.nplots = len(self.data.channels) @@ -34,6 +35,20 @@ class SpectraPlot(Plot): self.plots_adjust.update({'wspace': 0.4, 'hspace':0.4, 'left': 0.1, 'right': 0.9, 'bottom': 0.08}) self.ylabel = 'Range [km]' + def update(self, dataOut): + + data = {} + meta = {} + spc = 10*numpy.log10(dataOut.data_spc/dataOut.normFactor) + data['spc'] = spc + data['rti'] = dataOut.getPower() + data['noise'] = 10*numpy.log10(dataOut.getNoise()/dataOut.normFactor) + meta['xrange'] = (dataOut.getFreqRange(1)/1000., dataOut.getAcfRange(1), dataOut.getVelRange(1)) + if self.CODE == 'spc_moments': + data['moments'] = dataOut.moments + + return data, meta + def plot(self): if self.xaxis == "frequency": x = self.data.xrange[0] @@ -51,14 +66,16 @@ class SpectraPlot(Plot): self.titles = [] - y = self.data.heights + y = self.data.yrange self.y = y - z = self.data['spc'] + + data = self.data[-1] + z = data['spc'] for n, ax in enumerate(self.axes): - noise = self.data['noise'][n][-1] + noise = data['noise'][n] if self.CODE == 'spc_moments': - mean = self.data['moments'][n, :, 1, :][-1] + mean = data['moments'][n, 2] if ax.firsttime: self.xmax = self.xmax if self.xmax else numpy.nanmax(x) self.xmin = self.xmin if self.xmin else -self.xmax @@ -72,7 +89,7 @@ class SpectraPlot(Plot): if self.showprofile: ax.plt_profile = self.pf_axes[n].plot( - self.data['rti'][n][-1], y)[0] + data['rti'][n], y)[0] ax.plt_noise = self.pf_axes[n].plot(numpy.repeat(noise, len(y)), y, color="k", linestyle="dashed", lw=1)[0] if self.CODE == 'spc_moments': @@ -80,7 +97,7 @@ class SpectraPlot(Plot): else: ax.plt.set_array(z[n].T.ravel()) if self.showprofile: - ax.plt_profile.set_data(self.data['rti'][n][-1], y) + ax.plt_profile.set_data(data['rti'][n], y) ax.plt_noise.set_data(numpy.repeat(noise, len(y)), y) if self.CODE == 'spc_moments': ax.plt_mean.set_data(mean, y) @@ -100,14 +117,37 @@ class CrossSpectraPlot(Plot): def setup(self): self.ncols = 4 - self.nrows = len(self.data.pairs) - self.nplots = self.nrows * 4 + self.nplots = len(self.data.pairs) * 2 + self.nrows = int((1.0 * self.nplots / self.ncols) + 0.9) self.width = 3.1 * self.ncols self.height = 2.6 * self.nrows self.ylabel = 'Range [km]' self.showprofile = False self.plots_adjust.update({'left': 0.08, 'right': 0.92, 'wspace': 0.5, 'hspace':0.4, 'top':0.95, 'bottom': 0.08}) + def update(self, dataOut): + + data = {} + meta = {} + + spc = dataOut.data_spc + cspc = dataOut.data_cspc + meta['xrange'] = (dataOut.getFreqRange(1)/1000., dataOut.getAcfRange(1), dataOut.getVelRange(1)) + meta['pairs'] = dataOut.pairsList + + tmp = [] + + for n, pair in enumerate(meta['pairs']): + out = cspc[n] / numpy.sqrt(spc[pair[0]] * spc[pair[1]]) + coh = numpy.abs(out) + phase = numpy.arctan2(out.imag, out.real) * 180 / numpy.pi + tmp.append(coh) + tmp.append(phase) + + data['cspc'] = numpy.array(tmp) + + return data, meta + def plot(self): if self.xaxis == "frequency": @@ -122,46 +162,17 @@ class CrossSpectraPlot(Plot): self.titles = [] - y = self.data.heights + y = self.data.yrange self.y = y - nspc = self.data['spc'] - spc = self.data['cspc'][0] - cspc = self.data['cspc'][1] - for n in range(self.nrows): - noise = self.data['noise'][:,-1] - pair = self.data.pairs[n] - ax = self.axes[4 * n] - if ax.firsttime: - self.xmax = self.xmax if self.xmax else numpy.nanmax(x) - self.xmin = self.xmin if self.xmin else -self.xmax - self.zmin = self.zmin if self.zmin else numpy.nanmin(nspc) - self.zmax = self.zmax if self.zmax else numpy.nanmax(nspc) - ax.plt = ax.pcolormesh(x , y , nspc[pair[0]].T, - vmin=self.zmin, - vmax=self.zmax, - cmap=plt.get_cmap(self.colormap) - ) - else: - ax.plt.set_array(nspc[pair[0]].T.ravel()) - self.titles.append('CH {}: {:3.2f}dB'.format(pair[0], noise[pair[0]])) - - ax = self.axes[4 * n + 1] - if ax.firsttime: - ax.plt = ax.pcolormesh(x , y, nspc[pair[1]].T, - vmin=self.zmin, - vmax=self.zmax, - cmap=plt.get_cmap(self.colormap) - ) - else: - ax.plt.set_array(nspc[pair[1]].T.ravel()) - self.titles.append('CH {}: {:3.2f}dB'.format(pair[1], noise[pair[1]])) - - out = cspc[n] / numpy.sqrt(spc[pair[0]] * spc[pair[1]]) - coh = numpy.abs(out) - phase = numpy.arctan2(out.imag, out.real) * 180 / numpy.pi + data = self.data[-1] + cspc = data['cspc'] - ax = self.axes[4 * n + 2] + for n in range(len(self.data.pairs)): + pair = self.data.pairs[n] + coh = cspc[n*2] + phase = cspc[n*2+1] + ax = self.axes[2 * n] if ax.firsttime: ax.plt = ax.pcolormesh(x, y, coh.T, vmin=0, @@ -173,7 +184,7 @@ class CrossSpectraPlot(Plot): self.titles.append( 'Coherence Ch{} * Ch{}'.format(pair[0], pair[1])) - ax = self.axes[4 * n + 3] + ax = self.axes[2 * n + 1] if ax.firsttime: ax.plt = ax.pcolormesh(x, y, phase.T, vmin=-180, @@ -206,9 +217,18 @@ class RTIPlot(Plot): self.titles = ['{} Channel {}'.format( self.CODE.upper(), x) for x in range(self.nrows)] + def update(self, dataOut): + + data = {} + meta = {} + data['rti'] = dataOut.getPower() + data['noise'] = 10*numpy.log10(dataOut.getNoise()/dataOut.normFactor) + + return data, meta + def plot(self): self.x = self.data.times - self.y = self.data.heights + self.y = self.data.yrange self.z = self.data[self.CODE] self.z = numpy.ma.masked_invalid(self.z) @@ -220,6 +240,7 @@ class RTIPlot(Plot): for n, ax in enumerate(self.axes): self.zmin = self.zmin if self.zmin else numpy.min(self.z) self.zmax = self.zmax if self.zmax else numpy.max(self.z) + data = self.data[-1] if ax.firsttime: ax.plt = ax.pcolormesh(x, y, z[n].T, vmin=self.zmin, @@ -228,8 +249,8 @@ class RTIPlot(Plot): ) if self.showprofile: ax.plot_profile = self.pf_axes[n].plot( - self.data['rti'][n][-1], self.y)[0] - ax.plot_noise = self.pf_axes[n].plot(numpy.repeat(self.data['noise'][n][-1], len(self.y)), self.y, + data['rti'][n], self.y)[0] + ax.plot_noise = self.pf_axes[n].plot(numpy.repeat(data['noise'][n], len(self.y)), self.y, color="k", linestyle="dashed", lw=1)[0] else: ax.collections.remove(ax.collections[0]) @@ -239,9 +260,9 @@ class RTIPlot(Plot): cmap=plt.get_cmap(self.colormap) ) if self.showprofile: - ax.plot_profile.set_data(self.data['rti'][n][-1], self.y) + ax.plot_profile.set_data(data['rti'][n], self.y) ax.plot_noise.set_data(numpy.repeat( - self.data['noise'][n][-1], len(self.y)), self.y) + data['noise'][n], len(self.y)), self.y) class CoherencePlot(RTIPlot): @@ -268,6 +289,14 @@ class CoherencePlot(RTIPlot): self.titles = [ 'Phase Map Ch{} * Ch{}'.format(x[0], x[1]) for x in self.data.pairs] + def update(self, dataOut): + + data = {} + meta = {} + data['coh'] = dataOut.getCoherence() + meta['pairs'] = dataOut.pairsList + + return data, meta class PhasePlot(CoherencePlot): ''' @@ -277,6 +306,14 @@ class PhasePlot(CoherencePlot): CODE = 'phase' colormap = 'seismic' + def update(self, dataOut): + + data = {} + meta = {} + data['phase'] = dataOut.getCoherence(phase=True) + meta['pairs'] = dataOut.pairsList + + return data, meta class NoisePlot(Plot): ''' @@ -286,7 +323,6 @@ class NoisePlot(Plot): CODE = 'noise' plot_type = 'scatterbuffer' - def setup(self): self.xaxis = 'time' self.ncols = 1 @@ -296,33 +332,41 @@ class NoisePlot(Plot): self.xlabel = 'Time' self.titles = ['Noise'] self.colorbar = False + self.plots_adjust.update({'right': 0.85 }) + + def update(self, dataOut): + + data = {} + meta = {} + data['noise'] = 10*numpy.log10(dataOut.getNoise()/dataOut.normFactor).reshape(dataOut.nChannels, 1) + meta['yrange'] = numpy.array([]) + + return data, meta def plot(self): x = self.data.times xmin = self.data.min_time xmax = xmin + self.xrange * 60 * 60 - Y = self.data[self.CODE] + Y = self.data['noise'] if self.axes[0].firsttime: + self.ymin = numpy.nanmin(Y) - 5 + self.ymax = numpy.nanmax(Y) + 5 for ch in self.data.channels: y = Y[ch] self.axes[0].plot(x, y, lw=1, label='Ch{}'.format(ch)) - plt.legend() + plt.legend(bbox_to_anchor=(1.18, 1.0)) else: for ch in self.data.channels: y = Y[ch] self.axes[0].lines[ch].set_data(x, y) - self.ymin = numpy.nanmin(Y) - 5 - self.ymax = numpy.nanmax(Y) + 5 - - + class PowerProfilePlot(Plot): - CODE = 'spcprofile' + CODE = 'pow_profile' plot_type = 'scatter' - buffering = False def setup(self): @@ -336,12 +380,20 @@ class PowerProfilePlot(Plot): self.titles = ['Power Profile'] self.colorbar = False + def update(self, dataOut): + + data = {} + meta = {} + data[self.CODE] = dataOut.getPower() + + return data, meta + def plot(self): - y = self.data.heights + y = self.data.yrange self.y = y - x = self.data['spcprofile'] + x = self.data[-1][self.CODE] if self.xmin is None: self.xmin = numpy.nanmin(x)*0.9 if self.xmax is None: self.xmax = numpy.nanmax(x)*1.1 @@ -372,6 +424,16 @@ class SpectraCutPlot(Plot): self.colorbar = False self.plots_adjust.update({'left':0.1, 'hspace':0.3, 'right': 0.75, 'bottom':0.08}) + def update(self, dataOut): + + data = {} + meta = {} + spc = 10*numpy.log10(dataOut.data_spc/dataOut.normFactor) + data['spc'] = spc + meta['xrange'] = (dataOut.getFreqRange(1)/1000., dataOut.getAcfRange(1), dataOut.getVelRange(1)) + + return data, meta + def plot(self): if self.xaxis == "frequency": x = self.data.xrange[0][1:] @@ -385,9 +447,8 @@ class SpectraCutPlot(Plot): self.titles = [] - y = self.data.heights - #self.y = y - z = self.data['spc_cut'] + y = self.data.yrange + z = self.data[-1]['spc'] if self.height_index: index = numpy.array(self.height_index) diff --git a/schainpy/model/graphics/jroplot_voltage.py b/schainpy/model/graphics/jroplot_voltage.py index 76287ce..6faf42a 100644 --- a/schainpy/model/graphics/jroplot_voltage.py +++ b/schainpy/model/graphics/jroplot_voltage.py @@ -31,6 +31,27 @@ class ScopePlot(Plot): self.width = 6 self.height = 4 + def update(self, dataOut): + + data = {} + meta = { + 'nProfiles': dataOut.nProfiles, + 'flagDataAsBlock': dataOut.flagDataAsBlock, + 'profileIndex': dataOut.profileIndex, + } + if self.CODE == 'scope': + data[self.CODE] = dataOut.data + elif self.CODE == 'pp_power': + data[self.CODE] = dataOut.dataPP_POWER + elif self.CODE == 'pp_signal': + data[self.CODE] = dataOut.dataPP_POW + elif self.CODE == 'pp_velocity': + data[self.CODE] = dataOut.dataPP_DOP + elif self.CODE == 'pp_specwidth': + data[self.CODE] = dataOut.dataPP_WIDTH + + return data, meta + def plot_iq(self, x, y, channelIndexList, thisDatetime, wintitle): yreal = y[channelIndexList,:].real @@ -41,15 +62,14 @@ class ScopePlot(Plot): self.y = yreal self.x = x - self.xmin = min(x) - self.xmax = max(x) - self.titles[0] = title for i,ax in enumerate(self.axes): title = "Channel %d" %(i) if ax.firsttime: + self.xmin = min(x) + self.xmax = max(x) ax.plt_r = ax.plot(x, yreal[i,:], color='b')[0] ax.plt_i = ax.plot(x, yimag[i,:], color='r')[0] else: @@ -61,24 +81,22 @@ class ScopePlot(Plot): yreal = y.real yreal = 10*numpy.log10(yreal) self.y = yreal - title = wintitle + " Scope: %s" %(thisDatetime.strftime("%d-%b-%Y")) + title = wintitle + " Power: %s" %(thisDatetime.strftime("%d-%b-%Y")) self.xlabel = "Range (Km)" - self.ylabel = "Intensity" - self.xmin = min(x) - self.xmax = max(x) + self.ylabel = "Intensity [dB]" self.titles[0] = title for i,ax in enumerate(self.axes): title = "Channel %d" %(i) - ychannel = yreal[i,:] if ax.firsttime: + self.xmin = min(x) + self.xmax = max(x) ax.plt_r = ax.plot(x, ychannel)[0] else: - #pass ax.plt_r.set_data(x, ychannel) def plot_weatherpower(self, x, y, channelIndexList, thisDatetime, wintitle): @@ -153,16 +171,8 @@ class ScopePlot(Plot): channels = self.data.channels thisDatetime = datetime.datetime.utcfromtimestamp(self.data.times[-1]) - if self.CODE == "pp_power": - scope = self.data['pp_power'] - elif self.CODE == "pp_signal": - scope = self.data["pp_signal"] - elif self.CODE == "pp_velocity": - scope = self.data["pp_velocity"] - elif self.CODE == "pp_specwidth": - scope = self.data["pp_specwidth"] - else: - scope =self.data["scope"] + + scope = self.data[-1][self.CODE] if self.data.flagDataAsBlock: @@ -171,7 +181,7 @@ class ScopePlot(Plot): wintitle1 = " [Profile = %d] " %i if self.CODE =="scope": if self.type == "power": - self.plot_power(self.data.heights, + self.plot_power(self.data.yrange, scope[:,i,:], channels, thisDatetime, @@ -179,21 +189,21 @@ class ScopePlot(Plot): ) if self.type == "iq": - self.plot_iq(self.data.heights, + self.plot_iq(self.data.yrange, scope[:,i,:], channels, thisDatetime, wintitle1 ) if self.CODE=="pp_power": - self.plot_weatherpower(self.data.heights, + self.plot_weatherpower(self.data.yrange, scope[:,i,:], channels, thisDatetime, wintitle ) if self.CODE=="pp_signal": - self.plot_weatherpower(self.data.heights, + self.plot_weatherpower(self.data.yrange, scope[:,i,:], channels, thisDatetime, @@ -201,14 +211,14 @@ class ScopePlot(Plot): ) if self.CODE=="pp_velocity": self.plot_weathervelocity(scope[:,i,:], - self.data.heights, + self.data.yrange, channels, thisDatetime, wintitle ) if self.CODE=="pp_spcwidth": self.plot_weatherspecwidth(scope[:,i,:], - self.data.heights, + self.data.yrange, channels, thisDatetime, wintitle @@ -217,7 +227,7 @@ class ScopePlot(Plot): wintitle = " [Profile = %d] " %self.data.profileIndex if self.CODE== "scope": if self.type == "power": - self.plot_power(self.data.heights, + self.plot_power(self.data.yrange, scope, channels, thisDatetime, @@ -225,21 +235,21 @@ class ScopePlot(Plot): ) if self.type == "iq": - self.plot_iq(self.data.heights, + self.plot_iq(self.data.yrange, scope, channels, thisDatetime, wintitle ) if self.CODE=="pp_power": - self.plot_weatherpower(self.data.heights, + self.plot_weatherpower(self.data.yrange, scope, channels, thisDatetime, wintitle ) if self.CODE=="pp_signal": - self.plot_weatherpower(self.data.heights, + self.plot_weatherpower(self.data.yrange, scope, channels, thisDatetime, @@ -247,21 +257,20 @@ class ScopePlot(Plot): ) if self.CODE=="pp_velocity": self.plot_weathervelocity(scope, - self.data.heights, + self.data.yrange, channels, thisDatetime, wintitle ) if self.CODE=="pp_specwidth": self.plot_weatherspecwidth(scope, - self.data.heights, + self.data.yrange, channels, thisDatetime, wintitle ) - class PulsepairPowerPlot(ScopePlot): ''' Plot for P= S+N @@ -269,7 +278,6 @@ class PulsepairPowerPlot(ScopePlot): CODE = 'pp_power' plot_type = 'scatter' - buffering = False class PulsepairVelocityPlot(ScopePlot): ''' @@ -277,7 +285,6 @@ class PulsepairVelocityPlot(ScopePlot): ''' CODE = 'pp_velocity' plot_type = 'scatter' - buffering = False class PulsepairSpecwidthPlot(ScopePlot): ''' @@ -285,7 +292,6 @@ class PulsepairSpecwidthPlot(ScopePlot): ''' CODE = 'pp_specwidth' plot_type = 'scatter' - buffering = False class PulsepairSignalPlot(ScopePlot): ''' @@ -294,4 +300,3 @@ class PulsepairSignalPlot(ScopePlot): CODE = 'pp_signal' plot_type = 'scatter' - buffering = False diff --git a/schainpy/model/io/bltrIO_param.py b/schainpy/model/io/bltrIO_param.py index e253d7d..3adb361 100644 --- a/schainpy/model/io/bltrIO_param.py +++ b/schainpy/model/io/bltrIO_param.py @@ -304,7 +304,7 @@ class BLTRParamReader(Reader, ProcessingUnit): Storing data from databuffer to dataOut object ''' - self.dataOut.data_SNR = self.snr + self.dataOut.data_snr = self.snr self.dataOut.height = self.height self.dataOut.data = self.buffer self.dataOut.utctimeInit = self.time diff --git a/schainpy/model/io/jroIO_param.py b/schainpy/model/io/jroIO_param.py index 1eaa55b..4733785 100644 --- a/schainpy/model/io/jroIO_param.py +++ b/schainpy/model/io/jroIO_param.py @@ -618,8 +618,9 @@ class HDFWriter(Operation): for ds in self.ds: ds.resize(self.blockIndex, axis=0) - self.fp.flush() - self.fp.close() + if self.fp: + self.fp.flush() + self.fp.close() def close(self): diff --git a/schainpy/model/io/julIO_param.py b/schainpy/model/io/julIO_param.py index 4e019ca..b0d5bba 100644 --- a/schainpy/model/io/julIO_param.py +++ b/schainpy/model/io/julIO_param.py @@ -313,7 +313,7 @@ class JULIAParamReader(JRODataReader, ProcessingUnit): Storing data from databuffer to dataOut object ''' - self.dataOut.data_SNR = self.buffer[4].reshape(1, -1) + self.dataOut.data_snr = self.buffer[4].reshape(1, -1) self.dataOut.heightList = self.heights self.dataOut.data_param = self.buffer[0:4,] self.dataOut.utctimeInit = self.time diff --git a/schainpy/model/proc/bltrproc_parameters.py b/schainpy/model/proc/bltrproc_parameters.py index a4d4b98..3cc948c 100644 --- a/schainpy/model/proc/bltrproc_parameters.py +++ b/schainpy/model/proc/bltrproc_parameters.py @@ -25,7 +25,7 @@ class BLTRParametersProc(ProcessingUnit): self.dataOut.nchannels - Number of channels self.dataOut.nranges - Number of ranges - self.dataOut.data_SNR - SNR array + self.dataOut.data_snr - SNR array self.dataOut.data_output - Zonal, Vertical and Meridional velocity array self.dataOut.height - Height array (km) self.dataOut.time - Time array (seconds) @@ -67,10 +67,10 @@ class BLTRParametersProc(ProcessingUnit): self.dataOut.data_param = self.dataOut.data[mode] self.dataOut.heightList = self.dataOut.height[0] - self.dataOut.data_SNR = self.dataOut.data_SNR[mode] + self.dataOut.data_snr = self.dataOut.data_snr[mode] if snr_threshold is not None: - SNRavg = numpy.average(self.dataOut.data_SNR, axis=0) + SNRavg = numpy.average(self.dataOut.data_snr, axis=0) SNRavgdB = 10*numpy.log10(SNRavg) for i in range(3): self.dataOut.data_param[i][SNRavgdB <= snr_threshold] = numpy.nan diff --git a/schainpy/model/proc/jroproc_parameters.py b/schainpy/model/proc/jroproc_parameters.py index aa781a6..bfbd2a7 100755 --- a/schainpy/model/proc/jroproc_parameters.py +++ b/schainpy/model/proc/jroproc_parameters.py @@ -174,7 +174,7 @@ class ParametersProc(ProcessingUnit): self.dataOut.abscissaList = self.dataIn.lagRange self.dataOut.noise = self.dataIn.noise - self.dataOut.data_SNR = self.dataIn.SNR + self.dataOut.data_snr = self.dataIn.SNR self.dataOut.flagNoData = False self.dataOut.nAvg = self.dataIn.nAvg @@ -840,9 +840,9 @@ class FullSpectralAnalysis(Operation): data_SNR=numpy.zeros([nProfiles]) noise = dataOut.noise - dataOut.data_SNR = (numpy.mean(SNRspc,axis=1)- noise[0]) / noise[0] + dataOut.data_snr = (numpy.mean(SNRspc,axis=1)- noise[0]) / noise[0] - dataOut.data_SNR[numpy.where( dataOut.data_SNR <0 )] = 1e-20 + dataOut.data_snr[numpy.where( dataOut.data_snr <0 )] = 1e-20 data_output=numpy.ones([spc.shape[0],spc.shape[2]])*numpy.NaN @@ -851,7 +851,7 @@ class FullSpectralAnalysis(Operation): velocityY=[] velocityV=[] - dbSNR = 10*numpy.log10(dataOut.data_SNR) + dbSNR = 10*numpy.log10(dataOut.data_snr) dbSNR = numpy.average(dbSNR,0) '''***********************************************WIND ESTIMATION**************************************''' @@ -1290,7 +1290,7 @@ class SpectralMoments(Operation): Affected: self.dataOut.moments : Parameters per channel - self.dataOut.data_SNR : SNR per channel + self.dataOut.data_snr : SNR per channel ''' @@ -1306,10 +1306,10 @@ class SpectralMoments(Operation): data_param[ind,:,:] = self.__calculateMoments( data[ind,:,:] , absc , noise[ind] ) dataOut.moments = data_param[:,1:,:] - dataOut.data_SNR = data_param[:,0] - dataOut.data_POW = data_param[:,1] - dataOut.data_DOP = data_param[:,2] - dataOut.data_WIDTH = data_param[:,3] + dataOut.data_snr = data_param[:,0] + dataOut.data_pow = data_param[:,1] + dataOut.data_dop = data_param[:,2] + dataOut.data_width = data_param[:,3] return dataOut @@ -1436,7 +1436,7 @@ class SALags(Operation): self.dataOut.abscissaList self.dataOut.noise self.dataOut.normFactor - self.dataOut.data_SNR + self.dataOut.data_snr self.dataOut.groupList self.dataOut.nChannels @@ -1455,7 +1455,7 @@ class SALags(Operation): nHeights = dataOut.nHeights absc = dataOut.abscissaList noise = dataOut.noise - SNR = dataOut.data_SNR + SNR = dataOut.data_snr nChannels = dataOut.nChannels # pairsList = dataOut.groupList # pairsAutoCorr, pairsCrossCorr = self.__getPairsAutoCorr(pairsList, nChannels) @@ -1570,7 +1570,7 @@ class SpectralFitting(Operation): listChannels = groupArray.reshape((groupArray.size)) listChannels.sort() noise = self.dataIn.getNoise() - self.dataOut.data_SNR = self.__getSNR(self.dataIn.data_spc[listChannels,:,:], noise[listChannels]) + self.dataOut.data_snr = self.__getSNR(self.dataIn.data_spc[listChannels,:,:], noise[listChannels]) for i in range(nGroups): coord = groupArray[i,:] @@ -2222,7 +2222,7 @@ class WindProfiler(Operation): absc = dataOut.abscissaList[:-1] # noise = dataOut.noise heightList = dataOut.heightList - SNR = dataOut.data_SNR + SNR = dataOut.data_snr if technique == 'DBS': @@ -2230,7 +2230,7 @@ class WindProfiler(Operation): kwargs['heightList'] = heightList kwargs['SNR'] = SNR - dataOut.data_output, dataOut.heightList, dataOut.data_SNR = self.techniqueDBS(kwargs) #DBS Function + dataOut.data_output, dataOut.heightList, dataOut.data_snr = self.techniqueDBS(kwargs) #DBS Function dataOut.utctimeInit = dataOut.utctime dataOut.outputInterval = dataOut.paramInterval @@ -2424,7 +2424,7 @@ class EWDriftsEstimation(Operation): def run(self, dataOut, zenith, zenithCorrection): heiRang = dataOut.heightList velRadial = dataOut.data_param[:,3,:] - SNR = dataOut.data_SNR + SNR = dataOut.data_snr zenith = numpy.array(zenith) zenith -= zenithCorrection @@ -2445,7 +2445,7 @@ class EWDriftsEstimation(Operation): dataOut.heightList = heiRang1 dataOut.data_output = winds - dataOut.data_SNR = SNR1 + dataOut.data_snr = SNR1 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 db44b3d..fde1262 100644 --- a/schainpy/model/proc/jroproc_spectra.py +++ b/schainpy/model/proc/jroproc_spectra.py @@ -873,4 +873,26 @@ class IncohInt(Operation): dataOut.utctime = avgdatatime dataOut.flagNoData = False - return dataOut \ No newline at end of file + return dataOut + +class dopplerFlip(Operation): + + def run(self, dataOut): + # arreglo 1: (num_chan, num_profiles, num_heights) + self.dataOut = dataOut + # JULIA-oblicua, indice 2 + # arreglo 2: (num_profiles, num_heights) + jspectra = self.dataOut.data_spc[2] + jspectra_tmp = numpy.zeros(jspectra.shape) + num_profiles = jspectra.shape[0] + freq_dc = int(num_profiles / 2) + # Flip con for + for j in range(num_profiles): + jspectra_tmp[num_profiles-j-1]= jspectra[j] + # Intercambio perfil de DC con perfil inmediato anterior + jspectra_tmp[freq_dc-1]= jspectra[freq_dc-1] + jspectra_tmp[freq_dc]= jspectra[freq_dc] + # canal modificado es re-escrito en el arreglo de canales + self.dataOut.data_spc[2] = jspectra_tmp + + return self.dataOut \ No newline at end of file diff --git a/schainpy/model/proc/jroproc_voltage.py b/schainpy/model/proc/jroproc_voltage.py index 7a62196..9c71e4d 100644 --- a/schainpy/model/proc/jroproc_voltage.py +++ b/schainpy/model/proc/jroproc_voltage.py @@ -146,7 +146,7 @@ class selectChannels(Operation): class selectHeights(Operation): - def run(self, dataOut, minHei=None, maxHei=None): + def run(self, dataOut, minHei=None, maxHei=None, minIndex=None, maxIndex=None): """ Selecciona un bloque de datos en base a un grupo de valores de alturas segun el rango minHei <= height <= maxHei @@ -164,34 +164,30 @@ class selectHeights(Operation): self.dataOut = dataOut - if minHei == None: - minHei = self.dataOut.heightList[0] + if minHei and maxHei: - if maxHei == None: - maxHei = self.dataOut.heightList[-1] + if (minHei < self.dataOut.heightList[0]): + minHei = self.dataOut.heightList[0] - if (minHei < self.dataOut.heightList[0]): - minHei = self.dataOut.heightList[0] + if (maxHei > self.dataOut.heightList[-1]): + maxHei = self.dataOut.heightList[-1] - if (maxHei > self.dataOut.heightList[-1]): - maxHei = self.dataOut.heightList[-1] - - minIndex = 0 - maxIndex = 0 - heights = self.dataOut.heightList + minIndex = 0 + maxIndex = 0 + heights = self.dataOut.heightList - inda = numpy.where(heights >= minHei) - indb = numpy.where(heights <= maxHei) + inda = numpy.where(heights >= minHei) + indb = numpy.where(heights <= maxHei) - try: - minIndex = inda[0][0] - except: - minIndex = 0 + try: + minIndex = inda[0][0] + except: + minIndex = 0 - try: - maxIndex = indb[0][-1] - except: - maxIndex = len(heights) + try: + maxIndex = indb[0][-1] + except: + maxIndex = len(heights) self.selectHeightsByIndex(minIndex, maxIndex)