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