@@ -1,497 +1,519 | |||||
1 | import os |
|
1 | import os | |
2 | import numpy |
|
2 | import numpy | |
3 | import time, datetime |
|
3 | import time, datetime | |
4 | import mpldriver |
|
4 | import mpldriver | |
5 | from customftp import * |
|
5 | from customftp import * | |
6 |
|
6 | |||
7 | class Figure: |
|
7 | class Figure: | |
8 |
|
8 | |||
9 | __driver = mpldriver |
|
9 | __driver = mpldriver | |
10 | fig = None |
|
10 | fig = None | |
11 |
|
11 | |||
12 |
id |
|
12 | id = None | |
13 | wintitle = None |
|
13 | wintitle = None | |
14 | width = None |
|
14 | width = None | |
15 | height = None |
|
15 | height = None | |
16 | nplots = None |
|
16 | nplots = None | |
17 | timerange = None |
|
17 | timerange = None | |
18 |
|
18 | |||
19 | axesObjList = [] |
|
19 | axesObjList = [] | |
20 |
|
20 | |||
21 | WIDTH = None |
|
21 | WIDTH = None | |
22 | HEIGHT = None |
|
22 | HEIGHT = None | |
23 | PREFIX = 'fig' |
|
23 | PREFIX = 'fig' | |
24 |
|
24 | |||
25 | def __init__(self): |
|
25 | def __init__(self): | |
26 |
|
26 | |||
27 | raise ValueError, "This method is not implemented" |
|
27 | raise ValueError, "This method is not implemented" | |
28 |
|
28 | |||
29 | def __del__(self): |
|
29 | def __del__(self): | |
30 |
|
30 | |||
31 | self.__driver.closeFigure() |
|
31 | self.__driver.closeFigure() | |
32 |
|
32 | |||
33 | def getFilename(self, name, ext='.png'): |
|
33 | def getFilename(self, name, ext='.png'): | |
34 |
|
34 | |||
35 |
path = '%s%03d' %(self.PREFIX, self.id |
|
35 | path = '%s%03d' %(self.PREFIX, self.id) | |
36 | filename = '%s_%s%s' %(self.PREFIX, name, ext) |
|
36 | filename = '%s_%s%s' %(self.PREFIX, name, ext) | |
37 |
|
37 | |||
38 | return os.path.join(path, filename) |
|
38 | return os.path.join(path, filename) | |
39 |
|
39 | |||
40 | def getAxesObjList(self): |
|
40 | def getAxesObjList(self): | |
41 |
|
41 | |||
42 | return self.axesObjList |
|
42 | return self.axesObjList | |
43 |
|
43 | |||
44 | def getSubplots(self): |
|
44 | def getSubplots(self): | |
45 |
|
45 | |||
46 | raise ValueError, "Abstract method: This method should be defined" |
|
46 | raise ValueError, "Abstract method: This method should be defined" | |
47 |
|
47 | |||
48 | def getScreenDim(self, widthplot, heightplot): |
|
48 | def getScreenDim(self, widthplot, heightplot): | |
49 |
|
49 | |||
50 | nrow, ncol = self.getSubplots() |
|
50 | nrow, ncol = self.getSubplots() | |
51 |
|
51 | |||
52 | widthscreen = widthplot*ncol |
|
52 | widthscreen = widthplot*ncol | |
53 | heightscreen = heightplot*nrow |
|
53 | heightscreen = heightplot*nrow | |
54 |
|
54 | |||
55 | return widthscreen, heightscreen |
|
55 | return widthscreen, heightscreen | |
56 |
|
56 | |||
57 | def getTimeLim(self, x, xmin, xmax): |
|
57 | def getTimeLim(self, x, xmin, xmax): | |
58 |
|
58 | |||
59 | thisdatetime = datetime.datetime.utcfromtimestamp(numpy.min(x)) |
|
59 | thisdatetime = datetime.datetime.utcfromtimestamp(numpy.min(x)) | |
60 | thisdate = datetime.datetime.combine(thisdatetime.date(), datetime.time(0,0,0)) |
|
60 | thisdate = datetime.datetime.combine(thisdatetime.date(), datetime.time(0,0,0)) | |
61 |
|
61 | |||
62 | #################################################### |
|
62 | #################################################### | |
63 | #If the x is out of xrange |
|
63 | #If the x is out of xrange | |
64 | if xmax < (thisdatetime - thisdate).seconds/(60*60.): |
|
64 | if xmax < (thisdatetime - thisdate).seconds/(60*60.): | |
65 | xmin = None |
|
65 | xmin = None | |
66 | xmax = None |
|
66 | xmax = None | |
67 |
|
67 | |||
68 | if xmin == None: |
|
68 | if xmin == None: | |
69 | td = thisdatetime - thisdate |
|
69 | td = thisdatetime - thisdate | |
70 | xmin = td.seconds/(60*60.) |
|
70 | xmin = td.seconds/(60*60.) | |
71 |
|
71 | |||
72 | if xmax == None: |
|
72 | if xmax == None: | |
73 | xmax = xmin + self.timerange/(60*60.) |
|
73 | xmax = xmin + self.timerange/(60*60.) | |
74 |
|
74 | |||
75 | mindt = thisdate + datetime.timedelta(hours=xmin) - datetime.timedelta(seconds=time.timezone) |
|
75 | mindt = thisdate + datetime.timedelta(hours=xmin) - datetime.timedelta(seconds=time.timezone) | |
76 | tmin = time.mktime(mindt.timetuple()) |
|
76 | tmin = time.mktime(mindt.timetuple()) | |
77 |
|
77 | |||
78 | maxdt = thisdate + datetime.timedelta(hours=xmax) - datetime.timedelta(seconds=time.timezone) |
|
78 | maxdt = thisdate + datetime.timedelta(hours=xmax) - datetime.timedelta(seconds=time.timezone) | |
79 | tmax = time.mktime(maxdt.timetuple()) |
|
79 | tmax = time.mktime(maxdt.timetuple()) | |
80 |
|
80 | |||
81 | self.timerange = tmax - tmin |
|
81 | self.timerange = tmax - tmin | |
82 |
|
82 | |||
83 | return tmin, tmax |
|
83 | return tmin, tmax | |
84 |
|
84 | |||
85 |
def init(self, id |
|
85 | def init(self, id, nplots, wintitle): | |
86 |
|
86 | |||
87 | raise ValueError, "This method has been replaced with createFigure" |
|
87 | raise ValueError, "This method has been replaced with createFigure" | |
88 |
|
88 | |||
89 |
def createFigure(self, id |
|
89 | def createFigure(self, id, wintitle, widthplot=None, heightplot=None, show=True): | |
90 |
|
90 | |||
91 | """ |
|
91 | """ | |
92 | Crea la figura de acuerdo al driver y parametros seleccionados seleccionados. |
|
92 | Crea la figura de acuerdo al driver y parametros seleccionados seleccionados. | |
93 | Las dimensiones de la pantalla es calculada a partir de los atributos self.WIDTH |
|
93 | Las dimensiones de la pantalla es calculada a partir de los atributos self.WIDTH | |
94 | y self.HEIGHT y el numero de subplots (nrow, ncol) |
|
94 | y self.HEIGHT y el numero de subplots (nrow, ncol) | |
95 |
|
95 | |||
96 | Input: |
|
96 | Input: | |
97 |
id |
|
97 | id : Los parametros necesarios son | |
98 | wintitle : |
|
98 | wintitle : | |
99 |
|
99 | |||
100 | """ |
|
100 | """ | |
101 |
|
101 | |||
102 | if widthplot == None: |
|
102 | if widthplot == None: | |
103 | widthplot = self.WIDTH |
|
103 | widthplot = self.WIDTH | |
104 |
|
104 | |||
105 | if heightplot == None: |
|
105 | if heightplot == None: | |
106 | heightplot = self.HEIGHT |
|
106 | heightplot = self.HEIGHT | |
107 |
|
107 | |||
108 |
self.id |
|
108 | self.id = id | |
109 |
|
109 | |||
110 | self.wintitle = wintitle |
|
110 | self.wintitle = wintitle | |
111 |
|
111 | |||
112 | self.widthscreen, self.heightscreen = self.getScreenDim(widthplot, heightplot) |
|
112 | self.widthscreen, self.heightscreen = self.getScreenDim(widthplot, heightplot) | |
113 |
|
113 | |||
114 |
self.fig = self.__driver.createFigure(id |
|
114 | self.fig = self.__driver.createFigure(id=self.id, | |
115 | wintitle=self.wintitle, |
|
115 | wintitle=self.wintitle, | |
116 | width=self.widthscreen, |
|
116 | width=self.widthscreen, | |
117 | height=self.heightscreen, |
|
117 | height=self.heightscreen, | |
118 | show=show) |
|
118 | show=show) | |
119 |
|
119 | |||
120 | self.axesObjList = [] |
|
120 | self.axesObjList = [] | |
121 |
|
121 | |||
122 |
|
122 | |||
123 | def setDriver(self, driver=mpldriver): |
|
123 | def setDriver(self, driver=mpldriver): | |
124 |
|
124 | |||
125 | self.__driver = driver |
|
125 | self.__driver = driver | |
126 |
|
126 | |||
127 | def setTitle(self, title): |
|
127 | def setTitle(self, title): | |
128 |
|
128 | |||
129 | self.__driver.setTitle(self.fig, title) |
|
129 | self.__driver.setTitle(self.fig, title) | |
130 |
|
130 | |||
131 | def setWinTitle(self, title): |
|
131 | def setWinTitle(self, title): | |
132 |
|
132 | |||
133 | self.__driver.setWinTitle(self.fig, title=title) |
|
133 | self.__driver.setWinTitle(self.fig, title=title) | |
134 |
|
134 | |||
135 | def setTextFromAxes(self, text): |
|
135 | def setTextFromAxes(self, text): | |
136 |
|
136 | |||
137 | raise ValueError, "Este metodo ha sido reemplazaado con el metodo setText de la clase Axes" |
|
137 | raise ValueError, "Este metodo ha sido reemplazaado con el metodo setText de la clase Axes" | |
138 |
|
138 | |||
139 | def makeAxes(self, nrow, ncol, xpos, ypos, colspan, rowspan): |
|
139 | def makeAxes(self, nrow, ncol, xpos, ypos, colspan, rowspan): | |
140 |
|
140 | |||
141 | raise ValueError, "Este metodo ha sido reemplazaado con el metodo addAxes" |
|
141 | raise ValueError, "Este metodo ha sido reemplazaado con el metodo addAxes" | |
142 |
|
142 | |||
143 | def addAxes(self, *args): |
|
143 | def addAxes(self, *args): | |
144 | """ |
|
144 | """ | |
145 |
|
145 | |||
146 | Input: |
|
146 | Input: | |
147 | *args : Los parametros necesarios son |
|
147 | *args : Los parametros necesarios son | |
148 | nrow, ncol, xpos, ypos, colspan, rowspan |
|
148 | nrow, ncol, xpos, ypos, colspan, rowspan | |
149 | """ |
|
149 | """ | |
150 |
|
150 | |||
151 | axesObj = Axes(self.fig, *args) |
|
151 | axesObj = Axes(self.fig, *args) | |
152 | self.axesObjList.append(axesObj) |
|
152 | self.axesObjList.append(axesObj) | |
153 |
|
153 | |||
154 | def saveFigure(self, figpath, figfile, *args): |
|
154 | def saveFigure(self, figpath, figfile, *args): | |
155 |
|
155 | |||
156 | filename = os.path.join(figpath, figfile) |
|
156 | filename = os.path.join(figpath, figfile) | |
157 |
|
157 | |||
158 | fullpath = os.path.split(filename)[0] |
|
158 | fullpath = os.path.split(filename)[0] | |
159 |
|
159 | |||
160 | if not os.path.exists(fullpath): |
|
160 | if not os.path.exists(fullpath): | |
161 | subpath = os.path.split(fullpath)[0] |
|
161 | subpath = os.path.split(fullpath)[0] | |
162 |
|
162 | |||
163 | if not os.path.exists(subpath): |
|
163 | if not os.path.exists(subpath): | |
164 | os.mkdir(subpath) |
|
164 | os.mkdir(subpath) | |
165 |
|
165 | |||
166 | os.mkdir(fullpath) |
|
166 | os.mkdir(fullpath) | |
167 |
|
167 | |||
168 | self.__driver.saveFigure(self.fig, filename, *args) |
|
168 | self.__driver.saveFigure(self.fig, filename, *args) | |
169 |
|
169 | |||
170 | def sendByFTP(self, figfilename): |
|
170 | def sendByFTP(self, figfilename): | |
171 | ftpObj = Ftp() |
|
171 | ftpObj = Ftp() | |
172 | ftpObj.upload(figfilename) |
|
172 | ftpObj.upload(figfilename) | |
173 | ftpObj.close() |
|
173 | ftpObj.close() | |
174 |
|
174 | |||
175 | def draw(self): |
|
175 | def draw(self): | |
176 |
|
176 | |||
177 | self.__driver.draw(self.fig) |
|
177 | self.__driver.draw(self.fig) | |
178 |
|
178 | |||
179 | def run(self): |
|
179 | def run(self): | |
180 |
|
180 | |||
181 | raise ValueError, "This method is not implemented" |
|
181 | raise ValueError, "This method is not implemented" | |
182 |
|
182 | |||
183 | axesList = property(getAxesObjList) |
|
183 | axesList = property(getAxesObjList) | |
184 |
|
184 | |||
185 |
|
185 | |||
186 | class Axes: |
|
186 | class Axes: | |
187 |
|
187 | |||
188 | __driver = mpldriver |
|
188 | __driver = mpldriver | |
189 | fig = None |
|
189 | fig = None | |
190 | ax = None |
|
190 | ax = None | |
191 | plot = None |
|
191 | plot = None | |
192 | __missing = 1E30 |
|
192 | __missing = 1E30 | |
193 | __firsttime = None |
|
193 | __firsttime = None | |
194 |
|
194 | |||
195 | __showprofile = False |
|
195 | __showprofile = False | |
196 |
|
196 | |||
197 | xmin = None |
|
197 | xmin = None | |
198 | xmax = None |
|
198 | xmax = None | |
199 | ymin = None |
|
199 | ymin = None | |
200 | ymax = None |
|
200 | ymax = None | |
201 | zmin = None |
|
201 | zmin = None | |
202 | zmax = None |
|
202 | zmax = None | |
203 |
|
203 | |||
204 | x_buffer = None |
|
204 | x_buffer = None | |
205 | z_buffer = None |
|
205 | z_buffer = None | |
206 |
|
206 | |||
|
207 | __MAXNUMX = 1000 | |||
|
208 | __MAXNUMY = 500 | |||
|
209 | ||||
207 | def __init__(self, *args): |
|
210 | def __init__(self, *args): | |
208 |
|
211 | |||
209 | """ |
|
212 | """ | |
210 |
|
213 | |||
211 | Input: |
|
214 | Input: | |
212 | *args : Los parametros necesarios son |
|
215 | *args : Los parametros necesarios son | |
213 | fig, nrow, ncol, xpos, ypos, colspan, rowspan |
|
216 | fig, nrow, ncol, xpos, ypos, colspan, rowspan | |
214 | """ |
|
217 | """ | |
215 |
|
218 | |||
216 | ax = self.__driver.createAxes(*args) |
|
219 | ax = self.__driver.createAxes(*args) | |
217 | self.fig = args[0] |
|
220 | self.fig = args[0] | |
218 | self.ax = ax |
|
221 | self.ax = ax | |
219 | self.plot = None |
|
222 | self.plot = None | |
220 |
|
223 | |||
221 | self.__firsttime = True |
|
224 | self.__firsttime = True | |
222 | self.idlineList = [] |
|
225 | self.idlineList = [] | |
223 |
|
226 | |||
224 | self.x_buffer = numpy.array([]) |
|
227 | self.x_buffer = numpy.array([]) | |
225 | self.z_buffer = numpy.array([]) |
|
228 | self.z_buffer = numpy.array([]) | |
226 |
|
229 | |||
227 | def setText(self, text): |
|
230 | def setText(self, text): | |
228 |
|
231 | |||
229 | self.__driver.setAxesText(self.ax, text) |
|
232 | self.__driver.setAxesText(self.ax, text) | |
230 |
|
233 | |||
231 | def setXAxisAsTime(self): |
|
234 | def setXAxisAsTime(self): | |
232 | pass |
|
235 | pass | |
233 |
|
236 | |||
234 | def pline(self, x, y, |
|
237 | def pline(self, x, y, | |
235 | xmin=None, xmax=None, |
|
238 | xmin=None, xmax=None, | |
236 | ymin=None, ymax=None, |
|
239 | ymin=None, ymax=None, | |
237 | xlabel='', ylabel='', |
|
240 | xlabel='', ylabel='', | |
238 | title='', |
|
241 | title='', | |
239 | **kwargs): |
|
242 | **kwargs): | |
240 |
|
243 | |||
241 | """ |
|
244 | """ | |
242 |
|
245 | |||
243 | Input: |
|
246 | Input: | |
244 | x : |
|
247 | x : | |
245 | y : |
|
248 | y : | |
246 | xmin : |
|
249 | xmin : | |
247 | xmax : |
|
250 | xmax : | |
248 | ymin : |
|
251 | ymin : | |
249 | ymax : |
|
252 | ymax : | |
250 | xlabel : |
|
253 | xlabel : | |
251 | ylabel : |
|
254 | ylabel : | |
252 | title : |
|
255 | title : | |
253 | **kwargs : Los parametros aceptados son |
|
256 | **kwargs : Los parametros aceptados son | |
254 |
|
257 | |||
255 | ticksize |
|
258 | ticksize | |
256 | ytick_visible |
|
259 | ytick_visible | |
257 | """ |
|
260 | """ | |
258 |
|
261 | |||
259 | if self.__firsttime: |
|
262 | if self.__firsttime: | |
260 |
|
263 | |||
261 | if xmin == None: xmin = numpy.nanmin(x) |
|
264 | if xmin == None: xmin = numpy.nanmin(x) | |
262 | if xmax == None: xmax = numpy.nanmax(x) |
|
265 | if xmax == None: xmax = numpy.nanmax(x) | |
263 | if ymin == None: ymin = numpy.nanmin(y) |
|
266 | if ymin == None: ymin = numpy.nanmin(y) | |
264 | if ymax == None: ymax = numpy.nanmax(y) |
|
267 | if ymax == None: ymax = numpy.nanmax(y) | |
265 |
|
268 | |||
266 | self.plot = self.__driver.createPline(self.ax, x, y, |
|
269 | self.plot = self.__driver.createPline(self.ax, x, y, | |
267 | xmin, xmax, |
|
270 | xmin, xmax, | |
268 | ymin, ymax, |
|
271 | ymin, ymax, | |
269 | xlabel=xlabel, |
|
272 | xlabel=xlabel, | |
270 | ylabel=ylabel, |
|
273 | ylabel=ylabel, | |
271 | title=title, |
|
274 | title=title, | |
272 | **kwargs) |
|
275 | **kwargs) | |
273 |
|
276 | |||
274 | self.idlineList.append(0) |
|
277 | self.idlineList.append(0) | |
275 | self.__firsttime = False |
|
278 | self.__firsttime = False | |
276 | return |
|
279 | return | |
277 |
|
280 | |||
278 | self.__driver.pline(self.plot, x, y, xlabel=xlabel, |
|
281 | self.__driver.pline(self.plot, x, y, xlabel=xlabel, | |
279 | ylabel=ylabel, |
|
282 | ylabel=ylabel, | |
280 | title=title) |
|
283 | title=title) | |
281 |
|
284 | |||
282 | def addpline(self, x, y, idline, **kwargs): |
|
285 | def addpline(self, x, y, idline, **kwargs): | |
283 | lines = self.ax.lines |
|
286 | lines = self.ax.lines | |
284 |
|
287 | |||
285 | if idline in self.idlineList: |
|
288 | if idline in self.idlineList: | |
286 | self.__driver.set_linedata(self.ax, x, y, idline) |
|
289 | self.__driver.set_linedata(self.ax, x, y, idline) | |
287 |
|
290 | |||
288 | if idline not in(self.idlineList): |
|
291 | if idline not in(self.idlineList): | |
289 | self.__driver.addpline(self.ax, x, y, **kwargs) |
|
292 | self.__driver.addpline(self.ax, x, y, **kwargs) | |
290 | self.idlineList.append(idline) |
|
293 | self.idlineList.append(idline) | |
291 |
|
294 | |||
292 | return |
|
295 | return | |
293 |
|
296 | |||
294 | def pmultiline(self, x, y, |
|
297 | def pmultiline(self, x, y, | |
295 | xmin=None, xmax=None, |
|
298 | xmin=None, xmax=None, | |
296 | ymin=None, ymax=None, |
|
299 | ymin=None, ymax=None, | |
297 | xlabel='', ylabel='', |
|
300 | xlabel='', ylabel='', | |
298 | title='', |
|
301 | title='', | |
299 | **kwargs): |
|
302 | **kwargs): | |
300 |
|
303 | |||
301 | if self.__firsttime: |
|
304 | if self.__firsttime: | |
302 |
|
305 | |||
303 | if xmin == None: xmin = numpy.nanmin(x) |
|
306 | if xmin == None: xmin = numpy.nanmin(x) | |
304 | if xmax == None: xmax = numpy.nanmax(x) |
|
307 | if xmax == None: xmax = numpy.nanmax(x) | |
305 | if ymin == None: ymin = numpy.nanmin(y) |
|
308 | if ymin == None: ymin = numpy.nanmin(y) | |
306 | if ymax == None: ymax = numpy.nanmax(y) |
|
309 | if ymax == None: ymax = numpy.nanmax(y) | |
307 |
|
310 | |||
308 | self.plot = self.__driver.createPmultiline(self.ax, x, y, |
|
311 | self.plot = self.__driver.createPmultiline(self.ax, x, y, | |
309 | xmin, xmax, |
|
312 | xmin, xmax, | |
310 | ymin, ymax, |
|
313 | ymin, ymax, | |
311 | xlabel=xlabel, |
|
314 | xlabel=xlabel, | |
312 | ylabel=ylabel, |
|
315 | ylabel=ylabel, | |
313 | title=title, |
|
316 | title=title, | |
314 | **kwargs) |
|
317 | **kwargs) | |
315 | self.__firsttime = False |
|
318 | self.__firsttime = False | |
316 | return |
|
319 | return | |
317 |
|
320 | |||
318 | self.__driver.pmultiline(self.plot, x, y, xlabel=xlabel, |
|
321 | self.__driver.pmultiline(self.plot, x, y, xlabel=xlabel, | |
319 | ylabel=ylabel, |
|
322 | ylabel=ylabel, | |
320 | title=title) |
|
323 | title=title) | |
321 |
|
324 | |||
322 | def pmultilineyaxis(self, x, y, |
|
325 | def pmultilineyaxis(self, x, y, | |
323 | xmin=None, xmax=None, |
|
326 | xmin=None, xmax=None, | |
324 | ymin=None, ymax=None, |
|
327 | ymin=None, ymax=None, | |
325 | xlabel='', ylabel='', |
|
328 | xlabel='', ylabel='', | |
326 | title='', |
|
329 | title='', | |
327 | **kwargs): |
|
330 | **kwargs): | |
328 |
|
331 | |||
329 | if self.__firsttime: |
|
332 | if self.__firsttime: | |
330 |
|
333 | |||
331 | if xmin == None: xmin = numpy.nanmin(x) |
|
334 | if xmin == None: xmin = numpy.nanmin(x) | |
332 | if xmax == None: xmax = numpy.nanmax(x) |
|
335 | if xmax == None: xmax = numpy.nanmax(x) | |
333 | if ymin == None: ymin = numpy.nanmin(y) |
|
336 | if ymin == None: ymin = numpy.nanmin(y) | |
334 | if ymax == None: ymax = numpy.nanmax(y) |
|
337 | if ymax == None: ymax = numpy.nanmax(y) | |
335 |
|
338 | |||
336 | self.plot = self.__driver.createPmultilineYAxis(self.ax, x, y, |
|
339 | self.plot = self.__driver.createPmultilineYAxis(self.ax, x, y, | |
337 | xmin, xmax, |
|
340 | xmin, xmax, | |
338 | ymin, ymax, |
|
341 | ymin, ymax, | |
339 | xlabel=xlabel, |
|
342 | xlabel=xlabel, | |
340 | ylabel=ylabel, |
|
343 | ylabel=ylabel, | |
341 | title=title, |
|
344 | title=title, | |
342 | **kwargs) |
|
345 | **kwargs) | |
343 | if self.xmin == None: self.xmin = xmin |
|
346 | if self.xmin == None: self.xmin = xmin | |
344 | if self.xmax == None: self.xmax = xmax |
|
347 | if self.xmax == None: self.xmax = xmax | |
345 | if self.ymin == None: self.ymin = ymin |
|
348 | if self.ymin == None: self.ymin = ymin | |
346 | if self.ymax == None: self.ymax = ymax |
|
349 | if self.ymax == None: self.ymax = ymax | |
347 |
|
350 | |||
348 | self.__firsttime = False |
|
351 | self.__firsttime = False | |
349 | return |
|
352 | return | |
350 |
|
353 | |||
351 | self.__driver.pmultilineyaxis(self.plot, x, y, xlabel=xlabel, |
|
354 | self.__driver.pmultilineyaxis(self.plot, x, y, xlabel=xlabel, | |
352 | ylabel=ylabel, |
|
355 | ylabel=ylabel, | |
353 | title=title) |
|
356 | title=title) | |
354 |
|
357 | |||
355 | def pcolor(self, x, y, z, |
|
358 | def pcolor(self, x, y, z, | |
356 | xmin=None, xmax=None, |
|
359 | xmin=None, xmax=None, | |
357 | ymin=None, ymax=None, |
|
360 | ymin=None, ymax=None, | |
358 | zmin=None, zmax=None, |
|
361 | zmin=None, zmax=None, | |
359 | xlabel='', ylabel='', |
|
362 | xlabel='', ylabel='', | |
360 | title='', rti = False, colormap='jet', |
|
363 | title='', rti = False, colormap='jet', | |
361 | **kwargs): |
|
364 | **kwargs): | |
362 |
|
365 | |||
363 | """ |
|
366 | """ | |
364 | Input: |
|
367 | Input: | |
365 | x : |
|
368 | x : | |
366 | y : |
|
369 | y : | |
367 | x : |
|
370 | x : | |
368 | xmin : |
|
371 | xmin : | |
369 | xmax : |
|
372 | xmax : | |
370 | ymin : |
|
373 | ymin : | |
371 | ymax : |
|
374 | ymax : | |
372 | zmin : |
|
375 | zmin : | |
373 | zmax : |
|
376 | zmax : | |
374 | xlabel : |
|
377 | xlabel : | |
375 | ylabel : |
|
378 | ylabel : | |
376 | title : |
|
379 | title : | |
377 | **kwargs : Los parametros aceptados son |
|
380 | **kwargs : Los parametros aceptados son | |
378 | ticksize=9, |
|
381 | ticksize=9, | |
379 | cblabel='' |
|
382 | cblabel='' | |
380 | rti = True or False |
|
383 | rti = True or False | |
381 | """ |
|
384 | """ | |
382 |
|
385 | |||
383 | if self.__firsttime: |
|
386 | if self.__firsttime: | |
384 |
|
387 | |||
385 | if xmin == None: xmin = numpy.nanmin(x) |
|
388 | if xmin == None: xmin = numpy.nanmin(x) | |
386 | if xmax == None: xmax = numpy.nanmax(x) |
|
389 | if xmax == None: xmax = numpy.nanmax(x) | |
387 | if ymin == None: ymin = numpy.nanmin(y) |
|
390 | if ymin == None: ymin = numpy.nanmin(y) | |
388 | if ymax == None: ymax = numpy.nanmax(y) |
|
391 | if ymax == None: ymax = numpy.nanmax(y) | |
389 | if zmin == None: zmin = numpy.nanmin(z) |
|
392 | if zmin == None: zmin = numpy.nanmin(z) | |
390 | if zmax == None: zmax = numpy.nanmax(z) |
|
393 | if zmax == None: zmax = numpy.nanmax(z) | |
391 |
|
394 | |||
392 |
|
395 | |||
393 | self.plot = self.__driver.createPcolor(self.ax, x, y, z, |
|
396 | self.plot = self.__driver.createPcolor(self.ax, x, y, z, | |
394 | xmin, xmax, |
|
397 | xmin, xmax, | |
395 | ymin, ymax, |
|
398 | ymin, ymax, | |
396 | zmin, zmax, |
|
399 | zmin, zmax, | |
397 | xlabel=xlabel, |
|
400 | xlabel=xlabel, | |
398 | ylabel=ylabel, |
|
401 | ylabel=ylabel, | |
399 | title=title, |
|
402 | title=title, | |
400 | colormap=colormap, |
|
403 | colormap=colormap, | |
401 | **kwargs) |
|
404 | **kwargs) | |
402 |
|
405 | |||
403 | if self.xmin == None: self.xmin = xmin |
|
406 | if self.xmin == None: self.xmin = xmin | |
404 | if self.xmax == None: self.xmax = xmax |
|
407 | if self.xmax == None: self.xmax = xmax | |
405 | if self.ymin == None: self.ymin = ymin |
|
408 | if self.ymin == None: self.ymin = ymin | |
406 | if self.ymax == None: self.ymax = ymax |
|
409 | if self.ymax == None: self.ymax = ymax | |
407 | if self.zmin == None: self.zmin = zmin |
|
410 | if self.zmin == None: self.zmin = zmin | |
408 | if self.zmax == None: self.zmax = zmax |
|
411 | if self.zmax == None: self.zmax = zmax | |
409 |
|
412 | |||
410 | self.__firsttime = False |
|
413 | self.__firsttime = False | |
411 | return |
|
414 | return | |
412 |
|
415 | |||
413 | if rti: |
|
416 | if rti: | |
414 | self.__driver.addpcolor(self.ax, x, y, z, self.zmin, self.zmax, |
|
417 | self.__driver.addpcolor(self.ax, x, y, z, self.zmin, self.zmax, | |
415 | xlabel=xlabel, |
|
418 | xlabel=xlabel, | |
416 | ylabel=ylabel, |
|
419 | ylabel=ylabel, | |
417 | title=title, |
|
420 | title=title, | |
418 | colormap=colormap) |
|
421 | colormap=colormap) | |
419 | return |
|
422 | return | |
420 |
|
423 | |||
421 | self.__driver.pcolor(self.plot, z, |
|
424 | self.__driver.pcolor(self.plot, z, | |
422 | xlabel=xlabel, |
|
425 | xlabel=xlabel, | |
423 | ylabel=ylabel, |
|
426 | ylabel=ylabel, | |
424 | title=title) |
|
427 | title=title) | |
425 |
|
428 | |||
426 | def pcolorbuffer(self, x, y, z, |
|
429 | def pcolorbuffer(self, x, y, z, | |
427 | xmin=None, xmax=None, |
|
430 | xmin=None, xmax=None, | |
428 | ymin=None, ymax=None, |
|
431 | ymin=None, ymax=None, | |
429 | zmin=None, zmax=None, |
|
432 | zmin=None, zmax=None, | |
430 | xlabel='', ylabel='', |
|
433 | xlabel='', ylabel='', | |
431 | title='', rti = False, colormap='jet', |
|
434 | title='', rti = False, colormap='jet', | |
|
435 | maxNumX = None, maxNumY = None, | |||
432 | **kwargs): |
|
436 | **kwargs): | |
433 |
|
437 | |||
|
438 | if maxNumX == None: | |||
|
439 | maxNumX = self.__MAXNUMX | |||
|
440 | ||||
|
441 | if maxNumY == None: | |||
|
442 | maxNumY = self.__MAXNUMY | |||
434 |
|
443 | |||
435 | if self.__firsttime: |
|
444 | if self.__firsttime: | |
436 | self.z_buffer = z |
|
445 | self.z_buffer = z | |
437 | self.x_buffer = numpy.hstack((self.x_buffer, x)) |
|
446 | self.x_buffer = numpy.hstack((self.x_buffer, x)) | |
438 |
|
447 | |||
439 | if xmin == None: xmin = numpy.nanmin(x) |
|
448 | if xmin == None: xmin = numpy.nanmin(x) | |
440 | if xmax == None: xmax = numpy.nanmax(x) |
|
449 | if xmax == None: xmax = numpy.nanmax(x) | |
441 | if ymin == None: ymin = numpy.nanmin(y) |
|
450 | if ymin == None: ymin = numpy.nanmin(y) | |
442 | if ymax == None: ymax = numpy.nanmax(y) |
|
451 | if ymax == None: ymax = numpy.nanmax(y) | |
443 | if zmin == None: zmin = numpy.nanmin(z) |
|
452 | if zmin == None: zmin = numpy.nanmin(z) | |
444 | if zmax == None: zmax = numpy.nanmax(z) |
|
453 | if zmax == None: zmax = numpy.nanmax(z) | |
445 |
|
454 | |||
446 |
|
455 | |||
447 | self.plot = self.__driver.createPcolor(self.ax, self.x_buffer, y, z, |
|
456 | self.plot = self.__driver.createPcolor(self.ax, self.x_buffer, y, z, | |
448 | xmin, xmax, |
|
457 | xmin, xmax, | |
449 | ymin, ymax, |
|
458 | ymin, ymax, | |
450 | zmin, zmax, |
|
459 | zmin, zmax, | |
451 | xlabel=xlabel, |
|
460 | xlabel=xlabel, | |
452 | ylabel=ylabel, |
|
461 | ylabel=ylabel, | |
453 | title=title, |
|
462 | title=title, | |
454 | colormap=colormap, |
|
463 | colormap=colormap, | |
455 | **kwargs) |
|
464 | **kwargs) | |
456 |
|
465 | |||
457 | if self.xmin == None: self.xmin = xmin |
|
466 | if self.xmin == None: self.xmin = xmin | |
458 | if self.xmax == None: self.xmax = xmax |
|
467 | if self.xmax == None: self.xmax = xmax | |
459 | if self.ymin == None: self.ymin = ymin |
|
468 | if self.ymin == None: self.ymin = ymin | |
460 | if self.ymax == None: self.ymax = ymax |
|
469 | if self.ymax == None: self.ymax = ymax | |
461 | if self.zmin == None: self.zmin = zmin |
|
470 | if self.zmin == None: self.zmin = zmin | |
462 | if self.zmax == None: self.zmax = zmax |
|
471 | if self.zmax == None: self.zmax = zmax | |
463 |
|
472 | |||
|
473 | ||||
|
474 | deltax = (xmax - xmin)/maxNumX | |||
|
475 | deltay = (ymax - ymin)/maxNumY | |||
|
476 | ||||
|
477 | resolutionx = x[1]-x[0] | |||
|
478 | resolutiony = y[1]-y[0] | |||
|
479 | ||||
|
480 | self.decimationx = numpy.ceil(deltax / resolutionx) | |||
|
481 | self.decimationy = numpy.ceil(deltay / resolutiony) | |||
|
482 | ||||
464 | self.__firsttime = False |
|
483 | self.__firsttime = False | |
465 | return |
|
484 | return | |
466 |
|
485 | |||
467 | if rti: |
|
486 | if rti: | |
468 | if x[0]>self.x_buffer[-1]: |
|
487 | if x[0]>self.x_buffer[-1]: | |
469 | gap = z.copy() |
|
488 | gap = z.copy() | |
470 | gap[:] = self.__missing |
|
489 | gap[:] = self.__missing | |
471 | self.z_buffer = numpy.hstack((self.z_buffer, gap)) |
|
490 | self.z_buffer = numpy.hstack((self.z_buffer, gap)) | |
472 | self.z_buffer = numpy.ma.masked_inside(self.z_buffer,0.99*self.__missing,1.01*self.__missing) |
|
491 | self.z_buffer = numpy.ma.masked_inside(self.z_buffer,0.99*self.__missing,1.01*self.__missing) | |
473 | self.x_buffer = numpy.hstack((self.x_buffer, x)) |
|
492 | self.x_buffer = numpy.hstack((self.x_buffer, x)) | |
474 |
|
493 | |||
475 | else: |
|
494 | else: | |
476 | self.x_buffer = numpy.hstack((self.x_buffer, x[-1])) |
|
495 | self.x_buffer = numpy.hstack((self.x_buffer, x[-1])) | |
477 |
|
496 | |||
478 | self.z_buffer = numpy.hstack((self.z_buffer, z)) |
|
497 | self.z_buffer = numpy.hstack((self.z_buffer, z)) | |
479 |
|
498 | |||
480 | newydim = len(y) |
|
|||
481 |
|
||||
482 | # self.z_buffer = numpy.ma.masked_inside(self.z_buffer,0.99*self.__missing,1.01*self.__missing) |
|
499 | # self.z_buffer = numpy.ma.masked_inside(self.z_buffer,0.99*self.__missing,1.01*self.__missing) | |
|
500 | ydim = len(y) | |||
|
501 | z_buffer = self.z_buffer.reshape(-1,ydim) | |||
483 |
|
502 | |||
484 |
|
|
503 | x_buffer = self.x_buffer[::self.decimationx] | |
|
504 | y_buffer = y[::self.decimationy] | |||
|
505 | z_buffer = z_buffer[::self.decimationx, ::self.decimationy] | |||
|
506 | #=================================================== | |||
485 |
|
507 | |||
486 |
self.__driver.addpcolorbuffer(self.ax, |
|
508 | self.__driver.addpcolorbuffer(self.ax, x_buffer, y_buffer, z_buffer, self.zmin, self.zmax, | |
487 | xlabel=xlabel, |
|
509 | xlabel=xlabel, | |
488 | ylabel=ylabel, |
|
510 | ylabel=ylabel, | |
489 | title=title, |
|
511 | title=title, | |
490 | colormap=colormap) |
|
512 | colormap=colormap) | |
491 | return |
|
513 | return | |
492 |
|
514 | |||
493 | self.__driver.pcolor(self.plot, z, |
|
515 | self.__driver.pcolor(self.plot, z, | |
494 | xlabel=xlabel, |
|
516 | xlabel=xlabel, | |
495 | ylabel=ylabel, |
|
517 | ylabel=ylabel, | |
496 | title=title) |
|
518 | title=title) | |
497 | No newline at end of file |
|
519 |
@@ -1,382 +1,382 | |||||
1 | import numpy |
|
1 | import numpy | |
2 | import datetime |
|
2 | import datetime | |
3 | import sys |
|
3 | import sys | |
4 | import matplotlib |
|
4 | import matplotlib | |
5 |
|
5 | |||
6 | if 'linux' in sys.platform: |
|
6 | if 'linux' in sys.platform: | |
7 | matplotlib.use("TKAgg") |
|
7 | matplotlib.use("TKAgg") | |
8 |
|
8 | |||
9 | if 'darwin' in sys.platform: |
|
9 | if 'darwin' in sys.platform: | |
10 | matplotlib.use("TKAgg") |
|
10 | matplotlib.use("TKAgg") | |
11 |
|
11 | |||
12 | import matplotlib.pyplot |
|
12 | import matplotlib.pyplot | |
13 |
|
13 | |||
14 | from mpl_toolkits.axes_grid1 import make_axes_locatable |
|
14 | from mpl_toolkits.axes_grid1 import make_axes_locatable | |
15 | from matplotlib.ticker import * |
|
15 | from matplotlib.ticker import * | |
16 |
|
16 | |||
17 | ########################################### |
|
17 | ########################################### | |
18 | #Actualizacion de las funciones del driver |
|
18 | #Actualizacion de las funciones del driver | |
19 | ########################################### |
|
19 | ########################################### | |
20 |
|
20 | |||
21 |
def createFigure(id |
|
21 | def createFigure(id, wintitle, width, height, facecolor="w", show=True): | |
22 |
|
22 | |||
23 | matplotlib.pyplot.ioff() |
|
23 | matplotlib.pyplot.ioff() | |
24 |
fig = matplotlib.pyplot.figure(num=id |
|
24 | fig = matplotlib.pyplot.figure(num=id, facecolor=facecolor) | |
25 | fig.canvas.manager.set_window_title(wintitle) |
|
25 | fig.canvas.manager.set_window_title(wintitle) | |
26 | fig.canvas.manager.resize(width, height) |
|
26 | fig.canvas.manager.resize(width, height) | |
27 | matplotlib.pyplot.ion() |
|
27 | matplotlib.pyplot.ion() | |
28 | if show: |
|
28 | if show: | |
29 | matplotlib.pyplot.show() |
|
29 | matplotlib.pyplot.show() | |
30 |
|
30 | |||
31 | return fig |
|
31 | return fig | |
32 |
|
32 | |||
33 | def closeFigure(show=True): |
|
33 | def closeFigure(show=True): | |
34 |
|
34 | |||
35 | matplotlib.pyplot.ioff() |
|
35 | matplotlib.pyplot.ioff() | |
36 | if show: |
|
36 | if show: | |
37 | matplotlib.pyplot.show() |
|
37 | matplotlib.pyplot.show() | |
38 |
|
38 | |||
39 | return |
|
39 | return | |
40 |
|
40 | |||
41 | def saveFigure(fig, filename): |
|
41 | def saveFigure(fig, filename): | |
42 |
|
42 | |||
43 | matplotlib.pyplot.ioff() |
|
43 | matplotlib.pyplot.ioff() | |
44 | fig.savefig(filename) |
|
44 | fig.savefig(filename) | |
45 | matplotlib.pyplot.ion() |
|
45 | matplotlib.pyplot.ion() | |
46 |
|
46 | |||
47 | def setWinTitle(fig, title): |
|
47 | def setWinTitle(fig, title): | |
48 |
|
48 | |||
49 | fig.canvas.manager.set_window_title(title) |
|
49 | fig.canvas.manager.set_window_title(title) | |
50 |
|
50 | |||
51 | def setTitle(fig, title): |
|
51 | def setTitle(fig, title): | |
52 |
|
52 | |||
53 | fig.suptitle(title) |
|
53 | fig.suptitle(title) | |
54 |
|
54 | |||
55 | def createAxes(fig, nrow, ncol, xpos, ypos, colspan, rowspan): |
|
55 | def createAxes(fig, nrow, ncol, xpos, ypos, colspan, rowspan): | |
56 |
|
56 | |||
57 | matplotlib.pyplot.ioff() |
|
57 | matplotlib.pyplot.ioff() | |
58 | matplotlib.pyplot.figure(fig.number) |
|
58 | matplotlib.pyplot.figure(fig.number) | |
59 | axes = matplotlib.pyplot.subplot2grid((nrow, ncol), |
|
59 | axes = matplotlib.pyplot.subplot2grid((nrow, ncol), | |
60 | (xpos, ypos), |
|
60 | (xpos, ypos), | |
61 | colspan=colspan, |
|
61 | colspan=colspan, | |
62 | rowspan=rowspan) |
|
62 | rowspan=rowspan) | |
63 |
|
63 | |||
64 | matplotlib.pyplot.ion() |
|
64 | matplotlib.pyplot.ion() | |
65 | return axes |
|
65 | return axes | |
66 |
|
66 | |||
67 | def setAxesText(ax, text): |
|
67 | def setAxesText(ax, text): | |
68 |
|
68 | |||
69 | ax.annotate(text, |
|
69 | ax.annotate(text, | |
70 | xy = (.1, .99), |
|
70 | xy = (.1, .99), | |
71 | xycoords = 'figure fraction', |
|
71 | xycoords = 'figure fraction', | |
72 | horizontalalignment = 'left', |
|
72 | horizontalalignment = 'left', | |
73 | verticalalignment = 'top', |
|
73 | verticalalignment = 'top', | |
74 | fontsize = 10) |
|
74 | fontsize = 10) | |
75 |
|
75 | |||
76 | def printLabels(ax, xlabel, ylabel, title): |
|
76 | def printLabels(ax, xlabel, ylabel, title): | |
77 |
|
77 | |||
78 | ax.set_xlabel(xlabel, size=11) |
|
78 | ax.set_xlabel(xlabel, size=11) | |
79 | ax.set_ylabel(ylabel, size=11) |
|
79 | ax.set_ylabel(ylabel, size=11) | |
80 | ax.set_title(title, size=12) |
|
80 | ax.set_title(title, size=12) | |
81 |
|
81 | |||
82 | def createPline(ax, x, y, xmin, xmax, ymin, ymax, xlabel='', ylabel='', title='', |
|
82 | def createPline(ax, x, y, xmin, xmax, ymin, ymax, xlabel='', ylabel='', title='', | |
83 | ticksize=9, xtick_visible=True, ytick_visible=True, |
|
83 | ticksize=9, xtick_visible=True, ytick_visible=True, | |
84 | nxticks=4, nyticks=10, |
|
84 | nxticks=4, nyticks=10, | |
85 | grid=None): |
|
85 | grid=None): | |
86 |
|
86 | |||
87 | """ |
|
87 | """ | |
88 |
|
88 | |||
89 | Input: |
|
89 | Input: | |
90 | grid : None, 'both', 'x', 'y' |
|
90 | grid : None, 'both', 'x', 'y' | |
91 | """ |
|
91 | """ | |
92 |
|
92 | |||
93 | matplotlib.pyplot.ioff() |
|
93 | matplotlib.pyplot.ioff() | |
94 |
|
94 | |||
95 | ax.set_xlim([xmin,xmax]) |
|
95 | ax.set_xlim([xmin,xmax]) | |
96 | ax.set_ylim([ymin,ymax]) |
|
96 | ax.set_ylim([ymin,ymax]) | |
97 |
|
97 | |||
98 | printLabels(ax, xlabel, ylabel, title) |
|
98 | printLabels(ax, xlabel, ylabel, title) | |
99 |
|
99 | |||
100 | ###################################################### |
|
100 | ###################################################### | |
101 | if (xmax-xmin)<=1: |
|
101 | if (xmax-xmin)<=1: | |
102 | xtickspos = numpy.linspace(xmin,xmax,nxticks) |
|
102 | xtickspos = numpy.linspace(xmin,xmax,nxticks) | |
103 | xtickspos = numpy.array([float("%.1f"%i) for i in xtickspos]) |
|
103 | xtickspos = numpy.array([float("%.1f"%i) for i in xtickspos]) | |
104 | ax.set_xticks(xtickspos) |
|
104 | ax.set_xticks(xtickspos) | |
105 | else: |
|
105 | else: | |
106 | xtickspos = numpy.arange(nxticks)*int((xmax-xmin)/(nxticks)) + int(xmin) |
|
106 | xtickspos = numpy.arange(nxticks)*int((xmax-xmin)/(nxticks)) + int(xmin) | |
107 | ax.set_xticks(xtickspos) |
|
107 | ax.set_xticks(xtickspos) | |
108 |
|
108 | |||
109 | for tick in ax.get_xticklabels(): |
|
109 | for tick in ax.get_xticklabels(): | |
110 | tick.set_visible(xtick_visible) |
|
110 | tick.set_visible(xtick_visible) | |
111 |
|
111 | |||
112 | for tick in ax.xaxis.get_major_ticks(): |
|
112 | for tick in ax.xaxis.get_major_ticks(): | |
113 | tick.label.set_fontsize(ticksize) |
|
113 | tick.label.set_fontsize(ticksize) | |
114 |
|
114 | |||
115 | ###################################################### |
|
115 | ###################################################### | |
116 | for tick in ax.get_yticklabels(): |
|
116 | for tick in ax.get_yticklabels(): | |
117 | tick.set_visible(ytick_visible) |
|
117 | tick.set_visible(ytick_visible) | |
118 |
|
118 | |||
119 | for tick in ax.yaxis.get_major_ticks(): |
|
119 | for tick in ax.yaxis.get_major_ticks(): | |
120 | tick.label.set_fontsize(ticksize) |
|
120 | tick.label.set_fontsize(ticksize) | |
121 |
|
121 | |||
122 | ax.plot(x, y) |
|
122 | ax.plot(x, y) | |
123 | iplot = ax.lines[-1] |
|
123 | iplot = ax.lines[-1] | |
124 |
|
124 | |||
125 | ###################################################### |
|
125 | ###################################################### | |
126 | if '0.' in matplotlib.__version__[0:2]: |
|
126 | if '0.' in matplotlib.__version__[0:2]: | |
127 | print "The matplotlib version has to be updated to 1.1 or newer" |
|
127 | print "The matplotlib version has to be updated to 1.1 or newer" | |
128 | return iplot |
|
128 | return iplot | |
129 |
|
129 | |||
130 | if '1.0.' in matplotlib.__version__[0:4]: |
|
130 | if '1.0.' in matplotlib.__version__[0:4]: | |
131 | print "The matplotlib version has to be updated to 1.1 or newer" |
|
131 | print "The matplotlib version has to be updated to 1.1 or newer" | |
132 | return iplot |
|
132 | return iplot | |
133 |
|
133 | |||
134 | if grid != None: |
|
134 | if grid != None: | |
135 | ax.grid(b=True, which='major', axis=grid) |
|
135 | ax.grid(b=True, which='major', axis=grid) | |
136 |
|
136 | |||
137 | matplotlib.pyplot.tight_layout() |
|
137 | matplotlib.pyplot.tight_layout() | |
138 |
|
138 | |||
139 | matplotlib.pyplot.ion() |
|
139 | matplotlib.pyplot.ion() | |
140 |
|
140 | |||
141 | return iplot |
|
141 | return iplot | |
142 |
|
142 | |||
143 | def set_linedata(ax, x, y, idline): |
|
143 | def set_linedata(ax, x, y, idline): | |
144 |
|
144 | |||
145 | ax.lines[idline].set_data(x,y) |
|
145 | ax.lines[idline].set_data(x,y) | |
146 |
|
146 | |||
147 | def pline(iplot, x, y, xlabel='', ylabel='', title=''): |
|
147 | def pline(iplot, x, y, xlabel='', ylabel='', title=''): | |
148 |
|
148 | |||
149 | ax = iplot.get_axes() |
|
149 | ax = iplot.get_axes() | |
150 |
|
150 | |||
151 | printLabels(ax, xlabel, ylabel, title) |
|
151 | printLabels(ax, xlabel, ylabel, title) | |
152 |
|
152 | |||
153 | set_linedata(ax, x, y, idline=0) |
|
153 | set_linedata(ax, x, y, idline=0) | |
154 |
|
154 | |||
155 | def addpline(ax, x, y, color, linestyle, lw): |
|
155 | def addpline(ax, x, y, color, linestyle, lw): | |
156 |
|
156 | |||
157 | ax.plot(x,y,color=color,linestyle=linestyle,lw=lw) |
|
157 | ax.plot(x,y,color=color,linestyle=linestyle,lw=lw) | |
158 |
|
158 | |||
159 |
|
159 | |||
160 | def createPcolor(ax, x, y, z, xmin, xmax, ymin, ymax, zmin, zmax, |
|
160 | def createPcolor(ax, x, y, z, xmin, xmax, ymin, ymax, zmin, zmax, | |
161 | xlabel='', ylabel='', title='', ticksize = 9, |
|
161 | xlabel='', ylabel='', title='', ticksize = 9, | |
162 | colormap='jet',cblabel='', cbsize="5%", |
|
162 | colormap='jet',cblabel='', cbsize="5%", | |
163 | XAxisAsTime=False): |
|
163 | XAxisAsTime=False): | |
164 |
|
164 | |||
165 | matplotlib.pyplot.ioff() |
|
165 | matplotlib.pyplot.ioff() | |
166 |
|
166 | |||
167 | divider = make_axes_locatable(ax) |
|
167 | divider = make_axes_locatable(ax) | |
168 | ax_cb = divider.new_horizontal(size=cbsize, pad=0.05) |
|
168 | ax_cb = divider.new_horizontal(size=cbsize, pad=0.05) | |
169 | fig = ax.get_figure() |
|
169 | fig = ax.get_figure() | |
170 | fig.add_axes(ax_cb) |
|
170 | fig.add_axes(ax_cb) | |
171 |
|
171 | |||
172 | ax.set_xlim([xmin,xmax]) |
|
172 | ax.set_xlim([xmin,xmax]) | |
173 | ax.set_ylim([ymin,ymax]) |
|
173 | ax.set_ylim([ymin,ymax]) | |
174 |
|
174 | |||
175 | printLabels(ax, xlabel, ylabel, title) |
|
175 | printLabels(ax, xlabel, ylabel, title) | |
176 |
|
176 | |||
177 | imesh = ax.pcolormesh(x,y,z.T, vmin=zmin, vmax=zmax, cmap=matplotlib.pyplot.get_cmap(colormap)) |
|
177 | imesh = ax.pcolormesh(x,y,z.T, vmin=zmin, vmax=zmax, cmap=matplotlib.pyplot.get_cmap(colormap)) | |
178 | cb = matplotlib.pyplot.colorbar(imesh, cax=ax_cb) |
|
178 | cb = matplotlib.pyplot.colorbar(imesh, cax=ax_cb) | |
179 | cb.set_label(cblabel) |
|
179 | cb.set_label(cblabel) | |
180 |
|
180 | |||
181 | # for tl in ax_cb.get_yticklabels(): |
|
181 | # for tl in ax_cb.get_yticklabels(): | |
182 | # tl.set_visible(True) |
|
182 | # tl.set_visible(True) | |
183 |
|
183 | |||
184 | for tick in ax.yaxis.get_major_ticks(): |
|
184 | for tick in ax.yaxis.get_major_ticks(): | |
185 | tick.label.set_fontsize(ticksize) |
|
185 | tick.label.set_fontsize(ticksize) | |
186 |
|
186 | |||
187 | for tick in ax.xaxis.get_major_ticks(): |
|
187 | for tick in ax.xaxis.get_major_ticks(): | |
188 | tick.label.set_fontsize(ticksize) |
|
188 | tick.label.set_fontsize(ticksize) | |
189 |
|
189 | |||
190 | for tick in cb.ax.get_yticklabels(): |
|
190 | for tick in cb.ax.get_yticklabels(): | |
191 | tick.set_fontsize(ticksize) |
|
191 | tick.set_fontsize(ticksize) | |
192 |
|
192 | |||
193 | ax_cb.yaxis.tick_right() |
|
193 | ax_cb.yaxis.tick_right() | |
194 |
|
194 | |||
195 | if '0.' in matplotlib.__version__[0:2]: |
|
195 | if '0.' in matplotlib.__version__[0:2]: | |
196 | print "The matplotlib version has to be updated to 1.1 or newer" |
|
196 | print "The matplotlib version has to be updated to 1.1 or newer" | |
197 | return imesh |
|
197 | return imesh | |
198 |
|
198 | |||
199 | if '1.0.' in matplotlib.__version__[0:4]: |
|
199 | if '1.0.' in matplotlib.__version__[0:4]: | |
200 | print "The matplotlib version has to be updated to 1.1 or newer" |
|
200 | print "The matplotlib version has to be updated to 1.1 or newer" | |
201 | return imesh |
|
201 | return imesh | |
202 |
|
202 | |||
203 | matplotlib.pyplot.tight_layout() |
|
203 | matplotlib.pyplot.tight_layout() | |
204 |
|
204 | |||
205 | if XAxisAsTime: |
|
205 | if XAxisAsTime: | |
206 |
|
206 | |||
207 | func = lambda x, pos: ('%s') %(datetime.datetime.utcfromtimestamp(x).strftime("%H:%M:%S")) |
|
207 | func = lambda x, pos: ('%s') %(datetime.datetime.utcfromtimestamp(x).strftime("%H:%M:%S")) | |
208 | ax.xaxis.set_major_formatter(FuncFormatter(func)) |
|
208 | ax.xaxis.set_major_formatter(FuncFormatter(func)) | |
209 | ax.xaxis.set_major_locator(LinearLocator(7)) |
|
209 | ax.xaxis.set_major_locator(LinearLocator(7)) | |
210 |
|
210 | |||
211 | matplotlib.pyplot.ion() |
|
211 | matplotlib.pyplot.ion() | |
212 | return imesh |
|
212 | return imesh | |
213 |
|
213 | |||
214 | def pcolor(imesh, z, xlabel='', ylabel='', title=''): |
|
214 | def pcolor(imesh, z, xlabel='', ylabel='', title=''): | |
215 |
|
215 | |||
216 | z = z.T |
|
216 | z = z.T | |
217 |
|
217 | |||
218 | ax = imesh.get_axes() |
|
218 | ax = imesh.get_axes() | |
219 |
|
219 | |||
220 | printLabels(ax, xlabel, ylabel, title) |
|
220 | printLabels(ax, xlabel, ylabel, title) | |
221 |
|
221 | |||
222 | imesh.set_array(z.ravel()) |
|
222 | imesh.set_array(z.ravel()) | |
223 |
|
223 | |||
224 | def addpcolor(ax, x, y, z, zmin, zmax, xlabel='', ylabel='', title='', colormap='jet'): |
|
224 | def addpcolor(ax, x, y, z, zmin, zmax, xlabel='', ylabel='', title='', colormap='jet'): | |
225 |
|
225 | |||
226 | printLabels(ax, xlabel, ylabel, title) |
|
226 | printLabels(ax, xlabel, ylabel, title) | |
227 |
|
227 | |||
228 | ax.pcolormesh(x,y,z.T,vmin=zmin,vmax=zmax, cmap=matplotlib.pyplot.get_cmap(colormap)) |
|
228 | ax.pcolormesh(x,y,z.T,vmin=zmin,vmax=zmax, cmap=matplotlib.pyplot.get_cmap(colormap)) | |
229 |
|
229 | |||
230 | def addpcolorbuffer(ax, x, y, z, zmin, zmax, xlabel='', ylabel='', title='', colormap='jet'): |
|
230 | def addpcolorbuffer(ax, x, y, z, zmin, zmax, xlabel='', ylabel='', title='', colormap='jet'): | |
231 |
|
231 | |||
232 | printLabels(ax, xlabel, ylabel, title) |
|
232 | printLabels(ax, xlabel, ylabel, title) | |
233 |
|
233 | |||
234 | ax.collections.remove(ax.collections[0]) |
|
234 | ax.collections.remove(ax.collections[0]) | |
235 |
|
235 | |||
236 | ax.pcolormesh(x,y,z.T,vmin=zmin,vmax=zmax, cmap=matplotlib.pyplot.get_cmap(colormap)) |
|
236 | ax.pcolormesh(x,y,z.T,vmin=zmin,vmax=zmax, cmap=matplotlib.pyplot.get_cmap(colormap)) | |
237 |
|
237 | |||
238 | def createPmultiline(ax, x, y, xmin, xmax, ymin, ymax, xlabel='', ylabel='', title='', legendlabels=None, |
|
238 | def createPmultiline(ax, x, y, xmin, xmax, ymin, ymax, xlabel='', ylabel='', title='', legendlabels=None, | |
239 | ticksize=9, xtick_visible=True, ytick_visible=True, |
|
239 | ticksize=9, xtick_visible=True, ytick_visible=True, | |
240 | nxticks=4, nyticks=10, |
|
240 | nxticks=4, nyticks=10, | |
241 | grid=None): |
|
241 | grid=None): | |
242 |
|
242 | |||
243 | """ |
|
243 | """ | |
244 |
|
244 | |||
245 | Input: |
|
245 | Input: | |
246 | grid : None, 'both', 'x', 'y' |
|
246 | grid : None, 'both', 'x', 'y' | |
247 | """ |
|
247 | """ | |
248 |
|
248 | |||
249 | matplotlib.pyplot.ioff() |
|
249 | matplotlib.pyplot.ioff() | |
250 |
|
250 | |||
251 | lines = ax.plot(x.T, y) |
|
251 | lines = ax.plot(x.T, y) | |
252 | leg = ax.legend(lines, legendlabels, loc='upper right') |
|
252 | leg = ax.legend(lines, legendlabels, loc='upper right') | |
253 | leg.get_frame().set_alpha(0.5) |
|
253 | leg.get_frame().set_alpha(0.5) | |
254 | ax.set_xlim([xmin,xmax]) |
|
254 | ax.set_xlim([xmin,xmax]) | |
255 | ax.set_ylim([ymin,ymax]) |
|
255 | ax.set_ylim([ymin,ymax]) | |
256 | printLabels(ax, xlabel, ylabel, title) |
|
256 | printLabels(ax, xlabel, ylabel, title) | |
257 |
|
257 | |||
258 | xtickspos = numpy.arange(nxticks)*int((xmax-xmin)/(nxticks)) + int(xmin) |
|
258 | xtickspos = numpy.arange(nxticks)*int((xmax-xmin)/(nxticks)) + int(xmin) | |
259 | ax.set_xticks(xtickspos) |
|
259 | ax.set_xticks(xtickspos) | |
260 |
|
260 | |||
261 | for tick in ax.get_xticklabels(): |
|
261 | for tick in ax.get_xticklabels(): | |
262 | tick.set_visible(xtick_visible) |
|
262 | tick.set_visible(xtick_visible) | |
263 |
|
263 | |||
264 | for tick in ax.xaxis.get_major_ticks(): |
|
264 | for tick in ax.xaxis.get_major_ticks(): | |
265 | tick.label.set_fontsize(ticksize) |
|
265 | tick.label.set_fontsize(ticksize) | |
266 |
|
266 | |||
267 | for tick in ax.get_yticklabels(): |
|
267 | for tick in ax.get_yticklabels(): | |
268 | tick.set_visible(ytick_visible) |
|
268 | tick.set_visible(ytick_visible) | |
269 |
|
269 | |||
270 | for tick in ax.yaxis.get_major_ticks(): |
|
270 | for tick in ax.yaxis.get_major_ticks(): | |
271 | tick.label.set_fontsize(ticksize) |
|
271 | tick.label.set_fontsize(ticksize) | |
272 |
|
272 | |||
273 | iplot = ax.lines[-1] |
|
273 | iplot = ax.lines[-1] | |
274 |
|
274 | |||
275 | if '0.' in matplotlib.__version__[0:2]: |
|
275 | if '0.' in matplotlib.__version__[0:2]: | |
276 | print "The matplotlib version has to be updated to 1.1 or newer" |
|
276 | print "The matplotlib version has to be updated to 1.1 or newer" | |
277 | return iplot |
|
277 | return iplot | |
278 |
|
278 | |||
279 | if '1.0.' in matplotlib.__version__[0:4]: |
|
279 | if '1.0.' in matplotlib.__version__[0:4]: | |
280 | print "The matplotlib version has to be updated to 1.1 or newer" |
|
280 | print "The matplotlib version has to be updated to 1.1 or newer" | |
281 | return iplot |
|
281 | return iplot | |
282 |
|
282 | |||
283 | if grid != None: |
|
283 | if grid != None: | |
284 | ax.grid(b=True, which='major', axis=grid) |
|
284 | ax.grid(b=True, which='major', axis=grid) | |
285 |
|
285 | |||
286 | matplotlib.pyplot.tight_layout() |
|
286 | matplotlib.pyplot.tight_layout() | |
287 |
|
287 | |||
288 | matplotlib.pyplot.ion() |
|
288 | matplotlib.pyplot.ion() | |
289 |
|
289 | |||
290 | return iplot |
|
290 | return iplot | |
291 |
|
291 | |||
292 |
|
292 | |||
293 | def pmultiline(iplot, x, y, xlabel='', ylabel='', title=''): |
|
293 | def pmultiline(iplot, x, y, xlabel='', ylabel='', title=''): | |
294 |
|
294 | |||
295 | ax = iplot.get_axes() |
|
295 | ax = iplot.get_axes() | |
296 |
|
296 | |||
297 | printLabels(ax, xlabel, ylabel, title) |
|
297 | printLabels(ax, xlabel, ylabel, title) | |
298 |
|
298 | |||
299 | for i in range(len(ax.lines)): |
|
299 | for i in range(len(ax.lines)): | |
300 | line = ax.lines[i] |
|
300 | line = ax.lines[i] | |
301 | line.set_data(x[i,:],y) |
|
301 | line.set_data(x[i,:],y) | |
302 |
|
302 | |||
303 | def createPmultilineYAxis(ax, x, y, xmin, xmax, ymin, ymax, xlabel='', ylabel='', title='', legendlabels=None, |
|
303 | def createPmultilineYAxis(ax, x, y, xmin, xmax, ymin, ymax, xlabel='', ylabel='', title='', legendlabels=None, | |
304 | ticksize=9, xtick_visible=True, ytick_visible=True, |
|
304 | ticksize=9, xtick_visible=True, ytick_visible=True, | |
305 | nxticks=4, nyticks=10, marker='.', markersize=10, linestyle="None", |
|
305 | nxticks=4, nyticks=10, marker='.', markersize=10, linestyle="None", | |
306 | grid=None, XAxisAsTime=False): |
|
306 | grid=None, XAxisAsTime=False): | |
307 |
|
307 | |||
308 | """ |
|
308 | """ | |
309 |
|
309 | |||
310 | Input: |
|
310 | Input: | |
311 | grid : None, 'both', 'x', 'y' |
|
311 | grid : None, 'both', 'x', 'y' | |
312 | """ |
|
312 | """ | |
313 |
|
313 | |||
314 | matplotlib.pyplot.ioff() |
|
314 | matplotlib.pyplot.ioff() | |
315 |
|
315 | |||
316 | # lines = ax.plot(x, y.T, marker=marker,markersize=markersize,linestyle=linestyle) |
|
316 | # lines = ax.plot(x, y.T, marker=marker,markersize=markersize,linestyle=linestyle) | |
317 | lines = ax.plot(x, y.T, linestyle='None', marker='.', markersize=markersize) |
|
317 | lines = ax.plot(x, y.T, linestyle='None', marker='.', markersize=markersize) | |
318 | leg = ax.legend(lines, legendlabels, loc='upper left', bbox_to_anchor=(1.01, 1.00), numpoints=1, handlelength=1.5, \ |
|
318 | leg = ax.legend(lines, legendlabels, loc='upper left', bbox_to_anchor=(1.01, 1.00), numpoints=1, handlelength=1.5, \ | |
319 | handletextpad=0.5, borderpad=0.5, labelspacing=0.5, borderaxespad=0.) |
|
319 | handletextpad=0.5, borderpad=0.5, labelspacing=0.5, borderaxespad=0.) | |
320 |
|
320 | |||
321 | for label in leg.get_texts(): label.set_fontsize(9) |
|
321 | for label in leg.get_texts(): label.set_fontsize(9) | |
322 |
|
322 | |||
323 | ax.set_xlim([xmin,xmax]) |
|
323 | ax.set_xlim([xmin,xmax]) | |
324 | ax.set_ylim([ymin,ymax]) |
|
324 | ax.set_ylim([ymin,ymax]) | |
325 | printLabels(ax, xlabel, ylabel, title) |
|
325 | printLabels(ax, xlabel, ylabel, title) | |
326 |
|
326 | |||
327 | # xtickspos = numpy.arange(nxticks)*int((xmax-xmin)/(nxticks)) + int(xmin) |
|
327 | # xtickspos = numpy.arange(nxticks)*int((xmax-xmin)/(nxticks)) + int(xmin) | |
328 | # ax.set_xticks(xtickspos) |
|
328 | # ax.set_xticks(xtickspos) | |
329 |
|
329 | |||
330 | for tick in ax.get_xticklabels(): |
|
330 | for tick in ax.get_xticklabels(): | |
331 | tick.set_visible(xtick_visible) |
|
331 | tick.set_visible(xtick_visible) | |
332 |
|
332 | |||
333 | for tick in ax.xaxis.get_major_ticks(): |
|
333 | for tick in ax.xaxis.get_major_ticks(): | |
334 | tick.label.set_fontsize(ticksize) |
|
334 | tick.label.set_fontsize(ticksize) | |
335 |
|
335 | |||
336 | for tick in ax.get_yticklabels(): |
|
336 | for tick in ax.get_yticklabels(): | |
337 | tick.set_visible(ytick_visible) |
|
337 | tick.set_visible(ytick_visible) | |
338 |
|
338 | |||
339 | for tick in ax.yaxis.get_major_ticks(): |
|
339 | for tick in ax.yaxis.get_major_ticks(): | |
340 | tick.label.set_fontsize(ticksize) |
|
340 | tick.label.set_fontsize(ticksize) | |
341 |
|
341 | |||
342 | iplot = ax.lines[-1] |
|
342 | iplot = ax.lines[-1] | |
343 |
|
343 | |||
344 | if '0.' in matplotlib.__version__[0:2]: |
|
344 | if '0.' in matplotlib.__version__[0:2]: | |
345 | print "The matplotlib version has to be updated to 1.1 or newer" |
|
345 | print "The matplotlib version has to be updated to 1.1 or newer" | |
346 | return iplot |
|
346 | return iplot | |
347 |
|
347 | |||
348 | if '1.0.' in matplotlib.__version__[0:4]: |
|
348 | if '1.0.' in matplotlib.__version__[0:4]: | |
349 | print "The matplotlib version has to be updated to 1.1 or newer" |
|
349 | print "The matplotlib version has to be updated to 1.1 or newer" | |
350 | return iplot |
|
350 | return iplot | |
351 |
|
351 | |||
352 | if grid != None: |
|
352 | if grid != None: | |
353 | ax.grid(b=True, which='major', axis=grid) |
|
353 | ax.grid(b=True, which='major', axis=grid) | |
354 |
|
354 | |||
355 | matplotlib.pyplot.tight_layout() |
|
355 | matplotlib.pyplot.tight_layout() | |
356 |
|
356 | |||
357 | if XAxisAsTime: |
|
357 | if XAxisAsTime: | |
358 |
|
358 | |||
359 | func = lambda x, pos: ('%s') %(datetime.datetime.utcfromtimestamp(x).strftime("%H:%M:%S")) |
|
359 | func = lambda x, pos: ('%s') %(datetime.datetime.utcfromtimestamp(x).strftime("%H:%M:%S")) | |
360 | ax.xaxis.set_major_formatter(FuncFormatter(func)) |
|
360 | ax.xaxis.set_major_formatter(FuncFormatter(func)) | |
361 | ax.xaxis.set_major_locator(LinearLocator(7)) |
|
361 | ax.xaxis.set_major_locator(LinearLocator(7)) | |
362 |
|
362 | |||
363 | matplotlib.pyplot.ion() |
|
363 | matplotlib.pyplot.ion() | |
364 |
|
364 | |||
365 | return iplot |
|
365 | return iplot | |
366 |
|
366 | |||
367 | def pmultilineyaxis(iplot, x, y, xlabel='', ylabel='', title=''): |
|
367 | def pmultilineyaxis(iplot, x, y, xlabel='', ylabel='', title=''): | |
368 |
|
368 | |||
369 | ax = iplot.get_axes() |
|
369 | ax = iplot.get_axes() | |
370 |
|
370 | |||
371 | printLabels(ax, xlabel, ylabel, title) |
|
371 | printLabels(ax, xlabel, ylabel, title) | |
372 |
|
372 | |||
373 | for i in range(len(ax.lines)): |
|
373 | for i in range(len(ax.lines)): | |
374 | line = ax.lines[i] |
|
374 | line = ax.lines[i] | |
375 | line.set_data(x,y[i,:]) |
|
375 | line.set_data(x,y[i,:]) | |
376 |
|
376 | |||
377 | def draw(fig): |
|
377 | def draw(fig): | |
378 |
|
378 | |||
379 | if type(fig) == 'int': |
|
379 | if type(fig) == 'int': | |
380 | raise ValueError, "This parameter should be of tpye matplotlib figure" |
|
380 | raise ValueError, "This parameter should be of tpye matplotlib figure" | |
381 |
|
381 | |||
382 | fig.canvas.draw() No newline at end of file |
|
382 | fig.canvas.draw() |
@@ -1,1363 +1,1365 | |||||
1 | import numpy |
|
1 | import numpy | |
2 | import time, datetime, os |
|
2 | import time, datetime, os | |
3 | from graphics.figure import * |
|
3 | from graphics.figure import * | |
4 | def isRealtime(utcdatatime): |
|
4 | def isRealtime(utcdatatime): | |
5 | utcnow = time.mktime(datetime.datetime.utcnow().timetuple()) |
|
5 | utcnow = time.mktime(datetime.datetime.utcnow().timetuple()) | |
6 | delta = utcnow - utcdatatime # abs |
|
6 | delta = utcnow - utcdatatime # abs | |
7 | if delta >= 5*60.: |
|
7 | if delta >= 5*60.: | |
8 | return False |
|
8 | return False | |
9 | return True |
|
9 | return True | |
10 |
|
10 | |||
11 | class CrossSpectraPlot(Figure): |
|
11 | class CrossSpectraPlot(Figure): | |
12 |
|
12 | |||
13 | __isConfig = None |
|
13 | __isConfig = None | |
14 | __nsubplots = None |
|
14 | __nsubplots = None | |
15 |
|
15 | |||
16 | WIDTH = None |
|
16 | WIDTH = None | |
17 | HEIGHT = None |
|
17 | HEIGHT = None | |
18 | WIDTHPROF = None |
|
18 | WIDTHPROF = None | |
19 | HEIGHTPROF = None |
|
19 | HEIGHTPROF = None | |
20 | PREFIX = 'cspc' |
|
20 | PREFIX = 'cspc' | |
21 |
|
21 | |||
22 | def __init__(self): |
|
22 | def __init__(self): | |
23 |
|
23 | |||
24 | self.__isConfig = False |
|
24 | self.__isConfig = False | |
25 | self.__nsubplots = 4 |
|
25 | self.__nsubplots = 4 | |
26 |
|
26 | |||
27 | self.WIDTH = 250 |
|
27 | self.WIDTH = 250 | |
28 | self.HEIGHT = 250 |
|
28 | self.HEIGHT = 250 | |
29 | self.WIDTHPROF = 0 |
|
29 | self.WIDTHPROF = 0 | |
30 | self.HEIGHTPROF = 0 |
|
30 | self.HEIGHTPROF = 0 | |
31 |
|
31 | |||
32 | def getSubplots(self): |
|
32 | def getSubplots(self): | |
33 |
|
33 | |||
34 | ncol = 4 |
|
34 | ncol = 4 | |
35 | nrow = self.nplots |
|
35 | nrow = self.nplots | |
36 |
|
36 | |||
37 | return nrow, ncol |
|
37 | return nrow, ncol | |
38 |
|
38 | |||
39 |
def setup(self, id |
|
39 | def setup(self, id, nplots, wintitle, showprofile=True, show=True): | |
40 |
|
40 | |||
41 | self.__showprofile = showprofile |
|
41 | self.__showprofile = showprofile | |
42 | self.nplots = nplots |
|
42 | self.nplots = nplots | |
43 |
|
43 | |||
44 | ncolspan = 1 |
|
44 | ncolspan = 1 | |
45 | colspan = 1 |
|
45 | colspan = 1 | |
46 |
|
46 | |||
47 |
self.createFigure(id |
|
47 | self.createFigure(id = id, | |
48 | wintitle = wintitle, |
|
48 | wintitle = wintitle, | |
49 | widthplot = self.WIDTH + self.WIDTHPROF, |
|
49 | widthplot = self.WIDTH + self.WIDTHPROF, | |
50 | heightplot = self.HEIGHT + self.HEIGHTPROF, |
|
50 | heightplot = self.HEIGHT + self.HEIGHTPROF, | |
51 | show=True) |
|
51 | show=True) | |
52 |
|
52 | |||
53 | nrow, ncol = self.getSubplots() |
|
53 | nrow, ncol = self.getSubplots() | |
54 |
|
54 | |||
55 | counter = 0 |
|
55 | counter = 0 | |
56 | for y in range(nrow): |
|
56 | for y in range(nrow): | |
57 | for x in range(ncol): |
|
57 | for x in range(ncol): | |
58 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1) |
|
58 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1) | |
59 |
|
59 | |||
60 | counter += 1 |
|
60 | counter += 1 | |
61 |
|
61 | |||
62 |
def run(self, dataOut, id |
|
62 | def run(self, dataOut, id, wintitle="", pairsList=None, showprofile='True', | |
63 | xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None, |
|
63 | xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None, | |
64 | save=False, figpath='./', figfile=None, |
|
64 | save=False, figpath='./', figfile=None, | |
65 | power_cmap='jet', coherence_cmap='jet', phase_cmap='RdBu_r', show=True): |
|
65 | power_cmap='jet', coherence_cmap='jet', phase_cmap='RdBu_r', show=True): | |
66 |
|
66 | |||
67 | """ |
|
67 | """ | |
68 |
|
68 | |||
69 | Input: |
|
69 | Input: | |
70 | dataOut : |
|
70 | dataOut : | |
71 |
id |
|
71 | id : | |
72 | wintitle : |
|
72 | wintitle : | |
73 | channelList : |
|
73 | channelList : | |
74 | showProfile : |
|
74 | showProfile : | |
75 | xmin : None, |
|
75 | xmin : None, | |
76 | xmax : None, |
|
76 | xmax : None, | |
77 | ymin : None, |
|
77 | ymin : None, | |
78 | ymax : None, |
|
78 | ymax : None, | |
79 | zmin : None, |
|
79 | zmin : None, | |
80 | zmax : None |
|
80 | zmax : None | |
81 | """ |
|
81 | """ | |
82 |
|
82 | |||
83 | if pairsList == None: |
|
83 | if pairsList == None: | |
84 | pairsIndexList = dataOut.pairsIndexList |
|
84 | pairsIndexList = dataOut.pairsIndexList | |
85 | else: |
|
85 | else: | |
86 | pairsIndexList = [] |
|
86 | pairsIndexList = [] | |
87 | for pair in pairsList: |
|
87 | for pair in pairsList: | |
88 | if pair not in dataOut.pairsList: |
|
88 | if pair not in dataOut.pairsList: | |
89 | raise ValueError, "Pair %s is not in dataOut.pairsList" %(pair) |
|
89 | raise ValueError, "Pair %s is not in dataOut.pairsList" %(pair) | |
90 | pairsIndexList.append(dataOut.pairsList.index(pair)) |
|
90 | pairsIndexList.append(dataOut.pairsList.index(pair)) | |
91 |
|
91 | |||
92 | if pairsIndexList == []: |
|
92 | if pairsIndexList == []: | |
93 | return |
|
93 | return | |
94 |
|
94 | |||
95 | if len(pairsIndexList) > 4: |
|
95 | if len(pairsIndexList) > 4: | |
96 | pairsIndexList = pairsIndexList[0:4] |
|
96 | pairsIndexList = pairsIndexList[0:4] | |
97 | factor = dataOut.normFactor |
|
97 | factor = dataOut.normFactor | |
98 | x = dataOut.getVelRange(1) |
|
98 | x = dataOut.getVelRange(1) | |
99 | y = dataOut.getHeiRange() |
|
99 | y = dataOut.getHeiRange() | |
100 | z = dataOut.data_spc[:,:,:]/factor |
|
100 | z = dataOut.data_spc[:,:,:]/factor | |
101 | # z = numpy.where(numpy.isfinite(z), z, numpy.NAN) |
|
101 | # z = numpy.where(numpy.isfinite(z), z, numpy.NAN) | |
102 | avg = numpy.abs(numpy.average(z, axis=1)) |
|
102 | avg = numpy.abs(numpy.average(z, axis=1)) | |
103 | noise = dataOut.getNoise()/factor |
|
103 | noise = dataOut.getNoise()/factor | |
104 |
|
104 | |||
105 | zdB = 10*numpy.log10(z) |
|
105 | zdB = 10*numpy.log10(z) | |
106 | avgdB = 10*numpy.log10(avg) |
|
106 | avgdB = 10*numpy.log10(avg) | |
107 | noisedB = 10*numpy.log10(noise) |
|
107 | noisedB = 10*numpy.log10(noise) | |
108 |
|
108 | |||
109 |
|
109 | |||
110 | #thisDatetime = dataOut.datatime |
|
110 | #thisDatetime = dataOut.datatime | |
111 | thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[1]) |
|
111 | thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[1]) | |
112 | title = wintitle + " Cross-Spectra: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) |
|
112 | title = wintitle + " Cross-Spectra: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) | |
113 | xlabel = "Velocity (m/s)" |
|
113 | xlabel = "Velocity (m/s)" | |
114 | ylabel = "Range (Km)" |
|
114 | ylabel = "Range (Km)" | |
115 |
|
115 | |||
116 | if not self.__isConfig: |
|
116 | if not self.__isConfig: | |
117 |
|
117 | |||
118 | nplots = len(pairsIndexList) |
|
118 | nplots = len(pairsIndexList) | |
119 |
|
119 | |||
120 |
self.setup(id |
|
120 | self.setup(id=id, | |
121 | nplots=nplots, |
|
121 | nplots=nplots, | |
122 | wintitle=wintitle, |
|
122 | wintitle=wintitle, | |
123 | showprofile=showprofile, |
|
123 | showprofile=showprofile, | |
124 | show=show) |
|
124 | show=show) | |
125 |
|
125 | |||
126 | if xmin == None: xmin = numpy.nanmin(x) |
|
126 | if xmin == None: xmin = numpy.nanmin(x) | |
127 | if xmax == None: xmax = numpy.nanmax(x) |
|
127 | if xmax == None: xmax = numpy.nanmax(x) | |
128 | if ymin == None: ymin = numpy.nanmin(y) |
|
128 | if ymin == None: ymin = numpy.nanmin(y) | |
129 | if ymax == None: ymax = numpy.nanmax(y) |
|
129 | if ymax == None: ymax = numpy.nanmax(y) | |
130 | if zmin == None: zmin = numpy.nanmin(avgdB)*0.9 |
|
130 | if zmin == None: zmin = numpy.nanmin(avgdB)*0.9 | |
131 | if zmax == None: zmax = numpy.nanmax(avgdB)*0.9 |
|
131 | if zmax == None: zmax = numpy.nanmax(avgdB)*0.9 | |
132 |
|
132 | |||
133 | self.__isConfig = True |
|
133 | self.__isConfig = True | |
134 |
|
134 | |||
135 | self.setWinTitle(title) |
|
135 | self.setWinTitle(title) | |
136 |
|
136 | |||
137 | for i in range(self.nplots): |
|
137 | for i in range(self.nplots): | |
138 | pair = dataOut.pairsList[pairsIndexList[i]] |
|
138 | pair = dataOut.pairsList[pairsIndexList[i]] | |
139 |
|
139 | |||
140 | title = "Channel %d: %4.2fdB" %(pair[0], noisedB[pair[0]]) |
|
140 | title = "Channel %d: %4.2fdB" %(pair[0], noisedB[pair[0]]) | |
141 | zdB = 10.*numpy.log10(dataOut.data_spc[pair[0],:,:]/factor) |
|
141 | zdB = 10.*numpy.log10(dataOut.data_spc[pair[0],:,:]/factor) | |
142 | axes0 = self.axesList[i*self.__nsubplots] |
|
142 | axes0 = self.axesList[i*self.__nsubplots] | |
143 | axes0.pcolor(x, y, zdB, |
|
143 | axes0.pcolor(x, y, zdB, | |
144 | xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax, |
|
144 | xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax, | |
145 | xlabel=xlabel, ylabel=ylabel, title=title, |
|
145 | xlabel=xlabel, ylabel=ylabel, title=title, | |
146 | ticksize=9, colormap=power_cmap, cblabel='') |
|
146 | ticksize=9, colormap=power_cmap, cblabel='') | |
147 |
|
147 | |||
148 | title = "Channel %d: %4.2fdB" %(pair[1], noisedB[pair[1]]) |
|
148 | title = "Channel %d: %4.2fdB" %(pair[1], noisedB[pair[1]]) | |
149 | zdB = 10.*numpy.log10(dataOut.data_spc[pair[1],:,:]/factor) |
|
149 | zdB = 10.*numpy.log10(dataOut.data_spc[pair[1],:,:]/factor) | |
150 | axes0 = self.axesList[i*self.__nsubplots+1] |
|
150 | axes0 = self.axesList[i*self.__nsubplots+1] | |
151 | axes0.pcolor(x, y, zdB, |
|
151 | axes0.pcolor(x, y, zdB, | |
152 | xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax, |
|
152 | xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax, | |
153 | xlabel=xlabel, ylabel=ylabel, title=title, |
|
153 | xlabel=xlabel, ylabel=ylabel, title=title, | |
154 | ticksize=9, colormap=power_cmap, cblabel='') |
|
154 | ticksize=9, colormap=power_cmap, cblabel='') | |
155 |
|
155 | |||
156 | coherenceComplex = dataOut.data_cspc[pairsIndexList[i],:,:]/numpy.sqrt(dataOut.data_spc[pair[0],:,:]*dataOut.data_spc[pair[1],:,:]) |
|
156 | coherenceComplex = dataOut.data_cspc[pairsIndexList[i],:,:]/numpy.sqrt(dataOut.data_spc[pair[0],:,:]*dataOut.data_spc[pair[1],:,:]) | |
157 | coherence = numpy.abs(coherenceComplex) |
|
157 | coherence = numpy.abs(coherenceComplex) | |
158 | # phase = numpy.arctan(-1*coherenceComplex.imag/coherenceComplex.real)*180/numpy.pi |
|
158 | # phase = numpy.arctan(-1*coherenceComplex.imag/coherenceComplex.real)*180/numpy.pi | |
159 | phase = numpy.arctan2(coherenceComplex.imag, coherenceComplex.real)*180/numpy.pi |
|
159 | phase = numpy.arctan2(coherenceComplex.imag, coherenceComplex.real)*180/numpy.pi | |
160 |
|
160 | |||
161 | title = "Coherence %d%d" %(pair[0], pair[1]) |
|
161 | title = "Coherence %d%d" %(pair[0], pair[1]) | |
162 | axes0 = self.axesList[i*self.__nsubplots+2] |
|
162 | axes0 = self.axesList[i*self.__nsubplots+2] | |
163 | axes0.pcolor(x, y, coherence, |
|
163 | axes0.pcolor(x, y, coherence, | |
164 | xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=0, zmax=1, |
|
164 | xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=0, zmax=1, | |
165 | xlabel=xlabel, ylabel=ylabel, title=title, |
|
165 | xlabel=xlabel, ylabel=ylabel, title=title, | |
166 | ticksize=9, colormap=coherence_cmap, cblabel='') |
|
166 | ticksize=9, colormap=coherence_cmap, cblabel='') | |
167 |
|
167 | |||
168 | title = "Phase %d%d" %(pair[0], pair[1]) |
|
168 | title = "Phase %d%d" %(pair[0], pair[1]) | |
169 | axes0 = self.axesList[i*self.__nsubplots+3] |
|
169 | axes0 = self.axesList[i*self.__nsubplots+3] | |
170 | axes0.pcolor(x, y, phase, |
|
170 | axes0.pcolor(x, y, phase, | |
171 | xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=-180, zmax=180, |
|
171 | xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=-180, zmax=180, | |
172 | xlabel=xlabel, ylabel=ylabel, title=title, |
|
172 | xlabel=xlabel, ylabel=ylabel, title=title, | |
173 | ticksize=9, colormap=phase_cmap, cblabel='') |
|
173 | ticksize=9, colormap=phase_cmap, cblabel='') | |
174 |
|
174 | |||
175 |
|
175 | |||
176 |
|
176 | |||
177 | self.draw() |
|
177 | self.draw() | |
178 |
|
178 | |||
179 | if save: |
|
179 | if save: | |
180 | date = thisDatetime.strftime("%Y%m%d_%H%M%S") |
|
180 | date = thisDatetime.strftime("%Y%m%d_%H%M%S") | |
181 | if figfile == None: |
|
181 | if figfile == None: | |
182 | figfile = self.getFilename(name = date) |
|
182 | figfile = self.getFilename(name = date) | |
183 |
|
183 | |||
184 | self.saveFigure(figpath, figfile) |
|
184 | self.saveFigure(figpath, figfile) | |
185 |
|
185 | |||
186 |
|
186 | |||
187 | class RTIPlot(Figure): |
|
187 | class RTIPlot(Figure): | |
188 |
|
188 | |||
189 | __isConfig = None |
|
189 | __isConfig = None | |
190 | __nsubplots = None |
|
190 | __nsubplots = None | |
191 |
|
191 | |||
192 | WIDTHPROF = None |
|
192 | WIDTHPROF = None | |
193 | HEIGHTPROF = None |
|
193 | HEIGHTPROF = None | |
194 | PREFIX = 'rti' |
|
194 | PREFIX = 'rti' | |
195 |
|
195 | |||
196 | def __init__(self): |
|
196 | def __init__(self): | |
197 |
|
197 | |||
198 | self.timerange = 2*60*60 |
|
198 | self.timerange = 2*60*60 | |
199 | self.__isConfig = False |
|
199 | self.__isConfig = False | |
200 | self.__nsubplots = 1 |
|
200 | self.__nsubplots = 1 | |
201 |
|
201 | |||
202 | self.WIDTH = 800 |
|
202 | self.WIDTH = 800 | |
203 | self.HEIGHT = 150 |
|
203 | self.HEIGHT = 150 | |
204 | self.WIDTHPROF = 120 |
|
204 | self.WIDTHPROF = 120 | |
205 | self.HEIGHTPROF = 0 |
|
205 | self.HEIGHTPROF = 0 | |
206 |
self.counter |
|
206 | self.counter_imagwr = 0 | |
207 |
|
207 | |||
208 | def getSubplots(self): |
|
208 | def getSubplots(self): | |
209 |
|
209 | |||
210 | ncol = 1 |
|
210 | ncol = 1 | |
211 | nrow = self.nplots |
|
211 | nrow = self.nplots | |
212 |
|
212 | |||
213 | return nrow, ncol |
|
213 | return nrow, ncol | |
214 |
|
214 | |||
215 |
def setup(self, id |
|
215 | def setup(self, id, nplots, wintitle, showprofile=True, show=True): | |
216 |
|
216 | |||
217 | self.__showprofile = showprofile |
|
217 | self.__showprofile = showprofile | |
218 | self.nplots = nplots |
|
218 | self.nplots = nplots | |
219 |
|
219 | |||
220 | ncolspan = 1 |
|
220 | ncolspan = 1 | |
221 | colspan = 1 |
|
221 | colspan = 1 | |
222 | if showprofile: |
|
222 | if showprofile: | |
223 | ncolspan = 7 |
|
223 | ncolspan = 7 | |
224 | colspan = 6 |
|
224 | colspan = 6 | |
225 | self.__nsubplots = 2 |
|
225 | self.__nsubplots = 2 | |
226 |
|
226 | |||
227 |
self.createFigure(id |
|
227 | self.createFigure(id = id, | |
228 | wintitle = wintitle, |
|
228 | wintitle = wintitle, | |
229 | widthplot = self.WIDTH + self.WIDTHPROF, |
|
229 | widthplot = self.WIDTH + self.WIDTHPROF, | |
230 | heightplot = self.HEIGHT + self.HEIGHTPROF, |
|
230 | heightplot = self.HEIGHT + self.HEIGHTPROF, | |
231 | show=show) |
|
231 | show=show) | |
232 |
|
232 | |||
233 | nrow, ncol = self.getSubplots() |
|
233 | nrow, ncol = self.getSubplots() | |
234 |
|
234 | |||
235 | counter = 0 |
|
235 | counter = 0 | |
236 | for y in range(nrow): |
|
236 | for y in range(nrow): | |
237 | for x in range(ncol): |
|
237 | for x in range(ncol): | |
238 |
|
238 | |||
239 | if counter >= self.nplots: |
|
239 | if counter >= self.nplots: | |
240 | break |
|
240 | break | |
241 |
|
241 | |||
242 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1) |
|
242 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1) | |
243 |
|
243 | |||
244 | if showprofile: |
|
244 | if showprofile: | |
245 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1) |
|
245 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1) | |
246 |
|
246 | |||
247 | counter += 1 |
|
247 | counter += 1 | |
248 |
|
248 | |||
249 |
def run(self, dataOut, id |
|
249 | def run(self, dataOut, id, wintitle="", channelList=None, showprofile='True', | |
250 | xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None, |
|
250 | xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None, | |
251 | timerange=None, |
|
251 | timerange=None, | |
252 |
save=False, figpath='./', figfile=None, ftp=False, |
|
252 | save=False, figpath='./', figfile=None, ftp=False, res_imagwr=1, show=True): | |
253 |
|
253 | |||
254 | """ |
|
254 | """ | |
255 |
|
255 | |||
256 | Input: |
|
256 | Input: | |
257 | dataOut : |
|
257 | dataOut : | |
258 |
id |
|
258 | id : | |
259 | wintitle : |
|
259 | wintitle : | |
260 | channelList : |
|
260 | channelList : | |
261 | showProfile : |
|
261 | showProfile : | |
262 | xmin : None, |
|
262 | xmin : None, | |
263 | xmax : None, |
|
263 | xmax : None, | |
264 | ymin : None, |
|
264 | ymin : None, | |
265 | ymax : None, |
|
265 | ymax : None, | |
266 | zmin : None, |
|
266 | zmin : None, | |
267 | zmax : None |
|
267 | zmax : None | |
268 | """ |
|
268 | """ | |
269 |
|
269 | |||
270 | if channelList == None: |
|
270 | if channelList == None: | |
271 | channelIndexList = dataOut.channelIndexList |
|
271 | channelIndexList = dataOut.channelIndexList | |
272 | else: |
|
272 | else: | |
273 | channelIndexList = [] |
|
273 | channelIndexList = [] | |
274 | for channel in channelList: |
|
274 | for channel in channelList: | |
275 | if channel not in dataOut.channelList: |
|
275 | if channel not in dataOut.channelList: | |
276 | raise ValueError, "Channel %d is not in dataOut.channelList" |
|
276 | raise ValueError, "Channel %d is not in dataOut.channelList" | |
277 | channelIndexList.append(dataOut.channelList.index(channel)) |
|
277 | channelIndexList.append(dataOut.channelList.index(channel)) | |
278 |
|
278 | |||
279 | if timerange != None: |
|
279 | if timerange != None: | |
280 | self.timerange = timerange |
|
280 | self.timerange = timerange | |
281 |
|
281 | |||
282 | tmin = None |
|
282 | tmin = None | |
283 | tmax = None |
|
283 | tmax = None | |
284 | factor = dataOut.normFactor |
|
284 | factor = dataOut.normFactor | |
285 | x = dataOut.getTimeRange() |
|
285 | x = dataOut.getTimeRange() | |
286 | y = dataOut.getHeiRange() |
|
286 | y = dataOut.getHeiRange() | |
287 |
|
287 | |||
288 | z = dataOut.data_spc[channelIndexList,:,:]/factor |
|
288 | z = dataOut.data_spc[channelIndexList,:,:]/factor | |
289 | z = numpy.where(numpy.isfinite(z), z, numpy.NAN) |
|
289 | z = numpy.where(numpy.isfinite(z), z, numpy.NAN) | |
290 | avg = numpy.average(z, axis=1) |
|
290 | avg = numpy.average(z, axis=1) | |
291 |
|
291 | |||
292 | avgdB = 10.*numpy.log10(avg) |
|
292 | avgdB = 10.*numpy.log10(avg) | |
293 |
|
293 | |||
294 |
|
294 | |||
295 | # thisDatetime = dataOut.datatime |
|
295 | # thisDatetime = dataOut.datatime | |
296 | thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[1]) |
|
296 | thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[1]) | |
297 | title = wintitle + " RTI: %s" %(thisDatetime.strftime("%d-%b-%Y")) |
|
297 | title = wintitle + " RTI: %s" %(thisDatetime.strftime("%d-%b-%Y")) | |
298 | xlabel = "" |
|
298 | xlabel = "" | |
299 | ylabel = "Range (Km)" |
|
299 | ylabel = "Range (Km)" | |
300 |
|
300 | |||
301 | if not self.__isConfig: |
|
301 | if not self.__isConfig: | |
302 |
|
302 | |||
303 | nplots = len(channelIndexList) |
|
303 | nplots = len(channelIndexList) | |
304 |
|
304 | |||
305 |
self.setup(id |
|
305 | self.setup(id=id, | |
306 | nplots=nplots, |
|
306 | nplots=nplots, | |
307 | wintitle=wintitle, |
|
307 | wintitle=wintitle, | |
308 | showprofile=showprofile, |
|
308 | showprofile=showprofile, | |
309 | show=show) |
|
309 | show=show) | |
310 |
|
310 | |||
311 | tmin, tmax = self.getTimeLim(x, xmin, xmax) |
|
311 | tmin, tmax = self.getTimeLim(x, xmin, xmax) | |
312 | if ymin == None: ymin = numpy.nanmin(y) |
|
312 | if ymin == None: ymin = numpy.nanmin(y) | |
313 | if ymax == None: ymax = numpy.nanmax(y) |
|
313 | if ymax == None: ymax = numpy.nanmax(y) | |
314 | if zmin == None: zmin = numpy.nanmin(avgdB)*0.9 |
|
314 | if zmin == None: zmin = numpy.nanmin(avgdB)*0.9 | |
315 | if zmax == None: zmax = numpy.nanmax(avgdB)*0.9 |
|
315 | if zmax == None: zmax = numpy.nanmax(avgdB)*0.9 | |
316 |
|
316 | |||
317 | self.name = thisDatetime.strftime("%Y%m%d_%H%M%S") |
|
317 | self.name = thisDatetime.strftime("%Y%m%d_%H%M%S") | |
318 | self.__isConfig = True |
|
318 | self.__isConfig = True | |
319 |
|
319 | |||
320 |
|
320 | |||
321 | self.setWinTitle(title) |
|
321 | self.setWinTitle(title) | |
322 |
|
322 | |||
323 | for i in range(self.nplots): |
|
323 | for i in range(self.nplots): | |
324 | title = "Channel %d: %s" %(dataOut.channelList[i]+1, thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) |
|
324 | title = "Channel %d: %s" %(dataOut.channelList[i]+1, thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) | |
325 | axes = self.axesList[i*self.__nsubplots] |
|
325 | axes = self.axesList[i*self.__nsubplots] | |
326 | zdB = avgdB[i].reshape((1,-1)) |
|
326 | zdB = avgdB[i].reshape((1,-1)) | |
327 | axes.pcolorbuffer(x, y, zdB, |
|
327 | axes.pcolorbuffer(x, y, zdB, | |
328 | xmin=tmin, xmax=tmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax, |
|
328 | xmin=tmin, xmax=tmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax, | |
329 | xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True, |
|
329 | xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True, | |
330 | ticksize=9, cblabel='', cbsize="1%") |
|
330 | ticksize=9, cblabel='', cbsize="1%") | |
331 |
|
331 | |||
332 | if self.__showprofile: |
|
332 | if self.__showprofile: | |
333 | axes = self.axesList[i*self.__nsubplots +1] |
|
333 | axes = self.axesList[i*self.__nsubplots +1] | |
334 | axes.pline(avgdB[i], y, |
|
334 | axes.pline(avgdB[i], y, | |
335 | xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax, |
|
335 | xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax, | |
336 | xlabel='dB', ylabel='', title='', |
|
336 | xlabel='dB', ylabel='', title='', | |
337 | ytick_visible=False, |
|
337 | ytick_visible=False, | |
338 | grid='x') |
|
338 | grid='x') | |
339 |
|
339 | |||
340 | self.draw() |
|
340 | self.draw() | |
341 |
|
341 | |||
342 | if save: |
|
342 | if save: | |
343 |
|
343 | |||
344 | if figfile == None: |
|
344 | self.counter_imagwr += 1 | |
345 | figfile = self.getFilename(name = self.name) |
|
345 | if (self.counter_imagwr==res_imagwr): | |
346 |
|
346 | |||
347 | self.saveFigure(figpath, figfile) |
|
347 | ||
348 |
|
348 | fig_file = self.getFilename(name = self.name) | ||
349 | self.counterftp += 1 |
|
349 | self.saveFigure(figpath, fig_file) | |
350 | if (ftp and (self.counterftp==ftpratio)): |
|
350 | if ftp: | |
351 |
|
|
351 | self.saveFigure(figpath, figfile) | |
352 | self.sendByFTP(figfilename) |
|
352 | figfilename = os.path.join(figpath,figfile) | |
353 | self.counterftp = 0 |
|
353 | self.sendByFTP(figfilename) | |
|
354 | ||||
|
355 | self.counter_imagwr = 0 | |||
354 |
|
356 | |||
355 | if x[1] + (x[1]-x[0]) >= self.axesList[0].xmax: |
|
357 | if x[1] + (x[1]-x[0]) >= self.axesList[0].xmax: | |
356 | self.__isConfig = False |
|
358 | self.__isConfig = False | |
357 |
|
359 | |||
358 | class SpectraPlot(Figure): |
|
360 | class SpectraPlot(Figure): | |
359 |
|
361 | |||
360 | __isConfig = None |
|
362 | __isConfig = None | |
361 | __nsubplots = None |
|
363 | __nsubplots = None | |
362 |
|
364 | |||
363 | WIDTHPROF = None |
|
365 | WIDTHPROF = None | |
364 | HEIGHTPROF = None |
|
366 | HEIGHTPROF = None | |
365 | PREFIX = 'spc' |
|
367 | PREFIX = 'spc' | |
366 |
|
368 | |||
367 | def __init__(self): |
|
369 | def __init__(self): | |
368 |
|
370 | |||
369 | self.__isConfig = False |
|
371 | self.__isConfig = False | |
370 | self.__nsubplots = 1 |
|
372 | self.__nsubplots = 1 | |
371 |
|
373 | |||
372 | self.WIDTH = 230 |
|
374 | self.WIDTH = 230 | |
373 | self.HEIGHT = 250 |
|
375 | self.HEIGHT = 250 | |
374 | self.WIDTHPROF = 120 |
|
376 | self.WIDTHPROF = 120 | |
375 | self.HEIGHTPROF = 0 |
|
377 | self.HEIGHTPROF = 0 | |
376 |
|
378 | |||
377 | def getSubplots(self): |
|
379 | def getSubplots(self): | |
378 |
|
380 | |||
379 | ncol = int(numpy.sqrt(self.nplots)+0.9) |
|
381 | ncol = int(numpy.sqrt(self.nplots)+0.9) | |
380 | nrow = int(self.nplots*1./ncol + 0.9) |
|
382 | nrow = int(self.nplots*1./ncol + 0.9) | |
381 |
|
383 | |||
382 | return nrow, ncol |
|
384 | return nrow, ncol | |
383 |
|
385 | |||
384 |
def setup(self, id |
|
386 | def setup(self, id, nplots, wintitle, showprofile=True, show=True): | |
385 |
|
387 | |||
386 | self.__showprofile = showprofile |
|
388 | self.__showprofile = showprofile | |
387 | self.nplots = nplots |
|
389 | self.nplots = nplots | |
388 |
|
390 | |||
389 | ncolspan = 1 |
|
391 | ncolspan = 1 | |
390 | colspan = 1 |
|
392 | colspan = 1 | |
391 | if showprofile: |
|
393 | if showprofile: | |
392 | ncolspan = 3 |
|
394 | ncolspan = 3 | |
393 | colspan = 2 |
|
395 | colspan = 2 | |
394 | self.__nsubplots = 2 |
|
396 | self.__nsubplots = 2 | |
395 |
|
397 | |||
396 |
self.createFigure(id |
|
398 | self.createFigure(id = id, | |
397 | wintitle = wintitle, |
|
399 | wintitle = wintitle, | |
398 | widthplot = self.WIDTH + self.WIDTHPROF, |
|
400 | widthplot = self.WIDTH + self.WIDTHPROF, | |
399 | heightplot = self.HEIGHT + self.HEIGHTPROF, |
|
401 | heightplot = self.HEIGHT + self.HEIGHTPROF, | |
400 | show=show) |
|
402 | show=show) | |
401 |
|
403 | |||
402 | nrow, ncol = self.getSubplots() |
|
404 | nrow, ncol = self.getSubplots() | |
403 |
|
405 | |||
404 | counter = 0 |
|
406 | counter = 0 | |
405 | for y in range(nrow): |
|
407 | for y in range(nrow): | |
406 | for x in range(ncol): |
|
408 | for x in range(ncol): | |
407 |
|
409 | |||
408 | if counter >= self.nplots: |
|
410 | if counter >= self.nplots: | |
409 | break |
|
411 | break | |
410 |
|
412 | |||
411 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1) |
|
413 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1) | |
412 |
|
414 | |||
413 | if showprofile: |
|
415 | if showprofile: | |
414 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1) |
|
416 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1) | |
415 |
|
417 | |||
416 | counter += 1 |
|
418 | counter += 1 | |
417 |
|
419 | |||
418 |
def run(self, dataOut, id |
|
420 | def run(self, dataOut, id, wintitle="", channelList=None, showprofile='True', | |
419 | xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None, |
|
421 | xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None, | |
420 | save=False, figpath='./', figfile=None, show=True): |
|
422 | save=False, figpath='./', figfile=None, show=True): | |
421 |
|
423 | |||
422 | """ |
|
424 | """ | |
423 |
|
425 | |||
424 | Input: |
|
426 | Input: | |
425 | dataOut : |
|
427 | dataOut : | |
426 |
id |
|
428 | id : | |
427 | wintitle : |
|
429 | wintitle : | |
428 | channelList : |
|
430 | channelList : | |
429 | showProfile : |
|
431 | showProfile : | |
430 | xmin : None, |
|
432 | xmin : None, | |
431 | xmax : None, |
|
433 | xmax : None, | |
432 | ymin : None, |
|
434 | ymin : None, | |
433 | ymax : None, |
|
435 | ymax : None, | |
434 | zmin : None, |
|
436 | zmin : None, | |
435 | zmax : None |
|
437 | zmax : None | |
436 | """ |
|
438 | """ | |
437 |
|
439 | |||
438 | if channelList == None: |
|
440 | if channelList == None: | |
439 | channelIndexList = dataOut.channelIndexList |
|
441 | channelIndexList = dataOut.channelIndexList | |
440 | else: |
|
442 | else: | |
441 | channelIndexList = [] |
|
443 | channelIndexList = [] | |
442 | for channel in channelList: |
|
444 | for channel in channelList: | |
443 | if channel not in dataOut.channelList: |
|
445 | if channel not in dataOut.channelList: | |
444 | raise ValueError, "Channel %d is not in dataOut.channelList" |
|
446 | raise ValueError, "Channel %d is not in dataOut.channelList" | |
445 | channelIndexList.append(dataOut.channelList.index(channel)) |
|
447 | channelIndexList.append(dataOut.channelList.index(channel)) | |
446 | factor = dataOut.normFactor |
|
448 | factor = dataOut.normFactor | |
447 | x = dataOut.getVelRange(1) |
|
449 | x = dataOut.getVelRange(1) | |
448 | y = dataOut.getHeiRange() |
|
450 | y = dataOut.getHeiRange() | |
449 |
|
451 | |||
450 | z = dataOut.data_spc[channelIndexList,:,:]/factor |
|
452 | z = dataOut.data_spc[channelIndexList,:,:]/factor | |
451 | z = numpy.where(numpy.isfinite(z), z, numpy.NAN) |
|
453 | z = numpy.where(numpy.isfinite(z), z, numpy.NAN) | |
452 | avg = numpy.average(z, axis=1) |
|
454 | avg = numpy.average(z, axis=1) | |
453 | noise = dataOut.getNoise()/factor |
|
455 | noise = dataOut.getNoise()/factor | |
454 |
|
456 | |||
455 | zdB = 10*numpy.log10(z) |
|
457 | zdB = 10*numpy.log10(z) | |
456 | avgdB = 10*numpy.log10(avg) |
|
458 | avgdB = 10*numpy.log10(avg) | |
457 | noisedB = 10*numpy.log10(noise) |
|
459 | noisedB = 10*numpy.log10(noise) | |
458 |
|
460 | |||
459 | #thisDatetime = dataOut.datatime |
|
461 | #thisDatetime = dataOut.datatime | |
460 | thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[1]) |
|
462 | thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[1]) | |
461 | title = wintitle + " Spectra: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) |
|
463 | title = wintitle + " Spectra: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) | |
462 | xlabel = "Velocity (m/s)" |
|
464 | xlabel = "Velocity (m/s)" | |
463 | ylabel = "Range (Km)" |
|
465 | ylabel = "Range (Km)" | |
464 |
|
466 | |||
465 | if not self.__isConfig: |
|
467 | if not self.__isConfig: | |
466 |
|
468 | |||
467 | nplots = len(channelIndexList) |
|
469 | nplots = len(channelIndexList) | |
468 |
|
470 | |||
469 |
self.setup(id |
|
471 | self.setup(id=id, | |
470 | nplots=nplots, |
|
472 | nplots=nplots, | |
471 | wintitle=wintitle, |
|
473 | wintitle=wintitle, | |
472 | showprofile=showprofile, |
|
474 | showprofile=showprofile, | |
473 | show=show) |
|
475 | show=show) | |
474 |
|
476 | |||
475 | if xmin == None: xmin = numpy.nanmin(x) |
|
477 | if xmin == None: xmin = numpy.nanmin(x) | |
476 | if xmax == None: xmax = numpy.nanmax(x) |
|
478 | if xmax == None: xmax = numpy.nanmax(x) | |
477 | if ymin == None: ymin = numpy.nanmin(y) |
|
479 | if ymin == None: ymin = numpy.nanmin(y) | |
478 | if ymax == None: ymax = numpy.nanmax(y) |
|
480 | if ymax == None: ymax = numpy.nanmax(y) | |
479 | if zmin == None: zmin = numpy.nanmin(avgdB)*0.9 |
|
481 | if zmin == None: zmin = numpy.nanmin(avgdB)*0.9 | |
480 | if zmax == None: zmax = numpy.nanmax(avgdB)*0.9 |
|
482 | if zmax == None: zmax = numpy.nanmax(avgdB)*0.9 | |
481 |
|
483 | |||
482 | self.__isConfig = True |
|
484 | self.__isConfig = True | |
483 |
|
485 | |||
484 | self.setWinTitle(title) |
|
486 | self.setWinTitle(title) | |
485 |
|
487 | |||
486 | for i in range(self.nplots): |
|
488 | for i in range(self.nplots): | |
487 | title = "Channel %d: %4.2fdB" %(dataOut.channelList[i]+1, noisedB[i]) |
|
489 | title = "Channel %d: %4.2fdB" %(dataOut.channelList[i]+1, noisedB[i]) | |
488 | axes = self.axesList[i*self.__nsubplots] |
|
490 | axes = self.axesList[i*self.__nsubplots] | |
489 | axes.pcolor(x, y, zdB[i,:,:], |
|
491 | axes.pcolor(x, y, zdB[i,:,:], | |
490 | xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax, |
|
492 | xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax, | |
491 | xlabel=xlabel, ylabel=ylabel, title=title, |
|
493 | xlabel=xlabel, ylabel=ylabel, title=title, | |
492 | ticksize=9, cblabel='') |
|
494 | ticksize=9, cblabel='') | |
493 |
|
495 | |||
494 | if self.__showprofile: |
|
496 | if self.__showprofile: | |
495 | axes = self.axesList[i*self.__nsubplots +1] |
|
497 | axes = self.axesList[i*self.__nsubplots +1] | |
496 | axes.pline(avgdB[i], y, |
|
498 | axes.pline(avgdB[i], y, | |
497 | xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax, |
|
499 | xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax, | |
498 | xlabel='dB', ylabel='', title='', |
|
500 | xlabel='dB', ylabel='', title='', | |
499 | ytick_visible=False, |
|
501 | ytick_visible=False, | |
500 | grid='x') |
|
502 | grid='x') | |
501 |
|
503 | |||
502 | noiseline = numpy.repeat(noisedB[i], len(y)) |
|
504 | noiseline = numpy.repeat(noisedB[i], len(y)) | |
503 | axes.addpline(noiseline, y, idline=1, color="black", linestyle="dashed", lw=2) |
|
505 | axes.addpline(noiseline, y, idline=1, color="black", linestyle="dashed", lw=2) | |
504 |
|
506 | |||
505 | self.draw() |
|
507 | self.draw() | |
506 |
|
508 | |||
507 | if save: |
|
509 | if save: | |
508 | date = thisDatetime.strftime("%Y%m%d_%H%M%S") |
|
510 | date = thisDatetime.strftime("%Y%m%d_%H%M%S") | |
509 | if figfile == None: |
|
511 | if figfile == None: | |
510 | figfile = self.getFilename(name = date) |
|
512 | figfile = self.getFilename(name = date) | |
511 |
|
513 | |||
512 | self.saveFigure(figpath, figfile) |
|
514 | self.saveFigure(figpath, figfile) | |
513 |
|
515 | |||
514 | class Scope(Figure): |
|
516 | class Scope(Figure): | |
515 |
|
517 | |||
516 | __isConfig = None |
|
518 | __isConfig = None | |
517 |
|
519 | |||
518 | def __init__(self): |
|
520 | def __init__(self): | |
519 |
|
521 | |||
520 | self.__isConfig = False |
|
522 | self.__isConfig = False | |
521 | self.WIDTH = 600 |
|
523 | self.WIDTH = 600 | |
522 | self.HEIGHT = 200 |
|
524 | self.HEIGHT = 200 | |
523 |
|
525 | |||
524 | def getSubplots(self): |
|
526 | def getSubplots(self): | |
525 |
|
527 | |||
526 | nrow = self.nplots |
|
528 | nrow = self.nplots | |
527 | ncol = 3 |
|
529 | ncol = 3 | |
528 | return nrow, ncol |
|
530 | return nrow, ncol | |
529 |
|
531 | |||
530 |
def setup(self, id |
|
532 | def setup(self, id, nplots, wintitle, show): | |
531 |
|
533 | |||
532 | self.nplots = nplots |
|
534 | self.nplots = nplots | |
533 |
|
535 | |||
534 |
self.createFigure(id |
|
536 | self.createFigure(id=id, | |
535 | wintitle=wintitle, |
|
537 | wintitle=wintitle, | |
536 | show=show) |
|
538 | show=show) | |
537 |
|
539 | |||
538 | nrow,ncol = self.getSubplots() |
|
540 | nrow,ncol = self.getSubplots() | |
539 | colspan = 3 |
|
541 | colspan = 3 | |
540 | rowspan = 1 |
|
542 | rowspan = 1 | |
541 |
|
543 | |||
542 | for i in range(nplots): |
|
544 | for i in range(nplots): | |
543 | self.addAxes(nrow, ncol, i, 0, colspan, rowspan) |
|
545 | self.addAxes(nrow, ncol, i, 0, colspan, rowspan) | |
544 |
|
546 | |||
545 |
|
547 | |||
546 |
|
548 | |||
547 |
def run(self, dataOut, id |
|
549 | def run(self, dataOut, id, wintitle="", channelList=None, | |
548 | xmin=None, xmax=None, ymin=None, ymax=None, save=False, |
|
550 | xmin=None, xmax=None, ymin=None, ymax=None, save=False, | |
549 | figpath='./', figfile=None, show=True): |
|
551 | figpath='./', figfile=None, show=True): | |
550 |
|
552 | |||
551 | """ |
|
553 | """ | |
552 |
|
554 | |||
553 | Input: |
|
555 | Input: | |
554 | dataOut : |
|
556 | dataOut : | |
555 |
id |
|
557 | id : | |
556 | wintitle : |
|
558 | wintitle : | |
557 | channelList : |
|
559 | channelList : | |
558 | xmin : None, |
|
560 | xmin : None, | |
559 | xmax : None, |
|
561 | xmax : None, | |
560 | ymin : None, |
|
562 | ymin : None, | |
561 | ymax : None, |
|
563 | ymax : None, | |
562 | """ |
|
564 | """ | |
563 |
|
565 | |||
564 | if channelList == None: |
|
566 | if channelList == None: | |
565 | channelIndexList = dataOut.channelIndexList |
|
567 | channelIndexList = dataOut.channelIndexList | |
566 | else: |
|
568 | else: | |
567 | channelIndexList = [] |
|
569 | channelIndexList = [] | |
568 | for channel in channelList: |
|
570 | for channel in channelList: | |
569 | if channel not in dataOut.channelList: |
|
571 | if channel not in dataOut.channelList: | |
570 | raise ValueError, "Channel %d is not in dataOut.channelList" |
|
572 | raise ValueError, "Channel %d is not in dataOut.channelList" | |
571 | channelIndexList.append(dataOut.channelList.index(channel)) |
|
573 | channelIndexList.append(dataOut.channelList.index(channel)) | |
572 |
|
574 | |||
573 | x = dataOut.heightList |
|
575 | x = dataOut.heightList | |
574 | y = dataOut.data[channelIndexList,:] * numpy.conjugate(dataOut.data[channelIndexList,:]) |
|
576 | y = dataOut.data[channelIndexList,:] * numpy.conjugate(dataOut.data[channelIndexList,:]) | |
575 | y = y.real |
|
577 | y = y.real | |
576 |
|
578 | |||
577 | #thisDatetime = dataOut.datatime |
|
579 | #thisDatetime = dataOut.datatime | |
578 | thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[1]) |
|
580 | thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[1]) | |
579 | title = wintitle + " Scope: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) |
|
581 | title = wintitle + " Scope: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) | |
580 | xlabel = "Range (Km)" |
|
582 | xlabel = "Range (Km)" | |
581 | ylabel = "Intensity" |
|
583 | ylabel = "Intensity" | |
582 |
|
584 | |||
583 | if not self.__isConfig: |
|
585 | if not self.__isConfig: | |
584 | nplots = len(channelIndexList) |
|
586 | nplots = len(channelIndexList) | |
585 |
|
587 | |||
586 |
self.setup(id |
|
588 | self.setup(id=id, | |
587 | nplots=nplots, |
|
589 | nplots=nplots, | |
588 | wintitle=wintitle, |
|
590 | wintitle=wintitle, | |
589 | show=show) |
|
591 | show=show) | |
590 |
|
592 | |||
591 | if xmin == None: xmin = numpy.nanmin(x) |
|
593 | if xmin == None: xmin = numpy.nanmin(x) | |
592 | if xmax == None: xmax = numpy.nanmax(x) |
|
594 | if xmax == None: xmax = numpy.nanmax(x) | |
593 | if ymin == None: ymin = numpy.nanmin(y) |
|
595 | if ymin == None: ymin = numpy.nanmin(y) | |
594 | if ymax == None: ymax = numpy.nanmax(y) |
|
596 | if ymax == None: ymax = numpy.nanmax(y) | |
595 |
|
597 | |||
596 | self.__isConfig = True |
|
598 | self.__isConfig = True | |
597 |
|
599 | |||
598 | self.setWinTitle(title) |
|
600 | self.setWinTitle(title) | |
599 |
|
601 | |||
600 | for i in range(len(self.axesList)): |
|
602 | for i in range(len(self.axesList)): | |
601 | title = "Channel %d" %(i) |
|
603 | title = "Channel %d" %(i) | |
602 | axes = self.axesList[i] |
|
604 | axes = self.axesList[i] | |
603 | ychannel = y[i,:] |
|
605 | ychannel = y[i,:] | |
604 | axes.pline(x, ychannel, |
|
606 | axes.pline(x, ychannel, | |
605 | xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, |
|
607 | xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, | |
606 | xlabel=xlabel, ylabel=ylabel, title=title) |
|
608 | xlabel=xlabel, ylabel=ylabel, title=title) | |
607 |
|
609 | |||
608 | self.draw() |
|
610 | self.draw() | |
609 |
|
611 | |||
610 | if save: |
|
612 | if save: | |
611 | date = thisDatetime.strftime("%Y%m%d_%H%M%S") |
|
613 | date = thisDatetime.strftime("%Y%m%d_%H%M%S") | |
612 | if figfile == None: |
|
614 | if figfile == None: | |
613 | figfile = self.getFilename(name = date) |
|
615 | figfile = self.getFilename(name = date) | |
614 |
|
616 | |||
615 | self.saveFigure(figpath, figfile) |
|
617 | self.saveFigure(figpath, figfile) | |
616 |
|
618 | |||
617 | class PowerProfilePlot(Figure): |
|
619 | class PowerProfilePlot(Figure): | |
618 | __isConfig = None |
|
620 | __isConfig = None | |
619 | __nsubplots = None |
|
621 | __nsubplots = None | |
620 |
|
622 | |||
621 | WIDTHPROF = None |
|
623 | WIDTHPROF = None | |
622 | HEIGHTPROF = None |
|
624 | HEIGHTPROF = None | |
623 | PREFIX = 'spcprofile' |
|
625 | PREFIX = 'spcprofile' | |
624 |
|
626 | |||
625 | def __init__(self): |
|
627 | def __init__(self): | |
626 | self.__isConfig = False |
|
628 | self.__isConfig = False | |
627 | self.__nsubplots = 1 |
|
629 | self.__nsubplots = 1 | |
628 |
|
630 | |||
629 | self.WIDTH = 300 |
|
631 | self.WIDTH = 300 | |
630 | self.HEIGHT = 500 |
|
632 | self.HEIGHT = 500 | |
631 |
|
633 | |||
632 | def getSubplots(self): |
|
634 | def getSubplots(self): | |
633 | ncol = 1 |
|
635 | ncol = 1 | |
634 | nrow = 1 |
|
636 | nrow = 1 | |
635 |
|
637 | |||
636 | return nrow, ncol |
|
638 | return nrow, ncol | |
637 |
|
639 | |||
638 |
def setup(self, id |
|
640 | def setup(self, id, nplots, wintitle, show): | |
639 |
|
641 | |||
640 | self.nplots = nplots |
|
642 | self.nplots = nplots | |
641 |
|
643 | |||
642 | ncolspan = 1 |
|
644 | ncolspan = 1 | |
643 | colspan = 1 |
|
645 | colspan = 1 | |
644 |
|
646 | |||
645 |
self.createFigure(id |
|
647 | self.createFigure(id = id, | |
646 | wintitle = wintitle, |
|
648 | wintitle = wintitle, | |
647 | widthplot = self.WIDTH, |
|
649 | widthplot = self.WIDTH, | |
648 | heightplot = self.HEIGHT, |
|
650 | heightplot = self.HEIGHT, | |
649 | show=show) |
|
651 | show=show) | |
650 |
|
652 | |||
651 | nrow, ncol = self.getSubplots() |
|
653 | nrow, ncol = self.getSubplots() | |
652 |
|
654 | |||
653 | counter = 0 |
|
655 | counter = 0 | |
654 | for y in range(nrow): |
|
656 | for y in range(nrow): | |
655 | for x in range(ncol): |
|
657 | for x in range(ncol): | |
656 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1) |
|
658 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1) | |
657 |
|
659 | |||
658 |
def run(self, dataOut, id |
|
660 | def run(self, dataOut, id, wintitle="", channelList=None, | |
659 | xmin=None, xmax=None, ymin=None, ymax=None, |
|
661 | xmin=None, xmax=None, ymin=None, ymax=None, | |
660 | save=False, figpath='./', figfile=None, show=True): |
|
662 | save=False, figpath='./', figfile=None, show=True): | |
661 |
|
663 | |||
662 | if channelList == None: |
|
664 | if channelList == None: | |
663 | channelIndexList = dataOut.channelIndexList |
|
665 | channelIndexList = dataOut.channelIndexList | |
664 | channelList = dataOut.channelList |
|
666 | channelList = dataOut.channelList | |
665 | else: |
|
667 | else: | |
666 | channelIndexList = [] |
|
668 | channelIndexList = [] | |
667 | for channel in channelList: |
|
669 | for channel in channelList: | |
668 | if channel not in dataOut.channelList: |
|
670 | if channel not in dataOut.channelList: | |
669 | raise ValueError, "Channel %d is not in dataOut.channelList" |
|
671 | raise ValueError, "Channel %d is not in dataOut.channelList" | |
670 | channelIndexList.append(dataOut.channelList.index(channel)) |
|
672 | channelIndexList.append(dataOut.channelList.index(channel)) | |
671 |
|
673 | |||
672 | factor = dataOut.normFactor |
|
674 | factor = dataOut.normFactor | |
673 | y = dataOut.getHeiRange() |
|
675 | y = dataOut.getHeiRange() | |
674 | x = dataOut.data_spc[channelIndexList,:,:]/factor |
|
676 | x = dataOut.data_spc[channelIndexList,:,:]/factor | |
675 | x = numpy.where(numpy.isfinite(x), x, numpy.NAN) |
|
677 | x = numpy.where(numpy.isfinite(x), x, numpy.NAN) | |
676 | avg = numpy.average(x, axis=1) |
|
678 | avg = numpy.average(x, axis=1) | |
677 |
|
679 | |||
678 | avgdB = 10*numpy.log10(avg) |
|
680 | avgdB = 10*numpy.log10(avg) | |
679 |
|
681 | |||
680 | #thisDatetime = dataOut.datatime |
|
682 | #thisDatetime = dataOut.datatime | |
681 | thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[1]) |
|
683 | thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[1]) | |
682 | title = wintitle + " Power Profile %s" %(thisDatetime.strftime("%d-%b-%Y")) |
|
684 | title = wintitle + " Power Profile %s" %(thisDatetime.strftime("%d-%b-%Y")) | |
683 | xlabel = "dB" |
|
685 | xlabel = "dB" | |
684 | ylabel = "Range (Km)" |
|
686 | ylabel = "Range (Km)" | |
685 |
|
687 | |||
686 | if not self.__isConfig: |
|
688 | if not self.__isConfig: | |
687 |
|
689 | |||
688 | nplots = 1 |
|
690 | nplots = 1 | |
689 |
|
691 | |||
690 |
self.setup(id |
|
692 | self.setup(id=id, | |
691 | nplots=nplots, |
|
693 | nplots=nplots, | |
692 | wintitle=wintitle, |
|
694 | wintitle=wintitle, | |
693 | show=show) |
|
695 | show=show) | |
694 |
|
696 | |||
695 | if ymin == None: ymin = numpy.nanmin(y) |
|
697 | if ymin == None: ymin = numpy.nanmin(y) | |
696 | if ymax == None: ymax = numpy.nanmax(y) |
|
698 | if ymax == None: ymax = numpy.nanmax(y) | |
697 | if xmin == None: xmin = numpy.nanmin(avgdB)*0.9 |
|
699 | if xmin == None: xmin = numpy.nanmin(avgdB)*0.9 | |
698 | if xmax == None: xmax = numpy.nanmax(avgdB)*0.9 |
|
700 | if xmax == None: xmax = numpy.nanmax(avgdB)*0.9 | |
699 |
|
701 | |||
700 | self.__isConfig = True |
|
702 | self.__isConfig = True | |
701 |
|
703 | |||
702 | self.setWinTitle(title) |
|
704 | self.setWinTitle(title) | |
703 |
|
705 | |||
704 |
|
706 | |||
705 | title = "Power Profile: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) |
|
707 | title = "Power Profile: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) | |
706 | axes = self.axesList[0] |
|
708 | axes = self.axesList[0] | |
707 |
|
709 | |||
708 | legendlabels = ["channel %d"%x for x in channelList] |
|
710 | legendlabels = ["channel %d"%x for x in channelList] | |
709 | axes.pmultiline(avgdB, y, |
|
711 | axes.pmultiline(avgdB, y, | |
710 | xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, |
|
712 | xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, | |
711 | xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels, |
|
713 | xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels, | |
712 | ytick_visible=True, nxticks=5, |
|
714 | ytick_visible=True, nxticks=5, | |
713 | grid='x') |
|
715 | grid='x') | |
714 |
|
716 | |||
715 | self.draw() |
|
717 | self.draw() | |
716 |
|
718 | |||
717 | if save: |
|
719 | if save: | |
718 | date = thisDatetime.strftime("%Y%m%d") |
|
720 | date = thisDatetime.strftime("%Y%m%d") | |
719 | if figfile == None: |
|
721 | if figfile == None: | |
720 | figfile = self.getFilename(name = date) |
|
722 | figfile = self.getFilename(name = date) | |
721 |
|
723 | |||
722 | self.saveFigure(figpath, figfile) |
|
724 | self.saveFigure(figpath, figfile) | |
723 |
|
725 | |||
724 | class CoherenceMap(Figure): |
|
726 | class CoherenceMap(Figure): | |
725 | __isConfig = None |
|
727 | __isConfig = None | |
726 | __nsubplots = None |
|
728 | __nsubplots = None | |
727 |
|
729 | |||
728 | WIDTHPROF = None |
|
730 | WIDTHPROF = None | |
729 | HEIGHTPROF = None |
|
731 | HEIGHTPROF = None | |
730 | PREFIX = 'cmap' |
|
732 | PREFIX = 'cmap' | |
731 |
|
733 | |||
732 | def __init__(self): |
|
734 | def __init__(self): | |
733 | self.timerange = 2*60*60 |
|
735 | self.timerange = 2*60*60 | |
734 | self.__isConfig = False |
|
736 | self.__isConfig = False | |
735 | self.__nsubplots = 1 |
|
737 | self.__nsubplots = 1 | |
736 |
|
738 | |||
737 | self.WIDTH = 800 |
|
739 | self.WIDTH = 800 | |
738 | self.HEIGHT = 150 |
|
740 | self.HEIGHT = 150 | |
739 | self.WIDTHPROF = 120 |
|
741 | self.WIDTHPROF = 120 | |
740 | self.HEIGHTPROF = 0 |
|
742 | self.HEIGHTPROF = 0 | |
741 |
self.counter |
|
743 | self.counter_imagwr = 0 | |
742 |
|
744 | |||
743 | def getSubplots(self): |
|
745 | def getSubplots(self): | |
744 | ncol = 1 |
|
746 | ncol = 1 | |
745 | nrow = self.nplots*2 |
|
747 | nrow = self.nplots*2 | |
746 |
|
748 | |||
747 | return nrow, ncol |
|
749 | return nrow, ncol | |
748 |
|
750 | |||
749 |
def setup(self, id |
|
751 | def setup(self, id, nplots, wintitle, showprofile=True, show=True): | |
750 | self.__showprofile = showprofile |
|
752 | self.__showprofile = showprofile | |
751 | self.nplots = nplots |
|
753 | self.nplots = nplots | |
752 |
|
754 | |||
753 | ncolspan = 1 |
|
755 | ncolspan = 1 | |
754 | colspan = 1 |
|
756 | colspan = 1 | |
755 | if showprofile: |
|
757 | if showprofile: | |
756 | ncolspan = 7 |
|
758 | ncolspan = 7 | |
757 | colspan = 6 |
|
759 | colspan = 6 | |
758 | self.__nsubplots = 2 |
|
760 | self.__nsubplots = 2 | |
759 |
|
761 | |||
760 |
self.createFigure(id |
|
762 | self.createFigure(id = id, | |
761 | wintitle = wintitle, |
|
763 | wintitle = wintitle, | |
762 | widthplot = self.WIDTH + self.WIDTHPROF, |
|
764 | widthplot = self.WIDTH + self.WIDTHPROF, | |
763 | heightplot = self.HEIGHT + self.HEIGHTPROF, |
|
765 | heightplot = self.HEIGHT + self.HEIGHTPROF, | |
764 | show=True) |
|
766 | show=True) | |
765 |
|
767 | |||
766 | nrow, ncol = self.getSubplots() |
|
768 | nrow, ncol = self.getSubplots() | |
767 |
|
769 | |||
768 | for y in range(nrow): |
|
770 | for y in range(nrow): | |
769 | for x in range(ncol): |
|
771 | for x in range(ncol): | |
770 |
|
772 | |||
771 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1) |
|
773 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1) | |
772 |
|
774 | |||
773 | if showprofile: |
|
775 | if showprofile: | |
774 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1) |
|
776 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1) | |
775 |
|
777 | |||
776 |
def run(self, dataOut, id |
|
778 | def run(self, dataOut, id, wintitle="", pairsList=None, showprofile='True', | |
777 | xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None, |
|
779 | xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None, | |
778 | timerange=None, |
|
780 | timerange=None, | |
779 |
save=False, figpath='./', figfile=None, ftp=False, |
|
781 | save=False, figpath='./', figfile=None, ftp=False, res_imagwr=1, | |
780 | coherence_cmap='jet', phase_cmap='RdBu_r', show=True): |
|
782 | coherence_cmap='jet', phase_cmap='RdBu_r', show=True): | |
781 |
|
783 | |||
782 | if pairsList == None: |
|
784 | if pairsList == None: | |
783 | pairsIndexList = dataOut.pairsIndexList |
|
785 | pairsIndexList = dataOut.pairsIndexList | |
784 | else: |
|
786 | else: | |
785 | pairsIndexList = [] |
|
787 | pairsIndexList = [] | |
786 | for pair in pairsList: |
|
788 | for pair in pairsList: | |
787 | if pair not in dataOut.pairsList: |
|
789 | if pair not in dataOut.pairsList: | |
788 | raise ValueError, "Pair %s is not in dataOut.pairsList" %(pair) |
|
790 | raise ValueError, "Pair %s is not in dataOut.pairsList" %(pair) | |
789 | pairsIndexList.append(dataOut.pairsList.index(pair)) |
|
791 | pairsIndexList.append(dataOut.pairsList.index(pair)) | |
790 |
|
792 | |||
791 | if timerange != None: |
|
793 | if timerange != None: | |
792 | self.timerange = timerange |
|
794 | self.timerange = timerange | |
793 |
|
795 | |||
794 | if pairsIndexList == []: |
|
796 | if pairsIndexList == []: | |
795 | return |
|
797 | return | |
796 |
|
798 | |||
797 | if len(pairsIndexList) > 4: |
|
799 | if len(pairsIndexList) > 4: | |
798 | pairsIndexList = pairsIndexList[0:4] |
|
800 | pairsIndexList = pairsIndexList[0:4] | |
799 |
|
801 | |||
800 | tmin = None |
|
802 | tmin = None | |
801 | tmax = None |
|
803 | tmax = None | |
802 | x = dataOut.getTimeRange() |
|
804 | x = dataOut.getTimeRange() | |
803 | y = dataOut.getHeiRange() |
|
805 | y = dataOut.getHeiRange() | |
804 |
|
806 | |||
805 | #thisDatetime = dataOut.datatime |
|
807 | #thisDatetime = dataOut.datatime | |
806 | thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[1]) |
|
808 | thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[1]) | |
807 | title = wintitle + " CoherenceMap: %s" %(thisDatetime.strftime("%d-%b-%Y")) |
|
809 | title = wintitle + " CoherenceMap: %s" %(thisDatetime.strftime("%d-%b-%Y")) | |
808 | xlabel = "" |
|
810 | xlabel = "" | |
809 | ylabel = "Range (Km)" |
|
811 | ylabel = "Range (Km)" | |
810 |
|
812 | |||
811 | if not self.__isConfig: |
|
813 | if not self.__isConfig: | |
812 | nplots = len(pairsIndexList) |
|
814 | nplots = len(pairsIndexList) | |
813 |
self.setup(id |
|
815 | self.setup(id=id, | |
814 | nplots=nplots, |
|
816 | nplots=nplots, | |
815 | wintitle=wintitle, |
|
817 | wintitle=wintitle, | |
816 | showprofile=showprofile, |
|
818 | showprofile=showprofile, | |
817 | show=show) |
|
819 | show=show) | |
818 |
|
820 | |||
819 | tmin, tmax = self.getTimeLim(x, xmin, xmax) |
|
821 | tmin, tmax = self.getTimeLim(x, xmin, xmax) | |
820 | if ymin == None: ymin = numpy.nanmin(y) |
|
822 | if ymin == None: ymin = numpy.nanmin(y) | |
821 | if ymax == None: ymax = numpy.nanmax(y) |
|
823 | if ymax == None: ymax = numpy.nanmax(y) | |
822 |
|
824 | |||
823 | self.name = thisDatetime.strftime("%Y%m%d_%H%M%S") |
|
825 | self.name = thisDatetime.strftime("%Y%m%d_%H%M%S") | |
824 |
|
826 | |||
825 | self.__isConfig = True |
|
827 | self.__isConfig = True | |
826 |
|
828 | |||
827 | self.setWinTitle(title) |
|
829 | self.setWinTitle(title) | |
828 |
|
830 | |||
829 | for i in range(self.nplots): |
|
831 | for i in range(self.nplots): | |
830 |
|
832 | |||
831 | pair = dataOut.pairsList[pairsIndexList[i]] |
|
833 | pair = dataOut.pairsList[pairsIndexList[i]] | |
832 | coherenceComplex = dataOut.data_cspc[pairsIndexList[i],:,:]/numpy.sqrt(dataOut.data_spc[pair[0],:,:]*dataOut.data_spc[pair[1],:,:]) |
|
834 | coherenceComplex = dataOut.data_cspc[pairsIndexList[i],:,:]/numpy.sqrt(dataOut.data_spc[pair[0],:,:]*dataOut.data_spc[pair[1],:,:]) | |
833 | avgcoherenceComplex = numpy.average(coherenceComplex, axis=0) |
|
835 | avgcoherenceComplex = numpy.average(coherenceComplex, axis=0) | |
834 | coherence = numpy.abs(avgcoherenceComplex) |
|
836 | coherence = numpy.abs(avgcoherenceComplex) | |
835 | # coherence = numpy.abs(coherenceComplex) |
|
837 | # coherence = numpy.abs(coherenceComplex) | |
836 | # avg = numpy.average(coherence, axis=0) |
|
838 | # avg = numpy.average(coherence, axis=0) | |
837 |
|
839 | |||
838 | z = coherence.reshape((1,-1)) |
|
840 | z = coherence.reshape((1,-1)) | |
839 |
|
841 | |||
840 | counter = 0 |
|
842 | counter = 0 | |
841 |
|
843 | |||
842 | title = "Coherence %d%d: %s" %(pair[0], pair[1], thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) |
|
844 | title = "Coherence %d%d: %s" %(pair[0], pair[1], thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) | |
843 | axes = self.axesList[i*self.__nsubplots*2] |
|
845 | axes = self.axesList[i*self.__nsubplots*2] | |
844 | axes.pcolorbuffer(x, y, z, |
|
846 | axes.pcolorbuffer(x, y, z, | |
845 | xmin=tmin, xmax=tmax, ymin=ymin, ymax=ymax, zmin=0, zmax=1, |
|
847 | xmin=tmin, xmax=tmax, ymin=ymin, ymax=ymax, zmin=0, zmax=1, | |
846 | xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True, |
|
848 | xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True, | |
847 | ticksize=9, cblabel='', colormap=coherence_cmap, cbsize="1%") |
|
849 | ticksize=9, cblabel='', colormap=coherence_cmap, cbsize="1%") | |
848 |
|
850 | |||
849 | if self.__showprofile: |
|
851 | if self.__showprofile: | |
850 | counter += 1 |
|
852 | counter += 1 | |
851 | axes = self.axesList[i*self.__nsubplots*2 + counter] |
|
853 | axes = self.axesList[i*self.__nsubplots*2 + counter] | |
852 | axes.pline(coherence, y, |
|
854 | axes.pline(coherence, y, | |
853 | xmin=0, xmax=1, ymin=ymin, ymax=ymax, |
|
855 | xmin=0, xmax=1, ymin=ymin, ymax=ymax, | |
854 | xlabel='', ylabel='', title='', ticksize=7, |
|
856 | xlabel='', ylabel='', title='', ticksize=7, | |
855 | ytick_visible=False, nxticks=5, |
|
857 | ytick_visible=False, nxticks=5, | |
856 | grid='x') |
|
858 | grid='x') | |
857 |
|
859 | |||
858 | counter += 1 |
|
860 | counter += 1 | |
859 | # phase = numpy.arctan(-1*coherenceComplex.imag/coherenceComplex.real)*180/numpy.pi |
|
861 | # phase = numpy.arctan(-1*coherenceComplex.imag/coherenceComplex.real)*180/numpy.pi | |
860 | phase = numpy.arctan2(avgcoherenceComplex.imag, avgcoherenceComplex.real)*180/numpy.pi |
|
862 | phase = numpy.arctan2(avgcoherenceComplex.imag, avgcoherenceComplex.real)*180/numpy.pi | |
861 | # avg = numpy.average(phase, axis=0) |
|
863 | # avg = numpy.average(phase, axis=0) | |
862 | z = phase.reshape((1,-1)) |
|
864 | z = phase.reshape((1,-1)) | |
863 |
|
865 | |||
864 | title = "Phase %d%d: %s" %(pair[0], pair[1], thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) |
|
866 | title = "Phase %d%d: %s" %(pair[0], pair[1], thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) | |
865 | axes = self.axesList[i*self.__nsubplots*2 + counter] |
|
867 | axes = self.axesList[i*self.__nsubplots*2 + counter] | |
866 | axes.pcolorbuffer(x, y, z, |
|
868 | axes.pcolorbuffer(x, y, z, | |
867 | xmin=tmin, xmax=tmax, ymin=ymin, ymax=ymax, zmin=-180, zmax=180, |
|
869 | xmin=tmin, xmax=tmax, ymin=ymin, ymax=ymax, zmin=-180, zmax=180, | |
868 | xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True, |
|
870 | xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True, | |
869 | ticksize=9, cblabel='', colormap=phase_cmap, cbsize="1%") |
|
871 | ticksize=9, cblabel='', colormap=phase_cmap, cbsize="1%") | |
870 |
|
872 | |||
871 | if self.__showprofile: |
|
873 | if self.__showprofile: | |
872 | counter += 1 |
|
874 | counter += 1 | |
873 | axes = self.axesList[i*self.__nsubplots*2 + counter] |
|
875 | axes = self.axesList[i*self.__nsubplots*2 + counter] | |
874 | axes.pline(phase, y, |
|
876 | axes.pline(phase, y, | |
875 | xmin=-180, xmax=180, ymin=ymin, ymax=ymax, |
|
877 | xmin=-180, xmax=180, ymin=ymin, ymax=ymax, | |
876 | xlabel='', ylabel='', title='', ticksize=7, |
|
878 | xlabel='', ylabel='', title='', ticksize=7, | |
877 | ytick_visible=False, nxticks=4, |
|
879 | ytick_visible=False, nxticks=4, | |
878 | grid='x') |
|
880 | grid='x') | |
879 |
|
881 | |||
880 | self.draw() |
|
882 | self.draw() | |
881 |
|
883 | |||
882 | if save: |
|
884 | if save: | |
883 |
|
885 | |||
884 | if figfile == None: |
|
886 | self.counter_imagwr += 1 | |
885 | figfile = self.getFilename(name = self.name) |
|
887 | if (self.counter_imagwr==res_imagwr): | |
886 |
|
888 | fig_file = self.getFilename(name = self.name) | ||
887 | self.saveFigure(figpath, figfile) |
|
889 | self.saveFigure(figpath, fig_file) | |
888 |
|
890 | if ftp: | ||
889 | self.counterftp += 1 |
|
891 | self.saveFigure(figpath, figfile) | |
890 | if (ftp and (self.counterftp==ftpratio)): |
|
892 | figfilename = os.path.join(figpath,figfile) | |
891 | figfilename = os.path.join(figpath,figfile) |
|
893 | self.sendByFTP(figfilename) | |
892 | self.sendByFTP(figfilename) |
|
894 | ||
893 |
self.counter |
|
895 | self.counter_imagwr = 0 | |
894 |
|
896 | |||
895 | if x[1] + (x[1]-x[0]) >= self.axesList[0].xmax: |
|
897 | if x[1] + (x[1]-x[0]) >= self.axesList[0].xmax: | |
896 | self.__isConfig = False |
|
898 | self.__isConfig = False | |
897 |
|
899 | |||
898 | class RTIfromNoise(Figure): |
|
900 | class RTIfromNoise(Figure): | |
899 |
|
901 | |||
900 | __isConfig = None |
|
902 | __isConfig = None | |
901 | __nsubplots = None |
|
903 | __nsubplots = None | |
902 |
|
904 | |||
903 | PREFIX = 'rtinoise' |
|
905 | PREFIX = 'rtinoise' | |
904 |
|
906 | |||
905 | def __init__(self): |
|
907 | def __init__(self): | |
906 |
|
908 | |||
907 | self.timerange = 24*60*60 |
|
909 | self.timerange = 24*60*60 | |
908 | self.__isConfig = False |
|
910 | self.__isConfig = False | |
909 | self.__nsubplots = 1 |
|
911 | self.__nsubplots = 1 | |
910 |
|
912 | |||
911 | self.WIDTH = 820 |
|
913 | self.WIDTH = 820 | |
912 | self.HEIGHT = 200 |
|
914 | self.HEIGHT = 200 | |
913 | self.WIDTHPROF = 120 |
|
915 | self.WIDTHPROF = 120 | |
914 | self.HEIGHTPROF = 0 |
|
916 | self.HEIGHTPROF = 0 | |
915 | self.xdata = None |
|
917 | self.xdata = None | |
916 | self.ydata = None |
|
918 | self.ydata = None | |
917 |
|
919 | |||
918 | def getSubplots(self): |
|
920 | def getSubplots(self): | |
919 |
|
921 | |||
920 | ncol = 1 |
|
922 | ncol = 1 | |
921 | nrow = 1 |
|
923 | nrow = 1 | |
922 |
|
924 | |||
923 | return nrow, ncol |
|
925 | return nrow, ncol | |
924 |
|
926 | |||
925 |
def setup(self, id |
|
927 | def setup(self, id, nplots, wintitle, showprofile=True, show=True): | |
926 |
|
928 | |||
927 | self.__showprofile = showprofile |
|
929 | self.__showprofile = showprofile | |
928 | self.nplots = nplots |
|
930 | self.nplots = nplots | |
929 |
|
931 | |||
930 | ncolspan = 7 |
|
932 | ncolspan = 7 | |
931 | colspan = 6 |
|
933 | colspan = 6 | |
932 | self.__nsubplots = 2 |
|
934 | self.__nsubplots = 2 | |
933 |
|
935 | |||
934 |
self.createFigure(id |
|
936 | self.createFigure(id = id, | |
935 | wintitle = wintitle, |
|
937 | wintitle = wintitle, | |
936 | widthplot = self.WIDTH+self.WIDTHPROF, |
|
938 | widthplot = self.WIDTH+self.WIDTHPROF, | |
937 | heightplot = self.HEIGHT+self.HEIGHTPROF, |
|
939 | heightplot = self.HEIGHT+self.HEIGHTPROF, | |
938 | show=show) |
|
940 | show=show) | |
939 |
|
941 | |||
940 | nrow, ncol = self.getSubplots() |
|
942 | nrow, ncol = self.getSubplots() | |
941 |
|
943 | |||
942 | self.addAxes(nrow, ncol*ncolspan, 0, 0, colspan, 1) |
|
944 | self.addAxes(nrow, ncol*ncolspan, 0, 0, colspan, 1) | |
943 |
|
945 | |||
944 |
|
946 | |||
945 |
def run(self, dataOut, id |
|
947 | def run(self, dataOut, id, wintitle="", channelList=None, showprofile='True', | |
946 | xmin=None, xmax=None, ymin=None, ymax=None, |
|
948 | xmin=None, xmax=None, ymin=None, ymax=None, | |
947 | timerange=None, |
|
949 | timerange=None, | |
948 | save=False, figpath='./', figfile=None, show=True): |
|
950 | save=False, figpath='./', figfile=None, show=True): | |
949 |
|
951 | |||
950 | if channelList == None: |
|
952 | if channelList == None: | |
951 | channelIndexList = dataOut.channelIndexList |
|
953 | channelIndexList = dataOut.channelIndexList | |
952 | channelList = dataOut.channelList |
|
954 | channelList = dataOut.channelList | |
953 | else: |
|
955 | else: | |
954 | channelIndexList = [] |
|
956 | channelIndexList = [] | |
955 | for channel in channelList: |
|
957 | for channel in channelList: | |
956 | if channel not in dataOut.channelList: |
|
958 | if channel not in dataOut.channelList: | |
957 | raise ValueError, "Channel %d is not in dataOut.channelList" |
|
959 | raise ValueError, "Channel %d is not in dataOut.channelList" | |
958 | channelIndexList.append(dataOut.channelList.index(channel)) |
|
960 | channelIndexList.append(dataOut.channelList.index(channel)) | |
959 |
|
961 | |||
960 | if timerange != None: |
|
962 | if timerange != None: | |
961 | self.timerange = timerange |
|
963 | self.timerange = timerange | |
962 |
|
964 | |||
963 | tmin = None |
|
965 | tmin = None | |
964 | tmax = None |
|
966 | tmax = None | |
965 | x = dataOut.getTimeRange() |
|
967 | x = dataOut.getTimeRange() | |
966 | y = dataOut.getHeiRange() |
|
968 | y = dataOut.getHeiRange() | |
967 | factor = dataOut.normFactor |
|
969 | factor = dataOut.normFactor | |
968 | noise = dataOut.getNoise()/factor |
|
970 | noise = dataOut.getNoise()/factor | |
969 | noisedB = 10*numpy.log10(noise) |
|
971 | noisedB = 10*numpy.log10(noise) | |
970 |
|
972 | |||
971 | #thisDatetime = dataOut.datatime |
|
973 | #thisDatetime = dataOut.datatime | |
972 | thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[1]) |
|
974 | thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[1]) | |
973 | title = wintitle + " RTI Noise: %s" %(thisDatetime.strftime("%d-%b-%Y")) |
|
975 | title = wintitle + " RTI Noise: %s" %(thisDatetime.strftime("%d-%b-%Y")) | |
974 | xlabel = "" |
|
976 | xlabel = "" | |
975 | ylabel = "Range (Km)" |
|
977 | ylabel = "Range (Km)" | |
976 |
|
978 | |||
977 | if not self.__isConfig: |
|
979 | if not self.__isConfig: | |
978 |
|
980 | |||
979 | nplots = 1 |
|
981 | nplots = 1 | |
980 |
|
982 | |||
981 |
self.setup(id |
|
983 | self.setup(id=id, | |
982 | nplots=nplots, |
|
984 | nplots=nplots, | |
983 | wintitle=wintitle, |
|
985 | wintitle=wintitle, | |
984 | showprofile=showprofile, |
|
986 | showprofile=showprofile, | |
985 | show=show) |
|
987 | show=show) | |
986 |
|
988 | |||
987 | tmin, tmax = self.getTimeLim(x, xmin, xmax) |
|
989 | tmin, tmax = self.getTimeLim(x, xmin, xmax) | |
988 | if ymin == None: ymin = numpy.nanmin(noisedB) |
|
990 | if ymin == None: ymin = numpy.nanmin(noisedB) | |
989 | if ymax == None: ymax = numpy.nanmax(noisedB) |
|
991 | if ymax == None: ymax = numpy.nanmax(noisedB) | |
990 |
|
992 | |||
991 | self.name = thisDatetime.strftime("%Y%m%d_%H%M%S") |
|
993 | self.name = thisDatetime.strftime("%Y%m%d_%H%M%S") | |
992 | self.__isConfig = True |
|
994 | self.__isConfig = True | |
993 |
|
995 | |||
994 | self.xdata = numpy.array([]) |
|
996 | self.xdata = numpy.array([]) | |
995 | self.ydata = numpy.array([]) |
|
997 | self.ydata = numpy.array([]) | |
996 |
|
998 | |||
997 | self.setWinTitle(title) |
|
999 | self.setWinTitle(title) | |
998 |
|
1000 | |||
999 |
|
1001 | |||
1000 | title = "RTI Noise %s" %(thisDatetime.strftime("%d-%b-%Y")) |
|
1002 | title = "RTI Noise %s" %(thisDatetime.strftime("%d-%b-%Y")) | |
1001 |
|
1003 | |||
1002 | legendlabels = ["channel %d"%idchannel for idchannel in channelList] |
|
1004 | legendlabels = ["channel %d"%idchannel for idchannel in channelList] | |
1003 | axes = self.axesList[0] |
|
1005 | axes = self.axesList[0] | |
1004 |
|
1006 | |||
1005 | self.xdata = numpy.hstack((self.xdata, x[0:1])) |
|
1007 | self.xdata = numpy.hstack((self.xdata, x[0:1])) | |
1006 |
|
1008 | |||
1007 | if len(self.ydata)==0: |
|
1009 | if len(self.ydata)==0: | |
1008 | self.ydata = noisedB[channelIndexList].reshape(-1,1) |
|
1010 | self.ydata = noisedB[channelIndexList].reshape(-1,1) | |
1009 | else: |
|
1011 | else: | |
1010 | self.ydata = numpy.hstack((self.ydata, noisedB[channelIndexList].reshape(-1,1))) |
|
1012 | self.ydata = numpy.hstack((self.ydata, noisedB[channelIndexList].reshape(-1,1))) | |
1011 |
|
1013 | |||
1012 |
|
1014 | |||
1013 | axes.pmultilineyaxis(x=self.xdata, y=self.ydata, |
|
1015 | axes.pmultilineyaxis(x=self.xdata, y=self.ydata, | |
1014 | xmin=tmin, xmax=tmax, ymin=ymin, ymax=ymax, |
|
1016 | xmin=tmin, xmax=tmax, ymin=ymin, ymax=ymax, | |
1015 | xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels, marker='x', markersize=8, linestyle="solid", |
|
1017 | xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels, marker='x', markersize=8, linestyle="solid", | |
1016 | XAxisAsTime=True |
|
1018 | XAxisAsTime=True | |
1017 | ) |
|
1019 | ) | |
1018 |
|
1020 | |||
1019 | self.draw() |
|
1021 | self.draw() | |
1020 |
|
1022 | |||
1021 | if save: |
|
1023 | if save: | |
1022 |
|
1024 | |||
1023 | if figfile == None: |
|
1025 | if figfile == None: | |
1024 | figfile = self.getFilename(name = self.name) |
|
1026 | figfile = self.getFilename(name = self.name) | |
1025 |
|
1027 | |||
1026 | self.saveFigure(figpath, figfile) |
|
1028 | self.saveFigure(figpath, figfile) | |
1027 |
|
1029 | |||
1028 | if x[1] + (x[1]-x[0]) >= self.axesList[0].xmax: |
|
1030 | if x[1] + (x[1]-x[0]) >= self.axesList[0].xmax: | |
1029 | self.__isConfig = False |
|
1031 | self.__isConfig = False | |
1030 | del self.xdata |
|
1032 | del self.xdata | |
1031 | del self.ydata |
|
1033 | del self.ydata | |
1032 |
|
1034 | |||
1033 |
|
1035 | |||
1034 | class SpectraHeisScope(Figure): |
|
1036 | class SpectraHeisScope(Figure): | |
1035 |
|
1037 | |||
1036 |
|
1038 | |||
1037 | __isConfig = None |
|
1039 | __isConfig = None | |
1038 | __nsubplots = None |
|
1040 | __nsubplots = None | |
1039 |
|
1041 | |||
1040 | WIDTHPROF = None |
|
1042 | WIDTHPROF = None | |
1041 | HEIGHTPROF = None |
|
1043 | HEIGHTPROF = None | |
1042 | PREFIX = 'spc' |
|
1044 | PREFIX = 'spc' | |
1043 |
|
1045 | |||
1044 | def __init__(self): |
|
1046 | def __init__(self): | |
1045 |
|
1047 | |||
1046 | self.__isConfig = False |
|
1048 | self.__isConfig = False | |
1047 | self.__nsubplots = 1 |
|
1049 | self.__nsubplots = 1 | |
1048 |
|
1050 | |||
1049 | self.WIDTH = 230 |
|
1051 | self.WIDTH = 230 | |
1050 | self.HEIGHT = 250 |
|
1052 | self.HEIGHT = 250 | |
1051 | self.WIDTHPROF = 120 |
|
1053 | self.WIDTHPROF = 120 | |
1052 | self.HEIGHTPROF = 0 |
|
1054 | self.HEIGHTPROF = 0 | |
1053 |
self.counter |
|
1055 | self.counter_imagwr = 0 | |
1054 |
|
1056 | |||
1055 | def getSubplots(self): |
|
1057 | def getSubplots(self): | |
1056 |
|
1058 | |||
1057 | ncol = int(numpy.sqrt(self.nplots)+0.9) |
|
1059 | ncol = int(numpy.sqrt(self.nplots)+0.9) | |
1058 | nrow = int(self.nplots*1./ncol + 0.9) |
|
1060 | nrow = int(self.nplots*1./ncol + 0.9) | |
1059 |
|
1061 | |||
1060 | return nrow, ncol |
|
1062 | return nrow, ncol | |
1061 |
|
1063 | |||
1062 |
def setup(self, id |
|
1064 | def setup(self, id, nplots, wintitle, show): | |
1063 |
|
1065 | |||
1064 | showprofile = False |
|
1066 | showprofile = False | |
1065 | self.__showprofile = showprofile |
|
1067 | self.__showprofile = showprofile | |
1066 | self.nplots = nplots |
|
1068 | self.nplots = nplots | |
1067 |
|
1069 | |||
1068 | ncolspan = 1 |
|
1070 | ncolspan = 1 | |
1069 | colspan = 1 |
|
1071 | colspan = 1 | |
1070 | if showprofile: |
|
1072 | if showprofile: | |
1071 | ncolspan = 3 |
|
1073 | ncolspan = 3 | |
1072 | colspan = 2 |
|
1074 | colspan = 2 | |
1073 | self.__nsubplots = 2 |
|
1075 | self.__nsubplots = 2 | |
1074 |
|
1076 | |||
1075 |
self.createFigure(id |
|
1077 | self.createFigure(id = id, | |
1076 | wintitle = wintitle, |
|
1078 | wintitle = wintitle, | |
1077 | widthplot = self.WIDTH + self.WIDTHPROF, |
|
1079 | widthplot = self.WIDTH + self.WIDTHPROF, | |
1078 | heightplot = self.HEIGHT + self.HEIGHTPROF, |
|
1080 | heightplot = self.HEIGHT + self.HEIGHTPROF, | |
1079 | show = show) |
|
1081 | show = show) | |
1080 |
|
1082 | |||
1081 | nrow, ncol = self.getSubplots() |
|
1083 | nrow, ncol = self.getSubplots() | |
1082 |
|
1084 | |||
1083 | counter = 0 |
|
1085 | counter = 0 | |
1084 | for y in range(nrow): |
|
1086 | for y in range(nrow): | |
1085 | for x in range(ncol): |
|
1087 | for x in range(ncol): | |
1086 |
|
1088 | |||
1087 | if counter >= self.nplots: |
|
1089 | if counter >= self.nplots: | |
1088 | break |
|
1090 | break | |
1089 |
|
1091 | |||
1090 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1) |
|
1092 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1) | |
1091 |
|
1093 | |||
1092 | if showprofile: |
|
1094 | if showprofile: | |
1093 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1) |
|
1095 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1) | |
1094 |
|
1096 | |||
1095 | counter += 1 |
|
1097 | counter += 1 | |
1096 |
|
1098 | |||
1097 | # __isConfig = None |
|
1099 | # __isConfig = None | |
1098 | # def __init__(self): |
|
1100 | # def __init__(self): | |
1099 | # |
|
1101 | # | |
1100 | # self.__isConfig = False |
|
1102 | # self.__isConfig = False | |
1101 | # self.WIDTH = 600 |
|
1103 | # self.WIDTH = 600 | |
1102 | # self.HEIGHT = 200 |
|
1104 | # self.HEIGHT = 200 | |
1103 | # |
|
1105 | # | |
1104 | # def getSubplots(self): |
|
1106 | # def getSubplots(self): | |
1105 | # |
|
1107 | # | |
1106 | # nrow = self.nplots |
|
1108 | # nrow = self.nplots | |
1107 | # ncol = 3 |
|
1109 | # ncol = 3 | |
1108 | # return nrow, ncol |
|
1110 | # return nrow, ncol | |
1109 | # |
|
1111 | # | |
1110 |
# def setup(self, id |
|
1112 | # def setup(self, id, nplots, wintitle): | |
1111 | # |
|
1113 | # | |
1112 | # self.nplots = nplots |
|
1114 | # self.nplots = nplots | |
1113 | # |
|
1115 | # | |
1114 |
# self.createFigure(id |
|
1116 | # self.createFigure(id, wintitle) | |
1115 | # |
|
1117 | # | |
1116 | # nrow,ncol = self.getSubplots() |
|
1118 | # nrow,ncol = self.getSubplots() | |
1117 | # colspan = 3 |
|
1119 | # colspan = 3 | |
1118 | # rowspan = 1 |
|
1120 | # rowspan = 1 | |
1119 | # |
|
1121 | # | |
1120 | # for i in range(nplots): |
|
1122 | # for i in range(nplots): | |
1121 | # self.addAxes(nrow, ncol, i, 0, colspan, rowspan) |
|
1123 | # self.addAxes(nrow, ncol, i, 0, colspan, rowspan) | |
1122 |
|
1124 | |||
1123 |
def run(self, dataOut, id |
|
1125 | def run(self, dataOut, id, wintitle="", channelList=None, | |
1124 | xmin=None, xmax=None, ymin=None, ymax=None, save=False, |
|
1126 | xmin=None, xmax=None, ymin=None, ymax=None, save=False, | |
1125 |
figpath='./', figfile=None, ftp=False, |
|
1127 | figpath='./', figfile=None, ftp=False, res_imagwr=1, show=True): | |
1126 |
|
1128 | |||
1127 | """ |
|
1129 | """ | |
1128 |
|
1130 | |||
1129 | Input: |
|
1131 | Input: | |
1130 | dataOut : |
|
1132 | dataOut : | |
1131 |
id |
|
1133 | id : | |
1132 | wintitle : |
|
1134 | wintitle : | |
1133 | channelList : |
|
1135 | channelList : | |
1134 | xmin : None, |
|
1136 | xmin : None, | |
1135 | xmax : None, |
|
1137 | xmax : None, | |
1136 | ymin : None, |
|
1138 | ymin : None, | |
1137 | ymax : None, |
|
1139 | ymax : None, | |
1138 | """ |
|
1140 | """ | |
1139 |
|
1141 | |||
1140 | if dataOut.realtime: |
|
1142 | if dataOut.realtime: | |
1141 | if not(isRealtime(utcdatatime = dataOut.utctime)): |
|
1143 | if not(isRealtime(utcdatatime = dataOut.utctime)): | |
1142 | print 'Skipping this plot function' |
|
1144 | print 'Skipping this plot function' | |
1143 | return |
|
1145 | return | |
1144 |
|
1146 | |||
1145 | if channelList == None: |
|
1147 | if channelList == None: | |
1146 | channelIndexList = dataOut.channelIndexList |
|
1148 | channelIndexList = dataOut.channelIndexList | |
1147 | else: |
|
1149 | else: | |
1148 | channelIndexList = [] |
|
1150 | channelIndexList = [] | |
1149 | for channel in channelList: |
|
1151 | for channel in channelList: | |
1150 | if channel not in dataOut.channelList: |
|
1152 | if channel not in dataOut.channelList: | |
1151 | raise ValueError, "Channel %d is not in dataOut.channelList" |
|
1153 | raise ValueError, "Channel %d is not in dataOut.channelList" | |
1152 | channelIndexList.append(dataOut.channelList.index(channel)) |
|
1154 | channelIndexList.append(dataOut.channelList.index(channel)) | |
1153 |
|
1155 | |||
1154 | # x = dataOut.heightList |
|
1156 | # x = dataOut.heightList | |
1155 | c = 3E8 |
|
1157 | c = 3E8 | |
1156 | deltaHeight = dataOut.heightList[1] - dataOut.heightList[0] |
|
1158 | deltaHeight = dataOut.heightList[1] - dataOut.heightList[0] | |
1157 | #deberia cambiar para el caso de 1Mhz y 100KHz |
|
1159 | #deberia cambiar para el caso de 1Mhz y 100KHz | |
1158 | x = numpy.arange(-1*dataOut.nHeights/2.,dataOut.nHeights/2.)*(c/(2*deltaHeight*dataOut.nHeights*1000)) |
|
1160 | x = numpy.arange(-1*dataOut.nHeights/2.,dataOut.nHeights/2.)*(c/(2*deltaHeight*dataOut.nHeights*1000)) | |
1159 | x= x/(10000.0) |
|
1161 | x= x/(10000.0) | |
1160 | # y = dataOut.data[channelIndexList,:] * numpy.conjugate(dataOut.data[channelIndexList,:]) |
|
1162 | # y = dataOut.data[channelIndexList,:] * numpy.conjugate(dataOut.data[channelIndexList,:]) | |
1161 | # y = y.real |
|
1163 | # y = y.real | |
1162 | datadB = 10.*numpy.log10(dataOut.data_spc) |
|
1164 | datadB = 10.*numpy.log10(dataOut.data_spc) | |
1163 | y = datadB |
|
1165 | y = datadB | |
1164 |
|
1166 | |||
1165 | #thisDatetime = dataOut.datatime |
|
1167 | #thisDatetime = dataOut.datatime | |
1166 | thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[1]) |
|
1168 | thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[1]) | |
1167 | title = wintitle + " Scope: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) |
|
1169 | title = wintitle + " Scope: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) | |
1168 | xlabel = "Frequency x 10000" |
|
1170 | xlabel = "Frequency x 10000" | |
1169 | ylabel = "Intensity (dB)" |
|
1171 | ylabel = "Intensity (dB)" | |
1170 |
|
1172 | |||
1171 | if not self.__isConfig: |
|
1173 | if not self.__isConfig: | |
1172 | nplots = len(channelIndexList) |
|
1174 | nplots = len(channelIndexList) | |
1173 |
|
1175 | |||
1174 |
self.setup(id |
|
1176 | self.setup(id=id, | |
1175 | nplots=nplots, |
|
1177 | nplots=nplots, | |
1176 | wintitle=wintitle, |
|
1178 | wintitle=wintitle, | |
1177 | show=show) |
|
1179 | show=show) | |
1178 |
|
1180 | |||
1179 | if xmin == None: xmin = numpy.nanmin(x) |
|
1181 | if xmin == None: xmin = numpy.nanmin(x) | |
1180 | if xmax == None: xmax = numpy.nanmax(x) |
|
1182 | if xmax == None: xmax = numpy.nanmax(x) | |
1181 | if ymin == None: ymin = numpy.nanmin(y) |
|
1183 | if ymin == None: ymin = numpy.nanmin(y) | |
1182 | if ymax == None: ymax = numpy.nanmax(y) |
|
1184 | if ymax == None: ymax = numpy.nanmax(y) | |
1183 |
|
1185 | |||
1184 | self.__isConfig = True |
|
1186 | self.__isConfig = True | |
1185 |
|
1187 | |||
1186 | self.setWinTitle(title) |
|
1188 | self.setWinTitle(title) | |
1187 |
|
1189 | |||
1188 | for i in range(len(self.axesList)): |
|
1190 | for i in range(len(self.axesList)): | |
1189 | ychannel = y[i,:] |
|
1191 | ychannel = y[i,:] | |
1190 | title = "Channel %d - peak:%.2f" %(i,numpy.max(ychannel)) |
|
1192 | title = "Channel %d - peak:%.2f" %(i,numpy.max(ychannel)) | |
1191 | axes = self.axesList[i] |
|
1193 | axes = self.axesList[i] | |
1192 | axes.pline(x, ychannel, |
|
1194 | axes.pline(x, ychannel, | |
1193 | xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, |
|
1195 | xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, | |
1194 | xlabel=xlabel, ylabel=ylabel, title=title, grid='both') |
|
1196 | xlabel=xlabel, ylabel=ylabel, title=title, grid='both') | |
1195 |
|
1197 | |||
1196 |
|
1198 | |||
1197 | self.draw() |
|
1199 | self.draw() | |
1198 |
|
1200 | |||
1199 | if save: |
|
1201 | if save: | |
1200 | date = thisDatetime.strftime("%Y%m%d_%H%M%S") |
|
1202 | date = thisDatetime.strftime("%Y%m%d_%H%M%S") | |
1201 | if figfile == None: |
|
1203 | if figfile == None: | |
1202 | figfile = self.getFilename(name = date) |
|
1204 | figfile = self.getFilename(name = date) | |
1203 |
|
1205 | |||
1204 | self.saveFigure(figpath, figfile) |
|
1206 | self.saveFigure(figpath, figfile) | |
1205 |
|
1207 | |||
1206 |
self.counter |
|
1208 | self.counter_imagwr += 1 | |
1207 |
if (ftp and (self.counter |
|
1209 | if (ftp and (self.counter_imagwr==res_imagwr)): | |
1208 | figfilename = os.path.join(figpath,figfile) |
|
1210 | figfilename = os.path.join(figpath,figfile) | |
1209 | self.sendByFTP(figfilename) |
|
1211 | self.sendByFTP(figfilename) | |
1210 |
self.counter |
|
1212 | self.counter_imagwr = 0 | |
1211 |
|
1213 | |||
1212 |
|
1214 | |||
1213 | class RTIfromSpectraHeis(Figure): |
|
1215 | class RTIfromSpectraHeis(Figure): | |
1214 |
|
1216 | |||
1215 | __isConfig = None |
|
1217 | __isConfig = None | |
1216 | __nsubplots = None |
|
1218 | __nsubplots = None | |
1217 |
|
1219 | |||
1218 | PREFIX = 'rtinoise' |
|
1220 | PREFIX = 'rtinoise' | |
1219 |
|
1221 | |||
1220 | def __init__(self): |
|
1222 | def __init__(self): | |
1221 |
|
1223 | |||
1222 | self.timerange = 24*60*60 |
|
1224 | self.timerange = 24*60*60 | |
1223 | self.__isConfig = False |
|
1225 | self.__isConfig = False | |
1224 | self.__nsubplots = 1 |
|
1226 | self.__nsubplots = 1 | |
1225 |
|
1227 | |||
1226 | self.WIDTH = 820 |
|
1228 | self.WIDTH = 820 | |
1227 | self.HEIGHT = 200 |
|
1229 | self.HEIGHT = 200 | |
1228 | self.WIDTHPROF = 120 |
|
1230 | self.WIDTHPROF = 120 | |
1229 | self.HEIGHTPROF = 0 |
|
1231 | self.HEIGHTPROF = 0 | |
1230 |
self.counter |
|
1232 | self.counter_imagwr = 0 | |
1231 | self.xdata = None |
|
1233 | self.xdata = None | |
1232 | self.ydata = None |
|
1234 | self.ydata = None | |
1233 |
|
1235 | |||
1234 | def getSubplots(self): |
|
1236 | def getSubplots(self): | |
1235 |
|
1237 | |||
1236 | ncol = 1 |
|
1238 | ncol = 1 | |
1237 | nrow = 1 |
|
1239 | nrow = 1 | |
1238 |
|
1240 | |||
1239 | return nrow, ncol |
|
1241 | return nrow, ncol | |
1240 |
|
1242 | |||
1241 |
def setup(self, id |
|
1243 | def setup(self, id, nplots, wintitle, showprofile=True, show=True): | |
1242 |
|
1244 | |||
1243 | self.__showprofile = showprofile |
|
1245 | self.__showprofile = showprofile | |
1244 | self.nplots = nplots |
|
1246 | self.nplots = nplots | |
1245 |
|
1247 | |||
1246 | ncolspan = 7 |
|
1248 | ncolspan = 7 | |
1247 | colspan = 6 |
|
1249 | colspan = 6 | |
1248 | self.__nsubplots = 2 |
|
1250 | self.__nsubplots = 2 | |
1249 |
|
1251 | |||
1250 |
self.createFigure(id |
|
1252 | self.createFigure(id = id, | |
1251 | wintitle = wintitle, |
|
1253 | wintitle = wintitle, | |
1252 | widthplot = self.WIDTH+self.WIDTHPROF, |
|
1254 | widthplot = self.WIDTH+self.WIDTHPROF, | |
1253 | heightplot = self.HEIGHT+self.HEIGHTPROF, |
|
1255 | heightplot = self.HEIGHT+self.HEIGHTPROF, | |
1254 | show = show) |
|
1256 | show = show) | |
1255 |
|
1257 | |||
1256 | nrow, ncol = self.getSubplots() |
|
1258 | nrow, ncol = self.getSubplots() | |
1257 |
|
1259 | |||
1258 | self.addAxes(nrow, ncol*ncolspan, 0, 0, colspan, 1) |
|
1260 | self.addAxes(nrow, ncol*ncolspan, 0, 0, colspan, 1) | |
1259 |
|
1261 | |||
1260 |
|
1262 | |||
1261 |
def run(self, dataOut, id |
|
1263 | def run(self, dataOut, id, wintitle="", channelList=None, showprofile='True', | |
1262 | xmin=None, xmax=None, ymin=None, ymax=None, |
|
1264 | xmin=None, xmax=None, ymin=None, ymax=None, | |
1263 | timerange=None, |
|
1265 | timerange=None, | |
1264 |
save=False, figpath='./', figfile=None, ftp=False, |
|
1266 | save=False, figpath='./', figfile=None, ftp=False, res_imagwr=1, show=True): | |
1265 |
|
1267 | |||
1266 | if channelList == None: |
|
1268 | if channelList == None: | |
1267 | channelIndexList = dataOut.channelIndexList |
|
1269 | channelIndexList = dataOut.channelIndexList | |
1268 | channelList = dataOut.channelList |
|
1270 | channelList = dataOut.channelList | |
1269 | else: |
|
1271 | else: | |
1270 | channelIndexList = [] |
|
1272 | channelIndexList = [] | |
1271 | for channel in channelList: |
|
1273 | for channel in channelList: | |
1272 | if channel not in dataOut.channelList: |
|
1274 | if channel not in dataOut.channelList: | |
1273 | raise ValueError, "Channel %d is not in dataOut.channelList" |
|
1275 | raise ValueError, "Channel %d is not in dataOut.channelList" | |
1274 | channelIndexList.append(dataOut.channelList.index(channel)) |
|
1276 | channelIndexList.append(dataOut.channelList.index(channel)) | |
1275 |
|
1277 | |||
1276 | if timerange != None: |
|
1278 | if timerange != None: | |
1277 | self.timerange = timerange |
|
1279 | self.timerange = timerange | |
1278 |
|
1280 | |||
1279 | tmin = None |
|
1281 | tmin = None | |
1280 | tmax = None |
|
1282 | tmax = None | |
1281 | x = dataOut.getTimeRange() |
|
1283 | x = dataOut.getTimeRange() | |
1282 | y = dataOut.getHeiRange() |
|
1284 | y = dataOut.getHeiRange() | |
1283 |
|
1285 | |||
1284 | factor = 1 |
|
1286 | factor = 1 | |
1285 | data = dataOut.data_spc/factor |
|
1287 | data = dataOut.data_spc/factor | |
1286 | data = numpy.average(data,axis=1) |
|
1288 | data = numpy.average(data,axis=1) | |
1287 | datadB = 10*numpy.log10(data) |
|
1289 | datadB = 10*numpy.log10(data) | |
1288 |
|
1290 | |||
1289 | # factor = dataOut.normFactor |
|
1291 | # factor = dataOut.normFactor | |
1290 | # noise = dataOut.getNoise()/factor |
|
1292 | # noise = dataOut.getNoise()/factor | |
1291 | # noisedB = 10*numpy.log10(noise) |
|
1293 | # noisedB = 10*numpy.log10(noise) | |
1292 |
|
1294 | |||
1293 | #thisDatetime = dataOut.datatime |
|
1295 | #thisDatetime = dataOut.datatime | |
1294 | thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[1]) |
|
1296 | thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[1]) | |
1295 | title = wintitle + " RTI: %s" %(thisDatetime.strftime("%d-%b-%Y")) |
|
1297 | title = wintitle + " RTI: %s" %(thisDatetime.strftime("%d-%b-%Y")) | |
1296 | xlabel = "Local Time" |
|
1298 | xlabel = "Local Time" | |
1297 | ylabel = "Intensity (dB)" |
|
1299 | ylabel = "Intensity (dB)" | |
1298 |
|
1300 | |||
1299 | if not self.__isConfig: |
|
1301 | if not self.__isConfig: | |
1300 |
|
1302 | |||
1301 | nplots = 1 |
|
1303 | nplots = 1 | |
1302 |
|
1304 | |||
1303 |
self.setup(id |
|
1305 | self.setup(id=id, | |
1304 | nplots=nplots, |
|
1306 | nplots=nplots, | |
1305 | wintitle=wintitle, |
|
1307 | wintitle=wintitle, | |
1306 | showprofile=showprofile, |
|
1308 | showprofile=showprofile, | |
1307 | show=show) |
|
1309 | show=show) | |
1308 |
|
1310 | |||
1309 | tmin, tmax = self.getTimeLim(x, xmin, xmax) |
|
1311 | tmin, tmax = self.getTimeLim(x, xmin, xmax) | |
1310 | if ymin == None: ymin = numpy.nanmin(datadB) |
|
1312 | if ymin == None: ymin = numpy.nanmin(datadB) | |
1311 | if ymax == None: ymax = numpy.nanmax(datadB) |
|
1313 | if ymax == None: ymax = numpy.nanmax(datadB) | |
1312 |
|
1314 | |||
1313 | self.name = thisDatetime.strftime("%Y%m%d_%H%M%S") |
|
1315 | self.name = thisDatetime.strftime("%Y%m%d_%H%M%S") | |
1314 | self.__isConfig = True |
|
1316 | self.__isConfig = True | |
1315 |
|
1317 | |||
1316 | self.xdata = numpy.array([]) |
|
1318 | self.xdata = numpy.array([]) | |
1317 | self.ydata = numpy.array([]) |
|
1319 | self.ydata = numpy.array([]) | |
1318 |
|
1320 | |||
1319 | self.setWinTitle(title) |
|
1321 | self.setWinTitle(title) | |
1320 |
|
1322 | |||
1321 |
|
1323 | |||
1322 | # title = "RTI %s" %(thisDatetime.strftime("%d-%b-%Y")) |
|
1324 | # title = "RTI %s" %(thisDatetime.strftime("%d-%b-%Y")) | |
1323 | title = "RTI-Noise - %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) |
|
1325 | title = "RTI-Noise - %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) | |
1324 |
|
1326 | |||
1325 | legendlabels = ["channel %d"%idchannel for idchannel in channelList] |
|
1327 | legendlabels = ["channel %d"%idchannel for idchannel in channelList] | |
1326 | axes = self.axesList[0] |
|
1328 | axes = self.axesList[0] | |
1327 |
|
1329 | |||
1328 | self.xdata = numpy.hstack((self.xdata, x[0:1])) |
|
1330 | self.xdata = numpy.hstack((self.xdata, x[0:1])) | |
1329 |
|
1331 | |||
1330 | if len(self.ydata)==0: |
|
1332 | if len(self.ydata)==0: | |
1331 | self.ydata = datadB[channelIndexList].reshape(-1,1) |
|
1333 | self.ydata = datadB[channelIndexList].reshape(-1,1) | |
1332 | else: |
|
1334 | else: | |
1333 | self.ydata = numpy.hstack((self.ydata, datadB[channelIndexList].reshape(-1,1))) |
|
1335 | self.ydata = numpy.hstack((self.ydata, datadB[channelIndexList].reshape(-1,1))) | |
1334 |
|
1336 | |||
1335 |
|
1337 | |||
1336 | axes.pmultilineyaxis(x=self.xdata, y=self.ydata, |
|
1338 | axes.pmultilineyaxis(x=self.xdata, y=self.ydata, | |
1337 | xmin=tmin, xmax=tmax, ymin=ymin, ymax=ymax, |
|
1339 | xmin=tmin, xmax=tmax, ymin=ymin, ymax=ymax, | |
1338 | xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels, marker='.', markersize=8, linestyle="solid", grid='both', |
|
1340 | xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels, marker='.', markersize=8, linestyle="solid", grid='both', | |
1339 | XAxisAsTime=True |
|
1341 | XAxisAsTime=True | |
1340 | ) |
|
1342 | ) | |
1341 |
|
1343 | |||
1342 | self.draw() |
|
1344 | self.draw() | |
1343 |
|
1345 | |||
1344 | if save: |
|
1346 | if save: | |
1345 |
|
1347 | |||
1346 | if figfile == None: |
|
1348 | if figfile == None: | |
1347 | figfile = self.getFilename(name = self.name) |
|
1349 | figfile = self.getFilename(name = self.name) | |
1348 |
|
1350 | |||
1349 | self.saveFigure(figpath, figfile) |
|
1351 | self.saveFigure(figpath, figfile) | |
1350 |
|
1352 | |||
1351 |
self.counter |
|
1353 | self.counter_imagwr += 1 | |
1352 |
if (ftp and (self.counter |
|
1354 | if (ftp and (self.counter_imagwr==res_imagwr)): | |
1353 | figfilename = os.path.join(figpath,figfile) |
|
1355 | figfilename = os.path.join(figpath,figfile) | |
1354 | self.sendByFTP(figfilename) |
|
1356 | self.sendByFTP(figfilename) | |
1355 |
self.counter |
|
1357 | self.counter_imagwr = 0 | |
1356 |
|
1358 | |||
1357 | if x[1] + (x[1]-x[0]) >= self.axesList[0].xmax: |
|
1359 | if x[1] + (x[1]-x[0]) >= self.axesList[0].xmax: | |
1358 | self.__isConfig = False |
|
1360 | self.__isConfig = False | |
1359 | del self.xdata |
|
1361 | del self.xdata | |
1360 | del self.ydata |
|
1362 | del self.ydata | |
1361 |
|
1363 | |||
1362 |
|
1364 | |||
1363 | No newline at end of file |
|
1365 |
General Comments 0
You need to be logged in to leave comments.
Login now