##// END OF EJS Templates
Cambios realizados a la Clase VoltageReader: se ordenaron los metodos y atributos. Esta version contiene un bug en la lectura de datos
Daniel Valdez -
r5:9c86bf89cb54
parent child
Show More
@@ -1,31 +1,31
1 1 '''
2 2 Created on 23/01/2012
3 3
4 4 @author: danielangelsuarezmunoz
5 5 '''
6 6
7 7 import VoltageReader
8 8 import datetime
9 9 import time
10 10
11 11 objReader = VoltageReader.VoltageReader()
12 12
13 13 path = '/Users/danielangelsuarezmunoz/Documents/Projects'
14 startDateTime = datetime.datetime(2007,1,1,16,0,0)
15 endDateTime = datetime.datetime(2007,12,1,17,1,0)
14 startDateTime = datetime.datetime(2007,5,1,0,0,0)
15 endDateTime = datetime.datetime(2007,5,1,23,59,0)
16 16 set = None
17 17 expLabel = ''
18 18 ext = '*.r'
19 19
20 20 t0 = time.time()
21 21 objReader.setup(path, startDateTime, endDateTime, set, expLabel, ext)
22 22 print time.time() - t0
23 23
24 24
25 25 while(not(objReader.noMoreFiles)):
26 26
27 27 objReader.getData()
28 #print objReader.objStructShortHeader.dataBlock
28 print objReader.objBasicHeader.dataBlock
29 29 #print time.localtime(objReader.objStructShortHeader.universalTime)
30 30
31 31 No newline at end of file
@@ -1,592 +1,601
1 1 '''
2 2 Created on 23/01/2012
3 3
4 4 @author: danielangelsuarezmunoz
5 5 '''
6 6
7 7 from DataReader import DataReader
8 8
9 9 import numpy
10 10 import os.path
11 11 import glob
12 12 import fnmatch
13 13 import time
14 14 import datetime
15 15
16 16 class PROCFLAG:
17 17 COHERENT_INTEGRATION = numpy.uint32(0x00000001)
18 18 DECODE_DATA = numpy.uint32(0x00000002)
19 19 SPECTRA_CALC = numpy.uint32(0x00000004)
20 20 INCOHERENT_INTEGRATION = numpy.uint32(0x00000008)
21 21 POST_COHERENT_INTEGRATION = numpy.uint32(0x00000010)
22 22 SHIFT_FFT_DATA = numpy.uint32(0x00000020)
23 23
24 24 DATATYPE_CHAR = numpy.uint32(0x00000040)
25 25 DATATYPE_SHORT = numpy.uint32(0x00000080)
26 26 DATATYPE_LONG = numpy.uint32(0x00000100)
27 27 DATATYPE_INT64 = numpy.uint32(0x00000200)
28 28 DATATYPE_FLOAT = numpy.uint32(0x00000400)
29 29 DATATYPE_DOUBLE = numpy.uint32(0x00000800)
30 30
31 31 DATAARRANGE_CONTIGUOUS_CH = numpy.uint32(0x00001000)
32 32 DATAARRANGE_CONTIGUOUS_H = numpy.uint32(0x00002000)
33 33 DATAARRANGE_CONTIGUOUS_P = numpy.uint32(0x00004000)
34 34
35 35 SAVE_CHANNELS_DC = numpy.uint32(0x00008000)
36 36 DEFLIP_DATA = numpy.uint32(0x00010000)
37 37 DEFINE_PROCESS_CODE = numpy.uint32(0x00020000)
38 38
39 39 ACQ_SYS_NATALIA = numpy.uint32(0x00040000)
40 40 ACQ_SYS_ECHOTEK = numpy.uint32(0x00080000)
41 41 ACQ_SYS_ADRXD = numpy.uint32(0x000C0000)
42 42 ACQ_SYS_JULIA = numpy.uint32(0x00100000)
43 43 ACQ_SYS_XXXXXX = numpy.uint32(0x00140000)
44 44
45 45 EXP_NAME_ESP = numpy.uint32(0x00200000)
46 46 CHANNEL_NAMES_ESP = numpy.uint32(0x00400000)
47 47
48 48 OPERATION_MASK = numpy.uint32(0x0000003F)
49 49 DATATYPE_MASK = numpy.uint32(0x00000FC0)
50 50 DATAARRANGE_MASK = numpy.uint32(0x00007000)
51 51 ACQ_SYS_MASK = numpy.uint32(0x001C0000)
52 52
53 class StructShortHeader():
53 class BasicHeader():
54 54
55 55 size = 0
56 56 version = 0
57 57 dataBlock = 0
58 58 utc = 0
59 59 miliSecond = 0
60 60 timeZone = 0
61 61 dstFlag = 0
62 62 errorCount = 0
63 63 struct = numpy.dtype([
64 64 ('nSize','<u4'),
65 65 ('nVersion','<u2'),
66 66 ('nDataBlockId','<u4'),
67 67 ('nUtime','<u4'),
68 68 ('nMilsec','<u2'),
69 69 ('nTimezone','<i2'),
70 70 ('nDstflag','<i2'),
71 71 ('nErrorCount','<u4')
72 72 ])
73 73
74 74 def __init__(self):
75 75 pass
76 76
77 77 def read(self, fp):
78 78
79 79 header = numpy.fromfile(fp, self.struct,1)
80 80 self.size = header['nSize'][0]
81 81 self.version = header['nVersion'][0]
82 82 self.dataBlock = header['nDataBlockId'][0]
83 83 self.utc = header['nUtime'][0]
84 84 self.miliSecond = header['nMilsec'][0]
85 85 self.timeZone = header['nTimezone'][0]
86 86 self.dstFlag = header['nDstflag'][0]
87 87 self.errorCount = header['nErrorCount'][0]
88 88
89 89 return 1
90 90
91 class StructSystemHeader():
91 class SystemHeader():
92 92 size = 0
93 93 numSamples = 0
94 94 numProfiles = 0
95 95 numChannels = 0
96 96 adcResolution = 0
97 97 pciDioBusWidth = 0
98 98 struct = numpy.dtype([
99 99 ('nSize','<u4'),
100 100 ('nNumSamples','<u4'),
101 101 ('nNumProfiles','<u4'),
102 102 ('nNumChannels','<u4'),
103 103 ('nADCResolution','<u4'),
104 104 ('nPCDIOBusWidth','<u4'),
105 105 ])
106 106
107 107 def __init__(self):
108 108 pass
109 109
110 110 def read(self, fp):
111 header = numpy.fromfile(fp,self.struct,1)
112 self.size = header['nSize'][0]
113 self.numSamples = header['nNumSamples'][0]
114 self.numProfiles = header['nNumProfiles'][0]
115 self.numChannels = header['nNumChannels'][0]
116 self.adcResolution = header['nADCResolution'][0]
117 self.pciDioBusWidth = header['nPCDIOBusWidth'][0]
111 118
112 119
113 120 return 1
114 121
115 class StructRadarController():
122 class RadarControllerHeader():
116 123 size = 0
117 124 expType = 0
118 125 nTx = 0
119 126 ipp = 0
120 127 txA = 0
121 128 txB = 0
122 129 numWindows = 0
123 130 numTaus = 0
124 131 codeType = 0
125 132 line6Function = 0
126 133 line5Fuction = 0
127 134 fClock = 0
128 135 prePulseBefore = 0
129 136 prePulserAfter = 0
130 137 rangeIpp = 0
131 138 rangeTxA = 0
132 139 rangeTxB = 0
133 140 struct = numpy.dtype([
134 141 ('nSize','<u4'),
135 142 ('nExpType','<u4'),
136 143 ('nNTx','<u4'),
137 144 ('fIpp','<f4'),
138 145 ('fTxA','<f4'),
139 146 ('fTxB','<f4'),
140 147 ('nNumWindows','<u4'),
141 148 ('nNumTaus','<u4'),
142 149 ('nCodeType','<u4'),
143 150 ('nLine6Function','<u4'),
144 151 ('nLine5Function','<u4'),
145 152 ('fClock','<f4'),
146 153 ('nPrePulseBefore','<u4'),
147 154 ('nPrePulseAfter','<u4'),
148 155 ('sRangeIPP','<a20'),
149 156 ('sRangeTxA','<a20'),
150 157 ('sRangeTxB','<a20'),
151 158 ])
152 159
153 160
154 161 def __init__(self):
155 162 pass
156 163
157 164 def read(self, fp):
165 header = numpy.fromfile(fp,self.struct,1)
166 self.size = header['nSize'][0]
167 self.expType = header['nExpType'][0]
168 self.nTx = header['nNTx'][0]
169 self.ipp = header['fIpp'][0]
170 self.txA = header['fTxA'][0]
171 self.txB = header['fTxB'][0]
172 self.numWindows = header['nNumWindows'][0]
173 self.numTaus = header['nNumTaus'][0]
174 self.codeType = header['nCodeType'][0]
175 self.line6Function = header['nLine6Function'][0]
176 self.line5Fuction = header['nLine5Function'][0]
177 self.fClock = header['fClock'][0]
178 self.prePulseBefore = header['nPrePulseBefore'][0]
179 self.prePulserAfter = header['nPrePulseAfter'][0]
180 self.rangeIpp = header['sRangeIPP'][0]
181 self.rangeTxA = header['sRangeTxA'][0]
182 self.rangeTxB = header['sRangeTxB'][0]
183 # jump Dynamic Radar Controller Header
184 jumpHeader = self.size - 116
185 fp.seek(fp.tell() + jumpHeader)
158 186
159 187 return 1
160 188
161 class StructProcessing():
189 class ProcessingHeader():
162 190 size = 0
163 191 dataType = 0
164 192 blockSize = 0
165 193 profilesPerBlock = 0
166 194 dataBlocksPerFile = 0
167 195 numWindows = 0
168 196 processFlags = 0
169 197 coherentInt = 0
170 198 incoherentInt = 0
171 199 totalSpectra = 0
172 200 struct = numpy.dtype([
173 201 ('nSize','<u4'),
174 202 ('nDataType','<u4'),
175 203 ('nSizeOfDataBlock','<u4'),
176 204 ('nProfilesperBlock','<u4'),
177 205 ('nDataBlocksperFile','<u4'),
178 206 ('nNumWindows','<u4'),
179 207 ('nProcessFlags','<u4'),
180 208 ('nCoherentIntegrations','<u4'),
181 209 ('nIncoherentIntegrations','<u4'),
182 210 ('nTotalSpectra','<u4')
183 211 ])
184 212 samplingWindow = 0
185 213 structSamplingWindow = numpy.dtype([('h0','<f4'),('dh','<f4'),('nsa','<u4')])
186 214 numHeights = 0
187 215 firstHeight = 0
188 216 deltaHeight = 0
189 217 samplesWin = 0
190 218 spectraComb = 0
191 219 numCode = 0
192 220 codes = 0
193 221 numBaud = 0
194 222
195 223 def __init__(self):
196 224 pass
197 225
198 226 def read(self, fp):
227 header = numpy.fromfile(fp,self.struct,1)
228 self.size = header['nSize'][0]
229 self.dataType = header['nDataType'][0]
230 self.blockSize = header['nSizeOfDataBlock'][0]
231 self.profilesPerBlock = header['nProfilesperBlock'][0]
232 self.dataBlocksPerFile = header['nDataBlocksperFile'][0]
233 self.numWindows = header['nNumWindows'][0]
234 self.processFlags = header['nProcessFlags']
235 self.coherentInt = header['nCoherentIntegrations'][0]
236 self.incoherentInt = header['nIncoherentIntegrations'][0]
237 self.totalSpectra = header['nTotalSpectra'][0]
238 self.samplingWindow = numpy.fromfile(fp,self.structSamplingWindow,self.numWindows)
239 self.numHeights = numpy.sum(self.samplingWindow['nsa'])
240 self.firstHeight = self.samplingWindow['h0']
241 self.deltaHeight = self.samplingWindow['dh']
242 self.samplesWin = self.samplingWindow['nsa']
243 self.spectraComb = numpy.fromfile(fp,'u1',2*self.totalSpectra)
244 if self.processFlags & PROCFLAG.DEFINE_PROCESS_CODE == PROCFLAG.DEFINE_PROCESS_CODE:
245 self.numCode = numpy.fromfile(fp,'<u4',1)
246 self.numBaud = numpy.fromfile(fp,'<u4',1)
247 self.codes = numpy.fromfile(fp,'<f4',self.numCode*self.numBaud).reshape(self.numBaud,self.numCode)
248
199 249
200 250 return 1
201 251
202 252 class VoltageReader(DataReader):
203 253 # Este flag indica que la data leida no es continua
204 254 __jumpDataFlag = False
205 255
206 256 __idFile = 0
207 257
208 258 __fp = 0
209 259
210 260 __startDateTime = 0
211 261
212 262 __endDateTime = 0
213 263
214 264 __dataType = 0
215 265
216 266 __sizeOfFileByHeader = 0
217 267
218 __listOfPath = []
268 __pathList = []
219 269
220 270 filenameList = []
221 271
222 __flagReadShortHeader = 0
223
224 272 __lastUTTime = 0
225 273
226 274 __maxTimeStep = 5
227 275
228 276 __flagResetProcessing = 0
229 277
230 278 __flagIsNewFile = 0
231 279
232 280 noMoreFiles = 0
233 281
234 282 online = 0
235 283
236 284 filename = ''
237 285
238 286 fileSize = 0
239 287
240 288 firstHeaderSize = 0
241 289
242 290 basicHeaderSize = 24
243 291
244 objStructShortHeader = StructShortHeader()
292 objBasicHeader = BasicHeader()
245 293
246 objStructSystemHeader = StructSystemHeader()
294 objSystemHeader = SystemHeader()
247 295
248 objStructRadarController = StructRadarController()
296 objRadarControllerHeader = RadarControllerHeader()
249 297
250 objStructProcessing = StructProcessing()
298 objProcessingHeader = ProcessingHeader()
251 299
252 300 __buffer = 0
253 301
254 302 __buffer_id = 9999
255 303
256 304 def __init__(self):
257 305 pass
258 306
259 def __rdSystemHeader(self):
260 header = numpy.fromfile(self.__fp,self.objStructSystemHeader.struct,1)
261 self.objStructSystemHeader.size = header['nSize'][0]
262 self.objStructSystemHeader.numSamples = header['nNumSamples'][0]
263 self.objStructSystemHeader.numProfiles = header['nNumProfiles'][0]
264 self.objStructSystemHeader.numChannels = header['nNumChannels'][0]
265 self.objStructSystemHeader.adcResolution = header['nADCResolution'][0]
266 self.objStructSystemHeader.pciDioBusWidth = header['nPCDIOBusWidth'][0]
267
268 def __rdRadarControllerHeader(self):
269 header = numpy.fromfile(self.__fp,self.objStructRadarController.struct,1)
270 self.objStructRadarController.size = header['nSize'][0]
271 self.objStructRadarController.expType = header['nExpType'][0]
272 self.objStructRadarController.nTx = header['nNTx'][0]
273 self.objStructRadarController.ipp = header['fIpp'][0]
274 self.objStructRadarController.txA = header['fTxA'][0]
275 self.objStructRadarController.txB = header['fTxB'][0]
276 self.objStructRadarController.numWindows = header['nNumWindows'][0]
277 self.objStructRadarController.numTaus = header['nNumTaus'][0]
278 self.objStructRadarController.codeType = header['nCodeType'][0]
279 self.objStructRadarController.line6Function = header['nLine6Function'][0]
280 self.objStructRadarController.line5Fuction = header['nLine5Function'][0]
281 self.objStructRadarController.fClock = header['fClock'][0]
282 self.objStructRadarController.prePulseBefore = header['nPrePulseBefore'][0]
283 self.objStructRadarController.prePulserAfter = header['nPrePulseAfter'][0]
284 self.objStructRadarController.rangeIpp = header['sRangeIPP'][0]
285 self.objStructRadarController.rangeTxA = header['sRangeTxA'][0]
286 self.objStructRadarController.rangeTxB = header['sRangeTxB'][0]
287 # jump Dynamic Radar Controller Header
288 jumpHeader = self.objStructRadarController.size - 116
289 self.__fp.seek(self.__fp.tell() + jumpHeader)
290
291 def __rdProcessingHeader(self):
292 header = numpy.fromfile(self.__fp,self.objStructProcessing.struct,1)
293 self.objStructProcessing.size = header['nSize'][0]
294 self.objStructProcessing.dataType = header['nDataType'][0]
295 self.objStructProcessing.blockSize = header['nSizeOfDataBlock'][0]
296 self.objStructProcessing.profilesPerBlock = header['nProfilesperBlock'][0]
297 self.objStructProcessing.dataBlocksPerFile = header['nDataBlocksperFile'][0]
298 self.objStructProcessing.numWindows = header['nNumWindows'][0]
299 self.objStructProcessing.processFlags = header['nProcessFlags']
300 self.objStructProcessing.coherentInt = header['nCoherentIntegrations'][0]
301 self.objStructProcessing.incoherentInt = header['nIncoherentIntegrations'][0]
302 self.objStructProcessing.totalSpectra = header['nTotalSpectra'][0]
303 self.objStructProcessing.samplingWindow = numpy.fromfile(self.__fp,self.objStructProcessing.structSamplingWindow,self.objStructProcessing.numWindows)
304 self.objStructProcessing.numHeights = numpy.sum(self.objStructProcessing.samplingWindow['nsa'])
305 self.objStructProcessing.firstHeight = self.objStructProcessing.samplingWindow['h0']
306 self.objStructProcessing.deltaHeight = self.objStructProcessing.samplingWindow['dh']
307 self.objStructProcessing.samplesWin = self.objStructProcessing.samplingWindow['nsa']
308 self.objStructProcessing.spectraComb = numpy.fromfile(self.__fp,'u1',2*self.objStructProcessing.totalSpectra)
309 if self.objStructProcessing.processFlags & PROCFLAG.DEFINE_PROCESS_CODE == PROCFLAG.DEFINE_PROCESS_CODE:
310 self.objStructProcessing.numCode = numpy.fromfile(self.__fp,'<u4',1)
311 self.objStructProcessing.numBaud = numpy.fromfile(self.__fp,'<u4',1)
312 self.objStructProcessing.codes = numpy.fromfile(self.__fp,'<f4',self.objStructProcessing.numCode*self.objStructProcessing.numBaud).reshape(self.objStructProcessing.numBaud,self.objStructProcessing.numCode)
307 def __rdSystemHeader(self,fp=None):
308 if fp == None:
309 fp = self.__fp
310
311 self.objSystemHeader.read(fp)
313 312
313 def __rdRadarControllerHeader(self,fp=None):
314 if fp == None:
315 fp = self.__fp
316
317 self.objRadarControllerHeader.read(fp)
318
319 def __rdProcessingHeader(self,fp=None):
320 if fp == None:
321 fp = self.__fp
322
323 self.objProcessingHeader.read(fp)
324
314 325 def __searchFiles(self,path, startDateTime, endDateTime, set=None, expLabel = "", ext = "*.r"):
315 326
316 327 startUtSeconds = time.mktime(startDateTime.timetuple())
317 328 endUtSeconds = time.mktime(endDateTime.timetuple())
318 329
319 330 startYear = startDateTime.timetuple().tm_year
320 331 endYear = endDateTime.timetuple().tm_year
321 332
322 333 startDoy = startDateTime.timetuple().tm_yday
323 334 endDoy = endDateTime.timetuple().tm_yday
324 335
325 336 rangeOfYears = range(startYear,endYear+1)
326 337
327 338 listOfListDoys = []
328 339 if startYear == endYear:
329 340 doyList = range(startDoy,endDoy+1)
330 341 else:
331 342 for year in rangeOfYears:
332 343 if (year == startYear):
333 344 listOfListDoys.append(range(startDoy,365+1))
334 345 elif (year == endYear):
335 346 listOfListDoys.append(range(1,endDoy+1))
336 347 else:
337 348 listOfListDoys.append(range(1,365+1))
338 349 doyList = []
339 350 for list in listOfListDoys:
340 351 doyList = doyList + list
341 352
342 353 folders = []
343 354 for thisPath in os.listdir(path):
344 355 if os.path.isdir(os.path.join(path,thisPath)):
345 356 #folders.append(os.path.join(path,thisPath))
346 357 folders.append(thisPath)
347 358
348 listOfPath = []
359 pathList = []
349 360 dicOfPath = {}
350 361 for year in rangeOfYears:
351 362 for doy in doyList:
352 363 tmp = fnmatch.filter(folders, 'D' + '%4.4d%3.3d' % (year,doy))
353 364 if len(tmp) == 0:
354 365 continue
355 366 if expLabel == '':
356 listOfPath.append(os.path.join(path,tmp[0]))
367 pathList.append(os.path.join(path,tmp[0]))
357 368 dicOfPath.setdefault(os.path.join(path,tmp[0]))
358 369 dicOfPath[os.path.join(path,tmp[0])] = []
359 370 else:
360 listOfPath.append(os.path.join(path,os.path.join(tmp[0],expLabel)))
371 pathList.append(os.path.join(path,os.path.join(tmp[0],expLabel)))
361 372 dicOfPath.setdefault(os.path.join(path,os.path.join(tmp[0],expLabel)))
362 373 dicOfPath[os.path.join(path,os.path.join(tmp[0],expLabel))] = []
363 374
364 375
365 376 filenameList = []
366 for thisPath in listOfPath:
377 for thisPath in pathList:
367 378 fileList = glob.glob1(thisPath, ext)
368 379 #dicOfPath[thisPath].append(fileList)
369 380 fileList.sort()
370 381 for file in fileList:
371 382 filename = os.path.join(thisPath,file)
372 383 if self.isThisFileinRange(filename, startUtSeconds, endUtSeconds):
373 384 filenameList.append(filename)
374 385
375 386 self.filenameList = filenameList
376 387
377 return listOfPath, filenameList
378
388 return pathList, filenameList
379 389
380 390 def isThisFileinRange(self, filename, startUTSeconds=None, endUTSeconds=None):
381 391
382 392 try:
383 393 fp = open(filename,'rb')
384 394 except:
385 395 raise IOError, "The file %s can't be opened" %(filename)
386 396
387 397 if startUTSeconds==None:
388 398 startUTSeconds = self.startUTCSeconds
389 399
390 400 if endUTSeconds==None:
391 401 endUTSeconds = self.endUTCSeconds
392 402
393 objShortHeader = StructShortHeader()
403 objBasicHeader = BasicHeader()
394 404
395 if not(objShortHeader.read(fp)):
405 if not(objBasicHeader.read(fp)):
396 406 return 0
397 407
398 if not ((startUTSeconds <= objShortHeader.utc) and (endUTSeconds >= objShortHeader.utc)):
408 fp.close()
409
410 if not ((startUTSeconds <= objBasicHeader.utc) and (endUTSeconds >= objBasicHeader.utc)):
399 411 return 0
400 412
401 413 return 1
402 414
403 415 def __readBasicHeader(self, fp=None):
404 416
405 417 if fp == None:
406 418 fp = self.__fp
407 419
408 self.objStructShortHeader.read(fp)
420 self.objBasicHeader.read(fp)
409 421
410
411 422 def __readFirstHeader(self):
412 423
413 424 self.__readBasicHeader()
414 425 self.__rdSystemHeader()
415 426 self.__rdRadarControllerHeader()
416 427 self.__rdProcessingHeader()
417 self.firstHeaderSize = self.objStructShortHeader.size
428 self.firstHeaderSize = self.objBasicHeader.size
418 429
419 data_type=int(numpy.log2((self.objStructProcessing.processFlags & PROCFLAG.DATATYPE_MASK))-numpy.log2(PROCFLAG.DATATYPE_CHAR))
430 data_type=int(numpy.log2((self.objProcessingHeader.processFlags & PROCFLAG.DATATYPE_MASK))-numpy.log2(PROCFLAG.DATATYPE_CHAR))
420 431 if data_type == 0:
421 432 tmp=numpy.dtype([('real','<i1'),('imag','<i1')])
422 433 elif data_type == 1:
423 434 tmp=numpy.dtype([('real','<i2'),('imag','<i2')])
424 435 elif data_type == 2:
425 436 tmp=numpy.dtype([('real','<i4'),('imag','<i4')])
426 437 elif data_type == 3:
427 438 tmp=numpy.dtype([('real','<i8'),('imag','<i8')])
428 439 elif data_type == 4:
429 440 tmp=numpy.dtype([('real','<f4'),('imag','<f4')])
430 441 elif data_type == 5:
431 442 tmp=numpy.dtype([('real','<f8'),('imag','<f8')])
432 443 else:
433 444 print 'no define data type'
434 445 tmp = 0
435 446
436 447 self.__flagIsNewFile = 0
437 448 self.__dataType = tmp
438 self.__sizeOfFileByHeader = self.objStructProcessing.dataBlocksPerFile * self.objStructProcessing.blockSize + self.firstHeaderSize + self.basicHeaderSize*(self.objStructProcessing.dataBlocksPerFile - 1)
439
440
449 self.__sizeOfFileByHeader = self.objProcessingHeader.dataBlocksPerFile * self.objProcessingHeader.blockSize + self.firstHeaderSize + self.basicHeaderSize*(self.objProcessingHeader.dataBlocksPerFile - 1)
441 450
442 451 def __setNextFileOnline(self):
443 452 return 0
444 453
445 454 def __setNextFileOffline(self):
446 455
447 456 idFile = self.__idFile
448 457 while(True):
449 458
450 459 idFile += 1
451 460
452 461 if not(idFile < len(self.filenameList)):
453 462 self.noMoreFiles = 1
454 463 return 0
455 464
456 465 filename = self.filenameList[idFile]
457 466 fileSize = os.path.getsize(filename)
458 467 fp = open(filename,'rb')
459 468
460 469 currentSize = fileSize - fp.tell()
461 neededSize = self.objStructProcessing.blockSize + self.firstHeaderSize
470 neededSize = self.objProcessingHeader.blockSize + self.firstHeaderSize
462 471
463 472 if (currentSize < neededSize):
464 473 continue
465 474
466 475 break
467 476
468 477 self.__flagIsNewFile = 1
469 478 self.__idFile = idFile
470 479 self.filename = filename
471 480 self.fileSize = fileSize
472 481 self.__fp = fp
473 482
474 483 print 'Setting the file: %s'%self.filename
475 484
476 485 return 1
477 486
478 487 def __setNextFile(self):
479 488
480 489 if self.online:
481 490 return self.__setNextFileOnline()
482 491 else:
483 492 return self.__setNextFileOffline()
484 493
485 494 def __setNewBlock(self):
486 495
487 496 currentSize = self.fileSize - self.__fp.tell()
488 neededSize = self.objStructProcessing.blockSize + self.basicHeaderSize
497 neededSize = self.objProcessingHeader.blockSize + self.basicHeaderSize
489 498
490 499 # Bloque Completo
491 500 if (currentSize >= neededSize):
492 501 self.__readBasicHeader()
493 502 return 1
494 503
495 504 self.__setNextFile()
496 505 self.__readFirstHeader()
497 506
498 deltaTime = self.objStructShortHeader.utc - self.__lastUTTime # check this
507 deltaTime = self.objBasicHeader.utc - self.__lastUTTime # check this
499 508 if deltaTime > self.__maxTimeStep:
500 509 self.__flagResetProcessing = 1
501 510
502 511 return 1
503 512
504 513 def __readBlock(self):
505 514 """Lee el bloque de datos desde la posicion actual del puntero del archivo y
506 515 actualiza todos los parametros relacionados al bloque de datos (data, time,
507 516 etc). La data leida es almacenada en el buffer y el contador de datos leidos es
508 517 seteado a 0
509 518 """
510 519
511 pts2read = self.objStructProcessing.profilesPerBlock*self.objStructProcessing.numHeights*self.objStructSystemHeader.numChannels
520 pts2read = self.objProcessingHeader.profilesPerBlock*self.objProcessingHeader.numHeights*self.objSystemHeader.numChannels
512 521
513 522 data = numpy.fromfile(self.__fp,self.__dataType,pts2read)
514 523
515 data = data.reshape((self.objStructProcessing.profilesPerBlock, self.objStructProcessing.numHeights, self.objStructSystemHeader.numChannels))
524 data = data.reshape((self.objProcessingHeader.profilesPerBlock, self.objProcessingHeader.numHeights, self.objSystemHeader.numChannels))
516 525
517 526 self.__buffer = data
518 527
519 528 self.__buffer_id = 0
520 529
521 530 def readNextBlock(self):
522 531
523 532 self.__setNewBlock()
524 533
525 534 self.__readBlock()
526 535
527 self.__lastUTTime = self.objStructShortHeader.utc
536 self.__lastUTTime = self.objBasicHeader.utc
528 537
529 538 def __hasNotDataInBuffer(self):
530 if self.__buffer_id >= self.objStructProcessing.profilesPerBlock:
539 if self.__buffer_id >= self.objProcessingHeader.profilesPerBlock:
531 540 return 1
532 541
533 542 return 0
534 543
535 544 def getData(self):
536 545 """Obtiene un unidad de datos del buffer de lectura y es copiada a la clase "Data"
537 546 con todos los parametros asociados a este. cuando no hay datos en el buffer de
538 547 lectura es necesario hacer una nueva lectura de los bloques de datos
539 548 "__readBlock"
540 549 """
541 550
542 551 if self.__hasNotDataInBuffer():
543 552 self.readNextBlock()
544 553
545 554 if self.noMoreFiles == 1:
546 555 print 'read finished'
547 556 return None
548 557
549 558 data = self.__buffer[self.__buffer_id,:,:]
550 559
551 560 #print self.__buffer_id
552 561
553 562 self.__buffer_id += 1
554 563
555 564 #call setData - to Data Object
556 565
557 566 return data
558 567
559 568
560 569 def setup(self, path, startDateTime, endDateTime, set=None, expLabel = "", ext = ".r", online = 0):
561 570
562 571 if online == 0:
563 572 pathList, filenameList = self.__searchFiles(path, startDateTime, endDateTime, set, expLabel, ext)
564 573
565 574 if len(filenameList) == 0:
566 575 print 'Do not exist files in range: %s - %s'%(startDateTime.ctime(), endDateTime.ctime())
567 576 return 0
568 577
569 578 # for thisFile in filenameList:
570 579 # print thisFile
571 580
572 581 self.__idFile = -1
573 582
574 583 if not(self.__setNextFile()):
575 584 print "No more files"
576 585 return 0
577 586
578 587 self.__readFirstHeader()
579 588
580 589 self.startUTCSeconds = time.mktime(startDateTime.timetuple())
581 590 self.endUTCSeconds = time.mktime(endDateTime.timetuple())
582 591
583 592 self.startYear = startDateTime.timetuple().tm_year
584 593 self.endYear = endDateTime.timetuple().tm_year
585 594
586 595 self.startDoy = startDateTime.timetuple().tm_yday
587 596 self.endDoy = endDateTime.timetuple().tm_yday
588 597 #call fillHeaderValues() - to Data Object
589 598
590 self.__listOfPath = pathList
599 self.__pathList = pathList
591 600 self.filenameList = filenameList
592 601 self.online = online
General Comments 0
You need to be logged in to leave comments. Login now