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