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