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