jroplot_data.py
781 lines
| 26.1 KiB
| text/x-python
|
PythonLexer
|
r865 | ||
import os | |||
import time | |||
|
r1062 | import glob | |
|
r865 | import datetime | |
|
r1062 | from multiprocessing import Process | |
import zmq | |||
import numpy | |||
|
r927 | import matplotlib | |
|
r865 | import matplotlib.pyplot as plt | |
from mpl_toolkits.axes_grid1 import make_axes_locatable | |||
|
r1062 | from matplotlib.ticker import FuncFormatter, LinearLocator, MultipleLocator | |
|
r865 | ||
from schainpy.model.proc.jroproc_base import Operation | |||
|
r1062 | from schainpy.utils import log | |
r889 | |||
r922 | func = lambda x, pos: ('%s') %(datetime.datetime.fromtimestamp(x).strftime('%H:%M')) | ||
|
r1004 | ||
|
r1062 | d1970 = datetime.datetime(1970, 1, 1) | |
|
r865 | ||
r889 | class PlotData(Operation, Process): | ||
|
r1062 | ''' | |
Base class for Schain plotting operations | |||
''' | |||
|
r865 | ||
r889 | CODE = 'Figure' | ||
r922 | colormap = 'jro' | ||
|
r1062 | bgcolor = 'white' | |
|
r931 | CONFLATE = False | |
|
r865 | __MAXNUMX = 80 | |
__missing = 1E30 | |||
r889 | def __init__(self, **kwargs): | ||
|
r865 | ||
|
r906 | Operation.__init__(self, plot=True, **kwargs) | |
r889 | Process.__init__(self) | ||
|
r906 | self.kwargs['code'] = self.CODE | |
r889 | self.mp = False | ||
|
r1062 | self.data = None | |
self.isConfig = False | |||
self.figures = [] | |||
r889 | self.axes = [] | ||
|
r1062 | self.cb_axes = [] | |
|
r865 | self.localtime = kwargs.pop('localtime', True) | |
r889 | self.show = kwargs.get('show', True) | ||
self.save = kwargs.get('save', False) | |||
self.colormap = kwargs.get('colormap', self.colormap) | |||
r922 | self.colormap_coh = kwargs.get('colormap_coh', 'jet') | ||
self.colormap_phase = kwargs.get('colormap_phase', 'RdBu_r') | |||
|
r1062 | self.colormaps = kwargs.get('colormaps', None) | |
self.bgcolor = kwargs.get('bgcolor', self.bgcolor) | |||
self.showprofile = kwargs.get('showprofile', False) | |||
self.title = kwargs.get('wintitle', self.CODE.upper()) | |||
self.cb_label = kwargs.get('cb_label', None) | |||
self.cb_labels = kwargs.get('cb_labels', None) | |||
r922 | self.xaxis = kwargs.get('xaxis', 'frequency') | ||
|
r865 | self.zmin = kwargs.get('zmin', None) | |
self.zmax = kwargs.get('zmax', None) | |||
|
r1062 | self.zlimits = kwargs.get('zlimits', None) | |
r889 | self.xmin = kwargs.get('xmin', None) | ||
|
r1062 | if self.xmin is not None: | |
self.xmin += 5 | |||
r889 | self.xmax = kwargs.get('xmax', None) | ||
self.xrange = kwargs.get('xrange', 24) | |||
|
r866 | self.ymin = kwargs.get('ymin', None) | |
self.ymax = kwargs.get('ymax', None) | |||
|
r1062 | self.xlabel = kwargs.get('xlabel', None) | |
self.__MAXNUMY = kwargs.get('decimation', 100) | |||
self.showSNR = kwargs.get('showSNR', False) | |||
self.oneFigure = kwargs.get('oneFigure', True) | |||
self.width = kwargs.get('width', None) | |||
self.height = kwargs.get('height', None) | |||
self.colorbar = kwargs.get('colorbar', True) | |||
self.factors = kwargs.get('factors', [1, 1, 1, 1, 1, 1, 1, 1]) | |||
self.titles = ['' for __ in range(16)] | |||
def __setup(self): | |||
''' | |||
Common setup for all figures, here figures and axes are created | |||
''' | |||
self.setup() | |||
if self.width is None: | |||
self.width = 8 | |||
|
r933 | ||
|
r1062 | self.figures = [] | |
self.axes = [] | |||
self.cb_axes = [] | |||
self.pf_axes = [] | |||
self.cmaps = [] | |||
size = '15%' if self.ncols==1 else '30%' | |||
pad = '4%' if self.ncols==1 else '8%' | |||
if self.oneFigure: | |||
if self.height is None: | |||
self.height = 1.4*self.nrows + 1 | |||
fig = plt.figure(figsize=(self.width, self.height), | |||
edgecolor='k', | |||
facecolor='w') | |||
self.figures.append(fig) | |||
for n in range(self.nplots): | |||
ax = fig.add_subplot(self.nrows, self.ncols, n+1) | |||
ax.tick_params(labelsize=8) | |||
ax.firsttime = True | |||
self.axes.append(ax) | |||
if self.showprofile: | |||
cax = self.__add_axes(ax, size=size, pad=pad) | |||
cax.tick_params(labelsize=8) | |||
self.pf_axes.append(cax) | |||
else: | |||
if self.height is None: | |||
self.height = 3 | |||
for n in range(self.nplots): | |||
fig = plt.figure(figsize=(self.width, self.height), | |||
edgecolor='k', | |||
facecolor='w') | |||
ax = fig.add_subplot(1, 1, 1) | |||
ax.tick_params(labelsize=8) | |||
ax.firsttime = True | |||
self.figures.append(fig) | |||
self.axes.append(ax) | |||
if self.showprofile: | |||
cax = self.__add_axes(ax, size=size, pad=pad) | |||
cax.tick_params(labelsize=8) | |||
self.pf_axes.append(cax) | |||
for n in range(self.nrows): | |||
if self.colormaps is not None: | |||
cmap = plt.get_cmap(self.colormaps[n]) | |||
else: | |||
cmap = plt.get_cmap(self.colormap) | |||
cmap.set_bad(self.bgcolor, 1.) | |||
self.cmaps.append(cmap) | |||
def __add_axes(self, ax, size='30%', pad='8%'): | |||
|
r964 | ''' | |
|
r1062 | Add new axes to the given figure | |
|
r964 | ''' | |
|
r1062 | divider = make_axes_locatable(ax) | |
nax = divider.new_horizontal(size=size, pad=pad) | |||
ax.figure.add_axes(nax) | |||
return nax | |||
|
r964 | ||
r922 | |||
|
r1062 | def setup(self): | |
''' | |||
This method should be implemented in the child class, the following | |||
attributes should be set: | |||
self.nrows: number of rows | |||
self.ncols: number of cols | |||
self.nplots: number of plots (channels or pairs) | |||
self.ylabel: label for Y axes | |||
self.titles: list of axes title | |||
''' | |||
raise(NotImplementedError, 'Implement this method in child class') | |||
|
r865 | ||
|
r1062 | def fill_gaps(self, x_buffer, y_buffer, z_buffer): | |
''' | |||
Create a masked array for missing data | |||
''' | |||
|
r865 | if x_buffer.shape[0] < 2: | |
return x_buffer, y_buffer, z_buffer | |||
deltas = x_buffer[1:] - x_buffer[0:-1] | |||
|
r1062 | x_median = numpy.median(deltas) | |
|
r865 | ||
|
r1062 | index = numpy.where(deltas > 5*x_median) | |
|
r865 | ||
if len(index[0]) != 0: | |||
|
r897 | z_buffer[::, index[0], ::] = self.__missing | |
|
r1062 | z_buffer = numpy.ma.masked_inside(z_buffer, | |
|
r865 | 0.99*self.__missing, | |
1.01*self.__missing) | |||
return x_buffer, y_buffer, z_buffer | |||
|
r866 | def decimate(self): | |
r889 | |||
|
r898 | # dx = int(len(self.x)/self.__MAXNUMX) + 1 | |
|
r866 | dy = int(len(self.y)/self.__MAXNUMY) + 1 | |
r889 | |||
|
r898 | # x = self.x[::dx] | |
x = self.x | |||
r889 | y = self.y[::dy] | ||
|
r898 | z = self.z[::, ::, ::dy] | |
|
r1062 | ||
|
r866 | return x, y, z | |
|
r1062 | def format(self): | |
''' | |||
Set min and max values, labels, ticks and titles | |||
''' | |||
|
r983 | ||
|
r1062 | if self.xmin is None: | |
xmin = self.min_time | |||
else: | |||
if self.xaxis is 'time': | |||
dt = datetime.datetime.fromtimestamp(self.min_time) | |||
xmin = (datetime.datetime.combine(dt.date(), | |||
datetime.time(int(self.xmin), 0, 0))-d1970).total_seconds() | |||
else: | |||
xmin = self.xmin | |||
|
r983 | ||
|
r1062 | if self.xmax is None: | |
xmax = xmin+self.xrange*60*60 | |||
else: | |||
if self.xaxis is 'time': | |||
dt = datetime.datetime.fromtimestamp(self.min_time) | |||
xmax = (datetime.datetime.combine(dt.date(), | |||
datetime.time(int(self.xmax), 0, 0))-d1970).total_seconds() | |||
else: | |||
xmax = self.xmax | |||
ymin = self.ymin if self.ymin else numpy.nanmin(self.y) | |||
ymax = self.ymax if self.ymax else numpy.nanmax(self.y) | |||
ystep = 200 if ymax>= 800 else 100 if ymax>=400 else 50 if ymax>=200 else 20 | |||
for n, ax in enumerate(self.axes): | |||
if ax.firsttime: | |||
ax.set_facecolor(self.bgcolor) | |||
ax.yaxis.set_major_locator(MultipleLocator(ystep)) | |||
if self.xaxis is 'time': | |||
ax.xaxis.set_major_formatter(FuncFormatter(func)) | |||
ax.xaxis.set_major_locator(LinearLocator(9)) | |||
if self.xlabel is not None: | |||
ax.set_xlabel(self.xlabel) | |||
ax.set_ylabel(self.ylabel) | |||
ax.firsttime = False | |||
if self.showprofile: | |||
self.pf_axes[n].set_ylim(ymin, ymax) | |||
self.pf_axes[n].set_xlim(self.zmin, self.zmax) | |||
self.pf_axes[n].set_xlabel('dB') | |||
self.pf_axes[n].grid(b=True, axis='x') | |||
[tick.set_visible(False) for tick in self.pf_axes[n].get_yticklabels()] | |||
if self.colorbar: | |||
cb = plt.colorbar(ax.plt, ax=ax, pad=0.02) | |||
cb.ax.tick_params(labelsize=8) | |||
if self.cb_label: | |||
cb.set_label(self.cb_label, size=8) | |||
elif self.cb_labels: | |||
cb.set_label(self.cb_labels[n], size=8) | |||
ax.set_title('{} - {} UTC'.format( | |||
self.titles[n], | |||
datetime.datetime.fromtimestamp(self.max_time).strftime('%H:%M:%S')), | |||
size=8) | |||
ax.set_xlim(xmin, xmax) | |||
ax.set_ylim(ymin, ymax) | |||
|
r971 | ||
r889 | def __plot(self): | ||
|
r1062 | ''' | |
''' | |||
log.success('Plotting', self.name) | |||
self.plot() | |||
self.format() | |||
for n, fig in enumerate(self.figures): | |||
if self.nrows == 0 or self.nplots == 0: | |||
log.warning('No data', self.name) | |||
continue | |||
|
r964 | if self.show: | |
|
r1062 | fig.show() | |
fig.tight_layout() | |||
fig.canvas.manager.set_window_title('{} - {}'.format(self.title, | |||
datetime.datetime.fromtimestamp(self.max_time).strftime('%Y/%m/%d'))) | |||
# fig.canvas.draw() | |||
if self.save and self.data.ended: | |||
channels = range(self.nrows) | |||
if self.oneFigure: | |||
label = '' | |||
else: | |||
label = '_{}'.format(channels[n]) | |||
figname = os.path.join( | |||
self.save, | |||
'{}{}_{}.png'.format( | |||
self.CODE, | |||
label, | |||
datetime.datetime.fromtimestamp(self.saveTime).strftime('%y%m%d_%H%M%S') | |||
) | |||
) | |||
|
r964 | print 'Saving figure: {}'.format(figname) | |
|
r1062 | fig.savefig(figname) | |
|
r866 | ||
r889 | def plot(self): | ||
|
r1062 | ''' | |
''' | |||
raise(NotImplementedError, 'Implement this method in child class') | |||
|
r866 | ||
r889 | def run(self): | ||
|
r866 | ||
|
r1062 | log.success('Starting', self.name) | |
|
r937 | ||
r889 | context = zmq.Context() | ||
receiver = context.socket(zmq.SUB) | |||
receiver.setsockopt(zmq.SUBSCRIBE, '') | |||
|
r897 | receiver.setsockopt(zmq.CONFLATE, self.CONFLATE) | |
|
r962 | ||
|
r937 | if 'server' in self.kwargs['parent']: | |
receiver.connect('ipc:///tmp/{}.plots'.format(self.kwargs['parent']['server'])) | |||
else: | |||
|
r1062 | receiver.connect("ipc:///tmp/zmq.plots") | |
|
r938 | ||
r889 | while True: | ||
try: | |||
|
r1062 | self.data = receiver.recv_pyobj(flags=zmq.NOBLOCK) | |
self.min_time = self.data.times[0] | |||
self.max_time = self.data.times[-1] | |||
|
r866 | ||
r889 | if self.isConfig is False: | ||
|
r1062 | self.__setup() | |
r889 | self.isConfig = True | ||
|
r1062 | ||
self.__plot() | |||
r889 | |||
except zmq.Again as e: | |||
|
r1062 | log.log('Waiting for data...') | |
if self.data: | |||
plt.pause(self.data.throttle) | |||
else: | |||
time.sleep(2) | |||
|
r866 | ||
def close(self): | |||
|
r1062 | if self.data: | |
r922 | self.__plot() | ||
r889 | |||
|
r866 | ||
class PlotSpectraData(PlotData): | |||
|
r1062 | ''' | |
Plot for Spectra data | |||
''' | |||
|
r866 | ||
r889 | CODE = 'spc' | ||
|
r1062 | colormap = 'jro' | |
r922 | |||
r889 | def setup(self): | ||
|
r1062 | 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.width = 3.4*self.ncols | |||
self.height = 3*self.nrows | |||
self.cb_label = 'dB' | |||
if self.showprofile: | |||
self.width += 0.8*self.ncols | |||
r889 | |||
self.ylabel = 'Range [Km]' | |||
|
r865 | def plot(self): | |
r889 | if self.xaxis == "frequency": | ||
|
r1062 | x = self.data.xrange[0] | |
self.xlabel = "Frequency (kHz)" | |||
r889 | elif self.xaxis == "time": | ||
|
r1062 | x = self.data.xrange[1] | |
self.xlabel = "Time (ms)" | |||
r889 | else: | ||
|
r1062 | x = self.data.xrange[2] | |
self.xlabel = "Velocity (m/s)" | |||
if self.CODE == 'spc_mean': | |||
x = self.data.xrange[2] | |||
self.xlabel = "Velocity (m/s)" | |||
r889 | |||
|
r1062 | self.titles = [] | |
r889 | |||
|
r1062 | y = self.data.heights | |
self.y = y | |||
z = self.data['spc'] | |||
r889 | for n, ax in enumerate(self.axes): | ||
|
r1062 | noise = self.data['noise'][n][-1] | |
if self.CODE == 'spc_mean': | |||
mean = self.data['mean'][n][-1] | |||
r889 | if ax.firsttime: | ||
|
r1062 | self.xmax = self.xmax if self.xmax else numpy.nanmax(x) | |
r889 | self.xmin = self.xmin if self.xmin else -self.xmax | ||
|
r1062 | self.zmin = self.zmin if self.zmin else numpy.nanmin(z) | |
self.zmax = self.zmax if self.zmax else numpy.nanmax(z) | |||
ax.plt = ax.pcolormesh(x, y, z[n].T, | |||
vmin=self.zmin, | |||
vmax=self.zmax, | |||
cmap=plt.get_cmap(self.colormap) | |||
) | |||
r889 | |||
if self.showprofile: | |||
|
r1062 | ax.plt_profile= self.pf_axes[n].plot(self.data['rti'][n][-1], 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_mean': | |||
ax.plt_mean = ax.plot(mean, y, color='k')[0] | |||
r889 | else: | ||
|
r1062 | ax.plt.set_array(z[n].T.ravel()) | |
r889 | if self.showprofile: | ||
|
r1062 | ax.plt_profile.set_data(self.data['rti'][n][-1], y) | |
ax.plt_noise.set_data(numpy.repeat(noise, len(y)), y) | |||
if self.CODE == 'spc_mean': | |||
ax.plt_mean.set_data(mean, y) | |||
|
r866 | ||
|
r1062 | self.titles.append('CH {}: {:3.2f}dB'.format(n, noise)) | |
r922 | self.saveTime = self.max_time | ||
class PlotCrossSpectraData(PlotData): | |||
CODE = 'cspc' | |||
zmin_coh = None | |||
zmax_coh = None | |||
zmin_phase = None | |||
|
r1062 | zmax_phase = None | |
r922 | |||
def setup(self): | |||
|
r1062 | self.ncols = 4 | |
self.nrows = len(self.data.pairs) | |||
self.nplots = self.nrows*4 | |||
self.width = 3.4*self.ncols | |||
self.height = 3*self.nrows | |||
r922 | self.ylabel = 'Range [Km]' | ||
|
r1062 | self.showprofile = False | |
r922 | |||
def plot(self): | |||
if self.xaxis == "frequency": | |||
|
r1062 | x = self.data.xrange[0] | |
self.xlabel = "Frequency (kHz)" | |||
r922 | elif self.xaxis == "time": | ||
|
r1062 | x = self.data.xrange[1] | |
self.xlabel = "Time (ms)" | |||
r922 | else: | ||
|
r1062 | x = self.data.xrange[2] | |
self.xlabel = "Velocity (m/s)" | |||
self.titles = [] | |||
r922 | |||
|
r1062 | y = self.data.heights | |
self.y = y | |||
spc = self.data['spc'] | |||
cspc = self.data['cspc'] | |||
r922 | |||
for n in range(self.nrows): | |||
|
r1062 | noise = self.data['noise'][n][-1] | |
pair = self.data.pairs[n] | |||
ax = self.axes[4*n] | |||
ax3 = self.axes[4*n+3] | |||
r922 | if ax.firsttime: | ||
|
r1062 | self.xmax = self.xmax if self.xmax else numpy.nanmax(x) | |
r922 | self.xmin = self.xmin if self.xmin else -self.xmax | ||
|
r1062 | self.zmin = self.zmin if self.zmin else numpy.nanmin(spc) | |
self.zmax = self.zmax if self.zmax else numpy.nanmax(spc) | |||
ax.plt = ax.pcolormesh(x, y, spc[pair[0]].T, | |||
vmin=self.zmin, | |||
vmax=self.zmax, | |||
cmap=plt.get_cmap(self.colormap) | |||
) | |||
r922 | else: | ||
|
r1062 | ax.plt.set_array(spc[pair[0]].T.ravel()) | |
self.titles.append('CH {}: {:3.2f}dB'.format(n, noise)) | |||
r922 | |||
|
r1062 | ax = self.axes[4*n+1] | |
if ax.firsttime: | |||
ax.plt = ax.pcolormesh(x, y, spc[pair[1]].T, | |||
r922 | vmin=self.zmin, | ||
vmax=self.zmax, | |||
cmap=plt.get_cmap(self.colormap) | |||
) | |||
else: | |||
|
r1062 | ax.plt.set_array(spc[pair[1]].T.ravel()) | |
self.titles.append('CH {}: {:3.2f}dB'.format(n, noise)) | |||
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 | |||
ax = self.axes[4*n+2] | |||
if ax.firsttime: | |||
ax.plt = ax.pcolormesh(x, y, coh.T, | |||
vmin=0, | |||
vmax=1, | |||
cmap=plt.get_cmap(self.colormap_coh) | |||
) | |||
else: | |||
ax.plt.set_array(coh.T.ravel()) | |||
self.titles.append('Coherence Ch{} * Ch{}'.format(pair[0], pair[1])) | |||
r922 | |||
|
r1062 | ax = self.axes[4*n+3] | |
if ax.firsttime: | |||
ax.plt = ax.pcolormesh(x, y, phase.T, | |||
vmin=-180, | |||
vmax=180, | |||
cmap=plt.get_cmap(self.colormap_phase) | |||
) | |||
else: | |||
ax.plt.set_array(phase.T.ravel()) | |||
self.titles.append('Phase CH{} * CH{}'.format(pair[0], pair[1])) | |||
r922 | self.saveTime = self.max_time | ||
|
r866 | ||
|
r1062 | class PlotSpectraMeanData(PlotSpectraData): | |
''' | |||
Plot for Spectra and Mean | |||
''' | |||
CODE = 'spc_mean' | |||
colormap = 'jro' | |||
|
r866 | class PlotRTIData(PlotData): | |
|
r1062 | ''' | |
Plot for RTI data | |||
''' | |||
r889 | |||
CODE = 'rti' | |||
colormap = 'jro' | |||
def setup(self): | |||
|
r1062 | self.xaxis = 'time' | |
self.ncols = 1 | |||
self.nrows = len(self.data.channels) | |||
self.nplots = len(self.data.channels) | |||
|
r866 | self.ylabel = 'Range [Km]' | |
|
r1062 | self.cb_label = 'dB' | |
self.titles = ['{} Channel {}'.format(self.CODE.upper(), x) for x in range(self.nrows)] | |||
r922 | |||
|
r866 | def plot(self): | |
|
r1062 | self.x = self.data.times | |
self.y = self.data.heights | |||
self.z = self.data[self.CODE] | |||
self.z = numpy.ma.masked_invalid(self.z) | |||
|
r865 | ||
|
r1062 | for n, ax in enumerate(self.axes): | |
x, y, z = self.fill_gaps(*self.decimate()) | |||
self.zmin = self.zmin if self.zmin else numpy.min(self.z) | |||
self.zmax = self.zmax if self.zmax else numpy.max(self.z) | |||
if ax.firsttime: | |||
ax.plt = ax.pcolormesh(x, y, z[n].T, | |||
vmin=self.zmin, | |||
vmax=self.zmax, | |||
cmap=plt.get_cmap(self.colormap) | |||
) | |||
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, | |||
color="k", linestyle="dashed", lw=1)[0] | |||
else: | |||
ax.collections.remove(ax.collections[0]) | |||
ax.plt = ax.pcolormesh(x, y, z[n].T, | |||
vmin=self.zmin, | |||
vmax=self.zmax, | |||
cmap=plt.get_cmap(self.colormap) | |||
) | |||
if self.showprofile: | |||
ax.plot_profile.set_data(self.data['rti'][n][-1], self.y) | |||
ax.plot_noise.set_data(numpy.repeat(self.data['noise'][n][-1], len(self.y)), self.y) | |||
|
r964 | ||
|
r1062 | self.saveTime = self.min_time | |
r889 | |||
class PlotCOHData(PlotRTIData): | |||
|
r1062 | ''' | |
Plot for Coherence data | |||
''' | |||
r889 | |||
CODE = 'coh' | |||
def setup(self): | |||
|
r1062 | self.xaxis = 'time' | |
r889 | self.ncols = 1 | ||
|
r1062 | self.nrows = len(self.data.pairs) | |
self.nplots = len(self.data.pairs) | |||
self.ylabel = 'Range [Km]' | |||
if self.CODE == 'coh': | |||
self.cb_label = '' | |||
self.titles = ['Coherence Map Ch{} * Ch{}'.format(x[0], x[1]) for x in self.data.pairs] | |||
r889 | else: | ||
|
r1062 | self.cb_label = 'Degrees' | |
self.titles = ['Phase Map Ch{} * Ch{}'.format(x[0], x[1]) for x in self.data.pairs] | |||
r889 | |||
|
r1062 | ||
class PlotPHASEData(PlotCOHData): | |||
''' | |||
Plot for Phase map data | |||
''' | |||
CODE = 'phase' | |||
colormap = 'seismic' | |||
r889 | |||
|
r865 | ||
r907 | class PlotNoiseData(PlotData): | ||
|
r1062 | ''' | |
Plot for noise | |||
''' | |||
r907 | CODE = 'noise' | ||
def setup(self): | |||
|
r1062 | self.xaxis = 'time' | |
r907 | self.ncols = 1 | ||
self.nrows = 1 | |||
|
r1062 | self.nplots = 1 | |
r907 | self.ylabel = 'Intensity [dB]' | ||
self.titles = ['Noise'] | |||
|
r1062 | self.colorbar = False | |
r907 | |||
def plot(self): | |||
|
r1062 | x = self.data.times | |
r907 | xmin = self.min_time | ||
xmax = xmin+self.xrange*60*60 | |||
|
r1062 | Y = self.data[self.CODE] | |
if self.axes[0].firsttime: | |||
for ch in self.data.channels: | |||
y = Y[ch] | |||
self.axes[0].plot(x, y, lw=1, label='Ch{}'.format(ch)) | |||
r907 | plt.legend() | ||
else: | |||
|
r1062 | 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 | |||
r922 | self.saveTime = self.min_time | ||
r907 | |||
class PlotSNRData(PlotRTIData): | |||
|
r1062 | ''' | |
Plot for SNR Data | |||
''' | |||
|
r898 | CODE = 'snr' | |
r922 | colormap = 'jet' | ||
r889 | |||
|
r1062 | ||
|
r898 | class PlotDOPData(PlotRTIData): | |
|
r1062 | ''' | |
Plot for DOPPLER Data | |||
''' | |||
|
r898 | CODE = 'dop' | |
colormap = 'jet' | |||
r889 | |||
r922 | |||
|
r937 | class PlotSkyMapData(PlotData): | |
|
r1062 | ''' | |
Plot for meteors detection data | |||
''' | |||
|
r937 | ||
CODE = 'met' | |||
def setup(self): | |||
self.ncols = 1 | |||
self.nrows = 1 | |||
self.width = 7.2 | |||
self.height = 7.2 | |||
self.xlabel = 'Zonal Zenith Angle (deg)' | |||
self.ylabel = 'Meridional Zenith Angle (deg)' | |||
if self.figure is None: | |||
self.figure = plt.figure(figsize=(self.width, self.height), | |||
edgecolor='k', | |||
facecolor='w') | |||
else: | |||
self.figure.clf() | |||
self.ax = plt.subplot2grid((self.nrows, self.ncols), (0, 0), 1, 1, polar=True) | |||
self.ax.firsttime = True | |||
def plot(self): | |||
|
r1062 | arrayParameters = numpy.concatenate([self.data['param'][t] for t in self.data.times]) | |
|
r937 | error = arrayParameters[:,-1] | |
indValid = numpy.where(error == 0)[0] | |||
finalMeteor = arrayParameters[indValid,:] | |||
finalAzimuth = finalMeteor[:,3] | |||
finalZenith = finalMeteor[:,4] | |||
x = finalAzimuth*numpy.pi/180 | |||
y = finalZenith | |||
if self.ax.firsttime: | |||
self.ax.plot = self.ax.plot(x, y, 'bo', markersize=5)[0] | |||
self.ax.set_ylim(0,90) | |||
self.ax.set_yticks(numpy.arange(0,90,20)) | |||
self.ax.set_xlabel(self.xlabel) | |||
self.ax.set_ylabel(self.ylabel) | |||
self.ax.yaxis.labelpad = 40 | |||
self.ax.firsttime = False | |||
else: | |||
self.ax.plot.set_data(x, y) | |||
dt1 = datetime.datetime.fromtimestamp(self.min_time).strftime('%y/%m/%d %H:%M:%S') | |||
dt2 = datetime.datetime.fromtimestamp(self.max_time).strftime('%y/%m/%d %H:%M:%S') | |||
title = 'Meteor Detection Sky Map\n %s - %s \n Number of events: %5.0f\n' % (dt1, | |||
dt2, | |||
len(x)) | |||
self.ax.set_title(title, size=8) | |||
self.saveTime = self.max_time | |||
|
r1062 | ||
class PlotParamData(PlotRTIData): | |||
''' | |||
Plot for data_param object | |||
''' | |||
CODE = 'param' | |||
colormap = 'seismic' | |||
def setup(self): | |||
self.xaxis = 'time' | |||
self.ncols = 1 | |||
self.nrows = self.data.shape(self.CODE)[0] | |||
self.nplots = self.nrows | |||
if self.showSNR: | |||
self.nrows += 1 | |||
self.ylabel = 'Height [Km]' | |||
self.titles = self.data.parameters \ | |||
if self.data.parameters else ['Param {}'.format(x) for x in xrange(self.nrows)] | |||
if self.showSNR: | |||
self.titles.append('SNR') | |||
def plot(self): | |||
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.z = numpy.ma.masked_invalid(self.z) | |||
for n, ax in enumerate(self.axes): | |||
x, y, z = self.fill_gaps(*self.decimate()) | |||
if ax.firsttime: | |||
if self.zlimits is not None: | |||
self.zmin, self.zmax = self.zlimits[n] | |||
self.zmax = self.zmax if self.zmax is not None else numpy.nanmax(abs(self.z[:-1, :])) | |||
self.zmin = self.zmin if self.zmin is not None else -self.zmax | |||
ax.plt = ax.pcolormesh(x, y, z[n, :, :].T*self.factors[n], | |||
vmin=self.zmin, | |||
vmax=self.zmax, | |||
cmap=self.cmaps[n] | |||
) | |||
else: | |||
if self.zlimits is not None: | |||
self.zmin, self.zmax = self.zlimits[n] | |||
ax.collections.remove(ax.collections[0]) | |||
ax.plt = ax.pcolormesh(x, y, z[n, :, :].T*self.factors[n], | |||
vmin=self.zmin, | |||
vmax=self.zmax, | |||
cmap=self.cmaps[n] | |||
) | |||
self.saveTime = self.min_time | |||
class PlotOuputData(PlotParamData): | |||
''' | |||
Plot data_output object | |||
''' | |||
CODE = 'output' | |||
colormap = 'seismic' |