##// END OF EJS Templates
Se ha reordenado las variables
Miguel Valdez -
r89:b509e99f0d8d
parent child
Show More
@@ -1,178 +1,178
1 1 '''
2 2 Created on Feb 7, 2012
3 3
4 4 @author $Author$
5 5 @version $Id$
6 6 '''
7 7
8 8 import os, sys
9 9 import numpy
10 10 import datetime
11 11 import plplot
12 12
13 13 path = os.path.split(os.getcwd())[0]
14 14 sys.path.append(path)
15 15
16 16 from Graphics.BaseGraph import *
17 17 from Model.Spectra import Spectra
18 18
19 19 class Spectrum():
20 20
21 21 def __init__(self, Spectra, index=0):
22 22
23 23 """
24 24
25 25 Inputs:
26 26
27 27 type: "power" ->> Potencia
28 28 "iq" ->> Real + Imaginario
29 29 """
30 30
31 31 self.__isPlotConfig = False
32 32
33 33 self.__isPlotIni = False
34 34
35 35 self.__xrange = None
36 36
37 37 self.__yrange = None
38 38
39 39 self.nGraphs = 0
40 40
41 41 self.indexPlot = index
42 42
43 43 self.graphObjList = []
44 44
45 45 self.m_Spectra = Spectra
46 46
47 47
48 48 def __addGraph(self, subpage, title="", xlabel="", ylabel="", showColorbar=False, showPowerProfile=True, XAxisAsTime=False):
49 49
50 50 graphObj = ColorPlot()
51 51 graphObj.setup(subpage,
52 52 title,
53 53 xlabel,
54 54 ylabel,
55 55 showColorbar=showColorbar,
56 56 showPowerProfile=showPowerProfile,
57 57 XAxisAsTime=XAxisAsTime)
58 58
59 59 self.graphObjList.append(graphObj)
60 60
61 61
62 62 def setup(self, titleList=None, xlabelList=None, ylabelList=None, showColorbar=False, showPowerProfile=True, XAxisAsTime=False):
63 63
64 64 nChan = int(self.m_Spectra.m_SystemHeader.numChannels)
65 65 channels = range(nChan)
66 66
67 67 myXlabel = "Radial Velocity (m/s)"
68 68 myYlabel = "Range (km)"
69 69
70 70 for i in channels:
71 71 if titleList != None:
72 72 myTitle = titleList[i]
73 73 myXlabel = xlabelList[i]
74 74 myYlabel = ylabelList[i]
75 75
76 76 # if self.m_Spectra.m_NoiseObj != None:
77 77 # noise = '%4.2fdB' %(self.m_Spectra.m_NoiseObj[i])
78 78 # else:
79 79 noise = '--'
80 80
81 81 myTitle = "Channel: %d - Noise: %s" %(i, noise)
82 82
83 83 self.__addGraph(i+1,
84 84 title=myTitle,
85 85 xlabel=myXlabel,
86 86 ylabel=myYlabel,
87 87 showColorbar=showColorbar,
88 88 showPowerProfile=showPowerProfile,
89 89 XAxisAsTime=XAxisAsTime)
90 90
91 91 self.nGraphs = nChan
92 92 self.__isPlotConfig = True
93 93
94 94 def iniPlot(self, winTitle=""):
95 95
96 96 nx = int(numpy.sqrt(self.nGraphs)+1)
97 97 #ny = int(self.nGraphs/nx)
98 98
99 99 plplot.plsstrm(self.indexPlot)
100 100 plplot.plparseopts([winTitle], plplot.PL_PARSE_FULL)
101 101 plplot.plsetopt("geometry", "%dx%d" %(300*nx, 240*nx))
102 102 plplot.plsdev("xwin")
103 103 plplot.plscolbg(255,255,255)
104 104 plplot.plscol0(1,0,0,0)
105 105 plplot.plinit()
106 106 plplot.plspause(False)
107 107 plplot.pladv(0)
108 108 plplot.plssub(nx, nx)
109 109
110 110 self.__nx = nx
111 111 self.__ny = nx
112 112 self.__isPlotIni = True
113 113
114 114
115 115 def plotData(self, xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None, titleList=None, xlabelList=None, ylabelList=None, showColorbar=False, showPowerProfile=True, XAxisAsTime=False, winTitle="Spectra"):
116 116
117 117 if not(self.__isPlotConfig):
118 118 self.setup(titleList,
119 119 xlabelList,
120 120 ylabelList,
121 121 showColorbar,
122 122 showPowerProfile,
123 123 XAxisAsTime)
124 124
125 125 if not(self.__isPlotIni):
126 126 self.iniPlot(winTitle)
127 127
128 128 plplot.plsstrm(self.indexPlot)
129 129
130 130 data = 10.*numpy.log10(self.m_Spectra.data_spc)
131 131
132 132 #data.shape = Channels x Heights x Profiles
133 133 # data = numpy.transpose( data, (0,2,1) )
134 134 #data.shape = Channels x Profiles x Heights
135 135
136 136 nChan, nX, nY = numpy.shape(data)
137 137
138 138 x = numpy.arange(nX)
139 y = self.m_Spectra.heights
139 y = self.m_Spectra.heightList
140 140
141 141 thisDatetime = datetime.datetime.fromtimestamp(self.m_Spectra.m_BasicHeader.utc)
142 142 txtDate = "Self Spectra - Date: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
143 143
144 144 if xmin == None: xmin = x[0]
145 145 if xmax == None: xmax = x[-1]
146 146 if ymin == None: ymin = y[0]
147 147 if ymax == None: ymax = y[-1]
148 148 if zmin == None: zmin = numpy.nanmin(abs(data))
149 149 if zmax == None: zmax = numpy.nanmax(abs(data))
150 150
151 151 plplot.plbop()
152 152
153 153 plplot.plssub(self.__nx, self.__ny)
154 154 for i in range(self.nGraphs):
155 155 self.graphObjList[i].iniSubpage()
156 156 self.graphObjList[i].plotData(data[i,:,:],
157 157 x,
158 158 y,
159 159 xmin=xmin,
160 160 xmax=xmax,
161 161 ymin=ymin,
162 162 ymax=ymax,
163 163 zmin=zmin,
164 164 zmax=zmax)
165 165
166 166 plplot.plssub(1,0)
167 167 plplot.pladv(0)
168 168 plplot.plvpor(0., 1., 0., 1.)
169 169 plplot.plmtex("t",-1., 0.5, 0.5, txtDate)
170 170 plplot.plflush()
171 171 plplot.pleop()
172 172
173 173 def end(self):
174 174 plplot.plend()
175 175
176 176
177 177 if __name__ == '__main__':
178 178 pass No newline at end of file
@@ -1,17 +1,30
1 1 '''
2 2 Created on 23/01/2012
3 3
4 4 @author $Author$
5 5 @version $Id$
6 6 '''
7 7
8 8 from DataIO import DataReader
9 9 from DataIO import DataWriter
10 10
11 11 class CorrelationReader(DataReader):
12
12 13 def __init__(self):
14
13 15 pass
14 16
15 17 class CorrelationWriter(DataWriter):
18
16 19 def __init__(self):
17 pass No newline at end of file
20
21 pass
22
23 def puData(self):
24 pass
25
26 def writeBlock(self):
27 pass
28
29
30 No newline at end of file
@@ -1,1263 +1,1207
1 1 '''
2 2 Created on 23/01/2012
3 3
4 4 @author $Author$
5 5 @version $Id$
6 6 @version $Id$
7 7 '''
8 8
9 9 import os, sys
10 10 import glob
11 11 import time
12 12 import numpy
13 13 import fnmatch
14 14 import time, datetime
15 15
16 16 path = os.path.split(os.getcwd())[0]
17 17 sys.path.append(path)
18 18
19 19 from Model.JROHeader import *
20 20 from Model.JROData import JROData
21 21
22 22 def checkForRealPath(path, year, doy, set, ext):
23 23 """
24 24 Por ser Linux Case Sensitive entonces checkForRealPath encuentra el nombre correcto de un path,
25 25 Prueba por varias combinaciones de nombres entre mayusculas y minusculas para determinar
26 26 el path exacto de un determinado file.
27 27
28 28 Example :
29 29 nombre correcto del file es .../.../D2009307/P2009307367.ext
30 30
31 31 Entonces la funcion prueba con las siguientes combinaciones
32 32 .../.../x2009307/y2009307367.ext
33 33 .../.../x2009307/Y2009307367.ext
34 34 .../.../X2009307/y2009307367.ext
35 35 .../.../X2009307/Y2009307367.ext
36 36 siendo para este caso, la ultima combinacion de letras, identica al file buscado
37 37
38 38 Return:
39 39 Si encuentra la cobinacion adecuada devuelve el path completo y el nombre del file
40 40 caso contrario devuelve None como path y el la ultima combinacion de nombre en mayusculas
41 41 para el filename
42 42 """
43 43 filepath = None
44 44 find_flag = False
45 45 filename = None
46 46
47 47 if ext.lower() == ".r": #voltage
48 48 header1 = "dD"
49 49 header2 = "dD"
50 50 elif ext.lower() == ".pdata": #spectra
51 51 header1 = "dD"
52 52 header2 = "pP"
53 53 else:
54 54 return None, filename
55 55
56 56 for dir in header1: #barrido por las dos combinaciones posibles de "D"
57 57 for fil in header2: #barrido por las dos combinaciones posibles de "D"
58 58 doypath = "%s%04d%03d" % ( dir, year, doy ) #formo el nombre del directorio xYYYYDDD (x=d o x=D)
59 59 filename = "%s%04d%03d%03d%s" % ( fil, year, doy, set, ext ) #formo el nombre del file xYYYYDDDSSS.ext
60 60 filepath = os.path.join( path, doypath, filename ) #formo el path completo
61 61 if os.path.exists( filepath ): #verifico que exista
62 62 find_flag = True
63 63 break
64 64 if find_flag:
65 65 break
66 66
67 67 if not(find_flag):
68 68 return None, filename
69 69
70 70 return filepath, filename
71 71
72 72
73 73 def isNumber(str):
74 74 """
75 75 Chequea si el conjunto de caracteres que componen un string puede ser convertidos a un numero.
76 76
77 77 Excepciones:
78 78 Si un determinado string no puede ser convertido a numero
79 79 Input:
80 80 str, string al cual se le analiza para determinar si convertible a un numero o no
81 81
82 82 Return:
83 83 True : si el string es uno numerico
84 84 False : no es un string numerico
85 85 """
86 86 try:
87 87 float( str )
88 88 return True
89 89 except:
90 90 return False
91 91
92 92
93 93 def isThisFileinRange(filename, startUTSeconds, endUTSeconds):
94 94 """
95 95 Esta funcion determina si un archivo de datos se encuentra o no dentro del rango de fecha especificado.
96 96
97 97 Inputs:
98 98 filename : nombre completo del archivo de datos en formato Jicamarca (.r)
99 99
100 100 startUTSeconds : fecha inicial del rango seleccionado. La fecha esta dada en
101 101 segundos contados desde 01/01/1970.
102 102 endUTSeconds : fecha final del rango seleccionado. La fecha esta dada en
103 103 segundos contados desde 01/01/1970.
104 104
105 105 Return:
106 106 Boolean : Retorna True si el archivo de datos contiene datos en el rango de
107 107 fecha especificado, de lo contrario retorna False.
108 108
109 109 Excepciones:
110 110 Si el archivo no existe o no puede ser abierto
111 111 Si la cabecera no puede ser leida.
112 112
113 113 """
114 114 m_BasicHeader = BasicHeader()
115 115
116 116 try:
117 117 fp = open(filename,'rb')
118 118 except:
119 119 raise IOError, "The file %s can't be opened" %(filename)
120 120
121 121 sts = m_BasicHeader.read(fp)
122 122 fp.close()
123 123
124 124 if not(sts):
125 125 print "Skipping the file %s because it has not a valid header" %(filename)
126 126 return 0
127 127
128 128 if not ((startUTSeconds <= m_BasicHeader.utc) and (endUTSeconds > m_BasicHeader.utc)):
129 129 return 0
130 130
131 131 return 1
132 132
133 133
134 134 def getlastFileFromPath(path, ext):
135 135 """
136 136 Depura el fileList dejando solo los que cumplan el formato de "PYYYYDDDSSS.ext"
137 137 al final de la depuracion devuelve el ultimo file de la lista que quedo.
138 138
139 139 Input:
140 140 fileList : lista conteniendo todos los files (sin path) que componen una determinada carpeta
141 141 ext : extension de los files contenidos en una carpeta
142 142
143 143 Return:
144 144 El ultimo file de una determinada carpeta, no se considera el path.
145 145 """
146 146 validFilelist = []
147 147 fileList = os.listdir(path)
148 148
149 149 # 0 1234 567 89A BCDE
150 150 # H YYYY DDD SSS .ext
151 151
152 152 for file in fileList:
153 153 try:
154 154 year = int(file[1:5])
155 155 doy = int(file[5:8])
156 156
157 157 if (os.path.splitext(file)[-1].upper() != ext.upper()) : continue
158 158 except:
159 159 continue
160 160
161 161 validFilelist.append(file)
162 162
163 163 if validFilelist:
164 164 validFilelist = sorted( validFilelist, key=str.lower )
165 165 return validFilelist[-1]
166 166
167 167 return None
168 168
169
170 class DataReader():
171
172 def __init__(self):
173 pass
174
175
176 class DataWriter():
177
178 def __init__(self):
179 pass
180
169 class JRODataIO():
181 170
182 class JRODataReader(DataReader):
183
184 """
185 Esta clase es usada como la clase padre de las clases DataReader,
186 contiene todos lo metodos necesarios para leer datos desde archivos en formato
187 jicamarca o pdata (.r o .pdata). La lectura de los datos siempre se realiza por bloques. Los datos
188 leidos son array de 3 dimensiones:
189
190 Para Voltajes - perfiles * alturas * canales
191
192 Para Spectra - paresCanalesIguales * alturas * perfiles (Self Spectra)
193 paresCanalesDiferentes * alturas * perfiles (Cross Spectra)
194 canales * alturas (DC Channels)
195
196 y son almacenados en su buffer respectivo.
197
198 Esta clase contiene instancias (objetos) de las clases BasicHeader, SystemHeader,
199 RadarControllerHeader y DataObj. Los tres primeros se usan para almacenar informacion de la
200 cabecera de datos (metadata), y el cuarto (DataObj) para obtener y almacenar los datos desde
201 el buffer cada vez que se ejecute el metodo "getData".
202 """
171 #speed of light
172 c = 3E8
203 173
204 174 m_BasicHeader = BasicHeader()
205 175
206 176 m_SystemHeader = SystemHeader()
207 177
208 178 m_RadarControllerHeader = RadarControllerHeader()
209 179
210 180 m_ProcessingHeader = ProcessingHeader()
211 181
212 182 m_DataObj = None
213 183
214 heightList = None
215
216 channelList = None
217
218 184 online = 0
219 185
220 186 fp = None
221 187
188 dataType = None
189
222 190 fileSizeByHeader = None
223 191
224 192 filenameList = []
225 193
226 194 filename = None
227 195
228 196 fileSize = None
229 197
230 198 firstHeaderSize = 0
231 199
232 200 basicHeaderSize = 24
233 201
234 dataType = None
202 nTotalBlocks = 0
203
204 ippSeconds = 0
235 205
236 maxTimeStep = 30
237
238 flagNoMoreFiles = 0
206 blocksize = 0
239 207
240 208 set = 0
241 209
242 210 ext = None
243 211
244 212 path = None
245 213
214 maxTimeStep = 30
215
216
246 217 delay = 3 #seconds
247 218
248 219 nTries = 3 #quantity tries
249 220
250 nFiles = 3 #number of files for searching
221 nFiles = 3 #number of files for searching
222
251 223
252 nBlocks = 0
224 flagNoMoreFiles = 0
253 225
254 226 flagIsNewFile = 1
255
256 ippSeconds = 0
257
227
258 228 flagResetProcessing = 0
259 229
260 230 flagIsNewBlock = 0
261 231
262 nReadBlocks = 0
263
264 blocksize = 0
232 def __init__(self):
233 pass
234
235 class JRODataReader(JRODataIO):
236
237 """
238 Esta clase es usada como la clase padre de las clases VoltageReader y SpectraReader.
239 Contiene todos lo metodos necesarios para leer datos desde archivos en formato
240 jicamarca o pdata (.r o .pdata). La lectura de los datos siempre se realiza por bloques. Los datos
241 leidos son array de 3 dimensiones:
265 242
266 datablockIndex = 9999
243 Para Voltajes - perfiles * alturas * canales
244
245 Para Spectra - paresCanalesIguales * alturas * perfiles (Self Spectra)
246 paresCanalesDiferentes * alturas * perfiles (Cross Spectra)
247 canales * alturas (DC Channels)
248
249 y son almacenados en su buffer respectivo.
250
251 Esta clase contiene instancias (objetos) de las clases BasicHeader, SystemHeader,
252 RadarControllerHeader y DataObj. Los tres primeros se usan para almacenar informacion de la
253 cabecera de datos (metadata), y el cuarto (DataObj) para obtener y almacenar los datos desde
254 el buffer de datos cada vez que se ejecute el metodo "getData".
255 """
267 256
268 #speed of light
269 c = 3E8
257 nReadBlocks = 0
270 258
271 259 def __init__(self, m_DataObj=None):
260
272 261 raise ValueError, "This class can't be instanced"
273 262
274 263
275
276
277
278 264 def hasNotDataInBuffer(self):
265
279 266 raise ValueError, "Not implemented"
280
281
267
268 def getBlockDimension(self):
269
270 raise ValueError, "No implemented"
271
282 272 def readBlock(self):
273
274 self.nTotalBlocks += 1
275 self.nReadBlocks += 1
276
283 277 raise ValueError, "This method has not been implemented"
284
278
285 279 def getData( self ):
280
286 281 raise ValueError, "This method has not been implemented"
282
287 283
288 284 def __rdSystemHeader(self, fp=None):
289 285
290 286 if fp == None:
291 287 fp = self.fp
292 288
293 289 self.m_SystemHeader.read(fp)
294 290
295 291
296 292 def __rdRadarControllerHeader(self, fp=None):
297 293 if fp == None:
298 294 fp = self.fp
299 295
300 296 self.m_RadarControllerHeader.read(fp)
301 297
302 298
303 299 def __rdProcessingHeader(self, fp=None):
304 300 if fp == None:
305 301 fp = self.fp
306 302
307 303 self.m_ProcessingHeader.read(fp)
308 304
309 305
310 306 def __rdBasicHeader(self, fp=None):
311 307
312 308 if fp == None:
313 309 fp = self.fp
314 310
315 311 self.m_BasicHeader.read(fp)
316
317 def getBlockDimension(self):
318 raise ValueError, "No implemented"
319 312
320 313 def __readFirstHeader(self):
321 314 """
322 315 Lectura del First Header, es decir el Basic Header y el Long Header
323 316
324 317 Affected:
325 318 self.m_BasicHeader
326 319 self.m_SystemHeader
327 320 self.m_RadarControllerHeader
328 321 self.m_ProcessingHeader
329 322 self.firstHeaderSize
330 self.heightList
331 323 self.dataType
332 324 self.fileSizeByHeader
333 325 self.ippSeconds
334 326
335 327 Return:
336 328 None
337 329 """
338 330 self.__rdBasicHeader()
339 331 self.__rdSystemHeader()
340 332 self.__rdRadarControllerHeader()
341 333 self.__rdProcessingHeader()
342 334 self.firstHeaderSize = self.m_BasicHeader.size
343 335
344 data_type=int(numpy.log2((self.m_ProcessingHeader.processFlags & PROCFLAG.DATATYPE_MASK))-numpy.log2(PROCFLAG.DATATYPE_CHAR))
345 if data_type == 0:
346 tmp = numpy.dtype([('real','<i1'),('imag','<i1')])
336 datatype = int(numpy.log2((self.m_ProcessingHeader.processFlags & PROCFLAG.DATATYPE_MASK))-numpy.log2(PROCFLAG.DATATYPE_CHAR))
337 if datatype == 0:
338 datatype_str = numpy.dtype([('real','<i1'),('imag','<i1')])
347 339
348 elif data_type == 1:
349 tmp = numpy.dtype([('real','<i2'),('imag','<i2')])
340 elif datatype == 1:
341 datatype_str = numpy.dtype([('real','<i2'),('imag','<i2')])
350 342
351 elif data_type == 2:
352 tmp = numpy.dtype([('real','<i4'),('imag','<i4')])
343 elif datatype == 2:
344 datatype_str = numpy.dtype([('real','<i4'),('imag','<i4')])
353 345
354 elif data_type == 3:
355 tmp = numpy.dtype([('real','<i8'),('imag','<i8')])
346 elif datatype == 3:
347 datatype_str = numpy.dtype([('real','<i8'),('imag','<i8')])
356 348
357 elif data_type == 4:
358 tmp = numpy.dtype([('real','<f4'),('imag','<f4')])
349 elif datatype == 4:
350 datatype_str = numpy.dtype([('real','<f4'),('imag','<f4')])
359 351
360 elif data_type == 5:
361 tmp = numpy.dtype([('real','<f8'),('imag','<f8')])
352 elif datatype == 5:
353 datatype_str = numpy.dtype([('real','<f8'),('imag','<f8')])
362 354
363 355 else:
364 356 raise ValueError, 'Data type was not defined'
365 357
366 xi = self.m_ProcessingHeader.firstHeight
367 step = self.m_ProcessingHeader.deltaHeight
368 xf = xi + self.m_ProcessingHeader.numHeights*step
369
370 self.heightList = numpy.arange(xi, xf, step)
371 self.channelList = numpy.arange(self.m_SystemHeader.numChannels)
372 self.dataType = tmp
373 self.fileSizeByHeader = self.m_ProcessingHeader.dataBlocksPerFile * self.m_ProcessingHeader.blockSize + self.firstHeaderSize + self.basicHeaderSize*(self.m_ProcessingHeader.dataBlocksPerFile - 1)
358 self.dataType = datatype_str
374 359 self.ippSeconds = 2 * 1000 * self.m_RadarControllerHeader.ipp / self.c
375 360
361 self.fileSizeByHeader = self.m_ProcessingHeader.dataBlocksPerFile * self.m_ProcessingHeader.blockSize + self.firstHeaderSize + self.basicHeaderSize*(self.m_ProcessingHeader.dataBlocksPerFile - 1)
362
376 363 self.getBlockDimension()
364
365 def __setNewBlock(self):
366 """
367 Lee el Basic Header y posiciona le file pointer en la posicion inicial del bloque a leer
368
369 Affected:
370 self.m_BasicHeader
371 self.flagNoContinuousBlock
372 self.ns
373
374 Return:
375 0 : Si el file no tiene un Basic Header que pueda ser leido
376 1 : Si se pudo leer el Basic Header
377 """
378 if self.fp == None:
379 return 0
380
381 if self.flagIsNewFile:
382 return 1
383
384 self.lastUTTime = self.m_BasicHeader.utc
385
386 currentSize = self.fileSize - self.fp.tell()
387 neededSize = self.m_ProcessingHeader.blockSize + self.basicHeaderSize
388
389 #If there is enough data setting new data block
390 if ( currentSize >= neededSize ):
391 self.__rdBasicHeader()
392 return 1
393
394 #si es OnLine y ademas aun no se han leido un bloque completo entonces se espera por uno valido
395 if self.online and (self.nReadBlocks < self.m_ProcessingHeader.dataBlocksPerFile):
396
397 fpointer = self.fp.tell()
398
399 for nTries in range( self.nTries ):
400 #self.fp.close()
401
402 print "\tWaiting %0.2f seconds for the next block, try %03d ..." % (self.delay, nTries+1)
403 time.sleep( self.delay )
404
405 #self.fp = open( self.filename, 'rb' )
406 #self.fp.seek( fpointer )
407
408 self.fileSize = os.path.getsize( self.filename )
409 currentSize = self.fileSize - fpointer
410
411 if ( currentSize >= neededSize ):
412 self.__rdBasicHeader()
413 return 1
414
415 #Setting new file
416 if not( self.setNextFile() ):
417 return 0
418
419 deltaTime = self.m_BasicHeader.utc - self.lastUTTime # check this
420
421 self.flagResetProcessing = 0
422
423 if deltaTime > self.maxTimeStep:
424 self.flagResetProcessing = 1
425
426 return 1
427
428 def readNextBlock(self):
429 """
430 Establece un nuevo bloque de datos a leer y los lee, si es que no existiese
431 mas bloques disponibles en el archivo actual salta al siguiente.
432
433 Affected:
434 self.lastUTTime
377 435
436 Return: None
437 """
438
439 if not(self.__setNewBlock()):
440 return 0
441
442 if not(self.readBlock()):
443 return 0
444
445 return 1
378 446
379 447 def __setNextFileOnline(self):
380 448 """
381 449 Busca el siguiente file que tenga suficiente data para ser leida, dentro de un folder especifico, si
382 450 no encuentra un file valido espera un tiempo determinado y luego busca en los posibles n files
383 451 siguientes.
384 452
385 453 Affected:
386 454 self.flagIsNewFile
387 455 self.filename
388 456 self.fileSize
389 457 self.fp
390 458 self.set
391 459 self.flagNoMoreFiles
392 460
393 461 Return:
394 462 0 : si luego de una busqueda del siguiente file valido este no pudo ser encontrado
395 463 1 : si el file fue abierto con exito y esta listo a ser leido
396 464
397 465 Excepciones:
398 466 Si un determinado file no puede ser abierto
399 467 """
400 468 nFiles = 0
401 469 fileOk_flag = False
402 470 firstTime_flag = True
403 471
404 472 self.set += 1
405 473
406 474 #busca el 1er file disponible
407 475 file, filename = checkForRealPath( self.path, self.year, self.doy, self.set, self.ext )
408 476 if file:
409 477 if self.__verifyFile(file, False):
410 478 fileOk_flag = True
411 479
412 480 #si no encuentra un file entonces espera y vuelve a buscar
413 481 if not(fileOk_flag):
414 482 for nFiles in range(self.nFiles+1): #busco en los siguientes self.nFiles+1 files posibles
415 483
416 484 if firstTime_flag: #si es la 1era vez entonces hace el for self.nTries veces
417 485 tries = self.nTries
418 486 else:
419 487 tries = 1 #si no es la 1era vez entonces solo lo hace una vez
420 488
421 489 for nTries in range( tries ):
422 490 if firstTime_flag:
423 491 print "\tWaiting %0.2f sec for new \"%s\" file, try %03d ..." % ( self.delay, filename, nTries+1 )
424 492 time.sleep( self.delay )
425 493 else:
426 494 print "\tSearching next \"%s%04d%03d%03d%s\" file ..." % (self.optchar, self.year, self.doy, self.set, self.ext)
427 495
428 496 file, filename = checkForRealPath( self.path, self.year, self.doy, self.set, self.ext )
429 497 if file:
430 498 if self.__verifyFile(file):
431 499 fileOk_flag = True
432 500 break
433 501
434 502 if fileOk_flag:
435 503 break
436 504
437 505 firstTime_flag = False
438 506
439 507 print "\tSkipping the file \"%s\" due to this file doesn't exist yet" % filename
440 508 self.set += 1
441 509
442 510 if nFiles == (self.nFiles-1): #si no encuentro el file buscado cambio de carpeta y busco en la siguiente carpeta
443 511 self.set = 0
444 512 self.doy += 1
445 513
446 514 if fileOk_flag:
447 515 self.fileSize = os.path.getsize( file )
448 516 self.filename = file
449 517 self.flagIsNewFile = 1
450 518 if self.fp != None: self.fp.close()
451 519 self.fp = open(file)
452 520 self.flagNoMoreFiles = 0
453 521 print 'Setting the file: %s' % file
454 522 else:
455 523 self.fileSize = 0
456 524 self.filename = None
457 525 self.flagIsNewFile = 0
458 526 self.fp = None
459 527 self.flagNoMoreFiles = 1
460 528 print 'No more Files'
461 529
462 530 return fileOk_flag
463 531
464 532
465 533 def __setNextFileOffline(self):
466 534 """
467 535 Busca el siguiente file dentro de un folder que tenga suficiente data para ser leida
468 536
469 537 Affected:
470 538 self.flagIsNewFile
471 539 self.fileIndex
472 540 self.filename
473 541 self.fileSize
474 542 self.fp
475 543
476 544 Return:
477 545 0 : si un determinado file no puede ser abierto
478 546 1 : si el file fue abierto con exito
479 547
480 548 Excepciones:
481 549 Si un determinado file no puede ser abierto
482 550 """
483 551 idFile = self.fileIndex
484 552 while(True):
485 553
486 554 idFile += 1
487 555
488 556 if not(idFile < len(self.filenameList)):
489 557 self.flagNoMoreFiles = 1
490 558 print 'No more Files'
491 559 return 0
492 560
493 561 filename = self.filenameList[idFile]
494 562 fileSize = os.path.getsize(filename)
495 563
496 564 try:
497 565 fp = open(filename,'rb')
498 566 except:
499 567 raise IOError, "The file %s can't be opened" %filename
500 568
501 569 currentSize = fileSize - fp.tell()
502 570 neededSize = self.m_ProcessingHeader.blockSize + self.firstHeaderSize
503 571
504 572 if (currentSize < neededSize):
505 573 print "Skipping the file %s due to it hasn't enough data" %filename
506 574 continue
507 575
508 576 break
509 577
510 578 self.flagIsNewFile = 1
511 579 self.fileIndex = idFile
512 580 self.filename = filename
513 581 self.fileSize = fileSize
514 582 self.fp = fp
515 583
516 584 print 'Setting the file: %s'%self.filename
517 585
518 586 return 1
519 587
520 588
521 589 def setNextFile(self):
522 590 """
523 591 Determina el siguiente file a leer y si hay uno disponible lee el First Header
524 592
525 593 Affected:
526 594 self.m_BasicHeader
527 595 self.m_SystemHeader
528 596 self.m_RadarControllerHeader
529 597 self.m_ProcessingHeader
530 598 self.firstHeaderSize
531 599
532 600 Return:
533 601 0 : Si no hay files disponibles
534 602 1 : Si hay mas files disponibles
535 603 """
536 604 if self.fp != None:
537 605 self.fp.close()
538 606
539 607 if self.online:
540 608 newFile = self.__setNextFileOnline()
541 609 else:
542 610 newFile = self.__setNextFileOffline()
543
544 if self.flagNoMoreFiles:
545 sys.exit(0)
546 611
547 612 if not(newFile):
548 613 return 0
549 614
550 615 self.__readFirstHeader()
551 self.nBlocks = 0
616 self.nReadBlocks = 0
552 617 return 1
553
554
555 def __setNewBlock(self):
556 """
557 Lee el Basic Header y posiciona le file pointer en la posicion inicial del bloque a leer
558 618
559 Affected:
560 self.m_BasicHeader
561 self.flagNoContinuousBlock
562 self.ns
563
564 Return:
565 0 : Si el file no tiene un Basic Header que pueda ser leido
566 1 : Si se pudo leer el Basic Header
567 """
568 if self.fp == None:
569 return 0
570
571 if self.flagIsNewFile:
572 return 1
573
574 currentSize = self.fileSize - self.fp.tell()
575 neededSize = self.m_ProcessingHeader.blockSize + self.basicHeaderSize
576
577 #If there is enough data setting new data block
578 if ( currentSize >= neededSize ):
579 self.__rdBasicHeader()
580 return 1
581
582 #si es OnLine y ademas aun no se han leido un bloque completo entonces se espera por uno valido
583 elif (self.nBlocks != self.m_ProcessingHeader.dataBlocksPerFile) and self.online:
584 for nTries in range( self.nTries ):
585
586 fpointer = self.fp.tell()
587 self.fp.close()
588
589 print "\tWaiting %0.2f sec for the next block, try %03d ..." % (self.delay, nTries+1)
590 time.sleep( self.delay )
591
592 self.fp = open( self.filename, 'rb' )
593 self.fp.seek( fpointer )
594
595 self.fileSize = os.path.getsize( self.filename )
596 currentSize = self.fileSize - self.fp.tell()
597 neededSize = self.m_ProcessingHeader.blockSize + self.basicHeaderSize
598
599 if ( currentSize >= neededSize ):
600 self.__rdBasicHeader()
601 return 1
602
603 #Setting new file
604 if not( self.setNextFile() ):
605 return 0
606
607 deltaTime = self.m_BasicHeader.utc - self.lastUTTime # check this
608
609 self.flagResetProcessing = 0
610
611 if deltaTime > self.maxTimeStep:
612 self.flagResetProcessing = 1
613 #self.nReadBlocks = 0
614
615 return 1
616
617
618 619 def __searchFilesOnLine(self, path, startDateTime=None, endDateTime=None, expLabel = "", ext = None):
619 620 """
620 621 Busca el ultimo archivo de la ultima carpeta (determinada o no por startDateTime) y
621 622 devuelve el archivo encontrado ademas de otros datos.
622 623
623 624 Input:
624 625 path : carpeta donde estan contenidos los files que contiene data
625 626 startDateTime : punto especifico en el tiempo del cual se requiere la data
626 627 ext : extension de los files
627 628
628 629 Return:
629 630 year : el anho
630 631 doy : el numero de dia del anho
631 632 set : el set del archivo
632 633 filename : el ultimo file de una determinada carpeta
633 634 directory : eL directorio donde esta el file encontrado
634 635 """
635 636 dirList = []
636 637 pathList = []
637 638 directory = None
638 639
639 640 for thisPath in os.listdir(path):
640 641 if os.path.isdir(os.path.join(path,thisPath)):
641 642 dirList.append(thisPath)
642 643
643 644 if not(dirList):
644 645 return None, None, None, None, None
645 646
646 647 dirList = sorted( dirList, key=str.lower )
647 648
648 649 if startDateTime:
649 650 thisDateTime = startDateTime
650 651 if endDateTime == None: endDateTime = startDateTime
651 652
652 653 while(thisDateTime <= endDateTime):
653 654 year = thisDateTime.timetuple().tm_year
654 655 doy = thisDateTime.timetuple().tm_yday
655 656
656 657 match = fnmatch.filter(dirList, '?' + '%4.4d%3.3d' % (year,doy))
657 658 if len(match) == 0:
658 659 thisDateTime += datetime.timedelta(1)
659 660 continue
660 661
661 662 pathList.append(os.path.join(path,match[0], expLabel))
662 663 thisDateTime += datetime.timedelta(1)
663 664
664 665 if not(pathList):
665 666 print "\tNo files in range: %s - %s" %(startDateTime.ctime(), endDateTime.ctime())
666 667 return None, None, None, None, None
667 668
668 669 directory = pathList[0]
669 670
670 671 else:
671 672 directory = dirList[-1]
672 673 directory = os.path.join(path,directory)
673 674
674 675 filename = getlastFileFromPath(directory, ext)
675 676
676 677 if not(filename):
677 678 return None, None, None, None, None
678 679
679 680 if not(self.__verifyFile(os.path.join(directory, filename))):
680 681 return None, None, None, None, None
681 682
682 683 year = int( filename[1:5] )
683 684 doy = int( filename[5:8] )
684 685 set = int( filename[8:11] )
685 686
686 687 return directory, filename, year, doy, set
687 688
688 689
689 690 def __searchFilesOffLine(self, path, startDateTime, endDateTime, set=None, expLabel = "", ext = ".r"):
690 691 """
691 692 Realiza una busqueda de los archivos que coincidan con los parametros
692 693 especificados y se encuentren ubicados en el path indicado. Para realizar una busqueda
693 694 correcta la estructura de directorios debe ser la siguiente:
694 695
695 696 ...path/D[yyyy][ddd]/expLabel/D[yyyy][ddd][sss].ext
696 697
697 698 [yyyy]: anio
698 699 [ddd] : dia del anio
699 700 [sss] : set del archivo
700 701
701 702 Inputs:
702 703 path : Directorio de datos donde se realizara la busqueda. Todos los
703 704 ficheros que concidan con el criterio de busqueda seran
704 705 almacenados en una lista y luego retornados.
705 706 startDateTime : Fecha inicial. Rechaza todos los archivos donde
706 707 file end time < startDateTime (obejto datetime.datetime)
707 708
708 709 endDateTime : Fecha final. Rechaza todos los archivos donde
709 710 file start time > endDateTime (obejto datetime.datetime)
710 711
711 712 set : Set del primer archivo a leer. Por defecto None
712 713
713 714 expLabel : Nombre del subdirectorio de datos. Por defecto ""
714 715
715 716 ext : Extension de los archivos a leer. Por defecto .r
716 717
717 718 Return:
718 719
719 720 (pathList, filenameList)
720 721
721 722 pathList : Lista de directorios donde se encontraron archivos dentro
722 723 de los parametros especificados
723 724 filenameList : Lista de archivos (ruta completa) que coincidieron con los
724 725 parametros especificados.
725 726
726 727 Variables afectadas:
727 728
728 729 self.filenameList: Lista de archivos (ruta completa) que la clase utiliza
729 730 como fuente para leer los bloque de datos, si se termina
730 731 de leer todos los bloques de datos de un determinado
731 732 archivo se pasa al siguiente archivo de la lista.
732 733
733 734 Excepciones:
734 735
735 736 """
736 737
737 738 print "Searching files ..."
738 739
739 740 dirList = []
740 741 for thisPath in os.listdir(path):
741 742 if os.path.isdir(os.path.join(path,thisPath)):
742 743 dirList.append(thisPath)
743 744
744 745 if not(dirList):
745 746 return None, None
746 747
747 748 pathList = []
748 749
749 750 thisDateTime = startDateTime
750 751
751 752 while(thisDateTime <= endDateTime):
752 753 year = thisDateTime.timetuple().tm_year
753 754 doy = thisDateTime.timetuple().tm_yday
754 755
755 756 match = fnmatch.filter(dirList, '?' + '%4.4d%3.3d' % (year,doy))
756 757 if len(match) == 0:
757 758 thisDateTime += datetime.timedelta(1)
758 759 continue
759 760
760 761 pathList.append(os.path.join(path,match[0],expLabel))
761 762 thisDateTime += datetime.timedelta(1)
762 763
763 764 startUtSeconds = time.mktime(startDateTime.timetuple())
764 765 endUtSeconds = time.mktime(endDateTime.timetuple())
765 766
766 767 filenameList = []
767 768 for thisPath in pathList:
768 769 fileList = glob.glob1(thisPath, "*%s" %ext)
769 770 fileList.sort()
770 771 for file in fileList:
771 772 filename = os.path.join(thisPath,file)
772 773 if isThisFileinRange(filename, startUtSeconds, endUtSeconds):
773 774 filenameList.append(filename)
774 775
775 776 if not(filenameList):
776 777 return None, None
777 778
778 779 self.filenameList = filenameList
779 780
780 781 return pathList, filenameList
781 782
782 783
783 784 def __verifyFile(self, filename, msgFlag=True):
784 785 """
785 786 Verifica que el filename tenga data valida, para ello leo el FirstHeader del file
786 787
787 788 Return:
788 789 0 : file no valido para ser leido
789 790 1 : file valido para ser leido
790 791 """
791 792 m_BasicHeader = BasicHeader()
792 793 m_SystemHeader = SystemHeader()
793 794 m_RadarControllerHeader = RadarControllerHeader()
794 795 m_ProcessingHeader = ProcessingHeader()
795 796 flagFileOK = False
796 797
797 798 try:
798 799 fp = open( filename,'rb' ) #lectura binaria
799 800 except:
800 801 if msgFlag:
801 802 print "The file %s can't be opened" % (filename)
802 803
803 804 try:
804 805 if not( m_BasicHeader.read(fp) ): raise ValueError
805 806 if not( m_SystemHeader.read(fp) ): raise ValueError
806 807 if not( m_RadarControllerHeader.read(fp) ): raise ValueError
807 808 if not( m_ProcessingHeader.read(fp) ): raise ValueError
808 809 data_type = int(numpy.log2((m_ProcessingHeader.processFlags & PROCFLAG.DATATYPE_MASK))-numpy.log2(PROCFLAG.DATATYPE_CHAR))
809 810 if m_BasicHeader.size > self.basicHeaderSize:
810 811 flagFileOK = True
811 812 except:
812 813 if msgFlag:
813 814 print "\tThe file %s is empty or it hasn't enough data" % filename
814 815
815 816 fp.close()
816 817
817 818 if not(flagFileOK):
818 819 return 0
819 820
820 821 return 1
821
822 822
823 def updateDataHeader(self):
824
825 self.m_DataObj.m_BasicHeader = self.m_BasicHeader.copy()
826 self.m_DataObj.m_ProcessingHeader = self.m_ProcessingHeader.copy()
827 self.m_DataObj.m_RadarControllerHeader = self.m_RadarControllerHeader.copy()
828 self.m_DataObj.m_SystemHeader = self.m_SystemHeader.copy()
829
830 self.m_DataObj.updateObjFromHeader()
831
823 832 def setup(self, path, startDateTime=None, endDateTime=None, set=0, expLabel = "", ext = None, online = 0):
824 833 """
825 834 setup configura los parametros de lectura de la clase DataReader.
826 835
827 836 Si el modo de lectura es offline, primero se realiza una busqueda de todos los archivos
828 837 que coincidan con los parametros especificados; esta lista de archivos son almacenados en
829 838 self.filenameList.
830 839
831 840 Input:
832 841 path : Directorios donde se ubican los datos a leer. Dentro de este
833 842 directorio deberia de estar subdirectorios de la forma:
834 843
835 844 path/D[yyyy][ddd]/expLabel/P[yyyy][ddd][sss][ext]
836 845
837 846 startDateTime : Fecha inicial. Rechaza todos los archivos donde
838 847 file end time < startDatetime (obejto datetime.datetime)
839 848
840 849 endDateTime : Fecha final. Si no es None, rechaza todos los archivos donde
841 850 file end time < startDatetime (obejto datetime.datetime)
842 851
843 852 set : Set del primer archivo a leer. Por defecto None
844 853
845 854 expLabel : Nombre del subdirectorio de datos. Por defecto ""
846 855
847 856 ext : Extension de los archivos a leer. Por defecto .r
848 857
849 858 online : Si es == a 0 entonces busca files que cumplan con las condiciones dadas
850 859
851 860 Return:
852 861 0 : Si no encuentra files que cumplan con las condiciones dadas
853 862 1 : Si encuentra files que cumplan con las condiciones dadas
854 863
855 864 Affected:
856 865 self.startUTCSeconds
857 866 self.endUTCSeconds
858 867 self.startYear
859 868 self.endYear
860 869 self.startDoy
861 870 self.endDoy
862 871 self.pathList
863 872 self.filenameList
864 873 self.online
865 874 """
866 875
867 876 if ext == None:
868 877 ext = self.ext
869 878
870 879 if online:
871 880 print "Searching files ..."
872 881 doypath, file, year, doy, set = self.__searchFilesOnLine(path, startDateTime, endDateTime, expLabel, ext)
873 882
874 883 if not(doypath):
875 884 for nTries in range( self.nTries ):
876 885 print '\tWaiting %0.2f sec for valid file in %s: try %02d ...' % (self.delay, path, nTries+1)
877 886 time.sleep( self.delay )
878 887 doypath, file, year, doy, set = self.__searchFilesOnLine(path, startDateTime, endDateTime, expLabel, ext)
879 888 if doypath:
880 889 break
881 890
882 891 if not(doypath):
883 892 print "There 'isn't valied files in %s" % path
884 893 return 0
885 894
886 895 self.year = year
887 896 self.doy = doy
888 897 self.set = set - 1
889 898 self.path = path
890 899
891 900 else: # offline
892 901 pathList, filenameList = self.__searchFilesOffLine(path, startDateTime, endDateTime, set, expLabel, ext)
893 902 if not(pathList):
894 903 print "No files in range: %s - %s" %(startDateTime.ctime(), endDateTime.ctime())
895 904 return 0
896 905
897 906 self.fileIndex = -1
898 907 self.pathList = pathList
899 908 self.filenameList = filenameList
900 909
901 910 self.online = online
902 911 self.ext = ext
903 912
904 913 ext = ext.lower()
905 914
906 915 if not( self.setNextFile() ):
907 916 if (startDateTime != None) and (endDateTime != None):
908 917 print "No files in range: %s - %s" %(startDateTime.ctime(), endDateTime.ctime())
909 918 elif startDateTime != None:
910 919 print "No files in : %s" % startDateTime.ctime()
911 920 else:
912 921 print "No files"
913 922 return 0
914 923
915 924 if startDateTime != None:
916 925 self.startUTCSeconds = time.mktime(startDateTime.timetuple())
917 926 self.startYear = startDateTime.timetuple().tm_year
918 927 self.startDoy = startDateTime.timetuple().tm_yday
919 928
920 929 if endDateTime != None:
921 930 self.endUTCSeconds = time.mktime(endDateTime.timetuple())
922 931 self.endYear = endDateTime.timetuple().tm_year
923 932 self.endDoy = endDateTime.timetuple().tm_yday
924 933 #call fillHeaderValues() - to Data Object
925 934
926 self.m_DataObj.m_BasicHeader = self.m_BasicHeader.copy()
927 self.m_DataObj.m_ProcessingHeader = self.m_ProcessingHeader.copy()
928 self.m_DataObj.m_RadarControllerHeader = self.m_RadarControllerHeader.copy()
929 self.m_DataObj.m_SystemHeader = self.m_SystemHeader.copy()
930 self.m_DataObj.dataType = self.dataType
935 self.updateDataHeader()
931 936
932 return 1
933
934
935 def readNextBlock(self):
936 """
937 Establece un nuevo bloque de datos a leer y los lee, si es que no existiese
938 mas bloques disponibles en el archivo actual salta al siguiente.
939
940 Affected:
941 self.lastUTTime
942
943 Return: None
944 """
945 if not(self.__setNewBlock()):
946 return 0
947
948 if not(self.readBlock()):
949 return 0
950
951 self.lastUTTime = self.m_BasicHeader.utc
952
953 937 return 1
954
955
956 class JRODataWriter(DataWriter):
938
939 class JRODataWriter(JRODataIO):
957 940
958 941 """
959 942 Esta clase permite escribir datos a archivos procesados (.r o ,pdata). La escritura
960 943 de los datos siempre se realiza por bloques.
961 944 """
962 945
963 m_BasicHeader = BasicHeader()
964
965 m_SystemHeader = SystemHeader()
966
967 m_RadarControllerHeader = RadarControllerHeader()
968
969 m_ProcessingHeader = ProcessingHeader()
970
971 fp = None
972
973 blocksCounter = 0
974
975 flagIsNewFile = 1
976
977 nWriteBlocks = 0
978
979 flagIsNewBlock = 0
980
981 flagNoMoreFiles = 0
982
983 m_DataObj = None
984
985 fp = None
986
987 blocksCounter = 0
988
989 flagIsNewFile = 1
990
991 946 nWriteBlocks = 0
992
993 flagIsNewBlock = 0
994
995 flagNoMoreFiles = 0
996 947
997 948 setFile = None
998
999 dataType = None
1000
1001 path = None
1002
1003 noMoreFiles = 0
1004
1005 filename = None
1006
1007 channelList = None
1008 949
1009 950
1010 951 def __init__(self, m_DataObj=None):
1011 952 raise ValueError, "Not implemented"
1012 953
1013 954
1014 955 def hasAllDataInBuffer(self):
1015 956 raise ValueError, "Not implemented"
1016 957
1017 958
1018 959 def setBlockDimension(self):
1019 960 raise ValueError, "Not implemented"
1020 961
1021 962
1022 963 def writeBlock(self):
1023 964 raise ValueError, "No implemented"
1024 965
1025 966
1026 967 def putData(self):
1027 968 raise ValueError, "No implemented"
1028 969
1029 970
1030 971 def __writeFirstHeader(self):
1031 972 """
1032 973 Escribe el primer header del file es decir el Basic header y el Long header (SystemHeader, RadarControllerHeader, ProcessingHeader)
1033 974
1034 975 Affected:
1035 976 __dataType
1036 977
1037 978 Return:
1038 979 None
1039 980 """
1040 981 self.__writeBasicHeader()
1041 982 self.__wrSystemHeader()
1042 983 self.__wrRadarControllerHeader()
1043 984 self.__wrProcessingHeader()
1044 985 self.dataType = self.m_DataObj.dataType
1045 986
1046 987
1047 988 def __writeBasicHeader(self, fp=None):
1048 989 """
1049 990 Escribe solo el Basic header en el file creado
1050 991
1051 992 Return:
1052 993 None
1053 994 """
1054 995 if fp == None:
1055 996 fp = self.fp
1056 997
1057 998 self.m_DataObj.m_BasicHeader.write(fp)
1058 999
1059 1000
1060 1001 def __wrSystemHeader(self, fp=None):
1061 1002 """
1062 1003 Escribe solo el System header en el file creado
1063 1004
1064 1005 Return:
1065 1006 None
1066 1007 """
1067 1008 if fp == None:
1068 1009 fp = self.fp
1069 1010
1070 1011 self.m_DataObj.m_SystemHeader.write(fp)
1071 1012
1072 1013
1073 1014 def __wrRadarControllerHeader(self, fp=None):
1074 1015 """
1075 1016 Escribe solo el RadarController header en el file creado
1076 1017
1077 1018 Return:
1078 1019 None
1079 1020 """
1080 1021 if fp == None:
1081 1022 fp = self.fp
1082 1023
1083 1024 self.m_DataObj.m_RadarControllerHeader.write(fp)
1084 1025
1085 1026
1086 1027 def __wrProcessingHeader(self, fp=None):
1087 1028 """
1088 1029 Escribe solo el Processing header en el file creado
1089 1030
1090 1031 Return:
1091 1032 None
1092 1033 """
1093 1034 if fp == None:
1094 1035 fp = self.fp
1095 1036
1096 1037 self.m_DataObj.m_ProcessingHeader.write(fp)
1097 1038
1098 1039
1099 1040 def setNextFile(self):
1100 1041 """
1101 1042 Determina el siguiente file que sera escrito
1102 1043
1103 1044 Affected:
1104 1045 self.filename
1105 1046 self.subfolder
1106 1047 self.fp
1107 1048 self.setFile
1108 1049 self.flagIsNewFile
1109 1050
1110 1051 Return:
1111 1052 0 : Si el archivo no puede ser escrito
1112 1053 1 : Si el archivo esta listo para ser escrito
1113 1054 """
1114 1055 ext = self.ext
1115 1056 path = self.path
1116 1057
1117 1058 if self.fp != None:
1118 1059 self.fp.close()
1119 1060
1120 1061 timeTuple = time.localtime( self.m_DataObj.m_BasicHeader.utc )
1121 1062 subfolder = 'D%4.4d%3.3d' % (timeTuple.tm_year,timeTuple.tm_yday)
1122 1063
1123 tmp = os.path.join( path, subfolder )
1124 if not( os.path.exists(tmp) ):
1125 os.mkdir(tmp)
1064 doypath = os.path.join( path, subfolder )
1065 if not( os.path.exists(doypath) ):
1066 os.mkdir(doypath)
1126 1067 self.setFile = -1 #inicializo mi contador de seteo
1127 1068 else:
1128 filesList = os.listdir( tmp )
1069 filesList = os.listdir( doypath )
1129 1070 if len( filesList ) > 0:
1130 1071 filesList = sorted( filesList, key=str.lower )
1131 1072 filen = filesList[-1]
1132 1073 # el filename debera tener el siguiente formato
1133 1074 # 0 1234 567 89A BCDE (hex)
1134 1075 # x YYYY DDD SSS .ext
1135 1076 if isNumber( filen[8:11] ):
1136 1077 self.setFile = int( filen[8:11] ) #inicializo mi contador de seteo al seteo del ultimo file
1137 1078 else:
1138 1079 self.setFile = -1
1139 1080 else:
1140 1081 self.setFile = -1 #inicializo mi contador de seteo
1141 1082
1142 1083 setFile = self.setFile
1143 1084 setFile += 1
1144 1085
1145 1086 file = '%s%4.4d%3.3d%3.3d%s' % (self.optchar,
1146 1087 timeTuple.tm_year,
1147 1088 timeTuple.tm_yday,
1148 1089 setFile,
1149 1090 ext )
1150 1091
1151 1092 filename = os.path.join( path, subfolder, file )
1152 1093
1153 1094 fp = open( filename,'wb' )
1154 1095
1155 self.blocksCounter = 0
1096 self.nWriteBlocks = 0
1156 1097
1157 1098 #guardando atributos
1158 1099 self.filename = filename
1159 1100 self.subfolder = subfolder
1160 1101 self.fp = fp
1161 1102 self.setFile = setFile
1162 1103 self.flagIsNewFile = 1
1163 1104
1164 1105 print 'Writing the file: %s'%self.filename
1165 1106
1166 1107 self.__writeFirstHeader()
1167 1108
1168 1109 return 1
1169 1110
1170 1111
1171 1112 def __setNewBlock(self):
1172 1113 """
1173 1114 Si es un nuevo file escribe el First Header caso contrario escribe solo el Basic Header
1174 1115
1175 1116 Return:
1176 1117 0 : si no pudo escribir nada
1177 1118 1 : Si escribio el Basic el First Header
1178 1119 """
1179 1120 if self.fp == None:
1180 1121 self.setNextFile()
1181 1122
1182 1123 if self.flagIsNewFile:
1183 1124 return 1
1184 1125
1185 if self.blocksCounter < self.m_ProcessingHeader.dataBlocksPerFile:
1126 if self.nWriteBlocks < self.m_ProcessingHeader.dataBlocksPerFile:
1186 1127 self.__writeBasicHeader()
1187 1128 return 1
1188 1129
1189 1130 if not( self.setNextFile() ):
1190 1131 return 0
1191 1132
1192 1133 return 1
1193 1134
1194 1135
1195 1136 def writeNextBlock(self):
1196 1137 """
1197 1138 Selecciona el bloque siguiente de datos y los escribe en un file
1198 1139
1199 1140 Return:
1200 1141 0 : Si no hizo pudo escribir el bloque de datos
1201 1142 1 : Si no pudo escribir el bloque de datos
1202 1143 """
1203 1144 if not( self.__setNewBlock() ):
1204 1145 return 0
1205 1146
1206 1147 self.writeBlock()
1207 1148
1208 1149 return 1
1209 1150
1210 1151
1211 def getHeader(self):
1152 def getDataHeader(self):
1212 1153 """
1213 1154 Obtiene una copia del First Header
1214 1155
1215 1156 Affected:
1216 1157 self.m_BasicHeader
1217 1158 self.m_SystemHeader
1218 1159 self.m_RadarControllerHeader
1219 1160 self.m_ProcessingHeader
1220 1161 self.dataType
1221 1162
1222 1163 Return:
1223 1164 None
1224 1165 """
1166 self.m_DataObj.updateHeaderFromObj()
1167
1225 1168 self.m_BasicHeader = self.m_DataObj.m_BasicHeader.copy()
1226 1169 self.m_SystemHeader = self.m_DataObj.m_SystemHeader.copy()
1227 1170 self.m_RadarControllerHeader = self.m_DataObj.m_RadarControllerHeader.copy()
1228 1171 self.m_ProcessingHeader = self.m_DataObj.m_ProcessingHeader.copy()
1172
1229 1173 self.dataType = self.m_DataObj.dataType
1230
1174
1231 1175
1232 1176 def setup(self, path, set=0, ext=None):
1233 1177 """
1234 1178 Setea el tipo de formato en la cual sera guardada la data y escribe el First Header
1235 1179
1236 1180 Inputs:
1237 1181 path : el path destino en el cual se escribiran los files a crear
1238 1182 format : formato en el cual sera salvado un file
1239 1183 set : el setebo del file
1240 1184
1241 1185 Return:
1242 1186 0 : Si no realizo un buen seteo
1243 1187 1 : Si realizo un buen seteo
1244 1188 """
1245 1189
1246 1190 if ext == None:
1247 1191 ext = self.ext
1248 1192
1249 1193 ext = ext.lower()
1250 1194
1251 1195 self.path = path
1252 1196 self.setFile = set - 1
1253 1197 self.ext = ext
1254 1198 #self.format = format
1255 self.getHeader()
1199 self.getDataHeader()
1256 1200
1257 1201 self.setBlockDimension()
1258 1202
1259 1203 if not( self.setNextFile() ):
1260 1204 print "There isn't a next file"
1261 1205 return 0
1262 1206
1263 1207 return 1
@@ -1,566 +1,536
1 1 '''
2 2 File: SpectraIO.py
3 3 Created on 20/02/2012
4 4
5 5 @author $Author$
6 6 @version $Id$
7 7 '''
8 8
9 9 import os, sys
10 10 import numpy
11 11 import glob
12 12 import fnmatch
13 13 import time, datetime
14 14
15 15 path = os.path.split(os.getcwd())[0]
16 16 sys.path.append(path)
17 17
18 18 from Model.JROHeader import *
19 19 from Model.Spectra import Spectra
20 20
21 from DataIO import JRODataReader
22 from DataIO import JRODataWriter
23 from DataIO import isNumber
21 from JRODataIO import JRODataReader
22 from JRODataIO import JRODataWriter
23 from JRODataIO import isNumber
24 24
25 25
26 26 class SpectraReader( JRODataReader ):
27 27 """
28 28 Esta clase permite leer datos de espectros desde archivos procesados (.pdata). La lectura
29 29 de los datos siempre se realiza por bloques. Los datos leidos (array de 3 dimensiones)
30 30 son almacenados en tres buffer's para el Self Spectra, el Cross Spectra y el DC Channel.
31 31
32 32 paresCanalesIguales * alturas * perfiles (Self Spectra)
33 33 paresCanalesDiferentes * alturas * perfiles (Cross Spectra)
34 34 canales * alturas (DC Channels)
35 35
36 36 Esta clase contiene instancias (objetos) de las clases BasicHeader, SystemHeader,
37 37 RadarControllerHeader y Spectra. Los tres primeros se usan para almacenar informacion de la
38 38 cabecera de datos (metadata), y el cuarto (Spectra) para obtener y almacenar un bloque de
39 39 datos desde el "buffer" cada vez que se ejecute el metodo "getData".
40 40
41 41 Example:
42 42 dpath = "/home/myuser/data"
43 43
44 44 startTime = datetime.datetime(2010,1,20,0,0,0,0,0,0)
45 45
46 46 endTime = datetime.datetime(2010,1,21,23,59,59,0,0,0)
47 47
48 48 readerObj = SpectraReader()
49 49
50 50 readerObj.setup(dpath, startTime, endTime)
51 51
52 52 while(True):
53 53
54 54 readerObj.getData()
55 55
56 56 print readerObj.m_Spectra.data
57 57
58 58 if readerObj.flagNoMoreFiles:
59 59 break
60 60
61 61 """
62 62 m_DataObj = None
63 63
64 64 data_spc = None
65 65 data_cspc = None
66 66 data_dc = None
67 67
68 68 pts2read_SelfSpectra = 0
69 69 pts2read_CrossSpectra = 0
70 70 pts2read_DCchannels = 0
71 71
72 72 nChannels = 0
73 73
74 74 nPairs = 0
75 75
76 76 #pairList = None
77 77
78 78 channelList = None
79 79
80 80 def __init__(self, m_Spectra=None):
81 81 """
82 82 Inicializador de la clase SpectraReader para la lectura de datos de espectros.
83 83
84 84 Inputs:
85 85 m_Spectra : Objeto de la clase Spectra. Este objeto sera utilizado para
86 86 almacenar un perfil de datos cada vez que se haga un requerimiento
87 87 (getData). El perfil sera obtenido a partir del buffer de datos,
88 88 si el buffer esta vacio se hara un nuevo proceso de lectura de un
89 89 bloque de datos.
90 90 Si este parametro no es pasado se creara uno internamente.
91 91
92 92 Affected:
93 93 self.m_DataObj
94 94
95 95 Return : None
96 96 """
97 97 if m_Spectra == None:
98 98 m_Spectra = Spectra()
99 99
100 100 if not( isinstance(m_Spectra, Spectra) ):
101 101 raise ValueError, "in SpectraReader, m_Spectra must be an Spectra class object"
102 102
103 103 self.m_DataObj = m_Spectra
104 104
105 105 self.data_spc = None
106 106 self.data_cspc = None
107 107 self.data_dc = None
108 108
109 109 self.pts2read_SelfSpectra = 0
110 110 self.pts2read_CrossSpectra = 0
111 111 self.pts2read_DCs = 0
112 112
113 113 self.nChannels = 0
114 114
115 115 self.nPairs = 0
116 116
117 117 self.ext = ".pdata"
118 118
119 119 self.optchar = "P"
120 120
121 121 ######################
122 122
123 123 self.m_BasicHeader = BasicHeader()
124 124
125 125 self.m_SystemHeader = SystemHeader()
126 126
127 127 self.m_RadarControllerHeader = RadarControllerHeader()
128 128
129 129 self.m_ProcessingHeader = ProcessingHeader()
130 130
131 131 self.online = 0
132 132
133 133 self.fp = None
134 134
135 135 self.fileSizeByHeader = None
136 136
137 137 self.filenameList = []
138 138
139 139 self.filename = None
140 140
141 141 self.fileSize = None
142 142
143 143 self.firstHeaderSize = 0
144 144
145 145 self.basicHeaderSize = 24
146 146
147 147 self.dataType = None
148 148
149 149 self.maxTimeStep = 30
150 150
151 151 self.flagNoMoreFiles = 0
152 152
153 153 self.set = 0
154 154
155 155 self.path = None
156 156
157 157 self.delay = 3 #seconds
158 158
159 159 self.nTries = 3 #quantity tries
160 160
161 161 self.nFiles = 3 #number of files for searching
162 162
163 self.nBlocks = 0
163 self.nReadBlocks = 0
164 164
165 165 self.flagIsNewFile = 1
166 166
167 167 self.ippSeconds = 0
168 168
169 169 self.flagResetProcessing = 0
170 170
171 171 self.flagIsNewBlock = 0
172 172
173 self.nReadBlocks = 0
173 self.nTotalBlocks = 0
174 174
175 175 self.blocksize = 0
176 176
177 177 #pairList = None
178 178
179 179 channelList = None
180 180
181 181
182 182 def __hasNotDataInBuffer(self):
183 183 return 1
184 184
185 185
186 186 def getBlockDimension(self):
187 187 """
188 188 Obtiene la cantidad de puntos a leer por cada bloque de datos
189 189
190 190 Affected:
191 191 self.nChannels
192 192 self.nPairs
193 193 self.pts2read_SelfSpectra
194 194 self.pts2read_CrossSpectra
195 195 self.pts2read_DCchannels
196 196 self.blocksize
197 197 self.m_DataObj.nChannels
198 198 self.m_DataObj.nPairs
199 199
200 200 Return:
201 201 None
202 202 """
203 203 self.nChannels = 0
204 204 self.nPairs = 0
205 #self.pairList = []
205 self.pairList = []
206 206
207 207 for i in range( 0, self.m_ProcessingHeader.totalSpectra*2, 2 ):
208 208 if self.m_ProcessingHeader.spectraComb[i] == self.m_ProcessingHeader.spectraComb[i+1]:
209 209 self.nChannels = self.nChannels + 1 #par de canales iguales
210 210 else:
211 211 self.nPairs = self.nPairs + 1 #par de canales diferentes
212 #self.pairList.append( (self.m_ProcessingHeader.spectraComb[i], self.m_ProcessingHeader.spectraComb[i+1]) )
212 self.pairList.append( (self.m_ProcessingHeader.spectraComb[i], self.m_ProcessingHeader.spectraComb[i+1]) )
213 213
214 214 pts2read = self.m_ProcessingHeader.numHeights * self.m_ProcessingHeader.profilesPerBlock
215 215
216 216 self.pts2read_SelfSpectra = int( self.nChannels * pts2read )
217 217 self.pts2read_CrossSpectra = int( self.nPairs * pts2read )
218 218 self.pts2read_DCchannels = int( self.m_SystemHeader.numChannels * self.m_ProcessingHeader.numHeights )
219 219
220 self.blocksize = self.pts2read_SelfSpectra + self.pts2read_CrossSpectra + self.pts2read_DCchannels
220 self.blocksize = self.pts2read_SelfSpectra + self.pts2read_CrossSpectra + self.pts2read_DCchannels
221 221
222 self.m_DataObj.nPoints = self.m_ProcessingHeader.profilesPerBlock
223 self.m_DataObj.nChannels = self.nChannels
224 self.m_DataObj.nPairs = self.nPairs
225
226 #self.pairList = tuple( self.pairList )
227 222 self.channelList = numpy.arange( self.nChannels )
228 223
229 224
230 225 def readBlock(self):
231 226 """
232 227 Lee el bloque de datos desde la posicion actual del puntero del archivo
233 228 (self.fp) y actualiza todos los parametros relacionados al bloque de datos
234 229 (metadata + data). La data leida es almacenada en el buffer y el contador del buffer
235 230 es seteado a 0
236 231
237 232 Return: None
238 233
239 234 Variables afectadas:
240 235 self.datablockIndex
241 236 self.flagIsNewFile
242 237 self.flagIsNewBlock
243 self.nReadBlocks
238 self.nTotalBlocks
244 239 self.data_spc
245 240 self.data_cspc
246 241 self.data_dc
247 242
248 243 Exceptions:
249 244 Si un bloque leido no es un bloque valido
250 245 """
251 246 blockOk_flag = False
252 247 fpointer = self.fp.tell()
253 248
254 249 spc = numpy.fromfile( self.fp, self.dataType[0], self.pts2read_SelfSpectra )
255 250 cspc = numpy.fromfile( self.fp, self.dataType, self.pts2read_CrossSpectra )
256 251 dc = numpy.fromfile( self.fp, self.dataType, self.pts2read_DCchannels ) #int(self.m_ProcessingHeader.numHeights*self.m_SystemHeader.numChannels) )
257
258 if self.online:
259 if (spc.size + cspc.size + dc.size) != self.blocksize:
260 for nTries in range( self.nTries ):
261 print "\tWaiting %0.2f sec for the next block, try %03d ..." % (self.delay, nTries+1)
262 time.sleep( self.delay )
263 self.fp.seek( fpointer )
264 fpointer = self.fp.tell()
265
266 spc = numpy.fromfile( self.fp, self.dataType[0], self.pts2read_SelfSpectra )
267 cspc = numpy.fromfile( self.fp, self.dataType, self.pts2read_CrossSpectra )
268 dc = numpy.fromfile( self.fp, self.dataType, self.pts2read_DCchannels ) #int(self.m_ProcessingHeader.numHeights*self.m_SystemHeader.numChannels) )
269
270 if (spc.size + cspc.size + dc.size) == self.blocksize:
271 blockOk_flag = True
272 break
273
274 if not( blockOk_flag ):
275 return 0
276 252
277 253 try:
278 254 spc = spc.reshape( (self.nChannels, self.m_ProcessingHeader.numHeights, self.m_ProcessingHeader.profilesPerBlock) ) #transforma a un arreglo 3D
279 255 if self.nPairs != 0:
280 256 cspc = cspc.reshape( (self.nPairs, self.m_ProcessingHeader.numHeights, self.m_ProcessingHeader.profilesPerBlock) ) #transforma a un arreglo 3D
281 257 else:
282 258 cspc = None
283 259 dc = dc.reshape( (self.m_SystemHeader.numChannels, self.m_ProcessingHeader.numHeights) ) #transforma a un arreglo 2D
284 260 except:
285 261 print "Data file %s is invalid" % self.filename
286 262 return 0
287 263
288 264 if not( self.m_ProcessingHeader.shif_fft ):
289 265 spc = numpy.roll( spc, self.m_ProcessingHeader.profilesPerBlock/2, axis=2 ) #desplaza a la derecha en el eje 2 determinadas posiciones
290 266 if cspc != None:
291 267 cspc = numpy.roll( cspc, self.m_ProcessingHeader.profilesPerBlock/2, axis=2 ) #desplaza a la derecha en el eje 2 determinadas posiciones
292 268
293 269 spc = numpy.transpose( spc, (0,2,1) )
294 270 if cspc != None: cspc = numpy.transpose( cspc, (0,2,1) )
295 271
296 272 self.data_spc = spc
297 273 if cspc != None:
298 274 self.data_cspc = cspc['real'] + cspc['imag']*1j
299 275 else:
300 276 self.data_cspc = None
301 277 self.data_dc = dc['real'] + dc['imag']*1j
302 278
303 279 self.datablockIndex = 0
304 280 self.flagIsNewFile = 0
305 281 self.flagIsNewBlock = 1
306 282
283 self.nTotalBlocks += 1
307 284 self.nReadBlocks += 1
308 self.nBlocks += 1
309 285
310 286 return 1
311 287
312 288
313 289 def getData(self):
314 290 """
315 291 Copia el buffer de lectura a la clase "Spectra",
316 292 con todos los parametros asociados a este (metadata). cuando no hay datos en el buffer de
317 293 lectura es necesario hacer una nueva lectura de los bloques de datos usando "readNextBlock"
318 294
319 295 Return:
320 296 0 : Si no hay mas archivos disponibles
321 297 1 : Si hizo una buena copia del buffer
322 298
323 299 Affected:
324 300 self.m_DataObj
325 301 self.datablockIndex
326 302 self.flagResetProcessing
327 303 self.flagIsNewBlock
328 304 """
329 305
330 306 if self.flagNoMoreFiles: return 0
331 307
332 308 self.flagResetProcessing = 0
333 309 self.flagIsNewBlock = 0
334 310
335 311 if self.__hasNotDataInBuffer():
336 312
337 313 if not( self.readNextBlock() ):
338 self.setNextFile()
339 314 return 0
340 315
341 self.m_DataObj.m_BasicHeader = self.m_BasicHeader.copy()
342 self.m_DataObj.m_ProcessingHeader = self.m_ProcessingHeader.copy()
343 self.m_DataObj.m_RadarControllerHeader = self.m_RadarControllerHeader.copy()
344 self.m_DataObj.m_SystemHeader = self.m_SystemHeader.copy()
345 self.m_DataObj.heightList = self.heightList
346 self.m_DataObj.dataType = self.dataType
316 self.updateDataHeader()
347 317
348 318 if self.flagNoMoreFiles == 1:
349 319 print 'Process finished'
350 320 return 0
351 321
352 322 #data es un numpy array de 3 dmensiones (perfiles, alturas y canales)
353 323
354 324 if self.data_dc == None:
355 325 self.m_DataObj.flagNoData = True
356 326 return 0
357 327
358 328 self.m_DataObj.flagNoData = False
359 329 self.m_DataObj.flagResetProcessing = self.flagResetProcessing
360 330
361 331 self.m_DataObj.data_spc = self.data_spc
362 332 self.m_DataObj.data_cspc = self.data_cspc
363 333 self.m_DataObj.data_dc = self.data_dc
364 334
365 335 return 1
366 336
367 337
368 338 class SpectraWriter(JRODataWriter):
369 339
370 340 """
371 341 Esta clase permite escribir datos de espectros a archivos procesados (.pdata). La escritura
372 342 de los datos siempre se realiza por bloques.
373 343 """
374 344
375 345 m_DataObj = None
376 346
377 347 shape_spc_Buffer = None
378 348 shape_cspc_Buffer = None
379 349 shape_dc_Buffer = None
380 350
381 351 data_spc = None
382 352 data_cspc = None
383 353 data_dc = None
384 354
385 355
386 356 def __init__(self, m_Spectra=None):
387 357 """
388 358 Inicializador de la clase SpectraWriter para la escritura de datos de espectros.
389 359
390 360 Affected:
391 361 self.m_DataObj
392 362 self.m_BasicHeader
393 363 self.m_SystemHeader
394 364 self.m_RadarControllerHeader
395 365 self.m_ProcessingHeader
396 366
397 367 Return: None
398 368 """
399 369 if m_Spectra == None:
400 370 m_Spectra = Spectra()
401 371
402 372 if not( isinstance(m_Spectra, Spectra) ):
403 373 raise ValueError, "in SpectraReader, m_Spectra must be an Spectra class object"
404 374
405 375 self.m_DataObj = m_Spectra
406 376
407 377 self.ext = ".pdata"
408 378
409 379 self.optchar = "P"
410 380
411 381 self.shape_spc_Buffer = None
412 382 self.shape_cspc_Buffer = None
413 383 self.shape_dc_Buffer = None
414 384
415 385 self.data_spc = None
416 386 self.data_cspc = None
417 387 self.data_dc = None
418 388
419 389 ####################################
420 390
421 391 self.fp = None
422 392
423 self.blocksCounter = 0
393 self.nWriteBlocks = 0
424 394
425 395 self.flagIsNewFile = 1
426 396
427 self.nWriteBlocks = 0
397 self.nTotalBlocks = 0
428 398
429 399 self.flagIsNewBlock = 0
430 400
431 401 self.flagNoMoreFiles = 0
432 402
433 403 self.setFile = None
434 404
435 405 self.dataType = None
436 406
437 407 self.path = None
438 408
439 409 self.noMoreFiles = 0
440 410
441 411 self.filename = None
442 412
443 413 self.m_BasicHeader= BasicHeader()
444 414
445 415 self.m_SystemHeader = SystemHeader()
446 416
447 417 self.m_RadarControllerHeader = RadarControllerHeader()
448 418
449 419 self.m_ProcessingHeader = ProcessingHeader()
450 420
451 421
452 422 def hasAllDataInBuffer(self):
453 423 return 1
454 424
455 425
456 426 def setBlockDimension(self):
457 427 """
458 428 Obtiene las formas dimensionales del los subbloques de datos que componen un bloque
459 429
460 430 Affected:
461 431 self.shape_spc_Buffer
462 432 self.shape_cspc_Buffer
463 433 self.shape_dc_Buffer
464 434
465 435 Return: None
466 436 """
467 437 self.shape_spc_Buffer = (self.m_DataObj.nChannels,
468 438 self.m_ProcessingHeader.numHeights,
469 439 self.m_ProcessingHeader.profilesPerBlock)
470 440
471 441 self.shape_cspc_Buffer = (self.m_DataObj.nPairs,
472 442 self.m_ProcessingHeader.numHeights,
473 443 self.m_ProcessingHeader.profilesPerBlock)
474 444
475 445 self.shape_dc_Buffer = (self.m_SystemHeader.numChannels,
476 446 self.m_ProcessingHeader.numHeights)
477 447
478 448
479 449 def writeBlock(self):
480 450 """
481 451 Escribe el buffer en el file designado
482 452
483 453 Affected:
484 454 self.data_spc
485 455 self.data_cspc
486 456 self.data_dc
487 457 self.flagIsNewFile
488 458 self.flagIsNewBlock
489 self.nWriteBlocks
490 self.blocksCounter
459 self.nTotalBlocks
460 self.nWriteBlocks
491 461
492 462 Return: None
493 463 """
494 464
495 465 spc = numpy.transpose( self.data_spc, (0,2,1) )
496 466 if not( self.m_ProcessingHeader.shif_fft ):
497 467 spc = numpy.roll( spc, self.m_ProcessingHeader.profilesPerBlock/2, axis=2 ) #desplaza a la derecha en el eje 2 determinadas posiciones
498 468 data = spc.reshape((-1))
499 469 data.tofile(self.fp)
500 470
501 471 if self.data_cspc != None:
502 472 data = numpy.zeros( self.shape_cspc_Buffer, self.dataType )
503 473 cspc = numpy.transpose( self.data_cspc, (0,2,1) )
504 474 if not( self.m_ProcessingHeader.shif_fft ):
505 475 cspc = numpy.roll( cspc, self.m_ProcessingHeader.profilesPerBlock/2, axis=2 ) #desplaza a la derecha en el eje 2 determinadas posiciones
506 476 data['real'] = cspc.real
507 477 data['imag'] = cspc.imag
508 478 data = data.reshape((-1))
509 479 data.tofile(self.fp)
510 480
511 481 data = numpy.zeros( self.shape_dc_Buffer, self.dataType )
512 482 dc = self.data_dc
513 483 data['real'] = dc.real
514 484 data['imag'] = dc.imag
515 485 data = data.reshape((-1))
516 486 data.tofile(self.fp)
517 487
518 488 self.data_spc.fill(0)
519 489 self.data_dc.fill(0)
520 490 if self.data_cspc != None:
521 491 self.data_cspc.fill(0)
522 492
523 493 self.flagIsNewFile = 0
524 494 self.flagIsNewBlock = 1
495 self.nTotalBlocks += 1
525 496 self.nWriteBlocks += 1
526 self.blocksCounter += 1
527 497
528 498
529 499 def putData(self):
530 500 """
531 501 Setea un bloque de datos y luego los escribe en un file
532 502
533 503 Affected:
534 504 self.data_spc
535 505 self.data_cspc
536 506 self.data_dc
537 507
538 508 Return:
539 509 0 : Si no hay data o no hay mas files que puedan escribirse
540 510 1 : Si se escribio la data de un bloque en un file
541 511 """
542 512 self.flagIsNewBlock = 0
543 513
544 514 if self.m_DataObj.flagNoData:
545 515 return 0
546 516
547 517 if self.m_DataObj.flagResetProcessing:
548 518 self.data_spc.fill(0)
549 519 self.data_cspc.fill(0)
550 520 self.data_dc.fill(0)
551 521 self.setNextFile()
552 522
553 523 self.data_spc = self.m_DataObj.data_spc
554 524 self.data_cspc = self.m_DataObj.data_cspc
555 525 self.data_dc = self.m_DataObj.data_dc
556 526
557 527 # #self.m_ProcessingHeader.dataBlocksPerFile)
558 528 if self.hasAllDataInBuffer():
559 self.getHeader()
529 self.getDataHeader()
560 530 self.writeNextBlock()
561 531
562 532 if self.flagNoMoreFiles:
563 533 #print 'Process finished'
564 534 return 0
565 535
566 536 return 1 No newline at end of file
@@ -1,57 +1,57
1 1 '''
2 2 Created on 23/01/2012
3 3
4 4 @author $Author$
5 5 @version $Id$
6 6 '''
7 7 import os
8 8 import sys
9 9 import datetime
10 10 import time
11 11
12 12 class TestIO():
13 13
14 14 def __init__(self):
15 15 self.setValues()
16 16 self.createVoltageObjects()
17 17 self.testReadVoltage()
18 18 pass
19 19
20 20 def setValues(self):
21 21
22 22
23 23 self.path = '/Users/danielangelsuarezmunoz/Documents/Projects/testWR'
24 24 self.startDateTime = datetime.datetime(2007,5,1,17,49,0)
25 25 self.endDateTime = datetime.datetime(2007,5,1,18,15,0)
26 26
27 27 def createVoltageObjects(self):
28 28 path = os.path.split(os.getcwd())[0]
29 29 sys.path.append(path)
30 30
31 31 from IO.VoltageIO import VoltageReader
32 32 from IO.VoltageIO import VoltageWriter
33 33 from Model.Voltage import Voltage
34 34
35 35 self.voltageModelObj = Voltage()
36 36 self.voltageReaderObj = VoltageReader(self.voltageModelObj)
37 37 self.voltageReaderObj.setup(self.path, self.startDateTime, self.endDateTime)
38 38
39 39 # self.voltageWriterObj = VoltageWriter(self.voltageModelObj)
40 40 # self.voltageWriterObj.setup('/Users/danielangelsuarezmunoz/Documents/Projects/testWR')
41 41
42 42
43 43 def testReadVoltage(self):
44 44 while(not(self.voltageReaderObj.noMoreFiles)):
45 45
46 46 self.voltageReaderObj.getData()
47 47 if self.voltageReaderObj.flagResetProcessing:
48 48 print 'jump'
49 49
50 50 if self.voltageReaderObj.flagIsNewBlock:
51 print 'Block No %04d, Time: %s'%(self.voltageReaderObj.nReadBlocks,
51 print 'Block No %04d, Time: %s'%(self.voltageReaderObj.nTotalBlocks,
52 52 datetime.datetime.fromtimestamp(self.voltageReaderObj.m_BasicHeader.utc))
53 53
54 54 # self.voltageWriterObj.putData()
55 55
56 56 if __name__ == '__main__':
57 57 TestIO() No newline at end of file
@@ -1,476 +1,434
1 1 '''
2 2 Created on 23/01/2012
3 3
4 4 @author $Author$
5 5 @version $Id$
6 6 '''
7 7
8 8 import os, sys
9 9 import numpy
10 10 import glob
11 11 import fnmatch
12 12 import time, datetime
13 13
14 14 path = os.path.split(os.getcwd())[0]
15 15 sys.path.append(path)
16 16
17 17 from Model.JROHeader import *
18 18 from Model.Voltage import Voltage
19 19
20 from IO.DataIO import JRODataReader
21 from IO.DataIO import JRODataWriter
20 from IO.JRODataIO import JRODataReader
21 from IO.JRODataIO import JRODataWriter
22 22
23 23
24 24 class VoltageReader(JRODataReader):
25 25 """
26 26 Esta clase permite leer datos de voltage desde archivos en formato rawdata (.r). La lectura
27 27 de los datos siempre se realiza por bloques. Los datos leidos (array de 3 dimensiones:
28 28 perfiles*alturas*canales) son almacenados en la variable "buffer".
29 29
30 30 perfiles * alturas * canales
31 31
32 32 Esta clase contiene instancias (objetos) de las clases BasicHeader, SystemHeader,
33 33 RadarControllerHeader y Voltage. Los tres primeros se usan para almacenar informacion de la
34 34 cabecera de datos (metadata), y el cuarto (Voltage) para obtener y almacenar un perfil de
35 35 datos desde el "buffer" cada vez que se ejecute el metodo "getData".
36 36
37 37 Example:
38 38
39 39 dpath = "/home/myuser/data"
40 40
41 41 startTime = datetime.datetime(2010,1,20,0,0,0,0,0,0)
42 42
43 43 endTime = datetime.datetime(2010,1,21,23,59,59,0,0,0)
44 44
45 45 readerObj = VoltageReader()
46 46
47 47 readerObj.setup(dpath, startTime, endTime)
48 48
49 49 while(True):
50 50
51 51 #to get one profile
52 52 profile = readerObj.getData()
53
53
54 54 #print the profile
55 55 print profile
56 56
57 57 #If you want to see all datablock
58 58 print readerObj.datablock
59 59
60 60 if readerObj.flagNoMoreFiles:
61 61 break
62 62
63 63 """
64 64 m_DataObj = None
65 65
66 idProfile = 0
67
68 66 datablock = None
69
70 pts2read = 0
71
72 utc = 0
73 67
74 68 ext = ".r"
75 69
76 70 optchar = "D"
77 71
78 72
79 73 def __init__(self, m_Voltage=None):
80 74 """
81 75 Inicializador de la clase VoltageReader para la lectura de datos de voltage.
82 76
83 77 Input:
84 78 m_Voltage : Objeto de la clase Voltage. Este objeto sera utilizado para
85 79 almacenar un perfil de datos cada vez que se haga un requerimiento
86 80 (getData). El perfil sera obtenido a partir del buffer de datos,
87 81 si el buffer esta vacio se hara un nuevo proceso de lectura de un
88 82 bloque de datos.
89 83 Si este parametro no es pasado se creara uno internamente.
90 84
91 85 Variables afectadas:
92 86 self.m_DataObj
93 87
94 88 Return:
95 89 None
96 90 """
97 91 if m_Voltage == None:
98 92 m_Voltage = Voltage()
99 93
100 94 if not(isinstance(m_Voltage, Voltage)):
101 95 raise ValueError, "in VoltageReader, m_Voltage must be an Voltage class object"
102 96
103 97 self.m_DataObj = m_Voltage
104
105 self.idProfile = 0
106 98
107 99 self.datablock = None
108 100
109 self.pts2read = 0
110
111 101 self.utc = 0
112 102
113 103 self.ext = ".r"
114 104
115 105 self.optchar = "D"
116 106
117 107 self.m_BasicHeader = BasicHeader()
118 108
119 109 self.m_SystemHeader = SystemHeader()
120 110
121 111 self.m_RadarControllerHeader = RadarControllerHeader()
122 112
123 113 self.m_ProcessingHeader = ProcessingHeader()
124 114
125 115 self.online = 0
126 116
127 117 self.fp = None
128 118
129 119 self.idFile = None
130 120
131 121 self.startDateTime = None
132 122
133 123 self.endDateTime = None
134 124
135 125 self.dataType = None
136 126
137 127 self.fileSizeByHeader = None
138 128
139 129 self.filenameList = []
140 130
141 131 self.filename = None
142 132
143 133 self.fileSize = None
144 134
145 135 self.firstHeaderSize = 0
146 136
147 137 self.basicHeaderSize = 24
148 138
149 139 self.pathList = []
150 140
151 141 self.filenameList = []
152 142
153 143 self.lastUTTime = 0
154 144
155 145 self.maxTimeStep = 30
156 146
157 147 self.flagNoMoreFiles = 0
158 148
159 149 self.set = 0
160 150
161 151 self.path = None
162 152
163 self.datablockIndex = 9999
153 self.profileIndex = 9999
164 154
165 155 self.delay = 3 #seconds
166 156
167 157 self.nTries = 3 #quantity tries
168 158
169 159 self.nFiles = 3 #number of files for searching
170 160
171 self.nBlocks = 0
161 self.nReadBlocks = 0
172 162
173 163 self.flagIsNewFile = 1
174 164
175 165 self.ippSeconds = 0
176 166
177 167 self.flagResetProcessing = 0
178 168
179 169 self.flagIsNewBlock = 0
180 170
181 self.nReadBlocks = 0
171 self.nTotalBlocks = 0
182 172
183 173 self.blocksize = 0
184 174
185 175 def __hasNotDataInBuffer(self):
186 if self.datablockIndex >= self.m_ProcessingHeader.profilesPerBlock:
176 if self.profileIndex >= self.m_ProcessingHeader.profilesPerBlock:
187 177 return 1
188 178 return 0
189 179
190 180
191 181 def getBlockDimension(self):
192 182 """
193 183 Obtiene la cantidad de puntos a leer por cada bloque de datos
194 184
195 185 Affected:
196 self.pts2read
197 186 self.blocksize
198 187
199 188 Return:
200 189 None
201 190 """
202 self.pts2read = self.m_ProcessingHeader.profilesPerBlock * self.m_ProcessingHeader.numHeights * self.m_SystemHeader.numChannels
203 self.blocksize = self.pts2read
204 self.m_DataObj.nProfiles = self.m_ProcessingHeader.profilesPerBlock
191 pts2read = self.m_ProcessingHeader.profilesPerBlock * self.m_ProcessingHeader.numHeights * self.m_SystemHeader.numChannels
192 self.blocksize = pts2read
205 193
206 194
207 195 def readBlock(self):
208 196 """
209 197 readBlock lee el bloque de datos desde la posicion actual del puntero del archivo
210 198 (self.fp) y actualiza todos los parametros relacionados al bloque de datos
211 199 (metadata + data). La data leida es almacenada en el buffer y el contador del buffer
212 200 es seteado a 0
213 201
214 202 Inputs:
215 203 None
216 204
217 205 Return:
218 206 None
219 207
220 208 Affected:
221 self.datablockIndex
209 self.profileIndex
222 210 self.datablock
223 211 self.flagIsNewFile
224 self.idProfile
225 212 self.flagIsNewBlock
226 self.nReadBlocks
213 self.nTotalBlocks
227 214
228 215 Exceptions:
229 216 Si un bloque leido no es un bloque valido
230 217 """
231 blockOk_flag = False
232 fpointer = self.fp.tell()
233
234 junk = numpy.fromfile( self.fp, self.dataType, self.pts2read )
235
236 if self.online:
237 if junk.size != self.blocksize:
238 for nTries in range( self.nTries ):
239 print "\tWaiting %0.2f sec for the next block, try %03d ..." % (self.delay, nTries+1)
240 time.sleep( self.delay )
241 self.fp.seek( fpointer )
242 fpointer = self.fp.tell()
243
244 junk = numpy.fromfile( self.fp, self.dataType, self.pts2read )
245
246 if junk.size == self.blocksize:
247 blockOk_flag = True
248 break
249
250 if not( blockOk_flag ):
251 return 0
218
219 junk = numpy.fromfile( self.fp, self.dataType, self.blocksize )
252 220
253 221 try:
254 222 junk = junk.reshape( (self.m_ProcessingHeader.profilesPerBlock, self.m_ProcessingHeader.numHeights, self.m_SystemHeader.numChannels) )
255 223 except:
256 print "Data file %s is invalid" % self.filename
224 print "The read block (%3d) has not enough data" %self.nReadBlocks
257 225 return 0
258 226
259 227 junk = numpy.transpose(junk, (2,0,1))
260 228 self.datablock = junk['real'] + junk['imag']*1j
261 229
262 self.datablockIndex = 0
230 self.profileIndex = 0
231
263 232 self.flagIsNewFile = 0
264 self.idProfile = 0
265 233 self.flagIsNewBlock = 1
266 234
235 self.nTotalBlocks += 1
267 236 self.nReadBlocks += 1
268 self.nBlocks += 1
269 237
270 238 return 1
271 239
272 240
273 241 def getData(self):
274 242 """
275 243 getData obtiene una unidad de datos del buffer de lectura y la copia a la clase "Voltage"
276 244 con todos los parametros asociados a este (metadata). cuando no hay datos en el buffer de
277 245 lectura es necesario hacer una nueva lectura de los bloques de datos usando "readNextBlock"
278 246
279 247 Ademas incrementa el contador del buffer en 1.
280 248
281 249 Return:
282 250 data : retorna un perfil de voltages (alturas * canales) copiados desde el
283 251 buffer. Si no hay mas archivos a leer retorna None.
284 252
285 253 Variables afectadas:
286 254 self.m_DataObj
287 self.datablockIndex
288 self.idProfile
255 self.profileIndex
289 256
290 257 Affected:
291 258 self.m_DataObj
292 self.datablockIndex
259 self.profileIndex
293 260 self.flagResetProcessing
294 261 self.flagIsNewBlock
295 self.idProfile
296 262 """
297 263 if self.flagNoMoreFiles: return 0
298 264
299 265 self.flagResetProcessing = 0
300 266 self.flagIsNewBlock = 0
301 267
302 268 if self.__hasNotDataInBuffer():
303 269
304 270 if not( self.readNextBlock() ):
305 self.setNextFile()
306 271 return 0
307 272
308 self.m_DataObj.m_BasicHeader = self.m_BasicHeader.copy()
309 self.m_DataObj.m_ProcessingHeader = self.m_ProcessingHeader.copy()
310 self.m_DataObj.m_RadarControllerHeader = self.m_RadarControllerHeader.copy()
311 self.m_DataObj.m_SystemHeader = self.m_SystemHeader.copy()
312 self.m_DataObj.heightList = self.heightList
313 self.m_DataObj.dataType = self.dataType
273 self.updateDataHeader()
314 274
315 275 if self.flagNoMoreFiles == 1:
316 276 print 'Process finished'
317 277 return 0
318 278
319 279 #data es un numpy array de 3 dmensiones (perfiles, alturas y canales)
320 280
321 281 if self.datablock == None:
322 282 self.m_DataObj.flagNoData = True
323 283 return 0
324 284
325 time = self.m_BasicHeader.utc + self.datablockIndex * self.ippSeconds
285 time = self.m_BasicHeader.utc + self.profileIndex * self.ippSeconds
326 286 self.m_DataObj.m_BasicHeader.utc = time
327 287
328 288 self.m_DataObj.flagNoData = False
329 289 self.m_DataObj.flagResetProcessing = self.flagResetProcessing
330 290
331 self.m_DataObj.data = self.datablock[:,self.datablockIndex,:]
332 self.m_DataObj.idProfile = self.idProfile
291 self.m_DataObj.data = self.datablock[:,self.profileIndex,:]
333 292
334 self.datablockIndex += 1
335 self.idProfile += 1
293 self.profileIndex += 1
336 294
337 295 #call setData - to Data Object
338 296
339 297 return 1 #self.m_DataObj.data
340 298
341 299
342 300 class VoltageWriter( JRODataWriter ):
343 301 """
344 302 Esta clase permite escribir datos de voltajes a archivos procesados (.r). La escritura
345 303 de los datos siempre se realiza por bloques.
346 304 """
347 305 __configHeaderFile = 'wrSetHeadet.txt'
348 306
349 307 m_DataObj = None
350 308
351 309 ext = ".r"
352 310
353 311 optchar = "D"
354 312
355 313 datablock = None
356 314
357 datablockIndex = 0
315 profileIndex = 0
358 316
359 317 shapeBuffer = None
360 318
361 319
362 320 def __init__(self, m_Voltage=None):
363 321 """
364 322 Inicializador de la clase VoltageWriter para la escritura de datos de espectros.
365 323
366 324 Affected:
367 325 self.m_DataObj
368 326
369 327 Return: None
370 328 """
371 329 if m_Voltage == None:
372 330 m_Voltage = Voltage()
373 331
374 332 if not( isinstance(m_Voltage, Voltage) ):
375 333 raise ValueError, "in VoltageReader, m_Voltage must be an Spectra class object"
376 334
377 335 self.m_DataObj = m_Voltage
378 336
379 337
380 338 def hasAllDataInBuffer(self):
381 if self.datablockIndex >= self.m_ProcessingHeader.profilesPerBlock:
339 if self.profileIndex >= self.m_ProcessingHeader.profilesPerBlock:
382 340 return 1
383 341 return 0
384 342
385 343
386 344 def setBlockDimension(self):
387 345 """
388 346 Obtiene las formas dimensionales del los subbloques de datos que componen un bloque
389 347
390 348 Affected:
391 349 self.shape_spc_Buffer
392 350 self.shape_cspc_Buffer
393 351 self.shape_dc_Buffer
394 352
395 353 Return: None
396 354 """
397 355 self.shapeBuffer = (self.m_ProcessingHeader.profilesPerBlock,
398 356 self.m_ProcessingHeader.numHeights,
399 357 self.m_SystemHeader.numChannels )
400 358
401 359 self.datablock = numpy.zeros((self.m_SystemHeader.numChannels,
402 360 self.m_ProcessingHeader.profilesPerBlock,
403 361 self.m_ProcessingHeader.numHeights),
404 362 dtype=numpy.dtype('complex'))
405 363
406 364
407 365 def writeBlock(self):
408 366 """
409 367 Escribe el buffer en el file designado
410 368
411 369 Affected:
412 self.datablockIndex
370 self.profileIndex
413 371 self.flagIsNewFile
414 372 self.flagIsNewBlock
415 self.nWriteBlocks
416 self.blocksCounter
373 self.nTotalBlocks
374 self.nWriteBlocks
417 375
418 376 Return: None
419 377 """
420 378 data = numpy.zeros( self.shapeBuffer, self.dataType )
421 379
422 380 junk = numpy.transpose(self.datablock, (1,2,0))
423 381
424 382 data['real'] = junk.real
425 383 data['imag'] = junk.imag
426 384
427 385 data = data.reshape( (-1) )
428 386
429 387 data.tofile( self.fp )
430 388
431 389 self.datablock.fill(0)
432 self.datablockIndex = 0
390 self.profileIndex = 0
433 391 self.flagIsNewFile = 0
434 392 self.flagIsNewBlock = 1
393 self.nTotalBlocks += 1
435 394 self.nWriteBlocks += 1
436 self.blocksCounter += 1
437 395
438 396
439 397 def putData(self):
440 398 """
441 399 Setea un bloque de datos y luego los escribe en un file
442 400
443 401 Affected:
444 402 self.flagIsNewBlock
445 self.datablockIndex
403 self.profileIndex
446 404
447 405 Return:
448 406 0 : Si no hay data o no hay mas files que puedan escribirse
449 407 1 : Si se escribio la data de un bloque en un file
450 408 """
451 409 self.flagIsNewBlock = 0
452 410
453 411 if self.m_DataObj.flagNoData:
454 412 return 0
455 413
456 414 if self.m_DataObj.flagResetProcessing:
457 415
458 416 self.datablock.fill(0)
459 self.datablockIndex = 0
417 self.profileIndex = 0
460 418 self.setNextFile()
461 419
462 self.datablock[:,self.datablockIndex,:] = self.m_DataObj.data
420 self.datablock[:,self.profileIndex,:] = self.m_DataObj.data
463 421
464 self.datablockIndex += 1
422 self.profileIndex += 1
465 423
466 424 if self.hasAllDataInBuffer():
467 425 #if self.flagIsNewFile:
468 self.getHeader()
426 self.getDataHeader()
469 427 self.writeNextBlock()
470 428
471 429 if self.flagNoMoreFiles:
472 430 #print 'Process finished'
473 431 return 0
474 432
475 433 return 1
476 434 No newline at end of file
@@ -1,18 +1,58
1 1 '''
2 2 Created on Feb 7, 2012
3 3
4 4 @author $Author$
5 5 @version $Id$
6 6 '''
7 from JROData import JROData, Noise
8 from JROHeader import RadarControllerHeader, ProcessingHeader, SystemHeader, BasicHeader
7 9
8 class Correlation(Data):
10 class Correlation(JROData):
9 11 '''
10 12 classdocs
11 13 '''
12
13
14
15 data = None
16
17 nLags = None
18
19 lagsList = None
20
14 21 def __init__(self):
15 22 '''
16 23 Constructor
17 24 '''
18 pass No newline at end of file
25
26 self.m_RadarControllerHeader = RadarControllerHeader()
27
28 self.m_ProcessingHeader = ProcessingHeader()
29
30 self.m_SystemHeader = SystemHeader()
31
32 self.m_BasicHeader = BasicHeader()
33
34 self.m_NoiseObj = Noise()
35
36 self.type = "Spectra"
37
38 self.dataType = None
39
40 self.nHeights = 0
41
42 self.nChannels = 0
43
44 self.channelList = None
45
46 self.heightList = None
47
48 self.flagNoData = True
49
50 self.flagResetProcessing = False
51
52
53 self.data = None
54
55 self.nLags = 0
56
57 self.lagsList = None
58 No newline at end of file
@@ -1,72 +1,103
1 1 '''
2 2 Created on Feb 7, 2012
3 3
4 4 @author $Author$
5 5 @version $Id$
6 6 '''
7 7 import copy
8 8 from JROHeader import RadarControllerHeader, ProcessingHeader, SystemHeader, BasicHeader
9 9
10 10 class Data:
11 11 '''
12 12 classdocs
13 13 '''
14 type = None
15 14
16 15 def __init__(self):
17 16 '''
18 17 Constructor
19 18 '''
20 19 raise ValueError, "This class has not been implemented"
21 20
22 21 def copy(self, objIn=None):
23 22
24 23 if objIn == None:
25 24 return copy.deepcopy(self)
26 25
27 26 for key in objIn.__dict__.keys():
28 27 self.__dict__[key] = objIn.__dict__[key]
29 28
30 29 def deepcopy(self):
31 30
32 31 return copy.deepcopy(self)
33 32
34 33 class Noise(Data):
35 34 '''
36 35 classdocs
37 36 '''
38 37
39 38 def __init__(self):
40 39 '''
41 40 Constructor
42 41 '''
43 42 pass
44 43
45 44 class JROData(Data):
46 45 '''
47 46 classdocs
48 47 '''
48
49 49 m_RadarControllerHeader = RadarControllerHeader()
50
50 51 m_ProcessingHeader = ProcessingHeader()
52
51 53 m_SystemHeader = SystemHeader()
54
52 55 m_BasicHeader = BasicHeader()
56
53 57 m_NoiseObj = Noise()
54 58
55 data = None
59 type = None
60
56 61 dataType = None
57
58 nProfiles = None
62
59 63 nHeights = None
64
60 65 nChannels = None
61 66
62 67 heightList = None
68
63 69 channelList = None
64 70
65 71 flagNoData = False
72
66 73 flagResetProcessing = False
67 74
68 75 def __init__(self):
69 76 '''
70 77 Constructor
71 78 '''
72 raise ValueError, "This class has not been implemented" No newline at end of file
79 raise ValueError, "This class has not been implemented"
80
81 def updateHeaderFromObj(self):
82
83 xi = self.heightList[0]
84 step = self.heightList[1] - self.heightList[0]
85
86 self.m_ProcessingHeader.firstHeight = xi
87 self.m_ProcessingHeader.deltaHeight = step
88
89 self.m_ProcessingHeader.numHeights = self.nHeights
90 self.m_SystemHeader.numChannels = self.nChannels
91
92 def updateObjFromHeader(self):
93
94 xi = self.m_ProcessingHeader.firstHeight
95 step = self.m_ProcessingHeader.deltaHeight
96 xf = xi + self.m_ProcessingHeader.numHeights*step
97
98 self.heightList = numpy.arange(xi, xf, step)
99 self.channelList = numpy.arange(self.m_SystemHeader.numChannels)
100
101 self.nHeights = len(self.heightList)
102 self.nChannels = len(self.channelList)
103 No newline at end of file
@@ -1,60 +1,76
1 1 '''
2 2 Created on Feb 7, 2012
3 3
4 4 @author $Author$
5 5 @version $Id$
6 6 '''
7 7
8 8 from JROData import JROData, Noise
9 9 from JROHeader import RadarControllerHeader, ProcessingHeader, SystemHeader, BasicHeader
10 10
11 11 class Spectra(JROData):
12 12 '''
13 13 classdocs
14 14 '''
15 15
16 type = "Spectra"
17 16 data_spc = None
17
18 18 data_cspc = None
19
19 20 data_dc = None
20 21
22 nFFTPoints = None
23
24 nPairs = None
25
26 pairsList = None
27
21 28
22 29 def __init__(self):
23 30 '''
24 31 Constructor
25 32 '''
26 33
27 34 self.m_RadarControllerHeader = RadarControllerHeader()
28 35
29 36 self.m_ProcessingHeader = ProcessingHeader()
30 37
31 38 self.m_SystemHeader = SystemHeader()
32 39
33 40 self.m_BasicHeader = BasicHeader()
34 41
35 m_NoiseObj = Noise()
42 self.m_NoiseObj = Noise()
36 43
37 #data es un numpy array de 3 dmensiones (perfiles, alturas y canales)
38 self.data_spc = None
44 self.type = "Spectra"
39 45
40 self.data_cspc = None
46 self.dataType = None
41 47
42 self.data_dc = None
43
44 self.heightList = None
48 self.nHeights = 0
49
50 self.nChannels = 0
45 51
46 52 self.channelList = None
47 53
54 self.heightList = None
55
48 56 self.flagNoData = True
49 57
50 self.nProfiles = None
58 self.flagResetProcessing = False
59
51 60
52 self.nPoints = None
61 #data es un numpy array de 3 dmensiones (perfiles, alturas y canales)
62 self.data_spc = None
53 63
54 self.dataType = None
64 self.data_cspc = None
55 65
56 self.flagResetProcessing = False
66 self.data_dc = None
67
68 self.nFFTPoints = None
57 69
58 70 self.nPairs = 0
59
60 self.nChannels = 0 No newline at end of file
71
72 self.pairsList = None
73
74
75
76 No newline at end of file
@@ -1,49 +1,63
1 1 '''
2 2 Created on Feb 7, 2012
3 3
4 4 @author $Author$
5 5 @version $Id$
6 6 '''
7 7
8 8 from JROData import JROData, Noise
9 9 from JROHeader import RadarControllerHeader, ProcessingHeader, SystemHeader, BasicHeader
10 10
11 11 class Voltage(JROData):
12 12 '''
13 13 classdocs
14 14 '''
15 15
16 type = "Voltage"
17 16 data = None
17
18 nProfiles = None
19
18 20 profileIndex = None
19 21
20 22 def __init__(self):
21 23 '''
22 24 Constructor
23 25 '''
24 26
25 self.m_RadarControllerHeader= RadarControllerHeader()
27 self.m_RadarControllerHeader = RadarControllerHeader()
26 28
27 self.m_ProcessingHeader= ProcessingHeader()
29 self.m_ProcessingHeader = ProcessingHeader()
28 30
29 self.m_SystemHeader= SystemHeader()
31 self.m_SystemHeader = SystemHeader()
30 32
31 self.m_BasicHeader= BasicHeader()
33 self.m_BasicHeader = BasicHeader()
32 34
33 m_NoiseObj = Noise()
35 self.m_NoiseObj = Noise()
36
37 self.type = "Voltage"
34 38
35 39 #data es un numpy array de 3 dmensiones (perfiles, alturas y canales)
36 40 self.data = None
37 41
38 42 self.dataType = None
39 43
44 self.nHeights = 0
45
46 self.nChannels = 0
47
48 self.channelList = None
49
40 50 self.heightList = None
41 51
52 self.flagNoData = True
53
54 self.flagResetProcessing = False
55
56
57
42 58 self.profileIndex = None
43 59
44 60 self.nProfiles = None
45 61
46 self.flagNoData = True
47 62
48 self.flagResetProcessing = False
49 63 No newline at end of file
@@ -1,499 +1,497
1 1 '''
2 2 Created on Feb 7, 2012
3 3
4 4 @author $Author$
5 5 @version $Id$
6 6 '''
7 7 import os, sys
8 8 import numpy
9 9
10 10 path = os.path.split(os.getcwd())[0]
11 11 sys.path.append(path)
12 12
13 13 from Model.Spectra import Spectra
14 14 from IO.SpectraIO import SpectraWriter
15 15 from Graphics.SpectraPlot import Spectrum
16 16
17 17
18 18 class SpectraProcessor:
19 19 '''
20 20 classdocs
21 21 '''
22 22
23 23 def __init__(self, dataInObj, dataOutObj=None):
24 24 '''
25 25 Constructor
26 26 '''
27 27 self.dataInObj = dataInObj
28 28
29 29 if dataOutObj == None:
30 30 self.dataOutObj = Spectra()
31 31 else:
32 32 self.dataOutObj = dataOutObj
33 33
34 34 self.integratorIndex = None
35 35 self.decoderIndex = None
36 36 self.writerIndex = None
37 37 self.plotterIndex = None
38 38
39 39 self.integratorList = []
40 40 self.decoderList = []
41 41 self.writerList = []
42 42 self.plotterList = []
43 43
44 44 self.buffer = None
45 45 self.ptsId = 0
46 46
47 47 def init(self, nFFTPoints, pairList=None):
48 48
49 49 self.integratorIndex = 0
50 50 self.decoderIndex = 0
51 51 self.writerIndex = 0
52 52 self.plotterIndex = 0
53 53
54 54 if nFFTPoints == None:
55 nFFTPoints = self.dataOutObj.nPoints
55 nFFTPoints = self.dataOutObj.nFFTPoints
56 56
57 57 self.nFFTPoints = nFFTPoints
58 58 self.pairList = pairList
59 59
60 60 if not( isinstance(self.dataInObj, Spectra) ):
61 61 self.__getFft()
62 62 else:
63 63 self.dataOutObj.copy(self.dataInObj)
64 64
65 65
66 66 def __getFft(self):
67 67 """
68 68 Convierte valores de Voltaje a Spectra
69 69
70 70 Affected:
71 71 self.dataOutObj.data_spc
72 72 self.dataOutObj.data_cspc
73 73 self.dataOutObj.data_dc
74 74 self.dataOutObj.heightList
75 75 self.dataOutObj.m_BasicHeader
76 76 self.dataOutObj.m_ProcessingHeader
77 77 self.dataOutObj.m_RadarControllerHeader
78 78 self.dataOutObj.m_SystemHeader
79 79 self.ptsId
80 80 self.buffer
81 81 self.dataOutObj.flagNoData
82 82 self.dataOutObj.dataType
83 83 self.dataOutObj.nPairs
84 84 self.dataOutObj.nChannels
85 85 self.dataOutObj.nProfiles
86 86 self.dataOutObj.m_SystemHeader.numChannels
87 87 self.dataOutObj.m_ProcessingHeader.totalSpectra
88 88 self.dataOutObj.m_ProcessingHeader.profilesPerBlock
89 89 self.dataOutObj.m_ProcessingHeader.numHeights
90 90 self.dataOutObj.m_ProcessingHeader.spectraComb
91 91 self.dataOutObj.m_ProcessingHeader.shif_fft
92 92 """
93 93 blocksize = 0
94 npoints = self.nFFTPoints
95 nchannels, nheis = self.dataInObj.data.shape
94 nFFTPoints = self.nFFTPoints
95 nChannels, nheis = self.dataInObj.data.shape
96 96
97 97 if self.buffer == None:
98 self.buffer = numpy.zeros((nchannels, npoints, nheis), dtype='complex')
98 self.buffer = numpy.zeros((nChannels, nFFTPoints, nheis), dtype='complex')
99 99
100 100 self.buffer[:,self.ptsId,:] = self.dataInObj.data
101 101 self.ptsId += 1
102 102
103 if self.ptsId < self.dataOutObj.nPoints:
103 if self.ptsId < self.dataOutObj.nFFTPoints:
104 104 self.dataOutObj.flagNoData = True
105 105 return
106 106
107 107 fft_volt = numpy.fft.fft(self.buffer,axis=1)
108 108 dc = fft_volt[:,0,:]
109 109
110 110 #calculo de self-spectra
111 111 fft_volt = numpy.fft.fftshift(fft_volt,axes=(1,))
112 112 spc = numpy.abs(fft_volt * numpy.conjugate(fft_volt))
113 113
114 114 blocksize += dc.size
115 115 blocksize += spc.size
116 116
117 117 cspc = None
118 npair = 0
118 nPair = 0
119 119 if self.pairList != None:
120 120 #calculo de cross-spectra
121 npairs = len(self.pairList)
122 cspc = numpy.zeros((npairs, npoints, nheis), dtype='complex')
121 nPairs = len(self.pairList)
122 cspc = numpy.zeros((nPairs, nFFTPoints, nheis), dtype='complex')
123 123 for pair in self.pairList:
124 cspc[npair,:,:] = numpy.abs(fft_volt[pair[0],:,:] * numpy.conjugate(fft_volt[pair[1],:,:]))
125 npair += 1
124 cspc[nPair,:,:] = numpy.abs(fft_volt[pair[0],:,:] * numpy.conjugate(fft_volt[pair[1],:,:]))
125 nPair += 1
126 126 blocksize += cspc.size
127 127
128 128 self.dataOutObj.data_spc = spc
129 129 self.dataOutObj.data_cspc = cspc
130 130 self.dataOutObj.data_dc = dc
131 131
132 132 self.ptsId = 0
133 133 self.buffer = None
134 134 self.dataOutObj.flagNoData = False
135 135
136 136 self.dataOutObj.heightList = self.dataInObj.heightList
137 137 self.dataOutObj.channelList = self.dataInObj.channelList
138 138 self.dataOutObj.m_BasicHeader = self.dataInObj.m_BasicHeader.copy()
139 139 self.dataOutObj.m_ProcessingHeader = self.dataInObj.m_ProcessingHeader.copy()
140 140 self.dataOutObj.m_RadarControllerHeader = self.dataInObj.m_RadarControllerHeader.copy()
141 141 self.dataOutObj.m_SystemHeader = self.dataInObj.m_SystemHeader.copy()
142 142
143 143 self.dataOutObj.dataType = self.dataInObj.dataType
144 self.dataOutObj.nPairs = npair
145 self.dataOutObj.nChannels = nchannels
146 self.dataOutObj.nProfiles = npoints
144 self.dataOutObj.nPairs = nPair
145 self.dataOutObj.nChannels = nChannels
146 self.dataOutObj.nProfiles = nFFTPoints
147 147 self.dataOutObj.nHeights = nheis
148 self.dataOutObj.nPoints = npoints
148 self.dataOutObj.nFFTPoints = nFFTPoints
149 149 #self.dataOutObj.data = None
150 150
151 self.dataOutObj.m_SystemHeader.numChannels = nchannels
152 self.dataOutObj.m_SystemHeader.nProfiles = npoints
151 self.dataOutObj.m_SystemHeader.numChannels = nChannels
152 self.dataOutObj.m_SystemHeader.nProfiles = nFFTPoints
153 153
154 154 self.dataOutObj.m_ProcessingHeader.blockSize = blocksize
155 self.dataOutObj.m_ProcessingHeader.totalSpectra = nchannels + npair
156 self.dataOutObj.m_ProcessingHeader.profilesPerBlock = npoints
155 self.dataOutObj.m_ProcessingHeader.totalSpectra = nChannels + nPair
156 self.dataOutObj.m_ProcessingHeader.profilesPerBlock = nFFTPoints
157 157 self.dataOutObj.m_ProcessingHeader.numHeights = nheis
158 158 self.dataOutObj.m_ProcessingHeader.shif_fft = True
159 159
160 spectraComb = numpy.zeros( (nchannels+npair)*2,numpy.dtype('u1'))
160 spectraComb = numpy.zeros( (nChannels+nPair)*2,numpy.dtype('u1'))
161 161 k = 0
162 for i in range( 0,nchannels*2,2 ):
162 for i in range( 0,nChannels*2,2 ):
163 163 spectraComb[i] = k
164 164 spectraComb[i+1] = k
165 165 k += 1
166 166
167 167 k *= 2
168 168
169 169 if self.pairList != None:
170 170
171 171 for pair in self.pairList:
172 172 spectraComb[k] = pair[0]
173 173 spectraComb[k+1] = pair[1]
174 174 k += 2
175 175
176 176 self.dataOutObj.m_ProcessingHeader.spectraComb = spectraComb
177 177
178 178 #self.selectHeightsByIndex( 0,10)
179 179 #self.selectHeightsByValue( 120,200 )
180 180 #self.selectChannels((2,4,5), self.pairList)
181 181
182 182
183 183 def addWriter(self,wrpath):
184 184 objWriter = SpectraWriter(self.dataOutObj)
185 185 objWriter.setup(wrpath)
186 186 self.writerList.append(objWriter)
187 187
188 188
189 189 def addPlotter(self, index=None):
190 190
191 191 if index==None:
192 192 index = self.plotterIndex
193 193
194 194 plotObj = Spectrum(self.dataOutObj, index)
195 195 self.plotterList.append(plotObj)
196 196
197 197
198 198 def addIntegrator(self,N):
199 199
200 200 objIncohInt = IncoherentIntegration(N)
201 201 self.integratorList.append(objIncohInt)
202 202
203 203
204 204 def writeData(self, wrpath):
205 205 if self.dataOutObj.flagNoData:
206 206 return 0
207 207
208 208 if len(self.writerList) <= self.writerIndex:
209 209 self.addWriter(wrpath)
210 210
211 211 self.writerList[self.writerIndex].putData()
212 212
213 213 self.writerIndex += 1
214 214
215 215 def plotData(self,xmin=None, xmax=None, ymin=None, ymax=None, winTitle='', index=None):
216 216 if self.dataOutObj.flagNoData:
217 217 return 0
218 218
219 219 if len(self.plotterList) <= self.plotterIndex:
220 220 self.addPlotter(index)
221 221
222 222 self.plotterList[self.plotterIndex].plotData(xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax,winTitle=winTitle)
223 223
224 224 self.plotterIndex += 1
225 225
226 226 def integrator(self, N):
227 227 if self.dataOutObj.flagNoData:
228 228 return 0
229 229
230 230 if len(self.integratorList) <= self.integratorIndex:
231 231 self.addIntegrator(N)
232 232
233 233 myCohIntObj = self.integratorList[self.integratorIndex]
234 234 myCohIntObj.exe(self.dataOutObj.data_spc)
235 235
236 236 if myCohIntObj.flag:
237 237 self.dataOutObj.data_spc = myCohIntObj.data
238 238 self.dataOutObj.m_ProcessingHeader.incoherentInt *= N
239 239 self.dataOutObj.flagNoData = False
240 240
241 241 else:
242 242 self.dataOutObj.flagNoData = True
243 243
244 244 self.integratorIndex += 1
245 245
246 246 def removeDC(self, type):
247 247
248 248 if self.dataOutObj.flagNoData:
249 249 return 0
250 250 pass
251 251
252 252 def removeInterference(self):
253 253
254 254 if self.dataOutObj.flagNoData:
255 255 return 0
256 256 pass
257 257
258 258 def removeSatellites(self):
259 259
260 260 if self.dataOutObj.flagNoData:
261 261 return 0
262 262 pass
263 263
264 264 def selectChannels(self, channelList, pairList=None):
265 265 """
266 266 Selecciona un bloque de datos en base a canales y pares segun el channelList y el pairList
267 267
268 268 Input:
269 269 channelList : lista sencilla de canales a seleccionar por ej. (2,3,7)
270 270 pairList : tupla de pares que se desea selecionar por ej. ( (0,1), (0,2) )
271 271
272 272 Affected:
273 273 self.dataOutObj.data_spc
274 274 self.dataOutObj.data_cspc
275 275 self.dataOutObj.data_dc
276 276 self.dataOutObj.nChannels
277 277 self.dataOutObj.nPairs
278 278 self.dataOutObj.m_ProcessingHeader.spectraComb
279 279 self.dataOutObj.m_SystemHeader.numChannels
280 280
281 281 Return:
282 282 None
283 283 """
284 284
285 285 if self.dataOutObj.flagNoData:
286 286 return 0
287 287
288 nchannels = 0
289 npairs = 0
290 profiles = self.dataOutObj.nProfiles
288 nProfiles = self.dataOutObj.nProfiles
291 289 dataType = self.dataOutObj.dataType
292 heights = self.dataOutObj.m_ProcessingHeader.numHeights
290 nHeights = self.dataOutObj.m_ProcessingHeader.numHeights
293 291 blocksize = 0
294 292
295 293 #self spectra
296 nchannels = len(channelList)
297 spc = numpy.zeros( (nchannels,profiles,heights), dataType[0] )
294 nChannels = len(channelList)
295 spc = numpy.zeros( (nChannels,nProfiles,nHeights), dataType[0] )
298 296
299 297 for index, channel in enumerate(channelList):
300 298 spc[index,:,:] = self.dataOutObj.data_spc[channel,:,:]
301 299
302 300 #DC channel
303 dc = numpy.zeros( (nchannels,heights), dtype='complex' )
301 dc = numpy.zeros( (nChannels,nHeights), dtype='complex' )
304 302 for index, channel in enumerate(channelList):
305 303 dc[index,:] = self.dataOutObj.data_dc[channel,:]
306 304
307 305 blocksize += dc.size
308 306 blocksize += spc.size
309 307
310 npairs = 0
308 nPairs = 0
311 309 cspc = None
312 310
313 311 if pairList == None:
314 312 pairList = self.pairList
315 313
316 314 if pairList != None:
317 315 #cross spectra
318 npairs = len(pairList)
319 cspc = numpy.zeros( (npairs,profiles,heights), dtype='complex' )
316 nPairs = len(pairList)
317 cspc = numpy.zeros( (nPairs,nProfiles,nHeights), dtype='complex' )
320 318
321 319 spectraComb = self.dataOutObj.m_ProcessingHeader.spectraComb
322 320 totalSpectra = len(spectraComb)
323 321 nchan = self.dataOutObj.nChannels
324 322 indexList = []
325 323
326 324 for pair in pairList: #busco el par en la lista de pares del Spectra Combinations
327 325 for index in range(0,totalSpectra,2):
328 326 if pair[0] == spectraComb[index] and pair[1] == spectraComb[index+1]:
329 327 indexList.append( index/2 - nchan )
330 328
331 329 for index, pair in enumerate(indexList):
332 330 cspc[index,:,:] = self.dataOutObj.data_cspc[pair,:,:]
333 331 blocksize += cspc.size
334 332
335 333 else:
336 334 pairList = self.pairList
337 335 cspc = self.dataOutObj.data_cspc
338 336 if cspc != None:
339 337 blocksize += cspc.size
340 338
341 spectraComb = numpy.zeros( (nchannels+npairs)*2,numpy.dtype('u1'))
339 spectraComb = numpy.zeros( (nChannels+nPairs)*2,numpy.dtype('u1'))
342 340 i = 0
343 341 for val in channelList:
344 342 spectraComb[i] = val
345 343 spectraComb[i+1] = val
346 344 i += 2
347 345
348 346 if pairList != None:
349 347 for pair in pairList:
350 348 spectraComb[i] = pair[0]
351 349 spectraComb[i+1] = pair[1]
352 350 i += 2
353 351
354 352 self.dataOutObj.data_spc = spc
355 353 self.dataOutObj.data_cspc = cspc
356 354 self.dataOutObj.data_dc = dc
357 self.dataOutObj.nChannels = nchannels
358 self.dataOutObj.nPairs = npairs
355 self.dataOutObj.nChannels = nChannels
356 self.dataOutObj.nPairs = nPairs
359 357
360 358 self.dataOutObj.channelList = channelList
361 359
362 360 self.dataOutObj.m_ProcessingHeader.spectraComb = spectraComb
363 self.dataOutObj.m_ProcessingHeader.totalSpectra = nchannels + npairs
364 self.dataOutObj.m_SystemHeader.numChannels = nchannels
365 self.dataOutObj.nChannels = nchannels
361 self.dataOutObj.m_ProcessingHeader.totalSpectra = nChannels + nPairs
362 self.dataOutObj.m_SystemHeader.numChannels = nChannels
363 self.dataOutObj.nChannels = nChannels
366 364 self.dataOutObj.m_ProcessingHeader.blockSize = blocksize
367 365
368 366
369 367 def selectHeightsByValue(self, minHei, maxHei):
370 368 """
371 369 Selecciona un bloque de datos en base a un grupo de valores de alturas segun el rango
372 370 minHei <= height <= maxHei
373 371
374 372 Input:
375 373 minHei : valor minimo de altura a considerar
376 374 maxHei : valor maximo de altura a considerar
377 375
378 376 Affected:
379 377 Indirectamente son cambiados varios valores a travez del metodo selectHeightsByIndex
380 378
381 379 Return:
382 380 None
383 381 """
384 382
385 383 if self.dataOutObj.flagNoData:
386 384 return 0
387 385
388 386 minIndex = 0
389 387 maxIndex = 0
390 388 data = self.dataOutObj.heightList
391 389
392 390 for i,val in enumerate(data):
393 391 if val < minHei:
394 392 continue
395 393 else:
396 394 minIndex = i;
397 395 break
398 396
399 397 for i,val in enumerate(data):
400 398 if val <= maxHei:
401 399 maxIndex = i;
402 400 else:
403 401 break
404 402
405 403 self.selectHeightsByIndex(minIndex, maxIndex)
406 404
407 405
408 406 def selectHeightsByIndex(self, minIndex, maxIndex):
409 407 """
410 408 Selecciona un bloque de datos en base a un grupo indices de alturas segun el rango
411 409 minIndex <= index <= maxIndex
412 410
413 411 Input:
414 412 minIndex : valor minimo de altura a considerar
415 413 maxIndex : valor maximo de altura a considerar
416 414
417 415 Affected:
418 416 self.dataOutObj.data_spc
419 417 self.dataOutObj.data_cspc
420 418 self.dataOutObj.data_dc
421 419 self.dataOutObj.heightList
422 420 self.dataOutObj.nHeights
423 421 self.dataOutObj.m_ProcessingHeader.numHeights
424 422 self.dataOutObj.m_ProcessingHeader.blockSize
425 423 self.dataOutObj.m_ProcessingHeader.firstHeight
426 424 self.dataOutObj.m_RadarControllerHeader.numHeights
427 425
428 426 Return:
429 427 None
430 428 """
431 429
432 430 if self.dataOutObj.flagNoData:
433 431 return 0
434 432
435 nchannels = self.dataOutObj.nChannels
436 npairs = self.dataOutObj.nPairs
437 profiles = self.dataOutObj.nProfiles
433 nChannels = self.dataOutObj.nChannels
434 nPairs = self.dataOutObj.nPairs
435 nProfiles = self.dataOutObj.nProfiles
438 436 dataType = self.dataOutObj.dataType
439 437 newheis = maxIndex - minIndex + 1
440 438 blockSize = 0
441 439
442 440 #self spectra
443 spc = numpy.zeros( (nchannels,profiles,newheis), dataType[0] )
444 for i in range(nchannels):
441 spc = numpy.zeros( (nChannels,nProfiles,newheis), dataType[0] )
442 for i in range(nChannels):
445 443 spc[i,:,:] = self.dataOutObj.data_spc[i,:,minIndex:maxIndex+1]
446 444
447 445 #cross spectra
448 cspc = numpy.zeros( (npairs,profiles,newheis), dtype='complex')
449 for i in range(npairs):
446 cspc = numpy.zeros( (nPairs,nProfiles,newheis), dtype='complex')
447 for i in range(nPairs):
450 448 cspc[i,:,:] = self.dataOutObj.data_cspc[i,:,minIndex:maxIndex+1]
451 449
452 450 #DC channel
453 dc = numpy.zeros( (nchannels,newheis), dtype='complex')
454 for i in range(nchannels):
451 dc = numpy.zeros( (nChannels,newheis), dtype='complex')
452 for i in range(nChannels):
455 453 dc[i] = self.dataOutObj.data_dc[i,minIndex:maxIndex+1]
456 454
457 455 self.dataOutObj.data_spc = spc
458 456 self.dataOutObj.data_cspc = cspc
459 457 self.dataOutObj.data_dc = dc
460 458
461 459 firstHeight = self.dataOutObj.heightList[minIndex]
462 460
463 461 self.dataOutObj.nHeights = newheis
464 462 self.dataOutObj.m_ProcessingHeader.blockSize = spc.size + cspc.size + dc.size
465 463 self.dataOutObj.m_ProcessingHeader.numHeights = newheis
466 464 self.dataOutObj.m_ProcessingHeader.firstHeight = firstHeight
467 465 self.dataOutObj.m_RadarControllerHeader.numHeights = newheis
468 466
469 467 xi = firstHeight
470 468 step = self.dataOutObj.m_ProcessingHeader.deltaHeight
471 469 xf = xi + newheis * step
472 470 self.dataOutObj.heightList = numpy.arange(xi, xf, step)
473 471
474 472
475 473 class IncoherentIntegration:
476 474 def __init__(self, N):
477 475 self.profCounter = 1
478 476 self.data = None
479 477 self.buffer = None
480 478 self.flag = False
481 479 self.nIncohInt = N
482 480
483 481 def exe(self,data):
484 482
485 483 if self.buffer == None:
486 484 self.buffer = data
487 485 else:
488 486 self.buffer = self.buffer + data
489 487
490 488 if self.profCounter == self.nIncohInt:
491 489 self.data = self.buffer
492 490 self.buffer = None
493 491 self.profCounter = 0
494 492 self.flag = True
495 493 else:
496 494 self.flag = False
497 495
498 496 self.profCounter += 1
499 497
@@ -1,73 +1,73
1 1 '''
2 2 Created on 23/01/2012
3 3
4 4 @author $Author$
5 5 @version $Id$
6 6 '''
7 7 import os, sys
8 8 import time, datetime
9 9
10 10 from Model.JROData import JROData
11 11 from IO.DataIO import *
12 12 #===============================================================================
13 13 # from Graphics.DataPlot import Osciloscope
14 14 #
15 15 # from Model.Spectra import Spectra
16 16 # from IO.SpectraIO import *
17 17 # from Graphics.SpectraPlot import Spectrum
18 18 #===============================================================================
19 19
20 20 class TestSChain():
21 21
22 22
23 23 def __init__(self):
24 24 self.setValues()
25 25 self.createObjects()
26 26 self.testSChain()
27 27 pass
28 28
29 29 def setValues(self):
30 30
31 31 #self.path = "/home/valentin/Tmp/RAWDATA"
32 32 self.path = "/home/dsuarez/Projects"
33 33 #self.wrpath = "/home/dsuarez/Projects/testWR"
34 34 self.startDateTime = datetime.datetime(2007,5,1,15,49,0)
35 35 self.endDateTime = datetime.datetime(2007,5,1,16,0,0)
36 36
37 37 def createObjects(self):
38 38
39 39 self.Obj = JROData()
40 40 self.readerObj = JRODataReader(self.Obj)
41 41 #self.plotObj = Spectrum(self.Obj)
42 42
43 43 if not(self.readerObj.setup(self.path, self.startDateTime, self.endDateTime, ext = '.pdata', expLabel='', online =1)):
44 44 sys.exit(0)
45 45
46 46 def testSChain(self):
47 47
48 48 ini = time.time()
49 49 while(True):
50 50 if self.readerObj.getData():
51 51 print "",
52 52 #self.plotObj.plotData(zmin=40, zmax=140, showColorbar=True, showPowerProfile=True)
53 53
54 54 # self.writerObj.putData()
55 55
56 56
57 57 if self.readerObj.noMoreFiles:
58 58 break
59 59
60 if self.readerObj.flagIsNewBlock and self.readerObj.nReadBlocks:
61 print 'Block No %04d, Time: %s' %(self.readerObj.nReadBlocks,
60 if self.readerObj.flagIsNewBlock and self.readerObj.nTotalBlocks:
61 print 'Block No %04d, Time: %s' %(self.readerObj.nTotalBlocks,
62 62 datetime.datetime.fromtimestamp(self.readerObj.m_BasicHeader.utc),)
63 63 #===============================================================
64 64 # fin = time.time()
65 65 # print 'Tiempo de un bloque leido y escrito: [%6.5f]' %(fin - ini)
66 66 # ini = time.time()
67 67 #===============================================================
68 68
69 69 #time.sleep(0.5)
70 70 self.plotObj.end()
71 71
72 72 if __name__ == '__main__':
73 73 TestSChain() No newline at end of file
@@ -1,98 +1,98
1 1 '''
2 2 Created on 23/01/2012
3 3
4 4 @author $Author$
5 5 @version $Id$
6 6 '''
7 7 import os, sys
8 8 import time, datetime
9 9
10 10 from Model.Voltage import Voltage
11 11 from IO.VoltageIO import *
12 12 from Graphics.VoltagePlot import Osciloscope
13 13
14 14 from Model.Spectra import Spectra
15 15 from IO.SpectraIO import *
16 16 from Graphics.SpectraPlot import Spectrum
17 17
18 18 class TestSChain():
19 19
20 20
21 21 def __init__(self):
22 22 self.setValues()
23 23 self.createObjects()
24 24 self.setupObjects()
25 25 self.testSChain()
26 26 pass
27 27
28 28 def setValues(self):
29 29
30 30 self.path = '/home/roj-idl71/Data/RAWDATA/DP_Faraday/'
31 31 self.path = '/Users/danielangelsuarezmunoz/Documents/Projects/testWR'
32 32 self.path = '/home/roj-idl71/Data/RAWDATA/IMAGING'
33 33 #self.path = '/remote/puma/2011_08/E-F_Valley'
34 34 #self.path = '/remote/puma/2011_12/EEJ+150km+ONAXIS+ESF+Twilight/Twilight/'
35 35 self.path = '/home/roj-idl71/tmp/data/'
36 36
37 37 self.ppath = "/home/roj-idl71/tmp/data"
38 38 self.startDateTime = datetime.datetime(2011,1,31,0,20,0)
39 39 self.endDateTime = datetime.datetime(2011,12,5,18,10,0)
40 40
41 41 def createObjects(self):
42 42
43 43 # self.Obj = Voltage()
44 44 # self.readerObj = VoltageReader(self.Obj)
45 45 # self.plotObj = Osciloscope(self.Obj)
46 46 # self.writerObj = VoltageWriter(self.Obj)
47 47
48 48 self.Obj = Spectra()
49 49 self.readerObj = SpectraReader(self.Obj)
50 50 self.plotObj = Spectrum(self.Obj)
51 51 # self.writerObj = SpectraWriter(self.Obj)
52 52
53 53 def setupObjects(self):
54 54
55 55 if not(self.readerObj.setup(self.path, self.startDateTime, self.endDateTime, expLabel='', online = 0)):
56 56 sys.exit(0)
57 57
58 58 print "Parameters:"
59 59
60 60 print "Num profiles: %s" %(self.readerObj.m_SystemHeader.numProfiles)
61 61 print "Num samples: %s" %(self.readerObj.m_SystemHeader.numSamples)
62 62 print "Num channels: %s" %(self.readerObj.m_SystemHeader.numChannels)
63 63
64 64 print "Num profiles per block: %s" %(self.readerObj.m_ProcessingHeader.profilesPerBlock)
65 65 print "Num heights: %s" %(self.readerObj.m_ProcessingHeader.numHeights)
66 66 print "Num coh int: %s" %(self.readerObj.m_ProcessingHeader.coherentInt)
67 67 print "Num incoh int: %s" %(self.readerObj.m_ProcessingHeader.incoherentInt)
68 68
69 69 print "Num code: %d" %(self.readerObj.m_ProcessingHeader.numCode)
70 70 print "Num baud: %d" %(self.readerObj.m_ProcessingHeader.numBaud)
71 71
72 72 # if not(self.writerObj.setup(self.ppath)):
73 73 # sys.exit(0)
74 74
75 75 def testSChain(self):
76 76
77 77 ini = time.time()
78 78 while(True):
79 79 self.readerObj.getData()
80 80 self.plotObj.plotData(zmin=40, zmax=140, showColorbar=True, showPowerProfile=True)
81 81 #self.plotObj.plotData(idProfile=1, type="power")
82 82 # self.writerObj.putData()
83 83
84 84 if self.readerObj.noMoreFiles:
85 85 break
86 86
87 87 if self.readerObj.flagIsNewBlock:
88 print 'Block No %04d, Time: %s' %(self.readerObj.nReadBlocks,
88 print 'Block No %04d, Time: %s' %(self.readerObj.nTotalBlocks,
89 89 datetime.datetime.fromtimestamp(self.readerObj.m_BasicHeader.utc),)
90 90 fin = time.time()
91 91 print 'Tiempo de un bloque leido y escrito: [%6.5f]' %(fin - ini)
92 92 ini = time.time()
93 93
94 94 #time.sleep(0.5)
95 95 self.plotObj.end()
96 96
97 97 if __name__ == '__main__':
98 98 TestSChain() No newline at end of file
@@ -1,102 +1,102
1 1 '''
2 2 Created on 27/03/2012
3 3
4 4 @author $Author$
5 5 @version $Id$
6 6 '''
7 7 import os, sys
8 8 import time, datetime
9 9
10 10 from Model.Voltage import Voltage
11 11 from IO.VoltageIO import *
12 12 #from Graphics.VoltagePlot import Osciloscope
13 13
14 14 from Model.Spectra import Spectra
15 15 from IO.SpectraIO import *
16 16
17 17 from Processing.VoltageProcessor import *
18 18 from Processing.SpectraProcessor import *
19 19
20 20 class TestSChain():
21 21
22 22 def __init__(self):
23 23 self.setValues()
24 24 self.createObjects()
25 25 self.testSChain()
26 26
27 27
28 28 def setValues( self ):
29 29
30 30 self.path = "/home/dsuarez/Projects" #1
31 #self.path = "/home/valentin/Tmp/VOLTAGE2" #2
31 self.path = "/home/roj-idl71/Data/RAWDATA/IMAGING"
32 32 # self.startDateTime = datetime.datetime(2007,5,1,15,49,0)
33 33 # self.endDateTime = datetime.datetime(2007,5,1,23,0,0)
34 34
35 35 self.startDateTime = datetime.datetime(2011,10,4,0,0,0)
36 36 self.endDateTime = datetime.datetime(2011,10,4,0,20,0)
37 self.N = 2
38 self.npts = 4
37 self.N = 10
38 self.npts = 1024
39 39
40 40 def createObjects( self ):
41 41
42 self.Obj = Voltage()
43 self.OutObj = Voltage()
44 self.readerObj = VoltageReader(self.Obj)
45 self.procObj = VoltageProcessor(self.Obj, self.OutObj)
42 self.voltObj1 = Voltage()
43 self.voltObj2 = Voltage()
44 self.specObj1 = Spectra()
46 45
47 self.spectraObj = Spectra()
48 self.specProcObj = SpectraProcessor(self.OutObj, self.spectraObj,self.npts)
46 self.readerObj = VoltageReader(self.voltObj1)
47 self.voltProcObj = VoltageProcessor(self.voltObj1, self.voltObj2)
48 self.specProcObj = SpectraProcessor(self.voltObj2, self.specObj1)
49 49
50 50
51 #self.plotObj = Osciloscope(self.Obj)
51 #self.plotObj = Osciloscope(self.voltObj1)
52 52
53 53 if not(self.readerObj.setup( self.path, self.startDateTime, self.endDateTime, expLabel='', online =0) ):
54 54 sys.exit(0)
55 55
56 56 # if not(self.readerObj.setup(self.path, self.startDateTime, self.endDateTime)):
57 57 # sys.exit(0)
58 58
59 59 def testSChain( self ):
60 60
61 61 ini = time.time()
62 62 while(True):
63 63 self.readerObj.getData()
64 64
65 self.procObj.init()
65 self.voltProcObj.init()
66 66
67 self.procObj.plotData(idProfile = 1, type='power',winTitle='figura 1')
67 # self.voltProcObj.plotData(idProfile = 1, type='iq', ymin=-25000, ymax=25000, winTitle='sin decodificar')
68 68
69 self.procObj.decoder(type=0)
69 self.voltProcObj.decoder(type=0)
70 70
71 # self.procObj.plotData(idProfile = 1, type='iq', xmin=0, xmax=100,winTitle='figura 2')
71 # self.voltProcObj.plotData(idProfile = 1, type='iq', ymin=-70000, ymax=70000,winTitle='Decodificado')
72 72 #
73 # self.procObj.integrator(self.N)
73 self.voltProcObj.integrator(self.N)
74 74
75 self.procObj.plotData(idProfile = 1, type='power',winTitle='figura 3')
75 # self.voltProcObj.plotData(idProfile = 1, type='iq', ymin=-700000, ymax=700000,winTitle='figura 3')
76 76
77 self.specProcObj.init()
77 self.specProcObj.init(self.npts)
78 78
79 79 self.specProcObj.integrator(2)
80 80
81 self.specProcObj.plotData(winTitle='Spectra 1', index=2)
81 self.specProcObj.plotData(winTitle='Spectra 1', index=0)
82 82
83 83 # if self.readerObj.getData():
84 84 # self.plotObj.plotData(idProfile=0, type='power' )
85 85 #
86 86 #
87 # if self.readerObj.flagNoMoreFiles:
88 # break
87 if self.readerObj.flagNoMoreFiles:
88 break
89 89 #
90 90 if self.readerObj.flagIsNewBlock:
91 print 'Block No %04d, Time: %s' %(self.readerObj.nReadBlocks,
91 print 'Block No %04d, Time: %s' %(self.readerObj.nTotalBlocks,
92 92 datetime.datetime.fromtimestamp(self.readerObj.m_BasicHeader.utc),)
93 93
94 94 # fin = time.time()
95 95 # print 'Tiempo de un bloque leido y escrito: [%6.5f]' %(fin - ini)
96 96 # ini = time.time()
97 97
98 98 #time.sleep(0.5)
99 99 # self.plotObj.end()
100 100
101 101 if __name__ == '__main__':
102 102 TestSChain() No newline at end of file
@@ -1,72 +1,72
1 1 '''
2 2 Created on 23/01/2012
3 3
4 4 @author $Author$
5 5 @version $Id$
6 6 '''
7 7 import os, sys
8 8 import time, datetime
9 9
10 10 from Model.Voltage import Voltage
11 11 from IO.VoltageIO import *
12 12 from Graphics.VoltagePlot import Osciloscope
13 13
14 14 from Model.Spectra import Spectra
15 15 from IO.SpectraIO import *
16 16 from Graphics.SpectraPlot import Spectrum
17 17
18 18 class TestSChain():
19 19
20 20 def __init__(self):
21 21 self.setValues()
22 22 self.createObjects()
23 23 self.testSChain()
24 24 pass
25 25
26 26 def setValues(self):
27 27
28 28 #self.path = "/home/valentin/Tmp/RAWDATA"
29 29 self.path = "/home/valentin/Tmp/RAWDATA"
30 30 self.startDateTime = datetime.datetime(2009,11,2,00,00,0)
31 31 self.endDateTime = datetime.datetime(2009,11,30,18,10,0)
32 32
33 33 def createObjects(self):
34 34
35 35 self.Obj = Spectra()
36 36 self.readerObj = SpectraReader(self.Obj)
37 37 self.plotObj = Spectrum(self.Obj)
38 38 # self.writerObj = SpectraWriter(self.Obj)
39 39
40 40 if not(self.readerObj.setup(self.path, self.startDateTime, self.endDateTime, expLabel='', online =1)): #self.startDateTime
41 41 sys.exit(0)
42 42
43 43 # if not(self.writerObj.setup(self.ppath)):
44 44 # sys.exit(0)
45 45
46 46 def testSChain(self):
47 47
48 48 ini = time.time()
49 49 while(True):
50 50 if self.readerObj.getData():
51 51 self.plotObj.plotData(showColorbar=True, showPowerProfile=True) #zmin=40, zmax=140,
52 52
53 53 # self.writerObj.putData()
54 54
55 55
56 56 if self.readerObj.flagNoMoreFiles:
57 57 break
58 58
59 if self.readerObj.flagIsNewBlock and self.readerObj.nReadBlocks:
60 print 'Block No %04d, Time: %s' %(self.readerObj.nReadBlocks,
59 if self.readerObj.flagIsNewBlock and self.readerObj.nTotalBlocks:
60 print 'Block No %04d, Time: %s' %(self.readerObj.nTotalBlocks,
61 61 datetime.datetime.fromtimestamp(self.readerObj.m_BasicHeader.utc),)
62 62 #===============================================================
63 63 # fin = time.time()
64 64 # print 'Tiempo de un bloque leido y escrito: [%6.5f]' %(fin - ini)
65 65 # ini = time.time()
66 66 #===============================================================
67 67
68 68 #time.sleep(0.5)
69 69 self.plotObj.end()
70 70
71 71 if __name__ == '__main__':
72 72 TestSChain() No newline at end of file
@@ -1,73 +1,73
1 1 '''
2 2 Created on 20/03/2012
3 3
4 4 @author $Author$
5 5 @version $Id$
6 6 '''
7 7 import os, sys
8 8 import time, datetime
9 9
10 10 from Model.Voltage import Voltage
11 11 from IO.VoltageIO import *
12 12 from Graphics.VoltagePlot import Osciloscope
13 13
14 14 from Model.Spectra import Spectra
15 15 from IO.SpectraIO import *
16 16 from Graphics.SpectraPlot import Spectrum
17 17
18 18 class TestSChain():
19 19
20 20 def __init__(self):
21 21 self.setValues()
22 22 self.createObjects()
23 23 self.testSChain()
24 24 pass
25 25
26 26 def setValues(self):
27 27 self.srcPath = "/home/valentin/Tmp/RAWDATA"
28 28 self.dstPath = "/home/valentin/Tmp/RAWDATA2"
29 29 self.startDateTime = datetime.datetime(2009,11,1,00,00,0) #4
30 30 self.endDateTime = datetime.datetime(2009,11,30,18,10,0)
31 31
32 32 def createObjects(self):
33 33
34 34 self.Obj = Spectra()
35 35 self.readerObj = SpectraReader(self.Obj)
36 36 self.writerObj = SpectraWriter(self.Obj)
37 37 self.plotObj = Spectrum(self.Obj)
38 38
39 39 if not( self.readerObj.setup(self.srcPath, self.startDateTime, self.endDateTime, expLabel='', online =0) ):
40 40 sys.exit(0)
41 41
42 42 if not( self.writerObj.setup(path=self.dstPath) ): sys.exit(0)
43 43
44 44
45 45 def testSChain(self):
46 46
47 47 ini = time.time()
48 48 while(True):
49 49 if self.readerObj.getData():
50 50 self.plotObj.plotData( zmin=35, zmax=100, showColorbar=True, showPowerProfile=True)
51 51
52 52 ###################################################################################
53 53 #time.sleep( 2 )
54 54 self.writerObj.putData()
55 55 ###################################################################################
56 56
57 57 if self.readerObj.flagNoMoreFiles:
58 58 break
59 59
60 if self.readerObj.flagIsNewBlock and self.readerObj.nReadBlocks:
61 print 'Block No %04d, Time: %s' %(self.readerObj.nReadBlocks,
60 if self.readerObj.flagIsNewBlock and self.readerObj.nTotalBlocks:
61 print 'Block No %04d, Time: %s' %(self.readerObj.nTotalBlocks,
62 62 datetime.datetime.fromtimestamp(self.readerObj.m_BasicHeader.utc))
63 63 #===============================================================
64 64 # fin = time.time()
65 65 # print 'Tiempo de un bloque leido y escrito: [%6.5f]' %(fin - ini)
66 66 # ini = time.time()
67 67 #===============================================================
68 68
69 69 #time.sleep(0.5)
70 70 self.plotObj.end()
71 71
72 72 if __name__ == '__main__':
73 73 TestSChain() No newline at end of file
General Comments 0
You need to be logged in to leave comments. Login now