@@ -17,6 +17,7 d1970 = datetime.datetime(1970,1,1) | |||
|
17 | 17 | |
|
18 | 18 | class PlotData(Operation): |
|
19 | 19 | |
|
20 | __code = 'Figure' | |
|
20 | 21 | __MAXNUMX = 80 |
|
21 | 22 | __MAXNUMY = 80 |
|
22 | 23 | __missing = 1E30 |
@@ -30,11 +31,12 class PlotData(Operation): | |||
|
30 | 31 | self.dataOut = None |
|
31 | 32 | self.isConfig = False |
|
32 | 33 | self.figure = None |
|
34 | self.width = 6 | |
|
35 | self.height = 4 | |
|
33 | 36 | |
|
34 | 37 | def setup(self, dataOut, **kwargs): |
|
35 | 38 | |
|
36 | 39 | self.first = True |
|
37 | self.plottype = kwargs.pop('plottype', 'rti') | |
|
38 | 40 | self.localtime = kwargs.pop('localtime', True) |
|
39 | 41 | self.show = kwargs.pop('show', True) |
|
40 | 42 | self.save = kwargs.pop('save', False) |
@@ -45,7 +47,7 class PlotData(Operation): | |||
|
45 | 47 | self.data = [{} for __ in dataOut.channelList] |
|
46 | 48 | self.axes = [] |
|
47 | 49 | self.colormap = kwargs.get('colormap', 'jet') |
|
48 |
self.title = kwargs.get('wintitle', |
|
|
50 | self.title = kwargs.get('wintitle', '') | |
|
49 | 51 | self.xaxis = kwargs.get('xaxis', None) |
|
50 | 52 | self.zmin = kwargs.get('zmin', None) |
|
51 | 53 | self.zmax = kwargs.get('zmax', None) |
@@ -60,27 +62,23 class PlotData(Operation): | |||
|
60 | 62 | self.xmin = (dtmin-d1970).total_seconds() |
|
61 | 63 | self.xmax = (dtmax-d1970).total_seconds() |
|
62 | 64 | |
|
63 | if self.plottype in ('rti',): | |
|
64 | self.ncols = 1 | |
|
65 | self.nrows = dataOut.nChannels | |
|
66 | self.width = 8 | |
|
67 | self.height = 2.2*self.nrows | |
|
68 | self.ylabel = 'Range [Km]' | |
|
69 | self.y = dataOut.getHeiRange() | |
|
70 | ||
|
71 | self.ymin = kwargs.get('ymin', min(self.y)) | |
|
72 | self.ymax = kwargs.get('ymax', max(self.y)) | |
|
65 | self.ymin = kwargs.get('ymin', None) | |
|
66 | self.ymax = kwargs.get('ymax', None) | |
|
73 | 67 | |
|
74 | 68 | if self.figure is None: |
|
75 | 69 | self.figure = plt.figure() |
|
76 | 70 | else: |
|
77 | 71 | self.figure.clf() |
|
78 | 72 | |
|
73 | self.setup_fig() | |
|
74 | ||
|
79 | 75 | for n in range(dataOut.nChannels): |
|
80 | 76 | ax = self.figure.add_subplot(self.nrows, self.ncols, n+1) |
|
81 | 77 | ax.firsttime = True |
|
82 | 78 | self.axes.append(ax) |
|
83 | 79 | |
|
80 | self.setup_fig() | |
|
81 | ||
|
84 | 82 | self.figure.set_size_inches (self.width, self.height) |
|
85 | 83 | |
|
86 | 84 | def fill_gaps(self, x_buffer, y_buffer, z_buffer): |
@@ -94,24 +92,116 class PlotData(Operation): | |||
|
94 | 92 | index = np.where(deltas > 5*x_median) |
|
95 | 93 | |
|
96 | 94 | if len(index[0]) != 0: |
|
97 | z_buffer[index[0],::] = self.__missing | |
|
95 | z_buffer[::,index[0],::] = self.__missing | |
|
98 | 96 | z_buffer = np.ma.masked_inside(z_buffer, |
|
99 | 97 | 0.99*self.__missing, |
|
100 | 98 | 1.01*self.__missing) |
|
101 | 99 | |
|
102 | 100 | return x_buffer, y_buffer, z_buffer |
|
103 | 101 | |
|
102 | def decimate(self): | |
|
103 | ||
|
104 | dx = int(len(self.x)/self.__MAXNUMX) + 1 | |
|
105 | dy = int(len(self.y)/self.__MAXNUMY) + 1 | |
|
106 | ||
|
107 | x = self.x[::dx] | |
|
108 | y = self.y[::dy] | |
|
109 | z = self.z[::, ::dx, ::dy] | |
|
110 | ||
|
111 | return x, y, z | |
|
112 | ||
|
113 | def _plot(self): | |
|
114 | ||
|
115 | self.plot() | |
|
116 | ||
|
117 | self.figure.suptitle(self.title+self.__code) | |
|
118 | ||
|
119 | if self.save: | |
|
120 | figname = os.path.join(self.save, '{}_{}.png'.format(self.__code, | |
|
121 | self.plot_dt.strftime('%y%m%d_%H%M%S'))) | |
|
122 | print 'Saving figure: {}'.format(figname) | |
|
123 | self.figure.savefig(figname) | |
|
124 | ||
|
125 | self.figure.canvas.draw() | |
|
126 | if self.show: | |
|
127 | self.figure.show() | |
|
128 | if self.pause: | |
|
129 | raw_input('Press <ENTER> to continue') | |
|
130 | ||
|
131 | ||
|
132 | def update(self): | |
|
133 | ||
|
134 | pass | |
|
135 | ||
|
136 | def run(self, dataOut, **kwargs): | |
|
137 | ||
|
138 | self.dataOut = dataOut | |
|
139 | ||
|
140 | if not self.isConfig: | |
|
141 | self.setup(dataOut, **kwargs) | |
|
142 | self.isConfig = True | |
|
143 | ||
|
144 | self.nblock += 1 | |
|
145 | self.update() | |
|
146 | ||
|
147 | if dataOut.ltctime>=self.xmax: | |
|
148 | self._plot() | |
|
149 | self.isConfig = False | |
|
150 | ||
|
151 | def close(self): | |
|
152 | if self.dataOut: | |
|
153 | self._plot() | |
|
154 | ||
|
155 | ||
|
156 | class PlotSpectraData(PlotData): | |
|
157 | ||
|
158 | __code = 'Spectra' | |
|
159 | ||
|
160 | def setup_fig(self): | |
|
161 | pass | |
|
162 | ||
|
163 | def update(self): | |
|
164 | ||
|
165 | for ch in self.dataOut.channelList: | |
|
166 | self.data[ch] = self.dataOut.data_spc[ch] | |
|
167 | ||
|
104 | 168 | def plot(self): |
|
169 | pass | |
|
170 | ||
|
171 | ||
|
172 | class PlotRTIData(PlotData): | |
|
173 | ||
|
174 | __code = 'RTI' | |
|
175 | ||
|
176 | def setup_fig(self): | |
|
177 | ||
|
178 | self.ncols = 1 | |
|
179 | self.nrows = self.dataOut.nChannels | |
|
180 | self.width = 8 | |
|
181 | self.height = 2.2*self.nrows | |
|
182 | self.ylabel = 'Range [Km]' | |
|
183 | ||
|
184 | def update(self): | |
|
185 | ||
|
186 | self.time.append(self.dataOut.ltctime) | |
|
187 | ||
|
188 | for ch in self.dataOut.channelList: | |
|
189 | self.data[ch][self.dataOut.ltctime] = self.dataOut.getPower()[ch] | |
|
190 | ||
|
191 | def plot(self): | |
|
192 | ||
|
193 | self.plot_dt = datetime.datetime.utcfromtimestamp(self.time[-2]) | |
|
105 | 194 | |
|
106 | dt = datetime.datetime.utcfromtimestamp(self.time[-2]) | |
|
195 | self.time.sort() | |
|
196 | self.x = self.time | |
|
197 | self.y = self.dataOut.getHeiRange() | |
|
198 | self.z = [] | |
|
107 | 199 | |
|
108 | if self.plottype=='rti': | |
|
109 | self.time.sort() | |
|
110 | for ch in self.dataOut.channelList: | |
|
111 | self.z.append([self.data[ch][t] for t in self.time]) | |
|
112 |
|
|
|
113 | self.z = np.array(self.z) | |
|
114 | self.plot_rti() | |
|
200 | for ch in self.dataOut.channelList: | |
|
201 | self.z.append([self.data[ch][t] for t in self.time]) | |
|
202 | ||
|
203 | self.x = np.array(self.x) | |
|
204 | self.z = np.array(self.z) | |
|
115 | 205 | |
|
116 | 206 | for n, ax in enumerate(self.axes): |
|
117 | 207 | |
@@ -122,33 +212,25 class PlotData(Operation): | |||
|
122 | 212 | ax.yaxis.set_major_locator(LinearLocator(4)) |
|
123 | 213 | |
|
124 | 214 | ax.set_ylabel(self.ylabel) |
|
125 | ax.set_ylim(self.ymin, self.ymax) | |
|
215 | ||
|
126 | 216 | ax.set_xlim(self.xmin, self.xmax) |
|
127 | 217 | |
|
128 | ax.set_title('Channel {} {}'.format( | |
|
129 |
self. |
|
|
130 | dt.strftime('%y/%m/%d %H:%M:%S'), | |
|
131 | size=6)) | |
|
218 | ax.set_title('Channel {} {}'.format(self.dataOut.channelList[n], | |
|
219 | self.plot_dt.strftime('%y/%m/%d %H:%M:%S')), | |
|
220 | size=8) | |
|
132 | 221 | |
|
133 |
|
|
|
134 | figname = os.path.join(self.save, 'rti_{}.png'.format(dt.strftime('%y%m%d_%H%M%S'))) | |
|
135 | print 'Saving figure: {}'.format(figname) | |
|
136 | self.figure.savefig(figname) | |
|
137 | ||
|
138 | self.figure.canvas.draw() | |
|
139 | if self.show: | |
|
140 | self.figure.show() | |
|
141 | if self.pause: | |
|
142 | raw_input('Press <ENTER> to continue') | |
|
143 | ||
|
144 | def plot_rti(self): | |
|
222 | self.decimate() | |
|
145 | 223 | |
|
146 | 224 | for n, ax in enumerate(self.axes): |
|
147 | x, y, z = self.fill_gaps(self.x, self.y, self.z[n]) | |
|
225 | ||
|
226 | x, y, z = self.fill_gaps(*self.decimate()) | |
|
227 | ||
|
148 | 228 | if ax.firsttime: |
|
229 | ymin = self.ymin if self.ymin else np.nanmin(self.y) | |
|
230 | ymax = self.ymax if self.ymax else np.nanmax(self.y) | |
|
149 | 231 | zmin = self.zmin if self.zmin else np.nanmin(self.z) |
|
150 | 232 | zmax = self.zmax if self.zmax else np.nanmax(self.z) |
|
151 | plot = ax.pcolormesh(x, y, z.T, | |
|
233 | plot = ax.pcolormesh(x, y, z[n].T, | |
|
152 | 234 | vmin=zmin, |
|
153 | 235 | vmax=zmax, |
|
154 | 236 | cmap=plt.get_cmap(self.colormap) |
@@ -157,40 +239,21 class PlotData(Operation): | |||
|
157 | 239 | cax = divider.new_horizontal(size='3%', pad=0.05) |
|
158 | 240 | self.figure.add_axes(cax) |
|
159 | 241 | plt.colorbar(plot, cax) |
|
242 | ax.set_ylim(self.ymin, self.ymax) | |
|
160 | 243 | ax.firsttime = False |
|
161 | 244 | else: |
|
162 |
plot = ax.pcolormesh(x, y, z.T |
|
|
163 | vmin=zmin, | |
|
164 | vmax=zmax, | |
|
165 | cmap=plt.get_cmap(self.colormap) | |
|
166 | ) | |
|
245 | plot = ax.pcolormesh(x, y, z[n].T) | |
|
167 | 246 | |
|
168 | self.figure.suptitle(self.title) | |
|
169 | 247 | self.figure.subplots_adjust(wspace=None, hspace=0.5) |
|
248 | ||
|
170 | 249 | |
|
250 | class PlotSNRData(PlotRTIData): | |
|
251 | ||
|
252 | __code = 'SNR' | |
|
253 | ||
|
171 | 254 | def update(self): |
|
172 | ||
|
173 | self.nblock += 1 | |
|
255 | ||
|
174 | 256 | self.time.append(self.dataOut.ltctime) |
|
175 | if self.plottype=='rti': | |
|
176 | for ch in self.dataOut.channelList: | |
|
177 | self.data[ch][self.dataOut.ltctime] = self.dataOut.getPower()[ch] | |
|
178 | ||
|
179 | def run(self, dataOut, **kwargs): | |
|
180 | ||
|
181 | self.dataOut = dataOut | |
|
182 | ||
|
183 | if not self.isConfig: | |
|
184 | self.setup(dataOut, **kwargs) | |
|
185 | self.isConfig = True | |
|
186 | ||
|
187 | self.update() | |
|
188 | ||
|
189 | if dataOut.ltctime>=self.xmax: | |
|
190 | self.plot() | |
|
191 | self.isConfig = False | |
|
192 | ||
|
193 | def close(self): | |
|
194 | 257 | |
|
195 | self.plot() | |
|
196 | No newline at end of file | |
|
258 | for ch in self.dataOut.channelList: | |
|
259 | self.data[ch][self.dataOut.ltctime] = 10*np.log10(self.dataOut.data_SNR[ch]) No newline at end of file |
General Comments 0
You need to be logged in to leave comments.
Login now