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