##// END OF EJS Templates
Miguel Valdez -
r231:3ad829c7efcb
parent child
Show More
@@ -1,351 +1,353
1 import os
1 import os
2 import numpy
2 import numpy
3 import time, datetime
3 import mpldriver
4 import mpldriver
4
5
5
6
6 class Figure:
7 class Figure:
7
8
8 __driver = mpldriver
9 __driver = mpldriver
9 fig = None
10 fig = None
10
11
11 idfigure = None
12 idfigure = None
12 wintitle = None
13 wintitle = None
13 width = None
14 width = None
14 height = None
15 height = None
15 nplots = None
16 nplots = None
17 timerange = None
16
18
17 axesObjList = []
19 axesObjList = []
18
20
19 WIDTH = None
21 WIDTH = None
20 HEIGHT = None
22 HEIGHT = None
21 PREFIX = 'fig'
23 PREFIX = 'fig'
22
24
23 def __init__(self):
25 def __init__(self):
24
26
25 raise ValueError, "This method is not implemented"
27 raise ValueError, "This method is not implemented"
26
28
27 def __del__(self):
29 def __del__(self):
28
30
29 self.__driver.closeFigure()
31 self.__driver.closeFigure()
30
32
31 def getFilename(self, name, ext='.png'):
33 def getFilename(self, name, ext='.png'):
32
34
33 filename = '%s_%s%s' %(self.PREFIX, name, ext)
35 filename = '%s_%s%s' %(self.PREFIX, name, ext)
34
36
35 return filename
37 return filename
36
38
37 def getAxesObjList(self):
39 def getAxesObjList(self):
38
40
39 return self.axesObjList
41 return self.axesObjList
40
42
41 def getSubplots(self):
43 def getSubplots(self):
42
44
43 raise ValueError, "Abstract method: This method should be defined"
45 raise ValueError, "Abstract method: This method should be defined"
44
46
45 def getScreenDim(self, widthplot, heightplot):
47 def getScreenDim(self, widthplot, heightplot):
46
48
47 nrow, ncol = self.getSubplots()
49 nrow, ncol = self.getSubplots()
48
50
49 widthscreen = widthplot*ncol
51 widthscreen = widthplot*ncol
50 heightscreen = heightplot*nrow
52 heightscreen = heightplot*nrow
51
53
52 return widthscreen, heightscreen
54 return widthscreen, heightscreen
53
55
54 def getTimeLim(self, x, xmin, xmax):
56 def getTimeLim(self, x, xmin, xmax):
55
57
56 thisdatetime = datetime.datetime.fromtimestamp(numpy.min(x))
58 thisdatetime = datetime.datetime.fromtimestamp(numpy.min(x))
57 thisdate = datetime.datetime.combine(thisdatetime.date(), datetime.time(0,0,0))
59 thisdate = datetime.datetime.combine(thisdatetime.date(), datetime.time(0,0,0))
58
60
59 ####################################################
61 ####################################################
60 #If the x is out of xrange
62 #If the x is out of xrange
61 if xmax < (thisdatetime - thisdate).seconds/(60*60.):
63 if xmax < (thisdatetime - thisdate).seconds/(60*60.):
62 xmin = None
64 xmin = None
63 xmax = None
65 xmax = None
64
66
65 if xmin == None:
67 if xmin == None:
66 td = thisdatetime - thisdate
68 td = thisdatetime - thisdate
67 xmin = td.seconds/(60*60.)
69 xmin = td.seconds/(60*60.)
68
70
69 if xmax == None:
71 if xmax == None:
70 xmax = xmin + self.__timerange/(60*60.)
72 xmax = xmin + self.timerange/(60*60.)
71
73
72 mindt = thisdate + datetime.timedelta(0,0,0,0,0, xmin)
74 mindt = thisdate + datetime.timedelta(0,0,0,0,0, xmin)
73 tmin = time.mktime(mindt.timetuple())
75 tmin = time.mktime(mindt.timetuple())
74
76
75 maxdt = thisdate + datetime.timedelta(0,0,0,0,0, xmax)
77 maxdt = thisdate + datetime.timedelta(0,0,0,0,0, xmax)
76 tmax = time.mktime(maxdt.timetuple())
78 tmax = time.mktime(maxdt.timetuple())
77
79
78 self.__timerange = tmax - tmin
80 self.timerange = tmax - tmin
79
81
80 return tmin, tmax
82 return tmin, tmax
81
83
82 def init(self, idfigure, nplots, wintitle):
84 def init(self, idfigure, nplots, wintitle):
83
85
84 raise ValueError, "This method has been replaced with createFigure"
86 raise ValueError, "This method has been replaced with createFigure"
85
87
86 def createFigure(self, idfigure, wintitle, widthplot=None, heightplot=None):
88 def createFigure(self, idfigure, wintitle, widthplot=None, heightplot=None):
87
89
88 """
90 """
89 Crea la figura de acuerdo al driver y parametros seleccionados seleccionados.
91 Crea la figura de acuerdo al driver y parametros seleccionados seleccionados.
90 Las dimensiones de la pantalla es calculada a partir de los atributos self.WIDTH
92 Las dimensiones de la pantalla es calculada a partir de los atributos self.WIDTH
91 y self.HEIGHT y el numero de subplots (nrow, ncol)
93 y self.HEIGHT y el numero de subplots (nrow, ncol)
92
94
93 Input:
95 Input:
94 idfigure : Los parametros necesarios son
96 idfigure : Los parametros necesarios son
95 wintitle :
97 wintitle :
96
98
97 """
99 """
98
100
99 if widthplot == None:
101 if widthplot == None:
100 widthplot = self.WIDTH
102 widthplot = self.WIDTH
101
103
102 if heightplot == None:
104 if heightplot == None:
103 heightplot = self.HEIGHT
105 heightplot = self.HEIGHT
104
106
105 self.idfigure = idfigure
107 self.idfigure = idfigure
106
108
107 self.wintitle = wintitle
109 self.wintitle = wintitle
108
110
109 self.widthscreen, self.heightscreen = self.getScreenDim(widthplot, heightplot)
111 self.widthscreen, self.heightscreen = self.getScreenDim(widthplot, heightplot)
110
112
111 self.fig = self.__driver.createFigure(self.idfigure,
113 self.fig = self.__driver.createFigure(self.idfigure,
112 self.wintitle,
114 self.wintitle,
113 self.widthscreen,
115 self.widthscreen,
114 self.heightscreen)
116 self.heightscreen)
115
117
116 self.axesObjList = []
118 self.axesObjList = []
117
119
118 def setDriver(self, driver=mpldriver):
120 def setDriver(self, driver=mpldriver):
119
121
120 self.__driver = driver
122 self.__driver = driver
121
123
122 def setTitle(self, title):
124 def setTitle(self, title):
123
125
124 self.__driver.setTitle(self.fig, title)
126 self.__driver.setTitle(self.fig, title)
125
127
126 def setWinTitle(self, title):
128 def setWinTitle(self, title):
127
129
128 self.__driver.setWinTitle(self.fig, title=title)
130 self.__driver.setWinTitle(self.fig, title=title)
129
131
130 def setTextFromAxes(self, text):
132 def setTextFromAxes(self, text):
131
133
132 raise ValueError, "Este metodo ha sido reemplazaado con el metodo setText de la clase Axes"
134 raise ValueError, "Este metodo ha sido reemplazaado con el metodo setText de la clase Axes"
133
135
134 def makeAxes(self, nrow, ncol, xpos, ypos, colspan, rowspan):
136 def makeAxes(self, nrow, ncol, xpos, ypos, colspan, rowspan):
135
137
136 raise ValueError, "Este metodo ha sido reemplazaado con el metodo addAxes"
138 raise ValueError, "Este metodo ha sido reemplazaado con el metodo addAxes"
137
139
138 def addAxes(self, *args):
140 def addAxes(self, *args):
139 """
141 """
140
142
141 Input:
143 Input:
142 *args : Los parametros necesarios son
144 *args : Los parametros necesarios son
143 nrow, ncol, xpos, ypos, colspan, rowspan
145 nrow, ncol, xpos, ypos, colspan, rowspan
144 """
146 """
145
147
146 axesObj = Axes(self.fig, *args)
148 axesObj = Axes(self.fig, *args)
147 self.axesObjList.append(axesObj)
149 self.axesObjList.append(axesObj)
148
150
149 def saveFigure(self, figpath, figfile, *args):
151 def saveFigure(self, figpath, figfile, *args):
150
152
151 filename = os.path.join(figpath, figfile)
153 filename = os.path.join(figpath, figfile)
152 self.__driver.saveFigure(self.fig, filename, *args)
154 self.__driver.saveFigure(self.fig, filename, *args)
153
155
154 def draw(self):
156 def draw(self):
155
157
156 self.__driver.draw(self.fig)
158 self.__driver.draw(self.fig)
157
159
158 def run(self):
160 def run(self):
159
161
160 raise ValueError, "This method is not implemented"
162 raise ValueError, "This method is not implemented"
161
163
162 axesList = property(getAxesObjList)
164 axesList = property(getAxesObjList)
163
165
164
166
165 class Axes:
167 class Axes:
166
168
167 __driver = mpldriver
169 __driver = mpldriver
168 fig = None
170 fig = None
169 ax = None
171 ax = None
170 plot = None
172 plot = None
171
173
172 __firsttime = None
174 __firsttime = None
173
175
174 __showprofile = False
176 __showprofile = False
175
177
176 xmin = None
178 xmin = None
177 xmax = None
179 xmax = None
178 ymin = None
180 ymin = None
179 ymax = None
181 ymax = None
180 zmin = None
182 zmin = None
181 zmax = None
183 zmax = None
182
184
183 def __init__(self, *args):
185 def __init__(self, *args):
184
186
185 """
187 """
186
188
187 Input:
189 Input:
188 *args : Los parametros necesarios son
190 *args : Los parametros necesarios son
189 fig, nrow, ncol, xpos, ypos, colspan, rowspan
191 fig, nrow, ncol, xpos, ypos, colspan, rowspan
190 """
192 """
191
193
192 ax = self.__driver.createAxes(*args)
194 ax = self.__driver.createAxes(*args)
193 self.fig = args[0]
195 self.fig = args[0]
194 self.ax = ax
196 self.ax = ax
195 self.plot = None
197 self.plot = None
196
198
197 self.__firsttime = True
199 self.__firsttime = True
198
200
199 def setText(self, text):
201 def setText(self, text):
200
202
201 self.__driver.setAxesText(self.ax, text)
203 self.__driver.setAxesText(self.ax, text)
202
204
203 def setXAxisAsTime(self):
205 def setXAxisAsTime(self):
204 pass
206 pass
205
207
206 def pline(self, x, y,
208 def pline(self, x, y,
207 xmin=None, xmax=None,
209 xmin=None, xmax=None,
208 ymin=None, ymax=None,
210 ymin=None, ymax=None,
209 xlabel='', ylabel='',
211 xlabel='', ylabel='',
210 title='',
212 title='',
211 **kwargs):
213 **kwargs):
212
214
213 """
215 """
214
216
215 Input:
217 Input:
216 x :
218 x :
217 y :
219 y :
218 xmin :
220 xmin :
219 xmax :
221 xmax :
220 ymin :
222 ymin :
221 ymax :
223 ymax :
222 xlabel :
224 xlabel :
223 ylabel :
225 ylabel :
224 title :
226 title :
225 **kwargs : Los parametros aceptados son
227 **kwargs : Los parametros aceptados son
226
228
227 ticksize
229 ticksize
228 ytick_visible
230 ytick_visible
229 """
231 """
230
232
231 if self.__firsttime:
233 if self.__firsttime:
232
234
233 if xmin == None: xmin = numpy.nanmin(x)
235 if xmin == None: xmin = numpy.nanmin(x)
234 if xmax == None: xmax = numpy.nanmax(x)
236 if xmax == None: xmax = numpy.nanmax(x)
235 if ymin == None: ymin = numpy.nanmin(y)
237 if ymin == None: ymin = numpy.nanmin(y)
236 if ymax == None: ymax = numpy.nanmax(y)
238 if ymax == None: ymax = numpy.nanmax(y)
237
239
238 self.plot = self.__driver.createPline(self.ax, x, y,
240 self.plot = self.__driver.createPline(self.ax, x, y,
239 xmin, xmax,
241 xmin, xmax,
240 ymin, ymax,
242 ymin, ymax,
241 xlabel=xlabel,
243 xlabel=xlabel,
242 ylabel=ylabel,
244 ylabel=ylabel,
243 title=title,
245 title=title,
244 **kwargs)
246 **kwargs)
245 self.__firsttime = False
247 self.__firsttime = False
246 return
248 return
247
249
248 self.__driver.pline(self.plot, x, y, xlabel=xlabel,
250 self.__driver.pline(self.plot, x, y, xlabel=xlabel,
249 ylabel=ylabel,
251 ylabel=ylabel,
250 title=title)
252 title=title)
251
253
252 def pmultiline(self, x, y,
254 def pmultiline(self, x, y,
253 xmin=None, xmax=None,
255 xmin=None, xmax=None,
254 ymin=None, ymax=None,
256 ymin=None, ymax=None,
255 xlabel='', ylabel='',
257 xlabel='', ylabel='',
256 title='',
258 title='',
257 **kwargs):
259 **kwargs):
258
260
259 if self.__firsttime:
261 if self.__firsttime:
260
262
261 if xmin == None: xmin = numpy.nanmin(x)
263 if xmin == None: xmin = numpy.nanmin(x)
262 if xmax == None: xmax = numpy.nanmax(x)
264 if xmax == None: xmax = numpy.nanmax(x)
263 if ymin == None: ymin = numpy.nanmin(y)
265 if ymin == None: ymin = numpy.nanmin(y)
264 if ymax == None: ymax = numpy.nanmax(y)
266 if ymax == None: ymax = numpy.nanmax(y)
265
267
266 self.plot = self.__driver.createPmultiline(self.ax, x, y,
268 self.plot = self.__driver.createPmultiline(self.ax, x, y,
267 xmin, xmax,
269 xmin, xmax,
268 ymin, ymax,
270 ymin, ymax,
269 xlabel=xlabel,
271 xlabel=xlabel,
270 ylabel=ylabel,
272 ylabel=ylabel,
271 title=title,
273 title=title,
272 **kwargs)
274 **kwargs)
273 self.__firsttime = False
275 self.__firsttime = False
274 return
276 return
275
277
276 self.__driver.pmultiline(self.plot, x, y, xlabel=xlabel,
278 self.__driver.pmultiline(self.plot, x, y, xlabel=xlabel,
277 ylabel=ylabel,
279 ylabel=ylabel,
278 title=title)
280 title=title)
279
281
280 def pcolor(self, x, y, z,
282 def pcolor(self, x, y, z,
281 xmin=None, xmax=None,
283 xmin=None, xmax=None,
282 ymin=None, ymax=None,
284 ymin=None, ymax=None,
283 zmin=None, zmax=None,
285 zmin=None, zmax=None,
284 xlabel='', ylabel='',
286 xlabel='', ylabel='',
285 title='', rti = False, colormap='jet',
287 title='', rti = False, colormap='jet',
286 **kwargs):
288 **kwargs):
287
289
288 """
290 """
289 Input:
291 Input:
290 x :
292 x :
291 y :
293 y :
292 x :
294 x :
293 xmin :
295 xmin :
294 xmax :
296 xmax :
295 ymin :
297 ymin :
296 ymax :
298 ymax :
297 zmin :
299 zmin :
298 zmax :
300 zmax :
299 xlabel :
301 xlabel :
300 ylabel :
302 ylabel :
301 title :
303 title :
302 **kwargs : Los parametros aceptados son
304 **kwargs : Los parametros aceptados son
303 ticksize=9,
305 ticksize=9,
304 cblabel=''
306 cblabel=''
305 rti = True or False
307 rti = True or False
306 """
308 """
307
309
308 if self.__firsttime:
310 if self.__firsttime:
309
311
310 if xmin == None: xmin = numpy.nanmin(x)
312 if xmin == None: xmin = numpy.nanmin(x)
311 if xmax == None: xmax = numpy.nanmax(x)
313 if xmax == None: xmax = numpy.nanmax(x)
312 if ymin == None: ymin = numpy.nanmin(y)
314 if ymin == None: ymin = numpy.nanmin(y)
313 if ymax == None: ymax = numpy.nanmax(y)
315 if ymax == None: ymax = numpy.nanmax(y)
314 if zmin == None: zmin = numpy.nanmin(z)
316 if zmin == None: zmin = numpy.nanmin(z)
315 if zmax == None: zmax = numpy.nanmax(z)
317 if zmax == None: zmax = numpy.nanmax(z)
316
318
317
319
318 self.plot = self.__driver.createPcolor(self.ax, x, y, z,
320 self.plot = self.__driver.createPcolor(self.ax, x, y, z,
319 xmin, xmax,
321 xmin, xmax,
320 ymin, ymax,
322 ymin, ymax,
321 zmin, zmax,
323 zmin, zmax,
322 xlabel=xlabel,
324 xlabel=xlabel,
323 ylabel=ylabel,
325 ylabel=ylabel,
324 title=title,
326 title=title,
325 colormap=colormap,
327 colormap=colormap,
326 **kwargs)
328 **kwargs)
327
329
328 if self.xmin == None: self.xmin = xmin
330 if self.xmin == None: self.xmin = xmin
329 if self.xmax == None: self.xmax = xmax
331 if self.xmax == None: self.xmax = xmax
330 if self.ymin == None: self.ymin = ymin
332 if self.ymin == None: self.ymin = ymin
331 if self.ymax == None: self.ymax = ymax
333 if self.ymax == None: self.ymax = ymax
332 if self.zmin == None: self.zmin = zmin
334 if self.zmin == None: self.zmin = zmin
333 if self.zmax == None: self.zmax = zmax
335 if self.zmax == None: self.zmax = zmax
334
336
335 self.__firsttime = False
337 self.__firsttime = False
336 return
338 return
337
339
338 if rti:
340 if rti:
339 self.__driver.addpcolor(self.ax, x, y, z, self.zmin, self.zmax,
341 self.__driver.addpcolor(self.ax, x, y, z, self.zmin, self.zmax,
340 xlabel=xlabel,
342 xlabel=xlabel,
341 ylabel=ylabel,
343 ylabel=ylabel,
342 title=title,
344 title=title,
343 colormap=colormap)
345 colormap=colormap)
344 return
346 return
345
347
346 self.__driver.pcolor(self.plot, z,
348 self.__driver.pcolor(self.plot, z,
347 xlabel=xlabel,
349 xlabel=xlabel,
348 ylabel=ylabel,
350 ylabel=ylabel,
349 title=title)
351 title=title)
350
352
351 No newline at end of file
353
@@ -1,2541 +1,2547
1 '''
1 '''
2
2
3 $Author: murco $
3 $Author: murco $
4 $Id: JRODataIO.py 169 2012-11-19 21:57:03Z murco $
4 $Id: JRODataIO.py 169 2012-11-19 21:57:03Z murco $
5 '''
5 '''
6
6
7 import os, sys
7 import os, sys
8 import glob
8 import glob
9 import time
9 import time
10 import numpy
10 import numpy
11 import fnmatch
11 import fnmatch
12 import time, datetime
12 import time, datetime
13
13
14 from jrodata import *
14 from jrodata import *
15 from jroheaderIO import *
15 from jroheaderIO import *
16 from jroprocessing import *
16 from jroprocessing import *
17
17
18 def isNumber(str):
18 def isNumber(str):
19 """
19 """
20 Chequea si el conjunto de caracteres que componen un string puede ser convertidos a un numero.
20 Chequea si el conjunto de caracteres que componen un string puede ser convertidos a un numero.
21
21
22 Excepciones:
22 Excepciones:
23 Si un determinado string no puede ser convertido a numero
23 Si un determinado string no puede ser convertido a numero
24 Input:
24 Input:
25 str, string al cual se le analiza para determinar si convertible a un numero o no
25 str, string al cual se le analiza para determinar si convertible a un numero o no
26
26
27 Return:
27 Return:
28 True : si el string es uno numerico
28 True : si el string es uno numerico
29 False : no es un string numerico
29 False : no es un string numerico
30 """
30 """
31 try:
31 try:
32 float( str )
32 float( str )
33 return True
33 return True
34 except:
34 except:
35 return False
35 return False
36
36
37 def isThisFileinRange(filename, startUTSeconds, endUTSeconds):
37 def isThisFileinRange(filename, startUTSeconds, endUTSeconds):
38 """
38 """
39 Esta funcion determina si un archivo de datos se encuentra o no dentro del rango de fecha especificado.
39 Esta funcion determina si un archivo de datos se encuentra o no dentro del rango de fecha especificado.
40
40
41 Inputs:
41 Inputs:
42 filename : nombre completo del archivo de datos en formato Jicamarca (.r)
42 filename : nombre completo del archivo de datos en formato Jicamarca (.r)
43
43
44 startUTSeconds : fecha inicial del rango seleccionado. La fecha esta dada en
44 startUTSeconds : fecha inicial del rango seleccionado. La fecha esta dada en
45 segundos contados desde 01/01/1970.
45 segundos contados desde 01/01/1970.
46 endUTSeconds : fecha final del rango seleccionado. La fecha esta dada en
46 endUTSeconds : fecha final del rango seleccionado. La fecha esta dada en
47 segundos contados desde 01/01/1970.
47 segundos contados desde 01/01/1970.
48
48
49 Return:
49 Return:
50 Boolean : Retorna True si el archivo de datos contiene datos en el rango de
50 Boolean : Retorna True si el archivo de datos contiene datos en el rango de
51 fecha especificado, de lo contrario retorna False.
51 fecha especificado, de lo contrario retorna False.
52
52
53 Excepciones:
53 Excepciones:
54 Si el archivo no existe o no puede ser abierto
54 Si el archivo no existe o no puede ser abierto
55 Si la cabecera no puede ser leida.
55 Si la cabecera no puede ser leida.
56
56
57 """
57 """
58 basicHeaderObj = BasicHeader()
58 basicHeaderObj = BasicHeader()
59
59
60 try:
60 try:
61 fp = open(filename,'rb')
61 fp = open(filename,'rb')
62 except:
62 except:
63 raise IOError, "The file %s can't be opened" %(filename)
63 raise IOError, "The file %s can't be opened" %(filename)
64
64
65 sts = basicHeaderObj.read(fp)
65 sts = basicHeaderObj.read(fp)
66 fp.close()
66 fp.close()
67
67
68 if not(sts):
68 if not(sts):
69 print "Skipping the file %s because it has not a valid header" %(filename)
69 print "Skipping the file %s because it has not a valid header" %(filename)
70 return 0
70 return 0
71
71
72 if not ((startUTSeconds <= basicHeaderObj.utc) and (endUTSeconds > basicHeaderObj.utc)):
72 if not ((startUTSeconds <= basicHeaderObj.utc) and (endUTSeconds > basicHeaderObj.utc)):
73 return 0
73 return 0
74
74
75 return 1
75 return 1
76
76
77 def isFileinThisTime(filename, startTime, endTime):
77 def isFileinThisTime(filename, startTime, endTime):
78 """
78 """
79 Retorna 1 si el archivo de datos se encuentra dentro del rango de horas especificado.
79 Retorna 1 si el archivo de datos se encuentra dentro del rango de horas especificado.
80
80
81 Inputs:
81 Inputs:
82 filename : nombre completo del archivo de datos en formato Jicamarca (.r)
82 filename : nombre completo del archivo de datos en formato Jicamarca (.r)
83
83
84 startTime : tiempo inicial del rango seleccionado en formato datetime.time
84 startTime : tiempo inicial del rango seleccionado en formato datetime.time
85
85
86 endTime : tiempo final del rango seleccionado en formato datetime.time
86 endTime : tiempo final del rango seleccionado en formato datetime.time
87
87
88 Return:
88 Return:
89 Boolean : Retorna True si el archivo de datos contiene datos en el rango de
89 Boolean : Retorna True si el archivo de datos contiene datos en el rango de
90 fecha especificado, de lo contrario retorna False.
90 fecha especificado, de lo contrario retorna False.
91
91
92 Excepciones:
92 Excepciones:
93 Si el archivo no existe o no puede ser abierto
93 Si el archivo no existe o no puede ser abierto
94 Si la cabecera no puede ser leida.
94 Si la cabecera no puede ser leida.
95
95
96 """
96 """
97
97
98
98
99 try:
99 try:
100 fp = open(filename,'rb')
100 fp = open(filename,'rb')
101 except:
101 except:
102 raise IOError, "The file %s can't be opened" %(filename)
102 raise IOError, "The file %s can't be opened" %(filename)
103
103
104 basicHeaderObj = BasicHeader()
104 basicHeaderObj = BasicHeader()
105 sts = basicHeaderObj.read(fp)
105 sts = basicHeaderObj.read(fp)
106 fp.close()
106 fp.close()
107
107
108 thisTime = basicHeaderObj.datatime.time()
108 thisTime = basicHeaderObj.datatime.time()
109
109
110 if not(sts):
110 if not(sts):
111 print "Skipping the file %s because it has not a valid header" %(filename)
111 print "Skipping the file %s because it has not a valid header" %(filename)
112 return 0
112 return 0
113
113
114 if not ((startTime <= thisTime) and (endTime > thisTime)):
114 if not ((startTime <= thisTime) and (endTime > thisTime)):
115 return 0
115 return 0
116
116
117 return 1
117 return 1
118
118
119 def getlastFileFromPath(path, ext):
119 def getlastFileFromPath(path, ext):
120 """
120 """
121 Depura el fileList dejando solo los que cumplan el formato de "PYYYYDDDSSS.ext"
121 Depura el fileList dejando solo los que cumplan el formato de "PYYYYDDDSSS.ext"
122 al final de la depuracion devuelve el ultimo file de la lista que quedo.
122 al final de la depuracion devuelve el ultimo file de la lista que quedo.
123
123
124 Input:
124 Input:
125 fileList : lista conteniendo todos los files (sin path) que componen una determinada carpeta
125 fileList : lista conteniendo todos los files (sin path) que componen una determinada carpeta
126 ext : extension de los files contenidos en una carpeta
126 ext : extension de los files contenidos en una carpeta
127
127
128 Return:
128 Return:
129 El ultimo file de una determinada carpeta, no se considera el path.
129 El ultimo file de una determinada carpeta, no se considera el path.
130 """
130 """
131 validFilelist = []
131 validFilelist = []
132 fileList = os.listdir(path)
132 fileList = os.listdir(path)
133
133
134 # 0 1234 567 89A BCDE
134 # 0 1234 567 89A BCDE
135 # H YYYY DDD SSS .ext
135 # H YYYY DDD SSS .ext
136
136
137 for file in fileList:
137 for file in fileList:
138 try:
138 try:
139 year = int(file[1:5])
139 year = int(file[1:5])
140 doy = int(file[5:8])
140 doy = int(file[5:8])
141
141
142
142
143 except:
143 except:
144 continue
144 continue
145
145
146 if (os.path.splitext(file)[-1].lower() != ext.lower()):
146 if (os.path.splitext(file)[-1].lower() != ext.lower()):
147 continue
147 continue
148
148
149 validFilelist.append(file)
149 validFilelist.append(file)
150
150
151 if validFilelist:
151 if validFilelist:
152 validFilelist = sorted( validFilelist, key=str.lower )
152 validFilelist = sorted( validFilelist, key=str.lower )
153 return validFilelist[-1]
153 return validFilelist[-1]
154
154
155 return None
155 return None
156
156
157 def checkForRealPath(path, year, doy, set, ext):
157 def checkForRealPath(path, year, doy, set, ext):
158 """
158 """
159 Por ser Linux Case Sensitive entonces checkForRealPath encuentra el nombre correcto de un path,
159 Por ser Linux Case Sensitive entonces checkForRealPath encuentra el nombre correcto de un path,
160 Prueba por varias combinaciones de nombres entre mayusculas y minusculas para determinar
160 Prueba por varias combinaciones de nombres entre mayusculas y minusculas para determinar
161 el path exacto de un determinado file.
161 el path exacto de un determinado file.
162
162
163 Example :
163 Example :
164 nombre correcto del file es .../.../D2009307/P2009307367.ext
164 nombre correcto del file es .../.../D2009307/P2009307367.ext
165
165
166 Entonces la funcion prueba con las siguientes combinaciones
166 Entonces la funcion prueba con las siguientes combinaciones
167 .../.../y2009307367.ext
167 .../.../y2009307367.ext
168 .../.../Y2009307367.ext
168 .../.../Y2009307367.ext
169 .../.../x2009307/y2009307367.ext
169 .../.../x2009307/y2009307367.ext
170 .../.../x2009307/Y2009307367.ext
170 .../.../x2009307/Y2009307367.ext
171 .../.../X2009307/y2009307367.ext
171 .../.../X2009307/y2009307367.ext
172 .../.../X2009307/Y2009307367.ext
172 .../.../X2009307/Y2009307367.ext
173 siendo para este caso, la ultima combinacion de letras, identica al file buscado
173 siendo para este caso, la ultima combinacion de letras, identica al file buscado
174
174
175 Return:
175 Return:
176 Si encuentra la cobinacion adecuada devuelve el path completo y el nombre del file
176 Si encuentra la cobinacion adecuada devuelve el path completo y el nombre del file
177 caso contrario devuelve None como path y el la ultima combinacion de nombre en mayusculas
177 caso contrario devuelve None como path y el la ultima combinacion de nombre en mayusculas
178 para el filename
178 para el filename
179 """
179 """
180 fullfilename = None
180 fullfilename = None
181 find_flag = False
181 find_flag = False
182 filename = None
182 filename = None
183
183
184 prefixDirList = [None,'d','D']
184 prefixDirList = [None,'d','D']
185 if ext.lower() == ".r": #voltage
185 if ext.lower() == ".r": #voltage
186 prefixFileList = ['d','D']
186 prefixFileList = ['d','D']
187 elif ext.lower() == ".pdata": #spectra
187 elif ext.lower() == ".pdata": #spectra
188 prefixFileList = ['p','P']
188 prefixFileList = ['p','P']
189 else:
189 else:
190 return None, filename
190 return None, filename
191
191
192 #barrido por las combinaciones posibles
192 #barrido por las combinaciones posibles
193 for prefixDir in prefixDirList:
193 for prefixDir in prefixDirList:
194 thispath = path
194 thispath = path
195 if prefixDir != None:
195 if prefixDir != None:
196 #formo el nombre del directorio xYYYYDDD (x=d o x=D)
196 #formo el nombre del directorio xYYYYDDD (x=d o x=D)
197 thispath = os.path.join(path, "%s%04d%03d" % ( prefixDir, year, doy ))
197 thispath = os.path.join(path, "%s%04d%03d" % ( prefixDir, year, doy ))
198
198
199 for prefixFile in prefixFileList: #barrido por las dos combinaciones posibles de "D"
199 for prefixFile in prefixFileList: #barrido por las dos combinaciones posibles de "D"
200 filename = "%s%04d%03d%03d%s" % ( prefixFile, year, doy, set, ext ) #formo el nombre del file xYYYYDDDSSS.ext
200 filename = "%s%04d%03d%03d%s" % ( prefixFile, year, doy, set, ext ) #formo el nombre del file xYYYYDDDSSS.ext
201 fullfilename = os.path.join( thispath, filename ) #formo el path completo
201 fullfilename = os.path.join( thispath, filename ) #formo el path completo
202
202
203 if os.path.exists( fullfilename ): #verifico que exista
203 if os.path.exists( fullfilename ): #verifico que exista
204 find_flag = True
204 find_flag = True
205 break
205 break
206 if find_flag:
206 if find_flag:
207 break
207 break
208
208
209 if not(find_flag):
209 if not(find_flag):
210 return None, filename
210 return None, filename
211
211
212 return fullfilename, filename
212 return fullfilename, filename
213
213
214 class JRODataIO:
214 class JRODataIO:
215
215
216 c = 3E8
216 c = 3E8
217
217
218 isConfig = False
218 isConfig = False
219
219
220 basicHeaderObj = BasicHeader()
220 basicHeaderObj = BasicHeader()
221
221
222 systemHeaderObj = SystemHeader()
222 systemHeaderObj = SystemHeader()
223
223
224 radarControllerHeaderObj = RadarControllerHeader()
224 radarControllerHeaderObj = RadarControllerHeader()
225
225
226 processingHeaderObj = ProcessingHeader()
226 processingHeaderObj = ProcessingHeader()
227
227
228 online = 0
228 online = 0
229
229
230 dtype = None
230 dtype = None
231
231
232 pathList = []
232 pathList = []
233
233
234 filenameList = []
234 filenameList = []
235
235
236 filename = None
236 filename = None
237
237
238 ext = None
238 ext = None
239
239
240 flagIsNewFile = 1
240 flagIsNewFile = 1
241
241
242 flagTimeBlock = 0
242 flagTimeBlock = 0
243
243
244 flagIsNewBlock = 0
244 flagIsNewBlock = 0
245
245
246 fp = None
246 fp = None
247
247
248 firstHeaderSize = 0
248 firstHeaderSize = 0
249
249
250 basicHeaderSize = 24
250 basicHeaderSize = 24
251
251
252 versionFile = 1103
252 versionFile = 1103
253
253
254 fileSize = None
254 fileSize = None
255
255
256 ippSeconds = None
256 ippSeconds = None
257
257
258 fileSizeByHeader = None
258 fileSizeByHeader = None
259
259
260 fileIndex = None
260 fileIndex = None
261
261
262 profileIndex = None
262 profileIndex = None
263
263
264 blockIndex = None
264 blockIndex = None
265
265
266 nTotalBlocks = None
266 nTotalBlocks = None
267
267
268 maxTimeStep = 30
268 maxTimeStep = 30
269
269
270 lastUTTime = None
270 lastUTTime = None
271
271
272 datablock = None
272 datablock = None
273
273
274 dataOut = None
274 dataOut = None
275
275
276 blocksize = None
276 blocksize = None
277
277
278 def __init__(self):
278 def __init__(self):
279
279
280 raise ValueError, "Not implemented"
280 raise ValueError, "Not implemented"
281
281
282 def run(self):
282 def run(self):
283
283
284 raise ValueError, "Not implemented"
284 raise ValueError, "Not implemented"
285
285
286 def getOutput(self):
286 def getOutput(self):
287
287
288 return self.dataOut
288 return self.dataOut
289
289
290 class JRODataReader(JRODataIO, ProcessingUnit):
290 class JRODataReader(JRODataIO, ProcessingUnit):
291
291
292 nReadBlocks = 0
292 nReadBlocks = 0
293
293
294 delay = 10 #number of seconds waiting a new file
294 delay = 10 #number of seconds waiting a new file
295
295
296 nTries = 3 #quantity tries
296 nTries = 3 #quantity tries
297
297
298 nFiles = 3 #number of files for searching
298 nFiles = 3 #number of files for searching
299
299
300 flagNoMoreFiles = 0
300 flagNoMoreFiles = 0
301
301
302 def __init__(self):
302 def __init__(self):
303
303
304 """
304 """
305
305
306 """
306 """
307
307
308 raise ValueError, "This method has not been implemented"
308 raise ValueError, "This method has not been implemented"
309
309
310
310
311 def createObjByDefault(self):
311 def createObjByDefault(self):
312 """
312 """
313
313
314 """
314 """
315 raise ValueError, "This method has not been implemented"
315 raise ValueError, "This method has not been implemented"
316
316
317 def getBlockDimension(self):
317 def getBlockDimension(self):
318
318
319 raise ValueError, "No implemented"
319 raise ValueError, "No implemented"
320
320
321 def __searchFilesOffLine(self,
321 def __searchFilesOffLine(self,
322 path,
322 path,
323 startDate,
323 startDate,
324 endDate,
324 endDate,
325 startTime=datetime.time(0,0,0),
325 startTime=datetime.time(0,0,0),
326 endTime=datetime.time(23,59,59),
326 endTime=datetime.time(23,59,59),
327 set=None,
327 set=None,
328 expLabel='',
328 expLabel='',
329 ext='.r',
329 ext='.r',
330 walk=True):
330 walk=True):
331
331
332 pathList = []
332 pathList = []
333
333
334 if not walk:
334 if not walk:
335 pathList.append(path)
335 pathList.append(path)
336
336
337 else:
337 else:
338 dirList = []
338 dirList = []
339 for thisPath in os.listdir(path):
339 for thisPath in os.listdir(path):
340 if os.path.isdir(os.path.join(path,thisPath)):
340 if os.path.isdir(os.path.join(path,thisPath)):
341 dirList.append(thisPath)
341 dirList.append(thisPath)
342
342
343 if not(dirList):
343 if not(dirList):
344 return None, None
344 return None, None
345
345
346 thisDate = startDate
346 thisDate = startDate
347
347
348 while(thisDate <= endDate):
348 while(thisDate <= endDate):
349 year = thisDate.timetuple().tm_year
349 year = thisDate.timetuple().tm_year
350 doy = thisDate.timetuple().tm_yday
350 doy = thisDate.timetuple().tm_yday
351
351
352 match = fnmatch.filter(dirList, '?' + '%4.4d%3.3d' % (year,doy))
352 match = fnmatch.filter(dirList, '?' + '%4.4d%3.3d' % (year,doy))
353 if len(match) == 0:
353 if len(match) == 0:
354 thisDate += datetime.timedelta(1)
354 thisDate += datetime.timedelta(1)
355 continue
355 continue
356
356
357 pathList.append(os.path.join(path,match[0],expLabel))
357 pathList.append(os.path.join(path,match[0],expLabel))
358 thisDate += datetime.timedelta(1)
358 thisDate += datetime.timedelta(1)
359
359
360 if pathList == []:
361 print "Any folder found into date range %s-%s" %(startDate, endDate)
362 return None, None
363
364 print "%d folder(s) found [%s, ...]" %(len(pathList), pathList[0])
360
365
361 filenameList = []
366 filenameList = []
362 for thisPath in pathList:
367 for thisPath in pathList:
363
368
364 fileList = glob.glob1(thisPath, "*%s" %ext)
369 fileList = glob.glob1(thisPath, "*%s" %ext)
365 fileList.sort()
370 fileList.sort()
366
371
367 for file in fileList:
372 for file in fileList:
368
373
369 filename = os.path.join(thisPath,file)
374 filename = os.path.join(thisPath,file)
370
375
371 if isFileinThisTime(filename, startTime, endTime):
376 if isFileinThisTime(filename, startTime, endTime):
372 filenameList.append(filename)
377 filenameList.append(filename)
373
378
374 if not(filenameList):
379 if not(filenameList):
380 print "Any file found into time range %s-%s" %(startTime, endTime)
375 return None, None
381 return None, None
376
382
377 self.filenameList = filenameList
383 self.filenameList = filenameList
378
384
379 return pathList, filenameList
385 return pathList, filenameList
380
386
381 def __searchFilesOnLine(self, path, expLabel = "", ext = None, walk=True):
387 def __searchFilesOnLine(self, path, expLabel = "", ext = None, walk=True):
382
388
383 """
389 """
384 Busca el ultimo archivo de la ultima carpeta (determinada o no por startDateTime) y
390 Busca el ultimo archivo de la ultima carpeta (determinada o no por startDateTime) y
385 devuelve el archivo encontrado ademas de otros datos.
391 devuelve el archivo encontrado ademas de otros datos.
386
392
387 Input:
393 Input:
388 path : carpeta donde estan contenidos los files que contiene data
394 path : carpeta donde estan contenidos los files que contiene data
389
395
390 expLabel : Nombre del subexperimento (subfolder)
396 expLabel : Nombre del subexperimento (subfolder)
391
397
392 ext : extension de los files
398 ext : extension de los files
393
399
394 walk : Si es habilitado no realiza busquedas dentro de los ubdirectorios (doypath)
400 walk : Si es habilitado no realiza busquedas dentro de los ubdirectorios (doypath)
395
401
396 Return:
402 Return:
397 directory : eL directorio donde esta el file encontrado
403 directory : eL directorio donde esta el file encontrado
398 filename : el ultimo file de una determinada carpeta
404 filename : el ultimo file de una determinada carpeta
399 year : el anho
405 year : el anho
400 doy : el numero de dia del anho
406 doy : el numero de dia del anho
401 set : el set del archivo
407 set : el set del archivo
402
408
403
409
404 """
410 """
405 dirList = []
411 dirList = []
406
412
407 if walk:
413 if walk:
408
414
409 #Filtra solo los directorios
415 #Filtra solo los directorios
410 for thisPath in os.listdir(path):
416 for thisPath in os.listdir(path):
411 if os.path.isdir(os.path.join(path, thisPath)):
417 if os.path.isdir(os.path.join(path, thisPath)):
412 dirList.append(thisPath)
418 dirList.append(thisPath)
413
419
414 if not(dirList):
420 if not(dirList):
415 return None, None, None, None, None
421 return None, None, None, None, None
416
422
417 dirList = sorted( dirList, key=str.lower )
423 dirList = sorted( dirList, key=str.lower )
418
424
419 doypath = dirList[-1]
425 doypath = dirList[-1]
420 fullpath = os.path.join(path, doypath, expLabel)
426 fullpath = os.path.join(path, doypath, expLabel)
421
427
422 else:
428 else:
423 fullpath = path
429 fullpath = path
424
430
425 filename = getlastFileFromPath(fullpath, ext)
431 filename = getlastFileFromPath(fullpath, ext)
426
432
427 if not(filename):
433 if not(filename):
428 return None, None, None, None, None
434 return None, None, None, None, None
429
435
430 if not(self.__verifyFile(os.path.join(fullpath, filename))):
436 if not(self.__verifyFile(os.path.join(fullpath, filename))):
431 return None, None, None, None, None
437 return None, None, None, None, None
432
438
433 year = int( filename[1:5] )
439 year = int( filename[1:5] )
434 doy = int( filename[5:8] )
440 doy = int( filename[5:8] )
435 set = int( filename[8:11] )
441 set = int( filename[8:11] )
436
442
437 return fullpath, filename, year, doy, set
443 return fullpath, filename, year, doy, set
438
444
439
445
440
446
441 def __setNextFileOffline(self):
447 def __setNextFileOffline(self):
442
448
443 idFile = self.fileIndex
449 idFile = self.fileIndex
444
450
445 while (True):
451 while (True):
446 idFile += 1
452 idFile += 1
447 if not(idFile < len(self.filenameList)):
453 if not(idFile < len(self.filenameList)):
448 self.flagNoMoreFiles = 1
454 self.flagNoMoreFiles = 1
449 print "No more Files"
455 print "No more Files"
450 return 0
456 return 0
451
457
452 filename = self.filenameList[idFile]
458 filename = self.filenameList[idFile]
453
459
454 if not(self.__verifyFile(filename)):
460 if not(self.__verifyFile(filename)):
455 continue
461 continue
456
462
457 fileSize = os.path.getsize(filename)
463 fileSize = os.path.getsize(filename)
458 fp = open(filename,'rb')
464 fp = open(filename,'rb')
459 break
465 break
460
466
461 self.flagIsNewFile = 1
467 self.flagIsNewFile = 1
462 self.fileIndex = idFile
468 self.fileIndex = idFile
463 self.filename = filename
469 self.filename = filename
464 self.fileSize = fileSize
470 self.fileSize = fileSize
465 self.fp = fp
471 self.fp = fp
466
472
467 print "Setting the file: %s"%self.filename
473 print "Setting the file: %s"%self.filename
468
474
469 return 1
475 return 1
470
476
471 def __setNextFileOnline(self):
477 def __setNextFileOnline(self):
472 """
478 """
473 Busca el siguiente file que tenga suficiente data para ser leida, dentro de un folder especifico, si
479 Busca el siguiente file que tenga suficiente data para ser leida, dentro de un folder especifico, si
474 no encuentra un file valido espera un tiempo determinado y luego busca en los posibles n files
480 no encuentra un file valido espera un tiempo determinado y luego busca en los posibles n files
475 siguientes.
481 siguientes.
476
482
477 Affected:
483 Affected:
478 self.flagIsNewFile
484 self.flagIsNewFile
479 self.filename
485 self.filename
480 self.fileSize
486 self.fileSize
481 self.fp
487 self.fp
482 self.set
488 self.set
483 self.flagNoMoreFiles
489 self.flagNoMoreFiles
484
490
485 Return:
491 Return:
486 0 : si luego de una busqueda del siguiente file valido este no pudo ser encontrado
492 0 : si luego de una busqueda del siguiente file valido este no pudo ser encontrado
487 1 : si el file fue abierto con exito y esta listo a ser leido
493 1 : si el file fue abierto con exito y esta listo a ser leido
488
494
489 Excepciones:
495 Excepciones:
490 Si un determinado file no puede ser abierto
496 Si un determinado file no puede ser abierto
491 """
497 """
492 nFiles = 0
498 nFiles = 0
493 fileOk_flag = False
499 fileOk_flag = False
494 firstTime_flag = True
500 firstTime_flag = True
495
501
496 self.set += 1
502 self.set += 1
497
503
498 #busca el 1er file disponible
504 #busca el 1er file disponible
499 fullfilename, filename = checkForRealPath( self.path, self.year, self.doy, self.set, self.ext )
505 fullfilename, filename = checkForRealPath( self.path, self.year, self.doy, self.set, self.ext )
500 if fullfilename:
506 if fullfilename:
501 if self.__verifyFile(fullfilename, False):
507 if self.__verifyFile(fullfilename, False):
502 fileOk_flag = True
508 fileOk_flag = True
503
509
504 #si no encuentra un file entonces espera y vuelve a buscar
510 #si no encuentra un file entonces espera y vuelve a buscar
505 if not(fileOk_flag):
511 if not(fileOk_flag):
506 for nFiles in range(self.nFiles+1): #busco en los siguientes self.nFiles+1 files posibles
512 for nFiles in range(self.nFiles+1): #busco en los siguientes self.nFiles+1 files posibles
507
513
508 if firstTime_flag: #si es la 1era vez entonces hace el for self.nTries veces
514 if firstTime_flag: #si es la 1era vez entonces hace el for self.nTries veces
509 tries = self.nTries
515 tries = self.nTries
510 else:
516 else:
511 tries = 1 #si no es la 1era vez entonces solo lo hace una vez
517 tries = 1 #si no es la 1era vez entonces solo lo hace una vez
512
518
513 for nTries in range( tries ):
519 for nTries in range( tries ):
514 if firstTime_flag:
520 if firstTime_flag:
515 print "\tWaiting %0.2f sec for the file \"%s\" , try %03d ..." % ( self.delay, filename, nTries+1 )
521 print "\tWaiting %0.2f sec for the file \"%s\" , try %03d ..." % ( self.delay, filename, nTries+1 )
516 time.sleep( self.delay )
522 time.sleep( self.delay )
517 else:
523 else:
518 print "\tSearching next \"%s%04d%03d%03d%s\" file ..." % (self.optchar, self.year, self.doy, self.set, self.ext)
524 print "\tSearching next \"%s%04d%03d%03d%s\" file ..." % (self.optchar, self.year, self.doy, self.set, self.ext)
519
525
520 fullfilename, filename = checkForRealPath( self.path, self.year, self.doy, self.set, self.ext )
526 fullfilename, filename = checkForRealPath( self.path, self.year, self.doy, self.set, self.ext )
521 if fullfilename:
527 if fullfilename:
522 if self.__verifyFile(fullfilename):
528 if self.__verifyFile(fullfilename):
523 fileOk_flag = True
529 fileOk_flag = True
524 break
530 break
525
531
526 if fileOk_flag:
532 if fileOk_flag:
527 break
533 break
528
534
529 firstTime_flag = False
535 firstTime_flag = False
530
536
531 print "\tSkipping the file \"%s\" due to this file doesn't exist" % filename
537 print "\tSkipping the file \"%s\" due to this file doesn't exist" % filename
532 self.set += 1
538 self.set += 1
533
539
534 if nFiles == (self.nFiles-1): #si no encuentro el file buscado cambio de carpeta y busco en la siguiente carpeta
540 if nFiles == (self.nFiles-1): #si no encuentro el file buscado cambio de carpeta y busco en la siguiente carpeta
535 self.set = 0
541 self.set = 0
536 self.doy += 1
542 self.doy += 1
537
543
538 if fileOk_flag:
544 if fileOk_flag:
539 self.fileSize = os.path.getsize( fullfilename )
545 self.fileSize = os.path.getsize( fullfilename )
540 self.filename = fullfilename
546 self.filename = fullfilename
541 self.flagIsNewFile = 1
547 self.flagIsNewFile = 1
542 if self.fp != None: self.fp.close()
548 if self.fp != None: self.fp.close()
543 self.fp = open(fullfilename, 'rb')
549 self.fp = open(fullfilename, 'rb')
544 self.flagNoMoreFiles = 0
550 self.flagNoMoreFiles = 0
545 print 'Setting the file: %s' % fullfilename
551 print 'Setting the file: %s' % fullfilename
546 else:
552 else:
547 self.fileSize = 0
553 self.fileSize = 0
548 self.filename = None
554 self.filename = None
549 self.flagIsNewFile = 0
555 self.flagIsNewFile = 0
550 self.fp = None
556 self.fp = None
551 self.flagNoMoreFiles = 1
557 self.flagNoMoreFiles = 1
552 print 'No more Files'
558 print 'No more Files'
553
559
554 return fileOk_flag
560 return fileOk_flag
555
561
556
562
557 def setNextFile(self):
563 def setNextFile(self):
558 if self.fp != None:
564 if self.fp != None:
559 self.fp.close()
565 self.fp.close()
560
566
561 if self.online:
567 if self.online:
562 newFile = self.__setNextFileOnline()
568 newFile = self.__setNextFileOnline()
563 else:
569 else:
564 newFile = self.__setNextFileOffline()
570 newFile = self.__setNextFileOffline()
565
571
566 if not(newFile):
572 if not(newFile):
567 return 0
573 return 0
568
574
569 self.__readFirstHeader()
575 self.__readFirstHeader()
570 self.nReadBlocks = 0
576 self.nReadBlocks = 0
571 return 1
577 return 1
572
578
573 def __waitNewBlock(self):
579 def __waitNewBlock(self):
574 """
580 """
575 Return 1 si se encontro un nuevo bloque de datos, 0 de otra forma.
581 Return 1 si se encontro un nuevo bloque de datos, 0 de otra forma.
576
582
577 Si el modo de lectura es OffLine siempre retorn 0
583 Si el modo de lectura es OffLine siempre retorn 0
578 """
584 """
579 if not self.online:
585 if not self.online:
580 return 0
586 return 0
581
587
582 if (self.nReadBlocks >= self.processingHeaderObj.dataBlocksPerFile):
588 if (self.nReadBlocks >= self.processingHeaderObj.dataBlocksPerFile):
583 return 0
589 return 0
584
590
585 currentPointer = self.fp.tell()
591 currentPointer = self.fp.tell()
586
592
587 neededSize = self.processingHeaderObj.blockSize + self.basicHeaderSize
593 neededSize = self.processingHeaderObj.blockSize + self.basicHeaderSize
588
594
589 for nTries in range( self.nTries ):
595 for nTries in range( self.nTries ):
590
596
591 self.fp.close()
597 self.fp.close()
592 self.fp = open( self.filename, 'rb' )
598 self.fp = open( self.filename, 'rb' )
593 self.fp.seek( currentPointer )
599 self.fp.seek( currentPointer )
594
600
595 self.fileSize = os.path.getsize( self.filename )
601 self.fileSize = os.path.getsize( self.filename )
596 currentSize = self.fileSize - currentPointer
602 currentSize = self.fileSize - currentPointer
597
603
598 if ( currentSize >= neededSize ):
604 if ( currentSize >= neededSize ):
599 self.__rdBasicHeader()
605 self.__rdBasicHeader()
600 return 1
606 return 1
601
607
602 print "\tWaiting %0.2f seconds for the next block, try %03d ..." % (self.delay, nTries+1)
608 print "\tWaiting %0.2f seconds for the next block, try %03d ..." % (self.delay, nTries+1)
603 time.sleep( self.delay )
609 time.sleep( self.delay )
604
610
605
611
606 return 0
612 return 0
607
613
608 def __setNewBlock(self):
614 def __setNewBlock(self):
609
615
610 if self.fp == None:
616 if self.fp == None:
611 return 0
617 return 0
612
618
613 if self.flagIsNewFile:
619 if self.flagIsNewFile:
614 return 1
620 return 1
615
621
616 self.lastUTTime = self.basicHeaderObj.utc
622 self.lastUTTime = self.basicHeaderObj.utc
617 currentSize = self.fileSize - self.fp.tell()
623 currentSize = self.fileSize - self.fp.tell()
618 neededSize = self.processingHeaderObj.blockSize + self.basicHeaderSize
624 neededSize = self.processingHeaderObj.blockSize + self.basicHeaderSize
619
625
620 if (currentSize >= neededSize):
626 if (currentSize >= neededSize):
621 self.__rdBasicHeader()
627 self.__rdBasicHeader()
622 return 1
628 return 1
623
629
624 if self.__waitNewBlock():
630 if self.__waitNewBlock():
625 return 1
631 return 1
626
632
627 if not(self.setNextFile()):
633 if not(self.setNextFile()):
628 return 0
634 return 0
629
635
630 deltaTime = self.basicHeaderObj.utc - self.lastUTTime #
636 deltaTime = self.basicHeaderObj.utc - self.lastUTTime #
631
637
632 self.flagTimeBlock = 0
638 self.flagTimeBlock = 0
633
639
634 if deltaTime > self.maxTimeStep:
640 if deltaTime > self.maxTimeStep:
635 self.flagTimeBlock = 1
641 self.flagTimeBlock = 1
636
642
637 return 1
643 return 1
638
644
639
645
640 def readNextBlock(self):
646 def readNextBlock(self):
641 if not(self.__setNewBlock()):
647 if not(self.__setNewBlock()):
642 return 0
648 return 0
643
649
644 if not(self.readBlock()):
650 if not(self.readBlock()):
645 return 0
651 return 0
646
652
647 return 1
653 return 1
648
654
649 def __rdProcessingHeader(self, fp=None):
655 def __rdProcessingHeader(self, fp=None):
650 if fp == None:
656 if fp == None:
651 fp = self.fp
657 fp = self.fp
652
658
653 self.processingHeaderObj.read(fp)
659 self.processingHeaderObj.read(fp)
654
660
655 def __rdRadarControllerHeader(self, fp=None):
661 def __rdRadarControllerHeader(self, fp=None):
656 if fp == None:
662 if fp == None:
657 fp = self.fp
663 fp = self.fp
658
664
659 self.radarControllerHeaderObj.read(fp)
665 self.radarControllerHeaderObj.read(fp)
660
666
661 def __rdSystemHeader(self, fp=None):
667 def __rdSystemHeader(self, fp=None):
662 if fp == None:
668 if fp == None:
663 fp = self.fp
669 fp = self.fp
664
670
665 self.systemHeaderObj.read(fp)
671 self.systemHeaderObj.read(fp)
666
672
667 def __rdBasicHeader(self, fp=None):
673 def __rdBasicHeader(self, fp=None):
668 if fp == None:
674 if fp == None:
669 fp = self.fp
675 fp = self.fp
670
676
671 self.basicHeaderObj.read(fp)
677 self.basicHeaderObj.read(fp)
672
678
673
679
674 def __readFirstHeader(self):
680 def __readFirstHeader(self):
675 self.__rdBasicHeader()
681 self.__rdBasicHeader()
676 self.__rdSystemHeader()
682 self.__rdSystemHeader()
677 self.__rdRadarControllerHeader()
683 self.__rdRadarControllerHeader()
678 self.__rdProcessingHeader()
684 self.__rdProcessingHeader()
679
685
680 self.firstHeaderSize = self.basicHeaderObj.size
686 self.firstHeaderSize = self.basicHeaderObj.size
681
687
682 datatype = int(numpy.log2((self.processingHeaderObj.processFlags & PROCFLAG.DATATYPE_MASK))-numpy.log2(PROCFLAG.DATATYPE_CHAR))
688 datatype = int(numpy.log2((self.processingHeaderObj.processFlags & PROCFLAG.DATATYPE_MASK))-numpy.log2(PROCFLAG.DATATYPE_CHAR))
683 if datatype == 0:
689 if datatype == 0:
684 datatype_str = numpy.dtype([('real','<i1'),('imag','<i1')])
690 datatype_str = numpy.dtype([('real','<i1'),('imag','<i1')])
685 elif datatype == 1:
691 elif datatype == 1:
686 datatype_str = numpy.dtype([('real','<i2'),('imag','<i2')])
692 datatype_str = numpy.dtype([('real','<i2'),('imag','<i2')])
687 elif datatype == 2:
693 elif datatype == 2:
688 datatype_str = numpy.dtype([('real','<i4'),('imag','<i4')])
694 datatype_str = numpy.dtype([('real','<i4'),('imag','<i4')])
689 elif datatype == 3:
695 elif datatype == 3:
690 datatype_str = numpy.dtype([('real','<i8'),('imag','<i8')])
696 datatype_str = numpy.dtype([('real','<i8'),('imag','<i8')])
691 elif datatype == 4:
697 elif datatype == 4:
692 datatype_str = numpy.dtype([('real','<f4'),('imag','<f4')])
698 datatype_str = numpy.dtype([('real','<f4'),('imag','<f4')])
693 elif datatype == 5:
699 elif datatype == 5:
694 datatype_str = numpy.dtype([('real','<f8'),('imag','<f8')])
700 datatype_str = numpy.dtype([('real','<f8'),('imag','<f8')])
695 else:
701 else:
696 raise ValueError, 'Data type was not defined'
702 raise ValueError, 'Data type was not defined'
697
703
698 self.dtype = datatype_str
704 self.dtype = datatype_str
699 self.ippSeconds = 2 * 1000 * self.radarControllerHeaderObj.ipp / self.c
705 self.ippSeconds = 2 * 1000 * self.radarControllerHeaderObj.ipp / self.c
700 self.fileSizeByHeader = self.processingHeaderObj.dataBlocksPerFile * self.processingHeaderObj.blockSize + self.firstHeaderSize + self.basicHeaderSize*(self.processingHeaderObj.dataBlocksPerFile - 1)
706 self.fileSizeByHeader = self.processingHeaderObj.dataBlocksPerFile * self.processingHeaderObj.blockSize + self.firstHeaderSize + self.basicHeaderSize*(self.processingHeaderObj.dataBlocksPerFile - 1)
701 # self.dataOut.channelList = numpy.arange(self.systemHeaderObj.numChannels)
707 # self.dataOut.channelList = numpy.arange(self.systemHeaderObj.numChannels)
702 # self.dataOut.channelIndexList = numpy.arange(self.systemHeaderObj.numChannels)
708 # self.dataOut.channelIndexList = numpy.arange(self.systemHeaderObj.numChannels)
703 self.getBlockDimension()
709 self.getBlockDimension()
704
710
705
711
706 def __verifyFile(self, filename, msgFlag=True):
712 def __verifyFile(self, filename, msgFlag=True):
707 msg = None
713 msg = None
708 try:
714 try:
709 fp = open(filename, 'rb')
715 fp = open(filename, 'rb')
710 currentPosition = fp.tell()
716 currentPosition = fp.tell()
711 except:
717 except:
712 if msgFlag:
718 if msgFlag:
713 print "The file %s can't be opened" % (filename)
719 print "The file %s can't be opened" % (filename)
714 return False
720 return False
715
721
716 neededSize = self.processingHeaderObj.blockSize + self.firstHeaderSize
722 neededSize = self.processingHeaderObj.blockSize + self.firstHeaderSize
717
723
718 if neededSize == 0:
724 if neededSize == 0:
719 basicHeaderObj = BasicHeader()
725 basicHeaderObj = BasicHeader()
720 systemHeaderObj = SystemHeader()
726 systemHeaderObj = SystemHeader()
721 radarControllerHeaderObj = RadarControllerHeader()
727 radarControllerHeaderObj = RadarControllerHeader()
722 processingHeaderObj = ProcessingHeader()
728 processingHeaderObj = ProcessingHeader()
723
729
724 try:
730 try:
725 if not( basicHeaderObj.read(fp) ): raise IOError
731 if not( basicHeaderObj.read(fp) ): raise IOError
726 if not( systemHeaderObj.read(fp) ): raise IOError
732 if not( systemHeaderObj.read(fp) ): raise IOError
727 if not( radarControllerHeaderObj.read(fp) ): raise IOError
733 if not( radarControllerHeaderObj.read(fp) ): raise IOError
728 if not( processingHeaderObj.read(fp) ): raise IOError
734 if not( processingHeaderObj.read(fp) ): raise IOError
729 data_type = int(numpy.log2((processingHeaderObj.processFlags & PROCFLAG.DATATYPE_MASK))-numpy.log2(PROCFLAG.DATATYPE_CHAR))
735 data_type = int(numpy.log2((processingHeaderObj.processFlags & PROCFLAG.DATATYPE_MASK))-numpy.log2(PROCFLAG.DATATYPE_CHAR))
730
736
731 neededSize = processingHeaderObj.blockSize + basicHeaderObj.size
737 neededSize = processingHeaderObj.blockSize + basicHeaderObj.size
732
738
733 except:
739 except:
734 if msgFlag:
740 if msgFlag:
735 print "\tThe file %s is empty or it hasn't enough data" % filename
741 print "\tThe file %s is empty or it hasn't enough data" % filename
736
742
737 fp.close()
743 fp.close()
738 return False
744 return False
739 else:
745 else:
740 msg = "\tSkipping the file %s due to it hasn't enough data" %filename
746 msg = "\tSkipping the file %s due to it hasn't enough data" %filename
741
747
742 fp.close()
748 fp.close()
743 fileSize = os.path.getsize(filename)
749 fileSize = os.path.getsize(filename)
744 currentSize = fileSize - currentPosition
750 currentSize = fileSize - currentPosition
745 if currentSize < neededSize:
751 if currentSize < neededSize:
746 if msgFlag and (msg != None):
752 if msgFlag and (msg != None):
747 print msg #print"\tSkipping the file %s due to it hasn't enough data" %filename
753 print msg #print"\tSkipping the file %s due to it hasn't enough data" %filename
748 return False
754 return False
749
755
750 return True
756 return True
751
757
752 def setup(self,
758 def setup(self,
753 path=None,
759 path=None,
754 startDate=None,
760 startDate=None,
755 endDate=None,
761 endDate=None,
756 startTime=datetime.time(0,0,0),
762 startTime=datetime.time(0,0,0),
757 endTime=datetime.time(23,59,59),
763 endTime=datetime.time(23,59,59),
758 set=0,
764 set=0,
759 expLabel = "",
765 expLabel = "",
760 ext = None,
766 ext = None,
761 online = False,
767 online = False,
762 delay = 60,
768 delay = 60,
763 walk = True):
769 walk = True):
764
770
765 if path == None:
771 if path == None:
766 raise ValueError, "The path is not valid"
772 raise ValueError, "The path is not valid"
767
773
768 if ext == None:
774 if ext == None:
769 ext = self.ext
775 ext = self.ext
770
776
771 if online:
777 if online:
772 print "Searching files in online mode..."
778 print "Searching files in online mode..."
773
779
774 for nTries in range( self.nTries ):
780 for nTries in range( self.nTries ):
775 fullpath, file, year, doy, set = self.__searchFilesOnLine(path=path, expLabel=expLabel, ext=ext, walk=walk)
781 fullpath, file, year, doy, set = self.__searchFilesOnLine(path=path, expLabel=expLabel, ext=ext, walk=walk)
776
782
777 if fullpath:
783 if fullpath:
778 break
784 break
779
785
780 print '\tWaiting %0.2f sec for an valid file in %s: try %02d ...' % (self.delay, path, nTries+1)
786 print '\tWaiting %0.2f sec for an valid file in %s: try %02d ...' % (self.delay, path, nTries+1)
781 time.sleep( self.delay )
787 time.sleep( self.delay )
782
788
783 if not(fullpath):
789 if not(fullpath):
784 print "There 'isn't valied files in %s" % path
790 print "There 'isn't valied files in %s" % path
785 return None
791 return None
786
792
787 self.year = year
793 self.year = year
788 self.doy = doy
794 self.doy = doy
789 self.set = set - 1
795 self.set = set - 1
790 self.path = path
796 self.path = path
791
797
792 else:
798 else:
793 print "Searching files in offline mode ..."
799 print "Searching files in offline mode ..."
794 pathList, filenameList = self.__searchFilesOffLine(path, startDate=startDate, endDate=endDate,
800 pathList, filenameList = self.__searchFilesOffLine(path, startDate=startDate, endDate=endDate,
795 startTime=startTime, endTime=endTime,
801 startTime=startTime, endTime=endTime,
796 set=set, expLabel=expLabel, ext=ext,
802 set=set, expLabel=expLabel, ext=ext,
797 walk=walk)
803 walk=walk)
798
804
799 if not(pathList):
805 if not(pathList):
800 print "No *%s files into the folder %s \nfor the range: %s - %s"%(ext, path,
806 print "No *%s files into the folder %s \nfor the range: %s - %s"%(ext, path,
801 datetime.datetime.combine(startDate,startTime).ctime(),
807 datetime.datetime.combine(startDate,startTime).ctime(),
802 datetime.datetime.combine(endDate,endTime).ctime())
808 datetime.datetime.combine(endDate,endTime).ctime())
803
809
804 sys.exit(-1)
810 sys.exit(-1)
805
811
806
812
807 self.fileIndex = -1
813 self.fileIndex = -1
808 self.pathList = pathList
814 self.pathList = pathList
809 self.filenameList = filenameList
815 self.filenameList = filenameList
810
816
811 self.online = online
817 self.online = online
812 self.delay = delay
818 self.delay = delay
813 ext = ext.lower()
819 ext = ext.lower()
814 self.ext = ext
820 self.ext = ext
815
821
816 if not(self.setNextFile()):
822 if not(self.setNextFile()):
817 if (startDate!=None) and (endDate!=None):
823 if (startDate!=None) and (endDate!=None):
818 print "No files in range: %s - %s" %(datetime.datetime.combine(startDate,startTime).ctime(), datetime.datetime.combine(endDate,endTime).ctime())
824 print "No files in range: %s - %s" %(datetime.datetime.combine(startDate,startTime).ctime(), datetime.datetime.combine(endDate,endTime).ctime())
819 elif startDate != None:
825 elif startDate != None:
820 print "No files in range: %s" %(datetime.datetime.combine(startDate,startTime).ctime())
826 print "No files in range: %s" %(datetime.datetime.combine(startDate,startTime).ctime())
821 else:
827 else:
822 print "No files"
828 print "No files"
823
829
824 sys.exit(-1)
830 sys.exit(-1)
825
831
826 # self.updateDataHeader()
832 # self.updateDataHeader()
827
833
828 return self.dataOut
834 return self.dataOut
829
835
830 def getData():
836 def getData():
831
837
832 raise ValueError, "This method has not been implemented"
838 raise ValueError, "This method has not been implemented"
833
839
834 def hasNotDataInBuffer():
840 def hasNotDataInBuffer():
835
841
836 raise ValueError, "This method has not been implemented"
842 raise ValueError, "This method has not been implemented"
837
843
838 def readBlock():
844 def readBlock():
839
845
840 raise ValueError, "This method has not been implemented"
846 raise ValueError, "This method has not been implemented"
841
847
842 def isEndProcess(self):
848 def isEndProcess(self):
843
849
844 return self.flagNoMoreFiles
850 return self.flagNoMoreFiles
845
851
846 def printReadBlocks(self):
852 def printReadBlocks(self):
847
853
848 print "Number of read blocks per file %04d" %self.nReadBlocks
854 print "Number of read blocks per file %04d" %self.nReadBlocks
849
855
850 def printTotalBlocks(self):
856 def printTotalBlocks(self):
851
857
852 print "Number of read blocks %04d" %self.nTotalBlocks
858 print "Number of read blocks %04d" %self.nTotalBlocks
853
859
854 def printInfo(self):
860 def printInfo(self):
855
861
856 print self.basicHeaderObj.printInfo()
862 print self.basicHeaderObj.printInfo()
857 print self.systemHeaderObj.printInfo()
863 print self.systemHeaderObj.printInfo()
858 print self.radarControllerHeaderObj.printInfo()
864 print self.radarControllerHeaderObj.printInfo()
859 print self.processingHeaderObj.printInfo()
865 print self.processingHeaderObj.printInfo()
860
866
861
867
862 def run(self, **kwargs):
868 def run(self, **kwargs):
863
869
864 if not(self.isConfig):
870 if not(self.isConfig):
865
871
866 # self.dataOut = dataOut
872 # self.dataOut = dataOut
867 self.setup(**kwargs)
873 self.setup(**kwargs)
868 self.isConfig = True
874 self.isConfig = True
869
875
870 self.getData()
876 self.getData()
871
877
872 class JRODataWriter(JRODataIO, Operation):
878 class JRODataWriter(JRODataIO, Operation):
873
879
874 """
880 """
875 Esta clase permite escribir datos a archivos procesados (.r o ,pdata). La escritura
881 Esta clase permite escribir datos a archivos procesados (.r o ,pdata). La escritura
876 de los datos siempre se realiza por bloques.
882 de los datos siempre se realiza por bloques.
877 """
883 """
878
884
879 blockIndex = 0
885 blockIndex = 0
880
886
881 path = None
887 path = None
882
888
883 setFile = None
889 setFile = None
884
890
885 profilesPerBlock = None
891 profilesPerBlock = None
886
892
887 blocksPerFile = None
893 blocksPerFile = None
888
894
889 nWriteBlocks = 0
895 nWriteBlocks = 0
890
896
891 def __init__(self, dataOut=None):
897 def __init__(self, dataOut=None):
892 raise ValueError, "Not implemented"
898 raise ValueError, "Not implemented"
893
899
894
900
895 def hasAllDataInBuffer(self):
901 def hasAllDataInBuffer(self):
896 raise ValueError, "Not implemented"
902 raise ValueError, "Not implemented"
897
903
898
904
899 def setBlockDimension(self):
905 def setBlockDimension(self):
900 raise ValueError, "Not implemented"
906 raise ValueError, "Not implemented"
901
907
902
908
903 def writeBlock(self):
909 def writeBlock(self):
904 raise ValueError, "No implemented"
910 raise ValueError, "No implemented"
905
911
906
912
907 def putData(self):
913 def putData(self):
908 raise ValueError, "No implemented"
914 raise ValueError, "No implemented"
909
915
910 def getDataHeader(self):
916 def getDataHeader(self):
911 """
917 """
912 Obtiene una copia del First Header
918 Obtiene una copia del First Header
913
919
914 Affected:
920 Affected:
915
921
916 self.basicHeaderObj
922 self.basicHeaderObj
917 self.systemHeaderObj
923 self.systemHeaderObj
918 self.radarControllerHeaderObj
924 self.radarControllerHeaderObj
919 self.processingHeaderObj self.
925 self.processingHeaderObj self.
920
926
921 Return:
927 Return:
922 None
928 None
923 """
929 """
924
930
925 raise ValueError, "No implemented"
931 raise ValueError, "No implemented"
926
932
927 def getBasicHeader(self):
933 def getBasicHeader(self):
928
934
929 self.basicHeaderObj.size = self.basicHeaderSize #bytes
935 self.basicHeaderObj.size = self.basicHeaderSize #bytes
930 self.basicHeaderObj.version = self.versionFile
936 self.basicHeaderObj.version = self.versionFile
931 self.basicHeaderObj.dataBlock = self.nTotalBlocks
937 self.basicHeaderObj.dataBlock = self.nTotalBlocks
932
938
933 utc = numpy.floor(self.dataOut.utctime)
939 utc = numpy.floor(self.dataOut.utctime)
934 milisecond = (self.dataOut.utctime - utc)* 1000.0
940 milisecond = (self.dataOut.utctime - utc)* 1000.0
935
941
936 self.basicHeaderObj.utc = utc
942 self.basicHeaderObj.utc = utc
937 self.basicHeaderObj.miliSecond = milisecond
943 self.basicHeaderObj.miliSecond = milisecond
938 self.basicHeaderObj.timeZone = 0
944 self.basicHeaderObj.timeZone = 0
939 self.basicHeaderObj.dstFlag = 0
945 self.basicHeaderObj.dstFlag = 0
940 self.basicHeaderObj.errorCount = 0
946 self.basicHeaderObj.errorCount = 0
941
947
942 def __writeFirstHeader(self):
948 def __writeFirstHeader(self):
943 """
949 """
944 Escribe el primer header del file es decir el Basic header y el Long header (SystemHeader, RadarControllerHeader, ProcessingHeader)
950 Escribe el primer header del file es decir el Basic header y el Long header (SystemHeader, RadarControllerHeader, ProcessingHeader)
945
951
946 Affected:
952 Affected:
947 __dataType
953 __dataType
948
954
949 Return:
955 Return:
950 None
956 None
951 """
957 """
952
958
953 # CALCULAR PARAMETROS
959 # CALCULAR PARAMETROS
954
960
955 sizeLongHeader = self.systemHeaderObj.size + self.radarControllerHeaderObj.size + self.processingHeaderObj.size
961 sizeLongHeader = self.systemHeaderObj.size + self.radarControllerHeaderObj.size + self.processingHeaderObj.size
956 self.basicHeaderObj.size = self.basicHeaderSize + sizeLongHeader
962 self.basicHeaderObj.size = self.basicHeaderSize + sizeLongHeader
957
963
958 self.basicHeaderObj.write(self.fp)
964 self.basicHeaderObj.write(self.fp)
959 self.systemHeaderObj.write(self.fp)
965 self.systemHeaderObj.write(self.fp)
960 self.radarControllerHeaderObj.write(self.fp)
966 self.radarControllerHeaderObj.write(self.fp)
961 self.processingHeaderObj.write(self.fp)
967 self.processingHeaderObj.write(self.fp)
962
968
963 self.dtype = self.dataOut.dtype
969 self.dtype = self.dataOut.dtype
964
970
965 def __setNewBlock(self):
971 def __setNewBlock(self):
966 """
972 """
967 Si es un nuevo file escribe el First Header caso contrario escribe solo el Basic Header
973 Si es un nuevo file escribe el First Header caso contrario escribe solo el Basic Header
968
974
969 Return:
975 Return:
970 0 : si no pudo escribir nada
976 0 : si no pudo escribir nada
971 1 : Si escribio el Basic el First Header
977 1 : Si escribio el Basic el First Header
972 """
978 """
973 if self.fp == None:
979 if self.fp == None:
974 self.setNextFile()
980 self.setNextFile()
975
981
976 if self.flagIsNewFile:
982 if self.flagIsNewFile:
977 return 1
983 return 1
978
984
979 if self.blockIndex < self.processingHeaderObj.dataBlocksPerFile:
985 if self.blockIndex < self.processingHeaderObj.dataBlocksPerFile:
980 self.basicHeaderObj.write(self.fp)
986 self.basicHeaderObj.write(self.fp)
981 return 1
987 return 1
982
988
983 if not( self.setNextFile() ):
989 if not( self.setNextFile() ):
984 return 0
990 return 0
985
991
986 return 1
992 return 1
987
993
988
994
989 def writeNextBlock(self):
995 def writeNextBlock(self):
990 """
996 """
991 Selecciona el bloque siguiente de datos y los escribe en un file
997 Selecciona el bloque siguiente de datos y los escribe en un file
992
998
993 Return:
999 Return:
994 0 : Si no hizo pudo escribir el bloque de datos
1000 0 : Si no hizo pudo escribir el bloque de datos
995 1 : Si no pudo escribir el bloque de datos
1001 1 : Si no pudo escribir el bloque de datos
996 """
1002 """
997 if not( self.__setNewBlock() ):
1003 if not( self.__setNewBlock() ):
998 return 0
1004 return 0
999
1005
1000 self.writeBlock()
1006 self.writeBlock()
1001
1007
1002 return 1
1008 return 1
1003
1009
1004 def setNextFile(self):
1010 def setNextFile(self):
1005 """
1011 """
1006 Determina el siguiente file que sera escrito
1012 Determina el siguiente file que sera escrito
1007
1013
1008 Affected:
1014 Affected:
1009 self.filename
1015 self.filename
1010 self.subfolder
1016 self.subfolder
1011 self.fp
1017 self.fp
1012 self.setFile
1018 self.setFile
1013 self.flagIsNewFile
1019 self.flagIsNewFile
1014
1020
1015 Return:
1021 Return:
1016 0 : Si el archivo no puede ser escrito
1022 0 : Si el archivo no puede ser escrito
1017 1 : Si el archivo esta listo para ser escrito
1023 1 : Si el archivo esta listo para ser escrito
1018 """
1024 """
1019 ext = self.ext
1025 ext = self.ext
1020 path = self.path
1026 path = self.path
1021
1027
1022 if self.fp != None:
1028 if self.fp != None:
1023 self.fp.close()
1029 self.fp.close()
1024
1030
1025 timeTuple = time.localtime( self.dataOut.dataUtcTime)
1031 timeTuple = time.localtime( self.dataOut.dataUtcTime)
1026 subfolder = 'D%4.4d%3.3d' % (timeTuple.tm_year,timeTuple.tm_yday)
1032 subfolder = 'D%4.4d%3.3d' % (timeTuple.tm_year,timeTuple.tm_yday)
1027
1033
1028 fullpath = os.path.join( path, subfolder )
1034 fullpath = os.path.join( path, subfolder )
1029 if not( os.path.exists(fullpath) ):
1035 if not( os.path.exists(fullpath) ):
1030 os.mkdir(fullpath)
1036 os.mkdir(fullpath)
1031 self.setFile = -1 #inicializo mi contador de seteo
1037 self.setFile = -1 #inicializo mi contador de seteo
1032 else:
1038 else:
1033 filesList = os.listdir( fullpath )
1039 filesList = os.listdir( fullpath )
1034 if len( filesList ) > 0:
1040 if len( filesList ) > 0:
1035 filesList = sorted( filesList, key=str.lower )
1041 filesList = sorted( filesList, key=str.lower )
1036 filen = filesList[-1]
1042 filen = filesList[-1]
1037 # el filename debera tener el siguiente formato
1043 # el filename debera tener el siguiente formato
1038 # 0 1234 567 89A BCDE (hex)
1044 # 0 1234 567 89A BCDE (hex)
1039 # x YYYY DDD SSS .ext
1045 # x YYYY DDD SSS .ext
1040 if isNumber( filen[8:11] ):
1046 if isNumber( filen[8:11] ):
1041 self.setFile = int( filen[8:11] ) #inicializo mi contador de seteo al seteo del ultimo file
1047 self.setFile = int( filen[8:11] ) #inicializo mi contador de seteo al seteo del ultimo file
1042 else:
1048 else:
1043 self.setFile = -1
1049 self.setFile = -1
1044 else:
1050 else:
1045 self.setFile = -1 #inicializo mi contador de seteo
1051 self.setFile = -1 #inicializo mi contador de seteo
1046
1052
1047 setFile = self.setFile
1053 setFile = self.setFile
1048 setFile += 1
1054 setFile += 1
1049
1055
1050 file = '%s%4.4d%3.3d%3.3d%s' % (self.optchar,
1056 file = '%s%4.4d%3.3d%3.3d%s' % (self.optchar,
1051 timeTuple.tm_year,
1057 timeTuple.tm_year,
1052 timeTuple.tm_yday,
1058 timeTuple.tm_yday,
1053 setFile,
1059 setFile,
1054 ext )
1060 ext )
1055
1061
1056 filename = os.path.join( path, subfolder, file )
1062 filename = os.path.join( path, subfolder, file )
1057
1063
1058 fp = open( filename,'wb' )
1064 fp = open( filename,'wb' )
1059
1065
1060 self.blockIndex = 0
1066 self.blockIndex = 0
1061
1067
1062 #guardando atributos
1068 #guardando atributos
1063 self.filename = filename
1069 self.filename = filename
1064 self.subfolder = subfolder
1070 self.subfolder = subfolder
1065 self.fp = fp
1071 self.fp = fp
1066 self.setFile = setFile
1072 self.setFile = setFile
1067 self.flagIsNewFile = 1
1073 self.flagIsNewFile = 1
1068
1074
1069 self.getDataHeader()
1075 self.getDataHeader()
1070
1076
1071 print 'Writing the file: %s'%self.filename
1077 print 'Writing the file: %s'%self.filename
1072
1078
1073 self.__writeFirstHeader()
1079 self.__writeFirstHeader()
1074
1080
1075 return 1
1081 return 1
1076
1082
1077 def setup(self, dataOut, path, blocksPerFile, profilesPerBlock=None, set=0, ext=None):
1083 def setup(self, dataOut, path, blocksPerFile, profilesPerBlock=None, set=0, ext=None):
1078 """
1084 """
1079 Setea el tipo de formato en la cual sera guardada la data y escribe el First Header
1085 Setea el tipo de formato en la cual sera guardada la data y escribe el First Header
1080
1086
1081 Inputs:
1087 Inputs:
1082 path : el path destino en el cual se escribiran los files a crear
1088 path : el path destino en el cual se escribiran los files a crear
1083 format : formato en el cual sera salvado un file
1089 format : formato en el cual sera salvado un file
1084 set : el setebo del file
1090 set : el setebo del file
1085
1091
1086 Return:
1092 Return:
1087 0 : Si no realizo un buen seteo
1093 0 : Si no realizo un buen seteo
1088 1 : Si realizo un buen seteo
1094 1 : Si realizo un buen seteo
1089 """
1095 """
1090
1096
1091 if ext == None:
1097 if ext == None:
1092 ext = self.ext
1098 ext = self.ext
1093
1099
1094 ext = ext.lower()
1100 ext = ext.lower()
1095
1101
1096 self.ext = ext
1102 self.ext = ext
1097
1103
1098 self.path = path
1104 self.path = path
1099
1105
1100 self.setFile = set - 1
1106 self.setFile = set - 1
1101
1107
1102 self.blocksPerFile = blocksPerFile
1108 self.blocksPerFile = blocksPerFile
1103
1109
1104 self.profilesPerBlock = profilesPerBlock
1110 self.profilesPerBlock = profilesPerBlock
1105
1111
1106 self.dataOut = dataOut
1112 self.dataOut = dataOut
1107
1113
1108 if not(self.setNextFile()):
1114 if not(self.setNextFile()):
1109 print "There isn't a next file"
1115 print "There isn't a next file"
1110 return 0
1116 return 0
1111
1117
1112 self.setBlockDimension()
1118 self.setBlockDimension()
1113
1119
1114 return 1
1120 return 1
1115
1121
1116 def run(self, dataOut, **kwargs):
1122 def run(self, dataOut, **kwargs):
1117
1123
1118 if not(self.isConfig):
1124 if not(self.isConfig):
1119
1125
1120 self.setup(dataOut, **kwargs)
1126 self.setup(dataOut, **kwargs)
1121 self.isConfig = True
1127 self.isConfig = True
1122
1128
1123 self.putData()
1129 self.putData()
1124
1130
1125 class VoltageReader(JRODataReader):
1131 class VoltageReader(JRODataReader):
1126 """
1132 """
1127 Esta clase permite leer datos de voltage desde archivos en formato rawdata (.r). La lectura
1133 Esta clase permite leer datos de voltage desde archivos en formato rawdata (.r). La lectura
1128 de los datos siempre se realiza por bloques. Los datos leidos (array de 3 dimensiones:
1134 de los datos siempre se realiza por bloques. Los datos leidos (array de 3 dimensiones:
1129 perfiles*alturas*canales) son almacenados en la variable "buffer".
1135 perfiles*alturas*canales) son almacenados en la variable "buffer".
1130
1136
1131 perfiles * alturas * canales
1137 perfiles * alturas * canales
1132
1138
1133 Esta clase contiene instancias (objetos) de las clases BasicHeader, SystemHeader,
1139 Esta clase contiene instancias (objetos) de las clases BasicHeader, SystemHeader,
1134 RadarControllerHeader y Voltage. Los tres primeros se usan para almacenar informacion de la
1140 RadarControllerHeader y Voltage. Los tres primeros se usan para almacenar informacion de la
1135 cabecera de datos (metadata), y el cuarto (Voltage) para obtener y almacenar un perfil de
1141 cabecera de datos (metadata), y el cuarto (Voltage) para obtener y almacenar un perfil de
1136 datos desde el "buffer" cada vez que se ejecute el metodo "getData".
1142 datos desde el "buffer" cada vez que se ejecute el metodo "getData".
1137
1143
1138 Example:
1144 Example:
1139
1145
1140 dpath = "/home/myuser/data"
1146 dpath = "/home/myuser/data"
1141
1147
1142 startTime = datetime.datetime(2010,1,20,0,0,0,0,0,0)
1148 startTime = datetime.datetime(2010,1,20,0,0,0,0,0,0)
1143
1149
1144 endTime = datetime.datetime(2010,1,21,23,59,59,0,0,0)
1150 endTime = datetime.datetime(2010,1,21,23,59,59,0,0,0)
1145
1151
1146 readerObj = VoltageReader()
1152 readerObj = VoltageReader()
1147
1153
1148 readerObj.setup(dpath, startTime, endTime)
1154 readerObj.setup(dpath, startTime, endTime)
1149
1155
1150 while(True):
1156 while(True):
1151
1157
1152 #to get one profile
1158 #to get one profile
1153 profile = readerObj.getData()
1159 profile = readerObj.getData()
1154
1160
1155 #print the profile
1161 #print the profile
1156 print profile
1162 print profile
1157
1163
1158 #If you want to see all datablock
1164 #If you want to see all datablock
1159 print readerObj.datablock
1165 print readerObj.datablock
1160
1166
1161 if readerObj.flagNoMoreFiles:
1167 if readerObj.flagNoMoreFiles:
1162 break
1168 break
1163
1169
1164 """
1170 """
1165
1171
1166 ext = ".r"
1172 ext = ".r"
1167
1173
1168 optchar = "D"
1174 optchar = "D"
1169 dataOut = None
1175 dataOut = None
1170
1176
1171
1177
1172 def __init__(self):
1178 def __init__(self):
1173 """
1179 """
1174 Inicializador de la clase VoltageReader para la lectura de datos de voltage.
1180 Inicializador de la clase VoltageReader para la lectura de datos de voltage.
1175
1181
1176 Input:
1182 Input:
1177 dataOut : Objeto de la clase Voltage. Este objeto sera utilizado para
1183 dataOut : Objeto de la clase Voltage. Este objeto sera utilizado para
1178 almacenar un perfil de datos cada vez que se haga un requerimiento
1184 almacenar un perfil de datos cada vez que se haga un requerimiento
1179 (getData). El perfil sera obtenido a partir del buffer de datos,
1185 (getData). El perfil sera obtenido a partir del buffer de datos,
1180 si el buffer esta vacio se hara un nuevo proceso de lectura de un
1186 si el buffer esta vacio se hara un nuevo proceso de lectura de un
1181 bloque de datos.
1187 bloque de datos.
1182 Si este parametro no es pasado se creara uno internamente.
1188 Si este parametro no es pasado se creara uno internamente.
1183
1189
1184 Variables afectadas:
1190 Variables afectadas:
1185 self.dataOut
1191 self.dataOut
1186
1192
1187 Return:
1193 Return:
1188 None
1194 None
1189 """
1195 """
1190
1196
1191 self.isConfig = False
1197 self.isConfig = False
1192
1198
1193 self.datablock = None
1199 self.datablock = None
1194
1200
1195 self.utc = 0
1201 self.utc = 0
1196
1202
1197 self.ext = ".r"
1203 self.ext = ".r"
1198
1204
1199 self.optchar = "D"
1205 self.optchar = "D"
1200
1206
1201 self.basicHeaderObj = BasicHeader()
1207 self.basicHeaderObj = BasicHeader()
1202
1208
1203 self.systemHeaderObj = SystemHeader()
1209 self.systemHeaderObj = SystemHeader()
1204
1210
1205 self.radarControllerHeaderObj = RadarControllerHeader()
1211 self.radarControllerHeaderObj = RadarControllerHeader()
1206
1212
1207 self.processingHeaderObj = ProcessingHeader()
1213 self.processingHeaderObj = ProcessingHeader()
1208
1214
1209 self.online = 0
1215 self.online = 0
1210
1216
1211 self.fp = None
1217 self.fp = None
1212
1218
1213 self.idFile = None
1219 self.idFile = None
1214
1220
1215 self.dtype = None
1221 self.dtype = None
1216
1222
1217 self.fileSizeByHeader = None
1223 self.fileSizeByHeader = None
1218
1224
1219 self.filenameList = []
1225 self.filenameList = []
1220
1226
1221 self.filename = None
1227 self.filename = None
1222
1228
1223 self.fileSize = None
1229 self.fileSize = None
1224
1230
1225 self.firstHeaderSize = 0
1231 self.firstHeaderSize = 0
1226
1232
1227 self.basicHeaderSize = 24
1233 self.basicHeaderSize = 24
1228
1234
1229 self.pathList = []
1235 self.pathList = []
1230
1236
1231 self.filenameList = []
1237 self.filenameList = []
1232
1238
1233 self.lastUTTime = 0
1239 self.lastUTTime = 0
1234
1240
1235 self.maxTimeStep = 30
1241 self.maxTimeStep = 30
1236
1242
1237 self.flagNoMoreFiles = 0
1243 self.flagNoMoreFiles = 0
1238
1244
1239 self.set = 0
1245 self.set = 0
1240
1246
1241 self.path = None
1247 self.path = None
1242
1248
1243 self.profileIndex = 9999
1249 self.profileIndex = 9999
1244
1250
1245 self.delay = 3 #seconds
1251 self.delay = 3 #seconds
1246
1252
1247 self.nTries = 3 #quantity tries
1253 self.nTries = 3 #quantity tries
1248
1254
1249 self.nFiles = 3 #number of files for searching
1255 self.nFiles = 3 #number of files for searching
1250
1256
1251 self.nReadBlocks = 0
1257 self.nReadBlocks = 0
1252
1258
1253 self.flagIsNewFile = 1
1259 self.flagIsNewFile = 1
1254
1260
1255 self.ippSeconds = 0
1261 self.ippSeconds = 0
1256
1262
1257 self.flagTimeBlock = 0
1263 self.flagTimeBlock = 0
1258
1264
1259 self.flagIsNewBlock = 0
1265 self.flagIsNewBlock = 0
1260
1266
1261 self.nTotalBlocks = 0
1267 self.nTotalBlocks = 0
1262
1268
1263 self.blocksize = 0
1269 self.blocksize = 0
1264
1270
1265 self.dataOut = self.createObjByDefault()
1271 self.dataOut = self.createObjByDefault()
1266
1272
1267 def createObjByDefault(self):
1273 def createObjByDefault(self):
1268
1274
1269 dataObj = Voltage()
1275 dataObj = Voltage()
1270
1276
1271 return dataObj
1277 return dataObj
1272
1278
1273 def __hasNotDataInBuffer(self):
1279 def __hasNotDataInBuffer(self):
1274 if self.profileIndex >= self.processingHeaderObj.profilesPerBlock:
1280 if self.profileIndex >= self.processingHeaderObj.profilesPerBlock:
1275 return 1
1281 return 1
1276 return 0
1282 return 0
1277
1283
1278
1284
1279 def getBlockDimension(self):
1285 def getBlockDimension(self):
1280 """
1286 """
1281 Obtiene la cantidad de puntos a leer por cada bloque de datos
1287 Obtiene la cantidad de puntos a leer por cada bloque de datos
1282
1288
1283 Affected:
1289 Affected:
1284 self.blocksize
1290 self.blocksize
1285
1291
1286 Return:
1292 Return:
1287 None
1293 None
1288 """
1294 """
1289 pts2read = self.processingHeaderObj.profilesPerBlock * self.processingHeaderObj.nHeights * self.systemHeaderObj.nChannels
1295 pts2read = self.processingHeaderObj.profilesPerBlock * self.processingHeaderObj.nHeights * self.systemHeaderObj.nChannels
1290 self.blocksize = pts2read
1296 self.blocksize = pts2read
1291
1297
1292
1298
1293 def readBlock(self):
1299 def readBlock(self):
1294 """
1300 """
1295 readBlock lee el bloque de datos desde la posicion actual del puntero del archivo
1301 readBlock lee el bloque de datos desde la posicion actual del puntero del archivo
1296 (self.fp) y actualiza todos los parametros relacionados al bloque de datos
1302 (self.fp) y actualiza todos los parametros relacionados al bloque de datos
1297 (metadata + data). La data leida es almacenada en el buffer y el contador del buffer
1303 (metadata + data). La data leida es almacenada en el buffer y el contador del buffer
1298 es seteado a 0
1304 es seteado a 0
1299
1305
1300 Inputs:
1306 Inputs:
1301 None
1307 None
1302
1308
1303 Return:
1309 Return:
1304 None
1310 None
1305
1311
1306 Affected:
1312 Affected:
1307 self.profileIndex
1313 self.profileIndex
1308 self.datablock
1314 self.datablock
1309 self.flagIsNewFile
1315 self.flagIsNewFile
1310 self.flagIsNewBlock
1316 self.flagIsNewBlock
1311 self.nTotalBlocks
1317 self.nTotalBlocks
1312
1318
1313 Exceptions:
1319 Exceptions:
1314 Si un bloque leido no es un bloque valido
1320 Si un bloque leido no es un bloque valido
1315 """
1321 """
1316
1322
1317 junk = numpy.fromfile( self.fp, self.dtype, self.blocksize )
1323 junk = numpy.fromfile( self.fp, self.dtype, self.blocksize )
1318
1324
1319 try:
1325 try:
1320 junk = junk.reshape( (self.processingHeaderObj.profilesPerBlock, self.processingHeaderObj.nHeights, self.systemHeaderObj.nChannels) )
1326 junk = junk.reshape( (self.processingHeaderObj.profilesPerBlock, self.processingHeaderObj.nHeights, self.systemHeaderObj.nChannels) )
1321 except:
1327 except:
1322 print "The read block (%3d) has not enough data" %self.nReadBlocks
1328 print "The read block (%3d) has not enough data" %self.nReadBlocks
1323 return 0
1329 return 0
1324
1330
1325 junk = numpy.transpose(junk, (2,0,1))
1331 junk = numpy.transpose(junk, (2,0,1))
1326 self.datablock = junk['real'] + junk['imag']*1j
1332 self.datablock = junk['real'] + junk['imag']*1j
1327
1333
1328 self.profileIndex = 0
1334 self.profileIndex = 0
1329
1335
1330 self.flagIsNewFile = 0
1336 self.flagIsNewFile = 0
1331 self.flagIsNewBlock = 1
1337 self.flagIsNewBlock = 1
1332
1338
1333 self.nTotalBlocks += 1
1339 self.nTotalBlocks += 1
1334 self.nReadBlocks += 1
1340 self.nReadBlocks += 1
1335
1341
1336 return 1
1342 return 1
1337
1343
1338
1344
1339 def getData(self):
1345 def getData(self):
1340 """
1346 """
1341 getData obtiene una unidad de datos del buffer de lectura y la copia a la clase "Voltage"
1347 getData obtiene una unidad de datos del buffer de lectura y la copia a la clase "Voltage"
1342 con todos los parametros asociados a este (metadata). cuando no hay datos en el buffer de
1348 con todos los parametros asociados a este (metadata). cuando no hay datos en el buffer de
1343 lectura es necesario hacer una nueva lectura de los bloques de datos usando "readNextBlock"
1349 lectura es necesario hacer una nueva lectura de los bloques de datos usando "readNextBlock"
1344
1350
1345 Ademas incrementa el contador del buffer en 1.
1351 Ademas incrementa el contador del buffer en 1.
1346
1352
1347 Return:
1353 Return:
1348 data : retorna un perfil de voltages (alturas * canales) copiados desde el
1354 data : retorna un perfil de voltages (alturas * canales) copiados desde el
1349 buffer. Si no hay mas archivos a leer retorna None.
1355 buffer. Si no hay mas archivos a leer retorna None.
1350
1356
1351 Variables afectadas:
1357 Variables afectadas:
1352 self.dataOut
1358 self.dataOut
1353 self.profileIndex
1359 self.profileIndex
1354
1360
1355 Affected:
1361 Affected:
1356 self.dataOut
1362 self.dataOut
1357 self.profileIndex
1363 self.profileIndex
1358 self.flagTimeBlock
1364 self.flagTimeBlock
1359 self.flagIsNewBlock
1365 self.flagIsNewBlock
1360 """
1366 """
1361
1367
1362 if self.flagNoMoreFiles:
1368 if self.flagNoMoreFiles:
1363 self.dataOut.flagNoData = True
1369 self.dataOut.flagNoData = True
1364 print 'Process finished'
1370 print 'Process finished'
1365 return 0
1371 return 0
1366
1372
1367 self.flagTimeBlock = 0
1373 self.flagTimeBlock = 0
1368 self.flagIsNewBlock = 0
1374 self.flagIsNewBlock = 0
1369
1375
1370 if self.__hasNotDataInBuffer():
1376 if self.__hasNotDataInBuffer():
1371
1377
1372 if not( self.readNextBlock() ):
1378 if not( self.readNextBlock() ):
1373 return 0
1379 return 0
1374
1380
1375 self.dataOut.dtype = self.dtype
1381 self.dataOut.dtype = self.dtype
1376
1382
1377 self.dataOut.nProfiles = self.processingHeaderObj.profilesPerBlock
1383 self.dataOut.nProfiles = self.processingHeaderObj.profilesPerBlock
1378
1384
1379 xf = self.processingHeaderObj.firstHeight + self.processingHeaderObj.nHeights*self.processingHeaderObj.deltaHeight
1385 xf = self.processingHeaderObj.firstHeight + self.processingHeaderObj.nHeights*self.processingHeaderObj.deltaHeight
1380
1386
1381 self.dataOut.heightList = numpy.arange(self.processingHeaderObj.firstHeight, xf, self.processingHeaderObj.deltaHeight)
1387 self.dataOut.heightList = numpy.arange(self.processingHeaderObj.firstHeight, xf, self.processingHeaderObj.deltaHeight)
1382
1388
1383 self.dataOut.channelList = range(self.systemHeaderObj.nChannels)
1389 self.dataOut.channelList = range(self.systemHeaderObj.nChannels)
1384
1390
1385 self.dataOut.flagTimeBlock = self.flagTimeBlock
1391 self.dataOut.flagTimeBlock = self.flagTimeBlock
1386
1392
1387 self.dataOut.ippSeconds = self.ippSeconds
1393 self.dataOut.ippSeconds = self.ippSeconds
1388
1394
1389 self.dataOut.timeInterval = self.ippSeconds * self.processingHeaderObj.nCohInt
1395 self.dataOut.timeInterval = self.ippSeconds * self.processingHeaderObj.nCohInt
1390
1396
1391 self.dataOut.nCohInt = self.processingHeaderObj.nCohInt
1397 self.dataOut.nCohInt = self.processingHeaderObj.nCohInt
1392
1398
1393 self.dataOut.flagShiftFFT = False
1399 self.dataOut.flagShiftFFT = False
1394
1400
1395 if self.processingHeaderObj.code != None:
1401 if self.processingHeaderObj.code != None:
1396 self.dataOut.nCode = self.processingHeaderObj.nCode
1402 self.dataOut.nCode = self.processingHeaderObj.nCode
1397
1403
1398 self.dataOut.nBaud = self.processingHeaderObj.nBaud
1404 self.dataOut.nBaud = self.processingHeaderObj.nBaud
1399
1405
1400 self.dataOut.code = self.processingHeaderObj.code
1406 self.dataOut.code = self.processingHeaderObj.code
1401
1407
1402 self.dataOut.systemHeaderObj = self.systemHeaderObj.copy()
1408 self.dataOut.systemHeaderObj = self.systemHeaderObj.copy()
1403
1409
1404 self.dataOut.radarControllerHeaderObj = self.radarControllerHeaderObj.copy()
1410 self.dataOut.radarControllerHeaderObj = self.radarControllerHeaderObj.copy()
1405
1411
1406 # self.updateDataHeader()
1412 # self.updateDataHeader()
1407
1413
1408 #data es un numpy array de 3 dmensiones (perfiles, alturas y canales)
1414 #data es un numpy array de 3 dmensiones (perfiles, alturas y canales)
1409
1415
1410 if self.datablock == None:
1416 if self.datablock == None:
1411 self.dataOut.flagNoData = True
1417 self.dataOut.flagNoData = True
1412 return 0
1418 return 0
1413
1419
1414 self.dataOut.data = self.datablock[:,self.profileIndex,:]
1420 self.dataOut.data = self.datablock[:,self.profileIndex,:]
1415
1421
1416 self.dataOut.utctime = self.basicHeaderObj.utc + self.basicHeaderObj.miliSecond/1000. + self.profileIndex * self.ippSeconds
1422 self.dataOut.utctime = self.basicHeaderObj.utc + self.basicHeaderObj.miliSecond/1000. + self.profileIndex * self.ippSeconds
1417
1423
1418 self.profileIndex += 1
1424 self.profileIndex += 1
1419
1425
1420 self.dataOut.flagNoData = False
1426 self.dataOut.flagNoData = False
1421
1427
1422 # print self.profileIndex, self.dataOut.utctime
1428 # print self.profileIndex, self.dataOut.utctime
1423 # if self.profileIndex == 800:
1429 # if self.profileIndex == 800:
1424 # a=1
1430 # a=1
1425
1431
1426
1432
1427 return self.dataOut.data
1433 return self.dataOut.data
1428
1434
1429
1435
1430 class VoltageWriter(JRODataWriter):
1436 class VoltageWriter(JRODataWriter):
1431 """
1437 """
1432 Esta clase permite escribir datos de voltajes a archivos procesados (.r). La escritura
1438 Esta clase permite escribir datos de voltajes a archivos procesados (.r). La escritura
1433 de los datos siempre se realiza por bloques.
1439 de los datos siempre se realiza por bloques.
1434 """
1440 """
1435
1441
1436 ext = ".r"
1442 ext = ".r"
1437
1443
1438 optchar = "D"
1444 optchar = "D"
1439
1445
1440 shapeBuffer = None
1446 shapeBuffer = None
1441
1447
1442
1448
1443 def __init__(self):
1449 def __init__(self):
1444 """
1450 """
1445 Inicializador de la clase VoltageWriter para la escritura de datos de espectros.
1451 Inicializador de la clase VoltageWriter para la escritura de datos de espectros.
1446
1452
1447 Affected:
1453 Affected:
1448 self.dataOut
1454 self.dataOut
1449
1455
1450 Return: None
1456 Return: None
1451 """
1457 """
1452
1458
1453 self.nTotalBlocks = 0
1459 self.nTotalBlocks = 0
1454
1460
1455 self.profileIndex = 0
1461 self.profileIndex = 0
1456
1462
1457 self.isConfig = False
1463 self.isConfig = False
1458
1464
1459 self.fp = None
1465 self.fp = None
1460
1466
1461 self.flagIsNewFile = 1
1467 self.flagIsNewFile = 1
1462
1468
1463 self.nTotalBlocks = 0
1469 self.nTotalBlocks = 0
1464
1470
1465 self.flagIsNewBlock = 0
1471 self.flagIsNewBlock = 0
1466
1472
1467 self.setFile = None
1473 self.setFile = None
1468
1474
1469 self.dtype = None
1475 self.dtype = None
1470
1476
1471 self.path = None
1477 self.path = None
1472
1478
1473 self.filename = None
1479 self.filename = None
1474
1480
1475 self.basicHeaderObj = BasicHeader()
1481 self.basicHeaderObj = BasicHeader()
1476
1482
1477 self.systemHeaderObj = SystemHeader()
1483 self.systemHeaderObj = SystemHeader()
1478
1484
1479 self.radarControllerHeaderObj = RadarControllerHeader()
1485 self.radarControllerHeaderObj = RadarControllerHeader()
1480
1486
1481 self.processingHeaderObj = ProcessingHeader()
1487 self.processingHeaderObj = ProcessingHeader()
1482
1488
1483 def hasAllDataInBuffer(self):
1489 def hasAllDataInBuffer(self):
1484 if self.profileIndex >= self.processingHeaderObj.profilesPerBlock:
1490 if self.profileIndex >= self.processingHeaderObj.profilesPerBlock:
1485 return 1
1491 return 1
1486 return 0
1492 return 0
1487
1493
1488
1494
1489 def setBlockDimension(self):
1495 def setBlockDimension(self):
1490 """
1496 """
1491 Obtiene las formas dimensionales del los subbloques de datos que componen un bloque
1497 Obtiene las formas dimensionales del los subbloques de datos que componen un bloque
1492
1498
1493 Affected:
1499 Affected:
1494 self.shape_spc_Buffer
1500 self.shape_spc_Buffer
1495 self.shape_cspc_Buffer
1501 self.shape_cspc_Buffer
1496 self.shape_dc_Buffer
1502 self.shape_dc_Buffer
1497
1503
1498 Return: None
1504 Return: None
1499 """
1505 """
1500 self.shapeBuffer = (self.processingHeaderObj.profilesPerBlock,
1506 self.shapeBuffer = (self.processingHeaderObj.profilesPerBlock,
1501 self.processingHeaderObj.nHeights,
1507 self.processingHeaderObj.nHeights,
1502 self.systemHeaderObj.nChannels)
1508 self.systemHeaderObj.nChannels)
1503
1509
1504 self.datablock = numpy.zeros((self.systemHeaderObj.nChannels,
1510 self.datablock = numpy.zeros((self.systemHeaderObj.nChannels,
1505 self.processingHeaderObj.profilesPerBlock,
1511 self.processingHeaderObj.profilesPerBlock,
1506 self.processingHeaderObj.nHeights),
1512 self.processingHeaderObj.nHeights),
1507 dtype=numpy.dtype('complex'))
1513 dtype=numpy.dtype('complex'))
1508
1514
1509
1515
1510 def writeBlock(self):
1516 def writeBlock(self):
1511 """
1517 """
1512 Escribe el buffer en el file designado
1518 Escribe el buffer en el file designado
1513
1519
1514 Affected:
1520 Affected:
1515 self.profileIndex
1521 self.profileIndex
1516 self.flagIsNewFile
1522 self.flagIsNewFile
1517 self.flagIsNewBlock
1523 self.flagIsNewBlock
1518 self.nTotalBlocks
1524 self.nTotalBlocks
1519 self.blockIndex
1525 self.blockIndex
1520
1526
1521 Return: None
1527 Return: None
1522 """
1528 """
1523 data = numpy.zeros( self.shapeBuffer, self.dtype )
1529 data = numpy.zeros( self.shapeBuffer, self.dtype )
1524
1530
1525 junk = numpy.transpose(self.datablock, (1,2,0))
1531 junk = numpy.transpose(self.datablock, (1,2,0))
1526
1532
1527 data['real'] = junk.real
1533 data['real'] = junk.real
1528 data['imag'] = junk.imag
1534 data['imag'] = junk.imag
1529
1535
1530 data = data.reshape( (-1) )
1536 data = data.reshape( (-1) )
1531
1537
1532 data.tofile( self.fp )
1538 data.tofile( self.fp )
1533
1539
1534 self.datablock.fill(0)
1540 self.datablock.fill(0)
1535
1541
1536 self.profileIndex = 0
1542 self.profileIndex = 0
1537 self.flagIsNewFile = 0
1543 self.flagIsNewFile = 0
1538 self.flagIsNewBlock = 1
1544 self.flagIsNewBlock = 1
1539
1545
1540 self.blockIndex += 1
1546 self.blockIndex += 1
1541 self.nTotalBlocks += 1
1547 self.nTotalBlocks += 1
1542
1548
1543 def putData(self):
1549 def putData(self):
1544 """
1550 """
1545 Setea un bloque de datos y luego los escribe en un file
1551 Setea un bloque de datos y luego los escribe en un file
1546
1552
1547 Affected:
1553 Affected:
1548 self.flagIsNewBlock
1554 self.flagIsNewBlock
1549 self.profileIndex
1555 self.profileIndex
1550
1556
1551 Return:
1557 Return:
1552 0 : Si no hay data o no hay mas files que puedan escribirse
1558 0 : Si no hay data o no hay mas files que puedan escribirse
1553 1 : Si se escribio la data de un bloque en un file
1559 1 : Si se escribio la data de un bloque en un file
1554 """
1560 """
1555 if self.dataOut.flagNoData:
1561 if self.dataOut.flagNoData:
1556 return 0
1562 return 0
1557
1563
1558 self.flagIsNewBlock = 0
1564 self.flagIsNewBlock = 0
1559
1565
1560 if self.dataOut.flagTimeBlock:
1566 if self.dataOut.flagTimeBlock:
1561
1567
1562 self.datablock.fill(0)
1568 self.datablock.fill(0)
1563 self.profileIndex = 0
1569 self.profileIndex = 0
1564 self.setNextFile()
1570 self.setNextFile()
1565
1571
1566 if self.profileIndex == 0:
1572 if self.profileIndex == 0:
1567 self.getBasicHeader()
1573 self.getBasicHeader()
1568
1574
1569 self.datablock[:,self.profileIndex,:] = self.dataOut.data
1575 self.datablock[:,self.profileIndex,:] = self.dataOut.data
1570
1576
1571 self.profileIndex += 1
1577 self.profileIndex += 1
1572
1578
1573 if self.hasAllDataInBuffer():
1579 if self.hasAllDataInBuffer():
1574 #if self.flagIsNewFile:
1580 #if self.flagIsNewFile:
1575 self.writeNextBlock()
1581 self.writeNextBlock()
1576 # self.getDataHeader()
1582 # self.getDataHeader()
1577
1583
1578 return 1
1584 return 1
1579
1585
1580 def __getProcessFlags(self):
1586 def __getProcessFlags(self):
1581
1587
1582 processFlags = 0
1588 processFlags = 0
1583
1589
1584 dtype0 = numpy.dtype([('real','<i1'),('imag','<i1')])
1590 dtype0 = numpy.dtype([('real','<i1'),('imag','<i1')])
1585 dtype1 = numpy.dtype([('real','<i2'),('imag','<i2')])
1591 dtype1 = numpy.dtype([('real','<i2'),('imag','<i2')])
1586 dtype2 = numpy.dtype([('real','<i4'),('imag','<i4')])
1592 dtype2 = numpy.dtype([('real','<i4'),('imag','<i4')])
1587 dtype3 = numpy.dtype([('real','<i8'),('imag','<i8')])
1593 dtype3 = numpy.dtype([('real','<i8'),('imag','<i8')])
1588 dtype4 = numpy.dtype([('real','<f4'),('imag','<f4')])
1594 dtype4 = numpy.dtype([('real','<f4'),('imag','<f4')])
1589 dtype5 = numpy.dtype([('real','<f8'),('imag','<f8')])
1595 dtype5 = numpy.dtype([('real','<f8'),('imag','<f8')])
1590
1596
1591 dtypeList = [dtype0, dtype1, dtype2, dtype3, dtype4, dtype5]
1597 dtypeList = [dtype0, dtype1, dtype2, dtype3, dtype4, dtype5]
1592
1598
1593
1599
1594
1600
1595 datatypeValueList = [PROCFLAG.DATATYPE_CHAR,
1601 datatypeValueList = [PROCFLAG.DATATYPE_CHAR,
1596 PROCFLAG.DATATYPE_SHORT,
1602 PROCFLAG.DATATYPE_SHORT,
1597 PROCFLAG.DATATYPE_LONG,
1603 PROCFLAG.DATATYPE_LONG,
1598 PROCFLAG.DATATYPE_INT64,
1604 PROCFLAG.DATATYPE_INT64,
1599 PROCFLAG.DATATYPE_FLOAT,
1605 PROCFLAG.DATATYPE_FLOAT,
1600 PROCFLAG.DATATYPE_DOUBLE]
1606 PROCFLAG.DATATYPE_DOUBLE]
1601
1607
1602
1608
1603 for index in range(len(dtypeList)):
1609 for index in range(len(dtypeList)):
1604 if self.dataOut.dtype == dtypeList[index]:
1610 if self.dataOut.dtype == dtypeList[index]:
1605 dtypeValue = datatypeValueList[index]
1611 dtypeValue = datatypeValueList[index]
1606 break
1612 break
1607
1613
1608 processFlags += dtypeValue
1614 processFlags += dtypeValue
1609
1615
1610 if self.dataOut.flagDecodeData:
1616 if self.dataOut.flagDecodeData:
1611 processFlags += PROCFLAG.DECODE_DATA
1617 processFlags += PROCFLAG.DECODE_DATA
1612
1618
1613 if self.dataOut.flagDeflipData:
1619 if self.dataOut.flagDeflipData:
1614 processFlags += PROCFLAG.DEFLIP_DATA
1620 processFlags += PROCFLAG.DEFLIP_DATA
1615
1621
1616 if self.dataOut.code != None:
1622 if self.dataOut.code != None:
1617 processFlags += PROCFLAG.DEFINE_PROCESS_CODE
1623 processFlags += PROCFLAG.DEFINE_PROCESS_CODE
1618
1624
1619 if self.dataOut.nCohInt > 1:
1625 if self.dataOut.nCohInt > 1:
1620 processFlags += PROCFLAG.COHERENT_INTEGRATION
1626 processFlags += PROCFLAG.COHERENT_INTEGRATION
1621
1627
1622 return processFlags
1628 return processFlags
1623
1629
1624
1630
1625 def __getBlockSize(self):
1631 def __getBlockSize(self):
1626 '''
1632 '''
1627 Este metodos determina el cantidad de bytes para un bloque de datos de tipo Voltage
1633 Este metodos determina el cantidad de bytes para un bloque de datos de tipo Voltage
1628 '''
1634 '''
1629
1635
1630 dtype0 = numpy.dtype([('real','<i1'),('imag','<i1')])
1636 dtype0 = numpy.dtype([('real','<i1'),('imag','<i1')])
1631 dtype1 = numpy.dtype([('real','<i2'),('imag','<i2')])
1637 dtype1 = numpy.dtype([('real','<i2'),('imag','<i2')])
1632 dtype2 = numpy.dtype([('real','<i4'),('imag','<i4')])
1638 dtype2 = numpy.dtype([('real','<i4'),('imag','<i4')])
1633 dtype3 = numpy.dtype([('real','<i8'),('imag','<i8')])
1639 dtype3 = numpy.dtype([('real','<i8'),('imag','<i8')])
1634 dtype4 = numpy.dtype([('real','<f4'),('imag','<f4')])
1640 dtype4 = numpy.dtype([('real','<f4'),('imag','<f4')])
1635 dtype5 = numpy.dtype([('real','<f8'),('imag','<f8')])
1641 dtype5 = numpy.dtype([('real','<f8'),('imag','<f8')])
1636
1642
1637 dtypeList = [dtype0, dtype1, dtype2, dtype3, dtype4, dtype5]
1643 dtypeList = [dtype0, dtype1, dtype2, dtype3, dtype4, dtype5]
1638 datatypeValueList = [1,2,4,8,4,8]
1644 datatypeValueList = [1,2,4,8,4,8]
1639 for index in range(len(dtypeList)):
1645 for index in range(len(dtypeList)):
1640 if self.dataOut.dtype == dtypeList[index]:
1646 if self.dataOut.dtype == dtypeList[index]:
1641 datatypeValue = datatypeValueList[index]
1647 datatypeValue = datatypeValueList[index]
1642 break
1648 break
1643
1649
1644 blocksize = int(self.dataOut.nHeights * self.dataOut.nChannels * self.dataOut.nProfiles * datatypeValue * 2)
1650 blocksize = int(self.dataOut.nHeights * self.dataOut.nChannels * self.dataOut.nProfiles * datatypeValue * 2)
1645
1651
1646 return blocksize
1652 return blocksize
1647
1653
1648 def getDataHeader(self):
1654 def getDataHeader(self):
1649
1655
1650 """
1656 """
1651 Obtiene una copia del First Header
1657 Obtiene una copia del First Header
1652
1658
1653 Affected:
1659 Affected:
1654 self.systemHeaderObj
1660 self.systemHeaderObj
1655 self.radarControllerHeaderObj
1661 self.radarControllerHeaderObj
1656 self.dtype
1662 self.dtype
1657
1663
1658 Return:
1664 Return:
1659 None
1665 None
1660 """
1666 """
1661
1667
1662 self.systemHeaderObj = self.dataOut.systemHeaderObj.copy()
1668 self.systemHeaderObj = self.dataOut.systemHeaderObj.copy()
1663 self.systemHeaderObj.nChannels = self.dataOut.nChannels
1669 self.systemHeaderObj.nChannels = self.dataOut.nChannels
1664 self.radarControllerHeaderObj = self.dataOut.radarControllerHeaderObj.copy()
1670 self.radarControllerHeaderObj = self.dataOut.radarControllerHeaderObj.copy()
1665
1671
1666 self.getBasicHeader()
1672 self.getBasicHeader()
1667
1673
1668 processingHeaderSize = 40 # bytes
1674 processingHeaderSize = 40 # bytes
1669 self.processingHeaderObj.dtype = 0 # Voltage
1675 self.processingHeaderObj.dtype = 0 # Voltage
1670 self.processingHeaderObj.blockSize = self.__getBlockSize()
1676 self.processingHeaderObj.blockSize = self.__getBlockSize()
1671 self.processingHeaderObj.profilesPerBlock = self.profilesPerBlock
1677 self.processingHeaderObj.profilesPerBlock = self.profilesPerBlock
1672 self.processingHeaderObj.dataBlocksPerFile = self.blocksPerFile
1678 self.processingHeaderObj.dataBlocksPerFile = self.blocksPerFile
1673 self.processingHeaderObj.nWindows = 1 #podria ser 1 o self.dataOut.processingHeaderObj.nWindows
1679 self.processingHeaderObj.nWindows = 1 #podria ser 1 o self.dataOut.processingHeaderObj.nWindows
1674 self.processingHeaderObj.processFlags = self.__getProcessFlags()
1680 self.processingHeaderObj.processFlags = self.__getProcessFlags()
1675 self.processingHeaderObj.nCohInt = self.dataOut.nCohInt
1681 self.processingHeaderObj.nCohInt = self.dataOut.nCohInt
1676 self.processingHeaderObj.nIncohInt = 1 # Cuando la data de origen es de tipo Voltage
1682 self.processingHeaderObj.nIncohInt = 1 # Cuando la data de origen es de tipo Voltage
1677 self.processingHeaderObj.totalSpectra = 0 # Cuando la data de origen es de tipo Voltage
1683 self.processingHeaderObj.totalSpectra = 0 # Cuando la data de origen es de tipo Voltage
1678
1684
1679 if self.dataOut.code != None:
1685 if self.dataOut.code != None:
1680 self.processingHeaderObj.code = self.dataOut.code
1686 self.processingHeaderObj.code = self.dataOut.code
1681 self.processingHeaderObj.nCode = self.dataOut.nCode
1687 self.processingHeaderObj.nCode = self.dataOut.nCode
1682 self.processingHeaderObj.nBaud = self.dataOut.nBaud
1688 self.processingHeaderObj.nBaud = self.dataOut.nBaud
1683 codesize = int(8 + 4 * self.dataOut.nCode * self.dataOut.nBaud)
1689 codesize = int(8 + 4 * self.dataOut.nCode * self.dataOut.nBaud)
1684 processingHeaderSize += codesize
1690 processingHeaderSize += codesize
1685
1691
1686 if self.processingHeaderObj.nWindows != 0:
1692 if self.processingHeaderObj.nWindows != 0:
1687 self.processingHeaderObj.firstHeight = self.dataOut.heightList[0]
1693 self.processingHeaderObj.firstHeight = self.dataOut.heightList[0]
1688 self.processingHeaderObj.deltaHeight = self.dataOut.heightList[1] - self.dataOut.heightList[0]
1694 self.processingHeaderObj.deltaHeight = self.dataOut.heightList[1] - self.dataOut.heightList[0]
1689 self.processingHeaderObj.nHeights = self.dataOut.nHeights
1695 self.processingHeaderObj.nHeights = self.dataOut.nHeights
1690 self.processingHeaderObj.samplesWin = self.dataOut.nHeights
1696 self.processingHeaderObj.samplesWin = self.dataOut.nHeights
1691 processingHeaderSize += 12
1697 processingHeaderSize += 12
1692
1698
1693 self.processingHeaderObj.size = processingHeaderSize
1699 self.processingHeaderObj.size = processingHeaderSize
1694
1700
1695 class SpectraReader(JRODataReader):
1701 class SpectraReader(JRODataReader):
1696 """
1702 """
1697 Esta clase permite leer datos de espectros desde archivos procesados (.pdata). La lectura
1703 Esta clase permite leer datos de espectros desde archivos procesados (.pdata). La lectura
1698 de los datos siempre se realiza por bloques. Los datos leidos (array de 3 dimensiones)
1704 de los datos siempre se realiza por bloques. Los datos leidos (array de 3 dimensiones)
1699 son almacenados en tres buffer's para el Self Spectra, el Cross Spectra y el DC Channel.
1705 son almacenados en tres buffer's para el Self Spectra, el Cross Spectra y el DC Channel.
1700
1706
1701 paresCanalesIguales * alturas * perfiles (Self Spectra)
1707 paresCanalesIguales * alturas * perfiles (Self Spectra)
1702 paresCanalesDiferentes * alturas * perfiles (Cross Spectra)
1708 paresCanalesDiferentes * alturas * perfiles (Cross Spectra)
1703 canales * alturas (DC Channels)
1709 canales * alturas (DC Channels)
1704
1710
1705 Esta clase contiene instancias (objetos) de las clases BasicHeader, SystemHeader,
1711 Esta clase contiene instancias (objetos) de las clases BasicHeader, SystemHeader,
1706 RadarControllerHeader y Spectra. Los tres primeros se usan para almacenar informacion de la
1712 RadarControllerHeader y Spectra. Los tres primeros se usan para almacenar informacion de la
1707 cabecera de datos (metadata), y el cuarto (Spectra) para obtener y almacenar un bloque de
1713 cabecera de datos (metadata), y el cuarto (Spectra) para obtener y almacenar un bloque de
1708 datos desde el "buffer" cada vez que se ejecute el metodo "getData".
1714 datos desde el "buffer" cada vez que se ejecute el metodo "getData".
1709
1715
1710 Example:
1716 Example:
1711 dpath = "/home/myuser/data"
1717 dpath = "/home/myuser/data"
1712
1718
1713 startTime = datetime.datetime(2010,1,20,0,0,0,0,0,0)
1719 startTime = datetime.datetime(2010,1,20,0,0,0,0,0,0)
1714
1720
1715 endTime = datetime.datetime(2010,1,21,23,59,59,0,0,0)
1721 endTime = datetime.datetime(2010,1,21,23,59,59,0,0,0)
1716
1722
1717 readerObj = SpectraReader()
1723 readerObj = SpectraReader()
1718
1724
1719 readerObj.setup(dpath, startTime, endTime)
1725 readerObj.setup(dpath, startTime, endTime)
1720
1726
1721 while(True):
1727 while(True):
1722
1728
1723 readerObj.getData()
1729 readerObj.getData()
1724
1730
1725 print readerObj.data_spc
1731 print readerObj.data_spc
1726
1732
1727 print readerObj.data_cspc
1733 print readerObj.data_cspc
1728
1734
1729 print readerObj.data_dc
1735 print readerObj.data_dc
1730
1736
1731 if readerObj.flagNoMoreFiles:
1737 if readerObj.flagNoMoreFiles:
1732 break
1738 break
1733
1739
1734 """
1740 """
1735
1741
1736 pts2read_SelfSpectra = 0
1742 pts2read_SelfSpectra = 0
1737
1743
1738 pts2read_CrossSpectra = 0
1744 pts2read_CrossSpectra = 0
1739
1745
1740 pts2read_DCchannels = 0
1746 pts2read_DCchannels = 0
1741
1747
1742 ext = ".pdata"
1748 ext = ".pdata"
1743
1749
1744 optchar = "P"
1750 optchar = "P"
1745
1751
1746 dataOut = None
1752 dataOut = None
1747
1753
1748 nRdChannels = None
1754 nRdChannels = None
1749
1755
1750 nRdPairs = None
1756 nRdPairs = None
1751
1757
1752 rdPairList = []
1758 rdPairList = []
1753
1759
1754
1760
1755 def __init__(self):
1761 def __init__(self):
1756 """
1762 """
1757 Inicializador de la clase SpectraReader para la lectura de datos de espectros.
1763 Inicializador de la clase SpectraReader para la lectura de datos de espectros.
1758
1764
1759 Inputs:
1765 Inputs:
1760 dataOut : Objeto de la clase Spectra. Este objeto sera utilizado para
1766 dataOut : Objeto de la clase Spectra. Este objeto sera utilizado para
1761 almacenar un perfil de datos cada vez que se haga un requerimiento
1767 almacenar un perfil de datos cada vez que se haga un requerimiento
1762 (getData). El perfil sera obtenido a partir del buffer de datos,
1768 (getData). El perfil sera obtenido a partir del buffer de datos,
1763 si el buffer esta vacio se hara un nuevo proceso de lectura de un
1769 si el buffer esta vacio se hara un nuevo proceso de lectura de un
1764 bloque de datos.
1770 bloque de datos.
1765 Si este parametro no es pasado se creara uno internamente.
1771 Si este parametro no es pasado se creara uno internamente.
1766
1772
1767 Affected:
1773 Affected:
1768 self.dataOut
1774 self.dataOut
1769
1775
1770 Return : None
1776 Return : None
1771 """
1777 """
1772
1778
1773 self.isConfig = False
1779 self.isConfig = False
1774
1780
1775 self.pts2read_SelfSpectra = 0
1781 self.pts2read_SelfSpectra = 0
1776
1782
1777 self.pts2read_CrossSpectra = 0
1783 self.pts2read_CrossSpectra = 0
1778
1784
1779 self.pts2read_DCchannels = 0
1785 self.pts2read_DCchannels = 0
1780
1786
1781 self.datablock = None
1787 self.datablock = None
1782
1788
1783 self.utc = None
1789 self.utc = None
1784
1790
1785 self.ext = ".pdata"
1791 self.ext = ".pdata"
1786
1792
1787 self.optchar = "P"
1793 self.optchar = "P"
1788
1794
1789 self.basicHeaderObj = BasicHeader()
1795 self.basicHeaderObj = BasicHeader()
1790
1796
1791 self.systemHeaderObj = SystemHeader()
1797 self.systemHeaderObj = SystemHeader()
1792
1798
1793 self.radarControllerHeaderObj = RadarControllerHeader()
1799 self.radarControllerHeaderObj = RadarControllerHeader()
1794
1800
1795 self.processingHeaderObj = ProcessingHeader()
1801 self.processingHeaderObj = ProcessingHeader()
1796
1802
1797 self.online = 0
1803 self.online = 0
1798
1804
1799 self.fp = None
1805 self.fp = None
1800
1806
1801 self.idFile = None
1807 self.idFile = None
1802
1808
1803 self.dtype = None
1809 self.dtype = None
1804
1810
1805 self.fileSizeByHeader = None
1811 self.fileSizeByHeader = None
1806
1812
1807 self.filenameList = []
1813 self.filenameList = []
1808
1814
1809 self.filename = None
1815 self.filename = None
1810
1816
1811 self.fileSize = None
1817 self.fileSize = None
1812
1818
1813 self.firstHeaderSize = 0
1819 self.firstHeaderSize = 0
1814
1820
1815 self.basicHeaderSize = 24
1821 self.basicHeaderSize = 24
1816
1822
1817 self.pathList = []
1823 self.pathList = []
1818
1824
1819 self.lastUTTime = 0
1825 self.lastUTTime = 0
1820
1826
1821 self.maxTimeStep = 30
1827 self.maxTimeStep = 30
1822
1828
1823 self.flagNoMoreFiles = 0
1829 self.flagNoMoreFiles = 0
1824
1830
1825 self.set = 0
1831 self.set = 0
1826
1832
1827 self.path = None
1833 self.path = None
1828
1834
1829 self.delay = 3 #seconds
1835 self.delay = 3 #seconds
1830
1836
1831 self.nTries = 3 #quantity tries
1837 self.nTries = 3 #quantity tries
1832
1838
1833 self.nFiles = 3 #number of files for searching
1839 self.nFiles = 3 #number of files for searching
1834
1840
1835 self.nReadBlocks = 0
1841 self.nReadBlocks = 0
1836
1842
1837 self.flagIsNewFile = 1
1843 self.flagIsNewFile = 1
1838
1844
1839 self.ippSeconds = 0
1845 self.ippSeconds = 0
1840
1846
1841 self.flagTimeBlock = 0
1847 self.flagTimeBlock = 0
1842
1848
1843 self.flagIsNewBlock = 0
1849 self.flagIsNewBlock = 0
1844
1850
1845 self.nTotalBlocks = 0
1851 self.nTotalBlocks = 0
1846
1852
1847 self.blocksize = 0
1853 self.blocksize = 0
1848
1854
1849 self.dataOut = self.createObjByDefault()
1855 self.dataOut = self.createObjByDefault()
1850
1856
1851
1857
1852 def createObjByDefault(self):
1858 def createObjByDefault(self):
1853
1859
1854 dataObj = Spectra()
1860 dataObj = Spectra()
1855
1861
1856 return dataObj
1862 return dataObj
1857
1863
1858 def __hasNotDataInBuffer(self):
1864 def __hasNotDataInBuffer(self):
1859 return 1
1865 return 1
1860
1866
1861
1867
1862 def getBlockDimension(self):
1868 def getBlockDimension(self):
1863 """
1869 """
1864 Obtiene la cantidad de puntos a leer por cada bloque de datos
1870 Obtiene la cantidad de puntos a leer por cada bloque de datos
1865
1871
1866 Affected:
1872 Affected:
1867 self.nRdChannels
1873 self.nRdChannels
1868 self.nRdPairs
1874 self.nRdPairs
1869 self.pts2read_SelfSpectra
1875 self.pts2read_SelfSpectra
1870 self.pts2read_CrossSpectra
1876 self.pts2read_CrossSpectra
1871 self.pts2read_DCchannels
1877 self.pts2read_DCchannels
1872 self.blocksize
1878 self.blocksize
1873 self.dataOut.nChannels
1879 self.dataOut.nChannels
1874 self.dataOut.nPairs
1880 self.dataOut.nPairs
1875
1881
1876 Return:
1882 Return:
1877 None
1883 None
1878 """
1884 """
1879 self.nRdChannels = 0
1885 self.nRdChannels = 0
1880 self.nRdPairs = 0
1886 self.nRdPairs = 0
1881 self.rdPairList = []
1887 self.rdPairList = []
1882
1888
1883 for i in range(0, self.processingHeaderObj.totalSpectra*2, 2):
1889 for i in range(0, self.processingHeaderObj.totalSpectra*2, 2):
1884 if self.processingHeaderObj.spectraComb[i] == self.processingHeaderObj.spectraComb[i+1]:
1890 if self.processingHeaderObj.spectraComb[i] == self.processingHeaderObj.spectraComb[i+1]:
1885 self.nRdChannels = self.nRdChannels + 1 #par de canales iguales
1891 self.nRdChannels = self.nRdChannels + 1 #par de canales iguales
1886 else:
1892 else:
1887 self.nRdPairs = self.nRdPairs + 1 #par de canales diferentes
1893 self.nRdPairs = self.nRdPairs + 1 #par de canales diferentes
1888 self.rdPairList.append((self.processingHeaderObj.spectraComb[i], self.processingHeaderObj.spectraComb[i+1]))
1894 self.rdPairList.append((self.processingHeaderObj.spectraComb[i], self.processingHeaderObj.spectraComb[i+1]))
1889
1895
1890 pts2read = self.processingHeaderObj.nHeights * self.processingHeaderObj.profilesPerBlock
1896 pts2read = self.processingHeaderObj.nHeights * self.processingHeaderObj.profilesPerBlock
1891
1897
1892 self.pts2read_SelfSpectra = int(self.nRdChannels * pts2read)
1898 self.pts2read_SelfSpectra = int(self.nRdChannels * pts2read)
1893 self.blocksize = self.pts2read_SelfSpectra
1899 self.blocksize = self.pts2read_SelfSpectra
1894
1900
1895 if self.processingHeaderObj.flag_cspc:
1901 if self.processingHeaderObj.flag_cspc:
1896 self.pts2read_CrossSpectra = int(self.nRdPairs * pts2read)
1902 self.pts2read_CrossSpectra = int(self.nRdPairs * pts2read)
1897 self.blocksize += self.pts2read_CrossSpectra
1903 self.blocksize += self.pts2read_CrossSpectra
1898
1904
1899 if self.processingHeaderObj.flag_dc:
1905 if self.processingHeaderObj.flag_dc:
1900 self.pts2read_DCchannels = int(self.systemHeaderObj.nChannels * self.processingHeaderObj.nHeights)
1906 self.pts2read_DCchannels = int(self.systemHeaderObj.nChannels * self.processingHeaderObj.nHeights)
1901 self.blocksize += self.pts2read_DCchannels
1907 self.blocksize += self.pts2read_DCchannels
1902
1908
1903 # self.blocksize = self.pts2read_SelfSpectra + self.pts2read_CrossSpectra + self.pts2read_DCchannels
1909 # self.blocksize = self.pts2read_SelfSpectra + self.pts2read_CrossSpectra + self.pts2read_DCchannels
1904
1910
1905
1911
1906 def readBlock(self):
1912 def readBlock(self):
1907 """
1913 """
1908 Lee el bloque de datos desde la posicion actual del puntero del archivo
1914 Lee el bloque de datos desde la posicion actual del puntero del archivo
1909 (self.fp) y actualiza todos los parametros relacionados al bloque de datos
1915 (self.fp) y actualiza todos los parametros relacionados al bloque de datos
1910 (metadata + data). La data leida es almacenada en el buffer y el contador del buffer
1916 (metadata + data). La data leida es almacenada en el buffer y el contador del buffer
1911 es seteado a 0
1917 es seteado a 0
1912
1918
1913 Return: None
1919 Return: None
1914
1920
1915 Variables afectadas:
1921 Variables afectadas:
1916
1922
1917 self.flagIsNewFile
1923 self.flagIsNewFile
1918 self.flagIsNewBlock
1924 self.flagIsNewBlock
1919 self.nTotalBlocks
1925 self.nTotalBlocks
1920 self.data_spc
1926 self.data_spc
1921 self.data_cspc
1927 self.data_cspc
1922 self.data_dc
1928 self.data_dc
1923
1929
1924 Exceptions:
1930 Exceptions:
1925 Si un bloque leido no es un bloque valido
1931 Si un bloque leido no es un bloque valido
1926 """
1932 """
1927 blockOk_flag = False
1933 blockOk_flag = False
1928 fpointer = self.fp.tell()
1934 fpointer = self.fp.tell()
1929
1935
1930 spc = numpy.fromfile( self.fp, self.dtype[0], self.pts2read_SelfSpectra )
1936 spc = numpy.fromfile( self.fp, self.dtype[0], self.pts2read_SelfSpectra )
1931 spc = spc.reshape( (self.nRdChannels, self.processingHeaderObj.nHeights, self.processingHeaderObj.profilesPerBlock) ) #transforma a un arreglo 3D
1937 spc = spc.reshape( (self.nRdChannels, self.processingHeaderObj.nHeights, self.processingHeaderObj.profilesPerBlock) ) #transforma a un arreglo 3D
1932
1938
1933 if self.processingHeaderObj.flag_cspc:
1939 if self.processingHeaderObj.flag_cspc:
1934 cspc = numpy.fromfile( self.fp, self.dtype, self.pts2read_CrossSpectra )
1940 cspc = numpy.fromfile( self.fp, self.dtype, self.pts2read_CrossSpectra )
1935 cspc = cspc.reshape( (self.nRdPairs, self.processingHeaderObj.nHeights, self.processingHeaderObj.profilesPerBlock) ) #transforma a un arreglo 3D
1941 cspc = cspc.reshape( (self.nRdPairs, self.processingHeaderObj.nHeights, self.processingHeaderObj.profilesPerBlock) ) #transforma a un arreglo 3D
1936
1942
1937 if self.processingHeaderObj.flag_dc:
1943 if self.processingHeaderObj.flag_dc:
1938 dc = numpy.fromfile( self.fp, self.dtype, self.pts2read_DCchannels ) #int(self.processingHeaderObj.nHeights*self.systemHeaderObj.nChannels) )
1944 dc = numpy.fromfile( self.fp, self.dtype, self.pts2read_DCchannels ) #int(self.processingHeaderObj.nHeights*self.systemHeaderObj.nChannels) )
1939 dc = dc.reshape( (self.systemHeaderObj.nChannels, self.processingHeaderObj.nHeights) ) #transforma a un arreglo 2D
1945 dc = dc.reshape( (self.systemHeaderObj.nChannels, self.processingHeaderObj.nHeights) ) #transforma a un arreglo 2D
1940
1946
1941
1947
1942 if not(self.processingHeaderObj.shif_fft):
1948 if not(self.processingHeaderObj.shif_fft):
1943 #desplaza a la derecha en el eje 2 determinadas posiciones
1949 #desplaza a la derecha en el eje 2 determinadas posiciones
1944 shift = int(self.processingHeaderObj.profilesPerBlock/2)
1950 shift = int(self.processingHeaderObj.profilesPerBlock/2)
1945 spc = numpy.roll( spc, shift , axis=2 )
1951 spc = numpy.roll( spc, shift , axis=2 )
1946
1952
1947 if self.processingHeaderObj.flag_cspc:
1953 if self.processingHeaderObj.flag_cspc:
1948 #desplaza a la derecha en el eje 2 determinadas posiciones
1954 #desplaza a la derecha en el eje 2 determinadas posiciones
1949 cspc = numpy.roll( cspc, shift, axis=2 )
1955 cspc = numpy.roll( cspc, shift, axis=2 )
1950
1956
1951
1957
1952 spc = numpy.transpose( spc, (0,2,1) )
1958 spc = numpy.transpose( spc, (0,2,1) )
1953 self.data_spc = spc
1959 self.data_spc = spc
1954
1960
1955 if self.processingHeaderObj.flag_cspc:
1961 if self.processingHeaderObj.flag_cspc:
1956 cspc = numpy.transpose( cspc, (0,2,1) )
1962 cspc = numpy.transpose( cspc, (0,2,1) )
1957 self.data_cspc = cspc['real'] + cspc['imag']*1j
1963 self.data_cspc = cspc['real'] + cspc['imag']*1j
1958 else:
1964 else:
1959 self.data_cspc = None
1965 self.data_cspc = None
1960
1966
1961 if self.processingHeaderObj.flag_dc:
1967 if self.processingHeaderObj.flag_dc:
1962 self.data_dc = dc['real'] + dc['imag']*1j
1968 self.data_dc = dc['real'] + dc['imag']*1j
1963 else:
1969 else:
1964 self.data_dc = None
1970 self.data_dc = None
1965
1971
1966 self.flagIsNewFile = 0
1972 self.flagIsNewFile = 0
1967 self.flagIsNewBlock = 1
1973 self.flagIsNewBlock = 1
1968
1974
1969 self.nTotalBlocks += 1
1975 self.nTotalBlocks += 1
1970 self.nReadBlocks += 1
1976 self.nReadBlocks += 1
1971
1977
1972 return 1
1978 return 1
1973
1979
1974
1980
1975 def getData(self):
1981 def getData(self):
1976 """
1982 """
1977 Copia el buffer de lectura a la clase "Spectra",
1983 Copia el buffer de lectura a la clase "Spectra",
1978 con todos los parametros asociados a este (metadata). cuando no hay datos en el buffer de
1984 con todos los parametros asociados a este (metadata). cuando no hay datos en el buffer de
1979 lectura es necesario hacer una nueva lectura de los bloques de datos usando "readNextBlock"
1985 lectura es necesario hacer una nueva lectura de los bloques de datos usando "readNextBlock"
1980
1986
1981 Return:
1987 Return:
1982 0 : Si no hay mas archivos disponibles
1988 0 : Si no hay mas archivos disponibles
1983 1 : Si hizo una buena copia del buffer
1989 1 : Si hizo una buena copia del buffer
1984
1990
1985 Affected:
1991 Affected:
1986 self.dataOut
1992 self.dataOut
1987
1993
1988 self.flagTimeBlock
1994 self.flagTimeBlock
1989 self.flagIsNewBlock
1995 self.flagIsNewBlock
1990 """
1996 """
1991
1997
1992 if self.flagNoMoreFiles:
1998 if self.flagNoMoreFiles:
1993 self.dataOut.flagNoData = True
1999 self.dataOut.flagNoData = True
1994 print 'Process finished'
2000 print 'Process finished'
1995 return 0
2001 return 0
1996
2002
1997 self.flagTimeBlock = 0
2003 self.flagTimeBlock = 0
1998 self.flagIsNewBlock = 0
2004 self.flagIsNewBlock = 0
1999
2005
2000 if self.__hasNotDataInBuffer():
2006 if self.__hasNotDataInBuffer():
2001
2007
2002 if not( self.readNextBlock() ):
2008 if not( self.readNextBlock() ):
2003 self.dataOut.flagNoData = True
2009 self.dataOut.flagNoData = True
2004 return 0
2010 return 0
2005
2011
2006 # self.updateDataHeader()
2012 # self.updateDataHeader()
2007
2013
2008 #data es un numpy array de 3 dmensiones (perfiles, alturas y canales)
2014 #data es un numpy array de 3 dmensiones (perfiles, alturas y canales)
2009
2015
2010 if self.data_dc == None:
2016 if self.data_dc == None:
2011 self.dataOut.flagNoData = True
2017 self.dataOut.flagNoData = True
2012 return 0
2018 return 0
2013
2019
2014 self.dataOut.data_spc = self.data_spc
2020 self.dataOut.data_spc = self.data_spc
2015
2021
2016 self.dataOut.data_cspc = self.data_cspc
2022 self.dataOut.data_cspc = self.data_cspc
2017
2023
2018 self.dataOut.data_dc = self.data_dc
2024 self.dataOut.data_dc = self.data_dc
2019
2025
2020 self.dataOut.flagTimeBlock = self.flagTimeBlock
2026 self.dataOut.flagTimeBlock = self.flagTimeBlock
2021
2027
2022 self.dataOut.flagNoData = False
2028 self.dataOut.flagNoData = False
2023
2029
2024 self.dataOut.dtype = self.dtype
2030 self.dataOut.dtype = self.dtype
2025
2031
2026 # self.dataOut.nChannels = self.nRdChannels
2032 # self.dataOut.nChannels = self.nRdChannels
2027
2033
2028 self.dataOut.nPairs = self.nRdPairs
2034 self.dataOut.nPairs = self.nRdPairs
2029
2035
2030 self.dataOut.pairsList = self.rdPairList
2036 self.dataOut.pairsList = self.rdPairList
2031
2037
2032 # self.dataOut.nHeights = self.processingHeaderObj.nHeights
2038 # self.dataOut.nHeights = self.processingHeaderObj.nHeights
2033
2039
2034 self.dataOut.nProfiles = self.processingHeaderObj.profilesPerBlock
2040 self.dataOut.nProfiles = self.processingHeaderObj.profilesPerBlock
2035
2041
2036 self.dataOut.nFFTPoints = self.processingHeaderObj.profilesPerBlock
2042 self.dataOut.nFFTPoints = self.processingHeaderObj.profilesPerBlock
2037
2043
2038 self.dataOut.nCohInt = self.processingHeaderObj.nCohInt
2044 self.dataOut.nCohInt = self.processingHeaderObj.nCohInt
2039
2045
2040 self.dataOut.nIncohInt = self.processingHeaderObj.nIncohInt
2046 self.dataOut.nIncohInt = self.processingHeaderObj.nIncohInt
2041
2047
2042 xf = self.processingHeaderObj.firstHeight + self.processingHeaderObj.nHeights*self.processingHeaderObj.deltaHeight
2048 xf = self.processingHeaderObj.firstHeight + self.processingHeaderObj.nHeights*self.processingHeaderObj.deltaHeight
2043
2049
2044 self.dataOut.heightList = numpy.arange(self.processingHeaderObj.firstHeight, xf, self.processingHeaderObj.deltaHeight)
2050 self.dataOut.heightList = numpy.arange(self.processingHeaderObj.firstHeight, xf, self.processingHeaderObj.deltaHeight)
2045
2051
2046 self.dataOut.channelList = range(self.systemHeaderObj.nChannels)
2052 self.dataOut.channelList = range(self.systemHeaderObj.nChannels)
2047
2053
2048 # self.dataOut.channelIndexList = range(self.systemHeaderObj.nChannels)
2054 # self.dataOut.channelIndexList = range(self.systemHeaderObj.nChannels)
2049
2055
2050 self.dataOut.utctime = self.basicHeaderObj.utc + self.basicHeaderObj.miliSecond/1000.#+ self.profileIndex * self.ippSeconds
2056 self.dataOut.utctime = self.basicHeaderObj.utc + self.basicHeaderObj.miliSecond/1000.#+ self.profileIndex * self.ippSeconds
2051
2057
2052 self.dataOut.ippSeconds = self.ippSeconds
2058 self.dataOut.ippSeconds = self.ippSeconds
2053
2059
2054 self.dataOut.timeInterval = self.ippSeconds * self.processingHeaderObj.nCohInt * self.processingHeaderObj.nIncohInt * self.dataOut.nFFTPoints
2060 self.dataOut.timeInterval = self.ippSeconds * self.processingHeaderObj.nCohInt * self.processingHeaderObj.nIncohInt * self.dataOut.nFFTPoints
2055
2061
2056 self.dataOut.flagShiftFFT = self.processingHeaderObj.shif_fft
2062 self.dataOut.flagShiftFFT = self.processingHeaderObj.shif_fft
2057
2063
2058 # self.profileIndex += 1
2064 # self.profileIndex += 1
2059
2065
2060 self.dataOut.systemHeaderObj = self.systemHeaderObj.copy()
2066 self.dataOut.systemHeaderObj = self.systemHeaderObj.copy()
2061
2067
2062 self.dataOut.radarControllerHeaderObj = self.radarControllerHeaderObj.copy()
2068 self.dataOut.radarControllerHeaderObj = self.radarControllerHeaderObj.copy()
2063
2069
2064 return self.dataOut.data_spc
2070 return self.dataOut.data_spc
2065
2071
2066
2072
2067 class SpectraWriter(JRODataWriter):
2073 class SpectraWriter(JRODataWriter):
2068
2074
2069 """
2075 """
2070 Esta clase permite escribir datos de espectros a archivos procesados (.pdata). La escritura
2076 Esta clase permite escribir datos de espectros a archivos procesados (.pdata). La escritura
2071 de los datos siempre se realiza por bloques.
2077 de los datos siempre se realiza por bloques.
2072 """
2078 """
2073
2079
2074 ext = ".pdata"
2080 ext = ".pdata"
2075
2081
2076 optchar = "P"
2082 optchar = "P"
2077
2083
2078 shape_spc_Buffer = None
2084 shape_spc_Buffer = None
2079
2085
2080 shape_cspc_Buffer = None
2086 shape_cspc_Buffer = None
2081
2087
2082 shape_dc_Buffer = None
2088 shape_dc_Buffer = None
2083
2089
2084 data_spc = None
2090 data_spc = None
2085
2091
2086 data_cspc = None
2092 data_cspc = None
2087
2093
2088 data_dc = None
2094 data_dc = None
2089
2095
2090 # dataOut = None
2096 # dataOut = None
2091
2097
2092 def __init__(self):
2098 def __init__(self):
2093 """
2099 """
2094 Inicializador de la clase SpectraWriter para la escritura de datos de espectros.
2100 Inicializador de la clase SpectraWriter para la escritura de datos de espectros.
2095
2101
2096 Affected:
2102 Affected:
2097 self.dataOut
2103 self.dataOut
2098 self.basicHeaderObj
2104 self.basicHeaderObj
2099 self.systemHeaderObj
2105 self.systemHeaderObj
2100 self.radarControllerHeaderObj
2106 self.radarControllerHeaderObj
2101 self.processingHeaderObj
2107 self.processingHeaderObj
2102
2108
2103 Return: None
2109 Return: None
2104 """
2110 """
2105
2111
2106 self.isConfig = False
2112 self.isConfig = False
2107
2113
2108 self.nTotalBlocks = 0
2114 self.nTotalBlocks = 0
2109
2115
2110 self.data_spc = None
2116 self.data_spc = None
2111
2117
2112 self.data_cspc = None
2118 self.data_cspc = None
2113
2119
2114 self.data_dc = None
2120 self.data_dc = None
2115
2121
2116 self.fp = None
2122 self.fp = None
2117
2123
2118 self.flagIsNewFile = 1
2124 self.flagIsNewFile = 1
2119
2125
2120 self.nTotalBlocks = 0
2126 self.nTotalBlocks = 0
2121
2127
2122 self.flagIsNewBlock = 0
2128 self.flagIsNewBlock = 0
2123
2129
2124 self.setFile = None
2130 self.setFile = None
2125
2131
2126 self.dtype = None
2132 self.dtype = None
2127
2133
2128 self.path = None
2134 self.path = None
2129
2135
2130 self.noMoreFiles = 0
2136 self.noMoreFiles = 0
2131
2137
2132 self.filename = None
2138 self.filename = None
2133
2139
2134 self.basicHeaderObj = BasicHeader()
2140 self.basicHeaderObj = BasicHeader()
2135
2141
2136 self.systemHeaderObj = SystemHeader()
2142 self.systemHeaderObj = SystemHeader()
2137
2143
2138 self.radarControllerHeaderObj = RadarControllerHeader()
2144 self.radarControllerHeaderObj = RadarControllerHeader()
2139
2145
2140 self.processingHeaderObj = ProcessingHeader()
2146 self.processingHeaderObj = ProcessingHeader()
2141
2147
2142
2148
2143 def hasAllDataInBuffer(self):
2149 def hasAllDataInBuffer(self):
2144 return 1
2150 return 1
2145
2151
2146
2152
2147 def setBlockDimension(self):
2153 def setBlockDimension(self):
2148 """
2154 """
2149 Obtiene las formas dimensionales del los subbloques de datos que componen un bloque
2155 Obtiene las formas dimensionales del los subbloques de datos que componen un bloque
2150
2156
2151 Affected:
2157 Affected:
2152 self.shape_spc_Buffer
2158 self.shape_spc_Buffer
2153 self.shape_cspc_Buffer
2159 self.shape_cspc_Buffer
2154 self.shape_dc_Buffer
2160 self.shape_dc_Buffer
2155
2161
2156 Return: None
2162 Return: None
2157 """
2163 """
2158 self.shape_spc_Buffer = (self.dataOut.nChannels,
2164 self.shape_spc_Buffer = (self.dataOut.nChannels,
2159 self.processingHeaderObj.nHeights,
2165 self.processingHeaderObj.nHeights,
2160 self.processingHeaderObj.profilesPerBlock)
2166 self.processingHeaderObj.profilesPerBlock)
2161
2167
2162 self.shape_cspc_Buffer = (self.dataOut.nPairs,
2168 self.shape_cspc_Buffer = (self.dataOut.nPairs,
2163 self.processingHeaderObj.nHeights,
2169 self.processingHeaderObj.nHeights,
2164 self.processingHeaderObj.profilesPerBlock)
2170 self.processingHeaderObj.profilesPerBlock)
2165
2171
2166 self.shape_dc_Buffer = (self.dataOut.nChannels,
2172 self.shape_dc_Buffer = (self.dataOut.nChannels,
2167 self.processingHeaderObj.nHeights)
2173 self.processingHeaderObj.nHeights)
2168
2174
2169
2175
2170 def writeBlock(self):
2176 def writeBlock(self):
2171 """
2177 """
2172 Escribe el buffer en el file designado
2178 Escribe el buffer en el file designado
2173
2179
2174 Affected:
2180 Affected:
2175 self.data_spc
2181 self.data_spc
2176 self.data_cspc
2182 self.data_cspc
2177 self.data_dc
2183 self.data_dc
2178 self.flagIsNewFile
2184 self.flagIsNewFile
2179 self.flagIsNewBlock
2185 self.flagIsNewBlock
2180 self.nTotalBlocks
2186 self.nTotalBlocks
2181 self.nWriteBlocks
2187 self.nWriteBlocks
2182
2188
2183 Return: None
2189 Return: None
2184 """
2190 """
2185
2191
2186 spc = numpy.transpose( self.data_spc, (0,2,1) )
2192 spc = numpy.transpose( self.data_spc, (0,2,1) )
2187 if not( self.processingHeaderObj.shif_fft ):
2193 if not( self.processingHeaderObj.shif_fft ):
2188 spc = numpy.roll( spc, self.processingHeaderObj.profilesPerBlock/2, axis=2 ) #desplaza a la derecha en el eje 2 determinadas posiciones
2194 spc = numpy.roll( spc, self.processingHeaderObj.profilesPerBlock/2, axis=2 ) #desplaza a la derecha en el eje 2 determinadas posiciones
2189 data = spc.reshape((-1))
2195 data = spc.reshape((-1))
2190 data.tofile(self.fp)
2196 data.tofile(self.fp)
2191
2197
2192 if self.data_cspc != None:
2198 if self.data_cspc != None:
2193 data = numpy.zeros( self.shape_cspc_Buffer, self.dtype )
2199 data = numpy.zeros( self.shape_cspc_Buffer, self.dtype )
2194 cspc = numpy.transpose( self.data_cspc, (0,2,1) )
2200 cspc = numpy.transpose( self.data_cspc, (0,2,1) )
2195 if not( self.processingHeaderObj.shif_fft ):
2201 if not( self.processingHeaderObj.shif_fft ):
2196 cspc = numpy.roll( cspc, self.processingHeaderObj.profilesPerBlock/2, axis=2 ) #desplaza a la derecha en el eje 2 determinadas posiciones
2202 cspc = numpy.roll( cspc, self.processingHeaderObj.profilesPerBlock/2, axis=2 ) #desplaza a la derecha en el eje 2 determinadas posiciones
2197 data['real'] = cspc.real
2203 data['real'] = cspc.real
2198 data['imag'] = cspc.imag
2204 data['imag'] = cspc.imag
2199 data = data.reshape((-1))
2205 data = data.reshape((-1))
2200 data.tofile(self.fp)
2206 data.tofile(self.fp)
2201
2207
2202 if self.data_dc != None:
2208 if self.data_dc != None:
2203 data = numpy.zeros( self.shape_dc_Buffer, self.dtype )
2209 data = numpy.zeros( self.shape_dc_Buffer, self.dtype )
2204 dc = self.data_dc
2210 dc = self.data_dc
2205 data['real'] = dc.real
2211 data['real'] = dc.real
2206 data['imag'] = dc.imag
2212 data['imag'] = dc.imag
2207 data = data.reshape((-1))
2213 data = data.reshape((-1))
2208 data.tofile(self.fp)
2214 data.tofile(self.fp)
2209
2215
2210 self.data_spc.fill(0)
2216 self.data_spc.fill(0)
2211 self.data_dc.fill(0)
2217 self.data_dc.fill(0)
2212 if self.data_cspc != None:
2218 if self.data_cspc != None:
2213 self.data_cspc.fill(0)
2219 self.data_cspc.fill(0)
2214
2220
2215 self.flagIsNewFile = 0
2221 self.flagIsNewFile = 0
2216 self.flagIsNewBlock = 1
2222 self.flagIsNewBlock = 1
2217 self.nTotalBlocks += 1
2223 self.nTotalBlocks += 1
2218 self.nWriteBlocks += 1
2224 self.nWriteBlocks += 1
2219 self.blockIndex += 1
2225 self.blockIndex += 1
2220
2226
2221
2227
2222 def putData(self):
2228 def putData(self):
2223 """
2229 """
2224 Setea un bloque de datos y luego los escribe en un file
2230 Setea un bloque de datos y luego los escribe en un file
2225
2231
2226 Affected:
2232 Affected:
2227 self.data_spc
2233 self.data_spc
2228 self.data_cspc
2234 self.data_cspc
2229 self.data_dc
2235 self.data_dc
2230
2236
2231 Return:
2237 Return:
2232 0 : Si no hay data o no hay mas files que puedan escribirse
2238 0 : Si no hay data o no hay mas files que puedan escribirse
2233 1 : Si se escribio la data de un bloque en un file
2239 1 : Si se escribio la data de un bloque en un file
2234 """
2240 """
2235
2241
2236 if self.dataOut.flagNoData:
2242 if self.dataOut.flagNoData:
2237 return 0
2243 return 0
2238
2244
2239 self.flagIsNewBlock = 0
2245 self.flagIsNewBlock = 0
2240
2246
2241 if self.dataOut.flagTimeBlock:
2247 if self.dataOut.flagTimeBlock:
2242 self.data_spc.fill(0)
2248 self.data_spc.fill(0)
2243 self.data_cspc.fill(0)
2249 self.data_cspc.fill(0)
2244 self.data_dc.fill(0)
2250 self.data_dc.fill(0)
2245 self.setNextFile()
2251 self.setNextFile()
2246
2252
2247 if self.flagIsNewFile == 0:
2253 if self.flagIsNewFile == 0:
2248 self.getBasicHeader()
2254 self.getBasicHeader()
2249
2255
2250 self.data_spc = self.dataOut.data_spc
2256 self.data_spc = self.dataOut.data_spc
2251 self.data_cspc = self.dataOut.data_cspc
2257 self.data_cspc = self.dataOut.data_cspc
2252 self.data_dc = self.dataOut.data_dc
2258 self.data_dc = self.dataOut.data_dc
2253
2259
2254 # #self.processingHeaderObj.dataBlocksPerFile)
2260 # #self.processingHeaderObj.dataBlocksPerFile)
2255 if self.hasAllDataInBuffer():
2261 if self.hasAllDataInBuffer():
2256 # self.getDataHeader()
2262 # self.getDataHeader()
2257 self.writeNextBlock()
2263 self.writeNextBlock()
2258
2264
2259 return 1
2265 return 1
2260
2266
2261
2267
2262 def __getProcessFlags(self):
2268 def __getProcessFlags(self):
2263
2269
2264 processFlags = 0
2270 processFlags = 0
2265
2271
2266 dtype0 = numpy.dtype([('real','<i1'),('imag','<i1')])
2272 dtype0 = numpy.dtype([('real','<i1'),('imag','<i1')])
2267 dtype1 = numpy.dtype([('real','<i2'),('imag','<i2')])
2273 dtype1 = numpy.dtype([('real','<i2'),('imag','<i2')])
2268 dtype2 = numpy.dtype([('real','<i4'),('imag','<i4')])
2274 dtype2 = numpy.dtype([('real','<i4'),('imag','<i4')])
2269 dtype3 = numpy.dtype([('real','<i8'),('imag','<i8')])
2275 dtype3 = numpy.dtype([('real','<i8'),('imag','<i8')])
2270 dtype4 = numpy.dtype([('real','<f4'),('imag','<f4')])
2276 dtype4 = numpy.dtype([('real','<f4'),('imag','<f4')])
2271 dtype5 = numpy.dtype([('real','<f8'),('imag','<f8')])
2277 dtype5 = numpy.dtype([('real','<f8'),('imag','<f8')])
2272
2278
2273 dtypeList = [dtype0, dtype1, dtype2, dtype3, dtype4, dtype5]
2279 dtypeList = [dtype0, dtype1, dtype2, dtype3, dtype4, dtype5]
2274
2280
2275
2281
2276
2282
2277 datatypeValueList = [PROCFLAG.DATATYPE_CHAR,
2283 datatypeValueList = [PROCFLAG.DATATYPE_CHAR,
2278 PROCFLAG.DATATYPE_SHORT,
2284 PROCFLAG.DATATYPE_SHORT,
2279 PROCFLAG.DATATYPE_LONG,
2285 PROCFLAG.DATATYPE_LONG,
2280 PROCFLAG.DATATYPE_INT64,
2286 PROCFLAG.DATATYPE_INT64,
2281 PROCFLAG.DATATYPE_FLOAT,
2287 PROCFLAG.DATATYPE_FLOAT,
2282 PROCFLAG.DATATYPE_DOUBLE]
2288 PROCFLAG.DATATYPE_DOUBLE]
2283
2289
2284
2290
2285 for index in range(len(dtypeList)):
2291 for index in range(len(dtypeList)):
2286 if self.dataOut.dtype == dtypeList[index]:
2292 if self.dataOut.dtype == dtypeList[index]:
2287 dtypeValue = datatypeValueList[index]
2293 dtypeValue = datatypeValueList[index]
2288 break
2294 break
2289
2295
2290 processFlags += dtypeValue
2296 processFlags += dtypeValue
2291
2297
2292 if self.dataOut.flagDecodeData:
2298 if self.dataOut.flagDecodeData:
2293 processFlags += PROCFLAG.DECODE_DATA
2299 processFlags += PROCFLAG.DECODE_DATA
2294
2300
2295 if self.dataOut.flagDeflipData:
2301 if self.dataOut.flagDeflipData:
2296 processFlags += PROCFLAG.DEFLIP_DATA
2302 processFlags += PROCFLAG.DEFLIP_DATA
2297
2303
2298 if self.dataOut.code != None:
2304 if self.dataOut.code != None:
2299 processFlags += PROCFLAG.DEFINE_PROCESS_CODE
2305 processFlags += PROCFLAG.DEFINE_PROCESS_CODE
2300
2306
2301 if self.dataOut.nIncohInt > 1:
2307 if self.dataOut.nIncohInt > 1:
2302 processFlags += PROCFLAG.INCOHERENT_INTEGRATION
2308 processFlags += PROCFLAG.INCOHERENT_INTEGRATION
2303
2309
2304 if self.dataOut.data_dc != None:
2310 if self.dataOut.data_dc != None:
2305 processFlags += PROCFLAG.SAVE_CHANNELS_DC
2311 processFlags += PROCFLAG.SAVE_CHANNELS_DC
2306
2312
2307 return processFlags
2313 return processFlags
2308
2314
2309
2315
2310 def __getBlockSize(self):
2316 def __getBlockSize(self):
2311 '''
2317 '''
2312 Este metodos determina el cantidad de bytes para un bloque de datos de tipo Spectra
2318 Este metodos determina el cantidad de bytes para un bloque de datos de tipo Spectra
2313 '''
2319 '''
2314
2320
2315 dtype0 = numpy.dtype([('real','<i1'),('imag','<i1')])
2321 dtype0 = numpy.dtype([('real','<i1'),('imag','<i1')])
2316 dtype1 = numpy.dtype([('real','<i2'),('imag','<i2')])
2322 dtype1 = numpy.dtype([('real','<i2'),('imag','<i2')])
2317 dtype2 = numpy.dtype([('real','<i4'),('imag','<i4')])
2323 dtype2 = numpy.dtype([('real','<i4'),('imag','<i4')])
2318 dtype3 = numpy.dtype([('real','<i8'),('imag','<i8')])
2324 dtype3 = numpy.dtype([('real','<i8'),('imag','<i8')])
2319 dtype4 = numpy.dtype([('real','<f4'),('imag','<f4')])
2325 dtype4 = numpy.dtype([('real','<f4'),('imag','<f4')])
2320 dtype5 = numpy.dtype([('real','<f8'),('imag','<f8')])
2326 dtype5 = numpy.dtype([('real','<f8'),('imag','<f8')])
2321
2327
2322 dtypeList = [dtype0, dtype1, dtype2, dtype3, dtype4, dtype5]
2328 dtypeList = [dtype0, dtype1, dtype2, dtype3, dtype4, dtype5]
2323 datatypeValueList = [1,2,4,8,4,8]
2329 datatypeValueList = [1,2,4,8,4,8]
2324 for index in range(len(dtypeList)):
2330 for index in range(len(dtypeList)):
2325 if self.dataOut.dtype == dtypeList[index]:
2331 if self.dataOut.dtype == dtypeList[index]:
2326 datatypeValue = datatypeValueList[index]
2332 datatypeValue = datatypeValueList[index]
2327 break
2333 break
2328
2334
2329
2335
2330 pts2write = self.dataOut.nHeights * self.dataOut.nFFTPoints
2336 pts2write = self.dataOut.nHeights * self.dataOut.nFFTPoints
2331
2337
2332 pts2write_SelfSpectra = int(self.dataOut.nChannels * pts2write)
2338 pts2write_SelfSpectra = int(self.dataOut.nChannels * pts2write)
2333 blocksize = (pts2write_SelfSpectra*datatypeValue)
2339 blocksize = (pts2write_SelfSpectra*datatypeValue)
2334
2340
2335 if self.dataOut.data_cspc != None:
2341 if self.dataOut.data_cspc != None:
2336 pts2write_CrossSpectra = int(self.dataOut.nPairs * pts2write)
2342 pts2write_CrossSpectra = int(self.dataOut.nPairs * pts2write)
2337 blocksize += (pts2write_CrossSpectra*datatypeValue*2)
2343 blocksize += (pts2write_CrossSpectra*datatypeValue*2)
2338
2344
2339 if self.dataOut.data_dc != None:
2345 if self.dataOut.data_dc != None:
2340 pts2write_DCchannels = int(self.dataOut.nChannels * self.dataOut.nHeights)
2346 pts2write_DCchannels = int(self.dataOut.nChannels * self.dataOut.nHeights)
2341 blocksize += (pts2write_DCchannels*datatypeValue*2)
2347 blocksize += (pts2write_DCchannels*datatypeValue*2)
2342
2348
2343 blocksize = blocksize #* datatypeValue * 2 #CORREGIR ESTO
2349 blocksize = blocksize #* datatypeValue * 2 #CORREGIR ESTO
2344
2350
2345 return blocksize
2351 return blocksize
2346
2352
2347 def getDataHeader(self):
2353 def getDataHeader(self):
2348
2354
2349 """
2355 """
2350 Obtiene una copia del First Header
2356 Obtiene una copia del First Header
2351
2357
2352 Affected:
2358 Affected:
2353 self.systemHeaderObj
2359 self.systemHeaderObj
2354 self.radarControllerHeaderObj
2360 self.radarControllerHeaderObj
2355 self.dtype
2361 self.dtype
2356
2362
2357 Return:
2363 Return:
2358 None
2364 None
2359 """
2365 """
2360
2366
2361 self.systemHeaderObj = self.dataOut.systemHeaderObj.copy()
2367 self.systemHeaderObj = self.dataOut.systemHeaderObj.copy()
2362 self.systemHeaderObj.nChannels = self.dataOut.nChannels
2368 self.systemHeaderObj.nChannels = self.dataOut.nChannels
2363 self.radarControllerHeaderObj = self.dataOut.radarControllerHeaderObj.copy()
2369 self.radarControllerHeaderObj = self.dataOut.radarControllerHeaderObj.copy()
2364
2370
2365 self.getBasicHeader()
2371 self.getBasicHeader()
2366
2372
2367 processingHeaderSize = 40 # bytes
2373 processingHeaderSize = 40 # bytes
2368 self.processingHeaderObj.dtype = 0 # Voltage
2374 self.processingHeaderObj.dtype = 0 # Voltage
2369 self.processingHeaderObj.blockSize = self.__getBlockSize()
2375 self.processingHeaderObj.blockSize = self.__getBlockSize()
2370 self.processingHeaderObj.profilesPerBlock = self.dataOut.nFFTPoints
2376 self.processingHeaderObj.profilesPerBlock = self.dataOut.nFFTPoints
2371 self.processingHeaderObj.dataBlocksPerFile = self.blocksPerFile
2377 self.processingHeaderObj.dataBlocksPerFile = self.blocksPerFile
2372 self.processingHeaderObj.nWindows = 1 #podria ser 1 o self.dataOut.processingHeaderObj.nWindows
2378 self.processingHeaderObj.nWindows = 1 #podria ser 1 o self.dataOut.processingHeaderObj.nWindows
2373 self.processingHeaderObj.processFlags = self.__getProcessFlags()
2379 self.processingHeaderObj.processFlags = self.__getProcessFlags()
2374 self.processingHeaderObj.nCohInt = self.dataOut.nCohInt# Se requiere para determinar el valor de timeInterval
2380 self.processingHeaderObj.nCohInt = self.dataOut.nCohInt# Se requiere para determinar el valor de timeInterval
2375 self.processingHeaderObj.nIncohInt = self.dataOut.nIncohInt
2381 self.processingHeaderObj.nIncohInt = self.dataOut.nIncohInt
2376 self.processingHeaderObj.totalSpectra = self.dataOut.nPairs + self.dataOut.nChannels
2382 self.processingHeaderObj.totalSpectra = self.dataOut.nPairs + self.dataOut.nChannels
2377
2383
2378 if self.processingHeaderObj.totalSpectra > 0:
2384 if self.processingHeaderObj.totalSpectra > 0:
2379 channelList = []
2385 channelList = []
2380 for channel in range(self.dataOut.nChannels):
2386 for channel in range(self.dataOut.nChannels):
2381 channelList.append(channel)
2387 channelList.append(channel)
2382 channelList.append(channel)
2388 channelList.append(channel)
2383
2389
2384 pairsList = []
2390 pairsList = []
2385 for pair in self.dataOut.pairsList:
2391 for pair in self.dataOut.pairsList:
2386 pairsList.append(pair[0])
2392 pairsList.append(pair[0])
2387 pairsList.append(pair[1])
2393 pairsList.append(pair[1])
2388 spectraComb = channelList + pairsList
2394 spectraComb = channelList + pairsList
2389 spectraComb = numpy.array(spectraComb,dtype="u1")
2395 spectraComb = numpy.array(spectraComb,dtype="u1")
2390 self.processingHeaderObj.spectraComb = spectraComb
2396 self.processingHeaderObj.spectraComb = spectraComb
2391 sizeOfSpcComb = len(spectraComb)
2397 sizeOfSpcComb = len(spectraComb)
2392 processingHeaderSize += sizeOfSpcComb
2398 processingHeaderSize += sizeOfSpcComb
2393
2399
2394 if self.dataOut.code != None:
2400 if self.dataOut.code != None:
2395 self.processingHeaderObj.code = self.dataOut.code
2401 self.processingHeaderObj.code = self.dataOut.code
2396 self.processingHeaderObj.nCode = self.dataOut.nCode
2402 self.processingHeaderObj.nCode = self.dataOut.nCode
2397 self.processingHeaderObj.nBaud = self.dataOut.nBaud
2403 self.processingHeaderObj.nBaud = self.dataOut.nBaud
2398 nCodeSize = 4 # bytes
2404 nCodeSize = 4 # bytes
2399 nBaudSize = 4 # bytes
2405 nBaudSize = 4 # bytes
2400 codeSize = 4 # bytes
2406 codeSize = 4 # bytes
2401 sizeOfCode = int(nCodeSize + nBaudSize + codeSize * self.dataOut.nCode * self.dataOut.nBaud)
2407 sizeOfCode = int(nCodeSize + nBaudSize + codeSize * self.dataOut.nCode * self.dataOut.nBaud)
2402 processingHeaderSize += sizeOfCode
2408 processingHeaderSize += sizeOfCode
2403
2409
2404 if self.processingHeaderObj.nWindows != 0:
2410 if self.processingHeaderObj.nWindows != 0:
2405 self.processingHeaderObj.firstHeight = self.dataOut.heightList[0]
2411 self.processingHeaderObj.firstHeight = self.dataOut.heightList[0]
2406 self.processingHeaderObj.deltaHeight = self.dataOut.heightList[1] - self.dataOut.heightList[0]
2412 self.processingHeaderObj.deltaHeight = self.dataOut.heightList[1] - self.dataOut.heightList[0]
2407 self.processingHeaderObj.nHeights = self.dataOut.nHeights
2413 self.processingHeaderObj.nHeights = self.dataOut.nHeights
2408 self.processingHeaderObj.samplesWin = self.dataOut.nHeights
2414 self.processingHeaderObj.samplesWin = self.dataOut.nHeights
2409 sizeOfFirstHeight = 4
2415 sizeOfFirstHeight = 4
2410 sizeOfdeltaHeight = 4
2416 sizeOfdeltaHeight = 4
2411 sizeOfnHeights = 4
2417 sizeOfnHeights = 4
2412 sizeOfWindows = (sizeOfFirstHeight + sizeOfdeltaHeight + sizeOfnHeights)*self.processingHeaderObj.nWindows
2418 sizeOfWindows = (sizeOfFirstHeight + sizeOfdeltaHeight + sizeOfnHeights)*self.processingHeaderObj.nWindows
2413 processingHeaderSize += sizeOfWindows
2419 processingHeaderSize += sizeOfWindows
2414
2420
2415 self.processingHeaderObj.size = processingHeaderSize
2421 self.processingHeaderObj.size = processingHeaderSize
2416
2422
2417 class SpectraHeisWriter():
2423 class SpectraHeisWriter():
2418
2424
2419 i=0
2425 i=0
2420
2426
2421 def __init__(self, dataOut):
2427 def __init__(self, dataOut):
2422
2428
2423 self.wrObj = FITS()
2429 self.wrObj = FITS()
2424 self.dataOut = dataOut
2430 self.dataOut = dataOut
2425
2431
2426 def isNumber(str):
2432 def isNumber(str):
2427 """
2433 """
2428 Chequea si el conjunto de caracteres que componen un string puede ser convertidos a un numero.
2434 Chequea si el conjunto de caracteres que componen un string puede ser convertidos a un numero.
2429
2435
2430 Excepciones:
2436 Excepciones:
2431 Si un determinado string no puede ser convertido a numero
2437 Si un determinado string no puede ser convertido a numero
2432 Input:
2438 Input:
2433 str, string al cual se le analiza para determinar si convertible a un numero o no
2439 str, string al cual se le analiza para determinar si convertible a un numero o no
2434
2440
2435 Return:
2441 Return:
2436 True : si el string es uno numerico
2442 True : si el string es uno numerico
2437 False : no es un string numerico
2443 False : no es un string numerico
2438 """
2444 """
2439 try:
2445 try:
2440 float( str )
2446 float( str )
2441 return True
2447 return True
2442 except:
2448 except:
2443 return False
2449 return False
2444
2450
2445 def setup(self, wrpath,):
2451 def setup(self, wrpath,):
2446
2452
2447 if not(os.path.exists(wrpath)):
2453 if not(os.path.exists(wrpath)):
2448 os.mkdir(wrpath)
2454 os.mkdir(wrpath)
2449
2455
2450 self.wrpath = wrpath
2456 self.wrpath = wrpath
2451 self.setFile = 0
2457 self.setFile = 0
2452
2458
2453 def putData(self):
2459 def putData(self):
2454 # self.wrObj.writeHeader(nChannels=self.dataOut.nChannels, nFFTPoints=self.dataOut.nFFTPoints)
2460 # self.wrObj.writeHeader(nChannels=self.dataOut.nChannels, nFFTPoints=self.dataOut.nFFTPoints)
2455 #name = self.dataOut.utctime
2461 #name = self.dataOut.utctime
2456 name= time.localtime( self.dataOut.utctime)
2462 name= time.localtime( self.dataOut.utctime)
2457 ext=".fits"
2463 ext=".fits"
2458 #folder='D%4.4d%3.3d'%(name.tm_year,name.tm_yday)
2464 #folder='D%4.4d%3.3d'%(name.tm_year,name.tm_yday)
2459 subfolder = 'D%4.4d%3.3d' % (name.tm_year,name.tm_yday)
2465 subfolder = 'D%4.4d%3.3d' % (name.tm_year,name.tm_yday)
2460
2466
2461 fullpath = os.path.join( self.wrpath, subfolder )
2467 fullpath = os.path.join( self.wrpath, subfolder )
2462 if not( os.path.exists(fullpath) ):
2468 if not( os.path.exists(fullpath) ):
2463 os.mkdir(fullpath)
2469 os.mkdir(fullpath)
2464 self.setFile += 1
2470 self.setFile += 1
2465 file = 'D%4.4d%3.3d%3.3d%s' % (name.tm_year,name.tm_yday,self.setFile,ext)
2471 file = 'D%4.4d%3.3d%3.3d%s' % (name.tm_year,name.tm_yday,self.setFile,ext)
2466
2472
2467 filename = os.path.join(self.wrpath,subfolder, file)
2473 filename = os.path.join(self.wrpath,subfolder, file)
2468
2474
2469 # print self.dataOut.ippSeconds
2475 # print self.dataOut.ippSeconds
2470 freq=numpy.arange(-1*self.dataOut.nHeights/2.,self.dataOut.nHeights/2.)/(2*self.dataOut.ippSeconds)
2476 freq=numpy.arange(-1*self.dataOut.nHeights/2.,self.dataOut.nHeights/2.)/(2*self.dataOut.ippSeconds)
2471
2477
2472 col1=self.wrObj.setColF(name="freq", format=str(self.dataOut.nFFTPoints)+'E', array=freq)
2478 col1=self.wrObj.setColF(name="freq", format=str(self.dataOut.nFFTPoints)+'E', array=freq)
2473 col2=self.wrObj.writeData(name="P_Ch1",format=str(self.dataOut.nFFTPoints)+'E',data=10*numpy.log10(self.dataOut.data_spc[0,:]))
2479 col2=self.wrObj.writeData(name="P_Ch1",format=str(self.dataOut.nFFTPoints)+'E',data=10*numpy.log10(self.dataOut.data_spc[0,:]))
2474 col3=self.wrObj.writeData(name="P_Ch2",format=str(self.dataOut.nFFTPoints)+'E',data=10*numpy.log10(self.dataOut.data_spc[1,:]))
2480 col3=self.wrObj.writeData(name="P_Ch2",format=str(self.dataOut.nFFTPoints)+'E',data=10*numpy.log10(self.dataOut.data_spc[1,:]))
2475 col4=self.wrObj.writeData(name="P_Ch3",format=str(self.dataOut.nFFTPoints)+'E',data=10*numpy.log10(self.dataOut.data_spc[2,:]))
2481 col4=self.wrObj.writeData(name="P_Ch3",format=str(self.dataOut.nFFTPoints)+'E',data=10*numpy.log10(self.dataOut.data_spc[2,:]))
2476 col5=self.wrObj.writeData(name="P_Ch4",format=str(self.dataOut.nFFTPoints)+'E',data=10*numpy.log10(self.dataOut.data_spc[3,:]))
2482 col5=self.wrObj.writeData(name="P_Ch4",format=str(self.dataOut.nFFTPoints)+'E',data=10*numpy.log10(self.dataOut.data_spc[3,:]))
2477 col6=self.wrObj.writeData(name="P_Ch5",format=str(self.dataOut.nFFTPoints)+'E',data=10*numpy.log10(self.dataOut.data_spc[4,:]))
2483 col6=self.wrObj.writeData(name="P_Ch5",format=str(self.dataOut.nFFTPoints)+'E',data=10*numpy.log10(self.dataOut.data_spc[4,:]))
2478 col7=self.wrObj.writeData(name="P_Ch6",format=str(self.dataOut.nFFTPoints)+'E',data=10*numpy.log10(self.dataOut.data_spc[5,:]))
2484 col7=self.wrObj.writeData(name="P_Ch6",format=str(self.dataOut.nFFTPoints)+'E',data=10*numpy.log10(self.dataOut.data_spc[5,:]))
2479 col8=self.wrObj.writeData(name="P_Ch7",format=str(self.dataOut.nFFTPoints)+'E',data=10*numpy.log10(self.dataOut.data_spc[6,:]))
2485 col8=self.wrObj.writeData(name="P_Ch7",format=str(self.dataOut.nFFTPoints)+'E',data=10*numpy.log10(self.dataOut.data_spc[6,:]))
2480 col9=self.wrObj.writeData(name="P_Ch8",format=str(self.dataOut.nFFTPoints)+'E',data=10*numpy.log10(self.dataOut.data_spc[7,:]))
2486 col9=self.wrObj.writeData(name="P_Ch8",format=str(self.dataOut.nFFTPoints)+'E',data=10*numpy.log10(self.dataOut.data_spc[7,:]))
2481 #n=numpy.arange((100))
2487 #n=numpy.arange((100))
2482 n=self.dataOut.data_spc[6,:]
2488 n=self.dataOut.data_spc[6,:]
2483 a=self.wrObj.cFImage(n)
2489 a=self.wrObj.cFImage(n)
2484 b=self.wrObj.Ctable(col1,col2,col3,col4,col5,col6,col7,col8,col9)
2490 b=self.wrObj.Ctable(col1,col2,col3,col4,col5,col6,col7,col8,col9)
2485 self.wrObj.CFile(a,b)
2491 self.wrObj.CFile(a,b)
2486 self.wrObj.wFile(filename)
2492 self.wrObj.wFile(filename)
2487 return 1
2493 return 1
2488
2494
2489 class FITS:
2495 class FITS:
2490
2496
2491 name=None
2497 name=None
2492 format=None
2498 format=None
2493 array =None
2499 array =None
2494 data =None
2500 data =None
2495 thdulist=None
2501 thdulist=None
2496
2502
2497 def __init__(self):
2503 def __init__(self):
2498
2504
2499 pass
2505 pass
2500
2506
2501 def setColF(self,name,format,array):
2507 def setColF(self,name,format,array):
2502 self.name=name
2508 self.name=name
2503 self.format=format
2509 self.format=format
2504 self.array=array
2510 self.array=array
2505 a1=numpy.array([self.array],dtype=numpy.float32)
2511 a1=numpy.array([self.array],dtype=numpy.float32)
2506 self.col1 = pyfits.Column(name=self.name, format=self.format, array=a1)
2512 self.col1 = pyfits.Column(name=self.name, format=self.format, array=a1)
2507 return self.col1
2513 return self.col1
2508
2514
2509 # def setColP(self,name,format,data):
2515 # def setColP(self,name,format,data):
2510 # self.name=name
2516 # self.name=name
2511 # self.format=format
2517 # self.format=format
2512 # self.data=data
2518 # self.data=data
2513 # a2=numpy.array([self.data],dtype=numpy.float32)
2519 # a2=numpy.array([self.data],dtype=numpy.float32)
2514 # self.col2 = pyfits.Column(name=self.name, format=self.format, array=a2)
2520 # self.col2 = pyfits.Column(name=self.name, format=self.format, array=a2)
2515 # return self.col2
2521 # return self.col2
2516
2522
2517 def writeHeader(self,):
2523 def writeHeader(self,):
2518 pass
2524 pass
2519
2525
2520 def writeData(self,name,format,data):
2526 def writeData(self,name,format,data):
2521 self.name=name
2527 self.name=name
2522 self.format=format
2528 self.format=format
2523 self.data=data
2529 self.data=data
2524 a2=numpy.array([self.data],dtype=numpy.float32)
2530 a2=numpy.array([self.data],dtype=numpy.float32)
2525 self.col2 = pyfits.Column(name=self.name, format=self.format, array=a2)
2531 self.col2 = pyfits.Column(name=self.name, format=self.format, array=a2)
2526 return self.col2
2532 return self.col2
2527
2533
2528 def cFImage(self,n):
2534 def cFImage(self,n):
2529 self.hdu= pyfits.PrimaryHDU(n)
2535 self.hdu= pyfits.PrimaryHDU(n)
2530 return self.hdu
2536 return self.hdu
2531
2537
2532 def Ctable(self,col1,col2,col3,col4,col5,col6,col7,col8,col9):
2538 def Ctable(self,col1,col2,col3,col4,col5,col6,col7,col8,col9):
2533 self.cols=pyfits.ColDefs( [col1,col2,col3,col4,col5,col6,col7,col8,col9])
2539 self.cols=pyfits.ColDefs( [col1,col2,col3,col4,col5,col6,col7,col8,col9])
2534 self.tbhdu = pyfits.new_table(self.cols)
2540 self.tbhdu = pyfits.new_table(self.cols)
2535 return self.tbhdu
2541 return self.tbhdu
2536
2542
2537 def CFile(self,hdu,tbhdu):
2543 def CFile(self,hdu,tbhdu):
2538 self.thdulist=pyfits.HDUList([hdu,tbhdu])
2544 self.thdulist=pyfits.HDUList([hdu,tbhdu])
2539
2545
2540 def wFile(self,filename):
2546 def wFile(self,filename):
2541 self.thdulist.writeto(filename) No newline at end of file
2547 self.thdulist.writeto(filename)
@@ -1,818 +1,818
1 import numpy
1 import numpy
2 import time, datetime
2 import time, datetime
3 from graphics.figure import *
3 from graphics.figure import *
4
4
5 class CrossSpectraPlot(Figure):
5 class CrossSpectraPlot(Figure):
6
6
7 __isConfig = None
7 __isConfig = None
8 __nsubplots = None
8 __nsubplots = None
9
9
10 WIDTHPROF = None
10 WIDTHPROF = None
11 HEIGHTPROF = None
11 HEIGHTPROF = None
12 PREFIX = 'cspc'
12 PREFIX = 'cspc'
13
13
14 def __init__(self):
14 def __init__(self):
15
15
16 self.__isConfig = False
16 self.__isConfig = False
17 self.__nsubplots = 4
17 self.__nsubplots = 4
18
18
19 self.WIDTH = 300
19 self.WIDTH = 300
20 self.HEIGHT = 400
20 self.HEIGHT = 400
21 self.WIDTHPROF = 0
21 self.WIDTHPROF = 0
22 self.HEIGHTPROF = 0
22 self.HEIGHTPROF = 0
23
23
24 def getSubplots(self):
24 def getSubplots(self):
25
25
26 ncol = 4
26 ncol = 4
27 nrow = self.nplots
27 nrow = self.nplots
28
28
29 return nrow, ncol
29 return nrow, ncol
30
30
31 def setup(self, idfigure, nplots, wintitle, showprofile=True):
31 def setup(self, idfigure, nplots, wintitle, showprofile=True):
32
32
33 self.__showprofile = showprofile
33 self.__showprofile = showprofile
34 self.nplots = nplots
34 self.nplots = nplots
35
35
36 ncolspan = 1
36 ncolspan = 1
37 colspan = 1
37 colspan = 1
38
38
39 self.createFigure(idfigure = idfigure,
39 self.createFigure(idfigure = idfigure,
40 wintitle = wintitle,
40 wintitle = wintitle,
41 widthplot = self.WIDTH + self.WIDTHPROF,
41 widthplot = self.WIDTH + self.WIDTHPROF,
42 heightplot = self.HEIGHT + self.HEIGHTPROF)
42 heightplot = self.HEIGHT + self.HEIGHTPROF)
43
43
44 nrow, ncol = self.getSubplots()
44 nrow, ncol = self.getSubplots()
45
45
46 counter = 0
46 counter = 0
47 for y in range(nrow):
47 for y in range(nrow):
48 for x in range(ncol):
48 for x in range(ncol):
49 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
49 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
50
50
51 counter += 1
51 counter += 1
52
52
53 def run(self, dataOut, idfigure, wintitle="", pairsList=None, showprofile='True',
53 def run(self, dataOut, idfigure, wintitle="", pairsList=None, showprofile='True',
54 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
54 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
55 save=False, figpath='./', figfile=None):
55 save=False, figpath='./', figfile=None):
56
56
57 """
57 """
58
58
59 Input:
59 Input:
60 dataOut :
60 dataOut :
61 idfigure :
61 idfigure :
62 wintitle :
62 wintitle :
63 channelList :
63 channelList :
64 showProfile :
64 showProfile :
65 xmin : None,
65 xmin : None,
66 xmax : None,
66 xmax : None,
67 ymin : None,
67 ymin : None,
68 ymax : None,
68 ymax : None,
69 zmin : None,
69 zmin : None,
70 zmax : None
70 zmax : None
71 """
71 """
72
72
73 if pairsList == None:
73 if pairsList == None:
74 pairsIndexList = dataOut.pairsIndexList
74 pairsIndexList = dataOut.pairsIndexList
75 else:
75 else:
76 pairsIndexList = []
76 pairsIndexList = []
77 for pair in pairsList:
77 for pair in pairsList:
78 if pair not in dataOut.pairsList:
78 if pair not in dataOut.pairsList:
79 raise ValueError, "Pair %s is not in dataOut.pairsList" %(pair)
79 raise ValueError, "Pair %s is not in dataOut.pairsList" %(pair)
80 pairsIndexList.append(dataOut.pairsList.index(pair))
80 pairsIndexList.append(dataOut.pairsList.index(pair))
81
81
82 if pairsIndexList == []:
82 if pairsIndexList == []:
83 return
83 return
84
84
85 if len(pairsIndexList) > 4:
85 if len(pairsIndexList) > 4:
86 pairsIndexList = pairsIndexList[0:4]
86 pairsIndexList = pairsIndexList[0:4]
87
87
88 x = dataOut.getFreqRange(1)
88 x = dataOut.getFreqRange(1)
89 y = dataOut.getHeiRange()
89 y = dataOut.getHeiRange()
90 z = 10.*numpy.log10(dataOut.data_spc[:,:,:])
90 z = 10.*numpy.log10(dataOut.data_spc[:,:,:])
91 avg = numpy.average(numpy.abs(z), axis=1)
91 avg = numpy.average(numpy.abs(z), axis=1)
92
92
93 noise = dataOut.getNoise()
93 noise = dataOut.getNoise()
94
94
95 if not self.__isConfig:
95 if not self.__isConfig:
96
96
97 nplots = len(pairsIndexList)
97 nplots = len(pairsIndexList)
98
98
99 self.setup(idfigure=idfigure,
99 self.setup(idfigure=idfigure,
100 nplots=nplots,
100 nplots=nplots,
101 wintitle=wintitle,
101 wintitle=wintitle,
102 showprofile=showprofile)
102 showprofile=showprofile)
103
103
104 if xmin == None: xmin = numpy.nanmin(x)
104 if xmin == None: xmin = numpy.nanmin(x)
105 if xmax == None: xmax = numpy.nanmax(x)
105 if xmax == None: xmax = numpy.nanmax(x)
106 if ymin == None: ymin = numpy.nanmin(y)
106 if ymin == None: ymin = numpy.nanmin(y)
107 if ymax == None: ymax = numpy.nanmax(y)
107 if ymax == None: ymax = numpy.nanmax(y)
108 if zmin == None: zmin = numpy.nanmin(avg)*0.9
108 if zmin == None: zmin = numpy.nanmin(avg)*0.9
109 if zmax == None: zmax = numpy.nanmax(avg)*0.9
109 if zmax == None: zmax = numpy.nanmax(avg)*0.9
110
110
111 self.__isConfig = True
111 self.__isConfig = True
112
112
113 thisDatetime = dataOut.datatime
113 thisDatetime = dataOut.datatime
114 title = "Cross-Spectra: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
114 title = "Cross-Spectra: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
115 xlabel = "Velocity (m/s)"
115 xlabel = "Velocity (m/s)"
116 ylabel = "Range (Km)"
116 ylabel = "Range (Km)"
117
117
118 self.setWinTitle(title)
118 self.setWinTitle(title)
119
119
120 for i in range(self.nplots):
120 for i in range(self.nplots):
121 pair = dataOut.pairsList[pairsIndexList[i]]
121 pair = dataOut.pairsList[pairsIndexList[i]]
122
122
123 title = "Channel %d: %4.2fdB" %(pair[0], noise[pair[0]])
123 title = "Channel %d: %4.2fdB" %(pair[0], noise[pair[0]])
124 z = 10.*numpy.log10(dataOut.data_spc[pair[0],:,:])
124 z = 10.*numpy.log10(dataOut.data_spc[pair[0],:,:])
125 axes0 = self.axesList[i*self.__nsubplots]
125 axes0 = self.axesList[i*self.__nsubplots]
126 axes0.pcolor(x, y, z,
126 axes0.pcolor(x, y, z,
127 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
127 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
128 xlabel=xlabel, ylabel=ylabel, title=title,
128 xlabel=xlabel, ylabel=ylabel, title=title,
129 ticksize=9, cblabel='')
129 ticksize=9, cblabel='')
130
130
131 title = "Channel %d: %4.2fdB" %(pair[1], noise[pair[1]])
131 title = "Channel %d: %4.2fdB" %(pair[1], noise[pair[1]])
132 z = 10.*numpy.log10(dataOut.data_spc[pair[1],:,:])
132 z = 10.*numpy.log10(dataOut.data_spc[pair[1],:,:])
133 axes0 = self.axesList[i*self.__nsubplots+1]
133 axes0 = self.axesList[i*self.__nsubplots+1]
134 axes0.pcolor(x, y, z,
134 axes0.pcolor(x, y, z,
135 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
135 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
136 xlabel=xlabel, ylabel=ylabel, title=title,
136 xlabel=xlabel, ylabel=ylabel, title=title,
137 ticksize=9, cblabel='')
137 ticksize=9, cblabel='')
138
138
139 coherenceComplex = dataOut.data_cspc[pairsIndexList[i],:,:]/numpy.sqrt(dataOut.data_spc[pair[0],:,:]*dataOut.data_spc[pair[1],:,:])
139 coherenceComplex = dataOut.data_cspc[pairsIndexList[i],:,:]/numpy.sqrt(dataOut.data_spc[pair[0],:,:]*dataOut.data_spc[pair[1],:,:])
140 coherence = numpy.abs(coherenceComplex)
140 coherence = numpy.abs(coherenceComplex)
141 phase = numpy.arctan(-1*coherenceComplex.imag/coherenceComplex.real)*180/numpy.pi
141 phase = numpy.arctan(-1*coherenceComplex.imag/coherenceComplex.real)*180/numpy.pi
142
142
143
143
144 title = "Coherence %d%d" %(pair[0], pair[1])
144 title = "Coherence %d%d" %(pair[0], pair[1])
145 axes0 = self.axesList[i*self.__nsubplots+2]
145 axes0 = self.axesList[i*self.__nsubplots+2]
146 axes0.pcolor(x, y, coherence,
146 axes0.pcolor(x, y, coherence,
147 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=0, zmax=1,
147 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=0, zmax=1,
148 xlabel=xlabel, ylabel=ylabel, title=title,
148 xlabel=xlabel, ylabel=ylabel, title=title,
149 ticksize=9, cblabel='')
149 ticksize=9, cblabel='')
150
150
151 title = "Phase %d%d" %(pair[0], pair[1])
151 title = "Phase %d%d" %(pair[0], pair[1])
152 axes0 = self.axesList[i*self.__nsubplots+3]
152 axes0 = self.axesList[i*self.__nsubplots+3]
153 axes0.pcolor(x, y, phase,
153 axes0.pcolor(x, y, phase,
154 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=-180, zmax=180,
154 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=-180, zmax=180,
155 xlabel=xlabel, ylabel=ylabel, title=title,
155 xlabel=xlabel, ylabel=ylabel, title=title,
156 ticksize=9, cblabel='', colormap='RdBu')
156 ticksize=9, cblabel='', colormap='RdBu')
157
157
158
158
159
159
160 self.draw()
160 self.draw()
161
161
162 if save:
162 if save:
163 date = thisDatetime.strftime("%Y%m%d")
163 date = thisDatetime.strftime("%Y%m%d")
164 if figfile == None:
164 if figfile == None:
165 figfile = self.getFilename(name = date)
165 figfile = self.getFilename(name = date)
166
166
167 self.saveFigure(figpath, figfile)
167 self.saveFigure(figpath, figfile)
168
168
169
169
170 class RTIPlot(Figure):
170 class RTIPlot(Figure):
171
171
172 __isConfig = None
172 __isConfig = None
173 __nsubplots = None
173 __nsubplots = None
174
174
175 WIDTHPROF = None
175 WIDTHPROF = None
176 HEIGHTPROF = None
176 HEIGHTPROF = None
177 PREFIX = 'rti'
177 PREFIX = 'rti'
178
178
179 def __init__(self):
179 def __init__(self):
180
180
181 self.__timerange = 24*60*60
181 self.timerange = 24*60*60
182 self.__isConfig = False
182 self.__isConfig = False
183 self.__nsubplots = 1
183 self.__nsubplots = 1
184
184
185 self.WIDTH = 800
185 self.WIDTH = 800
186 self.HEIGHT = 200
186 self.HEIGHT = 200
187 self.WIDTHPROF = 120
187 self.WIDTHPROF = 120
188 self.HEIGHTPROF = 0
188 self.HEIGHTPROF = 0
189
189
190 def getSubplots(self):
190 def getSubplots(self):
191
191
192 ncol = 1
192 ncol = 1
193 nrow = self.nplots
193 nrow = self.nplots
194
194
195 return nrow, ncol
195 return nrow, ncol
196
196
197 def setup(self, idfigure, nplots, wintitle, showprofile=True):
197 def setup(self, idfigure, nplots, wintitle, showprofile=True):
198
198
199 self.__showprofile = showprofile
199 self.__showprofile = showprofile
200 self.nplots = nplots
200 self.nplots = nplots
201
201
202 ncolspan = 1
202 ncolspan = 1
203 colspan = 1
203 colspan = 1
204 if showprofile:
204 if showprofile:
205 ncolspan = 7
205 ncolspan = 7
206 colspan = 6
206 colspan = 6
207 self.__nsubplots = 2
207 self.__nsubplots = 2
208
208
209 self.createFigure(idfigure = idfigure,
209 self.createFigure(idfigure = idfigure,
210 wintitle = wintitle,
210 wintitle = wintitle,
211 widthplot = self.WIDTH + self.WIDTHPROF,
211 widthplot = self.WIDTH + self.WIDTHPROF,
212 heightplot = self.HEIGHT + self.HEIGHTPROF)
212 heightplot = self.HEIGHT + self.HEIGHTPROF)
213
213
214 nrow, ncol = self.getSubplots()
214 nrow, ncol = self.getSubplots()
215
215
216 counter = 0
216 counter = 0
217 for y in range(nrow):
217 for y in range(nrow):
218 for x in range(ncol):
218 for x in range(ncol):
219
219
220 if counter >= self.nplots:
220 if counter >= self.nplots:
221 break
221 break
222
222
223 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
223 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
224
224
225 if showprofile:
225 if showprofile:
226 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1)
226 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1)
227
227
228 counter += 1
228 counter += 1
229
229
230 def run(self, dataOut, idfigure, wintitle="", channelList=None, showprofile='True',
230 def run(self, dataOut, idfigure, wintitle="", channelList=None, showprofile='True',
231 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
231 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
232 timerange=None,
232 timerange=None,
233 save=False, figpath='./', figfile=None):
233 save=False, figpath='./', figfile=None):
234
234
235 """
235 """
236
236
237 Input:
237 Input:
238 dataOut :
238 dataOut :
239 idfigure :
239 idfigure :
240 wintitle :
240 wintitle :
241 channelList :
241 channelList :
242 showProfile :
242 showProfile :
243 xmin : None,
243 xmin : None,
244 xmax : None,
244 xmax : None,
245 ymin : None,
245 ymin : None,
246 ymax : None,
246 ymax : None,
247 zmin : None,
247 zmin : None,
248 zmax : None
248 zmax : None
249 """
249 """
250
250
251 if channelList == None:
251 if channelList == None:
252 channelIndexList = dataOut.channelIndexList
252 channelIndexList = dataOut.channelIndexList
253 else:
253 else:
254 channelIndexList = []
254 channelIndexList = []
255 for channel in channelList:
255 for channel in channelList:
256 if channel not in dataOut.channelList:
256 if channel not in dataOut.channelList:
257 raise ValueError, "Channel %d is not in dataOut.channelList"
257 raise ValueError, "Channel %d is not in dataOut.channelList"
258 channelIndexList.append(dataOut.channelList.index(channel))
258 channelIndexList.append(dataOut.channelList.index(channel))
259
259
260 if timerange != None:
260 if timerange != None:
261 self.__timerange = timerange
261 self.timerange = timerange
262
262
263 tmin = None
263 tmin = None
264 tmax = None
264 tmax = None
265 x = dataOut.getTimeRange()
265 x = dataOut.getTimeRange()
266 y = dataOut.getHeiRange()
266 y = dataOut.getHeiRange()
267 z = 10.*numpy.log10(dataOut.data_spc[channelIndexList,:,:])
267 z = 10.*numpy.log10(dataOut.data_spc[channelIndexList,:,:])
268 avg = numpy.average(z, axis=1)
268 avg = numpy.average(z, axis=1)
269
269
270 noise = dataOut.getNoise()
270 noise = dataOut.getNoise()
271
271
272 if not self.__isConfig:
272 if not self.__isConfig:
273
273
274 nplots = len(channelIndexList)
274 nplots = len(channelIndexList)
275
275
276 self.setup(idfigure=idfigure,
276 self.setup(idfigure=idfigure,
277 nplots=nplots,
277 nplots=nplots,
278 wintitle=wintitle,
278 wintitle=wintitle,
279 showprofile=showprofile)
279 showprofile=showprofile)
280
280
281 tmin, tmax = self.getTimeLim(x, xmin, xmax)
281 tmin, tmax = self.getTimeLim(x, xmin, xmax)
282 if ymin == None: ymin = numpy.nanmin(y)
282 if ymin == None: ymin = numpy.nanmin(y)
283 if ymax == None: ymax = numpy.nanmax(y)
283 if ymax == None: ymax = numpy.nanmax(y)
284 if zmin == None: zmin = numpy.nanmin(avg)*0.9
284 if zmin == None: zmin = numpy.nanmin(avg)*0.9
285 if zmax == None: zmax = numpy.nanmax(avg)*0.9
285 if zmax == None: zmax = numpy.nanmax(avg)*0.9
286
286
287 self.__isConfig = True
287 self.__isConfig = True
288
288
289 thisDatetime = dataOut.datatime
289 thisDatetime = dataOut.datatime
290 title = "RTI: %s" %(thisDatetime.strftime("%d-%b-%Y"))
290 title = "RTI: %s" %(thisDatetime.strftime("%d-%b-%Y"))
291 xlabel = "Velocity (m/s)"
291 xlabel = "Velocity (m/s)"
292 ylabel = "Range (Km)"
292 ylabel = "Range (Km)"
293
293
294 self.setWinTitle(title)
294 self.setWinTitle(title)
295
295
296 for i in range(self.nplots):
296 for i in range(self.nplots):
297 title = "Channel %d: %s" %(dataOut.channelList[i], thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
297 title = "Channel %d: %s" %(dataOut.channelList[i], thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
298 axes = self.axesList[i*self.__nsubplots]
298 axes = self.axesList[i*self.__nsubplots]
299 z = avg[i].reshape((1,-1))
299 z = avg[i].reshape((1,-1))
300 axes.pcolor(x, y, z,
300 axes.pcolor(x, y, z,
301 xmin=tmin, xmax=tmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
301 xmin=tmin, xmax=tmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
302 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
302 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
303 ticksize=9, cblabel='', cbsize="1%")
303 ticksize=9, cblabel='', cbsize="1%")
304
304
305 if self.__showprofile:
305 if self.__showprofile:
306 axes = self.axesList[i*self.__nsubplots +1]
306 axes = self.axesList[i*self.__nsubplots +1]
307 axes.pline(avg[i], y,
307 axes.pline(avg[i], y,
308 xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax,
308 xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax,
309 xlabel='dB', ylabel='', title='',
309 xlabel='dB', ylabel='', title='',
310 ytick_visible=False,
310 ytick_visible=False,
311 grid='x')
311 grid='x')
312
312
313 self.draw()
313 self.draw()
314
314
315 if save:
315 if save:
316 date = thisDatetime.strftime("%Y%m%d")
316 date = thisDatetime.strftime("%Y%m%d")
317 if figfile == None:
317 if figfile == None:
318 figfile = self.getFilename(name = date)
318 figfile = self.getFilename(name = date)
319
319
320 self.saveFigure(figpath, figfile)
320 self.saveFigure(figpath, figfile)
321
321
322 if x[1] + (x[1]-x[0]) >= self.axesList[0].xmax:
322 if x[1] + (x[1]-x[0]) >= self.axesList[0].xmax:
323 self.__isConfig = False
323 self.__isConfig = False
324
324
325 class SpectraPlot(Figure):
325 class SpectraPlot(Figure):
326
326
327 __isConfig = None
327 __isConfig = None
328 __nsubplots = None
328 __nsubplots = None
329
329
330 WIDTHPROF = None
330 WIDTHPROF = None
331 HEIGHTPROF = None
331 HEIGHTPROF = None
332 PREFIX = 'spc'
332 PREFIX = 'spc'
333
333
334 def __init__(self):
334 def __init__(self):
335
335
336 self.__isConfig = False
336 self.__isConfig = False
337 self.__nsubplots = 1
337 self.__nsubplots = 1
338
338
339 self.WIDTH = 300
339 self.WIDTH = 300
340 self.HEIGHT = 400
340 self.HEIGHT = 400
341 self.WIDTHPROF = 120
341 self.WIDTHPROF = 120
342 self.HEIGHTPROF = 0
342 self.HEIGHTPROF = 0
343
343
344 def getSubplots(self):
344 def getSubplots(self):
345
345
346 ncol = int(numpy.sqrt(self.nplots)+0.9)
346 ncol = int(numpy.sqrt(self.nplots)+0.9)
347 nrow = int(self.nplots*1./ncol + 0.9)
347 nrow = int(self.nplots*1./ncol + 0.9)
348
348
349 return nrow, ncol
349 return nrow, ncol
350
350
351 def setup(self, idfigure, nplots, wintitle, showprofile=True):
351 def setup(self, idfigure, nplots, wintitle, showprofile=True):
352
352
353 self.__showprofile = showprofile
353 self.__showprofile = showprofile
354 self.nplots = nplots
354 self.nplots = nplots
355
355
356 ncolspan = 1
356 ncolspan = 1
357 colspan = 1
357 colspan = 1
358 if showprofile:
358 if showprofile:
359 ncolspan = 3
359 ncolspan = 3
360 colspan = 2
360 colspan = 2
361 self.__nsubplots = 2
361 self.__nsubplots = 2
362
362
363 self.createFigure(idfigure = idfigure,
363 self.createFigure(idfigure = idfigure,
364 wintitle = wintitle,
364 wintitle = wintitle,
365 widthplot = self.WIDTH + self.WIDTHPROF,
365 widthplot = self.WIDTH + self.WIDTHPROF,
366 heightplot = self.HEIGHT + self.HEIGHTPROF)
366 heightplot = self.HEIGHT + self.HEIGHTPROF)
367
367
368 nrow, ncol = self.getSubplots()
368 nrow, ncol = self.getSubplots()
369
369
370 counter = 0
370 counter = 0
371 for y in range(nrow):
371 for y in range(nrow):
372 for x in range(ncol):
372 for x in range(ncol):
373
373
374 if counter >= self.nplots:
374 if counter >= self.nplots:
375 break
375 break
376
376
377 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
377 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
378
378
379 if showprofile:
379 if showprofile:
380 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1)
380 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1)
381
381
382 counter += 1
382 counter += 1
383
383
384 def run(self, dataOut, idfigure, wintitle="", channelList=None, showprofile='True',
384 def run(self, dataOut, idfigure, wintitle="", channelList=None, showprofile='True',
385 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
385 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
386 save=False, figpath='./', figfile=None):
386 save=False, figpath='./', figfile=None):
387
387
388 """
388 """
389
389
390 Input:
390 Input:
391 dataOut :
391 dataOut :
392 idfigure :
392 idfigure :
393 wintitle :
393 wintitle :
394 channelList :
394 channelList :
395 showProfile :
395 showProfile :
396 xmin : None,
396 xmin : None,
397 xmax : None,
397 xmax : None,
398 ymin : None,
398 ymin : None,
399 ymax : None,
399 ymax : None,
400 zmin : None,
400 zmin : None,
401 zmax : None
401 zmax : None
402 """
402 """
403
403
404 if channelList == None:
404 if channelList == None:
405 channelIndexList = dataOut.channelIndexList
405 channelIndexList = dataOut.channelIndexList
406 else:
406 else:
407 channelIndexList = []
407 channelIndexList = []
408 for channel in channelList:
408 for channel in channelList:
409 if channel not in dataOut.channelList:
409 if channel not in dataOut.channelList:
410 raise ValueError, "Channel %d is not in dataOut.channelList"
410 raise ValueError, "Channel %d is not in dataOut.channelList"
411 channelIndexList.append(dataOut.channelList.index(channel))
411 channelIndexList.append(dataOut.channelList.index(channel))
412
412
413 x = dataOut.getVelRange(1)
413 x = dataOut.getVelRange(1)
414 y = dataOut.getHeiRange()
414 y = dataOut.getHeiRange()
415 z = 10.*numpy.log10(dataOut.data_spc[channelIndexList,:,:])
415 z = 10.*numpy.log10(dataOut.data_spc[channelIndexList,:,:])
416 avg = numpy.average(z, axis=1)
416 avg = numpy.average(z, axis=1)
417
417
418 noise = dataOut.getNoise()
418 noise = dataOut.getNoise()
419
419
420 if not self.__isConfig:
420 if not self.__isConfig:
421
421
422 nplots = len(channelIndexList)
422 nplots = len(channelIndexList)
423
423
424 self.setup(idfigure=idfigure,
424 self.setup(idfigure=idfigure,
425 nplots=nplots,
425 nplots=nplots,
426 wintitle=wintitle,
426 wintitle=wintitle,
427 showprofile=showprofile)
427 showprofile=showprofile)
428
428
429 if xmin == None: xmin = numpy.nanmin(x)
429 if xmin == None: xmin = numpy.nanmin(x)
430 if xmax == None: xmax = numpy.nanmax(x)
430 if xmax == None: xmax = numpy.nanmax(x)
431 if ymin == None: ymin = numpy.nanmin(y)
431 if ymin == None: ymin = numpy.nanmin(y)
432 if ymax == None: ymax = numpy.nanmax(y)
432 if ymax == None: ymax = numpy.nanmax(y)
433 if zmin == None: zmin = numpy.nanmin(avg)*0.9
433 if zmin == None: zmin = numpy.nanmin(avg)*0.9
434 if zmax == None: zmax = numpy.nanmax(avg)*0.9
434 if zmax == None: zmax = numpy.nanmax(avg)*0.9
435
435
436 self.__isConfig = True
436 self.__isConfig = True
437
437
438 thisDatetime = dataOut.datatime
438 thisDatetime = dataOut.datatime
439 title = "Spectra: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
439 title = "Spectra: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
440 xlabel = "Velocity (m/s)"
440 xlabel = "Velocity (m/s)"
441 ylabel = "Range (Km)"
441 ylabel = "Range (Km)"
442
442
443 self.setWinTitle(title)
443 self.setWinTitle(title)
444
444
445 for i in range(self.nplots):
445 for i in range(self.nplots):
446 title = "Channel %d: %4.2fdB" %(dataOut.channelList[i], noise[i])
446 title = "Channel %d: %4.2fdB" %(dataOut.channelList[i], noise[i])
447 axes = self.axesList[i*self.__nsubplots]
447 axes = self.axesList[i*self.__nsubplots]
448 axes.pcolor(x, y, z[i,:,:],
448 axes.pcolor(x, y, z[i,:,:],
449 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
449 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
450 xlabel=xlabel, ylabel=ylabel, title=title,
450 xlabel=xlabel, ylabel=ylabel, title=title,
451 ticksize=9, cblabel='')
451 ticksize=9, cblabel='')
452
452
453 if self.__showprofile:
453 if self.__showprofile:
454 axes = self.axesList[i*self.__nsubplots +1]
454 axes = self.axesList[i*self.__nsubplots +1]
455 axes.pline(avg[i], y,
455 axes.pline(avg[i], y,
456 xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax,
456 xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax,
457 xlabel='dB', ylabel='', title='',
457 xlabel='dB', ylabel='', title='',
458 ytick_visible=False,
458 ytick_visible=False,
459 grid='x')
459 grid='x')
460
460
461 self.draw()
461 self.draw()
462
462
463 if save:
463 if save:
464 date = thisDatetime.strftime("%Y%m%d")
464 date = thisDatetime.strftime("%Y%m%d")
465 if figfile == None:
465 if figfile == None:
466 figfile = self.getFilename(name = date)
466 figfile = self.getFilename(name = date)
467
467
468 self.saveFigure(figpath, figfile)
468 self.saveFigure(figpath, figfile)
469
469
470 class Scope(Figure):
470 class Scope(Figure):
471
471
472 __isConfig = None
472 __isConfig = None
473
473
474 def __init__(self):
474 def __init__(self):
475
475
476 self.__isConfig = False
476 self.__isConfig = False
477 self.WIDTH = 600
477 self.WIDTH = 600
478 self.HEIGHT = 200
478 self.HEIGHT = 200
479
479
480 def getSubplots(self):
480 def getSubplots(self):
481
481
482 nrow = self.nplots
482 nrow = self.nplots
483 ncol = 3
483 ncol = 3
484 return nrow, ncol
484 return nrow, ncol
485
485
486 def setup(self, idfigure, nplots, wintitle):
486 def setup(self, idfigure, nplots, wintitle):
487
487
488 self.createFigure(idfigure, wintitle)
488 self.createFigure(idfigure, wintitle)
489
489
490 nrow,ncol = self.getSubplots()
490 nrow,ncol = self.getSubplots()
491 colspan = 3
491 colspan = 3
492 rowspan = 1
492 rowspan = 1
493
493
494 for i in range(nplots):
494 for i in range(nplots):
495 self.addAxes(nrow, ncol, i, 0, colspan, rowspan)
495 self.addAxes(nrow, ncol, i, 0, colspan, rowspan)
496
496
497 self.nplots = nplots
497 self.nplots = nplots
498
498
499 def run(self, dataOut, idfigure, wintitle="", channelList=None,
499 def run(self, dataOut, idfigure, wintitle="", channelList=None,
500 xmin=None, xmax=None, ymin=None, ymax=None, save=False, filename=None):
500 xmin=None, xmax=None, ymin=None, ymax=None, save=False, filename=None):
501
501
502 """
502 """
503
503
504 Input:
504 Input:
505 dataOut :
505 dataOut :
506 idfigure :
506 idfigure :
507 wintitle :
507 wintitle :
508 channelList :
508 channelList :
509 xmin : None,
509 xmin : None,
510 xmax : None,
510 xmax : None,
511 ymin : None,
511 ymin : None,
512 ymax : None,
512 ymax : None,
513 """
513 """
514
514
515 if channelList == None:
515 if channelList == None:
516 channelIndexList = dataOut.channelIndexList
516 channelIndexList = dataOut.channelIndexList
517 else:
517 else:
518 channelIndexList = []
518 channelIndexList = []
519 for channel in channelList:
519 for channel in channelList:
520 if channel not in dataOut.channelList:
520 if channel not in dataOut.channelList:
521 raise ValueError, "Channel %d is not in dataOut.channelList"
521 raise ValueError, "Channel %d is not in dataOut.channelList"
522 channelIndexList.append(dataOut.channelList.index(channel))
522 channelIndexList.append(dataOut.channelList.index(channel))
523
523
524 x = dataOut.heightList
524 x = dataOut.heightList
525 y = dataOut.data[channelList,:] * numpy.conjugate(dataOut.data[channelList,:])
525 y = dataOut.data[channelList,:] * numpy.conjugate(dataOut.data[channelList,:])
526 y = y.real
526 y = y.real
527
527
528 noise = dataOut.getNoise()
528 noise = dataOut.getNoise()
529
529
530 if not self.__isConfig:
530 if not self.__isConfig:
531 nplots = len(channelList)
531 nplots = len(channelList)
532
532
533 self.setup(idfigure=idfigure,
533 self.setup(idfigure=idfigure,
534 nplots=nplots,
534 nplots=nplots,
535 wintitle=wintitle)
535 wintitle=wintitle)
536
536
537 if xmin == None: xmin = numpy.nanmin(x)
537 if xmin == None: xmin = numpy.nanmin(x)
538 if xmax == None: xmax = numpy.nanmax(x)
538 if xmax == None: xmax = numpy.nanmax(x)
539 if ymin == None: ymin = numpy.nanmin(y)
539 if ymin == None: ymin = numpy.nanmin(y)
540 if ymax == None: ymax = numpy.nanmax(y)
540 if ymax == None: ymax = numpy.nanmax(y)
541
541
542 self.__isConfig = True
542 self.__isConfig = True
543
543
544
544
545 thisDatetime = dataOut.datatime
545 thisDatetime = dataOut.datatime
546 title = "Scope: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
546 title = "Scope: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
547 xlabel = "Range (Km)"
547 xlabel = "Range (Km)"
548 ylabel = "Intensity"
548 ylabel = "Intensity"
549
549
550 self.setWinTitle(title)
550 self.setWinTitle(title)
551
551
552 for i in range(len(self.axesList)):
552 for i in range(len(self.axesList)):
553 title = "Channel %d: %4.2fdB" %(i, noise[i])
553 title = "Channel %d: %4.2fdB" %(i, noise[i])
554 axes = self.axesList[i]
554 axes = self.axesList[i]
555 ychannel = y[i,:]
555 ychannel = y[i,:]
556 axes.pline(x, ychannel,
556 axes.pline(x, ychannel,
557 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax,
557 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax,
558 xlabel=xlabel, ylabel=ylabel, title=title)
558 xlabel=xlabel, ylabel=ylabel, title=title)
559
559
560 self.draw()
560 self.draw()
561
561
562 if save:
562 if save:
563 self.saveFigure(filename)
563 self.saveFigure(filename)
564
564
565 class ProfilePlot(Figure):
565 class ProfilePlot(Figure):
566 __isConfig = None
566 __isConfig = None
567 __nsubplots = None
567 __nsubplots = None
568
568
569 WIDTHPROF = None
569 WIDTHPROF = None
570 HEIGHTPROF = None
570 HEIGHTPROF = None
571 PREFIX = 'spcprofile'
571 PREFIX = 'spcprofile'
572
572
573 def __init__(self):
573 def __init__(self):
574 self.__isConfig = False
574 self.__isConfig = False
575 self.__nsubplots = 1
575 self.__nsubplots = 1
576
576
577 self.WIDTH = 300
577 self.WIDTH = 300
578 self.HEIGHT = 500
578 self.HEIGHT = 500
579
579
580 def getSubplots(self):
580 def getSubplots(self):
581 ncol = 1
581 ncol = 1
582 nrow = 1
582 nrow = 1
583
583
584 return nrow, ncol
584 return nrow, ncol
585
585
586 def setup(self, idfigure, nplots, wintitle):
586 def setup(self, idfigure, nplots, wintitle):
587
587
588 self.nplots = nplots
588 self.nplots = nplots
589
589
590 ncolspan = 1
590 ncolspan = 1
591 colspan = 1
591 colspan = 1
592
592
593 self.createFigure(idfigure = idfigure,
593 self.createFigure(idfigure = idfigure,
594 wintitle = wintitle,
594 wintitle = wintitle,
595 widthplot = self.WIDTH,
595 widthplot = self.WIDTH,
596 heightplot = self.HEIGHT)
596 heightplot = self.HEIGHT)
597
597
598 nrow, ncol = self.getSubplots()
598 nrow, ncol = self.getSubplots()
599
599
600 counter = 0
600 counter = 0
601 for y in range(nrow):
601 for y in range(nrow):
602 for x in range(ncol):
602 for x in range(ncol):
603 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
603 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
604
604
605 def run(self, dataOut, idfigure, wintitle="", channelList=None,
605 def run(self, dataOut, idfigure, wintitle="", channelList=None,
606 xmin=None, xmax=None, ymin=None, ymax=None,
606 xmin=None, xmax=None, ymin=None, ymax=None,
607 save=False, figpath='./', figfile=None):
607 save=False, figpath='./', figfile=None):
608
608
609 if channelList == None:
609 if channelList == None:
610 channelIndexList = dataOut.channelIndexList
610 channelIndexList = dataOut.channelIndexList
611 channelList = dataOut.channelList
611 channelList = dataOut.channelList
612 else:
612 else:
613 channelIndexList = []
613 channelIndexList = []
614 for channel in channelList:
614 for channel in channelList:
615 if channel not in dataOut.channelList:
615 if channel not in dataOut.channelList:
616 raise ValueError, "Channel %d is not in dataOut.channelList"
616 raise ValueError, "Channel %d is not in dataOut.channelList"
617 channelIndexList.append(dataOut.channelList.index(channel))
617 channelIndexList.append(dataOut.channelList.index(channel))
618
618
619
619
620 y = dataOut.getHeiRange()
620 y = dataOut.getHeiRange()
621 x = 10.*numpy.log10(dataOut.data_spc[channelIndexList,:,:])
621 x = 10.*numpy.log10(dataOut.data_spc[channelIndexList,:,:])
622 avg = numpy.average(x, axis=1)
622 avg = numpy.average(x, axis=1)
623
623
624
624
625 if not self.__isConfig:
625 if not self.__isConfig:
626
626
627 nplots = 1
627 nplots = 1
628
628
629 self.setup(idfigure=idfigure,
629 self.setup(idfigure=idfigure,
630 nplots=nplots,
630 nplots=nplots,
631 wintitle=wintitle)
631 wintitle=wintitle)
632
632
633 if ymin == None: ymin = numpy.nanmin(y)
633 if ymin == None: ymin = numpy.nanmin(y)
634 if ymax == None: ymax = numpy.nanmax(y)
634 if ymax == None: ymax = numpy.nanmax(y)
635 if xmin == None: xmin = numpy.nanmin(avg)*0.9
635 if xmin == None: xmin = numpy.nanmin(avg)*0.9
636 if xmax == None: xmax = numpy.nanmax(avg)*0.9
636 if xmax == None: xmax = numpy.nanmax(avg)*0.9
637
637
638 self.__isConfig = True
638 self.__isConfig = True
639
639
640 thisDatetime = dataOut.datatime
640 thisDatetime = dataOut.datatime
641 title = "Power Profile"
641 title = "Power Profile"
642 xlabel = "dB"
642 xlabel = "dB"
643 ylabel = "Range (Km)"
643 ylabel = "Range (Km)"
644
644
645 self.setWinTitle(title)
645 self.setWinTitle(title)
646
646
647
647
648 title = "Power Profile: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
648 title = "Power Profile: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
649 axes = self.axesList[0]
649 axes = self.axesList[0]
650
650
651 legendlabels = ["channel %d"%x for x in channelList]
651 legendlabels = ["channel %d"%x for x in channelList]
652 axes.pmultiline(avg, y,
652 axes.pmultiline(avg, y,
653 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax,
653 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax,
654 xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels,
654 xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels,
655 ytick_visible=True, nxticks=5,
655 ytick_visible=True, nxticks=5,
656 grid='x')
656 grid='x')
657
657
658 self.draw()
658 self.draw()
659
659
660 if save:
660 if save:
661 date = thisDatetime.strftime("%Y%m%d")
661 date = thisDatetime.strftime("%Y%m%d")
662 if figfile == None:
662 if figfile == None:
663 figfile = self.getFilename(name = date)
663 figfile = self.getFilename(name = date)
664
664
665 self.saveFigure(figpath, figfile)
665 self.saveFigure(figpath, figfile)
666
666
667 class CoherencePlot(Figure):
667 class CoherencePlot(Figure):
668 __isConfig = None
668 __isConfig = None
669 __nsubplots = None
669 __nsubplots = None
670
670
671 WIDTHPROF = None
671 WIDTHPROF = None
672 HEIGHTPROF = None
672 HEIGHTPROF = None
673 PREFIX = 'coherencemap'
673 PREFIX = 'coherencemap'
674
674
675 def __init__(self):
675 def __init__(self):
676 self.__timerange = 24*60*60
676 self.timerange = 24*60*60
677 self.__isConfig = False
677 self.__isConfig = False
678 self.__nsubplots = 1
678 self.__nsubplots = 1
679
679
680 self.WIDTH = 800
680 self.WIDTH = 800
681 self.HEIGHT = 200
681 self.HEIGHT = 200
682 self.WIDTHPROF = 120
682 self.WIDTHPROF = 120
683 self.HEIGHTPROF = 0
683 self.HEIGHTPROF = 0
684
684
685 def getSubplots(self):
685 def getSubplots(self):
686 ncol = 1
686 ncol = 1
687 nrow = self.nplots*2
687 nrow = self.nplots*2
688
688
689 return nrow, ncol
689 return nrow, ncol
690
690
691 def setup(self, idfigure, nplots, wintitle, showprofile=True):
691 def setup(self, idfigure, nplots, wintitle, showprofile=True):
692 self.__showprofile = showprofile
692 self.__showprofile = showprofile
693 self.nplots = nplots
693 self.nplots = nplots
694
694
695 ncolspan = 1
695 ncolspan = 1
696 colspan = 1
696 colspan = 1
697 if showprofile:
697 if showprofile:
698 ncolspan = 7
698 ncolspan = 7
699 colspan = 6
699 colspan = 6
700 self.__nsubplots = 2
700 self.__nsubplots = 2
701
701
702 self.createFigure(idfigure = idfigure,
702 self.createFigure(idfigure = idfigure,
703 wintitle = wintitle,
703 wintitle = wintitle,
704 widthplot = self.WIDTH + self.WIDTHPROF,
704 widthplot = self.WIDTH + self.WIDTHPROF,
705 heightplot = self.HEIGHT + self.HEIGHTPROF)
705 heightplot = self.HEIGHT + self.HEIGHTPROF)
706
706
707 nrow, ncol = self.getSubplots()
707 nrow, ncol = self.getSubplots()
708
708
709 for y in range(nrow):
709 for y in range(nrow):
710 for x in range(ncol):
710 for x in range(ncol):
711
711
712 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
712 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
713
713
714 if showprofile:
714 if showprofile:
715 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1)
715 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1)
716
716
717 def run(self, dataOut, idfigure, wintitle="", pairsList=None, showprofile='True',
717 def run(self, dataOut, idfigure, wintitle="", pairsList=None, showprofile='True',
718 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
718 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
719 timerange=None,
719 timerange=None,
720 save=False, figpath='./', figfile=None):
720 save=False, figpath='./', figfile=None):
721
721
722 if pairsList == None:
722 if pairsList == None:
723 pairsIndexList = dataOut.pairsIndexList
723 pairsIndexList = dataOut.pairsIndexList
724 else:
724 else:
725 pairsIndexList = []
725 pairsIndexList = []
726 for pair in pairsList:
726 for pair in pairsList:
727 if pair not in dataOut.pairsList:
727 if pair not in dataOut.pairsList:
728 raise ValueError, "Pair %s is not in dataOut.pairsList" %(pair)
728 raise ValueError, "Pair %s is not in dataOut.pairsList" %(pair)
729 pairsIndexList.append(dataOut.pairsList.index(pair))
729 pairsIndexList.append(dataOut.pairsList.index(pair))
730
730
731 if timerange != None:
731 if timerange != None:
732 self.__timerange = timerange
732 self.timerange = timerange
733
733
734 tmin = None
734 tmin = None
735 tmax = None
735 tmax = None
736 x = dataOut.getTimeRange()
736 x = dataOut.getTimeRange()
737 y = dataOut.getHeiRange()
737 y = dataOut.getHeiRange()
738
738
739 if not self.__isConfig:
739 if not self.__isConfig:
740 nplots = len(pairsIndexList)
740 nplots = len(pairsIndexList)
741 self.setup(idfigure=idfigure,
741 self.setup(idfigure=idfigure,
742 nplots=nplots,
742 nplots=nplots,
743 wintitle=wintitle,
743 wintitle=wintitle,
744 showprofile=showprofile)
744 showprofile=showprofile)
745
745
746 tmin, tmax = self.getTimeLim(x, xmin, xmax)
746 tmin, tmax = self.getTimeLim(x, xmin, xmax)
747 if ymin == None: ymin = numpy.nanmin(y)
747 if ymin == None: ymin = numpy.nanmin(y)
748 if ymax == None: ymax = numpy.nanmax(y)
748 if ymax == None: ymax = numpy.nanmax(y)
749
749
750 self.__isConfig = True
750 self.__isConfig = True
751
751
752 thisDatetime = dataOut.datatime
752 thisDatetime = dataOut.datatime
753 title = "CoherenceMap: %s" %(thisDatetime.strftime("%d-%b-%Y"))
753 title = "CoherenceMap: %s" %(thisDatetime.strftime("%d-%b-%Y"))
754 xlabel = ""
754 xlabel = ""
755 ylabel = "Range (Km)"
755 ylabel = "Range (Km)"
756
756
757 self.setWinTitle(title)
757 self.setWinTitle(title)
758
758
759 for i in range(self.nplots):
759 for i in range(self.nplots):
760
760
761 pair = dataOut.pairsList[pairsIndexList[i]]
761 pair = dataOut.pairsList[pairsIndexList[i]]
762 coherenceComplex = dataOut.data_cspc[pairsIndexList[i],:,:]/numpy.sqrt(dataOut.data_spc[pair[0],:,:]*dataOut.data_spc[pair[1],:,:])
762 coherenceComplex = dataOut.data_cspc[pairsIndexList[i],:,:]/numpy.sqrt(dataOut.data_spc[pair[0],:,:]*dataOut.data_spc[pair[1],:,:])
763 coherence = numpy.abs(coherenceComplex)
763 coherence = numpy.abs(coherenceComplex)
764 avg = numpy.average(coherence, axis=0)
764 avg = numpy.average(coherence, axis=0)
765 z = avg.reshape((1,-1))
765 z = avg.reshape((1,-1))
766
766
767 counter = 0
767 counter = 0
768
768
769 title = "Coherence %d%d: %s" %(pair[0], pair[1], thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
769 title = "Coherence %d%d: %s" %(pair[0], pair[1], thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
770 axes = self.axesList[i*self.__nsubplots*2]
770 axes = self.axesList[i*self.__nsubplots*2]
771 axes.pcolor(x, y, z,
771 axes.pcolor(x, y, z,
772 xmin=tmin, xmax=tmax, ymin=ymin, ymax=ymax, zmin=0, zmax=1,
772 xmin=tmin, xmax=tmax, ymin=ymin, ymax=ymax, zmin=0, zmax=1,
773 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
773 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
774 ticksize=9, cblabel='', cbsize="1%")
774 ticksize=9, cblabel='', cbsize="1%")
775
775
776 if self.__showprofile:
776 if self.__showprofile:
777 counter += 1
777 counter += 1
778 axes = self.axesList[i*self.__nsubplots*2 + counter]
778 axes = self.axesList[i*self.__nsubplots*2 + counter]
779 axes.pline(avg, y,
779 axes.pline(avg, y,
780 xmin=0, xmax=1, ymin=ymin, ymax=ymax,
780 xmin=0, xmax=1, ymin=ymin, ymax=ymax,
781 xlabel='', ylabel='', title='', ticksize=7,
781 xlabel='', ylabel='', title='', ticksize=7,
782 ytick_visible=False, nxticks=5,
782 ytick_visible=False, nxticks=5,
783 grid='x')
783 grid='x')
784
784
785 counter += 1
785 counter += 1
786 phase = numpy.arctan(-1*coherenceComplex.imag/coherenceComplex.real)*180/numpy.pi
786 phase = numpy.arctan(-1*coherenceComplex.imag/coherenceComplex.real)*180/numpy.pi
787 avg = numpy.average(phase, axis=0)
787 avg = numpy.average(phase, axis=0)
788 z = avg.reshape((1,-1))
788 z = avg.reshape((1,-1))
789
789
790 title = "Phase %d%d: %s" %(pair[0], pair[1], thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
790 title = "Phase %d%d: %s" %(pair[0], pair[1], thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
791 axes = self.axesList[i*self.__nsubplots*2 + counter]
791 axes = self.axesList[i*self.__nsubplots*2 + counter]
792 axes.pcolor(x, y, z,
792 axes.pcolor(x, y, z,
793 xmin=tmin, xmax=tmax, ymin=ymin, ymax=ymax, zmin=-180, zmax=180,
793 xmin=tmin, xmax=tmax, ymin=ymin, ymax=ymax, zmin=-180, zmax=180,
794 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
794 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
795 ticksize=9, cblabel='', colormap='RdBu', cbsize="1%")
795 ticksize=9, cblabel='', colormap='RdBu', cbsize="1%")
796
796
797 if self.__showprofile:
797 if self.__showprofile:
798 counter += 1
798 counter += 1
799 axes = self.axesList[i*self.__nsubplots*2 + counter]
799 axes = self.axesList[i*self.__nsubplots*2 + counter]
800 axes.pline(avg, y,
800 axes.pline(avg, y,
801 xmin=-180, xmax=180, ymin=ymin, ymax=ymax,
801 xmin=-180, xmax=180, ymin=ymin, ymax=ymax,
802 xlabel='', ylabel='', title='', ticksize=7,
802 xlabel='', ylabel='', title='', ticksize=7,
803 ytick_visible=False, nxticks=4,
803 ytick_visible=False, nxticks=4,
804 grid='x')
804 grid='x')
805
805
806 self.draw()
806 self.draw()
807
807
808 if save:
808 if save:
809 date = thisDatetime.strftime("%Y%m%d")
809 date = thisDatetime.strftime("%Y%m%d")
810 if figfile == None:
810 if figfile == None:
811 figfile = self.getFilename(name = date)
811 figfile = self.getFilename(name = date)
812
812
813 self.saveFigure(figpath, figfile)
813 self.saveFigure(figpath, figfile)
814
814
815 if x[1] + (x[1]-x[0]) >= self.axesList[0].xmax:
815 if x[1] + (x[1]-x[0]) >= self.axesList[0].xmax:
816 self.__isConfig = False
816 self.__isConfig = False
817
817
818 No newline at end of file
818
General Comments 0
You need to be logged in to leave comments. Login now