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