@@ -1,777 +1,781 | |||||
1 | ''' |
|
1 | ''' | |
2 |
|
2 | |||
3 | $Author$ |
|
3 | $Author$ | |
4 | $Id$ |
|
4 | $Id$ | |
5 | ''' |
|
5 | ''' | |
6 |
|
6 | |||
7 | import os, sys |
|
7 | import os, sys | |
8 | import numpy |
|
8 | import numpy | |
9 | import glob |
|
9 | import glob | |
10 | import fnmatch |
|
10 | import fnmatch | |
11 | import time, datetime |
|
11 | import time, datetime | |
12 |
|
12 | |||
13 | path = os.path.split(os.getcwd())[0] |
|
13 | path = os.path.split(os.getcwd())[0] | |
14 | sys.path.append(path) |
|
14 | sys.path.append(path) | |
15 |
|
15 | |||
16 | from JROHeaderIO import * |
|
16 | from JROHeaderIO import * | |
17 | from JRODataIO import JRODataReader |
|
17 | from JRODataIO import JRODataReader | |
18 | from JRODataIO import JRODataWriter |
|
18 | from JRODataIO import JRODataWriter | |
19 |
|
19 | |||
20 | from Data.JROData import Spectra |
|
20 | from Data.JROData import Spectra | |
21 |
|
21 | |||
22 | class SpectraReader(JRODataReader): |
|
22 | class SpectraReader(JRODataReader): | |
23 | """ |
|
23 | """ | |
24 | Esta clase permite leer datos de espectros desde archivos procesados (.pdata). La lectura |
|
24 | Esta clase permite leer datos de espectros desde archivos procesados (.pdata). La lectura | |
25 | de los datos siempre se realiza por bloques. Los datos leidos (array de 3 dimensiones) |
|
25 | de los datos siempre se realiza por bloques. Los datos leidos (array de 3 dimensiones) | |
26 | son almacenados en tres buffer's para el Self Spectra, el Cross Spectra y el DC Channel. |
|
26 | son almacenados en tres buffer's para el Self Spectra, el Cross Spectra y el DC Channel. | |
27 |
|
27 | |||
28 | paresCanalesIguales * alturas * perfiles (Self Spectra) |
|
28 | paresCanalesIguales * alturas * perfiles (Self Spectra) | |
29 | paresCanalesDiferentes * alturas * perfiles (Cross Spectra) |
|
29 | paresCanalesDiferentes * alturas * perfiles (Cross Spectra) | |
30 | canales * alturas (DC Channels) |
|
30 | canales * alturas (DC Channels) | |
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 Spectra. Los tres primeros se usan para almacenar informacion de la |
|
33 | RadarControllerHeader y Spectra. Los tres primeros se usan para almacenar informacion de la | |
34 | cabecera de datos (metadata), y el cuarto (Spectra) para obtener y almacenar un bloque de |
|
34 | cabecera de datos (metadata), y el cuarto (Spectra) para obtener y almacenar un bloque 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 | dpath = "/home/myuser/data" |
|
38 | dpath = "/home/myuser/data" | |
39 |
|
39 | |||
40 | startTime = datetime.datetime(2010,1,20,0,0,0,0,0,0) |
|
40 | startTime = datetime.datetime(2010,1,20,0,0,0,0,0,0) | |
41 |
|
41 | |||
42 | endTime = datetime.datetime(2010,1,21,23,59,59,0,0,0) |
|
42 | endTime = datetime.datetime(2010,1,21,23,59,59,0,0,0) | |
43 |
|
43 | |||
44 | readerObj = SpectraReader() |
|
44 | readerObj = SpectraReader() | |
45 |
|
45 | |||
46 | readerObj.setup(dpath, startTime, endTime) |
|
46 | readerObj.setup(dpath, startTime, endTime) | |
47 |
|
47 | |||
48 | while(True): |
|
48 | while(True): | |
49 |
|
49 | |||
50 | readerObj.getData() |
|
50 | readerObj.getData() | |
51 |
|
51 | |||
52 | print readerObj.data_spc |
|
52 | print readerObj.data_spc | |
53 |
|
53 | |||
54 | print readerObj.data_cspc |
|
54 | print readerObj.data_cspc | |
55 |
|
55 | |||
56 | print readerObj.data_dc |
|
56 | print readerObj.data_dc | |
57 |
|
57 | |||
58 | if readerObj.flagNoMoreFiles: |
|
58 | if readerObj.flagNoMoreFiles: | |
59 | break |
|
59 | break | |
60 |
|
60 | |||
61 | """ |
|
61 | """ | |
62 |
|
62 | |||
63 | pts2read_SelfSpectra = 0 |
|
63 | pts2read_SelfSpectra = 0 | |
64 |
|
64 | |||
65 | pts2read_CrossSpectra = 0 |
|
65 | pts2read_CrossSpectra = 0 | |
66 |
|
66 | |||
67 | pts2read_DCchannels = 0 |
|
67 | pts2read_DCchannels = 0 | |
68 |
|
68 | |||
69 | ext = ".pdata" |
|
69 | ext = ".pdata" | |
70 |
|
70 | |||
71 | optchar = "P" |
|
71 | optchar = "P" | |
72 |
|
72 | |||
73 | dataOutObj = None |
|
73 | dataOutObj = None | |
74 |
|
74 | |||
75 | nRdChannels = None |
|
75 | nRdChannels = None | |
76 |
|
76 | |||
77 | nRdPairs = None |
|
77 | nRdPairs = None | |
78 |
|
78 | |||
79 | rdPairList = [] |
|
79 | rdPairList = [] | |
80 |
|
80 | |||
81 |
|
81 | |||
82 | def __init__(self, dataOutObj=None): |
|
82 | def __init__(self, dataOutObj=None): | |
83 | """ |
|
83 | """ | |
84 | Inicializador de la clase SpectraReader para la lectura de datos de espectros. |
|
84 | Inicializador de la clase SpectraReader para la lectura de datos de espectros. | |
85 |
|
85 | |||
86 | Inputs: |
|
86 | Inputs: | |
87 | dataOutObj : Objeto de la clase Spectra. Este objeto sera utilizado para |
|
87 | dataOutObj : Objeto de la clase Spectra. Este objeto sera utilizado para | |
88 | almacenar un perfil de datos cada vez que se haga un requerimiento |
|
88 | almacenar un perfil de datos cada vez que se haga un requerimiento | |
89 | (getData). El perfil sera obtenido a partir del buffer de datos, |
|
89 | (getData). El perfil sera obtenido a partir del buffer de datos, | |
90 | si el buffer esta vacio se hara un nuevo proceso de lectura de un |
|
90 | si el buffer esta vacio se hara un nuevo proceso de lectura de un | |
91 | bloque de datos. |
|
91 | bloque de datos. | |
92 | Si este parametro no es pasado se creara uno internamente. |
|
92 | Si este parametro no es pasado se creara uno internamente. | |
93 |
|
93 | |||
94 | Affected: |
|
94 | Affected: | |
95 | self.dataOutObj |
|
95 | self.dataOutObj | |
96 |
|
96 | |||
97 | Return : None |
|
97 | Return : None | |
98 | """ |
|
98 | """ | |
99 |
|
99 | |||
100 | self.pts2read_SelfSpectra = 0 |
|
100 | self.pts2read_SelfSpectra = 0 | |
101 |
|
101 | |||
102 | self.pts2read_CrossSpectra = 0 |
|
102 | self.pts2read_CrossSpectra = 0 | |
103 |
|
103 | |||
104 | self.pts2read_DCchannels = 0 |
|
104 | self.pts2read_DCchannels = 0 | |
105 |
|
105 | |||
106 | self.datablock = None |
|
106 | self.datablock = None | |
107 |
|
107 | |||
108 | self.utc = None |
|
108 | self.utc = None | |
109 |
|
109 | |||
110 | self.ext = ".pdata" |
|
110 | self.ext = ".pdata" | |
111 |
|
111 | |||
112 | self.optchar = "P" |
|
112 | self.optchar = "P" | |
113 |
|
113 | |||
114 | self.basicHeaderObj = BasicHeader() |
|
114 | self.basicHeaderObj = BasicHeader() | |
115 |
|
115 | |||
116 | self.systemHeaderObj = SystemHeader() |
|
116 | self.systemHeaderObj = SystemHeader() | |
117 |
|
117 | |||
118 | self.radarControllerHeaderObj = RadarControllerHeader() |
|
118 | self.radarControllerHeaderObj = RadarControllerHeader() | |
119 |
|
119 | |||
120 | self.processingHeaderObj = ProcessingHeader() |
|
120 | self.processingHeaderObj = ProcessingHeader() | |
121 |
|
121 | |||
122 | self.online = 0 |
|
122 | self.online = 0 | |
123 |
|
123 | |||
124 | self.fp = None |
|
124 | self.fp = None | |
125 |
|
125 | |||
126 | self.idFile = None |
|
126 | self.idFile = None | |
127 |
|
127 | |||
128 | self.dtype = None |
|
128 | self.dtype = None | |
129 |
|
129 | |||
130 | self.fileSizeByHeader = None |
|
130 | self.fileSizeByHeader = None | |
131 |
|
131 | |||
132 | self.filenameList = [] |
|
132 | self.filenameList = [] | |
133 |
|
133 | |||
134 | self.filename = None |
|
134 | self.filename = None | |
135 |
|
135 | |||
136 | self.fileSize = None |
|
136 | self.fileSize = None | |
137 |
|
137 | |||
138 | self.firstHeaderSize = 0 |
|
138 | self.firstHeaderSize = 0 | |
139 |
|
139 | |||
140 | self.basicHeaderSize = 24 |
|
140 | self.basicHeaderSize = 24 | |
141 |
|
141 | |||
142 | self.pathList = [] |
|
142 | self.pathList = [] | |
143 |
|
143 | |||
144 | self.lastUTTime = 0 |
|
144 | self.lastUTTime = 0 | |
145 |
|
145 | |||
146 | self.maxTimeStep = 30 |
|
146 | self.maxTimeStep = 30 | |
147 |
|
147 | |||
148 | self.flagNoMoreFiles = 0 |
|
148 | self.flagNoMoreFiles = 0 | |
149 |
|
149 | |||
150 | self.set = 0 |
|
150 | self.set = 0 | |
151 |
|
151 | |||
152 | self.path = None |
|
152 | self.path = None | |
153 |
|
153 | |||
154 | self.delay = 3 #seconds |
|
154 | self.delay = 3 #seconds | |
155 |
|
155 | |||
156 | self.nTries = 3 #quantity tries |
|
156 | self.nTries = 3 #quantity tries | |
157 |
|
157 | |||
158 | self.nFiles = 3 #number of files for searching |
|
158 | self.nFiles = 3 #number of files for searching | |
159 |
|
159 | |||
160 | self.nReadBlocks = 0 |
|
160 | self.nReadBlocks = 0 | |
161 |
|
161 | |||
162 | self.flagIsNewFile = 1 |
|
162 | self.flagIsNewFile = 1 | |
163 |
|
163 | |||
164 | self.ippSeconds = 0 |
|
164 | self.ippSeconds = 0 | |
165 |
|
165 | |||
166 | self.flagTimeBlock = 0 |
|
166 | self.flagTimeBlock = 0 | |
167 |
|
167 | |||
168 | self.flagIsNewBlock = 0 |
|
168 | self.flagIsNewBlock = 0 | |
169 |
|
169 | |||
170 | self.nTotalBlocks = 0 |
|
170 | self.nTotalBlocks = 0 | |
171 |
|
171 | |||
172 | self.blocksize = 0 |
|
172 | self.blocksize = 0 | |
173 |
|
173 | |||
174 |
|
174 | |||
175 | def createObjByDefault(self): |
|
175 | def createObjByDefault(self): | |
176 |
|
176 | |||
177 | dataObj = Spectra() |
|
177 | dataObj = Spectra() | |
178 |
|
178 | |||
179 | return dataObj |
|
179 | return dataObj | |
180 |
|
180 | |||
181 | def __hasNotDataInBuffer(self): |
|
181 | def __hasNotDataInBuffer(self): | |
182 | return 1 |
|
182 | return 1 | |
183 |
|
183 | |||
184 |
|
184 | |||
185 | def getBlockDimension(self): |
|
185 | def getBlockDimension(self): | |
186 | """ |
|
186 | """ | |
187 | Obtiene la cantidad de puntos a leer por cada bloque de datos |
|
187 | Obtiene la cantidad de puntos a leer por cada bloque de datos | |
188 |
|
188 | |||
189 | Affected: |
|
189 | Affected: | |
190 | self.nRdChannels |
|
190 | self.nRdChannels | |
191 | self.nRdPairs |
|
191 | self.nRdPairs | |
192 | self.pts2read_SelfSpectra |
|
192 | self.pts2read_SelfSpectra | |
193 | self.pts2read_CrossSpectra |
|
193 | self.pts2read_CrossSpectra | |
194 | self.pts2read_DCchannels |
|
194 | self.pts2read_DCchannels | |
195 | self.blocksize |
|
195 | self.blocksize | |
196 | self.dataOutObj.nChannels |
|
196 | self.dataOutObj.nChannels | |
197 | self.dataOutObj.nPairs |
|
197 | self.dataOutObj.nPairs | |
198 |
|
198 | |||
199 | Return: |
|
199 | Return: | |
200 | None |
|
200 | None | |
201 | """ |
|
201 | """ | |
202 | self.nRdChannels = 0 |
|
202 | self.nRdChannels = 0 | |
203 | self.nRdPairs = 0 |
|
203 | self.nRdPairs = 0 | |
204 | self.rdPairList = [] |
|
204 | self.rdPairList = [] | |
205 |
|
205 | |||
206 | for i in range(0, self.processingHeaderObj.totalSpectra*2, 2): |
|
206 | for i in range(0, self.processingHeaderObj.totalSpectra*2, 2): | |
207 | if self.processingHeaderObj.spectraComb[i] == self.processingHeaderObj.spectraComb[i+1]: |
|
207 | if self.processingHeaderObj.spectraComb[i] == self.processingHeaderObj.spectraComb[i+1]: | |
208 | self.nRdChannels = self.nRdChannels + 1 #par de canales iguales |
|
208 | self.nRdChannels = self.nRdChannels + 1 #par de canales iguales | |
209 | else: |
|
209 | else: | |
210 | self.nRdPairs = self.nRdPairs + 1 #par de canales diferentes |
|
210 | self.nRdPairs = self.nRdPairs + 1 #par de canales diferentes | |
211 | self.rdPairList.append((self.processingHeaderObj.spectraComb[i], self.processingHeaderObj.spectraComb[i+1])) |
|
211 | self.rdPairList.append((self.processingHeaderObj.spectraComb[i], self.processingHeaderObj.spectraComb[i+1])) | |
212 |
|
212 | |||
213 | pts2read = self.processingHeaderObj.nHeights * self.processingHeaderObj.profilesPerBlock |
|
213 | pts2read = self.processingHeaderObj.nHeights * self.processingHeaderObj.profilesPerBlock | |
214 |
|
214 | |||
215 | self.pts2read_SelfSpectra = int(self.nRdChannels * pts2read) |
|
215 | self.pts2read_SelfSpectra = int(self.nRdChannels * pts2read) | |
216 | self.blocksize = self.pts2read_SelfSpectra |
|
216 | self.blocksize = self.pts2read_SelfSpectra | |
217 |
|
217 | |||
218 | if self.processingHeaderObj.flag_cspc: |
|
218 | if self.processingHeaderObj.flag_cspc: | |
219 | self.pts2read_CrossSpectra = int(self.nRdPairs * pts2read) |
|
219 | self.pts2read_CrossSpectra = int(self.nRdPairs * pts2read) | |
220 | self.blocksize += self.pts2read_CrossSpectra |
|
220 | self.blocksize += self.pts2read_CrossSpectra | |
221 |
|
221 | |||
222 | if self.processingHeaderObj.flag_dc: |
|
222 | if self.processingHeaderObj.flag_dc: | |
223 | self.pts2read_DCchannels = int(self.systemHeaderObj.nChannels * self.processingHeaderObj.nHeights) |
|
223 | self.pts2read_DCchannels = int(self.systemHeaderObj.nChannels * self.processingHeaderObj.nHeights) | |
224 | self.blocksize += self.pts2read_DCchannels |
|
224 | self.blocksize += self.pts2read_DCchannels | |
225 |
|
225 | |||
226 | # self.blocksize = self.pts2read_SelfSpectra + self.pts2read_CrossSpectra + self.pts2read_DCchannels |
|
226 | # self.blocksize = self.pts2read_SelfSpectra + self.pts2read_CrossSpectra + self.pts2read_DCchannels | |
227 |
|
227 | |||
228 |
|
228 | |||
229 | def readBlock(self): |
|
229 | def readBlock(self): | |
230 | """ |
|
230 | """ | |
231 | Lee el bloque de datos desde la posicion actual del puntero del archivo |
|
231 | Lee el bloque de datos desde la posicion actual del puntero del archivo | |
232 | (self.fp) y actualiza todos los parametros relacionados al bloque de datos |
|
232 | (self.fp) y actualiza todos los parametros relacionados al bloque de datos | |
233 | (metadata + data). La data leida es almacenada en el buffer y el contador del buffer |
|
233 | (metadata + data). La data leida es almacenada en el buffer y el contador del buffer | |
234 | es seteado a 0 |
|
234 | es seteado a 0 | |
235 |
|
235 | |||
236 | Return: None |
|
236 | Return: None | |
237 |
|
237 | |||
238 | Variables afectadas: |
|
238 | Variables afectadas: | |
239 |
|
239 | |||
240 | self.flagIsNewFile |
|
240 | self.flagIsNewFile | |
241 | self.flagIsNewBlock |
|
241 | self.flagIsNewBlock | |
242 | self.nTotalBlocks |
|
242 | self.nTotalBlocks | |
243 | self.data_spc |
|
243 | self.data_spc | |
244 | self.data_cspc |
|
244 | self.data_cspc | |
245 | self.data_dc |
|
245 | self.data_dc | |
246 |
|
246 | |||
247 | Exceptions: |
|
247 | Exceptions: | |
248 | Si un bloque leido no es un bloque valido |
|
248 | Si un bloque leido no es un bloque valido | |
249 | """ |
|
249 | """ | |
250 | blockOk_flag = False |
|
250 | blockOk_flag = False | |
251 | fpointer = self.fp.tell() |
|
251 | fpointer = self.fp.tell() | |
252 |
|
252 | |||
253 | spc = numpy.fromfile( self.fp, self.dtype[0], self.pts2read_SelfSpectra ) |
|
253 | spc = numpy.fromfile( self.fp, self.dtype[0], self.pts2read_SelfSpectra ) | |
254 | spc = spc.reshape( (self.nRdChannels, self.processingHeaderObj.nHeights, self.processingHeaderObj.profilesPerBlock) ) #transforma a un arreglo 3D |
|
254 | spc = spc.reshape( (self.nRdChannels, self.processingHeaderObj.nHeights, self.processingHeaderObj.profilesPerBlock) ) #transforma a un arreglo 3D | |
255 |
|
255 | |||
256 | if self.processingHeaderObj.flag_cspc: |
|
256 | if self.processingHeaderObj.flag_cspc: | |
257 | cspc = numpy.fromfile( self.fp, self.dtype, self.pts2read_CrossSpectra ) |
|
257 | cspc = numpy.fromfile( self.fp, self.dtype, self.pts2read_CrossSpectra ) | |
258 | cspc = cspc.reshape( (self.nRdPairs, self.processingHeaderObj.nHeights, self.processingHeaderObj.profilesPerBlock) ) #transforma a un arreglo 3D |
|
258 | cspc = cspc.reshape( (self.nRdPairs, self.processingHeaderObj.nHeights, self.processingHeaderObj.profilesPerBlock) ) #transforma a un arreglo 3D | |
259 |
|
259 | |||
260 | if self.processingHeaderObj.flag_dc: |
|
260 | if self.processingHeaderObj.flag_dc: | |
261 | dc = numpy.fromfile( self.fp, self.dtype, self.pts2read_DCchannels ) #int(self.processingHeaderObj.nHeights*self.systemHeaderObj.nChannels) ) |
|
261 | dc = numpy.fromfile( self.fp, self.dtype, self.pts2read_DCchannels ) #int(self.processingHeaderObj.nHeights*self.systemHeaderObj.nChannels) ) | |
262 | dc = dc.reshape( (self.systemHeaderObj.nChannels, self.processingHeaderObj.nHeights) ) #transforma a un arreglo 2D |
|
262 | dc = dc.reshape( (self.systemHeaderObj.nChannels, self.processingHeaderObj.nHeights) ) #transforma a un arreglo 2D | |
263 |
|
263 | |||
264 |
|
264 | |||
265 | if not(self.processingHeaderObj.shif_fft): |
|
265 | if not(self.processingHeaderObj.shif_fft): | |
266 | spc = numpy.roll( spc, self.processingHeaderObj.profilesPerBlock/2, axis=2 ) #desplaza a la derecha en el eje 2 determinadas posiciones |
|
266 | spc = numpy.roll( spc, self.processingHeaderObj.profilesPerBlock/2, axis=2 ) #desplaza a la derecha en el eje 2 determinadas posiciones | |
267 |
|
267 | |||
268 | if self.processingHeaderObj.flag_cspc: |
|
268 | if self.processingHeaderObj.flag_cspc: | |
269 | cspc = numpy.roll( cspc, self.processingHeaderObj.profilesPerBlock/2, axis=2 ) #desplaza a la derecha en el eje 2 determinadas posiciones |
|
269 | cspc = numpy.roll( cspc, self.processingHeaderObj.profilesPerBlock/2, axis=2 ) #desplaza a la derecha en el eje 2 determinadas posiciones | |
270 |
|
270 | |||
271 |
|
271 | |||
272 | spc = numpy.transpose( spc, (0,2,1) ) |
|
272 | spc = numpy.transpose( spc, (0,2,1) ) | |
273 | self.data_spc = spc |
|
273 | self.data_spc = spc | |
274 |
|
274 | |||
275 | if self.processingHeaderObj.flag_cspc: |
|
275 | if self.processingHeaderObj.flag_cspc: | |
276 | cspc = numpy.transpose( cspc, (0,2,1) ) |
|
276 | cspc = numpy.transpose( cspc, (0,2,1) ) | |
277 | self.data_cspc = cspc['real'] + cspc['imag']*1j |
|
277 | self.data_cspc = cspc['real'] + cspc['imag']*1j | |
278 | else: |
|
278 | else: | |
279 | self.data_cspc = None |
|
279 | self.data_cspc = None | |
280 |
|
280 | |||
281 | if self.processingHeaderObj.flag_dc: |
|
281 | if self.processingHeaderObj.flag_dc: | |
282 | self.data_dc = dc['real'] + dc['imag']*1j |
|
282 | self.data_dc = dc['real'] + dc['imag']*1j | |
283 | else: |
|
283 | else: | |
284 | self.data_dc = None |
|
284 | self.data_dc = None | |
285 |
|
285 | |||
286 | self.flagIsNewFile = 0 |
|
286 | self.flagIsNewFile = 0 | |
287 | self.flagIsNewBlock = 1 |
|
287 | self.flagIsNewBlock = 1 | |
288 |
|
288 | |||
289 | self.nTotalBlocks += 1 |
|
289 | self.nTotalBlocks += 1 | |
290 | self.nReadBlocks += 1 |
|
290 | self.nReadBlocks += 1 | |
291 |
|
291 | |||
292 | return 1 |
|
292 | return 1 | |
293 |
|
293 | |||
294 |
|
294 | |||
295 | def getData(self): |
|
295 | def getData(self): | |
296 | """ |
|
296 | """ | |
297 | Copia el buffer de lectura a la clase "Spectra", |
|
297 | Copia el buffer de lectura a la clase "Spectra", | |
298 | con todos los parametros asociados a este (metadata). cuando no hay datos en el buffer de |
|
298 | con todos los parametros asociados a este (metadata). cuando no hay datos en el buffer de | |
299 | lectura es necesario hacer una nueva lectura de los bloques de datos usando "readNextBlock" |
|
299 | lectura es necesario hacer una nueva lectura de los bloques de datos usando "readNextBlock" | |
300 |
|
300 | |||
301 | Return: |
|
301 | Return: | |
302 | 0 : Si no hay mas archivos disponibles |
|
302 | 0 : Si no hay mas archivos disponibles | |
303 | 1 : Si hizo una buena copia del buffer |
|
303 | 1 : Si hizo una buena copia del buffer | |
304 |
|
304 | |||
305 | Affected: |
|
305 | Affected: | |
306 | self.dataOutObj |
|
306 | self.dataOutObj | |
307 |
|
307 | |||
308 | self.flagTimeBlock |
|
308 | self.flagTimeBlock | |
309 | self.flagIsNewBlock |
|
309 | self.flagIsNewBlock | |
310 | """ |
|
310 | """ | |
311 |
|
311 | |||
312 | if self.flagNoMoreFiles: return 0 |
|
312 | if self.flagNoMoreFiles: return 0 | |
313 |
|
313 | |||
314 | self.flagTimeBlock = 0 |
|
314 | self.flagTimeBlock = 0 | |
315 | self.flagIsNewBlock = 0 |
|
315 | self.flagIsNewBlock = 0 | |
316 |
|
316 | |||
317 | if self.__hasNotDataInBuffer(): |
|
317 | if self.__hasNotDataInBuffer(): | |
318 |
|
318 | |||
319 | if not( self.readNextBlock() ): |
|
319 | if not( self.readNextBlock() ): | |
320 | return 0 |
|
320 | return 0 | |
321 |
|
321 | |||
322 | # self.updateDataHeader() |
|
322 | # self.updateDataHeader() | |
323 |
|
323 | |||
324 | if self.flagNoMoreFiles == 1: |
|
324 | if self.flagNoMoreFiles == 1: | |
325 | print 'Process finished' |
|
325 | print 'Process finished' | |
326 | return 0 |
|
326 | return 0 | |
327 |
|
327 | |||
328 | #data es un numpy array de 3 dmensiones (perfiles, alturas y canales) |
|
328 | #data es un numpy array de 3 dmensiones (perfiles, alturas y canales) | |
329 |
|
329 | |||
330 | if self.data_dc == None: |
|
330 | if self.data_dc == None: | |
331 | self.dataOutObj.flagNoData = True |
|
331 | self.dataOutObj.flagNoData = True | |
332 | return 0 |
|
332 | return 0 | |
333 |
|
333 | |||
334 |
|
334 | |||
335 | self.dataOutObj.data_spc = self.data_spc |
|
335 | self.dataOutObj.data_spc = self.data_spc | |
336 |
|
336 | |||
337 | self.dataOutObj.data_cspc = self.data_cspc |
|
337 | self.dataOutObj.data_cspc = self.data_cspc | |
338 |
|
338 | |||
339 | self.dataOutObj.data_dc = self.data_dc |
|
339 | self.dataOutObj.data_dc = self.data_dc | |
340 |
|
340 | |||
341 | self.dataOutObj.flagTimeBlock = self.flagTimeBlock |
|
341 | self.dataOutObj.flagTimeBlock = self.flagTimeBlock | |
342 |
|
342 | |||
343 | self.dataOutObj.flagNoData = False |
|
343 | self.dataOutObj.flagNoData = False | |
344 |
|
344 | |||
345 | self.dataOutObj.dtype = self.dtype |
|
345 | self.dataOutObj.dtype = self.dtype | |
346 |
|
346 | |||
347 | self.dataOutObj.nChannels = self.nRdChannels |
|
347 | self.dataOutObj.nChannels = self.nRdChannels | |
348 |
|
348 | |||
349 | self.dataOutObj.nPairs = self.nRdPairs |
|
349 | self.dataOutObj.nPairs = self.nRdPairs | |
350 |
|
350 | |||
351 | self.dataOutObj.pairsList = self.rdPairList |
|
351 | self.dataOutObj.pairsList = self.rdPairList | |
352 |
|
352 | |||
353 | self.dataOutObj.nHeights = self.processingHeaderObj.nHeights |
|
353 | self.dataOutObj.nHeights = self.processingHeaderObj.nHeights | |
354 |
|
354 | |||
355 | self.dataOutObj.nProfiles = self.processingHeaderObj.profilesPerBlock |
|
355 | self.dataOutObj.nProfiles = self.processingHeaderObj.profilesPerBlock | |
356 |
|
356 | |||
357 | self.dataOutObj.nFFTPoints = self.processingHeaderObj.profilesPerBlock |
|
357 | self.dataOutObj.nFFTPoints = self.processingHeaderObj.profilesPerBlock | |
358 |
|
358 | |||
359 | self.dataOutObj.nIncohInt = self.processingHeaderObj.nIncohInt |
|
359 | self.dataOutObj.nIncohInt = self.processingHeaderObj.nIncohInt | |
360 |
|
360 | |||
361 |
|
361 | |||
362 | xf = self.processingHeaderObj.firstHeight + self.processingHeaderObj.nHeights*self.processingHeaderObj.deltaHeight |
|
362 | xf = self.processingHeaderObj.firstHeight + self.processingHeaderObj.nHeights*self.processingHeaderObj.deltaHeight | |
363 |
|
363 | |||
364 | self.dataOutObj.heightList = numpy.arange(self.processingHeaderObj.firstHeight, xf, self.processingHeaderObj.deltaHeight) |
|
364 | self.dataOutObj.heightList = numpy.arange(self.processingHeaderObj.firstHeight, xf, self.processingHeaderObj.deltaHeight) | |
365 |
|
365 | |||
366 | self.dataOutObj.channelList = range(self.systemHeaderObj.nChannels) |
|
366 | self.dataOutObj.channelList = range(self.systemHeaderObj.nChannels) | |
367 |
|
367 | |||
368 | self.dataOutObj.channelIndexList = range(self.systemHeaderObj.nChannels) |
|
368 | self.dataOutObj.channelIndexList = range(self.systemHeaderObj.nChannels) | |
369 |
|
369 | |||
370 | self.dataOutObj.utctime = self.basicHeaderObj.utc + self.basicHeaderObj.miliSecond/1000.#+ self.profileIndex * self.ippSeconds |
|
370 | self.dataOutObj.utctime = self.basicHeaderObj.utc + self.basicHeaderObj.miliSecond/1000.#+ self.profileIndex * self.ippSeconds | |
371 |
|
371 | |||
|
372 | self.dataOutObj.ippSeconds = self.ippSeconds | |||
|
373 | ||||
|
374 | self.dataOutObj.timeInterval = self.ippSeconds * self.processingHeaderObj.nCohInt * self.processingHeaderObj.nIncohInt * self.dataOutObj.nFFTPoints | |||
|
375 | ||||
372 | self.dataOutObj.flagShiftFFT = self.processingHeaderObj.shif_fft |
|
376 | self.dataOutObj.flagShiftFFT = self.processingHeaderObj.shif_fft | |
373 |
|
377 | |||
374 | # self.profileIndex += 1 |
|
378 | # self.profileIndex += 1 | |
375 |
|
379 | |||
376 | self.dataOutObj.systemHeaderObj = self.systemHeaderObj.copy() |
|
380 | self.dataOutObj.systemHeaderObj = self.systemHeaderObj.copy() | |
377 |
|
381 | |||
378 | self.dataOutObj.radarControllerHeaderObj = self.radarControllerHeaderObj.copy() |
|
382 | self.dataOutObj.radarControllerHeaderObj = self.radarControllerHeaderObj.copy() | |
379 |
|
383 | |||
380 | return self.dataOutObj.data_spc |
|
384 | return self.dataOutObj.data_spc | |
381 |
|
385 | |||
382 |
|
386 | |||
383 | class SpectraWriter(JRODataWriter): |
|
387 | class SpectraWriter(JRODataWriter): | |
384 |
|
388 | |||
385 | """ |
|
389 | """ | |
386 | Esta clase permite escribir datos de espectros a archivos procesados (.pdata). La escritura |
|
390 | Esta clase permite escribir datos de espectros a archivos procesados (.pdata). La escritura | |
387 | de los datos siempre se realiza por bloques. |
|
391 | de los datos siempre se realiza por bloques. | |
388 | """ |
|
392 | """ | |
389 |
|
393 | |||
390 | ext = ".pdata" |
|
394 | ext = ".pdata" | |
391 |
|
395 | |||
392 | optchar = "P" |
|
396 | optchar = "P" | |
393 |
|
397 | |||
394 | shape_spc_Buffer = None |
|
398 | shape_spc_Buffer = None | |
395 |
|
399 | |||
396 | shape_cspc_Buffer = None |
|
400 | shape_cspc_Buffer = None | |
397 |
|
401 | |||
398 | shape_dc_Buffer = None |
|
402 | shape_dc_Buffer = None | |
399 |
|
403 | |||
400 | data_spc = None |
|
404 | data_spc = None | |
401 |
|
405 | |||
402 | data_cspc = None |
|
406 | data_cspc = None | |
403 |
|
407 | |||
404 | data_dc = None |
|
408 | data_dc = None | |
405 |
|
409 | |||
406 | wrPairList = [] |
|
410 | wrPairList = [] | |
407 |
|
411 | |||
408 | nWrPairs = 0 |
|
412 | nWrPairs = 0 | |
409 |
|
413 | |||
410 | nWrChannels = 0 |
|
414 | nWrChannels = 0 | |
411 |
|
415 | |||
412 | # dataOutObj = None |
|
416 | # dataOutObj = None | |
413 |
|
417 | |||
414 | def __init__(self, dataOutObj=None): |
|
418 | def __init__(self, dataOutObj=None): | |
415 | """ |
|
419 | """ | |
416 | Inicializador de la clase SpectraWriter para la escritura de datos de espectros. |
|
420 | Inicializador de la clase SpectraWriter para la escritura de datos de espectros. | |
417 |
|
421 | |||
418 | Affected: |
|
422 | Affected: | |
419 | self.dataOutObj |
|
423 | self.dataOutObj | |
420 | self.basicHeaderObj |
|
424 | self.basicHeaderObj | |
421 | self.systemHeaderObj |
|
425 | self.systemHeaderObj | |
422 | self.radarControllerHeaderObj |
|
426 | self.radarControllerHeaderObj | |
423 | self.processingHeaderObj |
|
427 | self.processingHeaderObj | |
424 |
|
428 | |||
425 | Return: None |
|
429 | Return: None | |
426 | """ |
|
430 | """ | |
427 | if dataOutObj == None: |
|
431 | if dataOutObj == None: | |
428 | dataOutObj = Spectra() |
|
432 | dataOutObj = Spectra() | |
429 |
|
433 | |||
430 | if not( isinstance(dataOutObj, Spectra) ): |
|
434 | if not( isinstance(dataOutObj, Spectra) ): | |
431 | raise ValueError, "in SpectraReader, dataOutObj must be an Spectra class object" |
|
435 | raise ValueError, "in SpectraReader, dataOutObj must be an Spectra class object" | |
432 |
|
436 | |||
433 | self.dataOutObj = dataOutObj |
|
437 | self.dataOutObj = dataOutObj | |
434 |
|
438 | |||
435 | self.nTotalBlocks = 0 |
|
439 | self.nTotalBlocks = 0 | |
436 |
|
440 | |||
437 | self.nWrChannels = self.dataOutObj.nChannels |
|
441 | self.nWrChannels = self.dataOutObj.nChannels | |
438 |
|
442 | |||
439 | # if len(pairList) > 0: |
|
443 | # if len(pairList) > 0: | |
440 | # self.wrPairList = pairList |
|
444 | # self.wrPairList = pairList | |
441 | # |
|
445 | # | |
442 | # self.nWrPairs = len(pairList) |
|
446 | # self.nWrPairs = len(pairList) | |
443 |
|
447 | |||
444 | self.wrPairList = self.dataOutObj.pairsList |
|
448 | self.wrPairList = self.dataOutObj.pairsList | |
445 |
|
449 | |||
446 | self.nWrPairs = self.dataOutObj.nPairs |
|
450 | self.nWrPairs = self.dataOutObj.nPairs | |
447 |
|
451 | |||
448 |
|
452 | |||
449 |
|
453 | |||
450 |
|
454 | |||
451 |
|
455 | |||
452 | # self.data_spc = None |
|
456 | # self.data_spc = None | |
453 | # self.data_cspc = None |
|
457 | # self.data_cspc = None | |
454 | # self.data_dc = None |
|
458 | # self.data_dc = None | |
455 |
|
459 | |||
456 | # self.fp = None |
|
460 | # self.fp = None | |
457 |
|
461 | |||
458 | # self.flagIsNewFile = 1 |
|
462 | # self.flagIsNewFile = 1 | |
459 | # |
|
463 | # | |
460 | # self.nTotalBlocks = 0 |
|
464 | # self.nTotalBlocks = 0 | |
461 | # |
|
465 | # | |
462 | # self.flagIsNewBlock = 0 |
|
466 | # self.flagIsNewBlock = 0 | |
463 | # |
|
467 | # | |
464 | # self.flagNoMoreFiles = 0 |
|
468 | # self.flagNoMoreFiles = 0 | |
465 | # |
|
469 | # | |
466 | # self.setFile = None |
|
470 | # self.setFile = None | |
467 | # |
|
471 | # | |
468 | # self.dtype = None |
|
472 | # self.dtype = None | |
469 | # |
|
473 | # | |
470 | # self.path = None |
|
474 | # self.path = None | |
471 | # |
|
475 | # | |
472 | # self.noMoreFiles = 0 |
|
476 | # self.noMoreFiles = 0 | |
473 | # |
|
477 | # | |
474 | # self.filename = None |
|
478 | # self.filename = None | |
475 | # |
|
479 | # | |
476 | # self.basicHeaderObj = BasicHeader() |
|
480 | # self.basicHeaderObj = BasicHeader() | |
477 | # |
|
481 | # | |
478 | # self.systemHeaderObj = SystemHeader() |
|
482 | # self.systemHeaderObj = SystemHeader() | |
479 | # |
|
483 | # | |
480 | # self.radarControllerHeaderObj = RadarControllerHeader() |
|
484 | # self.radarControllerHeaderObj = RadarControllerHeader() | |
481 | # |
|
485 | # | |
482 | # self.processingHeaderObj = ProcessingHeader() |
|
486 | # self.processingHeaderObj = ProcessingHeader() | |
483 |
|
487 | |||
484 |
|
488 | |||
485 | def hasAllDataInBuffer(self): |
|
489 | def hasAllDataInBuffer(self): | |
486 | return 1 |
|
490 | return 1 | |
487 |
|
491 | |||
488 |
|
492 | |||
489 | def setBlockDimension(self): |
|
493 | def setBlockDimension(self): | |
490 | """ |
|
494 | """ | |
491 | Obtiene las formas dimensionales del los subbloques de datos que componen un bloque |
|
495 | Obtiene las formas dimensionales del los subbloques de datos que componen un bloque | |
492 |
|
496 | |||
493 | Affected: |
|
497 | Affected: | |
494 | self.shape_spc_Buffer |
|
498 | self.shape_spc_Buffer | |
495 | self.shape_cspc_Buffer |
|
499 | self.shape_cspc_Buffer | |
496 | self.shape_dc_Buffer |
|
500 | self.shape_dc_Buffer | |
497 |
|
501 | |||
498 | Return: None |
|
502 | Return: None | |
499 | """ |
|
503 | """ | |
500 | self.shape_spc_Buffer = (self.dataOutObj.nChannels, |
|
504 | self.shape_spc_Buffer = (self.dataOutObj.nChannels, | |
501 | self.processingHeaderObj.nHeights, |
|
505 | self.processingHeaderObj.nHeights, | |
502 | self.processingHeaderObj.profilesPerBlock) |
|
506 | self.processingHeaderObj.profilesPerBlock) | |
503 |
|
507 | |||
504 | self.shape_cspc_Buffer = (self.dataOutObj.nPairs, |
|
508 | self.shape_cspc_Buffer = (self.dataOutObj.nPairs, | |
505 | self.processingHeaderObj.nHeights, |
|
509 | self.processingHeaderObj.nHeights, | |
506 | self.processingHeaderObj.profilesPerBlock) |
|
510 | self.processingHeaderObj.profilesPerBlock) | |
507 |
|
511 | |||
508 | self.shape_dc_Buffer = (self.dataOutObj.nChannels, |
|
512 | self.shape_dc_Buffer = (self.dataOutObj.nChannels, | |
509 | self.processingHeaderObj.nHeights) |
|
513 | self.processingHeaderObj.nHeights) | |
510 |
|
514 | |||
511 |
|
515 | |||
512 | def writeBlock(self): |
|
516 | def writeBlock(self): | |
513 | """ |
|
517 | """ | |
514 | Escribe el buffer en el file designado |
|
518 | Escribe el buffer en el file designado | |
515 |
|
519 | |||
516 | Affected: |
|
520 | Affected: | |
517 | self.data_spc |
|
521 | self.data_spc | |
518 | self.data_cspc |
|
522 | self.data_cspc | |
519 | self.data_dc |
|
523 | self.data_dc | |
520 | self.flagIsNewFile |
|
524 | self.flagIsNewFile | |
521 | self.flagIsNewBlock |
|
525 | self.flagIsNewBlock | |
522 | self.nTotalBlocks |
|
526 | self.nTotalBlocks | |
523 | self.nWriteBlocks |
|
527 | self.nWriteBlocks | |
524 |
|
528 | |||
525 | Return: None |
|
529 | Return: None | |
526 | """ |
|
530 | """ | |
527 |
|
531 | |||
528 | spc = numpy.transpose( self.data_spc, (0,2,1) ) |
|
532 | spc = numpy.transpose( self.data_spc, (0,2,1) ) | |
529 | if not( self.processingHeaderObj.shif_fft ): |
|
533 | if not( self.processingHeaderObj.shif_fft ): | |
530 | spc = numpy.roll( spc, self.processingHeaderObj.profilesPerBlock/2, axis=2 ) #desplaza a la derecha en el eje 2 determinadas posiciones |
|
534 | spc = numpy.roll( spc, self.processingHeaderObj.profilesPerBlock/2, axis=2 ) #desplaza a la derecha en el eje 2 determinadas posiciones | |
531 | data = spc.reshape((-1)) |
|
535 | data = spc.reshape((-1)) | |
532 | data.tofile(self.fp) |
|
536 | data.tofile(self.fp) | |
533 |
|
537 | |||
534 | if self.data_cspc != None: |
|
538 | if self.data_cspc != None: | |
535 | data = numpy.zeros( self.shape_cspc_Buffer, self.dtype ) |
|
539 | data = numpy.zeros( self.shape_cspc_Buffer, self.dtype ) | |
536 | cspc = numpy.transpose( self.data_cspc, (0,2,1) ) |
|
540 | cspc = numpy.transpose( self.data_cspc, (0,2,1) ) | |
537 | if not( self.processingHeaderObj.shif_fft ): |
|
541 | if not( self.processingHeaderObj.shif_fft ): | |
538 | cspc = numpy.roll( cspc, self.processingHeaderObj.profilesPerBlock/2, axis=2 ) #desplaza a la derecha en el eje 2 determinadas posiciones |
|
542 | cspc = numpy.roll( cspc, self.processingHeaderObj.profilesPerBlock/2, axis=2 ) #desplaza a la derecha en el eje 2 determinadas posiciones | |
539 | data['real'] = cspc.real |
|
543 | data['real'] = cspc.real | |
540 | data['imag'] = cspc.imag |
|
544 | data['imag'] = cspc.imag | |
541 | data = data.reshape((-1)) |
|
545 | data = data.reshape((-1)) | |
542 | data.tofile(self.fp) |
|
546 | data.tofile(self.fp) | |
543 |
|
547 | |||
544 | if self.data_dc != None: |
|
548 | if self.data_dc != None: | |
545 | data = numpy.zeros( self.shape_dc_Buffer, self.dtype ) |
|
549 | data = numpy.zeros( self.shape_dc_Buffer, self.dtype ) | |
546 | dc = self.data_dc |
|
550 | dc = self.data_dc | |
547 | data['real'] = dc.real |
|
551 | data['real'] = dc.real | |
548 | data['imag'] = dc.imag |
|
552 | data['imag'] = dc.imag | |
549 | data = data.reshape((-1)) |
|
553 | data = data.reshape((-1)) | |
550 | data.tofile(self.fp) |
|
554 | data.tofile(self.fp) | |
551 |
|
555 | |||
552 | self.data_spc.fill(0) |
|
556 | self.data_spc.fill(0) | |
553 | self.data_dc.fill(0) |
|
557 | self.data_dc.fill(0) | |
554 | if self.data_cspc != None: |
|
558 | if self.data_cspc != None: | |
555 | self.data_cspc.fill(0) |
|
559 | self.data_cspc.fill(0) | |
556 |
|
560 | |||
557 | self.flagIsNewFile = 0 |
|
561 | self.flagIsNewFile = 0 | |
558 | self.flagIsNewBlock = 1 |
|
562 | self.flagIsNewBlock = 1 | |
559 | self.nTotalBlocks += 1 |
|
563 | self.nTotalBlocks += 1 | |
560 | self.nWriteBlocks += 1 |
|
564 | self.nWriteBlocks += 1 | |
561 | self.blockIndex += 1 |
|
565 | self.blockIndex += 1 | |
562 |
|
566 | |||
563 |
|
567 | |||
564 | def putData(self): |
|
568 | def putData(self): | |
565 | """ |
|
569 | """ | |
566 | Setea un bloque de datos y luego los escribe en un file |
|
570 | Setea un bloque de datos y luego los escribe en un file | |
567 |
|
571 | |||
568 | Affected: |
|
572 | Affected: | |
569 | self.data_spc |
|
573 | self.data_spc | |
570 | self.data_cspc |
|
574 | self.data_cspc | |
571 | self.data_dc |
|
575 | self.data_dc | |
572 |
|
576 | |||
573 | Return: |
|
577 | Return: | |
574 | 0 : Si no hay data o no hay mas files que puedan escribirse |
|
578 | 0 : Si no hay data o no hay mas files que puedan escribirse | |
575 | 1 : Si se escribio la data de un bloque en un file |
|
579 | 1 : Si se escribio la data de un bloque en un file | |
576 | """ |
|
580 | """ | |
577 | self.flagIsNewBlock = 0 |
|
581 | self.flagIsNewBlock = 0 | |
578 |
|
582 | |||
579 | if self.dataOutObj.flagNoData: |
|
583 | if self.dataOutObj.flagNoData: | |
580 | return 0 |
|
584 | return 0 | |
581 |
|
585 | |||
582 | if self.dataOutObj.flagTimeBlock: |
|
586 | if self.dataOutObj.flagTimeBlock: | |
583 | self.data_spc.fill(0) |
|
587 | self.data_spc.fill(0) | |
584 | self.data_cspc.fill(0) |
|
588 | self.data_cspc.fill(0) | |
585 | self.data_dc.fill(0) |
|
589 | self.data_dc.fill(0) | |
586 | self.setNextFile() |
|
590 | self.setNextFile() | |
587 |
|
591 | |||
588 | if self.flagIsNewFile == 0: |
|
592 | if self.flagIsNewFile == 0: | |
589 | self.getBasicHeader() |
|
593 | self.getBasicHeader() | |
590 |
|
594 | |||
591 | self.data_spc = self.dataOutObj.data_spc |
|
595 | self.data_spc = self.dataOutObj.data_spc | |
592 | self.data_cspc = self.dataOutObj.data_cspc |
|
596 | self.data_cspc = self.dataOutObj.data_cspc | |
593 | self.data_dc = self.dataOutObj.data_dc |
|
597 | self.data_dc = self.dataOutObj.data_dc | |
594 |
|
598 | |||
595 | # #self.processingHeaderObj.dataBlocksPerFile) |
|
599 | # #self.processingHeaderObj.dataBlocksPerFile) | |
596 | if self.hasAllDataInBuffer(): |
|
600 | if self.hasAllDataInBuffer(): | |
597 | # self.getDataHeader() |
|
601 | # self.getDataHeader() | |
598 | self.writeNextBlock() |
|
602 | self.writeNextBlock() | |
599 |
|
603 | |||
600 | if self.flagNoMoreFiles: |
|
604 | if self.flagNoMoreFiles: | |
601 | #print 'Process finished' |
|
605 | #print 'Process finished' | |
602 | return 0 |
|
606 | return 0 | |
603 |
|
607 | |||
604 | return 1 |
|
608 | return 1 | |
605 |
|
609 | |||
606 |
|
610 | |||
607 | def __getProcessFlags(self): |
|
611 | def __getProcessFlags(self): | |
608 |
|
612 | |||
609 | processFlags = 0 |
|
613 | processFlags = 0 | |
610 |
|
614 | |||
611 | dtype0 = numpy.dtype([('real','<i1'),('imag','<i1')]) |
|
615 | dtype0 = numpy.dtype([('real','<i1'),('imag','<i1')]) | |
612 | dtype1 = numpy.dtype([('real','<i2'),('imag','<i2')]) |
|
616 | dtype1 = numpy.dtype([('real','<i2'),('imag','<i2')]) | |
613 | dtype2 = numpy.dtype([('real','<i4'),('imag','<i4')]) |
|
617 | dtype2 = numpy.dtype([('real','<i4'),('imag','<i4')]) | |
614 | dtype3 = numpy.dtype([('real','<i8'),('imag','<i8')]) |
|
618 | dtype3 = numpy.dtype([('real','<i8'),('imag','<i8')]) | |
615 | dtype4 = numpy.dtype([('real','<f4'),('imag','<f4')]) |
|
619 | dtype4 = numpy.dtype([('real','<f4'),('imag','<f4')]) | |
616 | dtype5 = numpy.dtype([('real','<f8'),('imag','<f8')]) |
|
620 | dtype5 = numpy.dtype([('real','<f8'),('imag','<f8')]) | |
617 |
|
621 | |||
618 | dtypeList = [dtype0, dtype1, dtype2, dtype3, dtype4, dtype5] |
|
622 | dtypeList = [dtype0, dtype1, dtype2, dtype3, dtype4, dtype5] | |
619 |
|
623 | |||
620 |
|
624 | |||
621 |
|
625 | |||
622 | datatypeValueList = [PROCFLAG.DATATYPE_CHAR, |
|
626 | datatypeValueList = [PROCFLAG.DATATYPE_CHAR, | |
623 | PROCFLAG.DATATYPE_SHORT, |
|
627 | PROCFLAG.DATATYPE_SHORT, | |
624 | PROCFLAG.DATATYPE_LONG, |
|
628 | PROCFLAG.DATATYPE_LONG, | |
625 | PROCFLAG.DATATYPE_INT64, |
|
629 | PROCFLAG.DATATYPE_INT64, | |
626 | PROCFLAG.DATATYPE_FLOAT, |
|
630 | PROCFLAG.DATATYPE_FLOAT, | |
627 | PROCFLAG.DATATYPE_DOUBLE] |
|
631 | PROCFLAG.DATATYPE_DOUBLE] | |
628 |
|
632 | |||
629 |
|
633 | |||
630 | for index in range(len(dtypeList)): |
|
634 | for index in range(len(dtypeList)): | |
631 | if self.dataOutObj.dtype == dtypeList[index]: |
|
635 | if self.dataOutObj.dtype == dtypeList[index]: | |
632 | dtypeValue = datatypeValueList[index] |
|
636 | dtypeValue = datatypeValueList[index] | |
633 | break |
|
637 | break | |
634 |
|
638 | |||
635 | processFlags += dtypeValue |
|
639 | processFlags += dtypeValue | |
636 |
|
640 | |||
637 | if self.dataOutObj.flagDecodeData: |
|
641 | if self.dataOutObj.flagDecodeData: | |
638 | processFlags += PROCFLAG.DECODE_DATA |
|
642 | processFlags += PROCFLAG.DECODE_DATA | |
639 |
|
643 | |||
640 | if self.dataOutObj.flagDeflipData: |
|
644 | if self.dataOutObj.flagDeflipData: | |
641 | processFlags += PROCFLAG.DEFLIP_DATA |
|
645 | processFlags += PROCFLAG.DEFLIP_DATA | |
642 |
|
646 | |||
643 | if self.dataOutObj.code != None: |
|
647 | if self.dataOutObj.code != None: | |
644 | processFlags += PROCFLAG.DEFINE_PROCESS_CODE |
|
648 | processFlags += PROCFLAG.DEFINE_PROCESS_CODE | |
645 |
|
649 | |||
646 | if self.dataOutObj.nIncohInt > 1: |
|
650 | if self.dataOutObj.nIncohInt > 1: | |
647 | processFlags += PROCFLAG.INCOHERENT_INTEGRATION |
|
651 | processFlags += PROCFLAG.INCOHERENT_INTEGRATION | |
648 |
|
652 | |||
649 | if self.dataOutObj.data_dc != None: |
|
653 | if self.dataOutObj.data_dc != None: | |
650 | processFlags += PROCFLAG.SAVE_CHANNELS_DC |
|
654 | processFlags += PROCFLAG.SAVE_CHANNELS_DC | |
651 |
|
655 | |||
652 | return processFlags |
|
656 | return processFlags | |
653 |
|
657 | |||
654 |
|
658 | |||
655 | def __getBlockSize(self): |
|
659 | def __getBlockSize(self): | |
656 | ''' |
|
660 | ''' | |
657 | Este metodos determina el cantidad de bytes para un bloque de datos de tipo Spectra |
|
661 | Este metodos determina el cantidad de bytes para un bloque de datos de tipo Spectra | |
658 | ''' |
|
662 | ''' | |
659 |
|
663 | |||
660 | dtype0 = numpy.dtype([('real','<i1'),('imag','<i1')]) |
|
664 | dtype0 = numpy.dtype([('real','<i1'),('imag','<i1')]) | |
661 | dtype1 = numpy.dtype([('real','<i2'),('imag','<i2')]) |
|
665 | dtype1 = numpy.dtype([('real','<i2'),('imag','<i2')]) | |
662 | dtype2 = numpy.dtype([('real','<i4'),('imag','<i4')]) |
|
666 | dtype2 = numpy.dtype([('real','<i4'),('imag','<i4')]) | |
663 | dtype3 = numpy.dtype([('real','<i8'),('imag','<i8')]) |
|
667 | dtype3 = numpy.dtype([('real','<i8'),('imag','<i8')]) | |
664 | dtype4 = numpy.dtype([('real','<f4'),('imag','<f4')]) |
|
668 | dtype4 = numpy.dtype([('real','<f4'),('imag','<f4')]) | |
665 | dtype5 = numpy.dtype([('real','<f8'),('imag','<f8')]) |
|
669 | dtype5 = numpy.dtype([('real','<f8'),('imag','<f8')]) | |
666 |
|
670 | |||
667 | dtypeList = [dtype0, dtype1, dtype2, dtype3, dtype4, dtype5] |
|
671 | dtypeList = [dtype0, dtype1, dtype2, dtype3, dtype4, dtype5] | |
668 | datatypeValueList = [1,2,4,8,4,8] |
|
672 | datatypeValueList = [1,2,4,8,4,8] | |
669 | for index in range(len(dtypeList)): |
|
673 | for index in range(len(dtypeList)): | |
670 | if self.dataOutObj.dtype == dtypeList[index]: |
|
674 | if self.dataOutObj.dtype == dtypeList[index]: | |
671 | datatypeValue = datatypeValueList[index] |
|
675 | datatypeValue = datatypeValueList[index] | |
672 | break |
|
676 | break | |
673 |
|
677 | |||
674 |
|
678 | |||
675 | pts2write = self.dataOutObj.nHeights * self.dataOutObj.nFFTPoints |
|
679 | pts2write = self.dataOutObj.nHeights * self.dataOutObj.nFFTPoints | |
676 |
|
680 | |||
677 | pts2write_SelfSpectra = int(self.nWrChannels * pts2write) |
|
681 | pts2write_SelfSpectra = int(self.nWrChannels * pts2write) | |
678 | blocksize = (pts2write_SelfSpectra*datatypeValue) |
|
682 | blocksize = (pts2write_SelfSpectra*datatypeValue) | |
679 |
|
683 | |||
680 | if self.dataOutObj.data_cspc != None: |
|
684 | if self.dataOutObj.data_cspc != None: | |
681 | pts2write_CrossSpectra = int(self.nWrPairs * pts2write) |
|
685 | pts2write_CrossSpectra = int(self.nWrPairs * pts2write) | |
682 | blocksize += (pts2write_CrossSpectra*datatypeValue*2) |
|
686 | blocksize += (pts2write_CrossSpectra*datatypeValue*2) | |
683 |
|
687 | |||
684 | if self.dataOutObj.data_dc != None: |
|
688 | if self.dataOutObj.data_dc != None: | |
685 | pts2write_DCchannels = int(self.nWrChannels * self.dataOutObj.nHeights) |
|
689 | pts2write_DCchannels = int(self.nWrChannels * self.dataOutObj.nHeights) | |
686 | blocksize += (pts2write_DCchannels*datatypeValue*2) |
|
690 | blocksize += (pts2write_DCchannels*datatypeValue*2) | |
687 |
|
691 | |||
688 | blocksize = blocksize #* datatypeValue * 2 #CORREGIR ESTO |
|
692 | blocksize = blocksize #* datatypeValue * 2 #CORREGIR ESTO | |
689 |
|
693 | |||
690 | return blocksize |
|
694 | return blocksize | |
691 |
|
695 | |||
692 |
|
696 | |||
693 | def getBasicHeader(self): |
|
697 | def getBasicHeader(self): | |
694 | self.basicHeaderObj.size = self.basicHeaderSize #bytes |
|
698 | self.basicHeaderObj.size = self.basicHeaderSize #bytes | |
695 | self.basicHeaderObj.version = self.versionFile |
|
699 | self.basicHeaderObj.version = self.versionFile | |
696 | self.basicHeaderObj.dataBlock = self.nTotalBlocks |
|
700 | self.basicHeaderObj.dataBlock = self.nTotalBlocks | |
697 |
|
701 | |||
698 | utc = numpy.floor(self.dataOutObj.utctime) |
|
702 | utc = numpy.floor(self.dataOutObj.utctime) | |
699 | milisecond = (self.dataOutObj.utctime - utc)* 1000.0 |
|
703 | milisecond = (self.dataOutObj.utctime - utc)* 1000.0 | |
700 |
|
704 | |||
701 | self.basicHeaderObj.utc = utc |
|
705 | self.basicHeaderObj.utc = utc | |
702 | self.basicHeaderObj.miliSecond = milisecond |
|
706 | self.basicHeaderObj.miliSecond = milisecond | |
703 | self.basicHeaderObj.timeZone = 0 |
|
707 | self.basicHeaderObj.timeZone = 0 | |
704 | self.basicHeaderObj.dstFlag = 0 |
|
708 | self.basicHeaderObj.dstFlag = 0 | |
705 | self.basicHeaderObj.errorCount = 0 |
|
709 | self.basicHeaderObj.errorCount = 0 | |
706 |
|
710 | |||
707 | def getDataHeader(self): |
|
711 | def getDataHeader(self): | |
708 |
|
712 | |||
709 | """ |
|
713 | """ | |
710 | Obtiene una copia del First Header |
|
714 | Obtiene una copia del First Header | |
711 |
|
715 | |||
712 | Affected: |
|
716 | Affected: | |
713 | self.systemHeaderObj |
|
717 | self.systemHeaderObj | |
714 | self.radarControllerHeaderObj |
|
718 | self.radarControllerHeaderObj | |
715 | self.dtype |
|
719 | self.dtype | |
716 |
|
720 | |||
717 | Return: |
|
721 | Return: | |
718 | None |
|
722 | None | |
719 | """ |
|
723 | """ | |
720 |
|
724 | |||
721 | self.systemHeaderObj = self.dataOutObj.systemHeaderObj.copy() |
|
725 | self.systemHeaderObj = self.dataOutObj.systemHeaderObj.copy() | |
722 | self.systemHeaderObj.nChannels = self.dataOutObj.nChannels |
|
726 | self.systemHeaderObj.nChannels = self.dataOutObj.nChannels | |
723 | self.radarControllerHeaderObj = self.dataOutObj.radarControllerHeaderObj.copy() |
|
727 | self.radarControllerHeaderObj = self.dataOutObj.radarControllerHeaderObj.copy() | |
724 |
|
728 | |||
725 | self.getBasicHeader() |
|
729 | self.getBasicHeader() | |
726 |
|
730 | |||
727 | processingHeaderSize = 40 # bytes |
|
731 | processingHeaderSize = 40 # bytes | |
728 | self.processingHeaderObj.dtype = 0 # Voltage |
|
732 | self.processingHeaderObj.dtype = 0 # Voltage | |
729 | self.processingHeaderObj.blockSize = self.__getBlockSize() |
|
733 | self.processingHeaderObj.blockSize = self.__getBlockSize() | |
730 | self.processingHeaderObj.profilesPerBlock = self.dataOutObj.nFFTPoints |
|
734 | self.processingHeaderObj.profilesPerBlock = self.dataOutObj.nFFTPoints | |
731 | self.processingHeaderObj.dataBlocksPerFile = self.blocksPerFile |
|
735 | self.processingHeaderObj.dataBlocksPerFile = self.blocksPerFile | |
732 | self.processingHeaderObj.nWindows = 1 #podria ser 1 o self.dataOutObj.processingHeaderObj.nWindows |
|
736 | self.processingHeaderObj.nWindows = 1 #podria ser 1 o self.dataOutObj.processingHeaderObj.nWindows | |
733 | self.processingHeaderObj.processFlags = self.__getProcessFlags() |
|
737 | self.processingHeaderObj.processFlags = self.__getProcessFlags() | |
734 | self.processingHeaderObj.nCohInt = 1# Cuando la data de origen es de tipo Spectra |
|
738 | self.processingHeaderObj.nCohInt = 1# Cuando la data de origen es de tipo Spectra | |
735 | self.processingHeaderObj.nIncohInt = self.dataOutObj.nIncohInt |
|
739 | self.processingHeaderObj.nIncohInt = self.dataOutObj.nIncohInt | |
736 | self.processingHeaderObj.totalSpectra = self.dataOutObj.nPairs + self.dataOutObj.nChannels |
|
740 | self.processingHeaderObj.totalSpectra = self.dataOutObj.nPairs + self.dataOutObj.nChannels | |
737 |
|
741 | |||
738 | if self.processingHeaderObj.totalSpectra > 0: |
|
742 | if self.processingHeaderObj.totalSpectra > 0: | |
739 | channelList = [] |
|
743 | channelList = [] | |
740 | for channel in range(self.dataOutObj.nChannels): |
|
744 | for channel in range(self.dataOutObj.nChannels): | |
741 | channelList.append(channel) |
|
745 | channelList.append(channel) | |
742 | channelList.append(channel) |
|
746 | channelList.append(channel) | |
743 |
|
747 | |||
744 | pairsList = [] |
|
748 | pairsList = [] | |
745 | for pair in self.dataOutObj.pairsList: |
|
749 | for pair in self.dataOutObj.pairsList: | |
746 | pairsList.append(pair[0]) |
|
750 | pairsList.append(pair[0]) | |
747 | pairsList.append(pair[1]) |
|
751 | pairsList.append(pair[1]) | |
748 | spectraComb = channelList + pairsList |
|
752 | spectraComb = channelList + pairsList | |
749 | spectraComb = numpy.array(spectraComb,dtype="u1") |
|
753 | spectraComb = numpy.array(spectraComb,dtype="u1") | |
750 | self.processingHeaderObj.spectraComb = spectraComb |
|
754 | self.processingHeaderObj.spectraComb = spectraComb | |
751 | sizeOfSpcComb = len(spectraComb) |
|
755 | sizeOfSpcComb = len(spectraComb) | |
752 | processingHeaderSize += sizeOfSpcComb |
|
756 | processingHeaderSize += sizeOfSpcComb | |
753 |
|
757 | |||
754 | if self.dataOutObj.code != None: |
|
758 | if self.dataOutObj.code != None: | |
755 | self.processingHeaderObj.code = self.dataOutObj.code |
|
759 | self.processingHeaderObj.code = self.dataOutObj.code | |
756 | self.processingHeaderObj.nCode = self.dataOutObj.nCode |
|
760 | self.processingHeaderObj.nCode = self.dataOutObj.nCode | |
757 | self.processingHeaderObj.nBaud = self.dataOutObj.nBaud |
|
761 | self.processingHeaderObj.nBaud = self.dataOutObj.nBaud | |
758 | nCodeSize = 4 # bytes |
|
762 | nCodeSize = 4 # bytes | |
759 | nBaudSize = 4 # bytes |
|
763 | nBaudSize = 4 # bytes | |
760 | codeSize = 4 # bytes |
|
764 | codeSize = 4 # bytes | |
761 | sizeOfCode = int(nCodeSize + nBaudSize + codeSize * self.dataOutObj.nCode * self.dataOutObj.nBaud) |
|
765 | sizeOfCode = int(nCodeSize + nBaudSize + codeSize * self.dataOutObj.nCode * self.dataOutObj.nBaud) | |
762 | processingHeaderSize += sizeOfCode |
|
766 | processingHeaderSize += sizeOfCode | |
763 |
|
767 | |||
764 | if self.processingHeaderObj.nWindows != 0: |
|
768 | if self.processingHeaderObj.nWindows != 0: | |
765 | self.processingHeaderObj.firstHeight = self.dataOutObj.heightList[0] |
|
769 | self.processingHeaderObj.firstHeight = self.dataOutObj.heightList[0] | |
766 | self.processingHeaderObj.deltaHeight = self.dataOutObj.heightList[1] - self.dataOutObj.heightList[0] |
|
770 | self.processingHeaderObj.deltaHeight = self.dataOutObj.heightList[1] - self.dataOutObj.heightList[0] | |
767 | self.processingHeaderObj.nHeights = self.dataOutObj.nHeights |
|
771 | self.processingHeaderObj.nHeights = self.dataOutObj.nHeights | |
768 | self.processingHeaderObj.samplesWin = self.dataOutObj.nHeights |
|
772 | self.processingHeaderObj.samplesWin = self.dataOutObj.nHeights | |
769 | sizeOfFirstHeight = 4 |
|
773 | sizeOfFirstHeight = 4 | |
770 | sizeOfdeltaHeight = 4 |
|
774 | sizeOfdeltaHeight = 4 | |
771 | sizeOfnHeights = 4 |
|
775 | sizeOfnHeights = 4 | |
772 | sizeOfWindows = (sizeOfFirstHeight + sizeOfdeltaHeight + sizeOfnHeights)*self.processingHeaderObj.nWindows |
|
776 | sizeOfWindows = (sizeOfFirstHeight + sizeOfdeltaHeight + sizeOfnHeights)*self.processingHeaderObj.nWindows | |
773 | processingHeaderSize += sizeOfWindows |
|
777 | processingHeaderSize += sizeOfWindows | |
774 |
|
778 | |||
775 | self.processingHeaderObj.size = processingHeaderSize |
|
779 | self.processingHeaderObj.size = processingHeaderSize | |
776 |
|
780 | |||
777 | No newline at end of file |
|
781 |
@@ -1,592 +1,592 | |||||
1 | ''' |
|
1 | ''' | |
2 |
|
2 | |||
3 | $Author$ |
|
3 | $Author$ | |
4 | $Id$ |
|
4 | $Id$ | |
5 | ''' |
|
5 | ''' | |
6 |
|
6 | |||
7 | import os, sys |
|
7 | import os, sys | |
8 | import numpy |
|
8 | import numpy | |
9 | import glob |
|
9 | import glob | |
10 | import fnmatch |
|
10 | import fnmatch | |
11 | import time, datetime |
|
11 | import time, datetime | |
12 |
|
12 | |||
13 | path = os.path.split(os.getcwd())[0] |
|
13 | path = os.path.split(os.getcwd())[0] | |
14 | sys.path.append(path) |
|
14 | sys.path.append(path) | |
15 |
|
15 | |||
16 | from JROHeaderIO import * |
|
16 | from JROHeaderIO import * | |
17 | from JRODataIO import JRODataReader |
|
17 | from JRODataIO import JRODataReader | |
18 | from JRODataIO import JRODataWriter |
|
18 | from JRODataIO import JRODataWriter | |
19 |
|
19 | |||
20 | from Data.JROData import Voltage |
|
20 | from Data.JROData import Voltage | |
21 |
|
21 | |||
22 | class VoltageReader(JRODataReader): |
|
22 | class VoltageReader(JRODataReader): | |
23 | """ |
|
23 | """ | |
24 | Esta clase permite leer datos de voltage desde archivos en formato rawdata (.r). La lectura |
|
24 | Esta clase permite leer datos de voltage desde archivos en formato rawdata (.r). La lectura | |
25 | de los datos siempre se realiza por bloques. Los datos leidos (array de 3 dimensiones: |
|
25 | de los datos siempre se realiza por bloques. Los datos leidos (array de 3 dimensiones: | |
26 | perfiles*alturas*canales) son almacenados en la variable "buffer". |
|
26 | perfiles*alturas*canales) son almacenados en la variable "buffer". | |
27 |
|
27 | |||
28 | perfiles * alturas * canales |
|
28 | perfiles * alturas * canales | |
29 |
|
29 | |||
30 | Esta clase contiene instancias (objetos) de las clases BasicHeader, SystemHeader, |
|
30 | Esta clase contiene instancias (objetos) de las clases BasicHeader, SystemHeader, | |
31 | RadarControllerHeader y Voltage. Los tres primeros se usan para almacenar informacion de la |
|
31 | RadarControllerHeader y Voltage. Los tres primeros se usan para almacenar informacion de la | |
32 | cabecera de datos (metadata), y el cuarto (Voltage) para obtener y almacenar un perfil de |
|
32 | cabecera de datos (metadata), y el cuarto (Voltage) para obtener y almacenar un perfil de | |
33 | datos desde el "buffer" cada vez que se ejecute el metodo "getData". |
|
33 | datos desde el "buffer" cada vez que se ejecute el metodo "getData". | |
34 |
|
34 | |||
35 | Example: |
|
35 | Example: | |
36 |
|
36 | |||
37 | dpath = "/home/myuser/data" |
|
37 | dpath = "/home/myuser/data" | |
38 |
|
38 | |||
39 | startTime = datetime.datetime(2010,1,20,0,0,0,0,0,0) |
|
39 | startTime = datetime.datetime(2010,1,20,0,0,0,0,0,0) | |
40 |
|
40 | |||
41 | endTime = datetime.datetime(2010,1,21,23,59,59,0,0,0) |
|
41 | endTime = datetime.datetime(2010,1,21,23,59,59,0,0,0) | |
42 |
|
42 | |||
43 | readerObj = VoltageReader() |
|
43 | readerObj = VoltageReader() | |
44 |
|
44 | |||
45 | readerObj.setup(dpath, startTime, endTime) |
|
45 | readerObj.setup(dpath, startTime, endTime) | |
46 |
|
46 | |||
47 | while(True): |
|
47 | while(True): | |
48 |
|
48 | |||
49 | #to get one profile |
|
49 | #to get one profile | |
50 | profile = readerObj.getData() |
|
50 | profile = readerObj.getData() | |
51 |
|
51 | |||
52 | #print the profile |
|
52 | #print the profile | |
53 | print profile |
|
53 | print profile | |
54 |
|
54 | |||
55 | #If you want to see all datablock |
|
55 | #If you want to see all datablock | |
56 | print readerObj.datablock |
|
56 | print readerObj.datablock | |
57 |
|
57 | |||
58 | if readerObj.flagNoMoreFiles: |
|
58 | if readerObj.flagNoMoreFiles: | |
59 | break |
|
59 | break | |
60 |
|
60 | |||
61 | """ |
|
61 | """ | |
62 |
|
62 | |||
63 | ext = ".r" |
|
63 | ext = ".r" | |
64 |
|
64 | |||
65 | optchar = "D" |
|
65 | optchar = "D" | |
66 | dataOutObj = None |
|
66 | dataOutObj = None | |
67 |
|
67 | |||
68 |
|
68 | |||
69 | def __init__(self, dataOutObj=None): |
|
69 | def __init__(self, dataOutObj=None): | |
70 | """ |
|
70 | """ | |
71 | Inicializador de la clase VoltageReader para la lectura de datos de voltage. |
|
71 | Inicializador de la clase VoltageReader para la lectura de datos de voltage. | |
72 |
|
72 | |||
73 | Input: |
|
73 | Input: | |
74 | dataOutObj : Objeto de la clase Voltage. Este objeto sera utilizado para |
|
74 | dataOutObj : Objeto de la clase Voltage. Este objeto sera utilizado para | |
75 | almacenar un perfil de datos cada vez que se haga un requerimiento |
|
75 | almacenar un perfil de datos cada vez que se haga un requerimiento | |
76 | (getData). El perfil sera obtenido a partir del buffer de datos, |
|
76 | (getData). El perfil sera obtenido a partir del buffer de datos, | |
77 | si el buffer esta vacio se hara un nuevo proceso de lectura de un |
|
77 | si el buffer esta vacio se hara un nuevo proceso de lectura de un | |
78 | bloque de datos. |
|
78 | bloque de datos. | |
79 | Si este parametro no es pasado se creara uno internamente. |
|
79 | Si este parametro no es pasado se creara uno internamente. | |
80 |
|
80 | |||
81 | Variables afectadas: |
|
81 | Variables afectadas: | |
82 | self.dataOutObj |
|
82 | self.dataOutObj | |
83 |
|
83 | |||
84 | Return: |
|
84 | Return: | |
85 | None |
|
85 | None | |
86 | """ |
|
86 | """ | |
87 |
|
87 | |||
88 | self.datablock = None |
|
88 | self.datablock = None | |
89 |
|
89 | |||
90 | self.utc = 0 |
|
90 | self.utc = 0 | |
91 |
|
91 | |||
92 | self.ext = ".r" |
|
92 | self.ext = ".r" | |
93 |
|
93 | |||
94 | self.optchar = "D" |
|
94 | self.optchar = "D" | |
95 |
|
95 | |||
96 | self.basicHeaderObj = BasicHeader() |
|
96 | self.basicHeaderObj = BasicHeader() | |
97 |
|
97 | |||
98 | self.systemHeaderObj = SystemHeader() |
|
98 | self.systemHeaderObj = SystemHeader() | |
99 |
|
99 | |||
100 | self.radarControllerHeaderObj = RadarControllerHeader() |
|
100 | self.radarControllerHeaderObj = RadarControllerHeader() | |
101 |
|
101 | |||
102 | self.processingHeaderObj = ProcessingHeader() |
|
102 | self.processingHeaderObj = ProcessingHeader() | |
103 |
|
103 | |||
104 | self.online = 0 |
|
104 | self.online = 0 | |
105 |
|
105 | |||
106 | self.fp = None |
|
106 | self.fp = None | |
107 |
|
107 | |||
108 | self.idFile = None |
|
108 | self.idFile = None | |
109 |
|
109 | |||
110 | self.dtype = None |
|
110 | self.dtype = None | |
111 |
|
111 | |||
112 | self.fileSizeByHeader = None |
|
112 | self.fileSizeByHeader = None | |
113 |
|
113 | |||
114 | self.filenameList = [] |
|
114 | self.filenameList = [] | |
115 |
|
115 | |||
116 | self.filename = None |
|
116 | self.filename = None | |
117 |
|
117 | |||
118 | self.fileSize = None |
|
118 | self.fileSize = None | |
119 |
|
119 | |||
120 | self.firstHeaderSize = 0 |
|
120 | self.firstHeaderSize = 0 | |
121 |
|
121 | |||
122 | self.basicHeaderSize = 24 |
|
122 | self.basicHeaderSize = 24 | |
123 |
|
123 | |||
124 | self.pathList = [] |
|
124 | self.pathList = [] | |
125 |
|
125 | |||
126 | self.filenameList = [] |
|
126 | self.filenameList = [] | |
127 |
|
127 | |||
128 | self.lastUTTime = 0 |
|
128 | self.lastUTTime = 0 | |
129 |
|
129 | |||
130 | self.maxTimeStep = 30 |
|
130 | self.maxTimeStep = 30 | |
131 |
|
131 | |||
132 | self.flagNoMoreFiles = 0 |
|
132 | self.flagNoMoreFiles = 0 | |
133 |
|
133 | |||
134 | self.set = 0 |
|
134 | self.set = 0 | |
135 |
|
135 | |||
136 | self.path = None |
|
136 | self.path = None | |
137 |
|
137 | |||
138 | self.profileIndex = 9999 |
|
138 | self.profileIndex = 9999 | |
139 |
|
139 | |||
140 | self.delay = 3 #seconds |
|
140 | self.delay = 3 #seconds | |
141 |
|
141 | |||
142 | self.nTries = 3 #quantity tries |
|
142 | self.nTries = 3 #quantity tries | |
143 |
|
143 | |||
144 | self.nFiles = 3 #number of files for searching |
|
144 | self.nFiles = 3 #number of files for searching | |
145 |
|
145 | |||
146 | self.nReadBlocks = 0 |
|
146 | self.nReadBlocks = 0 | |
147 |
|
147 | |||
148 | self.flagIsNewFile = 1 |
|
148 | self.flagIsNewFile = 1 | |
149 |
|
149 | |||
150 | self.ippSeconds = 0 |
|
150 | self.ippSeconds = 0 | |
151 |
|
151 | |||
152 | self.flagTimeBlock = 0 |
|
152 | self.flagTimeBlock = 0 | |
153 |
|
153 | |||
154 | self.flagIsNewBlock = 0 |
|
154 | self.flagIsNewBlock = 0 | |
155 |
|
155 | |||
156 | self.nTotalBlocks = 0 |
|
156 | self.nTotalBlocks = 0 | |
157 |
|
157 | |||
158 | self.blocksize = 0 |
|
158 | self.blocksize = 0 | |
159 |
|
159 | |||
160 | def createObjByDefault(self): |
|
160 | def createObjByDefault(self): | |
161 |
|
161 | |||
162 | dataObj = Voltage() |
|
162 | dataObj = Voltage() | |
163 |
|
163 | |||
164 | return dataObj |
|
164 | return dataObj | |
165 |
|
165 | |||
166 | def __hasNotDataInBuffer(self): |
|
166 | def __hasNotDataInBuffer(self): | |
167 | if self.profileIndex >= self.processingHeaderObj.profilesPerBlock: |
|
167 | if self.profileIndex >= self.processingHeaderObj.profilesPerBlock: | |
168 | return 1 |
|
168 | return 1 | |
169 | return 0 |
|
169 | return 0 | |
170 |
|
170 | |||
171 |
|
171 | |||
172 | def getBlockDimension(self): |
|
172 | def getBlockDimension(self): | |
173 | """ |
|
173 | """ | |
174 | Obtiene la cantidad de puntos a leer por cada bloque de datos |
|
174 | Obtiene la cantidad de puntos a leer por cada bloque de datos | |
175 |
|
175 | |||
176 | Affected: |
|
176 | Affected: | |
177 | self.blocksize |
|
177 | self.blocksize | |
178 |
|
178 | |||
179 | Return: |
|
179 | Return: | |
180 | None |
|
180 | None | |
181 | """ |
|
181 | """ | |
182 | pts2read = self.processingHeaderObj.profilesPerBlock * self.processingHeaderObj.nHeights * self.systemHeaderObj.nChannels |
|
182 | pts2read = self.processingHeaderObj.profilesPerBlock * self.processingHeaderObj.nHeights * self.systemHeaderObj.nChannels | |
183 | self.blocksize = pts2read |
|
183 | self.blocksize = pts2read | |
184 |
|
184 | |||
185 |
|
185 | |||
186 | def readBlock(self): |
|
186 | def readBlock(self): | |
187 | """ |
|
187 | """ | |
188 | readBlock lee el bloque de datos desde la posicion actual del puntero del archivo |
|
188 | readBlock lee el bloque de datos desde la posicion actual del puntero del archivo | |
189 | (self.fp) y actualiza todos los parametros relacionados al bloque de datos |
|
189 | (self.fp) y actualiza todos los parametros relacionados al bloque de datos | |
190 | (metadata + data). La data leida es almacenada en el buffer y el contador del buffer |
|
190 | (metadata + data). La data leida es almacenada en el buffer y el contador del buffer | |
191 | es seteado a 0 |
|
191 | es seteado a 0 | |
192 |
|
192 | |||
193 | Inputs: |
|
193 | Inputs: | |
194 | None |
|
194 | None | |
195 |
|
195 | |||
196 | Return: |
|
196 | Return: | |
197 | None |
|
197 | None | |
198 |
|
198 | |||
199 | Affected: |
|
199 | Affected: | |
200 | self.profileIndex |
|
200 | self.profileIndex | |
201 | self.datablock |
|
201 | self.datablock | |
202 | self.flagIsNewFile |
|
202 | self.flagIsNewFile | |
203 | self.flagIsNewBlock |
|
203 | self.flagIsNewBlock | |
204 | self.nTotalBlocks |
|
204 | self.nTotalBlocks | |
205 |
|
205 | |||
206 | Exceptions: |
|
206 | Exceptions: | |
207 | Si un bloque leido no es un bloque valido |
|
207 | Si un bloque leido no es un bloque valido | |
208 | """ |
|
208 | """ | |
209 |
|
209 | |||
210 | junk = numpy.fromfile( self.fp, self.dtype, self.blocksize ) |
|
210 | junk = numpy.fromfile( self.fp, self.dtype, self.blocksize ) | |
211 |
|
211 | |||
212 | try: |
|
212 | try: | |
213 | junk = junk.reshape( (self.processingHeaderObj.profilesPerBlock, self.processingHeaderObj.nHeights, self.systemHeaderObj.nChannels) ) |
|
213 | junk = junk.reshape( (self.processingHeaderObj.profilesPerBlock, self.processingHeaderObj.nHeights, self.systemHeaderObj.nChannels) ) | |
214 | except: |
|
214 | except: | |
215 | print "The read block (%3d) has not enough data" %self.nReadBlocks |
|
215 | print "The read block (%3d) has not enough data" %self.nReadBlocks | |
216 | return 0 |
|
216 | return 0 | |
217 |
|
217 | |||
218 | junk = numpy.transpose(junk, (2,0,1)) |
|
218 | junk = numpy.transpose(junk, (2,0,1)) | |
219 | self.datablock = junk['real'] + junk['imag']*1j |
|
219 | self.datablock = junk['real'] + junk['imag']*1j | |
220 |
|
220 | |||
221 | self.profileIndex = 0 |
|
221 | self.profileIndex = 0 | |
222 |
|
222 | |||
223 | self.flagIsNewFile = 0 |
|
223 | self.flagIsNewFile = 0 | |
224 | self.flagIsNewBlock = 1 |
|
224 | self.flagIsNewBlock = 1 | |
225 |
|
225 | |||
226 | self.nTotalBlocks += 1 |
|
226 | self.nTotalBlocks += 1 | |
227 | self.nReadBlocks += 1 |
|
227 | self.nReadBlocks += 1 | |
228 |
|
228 | |||
229 | return 1 |
|
229 | return 1 | |
230 |
|
230 | |||
231 |
|
231 | |||
232 | def getData(self): |
|
232 | def getData(self): | |
233 | """ |
|
233 | """ | |
234 | getData obtiene una unidad de datos del buffer de lectura y la copia a la clase "Voltage" |
|
234 | getData obtiene una unidad de datos del buffer de lectura y la copia a la clase "Voltage" | |
235 | con todos los parametros asociados a este (metadata). cuando no hay datos en el buffer de |
|
235 | con todos los parametros asociados a este (metadata). cuando no hay datos en el buffer de | |
236 | lectura es necesario hacer una nueva lectura de los bloques de datos usando "readNextBlock" |
|
236 | lectura es necesario hacer una nueva lectura de los bloques de datos usando "readNextBlock" | |
237 |
|
237 | |||
238 | Ademas incrementa el contador del buffer en 1. |
|
238 | Ademas incrementa el contador del buffer en 1. | |
239 |
|
239 | |||
240 | Return: |
|
240 | Return: | |
241 | data : retorna un perfil de voltages (alturas * canales) copiados desde el |
|
241 | data : retorna un perfil de voltages (alturas * canales) copiados desde el | |
242 | buffer. Si no hay mas archivos a leer retorna None. |
|
242 | buffer. Si no hay mas archivos a leer retorna None. | |
243 |
|
243 | |||
244 | Variables afectadas: |
|
244 | Variables afectadas: | |
245 | self.dataOutObj |
|
245 | self.dataOutObj | |
246 | self.profileIndex |
|
246 | self.profileIndex | |
247 |
|
247 | |||
248 | Affected: |
|
248 | Affected: | |
249 | self.dataOutObj |
|
249 | self.dataOutObj | |
250 | self.profileIndex |
|
250 | self.profileIndex | |
251 | self.flagTimeBlock |
|
251 | self.flagTimeBlock | |
252 | self.flagIsNewBlock |
|
252 | self.flagIsNewBlock | |
253 | """ |
|
253 | """ | |
254 | if self.flagNoMoreFiles: return 0 |
|
254 | if self.flagNoMoreFiles: return 0 | |
255 |
|
255 | |||
256 | self.flagTimeBlock = 0 |
|
256 | self.flagTimeBlock = 0 | |
257 | self.flagIsNewBlock = 0 |
|
257 | self.flagIsNewBlock = 0 | |
258 |
|
258 | |||
259 | if self.__hasNotDataInBuffer(): |
|
259 | if self.__hasNotDataInBuffer(): | |
260 |
|
260 | |||
261 | if not( self.readNextBlock() ): |
|
261 | if not( self.readNextBlock() ): | |
262 | return 0 |
|
262 | return 0 | |
263 |
|
263 | |||
264 | # self.updateDataHeader() |
|
264 | # self.updateDataHeader() | |
265 |
|
265 | |||
266 | if self.flagNoMoreFiles == 1: |
|
266 | if self.flagNoMoreFiles == 1: | |
267 | print 'Process finished' |
|
267 | print 'Process finished' | |
268 | return 0 |
|
268 | return 0 | |
269 |
|
269 | |||
270 | #data es un numpy array de 3 dmensiones (perfiles, alturas y canales) |
|
270 | #data es un numpy array de 3 dmensiones (perfiles, alturas y canales) | |
271 |
|
271 | |||
272 | if self.datablock == None: |
|
272 | if self.datablock == None: | |
273 | self.dataOutObj.flagNoData = True |
|
273 | self.dataOutObj.flagNoData = True | |
274 | return 0 |
|
274 | return 0 | |
275 |
|
275 | |||
276 | self.dataOutObj.data = self.datablock[:,self.profileIndex,:] |
|
276 | self.dataOutObj.data = self.datablock[:,self.profileIndex,:] | |
277 |
|
277 | |||
278 | self.dataOutObj.dtype = self.dtype |
|
278 | self.dataOutObj.dtype = self.dtype | |
279 |
|
279 | |||
280 | self.dataOutObj.nChannels = self.systemHeaderObj.nChannels |
|
280 | self.dataOutObj.nChannels = self.systemHeaderObj.nChannels | |
281 |
|
281 | |||
282 | self.dataOutObj.nHeights = self.processingHeaderObj.nHeights |
|
282 | self.dataOutObj.nHeights = self.processingHeaderObj.nHeights | |
283 |
|
283 | |||
284 | self.dataOutObj.nProfiles = self.processingHeaderObj.profilesPerBlock |
|
284 | self.dataOutObj.nProfiles = self.processingHeaderObj.profilesPerBlock | |
285 |
|
285 | |||
286 | xf = self.processingHeaderObj.firstHeight + self.processingHeaderObj.nHeights*self.processingHeaderObj.deltaHeight |
|
286 | xf = self.processingHeaderObj.firstHeight + self.processingHeaderObj.nHeights*self.processingHeaderObj.deltaHeight | |
287 |
|
287 | |||
288 | self.dataOutObj.heightList = numpy.arange(self.processingHeaderObj.firstHeight, xf, self.processingHeaderObj.deltaHeight) |
|
288 | self.dataOutObj.heightList = numpy.arange(self.processingHeaderObj.firstHeight, xf, self.processingHeaderObj.deltaHeight) | |
289 |
|
289 | |||
290 | self.dataOutObj.channelList = range(self.systemHeaderObj.nChannels) |
|
290 | self.dataOutObj.channelList = range(self.systemHeaderObj.nChannels) | |
291 |
|
291 | |||
292 | self.dataOutObj.channelIndexList = range(self.systemHeaderObj.nChannels) |
|
292 | self.dataOutObj.channelIndexList = range(self.systemHeaderObj.nChannels) | |
293 |
|
293 | |||
294 | self.dataOutObj.flagTimeBlock = self.flagTimeBlock |
|
294 | self.dataOutObj.flagTimeBlock = self.flagTimeBlock | |
295 |
|
295 | |||
296 | self.dataOutObj.utctime = self.basicHeaderObj.utc + self.basicHeaderObj.miliSecond/1000. + self.profileIndex * self.ippSeconds |
|
296 | self.dataOutObj.utctime = self.basicHeaderObj.utc + self.basicHeaderObj.miliSecond/1000. + self.profileIndex * self.ippSeconds | |
297 |
|
297 | |||
298 | self.dataOutObj.ippSeconds = self.ippSeconds |
|
298 | self.dataOutObj.ippSeconds = self.ippSeconds | |
299 |
|
299 | |||
300 | self.dataOutObj.timeInterval = self.ippSeconds |
|
300 | self.dataOutObj.timeInterval = self.ippSeconds * self.processingHeaderObj.nCohInt | |
301 |
|
301 | |||
302 | self.dataOutObj.nCohInt = self.processingHeaderObj.nCohInt |
|
302 | self.dataOutObj.nCohInt = self.processingHeaderObj.nCohInt | |
303 |
|
303 | |||
304 | self.dataOutObj.flagShiftFFT = False |
|
304 | self.dataOutObj.flagShiftFFT = False | |
305 |
|
305 | |||
306 | if self.processingHeaderObj.code != None: |
|
306 | if self.processingHeaderObj.code != None: | |
307 | self.dataOutObj.nCode = self.processingHeaderObj.nCode |
|
307 | self.dataOutObj.nCode = self.processingHeaderObj.nCode | |
308 |
|
308 | |||
309 | self.dataOutObj.nBaud = self.processingHeaderObj.nBaud |
|
309 | self.dataOutObj.nBaud = self.processingHeaderObj.nBaud | |
310 |
|
310 | |||
311 | self.dataOutObj.code = self.processingHeaderObj.code |
|
311 | self.dataOutObj.code = self.processingHeaderObj.code | |
312 |
|
312 | |||
313 | self.profileIndex += 1 |
|
313 | self.profileIndex += 1 | |
314 |
|
314 | |||
315 | self.dataOutObj.systemHeaderObj = self.systemHeaderObj.copy() |
|
315 | self.dataOutObj.systemHeaderObj = self.systemHeaderObj.copy() | |
316 |
|
316 | |||
317 | self.dataOutObj.radarControllerHeaderObj = self.radarControllerHeaderObj.copy() |
|
317 | self.dataOutObj.radarControllerHeaderObj = self.radarControllerHeaderObj.copy() | |
318 |
|
318 | |||
319 | self.dataOutObj.flagNoData = False |
|
319 | self.dataOutObj.flagNoData = False | |
320 |
|
320 | |||
321 | # print self.profileIndex, self.dataOutObj.utctime |
|
321 | # print self.profileIndex, self.dataOutObj.utctime | |
322 | # if self.profileIndex == 800: |
|
322 | # if self.profileIndex == 800: | |
323 | # a=1 |
|
323 | # a=1 | |
324 |
|
324 | |||
325 | return self.dataOutObj.data |
|
325 | return self.dataOutObj.data | |
326 |
|
326 | |||
327 |
|
327 | |||
328 | class VoltageWriter(JRODataWriter): |
|
328 | class VoltageWriter(JRODataWriter): | |
329 | """ |
|
329 | """ | |
330 | Esta clase permite escribir datos de voltajes a archivos procesados (.r). La escritura |
|
330 | Esta clase permite escribir datos de voltajes a archivos procesados (.r). La escritura | |
331 | de los datos siempre se realiza por bloques. |
|
331 | de los datos siempre se realiza por bloques. | |
332 | """ |
|
332 | """ | |
333 |
|
333 | |||
334 | ext = ".r" |
|
334 | ext = ".r" | |
335 |
|
335 | |||
336 | optchar = "D" |
|
336 | optchar = "D" | |
337 |
|
337 | |||
338 | shapeBuffer = None |
|
338 | shapeBuffer = None | |
339 |
|
339 | |||
340 |
|
340 | |||
341 | def __init__(self, dataOutObj=None): |
|
341 | def __init__(self, dataOutObj=None): | |
342 | """ |
|
342 | """ | |
343 | Inicializador de la clase VoltageWriter para la escritura de datos de espectros. |
|
343 | Inicializador de la clase VoltageWriter para la escritura de datos de espectros. | |
344 |
|
344 | |||
345 | Affected: |
|
345 | Affected: | |
346 | self.dataOutObj |
|
346 | self.dataOutObj | |
347 |
|
347 | |||
348 | Return: None |
|
348 | Return: None | |
349 | """ |
|
349 | """ | |
350 | if dataOutObj == None: |
|
350 | if dataOutObj == None: | |
351 | dataOutObj = Voltage() |
|
351 | dataOutObj = Voltage() | |
352 |
|
352 | |||
353 | if not( isinstance(dataOutObj, Voltage) ): |
|
353 | if not( isinstance(dataOutObj, Voltage) ): | |
354 | raise ValueError, "in VoltageReader, dataOutObj must be an Spectra class object" |
|
354 | raise ValueError, "in VoltageReader, dataOutObj must be an Spectra class object" | |
355 |
|
355 | |||
356 | self.dataOutObj = dataOutObj |
|
356 | self.dataOutObj = dataOutObj | |
357 |
|
357 | |||
358 | self.nTotalBlocks = 0 |
|
358 | self.nTotalBlocks = 0 | |
359 |
|
359 | |||
360 | self.profileIndex = 0 |
|
360 | self.profileIndex = 0 | |
361 |
|
361 | |||
362 | def hasAllDataInBuffer(self): |
|
362 | def hasAllDataInBuffer(self): | |
363 | if self.profileIndex >= self.processingHeaderObj.profilesPerBlock: |
|
363 | if self.profileIndex >= self.processingHeaderObj.profilesPerBlock: | |
364 | return 1 |
|
364 | return 1 | |
365 | return 0 |
|
365 | return 0 | |
366 |
|
366 | |||
367 |
|
367 | |||
368 | def setBlockDimension(self): |
|
368 | def setBlockDimension(self): | |
369 | """ |
|
369 | """ | |
370 | Obtiene las formas dimensionales del los subbloques de datos que componen un bloque |
|
370 | Obtiene las formas dimensionales del los subbloques de datos que componen un bloque | |
371 |
|
371 | |||
372 | Affected: |
|
372 | Affected: | |
373 | self.shape_spc_Buffer |
|
373 | self.shape_spc_Buffer | |
374 | self.shape_cspc_Buffer |
|
374 | self.shape_cspc_Buffer | |
375 | self.shape_dc_Buffer |
|
375 | self.shape_dc_Buffer | |
376 |
|
376 | |||
377 | Return: None |
|
377 | Return: None | |
378 | """ |
|
378 | """ | |
379 | self.shapeBuffer = (self.processingHeaderObj.profilesPerBlock, |
|
379 | self.shapeBuffer = (self.processingHeaderObj.profilesPerBlock, | |
380 | self.processingHeaderObj.nHeights, |
|
380 | self.processingHeaderObj.nHeights, | |
381 | self.systemHeaderObj.nChannels) |
|
381 | self.systemHeaderObj.nChannels) | |
382 |
|
382 | |||
383 | self.datablock = numpy.zeros((self.systemHeaderObj.nChannels, |
|
383 | self.datablock = numpy.zeros((self.systemHeaderObj.nChannels, | |
384 | self.processingHeaderObj.profilesPerBlock, |
|
384 | self.processingHeaderObj.profilesPerBlock, | |
385 | self.processingHeaderObj.nHeights), |
|
385 | self.processingHeaderObj.nHeights), | |
386 | dtype=numpy.dtype('complex')) |
|
386 | dtype=numpy.dtype('complex')) | |
387 |
|
387 | |||
388 |
|
388 | |||
389 | def writeBlock(self): |
|
389 | def writeBlock(self): | |
390 | """ |
|
390 | """ | |
391 | Escribe el buffer en el file designado |
|
391 | Escribe el buffer en el file designado | |
392 |
|
392 | |||
393 | Affected: |
|
393 | Affected: | |
394 | self.profileIndex |
|
394 | self.profileIndex | |
395 | self.flagIsNewFile |
|
395 | self.flagIsNewFile | |
396 | self.flagIsNewBlock |
|
396 | self.flagIsNewBlock | |
397 | self.nTotalBlocks |
|
397 | self.nTotalBlocks | |
398 | self.blockIndex |
|
398 | self.blockIndex | |
399 |
|
399 | |||
400 | Return: None |
|
400 | Return: None | |
401 | """ |
|
401 | """ | |
402 | data = numpy.zeros( self.shapeBuffer, self.dtype ) |
|
402 | data = numpy.zeros( self.shapeBuffer, self.dtype ) | |
403 |
|
403 | |||
404 | junk = numpy.transpose(self.datablock, (1,2,0)) |
|
404 | junk = numpy.transpose(self.datablock, (1,2,0)) | |
405 |
|
405 | |||
406 | data['real'] = junk.real |
|
406 | data['real'] = junk.real | |
407 | data['imag'] = junk.imag |
|
407 | data['imag'] = junk.imag | |
408 |
|
408 | |||
409 | data = data.reshape( (-1) ) |
|
409 | data = data.reshape( (-1) ) | |
410 |
|
410 | |||
411 | data.tofile( self.fp ) |
|
411 | data.tofile( self.fp ) | |
412 |
|
412 | |||
413 | self.datablock.fill(0) |
|
413 | self.datablock.fill(0) | |
414 |
|
414 | |||
415 | self.profileIndex = 0 |
|
415 | self.profileIndex = 0 | |
416 | self.flagIsNewFile = 0 |
|
416 | self.flagIsNewFile = 0 | |
417 | self.flagIsNewBlock = 1 |
|
417 | self.flagIsNewBlock = 1 | |
418 |
|
418 | |||
419 | self.blockIndex += 1 |
|
419 | self.blockIndex += 1 | |
420 | self.nTotalBlocks += 1 |
|
420 | self.nTotalBlocks += 1 | |
421 |
|
421 | |||
422 | def putData(self): |
|
422 | def putData(self): | |
423 | """ |
|
423 | """ | |
424 | Setea un bloque de datos y luego los escribe en un file |
|
424 | Setea un bloque de datos y luego los escribe en un file | |
425 |
|
425 | |||
426 | Affected: |
|
426 | Affected: | |
427 | self.flagIsNewBlock |
|
427 | self.flagIsNewBlock | |
428 | self.profileIndex |
|
428 | self.profileIndex | |
429 |
|
429 | |||
430 | Return: |
|
430 | Return: | |
431 | 0 : Si no hay data o no hay mas files que puedan escribirse |
|
431 | 0 : Si no hay data o no hay mas files que puedan escribirse | |
432 | 1 : Si se escribio la data de un bloque en un file |
|
432 | 1 : Si se escribio la data de un bloque en un file | |
433 | """ |
|
433 | """ | |
434 | self.flagIsNewBlock = 0 |
|
434 | self.flagIsNewBlock = 0 | |
435 |
|
435 | |||
436 | if self.dataOutObj.flagNoData: |
|
436 | if self.dataOutObj.flagNoData: | |
437 | return 0 |
|
437 | return 0 | |
438 |
|
438 | |||
439 | if self.dataOutObj.flagTimeBlock: |
|
439 | if self.dataOutObj.flagTimeBlock: | |
440 |
|
440 | |||
441 | self.datablock.fill(0) |
|
441 | self.datablock.fill(0) | |
442 | self.profileIndex = 0 |
|
442 | self.profileIndex = 0 | |
443 | self.setNextFile() |
|
443 | self.setNextFile() | |
444 |
|
444 | |||
445 | if self.profileIndex == 0: |
|
445 | if self.profileIndex == 0: | |
446 | self.getBasicHeader() |
|
446 | self.getBasicHeader() | |
447 |
|
447 | |||
448 | self.datablock[:,self.profileIndex,:] = self.dataOutObj.data |
|
448 | self.datablock[:,self.profileIndex,:] = self.dataOutObj.data | |
449 |
|
449 | |||
450 | self.profileIndex += 1 |
|
450 | self.profileIndex += 1 | |
451 |
|
451 | |||
452 | if self.hasAllDataInBuffer(): |
|
452 | if self.hasAllDataInBuffer(): | |
453 | #if self.flagIsNewFile: |
|
453 | #if self.flagIsNewFile: | |
454 | self.writeNextBlock() |
|
454 | self.writeNextBlock() | |
455 | # self.getDataHeader() |
|
455 | # self.getDataHeader() | |
456 |
|
456 | |||
457 | if self.flagNoMoreFiles: |
|
457 | if self.flagNoMoreFiles: | |
458 | #print 'Process finished' |
|
458 | #print 'Process finished' | |
459 | return 0 |
|
459 | return 0 | |
460 |
|
460 | |||
461 | return 1 |
|
461 | return 1 | |
462 |
|
462 | |||
463 | def __getProcessFlags(self): |
|
463 | def __getProcessFlags(self): | |
464 |
|
464 | |||
465 | processFlags = 0 |
|
465 | processFlags = 0 | |
466 |
|
466 | |||
467 | dtype0 = numpy.dtype([('real','<i1'),('imag','<i1')]) |
|
467 | dtype0 = numpy.dtype([('real','<i1'),('imag','<i1')]) | |
468 | dtype1 = numpy.dtype([('real','<i2'),('imag','<i2')]) |
|
468 | dtype1 = numpy.dtype([('real','<i2'),('imag','<i2')]) | |
469 | dtype2 = numpy.dtype([('real','<i4'),('imag','<i4')]) |
|
469 | dtype2 = numpy.dtype([('real','<i4'),('imag','<i4')]) | |
470 | dtype3 = numpy.dtype([('real','<i8'),('imag','<i8')]) |
|
470 | dtype3 = numpy.dtype([('real','<i8'),('imag','<i8')]) | |
471 | dtype4 = numpy.dtype([('real','<f4'),('imag','<f4')]) |
|
471 | dtype4 = numpy.dtype([('real','<f4'),('imag','<f4')]) | |
472 | dtype5 = numpy.dtype([('real','<f8'),('imag','<f8')]) |
|
472 | dtype5 = numpy.dtype([('real','<f8'),('imag','<f8')]) | |
473 |
|
473 | |||
474 | dtypeList = [dtype0, dtype1, dtype2, dtype3, dtype4, dtype5] |
|
474 | dtypeList = [dtype0, dtype1, dtype2, dtype3, dtype4, dtype5] | |
475 |
|
475 | |||
476 |
|
476 | |||
477 |
|
477 | |||
478 | datatypeValueList = [PROCFLAG.DATATYPE_CHAR, |
|
478 | datatypeValueList = [PROCFLAG.DATATYPE_CHAR, | |
479 | PROCFLAG.DATATYPE_SHORT, |
|
479 | PROCFLAG.DATATYPE_SHORT, | |
480 | PROCFLAG.DATATYPE_LONG, |
|
480 | PROCFLAG.DATATYPE_LONG, | |
481 | PROCFLAG.DATATYPE_INT64, |
|
481 | PROCFLAG.DATATYPE_INT64, | |
482 | PROCFLAG.DATATYPE_FLOAT, |
|
482 | PROCFLAG.DATATYPE_FLOAT, | |
483 | PROCFLAG.DATATYPE_DOUBLE] |
|
483 | PROCFLAG.DATATYPE_DOUBLE] | |
484 |
|
484 | |||
485 |
|
485 | |||
486 | for index in range(len(dtypeList)): |
|
486 | for index in range(len(dtypeList)): | |
487 | if self.dataOutObj.dtype == dtypeList[index]: |
|
487 | if self.dataOutObj.dtype == dtypeList[index]: | |
488 | dtypeValue = datatypeValueList[index] |
|
488 | dtypeValue = datatypeValueList[index] | |
489 | break |
|
489 | break | |
490 |
|
490 | |||
491 | processFlags += dtypeValue |
|
491 | processFlags += dtypeValue | |
492 |
|
492 | |||
493 | if self.dataOutObj.flagDecodeData: |
|
493 | if self.dataOutObj.flagDecodeData: | |
494 | processFlags += PROCFLAG.DECODE_DATA |
|
494 | processFlags += PROCFLAG.DECODE_DATA | |
495 |
|
495 | |||
496 | if self.dataOutObj.flagDeflipData: |
|
496 | if self.dataOutObj.flagDeflipData: | |
497 | processFlags += PROCFLAG.DEFLIP_DATA |
|
497 | processFlags += PROCFLAG.DEFLIP_DATA | |
498 |
|
498 | |||
499 | if self.dataOutObj.code != None: |
|
499 | if self.dataOutObj.code != None: | |
500 | processFlags += PROCFLAG.DEFINE_PROCESS_CODE |
|
500 | processFlags += PROCFLAG.DEFINE_PROCESS_CODE | |
501 |
|
501 | |||
502 | if self.dataOutObj.nCohInt > 1: |
|
502 | if self.dataOutObj.nCohInt > 1: | |
503 | processFlags += PROCFLAG.COHERENT_INTEGRATION |
|
503 | processFlags += PROCFLAG.COHERENT_INTEGRATION | |
504 |
|
504 | |||
505 | return processFlags |
|
505 | return processFlags | |
506 |
|
506 | |||
507 |
|
507 | |||
508 | def __getBlockSize(self): |
|
508 | def __getBlockSize(self): | |
509 | ''' |
|
509 | ''' | |
510 | Este metodos determina el cantidad de bytes para un bloque de datos de tipo Voltage |
|
510 | Este metodos determina el cantidad de bytes para un bloque de datos de tipo Voltage | |
511 | ''' |
|
511 | ''' | |
512 |
|
512 | |||
513 | dtype0 = numpy.dtype([('real','<i1'),('imag','<i1')]) |
|
513 | dtype0 = numpy.dtype([('real','<i1'),('imag','<i1')]) | |
514 | dtype1 = numpy.dtype([('real','<i2'),('imag','<i2')]) |
|
514 | dtype1 = numpy.dtype([('real','<i2'),('imag','<i2')]) | |
515 | dtype2 = numpy.dtype([('real','<i4'),('imag','<i4')]) |
|
515 | dtype2 = numpy.dtype([('real','<i4'),('imag','<i4')]) | |
516 | dtype3 = numpy.dtype([('real','<i8'),('imag','<i8')]) |
|
516 | dtype3 = numpy.dtype([('real','<i8'),('imag','<i8')]) | |
517 | dtype4 = numpy.dtype([('real','<f4'),('imag','<f4')]) |
|
517 | dtype4 = numpy.dtype([('real','<f4'),('imag','<f4')]) | |
518 | dtype5 = numpy.dtype([('real','<f8'),('imag','<f8')]) |
|
518 | dtype5 = numpy.dtype([('real','<f8'),('imag','<f8')]) | |
519 |
|
519 | |||
520 | dtypeList = [dtype0, dtype1, dtype2, dtype3, dtype4, dtype5] |
|
520 | dtypeList = [dtype0, dtype1, dtype2, dtype3, dtype4, dtype5] | |
521 | datatypeValueList = [1,2,4,8,4,8] |
|
521 | datatypeValueList = [1,2,4,8,4,8] | |
522 | for index in range(len(dtypeList)): |
|
522 | for index in range(len(dtypeList)): | |
523 | if self.dataOutObj.dtype == dtypeList[index]: |
|
523 | if self.dataOutObj.dtype == dtypeList[index]: | |
524 | datatypeValue = datatypeValueList[index] |
|
524 | datatypeValue = datatypeValueList[index] | |
525 | break |
|
525 | break | |
526 |
|
526 | |||
527 | blocksize = int(self.dataOutObj.nHeights * self.dataOutObj.nChannels * self.dataOutObj.nProfiles * datatypeValue * 2) |
|
527 | blocksize = int(self.dataOutObj.nHeights * self.dataOutObj.nChannels * self.dataOutObj.nProfiles * datatypeValue * 2) | |
528 |
|
528 | |||
529 | return blocksize |
|
529 | return blocksize | |
530 |
|
530 | |||
531 |
|
531 | |||
532 | def getBasicHeader(self): |
|
532 | def getBasicHeader(self): | |
533 | self.basicHeaderObj.size = self.basicHeaderSize #bytes |
|
533 | self.basicHeaderObj.size = self.basicHeaderSize #bytes | |
534 | self.basicHeaderObj.version = self.versionFile |
|
534 | self.basicHeaderObj.version = self.versionFile | |
535 | self.basicHeaderObj.dataBlock = self.nTotalBlocks |
|
535 | self.basicHeaderObj.dataBlock = self.nTotalBlocks | |
536 |
|
536 | |||
537 | utc = numpy.floor(self.dataOutObj.utctime) |
|
537 | utc = numpy.floor(self.dataOutObj.utctime) | |
538 | milisecond = (self.dataOutObj.utctime - utc)* 1000.0 |
|
538 | milisecond = (self.dataOutObj.utctime - utc)* 1000.0 | |
539 |
|
539 | |||
540 | self.basicHeaderObj.utc = utc |
|
540 | self.basicHeaderObj.utc = utc | |
541 | self.basicHeaderObj.miliSecond = milisecond |
|
541 | self.basicHeaderObj.miliSecond = milisecond | |
542 | self.basicHeaderObj.timeZone = 0 |
|
542 | self.basicHeaderObj.timeZone = 0 | |
543 | self.basicHeaderObj.dstFlag = 0 |
|
543 | self.basicHeaderObj.dstFlag = 0 | |
544 | self.basicHeaderObj.errorCount = 0 |
|
544 | self.basicHeaderObj.errorCount = 0 | |
545 |
|
545 | |||
546 | def getDataHeader(self): |
|
546 | def getDataHeader(self): | |
547 |
|
547 | |||
548 | """ |
|
548 | """ | |
549 | Obtiene una copia del First Header |
|
549 | Obtiene una copia del First Header | |
550 |
|
550 | |||
551 | Affected: |
|
551 | Affected: | |
552 | self.systemHeaderObj |
|
552 | self.systemHeaderObj | |
553 | self.radarControllerHeaderObj |
|
553 | self.radarControllerHeaderObj | |
554 | self.dtype |
|
554 | self.dtype | |
555 |
|
555 | |||
556 | Return: |
|
556 | Return: | |
557 | None |
|
557 | None | |
558 | """ |
|
558 | """ | |
559 |
|
559 | |||
560 | self.systemHeaderObj = self.dataOutObj.systemHeaderObj.copy() |
|
560 | self.systemHeaderObj = self.dataOutObj.systemHeaderObj.copy() | |
561 | self.systemHeaderObj.nChannels = self.dataOutObj.nChannels |
|
561 | self.systemHeaderObj.nChannels = self.dataOutObj.nChannels | |
562 | self.radarControllerHeaderObj = self.dataOutObj.radarControllerHeaderObj.copy() |
|
562 | self.radarControllerHeaderObj = self.dataOutObj.radarControllerHeaderObj.copy() | |
563 |
|
563 | |||
564 | self.getBasicHeader() |
|
564 | self.getBasicHeader() | |
565 |
|
565 | |||
566 | processingHeaderSize = 40 # bytes |
|
566 | processingHeaderSize = 40 # bytes | |
567 | self.processingHeaderObj.dtype = 0 # Voltage |
|
567 | self.processingHeaderObj.dtype = 0 # Voltage | |
568 | self.processingHeaderObj.blockSize = self.__getBlockSize() |
|
568 | self.processingHeaderObj.blockSize = self.__getBlockSize() | |
569 | self.processingHeaderObj.profilesPerBlock = self.profilesPerBlock |
|
569 | self.processingHeaderObj.profilesPerBlock = self.profilesPerBlock | |
570 | self.processingHeaderObj.dataBlocksPerFile = self.blocksPerFile |
|
570 | self.processingHeaderObj.dataBlocksPerFile = self.blocksPerFile | |
571 | self.processingHeaderObj.nWindows = 1 #podria ser 1 o self.dataOutObj.processingHeaderObj.nWindows |
|
571 | self.processingHeaderObj.nWindows = 1 #podria ser 1 o self.dataOutObj.processingHeaderObj.nWindows | |
572 | self.processingHeaderObj.processFlags = self.__getProcessFlags() |
|
572 | self.processingHeaderObj.processFlags = self.__getProcessFlags() | |
573 | self.processingHeaderObj.nCohInt = self.dataOutObj.nCohInt |
|
573 | self.processingHeaderObj.nCohInt = self.dataOutObj.nCohInt | |
574 | self.processingHeaderObj.nIncohInt = 1 # Cuando la data de origen es de tipo Voltage |
|
574 | self.processingHeaderObj.nIncohInt = 1 # Cuando la data de origen es de tipo Voltage | |
575 | self.processingHeaderObj.totalSpectra = 0 # Cuando la data de origen es de tipo Voltage |
|
575 | self.processingHeaderObj.totalSpectra = 0 # Cuando la data de origen es de tipo Voltage | |
576 |
|
576 | |||
577 | if self.dataOutObj.code != None: |
|
577 | if self.dataOutObj.code != None: | |
578 | self.processingHeaderObj.code = self.dataOutObj.code |
|
578 | self.processingHeaderObj.code = self.dataOutObj.code | |
579 | self.processingHeaderObj.nCode = self.dataOutObj.nCode |
|
579 | self.processingHeaderObj.nCode = self.dataOutObj.nCode | |
580 | self.processingHeaderObj.nBaud = self.dataOutObj.nBaud |
|
580 | self.processingHeaderObj.nBaud = self.dataOutObj.nBaud | |
581 | codesize = int(8 + 4 * self.dataOutObj.nCode * self.dataOutObj.nBaud) |
|
581 | codesize = int(8 + 4 * self.dataOutObj.nCode * self.dataOutObj.nBaud) | |
582 | processingHeaderSize += codesize |
|
582 | processingHeaderSize += codesize | |
583 |
|
583 | |||
584 | if self.processingHeaderObj.nWindows != 0: |
|
584 | if self.processingHeaderObj.nWindows != 0: | |
585 | self.processingHeaderObj.firstHeight = self.dataOutObj.heightList[0] |
|
585 | self.processingHeaderObj.firstHeight = self.dataOutObj.heightList[0] | |
586 | self.processingHeaderObj.deltaHeight = self.dataOutObj.heightList[1] - self.dataOutObj.heightList[0] |
|
586 | self.processingHeaderObj.deltaHeight = self.dataOutObj.heightList[1] - self.dataOutObj.heightList[0] | |
587 | self.processingHeaderObj.nHeights = self.dataOutObj.nHeights |
|
587 | self.processingHeaderObj.nHeights = self.dataOutObj.nHeights | |
588 | self.processingHeaderObj.samplesWin = self.dataOutObj.nHeights |
|
588 | self.processingHeaderObj.samplesWin = self.dataOutObj.nHeights | |
589 | processingHeaderSize += 12 |
|
589 | processingHeaderSize += 12 | |
590 |
|
590 | |||
591 | self.processingHeaderObj.size = processingHeaderSize |
|
591 | self.processingHeaderObj.size = processingHeaderSize | |
592 | No newline at end of file |
|
592 |
@@ -1,639 +1,698 | |||||
1 | ''' |
|
1 | ''' | |
2 |
|
2 | |||
3 | $Author$ |
|
3 | $Author$ | |
4 | $Id$ |
|
4 | $Id$ | |
5 | ''' |
|
5 | ''' | |
6 |
|
6 | |||
7 | import os, sys |
|
7 | import os, sys | |
8 | import numpy |
|
8 | import numpy | |
9 | import time |
|
9 | import time | |
10 | import datetime |
|
10 | import datetime | |
11 | path = os.path.split(os.getcwd())[0] |
|
11 | path = os.path.split(os.getcwd())[0] | |
12 | sys.path.append(path) |
|
12 | sys.path.append(path) | |
13 |
|
13 | |||
14 | from Data.JROData import Spectra, SpectraHeis |
|
14 | from Data.JROData import Spectra, SpectraHeis | |
15 | from IO.SpectraIO import SpectraWriter |
|
15 | from IO.SpectraIO import SpectraWriter | |
16 | from Graphics.schainPlotTypes import ScopeFigure, SpcFigure |
|
16 | from Graphics.schainPlotTypes import ScopeFigure, SpcFigure | |
17 | #from JRONoise import Noise |
|
17 | #from JRONoise import Noise | |
18 |
|
18 | |||
19 | class SpectraProcessor: |
|
19 | class SpectraProcessor: | |
20 | ''' |
|
20 | ''' | |
21 | classdocs |
|
21 | classdocs | |
22 | ''' |
|
22 | ''' | |
23 |
|
23 | |||
24 | dataInObj = None |
|
24 | dataInObj = None | |
25 |
|
25 | |||
26 | dataOutObj = None |
|
26 | dataOutObj = None | |
27 |
|
27 | |||
28 | noiseObj = None |
|
28 | noiseObj = None | |
29 |
|
29 | |||
30 | integratorObjList = [] |
|
30 | integratorObjList = [] | |
31 |
|
31 | |||
32 | writerObjList = [] |
|
32 | writerObjList = [] | |
33 |
|
33 | |||
34 | integratorObjIndex = None |
|
34 | integratorObjIndex = None | |
35 |
|
35 | |||
36 | writerObjIndex = None |
|
36 | writerObjIndex = None | |
37 |
|
37 | |||
38 | profIndex = 0 # Se emplea cuando el objeto de entrada es un Voltage |
|
38 | profIndex = 0 # Se emplea cuando el objeto de entrada es un Voltage | |
39 |
|
39 | |||
40 |
|
40 | |||
41 | def __init__(self): |
|
41 | def __init__(self): | |
42 | ''' |
|
42 | ''' | |
43 | Constructor |
|
43 | Constructor | |
44 | ''' |
|
44 | ''' | |
45 |
|
45 | |||
46 | self.integratorObjIndex = None |
|
46 | self.integratorObjIndex = None | |
47 | self.writerObjIndex = None |
|
47 | self.writerObjIndex = None | |
48 | self.plotObjIndex = None |
|
48 | self.plotObjIndex = None | |
49 | self.integratorOst = [] |
|
49 | self.integratorOst = [] | |
50 | self.plotObjList = [] |
|
50 | self.plotObjList = [] | |
51 | self.noiseObj = [] |
|
51 | self.noiseObj = [] | |
52 | self.writerObjList = [] |
|
52 | self.writerObjList = [] | |
53 | self.buffer = None |
|
53 | self.buffer = None | |
54 | self.profIndex = 0 |
|
54 | self.profIndex = 0 | |
55 |
|
55 | |||
56 | def setup(self, dataInObj=None, dataOutObj=None, nFFTPoints=None, pairsList=None): |
|
56 | def setup(self, dataInObj=None, dataOutObj=None, nFFTPoints=None, pairsList=None): | |
57 |
|
57 | |||
58 | if dataInObj == None: |
|
58 | if dataInObj == None: | |
59 | raise ValueError, "This SpectraProcessor.setup() function needs dataInObj input variable" |
|
59 | raise ValueError, "This SpectraProcessor.setup() function needs dataInObj input variable" | |
60 |
|
60 | |||
61 | if dataInObj.type == "Voltage": |
|
61 | if dataInObj.type == "Voltage": | |
62 | if nFFTPoints == None: |
|
62 | if nFFTPoints == None: | |
63 | raise ValueError, "This SpectraProcessor.setup() function needs nFFTPoints input variable" |
|
63 | raise ValueError, "This SpectraProcessor.setup() function needs nFFTPoints input variable" | |
64 |
|
64 | |||
65 |
|
65 | |||
66 |
|
66 | |||
67 | if dataInObj.type == "Spectra": |
|
67 | if dataInObj.type == "Spectra": | |
68 | if nFFTPoints != None: |
|
68 | if nFFTPoints != None: | |
69 | raise ValueError, "The nFFTPoints cannot be selected to this object type" |
|
69 | raise ValueError, "The nFFTPoints cannot be selected to this object type" | |
70 |
|
70 | |||
71 | nFFTPoints = dataInObj.nFFTPoints |
|
71 | nFFTPoints = dataInObj.nFFTPoints | |
72 |
|
72 | |||
73 | if pairsList == None: |
|
73 | if pairsList == None: | |
74 | pairsList = dataInObj.pairsList |
|
74 | pairsList = dataInObj.pairsList | |
75 |
|
75 | |||
76 | if pairsList == None: |
|
76 | if pairsList == None: | |
77 | nPairs = 0 |
|
77 | nPairs = 0 | |
78 | else: |
|
78 | else: | |
79 | nPairs = len(pairsList) |
|
79 | nPairs = len(pairsList) | |
80 |
|
80 | |||
81 | self.dataInObj = dataInObj |
|
81 | self.dataInObj = dataInObj | |
82 |
|
82 | |||
83 | if dataOutObj == None: |
|
83 | if dataOutObj == None: | |
84 | dataOutObj = Spectra() |
|
84 | dataOutObj = Spectra() | |
85 |
|
85 | |||
86 | self.dataOutObj = dataOutObj |
|
86 | self.dataOutObj = dataOutObj | |
87 | self.dataOutObj.nFFTPoints = nFFTPoints |
|
87 | self.dataOutObj.nFFTPoints = nFFTPoints | |
88 | self.dataOutObj.pairsList = pairsList |
|
88 | self.dataOutObj.pairsList = pairsList | |
89 | self.dataOutObj.nPairs = nPairs |
|
89 | self.dataOutObj.nPairs = nPairs | |
90 |
|
90 | |||
91 | return self.dataOutObj |
|
91 | return self.dataOutObj | |
92 |
|
92 | |||
93 | def init(self): |
|
93 | def init(self): | |
94 |
|
94 | |||
95 | self.dataOutObj.flagNoData = True |
|
95 | self.dataOutObj.flagNoData = True | |
96 |
|
96 | |||
97 | if self.dataInObj.flagNoData: |
|
97 | if self.dataInObj.flagNoData: | |
98 | return 0 |
|
98 | return 0 | |
99 |
|
99 | |||
100 | self.integratorObjIndex = 0 |
|
100 | self.integratorObjIndex = 0 | |
101 | self.writerObjIndex = 0 |
|
101 | self.writerObjIndex = 0 | |
102 | self.plotObjIndex = 0 |
|
102 | self.plotObjIndex = 0 | |
103 |
|
103 | |||
104 |
|
104 | |||
105 | if self.dataInObj.type == "Spectra": |
|
105 | if self.dataInObj.type == "Spectra": | |
106 |
|
106 | |||
107 | self.dataOutObj.copy(self.dataInObj) |
|
107 | self.dataOutObj.copy(self.dataInObj) | |
108 | self.dataOutObj.flagNoData = False |
|
108 | self.dataOutObj.flagNoData = False | |
109 | return |
|
109 | return | |
110 |
|
110 | |||
111 | if self.dataInObj.type == "Voltage": |
|
111 | if self.dataInObj.type == "Voltage": | |
112 |
|
112 | |||
113 | if self.buffer == None: |
|
113 | if self.buffer == None: | |
114 | self.buffer = numpy.zeros((self.dataInObj.nChannels, |
|
114 | self.buffer = numpy.zeros((self.dataInObj.nChannels, | |
115 | self.dataOutObj.nFFTPoints, |
|
115 | self.dataOutObj.nFFTPoints, | |
116 | self.dataInObj.nHeights), |
|
116 | self.dataInObj.nHeights), | |
117 | dtype='complex') |
|
117 | dtype='complex') | |
118 |
|
118 | |||
119 | self.buffer[:,self.profIndex,:] = self.dataInObj.data |
|
119 | self.buffer[:,self.profIndex,:] = self.dataInObj.data | |
120 | self.profIndex += 1 |
|
120 | self.profIndex += 1 | |
121 |
|
121 | |||
122 | if self.profIndex == self.dataOutObj.nFFTPoints: |
|
122 | if self.profIndex == self.dataOutObj.nFFTPoints: | |
123 |
|
123 | |||
124 | self.__updateObjFromInput() |
|
124 | self.__updateObjFromInput() | |
125 | self.__getFft() |
|
125 | self.__getFft() | |
126 |
|
126 | |||
127 | self.dataOutObj.flagNoData = False |
|
127 | self.dataOutObj.flagNoData = False | |
128 |
|
128 | |||
129 | self.buffer = None |
|
129 | self.buffer = None | |
130 | self.profIndex = 0 |
|
130 | self.profIndex = 0 | |
131 |
|
131 | |||
132 | return |
|
132 | return | |
133 |
|
133 | |||
134 | #Other kind of data |
|
134 | #Other kind of data | |
135 | raise ValueError, "The type object %(s) is not valid " %(self.dataOutObj.type) |
|
135 | raise ValueError, "The type object %(s) is not valid " %(self.dataOutObj.type) | |
136 |
|
136 | |||
137 | def __getFft(self): |
|
137 | def __getFft(self): | |
138 | """ |
|
138 | """ | |
139 | Convierte valores de Voltaje a Spectra |
|
139 | Convierte valores de Voltaje a Spectra | |
140 |
|
140 | |||
141 | Affected: |
|
141 | Affected: | |
142 | self.dataOutObj.data_spc |
|
142 | self.dataOutObj.data_spc | |
143 | self.dataOutObj.data_cspc |
|
143 | self.dataOutObj.data_cspc | |
144 | self.dataOutObj.data_dc |
|
144 | self.dataOutObj.data_dc | |
145 | self.dataOutObj.heightList |
|
145 | self.dataOutObj.heightList | |
146 | self.dataOutObj.m_BasicHeader |
|
146 | self.dataOutObj.m_BasicHeader | |
147 | self.dataOutObj.m_ProcessingHeader |
|
147 | self.dataOutObj.m_ProcessingHeader | |
148 | self.dataOutObj.radarControllerHeaderObj |
|
148 | self.dataOutObj.radarControllerHeaderObj | |
149 | self.dataOutObj.systemHeaderObj |
|
149 | self.dataOutObj.systemHeaderObj | |
150 | self.profIndex |
|
150 | self.profIndex | |
151 | self.buffer |
|
151 | self.buffer | |
152 | self.dataOutObj.flagNoData |
|
152 | self.dataOutObj.flagNoData | |
153 | self.dataOutObj.dtype |
|
153 | self.dataOutObj.dtype | |
154 | self.dataOutObj.nPairs |
|
154 | self.dataOutObj.nPairs | |
155 | self.dataOutObj.nChannels |
|
155 | self.dataOutObj.nChannels | |
156 | self.dataOutObj.nProfiles |
|
156 | self.dataOutObj.nProfiles | |
157 | self.dataOutObj.systemHeaderObj.numChannels |
|
157 | self.dataOutObj.systemHeaderObj.numChannels | |
158 | self.dataOutObj.m_ProcessingHeader.totalSpectra |
|
158 | self.dataOutObj.m_ProcessingHeader.totalSpectra | |
159 | self.dataOutObj.m_ProcessingHeader.profilesPerBlock |
|
159 | self.dataOutObj.m_ProcessingHeader.profilesPerBlock | |
160 | self.dataOutObj.m_ProcessingHeader.numHeights |
|
160 | self.dataOutObj.m_ProcessingHeader.numHeights | |
161 | self.dataOutObj.m_ProcessingHeader.spectraComb |
|
161 | self.dataOutObj.m_ProcessingHeader.spectraComb | |
162 | self.dataOutObj.m_ProcessingHeader.shif_fft |
|
162 | self.dataOutObj.m_ProcessingHeader.shif_fft | |
163 | """ |
|
163 | """ | |
164 |
|
164 | |||
165 | fft_volt = numpy.fft.fft(self.buffer,axis=1) |
|
165 | fft_volt = numpy.fft.fft(self.buffer,axis=1) | |
166 | dc = fft_volt[:,0,:] |
|
166 | dc = fft_volt[:,0,:] | |
167 |
|
167 | |||
168 | #calculo de self-spectra |
|
168 | #calculo de self-spectra | |
169 | fft_volt = numpy.fft.fftshift(fft_volt,axes=(1,)) |
|
169 | fft_volt = numpy.fft.fftshift(fft_volt,axes=(1,)) | |
170 | spc = fft_volt * numpy.conjugate(fft_volt) |
|
170 | spc = fft_volt * numpy.conjugate(fft_volt) | |
171 | spc = spc.real |
|
171 | spc = spc.real | |
172 |
|
172 | |||
173 | blocksize = 0 |
|
173 | blocksize = 0 | |
174 | blocksize += dc.size |
|
174 | blocksize += dc.size | |
175 | blocksize += spc.size |
|
175 | blocksize += spc.size | |
176 |
|
176 | |||
177 | cspc = None |
|
177 | cspc = None | |
178 | pairIndex = 0 |
|
178 | pairIndex = 0 | |
179 | if self.dataOutObj.pairsList != None: |
|
179 | if self.dataOutObj.pairsList != None: | |
180 | #calculo de cross-spectra |
|
180 | #calculo de cross-spectra | |
181 | cspc = numpy.zeros((self.dataOutObj.nPairs, self.dataOutObj.nFFTPoints, self.dataOutObj.nHeights), dtype='complex') |
|
181 | cspc = numpy.zeros((self.dataOutObj.nPairs, self.dataOutObj.nFFTPoints, self.dataOutObj.nHeights), dtype='complex') | |
182 | for pair in self.dataOutObj.pairsList: |
|
182 | for pair in self.dataOutObj.pairsList: | |
183 | cspc[pairIndex,:,:] = numpy.abs(fft_volt[pair[0],:,:] * numpy.conjugate(fft_volt[pair[1],:,:])) |
|
183 | cspc[pairIndex,:,:] = numpy.abs(fft_volt[pair[0],:,:] * numpy.conjugate(fft_volt[pair[1],:,:])) | |
184 | pairIndex += 1 |
|
184 | pairIndex += 1 | |
185 | blocksize += cspc.size |
|
185 | blocksize += cspc.size | |
186 |
|
186 | |||
187 | self.dataOutObj.data_spc = spc |
|
187 | self.dataOutObj.data_spc = spc | |
188 | self.dataOutObj.data_cspc = cspc |
|
188 | self.dataOutObj.data_cspc = cspc | |
189 | self.dataOutObj.data_dc = dc |
|
189 | self.dataOutObj.data_dc = dc | |
190 | self.dataOutObj.blockSize = blocksize |
|
190 | self.dataOutObj.blockSize = blocksize | |
191 |
|
191 | |||
192 | # self.getNoise() |
|
192 | # self.getNoise() | |
193 |
|
193 | |||
194 | def __updateObjFromInput(self): |
|
194 | def __updateObjFromInput(self): | |
195 |
|
195 | |||
196 | self.dataOutObj.radarControllerHeaderObj = self.dataInObj.radarControllerHeaderObj.copy() |
|
196 | self.dataOutObj.radarControllerHeaderObj = self.dataInObj.radarControllerHeaderObj.copy() | |
197 | self.dataOutObj.systemHeaderObj = self.dataInObj.systemHeaderObj.copy() |
|
197 | self.dataOutObj.systemHeaderObj = self.dataInObj.systemHeaderObj.copy() | |
198 | self.dataOutObj.channelList = self.dataInObj.channelList |
|
198 | self.dataOutObj.channelList = self.dataInObj.channelList | |
199 | self.dataOutObj.heightList = self.dataInObj.heightList |
|
199 | self.dataOutObj.heightList = self.dataInObj.heightList | |
200 | self.dataOutObj.dtype = self.dataInObj.dtype |
|
200 | self.dataOutObj.dtype = self.dataInObj.dtype | |
201 | self.dataOutObj.nHeights = self.dataInObj.nHeights |
|
201 | self.dataOutObj.nHeights = self.dataInObj.nHeights | |
202 | self.dataOutObj.nChannels = self.dataInObj.nChannels |
|
202 | self.dataOutObj.nChannels = self.dataInObj.nChannels | |
203 | self.dataOutObj.nBaud = self.dataInObj.nBaud |
|
203 | self.dataOutObj.nBaud = self.dataInObj.nBaud | |
204 | self.dataOutObj.nCode = self.dataInObj.nCode |
|
204 | self.dataOutObj.nCode = self.dataInObj.nCode | |
205 | self.dataOutObj.code = self.dataInObj.code |
|
205 | self.dataOutObj.code = self.dataInObj.code | |
206 | self.dataOutObj.nProfiles = self.dataOutObj.nFFTPoints |
|
206 | self.dataOutObj.nProfiles = self.dataOutObj.nFFTPoints | |
207 | self.dataOutObj.channelIndexList = self.dataInObj.channelIndexList |
|
207 | self.dataOutObj.channelIndexList = self.dataInObj.channelIndexList | |
208 | self.dataOutObj.flagTimeBlock = self.dataInObj.flagTimeBlock |
|
208 | self.dataOutObj.flagTimeBlock = self.dataInObj.flagTimeBlock | |
209 | self.dataOutObj.utctime = self.dataInObj.utctime |
|
209 | self.dataOutObj.utctime = self.dataInObj.utctime | |
210 | self.dataOutObj.flagDecodeData = self.dataInObj.flagDecodeData #asumo q la data esta decodificada |
|
210 | self.dataOutObj.flagDecodeData = self.dataInObj.flagDecodeData #asumo q la data esta decodificada | |
211 | self.dataOutObj.flagDeflipData = self.dataInObj.flagDeflipData #asumo q la data esta sin flip |
|
211 | self.dataOutObj.flagDeflipData = self.dataInObj.flagDeflipData #asumo q la data esta sin flip | |
212 | self.dataOutObj.flagShiftFFT = self.dataInObj.flagShiftFFT |
|
212 | self.dataOutObj.flagShiftFFT = self.dataInObj.flagShiftFFT | |
213 | self.dataOutObj.nIncohInt = 1 |
|
213 | self.dataOutObj.nIncohInt = 1 | |
|
214 | self.dataOutObj.ippSeconds = self.dataInObj.ippSeconds | |||
|
215 | self.dataOutObj.timeInterval = self.dataInObj.timeInterval | |||
214 |
|
216 | |||
215 | def addWriter(self, wrpath, blocksPerFile): |
|
217 | def addWriter(self, wrpath, blocksPerFile): | |
216 |
|
218 | |||
217 | objWriter = SpectraWriter(self.dataOutObj) |
|
219 | objWriter = SpectraWriter(self.dataOutObj) | |
218 | objWriter.setup(wrpath, blocksPerFile) |
|
220 | objWriter.setup(wrpath, blocksPerFile) | |
219 | self.writerObjList.append(objWriter) |
|
221 | self.writerObjList.append(objWriter) | |
220 |
|
222 | |||
221 | def addIntegrator(self,N,timeInterval): |
|
223 | def addIntegrator(self,N,timeInterval): | |
222 |
|
224 | |||
223 | objIncohInt = IncoherentIntegration(N,timeInterval) |
|
225 | objIncohInt = IncoherentIntegration(N,timeInterval) | |
224 | self.integratorObjList.append(objIncohInt) |
|
226 | self.integratorObjList.append(objIncohInt) | |
225 |
|
227 | |||
226 | def addCrossSpc(self, idfigure, nframes, wintitle, driver, colormap, colorbar, showprofile): |
|
228 | def addCrossSpc(self, idfigure, nframes, wintitle, driver, colormap, colorbar, showprofile): | |
227 | crossSpcObj = CrossSpcFigure(idfigure, nframes, wintitle, driver, colormap, colorbar, showprofile) |
|
229 | crossSpcObj = CrossSpcFigure(idfigure, nframes, wintitle, driver, colormap, colorbar, showprofile) | |
228 | self.plotObjList.append(crossSpcObj) |
|
230 | self.plotObjList.append(crossSpcObj) | |
229 |
|
231 | |||
230 | def plotCrossSpc(self, idfigure=None, |
|
232 | def plotCrossSpc(self, idfigure=None, | |
231 | xmin=None, |
|
233 | xmin=None, | |
232 | xmax=None, |
|
234 | xmax=None, | |
233 | ymin=None, |
|
235 | ymin=None, | |
234 | ymax=None, |
|
236 | ymax=None, | |
235 | minvalue=None, |
|
237 | minvalue=None, | |
236 | maxvalue=None, |
|
238 | maxvalue=None, | |
237 | wintitle='', |
|
239 | wintitle='', | |
238 | driver='plplot', |
|
240 | driver='plplot', | |
239 | colormap='br_green', |
|
241 | colormap='br_green', | |
240 | colorbar=True, |
|
242 | colorbar=True, | |
241 | showprofile=False, |
|
243 | showprofile=False, | |
242 | save=False, |
|
244 | save=False, | |
243 | gpath=None, |
|
245 | gpath=None, | |
244 | pairsList = None): |
|
246 | pairsList = None): | |
245 |
|
247 | |||
246 | if self.dataOutObj.flagNoData: |
|
248 | if self.dataOutObj.flagNoData: | |
247 | return 0 |
|
249 | return 0 | |
248 |
|
250 | |||
249 | if pairsList == None: |
|
251 | if pairsList == None: | |
250 | pairsList = self.dataOutObj.pairsList |
|
252 | pairsList = self.dataOutObj.pairsList | |
251 |
|
253 | |||
252 | nframes = len(pairsList) |
|
254 | nframes = len(pairsList) | |
253 |
|
255 | |||
254 | x = numpy.arange(self.dataOutObj.nFFTPoints) |
|
256 | x = numpy.arange(self.dataOutObj.nFFTPoints) | |
255 |
|
257 | |||
256 | y = self.dataOutObj.heightList |
|
258 | y = self.dataOutObj.heightList | |
257 |
|
259 | |||
258 |
|
260 | |||
259 |
|
261 | |||
260 |
|
262 | |||
261 | if len(self.plotObjList) <= self.plotObjIndex: |
|
263 | if len(self.plotObjList) <= self.plotObjIndex: | |
262 | self.addSpc(idfigure, nframes, wintitle, driver, colormap, colorbar, showprofile) |
|
264 | self.addSpc(idfigure, nframes, wintitle, driver, colormap, colorbar, showprofile) | |
263 |
|
265 | |||
|
266 | def addRti(self, idfigure, nframes, wintitle, driver, colormap, colorbar, showprofile): | |||
|
267 | rtiObj = RTIFigure(idfigure, nframes, wintitle, driver, colormap, colorbar, showprofile) | |||
|
268 | self.plotObjList.append(rtiObj) | |||
|
269 | ||||
|
270 | def plotRti(self, idfigure=None, | |||
|
271 | starttime=None, | |||
|
272 | endtime=None, | |||
|
273 | rangemin=None, | |||
|
274 | rangemax=None, | |||
|
275 | minvalue=None, | |||
|
276 | maxvalue=None, | |||
|
277 | wintitle='', | |||
|
278 | driver='plplot', | |||
|
279 | colormap='br_greeen', | |||
|
280 | colorbar=True, | |||
|
281 | showprofile=False, | |||
|
282 | xrangestep=None, | |||
|
283 | save=False, | |||
|
284 | gpath=None, | |||
|
285 | ratio=1, | |||
|
286 | channelList=None): | |||
|
287 | ||||
|
288 | if self.dataOutObj.flagNoData: | |||
|
289 | return 0 | |||
|
290 | ||||
|
291 | if channelList == None: | |||
|
292 | channelList = self.dataOutObj.channelList | |||
|
293 | ||||
|
294 | nframes = len(channelList) | |||
|
295 | ||||
|
296 | if len(self.plotObjList) <= self.plotObjIndex: | |||
|
297 | self.addRti(idfigure, nframes, wintitle, driver, colormap, colorbar, showprofile) | |||
|
298 | ||||
|
299 | data = 10.*numpy.log10(self.dataOutObj.data_spc[channelList,:,:]) | |||
|
300 | ||||
|
301 | currenttime = self.dataOutObj.utctime - time.timezone | |||
|
302 | ||||
|
303 | range = self.dataOutObj.heightList | |||
|
304 | ||||
|
305 | ||||
|
306 | figuretitle = "RTI Plot for Spectra Data" #+ date | |||
|
307 | ||||
|
308 | cleardata = False | |||
|
309 | ||||
|
310 | deltax = self.dataOutObj.timeInterval | |||
|
311 | ||||
|
312 | plotObj = self.plotObjList[self.plotObjIndex] | |||
|
313 | ||||
|
314 | ||||
|
315 | ||||
|
316 | ||||
|
317 | ||||
|
318 | self.plotObjIndex += 1 | |||
|
319 | ||||
|
320 | ||||
|
321 | ||||
|
322 | ||||
264 |
|
323 | |||
265 |
|
324 | |||
266 |
|
325 | |||
267 | def addSpc(self, idfigure, nframes, wintitle, driver, colormap, colorbar, showprofile): |
|
326 | def addSpc(self, idfigure, nframes, wintitle, driver, colormap, colorbar, showprofile): | |
268 |
|
327 | |||
269 | spcObj = SpcFigure(idfigure, nframes, wintitle, driver, colormap, colorbar, showprofile) |
|
328 | spcObj = SpcFigure(idfigure, nframes, wintitle, driver, colormap, colorbar, showprofile) | |
270 | self.plotObjList.append(spcObj) |
|
329 | self.plotObjList.append(spcObj) | |
271 |
|
330 | |||
272 | def plotSpc(self, idfigure=None, |
|
331 | def plotSpc(self, idfigure=None, | |
273 | xmin=None, |
|
332 | xmin=None, | |
274 | xmax=None, |
|
333 | xmax=None, | |
275 | ymin=None, |
|
334 | ymin=None, | |
276 | ymax=None, |
|
335 | ymax=None, | |
277 | minvalue=None, |
|
336 | minvalue=None, | |
278 | maxvalue=None, |
|
337 | maxvalue=None, | |
279 | wintitle='', |
|
338 | wintitle='', | |
280 | driver='plplot', |
|
339 | driver='plplot', | |
281 | colormap='br_green', |
|
340 | colormap='br_green', | |
282 | colorbar=True, |
|
341 | colorbar=True, | |
283 | showprofile=False, |
|
342 | showprofile=False, | |
284 | save=False, |
|
343 | save=False, | |
285 | gpath=None, |
|
344 | gpath=None, | |
286 | ratio=1, |
|
345 | ratio=1, | |
287 | channelList=None): |
|
346 | channelList=None): | |
288 |
|
347 | |||
289 | if self.dataOutObj.flagNoData: |
|
348 | if self.dataOutObj.flagNoData: | |
290 | return 0 |
|
349 | return 0 | |
291 |
|
350 | |||
292 | if channelList == None: |
|
351 | if channelList == None: | |
293 | channelList = self.dataOutObj.channelList |
|
352 | channelList = self.dataOutObj.channelList | |
294 |
|
353 | |||
295 | nframes = len(channelList) |
|
354 | nframes = len(channelList) | |
296 |
|
355 | |||
297 | if len(self.plotObjList) <= self.plotObjIndex: |
|
356 | if len(self.plotObjList) <= self.plotObjIndex: | |
298 | self.addSpc(idfigure, nframes, wintitle, driver, colormap, colorbar, showprofile) |
|
357 | self.addSpc(idfigure, nframes, wintitle, driver, colormap, colorbar, showprofile) | |
299 |
|
358 | |||
300 | x = numpy.arange(self.dataOutObj.nFFTPoints) |
|
359 | x = numpy.arange(self.dataOutObj.nFFTPoints) | |
301 |
|
360 | |||
302 | y = self.dataOutObj.heightList |
|
361 | y = self.dataOutObj.heightList | |
303 |
|
362 | |||
304 | data = 10.*numpy.log10(self.dataOutObj.data_spc[channelList,:,:]) |
|
363 | data = 10.*numpy.log10(self.dataOutObj.data_spc[channelList,:,:]) | |
305 | # noisedB = 10.*numpy.log10(noise) |
|
364 | # noisedB = 10.*numpy.log10(noise) | |
306 | noisedB = numpy.arange(len(channelList)+1) |
|
365 | noisedB = numpy.arange(len(channelList)+1) | |
307 | noisedB = noisedB *1.2 |
|
366 | noisedB = noisedB *1.2 | |
308 | titleList = [] |
|
367 | titleList = [] | |
309 | for i in range(len(noisedB)): |
|
368 | for i in range(len(noisedB)): | |
310 | title = "%.2f"%noisedB[i] |
|
369 | title = "%.2f"%noisedB[i] | |
311 | titleList.append(title) |
|
370 | titleList.append(title) | |
312 |
|
371 | |||
313 | thisdatetime = datetime.datetime.fromtimestamp(self.dataOutObj.utctime) |
|
372 | thisdatetime = datetime.datetime.fromtimestamp(self.dataOutObj.utctime) | |
314 | dateTime = "%s"%(thisdatetime.strftime("%d-%b-%Y %H:%M:%S")) |
|
373 | dateTime = "%s"%(thisdatetime.strftime("%d-%b-%Y %H:%M:%S")) | |
315 | figuretitle = "Spc Radar Data: %s"%dateTime |
|
374 | figuretitle = "Spc Radar Data: %s"%dateTime | |
316 |
|
375 | |||
317 | cleardata = True |
|
376 | cleardata = True | |
318 |
|
377 | |||
319 | plotObj = self.plotObjList[self.plotObjIndex] |
|
378 | plotObj = self.plotObjList[self.plotObjIndex] | |
320 |
|
379 | |||
321 | plotObj.plotPcolor(data=data, |
|
380 | plotObj.plotPcolor(data=data, | |
322 | x=x, |
|
381 | x=x, | |
323 | y=y, |
|
382 | y=y, | |
324 | channelList=channelList, |
|
383 | channelList=channelList, | |
325 | xmin=xmin, |
|
384 | xmin=xmin, | |
326 | xmax=xmax, |
|
385 | xmax=xmax, | |
327 | ymin=ymin, |
|
386 | ymin=ymin, | |
328 | ymax=ymax, |
|
387 | ymax=ymax, | |
329 | minvalue=minvalue, |
|
388 | minvalue=minvalue, | |
330 | maxvalue=maxvalue, |
|
389 | maxvalue=maxvalue, | |
331 | figuretitle=figuretitle, |
|
390 | figuretitle=figuretitle, | |
332 | xrangestep=None, |
|
391 | xrangestep=None, | |
333 | deltax=None, |
|
392 | deltax=None, | |
334 | save=save, |
|
393 | save=save, | |
335 | gpath=gpath, |
|
394 | gpath=gpath, | |
336 | cleardata=cleardata |
|
395 | cleardata=cleardata | |
337 | ) |
|
396 | ) | |
338 |
|
397 | |||
339 | self.plotObjIndex += 1 |
|
398 | self.plotObjIndex += 1 | |
340 |
|
399 | |||
341 |
|
400 | |||
342 | def writeData(self, wrpath, blocksPerFile): |
|
401 | def writeData(self, wrpath, blocksPerFile): | |
343 |
|
402 | |||
344 | if self.dataOutObj.flagNoData: |
|
403 | if self.dataOutObj.flagNoData: | |
345 | return 0 |
|
404 | return 0 | |
346 |
|
405 | |||
347 | if len(self.writerObjList) <= self.writerObjIndex: |
|
406 | if len(self.writerObjList) <= self.writerObjIndex: | |
348 | self.addWriter(wrpath, blocksPerFile) |
|
407 | self.addWriter(wrpath, blocksPerFile) | |
349 |
|
408 | |||
350 | self.writerObjList[self.writerObjIndex].putData() |
|
409 | self.writerObjList[self.writerObjIndex].putData() | |
351 |
|
410 | |||
352 | self.writerObjIndex += 1 |
|
411 | self.writerObjIndex += 1 | |
353 |
|
412 | |||
354 | def integrator(self, N=None, timeInterval=None): |
|
413 | def integrator(self, N=None, timeInterval=None): | |
355 |
|
414 | |||
356 | if self.dataOutObj.flagNoData: |
|
415 | if self.dataOutObj.flagNoData: | |
357 | return 0 |
|
416 | return 0 | |
358 |
|
417 | |||
359 | if len(self.integratorObjList) <= self.integratorObjIndex: |
|
418 | if len(self.integratorObjList) <= self.integratorObjIndex: | |
360 | self.addIntegrator(N,timeInterval) |
|
419 | self.addIntegrator(N,timeInterval) | |
361 |
|
420 | |||
362 | myIncohIntObj = self.integratorObjList[self.integratorObjIndex] |
|
421 | myIncohIntObj = self.integratorObjList[self.integratorObjIndex] | |
363 | myIncohIntObj.exe(data=self.dataOutObj.data_spc,timeOfData=self.dataOutObj.m_BasicHeader.utc) |
|
422 | myIncohIntObj.exe(data=self.dataOutObj.data_spc,timeOfData=self.dataOutObj.m_BasicHeader.utc) | |
364 |
|
423 | |||
365 | if myIncohIntObj.isReady: |
|
424 | if myIncohIntObj.isReady: | |
366 | self.dataOutObj.data_spc = myIncohIntObj.data |
|
425 | self.dataOutObj.data_spc = myIncohIntObj.data | |
367 | self.dataOutObj.nAvg = myIncohIntObj.navg |
|
426 | self.dataOutObj.nAvg = myIncohIntObj.navg | |
368 | self.dataOutObj.m_ProcessingHeader.incoherentInt = self.dataInObj.m_ProcessingHeader.incoherentInt*myIncohIntObj.navg |
|
427 | self.dataOutObj.m_ProcessingHeader.incoherentInt = self.dataInObj.m_ProcessingHeader.incoherentInt*myIncohIntObj.navg | |
369 | self.dataOutObj.flagNoData = False |
|
428 | self.dataOutObj.flagNoData = False | |
370 |
|
429 | |||
371 | """Calcular el ruido""" |
|
430 | """Calcular el ruido""" | |
372 | self.getNoise() |
|
431 | self.getNoise() | |
373 | else: |
|
432 | else: | |
374 | self.dataOutObj.flagNoData = True |
|
433 | self.dataOutObj.flagNoData = True | |
375 |
|
434 | |||
376 | self.integratorObjIndex += 1 |
|
435 | self.integratorObjIndex += 1 | |
377 |
|
436 | |||
378 |
|
437 | |||
379 | class SpectraHeisProcessor: |
|
438 | class SpectraHeisProcessor: | |
380 |
|
439 | |||
381 | def __init__(self): |
|
440 | def __init__(self): | |
382 |
|
441 | |||
383 | self.integratorObjIndex = None |
|
442 | self.integratorObjIndex = None | |
384 | self.writerObjIndex = None |
|
443 | self.writerObjIndex = None | |
385 | self.plotObjIndex = None |
|
444 | self.plotObjIndex = None | |
386 | self.integratorObjList = [] |
|
445 | self.integratorObjList = [] | |
387 | self.writerObjList = [] |
|
446 | self.writerObjList = [] | |
388 | self.plotObjList = [] |
|
447 | self.plotObjList = [] | |
389 | #self.noiseObj = Noise() |
|
448 | #self.noiseObj = Noise() | |
390 |
|
449 | |||
391 | def setup(self, dataInObj, dataOutObj=None, nFFTPoints=None, pairList=None): |
|
450 | def setup(self, dataInObj, dataOutObj=None, nFFTPoints=None, pairList=None): | |
392 |
|
451 | |||
393 | if nFFTPoints == None: |
|
452 | if nFFTPoints == None: | |
394 | nFFTPoints = self.dataInObj.nHeights |
|
453 | nFFTPoints = self.dataInObj.nHeights | |
395 |
|
454 | |||
396 | self.dataInObj = dataInObj |
|
455 | self.dataInObj = dataInObj | |
397 |
|
456 | |||
398 | if dataOutObj == None: |
|
457 | if dataOutObj == None: | |
399 | dataOutObj = SpectraHeis() |
|
458 | dataOutObj = SpectraHeis() | |
400 |
|
459 | |||
401 | self.dataOutObj = dataOutObj |
|
460 | self.dataOutObj = dataOutObj | |
402 |
|
461 | |||
403 | return self.dataOutObj |
|
462 | return self.dataOutObj | |
404 |
|
463 | |||
405 | def init(self): |
|
464 | def init(self): | |
406 |
|
465 | |||
407 | self.dataOutObj.flagNoData = True |
|
466 | self.dataOutObj.flagNoData = True | |
408 |
|
467 | |||
409 | if self.dataInObj.flagNoData: |
|
468 | if self.dataInObj.flagNoData: | |
410 | return 0 |
|
469 | return 0 | |
411 |
|
470 | |||
412 | self.integratorObjIndex = 0 |
|
471 | self.integratorObjIndex = 0 | |
413 | self.writerObjIndex = 0 |
|
472 | self.writerObjIndex = 0 | |
414 | self.plotObjIndex = 0 |
|
473 | self.plotObjIndex = 0 | |
415 |
|
474 | |||
416 | if self.dataInObj.type == "Voltage": |
|
475 | if self.dataInObj.type == "Voltage": | |
417 | self.__updateObjFromInput() |
|
476 | self.__updateObjFromInput() | |
418 | self.__getFft() |
|
477 | self.__getFft() | |
419 | self.dataOutObj.flagNoData = False |
|
478 | self.dataOutObj.flagNoData = False | |
420 | return |
|
479 | return | |
421 |
|
480 | |||
422 | #Other kind of data |
|
481 | #Other kind of data | |
423 | if self.dataInObj.type == "SpectraHeis": |
|
482 | if self.dataInObj.type == "SpectraHeis": | |
424 | self.dataOutObj.copy(self.dataInObj) |
|
483 | self.dataOutObj.copy(self.dataInObj) | |
425 | self.dataOutObj.flagNoData = False |
|
484 | self.dataOutObj.flagNoData = False | |
426 | return |
|
485 | return | |
427 |
|
486 | |||
428 | raise ValueError, "The type is not valid" |
|
487 | raise ValueError, "The type is not valid" | |
429 |
|
488 | |||
430 | def __updateObjFromInput(self): |
|
489 | def __updateObjFromInput(self): | |
431 |
|
490 | |||
432 | self.dataOutObj.radarControllerHeaderObj = self.dataInObj.radarControllerHeaderObj.copy() |
|
491 | self.dataOutObj.radarControllerHeaderObj = self.dataInObj.radarControllerHeaderObj.copy() | |
433 | self.dataOutObj.systemHeaderObj = self.dataInObj.systemHeaderObj.copy() |
|
492 | self.dataOutObj.systemHeaderObj = self.dataInObj.systemHeaderObj.copy() | |
434 | self.dataOutObj.channelList = self.dataInObj.channelList |
|
493 | self.dataOutObj.channelList = self.dataInObj.channelList | |
435 | self.dataOutObj.heightList = self.dataInObj.heightList |
|
494 | self.dataOutObj.heightList = self.dataInObj.heightList | |
436 | self.dataOutObj.dtype = self.dataInObj.dtype |
|
495 | self.dataOutObj.dtype = self.dataInObj.dtype | |
437 | self.dataOutObj.nHeights = self.dataInObj.nHeights |
|
496 | self.dataOutObj.nHeights = self.dataInObj.nHeights | |
438 | self.dataOutObj.nChannels = self.dataInObj.nChannels |
|
497 | self.dataOutObj.nChannels = self.dataInObj.nChannels | |
439 | self.dataOutObj.nBaud = self.dataInObj.nBaud |
|
498 | self.dataOutObj.nBaud = self.dataInObj.nBaud | |
440 | self.dataOutObj.nCode = self.dataInObj.nCode |
|
499 | self.dataOutObj.nCode = self.dataInObj.nCode | |
441 | self.dataOutObj.code = self.dataInObj.code |
|
500 | self.dataOutObj.code = self.dataInObj.code | |
442 | self.dataOutObj.nProfiles = 1 |
|
501 | self.dataOutObj.nProfiles = 1 | |
443 | self.dataOutObj.nFFTPoints = self.dataInObj.nHeights |
|
502 | self.dataOutObj.nFFTPoints = self.dataInObj.nHeights | |
444 | self.dataOutObj.channelIndexList = self.dataInObj.channelIndexList |
|
503 | self.dataOutObj.channelIndexList = self.dataInObj.channelIndexList | |
445 | self.dataOutObj.flagNoData = self.dataInObj.flagNoData |
|
504 | self.dataOutObj.flagNoData = self.dataInObj.flagNoData | |
446 | self.dataOutObj.flagTimeBlock = self.dataInObj.flagTimeBlock |
|
505 | self.dataOutObj.flagTimeBlock = self.dataInObj.flagTimeBlock | |
447 | self.dataOutObj.utctime = self.dataInObj.utctime |
|
506 | self.dataOutObj.utctime = self.dataInObj.utctime | |
448 | self.dataOutObj.flagDecodeData = self.dataInObj.flagDecodeData #asumo q la data esta decodificada |
|
507 | self.dataOutObj.flagDecodeData = self.dataInObj.flagDecodeData #asumo q la data esta decodificada | |
449 | self.dataOutObj.flagDeflipData = self.dataInObj.flagDeflipData #asumo q la data esta sin flip |
|
508 | self.dataOutObj.flagDeflipData = self.dataInObj.flagDeflipData #asumo q la data esta sin flip | |
450 | self.dataOutObj.flagShiftFFT = self.dataInObj.flagShiftFFT |
|
509 | self.dataOutObj.flagShiftFFT = self.dataInObj.flagShiftFFT | |
451 | self.dataOutObj.nIncohInt = 1 |
|
510 | self.dataOutObj.nIncohInt = 1 | |
452 |
|
511 | |||
453 | def __getFft(self): |
|
512 | def __getFft(self): | |
454 |
|
513 | |||
455 | fft_volt = numpy.fft.fft(self.dataInObj.data, axis=1) |
|
514 | fft_volt = numpy.fft.fft(self.dataInObj.data, axis=1) | |
456 | #print fft_volt |
|
515 | #print fft_volt | |
457 | #calculo de self-spectra |
|
516 | #calculo de self-spectra | |
458 | fft_volt = numpy.fft.fftshift(fft_volt,axes=(1,)) |
|
517 | fft_volt = numpy.fft.fftshift(fft_volt,axes=(1,)) | |
459 |
|
518 | |||
460 | spc = numpy.abs(fft_volt * numpy.conjugate(fft_volt)) |
|
519 | spc = numpy.abs(fft_volt * numpy.conjugate(fft_volt)) | |
461 | self.dataOutObj.data_spc = spc |
|
520 | self.dataOutObj.data_spc = spc | |
462 |
|
521 | |||
463 | def getSpectra(self): |
|
522 | def getSpectra(self): | |
464 |
|
523 | |||
465 | return self.dataOutObj.data_spc |
|
524 | return self.dataOutObj.data_spc | |
466 |
|
525 | |||
467 | def getFrecuencies(self): |
|
526 | def getFrecuencies(self): | |
468 |
|
527 | |||
469 | print self.nFFTPoints |
|
528 | print self.nFFTPoints | |
470 | return numpy.arange(int(self.nFFTPoints)) |
|
529 | return numpy.arange(int(self.nFFTPoints)) | |
471 |
|
530 | |||
472 | def addIntegrator(self,N,timeInterval): |
|
531 | def addIntegrator(self,N,timeInterval): | |
473 |
|
532 | |||
474 | objIncohInt = IncoherentIntegration(N,timeInterval) |
|
533 | objIncohInt = IncoherentIntegration(N,timeInterval) | |
475 | self.integratorObjList.append(objIncohInt) |
|
534 | self.integratorObjList.append(objIncohInt) | |
476 |
|
535 | |||
477 | def integrator(self, N=None, timeInterval=None): |
|
536 | def integrator(self, N=None, timeInterval=None): | |
478 |
|
537 | |||
479 | if self.dataOutObj.flagNoData: |
|
538 | if self.dataOutObj.flagNoData: | |
480 | return 0 |
|
539 | return 0 | |
481 |
|
540 | |||
482 | if len(self.integratorObjList) <= self.integratorObjIndex: |
|
541 | if len(self.integratorObjList) <= self.integratorObjIndex: | |
483 | self.addIntegrator(N,timeInterval) |
|
542 | self.addIntegrator(N,timeInterval) | |
484 |
|
543 | |||
485 | myIncohIntObj = self.integratorObjList[self.integratorObjIndex] |
|
544 | myIncohIntObj = self.integratorObjList[self.integratorObjIndex] | |
486 | myIncohIntObj.exe(data=self.dataOutObj.data_spc,timeOfData=self.dataOutObj.utctime) |
|
545 | myIncohIntObj.exe(data=self.dataOutObj.data_spc,timeOfData=self.dataOutObj.utctime) | |
487 |
|
546 | |||
488 | if myIncohIntObj.isReady: |
|
547 | if myIncohIntObj.isReady: | |
489 | self.dataOutObj.data_spc = myIncohIntObj.data |
|
548 | self.dataOutObj.data_spc = myIncohIntObj.data | |
490 | self.dataOutObj.nIncohInt = self.dataOutObj.nIncohInt*myIncohIntObj.navg |
|
549 | self.dataOutObj.nIncohInt = self.dataOutObj.nIncohInt*myIncohIntObj.navg | |
491 | self.dataOutObj.flagNoData = False |
|
550 | self.dataOutObj.flagNoData = False | |
492 |
|
551 | |||
493 | #self.getNoise(type="hildebrand",parm=myIncohIntObj.navg) |
|
552 | #self.getNoise(type="hildebrand",parm=myIncohIntObj.navg) | |
494 | # self.getNoise(type="sort", parm=16) |
|
553 | # self.getNoise(type="sort", parm=16) | |
495 |
|
554 | |||
496 | else: |
|
555 | else: | |
497 | self.dataOutObj.flagNoData = True |
|
556 | self.dataOutObj.flagNoData = True | |
498 |
|
557 | |||
499 | self.integratorObjIndex += 1 |
|
558 | self.integratorObjIndex += 1 | |
500 |
|
559 | |||
501 |
|
560 | |||
502 | def addScope(self, idfigure, nframes, wintitle, driver): |
|
561 | def addScope(self, idfigure, nframes, wintitle, driver): | |
503 |
|
562 | |||
504 | if idfigure==None: |
|
563 | if idfigure==None: | |
505 | idfigure = self.plotObjIndex |
|
564 | idfigure = self.plotObjIndex | |
506 |
|
565 | |||
507 | scopeObj = ScopeFigure(idfigure, nframes, wintitle, driver) |
|
566 | scopeObj = ScopeFigure(idfigure, nframes, wintitle, driver) | |
508 | self.plotObjList.append(scopeObj) |
|
567 | self.plotObjList.append(scopeObj) | |
509 |
|
568 | |||
510 | def plotScope(self, |
|
569 | def plotScope(self, | |
511 | idfigure=None, |
|
570 | idfigure=None, | |
512 | minvalue=None, |
|
571 | minvalue=None, | |
513 | maxvalue=None, |
|
572 | maxvalue=None, | |
514 | xmin=None, |
|
573 | xmin=None, | |
515 | xmax=None, |
|
574 | xmax=None, | |
516 | wintitle='', |
|
575 | wintitle='', | |
517 | driver='plplot', |
|
576 | driver='plplot', | |
518 | save=False, |
|
577 | save=False, | |
519 | gpath=None, |
|
578 | gpath=None, | |
520 | titleList=None, |
|
579 | titleList=None, | |
521 | xlabelList=None, |
|
580 | xlabelList=None, | |
522 | ylabelList=None): |
|
581 | ylabelList=None): | |
523 |
|
582 | |||
524 | if self.dataOutObj.flagNoData: |
|
583 | if self.dataOutObj.flagNoData: | |
525 | return 0 |
|
584 | return 0 | |
526 |
|
585 | |||
527 | nframes = len(self.dataOutObj.channelList) |
|
586 | nframes = len(self.dataOutObj.channelList) | |
528 |
|
587 | |||
529 | if len(self.plotObjList) <= self.plotObjIndex: |
|
588 | if len(self.plotObjList) <= self.plotObjIndex: | |
530 | self.addScope(idfigure, nframes, wintitle, driver) |
|
589 | self.addScope(idfigure, nframes, wintitle, driver) | |
531 |
|
590 | |||
532 |
|
591 | |||
533 | data1D = self.dataOutObj.data_spc |
|
592 | data1D = self.dataOutObj.data_spc | |
534 |
|
593 | |||
535 | x = numpy.arange(self.dataOutObj.nHeights) |
|
594 | x = numpy.arange(self.dataOutObj.nHeights) | |
536 |
|
595 | |||
537 | thisDatetime = datetime.datetime.fromtimestamp(self.dataOutObj.utctime) |
|
596 | thisDatetime = datetime.datetime.fromtimestamp(self.dataOutObj.utctime) | |
538 |
|
597 | |||
539 | dateTime = "%s"%(thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) |
|
598 | dateTime = "%s"%(thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) | |
540 | date = "%s"%(thisDatetime.strftime("%d-%b-%Y")) |
|
599 | date = "%s"%(thisDatetime.strftime("%d-%b-%Y")) | |
541 |
|
600 | |||
542 | figureTitle = "Scope Plot Radar Data: " + date |
|
601 | figureTitle = "Scope Plot Radar Data: " + date | |
543 |
|
602 | |||
544 | plotObj = self.plotObjList[self.plotObjIndex] |
|
603 | plotObj = self.plotObjList[self.plotObjIndex] | |
545 |
|
604 | |||
546 | plotObj.plot1DArray(data1D, |
|
605 | plotObj.plot1DArray(data1D, | |
547 | x, |
|
606 | x, | |
548 | self.dataOutObj.channelList, |
|
607 | self.dataOutObj.channelList, | |
549 | xmin, |
|
608 | xmin, | |
550 | xmax, |
|
609 | xmax, | |
551 | minvalue, |
|
610 | minvalue, | |
552 | maxvalue, |
|
611 | maxvalue, | |
553 | figureTitle, |
|
612 | figureTitle, | |
554 | save, |
|
613 | save, | |
555 | gpath) |
|
614 | gpath) | |
556 |
|
615 | |||
557 | self.plotObjIndex += 1 |
|
616 | self.plotObjIndex += 1 | |
558 |
|
617 | |||
559 | class IncoherentIntegration: |
|
618 | class IncoherentIntegration: | |
560 |
|
619 | |||
561 | integ_counter = None |
|
620 | integ_counter = None | |
562 | data = None |
|
621 | data = None | |
563 | navg = None |
|
622 | navg = None | |
564 | buffer = None |
|
623 | buffer = None | |
565 | nIncohInt = None |
|
624 | nIncohInt = None | |
566 |
|
625 | |||
567 | def __init__(self, N = None, timeInterval = None): |
|
626 | def __init__(self, N = None, timeInterval = None): | |
568 | """ |
|
627 | """ | |
569 | N |
|
628 | N | |
570 | timeInterval - interval time [min], integer value |
|
629 | timeInterval - interval time [min], integer value | |
571 | """ |
|
630 | """ | |
572 |
|
631 | |||
573 | self.data = None |
|
632 | self.data = None | |
574 | self.navg = None |
|
633 | self.navg = None | |
575 | self.buffer = None |
|
634 | self.buffer = None | |
576 | self.timeOut = None |
|
635 | self.timeOut = None | |
577 | self.exitCondition = False |
|
636 | self.exitCondition = False | |
578 | self.isReady = False |
|
637 | self.isReady = False | |
579 | self.nIncohInt = N |
|
638 | self.nIncohInt = N | |
580 | self.integ_counter = 0 |
|
639 | self.integ_counter = 0 | |
581 | if timeInterval!=None: |
|
640 | if timeInterval!=None: | |
582 | self.timeIntervalInSeconds = timeInterval * 60. #if (type(timeInterval)!=integer) -> change this line |
|
641 | self.timeIntervalInSeconds = timeInterval * 60. #if (type(timeInterval)!=integer) -> change this line | |
583 |
|
642 | |||
584 | if ((timeInterval==None) and (N==None)): |
|
643 | if ((timeInterval==None) and (N==None)): | |
585 | print 'N = None ; timeInterval = None' |
|
644 | print 'N = None ; timeInterval = None' | |
586 | sys.exit(0) |
|
645 | sys.exit(0) | |
587 | elif timeInterval == None: |
|
646 | elif timeInterval == None: | |
588 | self.timeFlag = False |
|
647 | self.timeFlag = False | |
589 | else: |
|
648 | else: | |
590 | self.timeFlag = True |
|
649 | self.timeFlag = True | |
591 |
|
650 | |||
592 |
|
651 | |||
593 | def exe(self,data,timeOfData): |
|
652 | def exe(self,data,timeOfData): | |
594 | """ |
|
653 | """ | |
595 | data |
|
654 | data | |
596 |
|
655 | |||
597 | timeOfData [seconds] |
|
656 | timeOfData [seconds] | |
598 | """ |
|
657 | """ | |
599 |
|
658 | |||
600 | if self.timeFlag: |
|
659 | if self.timeFlag: | |
601 | if self.timeOut == None: |
|
660 | if self.timeOut == None: | |
602 | self.timeOut = timeOfData + self.timeIntervalInSeconds |
|
661 | self.timeOut = timeOfData + self.timeIntervalInSeconds | |
603 |
|
662 | |||
604 | if timeOfData < self.timeOut: |
|
663 | if timeOfData < self.timeOut: | |
605 | if self.buffer == None: |
|
664 | if self.buffer == None: | |
606 | self.buffer = data |
|
665 | self.buffer = data | |
607 | else: |
|
666 | else: | |
608 | self.buffer = self.buffer + data |
|
667 | self.buffer = self.buffer + data | |
609 | self.integ_counter += 1 |
|
668 | self.integ_counter += 1 | |
610 | else: |
|
669 | else: | |
611 | self.exitCondition = True |
|
670 | self.exitCondition = True | |
612 |
|
671 | |||
613 | else: |
|
672 | else: | |
614 | if self.integ_counter < self.nIncohInt: |
|
673 | if self.integ_counter < self.nIncohInt: | |
615 | if self.buffer == None: |
|
674 | if self.buffer == None: | |
616 | self.buffer = data |
|
675 | self.buffer = data | |
617 | else: |
|
676 | else: | |
618 | self.buffer = self.buffer + data |
|
677 | self.buffer = self.buffer + data | |
619 |
|
678 | |||
620 | self.integ_counter += 1 |
|
679 | self.integ_counter += 1 | |
621 |
|
680 | |||
622 | if self.integ_counter == self.nIncohInt: |
|
681 | if self.integ_counter == self.nIncohInt: | |
623 | self.exitCondition = True |
|
682 | self.exitCondition = True | |
624 |
|
683 | |||
625 | if self.exitCondition: |
|
684 | if self.exitCondition: | |
626 | self.data = self.buffer |
|
685 | self.data = self.buffer | |
627 | self.navg = self.integ_counter |
|
686 | self.navg = self.integ_counter | |
628 | self.isReady = True |
|
687 | self.isReady = True | |
629 | self.buffer = None |
|
688 | self.buffer = None | |
630 | self.timeOut = None |
|
689 | self.timeOut = None | |
631 | self.integ_counter = 0 |
|
690 | self.integ_counter = 0 | |
632 | self.exitCondition = False |
|
691 | self.exitCondition = False | |
633 |
|
692 | |||
634 | if self.timeFlag: |
|
693 | if self.timeFlag: | |
635 | self.buffer = data |
|
694 | self.buffer = data | |
636 | self.timeOut = timeOfData + self.timeIntervalInSeconds |
|
695 | self.timeOut = timeOfData + self.timeIntervalInSeconds | |
637 | else: |
|
696 | else: | |
638 | self.isReady = False |
|
697 | self.isReady = False | |
639 | No newline at end of file |
|
698 |
@@ -1,419 +1,419 | |||||
1 | ''' |
|
1 | ''' | |
2 |
|
2 | |||
3 | $Author$ |
|
3 | $Author$ | |
4 | $Id$ |
|
4 | $Id$ | |
5 | ''' |
|
5 | ''' | |
6 |
|
6 | |||
7 | import os |
|
7 | import os | |
8 | import sys |
|
8 | import sys | |
9 | import numpy |
|
9 | import numpy | |
10 | import datetime |
|
10 | import datetime | |
11 | import time |
|
11 | import time | |
12 |
|
12 | |||
13 | path = os.path.split(os.getcwd())[0] |
|
13 | path = os.path.split(os.getcwd())[0] | |
14 | sys.path.append(path) |
|
14 | sys.path.append(path) | |
15 |
|
15 | |||
16 | from Data.JROData import Voltage |
|
16 | from Data.JROData import Voltage | |
17 | from IO.VoltageIO import VoltageWriter |
|
17 | from IO.VoltageIO import VoltageWriter | |
18 | from Graphics.schainPlotTypes import ScopeFigure, RTIFigure |
|
18 | from Graphics.schainPlotTypes import ScopeFigure, RTIFigure | |
19 |
|
19 | |||
20 | class VoltageProcessor: |
|
20 | class VoltageProcessor: | |
21 |
|
21 | |||
22 | dataInObj = None |
|
22 | dataInObj = None | |
23 | dataOutObj = None |
|
23 | dataOutObj = None | |
24 | integratorObjIndex = None |
|
24 | integratorObjIndex = None | |
25 | writerObjIndex = None |
|
25 | writerObjIndex = None | |
26 | integratorObjList = None |
|
26 | integratorObjList = None | |
27 | writerObjList = None |
|
27 | writerObjList = None | |
28 |
|
28 | |||
29 | def __init__(self): |
|
29 | def __init__(self): | |
30 | self.integratorObjIndex = None |
|
30 | self.integratorObjIndex = None | |
31 | self.writerObjIndex = None |
|
31 | self.writerObjIndex = None | |
32 | self.plotObjIndex = None |
|
32 | self.plotObjIndex = None | |
33 | self.integratorObjList = [] |
|
33 | self.integratorObjList = [] | |
34 | self.writerObjList = [] |
|
34 | self.writerObjList = [] | |
35 | self.plotObjList = [] |
|
35 | self.plotObjList = [] | |
36 |
|
36 | |||
37 | def setup(self,dataInObj=None,dataOutObj=None): |
|
37 | def setup(self,dataInObj=None,dataOutObj=None): | |
38 | self.dataInObj = dataInObj |
|
38 | self.dataInObj = dataInObj | |
39 |
|
39 | |||
40 | if self.dataOutObj == None: |
|
40 | if self.dataOutObj == None: | |
41 | dataOutObj = Voltage() |
|
41 | dataOutObj = Voltage() | |
42 |
|
42 | |||
43 | self.dataOutObj = dataOutObj |
|
43 | self.dataOutObj = dataOutObj | |
44 |
|
44 | |||
45 | return self.dataOutObj |
|
45 | return self.dataOutObj | |
46 |
|
46 | |||
47 | def init(self): |
|
47 | def init(self): | |
48 | self.integratorObjIndex = 0 |
|
48 | self.integratorObjIndex = 0 | |
49 | self.writerObjIndex = 0 |
|
49 | self.writerObjIndex = 0 | |
50 | self.plotObjIndex = 0 |
|
50 | self.plotObjIndex = 0 | |
51 |
|
51 | |||
52 | if not(self.dataInObj.flagNoData): |
|
52 | if not(self.dataInObj.flagNoData): | |
53 | self.dataOutObj.copy(self.dataInObj) |
|
53 | self.dataOutObj.copy(self.dataInObj) | |
54 | # No necesita copiar en cada init() los atributos de dataInObj |
|
54 | # No necesita copiar en cada init() los atributos de dataInObj | |
55 | # la copia deberia hacerse por cada nuevo bloque de datos |
|
55 | # la copia deberia hacerse por cada nuevo bloque de datos | |
56 |
|
56 | |||
57 | def addRti(self, idfigure, nframes, wintitle, driver, colormap, colorbar, showprofile): |
|
57 | def addRti(self, idfigure, nframes, wintitle, driver, colormap, colorbar, showprofile): | |
58 | rtiObj = RTIFigure(idfigure, nframes, wintitle, driver, colormap, colorbar, showprofile) |
|
58 | rtiObj = RTIFigure(idfigure, nframes, wintitle, driver, colormap, colorbar, showprofile) | |
59 | self.plotObjList.append(rtiObj) |
|
59 | self.plotObjList.append(rtiObj) | |
60 |
|
60 | |||
61 | def plotRti(self, idfigure=None, |
|
61 | def plotRti(self, idfigure=None, | |
62 | starttime=None, |
|
62 | starttime=None, | |
63 | endtime=None, |
|
63 | endtime=None, | |
64 | rangemin=None, |
|
64 | rangemin=None, | |
65 | rangemax=None, |
|
65 | rangemax=None, | |
66 | minvalue=None, |
|
66 | minvalue=None, | |
67 | maxvalue=None, |
|
67 | maxvalue=None, | |
68 | wintitle='', |
|
68 | wintitle='', | |
69 | driver='plplot', |
|
69 | driver='plplot', | |
70 | colormap='br_greeen', |
|
70 | colormap='br_greeen', | |
71 | colorbar=True, |
|
71 | colorbar=True, | |
72 | showprofile=False, |
|
72 | showprofile=False, | |
73 | xrangestep=None, |
|
73 | xrangestep=None, | |
74 | save=False, |
|
74 | save=False, | |
75 | gpath=None, |
|
75 | gpath=None, | |
76 | ratio=1, |
|
76 | ratio=1, | |
77 | channelList=None): |
|
77 | channelList=None): | |
78 |
|
78 | |||
79 | if self.dataOutObj.flagNoData: |
|
79 | if self.dataOutObj.flagNoData: | |
80 | return 0 |
|
80 | return 0 | |
81 |
|
81 | |||
82 | if channelList == None: |
|
82 | if channelList == None: | |
83 | channelList = self.dataOutObj.channelList |
|
83 | channelList = self.dataOutObj.channelList | |
84 |
|
84 | |||
85 | nframes = len(channelList) |
|
85 | nframes = len(channelList) | |
86 |
|
86 | |||
87 | if len(self.plotObjList) <= self.plotObjIndex: |
|
87 | if len(self.plotObjList) <= self.plotObjIndex: | |
88 | self.addRti(idfigure, nframes, wintitle, driver, colormap, colorbar, showprofile) |
|
88 | self.addRti(idfigure, nframes, wintitle, driver, colormap, colorbar, showprofile) | |
89 |
|
89 | |||
90 | data = self.dataOutObj.data[channelList,:] * numpy.conjugate(self.dataOutObj.data[channelList,:]) |
|
90 | data = self.dataOutObj.data[channelList,:] * numpy.conjugate(self.dataOutObj.data[channelList,:]) | |
91 | data = 10*numpy.log10(data.real) |
|
91 | data = 10*numpy.log10(data.real) | |
92 |
|
92 | |||
93 | currenttime = self.dataOutObj.utctime - time.timezone |
|
93 | currenttime = self.dataOutObj.utctime - time.timezone | |
94 |
|
94 | |||
95 | range = self.dataOutObj.heightList |
|
95 | range = self.dataOutObj.heightList | |
96 |
|
96 | |||
97 | thisdatetime = datetime.datetime.fromtimestamp(self.dataOutObj.utctime) |
|
97 | thisdatetime = datetime.datetime.fromtimestamp(self.dataOutObj.utctime) | |
98 | dateTime = "%s"%(thisdatetime.strftime("%d-%b-%Y %H:%M:%S")) |
|
98 | dateTime = "%s"%(thisdatetime.strftime("%d-%b-%Y %H:%M:%S")) | |
99 | date = "%s"%(thisdatetime.strftime("%d-%b-%Y")) |
|
99 | date = "%s"%(thisdatetime.strftime("%d-%b-%Y")) | |
100 | print thisdatetime |
|
100 | ||
101 | figuretitle = "RTI Plot Radar Data" #+ date |
|
101 | figuretitle = "RTI Plot Radar Data" #+ date | |
102 |
|
102 | |||
103 | plotObj = self.plotObjList[self.plotObjIndex] |
|
103 | plotObj = self.plotObjList[self.plotObjIndex] | |
104 |
|
104 | |||
105 | cleardata = False |
|
105 | cleardata = False | |
106 |
|
106 | |||
107 | deltax = self.dataOutObj.timeInterval |
|
107 | deltax = self.dataOutObj.timeInterval | |
108 |
|
108 | |||
109 | plotObj.plotPcolor(data=data, |
|
109 | plotObj.plotPcolor(data=data, | |
110 | x=currenttime, |
|
110 | x=currenttime, | |
111 | y=range, |
|
111 | y=range, | |
112 | channelList=channelList, |
|
112 | channelList=channelList, | |
113 | xmin=starttime, |
|
113 | xmin=starttime, | |
114 | xmax=endtime, |
|
114 | xmax=endtime, | |
115 | ymin=rangemin, |
|
115 | ymin=rangemin, | |
116 | ymax=rangemax, |
|
116 | ymax=rangemax, | |
117 | minvalue=minvalue, |
|
117 | minvalue=minvalue, | |
118 | maxvalue=maxvalue, |
|
118 | maxvalue=maxvalue, | |
119 | figuretitle=figuretitle, |
|
119 | figuretitle=figuretitle, | |
120 | xrangestep=xrangestep, |
|
120 | xrangestep=xrangestep, | |
121 | deltax=deltax, |
|
121 | deltax=deltax, | |
122 | save=save, |
|
122 | save=save, | |
123 | gpath=gpath, |
|
123 | gpath=gpath, | |
124 | ratio=ratio, |
|
124 | ratio=ratio, | |
125 | cleardata=cleardata |
|
125 | cleardata=cleardata | |
126 | ) |
|
126 | ) | |
127 |
|
127 | |||
128 |
|
128 | |||
129 | self.plotObjIndex += 1 |
|
129 | self.plotObjIndex += 1 | |
130 |
|
130 | |||
131 | def addScope(self, idfigure, nframes, wintitle, driver): |
|
131 | def addScope(self, idfigure, nframes, wintitle, driver): | |
132 | if idfigure==None: |
|
132 | if idfigure==None: | |
133 | idfigure = self.plotObjIndex |
|
133 | idfigure = self.plotObjIndex | |
134 |
|
134 | |||
135 | scopeObj = ScopeFigure(idfigure, nframes, wintitle, driver) |
|
135 | scopeObj = ScopeFigure(idfigure, nframes, wintitle, driver) | |
136 | self.plotObjList.append(scopeObj) |
|
136 | self.plotObjList.append(scopeObj) | |
137 |
|
137 | |||
138 | def plotScope(self, |
|
138 | def plotScope(self, | |
139 | idfigure=None, |
|
139 | idfigure=None, | |
140 | minvalue=None, |
|
140 | minvalue=None, | |
141 | maxvalue=None, |
|
141 | maxvalue=None, | |
142 | xmin=None, |
|
142 | xmin=None, | |
143 | xmax=None, |
|
143 | xmax=None, | |
144 | wintitle='', |
|
144 | wintitle='', | |
145 | driver='plplot', |
|
145 | driver='plplot', | |
146 | save=False, |
|
146 | save=False, | |
147 | gpath=None, |
|
147 | gpath=None, | |
148 | ratio=1, |
|
148 | ratio=1, | |
149 | type="power"): |
|
149 | type="power"): | |
150 |
|
150 | |||
151 | if self.dataOutObj.flagNoData: |
|
151 | if self.dataOutObj.flagNoData: | |
152 | return 0 |
|
152 | return 0 | |
153 |
|
153 | |||
154 | nframes = len(self.dataOutObj.channelList) |
|
154 | nframes = len(self.dataOutObj.channelList) | |
155 |
|
155 | |||
156 | if len(self.plotObjList) <= self.plotObjIndex: |
|
156 | if len(self.plotObjList) <= self.plotObjIndex: | |
157 | self.addScope(idfigure, nframes, wintitle, driver) |
|
157 | self.addScope(idfigure, nframes, wintitle, driver) | |
158 |
|
158 | |||
159 |
|
159 | |||
160 | if type=="power": |
|
160 | if type=="power": | |
161 | data1D = self.dataOutObj.data * numpy.conjugate(self.dataOutObj.data) |
|
161 | data1D = self.dataOutObj.data * numpy.conjugate(self.dataOutObj.data) | |
162 | data1D = data1D.real |
|
162 | data1D = data1D.real | |
163 |
|
163 | |||
164 | if type =="iq": |
|
164 | if type =="iq": | |
165 | data1D = self.dataOutObj.data |
|
165 | data1D = self.dataOutObj.data | |
166 |
|
166 | |||
167 | thisDatetime = datetime.datetime.fromtimestamp(self.dataOutObj.utctime) |
|
167 | thisDatetime = datetime.datetime.fromtimestamp(self.dataOutObj.utctime) | |
168 |
|
168 | |||
169 | dateTime = "%s"%(thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) |
|
169 | dateTime = "%s"%(thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) | |
170 | date = "%s"%(thisDatetime.strftime("%d-%b-%Y")) |
|
170 | date = "%s"%(thisDatetime.strftime("%d-%b-%Y")) | |
171 |
|
171 | |||
172 | figuretitle = "Scope Plot Radar Data: " + date |
|
172 | figuretitle = "Scope Plot Radar Data: " + date | |
173 |
|
173 | |||
174 | plotObj = self.plotObjList[self.plotObjIndex] |
|
174 | plotObj = self.plotObjList[self.plotObjIndex] | |
175 |
|
175 | |||
176 | plotObj.plot1DArray(data1D=data1D, |
|
176 | plotObj.plot1DArray(data1D=data1D, | |
177 | x=self.dataOutObj.heightList, |
|
177 | x=self.dataOutObj.heightList, | |
178 | channelList=self.dataOutObj.channelList, |
|
178 | channelList=self.dataOutObj.channelList, | |
179 | xmin=xmin, |
|
179 | xmin=xmin, | |
180 | xmax=xmax, |
|
180 | xmax=xmax, | |
181 | minvalue=minvalue, |
|
181 | minvalue=minvalue, | |
182 | maxvalue=maxvalue, |
|
182 | maxvalue=maxvalue, | |
183 | figuretitle=figuretitle, |
|
183 | figuretitle=figuretitle, | |
184 | save=save, |
|
184 | save=save, | |
185 | gpath=gpath, |
|
185 | gpath=gpath, | |
186 | ratio=ratio) |
|
186 | ratio=ratio) | |
187 |
|
187 | |||
188 |
|
188 | |||
189 | self.plotObjIndex += 1 |
|
189 | self.plotObjIndex += 1 | |
190 |
|
190 | |||
191 |
|
191 | |||
192 | def addIntegrator(self, *args): |
|
192 | def addIntegrator(self, *args): | |
193 | objCohInt = CoherentIntegrator(*args) |
|
193 | objCohInt = CoherentIntegrator(*args) | |
194 | self.integratorObjList.append(objCohInt) |
|
194 | self.integratorObjList.append(objCohInt) | |
195 |
|
195 | |||
196 | def addWriter(self, *args): |
|
196 | def addWriter(self, *args): | |
197 | writerObj = VoltageWriter(self.dataOutObj) |
|
197 | writerObj = VoltageWriter(self.dataOutObj) | |
198 | writerObj.setup(*args) |
|
198 | writerObj.setup(*args) | |
199 | self.writerObjList.append(writerObj) |
|
199 | self.writerObjList.append(writerObj) | |
200 |
|
200 | |||
201 | def writeData(self, wrpath, blocksPerFile, profilesPerBlock): |
|
201 | def writeData(self, wrpath, blocksPerFile, profilesPerBlock): | |
202 |
|
202 | |||
203 | if self.dataOutObj.flagNoData: |
|
203 | if self.dataOutObj.flagNoData: | |
204 | return 0 |
|
204 | return 0 | |
205 |
|
205 | |||
206 | if len(self.writerObjList) <= self.writerObjIndex: |
|
206 | if len(self.writerObjList) <= self.writerObjIndex: | |
207 | self.addWriter(wrpath, blocksPerFile, profilesPerBlock) |
|
207 | self.addWriter(wrpath, blocksPerFile, profilesPerBlock) | |
208 |
|
208 | |||
209 | self.writerObjList[self.writerObjIndex].putData() |
|
209 | self.writerObjList[self.writerObjIndex].putData() | |
210 |
|
210 | |||
211 | self.writerObjIndex += 1 |
|
211 | self.writerObjIndex += 1 | |
212 |
|
212 | |||
213 | def integrator(self, nCohInt=None, timeInterval=None, overlapping=False): |
|
213 | def integrator(self, nCohInt=None, timeInterval=None, overlapping=False): | |
214 |
|
214 | |||
215 | if self.dataOutObj.flagNoData: |
|
215 | if self.dataOutObj.flagNoData: | |
216 | return 0 |
|
216 | return 0 | |
217 |
|
217 | |||
218 | if len(self.integratorObjList) <= self.integratorObjIndex: |
|
218 | if len(self.integratorObjList) <= self.integratorObjIndex: | |
219 | self.addIntegrator(nCohInt, timeInterval, overlapping) |
|
219 | self.addIntegrator(nCohInt, timeInterval, overlapping) | |
220 |
|
220 | |||
221 | myCohIntObj = self.integratorObjList[self.integratorObjIndex] |
|
221 | myCohIntObj = self.integratorObjList[self.integratorObjIndex] | |
222 | myCohIntObj.exe(data = self.dataOutObj.data, datatime=None) |
|
222 | myCohIntObj.exe(data = self.dataOutObj.data, datatime=None) | |
223 |
|
223 | |||
224 | self.dataOutObj.timeInterval *= nCohInt |
|
224 | # self.dataOutObj.timeInterval *= nCohInt | |
225 | self.dataOutObj.flagNoData = True |
|
225 | self.dataOutObj.flagNoData = True | |
226 |
|
226 | |||
227 | if myCohIntObj.isReady: |
|
227 | if myCohIntObj.isReady: | |
228 | self.dataOutObj.timeInterval = myCohIntObj.nCohInt * self.dataOutObj.timeInterval |
|
228 | self.dataOutObj.timeInterval = myCohIntObj.nCohInt * self.dataOutObj.timeInterval | |
229 | self.dataOutObj.flagNoData = False |
|
229 | self.dataOutObj.flagNoData = False | |
230 |
|
230 | |||
231 | def selectChannels(self, channelList): |
|
231 | def selectChannels(self, channelList): | |
232 |
|
232 | |||
233 | self.selectChannelsByIndex(channelList) |
|
233 | self.selectChannelsByIndex(channelList) | |
234 |
|
234 | |||
235 | def selectChannelsByIndex(self, channelIndexList): |
|
235 | def selectChannelsByIndex(self, channelIndexList): | |
236 | """ |
|
236 | """ | |
237 | Selecciona un bloque de datos en base a canales segun el channelIndexList |
|
237 | Selecciona un bloque de datos en base a canales segun el channelIndexList | |
238 |
|
238 | |||
239 | Input: |
|
239 | Input: | |
240 | channelIndexList : lista sencilla de canales a seleccionar por ej. [2,3,7] |
|
240 | channelIndexList : lista sencilla de canales a seleccionar por ej. [2,3,7] | |
241 |
|
241 | |||
242 | Affected: |
|
242 | Affected: | |
243 | self.dataOutObj.data |
|
243 | self.dataOutObj.data | |
244 | self.dataOutObj.channelIndexList |
|
244 | self.dataOutObj.channelIndexList | |
245 | self.dataOutObj.nChannels |
|
245 | self.dataOutObj.nChannels | |
246 | self.dataOutObj.m_ProcessingHeader.totalSpectra |
|
246 | self.dataOutObj.m_ProcessingHeader.totalSpectra | |
247 | self.dataOutObj.systemHeaderObj.numChannels |
|
247 | self.dataOutObj.systemHeaderObj.numChannels | |
248 | self.dataOutObj.m_ProcessingHeader.blockSize |
|
248 | self.dataOutObj.m_ProcessingHeader.blockSize | |
249 |
|
249 | |||
250 | Return: |
|
250 | Return: | |
251 | None |
|
251 | None | |
252 | """ |
|
252 | """ | |
253 | if self.dataOutObj.flagNoData: |
|
253 | if self.dataOutObj.flagNoData: | |
254 | return 0 |
|
254 | return 0 | |
255 |
|
255 | |||
256 | for channel in channelIndexList: |
|
256 | for channel in channelIndexList: | |
257 | if channel not in self.dataOutObj.channelIndexList: |
|
257 | if channel not in self.dataOutObj.channelIndexList: | |
258 | raise ValueError, "The value %d in channelIndexList is not valid" %channel |
|
258 | raise ValueError, "The value %d in channelIndexList is not valid" %channel | |
259 |
|
259 | |||
260 | nChannels = len(channelIndexList) |
|
260 | nChannels = len(channelIndexList) | |
261 |
|
261 | |||
262 | data = self.dataOutObj.data[channelIndexList,:] |
|
262 | data = self.dataOutObj.data[channelIndexList,:] | |
263 |
|
263 | |||
264 | self.dataOutObj.data = data |
|
264 | self.dataOutObj.data = data | |
265 | self.dataOutObj.channelIndexList = channelIndexList |
|
265 | self.dataOutObj.channelIndexList = channelIndexList | |
266 | self.dataOutObj.channelList = [self.dataOutObj.channelList[i] for i in channelIndexList] |
|
266 | self.dataOutObj.channelList = [self.dataOutObj.channelList[i] for i in channelIndexList] | |
267 | self.dataOutObj.nChannels = nChannels |
|
267 | self.dataOutObj.nChannels = nChannels | |
268 |
|
268 | |||
269 | return 1 |
|
269 | return 1 | |
270 |
|
270 | |||
271 | class CoherentIntegrator: |
|
271 | class CoherentIntegrator: | |
272 |
|
272 | |||
273 |
|
273 | |||
274 | __profIndex = 0 |
|
274 | __profIndex = 0 | |
275 | __withOverapping = False |
|
275 | __withOverapping = False | |
276 |
|
276 | |||
277 | __isByTime = False |
|
277 | __isByTime = False | |
278 | __initime = None |
|
278 | __initime = None | |
279 | __integrationtime = None |
|
279 | __integrationtime = None | |
280 |
|
280 | |||
281 | __buffer = None |
|
281 | __buffer = None | |
282 |
|
282 | |||
283 | isReady = False |
|
283 | isReady = False | |
284 | nCohInt = None |
|
284 | nCohInt = None | |
285 |
|
285 | |||
286 |
|
286 | |||
287 | def __init__(self, nCohInt=None, timeInterval=None, overlapping=False): |
|
287 | def __init__(self, nCohInt=None, timeInterval=None, overlapping=False): | |
288 |
|
288 | |||
289 | """ |
|
289 | """ | |
290 | Set the parameters of the integration class. |
|
290 | Set the parameters of the integration class. | |
291 |
|
291 | |||
292 | Inputs: |
|
292 | Inputs: | |
293 |
|
293 | |||
294 | nCohInt : Number of coherent integrations |
|
294 | nCohInt : Number of coherent integrations | |
295 | timeInterval : Time of integration. If nCohInt is selected this parameter does not work |
|
295 | timeInterval : Time of integration. If nCohInt is selected this parameter does not work | |
296 | overlapping : |
|
296 | overlapping : | |
297 |
|
297 | |||
298 | """ |
|
298 | """ | |
299 |
|
299 | |||
300 | self.__buffer = None |
|
300 | self.__buffer = None | |
301 | self.isReady = False |
|
301 | self.isReady = False | |
302 |
|
302 | |||
303 | if nCohInt == None and timeInterval == None: |
|
303 | if nCohInt == None and timeInterval == None: | |
304 | raise ValueError, "nCohInt or timeInterval should be specified ..." |
|
304 | raise ValueError, "nCohInt or timeInterval should be specified ..." | |
305 |
|
305 | |||
306 | if nCohInt != None: |
|
306 | if nCohInt != None: | |
307 | self.nCohInt = nCohInt |
|
307 | self.nCohInt = nCohInt | |
308 | self.__isByTime = False |
|
308 | self.__isByTime = False | |
309 | else: |
|
309 | else: | |
310 | self.__integrationtime = timeInterval * 60. #if (type(timeInterval)!=integer) -> change this line |
|
310 | self.__integrationtime = timeInterval * 60. #if (type(timeInterval)!=integer) -> change this line | |
311 | self.__isByTime = True |
|
311 | self.__isByTime = True | |
312 |
|
312 | |||
313 | if overlapping: |
|
313 | if overlapping: | |
314 | self.__withOverapping = True |
|
314 | self.__withOverapping = True | |
315 | self.__buffer = None |
|
315 | self.__buffer = None | |
316 | else: |
|
316 | else: | |
317 | self.__withOverapping = False |
|
317 | self.__withOverapping = False | |
318 | self.__buffer = 0 |
|
318 | self.__buffer = 0 | |
319 |
|
319 | |||
320 | self.__profIndex = 0 |
|
320 | self.__profIndex = 0 | |
321 |
|
321 | |||
322 | def putData(self, data): |
|
322 | def putData(self, data): | |
323 |
|
323 | |||
324 | """ |
|
324 | """ | |
325 | Add a profile to the __buffer and increase in one the __profileIndex |
|
325 | Add a profile to the __buffer and increase in one the __profileIndex | |
326 |
|
326 | |||
327 | """ |
|
327 | """ | |
328 | if not self.__withOverapping: |
|
328 | if not self.__withOverapping: | |
329 | self.__buffer += data |
|
329 | self.__buffer += data | |
330 | self.__profIndex += 1 |
|
330 | self.__profIndex += 1 | |
331 | return |
|
331 | return | |
332 |
|
332 | |||
333 | #Overlapping data |
|
333 | #Overlapping data | |
334 | nChannels, nHeis = data.shape |
|
334 | nChannels, nHeis = data.shape | |
335 | data = numpy.reshape(data, (1, nChannels, nHeis)) |
|
335 | data = numpy.reshape(data, (1, nChannels, nHeis)) | |
336 |
|
336 | |||
337 | if self.__buffer == None: |
|
337 | if self.__buffer == None: | |
338 | self.__buffer = data |
|
338 | self.__buffer = data | |
339 | self.__profIndex += 1 |
|
339 | self.__profIndex += 1 | |
340 | return |
|
340 | return | |
341 |
|
341 | |||
342 | if self.__profIndex < self.nCohInt: |
|
342 | if self.__profIndex < self.nCohInt: | |
343 | self.__buffer = numpy.vstack((self.__buffer, data)) |
|
343 | self.__buffer = numpy.vstack((self.__buffer, data)) | |
344 | self.__profIndex += 1 |
|
344 | self.__profIndex += 1 | |
345 | return |
|
345 | return | |
346 |
|
346 | |||
347 | self.__buffer = numpy.roll(self.__buffer, -1, axis=0) |
|
347 | self.__buffer = numpy.roll(self.__buffer, -1, axis=0) | |
348 | self.__buffer[self.nCohInt-1] = data |
|
348 | self.__buffer[self.nCohInt-1] = data | |
349 | #self.__profIndex = self.nCohInt |
|
349 | #self.__profIndex = self.nCohInt | |
350 | return |
|
350 | return | |
351 |
|
351 | |||
352 |
|
352 | |||
353 | def pushData(self): |
|
353 | def pushData(self): | |
354 | """ |
|
354 | """ | |
355 | Return the sum of the last profiles and the profiles used in the sum. |
|
355 | Return the sum of the last profiles and the profiles used in the sum. | |
356 |
|
356 | |||
357 | Affected: |
|
357 | Affected: | |
358 |
|
358 | |||
359 | self.__profileIndex |
|
359 | self.__profileIndex | |
360 |
|
360 | |||
361 | """ |
|
361 | """ | |
362 |
|
362 | |||
363 | if not self.__withOverapping: |
|
363 | if not self.__withOverapping: | |
364 | data = self.__buffer |
|
364 | data = self.__buffer | |
365 | nCohInt = self.__profIndex |
|
365 | nCohInt = self.__profIndex | |
366 |
|
366 | |||
367 | self.__buffer = 0 |
|
367 | self.__buffer = 0 | |
368 | self.__profIndex = 0 |
|
368 | self.__profIndex = 0 | |
369 |
|
369 | |||
370 | return data, nCohInt |
|
370 | return data, nCohInt | |
371 |
|
371 | |||
372 | #Overlapping data |
|
372 | #Overlapping data | |
373 | data = numpy.sum(self.__buffer, axis=0) |
|
373 | data = numpy.sum(self.__buffer, axis=0) | |
374 | nCohInt = self.__profIndex |
|
374 | nCohInt = self.__profIndex | |
375 |
|
375 | |||
376 | return data, nCohInt |
|
376 | return data, nCohInt | |
377 |
|
377 | |||
378 | def byProfiles(self, data): |
|
378 | def byProfiles(self, data): | |
379 |
|
379 | |||
380 | self.isReady = False |
|
380 | self.isReady = False | |
381 | avg_data = None |
|
381 | avg_data = None | |
382 |
|
382 | |||
383 | self.putData(data) |
|
383 | self.putData(data) | |
384 |
|
384 | |||
385 | if self.__profIndex == self.nCohInt: |
|
385 | if self.__profIndex == self.nCohInt: | |
386 | avg_data, nCohInt = self.pushData() |
|
386 | avg_data, nCohInt = self.pushData() | |
387 | self.isReady = True |
|
387 | self.isReady = True | |
388 |
|
388 | |||
389 | return avg_data |
|
389 | return avg_data | |
390 |
|
390 | |||
391 | def byTime(self, data, datatime): |
|
391 | def byTime(self, data, datatime): | |
392 |
|
392 | |||
393 | self.isReady = False |
|
393 | self.isReady = False | |
394 | avg_data = None |
|
394 | avg_data = None | |
395 |
|
395 | |||
396 | if self.__initime == None: |
|
396 | if self.__initime == None: | |
397 | self.__initime = datatime |
|
397 | self.__initime = datatime | |
398 |
|
398 | |||
399 | self.putData(data) |
|
399 | self.putData(data) | |
400 |
|
400 | |||
401 | if (datatime - self.__initime) >= self.__integrationtime: |
|
401 | if (datatime - self.__initime) >= self.__integrationtime: | |
402 | avg_data, nCohInt = self.pushData() |
|
402 | avg_data, nCohInt = self.pushData() | |
403 | self.nCohInt = nCohInt |
|
403 | self.nCohInt = nCohInt | |
404 | self.isReady = True |
|
404 | self.isReady = True | |
405 |
|
405 | |||
406 | return avg_data |
|
406 | return avg_data | |
407 |
|
407 | |||
408 | def exe(self, data, datatime=None): |
|
408 | def exe(self, data, datatime=None): | |
409 |
|
409 | |||
410 | if not self.__isByTime: |
|
410 | if not self.__isByTime: | |
411 | avg_data = self.byProfiles(data) |
|
411 | avg_data = self.byProfiles(data) | |
412 | else: |
|
412 | else: | |
413 | avg_data = self.byTime(data, datatime) |
|
413 | avg_data = self.byTime(data, datatime) | |
414 |
|
414 | |||
415 | self.data = avg_data |
|
415 | self.data = avg_data | |
416 |
|
416 | |||
417 | return avg_data |
|
417 | return avg_data | |
418 |
|
418 | |||
419 |
|
419 |
General Comments 0
You need to be logged in to leave comments.
Login now