@@ -1,541 +1,551 | |||
|
1 | 1 | ''' |
|
2 | 2 | File: SpectraIO.py |
|
3 | 3 | Created on 20/02/2012 |
|
4 | 4 | |
|
5 | 5 | @author $Author$ |
|
6 | 6 | @version $Id$ |
|
7 | 7 | ''' |
|
8 | 8 | |
|
9 | 9 | import os, sys |
|
10 | 10 | import numpy |
|
11 | 11 | import glob |
|
12 | 12 | import fnmatch |
|
13 | 13 | import time, datetime |
|
14 | 14 | |
|
15 | 15 | path = os.path.split(os.getcwd())[0] |
|
16 | 16 | sys.path.append(path) |
|
17 | 17 | |
|
18 | 18 | from Model.JROHeader import * |
|
19 | 19 | from Model.Spectra import Spectra |
|
20 | 20 | |
|
21 | 21 | from JRODataIO import JRODataReader |
|
22 | 22 | from JRODataIO import JRODataWriter |
|
23 | 23 | from JRODataIO import isNumber |
|
24 | 24 | |
|
25 | 25 | |
|
26 | 26 | class SpectraReader(JRODataReader): |
|
27 | 27 | """ |
|
28 | 28 | Esta clase permite leer datos de espectros desde archivos procesados (.pdata). La lectura |
|
29 | 29 | de los datos siempre se realiza por bloques. Los datos leidos (array de 3 dimensiones) |
|
30 | 30 | son almacenados en tres buffer's para el Self Spectra, el Cross Spectra y el DC Channel. |
|
31 | 31 | |
|
32 | 32 | paresCanalesIguales * alturas * perfiles (Self Spectra) |
|
33 | 33 | paresCanalesDiferentes * alturas * perfiles (Cross Spectra) |
|
34 | 34 | canales * alturas (DC Channels) |
|
35 | 35 | |
|
36 | 36 | Esta clase contiene instancias (objetos) de las clases BasicHeader, SystemHeader, |
|
37 | 37 | RadarControllerHeader y Spectra. Los tres primeros se usan para almacenar informacion de la |
|
38 | 38 | cabecera de datos (metadata), y el cuarto (Spectra) para obtener y almacenar un bloque de |
|
39 | 39 | datos desde el "buffer" cada vez que se ejecute el metodo "getData". |
|
40 | 40 | |
|
41 | 41 | Example: |
|
42 | 42 | dpath = "/home/myuser/data" |
|
43 | 43 | |
|
44 | 44 | startTime = datetime.datetime(2010,1,20,0,0,0,0,0,0) |
|
45 | 45 | |
|
46 | 46 | endTime = datetime.datetime(2010,1,21,23,59,59,0,0,0) |
|
47 | 47 | |
|
48 | 48 | readerObj = SpectraReader() |
|
49 | 49 | |
|
50 | 50 | readerObj.setup(dpath, startTime, endTime) |
|
51 | 51 | |
|
52 | 52 | while(True): |
|
53 | 53 | |
|
54 | 54 | readerObj.getData() |
|
55 | 55 | |
|
56 | 56 | print readerObj.m_Spectra.data |
|
57 | 57 | |
|
58 | 58 | if readerObj.flagNoMoreFiles: |
|
59 | 59 | break |
|
60 | 60 | |
|
61 | 61 | """ |
|
62 | 62 | m_DataObj = None |
|
63 | 63 | |
|
64 | 64 | data_spc = None |
|
65 | 65 | data_cspc = None |
|
66 | 66 | data_dc = None |
|
67 | 67 | |
|
68 | 68 | pts2read_SelfSpectra = 0 |
|
69 | 69 | pts2read_CrossSpectra = 0 |
|
70 | 70 | pts2read_DCchannels = 0 |
|
71 | 71 | |
|
72 | 72 | nChannels = 0 |
|
73 | 73 | |
|
74 | 74 | nPairs = 0 |
|
75 | 75 | |
|
76 | 76 | #pairList = None |
|
77 | 77 | |
|
78 | 78 | channelList = None |
|
79 | 79 | |
|
80 | 80 | def __init__(self, m_Spectra=None): |
|
81 | 81 | """ |
|
82 | 82 | Inicializador de la clase SpectraReader para la lectura de datos de espectros. |
|
83 | 83 | |
|
84 | 84 | Inputs: |
|
85 | 85 | m_Spectra : Objeto de la clase Spectra. Este objeto sera utilizado para |
|
86 | 86 | almacenar un perfil de datos cada vez que se haga un requerimiento |
|
87 | 87 | (getData). El perfil sera obtenido a partir del buffer de datos, |
|
88 | 88 | si el buffer esta vacio se hara un nuevo proceso de lectura de un |
|
89 | 89 | bloque de datos. |
|
90 | 90 | Si este parametro no es pasado se creara uno internamente. |
|
91 | 91 | |
|
92 | 92 | Affected: |
|
93 | 93 | self.m_DataObj |
|
94 | 94 | |
|
95 | 95 | Return : None |
|
96 | 96 | """ |
|
97 | 97 | if m_Spectra == None: |
|
98 | 98 | m_Spectra = Spectra() |
|
99 | 99 | |
|
100 | 100 | if not( isinstance(m_Spectra, Spectra) ): |
|
101 | 101 | raise ValueError, "in SpectraReader, m_Spectra must be an Spectra class object" |
|
102 | 102 | |
|
103 | 103 | self.m_DataObj = m_Spectra |
|
104 | 104 | |
|
105 | 105 | self.data_spc = None |
|
106 | 106 | self.data_cspc = None |
|
107 | 107 | self.data_dc = None |
|
108 | 108 | |
|
109 | 109 | self.pts2read_SelfSpectra = 0 |
|
110 | 110 | self.pts2read_CrossSpectra = 0 |
|
111 | 111 | self.pts2read_DCs = 0 |
|
112 | 112 | |
|
113 | 113 | self.nChannels = 0 |
|
114 | 114 | |
|
115 | 115 | self.nPairs = 0 |
|
116 | 116 | |
|
117 | 117 | self.ext = ".pdata" |
|
118 | 118 | |
|
119 | 119 | self.optchar = "P" |
|
120 | 120 | |
|
121 | 121 | ###################### |
|
122 | 122 | |
|
123 | 123 | self.m_BasicHeader = BasicHeader() |
|
124 | 124 | |
|
125 | 125 | self.m_SystemHeader = SystemHeader() |
|
126 | 126 | |
|
127 | 127 | self.m_RadarControllerHeader = RadarControllerHeader() |
|
128 | 128 | |
|
129 | 129 | self.m_ProcessingHeader = ProcessingHeader() |
|
130 | 130 | |
|
131 | 131 | self.online = 0 |
|
132 | 132 | |
|
133 | 133 | self.fp = None |
|
134 | 134 | |
|
135 | 135 | self.fileSizeByHeader = None |
|
136 | 136 | |
|
137 | 137 | self.filenameList = [] |
|
138 | 138 | |
|
139 | 139 | self.filename = None |
|
140 | 140 | |
|
141 | 141 | self.fileSize = None |
|
142 | 142 | |
|
143 | 143 | self.firstHeaderSize = 0 |
|
144 | 144 | |
|
145 | 145 | self.basicHeaderSize = 24 |
|
146 | 146 | |
|
147 | 147 | self.dataType = None |
|
148 | 148 | |
|
149 | 149 | self.maxTimeStep = 30 |
|
150 | 150 | |
|
151 | 151 | self.flagNoMoreFiles = 0 |
|
152 | 152 | |
|
153 | 153 | self.set = 0 |
|
154 | 154 | |
|
155 | 155 | self.path = None |
|
156 | 156 | |
|
157 | 157 | self.delay = 3 #seconds |
|
158 | 158 | |
|
159 | 159 | self.nTries = 3 #quantity tries |
|
160 | 160 | |
|
161 | 161 | self.nFiles = 3 #number of files for searching |
|
162 | 162 | |
|
163 | 163 | self.nReadBlocks = 0 |
|
164 | 164 | |
|
165 | 165 | self.flagIsNewFile = 1 |
|
166 | 166 | |
|
167 | 167 | self.ippSeconds = 0 |
|
168 | 168 | |
|
169 | 169 | self.flagResetProcessing = 0 |
|
170 | 170 | |
|
171 | 171 | self.flagIsNewBlock = 0 |
|
172 | 172 | |
|
173 | 173 | self.nTotalBlocks = 0 |
|
174 | 174 | |
|
175 | 175 | self.blocksize = 0 |
|
176 | 176 | |
|
177 | 177 | #pairList = None |
|
178 | 178 | |
|
179 | 179 | channelList = None |
|
180 | 180 | |
|
181 | self.flag_cspc = False | |
|
182 | ||
|
181 | 183 | |
|
182 | 184 | def __hasNotDataInBuffer(self): |
|
183 | 185 | return 1 |
|
184 | 186 | |
|
185 | 187 | |
|
186 | 188 | def getBlockDimension(self): |
|
187 | 189 | """ |
|
188 | 190 | Obtiene la cantidad de puntos a leer por cada bloque de datos |
|
189 | 191 | |
|
190 | 192 | Affected: |
|
191 | 193 | self.nChannels |
|
192 | 194 | self.nPairs |
|
193 | 195 | self.pts2read_SelfSpectra |
|
194 | 196 | self.pts2read_CrossSpectra |
|
195 | 197 | self.pts2read_DCchannels |
|
196 | 198 | self.blocksize |
|
197 | 199 | self.m_DataObj.nChannels |
|
198 | 200 | self.m_DataObj.nPairs |
|
199 | 201 | |
|
200 | 202 | Return: |
|
201 | 203 | None |
|
202 | 204 | """ |
|
203 | 205 | self.nChannels = 0 |
|
204 | 206 | self.nPairs = 0 |
|
205 | 207 | self.pairList = [] |
|
206 | 208 | |
|
207 | 209 | for i in range( 0, self.m_ProcessingHeader.totalSpectra*2, 2 ): |
|
208 | 210 | if self.m_ProcessingHeader.spectraComb[i] == self.m_ProcessingHeader.spectraComb[i+1]: |
|
209 | 211 | self.nChannels = self.nChannels + 1 #par de canales iguales |
|
210 | 212 | else: |
|
211 | 213 | self.nPairs = self.nPairs + 1 #par de canales diferentes |
|
212 | 214 | self.pairList.append( (self.m_ProcessingHeader.spectraComb[i], self.m_ProcessingHeader.spectraComb[i+1]) ) |
|
213 | 215 | |
|
216 | if self.nPairs > 0: | |
|
217 | self.flag_cspc = True | |
|
218 | ||
|
214 | 219 | pts2read = self.m_ProcessingHeader.numHeights * self.m_ProcessingHeader.profilesPerBlock |
|
215 | 220 | |
|
216 | 221 |
self.pts2read_SelfSpectra = int( |
|
222 | self.blocksize = self.pts2read_SelfSpectra | |
|
223 | ||
|
224 | if self.flag_cspc: | |
|
217 | 225 |
self.pts2read_CrossSpectra = int( |
|
226 | self.blocksize += self.pts2read_CrossSpectra | |
|
227 | ||
|
228 | if self.m_ProcessingHeader.flag_dc: | |
|
218 | 229 |
self.pts2read_DCchannels = int( |
|
230 | self.blocksize += self.pts2read_DCchannels | |
|
219 | 231 | |
|
220 | self.blocksize = self.pts2read_SelfSpectra + self.pts2read_CrossSpectra + self.pts2read_DCchannels | |
|
232 | # self.blocksize = self.pts2read_SelfSpectra + self.pts2read_CrossSpectra + self.pts2read_DCchannels | |
|
221 | 233 | |
|
222 | 234 |
self.channelList = numpy.arange( |
|
223 | 235 | |
|
224 | 236 | |
|
225 | 237 | def readBlock(self): |
|
226 | 238 | """ |
|
227 | 239 | Lee el bloque de datos desde la posicion actual del puntero del archivo |
|
228 | 240 | (self.fp) y actualiza todos los parametros relacionados al bloque de datos |
|
229 | 241 | (metadata + data). La data leida es almacenada en el buffer y el contador del buffer |
|
230 | 242 | es seteado a 0 |
|
231 | 243 | |
|
232 | 244 | Return: None |
|
233 | 245 | |
|
234 | 246 | Variables afectadas: |
|
235 | 247 | self.datablockIndex |
|
236 | 248 | self.flagIsNewFile |
|
237 | 249 | self.flagIsNewBlock |
|
238 | 250 | self.nTotalBlocks |
|
239 | 251 | self.data_spc |
|
240 | 252 | self.data_cspc |
|
241 | 253 | self.data_dc |
|
242 | 254 | |
|
243 | 255 | Exceptions: |
|
244 | 256 | Si un bloque leido no es un bloque valido |
|
245 | 257 | """ |
|
246 | 258 | blockOk_flag = False |
|
247 | 259 | fpointer = self.fp.tell() |
|
248 | 260 | |
|
249 | 261 | spc = numpy.fromfile( self.fp, self.dataType[0], self.pts2read_SelfSpectra ) |
|
250 | cspc = numpy.fromfile( self.fp, self.dataType, self.pts2read_CrossSpectra ) | |
|
251 | dc = numpy.fromfile( self.fp, self.dataType, self.pts2read_DCchannels ) #int(self.m_ProcessingHeader.numHeights*self.m_SystemHeader.numChannels) ) | |
|
252 | ||
|
253 | try: | |
|
254 | 262 |
|
|
255 | if self.nPairs != 0: | |
|
263 | ||
|
264 | if self.flag_cspc: | |
|
265 | cspc = numpy.fromfile( self.fp, self.dataType, self.pts2read_CrossSpectra ) | |
|
256 | 266 |
|
|
257 |
|
|
|
258 | cspc = None | |
|
267 | ||
|
268 | if self.m_ProcessingHeader.flag_dc: | |
|
269 | dc = numpy.fromfile( self.fp, self.dataType, self.pts2read_DCchannels ) #int(self.m_ProcessingHeader.numHeights*self.m_SystemHeader.numChannels) ) | |
|
259 | 270 | dc = dc.reshape( (self.m_SystemHeader.numChannels, self.m_ProcessingHeader.numHeights) ) #transforma a un arreglo 2D |
|
260 | except: | |
|
261 | print "Data file %s is invalid" % self.filename | |
|
262 | return 0 | |
|
271 | ||
|
263 | 272 | |
|
264 | 273 |
if not( |
|
265 | 274 | spc = numpy.roll( spc, self.m_ProcessingHeader.profilesPerBlock/2, axis=2 ) #desplaza a la derecha en el eje 2 determinadas posiciones |
|
266 | 275 | |
|
267 |
if cspc |
|
|
276 | if self.flag_cspc: | |
|
268 | 277 | cspc = numpy.roll( cspc, self.m_ProcessingHeader.profilesPerBlock/2, axis=2 ) #desplaza a la derecha en el eje 2 determinadas posiciones |
|
269 | 278 | |
|
279 | ||
|
270 | 280 | spc = numpy.transpose( spc, (0,2,1) ) |
|
281 | self.data_spc = spc | |
|
271 | 282 | |
|
272 |
if cspc |
|
|
283 | if self.flag_cspc: | |
|
273 | 284 | cspc = numpy.transpose( cspc, (0,2,1) ) |
|
274 | ||
|
275 | ||
|
276 | if cspc != None: | |
|
277 | 285 | self.data_cspc = cspc['real'] + cspc['imag']*1j |
|
278 | 286 | else: |
|
279 | 287 | self.data_cspc = None |
|
280 | 288 | |
|
281 | self.data_spc = spc | |
|
289 | if self.m_ProcessingHeader.flag_dc: | |
|
282 | 290 | self.data_dc = dc['real'] + dc['imag']*1j |
|
291 | else: | |
|
292 | self.data_dc = None | |
|
283 | 293 | |
|
284 | 294 | self.datablockIndex = 0 |
|
285 | 295 | self.flagIsNewFile = 0 |
|
286 | 296 | self.flagIsNewBlock = 1 |
|
287 | 297 | |
|
288 | 298 | self.nTotalBlocks += 1 |
|
289 | 299 | self.nReadBlocks += 1 |
|
290 | 300 | |
|
291 | 301 | return 1 |
|
292 | 302 | |
|
293 | 303 | |
|
294 | 304 | def getData(self): |
|
295 | 305 | """ |
|
296 | 306 | Copia el buffer de lectura a la clase "Spectra", |
|
297 | 307 | con todos los parametros asociados a este (metadata). cuando no hay datos en el buffer de |
|
298 | 308 | lectura es necesario hacer una nueva lectura de los bloques de datos usando "readNextBlock" |
|
299 | 309 | |
|
300 | 310 | Return: |
|
301 | 311 | 0 : Si no hay mas archivos disponibles |
|
302 | 312 | 1 : Si hizo una buena copia del buffer |
|
303 | 313 | |
|
304 | 314 | Affected: |
|
305 | 315 | self.m_DataObj |
|
306 | 316 | self.datablockIndex |
|
307 | 317 | self.flagResetProcessing |
|
308 | 318 | self.flagIsNewBlock |
|
309 | 319 | """ |
|
310 | 320 | |
|
311 | 321 | if self.flagNoMoreFiles: return 0 |
|
312 | 322 | |
|
313 | 323 | self.flagResetProcessing = 0 |
|
314 | 324 | self.flagIsNewBlock = 0 |
|
315 | 325 | |
|
316 | 326 | if self.__hasNotDataInBuffer(): |
|
317 | 327 | |
|
318 | 328 | if not( self.readNextBlock() ): |
|
319 | 329 | return 0 |
|
320 | 330 | |
|
321 | 331 | self.updateDataHeader() |
|
322 | 332 | |
|
323 | 333 | if self.flagNoMoreFiles == 1: |
|
324 | 334 | print 'Process finished' |
|
325 | 335 | return 0 |
|
326 | 336 | |
|
327 | 337 | #data es un numpy array de 3 dmensiones (perfiles, alturas y canales) |
|
328 | 338 | |
|
329 | 339 | if self.data_dc == None: |
|
330 | 340 | self.m_DataObj.flagNoData = True |
|
331 | 341 | return 0 |
|
332 | 342 | |
|
333 | 343 | self.m_DataObj.flagNoData = False |
|
334 | 344 | self.m_DataObj.flagResetProcessing = self.flagResetProcessing |
|
335 | 345 | |
|
336 | 346 | self.m_DataObj.data_spc = self.data_spc |
|
337 | 347 | self.m_DataObj.data_cspc = self.data_cspc |
|
338 | 348 | self.m_DataObj.data_dc = self.data_dc |
|
339 | 349 | |
|
340 | 350 | return 1 |
|
341 | 351 | |
|
342 | 352 | |
|
343 | 353 | class SpectraWriter(JRODataWriter): |
|
344 | 354 | |
|
345 | 355 | """ |
|
346 | 356 | Esta clase permite escribir datos de espectros a archivos procesados (.pdata). La escritura |
|
347 | 357 | de los datos siempre se realiza por bloques. |
|
348 | 358 | """ |
|
349 | 359 | |
|
350 | 360 | m_DataObj = None |
|
351 | 361 | |
|
352 | 362 | shape_spc_Buffer = None |
|
353 | 363 | shape_cspc_Buffer = None |
|
354 | 364 | shape_dc_Buffer = None |
|
355 | 365 | |
|
356 | 366 | data_spc = None |
|
357 | 367 | data_cspc = None |
|
358 | 368 | data_dc = None |
|
359 | 369 | |
|
360 | 370 | |
|
361 | 371 | def __init__(self, m_Spectra=None): |
|
362 | 372 | """ |
|
363 | 373 | Inicializador de la clase SpectraWriter para la escritura de datos de espectros. |
|
364 | 374 | |
|
365 | 375 | Affected: |
|
366 | 376 | self.m_DataObj |
|
367 | 377 | self.m_BasicHeader |
|
368 | 378 | self.m_SystemHeader |
|
369 | 379 | self.m_RadarControllerHeader |
|
370 | 380 | self.m_ProcessingHeader |
|
371 | 381 | |
|
372 | 382 | Return: None |
|
373 | 383 | """ |
|
374 | 384 | if m_Spectra == None: |
|
375 | 385 | m_Spectra = Spectra() |
|
376 | 386 | |
|
377 | 387 | if not( isinstance(m_Spectra, Spectra) ): |
|
378 | 388 | raise ValueError, "in SpectraReader, m_Spectra must be an Spectra class object" |
|
379 | 389 | |
|
380 | 390 | self.m_DataObj = m_Spectra |
|
381 | 391 | |
|
382 | 392 | self.ext = ".pdata" |
|
383 | 393 | |
|
384 | 394 | self.optchar = "P" |
|
385 | 395 | |
|
386 | 396 | self.shape_spc_Buffer = None |
|
387 | 397 | self.shape_cspc_Buffer = None |
|
388 | 398 | self.shape_dc_Buffer = None |
|
389 | 399 | |
|
390 | 400 | self.data_spc = None |
|
391 | 401 | self.data_cspc = None |
|
392 | 402 | self.data_dc = None |
|
393 | 403 | |
|
394 | 404 | #################################### |
|
395 | 405 | |
|
396 | 406 | self.fp = None |
|
397 | 407 | |
|
398 | 408 | self.nWriteBlocks = 0 |
|
399 | 409 | |
|
400 | 410 | self.flagIsNewFile = 1 |
|
401 | 411 | |
|
402 | 412 | self.nTotalBlocks = 0 |
|
403 | 413 | |
|
404 | 414 | self.flagIsNewBlock = 0 |
|
405 | 415 | |
|
406 | 416 | self.flagNoMoreFiles = 0 |
|
407 | 417 | |
|
408 | 418 | self.setFile = None |
|
409 | 419 | |
|
410 | 420 | self.dataType = None |
|
411 | 421 | |
|
412 | 422 | self.path = None |
|
413 | 423 | |
|
414 | 424 | self.noMoreFiles = 0 |
|
415 | 425 | |
|
416 | 426 | self.filename = None |
|
417 | 427 | |
|
418 | 428 | self.m_BasicHeader= BasicHeader() |
|
419 | 429 | |
|
420 | 430 | self.m_SystemHeader = SystemHeader() |
|
421 | 431 | |
|
422 | 432 | self.m_RadarControllerHeader = RadarControllerHeader() |
|
423 | 433 | |
|
424 | 434 | self.m_ProcessingHeader = ProcessingHeader() |
|
425 | 435 | |
|
426 | 436 | |
|
427 | 437 | def hasAllDataInBuffer(self): |
|
428 | 438 | return 1 |
|
429 | 439 | |
|
430 | 440 | |
|
431 | 441 | def setBlockDimension(self): |
|
432 | 442 | """ |
|
433 | 443 | Obtiene las formas dimensionales del los subbloques de datos que componen un bloque |
|
434 | 444 | |
|
435 | 445 | Affected: |
|
436 | 446 | self.shape_spc_Buffer |
|
437 | 447 | self.shape_cspc_Buffer |
|
438 | 448 | self.shape_dc_Buffer |
|
439 | 449 | |
|
440 | 450 | Return: None |
|
441 | 451 | """ |
|
442 | 452 | self.shape_spc_Buffer = (self.m_DataObj.nChannels, |
|
443 | 453 | self.m_ProcessingHeader.numHeights, |
|
444 | 454 | self.m_ProcessingHeader.profilesPerBlock) |
|
445 | 455 | |
|
446 | 456 | self.shape_cspc_Buffer = (self.m_DataObj.nPairs, |
|
447 | 457 | self.m_ProcessingHeader.numHeights, |
|
448 | 458 | self.m_ProcessingHeader.profilesPerBlock) |
|
449 | 459 | |
|
450 | 460 | self.shape_dc_Buffer = (self.m_SystemHeader.numChannels, |
|
451 | 461 | self.m_ProcessingHeader.numHeights) |
|
452 | 462 | |
|
453 | 463 | |
|
454 | 464 | def writeBlock(self): |
|
455 | 465 | """ |
|
456 | 466 | Escribe el buffer en el file designado |
|
457 | 467 | |
|
458 | 468 | Affected: |
|
459 | 469 | self.data_spc |
|
460 | 470 | self.data_cspc |
|
461 | 471 | self.data_dc |
|
462 | 472 | self.flagIsNewFile |
|
463 | 473 | self.flagIsNewBlock |
|
464 | 474 | self.nTotalBlocks |
|
465 | 475 | self.nWriteBlocks |
|
466 | 476 | |
|
467 | 477 | Return: None |
|
468 | 478 | """ |
|
469 | 479 | |
|
470 | 480 | spc = numpy.transpose( self.data_spc, (0,2,1) ) |
|
471 | 481 | if not( self.m_ProcessingHeader.shif_fft ): |
|
472 | 482 | spc = numpy.roll( spc, self.m_ProcessingHeader.profilesPerBlock/2, axis=2 ) #desplaza a la derecha en el eje 2 determinadas posiciones |
|
473 | 483 | data = spc.reshape((-1)) |
|
474 | 484 | data.tofile(self.fp) |
|
475 | 485 | |
|
476 | 486 | if self.data_cspc != None: |
|
477 | 487 | data = numpy.zeros( self.shape_cspc_Buffer, self.dataType ) |
|
478 | 488 | cspc = numpy.transpose( self.data_cspc, (0,2,1) ) |
|
479 | 489 | if not( self.m_ProcessingHeader.shif_fft ): |
|
480 | 490 | cspc = numpy.roll( cspc, self.m_ProcessingHeader.profilesPerBlock/2, axis=2 ) #desplaza a la derecha en el eje 2 determinadas posiciones |
|
481 | 491 | data['real'] = cspc.real |
|
482 | 492 | data['imag'] = cspc.imag |
|
483 | 493 | data = data.reshape((-1)) |
|
484 | 494 | data.tofile(self.fp) |
|
485 | 495 | |
|
486 | 496 | data = numpy.zeros( self.shape_dc_Buffer, self.dataType ) |
|
487 | 497 | dc = self.data_dc |
|
488 | 498 | data['real'] = dc.real |
|
489 | 499 | data['imag'] = dc.imag |
|
490 | 500 | data = data.reshape((-1)) |
|
491 | 501 | data.tofile(self.fp) |
|
492 | 502 | |
|
493 | 503 | self.data_spc.fill(0) |
|
494 | 504 | self.data_dc.fill(0) |
|
495 | 505 | if self.data_cspc != None: |
|
496 | 506 | self.data_cspc.fill(0) |
|
497 | 507 | |
|
498 | 508 | self.flagIsNewFile = 0 |
|
499 | 509 | self.flagIsNewBlock = 1 |
|
500 | 510 | self.nTotalBlocks += 1 |
|
501 | 511 | self.nWriteBlocks += 1 |
|
502 | 512 | |
|
503 | 513 | |
|
504 | 514 | def putData(self): |
|
505 | 515 | """ |
|
506 | 516 | Setea un bloque de datos y luego los escribe en un file |
|
507 | 517 | |
|
508 | 518 | Affected: |
|
509 | 519 | self.data_spc |
|
510 | 520 | self.data_cspc |
|
511 | 521 | self.data_dc |
|
512 | 522 | |
|
513 | 523 | Return: |
|
514 | 524 | 0 : Si no hay data o no hay mas files que puedan escribirse |
|
515 | 525 | 1 : Si se escribio la data de un bloque en un file |
|
516 | 526 | """ |
|
517 | 527 | self.flagIsNewBlock = 0 |
|
518 | 528 | |
|
519 | 529 | if self.m_DataObj.flagNoData: |
|
520 | 530 | return 0 |
|
521 | 531 | |
|
522 | 532 | if self.m_DataObj.flagResetProcessing: |
|
523 | 533 | self.data_spc.fill(0) |
|
524 | 534 | self.data_cspc.fill(0) |
|
525 | 535 | self.data_dc.fill(0) |
|
526 | 536 | self.setNextFile() |
|
527 | 537 | |
|
528 | 538 | self.data_spc = self.m_DataObj.data_spc |
|
529 | 539 | self.data_cspc = self.m_DataObj.data_cspc |
|
530 | 540 | self.data_dc = self.m_DataObj.data_dc |
|
531 | 541 | |
|
532 | 542 | # #self.m_ProcessingHeader.dataBlocksPerFile) |
|
533 | 543 | if self.hasAllDataInBuffer(): |
|
534 | 544 | self.getDataHeader() |
|
535 | 545 | self.writeNextBlock() |
|
536 | 546 | |
|
537 | 547 | if self.flagNoMoreFiles: |
|
538 | 548 | #print 'Process finished' |
|
539 | 549 | return 0 |
|
540 | 550 | |
|
541 | 551 | return 1 No newline at end of file |
@@ -1,482 +1,486 | |||
|
1 | 1 | ''' |
|
2 | 2 | Created on 23/01/2012 |
|
3 | 3 | |
|
4 | 4 | @author $Author: vsarmiento $ |
|
5 | 5 | @version $Id: HeaderIO.py 37 2012-03-26 22:55:13Z vsarmiento $ |
|
6 | 6 | ''' |
|
7 | 7 | |
|
8 | 8 | import numpy |
|
9 | 9 | import copy |
|
10 | 10 | |
|
11 | 11 | class Header: |
|
12 | 12 | |
|
13 | 13 | def __init__(self): |
|
14 | 14 | raise |
|
15 | 15 | |
|
16 | 16 | def copy(self): |
|
17 | 17 | return copy.deepcopy(self) |
|
18 | 18 | |
|
19 | 19 | def read(): |
|
20 | 20 | pass |
|
21 | 21 | |
|
22 | 22 | def write(): |
|
23 | 23 | pass |
|
24 | 24 | |
|
25 | 25 | class BasicHeader(Header): |
|
26 | 26 | |
|
27 | 27 | size = None |
|
28 | 28 | version = None |
|
29 | 29 | dataBlock = None |
|
30 | 30 | utc = None |
|
31 | 31 | miliSecond = None |
|
32 | 32 | timeZone = None |
|
33 | 33 | dstFlag = None |
|
34 | 34 | errorCount = None |
|
35 | 35 | struct = None |
|
36 | 36 | |
|
37 | 37 | def __init__(self): |
|
38 | 38 | self.size = 0 |
|
39 | 39 | self.version = 0 |
|
40 | 40 | self.dataBlock = 0 |
|
41 | 41 | self.utc = 0 |
|
42 | 42 | self.miliSecond = 0 |
|
43 | 43 | self.timeZone = 0 |
|
44 | 44 | self.dstFlag = 0 |
|
45 | 45 | self.errorCount = 0 |
|
46 | 46 | self.struct = numpy.dtype([ |
|
47 | 47 | ('nSize','<u4'), |
|
48 | 48 | ('nVersion','<u2'), |
|
49 | 49 | ('nDataBlockId','<u4'), |
|
50 | 50 | ('nUtime','<u4'), |
|
51 | 51 | ('nMilsec','<u2'), |
|
52 | 52 | ('nTimezone','<i2'), |
|
53 | 53 | ('nDstflag','<i2'), |
|
54 | 54 | ('nErrorCount','<u4') |
|
55 | 55 | ]) |
|
56 | 56 | |
|
57 | 57 | |
|
58 | 58 | def read(self, fp): |
|
59 | 59 | try: |
|
60 | 60 | header = numpy.fromfile(fp, self.struct,1) |
|
61 | 61 | self.size = header['nSize'][0] |
|
62 | 62 | self.version = header['nVersion'][0] |
|
63 | 63 | self.dataBlock = header['nDataBlockId'][0] |
|
64 | 64 | self.utc = header['nUtime'][0] |
|
65 | 65 | self.miliSecond = header['nMilsec'][0] |
|
66 | 66 | self.timeZone = header['nTimezone'][0] |
|
67 | 67 | self.dstFlag = header['nDstflag'][0] |
|
68 | 68 | self.errorCount = header['nErrorCount'][0] |
|
69 | 69 | except: |
|
70 | 70 | return 0 |
|
71 | 71 | |
|
72 | 72 | return 1 |
|
73 | 73 | |
|
74 | 74 | def write(self, fp): |
|
75 | 75 | headerTuple = (self.size,self.version,self.dataBlock,self.utc,self.miliSecond,self.timeZone,self.dstFlag,self.errorCount) |
|
76 | 76 | header = numpy.array(headerTuple,self.struct) |
|
77 | 77 | header.tofile(fp) |
|
78 | 78 | |
|
79 | 79 | return 1 |
|
80 | 80 | |
|
81 | 81 | class SystemHeader(Header): |
|
82 | 82 | |
|
83 | 83 | size = None |
|
84 | 84 | numSamples = None |
|
85 | 85 | numProfiles = None |
|
86 | 86 | numChannels = None |
|
87 | 87 | adcResolution = None |
|
88 | 88 | pciDioBusWidth = None |
|
89 | 89 | struct = None |
|
90 | 90 | |
|
91 | 91 | def __init__(self): |
|
92 | 92 | self.size = 0 |
|
93 | 93 | self.numSamples = 0 |
|
94 | 94 | self.numProfiles = 0 |
|
95 | 95 | self.numChannels = 0 |
|
96 | 96 | self.adcResolution = 0 |
|
97 | 97 | self.pciDioBusWidth = 0 |
|
98 | 98 | self.struct = numpy.dtype([ |
|
99 | 99 | ('nSize','<u4'), |
|
100 | 100 | ('nNumSamples','<u4'), |
|
101 | 101 | ('nNumProfiles','<u4'), |
|
102 | 102 | ('nNumChannels','<u4'), |
|
103 | 103 | ('nADCResolution','<u4'), |
|
104 | 104 | ('nPCDIOBusWidth','<u4'), |
|
105 | 105 | ]) |
|
106 | 106 | |
|
107 | 107 | |
|
108 | 108 | def read(self, fp): |
|
109 | 109 | try: |
|
110 | 110 | header = numpy.fromfile(fp,self.struct,1) |
|
111 | 111 | self.size = header['nSize'][0] |
|
112 | 112 | self.numSamples = header['nNumSamples'][0] |
|
113 | 113 | self.numProfiles = header['nNumProfiles'][0] |
|
114 | 114 | self.numChannels = header['nNumChannels'][0] |
|
115 | 115 | self.adcResolution = header['nADCResolution'][0] |
|
116 | 116 | self.pciDioBusWidth = header['nPCDIOBusWidth'][0] |
|
117 | 117 | except: |
|
118 | 118 | return 0 |
|
119 | 119 | |
|
120 | 120 | return 1 |
|
121 | 121 | |
|
122 | 122 | def write(self, fp): |
|
123 | 123 | headerTuple = (self.size,self.numSamples,self.numProfiles,self.numChannels,self.adcResolution,self.pciDioBusWidth) |
|
124 | 124 | header = numpy.array(headerTuple,self.struct) |
|
125 | 125 | header.tofile(fp) |
|
126 | 126 | |
|
127 | 127 | return 1 |
|
128 | 128 | |
|
129 | 129 | class RadarControllerHeader(Header): |
|
130 | 130 | |
|
131 | 131 | size = None |
|
132 | 132 | expType = None |
|
133 | 133 | nTx = None |
|
134 | 134 | ipp = None |
|
135 | 135 | txA = None |
|
136 | 136 | txB = None |
|
137 | 137 | numWindows = None |
|
138 | 138 | numTaus = None |
|
139 | 139 | codeType = None |
|
140 | 140 | line6Function = None |
|
141 | 141 | line5Function = None |
|
142 | 142 | fClock = None |
|
143 | 143 | prePulseBefore = None |
|
144 | 144 | prePulserAfter = None |
|
145 | 145 | rangeIpp = None |
|
146 | 146 | rangeTxA = None |
|
147 | 147 | rangeTxB = None |
|
148 | 148 | struct = None |
|
149 | 149 | |
|
150 | 150 | def __init__(self): |
|
151 | 151 | self.size = 0 |
|
152 | 152 | self.expType = 0 |
|
153 | 153 | self.nTx = 0 |
|
154 | 154 | self.ipp = 0 |
|
155 | 155 | self.txA = 0 |
|
156 | 156 | self.txB = 0 |
|
157 | 157 | self.numWindows = 0 |
|
158 | 158 | self.numTaus = 0 |
|
159 | 159 | self.codeType = 0 |
|
160 | 160 | self.line6Function = 0 |
|
161 | 161 | self.line5Function = 0 |
|
162 | 162 | self.fClock = 0 |
|
163 | 163 | self.prePulseBefore = 0 |
|
164 | 164 | self.prePulserAfter = 0 |
|
165 | 165 | self.rangeIpp = 0 |
|
166 | 166 | self.rangeTxA = 0 |
|
167 | 167 | self.rangeTxB = 0 |
|
168 | 168 | self.struct = numpy.dtype([ |
|
169 | 169 | ('nSize','<u4'), |
|
170 | 170 | ('nExpType','<u4'), |
|
171 | 171 | ('nNTx','<u4'), |
|
172 | 172 | ('fIpp','<f4'), |
|
173 | 173 | ('fTxA','<f4'), |
|
174 | 174 | ('fTxB','<f4'), |
|
175 | 175 | ('nNumWindows','<u4'), |
|
176 | 176 | ('nNumTaus','<u4'), |
|
177 | 177 | ('nCodeType','<u4'), |
|
178 | 178 | ('nLine6Function','<u4'), |
|
179 | 179 | ('nLine5Function','<u4'), |
|
180 | 180 | ('fClock','<f4'), |
|
181 | 181 | ('nPrePulseBefore','<u4'), |
|
182 | 182 | ('nPrePulseAfter','<u4'), |
|
183 | 183 | ('sRangeIPP','<a20'), |
|
184 | 184 | ('sRangeTxA','<a20'), |
|
185 | 185 | ('sRangeTxB','<a20'), |
|
186 | 186 | ]) |
|
187 | 187 | |
|
188 | 188 | self.samplingWindowStruct = numpy.dtype([('h0','<f4'),('dh','<f4'),('nsa','<u4')]) |
|
189 | 189 | |
|
190 | 190 | self.samplingWindow = None |
|
191 | 191 | self.numHeights = None |
|
192 | 192 | self.firstHeight = None |
|
193 | 193 | self.deltaHeight = None |
|
194 | 194 | self.samplesWin = None |
|
195 | 195 | |
|
196 | 196 | self.numCode = None |
|
197 | 197 | self.numBaud = None |
|
198 | 198 | self.code = None |
|
199 | 199 | self.flip1 = None |
|
200 | 200 | self.flip2 = None |
|
201 | 201 | |
|
202 | 202 | self.dynamic = numpy.array([],numpy.dtype('byte')) |
|
203 | 203 | |
|
204 | 204 | |
|
205 | 205 | def read(self, fp): |
|
206 | 206 | try: |
|
207 | 207 | startFp = fp.tell() |
|
208 | 208 | header = numpy.fromfile(fp,self.struct,1) |
|
209 | 209 | self.size = header['nSize'][0] |
|
210 | 210 | self.expType = header['nExpType'][0] |
|
211 | 211 | self.nTx = header['nNTx'][0] |
|
212 | 212 | self.ipp = header['fIpp'][0] |
|
213 | 213 | self.txA = header['fTxA'][0] |
|
214 | 214 | self.txB = header['fTxB'][0] |
|
215 | 215 | self.numWindows = header['nNumWindows'][0] |
|
216 | 216 | self.numTaus = header['nNumTaus'][0] |
|
217 | 217 | self.codeType = header['nCodeType'][0] |
|
218 | 218 | self.line6Function = header['nLine6Function'][0] |
|
219 | 219 | self.line5Function = header['nLine5Function'][0] |
|
220 | 220 | self.fClock = header['fClock'][0] |
|
221 | 221 | self.prePulseBefore = header['nPrePulseBefore'][0] |
|
222 | 222 | self.prePulserAfter = header['nPrePulseAfter'][0] |
|
223 | 223 | self.rangeIpp = header['sRangeIPP'][0] |
|
224 | 224 | self.rangeTxA = header['sRangeTxA'][0] |
|
225 | 225 | self.rangeTxB = header['sRangeTxB'][0] |
|
226 | 226 | # jump Dynamic Radar Controller Header |
|
227 | 227 | jumpFp = self.size - 116 |
|
228 | 228 | self.dynamic = numpy.fromfile(fp,numpy.dtype('byte'),jumpFp) |
|
229 | 229 | #pointer backward to dynamic header and read |
|
230 | 230 | backFp = fp.tell() - jumpFp |
|
231 | 231 | fp.seek(backFp) |
|
232 | 232 | |
|
233 | 233 | self.samplingWindow = numpy.fromfile(fp,self.samplingWindowStruct,self.numWindows) |
|
234 | 234 | self.numHeights = numpy.sum(self.samplingWindow['nsa']) |
|
235 | 235 | self.firstHeight = self.samplingWindow['h0'] |
|
236 | 236 | self.deltaHeight = self.samplingWindow['dh'] |
|
237 | 237 | self.samplesWin = self.samplingWindow['nsa'] |
|
238 | 238 | |
|
239 | 239 | self.Taus = numpy.fromfile(fp,'<f4',self.numTaus) |
|
240 | 240 | |
|
241 | 241 | if self.codeType != 0: |
|
242 | 242 | self.numCode = numpy.fromfile(fp,'<u4',1) |
|
243 | 243 | self.numBaud = numpy.fromfile(fp,'<u4',1) |
|
244 | 244 | self.code = numpy.empty([self.numCode,self.numBaud],dtype='u1') |
|
245 | 245 | tempList = [] |
|
246 | 246 | for ic in range(self.numCode): |
|
247 | 247 | temp = numpy.fromfile(fp,'u1',4*numpy.ceil(self.numBaud/32.)) |
|
248 | 248 | tempList.append(temp) |
|
249 | 249 | self.code[ic] = numpy.unpackbits(temp[::-1])[-1*self.numBaud:] |
|
250 | 250 | self.code = 2.0*self.code - 1.0 |
|
251 | 251 | |
|
252 | 252 | if self.line5Function == RCfunction.FLIP: |
|
253 | 253 | self.flip1 = numpy.fromfile(fp,'<u4',1) |
|
254 | 254 | |
|
255 | 255 | if self.line6Function == RCfunction.FLIP: |
|
256 | 256 | self.flip2 = numpy.fromfile(fp,'<u4',1) |
|
257 | 257 | |
|
258 | 258 | endFp = self.size + startFp |
|
259 | 259 | jumpFp = endFp - fp.tell() |
|
260 | 260 | if jumpFp > 0: |
|
261 | 261 | fp.seek(jumpFp) |
|
262 | 262 | |
|
263 | 263 | except: |
|
264 | 264 | return 0 |
|
265 | 265 | |
|
266 | 266 | return 1 |
|
267 | 267 | |
|
268 | 268 | def write(self, fp): |
|
269 | 269 | headerTuple = (self.size, |
|
270 | 270 | self.expType, |
|
271 | 271 | self.nTx, |
|
272 | 272 | self.ipp, |
|
273 | 273 | self.txA, |
|
274 | 274 | self.txB, |
|
275 | 275 | self.numWindows, |
|
276 | 276 | self.numTaus, |
|
277 | 277 | self.codeType, |
|
278 | 278 | self.line6Function, |
|
279 | 279 | self.line5Function, |
|
280 | 280 | self.fClock, |
|
281 | 281 | self.prePulseBefore, |
|
282 | 282 | self.prePulserAfter, |
|
283 | 283 | self.rangeIpp, |
|
284 | 284 | self.rangeTxA, |
|
285 | 285 | self.rangeTxB) |
|
286 | 286 | |
|
287 | 287 | header = numpy.array(headerTuple,self.struct) |
|
288 | 288 | header.tofile(fp) |
|
289 | 289 | |
|
290 | 290 | dynamic = self.dynamic |
|
291 | 291 | dynamic.tofile(fp) |
|
292 | 292 | |
|
293 | 293 | return 1 |
|
294 | 294 | |
|
295 | 295 | |
|
296 | 296 | |
|
297 | 297 | class ProcessingHeader(Header): |
|
298 | 298 | |
|
299 | 299 | size = None |
|
300 | 300 | dataType = None |
|
301 | 301 | blockSize = None |
|
302 | 302 | profilesPerBlock = None |
|
303 | 303 | dataBlocksPerFile = None |
|
304 | 304 | numWindows = None |
|
305 | 305 | processFlags = None |
|
306 | 306 | coherentInt = None |
|
307 | 307 | incoherentInt = None |
|
308 | 308 | totalSpectra = None |
|
309 | 309 | struct = None |
|
310 | 310 | |
|
311 | 311 | def __init__(self): |
|
312 | 312 | self.size = 0 |
|
313 | 313 | self.dataType = 0 |
|
314 | 314 | self.blockSize = 0 |
|
315 | 315 | self.profilesPerBlock = 0 |
|
316 | 316 | self.dataBlocksPerFile = 0 |
|
317 | 317 | self.numWindows = 0 |
|
318 | 318 | self.processFlags = 0 |
|
319 | 319 | self.coherentInt = 0 |
|
320 | 320 | self.incoherentInt = 0 |
|
321 | 321 | self.totalSpectra = 0 |
|
322 | 322 | self.struct = numpy.dtype([ |
|
323 | 323 | ('nSize','<u4'), |
|
324 | 324 | ('nDataType','<u4'), |
|
325 | 325 | ('nSizeOfDataBlock','<u4'), |
|
326 | 326 | ('nProfilesperBlock','<u4'), |
|
327 | 327 | ('nDataBlocksperFile','<u4'), |
|
328 | 328 | ('nNumWindows','<u4'), |
|
329 | 329 | ('nProcessFlags','<u4'), |
|
330 | 330 | ('nCoherentIntegrations','<u4'), |
|
331 | 331 | ('nIncoherentIntegrations','<u4'), |
|
332 | 332 | ('nTotalSpectra','<u4') |
|
333 | 333 | ]) |
|
334 | 334 | self.samplingWindow = 0 |
|
335 | 335 | self.structSamplingWindow = numpy.dtype([('h0','<f4'),('dh','<f4'),('nsa','<u4')]) |
|
336 | 336 | self.numHeights = 0 |
|
337 | 337 | self.firstHeight = 0 |
|
338 | 338 | self.deltaHeight = 0 |
|
339 | 339 | self.samplesWin = 0 |
|
340 | 340 | self.spectraComb = 0 |
|
341 | 341 | self.numCode = 0 |
|
342 | 342 | self.code = 0 |
|
343 | 343 | self.numBaud = 0 |
|
344 | 344 | self.shif_fft = False |
|
345 | self.flag_dc = False | |
|
345 | 346 | |
|
346 | 347 | def read(self, fp): |
|
347 | 348 | try: |
|
348 | 349 | header = numpy.fromfile(fp,self.struct,1) |
|
349 | 350 | self.size = header['nSize'][0] |
|
350 | 351 | self.dataType = header['nDataType'][0] |
|
351 | 352 | self.blockSize = header['nSizeOfDataBlock'][0] |
|
352 | 353 | self.profilesPerBlock = header['nProfilesperBlock'][0] |
|
353 | 354 | self.dataBlocksPerFile = header['nDataBlocksperFile'][0] |
|
354 | 355 | self.numWindows = header['nNumWindows'][0] |
|
355 | 356 | self.processFlags = header['nProcessFlags'] |
|
356 | 357 | self.coherentInt = header['nCoherentIntegrations'][0] |
|
357 | 358 | self.incoherentInt = header['nIncoherentIntegrations'][0] |
|
358 | 359 | self.totalSpectra = header['nTotalSpectra'][0] |
|
359 | 360 | self.samplingWindow = numpy.fromfile(fp,self.structSamplingWindow,self.numWindows) |
|
360 | 361 | self.numHeights = numpy.sum(self.samplingWindow['nsa']) |
|
361 | 362 | self.firstHeight = self.samplingWindow['h0'] |
|
362 | 363 | self.deltaHeight = self.samplingWindow['dh'] |
|
363 | 364 | self.samplesWin = self.samplingWindow['nsa'] |
|
364 | 365 | self.spectraComb = numpy.fromfile(fp,'u1',2*self.totalSpectra) |
|
365 | 366 | |
|
366 | if self.processFlags & PROCFLAG.DEFINE_PROCESS_CODE == PROCFLAG.DEFINE_PROCESS_CODE: | |
|
367 | if ((self.processFlags & PROCFLAG.DEFINE_PROCESS_CODE) == PROCFLAG.DEFINE_PROCESS_CODE): | |
|
367 | 368 | self.numCode = numpy.fromfile(fp,'<u4',1) |
|
368 | 369 | self.numBaud = numpy.fromfile(fp,'<u4',1) |
|
369 | 370 | self.code = numpy.fromfile(fp,'<f4',self.numCode*self.numBaud).reshape(self.numBaud,self.numCode) |
|
370 | 371 | |
|
371 | if self.processFlags & PROCFLAG.SHIFT_FFT_DATA == PROCFLAG.SHIFT_FFT_DATA: | |
|
372 | if ((self.processFlags & PROCFLAG.SHIFT_FFT_DATA) == PROCFLAG.SHIFT_FFT_DATA): | |
|
372 | 373 | self.shif_fft = True |
|
373 | 374 | else: |
|
374 | 375 | self.shif_fft = False |
|
376 | ||
|
377 | if ((self.processFlags & PROCFLAG.SAVE_CHANNELS_DC) == PROCFLAG.SAVE_CHANNELS_DC): | |
|
378 | self.flag_dc = True | |
|
375 | 379 | except: |
|
376 | 380 | return 0 |
|
377 | 381 | |
|
378 | 382 | return 1 |
|
379 | 383 | |
|
380 | 384 | def write(self, fp): |
|
381 | 385 | headerTuple = (self.size, |
|
382 | 386 | self.dataType, |
|
383 | 387 | self.blockSize, |
|
384 | 388 | self.profilesPerBlock, |
|
385 | 389 | self.dataBlocksPerFile, |
|
386 | 390 | self.numWindows, |
|
387 | 391 | self.processFlags, |
|
388 | 392 | self.coherentInt, |
|
389 | 393 | self.incoherentInt, |
|
390 | 394 | self.totalSpectra) |
|
391 | 395 | |
|
392 | 396 | header = numpy.array(headerTuple,self.struct) |
|
393 | 397 | header.tofile(fp) |
|
394 | 398 | |
|
395 | 399 | if self.numWindows != 0: |
|
396 | 400 | sampleWindowTuple = (self.firstHeight,self.deltaHeight,self.samplesWin) |
|
397 | 401 | samplingWindow = numpy.array(sampleWindowTuple,self.structSamplingWindow) |
|
398 | 402 | samplingWindow.tofile(fp) |
|
399 | 403 | |
|
400 | 404 | |
|
401 | 405 | if self.totalSpectra != 0: |
|
402 | 406 | spectraComb = numpy.array([],numpy.dtype('u1')) |
|
403 | 407 | spectraComb = self.spectraComb |
|
404 | 408 | spectraComb.tofile(fp) |
|
405 | 409 | |
|
406 | 410 | |
|
407 | 411 | if self.processFlags & PROCFLAG.DEFINE_PROCESS_CODE == PROCFLAG.DEFINE_PROCESS_CODE: |
|
408 | 412 | numCode = self.numCode |
|
409 | 413 | numCode.tofile(fp) |
|
410 | 414 | |
|
411 | 415 | numBaud = self.numBaud |
|
412 | 416 | numBaud.tofile(fp) |
|
413 | 417 | |
|
414 | 418 | code = self.code.reshape(numCode*numBaud) |
|
415 | 419 | code.tofile(fp) |
|
416 | 420 | |
|
417 | 421 | return 1 |
|
418 | 422 | |
|
419 | 423 | class RCfunction: |
|
420 | 424 | NONE=0 |
|
421 | 425 | FLIP=1 |
|
422 | 426 | CODE=2 |
|
423 | 427 | SAMPLING=3 |
|
424 | 428 | LIN6DIV256=4 |
|
425 | 429 | SYNCHRO=5 |
|
426 | 430 | |
|
427 | 431 | class nCodeType: |
|
428 | 432 | NONE=0 |
|
429 | 433 | USERDEFINE=1 |
|
430 | 434 | BARKER2=2 |
|
431 | 435 | BARKER3=3 |
|
432 | 436 | BARKER4=4 |
|
433 | 437 | BARKER5=5 |
|
434 | 438 | BARKER7=6 |
|
435 | 439 | BARKER11=7 |
|
436 | 440 | BARKER13=8 |
|
437 | 441 | AC128=9 |
|
438 | 442 | COMPLEMENTARYCODE2=10 |
|
439 | 443 | COMPLEMENTARYCODE4=11 |
|
440 | 444 | COMPLEMENTARYCODE8=12 |
|
441 | 445 | COMPLEMENTARYCODE16=13 |
|
442 | 446 | COMPLEMENTARYCODE32=14 |
|
443 | 447 | COMPLEMENTARYCODE64=15 |
|
444 | 448 | COMPLEMENTARYCODE128=16 |
|
445 | 449 | CODE_BINARY28=17 |
|
446 | 450 | |
|
447 | 451 | class PROCFLAG: |
|
448 | 452 | COHERENT_INTEGRATION = numpy.uint32(0x00000001) |
|
449 | 453 | DECODE_DATA = numpy.uint32(0x00000002) |
|
450 | 454 | SPECTRA_CALC = numpy.uint32(0x00000004) |
|
451 | 455 | INCOHERENT_INTEGRATION = numpy.uint32(0x00000008) |
|
452 | 456 | POST_COHERENT_INTEGRATION = numpy.uint32(0x00000010) |
|
453 | 457 | SHIFT_FFT_DATA = numpy.uint32(0x00000020) |
|
454 | 458 | |
|
455 | 459 | DATATYPE_CHAR = numpy.uint32(0x00000040) |
|
456 | 460 | DATATYPE_SHORT = numpy.uint32(0x00000080) |
|
457 | 461 | DATATYPE_LONG = numpy.uint32(0x00000100) |
|
458 | 462 | DATATYPE_INT64 = numpy.uint32(0x00000200) |
|
459 | 463 | DATATYPE_FLOAT = numpy.uint32(0x00000400) |
|
460 | 464 | DATATYPE_DOUBLE = numpy.uint32(0x00000800) |
|
461 | 465 | |
|
462 | 466 | DATAARRANGE_CONTIGUOUS_CH = numpy.uint32(0x00001000) |
|
463 | 467 | DATAARRANGE_CONTIGUOUS_H = numpy.uint32(0x00002000) |
|
464 | 468 | DATAARRANGE_CONTIGUOUS_P = numpy.uint32(0x00004000) |
|
465 | 469 | |
|
466 | 470 | SAVE_CHANNELS_DC = numpy.uint32(0x00008000) |
|
467 | 471 | DEFLIP_DATA = numpy.uint32(0x00010000) |
|
468 | 472 | DEFINE_PROCESS_CODE = numpy.uint32(0x00020000) |
|
469 | 473 | |
|
470 | 474 | ACQ_SYS_NATALIA = numpy.uint32(0x00040000) |
|
471 | 475 | ACQ_SYS_ECHOTEK = numpy.uint32(0x00080000) |
|
472 | 476 | ACQ_SYS_ADRXD = numpy.uint32(0x000C0000) |
|
473 | 477 | ACQ_SYS_JULIA = numpy.uint32(0x00100000) |
|
474 | 478 | ACQ_SYS_XXXXXX = numpy.uint32(0x00140000) |
|
475 | 479 | |
|
476 | 480 | EXP_NAME_ESP = numpy.uint32(0x00200000) |
|
477 | 481 | CHANNEL_NAMES_ESP = numpy.uint32(0x00400000) |
|
478 | 482 | |
|
479 | 483 | OPERATION_MASK = numpy.uint32(0x0000003F) |
|
480 | 484 | DATATYPE_MASK = numpy.uint32(0x00000FC0) |
|
481 | 485 | DATAARRANGE_MASK = numpy.uint32(0x00007000) |
|
482 | 486 | ACQ_SYS_MASK = numpy.uint32(0x001C0000) No newline at end of file |
General Comments 0
You need to be logged in to leave comments.
Login now