##// END OF EJS Templates
Agregando los metodos para VoltageProcessor y SpectraProcessor.
Daniel Valdez -
r72:42a785dbddc5
parent child
Show More
@@ -1,433 +1,434
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$
5 @author $Author$
6 @version $Id$
6 @version $Id$
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 Model.JROHeader import *
18 from Model.JROHeader import *
19 from Model.Spectra import Spectra
19 from Model.Spectra import Spectra
20
20
21 from DataIO import JRODataReader
21 from DataIO import JRODataReader
22 from DataIO import JRODataWriter
22 from DataIO import JRODataWriter
23 from DataIO import isNumber
23 from DataIO 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.m_Spectra.data
56 print readerObj.m_Spectra.data
57
57
58 if readerObj.flagNoMoreFiles:
58 if readerObj.flagNoMoreFiles:
59 break
59 break
60
60
61 """
61 """
62 m_DataObj = None
62 m_DataObj = None
63
63
64 data_spc = None
64 data_spc = None
65 data_cspc = None
65 data_cspc = None
66 data_dc = None
66 data_dc = None
67
67
68 pts2read_SelfSpectra = 0
68 pts2read_SelfSpectra = 0
69 pts2read_CrossSpectra = 0
69 pts2read_CrossSpectra = 0
70 pts2read_DCchannels = 0
70 pts2read_DCchannels = 0
71
71
72 nPairsEqualChannels = 0
72 nPairsEqualChannels = 0
73
73
74 nPairsUnequalChannels = 0
74 nPairsUnequalChannels = 0
75
75
76 ext = ".pdata"
76 ext = ".pdata"
77
77
78 optchar = "P"
78 optchar = "P"
79
79
80
80
81 def __init__(self, m_Spectra=None):
81 def __init__(self, m_Spectra=None):
82 """
82 """
83 Inicializador de la clase SpectraReader para la lectura de datos de espectros.
83 Inicializador de la clase SpectraReader para la lectura de datos de espectros.
84
84
85 Inputs:
85 Inputs:
86 m_Spectra : Objeto de la clase Spectra. Este objeto sera utilizado para
86 m_Spectra : Objeto de la clase Spectra. Este objeto sera utilizado para
87 almacenar un perfil de datos cada vez que se haga un requerimiento
87 almacenar un perfil de datos cada vez que se haga un requerimiento
88 (getData). El perfil sera obtenido a partir del buffer de datos,
88 (getData). El perfil sera obtenido a partir del buffer de datos,
89 si el buffer esta vacio se hara un nuevo proceso de lectura de un
89 si el buffer esta vacio se hara un nuevo proceso de lectura de un
90 bloque de datos.
90 bloque de datos.
91 Si este parametro no es pasado se creara uno internamente.
91 Si este parametro no es pasado se creara uno internamente.
92
92
93 Affected:
93 Affected:
94 self.m_DataObj
94 self.m_DataObj
95
95
96 Return : None
96 Return : None
97 """
97 """
98 if m_Spectra == None:
98 if m_Spectra == None:
99 m_Spectra = Spectra()
99 m_Spectra = Spectra()
100
100
101 if not( isinstance(m_Spectra, Spectra) ):
101 if not( isinstance(m_Spectra, Spectra) ):
102 raise ValueError, "in SpectraReader, m_Spectra must be an Spectra class object"
102 raise ValueError, "in SpectraReader, m_Spectra must be an Spectra class object"
103
103
104 self.m_DataObj = m_Spectra
104 self.m_DataObj = m_Spectra
105
105
106
106
107 def __hasNotDataInBuffer(self):
107 def __hasNotDataInBuffer(self):
108 return 1
108 return 1
109
109
110
110
111 def getBlockDimension(self):
111 def getBlockDimension(self):
112 """
112 """
113 Obtiene la cantidad de puntos a leer por cada bloque de datos
113 Obtiene la cantidad de puntos a leer por cada bloque de datos
114
114
115 Affected:
115 Affected:
116 self.nPairsEqualChannels
116 self.nPairsEqualChannels
117 self.nPairsUnequalChannels
117 self.nPairsUnequalChannels
118 self.pts2read_SelfSpectra
118 self.pts2read_SelfSpectra
119 self.pts2read_CrossSpectra
119 self.pts2read_CrossSpectra
120 self.pts2read_DCchannels
120 self.pts2read_DCchannels
121 self.blocksize
121 self.blocksize
122 self.m_DataObj.nPairsEqualChannels
122 self.m_DataObj.nPairsEqualChannels
123 self.m_DataObj.nPairsUnequalChannels
123 self.m_DataObj.nPairsUnequalChannels
124
124
125 Return:
125 Return:
126 None
126 None
127 """
127 """
128 self.nPairsEqualChannels = 0
128 self.nPairsEqualChannels = 0
129 self.nPairsUnequalChannels = 0
129 self.nPairsUnequalChannels = 0
130
130
131 for i in range( 0, self.m_ProcessingHeader.totalSpectra*2, 2 ):
131 for i in range( 0, self.m_ProcessingHeader.totalSpectra*2, 2 ):
132 if self.m_ProcessingHeader.spectraComb[i] == self.m_ProcessingHeader.spectraComb[i+1]:
132 if self.m_ProcessingHeader.spectraComb[i] == self.m_ProcessingHeader.spectraComb[i+1]:
133 self.nPairsEqualChannels = self.nPairsEqualChannels + 1 #par de canales iguales
133 self.nPairsEqualChannels = self.nPairsEqualChannels + 1 #par de canales iguales
134 else:
134 else:
135 self.nPairsUnequalChannels = self.nPairsUnequalChannels + 1 #par de canales diferentes
135 self.nPairsUnequalChannels = self.nPairsUnequalChannels + 1 #par de canales diferentes
136
136
137 pts2read = self.m_ProcessingHeader.numHeights * self.m_ProcessingHeader.profilesPerBlock
137 pts2read = self.m_ProcessingHeader.numHeights * self.m_ProcessingHeader.profilesPerBlock
138
138
139 self.pts2read_SelfSpectra = int( self.nPairsEqualChannels * pts2read )
139 self.pts2read_SelfSpectra = int( self.nPairsEqualChannels * pts2read )
140 self.pts2read_CrossSpectra = int( self.nPairsUnequalChannels * pts2read )
140 self.pts2read_CrossSpectra = int( self.nPairsUnequalChannels * pts2read )
141 self.pts2read_DCchannels = int( self.m_SystemHeader.numChannels * self.m_ProcessingHeader.numHeights )
141 self.pts2read_DCchannels = int( self.m_SystemHeader.numChannels * self.m_ProcessingHeader.numHeights )
142
142
143 self.blocksize = self.pts2read_SelfSpectra + self.pts2read_CrossSpectra + self.pts2read_DCchannels
143 self.blocksize = self.pts2read_SelfSpectra + self.pts2read_CrossSpectra + self.pts2read_DCchannels
144
144
145 self.m_DataObj.nPoints = self.m_ProcessingHeader.profilesPerBlock
145 self.m_DataObj.nPairsEqualChannels = self.nPairsEqualChannels
146 self.m_DataObj.nPairsEqualChannels = self.nPairsEqualChannels
146 self.m_DataObj.nPairsUnequalChannels = self.nPairsUnequalChannels
147 self.m_DataObj.nPairsUnequalChannels = self.nPairsUnequalChannels
147
148
148
149
149 def readBlock(self):
150 def readBlock(self):
150 """
151 """
151 Lee el bloque de datos desde la posicion actual del puntero del archivo
152 Lee el bloque de datos desde la posicion actual del puntero del archivo
152 (self.fp) y actualiza todos los parametros relacionados al bloque de datos
153 (self.fp) y actualiza todos los parametros relacionados al bloque de datos
153 (metadata + data). La data leida es almacenada en el buffer y el contador del buffer
154 (metadata + data). La data leida es almacenada en el buffer y el contador del buffer
154 es seteado a 0
155 es seteado a 0
155
156
156 Return: None
157 Return: None
157
158
158 Variables afectadas:
159 Variables afectadas:
159 self.datablockIndex
160 self.datablockIndex
160 self.flagIsNewFile
161 self.flagIsNewFile
161 self.flagIsNewBlock
162 self.flagIsNewBlock
162 self.nReadBlocks
163 self.nReadBlocks
163 self.data_spc
164 self.data_spc
164 self.data_cspc
165 self.data_cspc
165 self.data_dc
166 self.data_dc
166
167
167 Exceptions:
168 Exceptions:
168 Si un bloque leido no es un bloque valido
169 Si un bloque leido no es un bloque valido
169 """
170 """
170 blockOk_flag = False
171 blockOk_flag = False
171 fpointer = self.fp.tell()
172 fpointer = self.fp.tell()
172
173
173 spc = numpy.fromfile( self.fp, self.dataType[0], self.pts2read_SelfSpectra )
174 spc = numpy.fromfile( self.fp, self.dataType[0], self.pts2read_SelfSpectra )
174 cspc = numpy.fromfile( self.fp, self.dataType, self.pts2read_CrossSpectra )
175 cspc = numpy.fromfile( self.fp, self.dataType, self.pts2read_CrossSpectra )
175 dc = numpy.fromfile( self.fp, self.dataType, self.pts2read_DCchannels ) #int(self.m_ProcessingHeader.numHeights*self.m_SystemHeader.numChannels) )
176 dc = numpy.fromfile( self.fp, self.dataType, self.pts2read_DCchannels ) #int(self.m_ProcessingHeader.numHeights*self.m_SystemHeader.numChannels) )
176
177
177 if self.online:
178 if self.online:
178 if (spc.size + cspc.size + dc.size) != self.blocksize:
179 if (spc.size + cspc.size + dc.size) != self.blocksize:
179 for nTries in range( self.nTries ):
180 for nTries in range( self.nTries ):
180 print "\tWaiting %0.2f sec for the next block, try %03d ..." % (self.delay, nTries+1)
181 print "\tWaiting %0.2f sec for the next block, try %03d ..." % (self.delay, nTries+1)
181 time.sleep( self.delay )
182 time.sleep( self.delay )
182 self.fp.seek( fpointer )
183 self.fp.seek( fpointer )
183 fpointer = self.fp.tell()
184 fpointer = self.fp.tell()
184
185
185 spc = numpy.fromfile( self.fp, self.dataType[0], self.pts2read_SelfSpectra )
186 spc = numpy.fromfile( self.fp, self.dataType[0], self.pts2read_SelfSpectra )
186 cspc = numpy.fromfile( self.fp, self.dataType, self.pts2read_CrossSpectra )
187 cspc = numpy.fromfile( self.fp, self.dataType, self.pts2read_CrossSpectra )
187 dc = numpy.fromfile( self.fp, self.dataType, self.pts2read_DCchannels ) #int(self.m_ProcessingHeader.numHeights*self.m_SystemHeader.numChannels) )
188 dc = numpy.fromfile( self.fp, self.dataType, self.pts2read_DCchannels ) #int(self.m_ProcessingHeader.numHeights*self.m_SystemHeader.numChannels) )
188
189
189 if (spc.size + cspc.size + dc.size) == self.blocksize:
190 if (spc.size + cspc.size + dc.size) == self.blocksize:
190 blockOk_flag = True
191 blockOk_flag = True
191 break
192 break
192
193
193 if not( blockOk_flag ):
194 if not( blockOk_flag ):
194 return 0
195 return 0
195
196
196 try:
197 try:
197 spc = spc.reshape( (self.nPairsEqualChannels, self.m_ProcessingHeader.numHeights, self.m_ProcessingHeader.profilesPerBlock) ) #transforma a un arreglo 3D
198 spc = spc.reshape( (self.nPairsEqualChannels, self.m_ProcessingHeader.numHeights, self.m_ProcessingHeader.profilesPerBlock) ) #transforma a un arreglo 3D
198 cspc = cspc.reshape( (self.nPairsUnequalChannels, self.m_ProcessingHeader.numHeights, self.m_ProcessingHeader.profilesPerBlock) ) #transforma a un arreglo 3D
199 cspc = cspc.reshape( (self.nPairsUnequalChannels, self.m_ProcessingHeader.numHeights, self.m_ProcessingHeader.profilesPerBlock) ) #transforma a un arreglo 3D
199 dc = dc.reshape( (self.m_SystemHeader.numChannels, self.m_ProcessingHeader.numHeights) ) #transforma a un arreglo 2D
200 dc = dc.reshape( (self.m_SystemHeader.numChannels, self.m_ProcessingHeader.numHeights) ) #transforma a un arreglo 2D
200 except:
201 except:
201 print "Data file %s is invalid" % self.filename
202 print "Data file %s is invalid" % self.filename
202 return 0
203 return 0
203
204
204 if not( self.m_ProcessingHeader.shif_fft ):
205 if not( self.m_ProcessingHeader.shif_fft ):
205 spc = numpy.roll( spc, self.m_ProcessingHeader.profilesPerBlock/2, axis=2 ) #desplaza a la derecha en el eje 2 determinadas posiciones
206 spc = numpy.roll( spc, self.m_ProcessingHeader.profilesPerBlock/2, axis=2 ) #desplaza a la derecha en el eje 2 determinadas posiciones
206 cspc = numpy.roll( cspc, self.m_ProcessingHeader.profilesPerBlock/2, axis=2 ) #desplaza a la derecha en el eje 2 determinadas posiciones
207 cspc = numpy.roll( cspc, self.m_ProcessingHeader.profilesPerBlock/2, axis=2 ) #desplaza a la derecha en el eje 2 determinadas posiciones
207
208
208 # spc = numpy.transpose( spc, (0,2,1) )
209 # spc = numpy.transpose( spc, (0,2,1) )
209 # cspc = numpy.transpose( cspc, (0,2,1) )
210 # cspc = numpy.transpose( cspc, (0,2,1) )
210 #dc = numpy.transpose(dc, (0,2,1))
211 #dc = numpy.transpose(dc, (0,2,1))
211
212
212 self.data_spc = spc
213 self.data_spc = spc
213 self.data_cspc = cspc['real'] + cspc['imag']*1j
214 self.data_cspc = cspc['real'] + cspc['imag']*1j
214 self.data_dc = dc['real'] + dc['imag']*1j
215 self.data_dc = dc['real'] + dc['imag']*1j
215
216
216 self.datablockIndex = 0
217 self.datablockIndex = 0
217 self.flagIsNewFile = 0
218 self.flagIsNewFile = 0
218 self.flagIsNewBlock = 1
219 self.flagIsNewBlock = 1
219
220
220 self.nReadBlocks += 1
221 self.nReadBlocks += 1
221 self.nBlocks += 1
222 self.nBlocks += 1
222
223
223 return 1
224 return 1
224
225
225
226
226 def getData(self):
227 def getData(self):
227 """
228 """
228 Copia el buffer de lectura a la clase "Spectra",
229 Copia el buffer de lectura a la clase "Spectra",
229 con todos los parametros asociados a este (metadata). cuando no hay datos en el buffer de
230 con todos los parametros asociados a este (metadata). cuando no hay datos en el buffer de
230 lectura es necesario hacer una nueva lectura de los bloques de datos usando "readNextBlock"
231 lectura es necesario hacer una nueva lectura de los bloques de datos usando "readNextBlock"
231
232
232 Return:
233 Return:
233 0 : Si no hay mas archivos disponibles
234 0 : Si no hay mas archivos disponibles
234 1 : Si hizo una buena copia del buffer
235 1 : Si hizo una buena copia del buffer
235
236
236 Affected:
237 Affected:
237 self.m_DataObj
238 self.m_DataObj
238 self.datablockIndex
239 self.datablockIndex
239 self.flagResetProcessing
240 self.flagResetProcessing
240 self.flagIsNewBlock
241 self.flagIsNewBlock
241 """
242 """
242
243
243 if self.flagNoMoreFiles: return 0
244 if self.flagNoMoreFiles: return 0
244
245
245 self.flagResetProcessing = 0
246 self.flagResetProcessing = 0
246 self.flagIsNewBlock = 0
247 self.flagIsNewBlock = 0
247
248
248 if self.__hasNotDataInBuffer():
249 if self.__hasNotDataInBuffer():
249
250
250 if not( self.readNextBlock() ):
251 if not( self.readNextBlock() ):
251 self.setNextFile()
252 self.setNextFile()
252 return 0
253 return 0
253
254
254 self.m_DataObj.m_BasicHeader = self.m_BasicHeader.copy()
255 self.m_DataObj.m_BasicHeader = self.m_BasicHeader.copy()
255 self.m_DataObj.m_ProcessingHeader = self.m_ProcessingHeader.copy()
256 self.m_DataObj.m_ProcessingHeader = self.m_ProcessingHeader.copy()
256 self.m_DataObj.m_RadarControllerHeader = self.m_RadarControllerHeader.copy()
257 self.m_DataObj.m_RadarControllerHeader = self.m_RadarControllerHeader.copy()
257 self.m_DataObj.m_SystemHeader = self.m_SystemHeader.copy()
258 self.m_DataObj.m_SystemHeader = self.m_SystemHeader.copy()
258 self.m_DataObj.heights = self.heights
259 self.m_DataObj.heights = self.heights
259 self.m_DataObj.dataType = self.dataType
260 self.m_DataObj.dataType = self.dataType
260
261
261 if self.flagNoMoreFiles == 1:
262 if self.flagNoMoreFiles == 1:
262 print 'Process finished'
263 print 'Process finished'
263 return 0
264 return 0
264
265
265 #data es un numpy array de 3 dmensiones (perfiles, alturas y canales)
266 #data es un numpy array de 3 dmensiones (perfiles, alturas y canales)
266
267
267 if self.data_dc == None:
268 if self.data_dc == None:
268 self.m_DataObj.flagNoData = True
269 self.m_DataObj.flagNoData = True
269 return 0
270 return 0
270
271
271 self.m_DataObj.flagNoData = False
272 self.m_DataObj.flagNoData = False
272 self.m_DataObj.flagResetProcessing = self.flagResetProcessing
273 self.m_DataObj.flagResetProcessing = self.flagResetProcessing
273
274
274 self.m_DataObj.data_spc = self.data_spc
275 self.m_DataObj.data_spc = self.data_spc
275 self.m_DataObj.data_cspc = self.data_cspc
276 self.m_DataObj.data_cspc = self.data_cspc
276 self.m_DataObj.data_dc = self.data_dc
277 self.m_DataObj.data_dc = self.data_dc
277
278
278 return 1
279 return 1
279
280
280
281
281 class SpectraWriter(JRODataWriter):
282 class SpectraWriter(JRODataWriter):
282
283
283 """
284 """
284 Esta clase permite escribir datos de espectros a archivos procesados (.pdata). La escritura
285 Esta clase permite escribir datos de espectros a archivos procesados (.pdata). La escritura
285 de los datos siempre se realiza por bloques.
286 de los datos siempre se realiza por bloques.
286 """
287 """
287
288
288 m_DataObj = None
289 m_DataObj = None
289
290
290 ext = ".pdata"
291 ext = ".pdata"
291
292
292 optchar = "P"
293 optchar = "P"
293
294
294 shape_spc_Buffer = None
295 shape_spc_Buffer = None
295 shape_cspc_Buffer = None
296 shape_cspc_Buffer = None
296 shape_dc_Buffer = None
297 shape_dc_Buffer = None
297
298
298
299
299 def __init__(self, m_Spectra=None):
300 def __init__(self, m_Spectra=None):
300 """
301 """
301 Inicializador de la clase SpectraWriter para la escritura de datos de espectros.
302 Inicializador de la clase SpectraWriter para la escritura de datos de espectros.
302
303
303 Affected:
304 Affected:
304 self.m_DataObj
305 self.m_DataObj
305 self.m_BasicHeader
306 self.m_BasicHeader
306 self.m_SystemHeader
307 self.m_SystemHeader
307 self.m_RadarControllerHeader
308 self.m_RadarControllerHeader
308 self.m_ProcessingHeader
309 self.m_ProcessingHeader
309
310
310 Return: None
311 Return: None
311 """
312 """
312 if m_Spectra == None:
313 if m_Spectra == None:
313 m_Spectra = Spectra()
314 m_Spectra = Spectra()
314
315
315 if not( isinstance(m_Spectra, Spectra) ):
316 if not( isinstance(m_Spectra, Spectra) ):
316 raise ValueError, "in SpectraReader, m_Spectra must be an Spectra class object"
317 raise ValueError, "in SpectraReader, m_Spectra must be an Spectra class object"
317
318
318 self.m_DataObj = m_Spectra
319 self.m_DataObj = m_Spectra
319
320
320
321
321 def hasAllDataInBuffer(self):
322 def hasAllDataInBuffer(self):
322 return 1
323 return 1
323
324
324
325
325 def setBlockDimension(self):
326 def setBlockDimension(self):
326 """
327 """
327 Obtiene las formas dimensionales del los subbloques de datos que componen un bloque
328 Obtiene las formas dimensionales del los subbloques de datos que componen un bloque
328
329
329 Affected:
330 Affected:
330 self.shape_spc_Buffer
331 self.shape_spc_Buffer
331 self.shape_cspc_Buffer
332 self.shape_cspc_Buffer
332 self.shape_dc_Buffer
333 self.shape_dc_Buffer
333
334
334 Return: None
335 Return: None
335 """
336 """
336 self.shape_spc_Buffer = (self.m_DataObj.nPairsEqualChannels,
337 self.shape_spc_Buffer = (self.m_DataObj.nPairsEqualChannels,
337 self.m_ProcessingHeader.numHeights,
338 self.m_ProcessingHeader.numHeights,
338 self.m_ProcessingHeader.profilesPerBlock)
339 self.m_ProcessingHeader.profilesPerBlock)
339
340
340 self.shape_cspc_Buffer = (self.m_DataObj.nPairsUnequalChannels,
341 self.shape_cspc_Buffer = (self.m_DataObj.nPairsUnequalChannels,
341 self.m_ProcessingHeader.numHeights,
342 self.m_ProcessingHeader.numHeights,
342 self.m_ProcessingHeader.profilesPerBlock)
343 self.m_ProcessingHeader.profilesPerBlock)
343
344
344 self.shape_dc_Buffer = (self.m_SystemHeader.numChannels,
345 self.shape_dc_Buffer = (self.m_SystemHeader.numChannels,
345 self.m_ProcessingHeader.numHeights)
346 self.m_ProcessingHeader.numHeights)
346
347
347
348
348 def writeBlock(self):
349 def writeBlock(self):
349 """
350 """
350 Escribe el buffer en el file designado
351 Escribe el buffer en el file designado
351
352
352 Affected:
353 Affected:
353 self.data_spc
354 self.data_spc
354 self.data_cspc
355 self.data_cspc
355 self.data_dc
356 self.data_dc
356 self.flagIsNewFile
357 self.flagIsNewFile
357 self.flagIsNewBlock
358 self.flagIsNewBlock
358 self.nWriteBlocks
359 self.nWriteBlocks
359 self.blocksCounter
360 self.blocksCounter
360
361
361 Return: None
362 Return: None
362 """
363 """
363 spc = self.data_spc
364 spc = self.data_spc
364 # spc = numpy.transpose( self.data_spc, (0,2,1) )
365 # spc = numpy.transpose( self.data_spc, (0,2,1) )
365 if not( self.m_ProcessingHeader.shif_fft ):
366 if not( self.m_ProcessingHeader.shif_fft ):
366 spc = numpy.roll( spc, self.m_ProcessingHeader.profilesPerBlock/2, axis=2 ) #desplaza a la derecha en el eje 2 determinadas posiciones
367 spc = numpy.roll( spc, self.m_ProcessingHeader.profilesPerBlock/2, axis=2 ) #desplaza a la derecha en el eje 2 determinadas posiciones
367 data = spc.reshape((-1))
368 data = spc.reshape((-1))
368 data.tofile(self.fp)
369 data.tofile(self.fp)
369
370
370 data = numpy.zeros( self.shape_cspc_Buffer, self.dataType )
371 data = numpy.zeros( self.shape_cspc_Buffer, self.dataType )
371 cspc = self.data_cspc
372 cspc = self.data_cspc
372 # cspc = numpy.transpose( self.data_cspc, (0,2,1) )
373 # cspc = numpy.transpose( self.data_cspc, (0,2,1) )
373 if not( self.m_ProcessingHeader.shif_fft ):
374 if not( self.m_ProcessingHeader.shif_fft ):
374 cspc = numpy.roll( cspc, self.m_ProcessingHeader.profilesPerBlock/2, axis=2 ) #desplaza a la derecha en el eje 2 determinadas posiciones
375 cspc = numpy.roll( cspc, self.m_ProcessingHeader.profilesPerBlock/2, axis=2 ) #desplaza a la derecha en el eje 2 determinadas posiciones
375 data['imag'] = cspc.imag
376 data['imag'] = cspc.imag
376 data = data.reshape((-1))
377 data = data.reshape((-1))
377 data.tofile(self.fp)
378 data.tofile(self.fp)
378
379
379 data = numpy.zeros( self.shape_dc_Buffer, self.dataType )
380 data = numpy.zeros( self.shape_dc_Buffer, self.dataType )
380 dc = self.data_dc
381 dc = self.data_dc
381 data['real'] = dc.real
382 data['real'] = dc.real
382 data['imag'] = dc.imag
383 data['imag'] = dc.imag
383 data = data.reshape((-1))
384 data = data.reshape((-1))
384 data.tofile(self.fp)
385 data.tofile(self.fp)
385
386
386 self.data_spc.fill(0)
387 self.data_spc.fill(0)
387 self.data_cspc.fill(0)
388 self.data_cspc.fill(0)
388 self.data_dc.fill(0)
389 self.data_dc.fill(0)
389
390
390 self.flagIsNewFile = 0
391 self.flagIsNewFile = 0
391 self.flagIsNewBlock = 1
392 self.flagIsNewBlock = 1
392 self.nWriteBlocks += 1
393 self.nWriteBlocks += 1
393 self.blocksCounter += 1
394 self.blocksCounter += 1
394
395
395
396
396 def putData(self):
397 def putData(self):
397 """
398 """
398 Setea un bloque de datos y luego los escribe en un file
399 Setea un bloque de datos y luego los escribe en un file
399
400
400 Affected:
401 Affected:
401 self.data_spc
402 self.data_spc
402 self.data_cspc
403 self.data_cspc
403 self.data_dc
404 self.data_dc
404
405
405 Return:
406 Return:
406 0 : Si no hay data o no hay mas files que puedan escribirse
407 0 : Si no hay data o no hay mas files que puedan escribirse
407 1 : Si se escribio la data de un bloque en un file
408 1 : Si se escribio la data de un bloque en un file
408 """
409 """
409 self.flagIsNewBlock = 0
410 self.flagIsNewBlock = 0
410
411
411 if self.m_DataObj.flagNoData:
412 if self.m_DataObj.flagNoData:
412 return 0
413 return 0
413
414
414 if self.m_DataObj.flagResetProcessing:
415 if self.m_DataObj.flagResetProcessing:
415 self.data_spc.fill(0)
416 self.data_spc.fill(0)
416 self.data_cspc.fill(0)
417 self.data_cspc.fill(0)
417 self.data_dc.fill(0)
418 self.data_dc.fill(0)
418 self.setNextFile()
419 self.setNextFile()
419
420
420 self.data_spc = self.m_DataObj.data_spc
421 self.data_spc = self.m_DataObj.data_spc
421 self.data_cspc = self.m_DataObj.data_cspc
422 self.data_cspc = self.m_DataObj.data_cspc
422 self.data_dc = self.m_DataObj.data_dc
423 self.data_dc = self.m_DataObj.data_dc
423
424
424 # #self.m_ProcessingHeader.dataBlocksPerFile)
425 # #self.m_ProcessingHeader.dataBlocksPerFile)
425 if True:
426 if True:
426 self.getHeader()
427 self.getHeader()
427 self.writeNextBlock()
428 self.writeNextBlock()
428
429
429 if self.flagNoMoreFiles:
430 if self.flagNoMoreFiles:
430 #print 'Process finished'
431 #print 'Process finished'
431 return 0
432 return 0
432
433
433 return 1 No newline at end of file
434 return 1
@@ -1,391 +1,392
1 '''
1 '''
2 Created on 23/01/2012
2 Created on 23/01/2012
3
3
4 @author $Author$
4 @author $Author$
5 @version $Id$
5 @version $Id$
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 Model.JROHeader import *
17 from Model.JROHeader import *
18 from Model.Voltage import Voltage
18 from Model.Voltage import Voltage
19
19
20 from IO.DataIO import JRODataReader
20 from IO.DataIO import JRODataReader
21 from IO.DataIO import JRODataWriter
21 from IO.DataIO import JRODataWriter
22
22
23
23
24 class VoltageReader(JRODataReader):
24 class VoltageReader(JRODataReader):
25 """
25 """
26 Esta clase permite leer datos de voltage desde archivos en formato rawdata (.r). La lectura
26 Esta clase permite leer datos de voltage desde archivos en formato rawdata (.r). La lectura
27 de los datos siempre se realiza por bloques. Los datos leidos (array de 3 dimensiones:
27 de los datos siempre se realiza por bloques. Los datos leidos (array de 3 dimensiones:
28 perfiles*alturas*canales) son almacenados en la variable "buffer".
28 perfiles*alturas*canales) son almacenados en la variable "buffer".
29
29
30 perfiles * alturas * canales
30 perfiles * alturas * canales
31
31
32 Esta clase contiene instancias (objetos) de las clases BasicHeader, SystemHeader,
32 Esta clase contiene instancias (objetos) de las clases BasicHeader, SystemHeader,
33 RadarControllerHeader y Voltage. Los tres primeros se usan para almacenar informacion de la
33 RadarControllerHeader y Voltage. Los tres primeros se usan para almacenar informacion de la
34 cabecera de datos (metadata), y el cuarto (Voltage) para obtener y almacenar un perfil de
34 cabecera de datos (metadata), y el cuarto (Voltage) para obtener y almacenar un perfil de
35 datos desde el "buffer" cada vez que se ejecute el metodo "getData".
35 datos desde el "buffer" cada vez que se ejecute el metodo "getData".
36
36
37 Example:
37 Example:
38
38
39 dpath = "/home/myuser/data"
39 dpath = "/home/myuser/data"
40
40
41 startTime = datetime.datetime(2010,1,20,0,0,0,0,0,0)
41 startTime = datetime.datetime(2010,1,20,0,0,0,0,0,0)
42
42
43 endTime = datetime.datetime(2010,1,21,23,59,59,0,0,0)
43 endTime = datetime.datetime(2010,1,21,23,59,59,0,0,0)
44
44
45 readerObj = VoltageReader()
45 readerObj = VoltageReader()
46
46
47 readerObj.setup(dpath, startTime, endTime)
47 readerObj.setup(dpath, startTime, endTime)
48
48
49 while(True):
49 while(True):
50
50
51 #to get one profile
51 #to get one profile
52 profile = readerObj.getData()
52 profile = readerObj.getData()
53
53
54 #print the profile
54 #print the profile
55 print profile
55 print profile
56
56
57 #If you want to see all datablock
57 #If you want to see all datablock
58 print readerObj.datablock
58 print readerObj.datablock
59
59
60 if readerObj.flagNoMoreFiles:
60 if readerObj.flagNoMoreFiles:
61 break
61 break
62
62
63 """
63 """
64 m_DataObj = None
64 m_DataObj = None
65
65
66 idProfile = 0
66 idProfile = 0
67
67
68 datablock = None
68 datablock = None
69
69
70 pts2read = 0
70 pts2read = 0
71
71
72 utc = 0
72 utc = 0
73
73
74 ext = ".r"
74 ext = ".r"
75
75
76 optchar = "D"
76 optchar = "D"
77
77
78
78
79 def __init__(self, m_Voltage=None):
79 def __init__(self, m_Voltage=None):
80 """
80 """
81 Inicializador de la clase VoltageReader para la lectura de datos de voltage.
81 Inicializador de la clase VoltageReader para la lectura de datos de voltage.
82
82
83 Input:
83 Input:
84 m_Voltage : Objeto de la clase Voltage. Este objeto sera utilizado para
84 m_Voltage : Objeto de la clase Voltage. Este objeto sera utilizado para
85 almacenar un perfil de datos cada vez que se haga un requerimiento
85 almacenar un perfil de datos cada vez que se haga un requerimiento
86 (getData). El perfil sera obtenido a partir del buffer de datos,
86 (getData). El perfil sera obtenido a partir del buffer de datos,
87 si el buffer esta vacio se hara un nuevo proceso de lectura de un
87 si el buffer esta vacio se hara un nuevo proceso de lectura de un
88 bloque de datos.
88 bloque de datos.
89 Si este parametro no es pasado se creara uno internamente.
89 Si este parametro no es pasado se creara uno internamente.
90
90
91 Variables afectadas:
91 Variables afectadas:
92 self.m_DataObj
92 self.m_DataObj
93
93
94 Return:
94 Return:
95 None
95 None
96 """
96 """
97 if m_Voltage == None:
97 if m_Voltage == None:
98 m_Voltage = Voltage()
98 m_Voltage = Voltage()
99
99
100 if not(isinstance(m_Voltage, Voltage)):
100 if not(isinstance(m_Voltage, Voltage)):
101 raise ValueError, "in VoltageReader, m_Voltage must be an Voltage class object"
101 raise ValueError, "in VoltageReader, m_Voltage must be an Voltage class object"
102
102
103 self.m_DataObj = m_Voltage
103 self.m_DataObj = m_Voltage
104
104
105
105
106 def __hasNotDataInBuffer(self):
106 def __hasNotDataInBuffer(self):
107 if self.datablockIndex >= self.m_ProcessingHeader.profilesPerBlock:
107 if self.datablockIndex >= self.m_ProcessingHeader.profilesPerBlock:
108 return 1
108 return 1
109 return 0
109 return 0
110
110
111
111
112 def getBlockDimension(self):
112 def getBlockDimension(self):
113 """
113 """
114 Obtiene la cantidad de puntos a leer por cada bloque de datos
114 Obtiene la cantidad de puntos a leer por cada bloque de datos
115
115
116 Affected:
116 Affected:
117 self.pts2read
117 self.pts2read
118 self.blocksize
118 self.blocksize
119
119
120 Return:
120 Return:
121 None
121 None
122 """
122 """
123 self.pts2read = self.m_ProcessingHeader.profilesPerBlock * self.m_ProcessingHeader.numHeights * self.m_SystemHeader.numChannels
123 self.pts2read = self.m_ProcessingHeader.profilesPerBlock * self.m_ProcessingHeader.numHeights * self.m_SystemHeader.numChannels
124 self.blocksize = self.pts2read
124 self.blocksize = self.pts2read
125 self.m_DataObj.nProfiles = self.m_ProcessingHeader.profilesPerBlock
125
126
126
127
127 def readBlock(self):
128 def readBlock(self):
128 """
129 """
129 readBlock lee el bloque de datos desde la posicion actual del puntero del archivo
130 readBlock lee el bloque de datos desde la posicion actual del puntero del archivo
130 (self.fp) y actualiza todos los parametros relacionados al bloque de datos
131 (self.fp) y actualiza todos los parametros relacionados al bloque de datos
131 (metadata + data). La data leida es almacenada en el buffer y el contador del buffer
132 (metadata + data). La data leida es almacenada en el buffer y el contador del buffer
132 es seteado a 0
133 es seteado a 0
133
134
134 Inputs:
135 Inputs:
135 None
136 None
136
137
137 Return:
138 Return:
138 None
139 None
139
140
140 Affected:
141 Affected:
141 self.datablockIndex
142 self.datablockIndex
142 self.datablock
143 self.datablock
143 self.flagIsNewFile
144 self.flagIsNewFile
144 self.idProfile
145 self.idProfile
145 self.flagIsNewBlock
146 self.flagIsNewBlock
146 self.nReadBlocks
147 self.nReadBlocks
147
148
148 Exceptions:
149 Exceptions:
149 Si un bloque leido no es un bloque valido
150 Si un bloque leido no es un bloque valido
150 """
151 """
151 blockOk_flag = False
152 blockOk_flag = False
152 fpointer = self.fp.tell()
153 fpointer = self.fp.tell()
153
154
154 junk = numpy.fromfile( self.fp, self.dataType, self.pts2read )
155 junk = numpy.fromfile( self.fp, self.dataType, self.pts2read )
155
156
156 if self.online:
157 if self.online:
157 if junk.size != self.blocksize:
158 if junk.size != self.blocksize:
158 for nTries in range( self.nTries ):
159 for nTries in range( self.nTries ):
159 print "\tWaiting %0.2f sec for the next block, try %03d ..." % (self.delay, nTries+1)
160 print "\tWaiting %0.2f sec for the next block, try %03d ..." % (self.delay, nTries+1)
160 time.sleep( self.delay )
161 time.sleep( self.delay )
161 self.fp.seek( fpointer )
162 self.fp.seek( fpointer )
162 fpointer = self.fp.tell()
163 fpointer = self.fp.tell()
163
164
164 junk = numpy.fromfile( self.fp, self.dataType, self.pts2read )
165 junk = numpy.fromfile( self.fp, self.dataType, self.pts2read )
165
166
166 if junk.size == self.blocksize:
167 if junk.size == self.blocksize:
167 blockOk_flag = True
168 blockOk_flag = True
168 break
169 break
169
170
170 if not( blockOk_flag ):
171 if not( blockOk_flag ):
171 return 0
172 return 0
172
173
173 try:
174 try:
174 junk = junk.reshape( (self.m_ProcessingHeader.profilesPerBlock, self.m_ProcessingHeader.numHeights, self.m_SystemHeader.numChannels) )
175 junk = junk.reshape( (self.m_ProcessingHeader.profilesPerBlock, self.m_ProcessingHeader.numHeights, self.m_SystemHeader.numChannels) )
175 except:
176 except:
176 print "Data file %s is invalid" % self.filename
177 print "Data file %s is invalid" % self.filename
177 return 0
178 return 0
178
179
179 self.datablock = junk['real'] + junk['imag']*1j
180 self.datablock = junk['real'] + junk['imag']*1j
180
181
181 self.datablockIndex = 0
182 self.datablockIndex = 0
182 self.flagIsNewFile = 0
183 self.flagIsNewFile = 0
183 self.idProfile = 0
184 self.idProfile = 0
184 self.flagIsNewBlock = 1
185 self.flagIsNewBlock = 1
185
186
186 self.nReadBlocks += 1
187 self.nReadBlocks += 1
187 self.nBlocks += 1
188 self.nBlocks += 1
188
189
189 return 1
190 return 1
190
191
191
192
192 def getData(self):
193 def getData(self):
193 """
194 """
194 getData obtiene una unidad de datos del buffer de lectura y la copia a la clase "Voltage"
195 getData obtiene una unidad de datos del buffer de lectura y la copia a la clase "Voltage"
195 con todos los parametros asociados a este (metadata). cuando no hay datos en el buffer de
196 con todos los parametros asociados a este (metadata). cuando no hay datos en el buffer de
196 lectura es necesario hacer una nueva lectura de los bloques de datos usando "readNextBlock"
197 lectura es necesario hacer una nueva lectura de los bloques de datos usando "readNextBlock"
197
198
198 Ademas incrementa el contador del buffer en 1.
199 Ademas incrementa el contador del buffer en 1.
199
200
200 Return:
201 Return:
201 data : retorna un perfil de voltages (alturas * canales) copiados desde el
202 data : retorna un perfil de voltages (alturas * canales) copiados desde el
202 buffer. Si no hay mas archivos a leer retorna None.
203 buffer. Si no hay mas archivos a leer retorna None.
203
204
204 Variables afectadas:
205 Variables afectadas:
205 self.m_DataObj
206 self.m_DataObj
206 self.datablockIndex
207 self.datablockIndex
207 self.idProfile
208 self.idProfile
208
209
209 Affected:
210 Affected:
210 self.m_DataObj
211 self.m_DataObj
211 self.datablockIndex
212 self.datablockIndex
212 self.flagResetProcessing
213 self.flagResetProcessing
213 self.flagIsNewBlock
214 self.flagIsNewBlock
214 self.idProfile
215 self.idProfile
215 """
216 """
216 if self.flagNoMoreFiles: return 0
217 if self.flagNoMoreFiles: return 0
217
218
218 self.flagResetProcessing = 0
219 self.flagResetProcessing = 0
219 self.flagIsNewBlock = 0
220 self.flagIsNewBlock = 0
220
221
221 if self.__hasNotDataInBuffer():
222 if self.__hasNotDataInBuffer():
222
223
223 if not( self.readNextBlock() ):
224 if not( self.readNextBlock() ):
224 self.setNextFile()
225 self.setNextFile()
225 return 0
226 return 0
226
227
227 self.m_DataObj.m_BasicHeader = self.m_BasicHeader.copy()
228 self.m_DataObj.m_BasicHeader = self.m_BasicHeader.copy()
228 self.m_DataObj.m_ProcessingHeader = self.m_ProcessingHeader.copy()
229 self.m_DataObj.m_ProcessingHeader = self.m_ProcessingHeader.copy()
229 self.m_DataObj.m_RadarControllerHeader = self.m_RadarControllerHeader.copy()
230 self.m_DataObj.m_RadarControllerHeader = self.m_RadarControllerHeader.copy()
230 self.m_DataObj.m_SystemHeader = self.m_SystemHeader.copy()
231 self.m_DataObj.m_SystemHeader = self.m_SystemHeader.copy()
231 self.m_DataObj.heights = self.heights
232 self.m_DataObj.heights = self.heights
232 self.m_DataObj.dataType = self.dataType
233 self.m_DataObj.dataType = self.dataType
233
234
234 if self.flagNoMoreFiles == 1:
235 if self.flagNoMoreFiles == 1:
235 print 'Process finished'
236 print 'Process finished'
236 return 0
237 return 0
237
238
238 #data es un numpy array de 3 dmensiones (perfiles, alturas y canales)
239 #data es un numpy array de 3 dmensiones (perfiles, alturas y canales)
239
240
240 if self.datablock == None:
241 if self.datablock == None:
241 self.m_DataObj.flagNoData = True
242 self.m_DataObj.flagNoData = True
242 return 0
243 return 0
243
244
244 time = self.m_BasicHeader.utc + self.datablockIndex * self.ippSeconds
245 time = self.m_BasicHeader.utc + self.datablockIndex * self.ippSeconds
245 self.utc = time
246 self.utc = time
246 #self.m_DataObj.m_BasicHeader.utc = time
247 #self.m_DataObj.m_BasicHeader.utc = time
247
248
248 self.m_DataObj.flagNoData = False
249 self.m_DataObj.flagNoData = False
249 self.m_DataObj.flagResetProcessing = self.flagResetProcessing
250 self.m_DataObj.flagResetProcessing = self.flagResetProcessing
250
251
251 self.m_DataObj.data = self.datablock[self.datablockIndex,:,:]
252 self.m_DataObj.data = self.datablock[self.datablockIndex,:,:]
252 self.m_DataObj.idProfile = self.idProfile
253 self.m_DataObj.idProfile = self.idProfile
253
254
254 self.datablockIndex += 1
255 self.datablockIndex += 1
255 self.idProfile += 1
256 self.idProfile += 1
256
257
257 #call setData - to Data Object
258 #call setData - to Data Object
258
259
259 return 1 #self.m_DataObj.data
260 return 1 #self.m_DataObj.data
260
261
261
262
262 class VoltageWriter( JRODataWriter ):
263 class VoltageWriter( JRODataWriter ):
263 """
264 """
264 Esta clase permite escribir datos de voltajes a archivos procesados (.r). La escritura
265 Esta clase permite escribir datos de voltajes a archivos procesados (.r). La escritura
265 de los datos siempre se realiza por bloques.
266 de los datos siempre se realiza por bloques.
266 """
267 """
267 __configHeaderFile = 'wrSetHeadet.txt'
268 __configHeaderFile = 'wrSetHeadet.txt'
268
269
269 m_DataObj = None
270 m_DataObj = None
270
271
271 ext = ".r"
272 ext = ".r"
272
273
273 optchar = "D"
274 optchar = "D"
274
275
275 datablock = None
276 datablock = None
276
277
277 datablockIndex = 0
278 datablockIndex = 0
278
279
279 shapeBuffer = None
280 shapeBuffer = None
280
281
281
282
282 def __init__(self, m_Voltage=None):
283 def __init__(self, m_Voltage=None):
283 """
284 """
284 Inicializador de la clase VoltageWriter para la escritura de datos de espectros.
285 Inicializador de la clase VoltageWriter para la escritura de datos de espectros.
285
286
286 Affected:
287 Affected:
287 self.m_DataObj
288 self.m_DataObj
288
289
289 Return: None
290 Return: None
290 """
291 """
291 if m_Voltage == None:
292 if m_Voltage == None:
292 m_Voltage = Voltage()
293 m_Voltage = Voltage()
293
294
294 if not( isinstance(m_Voltage, Voltage) ):
295 if not( isinstance(m_Voltage, Voltage) ):
295 raise ValueError, "in VoltageReader, m_Spectra must be an Spectra class object"
296 raise ValueError, "in VoltageReader, m_Spectra must be an Spectra class object"
296
297
297 self.m_DataObj = m_Voltage
298 self.m_DataObj = m_Voltage
298
299
299
300
300 def hasAllDataInBuffer(self):
301 def hasAllDataInBuffer(self):
301 if self.datablockIndex >= self.m_ProcessingHeader.profilesPerBlock:
302 if self.datablockIndex >= self.m_ProcessingHeader.profilesPerBlock:
302 return 1
303 return 1
303 return 0
304 return 0
304
305
305
306
306 def setBlockDimension(self):
307 def setBlockDimension(self):
307 """
308 """
308 Obtiene las formas dimensionales del los subbloques de datos que componen un bloque
309 Obtiene las formas dimensionales del los subbloques de datos que componen un bloque
309
310
310 Affected:
311 Affected:
311 self.shape_spc_Buffer
312 self.shape_spc_Buffer
312 self.shape_cspc_Buffer
313 self.shape_cspc_Buffer
313 self.shape_dc_Buffer
314 self.shape_dc_Buffer
314
315
315 Return: None
316 Return: None
316 """
317 """
317 self.shapeBuffer = (self.m_ProcessingHeader.profilesPerBlock,
318 self.shapeBuffer = (self.m_ProcessingHeader.profilesPerBlock,
318 self.m_ProcessingHeader.numHeights,
319 self.m_ProcessingHeader.numHeights,
319 self.m_SystemHeader.numChannels )
320 self.m_SystemHeader.numChannels )
320
321
321 self.datablock = numpy.zeros(self.shapeBuffer, numpy.dtype('complex'))
322 self.datablock = numpy.zeros(self.shapeBuffer, numpy.dtype('complex'))
322
323
323
324
324 def writeBlock(self):
325 def writeBlock(self):
325 """
326 """
326 Escribe el buffer en el file designado
327 Escribe el buffer en el file designado
327
328
328 Affected:
329 Affected:
329 self.datablockIndex
330 self.datablockIndex
330 self.flagIsNewFile
331 self.flagIsNewFile
331 self.flagIsNewBlock
332 self.flagIsNewBlock
332 self.nWriteBlocks
333 self.nWriteBlocks
333 self.blocksCounter
334 self.blocksCounter
334
335
335 Return: None
336 Return: None
336 """
337 """
337 data = numpy.zeros( self.shapeBuffer, self.dataType )
338 data = numpy.zeros( self.shapeBuffer, self.dataType )
338
339
339 data['real'] = self.datablock.real
340 data['real'] = self.datablock.real
340 data['imag'] = self.datablock.imag
341 data['imag'] = self.datablock.imag
341
342
342 data = data.reshape( (-1) )
343 data = data.reshape( (-1) )
343
344
344 data.tofile( self.fp )
345 data.tofile( self.fp )
345
346
346 self.datablock.fill(0)
347 self.datablock.fill(0)
347 self.datablockIndex = 0
348 self.datablockIndex = 0
348 self.flagIsNewFile = 0
349 self.flagIsNewFile = 0
349 self.flagIsNewBlock = 1
350 self.flagIsNewBlock = 1
350 self.nWriteBlocks += 1
351 self.nWriteBlocks += 1
351 self.blocksCounter += 1
352 self.blocksCounter += 1
352
353
353
354
354 def putData(self):
355 def putData(self):
355 """
356 """
356 Setea un bloque de datos y luego los escribe en un file
357 Setea un bloque de datos y luego los escribe en un file
357
358
358 Affected:
359 Affected:
359 self.flagIsNewBlock
360 self.flagIsNewBlock
360 self.datablockIndex
361 self.datablockIndex
361
362
362 Return:
363 Return:
363 0 : Si no hay data o no hay mas files que puedan escribirse
364 0 : Si no hay data o no hay mas files que puedan escribirse
364 1 : Si se escribio la data de un bloque en un file
365 1 : Si se escribio la data de un bloque en un file
365 """
366 """
366 self.flagIsNewBlock = 0
367 self.flagIsNewBlock = 0
367
368
368 if self.m_DataObj.flagNoData:
369 if self.m_DataObj.flagNoData:
369 return 0
370 return 0
370
371
371 if self.m_DataObj.flagResetProcessing:
372 if self.m_DataObj.flagResetProcessing:
372
373
373 self.datablock.fill(0)
374 self.datablock.fill(0)
374 self.datablockIndex = 0
375 self.datablockIndex = 0
375 self.setNextFile()
376 self.setNextFile()
376
377
377 self.datablock[self.datablockIndex,:,:] = self.m_DataObj.data
378 self.datablock[self.datablockIndex,:,:] = self.m_DataObj.data
378
379
379 self.datablockIndex += 1
380 self.datablockIndex += 1
380
381
381 if self.hasAllDataInBuffer():
382 if self.hasAllDataInBuffer():
382 #if self.flagIsNewFile:
383 #if self.flagIsNewFile:
383 self.getHeader()
384 self.getHeader()
384 self.writeNextBlock()
385 self.writeNextBlock()
385
386
386 if self.flagNoMoreFiles:
387 if self.flagNoMoreFiles:
387 #print 'Process finished'
388 #print 'Process finished'
388 return 0
389 return 0
389
390
390 return 1
391 return 1
391 No newline at end of file
392
@@ -1,405 +1,482
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 self.size = 0
38 self.size = 0
39 self.version = 0
39 self.version = 0
40 self.dataBlock = 0
40 self.dataBlock = 0
41 self.utc = 0
41 self.utc = 0
42 self.miliSecond = 0
42 self.miliSecond = 0
43 self.timeZone = 0
43 self.timeZone = 0
44 self.dstFlag = 0
44 self.dstFlag = 0
45 self.errorCount = 0
45 self.errorCount = 0
46 self.struct = numpy.dtype([
46 self.struct = numpy.dtype([
47 ('nSize','<u4'),
47 ('nSize','<u4'),
48 ('nVersion','<u2'),
48 ('nVersion','<u2'),
49 ('nDataBlockId','<u4'),
49 ('nDataBlockId','<u4'),
50 ('nUtime','<u4'),
50 ('nUtime','<u4'),
51 ('nMilsec','<u2'),
51 ('nMilsec','<u2'),
52 ('nTimezone','<i2'),
52 ('nTimezone','<i2'),
53 ('nDstflag','<i2'),
53 ('nDstflag','<i2'),
54 ('nErrorCount','<u4')
54 ('nErrorCount','<u4')
55 ])
55 ])
56 pass
56
57
57
58 def read(self, fp):
58 def read(self, fp):
59 try:
59 try:
60 header = numpy.fromfile(fp, self.struct,1)
60 header = numpy.fromfile(fp, self.struct,1)
61 self.size = header['nSize'][0]
61 self.size = header['nSize'][0]
62 self.version = header['nVersion'][0]
62 self.version = header['nVersion'][0]
63 self.dataBlock = header['nDataBlockId'][0]
63 self.dataBlock = header['nDataBlockId'][0]
64 self.utc = header['nUtime'][0]
64 self.utc = header['nUtime'][0]
65 self.miliSecond = header['nMilsec'][0]
65 self.miliSecond = header['nMilsec'][0]
66 self.timeZone = header['nTimezone'][0]
66 self.timeZone = header['nTimezone'][0]
67 self.dstFlag = header['nDstflag'][0]
67 self.dstFlag = header['nDstflag'][0]
68 self.errorCount = header['nErrorCount'][0]
68 self.errorCount = header['nErrorCount'][0]
69 except:
69 except:
70 return 0
70 return 0
71
71
72 return 1
72 return 1
73
73
74 def write(self, fp):
74 def write(self, fp):
75 headerTuple = (self.size,self.version,self.dataBlock,self.utc,self.miliSecond,self.timeZone,self.dstFlag,self.errorCount)
75 headerTuple = (self.size,self.version,self.dataBlock,self.utc,self.miliSecond,self.timeZone,self.dstFlag,self.errorCount)
76 header = numpy.array(headerTuple,self.struct)
76 header = numpy.array(headerTuple,self.struct)
77 header.tofile(fp)
77 header.tofile(fp)
78
78
79 return 1
79 return 1
80
80
81 class SystemHeader(Header):
81 class SystemHeader(Header):
82
82
83 size = None
83 size = None
84 numSamples = None
84 numSamples = None
85 numProfiles = None
85 numProfiles = None
86 numChannels = None
86 numChannels = None
87 adcResolution = None
87 adcResolution = None
88 pciDioBusWidth = None
88 pciDioBusWidth = None
89 struct = None
89 struct = None
90
90
91 def __init__(self):
91 def __init__(self):
92 self.size = 0
92 self.size = 0
93 self.numSamples = 0
93 self.numSamples = 0
94 self.numProfiles = 0
94 self.numProfiles = 0
95 self.numChannels = 0
95 self.numChannels = 0
96 self.adcResolution = 0
96 self.adcResolution = 0
97 self.pciDioBusWidth = 0
97 self.pciDioBusWidth = 0
98 self.struct = numpy.dtype([
98 self.struct = numpy.dtype([
99 ('nSize','<u4'),
99 ('nSize','<u4'),
100 ('nNumSamples','<u4'),
100 ('nNumSamples','<u4'),
101 ('nNumProfiles','<u4'),
101 ('nNumProfiles','<u4'),
102 ('nNumChannels','<u4'),
102 ('nNumChannels','<u4'),
103 ('nADCResolution','<u4'),
103 ('nADCResolution','<u4'),
104 ('nPCDIOBusWidth','<u4'),
104 ('nPCDIOBusWidth','<u4'),
105 ])
105 ])
106
106
107
107
108 def read(self, fp):
108 def read(self, fp):
109 try:
109 try:
110 header = numpy.fromfile(fp,self.struct,1)
110 header = numpy.fromfile(fp,self.struct,1)
111 self.size = header['nSize'][0]
111 self.size = header['nSize'][0]
112 self.numSamples = header['nNumSamples'][0]
112 self.numSamples = header['nNumSamples'][0]
113 self.numProfiles = header['nNumProfiles'][0]
113 self.numProfiles = header['nNumProfiles'][0]
114 self.numChannels = header['nNumChannels'][0]
114 self.numChannels = header['nNumChannels'][0]
115 self.adcResolution = header['nADCResolution'][0]
115 self.adcResolution = header['nADCResolution'][0]
116 self.pciDioBusWidth = header['nPCDIOBusWidth'][0]
116 self.pciDioBusWidth = header['nPCDIOBusWidth'][0]
117 except:
117 except:
118 return 0
118 return 0
119
119
120 return 1
120 return 1
121
121
122 def write(self, fp):
122 def write(self, fp):
123 headerTuple = (self.size,self.numSamples,self.numProfiles,self.numChannels,self.adcResolution,self.pciDioBusWidth)
123 headerTuple = (self.size,self.numSamples,self.numProfiles,self.numChannels,self.adcResolution,self.pciDioBusWidth)
124 header = numpy.array(headerTuple,self.struct)
124 header = numpy.array(headerTuple,self.struct)
125 header.tofile(fp)
125 header.tofile(fp)
126
126
127 return 1
127 return 1
128
128
129 class RadarControllerHeader(Header):
129 class RadarControllerHeader(Header):
130
130
131 size = None
131 size = None
132 expType = None
132 expType = None
133 nTx = None
133 nTx = None
134 ipp = None
134 ipp = None
135 txA = None
135 txA = None
136 txB = None
136 txB = None
137 numWindows = None
137 numWindows = None
138 numTaus = None
138 numTaus = None
139 codeType = None
139 codeType = None
140 line6Function = None
140 line6Function = None
141 line5Function = None
141 line5Function = None
142 fClock = None
142 fClock = None
143 prePulseBefore = None
143 prePulseBefore = None
144 prePulserAfter = None
144 prePulserAfter = None
145 rangeIpp = None
145 rangeIpp = None
146 rangeTxA = None
146 rangeTxA = None
147 rangeTxB = None
147 rangeTxB = None
148 struct = None
148 struct = None
149
149
150 def __init__(self):
150 def __init__(self):
151 self.size = 0
151 self.size = 0
152 self.expType = 0
152 self.expType = 0
153 self.nTx = 0
153 self.nTx = 0
154 self.ipp = 0
154 self.ipp = 0
155 self.txA = 0
155 self.txA = 0
156 self.txB = 0
156 self.txB = 0
157 self.numWindows = 0
157 self.numWindows = 0
158 self.numTaus = 0
158 self.numTaus = 0
159 self.codeType = 0
159 self.codeType = 0
160 self.line6Function = 0
160 self.line6Function = 0
161 self.line5Function = 0
161 self.line5Function = 0
162 self.fClock = 0
162 self.fClock = 0
163 self.prePulseBefore = 0
163 self.prePulseBefore = 0
164 self.prePulserAfter = 0
164 self.prePulserAfter = 0
165 self.rangeIpp = 0
165 self.rangeIpp = 0
166 self.rangeTxA = 0
166 self.rangeTxA = 0
167 self.rangeTxB = 0
167 self.rangeTxB = 0
168 self.struct = numpy.dtype([
168 self.struct = numpy.dtype([
169 ('nSize','<u4'),
169 ('nSize','<u4'),
170 ('nExpType','<u4'),
170 ('nExpType','<u4'),
171 ('nNTx','<u4'),
171 ('nNTx','<u4'),
172 ('fIpp','<f4'),
172 ('fIpp','<f4'),
173 ('fTxA','<f4'),
173 ('fTxA','<f4'),
174 ('fTxB','<f4'),
174 ('fTxB','<f4'),
175 ('nNumWindows','<u4'),
175 ('nNumWindows','<u4'),
176 ('nNumTaus','<u4'),
176 ('nNumTaus','<u4'),
177 ('nCodeType','<u4'),
177 ('nCodeType','<u4'),
178 ('nLine6Function','<u4'),
178 ('nLine6Function','<u4'),
179 ('nLine5Function','<u4'),
179 ('nLine5Function','<u4'),
180 ('fClock','<f4'),
180 ('fClock','<f4'),
181 ('nPrePulseBefore','<u4'),
181 ('nPrePulseBefore','<u4'),
182 ('nPrePulseAfter','<u4'),
182 ('nPrePulseAfter','<u4'),
183 ('sRangeIPP','<a20'),
183 ('sRangeIPP','<a20'),
184 ('sRangeTxA','<a20'),
184 ('sRangeTxA','<a20'),
185 ('sRangeTxB','<a20'),
185 ('sRangeTxB','<a20'),
186 ])
186 ])
187
188 self.samplingWindowStruct = numpy.dtype([('h0','<f4'),('dh','<f4'),('nsa','<u4')])
189
190 self.samplingWindow = None
191 self.numHeights = None
192 self.firstHeight = None
193 self.deltaHeight = None
194 self.samplesWin = None
195
196 self.numCode = None
197 self.numBaud = None
198 self.code = None
199 self.flip1 = None
200 self.flip2 = None
201
187 self.dynamic = numpy.array([],numpy.dtype('byte'))
202 self.dynamic = numpy.array([],numpy.dtype('byte'))
188
203
189
204
190 def read(self, fp):
205 def read(self, fp):
191 try:
206 try:
207 startFp = fp.tell()
192 header = numpy.fromfile(fp,self.struct,1)
208 header = numpy.fromfile(fp,self.struct,1)
193 self.size = header['nSize'][0]
209 self.size = header['nSize'][0]
194 self.expType = header['nExpType'][0]
210 self.expType = header['nExpType'][0]
195 self.nTx = header['nNTx'][0]
211 self.nTx = header['nNTx'][0]
196 self.ipp = header['fIpp'][0]
212 self.ipp = header['fIpp'][0]
197 self.txA = header['fTxA'][0]
213 self.txA = header['fTxA'][0]
198 self.txB = header['fTxB'][0]
214 self.txB = header['fTxB'][0]
199 self.numWindows = header['nNumWindows'][0]
215 self.numWindows = header['nNumWindows'][0]
200 self.numTaus = header['nNumTaus'][0]
216 self.numTaus = header['nNumTaus'][0]
201 self.codeType = header['nCodeType'][0]
217 self.codeType = header['nCodeType'][0]
202 self.line6Function = header['nLine6Function'][0]
218 self.line6Function = header['nLine6Function'][0]
203 self.line5Function = header['nLine5Function'][0]
219 self.line5Function = header['nLine5Function'][0]
204 self.fClock = header['fClock'][0]
220 self.fClock = header['fClock'][0]
205 self.prePulseBefore = header['nPrePulseBefore'][0]
221 self.prePulseBefore = header['nPrePulseBefore'][0]
206 self.prePulserAfter = header['nPrePulseAfter'][0]
222 self.prePulserAfter = header['nPrePulseAfter'][0]
207 self.rangeIpp = header['sRangeIPP'][0]
223 self.rangeIpp = header['sRangeIPP'][0]
208 self.rangeTxA = header['sRangeTxA'][0]
224 self.rangeTxA = header['sRangeTxA'][0]
209 self.rangeTxB = header['sRangeTxB'][0]
225 self.rangeTxB = header['sRangeTxB'][0]
210 # jump Dynamic Radar Controller Header
226 # jump Dynamic Radar Controller Header
211 jumpHeader = self.size - 116
227 jumpFp = self.size - 116
212 self.dynamic = numpy.fromfile(fp,numpy.dtype('byte'),jumpHeader)
228 self.dynamic = numpy.fromfile(fp,numpy.dtype('byte'),jumpFp)
229 #pointer backward to dynamic header and read
230 backFp = fp.tell() - jumpFp
231 fp.seek(backFp)
232
233 self.samplingWindow = numpy.fromfile(fp,self.samplingWindowStruct,self.numWindows)
234 self.numHeights = numpy.sum(self.samplingWindow['nsa'])
235 self.firstHeight = self.samplingWindow['h0']
236 self.deltaHeight = self.samplingWindow['dh']
237 self.samplesWin = self.samplingWindow['nsa']
238
239 self.Taus = numpy.fromfile(fp,'<f4',self.numTaus)
240
241 if self.codeType != 0:
242 self.numCode = numpy.fromfile(fp,'<u4',1)
243 self.numBaud = numpy.fromfile(fp,'<u4',1)
244 self.code = numpy.empty([self.numCode,self.numBaud],dtype='u1')
245 tempList = []
246 for ic in range(self.numCode):
247 temp = numpy.fromfile(fp,'u1',4*numpy.ceil(self.numBaud/32.))
248 tempList.append(temp)
249 self.code[ic] = numpy.unpackbits(temp[::-1])[-1*self.numBaud:]
250 self.code = 2.0*self.code - 1.0
251
252 if self.line5Function == RCfunction.FLIP:
253 self.flip1 = numpy.fromfile(fp,'<u4',1)
254
255 if self.line6Function == RCfunction.FLIP:
256 self.flip2 = numpy.fromfile(fp,'<u4',1)
257
258 endFp = self.size + startFp
259 jumpFp = endFp - fp.tell()
260 if jumpFp > 0:
261 fp.seek(jumpFp)
262
213 except:
263 except:
214 return 0
264 return 0
215
265
216 return 1
266 return 1
217
267
218 def write(self, fp):
268 def write(self, fp):
219 headerTuple = (self.size,
269 headerTuple = (self.size,
220 self.expType,
270 self.expType,
221 self.nTx,
271 self.nTx,
222 self.ipp,
272 self.ipp,
223 self.txA,
273 self.txA,
224 self.txB,
274 self.txB,
225 self.numWindows,
275 self.numWindows,
226 self.numTaus,
276 self.numTaus,
227 self.codeType,
277 self.codeType,
228 self.line6Function,
278 self.line6Function,
229 self.line5Function,
279 self.line5Function,
230 self.fClock,
280 self.fClock,
231 self.prePulseBefore,
281 self.prePulseBefore,
232 self.prePulserAfter,
282 self.prePulserAfter,
233 self.rangeIpp,
283 self.rangeIpp,
234 self.rangeTxA,
284 self.rangeTxA,
235 self.rangeTxB)
285 self.rangeTxB)
236
286
237 header = numpy.array(headerTuple,self.struct)
287 header = numpy.array(headerTuple,self.struct)
238 header.tofile(fp)
288 header.tofile(fp)
239
289
240 dynamic = self.dynamic
290 dynamic = self.dynamic
241 dynamic.tofile(fp)
291 dynamic.tofile(fp)
242
292
243 return 1
293 return 1
244
294
245
295
246
296
247 class ProcessingHeader(Header):
297 class ProcessingHeader(Header):
248
298
249 size = None
299 size = None
250 dataType = None
300 dataType = None
251 blockSize = None
301 blockSize = None
252 profilesPerBlock = None
302 profilesPerBlock = None
253 dataBlocksPerFile = None
303 dataBlocksPerFile = None
254 numWindows = None
304 numWindows = None
255 processFlags = None
305 processFlags = None
256 coherentInt = None
306 coherentInt = None
257 incoherentInt = None
307 incoherentInt = None
258 totalSpectra = None
308 totalSpectra = None
259 struct = None
309 struct = None
260
310
261 def __init__(self):
311 def __init__(self):
262 self.size = 0
312 self.size = 0
263 self.dataType = 0
313 self.dataType = 0
264 self.blockSize = 0
314 self.blockSize = 0
265 self.profilesPerBlock = 0
315 self.profilesPerBlock = 0
266 self.dataBlocksPerFile = 0
316 self.dataBlocksPerFile = 0
267 self.numWindows = 0
317 self.numWindows = 0
268 self.processFlags = 0
318 self.processFlags = 0
269 self.coherentInt = 0
319 self.coherentInt = 0
270 self.incoherentInt = 0
320 self.incoherentInt = 0
271 self.totalSpectra = 0
321 self.totalSpectra = 0
272 self.struct = numpy.dtype([
322 self.struct = numpy.dtype([
273 ('nSize','<u4'),
323 ('nSize','<u4'),
274 ('nDataType','<u4'),
324 ('nDataType','<u4'),
275 ('nSizeOfDataBlock','<u4'),
325 ('nSizeOfDataBlock','<u4'),
276 ('nProfilesperBlock','<u4'),
326 ('nProfilesperBlock','<u4'),
277 ('nDataBlocksperFile','<u4'),
327 ('nDataBlocksperFile','<u4'),
278 ('nNumWindows','<u4'),
328 ('nNumWindows','<u4'),
279 ('nProcessFlags','<u4'),
329 ('nProcessFlags','<u4'),
280 ('nCoherentIntegrations','<u4'),
330 ('nCoherentIntegrations','<u4'),
281 ('nIncoherentIntegrations','<u4'),
331 ('nIncoherentIntegrations','<u4'),
282 ('nTotalSpectra','<u4')
332 ('nTotalSpectra','<u4')
283 ])
333 ])
284 self.samplingWindow = 0
334 self.samplingWindow = 0
285 self.structSamplingWindow = numpy.dtype([('h0','<f4'),('dh','<f4'),('nsa','<u4')])
335 self.structSamplingWindow = numpy.dtype([('h0','<f4'),('dh','<f4'),('nsa','<u4')])
286 self.numHeights = 0
336 self.numHeights = 0
287 self.firstHeight = 0
337 self.firstHeight = 0
288 self.deltaHeight = 0
338 self.deltaHeight = 0
289 self.samplesWin = 0
339 self.samplesWin = 0
290 self.spectraComb = 0
340 self.spectraComb = 0
291 self.numCode = 0
341 self.numCode = 0
292 self.codes = 0
342 self.code = 0
293 self.numBaud = 0
343 self.numBaud = 0
294 self.shif_fft = False
344 self.shif_fft = False
295
345
296 def read(self, fp):
346 def read(self, fp):
297 try:
347 try:
298 header = numpy.fromfile(fp,self.struct,1)
348 header = numpy.fromfile(fp,self.struct,1)
299 self.size = header['nSize'][0]
349 self.size = header['nSize'][0]
300 self.dataType = header['nDataType'][0]
350 self.dataType = header['nDataType'][0]
301 self.blockSize = header['nSizeOfDataBlock'][0]
351 self.blockSize = header['nSizeOfDataBlock'][0]
302 self.profilesPerBlock = header['nProfilesperBlock'][0]
352 self.profilesPerBlock = header['nProfilesperBlock'][0]
303 self.dataBlocksPerFile = header['nDataBlocksperFile'][0]
353 self.dataBlocksPerFile = header['nDataBlocksperFile'][0]
304 self.numWindows = header['nNumWindows'][0]
354 self.numWindows = header['nNumWindows'][0]
305 self.processFlags = header['nProcessFlags']
355 self.processFlags = header['nProcessFlags']
306 self.coherentInt = header['nCoherentIntegrations'][0]
356 self.coherentInt = header['nCoherentIntegrations'][0]
307 self.incoherentInt = header['nIncoherentIntegrations'][0]
357 self.incoherentInt = header['nIncoherentIntegrations'][0]
308 self.totalSpectra = header['nTotalSpectra'][0]
358 self.totalSpectra = header['nTotalSpectra'][0]
309 self.samplingWindow = numpy.fromfile(fp,self.structSamplingWindow,self.numWindows)
359 self.samplingWindow = numpy.fromfile(fp,self.structSamplingWindow,self.numWindows)
310 self.numHeights = numpy.sum(self.samplingWindow['nsa'])
360 self.numHeights = numpy.sum(self.samplingWindow['nsa'])
311 self.firstHeight = self.samplingWindow['h0']
361 self.firstHeight = self.samplingWindow['h0']
312 self.deltaHeight = self.samplingWindow['dh']
362 self.deltaHeight = self.samplingWindow['dh']
313 self.samplesWin = self.samplingWindow['nsa']
363 self.samplesWin = self.samplingWindow['nsa']
314 self.spectraComb = numpy.fromfile(fp,'u1',2*self.totalSpectra)
364 self.spectraComb = numpy.fromfile(fp,'u1',2*self.totalSpectra)
315
365
316 if self.processFlags & PROCFLAG.DEFINE_PROCESS_CODE == PROCFLAG.DEFINE_PROCESS_CODE:
366 if self.processFlags & PROCFLAG.DEFINE_PROCESS_CODE == PROCFLAG.DEFINE_PROCESS_CODE:
317 self.numCode = numpy.fromfile(fp,'<u4',1)
367 self.numCode = numpy.fromfile(fp,'<u4',1)
318 self.numBaud = numpy.fromfile(fp,'<u4',1)
368 self.numBaud = numpy.fromfile(fp,'<u4',1)
319 self.codes = numpy.fromfile(fp,'<f4',self.numCode*self.numBaud).reshape(self.numBaud,self.numCode)
369 self.code = numpy.fromfile(fp,'<f4',self.numCode*self.numBaud).reshape(self.numBaud,self.numCode)
320
370
321 if self.processFlags & PROCFLAG.SHIFT_FFT_DATA == PROCFLAG.SHIFT_FFT_DATA:
371 if self.processFlags & PROCFLAG.SHIFT_FFT_DATA == PROCFLAG.SHIFT_FFT_DATA:
322 self.shif_fft = True
372 self.shif_fft = True
323 else:
373 else:
324 self.shif_fft = False
374 self.shif_fft = False
325 except:
375 except:
326 return 0
376 return 0
327
377
328 return 1
378 return 1
329
379
330 def write(self, fp):
380 def write(self, fp):
331 headerTuple = (self.size,
381 headerTuple = (self.size,
332 self.dataType,
382 self.dataType,
333 self.blockSize,
383 self.blockSize,
334 self.profilesPerBlock,
384 self.profilesPerBlock,
335 self.dataBlocksPerFile,
385 self.dataBlocksPerFile,
336 self.numWindows,
386 self.numWindows,
337 self.processFlags,
387 self.processFlags,
338 self.coherentInt,
388 self.coherentInt,
339 self.incoherentInt,
389 self.incoherentInt,
340 self.totalSpectra)
390 self.totalSpectra)
341
391
342 header = numpy.array(headerTuple,self.struct)
392 header = numpy.array(headerTuple,self.struct)
343 header.tofile(fp)
393 header.tofile(fp)
344
394
345 if self.numWindows != 0:
395 if self.numWindows != 0:
346 sampleWindowTuple = (self.firstHeight,self.deltaHeight,self.samplesWin)
396 sampleWindowTuple = (self.firstHeight,self.deltaHeight,self.samplesWin)
347 samplingWindow = numpy.array(sampleWindowTuple,self.structSamplingWindow)
397 samplingWindow = numpy.array(sampleWindowTuple,self.structSamplingWindow)
348 samplingWindow.tofile(fp)
398 samplingWindow.tofile(fp)
349
399
350
400
351 if self.totalSpectra != 0:
401 if self.totalSpectra != 0:
352 spectraComb = numpy.array([],numpy.dtype('u1'))
402 spectraComb = numpy.array([],numpy.dtype('u1'))
353 spectraComb = self.spectraComb
403 spectraComb = self.spectraComb
354 spectraComb.tofile(fp)
404 spectraComb.tofile(fp)
355
405
356
406
357 if self.processFlags & PROCFLAG.DEFINE_PROCESS_CODE == PROCFLAG.DEFINE_PROCESS_CODE:
407 if self.processFlags & PROCFLAG.DEFINE_PROCESS_CODE == PROCFLAG.DEFINE_PROCESS_CODE:
358 numCode = self.numCode
408 numCode = self.numCode
359 numCode.tofile(fp)
409 numCode.tofile(fp)
360
410
361 numBaud = self.numBaud
411 numBaud = self.numBaud
362 numBaud.tofile(fp)
412 numBaud.tofile(fp)
363
413
364 codes = self.codes.reshape(numCode*numBaud)
414 code = self.code.reshape(numCode*numBaud)
365 codes.tofile(fp)
415 code.tofile(fp)
366
416
367 return 1
417 return 1
368
418
419 class RCfunction:
420 NONE=0
421 FLIP=1
422 CODE=2
423 SAMPLING=3
424 LIN6DIV256=4
425 SYNCHRO=5
426
427 class nCodeType:
428 NONE=0
429 USERDEFINE=1
430 BARKER2=2
431 BARKER3=3
432 BARKER4=4
433 BARKER5=5
434 BARKER7=6
435 BARKER11=7
436 BARKER13=8
437 AC128=9
438 COMPLEMENTARYCODE2=10
439 COMPLEMENTARYCODE4=11
440 COMPLEMENTARYCODE8=12
441 COMPLEMENTARYCODE16=13
442 COMPLEMENTARYCODE32=14
443 COMPLEMENTARYCODE64=15
444 COMPLEMENTARYCODE128=16
445 CODE_BINARY28=17
369
446
370 class PROCFLAG:
447 class PROCFLAG:
371 COHERENT_INTEGRATION = numpy.uint32(0x00000001)
448 COHERENT_INTEGRATION = numpy.uint32(0x00000001)
372 DECODE_DATA = numpy.uint32(0x00000002)
449 DECODE_DATA = numpy.uint32(0x00000002)
373 SPECTRA_CALC = numpy.uint32(0x00000004)
450 SPECTRA_CALC = numpy.uint32(0x00000004)
374 INCOHERENT_INTEGRATION = numpy.uint32(0x00000008)
451 INCOHERENT_INTEGRATION = numpy.uint32(0x00000008)
375 POST_COHERENT_INTEGRATION = numpy.uint32(0x00000010)
452 POST_COHERENT_INTEGRATION = numpy.uint32(0x00000010)
376 SHIFT_FFT_DATA = numpy.uint32(0x00000020)
453 SHIFT_FFT_DATA = numpy.uint32(0x00000020)
377
454
378 DATATYPE_CHAR = numpy.uint32(0x00000040)
455 DATATYPE_CHAR = numpy.uint32(0x00000040)
379 DATATYPE_SHORT = numpy.uint32(0x00000080)
456 DATATYPE_SHORT = numpy.uint32(0x00000080)
380 DATATYPE_LONG = numpy.uint32(0x00000100)
457 DATATYPE_LONG = numpy.uint32(0x00000100)
381 DATATYPE_INT64 = numpy.uint32(0x00000200)
458 DATATYPE_INT64 = numpy.uint32(0x00000200)
382 DATATYPE_FLOAT = numpy.uint32(0x00000400)
459 DATATYPE_FLOAT = numpy.uint32(0x00000400)
383 DATATYPE_DOUBLE = numpy.uint32(0x00000800)
460 DATATYPE_DOUBLE = numpy.uint32(0x00000800)
384
461
385 DATAARRANGE_CONTIGUOUS_CH = numpy.uint32(0x00001000)
462 DATAARRANGE_CONTIGUOUS_CH = numpy.uint32(0x00001000)
386 DATAARRANGE_CONTIGUOUS_H = numpy.uint32(0x00002000)
463 DATAARRANGE_CONTIGUOUS_H = numpy.uint32(0x00002000)
387 DATAARRANGE_CONTIGUOUS_P = numpy.uint32(0x00004000)
464 DATAARRANGE_CONTIGUOUS_P = numpy.uint32(0x00004000)
388
465
389 SAVE_CHANNELS_DC = numpy.uint32(0x00008000)
466 SAVE_CHANNELS_DC = numpy.uint32(0x00008000)
390 DEFLIP_DATA = numpy.uint32(0x00010000)
467 DEFLIP_DATA = numpy.uint32(0x00010000)
391 DEFINE_PROCESS_CODE = numpy.uint32(0x00020000)
468 DEFINE_PROCESS_CODE = numpy.uint32(0x00020000)
392
469
393 ACQ_SYS_NATALIA = numpy.uint32(0x00040000)
470 ACQ_SYS_NATALIA = numpy.uint32(0x00040000)
394 ACQ_SYS_ECHOTEK = numpy.uint32(0x00080000)
471 ACQ_SYS_ECHOTEK = numpy.uint32(0x00080000)
395 ACQ_SYS_ADRXD = numpy.uint32(0x000C0000)
472 ACQ_SYS_ADRXD = numpy.uint32(0x000C0000)
396 ACQ_SYS_JULIA = numpy.uint32(0x00100000)
473 ACQ_SYS_JULIA = numpy.uint32(0x00100000)
397 ACQ_SYS_XXXXXX = numpy.uint32(0x00140000)
474 ACQ_SYS_XXXXXX = numpy.uint32(0x00140000)
398
475
399 EXP_NAME_ESP = numpy.uint32(0x00200000)
476 EXP_NAME_ESP = numpy.uint32(0x00200000)
400 CHANNEL_NAMES_ESP = numpy.uint32(0x00400000)
477 CHANNEL_NAMES_ESP = numpy.uint32(0x00400000)
401
478
402 OPERATION_MASK = numpy.uint32(0x0000003F)
479 OPERATION_MASK = numpy.uint32(0x0000003F)
403 DATATYPE_MASK = numpy.uint32(0x00000FC0)
480 DATATYPE_MASK = numpy.uint32(0x00000FC0)
404 DATAARRANGE_MASK = numpy.uint32(0x00007000)
481 DATAARRANGE_MASK = numpy.uint32(0x00007000)
405 ACQ_SYS_MASK = numpy.uint32(0x001C0000) No newline at end of file
482 ACQ_SYS_MASK = numpy.uint32(0x001C0000)
@@ -1,56 +1,58
1 '''
1 '''
2 Created on Feb 7, 2012
2 Created on Feb 7, 2012
3
3
4 @author $Author$
4 @author $Author$
5 @version $Id$
5 @version $Id$
6 '''
6 '''
7
7
8 from JROData import JROData, Noise
8 from JROData import JROData, Noise
9 from JROHeader import RadarControllerHeader, ProcessingHeader, SystemHeader, BasicHeader
9 from JROHeader import RadarControllerHeader, ProcessingHeader, SystemHeader, BasicHeader
10
10
11 class Spectra(JROData):
11 class Spectra(JROData):
12 '''
12 '''
13 classdocs
13 classdocs
14 '''
14 '''
15
15
16 type = "Spectra"
16 type = "Spectra"
17 data_spc = None
17 data_spc = None
18 data_cspc = None
18 data_cspc = None
19 data_dc = None
19 data_dc = None
20
20
21
21
22 def __init__(self):
22 def __init__(self):
23 '''
23 '''
24 Constructor
24 Constructor
25 '''
25 '''
26
26
27 self.m_RadarControllerHeader = RadarControllerHeader()
27 self.m_RadarControllerHeader = RadarControllerHeader()
28
28
29 self.m_ProcessingHeader = ProcessingHeader()
29 self.m_ProcessingHeader = ProcessingHeader()
30
30
31 self.m_SystemHeader = SystemHeader()
31 self.m_SystemHeader = SystemHeader()
32
32
33 self.m_BasicHeader = BasicHeader()
33 self.m_BasicHeader = BasicHeader()
34
34
35 m_NoiseObj = Noise()
35 m_NoiseObj = Noise()
36
36
37 #data es un numpy array de 3 dmensiones (perfiles, alturas y canales)
37 #data es un numpy array de 3 dmensiones (perfiles, alturas y canales)
38 self.data_spc = None
38 self.data_spc = None
39
39
40 self.data_cspc = None
40 self.data_cspc = None
41
41
42 self.data_dc = None
42 self.data_dc = None
43
43
44 self.heights = None
44 self.heights = None
45
45
46 self.flagNoData = True
46 self.flagNoData = True
47
47
48 self.nProfiles = None
48 self.nProfiles = None
49
49
50 self.nPoints = None
51
50 self.dataType = None
52 self.dataType = None
51
53
52 self.flagResetProcessing = False
54 self.flagResetProcessing = False
53
55
54 self.nPairsUnequalChannels = 0
56 self.nPairsUnequalChannels = 0
55
57
56 self.nPairsEqualChannels = 0 No newline at end of file
58 self.nPairsEqualChannels = 0
@@ -1,18 +1,183
1 '''
1 '''
2 Created on Feb 7, 2012
2 Created on Feb 7, 2012
3
3
4 @author $Author$
4 @author $Author$
5 @version $Id$
5 @version $Id$
6 '''
6 '''
7 import os, sys
8 import numpy
9
10 path = os.path.split(os.getcwd())[0]
11 sys.path.append(path)
12
13 from Model.Spectra import Spectra
14 from IO.SpectraIO import SpectraWriter
15 from Graphics.SpectraPlot import Spectrum
16
7
17
8 class SpectraProcessor:
18 class SpectraProcessor:
9 '''
19 '''
10 classdocs
20 classdocs
11 '''
21 '''
12
22
13
23 def __init__(self, spectraInObj, spectraOutObj=None, npts = None):
14 def __init__(self):
15 '''
24 '''
16 Constructor
25 Constructor
17 '''
26 '''
18 pass No newline at end of file
27 self.spectraInObj = spectraInObj
28
29 if spectraOutObj == None:
30 self.spectraOutObj = Spectra()
31 else:
32 self.spectraOutObj = spectraOutObj
33
34
35 self.integratorIndex = None
36 self.decoderIndex = None
37 self.writerIndex = None
38 self.plotterIndex = None
39
40 if npts != None:
41 self.spectraOutObj.nPoints = npts
42
43 self.npts = self.spectraOutObj.nPoints
44
45 self.integratorList = []
46 self.decoderList = []
47 self.writerList = []
48 self.plotterList = []
49
50 self.buffer = None
51 self.ptsId = 0
52
53 def init(self):
54 self.integratorIndex = 0
55 self.decoderIndex = 0
56 self.writerIndex = 0
57 self.plotterIndex = 0
58
59 if not( isinstance(self.spectraInObj, Spectra) ):
60 self.getFft()
61 else:
62 self.spectraOutObj.copy(self.spectraInObj)
63
64
65 def getFft(self):
66
67 if self.buffer == None:
68 nheis = self.spectraInObj.data.shape[0]
69 nchannel = self.spectraInObj.data.shape[1]
70 npoints = self.spectraOutObj.nPoints
71 self.buffer = numpy.zeros((nchannel,nheis,npoints),dtype='complex')
72
73 data = numpy.transpose(self.spectraInObj.data)
74 self.buffer[:,:,self.ptsId] = data
75 self.ptsId += 1
76 self.spectraOutObj.flagNoData = True
77 if self.ptsId >= self.spectraOutObj.nPoints:
78 data_spc = numpy.fft.fft(self.buffer,axis=2)
79 self.ptsId = 0
80 self.buffer = None
81
82 #calculo de self-spectra
83 self.spectraOutObj.data_spc = numpy.abs(data_spc * numpy.conjugate(data_spc))
84
85
86
87 #calculo de cross-spectra
88 #self.m_Spectra.data_cspc = self.__data_cspc
89
90
91 #escribiendo dc
92 #self.m_Spectra.data_dc = self.__data_dc
93
94
95 self.spectraOutObj.flagNoData = False
96
97
98 def addWriter(self,wrpath):
99 objWriter = SpectraWriter(self.spectraOutObj)
100 objWriter.setup(wrpath)
101 self.writerList.append(objWriter)
102
103
104 def addPlotter(self):
105
106 plotObj = Spectrum(self.spectraOutObj,self.plotterIndex)
107 self.plotterList.append(plotObj)
108
109
110 def addIntegrator(self,N):
111
112 objIncohInt = IncoherentIntegration(N)
113 self.integratorList.append(objIncohInt)
114
115
116 def writeData(self):
117 if self.voltageOutObj.flagNoData:
118 return 0
119
120 if len(self.writerList) <= self.writerIndex:
121 self.addWriter(wrpath)
122
123 self.writerList[self.writerIndex].putData()
124
125 self.writerIndex += 1
126
127 def plotData(self,xmin=None, xmax=None, ymin=None, ymax=None, winTitle=''):
128 if self.spectraOutObj.flagNoData:
129 return 0
130
131 if len(self.plotterList) <= self.plotterIndex:
132 self.addPlotter()
133
134 self.plotterList[self.plotterIndex].plotData(xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax,winTitle=winTitle)
135
136 self.plotterIndex += 1
137
138 def integrator(self, N):
139 if self.spectraOutObj.flagNoData:
140 return 0
141
142 if len(self.integratorList) <= self.integratorIndex:
143 self.addIntegrator(N)
144
145 myCohIntObj = self.integratorList[self.integratorIndex]
146 myCohIntObj.exe(self.spectraOutObj.data_spc)
147
148 if myCohIntObj.flag:
149 self.spectraOutObj.data_spc = myCohIntObj.data
150 self.spectraOutObj.m_ProcessingHeader.incoherentInt *= N
151 self.spectraOutObj.flagNoData = False
152
153 else:
154 self.spectraOutObj.flagNoData = True
155
156 self.integratorIndex += 1
157
158 class IncoherentIntegration:
159 def __init__(self, N):
160 self.profCounter = 1
161 self.data = None
162 self.buffer = None
163 self.flag = False
164 self.nIncohInt = N
165
166 def exe(self,data):
167 print 'intg:', self.profCounter
168
169 if self.buffer == None:
170 self.buffer = data
171 else:
172 self.buffer = self.buffer + data
173
174 if self.profCounter == self.nIncohInt:
175 self.data = self.buffer
176 self.buffer = None
177 self.profCounter = 0
178 self.flag = True
179 else:
180 self.flag = False
181
182 self.profCounter += 1
183
@@ -1,18 +1,247
1 '''
1 '''
2 Created on Feb 7, 2012
2 Created on Feb 7, 2012
3
3
4 @author $Author$
4 @author $Author$
5 @version $Id$
5 @version $Id$
6 '''
6 '''
7
7
8 import os, sys
9 import numpy
10
11 path = os.path.split(os.getcwd())[0]
12 sys.path.append(path)
13
14 from Model.Voltage import Voltage
15 from IO.VoltageIO import VoltageWriter
16 from Graphics.VoltagePlot import Osciloscope
17
8 class VoltageProcessor:
18 class VoltageProcessor:
9 '''
19 '''
10 classdocs
20 classdocs
11 '''
21 '''
12
22
13
23 def __init__(self, voltageInObj, voltageOutObj=None):
14 def __init__(self):
15 '''
24 '''
16 Constructor
25 Constructor
17 '''
26 '''
27
28 self.voltageInObj = voltageInObj
29
30 if voltageOutObj == None:
31 self.voltageOutObj = Voltage()
32 else:
33 self.voltageOutObj = voltageOutObj
34
35 self.integratorIndex = None
36 self.decoderIndex = None
37 self.writerIndex = None
38 self.plotterIndex = None
39
40 self.integratorList = []
41 self.decoderList = []
42 self.writerList = []
43 self.plotterList = []
44
45 def init(self):
46 self.integratorIndex = 0
47 self.decoderIndex = 0
48 self.writerIndex = 0
49 self.plotterIndex = 0
50 self.voltageOutObj.copy(self.voltageInObj)
51
52 def addWriter(self,wrpath):
53 objWriter = VoltageWriter(self.voltageOutObj)
54 objWriter.setup(wrpath)
55 self.writerList.append(objWriter)
56
57 def addPlotter(self):
58
59 plotObj = Osciloscope(self.voltageOutObj,self.plotterIndex)
60 self.plotterList.append(plotObj)
61
62 def addIntegrator(self,N):
63
64 objCohInt = CoherentIntegrator(N)
65 self.integratorList.append(objCohInt)
66
67 def addDecoder(self,code,ncode,nbaud):
68
69 objDecoder = Decoder(code,ncode,nbaud)
70 self.decoderList.append(objDecoder)
71
72 def writeData(self,wrpath):
73 if self.voltageOutObj.flagNoData:
74 return 0
75
76 if len(self.writerList) <= self.writerIndex:
77 self.addWriter(wrpath)
78
79 self.writerList[self.writerIndex].putData()
80
81 # myWrObj = self.writerList[self.writerIndex]
82 # myWrObj.putData()
83
84 self.writerIndex += 1
85
86 def plotData(self,idProfile, type, xmin=None, xmax=None, ymin=None, ymax=None, winTitle=''):
87 if self.voltageOutObj.flagNoData:
88 return 0
89
90 if len(self.plotterList) <= self.plotterIndex:
91 self.addPlotter()
92
93 self.plotterList[self.plotterIndex].plotData(type=type, xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax,winTitle=winTitle)
94
95 self.plotterIndex += 1
96
97 def integrator(self, N):
98 if self.voltageOutObj.flagNoData:
99 return 0
100
101 if len(self.integratorList) <= self.integratorIndex:
102 self.addIntegrator(N)
103
104 myCohIntObj = self.integratorList[self.integratorIndex]
105 myCohIntObj.exe(self.voltageOutObj.data)
106
107 if myCohIntObj.flag:
108 self.voltageOutObj.data = myCohIntObj.data
109 self.voltageOutObj.m_ProcessingHeader.coherentInt *= N
110 self.voltageOutObj.flagNoData = False
111
112 else:
113 self.voltageOutObj.flagNoData = True
114
115 self.integratorIndex += 1
116
117 def decoder(self,code=None,type = 0):
118 if self.voltageOutObj.flagNoData:
119 return 0
120 if code == None:
121 code = self.voltageOutObj.m_RadarControllerHeader.code
122 ncode, nbaud = code.shape
123
124 if len(self.decoderList) <= self.decoderIndex:
125 self.addDecoder(code,ncode,nbaud)
126
127 myDecodObj = self.decoderList[self.decoderIndex]
128 myDecodObj.exe(data=self.voltageOutObj.data,type=type)
129
130 if myDecodObj.flag:
131 self.voltageOutObj.data = myDecodObj.data
132 self.voltageOutObj.flagNoData = False
133 else:
134 self.voltageOutObj.flagNoData = True
135
136 self.decoderIndex += 1
137
138 def removeDC(self):
18 pass
139 pass
140
141 def removeSignalInt(self):
142 pass
143
144 def selChannel(self):
145 pass
146
147 def selRange(self):
148 pass
149
150 def selProfiles(self):
151 pass
152
153
154 class Decoder:
155 def __init__(self,code, ncode, nbaud):
156 self.buffer = None
157 self.profCounter = 1
158 self.nCode = ncode
159 self.nBaud = nbaud
160 self.codeIndex = 0
161 self.code = code #this is a List
162 self.fft_code = None
163 self.flag = False
164 self.setCodeFft = False
165
166 def exe(self, data, ndata=None, type = 0):
167 if ndata == None: ndata = data.shape[0]
168
169 if type == 0:
170 self.convolutionInFreq(data,ndata)
171
172 if type == 1:
173 self.convolutionInTime(data, ndata)
174
175 def convolutionInFreq(self,data,ndata):
176
177 newcode = numpy.zeros(ndata)
178 newcode[0:self.nBaud] = self.code[self.codeIndex]
179
180 self.codeIndex += 1
181
182 fft_data = numpy.fft.fft(data, axis=0)
183 fft_code = numpy.conj(numpy.fft.fft(newcode))
184 fft_code = fft_code.reshape(len(fft_code),1)
185
186 conv = fft_data.copy()
187 conv.fill(0)
188
189 conv = fft_data*fft_code # This other way to calculate multiplication between bidimensional arrays
190 # for i in range(ndata):
191 # conv[i,:] = fft_data[i,:]*fft_code[i]
192
193 self.data = numpy.fft.ifft(conv,axis=0)
194 self.flag = True
195
196 if self.profCounter == self.nCode:
197 self.profCounter = 0
198 self.codeIndex = 0
199
200 self.profCounter += 1
201
202 def convolutionInTime(self, data, ndata):
203
204 nchannel = data.shape[1]
205 newcode = self.code[self.codeIndex]
206 self.codeIndex += 1
207 conv = data.copy()
208 for i in range(nchannel):
209 conv[:,i] = numpy.correlate(data[:,i], newcode, 'same')
210
211 self.data = conv
212 self.flag = True
213
214 if self.profCounter == self.nCode:
215 self.profCounter = 0
216 self.codeIndex = 0
217
218 self.profCounter += 1
219
220
221 class CoherentIntegrator:
222 def __init__(self, N):
223 self.profCounter = 1
224 self.data = None
225 self.buffer = None
226 self.flag = False
227 self.nCohInt = N
228
229 def exe(self,data):
230
231 if self.buffer == None:
232 self.buffer = data
233 else:
234 self.buffer = self.buffer + data
235
236 if self.profCounter == self.nCohInt:
237 self.data = self.buffer
238 self.buffer = None
239 self.profCounter = 0
240 self.flag = True
241 else:
242 self.flag = False
243
244 self.profCounter += 1
245
246
247 No newline at end of file
General Comments 0
You need to be logged in to leave comments. Login now