@@ -1,734 +1,734 | |||
|
1 | 1 | ''' |
|
2 | 2 | |
|
3 | 3 | $Author: murco $ |
|
4 | 4 | $Id: JROHeaderIO.py 151 2012-10-31 19:00:51Z murco $ |
|
5 | 5 | ''' |
|
6 | 6 | import numpy |
|
7 | 7 | import copy |
|
8 | 8 | import datetime |
|
9 | 9 | |
|
10 | 10 | SPEED_OF_LIGHT = 299792458 |
|
11 | 11 | SPEED_OF_LIGHT = 3e8 |
|
12 | 12 | |
|
13 | 13 | BASIC_STRUCTURE = numpy.dtype([ |
|
14 | 14 | ('nSize','<u4'), |
|
15 | 15 | ('nVersion','<u2'), |
|
16 | 16 | ('nDataBlockId','<u4'), |
|
17 | 17 | ('nUtime','<u4'), |
|
18 | 18 | ('nMilsec','<u2'), |
|
19 | 19 | ('nTimezone','<i2'), |
|
20 | 20 | ('nDstflag','<i2'), |
|
21 | 21 | ('nErrorCount','<u4') |
|
22 | 22 | ]) |
|
23 | 23 | |
|
24 | 24 | SYSTEM_STRUCTURE = numpy.dtype([ |
|
25 | 25 | ('nSize','<u4'), |
|
26 | 26 | ('nNumSamples','<u4'), |
|
27 | 27 | ('nNumProfiles','<u4'), |
|
28 | 28 | ('nNumChannels','<u4'), |
|
29 | 29 | ('nADCResolution','<u4'), |
|
30 | 30 | ('nPCDIOBusWidth','<u4'), |
|
31 | 31 | ]) |
|
32 | 32 | |
|
33 | 33 | RADAR_STRUCTURE = numpy.dtype([ |
|
34 | 34 | ('nSize','<u4'), |
|
35 | 35 | ('nExpType','<u4'), |
|
36 | 36 | ('nNTx','<u4'), |
|
37 | 37 | ('fIpp','<f4'), |
|
38 | 38 | ('fTxA','<f4'), |
|
39 | 39 | ('fTxB','<f4'), |
|
40 | 40 | ('nNumWindows','<u4'), |
|
41 | 41 | ('nNumTaus','<u4'), |
|
42 | 42 | ('nCodeType','<u4'), |
|
43 | 43 | ('nLine6Function','<u4'), |
|
44 | 44 | ('nLine5Function','<u4'), |
|
45 | 45 | ('fClock','<f4'), |
|
46 | 46 | ('nPrePulseBefore','<u4'), |
|
47 | 47 | ('nPrePulseAfter','<u4'), |
|
48 | 48 | ('sRangeIPP','<a20'), |
|
49 | 49 | ('sRangeTxA','<a20'), |
|
50 | 50 | ('sRangeTxB','<a20'), |
|
51 | 51 | ]) |
|
52 | 52 | |
|
53 | 53 | SAMPLING_STRUCTURE = numpy.dtype([('h0','<f4'),('dh','<f4'),('nsa','<u4')]) |
|
54 | 54 | |
|
55 | 55 | |
|
56 | 56 | PROCESSING_STRUCTURE = numpy.dtype([ |
|
57 | 57 | ('nSize','<u4'), |
|
58 | 58 | ('nDataType','<u4'), |
|
59 | 59 | ('nSizeOfDataBlock','<u4'), |
|
60 | 60 | ('nProfilesperBlock','<u4'), |
|
61 | 61 | ('nDataBlocksperFile','<u4'), |
|
62 | 62 | ('nNumWindows','<u4'), |
|
63 | 63 | ('nProcessFlags','<u4'), |
|
64 | 64 | ('nCoherentIntegrations','<u4'), |
|
65 | 65 | ('nIncoherentIntegrations','<u4'), |
|
66 | 66 | ('nTotalSpectra','<u4') |
|
67 | 67 | ]) |
|
68 | 68 | |
|
69 | 69 | class Header(object): |
|
70 | 70 | |
|
71 | 71 | def __init__(self): |
|
72 | 72 | raise NotImplementedError |
|
73 | 73 | |
|
74 | 74 | def copy(self): |
|
75 | 75 | return copy.deepcopy(self) |
|
76 | 76 | |
|
77 | 77 | def read(self): |
|
78 | 78 | |
|
79 | 79 | raise NotImplementedError |
|
80 | 80 | |
|
81 | 81 | def write(self): |
|
82 | 82 | |
|
83 | 83 | raise NotImplementedError |
|
84 | 84 | |
|
85 | 85 | def printInfo(self): |
|
86 | 86 | |
|
87 | 87 | message = "#"*50 + "\n" |
|
88 | 88 | message += self.__class__.__name__.upper() + "\n" |
|
89 | 89 | message += "#"*50 + "\n" |
|
90 | 90 | |
|
91 | 91 | for key in self.__dict__.keys(): |
|
92 | 92 | message += "%s = %s" %(key, self.__dict__[key]) + "\n" |
|
93 | 93 | |
|
94 | 94 | print message |
|
95 | 95 | |
|
96 | 96 | class BasicHeader(Header): |
|
97 | 97 | |
|
98 | 98 | size = None |
|
99 | 99 | version = None |
|
100 | 100 | dataBlock = None |
|
101 | 101 | utc = None |
|
102 | 102 | ltc = None |
|
103 | 103 | miliSecond = None |
|
104 | 104 | timeZone = None |
|
105 | 105 | dstFlag = None |
|
106 | 106 | errorCount = None |
|
107 | 107 | datatime = None |
|
108 | 108 | |
|
109 | 109 | __LOCALTIME = None |
|
110 | 110 | |
|
111 | 111 | def __init__(self, useLocalTime=True): |
|
112 | 112 | |
|
113 | 113 | self.size = 24 |
|
114 | 114 | self.version = 0 |
|
115 | 115 | self.dataBlock = 0 |
|
116 | 116 | self.utc = 0 |
|
117 | 117 | self.miliSecond = 0 |
|
118 | 118 | self.timeZone = 0 |
|
119 | 119 | self.dstFlag = 0 |
|
120 | 120 | self.errorCount = 0 |
|
121 | 121 | |
|
122 | 122 | self.useLocalTime = useLocalTime |
|
123 | 123 | |
|
124 | 124 | def read(self, fp): |
|
125 | 125 | |
|
126 | 126 | try: |
|
127 | 127 | header = numpy.fromfile(fp, BASIC_STRUCTURE,1) |
|
128 | 128 | |
|
129 | 129 | except Exception, e: |
|
130 | 130 | print "BasicHeader: " |
|
131 | 131 | print e |
|
132 | 132 | return 0 |
|
133 | 133 | |
|
134 | 134 | self.size = int(header['nSize'][0]) |
|
135 | 135 | self.version = int(header['nVersion'][0]) |
|
136 | 136 | self.dataBlock = int(header['nDataBlockId'][0]) |
|
137 | 137 | self.utc = int(header['nUtime'][0]) |
|
138 | 138 | self.miliSecond = int(header['nMilsec'][0]) |
|
139 | 139 | self.timeZone = int(header['nTimezone'][0]) |
|
140 | 140 | self.dstFlag = int(header['nDstflag'][0]) |
|
141 | 141 | self.errorCount = int(header['nErrorCount'][0]) |
|
142 | 142 | |
|
143 | 143 | return 1 |
|
144 | 144 | |
|
145 | 145 | def write(self, fp): |
|
146 | 146 | |
|
147 | 147 | headerTuple = (self.size,self.version,self.dataBlock,self.utc,self.miliSecond,self.timeZone,self.dstFlag,self.errorCount) |
|
148 | 148 | header = numpy.array(headerTuple, BASIC_STRUCTURE) |
|
149 | 149 | header.tofile(fp) |
|
150 | 150 | |
|
151 | 151 | return 1 |
|
152 | 152 | |
|
153 | 153 | def get_ltc(self): |
|
154 | 154 | |
|
155 | 155 | return self.utc - self.timeZone*60 |
|
156 | 156 | |
|
157 | 157 | def set_ltc(self, value): |
|
158 | 158 | |
|
159 | 159 | self.utc = value + self.timeZone*60 |
|
160 | 160 | |
|
161 | 161 | def get_datatime(self): |
|
162 | 162 | |
|
163 | 163 | return datetime.datetime.utcfromtimestamp(self.ltc) |
|
164 | 164 | |
|
165 | 165 | ltc = property(get_ltc, set_ltc) |
|
166 | 166 | datatime = property(get_datatime) |
|
167 | 167 | |
|
168 | 168 | class SystemHeader(Header): |
|
169 | 169 | |
|
170 | 170 | size = None |
|
171 | 171 | nSamples = None |
|
172 | 172 | nProfiles = None |
|
173 | 173 | nChannels = None |
|
174 | 174 | adcResolution = None |
|
175 | 175 | pciDioBusWidth = None |
|
176 | 176 | |
|
177 | 177 | def __init__(self, nSamples=0, nProfiles=0, nChannels=0, adcResolution=14, pciDioBusWith=0): |
|
178 | 178 | |
|
179 | 179 | self.size = 24 |
|
180 | 180 | self.nSamples = nSamples |
|
181 | 181 | self.nProfiles = nProfiles |
|
182 | 182 | self.nChannels = nChannels |
|
183 | 183 | self.adcResolution = adcResolution |
|
184 | 184 | self.pciDioBusWidth = pciDioBusWith |
|
185 | 185 | |
|
186 | 186 | def read(self, fp): |
|
187 | 187 | |
|
188 | 188 | startFp = fp.tell() |
|
189 | 189 | |
|
190 | 190 | try: |
|
191 | 191 | header = numpy.fromfile(fp,SYSTEM_STRUCTURE,1) |
|
192 | 192 | except Exception, e: |
|
193 | 193 | print "SystemHeader: " + e |
|
194 | 194 | return 0 |
|
195 | 195 | |
|
196 | 196 | self.size = header['nSize'][0] |
|
197 | 197 | self.nSamples = header['nNumSamples'][0] |
|
198 | 198 | self.nProfiles = header['nNumProfiles'][0] |
|
199 | 199 | self.nChannels = header['nNumChannels'][0] |
|
200 | 200 | self.adcResolution = header['nADCResolution'][0] |
|
201 | 201 | self.pciDioBusWidth = header['nPCDIOBusWidth'][0] |
|
202 | 202 | |
|
203 | 203 | endFp = self.size + startFp |
|
204 | 204 | |
|
205 | 205 | if fp.tell() != endFp: |
|
206 | 206 | print "System Header is not consistent" |
|
207 | 207 | return 0 |
|
208 | 208 | |
|
209 | 209 | return 1 |
|
210 | 210 | |
|
211 | 211 | def write(self, fp): |
|
212 | 212 | |
|
213 | 213 | headerTuple = (self.size,self.nSamples,self.nProfiles,self.nChannels,self.adcResolution,self.pciDioBusWidth) |
|
214 | 214 | header = numpy.array(headerTuple,SYSTEM_STRUCTURE) |
|
215 | 215 | header.tofile(fp) |
|
216 | 216 | |
|
217 | 217 | return 1 |
|
218 | 218 | |
|
219 | 219 | class RadarControllerHeader(Header): |
|
220 | 220 | |
|
221 | 221 | size = None |
|
222 | 222 | expType = None |
|
223 | 223 | nTx = None |
|
224 | 224 | ipp = None |
|
225 | 225 | txA = None |
|
226 | 226 | txB = None |
|
227 | 227 | nWindows = None |
|
228 | 228 | numTaus = None |
|
229 | 229 | codeType = None |
|
230 | 230 | line6Function = None |
|
231 | 231 | line5Function = None |
|
232 | 232 | fClock = None |
|
233 | 233 | prePulseBefore = None |
|
234 | 234 | prePulserAfter = None |
|
235 | 235 | rangeIpp = None |
|
236 | 236 | rangeTxA = None |
|
237 | 237 | rangeTxB = None |
|
238 | 238 | |
|
239 | 239 | __size = None |
|
240 | 240 | |
|
241 | 241 | def __init__(self, expType=2, nTx=1, |
|
242 | 242 | ippKm=None, txA=0, txB=0, |
|
243 | 243 | nWindows=None, nHeights=None, firstHeight=None, deltaHeight=None, |
|
244 | 244 | numTaus=0, line6Function=0, line5Function=0, fClock=None, |
|
245 | 245 | prePulseBefore=0, prePulseAfter=0, |
|
246 | 246 | codeType=0, nCode=0, nBaud=0, code=None, |
|
247 | 247 | flip1=0, flip2=0): |
|
248 | 248 | |
|
249 | 249 | self.size = 116 |
|
250 | 250 | self.expType = expType |
|
251 | 251 | self.nTx = nTx |
|
252 | 252 | self.ipp = ippKm |
|
253 | 253 | self.txA = txA |
|
254 | 254 | self.txB = txB |
|
255 | 255 | self.rangeIpp = ippKm |
|
256 | 256 | self.rangeTxA = txA |
|
257 | 257 | self.rangeTxB = txB |
|
258 | 258 | |
|
259 | 259 | self.nWindows = nWindows |
|
260 | 260 | self.numTaus = numTaus |
|
261 | 261 | self.codeType = codeType |
|
262 | 262 | self.line6Function = line6Function |
|
263 | 263 | self.line5Function = line5Function |
|
264 | 264 | self.fClock = fClock |
|
265 | 265 | self.prePulseBefore = prePulseBefore |
|
266 | 266 | self.prePulserAfter = prePulseAfter |
|
267 | 267 | |
|
268 | 268 | self.nHeights = nHeights |
|
269 | 269 | self.firstHeight = firstHeight |
|
270 | 270 | self.deltaHeight = deltaHeight |
|
271 | 271 | self.samplesWin = nHeights |
|
272 | 272 | |
|
273 | 273 | self.nCode = nCode |
|
274 | 274 | self.nBaud = nBaud |
|
275 | 275 | self.code = code |
|
276 | 276 | self.flip1 = flip1 |
|
277 | 277 | self.flip2 = flip2 |
|
278 | 278 | |
|
279 | 279 | self.code_size = int(numpy.ceil(self.nBaud/32.))*self.nCode*4 |
|
280 | 280 | # self.dynamic = numpy.array([],numpy.dtype('byte')) |
|
281 | 281 | |
|
282 | 282 | if self.fClock is None and self.deltaHeight is not None: |
|
283 | 283 | self.fClock = 0.15/(deltaHeight*1e-6) #0.15Km / (height * 1u) |
|
284 | 284 | |
|
285 | 285 | def read(self, fp): |
|
286 | 286 | |
|
287 | 287 | |
|
288 | 288 | startFp = fp.tell() |
|
289 | 289 | try: |
|
290 | 290 | header = numpy.fromfile(fp,RADAR_STRUCTURE,1) |
|
291 | 291 | except Exception, e: |
|
292 | 292 | print "RadarControllerHeader: " + e |
|
293 | 293 | return 0 |
|
294 | 294 | |
|
295 | 295 | size = int(header['nSize'][0]) |
|
296 | 296 | self.expType = int(header['nExpType'][0]) |
|
297 | 297 | self.nTx = int(header['nNTx'][0]) |
|
298 | 298 | self.ipp = float(header['fIpp'][0]) |
|
299 | 299 | self.txA = float(header['fTxA'][0]) |
|
300 | 300 | self.txB = float(header['fTxB'][0]) |
|
301 | 301 | self.nWindows = int(header['nNumWindows'][0]) |
|
302 | 302 | self.numTaus = int(header['nNumTaus'][0]) |
|
303 | 303 | self.codeType = int(header['nCodeType'][0]) |
|
304 | 304 | self.line6Function = int(header['nLine6Function'][0]) |
|
305 | 305 | self.line5Function = int(header['nLine5Function'][0]) |
|
306 | 306 | self.fClock = float(header['fClock'][0]) |
|
307 | 307 | self.prePulseBefore = int(header['nPrePulseBefore'][0]) |
|
308 | 308 | self.prePulserAfter = int(header['nPrePulseAfter'][0]) |
|
309 | 309 | self.rangeIpp = header['sRangeIPP'][0] |
|
310 | 310 | self.rangeTxA = header['sRangeTxA'][0] |
|
311 | 311 | self.rangeTxB = header['sRangeTxB'][0] |
|
312 | 312 | |
|
313 | 313 | samplingWindow = numpy.fromfile(fp,SAMPLING_STRUCTURE,self.nWindows) |
|
314 | 314 | |
|
315 | 315 | self.nHeights = int(numpy.sum(samplingWindow['nsa'])) |
|
316 | 316 | self.firstHeight = samplingWindow['h0'] |
|
317 | 317 | self.deltaHeight = samplingWindow['dh'] |
|
318 | 318 | self.samplesWin = samplingWindow['nsa'] |
|
319 | 319 | |
|
320 | 320 | self.Taus = numpy.fromfile(fp,'<f4',self.numTaus) |
|
321 | 321 | |
|
322 | 322 | self.code_size = 0 |
|
323 | 323 | if self.codeType != 0: |
|
324 | 324 | self.nCode = int(numpy.fromfile(fp,'<u4',1)) |
|
325 | 325 | self.nBaud = int(numpy.fromfile(fp,'<u4',1)) |
|
326 | 326 | |
|
327 | 327 | code = numpy.empty([self.nCode,self.nBaud],dtype='i1') |
|
328 | 328 | for ic in range(self.nCode): |
|
329 | 329 | temp = numpy.fromfile(fp,'u4',int(numpy.ceil(self.nBaud/32.))) |
|
330 | 330 | for ib in range(self.nBaud-1,-1,-1): |
|
331 | 331 | code[ic,ib] = temp[ib/32]%2 |
|
332 | 332 | temp[ib/32] = temp[ib/32]/2 |
|
333 | 333 | |
|
334 | 334 | self.code = 2.0*code - 1.0 |
|
335 | 335 | self.code_size = int(numpy.ceil(self.nBaud/32.))*self.nCode*4 |
|
336 | 336 | |
|
337 | 337 | # if self.line5Function == RCfunction.FLIP: |
|
338 | 338 | # self.flip1 = numpy.fromfile(fp,'<u4',1) |
|
339 | 339 | # |
|
340 | 340 | # if self.line6Function == RCfunction.FLIP: |
|
341 | 341 | # self.flip2 = numpy.fromfile(fp,'<u4',1) |
|
342 | 342 | |
|
343 | 343 | endFp = size + startFp |
|
344 | 344 | |
|
345 | 345 | if fp.tell() != endFp: |
|
346 | 346 | print "Radar Controller Header is not consistent" |
|
347 | 347 | return 0 |
|
348 | 348 | |
|
349 | 349 | return 1 |
|
350 | 350 | |
|
351 | 351 | def write(self, fp): |
|
352 | 352 | |
|
353 | 353 | headerTuple = (self.size, |
|
354 | 354 | self.expType, |
|
355 | 355 | self.nTx, |
|
356 | 356 | self.ipp, |
|
357 | 357 | self.txA, |
|
358 | 358 | self.txB, |
|
359 | 359 | self.nWindows, |
|
360 | 360 | self.numTaus, |
|
361 | 361 | self.codeType, |
|
362 | 362 | self.line6Function, |
|
363 | 363 | self.line5Function, |
|
364 | 364 | self.fClock, |
|
365 | 365 | self.prePulseBefore, |
|
366 | 366 | self.prePulserAfter, |
|
367 | 367 | self.rangeIpp, |
|
368 | 368 | self.rangeTxA, |
|
369 | 369 | self.rangeTxB) |
|
370 | 370 | |
|
371 | 371 | header = numpy.array(headerTuple,RADAR_STRUCTURE) |
|
372 | 372 | header.tofile(fp) |
|
373 | 373 | |
|
374 | 374 | sampleWindowTuple = (self.firstHeight,self.deltaHeight,self.samplesWin) |
|
375 | 375 | samplingWindow = numpy.array(sampleWindowTuple,SAMPLING_STRUCTURE) |
|
376 | 376 | samplingWindow.tofile(fp) |
|
377 | 377 | |
|
378 | 378 | if self.numTaus > 0: |
|
379 | 379 | self.Taus.tofile(fp) |
|
380 | 380 | |
|
381 | 381 | if self.codeType !=0: |
|
382 | 382 | nCode = numpy.array(self.nCode, '<u4') |
|
383 | 383 | nCode.tofile(fp) |
|
384 | 384 | nBaud = numpy.array(self.nBaud, '<u4') |
|
385 | 385 | nBaud.tofile(fp) |
|
386 | 386 | code1 = (self.code + 1.0)/2. |
|
387 | 387 | |
|
388 | 388 | for ic in range(self.nCode): |
|
389 | 389 | tempx = numpy.zeros(numpy.ceil(self.nBaud/32.)) |
|
390 | 390 | start = 0 |
|
391 | 391 | end = 32 |
|
392 | 392 | for i in range(len(tempx)): |
|
393 | 393 | code_selected = code1[ic,start:end] |
|
394 | 394 | for j in range(len(code_selected)-1,-1,-1): |
|
395 | 395 | if code_selected[j] == 1: |
|
396 | 396 | tempx[i] = tempx[i] + 2**(len(code_selected)-1-j) |
|
397 | 397 | start = start + 32 |
|
398 | 398 | end = end + 32 |
|
399 | 399 | |
|
400 | 400 | tempx = tempx.astype('u4') |
|
401 | 401 | tempx.tofile(fp) |
|
402 | 402 | |
|
403 | 403 | # if self.line5Function == RCfunction.FLIP: |
|
404 | 404 | # self.flip1.tofile(fp) |
|
405 | 405 | # |
|
406 | 406 | # if self.line6Function == RCfunction.FLIP: |
|
407 | 407 | # self.flip2.tofile(fp) |
|
408 | 408 | |
|
409 | 409 | return 1 |
|
410 | 410 | |
|
411 | 411 | def get_ippSeconds(self): |
|
412 | 412 | ''' |
|
413 | 413 | ''' |
|
414 | 414 | ippSeconds = 2.0 * 1000 * self.ipp / SPEED_OF_LIGHT |
|
415 | 415 | |
|
416 | 416 | return ippSeconds |
|
417 | 417 | |
|
418 | 418 | def set_ippSeconds(self, ippSeconds): |
|
419 | 419 | ''' |
|
420 | 420 | ''' |
|
421 | 421 | |
|
422 | 422 | self.ipp = ippSeconds * SPEED_OF_LIGHT / (2.0*1000) |
|
423 | 423 | |
|
424 | 424 | return |
|
425 | 425 | |
|
426 | 426 | def get_size(self): |
|
427 | 427 | |
|
428 | 428 | self.__size = 116 + 12*self.nWindows + 4*self.numTaus |
|
429 | 429 | |
|
430 | 430 | if self.codeType != 0: |
|
431 | 431 | self.__size += 4 + 4 + 4*self.nCode*numpy.ceil(self.nBaud/32.) |
|
432 | 432 | |
|
433 | 433 | return self.__size |
|
434 | 434 | |
|
435 | 435 | def set_size(self, value): |
|
436 | 436 | |
|
437 | 437 | self.__size = value |
|
438 | 438 | |
|
439 | 439 | return |
|
440 | 440 | |
|
441 | 441 | ippSeconds = property(get_ippSeconds, set_ippSeconds) |
|
442 | 442 | size = property(get_size, set_size) |
|
443 | 443 | |
|
444 | 444 | class ProcessingHeader(Header): |
|
445 | 445 | |
|
446 | 446 | # size = None |
|
447 | 447 | dtype = None |
|
448 | 448 | blockSize = None |
|
449 | 449 | profilesPerBlock = None |
|
450 | 450 | dataBlocksPerFile = None |
|
451 | 451 | nWindows = None |
|
452 | 452 | processFlags = None |
|
453 | 453 | nCohInt = None |
|
454 | 454 | nIncohInt = None |
|
455 | 455 | totalSpectra = None |
|
456 | 456 | |
|
457 | 457 | flag_dc = None |
|
458 | 458 | flag_cspc = None |
|
459 | 459 | |
|
460 | 460 | def __init__(self): |
|
461 | 461 | |
|
462 | 462 | # self.size = 0 |
|
463 | 463 | self.dtype = 0 |
|
464 | 464 | self.blockSize = 0 |
|
465 | 465 | self.profilesPerBlock = 0 |
|
466 | 466 | self.dataBlocksPerFile = 0 |
|
467 | 467 | self.nWindows = 0 |
|
468 | 468 | self.processFlags = 0 |
|
469 | 469 | self.nCohInt = 0 |
|
470 | 470 | self.nIncohInt = 0 |
|
471 | 471 | self.totalSpectra = 0 |
|
472 | 472 | |
|
473 | 473 | self.nHeights = 0 |
|
474 | 474 | self.firstHeight = 0 |
|
475 | 475 | self.deltaHeight = 0 |
|
476 | 476 | self.samplesWin = 0 |
|
477 | 477 | self.spectraComb = 0 |
|
478 | 478 | self.nCode = None |
|
479 | 479 | self.code = None |
|
480 | 480 | self.nBaud = None |
|
481 | 481 | |
|
482 | 482 | self.shif_fft = False |
|
483 | 483 | self.flag_dc = False |
|
484 | 484 | self.flag_cspc = False |
|
485 | 485 | self.flag_decode = False |
|
486 | 486 | self.flag_deflip = False |
|
487 | 487 | |
|
488 | 488 | def read(self, fp): |
|
489 | 489 | |
|
490 | 490 | startFp = fp.tell() |
|
491 | 491 | |
|
492 | 492 | try: |
|
493 | 493 | header = numpy.fromfile(fp,PROCESSING_STRUCTURE,1) |
|
494 | 494 | except Exception, e: |
|
495 | 495 | print "ProcessingHeader: " + e |
|
496 | 496 | return 0 |
|
497 | 497 | |
|
498 | 498 | size = int(header['nSize'][0]) |
|
499 | 499 | self.dtype = int(header['nDataType'][0]) |
|
500 | 500 | self.blockSize = int(header['nSizeOfDataBlock'][0]) |
|
501 | 501 | self.profilesPerBlock = int(header['nProfilesperBlock'][0]) |
|
502 | 502 | self.dataBlocksPerFile = int(header['nDataBlocksperFile'][0]) |
|
503 | 503 | self.nWindows = int(header['nNumWindows'][0]) |
|
504 | 504 | self.processFlags = header['nProcessFlags'] |
|
505 | 505 | self.nCohInt = int(header['nCoherentIntegrations'][0]) |
|
506 | 506 | self.nIncohInt = int(header['nIncoherentIntegrations'][0]) |
|
507 | 507 | self.totalSpectra = int(header['nTotalSpectra'][0]) |
|
508 | 508 | |
|
509 | 509 | samplingWindow = numpy.fromfile(fp,SAMPLING_STRUCTURE,self.nWindows) |
|
510 | 510 | |
|
511 | 511 | self.nHeights = int(numpy.sum(samplingWindow['nsa'])) |
|
512 | 512 | self.firstHeight = float(samplingWindow['h0'][0]) |
|
513 | 513 | self.deltaHeight = float(samplingWindow['dh'][0]) |
|
514 | 514 | self.samplesWin = samplingWindow['nsa'][0] |
|
515 | 515 | |
|
516 | 516 | self.spectraComb = numpy.fromfile(fp,'u1',2*self.totalSpectra) |
|
517 | 517 | |
|
518 | 518 | if ((self.processFlags & PROCFLAG.DEFINE_PROCESS_CODE) == PROCFLAG.DEFINE_PROCESS_CODE): |
|
519 | 519 | self.nCode = int(numpy.fromfile(fp,'<u4',1)) |
|
520 | 520 | self.nBaud = int(numpy.fromfile(fp,'<u4',1)) |
|
521 | 521 | self.code = numpy.fromfile(fp,'<f4',self.nCode*self.nBaud).reshape(self.nCode,self.nBaud) |
|
522 | 522 | |
|
523 | 523 | if ((self.processFlags & PROCFLAG.EXP_NAME_ESP) == PROCFLAG.EXP_NAME_ESP): |
|
524 | 524 | exp_name_len = int(numpy.fromfile(fp,'<u4',1)) |
|
525 | 525 | exp_name = numpy.fromfile(fp,'u1',exp_name_len+1) |
|
526 | 526 | |
|
527 | 527 | if ((self.processFlags & PROCFLAG.SHIFT_FFT_DATA) == PROCFLAG.SHIFT_FFT_DATA): |
|
528 | 528 | self.shif_fft = True |
|
529 | 529 | else: |
|
530 | 530 | self.shif_fft = False |
|
531 | 531 | |
|
532 | 532 | if ((self.processFlags & PROCFLAG.SAVE_CHANNELS_DC) == PROCFLAG.SAVE_CHANNELS_DC): |
|
533 | 533 | self.flag_dc = True |
|
534 | 534 | else: |
|
535 | 535 | self.flag_dc = False |
|
536 | 536 | |
|
537 | 537 | if ((self.processFlags & PROCFLAG.DECODE_DATA) == PROCFLAG.DECODE_DATA): |
|
538 | 538 | self.flag_decode = True |
|
539 | 539 | else: |
|
540 | 540 | self.flag_decode = False |
|
541 | 541 | |
|
542 | 542 | if ((self.processFlags & PROCFLAG.DEFLIP_DATA) == PROCFLAG.DEFLIP_DATA): |
|
543 | 543 | self.flag_deflip = True |
|
544 | 544 | else: |
|
545 | 545 | self.flag_deflip = False |
|
546 | 546 | |
|
547 | 547 | nChannels = 0 |
|
548 | 548 | nPairs = 0 |
|
549 | 549 | pairList = [] |
|
550 | 550 | |
|
551 | 551 | for i in range( 0, self.totalSpectra*2, 2 ): |
|
552 | 552 | if self.spectraComb[i] == self.spectraComb[i+1]: |
|
553 | 553 | nChannels = nChannels + 1 #par de canales iguales |
|
554 | 554 | else: |
|
555 | 555 | nPairs = nPairs + 1 #par de canales diferentes |
|
556 | 556 | pairList.append( (self.spectraComb[i], self.spectraComb[i+1]) ) |
|
557 | 557 | |
|
558 | 558 | self.flag_cspc = False |
|
559 | 559 | if nPairs > 0: |
|
560 | 560 | self.flag_cspc = True |
|
561 | 561 | |
|
562 | 562 | endFp = size + startFp |
|
563 | 563 | |
|
564 | 564 | if fp.tell() != endFp: |
|
565 | 565 | print "Processing Header is not consistent" |
|
566 | 566 | return 0 |
|
567 | 567 | |
|
568 | 568 | return 1 |
|
569 | 569 | |
|
570 | 570 | def write(self, fp): |
|
571 | 571 | #Clear DEFINE_PROCESS_CODE |
|
572 |
|
|
|
572 | self.processFlags = self.processFlags & (~PROCFLAG.DEFINE_PROCESS_CODE) | |
|
573 | 573 | |
|
574 | 574 | headerTuple = (self.size, |
|
575 | 575 | self.dtype, |
|
576 | 576 | self.blockSize, |
|
577 | 577 | self.profilesPerBlock, |
|
578 | 578 | self.dataBlocksPerFile, |
|
579 | 579 | self.nWindows, |
|
580 | 580 | self.processFlags, |
|
581 | 581 | self.nCohInt, |
|
582 | 582 | self.nIncohInt, |
|
583 | 583 | self.totalSpectra) |
|
584 | 584 | |
|
585 | 585 | header = numpy.array(headerTuple,PROCESSING_STRUCTURE) |
|
586 | 586 | header.tofile(fp) |
|
587 | 587 | |
|
588 | 588 | if self.nWindows != 0: |
|
589 | 589 | sampleWindowTuple = (self.firstHeight,self.deltaHeight,self.samplesWin) |
|
590 | 590 | samplingWindow = numpy.array(sampleWindowTuple,SAMPLING_STRUCTURE) |
|
591 | 591 | samplingWindow.tofile(fp) |
|
592 | 592 | |
|
593 | 593 | if self.totalSpectra != 0: |
|
594 | 594 | # spectraComb = numpy.array([],numpy.dtype('u1')) |
|
595 | 595 | spectraComb = self.spectraComb |
|
596 | 596 | spectraComb.tofile(fp) |
|
597 | 597 | |
|
598 | 598 | if self.processFlags & PROCFLAG.DEFINE_PROCESS_CODE == PROCFLAG.DEFINE_PROCESS_CODE: |
|
599 | 599 | nCode = numpy.array([self.nCode], numpy.dtype('u4')) #Probar con un dato que almacene codigo, hasta el momento no se hizo la prueba |
|
600 | 600 | nCode.tofile(fp) |
|
601 | 601 | |
|
602 | 602 | nBaud = numpy.array([self.nBaud], numpy.dtype('u4')) |
|
603 | 603 | nBaud.tofile(fp) |
|
604 | 604 | |
|
605 | 605 | code = self.code.reshape(self.nCode*self.nBaud) |
|
606 | 606 | code = code.astype(numpy.dtype('<f4')) |
|
607 | 607 | code.tofile(fp) |
|
608 | 608 | |
|
609 | 609 | return 1 |
|
610 | 610 | |
|
611 | 611 | def get_size(self): |
|
612 | 612 | |
|
613 | 613 | self.__size = 40 + 12*self.nWindows + 2*self.totalSpectra |
|
614 | 614 | |
|
615 | 615 | if self.processFlags & PROCFLAG.DEFINE_PROCESS_CODE == PROCFLAG.DEFINE_PROCESS_CODE: |
|
616 | 616 | # self.__size += 4 + 4 + 4*self.nCode*numpy.ceil(self.nBaud/32.) |
|
617 | 617 | self.__size += 4 + 4 + 4 * self.nCode * self.nBaud |
|
618 | 618 | |
|
619 | 619 | return self.__size |
|
620 | 620 | |
|
621 | 621 | def set_size(self, value): |
|
622 | 622 | |
|
623 | 623 | self.__size = value |
|
624 | 624 | |
|
625 | 625 | return |
|
626 | 626 | |
|
627 | 627 | size = property(get_size, set_size) |
|
628 | 628 | |
|
629 | 629 | class RCfunction: |
|
630 | 630 | NONE=0 |
|
631 | 631 | FLIP=1 |
|
632 | 632 | CODE=2 |
|
633 | 633 | SAMPLING=3 |
|
634 | 634 | LIN6DIV256=4 |
|
635 | 635 | SYNCHRO=5 |
|
636 | 636 | |
|
637 | 637 | class nCodeType: |
|
638 | 638 | NONE=0 |
|
639 | 639 | USERDEFINE=1 |
|
640 | 640 | BARKER2=2 |
|
641 | 641 | BARKER3=3 |
|
642 | 642 | BARKER4=4 |
|
643 | 643 | BARKER5=5 |
|
644 | 644 | BARKER7=6 |
|
645 | 645 | BARKER11=7 |
|
646 | 646 | BARKER13=8 |
|
647 | 647 | AC128=9 |
|
648 | 648 | COMPLEMENTARYCODE2=10 |
|
649 | 649 | COMPLEMENTARYCODE4=11 |
|
650 | 650 | COMPLEMENTARYCODE8=12 |
|
651 | 651 | COMPLEMENTARYCODE16=13 |
|
652 | 652 | COMPLEMENTARYCODE32=14 |
|
653 | 653 | COMPLEMENTARYCODE64=15 |
|
654 | 654 | COMPLEMENTARYCODE128=16 |
|
655 | 655 | CODE_BINARY28=17 |
|
656 | 656 | |
|
657 | 657 | class PROCFLAG: |
|
658 | 658 | |
|
659 | 659 | COHERENT_INTEGRATION = numpy.uint32(0x00000001) |
|
660 | 660 | DECODE_DATA = numpy.uint32(0x00000002) |
|
661 | 661 | SPECTRA_CALC = numpy.uint32(0x00000004) |
|
662 | 662 | INCOHERENT_INTEGRATION = numpy.uint32(0x00000008) |
|
663 | 663 | POST_COHERENT_INTEGRATION = numpy.uint32(0x00000010) |
|
664 | 664 | SHIFT_FFT_DATA = numpy.uint32(0x00000020) |
|
665 | 665 | |
|
666 | 666 | DATATYPE_CHAR = numpy.uint32(0x00000040) |
|
667 | 667 | DATATYPE_SHORT = numpy.uint32(0x00000080) |
|
668 | 668 | DATATYPE_LONG = numpy.uint32(0x00000100) |
|
669 | 669 | DATATYPE_INT64 = numpy.uint32(0x00000200) |
|
670 | 670 | DATATYPE_FLOAT = numpy.uint32(0x00000400) |
|
671 | 671 | DATATYPE_DOUBLE = numpy.uint32(0x00000800) |
|
672 | 672 | |
|
673 | 673 | DATAARRANGE_CONTIGUOUS_CH = numpy.uint32(0x00001000) |
|
674 | 674 | DATAARRANGE_CONTIGUOUS_H = numpy.uint32(0x00002000) |
|
675 | 675 | DATAARRANGE_CONTIGUOUS_P = numpy.uint32(0x00004000) |
|
676 | 676 | |
|
677 | 677 | SAVE_CHANNELS_DC = numpy.uint32(0x00008000) |
|
678 | 678 | DEFLIP_DATA = numpy.uint32(0x00010000) |
|
679 | 679 | DEFINE_PROCESS_CODE = numpy.uint32(0x00020000) |
|
680 | 680 | |
|
681 | 681 | ACQ_SYS_NATALIA = numpy.uint32(0x00040000) |
|
682 | 682 | ACQ_SYS_ECHOTEK = numpy.uint32(0x00080000) |
|
683 | 683 | ACQ_SYS_ADRXD = numpy.uint32(0x000C0000) |
|
684 | 684 | ACQ_SYS_JULIA = numpy.uint32(0x00100000) |
|
685 | 685 | ACQ_SYS_XXXXXX = numpy.uint32(0x00140000) |
|
686 | 686 | |
|
687 | 687 | EXP_NAME_ESP = numpy.uint32(0x00200000) |
|
688 | 688 | CHANNEL_NAMES_ESP = numpy.uint32(0x00400000) |
|
689 | 689 | |
|
690 | 690 | OPERATION_MASK = numpy.uint32(0x0000003F) |
|
691 | 691 | DATATYPE_MASK = numpy.uint32(0x00000FC0) |
|
692 | 692 | DATAARRANGE_MASK = numpy.uint32(0x00007000) |
|
693 | 693 | ACQ_SYS_MASK = numpy.uint32(0x001C0000) |
|
694 | 694 | |
|
695 | 695 | dtype0 = numpy.dtype([('real','<i1'),('imag','<i1')]) |
|
696 | 696 | dtype1 = numpy.dtype([('real','<i2'),('imag','<i2')]) |
|
697 | 697 | dtype2 = numpy.dtype([('real','<i4'),('imag','<i4')]) |
|
698 | 698 | dtype3 = numpy.dtype([('real','<i8'),('imag','<i8')]) |
|
699 | 699 | dtype4 = numpy.dtype([('real','<f4'),('imag','<f4')]) |
|
700 | 700 | dtype5 = numpy.dtype([('real','<f8'),('imag','<f8')]) |
|
701 | 701 | |
|
702 | 702 | NUMPY_DTYPE_LIST = [dtype0, dtype1, dtype2, dtype3, dtype4, dtype5] |
|
703 | 703 | |
|
704 | 704 | PROCFLAG_DTYPE_LIST = [PROCFLAG.DATATYPE_CHAR, |
|
705 | 705 | PROCFLAG.DATATYPE_SHORT, |
|
706 | 706 | PROCFLAG.DATATYPE_LONG, |
|
707 | 707 | PROCFLAG.DATATYPE_INT64, |
|
708 | 708 | PROCFLAG.DATATYPE_FLOAT, |
|
709 | 709 | PROCFLAG.DATATYPE_DOUBLE] |
|
710 | 710 | |
|
711 | 711 | DTYPE_WIDTH = [1, 2, 4, 8, 4, 8] |
|
712 | 712 | |
|
713 | 713 | def get_dtype_index(numpy_dtype): |
|
714 | 714 | |
|
715 | 715 | index = None |
|
716 | 716 | |
|
717 | 717 | for i in range(len(NUMPY_DTYPE_LIST)): |
|
718 | 718 | if numpy_dtype == NUMPY_DTYPE_LIST[i]: |
|
719 | 719 | index = i |
|
720 | 720 | break |
|
721 | 721 | |
|
722 | 722 | return index |
|
723 | 723 | |
|
724 | 724 | def get_numpy_dtype(index): |
|
725 | 725 | |
|
726 | 726 | return NUMPY_DTYPE_LIST[index] |
|
727 | 727 | |
|
728 | 728 | def get_procflag_dtype(index): |
|
729 | 729 | |
|
730 | 730 | return PROCFLAG_DTYPE_LIST[index] |
|
731 | 731 | |
|
732 | 732 | def get_dtype_width(index): |
|
733 | 733 | |
|
734 | 734 | return DTYPE_WIDTH[index] No newline at end of file |
General Comments 0
You need to be logged in to leave comments.
Login now