@@ -1,353 +1,353 | |||
|
1 | 1 | import os |
|
2 | 2 | import numpy |
|
3 | 3 | import time, datetime |
|
4 | 4 | import mpldriver |
|
5 | 5 | |
|
6 | 6 | |
|
7 | 7 | class Figure: |
|
8 | 8 | |
|
9 | 9 | __driver = mpldriver |
|
10 | 10 | fig = None |
|
11 | 11 | |
|
12 | 12 | idfigure = None |
|
13 | 13 | wintitle = None |
|
14 | 14 | width = None |
|
15 | 15 | height = None |
|
16 | 16 | nplots = None |
|
17 | 17 | timerange = None |
|
18 | 18 | |
|
19 | 19 | axesObjList = [] |
|
20 | 20 | |
|
21 | 21 | WIDTH = None |
|
22 | 22 | HEIGHT = None |
|
23 | 23 | PREFIX = 'fig' |
|
24 | 24 | |
|
25 | 25 | def __init__(self): |
|
26 | 26 | |
|
27 | 27 | raise ValueError, "This method is not implemented" |
|
28 | 28 | |
|
29 | 29 | def __del__(self): |
|
30 | 30 | |
|
31 | 31 | self.__driver.closeFigure() |
|
32 | 32 | |
|
33 | 33 | def getFilename(self, name, ext='.png'): |
|
34 | 34 | |
|
35 | filename = '%s_%s%s' %(self.PREFIX, name, ext) | |
|
35 | filename = '%s-%s_%s%s' %(self.wintitle[0:10], self.PREFIX, name, ext) | |
|
36 | 36 | |
|
37 | 37 | return filename |
|
38 | 38 | |
|
39 | 39 | def getAxesObjList(self): |
|
40 | 40 | |
|
41 | 41 | return self.axesObjList |
|
42 | 42 | |
|
43 | 43 | def getSubplots(self): |
|
44 | 44 | |
|
45 | 45 | raise ValueError, "Abstract method: This method should be defined" |
|
46 | 46 | |
|
47 | 47 | def getScreenDim(self, widthplot, heightplot): |
|
48 | 48 | |
|
49 | 49 | nrow, ncol = self.getSubplots() |
|
50 | 50 | |
|
51 | 51 | widthscreen = widthplot*ncol |
|
52 | 52 | heightscreen = heightplot*nrow |
|
53 | 53 | |
|
54 | 54 | return widthscreen, heightscreen |
|
55 | 55 | |
|
56 | 56 | def getTimeLim(self, x, xmin, xmax): |
|
57 | 57 | |
|
58 | 58 | thisdatetime = datetime.datetime.fromtimestamp(numpy.min(x)) |
|
59 | 59 | thisdate = datetime.datetime.combine(thisdatetime.date(), datetime.time(0,0,0)) |
|
60 | 60 | |
|
61 | 61 | #################################################### |
|
62 | 62 | #If the x is out of xrange |
|
63 | 63 | if xmax < (thisdatetime - thisdate).seconds/(60*60.): |
|
64 | 64 | xmin = None |
|
65 | 65 | xmax = None |
|
66 | 66 | |
|
67 | 67 | if xmin == None: |
|
68 | 68 | td = thisdatetime - thisdate |
|
69 | 69 | xmin = td.seconds/(60*60.) |
|
70 | 70 | |
|
71 | 71 | if xmax == None: |
|
72 | 72 | xmax = xmin + self.timerange/(60*60.) |
|
73 | 73 | |
|
74 | 74 | mindt = thisdate + datetime.timedelta(0,0,0,0,0, xmin) |
|
75 | 75 | tmin = time.mktime(mindt.timetuple()) |
|
76 | 76 | |
|
77 | 77 | maxdt = thisdate + datetime.timedelta(0,0,0,0,0, xmax) |
|
78 | 78 | tmax = time.mktime(maxdt.timetuple()) |
|
79 | 79 | |
|
80 | 80 | self.timerange = tmax - tmin |
|
81 | 81 | |
|
82 | 82 | return tmin, tmax |
|
83 | 83 | |
|
84 | 84 | def init(self, idfigure, nplots, wintitle): |
|
85 | 85 | |
|
86 | 86 | raise ValueError, "This method has been replaced with createFigure" |
|
87 | 87 | |
|
88 | 88 | def createFigure(self, idfigure, wintitle, widthplot=None, heightplot=None): |
|
89 | 89 | |
|
90 | 90 | """ |
|
91 | 91 | Crea la figura de acuerdo al driver y parametros seleccionados seleccionados. |
|
92 | 92 | Las dimensiones de la pantalla es calculada a partir de los atributos self.WIDTH |
|
93 | 93 | y self.HEIGHT y el numero de subplots (nrow, ncol) |
|
94 | 94 | |
|
95 | 95 | Input: |
|
96 | 96 | idfigure : Los parametros necesarios son |
|
97 | 97 | wintitle : |
|
98 | 98 | |
|
99 | 99 | """ |
|
100 | 100 | |
|
101 | 101 | if widthplot == None: |
|
102 | 102 | widthplot = self.WIDTH |
|
103 | 103 | |
|
104 | 104 | if heightplot == None: |
|
105 | 105 | heightplot = self.HEIGHT |
|
106 | 106 | |
|
107 | 107 | self.idfigure = idfigure |
|
108 | 108 | |
|
109 | 109 | self.wintitle = wintitle |
|
110 | 110 | |
|
111 | 111 | self.widthscreen, self.heightscreen = self.getScreenDim(widthplot, heightplot) |
|
112 | 112 | |
|
113 | 113 | self.fig = self.__driver.createFigure(self.idfigure, |
|
114 | 114 | self.wintitle, |
|
115 | 115 | self.widthscreen, |
|
116 | 116 | self.heightscreen) |
|
117 | 117 | |
|
118 | 118 | self.axesObjList = [] |
|
119 | 119 | |
|
120 | 120 | def setDriver(self, driver=mpldriver): |
|
121 | 121 | |
|
122 | 122 | self.__driver = driver |
|
123 | 123 | |
|
124 | 124 | def setTitle(self, title): |
|
125 | 125 | |
|
126 | 126 | self.__driver.setTitle(self.fig, title) |
|
127 | 127 | |
|
128 | 128 | def setWinTitle(self, title): |
|
129 | 129 | |
|
130 | 130 | self.__driver.setWinTitle(self.fig, title=title) |
|
131 | 131 | |
|
132 | 132 | def setTextFromAxes(self, text): |
|
133 | 133 | |
|
134 | 134 | raise ValueError, "Este metodo ha sido reemplazaado con el metodo setText de la clase Axes" |
|
135 | 135 | |
|
136 | 136 | def makeAxes(self, nrow, ncol, xpos, ypos, colspan, rowspan): |
|
137 | 137 | |
|
138 | 138 | raise ValueError, "Este metodo ha sido reemplazaado con el metodo addAxes" |
|
139 | 139 | |
|
140 | 140 | def addAxes(self, *args): |
|
141 | 141 | """ |
|
142 | 142 | |
|
143 | 143 | Input: |
|
144 | 144 | *args : Los parametros necesarios son |
|
145 | 145 | nrow, ncol, xpos, ypos, colspan, rowspan |
|
146 | 146 | """ |
|
147 | 147 | |
|
148 | 148 | axesObj = Axes(self.fig, *args) |
|
149 | 149 | self.axesObjList.append(axesObj) |
|
150 | 150 | |
|
151 | 151 | def saveFigure(self, figpath, figfile, *args): |
|
152 | 152 | |
|
153 | 153 | filename = os.path.join(figpath, figfile) |
|
154 | 154 | self.__driver.saveFigure(self.fig, filename, *args) |
|
155 | 155 | |
|
156 | 156 | def draw(self): |
|
157 | 157 | |
|
158 | 158 | self.__driver.draw(self.fig) |
|
159 | 159 | |
|
160 | 160 | def run(self): |
|
161 | 161 | |
|
162 | 162 | raise ValueError, "This method is not implemented" |
|
163 | 163 | |
|
164 | 164 | axesList = property(getAxesObjList) |
|
165 | 165 | |
|
166 | 166 | |
|
167 | 167 | class Axes: |
|
168 | 168 | |
|
169 | 169 | __driver = mpldriver |
|
170 | 170 | fig = None |
|
171 | 171 | ax = None |
|
172 | 172 | plot = None |
|
173 | 173 | |
|
174 | 174 | __firsttime = None |
|
175 | 175 | |
|
176 | 176 | __showprofile = False |
|
177 | 177 | |
|
178 | 178 | xmin = None |
|
179 | 179 | xmax = None |
|
180 | 180 | ymin = None |
|
181 | 181 | ymax = None |
|
182 | 182 | zmin = None |
|
183 | 183 | zmax = None |
|
184 | 184 | |
|
185 | 185 | def __init__(self, *args): |
|
186 | 186 | |
|
187 | 187 | """ |
|
188 | 188 | |
|
189 | 189 | Input: |
|
190 | 190 | *args : Los parametros necesarios son |
|
191 | 191 | fig, nrow, ncol, xpos, ypos, colspan, rowspan |
|
192 | 192 | """ |
|
193 | 193 | |
|
194 | 194 | ax = self.__driver.createAxes(*args) |
|
195 | 195 | self.fig = args[0] |
|
196 | 196 | self.ax = ax |
|
197 | 197 | self.plot = None |
|
198 | 198 | |
|
199 | 199 | self.__firsttime = True |
|
200 | 200 | |
|
201 | 201 | def setText(self, text): |
|
202 | 202 | |
|
203 | 203 | self.__driver.setAxesText(self.ax, text) |
|
204 | 204 | |
|
205 | 205 | def setXAxisAsTime(self): |
|
206 | 206 | pass |
|
207 | 207 | |
|
208 | 208 | def pline(self, x, y, |
|
209 | 209 | xmin=None, xmax=None, |
|
210 | 210 | ymin=None, ymax=None, |
|
211 | 211 | xlabel='', ylabel='', |
|
212 | 212 | title='', |
|
213 | 213 | **kwargs): |
|
214 | 214 | |
|
215 | 215 | """ |
|
216 | 216 | |
|
217 | 217 | Input: |
|
218 | 218 | x : |
|
219 | 219 | y : |
|
220 | 220 | xmin : |
|
221 | 221 | xmax : |
|
222 | 222 | ymin : |
|
223 | 223 | ymax : |
|
224 | 224 | xlabel : |
|
225 | 225 | ylabel : |
|
226 | 226 | title : |
|
227 | 227 | **kwargs : Los parametros aceptados son |
|
228 | 228 | |
|
229 | 229 | ticksize |
|
230 | 230 | ytick_visible |
|
231 | 231 | """ |
|
232 | 232 | |
|
233 | 233 | if self.__firsttime: |
|
234 | 234 | |
|
235 | 235 | if xmin == None: xmin = numpy.nanmin(x) |
|
236 | 236 | if xmax == None: xmax = numpy.nanmax(x) |
|
237 | 237 | if ymin == None: ymin = numpy.nanmin(y) |
|
238 | 238 | if ymax == None: ymax = numpy.nanmax(y) |
|
239 | 239 | |
|
240 | 240 | self.plot = self.__driver.createPline(self.ax, x, y, |
|
241 | 241 | xmin, xmax, |
|
242 | 242 | ymin, ymax, |
|
243 | 243 | xlabel=xlabel, |
|
244 | 244 | ylabel=ylabel, |
|
245 | 245 | title=title, |
|
246 | 246 | **kwargs) |
|
247 | 247 | self.__firsttime = False |
|
248 | 248 | return |
|
249 | 249 | |
|
250 | 250 | self.__driver.pline(self.plot, x, y, xlabel=xlabel, |
|
251 | 251 | ylabel=ylabel, |
|
252 | 252 | title=title) |
|
253 | 253 | |
|
254 | 254 | def pmultiline(self, x, y, |
|
255 | 255 | xmin=None, xmax=None, |
|
256 | 256 | ymin=None, ymax=None, |
|
257 | 257 | xlabel='', ylabel='', |
|
258 | 258 | title='', |
|
259 | 259 | **kwargs): |
|
260 | 260 | |
|
261 | 261 | if self.__firsttime: |
|
262 | 262 | |
|
263 | 263 | if xmin == None: xmin = numpy.nanmin(x) |
|
264 | 264 | if xmax == None: xmax = numpy.nanmax(x) |
|
265 | 265 | if ymin == None: ymin = numpy.nanmin(y) |
|
266 | 266 | if ymax == None: ymax = numpy.nanmax(y) |
|
267 | 267 | |
|
268 | 268 | self.plot = self.__driver.createPmultiline(self.ax, x, y, |
|
269 | 269 | xmin, xmax, |
|
270 | 270 | ymin, ymax, |
|
271 | 271 | xlabel=xlabel, |
|
272 | 272 | ylabel=ylabel, |
|
273 | 273 | title=title, |
|
274 | 274 | **kwargs) |
|
275 | 275 | self.__firsttime = False |
|
276 | 276 | return |
|
277 | 277 | |
|
278 | 278 | self.__driver.pmultiline(self.plot, x, y, xlabel=xlabel, |
|
279 | 279 | ylabel=ylabel, |
|
280 | 280 | title=title) |
|
281 | 281 | |
|
282 | 282 | def pcolor(self, x, y, z, |
|
283 | 283 | xmin=None, xmax=None, |
|
284 | 284 | ymin=None, ymax=None, |
|
285 | 285 | zmin=None, zmax=None, |
|
286 | 286 | xlabel='', ylabel='', |
|
287 | 287 | title='', rti = False, colormap='jet', |
|
288 | 288 | **kwargs): |
|
289 | 289 | |
|
290 | 290 | """ |
|
291 | 291 | Input: |
|
292 | 292 | x : |
|
293 | 293 | y : |
|
294 | 294 | x : |
|
295 | 295 | xmin : |
|
296 | 296 | xmax : |
|
297 | 297 | ymin : |
|
298 | 298 | ymax : |
|
299 | 299 | zmin : |
|
300 | 300 | zmax : |
|
301 | 301 | xlabel : |
|
302 | 302 | ylabel : |
|
303 | 303 | title : |
|
304 | 304 | **kwargs : Los parametros aceptados son |
|
305 | 305 | ticksize=9, |
|
306 | 306 | cblabel='' |
|
307 | 307 | rti = True or False |
|
308 | 308 | """ |
|
309 | 309 | |
|
310 | 310 | if self.__firsttime: |
|
311 | 311 | |
|
312 | 312 | if xmin == None: xmin = numpy.nanmin(x) |
|
313 | 313 | if xmax == None: xmax = numpy.nanmax(x) |
|
314 | 314 | if ymin == None: ymin = numpy.nanmin(y) |
|
315 | 315 | if ymax == None: ymax = numpy.nanmax(y) |
|
316 | 316 | if zmin == None: zmin = numpy.nanmin(z) |
|
317 | 317 | if zmax == None: zmax = numpy.nanmax(z) |
|
318 | 318 | |
|
319 | 319 | |
|
320 | 320 | self.plot = self.__driver.createPcolor(self.ax, x, y, z, |
|
321 | 321 | xmin, xmax, |
|
322 | 322 | ymin, ymax, |
|
323 | 323 | zmin, zmax, |
|
324 | 324 | xlabel=xlabel, |
|
325 | 325 | ylabel=ylabel, |
|
326 | 326 | title=title, |
|
327 | 327 | colormap=colormap, |
|
328 | 328 | **kwargs) |
|
329 | 329 | |
|
330 | 330 | if self.xmin == None: self.xmin = xmin |
|
331 | 331 | if self.xmax == None: self.xmax = xmax |
|
332 | 332 | if self.ymin == None: self.ymin = ymin |
|
333 | 333 | if self.ymax == None: self.ymax = ymax |
|
334 | 334 | if self.zmin == None: self.zmin = zmin |
|
335 | 335 | if self.zmax == None: self.zmax = zmax |
|
336 | 336 | |
|
337 | 337 | self.__firsttime = False |
|
338 | 338 | return |
|
339 | 339 | |
|
340 | 340 | if rti: |
|
341 | 341 | self.__driver.addpcolor(self.ax, x, y, z, self.zmin, self.zmax, |
|
342 | 342 | xlabel=xlabel, |
|
343 | 343 | ylabel=ylabel, |
|
344 | 344 | title=title, |
|
345 | 345 | colormap=colormap) |
|
346 | 346 | return |
|
347 | 347 | |
|
348 | 348 | self.__driver.pcolor(self.plot, z, |
|
349 | 349 | xlabel=xlabel, |
|
350 | 350 | ylabel=ylabel, |
|
351 | 351 | title=title) |
|
352 | 352 | |
|
353 | 353 | No newline at end of file |
@@ -1,976 +1,983 | |||
|
1 | 1 | import numpy |
|
2 | 2 | import time, datetime |
|
3 | 3 | from graphics.figure import * |
|
4 | 4 | |
|
5 | 5 | class CrossSpectraPlot(Figure): |
|
6 | 6 | |
|
7 | 7 | __isConfig = None |
|
8 | 8 | __nsubplots = None |
|
9 | 9 | |
|
10 | 10 | WIDTH = None |
|
11 | 11 | HEIGHT = None |
|
12 | 12 | WIDTHPROF = None |
|
13 | 13 | HEIGHTPROF = None |
|
14 | 14 | PREFIX = 'cspc' |
|
15 | 15 | |
|
16 | 16 | def __init__(self): |
|
17 | 17 | |
|
18 | 18 | self.__isConfig = False |
|
19 | 19 | self.__nsubplots = 4 |
|
20 | 20 | |
|
21 | 21 | self.WIDTH = 250 |
|
22 | 22 | self.HEIGHT = 250 |
|
23 | 23 | self.WIDTHPROF = 0 |
|
24 | 24 | self.HEIGHTPROF = 0 |
|
25 | 25 | |
|
26 | 26 | def getSubplots(self): |
|
27 | 27 | |
|
28 | 28 | ncol = 4 |
|
29 | 29 | nrow = self.nplots |
|
30 | 30 | |
|
31 | 31 | return nrow, ncol |
|
32 | 32 | |
|
33 | 33 | def setup(self, idfigure, nplots, wintitle, showprofile=True): |
|
34 | 34 | |
|
35 | 35 | self.__showprofile = showprofile |
|
36 | 36 | self.nplots = nplots |
|
37 | 37 | |
|
38 | 38 | ncolspan = 1 |
|
39 | 39 | colspan = 1 |
|
40 | 40 | |
|
41 | 41 | self.createFigure(idfigure = idfigure, |
|
42 | 42 | wintitle = wintitle, |
|
43 | 43 | widthplot = self.WIDTH + self.WIDTHPROF, |
|
44 | 44 | heightplot = self.HEIGHT + self.HEIGHTPROF) |
|
45 | 45 | |
|
46 | 46 | nrow, ncol = self.getSubplots() |
|
47 | 47 | |
|
48 | 48 | counter = 0 |
|
49 | 49 | for y in range(nrow): |
|
50 | 50 | for x in range(ncol): |
|
51 | 51 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1) |
|
52 | 52 | |
|
53 | 53 | counter += 1 |
|
54 | 54 | |
|
55 | 55 | def run(self, dataOut, idfigure, wintitle="", pairsList=None, showprofile='True', |
|
56 | 56 | xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None, |
|
57 | 57 | save=False, figpath='./', figfile=None): |
|
58 | 58 | |
|
59 | 59 | """ |
|
60 | 60 | |
|
61 | 61 | Input: |
|
62 | 62 | dataOut : |
|
63 | 63 | idfigure : |
|
64 | 64 | wintitle : |
|
65 | 65 | channelList : |
|
66 | 66 | showProfile : |
|
67 | 67 | xmin : None, |
|
68 | 68 | xmax : None, |
|
69 | 69 | ymin : None, |
|
70 | 70 | ymax : None, |
|
71 | 71 | zmin : None, |
|
72 | 72 | zmax : None |
|
73 | 73 | """ |
|
74 | 74 | |
|
75 | 75 | if pairsList == None: |
|
76 | 76 | pairsIndexList = dataOut.pairsIndexList |
|
77 | 77 | else: |
|
78 | 78 | pairsIndexList = [] |
|
79 | 79 | for pair in pairsList: |
|
80 | 80 | if pair not in dataOut.pairsList: |
|
81 | 81 | raise ValueError, "Pair %s is not in dataOut.pairsList" %(pair) |
|
82 | 82 | pairsIndexList.append(dataOut.pairsList.index(pair)) |
|
83 | 83 | |
|
84 | 84 | if pairsIndexList == []: |
|
85 | 85 | return |
|
86 | 86 | |
|
87 | 87 | if len(pairsIndexList) > 4: |
|
88 | 88 | pairsIndexList = pairsIndexList[0:4] |
|
89 | 89 | |
|
90 | 90 | x = dataOut.getVelRange(1) |
|
91 | 91 | y = dataOut.getHeiRange() |
|
92 | 92 | z = 10.*numpy.log10(dataOut.data_spc[:,:,:]) |
|
93 | 93 | z = numpy.where(numpy.isfinite(z), z, numpy.NAN) |
|
94 | 94 | avg = numpy.average(numpy.abs(z), axis=1) |
|
95 | 95 | |
|
96 | 96 | noise = dataOut.getNoise() |
|
97 | 97 | |
|
98 | thisDatetime = dataOut.datatime | |
|
99 | title = "Cross-Spectra: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) | |
|
100 | xlabel = "Velocity (m/s)" | |
|
101 | ylabel = "Range (Km)" | |
|
102 | ||
|
98 | 103 | if not self.__isConfig: |
|
99 | 104 | |
|
100 | 105 | nplots = len(pairsIndexList) |
|
101 | 106 | |
|
102 | 107 | self.setup(idfigure=idfigure, |
|
103 | 108 | nplots=nplots, |
|
104 | 109 | wintitle=wintitle, |
|
105 | 110 | showprofile=showprofile) |
|
106 | 111 | |
|
107 | 112 | if xmin == None: xmin = numpy.nanmin(x) |
|
108 | 113 | if xmax == None: xmax = numpy.nanmax(x) |
|
109 | 114 | if ymin == None: ymin = numpy.nanmin(y) |
|
110 | 115 | if ymax == None: ymax = numpy.nanmax(y) |
|
111 | 116 | if zmin == None: zmin = numpy.nanmin(avg)*0.9 |
|
112 | 117 | if zmax == None: zmax = numpy.nanmax(avg)*0.9 |
|
113 | 118 | |
|
114 | 119 | self.__isConfig = True |
|
115 | ||
|
116 | thisDatetime = dataOut.datatime | |
|
117 | title = "Cross-Spectra: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) | |
|
118 | xlabel = "Velocity (m/s)" | |
|
119 | ylabel = "Range (Km)" | |
|
120 | 120 | |
|
121 | 121 | self.setWinTitle(title) |
|
122 | 122 | |
|
123 | 123 | for i in range(self.nplots): |
|
124 | 124 | pair = dataOut.pairsList[pairsIndexList[i]] |
|
125 | 125 | |
|
126 | 126 | title = "Channel %d: %4.2fdB" %(pair[0], noise[pair[0]]) |
|
127 | 127 | z = 10.*numpy.log10(dataOut.data_spc[pair[0],:,:]) |
|
128 | 128 | axes0 = self.axesList[i*self.__nsubplots] |
|
129 | 129 | axes0.pcolor(x, y, z, |
|
130 | 130 | xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax, |
|
131 | 131 | xlabel=xlabel, ylabel=ylabel, title=title, |
|
132 | 132 | ticksize=9, cblabel='') |
|
133 | 133 | |
|
134 | 134 | title = "Channel %d: %4.2fdB" %(pair[1], noise[pair[1]]) |
|
135 | 135 | z = 10.*numpy.log10(dataOut.data_spc[pair[1],:,:]) |
|
136 | 136 | axes0 = self.axesList[i*self.__nsubplots+1] |
|
137 | 137 | axes0.pcolor(x, y, z, |
|
138 | 138 | xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax, |
|
139 | 139 | xlabel=xlabel, ylabel=ylabel, title=title, |
|
140 | 140 | ticksize=9, cblabel='') |
|
141 | 141 | |
|
142 | 142 | coherenceComplex = dataOut.data_cspc[pairsIndexList[i],:,:]/numpy.sqrt(dataOut.data_spc[pair[0],:,:]*dataOut.data_spc[pair[1],:,:]) |
|
143 | 143 | coherence = numpy.abs(coherenceComplex) |
|
144 | 144 | phase = numpy.arctan(-1*coherenceComplex.imag/coherenceComplex.real)*180/numpy.pi |
|
145 | 145 | |
|
146 | 146 | |
|
147 | 147 | title = "Coherence %d%d" %(pair[0], pair[1]) |
|
148 | 148 | axes0 = self.axesList[i*self.__nsubplots+2] |
|
149 | 149 | axes0.pcolor(x, y, coherence, |
|
150 | 150 | xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=0, zmax=1, |
|
151 | 151 | xlabel=xlabel, ylabel=ylabel, title=title, |
|
152 | 152 | ticksize=9, cblabel='') |
|
153 | 153 | |
|
154 | 154 | title = "Phase %d%d" %(pair[0], pair[1]) |
|
155 | 155 | axes0 = self.axesList[i*self.__nsubplots+3] |
|
156 | 156 | axes0.pcolor(x, y, phase, |
|
157 | 157 | xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=-180, zmax=180, |
|
158 | 158 | xlabel=xlabel, ylabel=ylabel, title=title, |
|
159 | 159 | ticksize=9, cblabel='', colormap='RdBu_r') |
|
160 | 160 | |
|
161 | 161 | |
|
162 | 162 | |
|
163 | 163 | self.draw() |
|
164 | 164 | |
|
165 | 165 | if save: |
|
166 | date = thisDatetime.strftime("%Y%m%d") | |
|
166 | date = thisDatetime.strftime("%Y%m%d_%H%M%S") | |
|
167 | 167 | if figfile == None: |
|
168 | 168 | figfile = self.getFilename(name = date) |
|
169 | 169 | |
|
170 | 170 | self.saveFigure(figpath, figfile) |
|
171 | 171 | |
|
172 | 172 | |
|
173 | 173 | class RTIPlot(Figure): |
|
174 | 174 | |
|
175 | 175 | __isConfig = None |
|
176 | 176 | __nsubplots = None |
|
177 | 177 | |
|
178 | 178 | WIDTHPROF = None |
|
179 | 179 | HEIGHTPROF = None |
|
180 | 180 | PREFIX = 'rti' |
|
181 | 181 | |
|
182 | 182 | def __init__(self): |
|
183 | 183 | |
|
184 | 184 | self.timerange = 2*60*60 |
|
185 | 185 | self.__isConfig = False |
|
186 | 186 | self.__nsubplots = 1 |
|
187 | 187 | |
|
188 | 188 | self.WIDTH = 800 |
|
189 | 189 | self.HEIGHT = 200 |
|
190 | 190 | self.WIDTHPROF = 120 |
|
191 | 191 | self.HEIGHTPROF = 0 |
|
192 | 192 | |
|
193 | 193 | def getSubplots(self): |
|
194 | 194 | |
|
195 | 195 | ncol = 1 |
|
196 | 196 | nrow = self.nplots |
|
197 | 197 | |
|
198 | 198 | return nrow, ncol |
|
199 | 199 | |
|
200 | 200 | def setup(self, idfigure, nplots, wintitle, showprofile=True): |
|
201 | 201 | |
|
202 | 202 | self.__showprofile = showprofile |
|
203 | 203 | self.nplots = nplots |
|
204 | 204 | |
|
205 | 205 | ncolspan = 1 |
|
206 | 206 | colspan = 1 |
|
207 | 207 | if showprofile: |
|
208 | 208 | ncolspan = 7 |
|
209 | 209 | colspan = 6 |
|
210 | 210 | self.__nsubplots = 2 |
|
211 | 211 | |
|
212 | 212 | self.createFigure(idfigure = idfigure, |
|
213 | 213 | wintitle = wintitle, |
|
214 | 214 | widthplot = self.WIDTH + self.WIDTHPROF, |
|
215 | 215 | heightplot = self.HEIGHT + self.HEIGHTPROF) |
|
216 | 216 | |
|
217 | 217 | nrow, ncol = self.getSubplots() |
|
218 | 218 | |
|
219 | 219 | counter = 0 |
|
220 | 220 | for y in range(nrow): |
|
221 | 221 | for x in range(ncol): |
|
222 | 222 | |
|
223 | 223 | if counter >= self.nplots: |
|
224 | 224 | break |
|
225 | 225 | |
|
226 | 226 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1) |
|
227 | 227 | |
|
228 | 228 | if showprofile: |
|
229 | 229 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1) |
|
230 | 230 | |
|
231 | 231 | counter += 1 |
|
232 | 232 | |
|
233 | 233 | def run(self, dataOut, idfigure, wintitle="", channelList=None, showprofile='True', |
|
234 | 234 | xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None, |
|
235 | 235 | timerange=None, |
|
236 | 236 | save=False, figpath='./', figfile=None): |
|
237 | 237 | |
|
238 | 238 | """ |
|
239 | 239 | |
|
240 | 240 | Input: |
|
241 | 241 | dataOut : |
|
242 | 242 | idfigure : |
|
243 | 243 | wintitle : |
|
244 | 244 | channelList : |
|
245 | 245 | showProfile : |
|
246 | 246 | xmin : None, |
|
247 | 247 | xmax : None, |
|
248 | 248 | ymin : None, |
|
249 | 249 | ymax : None, |
|
250 | 250 | zmin : None, |
|
251 | 251 | zmax : None |
|
252 | 252 | """ |
|
253 | 253 | |
|
254 | 254 | if channelList == None: |
|
255 | 255 | channelIndexList = dataOut.channelIndexList |
|
256 | 256 | else: |
|
257 | 257 | channelIndexList = [] |
|
258 | 258 | for channel in channelList: |
|
259 | 259 | if channel not in dataOut.channelList: |
|
260 | 260 | raise ValueError, "Channel %d is not in dataOut.channelList" |
|
261 | 261 | channelIndexList.append(dataOut.channelList.index(channel)) |
|
262 | 262 | |
|
263 | 263 | if timerange != None: |
|
264 | 264 | self.timerange = timerange |
|
265 | 265 | |
|
266 | 266 | tmin = None |
|
267 | 267 | tmax = None |
|
268 | 268 | x = dataOut.getTimeRange() |
|
269 | 269 | y = dataOut.getHeiRange() |
|
270 | 270 | z = 10.*numpy.log10(dataOut.data_spc[channelIndexList,:,:]) |
|
271 | 271 | z = numpy.where(numpy.isfinite(z), z, numpy.NAN) |
|
272 | 272 | avg = numpy.average(z, axis=1) |
|
273 | 273 | |
|
274 | 274 | noise = dataOut.getNoise() |
|
275 | 275 | |
|
276 | 276 | thisDatetime = dataOut.datatime |
|
277 | 277 | title = "RTI: %s" %(thisDatetime.strftime("%d-%b-%Y")) |
|
278 | 278 | xlabel = "Velocity (m/s)" |
|
279 | 279 | ylabel = "Range (Km)" |
|
280 | 280 | |
|
281 | 281 | if not self.__isConfig: |
|
282 | 282 | |
|
283 | 283 | nplots = len(channelIndexList) |
|
284 | 284 | |
|
285 | 285 | self.setup(idfigure=idfigure, |
|
286 | 286 | nplots=nplots, |
|
287 | 287 | wintitle=wintitle, |
|
288 | 288 | showprofile=showprofile) |
|
289 | 289 | |
|
290 | 290 | tmin, tmax = self.getTimeLim(x, xmin, xmax) |
|
291 | 291 | if ymin == None: ymin = numpy.nanmin(y) |
|
292 | 292 | if ymax == None: ymax = numpy.nanmax(y) |
|
293 | 293 | if zmin == None: zmin = numpy.nanmin(avg)*0.9 |
|
294 | 294 | if zmax == None: zmax = numpy.nanmax(avg)*0.9 |
|
295 | 295 | |
|
296 | 296 | self.name = thisDatetime.strftime("%Y%m%d_%H%M%S") |
|
297 | 297 | self.__isConfig = True |
|
298 | 298 | |
|
299 | 299 | |
|
300 | 300 | self.setWinTitle(title) |
|
301 | 301 | |
|
302 | 302 | for i in range(self.nplots): |
|
303 | 303 | title = "Channel %d: %s" %(dataOut.channelList[i], thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) |
|
304 | 304 | axes = self.axesList[i*self.__nsubplots] |
|
305 | 305 | z = avg[i].reshape((1,-1)) |
|
306 | 306 | axes.pcolor(x, y, z, |
|
307 | 307 | xmin=tmin, xmax=tmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax, |
|
308 | 308 | xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True, |
|
309 | 309 | ticksize=9, cblabel='', cbsize="1%") |
|
310 | 310 | |
|
311 | 311 | if self.__showprofile: |
|
312 | 312 | axes = self.axesList[i*self.__nsubplots +1] |
|
313 | 313 | axes.pline(avg[i], y, |
|
314 | 314 | xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax, |
|
315 | 315 | xlabel='dB', ylabel='', title='', |
|
316 | 316 | ytick_visible=False, |
|
317 | 317 | grid='x') |
|
318 | 318 | |
|
319 | 319 | self.draw() |
|
320 | 320 | |
|
321 | 321 | if save: |
|
322 | 322 | |
|
323 | 323 | if figfile == None: |
|
324 | 324 | figfile = self.getFilename(name = self.name) |
|
325 | 325 | |
|
326 | 326 | self.saveFigure(figpath, figfile) |
|
327 | 327 | |
|
328 | 328 | if x[1] + (x[1]-x[0]) >= self.axesList[0].xmax: |
|
329 | 329 | self.__isConfig = False |
|
330 | 330 | |
|
331 | 331 | class SpectraPlot(Figure): |
|
332 | 332 | |
|
333 | 333 | __isConfig = None |
|
334 | 334 | __nsubplots = None |
|
335 | 335 | |
|
336 | 336 | WIDTHPROF = None |
|
337 | 337 | HEIGHTPROF = None |
|
338 | 338 | PREFIX = 'spc' |
|
339 | 339 | |
|
340 | 340 | def __init__(self): |
|
341 | 341 | |
|
342 | 342 | self.__isConfig = False |
|
343 | 343 | self.__nsubplots = 1 |
|
344 | 344 | |
|
345 | 345 | self.WIDTH = 230 |
|
346 | 346 | self.HEIGHT = 250 |
|
347 | 347 | self.WIDTHPROF = 120 |
|
348 | 348 | self.HEIGHTPROF = 0 |
|
349 | 349 | |
|
350 | 350 | def getSubplots(self): |
|
351 | 351 | |
|
352 | 352 | ncol = int(numpy.sqrt(self.nplots)+0.9) |
|
353 | 353 | nrow = int(self.nplots*1./ncol + 0.9) |
|
354 | 354 | |
|
355 | 355 | return nrow, ncol |
|
356 | 356 | |
|
357 | 357 | def setup(self, idfigure, nplots, wintitle, showprofile=True): |
|
358 | 358 | |
|
359 | 359 | self.__showprofile = showprofile |
|
360 | 360 | self.nplots = nplots |
|
361 | 361 | |
|
362 | 362 | ncolspan = 1 |
|
363 | 363 | colspan = 1 |
|
364 | 364 | if showprofile: |
|
365 | 365 | ncolspan = 3 |
|
366 | 366 | colspan = 2 |
|
367 | 367 | self.__nsubplots = 2 |
|
368 | 368 | |
|
369 | 369 | self.createFigure(idfigure = idfigure, |
|
370 | 370 | wintitle = wintitle, |
|
371 | 371 | widthplot = self.WIDTH + self.WIDTHPROF, |
|
372 | 372 | heightplot = self.HEIGHT + self.HEIGHTPROF) |
|
373 | 373 | |
|
374 | 374 | nrow, ncol = self.getSubplots() |
|
375 | 375 | |
|
376 | 376 | counter = 0 |
|
377 | 377 | for y in range(nrow): |
|
378 | 378 | for x in range(ncol): |
|
379 | 379 | |
|
380 | 380 | if counter >= self.nplots: |
|
381 | 381 | break |
|
382 | 382 | |
|
383 | 383 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1) |
|
384 | 384 | |
|
385 | 385 | if showprofile: |
|
386 | 386 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1) |
|
387 | 387 | |
|
388 | 388 | counter += 1 |
|
389 | 389 | |
|
390 | 390 | def run(self, dataOut, idfigure, wintitle="", channelList=None, showprofile='True', |
|
391 | 391 | xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None, |
|
392 | 392 | save=False, figpath='./', figfile=None): |
|
393 | 393 | |
|
394 | 394 | """ |
|
395 | 395 | |
|
396 | 396 | Input: |
|
397 | 397 | dataOut : |
|
398 | 398 | idfigure : |
|
399 | 399 | wintitle : |
|
400 | 400 | channelList : |
|
401 | 401 | showProfile : |
|
402 | 402 | xmin : None, |
|
403 | 403 | xmax : None, |
|
404 | 404 | ymin : None, |
|
405 | 405 | ymax : None, |
|
406 | 406 | zmin : None, |
|
407 | 407 | zmax : None |
|
408 | 408 | """ |
|
409 | 409 | |
|
410 | 410 | if channelList == None: |
|
411 | 411 | channelIndexList = dataOut.channelIndexList |
|
412 | 412 | else: |
|
413 | 413 | channelIndexList = [] |
|
414 | 414 | for channel in channelList: |
|
415 | 415 | if channel not in dataOut.channelList: |
|
416 | 416 | raise ValueError, "Channel %d is not in dataOut.channelList" |
|
417 | 417 | channelIndexList.append(dataOut.channelList.index(channel)) |
|
418 | 418 | |
|
419 | 419 | x = dataOut.getVelRange(1) |
|
420 | 420 | y = dataOut.getHeiRange() |
|
421 | 421 | |
|
422 | 422 | z = 10.*numpy.log10(dataOut.data_spc[channelIndexList,:,:]) |
|
423 | 423 | z = numpy.where(numpy.isfinite(z), z, numpy.NAN) |
|
424 | 424 | avg = numpy.average(z, axis=1) |
|
425 | 425 | |
|
426 | 426 | noise = dataOut.getNoise() |
|
427 | 427 | |
|
428 | thisDatetime = dataOut.datatime | |
|
429 | title = "Spectra: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) | |
|
430 | xlabel = "Velocity (m/s)" | |
|
431 | ylabel = "Range (Km)" | |
|
432 | ||
|
428 | 433 | if not self.__isConfig: |
|
429 | 434 | |
|
430 | 435 | nplots = len(channelIndexList) |
|
431 | 436 | |
|
432 | 437 | self.setup(idfigure=idfigure, |
|
433 | 438 | nplots=nplots, |
|
434 | 439 | wintitle=wintitle, |
|
435 | 440 | showprofile=showprofile) |
|
436 | 441 | |
|
437 | 442 | if xmin == None: xmin = numpy.nanmin(x) |
|
438 | 443 | if xmax == None: xmax = numpy.nanmax(x) |
|
439 | 444 | if ymin == None: ymin = numpy.nanmin(y) |
|
440 | 445 | if ymax == None: ymax = numpy.nanmax(y) |
|
441 | 446 | if zmin == None: zmin = numpy.nanmin(avg)*0.9 |
|
442 | 447 | if zmax == None: zmax = numpy.nanmax(avg)*0.9 |
|
443 | 448 | |
|
444 | 449 | self.__isConfig = True |
|
445 | ||
|
446 | thisDatetime = dataOut.datatime | |
|
447 | title = "Spectra: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) | |
|
448 | xlabel = "Velocity (m/s)" | |
|
449 | ylabel = "Range (Km)" | |
|
450 | 450 | |
|
451 | 451 | self.setWinTitle(title) |
|
452 | 452 | |
|
453 | 453 | for i in range(self.nplots): |
|
454 | 454 | title = "Channel %d: %4.2fdB" %(dataOut.channelList[i], noise[i]) |
|
455 | 455 | axes = self.axesList[i*self.__nsubplots] |
|
456 | 456 | axes.pcolor(x, y, z[i,:,:], |
|
457 | 457 | xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax, |
|
458 | 458 | xlabel=xlabel, ylabel=ylabel, title=title, |
|
459 | 459 | ticksize=9, cblabel='') |
|
460 | 460 | |
|
461 | 461 | if self.__showprofile: |
|
462 | 462 | axes = self.axesList[i*self.__nsubplots +1] |
|
463 | 463 | axes.pline(avg[i], y, |
|
464 | 464 | xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax, |
|
465 | 465 | xlabel='dB', ylabel='', title='', |
|
466 | 466 | ytick_visible=False, |
|
467 | 467 | grid='x') |
|
468 | 468 | |
|
469 | 469 | self.draw() |
|
470 | 470 | |
|
471 | 471 | if save: |
|
472 | date = thisDatetime.strftime("%Y%m%d") | |
|
472 | date = thisDatetime.strftime("%Y%m%d_%H%M%S") | |
|
473 | 473 | if figfile == None: |
|
474 | 474 | figfile = self.getFilename(name = date) |
|
475 | 475 | |
|
476 | 476 | self.saveFigure(figpath, figfile) |
|
477 | 477 | |
|
478 | 478 | class Scope(Figure): |
|
479 | 479 | |
|
480 | 480 | __isConfig = None |
|
481 | 481 | |
|
482 | 482 | def __init__(self): |
|
483 | 483 | |
|
484 | 484 | self.__isConfig = False |
|
485 | 485 | self.WIDTH = 600 |
|
486 | 486 | self.HEIGHT = 200 |
|
487 | 487 | |
|
488 | 488 | def getSubplots(self): |
|
489 | 489 | |
|
490 | 490 | nrow = self.nplots |
|
491 | 491 | ncol = 3 |
|
492 | 492 | return nrow, ncol |
|
493 | 493 | |
|
494 | 494 | def setup(self, idfigure, nplots, wintitle): |
|
495 | 495 | |
|
496 | 496 | self.nplots = nplots |
|
497 | 497 | |
|
498 | 498 | self.createFigure(idfigure, wintitle) |
|
499 | 499 | |
|
500 | 500 | nrow,ncol = self.getSubplots() |
|
501 | 501 | colspan = 3 |
|
502 | 502 | rowspan = 1 |
|
503 | 503 | |
|
504 | 504 | for i in range(nplots): |
|
505 | 505 | self.addAxes(nrow, ncol, i, 0, colspan, rowspan) |
|
506 | 506 | |
|
507 | 507 | |
|
508 | 508 | |
|
509 | 509 | def run(self, dataOut, idfigure, wintitle="", channelList=None, |
|
510 |
xmin=None, xmax=None, ymin=None, ymax=None, save=False, |
|
|
510 | xmin=None, xmax=None, ymin=None, ymax=None, save=False, | |
|
511 | figpath='./', figfile=None): | |
|
511 | 512 | |
|
512 | 513 | """ |
|
513 | 514 | |
|
514 | 515 | Input: |
|
515 | 516 | dataOut : |
|
516 | 517 | idfigure : |
|
517 | 518 | wintitle : |
|
518 | 519 | channelList : |
|
519 | 520 | xmin : None, |
|
520 | 521 | xmax : None, |
|
521 | 522 | ymin : None, |
|
522 | 523 | ymax : None, |
|
523 | 524 | """ |
|
524 | 525 | |
|
525 | 526 | if channelList == None: |
|
526 | 527 | channelIndexList = dataOut.channelIndexList |
|
527 | 528 | else: |
|
528 | 529 | channelIndexList = [] |
|
529 | 530 | for channel in channelList: |
|
530 | 531 | if channel not in dataOut.channelList: |
|
531 | 532 | raise ValueError, "Channel %d is not in dataOut.channelList" |
|
532 | 533 | channelIndexList.append(dataOut.channelList.index(channel)) |
|
533 | 534 | |
|
534 | 535 | x = dataOut.heightList |
|
535 | 536 | y = dataOut.data[channelIndexList,:] * numpy.conjugate(dataOut.data[channelIndexList,:]) |
|
536 | 537 | y = y.real |
|
537 | 538 | |
|
539 | thisDatetime = dataOut.datatime | |
|
540 | title = "Scope: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) | |
|
541 | xlabel = "Range (Km)" | |
|
542 | ylabel = "Intensity" | |
|
543 | ||
|
538 | 544 | if not self.__isConfig: |
|
539 | 545 | nplots = len(channelIndexList) |
|
540 | 546 | |
|
541 | 547 | self.setup(idfigure=idfigure, |
|
542 | 548 | nplots=nplots, |
|
543 | 549 | wintitle=wintitle) |
|
544 | 550 | |
|
545 | 551 | if xmin == None: xmin = numpy.nanmin(x) |
|
546 | 552 | if xmax == None: xmax = numpy.nanmax(x) |
|
547 | 553 | if ymin == None: ymin = numpy.nanmin(y) |
|
548 | 554 | if ymax == None: ymax = numpy.nanmax(y) |
|
549 | 555 | |
|
550 | 556 | self.__isConfig = True |
|
551 | 557 | |
|
552 | ||
|
553 | thisDatetime = dataOut.datatime | |
|
554 | title = "Scope: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) | |
|
555 | xlabel = "Range (Km)" | |
|
556 | ylabel = "Intensity" | |
|
557 | ||
|
558 | 558 | self.setWinTitle(title) |
|
559 | 559 | |
|
560 | 560 | for i in range(len(self.axesList)): |
|
561 | 561 | title = "Channel %d" %(i) |
|
562 | 562 | axes = self.axesList[i] |
|
563 | 563 | ychannel = y[i,:] |
|
564 | 564 | axes.pline(x, ychannel, |
|
565 | 565 | xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, |
|
566 | 566 | xlabel=xlabel, ylabel=ylabel, title=title) |
|
567 | 567 | |
|
568 | 568 | self.draw() |
|
569 | 569 | |
|
570 | 570 | if save: |
|
571 | self.saveFigure(filename) | |
|
571 | date = thisDatetime.strftime("%Y%m%d_%H%M%S") | |
|
572 | if figfile == None: | |
|
573 | figfile = self.getFilename(name = date) | |
|
574 | ||
|
575 | self.saveFigure(figpath, figfile) | |
|
572 | 576 | |
|
573 | 577 | class ProfilePlot(Figure): |
|
574 | 578 | __isConfig = None |
|
575 | 579 | __nsubplots = None |
|
576 | 580 | |
|
577 | 581 | WIDTHPROF = None |
|
578 | 582 | HEIGHTPROF = None |
|
579 | 583 | PREFIX = 'spcprofile' |
|
580 | 584 | |
|
581 | 585 | def __init__(self): |
|
582 | 586 | self.__isConfig = False |
|
583 | 587 | self.__nsubplots = 1 |
|
584 | 588 | |
|
585 | 589 | self.WIDTH = 300 |
|
586 | 590 | self.HEIGHT = 500 |
|
587 | 591 | |
|
588 | 592 | def getSubplots(self): |
|
589 | 593 | ncol = 1 |
|
590 | 594 | nrow = 1 |
|
591 | 595 | |
|
592 | 596 | return nrow, ncol |
|
593 | 597 | |
|
594 | 598 | def setup(self, idfigure, nplots, wintitle): |
|
595 | 599 | |
|
596 | 600 | self.nplots = nplots |
|
597 | 601 | |
|
598 | 602 | ncolspan = 1 |
|
599 | 603 | colspan = 1 |
|
600 | 604 | |
|
601 | 605 | self.createFigure(idfigure = idfigure, |
|
602 | 606 | wintitle = wintitle, |
|
603 | 607 | widthplot = self.WIDTH, |
|
604 | 608 | heightplot = self.HEIGHT) |
|
605 | 609 | |
|
606 | 610 | nrow, ncol = self.getSubplots() |
|
607 | 611 | |
|
608 | 612 | counter = 0 |
|
609 | 613 | for y in range(nrow): |
|
610 | 614 | for x in range(ncol): |
|
611 | 615 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1) |
|
612 | 616 | |
|
613 | 617 | def run(self, dataOut, idfigure, wintitle="", channelList=None, |
|
614 | 618 | xmin=None, xmax=None, ymin=None, ymax=None, |
|
615 | 619 | save=False, figpath='./', figfile=None): |
|
616 | 620 | |
|
617 | 621 | if channelList == None: |
|
618 | 622 | channelIndexList = dataOut.channelIndexList |
|
619 | 623 | channelList = dataOut.channelList |
|
620 | 624 | else: |
|
621 | 625 | channelIndexList = [] |
|
622 | 626 | for channel in channelList: |
|
623 | 627 | if channel not in dataOut.channelList: |
|
624 | 628 | raise ValueError, "Channel %d is not in dataOut.channelList" |
|
625 | 629 | channelIndexList.append(dataOut.channelList.index(channel)) |
|
626 | 630 | |
|
627 | 631 | |
|
628 | 632 | y = dataOut.getHeiRange() |
|
629 | 633 | x = 10.*numpy.log10(dataOut.data_spc[channelIndexList,:,:]) |
|
630 | 634 | avg = numpy.average(x, axis=1) |
|
631 | 635 | |
|
636 | thisDatetime = dataOut.datatime | |
|
637 | title = "Power Profile" | |
|
638 | xlabel = "dB" | |
|
639 | ylabel = "Range (Km)" | |
|
632 | 640 | |
|
633 | 641 | if not self.__isConfig: |
|
634 | 642 | |
|
635 | 643 | nplots = 1 |
|
636 | 644 | |
|
637 | 645 | self.setup(idfigure=idfigure, |
|
638 | 646 | nplots=nplots, |
|
639 | 647 | wintitle=wintitle) |
|
640 | 648 | |
|
641 | 649 | if ymin == None: ymin = numpy.nanmin(y) |
|
642 | 650 | if ymax == None: ymax = numpy.nanmax(y) |
|
643 | 651 | if xmin == None: xmin = numpy.nanmin(avg)*0.9 |
|
644 | 652 | if xmax == None: xmax = numpy.nanmax(avg)*0.9 |
|
645 | 653 | |
|
646 | 654 | self.__isConfig = True |
|
647 | ||
|
648 | thisDatetime = dataOut.datatime | |
|
649 | title = "Power Profile" | |
|
650 | xlabel = "dB" | |
|
651 | ylabel = "Range (Km)" | |
|
652 | 655 | |
|
653 | 656 | self.setWinTitle(title) |
|
654 | 657 | |
|
655 | 658 | |
|
656 | 659 | title = "Power Profile: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) |
|
657 | 660 | axes = self.axesList[0] |
|
658 | 661 | |
|
659 | 662 | legendlabels = ["channel %d"%x for x in channelList] |
|
660 | 663 | axes.pmultiline(avg, y, |
|
661 | 664 | xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, |
|
662 | 665 | xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels, |
|
663 | 666 | ytick_visible=True, nxticks=5, |
|
664 | 667 | grid='x') |
|
665 | 668 | |
|
666 | 669 | self.draw() |
|
667 | 670 | |
|
668 | 671 | if save: |
|
669 | 672 | date = thisDatetime.strftime("%Y%m%d") |
|
670 | 673 | if figfile == None: |
|
671 | 674 | figfile = self.getFilename(name = date) |
|
672 | 675 | |
|
673 | 676 | self.saveFigure(figpath, figfile) |
|
674 | 677 | |
|
675 | 678 | class CoherenceMap(Figure): |
|
676 | 679 | __isConfig = None |
|
677 | 680 | __nsubplots = None |
|
678 | 681 | |
|
679 | 682 | WIDTHPROF = None |
|
680 | 683 | HEIGHTPROF = None |
|
681 | 684 | PREFIX = 'coherencemap' |
|
682 | 685 | |
|
683 | 686 | def __init__(self): |
|
684 | 687 | self.timerange = 2*60*60 |
|
685 | 688 | self.__isConfig = False |
|
686 | 689 | self.__nsubplots = 1 |
|
687 | 690 | |
|
688 | 691 | self.WIDTH = 800 |
|
689 | 692 | self.HEIGHT = 200 |
|
690 | 693 | self.WIDTHPROF = 120 |
|
691 | 694 | self.HEIGHTPROF = 0 |
|
692 | 695 | |
|
693 | 696 | def getSubplots(self): |
|
694 | 697 | ncol = 1 |
|
695 | 698 | nrow = self.nplots*2 |
|
696 | 699 | |
|
697 | 700 | return nrow, ncol |
|
698 | 701 | |
|
699 | 702 | def setup(self, idfigure, nplots, wintitle, showprofile=True): |
|
700 | 703 | self.__showprofile = showprofile |
|
701 | 704 | self.nplots = nplots |
|
702 | 705 | |
|
703 | 706 | ncolspan = 1 |
|
704 | 707 | colspan = 1 |
|
705 | 708 | if showprofile: |
|
706 | 709 | ncolspan = 7 |
|
707 | 710 | colspan = 6 |
|
708 | 711 | self.__nsubplots = 2 |
|
709 | 712 | |
|
710 | 713 | self.createFigure(idfigure = idfigure, |
|
711 | 714 | wintitle = wintitle, |
|
712 | 715 | widthplot = self.WIDTH + self.WIDTHPROF, |
|
713 | 716 | heightplot = self.HEIGHT + self.HEIGHTPROF) |
|
714 | 717 | |
|
715 | 718 | nrow, ncol = self.getSubplots() |
|
716 | 719 | |
|
717 | 720 | for y in range(nrow): |
|
718 | 721 | for x in range(ncol): |
|
719 | 722 | |
|
720 | 723 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1) |
|
721 | 724 | |
|
722 | 725 | if showprofile: |
|
723 | 726 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1) |
|
724 | 727 | |
|
725 | 728 | def run(self, dataOut, idfigure, wintitle="", pairsList=None, showprofile='True', |
|
726 | 729 | xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None, |
|
727 | 730 | timerange=None, |
|
728 | 731 | save=False, figpath='./', figfile=None): |
|
729 | 732 | |
|
730 | 733 | if pairsList == None: |
|
731 | 734 | pairsIndexList = dataOut.pairsIndexList |
|
732 | 735 | else: |
|
733 | 736 | pairsIndexList = [] |
|
734 | 737 | for pair in pairsList: |
|
735 | 738 | if pair not in dataOut.pairsList: |
|
736 | 739 | raise ValueError, "Pair %s is not in dataOut.pairsList" %(pair) |
|
737 | 740 | pairsIndexList.append(dataOut.pairsList.index(pair)) |
|
738 | 741 | |
|
739 | 742 | if timerange != None: |
|
740 | 743 | self.timerange = timerange |
|
741 | 744 | |
|
742 | 745 | if pairsIndexList == []: |
|
743 | 746 | return |
|
744 | 747 | |
|
745 | 748 | if len(pairsIndexList) > 4: |
|
746 | 749 | pairsIndexList = pairsIndexList[0:4] |
|
747 | 750 | |
|
748 | 751 | tmin = None |
|
749 | 752 | tmax = None |
|
750 | 753 | x = dataOut.getTimeRange() |
|
751 | 754 | y = dataOut.getHeiRange() |
|
752 | 755 | |
|
756 | thisDatetime = dataOut.datatime | |
|
757 | title = "CoherenceMap: %s" %(thisDatetime.strftime("%d-%b-%Y")) | |
|
758 | xlabel = "" | |
|
759 | ylabel = "Range (Km)" | |
|
760 | ||
|
753 | 761 | if not self.__isConfig: |
|
754 | 762 | nplots = len(pairsIndexList) |
|
755 | 763 | self.setup(idfigure=idfigure, |
|
756 | 764 | nplots=nplots, |
|
757 | 765 | wintitle=wintitle, |
|
758 | 766 | showprofile=showprofile) |
|
759 | 767 | |
|
760 | 768 | tmin, tmax = self.getTimeLim(x, xmin, xmax) |
|
761 | 769 | if ymin == None: ymin = numpy.nanmin(y) |
|
762 | 770 | if ymax == None: ymax = numpy.nanmax(y) |
|
763 | 771 | |
|
772 | self.name = thisDatetime.strftime("%Y%m%d_%H%M%S") | |
|
773 | ||
|
764 | 774 | self.__isConfig = True |
|
765 | 775 | |
|
766 | thisDatetime = dataOut.datatime | |
|
767 | title = "CoherenceMap: %s" %(thisDatetime.strftime("%d-%b-%Y")) | |
|
768 | xlabel = "" | |
|
769 | ylabel = "Range (Km)" | |
|
770 | ||
|
771 | 776 | self.setWinTitle(title) |
|
772 | 777 | |
|
773 | 778 | for i in range(self.nplots): |
|
774 | 779 | |
|
775 | 780 | pair = dataOut.pairsList[pairsIndexList[i]] |
|
776 | 781 | coherenceComplex = dataOut.data_cspc[pairsIndexList[i],:,:]/numpy.sqrt(dataOut.data_spc[pair[0],:,:]*dataOut.data_spc[pair[1],:,:]) |
|
777 | 782 | coherence = numpy.abs(coherenceComplex) |
|
778 | 783 | avg = numpy.average(coherence, axis=0) |
|
779 | 784 | z = avg.reshape((1,-1)) |
|
780 | 785 | |
|
781 | 786 | counter = 0 |
|
782 | 787 | |
|
783 | 788 | title = "Coherence %d%d: %s" %(pair[0], pair[1], thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) |
|
784 | 789 | axes = self.axesList[i*self.__nsubplots*2] |
|
785 | 790 | axes.pcolor(x, y, z, |
|
786 | 791 | xmin=tmin, xmax=tmax, ymin=ymin, ymax=ymax, zmin=0, zmax=1, |
|
787 | 792 | xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True, |
|
788 | 793 | ticksize=9, cblabel='', cbsize="1%") |
|
789 | 794 | |
|
790 | 795 | if self.__showprofile: |
|
791 | 796 | counter += 1 |
|
792 | 797 | axes = self.axesList[i*self.__nsubplots*2 + counter] |
|
793 | 798 | axes.pline(avg, y, |
|
794 | 799 | xmin=0, xmax=1, ymin=ymin, ymax=ymax, |
|
795 | 800 | xlabel='', ylabel='', title='', ticksize=7, |
|
796 | 801 | ytick_visible=False, nxticks=5, |
|
797 | 802 | grid='x') |
|
798 | 803 | |
|
799 | 804 | counter += 1 |
|
800 | 805 | phase = numpy.arctan(-1*coherenceComplex.imag/coherenceComplex.real)*180/numpy.pi |
|
801 | 806 | avg = numpy.average(phase, axis=0) |
|
802 | 807 | z = avg.reshape((1,-1)) |
|
803 | 808 | |
|
804 | 809 | title = "Phase %d%d: %s" %(pair[0], pair[1], thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) |
|
805 | 810 | axes = self.axesList[i*self.__nsubplots*2 + counter] |
|
806 | 811 | axes.pcolor(x, y, z, |
|
807 | 812 | xmin=tmin, xmax=tmax, ymin=ymin, ymax=ymax, zmin=-180, zmax=180, |
|
808 | 813 | xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True, |
|
809 | 814 | ticksize=9, cblabel='', colormap='RdBu', cbsize="1%") |
|
810 | 815 | |
|
811 | 816 | if self.__showprofile: |
|
812 | 817 | counter += 1 |
|
813 | 818 | axes = self.axesList[i*self.__nsubplots*2 + counter] |
|
814 | 819 | axes.pline(avg, y, |
|
815 | 820 | xmin=-180, xmax=180, ymin=ymin, ymax=ymax, |
|
816 | 821 | xlabel='', ylabel='', title='', ticksize=7, |
|
817 | 822 | ytick_visible=False, nxticks=4, |
|
818 | 823 | grid='x') |
|
819 | 824 | |
|
820 | 825 | self.draw() |
|
821 | 826 | |
|
822 | 827 | if save: |
|
823 | date = thisDatetime.strftime("%Y%m%d") | |
|
828 | ||
|
824 | 829 | if figfile == None: |
|
825 |
figfile = self.getFilename(name = |
|
|
830 | figfile = self.getFilename(name = self.name) | |
|
826 | 831 | |
|
827 | 832 | self.saveFigure(figpath, figfile) |
|
828 | 833 | |
|
829 | 834 | if x[1] + (x[1]-x[0]) >= self.axesList[0].xmax: |
|
830 | 835 | self.__isConfig = False |
|
831 | 836 | |
|
832 | 837 | class RTIfromNoise(Figure): |
|
833 | 838 | |
|
834 | 839 | __isConfig = None |
|
835 | 840 | __nsubplots = None |
|
836 | 841 | |
|
837 | 842 | WIDTHPROF = None |
|
838 | 843 | HEIGHTPROF = None |
|
839 | 844 | PREFIX = 'rti' |
|
840 | 845 | |
|
841 | 846 | def __init__(self): |
|
842 | 847 | |
|
843 | 848 | self.__timerange = 24*60*60 |
|
844 | 849 | self.__isConfig = False |
|
845 | 850 | self.__nsubplots = 1 |
|
846 | 851 | |
|
847 | 852 | self.WIDTH = 800 |
|
848 | 853 | self.HEIGHT = 200 |
|
849 | 854 | |
|
850 | 855 | def getSubplots(self): |
|
851 | 856 | |
|
852 | 857 | ncol = 1 |
|
853 | 858 | nrow = self.nplots |
|
854 | 859 | |
|
855 | 860 | return nrow, ncol |
|
856 | 861 | |
|
857 | 862 | def setup(self, idfigure, nplots, wintitle, showprofile=True): |
|
858 | 863 | |
|
859 | 864 | self.__showprofile = showprofile |
|
860 | 865 | self.nplots = nplots |
|
861 | 866 | |
|
862 | 867 | ncolspan = 1 |
|
863 | 868 | colspan = 1 |
|
864 | 869 | |
|
865 | 870 | self.createFigure(idfigure = idfigure, |
|
866 | 871 | wintitle = wintitle, |
|
867 | 872 | widthplot = self.WIDTH + self.WIDTHPROF, |
|
868 | 873 | heightplot = self.HEIGHT + self.HEIGHTPROF) |
|
869 | 874 | |
|
870 | 875 | nrow, ncol = self.getSubplots() |
|
871 | 876 | |
|
872 | 877 | self.addAxes(nrow, ncol, 0, 0, 1, 1) |
|
873 | 878 | |
|
874 | 879 | |
|
875 | 880 | |
|
876 | 881 | def __getTimeLim(self, x, xmin, xmax): |
|
877 | 882 | |
|
878 | 883 | thisdatetime = datetime.datetime.fromtimestamp(numpy.min(x)) |
|
879 | 884 | thisdate = datetime.datetime.combine(thisdatetime.date(), datetime.time(0,0,0)) |
|
880 | 885 | |
|
881 | 886 | #################################################### |
|
882 | 887 | #If the x is out of xrange |
|
883 | 888 | if xmax < (thisdatetime - thisdate).seconds/(60*60.): |
|
884 | 889 | xmin = None |
|
885 | 890 | xmax = None |
|
886 | 891 | |
|
887 | 892 | if xmin == None: |
|
888 | 893 | td = thisdatetime - thisdate |
|
889 | 894 | xmin = td.seconds/(60*60.) |
|
890 | 895 | |
|
891 | 896 | if xmax == None: |
|
892 | 897 | xmax = xmin + self.__timerange/(60*60.) |
|
893 | 898 | |
|
894 | 899 | mindt = thisdate + datetime.timedelta(0,0,0,0,0, xmin) |
|
895 | 900 | tmin = time.mktime(mindt.timetuple()) |
|
896 | 901 | |
|
897 | 902 | maxdt = thisdate + datetime.timedelta(0,0,0,0,0, xmax) |
|
898 | 903 | tmax = time.mktime(maxdt.timetuple()) |
|
899 | 904 | |
|
900 | 905 | self.__timerange = tmax - tmin |
|
901 | 906 | |
|
902 | 907 | return tmin, tmax |
|
903 | 908 | |
|
904 | 909 | def run(self, dataOut, idfigure, wintitle="", channelList=None, showprofile='True', |
|
905 | 910 | xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None, |
|
906 | 911 | timerange=None, |
|
907 | 912 | save=False, figpath='./', figfile=None): |
|
908 | 913 | |
|
909 | 914 | if channelList == None: |
|
910 | 915 | channelIndexList = dataOut.channelIndexList |
|
911 | 916 | else: |
|
912 | 917 | channelIndexList = [] |
|
913 | 918 | for channel in channelList: |
|
914 | 919 | if channel not in dataOut.channelList: |
|
915 | 920 | raise ValueError, "Channel %d is not in dataOut.channelList" |
|
916 | 921 | channelIndexList.append(dataOut.channelList.index(channel)) |
|
917 | 922 | |
|
918 | 923 | if timerange != None: |
|
919 | 924 | self.__timerange = timerange |
|
920 | 925 | |
|
921 | 926 | tmin = None |
|
922 | 927 | tmax = None |
|
923 | 928 | x = dataOut.getTimeRange() |
|
924 | 929 | y = dataOut.getHeiRange() |
|
925 | 930 | x1 = dataOut.datatime |
|
926 | 931 | # z = 10.*numpy.log10(dataOut.data_spc[channelIndexList,:,:]) |
|
927 | 932 | # avg = numpy.average(z, axis=1) |
|
928 | 933 | |
|
929 | 934 | noise = dataOut.getNoise() |
|
930 |
|
|
|
935 | ||
|
936 | thisDatetime = dataOut.datatime | |
|
937 | title = "RTI: %s" %(thisDatetime.strftime("%d-%b-%Y")) | |
|
938 | xlabel = "Velocity (m/s)" | |
|
939 | ylabel = "Range (Km)" | |
|
940 | ||
|
941 | ||
|
931 | 942 | if not self.__isConfig: |
|
932 | 943 | |
|
933 | 944 | nplots = len(channelIndexList) |
|
934 | 945 | |
|
935 | 946 | self.setup(idfigure=idfigure, |
|
936 | 947 | nplots=nplots, |
|
937 | 948 | wintitle=wintitle, |
|
938 | 949 | showprofile=showprofile) |
|
939 | 950 | |
|
940 | 951 | tmin, tmax = self.__getTimeLim(x, xmin, xmax) |
|
941 | 952 | if ymin == None: ymin = numpy.nanmin(y) |
|
942 | 953 | if ymax == None: ymax = numpy.nanmax(y) |
|
943 | 954 | if zmin == None: zmin = numpy.nanmin(avg)*0.9 |
|
944 | 955 | if zmax == None: zmax = numpy.nanmax(avg)*0.9 |
|
945 | 956 | |
|
946 | 957 | self.__isConfig = True |
|
947 | 958 | |
|
948 | thisDatetime = dataOut.datatime | |
|
949 | title = "RTI: %s" %(thisDatetime.strftime("%d-%b-%Y")) | |
|
950 | xlabel = "Velocity (m/s)" | |
|
951 | ylabel = "Range (Km)" | |
|
952 | 959 | |
|
953 | 960 | self.setWinTitle(title) |
|
954 | 961 | |
|
955 | 962 | for i in range(self.nplots): |
|
956 | 963 | title = "Channel %d: %s" %(dataOut.channelList[i], thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) |
|
957 | 964 | axes = self.axesList[i*self.__nsubplots] |
|
958 | 965 | z = avg[i].reshape((1,-1)) |
|
959 | 966 | axes.pcolor(x, y, z, |
|
960 | 967 | xmin=tmin, xmax=tmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax, |
|
961 | 968 | xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True, |
|
962 | 969 | ticksize=9, cblabel='', cbsize="1%") |
|
963 | 970 | |
|
964 | 971 | |
|
965 | 972 | self.draw() |
|
966 | 973 | |
|
967 | 974 | if save: |
|
968 | 975 | date = thisDatetime.strftime("%Y%m%d") |
|
969 | 976 | if figfile == None: |
|
970 | 977 | figfile = self.getFilename(name = date) |
|
971 | 978 | |
|
972 | 979 | self.saveFigure(figpath, figfile) |
|
973 | 980 | |
|
974 | 981 | if x[1] + (x[1]-x[0]) >= self.axesList[0].xmax: |
|
975 | 982 | self.__isConfig = False |
|
976 | 983 | No newline at end of file |
General Comments 0
You need to be logged in to leave comments.
Login now