@@ -1,592 +1,629 | |||||
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 | class FTP_Thread (threading.Thread): |
|
10 | class FTP_Thread (threading.Thread): | |
11 | def __init__(self): |
|
11 | def __init__(self): | |
12 | threading.Thread.__init__(self) |
|
12 | threading.Thread.__init__(self) | |
13 | self.exitFlag = 0 |
|
13 | self.exitFlag = 0 | |
14 | self.queueLock = threading.Lock() |
|
14 | self.queueLock = threading.Lock() | |
15 | self.workQueue = Queue.Queue() |
|
15 | self.workQueue = Queue.Queue() | |
16 |
|
16 | |||
17 | def run(self): |
|
17 | def run(self): | |
18 | self.send_data() |
|
18 | self.send_data() | |
19 |
|
19 | |||
20 | def fin(self): |
|
20 | def fin(self): | |
21 | self.exitFlag = 1 |
|
21 | self.exitFlag = 1 | |
22 |
|
22 | |||
23 | def put_data(self, data): |
|
23 | def put_data(self, data): | |
24 | # Fill the queue |
|
24 | # Fill the queue | |
25 | self.queueLock.acquire() |
|
25 | self.queueLock.acquire() | |
26 | self.workQueue.put(data) |
|
26 | self.workQueue.put(data) | |
27 | self.queueLock.release() |
|
27 | self.queueLock.release() | |
28 |
|
28 | |||
29 | def send_data(self): |
|
29 | def send_data(self): | |
30 | while not self.exitFlag: |
|
30 | while not self.exitFlag: | |
31 | if self.workQueue.qsize(): |
|
31 | if self.workQueue.qsize(): | |
32 |
|
32 | |||
33 | data = self.workQueue.get(True) |
|
33 | data = self.workQueue.get(True) | |
34 |
|
34 | |||
35 | try: |
|
35 | try: | |
36 | ftpObj = Ftp(host=data['server'], |
|
36 | ftpObj = Ftp(host=data['server'], | |
37 | username=data['username'], |
|
37 | username=data['username'], | |
38 | passw=data['password'], |
|
38 | passw=data['password'], | |
39 | remotefolder=data['folder']) |
|
39 | remotefolder=data['folder']) | |
40 |
|
40 | |||
41 | ftpObj.upload(data['figfilename']) |
|
41 | ftpObj.upload(data['figfilename']) | |
42 | ftpObj.close() |
|
42 | ftpObj.close() | |
43 | except: |
|
43 | except: | |
44 | print ValueError, 'Error FTP' |
|
44 | print ValueError, 'Error FTP' | |
45 | print "don't worry still running the program" |
|
45 | print "don't worry still running the program" | |
46 |
|
46 | |||
47 |
|
47 | |||
48 | class Figure: |
|
48 | class Figure: | |
49 |
|
49 | |||
50 | __driver = mpldriver |
|
50 | __driver = mpldriver | |
51 | __isConfigThread = False |
|
51 | __isConfigThread = False | |
52 | fig = None |
|
52 | fig = None | |
53 |
|
53 | |||
54 | id = None |
|
54 | id = None | |
55 | wintitle = None |
|
55 | wintitle = None | |
56 | width = None |
|
56 | width = None | |
57 | height = None |
|
57 | height = None | |
58 | nplots = None |
|
58 | nplots = None | |
59 | timerange = None |
|
59 | timerange = None | |
60 |
|
60 | |||
61 | axesObjList = [] |
|
61 | axesObjList = [] | |
62 |
|
62 | |||
63 | WIDTH = None |
|
63 | WIDTH = None | |
64 | HEIGHT = None |
|
64 | HEIGHT = None | |
65 | PREFIX = 'fig' |
|
65 | PREFIX = 'fig' | |
66 |
|
66 | |||
|
67 | xmin = None | |||
|
68 | xmax = None | |||
|
69 | ||||
67 | def __init__(self): |
|
70 | def __init__(self): | |
68 |
|
71 | |||
69 | raise ValueError, "This method is not implemented" |
|
72 | raise ValueError, "This method is not implemented" | |
70 |
|
73 | |||
71 | def __del__(self): |
|
74 | def __del__(self): | |
72 |
|
75 | |||
73 | self.__driver.closeFigure() |
|
76 | self.__driver.closeFigure() | |
74 |
|
77 | |||
75 | def getFilename(self, name, ext='.png'): |
|
78 | def getFilename(self, name, ext='.png'): | |
76 |
|
79 | |||
77 | path = '%s%03d' %(self.PREFIX, self.id) |
|
80 | path = '%s%03d' %(self.PREFIX, self.id) | |
78 | filename = '%s_%s%s' %(self.PREFIX, name, ext) |
|
81 | filename = '%s_%s%s' %(self.PREFIX, name, ext) | |
79 | return os.path.join(path, filename) |
|
82 | return os.path.join(path, filename) | |
80 |
|
83 | |||
81 | def getAxesObjList(self): |
|
84 | def getAxesObjList(self): | |
82 |
|
85 | |||
83 | return self.axesObjList |
|
86 | return self.axesObjList | |
84 |
|
87 | |||
85 | def getSubplots(self): |
|
88 | def getSubplots(self): | |
86 |
|
89 | |||
87 | raise ValueError, "Abstract method: This method should be defined" |
|
90 | raise ValueError, "Abstract method: This method should be defined" | |
88 |
|
91 | |||
89 | def getScreenDim(self, widthplot, heightplot): |
|
92 | def getScreenDim(self, widthplot, heightplot): | |
90 |
|
93 | |||
91 | nrow, ncol = self.getSubplots() |
|
94 | nrow, ncol = self.getSubplots() | |
92 |
|
95 | |||
93 | widthscreen = widthplot*ncol |
|
96 | widthscreen = widthplot*ncol | |
94 | heightscreen = heightplot*nrow |
|
97 | heightscreen = heightplot*nrow | |
95 |
|
98 | |||
96 | return widthscreen, heightscreen |
|
99 | return widthscreen, heightscreen | |
97 |
|
100 | |||
98 | def getTimeLim(self, x, xmin, xmax): |
|
101 | def getTimeLim(self, x, xmin=None, xmax=None, timerange=None): | |
99 |
|
102 | |||
100 |
if self. |
|
103 | if self.xmin != None and self.xmax != None: | |
101 | txmin = x[0] - x[0]%self.timerange |
|
104 | if timerange == None: | |
102 | else: |
|
105 | timerange = self.xmax - self.xmin | |
103 |
|
|
106 | xmin = self.xmin + timerange | |
|
107 | xmax = self.xmax + timerange | |||
104 |
|
108 | |||
|
109 | return xmin, xmax | |||
|
110 | ||||
|
111 | ||||
|
112 | if timerange != None and self.xmin == None and self.xmax == None: | |||
|
113 | txmin = x[0] - x[0]%timerange | |||
105 | thisdatetime = datetime.datetime.utcfromtimestamp(txmin) |
|
114 | thisdatetime = datetime.datetime.utcfromtimestamp(txmin) | |
106 | thisdate = datetime.datetime.combine(thisdatetime.date(), datetime.time(0,0,0)) |
|
115 | thisdate = datetime.datetime.combine(thisdatetime.date(), datetime.time(0,0,0)) | |
|
116 | xmin = (thisdatetime - thisdate).seconds/(60*60.) | |||
|
117 | xmax = xmin + timerange/(60*60.) | |||
107 |
|
118 | |||
108 | #################################################### |
|
|||
109 | #If the x is out of xrange |
|
|||
110 | if xmax != None: |
|
|||
111 | if xmax < (thisdatetime - thisdate).seconds/(60*60.): |
|
|||
112 | xmin = None |
|
|||
113 | xmax = None |
|
|||
114 |
|
||||
115 | if xmin == None: |
|
|||
116 | td = thisdatetime - thisdate |
|
|||
117 | xmin = td.seconds/(60*60.) |
|
|||
118 |
|
|
119 | ||
119 |
if |
|
120 | if timerange == None: | |
120 | xmax = xmin + self.timerange/(60*60.) |
|
121 | txmin = numpy.min(x) | |
|
122 | thisdatetime = datetime.datetime.utcfromtimestamp(txmin) | |||
|
123 | thisdate = datetime.datetime.combine(thisdatetime.date(), datetime.time(0,0,0)) | |||
121 |
|
124 | |||
122 | mindt = thisdate + datetime.timedelta(hours=xmin) - datetime.timedelta(seconds=time.timezone) |
|
125 | mindt = thisdate + datetime.timedelta(hours=xmin) - datetime.timedelta(seconds=time.timezone) | |
123 |
|
|
126 | xmin_sec = time.mktime(mindt.timetuple()) | |
124 |
|
127 | |||
125 | maxdt = thisdate + datetime.timedelta(hours=xmax) - datetime.timedelta(seconds=time.timezone) |
|
128 | maxdt = thisdate + datetime.timedelta(hours=xmax) - datetime.timedelta(seconds=time.timezone) | |
126 |
|
|
129 | xmax_sec = time.mktime(maxdt.timetuple()) | |
127 |
|
130 | |||
128 | self.timerange = tmax - tmin |
|
131 | return xmin_sec, xmax_sec | |
129 |
|
132 | |||
130 | return tmin, tmax |
|
133 | ||
|
134 | ||||
|
135 | ||||
|
136 | ||||
|
137 | # if timerange != None: | |||
|
138 | # txmin = x[0] - x[0]%timerange | |||
|
139 | # else: | |||
|
140 | # txmin = numpy.min(x) | |||
|
141 | # | |||
|
142 | # thisdatetime = datetime.datetime.utcfromtimestamp(txmin) | |||
|
143 | # thisdate = datetime.datetime.combine(thisdatetime.date(), datetime.time(0,0,0)) | |||
|
144 | # | |||
|
145 | # #################################################### | |||
|
146 | # #If the x is out of xrange | |||
|
147 | # if xmax != None: | |||
|
148 | # if xmax < (thisdatetime - thisdate).seconds/(60*60.): | |||
|
149 | # xmin = None | |||
|
150 | # xmax = None | |||
|
151 | # | |||
|
152 | # if xmin == None: | |||
|
153 | # td = thisdatetime - thisdate | |||
|
154 | # xmin = td.seconds/(60*60.) | |||
|
155 | # | |||
|
156 | # if xmax == None: | |||
|
157 | # xmax = xmin + self.timerange/(60*60.) | |||
|
158 | # | |||
|
159 | # mindt = thisdate + datetime.timedelta(hours=xmin) - datetime.timedelta(seconds=time.timezone) | |||
|
160 | # tmin = time.mktime(mindt.timetuple()) | |||
|
161 | # | |||
|
162 | # maxdt = thisdate + datetime.timedelta(hours=xmax) - datetime.timedelta(seconds=time.timezone) | |||
|
163 | # tmax = time.mktime(maxdt.timetuple()) | |||
|
164 | # | |||
|
165 | # #self.timerange = tmax - tmin | |||
|
166 | # | |||
|
167 | # return tmin, tmax | |||
131 |
|
168 | |||
132 | def init(self, id, nplots, wintitle): |
|
169 | def init(self, id, nplots, wintitle): | |
133 |
|
170 | |||
134 | raise ValueError, "This method has been replaced with createFigure" |
|
171 | raise ValueError, "This method has been replaced with createFigure" | |
135 |
|
172 | |||
136 | def createFigure(self, id, wintitle, widthplot=None, heightplot=None, show=True): |
|
173 | def createFigure(self, id, wintitle, widthplot=None, heightplot=None, show=True): | |
137 |
|
174 | |||
138 | """ |
|
175 | """ | |
139 | Crea la figura de acuerdo al driver y parametros seleccionados seleccionados. |
|
176 | Crea la figura de acuerdo al driver y parametros seleccionados seleccionados. | |
140 | Las dimensiones de la pantalla es calculada a partir de los atributos self.WIDTH |
|
177 | Las dimensiones de la pantalla es calculada a partir de los atributos self.WIDTH | |
141 | y self.HEIGHT y el numero de subplots (nrow, ncol) |
|
178 | y self.HEIGHT y el numero de subplots (nrow, ncol) | |
142 |
|
179 | |||
143 | Input: |
|
180 | Input: | |
144 | id : Los parametros necesarios son |
|
181 | id : Los parametros necesarios son | |
145 | wintitle : |
|
182 | wintitle : | |
146 |
|
183 | |||
147 | """ |
|
184 | """ | |
148 |
|
185 | |||
149 | if widthplot == None: |
|
186 | if widthplot == None: | |
150 | widthplot = self.WIDTH |
|
187 | widthplot = self.WIDTH | |
151 |
|
188 | |||
152 | if heightplot == None: |
|
189 | if heightplot == None: | |
153 | heightplot = self.HEIGHT |
|
190 | heightplot = self.HEIGHT | |
154 |
|
191 | |||
155 | self.id = id |
|
192 | self.id = id | |
156 |
|
193 | |||
157 | self.wintitle = wintitle |
|
194 | self.wintitle = wintitle | |
158 |
|
195 | |||
159 | self.widthscreen, self.heightscreen = self.getScreenDim(widthplot, heightplot) |
|
196 | self.widthscreen, self.heightscreen = self.getScreenDim(widthplot, heightplot) | |
160 |
|
197 | |||
161 | self.fig = self.__driver.createFigure(id=self.id, |
|
198 | self.fig = self.__driver.createFigure(id=self.id, | |
162 | wintitle=self.wintitle, |
|
199 | wintitle=self.wintitle, | |
163 | width=self.widthscreen, |
|
200 | width=self.widthscreen, | |
164 | height=self.heightscreen, |
|
201 | height=self.heightscreen, | |
165 | show=show) |
|
202 | show=show) | |
166 |
|
203 | |||
167 | self.axesObjList = [] |
|
204 | self.axesObjList = [] | |
168 |
|
205 | |||
169 |
|
206 | |||
170 | def setDriver(self, driver=mpldriver): |
|
207 | def setDriver(self, driver=mpldriver): | |
171 |
|
208 | |||
172 | self.__driver = driver |
|
209 | self.__driver = driver | |
173 |
|
210 | |||
174 | def setTitle(self, title): |
|
211 | def setTitle(self, title): | |
175 |
|
212 | |||
176 | self.__driver.setTitle(self.fig, title) |
|
213 | self.__driver.setTitle(self.fig, title) | |
177 |
|
214 | |||
178 | def setWinTitle(self, title): |
|
215 | def setWinTitle(self, title): | |
179 |
|
216 | |||
180 | self.__driver.setWinTitle(self.fig, title=title) |
|
217 | self.__driver.setWinTitle(self.fig, title=title) | |
181 |
|
218 | |||
182 | def setTextFromAxes(self, text): |
|
219 | def setTextFromAxes(self, text): | |
183 |
|
220 | |||
184 | raise ValueError, "Este metodo ha sido reemplazaado con el metodo setText de la clase Axes" |
|
221 | raise ValueError, "Este metodo ha sido reemplazaado con el metodo setText de la clase Axes" | |
185 |
|
222 | |||
186 | def makeAxes(self, nrow, ncol, xpos, ypos, colspan, rowspan): |
|
223 | def makeAxes(self, nrow, ncol, xpos, ypos, colspan, rowspan): | |
187 |
|
224 | |||
188 | raise ValueError, "Este metodo ha sido reemplazaado con el metodo addAxes" |
|
225 | raise ValueError, "Este metodo ha sido reemplazaado con el metodo addAxes" | |
189 |
|
226 | |||
190 | def addAxes(self, *args): |
|
227 | def addAxes(self, *args): | |
191 | """ |
|
228 | """ | |
192 |
|
229 | |||
193 | Input: |
|
230 | Input: | |
194 | *args : Los parametros necesarios son |
|
231 | *args : Los parametros necesarios son | |
195 | nrow, ncol, xpos, ypos, colspan, rowspan |
|
232 | nrow, ncol, xpos, ypos, colspan, rowspan | |
196 | """ |
|
233 | """ | |
197 |
|
234 | |||
198 | axesObj = Axes(self.fig, *args) |
|
235 | axesObj = Axes(self.fig, *args) | |
199 | self.axesObjList.append(axesObj) |
|
236 | self.axesObjList.append(axesObj) | |
200 |
|
237 | |||
201 | def saveFigure(self, figpath, figfile, *args): |
|
238 | def saveFigure(self, figpath, figfile, *args): | |
202 |
|
239 | |||
203 | filename = os.path.join(figpath, figfile) |
|
240 | filename = os.path.join(figpath, figfile) | |
204 |
|
241 | |||
205 | fullpath = os.path.split(filename)[0] |
|
242 | fullpath = os.path.split(filename)[0] | |
206 |
|
243 | |||
207 | if not os.path.exists(fullpath): |
|
244 | if not os.path.exists(fullpath): | |
208 | subpath = os.path.split(fullpath)[0] |
|
245 | subpath = os.path.split(fullpath)[0] | |
209 |
|
246 | |||
210 | if not os.path.exists(subpath): |
|
247 | if not os.path.exists(subpath): | |
211 | os.mkdir(subpath) |
|
248 | os.mkdir(subpath) | |
212 |
|
249 | |||
213 | os.mkdir(fullpath) |
|
250 | os.mkdir(fullpath) | |
214 |
|
251 | |||
215 | self.__driver.saveFigure(self.fig, filename, *args) |
|
252 | self.__driver.saveFigure(self.fig, filename, *args) | |
216 |
|
253 | |||
217 | def sendByFTP(self, figfilename, server, folder, username, password): |
|
254 | def sendByFTP(self, figfilename, server, folder, username, password): | |
218 | ftpObj = Ftp(host=server, username=username, passw=password, remotefolder=folder) |
|
255 | ftpObj = Ftp(host=server, username=username, passw=password, remotefolder=folder) | |
219 | ftpObj.upload(figfilename) |
|
256 | ftpObj.upload(figfilename) | |
220 | ftpObj.close() |
|
257 | ftpObj.close() | |
221 |
|
258 | |||
222 | def sendByFTP_Thread(self, figfilename, server, folder, username, password): |
|
259 | def sendByFTP_Thread(self, figfilename, server, folder, username, password): | |
223 | data = {'figfilename':figfilename,'server':server,'folder':folder,'username':username,'password':password} |
|
260 | data = {'figfilename':figfilename,'server':server,'folder':folder,'username':username,'password':password} | |
224 |
|
261 | |||
225 | if not(self.__isConfigThread): |
|
262 | if not(self.__isConfigThread): | |
226 |
|
263 | |||
227 | self.thread = FTP_Thread() |
|
264 | self.thread = FTP_Thread() | |
228 | self.thread.start() |
|
265 | self.thread.start() | |
229 | self.__isConfigThread = True |
|
266 | self.__isConfigThread = True | |
230 |
|
267 | |||
231 | self.thread.put_data(data) |
|
268 | self.thread.put_data(data) | |
232 | #print 'thread.isAlive()', self.thread.isAlive() |
|
269 | #print 'thread.isAlive()', self.thread.isAlive() | |
233 |
|
270 | |||
234 |
|
271 | |||
235 | def getNameToFtp(self, thisDatetime, FTP_WEI, EXP_CODE, SUB_EXP_CODE, PLOT_CODE, PLOT_POS): |
|
272 | def getNameToFtp(self, thisDatetime, FTP_WEI, EXP_CODE, SUB_EXP_CODE, PLOT_CODE, PLOT_POS): | |
236 | YEAR_STR = '%4.4d'%thisDatetime.timetuple().tm_year |
|
273 | YEAR_STR = '%4.4d'%thisDatetime.timetuple().tm_year | |
237 | DOY_STR = '%3.3d'%thisDatetime.timetuple().tm_yday |
|
274 | DOY_STR = '%3.3d'%thisDatetime.timetuple().tm_yday | |
238 | FTP_WEI = '%2.2d'%FTP_WEI |
|
275 | FTP_WEI = '%2.2d'%FTP_WEI | |
239 | EXP_CODE = '%3.3d'%EXP_CODE |
|
276 | EXP_CODE = '%3.3d'%EXP_CODE | |
240 | SUB_EXP_CODE = '%2.2d'%SUB_EXP_CODE |
|
277 | SUB_EXP_CODE = '%2.2d'%SUB_EXP_CODE | |
241 | PLOT_CODE = '%2.2d'%PLOT_CODE |
|
278 | PLOT_CODE = '%2.2d'%PLOT_CODE | |
242 | PLOT_POS = '%2.2d'%PLOT_POS |
|
279 | PLOT_POS = '%2.2d'%PLOT_POS | |
243 | name = YEAR_STR + DOY_STR + FTP_WEI + EXP_CODE + SUB_EXP_CODE + PLOT_CODE + PLOT_POS |
|
280 | name = YEAR_STR + DOY_STR + FTP_WEI + EXP_CODE + SUB_EXP_CODE + PLOT_CODE + PLOT_POS | |
244 | return name |
|
281 | return name | |
245 |
|
282 | |||
246 | def draw(self): |
|
283 | def draw(self): | |
247 |
|
284 | |||
248 | self.__driver.draw(self.fig) |
|
285 | self.__driver.draw(self.fig) | |
249 |
|
286 | |||
250 | def run(self): |
|
287 | def run(self): | |
251 |
|
288 | |||
252 | raise ValueError, "This method is not implemented" |
|
289 | raise ValueError, "This method is not implemented" | |
253 |
|
290 | |||
254 | axesList = property(getAxesObjList) |
|
291 | axesList = property(getAxesObjList) | |
255 |
|
292 | |||
256 |
|
293 | |||
257 | class Axes: |
|
294 | class Axes: | |
258 |
|
295 | |||
259 | __driver = mpldriver |
|
296 | __driver = mpldriver | |
260 | fig = None |
|
297 | fig = None | |
261 | ax = None |
|
298 | ax = None | |
262 | plot = None |
|
299 | plot = None | |
263 | __missing = 1E30 |
|
300 | __missing = 1E30 | |
264 | __firsttime = None |
|
301 | __firsttime = None | |
265 |
|
302 | |||
266 | __showprofile = False |
|
303 | __showprofile = False | |
267 |
|
304 | |||
268 | xmin = None |
|
305 | xmin = None | |
269 | xmax = None |
|
306 | xmax = None | |
270 | ymin = None |
|
307 | ymin = None | |
271 | ymax = None |
|
308 | ymax = None | |
272 | zmin = None |
|
309 | zmin = None | |
273 | zmax = None |
|
310 | zmax = None | |
274 |
|
311 | |||
275 | x_buffer = None |
|
312 | x_buffer = None | |
276 | z_buffer = None |
|
313 | z_buffer = None | |
277 |
|
314 | |||
278 | decimationx = None |
|
315 | decimationx = None | |
279 | decimationy = None |
|
316 | decimationy = None | |
280 |
|
317 | |||
281 |
__MAXNUMX = |
|
318 | __MAXNUMX = 300 | |
282 |
__MAXNUMY = 50 |
|
319 | __MAXNUMY = 150 | |
283 |
|
320 | |||
284 | def __init__(self, *args): |
|
321 | def __init__(self, *args): | |
285 |
|
322 | |||
286 | """ |
|
323 | """ | |
287 |
|
324 | |||
288 | Input: |
|
325 | Input: | |
289 | *args : Los parametros necesarios son |
|
326 | *args : Los parametros necesarios son | |
290 | fig, nrow, ncol, xpos, ypos, colspan, rowspan |
|
327 | fig, nrow, ncol, xpos, ypos, colspan, rowspan | |
291 | """ |
|
328 | """ | |
292 |
|
329 | |||
293 | ax = self.__driver.createAxes(*args) |
|
330 | ax = self.__driver.createAxes(*args) | |
294 | self.fig = args[0] |
|
331 | self.fig = args[0] | |
295 | self.ax = ax |
|
332 | self.ax = ax | |
296 | self.plot = None |
|
333 | self.plot = None | |
297 |
|
334 | |||
298 | self.__firsttime = True |
|
335 | self.__firsttime = True | |
299 | self.idlineList = [] |
|
336 | self.idlineList = [] | |
300 |
|
337 | |||
301 | self.x_buffer = numpy.array([]) |
|
338 | self.x_buffer = numpy.array([]) | |
302 | self.z_buffer = numpy.array([]) |
|
339 | self.z_buffer = numpy.array([]) | |
303 |
|
340 | |||
304 | def setText(self, text): |
|
341 | def setText(self, text): | |
305 |
|
342 | |||
306 | self.__driver.setAxesText(self.ax, text) |
|
343 | self.__driver.setAxesText(self.ax, text) | |
307 |
|
344 | |||
308 | def setXAxisAsTime(self): |
|
345 | def setXAxisAsTime(self): | |
309 | pass |
|
346 | pass | |
310 |
|
347 | |||
311 | def pline(self, x, y, |
|
348 | def pline(self, x, y, | |
312 | xmin=None, xmax=None, |
|
349 | xmin=None, xmax=None, | |
313 | ymin=None, ymax=None, |
|
350 | ymin=None, ymax=None, | |
314 | xlabel='', ylabel='', |
|
351 | xlabel='', ylabel='', | |
315 | title='', |
|
352 | title='', | |
316 | **kwargs): |
|
353 | **kwargs): | |
317 |
|
354 | |||
318 | """ |
|
355 | """ | |
319 |
|
356 | |||
320 | Input: |
|
357 | Input: | |
321 | x : |
|
358 | x : | |
322 | y : |
|
359 | y : | |
323 | xmin : |
|
360 | xmin : | |
324 | xmax : |
|
361 | xmax : | |
325 | ymin : |
|
362 | ymin : | |
326 | ymax : |
|
363 | ymax : | |
327 | xlabel : |
|
364 | xlabel : | |
328 | ylabel : |
|
365 | ylabel : | |
329 | title : |
|
366 | title : | |
330 | **kwargs : Los parametros aceptados son |
|
367 | **kwargs : Los parametros aceptados son | |
331 |
|
368 | |||
332 | ticksize |
|
369 | ticksize | |
333 | ytick_visible |
|
370 | ytick_visible | |
334 | """ |
|
371 | """ | |
335 |
|
372 | |||
336 | if self.__firsttime: |
|
373 | if self.__firsttime: | |
337 |
|
374 | |||
338 | if xmin == None: xmin = numpy.nanmin(x) |
|
375 | if xmin == None: xmin = numpy.nanmin(x) | |
339 | if xmax == None: xmax = numpy.nanmax(x) |
|
376 | if xmax == None: xmax = numpy.nanmax(x) | |
340 | if ymin == None: ymin = numpy.nanmin(y) |
|
377 | if ymin == None: ymin = numpy.nanmin(y) | |
341 | if ymax == None: ymax = numpy.nanmax(y) |
|
378 | if ymax == None: ymax = numpy.nanmax(y) | |
342 |
|
379 | |||
343 | self.plot = self.__driver.createPline(self.ax, x, y, |
|
380 | self.plot = self.__driver.createPline(self.ax, x, y, | |
344 | xmin, xmax, |
|
381 | xmin, xmax, | |
345 | ymin, ymax, |
|
382 | ymin, ymax, | |
346 | xlabel=xlabel, |
|
383 | xlabel=xlabel, | |
347 | ylabel=ylabel, |
|
384 | ylabel=ylabel, | |
348 | title=title, |
|
385 | title=title, | |
349 | **kwargs) |
|
386 | **kwargs) | |
350 |
|
387 | |||
351 | self.idlineList.append(0) |
|
388 | self.idlineList.append(0) | |
352 | self.__firsttime = False |
|
389 | self.__firsttime = False | |
353 | return |
|
390 | return | |
354 |
|
391 | |||
355 | self.__driver.pline(self.plot, x, y, xlabel=xlabel, |
|
392 | self.__driver.pline(self.plot, x, y, xlabel=xlabel, | |
356 | ylabel=ylabel, |
|
393 | ylabel=ylabel, | |
357 | title=title) |
|
394 | title=title) | |
358 |
|
395 | |||
359 | def addpline(self, x, y, idline, **kwargs): |
|
396 | def addpline(self, x, y, idline, **kwargs): | |
360 | lines = self.ax.lines |
|
397 | lines = self.ax.lines | |
361 |
|
398 | |||
362 | if idline in self.idlineList: |
|
399 | if idline in self.idlineList: | |
363 | self.__driver.set_linedata(self.ax, x, y, idline) |
|
400 | self.__driver.set_linedata(self.ax, x, y, idline) | |
364 |
|
401 | |||
365 | if idline not in(self.idlineList): |
|
402 | if idline not in(self.idlineList): | |
366 | self.__driver.addpline(self.ax, x, y, **kwargs) |
|
403 | self.__driver.addpline(self.ax, x, y, **kwargs) | |
367 | self.idlineList.append(idline) |
|
404 | self.idlineList.append(idline) | |
368 |
|
405 | |||
369 | return |
|
406 | return | |
370 |
|
407 | |||
371 | def pmultiline(self, x, y, |
|
408 | def pmultiline(self, x, y, | |
372 | xmin=None, xmax=None, |
|
409 | xmin=None, xmax=None, | |
373 | ymin=None, ymax=None, |
|
410 | ymin=None, ymax=None, | |
374 | xlabel='', ylabel='', |
|
411 | xlabel='', ylabel='', | |
375 | title='', |
|
412 | title='', | |
376 | **kwargs): |
|
413 | **kwargs): | |
377 |
|
414 | |||
378 | if self.__firsttime: |
|
415 | if self.__firsttime: | |
379 |
|
416 | |||
380 | if xmin == None: xmin = numpy.nanmin(x) |
|
417 | if xmin == None: xmin = numpy.nanmin(x) | |
381 | if xmax == None: xmax = numpy.nanmax(x) |
|
418 | if xmax == None: xmax = numpy.nanmax(x) | |
382 | if ymin == None: ymin = numpy.nanmin(y) |
|
419 | if ymin == None: ymin = numpy.nanmin(y) | |
383 | if ymax == None: ymax = numpy.nanmax(y) |
|
420 | if ymax == None: ymax = numpy.nanmax(y) | |
384 |
|
421 | |||
385 | self.plot = self.__driver.createPmultiline(self.ax, x, y, |
|
422 | self.plot = self.__driver.createPmultiline(self.ax, x, y, | |
386 | xmin, xmax, |
|
423 | xmin, xmax, | |
387 | ymin, ymax, |
|
424 | ymin, ymax, | |
388 | xlabel=xlabel, |
|
425 | xlabel=xlabel, | |
389 | ylabel=ylabel, |
|
426 | ylabel=ylabel, | |
390 | title=title, |
|
427 | title=title, | |
391 | **kwargs) |
|
428 | **kwargs) | |
392 | self.__firsttime = False |
|
429 | self.__firsttime = False | |
393 | return |
|
430 | return | |
394 |
|
431 | |||
395 | self.__driver.pmultiline(self.plot, x, y, xlabel=xlabel, |
|
432 | self.__driver.pmultiline(self.plot, x, y, xlabel=xlabel, | |
396 | ylabel=ylabel, |
|
433 | ylabel=ylabel, | |
397 | title=title) |
|
434 | title=title) | |
398 |
|
435 | |||
399 | def pmultilineyaxis(self, x, y, |
|
436 | def pmultilineyaxis(self, x, y, | |
400 | xmin=None, xmax=None, |
|
437 | xmin=None, xmax=None, | |
401 | ymin=None, ymax=None, |
|
438 | ymin=None, ymax=None, | |
402 | xlabel='', ylabel='', |
|
439 | xlabel='', ylabel='', | |
403 | title='', |
|
440 | title='', | |
404 | **kwargs): |
|
441 | **kwargs): | |
405 |
|
442 | |||
406 | if self.__firsttime: |
|
443 | if self.__firsttime: | |
407 |
|
444 | |||
408 | if xmin == None: xmin = numpy.nanmin(x) |
|
445 | if xmin == None: xmin = numpy.nanmin(x) | |
409 | if xmax == None: xmax = numpy.nanmax(x) |
|
446 | if xmax == None: xmax = numpy.nanmax(x) | |
410 | if ymin == None: ymin = numpy.nanmin(y) |
|
447 | if ymin == None: ymin = numpy.nanmin(y) | |
411 | if ymax == None: ymax = numpy.nanmax(y) |
|
448 | if ymax == None: ymax = numpy.nanmax(y) | |
412 |
|
449 | |||
413 | self.plot = self.__driver.createPmultilineYAxis(self.ax, x, y, |
|
450 | self.plot = self.__driver.createPmultilineYAxis(self.ax, x, y, | |
414 | xmin, xmax, |
|
451 | xmin, xmax, | |
415 | ymin, ymax, |
|
452 | ymin, ymax, | |
416 | xlabel=xlabel, |
|
453 | xlabel=xlabel, | |
417 | ylabel=ylabel, |
|
454 | ylabel=ylabel, | |
418 | title=title, |
|
455 | title=title, | |
419 | **kwargs) |
|
456 | **kwargs) | |
420 | if self.xmin == None: self.xmin = xmin |
|
457 | if self.xmin == None: self.xmin = xmin | |
421 | if self.xmax == None: self.xmax = xmax |
|
458 | if self.xmax == None: self.xmax = xmax | |
422 | if self.ymin == None: self.ymin = ymin |
|
459 | if self.ymin == None: self.ymin = ymin | |
423 | if self.ymax == None: self.ymax = ymax |
|
460 | if self.ymax == None: self.ymax = ymax | |
424 |
|
461 | |||
425 | self.__firsttime = False |
|
462 | self.__firsttime = False | |
426 | return |
|
463 | return | |
427 |
|
464 | |||
428 | self.__driver.pmultilineyaxis(self.plot, x, y, xlabel=xlabel, |
|
465 | self.__driver.pmultilineyaxis(self.plot, x, y, xlabel=xlabel, | |
429 | ylabel=ylabel, |
|
466 | ylabel=ylabel, | |
430 | title=title) |
|
467 | title=title) | |
431 |
|
468 | |||
432 | def pcolor(self, x, y, z, |
|
469 | def pcolor(self, x, y, z, | |
433 | xmin=None, xmax=None, |
|
470 | xmin=None, xmax=None, | |
434 | ymin=None, ymax=None, |
|
471 | ymin=None, ymax=None, | |
435 | zmin=None, zmax=None, |
|
472 | zmin=None, zmax=None, | |
436 | xlabel='', ylabel='', |
|
473 | xlabel='', ylabel='', | |
437 | title='', rti = False, colormap='jet', |
|
474 | title='', rti = False, colormap='jet', | |
438 | **kwargs): |
|
475 | **kwargs): | |
439 |
|
476 | |||
440 | """ |
|
477 | """ | |
441 | Input: |
|
478 | Input: | |
442 | x : |
|
479 | x : | |
443 | y : |
|
480 | y : | |
444 | x : |
|
481 | x : | |
445 | xmin : |
|
482 | xmin : | |
446 | xmax : |
|
483 | xmax : | |
447 | ymin : |
|
484 | ymin : | |
448 | ymax : |
|
485 | ymax : | |
449 | zmin : |
|
486 | zmin : | |
450 | zmax : |
|
487 | zmax : | |
451 | xlabel : |
|
488 | xlabel : | |
452 | ylabel : |
|
489 | ylabel : | |
453 | title : |
|
490 | title : | |
454 | **kwargs : Los parametros aceptados son |
|
491 | **kwargs : Los parametros aceptados son | |
455 | ticksize=9, |
|
492 | ticksize=9, | |
456 | cblabel='' |
|
493 | cblabel='' | |
457 | rti = True or False |
|
494 | rti = True or False | |
458 | """ |
|
495 | """ | |
459 |
|
496 | |||
460 | if self.__firsttime: |
|
497 | if self.__firsttime: | |
461 |
|
498 | |||
462 | if xmin == None: xmin = numpy.nanmin(x) |
|
499 | if xmin == None: xmin = numpy.nanmin(x) | |
463 | if xmax == None: xmax = numpy.nanmax(x) |
|
500 | if xmax == None: xmax = numpy.nanmax(x) | |
464 | if ymin == None: ymin = numpy.nanmin(y) |
|
501 | if ymin == None: ymin = numpy.nanmin(y) | |
465 | if ymax == None: ymax = numpy.nanmax(y) |
|
502 | if ymax == None: ymax = numpy.nanmax(y) | |
466 | if zmin == None: zmin = numpy.nanmin(z) |
|
503 | if zmin == None: zmin = numpy.nanmin(z) | |
467 | if zmax == None: zmax = numpy.nanmax(z) |
|
504 | if zmax == None: zmax = numpy.nanmax(z) | |
468 |
|
505 | |||
469 |
|
506 | |||
470 | self.plot = self.__driver.createPcolor(self.ax, x, y, z, |
|
507 | self.plot = self.__driver.createPcolor(self.ax, x, y, z, | |
471 | xmin, xmax, |
|
508 | xmin, xmax, | |
472 | ymin, ymax, |
|
509 | ymin, ymax, | |
473 | zmin, zmax, |
|
510 | zmin, zmax, | |
474 | xlabel=xlabel, |
|
511 | xlabel=xlabel, | |
475 | ylabel=ylabel, |
|
512 | ylabel=ylabel, | |
476 | title=title, |
|
513 | title=title, | |
477 | colormap=colormap, |
|
514 | colormap=colormap, | |
478 | **kwargs) |
|
515 | **kwargs) | |
479 |
|
516 | |||
480 | if self.xmin == None: self.xmin = xmin |
|
517 | if self.xmin == None: self.xmin = xmin | |
481 | if self.xmax == None: self.xmax = xmax |
|
518 | if self.xmax == None: self.xmax = xmax | |
482 | if self.ymin == None: self.ymin = ymin |
|
519 | if self.ymin == None: self.ymin = ymin | |
483 | if self.ymax == None: self.ymax = ymax |
|
520 | if self.ymax == None: self.ymax = ymax | |
484 | if self.zmin == None: self.zmin = zmin |
|
521 | if self.zmin == None: self.zmin = zmin | |
485 | if self.zmax == None: self.zmax = zmax |
|
522 | if self.zmax == None: self.zmax = zmax | |
486 |
|
523 | |||
487 | self.__firsttime = False |
|
524 | self.__firsttime = False | |
488 | return |
|
525 | return | |
489 |
|
526 | |||
490 | if rti: |
|
527 | if rti: | |
491 | self.__driver.addpcolor(self.ax, x, y, z, self.zmin, self.zmax, |
|
528 | self.__driver.addpcolor(self.ax, x, y, z, self.zmin, self.zmax, | |
492 | xlabel=xlabel, |
|
529 | xlabel=xlabel, | |
493 | ylabel=ylabel, |
|
530 | ylabel=ylabel, | |
494 | title=title, |
|
531 | title=title, | |
495 | colormap=colormap) |
|
532 | colormap=colormap) | |
496 | return |
|
533 | return | |
497 |
|
534 | |||
498 | self.__driver.pcolor(self.plot, z, |
|
535 | self.__driver.pcolor(self.plot, z, | |
499 | xlabel=xlabel, |
|
536 | xlabel=xlabel, | |
500 | ylabel=ylabel, |
|
537 | ylabel=ylabel, | |
501 | title=title) |
|
538 | title=title) | |
502 |
|
539 | |||
503 | def pcolorbuffer(self, x, y, z, |
|
540 | def pcolorbuffer(self, x, y, z, | |
504 | xmin=None, xmax=None, |
|
541 | xmin=None, xmax=None, | |
505 | ymin=None, ymax=None, |
|
542 | ymin=None, ymax=None, | |
506 | zmin=None, zmax=None, |
|
543 | zmin=None, zmax=None, | |
507 | xlabel='', ylabel='', |
|
544 | xlabel='', ylabel='', | |
508 | title='', rti = True, colormap='jet', |
|
545 | title='', rti = True, colormap='jet', | |
509 | maxNumX = None, maxNumY = None, |
|
546 | maxNumX = None, maxNumY = None, | |
510 | **kwargs): |
|
547 | **kwargs): | |
511 |
|
548 | |||
512 | if maxNumX == None: |
|
549 | if maxNumX == None: | |
513 | maxNumX = self.__MAXNUMX |
|
550 | maxNumX = self.__MAXNUMX | |
514 |
|
551 | |||
515 | if maxNumY == None: |
|
552 | if maxNumY == None: | |
516 | maxNumY = self.__MAXNUMY |
|
553 | maxNumY = self.__MAXNUMY | |
517 |
|
554 | |||
518 | if self.__firsttime: |
|
555 | if self.__firsttime: | |
519 | self.z_buffer = z |
|
556 | self.z_buffer = z | |
520 | self.x_buffer = numpy.hstack((self.x_buffer, x)) |
|
557 | self.x_buffer = numpy.hstack((self.x_buffer, x)) | |
521 |
|
558 | |||
522 | if xmin == None: xmin = numpy.nanmin(x) |
|
559 | if xmin == None: xmin = numpy.nanmin(x) | |
523 | if xmax == None: xmax = numpy.nanmax(x) |
|
560 | if xmax == None: xmax = numpy.nanmax(x) | |
524 | if ymin == None: ymin = numpy.nanmin(y) |
|
561 | if ymin == None: ymin = numpy.nanmin(y) | |
525 | if ymax == None: ymax = numpy.nanmax(y) |
|
562 | if ymax == None: ymax = numpy.nanmax(y) | |
526 | if zmin == None: zmin = numpy.nanmin(z) |
|
563 | if zmin == None: zmin = numpy.nanmin(z) | |
527 | if zmax == None: zmax = numpy.nanmax(z) |
|
564 | if zmax == None: zmax = numpy.nanmax(z) | |
528 |
|
565 | |||
529 |
|
566 | |||
530 | self.plot = self.__driver.createPcolor(self.ax, self.x_buffer, y, z, |
|
567 | self.plot = self.__driver.createPcolor(self.ax, self.x_buffer, y, z, | |
531 | xmin, xmax, |
|
568 | xmin, xmax, | |
532 | ymin, ymax, |
|
569 | ymin, ymax, | |
533 | zmin, zmax, |
|
570 | zmin, zmax, | |
534 | xlabel=xlabel, |
|
571 | xlabel=xlabel, | |
535 | ylabel=ylabel, |
|
572 | ylabel=ylabel, | |
536 | title=title, |
|
573 | title=title, | |
537 | colormap=colormap, |
|
574 | colormap=colormap, | |
538 | **kwargs) |
|
575 | **kwargs) | |
539 |
|
576 | |||
540 | if self.xmin == None: self.xmin = xmin |
|
577 | if self.xmin == None: self.xmin = xmin | |
541 | if self.xmax == None: self.xmax = xmax |
|
578 | if self.xmax == None: self.xmax = xmax | |
542 | if self.ymin == None: self.ymin = ymin |
|
579 | if self.ymin == None: self.ymin = ymin | |
543 | if self.ymax == None: self.ymax = ymax |
|
580 | if self.ymax == None: self.ymax = ymax | |
544 | if self.zmin == None: self.zmin = zmin |
|
581 | if self.zmin == None: self.zmin = zmin | |
545 | if self.zmax == None: self.zmax = zmax |
|
582 | if self.zmax == None: self.zmax = zmax | |
546 |
|
583 | |||
547 | self.__firsttime = False |
|
584 | self.__firsttime = False | |
548 | return |
|
585 | return | |
549 |
|
586 | |||
550 | self.x_buffer = numpy.hstack((self.x_buffer, x[-1])) |
|
587 | self.x_buffer = numpy.hstack((self.x_buffer, x[-1])) | |
551 | self.z_buffer = numpy.hstack((self.z_buffer, z)) |
|
588 | self.z_buffer = numpy.hstack((self.z_buffer, z)) | |
552 |
|
589 | |||
553 | if self.decimationx == None: |
|
590 | if self.decimationx == None: | |
554 | deltax = float(self.xmax - self.xmin)/maxNumX |
|
591 | deltax = float(self.xmax - self.xmin)/maxNumX | |
555 | deltay = float(self.ymax - self.ymin)/maxNumY |
|
592 | deltay = float(self.ymax - self.ymin)/maxNumY | |
556 |
|
593 | |||
557 | resolutionx = self.x_buffer[2]-self.x_buffer[0] |
|
594 | resolutionx = self.x_buffer[2]-self.x_buffer[0] | |
558 | resolutiony = y[1]-y[0] |
|
595 | resolutiony = y[1]-y[0] | |
559 |
|
596 | |||
560 | self.decimationx = numpy.ceil(deltax / resolutionx) |
|
597 | self.decimationx = numpy.ceil(deltax / resolutionx) | |
561 | self.decimationy = numpy.ceil(deltay / resolutiony) |
|
598 | self.decimationy = numpy.ceil(deltay / resolutiony) | |
562 |
|
599 | |||
563 | z_buffer = self.z_buffer.reshape(-1,len(y)) |
|
600 | z_buffer = self.z_buffer.reshape(-1,len(y)) | |
564 |
|
601 | |||
565 | x_buffer = self.x_buffer[::self.decimationx] |
|
602 | x_buffer = self.x_buffer[::self.decimationx] | |
566 | y_buffer = y[::self.decimationy] |
|
603 | y_buffer = y[::self.decimationy] | |
567 | z_buffer = z_buffer[::self.decimationx, ::self.decimationy] |
|
604 | z_buffer = z_buffer[::self.decimationx, ::self.decimationy] | |
568 | #=================================================== |
|
605 | #=================================================== | |
569 |
|
606 | |||
570 | x_buffer, y_buffer, z_buffer = self.__fillGaps(x_buffer, y_buffer, z_buffer) |
|
607 | x_buffer, y_buffer, z_buffer = self.__fillGaps(x_buffer, y_buffer, z_buffer) | |
571 |
|
608 | |||
572 | self.__driver.addpcolorbuffer(self.ax, x_buffer, y_buffer, z_buffer, self.zmin, self.zmax, |
|
609 | self.__driver.addpcolorbuffer(self.ax, x_buffer, y_buffer, z_buffer, self.zmin, self.zmax, | |
573 | xlabel=xlabel, |
|
610 | xlabel=xlabel, | |
574 | ylabel=ylabel, |
|
611 | ylabel=ylabel, | |
575 | title=title, |
|
612 | title=title, | |
576 | colormap=colormap) |
|
613 | colormap=colormap) | |
577 | def __fillGaps(self, x_buffer, y_buffer, z_buffer): |
|
614 | def __fillGaps(self, x_buffer, y_buffer, z_buffer): | |
578 |
|
615 | |||
579 | deltas = x_buffer[1:] - x_buffer[0:-1] |
|
616 | deltas = x_buffer[1:] - x_buffer[0:-1] | |
580 | x_median = numpy.median(deltas) |
|
617 | x_median = numpy.median(deltas) | |
581 |
|
618 | |||
582 | index = numpy.where(deltas >= 2*x_median) |
|
619 | index = numpy.where(deltas >= 2*x_median) | |
583 |
|
620 | |||
584 | if len(index[0]) != 0: |
|
621 | if len(index[0]) != 0: | |
585 | z_buffer[index[0],::] = self.__missing |
|
622 | z_buffer[index[0],::] = self.__missing | |
586 | z_buffer = numpy.ma.masked_inside(z_buffer,0.99*self.__missing,1.01*self.__missing) |
|
623 | z_buffer = numpy.ma.masked_inside(z_buffer,0.99*self.__missing,1.01*self.__missing) | |
587 |
|
624 | |||
588 | return x_buffer, y_buffer, z_buffer |
|
625 | return x_buffer, y_buffer, z_buffer | |
589 |
|
626 | |||
590 |
|
627 | |||
591 |
|
628 | |||
592 | No newline at end of file |
|
629 |
@@ -1,2000 +1,2033 | |||||
1 | import numpy |
|
1 | import numpy | |
2 | import time, datetime, os |
|
2 | import time, datetime, os | |
3 | from graphics.figure import * |
|
3 | from graphics.figure import * | |
4 | def isRealtime(utcdatatime): |
|
4 | def isRealtime(utcdatatime): | |
5 | utcnow = time.mktime(time.localtime()) |
|
5 | utcnow = time.mktime(time.localtime()) | |
6 | delta = abs(utcnow - utcdatatime) # abs |
|
6 | delta = abs(utcnow - utcdatatime) # abs | |
7 | if delta >= 30.: |
|
7 | if delta >= 30.: | |
8 | return False |
|
8 | return False | |
9 | return True |
|
9 | return True | |
10 |
|
10 | |||
11 | class CrossSpectraPlot(Figure): |
|
11 | class CrossSpectraPlot(Figure): | |
12 |
|
12 | |||
13 | __isConfig = None |
|
13 | __isConfig = None | |
14 | __nsubplots = None |
|
14 | __nsubplots = None | |
15 |
|
15 | |||
16 | WIDTH = None |
|
16 | WIDTH = None | |
17 | HEIGHT = None |
|
17 | HEIGHT = None | |
18 | WIDTHPROF = None |
|
18 | WIDTHPROF = None | |
19 | HEIGHTPROF = None |
|
19 | HEIGHTPROF = None | |
20 | PREFIX = 'cspc' |
|
20 | PREFIX = 'cspc' | |
21 |
|
21 | |||
22 | def __init__(self): |
|
22 | def __init__(self): | |
23 |
|
23 | |||
24 | self.__isConfig = False |
|
24 | self.__isConfig = False | |
25 | self.__nsubplots = 4 |
|
25 | self.__nsubplots = 4 | |
26 | self.counter_imagwr = 0 |
|
26 | self.counter_imagwr = 0 | |
27 | self.WIDTH = 250 |
|
27 | self.WIDTH = 250 | |
28 | self.HEIGHT = 250 |
|
28 | self.HEIGHT = 250 | |
29 | self.WIDTHPROF = 0 |
|
29 | self.WIDTHPROF = 0 | |
30 | self.HEIGHTPROF = 0 |
|
30 | self.HEIGHTPROF = 0 | |
31 |
|
31 | |||
32 | self.PLOT_CODE = 1 |
|
32 | self.PLOT_CODE = 1 | |
33 | self.FTP_WEI = None |
|
33 | self.FTP_WEI = None | |
34 | self.EXP_CODE = None |
|
34 | self.EXP_CODE = None | |
35 | self.SUB_EXP_CODE = None |
|
35 | self.SUB_EXP_CODE = None | |
36 | self.PLOT_POS = None |
|
36 | self.PLOT_POS = None | |
37 |
|
37 | |||
38 | def getSubplots(self): |
|
38 | def getSubplots(self): | |
39 |
|
39 | |||
40 | ncol = 4 |
|
40 | ncol = 4 | |
41 | nrow = self.nplots |
|
41 | nrow = self.nplots | |
42 |
|
42 | |||
43 | return nrow, ncol |
|
43 | return nrow, ncol | |
44 |
|
44 | |||
45 | def setup(self, id, nplots, wintitle, showprofile=True, show=True): |
|
45 | def setup(self, id, nplots, wintitle, showprofile=True, show=True): | |
46 |
|
46 | |||
47 | self.__showprofile = showprofile |
|
47 | self.__showprofile = showprofile | |
48 | self.nplots = nplots |
|
48 | self.nplots = nplots | |
49 |
|
49 | |||
50 | ncolspan = 1 |
|
50 | ncolspan = 1 | |
51 | colspan = 1 |
|
51 | colspan = 1 | |
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=True) |
|
57 | show=True) | |
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 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1) |
|
64 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1) | |
65 |
|
65 | |||
66 | counter += 1 |
|
66 | counter += 1 | |
67 |
|
67 | |||
68 | def run(self, dataOut, id, wintitle="", pairsList=None, |
|
68 | def run(self, dataOut, id, wintitle="", pairsList=None, | |
69 | xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None, |
|
69 | xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None, | |
70 | save=False, figpath='./', figfile=None, ftp=False, wr_period=1, |
|
70 | save=False, figpath='./', figfile=None, ftp=False, wr_period=1, | |
71 | power_cmap='jet', coherence_cmap='jet', phase_cmap='RdBu_r', show=True, |
|
71 | power_cmap='jet', coherence_cmap='jet', phase_cmap='RdBu_r', show=True, | |
72 | server=None, folder=None, username=None, password=None, |
|
72 | server=None, folder=None, username=None, password=None, | |
73 | ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0): |
|
73 | ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0): | |
74 |
|
74 | |||
75 | """ |
|
75 | """ | |
76 |
|
76 | |||
77 | Input: |
|
77 | Input: | |
78 | dataOut : |
|
78 | dataOut : | |
79 | id : |
|
79 | id : | |
80 | wintitle : |
|
80 | wintitle : | |
81 | channelList : |
|
81 | channelList : | |
82 | showProfile : |
|
82 | showProfile : | |
83 | xmin : None, |
|
83 | xmin : None, | |
84 | xmax : None, |
|
84 | xmax : None, | |
85 | ymin : None, |
|
85 | ymin : None, | |
86 | ymax : None, |
|
86 | ymax : None, | |
87 | zmin : None, |
|
87 | zmin : None, | |
88 | zmax : None |
|
88 | zmax : None | |
89 | """ |
|
89 | """ | |
90 |
|
90 | |||
91 | if pairsList == None: |
|
91 | if pairsList == None: | |
92 | pairsIndexList = dataOut.pairsIndexList |
|
92 | pairsIndexList = dataOut.pairsIndexList | |
93 | else: |
|
93 | else: | |
94 | pairsIndexList = [] |
|
94 | pairsIndexList = [] | |
95 | for pair in pairsList: |
|
95 | for pair in pairsList: | |
96 | if pair not in dataOut.pairsList: |
|
96 | if pair not in dataOut.pairsList: | |
97 | raise ValueError, "Pair %s is not in dataOut.pairsList" %(pair) |
|
97 | raise ValueError, "Pair %s is not in dataOut.pairsList" %(pair) | |
98 | pairsIndexList.append(dataOut.pairsList.index(pair)) |
|
98 | pairsIndexList.append(dataOut.pairsList.index(pair)) | |
99 |
|
99 | |||
100 | if pairsIndexList == []: |
|
100 | if pairsIndexList == []: | |
101 | return |
|
101 | return | |
102 |
|
102 | |||
103 | if len(pairsIndexList) > 4: |
|
103 | if len(pairsIndexList) > 4: | |
104 | pairsIndexList = pairsIndexList[0:4] |
|
104 | pairsIndexList = pairsIndexList[0:4] | |
105 | factor = dataOut.normFactor |
|
105 | factor = dataOut.normFactor | |
106 | x = dataOut.getVelRange(1) |
|
106 | x = dataOut.getVelRange(1) | |
107 | y = dataOut.getHeiRange() |
|
107 | y = dataOut.getHeiRange() | |
108 | z = dataOut.data_spc[:,:,:]/factor |
|
108 | z = dataOut.data_spc[:,:,:]/factor | |
109 | # z = numpy.where(numpy.isfinite(z), z, numpy.NAN) |
|
109 | # z = numpy.where(numpy.isfinite(z), z, numpy.NAN) | |
110 | avg = numpy.abs(numpy.average(z, axis=1)) |
|
110 | avg = numpy.abs(numpy.average(z, axis=1)) | |
111 | noise = dataOut.getNoise()/factor |
|
111 | noise = dataOut.getNoise()/factor | |
112 |
|
112 | |||
113 | zdB = 10*numpy.log10(z) |
|
113 | zdB = 10*numpy.log10(z) | |
114 | avgdB = 10*numpy.log10(avg) |
|
114 | avgdB = 10*numpy.log10(avg) | |
115 | noisedB = 10*numpy.log10(noise) |
|
115 | noisedB = 10*numpy.log10(noise) | |
116 |
|
116 | |||
117 |
|
117 | |||
118 | #thisDatetime = dataOut.datatime |
|
118 | #thisDatetime = dataOut.datatime | |
119 | thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[1]) |
|
119 | thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[1]) | |
120 | title = wintitle + " Cross-Spectra: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) |
|
120 | title = wintitle + " Cross-Spectra: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) | |
121 | xlabel = "Velocity (m/s)" |
|
121 | xlabel = "Velocity (m/s)" | |
122 | ylabel = "Range (Km)" |
|
122 | ylabel = "Range (Km)" | |
123 |
|
123 | |||
124 | if not self.__isConfig: |
|
124 | if not self.__isConfig: | |
125 |
|
125 | |||
126 | nplots = len(pairsIndexList) |
|
126 | nplots = len(pairsIndexList) | |
127 |
|
127 | |||
128 | self.setup(id=id, |
|
128 | self.setup(id=id, | |
129 | nplots=nplots, |
|
129 | nplots=nplots, | |
130 | wintitle=wintitle, |
|
130 | wintitle=wintitle, | |
131 | showprofile=False, |
|
131 | showprofile=False, | |
132 | show=show) |
|
132 | show=show) | |
133 |
|
133 | |||
134 | if xmin == None: xmin = numpy.nanmin(x) |
|
134 | if xmin == None: xmin = numpy.nanmin(x) | |
135 | if xmax == None: xmax = numpy.nanmax(x) |
|
135 | if xmax == None: xmax = numpy.nanmax(x) | |
136 | if ymin == None: ymin = numpy.nanmin(y) |
|
136 | if ymin == None: ymin = numpy.nanmin(y) | |
137 | if ymax == None: ymax = numpy.nanmax(y) |
|
137 | if ymax == None: ymax = numpy.nanmax(y) | |
138 | if zmin == None: zmin = numpy.nanmin(avgdB)*0.9 |
|
138 | if zmin == None: zmin = numpy.nanmin(avgdB)*0.9 | |
139 | if zmax == None: zmax = numpy.nanmax(avgdB)*0.9 |
|
139 | if zmax == None: zmax = numpy.nanmax(avgdB)*0.9 | |
140 |
|
140 | |||
141 | self.FTP_WEI = ftp_wei |
|
141 | self.FTP_WEI = ftp_wei | |
142 | self.EXP_CODE = exp_code |
|
142 | self.EXP_CODE = exp_code | |
143 | self.SUB_EXP_CODE = sub_exp_code |
|
143 | self.SUB_EXP_CODE = sub_exp_code | |
144 | self.PLOT_POS = plot_pos |
|
144 | self.PLOT_POS = plot_pos | |
145 |
|
145 | |||
146 | self.__isConfig = True |
|
146 | self.__isConfig = True | |
147 |
|
147 | |||
148 | self.setWinTitle(title) |
|
148 | self.setWinTitle(title) | |
149 |
|
149 | |||
150 | for i in range(self.nplots): |
|
150 | for i in range(self.nplots): | |
151 | pair = dataOut.pairsList[pairsIndexList[i]] |
|
151 | pair = dataOut.pairsList[pairsIndexList[i]] | |
152 | str_datetime = '%s %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S")) |
|
152 | str_datetime = '%s %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S")) | |
153 | title = "Ch%d: %4.2fdB: %s" %(pair[0], noisedB[pair[0]], str_datetime) |
|
153 | title = "Ch%d: %4.2fdB: %s" %(pair[0], noisedB[pair[0]], str_datetime) | |
154 | zdB = 10.*numpy.log10(dataOut.data_spc[pair[0],:,:]) |
|
154 | zdB = 10.*numpy.log10(dataOut.data_spc[pair[0],:,:]) | |
155 | axes0 = self.axesList[i*self.__nsubplots] |
|
155 | axes0 = self.axesList[i*self.__nsubplots] | |
156 | axes0.pcolor(x, y, zdB, |
|
156 | axes0.pcolor(x, y, zdB, | |
157 | xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax, |
|
157 | xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax, | |
158 | xlabel=xlabel, ylabel=ylabel, title=title, |
|
158 | xlabel=xlabel, ylabel=ylabel, title=title, | |
159 | ticksize=9, colormap=power_cmap, cblabel='') |
|
159 | ticksize=9, colormap=power_cmap, cblabel='') | |
160 |
|
160 | |||
161 | title = "Ch%d: %4.2fdB: %s" %(pair[1], noisedB[pair[1]], str_datetime) |
|
161 | title = "Ch%d: %4.2fdB: %s" %(pair[1], noisedB[pair[1]], str_datetime) | |
162 | zdB = 10.*numpy.log10(dataOut.data_spc[pair[1],:,:]) |
|
162 | zdB = 10.*numpy.log10(dataOut.data_spc[pair[1],:,:]) | |
163 | axes0 = self.axesList[i*self.__nsubplots+1] |
|
163 | axes0 = self.axesList[i*self.__nsubplots+1] | |
164 | axes0.pcolor(x, y, zdB, |
|
164 | axes0.pcolor(x, y, zdB, | |
165 | xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax, |
|
165 | xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax, | |
166 | xlabel=xlabel, ylabel=ylabel, title=title, |
|
166 | xlabel=xlabel, ylabel=ylabel, title=title, | |
167 | ticksize=9, colormap=power_cmap, cblabel='') |
|
167 | ticksize=9, colormap=power_cmap, cblabel='') | |
168 |
|
168 | |||
169 | coherenceComplex = dataOut.data_cspc[pairsIndexList[i],:,:]/numpy.sqrt(dataOut.data_spc[pair[0],:,:]*dataOut.data_spc[pair[1],:,:]) |
|
169 | coherenceComplex = dataOut.data_cspc[pairsIndexList[i],:,:]/numpy.sqrt(dataOut.data_spc[pair[0],:,:]*dataOut.data_spc[pair[1],:,:]) | |
170 | coherence = numpy.abs(coherenceComplex) |
|
170 | coherence = numpy.abs(coherenceComplex) | |
171 | # phase = numpy.arctan(-1*coherenceComplex.imag/coherenceComplex.real)*180/numpy.pi |
|
171 | # phase = numpy.arctan(-1*coherenceComplex.imag/coherenceComplex.real)*180/numpy.pi | |
172 | phase = numpy.arctan2(coherenceComplex.imag, coherenceComplex.real)*180/numpy.pi |
|
172 | phase = numpy.arctan2(coherenceComplex.imag, coherenceComplex.real)*180/numpy.pi | |
173 |
|
173 | |||
174 | title = "Coherence %d%d" %(pair[0], pair[1]) |
|
174 | title = "Coherence %d%d" %(pair[0], pair[1]) | |
175 | axes0 = self.axesList[i*self.__nsubplots+2] |
|
175 | axes0 = self.axesList[i*self.__nsubplots+2] | |
176 | axes0.pcolor(x, y, coherence, |
|
176 | axes0.pcolor(x, y, coherence, | |
177 | xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=0, zmax=1, |
|
177 | xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=0, zmax=1, | |
178 | xlabel=xlabel, ylabel=ylabel, title=title, |
|
178 | xlabel=xlabel, ylabel=ylabel, title=title, | |
179 | ticksize=9, colormap=coherence_cmap, cblabel='') |
|
179 | ticksize=9, colormap=coherence_cmap, cblabel='') | |
180 |
|
180 | |||
181 | title = "Phase %d%d" %(pair[0], pair[1]) |
|
181 | title = "Phase %d%d" %(pair[0], pair[1]) | |
182 | axes0 = self.axesList[i*self.__nsubplots+3] |
|
182 | axes0 = self.axesList[i*self.__nsubplots+3] | |
183 | axes0.pcolor(x, y, phase, |
|
183 | axes0.pcolor(x, y, phase, | |
184 | xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=-180, zmax=180, |
|
184 | xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=-180, zmax=180, | |
185 | xlabel=xlabel, ylabel=ylabel, title=title, |
|
185 | xlabel=xlabel, ylabel=ylabel, title=title, | |
186 | ticksize=9, colormap=phase_cmap, cblabel='') |
|
186 | ticksize=9, colormap=phase_cmap, cblabel='') | |
187 |
|
187 | |||
188 |
|
188 | |||
189 |
|
189 | |||
190 | self.draw() |
|
190 | self.draw() | |
191 |
|
191 | |||
192 | if save: |
|
192 | if save: | |
193 |
|
193 | |||
194 | self.counter_imagwr += 1 |
|
194 | self.counter_imagwr += 1 | |
195 | if (self.counter_imagwr==wr_period): |
|
195 | if (self.counter_imagwr==wr_period): | |
196 | if figfile == None: |
|
196 | if figfile == None: | |
197 | str_datetime = thisDatetime.strftime("%Y%m%d_%H%M%S") |
|
197 | str_datetime = thisDatetime.strftime("%Y%m%d_%H%M%S") | |
198 | figfile = self.getFilename(name = str_datetime) |
|
198 | figfile = self.getFilename(name = str_datetime) | |
199 |
|
199 | |||
200 | self.saveFigure(figpath, figfile) |
|
200 | self.saveFigure(figpath, figfile) | |
201 |
|
201 | |||
202 | if ftp: |
|
202 | if ftp: | |
203 | #provisionalmente envia archivos en el formato de la web en tiempo real |
|
203 | #provisionalmente envia archivos en el formato de la web en tiempo real | |
204 | name = self.getNameToFtp(thisDatetime, self.FTP_WEI, self.EXP_CODE, self.SUB_EXP_CODE, self.PLOT_CODE, self.PLOT_POS) |
|
204 | name = self.getNameToFtp(thisDatetime, self.FTP_WEI, self.EXP_CODE, self.SUB_EXP_CODE, self.PLOT_CODE, self.PLOT_POS) | |
205 | path = '%s%03d' %(self.PREFIX, self.id) |
|
205 | path = '%s%03d' %(self.PREFIX, self.id) | |
206 | ftp_file = os.path.join(path,'ftp','%s.png'%name) |
|
206 | ftp_file = os.path.join(path,'ftp','%s.png'%name) | |
207 | self.saveFigure(figpath, ftp_file) |
|
207 | self.saveFigure(figpath, ftp_file) | |
208 | ftp_filename = os.path.join(figpath,ftp_file) |
|
208 | ftp_filename = os.path.join(figpath,ftp_file) | |
209 |
|
209 | |||
210 | self.sendByFTP_Thread(ftp_filename, server, folder, username, password) |
|
210 | self.sendByFTP_Thread(ftp_filename, server, folder, username, password) | |
211 | self.counter_imagwr = 0 |
|
211 | self.counter_imagwr = 0 | |
212 |
|
212 | |||
213 | self.counter_imagwr = 0 |
|
213 | self.counter_imagwr = 0 | |
214 |
|
214 | |||
215 | class SNRPlot(Figure): |
|
215 | class SNRPlot(Figure): | |
216 |
|
216 | |||
217 | __isConfig = None |
|
217 | __isConfig = None | |
218 | __nsubplots = None |
|
218 | __nsubplots = None | |
219 |
|
219 | |||
220 | WIDTHPROF = None |
|
220 | WIDTHPROF = None | |
221 | HEIGHTPROF = None |
|
221 | HEIGHTPROF = None | |
222 | PREFIX = 'snr' |
|
222 | PREFIX = 'snr' | |
223 |
|
223 | |||
224 | def __init__(self): |
|
224 | def __init__(self): | |
225 |
|
225 | |||
226 | self.timerange = 2*60*60 |
|
226 | self.timerange = 2*60*60 | |
227 | self.__isConfig = False |
|
227 | self.__isConfig = False | |
228 | self.__nsubplots = 1 |
|
228 | self.__nsubplots = 1 | |
229 |
|
229 | |||
230 | self.WIDTH = 800 |
|
230 | self.WIDTH = 800 | |
231 | self.HEIGHT = 150 |
|
231 | self.HEIGHT = 150 | |
232 | self.WIDTHPROF = 120 |
|
232 | self.WIDTHPROF = 120 | |
233 | self.HEIGHTPROF = 0 |
|
233 | self.HEIGHTPROF = 0 | |
234 | self.counter_imagwr = 0 |
|
234 | self.counter_imagwr = 0 | |
235 |
|
235 | |||
236 | self.PLOT_CODE = 0 |
|
236 | self.PLOT_CODE = 0 | |
237 | self.FTP_WEI = None |
|
237 | self.FTP_WEI = None | |
238 | self.EXP_CODE = None |
|
238 | self.EXP_CODE = None | |
239 | self.SUB_EXP_CODE = None |
|
239 | self.SUB_EXP_CODE = None | |
240 | self.PLOT_POS = None |
|
240 | self.PLOT_POS = None | |
241 |
|
241 | |||
242 | def getSubplots(self): |
|
242 | def getSubplots(self): | |
243 |
|
243 | |||
244 | ncol = 1 |
|
244 | ncol = 1 | |
245 | nrow = self.nplots |
|
245 | nrow = self.nplots | |
246 |
|
246 | |||
247 | return nrow, ncol |
|
247 | return nrow, ncol | |
248 |
|
248 | |||
249 | def setup(self, id, nplots, wintitle, showprofile=True, show=True): |
|
249 | def setup(self, id, nplots, wintitle, showprofile=True, show=True): | |
250 |
|
250 | |||
251 | self.__showprofile = showprofile |
|
251 | self.__showprofile = showprofile | |
252 | self.nplots = nplots |
|
252 | self.nplots = nplots | |
253 |
|
253 | |||
254 | ncolspan = 1 |
|
254 | ncolspan = 1 | |
255 | colspan = 1 |
|
255 | colspan = 1 | |
256 | if showprofile: |
|
256 | if showprofile: | |
257 | ncolspan = 7 |
|
257 | ncolspan = 7 | |
258 | colspan = 6 |
|
258 | colspan = 6 | |
259 | self.__nsubplots = 2 |
|
259 | self.__nsubplots = 2 | |
260 |
|
260 | |||
261 | self.createFigure(id = id, |
|
261 | self.createFigure(id = id, | |
262 | wintitle = wintitle, |
|
262 | wintitle = wintitle, | |
263 | widthplot = self.WIDTH + self.WIDTHPROF, |
|
263 | widthplot = self.WIDTH + self.WIDTHPROF, | |
264 | heightplot = self.HEIGHT + self.HEIGHTPROF, |
|
264 | heightplot = self.HEIGHT + self.HEIGHTPROF, | |
265 | show=show) |
|
265 | show=show) | |
266 |
|
266 | |||
267 | nrow, ncol = self.getSubplots() |
|
267 | nrow, ncol = self.getSubplots() | |
268 |
|
268 | |||
269 | counter = 0 |
|
269 | counter = 0 | |
270 | for y in range(nrow): |
|
270 | for y in range(nrow): | |
271 | for x in range(ncol): |
|
271 | for x in range(ncol): | |
272 |
|
272 | |||
273 | if counter >= self.nplots: |
|
273 | if counter >= self.nplots: | |
274 | break |
|
274 | break | |
275 |
|
275 | |||
276 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1) |
|
276 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1) | |
277 |
|
277 | |||
278 | if showprofile: |
|
278 | if showprofile: | |
279 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1) |
|
279 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1) | |
280 |
|
280 | |||
281 | counter += 1 |
|
281 | counter += 1 | |
282 |
|
282 | |||
283 | def run(self, dataOut, id, wintitle="", channelList=None, showprofile=False, |
|
283 | def run(self, dataOut, id, wintitle="", channelList=None, showprofile=False, | |
284 | xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None, |
|
284 | xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None, | |
285 | timerange=None, |
|
285 | timerange=None, | |
286 | save=False, figpath='./', lastone=0,figfile=None, ftp=False, wr_period=1, show=True, |
|
286 | save=False, figpath='./', lastone=0,figfile=None, ftp=False, wr_period=1, show=True, | |
287 | server=None, folder=None, username=None, password=None, |
|
287 | server=None, folder=None, username=None, password=None, | |
288 | ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0): |
|
288 | ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0): | |
289 |
|
289 | |||
290 | """ |
|
290 | """ | |
291 |
|
291 | |||
292 | Input: |
|
292 | Input: | |
293 | dataOut : |
|
293 | dataOut : | |
294 | id : |
|
294 | id : | |
295 | wintitle : |
|
295 | wintitle : | |
296 | channelList : |
|
296 | channelList : | |
297 | showProfile : |
|
297 | showProfile : | |
298 | xmin : None, |
|
298 | xmin : None, | |
299 | xmax : None, |
|
299 | xmax : None, | |
300 | ymin : None, |
|
300 | ymin : None, | |
301 | ymax : None, |
|
301 | ymax : None, | |
302 | zmin : None, |
|
302 | zmin : None, | |
303 | zmax : None |
|
303 | zmax : None | |
304 | """ |
|
304 | """ | |
305 |
|
305 | |||
306 | if channelList == None: |
|
306 | if channelList == None: | |
307 | channelIndexList = dataOut.channelIndexList |
|
307 | channelIndexList = dataOut.channelIndexList | |
308 | else: |
|
308 | else: | |
309 | channelIndexList = [] |
|
309 | channelIndexList = [] | |
310 | for channel in channelList: |
|
310 | for channel in channelList: | |
311 | if channel not in dataOut.channelList: |
|
311 | if channel not in dataOut.channelList: | |
312 | raise ValueError, "Channel %d is not in dataOut.channelList" |
|
312 | raise ValueError, "Channel %d is not in dataOut.channelList" | |
313 | channelIndexList.append(dataOut.channelList.index(channel)) |
|
313 | channelIndexList.append(dataOut.channelList.index(channel)) | |
314 |
|
314 | |||
315 | if timerange != None: |
|
315 | if timerange != None: | |
316 | self.timerange = timerange |
|
316 | self.timerange = timerange | |
317 |
|
317 | |||
318 | tmin = None |
|
318 | tmin = None | |
319 | tmax = None |
|
319 | tmax = None | |
320 | factor = dataOut.normFactor |
|
320 | factor = dataOut.normFactor | |
321 | x = dataOut.getTimeRange() |
|
321 | x = dataOut.getTimeRange() | |
322 | y = dataOut.getHeiRange() |
|
322 | y = dataOut.getHeiRange() | |
323 |
|
323 | |||
324 | z = dataOut.data_spc[channelIndexList,:,:]/factor |
|
324 | z = dataOut.data_spc[channelIndexList,:,:]/factor | |
325 | z = numpy.where(numpy.isfinite(z), z, numpy.NAN) |
|
325 | z = numpy.where(numpy.isfinite(z), z, numpy.NAN) | |
326 | avg = numpy.average(z, axis=1) |
|
326 | avg = numpy.average(z, axis=1) | |
327 |
|
327 | |||
328 | avgdB = 10.*numpy.log10(avg) |
|
328 | avgdB = 10.*numpy.log10(avg) | |
329 |
|
329 | |||
330 | noise = dataOut.getNoise()/factor |
|
330 | noise = dataOut.getNoise()/factor | |
331 | noisedB = 10.*numpy.log10(noise) |
|
331 | noisedB = 10.*numpy.log10(noise) | |
332 |
|
332 | |||
333 | SNR = numpy.transpose(numpy.divide(avg.T,noise)) |
|
333 | SNR = numpy.transpose(numpy.divide(avg.T,noise)) | |
334 |
|
334 | |||
335 | SNR_dB = 10.*numpy.log10(SNR) |
|
335 | SNR_dB = 10.*numpy.log10(SNR) | |
336 |
|
336 | |||
337 | #SNR_dB = numpy.transpose(numpy.subtract(avgdB.T, noisedB)) |
|
337 | #SNR_dB = numpy.transpose(numpy.subtract(avgdB.T, noisedB)) | |
338 |
|
338 | |||
339 | # thisDatetime = dataOut.datatime |
|
339 | # thisDatetime = dataOut.datatime | |
340 | thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[1]) |
|
340 | thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[1]) | |
341 | title = wintitle + " RTI" #: %s" %(thisDatetime.strftime("%d-%b-%Y")) |
|
341 | title = wintitle + " RTI" #: %s" %(thisDatetime.strftime("%d-%b-%Y")) | |
342 | xlabel = "" |
|
342 | xlabel = "" | |
343 | ylabel = "Range (Km)" |
|
343 | ylabel = "Range (Km)" | |
344 |
|
344 | |||
345 | if not self.__isConfig: |
|
345 | if not self.__isConfig: | |
346 |
|
346 | |||
347 | nplots = len(channelIndexList) |
|
347 | nplots = len(channelIndexList) | |
348 |
|
348 | |||
349 | self.setup(id=id, |
|
349 | self.setup(id=id, | |
350 | nplots=nplots, |
|
350 | nplots=nplots, | |
351 | wintitle=wintitle, |
|
351 | wintitle=wintitle, | |
352 | showprofile=showprofile, |
|
352 | showprofile=showprofile, | |
353 | show=show) |
|
353 | show=show) | |
354 |
|
354 | |||
355 | tmin, tmax = self.getTimeLim(x, xmin, xmax) |
|
355 | tmin, tmax = self.getTimeLim(x, xmin, xmax) | |
356 | if ymin == None: ymin = numpy.nanmin(y) |
|
356 | if ymin == None: ymin = numpy.nanmin(y) | |
357 | if ymax == None: ymax = numpy.nanmax(y) |
|
357 | if ymax == None: ymax = numpy.nanmax(y) | |
358 | if zmin == None: zmin = numpy.nanmin(avgdB)*0.9 |
|
358 | if zmin == None: zmin = numpy.nanmin(avgdB)*0.9 | |
359 | if zmax == None: zmax = numpy.nanmax(avgdB)*0.9 |
|
359 | if zmax == None: zmax = numpy.nanmax(avgdB)*0.9 | |
360 |
|
360 | |||
361 | self.FTP_WEI = ftp_wei |
|
361 | self.FTP_WEI = ftp_wei | |
362 | self.EXP_CODE = exp_code |
|
362 | self.EXP_CODE = exp_code | |
363 | self.SUB_EXP_CODE = sub_exp_code |
|
363 | self.SUB_EXP_CODE = sub_exp_code | |
364 | self.PLOT_POS = plot_pos |
|
364 | self.PLOT_POS = plot_pos | |
365 |
|
365 | |||
366 | self.name = thisDatetime.strftime("%Y%m%d_%H%M%S") |
|
366 | self.name = thisDatetime.strftime("%Y%m%d_%H%M%S") | |
367 | self.__isConfig = True |
|
367 | self.__isConfig = True | |
368 |
|
368 | |||
369 |
|
369 | |||
370 | self.setWinTitle(title) |
|
370 | self.setWinTitle(title) | |
371 |
|
371 | |||
372 | for i in range(self.nplots): |
|
372 | for i in range(self.nplots): | |
373 | title = "Channel %d: %s" %(dataOut.channelList[i]+1, thisDatetime.strftime("%Y/%m/%d %H:%M:%S")) |
|
373 | title = "Channel %d: %s" %(dataOut.channelList[i]+1, thisDatetime.strftime("%Y/%m/%d %H:%M:%S")) | |
374 | axes = self.axesList[i*self.__nsubplots] |
|
374 | axes = self.axesList[i*self.__nsubplots] | |
375 | zdB = SNR_dB[i].reshape((1,-1)) |
|
375 | zdB = SNR_dB[i].reshape((1,-1)) | |
376 | axes.pcolorbuffer(x, y, zdB, |
|
376 | axes.pcolorbuffer(x, y, zdB, | |
377 | xmin=tmin, xmax=tmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax, |
|
377 | xmin=tmin, xmax=tmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax, | |
378 | xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True, |
|
378 | xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True, | |
379 | ticksize=9, cblabel='', cbsize="1%") |
|
379 | ticksize=9, cblabel='', cbsize="1%") | |
380 |
|
380 | |||
381 | # if self.__showprofile: |
|
381 | # if self.__showprofile: | |
382 | # axes = self.axesList[i*self.__nsubplots +1] |
|
382 | # axes = self.axesList[i*self.__nsubplots +1] | |
383 | # axes.pline(avgdB[i], y, |
|
383 | # axes.pline(avgdB[i], y, | |
384 | # xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax, |
|
384 | # xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax, | |
385 | # xlabel='dB', ylabel='', title='', |
|
385 | # xlabel='dB', ylabel='', title='', | |
386 | # ytick_visible=False, |
|
386 | # ytick_visible=False, | |
387 | # grid='x') |
|
387 | # grid='x') | |
388 | # |
|
388 | # | |
389 | self.draw() |
|
389 | self.draw() | |
390 |
|
390 | |||
391 | if lastone: |
|
391 | if lastone: | |
392 | if dataOut.blocknow >= dataOut.last_block: |
|
392 | if dataOut.blocknow >= dataOut.last_block: | |
393 | if figfile == None: |
|
393 | if figfile == None: | |
394 | figfile = self.getFilename(name = self.name) |
|
394 | figfile = self.getFilename(name = self.name) | |
395 | self.saveFigure(figpath, figfile) |
|
395 | self.saveFigure(figpath, figfile) | |
396 |
|
396 | |||
397 | if (save and not(lastone)): |
|
397 | if (save and not(lastone)): | |
398 |
|
398 | |||
399 | self.counter_imagwr += 1 |
|
399 | self.counter_imagwr += 1 | |
400 | if (self.counter_imagwr==wr_period): |
|
400 | if (self.counter_imagwr==wr_period): | |
401 | if figfile == None: |
|
401 | if figfile == None: | |
402 | figfile = self.getFilename(name = self.name) |
|
402 | figfile = self.getFilename(name = self.name) | |
403 | self.saveFigure(figpath, figfile) |
|
403 | self.saveFigure(figpath, figfile) | |
404 |
|
404 | |||
405 | if ftp: |
|
405 | if ftp: | |
406 | #provisionalmente envia archivos en el formato de la web en tiempo real |
|
406 | #provisionalmente envia archivos en el formato de la web en tiempo real | |
407 | name = self.getNameToFtp(thisDatetime, self.FTP_WEI, self.EXP_CODE, self.SUB_EXP_CODE, self.PLOT_CODE, self.PLOT_POS) |
|
407 | name = self.getNameToFtp(thisDatetime, self.FTP_WEI, self.EXP_CODE, self.SUB_EXP_CODE, self.PLOT_CODE, self.PLOT_POS) | |
408 | path = '%s%03d' %(self.PREFIX, self.id) |
|
408 | path = '%s%03d' %(self.PREFIX, self.id) | |
409 | ftp_file = os.path.join(path,'ftp','%s.png'%name) |
|
409 | ftp_file = os.path.join(path,'ftp','%s.png'%name) | |
410 | self.saveFigure(figpath, ftp_file) |
|
410 | self.saveFigure(figpath, ftp_file) | |
411 | ftp_filename = os.path.join(figpath,ftp_file) |
|
411 | ftp_filename = os.path.join(figpath,ftp_file) | |
412 | self.sendByFTP_Thread(ftp_filename, server, folder, username, password) |
|
412 | self.sendByFTP_Thread(ftp_filename, server, folder, username, password) | |
413 | self.counter_imagwr = 0 |
|
413 | self.counter_imagwr = 0 | |
414 |
|
414 | |||
415 | self.counter_imagwr = 0 |
|
415 | self.counter_imagwr = 0 | |
416 |
|
416 | |||
417 | if x[1] + (x[1]-x[0]) >= self.axesList[0].xmax: |
|
417 | if x[1] + (x[1]-x[0]) >= self.axesList[0].xmax: | |
418 |
|
418 | |||
419 | self.__isConfig = False |
|
419 | self.__isConfig = False | |
420 |
|
420 | |||
421 | if lastone: |
|
421 | if lastone: | |
422 | if figfile == None: |
|
422 | if figfile == None: | |
423 | figfile = self.getFilename(name = self.name) |
|
423 | figfile = self.getFilename(name = self.name) | |
424 | self.saveFigure(figpath, figfile) |
|
424 | self.saveFigure(figpath, figfile) | |
425 |
|
425 | |||
426 | if ftp: |
|
426 | if ftp: | |
427 | #provisionalmente envia archivos en el formato de la web en tiempo real |
|
427 | #provisionalmente envia archivos en el formato de la web en tiempo real | |
428 | name = self.getNameToFtp(thisDatetime, self.FTP_WEI, self.EXP_CODE, self.SUB_EXP_CODE, self.PLOT_CODE, self.PLOT_POS) |
|
428 | name = self.getNameToFtp(thisDatetime, self.FTP_WEI, self.EXP_CODE, self.SUB_EXP_CODE, self.PLOT_CODE, self.PLOT_POS) | |
429 | path = '%s%03d' %(self.PREFIX, self.id) |
|
429 | path = '%s%03d' %(self.PREFIX, self.id) | |
430 | ftp_file = os.path.join(path,'ftp','%s.png'%name) |
|
430 | ftp_file = os.path.join(path,'ftp','%s.png'%name) | |
431 | self.saveFigure(figpath, ftp_file) |
|
431 | self.saveFigure(figpath, ftp_file) | |
432 | ftp_filename = os.path.join(figpath,ftp_file) |
|
432 | ftp_filename = os.path.join(figpath,ftp_file) | |
433 | self.sendByFTP_Thread(ftp_filename, server, folder, username, password) |
|
433 | self.sendByFTP_Thread(ftp_filename, server, folder, username, password) | |
434 |
|
434 | |||
435 |
|
435 | |||
436 | class RTIPlot(Figure): |
|
436 | class RTIPlot(Figure): | |
437 |
|
437 | |||
438 | __isConfig = None |
|
438 | __isConfig = None | |
439 | __nsubplots = None |
|
439 | __nsubplots = None | |
440 |
|
440 | |||
441 | WIDTHPROF = None |
|
441 | WIDTHPROF = None | |
442 | HEIGHTPROF = None |
|
442 | HEIGHTPROF = None | |
443 | PREFIX = 'rti' |
|
443 | PREFIX = 'rti' | |
444 |
|
444 | |||
445 | def __init__(self): |
|
445 | def __init__(self): | |
446 |
|
446 | |||
447 | self.timerange = 2*60*60 |
|
447 | self.timerange = 2*60*60 | |
448 | self.__isConfig = False |
|
448 | self.__isConfig = False | |
449 | self.__nsubplots = 1 |
|
449 | self.__nsubplots = 1 | |
450 |
|
450 | |||
451 | self.WIDTH = 800 |
|
451 | self.WIDTH = 800 | |
452 | self.HEIGHT = 150 |
|
452 | self.HEIGHT = 150 | |
453 | self.WIDTHPROF = 120 |
|
453 | self.WIDTHPROF = 120 | |
454 | self.HEIGHTPROF = 0 |
|
454 | self.HEIGHTPROF = 0 | |
455 | self.counter_imagwr = 0 |
|
455 | self.counter_imagwr = 0 | |
456 |
|
456 | |||
457 | self.PLOT_CODE = 0 |
|
457 | self.PLOT_CODE = 0 | |
458 | self.FTP_WEI = None |
|
458 | self.FTP_WEI = None | |
459 | self.EXP_CODE = None |
|
459 | self.EXP_CODE = None | |
460 | self.SUB_EXP_CODE = None |
|
460 | self.SUB_EXP_CODE = None | |
461 | self.PLOT_POS = None |
|
461 | self.PLOT_POS = None | |
|
462 | self.tmin = None | |||
|
463 | self.tmax = None | |||
|
464 | ||||
|
465 | self.xmin = None | |||
|
466 | self.xmax = None | |||
462 |
|
467 | |||
463 | def getSubplots(self): |
|
468 | def getSubplots(self): | |
464 |
|
469 | |||
465 | ncol = 1 |
|
470 | ncol = 1 | |
466 | nrow = self.nplots |
|
471 | nrow = self.nplots | |
467 |
|
472 | |||
468 | return nrow, ncol |
|
473 | return nrow, ncol | |
469 |
|
474 | |||
470 | def setup(self, id, nplots, wintitle, showprofile=True, show=True): |
|
475 | def setup(self, id, nplots, wintitle, showprofile=True, show=True): | |
471 |
|
476 | |||
472 | self.__showprofile = showprofile |
|
477 | self.__showprofile = showprofile | |
473 | self.nplots = nplots |
|
478 | self.nplots = nplots | |
474 |
|
479 | |||
475 | ncolspan = 1 |
|
480 | ncolspan = 1 | |
476 | colspan = 1 |
|
481 | colspan = 1 | |
477 | if showprofile: |
|
482 | if showprofile: | |
478 | ncolspan = 7 |
|
483 | ncolspan = 7 | |
479 | colspan = 6 |
|
484 | colspan = 6 | |
480 | self.__nsubplots = 2 |
|
485 | self.__nsubplots = 2 | |
481 |
|
486 | |||
482 | self.createFigure(id = id, |
|
487 | self.createFigure(id = id, | |
483 | wintitle = wintitle, |
|
488 | wintitle = wintitle, | |
484 | widthplot = self.WIDTH + self.WIDTHPROF, |
|
489 | widthplot = self.WIDTH + self.WIDTHPROF, | |
485 | heightplot = self.HEIGHT + self.HEIGHTPROF, |
|
490 | heightplot = self.HEIGHT + self.HEIGHTPROF, | |
486 | show=show) |
|
491 | show=show) | |
487 |
|
492 | |||
488 | nrow, ncol = self.getSubplots() |
|
493 | nrow, ncol = self.getSubplots() | |
489 |
|
494 | |||
490 | counter = 0 |
|
495 | counter = 0 | |
491 | for y in range(nrow): |
|
496 | for y in range(nrow): | |
492 | for x in range(ncol): |
|
497 | for x in range(ncol): | |
493 |
|
498 | |||
494 | if counter >= self.nplots: |
|
499 | if counter >= self.nplots: | |
495 | break |
|
500 | break | |
496 |
|
501 | |||
497 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1) |
|
502 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1) | |
498 |
|
503 | |||
499 | if showprofile: |
|
504 | if showprofile: | |
500 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1) |
|
505 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1) | |
501 |
|
506 | |||
502 | counter += 1 |
|
507 | counter += 1 | |
503 |
|
508 | |||
504 | def run(self, dataOut, id, wintitle="", channelList=None, showprofile='True', |
|
509 | def run(self, dataOut, id, wintitle="", channelList=None, showprofile='True', | |
505 | xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None, |
|
510 | xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None, | |
506 | timerange=None, |
|
511 | timerange=None, | |
507 | save=False, figpath='./', lastone=0,figfile=None, ftp=False, wr_period=1, show=True, |
|
512 | save=False, figpath='./', lastone=0,figfile=None, ftp=False, wr_period=1, show=True, | |
508 | server=None, folder=None, username=None, password=None, |
|
513 | server=None, folder=None, username=None, password=None, | |
509 | ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0): |
|
514 | ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0): | |
510 |
|
515 | |||
511 | """ |
|
516 | """ | |
512 |
|
517 | |||
513 | Input: |
|
518 | Input: | |
514 | dataOut : |
|
519 | dataOut : | |
515 | id : |
|
520 | id : | |
516 | wintitle : |
|
521 | wintitle : | |
517 | channelList : |
|
522 | channelList : | |
518 | showProfile : |
|
523 | showProfile : | |
519 | xmin : None, |
|
524 | xmin : None, | |
520 | xmax : None, |
|
525 | xmax : None, | |
521 | ymin : None, |
|
526 | ymin : None, | |
522 | ymax : None, |
|
527 | ymax : None, | |
523 | zmin : None, |
|
528 | zmin : None, | |
524 | zmax : None |
|
529 | zmax : None | |
525 | """ |
|
530 | """ | |
526 |
|
531 | |||
527 | if channelList == None: |
|
532 | if channelList == None: | |
528 | channelIndexList = dataOut.channelIndexList |
|
533 | channelIndexList = dataOut.channelIndexList | |
529 | else: |
|
534 | else: | |
530 | channelIndexList = [] |
|
535 | channelIndexList = [] | |
531 | for channel in channelList: |
|
536 | for channel in channelList: | |
532 | if channel not in dataOut.channelList: |
|
537 | if channel not in dataOut.channelList: | |
533 | raise ValueError, "Channel %d is not in dataOut.channelList" |
|
538 | raise ValueError, "Channel %d is not in dataOut.channelList" | |
534 | channelIndexList.append(dataOut.channelList.index(channel)) |
|
539 | channelIndexList.append(dataOut.channelList.index(channel)) | |
535 |
|
540 | |||
536 | if timerange != None: |
|
541 | if timerange != None: | |
537 | self.timerange = timerange |
|
542 | self.timerange = timerange | |
538 |
|
543 | |||
539 | tmin = None |
|
544 | #tmin = None | |
540 | tmax = None |
|
545 | #tmax = None | |
541 | factor = dataOut.normFactor |
|
546 | factor = dataOut.normFactor | |
542 | x = dataOut.getTimeRange() |
|
547 | x = dataOut.getTimeRange() | |
543 | y = dataOut.getHeiRange() |
|
548 | y = dataOut.getHeiRange() | |
544 |
|
549 | |||
545 | z = dataOut.data_spc[channelIndexList,:,:]/factor |
|
550 | z = dataOut.data_spc[channelIndexList,:,:]/factor | |
546 | z = numpy.where(numpy.isfinite(z), z, numpy.NAN) |
|
551 | z = numpy.where(numpy.isfinite(z), z, numpy.NAN) | |
547 | avg = numpy.average(z, axis=1) |
|
552 | avg = numpy.average(z, axis=1) | |
548 |
|
553 | |||
549 | avgdB = 10.*numpy.log10(avg) |
|
554 | avgdB = 10.*numpy.log10(avg) | |
550 |
|
555 | |||
551 |
|
556 | |||
552 | # thisDatetime = dataOut.datatime |
|
557 | # thisDatetime = dataOut.datatime | |
553 | thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[1]) |
|
558 | thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[1]) | |
554 | title = wintitle + " RTI" #: %s" %(thisDatetime.strftime("%d-%b-%Y")) |
|
559 | title = wintitle + " RTI" #: %s" %(thisDatetime.strftime("%d-%b-%Y")) | |
555 | xlabel = "" |
|
560 | xlabel = "" | |
556 | ylabel = "Range (Km)" |
|
561 | ylabel = "Range (Km)" | |
557 |
|
562 | |||
558 | if not self.__isConfig: |
|
563 | if not self.__isConfig: | |
559 |
|
564 | |||
560 | nplots = len(channelIndexList) |
|
565 | nplots = len(channelIndexList) | |
561 |
|
566 | |||
562 | self.setup(id=id, |
|
567 | self.setup(id=id, | |
563 | nplots=nplots, |
|
568 | nplots=nplots, | |
564 | wintitle=wintitle, |
|
569 | wintitle=wintitle, | |
565 | showprofile=showprofile, |
|
570 | showprofile=showprofile, | |
566 | show=show) |
|
571 | show=show) | |
567 |
|
572 | |||
568 |
|
|
573 | self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange) | |
|
574 | ||||
|
575 | # if timerange != None: | |||
|
576 | # self.timerange = timerange | |||
|
577 | # self.xmin, self.tmax = self.getTimeLim(x, xmin, xmax, timerange) | |||
|
578 | ||||
|
579 | ||||
|
580 | ||||
569 | if ymin == None: ymin = numpy.nanmin(y) |
|
581 | if ymin == None: ymin = numpy.nanmin(y) | |
570 | if ymax == None: ymax = numpy.nanmax(y) |
|
582 | if ymax == None: ymax = numpy.nanmax(y) | |
571 | if zmin == None: zmin = numpy.nanmin(avgdB)*0.9 |
|
583 | if zmin == None: zmin = numpy.nanmin(avgdB)*0.9 | |
572 | if zmax == None: zmax = numpy.nanmax(avgdB)*0.9 |
|
584 | if zmax == None: zmax = numpy.nanmax(avgdB)*0.9 | |
573 |
|
585 | |||
574 | self.FTP_WEI = ftp_wei |
|
586 | self.FTP_WEI = ftp_wei | |
575 | self.EXP_CODE = exp_code |
|
587 | self.EXP_CODE = exp_code | |
576 | self.SUB_EXP_CODE = sub_exp_code |
|
588 | self.SUB_EXP_CODE = sub_exp_code | |
577 | self.PLOT_POS = plot_pos |
|
589 | self.PLOT_POS = plot_pos | |
578 |
|
590 | |||
579 | self.name = thisDatetime.strftime("%Y%m%d_%H%M%S") |
|
591 | self.name = thisDatetime.strftime("%Y%m%d_%H%M%S") | |
580 | self.__isConfig = True |
|
592 | self.__isConfig = True | |
581 |
|
593 | |||
582 |
|
594 | |||
583 | self.setWinTitle(title) |
|
595 | self.setWinTitle(title) | |
584 |
|
|
596 | ||
|
597 | if ((self.xmax - x[1]) < (x[1]-x[0])): | |||
|
598 | x[1] = self.xmax | |||
|
599 | ||||
585 | for i in range(self.nplots): |
|
600 | for i in range(self.nplots): | |
586 | title = "Channel %d: %s" %(dataOut.channelList[i]+1, thisDatetime.strftime("%Y/%m/%d %H:%M:%S")) |
|
601 | title = "Channel %d: %s" %(dataOut.channelList[i]+1, thisDatetime.strftime("%Y/%m/%d %H:%M:%S")) | |
587 | axes = self.axesList[i*self.__nsubplots] |
|
602 | axes = self.axesList[i*self.__nsubplots] | |
588 | zdB = avgdB[i].reshape((1,-1)) |
|
603 | zdB = avgdB[i].reshape((1,-1)) | |
589 | axes.pcolorbuffer(x, y, zdB, |
|
604 | axes.pcolorbuffer(x, y, zdB, | |
590 |
xmin= |
|
605 | xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax, | |
591 | xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True, |
|
606 | xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True, | |
592 | ticksize=9, cblabel='', cbsize="1%") |
|
607 | ticksize=9, cblabel='', cbsize="1%") | |
593 |
|
608 | |||
594 | if self.__showprofile: |
|
609 | if self.__showprofile: | |
595 | axes = self.axesList[i*self.__nsubplots +1] |
|
610 | axes = self.axesList[i*self.__nsubplots +1] | |
596 | axes.pline(avgdB[i], y, |
|
611 | axes.pline(avgdB[i], y, | |
597 | xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax, |
|
612 | xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax, | |
598 | xlabel='dB', ylabel='', title='', |
|
613 | xlabel='dB', ylabel='', title='', | |
599 | ytick_visible=False, |
|
614 | ytick_visible=False, | |
600 | grid='x') |
|
615 | grid='x') | |
601 |
|
616 | |||
602 | self.draw() |
|
617 | self.draw() | |
603 |
|
618 | |||
604 | if lastone: |
|
619 | # if lastone: | |
605 | if dataOut.blocknow >= dataOut.last_block: |
|
620 | # if dataOut.blocknow >= dataOut.last_block: | |
606 | if figfile == None: |
|
621 | # if figfile == None: | |
607 | figfile = self.getFilename(name = self.name) |
|
622 | # figfile = self.getFilename(name = self.name) | |
608 | self.saveFigure(figpath, figfile) |
|
623 | # self.saveFigure(figpath, figfile) | |
609 |
|
624 | # | ||
610 | if (save and not(lastone)): |
|
625 | # if (save and not(lastone)): | |
|
626 | # | |||
|
627 | # self.counter_imagwr += 1 | |||
|
628 | # if (self.counter_imagwr==wr_period): | |||
|
629 | # if figfile == None: | |||
|
630 | # figfile = self.getFilename(name = self.name) | |||
|
631 | # self.saveFigure(figpath, figfile) | |||
|
632 | # | |||
|
633 | # if ftp: | |||
|
634 | # #provisionalmente envia archivos en el formato de la web en tiempo real | |||
|
635 | # name = self.getNameToFtp(thisDatetime, self.FTP_WEI, self.EXP_CODE, self.SUB_EXP_CODE, self.PLOT_CODE, self.PLOT_POS) | |||
|
636 | # path = '%s%03d' %(self.PREFIX, self.id) | |||
|
637 | # ftp_file = os.path.join(path,'ftp','%s.png'%name) | |||
|
638 | # self.saveFigure(figpath, ftp_file) | |||
|
639 | # ftp_filename = os.path.join(figpath,ftp_file) | |||
|
640 | # self.sendByFTP_Thread(ftp_filename, server, folder, username, password) | |||
|
641 | # self.counter_imagwr = 0 | |||
|
642 | # | |||
|
643 | # self.counter_imagwr = 0 | |||
611 |
|
644 | |||
612 | self.counter_imagwr += 1 |
|
645 | #if ((dataOut.utctime-time.timezone) >= self.axesList[0].xmax): | |
613 | if (self.counter_imagwr==wr_period): |
|
646 | if x[1] >= self.axesList[0].xmax: | |
614 | if figfile == None: |
|
|||
615 | figfile = self.getFilename(name = self.name) |
|
|||
616 |
|
|
647 | self.saveFigure(figpath, figfile) | |
617 |
|
||||
618 | if ftp: |
|
|||
619 | #provisionalmente envia archivos en el formato de la web en tiempo real |
|
|||
620 | name = self.getNameToFtp(thisDatetime, self.FTP_WEI, self.EXP_CODE, self.SUB_EXP_CODE, self.PLOT_CODE, self.PLOT_POS) |
|
|||
621 | path = '%s%03d' %(self.PREFIX, self.id) |
|
|||
622 | ftp_file = os.path.join(path,'ftp','%s.png'%name) |
|
|||
623 | self.saveFigure(figpath, ftp_file) |
|
|||
624 | ftp_filename = os.path.join(figpath,ftp_file) |
|
|||
625 | self.sendByFTP_Thread(ftp_filename, server, folder, username, password) |
|
|||
626 | self.counter_imagwr = 0 |
|
|||
627 |
|
||||
628 | self.counter_imagwr = 0 |
|
|||
629 |
|
||||
630 | if x[1] + (x[1]-x[0]) >= self.axesList[0].xmax: |
|
|||
631 |
|
||||
632 | self.__isConfig = False |
|
648 | self.__isConfig = False | |
633 |
|
649 | |||
634 | if lastone: |
|
650 | # if x[1] + (x[1]-x[0]) >= self.axesList[0].xmax: | |
635 | if figfile == None: |
|
651 | # | |
636 | figfile = self.getFilename(name = self.name) |
|
652 | # self.__isConfig = False | |
637 | self.saveFigure(figpath, figfile) |
|
|||
638 |
|
|
653 | ||
639 |
|
|
654 | # if lastone: | |
640 | #provisionalmente envia archivos en el formato de la web en tiempo real |
|
655 | # if figfile == None: | |
641 | name = self.getNameToFtp(thisDatetime, self.FTP_WEI, self.EXP_CODE, self.SUB_EXP_CODE, self.PLOT_CODE, self.PLOT_POS) |
|
656 | # figfile = self.getFilename(name = self.name) | |
642 | path = '%s%03d' %(self.PREFIX, self.id) |
|
657 | # self.saveFigure(figpath, figfile) | |
643 | ftp_file = os.path.join(path,'ftp','%s.png'%name) |
|
658 | # | |
644 | self.saveFigure(figpath, ftp_file) |
|
659 | # if ftp: | |
645 | ftp_filename = os.path.join(figpath,ftp_file) |
|
660 | # #provisionalmente envia archivos en el formato de la web en tiempo real | |
646 | self.sendByFTP_Thread(ftp_filename, server, folder, username, password) |
|
661 | # name = self.getNameToFtp(thisDatetime, self.FTP_WEI, self.EXP_CODE, self.SUB_EXP_CODE, self.PLOT_CODE, self.PLOT_POS) | |
|
662 | # path = '%s%03d' %(self.PREFIX, self.id) | |||
|
663 | # ftp_file = os.path.join(path,'ftp','%s.png'%name) | |||
|
664 | # self.saveFigure(figpath, ftp_file) | |||
|
665 | # ftp_filename = os.path.join(figpath,ftp_file) | |||
|
666 | # self.sendByFTP_Thread(ftp_filename, server, folder, username, password) | |||
647 |
|
667 | |||
648 |
|
668 | |||
649 | class SpectraPlot(Figure): |
|
669 | class SpectraPlot(Figure): | |
650 |
|
670 | |||
651 | __isConfig = None |
|
671 | __isConfig = None | |
652 | __nsubplots = None |
|
672 | __nsubplots = None | |
653 |
|
673 | |||
654 | WIDTHPROF = None |
|
674 | WIDTHPROF = None | |
655 | HEIGHTPROF = None |
|
675 | HEIGHTPROF = None | |
656 | PREFIX = 'spc' |
|
676 | PREFIX = 'spc' | |
657 |
|
677 | |||
658 | def __init__(self): |
|
678 | def __init__(self): | |
659 |
|
679 | |||
660 | self.__isConfig = False |
|
680 | self.__isConfig = False | |
661 | self.__nsubplots = 1 |
|
681 | self.__nsubplots = 1 | |
662 |
|
682 | |||
663 | self.WIDTH = 280 |
|
683 | self.WIDTH = 280 | |
664 | self.HEIGHT = 250 |
|
684 | self.HEIGHT = 250 | |
665 | self.WIDTHPROF = 120 |
|
685 | self.WIDTHPROF = 120 | |
666 | self.HEIGHTPROF = 0 |
|
686 | self.HEIGHTPROF = 0 | |
667 | self.counter_imagwr = 0 |
|
687 | self.counter_imagwr = 0 | |
668 |
|
688 | |||
669 | self.PLOT_CODE = 1 |
|
689 | self.PLOT_CODE = 1 | |
670 | self.FTP_WEI = None |
|
690 | self.FTP_WEI = None | |
671 | self.EXP_CODE = None |
|
691 | self.EXP_CODE = None | |
672 | self.SUB_EXP_CODE = None |
|
692 | self.SUB_EXP_CODE = None | |
673 | self.PLOT_POS = None |
|
693 | self.PLOT_POS = None | |
674 |
|
694 | |||
675 | def getSubplots(self): |
|
695 | def getSubplots(self): | |
676 |
|
696 | |||
677 | ncol = int(numpy.sqrt(self.nplots)+0.9) |
|
697 | ncol = int(numpy.sqrt(self.nplots)+0.9) | |
678 | nrow = int(self.nplots*1./ncol + 0.9) |
|
698 | nrow = int(self.nplots*1./ncol + 0.9) | |
679 |
|
699 | |||
680 | return nrow, ncol |
|
700 | return nrow, ncol | |
681 |
|
701 | |||
682 | def setup(self, id, nplots, wintitle, showprofile=True, show=True): |
|
702 | def setup(self, id, nplots, wintitle, showprofile=True, show=True): | |
683 |
|
703 | |||
684 | self.__showprofile = showprofile |
|
704 | self.__showprofile = showprofile | |
685 | self.nplots = nplots |
|
705 | self.nplots = nplots | |
686 |
|
706 | |||
687 | ncolspan = 1 |
|
707 | ncolspan = 1 | |
688 | colspan = 1 |
|
708 | colspan = 1 | |
689 | if showprofile: |
|
709 | if showprofile: | |
690 | ncolspan = 3 |
|
710 | ncolspan = 3 | |
691 | colspan = 2 |
|
711 | colspan = 2 | |
692 | self.__nsubplots = 2 |
|
712 | self.__nsubplots = 2 | |
693 |
|
713 | |||
694 | self.createFigure(id = id, |
|
714 | self.createFigure(id = id, | |
695 | wintitle = wintitle, |
|
715 | wintitle = wintitle, | |
696 | widthplot = self.WIDTH + self.WIDTHPROF, |
|
716 | widthplot = self.WIDTH + self.WIDTHPROF, | |
697 | heightplot = self.HEIGHT + self.HEIGHTPROF, |
|
717 | heightplot = self.HEIGHT + self.HEIGHTPROF, | |
698 | show=show) |
|
718 | show=show) | |
699 |
|
719 | |||
700 | nrow, ncol = self.getSubplots() |
|
720 | nrow, ncol = self.getSubplots() | |
701 |
|
721 | |||
702 | counter = 0 |
|
722 | counter = 0 | |
703 | for y in range(nrow): |
|
723 | for y in range(nrow): | |
704 | for x in range(ncol): |
|
724 | for x in range(ncol): | |
705 |
|
725 | |||
706 | if counter >= self.nplots: |
|
726 | if counter >= self.nplots: | |
707 | break |
|
727 | break | |
708 |
|
728 | |||
709 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1) |
|
729 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1) | |
710 |
|
730 | |||
711 | if showprofile: |
|
731 | if showprofile: | |
712 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1) |
|
732 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1) | |
713 |
|
733 | |||
714 | counter += 1 |
|
734 | counter += 1 | |
715 |
|
735 | |||
716 | def run(self, dataOut, id, wintitle="", channelList=None, showprofile=True, |
|
736 | def run(self, dataOut, id, wintitle="", channelList=None, showprofile=True, | |
717 | xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None, |
|
737 | xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None, | |
718 | save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1, |
|
738 | save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1, | |
719 | server=None, folder=None, username=None, password=None, |
|
739 | server=None, folder=None, username=None, password=None, | |
720 | ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0, realtime=False): |
|
740 | ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0, realtime=False): | |
721 |
|
741 | |||
722 | """ |
|
742 | """ | |
723 |
|
743 | |||
724 | Input: |
|
744 | Input: | |
725 | dataOut : |
|
745 | dataOut : | |
726 | id : |
|
746 | id : | |
727 | wintitle : |
|
747 | wintitle : | |
728 | channelList : |
|
748 | channelList : | |
729 | showProfile : |
|
749 | showProfile : | |
730 | xmin : None, |
|
750 | xmin : None, | |
731 | xmax : None, |
|
751 | xmax : None, | |
732 | ymin : None, |
|
752 | ymin : None, | |
733 | ymax : None, |
|
753 | ymax : None, | |
734 | zmin : None, |
|
754 | zmin : None, | |
735 | zmax : None |
|
755 | zmax : None | |
736 | """ |
|
756 | """ | |
737 |
|
757 | |||
738 | if realtime: |
|
758 | if realtime: | |
739 | if not(isRealtime(utcdatatime = dataOut.utctime)): |
|
759 | if not(isRealtime(utcdatatime = dataOut.utctime)): | |
740 | print 'Skipping this plot function' |
|
760 | print 'Skipping this plot function' | |
741 | return |
|
761 | return | |
742 |
|
762 | |||
743 | if channelList == None: |
|
763 | if channelList == None: | |
744 | channelIndexList = dataOut.channelIndexList |
|
764 | channelIndexList = dataOut.channelIndexList | |
745 | else: |
|
765 | else: | |
746 | channelIndexList = [] |
|
766 | channelIndexList = [] | |
747 | for channel in channelList: |
|
767 | for channel in channelList: | |
748 | if channel not in dataOut.channelList: |
|
768 | if channel not in dataOut.channelList: | |
749 | raise ValueError, "Channel %d is not in dataOut.channelList" |
|
769 | raise ValueError, "Channel %d is not in dataOut.channelList" | |
750 | channelIndexList.append(dataOut.channelList.index(channel)) |
|
770 | channelIndexList.append(dataOut.channelList.index(channel)) | |
751 | factor = dataOut.normFactor |
|
771 | factor = dataOut.normFactor | |
752 | x = dataOut.getVelRange(1) |
|
772 | x = dataOut.getVelRange(1) | |
753 | y = dataOut.getHeiRange() |
|
773 | y = dataOut.getHeiRange() | |
754 |
|
774 | |||
755 | z = dataOut.data_spc[channelIndexList,:,:]/factor |
|
775 | z = dataOut.data_spc[channelIndexList,:,:]/factor | |
756 | z = numpy.where(numpy.isfinite(z), z, numpy.NAN) |
|
776 | z = numpy.where(numpy.isfinite(z), z, numpy.NAN) | |
757 | avg = numpy.average(z, axis=1) |
|
777 | avg = numpy.average(z, axis=1) | |
758 | noise = dataOut.getNoise()/factor |
|
778 | noise = dataOut.getNoise()/factor | |
759 |
|
779 | |||
760 | zdB = 10*numpy.log10(z) |
|
780 | zdB = 10*numpy.log10(z) | |
761 | avgdB = 10*numpy.log10(avg) |
|
781 | avgdB = 10*numpy.log10(avg) | |
762 | noisedB = 10*numpy.log10(noise) |
|
782 | noisedB = 10*numpy.log10(noise) | |
763 |
|
783 | |||
764 | #thisDatetime = dataOut.datatime |
|
784 | #thisDatetime = dataOut.datatime | |
765 | thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[1]) |
|
785 | thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[1]) | |
766 | title = wintitle + " Spectra" |
|
786 | title = wintitle + " Spectra" | |
767 | xlabel = "Velocity (m/s)" |
|
787 | xlabel = "Velocity (m/s)" | |
768 | ylabel = "Range (Km)" |
|
788 | ylabel = "Range (Km)" | |
769 |
|
789 | |||
770 | if not self.__isConfig: |
|
790 | if not self.__isConfig: | |
771 |
|
791 | |||
772 | nplots = len(channelIndexList) |
|
792 | nplots = len(channelIndexList) | |
773 |
|
793 | |||
774 | self.setup(id=id, |
|
794 | self.setup(id=id, | |
775 | nplots=nplots, |
|
795 | nplots=nplots, | |
776 | wintitle=wintitle, |
|
796 | wintitle=wintitle, | |
777 | showprofile=showprofile, |
|
797 | showprofile=showprofile, | |
778 | show=show) |
|
798 | show=show) | |
779 |
|
799 | |||
780 | if xmin == None: xmin = numpy.nanmin(x) |
|
800 | if xmin == None: xmin = numpy.nanmin(x) | |
781 | if xmax == None: xmax = numpy.nanmax(x) |
|
801 | if xmax == None: xmax = numpy.nanmax(x) | |
782 | if ymin == None: ymin = numpy.nanmin(y) |
|
802 | if ymin == None: ymin = numpy.nanmin(y) | |
783 | if ymax == None: ymax = numpy.nanmax(y) |
|
803 | if ymax == None: ymax = numpy.nanmax(y) | |
784 | if zmin == None: zmin = numpy.nanmin(avgdB)*0.9 |
|
804 | if zmin == None: zmin = numpy.nanmin(avgdB)*0.9 | |
785 | if zmax == None: zmax = numpy.nanmax(avgdB)*0.9 |
|
805 | if zmax == None: zmax = numpy.nanmax(avgdB)*0.9 | |
786 |
|
806 | |||
787 | self.FTP_WEI = ftp_wei |
|
807 | self.FTP_WEI = ftp_wei | |
788 | self.EXP_CODE = exp_code |
|
808 | self.EXP_CODE = exp_code | |
789 | self.SUB_EXP_CODE = sub_exp_code |
|
809 | self.SUB_EXP_CODE = sub_exp_code | |
790 | self.PLOT_POS = plot_pos |
|
810 | self.PLOT_POS = plot_pos | |
791 |
|
811 | |||
792 | self.__isConfig = True |
|
812 | self.__isConfig = True | |
793 |
|
813 | |||
794 | self.setWinTitle(title) |
|
814 | self.setWinTitle(title) | |
795 |
|
815 | |||
796 | for i in range(self.nplots): |
|
816 | for i in range(self.nplots): | |
797 | str_datetime = '%s %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S")) |
|
817 | str_datetime = '%s %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S")) | |
798 | title = "Channel %d: %4.2fdB: %s" %(dataOut.channelList[i]+1, noisedB[i], str_datetime) |
|
818 | title = "Channel %d: %4.2fdB: %s" %(dataOut.channelList[i]+1, noisedB[i], str_datetime) | |
799 | axes = self.axesList[i*self.__nsubplots] |
|
819 | axes = self.axesList[i*self.__nsubplots] | |
800 | axes.pcolor(x, y, zdB[i,:,:], |
|
820 | axes.pcolor(x, y, zdB[i,:,:], | |
801 | xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax, |
|
821 | xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax, | |
802 | xlabel=xlabel, ylabel=ylabel, title=title, |
|
822 | xlabel=xlabel, ylabel=ylabel, title=title, | |
803 | ticksize=9, cblabel='') |
|
823 | ticksize=9, cblabel='') | |
804 |
|
824 | |||
805 | if self.__showprofile: |
|
825 | if self.__showprofile: | |
806 | axes = self.axesList[i*self.__nsubplots +1] |
|
826 | axes = self.axesList[i*self.__nsubplots +1] | |
807 | axes.pline(avgdB[i], y, |
|
827 | axes.pline(avgdB[i], y, | |
808 | xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax, |
|
828 | xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax, | |
809 | xlabel='dB', ylabel='', title='', |
|
829 | xlabel='dB', ylabel='', title='', | |
810 | ytick_visible=False, |
|
830 | ytick_visible=False, | |
811 | grid='x') |
|
831 | grid='x') | |
812 |
|
832 | |||
813 | noiseline = numpy.repeat(noisedB[i], len(y)) |
|
833 | noiseline = numpy.repeat(noisedB[i], len(y)) | |
814 | axes.addpline(noiseline, y, idline=1, color="black", linestyle="dashed", lw=2) |
|
834 | axes.addpline(noiseline, y, idline=1, color="black", linestyle="dashed", lw=2) | |
815 |
|
835 | |||
816 | self.draw() |
|
836 | self.draw() | |
817 |
|
837 | |||
818 | if save: |
|
838 | if save: | |
819 |
|
839 | |||
820 | self.counter_imagwr += 1 |
|
840 | self.counter_imagwr += 1 | |
821 | if (self.counter_imagwr==wr_period): |
|
841 | if (self.counter_imagwr==wr_period): | |
822 | if figfile == None: |
|
842 | if figfile == None: | |
823 | str_datetime = thisDatetime.strftime("%Y%m%d_%H%M%S") |
|
843 | str_datetime = thisDatetime.strftime("%Y%m%d_%H%M%S") | |
824 | figfile = self.getFilename(name = str_datetime) |
|
844 | figfile = self.getFilename(name = str_datetime) | |
825 |
|
845 | |||
826 | self.saveFigure(figpath, figfile) |
|
846 | self.saveFigure(figpath, figfile) | |
827 |
|
847 | |||
828 | if ftp: |
|
848 | if ftp: | |
829 | #provisionalmente envia archivos en el formato de la web en tiempo real |
|
849 | #provisionalmente envia archivos en el formato de la web en tiempo real | |
830 | name = self.getNameToFtp(thisDatetime, self.FTP_WEI, self.EXP_CODE, self.SUB_EXP_CODE, self.PLOT_CODE, self.PLOT_POS) |
|
850 | name = self.getNameToFtp(thisDatetime, self.FTP_WEI, self.EXP_CODE, self.SUB_EXP_CODE, self.PLOT_CODE, self.PLOT_POS) | |
831 | path = '%s%03d' %(self.PREFIX, self.id) |
|
851 | path = '%s%03d' %(self.PREFIX, self.id) | |
832 | ftp_file = os.path.join(path,'ftp','%s.png'%name) |
|
852 | ftp_file = os.path.join(path,'ftp','%s.png'%name) | |
833 | self.saveFigure(figpath, ftp_file) |
|
853 | self.saveFigure(figpath, ftp_file) | |
834 | ftp_filename = os.path.join(figpath,ftp_file) |
|
854 | ftp_filename = os.path.join(figpath,ftp_file) | |
835 | self.sendByFTP_Thread(ftp_filename, server, folder, username, password) |
|
855 | self.sendByFTP_Thread(ftp_filename, server, folder, username, password) | |
836 | self.counter_imagwr = 0 |
|
856 | self.counter_imagwr = 0 | |
837 |
|
857 | |||
838 |
|
858 | |||
839 | self.counter_imagwr = 0 |
|
859 | self.counter_imagwr = 0 | |
840 |
|
860 | |||
841 |
|
861 | |||
842 | class Scope(Figure): |
|
862 | class Scope(Figure): | |
843 |
|
863 | |||
844 | __isConfig = None |
|
864 | __isConfig = None | |
845 |
|
865 | |||
846 | def __init__(self): |
|
866 | def __init__(self): | |
847 |
|
867 | |||
848 | self.__isConfig = False |
|
868 | self.__isConfig = False | |
849 | self.WIDTH = 600 |
|
869 | self.WIDTH = 600 | |
850 | self.HEIGHT = 200 |
|
870 | self.HEIGHT = 200 | |
851 | self.counter_imagwr = 0 |
|
871 | self.counter_imagwr = 0 | |
852 |
|
872 | |||
853 | def getSubplots(self): |
|
873 | def getSubplots(self): | |
854 |
|
874 | |||
855 | nrow = self.nplots |
|
875 | nrow = self.nplots | |
856 | ncol = 3 |
|
876 | ncol = 3 | |
857 | return nrow, ncol |
|
877 | return nrow, ncol | |
858 |
|
878 | |||
859 | def setup(self, id, nplots, wintitle, show): |
|
879 | def setup(self, id, nplots, wintitle, show): | |
860 |
|
880 | |||
861 | self.nplots = nplots |
|
881 | self.nplots = nplots | |
862 |
|
882 | |||
863 | self.createFigure(id=id, |
|
883 | self.createFigure(id=id, | |
864 | wintitle=wintitle, |
|
884 | wintitle=wintitle, | |
865 | show=show) |
|
885 | show=show) | |
866 |
|
886 | |||
867 | nrow,ncol = self.getSubplots() |
|
887 | nrow,ncol = self.getSubplots() | |
868 | colspan = 3 |
|
888 | colspan = 3 | |
869 | rowspan = 1 |
|
889 | rowspan = 1 | |
870 |
|
890 | |||
871 | for i in range(nplots): |
|
891 | for i in range(nplots): | |
872 | self.addAxes(nrow, ncol, i, 0, colspan, rowspan) |
|
892 | self.addAxes(nrow, ncol, i, 0, colspan, rowspan) | |
873 |
|
893 | |||
874 |
|
894 | |||
875 |
|
895 | |||
876 | def run(self, dataOut, id, wintitle="", channelList=None, |
|
896 | def run(self, dataOut, id, wintitle="", channelList=None, | |
877 | xmin=None, xmax=None, ymin=None, ymax=None, save=False, |
|
897 | xmin=None, xmax=None, ymin=None, ymax=None, save=False, | |
878 | figpath='./', figfile=None, show=True, wr_period=1, |
|
898 | figpath='./', figfile=None, show=True, wr_period=1, | |
879 | server=None, folder=None, username=None, password=None): |
|
899 | server=None, folder=None, username=None, password=None): | |
880 |
|
900 | |||
881 | """ |
|
901 | """ | |
882 |
|
902 | |||
883 | Input: |
|
903 | Input: | |
884 | dataOut : |
|
904 | dataOut : | |
885 | id : |
|
905 | id : | |
886 | wintitle : |
|
906 | wintitle : | |
887 | channelList : |
|
907 | channelList : | |
888 | xmin : None, |
|
908 | xmin : None, | |
889 | xmax : None, |
|
909 | xmax : None, | |
890 | ymin : None, |
|
910 | ymin : None, | |
891 | ymax : None, |
|
911 | ymax : None, | |
892 | """ |
|
912 | """ | |
893 |
|
913 | |||
894 | if channelList == None: |
|
914 | if channelList == None: | |
895 | channelIndexList = dataOut.channelIndexList |
|
915 | channelIndexList = dataOut.channelIndexList | |
896 | else: |
|
916 | else: | |
897 | channelIndexList = [] |
|
917 | channelIndexList = [] | |
898 | for channel in channelList: |
|
918 | for channel in channelList: | |
899 | if channel not in dataOut.channelList: |
|
919 | if channel not in dataOut.channelList: | |
900 | raise ValueError, "Channel %d is not in dataOut.channelList" |
|
920 | raise ValueError, "Channel %d is not in dataOut.channelList" | |
901 | channelIndexList.append(dataOut.channelList.index(channel)) |
|
921 | channelIndexList.append(dataOut.channelList.index(channel)) | |
902 |
|
922 | |||
903 | x = dataOut.heightList |
|
923 | x = dataOut.heightList | |
904 | y = dataOut.data[channelIndexList,:] * numpy.conjugate(dataOut.data[channelIndexList,:]) |
|
924 | y = dataOut.data[channelIndexList,:] * numpy.conjugate(dataOut.data[channelIndexList,:]) | |
905 | y = y.real |
|
925 | y = y.real | |
906 |
|
926 | |||
907 | #thisDatetime = dataOut.datatime |
|
927 | #thisDatetime = dataOut.datatime | |
908 | thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[1]) |
|
928 | thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[1]) | |
909 | title = wintitle + " Scope: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) |
|
929 | title = wintitle + " Scope: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) | |
910 | xlabel = "Range (Km)" |
|
930 | xlabel = "Range (Km)" | |
911 | ylabel = "Intensity" |
|
931 | ylabel = "Intensity" | |
912 |
|
932 | |||
913 | if not self.__isConfig: |
|
933 | if not self.__isConfig: | |
914 | nplots = len(channelIndexList) |
|
934 | nplots = len(channelIndexList) | |
915 |
|
935 | |||
916 | self.setup(id=id, |
|
936 | self.setup(id=id, | |
917 | nplots=nplots, |
|
937 | nplots=nplots, | |
918 | wintitle=wintitle, |
|
938 | wintitle=wintitle, | |
919 | show=show) |
|
939 | show=show) | |
920 |
|
940 | |||
921 | if xmin == None: xmin = numpy.nanmin(x) |
|
941 | if xmin == None: xmin = numpy.nanmin(x) | |
922 | if xmax == None: xmax = numpy.nanmax(x) |
|
942 | if xmax == None: xmax = numpy.nanmax(x) | |
923 | if ymin == None: ymin = numpy.nanmin(y) |
|
943 | if ymin == None: ymin = numpy.nanmin(y) | |
924 | if ymax == None: ymax = numpy.nanmax(y) |
|
944 | if ymax == None: ymax = numpy.nanmax(y) | |
925 |
|
945 | |||
926 | self.__isConfig = True |
|
946 | self.__isConfig = True | |
927 |
|
947 | |||
928 | self.setWinTitle(title) |
|
948 | self.setWinTitle(title) | |
929 |
|
949 | |||
930 | for i in range(len(self.axesList)): |
|
950 | for i in range(len(self.axesList)): | |
931 | title = "Channel %d" %(i) |
|
951 | title = "Channel %d" %(i) | |
932 | axes = self.axesList[i] |
|
952 | axes = self.axesList[i] | |
933 | ychannel = y[i,:] |
|
953 | ychannel = y[i,:] | |
934 | axes.pline(x, ychannel, |
|
954 | axes.pline(x, ychannel, | |
935 | xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, |
|
955 | xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, | |
936 | xlabel=xlabel, ylabel=ylabel, title=title) |
|
956 | xlabel=xlabel, ylabel=ylabel, title=title) | |
937 |
|
957 | |||
938 | self.draw() |
|
958 | self.draw() | |
939 |
|
959 | |||
940 | if save: |
|
960 | if save: | |
941 | date = thisDatetime.strftime("%Y%m%d_%H%M%S") |
|
961 | date = thisDatetime.strftime("%Y%m%d_%H%M%S") | |
942 | if figfile == None: |
|
962 | if figfile == None: | |
943 | figfile = self.getFilename(name = date) |
|
963 | figfile = self.getFilename(name = date) | |
944 |
|
964 | |||
945 | self.saveFigure(figpath, figfile) |
|
965 | self.saveFigure(figpath, figfile) | |
946 |
|
966 | |||
947 | self.counter_imagwr += 1 |
|
967 | self.counter_imagwr += 1 | |
948 | if (ftp and (self.counter_imagwr==wr_period)): |
|
968 | if (ftp and (self.counter_imagwr==wr_period)): | |
949 | ftp_filename = os.path.join(figpath,figfile) |
|
969 | ftp_filename = os.path.join(figpath,figfile) | |
950 | self.sendByFTP_Thread(ftp_filename, server, folder, username, password) |
|
970 | self.sendByFTP_Thread(ftp_filename, server, folder, username, password) | |
951 | self.counter_imagwr = 0 |
|
971 | self.counter_imagwr = 0 | |
952 |
|
972 | |||
953 | class PowerProfilePlot(Figure): |
|
973 | class PowerProfilePlot(Figure): | |
954 | __isConfig = None |
|
974 | __isConfig = None | |
955 | __nsubplots = None |
|
975 | __nsubplots = None | |
956 |
|
976 | |||
957 | WIDTHPROF = None |
|
977 | WIDTHPROF = None | |
958 | HEIGHTPROF = None |
|
978 | HEIGHTPROF = None | |
959 | PREFIX = 'spcprofile' |
|
979 | PREFIX = 'spcprofile' | |
960 |
|
980 | |||
961 | def __init__(self): |
|
981 | def __init__(self): | |
962 | self.__isConfig = False |
|
982 | self.__isConfig = False | |
963 | self.__nsubplots = 1 |
|
983 | self.__nsubplots = 1 | |
964 |
|
984 | |||
965 | self.WIDTH = 300 |
|
985 | self.WIDTH = 300 | |
966 | self.HEIGHT = 500 |
|
986 | self.HEIGHT = 500 | |
967 | self.counter_imagwr = 0 |
|
987 | self.counter_imagwr = 0 | |
968 |
|
988 | |||
969 | def getSubplots(self): |
|
989 | def getSubplots(self): | |
970 | ncol = 1 |
|
990 | ncol = 1 | |
971 | nrow = 1 |
|
991 | nrow = 1 | |
972 |
|
992 | |||
973 | return nrow, ncol |
|
993 | return nrow, ncol | |
974 |
|
994 | |||
975 | def setup(self, id, nplots, wintitle, show): |
|
995 | def setup(self, id, nplots, wintitle, show): | |
976 |
|
996 | |||
977 | self.nplots = nplots |
|
997 | self.nplots = nplots | |
978 |
|
998 | |||
979 | ncolspan = 1 |
|
999 | ncolspan = 1 | |
980 | colspan = 1 |
|
1000 | colspan = 1 | |
981 |
|
1001 | |||
982 | self.createFigure(id = id, |
|
1002 | self.createFigure(id = id, | |
983 | wintitle = wintitle, |
|
1003 | wintitle = wintitle, | |
984 | widthplot = self.WIDTH, |
|
1004 | widthplot = self.WIDTH, | |
985 | heightplot = self.HEIGHT, |
|
1005 | heightplot = self.HEIGHT, | |
986 | show=show) |
|
1006 | show=show) | |
987 |
|
1007 | |||
988 | nrow, ncol = self.getSubplots() |
|
1008 | nrow, ncol = self.getSubplots() | |
989 |
|
1009 | |||
990 | counter = 0 |
|
1010 | counter = 0 | |
991 | for y in range(nrow): |
|
1011 | for y in range(nrow): | |
992 | for x in range(ncol): |
|
1012 | for x in range(ncol): | |
993 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1) |
|
1013 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1) | |
994 |
|
1014 | |||
995 | def run(self, dataOut, id, wintitle="", channelList=None, |
|
1015 | def run(self, dataOut, id, wintitle="", channelList=None, | |
996 | xmin=None, xmax=None, ymin=None, ymax=None, |
|
1016 | xmin=None, xmax=None, ymin=None, ymax=None, | |
997 | save=False, figpath='./', figfile=None, show=True, wr_period=1, |
|
1017 | save=False, figpath='./', figfile=None, show=True, wr_period=1, | |
998 | server=None, folder=None, username=None, password=None,): |
|
1018 | server=None, folder=None, username=None, password=None,): | |
999 |
|
1019 | |||
1000 | if channelList == None: |
|
1020 | if channelList == None: | |
1001 | channelIndexList = dataOut.channelIndexList |
|
1021 | channelIndexList = dataOut.channelIndexList | |
1002 | channelList = dataOut.channelList |
|
1022 | channelList = dataOut.channelList | |
1003 | else: |
|
1023 | else: | |
1004 | channelIndexList = [] |
|
1024 | channelIndexList = [] | |
1005 | for channel in channelList: |
|
1025 | for channel in channelList: | |
1006 | if channel not in dataOut.channelList: |
|
1026 | if channel not in dataOut.channelList: | |
1007 | raise ValueError, "Channel %d is not in dataOut.channelList" |
|
1027 | raise ValueError, "Channel %d is not in dataOut.channelList" | |
1008 | channelIndexList.append(dataOut.channelList.index(channel)) |
|
1028 | channelIndexList.append(dataOut.channelList.index(channel)) | |
1009 |
|
1029 | |||
1010 | factor = dataOut.normFactor |
|
1030 | factor = dataOut.normFactor | |
1011 | y = dataOut.getHeiRange() |
|
1031 | y = dataOut.getHeiRange() | |
1012 | x = dataOut.data_spc[channelIndexList,:,:]/factor |
|
1032 | x = dataOut.data_spc[channelIndexList,:,:]/factor | |
1013 | x = numpy.where(numpy.isfinite(x), x, numpy.NAN) |
|
1033 | x = numpy.where(numpy.isfinite(x), x, numpy.NAN) | |
1014 | avg = numpy.average(x, axis=1) |
|
1034 | avg = numpy.average(x, axis=1) | |
1015 |
|
1035 | |||
1016 | avgdB = 10*numpy.log10(avg) |
|
1036 | avgdB = 10*numpy.log10(avg) | |
1017 |
|
1037 | |||
1018 | #thisDatetime = dataOut.datatime |
|
1038 | #thisDatetime = dataOut.datatime | |
1019 | thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[1]) |
|
1039 | thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[1]) | |
1020 | title = wintitle + " Power Profile %s" %(thisDatetime.strftime("%d-%b-%Y")) |
|
1040 | title = wintitle + " Power Profile %s" %(thisDatetime.strftime("%d-%b-%Y")) | |
1021 | xlabel = "dB" |
|
1041 | xlabel = "dB" | |
1022 | ylabel = "Range (Km)" |
|
1042 | ylabel = "Range (Km)" | |
1023 |
|
1043 | |||
1024 | if not self.__isConfig: |
|
1044 | if not self.__isConfig: | |
1025 |
|
1045 | |||
1026 | nplots = 1 |
|
1046 | nplots = 1 | |
1027 |
|
1047 | |||
1028 | self.setup(id=id, |
|
1048 | self.setup(id=id, | |
1029 | nplots=nplots, |
|
1049 | nplots=nplots, | |
1030 | wintitle=wintitle, |
|
1050 | wintitle=wintitle, | |
1031 | show=show) |
|
1051 | show=show) | |
1032 |
|
1052 | |||
1033 | if ymin == None: ymin = numpy.nanmin(y) |
|
1053 | if ymin == None: ymin = numpy.nanmin(y) | |
1034 | if ymax == None: ymax = numpy.nanmax(y) |
|
1054 | if ymax == None: ymax = numpy.nanmax(y) | |
1035 | if xmin == None: xmin = numpy.nanmin(avgdB)*0.9 |
|
1055 | if xmin == None: xmin = numpy.nanmin(avgdB)*0.9 | |
1036 | if xmax == None: xmax = numpy.nanmax(avgdB)*0.9 |
|
1056 | if xmax == None: xmax = numpy.nanmax(avgdB)*0.9 | |
1037 |
|
1057 | |||
1038 | self.__isConfig = True |
|
1058 | self.__isConfig = True | |
1039 |
|
1059 | |||
1040 | self.setWinTitle(title) |
|
1060 | self.setWinTitle(title) | |
1041 |
|
1061 | |||
1042 |
|
1062 | |||
1043 | title = "Power Profile: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) |
|
1063 | title = "Power Profile: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) | |
1044 | axes = self.axesList[0] |
|
1064 | axes = self.axesList[0] | |
1045 |
|
1065 | |||
1046 | legendlabels = ["channel %d"%x for x in channelList] |
|
1066 | legendlabels = ["channel %d"%x for x in channelList] | |
1047 | axes.pmultiline(avgdB, y, |
|
1067 | axes.pmultiline(avgdB, y, | |
1048 | xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, |
|
1068 | xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, | |
1049 | xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels, |
|
1069 | xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels, | |
1050 | ytick_visible=True, nxticks=5, |
|
1070 | ytick_visible=True, nxticks=5, | |
1051 | grid='x') |
|
1071 | grid='x') | |
1052 |
|
1072 | |||
1053 | self.draw() |
|
1073 | self.draw() | |
1054 |
|
1074 | |||
1055 | if save: |
|
1075 | if save: | |
1056 | date = thisDatetime.strftime("%Y%m%d") |
|
1076 | date = thisDatetime.strftime("%Y%m%d") | |
1057 | if figfile == None: |
|
1077 | if figfile == None: | |
1058 | figfile = self.getFilename(name = date) |
|
1078 | figfile = self.getFilename(name = date) | |
1059 |
|
1079 | |||
1060 | self.saveFigure(figpath, figfile) |
|
1080 | self.saveFigure(figpath, figfile) | |
1061 |
|
1081 | |||
1062 | self.counter_imagwr += 1 |
|
1082 | self.counter_imagwr += 1 | |
1063 | if (ftp and (self.counter_imagwr==wr_period)): |
|
1083 | if (ftp and (self.counter_imagwr==wr_period)): | |
1064 | ftp_filename = os.path.join(figpath,figfile) |
|
1084 | ftp_filename = os.path.join(figpath,figfile) | |
1065 | self.sendByFTP_Thread(ftp_filename, server, folder, username, password) |
|
1085 | self.sendByFTP_Thread(ftp_filename, server, folder, username, password) | |
1066 | self.counter_imagwr = 0 |
|
1086 | self.counter_imagwr = 0 | |
1067 |
|
1087 | |||
1068 | class CoherenceMap(Figure): |
|
1088 | class CoherenceMap(Figure): | |
1069 | __isConfig = None |
|
1089 | __isConfig = None | |
1070 | __nsubplots = None |
|
1090 | __nsubplots = None | |
1071 |
|
1091 | |||
1072 | WIDTHPROF = None |
|
1092 | WIDTHPROF = None | |
1073 | HEIGHTPROF = None |
|
1093 | HEIGHTPROF = None | |
1074 | PREFIX = 'cmap' |
|
1094 | PREFIX = 'cmap' | |
1075 |
|
1095 | |||
1076 | def __init__(self): |
|
1096 | def __init__(self): | |
1077 | self.timerange = 2*60*60 |
|
1097 | self.timerange = 2*60*60 | |
1078 | self.__isConfig = False |
|
1098 | self.__isConfig = False | |
1079 | self.__nsubplots = 1 |
|
1099 | self.__nsubplots = 1 | |
1080 |
|
1100 | |||
1081 | self.WIDTH = 800 |
|
1101 | self.WIDTH = 800 | |
1082 | self.HEIGHT = 150 |
|
1102 | self.HEIGHT = 150 | |
1083 | self.WIDTHPROF = 120 |
|
1103 | self.WIDTHPROF = 120 | |
1084 | self.HEIGHTPROF = 0 |
|
1104 | self.HEIGHTPROF = 0 | |
1085 | self.counter_imagwr = 0 |
|
1105 | self.counter_imagwr = 0 | |
1086 |
|
1106 | |||
1087 | self.PLOT_CODE = 3 |
|
1107 | self.PLOT_CODE = 3 | |
1088 | self.FTP_WEI = None |
|
1108 | self.FTP_WEI = None | |
1089 | self.EXP_CODE = None |
|
1109 | self.EXP_CODE = None | |
1090 | self.SUB_EXP_CODE = None |
|
1110 | self.SUB_EXP_CODE = None | |
1091 | self.PLOT_POS = None |
|
1111 | self.PLOT_POS = None | |
1092 | self.counter_imagwr = 0 |
|
1112 | self.counter_imagwr = 0 | |
1093 |
|
1113 | |||
|
1114 | self.xmin = None | |||
|
1115 | self.xmax = None | |||
|
1116 | ||||
1094 | def getSubplots(self): |
|
1117 | def getSubplots(self): | |
1095 | ncol = 1 |
|
1118 | ncol = 1 | |
1096 | nrow = self.nplots*2 |
|
1119 | nrow = self.nplots*2 | |
1097 |
|
1120 | |||
1098 | return nrow, ncol |
|
1121 | return nrow, ncol | |
1099 |
|
1122 | |||
1100 | def setup(self, id, nplots, wintitle, showprofile=True, show=True): |
|
1123 | def setup(self, id, nplots, wintitle, showprofile=True, show=True): | |
1101 | self.__showprofile = showprofile |
|
1124 | self.__showprofile = showprofile | |
1102 | self.nplots = nplots |
|
1125 | self.nplots = nplots | |
1103 |
|
1126 | |||
1104 | ncolspan = 1 |
|
1127 | ncolspan = 1 | |
1105 | colspan = 1 |
|
1128 | colspan = 1 | |
1106 | if showprofile: |
|
1129 | if showprofile: | |
1107 | ncolspan = 7 |
|
1130 | ncolspan = 7 | |
1108 | colspan = 6 |
|
1131 | colspan = 6 | |
1109 | self.__nsubplots = 2 |
|
1132 | self.__nsubplots = 2 | |
1110 |
|
1133 | |||
1111 | self.createFigure(id = id, |
|
1134 | self.createFigure(id = id, | |
1112 | wintitle = wintitle, |
|
1135 | wintitle = wintitle, | |
1113 | widthplot = self.WIDTH + self.WIDTHPROF, |
|
1136 | widthplot = self.WIDTH + self.WIDTHPROF, | |
1114 | heightplot = self.HEIGHT + self.HEIGHTPROF, |
|
1137 | heightplot = self.HEIGHT + self.HEIGHTPROF, | |
1115 | show=True) |
|
1138 | show=True) | |
1116 |
|
1139 | |||
1117 | nrow, ncol = self.getSubplots() |
|
1140 | nrow, ncol = self.getSubplots() | |
1118 |
|
1141 | |||
1119 | for y in range(nrow): |
|
1142 | for y in range(nrow): | |
1120 | for x in range(ncol): |
|
1143 | for x in range(ncol): | |
1121 |
|
1144 | |||
1122 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1) |
|
1145 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1) | |
1123 |
|
1146 | |||
1124 | if showprofile: |
|
1147 | if showprofile: | |
1125 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1) |
|
1148 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1) | |
1126 |
|
1149 | |||
1127 | def run(self, dataOut, id, wintitle="", pairsList=None, showprofile='True', |
|
1150 | def run(self, dataOut, id, wintitle="", pairsList=None, showprofile='True', | |
1128 | xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None, |
|
1151 | xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None, | |
1129 | timerange=None, |
|
1152 | timerange=None, | |
1130 | save=False, figpath='./', figfile=None, ftp=False, wr_period=1, |
|
1153 | save=False, figpath='./', figfile=None, ftp=False, wr_period=1, | |
1131 | coherence_cmap='jet', phase_cmap='RdBu_r', show=True, |
|
1154 | coherence_cmap='jet', phase_cmap='RdBu_r', show=True, | |
1132 | server=None, folder=None, username=None, password=None, |
|
1155 | server=None, folder=None, username=None, password=None, | |
1133 | ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0): |
|
1156 | ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0): | |
1134 |
|
1157 | |||
1135 | if pairsList == None: |
|
1158 | if pairsList == None: | |
1136 | pairsIndexList = dataOut.pairsIndexList |
|
1159 | pairsIndexList = dataOut.pairsIndexList | |
1137 | else: |
|
1160 | else: | |
1138 | pairsIndexList = [] |
|
1161 | pairsIndexList = [] | |
1139 | for pair in pairsList: |
|
1162 | for pair in pairsList: | |
1140 | if pair not in dataOut.pairsList: |
|
1163 | if pair not in dataOut.pairsList: | |
1141 | raise ValueError, "Pair %s is not in dataOut.pairsList" %(pair) |
|
1164 | raise ValueError, "Pair %s is not in dataOut.pairsList" %(pair) | |
1142 | pairsIndexList.append(dataOut.pairsList.index(pair)) |
|
1165 | pairsIndexList.append(dataOut.pairsList.index(pair)) | |
1143 |
|
1166 | |||
1144 | if timerange != None: |
|
1167 | if timerange != None: | |
1145 | self.timerange = timerange |
|
1168 | self.timerange = timerange | |
1146 |
|
1169 | |||
1147 | if pairsIndexList == []: |
|
1170 | if pairsIndexList == []: | |
1148 | return |
|
1171 | return | |
1149 |
|
1172 | |||
1150 | if len(pairsIndexList) > 4: |
|
1173 | if len(pairsIndexList) > 4: | |
1151 | pairsIndexList = pairsIndexList[0:4] |
|
1174 | pairsIndexList = pairsIndexList[0:4] | |
1152 |
|
1175 | |||
1153 | tmin = None |
|
1176 | # tmin = None | |
1154 | tmax = None |
|
1177 | # tmax = None | |
1155 | x = dataOut.getTimeRange() |
|
1178 | x = dataOut.getTimeRange() | |
1156 | y = dataOut.getHeiRange() |
|
1179 | y = dataOut.getHeiRange() | |
1157 |
|
1180 | |||
1158 | #thisDatetime = dataOut.datatime |
|
1181 | #thisDatetime = dataOut.datatime | |
1159 | thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[1]) |
|
1182 | thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[1]) | |
1160 | title = wintitle + " CoherenceMap" #: %s" %(thisDatetime.strftime("%d-%b-%Y")) |
|
1183 | title = wintitle + " CoherenceMap" #: %s" %(thisDatetime.strftime("%d-%b-%Y")) | |
1161 | xlabel = "" |
|
1184 | xlabel = "" | |
1162 | ylabel = "Range (Km)" |
|
1185 | ylabel = "Range (Km)" | |
1163 |
|
1186 | |||
1164 | if not self.__isConfig: |
|
1187 | if not self.__isConfig: | |
1165 | nplots = len(pairsIndexList) |
|
1188 | nplots = len(pairsIndexList) | |
1166 | self.setup(id=id, |
|
1189 | self.setup(id=id, | |
1167 | nplots=nplots, |
|
1190 | nplots=nplots, | |
1168 | wintitle=wintitle, |
|
1191 | wintitle=wintitle, | |
1169 | showprofile=showprofile, |
|
1192 | showprofile=showprofile, | |
1170 | show=show) |
|
1193 | show=show) | |
1171 |
|
1194 | |||
1172 | tmin, tmax = self.getTimeLim(x, xmin, xmax) |
|
1195 | #tmin, tmax = self.getTimeLim(x, xmin, xmax) | |
|
1196 | ||||
|
1197 | self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange) | |||
|
1198 | ||||
1173 | if ymin == None: ymin = numpy.nanmin(y) |
|
1199 | if ymin == None: ymin = numpy.nanmin(y) | |
1174 | if ymax == None: ymax = numpy.nanmax(y) |
|
1200 | if ymax == None: ymax = numpy.nanmax(y) | |
1175 | if zmin == None: zmin = 0. |
|
1201 | if zmin == None: zmin = 0. | |
1176 | if zmax == None: zmax = 1. |
|
1202 | if zmax == None: zmax = 1. | |
1177 |
|
1203 | |||
1178 | self.FTP_WEI = ftp_wei |
|
1204 | self.FTP_WEI = ftp_wei | |
1179 | self.EXP_CODE = exp_code |
|
1205 | self.EXP_CODE = exp_code | |
1180 | self.SUB_EXP_CODE = sub_exp_code |
|
1206 | self.SUB_EXP_CODE = sub_exp_code | |
1181 | self.PLOT_POS = plot_pos |
|
1207 | self.PLOT_POS = plot_pos | |
1182 |
|
1208 | |||
1183 | self.name = thisDatetime.strftime("%Y%m%d_%H%M%S") |
|
1209 | self.name = thisDatetime.strftime("%Y%m%d_%H%M%S") | |
1184 |
|
1210 | |||
1185 | self.__isConfig = True |
|
1211 | self.__isConfig = True | |
1186 |
|
1212 | |||
1187 | self.setWinTitle(title) |
|
1213 | self.setWinTitle(title) | |
1188 |
|
1214 | |||
|
1215 | if ((self.xmax - x[1]) < (x[1]-x[0])): | |||
|
1216 | x[1] = self.xmax | |||
|
1217 | ||||
1189 | for i in range(self.nplots): |
|
1218 | for i in range(self.nplots): | |
1190 |
|
1219 | |||
1191 | pair = dataOut.pairsList[pairsIndexList[i]] |
|
1220 | pair = dataOut.pairsList[pairsIndexList[i]] | |
1192 | # coherenceComplex = dataOut.data_cspc[pairsIndexList[i],:,:]/numpy.sqrt(dataOut.data_spc[pair[0],:,:]*dataOut.data_spc[pair[1],:,:]) |
|
1221 | # coherenceComplex = dataOut.data_cspc[pairsIndexList[i],:,:]/numpy.sqrt(dataOut.data_spc[pair[0],:,:]*dataOut.data_spc[pair[1],:,:]) | |
1193 | # avgcoherenceComplex = numpy.average(coherenceComplex, axis=0) |
|
1222 | # avgcoherenceComplex = numpy.average(coherenceComplex, axis=0) | |
1194 | # coherence = numpy.abs(avgcoherenceComplex) |
|
1223 | # coherence = numpy.abs(avgcoherenceComplex) | |
1195 |
|
1224 | |||
1196 | ## coherence = numpy.abs(coherenceComplex) |
|
1225 | ## coherence = numpy.abs(coherenceComplex) | |
1197 | ## avg = numpy.average(coherence, axis=0) |
|
1226 | ## avg = numpy.average(coherence, axis=0) | |
1198 |
|
1227 | |||
1199 | ccf = numpy.average(dataOut.data_cspc[pairsIndexList[i],:,:],axis=0) |
|
1228 | ccf = numpy.average(dataOut.data_cspc[pairsIndexList[i],:,:],axis=0) | |
1200 | powa = numpy.average(dataOut.data_spc[pair[0],:,:],axis=0) |
|
1229 | powa = numpy.average(dataOut.data_spc[pair[0],:,:],axis=0) | |
1201 | powb = numpy.average(dataOut.data_spc[pair[1],:,:],axis=0) |
|
1230 | powb = numpy.average(dataOut.data_spc[pair[1],:,:],axis=0) | |
1202 |
|
1231 | |||
1203 |
|
1232 | |||
1204 | avgcoherenceComplex = ccf/numpy.sqrt(powa*powb) |
|
1233 | avgcoherenceComplex = ccf/numpy.sqrt(powa*powb) | |
1205 | coherence = numpy.abs(avgcoherenceComplex) |
|
1234 | coherence = numpy.abs(avgcoherenceComplex) | |
1206 |
|
1235 | |||
1207 | z = coherence.reshape((1,-1)) |
|
1236 | z = coherence.reshape((1,-1)) | |
1208 |
|
1237 | |||
1209 | counter = 0 |
|
1238 | counter = 0 | |
1210 |
|
1239 | |||
1211 | title = "Coherence %d%d: %s" %(pair[0], pair[1], thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) |
|
1240 | title = "Coherence %d%d: %s" %(pair[0], pair[1], thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) | |
1212 | axes = self.axesList[i*self.__nsubplots*2] |
|
1241 | axes = self.axesList[i*self.__nsubplots*2] | |
1213 | axes.pcolorbuffer(x, y, z, |
|
1242 | axes.pcolorbuffer(x, y, z, | |
1214 |
xmin= |
|
1243 | xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax, | |
1215 | xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True, |
|
1244 | xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True, | |
1216 | ticksize=9, cblabel='', colormap=coherence_cmap, cbsize="1%") |
|
1245 | ticksize=9, cblabel='', colormap=coherence_cmap, cbsize="1%") | |
1217 |
|
1246 | |||
1218 | if self.__showprofile: |
|
1247 | if self.__showprofile: | |
1219 | counter += 1 |
|
1248 | counter += 1 | |
1220 | axes = self.axesList[i*self.__nsubplots*2 + counter] |
|
1249 | axes = self.axesList[i*self.__nsubplots*2 + counter] | |
1221 | axes.pline(coherence, y, |
|
1250 | axes.pline(coherence, y, | |
1222 | xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax, |
|
1251 | xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax, | |
1223 | xlabel='', ylabel='', title='', ticksize=7, |
|
1252 | xlabel='', ylabel='', title='', ticksize=7, | |
1224 | ytick_visible=False, nxticks=5, |
|
1253 | ytick_visible=False, nxticks=5, | |
1225 | grid='x') |
|
1254 | grid='x') | |
1226 |
|
1255 | |||
1227 | counter += 1 |
|
1256 | counter += 1 | |
1228 | # phase = numpy.arctan(-1*coherenceComplex.imag/coherenceComplex.real)*180/numpy.pi |
|
1257 | # phase = numpy.arctan(-1*coherenceComplex.imag/coherenceComplex.real)*180/numpy.pi | |
1229 | phase = numpy.arctan2(avgcoherenceComplex.imag, avgcoherenceComplex.real)*180/numpy.pi |
|
1258 | phase = numpy.arctan2(avgcoherenceComplex.imag, avgcoherenceComplex.real)*180/numpy.pi | |
1230 | # avg = numpy.average(phase, axis=0) |
|
1259 | # avg = numpy.average(phase, axis=0) | |
1231 | z = phase.reshape((1,-1)) |
|
1260 | z = phase.reshape((1,-1)) | |
1232 |
|
1261 | |||
1233 | title = "Phase %d%d: %s" %(pair[0], pair[1], thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) |
|
1262 | title = "Phase %d%d: %s" %(pair[0], pair[1], thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) | |
1234 | axes = self.axesList[i*self.__nsubplots*2 + counter] |
|
1263 | axes = self.axesList[i*self.__nsubplots*2 + counter] | |
1235 | axes.pcolorbuffer(x, y, z, |
|
1264 | axes.pcolorbuffer(x, y, z, | |
1236 |
xmin= |
|
1265 | xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=-180, zmax=180, | |
1237 | xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True, |
|
1266 | xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True, | |
1238 | ticksize=9, cblabel='', colormap=phase_cmap, cbsize="1%") |
|
1267 | ticksize=9, cblabel='', colormap=phase_cmap, cbsize="1%") | |
1239 |
|
1268 | |||
1240 | if self.__showprofile: |
|
1269 | if self.__showprofile: | |
1241 | counter += 1 |
|
1270 | counter += 1 | |
1242 | axes = self.axesList[i*self.__nsubplots*2 + counter] |
|
1271 | axes = self.axesList[i*self.__nsubplots*2 + counter] | |
1243 | axes.pline(phase, y, |
|
1272 | axes.pline(phase, y, | |
1244 | xmin=-180, xmax=180, ymin=ymin, ymax=ymax, |
|
1273 | xmin=-180, xmax=180, ymin=ymin, ymax=ymax, | |
1245 | xlabel='', ylabel='', title='', ticksize=7, |
|
1274 | xlabel='', ylabel='', title='', ticksize=7, | |
1246 | ytick_visible=False, nxticks=4, |
|
1275 | ytick_visible=False, nxticks=4, | |
1247 | grid='x') |
|
1276 | grid='x') | |
1248 |
|
1277 | |||
1249 | self.draw() |
|
1278 | self.draw() | |
1250 |
|
1279 | |||
1251 | if save: |
|
1280 | if x[1] >= self.axesList[0].xmax: | |
1252 |
|
||||
1253 | self.counter_imagwr += 1 |
|
|||
1254 | if (self.counter_imagwr==wr_period): |
|
|||
1255 | if figfile == None: |
|
|||
1256 | figfile = self.getFilename(name = self.name) |
|
|||
1257 |
|
|
1281 | self.saveFigure(figpath, figfile) | |
1258 |
|
||||
1259 | if ftp: |
|
|||
1260 | #provisionalmente envia archivos en el formato de la web en tiempo real |
|
|||
1261 | name = self.getNameToFtp(thisDatetime, self.FTP_WEI, self.EXP_CODE, self.SUB_EXP_CODE, self.PLOT_CODE, self.PLOT_POS) |
|
|||
1262 | path = '%s%03d' %(self.PREFIX, self.id) |
|
|||
1263 | ftp_file = os.path.join(path,'ftp','%s.png'%name) |
|
|||
1264 | self.saveFigure(figpath, ftp_file) |
|
|||
1265 | ftp_filename = os.path.join(figpath,ftp_file) |
|
|||
1266 | self.sendByFTP_Thread(ftp_filename, server, folder, username, password) |
|
|||
1267 | self.counter_imagwr = 0 |
|
|||
1268 |
|
||||
1269 | self.counter_imagwr = 0 |
|
|||
1270 |
|
||||
1271 |
|
||||
1272 | if x[1] + (x[1]-x[0]) >= self.axesList[0].xmax: |
|
|||
1273 | self.__isConfig = False |
|
1282 | self.__isConfig = False | |
1274 |
|
1283 | |||
|
1284 | # if save: | |||
|
1285 | # | |||
|
1286 | # self.counter_imagwr += 1 | |||
|
1287 | # if (self.counter_imagwr==wr_period): | |||
|
1288 | # if figfile == None: | |||
|
1289 | # figfile = self.getFilename(name = self.name) | |||
|
1290 | # self.saveFigure(figpath, figfile) | |||
|
1291 | # | |||
|
1292 | # if ftp: | |||
|
1293 | # #provisionalmente envia archivos en el formato de la web en tiempo real | |||
|
1294 | # name = self.getNameToFtp(thisDatetime, self.FTP_WEI, self.EXP_CODE, self.SUB_EXP_CODE, self.PLOT_CODE, self.PLOT_POS) | |||
|
1295 | # path = '%s%03d' %(self.PREFIX, self.id) | |||
|
1296 | # ftp_file = os.path.join(path,'ftp','%s.png'%name) | |||
|
1297 | # self.saveFigure(figpath, ftp_file) | |||
|
1298 | # ftp_filename = os.path.join(figpath,ftp_file) | |||
|
1299 | # self.sendByFTP_Thread(ftp_filename, server, folder, username, password) | |||
|
1300 | # self.counter_imagwr = 0 | |||
|
1301 | # | |||
|
1302 | # self.counter_imagwr = 0 | |||
|
1303 | # | |||
|
1304 | # | |||
|
1305 | # if x[1] + (x[1]-x[0]) >= self.axesList[0].xmax: | |||
|
1306 | # self.__isConfig = False | |||
|
1307 | ||||
1275 | class BeaconPhase(Figure): |
|
1308 | class BeaconPhase(Figure): | |
1276 |
|
1309 | |||
1277 | __isConfig = None |
|
1310 | __isConfig = None | |
1278 | __nsubplots = None |
|
1311 | __nsubplots = None | |
1279 |
|
1312 | |||
1280 | PREFIX = 'beacon_phase' |
|
1313 | PREFIX = 'beacon_phase' | |
1281 |
|
1314 | |||
1282 | def __init__(self): |
|
1315 | def __init__(self): | |
1283 |
|
1316 | |||
1284 | self.timerange = 24*60*60 |
|
1317 | self.timerange = 24*60*60 | |
1285 | self.__isConfig = False |
|
1318 | self.__isConfig = False | |
1286 | self.__nsubplots = 1 |
|
1319 | self.__nsubplots = 1 | |
1287 | self.counter_imagwr = 0 |
|
1320 | self.counter_imagwr = 0 | |
1288 | self.WIDTH = 600 |
|
1321 | self.WIDTH = 600 | |
1289 | self.HEIGHT = 300 |
|
1322 | self.HEIGHT = 300 | |
1290 | self.WIDTHPROF = 120 |
|
1323 | self.WIDTHPROF = 120 | |
1291 | self.HEIGHTPROF = 0 |
|
1324 | self.HEIGHTPROF = 0 | |
1292 | self.xdata = None |
|
1325 | self.xdata = None | |
1293 | self.ydata = None |
|
1326 | self.ydata = None | |
1294 |
|
1327 | |||
1295 | self.PLOT_CODE = 18 |
|
1328 | self.PLOT_CODE = 18 | |
1296 | self.FTP_WEI = None |
|
1329 | self.FTP_WEI = None | |
1297 | self.EXP_CODE = None |
|
1330 | self.EXP_CODE = None | |
1298 | self.SUB_EXP_CODE = None |
|
1331 | self.SUB_EXP_CODE = None | |
1299 | self.PLOT_POS = None |
|
1332 | self.PLOT_POS = None | |
1300 |
|
1333 | |||
1301 | self.filename_phase = None |
|
1334 | self.filename_phase = None | |
1302 |
|
1335 | |||
1303 | def getSubplots(self): |
|
1336 | def getSubplots(self): | |
1304 |
|
1337 | |||
1305 | ncol = 1 |
|
1338 | ncol = 1 | |
1306 | nrow = 1 |
|
1339 | nrow = 1 | |
1307 |
|
1340 | |||
1308 | return nrow, ncol |
|
1341 | return nrow, ncol | |
1309 |
|
1342 | |||
1310 | def setup(self, id, nplots, wintitle, showprofile=True, show=True): |
|
1343 | def setup(self, id, nplots, wintitle, showprofile=True, show=True): | |
1311 |
|
1344 | |||
1312 | self.__showprofile = showprofile |
|
1345 | self.__showprofile = showprofile | |
1313 | self.nplots = nplots |
|
1346 | self.nplots = nplots | |
1314 |
|
1347 | |||
1315 | ncolspan = 7 |
|
1348 | ncolspan = 7 | |
1316 | colspan = 6 |
|
1349 | colspan = 6 | |
1317 | self.__nsubplots = 2 |
|
1350 | self.__nsubplots = 2 | |
1318 |
|
1351 | |||
1319 | self.createFigure(id = id, |
|
1352 | self.createFigure(id = id, | |
1320 | wintitle = wintitle, |
|
1353 | wintitle = wintitle, | |
1321 | widthplot = self.WIDTH+self.WIDTHPROF, |
|
1354 | widthplot = self.WIDTH+self.WIDTHPROF, | |
1322 | heightplot = self.HEIGHT+self.HEIGHTPROF, |
|
1355 | heightplot = self.HEIGHT+self.HEIGHTPROF, | |
1323 | show=show) |
|
1356 | show=show) | |
1324 |
|
1357 | |||
1325 | nrow, ncol = self.getSubplots() |
|
1358 | nrow, ncol = self.getSubplots() | |
1326 |
|
1359 | |||
1327 | self.addAxes(nrow, ncol*ncolspan, 0, 0, colspan, 1) |
|
1360 | self.addAxes(nrow, ncol*ncolspan, 0, 0, colspan, 1) | |
1328 |
|
1361 | |||
1329 | def save_phase(self, filename_phase): |
|
1362 | def save_phase(self, filename_phase): | |
1330 | f = open(filename_phase,'w+') |
|
1363 | f = open(filename_phase,'w+') | |
1331 | f.write('\n\n') |
|
1364 | f.write('\n\n') | |
1332 | f.write('JICAMARCA RADIO OBSERVATORY - Beacon Phase \n') |
|
1365 | f.write('JICAMARCA RADIO OBSERVATORY - Beacon Phase \n') | |
1333 | f.write('DD MM YYYY HH MM SS pair(2,0) pair(2,1) pair(2,3) pair(2,4)\n\n' ) |
|
1366 | f.write('DD MM YYYY HH MM SS pair(2,0) pair(2,1) pair(2,3) pair(2,4)\n\n' ) | |
1334 | f.close() |
|
1367 | f.close() | |
1335 |
|
1368 | |||
1336 | def save_data(self, filename_phase, data, data_datetime): |
|
1369 | def save_data(self, filename_phase, data, data_datetime): | |
1337 | f=open(filename_phase,'a') |
|
1370 | f=open(filename_phase,'a') | |
1338 | timetuple_data = data_datetime.timetuple() |
|
1371 | timetuple_data = data_datetime.timetuple() | |
1339 | day = str(timetuple_data.tm_mday) |
|
1372 | day = str(timetuple_data.tm_mday) | |
1340 | month = str(timetuple_data.tm_mon) |
|
1373 | month = str(timetuple_data.tm_mon) | |
1341 | year = str(timetuple_data.tm_year) |
|
1374 | year = str(timetuple_data.tm_year) | |
1342 | hour = str(timetuple_data.tm_hour) |
|
1375 | hour = str(timetuple_data.tm_hour) | |
1343 | minute = str(timetuple_data.tm_min) |
|
1376 | minute = str(timetuple_data.tm_min) | |
1344 | second = str(timetuple_data.tm_sec) |
|
1377 | second = str(timetuple_data.tm_sec) | |
1345 | f.write(day+' '+month+' '+year+' '+hour+' '+minute+' '+second+' '+str(data[0])+' '+str(data[1])+' '+str(data[2])+' '+str(data[3])+'\n') |
|
1378 | f.write(day+' '+month+' '+year+' '+hour+' '+minute+' '+second+' '+str(data[0])+' '+str(data[1])+' '+str(data[2])+' '+str(data[3])+'\n') | |
1346 | f.close() |
|
1379 | f.close() | |
1347 |
|
1380 | |||
1348 |
|
1381 | |||
1349 | def run(self, dataOut, id, wintitle="", pairsList=None, showprofile='True', |
|
1382 | def run(self, dataOut, id, wintitle="", pairsList=None, showprofile='True', | |
1350 | xmin=None, xmax=None, ymin=None, ymax=None, |
|
1383 | xmin=None, xmax=None, ymin=None, ymax=None, | |
1351 | timerange=None, |
|
1384 | timerange=None, | |
1352 | save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1, |
|
1385 | save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1, | |
1353 | server=None, folder=None, username=None, password=None, |
|
1386 | server=None, folder=None, username=None, password=None, | |
1354 | ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0): |
|
1387 | ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0): | |
1355 |
|
1388 | |||
1356 | if pairsList == None: |
|
1389 | if pairsList == None: | |
1357 | pairsIndexList = dataOut.pairsIndexList |
|
1390 | pairsIndexList = dataOut.pairsIndexList | |
1358 | else: |
|
1391 | else: | |
1359 | pairsIndexList = [] |
|
1392 | pairsIndexList = [] | |
1360 | for pair in pairsList: |
|
1393 | for pair in pairsList: | |
1361 | if pair not in dataOut.pairsList: |
|
1394 | if pair not in dataOut.pairsList: | |
1362 | raise ValueError, "Pair %s is not in dataOut.pairsList" %(pair) |
|
1395 | raise ValueError, "Pair %s is not in dataOut.pairsList" %(pair) | |
1363 | pairsIndexList.append(dataOut.pairsList.index(pair)) |
|
1396 | pairsIndexList.append(dataOut.pairsList.index(pair)) | |
1364 |
|
1397 | |||
1365 | if pairsIndexList == []: |
|
1398 | if pairsIndexList == []: | |
1366 | return |
|
1399 | return | |
1367 |
|
1400 | |||
1368 | # if len(pairsIndexList) > 4: |
|
1401 | # if len(pairsIndexList) > 4: | |
1369 | # pairsIndexList = pairsIndexList[0:4] |
|
1402 | # pairsIndexList = pairsIndexList[0:4] | |
1370 |
|
1403 | |||
1371 | if timerange != None: |
|
1404 | if timerange != None: | |
1372 | self.timerange = timerange |
|
1405 | self.timerange = timerange | |
1373 |
|
1406 | |||
1374 | tmin = None |
|
1407 | tmin = None | |
1375 | tmax = None |
|
1408 | tmax = None | |
1376 | x = dataOut.getTimeRange() |
|
1409 | x = dataOut.getTimeRange() | |
1377 | y = dataOut.getHeiRange() |
|
1410 | y = dataOut.getHeiRange() | |
1378 |
|
1411 | |||
1379 |
|
1412 | |||
1380 | #thisDatetime = dataOut.datatime |
|
1413 | #thisDatetime = dataOut.datatime | |
1381 | thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[1]) |
|
1414 | thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[1]) | |
1382 | title = wintitle + " Phase of Beacon Signal" # : %s" %(thisDatetime.strftime("%d-%b-%Y")) |
|
1415 | title = wintitle + " Phase of Beacon Signal" # : %s" %(thisDatetime.strftime("%d-%b-%Y")) | |
1383 | xlabel = "Local Time" |
|
1416 | xlabel = "Local Time" | |
1384 | ylabel = "Phase" |
|
1417 | ylabel = "Phase" | |
1385 |
|
1418 | |||
1386 | nplots = len(pairsIndexList) |
|
1419 | nplots = len(pairsIndexList) | |
1387 | #phase = numpy.zeros((len(pairsIndexList),len(dataOut.beacon_heiIndexList))) |
|
1420 | #phase = numpy.zeros((len(pairsIndexList),len(dataOut.beacon_heiIndexList))) | |
1388 | phase_beacon = numpy.zeros(len(pairsIndexList)) |
|
1421 | phase_beacon = numpy.zeros(len(pairsIndexList)) | |
1389 | for i in range(nplots): |
|
1422 | for i in range(nplots): | |
1390 | pair = dataOut.pairsList[pairsIndexList[i]] |
|
1423 | pair = dataOut.pairsList[pairsIndexList[i]] | |
1391 | ccf = numpy.average(dataOut.data_cspc[pairsIndexList[i],:,:],axis=0) |
|
1424 | ccf = numpy.average(dataOut.data_cspc[pairsIndexList[i],:,:],axis=0) | |
1392 | powa = numpy.average(dataOut.data_spc[pair[0],:,:],axis=0) |
|
1425 | powa = numpy.average(dataOut.data_spc[pair[0],:,:],axis=0) | |
1393 | powb = numpy.average(dataOut.data_spc[pair[1],:,:],axis=0) |
|
1426 | powb = numpy.average(dataOut.data_spc[pair[1],:,:],axis=0) | |
1394 | avgcoherenceComplex = ccf/numpy.sqrt(powa*powb) |
|
1427 | avgcoherenceComplex = ccf/numpy.sqrt(powa*powb) | |
1395 | phase = numpy.arctan2(avgcoherenceComplex.imag, avgcoherenceComplex.real)*180/numpy.pi |
|
1428 | phase = numpy.arctan2(avgcoherenceComplex.imag, avgcoherenceComplex.real)*180/numpy.pi | |
1396 |
|
1429 | |||
1397 | #print "Phase %d%d" %(pair[0], pair[1]) |
|
1430 | #print "Phase %d%d" %(pair[0], pair[1]) | |
1398 | #print phase[dataOut.beacon_heiIndexList] |
|
1431 | #print phase[dataOut.beacon_heiIndexList] | |
1399 |
|
1432 | |||
1400 | phase_beacon[i] = numpy.average(phase[dataOut.beacon_heiIndexList]) |
|
1433 | phase_beacon[i] = numpy.average(phase[dataOut.beacon_heiIndexList]) | |
1401 |
|
1434 | |||
1402 | if not self.__isConfig: |
|
1435 | if not self.__isConfig: | |
1403 |
|
1436 | |||
1404 | nplots = len(pairsIndexList) |
|
1437 | nplots = len(pairsIndexList) | |
1405 |
|
1438 | |||
1406 | self.setup(id=id, |
|
1439 | self.setup(id=id, | |
1407 | nplots=nplots, |
|
1440 | nplots=nplots, | |
1408 | wintitle=wintitle, |
|
1441 | wintitle=wintitle, | |
1409 | showprofile=showprofile, |
|
1442 | showprofile=showprofile, | |
1410 | show=show) |
|
1443 | show=show) | |
1411 |
|
1444 | |||
1412 | tmin, tmax = self.getTimeLim(x, xmin, xmax) |
|
1445 | tmin, tmax = self.getTimeLim(x, xmin, xmax) | |
1413 | if ymin == None: ymin = numpy.nanmin(phase_beacon) - 10.0 |
|
1446 | if ymin == None: ymin = numpy.nanmin(phase_beacon) - 10.0 | |
1414 | if ymax == None: ymax = numpy.nanmax(phase_beacon) + 10.0 |
|
1447 | if ymax == None: ymax = numpy.nanmax(phase_beacon) + 10.0 | |
1415 |
|
1448 | |||
1416 | self.FTP_WEI = ftp_wei |
|
1449 | self.FTP_WEI = ftp_wei | |
1417 | self.EXP_CODE = exp_code |
|
1450 | self.EXP_CODE = exp_code | |
1418 | self.SUB_EXP_CODE = sub_exp_code |
|
1451 | self.SUB_EXP_CODE = sub_exp_code | |
1419 | self.PLOT_POS = plot_pos |
|
1452 | self.PLOT_POS = plot_pos | |
1420 |
|
1453 | |||
1421 | self.name = thisDatetime.strftime("%Y%m%d_%H%M%S") |
|
1454 | self.name = thisDatetime.strftime("%Y%m%d_%H%M%S") | |
1422 | self.__isConfig = True |
|
1455 | self.__isConfig = True | |
1423 |
|
1456 | |||
1424 | self.xdata = numpy.array([]) |
|
1457 | self.xdata = numpy.array([]) | |
1425 | self.ydata = numpy.array([]) |
|
1458 | self.ydata = numpy.array([]) | |
1426 |
|
1459 | |||
1427 | #open file beacon phase |
|
1460 | #open file beacon phase | |
1428 | path = '%s%03d' %(self.PREFIX, self.id) |
|
1461 | path = '%s%03d' %(self.PREFIX, self.id) | |
1429 | beacon_file = os.path.join(path,'%s.txt'%self.name) |
|
1462 | beacon_file = os.path.join(path,'%s.txt'%self.name) | |
1430 | self.filename_phase = os.path.join(figpath,beacon_file) |
|
1463 | self.filename_phase = os.path.join(figpath,beacon_file) | |
1431 | self.save_phase(self.filename_phase) |
|
1464 | #self.save_phase(self.filename_phase) | |
1432 |
|
1465 | |||
1433 |
|
1466 | |||
1434 | #store data beacon phase |
|
1467 | #store data beacon phase | |
1435 | self.save_data(self.filename_phase, phase_beacon, thisDatetime) |
|
1468 | #self.save_data(self.filename_phase, phase_beacon, thisDatetime) | |
1436 |
|
1469 | |||
1437 | self.setWinTitle(title) |
|
1470 | self.setWinTitle(title) | |
1438 |
|
1471 | |||
1439 |
|
1472 | |||
1440 | title = "Beacon Signal %s" %(thisDatetime.strftime("%Y/%m/%d %H:%M:%S")) |
|
1473 | title = "Beacon Signal %s" %(thisDatetime.strftime("%Y/%m/%d %H:%M:%S")) | |
1441 |
|
1474 | |||
1442 | legendlabels = ["pairs %d%d"%(pair[0], pair[1]) for pair in dataOut.pairsList] |
|
1475 | legendlabels = ["pairs %d%d"%(pair[0], pair[1]) for pair in dataOut.pairsList] | |
1443 |
|
1476 | |||
1444 | axes = self.axesList[0] |
|
1477 | axes = self.axesList[0] | |
1445 |
|
1478 | |||
1446 | self.xdata = numpy.hstack((self.xdata, x[0:1])) |
|
1479 | self.xdata = numpy.hstack((self.xdata, x[0:1])) | |
1447 |
|
1480 | |||
1448 | if len(self.ydata)==0: |
|
1481 | if len(self.ydata)==0: | |
1449 | self.ydata = phase_beacon.reshape(-1,1) |
|
1482 | self.ydata = phase_beacon.reshape(-1,1) | |
1450 | else: |
|
1483 | else: | |
1451 | self.ydata = numpy.hstack((self.ydata, phase_beacon.reshape(-1,1))) |
|
1484 | self.ydata = numpy.hstack((self.ydata, phase_beacon.reshape(-1,1))) | |
1452 |
|
1485 | |||
1453 |
|
1486 | |||
1454 | axes.pmultilineyaxis(x=self.xdata, y=self.ydata, |
|
1487 | axes.pmultilineyaxis(x=self.xdata, y=self.ydata, | |
1455 | xmin=tmin, xmax=tmax, ymin=ymin, ymax=ymax, |
|
1488 | xmin=tmin, xmax=tmax, ymin=ymin, ymax=ymax, | |
1456 | xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels, marker='x', markersize=8, linestyle="solid", |
|
1489 | xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels, marker='x', markersize=8, linestyle="solid", | |
1457 | XAxisAsTime=True, grid='both' |
|
1490 | XAxisAsTime=True, grid='both' | |
1458 | ) |
|
1491 | ) | |
1459 |
|
1492 | |||
1460 | self.draw() |
|
1493 | self.draw() | |
1461 |
|
1494 | |||
1462 | if save: |
|
1495 | if save: | |
1463 |
|
1496 | |||
1464 | self.counter_imagwr += 1 |
|
1497 | self.counter_imagwr += 1 | |
1465 | if (self.counter_imagwr==wr_period): |
|
1498 | if (self.counter_imagwr==wr_period): | |
1466 | if figfile == None: |
|
1499 | if figfile == None: | |
1467 | figfile = self.getFilename(name = self.name) |
|
1500 | figfile = self.getFilename(name = self.name) | |
1468 | self.saveFigure(figpath, figfile) |
|
1501 | self.saveFigure(figpath, figfile) | |
1469 |
|
1502 | |||
1470 | if ftp: |
|
1503 | if ftp: | |
1471 | #provisionalmente envia archivos en el formato de la web en tiempo real |
|
1504 | #provisionalmente envia archivos en el formato de la web en tiempo real | |
1472 | name = self.getNameToFtp(thisDatetime, self.FTP_WEI, self.EXP_CODE, self.SUB_EXP_CODE, self.PLOT_CODE, self.PLOT_POS) |
|
1505 | name = self.getNameToFtp(thisDatetime, self.FTP_WEI, self.EXP_CODE, self.SUB_EXP_CODE, self.PLOT_CODE, self.PLOT_POS) | |
1473 | path = '%s%03d' %(self.PREFIX, self.id) |
|
1506 | path = '%s%03d' %(self.PREFIX, self.id) | |
1474 | ftp_file = os.path.join(path,'ftp','%s.png'%name) |
|
1507 | ftp_file = os.path.join(path,'ftp','%s.png'%name) | |
1475 | self.saveFigure(figpath, ftp_file) |
|
1508 | self.saveFigure(figpath, ftp_file) | |
1476 | ftp_filename = os.path.join(figpath,ftp_file) |
|
1509 | ftp_filename = os.path.join(figpath,ftp_file) | |
1477 | self.sendByFTP_Thread(ftp_filename, server, folder, username, password) |
|
1510 | self.sendByFTP_Thread(ftp_filename, server, folder, username, password) | |
1478 |
|
1511 | |||
1479 | self.counter_imagwr = 0 |
|
1512 | self.counter_imagwr = 0 | |
1480 |
|
1513 | |||
1481 | if x[1] + (x[1]-x[0]) >= self.axesList[0].xmax: |
|
1514 | if x[1] + (x[1]-x[0]) >= self.axesList[0].xmax: | |
1482 | self.__isConfig = False |
|
1515 | self.__isConfig = False | |
1483 | del self.xdata |
|
1516 | del self.xdata | |
1484 | del self.ydata |
|
1517 | del self.ydata | |
1485 |
|
1518 | |||
1486 |
|
1519 | |||
1487 |
|
1520 | |||
1488 |
|
1521 | |||
1489 | class Noise(Figure): |
|
1522 | class Noise(Figure): | |
1490 |
|
1523 | |||
1491 | __isConfig = None |
|
1524 | __isConfig = None | |
1492 | __nsubplots = None |
|
1525 | __nsubplots = None | |
1493 |
|
1526 | |||
1494 | PREFIX = 'noise' |
|
1527 | PREFIX = 'noise' | |
1495 |
|
1528 | |||
1496 | def __init__(self): |
|
1529 | def __init__(self): | |
1497 |
|
1530 | |||
1498 | self.timerange = 24*60*60 |
|
1531 | self.timerange = 24*60*60 | |
1499 | self.__isConfig = False |
|
1532 | self.__isConfig = False | |
1500 | self.__nsubplots = 1 |
|
1533 | self.__nsubplots = 1 | |
1501 | self.counter_imagwr = 0 |
|
1534 | self.counter_imagwr = 0 | |
1502 | self.WIDTH = 600 |
|
1535 | self.WIDTH = 600 | |
1503 | self.HEIGHT = 300 |
|
1536 | self.HEIGHT = 300 | |
1504 | self.WIDTHPROF = 120 |
|
1537 | self.WIDTHPROF = 120 | |
1505 | self.HEIGHTPROF = 0 |
|
1538 | self.HEIGHTPROF = 0 | |
1506 | self.xdata = None |
|
1539 | self.xdata = None | |
1507 | self.ydata = None |
|
1540 | self.ydata = None | |
1508 |
|
1541 | |||
1509 | self.PLOT_CODE = 77 |
|
1542 | self.PLOT_CODE = 77 | |
1510 | self.FTP_WEI = None |
|
1543 | self.FTP_WEI = None | |
1511 | self.EXP_CODE = None |
|
1544 | self.EXP_CODE = None | |
1512 | self.SUB_EXP_CODE = None |
|
1545 | self.SUB_EXP_CODE = None | |
1513 | self.PLOT_POS = None |
|
1546 | self.PLOT_POS = None | |
1514 |
|
1547 | |||
1515 | def getSubplots(self): |
|
1548 | def getSubplots(self): | |
1516 |
|
1549 | |||
1517 | ncol = 1 |
|
1550 | ncol = 1 | |
1518 | nrow = 1 |
|
1551 | nrow = 1 | |
1519 |
|
1552 | |||
1520 | return nrow, ncol |
|
1553 | return nrow, ncol | |
1521 |
|
1554 | |||
1522 | def openfile(self, filename): |
|
1555 | def openfile(self, filename): | |
1523 | f = open(filename,'w+') |
|
1556 | f = open(filename,'w+') | |
1524 | f.write('\n\n') |
|
1557 | f.write('\n\n') | |
1525 | f.write('JICAMARCA RADIO OBSERVATORY - Noise \n') |
|
1558 | f.write('JICAMARCA RADIO OBSERVATORY - Noise \n') | |
1526 | f.write('DD MM YYYY HH MM SS Channel0 Channel1 Channel2 Channel3\n\n' ) |
|
1559 | f.write('DD MM YYYY HH MM SS Channel0 Channel1 Channel2 Channel3\n\n' ) | |
1527 | f.close() |
|
1560 | f.close() | |
1528 |
|
1561 | |||
1529 | def save_data(self, filename_phase, data, data_datetime): |
|
1562 | def save_data(self, filename_phase, data, data_datetime): | |
1530 | f=open(filename_phase,'a') |
|
1563 | f=open(filename_phase,'a') | |
1531 | timetuple_data = data_datetime.timetuple() |
|
1564 | timetuple_data = data_datetime.timetuple() | |
1532 | day = str(timetuple_data.tm_mday) |
|
1565 | day = str(timetuple_data.tm_mday) | |
1533 | month = str(timetuple_data.tm_mon) |
|
1566 | month = str(timetuple_data.tm_mon) | |
1534 | year = str(timetuple_data.tm_year) |
|
1567 | year = str(timetuple_data.tm_year) | |
1535 | hour = str(timetuple_data.tm_hour) |
|
1568 | hour = str(timetuple_data.tm_hour) | |
1536 | minute = str(timetuple_data.tm_min) |
|
1569 | minute = str(timetuple_data.tm_min) | |
1537 | second = str(timetuple_data.tm_sec) |
|
1570 | second = str(timetuple_data.tm_sec) | |
1538 | f.write(day+' '+month+' '+year+' '+hour+' '+minute+' '+second+' '+str(data[0])+' '+str(data[1])+' '+str(data[2])+' '+str(data[3])+'\n') |
|
1571 | f.write(day+' '+month+' '+year+' '+hour+' '+minute+' '+second+' '+str(data[0])+' '+str(data[1])+' '+str(data[2])+' '+str(data[3])+'\n') | |
1539 | f.close() |
|
1572 | f.close() | |
1540 |
|
1573 | |||
1541 |
|
1574 | |||
1542 | def setup(self, id, nplots, wintitle, showprofile=True, show=True): |
|
1575 | def setup(self, id, nplots, wintitle, showprofile=True, show=True): | |
1543 |
|
1576 | |||
1544 | self.__showprofile = showprofile |
|
1577 | self.__showprofile = showprofile | |
1545 | self.nplots = nplots |
|
1578 | self.nplots = nplots | |
1546 |
|
1579 | |||
1547 | ncolspan = 7 |
|
1580 | ncolspan = 7 | |
1548 | colspan = 6 |
|
1581 | colspan = 6 | |
1549 | self.__nsubplots = 2 |
|
1582 | self.__nsubplots = 2 | |
1550 |
|
1583 | |||
1551 | self.createFigure(id = id, |
|
1584 | self.createFigure(id = id, | |
1552 | wintitle = wintitle, |
|
1585 | wintitle = wintitle, | |
1553 | widthplot = self.WIDTH+self.WIDTHPROF, |
|
1586 | widthplot = self.WIDTH+self.WIDTHPROF, | |
1554 | heightplot = self.HEIGHT+self.HEIGHTPROF, |
|
1587 | heightplot = self.HEIGHT+self.HEIGHTPROF, | |
1555 | show=show) |
|
1588 | show=show) | |
1556 |
|
1589 | |||
1557 | nrow, ncol = self.getSubplots() |
|
1590 | nrow, ncol = self.getSubplots() | |
1558 |
|
1591 | |||
1559 | self.addAxes(nrow, ncol*ncolspan, 0, 0, colspan, 1) |
|
1592 | self.addAxes(nrow, ncol*ncolspan, 0, 0, colspan, 1) | |
1560 |
|
1593 | |||
1561 |
|
1594 | |||
1562 | def run(self, dataOut, id, wintitle="", channelList=None, showprofile='True', |
|
1595 | def run(self, dataOut, id, wintitle="", channelList=None, showprofile='True', | |
1563 | xmin=None, xmax=None, ymin=None, ymax=None, |
|
1596 | xmin=None, xmax=None, ymin=None, ymax=None, | |
1564 | timerange=None, |
|
1597 | timerange=None, | |
1565 | save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1, |
|
1598 | save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1, | |
1566 | server=None, folder=None, username=None, password=None, |
|
1599 | server=None, folder=None, username=None, password=None, | |
1567 | ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0): |
|
1600 | ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0): | |
1568 |
|
1601 | |||
1569 | if channelList == None: |
|
1602 | if channelList == None: | |
1570 | channelIndexList = dataOut.channelIndexList |
|
1603 | channelIndexList = dataOut.channelIndexList | |
1571 | channelList = dataOut.channelList |
|
1604 | channelList = dataOut.channelList | |
1572 | else: |
|
1605 | else: | |
1573 | channelIndexList = [] |
|
1606 | channelIndexList = [] | |
1574 | for channel in channelList: |
|
1607 | for channel in channelList: | |
1575 | if channel not in dataOut.channelList: |
|
1608 | if channel not in dataOut.channelList: | |
1576 | raise ValueError, "Channel %d is not in dataOut.channelList" |
|
1609 | raise ValueError, "Channel %d is not in dataOut.channelList" | |
1577 | channelIndexList.append(dataOut.channelList.index(channel)) |
|
1610 | channelIndexList.append(dataOut.channelList.index(channel)) | |
1578 |
|
1611 | |||
1579 | if timerange != None: |
|
1612 | if timerange != None: | |
1580 | self.timerange = timerange |
|
1613 | self.timerange = timerange | |
1581 |
|
1614 | |||
1582 | tmin = None |
|
1615 | tmin = None | |
1583 | tmax = None |
|
1616 | tmax = None | |
1584 | x = dataOut.getTimeRange() |
|
1617 | x = dataOut.getTimeRange() | |
1585 | y = dataOut.getHeiRange() |
|
1618 | y = dataOut.getHeiRange() | |
1586 | factor = dataOut.normFactor |
|
1619 | factor = dataOut.normFactor | |
1587 | noise = dataOut.getNoise()/factor |
|
1620 | noise = dataOut.getNoise()/factor | |
1588 | noisedB = 10*numpy.log10(noise) |
|
1621 | noisedB = 10*numpy.log10(noise) | |
1589 |
|
1622 | |||
1590 | #thisDatetime = dataOut.datatime |
|
1623 | #thisDatetime = dataOut.datatime | |
1591 | thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[1]) |
|
1624 | thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[1]) | |
1592 | title = wintitle + " Noise" # : %s" %(thisDatetime.strftime("%d-%b-%Y")) |
|
1625 | title = wintitle + " Noise" # : %s" %(thisDatetime.strftime("%d-%b-%Y")) | |
1593 | xlabel = "" |
|
1626 | xlabel = "" | |
1594 | ylabel = "Intensity (dB)" |
|
1627 | ylabel = "Intensity (dB)" | |
1595 |
|
1628 | |||
1596 | if not self.__isConfig: |
|
1629 | if not self.__isConfig: | |
1597 |
|
1630 | |||
1598 | nplots = 1 |
|
1631 | nplots = 1 | |
1599 |
|
1632 | |||
1600 | self.setup(id=id, |
|
1633 | self.setup(id=id, | |
1601 | nplots=nplots, |
|
1634 | nplots=nplots, | |
1602 | wintitle=wintitle, |
|
1635 | wintitle=wintitle, | |
1603 | showprofile=showprofile, |
|
1636 | showprofile=showprofile, | |
1604 | show=show) |
|
1637 | show=show) | |
1605 |
|
1638 | |||
1606 | tmin, tmax = self.getTimeLim(x, xmin, xmax) |
|
1639 | tmin, tmax = self.getTimeLim(x, xmin, xmax) | |
1607 | if ymin == None: ymin = numpy.nanmin(noisedB) - 10.0 |
|
1640 | if ymin == None: ymin = numpy.nanmin(noisedB) - 10.0 | |
1608 | if ymax == None: ymax = numpy.nanmax(noisedB) + 10.0 |
|
1641 | if ymax == None: ymax = numpy.nanmax(noisedB) + 10.0 | |
1609 |
|
1642 | |||
1610 | self.FTP_WEI = ftp_wei |
|
1643 | self.FTP_WEI = ftp_wei | |
1611 | self.EXP_CODE = exp_code |
|
1644 | self.EXP_CODE = exp_code | |
1612 | self.SUB_EXP_CODE = sub_exp_code |
|
1645 | self.SUB_EXP_CODE = sub_exp_code | |
1613 | self.PLOT_POS = plot_pos |
|
1646 | self.PLOT_POS = plot_pos | |
1614 |
|
1647 | |||
1615 |
|
1648 | |||
1616 | self.name = thisDatetime.strftime("%Y%m%d_%H%M%S") |
|
1649 | self.name = thisDatetime.strftime("%Y%m%d_%H%M%S") | |
1617 | self.__isConfig = True |
|
1650 | self.__isConfig = True | |
1618 |
|
1651 | |||
1619 | self.xdata = numpy.array([]) |
|
1652 | self.xdata = numpy.array([]) | |
1620 | self.ydata = numpy.array([]) |
|
1653 | self.ydata = numpy.array([]) | |
1621 |
|
1654 | |||
1622 | #open file beacon phase |
|
1655 | #open file beacon phase | |
1623 | path = '%s%03d' %(self.PREFIX, self.id) |
|
1656 | path = '%s%03d' %(self.PREFIX, self.id) | |
1624 | noise_file = os.path.join(path,'%s.txt'%self.name) |
|
1657 | noise_file = os.path.join(path,'%s.txt'%self.name) | |
1625 | self.filename_noise = os.path.join(figpath,noise_file) |
|
1658 | self.filename_noise = os.path.join(figpath,noise_file) | |
1626 | self.openfile(self.filename_noise) |
|
1659 | self.openfile(self.filename_noise) | |
1627 |
|
1660 | |||
1628 |
|
1661 | |||
1629 | #store data beacon phase |
|
1662 | #store data beacon phase | |
1630 | self.save_data(self.filename_noise, noisedB, thisDatetime) |
|
1663 | self.save_data(self.filename_noise, noisedB, thisDatetime) | |
1631 |
|
1664 | |||
1632 |
|
1665 | |||
1633 | self.setWinTitle(title) |
|
1666 | self.setWinTitle(title) | |
1634 |
|
1667 | |||
1635 |
|
1668 | |||
1636 | title = "Noise %s" %(thisDatetime.strftime("%Y/%m/%d %H:%M:%S")) |
|
1669 | title = "Noise %s" %(thisDatetime.strftime("%Y/%m/%d %H:%M:%S")) | |
1637 |
|
1670 | |||
1638 | legendlabels = ["channel %d"%(idchannel+1) for idchannel in channelList] |
|
1671 | legendlabels = ["channel %d"%(idchannel+1) for idchannel in channelList] | |
1639 | axes = self.axesList[0] |
|
1672 | axes = self.axesList[0] | |
1640 |
|
1673 | |||
1641 | self.xdata = numpy.hstack((self.xdata, x[0:1])) |
|
1674 | self.xdata = numpy.hstack((self.xdata, x[0:1])) | |
1642 |
|
1675 | |||
1643 | if len(self.ydata)==0: |
|
1676 | if len(self.ydata)==0: | |
1644 | self.ydata = noisedB[channelIndexList].reshape(-1,1) |
|
1677 | self.ydata = noisedB[channelIndexList].reshape(-1,1) | |
1645 | else: |
|
1678 | else: | |
1646 | self.ydata = numpy.hstack((self.ydata, noisedB[channelIndexList].reshape(-1,1))) |
|
1679 | self.ydata = numpy.hstack((self.ydata, noisedB[channelIndexList].reshape(-1,1))) | |
1647 |
|
1680 | |||
1648 |
|
1681 | |||
1649 | axes.pmultilineyaxis(x=self.xdata, y=self.ydata, |
|
1682 | axes.pmultilineyaxis(x=self.xdata, y=self.ydata, | |
1650 | xmin=tmin, xmax=tmax, ymin=ymin, ymax=ymax, |
|
1683 | xmin=tmin, xmax=tmax, ymin=ymin, ymax=ymax, | |
1651 | xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels, marker='x', markersize=8, linestyle="solid", |
|
1684 | xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels, marker='x', markersize=8, linestyle="solid", | |
1652 | XAxisAsTime=True, grid='both' |
|
1685 | XAxisAsTime=True, grid='both' | |
1653 | ) |
|
1686 | ) | |
1654 |
|
1687 | |||
1655 | self.draw() |
|
1688 | self.draw() | |
1656 |
|
1689 | |||
1657 | # if save: |
|
1690 | # if save: | |
1658 | # |
|
1691 | # | |
1659 | # if figfile == None: |
|
1692 | # if figfile == None: | |
1660 | # figfile = self.getFilename(name = self.name) |
|
1693 | # figfile = self.getFilename(name = self.name) | |
1661 | # |
|
1694 | # | |
1662 | # self.saveFigure(figpath, figfile) |
|
1695 | # self.saveFigure(figpath, figfile) | |
1663 |
|
1696 | |||
1664 | if save: |
|
1697 | if save: | |
1665 |
|
1698 | |||
1666 | self.counter_imagwr += 1 |
|
1699 | self.counter_imagwr += 1 | |
1667 | if (self.counter_imagwr==wr_period): |
|
1700 | if (self.counter_imagwr==wr_period): | |
1668 | if figfile == None: |
|
1701 | if figfile == None: | |
1669 | figfile = self.getFilename(name = self.name) |
|
1702 | figfile = self.getFilename(name = self.name) | |
1670 | self.saveFigure(figpath, figfile) |
|
1703 | self.saveFigure(figpath, figfile) | |
1671 |
|
1704 | |||
1672 | if ftp: |
|
1705 | if ftp: | |
1673 | #provisionalmente envia archivos en el formato de la web en tiempo real |
|
1706 | #provisionalmente envia archivos en el formato de la web en tiempo real | |
1674 | name = self.getNameToFtp(thisDatetime, self.FTP_WEI, self.EXP_CODE, self.SUB_EXP_CODE, self.PLOT_CODE, self.PLOT_POS) |
|
1707 | name = self.getNameToFtp(thisDatetime, self.FTP_WEI, self.EXP_CODE, self.SUB_EXP_CODE, self.PLOT_CODE, self.PLOT_POS) | |
1675 | path = '%s%03d' %(self.PREFIX, self.id) |
|
1708 | path = '%s%03d' %(self.PREFIX, self.id) | |
1676 | ftp_file = os.path.join(path,'ftp','%s.png'%name) |
|
1709 | ftp_file = os.path.join(path,'ftp','%s.png'%name) | |
1677 | self.saveFigure(figpath, ftp_file) |
|
1710 | self.saveFigure(figpath, ftp_file) | |
1678 | ftp_filename = os.path.join(figpath,ftp_file) |
|
1711 | ftp_filename = os.path.join(figpath,ftp_file) | |
1679 | self.sendByFTP_Thread(ftp_filename, server, folder, username, password) |
|
1712 | self.sendByFTP_Thread(ftp_filename, server, folder, username, password) | |
1680 | self.counter_imagwr = 0 |
|
1713 | self.counter_imagwr = 0 | |
1681 |
|
1714 | |||
1682 | self.counter_imagwr = 0 |
|
1715 | self.counter_imagwr = 0 | |
1683 |
|
1716 | |||
1684 | if x[1] + (x[1]-x[0]) >= self.axesList[0].xmax: |
|
1717 | if x[1] + (x[1]-x[0]) >= self.axesList[0].xmax: | |
1685 | self.__isConfig = False |
|
1718 | self.__isConfig = False | |
1686 | del self.xdata |
|
1719 | del self.xdata | |
1687 | del self.ydata |
|
1720 | del self.ydata | |
1688 |
|
1721 | |||
1689 |
|
1722 | |||
1690 | class SpectraHeisScope(Figure): |
|
1723 | class SpectraHeisScope(Figure): | |
1691 |
|
1724 | |||
1692 |
|
1725 | |||
1693 | __isConfig = None |
|
1726 | __isConfig = None | |
1694 | __nsubplots = None |
|
1727 | __nsubplots = None | |
1695 |
|
1728 | |||
1696 | WIDTHPROF = None |
|
1729 | WIDTHPROF = None | |
1697 | HEIGHTPROF = None |
|
1730 | HEIGHTPROF = None | |
1698 | PREFIX = 'spc' |
|
1731 | PREFIX = 'spc' | |
1699 |
|
1732 | |||
1700 | def __init__(self): |
|
1733 | def __init__(self): | |
1701 |
|
1734 | |||
1702 | self.__isConfig = False |
|
1735 | self.__isConfig = False | |
1703 | self.__nsubplots = 1 |
|
1736 | self.__nsubplots = 1 | |
1704 |
|
1737 | |||
1705 | self.WIDTH = 230 |
|
1738 | self.WIDTH = 230 | |
1706 | self.HEIGHT = 250 |
|
1739 | self.HEIGHT = 250 | |
1707 | self.WIDTHPROF = 120 |
|
1740 | self.WIDTHPROF = 120 | |
1708 | self.HEIGHTPROF = 0 |
|
1741 | self.HEIGHTPROF = 0 | |
1709 | self.counter_imagwr = 0 |
|
1742 | self.counter_imagwr = 0 | |
1710 |
|
1743 | |||
1711 | def getSubplots(self): |
|
1744 | def getSubplots(self): | |
1712 |
|
1745 | |||
1713 | ncol = int(numpy.sqrt(self.nplots)+0.9) |
|
1746 | ncol = int(numpy.sqrt(self.nplots)+0.9) | |
1714 | nrow = int(self.nplots*1./ncol + 0.9) |
|
1747 | nrow = int(self.nplots*1./ncol + 0.9) | |
1715 |
|
1748 | |||
1716 | return nrow, ncol |
|
1749 | return nrow, ncol | |
1717 |
|
1750 | |||
1718 | def setup(self, id, nplots, wintitle, show): |
|
1751 | def setup(self, id, nplots, wintitle, show): | |
1719 |
|
1752 | |||
1720 | showprofile = False |
|
1753 | showprofile = False | |
1721 | self.__showprofile = showprofile |
|
1754 | self.__showprofile = showprofile | |
1722 | self.nplots = nplots |
|
1755 | self.nplots = nplots | |
1723 |
|
1756 | |||
1724 | ncolspan = 1 |
|
1757 | ncolspan = 1 | |
1725 | colspan = 1 |
|
1758 | colspan = 1 | |
1726 | if showprofile: |
|
1759 | if showprofile: | |
1727 | ncolspan = 3 |
|
1760 | ncolspan = 3 | |
1728 | colspan = 2 |
|
1761 | colspan = 2 | |
1729 | self.__nsubplots = 2 |
|
1762 | self.__nsubplots = 2 | |
1730 |
|
1763 | |||
1731 | self.createFigure(id = id, |
|
1764 | self.createFigure(id = id, | |
1732 | wintitle = wintitle, |
|
1765 | wintitle = wintitle, | |
1733 | widthplot = self.WIDTH + self.WIDTHPROF, |
|
1766 | widthplot = self.WIDTH + self.WIDTHPROF, | |
1734 | heightplot = self.HEIGHT + self.HEIGHTPROF, |
|
1767 | heightplot = self.HEIGHT + self.HEIGHTPROF, | |
1735 | show = show) |
|
1768 | show = show) | |
1736 |
|
1769 | |||
1737 | nrow, ncol = self.getSubplots() |
|
1770 | nrow, ncol = self.getSubplots() | |
1738 |
|
1771 | |||
1739 | counter = 0 |
|
1772 | counter = 0 | |
1740 | for y in range(nrow): |
|
1773 | for y in range(nrow): | |
1741 | for x in range(ncol): |
|
1774 | for x in range(ncol): | |
1742 |
|
1775 | |||
1743 | if counter >= self.nplots: |
|
1776 | if counter >= self.nplots: | |
1744 | break |
|
1777 | break | |
1745 |
|
1778 | |||
1746 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1) |
|
1779 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1) | |
1747 |
|
1780 | |||
1748 | if showprofile: |
|
1781 | if showprofile: | |
1749 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1) |
|
1782 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1) | |
1750 |
|
1783 | |||
1751 | counter += 1 |
|
1784 | counter += 1 | |
1752 |
|
1785 | |||
1753 |
|
1786 | |||
1754 | def run(self, dataOut, id, wintitle="", channelList=None, |
|
1787 | def run(self, dataOut, id, wintitle="", channelList=None, | |
1755 | xmin=None, xmax=None, ymin=None, ymax=None, save=False, |
|
1788 | xmin=None, xmax=None, ymin=None, ymax=None, save=False, | |
1756 | figpath='./', figfile=None, ftp=False, wr_period=1, show=True, |
|
1789 | figpath='./', figfile=None, ftp=False, wr_period=1, show=True, | |
1757 | server=None, folder=None, username=None, password=None): |
|
1790 | server=None, folder=None, username=None, password=None): | |
1758 |
|
1791 | |||
1759 | """ |
|
1792 | """ | |
1760 |
|
1793 | |||
1761 | Input: |
|
1794 | Input: | |
1762 | dataOut : |
|
1795 | dataOut : | |
1763 | id : |
|
1796 | id : | |
1764 | wintitle : |
|
1797 | wintitle : | |
1765 | channelList : |
|
1798 | channelList : | |
1766 | xmin : None, |
|
1799 | xmin : None, | |
1767 | xmax : None, |
|
1800 | xmax : None, | |
1768 | ymin : None, |
|
1801 | ymin : None, | |
1769 | ymax : None, |
|
1802 | ymax : None, | |
1770 | """ |
|
1803 | """ | |
1771 |
|
1804 | |||
1772 | if dataOut.realtime: |
|
1805 | if dataOut.realtime: | |
1773 | if not(isRealtime(utcdatatime = dataOut.utctime)): |
|
1806 | if not(isRealtime(utcdatatime = dataOut.utctime)): | |
1774 | print 'Skipping this plot function' |
|
1807 | print 'Skipping this plot function' | |
1775 | return |
|
1808 | return | |
1776 |
|
1809 | |||
1777 | if channelList == None: |
|
1810 | if channelList == None: | |
1778 | channelIndexList = dataOut.channelIndexList |
|
1811 | channelIndexList = dataOut.channelIndexList | |
1779 | else: |
|
1812 | else: | |
1780 | channelIndexList = [] |
|
1813 | channelIndexList = [] | |
1781 | for channel in channelList: |
|
1814 | for channel in channelList: | |
1782 | if channel not in dataOut.channelList: |
|
1815 | if channel not in dataOut.channelList: | |
1783 | raise ValueError, "Channel %d is not in dataOut.channelList" |
|
1816 | raise ValueError, "Channel %d is not in dataOut.channelList" | |
1784 | channelIndexList.append(dataOut.channelList.index(channel)) |
|
1817 | channelIndexList.append(dataOut.channelList.index(channel)) | |
1785 |
|
1818 | |||
1786 | # x = dataOut.heightList |
|
1819 | # x = dataOut.heightList | |
1787 | c = 3E8 |
|
1820 | c = 3E8 | |
1788 | deltaHeight = dataOut.heightList[1] - dataOut.heightList[0] |
|
1821 | deltaHeight = dataOut.heightList[1] - dataOut.heightList[0] | |
1789 | #deberia cambiar para el caso de 1Mhz y 100KHz |
|
1822 | #deberia cambiar para el caso de 1Mhz y 100KHz | |
1790 | x = numpy.arange(-1*dataOut.nHeights/2.,dataOut.nHeights/2.)*(c/(2*deltaHeight*dataOut.nHeights*1000)) |
|
1823 | x = numpy.arange(-1*dataOut.nHeights/2.,dataOut.nHeights/2.)*(c/(2*deltaHeight*dataOut.nHeights*1000)) | |
1791 | #para 1Mhz descomentar la siguiente linea |
|
1824 | #para 1Mhz descomentar la siguiente linea | |
1792 | #x= x/(10000.0) |
|
1825 | #x= x/(10000.0) | |
1793 | # y = dataOut.data[channelIndexList,:] * numpy.conjugate(dataOut.data[channelIndexList,:]) |
|
1826 | # y = dataOut.data[channelIndexList,:] * numpy.conjugate(dataOut.data[channelIndexList,:]) | |
1794 | # y = y.real |
|
1827 | # y = y.real | |
1795 | datadB = 10.*numpy.log10(dataOut.data_spc) |
|
1828 | datadB = 10.*numpy.log10(dataOut.data_spc) | |
1796 | y = datadB |
|
1829 | y = datadB | |
1797 |
|
1830 | |||
1798 | #thisDatetime = dataOut.datatime |
|
1831 | #thisDatetime = dataOut.datatime | |
1799 | thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[1]) |
|
1832 | thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[1]) | |
1800 | title = wintitle + " Scope: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) |
|
1833 | title = wintitle + " Scope: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) | |
1801 | xlabel = "" |
|
1834 | xlabel = "" | |
1802 | #para 1Mhz descomentar la siguiente linea |
|
1835 | #para 1Mhz descomentar la siguiente linea | |
1803 | #xlabel = "Frequency x 10000" |
|
1836 | #xlabel = "Frequency x 10000" | |
1804 | ylabel = "Intensity (dB)" |
|
1837 | ylabel = "Intensity (dB)" | |
1805 |
|
1838 | |||
1806 | if not self.__isConfig: |
|
1839 | if not self.__isConfig: | |
1807 | nplots = len(channelIndexList) |
|
1840 | nplots = len(channelIndexList) | |
1808 |
|
1841 | |||
1809 | self.setup(id=id, |
|
1842 | self.setup(id=id, | |
1810 | nplots=nplots, |
|
1843 | nplots=nplots, | |
1811 | wintitle=wintitle, |
|
1844 | wintitle=wintitle, | |
1812 | show=show) |
|
1845 | show=show) | |
1813 |
|
1846 | |||
1814 | if xmin == None: xmin = numpy.nanmin(x) |
|
1847 | if xmin == None: xmin = numpy.nanmin(x) | |
1815 | if xmax == None: xmax = numpy.nanmax(x) |
|
1848 | if xmax == None: xmax = numpy.nanmax(x) | |
1816 | if ymin == None: ymin = numpy.nanmin(y) |
|
1849 | if ymin == None: ymin = numpy.nanmin(y) | |
1817 | if ymax == None: ymax = numpy.nanmax(y) |
|
1850 | if ymax == None: ymax = numpy.nanmax(y) | |
1818 |
|
1851 | |||
1819 | self.__isConfig = True |
|
1852 | self.__isConfig = True | |
1820 |
|
1853 | |||
1821 | self.setWinTitle(title) |
|
1854 | self.setWinTitle(title) | |
1822 |
|
1855 | |||
1823 | for i in range(len(self.axesList)): |
|
1856 | for i in range(len(self.axesList)): | |
1824 | ychannel = y[i,:] |
|
1857 | ychannel = y[i,:] | |
1825 | str_datetime = '%s %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S")) |
|
1858 | str_datetime = '%s %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S")) | |
1826 | title = "Channel %d: %4.2fdB: %s" %(i, numpy.max(ychannel), str_datetime) |
|
1859 | title = "Channel %d: %4.2fdB: %s" %(i, numpy.max(ychannel), str_datetime) | |
1827 | axes = self.axesList[i] |
|
1860 | axes = self.axesList[i] | |
1828 | axes.pline(x, ychannel, |
|
1861 | axes.pline(x, ychannel, | |
1829 | xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, |
|
1862 | xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, | |
1830 | xlabel=xlabel, ylabel=ylabel, title=title, grid='both') |
|
1863 | xlabel=xlabel, ylabel=ylabel, title=title, grid='both') | |
1831 |
|
1864 | |||
1832 |
|
1865 | |||
1833 | self.draw() |
|
1866 | self.draw() | |
1834 |
|
1867 | |||
1835 | if save: |
|
1868 | if save: | |
1836 | date = thisDatetime.strftime("%Y%m%d_%H%M%S") |
|
1869 | date = thisDatetime.strftime("%Y%m%d_%H%M%S") | |
1837 | if figfile == None: |
|
1870 | if figfile == None: | |
1838 | figfile = self.getFilename(name = date) |
|
1871 | figfile = self.getFilename(name = date) | |
1839 |
|
1872 | |||
1840 | self.saveFigure(figpath, figfile) |
|
1873 | self.saveFigure(figpath, figfile) | |
1841 |
|
1874 | |||
1842 | self.counter_imagwr += 1 |
|
1875 | self.counter_imagwr += 1 | |
1843 | if (ftp and (self.counter_imagwr==wr_period)): |
|
1876 | if (ftp and (self.counter_imagwr==wr_period)): | |
1844 | ftp_filename = os.path.join(figpath,figfile) |
|
1877 | ftp_filename = os.path.join(figpath,figfile) | |
1845 | self.sendByFTP_Thread(ftp_filename, server, folder, username, password) |
|
1878 | self.sendByFTP_Thread(ftp_filename, server, folder, username, password) | |
1846 | self.counter_imagwr = 0 |
|
1879 | self.counter_imagwr = 0 | |
1847 |
|
1880 | |||
1848 |
|
1881 | |||
1849 | class RTIfromSpectraHeis(Figure): |
|
1882 | class RTIfromSpectraHeis(Figure): | |
1850 |
|
1883 | |||
1851 | __isConfig = None |
|
1884 | __isConfig = None | |
1852 | __nsubplots = None |
|
1885 | __nsubplots = None | |
1853 |
|
1886 | |||
1854 | PREFIX = 'rtinoise' |
|
1887 | PREFIX = 'rtinoise' | |
1855 |
|
1888 | |||
1856 | def __init__(self): |
|
1889 | def __init__(self): | |
1857 |
|
1890 | |||
1858 | self.timerange = 24*60*60 |
|
1891 | self.timerange = 24*60*60 | |
1859 | self.__isConfig = False |
|
1892 | self.__isConfig = False | |
1860 | self.__nsubplots = 1 |
|
1893 | self.__nsubplots = 1 | |
1861 |
|
1894 | |||
1862 | self.WIDTH = 820 |
|
1895 | self.WIDTH = 820 | |
1863 | self.HEIGHT = 200 |
|
1896 | self.HEIGHT = 200 | |
1864 | self.WIDTHPROF = 120 |
|
1897 | self.WIDTHPROF = 120 | |
1865 | self.HEIGHTPROF = 0 |
|
1898 | self.HEIGHTPROF = 0 | |
1866 | self.counter_imagwr = 0 |
|
1899 | self.counter_imagwr = 0 | |
1867 | self.xdata = None |
|
1900 | self.xdata = None | |
1868 | self.ydata = None |
|
1901 | self.ydata = None | |
1869 |
|
1902 | |||
1870 | def getSubplots(self): |
|
1903 | def getSubplots(self): | |
1871 |
|
1904 | |||
1872 | ncol = 1 |
|
1905 | ncol = 1 | |
1873 | nrow = 1 |
|
1906 | nrow = 1 | |
1874 |
|
1907 | |||
1875 | return nrow, ncol |
|
1908 | return nrow, ncol | |
1876 |
|
1909 | |||
1877 | def setup(self, id, nplots, wintitle, showprofile=True, show=True): |
|
1910 | def setup(self, id, nplots, wintitle, showprofile=True, show=True): | |
1878 |
|
1911 | |||
1879 | self.__showprofile = showprofile |
|
1912 | self.__showprofile = showprofile | |
1880 | self.nplots = nplots |
|
1913 | self.nplots = nplots | |
1881 |
|
1914 | |||
1882 | ncolspan = 7 |
|
1915 | ncolspan = 7 | |
1883 | colspan = 6 |
|
1916 | colspan = 6 | |
1884 | self.__nsubplots = 2 |
|
1917 | self.__nsubplots = 2 | |
1885 |
|
1918 | |||
1886 | self.createFigure(id = id, |
|
1919 | self.createFigure(id = id, | |
1887 | wintitle = wintitle, |
|
1920 | wintitle = wintitle, | |
1888 | widthplot = self.WIDTH+self.WIDTHPROF, |
|
1921 | widthplot = self.WIDTH+self.WIDTHPROF, | |
1889 | heightplot = self.HEIGHT+self.HEIGHTPROF, |
|
1922 | heightplot = self.HEIGHT+self.HEIGHTPROF, | |
1890 | show = show) |
|
1923 | show = show) | |
1891 |
|
1924 | |||
1892 | nrow, ncol = self.getSubplots() |
|
1925 | nrow, ncol = self.getSubplots() | |
1893 |
|
1926 | |||
1894 | self.addAxes(nrow, ncol*ncolspan, 0, 0, colspan, 1) |
|
1927 | self.addAxes(nrow, ncol*ncolspan, 0, 0, colspan, 1) | |
1895 |
|
1928 | |||
1896 |
|
1929 | |||
1897 | def run(self, dataOut, id, wintitle="", channelList=None, showprofile='True', |
|
1930 | def run(self, dataOut, id, wintitle="", channelList=None, showprofile='True', | |
1898 | xmin=None, xmax=None, ymin=None, ymax=None, |
|
1931 | xmin=None, xmax=None, ymin=None, ymax=None, | |
1899 | timerange=None, |
|
1932 | timerange=None, | |
1900 | save=False, figpath='./', figfile=None, ftp=False, wr_period=1, show=True, |
|
1933 | save=False, figpath='./', figfile=None, ftp=False, wr_period=1, show=True, | |
1901 | server=None, folder=None, username=None, password=None): |
|
1934 | server=None, folder=None, username=None, password=None): | |
1902 |
|
1935 | |||
1903 | if channelList == None: |
|
1936 | if channelList == None: | |
1904 | channelIndexList = dataOut.channelIndexList |
|
1937 | channelIndexList = dataOut.channelIndexList | |
1905 | channelList = dataOut.channelList |
|
1938 | channelList = dataOut.channelList | |
1906 | else: |
|
1939 | else: | |
1907 | channelIndexList = [] |
|
1940 | channelIndexList = [] | |
1908 | for channel in channelList: |
|
1941 | for channel in channelList: | |
1909 | if channel not in dataOut.channelList: |
|
1942 | if channel not in dataOut.channelList: | |
1910 | raise ValueError, "Channel %d is not in dataOut.channelList" |
|
1943 | raise ValueError, "Channel %d is not in dataOut.channelList" | |
1911 | channelIndexList.append(dataOut.channelList.index(channel)) |
|
1944 | channelIndexList.append(dataOut.channelList.index(channel)) | |
1912 |
|
1945 | |||
1913 | if timerange != None: |
|
1946 | if timerange != None: | |
1914 | self.timerange = timerange |
|
1947 | self.timerange = timerange | |
1915 |
|
1948 | |||
1916 | tmin = None |
|
1949 | tmin = None | |
1917 | tmax = None |
|
1950 | tmax = None | |
1918 | x = dataOut.getTimeRange() |
|
1951 | x = dataOut.getTimeRange() | |
1919 | y = dataOut.getHeiRange() |
|
1952 | y = dataOut.getHeiRange() | |
1920 |
|
1953 | |||
1921 | #factor = 1 |
|
1954 | #factor = 1 | |
1922 | data = dataOut.data_spc#/factor |
|
1955 | data = dataOut.data_spc#/factor | |
1923 | data = numpy.average(data,axis=1) |
|
1956 | data = numpy.average(data,axis=1) | |
1924 | datadB = 10*numpy.log10(data) |
|
1957 | datadB = 10*numpy.log10(data) | |
1925 |
|
1958 | |||
1926 | # factor = dataOut.normFactor |
|
1959 | # factor = dataOut.normFactor | |
1927 | # noise = dataOut.getNoise()/factor |
|
1960 | # noise = dataOut.getNoise()/factor | |
1928 | # noisedB = 10*numpy.log10(noise) |
|
1961 | # noisedB = 10*numpy.log10(noise) | |
1929 |
|
1962 | |||
1930 | #thisDatetime = dataOut.datatime |
|
1963 | #thisDatetime = dataOut.datatime | |
1931 | thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[1]) |
|
1964 | thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[1]) | |
1932 | title = wintitle + " RTI: %s" %(thisDatetime.strftime("%d-%b-%Y")) |
|
1965 | title = wintitle + " RTI: %s" %(thisDatetime.strftime("%d-%b-%Y")) | |
1933 | xlabel = "Local Time" |
|
1966 | xlabel = "Local Time" | |
1934 | ylabel = "Intensity (dB)" |
|
1967 | ylabel = "Intensity (dB)" | |
1935 |
|
1968 | |||
1936 | if not self.__isConfig: |
|
1969 | if not self.__isConfig: | |
1937 |
|
1970 | |||
1938 | nplots = 1 |
|
1971 | nplots = 1 | |
1939 |
|
1972 | |||
1940 | self.setup(id=id, |
|
1973 | self.setup(id=id, | |
1941 | nplots=nplots, |
|
1974 | nplots=nplots, | |
1942 | wintitle=wintitle, |
|
1975 | wintitle=wintitle, | |
1943 | showprofile=showprofile, |
|
1976 | showprofile=showprofile, | |
1944 | show=show) |
|
1977 | show=show) | |
1945 |
|
1978 | |||
1946 | tmin, tmax = self.getTimeLim(x, xmin, xmax) |
|
1979 | tmin, tmax = self.getTimeLim(x, xmin, xmax) | |
1947 | if ymin == None: ymin = numpy.nanmin(datadB) |
|
1980 | if ymin == None: ymin = numpy.nanmin(datadB) | |
1948 | if ymax == None: ymax = numpy.nanmax(datadB) |
|
1981 | if ymax == None: ymax = numpy.nanmax(datadB) | |
1949 |
|
1982 | |||
1950 | self.name = thisDatetime.strftime("%Y%m%d_%H%M%S") |
|
1983 | self.name = thisDatetime.strftime("%Y%m%d_%H%M%S") | |
1951 | self.__isConfig = True |
|
1984 | self.__isConfig = True | |
1952 |
|
1985 | |||
1953 | self.xdata = numpy.array([]) |
|
1986 | self.xdata = numpy.array([]) | |
1954 | self.ydata = numpy.array([]) |
|
1987 | self.ydata = numpy.array([]) | |
1955 |
|
1988 | |||
1956 | self.setWinTitle(title) |
|
1989 | self.setWinTitle(title) | |
1957 |
|
1990 | |||
1958 |
|
1991 | |||
1959 | # title = "RTI %s" %(thisDatetime.strftime("%d-%b-%Y")) |
|
1992 | # title = "RTI %s" %(thisDatetime.strftime("%d-%b-%Y")) | |
1960 | title = "RTI - %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) |
|
1993 | title = "RTI - %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) | |
1961 |
|
1994 | |||
1962 | legendlabels = ["channel %d"%idchannel for idchannel in channelList] |
|
1995 | legendlabels = ["channel %d"%idchannel for idchannel in channelList] | |
1963 | axes = self.axesList[0] |
|
1996 | axes = self.axesList[0] | |
1964 |
|
1997 | |||
1965 | self.xdata = numpy.hstack((self.xdata, x[0:1])) |
|
1998 | self.xdata = numpy.hstack((self.xdata, x[0:1])) | |
1966 |
|
1999 | |||
1967 | if len(self.ydata)==0: |
|
2000 | if len(self.ydata)==0: | |
1968 | self.ydata = datadB[channelIndexList].reshape(-1,1) |
|
2001 | self.ydata = datadB[channelIndexList].reshape(-1,1) | |
1969 | else: |
|
2002 | else: | |
1970 | self.ydata = numpy.hstack((self.ydata, datadB[channelIndexList].reshape(-1,1))) |
|
2003 | self.ydata = numpy.hstack((self.ydata, datadB[channelIndexList].reshape(-1,1))) | |
1971 |
|
2004 | |||
1972 |
|
2005 | |||
1973 | axes.pmultilineyaxis(x=self.xdata, y=self.ydata, |
|
2006 | axes.pmultilineyaxis(x=self.xdata, y=self.ydata, | |
1974 | xmin=tmin, xmax=tmax, ymin=ymin, ymax=ymax, |
|
2007 | xmin=tmin, xmax=tmax, ymin=ymin, ymax=ymax, | |
1975 | xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels, marker='.', markersize=8, linestyle="solid", grid='both', |
|
2008 | xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels, marker='.', markersize=8, linestyle="solid", grid='both', | |
1976 | XAxisAsTime=True |
|
2009 | XAxisAsTime=True | |
1977 | ) |
|
2010 | ) | |
1978 |
|
2011 | |||
1979 | self.draw() |
|
2012 | self.draw() | |
1980 |
|
2013 | |||
1981 | if save: |
|
2014 | if save: | |
1982 |
|
2015 | |||
1983 | if figfile == None: |
|
2016 | if figfile == None: | |
1984 | figfile = self.getFilename(name = self.name) |
|
2017 | figfile = self.getFilename(name = self.name) | |
1985 |
|
2018 | |||
1986 | self.saveFigure(figpath, figfile) |
|
2019 | self.saveFigure(figpath, figfile) | |
1987 |
|
2020 | |||
1988 | self.counter_imagwr += 1 |
|
2021 | self.counter_imagwr += 1 | |
1989 | if (ftp and (self.counter_imagwr==wr_period)): |
|
2022 | if (ftp and (self.counter_imagwr==wr_period)): | |
1990 | ftp_filename = os.path.join(figpath,figfile) |
|
2023 | ftp_filename = os.path.join(figpath,figfile) | |
1991 | self.sendByFTP_Thread(ftp_filename, server, folder, username, password) |
|
2024 | self.sendByFTP_Thread(ftp_filename, server, folder, username, password) | |
1992 | self.counter_imagwr = 0 |
|
2025 | self.counter_imagwr = 0 | |
1993 |
|
2026 | |||
1994 | if x[1] + (x[1]-x[0]) >= self.axesList[0].xmax: |
|
2027 | if x[1] + (x[1]-x[0]) >= self.axesList[0].xmax: | |
1995 | self.__isConfig = False |
|
2028 | self.__isConfig = False | |
1996 | del self.xdata |
|
2029 | del self.xdata | |
1997 | del self.ydata |
|
2030 | del self.ydata | |
1998 |
|
2031 | |||
1999 |
|
2032 | |||
2000 | No newline at end of file |
|
2033 |
@@ -1,2040 +1,2044 | |||||
1 | ''' |
|
1 | ''' | |
2 |
|
2 | |||
3 | $Author: dsuarez $ |
|
3 | $Author: dsuarez $ | |
4 | $Id: Processor.py 1 2012-11-12 18:56:07Z dsuarez $ |
|
4 | $Id: Processor.py 1 2012-11-12 18:56:07Z dsuarez $ | |
5 | ''' |
|
5 | ''' | |
6 | import os |
|
6 | import os | |
7 | import numpy |
|
7 | import numpy | |
8 | import datetime |
|
8 | import datetime | |
9 | import time |
|
9 | import time | |
10 | import math |
|
10 | import math | |
11 | from jrodata import * |
|
11 | from jrodata import * | |
12 | from jrodataIO import * |
|
12 | from jrodataIO import * | |
13 | from jroplot import * |
|
13 | from jroplot import * | |
14 |
|
14 | |||
15 | try: |
|
15 | try: | |
16 | import cfunctions |
|
16 | import cfunctions | |
17 | except: |
|
17 | except: | |
18 | pass |
|
18 | pass | |
19 |
|
19 | |||
20 | class ProcessingUnit: |
|
20 | class ProcessingUnit: | |
21 |
|
21 | |||
22 | """ |
|
22 | """ | |
23 | Esta es la clase base para el procesamiento de datos. |
|
23 | Esta es la clase base para el procesamiento de datos. | |
24 |
|
24 | |||
25 | Contiene el metodo "call" para llamar operaciones. Las operaciones pueden ser: |
|
25 | Contiene el metodo "call" para llamar operaciones. Las operaciones pueden ser: | |
26 | - Metodos internos (callMethod) |
|
26 | - Metodos internos (callMethod) | |
27 | - Objetos del tipo Operation (callObject). Antes de ser llamados, estos objetos |
|
27 | - Objetos del tipo Operation (callObject). Antes de ser llamados, estos objetos | |
28 | tienen que ser agreagados con el metodo "add". |
|
28 | tienen que ser agreagados con el metodo "add". | |
29 |
|
29 | |||
30 | """ |
|
30 | """ | |
31 | # objeto de datos de entrada (Voltage, Spectra o Correlation) |
|
31 | # objeto de datos de entrada (Voltage, Spectra o Correlation) | |
32 | dataIn = None |
|
32 | dataIn = None | |
33 |
|
33 | |||
34 | # objeto de datos de entrada (Voltage, Spectra o Correlation) |
|
34 | # objeto de datos de entrada (Voltage, Spectra o Correlation) | |
35 | dataOut = None |
|
35 | dataOut = None | |
36 |
|
36 | |||
37 |
|
37 | |||
38 | objectDict = None |
|
38 | objectDict = None | |
39 |
|
39 | |||
40 | def __init__(self): |
|
40 | def __init__(self): | |
41 |
|
41 | |||
42 | self.objectDict = {} |
|
42 | self.objectDict = {} | |
43 |
|
43 | |||
44 | def init(self): |
|
44 | def init(self): | |
45 |
|
45 | |||
46 | raise ValueError, "Not implemented" |
|
46 | raise ValueError, "Not implemented" | |
47 |
|
47 | |||
48 | def addOperation(self, object, objId): |
|
48 | def addOperation(self, object, objId): | |
49 |
|
49 | |||
50 | """ |
|
50 | """ | |
51 | Agrega el objeto "object" a la lista de objetos "self.objectList" y retorna el |
|
51 | Agrega el objeto "object" a la lista de objetos "self.objectList" y retorna el | |
52 | identificador asociado a este objeto. |
|
52 | identificador asociado a este objeto. | |
53 |
|
53 | |||
54 | Input: |
|
54 | Input: | |
55 |
|
55 | |||
56 | object : objeto de la clase "Operation" |
|
56 | object : objeto de la clase "Operation" | |
57 |
|
57 | |||
58 | Return: |
|
58 | Return: | |
59 |
|
59 | |||
60 | objId : identificador del objeto, necesario para ejecutar la operacion |
|
60 | objId : identificador del objeto, necesario para ejecutar la operacion | |
61 | """ |
|
61 | """ | |
62 |
|
62 | |||
63 | self.objectDict[objId] = object |
|
63 | self.objectDict[objId] = object | |
64 |
|
64 | |||
65 | return objId |
|
65 | return objId | |
66 |
|
66 | |||
67 | def operation(self, **kwargs): |
|
67 | def operation(self, **kwargs): | |
68 |
|
68 | |||
69 | """ |
|
69 | """ | |
70 | Operacion directa sobre la data (dataOut.data). Es necesario actualizar los valores de los |
|
70 | Operacion directa sobre la data (dataOut.data). Es necesario actualizar los valores de los | |
71 | atributos del objeto dataOut |
|
71 | atributos del objeto dataOut | |
72 |
|
72 | |||
73 | Input: |
|
73 | Input: | |
74 |
|
74 | |||
75 | **kwargs : Diccionario de argumentos de la funcion a ejecutar |
|
75 | **kwargs : Diccionario de argumentos de la funcion a ejecutar | |
76 | """ |
|
76 | """ | |
77 |
|
77 | |||
78 | raise ValueError, "ImplementedError" |
|
78 | raise ValueError, "ImplementedError" | |
79 |
|
79 | |||
80 | def callMethod(self, name, **kwargs): |
|
80 | def callMethod(self, name, **kwargs): | |
81 |
|
81 | |||
82 | """ |
|
82 | """ | |
83 | Ejecuta el metodo con el nombre "name" y con argumentos **kwargs de la propia clase. |
|
83 | Ejecuta el metodo con el nombre "name" y con argumentos **kwargs de la propia clase. | |
84 |
|
84 | |||
85 | Input: |
|
85 | Input: | |
86 | name : nombre del metodo a ejecutar |
|
86 | name : nombre del metodo a ejecutar | |
87 |
|
87 | |||
88 | **kwargs : diccionario con los nombres y valores de la funcion a ejecutar. |
|
88 | **kwargs : diccionario con los nombres y valores de la funcion a ejecutar. | |
89 |
|
89 | |||
90 | """ |
|
90 | """ | |
91 | if name != 'run': |
|
91 | if name != 'run': | |
92 |
|
92 | |||
93 | if name == 'init' and self.dataIn.isEmpty(): |
|
93 | if name == 'init' and self.dataIn.isEmpty(): | |
94 | self.dataOut.flagNoData = True |
|
94 | self.dataOut.flagNoData = True | |
95 | return False |
|
95 | return False | |
96 |
|
96 | |||
97 | if name != 'init' and self.dataOut.isEmpty(): |
|
97 | if name != 'init' and self.dataOut.isEmpty(): | |
98 | return False |
|
98 | return False | |
99 |
|
99 | |||
100 | methodToCall = getattr(self, name) |
|
100 | methodToCall = getattr(self, name) | |
101 |
|
101 | |||
102 | methodToCall(**kwargs) |
|
102 | methodToCall(**kwargs) | |
103 |
|
103 | |||
104 | if name != 'run': |
|
104 | if name != 'run': | |
105 | return True |
|
105 | return True | |
106 |
|
106 | |||
107 | if self.dataOut.isEmpty(): |
|
107 | if self.dataOut.isEmpty(): | |
108 | return False |
|
108 | return False | |
109 |
|
109 | |||
110 | return True |
|
110 | return True | |
111 |
|
111 | |||
112 | def callObject(self, objId, **kwargs): |
|
112 | def callObject(self, objId, **kwargs): | |
113 |
|
113 | |||
114 | """ |
|
114 | """ | |
115 | Ejecuta la operacion asociada al identificador del objeto "objId" |
|
115 | Ejecuta la operacion asociada al identificador del objeto "objId" | |
116 |
|
116 | |||
117 | Input: |
|
117 | Input: | |
118 |
|
118 | |||
119 | objId : identificador del objeto a ejecutar |
|
119 | objId : identificador del objeto a ejecutar | |
120 |
|
120 | |||
121 | **kwargs : diccionario con los nombres y valores de la funcion a ejecutar. |
|
121 | **kwargs : diccionario con los nombres y valores de la funcion a ejecutar. | |
122 |
|
122 | |||
123 | Return: |
|
123 | Return: | |
124 |
|
124 | |||
125 | None |
|
125 | None | |
126 | """ |
|
126 | """ | |
127 |
|
127 | |||
128 | if self.dataOut.isEmpty(): |
|
128 | if self.dataOut.isEmpty(): | |
129 | return False |
|
129 | return False | |
130 |
|
130 | |||
131 | object = self.objectDict[objId] |
|
131 | object = self.objectDict[objId] | |
132 |
|
132 | |||
133 | object.run(self.dataOut, **kwargs) |
|
133 | object.run(self.dataOut, **kwargs) | |
134 |
|
134 | |||
135 | return True |
|
135 | return True | |
136 |
|
136 | |||
137 | def call(self, operationConf, **kwargs): |
|
137 | def call(self, operationConf, **kwargs): | |
138 |
|
138 | |||
139 | """ |
|
139 | """ | |
140 | Return True si ejecuta la operacion "operationConf.name" con los |
|
140 | Return True si ejecuta la operacion "operationConf.name" con los | |
141 | argumentos "**kwargs". False si la operacion no se ha ejecutado. |
|
141 | argumentos "**kwargs". False si la operacion no se ha ejecutado. | |
142 | La operacion puede ser de dos tipos: |
|
142 | La operacion puede ser de dos tipos: | |
143 |
|
143 | |||
144 | 1. Un metodo propio de esta clase: |
|
144 | 1. Un metodo propio de esta clase: | |
145 |
|
145 | |||
146 | operation.type = "self" |
|
146 | operation.type = "self" | |
147 |
|
147 | |||
148 | 2. El metodo "run" de un objeto del tipo Operation o de un derivado de ella: |
|
148 | 2. El metodo "run" de un objeto del tipo Operation o de un derivado de ella: | |
149 | operation.type = "other". |
|
149 | operation.type = "other". | |
150 |
|
150 | |||
151 | Este objeto de tipo Operation debe de haber sido agregado antes con el metodo: |
|
151 | Este objeto de tipo Operation debe de haber sido agregado antes con el metodo: | |
152 | "addOperation" e identificado con el operation.id |
|
152 | "addOperation" e identificado con el operation.id | |
153 |
|
153 | |||
154 |
|
154 | |||
155 | con el id de la operacion. |
|
155 | con el id de la operacion. | |
156 |
|
156 | |||
157 | Input: |
|
157 | Input: | |
158 |
|
158 | |||
159 | Operation : Objeto del tipo operacion con los atributos: name, type y id. |
|
159 | Operation : Objeto del tipo operacion con los atributos: name, type y id. | |
160 |
|
160 | |||
161 | """ |
|
161 | """ | |
162 |
|
162 | |||
163 | if operationConf.type == 'self': |
|
163 | if operationConf.type == 'self': | |
164 | sts = self.callMethod(operationConf.name, **kwargs) |
|
164 | sts = self.callMethod(operationConf.name, **kwargs) | |
165 |
|
165 | |||
166 | if operationConf.type == 'other': |
|
166 | if operationConf.type == 'other': | |
167 | sts = self.callObject(operationConf.id, **kwargs) |
|
167 | sts = self.callObject(operationConf.id, **kwargs) | |
168 |
|
168 | |||
169 | return sts |
|
169 | return sts | |
170 |
|
170 | |||
171 | def setInput(self, dataIn): |
|
171 | def setInput(self, dataIn): | |
172 |
|
172 | |||
173 | self.dataIn = dataIn |
|
173 | self.dataIn = dataIn | |
174 |
|
174 | |||
175 | def getOutput(self): |
|
175 | def getOutput(self): | |
176 |
|
176 | |||
177 | return self.dataOut |
|
177 | return self.dataOut | |
178 |
|
178 | |||
179 | class Operation(): |
|
179 | class Operation(): | |
180 |
|
180 | |||
181 | """ |
|
181 | """ | |
182 | Clase base para definir las operaciones adicionales que se pueden agregar a la clase ProcessingUnit |
|
182 | Clase base para definir las operaciones adicionales que se pueden agregar a la clase ProcessingUnit | |
183 | y necesiten acumular informacion previa de los datos a procesar. De preferencia usar un buffer de |
|
183 | y necesiten acumular informacion previa de los datos a procesar. De preferencia usar un buffer de | |
184 | acumulacion dentro de esta clase |
|
184 | acumulacion dentro de esta clase | |
185 |
|
185 | |||
186 | Ejemplo: Integraciones coherentes, necesita la informacion previa de los n perfiles anteriores (bufffer) |
|
186 | Ejemplo: Integraciones coherentes, necesita la informacion previa de los n perfiles anteriores (bufffer) | |
187 |
|
187 | |||
188 | """ |
|
188 | """ | |
189 |
|
189 | |||
190 | __buffer = None |
|
190 | __buffer = None | |
191 | __isConfig = False |
|
191 | __isConfig = False | |
192 |
|
192 | |||
193 | def __init__(self): |
|
193 | def __init__(self): | |
194 |
|
194 | |||
195 | pass |
|
195 | pass | |
196 |
|
196 | |||
197 | def run(self, dataIn, **kwargs): |
|
197 | def run(self, dataIn, **kwargs): | |
198 |
|
198 | |||
199 | """ |
|
199 | """ | |
200 | Realiza las operaciones necesarias sobre la dataIn.data y actualiza los atributos del objeto dataIn. |
|
200 | Realiza las operaciones necesarias sobre la dataIn.data y actualiza los atributos del objeto dataIn. | |
201 |
|
201 | |||
202 | Input: |
|
202 | Input: | |
203 |
|
203 | |||
204 | dataIn : objeto del tipo JROData |
|
204 | dataIn : objeto del tipo JROData | |
205 |
|
205 | |||
206 | Return: |
|
206 | Return: | |
207 |
|
207 | |||
208 | None |
|
208 | None | |
209 |
|
209 | |||
210 | Affected: |
|
210 | Affected: | |
211 | __buffer : buffer de recepcion de datos. |
|
211 | __buffer : buffer de recepcion de datos. | |
212 |
|
212 | |||
213 | """ |
|
213 | """ | |
214 |
|
214 | |||
215 | raise ValueError, "ImplementedError" |
|
215 | raise ValueError, "ImplementedError" | |
216 |
|
216 | |||
217 | class VoltageProc(ProcessingUnit): |
|
217 | class VoltageProc(ProcessingUnit): | |
218 |
|
218 | |||
219 |
|
219 | |||
220 | def __init__(self): |
|
220 | def __init__(self): | |
221 |
|
221 | |||
222 | self.objectDict = {} |
|
222 | self.objectDict = {} | |
223 | self.dataOut = Voltage() |
|
223 | self.dataOut = Voltage() | |
224 | self.flip = 1 |
|
224 | self.flip = 1 | |
225 |
|
225 | |||
226 | def init(self): |
|
226 | def init(self): | |
227 |
|
227 | |||
228 | self.dataOut.copy(self.dataIn) |
|
228 | self.dataOut.copy(self.dataIn) | |
229 | # No necesita copiar en cada init() los atributos de dataIn |
|
229 | # No necesita copiar en cada init() los atributos de dataIn | |
230 | # la copia deberia hacerse por cada nuevo bloque de datos |
|
230 | # la copia deberia hacerse por cada nuevo bloque de datos | |
231 |
|
231 | |||
232 | def selectChannels(self, channelList): |
|
232 | def selectChannels(self, channelList): | |
233 |
|
233 | |||
234 | channelIndexList = [] |
|
234 | channelIndexList = [] | |
235 |
|
235 | |||
236 | for channel in channelList: |
|
236 | for channel in channelList: | |
237 | index = self.dataOut.channelList.index(channel) |
|
237 | index = self.dataOut.channelList.index(channel) | |
238 | channelIndexList.append(index) |
|
238 | channelIndexList.append(index) | |
239 |
|
239 | |||
240 | self.selectChannelsByIndex(channelIndexList) |
|
240 | self.selectChannelsByIndex(channelIndexList) | |
241 |
|
241 | |||
242 | def selectChannelsByIndex(self, channelIndexList): |
|
242 | def selectChannelsByIndex(self, channelIndexList): | |
243 | """ |
|
243 | """ | |
244 | Selecciona un bloque de datos en base a canales segun el channelIndexList |
|
244 | Selecciona un bloque de datos en base a canales segun el channelIndexList | |
245 |
|
245 | |||
246 | Input: |
|
246 | Input: | |
247 | channelIndexList : lista sencilla de canales a seleccionar por ej. [2,3,7] |
|
247 | channelIndexList : lista sencilla de canales a seleccionar por ej. [2,3,7] | |
248 |
|
248 | |||
249 | Affected: |
|
249 | Affected: | |
250 | self.dataOut.data |
|
250 | self.dataOut.data | |
251 | self.dataOut.channelIndexList |
|
251 | self.dataOut.channelIndexList | |
252 | self.dataOut.nChannels |
|
252 | self.dataOut.nChannels | |
253 | self.dataOut.m_ProcessingHeader.totalSpectra |
|
253 | self.dataOut.m_ProcessingHeader.totalSpectra | |
254 | self.dataOut.systemHeaderObj.numChannels |
|
254 | self.dataOut.systemHeaderObj.numChannels | |
255 | self.dataOut.m_ProcessingHeader.blockSize |
|
255 | self.dataOut.m_ProcessingHeader.blockSize | |
256 |
|
256 | |||
257 | Return: |
|
257 | Return: | |
258 | None |
|
258 | None | |
259 | """ |
|
259 | """ | |
260 |
|
260 | |||
261 | for channelIndex in channelIndexList: |
|
261 | for channelIndex in channelIndexList: | |
262 | if channelIndex not in self.dataOut.channelIndexList: |
|
262 | if channelIndex not in self.dataOut.channelIndexList: | |
263 | print channelIndexList |
|
263 | print channelIndexList | |
264 | raise ValueError, "The value %d in channelIndexList is not valid" %channelIndex |
|
264 | raise ValueError, "The value %d in channelIndexList is not valid" %channelIndex | |
265 |
|
265 | |||
266 | nChannels = len(channelIndexList) |
|
266 | nChannels = len(channelIndexList) | |
267 |
|
267 | |||
268 | data = self.dataOut.data[channelIndexList,:] |
|
268 | data = self.dataOut.data[channelIndexList,:] | |
269 |
|
269 | |||
270 | self.dataOut.data = data |
|
270 | self.dataOut.data = data | |
271 | self.dataOut.channelList = [self.dataOut.channelList[i] for i in channelIndexList] |
|
271 | self.dataOut.channelList = [self.dataOut.channelList[i] for i in channelIndexList] | |
272 | # self.dataOut.nChannels = nChannels |
|
272 | # self.dataOut.nChannels = nChannels | |
273 |
|
273 | |||
274 | return 1 |
|
274 | return 1 | |
275 |
|
275 | |||
276 | def selectHeights(self, minHei=None, maxHei=None): |
|
276 | def selectHeights(self, minHei=None, maxHei=None): | |
277 | """ |
|
277 | """ | |
278 | Selecciona un bloque de datos en base a un grupo de valores de alturas segun el rango |
|
278 | Selecciona un bloque de datos en base a un grupo de valores de alturas segun el rango | |
279 | minHei <= height <= maxHei |
|
279 | minHei <= height <= maxHei | |
280 |
|
280 | |||
281 | Input: |
|
281 | Input: | |
282 | minHei : valor minimo de altura a considerar |
|
282 | minHei : valor minimo de altura a considerar | |
283 | maxHei : valor maximo de altura a considerar |
|
283 | maxHei : valor maximo de altura a considerar | |
284 |
|
284 | |||
285 | Affected: |
|
285 | Affected: | |
286 | Indirectamente son cambiados varios valores a travez del metodo selectHeightsByIndex |
|
286 | Indirectamente son cambiados varios valores a travez del metodo selectHeightsByIndex | |
287 |
|
287 | |||
288 | Return: |
|
288 | Return: | |
289 | 1 si el metodo se ejecuto con exito caso contrario devuelve 0 |
|
289 | 1 si el metodo se ejecuto con exito caso contrario devuelve 0 | |
290 | """ |
|
290 | """ | |
291 |
|
291 | |||
292 | if minHei == None: |
|
292 | if minHei == None: | |
293 | minHei = self.dataOut.heightList[0] |
|
293 | minHei = self.dataOut.heightList[0] | |
294 |
|
294 | |||
295 | if maxHei == None: |
|
295 | if maxHei == None: | |
296 | maxHei = self.dataOut.heightList[-1] |
|
296 | maxHei = self.dataOut.heightList[-1] | |
297 |
|
297 | |||
298 | if (minHei < self.dataOut.heightList[0]) or (minHei > maxHei): |
|
298 | if (minHei < self.dataOut.heightList[0]) or (minHei > maxHei): | |
299 | raise ValueError, "some value in (%d,%d) is not valid" % (minHei, maxHei) |
|
299 | raise ValueError, "some value in (%d,%d) is not valid" % (minHei, maxHei) | |
300 |
|
300 | |||
301 |
|
301 | |||
302 | if (maxHei > self.dataOut.heightList[-1]): |
|
302 | if (maxHei > self.dataOut.heightList[-1]): | |
303 | maxHei = self.dataOut.heightList[-1] |
|
303 | maxHei = self.dataOut.heightList[-1] | |
304 | # raise ValueError, "some value in (%d,%d) is not valid" % (minHei, maxHei) |
|
304 | # raise ValueError, "some value in (%d,%d) is not valid" % (minHei, maxHei) | |
305 |
|
305 | |||
306 | minIndex = 0 |
|
306 | minIndex = 0 | |
307 | maxIndex = 0 |
|
307 | maxIndex = 0 | |
308 | heights = self.dataOut.heightList |
|
308 | heights = self.dataOut.heightList | |
309 |
|
309 | |||
310 | inda = numpy.where(heights >= minHei) |
|
310 | inda = numpy.where(heights >= minHei) | |
311 | indb = numpy.where(heights <= maxHei) |
|
311 | indb = numpy.where(heights <= maxHei) | |
312 |
|
312 | |||
313 | try: |
|
313 | try: | |
314 | minIndex = inda[0][0] |
|
314 | minIndex = inda[0][0] | |
315 | except: |
|
315 | except: | |
316 | minIndex = 0 |
|
316 | minIndex = 0 | |
317 |
|
317 | |||
318 | try: |
|
318 | try: | |
319 | maxIndex = indb[0][-1] |
|
319 | maxIndex = indb[0][-1] | |
320 | except: |
|
320 | except: | |
321 | maxIndex = len(heights) |
|
321 | maxIndex = len(heights) | |
322 |
|
322 | |||
323 | self.selectHeightsByIndex(minIndex, maxIndex) |
|
323 | self.selectHeightsByIndex(minIndex, maxIndex) | |
324 |
|
324 | |||
325 | return 1 |
|
325 | return 1 | |
326 |
|
326 | |||
327 |
|
327 | |||
328 | def selectHeightsByIndex(self, minIndex, maxIndex): |
|
328 | def selectHeightsByIndex(self, minIndex, maxIndex): | |
329 | """ |
|
329 | """ | |
330 | Selecciona un bloque de datos en base a un grupo indices de alturas segun el rango |
|
330 | Selecciona un bloque de datos en base a un grupo indices de alturas segun el rango | |
331 | minIndex <= index <= maxIndex |
|
331 | minIndex <= index <= maxIndex | |
332 |
|
332 | |||
333 | Input: |
|
333 | Input: | |
334 | minIndex : valor de indice minimo de altura a considerar |
|
334 | minIndex : valor de indice minimo de altura a considerar | |
335 | maxIndex : valor de indice maximo de altura a considerar |
|
335 | maxIndex : valor de indice maximo de altura a considerar | |
336 |
|
336 | |||
337 | Affected: |
|
337 | Affected: | |
338 | self.dataOut.data |
|
338 | self.dataOut.data | |
339 | self.dataOut.heightList |
|
339 | self.dataOut.heightList | |
340 |
|
340 | |||
341 | Return: |
|
341 | Return: | |
342 | 1 si el metodo se ejecuto con exito caso contrario devuelve 0 |
|
342 | 1 si el metodo se ejecuto con exito caso contrario devuelve 0 | |
343 | """ |
|
343 | """ | |
344 |
|
344 | |||
345 | if (minIndex < 0) or (minIndex > maxIndex): |
|
345 | if (minIndex < 0) or (minIndex > maxIndex): | |
346 | raise ValueError, "some value in (%d,%d) is not valid" % (minIndex, maxIndex) |
|
346 | raise ValueError, "some value in (%d,%d) is not valid" % (minIndex, maxIndex) | |
347 |
|
347 | |||
348 | if (maxIndex >= self.dataOut.nHeights): |
|
348 | if (maxIndex >= self.dataOut.nHeights): | |
349 | maxIndex = self.dataOut.nHeights-1 |
|
349 | maxIndex = self.dataOut.nHeights-1 | |
350 | # raise ValueError, "some value in (%d,%d) is not valid" % (minIndex, maxIndex) |
|
350 | # raise ValueError, "some value in (%d,%d) is not valid" % (minIndex, maxIndex) | |
351 |
|
351 | |||
352 | nHeights = maxIndex - minIndex + 1 |
|
352 | nHeights = maxIndex - minIndex + 1 | |
353 |
|
353 | |||
354 | #voltage |
|
354 | #voltage | |
355 | data = self.dataOut.data[:,minIndex:maxIndex+1] |
|
355 | data = self.dataOut.data[:,minIndex:maxIndex+1] | |
356 |
|
356 | |||
357 | firstHeight = self.dataOut.heightList[minIndex] |
|
357 | firstHeight = self.dataOut.heightList[minIndex] | |
358 |
|
358 | |||
359 | self.dataOut.data = data |
|
359 | self.dataOut.data = data | |
360 | self.dataOut.heightList = self.dataOut.heightList[minIndex:maxIndex+1] |
|
360 | self.dataOut.heightList = self.dataOut.heightList[minIndex:maxIndex+1] | |
361 |
|
361 | |||
362 | return 1 |
|
362 | return 1 | |
363 |
|
363 | |||
364 |
|
364 | |||
365 | def filterByHeights(self, window): |
|
365 | def filterByHeights(self, window): | |
366 | deltaHeight = self.dataOut.heightList[1] - self.dataOut.heightList[0] |
|
366 | deltaHeight = self.dataOut.heightList[1] - self.dataOut.heightList[0] | |
367 |
|
367 | |||
368 | if window == None: |
|
368 | if window == None: | |
369 | window = (self.dataOut.radarControllerHeaderObj.txA/self.dataOut.radarControllerHeaderObj.nBaud) / deltaHeight |
|
369 | window = (self.dataOut.radarControllerHeaderObj.txA/self.dataOut.radarControllerHeaderObj.nBaud) / deltaHeight | |
370 |
|
370 | |||
371 | newdelta = deltaHeight * window |
|
371 | newdelta = deltaHeight * window | |
372 | r = self.dataOut.data.shape[1] % window |
|
372 | r = self.dataOut.data.shape[1] % window | |
373 | buffer = self.dataOut.data[:,0:self.dataOut.data.shape[1]-r] |
|
373 | buffer = self.dataOut.data[:,0:self.dataOut.data.shape[1]-r] | |
374 | buffer = buffer.reshape(self.dataOut.data.shape[0],self.dataOut.data.shape[1]/window,window) |
|
374 | buffer = buffer.reshape(self.dataOut.data.shape[0],self.dataOut.data.shape[1]/window,window) | |
375 | buffer = numpy.sum(buffer,2) |
|
375 | buffer = numpy.sum(buffer,2) | |
376 | self.dataOut.data = buffer |
|
376 | self.dataOut.data = buffer | |
377 | self.dataOut.heightList = numpy.arange(self.dataOut.heightList[0],newdelta*(self.dataOut.nHeights-r)/window,newdelta) |
|
377 | self.dataOut.heightList = numpy.arange(self.dataOut.heightList[0],newdelta*(self.dataOut.nHeights-r)/window,newdelta) | |
378 | self.dataOut.windowOfFilter = window |
|
378 | self.dataOut.windowOfFilter = window | |
379 |
|
379 | |||
380 | def deFlip(self): |
|
380 | def deFlip(self): | |
381 | self.dataOut.data *= self.flip |
|
381 | self.dataOut.data *= self.flip | |
382 | self.flip *= -1. |
|
382 | self.flip *= -1. | |
383 |
|
383 | |||
384 | def setRadarFrequency(self, frequency=None): |
|
384 | def setRadarFrequency(self, frequency=None): | |
385 | if frequency != None: |
|
385 | if frequency != None: | |
386 | self.dataOut.frequency = frequency |
|
386 | self.dataOut.frequency = frequency | |
387 |
|
387 | |||
388 | return 1 |
|
388 | return 1 | |
389 |
|
389 | |||
390 | class CohInt(Operation): |
|
390 | class CohInt(Operation): | |
391 |
|
391 | |||
392 | __isConfig = False |
|
392 | __isConfig = False | |
393 |
|
393 | |||
394 | __profIndex = 0 |
|
394 | __profIndex = 0 | |
395 | __withOverapping = False |
|
395 | __withOverapping = False | |
396 |
|
396 | |||
397 | __byTime = False |
|
397 | __byTime = False | |
398 | __initime = None |
|
398 | __initime = None | |
399 | __lastdatatime = None |
|
399 | __lastdatatime = None | |
400 | __integrationtime = None |
|
400 | __integrationtime = None | |
401 |
|
401 | |||
402 | __buffer = None |
|
402 | __buffer = None | |
403 |
|
403 | |||
404 | __dataReady = False |
|
404 | __dataReady = False | |
405 |
|
405 | |||
406 | n = None |
|
406 | n = None | |
407 |
|
407 | |||
408 |
|
408 | |||
409 | def __init__(self): |
|
409 | def __init__(self): | |
410 |
|
410 | |||
411 | self.__isConfig = False |
|
411 | self.__isConfig = False | |
412 |
|
412 | |||
413 | def setup(self, n=None, timeInterval=None, overlapping=False): |
|
413 | def setup(self, n=None, timeInterval=None, overlapping=False): | |
414 | """ |
|
414 | """ | |
415 | Set the parameters of the integration class. |
|
415 | Set the parameters of the integration class. | |
416 |
|
416 | |||
417 | Inputs: |
|
417 | Inputs: | |
418 |
|
418 | |||
419 | n : Number of coherent integrations |
|
419 | n : Number of coherent integrations | |
420 | timeInterval : Time of integration. If the parameter "n" is selected this one does not work |
|
420 | timeInterval : Time of integration. If the parameter "n" is selected this one does not work | |
421 | overlapping : |
|
421 | overlapping : | |
422 |
|
422 | |||
423 | """ |
|
423 | """ | |
424 |
|
424 | |||
425 | self.__initime = None |
|
425 | self.__initime = None | |
426 | self.__lastdatatime = 0 |
|
426 | self.__lastdatatime = 0 | |
427 | self.__buffer = None |
|
427 | self.__buffer = None | |
428 | self.__dataReady = False |
|
428 | self.__dataReady = False | |
429 |
|
429 | |||
430 |
|
430 | |||
431 | if n == None and timeInterval == None: |
|
431 | if n == None and timeInterval == None: | |
432 | raise ValueError, "n or timeInterval should be specified ..." |
|
432 | raise ValueError, "n or timeInterval should be specified ..." | |
433 |
|
433 | |||
434 | if n != None: |
|
434 | if n != None: | |
435 | self.n = n |
|
435 | self.n = n | |
436 | self.__byTime = False |
|
436 | self.__byTime = False | |
437 | else: |
|
437 | else: | |
438 | self.__integrationtime = timeInterval * 60. #if (type(timeInterval)!=integer) -> change this line |
|
438 | self.__integrationtime = timeInterval * 60. #if (type(timeInterval)!=integer) -> change this line | |
439 | self.n = 9999 |
|
439 | self.n = 9999 | |
440 | self.__byTime = True |
|
440 | self.__byTime = True | |
441 |
|
441 | |||
442 | if overlapping: |
|
442 | if overlapping: | |
443 | self.__withOverapping = True |
|
443 | self.__withOverapping = True | |
444 | self.__buffer = None |
|
444 | self.__buffer = None | |
445 | else: |
|
445 | else: | |
446 | self.__withOverapping = False |
|
446 | self.__withOverapping = False | |
447 | self.__buffer = 0 |
|
447 | self.__buffer = 0 | |
448 |
|
448 | |||
449 | self.__profIndex = 0 |
|
449 | self.__profIndex = 0 | |
450 |
|
450 | |||
451 | def putData(self, data): |
|
451 | def putData(self, data): | |
452 |
|
452 | |||
453 | """ |
|
453 | """ | |
454 | Add a profile to the __buffer and increase in one the __profileIndex |
|
454 | Add a profile to the __buffer and increase in one the __profileIndex | |
455 |
|
455 | |||
456 | """ |
|
456 | """ | |
457 |
|
457 | |||
458 | if not self.__withOverapping: |
|
458 | if not self.__withOverapping: | |
459 | self.__buffer += data.copy() |
|
459 | self.__buffer += data.copy() | |
460 | self.__profIndex += 1 |
|
460 | self.__profIndex += 1 | |
461 | return |
|
461 | return | |
462 |
|
462 | |||
463 | #Overlapping data |
|
463 | #Overlapping data | |
464 | nChannels, nHeis = data.shape |
|
464 | nChannels, nHeis = data.shape | |
465 | data = numpy.reshape(data, (1, nChannels, nHeis)) |
|
465 | data = numpy.reshape(data, (1, nChannels, nHeis)) | |
466 |
|
466 | |||
467 | #If the buffer is empty then it takes the data value |
|
467 | #If the buffer is empty then it takes the data value | |
468 | if self.__buffer == None: |
|
468 | if self.__buffer == None: | |
469 | self.__buffer = data |
|
469 | self.__buffer = data | |
470 | self.__profIndex += 1 |
|
470 | self.__profIndex += 1 | |
471 | return |
|
471 | return | |
472 |
|
472 | |||
473 | #If the buffer length is lower than n then stakcing the data value |
|
473 | #If the buffer length is lower than n then stakcing the data value | |
474 | if self.__profIndex < self.n: |
|
474 | if self.__profIndex < self.n: | |
475 | self.__buffer = numpy.vstack((self.__buffer, data)) |
|
475 | self.__buffer = numpy.vstack((self.__buffer, data)) | |
476 | self.__profIndex += 1 |
|
476 | self.__profIndex += 1 | |
477 | return |
|
477 | return | |
478 |
|
478 | |||
479 | #If the buffer length is equal to n then replacing the last buffer value with the data value |
|
479 | #If the buffer length is equal to n then replacing the last buffer value with the data value | |
480 | self.__buffer = numpy.roll(self.__buffer, -1, axis=0) |
|
480 | self.__buffer = numpy.roll(self.__buffer, -1, axis=0) | |
481 | self.__buffer[self.n-1] = data |
|
481 | self.__buffer[self.n-1] = data | |
482 | self.__profIndex = self.n |
|
482 | self.__profIndex = self.n | |
483 | return |
|
483 | return | |
484 |
|
484 | |||
485 |
|
485 | |||
486 | def pushData(self): |
|
486 | def pushData(self): | |
487 | """ |
|
487 | """ | |
488 | Return the sum of the last profiles and the profiles used in the sum. |
|
488 | Return the sum of the last profiles and the profiles used in the sum. | |
489 |
|
489 | |||
490 | Affected: |
|
490 | Affected: | |
491 |
|
491 | |||
492 | self.__profileIndex |
|
492 | self.__profileIndex | |
493 |
|
493 | |||
494 | """ |
|
494 | """ | |
495 |
|
495 | |||
496 | if not self.__withOverapping: |
|
496 | if not self.__withOverapping: | |
497 | data = self.__buffer |
|
497 | data = self.__buffer | |
498 | n = self.__profIndex |
|
498 | n = self.__profIndex | |
499 |
|
499 | |||
500 | self.__buffer = 0 |
|
500 | self.__buffer = 0 | |
501 | self.__profIndex = 0 |
|
501 | self.__profIndex = 0 | |
502 |
|
502 | |||
503 | return data, n |
|
503 | return data, n | |
504 |
|
504 | |||
505 | #Integration with Overlapping |
|
505 | #Integration with Overlapping | |
506 | data = numpy.sum(self.__buffer, axis=0) |
|
506 | data = numpy.sum(self.__buffer, axis=0) | |
507 | n = self.__profIndex |
|
507 | n = self.__profIndex | |
508 |
|
508 | |||
509 | return data, n |
|
509 | return data, n | |
510 |
|
510 | |||
511 | def byProfiles(self, data): |
|
511 | def byProfiles(self, data): | |
512 |
|
512 | |||
513 | self.__dataReady = False |
|
513 | self.__dataReady = False | |
514 | avgdata = None |
|
514 | avgdata = None | |
515 | n = None |
|
515 | n = None | |
516 |
|
516 | |||
517 | self.putData(data) |
|
517 | self.putData(data) | |
518 |
|
518 | |||
519 | if self.__profIndex == self.n: |
|
519 | if self.__profIndex == self.n: | |
520 |
|
520 | |||
521 | avgdata, n = self.pushData() |
|
521 | avgdata, n = self.pushData() | |
522 | self.__dataReady = True |
|
522 | self.__dataReady = True | |
523 |
|
523 | |||
524 | return avgdata |
|
524 | return avgdata | |
525 |
|
525 | |||
526 | def byTime(self, data, datatime): |
|
526 | def byTime(self, data, datatime): | |
527 |
|
527 | |||
528 | self.__dataReady = False |
|
528 | self.__dataReady = False | |
529 | avgdata = None |
|
529 | avgdata = None | |
530 | n = None |
|
530 | n = None | |
531 |
|
531 | |||
532 | self.putData(data) |
|
532 | self.putData(data) | |
533 |
|
533 | |||
534 | if (datatime - self.__initime) >= self.__integrationtime: |
|
534 | if (datatime - self.__initime) >= self.__integrationtime: | |
535 | avgdata, n = self.pushData() |
|
535 | avgdata, n = self.pushData() | |
536 | self.n = n |
|
536 | self.n = n | |
537 | self.__dataReady = True |
|
537 | self.__dataReady = True | |
538 |
|
538 | |||
539 | return avgdata |
|
539 | return avgdata | |
540 |
|
540 | |||
541 | def integrate(self, data, datatime=None): |
|
541 | def integrate(self, data, datatime=None): | |
542 |
|
542 | |||
543 | if self.__initime == None: |
|
543 | if self.__initime == None: | |
544 | self.__initime = datatime |
|
544 | self.__initime = datatime | |
545 |
|
545 | |||
546 | if self.__byTime: |
|
546 | if self.__byTime: | |
547 | avgdata = self.byTime(data, datatime) |
|
547 | avgdata = self.byTime(data, datatime) | |
548 | else: |
|
548 | else: | |
549 | avgdata = self.byProfiles(data) |
|
549 | avgdata = self.byProfiles(data) | |
550 |
|
550 | |||
551 |
|
551 | |||
552 | self.__lastdatatime = datatime |
|
552 | self.__lastdatatime = datatime | |
553 |
|
553 | |||
554 | if avgdata == None: |
|
554 | if avgdata == None: | |
555 | return None, None |
|
555 | return None, None | |
556 |
|
556 | |||
557 | avgdatatime = self.__initime |
|
557 | avgdatatime = self.__initime | |
558 |
|
558 | |||
559 | deltatime = datatime -self.__lastdatatime |
|
559 | deltatime = datatime -self.__lastdatatime | |
560 |
|
560 | |||
561 | if not self.__withOverapping: |
|
561 | if not self.__withOverapping: | |
562 | self.__initime = datatime |
|
562 | self.__initime = datatime | |
563 | else: |
|
563 | else: | |
564 | self.__initime += deltatime |
|
564 | self.__initime += deltatime | |
565 |
|
565 | |||
566 | return avgdata, avgdatatime |
|
566 | return avgdata, avgdatatime | |
567 |
|
567 | |||
568 | def run(self, dataOut, **kwargs): |
|
568 | def run(self, dataOut, **kwargs): | |
569 |
|
569 | |||
570 | if not self.__isConfig: |
|
570 | if not self.__isConfig: | |
571 | self.setup(**kwargs) |
|
571 | self.setup(**kwargs) | |
572 | self.__isConfig = True |
|
572 | self.__isConfig = True | |
573 |
|
573 | |||
574 | avgdata, avgdatatime = self.integrate(dataOut.data, dataOut.utctime) |
|
574 | avgdata, avgdatatime = self.integrate(dataOut.data, dataOut.utctime) | |
575 |
|
575 | |||
576 | # dataOut.timeInterval *= n |
|
576 | # dataOut.timeInterval *= n | |
577 | dataOut.flagNoData = True |
|
577 | dataOut.flagNoData = True | |
578 |
|
578 | |||
579 | if self.__dataReady: |
|
579 | if self.__dataReady: | |
580 | dataOut.data = avgdata |
|
580 | dataOut.data = avgdata | |
581 | dataOut.nCohInt *= self.n |
|
581 | dataOut.nCohInt *= self.n | |
582 | dataOut.utctime = avgdatatime |
|
582 | dataOut.utctime = avgdatatime | |
583 | dataOut.timeInterval = dataOut.ippSeconds * dataOut.nCohInt |
|
583 | dataOut.timeInterval = dataOut.ippSeconds * dataOut.nCohInt | |
584 | dataOut.flagNoData = False |
|
584 | dataOut.flagNoData = False | |
585 |
|
585 | |||
586 |
|
586 | |||
587 | class Decoder(Operation): |
|
587 | class Decoder(Operation): | |
588 |
|
588 | |||
589 | __isConfig = False |
|
589 | __isConfig = False | |
590 | __profIndex = 0 |
|
590 | __profIndex = 0 | |
591 |
|
591 | |||
592 | code = None |
|
592 | code = None | |
593 |
|
593 | |||
594 | nCode = None |
|
594 | nCode = None | |
595 | nBaud = None |
|
595 | nBaud = None | |
596 |
|
596 | |||
597 | def __init__(self): |
|
597 | def __init__(self): | |
598 |
|
598 | |||
599 | self.__isConfig = False |
|
599 | self.__isConfig = False | |
600 |
|
600 | |||
601 | def setup(self, code, shape): |
|
601 | def setup(self, code, shape): | |
602 |
|
602 | |||
603 | self.__profIndex = 0 |
|
603 | self.__profIndex = 0 | |
604 |
|
604 | |||
605 | self.code = code |
|
605 | self.code = code | |
606 |
|
606 | |||
607 | self.nCode = len(code) |
|
607 | self.nCode = len(code) | |
608 | self.nBaud = len(code[0]) |
|
608 | self.nBaud = len(code[0]) | |
609 |
|
609 | |||
610 | self.__nChannels, self.__nHeis = shape |
|
610 | self.__nChannels, self.__nHeis = shape | |
611 |
|
611 | |||
612 | __codeBuffer = numpy.zeros((self.nCode, self.__nHeis), dtype=numpy.complex) |
|
612 | __codeBuffer = numpy.zeros((self.nCode, self.__nHeis), dtype=numpy.complex) | |
613 |
|
613 | |||
614 | __codeBuffer[:,0:self.nBaud] = self.code |
|
614 | __codeBuffer[:,0:self.nBaud] = self.code | |
615 |
|
615 | |||
616 | self.fft_code = numpy.conj(numpy.fft.fft(__codeBuffer, axis=1)) |
|
616 | self.fft_code = numpy.conj(numpy.fft.fft(__codeBuffer, axis=1)) | |
617 |
|
617 | |||
618 | self.ndatadec = self.__nHeis - self.nBaud + 1 |
|
618 | self.ndatadec = self.__nHeis - self.nBaud + 1 | |
619 |
|
619 | |||
620 | self.datadecTime = numpy.zeros((self.__nChannels, self.ndatadec), dtype=numpy.complex) |
|
620 | self.datadecTime = numpy.zeros((self.__nChannels, self.ndatadec), dtype=numpy.complex) | |
621 |
|
621 | |||
622 | def convolutionInFreq(self, data): |
|
622 | def convolutionInFreq(self, data): | |
623 |
|
623 | |||
624 | fft_code = self.fft_code[self.__profIndex].reshape(1,-1) |
|
624 | fft_code = self.fft_code[self.__profIndex].reshape(1,-1) | |
625 |
|
625 | |||
626 | fft_data = numpy.fft.fft(data, axis=1) |
|
626 | fft_data = numpy.fft.fft(data, axis=1) | |
627 |
|
627 | |||
628 | conv = fft_data*fft_code |
|
628 | conv = fft_data*fft_code | |
629 |
|
629 | |||
630 | data = numpy.fft.ifft(conv,axis=1) |
|
630 | data = numpy.fft.ifft(conv,axis=1) | |
631 |
|
631 | |||
632 | datadec = data[:,:-self.nBaud+1] |
|
632 | datadec = data[:,:-self.nBaud+1] | |
633 |
|
633 | |||
634 | return datadec |
|
634 | return datadec | |
635 |
|
635 | |||
636 | def convolutionInFreqOpt(self, data): |
|
636 | def convolutionInFreqOpt(self, data): | |
637 |
|
637 | |||
638 | fft_code = self.fft_code[self.__profIndex].reshape(1,-1) |
|
638 | fft_code = self.fft_code[self.__profIndex].reshape(1,-1) | |
639 |
|
639 | |||
640 | data = cfunctions.decoder(fft_code, data) |
|
640 | data = cfunctions.decoder(fft_code, data) | |
641 |
|
641 | |||
642 | datadec = data[:,:-self.nBaud+1] |
|
642 | datadec = data[:,:-self.nBaud+1] | |
643 |
|
643 | |||
644 | return datadec |
|
644 | return datadec | |
645 |
|
645 | |||
646 | def convolutionInTime(self, data): |
|
646 | def convolutionInTime(self, data): | |
647 |
|
647 | |||
648 | code = self.code[self.__profIndex] |
|
648 | code = self.code[self.__profIndex] | |
649 |
|
649 | |||
650 | for i in range(self.__nChannels): |
|
650 | for i in range(self.__nChannels): | |
651 | self.datadecTime[i,:] = numpy.correlate(data[i,:], code, mode='valid') |
|
651 | self.datadecTime[i,:] = numpy.correlate(data[i,:], code, mode='valid') | |
652 |
|
652 | |||
653 | return self.datadecTime |
|
653 | return self.datadecTime | |
654 |
|
654 | |||
655 | def run(self, dataOut, code=None, nCode=None, nBaud=None, mode = 0): |
|
655 | def run(self, dataOut, code=None, nCode=None, nBaud=None, mode = 0): | |
656 |
|
656 | |||
657 | if code == None: |
|
657 | if code == None: | |
658 | code = dataOut.code |
|
658 | code = dataOut.code | |
659 | else: |
|
659 | else: | |
660 | code = numpy.array(code).reshape(nCode,nBaud) |
|
660 | code = numpy.array(code).reshape(nCode,nBaud) | |
661 | dataOut.code = code |
|
661 | dataOut.code = code | |
662 | dataOut.nCode = nCode |
|
662 | dataOut.nCode = nCode | |
663 | dataOut.nBaud = nBaud |
|
663 | dataOut.nBaud = nBaud | |
664 | dataOut.radarControllerHeaderObj.code = code |
|
664 | dataOut.radarControllerHeaderObj.code = code | |
665 | dataOut.radarControllerHeaderObj.nCode = nCode |
|
665 | dataOut.radarControllerHeaderObj.nCode = nCode | |
666 | dataOut.radarControllerHeaderObj.nBaud = nBaud |
|
666 | dataOut.radarControllerHeaderObj.nBaud = nBaud | |
667 |
|
667 | |||
668 |
|
668 | |||
669 | if not self.__isConfig: |
|
669 | if not self.__isConfig: | |
670 |
|
670 | |||
671 | self.setup(code, dataOut.data.shape) |
|
671 | self.setup(code, dataOut.data.shape) | |
672 | self.__isConfig = True |
|
672 | self.__isConfig = True | |
673 |
|
673 | |||
674 | if mode == 0: |
|
674 | if mode == 0: | |
675 | datadec = self.convolutionInTime(dataOut.data) |
|
675 | datadec = self.convolutionInTime(dataOut.data) | |
676 |
|
676 | |||
677 | if mode == 1: |
|
677 | if mode == 1: | |
678 | datadec = self.convolutionInFreq(dataOut.data) |
|
678 | datadec = self.convolutionInFreq(dataOut.data) | |
679 |
|
679 | |||
680 | if mode == 2: |
|
680 | if mode == 2: | |
681 | datadec = self.convolutionInFreqOpt(dataOut.data) |
|
681 | datadec = self.convolutionInFreqOpt(dataOut.data) | |
682 |
|
682 | |||
683 | dataOut.data = datadec |
|
683 | dataOut.data = datadec | |
684 |
|
684 | |||
685 | dataOut.heightList = dataOut.heightList[0:self.ndatadec] |
|
685 | dataOut.heightList = dataOut.heightList[0:self.ndatadec] | |
686 |
|
686 | |||
687 | dataOut.flagDecodeData = True #asumo q la data no esta decodificada |
|
687 | dataOut.flagDecodeData = True #asumo q la data no esta decodificada | |
688 |
|
688 | |||
689 | if self.__profIndex == self.nCode-1: |
|
689 | if self.__profIndex == self.nCode-1: | |
690 | self.__profIndex = 0 |
|
690 | self.__profIndex = 0 | |
691 | return 1 |
|
691 | return 1 | |
692 |
|
692 | |||
693 | self.__profIndex += 1 |
|
693 | self.__profIndex += 1 | |
694 |
|
694 | |||
695 | return 1 |
|
695 | return 1 | |
696 | # dataOut.flagDeflipData = True #asumo q la data no esta sin flip |
|
696 | # dataOut.flagDeflipData = True #asumo q la data no esta sin flip | |
697 |
|
697 | |||
698 |
|
698 | |||
699 |
|
699 | |||
700 | class SpectraProc(ProcessingUnit): |
|
700 | class SpectraProc(ProcessingUnit): | |
701 |
|
701 | |||
702 | def __init__(self): |
|
702 | def __init__(self): | |
703 |
|
703 | |||
704 | self.objectDict = {} |
|
704 | self.objectDict = {} | |
705 | self.buffer = None |
|
705 | self.buffer = None | |
706 | self.firstdatatime = None |
|
706 | self.firstdatatime = None | |
707 | self.profIndex = 0 |
|
707 | self.profIndex = 0 | |
708 | self.dataOut = Spectra() |
|
708 | self.dataOut = Spectra() | |
709 |
|
709 | |||
710 | def __updateObjFromInput(self): |
|
710 | def __updateObjFromInput(self): | |
711 |
|
711 | |||
712 | self.dataOut.timeZone = self.dataIn.timeZone |
|
712 | self.dataOut.timeZone = self.dataIn.timeZone | |
713 | self.dataOut.dstFlag = self.dataIn.dstFlag |
|
713 | self.dataOut.dstFlag = self.dataIn.dstFlag | |
714 | self.dataOut.errorCount = self.dataIn.errorCount |
|
714 | self.dataOut.errorCount = self.dataIn.errorCount | |
715 | self.dataOut.useLocalTime = self.dataIn.useLocalTime |
|
715 | self.dataOut.useLocalTime = self.dataIn.useLocalTime | |
716 |
|
716 | |||
717 | self.dataOut.radarControllerHeaderObj = self.dataIn.radarControllerHeaderObj.copy() |
|
717 | self.dataOut.radarControllerHeaderObj = self.dataIn.radarControllerHeaderObj.copy() | |
718 | self.dataOut.systemHeaderObj = self.dataIn.systemHeaderObj.copy() |
|
718 | self.dataOut.systemHeaderObj = self.dataIn.systemHeaderObj.copy() | |
719 | self.dataOut.channelList = self.dataIn.channelList |
|
719 | self.dataOut.channelList = self.dataIn.channelList | |
720 | self.dataOut.heightList = self.dataIn.heightList |
|
720 | self.dataOut.heightList = self.dataIn.heightList | |
721 | self.dataOut.dtype = numpy.dtype([('real','<f4'),('imag','<f4')]) |
|
721 | self.dataOut.dtype = numpy.dtype([('real','<f4'),('imag','<f4')]) | |
722 | # self.dataOut.nHeights = self.dataIn.nHeights |
|
722 | # self.dataOut.nHeights = self.dataIn.nHeights | |
723 | # self.dataOut.nChannels = self.dataIn.nChannels |
|
723 | # self.dataOut.nChannels = self.dataIn.nChannels | |
724 | self.dataOut.nBaud = self.dataIn.nBaud |
|
724 | self.dataOut.nBaud = self.dataIn.nBaud | |
725 | self.dataOut.nCode = self.dataIn.nCode |
|
725 | self.dataOut.nCode = self.dataIn.nCode | |
726 | self.dataOut.code = self.dataIn.code |
|
726 | self.dataOut.code = self.dataIn.code | |
727 | self.dataOut.nProfiles = self.dataOut.nFFTPoints |
|
727 | self.dataOut.nProfiles = self.dataOut.nFFTPoints | |
728 | # self.dataOut.channelIndexList = self.dataIn.channelIndexList |
|
728 | # self.dataOut.channelIndexList = self.dataIn.channelIndexList | |
729 | self.dataOut.flagTimeBlock = self.dataIn.flagTimeBlock |
|
729 | self.dataOut.flagTimeBlock = self.dataIn.flagTimeBlock | |
730 | self.dataOut.utctime = self.firstdatatime |
|
730 | self.dataOut.utctime = self.firstdatatime | |
731 | self.dataOut.flagDecodeData = self.dataIn.flagDecodeData #asumo q la data esta decodificada |
|
731 | self.dataOut.flagDecodeData = self.dataIn.flagDecodeData #asumo q la data esta decodificada | |
732 | self.dataOut.flagDeflipData = self.dataIn.flagDeflipData #asumo q la data esta sin flip |
|
732 | self.dataOut.flagDeflipData = self.dataIn.flagDeflipData #asumo q la data esta sin flip | |
733 | # self.dataOut.flagShiftFFT = self.dataIn.flagShiftFFT |
|
733 | # self.dataOut.flagShiftFFT = self.dataIn.flagShiftFFT | |
734 | self.dataOut.nCohInt = self.dataIn.nCohInt |
|
734 | self.dataOut.nCohInt = self.dataIn.nCohInt | |
735 | self.dataOut.nIncohInt = 1 |
|
735 | self.dataOut.nIncohInt = 1 | |
736 | self.dataOut.ippSeconds = self.dataIn.ippSeconds |
|
736 | self.dataOut.ippSeconds = self.dataIn.ippSeconds | |
737 | self.dataOut.windowOfFilter = self.dataIn.windowOfFilter |
|
737 | self.dataOut.windowOfFilter = self.dataIn.windowOfFilter | |
738 |
|
738 | |||
739 | self.dataOut.timeInterval = self.dataIn.timeInterval*self.dataOut.nFFTPoints*self.dataOut.nIncohInt |
|
739 | self.dataOut.timeInterval = self.dataIn.timeInterval*self.dataOut.nFFTPoints*self.dataOut.nIncohInt | |
740 | self.dataOut.frequency = self.dataIn.frequency |
|
740 | self.dataOut.frequency = self.dataIn.frequency | |
741 | self.dataOut.realtime = self.dataIn.realtime |
|
741 | self.dataOut.realtime = self.dataIn.realtime | |
742 |
|
742 | |||
743 | def __getFft(self): |
|
743 | def __getFft(self): | |
744 | """ |
|
744 | """ | |
745 | Convierte valores de Voltaje a Spectra |
|
745 | Convierte valores de Voltaje a Spectra | |
746 |
|
746 | |||
747 | Affected: |
|
747 | Affected: | |
748 | self.dataOut.data_spc |
|
748 | self.dataOut.data_spc | |
749 | self.dataOut.data_cspc |
|
749 | self.dataOut.data_cspc | |
750 | self.dataOut.data_dc |
|
750 | self.dataOut.data_dc | |
751 | self.dataOut.heightList |
|
751 | self.dataOut.heightList | |
752 | self.profIndex |
|
752 | self.profIndex | |
753 | self.buffer |
|
753 | self.buffer | |
754 | self.dataOut.flagNoData |
|
754 | self.dataOut.flagNoData | |
755 | """ |
|
755 | """ | |
756 | fft_volt = numpy.fft.fft(self.buffer,n=self.dataOut.nFFTPoints,axis=1) |
|
756 | fft_volt = numpy.fft.fft(self.buffer,n=self.dataOut.nFFTPoints,axis=1) | |
757 | fft_volt = fft_volt.astype(numpy.dtype('complex')) |
|
757 | fft_volt = fft_volt.astype(numpy.dtype('complex')) | |
758 | dc = fft_volt[:,0,:] |
|
758 | dc = fft_volt[:,0,:] | |
759 |
|
759 | |||
760 | #calculo de self-spectra |
|
760 | #calculo de self-spectra | |
761 | fft_volt = numpy.fft.fftshift(fft_volt,axes=(1,)) |
|
761 | fft_volt = numpy.fft.fftshift(fft_volt,axes=(1,)) | |
762 | spc = fft_volt * numpy.conjugate(fft_volt) |
|
762 | spc = fft_volt * numpy.conjugate(fft_volt) | |
763 | spc = spc.real |
|
763 | spc = spc.real | |
764 |
|
764 | |||
765 | blocksize = 0 |
|
765 | blocksize = 0 | |
766 | blocksize += dc.size |
|
766 | blocksize += dc.size | |
767 | blocksize += spc.size |
|
767 | blocksize += spc.size | |
768 |
|
768 | |||
769 | cspc = None |
|
769 | cspc = None | |
770 | pairIndex = 0 |
|
770 | pairIndex = 0 | |
771 | if self.dataOut.pairsList != None: |
|
771 | if self.dataOut.pairsList != None: | |
772 | #calculo de cross-spectra |
|
772 | #calculo de cross-spectra | |
773 | cspc = numpy.zeros((self.dataOut.nPairs, self.dataOut.nFFTPoints, self.dataOut.nHeights), dtype='complex') |
|
773 | cspc = numpy.zeros((self.dataOut.nPairs, self.dataOut.nFFTPoints, self.dataOut.nHeights), dtype='complex') | |
774 | for pair in self.dataOut.pairsList: |
|
774 | for pair in self.dataOut.pairsList: | |
775 | cspc[pairIndex,:,:] = fft_volt[pair[0],:,:] * numpy.conjugate(fft_volt[pair[1],:,:]) |
|
775 | cspc[pairIndex,:,:] = fft_volt[pair[0],:,:] * numpy.conjugate(fft_volt[pair[1],:,:]) | |
776 | pairIndex += 1 |
|
776 | pairIndex += 1 | |
777 | blocksize += cspc.size |
|
777 | blocksize += cspc.size | |
778 |
|
778 | |||
779 | self.dataOut.data_spc = spc |
|
779 | self.dataOut.data_spc = spc | |
780 | self.dataOut.data_cspc = cspc |
|
780 | self.dataOut.data_cspc = cspc | |
781 | self.dataOut.data_dc = dc |
|
781 | self.dataOut.data_dc = dc | |
782 | self.dataOut.blockSize = blocksize |
|
782 | self.dataOut.blockSize = blocksize | |
783 | self.dataOut.flagShiftFFT = False |
|
783 | self.dataOut.flagShiftFFT = False | |
784 |
|
784 | |||
785 | def init(self, nProfiles=None, nFFTPoints=None, pairsList=None, ippFactor=None): |
|
785 | def init(self, nProfiles=None, nFFTPoints=None, pairsList=None, ippFactor=None): | |
786 |
|
786 | |||
787 | self.dataOut.flagNoData = True |
|
787 | self.dataOut.flagNoData = True | |
788 |
|
788 | |||
789 | if self.dataIn.type == "Spectra": |
|
789 | if self.dataIn.type == "Spectra": | |
790 | self.dataOut.copy(self.dataIn) |
|
790 | self.dataOut.copy(self.dataIn) | |
791 | return |
|
791 | return | |
792 |
|
792 | |||
793 | if self.dataIn.type == "Voltage": |
|
793 | if self.dataIn.type == "Voltage": | |
794 |
|
794 | |||
795 | if nFFTPoints == None: |
|
795 | if nFFTPoints == None: | |
796 | raise ValueError, "This SpectraProc.init() need nFFTPoints input variable" |
|
796 | raise ValueError, "This SpectraProc.init() need nFFTPoints input variable" | |
797 |
|
797 | |||
798 | if pairsList == None: |
|
798 | if pairsList == None: | |
799 | nPairs = 0 |
|
799 | nPairs = 0 | |
800 | else: |
|
800 | else: | |
801 | nPairs = len(pairsList) |
|
801 | nPairs = len(pairsList) | |
802 |
|
802 | |||
803 | if ippFactor == None: |
|
803 | if ippFactor == None: | |
804 | ippFactor = 1 |
|
804 | ippFactor = 1 | |
805 | self.dataOut.ippFactor = ippFactor |
|
805 | self.dataOut.ippFactor = ippFactor | |
806 |
|
806 | |||
807 | self.dataOut.nFFTPoints = nFFTPoints |
|
807 | self.dataOut.nFFTPoints = nFFTPoints | |
808 | self.dataOut.pairsList = pairsList |
|
808 | self.dataOut.pairsList = pairsList | |
809 | self.dataOut.nPairs = nPairs |
|
809 | self.dataOut.nPairs = nPairs | |
810 |
|
810 | |||
811 | if self.buffer == None: |
|
811 | if self.buffer == None: | |
812 | self.buffer = numpy.zeros((self.dataIn.nChannels, |
|
812 | self.buffer = numpy.zeros((self.dataIn.nChannels, | |
813 | nProfiles, |
|
813 | nProfiles, | |
814 | self.dataIn.nHeights), |
|
814 | self.dataIn.nHeights), | |
815 | dtype='complex') |
|
815 | dtype='complex') | |
816 |
|
816 | |||
817 |
|
817 | |||
818 | self.buffer[:,self.profIndex,:] = self.dataIn.data.copy() |
|
818 | self.buffer[:,self.profIndex,:] = self.dataIn.data.copy() | |
819 | self.profIndex += 1 |
|
819 | self.profIndex += 1 | |
820 |
|
820 | |||
821 | if self.firstdatatime == None: |
|
821 | if self.firstdatatime == None: | |
822 | self.firstdatatime = self.dataIn.utctime |
|
822 | self.firstdatatime = self.dataIn.utctime | |
823 |
|
823 | |||
824 | if self.profIndex == nProfiles: |
|
824 | if self.profIndex == nProfiles: | |
825 | self.__updateObjFromInput() |
|
825 | self.__updateObjFromInput() | |
826 | self.__getFft() |
|
826 | self.__getFft() | |
827 |
|
827 | |||
828 | self.dataOut.flagNoData = False |
|
828 | self.dataOut.flagNoData = False | |
829 |
|
829 | |||
830 | self.buffer = None |
|
830 | self.buffer = None | |
831 | self.firstdatatime = None |
|
831 | self.firstdatatime = None | |
832 | self.profIndex = 0 |
|
832 | self.profIndex = 0 | |
833 |
|
833 | |||
834 | return |
|
834 | return | |
835 |
|
835 | |||
836 | raise ValueError, "The type object %s is not valid"%(self.dataIn.type) |
|
836 | raise ValueError, "The type object %s is not valid"%(self.dataIn.type) | |
837 |
|
837 | |||
838 | def selectChannels(self, channelList): |
|
838 | def selectChannels(self, channelList): | |
839 |
|
839 | |||
840 | channelIndexList = [] |
|
840 | channelIndexList = [] | |
841 |
|
841 | |||
842 | for channel in channelList: |
|
842 | for channel in channelList: | |
843 | index = self.dataOut.channelList.index(channel) |
|
843 | index = self.dataOut.channelList.index(channel) | |
844 | channelIndexList.append(index) |
|
844 | channelIndexList.append(index) | |
845 |
|
845 | |||
846 | self.selectChannelsByIndex(channelIndexList) |
|
846 | self.selectChannelsByIndex(channelIndexList) | |
847 |
|
847 | |||
848 | def selectChannelsByIndex(self, channelIndexList): |
|
848 | def selectChannelsByIndex(self, channelIndexList): | |
849 | """ |
|
849 | """ | |
850 | Selecciona un bloque de datos en base a canales segun el channelIndexList |
|
850 | Selecciona un bloque de datos en base a canales segun el channelIndexList | |
851 |
|
851 | |||
852 | Input: |
|
852 | Input: | |
853 | channelIndexList : lista sencilla de canales a seleccionar por ej. [2,3,7] |
|
853 | channelIndexList : lista sencilla de canales a seleccionar por ej. [2,3,7] | |
854 |
|
854 | |||
855 | Affected: |
|
855 | Affected: | |
856 | self.dataOut.data_spc |
|
856 | self.dataOut.data_spc | |
857 | self.dataOut.channelIndexList |
|
857 | self.dataOut.channelIndexList | |
858 | self.dataOut.nChannels |
|
858 | self.dataOut.nChannels | |
859 |
|
859 | |||
860 | Return: |
|
860 | Return: | |
861 | None |
|
861 | None | |
862 | """ |
|
862 | """ | |
863 |
|
863 | |||
864 | for channelIndex in channelIndexList: |
|
864 | for channelIndex in channelIndexList: | |
865 | if channelIndex not in self.dataOut.channelIndexList: |
|
865 | if channelIndex not in self.dataOut.channelIndexList: | |
866 | print channelIndexList |
|
866 | print channelIndexList | |
867 | raise ValueError, "The value %d in channelIndexList is not valid" %channelIndex |
|
867 | raise ValueError, "The value %d in channelIndexList is not valid" %channelIndex | |
868 |
|
868 | |||
869 | nChannels = len(channelIndexList) |
|
869 | nChannels = len(channelIndexList) | |
870 |
|
870 | |||
871 | data_spc = self.dataOut.data_spc[channelIndexList,:] |
|
871 | data_spc = self.dataOut.data_spc[channelIndexList,:] | |
872 |
|
872 | |||
873 | self.dataOut.data_spc = data_spc |
|
873 | self.dataOut.data_spc = data_spc | |
874 | self.dataOut.channelList = [self.dataOut.channelList[i] for i in channelIndexList] |
|
874 | self.dataOut.channelList = [self.dataOut.channelList[i] for i in channelIndexList] | |
875 | # self.dataOut.nChannels = nChannels |
|
875 | # self.dataOut.nChannels = nChannels | |
876 |
|
876 | |||
877 | return 1 |
|
877 | return 1 | |
878 |
|
878 | |||
879 | def selectHeights(self, minHei, maxHei): |
|
879 | def selectHeights(self, minHei, maxHei): | |
880 | """ |
|
880 | """ | |
881 | Selecciona un bloque de datos en base a un grupo de valores de alturas segun el rango |
|
881 | Selecciona un bloque de datos en base a un grupo de valores de alturas segun el rango | |
882 | minHei <= height <= maxHei |
|
882 | minHei <= height <= maxHei | |
883 |
|
883 | |||
884 | Input: |
|
884 | Input: | |
885 | minHei : valor minimo de altura a considerar |
|
885 | minHei : valor minimo de altura a considerar | |
886 | maxHei : valor maximo de altura a considerar |
|
886 | maxHei : valor maximo de altura a considerar | |
887 |
|
887 | |||
888 | Affected: |
|
888 | Affected: | |
889 | Indirectamente son cambiados varios valores a travez del metodo selectHeightsByIndex |
|
889 | Indirectamente son cambiados varios valores a travez del metodo selectHeightsByIndex | |
890 |
|
890 | |||
891 | Return: |
|
891 | Return: | |
892 | 1 si el metodo se ejecuto con exito caso contrario devuelve 0 |
|
892 | 1 si el metodo se ejecuto con exito caso contrario devuelve 0 | |
893 | """ |
|
893 | """ | |
894 | if (minHei < self.dataOut.heightList[0]) or (minHei > maxHei): |
|
894 | if (minHei < self.dataOut.heightList[0]) or (minHei > maxHei): | |
895 | raise ValueError, "some value in (%d,%d) is not valid" % (minHei, maxHei) |
|
895 | raise ValueError, "some value in (%d,%d) is not valid" % (minHei, maxHei) | |
896 |
|
896 | |||
897 | if (maxHei > self.dataOut.heightList[-1]): |
|
897 | if (maxHei > self.dataOut.heightList[-1]): | |
898 | maxHei = self.dataOut.heightList[-1] |
|
898 | maxHei = self.dataOut.heightList[-1] | |
899 | # raise ValueError, "some value in (%d,%d) is not valid" % (minHei, maxHei) |
|
899 | # raise ValueError, "some value in (%d,%d) is not valid" % (minHei, maxHei) | |
900 |
|
900 | |||
901 | minIndex = 0 |
|
901 | minIndex = 0 | |
902 | maxIndex = 0 |
|
902 | maxIndex = 0 | |
903 | heights = self.dataOut.heightList |
|
903 | heights = self.dataOut.heightList | |
904 |
|
904 | |||
905 | inda = numpy.where(heights >= minHei) |
|
905 | inda = numpy.where(heights >= minHei) | |
906 | indb = numpy.where(heights <= maxHei) |
|
906 | indb = numpy.where(heights <= maxHei) | |
907 |
|
907 | |||
908 | try: |
|
908 | try: | |
909 | minIndex = inda[0][0] |
|
909 | minIndex = inda[0][0] | |
910 | except: |
|
910 | except: | |
911 | minIndex = 0 |
|
911 | minIndex = 0 | |
912 |
|
912 | |||
913 | try: |
|
913 | try: | |
914 | maxIndex = indb[0][-1] |
|
914 | maxIndex = indb[0][-1] | |
915 | except: |
|
915 | except: | |
916 | maxIndex = len(heights) |
|
916 | maxIndex = len(heights) | |
917 |
|
917 | |||
918 | self.selectHeightsByIndex(minIndex, maxIndex) |
|
918 | self.selectHeightsByIndex(minIndex, maxIndex) | |
919 |
|
919 | |||
920 | return 1 |
|
920 | return 1 | |
921 |
|
921 | |||
922 | def getBeaconSignal(self, tauindex = 0, channelindex = 0): |
|
922 | def getBeaconSignal(self, tauindex = 0, channelindex = 0, hei_ref=None): | |
923 | newheis = numpy.where(self.dataOut.heightList>self.dataOut.radarControllerHeaderObj.Taus[tauindex]) |
|
923 | newheis = numpy.where(self.dataOut.heightList>self.dataOut.radarControllerHeaderObj.Taus[tauindex]) | |
|
924 | ||||
|
925 | if hei_ref != None: | |||
|
926 | newheis = numpy.where(self.dataOut.heightList>hei_ref) | |||
|
927 | ||||
924 | minIndex = min(newheis[0]) |
|
928 | minIndex = min(newheis[0]) | |
925 | maxIndex = max(newheis[0]) |
|
929 | maxIndex = max(newheis[0]) | |
926 | data_spc = self.dataOut.data_spc[:,:,minIndex:maxIndex+1] |
|
930 | data_spc = self.dataOut.data_spc[:,:,minIndex:maxIndex+1] | |
927 | heightList = self.dataOut.heightList[minIndex:maxIndex+1] |
|
931 | heightList = self.dataOut.heightList[minIndex:maxIndex+1] | |
928 |
|
932 | |||
929 | # determina indices |
|
933 | # determina indices | |
930 | nheis = int(self.dataOut.radarControllerHeaderObj.txB/(self.dataOut.heightList[1]-self.dataOut.heightList[0])) |
|
934 | nheis = int(self.dataOut.radarControllerHeaderObj.txB/(self.dataOut.heightList[1]-self.dataOut.heightList[0])) | |
931 | avg_dB = 10*numpy.log10(numpy.sum(data_spc[channelindex,:,:],axis=0)) |
|
935 | avg_dB = 10*numpy.log10(numpy.sum(data_spc[channelindex,:,:],axis=0)) | |
932 | beacon_dB = numpy.sort(avg_dB)[-nheis:] |
|
936 | beacon_dB = numpy.sort(avg_dB)[-nheis:] | |
933 | beacon_heiIndexList = [] |
|
937 | beacon_heiIndexList = [] | |
934 | for val in avg_dB.tolist(): |
|
938 | for val in avg_dB.tolist(): | |
935 | if val >= beacon_dB[0]: |
|
939 | if val >= beacon_dB[0]: | |
936 | beacon_heiIndexList.append(avg_dB.tolist().index(val)) |
|
940 | beacon_heiIndexList.append(avg_dB.tolist().index(val)) | |
937 |
|
941 | |||
938 | #data_spc = data_spc[:,:,beacon_heiIndexList] |
|
942 | #data_spc = data_spc[:,:,beacon_heiIndexList] | |
939 | data_cspc = None |
|
943 | data_cspc = None | |
940 | if self.dataOut.data_cspc != None: |
|
944 | if self.dataOut.data_cspc != None: | |
941 | data_cspc = self.dataOut.data_cspc[:,:,minIndex:maxIndex+1] |
|
945 | data_cspc = self.dataOut.data_cspc[:,:,minIndex:maxIndex+1] | |
942 | #data_cspc = data_cspc[:,:,beacon_heiIndexList] |
|
946 | #data_cspc = data_cspc[:,:,beacon_heiIndexList] | |
943 |
|
947 | |||
944 | data_dc = None |
|
948 | data_dc = None | |
945 | if self.dataOut.data_dc != None: |
|
949 | if self.dataOut.data_dc != None: | |
946 | data_dc = self.dataOut.data_dc[:,minIndex:maxIndex+1] |
|
950 | data_dc = self.dataOut.data_dc[:,minIndex:maxIndex+1] | |
947 | #data_dc = data_dc[:,beacon_heiIndexList] |
|
951 | #data_dc = data_dc[:,beacon_heiIndexList] | |
948 |
|
952 | |||
949 | self.dataOut.data_spc = data_spc |
|
953 | self.dataOut.data_spc = data_spc | |
950 | self.dataOut.data_cspc = data_cspc |
|
954 | self.dataOut.data_cspc = data_cspc | |
951 | self.dataOut.data_dc = data_dc |
|
955 | self.dataOut.data_dc = data_dc | |
952 | self.dataOut.heightList = heightList |
|
956 | self.dataOut.heightList = heightList | |
953 | self.dataOut.beacon_heiIndexList = beacon_heiIndexList |
|
957 | self.dataOut.beacon_heiIndexList = beacon_heiIndexList | |
954 |
|
958 | |||
955 | return 1 |
|
959 | return 1 | |
956 |
|
960 | |||
957 |
|
961 | |||
958 | def selectHeightsByIndex(self, minIndex, maxIndex): |
|
962 | def selectHeightsByIndex(self, minIndex, maxIndex): | |
959 | """ |
|
963 | """ | |
960 | Selecciona un bloque de datos en base a un grupo indices de alturas segun el rango |
|
964 | Selecciona un bloque de datos en base a un grupo indices de alturas segun el rango | |
961 | minIndex <= index <= maxIndex |
|
965 | minIndex <= index <= maxIndex | |
962 |
|
966 | |||
963 | Input: |
|
967 | Input: | |
964 | minIndex : valor de indice minimo de altura a considerar |
|
968 | minIndex : valor de indice minimo de altura a considerar | |
965 | maxIndex : valor de indice maximo de altura a considerar |
|
969 | maxIndex : valor de indice maximo de altura a considerar | |
966 |
|
970 | |||
967 | Affected: |
|
971 | Affected: | |
968 | self.dataOut.data_spc |
|
972 | self.dataOut.data_spc | |
969 | self.dataOut.data_cspc |
|
973 | self.dataOut.data_cspc | |
970 | self.dataOut.data_dc |
|
974 | self.dataOut.data_dc | |
971 | self.dataOut.heightList |
|
975 | self.dataOut.heightList | |
972 |
|
976 | |||
973 | Return: |
|
977 | Return: | |
974 | 1 si el metodo se ejecuto con exito caso contrario devuelve 0 |
|
978 | 1 si el metodo se ejecuto con exito caso contrario devuelve 0 | |
975 | """ |
|
979 | """ | |
976 |
|
980 | |||
977 | if (minIndex < 0) or (minIndex > maxIndex): |
|
981 | if (minIndex < 0) or (minIndex > maxIndex): | |
978 | raise ValueError, "some value in (%d,%d) is not valid" % (minIndex, maxIndex) |
|
982 | raise ValueError, "some value in (%d,%d) is not valid" % (minIndex, maxIndex) | |
979 |
|
983 | |||
980 | if (maxIndex >= self.dataOut.nHeights): |
|
984 | if (maxIndex >= self.dataOut.nHeights): | |
981 | maxIndex = self.dataOut.nHeights-1 |
|
985 | maxIndex = self.dataOut.nHeights-1 | |
982 | # raise ValueError, "some value in (%d,%d) is not valid" % (minIndex, maxIndex) |
|
986 | # raise ValueError, "some value in (%d,%d) is not valid" % (minIndex, maxIndex) | |
983 |
|
987 | |||
984 | nHeights = maxIndex - minIndex + 1 |
|
988 | nHeights = maxIndex - minIndex + 1 | |
985 |
|
989 | |||
986 | #Spectra |
|
990 | #Spectra | |
987 | data_spc = self.dataOut.data_spc[:,:,minIndex:maxIndex+1] |
|
991 | data_spc = self.dataOut.data_spc[:,:,minIndex:maxIndex+1] | |
988 |
|
992 | |||
989 | data_cspc = None |
|
993 | data_cspc = None | |
990 | if self.dataOut.data_cspc != None: |
|
994 | if self.dataOut.data_cspc != None: | |
991 | data_cspc = self.dataOut.data_cspc[:,:,minIndex:maxIndex+1] |
|
995 | data_cspc = self.dataOut.data_cspc[:,:,minIndex:maxIndex+1] | |
992 |
|
996 | |||
993 | data_dc = None |
|
997 | data_dc = None | |
994 | if self.dataOut.data_dc != None: |
|
998 | if self.dataOut.data_dc != None: | |
995 | data_dc = self.dataOut.data_dc[:,minIndex:maxIndex+1] |
|
999 | data_dc = self.dataOut.data_dc[:,minIndex:maxIndex+1] | |
996 |
|
1000 | |||
997 | self.dataOut.data_spc = data_spc |
|
1001 | self.dataOut.data_spc = data_spc | |
998 | self.dataOut.data_cspc = data_cspc |
|
1002 | self.dataOut.data_cspc = data_cspc | |
999 | self.dataOut.data_dc = data_dc |
|
1003 | self.dataOut.data_dc = data_dc | |
1000 |
|
1004 | |||
1001 | self.dataOut.heightList = self.dataOut.heightList[minIndex:maxIndex+1] |
|
1005 | self.dataOut.heightList = self.dataOut.heightList[minIndex:maxIndex+1] | |
1002 |
|
1006 | |||
1003 | return 1 |
|
1007 | return 1 | |
1004 |
|
1008 | |||
1005 | def removeDC(self, mode = 2): |
|
1009 | def removeDC(self, mode = 2): | |
1006 | jspectra = self.dataOut.data_spc |
|
1010 | jspectra = self.dataOut.data_spc | |
1007 | jcspectra = self.dataOut.data_cspc |
|
1011 | jcspectra = self.dataOut.data_cspc | |
1008 |
|
1012 | |||
1009 |
|
1013 | |||
1010 | num_chan = jspectra.shape[0] |
|
1014 | num_chan = jspectra.shape[0] | |
1011 | num_hei = jspectra.shape[2] |
|
1015 | num_hei = jspectra.shape[2] | |
1012 |
|
1016 | |||
1013 | if jcspectra != None: |
|
1017 | if jcspectra != None: | |
1014 | jcspectraExist = True |
|
1018 | jcspectraExist = True | |
1015 | num_pairs = jcspectra.shape[0] |
|
1019 | num_pairs = jcspectra.shape[0] | |
1016 | else: jcspectraExist = False |
|
1020 | else: jcspectraExist = False | |
1017 |
|
1021 | |||
1018 | freq_dc = jspectra.shape[1]/2 |
|
1022 | freq_dc = jspectra.shape[1]/2 | |
1019 | ind_vel = numpy.array([-2,-1,1,2]) + freq_dc |
|
1023 | ind_vel = numpy.array([-2,-1,1,2]) + freq_dc | |
1020 |
|
1024 | |||
1021 | if ind_vel[0]<0: |
|
1025 | if ind_vel[0]<0: | |
1022 | ind_vel[range(0,1)] = ind_vel[range(0,1)] + self.num_prof |
|
1026 | ind_vel[range(0,1)] = ind_vel[range(0,1)] + self.num_prof | |
1023 |
|
1027 | |||
1024 | if mode == 1: |
|
1028 | if mode == 1: | |
1025 | jspectra[:,freq_dc,:] = (jspectra[:,ind_vel[1],:] + jspectra[:,ind_vel[2],:])/2 #CORRECCION |
|
1029 | jspectra[:,freq_dc,:] = (jspectra[:,ind_vel[1],:] + jspectra[:,ind_vel[2],:])/2 #CORRECCION | |
1026 |
|
1030 | |||
1027 | if jcspectraExist: |
|
1031 | if jcspectraExist: | |
1028 | jcspectra[:,freq_dc,:] = (jcspectra[:,ind_vel[1],:] + jcspectra[:,ind_vel[2],:])/2 |
|
1032 | jcspectra[:,freq_dc,:] = (jcspectra[:,ind_vel[1],:] + jcspectra[:,ind_vel[2],:])/2 | |
1029 |
|
1033 | |||
1030 | if mode == 2: |
|
1034 | if mode == 2: | |
1031 |
|
1035 | |||
1032 | vel = numpy.array([-2,-1,1,2]) |
|
1036 | vel = numpy.array([-2,-1,1,2]) | |
1033 | xx = numpy.zeros([4,4]) |
|
1037 | xx = numpy.zeros([4,4]) | |
1034 |
|
1038 | |||
1035 | for fil in range(4): |
|
1039 | for fil in range(4): | |
1036 | xx[fil,:] = vel[fil]**numpy.asarray(range(4)) |
|
1040 | xx[fil,:] = vel[fil]**numpy.asarray(range(4)) | |
1037 |
|
1041 | |||
1038 | xx_inv = numpy.linalg.inv(xx) |
|
1042 | xx_inv = numpy.linalg.inv(xx) | |
1039 | xx_aux = xx_inv[0,:] |
|
1043 | xx_aux = xx_inv[0,:] | |
1040 |
|
1044 | |||
1041 | for ich in range(num_chan): |
|
1045 | for ich in range(num_chan): | |
1042 | yy = jspectra[ich,ind_vel,:] |
|
1046 | yy = jspectra[ich,ind_vel,:] | |
1043 | jspectra[ich,freq_dc,:] = numpy.dot(xx_aux,yy) |
|
1047 | jspectra[ich,freq_dc,:] = numpy.dot(xx_aux,yy) | |
1044 |
|
1048 | |||
1045 | junkid = jspectra[ich,freq_dc,:]<=0 |
|
1049 | junkid = jspectra[ich,freq_dc,:]<=0 | |
1046 | cjunkid = sum(junkid) |
|
1050 | cjunkid = sum(junkid) | |
1047 |
|
1051 | |||
1048 | if cjunkid.any(): |
|
1052 | if cjunkid.any(): | |
1049 | jspectra[ich,freq_dc,junkid.nonzero()] = (jspectra[ich,ind_vel[1],junkid] + jspectra[ich,ind_vel[2],junkid])/2 |
|
1053 | jspectra[ich,freq_dc,junkid.nonzero()] = (jspectra[ich,ind_vel[1],junkid] + jspectra[ich,ind_vel[2],junkid])/2 | |
1050 |
|
1054 | |||
1051 | if jcspectraExist: |
|
1055 | if jcspectraExist: | |
1052 | for ip in range(num_pairs): |
|
1056 | for ip in range(num_pairs): | |
1053 | yy = jcspectra[ip,ind_vel,:] |
|
1057 | yy = jcspectra[ip,ind_vel,:] | |
1054 | jcspectra[ip,freq_dc,:] = numpy.dot(xx_aux,yy) |
|
1058 | jcspectra[ip,freq_dc,:] = numpy.dot(xx_aux,yy) | |
1055 |
|
1059 | |||
1056 |
|
1060 | |||
1057 | self.dataOut.data_spc = jspectra |
|
1061 | self.dataOut.data_spc = jspectra | |
1058 | self.dataOut.data_cspc = jcspectra |
|
1062 | self.dataOut.data_cspc = jcspectra | |
1059 |
|
1063 | |||
1060 | return 1 |
|
1064 | return 1 | |
1061 |
|
1065 | |||
1062 | def removeInterference(self, interf = 2,hei_interf = None, nhei_interf = None, offhei_interf = None): |
|
1066 | def removeInterference(self, interf = 2,hei_interf = None, nhei_interf = None, offhei_interf = None): | |
1063 |
|
1067 | |||
1064 | jspectra = self.dataOut.data_spc |
|
1068 | jspectra = self.dataOut.data_spc | |
1065 | jcspectra = self.dataOut.data_cspc |
|
1069 | jcspectra = self.dataOut.data_cspc | |
1066 | jnoise = self.dataOut.getNoise() |
|
1070 | jnoise = self.dataOut.getNoise() | |
1067 | num_incoh = self.dataOut.nIncohInt |
|
1071 | num_incoh = self.dataOut.nIncohInt | |
1068 |
|
1072 | |||
1069 | num_channel = jspectra.shape[0] |
|
1073 | num_channel = jspectra.shape[0] | |
1070 | num_prof = jspectra.shape[1] |
|
1074 | num_prof = jspectra.shape[1] | |
1071 | num_hei = jspectra.shape[2] |
|
1075 | num_hei = jspectra.shape[2] | |
1072 |
|
1076 | |||
1073 | #hei_interf |
|
1077 | #hei_interf | |
1074 | if hei_interf == None: |
|
1078 | if hei_interf == None: | |
1075 | count_hei = num_hei/2 #Como es entero no importa |
|
1079 | count_hei = num_hei/2 #Como es entero no importa | |
1076 | hei_interf = numpy.asmatrix(range(count_hei)) + num_hei - count_hei |
|
1080 | hei_interf = numpy.asmatrix(range(count_hei)) + num_hei - count_hei | |
1077 | hei_interf = numpy.asarray(hei_interf)[0] |
|
1081 | hei_interf = numpy.asarray(hei_interf)[0] | |
1078 | #nhei_interf |
|
1082 | #nhei_interf | |
1079 | if (nhei_interf == None): |
|
1083 | if (nhei_interf == None): | |
1080 | nhei_interf = 5 |
|
1084 | nhei_interf = 5 | |
1081 | if (nhei_interf < 1): |
|
1085 | if (nhei_interf < 1): | |
1082 | nhei_interf = 1 |
|
1086 | nhei_interf = 1 | |
1083 | if (nhei_interf > count_hei): |
|
1087 | if (nhei_interf > count_hei): | |
1084 | nhei_interf = count_hei |
|
1088 | nhei_interf = count_hei | |
1085 | if (offhei_interf == None): |
|
1089 | if (offhei_interf == None): | |
1086 | offhei_interf = 0 |
|
1090 | offhei_interf = 0 | |
1087 |
|
1091 | |||
1088 | ind_hei = range(num_hei) |
|
1092 | ind_hei = range(num_hei) | |
1089 | # mask_prof = numpy.asarray(range(num_prof - 2)) + 1 |
|
1093 | # mask_prof = numpy.asarray(range(num_prof - 2)) + 1 | |
1090 | # mask_prof[range(num_prof/2 - 1,len(mask_prof))] += 1 |
|
1094 | # mask_prof[range(num_prof/2 - 1,len(mask_prof))] += 1 | |
1091 | mask_prof = numpy.asarray(range(num_prof)) |
|
1095 | mask_prof = numpy.asarray(range(num_prof)) | |
1092 | num_mask_prof = mask_prof.size |
|
1096 | num_mask_prof = mask_prof.size | |
1093 | comp_mask_prof = [0, num_prof/2] |
|
1097 | comp_mask_prof = [0, num_prof/2] | |
1094 |
|
1098 | |||
1095 |
|
1099 | |||
1096 | #noise_exist: Determina si la variable jnoise ha sido definida y contiene la informacion del ruido de cada canal |
|
1100 | #noise_exist: Determina si la variable jnoise ha sido definida y contiene la informacion del ruido de cada canal | |
1097 | if (jnoise.size < num_channel or numpy.isnan(jnoise).any()): |
|
1101 | if (jnoise.size < num_channel or numpy.isnan(jnoise).any()): | |
1098 | jnoise = numpy.nan |
|
1102 | jnoise = numpy.nan | |
1099 | noise_exist = jnoise[0] < numpy.Inf |
|
1103 | noise_exist = jnoise[0] < numpy.Inf | |
1100 |
|
1104 | |||
1101 | #Subrutina de Remocion de la Interferencia |
|
1105 | #Subrutina de Remocion de la Interferencia | |
1102 | for ich in range(num_channel): |
|
1106 | for ich in range(num_channel): | |
1103 | #Se ordena los espectros segun su potencia (menor a mayor) |
|
1107 | #Se ordena los espectros segun su potencia (menor a mayor) | |
1104 | power = jspectra[ich,mask_prof,:] |
|
1108 | power = jspectra[ich,mask_prof,:] | |
1105 | power = power[:,hei_interf] |
|
1109 | power = power[:,hei_interf] | |
1106 | power = power.sum(axis = 0) |
|
1110 | power = power.sum(axis = 0) | |
1107 | psort = power.ravel().argsort() |
|
1111 | psort = power.ravel().argsort() | |
1108 |
|
1112 | |||
1109 | #Se estima la interferencia promedio en los Espectros de Potencia empleando |
|
1113 | #Se estima la interferencia promedio en los Espectros de Potencia empleando | |
1110 | junkspc_interf = jspectra[ich,:,hei_interf[psort[range(offhei_interf, nhei_interf + offhei_interf)]]] |
|
1114 | junkspc_interf = jspectra[ich,:,hei_interf[psort[range(offhei_interf, nhei_interf + offhei_interf)]]] | |
1111 |
|
1115 | |||
1112 | if noise_exist: |
|
1116 | if noise_exist: | |
1113 | # tmp_noise = jnoise[ich] / num_prof |
|
1117 | # tmp_noise = jnoise[ich] / num_prof | |
1114 | tmp_noise = jnoise[ich] |
|
1118 | tmp_noise = jnoise[ich] | |
1115 | junkspc_interf = junkspc_interf - tmp_noise |
|
1119 | junkspc_interf = junkspc_interf - tmp_noise | |
1116 | #junkspc_interf[:,comp_mask_prof] = 0 |
|
1120 | #junkspc_interf[:,comp_mask_prof] = 0 | |
1117 |
|
1121 | |||
1118 | jspc_interf = junkspc_interf.sum(axis = 0) / nhei_interf |
|
1122 | jspc_interf = junkspc_interf.sum(axis = 0) / nhei_interf | |
1119 | jspc_interf = jspc_interf.transpose() |
|
1123 | jspc_interf = jspc_interf.transpose() | |
1120 | #Calculando el espectro de interferencia promedio |
|
1124 | #Calculando el espectro de interferencia promedio | |
1121 | noiseid = numpy.where(jspc_interf <= tmp_noise/ math.sqrt(num_incoh)) |
|
1125 | noiseid = numpy.where(jspc_interf <= tmp_noise/ math.sqrt(num_incoh)) | |
1122 | noiseid = noiseid[0] |
|
1126 | noiseid = noiseid[0] | |
1123 | cnoiseid = noiseid.size |
|
1127 | cnoiseid = noiseid.size | |
1124 | interfid = numpy.where(jspc_interf > tmp_noise/ math.sqrt(num_incoh)) |
|
1128 | interfid = numpy.where(jspc_interf > tmp_noise/ math.sqrt(num_incoh)) | |
1125 | interfid = interfid[0] |
|
1129 | interfid = interfid[0] | |
1126 | cinterfid = interfid.size |
|
1130 | cinterfid = interfid.size | |
1127 |
|
1131 | |||
1128 | if (cnoiseid > 0): jspc_interf[noiseid] = 0 |
|
1132 | if (cnoiseid > 0): jspc_interf[noiseid] = 0 | |
1129 |
|
1133 | |||
1130 | #Expandiendo los perfiles a limpiar |
|
1134 | #Expandiendo los perfiles a limpiar | |
1131 | if (cinterfid > 0): |
|
1135 | if (cinterfid > 0): | |
1132 | new_interfid = (numpy.r_[interfid - 1, interfid, interfid + 1] + num_prof)%num_prof |
|
1136 | new_interfid = (numpy.r_[interfid - 1, interfid, interfid + 1] + num_prof)%num_prof | |
1133 | new_interfid = numpy.asarray(new_interfid) |
|
1137 | new_interfid = numpy.asarray(new_interfid) | |
1134 | new_interfid = {x for x in new_interfid} |
|
1138 | new_interfid = {x for x in new_interfid} | |
1135 | new_interfid = numpy.array(list(new_interfid)) |
|
1139 | new_interfid = numpy.array(list(new_interfid)) | |
1136 | new_cinterfid = new_interfid.size |
|
1140 | new_cinterfid = new_interfid.size | |
1137 | else: new_cinterfid = 0 |
|
1141 | else: new_cinterfid = 0 | |
1138 |
|
1142 | |||
1139 | for ip in range(new_cinterfid): |
|
1143 | for ip in range(new_cinterfid): | |
1140 | ind = junkspc_interf[:,new_interfid[ip]].ravel().argsort() |
|
1144 | ind = junkspc_interf[:,new_interfid[ip]].ravel().argsort() | |
1141 | jspc_interf[new_interfid[ip]] = junkspc_interf[ind[nhei_interf/2],new_interfid[ip]] |
|
1145 | jspc_interf[new_interfid[ip]] = junkspc_interf[ind[nhei_interf/2],new_interfid[ip]] | |
1142 |
|
1146 | |||
1143 |
|
1147 | |||
1144 | jspectra[ich,:,ind_hei] = jspectra[ich,:,ind_hei] - jspc_interf #Corregir indices |
|
1148 | jspectra[ich,:,ind_hei] = jspectra[ich,:,ind_hei] - jspc_interf #Corregir indices | |
1145 |
|
1149 | |||
1146 | #Removiendo la interferencia del punto de mayor interferencia |
|
1150 | #Removiendo la interferencia del punto de mayor interferencia | |
1147 | ListAux = jspc_interf[mask_prof].tolist() |
|
1151 | ListAux = jspc_interf[mask_prof].tolist() | |
1148 | maxid = ListAux.index(max(ListAux)) |
|
1152 | maxid = ListAux.index(max(ListAux)) | |
1149 |
|
1153 | |||
1150 |
|
1154 | |||
1151 | if cinterfid > 0: |
|
1155 | if cinterfid > 0: | |
1152 | for ip in range(cinterfid*(interf == 2) - 1): |
|
1156 | for ip in range(cinterfid*(interf == 2) - 1): | |
1153 | ind = (jspectra[ich,interfid[ip],:] < tmp_noise*(1 + 1/math.sqrt(num_incoh))).nonzero() |
|
1157 | ind = (jspectra[ich,interfid[ip],:] < tmp_noise*(1 + 1/math.sqrt(num_incoh))).nonzero() | |
1154 | cind = len(ind) |
|
1158 | cind = len(ind) | |
1155 |
|
1159 | |||
1156 | if (cind > 0): |
|
1160 | if (cind > 0): | |
1157 | jspectra[ich,interfid[ip],ind] = tmp_noise*(1 + (numpy.random.uniform(cind) - 0.5)/math.sqrt(num_incoh)) |
|
1161 | jspectra[ich,interfid[ip],ind] = tmp_noise*(1 + (numpy.random.uniform(cind) - 0.5)/math.sqrt(num_incoh)) | |
1158 |
|
1162 | |||
1159 | ind = numpy.array([-2,-1,1,2]) |
|
1163 | ind = numpy.array([-2,-1,1,2]) | |
1160 | xx = numpy.zeros([4,4]) |
|
1164 | xx = numpy.zeros([4,4]) | |
1161 |
|
1165 | |||
1162 | for id1 in range(4): |
|
1166 | for id1 in range(4): | |
1163 | xx[:,id1] = ind[id1]**numpy.asarray(range(4)) |
|
1167 | xx[:,id1] = ind[id1]**numpy.asarray(range(4)) | |
1164 |
|
1168 | |||
1165 | xx_inv = numpy.linalg.inv(xx) |
|
1169 | xx_inv = numpy.linalg.inv(xx) | |
1166 | xx = xx_inv[:,0] |
|
1170 | xx = xx_inv[:,0] | |
1167 | ind = (ind + maxid + num_mask_prof)%num_mask_prof |
|
1171 | ind = (ind + maxid + num_mask_prof)%num_mask_prof | |
1168 | yy = jspectra[ich,mask_prof[ind],:] |
|
1172 | yy = jspectra[ich,mask_prof[ind],:] | |
1169 | jspectra[ich,mask_prof[maxid],:] = numpy.dot(yy.transpose(),xx) |
|
1173 | jspectra[ich,mask_prof[maxid],:] = numpy.dot(yy.transpose(),xx) | |
1170 |
|
1174 | |||
1171 |
|
1175 | |||
1172 | indAux = (jspectra[ich,:,:] < tmp_noise*(1-1/math.sqrt(num_incoh))).nonzero() |
|
1176 | indAux = (jspectra[ich,:,:] < tmp_noise*(1-1/math.sqrt(num_incoh))).nonzero() | |
1173 | jspectra[ich,indAux[0],indAux[1]] = tmp_noise * (1 - 1/math.sqrt(num_incoh)) |
|
1177 | jspectra[ich,indAux[0],indAux[1]] = tmp_noise * (1 - 1/math.sqrt(num_incoh)) | |
1174 |
|
1178 | |||
1175 | #Remocion de Interferencia en el Cross Spectra |
|
1179 | #Remocion de Interferencia en el Cross Spectra | |
1176 | if jcspectra == None: return jspectra, jcspectra |
|
1180 | if jcspectra == None: return jspectra, jcspectra | |
1177 | num_pairs = jcspectra.size/(num_prof*num_hei) |
|
1181 | num_pairs = jcspectra.size/(num_prof*num_hei) | |
1178 | jcspectra = jcspectra.reshape(num_pairs, num_prof, num_hei) |
|
1182 | jcspectra = jcspectra.reshape(num_pairs, num_prof, num_hei) | |
1179 |
|
1183 | |||
1180 | for ip in range(num_pairs): |
|
1184 | for ip in range(num_pairs): | |
1181 |
|
1185 | |||
1182 | #------------------------------------------- |
|
1186 | #------------------------------------------- | |
1183 |
|
1187 | |||
1184 | cspower = numpy.abs(jcspectra[ip,mask_prof,:]) |
|
1188 | cspower = numpy.abs(jcspectra[ip,mask_prof,:]) | |
1185 | cspower = cspower[:,hei_interf] |
|
1189 | cspower = cspower[:,hei_interf] | |
1186 | cspower = cspower.sum(axis = 0) |
|
1190 | cspower = cspower.sum(axis = 0) | |
1187 |
|
1191 | |||
1188 | cspsort = cspower.ravel().argsort() |
|
1192 | cspsort = cspower.ravel().argsort() | |
1189 | junkcspc_interf = jcspectra[ip,:,hei_interf[cspsort[range(offhei_interf, nhei_interf + offhei_interf)]]] |
|
1193 | junkcspc_interf = jcspectra[ip,:,hei_interf[cspsort[range(offhei_interf, nhei_interf + offhei_interf)]]] | |
1190 | junkcspc_interf = junkcspc_interf.transpose() |
|
1194 | junkcspc_interf = junkcspc_interf.transpose() | |
1191 | jcspc_interf = junkcspc_interf.sum(axis = 1)/nhei_interf |
|
1195 | jcspc_interf = junkcspc_interf.sum(axis = 1)/nhei_interf | |
1192 |
|
1196 | |||
1193 | ind = numpy.abs(jcspc_interf[mask_prof]).ravel().argsort() |
|
1197 | ind = numpy.abs(jcspc_interf[mask_prof]).ravel().argsort() | |
1194 |
|
1198 | |||
1195 | median_real = numpy.median(numpy.real(junkcspc_interf[mask_prof[ind[range(3*num_prof/4)]],:])) |
|
1199 | median_real = numpy.median(numpy.real(junkcspc_interf[mask_prof[ind[range(3*num_prof/4)]],:])) | |
1196 | median_imag = numpy.median(numpy.imag(junkcspc_interf[mask_prof[ind[range(3*num_prof/4)]],:])) |
|
1200 | median_imag = numpy.median(numpy.imag(junkcspc_interf[mask_prof[ind[range(3*num_prof/4)]],:])) | |
1197 | junkcspc_interf[comp_mask_prof,:] = numpy.complex(median_real, median_imag) |
|
1201 | junkcspc_interf[comp_mask_prof,:] = numpy.complex(median_real, median_imag) | |
1198 |
|
1202 | |||
1199 | for iprof in range(num_prof): |
|
1203 | for iprof in range(num_prof): | |
1200 | ind = numpy.abs(junkcspc_interf[iprof,:]).ravel().argsort() |
|
1204 | ind = numpy.abs(junkcspc_interf[iprof,:]).ravel().argsort() | |
1201 | jcspc_interf[iprof] = junkcspc_interf[iprof, ind[nhei_interf/2]] |
|
1205 | jcspc_interf[iprof] = junkcspc_interf[iprof, ind[nhei_interf/2]] | |
1202 |
|
1206 | |||
1203 | #Removiendo la Interferencia |
|
1207 | #Removiendo la Interferencia | |
1204 | jcspectra[ip,:,ind_hei] = jcspectra[ip,:,ind_hei] - jcspc_interf |
|
1208 | jcspectra[ip,:,ind_hei] = jcspectra[ip,:,ind_hei] - jcspc_interf | |
1205 |
|
1209 | |||
1206 | ListAux = numpy.abs(jcspc_interf[mask_prof]).tolist() |
|
1210 | ListAux = numpy.abs(jcspc_interf[mask_prof]).tolist() | |
1207 | maxid = ListAux.index(max(ListAux)) |
|
1211 | maxid = ListAux.index(max(ListAux)) | |
1208 |
|
1212 | |||
1209 | ind = numpy.array([-2,-1,1,2]) |
|
1213 | ind = numpy.array([-2,-1,1,2]) | |
1210 | xx = numpy.zeros([4,4]) |
|
1214 | xx = numpy.zeros([4,4]) | |
1211 |
|
1215 | |||
1212 | for id1 in range(4): |
|
1216 | for id1 in range(4): | |
1213 | xx[:,id1] = ind[id1]**numpy.asarray(range(4)) |
|
1217 | xx[:,id1] = ind[id1]**numpy.asarray(range(4)) | |
1214 |
|
1218 | |||
1215 | xx_inv = numpy.linalg.inv(xx) |
|
1219 | xx_inv = numpy.linalg.inv(xx) | |
1216 | xx = xx_inv[:,0] |
|
1220 | xx = xx_inv[:,0] | |
1217 |
|
1221 | |||
1218 | ind = (ind + maxid + num_mask_prof)%num_mask_prof |
|
1222 | ind = (ind + maxid + num_mask_prof)%num_mask_prof | |
1219 | yy = jcspectra[ip,mask_prof[ind],:] |
|
1223 | yy = jcspectra[ip,mask_prof[ind],:] | |
1220 | jcspectra[ip,mask_prof[maxid],:] = numpy.dot(yy.transpose(),xx) |
|
1224 | jcspectra[ip,mask_prof[maxid],:] = numpy.dot(yy.transpose(),xx) | |
1221 |
|
1225 | |||
1222 | #Guardar Resultados |
|
1226 | #Guardar Resultados | |
1223 | self.dataOut.data_spc = jspectra |
|
1227 | self.dataOut.data_spc = jspectra | |
1224 | self.dataOut.data_cspc = jcspectra |
|
1228 | self.dataOut.data_cspc = jcspectra | |
1225 |
|
1229 | |||
1226 | return 1 |
|
1230 | return 1 | |
1227 |
|
1231 | |||
1228 | def setRadarFrequency(self, frequency=None): |
|
1232 | def setRadarFrequency(self, frequency=None): | |
1229 | if frequency != None: |
|
1233 | if frequency != None: | |
1230 | self.dataOut.frequency = frequency |
|
1234 | self.dataOut.frequency = frequency | |
1231 |
|
1235 | |||
1232 | return 1 |
|
1236 | return 1 | |
1233 |
|
1237 | |||
1234 | def getNoise(self, minHei=None, maxHei=None, minVel=None, maxVel=None): |
|
1238 | def getNoise(self, minHei=None, maxHei=None, minVel=None, maxVel=None): | |
1235 | #validacion de rango |
|
1239 | #validacion de rango | |
1236 | if minHei == None: |
|
1240 | if minHei == None: | |
1237 | minHei = self.dataOut.heightList[0] |
|
1241 | minHei = self.dataOut.heightList[0] | |
1238 |
|
1242 | |||
1239 | if maxHei == None: |
|
1243 | if maxHei == None: | |
1240 | maxHei = self.dataOut.heightList[-1] |
|
1244 | maxHei = self.dataOut.heightList[-1] | |
1241 |
|
1245 | |||
1242 | if (minHei < self.dataOut.heightList[0]) or (minHei > maxHei): |
|
1246 | if (minHei < self.dataOut.heightList[0]) or (minHei > maxHei): | |
1243 | print 'minHei: %.2f is out of the heights range'%(minHei) |
|
1247 | print 'minHei: %.2f is out of the heights range'%(minHei) | |
1244 | print 'minHei is setting to %.2f'%(self.dataOut.heightList[0]) |
|
1248 | print 'minHei is setting to %.2f'%(self.dataOut.heightList[0]) | |
1245 | minHei = self.dataOut.heightList[0] |
|
1249 | minHei = self.dataOut.heightList[0] | |
1246 |
|
1250 | |||
1247 | if (maxHei > self.dataOut.heightList[-1]) or (maxHei < minHei): |
|
1251 | if (maxHei > self.dataOut.heightList[-1]) or (maxHei < minHei): | |
1248 | print 'maxHei: %.2f is out of the heights range'%(maxHei) |
|
1252 | print 'maxHei: %.2f is out of the heights range'%(maxHei) | |
1249 | print 'maxHei is setting to %.2f'%(self.dataOut.heightList[-1]) |
|
1253 | print 'maxHei is setting to %.2f'%(self.dataOut.heightList[-1]) | |
1250 | maxHei = self.dataOut.heightList[-1] |
|
1254 | maxHei = self.dataOut.heightList[-1] | |
1251 |
|
1255 | |||
1252 | # validacion de velocidades |
|
1256 | # validacion de velocidades | |
1253 | velrange = self.dataOut.getVelRange(1) |
|
1257 | velrange = self.dataOut.getVelRange(1) | |
1254 |
|
1258 | |||
1255 | if minVel == None: |
|
1259 | if minVel == None: | |
1256 | minVel = velrange[0] |
|
1260 | minVel = velrange[0] | |
1257 |
|
1261 | |||
1258 | if maxVel == None: |
|
1262 | if maxVel == None: | |
1259 | maxVel = velrange[-1] |
|
1263 | maxVel = velrange[-1] | |
1260 |
|
1264 | |||
1261 | if (minVel < velrange[0]) or (minVel > maxVel): |
|
1265 | if (minVel < velrange[0]) or (minVel > maxVel): | |
1262 | print 'minVel: %.2f is out of the velocity range'%(minVel) |
|
1266 | print 'minVel: %.2f is out of the velocity range'%(minVel) | |
1263 | print 'minVel is setting to %.2f'%(velrange[0]) |
|
1267 | print 'minVel is setting to %.2f'%(velrange[0]) | |
1264 | minVel = velrange[0] |
|
1268 | minVel = velrange[0] | |
1265 |
|
1269 | |||
1266 | if (maxVel > velrange[-1]) or (maxVel < minVel): |
|
1270 | if (maxVel > velrange[-1]) or (maxVel < minVel): | |
1267 | print 'maxVel: %.2f is out of the velocity range'%(maxVel) |
|
1271 | print 'maxVel: %.2f is out of the velocity range'%(maxVel) | |
1268 | print 'maxVel is setting to %.2f'%(velrange[-1]) |
|
1272 | print 'maxVel is setting to %.2f'%(velrange[-1]) | |
1269 | maxVel = velrange[-1] |
|
1273 | maxVel = velrange[-1] | |
1270 |
|
1274 | |||
1271 | # seleccion de indices para rango |
|
1275 | # seleccion de indices para rango | |
1272 | minIndex = 0 |
|
1276 | minIndex = 0 | |
1273 | maxIndex = 0 |
|
1277 | maxIndex = 0 | |
1274 | heights = self.dataOut.heightList |
|
1278 | heights = self.dataOut.heightList | |
1275 |
|
1279 | |||
1276 | inda = numpy.where(heights >= minHei) |
|
1280 | inda = numpy.where(heights >= minHei) | |
1277 | indb = numpy.where(heights <= maxHei) |
|
1281 | indb = numpy.where(heights <= maxHei) | |
1278 |
|
1282 | |||
1279 | try: |
|
1283 | try: | |
1280 | minIndex = inda[0][0] |
|
1284 | minIndex = inda[0][0] | |
1281 | except: |
|
1285 | except: | |
1282 | minIndex = 0 |
|
1286 | minIndex = 0 | |
1283 |
|
1287 | |||
1284 | try: |
|
1288 | try: | |
1285 | maxIndex = indb[0][-1] |
|
1289 | maxIndex = indb[0][-1] | |
1286 | except: |
|
1290 | except: | |
1287 | maxIndex = len(heights) |
|
1291 | maxIndex = len(heights) | |
1288 |
|
1292 | |||
1289 | if (minIndex < 0) or (minIndex > maxIndex): |
|
1293 | if (minIndex < 0) or (minIndex > maxIndex): | |
1290 | raise ValueError, "some value in (%d,%d) is not valid" % (minIndex, maxIndex) |
|
1294 | raise ValueError, "some value in (%d,%d) is not valid" % (minIndex, maxIndex) | |
1291 |
|
1295 | |||
1292 | if (maxIndex >= self.dataOut.nHeights): |
|
1296 | if (maxIndex >= self.dataOut.nHeights): | |
1293 | maxIndex = self.dataOut.nHeights-1 |
|
1297 | maxIndex = self.dataOut.nHeights-1 | |
1294 |
|
1298 | |||
1295 | # seleccion de indices para velocidades |
|
1299 | # seleccion de indices para velocidades | |
1296 | indminvel = numpy.where(velrange >= minVel) |
|
1300 | indminvel = numpy.where(velrange >= minVel) | |
1297 | indmaxvel = numpy.where(velrange <= maxVel) |
|
1301 | indmaxvel = numpy.where(velrange <= maxVel) | |
1298 | try: |
|
1302 | try: | |
1299 | minIndexVel = indminvel[0][0] |
|
1303 | minIndexVel = indminvel[0][0] | |
1300 | except: |
|
1304 | except: | |
1301 | minIndexVel = 0 |
|
1305 | minIndexVel = 0 | |
1302 |
|
1306 | |||
1303 | try: |
|
1307 | try: | |
1304 | maxIndexVel = indmaxvel[0][-1] |
|
1308 | maxIndexVel = indmaxvel[0][-1] | |
1305 | except: |
|
1309 | except: | |
1306 | maxIndexVel = len(velrange) |
|
1310 | maxIndexVel = len(velrange) | |
1307 |
|
1311 | |||
1308 | #seleccion del espectro |
|
1312 | #seleccion del espectro | |
1309 | data_spc = self.dataOut.data_spc[:,minIndexVel:maxIndexVel+1,minIndex:maxIndex+1] |
|
1313 | data_spc = self.dataOut.data_spc[:,minIndexVel:maxIndexVel+1,minIndex:maxIndex+1] | |
1310 | #estimacion de ruido |
|
1314 | #estimacion de ruido | |
1311 | noise = numpy.zeros(self.dataOut.nChannels) |
|
1315 | noise = numpy.zeros(self.dataOut.nChannels) | |
1312 |
|
1316 | |||
1313 | for channel in range(self.dataOut.nChannels): |
|
1317 | for channel in range(self.dataOut.nChannels): | |
1314 | daux = data_spc[channel,:,:] |
|
1318 | daux = data_spc[channel,:,:] | |
1315 | noise[channel] = hildebrand_sekhon(daux, self.dataOut.nIncohInt) |
|
1319 | noise[channel] = hildebrand_sekhon(daux, self.dataOut.nIncohInt) | |
1316 |
|
1320 | |||
1317 | self.dataOut.noise = noise.copy() |
|
1321 | self.dataOut.noise = noise.copy() | |
1318 |
|
1322 | |||
1319 | return 1 |
|
1323 | return 1 | |
1320 |
|
1324 | |||
1321 |
|
1325 | |||
1322 | class IncohInt(Operation): |
|
1326 | class IncohInt(Operation): | |
1323 |
|
1327 | |||
1324 |
|
1328 | |||
1325 | __profIndex = 0 |
|
1329 | __profIndex = 0 | |
1326 | __withOverapping = False |
|
1330 | __withOverapping = False | |
1327 |
|
1331 | |||
1328 | __byTime = False |
|
1332 | __byTime = False | |
1329 | __initime = None |
|
1333 | __initime = None | |
1330 | __lastdatatime = None |
|
1334 | __lastdatatime = None | |
1331 | __integrationtime = None |
|
1335 | __integrationtime = None | |
1332 |
|
1336 | |||
1333 | __buffer_spc = None |
|
1337 | __buffer_spc = None | |
1334 | __buffer_cspc = None |
|
1338 | __buffer_cspc = None | |
1335 | __buffer_dc = None |
|
1339 | __buffer_dc = None | |
1336 |
|
1340 | |||
1337 | __dataReady = False |
|
1341 | __dataReady = False | |
1338 |
|
1342 | |||
1339 | __timeInterval = None |
|
1343 | __timeInterval = None | |
1340 |
|
1344 | |||
1341 | n = None |
|
1345 | n = None | |
1342 |
|
1346 | |||
1343 |
|
1347 | |||
1344 |
|
1348 | |||
1345 | def __init__(self): |
|
1349 | def __init__(self): | |
1346 |
|
1350 | |||
1347 | self.__isConfig = False |
|
1351 | self.__isConfig = False | |
1348 |
|
1352 | |||
1349 | def setup(self, n=None, timeInterval=None, overlapping=False): |
|
1353 | def setup(self, n=None, timeInterval=None, overlapping=False): | |
1350 | """ |
|
1354 | """ | |
1351 | Set the parameters of the integration class. |
|
1355 | Set the parameters of the integration class. | |
1352 |
|
1356 | |||
1353 | Inputs: |
|
1357 | Inputs: | |
1354 |
|
1358 | |||
1355 | n : Number of coherent integrations |
|
1359 | n : Number of coherent integrations | |
1356 | timeInterval : Time of integration. If the parameter "n" is selected this one does not work |
|
1360 | timeInterval : Time of integration. If the parameter "n" is selected this one does not work | |
1357 | overlapping : |
|
1361 | overlapping : | |
1358 |
|
1362 | |||
1359 | """ |
|
1363 | """ | |
1360 |
|
1364 | |||
1361 | self.__initime = None |
|
1365 | self.__initime = None | |
1362 | self.__lastdatatime = 0 |
|
1366 | self.__lastdatatime = 0 | |
1363 | self.__buffer_spc = None |
|
1367 | self.__buffer_spc = None | |
1364 | self.__buffer_cspc = None |
|
1368 | self.__buffer_cspc = None | |
1365 | self.__buffer_dc = None |
|
1369 | self.__buffer_dc = None | |
1366 | self.__dataReady = False |
|
1370 | self.__dataReady = False | |
1367 |
|
1371 | |||
1368 |
|
1372 | |||
1369 | if n == None and timeInterval == None: |
|
1373 | if n == None and timeInterval == None: | |
1370 | raise ValueError, "n or timeInterval should be specified ..." |
|
1374 | raise ValueError, "n or timeInterval should be specified ..." | |
1371 |
|
1375 | |||
1372 | if n != None: |
|
1376 | if n != None: | |
1373 | self.n = n |
|
1377 | self.n = n | |
1374 | self.__byTime = False |
|
1378 | self.__byTime = False | |
1375 | else: |
|
1379 | else: | |
1376 | self.__integrationtime = timeInterval #if (type(timeInterval)!=integer) -> change this line |
|
1380 | self.__integrationtime = timeInterval #if (type(timeInterval)!=integer) -> change this line | |
1377 | self.n = 9999 |
|
1381 | self.n = 9999 | |
1378 | self.__byTime = True |
|
1382 | self.__byTime = True | |
1379 |
|
1383 | |||
1380 | if overlapping: |
|
1384 | if overlapping: | |
1381 | self.__withOverapping = True |
|
1385 | self.__withOverapping = True | |
1382 | else: |
|
1386 | else: | |
1383 | self.__withOverapping = False |
|
1387 | self.__withOverapping = False | |
1384 | self.__buffer_spc = 0 |
|
1388 | self.__buffer_spc = 0 | |
1385 | self.__buffer_cspc = 0 |
|
1389 | self.__buffer_cspc = 0 | |
1386 | self.__buffer_dc = 0 |
|
1390 | self.__buffer_dc = 0 | |
1387 |
|
1391 | |||
1388 | self.__profIndex = 0 |
|
1392 | self.__profIndex = 0 | |
1389 |
|
1393 | |||
1390 | def putData(self, data_spc, data_cspc, data_dc): |
|
1394 | def putData(self, data_spc, data_cspc, data_dc): | |
1391 |
|
1395 | |||
1392 | """ |
|
1396 | """ | |
1393 | Add a profile to the __buffer_spc and increase in one the __profileIndex |
|
1397 | Add a profile to the __buffer_spc and increase in one the __profileIndex | |
1394 |
|
1398 | |||
1395 | """ |
|
1399 | """ | |
1396 |
|
1400 | |||
1397 | if not self.__withOverapping: |
|
1401 | if not self.__withOverapping: | |
1398 | self.__buffer_spc += data_spc |
|
1402 | self.__buffer_spc += data_spc | |
1399 |
|
1403 | |||
1400 | if data_cspc == None: |
|
1404 | if data_cspc == None: | |
1401 | self.__buffer_cspc = None |
|
1405 | self.__buffer_cspc = None | |
1402 | else: |
|
1406 | else: | |
1403 | self.__buffer_cspc += data_cspc |
|
1407 | self.__buffer_cspc += data_cspc | |
1404 |
|
1408 | |||
1405 | if data_dc == None: |
|
1409 | if data_dc == None: | |
1406 | self.__buffer_dc = None |
|
1410 | self.__buffer_dc = None | |
1407 | else: |
|
1411 | else: | |
1408 | self.__buffer_dc += data_dc |
|
1412 | self.__buffer_dc += data_dc | |
1409 |
|
1413 | |||
1410 | self.__profIndex += 1 |
|
1414 | self.__profIndex += 1 | |
1411 | return |
|
1415 | return | |
1412 |
|
1416 | |||
1413 | #Overlapping data |
|
1417 | #Overlapping data | |
1414 | nChannels, nFFTPoints, nHeis = data_spc.shape |
|
1418 | nChannels, nFFTPoints, nHeis = data_spc.shape | |
1415 | data_spc = numpy.reshape(data_spc, (1, nChannels, nFFTPoints, nHeis)) |
|
1419 | data_spc = numpy.reshape(data_spc, (1, nChannels, nFFTPoints, nHeis)) | |
1416 | if data_cspc != None: |
|
1420 | if data_cspc != None: | |
1417 | data_cspc = numpy.reshape(data_cspc, (1, -1, nFFTPoints, nHeis)) |
|
1421 | data_cspc = numpy.reshape(data_cspc, (1, -1, nFFTPoints, nHeis)) | |
1418 | if data_dc != None: |
|
1422 | if data_dc != None: | |
1419 | data_dc = numpy.reshape(data_dc, (1, -1, nHeis)) |
|
1423 | data_dc = numpy.reshape(data_dc, (1, -1, nHeis)) | |
1420 |
|
1424 | |||
1421 | #If the buffer is empty then it takes the data value |
|
1425 | #If the buffer is empty then it takes the data value | |
1422 | if self.__buffer_spc == None: |
|
1426 | if self.__buffer_spc == None: | |
1423 | self.__buffer_spc = data_spc |
|
1427 | self.__buffer_spc = data_spc | |
1424 |
|
1428 | |||
1425 | if data_cspc == None: |
|
1429 | if data_cspc == None: | |
1426 | self.__buffer_cspc = None |
|
1430 | self.__buffer_cspc = None | |
1427 | else: |
|
1431 | else: | |
1428 | self.__buffer_cspc += data_cspc |
|
1432 | self.__buffer_cspc += data_cspc | |
1429 |
|
1433 | |||
1430 | if data_dc == None: |
|
1434 | if data_dc == None: | |
1431 | self.__buffer_dc = None |
|
1435 | self.__buffer_dc = None | |
1432 | else: |
|
1436 | else: | |
1433 | self.__buffer_dc += data_dc |
|
1437 | self.__buffer_dc += data_dc | |
1434 |
|
1438 | |||
1435 | self.__profIndex += 1 |
|
1439 | self.__profIndex += 1 | |
1436 | return |
|
1440 | return | |
1437 |
|
1441 | |||
1438 | #If the buffer length is lower than n then stakcing the data value |
|
1442 | #If the buffer length is lower than n then stakcing the data value | |
1439 | if self.__profIndex < self.n: |
|
1443 | if self.__profIndex < self.n: | |
1440 | self.__buffer_spc = numpy.vstack((self.__buffer_spc, data_spc)) |
|
1444 | self.__buffer_spc = numpy.vstack((self.__buffer_spc, data_spc)) | |
1441 |
|
1445 | |||
1442 | if data_cspc != None: |
|
1446 | if data_cspc != None: | |
1443 | self.__buffer_cspc = numpy.vstack((self.__buffer_cspc, data_cspc)) |
|
1447 | self.__buffer_cspc = numpy.vstack((self.__buffer_cspc, data_cspc)) | |
1444 |
|
1448 | |||
1445 | if data_dc != None: |
|
1449 | if data_dc != None: | |
1446 | self.__buffer_dc = numpy.vstack((self.__buffer_dc, data_dc)) |
|
1450 | self.__buffer_dc = numpy.vstack((self.__buffer_dc, data_dc)) | |
1447 |
|
1451 | |||
1448 | self.__profIndex += 1 |
|
1452 | self.__profIndex += 1 | |
1449 | return |
|
1453 | return | |
1450 |
|
1454 | |||
1451 | #If the buffer length is equal to n then replacing the last buffer value with the data value |
|
1455 | #If the buffer length is equal to n then replacing the last buffer value with the data value | |
1452 | self.__buffer_spc = numpy.roll(self.__buffer_spc, -1, axis=0) |
|
1456 | self.__buffer_spc = numpy.roll(self.__buffer_spc, -1, axis=0) | |
1453 | self.__buffer_spc[self.n-1] = data_spc |
|
1457 | self.__buffer_spc[self.n-1] = data_spc | |
1454 |
|
1458 | |||
1455 | if data_cspc != None: |
|
1459 | if data_cspc != None: | |
1456 | self.__buffer_cspc = numpy.roll(self.__buffer_cspc, -1, axis=0) |
|
1460 | self.__buffer_cspc = numpy.roll(self.__buffer_cspc, -1, axis=0) | |
1457 | self.__buffer_cspc[self.n-1] = data_cspc |
|
1461 | self.__buffer_cspc[self.n-1] = data_cspc | |
1458 |
|
1462 | |||
1459 | if data_dc != None: |
|
1463 | if data_dc != None: | |
1460 | self.__buffer_dc = numpy.roll(self.__buffer_dc, -1, axis=0) |
|
1464 | self.__buffer_dc = numpy.roll(self.__buffer_dc, -1, axis=0) | |
1461 | self.__buffer_dc[self.n-1] = data_dc |
|
1465 | self.__buffer_dc[self.n-1] = data_dc | |
1462 |
|
1466 | |||
1463 | self.__profIndex = self.n |
|
1467 | self.__profIndex = self.n | |
1464 | return |
|
1468 | return | |
1465 |
|
1469 | |||
1466 |
|
1470 | |||
1467 | def pushData(self): |
|
1471 | def pushData(self): | |
1468 | """ |
|
1472 | """ | |
1469 | Return the sum of the last profiles and the profiles used in the sum. |
|
1473 | Return the sum of the last profiles and the profiles used in the sum. | |
1470 |
|
1474 | |||
1471 | Affected: |
|
1475 | Affected: | |
1472 |
|
1476 | |||
1473 | self.__profileIndex |
|
1477 | self.__profileIndex | |
1474 |
|
1478 | |||
1475 | """ |
|
1479 | """ | |
1476 | data_spc = None |
|
1480 | data_spc = None | |
1477 | data_cspc = None |
|
1481 | data_cspc = None | |
1478 | data_dc = None |
|
1482 | data_dc = None | |
1479 |
|
1483 | |||
1480 | if not self.__withOverapping: |
|
1484 | if not self.__withOverapping: | |
1481 | data_spc = self.__buffer_spc |
|
1485 | data_spc = self.__buffer_spc | |
1482 | data_cspc = self.__buffer_cspc |
|
1486 | data_cspc = self.__buffer_cspc | |
1483 | data_dc = self.__buffer_dc |
|
1487 | data_dc = self.__buffer_dc | |
1484 |
|
1488 | |||
1485 | n = self.__profIndex |
|
1489 | n = self.__profIndex | |
1486 |
|
1490 | |||
1487 | self.__buffer_spc = 0 |
|
1491 | self.__buffer_spc = 0 | |
1488 | self.__buffer_cspc = 0 |
|
1492 | self.__buffer_cspc = 0 | |
1489 | self.__buffer_dc = 0 |
|
1493 | self.__buffer_dc = 0 | |
1490 | self.__profIndex = 0 |
|
1494 | self.__profIndex = 0 | |
1491 |
|
1495 | |||
1492 | return data_spc, data_cspc, data_dc, n |
|
1496 | return data_spc, data_cspc, data_dc, n | |
1493 |
|
1497 | |||
1494 | #Integration with Overlapping |
|
1498 | #Integration with Overlapping | |
1495 | data_spc = numpy.sum(self.__buffer_spc, axis=0) |
|
1499 | data_spc = numpy.sum(self.__buffer_spc, axis=0) | |
1496 |
|
1500 | |||
1497 | if self.__buffer_cspc != None: |
|
1501 | if self.__buffer_cspc != None: | |
1498 | data_cspc = numpy.sum(self.__buffer_cspc, axis=0) |
|
1502 | data_cspc = numpy.sum(self.__buffer_cspc, axis=0) | |
1499 |
|
1503 | |||
1500 | if self.__buffer_dc != None: |
|
1504 | if self.__buffer_dc != None: | |
1501 | data_dc = numpy.sum(self.__buffer_dc, axis=0) |
|
1505 | data_dc = numpy.sum(self.__buffer_dc, axis=0) | |
1502 |
|
1506 | |||
1503 | n = self.__profIndex |
|
1507 | n = self.__profIndex | |
1504 |
|
1508 | |||
1505 | return data_spc, data_cspc, data_dc, n |
|
1509 | return data_spc, data_cspc, data_dc, n | |
1506 |
|
1510 | |||
1507 | def byProfiles(self, *args): |
|
1511 | def byProfiles(self, *args): | |
1508 |
|
1512 | |||
1509 | self.__dataReady = False |
|
1513 | self.__dataReady = False | |
1510 | avgdata_spc = None |
|
1514 | avgdata_spc = None | |
1511 | avgdata_cspc = None |
|
1515 | avgdata_cspc = None | |
1512 | avgdata_dc = None |
|
1516 | avgdata_dc = None | |
1513 | n = None |
|
1517 | n = None | |
1514 |
|
1518 | |||
1515 | self.putData(*args) |
|
1519 | self.putData(*args) | |
1516 |
|
1520 | |||
1517 | if self.__profIndex == self.n: |
|
1521 | if self.__profIndex == self.n: | |
1518 |
|
1522 | |||
1519 | avgdata_spc, avgdata_cspc, avgdata_dc, n = self.pushData() |
|
1523 | avgdata_spc, avgdata_cspc, avgdata_dc, n = self.pushData() | |
1520 | self.__dataReady = True |
|
1524 | self.__dataReady = True | |
1521 |
|
1525 | |||
1522 | return avgdata_spc, avgdata_cspc, avgdata_dc |
|
1526 | return avgdata_spc, avgdata_cspc, avgdata_dc | |
1523 |
|
1527 | |||
1524 | def byTime(self, datatime, *args): |
|
1528 | def byTime(self, datatime, *args): | |
1525 |
|
1529 | |||
1526 | self.__dataReady = False |
|
1530 | self.__dataReady = False | |
1527 | avgdata_spc = None |
|
1531 | avgdata_spc = None | |
1528 | avgdata_cspc = None |
|
1532 | avgdata_cspc = None | |
1529 | avgdata_dc = None |
|
1533 | avgdata_dc = None | |
1530 | n = None |
|
1534 | n = None | |
1531 |
|
1535 | |||
1532 | self.putData(*args) |
|
1536 | self.putData(*args) | |
1533 |
|
1537 | |||
1534 | if (datatime - self.__initime) >= self.__integrationtime: |
|
1538 | if (datatime - self.__initime) >= self.__integrationtime: | |
1535 | avgdata_spc, avgdata_cspc, avgdata_dc, n = self.pushData() |
|
1539 | avgdata_spc, avgdata_cspc, avgdata_dc, n = self.pushData() | |
1536 | self.n = n |
|
1540 | self.n = n | |
1537 | self.__dataReady = True |
|
1541 | self.__dataReady = True | |
1538 |
|
1542 | |||
1539 | return avgdata_spc, avgdata_cspc, avgdata_dc |
|
1543 | return avgdata_spc, avgdata_cspc, avgdata_dc | |
1540 |
|
1544 | |||
1541 | def integrate(self, datatime, *args): |
|
1545 | def integrate(self, datatime, *args): | |
1542 |
|
1546 | |||
1543 | if self.__initime == None: |
|
1547 | if self.__initime == None: | |
1544 | self.__initime = datatime |
|
1548 | self.__initime = datatime | |
1545 |
|
1549 | |||
1546 | if self.__byTime: |
|
1550 | if self.__byTime: | |
1547 | avgdata_spc, avgdata_cspc, avgdata_dc = self.byTime(datatime, *args) |
|
1551 | avgdata_spc, avgdata_cspc, avgdata_dc = self.byTime(datatime, *args) | |
1548 | else: |
|
1552 | else: | |
1549 | avgdata_spc, avgdata_cspc, avgdata_dc = self.byProfiles(*args) |
|
1553 | avgdata_spc, avgdata_cspc, avgdata_dc = self.byProfiles(*args) | |
1550 |
|
1554 | |||
1551 | self.__lastdatatime = datatime |
|
1555 | self.__lastdatatime = datatime | |
1552 |
|
1556 | |||
1553 | if avgdata_spc == None: |
|
1557 | if avgdata_spc == None: | |
1554 | return None, None, None, None |
|
1558 | return None, None, None, None | |
1555 |
|
1559 | |||
1556 | avgdatatime = self.__initime |
|
1560 | avgdatatime = self.__initime | |
1557 | try: |
|
1561 | try: | |
1558 | self.__timeInterval = (self.__lastdatatime - self.__initime)/(self.n - 1) |
|
1562 | self.__timeInterval = (self.__lastdatatime - self.__initime)/(self.n - 1) | |
1559 | except: |
|
1563 | except: | |
1560 | self.__timeInterval = self.__lastdatatime - self.__initime |
|
1564 | self.__timeInterval = self.__lastdatatime - self.__initime | |
1561 |
|
1565 | |||
1562 | deltatime = datatime -self.__lastdatatime |
|
1566 | deltatime = datatime -self.__lastdatatime | |
1563 |
|
1567 | |||
1564 | if not self.__withOverapping: |
|
1568 | if not self.__withOverapping: | |
1565 | self.__initime = datatime |
|
1569 | self.__initime = datatime | |
1566 | else: |
|
1570 | else: | |
1567 | self.__initime += deltatime |
|
1571 | self.__initime += deltatime | |
1568 |
|
1572 | |||
1569 | return avgdatatime, avgdata_spc, avgdata_cspc, avgdata_dc |
|
1573 | return avgdatatime, avgdata_spc, avgdata_cspc, avgdata_dc | |
1570 |
|
1574 | |||
1571 | def run(self, dataOut, n=None, timeInterval=None, overlapping=False): |
|
1575 | def run(self, dataOut, n=None, timeInterval=None, overlapping=False): | |
1572 |
|
1576 | |||
1573 | if n==1: |
|
1577 | if n==1: | |
1574 | dataOut.flagNoData = False |
|
1578 | dataOut.flagNoData = False | |
1575 | return |
|
1579 | return | |
1576 |
|
1580 | |||
1577 | if not self.__isConfig: |
|
1581 | if not self.__isConfig: | |
1578 | self.setup(n, timeInterval, overlapping) |
|
1582 | self.setup(n, timeInterval, overlapping) | |
1579 | self.__isConfig = True |
|
1583 | self.__isConfig = True | |
1580 |
|
1584 | |||
1581 | avgdatatime, avgdata_spc, avgdata_cspc, avgdata_dc = self.integrate(dataOut.utctime, |
|
1585 | avgdatatime, avgdata_spc, avgdata_cspc, avgdata_dc = self.integrate(dataOut.utctime, | |
1582 | dataOut.data_spc, |
|
1586 | dataOut.data_spc, | |
1583 | dataOut.data_cspc, |
|
1587 | dataOut.data_cspc, | |
1584 | dataOut.data_dc) |
|
1588 | dataOut.data_dc) | |
1585 |
|
1589 | |||
1586 | # dataOut.timeInterval *= n |
|
1590 | # dataOut.timeInterval *= n | |
1587 | dataOut.flagNoData = True |
|
1591 | dataOut.flagNoData = True | |
1588 |
|
1592 | |||
1589 | if self.__dataReady: |
|
1593 | if self.__dataReady: | |
1590 |
|
1594 | |||
1591 | dataOut.data_spc = avgdata_spc |
|
1595 | dataOut.data_spc = avgdata_spc | |
1592 | dataOut.data_cspc = avgdata_cspc |
|
1596 | dataOut.data_cspc = avgdata_cspc | |
1593 | dataOut.data_dc = avgdata_dc |
|
1597 | dataOut.data_dc = avgdata_dc | |
1594 |
|
1598 | |||
1595 | dataOut.nIncohInt *= self.n |
|
1599 | dataOut.nIncohInt *= self.n | |
1596 | dataOut.utctime = avgdatatime |
|
1600 | dataOut.utctime = avgdatatime | |
1597 | #dataOut.timeInterval = dataOut.ippSeconds * dataOut.nCohInt * dataOut.nIncohInt * dataOut.nFFTPoints |
|
1601 | #dataOut.timeInterval = dataOut.ippSeconds * dataOut.nCohInt * dataOut.nIncohInt * dataOut.nFFTPoints | |
1598 | dataOut.timeInterval = self.__timeInterval*self.n |
|
1602 | dataOut.timeInterval = self.__timeInterval*self.n | |
1599 | dataOut.flagNoData = False |
|
1603 | dataOut.flagNoData = False | |
1600 |
|
1604 | |||
1601 | class ProfileConcat(Operation): |
|
1605 | class ProfileConcat(Operation): | |
1602 |
|
1606 | |||
1603 | __isConfig = False |
|
1607 | __isConfig = False | |
1604 | buffer = None |
|
1608 | buffer = None | |
1605 |
|
1609 | |||
1606 | def __init__(self): |
|
1610 | def __init__(self): | |
1607 |
|
1611 | |||
1608 | self.profileIndex = 0 |
|
1612 | self.profileIndex = 0 | |
1609 |
|
1613 | |||
1610 | def reset(self): |
|
1614 | def reset(self): | |
1611 | self.buffer = numpy.zeros_like(self.buffer) |
|
1615 | self.buffer = numpy.zeros_like(self.buffer) | |
1612 | self.start_index = 0 |
|
1616 | self.start_index = 0 | |
1613 | self.times = 1 |
|
1617 | self.times = 1 | |
1614 |
|
1618 | |||
1615 | def setup(self, data, m, n=1): |
|
1619 | def setup(self, data, m, n=1): | |
1616 | self.buffer = numpy.zeros((data.shape[0],data.shape[1]*m),dtype=type(data[0,0])) |
|
1620 | self.buffer = numpy.zeros((data.shape[0],data.shape[1]*m),dtype=type(data[0,0])) | |
1617 | self.profiles = data.shape[1] |
|
1621 | self.profiles = data.shape[1] | |
1618 | self.start_index = 0 |
|
1622 | self.start_index = 0 | |
1619 | self.times = 1 |
|
1623 | self.times = 1 | |
1620 |
|
1624 | |||
1621 | def concat(self, data): |
|
1625 | def concat(self, data): | |
1622 |
|
1626 | |||
1623 | self.buffer[:,self.start_index:self.profiles*self.times] = data.copy() |
|
1627 | self.buffer[:,self.start_index:self.profiles*self.times] = data.copy() | |
1624 | self.start_index = self.start_index + self.profiles |
|
1628 | self.start_index = self.start_index + self.profiles | |
1625 |
|
1629 | |||
1626 | def run(self, dataOut, m): |
|
1630 | def run(self, dataOut, m): | |
1627 |
|
1631 | |||
1628 | dataOut.flagNoData = True |
|
1632 | dataOut.flagNoData = True | |
1629 |
|
1633 | |||
1630 | if not self.__isConfig: |
|
1634 | if not self.__isConfig: | |
1631 | self.setup(dataOut.data, m, 1) |
|
1635 | self.setup(dataOut.data, m, 1) | |
1632 | self.__isConfig = True |
|
1636 | self.__isConfig = True | |
1633 |
|
1637 | |||
1634 | self.concat(dataOut.data) |
|
1638 | self.concat(dataOut.data) | |
1635 | self.times += 1 |
|
1639 | self.times += 1 | |
1636 | if self.times > m: |
|
1640 | if self.times > m: | |
1637 | dataOut.data = self.buffer |
|
1641 | dataOut.data = self.buffer | |
1638 | self.reset() |
|
1642 | self.reset() | |
1639 | dataOut.flagNoData = False |
|
1643 | dataOut.flagNoData = False | |
1640 | # se deben actualizar mas propiedades del header y del objeto dataOut, por ejemplo, las alturas |
|
1644 | # se deben actualizar mas propiedades del header y del objeto dataOut, por ejemplo, las alturas | |
1641 | deltaHeight = dataOut.heightList[1] - dataOut.heightList[0] |
|
1645 | deltaHeight = dataOut.heightList[1] - dataOut.heightList[0] | |
1642 | xf = dataOut.heightList[0] + dataOut.nHeights * deltaHeight * 5 |
|
1646 | xf = dataOut.heightList[0] + dataOut.nHeights * deltaHeight * 5 | |
1643 | dataOut.heightList = numpy.arange(dataOut.heightList[0], xf, deltaHeight) |
|
1647 | dataOut.heightList = numpy.arange(dataOut.heightList[0], xf, deltaHeight) | |
1644 |
|
1648 | |||
1645 |
|
1649 | |||
1646 |
|
1650 | |||
1647 | class ProfileSelector(Operation): |
|
1651 | class ProfileSelector(Operation): | |
1648 |
|
1652 | |||
1649 | profileIndex = None |
|
1653 | profileIndex = None | |
1650 | # Tamanho total de los perfiles |
|
1654 | # Tamanho total de los perfiles | |
1651 | nProfiles = None |
|
1655 | nProfiles = None | |
1652 |
|
1656 | |||
1653 | def __init__(self): |
|
1657 | def __init__(self): | |
1654 |
|
1658 | |||
1655 | self.profileIndex = 0 |
|
1659 | self.profileIndex = 0 | |
1656 |
|
1660 | |||
1657 | def incIndex(self): |
|
1661 | def incIndex(self): | |
1658 | self.profileIndex += 1 |
|
1662 | self.profileIndex += 1 | |
1659 |
|
1663 | |||
1660 | if self.profileIndex >= self.nProfiles: |
|
1664 | if self.profileIndex >= self.nProfiles: | |
1661 | self.profileIndex = 0 |
|
1665 | self.profileIndex = 0 | |
1662 |
|
1666 | |||
1663 | def isProfileInRange(self, minIndex, maxIndex): |
|
1667 | def isProfileInRange(self, minIndex, maxIndex): | |
1664 |
|
1668 | |||
1665 | if self.profileIndex < minIndex: |
|
1669 | if self.profileIndex < minIndex: | |
1666 | return False |
|
1670 | return False | |
1667 |
|
1671 | |||
1668 | if self.profileIndex > maxIndex: |
|
1672 | if self.profileIndex > maxIndex: | |
1669 | return False |
|
1673 | return False | |
1670 |
|
1674 | |||
1671 | return True |
|
1675 | return True | |
1672 |
|
1676 | |||
1673 | def isProfileInList(self, profileList): |
|
1677 | def isProfileInList(self, profileList): | |
1674 |
|
1678 | |||
1675 | if self.profileIndex not in profileList: |
|
1679 | if self.profileIndex not in profileList: | |
1676 | return False |
|
1680 | return False | |
1677 |
|
1681 | |||
1678 | return True |
|
1682 | return True | |
1679 |
|
1683 | |||
1680 | def run(self, dataOut, profileList=None, profileRangeList=None): |
|
1684 | def run(self, dataOut, profileList=None, profileRangeList=None): | |
1681 |
|
1685 | |||
1682 | dataOut.flagNoData = True |
|
1686 | dataOut.flagNoData = True | |
1683 | self.nProfiles = dataOut.nProfiles |
|
1687 | self.nProfiles = dataOut.nProfiles | |
1684 |
|
1688 | |||
1685 | if profileList != None: |
|
1689 | if profileList != None: | |
1686 | if self.isProfileInList(profileList): |
|
1690 | if self.isProfileInList(profileList): | |
1687 | dataOut.flagNoData = False |
|
1691 | dataOut.flagNoData = False | |
1688 |
|
1692 | |||
1689 | self.incIndex() |
|
1693 | self.incIndex() | |
1690 | return 1 |
|
1694 | return 1 | |
1691 |
|
1695 | |||
1692 |
|
1696 | |||
1693 | elif profileRangeList != None: |
|
1697 | elif profileRangeList != None: | |
1694 | minIndex = profileRangeList[0] |
|
1698 | minIndex = profileRangeList[0] | |
1695 | maxIndex = profileRangeList[1] |
|
1699 | maxIndex = profileRangeList[1] | |
1696 | if self.isProfileInRange(minIndex, maxIndex): |
|
1700 | if self.isProfileInRange(minIndex, maxIndex): | |
1697 | dataOut.flagNoData = False |
|
1701 | dataOut.flagNoData = False | |
1698 |
|
1702 | |||
1699 | self.incIndex() |
|
1703 | self.incIndex() | |
1700 | return 1 |
|
1704 | return 1 | |
1701 |
|
1705 | |||
1702 | else: |
|
1706 | else: | |
1703 | raise ValueError, "ProfileSelector needs profileList or profileRangeList" |
|
1707 | raise ValueError, "ProfileSelector needs profileList or profileRangeList" | |
1704 |
|
1708 | |||
1705 | return 0 |
|
1709 | return 0 | |
1706 |
|
1710 | |||
1707 | class SpectraHeisProc(ProcessingUnit): |
|
1711 | class SpectraHeisProc(ProcessingUnit): | |
1708 | def __init__(self): |
|
1712 | def __init__(self): | |
1709 | self.objectDict = {} |
|
1713 | self.objectDict = {} | |
1710 | # self.buffer = None |
|
1714 | # self.buffer = None | |
1711 | # self.firstdatatime = None |
|
1715 | # self.firstdatatime = None | |
1712 | # self.profIndex = 0 |
|
1716 | # self.profIndex = 0 | |
1713 | self.dataOut = SpectraHeis() |
|
1717 | self.dataOut = SpectraHeis() | |
1714 |
|
1718 | |||
1715 | def __updateObjFromInput(self): |
|
1719 | def __updateObjFromInput(self): | |
1716 | self.dataOut.timeZone = self.dataIn.timeZone |
|
1720 | self.dataOut.timeZone = self.dataIn.timeZone | |
1717 | self.dataOut.dstFlag = self.dataIn.dstFlag |
|
1721 | self.dataOut.dstFlag = self.dataIn.dstFlag | |
1718 | self.dataOut.errorCount = self.dataIn.errorCount |
|
1722 | self.dataOut.errorCount = self.dataIn.errorCount | |
1719 | self.dataOut.useLocalTime = self.dataIn.useLocalTime |
|
1723 | self.dataOut.useLocalTime = self.dataIn.useLocalTime | |
1720 |
|
1724 | |||
1721 | self.dataOut.radarControllerHeaderObj = self.dataIn.radarControllerHeaderObj.copy()# |
|
1725 | self.dataOut.radarControllerHeaderObj = self.dataIn.radarControllerHeaderObj.copy()# | |
1722 | self.dataOut.systemHeaderObj = self.dataIn.systemHeaderObj.copy()# |
|
1726 | self.dataOut.systemHeaderObj = self.dataIn.systemHeaderObj.copy()# | |
1723 | self.dataOut.channelList = self.dataIn.channelList |
|
1727 | self.dataOut.channelList = self.dataIn.channelList | |
1724 | self.dataOut.heightList = self.dataIn.heightList |
|
1728 | self.dataOut.heightList = self.dataIn.heightList | |
1725 | # self.dataOut.dtype = self.dataIn.dtype |
|
1729 | # self.dataOut.dtype = self.dataIn.dtype | |
1726 | self.dataOut.dtype = numpy.dtype([('real','<f4'),('imag','<f4')]) |
|
1730 | self.dataOut.dtype = numpy.dtype([('real','<f4'),('imag','<f4')]) | |
1727 | # self.dataOut.nHeights = self.dataIn.nHeights |
|
1731 | # self.dataOut.nHeights = self.dataIn.nHeights | |
1728 | # self.dataOut.nChannels = self.dataIn.nChannels |
|
1732 | # self.dataOut.nChannels = self.dataIn.nChannels | |
1729 | self.dataOut.nBaud = self.dataIn.nBaud |
|
1733 | self.dataOut.nBaud = self.dataIn.nBaud | |
1730 | self.dataOut.nCode = self.dataIn.nCode |
|
1734 | self.dataOut.nCode = self.dataIn.nCode | |
1731 | self.dataOut.code = self.dataIn.code |
|
1735 | self.dataOut.code = self.dataIn.code | |
1732 | # self.dataOut.nProfiles = 1 |
|
1736 | # self.dataOut.nProfiles = 1 | |
1733 | # self.dataOut.nProfiles = self.dataOut.nFFTPoints |
|
1737 | # self.dataOut.nProfiles = self.dataOut.nFFTPoints | |
1734 | self.dataOut.nFFTPoints = self.dataIn.nHeights |
|
1738 | self.dataOut.nFFTPoints = self.dataIn.nHeights | |
1735 | # self.dataOut.channelIndexList = self.dataIn.channelIndexList |
|
1739 | # self.dataOut.channelIndexList = self.dataIn.channelIndexList | |
1736 | # self.dataOut.flagNoData = self.dataIn.flagNoData |
|
1740 | # self.dataOut.flagNoData = self.dataIn.flagNoData | |
1737 | self.dataOut.flagTimeBlock = self.dataIn.flagTimeBlock |
|
1741 | self.dataOut.flagTimeBlock = self.dataIn.flagTimeBlock | |
1738 | self.dataOut.utctime = self.dataIn.utctime |
|
1742 | self.dataOut.utctime = self.dataIn.utctime | |
1739 | # self.dataOut.utctime = self.firstdatatime |
|
1743 | # self.dataOut.utctime = self.firstdatatime | |
1740 | self.dataOut.flagDecodeData = self.dataIn.flagDecodeData #asumo q la data esta decodificada |
|
1744 | self.dataOut.flagDecodeData = self.dataIn.flagDecodeData #asumo q la data esta decodificada | |
1741 | self.dataOut.flagDeflipData = self.dataIn.flagDeflipData #asumo q la data esta sin flip |
|
1745 | self.dataOut.flagDeflipData = self.dataIn.flagDeflipData #asumo q la data esta sin flip | |
1742 | # self.dataOut.flagShiftFFT = self.dataIn.flagShiftFFT |
|
1746 | # self.dataOut.flagShiftFFT = self.dataIn.flagShiftFFT | |
1743 | self.dataOut.nCohInt = self.dataIn.nCohInt |
|
1747 | self.dataOut.nCohInt = self.dataIn.nCohInt | |
1744 | self.dataOut.nIncohInt = 1 |
|
1748 | self.dataOut.nIncohInt = 1 | |
1745 | self.dataOut.ippSeconds= self.dataIn.ippSeconds |
|
1749 | self.dataOut.ippSeconds= self.dataIn.ippSeconds | |
1746 | self.dataOut.windowOfFilter = self.dataIn.windowOfFilter |
|
1750 | self.dataOut.windowOfFilter = self.dataIn.windowOfFilter | |
1747 |
|
1751 | |||
1748 | self.dataOut.timeInterval = self.dataIn.timeInterval*self.dataOut.nIncohInt |
|
1752 | self.dataOut.timeInterval = self.dataIn.timeInterval*self.dataOut.nIncohInt | |
1749 | # self.dataOut.set=self.dataIn.set |
|
1753 | # self.dataOut.set=self.dataIn.set | |
1750 | # self.dataOut.deltaHeight=self.dataIn.deltaHeight |
|
1754 | # self.dataOut.deltaHeight=self.dataIn.deltaHeight | |
1751 |
|
1755 | |||
1752 |
|
1756 | |||
1753 | def __updateObjFromFits(self): |
|
1757 | def __updateObjFromFits(self): | |
1754 | self.dataOut.utctime = self.dataIn.utctime |
|
1758 | self.dataOut.utctime = self.dataIn.utctime | |
1755 | self.dataOut.channelIndexList = self.dataIn.channelIndexList |
|
1759 | self.dataOut.channelIndexList = self.dataIn.channelIndexList | |
1756 |
|
1760 | |||
1757 | self.dataOut.channelList = self.dataIn.channelList |
|
1761 | self.dataOut.channelList = self.dataIn.channelList | |
1758 | self.dataOut.heightList = self.dataIn.heightList |
|
1762 | self.dataOut.heightList = self.dataIn.heightList | |
1759 | self.dataOut.data_spc = self.dataIn.data |
|
1763 | self.dataOut.data_spc = self.dataIn.data | |
1760 | self.dataOut.timeInterval = self.dataIn.timeInterval |
|
1764 | self.dataOut.timeInterval = self.dataIn.timeInterval | |
1761 | self.dataOut.timeZone = self.dataIn.timeZone |
|
1765 | self.dataOut.timeZone = self.dataIn.timeZone | |
1762 | self.dataOut.useLocalTime = True |
|
1766 | self.dataOut.useLocalTime = True | |
1763 | # self.dataOut. |
|
1767 | # self.dataOut. | |
1764 | # self.dataOut. |
|
1768 | # self.dataOut. | |
1765 |
|
1769 | |||
1766 | def __getFft(self): |
|
1770 | def __getFft(self): | |
1767 |
|
1771 | |||
1768 | fft_volt = numpy.fft.fft(self.dataIn.data, axis=1) |
|
1772 | fft_volt = numpy.fft.fft(self.dataIn.data, axis=1) | |
1769 | fft_volt = numpy.fft.fftshift(fft_volt,axes=(1,)) |
|
1773 | fft_volt = numpy.fft.fftshift(fft_volt,axes=(1,)) | |
1770 | spc = numpy.abs(fft_volt * numpy.conjugate(fft_volt))/(self.dataOut.nFFTPoints) |
|
1774 | spc = numpy.abs(fft_volt * numpy.conjugate(fft_volt))/(self.dataOut.nFFTPoints) | |
1771 | self.dataOut.data_spc = spc |
|
1775 | self.dataOut.data_spc = spc | |
1772 |
|
1776 | |||
1773 | def init(self): |
|
1777 | def init(self): | |
1774 |
|
1778 | |||
1775 | self.dataOut.flagNoData = True |
|
1779 | self.dataOut.flagNoData = True | |
1776 |
|
1780 | |||
1777 | if self.dataIn.type == "Fits": |
|
1781 | if self.dataIn.type == "Fits": | |
1778 | self.__updateObjFromFits() |
|
1782 | self.__updateObjFromFits() | |
1779 | self.dataOut.flagNoData = False |
|
1783 | self.dataOut.flagNoData = False | |
1780 | return |
|
1784 | return | |
1781 |
|
1785 | |||
1782 | if self.dataIn.type == "SpectraHeis": |
|
1786 | if self.dataIn.type == "SpectraHeis": | |
1783 | self.dataOut.copy(self.dataIn) |
|
1787 | self.dataOut.copy(self.dataIn) | |
1784 | return |
|
1788 | return | |
1785 |
|
1789 | |||
1786 | if self.dataIn.type == "Voltage": |
|
1790 | if self.dataIn.type == "Voltage": | |
1787 | self.__updateObjFromInput() |
|
1791 | self.__updateObjFromInput() | |
1788 | self.__getFft() |
|
1792 | self.__getFft() | |
1789 | self.dataOut.flagNoData = False |
|
1793 | self.dataOut.flagNoData = False | |
1790 |
|
1794 | |||
1791 | return |
|
1795 | return | |
1792 |
|
1796 | |||
1793 | raise ValueError, "The type object %s is not valid"%(self.dataIn.type) |
|
1797 | raise ValueError, "The type object %s is not valid"%(self.dataIn.type) | |
1794 |
|
1798 | |||
1795 |
|
1799 | |||
1796 | def selectChannels(self, channelList): |
|
1800 | def selectChannels(self, channelList): | |
1797 |
|
1801 | |||
1798 | channelIndexList = [] |
|
1802 | channelIndexList = [] | |
1799 |
|
1803 | |||
1800 | for channel in channelList: |
|
1804 | for channel in channelList: | |
1801 | index = self.dataOut.channelList.index(channel) |
|
1805 | index = self.dataOut.channelList.index(channel) | |
1802 | channelIndexList.append(index) |
|
1806 | channelIndexList.append(index) | |
1803 |
|
1807 | |||
1804 | self.selectChannelsByIndex(channelIndexList) |
|
1808 | self.selectChannelsByIndex(channelIndexList) | |
1805 |
|
1809 | |||
1806 | def selectChannelsByIndex(self, channelIndexList): |
|
1810 | def selectChannelsByIndex(self, channelIndexList): | |
1807 | """ |
|
1811 | """ | |
1808 | Selecciona un bloque de datos en base a canales segun el channelIndexList |
|
1812 | Selecciona un bloque de datos en base a canales segun el channelIndexList | |
1809 |
|
1813 | |||
1810 | Input: |
|
1814 | Input: | |
1811 | channelIndexList : lista sencilla de canales a seleccionar por ej. [2,3,7] |
|
1815 | channelIndexList : lista sencilla de canales a seleccionar por ej. [2,3,7] | |
1812 |
|
1816 | |||
1813 | Affected: |
|
1817 | Affected: | |
1814 | self.dataOut.data |
|
1818 | self.dataOut.data | |
1815 | self.dataOut.channelIndexList |
|
1819 | self.dataOut.channelIndexList | |
1816 | self.dataOut.nChannels |
|
1820 | self.dataOut.nChannels | |
1817 | self.dataOut.m_ProcessingHeader.totalSpectra |
|
1821 | self.dataOut.m_ProcessingHeader.totalSpectra | |
1818 | self.dataOut.systemHeaderObj.numChannels |
|
1822 | self.dataOut.systemHeaderObj.numChannels | |
1819 | self.dataOut.m_ProcessingHeader.blockSize |
|
1823 | self.dataOut.m_ProcessingHeader.blockSize | |
1820 |
|
1824 | |||
1821 | Return: |
|
1825 | Return: | |
1822 | None |
|
1826 | None | |
1823 | """ |
|
1827 | """ | |
1824 |
|
1828 | |||
1825 | for channelIndex in channelIndexList: |
|
1829 | for channelIndex in channelIndexList: | |
1826 | if channelIndex not in self.dataOut.channelIndexList: |
|
1830 | if channelIndex not in self.dataOut.channelIndexList: | |
1827 | print channelIndexList |
|
1831 | print channelIndexList | |
1828 | raise ValueError, "The value %d in channelIndexList is not valid" %channelIndex |
|
1832 | raise ValueError, "The value %d in channelIndexList is not valid" %channelIndex | |
1829 |
|
1833 | |||
1830 | nChannels = len(channelIndexList) |
|
1834 | nChannels = len(channelIndexList) | |
1831 |
|
1835 | |||
1832 | data_spc = self.dataOut.data_spc[channelIndexList,:] |
|
1836 | data_spc = self.dataOut.data_spc[channelIndexList,:] | |
1833 |
|
1837 | |||
1834 | self.dataOut.data_spc = data_spc |
|
1838 | self.dataOut.data_spc = data_spc | |
1835 | self.dataOut.channelList = [self.dataOut.channelList[i] for i in channelIndexList] |
|
1839 | self.dataOut.channelList = [self.dataOut.channelList[i] for i in channelIndexList] | |
1836 |
|
1840 | |||
1837 | return 1 |
|
1841 | return 1 | |
1838 |
|
1842 | |||
1839 | class IncohInt4SpectraHeis(Operation): |
|
1843 | class IncohInt4SpectraHeis(Operation): | |
1840 |
|
1844 | |||
1841 | __isConfig = False |
|
1845 | __isConfig = False | |
1842 |
|
1846 | |||
1843 | __profIndex = 0 |
|
1847 | __profIndex = 0 | |
1844 | __withOverapping = False |
|
1848 | __withOverapping = False | |
1845 |
|
1849 | |||
1846 | __byTime = False |
|
1850 | __byTime = False | |
1847 | __initime = None |
|
1851 | __initime = None | |
1848 | __lastdatatime = None |
|
1852 | __lastdatatime = None | |
1849 | __integrationtime = None |
|
1853 | __integrationtime = None | |
1850 |
|
1854 | |||
1851 | __buffer = None |
|
1855 | __buffer = None | |
1852 |
|
1856 | |||
1853 | __dataReady = False |
|
1857 | __dataReady = False | |
1854 |
|
1858 | |||
1855 | n = None |
|
1859 | n = None | |
1856 |
|
1860 | |||
1857 |
|
1861 | |||
1858 | def __init__(self): |
|
1862 | def __init__(self): | |
1859 |
|
1863 | |||
1860 | self.__isConfig = False |
|
1864 | self.__isConfig = False | |
1861 |
|
1865 | |||
1862 | def setup(self, n=None, timeInterval=None, overlapping=False): |
|
1866 | def setup(self, n=None, timeInterval=None, overlapping=False): | |
1863 | """ |
|
1867 | """ | |
1864 | Set the parameters of the integration class. |
|
1868 | Set the parameters of the integration class. | |
1865 |
|
1869 | |||
1866 | Inputs: |
|
1870 | Inputs: | |
1867 |
|
1871 | |||
1868 | n : Number of coherent integrations |
|
1872 | n : Number of coherent integrations | |
1869 | timeInterval : Time of integration. If the parameter "n" is selected this one does not work |
|
1873 | timeInterval : Time of integration. If the parameter "n" is selected this one does not work | |
1870 | overlapping : |
|
1874 | overlapping : | |
1871 |
|
1875 | |||
1872 | """ |
|
1876 | """ | |
1873 |
|
1877 | |||
1874 | self.__initime = None |
|
1878 | self.__initime = None | |
1875 | self.__lastdatatime = 0 |
|
1879 | self.__lastdatatime = 0 | |
1876 | self.__buffer = None |
|
1880 | self.__buffer = None | |
1877 | self.__dataReady = False |
|
1881 | self.__dataReady = False | |
1878 |
|
1882 | |||
1879 |
|
1883 | |||
1880 | if n == None and timeInterval == None: |
|
1884 | if n == None and timeInterval == None: | |
1881 | raise ValueError, "n or timeInterval should be specified ..." |
|
1885 | raise ValueError, "n or timeInterval should be specified ..." | |
1882 |
|
1886 | |||
1883 | if n != None: |
|
1887 | if n != None: | |
1884 | self.n = n |
|
1888 | self.n = n | |
1885 | self.__byTime = False |
|
1889 | self.__byTime = False | |
1886 | else: |
|
1890 | else: | |
1887 | self.__integrationtime = timeInterval #* 60. #if (type(timeInterval)!=integer) -> change this line |
|
1891 | self.__integrationtime = timeInterval #* 60. #if (type(timeInterval)!=integer) -> change this line | |
1888 | self.n = 9999 |
|
1892 | self.n = 9999 | |
1889 | self.__byTime = True |
|
1893 | self.__byTime = True | |
1890 |
|
1894 | |||
1891 | if overlapping: |
|
1895 | if overlapping: | |
1892 | self.__withOverapping = True |
|
1896 | self.__withOverapping = True | |
1893 | self.__buffer = None |
|
1897 | self.__buffer = None | |
1894 | else: |
|
1898 | else: | |
1895 | self.__withOverapping = False |
|
1899 | self.__withOverapping = False | |
1896 | self.__buffer = 0 |
|
1900 | self.__buffer = 0 | |
1897 |
|
1901 | |||
1898 | self.__profIndex = 0 |
|
1902 | self.__profIndex = 0 | |
1899 |
|
1903 | |||
1900 | def putData(self, data): |
|
1904 | def putData(self, data): | |
1901 |
|
1905 | |||
1902 | """ |
|
1906 | """ | |
1903 | Add a profile to the __buffer and increase in one the __profileIndex |
|
1907 | Add a profile to the __buffer and increase in one the __profileIndex | |
1904 |
|
1908 | |||
1905 | """ |
|
1909 | """ | |
1906 |
|
1910 | |||
1907 | if not self.__withOverapping: |
|
1911 | if not self.__withOverapping: | |
1908 | self.__buffer += data.copy() |
|
1912 | self.__buffer += data.copy() | |
1909 | self.__profIndex += 1 |
|
1913 | self.__profIndex += 1 | |
1910 | return |
|
1914 | return | |
1911 |
|
1915 | |||
1912 | #Overlapping data |
|
1916 | #Overlapping data | |
1913 | nChannels, nHeis = data.shape |
|
1917 | nChannels, nHeis = data.shape | |
1914 | data = numpy.reshape(data, (1, nChannels, nHeis)) |
|
1918 | data = numpy.reshape(data, (1, nChannels, nHeis)) | |
1915 |
|
1919 | |||
1916 | #If the buffer is empty then it takes the data value |
|
1920 | #If the buffer is empty then it takes the data value | |
1917 | if self.__buffer == None: |
|
1921 | if self.__buffer == None: | |
1918 | self.__buffer = data |
|
1922 | self.__buffer = data | |
1919 | self.__profIndex += 1 |
|
1923 | self.__profIndex += 1 | |
1920 | return |
|
1924 | return | |
1921 |
|
1925 | |||
1922 | #If the buffer length is lower than n then stakcing the data value |
|
1926 | #If the buffer length is lower than n then stakcing the data value | |
1923 | if self.__profIndex < self.n: |
|
1927 | if self.__profIndex < self.n: | |
1924 | self.__buffer = numpy.vstack((self.__buffer, data)) |
|
1928 | self.__buffer = numpy.vstack((self.__buffer, data)) | |
1925 | self.__profIndex += 1 |
|
1929 | self.__profIndex += 1 | |
1926 | return |
|
1930 | return | |
1927 |
|
1931 | |||
1928 | #If the buffer length is equal to n then replacing the last buffer value with the data value |
|
1932 | #If the buffer length is equal to n then replacing the last buffer value with the data value | |
1929 | self.__buffer = numpy.roll(self.__buffer, -1, axis=0) |
|
1933 | self.__buffer = numpy.roll(self.__buffer, -1, axis=0) | |
1930 | self.__buffer[self.n-1] = data |
|
1934 | self.__buffer[self.n-1] = data | |
1931 | self.__profIndex = self.n |
|
1935 | self.__profIndex = self.n | |
1932 | return |
|
1936 | return | |
1933 |
|
1937 | |||
1934 |
|
1938 | |||
1935 | def pushData(self): |
|
1939 | def pushData(self): | |
1936 | """ |
|
1940 | """ | |
1937 | Return the sum of the last profiles and the profiles used in the sum. |
|
1941 | Return the sum of the last profiles and the profiles used in the sum. | |
1938 |
|
1942 | |||
1939 | Affected: |
|
1943 | Affected: | |
1940 |
|
1944 | |||
1941 | self.__profileIndex |
|
1945 | self.__profileIndex | |
1942 |
|
1946 | |||
1943 | """ |
|
1947 | """ | |
1944 |
|
1948 | |||
1945 | if not self.__withOverapping: |
|
1949 | if not self.__withOverapping: | |
1946 | data = self.__buffer |
|
1950 | data = self.__buffer | |
1947 | n = self.__profIndex |
|
1951 | n = self.__profIndex | |
1948 |
|
1952 | |||
1949 | self.__buffer = 0 |
|
1953 | self.__buffer = 0 | |
1950 | self.__profIndex = 0 |
|
1954 | self.__profIndex = 0 | |
1951 |
|
1955 | |||
1952 | return data, n |
|
1956 | return data, n | |
1953 |
|
1957 | |||
1954 | #Integration with Overlapping |
|
1958 | #Integration with Overlapping | |
1955 | data = numpy.sum(self.__buffer, axis=0) |
|
1959 | data = numpy.sum(self.__buffer, axis=0) | |
1956 | n = self.__profIndex |
|
1960 | n = self.__profIndex | |
1957 |
|
1961 | |||
1958 | return data, n |
|
1962 | return data, n | |
1959 |
|
1963 | |||
1960 | def byProfiles(self, data): |
|
1964 | def byProfiles(self, data): | |
1961 |
|
1965 | |||
1962 | self.__dataReady = False |
|
1966 | self.__dataReady = False | |
1963 | avgdata = None |
|
1967 | avgdata = None | |
1964 | n = None |
|
1968 | n = None | |
1965 |
|
1969 | |||
1966 | self.putData(data) |
|
1970 | self.putData(data) | |
1967 |
|
1971 | |||
1968 | if self.__profIndex == self.n: |
|
1972 | if self.__profIndex == self.n: | |
1969 |
|
1973 | |||
1970 | avgdata, n = self.pushData() |
|
1974 | avgdata, n = self.pushData() | |
1971 | self.__dataReady = True |
|
1975 | self.__dataReady = True | |
1972 |
|
1976 | |||
1973 | return avgdata |
|
1977 | return avgdata | |
1974 |
|
1978 | |||
1975 | def byTime(self, data, datatime): |
|
1979 | def byTime(self, data, datatime): | |
1976 |
|
1980 | |||
1977 | self.__dataReady = False |
|
1981 | self.__dataReady = False | |
1978 | avgdata = None |
|
1982 | avgdata = None | |
1979 | n = None |
|
1983 | n = None | |
1980 |
|
1984 | |||
1981 | self.putData(data) |
|
1985 | self.putData(data) | |
1982 |
|
1986 | |||
1983 | if (datatime - self.__initime) >= self.__integrationtime: |
|
1987 | if (datatime - self.__initime) >= self.__integrationtime: | |
1984 | avgdata, n = self.pushData() |
|
1988 | avgdata, n = self.pushData() | |
1985 | self.n = n |
|
1989 | self.n = n | |
1986 | self.__dataReady = True |
|
1990 | self.__dataReady = True | |
1987 |
|
1991 | |||
1988 | return avgdata |
|
1992 | return avgdata | |
1989 |
|
1993 | |||
1990 | def integrate(self, data, datatime=None): |
|
1994 | def integrate(self, data, datatime=None): | |
1991 |
|
1995 | |||
1992 | if self.__initime == None: |
|
1996 | if self.__initime == None: | |
1993 | self.__initime = datatime |
|
1997 | self.__initime = datatime | |
1994 |
|
1998 | |||
1995 | if self.__byTime: |
|
1999 | if self.__byTime: | |
1996 | avgdata = self.byTime(data, datatime) |
|
2000 | avgdata = self.byTime(data, datatime) | |
1997 | else: |
|
2001 | else: | |
1998 | avgdata = self.byProfiles(data) |
|
2002 | avgdata = self.byProfiles(data) | |
1999 |
|
2003 | |||
2000 |
|
2004 | |||
2001 | self.__lastdatatime = datatime |
|
2005 | self.__lastdatatime = datatime | |
2002 |
|
2006 | |||
2003 | if avgdata == None: |
|
2007 | if avgdata == None: | |
2004 | return None, None |
|
2008 | return None, None | |
2005 |
|
2009 | |||
2006 | avgdatatime = self.__initime |
|
2010 | avgdatatime = self.__initime | |
2007 |
|
2011 | |||
2008 | deltatime = datatime -self.__lastdatatime |
|
2012 | deltatime = datatime -self.__lastdatatime | |
2009 |
|
2013 | |||
2010 | if not self.__withOverapping: |
|
2014 | if not self.__withOverapping: | |
2011 | self.__initime = datatime |
|
2015 | self.__initime = datatime | |
2012 | else: |
|
2016 | else: | |
2013 | self.__initime += deltatime |
|
2017 | self.__initime += deltatime | |
2014 |
|
2018 | |||
2015 | return avgdata, avgdatatime |
|
2019 | return avgdata, avgdatatime | |
2016 |
|
2020 | |||
2017 | def run(self, dataOut, **kwargs): |
|
2021 | def run(self, dataOut, **kwargs): | |
2018 |
|
2022 | |||
2019 | if not self.__isConfig: |
|
2023 | if not self.__isConfig: | |
2020 | self.setup(**kwargs) |
|
2024 | self.setup(**kwargs) | |
2021 | self.__isConfig = True |
|
2025 | self.__isConfig = True | |
2022 |
|
2026 | |||
2023 | avgdata, avgdatatime = self.integrate(dataOut.data_spc, dataOut.utctime) |
|
2027 | avgdata, avgdatatime = self.integrate(dataOut.data_spc, dataOut.utctime) | |
2024 |
|
2028 | |||
2025 | # dataOut.timeInterval *= n |
|
2029 | # dataOut.timeInterval *= n | |
2026 | dataOut.flagNoData = True |
|
2030 | dataOut.flagNoData = True | |
2027 |
|
2031 | |||
2028 | if self.__dataReady: |
|
2032 | if self.__dataReady: | |
2029 | dataOut.data_spc = avgdata |
|
2033 | dataOut.data_spc = avgdata | |
2030 | dataOut.nIncohInt *= self.n |
|
2034 | dataOut.nIncohInt *= self.n | |
2031 | # dataOut.nCohInt *= self.n |
|
2035 | # dataOut.nCohInt *= self.n | |
2032 | dataOut.utctime = avgdatatime |
|
2036 | dataOut.utctime = avgdatatime | |
2033 | dataOut.timeInterval = dataOut.ippSeconds * dataOut.nIncohInt |
|
2037 | dataOut.timeInterval = dataOut.ippSeconds * dataOut.nIncohInt | |
2034 | # dataOut.timeInterval = self.__timeInterval*self.n |
|
2038 | # dataOut.timeInterval = self.__timeInterval*self.n | |
2035 | dataOut.flagNoData = False |
|
2039 | dataOut.flagNoData = False | |
2036 |
|
2040 | |||
2037 |
|
2041 | |||
2038 |
|
2042 | |||
2039 |
|
2043 | |||
2040 | No newline at end of file |
|
2044 |
General Comments 0
You need to be logged in to leave comments.
Login now