jroplot_heispectra.py
101 lines
| 2.9 KiB
| text/x-python
|
PythonLexer
r1343 | # 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 | ||||
|
r487 | |||
r1343 | """ | |||
|
r897 | |||
r1343 | import numpy | |||
|
r897 | |||
r1343 | from schainpy.model.graphics.jroplot_base import Plot, plt | |||
|
r897 | |||
|
r1191 | |||
r1343 | class SpectraHeisPlot(Plot): | |||
|
r1191 | |||
r1343 | CODE = 'spc_heis' | |||
|
r897 | |||
r1343 | def setup(self): | |||
|
r897 | |||
r1343 | 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 | ||||
|
r897 | |||
r1343 | def update(self, dataOut): | |||
|
r897 | |||
r1343 | data = {} | |||
meta = {} | ||||
spc = 10*numpy.log10(dataOut.data_spc / dataOut.normFactor) | ||||
data['spc_heis'] = spc | ||||
return data, meta | ||||
|
r897 | |||
r1343 | def plot(self): | |||
|
r897 | |||
r1343 | 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 = [] | ||||
|
r897 | |||
r1343 | 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) | ||||
|
r897 | |||
r1343 | self.titles.append("Channel {}: {:4.2f}dB".format(n, numpy.max(ychannel))) | |||
|
r897 | |||
r1343 | class RTIHeisPlot(Plot): | |||
|
r897 | |||
r1343 | CODE = 'rti_heis' | |||
|
r897 | |||
r1343 | def setup(self): | |||
|
r897 | |||
r1343 | 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 }) | ||||
|
r897 | |||
r1343 | def update(self, dataOut): | |||
|
r897 | |||
r1343 | data = {} | |||
meta = {} | ||||
spc = dataOut.data_spc / dataOut.normFactor | ||||
spc = 10*numpy.log10(numpy.average(spc, axis=1)) | ||||
data['rti_heis'] = spc | ||||
return data, meta | ||||
|
r897 | |||
r1343 | def plot(self): | |||
|
r897 | |||
r1343 | x = self.data.times | |||
Y = self.data['rti_heis'] | ||||
|
r897 | |||
r1343 | 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)) | ||||
|
r487 | else: | ||
r1343 | for ch in self.data.channels: | |||
y = Y[ch] | ||||
self.axes[0].lines[ch].set_data(x, y) | ||||