This diff has been collapsed as it changes many lines, (786 lines changed) Show them Hide them | |||
@@ -1,948 +1,1566 | |||
|
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 IO.HeaderIO import * |
|
18 | 18 | from IO.DataIO import DataReader |
|
19 | 19 | from IO.DataIO import DataWriter |
|
20 | 20 | |
|
21 | 21 | from Model.Voltage import Voltage |
|
22 | 22 | |
|
23 | ||
|
24 | def getlastFileFromPath( pathList, ext ): | |
|
25 | """ | |
|
26 | Depura el pathList dejando solo los que cumplan el formato de "PYYYYDDDSSS.ext" | |
|
27 | al final de la depuracion devuelve el ultimo file de la lista que quedo. | |
|
28 | ||
|
29 | Input: | |
|
30 | pathList : lista conteniendo todos los filename completos que componen una determinada carpeta | |
|
31 | ext : extension de los files contenidos en una carpeta | |
|
32 | ||
|
33 | Return: | |
|
34 | El ultimo file de una determinada carpeta | |
|
35 | """ | |
|
36 | ||
|
37 | filesList = [] | |
|
38 | filename = None | |
|
39 | ||
|
40 | # 0 1234 567 89A BCDE | |
|
41 | # D YYYY DDD SSS .ext | |
|
42 | ||
|
43 | for filename in pathList: | |
|
44 | year = filename[1:5] | |
|
45 | doy = filename[5:8] | |
|
46 | leng = len( ext ) | |
|
47 | ||
|
48 | if ( filename[-leng:].upper() != ext.upper() ) : continue | |
|
49 | if not( isNumber( year ) ) : continue | |
|
50 | if not( isNumber( doy ) ) : continue | |
|
51 | ||
|
52 | filesList.append(filename) | |
|
53 | ||
|
54 | if len( filesList ) > 0: | |
|
55 | filesList = sorted( filesList, key=str.lower ) | |
|
56 | filename = filesList[-1] | |
|
57 | ||
|
58 | return filename | |
|
59 | ||
|
60 | ||
|
61 | def checkForRealPath( path, year, doy, set, ext ): | |
|
62 | """ | |
|
63 | Por ser Linux Case Sensitive entonces checkForRealPath encuentra el nombre correcto de un path, | |
|
64 | Prueba por varias combinaciones de nombres entre mayusculas y minusculas para determinar | |
|
65 | el path exacto de un determinado file. | |
|
66 | ||
|
67 | Example : | |
|
68 | nombre correcto del file es ../RAWDATA/D2009307/P2009307367 | |
|
69 | ||
|
70 | Entonces la funcion prueba con las siguientes combinaciones | |
|
71 | ../RAWDATA/d2009307/p2009307367 | |
|
72 | ../RAWDATA/d2009307/P2009307367 | |
|
73 | ../RAWDATA/D2009307/p2009307367 | |
|
74 | ../RAWDATA/D2009307/P2009307367 | |
|
75 | siendo para este caso, la ultima combinacion de letras, identica al file buscado | |
|
76 | ||
|
77 | Return: | |
|
78 | Si encuentra la cobinacion adecuada devuelve el path completo y el nombre del file | |
|
79 | caso contrario devuelve None como path y el la ultima combinacion de nombre en mayusculas | |
|
80 | para el filename | |
|
81 | """ | |
|
82 | filepath = None | |
|
83 | find_flag = False | |
|
84 | filename = None | |
|
85 | ||
|
86 | for dir in "dD": #barrido por las dos combinaciones posibles de "D" | |
|
87 | for fil in "dD": #barrido por las dos combinaciones posibles de "D" | |
|
88 | doypath = "%s%04d%03d" % ( dir, year, doy ) #formo el nombre del directorio xYYYYDDD (x=d o x=D) | |
|
89 | filename = "%s%04d%03d%03d%s" % ( fil, year, doy, set, ext ) #formo el nombre del file xYYYYDDDSSS.ext (p=d o p=D) | |
|
90 | filepath = os.path.join( path, doypath, filename ) #formo el path completo | |
|
91 | if os.path.exists( filepath ): #verifico que exista | |
|
92 | find_flag = True | |
|
93 | break | |
|
94 | if find_flag: | |
|
95 | break | |
|
96 | ||
|
97 | if not(find_flag): | |
|
98 | return None, filename | |
|
99 | ||
|
100 | return filepath, filename | |
|
101 | ||
|
102 | ||
|
103 | def isNumber( str ): | |
|
104 | """ | |
|
105 | Chequea si el conjunto de caracteres que componen un string puede ser convertidos a un numero. | |
|
106 | ||
|
107 | Excepciones: | |
|
108 | Si un determinado string no puede ser convertido a numero | |
|
109 | Input: | |
|
110 | str, string al cual se le analiza para determinar si convertible a un numero o no | |
|
111 | ||
|
112 | Return: | |
|
113 | True : si el string es uno numerico | |
|
114 | False : no es un string numerico | |
|
115 | """ | |
|
116 | try: | |
|
117 | float( str ) | |
|
118 | return True | |
|
119 | except: | |
|
120 | return False | |
|
121 | ||
|
122 | ||
|
23 | 123 | def isThisFileinRange(filename, startUTSeconds, endUTSeconds): |
|
24 | 124 | """ |
|
25 | 125 | Esta funcion determina si un archivo de datos en formato Jicamarca(.r) se encuentra |
|
26 | 126 | o no dentro del rango de fecha especificado. |
|
27 | 127 | |
|
28 | 128 | Inputs: |
|
29 | 129 | filename : nombre completo del archivo de datos en formato Jicamarca (.r) |
|
30 | 130 | |
|
31 | 131 | startUTSeconds : fecha inicial del rango seleccionado. La fecha esta dada en |
|
32 | 132 | segundos contados desde 01/01/1970. |
|
33 | 133 | endUTSeconds : fecha final del rango seleccionado. La fecha esta dada en |
|
34 | 134 | segundos contados desde 01/01/1970. |
|
35 | 135 | |
|
36 | 136 | Return: |
|
37 | 137 | Boolean : Retorna True si el archivo de datos contiene datos en el rango de |
|
38 | 138 | fecha especificado, de lo contrario retorna False. |
|
39 | 139 | |
|
40 | 140 | Excepciones: |
|
41 | 141 | Si el archivo no existe o no puede ser abierto |
|
42 | 142 | Si la cabecera no puede ser leida. |
|
43 | 143 | |
|
44 | 144 | """ |
|
45 | 145 | m_BasicHeader = BasicHeader() |
|
46 | 146 | |
|
47 | 147 | try: |
|
48 | 148 | fp = open(filename,'rb') |
|
49 | 149 | except: |
|
50 | 150 | raise IOError, "The file %s can't be opened" %(filename) |
|
51 | 151 | |
|
52 | 152 | if not(m_BasicHeader.read(fp)): |
|
53 | 153 | raise IOError, "The file %s has not a valid header" %(filename) |
|
54 | 154 | |
|
55 | 155 | fp.close() |
|
56 | 156 | |
|
57 | 157 | if not ((startUTSeconds <= m_BasicHeader.utc) and (endUTSeconds >= m_BasicHeader.utc)): |
|
58 | 158 | return 0 |
|
59 | 159 | |
|
60 | 160 | return 1 |
|
61 | 161 | |
|
62 | 162 | class VoltageReader(DataReader): |
|
63 | 163 | """ |
|
64 | 164 | Esta clase permite leer datos de voltage desde archivos en formato rawdata (.r). La lectura |
|
65 | 165 | de los datos siempre se realiza por bloques. Los datos leidos (array de 3 dimensiones: |
|
66 | 166 | perfiles*alturas*canales) son almacenados en la variable "buffer". |
|
67 | 167 | |
|
68 | 168 | Esta clase contiene instancias (objetos) de las clases BasicHeader, SystemHeader, |
|
69 | 169 | RadarControllerHeader y Voltage. Los tres primeros se usan para almacenar informacion de la |
|
70 | 170 | cabecera de datos (metadata), y el cuarto (Voltage) para obtener y almacenar un perfil de |
|
71 | 171 | datos desde el "buffer" cada vez que se ejecute el metodo "getData". |
|
72 | 172 | |
|
73 | 173 | Example: |
|
74 | 174 | |
|
75 | 175 | dpath = "/home/myuser/data" |
|
76 | 176 | |
|
77 | 177 | startTime = datetime.datetime(2010,1,20,0,0,0,0,0,0) |
|
78 | 178 | |
|
79 | 179 | endTime = datetime.datetime(2010,1,21,23,59,59,0,0,0) |
|
80 | 180 | |
|
81 | 181 | readerObj = VoltageReader() |
|
82 | 182 | |
|
83 | 183 | readerObj.setup(dpath, startTime, endTime) |
|
84 | 184 | |
|
85 | 185 | while(True): |
|
86 | 186 | |
|
87 | 187 | #to get one profile |
|
88 | 188 | profile = readerObj.getData() |
|
89 | 189 | |
|
90 | 190 | #print the profile |
|
91 | 191 | print profile |
|
92 | 192 | |
|
93 | 193 | #If you want to see all datablock |
|
94 | 194 | print readerObj.datablock |
|
95 | 195 | |
|
96 | 196 | if readerObj.noMoreFiles: |
|
97 | 197 | break |
|
98 | 198 | |
|
99 | 199 | """ |
|
100 | 200 | |
|
101 | 201 | #speed of light |
|
102 | 202 | __c = 3E8 |
|
103 | 203 | |
|
104 | 204 | def __init__(self, m_Voltage = None): |
|
105 | 205 | """ |
|
106 | 206 | Inicializador de la clase VoltageReader para la lectura de datos de voltage. |
|
107 | 207 | |
|
108 | 208 | Input: |
|
109 | 209 | m_Voltage : Objeto de la clase Voltage. Este objeto sera utilizado para |
|
110 | 210 | almacenar un perfil de datos cada vez que se haga un requerimiento |
|
111 | 211 | (getData). El perfil sera obtenido a partir del buffer de datos, |
|
112 | 212 | si el buffer esta vacio se hara un nuevo proceso de lectura de un |
|
113 | 213 | bloque de datos. |
|
114 | 214 | Si este parametro no es pasado se creara uno internamente. |
|
115 | 215 | |
|
116 | 216 | Variables afectadas: |
|
117 | 217 | self.m_Voltage |
|
118 | 218 | self.m_BasicHeader |
|
119 | 219 | self.m_SystemHeader |
|
120 | 220 | self.m_RadarControllerHeader |
|
121 | 221 | self.m_ProcessingHeader |
|
122 | 222 | |
|
123 | 223 | |
|
124 | 224 | Return: |
|
125 | 225 | Void |
|
126 | 226 | |
|
127 | 227 | """ |
|
128 | 228 | if m_Voltage == None: |
|
129 | 229 | m_Voltage = Voltage() |
|
130 | 230 | |
|
131 | 231 | if not(isinstance(m_Voltage, Voltage)): |
|
132 | 232 | raise ValueError, "in VoltageReader, m_Voltage must be an Voltage class object" |
|
133 | 233 | |
|
134 | 234 | self.m_Voltage = m_Voltage |
|
135 | 235 | |
|
136 | 236 | self.m_BasicHeader = BasicHeader() |
|
137 | 237 | |
|
138 | 238 | self.m_SystemHeader = SystemHeader() |
|
139 | 239 | |
|
140 | 240 | self.m_RadarControllerHeader = RadarControllerHeader() |
|
141 | 241 | |
|
142 | 242 | self.m_ProcessingHeader = ProcessingHeader() |
|
143 | 243 | |
|
144 | 244 | self.__fp = None |
|
145 | 245 | |
|
146 | 246 | self.__idFile = None |
|
147 | 247 | |
|
148 | 248 | self.__startDateTime = None |
|
149 | 249 | |
|
150 | 250 | self.__endDateTime = None |
|
151 | 251 | |
|
152 | 252 | self.__dataType = None |
|
153 | 253 | |
|
154 | 254 | self.__fileSizeByHeader = 0 |
|
155 | 255 | |
|
156 | 256 | self.__pathList = [] |
|
157 | 257 | |
|
158 | 258 | self.filenameList = [] |
|
159 | 259 | |
|
160 | 260 | self.__lastUTTime = 0 |
|
161 | 261 | |
|
162 | 262 | self.__maxTimeStep = 30 |
|
163 | 263 | |
|
164 | 264 | self.__flagIsNewFile = 0 |
|
165 | 265 | |
|
166 | 266 | self.__ippSeconds = 0 |
|
167 | 267 | |
|
168 | 268 | self.flagResetProcessing = 0 |
|
169 | 269 | |
|
170 | 270 | self.flagIsNewBlock = 0 |
|
171 | 271 | |
|
172 | 272 | self.noMoreFiles = 0 |
|
173 | 273 | |
|
174 | 274 | self.nReadBlocks = 0 |
|
175 | 275 | |
|
176 | 276 | self.online = 0 |
|
177 | 277 | |
|
178 | 278 | self.filename = None |
|
179 | 279 | |
|
180 | 280 | self.fileSize = None |
|
181 | 281 | |
|
182 | 282 | self.firstHeaderSize = 0 |
|
183 | 283 | |
|
184 | 284 | self.basicHeaderSize = 24 |
|
185 | 285 | |
|
186 | 286 | self.idProfile = 0 |
|
187 | 287 | |
|
188 | 288 | self.datablock = None |
|
189 | 289 | |
|
190 | 290 | self.__datablockIndex = 9999 |
|
291 | ||
|
292 | self.__delay = 7 #seconds | |
|
293 | self.__nTries = 3 #quantity tries | |
|
294 | self.__nFiles = 3 #number of files for searching | |
|
295 | self.__year = 0 | |
|
296 | self.__doy = 0 | |
|
297 | self.__set = 0 | |
|
298 | self.__ext = None | |
|
299 | self.__path = None | |
|
300 | self.__pts2read = 0 | |
|
301 | self.__blocksize = 0 | |
|
191 | 302 | |
|
192 | 303 | def __rdSystemHeader(self,fp=None): |
|
193 | 304 | if fp == None: |
|
194 | 305 | fp = self.__fp |
|
195 | 306 | |
|
196 | 307 | self.m_SystemHeader.read(fp) |
|
197 | 308 | |
|
198 | 309 | def __rdRadarControllerHeader(self,fp=None): |
|
199 | 310 | if fp == None: |
|
200 | 311 | fp = self.__fp |
|
201 | 312 | |
|
202 | 313 | self.m_RadarControllerHeader.read(fp) |
|
203 | 314 | |
|
204 | 315 | def __rdProcessingHeader(self,fp=None): |
|
205 | 316 | if fp == None: |
|
206 | 317 | fp = self.__fp |
|
207 | 318 | |
|
208 | 319 | self.m_ProcessingHeader.read(fp) |
|
209 | 320 | |
|
210 | 321 | def __rdBasicHeader(self, fp=None): |
|
211 | 322 | |
|
212 | 323 | if fp == None: |
|
213 | 324 | fp = self.__fp |
|
214 | 325 | |
|
215 | 326 | self.m_BasicHeader.read(fp) |
|
216 | 327 | |
|
217 | 328 | def __readFirstHeader(self): |
|
218 | 329 | |
|
219 | 330 | self.__rdBasicHeader() |
|
220 | 331 | self.__rdSystemHeader() |
|
221 | 332 | self.__rdRadarControllerHeader() |
|
222 | 333 | self.__rdProcessingHeader() |
|
223 | 334 | self.firstHeaderSize = self.m_BasicHeader.size |
|
224 | 335 | |
|
225 | 336 | data_type=int(numpy.log2((self.m_ProcessingHeader.processFlags & PROCFLAG.DATATYPE_MASK))-numpy.log2(PROCFLAG.DATATYPE_CHAR)) |
|
226 | 337 | if data_type == 0: |
|
227 | 338 | tmp = numpy.dtype([('real','<i1'),('imag','<i1')]) |
|
228 | 339 | |
|
229 | 340 | elif data_type == 1: |
|
230 | 341 | tmp = numpy.dtype([('real','<i2'),('imag','<i2')]) |
|
231 | 342 | |
|
232 | 343 | elif data_type == 2: |
|
233 | 344 | tmp = numpy.dtype([('real','<i4'),('imag','<i4')]) |
|
234 | 345 | |
|
235 | 346 | elif data_type == 3: |
|
236 | 347 | tmp = numpy.dtype([('real','<i8'),('imag','<i8')]) |
|
237 | 348 | |
|
238 | 349 | elif data_type == 4: |
|
239 | 350 | tmp = numpy.dtype([('real','<f4'),('imag','<f4')]) |
|
240 | 351 | |
|
241 | 352 | elif data_type == 5: |
|
242 | 353 | tmp = numpy.dtype([('real','<f8'),('imag','<f8')]) |
|
243 | 354 | |
|
244 | 355 | else: |
|
245 | 356 | raise ValueError, 'Data type was not defined' |
|
246 | 357 | |
|
247 | 358 | xi = self.m_ProcessingHeader.firstHeight |
|
248 | 359 | step = self.m_ProcessingHeader.deltaHeight |
|
249 | 360 | xf = xi + self.m_ProcessingHeader.numHeights*step |
|
250 | 361 | |
|
251 | 362 | self.__heights = numpy.arange(xi, xf, step) |
|
252 | 363 | self.__dataType = tmp |
|
253 | 364 | self.__fileSizeByHeader = self.m_ProcessingHeader.dataBlocksPerFile * self.m_ProcessingHeader.blockSize + self.firstHeaderSize + self.basicHeaderSize*(self.m_ProcessingHeader.dataBlocksPerFile - 1) |
|
254 | 365 | self.__ippSeconds = 2*1000*self.m_RadarControllerHeader.ipp/self.__c |
|
366 | ||
|
367 | self.__pts2read = self.m_ProcessingHeader.profilesPerBlock * self.m_ProcessingHeader.numHeights * self.m_SystemHeader.numChannels | |
|
368 | self.__blocksize = self.__pts2read | |
|
369 | ||
|
255 | 370 | |
|
256 | def __setNextFileOnline(self): | |
|
257 | return 0 | |
|
371 | def __setNextFileOnline( self ): | |
|
372 | """ | |
|
373 | Busca el siguiente file que tenga suficiente data para ser leida, dentro de un folder especifico, si | |
|
374 | no encuentra un file valido espera un tiempo determinado y luego busca en los posibles n files | |
|
375 | siguientes. | |
|
376 | ||
|
377 | Affected: | |
|
378 | self.__flagIsNewFile | |
|
379 | self.filename | |
|
380 | self.fileSize | |
|
381 | self.__fp | |
|
382 | self.__set | |
|
383 | self.noMoreFiles | |
|
384 | ||
|
385 | Return: | |
|
386 | 0 : si luego de una busqueda del siguiente file valido este no pudo ser encontrado | |
|
387 | 1 : si el file fue abierto con exito y esta listo a ser leido | |
|
388 | ||
|
389 | Excepciones: | |
|
390 | Si un determinado file no puede ser abierto | |
|
391 | """ | |
|
392 | countFiles = 0 | |
|
393 | countTries = 0 | |
|
394 | ||
|
395 | fileStatus = 0 | |
|
396 | notFirstTime_flag = False | |
|
397 | bChangeDir = False | |
|
398 | ||
|
399 | fileSize = 0 | |
|
400 | fp = None | |
|
401 | ||
|
402 | self.__flagIsNewFile = 0 | |
|
403 | ||
|
404 | while( True ): #este loop permite llevar la cuenta de intentos, de files y carpetas, | |
|
405 | #si no encuentra alguno sale del bucle | |
|
406 | countFiles += 1 | |
|
407 | ||
|
408 | if countFiles > (self.__nFiles + 1): | |
|
409 | break | |
|
410 | ||
|
411 | self.__set += 1 | |
|
412 | ||
|
413 | if countFiles > self.__nFiles: #si no encuentro el file buscado cambio de carpeta y busco en la siguiente carpeta | |
|
414 | self.__set = 0 | |
|
415 | self.__doy += 1 | |
|
416 | bChangeDir = True | |
|
417 | ||
|
418 | file = None | |
|
419 | filename = None | |
|
420 | ||
|
421 | countTries = 0 | |
|
422 | ||
|
423 | #espero hasta encontrar el 1er file disponible | |
|
424 | while( True ): | |
|
425 | ||
|
426 | countTries += 1 | |
|
427 | if( countTries >= self.__nTries ): #checkeo que no haya ido mas alla de la cantidad de intentos | |
|
428 | break | |
|
429 | ||
|
430 | file, filename = checkForRealPath( self.__path, self.__year, self.__doy, self.__set, self.__ext ) | |
|
431 | if file != None: | |
|
432 | break | |
|
433 | ||
|
434 | if notFirstTime_flag: #este flag me sirve solo para esperar por el 1er file, en lo siguientes no espera solo checkea si existe o no | |
|
435 | countTries = self.__nTries | |
|
436 | print "\tsearching next \"%s\" file ..." % filename | |
|
437 | break | |
|
438 | ||
|
439 | print "\twaiting new \"%s\" file ..." % filename | |
|
440 | time.sleep( self.__delay ) | |
|
441 | ||
|
442 | if countTries >= self.__nTries: #se realizaron n intentos y no hubo un file nuevo | |
|
443 | notFirstTime_flag = True | |
|
444 | continue #vuelvo al inico del while principal | |
|
445 | ||
|
446 | countTries = 0 | |
|
447 | ||
|
448 | #una vez que se obtuvo el 1er file valido se procede a checkear su contenido, y se espera una cierta cantidad | |
|
449 | #de tiempo por una cierta cantidad de veces hasta que el contenido del file sea un contenido valido | |
|
450 | while( True ): | |
|
451 | countTries += 1 | |
|
452 | if countTries > self.__nTries: | |
|
453 | break | |
|
454 | ||
|
455 | try: | |
|
456 | fp = open(file) | |
|
457 | except: | |
|
458 | print "The file \"%s\" can't be opened" % file | |
|
459 | break | |
|
460 | ||
|
461 | fileSize = os.path.getsize( file ) | |
|
462 | currentSize = fileSize - fp.tell() | |
|
463 | neededSize = self.m_ProcessingHeader.blockSize + self.firstHeaderSize | |
|
464 | ||
|
465 | if currentSize > neededSize: | |
|
466 | fileStatus = 1 | |
|
467 | break | |
|
468 | ||
|
469 | fp.close() | |
|
470 | ||
|
471 | if bChangeDir: #si al buscar un file cambie de directorio ya no espero y salgo del bucle while | |
|
472 | print "\tsearching next \"%s\" file ..." % filename | |
|
473 | break | |
|
474 | ||
|
475 | print "\twaiting for block of \"%s\" file ..." % filename | |
|
476 | time.sleep( self.__delay ) | |
|
477 | ||
|
478 | if fileStatus == 1: | |
|
479 | break | |
|
480 | ||
|
481 | print "Skipping the file \"%s\" due to this files is empty" % filename | |
|
482 | countFiles = 0 | |
|
483 | ||
|
484 | ||
|
485 | if fileStatus == 1: | |
|
486 | self.fileSize = fileSize | |
|
487 | self.filename = file | |
|
488 | self.__flagIsNewFile = 1 | |
|
489 | self.__fp = fp | |
|
490 | self.noMoreFiles = 0 | |
|
491 | print 'Setting the file: %s' % file | |
|
492 | else: | |
|
493 | self.fileSize = 0 | |
|
494 | self.filename = None | |
|
495 | self.__fp = None | |
|
496 | self.noMoreFiles = 1 | |
|
497 | print 'No more Files' | |
|
498 | ||
|
499 | return fileStatus | |
|
500 | ||
|
258 | 501 | |
|
259 | 502 | def __setNextFileOffline(self): |
|
260 | 503 | |
|
261 | 504 | idFile = self.__idFile |
|
262 | 505 | while(True): |
|
263 | 506 | |
|
264 | 507 | idFile += 1 |
|
265 | 508 | |
|
266 | 509 | if not(idFile < len(self.filenameList)): |
|
267 | 510 | self.noMoreFiles = 1 |
|
268 | 511 | return 0 |
|
269 | 512 | |
|
270 | 513 | filename = self.filenameList[idFile] |
|
271 | 514 | fileSize = os.path.getsize(filename) |
|
272 | 515 | |
|
273 | 516 | try: |
|
274 | 517 | fp = open(filename,'rb') |
|
275 | 518 | except: |
|
276 | 519 | raise IOError, "The file %s can't be opened" %filename |
|
277 | 520 | |
|
278 | 521 | currentSize = fileSize - fp.tell() |
|
279 | 522 | neededSize = self.m_ProcessingHeader.blockSize + self.firstHeaderSize |
|
280 | 523 | |
|
281 | 524 | if (currentSize < neededSize): |
|
282 | 525 | print "Skipping the file %s due to it hasn't enough data" %filename |
|
283 | 526 | continue |
|
284 | 527 | |
|
285 | 528 | break |
|
286 | 529 | |
|
287 | 530 | self.__flagIsNewFile = 1 |
|
288 | 531 | self.__idFile = idFile |
|
289 | 532 | self.filename = filename |
|
290 | 533 | self.fileSize = fileSize |
|
291 | 534 | self.__fp = fp |
|
292 | 535 | |
|
293 | 536 | print 'Setting the file: %s'%self.filename |
|
294 | 537 | |
|
295 | 538 | return 1 |
|
296 | 539 | |
|
297 | def __setNextFile(self): | |
|
298 | ||
|
540 | def __setNextFile( self ): | |
|
541 | """ | |
|
542 | Determina el siguiente file a leer y si hay uno disponible lee el First Header | |
|
543 | ||
|
544 | Affected: | |
|
545 | self.m_BasicHeader | |
|
546 | self.m_SystemHeader | |
|
547 | self.m_RadarControllerHeader | |
|
548 | self.m_ProcessingHeader | |
|
549 | self.firstHeaderSize | |
|
550 | ||
|
551 | Return: | |
|
552 | 0 : Si no hay files disponibles | |
|
553 | 1 : Si hay mas files disponibles | |
|
554 | """ | |
|
555 | if self.__fp != None: | |
|
556 | self.__fp.close() | |
|
557 | ||
|
299 | 558 | if self.online: |
|
300 | 559 | newFile = self.__setNextFileOnline() |
|
301 | 560 | else: |
|
302 | 561 | newFile = self.__setNextFileOffline() |
|
303 | 562 | |
|
304 | 563 | if not(newFile): |
|
305 | 564 | return 0 |
|
306 | 565 | |
|
307 | 566 | self.__readFirstHeader() |
|
308 | 567 | |
|
309 | 568 | return 1 |
|
310 | ||
|
311 | def __setNewBlock(self): | |
|
312 | 569 | |
|
570 | ||
|
571 | def __setNewBlock( self ): | |
|
572 | """ | |
|
573 | Lee el Basic Header y posiciona le file pointer en la posicion inicial del bloque a leer | |
|
574 | ||
|
575 | Affected: | |
|
576 | self.m_BasicHeader | |
|
577 | self.flagResetProcessing | |
|
578 | self.ns | |
|
579 | ||
|
580 | Return: | |
|
581 | 0 : Si el file no tiene un Basic Header que pueda ser leido | |
|
582 | 1 : Si se pudo leer el Basic Header | |
|
583 | """ | |
|
313 | 584 | if self.__fp == None: |
|
314 | 585 | return 0 |
|
315 | 586 | |
|
316 | 587 | if self.__flagIsNewFile: |
|
317 | 588 | return 1 |
|
318 | 589 | |
|
319 | 590 | currentSize = self.fileSize - self.__fp.tell() |
|
320 | 591 | neededSize = self.m_ProcessingHeader.blockSize + self.basicHeaderSize |
|
321 | 592 | |
|
322 | 593 | #If there is enough data setting new data block |
|
323 | if (currentSize >= neededSize): | |
|
594 | if ( currentSize >= neededSize ): | |
|
324 | 595 | self.__rdBasicHeader() |
|
325 | 596 | return 1 |
|
597 | elif self.online: | |
|
598 | nTries = 0 | |
|
599 | while( nTries < self.__nTries ): | |
|
600 | nTries += 1 | |
|
601 | print "Waiting for the next block, try %03d ..." % nTries | |
|
602 | time.sleep( self.__delay ) | |
|
603 | ||
|
604 | fileSize = os.path.getsize(self.filename) | |
|
605 | currentSize = fileSize - self.__fp.tell() | |
|
606 | neededSize = self.m_ProcessingHeader.blockSize + self.basicHeaderSize | |
|
607 | ||
|
608 | if ( currentSize >= neededSize ): | |
|
609 | self.__rdBasicHeader() | |
|
610 | return 1 | |
|
326 | 611 | |
|
327 | 612 | #Setting new file |
|
328 | if not(self.__setNextFile()): | |
|
613 | if not( self.__setNextFile() ): | |
|
329 | 614 | return 0 |
|
330 | 615 | |
|
331 | 616 | deltaTime = self.m_BasicHeader.utc - self.__lastUTTime # check this |
|
332 | 617 | |
|
333 | 618 | self.flagResetProcessing = 0 |
|
334 | 619 | |
|
335 | 620 | if deltaTime > self.__maxTimeStep: |
|
336 | 621 | self.flagResetProcessing = 1 |
|
337 | 622 | self.nReadBlocks = 0 |
|
338 | 623 | |
|
339 | 624 | return 1 |
|
340 | 625 | |
|
341 | 626 | def __readBlock(self): |
|
342 | 627 | """ |
|
343 | 628 | __readBlock lee el bloque de datos desde la posicion actual del puntero del archivo |
|
344 | 629 | (self.__fp) y actualiza todos los parametros relacionados al bloque de datos |
|
345 | 630 | (metadata + data). La data leida es almacenada en el buffer y el contador del buffer |
|
346 | 631 | es seteado a 0 |
|
347 | 632 | |
|
348 | 633 | |
|
349 | 634 | Inputs: |
|
350 | 635 | None |
|
351 | 636 | |
|
352 | 637 | Return: |
|
353 | 638 | None |
|
354 | 639 | |
|
355 | 640 | Variables afectadas: |
|
356 | 641 | |
|
357 | 642 | self.__datablockIndex |
|
358 | 643 | |
|
359 | 644 | self.datablock |
|
360 | 645 | |
|
361 | 646 | self.__flagIsNewFile |
|
362 | 647 | |
|
363 | 648 | self.idProfile |
|
364 | 649 | |
|
365 | 650 | self.flagIsNewBlock |
|
366 | 651 | |
|
367 | 652 | self.nReadBlocks |
|
368 | 653 | |
|
369 | 654 | """ |
|
370 | 655 | |
|
371 | pts2read = self.m_ProcessingHeader.profilesPerBlock*self.m_ProcessingHeader.numHeights*self.m_SystemHeader.numChannels | |
|
656 | #pts2read = self.m_ProcessingHeader.profilesPerBlock*self.m_ProcessingHeader.numHeights*self.m_SystemHeader.numChannels | |
|
372 | 657 | |
|
373 | junk = numpy.fromfile(self.__fp, self.__dataType, pts2read) | |
|
658 | fpointer = self.__fp.tell() | |
|
374 | 659 | |
|
375 | junk = junk.reshape((self.m_ProcessingHeader.profilesPerBlock, self.m_ProcessingHeader.numHeights, self.m_SystemHeader.numChannels)) | |
|
660 | junk = numpy.fromfile( self.__fp, self.__dataType, self.__pts2read ) | |
|
661 | ||
|
662 | if self.online: | |
|
663 | if junk.size != self.__blocksize: | |
|
664 | nTries = 0 | |
|
665 | while( nTries < self.__nTries ): | |
|
666 | nTries += 1 | |
|
667 | print "Waiting for the next block, try %03d ..." % nTries | |
|
668 | time.sleep( self.__delay ) | |
|
669 | self.__fp.seek( fpointer ) | |
|
670 | fpointer = self.__fp.tell() | |
|
671 | junk = numpy.fromfile( self.__fp, self.__dataType, self.__pts2read ) | |
|
672 | if junk.size == self.__blocksize: | |
|
673 | nTries = 0 | |
|
674 | break | |
|
675 | if nTries > 0: | |
|
676 | return | |
|
677 | ||
|
678 | junk = junk.reshape( (self.m_ProcessingHeader.profilesPerBlock, self.m_ProcessingHeader.numHeights, self.m_SystemHeader.numChannels) ) | |
|
376 | 679 | |
|
377 | 680 | data = junk['real'] + junk['imag']*1j |
|
378 | 681 | |
|
379 | 682 | self.__datablockIndex = 0 |
|
380 | 683 | |
|
381 | 684 | self.datablock = data |
|
382 | 685 | |
|
383 | 686 | self.__flagIsNewFile = 0 |
|
384 | 687 | |
|
385 | 688 | self.idProfile = 0 |
|
386 | 689 | |
|
387 | 690 | self.flagIsNewBlock = 1 |
|
388 | 691 | |
|
389 | 692 | self.nReadBlocks += 1 |
|
390 | 693 | |
|
391 | 694 | def __hasNotDataInBuffer(self): |
|
392 | 695 | if self.__datablockIndex >= self.m_ProcessingHeader.profilesPerBlock: |
|
393 | 696 | return 1 |
|
394 | 697 | |
|
395 | 698 | return 0 |
|
396 | 699 | |
|
397 | def __searchFiles(self, path, startDateTime, endDateTime, set=None, expLabel = "", ext = ".r"): | |
|
700 | ||
|
701 | def __searchFilesOnLine( self, path, startDateTime=None, ext = ".r" ): | |
|
398 | 702 | """ |
|
399 | __searchFiles realiza una busqueda de los archivos que coincidan con los parametros | |
|
703 | Busca el ultimo archivo de la ultima carpeta (determinada o no por startDateTime) y | |
|
704 | devuelve el archivo encontrado ademas de otros datos. | |
|
705 | ||
|
706 | Input: | |
|
707 | path : carpeta donde estan contenidos los files que contiene data | |
|
708 | startDateTime : punto especifico en el tiempo del cual se requiere la data | |
|
709 | ext : extension de los files | |
|
710 | ||
|
711 | Return: | |
|
712 | year : el anho | |
|
713 | doy : el numero de dia del anho | |
|
714 | set : el set del archivo | |
|
715 | filename : el ultimo file de una determinada carpeta | |
|
716 | directory : eL directorio donde esta el file encontrado | |
|
717 | """ | |
|
718 | ||
|
719 | print "Searching files ..." | |
|
720 | ||
|
721 | dirList = [] | |
|
722 | directory = None | |
|
723 | ||
|
724 | if startDateTime == None: | |
|
725 | for thisPath in os.listdir(path): | |
|
726 | if os.path.isdir( os.path.join(path,thisPath) ): | |
|
727 | dirList.append( thisPath ) | |
|
728 | ||
|
729 | dirList = sorted( dirList, key=str.lower ) #para que quede ordenado al margen de si el nombre esta en mayusculas o minusculas, utilizo la funcion sorted | |
|
730 | if len(dirList) > 0 : | |
|
731 | directory = dirList[-1] | |
|
732 | else: | |
|
733 | year = startDateTime.timetuple().tm_year | |
|
734 | doy = startDateTime.timetuple().tm_yday | |
|
735 | ||
|
736 | doyPath = "D%04d%03d" % (year,doy) #caso del nombre en mayusculas | |
|
737 | if os.path.isdir( os.path.join(path,doyPath) ): | |
|
738 | directory = doyPath | |
|
739 | ||
|
740 | doyPath = doyPath.lower() #caso del nombre en minusculas | |
|
741 | if os.path.isdir( os.path.join(path,doyPath) ): | |
|
742 | directory = doyPath | |
|
743 | ||
|
744 | if directory == None: | |
|
745 | return 0, 0, 0, None, None | |
|
746 | ||
|
747 | filename = getlastFileFromPath( os.listdir( os.path.join(path,directory) ), ext ) | |
|
748 | ||
|
749 | if filename == None: | |
|
750 | return 0, 0, 0, None, None | |
|
751 | ||
|
752 | year = int( directory[-7:-3] ) | |
|
753 | doy = int( directory[-3:] ) | |
|
754 | ln = len( ext ) | |
|
755 | set = int( filename[-ln-3:-ln] ) | |
|
756 | ||
|
757 | return year, doy, set, filename, directory | |
|
758 | ||
|
759 | ||
|
760 | def __searchFilesOffLine(self, path, startDateTime, endDateTime, set=None, expLabel = "", ext = ".r"): | |
|
761 | """ | |
|
762 | Realiza una busqueda de los archivos que coincidan con los parametros | |
|
400 | 763 | especificados y se encuentren ubicados en el path indicado. Para realizar una busqueda |
|
401 | 764 | correcta la estructura de directorios debe ser la siguiente: |
|
402 | 765 | |
|
403 | 766 | ...path/D[yyyy][ddd]/expLabel/D[yyyy][ddd][sss].ext |
|
404 | 767 | |
|
405 | 768 | [yyyy]: anio |
|
406 | 769 | [ddd] : dia del anio |
|
407 | 770 | [sss] : set del archivo |
|
408 | 771 | |
|
409 | 772 | Inputs: |
|
410 | 773 | path : Directorio de datos donde se realizara la busqueda. Todos los |
|
411 | 774 | ficheros que concidan con el criterio de busqueda seran |
|
412 | 775 | almacenados en una lista y luego retornados. |
|
413 | 776 | startDateTime : Fecha inicial. Rechaza todos los archivos donde |
|
414 | 777 | file end time < startDateTime (obejto datetime.datetime) |
|
415 | 778 | |
|
416 | 779 | endDateTime : Fecha final. Rechaza todos los archivos donde |
|
417 | 780 | file start time > endDateTime (obejto datetime.datetime) |
|
418 | 781 | |
|
419 | 782 | set : Set del primer archivo a leer. Por defecto None |
|
420 | 783 | |
|
421 | 784 | expLabel : Nombre del subdirectorio de datos. Por defecto "" |
|
422 | 785 | |
|
423 | 786 | ext : Extension de los archivos a leer. Por defecto .r |
|
424 | 787 | |
|
425 | 788 | Return: |
|
426 | 789 | |
|
427 | 790 | (pathList, filenameList) |
|
428 | 791 | |
|
429 | 792 | pathList : Lista de directorios donde se encontraron archivos dentro |
|
430 | 793 | de los parametros especificados |
|
431 | 794 | filenameList : Lista de archivos (ruta completa) que coincidieron con los |
|
432 | 795 | parametros especificados. |
|
433 | 796 | |
|
434 | 797 | Variables afectadas: |
|
435 | 798 | |
|
436 | 799 | self.filenameList: Lista de archivos (ruta completa) que la clase utiliza |
|
437 | 800 | como fuente para leer los bloque de datos, si se termina |
|
438 | 801 | de leer todos los bloques de datos de un determinado |
|
439 | 802 | archivo se pasa al siguiente archivo de la lista. |
|
440 | 803 | |
|
441 | 804 | Excepciones: |
|
442 | 805 | |
|
443 | 806 | """ |
|
444 | 807 | |
|
445 | 808 | print "Searching files ..." |
|
446 | 809 | |
|
447 | 810 | dirList = [] |
|
448 | 811 | for thisPath in os.listdir(path): |
|
449 | 812 | if os.path.isdir(os.path.join(path,thisPath)): |
|
450 | 813 | dirList.append(thisPath) |
|
451 | 814 | |
|
452 | 815 | pathList = [] |
|
453 | 816 | |
|
454 | 817 | thisDateTime = startDateTime |
|
455 | 818 | |
|
456 | 819 | while(thisDateTime <= endDateTime): |
|
457 | 820 | year = thisDateTime.timetuple().tm_year |
|
458 | 821 | doy = thisDateTime.timetuple().tm_yday |
|
459 | 822 | |
|
460 | 823 | match = fnmatch.filter(dirList, '?' + '%4.4d%3.3d' % (year,doy)) |
|
461 | 824 | if len(match) == 0: |
|
462 | 825 | thisDateTime += datetime.timedelta(1) |
|
463 | 826 | continue |
|
464 | 827 | |
|
465 | 828 | pathList.append(os.path.join(path,match[0],expLabel)) |
|
466 | 829 | thisDateTime += datetime.timedelta(1) |
|
467 | 830 | |
|
468 | 831 | startUtSeconds = time.mktime(startDateTime.timetuple()) |
|
469 | 832 | endUtSeconds = time.mktime(endDateTime.timetuple()) |
|
470 | 833 | |
|
471 | 834 | filenameList = [] |
|
472 | 835 | for thisPath in pathList: |
|
473 | 836 | fileList = glob.glob1(thisPath, "*%s" %ext) |
|
474 | 837 | fileList.sort() |
|
475 | 838 | for file in fileList: |
|
476 | 839 | filename = os.path.join(thisPath,file) |
|
477 | 840 | if isThisFileinRange(filename, startUtSeconds, endUtSeconds): |
|
478 | 841 | filenameList.append(filename) |
|
479 | 842 | |
|
480 | 843 | self.filenameList = filenameList |
|
481 | 844 | |
|
482 | 845 | return pathList, filenameList |
|
846 | ||
|
847 | ||
|
848 | def __initFilesOnline( self, path, dirfilename, filename ): | |
|
849 | """ | |
|
850 | Verifica que el primer file tenga una data valida, para ello leo el 1er bloque | |
|
851 | del file, si no es un file valido espera una cierta cantidad de tiempo a que | |
|
852 | lo sea, si transcurrido el tiempo no logra validar el file entonces el metodo | |
|
853 | devuelve 0 caso contrario devuelve 1 | |
|
854 | ||
|
855 | Affected: | |
|
856 | m_BasicHeader | |
|
857 | ||
|
858 | Return: | |
|
859 | 0 : file no valido para ser leido | |
|
860 | 1 : file valido para ser leido | |
|
861 | """ | |
|
862 | m_BasicHeader = BasicHeader() | |
|
863 | ||
|
864 | file = os.path.join( path, dirfilename, filename ) | |
|
865 | ||
|
866 | nTries = 0 | |
|
867 | while(True): | |
|
868 | ||
|
869 | nTries += 1 | |
|
870 | if nTries > self.__nTries: | |
|
871 | break | |
|
872 | ||
|
873 | try: | |
|
874 | fp = open( file,'rb' ) #lectura binaria | |
|
875 | except: | |
|
876 | raise IOError, "The file %s can't be opened" %(file) | |
|
877 | ||
|
878 | try: | |
|
879 | m_BasicHeader.read(fp) | |
|
880 | except: | |
|
881 | print "The file %s is empty" % filename | |
|
882 | ||
|
883 | fp.close() | |
|
884 | ||
|
885 | if m_BasicHeader.size > 24: | |
|
886 | break | |
|
887 | ||
|
888 | print 'waiting for new block: try %02d' % ( nTries ) | |
|
889 | time.sleep( self.__delay) | |
|
890 | ||
|
891 | if m_BasicHeader.size <= 24: | |
|
892 | return 0 | |
|
893 | ||
|
894 | return 1 | |
|
895 | ||
|
483 | 896 | |
|
484 | 897 | def setup(self, path, startDateTime, endDateTime=None, set=None, expLabel = "", ext = ".r", online = 0): |
|
485 | 898 | """ |
|
486 | 899 | setup configura los parametros de lectura de la clase VoltageReader. |
|
487 | 900 | |
|
488 | 901 | Si el modo de lectura es offline, primero se realiza una busqueda de todos los archivos |
|
489 | 902 | que coincidan con los parametros especificados; esta lista de archivos son almacenados en |
|
490 | 903 | self.filenameList. |
|
491 | 904 | |
|
492 | 905 | Input: |
|
493 | 906 | path : Directorios donde se ubican los datos a leer. Dentro de este |
|
494 | 907 | directorio deberia de estar subdirectorios de la forma: |
|
495 | 908 | |
|
496 | 909 | path/D[yyyy][ddd]/expLabel/P[yyyy][ddd][sss][ext] |
|
497 | 910 | |
|
498 | 911 | startDateTime : Fecha inicial. Rechaza todos los archivos donde |
|
499 | 912 | file end time < startDatetime (obejto datetime.datetime) |
|
500 | 913 | |
|
501 | 914 | endDateTime : Fecha final. Si no es None, rechaza todos los archivos donde |
|
502 | 915 | file end time < startDatetime (obejto datetime.datetime) |
|
503 | 916 | |
|
504 | 917 | set : Set del primer archivo a leer. Por defecto None |
|
505 | 918 | |
|
506 | 919 | expLabel : Nombre del subdirectorio de datos. Por defecto "" |
|
507 | 920 | |
|
508 | 921 | ext : Extension de los archivos a leer. Por defecto .r |
|
509 | 922 | |
|
510 | online : | |
|
923 | online : Si es == a 0 entonces busca files que cumplan con las condiciones dadas | |
|
511 | 924 | |
|
512 | 925 | Return: |
|
926 | 0 : Si no encuentra files que cumplan con las condiciones dadas | |
|
927 | 1 : Si encuentra files que cumplan con las condiciones dadas | |
|
513 | 928 | |
|
514 | 929 | Affected: |
|
515 | ||
|
516 | Excepciones: | |
|
517 | ||
|
518 | Example: | |
|
519 | ||
|
930 | self.startUTCSeconds | |
|
931 | self.endUTCSeconds | |
|
932 | self.startYear | |
|
933 | self.endYear | |
|
934 | self.startDoy | |
|
935 | self.endDoy | |
|
936 | self.__pathList | |
|
937 | self.filenameList | |
|
938 | self.online | |
|
520 | 939 | """ |
|
521 | ||
|
522 | if online == 0: | |
|
523 | pathList, filenameList = self.__searchFiles(path, startDateTime, endDateTime, set, expLabel, ext) | |
|
524 | ||
|
525 | self.__idFile = -1 | |
|
526 | ||
|
527 | if not(self.__setNextFile()): | |
|
528 | print "No files in range: %s - %s" %(startDateTime.ctime(), endDateTime.ctime()) | |
|
940 | if online: | |
|
941 | nTries = 0 | |
|
942 | while( nTries < self.__nTries ): | |
|
943 | nTries += 1 | |
|
944 | subfolder = "D%04d%03d" % ( startDateTime.timetuple().tm_year, startDateTime.timetuple().tm_yday ) | |
|
945 | year, doy, set, filename, dirfilename = self.__searchFilesOnLine( path, startDateTime, ext ) | |
|
946 | if filename == None: | |
|
947 | file = os.path.join( path, subfolder ) | |
|
948 | print "Searching first file in \"%s\", try %03d ..." % ( file, nTries ) | |
|
949 | time.sleep( self.__delay ) | |
|
950 | else: | |
|
951 | break | |
|
952 | ||
|
953 | if filename == None: | |
|
954 | print "No files On Line" | |
|
955 | return 0 | |
|
956 | ||
|
957 | if self.__initFilesOnline( path, dirfilename, filename ) == 0: | |
|
958 | print "The file %s hasn't enough data" | |
|
959 | return 0 | |
|
960 | ||
|
961 | self.__year = year | |
|
962 | self.__doy = doy | |
|
963 | self.__set = set - 1 | |
|
964 | self.__path = path | |
|
965 | ||
|
966 | else: | |
|
967 | pathList, filenameList = self.__searchFilesOffLine( path, startDateTime, endDateTime, set, expLabel, ext ) | |
|
968 | self.__idFile = -1 | |
|
969 | self.__pathList = pathList | |
|
970 | self.filenameList = filenameList | |
|
971 | ||
|
972 | self.online = online | |
|
973 | self.__ext = ext | |
|
974 | ||
|
975 | if not( self.__setNextFile() ): | |
|
976 | if (startDateTime != None) and (endDateTime != None): | |
|
977 | print "No files in range: %s - %s" %(startDateTime.ctime(), endDateTime.ctime()) | |
|
978 | elif startDateTime != None: | |
|
979 | print "No files in : %s" % startDateTime.ctime() | |
|
980 | else: | |
|
981 | print "No files" | |
|
529 | 982 | return 0 |
|
530 | 983 | |
|
531 | self.startUTCSeconds = time.mktime(startDateTime.timetuple()) | |
|
532 |
self. |
|
|
984 | if startDateTime != None: | |
|
985 | self.startUTCSeconds = time.mktime(startDateTime.timetuple()) | |
|
986 | self.startYear = startDateTime.timetuple().tm_year | |
|
987 | self.startDoy = startDateTime.timetuple().tm_yday | |
|
533 | 988 | |
|
534 | self.startYear = startDateTime.timetuple().tm_year | |
|
535 |
self.end |
|
|
536 |
self. |
|
|
537 | self.endDoy = endDateTime.timetuple().tm_yday | |
|
989 | if endDateTime != None: | |
|
990 | self.endUTCSeconds = time.mktime(endDateTime.timetuple()) | |
|
991 | self.endYear = endDateTime.timetuple().tm_year | |
|
992 | self.endDoy = endDateTime.timetuple().tm_yday | |
|
993 | #call fillHeaderValues() - to Data Object | |
|
538 | 994 | |
|
539 | 995 | self.m_Voltage.m_BasicHeader = self.m_BasicHeader.copy() |
|
540 | 996 | self.m_Voltage.m_ProcessingHeader = self.m_ProcessingHeader.copy() |
|
541 | 997 | self.m_Voltage.m_RadarControllerHeader = self.m_RadarControllerHeader.copy() |
|
542 | 998 | self.m_Voltage.m_SystemHeader = self.m_SystemHeader.copy() |
|
543 | 999 | self.m_Voltage.dataType = self.__dataType |
|
544 | 1000 | |
|
545 | self.__pathList = pathList | |
|
546 | self.filenameList = filenameList | |
|
547 | self.online = online | |
|
548 | ||
|
549 | 1001 | return 1 |
|
1002 | ||
|
550 | 1003 | |
|
551 | def readNextBlock(self): | |
|
552 | """ | |
|
553 |
|
|
|
1004 | def readNextBlock( self ): | |
|
1005 | """ | |
|
1006 | Establece un nuevo bloque de datos a leer y los lee, si es que no existiese | |
|
554 | 1007 | mas bloques disponibles en el archivo actual salta al siguiente. |
|
555 | ||
|
1008 | ||
|
1009 | Affected: | |
|
1010 | self.__lastUTTime | |
|
1011 | ||
|
1012 | Return: None | |
|
556 | 1013 | """ |
|
557 | ||
|
558 | 1014 | if not(self.__setNewBlock()): |
|
559 | 1015 | return 0 |
|
560 | 1016 | |
|
561 | 1017 | self.__readBlock() |
|
562 | 1018 | |
|
563 | 1019 | self.__lastUTTime = self.m_BasicHeader.utc |
|
564 | 1020 | |
|
565 | 1021 | return 1 |
|
1022 | ||
|
566 | 1023 | |
|
567 | def getData(self): | |
|
1024 | def getData( self ): | |
|
568 | 1025 | """ |
|
569 | 1026 | getData obtiene una unidad de datos del buffer de lectura y la copia a la clase "Voltage" |
|
570 | 1027 | con todos los parametros asociados a este (metadata). cuando no hay datos en el buffer de |
|
571 | 1028 | lectura es necesario hacer una nueva lectura de los bloques de datos usando "readNextBlock" |
|
572 | 1029 | |
|
573 | 1030 | Ademas incrementa el contador del buffer en 1. |
|
574 | 1031 | |
|
575 | Inputs: | |
|
576 | None | |
|
577 | ||
|
578 | 1032 | Return: |
|
579 | 1033 | data : retorna un perfil de voltages (alturas * canales) copiados desde el |
|
580 | 1034 | buffer. Si no hay mas archivos a leer retorna None. |
|
581 | 1035 | |
|
582 | 1036 | Variables afectadas: |
|
583 | 1037 | self.m_Voltage |
|
584 | 1038 | self.__datablockIndex |
|
585 | 1039 | self.idProfile |
|
586 | 1040 | |
|
587 | Excepciones: | |
|
588 | ||
|
1041 | Affected: | |
|
1042 | self.m_Voltage | |
|
1043 | self.__datablockIndex | |
|
1044 | self.flagResetProcessing | |
|
1045 | self.flagIsNewBlock | |
|
1046 | self.idProfile | |
|
589 | 1047 | """ |
|
590 | 1048 | self.flagResetProcessing = 0 |
|
591 | 1049 | self.flagIsNewBlock = 0 |
|
592 | 1050 | |
|
593 | 1051 | if self.__hasNotDataInBuffer(): |
|
1052 | ||
|
594 | 1053 | self.readNextBlock() |
|
595 | 1054 | |
|
596 | 1055 | self.m_Voltage.m_BasicHeader = self.m_BasicHeader.copy() |
|
597 | 1056 | self.m_Voltage.m_ProcessingHeader = self.m_ProcessingHeader.copy() |
|
598 | 1057 | self.m_Voltage.m_RadarControllerHeader = self.m_RadarControllerHeader.copy() |
|
599 | 1058 | self.m_Voltage.m_SystemHeader = self.m_SystemHeader.copy() |
|
600 | ||
|
601 | 1059 | self.m_Voltage.heights = self.__heights |
|
602 | 1060 | self.m_Voltage.dataType = self.__dataType |
|
603 | 1061 | |
|
604 | 1062 | if self.noMoreFiles == 1: |
|
605 | 1063 | print 'Process finished' |
|
606 | 1064 | return None |
|
607 | 1065 | |
|
608 | 1066 | #data es un numpy array de 3 dmensiones (perfiles, alturas y canales) |
|
609 | 1067 | |
|
610 | time = self.m_BasicHeader.utc + self.__datablockIndex*self.__ippSeconds | |
|
1068 | time = self.m_BasicHeader.utc + self.__datablockIndex * self.__ippSeconds | |
|
611 | 1069 | self.m_Voltage.m_BasicHeader.utc = time |
|
1070 | ||
|
612 | 1071 | self.m_Voltage.flagNoData = False |
|
613 | 1072 | self.m_Voltage.flagResetProcessing = self.flagResetProcessing |
|
614 | 1073 | |
|
615 | 1074 | self.m_Voltage.data = self.datablock[self.__datablockIndex,:,:] |
|
616 | 1075 | self.m_Voltage.idProfile = self.idProfile |
|
617 | 1076 | |
|
618 | ||
|
619 | 1077 | self.__datablockIndex += 1 |
|
620 | 1078 | self.idProfile += 1 |
|
621 | 1079 | |
|
622 | 1080 | #call setData - to Data Object |
|
623 | 1081 | |
|
624 | 1082 | return self.m_Voltage.data |
|
625 | 1083 | |
|
626 | class VoltageWriter(DataWriter): | |
|
1084 | ||
|
1085 | class VoltageWriter( DataWriter ): | |
|
1086 | """ | |
|
1087 | Esta clase permite escribir datos de voltajes a archivos procesados (.r). La escritura | |
|
1088 | de los datos siempre se realiza por bloques. | |
|
1089 | """ | |
|
627 | 1090 | __configHeaderFile = 'wrSetHeadet.txt' |
|
628 | 1091 | |
|
629 | def __init__(self, m_Voltage = None): | |
|
630 | ||
|
1092 | def __init__( self, m_Voltage = None ): | |
|
1093 | """ | |
|
1094 | Inicializador de la clase VoltageWriter para la escritura de datos de espectros. | |
|
1095 | ||
|
1096 | Affected: | |
|
1097 | self.m_Voltage | |
|
1098 | self.m_BasicHeader | |
|
1099 | self.m_SystemHeader | |
|
1100 | self.m_RadarControllerHeader | |
|
1101 | self.m_ProcessingHeader | |
|
1102 | ||
|
1103 | Return: None | |
|
1104 | """ | |
|
631 | 1105 | if m_Voltage == None: |
|
632 | 1106 | m_Voltage = Voltage() |
|
633 | 1107 | |
|
634 | 1108 | self.m_Voltage = m_Voltage |
|
635 | 1109 | |
|
636 | 1110 | self.__path = None |
|
637 | 1111 | |
|
638 | 1112 | self.__fp = None |
|
639 | 1113 | |
|
640 | 1114 | self.__format = None |
|
641 | 1115 | |
|
642 | 1116 | self.__blocksCounter = 0 |
|
643 | 1117 | |
|
644 | 1118 | self.__setFile = None |
|
645 | 1119 | |
|
646 | 1120 | self.__flagIsNewFile = 1 |
|
647 | 1121 | |
|
648 | 1122 | self.datablock = None |
|
649 | 1123 | |
|
650 | 1124 | self.__datablockIndex = 0 |
|
651 | 1125 | |
|
652 | 1126 | self.__dataType = None |
|
653 | 1127 | |
|
654 | 1128 | self.__ext = None |
|
655 | 1129 | |
|
656 | 1130 | self.__shapeBuffer = None |
|
657 | 1131 | |
|
658 | 1132 | self.nWriteBlocks = 0 |
|
659 | 1133 | |
|
660 | 1134 | self.flagIsNewBlock = 0 |
|
661 | 1135 | |
|
662 | 1136 | self.noMoreFiles = 0 |
|
663 | 1137 | |
|
664 | 1138 | self.filename = None |
|
665 | 1139 | |
|
666 | 1140 | self.m_BasicHeader= BasicHeader() |
|
667 | 1141 | |
|
668 | 1142 | self.m_SystemHeader = SystemHeader() |
|
669 | 1143 | |
|
670 | 1144 | self.m_RadarControllerHeader = RadarControllerHeader() |
|
671 | 1145 | |
|
672 | 1146 | self.m_ProcessingHeader = ProcessingHeader() |
|
1147 | ||
|
673 | 1148 | |
|
674 | ||
|
675 | def __writeFirstHeader(self): | |
|
1149 | def __writeFirstHeader( self ): | |
|
1150 | """ | |
|
1151 | Escribe el primer header del file es decir el Basic header y el Long header (SystemHeader, RadarControllerHeader, ProcessingHeader) | |
|
1152 | ||
|
1153 | Affected: | |
|
1154 | __dataType | |
|
1155 | ||
|
1156 | Return: | |
|
1157 | None | |
|
1158 | """ | |
|
676 | 1159 | self.__writeBasicHeader() |
|
677 | 1160 | self.__wrSystemHeader() |
|
678 | 1161 | self.__wrRadarControllerHeader() |
|
679 | 1162 | self.__wrProcessingHeader() |
|
680 | 1163 | self.__dataType = self.m_Voltage.dataType |
|
1164 | ||
|
681 | 1165 | |
|
682 | def __writeBasicHeader(self, fp=None): | |
|
1166 | def __writeBasicHeader( self, fp=None ): | |
|
1167 | """ | |
|
1168 | Escribe solo el Basic header en el file creado | |
|
1169 | ||
|
1170 | Return: | |
|
1171 | None | |
|
1172 | """ | |
|
683 | 1173 | if fp == None: |
|
684 | 1174 | fp = self.__fp |
|
685 | 1175 | |
|
686 | 1176 | self.m_BasicHeader.write(fp) |
|
1177 | ||
|
687 | 1178 | |
|
688 | def __wrSystemHeader(self,fp=None): | |
|
1179 | def __wrSystemHeader( self, fp=None ): | |
|
1180 | """ | |
|
1181 | Escribe solo el System header en el file creado | |
|
1182 | ||
|
1183 | Return: | |
|
1184 | None | |
|
1185 | """ | |
|
689 | 1186 | if fp == None: |
|
690 | 1187 | fp = self.__fp |
|
691 | 1188 | |
|
692 | 1189 | self.m_SystemHeader.write(fp) |
|
1190 | ||
|
693 | 1191 | |
|
694 | def __wrRadarControllerHeader(self,fp=None): | |
|
1192 | def __wrRadarControllerHeader( self, fp=None ): | |
|
1193 | """ | |
|
1194 | Escribe solo el RadarController header en el file creado | |
|
1195 | ||
|
1196 | Return: | |
|
1197 | None | |
|
1198 | """ | |
|
695 | 1199 | if fp == None: |
|
696 | 1200 | fp = self.__fp |
|
697 | 1201 | |
|
698 | 1202 | self.m_RadarControllerHeader.write(fp) |
|
1203 | ||
|
699 | 1204 | |
|
700 | def __wrProcessingHeader(self,fp=None): | |
|
1205 | def __wrProcessingHeader( self, fp=None ): | |
|
1206 | """ | |
|
1207 | Escribe solo el Processing header en el file creado | |
|
1208 | ||
|
1209 | Return: | |
|
1210 | None | |
|
1211 | """ | |
|
701 | 1212 | if fp == None: |
|
702 | 1213 | fp = self.__fp |
|
703 | 1214 | |
|
704 | 1215 | self.m_ProcessingHeader.write(fp) |
|
705 | 1216 | |
|
706 | def __setNextFile(self): | |
|
707 | ||
|
708 | setFile = self.__setFile | |
|
1217 | def __setNextFile( self ): | |
|
1218 | """ | |
|
1219 | Determina el siguiente file que sera escrito | |
|
1220 | ||
|
1221 | Affected: | |
|
1222 | self.filename | |
|
1223 | self.__subfolder | |
|
1224 | self.__fp | |
|
1225 | self.__setFile | |
|
1226 | self.__flagIsNewFile | |
|
1227 | ||
|
1228 | Return: | |
|
1229 | 0 : Si el archivo no puede ser escrito | |
|
1230 | 1 : Si el archivo esta listo para ser escrito | |
|
1231 | """ | |
|
1232 | #setFile = self.__setFile | |
|
709 | 1233 | ext = self.__ext |
|
710 | 1234 | path = self.__path |
|
711 | 1235 | |
|
712 | setFile += 1 | |
|
1236 | #setFile += 1 | |
|
713 | 1237 | |
|
714 | 1238 | if self.__fp != None: |
|
715 | 1239 | self.__fp.close() |
|
716 | 1240 |
|
|
1241 | """ | |
|
717 | 1242 | timeTuple = time.localtime(self.m_Voltage.m_BasicHeader.utc) # utc from m_Voltage |
|
718 | 1243 | file = 'D%4.4d%3.3d%3.3d%s' % (timeTuple.tm_year,timeTuple.tm_yday,setFile,ext) |
|
719 | 1244 | subfolder = 'D%4.4d%3.3d' % (timeTuple.tm_year,timeTuple.tm_yday) |
|
720 | 1245 | tmp = os.path.join(path,subfolder) |
|
721 | 1246 | if not(os.path.exists(tmp)): |
|
722 | 1247 | os.mkdir(tmp) |
|
723 | ||
|
724 | filename = os.path.join(path,subfolder,file) | |
|
725 | fp = open(filename,'wb') | |
|
1248 | """ | |
|
1249 | ################################## | |
|
1250 | if self.m_BasicHeader.size <= 24: return 0 #no existe la suficiente data para ser escrita | |
|
1251 | ||
|
1252 | timeTuple = time.localtime( self.m_Voltage.m_BasicHeader.utc ) # utc from m_Voltage | |
|
1253 | subfolder = 'D%4.4d%3.3d' % (timeTuple.tm_year,timeTuple.tm_yday) | |
|
1254 | ||
|
1255 | tmp = os.path.join( path, subfolder ) | |
|
1256 | if not( os.path.exists(tmp) ): | |
|
1257 | os.mkdir(tmp) | |
|
1258 | self.__setFile = -1 #inicializo mi contador de seteo | |
|
1259 | else: | |
|
1260 | filesList = os.listdir( tmp ) | |
|
1261 | if len( filesList ) > 0: | |
|
1262 | filesList = sorted( filesList, key=str.lower ) | |
|
1263 | filen = filesList[-1] | |
|
1264 | # el filename debera tener el siguiente formato | |
|
1265 | # 0 1234 567 89A BCDE (hex) | |
|
1266 | # D YYYY DDD SSS .ext | |
|
1267 | if isNumber( filen[8:11] ): | |
|
1268 | self.__setFile = int( filen[8:11] ) #inicializo mi contador de seteo al seteo del ultimo file | |
|
1269 | else: | |
|
1270 | self.__setFile = -1 | |
|
1271 | else: | |
|
1272 | self.__setFile = -1 #inicializo mi contador de seteo | |
|
1273 | ||
|
1274 | setFile = self.__setFile | |
|
1275 | setFile += 1 | |
|
1276 | file = 'D%4.4d%3.3d%3.3d%s' % ( timeTuple.tm_year, timeTuple.tm_yday, setFile, ext ) | |
|
1277 | ################################## | |
|
1278 | ||
|
1279 | filename = os.path.join( path, subfolder, file ) | |
|
1280 | ||
|
1281 | fp = open( filename,'wb' ) | |
|
726 | 1282 | |
|
727 | 1283 | self.__blocksCounter = 0 |
|
728 | 1284 | |
|
729 | 1285 | #guardando atributos |
|
730 | 1286 | self.filename = filename |
|
731 | 1287 | self.__subfolder = subfolder |
|
732 | 1288 | self.__fp = fp |
|
733 | 1289 | self.__setFile = setFile |
|
734 | 1290 | self.__flagIsNewFile = 1 |
|
735 | 1291 | |
|
736 | 1292 | print 'Writing the file: %s'%self.filename |
|
737 | 1293 | |
|
738 | 1294 | self.__writeFirstHeader() |
|
739 | 1295 | |
|
740 | 1296 | return 1 |
|
1297 | ||
|
741 | 1298 | |
|
742 | def __setNewBlock(self): | |
|
1299 | def __setNewBlock( self ): | |
|
1300 | """ | |
|
1301 | Si es un nuevo file escribe el First Header caso contrario escribe solo el Basic Header | |
|
743 | 1302 |
|
|
1303 | Return: | |
|
1304 | 0 : si no pudo escribir nada | |
|
1305 | 1 : Si escribio el Basic el First Header | |
|
1306 | """ | |
|
744 | 1307 | if self.__fp == None: |
|
745 | 1308 | self.__setNextFile() |
|
746 | 1309 | |
|
747 | 1310 | if self.__flagIsNewFile: |
|
748 | 1311 | return 1 |
|
749 | 1312 | |
|
750 | 1313 | if self.__blocksCounter < self.m_ProcessingHeader.dataBlocksPerFile: |
|
751 | 1314 | self.__writeBasicHeader() |
|
752 | 1315 | return 1 |
|
753 | 1316 | |
|
754 | if not(self.__setNextFile()): | |
|
1317 | if not( self.__setNextFile() ): | |
|
755 | 1318 | return 0 |
|
756 | 1319 | |
|
757 | 1320 | return 1 |
|
758 | 1321 | |
|
759 | def __writeBlock(self): | |
|
760 | ||
|
761 | data = numpy.zeros(self.__shapeBuffer, self.__dataType) | |
|
1322 | def __writeBlock( self ): | |
|
1323 | """ | |
|
1324 | Escribe el buffer en el file designado | |
|
1325 | ||
|
1326 | Affected: | |
|
1327 | self.__datablockIndex | |
|
1328 | self.__flagIsNewFile | |
|
1329 | self.flagIsNewBlock | |
|
1330 | self.nWriteBlocks | |
|
1331 | self.__blocksCounter | |
|
1332 | ||
|
1333 | Return: None | |
|
1334 | """ | |
|
1335 | data = numpy.zeros( self.__shapeBuffer, self.__dataType ) | |
|
762 | 1336 | |
|
763 | 1337 | data['real'] = self.datablock.real |
|
764 | 1338 | data['imag'] = self.datablock.imag |
|
765 | 1339 | |
|
766 | data = data.reshape((-1)) | |
|
1340 | data = data.reshape( (-1) ) | |
|
767 | 1341 | |
|
768 | data.tofile(self.__fp) | |
|
1342 | data.tofile( self.__fp ) | |
|
769 | 1343 | |
|
770 | 1344 | self.datablock.fill(0) |
|
771 | 1345 | |
|
772 | 1346 | self.__datablockIndex = 0 |
|
773 | 1347 | |
|
774 | 1348 | self.__flagIsNewFile = 0 |
|
775 | 1349 | |
|
776 | 1350 | self.flagIsNewBlock = 1 |
|
777 | 1351 | |
|
778 | 1352 | self.nWriteBlocks += 1 |
|
779 | 1353 | |
|
780 | 1354 | self.__blocksCounter += 1 |
|
781 | 1355 | |
|
782 | 1356 | |
|
783 | def writeNextBlock(self): | |
|
784 | ||
|
1357 | def writeNextBlock( self ): | |
|
1358 | """ | |
|
1359 | Selecciona el bloque siguiente de datos y los escribe en un file | |
|
1360 | ||
|
1361 | Return: | |
|
1362 | 0 : Si no hizo pudo escribir el bloque de datos | |
|
1363 | 1 : Si no pudo escribir el bloque de datos | |
|
1364 | """ | |
|
785 | 1365 | if not(self.__setNewBlock()): |
|
786 | 1366 | return 0 |
|
787 | 1367 | |
|
788 | 1368 | self.__writeBlock() |
|
789 | 1369 | |
|
790 | 1370 | return 1 |
|
791 | 1371 | |
|
792 | def __hasAllDataInBuffer(self): | |
|
1372 | ||
|
1373 | def __hasAllDataInBuffer( self ): | |
|
793 | 1374 | if self.__datablockIndex >= self.m_ProcessingHeader.profilesPerBlock: |
|
794 | 1375 | return 1 |
|
795 | 1376 | |
|
796 | 1377 | return 0 |
|
1378 | ||
|
797 | 1379 | |
|
798 | def putData(self): | |
|
799 | ||
|
1380 | def putData( self ): | |
|
1381 | """ | |
|
1382 | Setea un bloque de datos y luego los escribe en un file | |
|
1383 | ||
|
1384 | Affected: | |
|
1385 | self.flagIsNewBlock | |
|
1386 | self.__datablockIndex | |
|
1387 | ||
|
1388 | Return: | |
|
1389 | 0 : Si no hay data o no hay mas files que puedan escribirse | |
|
1390 | 1 : Si se escribio la data de un bloque en un file | |
|
1391 | """ | |
|
800 | 1392 | self.flagIsNewBlock = 0 |
|
801 | 1393 | |
|
802 | 1394 | if self.m_Voltage.flagNoData: |
|
803 | 1395 | return 0 |
|
804 | 1396 | |
|
805 | 1397 | if self.m_Voltage.flagResetProcessing: |
|
806 | 1398 | |
|
807 | 1399 | self.datablock.fill(0) |
|
808 | 1400 | |
|
809 | 1401 | self.__datablockIndex = 0 |
|
810 | 1402 | self.__setNextFile() |
|
811 | 1403 | |
|
812 | 1404 | self.datablock[self.__datablockIndex,:,:] = self.m_Voltage.data |
|
813 | 1405 | |
|
814 | 1406 | self.__datablockIndex += 1 |
|
815 | 1407 | |
|
816 | 1408 | if self.__hasAllDataInBuffer(): |
|
817 | 1409 | |
|
818 | 1410 | self.__getHeader() |
|
819 | 1411 | self.writeNextBlock() |
|
820 | 1412 | |
|
821 | 1413 | if self.noMoreFiles: |
|
822 | 1414 | #print 'Process finished' |
|
823 | 1415 | return 0 |
|
824 | 1416 | |
|
825 | 1417 | return 1 |
|
826 | 1418 | |
|
827 | def __getHeader(self): | |
|
1419 | ||
|
1420 | def __getHeader( self ): | |
|
1421 | """ | |
|
1422 | Obtiene una copia del First Header | |
|
1423 | ||
|
1424 | Affected: | |
|
1425 | self.m_BasicHeader | |
|
1426 | self.m_SystemHeader | |
|
1427 | self.m_RadarControllerHeader | |
|
1428 | self.m_ProcessingHeader | |
|
1429 | self.__dataType | |
|
1430 | ||
|
1431 | Return: | |
|
1432 | None | |
|
1433 | """ | |
|
828 | 1434 | self.m_BasicHeader = self.m_Voltage.m_BasicHeader.copy() |
|
829 | 1435 | self.m_SystemHeader = self.m_Voltage.m_SystemHeader.copy() |
|
830 | 1436 | self.m_RadarControllerHeader = self.m_Voltage.m_RadarControllerHeader.copy() |
|
831 | 1437 | self.m_ProcessingHeader = self.m_Voltage.m_ProcessingHeader.copy() |
|
832 | 1438 | self.__dataType = self.m_Voltage.dataType |
|
1439 | ||
|
833 | 1440 | |
|
834 | def __setHeaderByFile(self): | |
|
1441 | def __setHeaderByFile( self ): | |
|
835 | 1442 | |
|
836 | 1443 | format = self.__format |
|
837 | 1444 | header = ['Basic','System','RadarController','Processing'] |
|
838 | 1445 | |
|
839 | 1446 | fmtFromFile = None |
|
840 | 1447 | headerFromFile = None |
|
841 | 1448 | |
|
842 | 1449 | |
|
843 | 1450 | fileTable = self.__configHeaderFile |
|
844 | 1451 | |
|
845 | 1452 | if os.access(fileTable, os.R_OK): |
|
846 | 1453 | import re, string |
|
847 | 1454 | |
|
848 | 1455 | f = open(fileTable,'r') |
|
849 | 1456 | lines = f.read() |
|
850 | 1457 | f.close() |
|
851 | 1458 | |
|
852 | 1459 | #Delete comments into expConfig |
|
853 | 1460 | while 1: |
|
854 | 1461 | |
|
855 | 1462 | startComment = string.find(lines.lower(),'#') |
|
856 | 1463 | if startComment == -1: |
|
857 | 1464 | break |
|
858 | 1465 | endComment = string.find(lines.lower(),'\n',startComment) |
|
859 | 1466 | lines = string.replace(lines,lines[startComment:endComment+1],'', 1) |
|
860 | 1467 | |
|
861 | 1468 | while expFromFile == None: |
|
862 | 1469 | |
|
863 | 1470 | currFmt = string.find(lines.lower(),'format="%s"' %(expName)) |
|
864 | 1471 | nextFmt = string.find(lines.lower(),'format',currFmt+10) |
|
865 | 1472 | |
|
866 | 1473 | if currFmt == -1: |
|
867 | 1474 | break |
|
868 | 1475 | if nextFmt == -1: |
|
869 | 1476 | nextFmt = len(lines)-1 |
|
870 | 1477 | |
|
871 | 1478 | fmtTable = lines[currFmt:nextFmt] |
|
872 | 1479 | lines = lines[nextFmt:] |
|
873 | 1480 | |
|
874 | 1481 | fmtRead = self.__getValueFromArg(fmtTable,'format') |
|
875 | 1482 | if fmtRead != format: |
|
876 | 1483 | continue |
|
877 | 1484 | fmtFromFile = fmtRead |
|
878 | 1485 | |
|
879 | 1486 | lines2 = fmtTable |
|
880 | 1487 | |
|
881 | 1488 | while headerFromFile == None: |
|
882 | 1489 | |
|
883 | 1490 | currHeader = string.find(lines2.lower(),'header="%s"' %(header)) |
|
884 | 1491 | nextHeader = string.find(lines2.lower(),'header',currHeader+10) |
|
885 | 1492 | |
|
886 | 1493 | if currHeader == -1: |
|
887 | 1494 | break |
|
888 | 1495 | if nextHeader == -1: |
|
889 | 1496 | nextHeader = len(lines2)-1 |
|
890 | 1497 | |
|
891 | 1498 | headerTable = lines2[currHeader:nextHeader] |
|
892 | 1499 | lines2 = lines2[nextHeader:] |
|
893 | 1500 | |
|
894 | 1501 | headerRead = self.__getValueFromArg(headerTable,'site') |
|
895 | 1502 | if not(headerRead in header): |
|
896 | 1503 | continue |
|
897 | 1504 | headerFromFile = headerRead |
|
898 | 1505 | |
|
899 | 1506 | if headerRead == 'Basic': |
|
900 | 1507 | self.m_BasicHeader.size = self.__getValueFromArg(headerTable,'size',lower=False) |
|
901 | 1508 | self.m_BasicHeader.version = self.__getValueFromArg(headerTable,'version',lower=False) |
|
902 | 1509 | self.m_BasicHeader.dataBlock = self.__getValueFromArg(headerTable,'dataBlock',lower=False) |
|
903 | 1510 | self.m_BasicHeader.utc = self.__getValueFromArg(headerTable,'utc',lower=False) |
|
904 | 1511 | self.m_BasicHeader.miliSecond = self.__getValueFromArg(headerTable,'miliSecond',lower=False) |
|
905 | 1512 | self.m_BasicHeader.timeZone = self.__getValueFromArg(headerTable,'timeZone',lower=False) |
|
906 | 1513 | self.m_BasicHeader.dstFlag = self.__getValueFromArg(headerTable,'dstFlag',lower=False) |
|
907 | 1514 | self.m_BasicHeader.errorCount = self.__getValueFromArg(headerTable,'errorCount',lower=False) |
|
908 | 1515 | |
|
909 | 1516 | else: |
|
910 | 1517 | print "file access denied:%s"%fileTable |
|
911 | 1518 | sys.exit(0) |
|
912 | 1519 | |
|
913 | def setup(self, path, set=0, format='rawdata'): | |
|
914 | ||
|
915 | ||
|
1520 | ||
|
1521 | def setup( self, path, set=0, format='rawdata' ): | |
|
1522 | """ | |
|
1523 | Setea el tipo de formato en la cual sera guardada la data y escribe el First Header | |
|
1524 | ||
|
1525 | Inputs: | |
|
1526 | path : el path destino en el cual se escribiran los files a crear | |
|
1527 | format : formato en el cual sera salvado un file | |
|
1528 | set : el setebo del file | |
|
1529 | ||
|
1530 | Return: | |
|
1531 | 0 : Si no realizo un buen seteo | |
|
1532 | 1 : Si realizo un buen seteo | |
|
1533 | """ | |
|
916 | 1534 | if format == 'hdf5': |
|
917 | 1535 | ext = '.hdf5' |
|
918 | 1536 | format = 'hdf5' |
|
919 | 1537 | print 'call hdf5 library' |
|
920 | 1538 | return 0 |
|
921 | 1539 | |
|
922 | 1540 | if format == 'rawdata': |
|
923 | 1541 | ext = '.r' |
|
924 | 1542 | format = 'Jicamarca' |
|
925 | 1543 | |
|
926 | 1544 | #call to config_headers |
|
927 | 1545 | #self.__setHeaderByFile() |
|
928 | 1546 | |
|
929 | 1547 | self.__path = path |
|
930 | 1548 | self.__setFile = set - 1 |
|
931 | 1549 | self.__ext = ext |
|
932 | 1550 | self.__format = format |
|
933 | 1551 | |
|
934 | 1552 | self.__getHeader() |
|
935 | 1553 | self.__shapeBuffer = (self.m_ProcessingHeader.profilesPerBlock, |
|
936 | 1554 | self.m_ProcessingHeader.numHeights, |
|
937 | 1555 | self.m_SystemHeader.numChannels ) |
|
938 | 1556 | |
|
939 | 1557 | self.datablock = numpy.zeros(self.__shapeBuffer, numpy.dtype('complex')) |
|
940 | 1558 | |
|
941 | 1559 | # if not(self.__setNextFile()): |
|
942 | 1560 | # return 0 |
|
943 | 1561 | return 1 |
|
944 | 1562 | |
|
945 | 1563 | |
|
946 | 1564 | |
|
947 | 1565 | |
|
948 | 1566 | No newline at end of file |
General Comments 0
You need to be logged in to leave comments.
Login now