jroplot_data.py
1147 lines
| 39.5 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 | |
r1147 | from matplotlib.patches import Polygon | ||
|
r865 | 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 | |||
|
r1095 | jet_values = matplotlib.pyplot.get_cmap('jet', 100)(numpy.arange(100))[10:90] | |
|
r1080 | blu_values = matplotlib.pyplot.get_cmap( | |
|
r1095 | 'seismic_r', 20)(numpy.arange(20))[10:15] | |
|
r1080 | ncmap = matplotlib.colors.LinearSegmentedColormap.from_list( | |
|
r1095 | 'jro', numpy.vstack((blu_values, jet_values))) | |
r1071 | matplotlib.pyplot.register_cmap(cmap=ncmap) | ||
|
r1004 | ||
|
r1119 | CMAPS = [plt.get_cmap(s) for s in ('jro', 'jet', 'viridis', 'plasma', 'inferno', 'Greys', 'seismic', 'bwr', 'coolwarm')] | |
|
r865 | ||
r1145 | EARTH_RADIUS = 6.3710e3 | ||
r1144 | def ll2xy(lat1, lon1, lat2, lon2): | ||
p = 0.017453292519943295 | |||
a = 0.5 - numpy.cos((lat2 - lat1) * p)/2 + numpy.cos(lat1 * p) * numpy.cos(lat2 * p) * (1 - numpy.cos((lon2 - lon1) * p)) / 2 | |||
r = 12742 * numpy.arcsin(numpy.sqrt(a)) | |||
theta = numpy.arctan2(numpy.sin((lon2-lon1)*p)*numpy.cos(lat2*p), numpy.cos(lat1*p)*numpy.sin(lat2*p)-numpy.sin(lat1*p)*numpy.cos(lat2*p)*numpy.cos((lon2-lon1)*p)) | |||
theta = -theta + numpy.pi/2 | |||
return r*numpy.cos(theta), r*numpy.sin(theta) | |||
|
r1093 | ||
r1145 | def km2deg(km): | ||
''' | |||
Convert distance in km to degrees | |||
''' | |||
return numpy.rad2deg(km/EARTH_RADIUS) | |||
|
r1093 | ||
|
r1089 | def figpause(interval): | |
backend = plt.rcParams['backend'] | |||
if backend in matplotlib.rcsetup.interactive_bk: | |||
figManager = matplotlib._pylab_helpers.Gcf.get_active() | |||
if figManager is not None: | |||
canvas = figManager.canvas | |||
if canvas.figure.stale: | |||
canvas.draw() | |||
r1130 | try: | ||
canvas.start_event_loop(interval) | |||
except: | |||
pass | |||
|
r1089 | return | |
r1128 | def popup(message): | ||
r1130 | ''' | ||
''' | |||
fig = plt.figure(figsize=(12, 8), facecolor='r') | |||
text = '\n'.join([s.strip() for s in message.split(':')]) | |||
fig.text(0.01, 0.5, text, ha='left', va='center', size='20', weight='heavy', color='w') | |||
r1128 | fig.show() | ||
figpause(1000) | |||
r889 | class PlotData(Operation, Process): | ||
|
r1062 | ''' | |
Base class for Schain plotting operations | |||
''' | |||
|
r865 | ||
r889 | CODE = 'Figure' | ||
r922 | colormap = 'jro' | ||
|
r1062 | bgcolor = 'white' | |
|
r1119 | CONFLATE = False | |
|
r865 | __missing = 1E30 | |
|
r1097 | __attrs__ = ['show', 'save', 'xmin', 'xmax', 'ymin', 'ymax', 'zmin', 'zmax', | |
|
r1099 | 'zlimits', 'xlabel', 'ylabel', 'xaxis','cb_label', 'title', | |
'colorbar', 'bgcolor', 'width', 'height', 'localtime', 'oneFigure', | |||
r1137 | 'showprofile', 'decimation', 'ftp'] | ||
|
r1097 | ||
r889 | def __init__(self, **kwargs): | ||
|
r865 | ||
|
r906 | Operation.__init__(self, plot=True, **kwargs) | |
r889 | Process.__init__(self) | ||
r1105 | |||
|
r906 | self.kwargs['code'] = self.CODE | |
r889 | self.mp = False | ||
|
r1062 | self.data = None | |
|
r1080 | self.isConfig = False | |
|
r1062 | 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) | |||
r1137 | self.ftp = kwargs.get('ftp', False) | ||
r889 | 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) | |||
r1137 | self.labels = kwargs.get('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) | |
|
r1080 | self.xmin = kwargs.get('xmin', None) | |
r889 | self.xmax = kwargs.get('xmax', None) | ||
self.xrange = kwargs.get('xrange', 24) | |||
r1137 | self.xscale = kwargs.get('xscale', None) | ||
|
r866 | self.ymin = kwargs.get('ymin', None) | |
self.ymax = kwargs.get('ymax', None) | |||
r1137 | self.yscale = kwargs.get('yscale', None) | ||
|
r1062 | self.xlabel = kwargs.get('xlabel', None) | |
|
r1119 | self.decimation = kwargs.get('decimation', None) | |
|
r1062 | 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]) | |||
r1137 | self.channels = kwargs.get('channels', None) | ||
r1105 | self.titles = kwargs.get('titles', []) | ||
|
r1095 | self.polar = False | |
r1147 | self.grid = kwargs.get('grid', False) | ||
r1091 | |||
|
r1089 | def __fmtTime(self, x, pos): | |
''' | |||
''' | |||
return '{}'.format(self.getDateTime(x).strftime('%H:%M')) | |||
|
r1062 | ||
def __setup(self): | |||
''' | |||
Common setup for all figures, here figures and axes are created | |||
''' | |||
|
r1095 | if self.CODE not in self.data: | |
raise ValueError(log.error('Missing data for {}'.format(self.CODE), | |||
|
r1098 | self.name)) | |
|
r1062 | ||
self.setup() | |||
r1071 | self.time_label = 'LT' if self.localtime else 'UTC' | ||
|
r1089 | if self.data.localtime: | |
|
r1093 | self.getDateTime = datetime.datetime.fromtimestamp | |
|
r1089 | else: | |
|
r1093 | self.getDateTime = datetime.datetime.utcfromtimestamp | |
r1071 | |||
|
r1062 | if self.width is None: | |
self.width = 8 | |||
|
r933 | ||
|
r1062 | self.figures = [] | |
self.axes = [] | |||
self.cb_axes = [] | |||
self.pf_axes = [] | |||
self.cmaps = [] | |||
|
r1080 | size = '15%' if self.ncols == 1 else '30%' | |
pad = '4%' if self.ncols == 1 else '8%' | |||
|
r1062 | ||
if self.oneFigure: | |||
if self.height is None: | |||
|
r1080 | self.height = 1.4 * self.nrows + 1 | |
|
r1062 | fig = plt.figure(figsize=(self.width, self.height), | |
edgecolor='k', | |||
facecolor='w') | |||
self.figures.append(fig) | |||
|
r1080 | for n in range(self.nplots): | |
|
r1098 | ax = fig.add_subplot(self.nrows, self.ncols, | |
n + 1, polar=self.polar) | |||
|
r1062 | ax.tick_params(labelsize=8) | |
ax.firsttime = True | |||
r1071 | ax.index = 0 | ||
|
r1087 | ax.press = None | |
|
r1093 | self.axes.append(ax) | |
|
r1062 | if self.showprofile: | |
cax = self.__add_axes(ax, size=size, pad=pad) | |||
|
r1080 | cax.tick_params(labelsize=8) | |
|
r1062 | 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), | |||
|
r1080 | edgecolor='k', | |
facecolor='w') | |||
|
r1095 | ax = fig.add_subplot(1, 1, 1, polar=self.polar) | |
|
r1062 | ax.tick_params(labelsize=8) | |
ax.firsttime = True | |||
r1071 | ax.index = 0 | ||
|
r1087 | ax.press = None | |
|
r1093 | self.figures.append(fig) | |
|
r1062 | self.axes.append(ax) | |
if self.showprofile: | |||
cax = self.__add_axes(ax, size=size, pad=pad) | |||
|
r1080 | cax.tick_params(labelsize=8) | |
|
r1062 | self.pf_axes.append(cax) | |
|
r1080 | ||
|
r1062 | for n in range(self.nrows): | |
if self.colormaps is not None: | |||
|
r1080 | cmap = plt.get_cmap(self.colormaps[n]) | |
|
r1062 | else: | |
cmap = plt.get_cmap(self.colormap) | |||
cmap.set_bad(self.bgcolor, 1.) | |||
self.cmaps.append(cmap) | |||
r1071 | for fig in self.figures: | ||
|
r1087 | fig.canvas.mpl_connect('key_press_event', self.OnKeyPress) | |
fig.canvas.mpl_connect('scroll_event', self.OnBtnScroll) | |||
fig.canvas.mpl_connect('button_press_event', self.onBtnPress) | |||
fig.canvas.mpl_connect('motion_notify_event', self.onMotion) | |||
fig.canvas.mpl_connect('button_release_event', self.onBtnRelease) | |||
|
r1089 | if self.show: | |
fig.show() | |||
|
r1087 | ||
def OnKeyPress(self, event): | |||
''' | |||
Event for pressing keys (up, down) change colormap | |||
''' | |||
ax = event.inaxes | |||
|
r1093 | if ax in self.axes: | |
|
r1087 | if event.key == 'down': | |
ax.index += 1 | |||
elif event.key == 'up': | |||
ax.index -= 1 | |||
if ax.index < 0: | |||
|
r1093 | ax.index = len(CMAPS) - 1 | |
|
r1087 | elif ax.index == len(CMAPS): | |
ax.index = 0 | |||
|
r1093 | cmap = CMAPS[ax.index] | |
|
r1087 | ax.cbar.set_cmap(cmap) | |
ax.cbar.draw_all() | |||
|
r1093 | ax.plt.set_cmap(cmap) | |
|
r1087 | ax.cbar.patch.figure.canvas.draw() | |
|
r1089 | self.colormap = cmap.name | |
r1071 | |||
|
r1087 | def OnBtnScroll(self, event): | |
r1071 | ''' | ||
|
r1087 | Event for scrolling, scale figure | |
r1071 | ''' | ||
|
r1087 | cb_ax = event.inaxes | |
r1091 | if cb_ax in [ax.cbar.ax for ax in self.axes if ax.cbar]: | ||
|
r1087 | ax = [ax for ax in self.axes if cb_ax == ax.cbar.ax][0] | |
|
r1093 | pt = ax.cbar.ax.bbox.get_points()[:, 1] | |
|
r1087 | nrm = ax.cbar.norm | |
|
r1093 | vmin, vmax, p0, p1, pS = ( | |
nrm.vmin, nrm.vmax, pt[0], pt[1], event.y) | |||
|
r1087 | scale = 2 if event.step == 1 else 0.5 | |
|
r1093 | point = vmin + (vmax - vmin) / (p1 - p0) * (pS - p0) | |
ax.cbar.norm.vmin = point - scale * (point - vmin) | |||
ax.cbar.norm.vmax = point - scale * (point - vmax) | |||
|
r1087 | ax.plt.set_norm(ax.cbar.norm) | |
ax.cbar.draw_all() | |||
ax.cbar.patch.figure.canvas.draw() | |||
def onBtnPress(self, event): | |||
''' | |||
Event for mouse button press | |||
''' | |||
cb_ax = event.inaxes | |||
if cb_ax is None: | |||
return | |||
r1071 | |||
r1091 | if cb_ax in [ax.cbar.ax for ax in self.axes if ax.cbar]: | ||
|
r1087 | cb_ax.press = event.x, event.y | |
else: | |||
cb_ax.press = None | |||
def onMotion(self, event): | |||
''' | |||
Event for move inside colorbar | |||
''' | |||
cb_ax = event.inaxes | |||
if cb_ax is None: | |||
return | |||
r1091 | if cb_ax not in [ax.cbar.ax for ax in self.axes if ax.cbar]: | ||
|
r1087 | return | |
|
r1093 | if cb_ax.press is None: | |
|
r1087 | return | |
ax = [ax for ax in self.axes if cb_ax == ax.cbar.ax][0] | |||
xprev, yprev = cb_ax.press | |||
dx = event.x - xprev | |||
dy = event.y - yprev | |||
|
r1093 | cb_ax.press = event.x, event.y | |
|
r1087 | scale = ax.cbar.norm.vmax - ax.cbar.norm.vmin | |
perc = 0.03 | |||
if event.button == 1: | |||
|
r1093 | ax.cbar.norm.vmin -= (perc * scale) * numpy.sign(dy) | |
ax.cbar.norm.vmax -= (perc * scale) * numpy.sign(dy) | |||
|
r1087 | elif event.button == 3: | |
|
r1093 | ax.cbar.norm.vmin -= (perc * scale) * numpy.sign(dy) | |
ax.cbar.norm.vmax += (perc * scale) * numpy.sign(dy) | |||
|
r1087 | ||
ax.cbar.draw_all() | |||
ax.plt.set_norm(ax.cbar.norm) | |||
ax.cbar.patch.figure.canvas.draw() | |||
def onBtnRelease(self, event): | |||
''' | |||
Event for mouse button release | |||
''' | |||
cb_ax = event.inaxes | |||
if cb_ax is not None: | |||
cb_ax.press = None | |||
r1071 | |||
|
r1062 | 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) | |||
|
r1080 | ax.figure.add_axes(nax) | |
|
r1062 | return nax | |
|
r964 | ||
r1065 | self.setup() | ||
r922 | |||
|
r1062 | def setup(self): | |
''' | |||
This method should be implemented in the child class, the following | |||
attributes should be set: | |||
|
r1080 | ||
|
r1062 | 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 | |||
''' | |||
|
r1167 | raise NotImplementedError | |
|
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 | ||
|
r1080 | 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, | |
|
r1080 | 0.99 * self.__missing, | |
1.01 * self.__missing) | |||
|
r865 | ||
return x_buffer, y_buffer, z_buffer | |||
|
r866 | def decimate(self): | |
r889 | |||
|
r898 | # dx = int(len(self.x)/self.__MAXNUMX) + 1 | |
|
r1119 | dy = int(len(self.y) / self.decimation) + 1 | |
r889 | |||
|
r898 | # x = self.x[::dx] | |
x = self.x | |||
r889 | y = self.y[::dy] | ||
|
r898 | z = self.z[::, ::, ::dy] | |
|
r1080 | ||
|
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': | |||
|
r1093 | dt = self.getDateTime(self.min_time) | |
xmin = (dt.replace(hour=int(self.xmin), minute=0, second=0) - | |||
datetime.datetime(1970, 1, 1)).total_seconds() | |||
|
r1089 | if self.data.localtime: | |
xmin += time.timezone | |||
|
r1062 | else: | |
xmin = self.xmin | |||
|
r983 | ||
|
r1062 | if self.xmax is None: | |
|
r1080 | xmax = xmin + self.xrange * 60 * 60 | |
|
r1062 | else: | |
if self.xaxis is 'time': | |||
|
r1089 | dt = self.getDateTime(self.max_time) | |
|
r1098 | xmax = (dt.replace(hour=int(self.xmax), minute=59, second=59) - | |
|
r1099 | datetime.datetime(1970, 1, 1) + datetime.timedelta(seconds=1)).total_seconds() | |
|
r1089 | if self.data.localtime: | |
xmax += time.timezone | |||
|
r1062 | else: | |
xmax = self.xmax | |||
|
r1087 | ||
|
r1062 | ymin = self.ymin if self.ymin else numpy.nanmin(self.y) | |
|
r1093 | ymax = self.ymax if self.ymax else numpy.nanmax(self.y) | |
|
r1087 | ||
r1145 | Y = numpy.array([1, 2, 5, 10, 20, 50, 100, 200, 500, 1000, 2000, 5000]) | ||
r1137 | i = 1 if numpy.where(abs(ymax-ymin) <= Y)[0][0] < 0 else numpy.where(abs(ymax-ymin) <= Y)[0][0] | ||
r1147 | ystep = Y[i] / 10. | ||
|
r1062 | ||
|
r1080 | for n, ax in enumerate(self.axes): | |
|
r1062 | if ax.firsttime: | |
ax.set_facecolor(self.bgcolor) | |||
ax.yaxis.set_major_locator(MultipleLocator(ystep)) | |||
r1137 | ax.xaxis.set_major_locator(MultipleLocator(ystep)) | ||
if self.xscale: | |||
ax.xaxis.set_major_formatter(FuncFormatter(lambda x, pos: '{0:g}'.format(x*self.xscale))) | |||
if self.xscale: | |||
ax.yaxis.set_major_formatter(FuncFormatter(lambda x, pos: '{0:g}'.format(x*self.yscale))) | |||
|
r1093 | if self.xaxis is 'time': | |
|
r1089 | ax.xaxis.set_major_formatter(FuncFormatter(self.__fmtTime)) | |
|
r1093 | ax.xaxis.set_major_locator(LinearLocator(9)) | |
|
r1062 | if self.xlabel is not None: | |
ax.set_xlabel(self.xlabel) | |||
|
r1080 | ax.set_ylabel(self.ylabel) | |
|
r1062 | ax.firsttime = False | |
if self.showprofile: | |||
self.pf_axes[n].set_ylim(ymin, ymax) | |||
|
r1080 | self.pf_axes[n].set_xlim(self.zmin, self.zmax) | |
|
r1062 | self.pf_axes[n].set_xlabel('dB') | |
self.pf_axes[n].grid(b=True, axis='x') | |||
|
r1080 | [tick.set_visible(False) | |
for tick in self.pf_axes[n].get_yticklabels()] | |||
|
r1062 | if self.colorbar: | |
|
r1098 | ax.cbar = plt.colorbar( | |
ax.plt, ax=ax, fraction=0.05, pad=0.02, aspect=10) | |||
r1071 | ax.cbar.ax.tick_params(labelsize=8) | ||
|
r1087 | ax.cbar.ax.press = None | |
|
r1062 | if self.cb_label: | |
r1071 | ax.cbar.set_label(self.cb_label, size=8) | ||
|
r1062 | elif self.cb_labels: | |
r1071 | ax.cbar.set_label(self.cb_labels[n], size=8) | ||
r1091 | else: | ||
ax.cbar = None | |||
r1147 | if self.grid: | ||
ax.grid(True) | |||
|
r1080 | ||
|
r1095 | if not self.polar: | |
ax.set_xlim(xmin, xmax) | |||
ax.set_ylim(ymin, ymax) | |||
r1143 | ax.set_title('{} {} {}'.format( | ||
|
r1062 | self.titles[n], | |
r1143 | self.getDateTime(self.max_time).strftime('%Y-%m-%dT%H:%M:%S'), | ||
r1071 | self.time_label), | ||
|
r1098 | size=8) | |
else: | |||
|
r1095 | ax.set_title('{}'.format(self.titles[n]), size=8) | |
ax.set_ylim(0, 90) | |||
ax.set_yticks(numpy.arange(0, 90, 20)) | |||
ax.yaxis.labelpad = 40 | |||
|
r971 | ||
r889 | def __plot(self): | ||
|
r1062 | ''' | |
''' | |||
r1137 | log.log('Plotting', self.name) | ||
|
r1080 | ||
r1121 | try: | ||
self.plot() | |||
self.format() | |||
r1141 | except Exception as e: | ||
r1121 | log.warning('{} Plot could not be updated... check data'.format(self.CODE), self.name) | ||
r1141 | log.error(str(e), '') | ||
return | |||
|
r1080 | ||
|
r1062 | for n, fig in enumerate(self.figures): | |
if self.nrows == 0 or self.nplots == 0: | |||
log.warning('No data', self.name) | |||
|
r1095 | fig.text(0.5, 0.5, 'No Data', fontsize='large', ha='center') | |
|
r1099 | fig.canvas.manager.set_window_title(self.CODE) | |
|
r1093 | continue | |
|
r1062 | fig.tight_layout() | |
|
r1093 | fig.canvas.manager.set_window_title('{} - {}'.format(self.title, | |
|
r1089 | self.getDateTime(self.max_time).strftime('%Y/%m/%d'))) | |
r1105 | fig.canvas.draw() | ||
|
r1080 | ||
r1137 | if self.save and (self.data.ended or not self.data.buffering): | ||
r1141 | if self.save_labels: | ||
labels = self.save_labels | |||
r1137 | else: | ||
|
r1167 | labels = list(range(self.nrows)) | |
r1137 | |||
|
r1062 | if self.oneFigure: | |
label = '' | |||
else: | |||
r1137 | label = '-{}'.format(labels[n]) | ||
|
r1062 | figname = os.path.join( | |
self.save, | |||
r1137 | self.CODE, | ||
|
r1099 | '{}{}_{}.png'.format( | |
|
r1062 | self.CODE, | |
label, | |||
|
r1093 | self.getDateTime(self.saveTime).strftime( | |
r1122 | '%Y%m%d_%H%M%S'), | ||
|
r1062 | ) | |
) | |||
|
r1095 | log.log('Saving figure: {}'.format(figname), self.name) | |
r1137 | if not os.path.isdir(os.path.dirname(figname)): | ||
os.makedirs(os.path.dirname(figname)) | |||
|
r1062 | fig.savefig(figname) | |
|
r866 | ||
r889 | def plot(self): | ||
|
r1062 | ''' | |
''' | |||
|
r1167 | raise NotImplementedError | |
|
r866 | ||
r889 | def run(self): | ||
|
r866 | ||
r1137 | log.log('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']: | |
|
r1080 | receiver.connect( | |
'ipc:///tmp/{}.plots'.format(self.kwargs['parent']['server'])) | |||
|
r937 | else: | |
|
r1080 | receiver.connect("ipc:///tmp/zmq.plots") | |
|
r938 | ||
r889 | while True: | ||
try: | |||
r1071 | self.data = receiver.recv_pyobj(flags=zmq.NOBLOCK) | ||
|
r1089 | if self.data.localtime and self.localtime: | |
self.times = self.data.times | |||
elif self.data.localtime and not self.localtime: | |||
self.times = self.data.times + time.timezone | |||
elif not self.data.localtime and self.localtime: | |||
r1071 | self.times = self.data.times - time.timezone | ||
else: | |||
self.times = self.data.times | |||
|
r1089 | ||
r1071 | self.min_time = self.times[0] | ||
self.max_time = self.times[-1] | |||
|
r866 | ||
r889 | if self.isConfig is False: | ||
|
r1062 | self.__setup() | |
r889 | self.isConfig = True | ||
|
r1080 | ||
|
r1062 | self.__plot() | |
r889 | |||
except zmq.Again as e: | |||
|
r1163 | if self.data and self.data.ended: | |
break | |||
|
r1062 | log.log('Waiting for data...') | |
if self.data: | |||
|
r1089 | figpause(self.data.throttle) | |
|
r1062 | else: | |
time.sleep(2) | |||
|
r866 | ||
def close(self): | |||
|
r1062 | if self.data: | |
r922 | self.__plot() | ||
r889 | |||
|
r1080 | ||
|
r866 | class PlotSpectraData(PlotData): | |
|
r1062 | ''' | |
Plot for Spectra data | |||
''' | |||
|
r866 | ||
r889 | CODE = 'spc' | ||
|
r1080 | colormap = 'jro' | |
r922 | |||
r889 | def setup(self): | ||
|
r1062 | self.nplots = len(self.data.channels) | |
|
r1080 | 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 | |||
|
r1062 | self.cb_label = 'dB' | |
|
r1080 | if self.showprofile: | |
self.width += 0.8 * self.ncols | |||
r889 | |||
r1122 | self.ylabel = 'Range [km]' | ||
r889 | |||
|
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'] | |||
|
r1080 | ||
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, | |||
|
r1080 | vmin=self.zmin, | |
vmax=self.zmax, | |||
cmap=plt.get_cmap(self.colormap) | |||
) | |||
r889 | |||
if self.showprofile: | |||
|
r1080 | ax.plt_profile = self.pf_axes[n].plot( | |
self.data['rti'][n][-1], y)[0] | |||
|
r1062 | ax.plt_noise = self.pf_axes[n].plot(numpy.repeat(noise, len(y)), y, | |
|
r1080 | color="k", linestyle="dashed", lw=1)[0] | |
|
r1062 | 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 | |||
|
r1080 | zmax_phase = None | |
r922 | |||
def setup(self): | |||
|
r1062 | self.ncols = 4 | |
self.nrows = len(self.data.pairs) | |||
|
r1080 | self.nplots = self.nrows * 4 | |
self.width = 3.4 * self.ncols | |||
self.height = 3 * self.nrows | |||
r1122 | self.ylabel = 'Range [km]' | ||
|
r1080 | 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] | |||
|
r1080 | 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) | |
|
r1080 | self.zmax = self.zmax if self.zmax else numpy.nanmax(spc) | |
|
r1062 | ax.plt = ax.pcolormesh(x, y, spc[pair[0]].T, | |
vmin=self.zmin, | |||
vmax=self.zmax, | |||
cmap=plt.get_cmap(self.colormap) | |||
|
r1080 | ) | |
r922 | else: | ||
|
r1062 | ax.plt.set_array(spc[pair[0]].T.ravel()) | |
self.titles.append('CH {}: {:3.2f}dB'.format(n, noise)) | |||
r922 | |||
|
r1080 | ax = self.axes[4 * n + 1] | |
if ax.firsttime: | |||
|
r1062 | 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)) | |||
|
r1080 | out = cspc[n] / numpy.sqrt(spc[pair[0]] * spc[pair[1]]) | |
|
r1062 | coh = numpy.abs(out) | |
|
r1080 | phase = numpy.arctan2(out.imag, out.real) * 180 / numpy.pi | |
ax = self.axes[4 * n + 2] | |||
if ax.firsttime: | |||
|
r1062 | 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()) | |||
|
r1080 | self.titles.append( | |
'Coherence Ch{} * Ch{}'.format(pair[0], pair[1])) | |||
r922 | |||
|
r1080 | ax = self.axes[4 * n + 3] | |
|
r1062 | 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])) | |||
|
r1080 | ||
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' | |
|
r1080 | self.ncols = 1 | |
|
r1062 | self.nrows = len(self.data.channels) | |
self.nplots = len(self.data.channels) | |||
r1122 | self.ylabel = 'Range [km]' | ||
|
r1062 | self.cb_label = 'dB' | |
|
r1080 | self.titles = ['{} Channel {}'.format( | |
self.CODE.upper(), x) for x in range(self.nrows)] | |||
r922 | |||
|
r866 | def plot(self): | |
r1071 | self.x = self.times | ||
|
r1062 | self.y = self.data.heights | |
self.z = self.data[self.CODE] | |||
self.z = numpy.ma.masked_invalid(self.z) | |||
|
r865 | ||
|
r1119 | if self.decimation is None: | |
x, y, z = self.fill_gaps(self.x, self.y, self.z) | |||
else: | |||
|
r1080 | x, y, z = self.fill_gaps(*self.decimate()) | |
|
r1119 | ||
for n, ax in enumerate(self.axes): | |||
|
r1062 | self.zmin = self.zmin if self.zmin else numpy.min(self.z) | |
self.zmax = self.zmax if self.zmax else numpy.max(self.z) | |||
|
r1080 | if ax.firsttime: | |
|
r1062 | ax.plt = ax.pcolormesh(x, y, z[n].T, | |
|
r1080 | vmin=self.zmin, | |
vmax=self.zmax, | |||
cmap=plt.get_cmap(self.colormap) | |||
) | |||
|
r1062 | if self.showprofile: | |
|
r1080 | ax.plot_profile = self.pf_axes[n].plot( | |
self.data['rti'][n][-1], self.y)[0] | |||
|
r1062 | 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) | |||
|
r1080 | ) | |
|
r1062 | if self.showprofile: | |
ax.plot_profile.set_data(self.data['rti'][n][-1], self.y) | |||
|
r1080 | ax.plot_noise.set_data(numpy.repeat( | |
self.data['noise'][n][-1], len(self.y)), self.y) | |||
|
r964 | ||
|
r1080 | 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) | |||
r1122 | self.ylabel = 'Range [km]' | ||
|
r1062 | if self.CODE == 'coh': | |
self.cb_label = '' | |||
|
r1080 | self.titles = [ | |
'Coherence Map Ch{} * Ch{}'.format(x[0], x[1]) for x in self.data.pairs] | |||
r889 | else: | ||
|
r1062 | self.cb_label = 'Degrees' | |
|
r1080 | 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): | |||
r1071 | x = self.times | ||
r907 | xmin = self.min_time | ||
|
r1080 | xmax = xmin + self.xrange * 60 * 60 | |
|
r1062 | Y = self.data[self.CODE] | |
|
r1080 | ||
|
r1062 | 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) | |||
|
r1080 | ||
|
r1062 | 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 | ||
|
r1095 | CODE = 'param' | |
|
r937 | ||
def setup(self): | |||
self.ncols = 1 | |||
self.nrows = 1 | |||
self.width = 7.2 | |||
self.height = 7.2 | |||
|
r1095 | self.nplots = 1 | |
|
r937 | self.xlabel = 'Zonal Zenith Angle (deg)' | |
self.ylabel = 'Meridional Zenith Angle (deg)' | |||
|
r1095 | self.polar = True | |
self.ymin = -180 | |||
self.ymax = 180 | |||
self.colorbar = False | |||
|
r937 | ||
def plot(self): | |||
|
r1098 | arrayParameters = numpy.concatenate(self.data['param']) | |
|
r1080 | error = arrayParameters[:, -1] | |
|
r937 | indValid = numpy.where(error == 0)[0] | |
|
r1080 | finalMeteor = arrayParameters[indValid, :] | |
finalAzimuth = finalMeteor[:, 3] | |||
finalZenith = finalMeteor[:, 4] | |||
|
r937 | ||
|
r1080 | x = finalAzimuth * numpy.pi / 180 | |
|
r937 | y = finalZenith | |
|
r1095 | ax = self.axes[0] | |
if ax.firsttime: | |||
|
r1098 | ax.plot = ax.plot(x, y, 'bo', markersize=5)[0] | |
|
r937 | else: | |
|
r1095 | ax.plot.set_data(x, y) | |
|
r937 | ||
|
r1089 | dt1 = self.getDateTime(self.min_time).strftime('%y/%m/%d %H:%M:%S') | |
dt2 = self.getDateTime(self.max_time).strftime('%y/%m/%d %H:%M:%S') | |||
|
r937 | title = 'Meteor Detection Sky Map\n %s - %s \n Number of events: %5.0f\n' % (dt1, | |
dt2, | |||
len(x)) | |||
|
r1095 | self.titles[0] = title | |
|
r937 | self.saveTime = self.max_time | |
|
r1062 | ||
|
r1080 | ||
|
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 | |||
r1065 | self.nplots += 1 | ||
|
r1080 | ||
r1122 | self.ylabel = 'Height [km]' | ||
r1105 | if not self.titles: | ||
self.titles = self.data.parameters \ | |||
|
r1167 | if self.data.parameters else ['Param {}'.format(x) for x in range(self.nrows)] | |
r1105 | if self.showSNR: | ||
self.titles.append('SNR') | |||
|
r1062 | ||
def plot(self): | |||
|
r1080 | self.data.normalize_heights() | |
r1071 | self.x = self.times | ||
|
r1062 | self.y = self.data.heights | |
|
r1080 | if self.showSNR: | |
|
r1062 | 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) | |||
|
r1119 | if self.decimation is None: | |
x, y, z = self.fill_gaps(self.x, self.y, self.z) | |||
else: | |||
|
r1062 | x, y, z = self.fill_gaps(*self.decimate()) | |
|
r1119 | ||
for n, ax in enumerate(self.axes): | |||
|
r1093 | self.zmax = self.zmax if self.zmax is not None else numpy.max( | |
self.z[n]) | |||
self.zmin = self.zmin if self.zmin is not None else numpy.min( | |||
self.z[n]) | |||
|
r1062 | if ax.firsttime: | |
if self.zlimits is not None: | |||
self.zmin, self.zmax = self.zlimits[n] | |||
|
r1093 | ||
ax.plt = ax.pcolormesh(x, y, z[n].T * self.factors[n], | |||
|
r1062 | vmin=self.zmin, | |
vmax=self.zmax, | |||
cmap=self.cmaps[n] | |||
|
r1080 | ) | |
|
r1062 | else: | |
if self.zlimits is not None: | |||
self.zmin, self.zmax = self.zlimits[n] | |||
ax.collections.remove(ax.collections[0]) | |||
|
r1093 | ax.plt = ax.pcolormesh(x, y, z[n].T * self.factors[n], | |
|
r1062 | vmin=self.zmin, | |
vmax=self.zmax, | |||
cmap=self.cmaps[n] | |||
|
r1080 | ) | |
|
r1062 | ||
self.saveTime = self.min_time | |||
|
r1093 | ||
|
r1087 | class PlotOutputData(PlotParamData): | |
|
r1062 | ''' | |
Plot data_output object | |||
''' | |||
CODE = 'output' | |||
r1065 | colormap = 'seismic' | ||
r1137 | |||
class PlotPolarMapData(PlotData): | |||
''' | |||
Plot for meteors detection data | |||
''' | |||
CODE = 'param' | |||
colormap = 'seismic' | |||
def setup(self): | |||
self.ncols = 1 | |||
self.nrows = 1 | |||
self.width = 9 | |||
self.height = 8 | |||
r1145 | self.mode = self.data.meta['mode'] | ||
r1137 | if self.channels is not None: | ||
self.nplots = len(self.channels) | |||
self.nrows = len(self.channels) | |||
else: | |||
self.nplots = self.data.shape(self.CODE)[0] | |||
self.nrows = self.nplots | |||
|
r1167 | self.channels = list(range(self.nplots)) | |
r1145 | if self.mode == 'E': | ||
self.xlabel = 'Longitude' | |||
self.ylabel = 'Latitude' | |||
r1141 | else: | ||
self.xlabel = 'Range (km)' | |||
self.ylabel = 'Height (km)' | |||
r1137 | self.bgcolor = 'white' | ||
r1141 | self.cb_labels = self.data.meta['units'] | ||
r1145 | self.lat = self.data.meta['latitude'] | ||
self.lon = self.data.meta['longitude'] | |||
r1147 | self.xmin, self.xmax = float(km2deg(self.xmin) + self.lon), float(km2deg(self.xmax) + self.lon) | ||
self.ymin, self.ymax = float(km2deg(self.ymin) + self.lat), float(km2deg(self.ymax) + self.lat) | |||
r1145 | # self.polar = True | ||
def plot(self): | |||
r1137 | |||
for n, ax in enumerate(self.axes): | |||
data = self.data['param'][self.channels[n]] | |||
r1141 | zeniths = numpy.linspace(0, self.data.meta['max_range'], data.shape[1]) | ||
r1145 | if self.mode == 'E': | ||
r1141 | azimuths = -numpy.radians(self.data.heights)+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'])) | |||
r1145 | x = km2deg(x) + self.lon | ||
y = km2deg(y) + self.lat | |||
r1141 | else: | ||
azimuths = numpy.radians(self.data.heights) | |||
r, theta = numpy.meshgrid(zeniths, azimuths) | |||
x, y = r*numpy.cos(theta), r*numpy.sin(theta) | |||
r1137 | self.y = zeniths | ||
if ax.firsttime: | |||
if self.zlimits is not None: | |||
self.zmin, self.zmax = self.zlimits[n] | |||
r1141 | ax.plt = ax.pcolormesh(#r, theta, numpy.ma.array(data, mask=numpy.isnan(data)), | ||
x, y, numpy.ma.array(data, mask=numpy.isnan(data)), | |||
r1137 | 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]) | |||
r1141 | ax.plt = ax.pcolormesh(# r, theta, numpy.ma.array(data, mask=numpy.isnan(data)), | ||
x, y, numpy.ma.array(data, mask=numpy.isnan(data)), | |||
r1137 | vmin=self.zmin, | ||
vmax=self.zmax, | |||
cmap=self.cmaps[n]) | |||
r1145 | if self.mode == 'A': | ||
r1141 | continue | ||
r1144 | |||
r1147 | # plot district names | ||
f = open('/data/workspace/schain_scripts/distrito.csv') | |||
r1141 | for line in f: | ||
r1144 | label, lon, lat = [s.strip() for s in line.split(',') if s] | ||
lat = float(lat) | |||
r1145 | lon = float(lon) | ||
r1147 | # ax.plot(lon, lat, '.b', ms=2) | ||
r1145 | ax.text(lon, lat, label.decode('utf8'), ha='center', va='bottom', size='8', color='black') | ||
r1147 | |||
# plot limites | |||
limites =[] | |||
tmp = [] | |||
for line in open('/data/workspace/schain_scripts/lima.csv'): | |||
if '#' in line: | |||
if tmp: | |||
limites.append(tmp) | |||
tmp = [] | |||
continue | |||
values = line.strip().split(',') | |||
tmp.append((float(values[0]), float(values[1]))) | |||
for points in limites: | |||
ax.add_patch(Polygon(points, ec='k', fc='none', ls='--', lw=0.5)) | |||
# plot Cuencas | |||
for cuenca in ('rimac', 'lurin', 'mala', 'chillon', 'chilca', 'chancay-huaral'): | |||
f = open('/data/workspace/schain_scripts/{}.csv'.format(cuenca)) | |||
values = [line.strip().split(',') for line in f] | |||
points = [(float(s[0]), float(s[1])) for s in values] | |||
ax.add_patch(Polygon(points, ec='b', fc='none')) | |||
# plot grid | |||
for r in (15, 30, 45, 60): | |||
ax.add_artist(plt.Circle((self.lon, self.lat), km2deg(r), color='0.6', fill=False, lw=0.2)) | |||
ax.text( | |||
self.lon + (km2deg(r))*numpy.cos(60*numpy.pi/180), | |||
self.lat + (km2deg(r))*numpy.sin(60*numpy.pi/180), | |||
'{}km'.format(r), | |||
ha='center', va='bottom', size='8', color='0.6', weight='heavy') | |||
r1144 | |||
r1145 | if self.mode == 'E': | ||
r1141 | title = 'El={}$^\circ$'.format(self.data.meta['elevation']) | ||
r1145 | label = 'E{:02d}'.format(int(self.data.meta['elevation'])) | ||
r1141 | else: | ||
title = 'Az={}$^\circ$'.format(self.data.meta['azimuth']) | |||
r1145 | label = 'A{:02d}'.format(int(self.data.meta['azimuth'])) | ||
r1141 | |||
self.save_labels = ['{}-{}'.format(lbl, label) for lbl in self.labels] | |||
self.titles = ['{} {}'.format(self.data.parameters[x], title) for x in self.channels] | |||
r1137 | self.saveTime = self.max_time | ||
r1141 | |||
|
r1167 |