##// END OF EJS Templates
Filtering block by time
Miguel Valdez -
r759:7c9c0d91a0d5
parent child
Show More
@@ -1,1646 +1,1698
1 '''
1 '''
2 Created on Jul 2, 2014
2 Created on Jul 2, 2014
3
3
4 @author: roj-idl71
4 @author: roj-idl71
5 '''
5 '''
6 import os
6 import os
7 import sys
7 import sys
8 import glob
8 import glob
9 import time
9 import time
10 import numpy
10 import numpy
11 import fnmatch
11 import fnmatch
12 import time, datetime
12 import time, datetime
13 #import h5py
13 #import h5py
14 import traceback
14 import traceback
15
15
16 try:
16 try:
17 from gevent import sleep
17 from gevent import sleep
18 except:
18 except:
19 from time import sleep
19 from time import sleep
20
20
21 from schainpy.model.data.jroheaderIO import PROCFLAG, BasicHeader, SystemHeader, RadarControllerHeader, ProcessingHeader
21 from schainpy.model.data.jroheaderIO import PROCFLAG, BasicHeader, SystemHeader, RadarControllerHeader, ProcessingHeader
22 from schainpy.model.data.jroheaderIO import get_dtype_index, get_numpy_dtype, get_procflag_dtype, get_dtype_width
22 from schainpy.model.data.jroheaderIO import get_dtype_index, get_numpy_dtype, get_procflag_dtype, get_dtype_width
23
23
24 LOCALTIME = True
24 LOCALTIME = True
25
25
26 def isNumber(cad):
26 def isNumber(cad):
27 """
27 """
28 Chequea si el conjunto de caracteres que componen un string puede ser convertidos a un numero.
28 Chequea si el conjunto de caracteres que componen un string puede ser convertidos a un numero.
29
29
30 Excepciones:
30 Excepciones:
31 Si un determinado string no puede ser convertido a numero
31 Si un determinado string no puede ser convertido a numero
32 Input:
32 Input:
33 str, string al cual se le analiza para determinar si convertible a un numero o no
33 str, string al cual se le analiza para determinar si convertible a un numero o no
34
34
35 Return:
35 Return:
36 True : si el string es uno numerico
36 True : si el string es uno numerico
37 False : no es un string numerico
37 False : no es un string numerico
38 """
38 """
39 try:
39 try:
40 float( cad )
40 float( cad )
41 return True
41 return True
42 except:
42 except:
43 return False
43 return False
44
44
45 def isFileInEpoch(filename, startUTSeconds, endUTSeconds):
45 def isFileInEpoch(filename, startUTSeconds, endUTSeconds):
46 """
46 """
47 Esta funcion determina si un archivo de datos se encuentra o no dentro del rango de fecha especificado.
47 Esta funcion determina si un archivo de datos se encuentra o no dentro del rango de fecha especificado.
48
48
49 Inputs:
49 Inputs:
50 filename : nombre completo del archivo de datos en formato Jicamarca (.r)
50 filename : nombre completo del archivo de datos en formato Jicamarca (.r)
51
51
52 startUTSeconds : fecha inicial del rango seleccionado. La fecha esta dada en
52 startUTSeconds : fecha inicial del rango seleccionado. La fecha esta dada en
53 segundos contados desde 01/01/1970.
53 segundos contados desde 01/01/1970.
54 endUTSeconds : fecha final del rango seleccionado. La fecha esta dada en
54 endUTSeconds : fecha final del rango seleccionado. La fecha esta dada en
55 segundos contados desde 01/01/1970.
55 segundos contados desde 01/01/1970.
56
56
57 Return:
57 Return:
58 Boolean : Retorna True si el archivo de datos contiene datos en el rango de
58 Boolean : Retorna True si el archivo de datos contiene datos en el rango de
59 fecha especificado, de lo contrario retorna False.
59 fecha especificado, de lo contrario retorna False.
60
60
61 Excepciones:
61 Excepciones:
62 Si el archivo no existe o no puede ser abierto
62 Si el archivo no existe o no puede ser abierto
63 Si la cabecera no puede ser leida.
63 Si la cabecera no puede ser leida.
64
64
65 """
65 """
66 basicHeaderObj = BasicHeader(LOCALTIME)
66 basicHeaderObj = BasicHeader(LOCALTIME)
67
67
68 try:
68 try:
69 fp = open(filename,'rb')
69 fp = open(filename,'rb')
70 except IOError:
70 except IOError:
71 print "The file %s can't be opened" %(filename)
71 print "The file %s can't be opened" %(filename)
72 return 0
72 return 0
73
73
74 sts = basicHeaderObj.read(fp)
74 sts = basicHeaderObj.read(fp)
75 fp.close()
75 fp.close()
76
76
77 if not(sts):
77 if not(sts):
78 print "Skipping the file %s because it has not a valid header" %(filename)
78 print "Skipping the file %s because it has not a valid header" %(filename)
79 return 0
79 return 0
80
80
81 if not ((startUTSeconds <= basicHeaderObj.utc) and (endUTSeconds > basicHeaderObj.utc)):
81 if not ((startUTSeconds <= basicHeaderObj.utc) and (endUTSeconds > basicHeaderObj.utc)):
82 return 0
82 return 0
83
83
84 return 1
84 return 1
85
85
86 def isTimeInRange(thisTime, startTime, endTime):
87
88 if endTime >= startTime:
89 if (thisTime < startTime) or (thisTime > endTime):
90 return 0
91
92 return 1
93 else:
94 if (thisTime < startTime) and (thisTime > endTime):
95 return 0
96
97 return 1
98
86 def isFileInTimeRange(filename, startDate, endDate, startTime, endTime):
99 def isFileInTimeRange(filename, startDate, endDate, startTime, endTime):
87 """
100 """
88 Retorna 1 si el archivo de datos se encuentra dentro del rango de horas especificado.
101 Retorna 1 si el archivo de datos se encuentra dentro del rango de horas especificado.
89
102
90 Inputs:
103 Inputs:
91 filename : nombre completo del archivo de datos en formato Jicamarca (.r)
104 filename : nombre completo del archivo de datos en formato Jicamarca (.r)
92
105
93 startDate : fecha inicial del rango seleccionado en formato datetime.date
106 startDate : fecha inicial del rango seleccionado en formato datetime.date
94
107
95 endDate : fecha final del rango seleccionado en formato datetime.date
108 endDate : fecha final del rango seleccionado en formato datetime.date
96
109
97 startTime : tiempo inicial del rango seleccionado en formato datetime.time
110 startTime : tiempo inicial del rango seleccionado en formato datetime.time
98
111
99 endTime : tiempo final del rango seleccionado en formato datetime.time
112 endTime : tiempo final del rango seleccionado en formato datetime.time
100
113
101 Return:
114 Return:
102 Boolean : Retorna True si el archivo de datos contiene datos en el rango de
115 Boolean : Retorna True si el archivo de datos contiene datos en el rango de
103 fecha especificado, de lo contrario retorna False.
116 fecha especificado, de lo contrario retorna False.
104
117
105 Excepciones:
118 Excepciones:
106 Si el archivo no existe o no puede ser abierto
119 Si el archivo no existe o no puede ser abierto
107 Si la cabecera no puede ser leida.
120 Si la cabecera no puede ser leida.
108
121
109 """
122 """
110
123
111
124
112 try:
125 try:
113 fp = open(filename,'rb')
126 fp = open(filename,'rb')
114 except IOError:
127 except IOError:
115 print "The file %s can't be opened" %(filename)
128 print "The file %s can't be opened" %(filename)
116 return None
129 return None
117
130
118 basicHeaderObj = BasicHeader(LOCALTIME)
131 firstBasicHeaderObj = BasicHeader(LOCALTIME)
119 sts = basicHeaderObj.read(fp)
132 systemHeaderObj = SystemHeader()
120 fp.close()
133 radarControllerHeaderObj = RadarControllerHeader()
134 processingHeaderObj = ProcessingHeader()
121
135
122 thisDatetime = basicHeaderObj.datatime
136 lastBasicHeaderObj = BasicHeader(LOCALTIME)
123 thisDate = thisDatetime.date()
137
124 thisTime = thisDatetime.time()
138 sts = firstBasicHeaderObj.read(fp)
139 sts = systemHeaderObj.read(fp)
140 sts = radarControllerHeaderObj.read(fp)
141 sts = processingHeaderObj.read(fp)
142
143 offset = processingHeaderObj.blockSize + 24 #header size
144
145 fp.seek(-offset, 2)
146
147 sts = lastBasicHeaderObj.read(fp)
148
149 fp.close()
125
150
126 if not(sts):
151 if not(sts):
127 print "Skipping the file %s because it has not a valid header" %(filename)
152 print "Skipping the file %s because it has not a valid header" %(filename)
128 return None
153 return None
129
154
155 thisDatetime = firstBasicHeaderObj.datatime
156 thisDate = thisDatetime.date()
157 thisTime_first_block = thisDatetime.time()
158
159 thisDatetime = lastBasicHeaderObj.datatime
160 thisTime_last_block = thisDatetime.time()
161
162
130 #General case
163 #General case
131 # o>>>>>>>>>>>>>><<<<<<<<<<<<<<o
164 # o>>>>>>>>>>>>>><<<<<<<<<<<<<<o
132 #-----------o----------------------------o-----------
165 #-----------o----------------------------o-----------
133 # startTime endTime
166 # startTime endTime
134
167
135 if endTime >= startTime:
168 if endTime >= startTime:
136 if (thisTime < startTime) or (thisTime > endTime):
169 if (thisTime_last_block < startTime) or (thisTime_first_block > endTime):
137 return None
170 return None
138
171
139 return thisDatetime
172 return thisDatetime
140
173
141 #If endTime < startTime then endTime belongs to the next day
174 #If endTime < startTime then endTime belongs to the next day
142
175
143
176
144 #<<<<<<<<<<<o o>>>>>>>>>>>
177 #<<<<<<<<<<<o o>>>>>>>>>>>
145 #-----------o----------------------------o-----------
178 #-----------o----------------------------o-----------
146 # endTime startTime
179 # endTime startTime
147
180
148 if (thisDate == startDate) and (thisTime < startTime):
181 if (thisDate == startDate) and (thisTime_last_block < startTime):
149 return None
182 return None
150
183
151 if (thisDate == endDate) and (thisTime > endTime):
184 if (thisDate == endDate) and (thisTime_first_block > endTime):
152 return None
185 return None
153
186
154 if (thisTime < startTime) and (thisTime > endTime):
187 if (thisTime_last_block < startTime) and (thisTime_first_block > endTime):
155 return None
188 return None
156
189
157 return thisDatetime
190 return thisDatetime
158
191
159 def isFolderInDateRange(folder, startDate=None, endDate=None):
192 def isFolderInDateRange(folder, startDate=None, endDate=None):
160 """
193 """
161 Retorna 1 si el archivo de datos se encuentra dentro del rango de horas especificado.
194 Retorna 1 si el archivo de datos se encuentra dentro del rango de horas especificado.
162
195
163 Inputs:
196 Inputs:
164 folder : nombre completo del directorio.
197 folder : nombre completo del directorio.
165 Su formato deberia ser "/path_root/?YYYYDDD"
198 Su formato deberia ser "/path_root/?YYYYDDD"
166
199
167 siendo:
200 siendo:
168 YYYY : Anio (ejemplo 2015)
201 YYYY : Anio (ejemplo 2015)
169 DDD : Dia del anio (ejemplo 305)
202 DDD : Dia del anio (ejemplo 305)
170
203
171 startDate : fecha inicial del rango seleccionado en formato datetime.date
204 startDate : fecha inicial del rango seleccionado en formato datetime.date
172
205
173 endDate : fecha final del rango seleccionado en formato datetime.date
206 endDate : fecha final del rango seleccionado en formato datetime.date
174
207
175 Return:
208 Return:
176 Boolean : Retorna True si el archivo de datos contiene datos en el rango de
209 Boolean : Retorna True si el archivo de datos contiene datos en el rango de
177 fecha especificado, de lo contrario retorna False.
210 fecha especificado, de lo contrario retorna False.
178 Excepciones:
211 Excepciones:
179 Si el directorio no tiene el formato adecuado
212 Si el directorio no tiene el formato adecuado
180 """
213 """
181
214
182 basename = os.path.basename(folder)
215 basename = os.path.basename(folder)
183
216
184 if not isRadarFolder(basename):
217 if not isRadarFolder(basename):
185 print "The folder %s has not the rigth format" %folder
218 print "The folder %s has not the rigth format" %folder
186 return 0
219 return 0
187
220
188 if startDate and endDate:
221 if startDate and endDate:
189 thisDate = getDateFromRadarFolder(basename)
222 thisDate = getDateFromRadarFolder(basename)
190
223
191 if thisDate < startDate:
224 if thisDate < startDate:
192 return 0
225 return 0
193
226
194 if thisDate > endDate:
227 if thisDate > endDate:
195 return 0
228 return 0
196
229
197 return 1
230 return 1
198
231
199 def isFileInDateRange(filename, startDate=None, endDate=None):
232 def isFileInDateRange(filename, startDate=None, endDate=None):
200 """
233 """
201 Retorna 1 si el archivo de datos se encuentra dentro del rango de horas especificado.
234 Retorna 1 si el archivo de datos se encuentra dentro del rango de horas especificado.
202
235
203 Inputs:
236 Inputs:
204 filename : nombre completo del archivo de datos en formato Jicamarca (.r)
237 filename : nombre completo del archivo de datos en formato Jicamarca (.r)
205
238
206 Su formato deberia ser "?YYYYDDDsss"
239 Su formato deberia ser "?YYYYDDDsss"
207
240
208 siendo:
241 siendo:
209 YYYY : Anio (ejemplo 2015)
242 YYYY : Anio (ejemplo 2015)
210 DDD : Dia del anio (ejemplo 305)
243 DDD : Dia del anio (ejemplo 305)
211 sss : set
244 sss : set
212
245
213 startDate : fecha inicial del rango seleccionado en formato datetime.date
246 startDate : fecha inicial del rango seleccionado en formato datetime.date
214
247
215 endDate : fecha final del rango seleccionado en formato datetime.date
248 endDate : fecha final del rango seleccionado en formato datetime.date
216
249
217 Return:
250 Return:
218 Boolean : Retorna True si el archivo de datos contiene datos en el rango de
251 Boolean : Retorna True si el archivo de datos contiene datos en el rango de
219 fecha especificado, de lo contrario retorna False.
252 fecha especificado, de lo contrario retorna False.
220 Excepciones:
253 Excepciones:
221 Si el archivo no tiene el formato adecuado
254 Si el archivo no tiene el formato adecuado
222 """
255 """
223
256
224 basename = os.path.basename(filename)
257 basename = os.path.basename(filename)
225
258
226 if not isRadarFile(basename):
259 if not isRadarFile(basename):
227 print "The filename %s has not the rigth format" %filename
260 print "The filename %s has not the rigth format" %filename
228 return 0
261 return 0
229
262
230 if startDate and endDate:
263 if startDate and endDate:
231 thisDate = getDateFromRadarFile(basename)
264 thisDate = getDateFromRadarFile(basename)
232
265
233 if thisDate < startDate:
266 if thisDate < startDate:
234 return 0
267 return 0
235
268
236 if thisDate > endDate:
269 if thisDate > endDate:
237 return 0
270 return 0
238
271
239 return 1
272 return 1
240
273
241 def getFileFromSet(path, ext, set):
274 def getFileFromSet(path, ext, set):
242 validFilelist = []
275 validFilelist = []
243 fileList = os.listdir(path)
276 fileList = os.listdir(path)
244
277
245 # 0 1234 567 89A BCDE
278 # 0 1234 567 89A BCDE
246 # H YYYY DDD SSS .ext
279 # H YYYY DDD SSS .ext
247
280
248 for thisFile in fileList:
281 for thisFile in fileList:
249 try:
282 try:
250 year = int(thisFile[1:5])
283 year = int(thisFile[1:5])
251 doy = int(thisFile[5:8])
284 doy = int(thisFile[5:8])
252 except:
285 except:
253 continue
286 continue
254
287
255 if (os.path.splitext(thisFile)[-1].lower() != ext.lower()):
288 if (os.path.splitext(thisFile)[-1].lower() != ext.lower()):
256 continue
289 continue
257
290
258 validFilelist.append(thisFile)
291 validFilelist.append(thisFile)
259
292
260 myfile = fnmatch.filter(validFilelist,'*%4.4d%3.3d%3.3d*'%(year,doy,set))
293 myfile = fnmatch.filter(validFilelist,'*%4.4d%3.3d%3.3d*'%(year,doy,set))
261
294
262 if len(myfile)!= 0:
295 if len(myfile)!= 0:
263 return myfile[0]
296 return myfile[0]
264 else:
297 else:
265 filename = '*%4.4d%3.3d%3.3d%s'%(year,doy,set,ext.lower())
298 filename = '*%4.4d%3.3d%3.3d%s'%(year,doy,set,ext.lower())
266 print 'the filename %s does not exist'%filename
299 print 'the filename %s does not exist'%filename
267 print '...going to the last file: '
300 print '...going to the last file: '
268
301
269 if validFilelist:
302 if validFilelist:
270 validFilelist = sorted( validFilelist, key=str.lower )
303 validFilelist = sorted( validFilelist, key=str.lower )
271 return validFilelist[-1]
304 return validFilelist[-1]
272
305
273 return None
306 return None
274
307
275 def getlastFileFromPath(path, ext):
308 def getlastFileFromPath(path, ext):
276 """
309 """
277 Depura el fileList dejando solo los que cumplan el formato de "PYYYYDDDSSS.ext"
310 Depura el fileList dejando solo los que cumplan el formato de "PYYYYDDDSSS.ext"
278 al final de la depuracion devuelve el ultimo file de la lista que quedo.
311 al final de la depuracion devuelve el ultimo file de la lista que quedo.
279
312
280 Input:
313 Input:
281 fileList : lista conteniendo todos los files (sin path) que componen una determinada carpeta
314 fileList : lista conteniendo todos los files (sin path) que componen una determinada carpeta
282 ext : extension de los files contenidos en una carpeta
315 ext : extension de los files contenidos en una carpeta
283
316
284 Return:
317 Return:
285 El ultimo file de una determinada carpeta, no se considera el path.
318 El ultimo file de una determinada carpeta, no se considera el path.
286 """
319 """
287 validFilelist = []
320 validFilelist = []
288 fileList = os.listdir(path)
321 fileList = os.listdir(path)
289
322
290 # 0 1234 567 89A BCDE
323 # 0 1234 567 89A BCDE
291 # H YYYY DDD SSS .ext
324 # H YYYY DDD SSS .ext
292
325
293 for thisFile in fileList:
326 for thisFile in fileList:
294
327
295 year = thisFile[1:5]
328 year = thisFile[1:5]
296 if not isNumber(year):
329 if not isNumber(year):
297 continue
330 continue
298
331
299 doy = thisFile[5:8]
332 doy = thisFile[5:8]
300 if not isNumber(doy):
333 if not isNumber(doy):
301 continue
334 continue
302
335
303 year = int(year)
336 year = int(year)
304 doy = int(doy)
337 doy = int(doy)
305
338
306 if (os.path.splitext(thisFile)[-1].lower() != ext.lower()):
339 if (os.path.splitext(thisFile)[-1].lower() != ext.lower()):
307 continue
340 continue
308
341
309 validFilelist.append(thisFile)
342 validFilelist.append(thisFile)
310
343
311 if validFilelist:
344 if validFilelist:
312 validFilelist = sorted( validFilelist, key=str.lower )
345 validFilelist = sorted( validFilelist, key=str.lower )
313 return validFilelist[-1]
346 return validFilelist[-1]
314
347
315 return None
348 return None
316
349
317 def checkForRealPath(path, foldercounter, year, doy, set, ext):
350 def checkForRealPath(path, foldercounter, year, doy, set, ext):
318 """
351 """
319 Por ser Linux Case Sensitive entonces checkForRealPath encuentra el nombre correcto de un path,
352 Por ser Linux Case Sensitive entonces checkForRealPath encuentra el nombre correcto de un path,
320 Prueba por varias combinaciones de nombres entre mayusculas y minusculas para determinar
353 Prueba por varias combinaciones de nombres entre mayusculas y minusculas para determinar
321 el path exacto de un determinado file.
354 el path exacto de un determinado file.
322
355
323 Example :
356 Example :
324 nombre correcto del file es .../.../D2009307/P2009307367.ext
357 nombre correcto del file es .../.../D2009307/P2009307367.ext
325
358
326 Entonces la funcion prueba con las siguientes combinaciones
359 Entonces la funcion prueba con las siguientes combinaciones
327 .../.../y2009307367.ext
360 .../.../y2009307367.ext
328 .../.../Y2009307367.ext
361 .../.../Y2009307367.ext
329 .../.../x2009307/y2009307367.ext
362 .../.../x2009307/y2009307367.ext
330 .../.../x2009307/Y2009307367.ext
363 .../.../x2009307/Y2009307367.ext
331 .../.../X2009307/y2009307367.ext
364 .../.../X2009307/y2009307367.ext
332 .../.../X2009307/Y2009307367.ext
365 .../.../X2009307/Y2009307367.ext
333 siendo para este caso, la ultima combinacion de letras, identica al file buscado
366 siendo para este caso, la ultima combinacion de letras, identica al file buscado
334
367
335 Return:
368 Return:
336 Si encuentra la cobinacion adecuada devuelve el path completo y el nombre del file
369 Si encuentra la cobinacion adecuada devuelve el path completo y el nombre del file
337 caso contrario devuelve None como path y el la ultima combinacion de nombre en mayusculas
370 caso contrario devuelve None como path y el la ultima combinacion de nombre en mayusculas
338 para el filename
371 para el filename
339 """
372 """
340 fullfilename = None
373 fullfilename = None
341 find_flag = False
374 find_flag = False
342 filename = None
375 filename = None
343
376
344 prefixDirList = [None,'d','D']
377 prefixDirList = [None,'d','D']
345 if ext.lower() == ".r": #voltage
378 if ext.lower() == ".r": #voltage
346 prefixFileList = ['d','D']
379 prefixFileList = ['d','D']
347 elif ext.lower() == ".pdata": #spectra
380 elif ext.lower() == ".pdata": #spectra
348 prefixFileList = ['p','P']
381 prefixFileList = ['p','P']
349 else:
382 else:
350 return None, filename
383 return None, filename
351
384
352 #barrido por las combinaciones posibles
385 #barrido por las combinaciones posibles
353 for prefixDir in prefixDirList:
386 for prefixDir in prefixDirList:
354 thispath = path
387 thispath = path
355 if prefixDir != None:
388 if prefixDir != None:
356 #formo el nombre del directorio xYYYYDDD (x=d o x=D)
389 #formo el nombre del directorio xYYYYDDD (x=d o x=D)
357 if foldercounter == 0:
390 if foldercounter == 0:
358 thispath = os.path.join(path, "%s%04d%03d" % ( prefixDir, year, doy ))
391 thispath = os.path.join(path, "%s%04d%03d" % ( prefixDir, year, doy ))
359 else:
392 else:
360 thispath = os.path.join(path, "%s%04d%03d_%02d" % ( prefixDir, year, doy , foldercounter))
393 thispath = os.path.join(path, "%s%04d%03d_%02d" % ( prefixDir, year, doy , foldercounter))
361 for prefixFile in prefixFileList: #barrido por las dos combinaciones posibles de "D"
394 for prefixFile in prefixFileList: #barrido por las dos combinaciones posibles de "D"
362 filename = "%s%04d%03d%03d%s" % ( prefixFile, year, doy, set, ext ) #formo el nombre del file xYYYYDDDSSS.ext
395 filename = "%s%04d%03d%03d%s" % ( prefixFile, year, doy, set, ext ) #formo el nombre del file xYYYYDDDSSS.ext
363 fullfilename = os.path.join( thispath, filename ) #formo el path completo
396 fullfilename = os.path.join( thispath, filename ) #formo el path completo
364
397
365 if os.path.exists( fullfilename ): #verifico que exista
398 if os.path.exists( fullfilename ): #verifico que exista
366 find_flag = True
399 find_flag = True
367 break
400 break
368 if find_flag:
401 if find_flag:
369 break
402 break
370
403
371 if not(find_flag):
404 if not(find_flag):
372 return None, filename
405 return None, filename
373
406
374 return fullfilename, filename
407 return fullfilename, filename
375
408
376 def isRadarFolder(folder):
409 def isRadarFolder(folder):
377 try:
410 try:
378 year = int(folder[1:5])
411 year = int(folder[1:5])
379 doy = int(folder[5:8])
412 doy = int(folder[5:8])
380 except:
413 except:
381 return 0
414 return 0
382
415
383 return 1
416 return 1
384
417
385 def isRadarFile(file):
418 def isRadarFile(file):
386 try:
419 try:
387 year = int(file[1:5])
420 year = int(file[1:5])
388 doy = int(file[5:8])
421 doy = int(file[5:8])
389 set = int(file[8:11])
422 set = int(file[8:11])
390 except:
423 except:
391 return 0
424 return 0
392
425
393 return 1
426 return 1
394
427
395 def getDateFromRadarFile(file):
428 def getDateFromRadarFile(file):
396 try:
429 try:
397 year = int(file[1:5])
430 year = int(file[1:5])
398 doy = int(file[5:8])
431 doy = int(file[5:8])
399 set = int(file[8:11])
432 set = int(file[8:11])
400 except:
433 except:
401 return None
434 return None
402
435
403 thisDate = datetime.date(year, 1, 1) + datetime.timedelta(doy-1)
436 thisDate = datetime.date(year, 1, 1) + datetime.timedelta(doy-1)
404 return thisDate
437 return thisDate
405
438
406 def getDateFromRadarFolder(folder):
439 def getDateFromRadarFolder(folder):
407 try:
440 try:
408 year = int(folder[1:5])
441 year = int(folder[1:5])
409 doy = int(folder[5:8])
442 doy = int(folder[5:8])
410 except:
443 except:
411 return None
444 return None
412
445
413 thisDate = datetime.date(year, 1, 1) + datetime.timedelta(doy-1)
446 thisDate = datetime.date(year, 1, 1) + datetime.timedelta(doy-1)
414 return thisDate
447 return thisDate
415
448
416 class JRODataIO:
449 class JRODataIO:
417
450
418 c = 3E8
451 c = 3E8
419
452
420 isConfig = False
453 isConfig = False
421
454
422 basicHeaderObj = None
455 basicHeaderObj = None
423
456
424 systemHeaderObj = None
457 systemHeaderObj = None
425
458
426 radarControllerHeaderObj = None
459 radarControllerHeaderObj = None
427
460
428 processingHeaderObj = None
461 processingHeaderObj = None
429
462
430 dtype = None
463 dtype = None
431
464
432 pathList = []
465 pathList = []
433
466
434 filenameList = []
467 filenameList = []
435
468
436 filename = None
469 filename = None
437
470
438 ext = None
471 ext = None
439
472
440 flagIsNewFile = 1
473 flagIsNewFile = 1
441
474
442 flagDiscontinuousBlock = 0
475 flagDiscontinuousBlock = 0
443
476
444 flagIsNewBlock = 0
477 flagIsNewBlock = 0
445
478
446 fp = None
479 fp = None
447
480
448 firstHeaderSize = 0
481 firstHeaderSize = 0
449
482
450 basicHeaderSize = 24
483 basicHeaderSize = 24
451
484
452 versionFile = 1103
485 versionFile = 1103
453
486
454 fileSize = None
487 fileSize = None
455
488
456 # ippSeconds = None
489 # ippSeconds = None
457
490
458 fileSizeByHeader = None
491 fileSizeByHeader = None
459
492
460 fileIndex = None
493 fileIndex = None
461
494
462 profileIndex = None
495 profileIndex = None
463
496
464 blockIndex = None
497 blockIndex = None
465
498
466 nTotalBlocks = None
499 nTotalBlocks = None
467
500
468 maxTimeStep = 30
501 maxTimeStep = 30
469
502
470 lastUTTime = None
503 lastUTTime = None
471
504
472 datablock = None
505 datablock = None
473
506
474 dataOut = None
507 dataOut = None
475
508
476 blocksize = None
509 blocksize = None
477
510
478 getByBlock = False
511 getByBlock = False
479
512
480 def __init__(self):
513 def __init__(self):
481
514
482 raise NotImplementedError
515 raise NotImplementedError
483
516
484 def run(self):
517 def run(self):
485
518
486 raise NotImplementedError
519 raise NotImplementedError
487
520
488 def getDtypeWidth(self):
521 def getDtypeWidth(self):
489
522
490 dtype_index = get_dtype_index(self.dtype)
523 dtype_index = get_dtype_index(self.dtype)
491 dtype_width = get_dtype_width(dtype_index)
524 dtype_width = get_dtype_width(dtype_index)
492
525
493 return dtype_width
526 return dtype_width
494
527
495 class JRODataReader(JRODataIO):
528 class JRODataReader(JRODataIO):
496
529
497
530
498 online = 0
531 online = 0
499
532
500 realtime = 0
533 realtime = 0
501
534
502 nReadBlocks = 0
535 nReadBlocks = 0
503
536
504 delay = 10 #number of seconds waiting a new file
537 delay = 10 #number of seconds waiting a new file
505
538
506 nTries = 3 #quantity tries
539 nTries = 3 #quantity tries
507
540
508 nFiles = 3 #number of files for searching
541 nFiles = 3 #number of files for searching
509
542
510 path = None
543 path = None
511
544
512 foldercounter = 0
545 foldercounter = 0
513
546
514 flagNoMoreFiles = 0
547 flagNoMoreFiles = 0
515
548
516 datetimeList = []
549 datetimeList = []
517
550
518 __isFirstTimeOnline = 1
551 __isFirstTimeOnline = 1
519
552
520 __printInfo = True
553 __printInfo = True
521
554
522 profileIndex = None
555 profileIndex = None
523
556
524 nTxs = 1
557 nTxs = 1
525
558
526 txIndex = None
559 txIndex = None
527
560
528 def __init__(self):
561 def __init__(self):
529
562
530 """
563 """
531 This class is used to find data files
564 This class is used to find data files
532
565
533 Example:
566 Example:
534 reader = JRODataReader()
567 reader = JRODataReader()
535 fileList = reader.findDataFiles()
568 fileList = reader.findDataFiles()
536
569
537 """
570 """
538 pass
571 pass
539
572
540
573
541 def createObjByDefault(self):
574 def createObjByDefault(self):
542 """
575 """
543
576
544 """
577 """
545 raise NotImplementedError
578 raise NotImplementedError
546
579
547 def getBlockDimension(self):
580 def getBlockDimension(self):
548
581
549 raise NotImplementedError
582 raise NotImplementedError
550
583
551 def __searchFilesOffLine(self,
584 def __searchFilesOffLine(self,
552 path,
585 path,
553 startDate=None,
586 startDate=None,
554 endDate=None,
587 endDate=None,
555 startTime=datetime.time(0,0,0),
588 startTime=datetime.time(0,0,0),
556 endTime=datetime.time(23,59,59),
589 endTime=datetime.time(23,59,59),
557 set=None,
590 set=None,
558 expLabel='',
591 expLabel='',
559 ext='.r',
592 ext='.r',
560 walk=True):
593 walk=True):
561
594
562 self.filenameList = []
595 self.filenameList = []
563 self.datetimeList = []
596 self.datetimeList = []
564
597
565 pathList = []
598 pathList = []
566
599
567 dateList, pathList = self.findDatafiles(path, startDate, endDate, expLabel, ext, walk, include_path=True)
600 dateList, pathList = self.findDatafiles(path, startDate, endDate, expLabel, ext, walk, include_path=True)
568
601
569 if dateList == []:
602 if dateList == []:
570 # print "[Reading] No *%s files in %s from %s to %s)"%(ext, path,
603 # print "[Reading] Date range selected invalid [%s - %s]: No *%s files in %s)" %(startDate, endDate, ext, path)
571 # datetime.datetime.combine(startDate,startTime).ctime(),
572 # datetime.datetime.combine(endDate,endTime).ctime())
573
574 return None, None
604 return None, None
575
605
576 if len(dateList) > 1:
606 if len(dateList) > 1:
577 print "[Reading] Data found: total days = %d, date range = %s - %s" %(len(dateList), startDate, endDate)
607 print "[Reading] Data found for date range [%s - %s]: total days = %d" %(startDate, endDate, len(dateList))
578 else:
608 else:
579 print "[Reading] Data found: date = %s" %(dateList[0])
609 print "[Reading] Data found for date range [%s - %s]: date = %s" %(startDate, endDate, dateList[0])
580
610
581 filenameList = []
611 filenameList = []
582 datetimeList = []
612 datetimeList = []
583
613
584 for thisPath in pathList:
614 for thisPath in pathList:
585 # thisPath = pathList[pathDict[file]]
615 # thisPath = pathList[pathDict[file]]
586
616
587 fileList = glob.glob1(thisPath, "*%s" %ext)
617 fileList = glob.glob1(thisPath, "*%s" %ext)
588 fileList.sort()
618 fileList.sort()
589
619
590 for file in fileList:
620 for file in fileList:
591
621
592 filename = os.path.join(thisPath,file)
622 filename = os.path.join(thisPath,file)
593
623
594 if not isFileInDateRange(filename, startDate, endDate):
624 if not isFileInDateRange(filename, startDate, endDate):
595 continue
625 continue
596
626
597 thisDatetime = isFileInTimeRange(filename, startDate, endDate, startTime, endTime)
627 thisDatetime = isFileInTimeRange(filename, startDate, endDate, startTime, endTime)
598
628
599 if not(thisDatetime):
629 if not(thisDatetime):
600 continue
630 continue
601
631
602 filenameList.append(filename)
632 filenameList.append(filename)
603 datetimeList.append(thisDatetime)
633 datetimeList.append(thisDatetime)
604
634
605 if not(filenameList):
635 if not(filenameList):
606 print "[Reading] Any file was found int time range %s - %s" %(datetime.datetime.combine(startDate,startTime).ctime(), datetime.datetime.combine(endDate,endTime).ctime())
636 print "[Reading] Time range selected invalid [%s - %s]: No *%s files in %s)" %(startTime, endTime, ext, path)
607 return None, None
637 return None, None
608
638
609 print "[Reading] %d file(s) was(were) found in time range: %s - %s" %(len(filenameList), startTime, endTime)
639 print "[Reading] %d file(s) was(were) found in time range: %s - %s" %(len(filenameList), startTime, endTime)
610 print
640 print
611
641
612 for i in range(len(filenameList)):
642 for i in range(len(filenameList)):
613 print "[Reading] %s -> [%s]" %(filenameList[i], datetimeList[i].ctime())
643 print "[Reading] %s -> [%s]" %(filenameList[i], datetimeList[i].ctime())
614
644
615 self.filenameList = filenameList
645 self.filenameList = filenameList
616 self.datetimeList = datetimeList
646 self.datetimeList = datetimeList
617
647
618 return pathList, filenameList
648 return pathList, filenameList
619
649
620 def __searchFilesOnLine(self, path, expLabel = "", ext = None, walk=True, set=None):
650 def __searchFilesOnLine(self, path, expLabel = "", ext = None, walk=True, set=None):
621
651
622 """
652 """
623 Busca el ultimo archivo de la ultima carpeta (determinada o no por startDateTime) y
653 Busca el ultimo archivo de la ultima carpeta (determinada o no por startDateTime) y
624 devuelve el archivo encontrado ademas de otros datos.
654 devuelve el archivo encontrado ademas de otros datos.
625
655
626 Input:
656 Input:
627 path : carpeta donde estan contenidos los files que contiene data
657 path : carpeta donde estan contenidos los files que contiene data
628
658
629 expLabel : Nombre del subexperimento (subfolder)
659 expLabel : Nombre del subexperimento (subfolder)
630
660
631 ext : extension de los files
661 ext : extension de los files
632
662
633 walk : Si es habilitado no realiza busquedas dentro de los ubdirectorios (doypath)
663 walk : Si es habilitado no realiza busquedas dentro de los ubdirectorios (doypath)
634
664
635 Return:
665 Return:
636 directory : eL directorio donde esta el file encontrado
666 directory : eL directorio donde esta el file encontrado
637 filename : el ultimo file de una determinada carpeta
667 filename : el ultimo file de una determinada carpeta
638 year : el anho
668 year : el anho
639 doy : el numero de dia del anho
669 doy : el numero de dia del anho
640 set : el set del archivo
670 set : el set del archivo
641
671
642
672
643 """
673 """
644 if not os.path.isdir(path):
674 if not os.path.isdir(path):
645 return None, None, None, None, None, None
675 return None, None, None, None, None, None
646
676
647 dirList = []
677 dirList = []
648
678
649 if not walk:
679 if not walk:
650 fullpath = path
680 fullpath = path
651 foldercounter = 0
681 foldercounter = 0
652 else:
682 else:
653 #Filtra solo los directorios
683 #Filtra solo los directorios
654 for thisPath in os.listdir(path):
684 for thisPath in os.listdir(path):
655 if not os.path.isdir(os.path.join(path,thisPath)):
685 if not os.path.isdir(os.path.join(path,thisPath)):
656 continue
686 continue
657 if not isRadarFolder(thisPath):
687 if not isRadarFolder(thisPath):
658 continue
688 continue
659
689
660 dirList.append(thisPath)
690 dirList.append(thisPath)
661
691
662 if not(dirList):
692 if not(dirList):
663 return None, None, None, None, None, None
693 return None, None, None, None, None, None
664
694
665 dirList = sorted( dirList, key=str.lower )
695 dirList = sorted( dirList, key=str.lower )
666
696
667 doypath = dirList[-1]
697 doypath = dirList[-1]
668 foldercounter = int(doypath.split('_')[1]) if len(doypath.split('_'))>1 else 0
698 foldercounter = int(doypath.split('_')[1]) if len(doypath.split('_'))>1 else 0
669 fullpath = os.path.join(path, doypath, expLabel)
699 fullpath = os.path.join(path, doypath, expLabel)
670
700
671
701
672 print "[Reading] %s folder was found: " %(fullpath )
702 print "[Reading] %s folder was found: " %(fullpath )
673
703
674 if set == None:
704 if set == None:
675 filename = getlastFileFromPath(fullpath, ext)
705 filename = getlastFileFromPath(fullpath, ext)
676 else:
706 else:
677 filename = getFileFromSet(fullpath, ext, set)
707 filename = getFileFromSet(fullpath, ext, set)
678
708
679 if not(filename):
709 if not(filename):
680 return None, None, None, None, None, None
710 return None, None, None, None, None, None
681
711
682 print "[Reading] %s file was found" %(filename)
712 print "[Reading] %s file was found" %(filename)
683
713
684 if not(self.__verifyFile(os.path.join(fullpath, filename))):
714 if not(self.__verifyFile(os.path.join(fullpath, filename))):
685 return None, None, None, None, None, None
715 return None, None, None, None, None, None
686
716
687 year = int( filename[1:5] )
717 year = int( filename[1:5] )
688 doy = int( filename[5:8] )
718 doy = int( filename[5:8] )
689 set = int( filename[8:11] )
719 set = int( filename[8:11] )
690
720
691 return fullpath, foldercounter, filename, year, doy, set
721 return fullpath, foldercounter, filename, year, doy, set
692
722
693 def __setNextFileOffline(self):
723 def __setNextFileOffline(self):
694
724
695 idFile = self.fileIndex
725 idFile = self.fileIndex
696
726
697 while (True):
727 while (True):
698 idFile += 1
728 idFile += 1
699 if not(idFile < len(self.filenameList)):
729 if not(idFile < len(self.filenameList)):
700 self.flagNoMoreFiles = 1
730 self.flagNoMoreFiles = 1
701 # print "[Reading] No more Files"
731 # print "[Reading] No more Files"
702 return 0
732 return 0
703
733
704 filename = self.filenameList[idFile]
734 filename = self.filenameList[idFile]
705
735
706 if not(self.__verifyFile(filename)):
736 if not(self.__verifyFile(filename)):
707 continue
737 continue
708
738
709 fileSize = os.path.getsize(filename)
739 fileSize = os.path.getsize(filename)
710 fp = open(filename,'rb')
740 fp = open(filename,'rb')
711 break
741 break
712
742
713 self.flagIsNewFile = 1
743 self.flagIsNewFile = 1
714 self.fileIndex = idFile
744 self.fileIndex = idFile
715 self.filename = filename
745 self.filename = filename
716 self.fileSize = fileSize
746 self.fileSize = fileSize
717 self.fp = fp
747 self.fp = fp
718
748
719 # print "[Reading] Setting the file: %s"%self.filename
749 # print "[Reading] Setting the file: %s"%self.filename
720
750
721 return 1
751 return 1
722
752
723 def __setNextFileOnline(self):
753 def __setNextFileOnline(self):
724 """
754 """
725 Busca el siguiente file que tenga suficiente data para ser leida, dentro de un folder especifico, si
755 Busca el siguiente file que tenga suficiente data para ser leida, dentro de un folder especifico, si
726 no encuentra un file valido espera un tiempo determinado y luego busca en los posibles n files
756 no encuentra un file valido espera un tiempo determinado y luego busca en los posibles n files
727 siguientes.
757 siguientes.
728
758
729 Affected:
759 Affected:
730 self.flagIsNewFile
760 self.flagIsNewFile
731 self.filename
761 self.filename
732 self.fileSize
762 self.fileSize
733 self.fp
763 self.fp
734 self.set
764 self.set
735 self.flagNoMoreFiles
765 self.flagNoMoreFiles
736
766
737 Return:
767 Return:
738 0 : si luego de una busqueda del siguiente file valido este no pudo ser encontrado
768 0 : si luego de una busqueda del siguiente file valido este no pudo ser encontrado
739 1 : si el file fue abierto con exito y esta listo a ser leido
769 1 : si el file fue abierto con exito y esta listo a ser leido
740
770
741 Excepciones:
771 Excepciones:
742 Si un determinado file no puede ser abierto
772 Si un determinado file no puede ser abierto
743 """
773 """
744 nFiles = 0
774 nFiles = 0
745 fileOk_flag = False
775 fileOk_flag = False
746 firstTime_flag = True
776 firstTime_flag = True
747
777
748 self.set += 1
778 self.set += 1
749
779
750 if self.set > 999:
780 if self.set > 999:
751 self.set = 0
781 self.set = 0
752 self.foldercounter += 1
782 self.foldercounter += 1
753
783
754 #busca el 1er file disponible
784 #busca el 1er file disponible
755 fullfilename, filename = checkForRealPath( self.path, self.foldercounter, self.year, self.doy, self.set, self.ext )
785 fullfilename, filename = checkForRealPath( self.path, self.foldercounter, self.year, self.doy, self.set, self.ext )
756 if fullfilename:
786 if fullfilename:
757 if self.__verifyFile(fullfilename, False):
787 if self.__verifyFile(fullfilename, False):
758 fileOk_flag = True
788 fileOk_flag = True
759
789
760 #si no encuentra un file entonces espera y vuelve a buscar
790 #si no encuentra un file entonces espera y vuelve a buscar
761 if not(fileOk_flag):
791 if not(fileOk_flag):
762 for nFiles in range(self.nFiles+1): #busco en los siguientes self.nFiles+1 files posibles
792 for nFiles in range(self.nFiles+1): #busco en los siguientes self.nFiles+1 files posibles
763
793
764 if firstTime_flag: #si es la 1era vez entonces hace el for self.nTries veces
794 if firstTime_flag: #si es la 1era vez entonces hace el for self.nTries veces
765 tries = self.nTries
795 tries = self.nTries
766 else:
796 else:
767 tries = 1 #si no es la 1era vez entonces solo lo hace una vez
797 tries = 1 #si no es la 1era vez entonces solo lo hace una vez
768
798
769 for nTries in range( tries ):
799 for nTries in range( tries ):
770 if firstTime_flag:
800 if firstTime_flag:
771 print "\t[Reading] Waiting %0.2f sec for the next file: \"%s\" , try %03d ..." % ( self.delay, filename, nTries+1 )
801 print "\t[Reading] Waiting %0.2f sec for the next file: \"%s\" , try %03d ..." % ( self.delay, filename, nTries+1 )
772 sleep( self.delay )
802 sleep( self.delay )
773 else:
803 else:
774 print "\t[Reading] Searching the next \"%s%04d%03d%03d%s\" file ..." % (self.optchar, self.year, self.doy, self.set, self.ext)
804 print "\t[Reading] Searching the next \"%s%04d%03d%03d%s\" file ..." % (self.optchar, self.year, self.doy, self.set, self.ext)
775
805
776 fullfilename, filename = checkForRealPath( self.path, self.foldercounter, self.year, self.doy, self.set, self.ext )
806 fullfilename, filename = checkForRealPath( self.path, self.foldercounter, self.year, self.doy, self.set, self.ext )
777 if fullfilename:
807 if fullfilename:
778 if self.__verifyFile(fullfilename):
808 if self.__verifyFile(fullfilename):
779 fileOk_flag = True
809 fileOk_flag = True
780 break
810 break
781
811
782 if fileOk_flag:
812 if fileOk_flag:
783 break
813 break
784
814
785 firstTime_flag = False
815 firstTime_flag = False
786
816
787 print "\t[Reading] Skipping the file \"%s\" due to this file doesn't exist" % filename
817 print "\t[Reading] Skipping the file \"%s\" due to this file doesn't exist" % filename
788 self.set += 1
818 self.set += 1
789
819
790 if nFiles == (self.nFiles-1): #si no encuentro el file buscado cambio de carpeta y busco en la siguiente carpeta
820 if nFiles == (self.nFiles-1): #si no encuentro el file buscado cambio de carpeta y busco en la siguiente carpeta
791 self.set = 0
821 self.set = 0
792 self.doy += 1
822 self.doy += 1
793 self.foldercounter = 0
823 self.foldercounter = 0
794
824
795 if fileOk_flag:
825 if fileOk_flag:
796 self.fileSize = os.path.getsize( fullfilename )
826 self.fileSize = os.path.getsize( fullfilename )
797 self.filename = fullfilename
827 self.filename = fullfilename
798 self.flagIsNewFile = 1
828 self.flagIsNewFile = 1
799 if self.fp != None: self.fp.close()
829 if self.fp != None: self.fp.close()
800 self.fp = open(fullfilename, 'rb')
830 self.fp = open(fullfilename, 'rb')
801 self.flagNoMoreFiles = 0
831 self.flagNoMoreFiles = 0
802 # print '[Reading] Setting the file: %s' % fullfilename
832 # print '[Reading] Setting the file: %s' % fullfilename
803 else:
833 else:
804 self.fileSize = 0
834 self.fileSize = 0
805 self.filename = None
835 self.filename = None
806 self.flagIsNewFile = 0
836 self.flagIsNewFile = 0
807 self.fp = None
837 self.fp = None
808 self.flagNoMoreFiles = 1
838 self.flagNoMoreFiles = 1
809 # print '[Reading] No more files to read'
839 # print '[Reading] No more files to read'
810
840
811 return fileOk_flag
841 return fileOk_flag
812
842
813 def setNextFile(self):
843 def setNextFile(self):
814 if self.fp != None:
844 if self.fp != None:
815 self.fp.close()
845 self.fp.close()
816
846
817 if self.online:
847 if self.online:
818 newFile = self.__setNextFileOnline()
848 newFile = self.__setNextFileOnline()
819 else:
849 else:
820 newFile = self.__setNextFileOffline()
850 newFile = self.__setNextFileOffline()
821
851
822 if not(newFile):
852 if not(newFile):
823 print '[Reading] No more files to read'
853 print '[Reading] No more files to read'
824 return 0
854 return 0
825
855
826 print '[Reading] Setting the file: %s' % self.filename
856 print '[Reading] Setting the file: %s' % self.filename
827
857
828 self.__readFirstHeader()
858 self.__readFirstHeader()
829 self.nReadBlocks = 0
859 self.nReadBlocks = 0
830 return 1
860 return 1
831
861
832 def __waitNewBlock(self):
862 def __waitNewBlock(self):
833 """
863 """
834 Return 1 si se encontro un nuevo bloque de datos, 0 de otra forma.
864 Return 1 si se encontro un nuevo bloque de datos, 0 de otra forma.
835
865
836 Si el modo de lectura es OffLine siempre retorn 0
866 Si el modo de lectura es OffLine siempre retorn 0
837 """
867 """
838 if not self.online:
868 if not self.online:
839 return 0
869 return 0
840
870
841 if (self.nReadBlocks >= self.processingHeaderObj.dataBlocksPerFile):
871 if (self.nReadBlocks >= self.processingHeaderObj.dataBlocksPerFile):
842 return 0
872 return 0
843
873
844 currentPointer = self.fp.tell()
874 currentPointer = self.fp.tell()
845
875
846 neededSize = self.processingHeaderObj.blockSize + self.basicHeaderSize
876 neededSize = self.processingHeaderObj.blockSize + self.basicHeaderSize
847
877
848 for nTries in range( self.nTries ):
878 for nTries in range( self.nTries ):
849
879
850 self.fp.close()
880 self.fp.close()
851 self.fp = open( self.filename, 'rb' )
881 self.fp = open( self.filename, 'rb' )
852 self.fp.seek( currentPointer )
882 self.fp.seek( currentPointer )
853
883
854 self.fileSize = os.path.getsize( self.filename )
884 self.fileSize = os.path.getsize( self.filename )
855 currentSize = self.fileSize - currentPointer
885 currentSize = self.fileSize - currentPointer
856
886
857 if ( currentSize >= neededSize ):
887 if ( currentSize >= neededSize ):
858 self.basicHeaderObj.read(self.fp)
888 self.basicHeaderObj.read(self.fp)
859 return 1
889 return 1
860
890
861 if self.fileSize == self.fileSizeByHeader:
891 if self.fileSize == self.fileSizeByHeader:
862 # self.flagEoF = True
892 # self.flagEoF = True
863 return 0
893 return 0
864
894
865 print "[Reading] Waiting %0.2f seconds for the next block, try %03d ..." % (self.delay, nTries+1)
895 print "[Reading] Waiting %0.2f seconds for the next block, try %03d ..." % (self.delay, nTries+1)
866 sleep( self.delay )
896 sleep( self.delay )
867
897
868
898
869 return 0
899 return 0
870
900
871 def waitDataBlock(self,pointer_location):
901 def waitDataBlock(self,pointer_location):
872
902
873 currentPointer = pointer_location
903 currentPointer = pointer_location
874
904
875 neededSize = self.processingHeaderObj.blockSize #+ self.basicHeaderSize
905 neededSize = self.processingHeaderObj.blockSize #+ self.basicHeaderSize
876
906
877 for nTries in range( self.nTries ):
907 for nTries in range( self.nTries ):
878 self.fp.close()
908 self.fp.close()
879 self.fp = open( self.filename, 'rb' )
909 self.fp = open( self.filename, 'rb' )
880 self.fp.seek( currentPointer )
910 self.fp.seek( currentPointer )
881
911
882 self.fileSize = os.path.getsize( self.filename )
912 self.fileSize = os.path.getsize( self.filename )
883 currentSize = self.fileSize - currentPointer
913 currentSize = self.fileSize - currentPointer
884
914
885 if ( currentSize >= neededSize ):
915 if ( currentSize >= neededSize ):
886 return 1
916 return 1
887
917
888 print "[Reading] Waiting %0.2f seconds for the next block, try %03d ..." % (self.delay, nTries+1)
918 print "[Reading] Waiting %0.2f seconds for the next block, try %03d ..." % (self.delay, nTries+1)
889 sleep( self.delay )
919 sleep( self.delay )
890
920
891 return 0
921 return 0
892
922
893 def __jumpToLastBlock(self):
923 def __jumpToLastBlock(self):
894
924
895 if not(self.__isFirstTimeOnline):
925 if not(self.__isFirstTimeOnline):
896 return
926 return
897
927
898 csize = self.fileSize - self.fp.tell()
928 csize = self.fileSize - self.fp.tell()
899 blocksize = self.processingHeaderObj.blockSize
929 blocksize = self.processingHeaderObj.blockSize
900
930
901 #salta el primer bloque de datos
931 #salta el primer bloque de datos
902 if csize > self.processingHeaderObj.blockSize:
932 if csize > self.processingHeaderObj.blockSize:
903 self.fp.seek(self.fp.tell() + blocksize)
933 self.fp.seek(self.fp.tell() + blocksize)
904 else:
934 else:
905 return
935 return
906
936
907 csize = self.fileSize - self.fp.tell()
937 csize = self.fileSize - self.fp.tell()
908 neededsize = self.processingHeaderObj.blockSize + self.basicHeaderSize
938 neededsize = self.processingHeaderObj.blockSize + self.basicHeaderSize
909 while True:
939 while True:
910
940
911 if self.fp.tell()<self.fileSize:
941 if self.fp.tell()<self.fileSize:
912 self.fp.seek(self.fp.tell() + neededsize)
942 self.fp.seek(self.fp.tell() + neededsize)
913 else:
943 else:
914 self.fp.seek(self.fp.tell() - neededsize)
944 self.fp.seek(self.fp.tell() - neededsize)
915 break
945 break
916
946
917 # csize = self.fileSize - self.fp.tell()
947 # csize = self.fileSize - self.fp.tell()
918 # neededsize = self.processingHeaderObj.blockSize + self.basicHeaderSize
948 # neededsize = self.processingHeaderObj.blockSize + self.basicHeaderSize
919 # factor = int(csize/neededsize)
949 # factor = int(csize/neededsize)
920 # if factor > 0:
950 # if factor > 0:
921 # self.fp.seek(self.fp.tell() + factor*neededsize)
951 # self.fp.seek(self.fp.tell() + factor*neededsize)
922
952
923 self.flagIsNewFile = 0
953 self.flagIsNewFile = 0
924 self.__isFirstTimeOnline = 0
954 self.__isFirstTimeOnline = 0
925
955
926 def __setNewBlock(self):
956 def __setNewBlock(self):
927
957
928 if self.fp == None:
958 if self.fp == None:
929 return 0
959 return 0
930
960
931 # if self.online:
961 # if self.online:
932 # self.__jumpToLastBlock()
962 # self.__jumpToLastBlock()
933
963
934 if self.flagIsNewFile:
964 if self.flagIsNewFile:
935 self.lastUTTime = self.basicHeaderObj.utc
965 self.lastUTTime = self.basicHeaderObj.utc
936 return 1
966 return 1
937
967
938 if self.realtime:
968 if self.realtime:
939 self.flagDiscontinuousBlock = 1
969 self.flagDiscontinuousBlock = 1
940 if not(self.setNextFile()):
970 if not(self.setNextFile()):
941 return 0
971 return 0
942 else:
972 else:
943 return 1
973 return 1
944
974
945 currentSize = self.fileSize - self.fp.tell()
975 currentSize = self.fileSize - self.fp.tell()
946 neededSize = self.processingHeaderObj.blockSize + self.basicHeaderSize
976 neededSize = self.processingHeaderObj.blockSize + self.basicHeaderSize
947
977
948 if (currentSize >= neededSize):
978 if (currentSize >= neededSize):
949 self.basicHeaderObj.read(self.fp)
979 self.basicHeaderObj.read(self.fp)
950 self.lastUTTime = self.basicHeaderObj.utc
980 self.lastUTTime = self.basicHeaderObj.utc
951 return 1
981 return 1
952
982
953 if self.__waitNewBlock():
983 if self.__waitNewBlock():
954 self.lastUTTime = self.basicHeaderObj.utc
984 self.lastUTTime = self.basicHeaderObj.utc
955 return 1
985 return 1
956
986
957 if not(self.setNextFile()):
987 if not(self.setNextFile()):
958 return 0
988 return 0
959
989
960 deltaTime = self.basicHeaderObj.utc - self.lastUTTime #
990 deltaTime = self.basicHeaderObj.utc - self.lastUTTime #
961 self.lastUTTime = self.basicHeaderObj.utc
991 self.lastUTTime = self.basicHeaderObj.utc
962
992
963 self.flagDiscontinuousBlock = 0
993 self.flagDiscontinuousBlock = 0
964
994
965 if deltaTime > self.maxTimeStep:
995 if deltaTime > self.maxTimeStep:
966 self.flagDiscontinuousBlock = 1
996 self.flagDiscontinuousBlock = 1
967
997
968 return 1
998 return 1
969
999
970 def readNextBlock(self):
1000 def readNextBlock(self):
971
1001
972 if not(self.__setNewBlock()):
1002 #Skip block out of startTime and endTime
973 return 0
1003 while True:
974
1004 if not(self.__setNewBlock()):
975 if not(self.readBlock()):
1005 return 0
976 return 0
1006
1007 if not(self.readBlock()):
1008 return 0
1009
1010 self.getBasicHeader()
977
1011
978 self.getBasicHeader()
1012 if not isTimeInRange(self.dataOut.datatime.time(), self.startTime, self.endTime):
1013
1014 print "[Reading] Block No. %d/%d -> %s [Skipping]" %(self.nReadBlocks,
1015 self.processingHeaderObj.dataBlocksPerFile,
1016 self.dataOut.datatime.ctime())
1017 continue
1018
1019 break
979
1020
980 print "[Reading] Block No. %d/%d -> %s" %(self.nReadBlocks,
1021 print "[Reading] Block No. %d/%d -> %s" %(self.nReadBlocks,
981 self.processingHeaderObj.dataBlocksPerFile,
1022 self.processingHeaderObj.dataBlocksPerFile,
982 self.dataOut.datatime.ctime())
1023 self.dataOut.datatime.ctime())
983 return 1
1024 return 1
984
1025
985 def __readFirstHeader(self):
1026 def __readFirstHeader(self):
986
1027
987 self.basicHeaderObj.read(self.fp)
1028 self.basicHeaderObj.read(self.fp)
988 self.systemHeaderObj.read(self.fp)
1029 self.systemHeaderObj.read(self.fp)
989 self.radarControllerHeaderObj.read(self.fp)
1030 self.radarControllerHeaderObj.read(self.fp)
990 self.processingHeaderObj.read(self.fp)
1031 self.processingHeaderObj.read(self.fp)
991
1032
992 self.firstHeaderSize = self.basicHeaderObj.size
1033 self.firstHeaderSize = self.basicHeaderObj.size
993
1034
994 datatype = int(numpy.log2((self.processingHeaderObj.processFlags & PROCFLAG.DATATYPE_MASK))-numpy.log2(PROCFLAG.DATATYPE_CHAR))
1035 datatype = int(numpy.log2((self.processingHeaderObj.processFlags & PROCFLAG.DATATYPE_MASK))-numpy.log2(PROCFLAG.DATATYPE_CHAR))
995 if datatype == 0:
1036 if datatype == 0:
996 datatype_str = numpy.dtype([('real','<i1'),('imag','<i1')])
1037 datatype_str = numpy.dtype([('real','<i1'),('imag','<i1')])
997 elif datatype == 1:
1038 elif datatype == 1:
998 datatype_str = numpy.dtype([('real','<i2'),('imag','<i2')])
1039 datatype_str = numpy.dtype([('real','<i2'),('imag','<i2')])
999 elif datatype == 2:
1040 elif datatype == 2:
1000 datatype_str = numpy.dtype([('real','<i4'),('imag','<i4')])
1041 datatype_str = numpy.dtype([('real','<i4'),('imag','<i4')])
1001 elif datatype == 3:
1042 elif datatype == 3:
1002 datatype_str = numpy.dtype([('real','<i8'),('imag','<i8')])
1043 datatype_str = numpy.dtype([('real','<i8'),('imag','<i8')])
1003 elif datatype == 4:
1044 elif datatype == 4:
1004 datatype_str = numpy.dtype([('real','<f4'),('imag','<f4')])
1045 datatype_str = numpy.dtype([('real','<f4'),('imag','<f4')])
1005 elif datatype == 5:
1046 elif datatype == 5:
1006 datatype_str = numpy.dtype([('real','<f8'),('imag','<f8')])
1047 datatype_str = numpy.dtype([('real','<f8'),('imag','<f8')])
1007 else:
1048 else:
1008 raise ValueError, 'Data type was not defined'
1049 raise ValueError, 'Data type was not defined'
1009
1050
1010 self.dtype = datatype_str
1051 self.dtype = datatype_str
1011 #self.ippSeconds = 2 * 1000 * self.radarControllerHeaderObj.ipp / self.c
1052 #self.ippSeconds = 2 * 1000 * self.radarControllerHeaderObj.ipp / self.c
1012 self.fileSizeByHeader = self.processingHeaderObj.dataBlocksPerFile * self.processingHeaderObj.blockSize + self.firstHeaderSize + self.basicHeaderSize*(self.processingHeaderObj.dataBlocksPerFile - 1)
1053 self.fileSizeByHeader = self.processingHeaderObj.dataBlocksPerFile * self.processingHeaderObj.blockSize + self.firstHeaderSize + self.basicHeaderSize*(self.processingHeaderObj.dataBlocksPerFile - 1)
1013 # self.dataOut.channelList = numpy.arange(self.systemHeaderObj.numChannels)
1054 # self.dataOut.channelList = numpy.arange(self.systemHeaderObj.numChannels)
1014 # self.dataOut.channelIndexList = numpy.arange(self.systemHeaderObj.numChannels)
1055 # self.dataOut.channelIndexList = numpy.arange(self.systemHeaderObj.numChannels)
1015 self.getBlockDimension()
1056 self.getBlockDimension()
1016
1057
1017 def __verifyFile(self, filename, msgFlag=True):
1058 def __verifyFile(self, filename, msgFlag=True):
1018
1059
1019 msg = None
1060 msg = None
1020
1061
1021 try:
1062 try:
1022 fp = open(filename, 'rb')
1063 fp = open(filename, 'rb')
1023 except IOError:
1064 except IOError:
1024
1065
1025 if msgFlag:
1066 if msgFlag:
1026 print "[Reading] File %s can't be opened" % (filename)
1067 print "[Reading] File %s can't be opened" % (filename)
1027
1068
1028 return False
1069 return False
1029
1070
1030 currentPosition = fp.tell()
1071 currentPosition = fp.tell()
1031 neededSize = self.processingHeaderObj.blockSize + self.firstHeaderSize
1072 neededSize = self.processingHeaderObj.blockSize + self.firstHeaderSize
1032
1073
1033 if neededSize == 0:
1074 if neededSize == 0:
1034 basicHeaderObj = BasicHeader(LOCALTIME)
1075 basicHeaderObj = BasicHeader(LOCALTIME)
1035 systemHeaderObj = SystemHeader()
1076 systemHeaderObj = SystemHeader()
1036 radarControllerHeaderObj = RadarControllerHeader()
1077 radarControllerHeaderObj = RadarControllerHeader()
1037 processingHeaderObj = ProcessingHeader()
1078 processingHeaderObj = ProcessingHeader()
1038
1079
1039 if not( basicHeaderObj.read(fp) ):
1080 if not( basicHeaderObj.read(fp) ):
1040 fp.close()
1081 fp.close()
1041 return False
1082 return False
1042
1083
1043 if not( systemHeaderObj.read(fp) ):
1084 if not( systemHeaderObj.read(fp) ):
1044 fp.close()
1085 fp.close()
1045 return False
1086 return False
1046
1087
1047 if not( radarControllerHeaderObj.read(fp) ):
1088 if not( radarControllerHeaderObj.read(fp) ):
1048 fp.close()
1089 fp.close()
1049 return False
1090 return False
1050
1091
1051 if not( processingHeaderObj.read(fp) ):
1092 if not( processingHeaderObj.read(fp) ):
1052 fp.close()
1093 fp.close()
1053 return False
1094 return False
1054
1095
1055 neededSize = processingHeaderObj.blockSize + basicHeaderObj.size
1096 neededSize = processingHeaderObj.blockSize + basicHeaderObj.size
1056 else:
1097 else:
1057 msg = "[Reading] Skipping the file %s due to it hasn't enough data" %filename
1098 msg = "[Reading] Skipping the file %s due to it hasn't enough data" %filename
1058
1099
1059 fp.close()
1100 fp.close()
1060
1101
1061 fileSize = os.path.getsize(filename)
1102 fileSize = os.path.getsize(filename)
1062 currentSize = fileSize - currentPosition
1103 currentSize = fileSize - currentPosition
1063
1104
1064 if currentSize < neededSize:
1105 if currentSize < neededSize:
1065 if msgFlag and (msg != None):
1106 if msgFlag and (msg != None):
1066 print msg
1107 print msg
1067 return False
1108 return False
1068
1109
1069 return True
1110 return True
1070
1111
1071 def findDatafiles(self, path, startDate=None, endDate=None, expLabel='', ext='.r', walk=True, include_path=False):
1112 def findDatafiles(self, path, startDate=None, endDate=None, expLabel='', ext='.r', walk=True, include_path=False):
1072
1113
1114 path_empty = True
1115
1073 dateList = []
1116 dateList = []
1074 pathList = []
1117 pathList = []
1075
1118
1076 multi_path = path.split(',')
1119 multi_path = path.split(',')
1077
1120
1078 if not walk:
1121 if not walk:
1079
1122
1080 for single_path in multi_path:
1123 for single_path in multi_path:
1081
1124
1082 if not os.path.isdir(single_path):
1125 if not os.path.isdir(single_path):
1083 continue
1126 continue
1084
1127
1085 fileList = glob.glob1(single_path, "*"+ext)
1128 fileList = glob.glob1(single_path, "*"+ext)
1086
1129
1087 if not fileList:
1130 if not fileList:
1088 continue
1131 continue
1089
1132
1133 path_empty = False
1134
1090 fileList.sort()
1135 fileList.sort()
1091
1136
1092 for thisFile in fileList:
1137 for thisFile in fileList:
1093
1138
1094 if not os.path.isfile(os.path.join(single_path, thisFile)):
1139 if not os.path.isfile(os.path.join(single_path, thisFile)):
1095 continue
1140 continue
1096
1141
1097 if not isRadarFile(thisFile):
1142 if not isRadarFile(thisFile):
1098 continue
1143 continue
1099
1144
1100 if not isFileInDateRange(thisFile, startDate, endDate):
1145 if not isFileInDateRange(thisFile, startDate, endDate):
1101 continue
1146 continue
1102
1147
1103 thisDate = getDateFromRadarFile(thisFile)
1148 thisDate = getDateFromRadarFile(thisFile)
1104
1149
1105 if thisDate in dateList:
1150 if thisDate in dateList:
1106 continue
1151 continue
1107
1152
1108 dateList.append(thisDate)
1153 dateList.append(thisDate)
1109 pathList.append(single_path)
1154 pathList.append(single_path)
1110
1155
1111 else:
1156 else:
1112 for single_path in multi_path:
1157 for single_path in multi_path:
1113
1158
1114 if not os.path.isdir(single_path):
1159 if not os.path.isdir(single_path):
1115 continue
1160 continue
1116
1161
1117 dirList = []
1162 dirList = []
1118
1163
1119 for thisPath in os.listdir(single_path):
1164 for thisPath in os.listdir(single_path):
1120
1165
1121 if not os.path.isdir(os.path.join(single_path,thisPath)):
1166 if not os.path.isdir(os.path.join(single_path,thisPath)):
1122 continue
1167 continue
1123
1168
1124 if not isRadarFolder(thisPath):
1169 if not isRadarFolder(thisPath):
1125 continue
1170 continue
1126
1171
1127 if not isFolderInDateRange(thisPath, startDate, endDate):
1172 if not isFolderInDateRange(thisPath, startDate, endDate):
1128 continue
1173 continue
1129
1174
1130 dirList.append(thisPath)
1175 dirList.append(thisPath)
1131
1176
1132 if not dirList:
1177 if not dirList:
1133 continue
1178 continue
1134
1179
1135 dirList.sort()
1180 dirList.sort()
1136
1181
1137 for thisDir in dirList:
1182 for thisDir in dirList:
1138
1183
1139 datapath = os.path.join(single_path, thisDir, expLabel)
1184 datapath = os.path.join(single_path, thisDir, expLabel)
1140 fileList = glob.glob1(datapath, "*"+ext)
1185 fileList = glob.glob1(datapath, "*"+ext)
1141
1186
1142 if len(fileList) < 1:
1187 if not fileList:
1143 continue
1188 continue
1144
1189
1190 path_empty = False
1191
1145 thisDate = getDateFromRadarFolder(thisDir)
1192 thisDate = getDateFromRadarFolder(thisDir)
1146
1193
1147 pathList.append(datapath)
1194 pathList.append(datapath)
1148 dateList.append(thisDate)
1195 dateList.append(thisDate)
1149
1196
1150 dateList.sort()
1197 dateList.sort()
1151
1198
1152 if walk:
1199 if walk:
1153 pattern_path = os.path.join(multi_path[0], "[dYYYYDDD]", expLabel)
1200 pattern_path = os.path.join(multi_path[0], "[dYYYYDDD]", expLabel)
1154 else:
1201 else:
1155 pattern_path = multi_path[0]
1202 pattern_path = multi_path[0]
1156
1203
1157 if not dateList:
1204 if path_empty:
1158 print "[Reading] No *%s files in %s from %s to %s" %(ext, pattern_path, startDate, endDate)
1205 print "[Reading] No *%s files in %s for %s to %s" %(ext, pattern_path, startDate, endDate)
1159
1206 else:
1207 if not dateList:
1208 print "[Reading] Date range selected invalid [%s - %s]: No *%s files in %s)" %(startDate, endDate, ext, path)
1209
1160 if include_path:
1210 if include_path:
1161 return dateList, pathList
1211 return dateList, pathList
1162
1212
1163 return dateList
1213 return dateList
1164
1214
1165 def setup(self,
1215 def setup(self,
1166 path=None,
1216 path=None,
1167 startDate=None,
1217 startDate=None,
1168 endDate=None,
1218 endDate=None,
1169 startTime=datetime.time(0,0,0),
1219 startTime=datetime.time(0,0,0),
1170 endTime=datetime.time(23,59,59),
1220 endTime=datetime.time(23,59,59),
1171 set=None,
1221 set=None,
1172 expLabel = "",
1222 expLabel = "",
1173 ext = None,
1223 ext = None,
1174 online = False,
1224 online = False,
1175 delay = 60,
1225 delay = 60,
1176 walk = True,
1226 walk = True,
1177 getblock = False,
1227 getblock = False,
1178 nTxs = 1,
1228 nTxs = 1,
1179 realtime=False):
1229 realtime=False):
1180
1230
1181 if path == None:
1231 if path == None:
1182 raise ValueError, "[Reading] The path is not valid"
1232 raise ValueError, "[Reading] The path is not valid"
1183
1233
1184 if ext == None:
1234 if ext == None:
1185 ext = self.ext
1235 ext = self.ext
1186
1236
1187 if online:
1237 if online:
1188 print "[Reading] Searching files in online mode..."
1238 print "[Reading] Searching files in online mode..."
1189
1239
1190 for nTries in range( self.nTries ):
1240 for nTries in range( self.nTries ):
1191 fullpath, foldercounter, file, year, doy, set = self.__searchFilesOnLine(path=path, expLabel=expLabel, ext=ext, walk=walk, set=set)
1241 fullpath, foldercounter, file, year, doy, set = self.__searchFilesOnLine(path=path, expLabel=expLabel, ext=ext, walk=walk, set=set)
1192
1242
1193 if fullpath:
1243 if fullpath:
1194 break
1244 break
1195
1245
1196 print '[Reading] Waiting %0.2f sec for an valid file in %s: try %02d ...' % (self.delay, path, nTries+1)
1246 print '[Reading] Waiting %0.2f sec for an valid file in %s: try %02d ...' % (self.delay, path, nTries+1)
1197 sleep( self.delay )
1247 sleep( self.delay )
1198
1248
1199 if not(fullpath):
1249 if not(fullpath):
1200 print "[Reading] There 'isn't any valid file in %s" % path
1250 print "[Reading] There 'isn't any valid file in %s" % path
1201 return
1251 return
1202
1252
1203 self.year = year
1253 self.year = year
1204 self.doy = doy
1254 self.doy = doy
1205 self.set = set - 1
1255 self.set = set - 1
1206 self.path = path
1256 self.path = path
1207 self.foldercounter = foldercounter
1257 self.foldercounter = foldercounter
1208 last_set = None
1258 last_set = None
1209
1259
1210 else:
1260 else:
1211 print "[Reading] Searching files in offline mode ..."
1261 print "[Reading] Searching files in offline mode ..."
1212 pathList, filenameList = self.__searchFilesOffLine(path, startDate=startDate, endDate=endDate,
1262 pathList, filenameList = self.__searchFilesOffLine(path, startDate=startDate, endDate=endDate,
1213 startTime=startTime, endTime=endTime,
1263 startTime=startTime, endTime=endTime,
1214 set=set, expLabel=expLabel, ext=ext,
1264 set=set, expLabel=expLabel, ext=ext,
1215 walk=walk)
1265 walk=walk)
1216
1266
1217 if not(pathList):
1267 if not(pathList):
1218 # print "[Reading] No *%s files in %s (%s - %s)"%(ext, path,
1268 # print "[Reading] No *%s files in %s (%s - %s)"%(ext, path,
1219 # datetime.datetime.combine(startDate,startTime).ctime(),
1269 # datetime.datetime.combine(startDate,startTime).ctime(),
1220 # datetime.datetime.combine(endDate,endTime).ctime())
1270 # datetime.datetime.combine(endDate,endTime).ctime())
1221
1271
1222 # sys.exit(-1)
1272 # sys.exit(-1)
1223
1273
1224 self.fileIndex = -1
1274 self.fileIndex = -1
1225 self.pathList = []
1275 self.pathList = []
1226 self.filenameList = []
1276 self.filenameList = []
1227 return
1277 return
1228
1278
1229 self.fileIndex = -1
1279 self.fileIndex = -1
1230 self.pathList = pathList
1280 self.pathList = pathList
1231 self.filenameList = filenameList
1281 self.filenameList = filenameList
1232 file_name = os.path.basename(filenameList[-1])
1282 file_name = os.path.basename(filenameList[-1])
1233 basename, ext = os.path.splitext(file_name)
1283 basename, ext = os.path.splitext(file_name)
1234 last_set = int(basename[-3:])
1284 last_set = int(basename[-3:])
1235
1285
1236 self.online = online
1286 self.online = online
1237 self.realtime = realtime
1287 self.realtime = realtime
1238 self.delay = delay
1288 self.delay = delay
1239 ext = ext.lower()
1289 ext = ext.lower()
1240 self.ext = ext
1290 self.ext = ext
1241 self.getByBlock = getblock
1291 self.getByBlock = getblock
1242 self.nTxs = nTxs
1292 self.nTxs = nTxs
1293 self.startTime = startTime
1294 self.endTime = endTime
1243
1295
1244 if not(self.setNextFile()):
1296 if not(self.setNextFile()):
1245 if (startDate!=None) and (endDate!=None):
1297 if (startDate!=None) and (endDate!=None):
1246 print "[Reading] No files in range: %s - %s" %(datetime.datetime.combine(startDate,startTime).ctime(), datetime.datetime.combine(endDate,endTime).ctime())
1298 print "[Reading] No files in range: %s - %s" %(datetime.datetime.combine(startDate,startTime).ctime(), datetime.datetime.combine(endDate,endTime).ctime())
1247 elif startDate != None:
1299 elif startDate != None:
1248 print "[Reading] No files in range: %s" %(datetime.datetime.combine(startDate,startTime).ctime())
1300 print "[Reading] No files in range: %s" %(datetime.datetime.combine(startDate,startTime).ctime())
1249 else:
1301 else:
1250 print "[Reading] No files"
1302 print "[Reading] No files"
1251
1303
1252 self.fileIndex = -1
1304 self.fileIndex = -1
1253 self.pathList = []
1305 self.pathList = []
1254 self.filenameList = []
1306 self.filenameList = []
1255 return
1307 return
1256
1308
1257 # self.getBasicHeader()
1309 # self.getBasicHeader()
1258
1310
1259 if last_set != None:
1311 if last_set != None:
1260 self.dataOut.last_block = last_set * self.processingHeaderObj.dataBlocksPerFile + self.basicHeaderObj.dataBlock
1312 self.dataOut.last_block = last_set * self.processingHeaderObj.dataBlocksPerFile + self.basicHeaderObj.dataBlock
1261 return
1313 return
1262
1314
1263 def getBasicHeader(self):
1315 def getBasicHeader(self):
1264
1316
1265 self.dataOut.utctime = self.basicHeaderObj.utc + self.basicHeaderObj.miliSecond/1000. + self.profileIndex * self.radarControllerHeaderObj.ippSeconds
1317 self.dataOut.utctime = self.basicHeaderObj.utc + self.basicHeaderObj.miliSecond/1000. + self.profileIndex * self.radarControllerHeaderObj.ippSeconds
1266
1318
1267 self.dataOut.flagDiscontinuousBlock = self.flagDiscontinuousBlock
1319 self.dataOut.flagDiscontinuousBlock = self.flagDiscontinuousBlock
1268
1320
1269 self.dataOut.timeZone = self.basicHeaderObj.timeZone
1321 self.dataOut.timeZone = self.basicHeaderObj.timeZone
1270
1322
1271 self.dataOut.dstFlag = self.basicHeaderObj.dstFlag
1323 self.dataOut.dstFlag = self.basicHeaderObj.dstFlag
1272
1324
1273 self.dataOut.errorCount = self.basicHeaderObj.errorCount
1325 self.dataOut.errorCount = self.basicHeaderObj.errorCount
1274
1326
1275 self.dataOut.useLocalTime = self.basicHeaderObj.useLocalTime
1327 self.dataOut.useLocalTime = self.basicHeaderObj.useLocalTime
1276
1328
1277 self.dataOut.ippSeconds = self.radarControllerHeaderObj.ippSeconds/self.nTxs
1329 self.dataOut.ippSeconds = self.radarControllerHeaderObj.ippSeconds/self.nTxs
1278
1330
1279 self.dataOut.nProfiles = self.processingHeaderObj.profilesPerBlock*self.nTxs
1331 self.dataOut.nProfiles = self.processingHeaderObj.profilesPerBlock*self.nTxs
1280
1332
1281
1333
1282 def getFirstHeader(self):
1334 def getFirstHeader(self):
1283
1335
1284 raise NotImplementedError
1336 raise NotImplementedError
1285
1337
1286 def getData(self):
1338 def getData(self):
1287
1339
1288 raise NotImplementedError
1340 raise NotImplementedError
1289
1341
1290 def hasNotDataInBuffer(self):
1342 def hasNotDataInBuffer(self):
1291
1343
1292 raise NotImplementedError
1344 raise NotImplementedError
1293
1345
1294 def readBlock(self):
1346 def readBlock(self):
1295
1347
1296 raise NotImplementedError
1348 raise NotImplementedError
1297
1349
1298 def isEndProcess(self):
1350 def isEndProcess(self):
1299
1351
1300 return self.flagNoMoreFiles
1352 return self.flagNoMoreFiles
1301
1353
1302 def printReadBlocks(self):
1354 def printReadBlocks(self):
1303
1355
1304 print "[Reading] Number of read blocks per file %04d" %self.nReadBlocks
1356 print "[Reading] Number of read blocks per file %04d" %self.nReadBlocks
1305
1357
1306 def printTotalBlocks(self):
1358 def printTotalBlocks(self):
1307
1359
1308 print "[Reading] Number of read blocks %04d" %self.nTotalBlocks
1360 print "[Reading] Number of read blocks %04d" %self.nTotalBlocks
1309
1361
1310 def printNumberOfBlock(self):
1362 def printNumberOfBlock(self):
1311
1363
1312 if self.flagIsNewBlock:
1364 if self.flagIsNewBlock:
1313 print "[Reading] Block No. %d/%d -> %s" %(self.nReadBlocks,
1365 print "[Reading] Block No. %d/%d -> %s" %(self.nReadBlocks,
1314 self.processingHeaderObj.dataBlocksPerFile,
1366 self.processingHeaderObj.dataBlocksPerFile,
1315 self.dataOut.datatime.ctime())
1367 self.dataOut.datatime.ctime())
1316
1368
1317 def printInfo(self):
1369 def printInfo(self):
1318
1370
1319 if self.__printInfo == False:
1371 if self.__printInfo == False:
1320 return
1372 return
1321
1373
1322 self.basicHeaderObj.printInfo()
1374 self.basicHeaderObj.printInfo()
1323 self.systemHeaderObj.printInfo()
1375 self.systemHeaderObj.printInfo()
1324 self.radarControllerHeaderObj.printInfo()
1376 self.radarControllerHeaderObj.printInfo()
1325 self.processingHeaderObj.printInfo()
1377 self.processingHeaderObj.printInfo()
1326
1378
1327 self.__printInfo = False
1379 self.__printInfo = False
1328
1380
1329
1381
1330 def run(self, **kwargs):
1382 def run(self, **kwargs):
1331
1383
1332 if not(self.isConfig):
1384 if not(self.isConfig):
1333
1385
1334 # self.dataOut = dataOut
1386 # self.dataOut = dataOut
1335 self.setup(**kwargs)
1387 self.setup(**kwargs)
1336 self.isConfig = True
1388 self.isConfig = True
1337
1389
1338 self.getData()
1390 self.getData()
1339
1391
1340 class JRODataWriter(JRODataIO):
1392 class JRODataWriter(JRODataIO):
1341
1393
1342 """
1394 """
1343 Esta clase permite escribir datos a archivos procesados (.r o ,pdata). La escritura
1395 Esta clase permite escribir datos a archivos procesados (.r o ,pdata). La escritura
1344 de los datos siempre se realiza por bloques.
1396 de los datos siempre se realiza por bloques.
1345 """
1397 """
1346
1398
1347 blockIndex = 0
1399 blockIndex = 0
1348
1400
1349 path = None
1401 path = None
1350
1402
1351 setFile = None
1403 setFile = None
1352
1404
1353 profilesPerBlock = None
1405 profilesPerBlock = None
1354
1406
1355 blocksPerFile = None
1407 blocksPerFile = None
1356
1408
1357 nWriteBlocks = 0
1409 nWriteBlocks = 0
1358
1410
1359 fileDate = None
1411 fileDate = None
1360
1412
1361 def __init__(self, dataOut=None):
1413 def __init__(self, dataOut=None):
1362 raise NotImplementedError
1414 raise NotImplementedError
1363
1415
1364
1416
1365 def hasAllDataInBuffer(self):
1417 def hasAllDataInBuffer(self):
1366 raise NotImplementedError
1418 raise NotImplementedError
1367
1419
1368
1420
1369 def setBlockDimension(self):
1421 def setBlockDimension(self):
1370 raise NotImplementedError
1422 raise NotImplementedError
1371
1423
1372
1424
1373 def writeBlock(self):
1425 def writeBlock(self):
1374 raise NotImplementedError
1426 raise NotImplementedError
1375
1427
1376
1428
1377 def putData(self):
1429 def putData(self):
1378 raise NotImplementedError
1430 raise NotImplementedError
1379
1431
1380
1432
1381 def getProcessFlags(self):
1433 def getProcessFlags(self):
1382
1434
1383 processFlags = 0
1435 processFlags = 0
1384
1436
1385 dtype_index = get_dtype_index(self.dtype)
1437 dtype_index = get_dtype_index(self.dtype)
1386 procflag_dtype = get_procflag_dtype(dtype_index)
1438 procflag_dtype = get_procflag_dtype(dtype_index)
1387
1439
1388 processFlags += procflag_dtype
1440 processFlags += procflag_dtype
1389
1441
1390 if self.dataOut.flagDecodeData:
1442 if self.dataOut.flagDecodeData:
1391 processFlags += PROCFLAG.DECODE_DATA
1443 processFlags += PROCFLAG.DECODE_DATA
1392
1444
1393 if self.dataOut.flagDeflipData:
1445 if self.dataOut.flagDeflipData:
1394 processFlags += PROCFLAG.DEFLIP_DATA
1446 processFlags += PROCFLAG.DEFLIP_DATA
1395
1447
1396 if self.dataOut.code is not None:
1448 if self.dataOut.code is not None:
1397 processFlags += PROCFLAG.DEFINE_PROCESS_CODE
1449 processFlags += PROCFLAG.DEFINE_PROCESS_CODE
1398
1450
1399 if self.dataOut.nCohInt > 1:
1451 if self.dataOut.nCohInt > 1:
1400 processFlags += PROCFLAG.COHERENT_INTEGRATION
1452 processFlags += PROCFLAG.COHERENT_INTEGRATION
1401
1453
1402 if self.dataOut.type == "Spectra":
1454 if self.dataOut.type == "Spectra":
1403 if self.dataOut.nIncohInt > 1:
1455 if self.dataOut.nIncohInt > 1:
1404 processFlags += PROCFLAG.INCOHERENT_INTEGRATION
1456 processFlags += PROCFLAG.INCOHERENT_INTEGRATION
1405
1457
1406 if self.dataOut.data_dc is not None:
1458 if self.dataOut.data_dc is not None:
1407 processFlags += PROCFLAG.SAVE_CHANNELS_DC
1459 processFlags += PROCFLAG.SAVE_CHANNELS_DC
1408
1460
1409 if self.dataOut.flagShiftFFT:
1461 if self.dataOut.flagShiftFFT:
1410 processFlags += PROCFLAG.SHIFT_FFT_DATA
1462 processFlags += PROCFLAG.SHIFT_FFT_DATA
1411
1463
1412 return processFlags
1464 return processFlags
1413
1465
1414 def setBasicHeader(self):
1466 def setBasicHeader(self):
1415
1467
1416 self.basicHeaderObj.size = self.basicHeaderSize #bytes
1468 self.basicHeaderObj.size = self.basicHeaderSize #bytes
1417 self.basicHeaderObj.version = self.versionFile
1469 self.basicHeaderObj.version = self.versionFile
1418 self.basicHeaderObj.dataBlock = self.nTotalBlocks
1470 self.basicHeaderObj.dataBlock = self.nTotalBlocks
1419
1471
1420 utc = numpy.floor(self.dataOut.utctime)
1472 utc = numpy.floor(self.dataOut.utctime)
1421 milisecond = (self.dataOut.utctime - utc)* 1000.0
1473 milisecond = (self.dataOut.utctime - utc)* 1000.0
1422
1474
1423 self.basicHeaderObj.utc = utc
1475 self.basicHeaderObj.utc = utc
1424 self.basicHeaderObj.miliSecond = milisecond
1476 self.basicHeaderObj.miliSecond = milisecond
1425 self.basicHeaderObj.timeZone = self.dataOut.timeZone
1477 self.basicHeaderObj.timeZone = self.dataOut.timeZone
1426 self.basicHeaderObj.dstFlag = self.dataOut.dstFlag
1478 self.basicHeaderObj.dstFlag = self.dataOut.dstFlag
1427 self.basicHeaderObj.errorCount = self.dataOut.errorCount
1479 self.basicHeaderObj.errorCount = self.dataOut.errorCount
1428
1480
1429 def setFirstHeader(self):
1481 def setFirstHeader(self):
1430 """
1482 """
1431 Obtiene una copia del First Header
1483 Obtiene una copia del First Header
1432
1484
1433 Affected:
1485 Affected:
1434
1486
1435 self.basicHeaderObj
1487 self.basicHeaderObj
1436 self.systemHeaderObj
1488 self.systemHeaderObj
1437 self.radarControllerHeaderObj
1489 self.radarControllerHeaderObj
1438 self.processingHeaderObj self.
1490 self.processingHeaderObj self.
1439
1491
1440 Return:
1492 Return:
1441 None
1493 None
1442 """
1494 """
1443
1495
1444 raise NotImplementedError
1496 raise NotImplementedError
1445
1497
1446 def __writeFirstHeader(self):
1498 def __writeFirstHeader(self):
1447 """
1499 """
1448 Escribe el primer header del file es decir el Basic header y el Long header (SystemHeader, RadarControllerHeader, ProcessingHeader)
1500 Escribe el primer header del file es decir el Basic header y el Long header (SystemHeader, RadarControllerHeader, ProcessingHeader)
1449
1501
1450 Affected:
1502 Affected:
1451 __dataType
1503 __dataType
1452
1504
1453 Return:
1505 Return:
1454 None
1506 None
1455 """
1507 """
1456
1508
1457 # CALCULAR PARAMETROS
1509 # CALCULAR PARAMETROS
1458
1510
1459 sizeLongHeader = self.systemHeaderObj.size + self.radarControllerHeaderObj.size + self.processingHeaderObj.size
1511 sizeLongHeader = self.systemHeaderObj.size + self.radarControllerHeaderObj.size + self.processingHeaderObj.size
1460 self.basicHeaderObj.size = self.basicHeaderSize + sizeLongHeader
1512 self.basicHeaderObj.size = self.basicHeaderSize + sizeLongHeader
1461
1513
1462 self.basicHeaderObj.write(self.fp)
1514 self.basicHeaderObj.write(self.fp)
1463 self.systemHeaderObj.write(self.fp)
1515 self.systemHeaderObj.write(self.fp)
1464 self.radarControllerHeaderObj.write(self.fp)
1516 self.radarControllerHeaderObj.write(self.fp)
1465 self.processingHeaderObj.write(self.fp)
1517 self.processingHeaderObj.write(self.fp)
1466
1518
1467 def __setNewBlock(self):
1519 def __setNewBlock(self):
1468 """
1520 """
1469 Si es un nuevo file escribe el First Header caso contrario escribe solo el Basic Header
1521 Si es un nuevo file escribe el First Header caso contrario escribe solo el Basic Header
1470
1522
1471 Return:
1523 Return:
1472 0 : si no pudo escribir nada
1524 0 : si no pudo escribir nada
1473 1 : Si escribio el Basic el First Header
1525 1 : Si escribio el Basic el First Header
1474 """
1526 """
1475 if self.fp == None:
1527 if self.fp == None:
1476 self.setNextFile()
1528 self.setNextFile()
1477
1529
1478 if self.flagIsNewFile:
1530 if self.flagIsNewFile:
1479 return 1
1531 return 1
1480
1532
1481 if self.blockIndex < self.processingHeaderObj.dataBlocksPerFile:
1533 if self.blockIndex < self.processingHeaderObj.dataBlocksPerFile:
1482 self.basicHeaderObj.write(self.fp)
1534 self.basicHeaderObj.write(self.fp)
1483 return 1
1535 return 1
1484
1536
1485 if not( self.setNextFile() ):
1537 if not( self.setNextFile() ):
1486 return 0
1538 return 0
1487
1539
1488 return 1
1540 return 1
1489
1541
1490
1542
1491 def writeNextBlock(self):
1543 def writeNextBlock(self):
1492 """
1544 """
1493 Selecciona el bloque siguiente de datos y los escribe en un file
1545 Selecciona el bloque siguiente de datos y los escribe en un file
1494
1546
1495 Return:
1547 Return:
1496 0 : Si no hizo pudo escribir el bloque de datos
1548 0 : Si no hizo pudo escribir el bloque de datos
1497 1 : Si no pudo escribir el bloque de datos
1549 1 : Si no pudo escribir el bloque de datos
1498 """
1550 """
1499 if not( self.__setNewBlock() ):
1551 if not( self.__setNewBlock() ):
1500 return 0
1552 return 0
1501
1553
1502 self.writeBlock()
1554 self.writeBlock()
1503
1555
1504 print "[Writing] Block No. %d/%d" %(self.blockIndex,
1556 print "[Writing] Block No. %d/%d" %(self.blockIndex,
1505 self.processingHeaderObj.dataBlocksPerFile)
1557 self.processingHeaderObj.dataBlocksPerFile)
1506
1558
1507 return 1
1559 return 1
1508
1560
1509 def setNextFile(self):
1561 def setNextFile(self):
1510 """
1562 """
1511 Determina el siguiente file que sera escrito
1563 Determina el siguiente file que sera escrito
1512
1564
1513 Affected:
1565 Affected:
1514 self.filename
1566 self.filename
1515 self.subfolder
1567 self.subfolder
1516 self.fp
1568 self.fp
1517 self.setFile
1569 self.setFile
1518 self.flagIsNewFile
1570 self.flagIsNewFile
1519
1571
1520 Return:
1572 Return:
1521 0 : Si el archivo no puede ser escrito
1573 0 : Si el archivo no puede ser escrito
1522 1 : Si el archivo esta listo para ser escrito
1574 1 : Si el archivo esta listo para ser escrito
1523 """
1575 """
1524 ext = self.ext
1576 ext = self.ext
1525 path = self.path
1577 path = self.path
1526
1578
1527 if self.fp != None:
1579 if self.fp != None:
1528 self.fp.close()
1580 self.fp.close()
1529
1581
1530 timeTuple = time.localtime( self.dataOut.utctime)
1582 timeTuple = time.localtime( self.dataOut.utctime)
1531 subfolder = 'd%4.4d%3.3d' % (timeTuple.tm_year,timeTuple.tm_yday)
1583 subfolder = 'd%4.4d%3.3d' % (timeTuple.tm_year,timeTuple.tm_yday)
1532
1584
1533 fullpath = os.path.join( path, subfolder )
1585 fullpath = os.path.join( path, subfolder )
1534 setFile = self.setFile
1586 setFile = self.setFile
1535
1587
1536 if not( os.path.exists(fullpath) ):
1588 if not( os.path.exists(fullpath) ):
1537 os.mkdir(fullpath)
1589 os.mkdir(fullpath)
1538 setFile = -1 #inicializo mi contador de seteo
1590 setFile = -1 #inicializo mi contador de seteo
1539 else:
1591 else:
1540 filesList = os.listdir( fullpath )
1592 filesList = os.listdir( fullpath )
1541 if len( filesList ) > 0:
1593 if len( filesList ) > 0:
1542 filesList = sorted( filesList, key=str.lower )
1594 filesList = sorted( filesList, key=str.lower )
1543 filen = filesList[-1]
1595 filen = filesList[-1]
1544 # el filename debera tener el siguiente formato
1596 # el filename debera tener el siguiente formato
1545 # 0 1234 567 89A BCDE (hex)
1597 # 0 1234 567 89A BCDE (hex)
1546 # x YYYY DDD SSS .ext
1598 # x YYYY DDD SSS .ext
1547 if isNumber( filen[8:11] ):
1599 if isNumber( filen[8:11] ):
1548 setFile = int( filen[8:11] ) #inicializo mi contador de seteo al seteo del ultimo file
1600 setFile = int( filen[8:11] ) #inicializo mi contador de seteo al seteo del ultimo file
1549 else:
1601 else:
1550 setFile = -1
1602 setFile = -1
1551 else:
1603 else:
1552 setFile = -1 #inicializo mi contador de seteo
1604 setFile = -1 #inicializo mi contador de seteo
1553
1605
1554 setFile += 1
1606 setFile += 1
1555
1607
1556 #If this is a new day it resets some values
1608 #If this is a new day it resets some values
1557 if self.dataOut.datatime.date() > self.fileDate:
1609 if self.dataOut.datatime.date() > self.fileDate:
1558 setFile = 0
1610 setFile = 0
1559 self.nTotalBlocks = 0
1611 self.nTotalBlocks = 0
1560
1612
1561 filen = '%s%4.4d%3.3d%3.3d%s' % (self.optchar, timeTuple.tm_year, timeTuple.tm_yday, setFile, ext )
1613 filen = '%s%4.4d%3.3d%3.3d%s' % (self.optchar, timeTuple.tm_year, timeTuple.tm_yday, setFile, ext )
1562
1614
1563 filename = os.path.join( path, subfolder, filen )
1615 filename = os.path.join( path, subfolder, filen )
1564
1616
1565 fp = open( filename,'wb' )
1617 fp = open( filename,'wb' )
1566
1618
1567 self.blockIndex = 0
1619 self.blockIndex = 0
1568
1620
1569 #guardando atributos
1621 #guardando atributos
1570 self.filename = filename
1622 self.filename = filename
1571 self.subfolder = subfolder
1623 self.subfolder = subfolder
1572 self.fp = fp
1624 self.fp = fp
1573 self.setFile = setFile
1625 self.setFile = setFile
1574 self.flagIsNewFile = 1
1626 self.flagIsNewFile = 1
1575 self.fileDate = self.dataOut.datatime.date()
1627 self.fileDate = self.dataOut.datatime.date()
1576
1628
1577 self.setFirstHeader()
1629 self.setFirstHeader()
1578
1630
1579 print '[Writing] Opening file: %s'%self.filename
1631 print '[Writing] Opening file: %s'%self.filename
1580
1632
1581 self.__writeFirstHeader()
1633 self.__writeFirstHeader()
1582
1634
1583 return 1
1635 return 1
1584
1636
1585 def setup(self, dataOut, path, blocksPerFile, profilesPerBlock=64, set=None, ext=None, datatype=4):
1637 def setup(self, dataOut, path, blocksPerFile, profilesPerBlock=64, set=None, ext=None, datatype=4):
1586 """
1638 """
1587 Setea el tipo de formato en la cual sera guardada la data y escribe el First Header
1639 Setea el tipo de formato en la cual sera guardada la data y escribe el First Header
1588
1640
1589 Inputs:
1641 Inputs:
1590 path : directory where data will be saved
1642 path : directory where data will be saved
1591 profilesPerBlock : number of profiles per block
1643 profilesPerBlock : number of profiles per block
1592 set : initial file set
1644 set : initial file set
1593 datatype : An integer number that defines data type:
1645 datatype : An integer number that defines data type:
1594 0 : int8 (1 byte)
1646 0 : int8 (1 byte)
1595 1 : int16 (2 bytes)
1647 1 : int16 (2 bytes)
1596 2 : int32 (4 bytes)
1648 2 : int32 (4 bytes)
1597 3 : int64 (8 bytes)
1649 3 : int64 (8 bytes)
1598 4 : float32 (4 bytes)
1650 4 : float32 (4 bytes)
1599 5 : double64 (8 bytes)
1651 5 : double64 (8 bytes)
1600
1652
1601 Return:
1653 Return:
1602 0 : Si no realizo un buen seteo
1654 0 : Si no realizo un buen seteo
1603 1 : Si realizo un buen seteo
1655 1 : Si realizo un buen seteo
1604 """
1656 """
1605
1657
1606 if ext == None:
1658 if ext == None:
1607 ext = self.ext
1659 ext = self.ext
1608
1660
1609 self.ext = ext.lower()
1661 self.ext = ext.lower()
1610
1662
1611 self.path = path
1663 self.path = path
1612
1664
1613 if set is None:
1665 if set is None:
1614 self.setFile = -1
1666 self.setFile = -1
1615 else:
1667 else:
1616 self.setFile = set - 1
1668 self.setFile = set - 1
1617
1669
1618 self.blocksPerFile = blocksPerFile
1670 self.blocksPerFile = blocksPerFile
1619
1671
1620 self.profilesPerBlock = profilesPerBlock
1672 self.profilesPerBlock = profilesPerBlock
1621
1673
1622 self.dataOut = dataOut
1674 self.dataOut = dataOut
1623 self.fileDate = self.dataOut.datatime.date()
1675 self.fileDate = self.dataOut.datatime.date()
1624 #By default
1676 #By default
1625 self.dtype = self.dataOut.dtype
1677 self.dtype = self.dataOut.dtype
1626
1678
1627 if datatype is not None:
1679 if datatype is not None:
1628 self.dtype = get_numpy_dtype(datatype)
1680 self.dtype = get_numpy_dtype(datatype)
1629
1681
1630 if not(self.setNextFile()):
1682 if not(self.setNextFile()):
1631 print "[Writing] There isn't a next file"
1683 print "[Writing] There isn't a next file"
1632 return 0
1684 return 0
1633
1685
1634 self.setBlockDimension()
1686 self.setBlockDimension()
1635
1687
1636 return 1
1688 return 1
1637
1689
1638 def run(self, dataOut, **kwargs):
1690 def run(self, dataOut, **kwargs):
1639
1691
1640 if not(self.isConfig):
1692 if not(self.isConfig):
1641
1693
1642 self.setup(dataOut, **kwargs)
1694 self.setup(dataOut, **kwargs)
1643 self.isConfig = True
1695 self.isConfig = True
1644
1696
1645 self.putData()
1697 self.putData()
1646
1698
General Comments 0
You need to be logged in to leave comments. Login now