@@ -1,690 +1,690 | |||||
1 | ''' |
|
1 | ''' | |
2 |
|
2 | |||
3 | $Author: murco $ |
|
3 | $Author: murco $ | |
4 | $Id: JROData.py 173 2012-11-20 15:06:21Z murco $ |
|
4 | $Id: JROData.py 173 2012-11-20 15:06:21Z murco $ | |
5 | ''' |
|
5 | ''' | |
6 |
|
6 | |||
7 | import os, sys |
|
7 | import os, sys | |
8 | import copy |
|
8 | import copy | |
9 | import numpy |
|
9 | import numpy | |
10 | import datetime |
|
10 | import datetime | |
11 |
|
11 | |||
12 | from jroheaderIO import SystemHeader, RadarControllerHeader |
|
12 | from jroheaderIO import SystemHeader, RadarControllerHeader | |
13 |
|
13 | |||
14 |
|
14 | |||
15 | def hildebrand_sekhon(data, navg): |
|
15 | def hildebrand_sekhon(data, navg): | |
16 |
|
16 | |||
17 | data = data.copy() |
|
17 | data = data.copy() | |
18 |
|
18 | |||
19 | sortdata = numpy.sort(data,axis=None) |
|
19 | sortdata = numpy.sort(data,axis=None) | |
20 | lenOfData = len(sortdata) |
|
20 | lenOfData = len(sortdata) | |
21 | nums_min = lenOfData/10 |
|
21 | nums_min = lenOfData/10 | |
22 |
|
22 | |||
23 | if (lenOfData/10) > 2: |
|
23 | if (lenOfData/10) > 2: | |
24 | nums_min = lenOfData/10 |
|
24 | nums_min = lenOfData/10 | |
25 | else: |
|
25 | else: | |
26 | nums_min = 2 |
|
26 | nums_min = 2 | |
27 |
|
27 | |||
28 | sump = 0. |
|
28 | sump = 0. | |
29 |
|
29 | |||
30 | sumq = 0. |
|
30 | sumq = 0. | |
31 |
|
31 | |||
32 | j = 0 |
|
32 | j = 0 | |
33 |
|
33 | |||
34 | cont = 1 |
|
34 | cont = 1 | |
35 |
|
35 | |||
36 | while((cont==1)and(j<lenOfData)): |
|
36 | while((cont==1)and(j<lenOfData)): | |
37 |
|
37 | |||
38 | sump += sortdata[j] |
|
38 | sump += sortdata[j] | |
39 |
|
39 | |||
40 | sumq += sortdata[j]**2 |
|
40 | sumq += sortdata[j]**2 | |
41 |
|
41 | |||
42 | j += 1 |
|
42 | j += 1 | |
43 |
|
43 | |||
44 | if j > nums_min: |
|
44 | if j > nums_min: | |
45 | rtest = float(j)/(j-1) + 1.0/navg |
|
45 | rtest = float(j)/(j-1) + 1.0/navg | |
46 | if ((sumq*j) > (rtest*sump**2)): |
|
46 | if ((sumq*j) > (rtest*sump**2)): | |
47 | j = j - 1 |
|
47 | j = j - 1 | |
48 | sump = sump - sortdata[j] |
|
48 | sump = sump - sortdata[j] | |
49 | sumq = sumq - sortdata[j]**2 |
|
49 | sumq = sumq - sortdata[j]**2 | |
50 | cont = 0 |
|
50 | cont = 0 | |
51 |
|
51 | |||
52 | lnoise = sump /j |
|
52 | lnoise = sump /j | |
53 | stdv = numpy.sqrt((sumq - lnoise**2)/(j - 1)) |
|
53 | stdv = numpy.sqrt((sumq - lnoise**2)/(j - 1)) | |
54 | return lnoise |
|
54 | return lnoise | |
55 |
|
55 | |||
56 | class JROData: |
|
56 | class JROData: | |
57 |
|
57 | |||
58 | # m_BasicHeader = BasicHeader() |
|
58 | # m_BasicHeader = BasicHeader() | |
59 | # m_ProcessingHeader = ProcessingHeader() |
|
59 | # m_ProcessingHeader = ProcessingHeader() | |
60 |
|
60 | |||
61 | systemHeaderObj = SystemHeader() |
|
61 | systemHeaderObj = SystemHeader() | |
62 |
|
62 | |||
63 | radarControllerHeaderObj = RadarControllerHeader() |
|
63 | radarControllerHeaderObj = RadarControllerHeader() | |
64 |
|
64 | |||
65 | # data = None |
|
65 | # data = None | |
66 |
|
66 | |||
67 | type = None |
|
67 | type = None | |
68 |
|
68 | |||
69 | dtype = None |
|
69 | dtype = None | |
70 |
|
70 | |||
71 | # nChannels = None |
|
71 | # nChannels = None | |
72 |
|
72 | |||
73 | # nHeights = None |
|
73 | # nHeights = None | |
74 |
|
74 | |||
75 | nProfiles = None |
|
75 | nProfiles = None | |
76 |
|
76 | |||
77 | heightList = None |
|
77 | heightList = None | |
78 |
|
78 | |||
79 | channelList = None |
|
79 | channelList = None | |
80 |
|
80 | |||
81 | flagNoData = True |
|
81 | flagNoData = True | |
82 |
|
82 | |||
83 | flagTimeBlock = False |
|
83 | flagTimeBlock = False | |
84 |
|
84 | |||
85 | useLocalTime = False |
|
85 | useLocalTime = False | |
86 |
|
86 | |||
87 | utctime = None |
|
87 | utctime = None | |
88 |
|
88 | |||
89 | timeZone = None |
|
89 | timeZone = None | |
90 |
|
90 | |||
91 | dstFlag = None |
|
91 | dstFlag = None | |
92 |
|
92 | |||
93 | errorCount = None |
|
93 | errorCount = None | |
94 |
|
94 | |||
95 | blocksize = None |
|
95 | blocksize = None | |
96 |
|
96 | |||
97 | nCode = None |
|
97 | nCode = None | |
98 |
|
98 | |||
99 | nBaud = None |
|
99 | nBaud = None | |
100 |
|
100 | |||
101 | code = None |
|
101 | code = None | |
102 |
|
102 | |||
103 | flagDecodeData = False #asumo q la data no esta decodificada |
|
103 | flagDecodeData = False #asumo q la data no esta decodificada | |
104 |
|
104 | |||
105 | flagDeflipData = False #asumo q la data no esta sin flip |
|
105 | flagDeflipData = False #asumo q la data no esta sin flip | |
106 |
|
106 | |||
107 | flagShiftFFT = False |
|
107 | flagShiftFFT = False | |
108 |
|
108 | |||
109 | ippSeconds = None |
|
109 | ippSeconds = None | |
110 |
|
110 | |||
111 | timeInterval = None |
|
111 | timeInterval = None | |
112 |
|
112 | |||
113 | nCohInt = None |
|
113 | nCohInt = None | |
114 |
|
114 | |||
115 | noise = None |
|
115 | noise = None | |
116 |
|
116 | |||
117 | windowOfFilter = 1 |
|
117 | windowOfFilter = 1 | |
118 |
|
118 | |||
119 | #Speed of ligth |
|
119 | #Speed of ligth | |
120 | C = 3e8 |
|
120 | C = 3e8 | |
121 |
|
121 | |||
122 | frequency = 49.92e6 |
|
122 | frequency = 49.92e6 | |
123 |
|
123 | |||
124 | realtime = False |
|
124 | realtime = False | |
125 |
|
125 | |||
126 | beacon_heiIndexList = None |
|
126 | beacon_heiIndexList = None | |
127 |
|
127 | |||
128 | last_block = None |
|
128 | last_block = None | |
129 |
|
129 | |||
130 | blocknow = None |
|
130 | blocknow = None | |
131 |
|
131 | |||
132 | def __init__(self): |
|
132 | def __init__(self): | |
133 |
|
133 | |||
134 | raise ValueError, "This class has not been implemented" |
|
134 | raise ValueError, "This class has not been implemented" | |
135 |
|
135 | |||
136 | def copy(self, inputObj=None): |
|
136 | def copy(self, inputObj=None): | |
137 |
|
137 | |||
138 | if inputObj == None: |
|
138 | if inputObj == None: | |
139 | return copy.deepcopy(self) |
|
139 | return copy.deepcopy(self) | |
140 |
|
140 | |||
141 | for key in inputObj.__dict__.keys(): |
|
141 | for key in inputObj.__dict__.keys(): | |
142 | self.__dict__[key] = inputObj.__dict__[key] |
|
142 | self.__dict__[key] = inputObj.__dict__[key] | |
143 |
|
143 | |||
144 | def deepcopy(self): |
|
144 | def deepcopy(self): | |
145 |
|
145 | |||
146 | return copy.deepcopy(self) |
|
146 | return copy.deepcopy(self) | |
147 |
|
147 | |||
148 | def isEmpty(self): |
|
148 | def isEmpty(self): | |
149 |
|
149 | |||
150 | return self.flagNoData |
|
150 | return self.flagNoData | |
151 |
|
151 | |||
152 | def getNoise(self): |
|
152 | def getNoise(self): | |
153 |
|
153 | |||
154 | raise ValueError, "Not implemented" |
|
154 | raise ValueError, "Not implemented" | |
155 |
|
155 | |||
156 | def getNChannels(self): |
|
156 | def getNChannels(self): | |
157 |
|
157 | |||
158 | return len(self.channelList) |
|
158 | return len(self.channelList) | |
159 |
|
159 | |||
160 | def getChannelIndexList(self): |
|
160 | def getChannelIndexList(self): | |
161 |
|
161 | |||
162 | return range(self.nChannels) |
|
162 | return range(self.nChannels) | |
163 |
|
163 | |||
164 | def getNHeights(self): |
|
164 | def getNHeights(self): | |
165 |
|
165 | |||
166 | return len(self.heightList) |
|
166 | return len(self.heightList) | |
167 |
|
167 | |||
168 | def getHeiRange(self, extrapoints=0): |
|
168 | def getHeiRange(self, extrapoints=0): | |
169 |
|
169 | |||
170 | heis = self.heightList |
|
170 | heis = self.heightList | |
171 | # deltah = self.heightList[1] - self.heightList[0] |
|
171 | # deltah = self.heightList[1] - self.heightList[0] | |
172 | # |
|
172 | # | |
173 | # heis.append(self.heightList[-1]) |
|
173 | # heis.append(self.heightList[-1]) | |
174 |
|
174 | |||
175 | return heis |
|
175 | return heis | |
176 |
|
176 | |||
177 | def getltctime(self): |
|
177 | def getltctime(self): | |
178 |
|
178 | |||
179 | if self.useLocalTime: |
|
179 | if self.useLocalTime: | |
180 | return self.utctime - self.timeZone*60 |
|
180 | return self.utctime - self.timeZone*60 | |
181 |
|
181 | |||
182 | return self.utctime |
|
182 | return self.utctime | |
183 |
|
183 | |||
184 | def getDatatime(self): |
|
184 | def getDatatime(self): | |
185 |
|
185 | |||
186 | datatime = datetime.datetime.utcfromtimestamp(self.ltctime) |
|
186 | datatime = datetime.datetime.utcfromtimestamp(self.ltctime) | |
187 | return datatime |
|
187 | return datatime | |
188 |
|
188 | |||
189 | def getTimeRange(self): |
|
189 | def getTimeRange(self): | |
190 |
|
190 | |||
191 | datatime = [] |
|
191 | datatime = [] | |
192 |
|
192 | |||
193 | datatime.append(self.ltctime) |
|
193 | datatime.append(self.ltctime) | |
194 | datatime.append(self.ltctime + self.timeInterval) |
|
194 | datatime.append(self.ltctime + self.timeInterval) | |
195 |
|
195 | |||
196 | datatime = numpy.array(datatime) |
|
196 | datatime = numpy.array(datatime) | |
197 |
|
197 | |||
198 | return datatime |
|
198 | return datatime | |
199 |
|
199 | |||
200 | def getFmax(self): |
|
200 | def getFmax(self): | |
201 |
|
201 | |||
202 | PRF = 1./(self.ippSeconds * self.nCohInt) |
|
202 | PRF = 1./(self.ippSeconds * self.nCohInt) | |
203 |
|
203 | |||
204 | fmax = PRF/2. |
|
204 | fmax = PRF/2. | |
205 |
|
205 | |||
206 | return fmax |
|
206 | return fmax | |
207 |
|
207 | |||
208 | def getVmax(self): |
|
208 | def getVmax(self): | |
209 |
|
209 | |||
210 | _lambda = self.C/self.frequency |
|
210 | _lambda = self.C/self.frequency | |
211 |
|
211 | |||
212 | vmax = self.getFmax() * _lambda |
|
212 | vmax = self.getFmax() * _lambda | |
213 |
|
213 | |||
214 | return vmax |
|
214 | return vmax | |
215 |
|
215 | |||
216 | nChannels = property(getNChannels, "I'm the 'nChannel' property.") |
|
216 | nChannels = property(getNChannels, "I'm the 'nChannel' property.") | |
217 | channelIndexList = property(getChannelIndexList, "I'm the 'channelIndexList' property.") |
|
217 | channelIndexList = property(getChannelIndexList, "I'm the 'channelIndexList' property.") | |
218 | nHeights = property(getNHeights, "I'm the 'nHeights' property.") |
|
218 | nHeights = property(getNHeights, "I'm the 'nHeights' property.") | |
219 | noise = property(getNoise, "I'm the 'nHeights' property.") |
|
219 | noise = property(getNoise, "I'm the 'nHeights' property.") | |
220 | datatime = property(getDatatime, "I'm the 'datatime' property") |
|
220 | datatime = property(getDatatime, "I'm the 'datatime' property") | |
221 | ltctime = property(getltctime, "I'm the 'ltctime' property") |
|
221 | ltctime = property(getltctime, "I'm the 'ltctime' property") | |
222 |
|
222 | |||
223 | class Voltage(JROData): |
|
223 | class Voltage(JROData): | |
224 |
|
224 | |||
225 | #data es un numpy array de 2 dmensiones (canales, alturas) |
|
225 | #data es un numpy array de 2 dmensiones (canales, alturas) | |
226 | data = None |
|
226 | data = None | |
227 |
|
227 | |||
228 | def __init__(self): |
|
228 | def __init__(self): | |
229 | ''' |
|
229 | ''' | |
230 | Constructor |
|
230 | Constructor | |
231 | ''' |
|
231 | ''' | |
232 |
|
232 | |||
233 | self.radarControllerHeaderObj = RadarControllerHeader() |
|
233 | self.radarControllerHeaderObj = RadarControllerHeader() | |
234 |
|
234 | |||
235 | self.systemHeaderObj = SystemHeader() |
|
235 | self.systemHeaderObj = SystemHeader() | |
236 |
|
236 | |||
237 | self.type = "Voltage" |
|
237 | self.type = "Voltage" | |
238 |
|
238 | |||
239 | self.data = None |
|
239 | self.data = None | |
240 |
|
240 | |||
241 | self.dtype = None |
|
241 | self.dtype = None | |
242 |
|
242 | |||
243 | # self.nChannels = 0 |
|
243 | # self.nChannels = 0 | |
244 |
|
244 | |||
245 | # self.nHeights = 0 |
|
245 | # self.nHeights = 0 | |
246 |
|
246 | |||
247 | self.nProfiles = None |
|
247 | self.nProfiles = None | |
248 |
|
248 | |||
249 | self.heightList = None |
|
249 | self.heightList = None | |
250 |
|
250 | |||
251 | self.channelList = None |
|
251 | self.channelList = None | |
252 |
|
252 | |||
253 | # self.channelIndexList = None |
|
253 | # self.channelIndexList = None | |
254 |
|
254 | |||
255 | self.flagNoData = True |
|
255 | self.flagNoData = True | |
256 |
|
256 | |||
257 | self.flagTimeBlock = False |
|
257 | self.flagTimeBlock = False | |
258 |
|
258 | |||
259 | self.utctime = None |
|
259 | self.utctime = None | |
260 |
|
260 | |||
261 | self.timeZone = None |
|
261 | self.timeZone = None | |
262 |
|
262 | |||
263 | self.dstFlag = None |
|
263 | self.dstFlag = None | |
264 |
|
264 | |||
265 | self.errorCount = None |
|
265 | self.errorCount = None | |
266 |
|
266 | |||
267 | self.nCohInt = None |
|
267 | self.nCohInt = None | |
268 |
|
268 | |||
269 | self.blocksize = None |
|
269 | self.blocksize = None | |
270 |
|
270 | |||
271 | self.flagDecodeData = False #asumo q la data no esta decodificada |
|
271 | self.flagDecodeData = False #asumo q la data no esta decodificada | |
272 |
|
272 | |||
273 | self.flagDeflipData = False #asumo q la data no esta sin flip |
|
273 | self.flagDeflipData = False #asumo q la data no esta sin flip | |
274 |
|
274 | |||
275 | self.flagShiftFFT = False |
|
275 | self.flagShiftFFT = False | |
276 |
|
276 | |||
277 |
|
277 | |||
278 | def getNoisebyHildebrand(self): |
|
278 | def getNoisebyHildebrand(self): | |
279 | """ |
|
279 | """ | |
280 | Determino el nivel de ruido usando el metodo Hildebrand-Sekhon |
|
280 | Determino el nivel de ruido usando el metodo Hildebrand-Sekhon | |
281 |
|
281 | |||
282 | Return: |
|
282 | Return: | |
283 | noiselevel |
|
283 | noiselevel | |
284 | """ |
|
284 | """ | |
285 |
|
285 | |||
286 | for channel in range(self.nChannels): |
|
286 | for channel in range(self.nChannels): | |
287 | daux = self.data_spc[channel,:,:] |
|
287 | daux = self.data_spc[channel,:,:] | |
288 | self.noise[channel] = hildebrand_sekhon(daux, self.nCohInt) |
|
288 | self.noise[channel] = hildebrand_sekhon(daux, self.nCohInt) | |
289 |
|
289 | |||
290 | return self.noise |
|
290 | return self.noise | |
291 |
|
291 | |||
292 | def getNoise(self, type = 1): |
|
292 | def getNoise(self, type = 1): | |
293 |
|
293 | |||
294 | self.noise = numpy.zeros(self.nChannels) |
|
294 | self.noise = numpy.zeros(self.nChannels) | |
295 |
|
295 | |||
296 | if type == 1: |
|
296 | if type == 1: | |
297 | noise = self.getNoisebyHildebrand() |
|
297 | noise = self.getNoisebyHildebrand() | |
298 |
|
298 | |||
299 | return 10*numpy.log10(noise) |
|
299 | return 10*numpy.log10(noise) | |
300 |
|
300 | |||
301 | class Spectra(JROData): |
|
301 | class Spectra(JROData): | |
302 |
|
302 | |||
303 | #data es un numpy array de 2 dmensiones (canales, perfiles, alturas) |
|
303 | #data es un numpy array de 2 dmensiones (canales, perfiles, alturas) | |
304 | data_spc = None |
|
304 | data_spc = None | |
305 |
|
305 | |||
306 | #data es un numpy array de 2 dmensiones (canales, pares, alturas) |
|
306 | #data es un numpy array de 2 dmensiones (canales, pares, alturas) | |
307 | data_cspc = None |
|
307 | data_cspc = None | |
308 |
|
308 | |||
309 | #data es un numpy array de 2 dmensiones (canales, alturas) |
|
309 | #data es un numpy array de 2 dmensiones (canales, alturas) | |
310 | data_dc = None |
|
310 | data_dc = None | |
311 |
|
311 | |||
312 | nFFTPoints = None |
|
312 | nFFTPoints = None | |
313 |
|
313 | |||
314 | nPairs = None |
|
314 | nPairs = None | |
315 |
|
315 | |||
316 | pairsList = None |
|
316 | pairsList = None | |
317 |
|
317 | |||
318 | nIncohInt = None |
|
318 | nIncohInt = None | |
319 |
|
319 | |||
320 | wavelength = None #Necesario para cacular el rango de velocidad desde la frecuencia |
|
320 | wavelength = None #Necesario para cacular el rango de velocidad desde la frecuencia | |
321 |
|
321 | |||
322 | nCohInt = None #se requiere para determinar el valor de timeInterval |
|
322 | nCohInt = None #se requiere para determinar el valor de timeInterval | |
323 |
|
323 | |||
324 | ippFactor = None |
|
324 | ippFactor = None | |
325 |
|
325 | |||
326 | def __init__(self): |
|
326 | def __init__(self): | |
327 | ''' |
|
327 | ''' | |
328 | Constructor |
|
328 | Constructor | |
329 | ''' |
|
329 | ''' | |
330 |
|
330 | |||
331 | self.radarControllerHeaderObj = RadarControllerHeader() |
|
331 | self.radarControllerHeaderObj = RadarControllerHeader() | |
332 |
|
332 | |||
333 | self.systemHeaderObj = SystemHeader() |
|
333 | self.systemHeaderObj = SystemHeader() | |
334 |
|
334 | |||
335 | self.type = "Spectra" |
|
335 | self.type = "Spectra" | |
336 |
|
336 | |||
337 | # self.data = None |
|
337 | # self.data = None | |
338 |
|
338 | |||
339 | self.dtype = None |
|
339 | self.dtype = None | |
340 |
|
340 | |||
341 | # self.nChannels = 0 |
|
341 | # self.nChannels = 0 | |
342 |
|
342 | |||
343 | # self.nHeights = 0 |
|
343 | # self.nHeights = 0 | |
344 |
|
344 | |||
345 | self.nProfiles = None |
|
345 | self.nProfiles = None | |
346 |
|
346 | |||
347 | self.heightList = None |
|
347 | self.heightList = None | |
348 |
|
348 | |||
349 | self.channelList = None |
|
349 | self.channelList = None | |
350 |
|
350 | |||
351 | # self.channelIndexList = None |
|
351 | # self.channelIndexList = None | |
352 |
|
352 | |||
353 | self.flagNoData = True |
|
353 | self.flagNoData = True | |
354 |
|
354 | |||
355 | self.flagTimeBlock = False |
|
355 | self.flagTimeBlock = False | |
356 |
|
356 | |||
357 | self.utctime = None |
|
357 | self.utctime = None | |
358 |
|
358 | |||
359 | self.nCohInt = None |
|
359 | self.nCohInt = None | |
360 |
|
360 | |||
361 | self.nIncohInt = None |
|
361 | self.nIncohInt = None | |
362 |
|
362 | |||
363 | self.blocksize = None |
|
363 | self.blocksize = None | |
364 |
|
364 | |||
365 | self.nFFTPoints = None |
|
365 | self.nFFTPoints = None | |
366 |
|
366 | |||
367 | self.wavelength = None |
|
367 | self.wavelength = None | |
368 |
|
368 | |||
369 | self.flagDecodeData = False #asumo q la data no esta decodificada |
|
369 | self.flagDecodeData = False #asumo q la data no esta decodificada | |
370 |
|
370 | |||
371 | self.flagDeflipData = False #asumo q la data no esta sin flip |
|
371 | self.flagDeflipData = False #asumo q la data no esta sin flip | |
372 |
|
372 | |||
373 | self.flagShiftFFT = False |
|
373 | self.flagShiftFFT = False | |
374 |
|
374 | |||
375 | self.ippFactor = 1 |
|
375 | self.ippFactor = 1 | |
376 |
|
376 | |||
377 | self.noise = None |
|
377 | self.noise = None | |
378 |
|
378 | |||
379 | self.beacon_heiIndexList = [] |
|
379 | self.beacon_heiIndexList = [] | |
380 |
|
380 | |||
381 |
|
381 | |||
382 | def getNoisebyHildebrand(self): |
|
382 | def getNoisebyHildebrand(self): | |
383 | """ |
|
383 | """ | |
384 | Determino el nivel de ruido usando el metodo Hildebrand-Sekhon |
|
384 | Determino el nivel de ruido usando el metodo Hildebrand-Sekhon | |
385 |
|
385 | |||
386 | Return: |
|
386 | Return: | |
387 | noiselevel |
|
387 | noiselevel | |
388 | """ |
|
388 | """ | |
389 | noise = numpy.zeros(self.nChannels) |
|
389 | noise = numpy.zeros(self.nChannels) | |
390 | for channel in range(self.nChannels): |
|
390 | for channel in range(self.nChannels): | |
391 | daux = self.data_spc[channel,:,:] |
|
391 | daux = self.data_spc[channel,:,:] | |
392 | noise[channel] = hildebrand_sekhon(daux, self.nIncohInt) |
|
392 | noise[channel] = hildebrand_sekhon(daux, self.nIncohInt) | |
393 |
|
393 | |||
394 | return noise |
|
394 | return noise | |
395 |
|
395 | |||
396 | def getNoise(self): |
|
396 | def getNoise(self): | |
397 | if self.noise != None: |
|
397 | if self.noise != None: | |
398 | return self.noise |
|
398 | return self.noise | |
399 | else: |
|
399 | else: | |
400 | noise = self.getNoisebyHildebrand() |
|
400 | noise = self.getNoisebyHildebrand() | |
401 | return noise |
|
401 | return noise | |
402 |
|
402 | |||
403 |
|
403 | |||
404 | def getFreqRange(self, extrapoints=0): |
|
404 | def getFreqRange(self, extrapoints=0): | |
405 |
|
405 | |||
406 | deltafreq = self.getFmax() / (self.nFFTPoints*self.ippFactor) |
|
406 | deltafreq = self.getFmax() / (self.nFFTPoints*self.ippFactor) | |
407 | freqrange = deltafreq*(numpy.arange(self.nFFTPoints+extrapoints)-self.nFFTPoints/2.) - deltafreq/2 |
|
407 | freqrange = deltafreq*(numpy.arange(self.nFFTPoints+extrapoints)-self.nFFTPoints/2.) - deltafreq/2 | |
408 |
|
408 | |||
409 | return freqrange |
|
409 | return freqrange | |
410 |
|
410 | |||
411 | def getVelRange(self, extrapoints=0): |
|
411 | def getVelRange(self, extrapoints=0): | |
412 |
|
412 | |||
413 | deltav = self.getVmax() / (self.nFFTPoints*self.ippFactor) |
|
413 | deltav = self.getVmax() / (self.nFFTPoints*self.ippFactor) | |
414 | velrange = deltav*(numpy.arange(self.nFFTPoints+extrapoints)-self.nFFTPoints/2.) - deltav/2 |
|
414 | velrange = deltav*(numpy.arange(self.nFFTPoints+extrapoints)-self.nFFTPoints/2.) - deltav/2 | |
415 |
|
415 | |||
416 | return velrange |
|
416 | return velrange | |
417 |
|
417 | |||
418 | def getNPairs(self): |
|
418 | def getNPairs(self): | |
419 |
|
419 | |||
420 | return len(self.pairsList) |
|
420 | return len(self.pairsList) | |
421 |
|
421 | |||
422 | def getPairsIndexList(self): |
|
422 | def getPairsIndexList(self): | |
423 |
|
423 | |||
424 | return range(self.nPairs) |
|
424 | return range(self.nPairs) | |
425 |
|
425 | |||
426 | def getNormFactor(self): |
|
426 | def getNormFactor(self): | |
427 | pwcode = 1 |
|
427 | pwcode = 1 | |
428 | if self.flagDecodeData: |
|
428 | if self.flagDecodeData: | |
429 | pwcode = numpy.sum(self.code[0]**2) |
|
429 | pwcode = numpy.sum(self.code[0]**2) | |
430 | #normFactor = min(self.nFFTPoints,self.nProfiles)*self.nIncohInt*self.nCohInt*pwcode*self.windowOfFilter |
|
430 | #normFactor = min(self.nFFTPoints,self.nProfiles)*self.nIncohInt*self.nCohInt*pwcode*self.windowOfFilter | |
431 | normFactor = self.nProfiles*self.nIncohInt*self.nCohInt*pwcode*self.windowOfFilter |
|
431 | normFactor = self.nProfiles*self.nIncohInt*self.nCohInt*pwcode*self.windowOfFilter | |
432 |
|
432 | |||
433 | return normFactor |
|
433 | return normFactor | |
434 |
|
434 | |||
435 | def getFlagCspc(self): |
|
435 | def getFlagCspc(self): | |
436 |
|
436 | |||
437 | if self.data_cspc == None: |
|
437 | if self.data_cspc == None: | |
438 | return True |
|
438 | return True | |
439 |
|
439 | |||
440 | return False |
|
440 | return False | |
441 |
|
441 | |||
442 | def getFlagDc(self): |
|
442 | def getFlagDc(self): | |
443 |
|
443 | |||
444 | if self.data_dc == None: |
|
444 | if self.data_dc == None: | |
445 | return True |
|
445 | return True | |
446 |
|
446 | |||
447 | return False |
|
447 | return False | |
448 |
|
448 | |||
449 | nPairs = property(getNPairs, "I'm the 'nPairs' property.") |
|
449 | nPairs = property(getNPairs, "I'm the 'nPairs' property.") | |
450 | pairsIndexList = property(getPairsIndexList, "I'm the 'pairsIndexList' property.") |
|
450 | pairsIndexList = property(getPairsIndexList, "I'm the 'pairsIndexList' property.") | |
451 | normFactor = property(getNormFactor, "I'm the 'getNormFactor' property.") |
|
451 | normFactor = property(getNormFactor, "I'm the 'getNormFactor' property.") | |
452 | flag_cspc = property(getFlagCspc) |
|
452 | flag_cspc = property(getFlagCspc) | |
453 | flag_dc = property(getFlagDc) |
|
453 | flag_dc = property(getFlagDc) | |
454 |
|
454 | |||
455 | class SpectraHeis(JROData): |
|
455 | class SpectraHeis(JROData): | |
456 |
|
456 | |||
457 | data_spc = None |
|
457 | data_spc = None | |
458 |
|
458 | |||
459 | data_cspc = None |
|
459 | data_cspc = None | |
460 |
|
460 | |||
461 | data_dc = None |
|
461 | data_dc = None | |
462 |
|
462 | |||
463 | nFFTPoints = None |
|
463 | nFFTPoints = None | |
464 |
|
464 | |||
465 | nPairs = None |
|
465 | nPairs = None | |
466 |
|
466 | |||
467 | pairsList = None |
|
467 | pairsList = None | |
468 |
|
468 | |||
469 | nIncohInt = None |
|
469 | nIncohInt = None | |
470 |
|
470 | |||
471 | def __init__(self): |
|
471 | def __init__(self): | |
472 |
|
472 | |||
473 | self.radarControllerHeaderObj = RadarControllerHeader() |
|
473 | self.radarControllerHeaderObj = RadarControllerHeader() | |
474 |
|
474 | |||
475 | self.systemHeaderObj = SystemHeader() |
|
475 | self.systemHeaderObj = SystemHeader() | |
476 |
|
476 | |||
477 | self.type = "SpectraHeis" |
|
477 | self.type = "SpectraHeis" | |
478 |
|
478 | |||
479 | self.dtype = None |
|
479 | self.dtype = None | |
480 |
|
480 | |||
481 | # self.nChannels = 0 |
|
481 | # self.nChannels = 0 | |
482 |
|
482 | |||
483 | # self.nHeights = 0 |
|
483 | # self.nHeights = 0 | |
484 |
|
484 | |||
485 | self.nProfiles = None |
|
485 | self.nProfiles = None | |
486 |
|
486 | |||
487 | self.heightList = None |
|
487 | self.heightList = None | |
488 |
|
488 | |||
489 | self.channelList = None |
|
489 | self.channelList = None | |
490 |
|
490 | |||
491 | # self.channelIndexList = None |
|
491 | # self.channelIndexList = None | |
492 |
|
492 | |||
493 | self.flagNoData = True |
|
493 | self.flagNoData = True | |
494 |
|
494 | |||
495 | self.flagTimeBlock = False |
|
495 | self.flagTimeBlock = False | |
496 |
|
496 | |||
497 | self.nPairs = 0 |
|
497 | self.nPairs = 0 | |
498 |
|
498 | |||
499 | self.utctime = None |
|
499 | self.utctime = None | |
500 |
|
500 | |||
501 | self.blocksize = None |
|
501 | self.blocksize = None | |
502 |
|
502 | |||
503 | class Fits: |
|
503 | class Fits: | |
504 |
|
504 | |||
505 | heightList = None |
|
505 | heightList = None | |
506 |
|
506 | |||
507 | channelList = None |
|
507 | channelList = None | |
508 |
|
508 | |||
509 | flagNoData = True |
|
509 | flagNoData = True | |
510 |
|
510 | |||
511 | flagTimeBlock = False |
|
511 | flagTimeBlock = False | |
512 |
|
512 | |||
513 | useLocalTime = False |
|
513 | useLocalTime = False | |
514 |
|
514 | |||
515 | utctime = None |
|
515 | utctime = None | |
516 |
|
516 | |||
517 | timeZone = None |
|
517 | timeZone = None | |
518 |
|
518 | |||
519 | ippSeconds = None |
|
519 | ippSeconds = None | |
520 |
|
520 | |||
521 | timeInterval = None |
|
521 | timeInterval = None | |
522 |
|
522 | |||
523 | nCohInt = None |
|
523 | nCohInt = None | |
524 |
|
524 | |||
525 | nIncohInt = None |
|
525 | nIncohInt = None | |
526 |
|
526 | |||
527 | noise = None |
|
527 | noise = None | |
528 |
|
528 | |||
529 | windowOfFilter = 1 |
|
529 | windowOfFilter = 1 | |
530 |
|
530 | |||
531 | #Speed of ligth |
|
531 | #Speed of ligth | |
532 | C = 3e8 |
|
532 | C = 3e8 | |
533 |
|
533 | |||
534 | frequency = 49.92e6 |
|
534 | frequency = 49.92e6 | |
535 |
|
535 | |||
536 | realtime = False |
|
536 | realtime = False | |
537 |
|
537 | |||
538 |
|
538 | |||
539 | def __init__(self): |
|
539 | def __init__(self): | |
540 |
|
540 | |||
541 | self.type = "Fits" |
|
541 | self.type = "Fits" | |
542 |
|
542 | |||
543 | self.nProfiles = None |
|
543 | self.nProfiles = None | |
544 |
|
544 | |||
545 | self.heightList = None |
|
545 | self.heightList = None | |
546 |
|
546 | |||
547 | self.channelList = None |
|
547 | self.channelList = None | |
548 |
|
548 | |||
549 | # self.channelIndexList = None |
|
549 | # self.channelIndexList = None | |
550 |
|
550 | |||
551 | self.flagNoData = True |
|
551 | self.flagNoData = True | |
552 |
|
552 | |||
553 | self.utctime = None |
|
553 | self.utctime = None | |
554 |
|
554 | |||
555 | self.nCohInt = None |
|
555 | self.nCohInt = None | |
556 |
|
556 | |||
557 | self.nIncohInt = None |
|
557 | self.nIncohInt = None | |
558 |
|
558 | |||
559 | self.useLocalTime = True |
|
559 | self.useLocalTime = True | |
560 |
|
560 | |||
561 | # self.utctime = None |
|
561 | # self.utctime = None | |
562 | # self.timeZone = None |
|
562 | # self.timeZone = None | |
563 | # self.ltctime = None |
|
563 | # self.ltctime = None | |
564 | # self.timeInterval = None |
|
564 | # self.timeInterval = None | |
565 | # self.header = None |
|
565 | # self.header = None | |
566 | # self.data_header = None |
|
566 | # self.data_header = None | |
567 | # self.data = None |
|
567 | # self.data = None | |
568 | # self.datatime = None |
|
568 | # self.datatime = None | |
569 | # self.flagNoData = False |
|
569 | # self.flagNoData = False | |
570 | # self.expName = '' |
|
570 | # self.expName = '' | |
571 | # self.nChannels = None |
|
571 | # self.nChannels = None | |
572 | # self.nSamples = None |
|
572 | # self.nSamples = None | |
573 | # self.dataBlocksPerFile = None |
|
573 | # self.dataBlocksPerFile = None | |
574 | # self.comments = '' |
|
574 | # self.comments = '' | |
575 | # |
|
575 | # | |
576 |
|
576 | |||
577 |
|
577 | |||
578 | def getltctime(self): |
|
578 | def getltctime(self): | |
579 |
|
579 | |||
580 | if self.useLocalTime: |
|
580 | if self.useLocalTime: | |
581 | return self.utctime - self.timeZone*60 |
|
581 | return self.utctime - self.timeZone*60 | |
582 |
|
582 | |||
583 | return self.utctime |
|
583 | return self.utctime | |
584 |
|
584 | |||
585 | def getDatatime(self): |
|
585 | def getDatatime(self): | |
586 |
|
586 | |||
587 | datatime = datetime.datetime.utcfromtimestamp(self.ltctime) |
|
587 | datatime = datetime.datetime.utcfromtimestamp(self.ltctime) | |
588 | return datatime |
|
588 | return datatime | |
589 |
|
589 | |||
590 | def getTimeRange(self): |
|
590 | def getTimeRange(self): | |
591 |
|
591 | |||
592 | datatime = [] |
|
592 | datatime = [] | |
593 |
|
593 | |||
594 | datatime.append(self.ltctime) |
|
594 | datatime.append(self.ltctime) | |
595 | datatime.append(self.ltctime + self.timeInterval) |
|
595 | datatime.append(self.ltctime + self.timeInterval) | |
596 |
|
596 | |||
597 | datatime = numpy.array(datatime) |
|
597 | datatime = numpy.array(datatime) | |
598 |
|
598 | |||
599 | return datatime |
|
599 | return datatime | |
600 |
|
600 | |||
601 | def getHeiRange(self): |
|
601 | def getHeiRange(self): | |
602 |
|
602 | |||
603 | heis = self.heightList |
|
603 | heis = self.heightList | |
604 |
|
604 | |||
605 | return heis |
|
605 | return heis | |
606 |
|
606 | |||
607 | def isEmpty(self): |
|
607 | def isEmpty(self): | |
608 |
|
608 | |||
609 | return self.flagNoData |
|
609 | return self.flagNoData | |
610 |
|
610 | |||
611 | def getNHeights(self): |
|
611 | def getNHeights(self): | |
612 |
|
612 | |||
613 | return len(self.heightList) |
|
613 | return len(self.heightList) | |
614 |
|
614 | |||
615 | def getNChannels(self): |
|
615 | def getNChannels(self): | |
616 |
|
616 | |||
617 | return len(self.channelList) |
|
617 | return len(self.channelList) | |
618 |
|
618 | |||
619 | def getChannelIndexList(self): |
|
619 | def getChannelIndexList(self): | |
620 |
|
620 | |||
621 | return range(self.nChannels) |
|
621 | return range(self.nChannels) | |
622 |
|
622 | |||
623 | def getNoise(self, type = 1): |
|
623 | def getNoise(self, type = 1): | |
624 |
|
624 | |||
625 | self.noise = numpy.zeros(self.nChannels) |
|
625 | self.noise = numpy.zeros(self.nChannels) | |
626 |
|
626 | |||
627 | if type == 1: |
|
627 | if type == 1: | |
628 | noise = self.getNoisebyHildebrand() |
|
628 | noise = self.getNoisebyHildebrand() | |
629 |
|
629 | |||
630 | if type == 2: |
|
630 | if type == 2: | |
631 | noise = self.getNoisebySort() |
|
631 | noise = self.getNoisebySort() | |
632 |
|
632 | |||
633 | if type == 3: |
|
633 | if type == 3: | |
634 | noise = self.getNoisebyWindow() |
|
634 | noise = self.getNoisebyWindow() | |
635 |
|
635 | |||
636 | return noise |
|
636 | return noise | |
637 |
|
637 | |||
638 | datatime = property(getDatatime, "I'm the 'datatime' property") |
|
638 | datatime = property(getDatatime, "I'm the 'datatime' property") | |
639 | nHeights = property(getNHeights, "I'm the 'nHeights' property.") |
|
639 | nHeights = property(getNHeights, "I'm the 'nHeights' property.") | |
640 | nChannels = property(getNChannels, "I'm the 'nChannel' property.") |
|
640 | nChannels = property(getNChannels, "I'm the 'nChannel' property.") | |
641 | channelIndexList = property(getChannelIndexList, "I'm the 'channelIndexList' property.") |
|
641 | channelIndexList = property(getChannelIndexList, "I'm the 'channelIndexList' property.") | |
642 | noise = property(getNoise, "I'm the 'nHeights' property.") |
|
642 | noise = property(getNoise, "I'm the 'nHeights' property.") | |
643 | datatime = property(getDatatime, "I'm the 'datatime' property") |
|
643 | datatime = property(getDatatime, "I'm the 'datatime' property") | |
644 | ltctime = property(getltctime, "I'm the 'ltctime' property") |
|
644 | ltctime = property(getltctime, "I'm the 'ltctime' property") | |
645 |
|
645 | |||
646 | ltctime = property(getltctime, "I'm the 'ltctime' property") |
|
646 | ltctime = property(getltctime, "I'm the 'ltctime' property") | |
647 |
|
647 | |||
648 | class AMISR: |
|
648 | class AMISR: | |
649 | def __init__(self): |
|
649 | def __init__(self): | |
650 | self.flagNoData = True |
|
650 | self.flagNoData = True | |
651 | self.data = None |
|
651 | self.data = None | |
652 | self.utctime = None |
|
652 | self.utctime = None | |
653 | self.type = "AMISR" |
|
653 | self.type = "AMISR" | |
654 |
|
654 | |||
655 | #propiedades para compatibilidad con Voltages |
|
655 | #propiedades para compatibilidad con Voltages | |
656 | self.timeZone = 0#self.dataIn.timeZone |
|
656 | self.timeZone = 0#self.dataIn.timeZone | |
657 | self.dstFlag = 0#self.dataIn.dstFlag |
|
657 | self.dstFlag = 0#self.dataIn.dstFlag | |
658 | self.errorCount = 0#self.dataIn.errorCount |
|
658 | self.errorCount = 0#self.dataIn.errorCount | |
659 | self.useLocalTime = True#self.dataIn.useLocalTime |
|
659 | self.useLocalTime = True#self.dataIn.useLocalTime | |
660 |
|
660 | |||
661 | self.radarControllerHeaderObj = None#self.dataIn.radarControllerHeaderObj.copy() |
|
661 | self.radarControllerHeaderObj = None#self.dataIn.radarControllerHeaderObj.copy() | |
662 | self.systemHeaderObj = None#self.dataIn.systemHeaderObj.copy() |
|
662 | self.systemHeaderObj = None#self.dataIn.systemHeaderObj.copy() | |
663 | self.channelList = [1]#self.dataIn.channelList esto solo aplica para el caso de AMISR |
|
663 | self.channelList = [1]#self.dataIn.channelList esto solo aplica para el caso de AMISR | |
664 | self.dtype = numpy.dtype([('real','<f4'),('imag','<f4')]) |
|
664 | self.dtype = numpy.dtype([('real','<f4'),('imag','<f4')]) | |
665 |
|
665 | |||
666 | self.flagTimeBlock = None#self.dataIn.flagTimeBlock |
|
666 | self.flagTimeBlock = None#self.dataIn.flagTimeBlock | |
667 | #self.utctime = #self.firstdatatime |
|
667 | #self.utctime = #self.firstdatatime | |
668 | self.flagDecodeData = None#self.dataIn.flagDecodeData #asumo q la data esta decodificada |
|
668 | self.flagDecodeData = None#self.dataIn.flagDecodeData #asumo q la data esta decodificada | |
669 | self.flagDeflipData = None#self.dataIn.flagDeflipData #asumo q la data esta sin flip |
|
669 | self.flagDeflipData = None#self.dataIn.flagDeflipData #asumo q la data esta sin flip | |
670 |
|
670 | |||
671 | self.nCohInt = 1#self.dataIn.nCohInt |
|
671 | self.nCohInt = 1#self.dataIn.nCohInt | |
672 | self.nIncohInt = 1 |
|
672 | self.nIncohInt = 1 | |
673 | self.ippSeconds = 0.004#self.dataIn.ippSeconds, segun el filename/Setup/Tufile |
|
673 | self.ippSeconds = 0.004#self.dataIn.ippSeconds, segun el filename/Setup/Tufile | |
674 | self.windowOfFilter = None#self.dataIn.windowOfFilter |
|
674 | self.windowOfFilter = None#self.dataIn.windowOfFilter | |
675 |
|
675 | |||
676 | self.timeInterval = None#self.dataIn.timeInterval*self.dataOut.nFFTPoints*self.dataOut.nIncohInt |
|
676 | self.timeInterval = None#self.dataIn.timeInterval*self.dataOut.nFFTPoints*self.dataOut.nIncohInt | |
677 | self.frequency = 20000#self.dataIn.frequency |
|
677 | self.frequency = 20000000#self.dataIn.frequency | |
678 | self.realtime = 0#self.dataIn.realtime |
|
678 | self.realtime = 0#self.dataIn.realtime | |
679 |
|
679 | |||
680 | #actualizar en la lectura de datos |
|
680 | #actualizar en la lectura de datos | |
681 | self.heightList = None#self.dataIn.heightList |
|
681 | self.heightList = None#self.dataIn.heightList | |
682 | self.nProfiles = None#self.dataOut.nFFTPoints |
|
682 | self.nProfiles = None#self.dataOut.nFFTPoints | |
683 | self.nBaud = None#self.dataIn.nBaud |
|
683 | self.nBaud = None#self.dataIn.nBaud | |
684 | self.nCode = None#self.dataIn.nCode |
|
684 | self.nCode = None#self.dataIn.nCode | |
685 | self.code = None#self.dataIn.code |
|
685 | self.code = None#self.dataIn.code | |
686 |
|
686 | |||
687 |
|
687 | |||
688 | def isEmpty(self): |
|
688 | def isEmpty(self): | |
689 |
|
689 | |||
690 | return self.flagNoData No newline at end of file |
|
690 | return self.flagNoData |
@@ -1,2110 +1,2118 | |||||
1 | import numpy |
|
1 | import numpy | |
2 | import time, datetime, os |
|
2 | import time, datetime, os | |
3 | from graphics.figure import * |
|
3 | from graphics.figure import * | |
4 | def isRealtime(utcdatatime): |
|
4 | def isRealtime(utcdatatime): | |
5 | utcnow = time.mktime(time.localtime()) |
|
5 | utcnow = time.mktime(time.localtime()) | |
6 | delta = abs(utcnow - utcdatatime) # abs |
|
6 | delta = abs(utcnow - utcdatatime) # abs | |
7 | if delta >= 30.: |
|
7 | if delta >= 30.: | |
8 | return False |
|
8 | return False | |
9 | return True |
|
9 | return True | |
10 |
|
10 | |||
11 | class CrossSpectraPlot(Figure): |
|
11 | class CrossSpectraPlot(Figure): | |
12 |
|
12 | |||
13 | __isConfig = None |
|
13 | __isConfig = None | |
14 | __nsubplots = None |
|
14 | __nsubplots = None | |
15 |
|
15 | |||
16 | WIDTH = None |
|
16 | WIDTH = None | |
17 | HEIGHT = None |
|
17 | HEIGHT = None | |
18 | WIDTHPROF = None |
|
18 | WIDTHPROF = None | |
19 | HEIGHTPROF = None |
|
19 | HEIGHTPROF = None | |
20 | PREFIX = 'cspc' |
|
20 | PREFIX = 'cspc' | |
21 |
|
21 | |||
22 | def __init__(self): |
|
22 | def __init__(self): | |
23 |
|
23 | |||
24 | self.__isConfig = False |
|
24 | self.__isConfig = False | |
25 | self.__nsubplots = 4 |
|
25 | self.__nsubplots = 4 | |
26 | self.counter_imagwr = 0 |
|
26 | self.counter_imagwr = 0 | |
27 | self.WIDTH = 250 |
|
27 | self.WIDTH = 250 | |
28 | self.HEIGHT = 250 |
|
28 | self.HEIGHT = 250 | |
29 | self.WIDTHPROF = 0 |
|
29 | self.WIDTHPROF = 0 | |
30 | self.HEIGHTPROF = 0 |
|
30 | self.HEIGHTPROF = 0 | |
31 |
|
31 | |||
32 | self.PLOT_CODE = 1 |
|
32 | self.PLOT_CODE = 1 | |
33 | self.FTP_WEI = None |
|
33 | self.FTP_WEI = None | |
34 | self.EXP_CODE = None |
|
34 | self.EXP_CODE = None | |
35 | self.SUB_EXP_CODE = None |
|
35 | self.SUB_EXP_CODE = None | |
36 | self.PLOT_POS = None |
|
36 | self.PLOT_POS = None | |
37 |
|
37 | |||
38 | def getSubplots(self): |
|
38 | def getSubplots(self): | |
39 |
|
39 | |||
40 | ncol = 4 |
|
40 | ncol = 4 | |
41 | nrow = self.nplots |
|
41 | nrow = self.nplots | |
42 |
|
42 | |||
43 | return nrow, ncol |
|
43 | return nrow, ncol | |
44 |
|
44 | |||
45 | def setup(self, id, nplots, wintitle, showprofile=True, show=True): |
|
45 | def setup(self, id, nplots, wintitle, showprofile=True, show=True): | |
46 |
|
46 | |||
47 | self.__showprofile = showprofile |
|
47 | self.__showprofile = showprofile | |
48 | self.nplots = nplots |
|
48 | self.nplots = nplots | |
49 |
|
49 | |||
50 | ncolspan = 1 |
|
50 | ncolspan = 1 | |
51 | colspan = 1 |
|
51 | colspan = 1 | |
52 |
|
52 | |||
53 | self.createFigure(id = id, |
|
53 | self.createFigure(id = id, | |
54 | wintitle = wintitle, |
|
54 | wintitle = wintitle, | |
55 | widthplot = self.WIDTH + self.WIDTHPROF, |
|
55 | widthplot = self.WIDTH + self.WIDTHPROF, | |
56 | heightplot = self.HEIGHT + self.HEIGHTPROF, |
|
56 | heightplot = self.HEIGHT + self.HEIGHTPROF, | |
57 | show=True) |
|
57 | show=True) | |
58 |
|
58 | |||
59 | nrow, ncol = self.getSubplots() |
|
59 | nrow, ncol = self.getSubplots() | |
60 |
|
60 | |||
61 | counter = 0 |
|
61 | counter = 0 | |
62 | for y in range(nrow): |
|
62 | for y in range(nrow): | |
63 | for x in range(ncol): |
|
63 | for x in range(ncol): | |
64 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1) |
|
64 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1) | |
65 |
|
65 | |||
66 | counter += 1 |
|
66 | counter += 1 | |
67 |
|
67 | |||
68 | def run(self, dataOut, id, wintitle="", pairsList=None, |
|
68 | def run(self, dataOut, id, wintitle="", pairsList=None, | |
69 | xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None, |
|
69 | xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None, | |
70 | save=False, figpath='./', figfile=None, ftp=False, wr_period=1, |
|
70 | save=False, figpath='./', figfile=None, ftp=False, wr_period=1, | |
71 | power_cmap='jet', coherence_cmap='jet', phase_cmap='RdBu_r', show=True, |
|
71 | power_cmap='jet', coherence_cmap='jet', phase_cmap='RdBu_r', show=True, | |
72 | server=None, folder=None, username=None, password=None, |
|
72 | server=None, folder=None, username=None, password=None, | |
73 | ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0): |
|
73 | ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0): | |
74 |
|
74 | |||
75 | """ |
|
75 | """ | |
76 |
|
76 | |||
77 | Input: |
|
77 | Input: | |
78 | dataOut : |
|
78 | dataOut : | |
79 | id : |
|
79 | id : | |
80 | wintitle : |
|
80 | wintitle : | |
81 | channelList : |
|
81 | channelList : | |
82 | showProfile : |
|
82 | showProfile : | |
83 | xmin : None, |
|
83 | xmin : None, | |
84 | xmax : None, |
|
84 | xmax : None, | |
85 | ymin : None, |
|
85 | ymin : None, | |
86 | ymax : None, |
|
86 | ymax : None, | |
87 | zmin : None, |
|
87 | zmin : None, | |
88 | zmax : None |
|
88 | zmax : None | |
89 | """ |
|
89 | """ | |
90 |
|
90 | |||
91 | if pairsList == None: |
|
91 | if pairsList == None: | |
92 | pairsIndexList = dataOut.pairsIndexList |
|
92 | pairsIndexList = dataOut.pairsIndexList | |
93 | else: |
|
93 | else: | |
94 | pairsIndexList = [] |
|
94 | pairsIndexList = [] | |
95 | for pair in pairsList: |
|
95 | for pair in pairsList: | |
96 | if pair not in dataOut.pairsList: |
|
96 | if pair not in dataOut.pairsList: | |
97 | raise ValueError, "Pair %s is not in dataOut.pairsList" %(pair) |
|
97 | raise ValueError, "Pair %s is not in dataOut.pairsList" %(pair) | |
98 | pairsIndexList.append(dataOut.pairsList.index(pair)) |
|
98 | pairsIndexList.append(dataOut.pairsList.index(pair)) | |
99 |
|
99 | |||
100 | if pairsIndexList == []: |
|
100 | if pairsIndexList == []: | |
101 | return |
|
101 | return | |
102 |
|
102 | |||
103 | if len(pairsIndexList) > 4: |
|
103 | if len(pairsIndexList) > 4: | |
104 | pairsIndexList = pairsIndexList[0:4] |
|
104 | pairsIndexList = pairsIndexList[0:4] | |
105 | factor = dataOut.normFactor |
|
105 | factor = dataOut.normFactor | |
106 | x = dataOut.getVelRange(1) |
|
106 | x = dataOut.getVelRange(1) | |
107 | y = dataOut.getHeiRange() |
|
107 | y = dataOut.getHeiRange() | |
108 | z = dataOut.data_spc[:,:,:]/factor |
|
108 | z = dataOut.data_spc[:,:,:]/factor | |
109 | # z = numpy.where(numpy.isfinite(z), z, numpy.NAN) |
|
109 | # z = numpy.where(numpy.isfinite(z), z, numpy.NAN) | |
110 | avg = numpy.abs(numpy.average(z, axis=1)) |
|
110 | avg = numpy.abs(numpy.average(z, axis=1)) | |
111 | noise = dataOut.getNoise()/factor |
|
111 | noise = dataOut.getNoise()/factor | |
112 |
|
112 | |||
113 | zdB = 10*numpy.log10(z) |
|
113 | zdB = 10*numpy.log10(z) | |
114 | avgdB = 10*numpy.log10(avg) |
|
114 | avgdB = 10*numpy.log10(avg) | |
115 | noisedB = 10*numpy.log10(noise) |
|
115 | noisedB = 10*numpy.log10(noise) | |
116 |
|
116 | |||
117 |
|
117 | |||
118 | #thisDatetime = dataOut.datatime |
|
118 | #thisDatetime = dataOut.datatime | |
119 | thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[1]) |
|
119 | thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[1]) | |
120 | title = wintitle + " Cross-Spectra: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) |
|
120 | title = wintitle + " Cross-Spectra: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) | |
121 | xlabel = "Velocity (m/s)" |
|
121 | xlabel = "Velocity (m/s)" | |
122 | ylabel = "Range (Km)" |
|
122 | ylabel = "Range (Km)" | |
123 |
|
123 | |||
124 | if not self.__isConfig: |
|
124 | if not self.__isConfig: | |
125 |
|
125 | |||
126 | nplots = len(pairsIndexList) |
|
126 | nplots = len(pairsIndexList) | |
127 |
|
127 | |||
128 | self.setup(id=id, |
|
128 | self.setup(id=id, | |
129 | nplots=nplots, |
|
129 | nplots=nplots, | |
130 | wintitle=wintitle, |
|
130 | wintitle=wintitle, | |
131 | showprofile=False, |
|
131 | showprofile=False, | |
132 | show=show) |
|
132 | show=show) | |
133 |
|
133 | |||
134 | if xmin == None: xmin = numpy.nanmin(x) |
|
134 | if xmin == None: xmin = numpy.nanmin(x) | |
135 | if xmax == None: xmax = numpy.nanmax(x) |
|
135 | if xmax == None: xmax = numpy.nanmax(x) | |
136 | if ymin == None: ymin = numpy.nanmin(y) |
|
136 | if ymin == None: ymin = numpy.nanmin(y) | |
137 | if ymax == None: ymax = numpy.nanmax(y) |
|
137 | if ymax == None: ymax = numpy.nanmax(y) | |
138 | if zmin == None: zmin = numpy.nanmin(avgdB)*0.9 |
|
138 | if zmin == None: zmin = numpy.nanmin(avgdB)*0.9 | |
139 | if zmax == None: zmax = numpy.nanmax(avgdB)*0.9 |
|
139 | if zmax == None: zmax = numpy.nanmax(avgdB)*0.9 | |
140 |
|
140 | |||
141 | self.FTP_WEI = ftp_wei |
|
141 | self.FTP_WEI = ftp_wei | |
142 | self.EXP_CODE = exp_code |
|
142 | self.EXP_CODE = exp_code | |
143 | self.SUB_EXP_CODE = sub_exp_code |
|
143 | self.SUB_EXP_CODE = sub_exp_code | |
144 | self.PLOT_POS = plot_pos |
|
144 | self.PLOT_POS = plot_pos | |
145 |
|
145 | |||
146 | self.__isConfig = True |
|
146 | self.__isConfig = True | |
147 |
|
147 | |||
148 | self.setWinTitle(title) |
|
148 | self.setWinTitle(title) | |
149 |
|
149 | |||
150 | for i in range(self.nplots): |
|
150 | for i in range(self.nplots): | |
151 | pair = dataOut.pairsList[pairsIndexList[i]] |
|
151 | pair = dataOut.pairsList[pairsIndexList[i]] | |
152 | str_datetime = '%s %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S")) |
|
152 | str_datetime = '%s %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S")) | |
153 | title = "Ch%d: %4.2fdB: %s" %(pair[0], noisedB[pair[0]], str_datetime) |
|
153 | title = "Ch%d: %4.2fdB: %s" %(pair[0], noisedB[pair[0]], str_datetime) | |
154 | zdB = 10.*numpy.log10(dataOut.data_spc[pair[0],:,:]) |
|
154 | zdB = 10.*numpy.log10(dataOut.data_spc[pair[0],:,:]) | |
155 | axes0 = self.axesList[i*self.__nsubplots] |
|
155 | axes0 = self.axesList[i*self.__nsubplots] | |
156 | axes0.pcolor(x, y, zdB, |
|
156 | axes0.pcolor(x, y, zdB, | |
157 | xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax, |
|
157 | xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax, | |
158 | xlabel=xlabel, ylabel=ylabel, title=title, |
|
158 | xlabel=xlabel, ylabel=ylabel, title=title, | |
159 | ticksize=9, colormap=power_cmap, cblabel='') |
|
159 | ticksize=9, colormap=power_cmap, cblabel='') | |
160 |
|
160 | |||
161 | title = "Ch%d: %4.2fdB: %s" %(pair[1], noisedB[pair[1]], str_datetime) |
|
161 | title = "Ch%d: %4.2fdB: %s" %(pair[1], noisedB[pair[1]], str_datetime) | |
162 | zdB = 10.*numpy.log10(dataOut.data_spc[pair[1],:,:]) |
|
162 | zdB = 10.*numpy.log10(dataOut.data_spc[pair[1],:,:]) | |
163 | axes0 = self.axesList[i*self.__nsubplots+1] |
|
163 | axes0 = self.axesList[i*self.__nsubplots+1] | |
164 | axes0.pcolor(x, y, zdB, |
|
164 | axes0.pcolor(x, y, zdB, | |
165 | xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax, |
|
165 | xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax, | |
166 | xlabel=xlabel, ylabel=ylabel, title=title, |
|
166 | xlabel=xlabel, ylabel=ylabel, title=title, | |
167 | ticksize=9, colormap=power_cmap, cblabel='') |
|
167 | ticksize=9, colormap=power_cmap, cblabel='') | |
168 |
|
168 | |||
169 | coherenceComplex = dataOut.data_cspc[pairsIndexList[i],:,:]/numpy.sqrt(dataOut.data_spc[pair[0],:,:]*dataOut.data_spc[pair[1],:,:]) |
|
169 | coherenceComplex = dataOut.data_cspc[pairsIndexList[i],:,:]/numpy.sqrt(dataOut.data_spc[pair[0],:,:]*dataOut.data_spc[pair[1],:,:]) | |
170 | coherence = numpy.abs(coherenceComplex) |
|
170 | coherence = numpy.abs(coherenceComplex) | |
171 | # phase = numpy.arctan(-1*coherenceComplex.imag/coherenceComplex.real)*180/numpy.pi |
|
171 | # phase = numpy.arctan(-1*coherenceComplex.imag/coherenceComplex.real)*180/numpy.pi | |
172 | phase = numpy.arctan2(coherenceComplex.imag, coherenceComplex.real)*180/numpy.pi |
|
172 | phase = numpy.arctan2(coherenceComplex.imag, coherenceComplex.real)*180/numpy.pi | |
173 |
|
173 | |||
174 | title = "Coherence %d%d" %(pair[0], pair[1]) |
|
174 | title = "Coherence %d%d" %(pair[0], pair[1]) | |
175 | axes0 = self.axesList[i*self.__nsubplots+2] |
|
175 | axes0 = self.axesList[i*self.__nsubplots+2] | |
176 | axes0.pcolor(x, y, coherence, |
|
176 | axes0.pcolor(x, y, coherence, | |
177 | xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=0, zmax=1, |
|
177 | xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=0, zmax=1, | |
178 | xlabel=xlabel, ylabel=ylabel, title=title, |
|
178 | xlabel=xlabel, ylabel=ylabel, title=title, | |
179 | ticksize=9, colormap=coherence_cmap, cblabel='') |
|
179 | ticksize=9, colormap=coherence_cmap, cblabel='') | |
180 |
|
180 | |||
181 | title = "Phase %d%d" %(pair[0], pair[1]) |
|
181 | title = "Phase %d%d" %(pair[0], pair[1]) | |
182 | axes0 = self.axesList[i*self.__nsubplots+3] |
|
182 | axes0 = self.axesList[i*self.__nsubplots+3] | |
183 | axes0.pcolor(x, y, phase, |
|
183 | axes0.pcolor(x, y, phase, | |
184 | xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=-180, zmax=180, |
|
184 | xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=-180, zmax=180, | |
185 | xlabel=xlabel, ylabel=ylabel, title=title, |
|
185 | xlabel=xlabel, ylabel=ylabel, title=title, | |
186 | ticksize=9, colormap=phase_cmap, cblabel='') |
|
186 | ticksize=9, colormap=phase_cmap, cblabel='') | |
187 |
|
187 | |||
188 |
|
188 | |||
189 |
|
189 | |||
190 | self.draw() |
|
190 | self.draw() | |
191 |
|
191 | |||
192 | if save: |
|
192 | if save: | |
193 |
|
193 | |||
194 | self.counter_imagwr += 1 |
|
194 | self.counter_imagwr += 1 | |
195 | if (self.counter_imagwr==wr_period): |
|
195 | if (self.counter_imagwr==wr_period): | |
196 | if figfile == None: |
|
196 | if figfile == None: | |
197 | str_datetime = thisDatetime.strftime("%Y%m%d_%H%M%S") |
|
197 | str_datetime = thisDatetime.strftime("%Y%m%d_%H%M%S") | |
198 | figfile = self.getFilename(name = str_datetime) |
|
198 | figfile = self.getFilename(name = str_datetime) | |
199 |
|
199 | |||
200 | self.saveFigure(figpath, figfile) |
|
200 | self.saveFigure(figpath, figfile) | |
201 |
|
201 | |||
202 | if ftp: |
|
202 | if ftp: | |
203 | #provisionalmente envia archivos en el formato de la web en tiempo real |
|
203 | #provisionalmente envia archivos en el formato de la web en tiempo real | |
204 | name = self.getNameToFtp(thisDatetime, self.FTP_WEI, self.EXP_CODE, self.SUB_EXP_CODE, self.PLOT_CODE, self.PLOT_POS) |
|
204 | name = self.getNameToFtp(thisDatetime, self.FTP_WEI, self.EXP_CODE, self.SUB_EXP_CODE, self.PLOT_CODE, self.PLOT_POS) | |
205 | path = '%s%03d' %(self.PREFIX, self.id) |
|
205 | path = '%s%03d' %(self.PREFIX, self.id) | |
206 | ftp_file = os.path.join(path,'ftp','%s.png'%name) |
|
206 | ftp_file = os.path.join(path,'ftp','%s.png'%name) | |
207 | self.saveFigure(figpath, ftp_file) |
|
207 | self.saveFigure(figpath, ftp_file) | |
208 | ftp_filename = os.path.join(figpath,ftp_file) |
|
208 | ftp_filename = os.path.join(figpath,ftp_file) | |
209 |
|
209 | |||
210 | self.sendByFTP_Thread(ftp_filename, server, folder, username, password) |
|
210 | self.sendByFTP_Thread(ftp_filename, server, folder, username, password) | |
211 | self.counter_imagwr = 0 |
|
211 | self.counter_imagwr = 0 | |
212 |
|
212 | |||
213 | self.counter_imagwr = 0 |
|
213 | self.counter_imagwr = 0 | |
214 |
|
214 | |||
215 | class SNRPlot(Figure): |
|
215 | class SNRPlot(Figure): | |
216 |
|
216 | |||
217 | __isConfig = None |
|
217 | __isConfig = None | |
218 | __nsubplots = None |
|
218 | __nsubplots = None | |
219 |
|
219 | |||
220 | WIDTHPROF = None |
|
220 | WIDTHPROF = None | |
221 | HEIGHTPROF = None |
|
221 | HEIGHTPROF = None | |
222 | PREFIX = 'snr' |
|
222 | PREFIX = 'snr' | |
223 |
|
223 | |||
224 | def __init__(self): |
|
224 | def __init__(self): | |
225 |
|
225 | |||
226 | self.timerange = 2*60*60 |
|
226 | self.timerange = 2*60*60 | |
227 | self.__isConfig = False |
|
227 | self.__isConfig = False | |
228 | self.__nsubplots = 1 |
|
228 | self.__nsubplots = 1 | |
229 |
|
229 | |||
230 | self.WIDTH = 800 |
|
230 | self.WIDTH = 800 | |
231 | self.HEIGHT = 150 |
|
231 | self.HEIGHT = 150 | |
232 | self.WIDTHPROF = 120 |
|
232 | self.WIDTHPROF = 120 | |
233 | self.HEIGHTPROF = 0 |
|
233 | self.HEIGHTPROF = 0 | |
234 | self.counter_imagwr = 0 |
|
234 | self.counter_imagwr = 0 | |
235 |
|
235 | |||
236 | self.PLOT_CODE = 0 |
|
236 | self.PLOT_CODE = 0 | |
237 | self.FTP_WEI = None |
|
237 | self.FTP_WEI = None | |
238 | self.EXP_CODE = None |
|
238 | self.EXP_CODE = None | |
239 | self.SUB_EXP_CODE = None |
|
239 | self.SUB_EXP_CODE = None | |
240 | self.PLOT_POS = None |
|
240 | self.PLOT_POS = None | |
241 |
|
241 | |||
242 | def getSubplots(self): |
|
242 | def getSubplots(self): | |
243 |
|
243 | |||
244 | ncol = 1 |
|
244 | ncol = 1 | |
245 | nrow = self.nplots |
|
245 | nrow = self.nplots | |
246 |
|
246 | |||
247 | return nrow, ncol |
|
247 | return nrow, ncol | |
248 |
|
248 | |||
249 | def setup(self, id, nplots, wintitle, showprofile=True, show=True): |
|
249 | def setup(self, id, nplots, wintitle, showprofile=True, show=True): | |
250 |
|
250 | |||
251 | self.__showprofile = showprofile |
|
251 | self.__showprofile = showprofile | |
252 | self.nplots = nplots |
|
252 | self.nplots = nplots | |
253 |
|
253 | |||
254 | ncolspan = 1 |
|
254 | ncolspan = 1 | |
255 | colspan = 1 |
|
255 | colspan = 1 | |
256 | if showprofile: |
|
256 | if showprofile: | |
257 | ncolspan = 7 |
|
257 | ncolspan = 7 | |
258 | colspan = 6 |
|
258 | colspan = 6 | |
259 | self.__nsubplots = 2 |
|
259 | self.__nsubplots = 2 | |
260 |
|
260 | |||
261 | self.createFigure(id = id, |
|
261 | self.createFigure(id = id, | |
262 | wintitle = wintitle, |
|
262 | wintitle = wintitle, | |
263 | widthplot = self.WIDTH + self.WIDTHPROF, |
|
263 | widthplot = self.WIDTH + self.WIDTHPROF, | |
264 | heightplot = self.HEIGHT + self.HEIGHTPROF, |
|
264 | heightplot = self.HEIGHT + self.HEIGHTPROF, | |
265 | show=show) |
|
265 | show=show) | |
266 |
|
266 | |||
267 | nrow, ncol = self.getSubplots() |
|
267 | nrow, ncol = self.getSubplots() | |
268 |
|
268 | |||
269 | counter = 0 |
|
269 | counter = 0 | |
270 | for y in range(nrow): |
|
270 | for y in range(nrow): | |
271 | for x in range(ncol): |
|
271 | for x in range(ncol): | |
272 |
|
272 | |||
273 | if counter >= self.nplots: |
|
273 | if counter >= self.nplots: | |
274 | break |
|
274 | break | |
275 |
|
275 | |||
276 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1) |
|
276 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1) | |
277 |
|
277 | |||
278 | if showprofile: |
|
278 | if showprofile: | |
279 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1) |
|
279 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1) | |
280 |
|
280 | |||
281 | counter += 1 |
|
281 | counter += 1 | |
282 |
|
282 | |||
283 | def run(self, dataOut, id, wintitle="", channelList=None, showprofile=False, |
|
283 | def run(self, dataOut, id, wintitle="", channelList=None, showprofile=False, | |
284 | xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None, |
|
284 | xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None, | |
285 | timerange=None, |
|
285 | timerange=None, | |
286 | save=False, figpath='./', lastone=0,figfile=None, ftp=False, wr_period=1, show=True, |
|
286 | save=False, figpath='./', lastone=0,figfile=None, ftp=False, wr_period=1, show=True, | |
287 | server=None, folder=None, username=None, password=None, |
|
287 | server=None, folder=None, username=None, password=None, | |
288 | ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0): |
|
288 | ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0): | |
289 |
|
289 | |||
290 | """ |
|
290 | """ | |
291 |
|
291 | |||
292 | Input: |
|
292 | Input: | |
293 | dataOut : |
|
293 | dataOut : | |
294 | id : |
|
294 | id : | |
295 | wintitle : |
|
295 | wintitle : | |
296 | channelList : |
|
296 | channelList : | |
297 | showProfile : |
|
297 | showProfile : | |
298 | xmin : None, |
|
298 | xmin : None, | |
299 | xmax : None, |
|
299 | xmax : None, | |
300 | ymin : None, |
|
300 | ymin : None, | |
301 | ymax : None, |
|
301 | ymax : None, | |
302 | zmin : None, |
|
302 | zmin : None, | |
303 | zmax : None |
|
303 | zmax : None | |
304 | """ |
|
304 | """ | |
305 |
|
305 | |||
306 | if channelList == None: |
|
306 | if channelList == None: | |
307 | channelIndexList = dataOut.channelIndexList |
|
307 | channelIndexList = dataOut.channelIndexList | |
308 | else: |
|
308 | else: | |
309 | channelIndexList = [] |
|
309 | channelIndexList = [] | |
310 | for channel in channelList: |
|
310 | for channel in channelList: | |
311 | if channel not in dataOut.channelList: |
|
311 | if channel not in dataOut.channelList: | |
312 | raise ValueError, "Channel %d is not in dataOut.channelList" |
|
312 | raise ValueError, "Channel %d is not in dataOut.channelList" | |
313 | channelIndexList.append(dataOut.channelList.index(channel)) |
|
313 | channelIndexList.append(dataOut.channelList.index(channel)) | |
314 |
|
314 | |||
315 | if timerange != None: |
|
315 | if timerange != None: | |
316 | self.timerange = timerange |
|
316 | self.timerange = timerange | |
317 |
|
317 | |||
318 | tmin = None |
|
318 | tmin = None | |
319 | tmax = None |
|
319 | tmax = None | |
320 | factor = dataOut.normFactor |
|
320 | factor = dataOut.normFactor | |
321 | x = dataOut.getTimeRange() |
|
321 | x = dataOut.getTimeRange() | |
322 | y = dataOut.getHeiRange() |
|
322 | y = dataOut.getHeiRange() | |
323 |
|
323 | |||
324 | z = dataOut.data_spc[channelIndexList,:,:]/factor |
|
324 | z = dataOut.data_spc[channelIndexList,:,:]/factor | |
325 | z = numpy.where(numpy.isfinite(z), z, numpy.NAN) |
|
325 | z = numpy.where(numpy.isfinite(z), z, numpy.NAN) | |
326 | avg = numpy.average(z, axis=1) |
|
326 | avg = numpy.average(z, axis=1) | |
327 |
|
327 | |||
328 | avgdB = 10.*numpy.log10(avg) |
|
328 | avgdB = 10.*numpy.log10(avg) | |
329 |
|
329 | |||
330 | noise = dataOut.getNoise()/factor |
|
330 | noise = dataOut.getNoise()/factor | |
331 | noisedB = 10.*numpy.log10(noise) |
|
331 | noisedB = 10.*numpy.log10(noise) | |
332 |
|
332 | |||
333 | SNR = numpy.transpose(numpy.divide(avg.T,noise)) |
|
333 | SNR = numpy.transpose(numpy.divide(avg.T,noise)) | |
334 |
|
334 | |||
335 | SNR_dB = 10.*numpy.log10(SNR) |
|
335 | SNR_dB = 10.*numpy.log10(SNR) | |
336 |
|
336 | |||
337 | #SNR_dB = numpy.transpose(numpy.subtract(avgdB.T, noisedB)) |
|
337 | #SNR_dB = numpy.transpose(numpy.subtract(avgdB.T, noisedB)) | |
338 |
|
338 | |||
339 | # thisDatetime = dataOut.datatime |
|
339 | # thisDatetime = dataOut.datatime | |
340 | thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[1]) |
|
340 | thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[1]) | |
341 | title = wintitle + " RTI" #: %s" %(thisDatetime.strftime("%d-%b-%Y")) |
|
341 | title = wintitle + " RTI" #: %s" %(thisDatetime.strftime("%d-%b-%Y")) | |
342 | xlabel = "" |
|
342 | xlabel = "" | |
343 | ylabel = "Range (Km)" |
|
343 | ylabel = "Range (Km)" | |
344 |
|
344 | |||
345 | if not self.__isConfig: |
|
345 | if not self.__isConfig: | |
346 |
|
346 | |||
347 | nplots = len(channelIndexList) |
|
347 | nplots = len(channelIndexList) | |
348 |
|
348 | |||
349 | self.setup(id=id, |
|
349 | self.setup(id=id, | |
350 | nplots=nplots, |
|
350 | nplots=nplots, | |
351 | wintitle=wintitle, |
|
351 | wintitle=wintitle, | |
352 | showprofile=showprofile, |
|
352 | showprofile=showprofile, | |
353 | show=show) |
|
353 | show=show) | |
354 |
|
354 | |||
355 | tmin, tmax = self.getTimeLim(x, xmin, xmax) |
|
355 | tmin, tmax = self.getTimeLim(x, xmin, xmax) | |
356 | if ymin == None: ymin = numpy.nanmin(y) |
|
356 | if ymin == None: ymin = numpy.nanmin(y) | |
357 | if ymax == None: ymax = numpy.nanmax(y) |
|
357 | if ymax == None: ymax = numpy.nanmax(y) | |
358 | if zmin == None: zmin = numpy.nanmin(avgdB)*0.9 |
|
358 | if zmin == None: zmin = numpy.nanmin(avgdB)*0.9 | |
359 | if zmax == None: zmax = numpy.nanmax(avgdB)*0.9 |
|
359 | if zmax == None: zmax = numpy.nanmax(avgdB)*0.9 | |
360 |
|
360 | |||
361 | self.FTP_WEI = ftp_wei |
|
361 | self.FTP_WEI = ftp_wei | |
362 | self.EXP_CODE = exp_code |
|
362 | self.EXP_CODE = exp_code | |
363 | self.SUB_EXP_CODE = sub_exp_code |
|
363 | self.SUB_EXP_CODE = sub_exp_code | |
364 | self.PLOT_POS = plot_pos |
|
364 | self.PLOT_POS = plot_pos | |
365 |
|
365 | |||
366 | self.name = thisDatetime.strftime("%Y%m%d_%H%M%S") |
|
366 | self.name = thisDatetime.strftime("%Y%m%d_%H%M%S") | |
367 | self.__isConfig = True |
|
367 | self.__isConfig = True | |
368 |
|
368 | |||
369 |
|
369 | |||
370 | self.setWinTitle(title) |
|
370 | self.setWinTitle(title) | |
371 |
|
371 | |||
372 | for i in range(self.nplots): |
|
372 | for i in range(self.nplots): | |
373 | title = "Channel %d: %s" %(dataOut.channelList[i]+1, thisDatetime.strftime("%Y/%m/%d %H:%M:%S")) |
|
373 | title = "Channel %d: %s" %(dataOut.channelList[i]+1, thisDatetime.strftime("%Y/%m/%d %H:%M:%S")) | |
374 | axes = self.axesList[i*self.__nsubplots] |
|
374 | axes = self.axesList[i*self.__nsubplots] | |
375 | zdB = SNR_dB[i].reshape((1,-1)) |
|
375 | zdB = SNR_dB[i].reshape((1,-1)) | |
376 | axes.pcolorbuffer(x, y, zdB, |
|
376 | axes.pcolorbuffer(x, y, zdB, | |
377 | xmin=tmin, xmax=tmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax, |
|
377 | xmin=tmin, xmax=tmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax, | |
378 | xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True, |
|
378 | xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True, | |
379 | ticksize=9, cblabel='', cbsize="1%") |
|
379 | ticksize=9, cblabel='', cbsize="1%") | |
380 |
|
380 | |||
381 | # if self.__showprofile: |
|
381 | # if self.__showprofile: | |
382 | # axes = self.axesList[i*self.__nsubplots +1] |
|
382 | # axes = self.axesList[i*self.__nsubplots +1] | |
383 | # axes.pline(avgdB[i], y, |
|
383 | # axes.pline(avgdB[i], y, | |
384 | # xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax, |
|
384 | # xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax, | |
385 | # xlabel='dB', ylabel='', title='', |
|
385 | # xlabel='dB', ylabel='', title='', | |
386 | # ytick_visible=False, |
|
386 | # ytick_visible=False, | |
387 | # grid='x') |
|
387 | # grid='x') | |
388 | # |
|
388 | # | |
389 | self.draw() |
|
389 | self.draw() | |
390 |
|
390 | |||
391 | if lastone: |
|
391 | if lastone: | |
392 | if dataOut.blocknow >= dataOut.last_block: |
|
392 | if dataOut.blocknow >= dataOut.last_block: | |
393 | if figfile == None: |
|
393 | if figfile == None: | |
394 | figfile = self.getFilename(name = self.name) |
|
394 | figfile = self.getFilename(name = self.name) | |
395 | self.saveFigure(figpath, figfile) |
|
395 | self.saveFigure(figpath, figfile) | |
396 |
|
396 | |||
397 | if (save and not(lastone)): |
|
397 | if (save and not(lastone)): | |
398 |
|
398 | |||
399 | self.counter_imagwr += 1 |
|
399 | self.counter_imagwr += 1 | |
400 | if (self.counter_imagwr==wr_period): |
|
400 | if (self.counter_imagwr==wr_period): | |
401 | if figfile == None: |
|
401 | if figfile == None: | |
402 | figfile = self.getFilename(name = self.name) |
|
402 | figfile = self.getFilename(name = self.name) | |
403 | self.saveFigure(figpath, figfile) |
|
403 | self.saveFigure(figpath, figfile) | |
404 |
|
404 | |||
405 | if ftp: |
|
405 | if ftp: | |
406 | #provisionalmente envia archivos en el formato de la web en tiempo real |
|
406 | #provisionalmente envia archivos en el formato de la web en tiempo real | |
407 | name = self.getNameToFtp(thisDatetime, self.FTP_WEI, self.EXP_CODE, self.SUB_EXP_CODE, self.PLOT_CODE, self.PLOT_POS) |
|
407 | name = self.getNameToFtp(thisDatetime, self.FTP_WEI, self.EXP_CODE, self.SUB_EXP_CODE, self.PLOT_CODE, self.PLOT_POS) | |
408 | path = '%s%03d' %(self.PREFIX, self.id) |
|
408 | path = '%s%03d' %(self.PREFIX, self.id) | |
409 | ftp_file = os.path.join(path,'ftp','%s.png'%name) |
|
409 | ftp_file = os.path.join(path,'ftp','%s.png'%name) | |
410 | self.saveFigure(figpath, ftp_file) |
|
410 | self.saveFigure(figpath, ftp_file) | |
411 | ftp_filename = os.path.join(figpath,ftp_file) |
|
411 | ftp_filename = os.path.join(figpath,ftp_file) | |
412 | self.sendByFTP_Thread(ftp_filename, server, folder, username, password) |
|
412 | self.sendByFTP_Thread(ftp_filename, server, folder, username, password) | |
413 | self.counter_imagwr = 0 |
|
413 | self.counter_imagwr = 0 | |
414 |
|
414 | |||
415 | self.counter_imagwr = 0 |
|
415 | self.counter_imagwr = 0 | |
416 |
|
416 | |||
417 | if x[1] + (x[1]-x[0]) >= self.axesList[0].xmax: |
|
417 | if x[1] + (x[1]-x[0]) >= self.axesList[0].xmax: | |
418 |
|
418 | |||
419 | self.__isConfig = False |
|
419 | self.__isConfig = False | |
420 |
|
420 | |||
421 | if lastone: |
|
421 | if lastone: | |
422 | if figfile == None: |
|
422 | if figfile == None: | |
423 | figfile = self.getFilename(name = self.name) |
|
423 | figfile = self.getFilename(name = self.name) | |
424 | self.saveFigure(figpath, figfile) |
|
424 | self.saveFigure(figpath, figfile) | |
425 |
|
425 | |||
426 | if ftp: |
|
426 | if ftp: | |
427 | #provisionalmente envia archivos en el formato de la web en tiempo real |
|
427 | #provisionalmente envia archivos en el formato de la web en tiempo real | |
428 | name = self.getNameToFtp(thisDatetime, self.FTP_WEI, self.EXP_CODE, self.SUB_EXP_CODE, self.PLOT_CODE, self.PLOT_POS) |
|
428 | name = self.getNameToFtp(thisDatetime, self.FTP_WEI, self.EXP_CODE, self.SUB_EXP_CODE, self.PLOT_CODE, self.PLOT_POS) | |
429 | path = '%s%03d' %(self.PREFIX, self.id) |
|
429 | path = '%s%03d' %(self.PREFIX, self.id) | |
430 | ftp_file = os.path.join(path,'ftp','%s.png'%name) |
|
430 | ftp_file = os.path.join(path,'ftp','%s.png'%name) | |
431 | self.saveFigure(figpath, ftp_file) |
|
431 | self.saveFigure(figpath, ftp_file) | |
432 | ftp_filename = os.path.join(figpath,ftp_file) |
|
432 | ftp_filename = os.path.join(figpath,ftp_file) | |
433 | self.sendByFTP_Thread(ftp_filename, server, folder, username, password) |
|
433 | self.sendByFTP_Thread(ftp_filename, server, folder, username, password) | |
434 |
|
434 | |||
435 |
|
435 | |||
436 | class RTIPlot(Figure): |
|
436 | class RTIPlot(Figure): | |
437 |
|
437 | |||
438 | __isConfig = None |
|
438 | __isConfig = None | |
439 | __nsubplots = None |
|
439 | __nsubplots = None | |
440 |
|
440 | |||
441 | WIDTHPROF = None |
|
441 | WIDTHPROF = None | |
442 | HEIGHTPROF = None |
|
442 | HEIGHTPROF = None | |
443 | PREFIX = 'rti' |
|
443 | PREFIX = 'rti' | |
444 |
|
444 | |||
445 | def __init__(self): |
|
445 | def __init__(self): | |
446 |
|
446 | |||
447 | self.timerange = 2*60*60 |
|
447 | self.timerange = 2*60*60 | |
448 | self.__isConfig = False |
|
448 | self.__isConfig = False | |
449 | self.__nsubplots = 1 |
|
449 | self.__nsubplots = 1 | |
450 |
|
450 | |||
451 | self.WIDTH = 800 |
|
451 | self.WIDTH = 800 | |
452 | self.HEIGHT = 150 |
|
452 | self.HEIGHT = 150 | |
453 | self.WIDTHPROF = 120 |
|
453 | self.WIDTHPROF = 120 | |
454 | self.HEIGHTPROF = 0 |
|
454 | self.HEIGHTPROF = 0 | |
455 | self.counter_imagwr = 0 |
|
455 | self.counter_imagwr = 0 | |
456 |
|
456 | |||
457 | self.PLOT_CODE = 0 |
|
457 | self.PLOT_CODE = 0 | |
458 | self.FTP_WEI = None |
|
458 | self.FTP_WEI = None | |
459 | self.EXP_CODE = None |
|
459 | self.EXP_CODE = None | |
460 | self.SUB_EXP_CODE = None |
|
460 | self.SUB_EXP_CODE = None | |
461 | self.PLOT_POS = None |
|
461 | self.PLOT_POS = None | |
462 | self.tmin = None |
|
462 | self.tmin = None | |
463 | self.tmax = None |
|
463 | self.tmax = None | |
464 |
|
464 | |||
465 | self.xmin = None |
|
465 | self.xmin = None | |
466 | self.xmax = None |
|
466 | self.xmax = None | |
467 |
|
467 | |||
468 | def getSubplots(self): |
|
468 | def getSubplots(self): | |
469 |
|
469 | |||
470 | ncol = 1 |
|
470 | ncol = 1 | |
471 | nrow = self.nplots |
|
471 | nrow = self.nplots | |
472 |
|
472 | |||
473 | return nrow, ncol |
|
473 | return nrow, ncol | |
474 |
|
474 | |||
475 | def setup(self, id, nplots, wintitle, showprofile=True, show=True): |
|
475 | def setup(self, id, nplots, wintitle, showprofile=True, show=True): | |
476 |
|
476 | |||
477 | self.__showprofile = showprofile |
|
477 | self.__showprofile = showprofile | |
478 | self.nplots = nplots |
|
478 | self.nplots = nplots | |
479 |
|
479 | |||
480 | ncolspan = 1 |
|
480 | ncolspan = 1 | |
481 | colspan = 1 |
|
481 | colspan = 1 | |
482 | if showprofile: |
|
482 | if showprofile: | |
483 | ncolspan = 7 |
|
483 | ncolspan = 7 | |
484 | colspan = 6 |
|
484 | colspan = 6 | |
485 | self.__nsubplots = 2 |
|
485 | self.__nsubplots = 2 | |
486 |
|
486 | |||
487 | self.createFigure(id = id, |
|
487 | self.createFigure(id = id, | |
488 | wintitle = wintitle, |
|
488 | wintitle = wintitle, | |
489 | widthplot = self.WIDTH + self.WIDTHPROF, |
|
489 | widthplot = self.WIDTH + self.WIDTHPROF, | |
490 | heightplot = self.HEIGHT + self.HEIGHTPROF, |
|
490 | heightplot = self.HEIGHT + self.HEIGHTPROF, | |
491 | show=show) |
|
491 | show=show) | |
492 |
|
492 | |||
493 | nrow, ncol = self.getSubplots() |
|
493 | nrow, ncol = self.getSubplots() | |
494 |
|
494 | |||
495 | counter = 0 |
|
495 | counter = 0 | |
496 | for y in range(nrow): |
|
496 | for y in range(nrow): | |
497 | for x in range(ncol): |
|
497 | for x in range(ncol): | |
498 |
|
498 | |||
499 | if counter >= self.nplots: |
|
499 | if counter >= self.nplots: | |
500 | break |
|
500 | break | |
501 |
|
501 | |||
502 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1) |
|
502 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1) | |
503 |
|
503 | |||
504 | if showprofile: |
|
504 | if showprofile: | |
505 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1) |
|
505 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1) | |
506 |
|
506 | |||
507 | counter += 1 |
|
507 | counter += 1 | |
508 |
|
508 | |||
509 | def run(self, dataOut, id, wintitle="", channelList=None, showprofile='True', |
|
509 | def run(self, dataOut, id, wintitle="", channelList=None, showprofile='True', | |
510 | xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None, |
|
510 | xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None, | |
511 | timerange=None, |
|
511 | timerange=None, | |
512 | save=False, figpath='./', lastone=0,figfile=None, ftp=False, wr_period=1, show=True, |
|
512 | save=False, figpath='./', lastone=0,figfile=None, ftp=False, wr_period=1, show=True, | |
513 | server=None, folder=None, username=None, password=None, |
|
513 | server=None, folder=None, username=None, password=None, | |
514 | ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0): |
|
514 | ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0): | |
515 |
|
515 | |||
516 | """ |
|
516 | """ | |
517 |
|
517 | |||
518 | Input: |
|
518 | Input: | |
519 | dataOut : |
|
519 | dataOut : | |
520 | id : |
|
520 | id : | |
521 | wintitle : |
|
521 | wintitle : | |
522 | channelList : |
|
522 | channelList : | |
523 | showProfile : |
|
523 | showProfile : | |
524 | xmin : None, |
|
524 | xmin : None, | |
525 | xmax : None, |
|
525 | xmax : None, | |
526 | ymin : None, |
|
526 | ymin : None, | |
527 | ymax : None, |
|
527 | ymax : None, | |
528 | zmin : None, |
|
528 | zmin : None, | |
529 | zmax : None |
|
529 | zmax : None | |
530 | """ |
|
530 | """ | |
531 |
|
531 | |||
532 | if channelList == None: |
|
532 | if channelList == None: | |
533 | channelIndexList = dataOut.channelIndexList |
|
533 | channelIndexList = dataOut.channelIndexList | |
534 | else: |
|
534 | else: | |
535 | channelIndexList = [] |
|
535 | channelIndexList = [] | |
536 | for channel in channelList: |
|
536 | for channel in channelList: | |
537 | if channel not in dataOut.channelList: |
|
537 | if channel not in dataOut.channelList: | |
538 | raise ValueError, "Channel %d is not in dataOut.channelList" |
|
538 | raise ValueError, "Channel %d is not in dataOut.channelList" | |
539 | channelIndexList.append(dataOut.channelList.index(channel)) |
|
539 | channelIndexList.append(dataOut.channelList.index(channel)) | |
540 |
|
540 | |||
541 | if timerange != None: |
|
541 | if timerange != None: | |
542 | self.timerange = timerange |
|
542 | self.timerange = timerange | |
543 |
|
543 | |||
544 | #tmin = None |
|
544 | #tmin = None | |
545 | #tmax = None |
|
545 | #tmax = None | |
546 | factor = dataOut.normFactor |
|
546 | factor = dataOut.normFactor | |
547 | x = dataOut.getTimeRange() |
|
547 | x = dataOut.getTimeRange() | |
548 | y = dataOut.getHeiRange() |
|
548 | y = dataOut.getHeiRange() | |
549 |
|
549 | |||
550 | z = dataOut.data_spc[channelIndexList,:,:]/factor |
|
550 | z = dataOut.data_spc[channelIndexList,:,:]/factor | |
551 | z = numpy.where(numpy.isfinite(z), z, numpy.NAN) |
|
551 | z = numpy.where(numpy.isfinite(z), z, numpy.NAN) | |
552 | avg = numpy.average(z, axis=1) |
|
552 | avg = numpy.average(z, axis=1) | |
553 |
|
553 | |||
554 | avgdB = 10.*numpy.log10(avg) |
|
554 | avgdB = 10.*numpy.log10(avg) | |
555 |
|
555 | |||
556 |
|
556 | |||
557 | # thisDatetime = dataOut.datatime |
|
557 | # thisDatetime = dataOut.datatime | |
558 | thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[1]) |
|
558 | thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[1]) | |
559 | title = wintitle + " RTI" #: %s" %(thisDatetime.strftime("%d-%b-%Y")) |
|
559 | title = wintitle + " RTI" #: %s" %(thisDatetime.strftime("%d-%b-%Y")) | |
560 | xlabel = "" |
|
560 | xlabel = "" | |
561 | ylabel = "Range (Km)" |
|
561 | ylabel = "Range (Km)" | |
562 |
|
562 | |||
563 | if not self.__isConfig: |
|
563 | if not self.__isConfig: | |
564 |
|
564 | |||
565 | nplots = len(channelIndexList) |
|
565 | nplots = len(channelIndexList) | |
566 |
|
566 | |||
567 | self.setup(id=id, |
|
567 | self.setup(id=id, | |
568 | nplots=nplots, |
|
568 | nplots=nplots, | |
569 | wintitle=wintitle, |
|
569 | wintitle=wintitle, | |
570 | showprofile=showprofile, |
|
570 | showprofile=showprofile, | |
571 | show=show) |
|
571 | show=show) | |
572 |
|
572 | |||
573 | self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange) |
|
573 | self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange) | |
574 |
|
574 | |||
575 | # if timerange != None: |
|
575 | # if timerange != None: | |
576 | # self.timerange = timerange |
|
576 | # self.timerange = timerange | |
577 | # self.xmin, self.tmax = self.getTimeLim(x, xmin, xmax, timerange) |
|
577 | # self.xmin, self.tmax = self.getTimeLim(x, xmin, xmax, timerange) | |
578 |
|
578 | |||
579 |
|
579 | |||
580 |
|
580 | |||
581 | if ymin == None: ymin = numpy.nanmin(y) |
|
581 | if ymin == None: ymin = numpy.nanmin(y) | |
582 | if ymax == None: ymax = numpy.nanmax(y) |
|
582 | if ymax == None: ymax = numpy.nanmax(y) | |
583 | if zmin == None: zmin = numpy.nanmin(avgdB)*0.9 |
|
583 | if zmin == None: zmin = numpy.nanmin(avgdB)*0.9 | |
584 | if zmax == None: zmax = numpy.nanmax(avgdB)*0.9 |
|
584 | if zmax == None: zmax = numpy.nanmax(avgdB)*0.9 | |
585 |
|
585 | |||
586 | self.FTP_WEI = ftp_wei |
|
586 | self.FTP_WEI = ftp_wei | |
587 | self.EXP_CODE = exp_code |
|
587 | self.EXP_CODE = exp_code | |
588 | self.SUB_EXP_CODE = sub_exp_code |
|
588 | self.SUB_EXP_CODE = sub_exp_code | |
589 | self.PLOT_POS = plot_pos |
|
589 | self.PLOT_POS = plot_pos | |
590 |
|
590 | |||
591 | self.name = thisDatetime.strftime("%Y%m%d_%H%M%S") |
|
591 | self.name = thisDatetime.strftime("%Y%m%d_%H%M%S") | |
592 | self.__isConfig = True |
|
592 | self.__isConfig = True | |
593 |
|
593 | |||
594 |
|
594 | |||
595 | self.setWinTitle(title) |
|
595 | self.setWinTitle(title) | |
596 |
|
596 | |||
597 | if ((self.xmax - x[1]) < (x[1]-x[0])): |
|
597 | if ((self.xmax - x[1]) < (x[1]-x[0])): | |
598 | x[1] = self.xmax |
|
598 | x[1] = self.xmax | |
599 |
|
599 | |||
600 | for i in range(self.nplots): |
|
600 | for i in range(self.nplots): | |
601 | title = "Channel %d: %s" %(dataOut.channelList[i]+1, thisDatetime.strftime("%Y/%m/%d %H:%M:%S")) |
|
601 | title = "Channel %d: %s" %(dataOut.channelList[i]+1, thisDatetime.strftime("%Y/%m/%d %H:%M:%S")) | |
602 | axes = self.axesList[i*self.__nsubplots] |
|
602 | axes = self.axesList[i*self.__nsubplots] | |
603 | zdB = avgdB[i].reshape((1,-1)) |
|
603 | zdB = avgdB[i].reshape((1,-1)) | |
604 | axes.pcolorbuffer(x, y, zdB, |
|
604 | axes.pcolorbuffer(x, y, zdB, | |
605 | xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax, |
|
605 | xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax, | |
606 | xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True, |
|
606 | xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True, | |
607 | ticksize=9, cblabel='', cbsize="1%") |
|
607 | ticksize=9, cblabel='', cbsize="1%") | |
608 |
|
608 | |||
609 | if self.__showprofile: |
|
609 | if self.__showprofile: | |
610 | axes = self.axesList[i*self.__nsubplots +1] |
|
610 | axes = self.axesList[i*self.__nsubplots +1] | |
611 | axes.pline(avgdB[i], y, |
|
611 | axes.pline(avgdB[i], y, | |
612 | xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax, |
|
612 | xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax, | |
613 | xlabel='dB', ylabel='', title='', |
|
613 | xlabel='dB', ylabel='', title='', | |
614 | ytick_visible=False, |
|
614 | ytick_visible=False, | |
615 | grid='x') |
|
615 | grid='x') | |
616 |
|
616 | |||
617 | self.draw() |
|
617 | self.draw() | |
618 |
|
618 | |||
619 | # if lastone: |
|
619 | # if lastone: | |
620 | # if dataOut.blocknow >= dataOut.last_block: |
|
620 | # if dataOut.blocknow >= dataOut.last_block: | |
621 | # if figfile == None: |
|
621 | # if figfile == None: | |
622 | # figfile = self.getFilename(name = self.name) |
|
622 | # figfile = self.getFilename(name = self.name) | |
623 | # self.saveFigure(figpath, figfile) |
|
623 | # self.saveFigure(figpath, figfile) | |
624 | # |
|
624 | # | |
625 | # if (save and not(lastone)): |
|
625 | # if (save and not(lastone)): | |
626 | # |
|
626 | # | |
627 | # self.counter_imagwr += 1 |
|
627 | # self.counter_imagwr += 1 | |
628 | # if (self.counter_imagwr==wr_period): |
|
628 | # if (self.counter_imagwr==wr_period): | |
629 | # if figfile == None: |
|
629 | # if figfile == None: | |
630 | # figfile = self.getFilename(name = self.name) |
|
630 | # figfile = self.getFilename(name = self.name) | |
631 | # self.saveFigure(figpath, figfile) |
|
631 | # self.saveFigure(figpath, figfile) | |
632 | # |
|
632 | # | |
633 | # if ftp: |
|
633 | # if ftp: | |
634 | # #provisionalmente envia archivos en el formato de la web en tiempo real |
|
634 | # #provisionalmente envia archivos en el formato de la web en tiempo real | |
635 | # name = self.getNameToFtp(thisDatetime, self.FTP_WEI, self.EXP_CODE, self.SUB_EXP_CODE, self.PLOT_CODE, self.PLOT_POS) |
|
635 | # name = self.getNameToFtp(thisDatetime, self.FTP_WEI, self.EXP_CODE, self.SUB_EXP_CODE, self.PLOT_CODE, self.PLOT_POS) | |
636 | # path = '%s%03d' %(self.PREFIX, self.id) |
|
636 | # path = '%s%03d' %(self.PREFIX, self.id) | |
637 | # ftp_file = os.path.join(path,'ftp','%s.png'%name) |
|
637 | # ftp_file = os.path.join(path,'ftp','%s.png'%name) | |
638 | # self.saveFigure(figpath, ftp_file) |
|
638 | # self.saveFigure(figpath, ftp_file) | |
639 | # ftp_filename = os.path.join(figpath,ftp_file) |
|
639 | # ftp_filename = os.path.join(figpath,ftp_file) | |
640 | # self.sendByFTP_Thread(ftp_filename, server, folder, username, password) |
|
640 | # self.sendByFTP_Thread(ftp_filename, server, folder, username, password) | |
641 | # self.counter_imagwr = 0 |
|
641 | # self.counter_imagwr = 0 | |
642 | # |
|
642 | # | |
643 | # self.counter_imagwr = 0 |
|
643 | # self.counter_imagwr = 0 | |
644 |
|
644 | |||
645 | #if ((dataOut.utctime-time.timezone) >= self.axesList[0].xmax): |
|
645 | #if ((dataOut.utctime-time.timezone) >= self.axesList[0].xmax): | |
646 | if x[1] >= self.axesList[0].xmax: |
|
646 | if x[1] >= self.axesList[0].xmax: | |
647 | self.saveFigure(figpath, figfile) |
|
647 | #self.saveFigure(figpath, figfile) | |
648 | self.__isConfig = False |
|
648 | self.__isConfig = False | |
649 |
|
649 | |||
650 | # if x[1] + (x[1]-x[0]) >= self.axesList[0].xmax: |
|
650 | # if x[1] + (x[1]-x[0]) >= self.axesList[0].xmax: | |
651 | # |
|
651 | # | |
652 | # self.__isConfig = False |
|
652 | # self.__isConfig = False | |
653 |
|
653 | |||
654 | # if lastone: |
|
654 | # if lastone: | |
655 | # if figfile == None: |
|
655 | # if figfile == None: | |
656 | # figfile = self.getFilename(name = self.name) |
|
656 | # figfile = self.getFilename(name = self.name) | |
657 | # self.saveFigure(figpath, figfile) |
|
657 | # self.saveFigure(figpath, figfile) | |
658 | # |
|
658 | # | |
659 | # if ftp: |
|
659 | # if ftp: | |
660 | # #provisionalmente envia archivos en el formato de la web en tiempo real |
|
660 | # #provisionalmente envia archivos en el formato de la web en tiempo real | |
661 | # name = self.getNameToFtp(thisDatetime, self.FTP_WEI, self.EXP_CODE, self.SUB_EXP_CODE, self.PLOT_CODE, self.PLOT_POS) |
|
661 | # name = self.getNameToFtp(thisDatetime, self.FTP_WEI, self.EXP_CODE, self.SUB_EXP_CODE, self.PLOT_CODE, self.PLOT_POS) | |
662 | # path = '%s%03d' %(self.PREFIX, self.id) |
|
662 | # path = '%s%03d' %(self.PREFIX, self.id) | |
663 | # ftp_file = os.path.join(path,'ftp','%s.png'%name) |
|
663 | # ftp_file = os.path.join(path,'ftp','%s.png'%name) | |
664 | # self.saveFigure(figpath, ftp_file) |
|
664 | # self.saveFigure(figpath, ftp_file) | |
665 | # ftp_filename = os.path.join(figpath,ftp_file) |
|
665 | # ftp_filename = os.path.join(figpath,ftp_file) | |
666 | # self.sendByFTP_Thread(ftp_filename, server, folder, username, password) |
|
666 | # self.sendByFTP_Thread(ftp_filename, server, folder, username, password) | |
667 |
|
667 | |||
668 |
|
668 | |||
669 | class SpectraPlot(Figure): |
|
669 | class SpectraPlot(Figure): | |
670 |
|
670 | |||
671 | __isConfig = None |
|
671 | __isConfig = None | |
672 | __nsubplots = None |
|
672 | __nsubplots = None | |
673 |
|
673 | |||
674 | WIDTHPROF = None |
|
674 | WIDTHPROF = None | |
675 | HEIGHTPROF = None |
|
675 | HEIGHTPROF = None | |
676 | PREFIX = 'spc' |
|
676 | PREFIX = 'spc' | |
677 |
|
677 | |||
678 | def __init__(self): |
|
678 | def __init__(self): | |
679 |
|
679 | |||
680 | self.__isConfig = False |
|
680 | self.__isConfig = False | |
681 | self.__nsubplots = 1 |
|
681 | self.__nsubplots = 1 | |
682 |
|
682 | |||
683 | self.WIDTH = 280 |
|
683 | self.WIDTH = 280 | |
684 | self.HEIGHT = 250 |
|
684 | self.HEIGHT = 250 | |
685 | self.WIDTHPROF = 120 |
|
685 | self.WIDTHPROF = 120 | |
686 | self.HEIGHTPROF = 0 |
|
686 | self.HEIGHTPROF = 0 | |
687 | self.counter_imagwr = 0 |
|
687 | self.counter_imagwr = 0 | |
688 |
|
688 | |||
689 | self.PLOT_CODE = 1 |
|
689 | self.PLOT_CODE = 1 | |
690 | self.FTP_WEI = None |
|
690 | self.FTP_WEI = None | |
691 | self.EXP_CODE = None |
|
691 | self.EXP_CODE = None | |
692 | self.SUB_EXP_CODE = None |
|
692 | self.SUB_EXP_CODE = None | |
693 | self.PLOT_POS = None |
|
693 | self.PLOT_POS = None | |
694 |
|
694 | |||
695 | def getSubplots(self): |
|
695 | def getSubplots(self): | |
696 |
|
696 | |||
697 | ncol = int(numpy.sqrt(self.nplots)+0.9) |
|
697 | ncol = int(numpy.sqrt(self.nplots)+0.9) | |
698 | nrow = int(self.nplots*1./ncol + 0.9) |
|
698 | nrow = int(self.nplots*1./ncol + 0.9) | |
699 |
|
699 | |||
700 | return nrow, ncol |
|
700 | return nrow, ncol | |
701 |
|
701 | |||
702 | def setup(self, id, nplots, wintitle, showprofile=True, show=True): |
|
702 | def setup(self, id, nplots, wintitle, showprofile=True, show=True): | |
703 |
|
703 | |||
704 | self.__showprofile = showprofile |
|
704 | self.__showprofile = showprofile | |
705 | self.nplots = nplots |
|
705 | self.nplots = nplots | |
706 |
|
706 | |||
707 | ncolspan = 1 |
|
707 | ncolspan = 1 | |
708 | colspan = 1 |
|
708 | colspan = 1 | |
709 | if showprofile: |
|
709 | if showprofile: | |
710 | ncolspan = 3 |
|
710 | ncolspan = 3 | |
711 | colspan = 2 |
|
711 | colspan = 2 | |
712 | self.__nsubplots = 2 |
|
712 | self.__nsubplots = 2 | |
713 |
|
713 | |||
714 | self.createFigure(id = id, |
|
714 | self.createFigure(id = id, | |
715 | wintitle = wintitle, |
|
715 | wintitle = wintitle, | |
716 | widthplot = self.WIDTH + self.WIDTHPROF, |
|
716 | widthplot = self.WIDTH + self.WIDTHPROF, | |
717 | heightplot = self.HEIGHT + self.HEIGHTPROF, |
|
717 | heightplot = self.HEIGHT + self.HEIGHTPROF, | |
718 | show=show) |
|
718 | show=show) | |
719 |
|
719 | |||
720 | nrow, ncol = self.getSubplots() |
|
720 | nrow, ncol = self.getSubplots() | |
721 |
|
721 | |||
722 | counter = 0 |
|
722 | counter = 0 | |
723 | for y in range(nrow): |
|
723 | for y in range(nrow): | |
724 | for x in range(ncol): |
|
724 | for x in range(ncol): | |
725 |
|
725 | |||
726 | if counter >= self.nplots: |
|
726 | if counter >= self.nplots: | |
727 | break |
|
727 | break | |
728 |
|
728 | |||
729 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1) |
|
729 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1) | |
730 |
|
730 | |||
731 | if showprofile: |
|
731 | if showprofile: | |
732 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1) |
|
732 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1) | |
733 |
|
733 | |||
734 | counter += 1 |
|
734 | counter += 1 | |
735 |
|
735 | |||
736 | def run(self, dataOut, id, wintitle="", channelList=None, showprofile=True, |
|
736 | def run(self, dataOut, id, wintitle="", channelList=None, showprofile=True, | |
737 | xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None, |
|
737 | xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None, | |
738 | save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1, |
|
738 | save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1, | |
739 | server=None, folder=None, username=None, password=None, |
|
739 | server=None, folder=None, username=None, password=None, | |
740 | ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0, realtime=False): |
|
740 | ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0, realtime=False): | |
741 |
|
741 | |||
742 | """ |
|
742 | """ | |
743 |
|
743 | |||
744 | Input: |
|
744 | Input: | |
745 | dataOut : |
|
745 | dataOut : | |
746 | id : |
|
746 | id : | |
747 | wintitle : |
|
747 | wintitle : | |
748 | channelList : |
|
748 | channelList : | |
749 | showProfile : |
|
749 | showProfile : | |
750 | xmin : None, |
|
750 | xmin : None, | |
751 | xmax : None, |
|
751 | xmax : None, | |
752 | ymin : None, |
|
752 | ymin : None, | |
753 | ymax : None, |
|
753 | ymax : None, | |
754 | zmin : None, |
|
754 | zmin : None, | |
755 | zmax : None |
|
755 | zmax : None | |
756 | """ |
|
756 | """ | |
757 |
|
757 | |||
|
758 | if dataOut.flagNoData: | |||
|
759 | return None | |||
|
760 | ||||
758 | if realtime: |
|
761 | if realtime: | |
759 | if not(isRealtime(utcdatatime = dataOut.utctime)): |
|
762 | if not(isRealtime(utcdatatime = dataOut.utctime)): | |
760 | print 'Skipping this plot function' |
|
763 | print 'Skipping this plot function' | |
761 | return |
|
764 | return | |
762 |
|
765 | |||
763 | if channelList == None: |
|
766 | if channelList == None: | |
764 | channelIndexList = dataOut.channelIndexList |
|
767 | channelIndexList = dataOut.channelIndexList | |
765 | else: |
|
768 | else: | |
766 | channelIndexList = [] |
|
769 | channelIndexList = [] | |
767 | for channel in channelList: |
|
770 | for channel in channelList: | |
768 | if channel not in dataOut.channelList: |
|
771 | if channel not in dataOut.channelList: | |
769 | raise ValueError, "Channel %d is not in dataOut.channelList" |
|
772 | raise ValueError, "Channel %d is not in dataOut.channelList" | |
770 | channelIndexList.append(dataOut.channelList.index(channel)) |
|
773 | channelIndexList.append(dataOut.channelList.index(channel)) | |
771 | factor = dataOut.normFactor |
|
774 | factor = dataOut.normFactor | |
772 | x = dataOut.getVelRange(1) |
|
775 | x = dataOut.getVelRange(1) | |
773 | y = dataOut.getHeiRange() |
|
776 | y = dataOut.getHeiRange() | |
774 |
|
777 | |||
775 | z = dataOut.data_spc[channelIndexList,:,:]/factor |
|
778 | z = dataOut.data_spc[channelIndexList,:,:]/factor | |
776 | z = numpy.where(numpy.isfinite(z), z, numpy.NAN) |
|
779 | z = numpy.where(numpy.isfinite(z), z, numpy.NAN) | |
777 | avg = numpy.average(z, axis=1) |
|
780 | avg = numpy.average(z, axis=1) | |
778 | noise = dataOut.getNoise()/factor |
|
781 | noise = dataOut.getNoise()/factor | |
779 |
|
782 | |||
780 | zdB = 10*numpy.log10(z) |
|
783 | zdB = 10*numpy.log10(z) | |
781 | avgdB = 10*numpy.log10(avg) |
|
784 | avgdB = 10*numpy.log10(avg) | |
782 | noisedB = 10*numpy.log10(noise) |
|
785 | noisedB = 10*numpy.log10(noise) | |
783 |
|
786 | |||
784 | #thisDatetime = dataOut.datatime |
|
787 | #thisDatetime = dataOut.datatime | |
785 | thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[1]) |
|
788 | thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[1]) | |
786 | title = wintitle + " Spectra" |
|
789 | title = wintitle + " Spectra" | |
787 | xlabel = "Velocity (m/s)" |
|
790 | xlabel = "Velocity (m/s)" | |
788 | ylabel = "Range (Km)" |
|
791 | ylabel = "Range (Km)" | |
789 |
|
792 | |||
790 | if not self.__isConfig: |
|
793 | if not self.__isConfig: | |
791 |
|
794 | |||
792 | nplots = len(channelIndexList) |
|
795 | nplots = len(channelIndexList) | |
793 |
|
796 | |||
794 | self.setup(id=id, |
|
797 | self.setup(id=id, | |
795 | nplots=nplots, |
|
798 | nplots=nplots, | |
796 | wintitle=wintitle, |
|
799 | wintitle=wintitle, | |
797 | showprofile=showprofile, |
|
800 | showprofile=showprofile, | |
798 | show=show) |
|
801 | show=show) | |
799 |
|
802 | |||
800 | if xmin == None: xmin = numpy.nanmin(x) |
|
803 | if xmin == None: xmin = numpy.nanmin(x) | |
801 | if xmax == None: xmax = numpy.nanmax(x) |
|
804 | if xmax == None: xmax = numpy.nanmax(x) | |
802 | if ymin == None: ymin = numpy.nanmin(y) |
|
805 | if ymin == None: ymin = numpy.nanmin(y) | |
803 | if ymax == None: ymax = numpy.nanmax(y) |
|
806 | if ymax == None: ymax = numpy.nanmax(y) | |
804 | if zmin == None: zmin = numpy.nanmin(avgdB)*0.9 |
|
807 | if zmin == None: zmin = numpy.nanmin(avgdB)*0.9 | |
805 | if zmax == None: zmax = numpy.nanmax(avgdB)*0.9 |
|
808 | if zmax == None: zmax = numpy.nanmax(avgdB)*0.9 | |
806 |
|
809 | |||
807 | self.FTP_WEI = ftp_wei |
|
810 | self.FTP_WEI = ftp_wei | |
808 | self.EXP_CODE = exp_code |
|
811 | self.EXP_CODE = exp_code | |
809 | self.SUB_EXP_CODE = sub_exp_code |
|
812 | self.SUB_EXP_CODE = sub_exp_code | |
810 | self.PLOT_POS = plot_pos |
|
813 | self.PLOT_POS = plot_pos | |
811 |
|
814 | |||
812 | self.__isConfig = True |
|
815 | self.__isConfig = True | |
813 |
|
816 | |||
814 | self.setWinTitle(title) |
|
817 | self.setWinTitle(title) | |
815 |
|
818 | |||
816 | for i in range(self.nplots): |
|
819 | for i in range(self.nplots): | |
817 | str_datetime = '%s %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S")) |
|
820 | str_datetime = '%s %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S")) | |
818 | title = "Channel %d: %4.2fdB: %s" %(dataOut.channelList[i]+1, noisedB[i], str_datetime) |
|
821 | title = "Channel %d: %4.2fdB: %s" %(dataOut.channelList[i]+1, noisedB[i], str_datetime) | |
819 | axes = self.axesList[i*self.__nsubplots] |
|
822 | axes = self.axesList[i*self.__nsubplots] | |
820 | axes.pcolor(x, y, zdB[i,:,:], |
|
823 | axes.pcolor(x, y, zdB[i,:,:], | |
821 | xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax, |
|
824 | xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax, | |
822 | xlabel=xlabel, ylabel=ylabel, title=title, |
|
825 | xlabel=xlabel, ylabel=ylabel, title=title, | |
823 | ticksize=9, cblabel='') |
|
826 | ticksize=9, cblabel='') | |
824 |
|
827 | |||
825 | if self.__showprofile: |
|
828 | if self.__showprofile: | |
826 | axes = self.axesList[i*self.__nsubplots +1] |
|
829 | axes = self.axesList[i*self.__nsubplots +1] | |
827 | axes.pline(avgdB[i], y, |
|
830 | axes.pline(avgdB[i], y, | |
828 | xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax, |
|
831 | xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax, | |
829 | xlabel='dB', ylabel='', title='', |
|
832 | xlabel='dB', ylabel='', title='', | |
830 | ytick_visible=False, |
|
833 | ytick_visible=False, | |
831 | grid='x') |
|
834 | grid='x') | |
832 |
|
835 | |||
833 | noiseline = numpy.repeat(noisedB[i], len(y)) |
|
836 | noiseline = numpy.repeat(noisedB[i], len(y)) | |
834 | axes.addpline(noiseline, y, idline=1, color="black", linestyle="dashed", lw=2) |
|
837 | axes.addpline(noiseline, y, idline=1, color="black", linestyle="dashed", lw=2) | |
835 |
|
838 | |||
836 | self.draw() |
|
839 | self.draw() | |
837 |
|
840 | |||
838 | if save: |
|
841 | if save: | |
839 |
|
842 | |||
840 | self.counter_imagwr += 1 |
|
843 | self.counter_imagwr += 1 | |
841 | if (self.counter_imagwr==wr_period): |
|
844 | if (self.counter_imagwr==wr_period): | |
842 | if figfile == None: |
|
845 | if figfile == None: | |
843 | str_datetime = thisDatetime.strftime("%Y%m%d_%H%M%S") |
|
846 | str_datetime = thisDatetime.strftime("%Y%m%d_%H%M%S") | |
844 | figfile = self.getFilename(name = str_datetime) |
|
847 | figfile = self.getFilename(name = str_datetime) | |
845 |
|
848 | |||
846 | self.saveFigure(figpath, figfile) |
|
849 | self.saveFigure(figpath, figfile) | |
847 |
|
850 | |||
848 | if ftp: |
|
851 | if ftp: | |
849 | #provisionalmente envia archivos en el formato de la web en tiempo real |
|
852 | #provisionalmente envia archivos en el formato de la web en tiempo real | |
850 | name = self.getNameToFtp(thisDatetime, self.FTP_WEI, self.EXP_CODE, self.SUB_EXP_CODE, self.PLOT_CODE, self.PLOT_POS) |
|
853 | name = self.getNameToFtp(thisDatetime, self.FTP_WEI, self.EXP_CODE, self.SUB_EXP_CODE, self.PLOT_CODE, self.PLOT_POS) | |
851 | path = '%s%03d' %(self.PREFIX, self.id) |
|
854 | path = '%s%03d' %(self.PREFIX, self.id) | |
852 | ftp_file = os.path.join(path,'ftp','%s.png'%name) |
|
855 | ftp_file = os.path.join(path,'ftp','%s.png'%name) | |
853 | self.saveFigure(figpath, ftp_file) |
|
856 | self.saveFigure(figpath, ftp_file) | |
854 | ftp_filename = os.path.join(figpath,ftp_file) |
|
857 | ftp_filename = os.path.join(figpath,ftp_file) | |
855 | self.sendByFTP_Thread(ftp_filename, server, folder, username, password) |
|
858 | self.sendByFTP_Thread(ftp_filename, server, folder, username, password) | |
856 | self.counter_imagwr = 0 |
|
859 | self.counter_imagwr = 0 | |
857 |
|
860 | |||
858 |
|
861 | |||
859 | self.counter_imagwr = 0 |
|
862 | self.counter_imagwr = 0 | |
860 |
|
863 | |||
861 |
|
864 | |||
862 | class Scope(Figure): |
|
865 | class Scope(Figure): | |
863 |
|
866 | |||
864 | __isConfig = None |
|
867 | __isConfig = None | |
865 |
|
868 | |||
866 | def __init__(self): |
|
869 | def __init__(self): | |
867 |
|
870 | |||
868 | self.__isConfig = False |
|
871 | self.__isConfig = False | |
869 | self.WIDTH = 300 |
|
872 | self.WIDTH = 300 | |
870 | self.HEIGHT = 200 |
|
873 | self.HEIGHT = 200 | |
871 | self.counter_imagwr = 0 |
|
874 | self.counter_imagwr = 0 | |
872 |
|
875 | |||
873 | def getSubplots(self): |
|
876 | def getSubplots(self): | |
874 |
|
877 | |||
875 | nrow = self.nplots |
|
878 | nrow = self.nplots | |
876 | ncol = 3 |
|
879 | ncol = 3 | |
877 | return nrow, ncol |
|
880 | return nrow, ncol | |
878 |
|
881 | |||
879 | def setup(self, id, nplots, wintitle, show): |
|
882 | def setup(self, id, nplots, wintitle, show): | |
880 |
|
883 | |||
881 | self.nplots = nplots |
|
884 | self.nplots = nplots | |
882 |
|
885 | |||
883 | self.createFigure(id=id, |
|
886 | self.createFigure(id=id, | |
884 | wintitle=wintitle, |
|
887 | wintitle=wintitle, | |
885 | show=show) |
|
888 | show=show) | |
886 |
|
889 | |||
887 | nrow,ncol = self.getSubplots() |
|
890 | nrow,ncol = self.getSubplots() | |
888 | colspan = 3 |
|
891 | colspan = 3 | |
889 | rowspan = 1 |
|
892 | rowspan = 1 | |
890 |
|
893 | |||
891 | for i in range(nplots): |
|
894 | for i in range(nplots): | |
892 | self.addAxes(nrow, ncol, i, 0, colspan, rowspan) |
|
895 | self.addAxes(nrow, ncol, i, 0, colspan, rowspan) | |
893 |
|
896 | |||
894 | def plot_iq(self, x, y, id, channelIndexList, thisDatetime, wintitle, show, xmin, xmax, ymin, ymax): |
|
897 | def plot_iq(self, x, y, id, channelIndexList, thisDatetime, wintitle, show, xmin, xmax, ymin, ymax): | |
895 | yreal = y[channelIndexList,:].real |
|
898 | yreal = y[channelIndexList,:].real | |
896 | yimag = y[channelIndexList,:].imag |
|
899 | yimag = y[channelIndexList,:].imag | |
897 |
|
900 | |||
898 | title = wintitle + " Scope: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) |
|
901 | title = wintitle + " Scope: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) | |
899 | xlabel = "Range (Km)" |
|
902 | xlabel = "Range (Km)" | |
900 | ylabel = "Intensity - IQ" |
|
903 | ylabel = "Intensity - IQ" | |
901 |
|
904 | |||
902 | if not self.__isConfig: |
|
905 | if not self.__isConfig: | |
903 | nplots = len(channelIndexList) |
|
906 | nplots = len(channelIndexList) | |
904 |
|
907 | |||
905 | self.setup(id=id, |
|
908 | self.setup(id=id, | |
906 | nplots=nplots, |
|
909 | nplots=nplots, | |
907 | wintitle='', |
|
910 | wintitle='', | |
908 | show=show) |
|
911 | show=show) | |
909 |
|
912 | |||
910 | if xmin == None: xmin = numpy.nanmin(x) |
|
913 | if xmin == None: xmin = numpy.nanmin(x) | |
911 | if xmax == None: xmax = numpy.nanmax(x) |
|
914 | if xmax == None: xmax = numpy.nanmax(x) | |
912 | if ymin == None: ymin = min(numpy.nanmin(yreal),numpy.nanmin(yimag)) |
|
915 | if ymin == None: ymin = min(numpy.nanmin(yreal),numpy.nanmin(yimag)) | |
913 | if ymax == None: ymax = max(numpy.nanmax(yreal),numpy.nanmax(yimag)) |
|
916 | if ymax == None: ymax = max(numpy.nanmax(yreal),numpy.nanmax(yimag)) | |
914 |
|
917 | |||
915 | self.__isConfig = True |
|
918 | self.__isConfig = True | |
916 |
|
919 | |||
917 | self.setWinTitle(title) |
|
920 | self.setWinTitle(title) | |
918 |
|
921 | |||
919 | for i in range(len(self.axesList)): |
|
922 | for i in range(len(self.axesList)): | |
920 | title = "Channel %d" %(i) |
|
923 | title = "Channel %d" %(i) | |
921 | axes = self.axesList[i] |
|
924 | axes = self.axesList[i] | |
922 |
|
925 | |||
923 | axes.pline(x, yreal[i,:], |
|
926 | axes.pline(x, yreal[i,:], | |
924 | xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, |
|
927 | xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, | |
925 | xlabel=xlabel, ylabel=ylabel, title=title) |
|
928 | xlabel=xlabel, ylabel=ylabel, title=title) | |
926 |
|
929 | |||
927 | axes.addpline(x, yimag[i,:], idline=1, color="red", linestyle="solid", lw=2) |
|
930 | axes.addpline(x, yimag[i,:], idline=1, color="red", linestyle="solid", lw=2) | |
928 |
|
931 | |||
929 | def plot_power(self, x, y, id, channelIndexList, thisDatetime, wintitle, show, xmin, xmax, ymin, ymax): |
|
932 | def plot_power(self, x, y, id, channelIndexList, thisDatetime, wintitle, show, xmin, xmax, ymin, ymax): | |
930 | y = y[channelIndexList,:] * numpy.conjugate(y[channelIndexList,:]) |
|
933 | y = y[channelIndexList,:] * numpy.conjugate(y[channelIndexList,:]) | |
931 | yreal = y.real |
|
934 | yreal = y.real | |
932 |
|
935 | |||
933 | title = wintitle + " Scope: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) |
|
936 | title = wintitle + " Scope: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) | |
934 | xlabel = "Range (Km)" |
|
937 | xlabel = "Range (Km)" | |
935 | ylabel = "Intensity" |
|
938 | ylabel = "Intensity" | |
936 |
|
939 | |||
937 | if not self.__isConfig: |
|
940 | if not self.__isConfig: | |
938 | nplots = len(channelIndexList) |
|
941 | nplots = len(channelIndexList) | |
939 |
|
942 | |||
940 | self.setup(id=id, |
|
943 | self.setup(id=id, | |
941 | nplots=nplots, |
|
944 | nplots=nplots, | |
942 | wintitle='', |
|
945 | wintitle='', | |
943 | show=show) |
|
946 | show=show) | |
944 |
|
947 | |||
945 | if xmin == None: xmin = numpy.nanmin(x) |
|
948 | if xmin == None: xmin = numpy.nanmin(x) | |
946 | if xmax == None: xmax = numpy.nanmax(x) |
|
949 | if xmax == None: xmax = numpy.nanmax(x) | |
947 | if ymin == None: ymin = numpy.nanmin(yreal) |
|
950 | if ymin == None: ymin = numpy.nanmin(yreal) | |
948 | if ymax == None: ymax = numpy.nanmax(yreal) |
|
951 | if ymax == None: ymax = numpy.nanmax(yreal) | |
949 |
|
952 | |||
950 | self.__isConfig = True |
|
953 | self.__isConfig = True | |
951 |
|
954 | |||
952 | self.setWinTitle(title) |
|
955 | self.setWinTitle(title) | |
953 |
|
956 | |||
954 | for i in range(len(self.axesList)): |
|
957 | for i in range(len(self.axesList)): | |
955 | title = "Channel %d" %(i) |
|
958 | title = "Channel %d" %(i) | |
956 | axes = self.axesList[i] |
|
959 | axes = self.axesList[i] | |
957 | ychannel = yreal[i,:] |
|
960 | ychannel = yreal[i,:] | |
958 | axes.pline(x, ychannel, |
|
961 | axes.pline(x, ychannel, | |
959 | xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, |
|
962 | xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, | |
960 | xlabel=xlabel, ylabel=ylabel, title=title) |
|
963 | xlabel=xlabel, ylabel=ylabel, title=title) | |
961 |
|
964 | |||
962 |
|
965 | |||
963 | def run(self, dataOut, id, wintitle="", channelList=None, |
|
966 | def run(self, dataOut, id, wintitle="", channelList=None, | |
964 | xmin=None, xmax=None, ymin=None, ymax=None, save=False, |
|
967 | xmin=None, xmax=None, ymin=None, ymax=None, save=False, | |
965 | figpath='./', figfile=None, show=True, wr_period=1, |
|
968 | figpath='./', figfile=None, show=True, wr_period=1, | |
966 | server=None, folder=None, username=None, password=None, type='power'): |
|
969 | server=None, folder=None, username=None, password=None, type='power'): | |
967 |
|
970 | |||
968 | """ |
|
971 | """ | |
969 |
|
972 | |||
970 | Input: |
|
973 | Input: | |
971 | dataOut : |
|
974 | dataOut : | |
972 | id : |
|
975 | id : | |
973 | wintitle : |
|
976 | wintitle : | |
974 | channelList : |
|
977 | channelList : | |
975 | xmin : None, |
|
978 | xmin : None, | |
976 | xmax : None, |
|
979 | xmax : None, | |
977 | ymin : None, |
|
980 | ymin : None, | |
978 | ymax : None, |
|
981 | ymax : None, | |
979 | """ |
|
982 | """ | |
|
983 | if dataOut.flagNoData: | |||
|
984 | return None | |||
980 |
|
985 | |||
981 | if channelList == None: |
|
986 | if channelList == None: | |
982 | channelIndexList = dataOut.channelIndexList |
|
987 | channelIndexList = dataOut.channelIndexList | |
983 | else: |
|
988 | else: | |
984 | channelIndexList = [] |
|
989 | channelIndexList = [] | |
985 | for channel in channelList: |
|
990 | for channel in channelList: | |
986 | if channel not in dataOut.channelList: |
|
991 | if channel not in dataOut.channelList: | |
987 | raise ValueError, "Channel %d is not in dataOut.channelList" |
|
992 | raise ValueError, "Channel %d is not in dataOut.channelList" | |
988 | channelIndexList.append(dataOut.channelList.index(channel)) |
|
993 | channelIndexList.append(dataOut.channelList.index(channel)) | |
989 |
|
994 | |||
990 | x = dataOut.heightList |
|
995 | x = dataOut.heightList | |
991 | y = dataOut.data[channelIndexList,:] * numpy.conjugate(dataOut.data[channelIndexList,:]) |
|
996 | y = dataOut.data[channelIndexList,:] * numpy.conjugate(dataOut.data[channelIndexList,:]) | |
992 | y = y.real |
|
997 | y = y.real | |
993 |
|
998 | |||
994 | thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[1]) |
|
999 | thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[1]) | |
995 |
|
1000 | |||
996 | if type == "power": |
|
1001 | if type == "power": | |
997 | self.plot_power(dataOut.heightList, |
|
1002 | self.plot_power(dataOut.heightList, | |
998 | dataOut.data, |
|
1003 | dataOut.data, | |
999 | id, |
|
1004 | id, | |
1000 | channelIndexList, |
|
1005 | channelIndexList, | |
1001 | thisDatetime, |
|
1006 | thisDatetime, | |
1002 | wintitle, |
|
1007 | wintitle, | |
1003 | show, |
|
1008 | show, | |
1004 | xmin, |
|
1009 | xmin, | |
1005 | xmax, |
|
1010 | xmax, | |
1006 | ymin, |
|
1011 | ymin, | |
1007 | ymax) |
|
1012 | ymax) | |
1008 |
|
1013 | |||
1009 | if type == "iq": |
|
1014 | if type == "iq": | |
1010 | self.plot_iq(dataOut.heightList, |
|
1015 | self.plot_iq(dataOut.heightList, | |
1011 | dataOut.data, |
|
1016 | dataOut.data, | |
1012 | id, |
|
1017 | id, | |
1013 | channelIndexList, |
|
1018 | channelIndexList, | |
1014 | thisDatetime, |
|
1019 | thisDatetime, | |
1015 | wintitle, |
|
1020 | wintitle, | |
1016 | show, |
|
1021 | show, | |
1017 | xmin, |
|
1022 | xmin, | |
1018 | xmax, |
|
1023 | xmax, | |
1019 | ymin, |
|
1024 | ymin, | |
1020 | ymax) |
|
1025 | ymax) | |
1021 |
|
1026 | |||
1022 |
|
1027 | |||
1023 | self.draw() |
|
1028 | self.draw() | |
1024 |
|
1029 | |||
1025 | if save: |
|
1030 | if save: | |
1026 | date = thisDatetime.strftime("%Y%m%d_%H%M%S") |
|
1031 | date = thisDatetime.strftime("%Y%m%d_%H%M%S") | |
1027 | if figfile == None: |
|
1032 | if figfile == None: | |
1028 | figfile = self.getFilename(name = date) |
|
1033 | figfile = self.getFilename(name = date) | |
1029 |
|
1034 | |||
1030 | self.saveFigure(figpath, figfile) |
|
1035 | self.saveFigure(figpath, figfile) | |
1031 |
|
1036 | |||
1032 | self.counter_imagwr += 1 |
|
1037 | self.counter_imagwr += 1 | |
1033 | if (ftp and (self.counter_imagwr==wr_period)): |
|
1038 | if (ftp and (self.counter_imagwr==wr_period)): | |
1034 | ftp_filename = os.path.join(figpath,figfile) |
|
1039 | ftp_filename = os.path.join(figpath,figfile) | |
1035 | self.sendByFTP_Thread(ftp_filename, server, folder, username, password) |
|
1040 | self.sendByFTP_Thread(ftp_filename, server, folder, username, password) | |
1036 | self.counter_imagwr = 0 |
|
1041 | self.counter_imagwr = 0 | |
1037 |
|
1042 | |||
1038 | class PowerProfile(Figure): |
|
1043 | class PowerProfile(Figure): | |
1039 | __isConfig = None |
|
1044 | __isConfig = None | |
1040 | __nsubplots = None |
|
1045 | __nsubplots = None | |
1041 |
|
1046 | |||
1042 | WIDTHPROF = None |
|
1047 | WIDTHPROF = None | |
1043 | HEIGHTPROF = None |
|
1048 | HEIGHTPROF = None | |
1044 | PREFIX = 'spcprofile' |
|
1049 | PREFIX = 'spcprofile' | |
1045 |
|
1050 | |||
1046 | def __init__(self): |
|
1051 | def __init__(self): | |
1047 | self.__isConfig = False |
|
1052 | self.__isConfig = False | |
1048 | self.__nsubplots = 1 |
|
1053 | self.__nsubplots = 1 | |
1049 |
|
1054 | |||
1050 | self.WIDTH = 300 |
|
1055 | self.WIDTH = 300 | |
1051 | self.HEIGHT = 500 |
|
1056 | self.HEIGHT = 500 | |
1052 | self.counter_imagwr = 0 |
|
1057 | self.counter_imagwr = 0 | |
1053 |
|
1058 | |||
1054 | def getSubplots(self): |
|
1059 | def getSubplots(self): | |
1055 | ncol = 1 |
|
1060 | ncol = 1 | |
1056 | nrow = 1 |
|
1061 | nrow = 1 | |
1057 |
|
1062 | |||
1058 | return nrow, ncol |
|
1063 | return nrow, ncol | |
1059 |
|
1064 | |||
1060 | def setup(self, id, nplots, wintitle, show): |
|
1065 | def setup(self, id, nplots, wintitle, show): | |
1061 |
|
1066 | |||
1062 | self.nplots = nplots |
|
1067 | self.nplots = nplots | |
1063 |
|
1068 | |||
1064 | ncolspan = 1 |
|
1069 | ncolspan = 1 | |
1065 | colspan = 1 |
|
1070 | colspan = 1 | |
1066 |
|
1071 | |||
1067 | self.createFigure(id = id, |
|
1072 | self.createFigure(id = id, | |
1068 | wintitle = wintitle, |
|
1073 | wintitle = wintitle, | |
1069 | widthplot = self.WIDTH, |
|
1074 | widthplot = self.WIDTH, | |
1070 | heightplot = self.HEIGHT, |
|
1075 | heightplot = self.HEIGHT, | |
1071 | show=show) |
|
1076 | show=show) | |
1072 |
|
1077 | |||
1073 | nrow, ncol = self.getSubplots() |
|
1078 | nrow, ncol = self.getSubplots() | |
1074 |
|
1079 | |||
1075 | counter = 0 |
|
1080 | counter = 0 | |
1076 | for y in range(nrow): |
|
1081 | for y in range(nrow): | |
1077 | for x in range(ncol): |
|
1082 | for x in range(ncol): | |
1078 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1) |
|
1083 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1) | |
1079 |
|
1084 | |||
1080 | def run(self, dataOut, id, wintitle="", channelList=None, |
|
1085 | def run(self, dataOut, id, wintitle="", channelList=None, | |
1081 | xmin=None, xmax=None, ymin=None, ymax=None, |
|
1086 | xmin=None, xmax=None, ymin=None, ymax=None, | |
1082 | save=False, figpath='./', figfile=None, show=True, wr_period=1, |
|
1087 | save=False, figpath='./', figfile=None, show=True, wr_period=1, | |
1083 | server=None, folder=None, username=None, password=None,): |
|
1088 | server=None, folder=None, username=None, password=None,): | |
1084 |
|
1089 | |||
|
1090 | if dataOut.flagNoData: | |||
|
1091 | return None | |||
|
1092 | ||||
1085 | if channelList == None: |
|
1093 | if channelList == None: | |
1086 | channelIndexList = dataOut.channelIndexList |
|
1094 | channelIndexList = dataOut.channelIndexList | |
1087 | channelList = dataOut.channelList |
|
1095 | channelList = dataOut.channelList | |
1088 | else: |
|
1096 | else: | |
1089 | channelIndexList = [] |
|
1097 | channelIndexList = [] | |
1090 | for channel in channelList: |
|
1098 | for channel in channelList: | |
1091 | if channel not in dataOut.channelList: |
|
1099 | if channel not in dataOut.channelList: | |
1092 | raise ValueError, "Channel %d is not in dataOut.channelList" |
|
1100 | raise ValueError, "Channel %d is not in dataOut.channelList" | |
1093 | channelIndexList.append(dataOut.channelList.index(channel)) |
|
1101 | channelIndexList.append(dataOut.channelList.index(channel)) | |
1094 |
|
1102 | |||
1095 | try: |
|
1103 | try: | |
1096 | factor = dataOut.normFactor |
|
1104 | factor = dataOut.normFactor | |
1097 | except: |
|
1105 | except: | |
1098 | factor = 1 |
|
1106 | factor = 1 | |
1099 |
|
1107 | |||
1100 | y = dataOut.getHeiRange() |
|
1108 | y = dataOut.getHeiRange() | |
1101 |
|
1109 | |||
1102 | #for voltage |
|
1110 | #for voltage | |
1103 | if dataOut.type == 'Voltage': |
|
1111 | if dataOut.type == 'Voltage': | |
1104 | x = dataOut.data[channelIndexList,:] * numpy.conjugate(dataOut.data[channelIndexList,:]) |
|
1112 | x = dataOut.data[channelIndexList,:] * numpy.conjugate(dataOut.data[channelIndexList,:]) | |
1105 | x = x.real |
|
1113 | x = x.real | |
1106 | x = numpy.where(numpy.isfinite(x), x, numpy.NAN) |
|
1114 | x = numpy.where(numpy.isfinite(x), x, numpy.NAN) | |
1107 |
|
1115 | |||
1108 | #for spectra |
|
1116 | #for spectra | |
1109 | if dataOut.type == 'Spectra': |
|
1117 | if dataOut.type == 'Spectra': | |
1110 | x = dataOut.data_spc[channelIndexList,:,:]/factor |
|
1118 | x = dataOut.data_spc[channelIndexList,:,:]/factor | |
1111 | x = numpy.where(numpy.isfinite(x), x, numpy.NAN) |
|
1119 | x = numpy.where(numpy.isfinite(x), x, numpy.NAN) | |
1112 | x = numpy.average(x, axis=1) |
|
1120 | x = numpy.average(x, axis=1) | |
1113 |
|
1121 | |||
1114 |
|
1122 | |||
1115 | xdB = 10*numpy.log10(x) |
|
1123 | xdB = 10*numpy.log10(x) | |
1116 |
|
1124 | |||
1117 | thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[1]) |
|
1125 | thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[1]) | |
1118 | title = wintitle + " Power Profile %s" %(thisDatetime.strftime("%d-%b-%Y")) |
|
1126 | title = wintitle + " Power Profile %s" %(thisDatetime.strftime("%d-%b-%Y")) | |
1119 | xlabel = "dB" |
|
1127 | xlabel = "dB" | |
1120 | ylabel = "Range (Km)" |
|
1128 | ylabel = "Range (Km)" | |
1121 |
|
1129 | |||
1122 | if not self.__isConfig: |
|
1130 | if not self.__isConfig: | |
1123 |
|
1131 | |||
1124 | nplots = 1 |
|
1132 | nplots = 1 | |
1125 |
|
1133 | |||
1126 | self.setup(id=id, |
|
1134 | self.setup(id=id, | |
1127 | nplots=nplots, |
|
1135 | nplots=nplots, | |
1128 | wintitle=wintitle, |
|
1136 | wintitle=wintitle, | |
1129 | show=show) |
|
1137 | show=show) | |
1130 |
|
1138 | |||
1131 | if ymin == None: ymin = numpy.nanmin(y) |
|
1139 | if ymin == None: ymin = numpy.nanmin(y) | |
1132 | if ymax == None: ymax = numpy.nanmax(y) |
|
1140 | if ymax == None: ymax = numpy.nanmax(y) | |
1133 | if xmin == None: xmin = numpy.nanmin(xdB)*0.9 |
|
1141 | if xmin == None: xmin = numpy.nanmin(xdB)*0.9 | |
1134 | if xmax == None: xmax = numpy.nanmax(xdB)*0.9 |
|
1142 | if xmax == None: xmax = numpy.nanmax(xdB)*0.9 | |
1135 |
|
1143 | |||
1136 | self.__isConfig = True |
|
1144 | self.__isConfig = True | |
1137 |
|
1145 | |||
1138 | self.setWinTitle(title) |
|
1146 | self.setWinTitle(title) | |
1139 |
|
1147 | |||
1140 | title = "Power Profile: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) |
|
1148 | title = "Power Profile: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) | |
1141 | axes = self.axesList[0] |
|
1149 | axes = self.axesList[0] | |
1142 |
|
1150 | |||
1143 | legendlabels = ["channel %d"%x for x in channelList] |
|
1151 | legendlabels = ["channel %d"%x for x in channelList] | |
1144 | axes.pmultiline(xdB, y, |
|
1152 | axes.pmultiline(xdB, y, | |
1145 | xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, |
|
1153 | xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, | |
1146 | xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels, |
|
1154 | xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels, | |
1147 | ytick_visible=True, nxticks=5, |
|
1155 | ytick_visible=True, nxticks=5, | |
1148 | grid='x') |
|
1156 | grid='x') | |
1149 |
|
1157 | |||
1150 | self.draw() |
|
1158 | self.draw() | |
1151 |
|
1159 | |||
1152 | if save: |
|
1160 | if save: | |
1153 | date = thisDatetime.strftime("%Y%m%d") |
|
1161 | date = thisDatetime.strftime("%Y%m%d") | |
1154 | if figfile == None: |
|
1162 | if figfile == None: | |
1155 | figfile = self.getFilename(name = date) |
|
1163 | figfile = self.getFilename(name = date) | |
1156 |
|
1164 | |||
1157 | self.saveFigure(figpath, figfile) |
|
1165 | self.saveFigure(figpath, figfile) | |
1158 |
|
1166 | |||
1159 | self.counter_imagwr += 1 |
|
1167 | self.counter_imagwr += 1 | |
1160 | if (ftp and (self.counter_imagwr==wr_period)): |
|
1168 | if (ftp and (self.counter_imagwr==wr_period)): | |
1161 | ftp_filename = os.path.join(figpath,figfile) |
|
1169 | ftp_filename = os.path.join(figpath,figfile) | |
1162 | self.sendByFTP_Thread(ftp_filename, server, folder, username, password) |
|
1170 | self.sendByFTP_Thread(ftp_filename, server, folder, username, password) | |
1163 | self.counter_imagwr = 0 |
|
1171 | self.counter_imagwr = 0 | |
1164 |
|
1172 | |||
1165 | class CoherenceMap(Figure): |
|
1173 | class CoherenceMap(Figure): | |
1166 | __isConfig = None |
|
1174 | __isConfig = None | |
1167 | __nsubplots = None |
|
1175 | __nsubplots = None | |
1168 |
|
1176 | |||
1169 | WIDTHPROF = None |
|
1177 | WIDTHPROF = None | |
1170 | HEIGHTPROF = None |
|
1178 | HEIGHTPROF = None | |
1171 | PREFIX = 'cmap' |
|
1179 | PREFIX = 'cmap' | |
1172 |
|
1180 | |||
1173 | def __init__(self): |
|
1181 | def __init__(self): | |
1174 | self.timerange = 2*60*60 |
|
1182 | self.timerange = 2*60*60 | |
1175 | self.__isConfig = False |
|
1183 | self.__isConfig = False | |
1176 | self.__nsubplots = 1 |
|
1184 | self.__nsubplots = 1 | |
1177 |
|
1185 | |||
1178 | self.WIDTH = 800 |
|
1186 | self.WIDTH = 800 | |
1179 | self.HEIGHT = 150 |
|
1187 | self.HEIGHT = 150 | |
1180 | self.WIDTHPROF = 120 |
|
1188 | self.WIDTHPROF = 120 | |
1181 | self.HEIGHTPROF = 0 |
|
1189 | self.HEIGHTPROF = 0 | |
1182 | self.counter_imagwr = 0 |
|
1190 | self.counter_imagwr = 0 | |
1183 |
|
1191 | |||
1184 | self.PLOT_CODE = 3 |
|
1192 | self.PLOT_CODE = 3 | |
1185 | self.FTP_WEI = None |
|
1193 | self.FTP_WEI = None | |
1186 | self.EXP_CODE = None |
|
1194 | self.EXP_CODE = None | |
1187 | self.SUB_EXP_CODE = None |
|
1195 | self.SUB_EXP_CODE = None | |
1188 | self.PLOT_POS = None |
|
1196 | self.PLOT_POS = None | |
1189 | self.counter_imagwr = 0 |
|
1197 | self.counter_imagwr = 0 | |
1190 |
|
1198 | |||
1191 | self.xmin = None |
|
1199 | self.xmin = None | |
1192 | self.xmax = None |
|
1200 | self.xmax = None | |
1193 |
|
1201 | |||
1194 | def getSubplots(self): |
|
1202 | def getSubplots(self): | |
1195 | ncol = 1 |
|
1203 | ncol = 1 | |
1196 | nrow = self.nplots*2 |
|
1204 | nrow = self.nplots*2 | |
1197 |
|
1205 | |||
1198 | return nrow, ncol |
|
1206 | return nrow, ncol | |
1199 |
|
1207 | |||
1200 | def setup(self, id, nplots, wintitle, showprofile=True, show=True): |
|
1208 | def setup(self, id, nplots, wintitle, showprofile=True, show=True): | |
1201 | self.__showprofile = showprofile |
|
1209 | self.__showprofile = showprofile | |
1202 | self.nplots = nplots |
|
1210 | self.nplots = nplots | |
1203 |
|
1211 | |||
1204 | ncolspan = 1 |
|
1212 | ncolspan = 1 | |
1205 | colspan = 1 |
|
1213 | colspan = 1 | |
1206 | if showprofile: |
|
1214 | if showprofile: | |
1207 | ncolspan = 7 |
|
1215 | ncolspan = 7 | |
1208 | colspan = 6 |
|
1216 | colspan = 6 | |
1209 | self.__nsubplots = 2 |
|
1217 | self.__nsubplots = 2 | |
1210 |
|
1218 | |||
1211 | self.createFigure(id = id, |
|
1219 | self.createFigure(id = id, | |
1212 | wintitle = wintitle, |
|
1220 | wintitle = wintitle, | |
1213 | widthplot = self.WIDTH + self.WIDTHPROF, |
|
1221 | widthplot = self.WIDTH + self.WIDTHPROF, | |
1214 | heightplot = self.HEIGHT + self.HEIGHTPROF, |
|
1222 | heightplot = self.HEIGHT + self.HEIGHTPROF, | |
1215 | show=True) |
|
1223 | show=True) | |
1216 |
|
1224 | |||
1217 | nrow, ncol = self.getSubplots() |
|
1225 | nrow, ncol = self.getSubplots() | |
1218 |
|
1226 | |||
1219 | for y in range(nrow): |
|
1227 | for y in range(nrow): | |
1220 | for x in range(ncol): |
|
1228 | for x in range(ncol): | |
1221 |
|
1229 | |||
1222 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1) |
|
1230 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1) | |
1223 |
|
1231 | |||
1224 | if showprofile: |
|
1232 | if showprofile: | |
1225 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1) |
|
1233 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1) | |
1226 |
|
1234 | |||
1227 | def run(self, dataOut, id, wintitle="", pairsList=None, showprofile='True', |
|
1235 | def run(self, dataOut, id, wintitle="", pairsList=None, showprofile='True', | |
1228 | xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None, |
|
1236 | xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None, | |
1229 | timerange=None, |
|
1237 | timerange=None, | |
1230 | save=False, figpath='./', figfile=None, ftp=False, wr_period=1, |
|
1238 | save=False, figpath='./', figfile=None, ftp=False, wr_period=1, | |
1231 | coherence_cmap='jet', phase_cmap='RdBu_r', show=True, |
|
1239 | coherence_cmap='jet', phase_cmap='RdBu_r', show=True, | |
1232 | server=None, folder=None, username=None, password=None, |
|
1240 | server=None, folder=None, username=None, password=None, | |
1233 | ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0): |
|
1241 | ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0): | |
1234 |
|
1242 | |||
1235 | if pairsList == None: |
|
1243 | if pairsList == None: | |
1236 | pairsIndexList = dataOut.pairsIndexList |
|
1244 | pairsIndexList = dataOut.pairsIndexList | |
1237 | else: |
|
1245 | else: | |
1238 | pairsIndexList = [] |
|
1246 | pairsIndexList = [] | |
1239 | for pair in pairsList: |
|
1247 | for pair in pairsList: | |
1240 | if pair not in dataOut.pairsList: |
|
1248 | if pair not in dataOut.pairsList: | |
1241 | raise ValueError, "Pair %s is not in dataOut.pairsList" %(pair) |
|
1249 | raise ValueError, "Pair %s is not in dataOut.pairsList" %(pair) | |
1242 | pairsIndexList.append(dataOut.pairsList.index(pair)) |
|
1250 | pairsIndexList.append(dataOut.pairsList.index(pair)) | |
1243 |
|
1251 | |||
1244 | if timerange != None: |
|
1252 | if timerange != None: | |
1245 | self.timerange = timerange |
|
1253 | self.timerange = timerange | |
1246 |
|
1254 | |||
1247 | if pairsIndexList == []: |
|
1255 | if pairsIndexList == []: | |
1248 | return |
|
1256 | return | |
1249 |
|
1257 | |||
1250 | if len(pairsIndexList) > 4: |
|
1258 | if len(pairsIndexList) > 4: | |
1251 | pairsIndexList = pairsIndexList[0:4] |
|
1259 | pairsIndexList = pairsIndexList[0:4] | |
1252 |
|
1260 | |||
1253 | # tmin = None |
|
1261 | # tmin = None | |
1254 | # tmax = None |
|
1262 | # tmax = None | |
1255 | x = dataOut.getTimeRange() |
|
1263 | x = dataOut.getTimeRange() | |
1256 | y = dataOut.getHeiRange() |
|
1264 | y = dataOut.getHeiRange() | |
1257 |
|
1265 | |||
1258 | #thisDatetime = dataOut.datatime |
|
1266 | #thisDatetime = dataOut.datatime | |
1259 | thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[1]) |
|
1267 | thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[1]) | |
1260 | title = wintitle + " CoherenceMap" #: %s" %(thisDatetime.strftime("%d-%b-%Y")) |
|
1268 | title = wintitle + " CoherenceMap" #: %s" %(thisDatetime.strftime("%d-%b-%Y")) | |
1261 | xlabel = "" |
|
1269 | xlabel = "" | |
1262 | ylabel = "Range (Km)" |
|
1270 | ylabel = "Range (Km)" | |
1263 |
|
1271 | |||
1264 | if not self.__isConfig: |
|
1272 | if not self.__isConfig: | |
1265 | nplots = len(pairsIndexList) |
|
1273 | nplots = len(pairsIndexList) | |
1266 | self.setup(id=id, |
|
1274 | self.setup(id=id, | |
1267 | nplots=nplots, |
|
1275 | nplots=nplots, | |
1268 | wintitle=wintitle, |
|
1276 | wintitle=wintitle, | |
1269 | showprofile=showprofile, |
|
1277 | showprofile=showprofile, | |
1270 | show=show) |
|
1278 | show=show) | |
1271 |
|
1279 | |||
1272 | #tmin, tmax = self.getTimeLim(x, xmin, xmax) |
|
1280 | #tmin, tmax = self.getTimeLim(x, xmin, xmax) | |
1273 |
|
1281 | |||
1274 | self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange) |
|
1282 | self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange) | |
1275 |
|
1283 | |||
1276 | if ymin == None: ymin = numpy.nanmin(y) |
|
1284 | if ymin == None: ymin = numpy.nanmin(y) | |
1277 | if ymax == None: ymax = numpy.nanmax(y) |
|
1285 | if ymax == None: ymax = numpy.nanmax(y) | |
1278 | if zmin == None: zmin = 0. |
|
1286 | if zmin == None: zmin = 0. | |
1279 | if zmax == None: zmax = 1. |
|
1287 | if zmax == None: zmax = 1. | |
1280 |
|
1288 | |||
1281 | self.FTP_WEI = ftp_wei |
|
1289 | self.FTP_WEI = ftp_wei | |
1282 | self.EXP_CODE = exp_code |
|
1290 | self.EXP_CODE = exp_code | |
1283 | self.SUB_EXP_CODE = sub_exp_code |
|
1291 | self.SUB_EXP_CODE = sub_exp_code | |
1284 | self.PLOT_POS = plot_pos |
|
1292 | self.PLOT_POS = plot_pos | |
1285 |
|
1293 | |||
1286 | self.name = thisDatetime.strftime("%Y%m%d_%H%M%S") |
|
1294 | self.name = thisDatetime.strftime("%Y%m%d_%H%M%S") | |
1287 |
|
1295 | |||
1288 | self.__isConfig = True |
|
1296 | self.__isConfig = True | |
1289 |
|
1297 | |||
1290 | self.setWinTitle(title) |
|
1298 | self.setWinTitle(title) | |
1291 |
|
1299 | |||
1292 | if ((self.xmax - x[1]) < (x[1]-x[0])): |
|
1300 | if ((self.xmax - x[1]) < (x[1]-x[0])): | |
1293 | x[1] = self.xmax |
|
1301 | x[1] = self.xmax | |
1294 |
|
1302 | |||
1295 | for i in range(self.nplots): |
|
1303 | for i in range(self.nplots): | |
1296 |
|
1304 | |||
1297 | pair = dataOut.pairsList[pairsIndexList[i]] |
|
1305 | pair = dataOut.pairsList[pairsIndexList[i]] | |
1298 | # coherenceComplex = dataOut.data_cspc[pairsIndexList[i],:,:]/numpy.sqrt(dataOut.data_spc[pair[0],:,:]*dataOut.data_spc[pair[1],:,:]) |
|
1306 | # coherenceComplex = dataOut.data_cspc[pairsIndexList[i],:,:]/numpy.sqrt(dataOut.data_spc[pair[0],:,:]*dataOut.data_spc[pair[1],:,:]) | |
1299 | # avgcoherenceComplex = numpy.average(coherenceComplex, axis=0) |
|
1307 | # avgcoherenceComplex = numpy.average(coherenceComplex, axis=0) | |
1300 | # coherence = numpy.abs(avgcoherenceComplex) |
|
1308 | # coherence = numpy.abs(avgcoherenceComplex) | |
1301 |
|
1309 | |||
1302 | ## coherence = numpy.abs(coherenceComplex) |
|
1310 | ## coherence = numpy.abs(coherenceComplex) | |
1303 | ## avg = numpy.average(coherence, axis=0) |
|
1311 | ## avg = numpy.average(coherence, axis=0) | |
1304 |
|
1312 | |||
1305 | ccf = numpy.average(dataOut.data_cspc[pairsIndexList[i],:,:],axis=0) |
|
1313 | ccf = numpy.average(dataOut.data_cspc[pairsIndexList[i],:,:],axis=0) | |
1306 | powa = numpy.average(dataOut.data_spc[pair[0],:,:],axis=0) |
|
1314 | powa = numpy.average(dataOut.data_spc[pair[0],:,:],axis=0) | |
1307 | powb = numpy.average(dataOut.data_spc[pair[1],:,:],axis=0) |
|
1315 | powb = numpy.average(dataOut.data_spc[pair[1],:,:],axis=0) | |
1308 |
|
1316 | |||
1309 |
|
1317 | |||
1310 | avgcoherenceComplex = ccf/numpy.sqrt(powa*powb) |
|
1318 | avgcoherenceComplex = ccf/numpy.sqrt(powa*powb) | |
1311 | coherence = numpy.abs(avgcoherenceComplex) |
|
1319 | coherence = numpy.abs(avgcoherenceComplex) | |
1312 |
|
1320 | |||
1313 | z = coherence.reshape((1,-1)) |
|
1321 | z = coherence.reshape((1,-1)) | |
1314 |
|
1322 | |||
1315 | counter = 0 |
|
1323 | counter = 0 | |
1316 |
|
1324 | |||
1317 | title = "Coherence %d%d: %s" %(pair[0], pair[1], thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) |
|
1325 | title = "Coherence %d%d: %s" %(pair[0], pair[1], thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) | |
1318 | axes = self.axesList[i*self.__nsubplots*2] |
|
1326 | axes = self.axesList[i*self.__nsubplots*2] | |
1319 | axes.pcolorbuffer(x, y, z, |
|
1327 | axes.pcolorbuffer(x, y, z, | |
1320 | xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax, |
|
1328 | xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax, | |
1321 | xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True, |
|
1329 | xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True, | |
1322 | ticksize=9, cblabel='', colormap=coherence_cmap, cbsize="1%") |
|
1330 | ticksize=9, cblabel='', colormap=coherence_cmap, cbsize="1%") | |
1323 |
|
1331 | |||
1324 | if self.__showprofile: |
|
1332 | if self.__showprofile: | |
1325 | counter += 1 |
|
1333 | counter += 1 | |
1326 | axes = self.axesList[i*self.__nsubplots*2 + counter] |
|
1334 | axes = self.axesList[i*self.__nsubplots*2 + counter] | |
1327 | axes.pline(coherence, y, |
|
1335 | axes.pline(coherence, y, | |
1328 | xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax, |
|
1336 | xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax, | |
1329 | xlabel='', ylabel='', title='', ticksize=7, |
|
1337 | xlabel='', ylabel='', title='', ticksize=7, | |
1330 | ytick_visible=False, nxticks=5, |
|
1338 | ytick_visible=False, nxticks=5, | |
1331 | grid='x') |
|
1339 | grid='x') | |
1332 |
|
1340 | |||
1333 | counter += 1 |
|
1341 | counter += 1 | |
1334 | # phase = numpy.arctan(-1*coherenceComplex.imag/coherenceComplex.real)*180/numpy.pi |
|
1342 | # phase = numpy.arctan(-1*coherenceComplex.imag/coherenceComplex.real)*180/numpy.pi | |
1335 | phase = numpy.arctan2(avgcoherenceComplex.imag, avgcoherenceComplex.real)*180/numpy.pi |
|
1343 | phase = numpy.arctan2(avgcoherenceComplex.imag, avgcoherenceComplex.real)*180/numpy.pi | |
1336 | # avg = numpy.average(phase, axis=0) |
|
1344 | # avg = numpy.average(phase, axis=0) | |
1337 | z = phase.reshape((1,-1)) |
|
1345 | z = phase.reshape((1,-1)) | |
1338 |
|
1346 | |||
1339 | title = "Phase %d%d: %s" %(pair[0], pair[1], thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) |
|
1347 | title = "Phase %d%d: %s" %(pair[0], pair[1], thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) | |
1340 | axes = self.axesList[i*self.__nsubplots*2 + counter] |
|
1348 | axes = self.axesList[i*self.__nsubplots*2 + counter] | |
1341 | axes.pcolorbuffer(x, y, z, |
|
1349 | axes.pcolorbuffer(x, y, z, | |
1342 | xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=-180, zmax=180, |
|
1350 | xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=-180, zmax=180, | |
1343 | xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True, |
|
1351 | xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True, | |
1344 | ticksize=9, cblabel='', colormap=phase_cmap, cbsize="1%") |
|
1352 | ticksize=9, cblabel='', colormap=phase_cmap, cbsize="1%") | |
1345 |
|
1353 | |||
1346 | if self.__showprofile: |
|
1354 | if self.__showprofile: | |
1347 | counter += 1 |
|
1355 | counter += 1 | |
1348 | axes = self.axesList[i*self.__nsubplots*2 + counter] |
|
1356 | axes = self.axesList[i*self.__nsubplots*2 + counter] | |
1349 | axes.pline(phase, y, |
|
1357 | axes.pline(phase, y, | |
1350 | xmin=-180, xmax=180, ymin=ymin, ymax=ymax, |
|
1358 | xmin=-180, xmax=180, ymin=ymin, ymax=ymax, | |
1351 | xlabel='', ylabel='', title='', ticksize=7, |
|
1359 | xlabel='', ylabel='', title='', ticksize=7, | |
1352 | ytick_visible=False, nxticks=4, |
|
1360 | ytick_visible=False, nxticks=4, | |
1353 | grid='x') |
|
1361 | grid='x') | |
1354 |
|
1362 | |||
1355 | self.draw() |
|
1363 | self.draw() | |
1356 |
|
1364 | |||
1357 | if x[1] >= self.axesList[0].xmax: |
|
1365 | if x[1] >= self.axesList[0].xmax: | |
1358 | self.saveFigure(figpath, figfile) |
|
1366 | self.saveFigure(figpath, figfile) | |
1359 | self.__isConfig = False |
|
1367 | self.__isConfig = False | |
1360 |
|
1368 | |||
1361 | # if save: |
|
1369 | # if save: | |
1362 | # |
|
1370 | # | |
1363 | # self.counter_imagwr += 1 |
|
1371 | # self.counter_imagwr += 1 | |
1364 | # if (self.counter_imagwr==wr_period): |
|
1372 | # if (self.counter_imagwr==wr_period): | |
1365 | # if figfile == None: |
|
1373 | # if figfile == None: | |
1366 | # figfile = self.getFilename(name = self.name) |
|
1374 | # figfile = self.getFilename(name = self.name) | |
1367 | # self.saveFigure(figpath, figfile) |
|
1375 | # self.saveFigure(figpath, figfile) | |
1368 | # |
|
1376 | # | |
1369 | # if ftp: |
|
1377 | # if ftp: | |
1370 | # #provisionalmente envia archivos en el formato de la web en tiempo real |
|
1378 | # #provisionalmente envia archivos en el formato de la web en tiempo real | |
1371 | # name = self.getNameToFtp(thisDatetime, self.FTP_WEI, self.EXP_CODE, self.SUB_EXP_CODE, self.PLOT_CODE, self.PLOT_POS) |
|
1379 | # name = self.getNameToFtp(thisDatetime, self.FTP_WEI, self.EXP_CODE, self.SUB_EXP_CODE, self.PLOT_CODE, self.PLOT_POS) | |
1372 | # path = '%s%03d' %(self.PREFIX, self.id) |
|
1380 | # path = '%s%03d' %(self.PREFIX, self.id) | |
1373 | # ftp_file = os.path.join(path,'ftp','%s.png'%name) |
|
1381 | # ftp_file = os.path.join(path,'ftp','%s.png'%name) | |
1374 | # self.saveFigure(figpath, ftp_file) |
|
1382 | # self.saveFigure(figpath, ftp_file) | |
1375 | # ftp_filename = os.path.join(figpath,ftp_file) |
|
1383 | # ftp_filename = os.path.join(figpath,ftp_file) | |
1376 | # self.sendByFTP_Thread(ftp_filename, server, folder, username, password) |
|
1384 | # self.sendByFTP_Thread(ftp_filename, server, folder, username, password) | |
1377 | # self.counter_imagwr = 0 |
|
1385 | # self.counter_imagwr = 0 | |
1378 | # |
|
1386 | # | |
1379 | # self.counter_imagwr = 0 |
|
1387 | # self.counter_imagwr = 0 | |
1380 | # |
|
1388 | # | |
1381 | # |
|
1389 | # | |
1382 | # if x[1] + (x[1]-x[0]) >= self.axesList[0].xmax: |
|
1390 | # if x[1] + (x[1]-x[0]) >= self.axesList[0].xmax: | |
1383 | # self.__isConfig = False |
|
1391 | # self.__isConfig = False | |
1384 |
|
1392 | |||
1385 | class BeaconPhase(Figure): |
|
1393 | class BeaconPhase(Figure): | |
1386 |
|
1394 | |||
1387 | __isConfig = None |
|
1395 | __isConfig = None | |
1388 | __nsubplots = None |
|
1396 | __nsubplots = None | |
1389 |
|
1397 | |||
1390 | PREFIX = 'beacon_phase' |
|
1398 | PREFIX = 'beacon_phase' | |
1391 |
|
1399 | |||
1392 | def __init__(self): |
|
1400 | def __init__(self): | |
1393 |
|
1401 | |||
1394 | self.timerange = 24*60*60 |
|
1402 | self.timerange = 24*60*60 | |
1395 | self.__isConfig = False |
|
1403 | self.__isConfig = False | |
1396 | self.__nsubplots = 1 |
|
1404 | self.__nsubplots = 1 | |
1397 | self.counter_imagwr = 0 |
|
1405 | self.counter_imagwr = 0 | |
1398 | self.WIDTH = 600 |
|
1406 | self.WIDTH = 600 | |
1399 | self.HEIGHT = 300 |
|
1407 | self.HEIGHT = 300 | |
1400 | self.WIDTHPROF = 120 |
|
1408 | self.WIDTHPROF = 120 | |
1401 | self.HEIGHTPROF = 0 |
|
1409 | self.HEIGHTPROF = 0 | |
1402 | self.xdata = None |
|
1410 | self.xdata = None | |
1403 | self.ydata = None |
|
1411 | self.ydata = None | |
1404 |
|
1412 | |||
1405 | self.PLOT_CODE = 18 |
|
1413 | self.PLOT_CODE = 18 | |
1406 | self.FTP_WEI = None |
|
1414 | self.FTP_WEI = None | |
1407 | self.EXP_CODE = None |
|
1415 | self.EXP_CODE = None | |
1408 | self.SUB_EXP_CODE = None |
|
1416 | self.SUB_EXP_CODE = None | |
1409 | self.PLOT_POS = None |
|
1417 | self.PLOT_POS = None | |
1410 |
|
1418 | |||
1411 | self.filename_phase = None |
|
1419 | self.filename_phase = None | |
1412 |
|
1420 | |||
1413 | def getSubplots(self): |
|
1421 | def getSubplots(self): | |
1414 |
|
1422 | |||
1415 | ncol = 1 |
|
1423 | ncol = 1 | |
1416 | nrow = 1 |
|
1424 | nrow = 1 | |
1417 |
|
1425 | |||
1418 | return nrow, ncol |
|
1426 | return nrow, ncol | |
1419 |
|
1427 | |||
1420 | def setup(self, id, nplots, wintitle, showprofile=True, show=True): |
|
1428 | def setup(self, id, nplots, wintitle, showprofile=True, show=True): | |
1421 |
|
1429 | |||
1422 | self.__showprofile = showprofile |
|
1430 | self.__showprofile = showprofile | |
1423 | self.nplots = nplots |
|
1431 | self.nplots = nplots | |
1424 |
|
1432 | |||
1425 | ncolspan = 7 |
|
1433 | ncolspan = 7 | |
1426 | colspan = 6 |
|
1434 | colspan = 6 | |
1427 | self.__nsubplots = 2 |
|
1435 | self.__nsubplots = 2 | |
1428 |
|
1436 | |||
1429 | self.createFigure(id = id, |
|
1437 | self.createFigure(id = id, | |
1430 | wintitle = wintitle, |
|
1438 | wintitle = wintitle, | |
1431 | widthplot = self.WIDTH+self.WIDTHPROF, |
|
1439 | widthplot = self.WIDTH+self.WIDTHPROF, | |
1432 | heightplot = self.HEIGHT+self.HEIGHTPROF, |
|
1440 | heightplot = self.HEIGHT+self.HEIGHTPROF, | |
1433 | show=show) |
|
1441 | show=show) | |
1434 |
|
1442 | |||
1435 | nrow, ncol = self.getSubplots() |
|
1443 | nrow, ncol = self.getSubplots() | |
1436 |
|
1444 | |||
1437 | self.addAxes(nrow, ncol*ncolspan, 0, 0, colspan, 1) |
|
1445 | self.addAxes(nrow, ncol*ncolspan, 0, 0, colspan, 1) | |
1438 |
|
1446 | |||
1439 | def save_phase(self, filename_phase): |
|
1447 | def save_phase(self, filename_phase): | |
1440 | f = open(filename_phase,'w+') |
|
1448 | f = open(filename_phase,'w+') | |
1441 | f.write('\n\n') |
|
1449 | f.write('\n\n') | |
1442 | f.write('JICAMARCA RADIO OBSERVATORY - Beacon Phase \n') |
|
1450 | f.write('JICAMARCA RADIO OBSERVATORY - Beacon Phase \n') | |
1443 | f.write('DD MM YYYY HH MM SS pair(2,0) pair(2,1) pair(2,3) pair(2,4)\n\n' ) |
|
1451 | f.write('DD MM YYYY HH MM SS pair(2,0) pair(2,1) pair(2,3) pair(2,4)\n\n' ) | |
1444 | f.close() |
|
1452 | f.close() | |
1445 |
|
1453 | |||
1446 | def save_data(self, filename_phase, data, data_datetime): |
|
1454 | def save_data(self, filename_phase, data, data_datetime): | |
1447 | f=open(filename_phase,'a') |
|
1455 | f=open(filename_phase,'a') | |
1448 | timetuple_data = data_datetime.timetuple() |
|
1456 | timetuple_data = data_datetime.timetuple() | |
1449 | day = str(timetuple_data.tm_mday) |
|
1457 | day = str(timetuple_data.tm_mday) | |
1450 | month = str(timetuple_data.tm_mon) |
|
1458 | month = str(timetuple_data.tm_mon) | |
1451 | year = str(timetuple_data.tm_year) |
|
1459 | year = str(timetuple_data.tm_year) | |
1452 | hour = str(timetuple_data.tm_hour) |
|
1460 | hour = str(timetuple_data.tm_hour) | |
1453 | minute = str(timetuple_data.tm_min) |
|
1461 | minute = str(timetuple_data.tm_min) | |
1454 | second = str(timetuple_data.tm_sec) |
|
1462 | second = str(timetuple_data.tm_sec) | |
1455 | f.write(day+' '+month+' '+year+' '+hour+' '+minute+' '+second+' '+str(data[0])+' '+str(data[1])+' '+str(data[2])+' '+str(data[3])+'\n') |
|
1463 | f.write(day+' '+month+' '+year+' '+hour+' '+minute+' '+second+' '+str(data[0])+' '+str(data[1])+' '+str(data[2])+' '+str(data[3])+'\n') | |
1456 | f.close() |
|
1464 | f.close() | |
1457 |
|
1465 | |||
1458 |
|
1466 | |||
1459 | def run(self, dataOut, id, wintitle="", pairsList=None, showprofile='True', |
|
1467 | def run(self, dataOut, id, wintitle="", pairsList=None, showprofile='True', | |
1460 | xmin=None, xmax=None, ymin=None, ymax=None, |
|
1468 | xmin=None, xmax=None, ymin=None, ymax=None, | |
1461 | timerange=None, |
|
1469 | timerange=None, | |
1462 | save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1, |
|
1470 | save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1, | |
1463 | server=None, folder=None, username=None, password=None, |
|
1471 | server=None, folder=None, username=None, password=None, | |
1464 | ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0): |
|
1472 | ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0): | |
1465 |
|
1473 | |||
1466 | if pairsList == None: |
|
1474 | if pairsList == None: | |
1467 | pairsIndexList = dataOut.pairsIndexList |
|
1475 | pairsIndexList = dataOut.pairsIndexList | |
1468 | else: |
|
1476 | else: | |
1469 | pairsIndexList = [] |
|
1477 | pairsIndexList = [] | |
1470 | for pair in pairsList: |
|
1478 | for pair in pairsList: | |
1471 | if pair not in dataOut.pairsList: |
|
1479 | if pair not in dataOut.pairsList: | |
1472 | raise ValueError, "Pair %s is not in dataOut.pairsList" %(pair) |
|
1480 | raise ValueError, "Pair %s is not in dataOut.pairsList" %(pair) | |
1473 | pairsIndexList.append(dataOut.pairsList.index(pair)) |
|
1481 | pairsIndexList.append(dataOut.pairsList.index(pair)) | |
1474 |
|
1482 | |||
1475 | if pairsIndexList == []: |
|
1483 | if pairsIndexList == []: | |
1476 | return |
|
1484 | return | |
1477 |
|
1485 | |||
1478 | # if len(pairsIndexList) > 4: |
|
1486 | # if len(pairsIndexList) > 4: | |
1479 | # pairsIndexList = pairsIndexList[0:4] |
|
1487 | # pairsIndexList = pairsIndexList[0:4] | |
1480 |
|
1488 | |||
1481 | if timerange != None: |
|
1489 | if timerange != None: | |
1482 | self.timerange = timerange |
|
1490 | self.timerange = timerange | |
1483 |
|
1491 | |||
1484 | tmin = None |
|
1492 | tmin = None | |
1485 | tmax = None |
|
1493 | tmax = None | |
1486 | x = dataOut.getTimeRange() |
|
1494 | x = dataOut.getTimeRange() | |
1487 | y = dataOut.getHeiRange() |
|
1495 | y = dataOut.getHeiRange() | |
1488 |
|
1496 | |||
1489 |
|
1497 | |||
1490 | #thisDatetime = dataOut.datatime |
|
1498 | #thisDatetime = dataOut.datatime | |
1491 | thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[1]) |
|
1499 | thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[1]) | |
1492 | title = wintitle + " Phase of Beacon Signal" # : %s" %(thisDatetime.strftime("%d-%b-%Y")) |
|
1500 | title = wintitle + " Phase of Beacon Signal" # : %s" %(thisDatetime.strftime("%d-%b-%Y")) | |
1493 | xlabel = "Local Time" |
|
1501 | xlabel = "Local Time" | |
1494 | ylabel = "Phase" |
|
1502 | ylabel = "Phase" | |
1495 |
|
1503 | |||
1496 | nplots = len(pairsIndexList) |
|
1504 | nplots = len(pairsIndexList) | |
1497 | #phase = numpy.zeros((len(pairsIndexList),len(dataOut.beacon_heiIndexList))) |
|
1505 | #phase = numpy.zeros((len(pairsIndexList),len(dataOut.beacon_heiIndexList))) | |
1498 | phase_beacon = numpy.zeros(len(pairsIndexList)) |
|
1506 | phase_beacon = numpy.zeros(len(pairsIndexList)) | |
1499 | for i in range(nplots): |
|
1507 | for i in range(nplots): | |
1500 | pair = dataOut.pairsList[pairsIndexList[i]] |
|
1508 | pair = dataOut.pairsList[pairsIndexList[i]] | |
1501 | ccf = numpy.average(dataOut.data_cspc[pairsIndexList[i],:,:],axis=0) |
|
1509 | ccf = numpy.average(dataOut.data_cspc[pairsIndexList[i],:,:],axis=0) | |
1502 | powa = numpy.average(dataOut.data_spc[pair[0],:,:],axis=0) |
|
1510 | powa = numpy.average(dataOut.data_spc[pair[0],:,:],axis=0) | |
1503 | powb = numpy.average(dataOut.data_spc[pair[1],:,:],axis=0) |
|
1511 | powb = numpy.average(dataOut.data_spc[pair[1],:,:],axis=0) | |
1504 | avgcoherenceComplex = ccf/numpy.sqrt(powa*powb) |
|
1512 | avgcoherenceComplex = ccf/numpy.sqrt(powa*powb) | |
1505 | phase = numpy.arctan2(avgcoherenceComplex.imag, avgcoherenceComplex.real)*180/numpy.pi |
|
1513 | phase = numpy.arctan2(avgcoherenceComplex.imag, avgcoherenceComplex.real)*180/numpy.pi | |
1506 |
|
1514 | |||
1507 | #print "Phase %d%d" %(pair[0], pair[1]) |
|
1515 | #print "Phase %d%d" %(pair[0], pair[1]) | |
1508 | #print phase[dataOut.beacon_heiIndexList] |
|
1516 | #print phase[dataOut.beacon_heiIndexList] | |
1509 |
|
1517 | |||
1510 | phase_beacon[i] = numpy.average(phase[dataOut.beacon_heiIndexList]) |
|
1518 | phase_beacon[i] = numpy.average(phase[dataOut.beacon_heiIndexList]) | |
1511 |
|
1519 | |||
1512 | if not self.__isConfig: |
|
1520 | if not self.__isConfig: | |
1513 |
|
1521 | |||
1514 | nplots = len(pairsIndexList) |
|
1522 | nplots = len(pairsIndexList) | |
1515 |
|
1523 | |||
1516 | self.setup(id=id, |
|
1524 | self.setup(id=id, | |
1517 | nplots=nplots, |
|
1525 | nplots=nplots, | |
1518 | wintitle=wintitle, |
|
1526 | wintitle=wintitle, | |
1519 | showprofile=showprofile, |
|
1527 | showprofile=showprofile, | |
1520 | show=show) |
|
1528 | show=show) | |
1521 |
|
1529 | |||
1522 | tmin, tmax = self.getTimeLim(x, xmin, xmax) |
|
1530 | tmin, tmax = self.getTimeLim(x, xmin, xmax) | |
1523 | if ymin == None: ymin = numpy.nanmin(phase_beacon) - 10.0 |
|
1531 | if ymin == None: ymin = numpy.nanmin(phase_beacon) - 10.0 | |
1524 | if ymax == None: ymax = numpy.nanmax(phase_beacon) + 10.0 |
|
1532 | if ymax == None: ymax = numpy.nanmax(phase_beacon) + 10.0 | |
1525 |
|
1533 | |||
1526 | self.FTP_WEI = ftp_wei |
|
1534 | self.FTP_WEI = ftp_wei | |
1527 | self.EXP_CODE = exp_code |
|
1535 | self.EXP_CODE = exp_code | |
1528 | self.SUB_EXP_CODE = sub_exp_code |
|
1536 | self.SUB_EXP_CODE = sub_exp_code | |
1529 | self.PLOT_POS = plot_pos |
|
1537 | self.PLOT_POS = plot_pos | |
1530 |
|
1538 | |||
1531 | self.name = thisDatetime.strftime("%Y%m%d_%H%M%S") |
|
1539 | self.name = thisDatetime.strftime("%Y%m%d_%H%M%S") | |
1532 | self.__isConfig = True |
|
1540 | self.__isConfig = True | |
1533 |
|
1541 | |||
1534 | self.xdata = numpy.array([]) |
|
1542 | self.xdata = numpy.array([]) | |
1535 | self.ydata = numpy.array([]) |
|
1543 | self.ydata = numpy.array([]) | |
1536 |
|
1544 | |||
1537 | #open file beacon phase |
|
1545 | #open file beacon phase | |
1538 | path = '%s%03d' %(self.PREFIX, self.id) |
|
1546 | path = '%s%03d' %(self.PREFIX, self.id) | |
1539 | beacon_file = os.path.join(path,'%s.txt'%self.name) |
|
1547 | beacon_file = os.path.join(path,'%s.txt'%self.name) | |
1540 | self.filename_phase = os.path.join(figpath,beacon_file) |
|
1548 | self.filename_phase = os.path.join(figpath,beacon_file) | |
1541 | #self.save_phase(self.filename_phase) |
|
1549 | #self.save_phase(self.filename_phase) | |
1542 |
|
1550 | |||
1543 |
|
1551 | |||
1544 | #store data beacon phase |
|
1552 | #store data beacon phase | |
1545 | #self.save_data(self.filename_phase, phase_beacon, thisDatetime) |
|
1553 | #self.save_data(self.filename_phase, phase_beacon, thisDatetime) | |
1546 |
|
1554 | |||
1547 | self.setWinTitle(title) |
|
1555 | self.setWinTitle(title) | |
1548 |
|
1556 | |||
1549 |
|
1557 | |||
1550 | title = "Beacon Signal %s" %(thisDatetime.strftime("%Y/%m/%d %H:%M:%S")) |
|
1558 | title = "Beacon Signal %s" %(thisDatetime.strftime("%Y/%m/%d %H:%M:%S")) | |
1551 |
|
1559 | |||
1552 | legendlabels = ["pairs %d%d"%(pair[0], pair[1]) for pair in dataOut.pairsList] |
|
1560 | legendlabels = ["pairs %d%d"%(pair[0], pair[1]) for pair in dataOut.pairsList] | |
1553 |
|
1561 | |||
1554 | axes = self.axesList[0] |
|
1562 | axes = self.axesList[0] | |
1555 |
|
1563 | |||
1556 | self.xdata = numpy.hstack((self.xdata, x[0:1])) |
|
1564 | self.xdata = numpy.hstack((self.xdata, x[0:1])) | |
1557 |
|
1565 | |||
1558 | if len(self.ydata)==0: |
|
1566 | if len(self.ydata)==0: | |
1559 | self.ydata = phase_beacon.reshape(-1,1) |
|
1567 | self.ydata = phase_beacon.reshape(-1,1) | |
1560 | else: |
|
1568 | else: | |
1561 | self.ydata = numpy.hstack((self.ydata, phase_beacon.reshape(-1,1))) |
|
1569 | self.ydata = numpy.hstack((self.ydata, phase_beacon.reshape(-1,1))) | |
1562 |
|
1570 | |||
1563 |
|
1571 | |||
1564 | axes.pmultilineyaxis(x=self.xdata, y=self.ydata, |
|
1572 | axes.pmultilineyaxis(x=self.xdata, y=self.ydata, | |
1565 | xmin=tmin, xmax=tmax, ymin=ymin, ymax=ymax, |
|
1573 | xmin=tmin, xmax=tmax, ymin=ymin, ymax=ymax, | |
1566 | xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels, marker='x', markersize=8, linestyle="solid", |
|
1574 | xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels, marker='x', markersize=8, linestyle="solid", | |
1567 | XAxisAsTime=True, grid='both' |
|
1575 | XAxisAsTime=True, grid='both' | |
1568 | ) |
|
1576 | ) | |
1569 |
|
1577 | |||
1570 | self.draw() |
|
1578 | self.draw() | |
1571 |
|
1579 | |||
1572 | if save: |
|
1580 | if save: | |
1573 |
|
1581 | |||
1574 | self.counter_imagwr += 1 |
|
1582 | self.counter_imagwr += 1 | |
1575 | if (self.counter_imagwr==wr_period): |
|
1583 | if (self.counter_imagwr==wr_period): | |
1576 | if figfile == None: |
|
1584 | if figfile == None: | |
1577 | figfile = self.getFilename(name = self.name) |
|
1585 | figfile = self.getFilename(name = self.name) | |
1578 | self.saveFigure(figpath, figfile) |
|
1586 | self.saveFigure(figpath, figfile) | |
1579 |
|
1587 | |||
1580 | if ftp: |
|
1588 | if ftp: | |
1581 | #provisionalmente envia archivos en el formato de la web en tiempo real |
|
1589 | #provisionalmente envia archivos en el formato de la web en tiempo real | |
1582 | name = self.getNameToFtp(thisDatetime, self.FTP_WEI, self.EXP_CODE, self.SUB_EXP_CODE, self.PLOT_CODE, self.PLOT_POS) |
|
1590 | name = self.getNameToFtp(thisDatetime, self.FTP_WEI, self.EXP_CODE, self.SUB_EXP_CODE, self.PLOT_CODE, self.PLOT_POS) | |
1583 | path = '%s%03d' %(self.PREFIX, self.id) |
|
1591 | path = '%s%03d' %(self.PREFIX, self.id) | |
1584 | ftp_file = os.path.join(path,'ftp','%s.png'%name) |
|
1592 | ftp_file = os.path.join(path,'ftp','%s.png'%name) | |
1585 | self.saveFigure(figpath, ftp_file) |
|
1593 | self.saveFigure(figpath, ftp_file) | |
1586 | ftp_filename = os.path.join(figpath,ftp_file) |
|
1594 | ftp_filename = os.path.join(figpath,ftp_file) | |
1587 | self.sendByFTP_Thread(ftp_filename, server, folder, username, password) |
|
1595 | self.sendByFTP_Thread(ftp_filename, server, folder, username, password) | |
1588 |
|
1596 | |||
1589 | self.counter_imagwr = 0 |
|
1597 | self.counter_imagwr = 0 | |
1590 |
|
1598 | |||
1591 | if x[1] + (x[1]-x[0]) >= self.axesList[0].xmax: |
|
1599 | if x[1] + (x[1]-x[0]) >= self.axesList[0].xmax: | |
1592 | self.__isConfig = False |
|
1600 | self.__isConfig = False | |
1593 | del self.xdata |
|
1601 | del self.xdata | |
1594 | del self.ydata |
|
1602 | del self.ydata | |
1595 |
|
1603 | |||
1596 |
|
1604 | |||
1597 |
|
1605 | |||
1598 |
|
1606 | |||
1599 | class Noise(Figure): |
|
1607 | class Noise(Figure): | |
1600 |
|
1608 | |||
1601 | __isConfig = None |
|
1609 | __isConfig = None | |
1602 | __nsubplots = None |
|
1610 | __nsubplots = None | |
1603 |
|
1611 | |||
1604 | PREFIX = 'noise' |
|
1612 | PREFIX = 'noise' | |
1605 |
|
1613 | |||
1606 | def __init__(self): |
|
1614 | def __init__(self): | |
1607 |
|
1615 | |||
1608 | self.timerange = 24*60*60 |
|
1616 | self.timerange = 24*60*60 | |
1609 | self.__isConfig = False |
|
1617 | self.__isConfig = False | |
1610 | self.__nsubplots = 1 |
|
1618 | self.__nsubplots = 1 | |
1611 | self.counter_imagwr = 0 |
|
1619 | self.counter_imagwr = 0 | |
1612 | self.WIDTH = 600 |
|
1620 | self.WIDTH = 600 | |
1613 | self.HEIGHT = 300 |
|
1621 | self.HEIGHT = 300 | |
1614 | self.WIDTHPROF = 120 |
|
1622 | self.WIDTHPROF = 120 | |
1615 | self.HEIGHTPROF = 0 |
|
1623 | self.HEIGHTPROF = 0 | |
1616 | self.xdata = None |
|
1624 | self.xdata = None | |
1617 | self.ydata = None |
|
1625 | self.ydata = None | |
1618 |
|
1626 | |||
1619 | self.PLOT_CODE = 77 |
|
1627 | self.PLOT_CODE = 77 | |
1620 | self.FTP_WEI = None |
|
1628 | self.FTP_WEI = None | |
1621 | self.EXP_CODE = None |
|
1629 | self.EXP_CODE = None | |
1622 | self.SUB_EXP_CODE = None |
|
1630 | self.SUB_EXP_CODE = None | |
1623 | self.PLOT_POS = None |
|
1631 | self.PLOT_POS = None | |
1624 |
|
1632 | |||
1625 | def getSubplots(self): |
|
1633 | def getSubplots(self): | |
1626 |
|
1634 | |||
1627 | ncol = 1 |
|
1635 | ncol = 1 | |
1628 | nrow = 1 |
|
1636 | nrow = 1 | |
1629 |
|
1637 | |||
1630 | return nrow, ncol |
|
1638 | return nrow, ncol | |
1631 |
|
1639 | |||
1632 | def openfile(self, filename): |
|
1640 | def openfile(self, filename): | |
1633 | f = open(filename,'w+') |
|
1641 | f = open(filename,'w+') | |
1634 | f.write('\n\n') |
|
1642 | f.write('\n\n') | |
1635 | f.write('JICAMARCA RADIO OBSERVATORY - Noise \n') |
|
1643 | f.write('JICAMARCA RADIO OBSERVATORY - Noise \n') | |
1636 | f.write('DD MM YYYY HH MM SS Channel0 Channel1 Channel2 Channel3\n\n' ) |
|
1644 | f.write('DD MM YYYY HH MM SS Channel0 Channel1 Channel2 Channel3\n\n' ) | |
1637 | f.close() |
|
1645 | f.close() | |
1638 |
|
1646 | |||
1639 | def save_data(self, filename_phase, data, data_datetime): |
|
1647 | def save_data(self, filename_phase, data, data_datetime): | |
1640 | f=open(filename_phase,'a') |
|
1648 | f=open(filename_phase,'a') | |
1641 | timetuple_data = data_datetime.timetuple() |
|
1649 | timetuple_data = data_datetime.timetuple() | |
1642 | day = str(timetuple_data.tm_mday) |
|
1650 | day = str(timetuple_data.tm_mday) | |
1643 | month = str(timetuple_data.tm_mon) |
|
1651 | month = str(timetuple_data.tm_mon) | |
1644 | year = str(timetuple_data.tm_year) |
|
1652 | year = str(timetuple_data.tm_year) | |
1645 | hour = str(timetuple_data.tm_hour) |
|
1653 | hour = str(timetuple_data.tm_hour) | |
1646 | minute = str(timetuple_data.tm_min) |
|
1654 | minute = str(timetuple_data.tm_min) | |
1647 | second = str(timetuple_data.tm_sec) |
|
1655 | second = str(timetuple_data.tm_sec) | |
1648 | f.write(day+' '+month+' '+year+' '+hour+' '+minute+' '+second+' '+str(data[0])+' '+str(data[1])+' '+str(data[2])+' '+str(data[3])+'\n') |
|
1656 | f.write(day+' '+month+' '+year+' '+hour+' '+minute+' '+second+' '+str(data[0])+' '+str(data[1])+' '+str(data[2])+' '+str(data[3])+'\n') | |
1649 | f.close() |
|
1657 | f.close() | |
1650 |
|
1658 | |||
1651 |
|
1659 | |||
1652 | def setup(self, id, nplots, wintitle, showprofile=True, show=True): |
|
1660 | def setup(self, id, nplots, wintitle, showprofile=True, show=True): | |
1653 |
|
1661 | |||
1654 | self.__showprofile = showprofile |
|
1662 | self.__showprofile = showprofile | |
1655 | self.nplots = nplots |
|
1663 | self.nplots = nplots | |
1656 |
|
1664 | |||
1657 | ncolspan = 7 |
|
1665 | ncolspan = 7 | |
1658 | colspan = 6 |
|
1666 | colspan = 6 | |
1659 | self.__nsubplots = 2 |
|
1667 | self.__nsubplots = 2 | |
1660 |
|
1668 | |||
1661 | self.createFigure(id = id, |
|
1669 | self.createFigure(id = id, | |
1662 | wintitle = wintitle, |
|
1670 | wintitle = wintitle, | |
1663 | widthplot = self.WIDTH+self.WIDTHPROF, |
|
1671 | widthplot = self.WIDTH+self.WIDTHPROF, | |
1664 | heightplot = self.HEIGHT+self.HEIGHTPROF, |
|
1672 | heightplot = self.HEIGHT+self.HEIGHTPROF, | |
1665 | show=show) |
|
1673 | show=show) | |
1666 |
|
1674 | |||
1667 | nrow, ncol = self.getSubplots() |
|
1675 | nrow, ncol = self.getSubplots() | |
1668 |
|
1676 | |||
1669 | self.addAxes(nrow, ncol*ncolspan, 0, 0, colspan, 1) |
|
1677 | self.addAxes(nrow, ncol*ncolspan, 0, 0, colspan, 1) | |
1670 |
|
1678 | |||
1671 |
|
1679 | |||
1672 | def run(self, dataOut, id, wintitle="", channelList=None, showprofile='True', |
|
1680 | def run(self, dataOut, id, wintitle="", channelList=None, showprofile='True', | |
1673 | xmin=None, xmax=None, ymin=None, ymax=None, |
|
1681 | xmin=None, xmax=None, ymin=None, ymax=None, | |
1674 | timerange=None, |
|
1682 | timerange=None, | |
1675 | save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1, |
|
1683 | save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1, | |
1676 | server=None, folder=None, username=None, password=None, |
|
1684 | server=None, folder=None, username=None, password=None, | |
1677 | ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0): |
|
1685 | ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0): | |
1678 |
|
1686 | |||
1679 | if channelList == None: |
|
1687 | if channelList == None: | |
1680 | channelIndexList = dataOut.channelIndexList |
|
1688 | channelIndexList = dataOut.channelIndexList | |
1681 | channelList = dataOut.channelList |
|
1689 | channelList = dataOut.channelList | |
1682 | else: |
|
1690 | else: | |
1683 | channelIndexList = [] |
|
1691 | channelIndexList = [] | |
1684 | for channel in channelList: |
|
1692 | for channel in channelList: | |
1685 | if channel not in dataOut.channelList: |
|
1693 | if channel not in dataOut.channelList: | |
1686 | raise ValueError, "Channel %d is not in dataOut.channelList" |
|
1694 | raise ValueError, "Channel %d is not in dataOut.channelList" | |
1687 | channelIndexList.append(dataOut.channelList.index(channel)) |
|
1695 | channelIndexList.append(dataOut.channelList.index(channel)) | |
1688 |
|
1696 | |||
1689 | if timerange != None: |
|
1697 | if timerange != None: | |
1690 | self.timerange = timerange |
|
1698 | self.timerange = timerange | |
1691 |
|
1699 | |||
1692 | tmin = None |
|
1700 | tmin = None | |
1693 | tmax = None |
|
1701 | tmax = None | |
1694 | x = dataOut.getTimeRange() |
|
1702 | x = dataOut.getTimeRange() | |
1695 | y = dataOut.getHeiRange() |
|
1703 | y = dataOut.getHeiRange() | |
1696 | factor = dataOut.normFactor |
|
1704 | factor = dataOut.normFactor | |
1697 | noise = dataOut.getNoise()/factor |
|
1705 | noise = dataOut.getNoise()/factor | |
1698 | noisedB = 10*numpy.log10(noise) |
|
1706 | noisedB = 10*numpy.log10(noise) | |
1699 |
|
1707 | |||
1700 | #thisDatetime = dataOut.datatime |
|
1708 | #thisDatetime = dataOut.datatime | |
1701 | thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[1]) |
|
1709 | thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[1]) | |
1702 | title = wintitle + " Noise" # : %s" %(thisDatetime.strftime("%d-%b-%Y")) |
|
1710 | title = wintitle + " Noise" # : %s" %(thisDatetime.strftime("%d-%b-%Y")) | |
1703 | xlabel = "" |
|
1711 | xlabel = "" | |
1704 | ylabel = "Intensity (dB)" |
|
1712 | ylabel = "Intensity (dB)" | |
1705 |
|
1713 | |||
1706 | if not self.__isConfig: |
|
1714 | if not self.__isConfig: | |
1707 |
|
1715 | |||
1708 | nplots = 1 |
|
1716 | nplots = 1 | |
1709 |
|
1717 | |||
1710 | self.setup(id=id, |
|
1718 | self.setup(id=id, | |
1711 | nplots=nplots, |
|
1719 | nplots=nplots, | |
1712 | wintitle=wintitle, |
|
1720 | wintitle=wintitle, | |
1713 | showprofile=showprofile, |
|
1721 | showprofile=showprofile, | |
1714 | show=show) |
|
1722 | show=show) | |
1715 |
|
1723 | |||
1716 | tmin, tmax = self.getTimeLim(x, xmin, xmax) |
|
1724 | tmin, tmax = self.getTimeLim(x, xmin, xmax) | |
1717 | if ymin == None: ymin = numpy.nanmin(noisedB) - 10.0 |
|
1725 | if ymin == None: ymin = numpy.nanmin(noisedB) - 10.0 | |
1718 | if ymax == None: ymax = numpy.nanmax(noisedB) + 10.0 |
|
1726 | if ymax == None: ymax = numpy.nanmax(noisedB) + 10.0 | |
1719 |
|
1727 | |||
1720 | self.FTP_WEI = ftp_wei |
|
1728 | self.FTP_WEI = ftp_wei | |
1721 | self.EXP_CODE = exp_code |
|
1729 | self.EXP_CODE = exp_code | |
1722 | self.SUB_EXP_CODE = sub_exp_code |
|
1730 | self.SUB_EXP_CODE = sub_exp_code | |
1723 | self.PLOT_POS = plot_pos |
|
1731 | self.PLOT_POS = plot_pos | |
1724 |
|
1732 | |||
1725 |
|
1733 | |||
1726 | self.name = thisDatetime.strftime("%Y%m%d_%H%M%S") |
|
1734 | self.name = thisDatetime.strftime("%Y%m%d_%H%M%S") | |
1727 | self.__isConfig = True |
|
1735 | self.__isConfig = True | |
1728 |
|
1736 | |||
1729 | self.xdata = numpy.array([]) |
|
1737 | self.xdata = numpy.array([]) | |
1730 | self.ydata = numpy.array([]) |
|
1738 | self.ydata = numpy.array([]) | |
1731 |
|
1739 | |||
1732 | #open file beacon phase |
|
1740 | #open file beacon phase | |
1733 | path = '%s%03d' %(self.PREFIX, self.id) |
|
1741 | path = '%s%03d' %(self.PREFIX, self.id) | |
1734 | noise_file = os.path.join(path,'%s.txt'%self.name) |
|
1742 | noise_file = os.path.join(path,'%s.txt'%self.name) | |
1735 | self.filename_noise = os.path.join(figpath,noise_file) |
|
1743 | self.filename_noise = os.path.join(figpath,noise_file) | |
1736 | self.openfile(self.filename_noise) |
|
1744 | self.openfile(self.filename_noise) | |
1737 |
|
1745 | |||
1738 |
|
1746 | |||
1739 | #store data beacon phase |
|
1747 | #store data beacon phase | |
1740 | self.save_data(self.filename_noise, noisedB, thisDatetime) |
|
1748 | self.save_data(self.filename_noise, noisedB, thisDatetime) | |
1741 |
|
1749 | |||
1742 |
|
1750 | |||
1743 | self.setWinTitle(title) |
|
1751 | self.setWinTitle(title) | |
1744 |
|
1752 | |||
1745 |
|
1753 | |||
1746 | title = "Noise %s" %(thisDatetime.strftime("%Y/%m/%d %H:%M:%S")) |
|
1754 | title = "Noise %s" %(thisDatetime.strftime("%Y/%m/%d %H:%M:%S")) | |
1747 |
|
1755 | |||
1748 | legendlabels = ["channel %d"%(idchannel+1) for idchannel in channelList] |
|
1756 | legendlabels = ["channel %d"%(idchannel+1) for idchannel in channelList] | |
1749 | axes = self.axesList[0] |
|
1757 | axes = self.axesList[0] | |
1750 |
|
1758 | |||
1751 | self.xdata = numpy.hstack((self.xdata, x[0:1])) |
|
1759 | self.xdata = numpy.hstack((self.xdata, x[0:1])) | |
1752 |
|
1760 | |||
1753 | if len(self.ydata)==0: |
|
1761 | if len(self.ydata)==0: | |
1754 | self.ydata = noisedB[channelIndexList].reshape(-1,1) |
|
1762 | self.ydata = noisedB[channelIndexList].reshape(-1,1) | |
1755 | else: |
|
1763 | else: | |
1756 | self.ydata = numpy.hstack((self.ydata, noisedB[channelIndexList].reshape(-1,1))) |
|
1764 | self.ydata = numpy.hstack((self.ydata, noisedB[channelIndexList].reshape(-1,1))) | |
1757 |
|
1765 | |||
1758 |
|
1766 | |||
1759 | axes.pmultilineyaxis(x=self.xdata, y=self.ydata, |
|
1767 | axes.pmultilineyaxis(x=self.xdata, y=self.ydata, | |
1760 | xmin=tmin, xmax=tmax, ymin=ymin, ymax=ymax, |
|
1768 | xmin=tmin, xmax=tmax, ymin=ymin, ymax=ymax, | |
1761 | xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels, marker='x', markersize=8, linestyle="solid", |
|
1769 | xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels, marker='x', markersize=8, linestyle="solid", | |
1762 | XAxisAsTime=True, grid='both' |
|
1770 | XAxisAsTime=True, grid='both' | |
1763 | ) |
|
1771 | ) | |
1764 |
|
1772 | |||
1765 | self.draw() |
|
1773 | self.draw() | |
1766 |
|
1774 | |||
1767 | # if save: |
|
1775 | # if save: | |
1768 | # |
|
1776 | # | |
1769 | # if figfile == None: |
|
1777 | # if figfile == None: | |
1770 | # figfile = self.getFilename(name = self.name) |
|
1778 | # figfile = self.getFilename(name = self.name) | |
1771 | # |
|
1779 | # | |
1772 | # self.saveFigure(figpath, figfile) |
|
1780 | # self.saveFigure(figpath, figfile) | |
1773 |
|
1781 | |||
1774 | if save: |
|
1782 | if save: | |
1775 |
|
1783 | |||
1776 | self.counter_imagwr += 1 |
|
1784 | self.counter_imagwr += 1 | |
1777 | if (self.counter_imagwr==wr_period): |
|
1785 | if (self.counter_imagwr==wr_period): | |
1778 | if figfile == None: |
|
1786 | if figfile == None: | |
1779 | figfile = self.getFilename(name = self.name) |
|
1787 | figfile = self.getFilename(name = self.name) | |
1780 | self.saveFigure(figpath, figfile) |
|
1788 | self.saveFigure(figpath, figfile) | |
1781 |
|
1789 | |||
1782 | if ftp: |
|
1790 | if ftp: | |
1783 | #provisionalmente envia archivos en el formato de la web en tiempo real |
|
1791 | #provisionalmente envia archivos en el formato de la web en tiempo real | |
1784 | name = self.getNameToFtp(thisDatetime, self.FTP_WEI, self.EXP_CODE, self.SUB_EXP_CODE, self.PLOT_CODE, self.PLOT_POS) |
|
1792 | name = self.getNameToFtp(thisDatetime, self.FTP_WEI, self.EXP_CODE, self.SUB_EXP_CODE, self.PLOT_CODE, self.PLOT_POS) | |
1785 | path = '%s%03d' %(self.PREFIX, self.id) |
|
1793 | path = '%s%03d' %(self.PREFIX, self.id) | |
1786 | ftp_file = os.path.join(path,'ftp','%s.png'%name) |
|
1794 | ftp_file = os.path.join(path,'ftp','%s.png'%name) | |
1787 | self.saveFigure(figpath, ftp_file) |
|
1795 | self.saveFigure(figpath, ftp_file) | |
1788 | ftp_filename = os.path.join(figpath,ftp_file) |
|
1796 | ftp_filename = os.path.join(figpath,ftp_file) | |
1789 | self.sendByFTP_Thread(ftp_filename, server, folder, username, password) |
|
1797 | self.sendByFTP_Thread(ftp_filename, server, folder, username, password) | |
1790 | self.counter_imagwr = 0 |
|
1798 | self.counter_imagwr = 0 | |
1791 |
|
1799 | |||
1792 | self.counter_imagwr = 0 |
|
1800 | self.counter_imagwr = 0 | |
1793 |
|
1801 | |||
1794 | if x[1] + (x[1]-x[0]) >= self.axesList[0].xmax: |
|
1802 | if x[1] + (x[1]-x[0]) >= self.axesList[0].xmax: | |
1795 | self.__isConfig = False |
|
1803 | self.__isConfig = False | |
1796 | del self.xdata |
|
1804 | del self.xdata | |
1797 | del self.ydata |
|
1805 | del self.ydata | |
1798 |
|
1806 | |||
1799 |
|
1807 | |||
1800 | class SpectraHeisScope(Figure): |
|
1808 | class SpectraHeisScope(Figure): | |
1801 |
|
1809 | |||
1802 |
|
1810 | |||
1803 | __isConfig = None |
|
1811 | __isConfig = None | |
1804 | __nsubplots = None |
|
1812 | __nsubplots = None | |
1805 |
|
1813 | |||
1806 | WIDTHPROF = None |
|
1814 | WIDTHPROF = None | |
1807 | HEIGHTPROF = None |
|
1815 | HEIGHTPROF = None | |
1808 | PREFIX = 'spc' |
|
1816 | PREFIX = 'spc' | |
1809 |
|
1817 | |||
1810 | def __init__(self): |
|
1818 | def __init__(self): | |
1811 |
|
1819 | |||
1812 | self.__isConfig = False |
|
1820 | self.__isConfig = False | |
1813 | self.__nsubplots = 1 |
|
1821 | self.__nsubplots = 1 | |
1814 |
|
1822 | |||
1815 | self.WIDTH = 230 |
|
1823 | self.WIDTH = 230 | |
1816 | self.HEIGHT = 250 |
|
1824 | self.HEIGHT = 250 | |
1817 | self.WIDTHPROF = 120 |
|
1825 | self.WIDTHPROF = 120 | |
1818 | self.HEIGHTPROF = 0 |
|
1826 | self.HEIGHTPROF = 0 | |
1819 | self.counter_imagwr = 0 |
|
1827 | self.counter_imagwr = 0 | |
1820 |
|
1828 | |||
1821 | def getSubplots(self): |
|
1829 | def getSubplots(self): | |
1822 |
|
1830 | |||
1823 | ncol = int(numpy.sqrt(self.nplots)+0.9) |
|
1831 | ncol = int(numpy.sqrt(self.nplots)+0.9) | |
1824 | nrow = int(self.nplots*1./ncol + 0.9) |
|
1832 | nrow = int(self.nplots*1./ncol + 0.9) | |
1825 |
|
1833 | |||
1826 | return nrow, ncol |
|
1834 | return nrow, ncol | |
1827 |
|
1835 | |||
1828 | def setup(self, id, nplots, wintitle, show): |
|
1836 | def setup(self, id, nplots, wintitle, show): | |
1829 |
|
1837 | |||
1830 | showprofile = False |
|
1838 | showprofile = False | |
1831 | self.__showprofile = showprofile |
|
1839 | self.__showprofile = showprofile | |
1832 | self.nplots = nplots |
|
1840 | self.nplots = nplots | |
1833 |
|
1841 | |||
1834 | ncolspan = 1 |
|
1842 | ncolspan = 1 | |
1835 | colspan = 1 |
|
1843 | colspan = 1 | |
1836 | if showprofile: |
|
1844 | if showprofile: | |
1837 | ncolspan = 3 |
|
1845 | ncolspan = 3 | |
1838 | colspan = 2 |
|
1846 | colspan = 2 | |
1839 | self.__nsubplots = 2 |
|
1847 | self.__nsubplots = 2 | |
1840 |
|
1848 | |||
1841 | self.createFigure(id = id, |
|
1849 | self.createFigure(id = id, | |
1842 | wintitle = wintitle, |
|
1850 | wintitle = wintitle, | |
1843 | widthplot = self.WIDTH + self.WIDTHPROF, |
|
1851 | widthplot = self.WIDTH + self.WIDTHPROF, | |
1844 | heightplot = self.HEIGHT + self.HEIGHTPROF, |
|
1852 | heightplot = self.HEIGHT + self.HEIGHTPROF, | |
1845 | show = show) |
|
1853 | show = show) | |
1846 |
|
1854 | |||
1847 | nrow, ncol = self.getSubplots() |
|
1855 | nrow, ncol = self.getSubplots() | |
1848 |
|
1856 | |||
1849 | counter = 0 |
|
1857 | counter = 0 | |
1850 | for y in range(nrow): |
|
1858 | for y in range(nrow): | |
1851 | for x in range(ncol): |
|
1859 | for x in range(ncol): | |
1852 |
|
1860 | |||
1853 | if counter >= self.nplots: |
|
1861 | if counter >= self.nplots: | |
1854 | break |
|
1862 | break | |
1855 |
|
1863 | |||
1856 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1) |
|
1864 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1) | |
1857 |
|
1865 | |||
1858 | if showprofile: |
|
1866 | if showprofile: | |
1859 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1) |
|
1867 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1) | |
1860 |
|
1868 | |||
1861 | counter += 1 |
|
1869 | counter += 1 | |
1862 |
|
1870 | |||
1863 |
|
1871 | |||
1864 | def run(self, dataOut, id, wintitle="", channelList=None, |
|
1872 | def run(self, dataOut, id, wintitle="", channelList=None, | |
1865 | xmin=None, xmax=None, ymin=None, ymax=None, save=False, |
|
1873 | xmin=None, xmax=None, ymin=None, ymax=None, save=False, | |
1866 | figpath='./', figfile=None, ftp=False, wr_period=1, show=True, |
|
1874 | figpath='./', figfile=None, ftp=False, wr_period=1, show=True, | |
1867 | server=None, folder=None, username=None, password=None): |
|
1875 | server=None, folder=None, username=None, password=None): | |
1868 |
|
1876 | |||
1869 | """ |
|
1877 | """ | |
1870 |
|
1878 | |||
1871 | Input: |
|
1879 | Input: | |
1872 | dataOut : |
|
1880 | dataOut : | |
1873 | id : |
|
1881 | id : | |
1874 | wintitle : |
|
1882 | wintitle : | |
1875 | channelList : |
|
1883 | channelList : | |
1876 | xmin : None, |
|
1884 | xmin : None, | |
1877 | xmax : None, |
|
1885 | xmax : None, | |
1878 | ymin : None, |
|
1886 | ymin : None, | |
1879 | ymax : None, |
|
1887 | ymax : None, | |
1880 | """ |
|
1888 | """ | |
1881 |
|
1889 | |||
1882 | if dataOut.realtime: |
|
1890 | if dataOut.realtime: | |
1883 | if not(isRealtime(utcdatatime = dataOut.utctime)): |
|
1891 | if not(isRealtime(utcdatatime = dataOut.utctime)): | |
1884 | print 'Skipping this plot function' |
|
1892 | print 'Skipping this plot function' | |
1885 | return |
|
1893 | return | |
1886 |
|
1894 | |||
1887 | if channelList == None: |
|
1895 | if channelList == None: | |
1888 | channelIndexList = dataOut.channelIndexList |
|
1896 | channelIndexList = dataOut.channelIndexList | |
1889 | else: |
|
1897 | else: | |
1890 | channelIndexList = [] |
|
1898 | channelIndexList = [] | |
1891 | for channel in channelList: |
|
1899 | for channel in channelList: | |
1892 | if channel not in dataOut.channelList: |
|
1900 | if channel not in dataOut.channelList: | |
1893 | raise ValueError, "Channel %d is not in dataOut.channelList" |
|
1901 | raise ValueError, "Channel %d is not in dataOut.channelList" | |
1894 | channelIndexList.append(dataOut.channelList.index(channel)) |
|
1902 | channelIndexList.append(dataOut.channelList.index(channel)) | |
1895 |
|
1903 | |||
1896 | # x = dataOut.heightList |
|
1904 | # x = dataOut.heightList | |
1897 | c = 3E8 |
|
1905 | c = 3E8 | |
1898 | deltaHeight = dataOut.heightList[1] - dataOut.heightList[0] |
|
1906 | deltaHeight = dataOut.heightList[1] - dataOut.heightList[0] | |
1899 | #deberia cambiar para el caso de 1Mhz y 100KHz |
|
1907 | #deberia cambiar para el caso de 1Mhz y 100KHz | |
1900 | x = numpy.arange(-1*dataOut.nHeights/2.,dataOut.nHeights/2.)*(c/(2*deltaHeight*dataOut.nHeights*1000)) |
|
1908 | x = numpy.arange(-1*dataOut.nHeights/2.,dataOut.nHeights/2.)*(c/(2*deltaHeight*dataOut.nHeights*1000)) | |
1901 | #para 1Mhz descomentar la siguiente linea |
|
1909 | #para 1Mhz descomentar la siguiente linea | |
1902 | #x= x/(10000.0) |
|
1910 | #x= x/(10000.0) | |
1903 | # y = dataOut.data[channelIndexList,:] * numpy.conjugate(dataOut.data[channelIndexList,:]) |
|
1911 | # y = dataOut.data[channelIndexList,:] * numpy.conjugate(dataOut.data[channelIndexList,:]) | |
1904 | # y = y.real |
|
1912 | # y = y.real | |
1905 | datadB = 10.*numpy.log10(dataOut.data_spc) |
|
1913 | datadB = 10.*numpy.log10(dataOut.data_spc) | |
1906 | y = datadB |
|
1914 | y = datadB | |
1907 |
|
1915 | |||
1908 | #thisDatetime = dataOut.datatime |
|
1916 | #thisDatetime = dataOut.datatime | |
1909 | thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[1]) |
|
1917 | thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[1]) | |
1910 | title = wintitle + " Scope: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) |
|
1918 | title = wintitle + " Scope: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) | |
1911 | xlabel = "" |
|
1919 | xlabel = "" | |
1912 | #para 1Mhz descomentar la siguiente linea |
|
1920 | #para 1Mhz descomentar la siguiente linea | |
1913 | #xlabel = "Frequency x 10000" |
|
1921 | #xlabel = "Frequency x 10000" | |
1914 | ylabel = "Intensity (dB)" |
|
1922 | ylabel = "Intensity (dB)" | |
1915 |
|
1923 | |||
1916 | if not self.__isConfig: |
|
1924 | if not self.__isConfig: | |
1917 | nplots = len(channelIndexList) |
|
1925 | nplots = len(channelIndexList) | |
1918 |
|
1926 | |||
1919 | self.setup(id=id, |
|
1927 | self.setup(id=id, | |
1920 | nplots=nplots, |
|
1928 | nplots=nplots, | |
1921 | wintitle=wintitle, |
|
1929 | wintitle=wintitle, | |
1922 | show=show) |
|
1930 | show=show) | |
1923 |
|
1931 | |||
1924 | if xmin == None: xmin = numpy.nanmin(x) |
|
1932 | if xmin == None: xmin = numpy.nanmin(x) | |
1925 | if xmax == None: xmax = numpy.nanmax(x) |
|
1933 | if xmax == None: xmax = numpy.nanmax(x) | |
1926 | if ymin == None: ymin = numpy.nanmin(y) |
|
1934 | if ymin == None: ymin = numpy.nanmin(y) | |
1927 | if ymax == None: ymax = numpy.nanmax(y) |
|
1935 | if ymax == None: ymax = numpy.nanmax(y) | |
1928 |
|
1936 | |||
1929 | self.__isConfig = True |
|
1937 | self.__isConfig = True | |
1930 |
|
1938 | |||
1931 | self.setWinTitle(title) |
|
1939 | self.setWinTitle(title) | |
1932 |
|
1940 | |||
1933 | for i in range(len(self.axesList)): |
|
1941 | for i in range(len(self.axesList)): | |
1934 | ychannel = y[i,:] |
|
1942 | ychannel = y[i,:] | |
1935 | str_datetime = '%s %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S")) |
|
1943 | str_datetime = '%s %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S")) | |
1936 | title = "Channel %d: %4.2fdB: %s" %(i, numpy.max(ychannel), str_datetime) |
|
1944 | title = "Channel %d: %4.2fdB: %s" %(i, numpy.max(ychannel), str_datetime) | |
1937 | axes = self.axesList[i] |
|
1945 | axes = self.axesList[i] | |
1938 | axes.pline(x, ychannel, |
|
1946 | axes.pline(x, ychannel, | |
1939 | xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, |
|
1947 | xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, | |
1940 | xlabel=xlabel, ylabel=ylabel, title=title, grid='both') |
|
1948 | xlabel=xlabel, ylabel=ylabel, title=title, grid='both') | |
1941 |
|
1949 | |||
1942 |
|
1950 | |||
1943 | self.draw() |
|
1951 | self.draw() | |
1944 |
|
1952 | |||
1945 | if save: |
|
1953 | if save: | |
1946 | date = thisDatetime.strftime("%Y%m%d_%H%M%S") |
|
1954 | date = thisDatetime.strftime("%Y%m%d_%H%M%S") | |
1947 | if figfile == None: |
|
1955 | if figfile == None: | |
1948 | figfile = self.getFilename(name = date) |
|
1956 | figfile = self.getFilename(name = date) | |
1949 |
|
1957 | |||
1950 | self.saveFigure(figpath, figfile) |
|
1958 | self.saveFigure(figpath, figfile) | |
1951 |
|
1959 | |||
1952 | self.counter_imagwr += 1 |
|
1960 | self.counter_imagwr += 1 | |
1953 | if (ftp and (self.counter_imagwr==wr_period)): |
|
1961 | if (ftp and (self.counter_imagwr==wr_period)): | |
1954 | ftp_filename = os.path.join(figpath,figfile) |
|
1962 | ftp_filename = os.path.join(figpath,figfile) | |
1955 | self.sendByFTP_Thread(ftp_filename, server, folder, username, password) |
|
1963 | self.sendByFTP_Thread(ftp_filename, server, folder, username, password) | |
1956 | self.counter_imagwr = 0 |
|
1964 | self.counter_imagwr = 0 | |
1957 |
|
1965 | |||
1958 |
|
1966 | |||
1959 | class RTIfromSpectraHeis(Figure): |
|
1967 | class RTIfromSpectraHeis(Figure): | |
1960 |
|
1968 | |||
1961 | __isConfig = None |
|
1969 | __isConfig = None | |
1962 | __nsubplots = None |
|
1970 | __nsubplots = None | |
1963 |
|
1971 | |||
1964 | PREFIX = 'rtinoise' |
|
1972 | PREFIX = 'rtinoise' | |
1965 |
|
1973 | |||
1966 | def __init__(self): |
|
1974 | def __init__(self): | |
1967 |
|
1975 | |||
1968 | self.timerange = 24*60*60 |
|
1976 | self.timerange = 24*60*60 | |
1969 | self.__isConfig = False |
|
1977 | self.__isConfig = False | |
1970 | self.__nsubplots = 1 |
|
1978 | self.__nsubplots = 1 | |
1971 |
|
1979 | |||
1972 | self.WIDTH = 820 |
|
1980 | self.WIDTH = 820 | |
1973 | self.HEIGHT = 200 |
|
1981 | self.HEIGHT = 200 | |
1974 | self.WIDTHPROF = 120 |
|
1982 | self.WIDTHPROF = 120 | |
1975 | self.HEIGHTPROF = 0 |
|
1983 | self.HEIGHTPROF = 0 | |
1976 | self.counter_imagwr = 0 |
|
1984 | self.counter_imagwr = 0 | |
1977 | self.xdata = None |
|
1985 | self.xdata = None | |
1978 | self.ydata = None |
|
1986 | self.ydata = None | |
1979 |
|
1987 | |||
1980 | def getSubplots(self): |
|
1988 | def getSubplots(self): | |
1981 |
|
1989 | |||
1982 | ncol = 1 |
|
1990 | ncol = 1 | |
1983 | nrow = 1 |
|
1991 | nrow = 1 | |
1984 |
|
1992 | |||
1985 | return nrow, ncol |
|
1993 | return nrow, ncol | |
1986 |
|
1994 | |||
1987 | def setup(self, id, nplots, wintitle, showprofile=True, show=True): |
|
1995 | def setup(self, id, nplots, wintitle, showprofile=True, show=True): | |
1988 |
|
1996 | |||
1989 | self.__showprofile = showprofile |
|
1997 | self.__showprofile = showprofile | |
1990 | self.nplots = nplots |
|
1998 | self.nplots = nplots | |
1991 |
|
1999 | |||
1992 | ncolspan = 7 |
|
2000 | ncolspan = 7 | |
1993 | colspan = 6 |
|
2001 | colspan = 6 | |
1994 | self.__nsubplots = 2 |
|
2002 | self.__nsubplots = 2 | |
1995 |
|
2003 | |||
1996 | self.createFigure(id = id, |
|
2004 | self.createFigure(id = id, | |
1997 | wintitle = wintitle, |
|
2005 | wintitle = wintitle, | |
1998 | widthplot = self.WIDTH+self.WIDTHPROF, |
|
2006 | widthplot = self.WIDTH+self.WIDTHPROF, | |
1999 | heightplot = self.HEIGHT+self.HEIGHTPROF, |
|
2007 | heightplot = self.HEIGHT+self.HEIGHTPROF, | |
2000 | show = show) |
|
2008 | show = show) | |
2001 |
|
2009 | |||
2002 | nrow, ncol = self.getSubplots() |
|
2010 | nrow, ncol = self.getSubplots() | |
2003 |
|
2011 | |||
2004 | self.addAxes(nrow, ncol*ncolspan, 0, 0, colspan, 1) |
|
2012 | self.addAxes(nrow, ncol*ncolspan, 0, 0, colspan, 1) | |
2005 |
|
2013 | |||
2006 |
|
2014 | |||
2007 | def run(self, dataOut, id, wintitle="", channelList=None, showprofile='True', |
|
2015 | def run(self, dataOut, id, wintitle="", channelList=None, showprofile='True', | |
2008 | xmin=None, xmax=None, ymin=None, ymax=None, |
|
2016 | xmin=None, xmax=None, ymin=None, ymax=None, | |
2009 | timerange=None, |
|
2017 | timerange=None, | |
2010 | save=False, figpath='./', figfile=None, ftp=False, wr_period=1, show=True, |
|
2018 | save=False, figpath='./', figfile=None, ftp=False, wr_period=1, show=True, | |
2011 | server=None, folder=None, username=None, password=None): |
|
2019 | server=None, folder=None, username=None, password=None): | |
2012 |
|
2020 | |||
2013 | if channelList == None: |
|
2021 | if channelList == None: | |
2014 | channelIndexList = dataOut.channelIndexList |
|
2022 | channelIndexList = dataOut.channelIndexList | |
2015 | channelList = dataOut.channelList |
|
2023 | channelList = dataOut.channelList | |
2016 | else: |
|
2024 | else: | |
2017 | channelIndexList = [] |
|
2025 | channelIndexList = [] | |
2018 | for channel in channelList: |
|
2026 | for channel in channelList: | |
2019 | if channel not in dataOut.channelList: |
|
2027 | if channel not in dataOut.channelList: | |
2020 | raise ValueError, "Channel %d is not in dataOut.channelList" |
|
2028 | raise ValueError, "Channel %d is not in dataOut.channelList" | |
2021 | channelIndexList.append(dataOut.channelList.index(channel)) |
|
2029 | channelIndexList.append(dataOut.channelList.index(channel)) | |
2022 |
|
2030 | |||
2023 | if timerange != None: |
|
2031 | if timerange != None: | |
2024 | self.timerange = timerange |
|
2032 | self.timerange = timerange | |
2025 |
|
2033 | |||
2026 | tmin = None |
|
2034 | tmin = None | |
2027 | tmax = None |
|
2035 | tmax = None | |
2028 | x = dataOut.getTimeRange() |
|
2036 | x = dataOut.getTimeRange() | |
2029 | y = dataOut.getHeiRange() |
|
2037 | y = dataOut.getHeiRange() | |
2030 |
|
2038 | |||
2031 | #factor = 1 |
|
2039 | #factor = 1 | |
2032 | data = dataOut.data_spc#/factor |
|
2040 | data = dataOut.data_spc#/factor | |
2033 | data = numpy.average(data,axis=1) |
|
2041 | data = numpy.average(data,axis=1) | |
2034 | datadB = 10*numpy.log10(data) |
|
2042 | datadB = 10*numpy.log10(data) | |
2035 |
|
2043 | |||
2036 | # factor = dataOut.normFactor |
|
2044 | # factor = dataOut.normFactor | |
2037 | # noise = dataOut.getNoise()/factor |
|
2045 | # noise = dataOut.getNoise()/factor | |
2038 | # noisedB = 10*numpy.log10(noise) |
|
2046 | # noisedB = 10*numpy.log10(noise) | |
2039 |
|
2047 | |||
2040 | #thisDatetime = dataOut.datatime |
|
2048 | #thisDatetime = dataOut.datatime | |
2041 | thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[1]) |
|
2049 | thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[1]) | |
2042 | title = wintitle + " RTI: %s" %(thisDatetime.strftime("%d-%b-%Y")) |
|
2050 | title = wintitle + " RTI: %s" %(thisDatetime.strftime("%d-%b-%Y")) | |
2043 | xlabel = "Local Time" |
|
2051 | xlabel = "Local Time" | |
2044 | ylabel = "Intensity (dB)" |
|
2052 | ylabel = "Intensity (dB)" | |
2045 |
|
2053 | |||
2046 | if not self.__isConfig: |
|
2054 | if not self.__isConfig: | |
2047 |
|
2055 | |||
2048 | nplots = 1 |
|
2056 | nplots = 1 | |
2049 |
|
2057 | |||
2050 | self.setup(id=id, |
|
2058 | self.setup(id=id, | |
2051 | nplots=nplots, |
|
2059 | nplots=nplots, | |
2052 | wintitle=wintitle, |
|
2060 | wintitle=wintitle, | |
2053 | showprofile=showprofile, |
|
2061 | showprofile=showprofile, | |
2054 | show=show) |
|
2062 | show=show) | |
2055 |
|
2063 | |||
2056 | tmin, tmax = self.getTimeLim(x, xmin, xmax) |
|
2064 | tmin, tmax = self.getTimeLim(x, xmin, xmax) | |
2057 | if ymin == None: ymin = numpy.nanmin(datadB) |
|
2065 | if ymin == None: ymin = numpy.nanmin(datadB) | |
2058 | if ymax == None: ymax = numpy.nanmax(datadB) |
|
2066 | if ymax == None: ymax = numpy.nanmax(datadB) | |
2059 |
|
2067 | |||
2060 | self.name = thisDatetime.strftime("%Y%m%d_%H%M%S") |
|
2068 | self.name = thisDatetime.strftime("%Y%m%d_%H%M%S") | |
2061 | self.__isConfig = True |
|
2069 | self.__isConfig = True | |
2062 |
|
2070 | |||
2063 | self.xdata = numpy.array([]) |
|
2071 | self.xdata = numpy.array([]) | |
2064 | self.ydata = numpy.array([]) |
|
2072 | self.ydata = numpy.array([]) | |
2065 |
|
2073 | |||
2066 | self.setWinTitle(title) |
|
2074 | self.setWinTitle(title) | |
2067 |
|
2075 | |||
2068 |
|
2076 | |||
2069 | # title = "RTI %s" %(thisDatetime.strftime("%d-%b-%Y")) |
|
2077 | # title = "RTI %s" %(thisDatetime.strftime("%d-%b-%Y")) | |
2070 | title = "RTI - %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) |
|
2078 | title = "RTI - %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) | |
2071 |
|
2079 | |||
2072 | legendlabels = ["channel %d"%idchannel for idchannel in channelList] |
|
2080 | legendlabels = ["channel %d"%idchannel for idchannel in channelList] | |
2073 | axes = self.axesList[0] |
|
2081 | axes = self.axesList[0] | |
2074 |
|
2082 | |||
2075 | self.xdata = numpy.hstack((self.xdata, x[0:1])) |
|
2083 | self.xdata = numpy.hstack((self.xdata, x[0:1])) | |
2076 |
|
2084 | |||
2077 | if len(self.ydata)==0: |
|
2085 | if len(self.ydata)==0: | |
2078 | self.ydata = datadB[channelIndexList].reshape(-1,1) |
|
2086 | self.ydata = datadB[channelIndexList].reshape(-1,1) | |
2079 | else: |
|
2087 | else: | |
2080 | self.ydata = numpy.hstack((self.ydata, datadB[channelIndexList].reshape(-1,1))) |
|
2088 | self.ydata = numpy.hstack((self.ydata, datadB[channelIndexList].reshape(-1,1))) | |
2081 |
|
2089 | |||
2082 |
|
2090 | |||
2083 | axes.pmultilineyaxis(x=self.xdata, y=self.ydata, |
|
2091 | axes.pmultilineyaxis(x=self.xdata, y=self.ydata, | |
2084 | xmin=tmin, xmax=tmax, ymin=ymin, ymax=ymax, |
|
2092 | xmin=tmin, xmax=tmax, ymin=ymin, ymax=ymax, | |
2085 | xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels, marker='.', markersize=8, linestyle="solid", grid='both', |
|
2093 | xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels, marker='.', markersize=8, linestyle="solid", grid='both', | |
2086 | XAxisAsTime=True |
|
2094 | XAxisAsTime=True | |
2087 | ) |
|
2095 | ) | |
2088 |
|
2096 | |||
2089 | self.draw() |
|
2097 | self.draw() | |
2090 |
|
2098 | |||
2091 | if save: |
|
2099 | if save: | |
2092 |
|
2100 | |||
2093 | if figfile == None: |
|
2101 | if figfile == None: | |
2094 | figfile = self.getFilename(name = self.name) |
|
2102 | figfile = self.getFilename(name = self.name) | |
2095 |
|
2103 | |||
2096 | self.saveFigure(figpath, figfile) |
|
2104 | self.saveFigure(figpath, figfile) | |
2097 |
|
2105 | |||
2098 | self.counter_imagwr += 1 |
|
2106 | self.counter_imagwr += 1 | |
2099 | if (ftp and (self.counter_imagwr==wr_period)): |
|
2107 | if (ftp and (self.counter_imagwr==wr_period)): | |
2100 | ftp_filename = os.path.join(figpath,figfile) |
|
2108 | ftp_filename = os.path.join(figpath,figfile) | |
2101 | self.sendByFTP_Thread(ftp_filename, server, folder, username, password) |
|
2109 | self.sendByFTP_Thread(ftp_filename, server, folder, username, password) | |
2102 | self.counter_imagwr = 0 |
|
2110 | self.counter_imagwr = 0 | |
2103 |
|
2111 | |||
2104 | if x[1] + (x[1]-x[0]) >= self.axesList[0].xmax: |
|
2112 | if x[1] + (x[1]-x[0]) >= self.axesList[0].xmax: | |
2105 | self.__isConfig = False |
|
2113 | self.__isConfig = False | |
2106 | del self.xdata |
|
2114 | del self.xdata | |
2107 | del self.ydata |
|
2115 | del self.ydata | |
2108 |
|
2116 | |||
2109 |
|
2117 | |||
2110 | No newline at end of file |
|
2118 |
@@ -1,2066 +1,2070 | |||||
1 | ''' |
|
1 | ''' | |
2 |
|
2 | |||
3 | $Author: dsuarez $ |
|
3 | $Author: dsuarez $ | |
4 | $Id: Processor.py 1 2012-11-12 18:56:07Z dsuarez $ |
|
4 | $Id: Processor.py 1 2012-11-12 18:56:07Z dsuarez $ | |
5 | ''' |
|
5 | ''' | |
6 | import os |
|
6 | import os | |
7 | import numpy |
|
7 | import numpy | |
8 | import datetime |
|
8 | import datetime | |
9 | import time |
|
9 | import time | |
10 | import math |
|
10 | import math | |
11 | from jrodata import * |
|
11 | from jrodata import * | |
12 | from jrodataIO import * |
|
12 | from jrodataIO import * | |
13 | from jroplot import * |
|
13 | from jroplot import * | |
14 |
|
14 | |||
15 | try: |
|
15 | try: | |
16 | import cfunctions |
|
16 | import cfunctions | |
17 | except: |
|
17 | except: | |
18 | pass |
|
18 | pass | |
19 |
|
19 | |||
20 | class ProcessingUnit: |
|
20 | class ProcessingUnit: | |
21 |
|
21 | |||
22 | """ |
|
22 | """ | |
23 | Esta es la clase base para el procesamiento de datos. |
|
23 | Esta es la clase base para el procesamiento de datos. | |
24 |
|
24 | |||
25 | Contiene el metodo "call" para llamar operaciones. Las operaciones pueden ser: |
|
25 | Contiene el metodo "call" para llamar operaciones. Las operaciones pueden ser: | |
26 | - Metodos internos (callMethod) |
|
26 | - Metodos internos (callMethod) | |
27 | - Objetos del tipo Operation (callObject). Antes de ser llamados, estos objetos |
|
27 | - Objetos del tipo Operation (callObject). Antes de ser llamados, estos objetos | |
28 | tienen que ser agreagados con el metodo "add". |
|
28 | tienen que ser agreagados con el metodo "add". | |
29 |
|
29 | |||
30 | """ |
|
30 | """ | |
31 | # objeto de datos de entrada (Voltage, Spectra o Correlation) |
|
31 | # objeto de datos de entrada (Voltage, Spectra o Correlation) | |
32 | dataIn = None |
|
32 | dataIn = None | |
33 |
|
33 | |||
34 | # objeto de datos de entrada (Voltage, Spectra o Correlation) |
|
34 | # objeto de datos de entrada (Voltage, Spectra o Correlation) | |
35 | dataOut = None |
|
35 | dataOut = None | |
36 |
|
36 | |||
37 |
|
37 | |||
38 | objectDict = None |
|
38 | objectDict = None | |
39 |
|
39 | |||
40 | def __init__(self): |
|
40 | def __init__(self): | |
41 |
|
41 | |||
42 | self.objectDict = {} |
|
42 | self.objectDict = {} | |
43 |
|
43 | |||
44 | def init(self): |
|
44 | def init(self): | |
45 |
|
45 | |||
46 | raise ValueError, "Not implemented" |
|
46 | raise ValueError, "Not implemented" | |
47 |
|
47 | |||
48 | def addOperation(self, object, objId): |
|
48 | def addOperation(self, object, objId): | |
49 |
|
49 | |||
50 | """ |
|
50 | """ | |
51 | Agrega el objeto "object" a la lista de objetos "self.objectList" y retorna el |
|
51 | Agrega el objeto "object" a la lista de objetos "self.objectList" y retorna el | |
52 | identificador asociado a este objeto. |
|
52 | identificador asociado a este objeto. | |
53 |
|
53 | |||
54 | Input: |
|
54 | Input: | |
55 |
|
55 | |||
56 | object : objeto de la clase "Operation" |
|
56 | object : objeto de la clase "Operation" | |
57 |
|
57 | |||
58 | Return: |
|
58 | Return: | |
59 |
|
59 | |||
60 | objId : identificador del objeto, necesario para ejecutar la operacion |
|
60 | objId : identificador del objeto, necesario para ejecutar la operacion | |
61 | """ |
|
61 | """ | |
62 |
|
62 | |||
63 | self.objectDict[objId] = object |
|
63 | self.objectDict[objId] = object | |
64 |
|
64 | |||
65 | return objId |
|
65 | return objId | |
66 |
|
66 | |||
67 | def operation(self, **kwargs): |
|
67 | def operation(self, **kwargs): | |
68 |
|
68 | |||
69 | """ |
|
69 | """ | |
70 | Operacion directa sobre la data (dataOut.data). Es necesario actualizar los valores de los |
|
70 | Operacion directa sobre la data (dataOut.data). Es necesario actualizar los valores de los | |
71 | atributos del objeto dataOut |
|
71 | atributos del objeto dataOut | |
72 |
|
72 | |||
73 | Input: |
|
73 | Input: | |
74 |
|
74 | |||
75 | **kwargs : Diccionario de argumentos de la funcion a ejecutar |
|
75 | **kwargs : Diccionario de argumentos de la funcion a ejecutar | |
76 | """ |
|
76 | """ | |
77 |
|
77 | |||
78 | raise ValueError, "ImplementedError" |
|
78 | raise ValueError, "ImplementedError" | |
79 |
|
79 | |||
80 | def callMethod(self, name, **kwargs): |
|
80 | def callMethod(self, name, **kwargs): | |
81 |
|
81 | |||
82 | """ |
|
82 | """ | |
83 | Ejecuta el metodo con el nombre "name" y con argumentos **kwargs de la propia clase. |
|
83 | Ejecuta el metodo con el nombre "name" y con argumentos **kwargs de la propia clase. | |
84 |
|
84 | |||
85 | Input: |
|
85 | Input: | |
86 | name : nombre del metodo a ejecutar |
|
86 | name : nombre del metodo a ejecutar | |
87 |
|
87 | |||
88 | **kwargs : diccionario con los nombres y valores de la funcion a ejecutar. |
|
88 | **kwargs : diccionario con los nombres y valores de la funcion a ejecutar. | |
89 |
|
89 | |||
90 | """ |
|
90 | """ | |
91 | if name != 'run': |
|
91 | if name != 'run': | |
92 |
|
92 | |||
93 | if name == 'init' and self.dataIn.isEmpty(): |
|
93 | if name == 'init' and self.dataIn.isEmpty(): | |
94 | self.dataOut.flagNoData = True |
|
94 | self.dataOut.flagNoData = True | |
95 | return False |
|
95 | return False | |
96 |
|
96 | |||
97 | if name != 'init' and self.dataOut.isEmpty(): |
|
97 | if name != 'init' and self.dataOut.isEmpty(): | |
98 | return False |
|
98 | return False | |
99 |
|
99 | |||
100 | methodToCall = getattr(self, name) |
|
100 | methodToCall = getattr(self, name) | |
101 |
|
101 | |||
102 | methodToCall(**kwargs) |
|
102 | methodToCall(**kwargs) | |
103 |
|
103 | |||
104 | if name != 'run': |
|
104 | if name != 'run': | |
105 | return True |
|
105 | return True | |
106 |
|
106 | |||
107 | if self.dataOut.isEmpty(): |
|
107 | if self.dataOut.isEmpty(): | |
108 | return False |
|
108 | return False | |
109 |
|
109 | |||
110 | return True |
|
110 | return True | |
111 |
|
111 | |||
112 | def callObject(self, objId, **kwargs): |
|
112 | def callObject(self, objId, **kwargs): | |
113 |
|
113 | |||
114 | """ |
|
114 | """ | |
115 | Ejecuta la operacion asociada al identificador del objeto "objId" |
|
115 | Ejecuta la operacion asociada al identificador del objeto "objId" | |
116 |
|
116 | |||
117 | Input: |
|
117 | Input: | |
118 |
|
118 | |||
119 | objId : identificador del objeto a ejecutar |
|
119 | objId : identificador del objeto a ejecutar | |
120 |
|
120 | |||
121 | **kwargs : diccionario con los nombres y valores de la funcion a ejecutar. |
|
121 | **kwargs : diccionario con los nombres y valores de la funcion a ejecutar. | |
122 |
|
122 | |||
123 | Return: |
|
123 | Return: | |
124 |
|
124 | |||
125 | None |
|
125 | None | |
126 | """ |
|
126 | """ | |
127 |
|
127 | |||
128 | if self.dataOut.isEmpty(): |
|
128 | if self.dataOut.isEmpty(): | |
129 | return False |
|
129 | return False | |
130 |
|
130 | |||
131 | object = self.objectDict[objId] |
|
131 | object = self.objectDict[objId] | |
132 |
|
132 | |||
133 | object.run(self.dataOut, **kwargs) |
|
133 | object.run(self.dataOut, **kwargs) | |
134 |
|
134 | |||
135 | return True |
|
135 | return True | |
136 |
|
136 | |||
137 | def call(self, operationConf, **kwargs): |
|
137 | def call(self, operationConf, **kwargs): | |
138 |
|
138 | |||
139 | """ |
|
139 | """ | |
140 | Return True si ejecuta la operacion "operationConf.name" con los |
|
140 | Return True si ejecuta la operacion "operationConf.name" con los | |
141 | argumentos "**kwargs". False si la operacion no se ha ejecutado. |
|
141 | argumentos "**kwargs". False si la operacion no se ha ejecutado. | |
142 | La operacion puede ser de dos tipos: |
|
142 | La operacion puede ser de dos tipos: | |
143 |
|
143 | |||
144 | 1. Un metodo propio de esta clase: |
|
144 | 1. Un metodo propio de esta clase: | |
145 |
|
145 | |||
146 | operation.type = "self" |
|
146 | operation.type = "self" | |
147 |
|
147 | |||
148 | 2. El metodo "run" de un objeto del tipo Operation o de un derivado de ella: |
|
148 | 2. El metodo "run" de un objeto del tipo Operation o de un derivado de ella: | |
149 | operation.type = "other". |
|
149 | operation.type = "other". | |
150 |
|
150 | |||
151 | Este objeto de tipo Operation debe de haber sido agregado antes con el metodo: |
|
151 | Este objeto de tipo Operation debe de haber sido agregado antes con el metodo: | |
152 | "addOperation" e identificado con el operation.id |
|
152 | "addOperation" e identificado con el operation.id | |
153 |
|
153 | |||
154 |
|
154 | |||
155 | con el id de la operacion. |
|
155 | con el id de la operacion. | |
156 |
|
156 | |||
157 | Input: |
|
157 | Input: | |
158 |
|
158 | |||
159 | Operation : Objeto del tipo operacion con los atributos: name, type y id. |
|
159 | Operation : Objeto del tipo operacion con los atributos: name, type y id. | |
160 |
|
160 | |||
161 | """ |
|
161 | """ | |
162 |
|
162 | |||
163 | if operationConf.type == 'self': |
|
163 | if operationConf.type == 'self': | |
164 | sts = self.callMethod(operationConf.name, **kwargs) |
|
164 | sts = self.callMethod(operationConf.name, **kwargs) | |
165 |
|
165 | |||
166 | if operationConf.type == 'other': |
|
166 | if operationConf.type == 'other': | |
167 | sts = self.callObject(operationConf.id, **kwargs) |
|
167 | sts = self.callObject(operationConf.id, **kwargs) | |
168 |
|
168 | |||
169 | return sts |
|
169 | return sts | |
170 |
|
170 | |||
171 | def setInput(self, dataIn): |
|
171 | def setInput(self, dataIn): | |
172 |
|
172 | |||
173 | self.dataIn = dataIn |
|
173 | self.dataIn = dataIn | |
174 |
|
174 | |||
175 | def getOutput(self): |
|
175 | def getOutput(self): | |
176 |
|
176 | |||
177 | return self.dataOut |
|
177 | return self.dataOut | |
178 |
|
178 | |||
179 | class Operation(): |
|
179 | class Operation(): | |
180 |
|
180 | |||
181 | """ |
|
181 | """ | |
182 | Clase base para definir las operaciones adicionales que se pueden agregar a la clase ProcessingUnit |
|
182 | Clase base para definir las operaciones adicionales que se pueden agregar a la clase ProcessingUnit | |
183 | y necesiten acumular informacion previa de los datos a procesar. De preferencia usar un buffer de |
|
183 | y necesiten acumular informacion previa de los datos a procesar. De preferencia usar un buffer de | |
184 | acumulacion dentro de esta clase |
|
184 | acumulacion dentro de esta clase | |
185 |
|
185 | |||
186 | Ejemplo: Integraciones coherentes, necesita la informacion previa de los n perfiles anteriores (bufffer) |
|
186 | Ejemplo: Integraciones coherentes, necesita la informacion previa de los n perfiles anteriores (bufffer) | |
187 |
|
187 | |||
188 | """ |
|
188 | """ | |
189 |
|
189 | |||
190 | __buffer = None |
|
190 | __buffer = None | |
191 | __isConfig = False |
|
191 | __isConfig = False | |
192 |
|
192 | |||
193 | def __init__(self): |
|
193 | def __init__(self): | |
194 |
|
194 | |||
195 | pass |
|
195 | pass | |
196 |
|
196 | |||
197 | def run(self, dataIn, **kwargs): |
|
197 | def run(self, dataIn, **kwargs): | |
198 |
|
198 | |||
199 | """ |
|
199 | """ | |
200 | Realiza las operaciones necesarias sobre la dataIn.data y actualiza los atributos del objeto dataIn. |
|
200 | Realiza las operaciones necesarias sobre la dataIn.data y actualiza los atributos del objeto dataIn. | |
201 |
|
201 | |||
202 | Input: |
|
202 | Input: | |
203 |
|
203 | |||
204 | dataIn : objeto del tipo JROData |
|
204 | dataIn : objeto del tipo JROData | |
205 |
|
205 | |||
206 | Return: |
|
206 | Return: | |
207 |
|
207 | |||
208 | None |
|
208 | None | |
209 |
|
209 | |||
210 | Affected: |
|
210 | Affected: | |
211 | __buffer : buffer de recepcion de datos. |
|
211 | __buffer : buffer de recepcion de datos. | |
212 |
|
212 | |||
213 | """ |
|
213 | """ | |
214 |
|
214 | |||
215 | raise ValueError, "ImplementedError" |
|
215 | raise ValueError, "ImplementedError" | |
216 |
|
216 | |||
217 | class VoltageProc(ProcessingUnit): |
|
217 | class VoltageProc(ProcessingUnit): | |
218 |
|
218 | |||
219 |
|
219 | |||
220 | def __init__(self): |
|
220 | def __init__(self): | |
221 |
|
221 | |||
222 | self.objectDict = {} |
|
222 | self.objectDict = {} | |
223 | self.dataOut = Voltage() |
|
223 | self.dataOut = Voltage() | |
224 | self.flip = 1 |
|
224 | self.flip = 1 | |
225 |
|
225 | |||
226 | def __updateObjFromAmisrInput(self): |
|
226 | def __updateObjFromAmisrInput(self): | |
227 |
|
227 | |||
228 | self.dataOut.timeZone = self.dataIn.timeZone |
|
228 | self.dataOut.timeZone = self.dataIn.timeZone | |
229 | self.dataOut.dstFlag = self.dataIn.dstFlag |
|
229 | self.dataOut.dstFlag = self.dataIn.dstFlag | |
230 | self.dataOut.errorCount = self.dataIn.errorCount |
|
230 | self.dataOut.errorCount = self.dataIn.errorCount | |
231 | self.dataOut.useLocalTime = self.dataIn.useLocalTime |
|
231 | self.dataOut.useLocalTime = self.dataIn.useLocalTime | |
232 |
|
232 | |||
233 | self.dataOut.flagNoData = self.dataIn.flagNoData |
|
233 | self.dataOut.flagNoData = self.dataIn.flagNoData | |
234 | self.dataOut.data = self.dataIn.data |
|
234 | self.dataOut.data = self.dataIn.data | |
235 | self.dataOut.utctime = self.dataIn.utctime |
|
235 | self.dataOut.utctime = self.dataIn.utctime | |
236 | self.dataOut.channelList = self.dataIn.channelList |
|
236 | self.dataOut.channelList = self.dataIn.channelList | |
237 | self.dataOut.timeInterval = self.dataIn.timeInterval |
|
237 | self.dataOut.timeInterval = self.dataIn.timeInterval | |
238 | self.dataOut.heightList = self.dataIn.heightList |
|
238 | self.dataOut.heightList = self.dataIn.heightList | |
239 | self.dataOut.nProfiles = self.dataIn.nProfiles |
|
239 | self.dataOut.nProfiles = self.dataIn.nProfiles | |
240 |
|
240 | |||
|
241 | self.dataOut.nCohInt = self.dataIn.nCohInt | |||
|
242 | self.dataOut.ippSeconds = self.dataIn.ippSeconds | |||
|
243 | self.dataOut.frequency = self.dataIn.frequency | |||
|
244 | ||||
241 | pass |
|
245 | pass | |
242 |
|
246 | |||
243 | def init(self): |
|
247 | def init(self): | |
244 |
|
248 | |||
245 |
|
249 | |||
246 | if self.dataIn.type == 'AMISR': |
|
250 | if self.dataIn.type == 'AMISR': | |
247 | self.__updateObjFromAmisrInput() |
|
251 | self.__updateObjFromAmisrInput() | |
248 |
|
252 | |||
249 | if self.dataIn.type == 'Voltage': |
|
253 | if self.dataIn.type == 'Voltage': | |
250 | self.dataOut.copy(self.dataIn) |
|
254 | self.dataOut.copy(self.dataIn) | |
251 | # No necesita copiar en cada init() los atributos de dataIn |
|
255 | # No necesita copiar en cada init() los atributos de dataIn | |
252 | # la copia deberia hacerse por cada nuevo bloque de datos |
|
256 | # la copia deberia hacerse por cada nuevo bloque de datos | |
253 |
|
257 | |||
254 | def selectChannels(self, channelList): |
|
258 | def selectChannels(self, channelList): | |
255 |
|
259 | |||
256 | channelIndexList = [] |
|
260 | channelIndexList = [] | |
257 |
|
261 | |||
258 | for channel in channelList: |
|
262 | for channel in channelList: | |
259 | index = self.dataOut.channelList.index(channel) |
|
263 | index = self.dataOut.channelList.index(channel) | |
260 | channelIndexList.append(index) |
|
264 | channelIndexList.append(index) | |
261 |
|
265 | |||
262 | self.selectChannelsByIndex(channelIndexList) |
|
266 | self.selectChannelsByIndex(channelIndexList) | |
263 |
|
267 | |||
264 | def selectChannelsByIndex(self, channelIndexList): |
|
268 | def selectChannelsByIndex(self, channelIndexList): | |
265 | """ |
|
269 | """ | |
266 | Selecciona un bloque de datos en base a canales segun el channelIndexList |
|
270 | Selecciona un bloque de datos en base a canales segun el channelIndexList | |
267 |
|
271 | |||
268 | Input: |
|
272 | Input: | |
269 | channelIndexList : lista sencilla de canales a seleccionar por ej. [2,3,7] |
|
273 | channelIndexList : lista sencilla de canales a seleccionar por ej. [2,3,7] | |
270 |
|
274 | |||
271 | Affected: |
|
275 | Affected: | |
272 | self.dataOut.data |
|
276 | self.dataOut.data | |
273 | self.dataOut.channelIndexList |
|
277 | self.dataOut.channelIndexList | |
274 | self.dataOut.nChannels |
|
278 | self.dataOut.nChannels | |
275 | self.dataOut.m_ProcessingHeader.totalSpectra |
|
279 | self.dataOut.m_ProcessingHeader.totalSpectra | |
276 | self.dataOut.systemHeaderObj.numChannels |
|
280 | self.dataOut.systemHeaderObj.numChannels | |
277 | self.dataOut.m_ProcessingHeader.blockSize |
|
281 | self.dataOut.m_ProcessingHeader.blockSize | |
278 |
|
282 | |||
279 | Return: |
|
283 | Return: | |
280 | None |
|
284 | None | |
281 | """ |
|
285 | """ | |
282 |
|
286 | |||
283 | for channelIndex in channelIndexList: |
|
287 | for channelIndex in channelIndexList: | |
284 | if channelIndex not in self.dataOut.channelIndexList: |
|
288 | if channelIndex not in self.dataOut.channelIndexList: | |
285 | print channelIndexList |
|
289 | print channelIndexList | |
286 | raise ValueError, "The value %d in channelIndexList is not valid" %channelIndex |
|
290 | raise ValueError, "The value %d in channelIndexList is not valid" %channelIndex | |
287 |
|
291 | |||
288 | nChannels = len(channelIndexList) |
|
292 | nChannels = len(channelIndexList) | |
289 |
|
293 | |||
290 | data = self.dataOut.data[channelIndexList,:] |
|
294 | data = self.dataOut.data[channelIndexList,:] | |
291 |
|
295 | |||
292 | self.dataOut.data = data |
|
296 | self.dataOut.data = data | |
293 | self.dataOut.channelList = [self.dataOut.channelList[i] for i in channelIndexList] |
|
297 | self.dataOut.channelList = [self.dataOut.channelList[i] for i in channelIndexList] | |
294 | # self.dataOut.nChannels = nChannels |
|
298 | # self.dataOut.nChannels = nChannels | |
295 |
|
299 | |||
296 | return 1 |
|
300 | return 1 | |
297 |
|
301 | |||
298 | def selectHeights(self, minHei=None, maxHei=None): |
|
302 | def selectHeights(self, minHei=None, maxHei=None): | |
299 | """ |
|
303 | """ | |
300 | Selecciona un bloque de datos en base a un grupo de valores de alturas segun el rango |
|
304 | Selecciona un bloque de datos en base a un grupo de valores de alturas segun el rango | |
301 | minHei <= height <= maxHei |
|
305 | minHei <= height <= maxHei | |
302 |
|
306 | |||
303 | Input: |
|
307 | Input: | |
304 | minHei : valor minimo de altura a considerar |
|
308 | minHei : valor minimo de altura a considerar | |
305 | maxHei : valor maximo de altura a considerar |
|
309 | maxHei : valor maximo de altura a considerar | |
306 |
|
310 | |||
307 | Affected: |
|
311 | Affected: | |
308 | Indirectamente son cambiados varios valores a travez del metodo selectHeightsByIndex |
|
312 | Indirectamente son cambiados varios valores a travez del metodo selectHeightsByIndex | |
309 |
|
313 | |||
310 | Return: |
|
314 | Return: | |
311 | 1 si el metodo se ejecuto con exito caso contrario devuelve 0 |
|
315 | 1 si el metodo se ejecuto con exito caso contrario devuelve 0 | |
312 | """ |
|
316 | """ | |
313 |
|
317 | |||
314 | if minHei == None: |
|
318 | if minHei == None: | |
315 | minHei = self.dataOut.heightList[0] |
|
319 | minHei = self.dataOut.heightList[0] | |
316 |
|
320 | |||
317 | if maxHei == None: |
|
321 | if maxHei == None: | |
318 | maxHei = self.dataOut.heightList[-1] |
|
322 | maxHei = self.dataOut.heightList[-1] | |
319 |
|
323 | |||
320 | if (minHei < self.dataOut.heightList[0]) or (minHei > maxHei): |
|
324 | if (minHei < self.dataOut.heightList[0]) or (minHei > maxHei): | |
321 | raise ValueError, "some value in (%d,%d) is not valid" % (minHei, maxHei) |
|
325 | raise ValueError, "some value in (%d,%d) is not valid" % (minHei, maxHei) | |
322 |
|
326 | |||
323 |
|
327 | |||
324 | if (maxHei > self.dataOut.heightList[-1]): |
|
328 | if (maxHei > self.dataOut.heightList[-1]): | |
325 | maxHei = self.dataOut.heightList[-1] |
|
329 | maxHei = self.dataOut.heightList[-1] | |
326 | # raise ValueError, "some value in (%d,%d) is not valid" % (minHei, maxHei) |
|
330 | # raise ValueError, "some value in (%d,%d) is not valid" % (minHei, maxHei) | |
327 |
|
331 | |||
328 | minIndex = 0 |
|
332 | minIndex = 0 | |
329 | maxIndex = 0 |
|
333 | maxIndex = 0 | |
330 | heights = self.dataOut.heightList |
|
334 | heights = self.dataOut.heightList | |
331 |
|
335 | |||
332 | inda = numpy.where(heights >= minHei) |
|
336 | inda = numpy.where(heights >= minHei) | |
333 | indb = numpy.where(heights <= maxHei) |
|
337 | indb = numpy.where(heights <= maxHei) | |
334 |
|
338 | |||
335 | try: |
|
339 | try: | |
336 | minIndex = inda[0][0] |
|
340 | minIndex = inda[0][0] | |
337 | except: |
|
341 | except: | |
338 | minIndex = 0 |
|
342 | minIndex = 0 | |
339 |
|
343 | |||
340 | try: |
|
344 | try: | |
341 | maxIndex = indb[0][-1] |
|
345 | maxIndex = indb[0][-1] | |
342 | except: |
|
346 | except: | |
343 | maxIndex = len(heights) |
|
347 | maxIndex = len(heights) | |
344 |
|
348 | |||
345 | self.selectHeightsByIndex(minIndex, maxIndex) |
|
349 | self.selectHeightsByIndex(minIndex, maxIndex) | |
346 |
|
350 | |||
347 | return 1 |
|
351 | return 1 | |
348 |
|
352 | |||
349 |
|
353 | |||
350 | def selectHeightsByIndex(self, minIndex, maxIndex): |
|
354 | def selectHeightsByIndex(self, minIndex, maxIndex): | |
351 | """ |
|
355 | """ | |
352 | Selecciona un bloque de datos en base a un grupo indices de alturas segun el rango |
|
356 | Selecciona un bloque de datos en base a un grupo indices de alturas segun el rango | |
353 | minIndex <= index <= maxIndex |
|
357 | minIndex <= index <= maxIndex | |
354 |
|
358 | |||
355 | Input: |
|
359 | Input: | |
356 | minIndex : valor de indice minimo de altura a considerar |
|
360 | minIndex : valor de indice minimo de altura a considerar | |
357 | maxIndex : valor de indice maximo de altura a considerar |
|
361 | maxIndex : valor de indice maximo de altura a considerar | |
358 |
|
362 | |||
359 | Affected: |
|
363 | Affected: | |
360 | self.dataOut.data |
|
364 | self.dataOut.data | |
361 | self.dataOut.heightList |
|
365 | self.dataOut.heightList | |
362 |
|
366 | |||
363 | Return: |
|
367 | Return: | |
364 | 1 si el metodo se ejecuto con exito caso contrario devuelve 0 |
|
368 | 1 si el metodo se ejecuto con exito caso contrario devuelve 0 | |
365 | """ |
|
369 | """ | |
366 |
|
370 | |||
367 | if (minIndex < 0) or (minIndex > maxIndex): |
|
371 | if (minIndex < 0) or (minIndex > maxIndex): | |
368 | raise ValueError, "some value in (%d,%d) is not valid" % (minIndex, maxIndex) |
|
372 | raise ValueError, "some value in (%d,%d) is not valid" % (minIndex, maxIndex) | |
369 |
|
373 | |||
370 | if (maxIndex >= self.dataOut.nHeights): |
|
374 | if (maxIndex >= self.dataOut.nHeights): | |
371 | maxIndex = self.dataOut.nHeights-1 |
|
375 | maxIndex = self.dataOut.nHeights-1 | |
372 | # raise ValueError, "some value in (%d,%d) is not valid" % (minIndex, maxIndex) |
|
376 | # raise ValueError, "some value in (%d,%d) is not valid" % (minIndex, maxIndex) | |
373 |
|
377 | |||
374 | nHeights = maxIndex - minIndex + 1 |
|
378 | nHeights = maxIndex - minIndex + 1 | |
375 |
|
379 | |||
376 | #voltage |
|
380 | #voltage | |
377 | data = self.dataOut.data[:,minIndex:maxIndex+1] |
|
381 | data = self.dataOut.data[:,minIndex:maxIndex+1] | |
378 |
|
382 | |||
379 | firstHeight = self.dataOut.heightList[minIndex] |
|
383 | firstHeight = self.dataOut.heightList[minIndex] | |
380 |
|
384 | |||
381 | self.dataOut.data = data |
|
385 | self.dataOut.data = data | |
382 | self.dataOut.heightList = self.dataOut.heightList[minIndex:maxIndex+1] |
|
386 | self.dataOut.heightList = self.dataOut.heightList[minIndex:maxIndex+1] | |
383 |
|
387 | |||
384 | return 1 |
|
388 | return 1 | |
385 |
|
389 | |||
386 |
|
390 | |||
387 | def filterByHeights(self, window): |
|
391 | def filterByHeights(self, window): | |
388 | deltaHeight = self.dataOut.heightList[1] - self.dataOut.heightList[0] |
|
392 | deltaHeight = self.dataOut.heightList[1] - self.dataOut.heightList[0] | |
389 |
|
393 | |||
390 | if window == None: |
|
394 | if window == None: | |
391 | window = (self.dataOut.radarControllerHeaderObj.txA/self.dataOut.radarControllerHeaderObj.nBaud) / deltaHeight |
|
395 | window = (self.dataOut.radarControllerHeaderObj.txA/self.dataOut.radarControllerHeaderObj.nBaud) / deltaHeight | |
392 |
|
396 | |||
393 | newdelta = deltaHeight * window |
|
397 | newdelta = deltaHeight * window | |
394 | r = self.dataOut.data.shape[1] % window |
|
398 | r = self.dataOut.data.shape[1] % window | |
395 | buffer = self.dataOut.data[:,0:self.dataOut.data.shape[1]-r] |
|
399 | buffer = self.dataOut.data[:,0:self.dataOut.data.shape[1]-r] | |
396 | buffer = buffer.reshape(self.dataOut.data.shape[0],self.dataOut.data.shape[1]/window,window) |
|
400 | buffer = buffer.reshape(self.dataOut.data.shape[0],self.dataOut.data.shape[1]/window,window) | |
397 | buffer = numpy.sum(buffer,2) |
|
401 | buffer = numpy.sum(buffer,2) | |
398 | self.dataOut.data = buffer |
|
402 | self.dataOut.data = buffer | |
399 | self.dataOut.heightList = numpy.arange(self.dataOut.heightList[0],newdelta*(self.dataOut.nHeights-r)/window,newdelta) |
|
403 | self.dataOut.heightList = numpy.arange(self.dataOut.heightList[0],newdelta*(self.dataOut.nHeights-r)/window,newdelta) | |
400 | self.dataOut.windowOfFilter = window |
|
404 | self.dataOut.windowOfFilter = window | |
401 |
|
405 | |||
402 | def deFlip(self): |
|
406 | def deFlip(self): | |
403 | self.dataOut.data *= self.flip |
|
407 | self.dataOut.data *= self.flip | |
404 | self.flip *= -1. |
|
408 | self.flip *= -1. | |
405 |
|
409 | |||
406 | def setRadarFrequency(self, frequency=None): |
|
410 | def setRadarFrequency(self, frequency=None): | |
407 | if frequency != None: |
|
411 | if frequency != None: | |
408 | self.dataOut.frequency = frequency |
|
412 | self.dataOut.frequency = frequency | |
409 |
|
413 | |||
410 | return 1 |
|
414 | return 1 | |
411 |
|
415 | |||
412 | class CohInt(Operation): |
|
416 | class CohInt(Operation): | |
413 |
|
417 | |||
414 | __isConfig = False |
|
418 | __isConfig = False | |
415 |
|
419 | |||
416 | __profIndex = 0 |
|
420 | __profIndex = 0 | |
417 | __withOverapping = False |
|
421 | __withOverapping = False | |
418 |
|
422 | |||
419 | __byTime = False |
|
423 | __byTime = False | |
420 | __initime = None |
|
424 | __initime = None | |
421 | __lastdatatime = None |
|
425 | __lastdatatime = None | |
422 | __integrationtime = None |
|
426 | __integrationtime = None | |
423 |
|
427 | |||
424 | __buffer = None |
|
428 | __buffer = None | |
425 |
|
429 | |||
426 | __dataReady = False |
|
430 | __dataReady = False | |
427 |
|
431 | |||
428 | n = None |
|
432 | n = None | |
429 |
|
433 | |||
430 |
|
434 | |||
431 | def __init__(self): |
|
435 | def __init__(self): | |
432 |
|
436 | |||
433 | self.__isConfig = False |
|
437 | self.__isConfig = False | |
434 |
|
438 | |||
435 | def setup(self, n=None, timeInterval=None, overlapping=False): |
|
439 | def setup(self, n=None, timeInterval=None, overlapping=False): | |
436 | """ |
|
440 | """ | |
437 | Set the parameters of the integration class. |
|
441 | Set the parameters of the integration class. | |
438 |
|
442 | |||
439 | Inputs: |
|
443 | Inputs: | |
440 |
|
444 | |||
441 | n : Number of coherent integrations |
|
445 | n : Number of coherent integrations | |
442 | timeInterval : Time of integration. If the parameter "n" is selected this one does not work |
|
446 | timeInterval : Time of integration. If the parameter "n" is selected this one does not work | |
443 | overlapping : |
|
447 | overlapping : | |
444 |
|
448 | |||
445 | """ |
|
449 | """ | |
446 |
|
450 | |||
447 | self.__initime = None |
|
451 | self.__initime = None | |
448 | self.__lastdatatime = 0 |
|
452 | self.__lastdatatime = 0 | |
449 | self.__buffer = None |
|
453 | self.__buffer = None | |
450 | self.__dataReady = False |
|
454 | self.__dataReady = False | |
451 |
|
455 | |||
452 |
|
456 | |||
453 | if n == None and timeInterval == None: |
|
457 | if n == None and timeInterval == None: | |
454 | raise ValueError, "n or timeInterval should be specified ..." |
|
458 | raise ValueError, "n or timeInterval should be specified ..." | |
455 |
|
459 | |||
456 | if n != None: |
|
460 | if n != None: | |
457 | self.n = n |
|
461 | self.n = n | |
458 | self.__byTime = False |
|
462 | self.__byTime = False | |
459 | else: |
|
463 | else: | |
460 | self.__integrationtime = timeInterval * 60. #if (type(timeInterval)!=integer) -> change this line |
|
464 | self.__integrationtime = timeInterval * 60. #if (type(timeInterval)!=integer) -> change this line | |
461 | self.n = 9999 |
|
465 | self.n = 9999 | |
462 | self.__byTime = True |
|
466 | self.__byTime = True | |
463 |
|
467 | |||
464 | if overlapping: |
|
468 | if overlapping: | |
465 | self.__withOverapping = True |
|
469 | self.__withOverapping = True | |
466 | self.__buffer = None |
|
470 | self.__buffer = None | |
467 | else: |
|
471 | else: | |
468 | self.__withOverapping = False |
|
472 | self.__withOverapping = False | |
469 | self.__buffer = 0 |
|
473 | self.__buffer = 0 | |
470 |
|
474 | |||
471 | self.__profIndex = 0 |
|
475 | self.__profIndex = 0 | |
472 |
|
476 | |||
473 | def putData(self, data): |
|
477 | def putData(self, data): | |
474 |
|
478 | |||
475 | """ |
|
479 | """ | |
476 | Add a profile to the __buffer and increase in one the __profileIndex |
|
480 | Add a profile to the __buffer and increase in one the __profileIndex | |
477 |
|
481 | |||
478 | """ |
|
482 | """ | |
479 |
|
483 | |||
480 | if not self.__withOverapping: |
|
484 | if not self.__withOverapping: | |
481 | self.__buffer += data.copy() |
|
485 | self.__buffer += data.copy() | |
482 | self.__profIndex += 1 |
|
486 | self.__profIndex += 1 | |
483 | return |
|
487 | return | |
484 |
|
488 | |||
485 | #Overlapping data |
|
489 | #Overlapping data | |
486 | nChannels, nHeis = data.shape |
|
490 | nChannels, nHeis = data.shape | |
487 | data = numpy.reshape(data, (1, nChannels, nHeis)) |
|
491 | data = numpy.reshape(data, (1, nChannels, nHeis)) | |
488 |
|
492 | |||
489 | #If the buffer is empty then it takes the data value |
|
493 | #If the buffer is empty then it takes the data value | |
490 | if self.__buffer == None: |
|
494 | if self.__buffer == None: | |
491 | self.__buffer = data |
|
495 | self.__buffer = data | |
492 | self.__profIndex += 1 |
|
496 | self.__profIndex += 1 | |
493 | return |
|
497 | return | |
494 |
|
498 | |||
495 | #If the buffer length is lower than n then stakcing the data value |
|
499 | #If the buffer length is lower than n then stakcing the data value | |
496 | if self.__profIndex < self.n: |
|
500 | if self.__profIndex < self.n: | |
497 | self.__buffer = numpy.vstack((self.__buffer, data)) |
|
501 | self.__buffer = numpy.vstack((self.__buffer, data)) | |
498 | self.__profIndex += 1 |
|
502 | self.__profIndex += 1 | |
499 | return |
|
503 | return | |
500 |
|
504 | |||
501 | #If the buffer length is equal to n then replacing the last buffer value with the data value |
|
505 | #If the buffer length is equal to n then replacing the last buffer value with the data value | |
502 | self.__buffer = numpy.roll(self.__buffer, -1, axis=0) |
|
506 | self.__buffer = numpy.roll(self.__buffer, -1, axis=0) | |
503 | self.__buffer[self.n-1] = data |
|
507 | self.__buffer[self.n-1] = data | |
504 | self.__profIndex = self.n |
|
508 | self.__profIndex = self.n | |
505 | return |
|
509 | return | |
506 |
|
510 | |||
507 |
|
511 | |||
508 | def pushData(self): |
|
512 | def pushData(self): | |
509 | """ |
|
513 | """ | |
510 | Return the sum of the last profiles and the profiles used in the sum. |
|
514 | Return the sum of the last profiles and the profiles used in the sum. | |
511 |
|
515 | |||
512 | Affected: |
|
516 | Affected: | |
513 |
|
517 | |||
514 | self.__profileIndex |
|
518 | self.__profileIndex | |
515 |
|
519 | |||
516 | """ |
|
520 | """ | |
517 |
|
521 | |||
518 | if not self.__withOverapping: |
|
522 | if not self.__withOverapping: | |
519 | data = self.__buffer |
|
523 | data = self.__buffer | |
520 | n = self.__profIndex |
|
524 | n = self.__profIndex | |
521 |
|
525 | |||
522 | self.__buffer = 0 |
|
526 | self.__buffer = 0 | |
523 | self.__profIndex = 0 |
|
527 | self.__profIndex = 0 | |
524 |
|
528 | |||
525 | return data, n |
|
529 | return data, n | |
526 |
|
530 | |||
527 | #Integration with Overlapping |
|
531 | #Integration with Overlapping | |
528 | data = numpy.sum(self.__buffer, axis=0) |
|
532 | data = numpy.sum(self.__buffer, axis=0) | |
529 | n = self.__profIndex |
|
533 | n = self.__profIndex | |
530 |
|
534 | |||
531 | return data, n |
|
535 | return data, n | |
532 |
|
536 | |||
533 | def byProfiles(self, data): |
|
537 | def byProfiles(self, data): | |
534 |
|
538 | |||
535 | self.__dataReady = False |
|
539 | self.__dataReady = False | |
536 | avgdata = None |
|
540 | avgdata = None | |
537 | n = None |
|
541 | n = None | |
538 |
|
542 | |||
539 | self.putData(data) |
|
543 | self.putData(data) | |
540 |
|
544 | |||
541 | if self.__profIndex == self.n: |
|
545 | if self.__profIndex == self.n: | |
542 |
|
546 | |||
543 | avgdata, n = self.pushData() |
|
547 | avgdata, n = self.pushData() | |
544 | self.__dataReady = True |
|
548 | self.__dataReady = True | |
545 |
|
549 | |||
546 | return avgdata |
|
550 | return avgdata | |
547 |
|
551 | |||
548 | def byTime(self, data, datatime): |
|
552 | def byTime(self, data, datatime): | |
549 |
|
553 | |||
550 | self.__dataReady = False |
|
554 | self.__dataReady = False | |
551 | avgdata = None |
|
555 | avgdata = None | |
552 | n = None |
|
556 | n = None | |
553 |
|
557 | |||
554 | self.putData(data) |
|
558 | self.putData(data) | |
555 |
|
559 | |||
556 | if (datatime - self.__initime) >= self.__integrationtime: |
|
560 | if (datatime - self.__initime) >= self.__integrationtime: | |
557 | avgdata, n = self.pushData() |
|
561 | avgdata, n = self.pushData() | |
558 | self.n = n |
|
562 | self.n = n | |
559 | self.__dataReady = True |
|
563 | self.__dataReady = True | |
560 |
|
564 | |||
561 | return avgdata |
|
565 | return avgdata | |
562 |
|
566 | |||
563 | def integrate(self, data, datatime=None): |
|
567 | def integrate(self, data, datatime=None): | |
564 |
|
568 | |||
565 | if self.__initime == None: |
|
569 | if self.__initime == None: | |
566 | self.__initime = datatime |
|
570 | self.__initime = datatime | |
567 |
|
571 | |||
568 | if self.__byTime: |
|
572 | if self.__byTime: | |
569 | avgdata = self.byTime(data, datatime) |
|
573 | avgdata = self.byTime(data, datatime) | |
570 | else: |
|
574 | else: | |
571 | avgdata = self.byProfiles(data) |
|
575 | avgdata = self.byProfiles(data) | |
572 |
|
576 | |||
573 |
|
577 | |||
574 | self.__lastdatatime = datatime |
|
578 | self.__lastdatatime = datatime | |
575 |
|
579 | |||
576 | if avgdata == None: |
|
580 | if avgdata == None: | |
577 | return None, None |
|
581 | return None, None | |
578 |
|
582 | |||
579 | avgdatatime = self.__initime |
|
583 | avgdatatime = self.__initime | |
580 |
|
584 | |||
581 | deltatime = datatime -self.__lastdatatime |
|
585 | deltatime = datatime -self.__lastdatatime | |
582 |
|
586 | |||
583 | if not self.__withOverapping: |
|
587 | if not self.__withOverapping: | |
584 | self.__initime = datatime |
|
588 | self.__initime = datatime | |
585 | else: |
|
589 | else: | |
586 | self.__initime += deltatime |
|
590 | self.__initime += deltatime | |
587 |
|
591 | |||
588 | return avgdata, avgdatatime |
|
592 | return avgdata, avgdatatime | |
589 |
|
593 | |||
590 | def run(self, dataOut, **kwargs): |
|
594 | def run(self, dataOut, **kwargs): | |
591 |
|
595 | |||
592 | if not self.__isConfig: |
|
596 | if not self.__isConfig: | |
593 | self.setup(**kwargs) |
|
597 | self.setup(**kwargs) | |
594 | self.__isConfig = True |
|
598 | self.__isConfig = True | |
595 |
|
599 | |||
596 | avgdata, avgdatatime = self.integrate(dataOut.data, dataOut.utctime) |
|
600 | avgdata, avgdatatime = self.integrate(dataOut.data, dataOut.utctime) | |
597 |
|
601 | |||
598 | # dataOut.timeInterval *= n |
|
602 | # dataOut.timeInterval *= n | |
599 | dataOut.flagNoData = True |
|
603 | dataOut.flagNoData = True | |
600 |
|
604 | |||
601 | if self.__dataReady: |
|
605 | if self.__dataReady: | |
602 | dataOut.data = avgdata |
|
606 | dataOut.data = avgdata | |
603 | dataOut.nCohInt *= self.n |
|
607 | dataOut.nCohInt *= self.n | |
604 | dataOut.utctime = avgdatatime |
|
608 | dataOut.utctime = avgdatatime | |
605 | dataOut.timeInterval = dataOut.ippSeconds * dataOut.nCohInt |
|
609 | dataOut.timeInterval = dataOut.ippSeconds * dataOut.nCohInt | |
606 | dataOut.flagNoData = False |
|
610 | dataOut.flagNoData = False | |
607 |
|
611 | |||
608 |
|
612 | |||
609 | class Decoder(Operation): |
|
613 | class Decoder(Operation): | |
610 |
|
614 | |||
611 | __isConfig = False |
|
615 | __isConfig = False | |
612 | __profIndex = 0 |
|
616 | __profIndex = 0 | |
613 |
|
617 | |||
614 | code = None |
|
618 | code = None | |
615 |
|
619 | |||
616 | nCode = None |
|
620 | nCode = None | |
617 | nBaud = None |
|
621 | nBaud = None | |
618 |
|
622 | |||
619 | def __init__(self): |
|
623 | def __init__(self): | |
620 |
|
624 | |||
621 | self.__isConfig = False |
|
625 | self.__isConfig = False | |
622 |
|
626 | |||
623 | def setup(self, code, shape): |
|
627 | def setup(self, code, shape): | |
624 |
|
628 | |||
625 | self.__profIndex = 0 |
|
629 | self.__profIndex = 0 | |
626 |
|
630 | |||
627 | self.code = code |
|
631 | self.code = code | |
628 |
|
632 | |||
629 | self.nCode = len(code) |
|
633 | self.nCode = len(code) | |
630 | self.nBaud = len(code[0]) |
|
634 | self.nBaud = len(code[0]) | |
631 |
|
635 | |||
632 | self.__nChannels, self.__nHeis = shape |
|
636 | self.__nChannels, self.__nHeis = shape | |
633 |
|
637 | |||
634 | __codeBuffer = numpy.zeros((self.nCode, self.__nHeis), dtype=numpy.complex) |
|
638 | __codeBuffer = numpy.zeros((self.nCode, self.__nHeis), dtype=numpy.complex) | |
635 |
|
639 | |||
636 | __codeBuffer[:,0:self.nBaud] = self.code |
|
640 | __codeBuffer[:,0:self.nBaud] = self.code | |
637 |
|
641 | |||
638 | self.fft_code = numpy.conj(numpy.fft.fft(__codeBuffer, axis=1)) |
|
642 | self.fft_code = numpy.conj(numpy.fft.fft(__codeBuffer, axis=1)) | |
639 |
|
643 | |||
640 | self.ndatadec = self.__nHeis - self.nBaud + 1 |
|
644 | self.ndatadec = self.__nHeis - self.nBaud + 1 | |
641 |
|
645 | |||
642 | self.datadecTime = numpy.zeros((self.__nChannels, self.ndatadec), dtype=numpy.complex) |
|
646 | self.datadecTime = numpy.zeros((self.__nChannels, self.ndatadec), dtype=numpy.complex) | |
643 |
|
647 | |||
644 | def convolutionInFreq(self, data): |
|
648 | def convolutionInFreq(self, data): | |
645 |
|
649 | |||
646 | fft_code = self.fft_code[self.__profIndex].reshape(1,-1) |
|
650 | fft_code = self.fft_code[self.__profIndex].reshape(1,-1) | |
647 |
|
651 | |||
648 | fft_data = numpy.fft.fft(data, axis=1) |
|
652 | fft_data = numpy.fft.fft(data, axis=1) | |
649 |
|
653 | |||
650 | conv = fft_data*fft_code |
|
654 | conv = fft_data*fft_code | |
651 |
|
655 | |||
652 | data = numpy.fft.ifft(conv,axis=1) |
|
656 | data = numpy.fft.ifft(conv,axis=1) | |
653 |
|
657 | |||
654 | datadec = data[:,:-self.nBaud+1] |
|
658 | datadec = data[:,:-self.nBaud+1] | |
655 |
|
659 | |||
656 | return datadec |
|
660 | return datadec | |
657 |
|
661 | |||
658 | def convolutionInFreqOpt(self, data): |
|
662 | def convolutionInFreqOpt(self, data): | |
659 |
|
663 | |||
660 | fft_code = self.fft_code[self.__profIndex].reshape(1,-1) |
|
664 | fft_code = self.fft_code[self.__profIndex].reshape(1,-1) | |
661 |
|
665 | |||
662 | data = cfunctions.decoder(fft_code, data) |
|
666 | data = cfunctions.decoder(fft_code, data) | |
663 |
|
667 | |||
664 | datadec = data[:,:-self.nBaud+1] |
|
668 | datadec = data[:,:-self.nBaud+1] | |
665 |
|
669 | |||
666 | return datadec |
|
670 | return datadec | |
667 |
|
671 | |||
668 | def convolutionInTime(self, data): |
|
672 | def convolutionInTime(self, data): | |
669 |
|
673 | |||
670 | code = self.code[self.__profIndex] |
|
674 | code = self.code[self.__profIndex] | |
671 |
|
675 | |||
672 | for i in range(self.__nChannels): |
|
676 | for i in range(self.__nChannels): | |
673 | self.datadecTime[i,:] = numpy.correlate(data[i,:], code, mode='valid') |
|
677 | self.datadecTime[i,:] = numpy.correlate(data[i,:], code, mode='valid') | |
674 |
|
678 | |||
675 | return self.datadecTime |
|
679 | return self.datadecTime | |
676 |
|
680 | |||
677 | def run(self, dataOut, code=None, nCode=None, nBaud=None, mode = 0): |
|
681 | def run(self, dataOut, code=None, nCode=None, nBaud=None, mode = 0): | |
678 |
|
682 | |||
679 | if code == None: |
|
683 | if code == None: | |
680 | code = dataOut.code |
|
684 | code = dataOut.code | |
681 | else: |
|
685 | else: | |
682 | code = numpy.array(code).reshape(nCode,nBaud) |
|
686 | code = numpy.array(code).reshape(nCode,nBaud) | |
683 | dataOut.code = code |
|
687 | dataOut.code = code | |
684 | dataOut.nCode = nCode |
|
688 | dataOut.nCode = nCode | |
685 | dataOut.nBaud = nBaud |
|
689 | dataOut.nBaud = nBaud | |
686 | dataOut.radarControllerHeaderObj.code = code |
|
690 | dataOut.radarControllerHeaderObj.code = code | |
687 | dataOut.radarControllerHeaderObj.nCode = nCode |
|
691 | dataOut.radarControllerHeaderObj.nCode = nCode | |
688 | dataOut.radarControllerHeaderObj.nBaud = nBaud |
|
692 | dataOut.radarControllerHeaderObj.nBaud = nBaud | |
689 |
|
693 | |||
690 |
|
694 | |||
691 | if not self.__isConfig: |
|
695 | if not self.__isConfig: | |
692 |
|
696 | |||
693 | self.setup(code, dataOut.data.shape) |
|
697 | self.setup(code, dataOut.data.shape) | |
694 | self.__isConfig = True |
|
698 | self.__isConfig = True | |
695 |
|
699 | |||
696 | if mode == 0: |
|
700 | if mode == 0: | |
697 | datadec = self.convolutionInTime(dataOut.data) |
|
701 | datadec = self.convolutionInTime(dataOut.data) | |
698 |
|
702 | |||
699 | if mode == 1: |
|
703 | if mode == 1: | |
700 | datadec = self.convolutionInFreq(dataOut.data) |
|
704 | datadec = self.convolutionInFreq(dataOut.data) | |
701 |
|
705 | |||
702 | if mode == 2: |
|
706 | if mode == 2: | |
703 | datadec = self.convolutionInFreqOpt(dataOut.data) |
|
707 | datadec = self.convolutionInFreqOpt(dataOut.data) | |
704 |
|
708 | |||
705 | dataOut.data = datadec |
|
709 | dataOut.data = datadec | |
706 |
|
710 | |||
707 | dataOut.heightList = dataOut.heightList[0:self.ndatadec] |
|
711 | dataOut.heightList = dataOut.heightList[0:self.ndatadec] | |
708 |
|
712 | |||
709 | dataOut.flagDecodeData = True #asumo q la data no esta decodificada |
|
713 | dataOut.flagDecodeData = True #asumo q la data no esta decodificada | |
710 |
|
714 | |||
711 | if self.__profIndex == self.nCode-1: |
|
715 | if self.__profIndex == self.nCode-1: | |
712 | self.__profIndex = 0 |
|
716 | self.__profIndex = 0 | |
713 | return 1 |
|
717 | return 1 | |
714 |
|
718 | |||
715 | self.__profIndex += 1 |
|
719 | self.__profIndex += 1 | |
716 |
|
720 | |||
717 | return 1 |
|
721 | return 1 | |
718 | # dataOut.flagDeflipData = True #asumo q la data no esta sin flip |
|
722 | # dataOut.flagDeflipData = True #asumo q la data no esta sin flip | |
719 |
|
723 | |||
720 |
|
724 | |||
721 |
|
725 | |||
722 | class SpectraProc(ProcessingUnit): |
|
726 | class SpectraProc(ProcessingUnit): | |
723 |
|
727 | |||
724 | def __init__(self): |
|
728 | def __init__(self): | |
725 |
|
729 | |||
726 | self.objectDict = {} |
|
730 | self.objectDict = {} | |
727 | self.buffer = None |
|
731 | self.buffer = None | |
728 | self.firstdatatime = None |
|
732 | self.firstdatatime = None | |
729 | self.profIndex = 0 |
|
733 | self.profIndex = 0 | |
730 | self.dataOut = Spectra() |
|
734 | self.dataOut = Spectra() | |
731 |
|
735 | |||
732 | def __updateObjFromInput(self): |
|
736 | def __updateObjFromInput(self): | |
733 |
|
737 | |||
734 | self.dataOut.timeZone = self.dataIn.timeZone |
|
738 | self.dataOut.timeZone = self.dataIn.timeZone | |
735 | self.dataOut.dstFlag = self.dataIn.dstFlag |
|
739 | self.dataOut.dstFlag = self.dataIn.dstFlag | |
736 | self.dataOut.errorCount = self.dataIn.errorCount |
|
740 | self.dataOut.errorCount = self.dataIn.errorCount | |
737 | self.dataOut.useLocalTime = self.dataIn.useLocalTime |
|
741 | self.dataOut.useLocalTime = self.dataIn.useLocalTime | |
738 |
|
742 | |||
739 | self.dataOut.radarControllerHeaderObj = self.dataIn.radarControllerHeaderObj.copy() |
|
743 | self.dataOut.radarControllerHeaderObj = self.dataIn.radarControllerHeaderObj.copy() | |
740 | self.dataOut.systemHeaderObj = self.dataIn.systemHeaderObj.copy() |
|
744 | self.dataOut.systemHeaderObj = self.dataIn.systemHeaderObj.copy() | |
741 | self.dataOut.channelList = self.dataIn.channelList |
|
745 | self.dataOut.channelList = self.dataIn.channelList | |
742 | self.dataOut.heightList = self.dataIn.heightList |
|
746 | self.dataOut.heightList = self.dataIn.heightList | |
743 | self.dataOut.dtype = numpy.dtype([('real','<f4'),('imag','<f4')]) |
|
747 | self.dataOut.dtype = numpy.dtype([('real','<f4'),('imag','<f4')]) | |
744 | # self.dataOut.nHeights = self.dataIn.nHeights |
|
748 | # self.dataOut.nHeights = self.dataIn.nHeights | |
745 | # self.dataOut.nChannels = self.dataIn.nChannels |
|
749 | # self.dataOut.nChannels = self.dataIn.nChannels | |
746 | self.dataOut.nBaud = self.dataIn.nBaud |
|
750 | self.dataOut.nBaud = self.dataIn.nBaud | |
747 | self.dataOut.nCode = self.dataIn.nCode |
|
751 | self.dataOut.nCode = self.dataIn.nCode | |
748 | self.dataOut.code = self.dataIn.code |
|
752 | self.dataOut.code = self.dataIn.code | |
749 | self.dataOut.nProfiles = self.dataOut.nFFTPoints |
|
753 | self.dataOut.nProfiles = self.dataOut.nFFTPoints | |
750 | # self.dataOut.channelIndexList = self.dataIn.channelIndexList |
|
754 | # self.dataOut.channelIndexList = self.dataIn.channelIndexList | |
751 | self.dataOut.flagTimeBlock = self.dataIn.flagTimeBlock |
|
755 | self.dataOut.flagTimeBlock = self.dataIn.flagTimeBlock | |
752 | self.dataOut.utctime = self.firstdatatime |
|
756 | self.dataOut.utctime = self.firstdatatime | |
753 | self.dataOut.flagDecodeData = self.dataIn.flagDecodeData #asumo q la data esta decodificada |
|
757 | self.dataOut.flagDecodeData = self.dataIn.flagDecodeData #asumo q la data esta decodificada | |
754 | self.dataOut.flagDeflipData = self.dataIn.flagDeflipData #asumo q la data esta sin flip |
|
758 | self.dataOut.flagDeflipData = self.dataIn.flagDeflipData #asumo q la data esta sin flip | |
755 | # self.dataOut.flagShiftFFT = self.dataIn.flagShiftFFT |
|
759 | # self.dataOut.flagShiftFFT = self.dataIn.flagShiftFFT | |
756 | self.dataOut.nCohInt = self.dataIn.nCohInt |
|
760 | self.dataOut.nCohInt = self.dataIn.nCohInt | |
757 | self.dataOut.nIncohInt = 1 |
|
761 | self.dataOut.nIncohInt = 1 | |
758 | self.dataOut.ippSeconds = self.dataIn.ippSeconds |
|
762 | self.dataOut.ippSeconds = self.dataIn.ippSeconds | |
759 | self.dataOut.windowOfFilter = self.dataIn.windowOfFilter |
|
763 | self.dataOut.windowOfFilter = self.dataIn.windowOfFilter | |
760 |
|
764 | |||
761 | self.dataOut.timeInterval = self.dataIn.timeInterval*self.dataOut.nFFTPoints*self.dataOut.nIncohInt |
|
765 | self.dataOut.timeInterval = self.dataIn.timeInterval*self.dataOut.nFFTPoints*self.dataOut.nIncohInt | |
762 | self.dataOut.frequency = self.dataIn.frequency |
|
766 | self.dataOut.frequency = self.dataIn.frequency | |
763 | self.dataOut.realtime = self.dataIn.realtime |
|
767 | self.dataOut.realtime = self.dataIn.realtime | |
764 |
|
768 | |||
765 | def __getFft(self): |
|
769 | def __getFft(self): | |
766 | """ |
|
770 | """ | |
767 | Convierte valores de Voltaje a Spectra |
|
771 | Convierte valores de Voltaje a Spectra | |
768 |
|
772 | |||
769 | Affected: |
|
773 | Affected: | |
770 | self.dataOut.data_spc |
|
774 | self.dataOut.data_spc | |
771 | self.dataOut.data_cspc |
|
775 | self.dataOut.data_cspc | |
772 | self.dataOut.data_dc |
|
776 | self.dataOut.data_dc | |
773 | self.dataOut.heightList |
|
777 | self.dataOut.heightList | |
774 | self.profIndex |
|
778 | self.profIndex | |
775 | self.buffer |
|
779 | self.buffer | |
776 | self.dataOut.flagNoData |
|
780 | self.dataOut.flagNoData | |
777 | """ |
|
781 | """ | |
778 | fft_volt = numpy.fft.fft(self.buffer,n=self.dataOut.nFFTPoints,axis=1) |
|
782 | fft_volt = numpy.fft.fft(self.buffer,n=self.dataOut.nFFTPoints,axis=1) | |
779 | fft_volt = fft_volt.astype(numpy.dtype('complex')) |
|
783 | fft_volt = fft_volt.astype(numpy.dtype('complex')) | |
780 | dc = fft_volt[:,0,:] |
|
784 | dc = fft_volt[:,0,:] | |
781 |
|
785 | |||
782 | #calculo de self-spectra |
|
786 | #calculo de self-spectra | |
783 | fft_volt = numpy.fft.fftshift(fft_volt,axes=(1,)) |
|
787 | fft_volt = numpy.fft.fftshift(fft_volt,axes=(1,)) | |
784 | spc = fft_volt * numpy.conjugate(fft_volt) |
|
788 | spc = fft_volt * numpy.conjugate(fft_volt) | |
785 | spc = spc.real |
|
789 | spc = spc.real | |
786 |
|
790 | |||
787 | blocksize = 0 |
|
791 | blocksize = 0 | |
788 | blocksize += dc.size |
|
792 | blocksize += dc.size | |
789 | blocksize += spc.size |
|
793 | blocksize += spc.size | |
790 |
|
794 | |||
791 | cspc = None |
|
795 | cspc = None | |
792 | pairIndex = 0 |
|
796 | pairIndex = 0 | |
793 | if self.dataOut.pairsList != None: |
|
797 | if self.dataOut.pairsList != None: | |
794 | #calculo de cross-spectra |
|
798 | #calculo de cross-spectra | |
795 | cspc = numpy.zeros((self.dataOut.nPairs, self.dataOut.nFFTPoints, self.dataOut.nHeights), dtype='complex') |
|
799 | cspc = numpy.zeros((self.dataOut.nPairs, self.dataOut.nFFTPoints, self.dataOut.nHeights), dtype='complex') | |
796 | for pair in self.dataOut.pairsList: |
|
800 | for pair in self.dataOut.pairsList: | |
797 | cspc[pairIndex,:,:] = fft_volt[pair[0],:,:] * numpy.conjugate(fft_volt[pair[1],:,:]) |
|
801 | cspc[pairIndex,:,:] = fft_volt[pair[0],:,:] * numpy.conjugate(fft_volt[pair[1],:,:]) | |
798 | pairIndex += 1 |
|
802 | pairIndex += 1 | |
799 | blocksize += cspc.size |
|
803 | blocksize += cspc.size | |
800 |
|
804 | |||
801 | self.dataOut.data_spc = spc |
|
805 | self.dataOut.data_spc = spc | |
802 | self.dataOut.data_cspc = cspc |
|
806 | self.dataOut.data_cspc = cspc | |
803 | self.dataOut.data_dc = dc |
|
807 | self.dataOut.data_dc = dc | |
804 | self.dataOut.blockSize = blocksize |
|
808 | self.dataOut.blockSize = blocksize | |
805 | self.dataOut.flagShiftFFT = False |
|
809 | self.dataOut.flagShiftFFT = False | |
806 |
|
810 | |||
807 | def init(self, nProfiles=None, nFFTPoints=None, pairsList=None, ippFactor=None): |
|
811 | def init(self, nProfiles=None, nFFTPoints=None, pairsList=None, ippFactor=None): | |
808 |
|
812 | |||
809 | self.dataOut.flagNoData = True |
|
813 | self.dataOut.flagNoData = True | |
810 |
|
814 | |||
811 | if self.dataIn.type == "Spectra": |
|
815 | if self.dataIn.type == "Spectra": | |
812 | self.dataOut.copy(self.dataIn) |
|
816 | self.dataOut.copy(self.dataIn) | |
813 | return |
|
817 | return | |
814 |
|
818 | |||
815 | if self.dataIn.type == "Voltage": |
|
819 | if self.dataIn.type == "Voltage": | |
816 |
|
820 | |||
817 | if nFFTPoints == None: |
|
821 | if nFFTPoints == None: | |
818 | raise ValueError, "This SpectraProc.init() need nFFTPoints input variable" |
|
822 | raise ValueError, "This SpectraProc.init() need nFFTPoints input variable" | |
819 |
|
823 | |||
820 | if pairsList == None: |
|
824 | if pairsList == None: | |
821 | nPairs = 0 |
|
825 | nPairs = 0 | |
822 | else: |
|
826 | else: | |
823 | nPairs = len(pairsList) |
|
827 | nPairs = len(pairsList) | |
824 |
|
828 | |||
825 | if ippFactor == None: |
|
829 | if ippFactor == None: | |
826 | ippFactor = 1 |
|
830 | ippFactor = 1 | |
827 | self.dataOut.ippFactor = ippFactor |
|
831 | self.dataOut.ippFactor = ippFactor | |
828 |
|
832 | |||
829 | self.dataOut.nFFTPoints = nFFTPoints |
|
833 | self.dataOut.nFFTPoints = nFFTPoints | |
830 | self.dataOut.pairsList = pairsList |
|
834 | self.dataOut.pairsList = pairsList | |
831 | self.dataOut.nPairs = nPairs |
|
835 | self.dataOut.nPairs = nPairs | |
832 |
|
836 | |||
833 | if self.buffer == None: |
|
837 | if self.buffer == None: | |
834 | self.buffer = numpy.zeros((self.dataIn.nChannels, |
|
838 | self.buffer = numpy.zeros((self.dataIn.nChannels, | |
835 | nProfiles, |
|
839 | nProfiles, | |
836 | self.dataIn.nHeights), |
|
840 | self.dataIn.nHeights), | |
837 | dtype='complex') |
|
841 | dtype='complex') | |
838 |
|
842 | |||
839 |
|
843 | |||
840 | self.buffer[:,self.profIndex,:] = self.dataIn.data.copy() |
|
844 | self.buffer[:,self.profIndex,:] = self.dataIn.data.copy() | |
841 | self.profIndex += 1 |
|
845 | self.profIndex += 1 | |
842 |
|
846 | |||
843 | if self.firstdatatime == None: |
|
847 | if self.firstdatatime == None: | |
844 | self.firstdatatime = self.dataIn.utctime |
|
848 | self.firstdatatime = self.dataIn.utctime | |
845 |
|
849 | |||
846 | if self.profIndex == nProfiles: |
|
850 | if self.profIndex == nProfiles: | |
847 | self.__updateObjFromInput() |
|
851 | self.__updateObjFromInput() | |
848 | self.__getFft() |
|
852 | self.__getFft() | |
849 |
|
853 | |||
850 | self.dataOut.flagNoData = False |
|
854 | self.dataOut.flagNoData = False | |
851 |
|
855 | |||
852 | self.buffer = None |
|
856 | self.buffer = None | |
853 | self.firstdatatime = None |
|
857 | self.firstdatatime = None | |
854 | self.profIndex = 0 |
|
858 | self.profIndex = 0 | |
855 |
|
859 | |||
856 | return |
|
860 | return | |
857 |
|
861 | |||
858 | raise ValueError, "The type object %s is not valid"%(self.dataIn.type) |
|
862 | raise ValueError, "The type object %s is not valid"%(self.dataIn.type) | |
859 |
|
863 | |||
860 | def selectChannels(self, channelList): |
|
864 | def selectChannels(self, channelList): | |
861 |
|
865 | |||
862 | channelIndexList = [] |
|
866 | channelIndexList = [] | |
863 |
|
867 | |||
864 | for channel in channelList: |
|
868 | for channel in channelList: | |
865 | index = self.dataOut.channelList.index(channel) |
|
869 | index = self.dataOut.channelList.index(channel) | |
866 | channelIndexList.append(index) |
|
870 | channelIndexList.append(index) | |
867 |
|
871 | |||
868 | self.selectChannelsByIndex(channelIndexList) |
|
872 | self.selectChannelsByIndex(channelIndexList) | |
869 |
|
873 | |||
870 | def selectChannelsByIndex(self, channelIndexList): |
|
874 | def selectChannelsByIndex(self, channelIndexList): | |
871 | """ |
|
875 | """ | |
872 | Selecciona un bloque de datos en base a canales segun el channelIndexList |
|
876 | Selecciona un bloque de datos en base a canales segun el channelIndexList | |
873 |
|
877 | |||
874 | Input: |
|
878 | Input: | |
875 | channelIndexList : lista sencilla de canales a seleccionar por ej. [2,3,7] |
|
879 | channelIndexList : lista sencilla de canales a seleccionar por ej. [2,3,7] | |
876 |
|
880 | |||
877 | Affected: |
|
881 | Affected: | |
878 | self.dataOut.data_spc |
|
882 | self.dataOut.data_spc | |
879 | self.dataOut.channelIndexList |
|
883 | self.dataOut.channelIndexList | |
880 | self.dataOut.nChannels |
|
884 | self.dataOut.nChannels | |
881 |
|
885 | |||
882 | Return: |
|
886 | Return: | |
883 | None |
|
887 | None | |
884 | """ |
|
888 | """ | |
885 |
|
889 | |||
886 | for channelIndex in channelIndexList: |
|
890 | for channelIndex in channelIndexList: | |
887 | if channelIndex not in self.dataOut.channelIndexList: |
|
891 | if channelIndex not in self.dataOut.channelIndexList: | |
888 | print channelIndexList |
|
892 | print channelIndexList | |
889 | raise ValueError, "The value %d in channelIndexList is not valid" %channelIndex |
|
893 | raise ValueError, "The value %d in channelIndexList is not valid" %channelIndex | |
890 |
|
894 | |||
891 | nChannels = len(channelIndexList) |
|
895 | nChannels = len(channelIndexList) | |
892 |
|
896 | |||
893 | data_spc = self.dataOut.data_spc[channelIndexList,:] |
|
897 | data_spc = self.dataOut.data_spc[channelIndexList,:] | |
894 |
|
898 | |||
895 | self.dataOut.data_spc = data_spc |
|
899 | self.dataOut.data_spc = data_spc | |
896 | self.dataOut.channelList = [self.dataOut.channelList[i] for i in channelIndexList] |
|
900 | self.dataOut.channelList = [self.dataOut.channelList[i] for i in channelIndexList] | |
897 | # self.dataOut.nChannels = nChannels |
|
901 | # self.dataOut.nChannels = nChannels | |
898 |
|
902 | |||
899 | return 1 |
|
903 | return 1 | |
900 |
|
904 | |||
901 | def selectHeights(self, minHei, maxHei): |
|
905 | def selectHeights(self, minHei, maxHei): | |
902 | """ |
|
906 | """ | |
903 | Selecciona un bloque de datos en base a un grupo de valores de alturas segun el rango |
|
907 | Selecciona un bloque de datos en base a un grupo de valores de alturas segun el rango | |
904 | minHei <= height <= maxHei |
|
908 | minHei <= height <= maxHei | |
905 |
|
909 | |||
906 | Input: |
|
910 | Input: | |
907 | minHei : valor minimo de altura a considerar |
|
911 | minHei : valor minimo de altura a considerar | |
908 | maxHei : valor maximo de altura a considerar |
|
912 | maxHei : valor maximo de altura a considerar | |
909 |
|
913 | |||
910 | Affected: |
|
914 | Affected: | |
911 | Indirectamente son cambiados varios valores a travez del metodo selectHeightsByIndex |
|
915 | Indirectamente son cambiados varios valores a travez del metodo selectHeightsByIndex | |
912 |
|
916 | |||
913 | Return: |
|
917 | Return: | |
914 | 1 si el metodo se ejecuto con exito caso contrario devuelve 0 |
|
918 | 1 si el metodo se ejecuto con exito caso contrario devuelve 0 | |
915 | """ |
|
919 | """ | |
916 | if (minHei < self.dataOut.heightList[0]) or (minHei > maxHei): |
|
920 | if (minHei < self.dataOut.heightList[0]) or (minHei > maxHei): | |
917 | raise ValueError, "some value in (%d,%d) is not valid" % (minHei, maxHei) |
|
921 | raise ValueError, "some value in (%d,%d) is not valid" % (minHei, maxHei) | |
918 |
|
922 | |||
919 | if (maxHei > self.dataOut.heightList[-1]): |
|
923 | if (maxHei > self.dataOut.heightList[-1]): | |
920 | maxHei = self.dataOut.heightList[-1] |
|
924 | maxHei = self.dataOut.heightList[-1] | |
921 | # raise ValueError, "some value in (%d,%d) is not valid" % (minHei, maxHei) |
|
925 | # raise ValueError, "some value in (%d,%d) is not valid" % (minHei, maxHei) | |
922 |
|
926 | |||
923 | minIndex = 0 |
|
927 | minIndex = 0 | |
924 | maxIndex = 0 |
|
928 | maxIndex = 0 | |
925 | heights = self.dataOut.heightList |
|
929 | heights = self.dataOut.heightList | |
926 |
|
930 | |||
927 | inda = numpy.where(heights >= minHei) |
|
931 | inda = numpy.where(heights >= minHei) | |
928 | indb = numpy.where(heights <= maxHei) |
|
932 | indb = numpy.where(heights <= maxHei) | |
929 |
|
933 | |||
930 | try: |
|
934 | try: | |
931 | minIndex = inda[0][0] |
|
935 | minIndex = inda[0][0] | |
932 | except: |
|
936 | except: | |
933 | minIndex = 0 |
|
937 | minIndex = 0 | |
934 |
|
938 | |||
935 | try: |
|
939 | try: | |
936 | maxIndex = indb[0][-1] |
|
940 | maxIndex = indb[0][-1] | |
937 | except: |
|
941 | except: | |
938 | maxIndex = len(heights) |
|
942 | maxIndex = len(heights) | |
939 |
|
943 | |||
940 | self.selectHeightsByIndex(minIndex, maxIndex) |
|
944 | self.selectHeightsByIndex(minIndex, maxIndex) | |
941 |
|
945 | |||
942 | return 1 |
|
946 | return 1 | |
943 |
|
947 | |||
944 | def getBeaconSignal(self, tauindex = 0, channelindex = 0, hei_ref=None): |
|
948 | def getBeaconSignal(self, tauindex = 0, channelindex = 0, hei_ref=None): | |
945 | newheis = numpy.where(self.dataOut.heightList>self.dataOut.radarControllerHeaderObj.Taus[tauindex]) |
|
949 | newheis = numpy.where(self.dataOut.heightList>self.dataOut.radarControllerHeaderObj.Taus[tauindex]) | |
946 |
|
950 | |||
947 | if hei_ref != None: |
|
951 | if hei_ref != None: | |
948 | newheis = numpy.where(self.dataOut.heightList>hei_ref) |
|
952 | newheis = numpy.where(self.dataOut.heightList>hei_ref) | |
949 |
|
953 | |||
950 | minIndex = min(newheis[0]) |
|
954 | minIndex = min(newheis[0]) | |
951 | maxIndex = max(newheis[0]) |
|
955 | maxIndex = max(newheis[0]) | |
952 | data_spc = self.dataOut.data_spc[:,:,minIndex:maxIndex+1] |
|
956 | data_spc = self.dataOut.data_spc[:,:,minIndex:maxIndex+1] | |
953 | heightList = self.dataOut.heightList[minIndex:maxIndex+1] |
|
957 | heightList = self.dataOut.heightList[minIndex:maxIndex+1] | |
954 |
|
958 | |||
955 | # determina indices |
|
959 | # determina indices | |
956 | nheis = int(self.dataOut.radarControllerHeaderObj.txB/(self.dataOut.heightList[1]-self.dataOut.heightList[0])) |
|
960 | nheis = int(self.dataOut.radarControllerHeaderObj.txB/(self.dataOut.heightList[1]-self.dataOut.heightList[0])) | |
957 | avg_dB = 10*numpy.log10(numpy.sum(data_spc[channelindex,:,:],axis=0)) |
|
961 | avg_dB = 10*numpy.log10(numpy.sum(data_spc[channelindex,:,:],axis=0)) | |
958 | beacon_dB = numpy.sort(avg_dB)[-nheis:] |
|
962 | beacon_dB = numpy.sort(avg_dB)[-nheis:] | |
959 | beacon_heiIndexList = [] |
|
963 | beacon_heiIndexList = [] | |
960 | for val in avg_dB.tolist(): |
|
964 | for val in avg_dB.tolist(): | |
961 | if val >= beacon_dB[0]: |
|
965 | if val >= beacon_dB[0]: | |
962 | beacon_heiIndexList.append(avg_dB.tolist().index(val)) |
|
966 | beacon_heiIndexList.append(avg_dB.tolist().index(val)) | |
963 |
|
967 | |||
964 | #data_spc = data_spc[:,:,beacon_heiIndexList] |
|
968 | #data_spc = data_spc[:,:,beacon_heiIndexList] | |
965 | data_cspc = None |
|
969 | data_cspc = None | |
966 | if self.dataOut.data_cspc != None: |
|
970 | if self.dataOut.data_cspc != None: | |
967 | data_cspc = self.dataOut.data_cspc[:,:,minIndex:maxIndex+1] |
|
971 | data_cspc = self.dataOut.data_cspc[:,:,minIndex:maxIndex+1] | |
968 | #data_cspc = data_cspc[:,:,beacon_heiIndexList] |
|
972 | #data_cspc = data_cspc[:,:,beacon_heiIndexList] | |
969 |
|
973 | |||
970 | data_dc = None |
|
974 | data_dc = None | |
971 | if self.dataOut.data_dc != None: |
|
975 | if self.dataOut.data_dc != None: | |
972 | data_dc = self.dataOut.data_dc[:,minIndex:maxIndex+1] |
|
976 | data_dc = self.dataOut.data_dc[:,minIndex:maxIndex+1] | |
973 | #data_dc = data_dc[:,beacon_heiIndexList] |
|
977 | #data_dc = data_dc[:,beacon_heiIndexList] | |
974 |
|
978 | |||
975 | self.dataOut.data_spc = data_spc |
|
979 | self.dataOut.data_spc = data_spc | |
976 | self.dataOut.data_cspc = data_cspc |
|
980 | self.dataOut.data_cspc = data_cspc | |
977 | self.dataOut.data_dc = data_dc |
|
981 | self.dataOut.data_dc = data_dc | |
978 | self.dataOut.heightList = heightList |
|
982 | self.dataOut.heightList = heightList | |
979 | self.dataOut.beacon_heiIndexList = beacon_heiIndexList |
|
983 | self.dataOut.beacon_heiIndexList = beacon_heiIndexList | |
980 |
|
984 | |||
981 | return 1 |
|
985 | return 1 | |
982 |
|
986 | |||
983 |
|
987 | |||
984 | def selectHeightsByIndex(self, minIndex, maxIndex): |
|
988 | def selectHeightsByIndex(self, minIndex, maxIndex): | |
985 | """ |
|
989 | """ | |
986 | Selecciona un bloque de datos en base a un grupo indices de alturas segun el rango |
|
990 | Selecciona un bloque de datos en base a un grupo indices de alturas segun el rango | |
987 | minIndex <= index <= maxIndex |
|
991 | minIndex <= index <= maxIndex | |
988 |
|
992 | |||
989 | Input: |
|
993 | Input: | |
990 | minIndex : valor de indice minimo de altura a considerar |
|
994 | minIndex : valor de indice minimo de altura a considerar | |
991 | maxIndex : valor de indice maximo de altura a considerar |
|
995 | maxIndex : valor de indice maximo de altura a considerar | |
992 |
|
996 | |||
993 | Affected: |
|
997 | Affected: | |
994 | self.dataOut.data_spc |
|
998 | self.dataOut.data_spc | |
995 | self.dataOut.data_cspc |
|
999 | self.dataOut.data_cspc | |
996 | self.dataOut.data_dc |
|
1000 | self.dataOut.data_dc | |
997 | self.dataOut.heightList |
|
1001 | self.dataOut.heightList | |
998 |
|
1002 | |||
999 | Return: |
|
1003 | Return: | |
1000 | 1 si el metodo se ejecuto con exito caso contrario devuelve 0 |
|
1004 | 1 si el metodo se ejecuto con exito caso contrario devuelve 0 | |
1001 | """ |
|
1005 | """ | |
1002 |
|
1006 | |||
1003 | if (minIndex < 0) or (minIndex > maxIndex): |
|
1007 | if (minIndex < 0) or (minIndex > maxIndex): | |
1004 | raise ValueError, "some value in (%d,%d) is not valid" % (minIndex, maxIndex) |
|
1008 | raise ValueError, "some value in (%d,%d) is not valid" % (minIndex, maxIndex) | |
1005 |
|
1009 | |||
1006 | if (maxIndex >= self.dataOut.nHeights): |
|
1010 | if (maxIndex >= self.dataOut.nHeights): | |
1007 | maxIndex = self.dataOut.nHeights-1 |
|
1011 | maxIndex = self.dataOut.nHeights-1 | |
1008 | # raise ValueError, "some value in (%d,%d) is not valid" % (minIndex, maxIndex) |
|
1012 | # raise ValueError, "some value in (%d,%d) is not valid" % (minIndex, maxIndex) | |
1009 |
|
1013 | |||
1010 | nHeights = maxIndex - minIndex + 1 |
|
1014 | nHeights = maxIndex - minIndex + 1 | |
1011 |
|
1015 | |||
1012 | #Spectra |
|
1016 | #Spectra | |
1013 | data_spc = self.dataOut.data_spc[:,:,minIndex:maxIndex+1] |
|
1017 | data_spc = self.dataOut.data_spc[:,:,minIndex:maxIndex+1] | |
1014 |
|
1018 | |||
1015 | data_cspc = None |
|
1019 | data_cspc = None | |
1016 | if self.dataOut.data_cspc != None: |
|
1020 | if self.dataOut.data_cspc != None: | |
1017 | data_cspc = self.dataOut.data_cspc[:,:,minIndex:maxIndex+1] |
|
1021 | data_cspc = self.dataOut.data_cspc[:,:,minIndex:maxIndex+1] | |
1018 |
|
1022 | |||
1019 | data_dc = None |
|
1023 | data_dc = None | |
1020 | if self.dataOut.data_dc != None: |
|
1024 | if self.dataOut.data_dc != None: | |
1021 | data_dc = self.dataOut.data_dc[:,minIndex:maxIndex+1] |
|
1025 | data_dc = self.dataOut.data_dc[:,minIndex:maxIndex+1] | |
1022 |
|
1026 | |||
1023 | self.dataOut.data_spc = data_spc |
|
1027 | self.dataOut.data_spc = data_spc | |
1024 | self.dataOut.data_cspc = data_cspc |
|
1028 | self.dataOut.data_cspc = data_cspc | |
1025 | self.dataOut.data_dc = data_dc |
|
1029 | self.dataOut.data_dc = data_dc | |
1026 |
|
1030 | |||
1027 | self.dataOut.heightList = self.dataOut.heightList[minIndex:maxIndex+1] |
|
1031 | self.dataOut.heightList = self.dataOut.heightList[minIndex:maxIndex+1] | |
1028 |
|
1032 | |||
1029 | return 1 |
|
1033 | return 1 | |
1030 |
|
1034 | |||
1031 | def removeDC(self, mode = 2): |
|
1035 | def removeDC(self, mode = 2): | |
1032 | jspectra = self.dataOut.data_spc |
|
1036 | jspectra = self.dataOut.data_spc | |
1033 | jcspectra = self.dataOut.data_cspc |
|
1037 | jcspectra = self.dataOut.data_cspc | |
1034 |
|
1038 | |||
1035 |
|
1039 | |||
1036 | num_chan = jspectra.shape[0] |
|
1040 | num_chan = jspectra.shape[0] | |
1037 | num_hei = jspectra.shape[2] |
|
1041 | num_hei = jspectra.shape[2] | |
1038 |
|
1042 | |||
1039 | if jcspectra != None: |
|
1043 | if jcspectra != None: | |
1040 | jcspectraExist = True |
|
1044 | jcspectraExist = True | |
1041 | num_pairs = jcspectra.shape[0] |
|
1045 | num_pairs = jcspectra.shape[0] | |
1042 | else: jcspectraExist = False |
|
1046 | else: jcspectraExist = False | |
1043 |
|
1047 | |||
1044 | freq_dc = jspectra.shape[1]/2 |
|
1048 | freq_dc = jspectra.shape[1]/2 | |
1045 | ind_vel = numpy.array([-2,-1,1,2]) + freq_dc |
|
1049 | ind_vel = numpy.array([-2,-1,1,2]) + freq_dc | |
1046 |
|
1050 | |||
1047 | if ind_vel[0]<0: |
|
1051 | if ind_vel[0]<0: | |
1048 | ind_vel[range(0,1)] = ind_vel[range(0,1)] + self.num_prof |
|
1052 | ind_vel[range(0,1)] = ind_vel[range(0,1)] + self.num_prof | |
1049 |
|
1053 | |||
1050 | if mode == 1: |
|
1054 | if mode == 1: | |
1051 | jspectra[:,freq_dc,:] = (jspectra[:,ind_vel[1],:] + jspectra[:,ind_vel[2],:])/2 #CORRECCION |
|
1055 | jspectra[:,freq_dc,:] = (jspectra[:,ind_vel[1],:] + jspectra[:,ind_vel[2],:])/2 #CORRECCION | |
1052 |
|
1056 | |||
1053 | if jcspectraExist: |
|
1057 | if jcspectraExist: | |
1054 | jcspectra[:,freq_dc,:] = (jcspectra[:,ind_vel[1],:] + jcspectra[:,ind_vel[2],:])/2 |
|
1058 | jcspectra[:,freq_dc,:] = (jcspectra[:,ind_vel[1],:] + jcspectra[:,ind_vel[2],:])/2 | |
1055 |
|
1059 | |||
1056 | if mode == 2: |
|
1060 | if mode == 2: | |
1057 |
|
1061 | |||
1058 | vel = numpy.array([-2,-1,1,2]) |
|
1062 | vel = numpy.array([-2,-1,1,2]) | |
1059 | xx = numpy.zeros([4,4]) |
|
1063 | xx = numpy.zeros([4,4]) | |
1060 |
|
1064 | |||
1061 | for fil in range(4): |
|
1065 | for fil in range(4): | |
1062 | xx[fil,:] = vel[fil]**numpy.asarray(range(4)) |
|
1066 | xx[fil,:] = vel[fil]**numpy.asarray(range(4)) | |
1063 |
|
1067 | |||
1064 | xx_inv = numpy.linalg.inv(xx) |
|
1068 | xx_inv = numpy.linalg.inv(xx) | |
1065 | xx_aux = xx_inv[0,:] |
|
1069 | xx_aux = xx_inv[0,:] | |
1066 |
|
1070 | |||
1067 | for ich in range(num_chan): |
|
1071 | for ich in range(num_chan): | |
1068 | yy = jspectra[ich,ind_vel,:] |
|
1072 | yy = jspectra[ich,ind_vel,:] | |
1069 | jspectra[ich,freq_dc,:] = numpy.dot(xx_aux,yy) |
|
1073 | jspectra[ich,freq_dc,:] = numpy.dot(xx_aux,yy) | |
1070 |
|
1074 | |||
1071 | junkid = jspectra[ich,freq_dc,:]<=0 |
|
1075 | junkid = jspectra[ich,freq_dc,:]<=0 | |
1072 | cjunkid = sum(junkid) |
|
1076 | cjunkid = sum(junkid) | |
1073 |
|
1077 | |||
1074 | if cjunkid.any(): |
|
1078 | if cjunkid.any(): | |
1075 | jspectra[ich,freq_dc,junkid.nonzero()] = (jspectra[ich,ind_vel[1],junkid] + jspectra[ich,ind_vel[2],junkid])/2 |
|
1079 | jspectra[ich,freq_dc,junkid.nonzero()] = (jspectra[ich,ind_vel[1],junkid] + jspectra[ich,ind_vel[2],junkid])/2 | |
1076 |
|
1080 | |||
1077 | if jcspectraExist: |
|
1081 | if jcspectraExist: | |
1078 | for ip in range(num_pairs): |
|
1082 | for ip in range(num_pairs): | |
1079 | yy = jcspectra[ip,ind_vel,:] |
|
1083 | yy = jcspectra[ip,ind_vel,:] | |
1080 | jcspectra[ip,freq_dc,:] = numpy.dot(xx_aux,yy) |
|
1084 | jcspectra[ip,freq_dc,:] = numpy.dot(xx_aux,yy) | |
1081 |
|
1085 | |||
1082 |
|
1086 | |||
1083 | self.dataOut.data_spc = jspectra |
|
1087 | self.dataOut.data_spc = jspectra | |
1084 | self.dataOut.data_cspc = jcspectra |
|
1088 | self.dataOut.data_cspc = jcspectra | |
1085 |
|
1089 | |||
1086 | return 1 |
|
1090 | return 1 | |
1087 |
|
1091 | |||
1088 | def removeInterference(self, interf = 2,hei_interf = None, nhei_interf = None, offhei_interf = None): |
|
1092 | def removeInterference(self, interf = 2,hei_interf = None, nhei_interf = None, offhei_interf = None): | |
1089 |
|
1093 | |||
1090 | jspectra = self.dataOut.data_spc |
|
1094 | jspectra = self.dataOut.data_spc | |
1091 | jcspectra = self.dataOut.data_cspc |
|
1095 | jcspectra = self.dataOut.data_cspc | |
1092 | jnoise = self.dataOut.getNoise() |
|
1096 | jnoise = self.dataOut.getNoise() | |
1093 | num_incoh = self.dataOut.nIncohInt |
|
1097 | num_incoh = self.dataOut.nIncohInt | |
1094 |
|
1098 | |||
1095 | num_channel = jspectra.shape[0] |
|
1099 | num_channel = jspectra.shape[0] | |
1096 | num_prof = jspectra.shape[1] |
|
1100 | num_prof = jspectra.shape[1] | |
1097 | num_hei = jspectra.shape[2] |
|
1101 | num_hei = jspectra.shape[2] | |
1098 |
|
1102 | |||
1099 | #hei_interf |
|
1103 | #hei_interf | |
1100 | if hei_interf == None: |
|
1104 | if hei_interf == None: | |
1101 | count_hei = num_hei/2 #Como es entero no importa |
|
1105 | count_hei = num_hei/2 #Como es entero no importa | |
1102 | hei_interf = numpy.asmatrix(range(count_hei)) + num_hei - count_hei |
|
1106 | hei_interf = numpy.asmatrix(range(count_hei)) + num_hei - count_hei | |
1103 | hei_interf = numpy.asarray(hei_interf)[0] |
|
1107 | hei_interf = numpy.asarray(hei_interf)[0] | |
1104 | #nhei_interf |
|
1108 | #nhei_interf | |
1105 | if (nhei_interf == None): |
|
1109 | if (nhei_interf == None): | |
1106 | nhei_interf = 5 |
|
1110 | nhei_interf = 5 | |
1107 | if (nhei_interf < 1): |
|
1111 | if (nhei_interf < 1): | |
1108 | nhei_interf = 1 |
|
1112 | nhei_interf = 1 | |
1109 | if (nhei_interf > count_hei): |
|
1113 | if (nhei_interf > count_hei): | |
1110 | nhei_interf = count_hei |
|
1114 | nhei_interf = count_hei | |
1111 | if (offhei_interf == None): |
|
1115 | if (offhei_interf == None): | |
1112 | offhei_interf = 0 |
|
1116 | offhei_interf = 0 | |
1113 |
|
1117 | |||
1114 | ind_hei = range(num_hei) |
|
1118 | ind_hei = range(num_hei) | |
1115 | # mask_prof = numpy.asarray(range(num_prof - 2)) + 1 |
|
1119 | # mask_prof = numpy.asarray(range(num_prof - 2)) + 1 | |
1116 | # mask_prof[range(num_prof/2 - 1,len(mask_prof))] += 1 |
|
1120 | # mask_prof[range(num_prof/2 - 1,len(mask_prof))] += 1 | |
1117 | mask_prof = numpy.asarray(range(num_prof)) |
|
1121 | mask_prof = numpy.asarray(range(num_prof)) | |
1118 | num_mask_prof = mask_prof.size |
|
1122 | num_mask_prof = mask_prof.size | |
1119 | comp_mask_prof = [0, num_prof/2] |
|
1123 | comp_mask_prof = [0, num_prof/2] | |
1120 |
|
1124 | |||
1121 |
|
1125 | |||
1122 | #noise_exist: Determina si la variable jnoise ha sido definida y contiene la informacion del ruido de cada canal |
|
1126 | #noise_exist: Determina si la variable jnoise ha sido definida y contiene la informacion del ruido de cada canal | |
1123 | if (jnoise.size < num_channel or numpy.isnan(jnoise).any()): |
|
1127 | if (jnoise.size < num_channel or numpy.isnan(jnoise).any()): | |
1124 | jnoise = numpy.nan |
|
1128 | jnoise = numpy.nan | |
1125 | noise_exist = jnoise[0] < numpy.Inf |
|
1129 | noise_exist = jnoise[0] < numpy.Inf | |
1126 |
|
1130 | |||
1127 | #Subrutina de Remocion de la Interferencia |
|
1131 | #Subrutina de Remocion de la Interferencia | |
1128 | for ich in range(num_channel): |
|
1132 | for ich in range(num_channel): | |
1129 | #Se ordena los espectros segun su potencia (menor a mayor) |
|
1133 | #Se ordena los espectros segun su potencia (menor a mayor) | |
1130 | power = jspectra[ich,mask_prof,:] |
|
1134 | power = jspectra[ich,mask_prof,:] | |
1131 | power = power[:,hei_interf] |
|
1135 | power = power[:,hei_interf] | |
1132 | power = power.sum(axis = 0) |
|
1136 | power = power.sum(axis = 0) | |
1133 | psort = power.ravel().argsort() |
|
1137 | psort = power.ravel().argsort() | |
1134 |
|
1138 | |||
1135 | #Se estima la interferencia promedio en los Espectros de Potencia empleando |
|
1139 | #Se estima la interferencia promedio en los Espectros de Potencia empleando | |
1136 | junkspc_interf = jspectra[ich,:,hei_interf[psort[range(offhei_interf, nhei_interf + offhei_interf)]]] |
|
1140 | junkspc_interf = jspectra[ich,:,hei_interf[psort[range(offhei_interf, nhei_interf + offhei_interf)]]] | |
1137 |
|
1141 | |||
1138 | if noise_exist: |
|
1142 | if noise_exist: | |
1139 | # tmp_noise = jnoise[ich] / num_prof |
|
1143 | # tmp_noise = jnoise[ich] / num_prof | |
1140 | tmp_noise = jnoise[ich] |
|
1144 | tmp_noise = jnoise[ich] | |
1141 | junkspc_interf = junkspc_interf - tmp_noise |
|
1145 | junkspc_interf = junkspc_interf - tmp_noise | |
1142 | #junkspc_interf[:,comp_mask_prof] = 0 |
|
1146 | #junkspc_interf[:,comp_mask_prof] = 0 | |
1143 |
|
1147 | |||
1144 | jspc_interf = junkspc_interf.sum(axis = 0) / nhei_interf |
|
1148 | jspc_interf = junkspc_interf.sum(axis = 0) / nhei_interf | |
1145 | jspc_interf = jspc_interf.transpose() |
|
1149 | jspc_interf = jspc_interf.transpose() | |
1146 | #Calculando el espectro de interferencia promedio |
|
1150 | #Calculando el espectro de interferencia promedio | |
1147 | noiseid = numpy.where(jspc_interf <= tmp_noise/ math.sqrt(num_incoh)) |
|
1151 | noiseid = numpy.where(jspc_interf <= tmp_noise/ math.sqrt(num_incoh)) | |
1148 | noiseid = noiseid[0] |
|
1152 | noiseid = noiseid[0] | |
1149 | cnoiseid = noiseid.size |
|
1153 | cnoiseid = noiseid.size | |
1150 | interfid = numpy.where(jspc_interf > tmp_noise/ math.sqrt(num_incoh)) |
|
1154 | interfid = numpy.where(jspc_interf > tmp_noise/ math.sqrt(num_incoh)) | |
1151 | interfid = interfid[0] |
|
1155 | interfid = interfid[0] | |
1152 | cinterfid = interfid.size |
|
1156 | cinterfid = interfid.size | |
1153 |
|
1157 | |||
1154 | if (cnoiseid > 0): jspc_interf[noiseid] = 0 |
|
1158 | if (cnoiseid > 0): jspc_interf[noiseid] = 0 | |
1155 |
|
1159 | |||
1156 | #Expandiendo los perfiles a limpiar |
|
1160 | #Expandiendo los perfiles a limpiar | |
1157 | if (cinterfid > 0): |
|
1161 | if (cinterfid > 0): | |
1158 | new_interfid = (numpy.r_[interfid - 1, interfid, interfid + 1] + num_prof)%num_prof |
|
1162 | new_interfid = (numpy.r_[interfid - 1, interfid, interfid + 1] + num_prof)%num_prof | |
1159 | new_interfid = numpy.asarray(new_interfid) |
|
1163 | new_interfid = numpy.asarray(new_interfid) | |
1160 | new_interfid = {x for x in new_interfid} |
|
1164 | new_interfid = {x for x in new_interfid} | |
1161 | new_interfid = numpy.array(list(new_interfid)) |
|
1165 | new_interfid = numpy.array(list(new_interfid)) | |
1162 | new_cinterfid = new_interfid.size |
|
1166 | new_cinterfid = new_interfid.size | |
1163 | else: new_cinterfid = 0 |
|
1167 | else: new_cinterfid = 0 | |
1164 |
|
1168 | |||
1165 | for ip in range(new_cinterfid): |
|
1169 | for ip in range(new_cinterfid): | |
1166 | ind = junkspc_interf[:,new_interfid[ip]].ravel().argsort() |
|
1170 | ind = junkspc_interf[:,new_interfid[ip]].ravel().argsort() | |
1167 | jspc_interf[new_interfid[ip]] = junkspc_interf[ind[nhei_interf/2],new_interfid[ip]] |
|
1171 | jspc_interf[new_interfid[ip]] = junkspc_interf[ind[nhei_interf/2],new_interfid[ip]] | |
1168 |
|
1172 | |||
1169 |
|
1173 | |||
1170 | jspectra[ich,:,ind_hei] = jspectra[ich,:,ind_hei] - jspc_interf #Corregir indices |
|
1174 | jspectra[ich,:,ind_hei] = jspectra[ich,:,ind_hei] - jspc_interf #Corregir indices | |
1171 |
|
1175 | |||
1172 | #Removiendo la interferencia del punto de mayor interferencia |
|
1176 | #Removiendo la interferencia del punto de mayor interferencia | |
1173 | ListAux = jspc_interf[mask_prof].tolist() |
|
1177 | ListAux = jspc_interf[mask_prof].tolist() | |
1174 | maxid = ListAux.index(max(ListAux)) |
|
1178 | maxid = ListAux.index(max(ListAux)) | |
1175 |
|
1179 | |||
1176 |
|
1180 | |||
1177 | if cinterfid > 0: |
|
1181 | if cinterfid > 0: | |
1178 | for ip in range(cinterfid*(interf == 2) - 1): |
|
1182 | for ip in range(cinterfid*(interf == 2) - 1): | |
1179 | ind = (jspectra[ich,interfid[ip],:] < tmp_noise*(1 + 1/math.sqrt(num_incoh))).nonzero() |
|
1183 | ind = (jspectra[ich,interfid[ip],:] < tmp_noise*(1 + 1/math.sqrt(num_incoh))).nonzero() | |
1180 | cind = len(ind) |
|
1184 | cind = len(ind) | |
1181 |
|
1185 | |||
1182 | if (cind > 0): |
|
1186 | if (cind > 0): | |
1183 | jspectra[ich,interfid[ip],ind] = tmp_noise*(1 + (numpy.random.uniform(cind) - 0.5)/math.sqrt(num_incoh)) |
|
1187 | jspectra[ich,interfid[ip],ind] = tmp_noise*(1 + (numpy.random.uniform(cind) - 0.5)/math.sqrt(num_incoh)) | |
1184 |
|
1188 | |||
1185 | ind = numpy.array([-2,-1,1,2]) |
|
1189 | ind = numpy.array([-2,-1,1,2]) | |
1186 | xx = numpy.zeros([4,4]) |
|
1190 | xx = numpy.zeros([4,4]) | |
1187 |
|
1191 | |||
1188 | for id1 in range(4): |
|
1192 | for id1 in range(4): | |
1189 | xx[:,id1] = ind[id1]**numpy.asarray(range(4)) |
|
1193 | xx[:,id1] = ind[id1]**numpy.asarray(range(4)) | |
1190 |
|
1194 | |||
1191 | xx_inv = numpy.linalg.inv(xx) |
|
1195 | xx_inv = numpy.linalg.inv(xx) | |
1192 | xx = xx_inv[:,0] |
|
1196 | xx = xx_inv[:,0] | |
1193 | ind = (ind + maxid + num_mask_prof)%num_mask_prof |
|
1197 | ind = (ind + maxid + num_mask_prof)%num_mask_prof | |
1194 | yy = jspectra[ich,mask_prof[ind],:] |
|
1198 | yy = jspectra[ich,mask_prof[ind],:] | |
1195 | jspectra[ich,mask_prof[maxid],:] = numpy.dot(yy.transpose(),xx) |
|
1199 | jspectra[ich,mask_prof[maxid],:] = numpy.dot(yy.transpose(),xx) | |
1196 |
|
1200 | |||
1197 |
|
1201 | |||
1198 | indAux = (jspectra[ich,:,:] < tmp_noise*(1-1/math.sqrt(num_incoh))).nonzero() |
|
1202 | indAux = (jspectra[ich,:,:] < tmp_noise*(1-1/math.sqrt(num_incoh))).nonzero() | |
1199 | jspectra[ich,indAux[0],indAux[1]] = tmp_noise * (1 - 1/math.sqrt(num_incoh)) |
|
1203 | jspectra[ich,indAux[0],indAux[1]] = tmp_noise * (1 - 1/math.sqrt(num_incoh)) | |
1200 |
|
1204 | |||
1201 | #Remocion de Interferencia en el Cross Spectra |
|
1205 | #Remocion de Interferencia en el Cross Spectra | |
1202 | if jcspectra == None: return jspectra, jcspectra |
|
1206 | if jcspectra == None: return jspectra, jcspectra | |
1203 | num_pairs = jcspectra.size/(num_prof*num_hei) |
|
1207 | num_pairs = jcspectra.size/(num_prof*num_hei) | |
1204 | jcspectra = jcspectra.reshape(num_pairs, num_prof, num_hei) |
|
1208 | jcspectra = jcspectra.reshape(num_pairs, num_prof, num_hei) | |
1205 |
|
1209 | |||
1206 | for ip in range(num_pairs): |
|
1210 | for ip in range(num_pairs): | |
1207 |
|
1211 | |||
1208 | #------------------------------------------- |
|
1212 | #------------------------------------------- | |
1209 |
|
1213 | |||
1210 | cspower = numpy.abs(jcspectra[ip,mask_prof,:]) |
|
1214 | cspower = numpy.abs(jcspectra[ip,mask_prof,:]) | |
1211 | cspower = cspower[:,hei_interf] |
|
1215 | cspower = cspower[:,hei_interf] | |
1212 | cspower = cspower.sum(axis = 0) |
|
1216 | cspower = cspower.sum(axis = 0) | |
1213 |
|
1217 | |||
1214 | cspsort = cspower.ravel().argsort() |
|
1218 | cspsort = cspower.ravel().argsort() | |
1215 | junkcspc_interf = jcspectra[ip,:,hei_interf[cspsort[range(offhei_interf, nhei_interf + offhei_interf)]]] |
|
1219 | junkcspc_interf = jcspectra[ip,:,hei_interf[cspsort[range(offhei_interf, nhei_interf + offhei_interf)]]] | |
1216 | junkcspc_interf = junkcspc_interf.transpose() |
|
1220 | junkcspc_interf = junkcspc_interf.transpose() | |
1217 | jcspc_interf = junkcspc_interf.sum(axis = 1)/nhei_interf |
|
1221 | jcspc_interf = junkcspc_interf.sum(axis = 1)/nhei_interf | |
1218 |
|
1222 | |||
1219 | ind = numpy.abs(jcspc_interf[mask_prof]).ravel().argsort() |
|
1223 | ind = numpy.abs(jcspc_interf[mask_prof]).ravel().argsort() | |
1220 |
|
1224 | |||
1221 | median_real = numpy.median(numpy.real(junkcspc_interf[mask_prof[ind[range(3*num_prof/4)]],:])) |
|
1225 | median_real = numpy.median(numpy.real(junkcspc_interf[mask_prof[ind[range(3*num_prof/4)]],:])) | |
1222 | median_imag = numpy.median(numpy.imag(junkcspc_interf[mask_prof[ind[range(3*num_prof/4)]],:])) |
|
1226 | median_imag = numpy.median(numpy.imag(junkcspc_interf[mask_prof[ind[range(3*num_prof/4)]],:])) | |
1223 | junkcspc_interf[comp_mask_prof,:] = numpy.complex(median_real, median_imag) |
|
1227 | junkcspc_interf[comp_mask_prof,:] = numpy.complex(median_real, median_imag) | |
1224 |
|
1228 | |||
1225 | for iprof in range(num_prof): |
|
1229 | for iprof in range(num_prof): | |
1226 | ind = numpy.abs(junkcspc_interf[iprof,:]).ravel().argsort() |
|
1230 | ind = numpy.abs(junkcspc_interf[iprof,:]).ravel().argsort() | |
1227 | jcspc_interf[iprof] = junkcspc_interf[iprof, ind[nhei_interf/2]] |
|
1231 | jcspc_interf[iprof] = junkcspc_interf[iprof, ind[nhei_interf/2]] | |
1228 |
|
1232 | |||
1229 | #Removiendo la Interferencia |
|
1233 | #Removiendo la Interferencia | |
1230 | jcspectra[ip,:,ind_hei] = jcspectra[ip,:,ind_hei] - jcspc_interf |
|
1234 | jcspectra[ip,:,ind_hei] = jcspectra[ip,:,ind_hei] - jcspc_interf | |
1231 |
|
1235 | |||
1232 | ListAux = numpy.abs(jcspc_interf[mask_prof]).tolist() |
|
1236 | ListAux = numpy.abs(jcspc_interf[mask_prof]).tolist() | |
1233 | maxid = ListAux.index(max(ListAux)) |
|
1237 | maxid = ListAux.index(max(ListAux)) | |
1234 |
|
1238 | |||
1235 | ind = numpy.array([-2,-1,1,2]) |
|
1239 | ind = numpy.array([-2,-1,1,2]) | |
1236 | xx = numpy.zeros([4,4]) |
|
1240 | xx = numpy.zeros([4,4]) | |
1237 |
|
1241 | |||
1238 | for id1 in range(4): |
|
1242 | for id1 in range(4): | |
1239 | xx[:,id1] = ind[id1]**numpy.asarray(range(4)) |
|
1243 | xx[:,id1] = ind[id1]**numpy.asarray(range(4)) | |
1240 |
|
1244 | |||
1241 | xx_inv = numpy.linalg.inv(xx) |
|
1245 | xx_inv = numpy.linalg.inv(xx) | |
1242 | xx = xx_inv[:,0] |
|
1246 | xx = xx_inv[:,0] | |
1243 |
|
1247 | |||
1244 | ind = (ind + maxid + num_mask_prof)%num_mask_prof |
|
1248 | ind = (ind + maxid + num_mask_prof)%num_mask_prof | |
1245 | yy = jcspectra[ip,mask_prof[ind],:] |
|
1249 | yy = jcspectra[ip,mask_prof[ind],:] | |
1246 | jcspectra[ip,mask_prof[maxid],:] = numpy.dot(yy.transpose(),xx) |
|
1250 | jcspectra[ip,mask_prof[maxid],:] = numpy.dot(yy.transpose(),xx) | |
1247 |
|
1251 | |||
1248 | #Guardar Resultados |
|
1252 | #Guardar Resultados | |
1249 | self.dataOut.data_spc = jspectra |
|
1253 | self.dataOut.data_spc = jspectra | |
1250 | self.dataOut.data_cspc = jcspectra |
|
1254 | self.dataOut.data_cspc = jcspectra | |
1251 |
|
1255 | |||
1252 | return 1 |
|
1256 | return 1 | |
1253 |
|
1257 | |||
1254 | def setRadarFrequency(self, frequency=None): |
|
1258 | def setRadarFrequency(self, frequency=None): | |
1255 | if frequency != None: |
|
1259 | if frequency != None: | |
1256 | self.dataOut.frequency = frequency |
|
1260 | self.dataOut.frequency = frequency | |
1257 |
|
1261 | |||
1258 | return 1 |
|
1262 | return 1 | |
1259 |
|
1263 | |||
1260 | def getNoise(self, minHei=None, maxHei=None, minVel=None, maxVel=None): |
|
1264 | def getNoise(self, minHei=None, maxHei=None, minVel=None, maxVel=None): | |
1261 | #validacion de rango |
|
1265 | #validacion de rango | |
1262 | if minHei == None: |
|
1266 | if minHei == None: | |
1263 | minHei = self.dataOut.heightList[0] |
|
1267 | minHei = self.dataOut.heightList[0] | |
1264 |
|
1268 | |||
1265 | if maxHei == None: |
|
1269 | if maxHei == None: | |
1266 | maxHei = self.dataOut.heightList[-1] |
|
1270 | maxHei = self.dataOut.heightList[-1] | |
1267 |
|
1271 | |||
1268 | if (minHei < self.dataOut.heightList[0]) or (minHei > maxHei): |
|
1272 | if (minHei < self.dataOut.heightList[0]) or (minHei > maxHei): | |
1269 | print 'minHei: %.2f is out of the heights range'%(minHei) |
|
1273 | print 'minHei: %.2f is out of the heights range'%(minHei) | |
1270 | print 'minHei is setting to %.2f'%(self.dataOut.heightList[0]) |
|
1274 | print 'minHei is setting to %.2f'%(self.dataOut.heightList[0]) | |
1271 | minHei = self.dataOut.heightList[0] |
|
1275 | minHei = self.dataOut.heightList[0] | |
1272 |
|
1276 | |||
1273 | if (maxHei > self.dataOut.heightList[-1]) or (maxHei < minHei): |
|
1277 | if (maxHei > self.dataOut.heightList[-1]) or (maxHei < minHei): | |
1274 | print 'maxHei: %.2f is out of the heights range'%(maxHei) |
|
1278 | print 'maxHei: %.2f is out of the heights range'%(maxHei) | |
1275 | print 'maxHei is setting to %.2f'%(self.dataOut.heightList[-1]) |
|
1279 | print 'maxHei is setting to %.2f'%(self.dataOut.heightList[-1]) | |
1276 | maxHei = self.dataOut.heightList[-1] |
|
1280 | maxHei = self.dataOut.heightList[-1] | |
1277 |
|
1281 | |||
1278 | # validacion de velocidades |
|
1282 | # validacion de velocidades | |
1279 | velrange = self.dataOut.getVelRange(1) |
|
1283 | velrange = self.dataOut.getVelRange(1) | |
1280 |
|
1284 | |||
1281 | if minVel == None: |
|
1285 | if minVel == None: | |
1282 | minVel = velrange[0] |
|
1286 | minVel = velrange[0] | |
1283 |
|
1287 | |||
1284 | if maxVel == None: |
|
1288 | if maxVel == None: | |
1285 | maxVel = velrange[-1] |
|
1289 | maxVel = velrange[-1] | |
1286 |
|
1290 | |||
1287 | if (minVel < velrange[0]) or (minVel > maxVel): |
|
1291 | if (minVel < velrange[0]) or (minVel > maxVel): | |
1288 | print 'minVel: %.2f is out of the velocity range'%(minVel) |
|
1292 | print 'minVel: %.2f is out of the velocity range'%(minVel) | |
1289 | print 'minVel is setting to %.2f'%(velrange[0]) |
|
1293 | print 'minVel is setting to %.2f'%(velrange[0]) | |
1290 | minVel = velrange[0] |
|
1294 | minVel = velrange[0] | |
1291 |
|
1295 | |||
1292 | if (maxVel > velrange[-1]) or (maxVel < minVel): |
|
1296 | if (maxVel > velrange[-1]) or (maxVel < minVel): | |
1293 | print 'maxVel: %.2f is out of the velocity range'%(maxVel) |
|
1297 | print 'maxVel: %.2f is out of the velocity range'%(maxVel) | |
1294 | print 'maxVel is setting to %.2f'%(velrange[-1]) |
|
1298 | print 'maxVel is setting to %.2f'%(velrange[-1]) | |
1295 | maxVel = velrange[-1] |
|
1299 | maxVel = velrange[-1] | |
1296 |
|
1300 | |||
1297 | # seleccion de indices para rango |
|
1301 | # seleccion de indices para rango | |
1298 | minIndex = 0 |
|
1302 | minIndex = 0 | |
1299 | maxIndex = 0 |
|
1303 | maxIndex = 0 | |
1300 | heights = self.dataOut.heightList |
|
1304 | heights = self.dataOut.heightList | |
1301 |
|
1305 | |||
1302 | inda = numpy.where(heights >= minHei) |
|
1306 | inda = numpy.where(heights >= minHei) | |
1303 | indb = numpy.where(heights <= maxHei) |
|
1307 | indb = numpy.where(heights <= maxHei) | |
1304 |
|
1308 | |||
1305 | try: |
|
1309 | try: | |
1306 | minIndex = inda[0][0] |
|
1310 | minIndex = inda[0][0] | |
1307 | except: |
|
1311 | except: | |
1308 | minIndex = 0 |
|
1312 | minIndex = 0 | |
1309 |
|
1313 | |||
1310 | try: |
|
1314 | try: | |
1311 | maxIndex = indb[0][-1] |
|
1315 | maxIndex = indb[0][-1] | |
1312 | except: |
|
1316 | except: | |
1313 | maxIndex = len(heights) |
|
1317 | maxIndex = len(heights) | |
1314 |
|
1318 | |||
1315 | if (minIndex < 0) or (minIndex > maxIndex): |
|
1319 | if (minIndex < 0) or (minIndex > maxIndex): | |
1316 | raise ValueError, "some value in (%d,%d) is not valid" % (minIndex, maxIndex) |
|
1320 | raise ValueError, "some value in (%d,%d) is not valid" % (minIndex, maxIndex) | |
1317 |
|
1321 | |||
1318 | if (maxIndex >= self.dataOut.nHeights): |
|
1322 | if (maxIndex >= self.dataOut.nHeights): | |
1319 | maxIndex = self.dataOut.nHeights-1 |
|
1323 | maxIndex = self.dataOut.nHeights-1 | |
1320 |
|
1324 | |||
1321 | # seleccion de indices para velocidades |
|
1325 | # seleccion de indices para velocidades | |
1322 | indminvel = numpy.where(velrange >= minVel) |
|
1326 | indminvel = numpy.where(velrange >= minVel) | |
1323 | indmaxvel = numpy.where(velrange <= maxVel) |
|
1327 | indmaxvel = numpy.where(velrange <= maxVel) | |
1324 | try: |
|
1328 | try: | |
1325 | minIndexVel = indminvel[0][0] |
|
1329 | minIndexVel = indminvel[0][0] | |
1326 | except: |
|
1330 | except: | |
1327 | minIndexVel = 0 |
|
1331 | minIndexVel = 0 | |
1328 |
|
1332 | |||
1329 | try: |
|
1333 | try: | |
1330 | maxIndexVel = indmaxvel[0][-1] |
|
1334 | maxIndexVel = indmaxvel[0][-1] | |
1331 | except: |
|
1335 | except: | |
1332 | maxIndexVel = len(velrange) |
|
1336 | maxIndexVel = len(velrange) | |
1333 |
|
1337 | |||
1334 | #seleccion del espectro |
|
1338 | #seleccion del espectro | |
1335 | data_spc = self.dataOut.data_spc[:,minIndexVel:maxIndexVel+1,minIndex:maxIndex+1] |
|
1339 | data_spc = self.dataOut.data_spc[:,minIndexVel:maxIndexVel+1,minIndex:maxIndex+1] | |
1336 | #estimacion de ruido |
|
1340 | #estimacion de ruido | |
1337 | noise = numpy.zeros(self.dataOut.nChannels) |
|
1341 | noise = numpy.zeros(self.dataOut.nChannels) | |
1338 |
|
1342 | |||
1339 | for channel in range(self.dataOut.nChannels): |
|
1343 | for channel in range(self.dataOut.nChannels): | |
1340 | daux = data_spc[channel,:,:] |
|
1344 | daux = data_spc[channel,:,:] | |
1341 | noise[channel] = hildebrand_sekhon(daux, self.dataOut.nIncohInt) |
|
1345 | noise[channel] = hildebrand_sekhon(daux, self.dataOut.nIncohInt) | |
1342 |
|
1346 | |||
1343 | self.dataOut.noise = noise.copy() |
|
1347 | self.dataOut.noise = noise.copy() | |
1344 |
|
1348 | |||
1345 | return 1 |
|
1349 | return 1 | |
1346 |
|
1350 | |||
1347 |
|
1351 | |||
1348 | class IncohInt(Operation): |
|
1352 | class IncohInt(Operation): | |
1349 |
|
1353 | |||
1350 |
|
1354 | |||
1351 | __profIndex = 0 |
|
1355 | __profIndex = 0 | |
1352 | __withOverapping = False |
|
1356 | __withOverapping = False | |
1353 |
|
1357 | |||
1354 | __byTime = False |
|
1358 | __byTime = False | |
1355 | __initime = None |
|
1359 | __initime = None | |
1356 | __lastdatatime = None |
|
1360 | __lastdatatime = None | |
1357 | __integrationtime = None |
|
1361 | __integrationtime = None | |
1358 |
|
1362 | |||
1359 | __buffer_spc = None |
|
1363 | __buffer_spc = None | |
1360 | __buffer_cspc = None |
|
1364 | __buffer_cspc = None | |
1361 | __buffer_dc = None |
|
1365 | __buffer_dc = None | |
1362 |
|
1366 | |||
1363 | __dataReady = False |
|
1367 | __dataReady = False | |
1364 |
|
1368 | |||
1365 | __timeInterval = None |
|
1369 | __timeInterval = None | |
1366 |
|
1370 | |||
1367 | n = None |
|
1371 | n = None | |
1368 |
|
1372 | |||
1369 |
|
1373 | |||
1370 |
|
1374 | |||
1371 | def __init__(self): |
|
1375 | def __init__(self): | |
1372 |
|
1376 | |||
1373 | self.__isConfig = False |
|
1377 | self.__isConfig = False | |
1374 |
|
1378 | |||
1375 | def setup(self, n=None, timeInterval=None, overlapping=False): |
|
1379 | def setup(self, n=None, timeInterval=None, overlapping=False): | |
1376 | """ |
|
1380 | """ | |
1377 | Set the parameters of the integration class. |
|
1381 | Set the parameters of the integration class. | |
1378 |
|
1382 | |||
1379 | Inputs: |
|
1383 | Inputs: | |
1380 |
|
1384 | |||
1381 | n : Number of coherent integrations |
|
1385 | n : Number of coherent integrations | |
1382 | timeInterval : Time of integration. If the parameter "n" is selected this one does not work |
|
1386 | timeInterval : Time of integration. If the parameter "n" is selected this one does not work | |
1383 | overlapping : |
|
1387 | overlapping : | |
1384 |
|
1388 | |||
1385 | """ |
|
1389 | """ | |
1386 |
|
1390 | |||
1387 | self.__initime = None |
|
1391 | self.__initime = None | |
1388 | self.__lastdatatime = 0 |
|
1392 | self.__lastdatatime = 0 | |
1389 | self.__buffer_spc = None |
|
1393 | self.__buffer_spc = None | |
1390 | self.__buffer_cspc = None |
|
1394 | self.__buffer_cspc = None | |
1391 | self.__buffer_dc = None |
|
1395 | self.__buffer_dc = None | |
1392 | self.__dataReady = False |
|
1396 | self.__dataReady = False | |
1393 |
|
1397 | |||
1394 |
|
1398 | |||
1395 | if n == None and timeInterval == None: |
|
1399 | if n == None and timeInterval == None: | |
1396 | raise ValueError, "n or timeInterval should be specified ..." |
|
1400 | raise ValueError, "n or timeInterval should be specified ..." | |
1397 |
|
1401 | |||
1398 | if n != None: |
|
1402 | if n != None: | |
1399 | self.n = n |
|
1403 | self.n = n | |
1400 | self.__byTime = False |
|
1404 | self.__byTime = False | |
1401 | else: |
|
1405 | else: | |
1402 | self.__integrationtime = timeInterval #if (type(timeInterval)!=integer) -> change this line |
|
1406 | self.__integrationtime = timeInterval #if (type(timeInterval)!=integer) -> change this line | |
1403 | self.n = 9999 |
|
1407 | self.n = 9999 | |
1404 | self.__byTime = True |
|
1408 | self.__byTime = True | |
1405 |
|
1409 | |||
1406 | if overlapping: |
|
1410 | if overlapping: | |
1407 | self.__withOverapping = True |
|
1411 | self.__withOverapping = True | |
1408 | else: |
|
1412 | else: | |
1409 | self.__withOverapping = False |
|
1413 | self.__withOverapping = False | |
1410 | self.__buffer_spc = 0 |
|
1414 | self.__buffer_spc = 0 | |
1411 | self.__buffer_cspc = 0 |
|
1415 | self.__buffer_cspc = 0 | |
1412 | self.__buffer_dc = 0 |
|
1416 | self.__buffer_dc = 0 | |
1413 |
|
1417 | |||
1414 | self.__profIndex = 0 |
|
1418 | self.__profIndex = 0 | |
1415 |
|
1419 | |||
1416 | def putData(self, data_spc, data_cspc, data_dc): |
|
1420 | def putData(self, data_spc, data_cspc, data_dc): | |
1417 |
|
1421 | |||
1418 | """ |
|
1422 | """ | |
1419 | Add a profile to the __buffer_spc and increase in one the __profileIndex |
|
1423 | Add a profile to the __buffer_spc and increase in one the __profileIndex | |
1420 |
|
1424 | |||
1421 | """ |
|
1425 | """ | |
1422 |
|
1426 | |||
1423 | if not self.__withOverapping: |
|
1427 | if not self.__withOverapping: | |
1424 | self.__buffer_spc += data_spc |
|
1428 | self.__buffer_spc += data_spc | |
1425 |
|
1429 | |||
1426 | if data_cspc == None: |
|
1430 | if data_cspc == None: | |
1427 | self.__buffer_cspc = None |
|
1431 | self.__buffer_cspc = None | |
1428 | else: |
|
1432 | else: | |
1429 | self.__buffer_cspc += data_cspc |
|
1433 | self.__buffer_cspc += data_cspc | |
1430 |
|
1434 | |||
1431 | if data_dc == None: |
|
1435 | if data_dc == None: | |
1432 | self.__buffer_dc = None |
|
1436 | self.__buffer_dc = None | |
1433 | else: |
|
1437 | else: | |
1434 | self.__buffer_dc += data_dc |
|
1438 | self.__buffer_dc += data_dc | |
1435 |
|
1439 | |||
1436 | self.__profIndex += 1 |
|
1440 | self.__profIndex += 1 | |
1437 | return |
|
1441 | return | |
1438 |
|
1442 | |||
1439 | #Overlapping data |
|
1443 | #Overlapping data | |
1440 | nChannels, nFFTPoints, nHeis = data_spc.shape |
|
1444 | nChannels, nFFTPoints, nHeis = data_spc.shape | |
1441 | data_spc = numpy.reshape(data_spc, (1, nChannels, nFFTPoints, nHeis)) |
|
1445 | data_spc = numpy.reshape(data_spc, (1, nChannels, nFFTPoints, nHeis)) | |
1442 | if data_cspc != None: |
|
1446 | if data_cspc != None: | |
1443 | data_cspc = numpy.reshape(data_cspc, (1, -1, nFFTPoints, nHeis)) |
|
1447 | data_cspc = numpy.reshape(data_cspc, (1, -1, nFFTPoints, nHeis)) | |
1444 | if data_dc != None: |
|
1448 | if data_dc != None: | |
1445 | data_dc = numpy.reshape(data_dc, (1, -1, nHeis)) |
|
1449 | data_dc = numpy.reshape(data_dc, (1, -1, nHeis)) | |
1446 |
|
1450 | |||
1447 | #If the buffer is empty then it takes the data value |
|
1451 | #If the buffer is empty then it takes the data value | |
1448 | if self.__buffer_spc == None: |
|
1452 | if self.__buffer_spc == None: | |
1449 | self.__buffer_spc = data_spc |
|
1453 | self.__buffer_spc = data_spc | |
1450 |
|
1454 | |||
1451 | if data_cspc == None: |
|
1455 | if data_cspc == None: | |
1452 | self.__buffer_cspc = None |
|
1456 | self.__buffer_cspc = None | |
1453 | else: |
|
1457 | else: | |
1454 | self.__buffer_cspc += data_cspc |
|
1458 | self.__buffer_cspc += data_cspc | |
1455 |
|
1459 | |||
1456 | if data_dc == None: |
|
1460 | if data_dc == None: | |
1457 | self.__buffer_dc = None |
|
1461 | self.__buffer_dc = None | |
1458 | else: |
|
1462 | else: | |
1459 | self.__buffer_dc += data_dc |
|
1463 | self.__buffer_dc += data_dc | |
1460 |
|
1464 | |||
1461 | self.__profIndex += 1 |
|
1465 | self.__profIndex += 1 | |
1462 | return |
|
1466 | return | |
1463 |
|
1467 | |||
1464 | #If the buffer length is lower than n then stakcing the data value |
|
1468 | #If the buffer length is lower than n then stakcing the data value | |
1465 | if self.__profIndex < self.n: |
|
1469 | if self.__profIndex < self.n: | |
1466 | self.__buffer_spc = numpy.vstack((self.__buffer_spc, data_spc)) |
|
1470 | self.__buffer_spc = numpy.vstack((self.__buffer_spc, data_spc)) | |
1467 |
|
1471 | |||
1468 | if data_cspc != None: |
|
1472 | if data_cspc != None: | |
1469 | self.__buffer_cspc = numpy.vstack((self.__buffer_cspc, data_cspc)) |
|
1473 | self.__buffer_cspc = numpy.vstack((self.__buffer_cspc, data_cspc)) | |
1470 |
|
1474 | |||
1471 | if data_dc != None: |
|
1475 | if data_dc != None: | |
1472 | self.__buffer_dc = numpy.vstack((self.__buffer_dc, data_dc)) |
|
1476 | self.__buffer_dc = numpy.vstack((self.__buffer_dc, data_dc)) | |
1473 |
|
1477 | |||
1474 | self.__profIndex += 1 |
|
1478 | self.__profIndex += 1 | |
1475 | return |
|
1479 | return | |
1476 |
|
1480 | |||
1477 | #If the buffer length is equal to n then replacing the last buffer value with the data value |
|
1481 | #If the buffer length is equal to n then replacing the last buffer value with the data value | |
1478 | self.__buffer_spc = numpy.roll(self.__buffer_spc, -1, axis=0) |
|
1482 | self.__buffer_spc = numpy.roll(self.__buffer_spc, -1, axis=0) | |
1479 | self.__buffer_spc[self.n-1] = data_spc |
|
1483 | self.__buffer_spc[self.n-1] = data_spc | |
1480 |
|
1484 | |||
1481 | if data_cspc != None: |
|
1485 | if data_cspc != None: | |
1482 | self.__buffer_cspc = numpy.roll(self.__buffer_cspc, -1, axis=0) |
|
1486 | self.__buffer_cspc = numpy.roll(self.__buffer_cspc, -1, axis=0) | |
1483 | self.__buffer_cspc[self.n-1] = data_cspc |
|
1487 | self.__buffer_cspc[self.n-1] = data_cspc | |
1484 |
|
1488 | |||
1485 | if data_dc != None: |
|
1489 | if data_dc != None: | |
1486 | self.__buffer_dc = numpy.roll(self.__buffer_dc, -1, axis=0) |
|
1490 | self.__buffer_dc = numpy.roll(self.__buffer_dc, -1, axis=0) | |
1487 | self.__buffer_dc[self.n-1] = data_dc |
|
1491 | self.__buffer_dc[self.n-1] = data_dc | |
1488 |
|
1492 | |||
1489 | self.__profIndex = self.n |
|
1493 | self.__profIndex = self.n | |
1490 | return |
|
1494 | return | |
1491 |
|
1495 | |||
1492 |
|
1496 | |||
1493 | def pushData(self): |
|
1497 | def pushData(self): | |
1494 | """ |
|
1498 | """ | |
1495 | Return the sum of the last profiles and the profiles used in the sum. |
|
1499 | Return the sum of the last profiles and the profiles used in the sum. | |
1496 |
|
1500 | |||
1497 | Affected: |
|
1501 | Affected: | |
1498 |
|
1502 | |||
1499 | self.__profileIndex |
|
1503 | self.__profileIndex | |
1500 |
|
1504 | |||
1501 | """ |
|
1505 | """ | |
1502 | data_spc = None |
|
1506 | data_spc = None | |
1503 | data_cspc = None |
|
1507 | data_cspc = None | |
1504 | data_dc = None |
|
1508 | data_dc = None | |
1505 |
|
1509 | |||
1506 | if not self.__withOverapping: |
|
1510 | if not self.__withOverapping: | |
1507 | data_spc = self.__buffer_spc |
|
1511 | data_spc = self.__buffer_spc | |
1508 | data_cspc = self.__buffer_cspc |
|
1512 | data_cspc = self.__buffer_cspc | |
1509 | data_dc = self.__buffer_dc |
|
1513 | data_dc = self.__buffer_dc | |
1510 |
|
1514 | |||
1511 | n = self.__profIndex |
|
1515 | n = self.__profIndex | |
1512 |
|
1516 | |||
1513 | self.__buffer_spc = 0 |
|
1517 | self.__buffer_spc = 0 | |
1514 | self.__buffer_cspc = 0 |
|
1518 | self.__buffer_cspc = 0 | |
1515 | self.__buffer_dc = 0 |
|
1519 | self.__buffer_dc = 0 | |
1516 | self.__profIndex = 0 |
|
1520 | self.__profIndex = 0 | |
1517 |
|
1521 | |||
1518 | return data_spc, data_cspc, data_dc, n |
|
1522 | return data_spc, data_cspc, data_dc, n | |
1519 |
|
1523 | |||
1520 | #Integration with Overlapping |
|
1524 | #Integration with Overlapping | |
1521 | data_spc = numpy.sum(self.__buffer_spc, axis=0) |
|
1525 | data_spc = numpy.sum(self.__buffer_spc, axis=0) | |
1522 |
|
1526 | |||
1523 | if self.__buffer_cspc != None: |
|
1527 | if self.__buffer_cspc != None: | |
1524 | data_cspc = numpy.sum(self.__buffer_cspc, axis=0) |
|
1528 | data_cspc = numpy.sum(self.__buffer_cspc, axis=0) | |
1525 |
|
1529 | |||
1526 | if self.__buffer_dc != None: |
|
1530 | if self.__buffer_dc != None: | |
1527 | data_dc = numpy.sum(self.__buffer_dc, axis=0) |
|
1531 | data_dc = numpy.sum(self.__buffer_dc, axis=0) | |
1528 |
|
1532 | |||
1529 | n = self.__profIndex |
|
1533 | n = self.__profIndex | |
1530 |
|
1534 | |||
1531 | return data_spc, data_cspc, data_dc, n |
|
1535 | return data_spc, data_cspc, data_dc, n | |
1532 |
|
1536 | |||
1533 | def byProfiles(self, *args): |
|
1537 | def byProfiles(self, *args): | |
1534 |
|
1538 | |||
1535 | self.__dataReady = False |
|
1539 | self.__dataReady = False | |
1536 | avgdata_spc = None |
|
1540 | avgdata_spc = None | |
1537 | avgdata_cspc = None |
|
1541 | avgdata_cspc = None | |
1538 | avgdata_dc = None |
|
1542 | avgdata_dc = None | |
1539 | n = None |
|
1543 | n = None | |
1540 |
|
1544 | |||
1541 | self.putData(*args) |
|
1545 | self.putData(*args) | |
1542 |
|
1546 | |||
1543 | if self.__profIndex == self.n: |
|
1547 | if self.__profIndex == self.n: | |
1544 |
|
1548 | |||
1545 | avgdata_spc, avgdata_cspc, avgdata_dc, n = self.pushData() |
|
1549 | avgdata_spc, avgdata_cspc, avgdata_dc, n = self.pushData() | |
1546 | self.__dataReady = True |
|
1550 | self.__dataReady = True | |
1547 |
|
1551 | |||
1548 | return avgdata_spc, avgdata_cspc, avgdata_dc |
|
1552 | return avgdata_spc, avgdata_cspc, avgdata_dc | |
1549 |
|
1553 | |||
1550 | def byTime(self, datatime, *args): |
|
1554 | def byTime(self, datatime, *args): | |
1551 |
|
1555 | |||
1552 | self.__dataReady = False |
|
1556 | self.__dataReady = False | |
1553 | avgdata_spc = None |
|
1557 | avgdata_spc = None | |
1554 | avgdata_cspc = None |
|
1558 | avgdata_cspc = None | |
1555 | avgdata_dc = None |
|
1559 | avgdata_dc = None | |
1556 | n = None |
|
1560 | n = None | |
1557 |
|
1561 | |||
1558 | self.putData(*args) |
|
1562 | self.putData(*args) | |
1559 |
|
1563 | |||
1560 | if (datatime - self.__initime) >= self.__integrationtime: |
|
1564 | if (datatime - self.__initime) >= self.__integrationtime: | |
1561 | avgdata_spc, avgdata_cspc, avgdata_dc, n = self.pushData() |
|
1565 | avgdata_spc, avgdata_cspc, avgdata_dc, n = self.pushData() | |
1562 | self.n = n |
|
1566 | self.n = n | |
1563 | self.__dataReady = True |
|
1567 | self.__dataReady = True | |
1564 |
|
1568 | |||
1565 | return avgdata_spc, avgdata_cspc, avgdata_dc |
|
1569 | return avgdata_spc, avgdata_cspc, avgdata_dc | |
1566 |
|
1570 | |||
1567 | def integrate(self, datatime, *args): |
|
1571 | def integrate(self, datatime, *args): | |
1568 |
|
1572 | |||
1569 | if self.__initime == None: |
|
1573 | if self.__initime == None: | |
1570 | self.__initime = datatime |
|
1574 | self.__initime = datatime | |
1571 |
|
1575 | |||
1572 | if self.__byTime: |
|
1576 | if self.__byTime: | |
1573 | avgdata_spc, avgdata_cspc, avgdata_dc = self.byTime(datatime, *args) |
|
1577 | avgdata_spc, avgdata_cspc, avgdata_dc = self.byTime(datatime, *args) | |
1574 | else: |
|
1578 | else: | |
1575 | avgdata_spc, avgdata_cspc, avgdata_dc = self.byProfiles(*args) |
|
1579 | avgdata_spc, avgdata_cspc, avgdata_dc = self.byProfiles(*args) | |
1576 |
|
1580 | |||
1577 | self.__lastdatatime = datatime |
|
1581 | self.__lastdatatime = datatime | |
1578 |
|
1582 | |||
1579 | if avgdata_spc == None: |
|
1583 | if avgdata_spc == None: | |
1580 | return None, None, None, None |
|
1584 | return None, None, None, None | |
1581 |
|
1585 | |||
1582 | avgdatatime = self.__initime |
|
1586 | avgdatatime = self.__initime | |
1583 | try: |
|
1587 | try: | |
1584 | self.__timeInterval = (self.__lastdatatime - self.__initime)/(self.n - 1) |
|
1588 | self.__timeInterval = (self.__lastdatatime - self.__initime)/(self.n - 1) | |
1585 | except: |
|
1589 | except: | |
1586 | self.__timeInterval = self.__lastdatatime - self.__initime |
|
1590 | self.__timeInterval = self.__lastdatatime - self.__initime | |
1587 |
|
1591 | |||
1588 | deltatime = datatime -self.__lastdatatime |
|
1592 | deltatime = datatime -self.__lastdatatime | |
1589 |
|
1593 | |||
1590 | if not self.__withOverapping: |
|
1594 | if not self.__withOverapping: | |
1591 | self.__initime = datatime |
|
1595 | self.__initime = datatime | |
1592 | else: |
|
1596 | else: | |
1593 | self.__initime += deltatime |
|
1597 | self.__initime += deltatime | |
1594 |
|
1598 | |||
1595 | return avgdatatime, avgdata_spc, avgdata_cspc, avgdata_dc |
|
1599 | return avgdatatime, avgdata_spc, avgdata_cspc, avgdata_dc | |
1596 |
|
1600 | |||
1597 | def run(self, dataOut, n=None, timeInterval=None, overlapping=False): |
|
1601 | def run(self, dataOut, n=None, timeInterval=None, overlapping=False): | |
1598 |
|
1602 | |||
1599 | if n==1: |
|
1603 | if n==1: | |
1600 | dataOut.flagNoData = False |
|
1604 | dataOut.flagNoData = False | |
1601 | return |
|
1605 | return | |
1602 |
|
1606 | |||
1603 | if not self.__isConfig: |
|
1607 | if not self.__isConfig: | |
1604 | self.setup(n, timeInterval, overlapping) |
|
1608 | self.setup(n, timeInterval, overlapping) | |
1605 | self.__isConfig = True |
|
1609 | self.__isConfig = True | |
1606 |
|
1610 | |||
1607 | avgdatatime, avgdata_spc, avgdata_cspc, avgdata_dc = self.integrate(dataOut.utctime, |
|
1611 | avgdatatime, avgdata_spc, avgdata_cspc, avgdata_dc = self.integrate(dataOut.utctime, | |
1608 | dataOut.data_spc, |
|
1612 | dataOut.data_spc, | |
1609 | dataOut.data_cspc, |
|
1613 | dataOut.data_cspc, | |
1610 | dataOut.data_dc) |
|
1614 | dataOut.data_dc) | |
1611 |
|
1615 | |||
1612 | # dataOut.timeInterval *= n |
|
1616 | # dataOut.timeInterval *= n | |
1613 | dataOut.flagNoData = True |
|
1617 | dataOut.flagNoData = True | |
1614 |
|
1618 | |||
1615 | if self.__dataReady: |
|
1619 | if self.__dataReady: | |
1616 |
|
1620 | |||
1617 | dataOut.data_spc = avgdata_spc |
|
1621 | dataOut.data_spc = avgdata_spc | |
1618 | dataOut.data_cspc = avgdata_cspc |
|
1622 | dataOut.data_cspc = avgdata_cspc | |
1619 | dataOut.data_dc = avgdata_dc |
|
1623 | dataOut.data_dc = avgdata_dc | |
1620 |
|
1624 | |||
1621 | dataOut.nIncohInt *= self.n |
|
1625 | dataOut.nIncohInt *= self.n | |
1622 | dataOut.utctime = avgdatatime |
|
1626 | dataOut.utctime = avgdatatime | |
1623 | #dataOut.timeInterval = dataOut.ippSeconds * dataOut.nCohInt * dataOut.nIncohInt * dataOut.nFFTPoints |
|
1627 | #dataOut.timeInterval = dataOut.ippSeconds * dataOut.nCohInt * dataOut.nIncohInt * dataOut.nFFTPoints | |
1624 | dataOut.timeInterval = self.__timeInterval*self.n |
|
1628 | dataOut.timeInterval = self.__timeInterval*self.n | |
1625 | dataOut.flagNoData = False |
|
1629 | dataOut.flagNoData = False | |
1626 |
|
1630 | |||
1627 | class ProfileConcat(Operation): |
|
1631 | class ProfileConcat(Operation): | |
1628 |
|
1632 | |||
1629 | __isConfig = False |
|
1633 | __isConfig = False | |
1630 | buffer = None |
|
1634 | buffer = None | |
1631 |
|
1635 | |||
1632 | def __init__(self): |
|
1636 | def __init__(self): | |
1633 |
|
1637 | |||
1634 | self.profileIndex = 0 |
|
1638 | self.profileIndex = 0 | |
1635 |
|
1639 | |||
1636 | def reset(self): |
|
1640 | def reset(self): | |
1637 | self.buffer = numpy.zeros_like(self.buffer) |
|
1641 | self.buffer = numpy.zeros_like(self.buffer) | |
1638 | self.start_index = 0 |
|
1642 | self.start_index = 0 | |
1639 | self.times = 1 |
|
1643 | self.times = 1 | |
1640 |
|
1644 | |||
1641 | def setup(self, data, m, n=1): |
|
1645 | def setup(self, data, m, n=1): | |
1642 | self.buffer = numpy.zeros((data.shape[0],data.shape[1]*m),dtype=type(data[0,0])) |
|
1646 | self.buffer = numpy.zeros((data.shape[0],data.shape[1]*m),dtype=type(data[0,0])) | |
1643 | self.profiles = data.shape[1] |
|
1647 | self.profiles = data.shape[1] | |
1644 | self.start_index = 0 |
|
1648 | self.start_index = 0 | |
1645 | self.times = 1 |
|
1649 | self.times = 1 | |
1646 |
|
1650 | |||
1647 | def concat(self, data): |
|
1651 | def concat(self, data): | |
1648 |
|
1652 | |||
1649 | self.buffer[:,self.start_index:self.profiles*self.times] = data.copy() |
|
1653 | self.buffer[:,self.start_index:self.profiles*self.times] = data.copy() | |
1650 | self.start_index = self.start_index + self.profiles |
|
1654 | self.start_index = self.start_index + self.profiles | |
1651 |
|
1655 | |||
1652 | def run(self, dataOut, m): |
|
1656 | def run(self, dataOut, m): | |
1653 |
|
1657 | |||
1654 | dataOut.flagNoData = True |
|
1658 | dataOut.flagNoData = True | |
1655 |
|
1659 | |||
1656 | if not self.__isConfig: |
|
1660 | if not self.__isConfig: | |
1657 | self.setup(dataOut.data, m, 1) |
|
1661 | self.setup(dataOut.data, m, 1) | |
1658 | self.__isConfig = True |
|
1662 | self.__isConfig = True | |
1659 |
|
1663 | |||
1660 | self.concat(dataOut.data) |
|
1664 | self.concat(dataOut.data) | |
1661 | self.times += 1 |
|
1665 | self.times += 1 | |
1662 | if self.times > m: |
|
1666 | if self.times > m: | |
1663 | dataOut.data = self.buffer |
|
1667 | dataOut.data = self.buffer | |
1664 | self.reset() |
|
1668 | self.reset() | |
1665 | dataOut.flagNoData = False |
|
1669 | dataOut.flagNoData = False | |
1666 | # se deben actualizar mas propiedades del header y del objeto dataOut, por ejemplo, las alturas |
|
1670 | # se deben actualizar mas propiedades del header y del objeto dataOut, por ejemplo, las alturas | |
1667 | deltaHeight = dataOut.heightList[1] - dataOut.heightList[0] |
|
1671 | deltaHeight = dataOut.heightList[1] - dataOut.heightList[0] | |
1668 | xf = dataOut.heightList[0] + dataOut.nHeights * deltaHeight * 5 |
|
1672 | xf = dataOut.heightList[0] + dataOut.nHeights * deltaHeight * 5 | |
1669 | dataOut.heightList = numpy.arange(dataOut.heightList[0], xf, deltaHeight) |
|
1673 | dataOut.heightList = numpy.arange(dataOut.heightList[0], xf, deltaHeight) | |
1670 |
|
1674 | |||
1671 |
|
1675 | |||
1672 |
|
1676 | |||
1673 | class ProfileSelector(Operation): |
|
1677 | class ProfileSelector(Operation): | |
1674 |
|
1678 | |||
1675 | profileIndex = None |
|
1679 | profileIndex = None | |
1676 | # Tamanho total de los perfiles |
|
1680 | # Tamanho total de los perfiles | |
1677 | nProfiles = None |
|
1681 | nProfiles = None | |
1678 |
|
1682 | |||
1679 | def __init__(self): |
|
1683 | def __init__(self): | |
1680 |
|
1684 | |||
1681 | self.profileIndex = 0 |
|
1685 | self.profileIndex = 0 | |
1682 |
|
1686 | |||
1683 | def incIndex(self): |
|
1687 | def incIndex(self): | |
1684 | self.profileIndex += 1 |
|
1688 | self.profileIndex += 1 | |
1685 |
|
1689 | |||
1686 | if self.profileIndex >= self.nProfiles: |
|
1690 | if self.profileIndex >= self.nProfiles: | |
1687 | self.profileIndex = 0 |
|
1691 | self.profileIndex = 0 | |
1688 |
|
1692 | |||
1689 | def isProfileInRange(self, minIndex, maxIndex): |
|
1693 | def isProfileInRange(self, minIndex, maxIndex): | |
1690 |
|
1694 | |||
1691 | if self.profileIndex < minIndex: |
|
1695 | if self.profileIndex < minIndex: | |
1692 | return False |
|
1696 | return False | |
1693 |
|
1697 | |||
1694 | if self.profileIndex > maxIndex: |
|
1698 | if self.profileIndex > maxIndex: | |
1695 | return False |
|
1699 | return False | |
1696 |
|
1700 | |||
1697 | return True |
|
1701 | return True | |
1698 |
|
1702 | |||
1699 | def isProfileInList(self, profileList): |
|
1703 | def isProfileInList(self, profileList): | |
1700 |
|
1704 | |||
1701 | if self.profileIndex not in profileList: |
|
1705 | if self.profileIndex not in profileList: | |
1702 | return False |
|
1706 | return False | |
1703 |
|
1707 | |||
1704 | return True |
|
1708 | return True | |
1705 |
|
1709 | |||
1706 | def run(self, dataOut, profileList=None, profileRangeList=None): |
|
1710 | def run(self, dataOut, profileList=None, profileRangeList=None): | |
1707 |
|
1711 | |||
1708 | dataOut.flagNoData = True |
|
1712 | dataOut.flagNoData = True | |
1709 | self.nProfiles = dataOut.nProfiles |
|
1713 | self.nProfiles = dataOut.nProfiles | |
1710 |
|
1714 | |||
1711 | if profileList != None: |
|
1715 | if profileList != None: | |
1712 | if self.isProfileInList(profileList): |
|
1716 | if self.isProfileInList(profileList): | |
1713 | dataOut.flagNoData = False |
|
1717 | dataOut.flagNoData = False | |
1714 |
|
1718 | |||
1715 | self.incIndex() |
|
1719 | self.incIndex() | |
1716 | return 1 |
|
1720 | return 1 | |
1717 |
|
1721 | |||
1718 |
|
1722 | |||
1719 | elif profileRangeList != None: |
|
1723 | elif profileRangeList != None: | |
1720 | minIndex = profileRangeList[0] |
|
1724 | minIndex = profileRangeList[0] | |
1721 | maxIndex = profileRangeList[1] |
|
1725 | maxIndex = profileRangeList[1] | |
1722 | if self.isProfileInRange(minIndex, maxIndex): |
|
1726 | if self.isProfileInRange(minIndex, maxIndex): | |
1723 | dataOut.flagNoData = False |
|
1727 | dataOut.flagNoData = False | |
1724 |
|
1728 | |||
1725 | self.incIndex() |
|
1729 | self.incIndex() | |
1726 | return 1 |
|
1730 | return 1 | |
1727 |
|
1731 | |||
1728 | else: |
|
1732 | else: | |
1729 | raise ValueError, "ProfileSelector needs profileList or profileRangeList" |
|
1733 | raise ValueError, "ProfileSelector needs profileList or profileRangeList" | |
1730 |
|
1734 | |||
1731 | return 0 |
|
1735 | return 0 | |
1732 |
|
1736 | |||
1733 | class SpectraHeisProc(ProcessingUnit): |
|
1737 | class SpectraHeisProc(ProcessingUnit): | |
1734 | def __init__(self): |
|
1738 | def __init__(self): | |
1735 | self.objectDict = {} |
|
1739 | self.objectDict = {} | |
1736 | # self.buffer = None |
|
1740 | # self.buffer = None | |
1737 | # self.firstdatatime = None |
|
1741 | # self.firstdatatime = None | |
1738 | # self.profIndex = 0 |
|
1742 | # self.profIndex = 0 | |
1739 | self.dataOut = SpectraHeis() |
|
1743 | self.dataOut = SpectraHeis() | |
1740 |
|
1744 | |||
1741 | def __updateObjFromInput(self): |
|
1745 | def __updateObjFromInput(self): | |
1742 | self.dataOut.timeZone = self.dataIn.timeZone |
|
1746 | self.dataOut.timeZone = self.dataIn.timeZone | |
1743 | self.dataOut.dstFlag = self.dataIn.dstFlag |
|
1747 | self.dataOut.dstFlag = self.dataIn.dstFlag | |
1744 | self.dataOut.errorCount = self.dataIn.errorCount |
|
1748 | self.dataOut.errorCount = self.dataIn.errorCount | |
1745 | self.dataOut.useLocalTime = self.dataIn.useLocalTime |
|
1749 | self.dataOut.useLocalTime = self.dataIn.useLocalTime | |
1746 |
|
1750 | |||
1747 | self.dataOut.radarControllerHeaderObj = self.dataIn.radarControllerHeaderObj.copy()# |
|
1751 | self.dataOut.radarControllerHeaderObj = self.dataIn.radarControllerHeaderObj.copy()# | |
1748 | self.dataOut.systemHeaderObj = self.dataIn.systemHeaderObj.copy()# |
|
1752 | self.dataOut.systemHeaderObj = self.dataIn.systemHeaderObj.copy()# | |
1749 | self.dataOut.channelList = self.dataIn.channelList |
|
1753 | self.dataOut.channelList = self.dataIn.channelList | |
1750 | self.dataOut.heightList = self.dataIn.heightList |
|
1754 | self.dataOut.heightList = self.dataIn.heightList | |
1751 | # self.dataOut.dtype = self.dataIn.dtype |
|
1755 | # self.dataOut.dtype = self.dataIn.dtype | |
1752 | self.dataOut.dtype = numpy.dtype([('real','<f4'),('imag','<f4')]) |
|
1756 | self.dataOut.dtype = numpy.dtype([('real','<f4'),('imag','<f4')]) | |
1753 | # self.dataOut.nHeights = self.dataIn.nHeights |
|
1757 | # self.dataOut.nHeights = self.dataIn.nHeights | |
1754 | # self.dataOut.nChannels = self.dataIn.nChannels |
|
1758 | # self.dataOut.nChannels = self.dataIn.nChannels | |
1755 | self.dataOut.nBaud = self.dataIn.nBaud |
|
1759 | self.dataOut.nBaud = self.dataIn.nBaud | |
1756 | self.dataOut.nCode = self.dataIn.nCode |
|
1760 | self.dataOut.nCode = self.dataIn.nCode | |
1757 | self.dataOut.code = self.dataIn.code |
|
1761 | self.dataOut.code = self.dataIn.code | |
1758 | # self.dataOut.nProfiles = 1 |
|
1762 | # self.dataOut.nProfiles = 1 | |
1759 | # self.dataOut.nProfiles = self.dataOut.nFFTPoints |
|
1763 | # self.dataOut.nProfiles = self.dataOut.nFFTPoints | |
1760 | self.dataOut.nFFTPoints = self.dataIn.nHeights |
|
1764 | self.dataOut.nFFTPoints = self.dataIn.nHeights | |
1761 | # self.dataOut.channelIndexList = self.dataIn.channelIndexList |
|
1765 | # self.dataOut.channelIndexList = self.dataIn.channelIndexList | |
1762 | # self.dataOut.flagNoData = self.dataIn.flagNoData |
|
1766 | # self.dataOut.flagNoData = self.dataIn.flagNoData | |
1763 | self.dataOut.flagTimeBlock = self.dataIn.flagTimeBlock |
|
1767 | self.dataOut.flagTimeBlock = self.dataIn.flagTimeBlock | |
1764 | self.dataOut.utctime = self.dataIn.utctime |
|
1768 | self.dataOut.utctime = self.dataIn.utctime | |
1765 | # self.dataOut.utctime = self.firstdatatime |
|
1769 | # self.dataOut.utctime = self.firstdatatime | |
1766 | self.dataOut.flagDecodeData = self.dataIn.flagDecodeData #asumo q la data esta decodificada |
|
1770 | self.dataOut.flagDecodeData = self.dataIn.flagDecodeData #asumo q la data esta decodificada | |
1767 | self.dataOut.flagDeflipData = self.dataIn.flagDeflipData #asumo q la data esta sin flip |
|
1771 | self.dataOut.flagDeflipData = self.dataIn.flagDeflipData #asumo q la data esta sin flip | |
1768 | # self.dataOut.flagShiftFFT = self.dataIn.flagShiftFFT |
|
1772 | # self.dataOut.flagShiftFFT = self.dataIn.flagShiftFFT | |
1769 | self.dataOut.nCohInt = self.dataIn.nCohInt |
|
1773 | self.dataOut.nCohInt = self.dataIn.nCohInt | |
1770 | self.dataOut.nIncohInt = 1 |
|
1774 | self.dataOut.nIncohInt = 1 | |
1771 | self.dataOut.ippSeconds= self.dataIn.ippSeconds |
|
1775 | self.dataOut.ippSeconds= self.dataIn.ippSeconds | |
1772 | self.dataOut.windowOfFilter = self.dataIn.windowOfFilter |
|
1776 | self.dataOut.windowOfFilter = self.dataIn.windowOfFilter | |
1773 |
|
1777 | |||
1774 | self.dataOut.timeInterval = self.dataIn.timeInterval*self.dataOut.nIncohInt |
|
1778 | self.dataOut.timeInterval = self.dataIn.timeInterval*self.dataOut.nIncohInt | |
1775 | # self.dataOut.set=self.dataIn.set |
|
1779 | # self.dataOut.set=self.dataIn.set | |
1776 | # self.dataOut.deltaHeight=self.dataIn.deltaHeight |
|
1780 | # self.dataOut.deltaHeight=self.dataIn.deltaHeight | |
1777 |
|
1781 | |||
1778 |
|
1782 | |||
1779 | def __updateObjFromFits(self): |
|
1783 | def __updateObjFromFits(self): | |
1780 | self.dataOut.utctime = self.dataIn.utctime |
|
1784 | self.dataOut.utctime = self.dataIn.utctime | |
1781 | self.dataOut.channelIndexList = self.dataIn.channelIndexList |
|
1785 | self.dataOut.channelIndexList = self.dataIn.channelIndexList | |
1782 |
|
1786 | |||
1783 | self.dataOut.channelList = self.dataIn.channelList |
|
1787 | self.dataOut.channelList = self.dataIn.channelList | |
1784 | self.dataOut.heightList = self.dataIn.heightList |
|
1788 | self.dataOut.heightList = self.dataIn.heightList | |
1785 | self.dataOut.data_spc = self.dataIn.data |
|
1789 | self.dataOut.data_spc = self.dataIn.data | |
1786 | self.dataOut.timeInterval = self.dataIn.timeInterval |
|
1790 | self.dataOut.timeInterval = self.dataIn.timeInterval | |
1787 | self.dataOut.timeZone = self.dataIn.timeZone |
|
1791 | self.dataOut.timeZone = self.dataIn.timeZone | |
1788 | self.dataOut.useLocalTime = True |
|
1792 | self.dataOut.useLocalTime = True | |
1789 | # self.dataOut. |
|
1793 | # self.dataOut. | |
1790 | # self.dataOut. |
|
1794 | # self.dataOut. | |
1791 |
|
1795 | |||
1792 | def __getFft(self): |
|
1796 | def __getFft(self): | |
1793 |
|
1797 | |||
1794 | fft_volt = numpy.fft.fft(self.dataIn.data, axis=1) |
|
1798 | fft_volt = numpy.fft.fft(self.dataIn.data, axis=1) | |
1795 | fft_volt = numpy.fft.fftshift(fft_volt,axes=(1,)) |
|
1799 | fft_volt = numpy.fft.fftshift(fft_volt,axes=(1,)) | |
1796 | spc = numpy.abs(fft_volt * numpy.conjugate(fft_volt))/(self.dataOut.nFFTPoints) |
|
1800 | spc = numpy.abs(fft_volt * numpy.conjugate(fft_volt))/(self.dataOut.nFFTPoints) | |
1797 | self.dataOut.data_spc = spc |
|
1801 | self.dataOut.data_spc = spc | |
1798 |
|
1802 | |||
1799 | def init(self): |
|
1803 | def init(self): | |
1800 |
|
1804 | |||
1801 | self.dataOut.flagNoData = True |
|
1805 | self.dataOut.flagNoData = True | |
1802 |
|
1806 | |||
1803 | if self.dataIn.type == "Fits": |
|
1807 | if self.dataIn.type == "Fits": | |
1804 | self.__updateObjFromFits() |
|
1808 | self.__updateObjFromFits() | |
1805 | self.dataOut.flagNoData = False |
|
1809 | self.dataOut.flagNoData = False | |
1806 | return |
|
1810 | return | |
1807 |
|
1811 | |||
1808 | if self.dataIn.type == "SpectraHeis": |
|
1812 | if self.dataIn.type == "SpectraHeis": | |
1809 | self.dataOut.copy(self.dataIn) |
|
1813 | self.dataOut.copy(self.dataIn) | |
1810 | return |
|
1814 | return | |
1811 |
|
1815 | |||
1812 | if self.dataIn.type == "Voltage": |
|
1816 | if self.dataIn.type == "Voltage": | |
1813 | self.__updateObjFromInput() |
|
1817 | self.__updateObjFromInput() | |
1814 | self.__getFft() |
|
1818 | self.__getFft() | |
1815 | self.dataOut.flagNoData = False |
|
1819 | self.dataOut.flagNoData = False | |
1816 |
|
1820 | |||
1817 | return |
|
1821 | return | |
1818 |
|
1822 | |||
1819 | raise ValueError, "The type object %s is not valid"%(self.dataIn.type) |
|
1823 | raise ValueError, "The type object %s is not valid"%(self.dataIn.type) | |
1820 |
|
1824 | |||
1821 |
|
1825 | |||
1822 | def selectChannels(self, channelList): |
|
1826 | def selectChannels(self, channelList): | |
1823 |
|
1827 | |||
1824 | channelIndexList = [] |
|
1828 | channelIndexList = [] | |
1825 |
|
1829 | |||
1826 | for channel in channelList: |
|
1830 | for channel in channelList: | |
1827 | index = self.dataOut.channelList.index(channel) |
|
1831 | index = self.dataOut.channelList.index(channel) | |
1828 | channelIndexList.append(index) |
|
1832 | channelIndexList.append(index) | |
1829 |
|
1833 | |||
1830 | self.selectChannelsByIndex(channelIndexList) |
|
1834 | self.selectChannelsByIndex(channelIndexList) | |
1831 |
|
1835 | |||
1832 | def selectChannelsByIndex(self, channelIndexList): |
|
1836 | def selectChannelsByIndex(self, channelIndexList): | |
1833 | """ |
|
1837 | """ | |
1834 | Selecciona un bloque de datos en base a canales segun el channelIndexList |
|
1838 | Selecciona un bloque de datos en base a canales segun el channelIndexList | |
1835 |
|
1839 | |||
1836 | Input: |
|
1840 | Input: | |
1837 | channelIndexList : lista sencilla de canales a seleccionar por ej. [2,3,7] |
|
1841 | channelIndexList : lista sencilla de canales a seleccionar por ej. [2,3,7] | |
1838 |
|
1842 | |||
1839 | Affected: |
|
1843 | Affected: | |
1840 | self.dataOut.data |
|
1844 | self.dataOut.data | |
1841 | self.dataOut.channelIndexList |
|
1845 | self.dataOut.channelIndexList | |
1842 | self.dataOut.nChannels |
|
1846 | self.dataOut.nChannels | |
1843 | self.dataOut.m_ProcessingHeader.totalSpectra |
|
1847 | self.dataOut.m_ProcessingHeader.totalSpectra | |
1844 | self.dataOut.systemHeaderObj.numChannels |
|
1848 | self.dataOut.systemHeaderObj.numChannels | |
1845 | self.dataOut.m_ProcessingHeader.blockSize |
|
1849 | self.dataOut.m_ProcessingHeader.blockSize | |
1846 |
|
1850 | |||
1847 | Return: |
|
1851 | Return: | |
1848 | None |
|
1852 | None | |
1849 | """ |
|
1853 | """ | |
1850 |
|
1854 | |||
1851 | for channelIndex in channelIndexList: |
|
1855 | for channelIndex in channelIndexList: | |
1852 | if channelIndex not in self.dataOut.channelIndexList: |
|
1856 | if channelIndex not in self.dataOut.channelIndexList: | |
1853 | print channelIndexList |
|
1857 | print channelIndexList | |
1854 | raise ValueError, "The value %d in channelIndexList is not valid" %channelIndex |
|
1858 | raise ValueError, "The value %d in channelIndexList is not valid" %channelIndex | |
1855 |
|
1859 | |||
1856 | nChannels = len(channelIndexList) |
|
1860 | nChannels = len(channelIndexList) | |
1857 |
|
1861 | |||
1858 | data_spc = self.dataOut.data_spc[channelIndexList,:] |
|
1862 | data_spc = self.dataOut.data_spc[channelIndexList,:] | |
1859 |
|
1863 | |||
1860 | self.dataOut.data_spc = data_spc |
|
1864 | self.dataOut.data_spc = data_spc | |
1861 | self.dataOut.channelList = [self.dataOut.channelList[i] for i in channelIndexList] |
|
1865 | self.dataOut.channelList = [self.dataOut.channelList[i] for i in channelIndexList] | |
1862 |
|
1866 | |||
1863 | return 1 |
|
1867 | return 1 | |
1864 |
|
1868 | |||
1865 | class IncohInt4SpectraHeis(Operation): |
|
1869 | class IncohInt4SpectraHeis(Operation): | |
1866 |
|
1870 | |||
1867 | __isConfig = False |
|
1871 | __isConfig = False | |
1868 |
|
1872 | |||
1869 | __profIndex = 0 |
|
1873 | __profIndex = 0 | |
1870 | __withOverapping = False |
|
1874 | __withOverapping = False | |
1871 |
|
1875 | |||
1872 | __byTime = False |
|
1876 | __byTime = False | |
1873 | __initime = None |
|
1877 | __initime = None | |
1874 | __lastdatatime = None |
|
1878 | __lastdatatime = None | |
1875 | __integrationtime = None |
|
1879 | __integrationtime = None | |
1876 |
|
1880 | |||
1877 | __buffer = None |
|
1881 | __buffer = None | |
1878 |
|
1882 | |||
1879 | __dataReady = False |
|
1883 | __dataReady = False | |
1880 |
|
1884 | |||
1881 | n = None |
|
1885 | n = None | |
1882 |
|
1886 | |||
1883 |
|
1887 | |||
1884 | def __init__(self): |
|
1888 | def __init__(self): | |
1885 |
|
1889 | |||
1886 | self.__isConfig = False |
|
1890 | self.__isConfig = False | |
1887 |
|
1891 | |||
1888 | def setup(self, n=None, timeInterval=None, overlapping=False): |
|
1892 | def setup(self, n=None, timeInterval=None, overlapping=False): | |
1889 | """ |
|
1893 | """ | |
1890 | Set the parameters of the integration class. |
|
1894 | Set the parameters of the integration class. | |
1891 |
|
1895 | |||
1892 | Inputs: |
|
1896 | Inputs: | |
1893 |
|
1897 | |||
1894 | n : Number of coherent integrations |
|
1898 | n : Number of coherent integrations | |
1895 | timeInterval : Time of integration. If the parameter "n" is selected this one does not work |
|
1899 | timeInterval : Time of integration. If the parameter "n" is selected this one does not work | |
1896 | overlapping : |
|
1900 | overlapping : | |
1897 |
|
1901 | |||
1898 | """ |
|
1902 | """ | |
1899 |
|
1903 | |||
1900 | self.__initime = None |
|
1904 | self.__initime = None | |
1901 | self.__lastdatatime = 0 |
|
1905 | self.__lastdatatime = 0 | |
1902 | self.__buffer = None |
|
1906 | self.__buffer = None | |
1903 | self.__dataReady = False |
|
1907 | self.__dataReady = False | |
1904 |
|
1908 | |||
1905 |
|
1909 | |||
1906 | if n == None and timeInterval == None: |
|
1910 | if n == None and timeInterval == None: | |
1907 | raise ValueError, "n or timeInterval should be specified ..." |
|
1911 | raise ValueError, "n or timeInterval should be specified ..." | |
1908 |
|
1912 | |||
1909 | if n != None: |
|
1913 | if n != None: | |
1910 | self.n = n |
|
1914 | self.n = n | |
1911 | self.__byTime = False |
|
1915 | self.__byTime = False | |
1912 | else: |
|
1916 | else: | |
1913 | self.__integrationtime = timeInterval #* 60. #if (type(timeInterval)!=integer) -> change this line |
|
1917 | self.__integrationtime = timeInterval #* 60. #if (type(timeInterval)!=integer) -> change this line | |
1914 | self.n = 9999 |
|
1918 | self.n = 9999 | |
1915 | self.__byTime = True |
|
1919 | self.__byTime = True | |
1916 |
|
1920 | |||
1917 | if overlapping: |
|
1921 | if overlapping: | |
1918 | self.__withOverapping = True |
|
1922 | self.__withOverapping = True | |
1919 | self.__buffer = None |
|
1923 | self.__buffer = None | |
1920 | else: |
|
1924 | else: | |
1921 | self.__withOverapping = False |
|
1925 | self.__withOverapping = False | |
1922 | self.__buffer = 0 |
|
1926 | self.__buffer = 0 | |
1923 |
|
1927 | |||
1924 | self.__profIndex = 0 |
|
1928 | self.__profIndex = 0 | |
1925 |
|
1929 | |||
1926 | def putData(self, data): |
|
1930 | def putData(self, data): | |
1927 |
|
1931 | |||
1928 | """ |
|
1932 | """ | |
1929 | Add a profile to the __buffer and increase in one the __profileIndex |
|
1933 | Add a profile to the __buffer and increase in one the __profileIndex | |
1930 |
|
1934 | |||
1931 | """ |
|
1935 | """ | |
1932 |
|
1936 | |||
1933 | if not self.__withOverapping: |
|
1937 | if not self.__withOverapping: | |
1934 | self.__buffer += data.copy() |
|
1938 | self.__buffer += data.copy() | |
1935 | self.__profIndex += 1 |
|
1939 | self.__profIndex += 1 | |
1936 | return |
|
1940 | return | |
1937 |
|
1941 | |||
1938 | #Overlapping data |
|
1942 | #Overlapping data | |
1939 | nChannels, nHeis = data.shape |
|
1943 | nChannels, nHeis = data.shape | |
1940 | data = numpy.reshape(data, (1, nChannels, nHeis)) |
|
1944 | data = numpy.reshape(data, (1, nChannels, nHeis)) | |
1941 |
|
1945 | |||
1942 | #If the buffer is empty then it takes the data value |
|
1946 | #If the buffer is empty then it takes the data value | |
1943 | if self.__buffer == None: |
|
1947 | if self.__buffer == None: | |
1944 | self.__buffer = data |
|
1948 | self.__buffer = data | |
1945 | self.__profIndex += 1 |
|
1949 | self.__profIndex += 1 | |
1946 | return |
|
1950 | return | |
1947 |
|
1951 | |||
1948 | #If the buffer length is lower than n then stakcing the data value |
|
1952 | #If the buffer length is lower than n then stakcing the data value | |
1949 | if self.__profIndex < self.n: |
|
1953 | if self.__profIndex < self.n: | |
1950 | self.__buffer = numpy.vstack((self.__buffer, data)) |
|
1954 | self.__buffer = numpy.vstack((self.__buffer, data)) | |
1951 | self.__profIndex += 1 |
|
1955 | self.__profIndex += 1 | |
1952 | return |
|
1956 | return | |
1953 |
|
1957 | |||
1954 | #If the buffer length is equal to n then replacing the last buffer value with the data value |
|
1958 | #If the buffer length is equal to n then replacing the last buffer value with the data value | |
1955 | self.__buffer = numpy.roll(self.__buffer, -1, axis=0) |
|
1959 | self.__buffer = numpy.roll(self.__buffer, -1, axis=0) | |
1956 | self.__buffer[self.n-1] = data |
|
1960 | self.__buffer[self.n-1] = data | |
1957 | self.__profIndex = self.n |
|
1961 | self.__profIndex = self.n | |
1958 | return |
|
1962 | return | |
1959 |
|
1963 | |||
1960 |
|
1964 | |||
1961 | def pushData(self): |
|
1965 | def pushData(self): | |
1962 | """ |
|
1966 | """ | |
1963 | Return the sum of the last profiles and the profiles used in the sum. |
|
1967 | Return the sum of the last profiles and the profiles used in the sum. | |
1964 |
|
1968 | |||
1965 | Affected: |
|
1969 | Affected: | |
1966 |
|
1970 | |||
1967 | self.__profileIndex |
|
1971 | self.__profileIndex | |
1968 |
|
1972 | |||
1969 | """ |
|
1973 | """ | |
1970 |
|
1974 | |||
1971 | if not self.__withOverapping: |
|
1975 | if not self.__withOverapping: | |
1972 | data = self.__buffer |
|
1976 | data = self.__buffer | |
1973 | n = self.__profIndex |
|
1977 | n = self.__profIndex | |
1974 |
|
1978 | |||
1975 | self.__buffer = 0 |
|
1979 | self.__buffer = 0 | |
1976 | self.__profIndex = 0 |
|
1980 | self.__profIndex = 0 | |
1977 |
|
1981 | |||
1978 | return data, n |
|
1982 | return data, n | |
1979 |
|
1983 | |||
1980 | #Integration with Overlapping |
|
1984 | #Integration with Overlapping | |
1981 | data = numpy.sum(self.__buffer, axis=0) |
|
1985 | data = numpy.sum(self.__buffer, axis=0) | |
1982 | n = self.__profIndex |
|
1986 | n = self.__profIndex | |
1983 |
|
1987 | |||
1984 | return data, n |
|
1988 | return data, n | |
1985 |
|
1989 | |||
1986 | def byProfiles(self, data): |
|
1990 | def byProfiles(self, data): | |
1987 |
|
1991 | |||
1988 | self.__dataReady = False |
|
1992 | self.__dataReady = False | |
1989 | avgdata = None |
|
1993 | avgdata = None | |
1990 | n = None |
|
1994 | n = None | |
1991 |
|
1995 | |||
1992 | self.putData(data) |
|
1996 | self.putData(data) | |
1993 |
|
1997 | |||
1994 | if self.__profIndex == self.n: |
|
1998 | if self.__profIndex == self.n: | |
1995 |
|
1999 | |||
1996 | avgdata, n = self.pushData() |
|
2000 | avgdata, n = self.pushData() | |
1997 | self.__dataReady = True |
|
2001 | self.__dataReady = True | |
1998 |
|
2002 | |||
1999 | return avgdata |
|
2003 | return avgdata | |
2000 |
|
2004 | |||
2001 | def byTime(self, data, datatime): |
|
2005 | def byTime(self, data, datatime): | |
2002 |
|
2006 | |||
2003 | self.__dataReady = False |
|
2007 | self.__dataReady = False | |
2004 | avgdata = None |
|
2008 | avgdata = None | |
2005 | n = None |
|
2009 | n = None | |
2006 |
|
2010 | |||
2007 | self.putData(data) |
|
2011 | self.putData(data) | |
2008 |
|
2012 | |||
2009 | if (datatime - self.__initime) >= self.__integrationtime: |
|
2013 | if (datatime - self.__initime) >= self.__integrationtime: | |
2010 | avgdata, n = self.pushData() |
|
2014 | avgdata, n = self.pushData() | |
2011 | self.n = n |
|
2015 | self.n = n | |
2012 | self.__dataReady = True |
|
2016 | self.__dataReady = True | |
2013 |
|
2017 | |||
2014 | return avgdata |
|
2018 | return avgdata | |
2015 |
|
2019 | |||
2016 | def integrate(self, data, datatime=None): |
|
2020 | def integrate(self, data, datatime=None): | |
2017 |
|
2021 | |||
2018 | if self.__initime == None: |
|
2022 | if self.__initime == None: | |
2019 | self.__initime = datatime |
|
2023 | self.__initime = datatime | |
2020 |
|
2024 | |||
2021 | if self.__byTime: |
|
2025 | if self.__byTime: | |
2022 | avgdata = self.byTime(data, datatime) |
|
2026 | avgdata = self.byTime(data, datatime) | |
2023 | else: |
|
2027 | else: | |
2024 | avgdata = self.byProfiles(data) |
|
2028 | avgdata = self.byProfiles(data) | |
2025 |
|
2029 | |||
2026 |
|
2030 | |||
2027 | self.__lastdatatime = datatime |
|
2031 | self.__lastdatatime = datatime | |
2028 |
|
2032 | |||
2029 | if avgdata == None: |
|
2033 | if avgdata == None: | |
2030 | return None, None |
|
2034 | return None, None | |
2031 |
|
2035 | |||
2032 | avgdatatime = self.__initime |
|
2036 | avgdatatime = self.__initime | |
2033 |
|
2037 | |||
2034 | deltatime = datatime -self.__lastdatatime |
|
2038 | deltatime = datatime -self.__lastdatatime | |
2035 |
|
2039 | |||
2036 | if not self.__withOverapping: |
|
2040 | if not self.__withOverapping: | |
2037 | self.__initime = datatime |
|
2041 | self.__initime = datatime | |
2038 | else: |
|
2042 | else: | |
2039 | self.__initime += deltatime |
|
2043 | self.__initime += deltatime | |
2040 |
|
2044 | |||
2041 | return avgdata, avgdatatime |
|
2045 | return avgdata, avgdatatime | |
2042 |
|
2046 | |||
2043 | def run(self, dataOut, **kwargs): |
|
2047 | def run(self, dataOut, **kwargs): | |
2044 |
|
2048 | |||
2045 | if not self.__isConfig: |
|
2049 | if not self.__isConfig: | |
2046 | self.setup(**kwargs) |
|
2050 | self.setup(**kwargs) | |
2047 | self.__isConfig = True |
|
2051 | self.__isConfig = True | |
2048 |
|
2052 | |||
2049 | avgdata, avgdatatime = self.integrate(dataOut.data_spc, dataOut.utctime) |
|
2053 | avgdata, avgdatatime = self.integrate(dataOut.data_spc, dataOut.utctime) | |
2050 |
|
2054 | |||
2051 | # dataOut.timeInterval *= n |
|
2055 | # dataOut.timeInterval *= n | |
2052 | dataOut.flagNoData = True |
|
2056 | dataOut.flagNoData = True | |
2053 |
|
2057 | |||
2054 | if self.__dataReady: |
|
2058 | if self.__dataReady: | |
2055 | dataOut.data_spc = avgdata |
|
2059 | dataOut.data_spc = avgdata | |
2056 | dataOut.nIncohInt *= self.n |
|
2060 | dataOut.nIncohInt *= self.n | |
2057 | # dataOut.nCohInt *= self.n |
|
2061 | # dataOut.nCohInt *= self.n | |
2058 | dataOut.utctime = avgdatatime |
|
2062 | dataOut.utctime = avgdatatime | |
2059 | dataOut.timeInterval = dataOut.ippSeconds * dataOut.nIncohInt |
|
2063 | dataOut.timeInterval = dataOut.ippSeconds * dataOut.nIncohInt | |
2060 | # dataOut.timeInterval = self.__timeInterval*self.n |
|
2064 | # dataOut.timeInterval = self.__timeInterval*self.n | |
2061 | dataOut.flagNoData = False |
|
2065 | dataOut.flagNoData = False | |
2062 |
|
2066 | |||
2063 |
|
2067 | |||
2064 |
|
2068 | |||
2065 |
|
2069 | |||
2066 | No newline at end of file |
|
2070 |
General Comments 0
You need to be logged in to leave comments.
Login now