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