@@ -1,506 +1,506 | |||
|
1 | 1 | ''' |
|
2 | 2 | Created on 23/01/2012 |
|
3 | 3 | |
|
4 | 4 | @author $Author: vsarmiento $ |
|
5 | 5 | @version $Id: HeaderIO.py 37 2012-03-26 22:55:13Z vsarmiento $ |
|
6 | 6 | ''' |
|
7 | 7 | |
|
8 | 8 | import numpy |
|
9 | 9 | import copy |
|
10 | 10 | |
|
11 | 11 | class Header: |
|
12 | 12 | |
|
13 | 13 | def __init__(self): |
|
14 | 14 | raise |
|
15 | 15 | |
|
16 | 16 | def copy(self): |
|
17 | 17 | return copy.deepcopy(self) |
|
18 | 18 | |
|
19 | 19 | def read(): |
|
20 | 20 | pass |
|
21 | 21 | |
|
22 | 22 | def write(): |
|
23 | 23 | pass |
|
24 | 24 | |
|
25 | 25 | class BasicHeader(Header): |
|
26 | 26 | |
|
27 | 27 | size = None |
|
28 | 28 | version = None |
|
29 | 29 | dataBlock = None |
|
30 | 30 | utc = None |
|
31 | 31 | miliSecond = None |
|
32 | 32 | timeZone = None |
|
33 | 33 | dstFlag = None |
|
34 | 34 | errorCount = None |
|
35 | 35 | struct = None |
|
36 | 36 | |
|
37 | 37 | def __init__(self): |
|
38 | 38 | |
|
39 | 39 | self.size = 0 |
|
40 | 40 | self.version = 0 |
|
41 | 41 | self.dataBlock = 0 |
|
42 | 42 | self.utc = 0 |
|
43 | 43 | self.miliSecond = 0 |
|
44 | 44 | self.timeZone = 0 |
|
45 | 45 | self.dstFlag = 0 |
|
46 | 46 | self.errorCount = 0 |
|
47 | 47 | self.struct = numpy.dtype([ |
|
48 | 48 | ('nSize','<u4'), |
|
49 | 49 | ('nVersion','<u2'), |
|
50 | 50 | ('nDataBlockId','<u4'), |
|
51 | 51 | ('nUtime','<u4'), |
|
52 | 52 | ('nMilsec','<u2'), |
|
53 | 53 | ('nTimezone','<i2'), |
|
54 | 54 | ('nDstflag','<i2'), |
|
55 | 55 | ('nErrorCount','<u4') |
|
56 | 56 | ]) |
|
57 | 57 | |
|
58 | 58 | |
|
59 | 59 | def read(self, fp): |
|
60 | 60 | try: |
|
61 | 61 | header = numpy.fromfile(fp, self.struct,1) |
|
62 | 62 | self.size = header['nSize'][0] |
|
63 | 63 | self.version = header['nVersion'][0] |
|
64 | 64 | self.dataBlock = header['nDataBlockId'][0] |
|
65 | 65 | self.utc = header['nUtime'][0] |
|
66 | 66 | self.miliSecond = header['nMilsec'][0] |
|
67 | 67 | self.timeZone = header['nTimezone'][0] |
|
68 | 68 | self.dstFlag = header['nDstflag'][0] |
|
69 | 69 | self.errorCount = header['nErrorCount'][0] |
|
70 | 70 | except: |
|
71 | 71 | return 0 |
|
72 | 72 | |
|
73 | 73 | return 1 |
|
74 | 74 | |
|
75 | 75 | def write(self, fp): |
|
76 | 76 | headerTuple = (self.size,self.version,self.dataBlock,self.utc,self.miliSecond,self.timeZone,self.dstFlag,self.errorCount) |
|
77 | 77 | header = numpy.array(headerTuple,self.struct) |
|
78 | 78 | header.tofile(fp) |
|
79 | 79 | |
|
80 | 80 | return 1 |
|
81 | 81 | |
|
82 | 82 | class SystemHeader(Header): |
|
83 | 83 | |
|
84 | 84 | size = None |
|
85 | 85 | nSamples = None |
|
86 | 86 | nProfiles = None |
|
87 | 87 | nChannels = None |
|
88 | 88 | adcResolution = None |
|
89 | 89 | pciDioBusWidth = None |
|
90 | 90 | struct = None |
|
91 | 91 | |
|
92 | 92 | def __init__(self): |
|
93 | 93 | self.size = 0 |
|
94 | 94 | self.nSamples = 0 |
|
95 | 95 | self.nProfiles = 0 |
|
96 | 96 | self.nChannels = 0 |
|
97 | 97 | self.adcResolution = 0 |
|
98 | 98 | self.pciDioBusWidth = 0 |
|
99 | 99 | self.struct = numpy.dtype([ |
|
100 | 100 | ('nSize','<u4'), |
|
101 | 101 | ('nNumSamples','<u4'), |
|
102 | 102 | ('nNumProfiles','<u4'), |
|
103 | 103 | ('nNumChannels','<u4'), |
|
104 | 104 | ('nADCResolution','<u4'), |
|
105 | 105 | ('nPCDIOBusWidth','<u4'), |
|
106 | 106 | ]) |
|
107 | 107 | |
|
108 | 108 | |
|
109 | 109 | def read(self, fp): |
|
110 | 110 | try: |
|
111 | 111 | header = numpy.fromfile(fp,self.struct,1) |
|
112 | 112 | self.size = header['nSize'][0] |
|
113 | 113 | self.nSamples = header['nNumSamples'][0] |
|
114 | 114 | self.nProfiles = header['nNumProfiles'][0] |
|
115 | 115 | self.nChannels = header['nNumChannels'][0] |
|
116 | 116 | self.adcResolution = header['nADCResolution'][0] |
|
117 | 117 | self.pciDioBusWidth = header['nPCDIOBusWidth'][0] |
|
118 | 118 | except: |
|
119 | 119 | return 0 |
|
120 | 120 | |
|
121 | 121 | return 1 |
|
122 | 122 | |
|
123 | 123 | def write(self, fp): |
|
124 | 124 | headerTuple = (self.size,self.nSamples,self.nProfiles,self.nChannels,self.adcResolution,self.pciDioBusWidth) |
|
125 | 125 | header = numpy.array(headerTuple,self.struct) |
|
126 | 126 | header.tofile(fp) |
|
127 | 127 | |
|
128 | 128 | return 1 |
|
129 | 129 | |
|
130 | 130 | class RadarControllerHeader(Header): |
|
131 | 131 | |
|
132 | 132 | size = None |
|
133 | 133 | expType = None |
|
134 | 134 | nTx = None |
|
135 | 135 | ipp = None |
|
136 | 136 | txA = None |
|
137 | 137 | txB = None |
|
138 | 138 | nWindows = None |
|
139 | 139 | numTaus = None |
|
140 | 140 | codeType = None |
|
141 | 141 | line6Function = None |
|
142 | 142 | line5Function = None |
|
143 | 143 | fClock = None |
|
144 | 144 | prePulseBefore = None |
|
145 | 145 | prePulserAfter = None |
|
146 | 146 | rangeIpp = None |
|
147 | 147 | rangeTxA = None |
|
148 | 148 | rangeTxB = None |
|
149 | 149 | struct = None |
|
150 | 150 | |
|
151 | 151 | def __init__(self): |
|
152 | 152 | self.size = 0 |
|
153 | 153 | self.expType = 0 |
|
154 | 154 | self.nTx = 0 |
|
155 | 155 | self.ipp = 0 |
|
156 | 156 | self.txA = 0 |
|
157 | 157 | self.txB = 0 |
|
158 | 158 | self.nWindows = 0 |
|
159 | 159 | self.numTaus = 0 |
|
160 | 160 | self.codeType = 0 |
|
161 | 161 | self.line6Function = 0 |
|
162 | 162 | self.line5Function = 0 |
|
163 | 163 | self.fClock = 0 |
|
164 | 164 | self.prePulseBefore = 0 |
|
165 | 165 | self.prePulserAfter = 0 |
|
166 | 166 | self.rangeIpp = 0 |
|
167 | 167 | self.rangeTxA = 0 |
|
168 | 168 | self.rangeTxB = 0 |
|
169 | 169 | self.struct = numpy.dtype([ |
|
170 | 170 | ('nSize','<u4'), |
|
171 | 171 | ('nExpType','<u4'), |
|
172 | 172 | ('nNTx','<u4'), |
|
173 | 173 | ('fIpp','<f4'), |
|
174 | 174 | ('fTxA','<f4'), |
|
175 | 175 | ('fTxB','<f4'), |
|
176 | 176 | ('nNumWindows','<u4'), |
|
177 | 177 | ('nNumTaus','<u4'), |
|
178 | 178 | ('nCodeType','<u4'), |
|
179 | 179 | ('nLine6Function','<u4'), |
|
180 | 180 | ('nLine5Function','<u4'), |
|
181 | 181 | ('fClock','<f4'), |
|
182 | 182 | ('nPrePulseBefore','<u4'), |
|
183 | 183 | ('nPrePulseAfter','<u4'), |
|
184 | 184 | ('sRangeIPP','<a20'), |
|
185 | 185 | ('sRangeTxA','<a20'), |
|
186 | 186 | ('sRangeTxB','<a20'), |
|
187 | 187 | ]) |
|
188 | 188 | |
|
189 | 189 | self.samplingWindowStruct = numpy.dtype([('h0','<f4'),('dh','<f4'),('nsa','<u4')]) |
|
190 | 190 | |
|
191 | 191 | self.samplingWindow = None |
|
192 | 192 | self.nHeights = None |
|
193 | 193 | self.firstHeight = None |
|
194 | 194 | self.deltaHeight = None |
|
195 | 195 | self.samplesWin = None |
|
196 | 196 | |
|
197 | 197 | self.nCode = None |
|
198 | 198 | self.nBaud = None |
|
199 | 199 | self.code = None |
|
200 | 200 | self.flip1 = None |
|
201 | 201 | self.flip2 = None |
|
202 | 202 | |
|
203 | 203 | self.dynamic = numpy.array([],numpy.dtype('byte')) |
|
204 | 204 | |
|
205 | 205 | |
|
206 | 206 | def read(self, fp): |
|
207 | 207 | try: |
|
208 | 208 | startFp = fp.tell() |
|
209 | 209 | header = numpy.fromfile(fp,self.struct,1) |
|
210 | 210 | self.size = header['nSize'][0] |
|
211 | 211 | self.expType = header['nExpType'][0] |
|
212 | 212 | self.nTx = header['nNTx'][0] |
|
213 | 213 | self.ipp = header['fIpp'][0] |
|
214 | 214 | self.txA = header['fTxA'][0] |
|
215 | 215 | self.txB = header['fTxB'][0] |
|
216 | 216 | self.nWindows = header['nNumWindows'][0] |
|
217 | 217 | self.numTaus = header['nNumTaus'][0] |
|
218 | 218 | self.codeType = header['nCodeType'][0] |
|
219 | 219 | self.line6Function = header['nLine6Function'][0] |
|
220 | 220 | self.line5Function = header['nLine5Function'][0] |
|
221 | 221 | self.fClock = header['fClock'][0] |
|
222 | 222 | self.prePulseBefore = header['nPrePulseBefore'][0] |
|
223 | 223 | self.prePulserAfter = header['nPrePulseAfter'][0] |
|
224 | 224 | self.rangeIpp = header['sRangeIPP'][0] |
|
225 | 225 | self.rangeTxA = header['sRangeTxA'][0] |
|
226 | 226 | self.rangeTxB = header['sRangeTxB'][0] |
|
227 | 227 | # jump Dynamic Radar Controller Header |
|
228 | 228 | jumpFp = self.size - 116 |
|
229 | 229 | self.dynamic = numpy.fromfile(fp,numpy.dtype('byte'),jumpFp) |
|
230 | 230 | #pointer backward to dynamic header and read |
|
231 | 231 | backFp = fp.tell() - jumpFp |
|
232 | 232 | fp.seek(backFp) |
|
233 | 233 | |
|
234 | 234 | self.samplingWindow = numpy.fromfile(fp,self.samplingWindowStruct,self.nWindows) |
|
235 | 235 | self.nHeights = numpy.sum(self.samplingWindow['nsa']) |
|
236 | 236 | self.firstHeight = self.samplingWindow['h0'] |
|
237 | 237 | self.deltaHeight = self.samplingWindow['dh'] |
|
238 | 238 | self.samplesWin = self.samplingWindow['nsa'] |
|
239 | 239 | |
|
240 | 240 | self.Taus = numpy.fromfile(fp,'<f4',self.numTaus) |
|
241 | 241 | |
|
242 | 242 | if self.codeType != 0: |
|
243 | 243 | self.nCode = numpy.fromfile(fp,'<u4',1) |
|
244 | 244 | self.nBaud = numpy.fromfile(fp,'<u4',1) |
|
245 | 245 | self.code = numpy.empty([self.nCode,self.nBaud],dtype='u1') |
|
246 | 246 | tempList = [] |
|
247 | 247 | for ic in range(self.nCode): |
|
248 | 248 | temp = numpy.fromfile(fp,'u1',4*numpy.ceil(self.nBaud/32.)) |
|
249 | 249 | tempList.append(temp) |
|
250 | 250 | self.code[ic] = numpy.unpackbits(temp[::-1])[-1*self.nBaud:] |
|
251 | 251 | self.code = 2.0*self.code - 1.0 |
|
252 | 252 | |
|
253 | 253 | if self.line5Function == RCfunction.FLIP: |
|
254 | 254 | self.flip1 = numpy.fromfile(fp,'<u4',1) |
|
255 | 255 | |
|
256 | 256 | if self.line6Function == RCfunction.FLIP: |
|
257 | 257 | self.flip2 = numpy.fromfile(fp,'<u4',1) |
|
258 | 258 | |
|
259 | 259 | endFp = self.size + startFp |
|
260 | 260 | jumpFp = endFp - fp.tell() |
|
261 | 261 | if jumpFp > 0: |
|
262 | 262 | fp.seek(jumpFp) |
|
263 | 263 | |
|
264 | 264 | except: |
|
265 | 265 | return 0 |
|
266 | 266 | |
|
267 | 267 | return 1 |
|
268 | 268 | |
|
269 | 269 | def write(self, fp): |
|
270 | 270 | headerTuple = (self.size, |
|
271 | 271 | self.expType, |
|
272 | 272 | self.nTx, |
|
273 | 273 | self.ipp, |
|
274 | 274 | self.txA, |
|
275 | 275 | self.txB, |
|
276 | 276 | self.nWindows, |
|
277 | 277 | self.numTaus, |
|
278 | 278 | self.codeType, |
|
279 | 279 | self.line6Function, |
|
280 | 280 | self.line5Function, |
|
281 | 281 | self.fClock, |
|
282 | 282 | self.prePulseBefore, |
|
283 | 283 | self.prePulserAfter, |
|
284 | 284 | self.rangeIpp, |
|
285 | 285 | self.rangeTxA, |
|
286 | 286 | self.rangeTxB) |
|
287 | 287 | |
|
288 | 288 | header = numpy.array(headerTuple,self.struct) |
|
289 | 289 | header.tofile(fp) |
|
290 | 290 | |
|
291 | 291 | dynamic = self.dynamic |
|
292 | 292 | dynamic.tofile(fp) |
|
293 | 293 | |
|
294 | 294 | return 1 |
|
295 | 295 | |
|
296 | 296 | |
|
297 | 297 | |
|
298 | 298 | class ProcessingHeader(Header): |
|
299 | 299 | |
|
300 | 300 | size = None |
|
301 | 301 | dtype = None |
|
302 | 302 | blockSize = None |
|
303 | 303 | profilesPerBlock = None |
|
304 | 304 | dataBlocksPerFile = None |
|
305 | 305 | nWindows = None |
|
306 | 306 | processFlags = None |
|
307 | 307 | nCohInt = None |
|
308 | 308 | nIncohInt = None |
|
309 | 309 | totalSpectra = None |
|
310 | 310 | struct = None |
|
311 | 311 | flag_dc = None |
|
312 | 312 | flag_cspc = None |
|
313 | 313 | |
|
314 | 314 | def __init__(self): |
|
315 | 315 | self.size = 0 |
|
316 | 316 | self.dataType = 0 |
|
317 | 317 | self.blockSize = 0 |
|
318 | 318 | self.profilesPerBlock = 0 |
|
319 | 319 | self.dataBlocksPerFile = 0 |
|
320 | 320 | self.nWindows = 0 |
|
321 | 321 | self.processFlags = 0 |
|
322 | 322 | self.nCohInt = 0 |
|
323 | 323 | self.nIncohInt = 0 |
|
324 | 324 | self.totalSpectra = 0 |
|
325 | 325 | self.struct = numpy.dtype([ |
|
326 | 326 | ('nSize','<u4'), |
|
327 | 327 | ('nDataType','<u4'), |
|
328 | 328 | ('nSizeOfDataBlock','<u4'), |
|
329 | 329 | ('nProfilesperBlock','<u4'), |
|
330 | 330 | ('nDataBlocksperFile','<u4'), |
|
331 | 331 | ('nNumWindows','<u4'), |
|
332 | 332 | ('nProcessFlags','<u4'), |
|
333 | 333 | ('nCoherentIntegrations','<u4'), |
|
334 | 334 | ('nIncoherentIntegrations','<u4'), |
|
335 | 335 | ('nTotalSpectra','<u4') |
|
336 | 336 | ]) |
|
337 | 337 | self.samplingWindow = 0 |
|
338 | 338 | self.structSamplingWindow = numpy.dtype([('h0','<f4'),('dh','<f4'),('nsa','<u4')]) |
|
339 | 339 | self.nHeights = 0 |
|
340 | 340 | self.firstHeight = 0 |
|
341 | 341 | self.deltaHeight = 0 |
|
342 | 342 | self.samplesWin = 0 |
|
343 | 343 | self.spectraComb = 0 |
|
344 | 344 | self.nCode = None |
|
345 | 345 | self.code = None |
|
346 | 346 | self.nBaud = None |
|
347 | 347 | self.shif_fft = False |
|
348 | 348 | self.flag_dc = False |
|
349 | 349 | self.flag_cspc = False |
|
350 | 350 | |
|
351 | 351 | def read(self, fp): |
|
352 | 352 | try: |
|
353 | 353 | header = numpy.fromfile(fp,self.struct,1) |
|
354 | 354 | self.size = header['nSize'][0] |
|
355 | 355 | self.dataType = header['nDataType'][0] |
|
356 | 356 | self.blockSize = header['nSizeOfDataBlock'][0] |
|
357 | 357 | self.profilesPerBlock = header['nProfilesperBlock'][0] |
|
358 | 358 | self.dataBlocksPerFile = header['nDataBlocksperFile'][0] |
|
359 | 359 | self.nWindows = header['nNumWindows'][0] |
|
360 | 360 | self.processFlags = header['nProcessFlags'] |
|
361 | 361 | self.nCohInt = header['nCoherentIntegrations'][0] |
|
362 | 362 | self.nIncohInt = header['nIncoherentIntegrations'][0] |
|
363 | 363 | self.totalSpectra = header['nTotalSpectra'][0] |
|
364 | 364 | self.samplingWindow = numpy.fromfile(fp,self.structSamplingWindow,self.nWindows) |
|
365 | 365 | self.nHeights = numpy.sum(self.samplingWindow['nsa']) |
|
366 | 366 | self.firstHeight = self.samplingWindow['h0'][0] |
|
367 | 367 | self.deltaHeight = self.samplingWindow['dh'][0] |
|
368 | 368 | self.samplesWin = self.samplingWindow['nsa'] |
|
369 | 369 | self.spectraComb = numpy.fromfile(fp,'u1',2*self.totalSpectra) |
|
370 | 370 | |
|
371 | 371 | if ((self.processFlags & PROCFLAG.DEFINE_PROCESS_CODE) == PROCFLAG.DEFINE_PROCESS_CODE): |
|
372 | 372 | self.nCode = numpy.fromfile(fp,'<u4',1) |
|
373 | 373 | self.nBaud = numpy.fromfile(fp,'<u4',1) |
|
374 | 374 | self.code = numpy.fromfile(fp,'<f4',self.nCode*self.nBaud).reshape(self.nBaud,self.nCode) |
|
375 | 375 | |
|
376 | 376 | if ((self.processFlags & PROCFLAG.SHIFT_FFT_DATA) == PROCFLAG.SHIFT_FFT_DATA): |
|
377 | 377 | self.shif_fft = True |
|
378 | 378 | else: |
|
379 | 379 | self.shif_fft = False |
|
380 | 380 | |
|
381 | 381 | if ((self.processFlags & PROCFLAG.SAVE_CHANNELS_DC) == PROCFLAG.SAVE_CHANNELS_DC): |
|
382 | 382 | self.flag_dc = True |
|
383 | 383 | |
|
384 | 384 | nChannels = 0 |
|
385 | 385 | nPairs = 0 |
|
386 | 386 | pairList = [] |
|
387 | 387 | |
|
388 | 388 | for i in range( 0, self.totalSpectra*2, 2 ): |
|
389 | 389 | if self.spectraComb[i] == self.spectraComb[i+1]: |
|
390 | 390 | nChannels = nChannels + 1 #par de canales iguales |
|
391 | 391 | else: |
|
392 | 392 | nPairs = nPairs + 1 #par de canales diferentes |
|
393 | 393 | pairList.append( (self.spectraComb[i], self.spectraComb[i+1]) ) |
|
394 | 394 | |
|
395 | 395 | self.flag_cspc = False |
|
396 | 396 | if nPairs > 0: |
|
397 | 397 | self.flag_cspc = True |
|
398 | 398 | |
|
399 | 399 | except: |
|
400 | 400 | return 0 |
|
401 | 401 | |
|
402 | 402 | return 1 |
|
403 | 403 | |
|
404 | 404 | def write(self, fp): |
|
405 | 405 | headerTuple = (self.size, |
|
406 | 406 | self.dataType, |
|
407 | 407 | self.blockSize, |
|
408 | 408 | self.profilesPerBlock, |
|
409 | 409 | self.dataBlocksPerFile, |
|
410 | 410 | self.nWindows, |
|
411 | 411 | self.processFlags, |
|
412 | 412 | self.nCohInt, |
|
413 | 413 | self.nIncohInt, |
|
414 | 414 | self.totalSpectra) |
|
415 | 415 | |
|
416 | 416 | header = numpy.array(headerTuple,self.struct) |
|
417 | 417 | header.tofile(fp) |
|
418 | 418 | |
|
419 | 419 | if self.nWindows != 0: |
|
420 | 420 | sampleWindowTuple = (self.firstHeight,self.deltaHeight,self.samplesWin) |
|
421 | 421 | samplingWindow = numpy.array(sampleWindowTuple,self.structSamplingWindow) |
|
422 | 422 | samplingWindow.tofile(fp) |
|
423 | 423 | |
|
424 | 424 | |
|
425 | 425 | if self.totalSpectra != 0: |
|
426 | 426 | spectraComb = numpy.array([],numpy.dtype('u1')) |
|
427 | 427 | spectraComb = self.spectraComb |
|
428 | 428 | spectraComb.tofile(fp) |
|
429 | 429 | |
|
430 | 430 | |
|
431 | 431 | if self.processFlags & PROCFLAG.DEFINE_PROCESS_CODE == PROCFLAG.DEFINE_PROCESS_CODE: |
|
432 | nCode = self.nCode | |
|
432 | nCode = self.nCode #Probar con un dato que almacene codigo, hasta el momento no se hizo la prueba | |
|
433 | 433 | nCode.tofile(fp) |
|
434 | 434 | |
|
435 | 435 | nBaud = self.nBaud |
|
436 | 436 | nBaud.tofile(fp) |
|
437 | 437 | |
|
438 | 438 | code = self.code.reshape(nCode*nBaud) |
|
439 | 439 | code.tofile(fp) |
|
440 | 440 | |
|
441 | 441 | return 1 |
|
442 | 442 | |
|
443 | 443 | class RCfunction: |
|
444 | 444 | NONE=0 |
|
445 | 445 | FLIP=1 |
|
446 | 446 | CODE=2 |
|
447 | 447 | SAMPLING=3 |
|
448 | 448 | LIN6DIV256=4 |
|
449 | 449 | SYNCHRO=5 |
|
450 | 450 | |
|
451 | 451 | class nCodeType: |
|
452 | 452 | NONE=0 |
|
453 | 453 | USERDEFINE=1 |
|
454 | 454 | BARKER2=2 |
|
455 | 455 | BARKER3=3 |
|
456 | 456 | BARKER4=4 |
|
457 | 457 | BARKER5=5 |
|
458 | 458 | BARKER7=6 |
|
459 | 459 | BARKER11=7 |
|
460 | 460 | BARKER13=8 |
|
461 | 461 | AC128=9 |
|
462 | 462 | COMPLEMENTARYCODE2=10 |
|
463 | 463 | COMPLEMENTARYCODE4=11 |
|
464 | 464 | COMPLEMENTARYCODE8=12 |
|
465 | 465 | COMPLEMENTARYCODE16=13 |
|
466 | 466 | COMPLEMENTARYCODE32=14 |
|
467 | 467 | COMPLEMENTARYCODE64=15 |
|
468 | 468 | COMPLEMENTARYCODE128=16 |
|
469 | 469 | CODE_BINARY28=17 |
|
470 | 470 | |
|
471 | 471 | class PROCFLAG: |
|
472 | 472 | COHERENT_INTEGRATION = numpy.uint32(0x00000001) |
|
473 | 473 | DECODE_DATA = numpy.uint32(0x00000002) |
|
474 | 474 | SPECTRA_CALC = numpy.uint32(0x00000004) |
|
475 | 475 | INCOHERENT_INTEGRATION = numpy.uint32(0x00000008) |
|
476 | 476 | POST_COHERENT_INTEGRATION = numpy.uint32(0x00000010) |
|
477 | 477 | SHIFT_FFT_DATA = numpy.uint32(0x00000020) |
|
478 | 478 | |
|
479 | 479 | DATATYPE_CHAR = numpy.uint32(0x00000040) |
|
480 | 480 | DATATYPE_SHORT = numpy.uint32(0x00000080) |
|
481 | 481 | DATATYPE_LONG = numpy.uint32(0x00000100) |
|
482 | 482 | DATATYPE_INT64 = numpy.uint32(0x00000200) |
|
483 | 483 | DATATYPE_FLOAT = numpy.uint32(0x00000400) |
|
484 | 484 | DATATYPE_DOUBLE = numpy.uint32(0x00000800) |
|
485 | 485 | |
|
486 | 486 | DATAARRANGE_CONTIGUOUS_CH = numpy.uint32(0x00001000) |
|
487 | 487 | DATAARRANGE_CONTIGUOUS_H = numpy.uint32(0x00002000) |
|
488 | 488 | DATAARRANGE_CONTIGUOUS_P = numpy.uint32(0x00004000) |
|
489 | 489 | |
|
490 | 490 | SAVE_CHANNELS_DC = numpy.uint32(0x00008000) |
|
491 | 491 | DEFLIP_DATA = numpy.uint32(0x00010000) |
|
492 | 492 | DEFINE_PROCESS_CODE = numpy.uint32(0x00020000) |
|
493 | 493 | |
|
494 | 494 | ACQ_SYS_NATALIA = numpy.uint32(0x00040000) |
|
495 | 495 | ACQ_SYS_ECHOTEK = numpy.uint32(0x00080000) |
|
496 | 496 | ACQ_SYS_ADRXD = numpy.uint32(0x000C0000) |
|
497 | 497 | ACQ_SYS_JULIA = numpy.uint32(0x00100000) |
|
498 | 498 | ACQ_SYS_XXXXXX = numpy.uint32(0x00140000) |
|
499 | 499 | |
|
500 | 500 | EXP_NAME_ESP = numpy.uint32(0x00200000) |
|
501 | 501 | CHANNEL_NAMES_ESP = numpy.uint32(0x00400000) |
|
502 | 502 | |
|
503 | 503 | OPERATION_MASK = numpy.uint32(0x0000003F) |
|
504 | 504 | DATATYPE_MASK = numpy.uint32(0x00000FC0) |
|
505 | 505 | DATAARRANGE_MASK = numpy.uint32(0x00007000) |
|
506 | 506 | ACQ_SYS_MASK = numpy.uint32(0x001C0000) No newline at end of file |
@@ -1,748 +1,775 | |||
|
1 | 1 | ''' |
|
2 | 2 | File: SpectraIO.py |
|
3 | 3 | Created on 20/02/2012 |
|
4 | 4 | |
|
5 | 5 | @author $Author: dsuarez $ |
|
6 | 6 | @version $Id: SpectraIO.py 110 2012-07-19 15:18:18Z dsuarez $ |
|
7 | 7 | ''' |
|
8 | 8 | |
|
9 | 9 | import os, sys |
|
10 | 10 | import numpy |
|
11 | 11 | import glob |
|
12 | 12 | import fnmatch |
|
13 | 13 | import time, datetime |
|
14 | 14 | |
|
15 | 15 | path = os.path.split(os.getcwd())[0] |
|
16 | 16 | sys.path.append(path) |
|
17 | 17 | |
|
18 | 18 | from IO.JROHeader import * |
|
19 | 19 | from Data.Spectra import Spectra |
|
20 | 20 | |
|
21 | 21 | from JRODataIO import JRODataReader |
|
22 | 22 | from JRODataIO import JRODataWriter |
|
23 | 23 | from JRODataIO import isNumber |
|
24 | 24 | |
|
25 | 25 | |
|
26 | 26 | class SpectraReader(JRODataReader): |
|
27 | 27 | """ |
|
28 | 28 | Esta clase permite leer datos de espectros desde archivos procesados (.pdata). La lectura |
|
29 | 29 | de los datos siempre se realiza por bloques. Los datos leidos (array de 3 dimensiones) |
|
30 | 30 | son almacenados en tres buffer's para el Self Spectra, el Cross Spectra y el DC Channel. |
|
31 | 31 | |
|
32 | 32 | paresCanalesIguales * alturas * perfiles (Self Spectra) |
|
33 | 33 | paresCanalesDiferentes * alturas * perfiles (Cross Spectra) |
|
34 | 34 | canales * alturas (DC Channels) |
|
35 | 35 | |
|
36 | 36 | Esta clase contiene instancias (objetos) de las clases BasicHeader, SystemHeader, |
|
37 | 37 | RadarControllerHeader y Spectra. Los tres primeros se usan para almacenar informacion de la |
|
38 | 38 | cabecera de datos (metadata), y el cuarto (Spectra) para obtener y almacenar un bloque de |
|
39 | 39 | datos desde el "buffer" cada vez que se ejecute el metodo "getData". |
|
40 | 40 | |
|
41 | 41 | Example: |
|
42 | 42 | dpath = "/home/myuser/data" |
|
43 | 43 | |
|
44 | 44 | startTime = datetime.datetime(2010,1,20,0,0,0,0,0,0) |
|
45 | 45 | |
|
46 | 46 | endTime = datetime.datetime(2010,1,21,23,59,59,0,0,0) |
|
47 | 47 | |
|
48 | 48 | readerObj = SpectraReader() |
|
49 | 49 | |
|
50 | 50 | readerObj.setup(dpath, startTime, endTime) |
|
51 | 51 | |
|
52 | 52 | while(True): |
|
53 | 53 | |
|
54 | 54 | readerObj.getData() |
|
55 | 55 | |
|
56 | 56 | print readerObj.dataOutObj.data |
|
57 | 57 | |
|
58 | 58 | if readerObj.flagNoMoreFiles: |
|
59 | 59 | break |
|
60 | 60 | |
|
61 | 61 | """ |
|
62 | 62 | |
|
63 | 63 | pts2read_SelfSpectra = 0 |
|
64 | 64 | |
|
65 | 65 | pts2read_CrossSpectra = 0 |
|
66 | 66 | |
|
67 | 67 | pts2read_DCchannels = 0 |
|
68 | 68 | |
|
69 | 69 | ext = ".pdata" |
|
70 | 70 | |
|
71 | 71 | optchar = "P" |
|
72 | 72 | |
|
73 | 73 | dataOutObj = None |
|
74 | 74 | |
|
75 | 75 | nRdChannels = None |
|
76 | 76 | |
|
77 | 77 | nRdPairs = None |
|
78 | 78 | |
|
79 | 79 | rdPairList = [] |
|
80 | 80 | |
|
81 | 81 | |
|
82 | 82 | def __init__(self, dataOutObj=None): |
|
83 | 83 | """ |
|
84 | 84 | Inicializador de la clase SpectraReader para la lectura de datos de espectros. |
|
85 | 85 | |
|
86 | 86 | Inputs: |
|
87 | 87 | dataOutObj : Objeto de la clase Spectra. Este objeto sera utilizado para |
|
88 | 88 | almacenar un perfil de datos cada vez que se haga un requerimiento |
|
89 | 89 | (getData). El perfil sera obtenido a partir del buffer de datos, |
|
90 | 90 | si el buffer esta vacio se hara un nuevo proceso de lectura de un |
|
91 | 91 | bloque de datos. |
|
92 | 92 | Si este parametro no es pasado se creara uno internamente. |
|
93 | 93 | |
|
94 | 94 | Affected: |
|
95 | 95 | self.dataOutObj |
|
96 | 96 | |
|
97 | 97 | Return : None |
|
98 | 98 | """ |
|
99 | 99 | |
|
100 | 100 | self.pts2read_SelfSpectra = 0 |
|
101 | 101 | |
|
102 | 102 | self.pts2read_CrossSpectra = 0 |
|
103 | 103 | |
|
104 | 104 | self.pts2read_DCchannels = 0 |
|
105 | 105 | |
|
106 | 106 | self.datablock = None |
|
107 | 107 | |
|
108 | 108 | self.utc = None |
|
109 | 109 | |
|
110 | 110 | self.ext = ".pdata" |
|
111 | 111 | |
|
112 | 112 | self.optchar = "P" |
|
113 | 113 | |
|
114 | 114 | self.basicHeaderObj = BasicHeader() |
|
115 | 115 | |
|
116 | 116 | self.systemHeaderObj = SystemHeader() |
|
117 | 117 | |
|
118 | 118 | self.radarControllerHeaderObj = RadarControllerHeader() |
|
119 | 119 | |
|
120 | 120 | self.processingHeaderObj = ProcessingHeader() |
|
121 | 121 | |
|
122 | 122 | self.online = 0 |
|
123 | 123 | |
|
124 | 124 | self.fp = None |
|
125 | 125 | |
|
126 | 126 | self.idFile = None |
|
127 | 127 | |
|
128 | 128 | self.dtype = None |
|
129 | 129 | |
|
130 | 130 | self.fileSizeByHeader = None |
|
131 | 131 | |
|
132 | 132 | self.filenameList = [] |
|
133 | 133 | |
|
134 | 134 | self.filename = None |
|
135 | 135 | |
|
136 | 136 | self.fileSize = None |
|
137 | 137 | |
|
138 | 138 | self.firstHeaderSize = 0 |
|
139 | 139 | |
|
140 | 140 | self.basicHeaderSize = 24 |
|
141 | 141 | |
|
142 | 142 | self.pathList = [] |
|
143 | 143 | |
|
144 | 144 | self.lastUTTime = 0 |
|
145 | 145 | |
|
146 | 146 | self.maxTimeStep = 30 |
|
147 | 147 | |
|
148 | 148 | self.flagNoMoreFiles = 0 |
|
149 | 149 | |
|
150 | 150 | self.set = 0 |
|
151 | 151 | |
|
152 | 152 | self.path = None |
|
153 | 153 | |
|
154 | 154 | self.delay = 3 #seconds |
|
155 | 155 | |
|
156 | 156 | self.nTries = 3 #quantity tries |
|
157 | 157 | |
|
158 | 158 | self.nFiles = 3 #number of files for searching |
|
159 | 159 | |
|
160 | 160 | self.nReadBlocks = 0 |
|
161 | 161 | |
|
162 | 162 | self.flagIsNewFile = 1 |
|
163 | 163 | |
|
164 | 164 | self.ippSeconds = 0 |
|
165 | 165 | |
|
166 | 166 | self.flagTimeBlock = 0 |
|
167 | 167 | |
|
168 | 168 | self.flagIsNewBlock = 0 |
|
169 | 169 | |
|
170 | 170 | self.nTotalBlocks = 0 |
|
171 | 171 | |
|
172 | 172 | self.blocksize = 0 |
|
173 | 173 | |
|
174 | 174 | |
|
175 | 175 | def createObjByDefault(self): |
|
176 | 176 | |
|
177 | 177 | dataObj = Spectra() |
|
178 | 178 | |
|
179 | 179 | return dataObj |
|
180 | 180 | |
|
181 | 181 | def __hasNotDataInBuffer(self): |
|
182 | 182 | return 1 |
|
183 | 183 | |
|
184 | 184 | |
|
185 | 185 | def getBlockDimension(self): |
|
186 | 186 | """ |
|
187 | 187 | Obtiene la cantidad de puntos a leer por cada bloque de datos |
|
188 | 188 | |
|
189 | 189 | Affected: |
|
190 | 190 | self.nRdChannels |
|
191 | 191 | self.nRdPairs |
|
192 | 192 | self.pts2read_SelfSpectra |
|
193 | 193 | self.pts2read_CrossSpectra |
|
194 | 194 | self.pts2read_DCchannels |
|
195 | 195 | self.blocksize |
|
196 | 196 | self.dataOutObj.nChannels |
|
197 | 197 | self.dataOutObj.nPairs |
|
198 | 198 | |
|
199 | 199 | Return: |
|
200 | 200 | None |
|
201 | 201 | """ |
|
202 | 202 | self.nRdChannels = 0 |
|
203 | 203 | self.nRdPairs = 0 |
|
204 | 204 | self.rdPairList = [] |
|
205 | 205 | |
|
206 | 206 | for i in range(0, self.processingHeaderObj.totalSpectra*2, 2): |
|
207 | 207 | if self.processingHeaderObj.spectraComb[i] == self.processingHeaderObj.spectraComb[i+1]: |
|
208 | 208 | self.nRdChannels = self.nRdChannels + 1 #par de canales iguales |
|
209 | 209 | else: |
|
210 | 210 | self.nRdPairs = self.nRdPairs + 1 #par de canales diferentes |
|
211 | 211 | self.rdPairList.append((self.processingHeaderObj.spectraComb[i], self.processingHeaderObj.spectraComb[i+1])) |
|
212 | 212 | |
|
213 | 213 | pts2read = self.processingHeaderObj.nHeights * self.processingHeaderObj.profilesPerBlock |
|
214 | 214 | |
|
215 | 215 | self.pts2read_SelfSpectra = int(self.nRdChannels * pts2read) |
|
216 | 216 | self.blocksize = self.pts2read_SelfSpectra |
|
217 | 217 | |
|
218 | 218 | if self.processingHeaderObj.flag_cspc: |
|
219 | 219 | self.pts2read_CrossSpectra = int(self.nRdPairs * pts2read) |
|
220 | 220 | self.blocksize += self.pts2read_CrossSpectra |
|
221 | 221 | |
|
222 | 222 | if self.processingHeaderObj.flag_dc: |
|
223 | 223 | self.pts2read_DCchannels = int(self.systemHeaderObj.nChannels * self.processingHeaderObj.nHeights) |
|
224 | 224 | self.blocksize += self.pts2read_DCchannels |
|
225 | 225 | |
|
226 | 226 | # self.blocksize = self.pts2read_SelfSpectra + self.pts2read_CrossSpectra + self.pts2read_DCchannels |
|
227 | 227 | |
|
228 | 228 | |
|
229 | 229 | def readBlock(self): |
|
230 | 230 | """ |
|
231 | 231 | Lee el bloque de datos desde la posicion actual del puntero del archivo |
|
232 | 232 | (self.fp) y actualiza todos los parametros relacionados al bloque de datos |
|
233 | 233 | (metadata + data). La data leida es almacenada en el buffer y el contador del buffer |
|
234 | 234 | es seteado a 0 |
|
235 | 235 | |
|
236 | 236 | Return: None |
|
237 | 237 | |
|
238 | 238 | Variables afectadas: |
|
239 | 239 | |
|
240 | 240 | self.flagIsNewFile |
|
241 | 241 | self.flagIsNewBlock |
|
242 | 242 | self.nTotalBlocks |
|
243 | 243 | self.data_spc |
|
244 | 244 | self.data_cspc |
|
245 | 245 | self.data_dc |
|
246 | 246 | |
|
247 | 247 | Exceptions: |
|
248 | 248 | Si un bloque leido no es un bloque valido |
|
249 | 249 | """ |
|
250 | 250 | blockOk_flag = False |
|
251 | 251 | fpointer = self.fp.tell() |
|
252 | 252 | |
|
253 | 253 | spc = numpy.fromfile( self.fp, self.dtype[0], self.pts2read_SelfSpectra ) |
|
254 | 254 | spc = spc.reshape( (self.nRdChannels, self.processingHeaderObj.nHeights, self.processingHeaderObj.profilesPerBlock) ) #transforma a un arreglo 3D |
|
255 | 255 | |
|
256 | 256 | if self.processingHeaderObj.flag_cspc: |
|
257 | 257 | cspc = numpy.fromfile( self.fp, self.dtype, self.pts2read_CrossSpectra ) |
|
258 | 258 | cspc = cspc.reshape( (self.nRdPairs, self.processingHeaderObj.nHeights, self.processingHeaderObj.profilesPerBlock) ) #transforma a un arreglo 3D |
|
259 | 259 | |
|
260 | 260 | if self.processingHeaderObj.flag_dc: |
|
261 | 261 | dc = numpy.fromfile( self.fp, self.dtype, self.pts2read_DCchannels ) #int(self.processingHeaderObj.nHeights*self.systemHeaderObj.nChannels) ) |
|
262 | 262 | dc = dc.reshape( (self.systemHeaderObj.nChannels, self.processingHeaderObj.nHeights) ) #transforma a un arreglo 2D |
|
263 | 263 | |
|
264 | 264 | |
|
265 | 265 | if not(self.processingHeaderObj.shif_fft): |
|
266 | 266 | spc = numpy.roll( spc, self.processingHeaderObj.profilesPerBlock/2, axis=2 ) #desplaza a la derecha en el eje 2 determinadas posiciones |
|
267 | 267 | |
|
268 | 268 | if self.processingHeaderObj.flag_cspc: |
|
269 | 269 | cspc = numpy.roll( cspc, self.processingHeaderObj.profilesPerBlock/2, axis=2 ) #desplaza a la derecha en el eje 2 determinadas posiciones |
|
270 | 270 | |
|
271 | 271 | |
|
272 | 272 | spc = numpy.transpose( spc, (0,2,1) ) |
|
273 | 273 | self.data_spc = spc |
|
274 | 274 | |
|
275 | 275 | if self.processingHeaderObj.flag_cspc: |
|
276 | 276 | cspc = numpy.transpose( cspc, (0,2,1) ) |
|
277 | 277 | self.data_cspc = cspc['real'] + cspc['imag']*1j |
|
278 | 278 | else: |
|
279 | 279 | self.data_cspc = None |
|
280 | 280 | |
|
281 | 281 | if self.processingHeaderObj.flag_dc: |
|
282 | 282 | self.data_dc = dc['real'] + dc['imag']*1j |
|
283 | 283 | else: |
|
284 | 284 | self.data_dc = None |
|
285 | 285 | |
|
286 | 286 | self.flagIsNewFile = 0 |
|
287 | 287 | self.flagIsNewBlock = 1 |
|
288 | 288 | |
|
289 | 289 | self.nTotalBlocks += 1 |
|
290 | 290 | self.nReadBlocks += 1 |
|
291 | 291 | |
|
292 | 292 | return 1 |
|
293 | 293 | |
|
294 | 294 | |
|
295 | 295 | def getData(self): |
|
296 | 296 | """ |
|
297 | 297 | Copia el buffer de lectura a la clase "Spectra", |
|
298 | 298 | con todos los parametros asociados a este (metadata). cuando no hay datos en el buffer de |
|
299 | 299 | lectura es necesario hacer una nueva lectura de los bloques de datos usando "readNextBlock" |
|
300 | 300 | |
|
301 | 301 | Return: |
|
302 | 302 | 0 : Si no hay mas archivos disponibles |
|
303 | 303 | 1 : Si hizo una buena copia del buffer |
|
304 | 304 | |
|
305 | 305 | Affected: |
|
306 | 306 | self.dataOutObj |
|
307 | 307 | |
|
308 | 308 | self.flagTimeBlock |
|
309 | 309 | self.flagIsNewBlock |
|
310 | 310 | """ |
|
311 | 311 | |
|
312 | 312 | if self.flagNoMoreFiles: return 0 |
|
313 | 313 | |
|
314 | 314 | self.flagTimeBlock = 0 |
|
315 | 315 | self.flagIsNewBlock = 0 |
|
316 | 316 | |
|
317 | 317 | if self.__hasNotDataInBuffer(): |
|
318 | 318 | |
|
319 | 319 | if not( self.readNextBlock() ): |
|
320 | 320 | return 0 |
|
321 | 321 | |
|
322 | 322 | # self.updateDataHeader() |
|
323 | 323 | |
|
324 | 324 | if self.flagNoMoreFiles == 1: |
|
325 | 325 | print 'Process finished' |
|
326 | 326 | return 0 |
|
327 | 327 | |
|
328 | 328 | #data es un numpy array de 3 dmensiones (perfiles, alturas y canales) |
|
329 | 329 | |
|
330 | 330 | if self.data_dc == None: |
|
331 | 331 | self.dataOutObj.flagNoData = True |
|
332 | 332 | return 0 |
|
333 | 333 | |
|
334 | 334 | |
|
335 | 335 | self.dataOutObj.data_spc = self.data_spc |
|
336 | 336 | |
|
337 | 337 | self.dataOutObj.data_cspc = self.data_cspc |
|
338 | 338 | |
|
339 | 339 | self.dataOutObj.data_dc = self.data_dc |
|
340 | 340 | |
|
341 | 341 | self.dataOutObj.flagTimeBlock = self.flagTimeBlock |
|
342 | 342 | |
|
343 | 343 | self.dataOutObj.flagNoData = False |
|
344 | 344 | |
|
345 | 345 | self.dataOutObj.dtype = self.dtype |
|
346 | 346 | |
|
347 | 347 | self.dataOutObj.nChannels = self.nRdChannels |
|
348 | 348 | |
|
349 | 349 | self.dataOutObj.nPairs = self.nRdPairs |
|
350 | 350 | |
|
351 | 351 | self.dataOutObj.pairsList = self.rdPairList |
|
352 | 352 | |
|
353 | 353 | self.dataOutObj.nHeights = self.processingHeaderObj.nHeights |
|
354 | 354 | |
|
355 | 355 | self.dataOutObj.nProfiles = self.processingHeaderObj.profilesPerBlock |
|
356 | 356 | |
|
357 | 357 | self.dataOutObj.nFFTPoints = self.processingHeaderObj.profilesPerBlock |
|
358 | 358 | |
|
359 | 359 | self.dataOutObj.nIncohInt = self.processingHeaderObj.nIncohInt |
|
360 | 360 | |
|
361 | 361 | |
|
362 | 362 | xf = self.processingHeaderObj.firstHeight + self.processingHeaderObj.nHeights*self.processingHeaderObj.deltaHeight |
|
363 | 363 | |
|
364 | 364 | self.dataOutObj.heightList = numpy.arange(self.processingHeaderObj.firstHeight, xf, self.processingHeaderObj.deltaHeight) |
|
365 | 365 | |
|
366 | 366 | self.dataOutObj.channelList = range(self.systemHeaderObj.nChannels) |
|
367 | 367 | |
|
368 | 368 | self.dataOutObj.channelIndexList = range(self.systemHeaderObj.nChannels) |
|
369 | 369 | |
|
370 | 370 | self.dataOutObj.dataUtcTime = self.basicHeaderObj.utc #+ self.profileIndex * self.ippSeconds |
|
371 | 371 | |
|
372 | 372 | self.dataOutObj.flagShiftFFT = self.processingHeaderObj.shif_fft |
|
373 | 373 | |
|
374 | 374 | # self.profileIndex += 1 |
|
375 | 375 | |
|
376 | 376 | self.dataOutObj.systemHeaderObj = self.systemHeaderObj.copy() |
|
377 | 377 | |
|
378 | 378 | self.dataOutObj.radarControllerHeaderObj = self.radarControllerHeaderObj.copy() |
|
379 | 379 | |
|
380 | 380 | return 1 |
|
381 | 381 | |
|
382 | 382 | |
|
383 | 383 | class SpectraWriter(JRODataWriter): |
|
384 | 384 | |
|
385 | 385 | """ |
|
386 | 386 | Esta clase permite escribir datos de espectros a archivos procesados (.pdata). La escritura |
|
387 | 387 | de los datos siempre se realiza por bloques. |
|
388 | 388 | """ |
|
389 | 389 | |
|
390 | 390 | ext = ".pdata" |
|
391 | 391 | |
|
392 | 392 | optchar = "P" |
|
393 | 393 | |
|
394 | 394 | shape_spc_Buffer = None |
|
395 | 395 | |
|
396 | 396 | shape_cspc_Buffer = None |
|
397 | 397 | |
|
398 | 398 | shape_dc_Buffer = None |
|
399 | 399 | |
|
400 | 400 | data_spc = None |
|
401 | 401 | |
|
402 | 402 | data_cspc = None |
|
403 | 403 | |
|
404 | 404 | data_dc = None |
|
405 | 405 | |
|
406 | 406 | wrPairList = [] |
|
407 | 407 | |
|
408 | 408 | nWrPairs = 0 |
|
409 | 409 | |
|
410 | 410 | nWrChannels = 0 |
|
411 | 411 | |
|
412 | 412 | # dataOutObj = None |
|
413 | 413 | |
|
414 | 414 | def __init__(self, dataOutObj=None): |
|
415 | 415 | """ |
|
416 | 416 | Inicializador de la clase SpectraWriter para la escritura de datos de espectros. |
|
417 | 417 | |
|
418 | 418 | Affected: |
|
419 | 419 | self.dataOutObj |
|
420 | 420 | self.basicHeaderObj |
|
421 | 421 | self.systemHeaderObj |
|
422 | 422 | self.radarControllerHeaderObj |
|
423 | 423 | self.processingHeaderObj |
|
424 | 424 | |
|
425 | 425 | Return: None |
|
426 | 426 | """ |
|
427 | 427 | if dataOutObj == None: |
|
428 | 428 | dataOutObj = Spectra() |
|
429 | 429 | |
|
430 | 430 | if not( isinstance(dataOutObj, Spectra) ): |
|
431 | 431 | raise ValueError, "in SpectraReader, dataOutObj must be an Spectra class object" |
|
432 | 432 | |
|
433 | 433 | self.dataOutObj = dataOutObj |
|
434 | 434 | |
|
435 | 435 | self.nTotalBlocks = 0 |
|
436 | 436 | |
|
437 | 437 | self.nWrChannels = self.dataOutObj.nChannels |
|
438 | 438 | |
|
439 | 439 | # if len(pairList) > 0: |
|
440 | 440 | # self.wrPairList = pairList |
|
441 | 441 | # |
|
442 | 442 | # self.nWrPairs = len(pairList) |
|
443 | 443 | |
|
444 | self.wrPairList = self.dataOutObj.pairList | |
|
444 | self.wrPairList = self.dataOutObj.pairsList | |
|
445 | 445 | |
|
446 | 446 | self.nWrPairs = self.dataOutObj.nPairs |
|
447 | 447 | |
|
448 | 448 | |
|
449 | 449 | |
|
450 | 450 | |
|
451 | 451 | |
|
452 | 452 | # self.data_spc = None |
|
453 | 453 | # self.data_cspc = None |
|
454 | 454 | # self.data_dc = None |
|
455 | 455 | |
|
456 | 456 | # self.fp = None |
|
457 | 457 | |
|
458 | 458 | # self.flagIsNewFile = 1 |
|
459 | 459 | # |
|
460 | 460 | # self.nTotalBlocks = 0 |
|
461 | 461 | # |
|
462 | 462 | # self.flagIsNewBlock = 0 |
|
463 | 463 | # |
|
464 | 464 | # self.flagNoMoreFiles = 0 |
|
465 | 465 | # |
|
466 | 466 | # self.setFile = None |
|
467 | 467 | # |
|
468 | 468 | # self.dtype = None |
|
469 | 469 | # |
|
470 | 470 | # self.path = None |
|
471 | 471 | # |
|
472 | 472 | # self.noMoreFiles = 0 |
|
473 | 473 | # |
|
474 | 474 | # self.filename = None |
|
475 | 475 | # |
|
476 | 476 | # self.basicHeaderObj = BasicHeader() |
|
477 | 477 | # |
|
478 | 478 | # self.systemHeaderObj = SystemHeader() |
|
479 | 479 | # |
|
480 | 480 | # self.radarControllerHeaderObj = RadarControllerHeader() |
|
481 | 481 | # |
|
482 | 482 | # self.processingHeaderObj = ProcessingHeader() |
|
483 | 483 | |
|
484 | 484 | |
|
485 | 485 | def hasAllDataInBuffer(self): |
|
486 | 486 | return 1 |
|
487 | 487 | |
|
488 | 488 | |
|
489 | 489 | def setBlockDimension(self): |
|
490 | 490 | """ |
|
491 | 491 | Obtiene las formas dimensionales del los subbloques de datos que componen un bloque |
|
492 | 492 | |
|
493 | 493 | Affected: |
|
494 | 494 | self.shape_spc_Buffer |
|
495 | 495 | self.shape_cspc_Buffer |
|
496 | 496 | self.shape_dc_Buffer |
|
497 | 497 | |
|
498 | 498 | Return: None |
|
499 | 499 | """ |
|
500 | 500 | self.shape_spc_Buffer = (self.dataOutObj.nChannels, |
|
501 | 501 | self.processingHeaderObj.nHeights, |
|
502 | 502 | self.processingHeaderObj.profilesPerBlock) |
|
503 | 503 | |
|
504 | 504 | self.shape_cspc_Buffer = (self.dataOutObj.nPairs, |
|
505 | 505 | self.processingHeaderObj.nHeights, |
|
506 | 506 | self.processingHeaderObj.profilesPerBlock) |
|
507 | 507 | |
|
508 |
self.shape_dc_Buffer = (self. |
|
|
508 | self.shape_dc_Buffer = (self.dataOutObj.nChannels, | |
|
509 | 509 | self.processingHeaderObj.nHeights) |
|
510 | 510 | |
|
511 | 511 | |
|
512 | 512 | def writeBlock(self): |
|
513 | 513 | """ |
|
514 | 514 | Escribe el buffer en el file designado |
|
515 | 515 | |
|
516 | 516 | Affected: |
|
517 | 517 | self.data_spc |
|
518 | 518 | self.data_cspc |
|
519 | 519 | self.data_dc |
|
520 | 520 | self.flagIsNewFile |
|
521 | 521 | self.flagIsNewBlock |
|
522 | 522 | self.nTotalBlocks |
|
523 | 523 | self.nWriteBlocks |
|
524 | 524 | |
|
525 | 525 | Return: None |
|
526 | 526 | """ |
|
527 | 527 | |
|
528 | 528 | spc = numpy.transpose( self.data_spc, (0,2,1) ) |
|
529 | 529 | if not( self.processingHeaderObj.shif_fft ): |
|
530 | 530 | spc = numpy.roll( spc, self.processingHeaderObj.profilesPerBlock/2, axis=2 ) #desplaza a la derecha en el eje 2 determinadas posiciones |
|
531 | 531 | data = spc.reshape((-1)) |
|
532 | 532 | data.tofile(self.fp) |
|
533 | 533 | |
|
534 | 534 | if self.data_cspc != None: |
|
535 | 535 | data = numpy.zeros( self.shape_cspc_Buffer, self.dtype ) |
|
536 | 536 | cspc = numpy.transpose( self.data_cspc, (0,2,1) ) |
|
537 | 537 | if not( self.processingHeaderObj.shif_fft ): |
|
538 | 538 | cspc = numpy.roll( cspc, self.processingHeaderObj.profilesPerBlock/2, axis=2 ) #desplaza a la derecha en el eje 2 determinadas posiciones |
|
539 | 539 | data['real'] = cspc.real |
|
540 | 540 | data['imag'] = cspc.imag |
|
541 | 541 | data = data.reshape((-1)) |
|
542 | 542 | data.tofile(self.fp) |
|
543 | 543 | |
|
544 | 544 | data = numpy.zeros( self.shape_dc_Buffer, self.dtype ) |
|
545 | 545 | dc = self.data_dc |
|
546 | 546 | data['real'] = dc.real |
|
547 | 547 | data['imag'] = dc.imag |
|
548 | 548 | data = data.reshape((-1)) |
|
549 | 549 | data.tofile(self.fp) |
|
550 | 550 | |
|
551 | 551 | self.data_spc.fill(0) |
|
552 | 552 | self.data_dc.fill(0) |
|
553 | 553 | if self.data_cspc != None: |
|
554 | 554 | self.data_cspc.fill(0) |
|
555 | 555 | |
|
556 | 556 | self.flagIsNewFile = 0 |
|
557 | 557 | self.flagIsNewBlock = 1 |
|
558 | 558 | self.nTotalBlocks += 1 |
|
559 | 559 | self.nWriteBlocks += 1 |
|
560 | 560 | |
|
561 | 561 | |
|
562 | 562 | def putData(self): |
|
563 | 563 | """ |
|
564 | 564 | Setea un bloque de datos y luego los escribe en un file |
|
565 | 565 | |
|
566 | 566 | Affected: |
|
567 | 567 | self.data_spc |
|
568 | 568 | self.data_cspc |
|
569 | 569 | self.data_dc |
|
570 | 570 | |
|
571 | 571 | Return: |
|
572 | 572 | 0 : Si no hay data o no hay mas files que puedan escribirse |
|
573 | 573 | 1 : Si se escribio la data de un bloque en un file |
|
574 | 574 | """ |
|
575 | 575 | self.flagIsNewBlock = 0 |
|
576 | 576 | |
|
577 | 577 | if self.dataOutObj.flagNoData: |
|
578 | 578 | return 0 |
|
579 | 579 | |
|
580 | 580 | if self.dataOutObj.flagTimeBlock: |
|
581 | 581 | self.data_spc.fill(0) |
|
582 | 582 | self.data_cspc.fill(0) |
|
583 | 583 | self.data_dc.fill(0) |
|
584 | 584 | self.setNextFile() |
|
585 | 585 | |
|
586 | if self.flagIsNewFile == 0: | |
|
587 | self.getBasicHeader() | |
|
588 | ||
|
586 | 589 | self.data_spc = self.dataOutObj.data_spc |
|
587 | 590 | self.data_cspc = self.dataOutObj.data_cspc |
|
588 | 591 | self.data_dc = self.dataOutObj.data_dc |
|
589 | 592 | |
|
590 | 593 | # #self.processingHeaderObj.dataBlocksPerFile) |
|
591 | 594 | if self.hasAllDataInBuffer(): |
|
592 | self.getDataHeader() | |
|
595 | # self.getDataHeader() | |
|
593 | 596 | self.writeNextBlock() |
|
594 | 597 | |
|
595 | 598 | if self.flagNoMoreFiles: |
|
596 | 599 | #print 'Process finished' |
|
597 | 600 | return 0 |
|
598 | 601 | |
|
599 | 602 | return 1 |
|
600 | 603 | |
|
601 | 604 | |
|
602 | 605 | def __getProcessFlags(self): |
|
603 | 606 | |
|
604 | 607 | processFlags = 0 |
|
605 | 608 | |
|
606 | 609 | dtype0 = numpy.dtype([('real','<i1'),('imag','<i1')]) |
|
607 | 610 | dtype1 = numpy.dtype([('real','<i2'),('imag','<i2')]) |
|
608 | 611 | dtype2 = numpy.dtype([('real','<i4'),('imag','<i4')]) |
|
609 | 612 | dtype3 = numpy.dtype([('real','<i8'),('imag','<i8')]) |
|
610 | 613 | dtype4 = numpy.dtype([('real','<f4'),('imag','<f4')]) |
|
611 | 614 | dtype5 = numpy.dtype([('real','<f8'),('imag','<f8')]) |
|
612 | 615 | |
|
613 | 616 | dtypeList = [dtype0, dtype1, dtype2, dtype3, dtype4, dtype5] |
|
614 | 617 | |
|
615 | 618 | |
|
616 | 619 | |
|
617 | 620 | datatypeValueList = [PROCFLAG.DATATYPE_CHAR, |
|
618 | 621 | PROCFLAG.DATATYPE_SHORT, |
|
619 | 622 | PROCFLAG.DATATYPE_LONG, |
|
620 | 623 | PROCFLAG.DATATYPE_INT64, |
|
621 | 624 | PROCFLAG.DATATYPE_FLOAT, |
|
622 | 625 | PROCFLAG.DATATYPE_DOUBLE] |
|
623 | 626 | |
|
624 | 627 | |
|
625 | 628 | for index in range(len(dtypeList)): |
|
626 | 629 | if self.dataOutObj.dtype == dtypeList[index]: |
|
627 | 630 | dtypeValue = datatypeValueList[index] |
|
628 | 631 | break |
|
629 | 632 | |
|
630 | 633 | processFlags += dtypeValue |
|
631 | 634 | |
|
632 | 635 | if self.dataOutObj.flagDecodeData: |
|
633 | 636 | processFlags += PROCFLAG.DECODE_DATA |
|
634 | 637 | |
|
635 | 638 | if self.dataOutObj.flagDeflipData: |
|
636 | 639 | processFlags += PROCFLAG.DEFLIP_DATA |
|
637 | 640 | |
|
638 | 641 | if self.dataOutObj.code != None: |
|
639 | 642 | processFlags += PROCFLAG.DEFINE_PROCESS_CODE |
|
640 | 643 | |
|
641 | 644 | if self.dataOutObj.nIncohInt > 1: |
|
642 | 645 | processFlags += PROCFLAG.INCOHERENT_INTEGRATION |
|
643 | 646 | |
|
644 | 647 | if self.dataOutObj.data_dc != None: |
|
645 | 648 | processFlags += PROCFLAG.SAVE_CHANNELS_DC |
|
646 | 649 | |
|
647 | 650 | return processFlags |
|
648 | 651 | |
|
649 | 652 | |
|
650 | 653 | def __getBlockSize(self): |
|
651 | 654 | ''' |
|
652 | 655 | Este metodos determina el cantidad de bytes para un bloque de datos de tipo Spectra |
|
653 | 656 | ''' |
|
654 | 657 | |
|
655 | 658 | dtype0 = numpy.dtype([('real','<i1'),('imag','<i1')]) |
|
656 | 659 | dtype1 = numpy.dtype([('real','<i2'),('imag','<i2')]) |
|
657 | 660 | dtype2 = numpy.dtype([('real','<i4'),('imag','<i4')]) |
|
658 | 661 | dtype3 = numpy.dtype([('real','<i8'),('imag','<i8')]) |
|
659 | 662 | dtype4 = numpy.dtype([('real','<f4'),('imag','<f4')]) |
|
660 | 663 | dtype5 = numpy.dtype([('real','<f8'),('imag','<f8')]) |
|
661 | 664 | |
|
662 | 665 | dtypeList = [dtype0, dtype1, dtype2, dtype3, dtype4, dtype5] |
|
663 | 666 | datatypeValueList = [1,2,4,8,4,8] |
|
664 | 667 | for index in range(len(dtypeList)): |
|
665 | 668 | if self.dataOutObj.dtype == dtypeList[index]: |
|
666 | 669 | datatypeValue = datatypeValueList[index] |
|
667 | 670 | break |
|
668 | 671 | |
|
669 | 672 | |
|
670 | 673 | pts2write = self.dataOutObj.nHeights * self.dataOutObj.nFFTPoints |
|
671 | 674 | |
|
672 | 675 | pts2write_SelfSpectra = int(self.nWrChannels * pts2write) |
|
673 | 676 | blocksize = pts2write_SelfSpectra |
|
674 | 677 | |
|
675 | 678 | if self.dataOutObj.data_cspc != None: |
|
676 | 679 | pts2write_CrossSpectra = int(self.nWrPairs * pts2write) |
|
677 | 680 | blocksize += pts2write_CrossSpectra |
|
678 | 681 | |
|
679 | 682 | if self.dataOutObj.data_dc != None: |
|
680 | 683 | pts2write_DCchannels = int(self.nWrChannels * self.dataOutObj.nHeights) |
|
681 | 684 | blocksize += pts2write_DCchannels |
|
682 | 685 | |
|
683 | 686 | blocksize = blocksize * datatypeValue * 2 |
|
684 | 687 | |
|
685 | 688 | return blocksize |
|
686 | 689 | |
|
687 | 690 | |
|
688 | 691 | def getBasicHeader(self): |
|
689 | 692 | self.basicHeaderObj.size = self.basicHeaderSize #bytes |
|
690 | 693 | self.basicHeaderObj.version = self.versionFile |
|
691 | 694 | self.basicHeaderObj.dataBlock = self.nTotalBlocks |
|
692 | 695 | |
|
693 | 696 | utc = numpy.floor(self.dataOutObj.dataUtcTime) |
|
694 | 697 | milisecond = (self.dataOutObj.dataUtcTime - utc)* 1000.0 |
|
695 | 698 | |
|
696 | 699 | self.basicHeaderObj.utc = utc |
|
697 | 700 | self.basicHeaderObj.miliSecond = milisecond |
|
698 | 701 | self.basicHeaderObj.timeZone = 0 |
|
699 | 702 | self.basicHeaderObj.dstFlag = 0 |
|
700 | 703 | self.basicHeaderObj.errorCount = 0 |
|
701 | 704 | |
|
702 | 705 | def getDataHeader(self): |
|
703 | 706 | |
|
704 | 707 | """ |
|
705 | 708 | Obtiene una copia del First Header |
|
706 | 709 | |
|
707 | 710 | Affected: |
|
708 | 711 | self.systemHeaderObj |
|
709 | 712 | self.radarControllerHeaderObj |
|
710 | 713 | self.dtype |
|
711 | 714 | |
|
712 | 715 | Return: |
|
713 | 716 | None |
|
714 | 717 | """ |
|
715 | 718 | |
|
716 | 719 | self.systemHeaderObj = self.dataOutObj.systemHeaderObj.copy() |
|
720 | self.systemHeaderObj.nChannels = self.dataOutObj.nChannels | |
|
717 | 721 | self.radarControllerHeaderObj = self.dataOutObj.radarControllerHeaderObj.copy() |
|
718 | 722 | |
|
719 | 723 | self.getBasicHeader() |
|
720 | 724 | |
|
721 | 725 | processingHeaderSize = 40 # bytes |
|
722 | 726 | self.processingHeaderObj.dtype = 0 # Voltage |
|
723 | 727 | self.processingHeaderObj.blockSize = self.__getBlockSize() |
|
724 |
self.processingHeaderObj.profilesPerBlock = self. |
|
|
728 | self.processingHeaderObj.profilesPerBlock = self.dataOutObj.nFFTPoints | |
|
725 | 729 | self.processingHeaderObj.dataBlocksPerFile = self.blocksPerFile |
|
726 | 730 | self.processingHeaderObj.nWindows = 1 #podria ser 1 o self.dataOutObj.processingHeaderObj.nWindows |
|
727 | 731 | self.processingHeaderObj.processFlags = self.__getProcessFlags() |
|
728 |
self.processingHeaderObj.nCohInt = |
|
|
729 |
self.processingHeaderObj.nIncohInt = |
|
|
730 |
self.processingHeaderObj.totalSpectra = |
|
|
732 | self.processingHeaderObj.nCohInt = 1# Cuando la data de origen es de tipo Spectra | |
|
733 | self.processingHeaderObj.nIncohInt = self.dataOutObj.nIncohInt | |
|
734 | self.processingHeaderObj.totalSpectra = self.dataOutObj.nPairs + self.dataOutObj.nChannels | |
|
735 | ||
|
736 | if self.processingHeaderObj.totalSpectra > 0: | |
|
737 | channelList = [] | |
|
738 | for channel in range(self.dataOutObj.nChannels): | |
|
739 | channelList.append(channel) | |
|
740 | channelList.append(channel) | |
|
741 | ||
|
742 | pairsList = [] | |
|
743 | for pair in self.dataOutObj.pairsList: | |
|
744 | pairsList.append(pair[0]) | |
|
745 | pairsList.append(pair[1]) | |
|
746 | spectraComb = channelList + pairsList | |
|
747 | spectraComb = numpy.array(spectraComb,dtype="u1") | |
|
748 | self.processingHeaderObj.spectraComb = spectraComb | |
|
749 | sizeOfSpcComb = len(spectraComb) | |
|
750 | processingHeaderSize += sizeOfSpcComb | |
|
731 | 751 | |
|
732 | 752 | if self.dataOutObj.code != None: |
|
733 | 753 | self.processingHeaderObj.code = self.dataOutObj.code |
|
734 | 754 | self.processingHeaderObj.nCode = self.dataOutObj.nCode |
|
735 | 755 | self.processingHeaderObj.nBaud = self.dataOutObj.nBaud |
|
736 | codesize = int(8 + 4 * self.dataOutObj.nCode * self.dataOutObj.nBaud) | |
|
737 |
|
|
|
756 | nCodeSize = 4 # bytes | |
|
757 | nBaudSize = 4 # bytes | |
|
758 | codeSize = 4 # bytes | |
|
759 | sizeOfCode = int(nCodeSize + nBaudSize + codeSize * self.dataOutObj.nCode * self.dataOutObj.nBaud) | |
|
760 | processingHeaderSize += sizeOfCode | |
|
738 | 761 | |
|
739 | 762 | if self.processingHeaderObj.nWindows != 0: |
|
740 | 763 | self.processingHeaderObj.firstHeight = self.dataOutObj.heightList[0] |
|
741 | 764 | self.processingHeaderObj.deltaHeight = self.dataOutObj.heightList[1] - self.dataOutObj.heightList[0] |
|
742 | 765 | self.processingHeaderObj.nHeights = self.dataOutObj.nHeights |
|
743 | 766 | self.processingHeaderObj.samplesWin = self.dataOutObj.nHeights |
|
744 | processingHeaderSize += 12 | |
|
767 | sizeOfFirstHeight = 4 | |
|
768 | sizeOfdeltaHeight = 4 | |
|
769 | sizeOfnHeights = 4 | |
|
770 | sizeOfWindows = (sizeOfFirstHeight + sizeOfdeltaHeight + sizeOfnHeights)*self.processingHeaderObj.nWindows | |
|
771 | processingHeaderSize += sizeOfWindows | |
|
745 | 772 | |
|
746 | 773 | self.processingHeaderObj.size = processingHeaderSize |
|
747 | 774 | |
|
748 | 775 | No newline at end of file |
@@ -1,584 +1,585 | |||
|
1 | 1 | ''' |
|
2 | 2 | Created on 23/01/2012 |
|
3 | 3 | |
|
4 | 4 | @author $Author: dsuarez $ |
|
5 | 5 | @version $Id: VoltageIO.py 110 2012-07-19 15:18:18Z dsuarez $ |
|
6 | 6 | ''' |
|
7 | 7 | |
|
8 | 8 | import os, sys |
|
9 | 9 | import numpy |
|
10 | 10 | import glob |
|
11 | 11 | import fnmatch |
|
12 | 12 | import time, datetime |
|
13 | 13 | |
|
14 | 14 | path = os.path.split(os.getcwd())[0] |
|
15 | 15 | sys.path.append(path) |
|
16 | 16 | |
|
17 | 17 | from JROHeader import * |
|
18 | 18 | from JRODataIO import JRODataReader |
|
19 | 19 | from JRODataIO import JRODataWriter |
|
20 | 20 | |
|
21 | 21 | from Data.Voltage import Voltage |
|
22 | 22 | |
|
23 | 23 | class VoltageReader(JRODataReader): |
|
24 | 24 | """ |
|
25 | 25 | Esta clase permite leer datos de voltage desde archivos en formato rawdata (.r). La lectura |
|
26 | 26 | de los datos siempre se realiza por bloques. Los datos leidos (array de 3 dimensiones: |
|
27 | 27 | perfiles*alturas*canales) son almacenados en la variable "buffer". |
|
28 | 28 | |
|
29 | 29 | perfiles * alturas * canales |
|
30 | 30 | |
|
31 | 31 | Esta clase contiene instancias (objetos) de las clases BasicHeader, SystemHeader, |
|
32 | 32 | RadarControllerHeader y Voltage. Los tres primeros se usan para almacenar informacion de la |
|
33 | 33 | cabecera de datos (metadata), y el cuarto (Voltage) para obtener y almacenar un perfil de |
|
34 | 34 | datos desde el "buffer" cada vez que se ejecute el metodo "getData". |
|
35 | 35 | |
|
36 | 36 | Example: |
|
37 | 37 | |
|
38 | 38 | dpath = "/home/myuser/data" |
|
39 | 39 | |
|
40 | 40 | startTime = datetime.datetime(2010,1,20,0,0,0,0,0,0) |
|
41 | 41 | |
|
42 | 42 | endTime = datetime.datetime(2010,1,21,23,59,59,0,0,0) |
|
43 | 43 | |
|
44 | 44 | readerObj = VoltageReader() |
|
45 | 45 | |
|
46 | 46 | readerObj.setup(dpath, startTime, endTime) |
|
47 | 47 | |
|
48 | 48 | while(True): |
|
49 | 49 | |
|
50 | 50 | #to get one profile |
|
51 | 51 | profile = readerObj.getData() |
|
52 | 52 | |
|
53 | 53 | #print the profile |
|
54 | 54 | print profile |
|
55 | 55 | |
|
56 | 56 | #If you want to see all datablock |
|
57 | 57 | print readerObj.datablock |
|
58 | 58 | |
|
59 | 59 | if readerObj.flagNoMoreFiles: |
|
60 | 60 | break |
|
61 | 61 | |
|
62 | 62 | """ |
|
63 | 63 | |
|
64 | 64 | ext = ".r" |
|
65 | 65 | |
|
66 | 66 | optchar = "D" |
|
67 | 67 | dataOutObj = None |
|
68 | 68 | |
|
69 | 69 | |
|
70 | 70 | def __init__(self, dataOutObj=None): |
|
71 | 71 | """ |
|
72 | 72 | Inicializador de la clase VoltageReader para la lectura de datos de voltage. |
|
73 | 73 | |
|
74 | 74 | Input: |
|
75 | 75 | dataOutObj : Objeto de la clase Voltage. Este objeto sera utilizado para |
|
76 | 76 | almacenar un perfil de datos cada vez que se haga un requerimiento |
|
77 | 77 | (getData). El perfil sera obtenido a partir del buffer de datos, |
|
78 | 78 | si el buffer esta vacio se hara un nuevo proceso de lectura de un |
|
79 | 79 | bloque de datos. |
|
80 | 80 | Si este parametro no es pasado se creara uno internamente. |
|
81 | 81 | |
|
82 | 82 | Variables afectadas: |
|
83 | 83 | self.dataOutObj |
|
84 | 84 | |
|
85 | 85 | Return: |
|
86 | 86 | None |
|
87 | 87 | """ |
|
88 | 88 | |
|
89 | 89 | self.datablock = None |
|
90 | 90 | |
|
91 | 91 | self.utc = 0 |
|
92 | 92 | |
|
93 | 93 | self.ext = ".r" |
|
94 | 94 | |
|
95 | 95 | self.optchar = "D" |
|
96 | 96 | |
|
97 | 97 | self.basicHeaderObj = BasicHeader() |
|
98 | 98 | |
|
99 | 99 | self.systemHeaderObj = SystemHeader() |
|
100 | 100 | |
|
101 | 101 | self.radarControllerHeaderObj = RadarControllerHeader() |
|
102 | 102 | |
|
103 | 103 | self.processingHeaderObj = ProcessingHeader() |
|
104 | 104 | |
|
105 | 105 | self.online = 0 |
|
106 | 106 | |
|
107 | 107 | self.fp = None |
|
108 | 108 | |
|
109 | 109 | self.idFile = None |
|
110 | 110 | |
|
111 | 111 | self.dtype = None |
|
112 | 112 | |
|
113 | 113 | self.fileSizeByHeader = None |
|
114 | 114 | |
|
115 | 115 | self.filenameList = [] |
|
116 | 116 | |
|
117 | 117 | self.filename = None |
|
118 | 118 | |
|
119 | 119 | self.fileSize = None |
|
120 | 120 | |
|
121 | 121 | self.firstHeaderSize = 0 |
|
122 | 122 | |
|
123 | 123 | self.basicHeaderSize = 24 |
|
124 | 124 | |
|
125 | 125 | self.pathList = [] |
|
126 | 126 | |
|
127 | 127 | self.filenameList = [] |
|
128 | 128 | |
|
129 | 129 | self.lastUTTime = 0 |
|
130 | 130 | |
|
131 | 131 | self.maxTimeStep = 30 |
|
132 | 132 | |
|
133 | 133 | self.flagNoMoreFiles = 0 |
|
134 | 134 | |
|
135 | 135 | self.set = 0 |
|
136 | 136 | |
|
137 | 137 | self.path = None |
|
138 | 138 | |
|
139 | 139 | self.profileIndex = 9999 |
|
140 | 140 | |
|
141 | 141 | self.delay = 3 #seconds |
|
142 | 142 | |
|
143 | 143 | self.nTries = 3 #quantity tries |
|
144 | 144 | |
|
145 | 145 | self.nFiles = 3 #number of files for searching |
|
146 | 146 | |
|
147 | 147 | self.nReadBlocks = 0 |
|
148 | 148 | |
|
149 | 149 | self.flagIsNewFile = 1 |
|
150 | 150 | |
|
151 | 151 | self.ippSeconds = 0 |
|
152 | 152 | |
|
153 | 153 | self.flagTimeBlock = 0 |
|
154 | 154 | |
|
155 | 155 | self.flagIsNewBlock = 0 |
|
156 | 156 | |
|
157 | 157 | self.nTotalBlocks = 0 |
|
158 | 158 | |
|
159 | 159 | self.blocksize = 0 |
|
160 | 160 | |
|
161 | 161 | def createObjByDefault(self): |
|
162 | 162 | |
|
163 | 163 | dataObj = Voltage() |
|
164 | 164 | |
|
165 | 165 | return dataObj |
|
166 | 166 | |
|
167 | 167 | def __hasNotDataInBuffer(self): |
|
168 | 168 | if self.profileIndex >= self.processingHeaderObj.profilesPerBlock: |
|
169 | 169 | return 1 |
|
170 | 170 | return 0 |
|
171 | 171 | |
|
172 | 172 | |
|
173 | 173 | def getBlockDimension(self): |
|
174 | 174 | """ |
|
175 | 175 | Obtiene la cantidad de puntos a leer por cada bloque de datos |
|
176 | 176 | |
|
177 | 177 | Affected: |
|
178 | 178 | self.blocksize |
|
179 | 179 | |
|
180 | 180 | Return: |
|
181 | 181 | None |
|
182 | 182 | """ |
|
183 | 183 | pts2read = self.processingHeaderObj.profilesPerBlock * self.processingHeaderObj.nHeights * self.systemHeaderObj.nChannels |
|
184 | 184 | self.blocksize = pts2read |
|
185 | 185 | |
|
186 | 186 | |
|
187 | 187 | def readBlock(self): |
|
188 | 188 | """ |
|
189 | 189 | readBlock lee el bloque de datos desde la posicion actual del puntero del archivo |
|
190 | 190 | (self.fp) y actualiza todos los parametros relacionados al bloque de datos |
|
191 | 191 | (metadata + data). La data leida es almacenada en el buffer y el contador del buffer |
|
192 | 192 | es seteado a 0 |
|
193 | 193 | |
|
194 | 194 | Inputs: |
|
195 | 195 | None |
|
196 | 196 | |
|
197 | 197 | Return: |
|
198 | 198 | None |
|
199 | 199 | |
|
200 | 200 | Affected: |
|
201 | 201 | self.profileIndex |
|
202 | 202 | self.datablock |
|
203 | 203 | self.flagIsNewFile |
|
204 | 204 | self.flagIsNewBlock |
|
205 | 205 | self.nTotalBlocks |
|
206 | 206 | |
|
207 | 207 | Exceptions: |
|
208 | 208 | Si un bloque leido no es un bloque valido |
|
209 | 209 | """ |
|
210 | 210 | |
|
211 | 211 | junk = numpy.fromfile( self.fp, self.dtype, self.blocksize ) |
|
212 | 212 | |
|
213 | 213 | try: |
|
214 | 214 | junk = junk.reshape( (self.processingHeaderObj.profilesPerBlock, self.processingHeaderObj.nHeights, self.systemHeaderObj.nChannels) ) |
|
215 | 215 | except: |
|
216 | 216 | print "The read block (%3d) has not enough data" %self.nReadBlocks |
|
217 | 217 | return 0 |
|
218 | 218 | |
|
219 | 219 | junk = numpy.transpose(junk, (2,0,1)) |
|
220 | 220 | self.datablock = junk['real'] + junk['imag']*1j |
|
221 | 221 | |
|
222 | 222 | self.profileIndex = 0 |
|
223 | 223 | |
|
224 | 224 | self.flagIsNewFile = 0 |
|
225 | 225 | self.flagIsNewBlock = 1 |
|
226 | 226 | |
|
227 | 227 | self.nTotalBlocks += 1 |
|
228 | 228 | self.nReadBlocks += 1 |
|
229 | 229 | |
|
230 | 230 | return 1 |
|
231 | 231 | |
|
232 | 232 | |
|
233 | 233 | def getData(self): |
|
234 | 234 | """ |
|
235 | 235 | getData obtiene una unidad de datos del buffer de lectura y la copia a la clase "Voltage" |
|
236 | 236 | con todos los parametros asociados a este (metadata). cuando no hay datos en el buffer de |
|
237 | 237 | lectura es necesario hacer una nueva lectura de los bloques de datos usando "readNextBlock" |
|
238 | 238 | |
|
239 | 239 | Ademas incrementa el contador del buffer en 1. |
|
240 | 240 | |
|
241 | 241 | Return: |
|
242 | 242 | data : retorna un perfil de voltages (alturas * canales) copiados desde el |
|
243 | 243 | buffer. Si no hay mas archivos a leer retorna None. |
|
244 | 244 | |
|
245 | 245 | Variables afectadas: |
|
246 | 246 | self.dataOutObj |
|
247 | 247 | self.profileIndex |
|
248 | 248 | |
|
249 | 249 | Affected: |
|
250 | 250 | self.dataOutObj |
|
251 | 251 | self.profileIndex |
|
252 | 252 | self.flagTimeBlock |
|
253 | 253 | self.flagIsNewBlock |
|
254 | 254 | """ |
|
255 | 255 | if self.flagNoMoreFiles: return 0 |
|
256 | 256 | |
|
257 | 257 | self.flagTimeBlock = 0 |
|
258 | 258 | self.flagIsNewBlock = 0 |
|
259 | 259 | |
|
260 | 260 | if self.__hasNotDataInBuffer(): |
|
261 | 261 | |
|
262 | 262 | if not( self.readNextBlock() ): |
|
263 | 263 | return 0 |
|
264 | 264 | |
|
265 | 265 | # self.updateDataHeader() |
|
266 | 266 | |
|
267 | 267 | if self.flagNoMoreFiles == 1: |
|
268 | 268 | print 'Process finished' |
|
269 | 269 | return 0 |
|
270 | 270 | |
|
271 | 271 | #data es un numpy array de 3 dmensiones (perfiles, alturas y canales) |
|
272 | 272 | |
|
273 | 273 | if self.datablock == None: |
|
274 | 274 | self.dataOutObj.flagNoData = True |
|
275 | 275 | return 0 |
|
276 | 276 | |
|
277 | 277 | self.dataOutObj.data = self.datablock[:,self.profileIndex,:] |
|
278 | 278 | |
|
279 | 279 | self.dataOutObj.dtype = self.dtype |
|
280 | 280 | |
|
281 | 281 | self.dataOutObj.nChannels = self.systemHeaderObj.nChannels |
|
282 | 282 | |
|
283 | 283 | self.dataOutObj.nHeights = self.processingHeaderObj.nHeights |
|
284 | 284 | |
|
285 | 285 | self.dataOutObj.nProfiles = self.processingHeaderObj.profilesPerBlock |
|
286 | 286 | |
|
287 | 287 | xf = self.processingHeaderObj.firstHeight + self.processingHeaderObj.nHeights*self.processingHeaderObj.deltaHeight |
|
288 | 288 | |
|
289 | 289 | self.dataOutObj.heightList = numpy.arange(self.processingHeaderObj.firstHeight, xf, self.processingHeaderObj.deltaHeight) |
|
290 | 290 | |
|
291 | 291 | self.dataOutObj.channelList = range(self.systemHeaderObj.nChannels) |
|
292 | 292 | |
|
293 | 293 | self.dataOutObj.channelIndexList = range(self.systemHeaderObj.nChannels) |
|
294 | 294 | |
|
295 | 295 | self.dataOutObj.flagTimeBlock = self.flagTimeBlock |
|
296 | 296 | |
|
297 | 297 | self.dataOutObj.dataUtcTime = self.basicHeaderObj.utc + self.profileIndex * self.ippSeconds |
|
298 | 298 | |
|
299 | 299 | self.dataOutObj.nCohInt = self.processingHeaderObj.nCohInt |
|
300 | 300 | |
|
301 | 301 | self.dataOutObj.flagShiftFFT = False |
|
302 | 302 | |
|
303 | 303 | if self.processingHeaderObj.code != None: |
|
304 | 304 | self.dataOutObj.nCode = self.processingHeaderObj.nCode |
|
305 | 305 | |
|
306 | 306 | self.dataOutObj.nBaud = self.processingHeaderObj.nBaud |
|
307 | 307 | |
|
308 | 308 | self.dataOutObj.code = self.processingHeaderObj.code |
|
309 | 309 | |
|
310 | 310 | self.profileIndex += 1 |
|
311 | 311 | |
|
312 | 312 | self.dataOutObj.systemHeaderObj = self.systemHeaderObj.copy() |
|
313 | 313 | |
|
314 | 314 | self.dataOutObj.radarControllerHeaderObj = self.radarControllerHeaderObj.copy() |
|
315 | 315 | |
|
316 | 316 | self.dataOutObj.flagNoData = False |
|
317 | 317 | |
|
318 | 318 | return 1 |
|
319 | 319 | |
|
320 | 320 | |
|
321 | 321 | class VoltageWriter(JRODataWriter): |
|
322 | 322 | """ |
|
323 | 323 | Esta clase permite escribir datos de voltajes a archivos procesados (.r). La escritura |
|
324 | 324 | de los datos siempre se realiza por bloques. |
|
325 | 325 | """ |
|
326 | 326 | |
|
327 | 327 | ext = ".r" |
|
328 | 328 | |
|
329 | 329 | optchar = "D" |
|
330 | 330 | |
|
331 | 331 | shapeBuffer = None |
|
332 | 332 | |
|
333 | 333 | |
|
334 | 334 | def __init__(self, dataOutObj=None): |
|
335 | 335 | """ |
|
336 | 336 | Inicializador de la clase VoltageWriter para la escritura de datos de espectros. |
|
337 | 337 | |
|
338 | 338 | Affected: |
|
339 | 339 | self.dataOutObj |
|
340 | 340 | |
|
341 | 341 | Return: None |
|
342 | 342 | """ |
|
343 | 343 | if dataOutObj == None: |
|
344 | 344 | dataOutObj = Voltage() |
|
345 | 345 | |
|
346 | 346 | if not( isinstance(dataOutObj, Voltage) ): |
|
347 | 347 | raise ValueError, "in VoltageReader, dataOutObj must be an Spectra class object" |
|
348 | 348 | |
|
349 | 349 | self.dataOutObj = dataOutObj |
|
350 | 350 | |
|
351 | 351 | self.nTotalBlocks = 0 |
|
352 | 352 | |
|
353 | 353 | self.profileIndex = 0 |
|
354 | 354 | |
|
355 | 355 | def hasAllDataInBuffer(self): |
|
356 | 356 | if self.profileIndex >= self.processingHeaderObj.profilesPerBlock: |
|
357 | 357 | return 1 |
|
358 | 358 | return 0 |
|
359 | 359 | |
|
360 | 360 | |
|
361 | 361 | def setBlockDimension(self): |
|
362 | 362 | """ |
|
363 | 363 | Obtiene las formas dimensionales del los subbloques de datos que componen un bloque |
|
364 | 364 | |
|
365 | 365 | Affected: |
|
366 | 366 | self.shape_spc_Buffer |
|
367 | 367 | self.shape_cspc_Buffer |
|
368 | 368 | self.shape_dc_Buffer |
|
369 | 369 | |
|
370 | 370 | Return: None |
|
371 | 371 | """ |
|
372 | 372 | self.shapeBuffer = (self.processingHeaderObj.profilesPerBlock, |
|
373 | 373 | self.processingHeaderObj.nHeights, |
|
374 | 374 | self.systemHeaderObj.nChannels) |
|
375 | 375 | |
|
376 | 376 | self.datablock = numpy.zeros((self.systemHeaderObj.nChannels, |
|
377 | 377 | self.processingHeaderObj.profilesPerBlock, |
|
378 | 378 | self.processingHeaderObj.nHeights), |
|
379 | 379 | dtype=numpy.dtype('complex')) |
|
380 | 380 | |
|
381 | 381 | |
|
382 | 382 | def writeBlock(self): |
|
383 | 383 | """ |
|
384 | 384 | Escribe el buffer en el file designado |
|
385 | 385 | |
|
386 | 386 | Affected: |
|
387 | 387 | self.profileIndex |
|
388 | 388 | self.flagIsNewFile |
|
389 | 389 | self.flagIsNewBlock |
|
390 | 390 | self.nTotalBlocks |
|
391 | 391 | self.blockIndex |
|
392 | 392 | |
|
393 | 393 | Return: None |
|
394 | 394 | """ |
|
395 | 395 | data = numpy.zeros( self.shapeBuffer, self.dtype ) |
|
396 | 396 | |
|
397 | 397 | junk = numpy.transpose(self.datablock, (1,2,0)) |
|
398 | 398 | |
|
399 | 399 | data['real'] = junk.real |
|
400 | 400 | data['imag'] = junk.imag |
|
401 | 401 | |
|
402 | 402 | data = data.reshape( (-1) ) |
|
403 | 403 | |
|
404 | 404 | data.tofile( self.fp ) |
|
405 | 405 | |
|
406 | 406 | self.datablock.fill(0) |
|
407 | 407 | |
|
408 | 408 | self.profileIndex = 0 |
|
409 | 409 | self.flagIsNewFile = 0 |
|
410 | 410 | self.flagIsNewBlock = 1 |
|
411 | 411 | |
|
412 | 412 | self.blockIndex += 1 |
|
413 | 413 | self.nTotalBlocks += 1 |
|
414 | 414 | |
|
415 | 415 | def putData(self): |
|
416 | 416 | """ |
|
417 | 417 | Setea un bloque de datos y luego los escribe en un file |
|
418 | 418 | |
|
419 | 419 | Affected: |
|
420 | 420 | self.flagIsNewBlock |
|
421 | 421 | self.profileIndex |
|
422 | 422 | |
|
423 | 423 | Return: |
|
424 | 424 | 0 : Si no hay data o no hay mas files que puedan escribirse |
|
425 | 425 | 1 : Si se escribio la data de un bloque en un file |
|
426 | 426 | """ |
|
427 | 427 | self.flagIsNewBlock = 0 |
|
428 | 428 | |
|
429 | 429 | if self.dataOutObj.flagNoData: |
|
430 | 430 | return 0 |
|
431 | 431 | |
|
432 | 432 | if self.dataOutObj.flagTimeBlock: |
|
433 | 433 | |
|
434 | 434 | self.datablock.fill(0) |
|
435 | 435 | self.profileIndex = 0 |
|
436 | 436 | self.setNextFile() |
|
437 | 437 | |
|
438 | 438 | if self.profileIndex == 0: |
|
439 | 439 | self.getBasicHeader() |
|
440 | 440 | |
|
441 | 441 | self.datablock[:,self.profileIndex,:] = self.dataOutObj.data |
|
442 | 442 | |
|
443 | 443 | self.profileIndex += 1 |
|
444 | 444 | |
|
445 | 445 | if self.hasAllDataInBuffer(): |
|
446 | 446 | #if self.flagIsNewFile: |
|
447 | 447 | self.writeNextBlock() |
|
448 | 448 | # self.getDataHeader() |
|
449 | 449 | |
|
450 | 450 | if self.flagNoMoreFiles: |
|
451 | 451 | #print 'Process finished' |
|
452 | 452 | return 0 |
|
453 | 453 | |
|
454 | 454 | return 1 |
|
455 | 455 | |
|
456 | 456 | def __getProcessFlags(self): |
|
457 | 457 | |
|
458 | 458 | processFlags = 0 |
|
459 | 459 | |
|
460 | 460 | dtype0 = numpy.dtype([('real','<i1'),('imag','<i1')]) |
|
461 | 461 | dtype1 = numpy.dtype([('real','<i2'),('imag','<i2')]) |
|
462 | 462 | dtype2 = numpy.dtype([('real','<i4'),('imag','<i4')]) |
|
463 | 463 | dtype3 = numpy.dtype([('real','<i8'),('imag','<i8')]) |
|
464 | 464 | dtype4 = numpy.dtype([('real','<f4'),('imag','<f4')]) |
|
465 | 465 | dtype5 = numpy.dtype([('real','<f8'),('imag','<f8')]) |
|
466 | 466 | |
|
467 | 467 | dtypeList = [dtype0, dtype1, dtype2, dtype3, dtype4, dtype5] |
|
468 | 468 | |
|
469 | 469 | |
|
470 | 470 | |
|
471 | 471 | datatypeValueList = [PROCFLAG.DATATYPE_CHAR, |
|
472 | 472 | PROCFLAG.DATATYPE_SHORT, |
|
473 | 473 | PROCFLAG.DATATYPE_LONG, |
|
474 | 474 | PROCFLAG.DATATYPE_INT64, |
|
475 | 475 | PROCFLAG.DATATYPE_FLOAT, |
|
476 | 476 | PROCFLAG.DATATYPE_DOUBLE] |
|
477 | 477 | |
|
478 | 478 | |
|
479 | 479 | for index in range(len(dtypeList)): |
|
480 | 480 | if self.dataOutObj.dtype == dtypeList[index]: |
|
481 | 481 | dtypeValue = datatypeValueList[index] |
|
482 | 482 | break |
|
483 | 483 | |
|
484 | 484 | processFlags += dtypeValue |
|
485 | 485 | |
|
486 | 486 | if self.dataOutObj.flagDecodeData: |
|
487 | 487 | processFlags += PROCFLAG.DECODE_DATA |
|
488 | 488 | |
|
489 | 489 | if self.dataOutObj.flagDeflipData: |
|
490 | 490 | processFlags += PROCFLAG.DEFLIP_DATA |
|
491 | 491 | |
|
492 | 492 | if self.dataOutObj.code != None: |
|
493 | 493 | processFlags += PROCFLAG.DEFINE_PROCESS_CODE |
|
494 | 494 | |
|
495 | 495 | if self.dataOutObj.nCohInt > 1: |
|
496 | 496 | processFlags += PROCFLAG.COHERENT_INTEGRATION |
|
497 | 497 | |
|
498 | 498 | return processFlags |
|
499 | 499 | |
|
500 | 500 | |
|
501 | 501 | def __getBlockSize(self): |
|
502 | 502 | ''' |
|
503 | 503 | Este metodos determina el cantidad de bytes para un bloque de datos de tipo Voltage |
|
504 | 504 | ''' |
|
505 | 505 | |
|
506 | 506 | dtype0 = numpy.dtype([('real','<i1'),('imag','<i1')]) |
|
507 | 507 | dtype1 = numpy.dtype([('real','<i2'),('imag','<i2')]) |
|
508 | 508 | dtype2 = numpy.dtype([('real','<i4'),('imag','<i4')]) |
|
509 | 509 | dtype3 = numpy.dtype([('real','<i8'),('imag','<i8')]) |
|
510 | 510 | dtype4 = numpy.dtype([('real','<f4'),('imag','<f4')]) |
|
511 | 511 | dtype5 = numpy.dtype([('real','<f8'),('imag','<f8')]) |
|
512 | 512 | |
|
513 | 513 | dtypeList = [dtype0, dtype1, dtype2, dtype3, dtype4, dtype5] |
|
514 | 514 | datatypeValueList = [1,2,4,8,4,8] |
|
515 | 515 | for index in range(len(dtypeList)): |
|
516 | 516 | if self.dataOutObj.dtype == dtypeList[index]: |
|
517 | 517 | datatypeValue = datatypeValueList[index] |
|
518 | 518 | break |
|
519 | 519 | |
|
520 | 520 | blocksize = int(self.dataOutObj.nHeights * self.dataOutObj.nChannels * self.dataOutObj.nProfiles * datatypeValue * 2) |
|
521 | 521 | |
|
522 | 522 | return blocksize |
|
523 | 523 | |
|
524 | 524 | |
|
525 | 525 | def getBasicHeader(self): |
|
526 | 526 | self.basicHeaderObj.size = self.basicHeaderSize #bytes |
|
527 | 527 | self.basicHeaderObj.version = self.versionFile |
|
528 | 528 | self.basicHeaderObj.dataBlock = self.nTotalBlocks |
|
529 | 529 | |
|
530 | 530 | utc = numpy.floor(self.dataOutObj.dataUtcTime) |
|
531 | 531 | milisecond = (self.dataOutObj.dataUtcTime - utc)* 1000.0 |
|
532 | 532 | |
|
533 | 533 | self.basicHeaderObj.utc = utc |
|
534 | 534 | self.basicHeaderObj.miliSecond = milisecond |
|
535 | 535 | self.basicHeaderObj.timeZone = 0 |
|
536 | 536 | self.basicHeaderObj.dstFlag = 0 |
|
537 | 537 | self.basicHeaderObj.errorCount = 0 |
|
538 | 538 | |
|
539 | 539 | def getDataHeader(self): |
|
540 | 540 | |
|
541 | 541 | """ |
|
542 | 542 | Obtiene una copia del First Header |
|
543 | 543 | |
|
544 | 544 | Affected: |
|
545 | 545 | self.systemHeaderObj |
|
546 | 546 | self.radarControllerHeaderObj |
|
547 | 547 | self.dtype |
|
548 | 548 | |
|
549 | 549 | Return: |
|
550 | 550 | None |
|
551 | 551 | """ |
|
552 | 552 | |
|
553 | 553 | self.systemHeaderObj = self.dataOutObj.systemHeaderObj.copy() |
|
554 | self.systemHeaderObj.nChannels = self.dataOutObj.nChannels | |
|
554 | 555 | self.radarControllerHeaderObj = self.dataOutObj.radarControllerHeaderObj.copy() |
|
555 | 556 | |
|
556 | 557 | self.getBasicHeader() |
|
557 | 558 | |
|
558 | 559 | processingHeaderSize = 40 # bytes |
|
559 | 560 | self.processingHeaderObj.dtype = 0 # Voltage |
|
560 | 561 | self.processingHeaderObj.blockSize = self.__getBlockSize() |
|
561 | 562 | self.processingHeaderObj.profilesPerBlock = self.profilesPerBlock |
|
562 | 563 | self.processingHeaderObj.dataBlocksPerFile = self.blocksPerFile |
|
563 | 564 | self.processingHeaderObj.nWindows = 1 #podria ser 1 o self.dataOutObj.processingHeaderObj.nWindows |
|
564 | 565 | self.processingHeaderObj.processFlags = self.__getProcessFlags() |
|
565 | 566 | self.processingHeaderObj.nCohInt = self.dataOutObj.nCohInt |
|
566 | 567 | self.processingHeaderObj.nIncohInt = 1 # Cuando la data de origen es de tipo Voltage |
|
567 | 568 | self.processingHeaderObj.totalSpectra = 0 # Cuando la data de origen es de tipo Voltage |
|
568 | 569 | |
|
569 | 570 | if self.dataOutObj.code != None: |
|
570 | 571 | self.processingHeaderObj.code = self.dataOutObj.code |
|
571 | 572 | self.processingHeaderObj.nCode = self.dataOutObj.nCode |
|
572 | 573 | self.processingHeaderObj.nBaud = self.dataOutObj.nBaud |
|
573 | 574 | codesize = int(8 + 4 * self.dataOutObj.nCode * self.dataOutObj.nBaud) |
|
574 | 575 | processingHeaderSize += codesize |
|
575 | 576 | |
|
576 | 577 | if self.processingHeaderObj.nWindows != 0: |
|
577 | 578 | self.processingHeaderObj.firstHeight = self.dataOutObj.heightList[0] |
|
578 | 579 | self.processingHeaderObj.deltaHeight = self.dataOutObj.heightList[1] - self.dataOutObj.heightList[0] |
|
579 | 580 | self.processingHeaderObj.nHeights = self.dataOutObj.nHeights |
|
580 | 581 | self.processingHeaderObj.samplesWin = self.dataOutObj.nHeights |
|
581 | 582 | processingHeaderSize += 12 |
|
582 | 583 | |
|
583 | 584 | self.processingHeaderObj.size = processingHeaderSize |
|
584 | 585 | No newline at end of file |
@@ -1,388 +1,388 | |||
|
1 | 1 | ''' |
|
2 | 2 | Created on Feb 7, 2012 |
|
3 | 3 | |
|
4 | 4 | @author $Author: murco $ |
|
5 | 5 | @version $Id: SpectraProcessor.py 119 2012-09-05 17:06:09Z murco $ |
|
6 | 6 | ''' |
|
7 | 7 | import os, sys |
|
8 | 8 | import numpy |
|
9 | 9 | import time |
|
10 | 10 | |
|
11 | 11 | path = os.path.split(os.getcwd())[0] |
|
12 | 12 | sys.path.append(path) |
|
13 | 13 | |
|
14 | 14 | from Data.Spectra import Spectra |
|
15 | 15 | from IO.SpectraIO import SpectraWriter |
|
16 | 16 | #from Graphics.SpectraPlot import Spectrum |
|
17 | 17 | #from JRONoise import Noise |
|
18 | 18 | |
|
19 | 19 | class SpectraProcessor: |
|
20 | 20 | ''' |
|
21 | 21 | classdocs |
|
22 | 22 | ''' |
|
23 | 23 | |
|
24 | 24 | dataInObj = None |
|
25 | 25 | |
|
26 | 26 | dataOutObj = None |
|
27 | 27 | |
|
28 | 28 | noiseObj = None |
|
29 | 29 | |
|
30 | 30 | integratorObjList = [] |
|
31 | 31 | |
|
32 | 32 | writerObjList = [] |
|
33 | 33 | |
|
34 | 34 | integratorObjIndex = None |
|
35 | 35 | |
|
36 | 36 | writerObjIndex = None |
|
37 | 37 | |
|
38 | 38 | profIndex = 0 # Se emplea cuando el objeto de entrada es un Voltage |
|
39 | 39 | |
|
40 | 40 | # integratorObjList = [] |
|
41 | 41 | # |
|
42 | 42 | # decoderObjList = [] |
|
43 | 43 | # |
|
44 | 44 | # writerObjList = [] |
|
45 | 45 | # |
|
46 | 46 | # plotterObjList = [] |
|
47 | 47 | # |
|
48 | 48 | # integratorObjIndex = None |
|
49 | 49 | # |
|
50 | 50 | # decoderObjIndex = None |
|
51 | 51 | # |
|
52 | 52 | # writerObjIndex = None |
|
53 | 53 | # |
|
54 | 54 | # plotterObjIndex = None |
|
55 | 55 | # |
|
56 | 56 | # buffer = None |
|
57 | 57 | # |
|
58 | 58 | # profIndex = 0 |
|
59 | 59 | # |
|
60 | 60 | # nFFTPoints = None |
|
61 | 61 | # |
|
62 | 62 | # nChannels = None |
|
63 | 63 | # |
|
64 | 64 | # nHeights = None |
|
65 | 65 | # |
|
66 | 66 | # nPairs = None |
|
67 | 67 | # |
|
68 | 68 | # pairList = None |
|
69 | 69 | |
|
70 | 70 | |
|
71 | 71 | def __init__(self): |
|
72 | 72 | ''' |
|
73 | 73 | Constructor |
|
74 | 74 | ''' |
|
75 | 75 | |
|
76 | 76 | self.integratorObjIndex = None |
|
77 | 77 | self.writerObjIndex = None |
|
78 | 78 | self.integratorObjList = [] |
|
79 | 79 | self.writerObjList = [] |
|
80 | 80 | self.noiseObj = None |
|
81 | 81 | self.buffer = None |
|
82 | 82 | self.profIndex = 0 |
|
83 | 83 | |
|
84 | 84 | def setup(self, dataInObj=None, dataOutObj=None, nFFTPoints=None, pairList=None): |
|
85 | 85 | |
|
86 | 86 | if dataInObj == None: |
|
87 | 87 | raise ValueError, "This SpectraProcessor.setup() function needs dataInObj input variable" |
|
88 | 88 | |
|
89 | 89 | if dataInObj.type == "Voltage": |
|
90 | 90 | if nFFTPoints == None: |
|
91 | 91 | raise ValueError, "This SpectraProcessor.setup() function needs nFFTPoints input variable" |
|
92 | 92 | else: |
|
93 | 93 | nFFTPoints = dataInObj.nFFTPoints |
|
94 | 94 | |
|
95 | 95 | self.dataInObj = dataInObj |
|
96 | 96 | |
|
97 | 97 | if dataOutObj == None: |
|
98 | 98 | dataOutObj = Spectra() |
|
99 | 99 | |
|
100 | 100 | self.dataOutObj = dataOutObj |
|
101 | 101 | |
|
102 | 102 | # self.noiseObj = Noise() #aun no se incluye el objeto Noise() |
|
103 | 103 | |
|
104 | 104 | ########################################## |
|
105 | 105 | # self.nFFTPoints = nFFTPoints |
|
106 | 106 | # self.nChannels = self.dataInObj.nChannels |
|
107 | 107 | # self.nHeights = self.dataInObj.nHeights |
|
108 | 108 | # self.pairList = pairList |
|
109 | 109 | # if pairList != None: |
|
110 | 110 | # self.nPairs = len(pairList) |
|
111 | 111 | # else: |
|
112 | 112 | # self.nPairs = 0 |
|
113 | 113 | # |
|
114 | 114 | # self.dataOutObj.heightList = self.dataInObj.heightList |
|
115 | 115 | # self.dataOutObj.channelIndexList = self.dataInObj.channelIndexList |
|
116 | 116 | # self.dataOutObj.m_BasicHeader = self.dataInObj.m_BasicHeader.copy() |
|
117 | 117 | # self.dataOutObj.m_ProcessingHeader = self.dataInObj.m_ProcessingHeader.copy() |
|
118 | 118 | # self.dataOutObj.m_RadarControllerHeader = self.dataInObj.m_RadarControllerHeader.copy() |
|
119 | 119 | # self.dataOutObj.m_SystemHeader = self.dataInObj.m_SystemHeader.copy() |
|
120 | 120 | # |
|
121 | 121 | # self.dataOutObj.dataType = self.dataInObj.dataType |
|
122 | 122 | # self.dataOutObj.nPairs = self.nPairs |
|
123 | 123 | # self.dataOutObj.nChannels = self.nChannels |
|
124 | 124 | # self.dataOutObj.nProfiles = self.nFFTPoints |
|
125 | 125 | # self.dataOutObj.nHeights = self.nHeights |
|
126 | 126 | # self.dataOutObj.nFFTPoints = self.nFFTPoints |
|
127 | 127 | # #self.dataOutObj.data = None |
|
128 | 128 | # |
|
129 | 129 | # self.dataOutObj.m_SystemHeader.numChannels = self.nChannels |
|
130 | 130 | # self.dataOutObj.m_SystemHeader.nProfiles = self.nFFTPoints |
|
131 | 131 | # |
|
132 | 132 | # self.dataOutObj.m_ProcessingHeader.totalSpectra = self.nChannels + self.nPairs |
|
133 | 133 | # self.dataOutObj.m_ProcessingHeader.profilesPerBlock = self.nFFTPoints |
|
134 | 134 | # self.dataOutObj.m_ProcessingHeader.numHeights = self.nHeights |
|
135 | 135 | # self.dataOutObj.m_ProcessingHeader.shif_fft = True |
|
136 | 136 | # |
|
137 | 137 | # spectraComb = numpy.zeros( (self.nChannels+self.nPairs)*2,numpy.dtype('u1')) |
|
138 | 138 | # k = 0 |
|
139 | 139 | # for i in range( 0,self.nChannels*2,2 ): |
|
140 | 140 | # spectraComb[i] = k |
|
141 | 141 | # spectraComb[i+1] = k |
|
142 | 142 | # k += 1 |
|
143 | 143 | # |
|
144 | 144 | # k *= 2 |
|
145 | 145 | # |
|
146 | 146 | # if self.pairList != None: |
|
147 | 147 | # |
|
148 | 148 | # for pair in self.pairList: |
|
149 | 149 | # spectraComb[k] = pair[0] |
|
150 | 150 | # spectraComb[k+1] = pair[1] |
|
151 | 151 | # k += 2 |
|
152 | 152 | # |
|
153 | 153 | # self.dataOutObj.m_ProcessingHeader.spectraComb = spectraComb |
|
154 | 154 | |
|
155 | 155 | return self.dataOutObj |
|
156 | 156 | |
|
157 | 157 | def init(self): |
|
158 | 158 | # |
|
159 | 159 | # self.nHeights = self.dataInObj.nHeights |
|
160 | 160 | # self.dataOutObj.nHeights = self.nHeights |
|
161 | 161 | # self.dataOutObj.heightList = self.dataInObj.heightList |
|
162 | 162 | # |
|
163 | 163 | |
|
164 | 164 | self.integratorObjIndex = 0 |
|
165 | 165 | self.writerObjIndex = 0 |
|
166 | 166 | |
|
167 | 167 | if self.dataInObj.type == "Voltage": |
|
168 | 168 | |
|
169 | 169 | if self.buffer == None: |
|
170 | 170 | self.buffer = numpy.zeros((self.nChannels, |
|
171 | 171 | self.nFFTPoints, |
|
172 | 172 | self.dataInObj.nHeights), |
|
173 | 173 | dtype='complex') |
|
174 | 174 | |
|
175 | 175 | self.buffer[:,self.profIndex,:] = self.dataInObj.data |
|
176 | 176 | self.profIndex += 1 |
|
177 | 177 | |
|
178 | 178 | if self.profIndex == self.nFFTPoints: |
|
179 | 179 | self.__getFft() |
|
180 | 180 | self.dataOutObj.flagNoData = False |
|
181 | 181 | |
|
182 | 182 | self.buffer = None |
|
183 | 183 | self.profIndex = 0 |
|
184 | 184 | return |
|
185 | 185 | |
|
186 | 186 | self.dataOutObj.flagNoData = True |
|
187 | 187 | |
|
188 | 188 | return |
|
189 | 189 | |
|
190 | 190 | #Other kind of data |
|
191 | 191 | if self.dataInObj.type == "Spectra": |
|
192 | 192 | self.dataOutObj.copy(self.dataInObj) |
|
193 | 193 | self.dataOutObj.flagNoData = False |
|
194 | 194 | return |
|
195 | 195 | |
|
196 | 196 | raise ValueError, "The datatype is not valid" |
|
197 | 197 | |
|
198 | 198 | def __getFft(self): |
|
199 | 199 | """ |
|
200 | 200 | Convierte valores de Voltaje a Spectra |
|
201 | 201 | |
|
202 | 202 | Affected: |
|
203 | 203 | self.dataOutObj.data_spc |
|
204 | 204 | self.dataOutObj.data_cspc |
|
205 | 205 | self.dataOutObj.data_dc |
|
206 | 206 | self.dataOutObj.heightList |
|
207 | 207 | self.dataOutObj.m_BasicHeader |
|
208 | 208 | self.dataOutObj.m_ProcessingHeader |
|
209 | 209 | self.dataOutObj.m_RadarControllerHeader |
|
210 | 210 | self.dataOutObj.m_SystemHeader |
|
211 | 211 | self.profIndex |
|
212 | 212 | self.buffer |
|
213 | 213 | self.dataOutObj.flagNoData |
|
214 | 214 | self.dataOutObj.dataType |
|
215 | 215 | self.dataOutObj.nPairs |
|
216 | 216 | self.dataOutObj.nChannels |
|
217 | 217 | self.dataOutObj.nProfiles |
|
218 | 218 | self.dataOutObj.m_SystemHeader.numChannels |
|
219 | 219 | self.dataOutObj.m_ProcessingHeader.totalSpectra |
|
220 | 220 | self.dataOutObj.m_ProcessingHeader.profilesPerBlock |
|
221 | 221 | self.dataOutObj.m_ProcessingHeader.numHeights |
|
222 | 222 | self.dataOutObj.m_ProcessingHeader.spectraComb |
|
223 | 223 | self.dataOutObj.m_ProcessingHeader.shif_fft |
|
224 | 224 | """ |
|
225 | 225 | |
|
226 | 226 | if self.dataInObj.flagNoData: |
|
227 | 227 | return 0 |
|
228 | 228 | |
|
229 | 229 | fft_volt = numpy.fft.fft(self.buffer,axis=1) |
|
230 | 230 | dc = fft_volt[:,0,:] |
|
231 | 231 | |
|
232 | 232 | #calculo de self-spectra |
|
233 | 233 | fft_volt = numpy.fft.fftshift(fft_volt,axes=(1,)) |
|
234 | 234 | spc = fft_volt * numpy.conjugate(fft_volt) |
|
235 | 235 | spc = spc.real |
|
236 | 236 | |
|
237 | 237 | blocksize = 0 |
|
238 | 238 | blocksize += dc.size |
|
239 | 239 | blocksize += spc.size |
|
240 | 240 | |
|
241 | 241 | cspc = None |
|
242 | 242 | pairIndex = 0 |
|
243 | 243 | if self.pairList != None: |
|
244 | 244 | #calculo de cross-spectra |
|
245 | 245 | cspc = numpy.zeros((self.nPairs, self.nFFTPoints, self.nHeights), dtype='complex') |
|
246 | 246 | for pair in self.pairList: |
|
247 | 247 | cspc[pairIndex,:,:] = numpy.abs(fft_volt[pair[0],:,:] * numpy.conjugate(fft_volt[pair[1],:,:])) |
|
248 | 248 | pairIndex += 1 |
|
249 | 249 | blocksize += cspc.size |
|
250 | 250 | |
|
251 | 251 | self.dataOutObj.data_spc = spc |
|
252 | 252 | self.dataOutObj.data_cspc = cspc |
|
253 | 253 | self.dataOutObj.data_dc = dc |
|
254 | 254 | self.dataOutObj.m_ProcessingHeader.blockSize = blocksize |
|
255 | 255 | self.dataOutObj.m_BasicHeader.utc = self.dataInObj.m_BasicHeader.utc |
|
256 | 256 | |
|
257 | 257 | # self.getNoise() |
|
258 | 258 | |
|
259 | 259 | def addWriter(self, wrpath, profilesPerBlock, blocksPerFile): |
|
260 |
objWriter = SpectraWriter(self.dataOutObj |
|
|
260 | objWriter = SpectraWriter(self.dataOutObj) | |
|
261 | 261 | objWriter.setup(wrpath, profilesPerBlock, blocksPerFile) |
|
262 | 262 | self.writerObjList.append(objWriter) |
|
263 | 263 | |
|
264 | 264 | def addIntegrator(self,N,timeInterval): |
|
265 | 265 | |
|
266 | 266 | objIncohInt = IncoherentIntegration(N,timeInterval) |
|
267 | 267 | self.integratorObjList.append(objIncohInt) |
|
268 | 268 | |
|
269 | 269 | def writeData(self, wrpath, profilesPerBlock, blocksPerFile): |
|
270 | 270 | if self.dataOutObj.flagNoData: |
|
271 | 271 | return 0 |
|
272 | 272 | |
|
273 | 273 | if len(self.writerObjList) <= self.writerObjIndex: |
|
274 | 274 | self.addWriter(wrpath, profilesPerBlock, blocksPerFile) |
|
275 | 275 | |
|
276 | 276 | self.writerObjList[self.writerObjIndex].putData() |
|
277 | 277 | |
|
278 | 278 | self.writerObjIndex += 1 |
|
279 | 279 | |
|
280 | 280 | def integrator(self, N=None, timeInterval=None): |
|
281 | 281 | |
|
282 | 282 | if self.dataOutObj.flagNoData: |
|
283 | 283 | return 0 |
|
284 | 284 | |
|
285 | 285 | if len(self.integratorObjList) <= self.integratorObjIndex: |
|
286 | 286 | self.addIntegrator(N,timeInterval) |
|
287 | 287 | |
|
288 | 288 | myIncohIntObj = self.integratorObjList[self.integratorObjIndex] |
|
289 | 289 | myIncohIntObj.exe(data=self.dataOutObj.data_spc,timeOfData=self.dataOutObj.m_BasicHeader.utc) |
|
290 | 290 | |
|
291 | 291 | if myIncohIntObj.isReady: |
|
292 | 292 | self.dataOutObj.data_spc = myIncohIntObj.data |
|
293 | 293 | self.dataOutObj.nAvg = myIncohIntObj.navg |
|
294 | 294 | self.dataOutObj.m_ProcessingHeader.incoherentInt = self.dataInObj.m_ProcessingHeader.incoherentInt*myIncohIntObj.navg |
|
295 | 295 | #print "myIncohIntObj.navg: ",myIncohIntObj.navg |
|
296 | 296 | self.dataOutObj.flagNoData = False |
|
297 | 297 | |
|
298 | 298 | """Calcular el ruido""" |
|
299 | 299 | self.getNoise() |
|
300 | 300 | else: |
|
301 | 301 | self.dataOutObj.flagNoData = True |
|
302 | 302 | |
|
303 | 303 | self.integratorObjIndex += 1 |
|
304 | 304 | |
|
305 | 305 | |
|
306 | 306 | |
|
307 | 307 | |
|
308 | 308 | class IncoherentIntegration: |
|
309 | 309 | |
|
310 | 310 | integ_counter = None |
|
311 | 311 | data = None |
|
312 | 312 | navg = None |
|
313 | 313 | buffer = None |
|
314 | 314 | nIncohInt = None |
|
315 | 315 | |
|
316 | 316 | def __init__(self, N = None, timeInterval = None): |
|
317 | 317 | """ |
|
318 | 318 | N |
|
319 | 319 | timeInterval - interval time [min], integer value |
|
320 | 320 | """ |
|
321 | 321 | |
|
322 | 322 | self.data = None |
|
323 | 323 | self.navg = None |
|
324 | 324 | self.buffer = None |
|
325 | 325 | self.timeOut = None |
|
326 | 326 | self.exitCondition = False |
|
327 | 327 | self.isReady = False |
|
328 | 328 | self.nIncohInt = N |
|
329 | 329 | self.integ_counter = 0 |
|
330 | 330 | if timeInterval!=None: |
|
331 | 331 | self.timeIntervalInSeconds = timeInterval * 60. #if (type(timeInterval)!=integer) -> change this line |
|
332 | 332 | |
|
333 | 333 | if ((timeInterval==None) and (N==None)): |
|
334 | 334 | print 'N = None ; timeInterval = None' |
|
335 | 335 | sys.exit(0) |
|
336 | 336 | elif timeInterval == None: |
|
337 | 337 | self.timeFlag = False |
|
338 | 338 | else: |
|
339 | 339 | self.timeFlag = True |
|
340 | 340 | |
|
341 | 341 | |
|
342 | 342 | def exe(self,data,timeOfData): |
|
343 | 343 | """ |
|
344 | 344 | data |
|
345 | 345 | |
|
346 | 346 | timeOfData [seconds] |
|
347 | 347 | """ |
|
348 | 348 | |
|
349 | 349 | if self.timeFlag: |
|
350 | 350 | if self.timeOut == None: |
|
351 | 351 | self.timeOut = timeOfData + self.timeIntervalInSeconds |
|
352 | 352 | |
|
353 | 353 | if timeOfData < self.timeOut: |
|
354 | 354 | if self.buffer == None: |
|
355 | 355 | self.buffer = data |
|
356 | 356 | else: |
|
357 | 357 | self.buffer = self.buffer + data |
|
358 | 358 | self.integ_counter += 1 |
|
359 | 359 | else: |
|
360 | 360 | self.exitCondition = True |
|
361 | 361 | |
|
362 | 362 | else: |
|
363 | 363 | if self.integ_counter < self.nIncohInt: |
|
364 | 364 | if self.buffer == None: |
|
365 | 365 | self.buffer = data |
|
366 | 366 | else: |
|
367 | 367 | self.buffer = self.buffer + data |
|
368 | 368 | |
|
369 | 369 | self.integ_counter += 1 |
|
370 | 370 | |
|
371 | 371 | if self.integ_counter == self.nIncohInt: |
|
372 | 372 | self.exitCondition = True |
|
373 | 373 | |
|
374 | 374 | if self.exitCondition: |
|
375 | 375 | self.data = self.buffer |
|
376 | 376 | self.navg = self.integ_counter |
|
377 | 377 | self.isReady = True |
|
378 | 378 | self.buffer = None |
|
379 | 379 | self.timeOut = None |
|
380 | 380 | self.integ_counter = 0 |
|
381 | 381 | self.exitCondition = False |
|
382 | 382 | |
|
383 | 383 | if self.timeFlag: |
|
384 | 384 | self.buffer = data |
|
385 | 385 | self.timeOut = timeOfData + self.timeIntervalInSeconds |
|
386 | 386 | else: |
|
387 | 387 | self.isReady = False |
|
388 | 388 | No newline at end of file |
@@ -1,80 +1,80 | |||
|
1 | 1 | |
|
2 | 2 | import os, sys |
|
3 | 3 | import time, datetime |
|
4 | 4 | |
|
5 | 5 | path = os.path.split(os.getcwd())[0] |
|
6 | 6 | sys.path.append(path) |
|
7 | 7 | |
|
8 | 8 | |
|
9 | 9 | from Data.Spectra import Spectra |
|
10 | 10 | from IO.SpectraIO import * |
|
11 | 11 | from Processing.SpectraProcessor import * |
|
12 | 12 | |
|
13 | 13 | |
|
14 | 14 | |
|
15 | 15 | class TestSChain: |
|
16 | 16 | |
|
17 | 17 | def __init__(self): |
|
18 | 18 | self.setValues() |
|
19 | 19 | self.createObjects() |
|
20 | 20 | self.testSChain() |
|
21 | 21 | |
|
22 | 22 | def setValues(self): |
|
23 | 23 | self.path = "/Users/jro/Documents/RadarData/MST_ISR/MST" |
|
24 | 24 | # self.path = "/home/roj-idl71/Data/RAWDATA/IMAGING" |
|
25 | 25 | self.path = "/Users/danielangelsuarezmunoz/Data/EW_Drifts" |
|
26 | 26 | self.path = "/Users/danielangelsuarezmunoz/Data/IMAGING" |
|
27 | 27 | |
|
28 | 28 | self.startDate = datetime.date(2012,3,1) |
|
29 | 29 | self.endDate = datetime.date(2012,3,30) |
|
30 | 30 | |
|
31 | 31 | self.startTime = datetime.time(0,0,0) |
|
32 | 32 | self.endTime = datetime.time(14,1,1) |
|
33 | 33 | |
|
34 | 34 | # paramatros para Escritura de Pdata |
|
35 | 35 | self.wrpath = "/Users/danielangelsuarezmunoz/Data/testWR_pdata" |
|
36 |
self.profilesPerBlock = |
|
|
36 | self.profilesPerBlock = 8 | |
|
37 | 37 | self.blocksPerFile = 5 |
|
38 | 38 | # self.pairList = [(0,1),(0,2)] |
|
39 | 39 | |
|
40 | 40 | |
|
41 | 41 | def createObjects(self): |
|
42 | 42 | |
|
43 | 43 | self.readerObj = SpectraReader() |
|
44 | 44 | |
|
45 | 45 | self.specObj1 = self.readerObj.setup( |
|
46 | 46 | path = self.path, |
|
47 | 47 | startDate = self.startDate, |
|
48 | 48 | endDate = self.endDate, |
|
49 | 49 | startTime = self.startTime, |
|
50 | 50 | endTime = self.endTime, |
|
51 | 51 | expLabel = '', |
|
52 | 52 | online = 0) |
|
53 | 53 | # new lines |
|
54 | 54 | self.specObjProc = SpectraProcessor() |
|
55 | 55 | |
|
56 | 56 | self.specObj2 = self.specObjProc.setup(dataInObj = self.specObj1) |
|
57 | 57 | |
|
58 | 58 | |
|
59 | 59 | |
|
60 | 60 | def testSChain(self): |
|
61 | 61 | |
|
62 | 62 | ini = time.time() |
|
63 | 63 | |
|
64 | 64 | while(True): |
|
65 | 65 | self.readerObj.getData() |
|
66 | 66 | |
|
67 | 67 | self.specObjProc.init() |
|
68 | 68 | |
|
69 | 69 | self.specObjProc.writeData(self.wrpath,self.profilesPerBlock,self.blocksPerFile) |
|
70 | 70 | |
|
71 | 71 | if self.readerObj.flagNoMoreFiles: |
|
72 | 72 | break |
|
73 | 73 | |
|
74 | 74 | if self.readerObj.flagIsNewBlock: |
|
75 | 75 | print 'Block No %04d, Time: %s' %(self.readerObj.nTotalBlocks, |
|
76 | 76 | datetime.datetime.fromtimestamp(self.readerObj.basicHeaderObj.utc)) |
|
77 | 77 | |
|
78 | 78 | |
|
79 | 79 | if __name__ == '__main__': |
|
80 | 80 | TestSChain() No newline at end of file |
General Comments 0
You need to be logged in to leave comments.
Login now