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