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