1 | NO CONTENT: modified file |
|
NO CONTENT: modified file |
@@ -1,1228 +1,1220 | |||||
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 copy |
|
7 | import copy | |
8 | import numpy |
|
8 | import numpy | |
9 | import datetime |
|
9 | import datetime | |
10 |
|
10 | |||
11 | from jroheaderIO import SystemHeader, RadarControllerHeader |
|
11 | from jroheaderIO import SystemHeader, RadarControllerHeader | |
12 | from schainpy import cSchain |
|
12 | from schainpy import cSchain | |
13 |
|
13 | |||
14 |
|
14 | |||
15 | def getNumpyDtype(dataTypeCode): |
|
15 | def getNumpyDtype(dataTypeCode): | |
16 |
|
16 | |||
17 | if dataTypeCode == 0: |
|
17 | if dataTypeCode == 0: | |
18 | numpyDtype = numpy.dtype([('real','<i1'),('imag','<i1')]) |
|
18 | numpyDtype = numpy.dtype([('real','<i1'),('imag','<i1')]) | |
19 | elif dataTypeCode == 1: |
|
19 | elif dataTypeCode == 1: | |
20 | numpyDtype = numpy.dtype([('real','<i2'),('imag','<i2')]) |
|
20 | numpyDtype = numpy.dtype([('real','<i2'),('imag','<i2')]) | |
21 | elif dataTypeCode == 2: |
|
21 | elif dataTypeCode == 2: | |
22 | numpyDtype = numpy.dtype([('real','<i4'),('imag','<i4')]) |
|
22 | numpyDtype = numpy.dtype([('real','<i4'),('imag','<i4')]) | |
23 | elif dataTypeCode == 3: |
|
23 | elif dataTypeCode == 3: | |
24 | numpyDtype = numpy.dtype([('real','<i8'),('imag','<i8')]) |
|
24 | numpyDtype = numpy.dtype([('real','<i8'),('imag','<i8')]) | |
25 | elif dataTypeCode == 4: |
|
25 | elif dataTypeCode == 4: | |
26 | numpyDtype = numpy.dtype([('real','<f4'),('imag','<f4')]) |
|
26 | numpyDtype = numpy.dtype([('real','<f4'),('imag','<f4')]) | |
27 | elif dataTypeCode == 5: |
|
27 | elif dataTypeCode == 5: | |
28 | numpyDtype = numpy.dtype([('real','<f8'),('imag','<f8')]) |
|
28 | numpyDtype = numpy.dtype([('real','<f8'),('imag','<f8')]) | |
29 | else: |
|
29 | else: | |
30 | raise ValueError, 'dataTypeCode was not defined' |
|
30 | raise ValueError, 'dataTypeCode was not defined' | |
31 |
|
31 | |||
32 | return numpyDtype |
|
32 | return numpyDtype | |
33 |
|
33 | |||
34 | def getDataTypeCode(numpyDtype): |
|
34 | def getDataTypeCode(numpyDtype): | |
35 |
|
35 | |||
36 | if numpyDtype == numpy.dtype([('real','<i1'),('imag','<i1')]): |
|
36 | if numpyDtype == numpy.dtype([('real','<i1'),('imag','<i1')]): | |
37 | datatype = 0 |
|
37 | datatype = 0 | |
38 | elif numpyDtype == numpy.dtype([('real','<i2'),('imag','<i2')]): |
|
38 | elif numpyDtype == numpy.dtype([('real','<i2'),('imag','<i2')]): | |
39 | datatype = 1 |
|
39 | datatype = 1 | |
40 | elif numpyDtype == numpy.dtype([('real','<i4'),('imag','<i4')]): |
|
40 | elif numpyDtype == numpy.dtype([('real','<i4'),('imag','<i4')]): | |
41 | datatype = 2 |
|
41 | datatype = 2 | |
42 | elif numpyDtype == numpy.dtype([('real','<i8'),('imag','<i8')]): |
|
42 | elif numpyDtype == numpy.dtype([('real','<i8'),('imag','<i8')]): | |
43 | datatype = 3 |
|
43 | datatype = 3 | |
44 | elif numpyDtype == numpy.dtype([('real','<f4'),('imag','<f4')]): |
|
44 | elif numpyDtype == numpy.dtype([('real','<f4'),('imag','<f4')]): | |
45 | datatype = 4 |
|
45 | datatype = 4 | |
46 | elif numpyDtype == numpy.dtype([('real','<f8'),('imag','<f8')]): |
|
46 | elif numpyDtype == numpy.dtype([('real','<f8'),('imag','<f8')]): | |
47 | datatype = 5 |
|
47 | datatype = 5 | |
48 | else: |
|
48 | else: | |
49 | datatype = None |
|
49 | datatype = None | |
50 |
|
50 | |||
51 | return datatype |
|
51 | return datatype | |
52 |
|
52 | |||
53 | def hildebrand_sekhon(data, navg): |
|
53 | def hildebrand_sekhon(data, navg): | |
54 | """ |
|
54 | """ | |
55 | This method is for the objective determination of the noise level in Doppler spectra. This |
|
55 | This method is for the objective determination of the noise level in Doppler spectra. This | |
56 | implementation technique is based on the fact that the standard deviation of the spectral |
|
56 | implementation technique is based on the fact that the standard deviation of the spectral | |
57 | densities is equal to the mean spectral density for white Gaussian noise |
|
57 | densities is equal to the mean spectral density for white Gaussian noise | |
58 |
|
58 | |||
59 | Inputs: |
|
59 | Inputs: | |
60 | Data : heights |
|
60 | Data : heights | |
61 | navg : numbers of averages |
|
61 | navg : numbers of averages | |
62 |
|
62 | |||
63 | Return: |
|
63 | Return: | |
64 | -1 : any error |
|
64 | -1 : any error | |
65 | anoise : noise's level |
|
65 | anoise : noise's level | |
66 | """ |
|
66 | """ | |
67 |
|
67 | |||
68 | sortdata = numpy.sort(data, axis=None) |
|
68 | sortdata = numpy.sort(data, axis=None) | |
69 | # lenOfData = len(sortdata) |
|
69 | # lenOfData = len(sortdata) | |
70 | # nums_min = lenOfData*0.2 |
|
70 | # nums_min = lenOfData*0.2 | |
71 | # |
|
71 | # | |
72 | # if nums_min <= 5: |
|
72 | # if nums_min <= 5: | |
73 | # nums_min = 5 |
|
73 | # nums_min = 5 | |
74 | # |
|
74 | # | |
75 | # sump = 0. |
|
75 | # sump = 0. | |
76 | # |
|
76 | # | |
77 | # sumq = 0. |
|
77 | # sumq = 0. | |
78 | # |
|
78 | # | |
79 | # j = 0 |
|
79 | # j = 0 | |
80 | # |
|
80 | # | |
81 | # cont = 1 |
|
81 | # cont = 1 | |
82 | # |
|
82 | # | |
83 | # while((cont==1)and(j<lenOfData)): |
|
83 | # while((cont==1)and(j<lenOfData)): | |
84 | # |
|
84 | # | |
85 | # sump += sortdata[j] |
|
85 | # sump += sortdata[j] | |
86 | # |
|
86 | # | |
87 | # sumq += sortdata[j]**2 |
|
87 | # sumq += sortdata[j]**2 | |
88 | # |
|
88 | # | |
89 | # if j > nums_min: |
|
89 | # if j > nums_min: | |
90 | # rtest = float(j)/(j-1) + 1.0/navg |
|
90 | # rtest = float(j)/(j-1) + 1.0/navg | |
91 | # if ((sumq*j) > (rtest*sump**2)): |
|
91 | # if ((sumq*j) > (rtest*sump**2)): | |
92 | # j = j - 1 |
|
92 | # j = j - 1 | |
93 | # sump = sump - sortdata[j] |
|
93 | # sump = sump - sortdata[j] | |
94 | # sumq = sumq - sortdata[j]**2 |
|
94 | # sumq = sumq - sortdata[j]**2 | |
95 | # cont = 0 |
|
95 | # cont = 0 | |
96 | # |
|
96 | # | |
97 | # j += 1 |
|
97 | # j += 1 | |
98 | # |
|
98 | # | |
99 | # lnoise = sump /j |
|
99 | # lnoise = sump /j | |
100 | # |
|
100 | # | |
101 | # return lnoise |
|
101 | # return lnoise | |
102 |
|
102 | |||
103 | return cSchain.hildebrand_sekhon(sortdata, navg) |
|
103 | return cSchain.hildebrand_sekhon(sortdata, navg) | |
104 |
|
104 | |||
105 |
|
105 | |||
106 | class Beam: |
|
106 | class Beam: | |
107 |
|
107 | |||
108 | def __init__(self): |
|
108 | def __init__(self): | |
109 | self.codeList = [] |
|
109 | self.codeList = [] | |
110 | self.azimuthList = [] |
|
110 | self.azimuthList = [] | |
111 | self.zenithList = [] |
|
111 | self.zenithList = [] | |
112 |
|
112 | |||
113 | class GenericData(object): |
|
113 | class GenericData(object): | |
114 |
|
114 | |||
115 | flagNoData = True |
|
115 | flagNoData = True | |
116 |
|
116 | |||
117 | def __init__(self): |
|
|||
118 |
|
||||
119 | raise NotImplementedError |
|
|||
120 |
|
||||
121 | def copy(self, inputObj=None): |
|
117 | def copy(self, inputObj=None): | |
122 |
|
118 | |||
123 | if inputObj == None: |
|
119 | if inputObj == None: | |
124 | return copy.deepcopy(self) |
|
120 | return copy.deepcopy(self) | |
125 |
|
121 | |||
126 | for key in inputObj.__dict__.keys(): |
|
122 | for key in inputObj.__dict__.keys(): | |
127 |
|
123 | |||
128 | attribute = inputObj.__dict__[key] |
|
124 | attribute = inputObj.__dict__[key] | |
129 |
|
125 | |||
130 | #If this attribute is a tuple or list |
|
126 | #If this attribute is a tuple or list | |
131 | if type(inputObj.__dict__[key]) in (tuple, list): |
|
127 | if type(inputObj.__dict__[key]) in (tuple, list): | |
132 | self.__dict__[key] = attribute[:] |
|
128 | self.__dict__[key] = attribute[:] | |
133 | continue |
|
129 | continue | |
134 |
|
130 | |||
135 | #If this attribute is another object or instance |
|
131 | #If this attribute is another object or instance | |
136 | if hasattr(attribute, '__dict__'): |
|
132 | if hasattr(attribute, '__dict__'): | |
137 | self.__dict__[key] = attribute.copy() |
|
133 | self.__dict__[key] = attribute.copy() | |
138 | continue |
|
134 | continue | |
139 |
|
135 | |||
140 | self.__dict__[key] = inputObj.__dict__[key] |
|
136 | self.__dict__[key] = inputObj.__dict__[key] | |
141 |
|
137 | |||
142 | def deepcopy(self): |
|
138 | def deepcopy(self): | |
143 |
|
139 | |||
144 | return copy.deepcopy(self) |
|
140 | return copy.deepcopy(self) | |
145 |
|
141 | |||
146 | def isEmpty(self): |
|
142 | def isEmpty(self): | |
147 |
|
143 | |||
148 | return self.flagNoData |
|
144 | return self.flagNoData | |
149 |
|
145 | |||
150 | class JROData(GenericData): |
|
146 | class JROData(GenericData): | |
151 |
|
147 | |||
152 | # m_BasicHeader = BasicHeader() |
|
148 | # m_BasicHeader = BasicHeader() | |
153 | # m_ProcessingHeader = ProcessingHeader() |
|
149 | # m_ProcessingHeader = ProcessingHeader() | |
154 |
|
150 | |||
155 | systemHeaderObj = SystemHeader() |
|
151 | systemHeaderObj = SystemHeader() | |
156 |
|
152 | |||
157 | radarControllerHeaderObj = RadarControllerHeader() |
|
153 | radarControllerHeaderObj = RadarControllerHeader() | |
158 |
|
154 | |||
159 | # data = None |
|
155 | # data = None | |
160 |
|
156 | |||
161 | type = None |
|
157 | type = None | |
162 |
|
158 | |||
163 | datatype = None #dtype but in string |
|
159 | datatype = None #dtype but in string | |
164 |
|
160 | |||
165 | # dtype = None |
|
161 | # dtype = None | |
166 |
|
162 | |||
167 | # nChannels = None |
|
163 | # nChannels = None | |
168 |
|
164 | |||
169 | # nHeights = None |
|
165 | # nHeights = None | |
170 |
|
166 | |||
171 | nProfiles = None |
|
167 | nProfiles = None | |
172 |
|
168 | |||
173 | heightList = None |
|
169 | heightList = None | |
174 |
|
170 | |||
175 | channelList = None |
|
171 | channelList = None | |
176 |
|
172 | |||
177 | flagDiscontinuousBlock = False |
|
173 | flagDiscontinuousBlock = False | |
178 |
|
174 | |||
179 | useLocalTime = False |
|
175 | useLocalTime = False | |
180 |
|
176 | |||
181 | utctime = None |
|
177 | utctime = None | |
182 |
|
178 | |||
183 | timeZone = None |
|
179 | timeZone = None | |
184 |
|
180 | |||
185 | dstFlag = None |
|
181 | dstFlag = None | |
186 |
|
182 | |||
187 | errorCount = None |
|
183 | errorCount = None | |
188 |
|
184 | |||
189 | blocksize = None |
|
185 | blocksize = None | |
190 |
|
186 | |||
191 | # nCode = None |
|
187 | # nCode = None | |
192 | # |
|
188 | # | |
193 | # nBaud = None |
|
189 | # nBaud = None | |
194 | # |
|
190 | # | |
195 | # code = None |
|
191 | # code = None | |
196 |
|
192 | |||
197 | flagDecodeData = False #asumo q la data no esta decodificada |
|
193 | flagDecodeData = False #asumo q la data no esta decodificada | |
198 |
|
194 | |||
199 | flagDeflipData = False #asumo q la data no esta sin flip |
|
195 | flagDeflipData = False #asumo q la data no esta sin flip | |
200 |
|
196 | |||
201 | flagShiftFFT = False |
|
197 | flagShiftFFT = False | |
202 |
|
198 | |||
203 | # ippSeconds = None |
|
199 | # ippSeconds = None | |
204 |
|
200 | |||
205 | # timeInterval = None |
|
201 | # timeInterval = None | |
206 |
|
202 | |||
207 | nCohInt = None |
|
203 | nCohInt = None | |
208 |
|
204 | |||
209 | # noise = None |
|
205 | # noise = None | |
210 |
|
206 | |||
211 | windowOfFilter = 1 |
|
207 | windowOfFilter = 1 | |
212 |
|
208 | |||
213 | #Speed of ligth |
|
209 | #Speed of ligth | |
214 | C = 3e8 |
|
210 | C = 3e8 | |
215 |
|
211 | |||
216 | frequency = 49.92e6 |
|
212 | frequency = 49.92e6 | |
217 |
|
213 | |||
218 | realtime = False |
|
214 | realtime = False | |
219 |
|
215 | |||
220 | beacon_heiIndexList = None |
|
216 | beacon_heiIndexList = None | |
221 |
|
217 | |||
222 | last_block = None |
|
218 | last_block = None | |
223 |
|
219 | |||
224 | blocknow = None |
|
220 | blocknow = None | |
225 |
|
221 | |||
226 | azimuth = None |
|
222 | azimuth = None | |
227 |
|
223 | |||
228 | zenith = None |
|
224 | zenith = None | |
229 |
|
225 | |||
230 | beam = Beam() |
|
226 | beam = Beam() | |
231 |
|
227 | |||
232 | profileIndex = None |
|
228 | profileIndex = None | |
233 |
|
229 | |||
234 | def __init__(self): |
|
|||
235 |
|
||||
236 | raise NotImplementedError |
|
|||
237 |
|
||||
238 | def getNoise(self): |
|
230 | def getNoise(self): | |
239 |
|
231 | |||
240 | raise NotImplementedError |
|
232 | raise NotImplementedError | |
241 |
|
233 | |||
242 | def getNChannels(self): |
|
234 | def getNChannels(self): | |
243 |
|
235 | |||
244 | return len(self.channelList) |
|
236 | return len(self.channelList) | |
245 |
|
237 | |||
246 | def getChannelIndexList(self): |
|
238 | def getChannelIndexList(self): | |
247 |
|
239 | |||
248 | return range(self.nChannels) |
|
240 | return range(self.nChannels) | |
249 |
|
241 | |||
250 | def getNHeights(self): |
|
242 | def getNHeights(self): | |
251 |
|
243 | |||
252 | return len(self.heightList) |
|
244 | return len(self.heightList) | |
253 |
|
245 | |||
254 | def getHeiRange(self, extrapoints=0): |
|
246 | def getHeiRange(self, extrapoints=0): | |
255 |
|
247 | |||
256 | heis = self.heightList |
|
248 | heis = self.heightList | |
257 | # deltah = self.heightList[1] - self.heightList[0] |
|
249 | # deltah = self.heightList[1] - self.heightList[0] | |
258 | # |
|
250 | # | |
259 | # heis.append(self.heightList[-1]) |
|
251 | # heis.append(self.heightList[-1]) | |
260 |
|
252 | |||
261 | return heis |
|
253 | return heis | |
262 |
|
254 | |||
263 | def getDeltaH(self): |
|
255 | def getDeltaH(self): | |
264 |
|
256 | |||
265 | delta = self.heightList[1] - self.heightList[0] |
|
257 | delta = self.heightList[1] - self.heightList[0] | |
266 |
|
258 | |||
267 | return delta |
|
259 | return delta | |
268 |
|
260 | |||
269 | def getltctime(self): |
|
261 | def getltctime(self): | |
270 |
|
262 | |||
271 | if self.useLocalTime: |
|
263 | if self.useLocalTime: | |
272 | return self.utctime - self.timeZone*60 |
|
264 | return self.utctime - self.timeZone*60 | |
273 |
|
265 | |||
274 | return self.utctime |
|
266 | return self.utctime | |
275 |
|
267 | |||
276 | def getDatatime(self): |
|
268 | def getDatatime(self): | |
277 |
|
269 | |||
278 | datatimeValue = datetime.datetime.utcfromtimestamp(self.ltctime) |
|
270 | datatimeValue = datetime.datetime.utcfromtimestamp(self.ltctime) | |
279 | return datatimeValue |
|
271 | return datatimeValue | |
280 |
|
272 | |||
281 | def getTimeRange(self): |
|
273 | def getTimeRange(self): | |
282 |
|
274 | |||
283 | datatime = [] |
|
275 | datatime = [] | |
284 |
|
276 | |||
285 | datatime.append(self.ltctime) |
|
277 | datatime.append(self.ltctime) | |
286 | datatime.append(self.ltctime + self.timeInterval+1) |
|
278 | datatime.append(self.ltctime + self.timeInterval+1) | |
287 |
|
279 | |||
288 | datatime = numpy.array(datatime) |
|
280 | datatime = numpy.array(datatime) | |
289 |
|
281 | |||
290 | return datatime |
|
282 | return datatime | |
291 |
|
283 | |||
292 | def getFmaxTimeResponse(self): |
|
284 | def getFmaxTimeResponse(self): | |
293 |
|
285 | |||
294 | period = (10**-6)*self.getDeltaH()/(0.15) |
|
286 | period = (10**-6)*self.getDeltaH()/(0.15) | |
295 |
|
287 | |||
296 | PRF = 1./(period * self.nCohInt) |
|
288 | PRF = 1./(period * self.nCohInt) | |
297 |
|
289 | |||
298 | fmax = PRF |
|
290 | fmax = PRF | |
299 |
|
291 | |||
300 | return fmax |
|
292 | return fmax | |
301 |
|
293 | |||
302 | def getFmax(self): |
|
294 | def getFmax(self): | |
303 |
|
295 | |||
304 | PRF = 1./(self.ippSeconds * self.nCohInt) |
|
296 | PRF = 1./(self.ippSeconds * self.nCohInt) | |
305 |
|
297 | |||
306 | fmax = PRF |
|
298 | fmax = PRF | |
307 |
|
299 | |||
308 | return fmax |
|
300 | return fmax | |
309 |
|
301 | |||
310 | def getVmax(self): |
|
302 | def getVmax(self): | |
311 |
|
303 | |||
312 | _lambda = self.C/self.frequency |
|
304 | _lambda = self.C/self.frequency | |
313 |
|
305 | |||
314 | vmax = self.getFmax() * _lambda/2 |
|
306 | vmax = self.getFmax() * _lambda/2 | |
315 |
|
307 | |||
316 | return vmax |
|
308 | return vmax | |
317 |
|
309 | |||
318 | def get_ippSeconds(self): |
|
310 | def get_ippSeconds(self): | |
319 | ''' |
|
311 | ''' | |
320 | ''' |
|
312 | ''' | |
321 | return self.radarControllerHeaderObj.ippSeconds |
|
313 | return self.radarControllerHeaderObj.ippSeconds | |
322 |
|
314 | |||
323 | def set_ippSeconds(self, ippSeconds): |
|
315 | def set_ippSeconds(self, ippSeconds): | |
324 | ''' |
|
316 | ''' | |
325 | ''' |
|
317 | ''' | |
326 |
|
318 | |||
327 | self.radarControllerHeaderObj.ippSeconds = ippSeconds |
|
319 | self.radarControllerHeaderObj.ippSeconds = ippSeconds | |
328 |
|
320 | |||
329 | return |
|
321 | return | |
330 |
|
322 | |||
331 | def get_dtype(self): |
|
323 | def get_dtype(self): | |
332 | ''' |
|
324 | ''' | |
333 | ''' |
|
325 | ''' | |
334 | return getNumpyDtype(self.datatype) |
|
326 | return getNumpyDtype(self.datatype) | |
335 |
|
327 | |||
336 | def set_dtype(self, numpyDtype): |
|
328 | def set_dtype(self, numpyDtype): | |
337 | ''' |
|
329 | ''' | |
338 | ''' |
|
330 | ''' | |
339 |
|
331 | |||
340 | self.datatype = getDataTypeCode(numpyDtype) |
|
332 | self.datatype = getDataTypeCode(numpyDtype) | |
341 |
|
333 | |||
342 | def get_code(self): |
|
334 | def get_code(self): | |
343 | ''' |
|
335 | ''' | |
344 | ''' |
|
336 | ''' | |
345 | return self.radarControllerHeaderObj.code |
|
337 | return self.radarControllerHeaderObj.code | |
346 |
|
338 | |||
347 | def set_code(self, code): |
|
339 | def set_code(self, code): | |
348 | ''' |
|
340 | ''' | |
349 | ''' |
|
341 | ''' | |
350 | self.radarControllerHeaderObj.code = code |
|
342 | self.radarControllerHeaderObj.code = code | |
351 |
|
343 | |||
352 | return |
|
344 | return | |
353 |
|
345 | |||
354 | def get_ncode(self): |
|
346 | def get_ncode(self): | |
355 | ''' |
|
347 | ''' | |
356 | ''' |
|
348 | ''' | |
357 | return self.radarControllerHeaderObj.nCode |
|
349 | return self.radarControllerHeaderObj.nCode | |
358 |
|
350 | |||
359 | def set_ncode(self, nCode): |
|
351 | def set_ncode(self, nCode): | |
360 | ''' |
|
352 | ''' | |
361 | ''' |
|
353 | ''' | |
362 | self.radarControllerHeaderObj.nCode = nCode |
|
354 | self.radarControllerHeaderObj.nCode = nCode | |
363 |
|
355 | |||
364 | return |
|
356 | return | |
365 |
|
357 | |||
366 | def get_nbaud(self): |
|
358 | def get_nbaud(self): | |
367 | ''' |
|
359 | ''' | |
368 | ''' |
|
360 | ''' | |
369 | return self.radarControllerHeaderObj.nBaud |
|
361 | return self.radarControllerHeaderObj.nBaud | |
370 |
|
362 | |||
371 | def set_nbaud(self, nBaud): |
|
363 | def set_nbaud(self, nBaud): | |
372 | ''' |
|
364 | ''' | |
373 | ''' |
|
365 | ''' | |
374 | self.radarControllerHeaderObj.nBaud = nBaud |
|
366 | self.radarControllerHeaderObj.nBaud = nBaud | |
375 |
|
367 | |||
376 | return |
|
368 | return | |
377 |
|
369 | |||
378 | nChannels = property(getNChannels, "I'm the 'nChannel' property.") |
|
370 | nChannels = property(getNChannels, "I'm the 'nChannel' property.") | |
379 | channelIndexList = property(getChannelIndexList, "I'm the 'channelIndexList' property.") |
|
371 | channelIndexList = property(getChannelIndexList, "I'm the 'channelIndexList' property.") | |
380 | nHeights = property(getNHeights, "I'm the 'nHeights' property.") |
|
372 | nHeights = property(getNHeights, "I'm the 'nHeights' property.") | |
381 | #noise = property(getNoise, "I'm the 'nHeights' property.") |
|
373 | #noise = property(getNoise, "I'm the 'nHeights' property.") | |
382 | datatime = property(getDatatime, "I'm the 'datatime' property") |
|
374 | datatime = property(getDatatime, "I'm the 'datatime' property") | |
383 | ltctime = property(getltctime, "I'm the 'ltctime' property") |
|
375 | ltctime = property(getltctime, "I'm the 'ltctime' property") | |
384 | ippSeconds = property(get_ippSeconds, set_ippSeconds) |
|
376 | ippSeconds = property(get_ippSeconds, set_ippSeconds) | |
385 | dtype = property(get_dtype, set_dtype) |
|
377 | dtype = property(get_dtype, set_dtype) | |
386 | # timeInterval = property(getTimeInterval, "I'm the 'timeInterval' property") |
|
378 | # timeInterval = property(getTimeInterval, "I'm the 'timeInterval' property") | |
387 | code = property(get_code, set_code) |
|
379 | code = property(get_code, set_code) | |
388 | nCode = property(get_ncode, set_ncode) |
|
380 | nCode = property(get_ncode, set_ncode) | |
389 | nBaud = property(get_nbaud, set_nbaud) |
|
381 | nBaud = property(get_nbaud, set_nbaud) | |
390 |
|
382 | |||
391 | class Voltage(JROData): |
|
383 | class Voltage(JROData): | |
392 |
|
384 | |||
393 | #data es un numpy array de 2 dmensiones (canales, alturas) |
|
385 | #data es un numpy array de 2 dmensiones (canales, alturas) | |
394 | data = None |
|
386 | data = None | |
395 |
|
387 | |||
396 | def __init__(self): |
|
388 | def __init__(self): | |
397 | ''' |
|
389 | ''' | |
398 | Constructor |
|
390 | Constructor | |
399 | ''' |
|
391 | ''' | |
400 |
|
392 | |||
401 | self.useLocalTime = True |
|
393 | self.useLocalTime = True | |
402 |
|
394 | |||
403 | self.radarControllerHeaderObj = RadarControllerHeader() |
|
395 | self.radarControllerHeaderObj = RadarControllerHeader() | |
404 |
|
396 | |||
405 | self.systemHeaderObj = SystemHeader() |
|
397 | self.systemHeaderObj = SystemHeader() | |
406 |
|
398 | |||
407 | self.type = "Voltage" |
|
399 | self.type = "Voltage" | |
408 |
|
400 | |||
409 | self.data = None |
|
401 | self.data = None | |
410 |
|
402 | |||
411 | # self.dtype = None |
|
403 | # self.dtype = None | |
412 |
|
404 | |||
413 | # self.nChannels = 0 |
|
405 | # self.nChannels = 0 | |
414 |
|
406 | |||
415 | # self.nHeights = 0 |
|
407 | # self.nHeights = 0 | |
416 |
|
408 | |||
417 | self.nProfiles = None |
|
409 | self.nProfiles = None | |
418 |
|
410 | |||
419 | self.heightList = None |
|
411 | self.heightList = None | |
420 |
|
412 | |||
421 | self.channelList = None |
|
413 | self.channelList = None | |
422 |
|
414 | |||
423 | # self.channelIndexList = None |
|
415 | # self.channelIndexList = None | |
424 |
|
416 | |||
425 | self.flagNoData = True |
|
417 | self.flagNoData = True | |
426 |
|
418 | |||
427 | self.flagDiscontinuousBlock = False |
|
419 | self.flagDiscontinuousBlock = False | |
428 |
|
420 | |||
429 | self.utctime = None |
|
421 | self.utctime = None | |
430 |
|
422 | |||
431 | self.timeZone = None |
|
423 | self.timeZone = None | |
432 |
|
424 | |||
433 | self.dstFlag = None |
|
425 | self.dstFlag = None | |
434 |
|
426 | |||
435 | self.errorCount = None |
|
427 | self.errorCount = None | |
436 |
|
428 | |||
437 | self.nCohInt = None |
|
429 | self.nCohInt = None | |
438 |
|
430 | |||
439 | self.blocksize = None |
|
431 | self.blocksize = None | |
440 |
|
432 | |||
441 | self.flagDecodeData = False #asumo q la data no esta decodificada |
|
433 | self.flagDecodeData = False #asumo q la data no esta decodificada | |
442 |
|
434 | |||
443 | self.flagDeflipData = False #asumo q la data no esta sin flip |
|
435 | self.flagDeflipData = False #asumo q la data no esta sin flip | |
444 |
|
436 | |||
445 | self.flagShiftFFT = False |
|
437 | self.flagShiftFFT = False | |
446 |
|
438 | |||
447 | self.flagDataAsBlock = False #Asumo que la data es leida perfil a perfil |
|
439 | self.flagDataAsBlock = False #Asumo que la data es leida perfil a perfil | |
448 |
|
440 | |||
449 | self.profileIndex = 0 |
|
441 | self.profileIndex = 0 | |
450 |
|
442 | |||
451 | def getNoisebyHildebrand(self, channel = None): |
|
443 | def getNoisebyHildebrand(self, channel = None): | |
452 | """ |
|
444 | """ | |
453 | Determino el nivel de ruido usando el metodo Hildebrand-Sekhon |
|
445 | Determino el nivel de ruido usando el metodo Hildebrand-Sekhon | |
454 |
|
446 | |||
455 | Return: |
|
447 | Return: | |
456 | noiselevel |
|
448 | noiselevel | |
457 | """ |
|
449 | """ | |
458 |
|
450 | |||
459 | if channel != None: |
|
451 | if channel != None: | |
460 | data = self.data[channel] |
|
452 | data = self.data[channel] | |
461 | nChannels = 1 |
|
453 | nChannels = 1 | |
462 | else: |
|
454 | else: | |
463 | data = self.data |
|
455 | data = self.data | |
464 | nChannels = self.nChannels |
|
456 | nChannels = self.nChannels | |
465 |
|
457 | |||
466 | noise = numpy.zeros(nChannels) |
|
458 | noise = numpy.zeros(nChannels) | |
467 | power = data * numpy.conjugate(data) |
|
459 | power = data * numpy.conjugate(data) | |
468 |
|
460 | |||
469 | for thisChannel in range(nChannels): |
|
461 | for thisChannel in range(nChannels): | |
470 | if nChannels == 1: |
|
462 | if nChannels == 1: | |
471 | daux = power[:].real |
|
463 | daux = power[:].real | |
472 | else: |
|
464 | else: | |
473 | daux = power[thisChannel,:].real |
|
465 | daux = power[thisChannel,:].real | |
474 | noise[thisChannel] = hildebrand_sekhon(daux, self.nCohInt) |
|
466 | noise[thisChannel] = hildebrand_sekhon(daux, self.nCohInt) | |
475 |
|
467 | |||
476 | return noise |
|
468 | return noise | |
477 |
|
469 | |||
478 | def getNoise(self, type = 1, channel = None): |
|
470 | def getNoise(self, type = 1, channel = None): | |
479 |
|
471 | |||
480 | if type == 1: |
|
472 | if type == 1: | |
481 | noise = self.getNoisebyHildebrand(channel) |
|
473 | noise = self.getNoisebyHildebrand(channel) | |
482 |
|
474 | |||
483 | return noise |
|
475 | return noise | |
484 |
|
476 | |||
485 | def getPower(self, channel = None): |
|
477 | def getPower(self, channel = None): | |
486 |
|
478 | |||
487 | if channel != None: |
|
479 | if channel != None: | |
488 | data = self.data[channel] |
|
480 | data = self.data[channel] | |
489 | else: |
|
481 | else: | |
490 | data = self.data |
|
482 | data = self.data | |
491 |
|
483 | |||
492 | power = data * numpy.conjugate(data) |
|
484 | power = data * numpy.conjugate(data) | |
493 | powerdB = 10*numpy.log10(power.real) |
|
485 | powerdB = 10*numpy.log10(power.real) | |
494 | powerdB = numpy.squeeze(powerdB) |
|
486 | powerdB = numpy.squeeze(powerdB) | |
495 |
|
487 | |||
496 | return powerdB |
|
488 | return powerdB | |
497 |
|
489 | |||
498 | def getTimeInterval(self): |
|
490 | def getTimeInterval(self): | |
499 |
|
491 | |||
500 | timeInterval = self.ippSeconds * self.nCohInt |
|
492 | timeInterval = self.ippSeconds * self.nCohInt | |
501 |
|
493 | |||
502 | return timeInterval |
|
494 | return timeInterval | |
503 |
|
495 | |||
504 | noise = property(getNoise, "I'm the 'nHeights' property.") |
|
496 | noise = property(getNoise, "I'm the 'nHeights' property.") | |
505 | timeInterval = property(getTimeInterval, "I'm the 'timeInterval' property") |
|
497 | timeInterval = property(getTimeInterval, "I'm the 'timeInterval' property") | |
506 |
|
498 | |||
507 | class Spectra(JROData): |
|
499 | class Spectra(JROData): | |
508 |
|
500 | |||
509 | #data spc es un numpy array de 2 dmensiones (canales, perfiles, alturas) |
|
501 | #data spc es un numpy array de 2 dmensiones (canales, perfiles, alturas) | |
510 | data_spc = None |
|
502 | data_spc = None | |
511 |
|
503 | |||
512 | #data cspc es un numpy array de 2 dmensiones (canales, pares, alturas) |
|
504 | #data cspc es un numpy array de 2 dmensiones (canales, pares, alturas) | |
513 | data_cspc = None |
|
505 | data_cspc = None | |
514 |
|
506 | |||
515 | #data dc es un numpy array de 2 dmensiones (canales, alturas) |
|
507 | #data dc es un numpy array de 2 dmensiones (canales, alturas) | |
516 | data_dc = None |
|
508 | data_dc = None | |
517 |
|
509 | |||
518 | #data power |
|
510 | #data power | |
519 | data_pwr = None |
|
511 | data_pwr = None | |
520 |
|
512 | |||
521 | nFFTPoints = None |
|
513 | nFFTPoints = None | |
522 |
|
514 | |||
523 | # nPairs = None |
|
515 | # nPairs = None | |
524 |
|
516 | |||
525 | pairsList = None |
|
517 | pairsList = None | |
526 |
|
518 | |||
527 | nIncohInt = None |
|
519 | nIncohInt = None | |
528 |
|
520 | |||
529 | wavelength = None #Necesario para cacular el rango de velocidad desde la frecuencia |
|
521 | wavelength = None #Necesario para cacular el rango de velocidad desde la frecuencia | |
530 |
|
522 | |||
531 | nCohInt = None #se requiere para determinar el valor de timeInterval |
|
523 | nCohInt = None #se requiere para determinar el valor de timeInterval | |
532 |
|
524 | |||
533 | ippFactor = None |
|
525 | ippFactor = None | |
534 |
|
526 | |||
535 | profileIndex = 0 |
|
527 | profileIndex = 0 | |
536 |
|
528 | |||
537 | plotting = "spectra" |
|
529 | plotting = "spectra" | |
538 |
|
530 | |||
539 | def __init__(self): |
|
531 | def __init__(self): | |
540 | ''' |
|
532 | ''' | |
541 | Constructor |
|
533 | Constructor | |
542 | ''' |
|
534 | ''' | |
543 |
|
535 | |||
544 | self.useLocalTime = True |
|
536 | self.useLocalTime = True | |
545 |
|
537 | |||
546 | self.radarControllerHeaderObj = RadarControllerHeader() |
|
538 | self.radarControllerHeaderObj = RadarControllerHeader() | |
547 |
|
539 | |||
548 | self.systemHeaderObj = SystemHeader() |
|
540 | self.systemHeaderObj = SystemHeader() | |
549 |
|
541 | |||
550 | self.type = "Spectra" |
|
542 | self.type = "Spectra" | |
551 |
|
543 | |||
552 | # self.data = None |
|
544 | # self.data = None | |
553 |
|
545 | |||
554 | # self.dtype = None |
|
546 | # self.dtype = None | |
555 |
|
547 | |||
556 | # self.nChannels = 0 |
|
548 | # self.nChannels = 0 | |
557 |
|
549 | |||
558 | # self.nHeights = 0 |
|
550 | # self.nHeights = 0 | |
559 |
|
551 | |||
560 | self.nProfiles = None |
|
552 | self.nProfiles = None | |
561 |
|
553 | |||
562 | self.heightList = None |
|
554 | self.heightList = None | |
563 |
|
555 | |||
564 | self.channelList = None |
|
556 | self.channelList = None | |
565 |
|
557 | |||
566 | # self.channelIndexList = None |
|
558 | # self.channelIndexList = None | |
567 |
|
559 | |||
568 | self.pairsList = None |
|
560 | self.pairsList = None | |
569 |
|
561 | |||
570 | self.flagNoData = True |
|
562 | self.flagNoData = True | |
571 |
|
563 | |||
572 | self.flagDiscontinuousBlock = False |
|
564 | self.flagDiscontinuousBlock = False | |
573 |
|
565 | |||
574 | self.utctime = None |
|
566 | self.utctime = None | |
575 |
|
567 | |||
576 | self.nCohInt = None |
|
568 | self.nCohInt = None | |
577 |
|
569 | |||
578 | self.nIncohInt = None |
|
570 | self.nIncohInt = None | |
579 |
|
571 | |||
580 | self.blocksize = None |
|
572 | self.blocksize = None | |
581 |
|
573 | |||
582 | self.nFFTPoints = None |
|
574 | self.nFFTPoints = None | |
583 |
|
575 | |||
584 | self.wavelength = None |
|
576 | self.wavelength = None | |
585 |
|
577 | |||
586 | self.flagDecodeData = False #asumo q la data no esta decodificada |
|
578 | self.flagDecodeData = False #asumo q la data no esta decodificada | |
587 |
|
579 | |||
588 | self.flagDeflipData = False #asumo q la data no esta sin flip |
|
580 | self.flagDeflipData = False #asumo q la data no esta sin flip | |
589 |
|
581 | |||
590 | self.flagShiftFFT = False |
|
582 | self.flagShiftFFT = False | |
591 |
|
583 | |||
592 | self.ippFactor = 1 |
|
584 | self.ippFactor = 1 | |
593 |
|
585 | |||
594 | #self.noise = None |
|
586 | #self.noise = None | |
595 |
|
587 | |||
596 | self.beacon_heiIndexList = [] |
|
588 | self.beacon_heiIndexList = [] | |
597 |
|
589 | |||
598 | self.noise_estimation = None |
|
590 | self.noise_estimation = None | |
599 |
|
591 | |||
600 |
|
592 | |||
601 | def getNoisebyHildebrand(self, xmin_index=None, xmax_index=None, ymin_index=None, ymax_index=None): |
|
593 | def getNoisebyHildebrand(self, xmin_index=None, xmax_index=None, ymin_index=None, ymax_index=None): | |
602 | """ |
|
594 | """ | |
603 | Determino el nivel de ruido usando el metodo Hildebrand-Sekhon |
|
595 | Determino el nivel de ruido usando el metodo Hildebrand-Sekhon | |
604 |
|
596 | |||
605 | Return: |
|
597 | Return: | |
606 | noiselevel |
|
598 | noiselevel | |
607 | """ |
|
599 | """ | |
608 |
|
600 | |||
609 | noise = numpy.zeros(self.nChannels) |
|
601 | noise = numpy.zeros(self.nChannels) | |
610 |
|
602 | |||
611 | for channel in range(self.nChannels): |
|
603 | for channel in range(self.nChannels): | |
612 | daux = self.data_spc[channel,xmin_index:xmax_index,ymin_index:ymax_index] |
|
604 | daux = self.data_spc[channel,xmin_index:xmax_index,ymin_index:ymax_index] | |
613 | noise[channel] = hildebrand_sekhon(daux, self.nIncohInt) |
|
605 | noise[channel] = hildebrand_sekhon(daux, self.nIncohInt) | |
614 |
|
606 | |||
615 | return noise |
|
607 | return noise | |
616 |
|
608 | |||
617 | def getNoise(self, xmin_index=None, xmax_index=None, ymin_index=None, ymax_index=None): |
|
609 | def getNoise(self, xmin_index=None, xmax_index=None, ymin_index=None, ymax_index=None): | |
618 |
|
610 | |||
619 | if self.noise_estimation is not None: |
|
611 | if self.noise_estimation is not None: | |
620 | return self.noise_estimation #this was estimated by getNoise Operation defined in jroproc_spectra.py |
|
612 | return self.noise_estimation #this was estimated by getNoise Operation defined in jroproc_spectra.py | |
621 | else: |
|
613 | else: | |
622 | noise = self.getNoisebyHildebrand(xmin_index, xmax_index, ymin_index, ymax_index) |
|
614 | noise = self.getNoisebyHildebrand(xmin_index, xmax_index, ymin_index, ymax_index) | |
623 | return noise |
|
615 | return noise | |
624 |
|
616 | |||
625 | def getFreqRangeTimeResponse(self, extrapoints=0): |
|
617 | def getFreqRangeTimeResponse(self, extrapoints=0): | |
626 |
|
618 | |||
627 | deltafreq = self.getFmaxTimeResponse() / (self.nFFTPoints*self.ippFactor) |
|
619 | deltafreq = self.getFmaxTimeResponse() / (self.nFFTPoints*self.ippFactor) | |
628 | freqrange = deltafreq*(numpy.arange(self.nFFTPoints+extrapoints)-self.nFFTPoints/2.) - deltafreq/2 |
|
620 | freqrange = deltafreq*(numpy.arange(self.nFFTPoints+extrapoints)-self.nFFTPoints/2.) - deltafreq/2 | |
629 |
|
621 | |||
630 | return freqrange |
|
622 | return freqrange | |
631 |
|
623 | |||
632 | def getAcfRange(self, extrapoints=0): |
|
624 | def getAcfRange(self, extrapoints=0): | |
633 |
|
625 | |||
634 | deltafreq = 10./(self.getFmax() / (self.nFFTPoints*self.ippFactor)) |
|
626 | deltafreq = 10./(self.getFmax() / (self.nFFTPoints*self.ippFactor)) | |
635 | freqrange = deltafreq*(numpy.arange(self.nFFTPoints+extrapoints)-self.nFFTPoints/2.) - deltafreq/2 |
|
627 | freqrange = deltafreq*(numpy.arange(self.nFFTPoints+extrapoints)-self.nFFTPoints/2.) - deltafreq/2 | |
636 |
|
628 | |||
637 | return freqrange |
|
629 | return freqrange | |
638 |
|
630 | |||
639 | def getFreqRange(self, extrapoints=0): |
|
631 | def getFreqRange(self, extrapoints=0): | |
640 |
|
632 | |||
641 | deltafreq = self.getFmax() / (self.nFFTPoints*self.ippFactor) |
|
633 | deltafreq = self.getFmax() / (self.nFFTPoints*self.ippFactor) | |
642 | freqrange = deltafreq*(numpy.arange(self.nFFTPoints+extrapoints)-self.nFFTPoints/2.) - deltafreq/2 |
|
634 | freqrange = deltafreq*(numpy.arange(self.nFFTPoints+extrapoints)-self.nFFTPoints/2.) - deltafreq/2 | |
643 |
|
635 | |||
644 | return freqrange |
|
636 | return freqrange | |
645 |
|
637 | |||
646 | def getVelRange(self, extrapoints=0): |
|
638 | def getVelRange(self, extrapoints=0): | |
647 |
|
639 | |||
648 | deltav = self.getVmax() / (self.nFFTPoints*self.ippFactor) |
|
640 | deltav = self.getVmax() / (self.nFFTPoints*self.ippFactor) | |
649 | velrange = deltav*(numpy.arange(self.nFFTPoints+extrapoints)-self.nFFTPoints/2.) #- deltav/2 |
|
641 | velrange = deltav*(numpy.arange(self.nFFTPoints+extrapoints)-self.nFFTPoints/2.) #- deltav/2 | |
650 |
|
642 | |||
651 | return velrange |
|
643 | return velrange | |
652 |
|
644 | |||
653 | def getNPairs(self): |
|
645 | def getNPairs(self): | |
654 |
|
646 | |||
655 | return len(self.pairsList) |
|
647 | return len(self.pairsList) | |
656 |
|
648 | |||
657 | def getPairsIndexList(self): |
|
649 | def getPairsIndexList(self): | |
658 |
|
650 | |||
659 | return range(self.nPairs) |
|
651 | return range(self.nPairs) | |
660 |
|
652 | |||
661 | def getNormFactor(self): |
|
653 | def getNormFactor(self): | |
662 |
|
654 | |||
663 | pwcode = 1 |
|
655 | pwcode = 1 | |
664 |
|
656 | |||
665 | if self.flagDecodeData: |
|
657 | if self.flagDecodeData: | |
666 | pwcode = numpy.sum(self.code[0]**2) |
|
658 | pwcode = numpy.sum(self.code[0]**2) | |
667 | #normFactor = min(self.nFFTPoints,self.nProfiles)*self.nIncohInt*self.nCohInt*pwcode*self.windowOfFilter |
|
659 | #normFactor = min(self.nFFTPoints,self.nProfiles)*self.nIncohInt*self.nCohInt*pwcode*self.windowOfFilter | |
668 | normFactor = self.nProfiles*self.nIncohInt*self.nCohInt*pwcode*self.windowOfFilter |
|
660 | normFactor = self.nProfiles*self.nIncohInt*self.nCohInt*pwcode*self.windowOfFilter | |
669 |
|
661 | |||
670 | return normFactor |
|
662 | return normFactor | |
671 |
|
663 | |||
672 | def getFlagCspc(self): |
|
664 | def getFlagCspc(self): | |
673 |
|
665 | |||
674 | if self.data_cspc is None: |
|
666 | if self.data_cspc is None: | |
675 | return True |
|
667 | return True | |
676 |
|
668 | |||
677 | return False |
|
669 | return False | |
678 |
|
670 | |||
679 | def getFlagDc(self): |
|
671 | def getFlagDc(self): | |
680 |
|
672 | |||
681 | if self.data_dc is None: |
|
673 | if self.data_dc is None: | |
682 | return True |
|
674 | return True | |
683 |
|
675 | |||
684 | return False |
|
676 | return False | |
685 |
|
677 | |||
686 | def getTimeInterval(self): |
|
678 | def getTimeInterval(self): | |
687 |
|
679 | |||
688 | timeInterval = self.ippSeconds * self.nCohInt * self.nIncohInt * self.nProfiles |
|
680 | timeInterval = self.ippSeconds * self.nCohInt * self.nIncohInt * self.nProfiles | |
689 |
|
681 | |||
690 | return timeInterval |
|
682 | return timeInterval | |
691 |
|
683 | |||
692 | def getPower(self): |
|
684 | def getPower(self): | |
693 |
|
685 | |||
694 | factor = self.normFactor |
|
686 | factor = self.normFactor | |
695 | z = self.data_spc/factor |
|
687 | z = self.data_spc/factor | |
696 | z = numpy.where(numpy.isfinite(z), z, numpy.NAN) |
|
688 | z = numpy.where(numpy.isfinite(z), z, numpy.NAN) | |
697 | avg = numpy.average(z, axis=1) |
|
689 | avg = numpy.average(z, axis=1) | |
698 |
|
690 | |||
699 | return 10*numpy.log10(avg) |
|
691 | return 10*numpy.log10(avg) | |
700 |
|
692 | |||
701 | def getCoherence(self, pairsList=None, phase=False): |
|
693 | def getCoherence(self, pairsList=None, phase=False): | |
702 |
|
694 | |||
703 | z = [] |
|
695 | z = [] | |
704 | if pairsList is None: |
|
696 | if pairsList is None: | |
705 | pairsIndexList = self.pairsIndexList |
|
697 | pairsIndexList = self.pairsIndexList | |
706 | else: |
|
698 | else: | |
707 | pairsIndexList = [] |
|
699 | pairsIndexList = [] | |
708 | for pair in pairsList: |
|
700 | for pair in pairsList: | |
709 | if pair not in self.pairsList: |
|
701 | if pair not in self.pairsList: | |
710 | raise ValueError, "Pair %s is not in dataOut.pairsList" %(pair) |
|
702 | raise ValueError, "Pair %s is not in dataOut.pairsList" %(pair) | |
711 | pairsIndexList.append(self.pairsList.index(pair)) |
|
703 | pairsIndexList.append(self.pairsList.index(pair)) | |
712 | for i in range(len(pairsIndexList)): |
|
704 | for i in range(len(pairsIndexList)): | |
713 | pair = self.pairsList[pairsIndexList[i]] |
|
705 | pair = self.pairsList[pairsIndexList[i]] | |
714 | ccf = numpy.average(self.data_cspc[pairsIndexList[i], :, :], axis=0) |
|
706 | ccf = numpy.average(self.data_cspc[pairsIndexList[i], :, :], axis=0) | |
715 | powa = numpy.average(self.data_spc[pair[0], :, :], axis=0) |
|
707 | powa = numpy.average(self.data_spc[pair[0], :, :], axis=0) | |
716 | powb = numpy.average(self.data_spc[pair[1], :, :], axis=0) |
|
708 | powb = numpy.average(self.data_spc[pair[1], :, :], axis=0) | |
717 | avgcoherenceComplex = ccf/numpy.sqrt(powa*powb) |
|
709 | avgcoherenceComplex = ccf/numpy.sqrt(powa*powb) | |
718 | if phase: |
|
710 | if phase: | |
719 | data = numpy.arctan2(avgcoherenceComplex.imag, |
|
711 | data = numpy.arctan2(avgcoherenceComplex.imag, | |
720 | avgcoherenceComplex.real)*180/numpy.pi |
|
712 | avgcoherenceComplex.real)*180/numpy.pi | |
721 | else: |
|
713 | else: | |
722 | data = numpy.abs(avgcoherenceComplex) |
|
714 | data = numpy.abs(avgcoherenceComplex) | |
723 |
|
715 | |||
724 | z.append(data) |
|
716 | z.append(data) | |
725 |
|
717 | |||
726 | return numpy.array(z) |
|
718 | return numpy.array(z) | |
727 |
|
719 | |||
728 | def setValue(self, value): |
|
720 | def setValue(self, value): | |
729 |
|
721 | |||
730 | print "This property should not be initialized" |
|
722 | print "This property should not be initialized" | |
731 |
|
723 | |||
732 | return |
|
724 | return | |
733 |
|
725 | |||
734 | nPairs = property(getNPairs, setValue, "I'm the 'nPairs' property.") |
|
726 | nPairs = property(getNPairs, setValue, "I'm the 'nPairs' property.") | |
735 | pairsIndexList = property(getPairsIndexList, setValue, "I'm the 'pairsIndexList' property.") |
|
727 | pairsIndexList = property(getPairsIndexList, setValue, "I'm the 'pairsIndexList' property.") | |
736 | normFactor = property(getNormFactor, setValue, "I'm the 'getNormFactor' property.") |
|
728 | normFactor = property(getNormFactor, setValue, "I'm the 'getNormFactor' property.") | |
737 | flag_cspc = property(getFlagCspc, setValue) |
|
729 | flag_cspc = property(getFlagCspc, setValue) | |
738 | flag_dc = property(getFlagDc, setValue) |
|
730 | flag_dc = property(getFlagDc, setValue) | |
739 | noise = property(getNoise, setValue, "I'm the 'nHeights' property.") |
|
731 | noise = property(getNoise, setValue, "I'm the 'nHeights' property.") | |
740 | timeInterval = property(getTimeInterval, setValue, "I'm the 'timeInterval' property") |
|
732 | timeInterval = property(getTimeInterval, setValue, "I'm the 'timeInterval' property") | |
741 |
|
733 | |||
742 | class SpectraHeis(Spectra): |
|
734 | class SpectraHeis(Spectra): | |
743 |
|
735 | |||
744 | data_spc = None |
|
736 | data_spc = None | |
745 |
|
737 | |||
746 | data_cspc = None |
|
738 | data_cspc = None | |
747 |
|
739 | |||
748 | data_dc = None |
|
740 | data_dc = None | |
749 |
|
741 | |||
750 | nFFTPoints = None |
|
742 | nFFTPoints = None | |
751 |
|
743 | |||
752 | # nPairs = None |
|
744 | # nPairs = None | |
753 |
|
745 | |||
754 | pairsList = None |
|
746 | pairsList = None | |
755 |
|
747 | |||
756 | nCohInt = None |
|
748 | nCohInt = None | |
757 |
|
749 | |||
758 | nIncohInt = None |
|
750 | nIncohInt = None | |
759 |
|
751 | |||
760 | def __init__(self): |
|
752 | def __init__(self): | |
761 |
|
753 | |||
762 | self.radarControllerHeaderObj = RadarControllerHeader() |
|
754 | self.radarControllerHeaderObj = RadarControllerHeader() | |
763 |
|
755 | |||
764 | self.systemHeaderObj = SystemHeader() |
|
756 | self.systemHeaderObj = SystemHeader() | |
765 |
|
757 | |||
766 | self.type = "SpectraHeis" |
|
758 | self.type = "SpectraHeis" | |
767 |
|
759 | |||
768 | # self.dtype = None |
|
760 | # self.dtype = None | |
769 |
|
761 | |||
770 | # self.nChannels = 0 |
|
762 | # self.nChannels = 0 | |
771 |
|
763 | |||
772 | # self.nHeights = 0 |
|
764 | # self.nHeights = 0 | |
773 |
|
765 | |||
774 | self.nProfiles = None |
|
766 | self.nProfiles = None | |
775 |
|
767 | |||
776 | self.heightList = None |
|
768 | self.heightList = None | |
777 |
|
769 | |||
778 | self.channelList = None |
|
770 | self.channelList = None | |
779 |
|
771 | |||
780 | # self.channelIndexList = None |
|
772 | # self.channelIndexList = None | |
781 |
|
773 | |||
782 | self.flagNoData = True |
|
774 | self.flagNoData = True | |
783 |
|
775 | |||
784 | self.flagDiscontinuousBlock = False |
|
776 | self.flagDiscontinuousBlock = False | |
785 |
|
777 | |||
786 | # self.nPairs = 0 |
|
778 | # self.nPairs = 0 | |
787 |
|
779 | |||
788 | self.utctime = None |
|
780 | self.utctime = None | |
789 |
|
781 | |||
790 | self.blocksize = None |
|
782 | self.blocksize = None | |
791 |
|
783 | |||
792 | self.profileIndex = 0 |
|
784 | self.profileIndex = 0 | |
793 |
|
785 | |||
794 | self.nCohInt = 1 |
|
786 | self.nCohInt = 1 | |
795 |
|
787 | |||
796 | self.nIncohInt = 1 |
|
788 | self.nIncohInt = 1 | |
797 |
|
789 | |||
798 | def getNormFactor(self): |
|
790 | def getNormFactor(self): | |
799 | pwcode = 1 |
|
791 | pwcode = 1 | |
800 | if self.flagDecodeData: |
|
792 | if self.flagDecodeData: | |
801 | pwcode = numpy.sum(self.code[0]**2) |
|
793 | pwcode = numpy.sum(self.code[0]**2) | |
802 |
|
794 | |||
803 | normFactor = self.nIncohInt*self.nCohInt*pwcode |
|
795 | normFactor = self.nIncohInt*self.nCohInt*pwcode | |
804 |
|
796 | |||
805 | return normFactor |
|
797 | return normFactor | |
806 |
|
798 | |||
807 | def getTimeInterval(self): |
|
799 | def getTimeInterval(self): | |
808 |
|
800 | |||
809 | timeInterval = self.ippSeconds * self.nCohInt * self.nIncohInt |
|
801 | timeInterval = self.ippSeconds * self.nCohInt * self.nIncohInt | |
810 |
|
802 | |||
811 | return timeInterval |
|
803 | return timeInterval | |
812 |
|
804 | |||
813 | normFactor = property(getNormFactor, "I'm the 'getNormFactor' property.") |
|
805 | normFactor = property(getNormFactor, "I'm the 'getNormFactor' property.") | |
814 | timeInterval = property(getTimeInterval, "I'm the 'timeInterval' property") |
|
806 | timeInterval = property(getTimeInterval, "I'm the 'timeInterval' property") | |
815 |
|
807 | |||
816 | class Fits(JROData): |
|
808 | class Fits(JROData): | |
817 |
|
809 | |||
818 | heightList = None |
|
810 | heightList = None | |
819 |
|
811 | |||
820 | channelList = None |
|
812 | channelList = None | |
821 |
|
813 | |||
822 | flagNoData = True |
|
814 | flagNoData = True | |
823 |
|
815 | |||
824 | flagDiscontinuousBlock = False |
|
816 | flagDiscontinuousBlock = False | |
825 |
|
817 | |||
826 | useLocalTime = False |
|
818 | useLocalTime = False | |
827 |
|
819 | |||
828 | utctime = None |
|
820 | utctime = None | |
829 |
|
821 | |||
830 | timeZone = None |
|
822 | timeZone = None | |
831 |
|
823 | |||
832 | # ippSeconds = None |
|
824 | # ippSeconds = None | |
833 |
|
825 | |||
834 | # timeInterval = None |
|
826 | # timeInterval = None | |
835 |
|
827 | |||
836 | nCohInt = None |
|
828 | nCohInt = None | |
837 |
|
829 | |||
838 | nIncohInt = None |
|
830 | nIncohInt = None | |
839 |
|
831 | |||
840 | noise = None |
|
832 | noise = None | |
841 |
|
833 | |||
842 | windowOfFilter = 1 |
|
834 | windowOfFilter = 1 | |
843 |
|
835 | |||
844 | #Speed of ligth |
|
836 | #Speed of ligth | |
845 | C = 3e8 |
|
837 | C = 3e8 | |
846 |
|
838 | |||
847 | frequency = 49.92e6 |
|
839 | frequency = 49.92e6 | |
848 |
|
840 | |||
849 | realtime = False |
|
841 | realtime = False | |
850 |
|
842 | |||
851 |
|
843 | |||
852 | def __init__(self): |
|
844 | def __init__(self): | |
853 |
|
845 | |||
854 | self.type = "Fits" |
|
846 | self.type = "Fits" | |
855 |
|
847 | |||
856 | self.nProfiles = None |
|
848 | self.nProfiles = None | |
857 |
|
849 | |||
858 | self.heightList = None |
|
850 | self.heightList = None | |
859 |
|
851 | |||
860 | self.channelList = None |
|
852 | self.channelList = None | |
861 |
|
853 | |||
862 | # self.channelIndexList = None |
|
854 | # self.channelIndexList = None | |
863 |
|
855 | |||
864 | self.flagNoData = True |
|
856 | self.flagNoData = True | |
865 |
|
857 | |||
866 | self.utctime = None |
|
858 | self.utctime = None | |
867 |
|
859 | |||
868 | self.nCohInt = 1 |
|
860 | self.nCohInt = 1 | |
869 |
|
861 | |||
870 | self.nIncohInt = 1 |
|
862 | self.nIncohInt = 1 | |
871 |
|
863 | |||
872 | self.useLocalTime = True |
|
864 | self.useLocalTime = True | |
873 |
|
865 | |||
874 | self.profileIndex = 0 |
|
866 | self.profileIndex = 0 | |
875 |
|
867 | |||
876 | # self.utctime = None |
|
868 | # self.utctime = None | |
877 | # self.timeZone = None |
|
869 | # self.timeZone = None | |
878 | # self.ltctime = None |
|
870 | # self.ltctime = None | |
879 | # self.timeInterval = None |
|
871 | # self.timeInterval = None | |
880 | # self.header = None |
|
872 | # self.header = None | |
881 | # self.data_header = None |
|
873 | # self.data_header = None | |
882 | # self.data = None |
|
874 | # self.data = None | |
883 | # self.datatime = None |
|
875 | # self.datatime = None | |
884 | # self.flagNoData = False |
|
876 | # self.flagNoData = False | |
885 | # self.expName = '' |
|
877 | # self.expName = '' | |
886 | # self.nChannels = None |
|
878 | # self.nChannels = None | |
887 | # self.nSamples = None |
|
879 | # self.nSamples = None | |
888 | # self.dataBlocksPerFile = None |
|
880 | # self.dataBlocksPerFile = None | |
889 | # self.comments = '' |
|
881 | # self.comments = '' | |
890 | # |
|
882 | # | |
891 |
|
883 | |||
892 |
|
884 | |||
893 | def getltctime(self): |
|
885 | def getltctime(self): | |
894 |
|
886 | |||
895 | if self.useLocalTime: |
|
887 | if self.useLocalTime: | |
896 | return self.utctime - self.timeZone*60 |
|
888 | return self.utctime - self.timeZone*60 | |
897 |
|
889 | |||
898 | return self.utctime |
|
890 | return self.utctime | |
899 |
|
891 | |||
900 | def getDatatime(self): |
|
892 | def getDatatime(self): | |
901 |
|
893 | |||
902 | datatime = datetime.datetime.utcfromtimestamp(self.ltctime) |
|
894 | datatime = datetime.datetime.utcfromtimestamp(self.ltctime) | |
903 | return datatime |
|
895 | return datatime | |
904 |
|
896 | |||
905 | def getTimeRange(self): |
|
897 | def getTimeRange(self): | |
906 |
|
898 | |||
907 | datatime = [] |
|
899 | datatime = [] | |
908 |
|
900 | |||
909 | datatime.append(self.ltctime) |
|
901 | datatime.append(self.ltctime) | |
910 | datatime.append(self.ltctime + self.timeInterval) |
|
902 | datatime.append(self.ltctime + self.timeInterval) | |
911 |
|
903 | |||
912 | datatime = numpy.array(datatime) |
|
904 | datatime = numpy.array(datatime) | |
913 |
|
905 | |||
914 | return datatime |
|
906 | return datatime | |
915 |
|
907 | |||
916 | def getHeiRange(self): |
|
908 | def getHeiRange(self): | |
917 |
|
909 | |||
918 | heis = self.heightList |
|
910 | heis = self.heightList | |
919 |
|
911 | |||
920 | return heis |
|
912 | return heis | |
921 |
|
913 | |||
922 | def getNHeights(self): |
|
914 | def getNHeights(self): | |
923 |
|
915 | |||
924 | return len(self.heightList) |
|
916 | return len(self.heightList) | |
925 |
|
917 | |||
926 | def getNChannels(self): |
|
918 | def getNChannels(self): | |
927 |
|
919 | |||
928 | return len(self.channelList) |
|
920 | return len(self.channelList) | |
929 |
|
921 | |||
930 | def getChannelIndexList(self): |
|
922 | def getChannelIndexList(self): | |
931 |
|
923 | |||
932 | return range(self.nChannels) |
|
924 | return range(self.nChannels) | |
933 |
|
925 | |||
934 | def getNoise(self, type = 1): |
|
926 | def getNoise(self, type = 1): | |
935 |
|
927 | |||
936 | #noise = numpy.zeros(self.nChannels) |
|
928 | #noise = numpy.zeros(self.nChannels) | |
937 |
|
929 | |||
938 | if type == 1: |
|
930 | if type == 1: | |
939 | noise = self.getNoisebyHildebrand() |
|
931 | noise = self.getNoisebyHildebrand() | |
940 |
|
932 | |||
941 | if type == 2: |
|
933 | if type == 2: | |
942 | noise = self.getNoisebySort() |
|
934 | noise = self.getNoisebySort() | |
943 |
|
935 | |||
944 | if type == 3: |
|
936 | if type == 3: | |
945 | noise = self.getNoisebyWindow() |
|
937 | noise = self.getNoisebyWindow() | |
946 |
|
938 | |||
947 | return noise |
|
939 | return noise | |
948 |
|
940 | |||
949 | def getTimeInterval(self): |
|
941 | def getTimeInterval(self): | |
950 |
|
942 | |||
951 | timeInterval = self.ippSeconds * self.nCohInt * self.nIncohInt |
|
943 | timeInterval = self.ippSeconds * self.nCohInt * self.nIncohInt | |
952 |
|
944 | |||
953 | return timeInterval |
|
945 | return timeInterval | |
954 |
|
946 | |||
955 | datatime = property(getDatatime, "I'm the 'datatime' property") |
|
947 | datatime = property(getDatatime, "I'm the 'datatime' property") | |
956 | nHeights = property(getNHeights, "I'm the 'nHeights' property.") |
|
948 | nHeights = property(getNHeights, "I'm the 'nHeights' property.") | |
957 | nChannels = property(getNChannels, "I'm the 'nChannel' property.") |
|
949 | nChannels = property(getNChannels, "I'm the 'nChannel' property.") | |
958 | channelIndexList = property(getChannelIndexList, "I'm the 'channelIndexList' property.") |
|
950 | channelIndexList = property(getChannelIndexList, "I'm the 'channelIndexList' property.") | |
959 | noise = property(getNoise, "I'm the 'nHeights' property.") |
|
951 | noise = property(getNoise, "I'm the 'nHeights' property.") | |
960 |
|
952 | |||
961 | ltctime = property(getltctime, "I'm the 'ltctime' property") |
|
953 | ltctime = property(getltctime, "I'm the 'ltctime' property") | |
962 | timeInterval = property(getTimeInterval, "I'm the 'timeInterval' property") |
|
954 | timeInterval = property(getTimeInterval, "I'm the 'timeInterval' property") | |
963 |
|
955 | |||
964 |
|
956 | |||
965 | class Correlation(JROData): |
|
957 | class Correlation(JROData): | |
966 |
|
958 | |||
967 | noise = None |
|
959 | noise = None | |
968 |
|
960 | |||
969 | SNR = None |
|
961 | SNR = None | |
970 |
|
962 | |||
971 | #-------------------------------------------------- |
|
963 | #-------------------------------------------------- | |
972 |
|
964 | |||
973 | mode = None |
|
965 | mode = None | |
974 |
|
966 | |||
975 | split = False |
|
967 | split = False | |
976 |
|
968 | |||
977 | data_cf = None |
|
969 | data_cf = None | |
978 |
|
970 | |||
979 | lags = None |
|
971 | lags = None | |
980 |
|
972 | |||
981 | lagRange = None |
|
973 | lagRange = None | |
982 |
|
974 | |||
983 | pairsList = None |
|
975 | pairsList = None | |
984 |
|
976 | |||
985 | normFactor = None |
|
977 | normFactor = None | |
986 |
|
978 | |||
987 | #-------------------------------------------------- |
|
979 | #-------------------------------------------------- | |
988 |
|
980 | |||
989 | # calculateVelocity = None |
|
981 | # calculateVelocity = None | |
990 |
|
982 | |||
991 | nLags = None |
|
983 | nLags = None | |
992 |
|
984 | |||
993 | nPairs = None |
|
985 | nPairs = None | |
994 |
|
986 | |||
995 | nAvg = None |
|
987 | nAvg = None | |
996 |
|
988 | |||
997 |
|
989 | |||
998 | def __init__(self): |
|
990 | def __init__(self): | |
999 | ''' |
|
991 | ''' | |
1000 | Constructor |
|
992 | Constructor | |
1001 | ''' |
|
993 | ''' | |
1002 | self.radarControllerHeaderObj = RadarControllerHeader() |
|
994 | self.radarControllerHeaderObj = RadarControllerHeader() | |
1003 |
|
995 | |||
1004 | self.systemHeaderObj = SystemHeader() |
|
996 | self.systemHeaderObj = SystemHeader() | |
1005 |
|
997 | |||
1006 | self.type = "Correlation" |
|
998 | self.type = "Correlation" | |
1007 |
|
999 | |||
1008 | self.data = None |
|
1000 | self.data = None | |
1009 |
|
1001 | |||
1010 | self.dtype = None |
|
1002 | self.dtype = None | |
1011 |
|
1003 | |||
1012 | self.nProfiles = None |
|
1004 | self.nProfiles = None | |
1013 |
|
1005 | |||
1014 | self.heightList = None |
|
1006 | self.heightList = None | |
1015 |
|
1007 | |||
1016 | self.channelList = None |
|
1008 | self.channelList = None | |
1017 |
|
1009 | |||
1018 | self.flagNoData = True |
|
1010 | self.flagNoData = True | |
1019 |
|
1011 | |||
1020 | self.flagDiscontinuousBlock = False |
|
1012 | self.flagDiscontinuousBlock = False | |
1021 |
|
1013 | |||
1022 | self.utctime = None |
|
1014 | self.utctime = None | |
1023 |
|
1015 | |||
1024 | self.timeZone = None |
|
1016 | self.timeZone = None | |
1025 |
|
1017 | |||
1026 | self.dstFlag = None |
|
1018 | self.dstFlag = None | |
1027 |
|
1019 | |||
1028 | self.errorCount = None |
|
1020 | self.errorCount = None | |
1029 |
|
1021 | |||
1030 | self.blocksize = None |
|
1022 | self.blocksize = None | |
1031 |
|
1023 | |||
1032 | self.flagDecodeData = False #asumo q la data no esta decodificada |
|
1024 | self.flagDecodeData = False #asumo q la data no esta decodificada | |
1033 |
|
1025 | |||
1034 | self.flagDeflipData = False #asumo q la data no esta sin flip |
|
1026 | self.flagDeflipData = False #asumo q la data no esta sin flip | |
1035 |
|
1027 | |||
1036 | self.pairsList = None |
|
1028 | self.pairsList = None | |
1037 |
|
1029 | |||
1038 | self.nPoints = None |
|
1030 | self.nPoints = None | |
1039 |
|
1031 | |||
1040 | def getPairsList(self): |
|
1032 | def getPairsList(self): | |
1041 |
|
1033 | |||
1042 | return self.pairsList |
|
1034 | return self.pairsList | |
1043 |
|
1035 | |||
1044 | def getNoise(self, mode = 2): |
|
1036 | def getNoise(self, mode = 2): | |
1045 |
|
1037 | |||
1046 | indR = numpy.where(self.lagR == 0)[0][0] |
|
1038 | indR = numpy.where(self.lagR == 0)[0][0] | |
1047 | indT = numpy.where(self.lagT == 0)[0][0] |
|
1039 | indT = numpy.where(self.lagT == 0)[0][0] | |
1048 |
|
1040 | |||
1049 | jspectra0 = self.data_corr[:,:,indR,:] |
|
1041 | jspectra0 = self.data_corr[:,:,indR,:] | |
1050 | jspectra = copy.copy(jspectra0) |
|
1042 | jspectra = copy.copy(jspectra0) | |
1051 |
|
1043 | |||
1052 | num_chan = jspectra.shape[0] |
|
1044 | num_chan = jspectra.shape[0] | |
1053 | num_hei = jspectra.shape[2] |
|
1045 | num_hei = jspectra.shape[2] | |
1054 |
|
1046 | |||
1055 | freq_dc = jspectra.shape[1]/2 |
|
1047 | freq_dc = jspectra.shape[1]/2 | |
1056 | ind_vel = numpy.array([-2,-1,1,2]) + freq_dc |
|
1048 | ind_vel = numpy.array([-2,-1,1,2]) + freq_dc | |
1057 |
|
1049 | |||
1058 | if ind_vel[0]<0: |
|
1050 | if ind_vel[0]<0: | |
1059 | ind_vel[range(0,1)] = ind_vel[range(0,1)] + self.num_prof |
|
1051 | ind_vel[range(0,1)] = ind_vel[range(0,1)] + self.num_prof | |
1060 |
|
1052 | |||
1061 | if mode == 1: |
|
1053 | if mode == 1: | |
1062 | jspectra[:,freq_dc,:] = (jspectra[:,ind_vel[1],:] + jspectra[:,ind_vel[2],:])/2 #CORRECCION |
|
1054 | jspectra[:,freq_dc,:] = (jspectra[:,ind_vel[1],:] + jspectra[:,ind_vel[2],:])/2 #CORRECCION | |
1063 |
|
1055 | |||
1064 | if mode == 2: |
|
1056 | if mode == 2: | |
1065 |
|
1057 | |||
1066 | vel = numpy.array([-2,-1,1,2]) |
|
1058 | vel = numpy.array([-2,-1,1,2]) | |
1067 | xx = numpy.zeros([4,4]) |
|
1059 | xx = numpy.zeros([4,4]) | |
1068 |
|
1060 | |||
1069 | for fil in range(4): |
|
1061 | for fil in range(4): | |
1070 | xx[fil,:] = vel[fil]**numpy.asarray(range(4)) |
|
1062 | xx[fil,:] = vel[fil]**numpy.asarray(range(4)) | |
1071 |
|
1063 | |||
1072 | xx_inv = numpy.linalg.inv(xx) |
|
1064 | xx_inv = numpy.linalg.inv(xx) | |
1073 | xx_aux = xx_inv[0,:] |
|
1065 | xx_aux = xx_inv[0,:] | |
1074 |
|
1066 | |||
1075 | for ich in range(num_chan): |
|
1067 | for ich in range(num_chan): | |
1076 | yy = jspectra[ich,ind_vel,:] |
|
1068 | yy = jspectra[ich,ind_vel,:] | |
1077 | jspectra[ich,freq_dc,:] = numpy.dot(xx_aux,yy) |
|
1069 | jspectra[ich,freq_dc,:] = numpy.dot(xx_aux,yy) | |
1078 |
|
1070 | |||
1079 | junkid = jspectra[ich,freq_dc,:]<=0 |
|
1071 | junkid = jspectra[ich,freq_dc,:]<=0 | |
1080 | cjunkid = sum(junkid) |
|
1072 | cjunkid = sum(junkid) | |
1081 |
|
1073 | |||
1082 | if cjunkid.any(): |
|
1074 | if cjunkid.any(): | |
1083 | jspectra[ich,freq_dc,junkid.nonzero()] = (jspectra[ich,ind_vel[1],junkid] + jspectra[ich,ind_vel[2],junkid])/2 |
|
1075 | jspectra[ich,freq_dc,junkid.nonzero()] = (jspectra[ich,ind_vel[1],junkid] + jspectra[ich,ind_vel[2],junkid])/2 | |
1084 |
|
1076 | |||
1085 | noise = jspectra0[:,freq_dc,:] - jspectra[:,freq_dc,:] |
|
1077 | noise = jspectra0[:,freq_dc,:] - jspectra[:,freq_dc,:] | |
1086 |
|
1078 | |||
1087 | return noise |
|
1079 | return noise | |
1088 |
|
1080 | |||
1089 | def getTimeInterval(self): |
|
1081 | def getTimeInterval(self): | |
1090 |
|
1082 | |||
1091 | timeInterval = self.ippSeconds * self.nCohInt * self.nProfiles |
|
1083 | timeInterval = self.ippSeconds * self.nCohInt * self.nProfiles | |
1092 |
|
1084 | |||
1093 | return timeInterval |
|
1085 | return timeInterval | |
1094 |
|
1086 | |||
1095 | def splitFunctions(self): |
|
1087 | def splitFunctions(self): | |
1096 |
|
1088 | |||
1097 | pairsList = self.pairsList |
|
1089 | pairsList = self.pairsList | |
1098 | ccf_pairs = [] |
|
1090 | ccf_pairs = [] | |
1099 | acf_pairs = [] |
|
1091 | acf_pairs = [] | |
1100 | ccf_ind = [] |
|
1092 | ccf_ind = [] | |
1101 | acf_ind = [] |
|
1093 | acf_ind = [] | |
1102 | for l in range(len(pairsList)): |
|
1094 | for l in range(len(pairsList)): | |
1103 | chan0 = pairsList[l][0] |
|
1095 | chan0 = pairsList[l][0] | |
1104 | chan1 = pairsList[l][1] |
|
1096 | chan1 = pairsList[l][1] | |
1105 |
|
1097 | |||
1106 | #Obteniendo pares de Autocorrelacion |
|
1098 | #Obteniendo pares de Autocorrelacion | |
1107 | if chan0 == chan1: |
|
1099 | if chan0 == chan1: | |
1108 | acf_pairs.append(chan0) |
|
1100 | acf_pairs.append(chan0) | |
1109 | acf_ind.append(l) |
|
1101 | acf_ind.append(l) | |
1110 | else: |
|
1102 | else: | |
1111 | ccf_pairs.append(pairsList[l]) |
|
1103 | ccf_pairs.append(pairsList[l]) | |
1112 | ccf_ind.append(l) |
|
1104 | ccf_ind.append(l) | |
1113 |
|
1105 | |||
1114 | data_acf = self.data_cf[acf_ind] |
|
1106 | data_acf = self.data_cf[acf_ind] | |
1115 | data_ccf = self.data_cf[ccf_ind] |
|
1107 | data_ccf = self.data_cf[ccf_ind] | |
1116 |
|
1108 | |||
1117 | return acf_ind, ccf_ind, acf_pairs, ccf_pairs, data_acf, data_ccf |
|
1109 | return acf_ind, ccf_ind, acf_pairs, ccf_pairs, data_acf, data_ccf | |
1118 |
|
1110 | |||
1119 | def getNormFactor(self): |
|
1111 | def getNormFactor(self): | |
1120 | acf_ind, ccf_ind, acf_pairs, ccf_pairs, data_acf, data_ccf = self.splitFunctions() |
|
1112 | acf_ind, ccf_ind, acf_pairs, ccf_pairs, data_acf, data_ccf = self.splitFunctions() | |
1121 | acf_pairs = numpy.array(acf_pairs) |
|
1113 | acf_pairs = numpy.array(acf_pairs) | |
1122 | normFactor = numpy.zeros((self.nPairs,self.nHeights)) |
|
1114 | normFactor = numpy.zeros((self.nPairs,self.nHeights)) | |
1123 |
|
1115 | |||
1124 | for p in range(self.nPairs): |
|
1116 | for p in range(self.nPairs): | |
1125 | pair = self.pairsList[p] |
|
1117 | pair = self.pairsList[p] | |
1126 |
|
1118 | |||
1127 | ch0 = pair[0] |
|
1119 | ch0 = pair[0] | |
1128 | ch1 = pair[1] |
|
1120 | ch1 = pair[1] | |
1129 |
|
1121 | |||
1130 | ch0_max = numpy.max(data_acf[acf_pairs==ch0,:,:], axis=1) |
|
1122 | ch0_max = numpy.max(data_acf[acf_pairs==ch0,:,:], axis=1) | |
1131 | ch1_max = numpy.max(data_acf[acf_pairs==ch1,:,:], axis=1) |
|
1123 | ch1_max = numpy.max(data_acf[acf_pairs==ch1,:,:], axis=1) | |
1132 | normFactor[p,:] = numpy.sqrt(ch0_max*ch1_max) |
|
1124 | normFactor[p,:] = numpy.sqrt(ch0_max*ch1_max) | |
1133 |
|
1125 | |||
1134 | return normFactor |
|
1126 | return normFactor | |
1135 |
|
1127 | |||
1136 | timeInterval = property(getTimeInterval, "I'm the 'timeInterval' property") |
|
1128 | timeInterval = property(getTimeInterval, "I'm the 'timeInterval' property") | |
1137 | normFactor = property(getNormFactor, "I'm the 'normFactor property'") |
|
1129 | normFactor = property(getNormFactor, "I'm the 'normFactor property'") | |
1138 |
|
1130 | |||
1139 | class Parameters(Spectra): |
|
1131 | class Parameters(Spectra): | |
1140 |
|
1132 | |||
1141 | experimentInfo = None #Information about the experiment |
|
1133 | experimentInfo = None #Information about the experiment | |
1142 |
|
1134 | |||
1143 | #Information from previous data |
|
1135 | #Information from previous data | |
1144 |
|
1136 | |||
1145 | inputUnit = None #Type of data to be processed |
|
1137 | inputUnit = None #Type of data to be processed | |
1146 |
|
1138 | |||
1147 | operation = None #Type of operation to parametrize |
|
1139 | operation = None #Type of operation to parametrize | |
1148 |
|
1140 | |||
1149 | #normFactor = None #Normalization Factor |
|
1141 | #normFactor = None #Normalization Factor | |
1150 |
|
1142 | |||
1151 | groupList = None #List of Pairs, Groups, etc |
|
1143 | groupList = None #List of Pairs, Groups, etc | |
1152 |
|
1144 | |||
1153 | #Parameters |
|
1145 | #Parameters | |
1154 |
|
1146 | |||
1155 | data_param = None #Parameters obtained |
|
1147 | data_param = None #Parameters obtained | |
1156 |
|
1148 | |||
1157 | data_pre = None #Data Pre Parametrization |
|
1149 | data_pre = None #Data Pre Parametrization | |
1158 |
|
1150 | |||
1159 | data_SNR = None #Signal to Noise Ratio |
|
1151 | data_SNR = None #Signal to Noise Ratio | |
1160 |
|
1152 | |||
1161 | # heightRange = None #Heights |
|
1153 | # heightRange = None #Heights | |
1162 |
|
1154 | |||
1163 | abscissaList = None #Abscissa, can be velocities, lags or time |
|
1155 | abscissaList = None #Abscissa, can be velocities, lags or time | |
1164 |
|
1156 | |||
1165 | # noise = None #Noise Potency |
|
1157 | # noise = None #Noise Potency | |
1166 |
|
1158 | |||
1167 | utctimeInit = None #Initial UTC time |
|
1159 | utctimeInit = None #Initial UTC time | |
1168 |
|
1160 | |||
1169 | paramInterval = None #Time interval to calculate Parameters in seconds |
|
1161 | paramInterval = None #Time interval to calculate Parameters in seconds | |
1170 |
|
1162 | |||
1171 | useLocalTime = True |
|
1163 | useLocalTime = True | |
1172 |
|
1164 | |||
1173 | #Fitting |
|
1165 | #Fitting | |
1174 |
|
1166 | |||
1175 | data_error = None #Error of the estimation |
|
1167 | data_error = None #Error of the estimation | |
1176 |
|
1168 | |||
1177 | constants = None |
|
1169 | constants = None | |
1178 |
|
1170 | |||
1179 | library = None |
|
1171 | library = None | |
1180 |
|
1172 | |||
1181 | #Output signal |
|
1173 | #Output signal | |
1182 |
|
1174 | |||
1183 | outputInterval = None #Time interval to calculate output signal in seconds |
|
1175 | outputInterval = None #Time interval to calculate output signal in seconds | |
1184 |
|
1176 | |||
1185 | data_output = None #Out signal |
|
1177 | data_output = None #Out signal | |
1186 |
|
1178 | |||
1187 | nAvg = None |
|
1179 | nAvg = None | |
1188 |
|
1180 | |||
1189 | noise_estimation = None |
|
1181 | noise_estimation = None | |
1190 |
|
1182 | |||
1191 |
|
1183 | |||
1192 | def __init__(self): |
|
1184 | def __init__(self): | |
1193 | ''' |
|
1185 | ''' | |
1194 | Constructor |
|
1186 | Constructor | |
1195 | ''' |
|
1187 | ''' | |
1196 | self.radarControllerHeaderObj = RadarControllerHeader() |
|
1188 | self.radarControllerHeaderObj = RadarControllerHeader() | |
1197 |
|
1189 | |||
1198 | self.systemHeaderObj = SystemHeader() |
|
1190 | self.systemHeaderObj = SystemHeader() | |
1199 |
|
1191 | |||
1200 | self.type = "Parameters" |
|
1192 | self.type = "Parameters" | |
1201 |
|
1193 | |||
1202 | def getTimeRange1(self, interval): |
|
1194 | def getTimeRange1(self, interval): | |
1203 |
|
1195 | |||
1204 | datatime = [] |
|
1196 | datatime = [] | |
1205 |
|
1197 | |||
1206 | if self.useLocalTime: |
|
1198 | if self.useLocalTime: | |
1207 | time1 = self.utctimeInit - self.timeZone*60 |
|
1199 | time1 = self.utctimeInit - self.timeZone*60 | |
1208 | else: |
|
1200 | else: | |
1209 | time1 = self.utctimeInit |
|
1201 | time1 = self.utctimeInit | |
1210 |
|
1202 | |||
1211 | datatime.append(time1) |
|
1203 | datatime.append(time1) | |
1212 | datatime.append(time1 + interval) |
|
1204 | datatime.append(time1 + interval) | |
1213 | datatime = numpy.array(datatime) |
|
1205 | datatime = numpy.array(datatime) | |
1214 |
|
1206 | |||
1215 | return datatime |
|
1207 | return datatime | |
1216 |
|
1208 | |||
1217 | def getTimeInterval(self): |
|
1209 | def getTimeInterval(self): | |
1218 |
|
1210 | |||
1219 | if hasattr(self, 'timeInterval1'): |
|
1211 | if hasattr(self, 'timeInterval1'): | |
1220 | return self.timeInterval1 |
|
1212 | return self.timeInterval1 | |
1221 | else: |
|
1213 | else: | |
1222 | return self.paramInterval |
|
1214 | return self.paramInterval | |
1223 |
|
1215 | |||
1224 | def getNoise(self): |
|
1216 | def getNoise(self): | |
1225 |
|
1217 | |||
1226 | return self.spc_noise |
|
1218 | return self.spc_noise | |
1227 |
|
1219 | |||
1228 | timeInterval = property(getTimeInterval) |
|
1220 | timeInterval = property(getTimeInterval) |
@@ -1,464 +1,502 | |||||
1 | ''' |
|
1 | ''' | |
2 | @author: Juan C. Espinoza |
|
2 | @author: Juan C. Espinoza | |
3 | ''' |
|
3 | ''' | |
4 |
|
4 | |||
5 | import time |
|
5 | import time | |
6 | import json |
|
6 | import json | |
7 | import numpy |
|
7 | import numpy | |
8 | import paho.mqtt.client as mqtt |
|
8 | import paho.mqtt.client as mqtt | |
9 | import zmq |
|
9 | import zmq | |
10 | from profilehooks import profile |
|
10 | from profilehooks import profile | |
11 | import datetime |
|
11 | import datetime | |
12 | from zmq.utils.monitor import recv_monitor_message |
|
12 | from zmq.utils.monitor import recv_monitor_message | |
13 | from functools import wraps |
|
13 | from functools import wraps | |
14 | from threading import Thread |
|
14 | from threading import Thread | |
15 | from multiprocessing import Process |
|
15 | from multiprocessing import Process | |
16 |
|
16 | |||
17 | from schainpy.model.proc.jroproc_base import Operation, ProcessingUnit |
|
17 | from schainpy.model.proc.jroproc_base import Operation, ProcessingUnit | |
|
18 | from schainpy.model.data.jrodata import JROData | |||
18 |
|
19 | |||
19 | MAXNUMX = 100 |
|
20 | MAXNUMX = 100 | |
20 | MAXNUMY = 100 |
|
21 | MAXNUMY = 100 | |
21 |
|
22 | |||
22 | class PrettyFloat(float): |
|
23 | class PrettyFloat(float): | |
23 | def __repr__(self): |
|
24 | def __repr__(self): | |
24 | return '%.2f' % self |
|
25 | return '%.2f' % self | |
25 |
|
26 | |||
26 | def roundFloats(obj): |
|
27 | def roundFloats(obj): | |
27 | if isinstance(obj, list): |
|
28 | if isinstance(obj, list): | |
28 | return map(roundFloats, obj) |
|
29 | return map(roundFloats, obj) | |
29 | elif isinstance(obj, float): |
|
30 | elif isinstance(obj, float): | |
30 | return round(obj, 2) |
|
31 | return round(obj, 2) | |
31 |
|
32 | |||
32 | def decimate(z, MAXNUMY): |
|
33 | def decimate(z, MAXNUMY): | |
33 | # dx = int(len(self.x)/self.__MAXNUMX) + 1 |
|
34 | # dx = int(len(self.x)/self.__MAXNUMX) + 1 | |
34 |
|
35 | |||
35 | dy = int(len(z[0])/MAXNUMY) + 1 |
|
36 | dy = int(len(z[0])/MAXNUMY) + 1 | |
36 |
|
37 | |||
37 | return z[::, ::dy] |
|
38 | return z[::, ::dy] | |
38 |
|
39 | |||
39 | class throttle(object): |
|
40 | class throttle(object): | |
40 | """Decorator that prevents a function from being called more than once every |
|
41 | """Decorator that prevents a function from being called more than once every | |
41 | time period. |
|
42 | time period. | |
42 | To create a function that cannot be called more than once a minute, but |
|
43 | To create a function that cannot be called more than once a minute, but | |
43 | will sleep until it can be called: |
|
44 | will sleep until it can be called: | |
44 | @throttle(minutes=1) |
|
45 | @throttle(minutes=1) | |
45 | def foo(): |
|
46 | def foo(): | |
46 | pass |
|
47 | pass | |
47 |
|
48 | |||
48 | for i in range(10): |
|
49 | for i in range(10): | |
49 | foo() |
|
50 | foo() | |
50 | print "This function has run %s times." % i |
|
51 | print "This function has run %s times." % i | |
51 | """ |
|
52 | """ | |
52 |
|
53 | |||
53 | def __init__(self, seconds=0, minutes=0, hours=0): |
|
54 | def __init__(self, seconds=0, minutes=0, hours=0): | |
54 | self.throttle_period = datetime.timedelta( |
|
55 | self.throttle_period = datetime.timedelta( | |
55 | seconds=seconds, minutes=minutes, hours=hours |
|
56 | seconds=seconds, minutes=minutes, hours=hours | |
56 | ) |
|
57 | ) | |
57 |
|
58 | |||
58 | self.time_of_last_call = datetime.datetime.min |
|
59 | self.time_of_last_call = datetime.datetime.min | |
59 |
|
60 | |||
60 | def __call__(self, fn): |
|
61 | def __call__(self, fn): | |
61 | @wraps(fn) |
|
62 | @wraps(fn) | |
62 | def wrapper(*args, **kwargs): |
|
63 | def wrapper(*args, **kwargs): | |
63 | now = datetime.datetime.now() |
|
64 | now = datetime.datetime.now() | |
64 | time_since_last_call = now - self.time_of_last_call |
|
65 | time_since_last_call = now - self.time_of_last_call | |
65 | time_left = self.throttle_period - time_since_last_call |
|
66 | time_left = self.throttle_period - time_since_last_call | |
66 |
|
67 | |||
67 | if time_left > datetime.timedelta(seconds=0): |
|
68 | if time_left > datetime.timedelta(seconds=0): | |
68 | return |
|
69 | return | |
69 |
|
70 | |||
70 | self.time_of_last_call = datetime.datetime.now() |
|
71 | self.time_of_last_call = datetime.datetime.now() | |
71 | return fn(*args, **kwargs) |
|
72 | return fn(*args, **kwargs) | |
72 |
|
73 | |||
73 | return wrapper |
|
74 | return wrapper | |
74 |
|
75 | |||
75 |
|
76 | |||
76 | class PublishData(Operation): |
|
77 | class PublishData(Operation): | |
77 | """Clase publish.""" |
|
78 | """Clase publish.""" | |
78 |
|
79 | |||
79 | def __init__(self, **kwargs): |
|
80 | def __init__(self, **kwargs): | |
80 | """Inicio.""" |
|
81 | """Inicio.""" | |
81 | Operation.__init__(self, **kwargs) |
|
82 | Operation.__init__(self, **kwargs) | |
82 | self.isConfig = False |
|
83 | self.isConfig = False | |
83 | self.client = None |
|
84 | self.client = None | |
84 | self.zeromq = None |
|
85 | self.zeromq = None | |
85 | self.mqtt = None |
|
86 | self.mqtt = None | |
86 |
|
87 | |||
87 | def on_disconnect(self, client, userdata, rc): |
|
88 | def on_disconnect(self, client, userdata, rc): | |
88 | if rc != 0: |
|
89 | if rc != 0: | |
89 | print("Unexpected disconnection.") |
|
90 | print("Unexpected disconnection.") | |
90 | self.connect() |
|
91 | self.connect() | |
91 |
|
92 | |||
92 | def connect(self): |
|
93 | def connect(self): | |
93 | print 'trying to connect' |
|
94 | print 'trying to connect' | |
94 | try: |
|
95 | try: | |
95 | self.client.connect( |
|
96 | self.client.connect( | |
96 | host=self.host, |
|
97 | host=self.host, | |
97 | port=self.port, |
|
98 | port=self.port, | |
98 | keepalive=60*10, |
|
99 | keepalive=60*10, | |
99 | bind_address='') |
|
100 | bind_address='') | |
100 | self.client.loop_start() |
|
101 | self.client.loop_start() | |
101 | # self.client.publish( |
|
102 | # self.client.publish( | |
102 | # self.topic + 'SETUP', |
|
103 | # self.topic + 'SETUP', | |
103 | # json.dumps(setup), |
|
104 | # json.dumps(setup), | |
104 | # retain=True |
|
105 | # retain=True | |
105 | # ) |
|
106 | # ) | |
106 | except: |
|
107 | except: | |
107 | print "MQTT Conection error." |
|
108 | print "MQTT Conection error." | |
108 | self.client = False |
|
109 | self.client = False | |
109 |
|
110 | |||
110 | def setup(self, port=1883, username=None, password=None, clientId="user", zeromq=1, verbose=True, **kwargs): |
|
111 | def setup(self, port=1883, username=None, password=None, clientId="user", zeromq=1, verbose=True, **kwargs): | |
111 | self.counter = 0 |
|
112 | self.counter = 0 | |
112 | self.topic = kwargs.get('topic', 'schain') |
|
113 | self.topic = kwargs.get('topic', 'schain') | |
113 | self.delay = kwargs.get('delay', 0) |
|
114 | self.delay = kwargs.get('delay', 0) | |
114 | self.plottype = kwargs.get('plottype', 'spectra') |
|
115 | self.plottype = kwargs.get('plottype', 'spectra') | |
115 | self.host = kwargs.get('host', "10.10.10.82") |
|
116 | self.host = kwargs.get('host', "10.10.10.82") | |
116 | self.port = kwargs.get('port', 3000) |
|
117 | self.port = kwargs.get('port', 3000) | |
117 | self.clientId = clientId |
|
118 | self.clientId = clientId | |
118 | self.cnt = 0 |
|
119 | self.cnt = 0 | |
119 | self.zeromq = zeromq |
|
120 | self.zeromq = zeromq | |
120 | self.mqtt = kwargs.get('plottype', 0) |
|
121 | self.mqtt = kwargs.get('plottype', 0) | |
121 | self.client = None |
|
122 | self.client = None | |
122 | self.verbose = verbose |
|
123 | self.verbose = verbose | |
123 | self.dataOut.firstdata = True |
|
124 | self.dataOut.firstdata = True | |
124 | setup = [] |
|
125 | setup = [] | |
125 | if mqtt is 1: |
|
126 | if mqtt is 1: | |
126 | self.client = mqtt.Client( |
|
127 | self.client = mqtt.Client( | |
127 | client_id=self.clientId + self.topic + 'SCHAIN', |
|
128 | client_id=self.clientId + self.topic + 'SCHAIN', | |
128 | clean_session=True) |
|
129 | clean_session=True) | |
129 | self.client.on_disconnect = self.on_disconnect |
|
130 | self.client.on_disconnect = self.on_disconnect | |
130 | self.connect() |
|
131 | self.connect() | |
131 | for plot in self.plottype: |
|
132 | for plot in self.plottype: | |
132 | setup.append({ |
|
133 | setup.append({ | |
133 | 'plot': plot, |
|
134 | 'plot': plot, | |
134 | 'topic': self.topic + plot, |
|
135 | 'topic': self.topic + plot, | |
135 | 'title': getattr(self, plot + '_' + 'title', False), |
|
136 | 'title': getattr(self, plot + '_' + 'title', False), | |
136 | 'xlabel': getattr(self, plot + '_' + 'xlabel', False), |
|
137 | 'xlabel': getattr(self, plot + '_' + 'xlabel', False), | |
137 | 'ylabel': getattr(self, plot + '_' + 'ylabel', False), |
|
138 | 'ylabel': getattr(self, plot + '_' + 'ylabel', False), | |
138 | 'xrange': getattr(self, plot + '_' + 'xrange', False), |
|
139 | 'xrange': getattr(self, plot + '_' + 'xrange', False), | |
139 | 'yrange': getattr(self, plot + '_' + 'yrange', False), |
|
140 | 'yrange': getattr(self, plot + '_' + 'yrange', False), | |
140 | 'zrange': getattr(self, plot + '_' + 'zrange', False), |
|
141 | 'zrange': getattr(self, plot + '_' + 'zrange', False), | |
141 | }) |
|
142 | }) | |
142 | if zeromq is 1: |
|
143 | if zeromq is 1: | |
143 | context = zmq.Context() |
|
144 | context = zmq.Context() | |
144 | self.zmq_socket = context.socket(zmq.PUSH) |
|
145 | self.zmq_socket = context.socket(zmq.PUSH) | |
145 | server = kwargs.get('server', 'zmq.pipe') |
|
146 | server = kwargs.get('server', 'zmq.pipe') | |
146 |
|
147 | |||
147 | if 'tcp://' in server: |
|
148 | if 'tcp://' in server: | |
148 | address = server |
|
149 | address = server | |
149 | else: |
|
150 | else: | |
150 | address = 'ipc:///tmp/%s' % server |
|
151 | address = 'ipc:///tmp/%s' % server | |
151 |
|
152 | |||
152 | self.zmq_socket.connect(address) |
|
153 | self.zmq_socket.connect(address) | |
153 | time.sleep(1) |
|
154 | time.sleep(1) | |
154 |
|
155 | |||
155 |
|
156 | |||
156 | def publish_data(self): |
|
157 | def publish_data(self): | |
157 | self.dataOut.finished = False |
|
158 | self.dataOut.finished = False | |
158 | if self.mqtt is 1: |
|
159 | if self.mqtt is 1: | |
159 | yData = self.dataOut.heightList[:2].tolist() |
|
160 | yData = self.dataOut.heightList[:2].tolist() | |
160 | if self.plottype == 'spectra': |
|
161 | if self.plottype == 'spectra': | |
161 | data = getattr(self.dataOut, 'data_spc') |
|
162 | data = getattr(self.dataOut, 'data_spc') | |
162 | z = data/self.dataOut.normFactor |
|
163 | z = data/self.dataOut.normFactor | |
163 | zdB = 10*numpy.log10(z) |
|
164 | zdB = 10*numpy.log10(z) | |
164 | xlen, ylen = zdB[0].shape |
|
165 | xlen, ylen = zdB[0].shape | |
165 | dx = int(xlen/MAXNUMX) + 1 |
|
166 | dx = int(xlen/MAXNUMX) + 1 | |
166 | dy = int(ylen/MAXNUMY) + 1 |
|
167 | dy = int(ylen/MAXNUMY) + 1 | |
167 | Z = [0 for i in self.dataOut.channelList] |
|
168 | Z = [0 for i in self.dataOut.channelList] | |
168 | for i in self.dataOut.channelList: |
|
169 | for i in self.dataOut.channelList: | |
169 | Z[i] = zdB[i][::dx, ::dy].tolist() |
|
170 | Z[i] = zdB[i][::dx, ::dy].tolist() | |
170 | payload = { |
|
171 | payload = { | |
171 | 'timestamp': self.dataOut.utctime, |
|
172 | 'timestamp': self.dataOut.utctime, | |
172 | 'data': roundFloats(Z), |
|
173 | 'data': roundFloats(Z), | |
173 | 'channels': ['Ch %s' % ch for ch in self.dataOut.channelList], |
|
174 | 'channels': ['Ch %s' % ch for ch in self.dataOut.channelList], | |
174 | 'interval': self.dataOut.getTimeInterval(), |
|
175 | 'interval': self.dataOut.getTimeInterval(), | |
175 | 'type': self.plottype, |
|
176 | 'type': self.plottype, | |
176 | 'yData': yData |
|
177 | 'yData': yData | |
177 | } |
|
178 | } | |
178 | # print payload |
|
179 | # print payload | |
179 |
|
180 | |||
180 | elif self.plottype in ('rti', 'power'): |
|
181 | elif self.plottype in ('rti', 'power'): | |
181 | data = getattr(self.dataOut, 'data_spc') |
|
182 | data = getattr(self.dataOut, 'data_spc') | |
182 | z = data/self.dataOut.normFactor |
|
183 | z = data/self.dataOut.normFactor | |
183 | avg = numpy.average(z, axis=1) |
|
184 | avg = numpy.average(z, axis=1) | |
184 | avgdB = 10*numpy.log10(avg) |
|
185 | avgdB = 10*numpy.log10(avg) | |
185 | xlen, ylen = z[0].shape |
|
186 | xlen, ylen = z[0].shape | |
186 | dy = numpy.floor(ylen/self.__MAXNUMY) + 1 |
|
187 | dy = numpy.floor(ylen/self.__MAXNUMY) + 1 | |
187 | AVG = [0 for i in self.dataOut.channelList] |
|
188 | AVG = [0 for i in self.dataOut.channelList] | |
188 | for i in self.dataOut.channelList: |
|
189 | for i in self.dataOut.channelList: | |
189 | AVG[i] = avgdB[i][::dy].tolist() |
|
190 | AVG[i] = avgdB[i][::dy].tolist() | |
190 | payload = { |
|
191 | payload = { | |
191 | 'timestamp': self.dataOut.utctime, |
|
192 | 'timestamp': self.dataOut.utctime, | |
192 | 'data': roundFloats(AVG), |
|
193 | 'data': roundFloats(AVG), | |
193 | 'channels': ['Ch %s' % ch for ch in self.dataOut.channelList], |
|
194 | 'channels': ['Ch %s' % ch for ch in self.dataOut.channelList], | |
194 | 'interval': self.dataOut.getTimeInterval(), |
|
195 | 'interval': self.dataOut.getTimeInterval(), | |
195 | 'type': self.plottype, |
|
196 | 'type': self.plottype, | |
196 | 'yData': yData |
|
197 | 'yData': yData | |
197 | } |
|
198 | } | |
198 | elif self.plottype == 'noise': |
|
199 | elif self.plottype == 'noise': | |
199 | noise = self.dataOut.getNoise()/self.dataOut.normFactor |
|
200 | noise = self.dataOut.getNoise()/self.dataOut.normFactor | |
200 | noisedB = 10*numpy.log10(noise) |
|
201 | noisedB = 10*numpy.log10(noise) | |
201 | payload = { |
|
202 | payload = { | |
202 | 'timestamp': self.dataOut.utctime, |
|
203 | 'timestamp': self.dataOut.utctime, | |
203 | 'data': roundFloats(noisedB.reshape(-1, 1).tolist()), |
|
204 | 'data': roundFloats(noisedB.reshape(-1, 1).tolist()), | |
204 | 'channels': ['Ch %s' % ch for ch in self.dataOut.channelList], |
|
205 | 'channels': ['Ch %s' % ch for ch in self.dataOut.channelList], | |
205 | 'interval': self.dataOut.getTimeInterval(), |
|
206 | 'interval': self.dataOut.getTimeInterval(), | |
206 | 'type': self.plottype, |
|
207 | 'type': self.plottype, | |
207 | 'yData': yData |
|
208 | 'yData': yData | |
208 | } |
|
209 | } | |
209 | elif self.plottype == 'snr': |
|
210 | elif self.plottype == 'snr': | |
210 | data = getattr(self.dataOut, 'data_SNR') |
|
211 | data = getattr(self.dataOut, 'data_SNR') | |
211 | avgdB = 10*numpy.log10(data) |
|
212 | avgdB = 10*numpy.log10(data) | |
212 |
|
213 | |||
213 | ylen = data[0].size |
|
214 | ylen = data[0].size | |
214 | dy = numpy.floor(ylen/self.__MAXNUMY) + 1 |
|
215 | dy = numpy.floor(ylen/self.__MAXNUMY) + 1 | |
215 | AVG = [0 for i in self.dataOut.channelList] |
|
216 | AVG = [0 for i in self.dataOut.channelList] | |
216 | for i in self.dataOut.channelList: |
|
217 | for i in self.dataOut.channelList: | |
217 | AVG[i] = avgdB[i][::dy].tolist() |
|
218 | AVG[i] = avgdB[i][::dy].tolist() | |
218 | payload = { |
|
219 | payload = { | |
219 | 'timestamp': self.dataOut.utctime, |
|
220 | 'timestamp': self.dataOut.utctime, | |
220 | 'data': roundFloats(AVG), |
|
221 | 'data': roundFloats(AVG), | |
221 | 'channels': ['Ch %s' % ch for ch in self.dataOut.channelList], |
|
222 | 'channels': ['Ch %s' % ch for ch in self.dataOut.channelList], | |
222 | 'type': self.plottype, |
|
223 | 'type': self.plottype, | |
223 | 'yData': yData |
|
224 | 'yData': yData | |
224 | } |
|
225 | } | |
225 | else: |
|
226 | else: | |
226 | print "Tipo de grafico invalido" |
|
227 | print "Tipo de grafico invalido" | |
227 | payload = { |
|
228 | payload = { | |
228 | 'data': 'None', |
|
229 | 'data': 'None', | |
229 | 'timestamp': 'None', |
|
230 | 'timestamp': 'None', | |
230 | 'type': None |
|
231 | 'type': None | |
231 | } |
|
232 | } | |
232 | # print 'Publishing data to {}'.format(self.host) |
|
233 | # print 'Publishing data to {}'.format(self.host) | |
233 | self.client.publish(self.topic + self.plottype, json.dumps(payload), qos=0) |
|
234 | self.client.publish(self.topic + self.plottype, json.dumps(payload), qos=0) | |
234 |
|
235 | |||
235 | if self.zeromq is 1: |
|
236 | if self.zeromq is 1: | |
236 | if self.verbose: |
|
237 | if self.verbose: | |
237 | print '[Sending] {} - {}'.format(self.dataOut.type, self.dataOut.datatime) |
|
238 | print '[Sending] {} - {}'.format(self.dataOut.type, self.dataOut.datatime) | |
238 | self.zmq_socket.send_pyobj(self.dataOut) |
|
239 | self.zmq_socket.send_pyobj(self.dataOut) | |
239 | self.dataOut.firstdata = False |
|
240 | self.dataOut.firstdata = False | |
240 |
|
241 | |||
241 |
|
242 | |||
242 | def run(self, dataOut, **kwargs): |
|
243 | def run(self, dataOut, **kwargs): | |
243 | self.dataOut = dataOut |
|
244 | self.dataOut = dataOut | |
244 | if not self.isConfig: |
|
245 | if not self.isConfig: | |
245 | self.setup(**kwargs) |
|
246 | self.setup(**kwargs) | |
246 | self.isConfig = True |
|
247 | self.isConfig = True | |
247 |
|
248 | |||
248 | self.publish_data() |
|
249 | self.publish_data() | |
249 | time.sleep(self.delay) |
|
250 | time.sleep(self.delay) | |
250 |
|
251 | |||
251 | def close(self): |
|
252 | def close(self): | |
252 | if self.zeromq is 1: |
|
253 | if self.zeromq is 1: | |
253 | self.dataOut.finished = True |
|
254 | self.dataOut.finished = True | |
254 | self.zmq_socket.send_pyobj(self.dataOut) |
|
255 | self.zmq_socket.send_pyobj(self.dataOut) | |
255 | self.zmq_socket.close() |
|
256 | self.zmq_socket.close() | |
256 | if self.client: |
|
257 | if self.client: | |
257 | self.client.loop_stop() |
|
258 | self.client.loop_stop() | |
258 | self.client.disconnect() |
|
259 | self.client.disconnect() | |
259 |
|
260 | |||
260 | class ReceiverData(ProcessingUnit, Process): |
|
261 | ||
|
262 | class ReceiverData(ProcessingUnit): | |||
|
263 | ||||
|
264 | def __init__(self, **kwargs): | |||
|
265 | ||||
|
266 | ProcessingUnit.__init__(self, **kwargs) | |||
|
267 | ||||
|
268 | self.isConfig = False | |||
|
269 | server = kwargs.get('server', 'zmq.pipe') | |||
|
270 | if 'tcp://' in server: | |||
|
271 | address = server | |||
|
272 | else: | |||
|
273 | address = 'ipc:///tmp/%s' % server | |||
|
274 | ||||
|
275 | self.address = address | |||
|
276 | self.dataOut = JROData() | |||
|
277 | ||||
|
278 | def setup(self): | |||
|
279 | ||||
|
280 | self.context = zmq.Context() | |||
|
281 | self.receiver = self.context.socket(zmq.PULL) | |||
|
282 | self.receiver.bind(self.address) | |||
|
283 | time.sleep(0.5) | |||
|
284 | print '[Starting] ReceiverData from {}'.format(self.address) | |||
|
285 | ||||
|
286 | ||||
|
287 | def run(self): | |||
|
288 | ||||
|
289 | if not self.isConfig: | |||
|
290 | self.setup() | |||
|
291 | self.isConfig = True | |||
|
292 | ||||
|
293 | self.dataOut = self.receiver.recv_pyobj() | |||
|
294 | print '[Receiving] {} - {}'.format(self.dataOut.type, | |||
|
295 | self.dataOut.datatime.ctime()) | |||
|
296 | ||||
|
297 | ||||
|
298 | class PlotterReceiver(ProcessingUnit, Process): | |||
261 |
|
299 | |||
262 | throttle_value = 5 |
|
300 | throttle_value = 5 | |
263 |
|
301 | |||
264 | def __init__(self, **kwargs): |
|
302 | def __init__(self, **kwargs): | |
265 |
|
303 | |||
266 | ProcessingUnit.__init__(self, **kwargs) |
|
304 | ProcessingUnit.__init__(self, **kwargs) | |
267 | Process.__init__(self) |
|
305 | Process.__init__(self) | |
268 | self.mp = False |
|
306 | self.mp = False | |
269 | self.isConfig = False |
|
307 | self.isConfig = False | |
270 | self.isWebConfig = False |
|
308 | self.isWebConfig = False | |
271 | self.plottypes =[] |
|
309 | self.plottypes = [] | |
272 | self.connections = 0 |
|
310 | self.connections = 0 | |
273 | server = kwargs.get('server', 'zmq.pipe') |
|
311 | server = kwargs.get('server', 'zmq.pipe') | |
274 | plot_server = kwargs.get('plot_server', 'zmq.web') |
|
312 | plot_server = kwargs.get('plot_server', 'zmq.web') | |
275 | if 'tcp://' in server: |
|
313 | if 'tcp://' in server: | |
276 | address = server |
|
314 | address = server | |
277 | else: |
|
315 | else: | |
278 | address = 'ipc:///tmp/%s' % server |
|
316 | address = 'ipc:///tmp/%s' % server | |
279 |
|
317 | |||
280 | if 'tcp://' in plot_server: |
|
318 | if 'tcp://' in plot_server: | |
281 | plot_address = plot_server |
|
319 | plot_address = plot_server | |
282 | else: |
|
320 | else: | |
283 | plot_address = 'ipc:///tmp/%s' % plot_server |
|
321 | plot_address = 'ipc:///tmp/%s' % plot_server | |
284 |
|
322 | |||
285 | self.address = address |
|
323 | self.address = address | |
286 | self.plot_address = plot_address |
|
324 | self.plot_address = plot_address | |
287 | self.plottypes = [s.strip() for s in kwargs.get('plottypes', 'rti').split(',')] |
|
325 | self.plottypes = [s.strip() for s in kwargs.get('plottypes', 'rti').split(',')] | |
288 | self.realtime = kwargs.get('realtime', False) |
|
326 | self.realtime = kwargs.get('realtime', False) | |
289 | self.throttle_value = kwargs.get('throttle', 5) |
|
327 | self.throttle_value = kwargs.get('throttle', 5) | |
290 | self.sendData = self.initThrottle(self.throttle_value) |
|
328 | self.sendData = self.initThrottle(self.throttle_value) | |
291 | self.setup() |
|
329 | self.setup() | |
292 |
|
330 | |||
293 | def setup(self): |
|
331 | def setup(self): | |
294 |
|
332 | |||
295 | self.data = {} |
|
333 | self.data = {} | |
296 | self.data['times'] = [] |
|
334 | self.data['times'] = [] | |
297 | for plottype in self.plottypes: |
|
335 | for plottype in self.plottypes: | |
298 | self.data[plottype] = {} |
|
336 | self.data[plottype] = {} | |
299 | self.data['noise'] = {} |
|
337 | self.data['noise'] = {} | |
300 | self.data['throttle'] = self.throttle_value |
|
338 | self.data['throttle'] = self.throttle_value | |
301 | self.data['ENDED'] = False |
|
339 | self.data['ENDED'] = False | |
302 | self.isConfig = True |
|
340 | self.isConfig = True | |
303 | self.data_web = {} |
|
341 | self.data_web = {} | |
304 |
|
342 | |||
305 | def event_monitor(self, monitor): |
|
343 | def event_monitor(self, monitor): | |
306 |
|
344 | |||
307 | events = {} |
|
345 | events = {} | |
308 |
|
346 | |||
309 | for name in dir(zmq): |
|
347 | for name in dir(zmq): | |
310 | if name.startswith('EVENT_'): |
|
348 | if name.startswith('EVENT_'): | |
311 | value = getattr(zmq, name) |
|
349 | value = getattr(zmq, name) | |
312 | events[value] = name |
|
350 | events[value] = name | |
313 |
|
351 | |||
314 | while monitor.poll(): |
|
352 | while monitor.poll(): | |
315 | evt = recv_monitor_message(monitor) |
|
353 | evt = recv_monitor_message(monitor) | |
316 | if evt['event'] == 32: |
|
354 | if evt['event'] == 32: | |
317 | self.connections += 1 |
|
355 | self.connections += 1 | |
318 | if evt['event'] == 512: |
|
356 | if evt['event'] == 512: | |
319 | pass |
|
357 | pass | |
320 | if self.connections == 0 and self.started is True: |
|
358 | if self.connections == 0 and self.started is True: | |
321 | self.ended = True |
|
359 | self.ended = True | |
322 |
|
360 | |||
323 | evt.update({'description': events[evt['event']]}) |
|
361 | evt.update({'description': events[evt['event']]}) | |
324 |
|
362 | |||
325 | if evt['event'] == zmq.EVENT_MONITOR_STOPPED: |
|
363 | if evt['event'] == zmq.EVENT_MONITOR_STOPPED: | |
326 | break |
|
364 | break | |
327 | monitor.close() |
|
365 | monitor.close() | |
328 | print("event monitor thread done!") |
|
366 | print("event monitor thread done!") | |
329 |
|
367 | |||
330 | def initThrottle(self, throttle_value): |
|
368 | def initThrottle(self, throttle_value): | |
331 |
|
369 | |||
332 | @throttle(seconds=throttle_value) |
|
370 | @throttle(seconds=throttle_value) | |
333 | def sendDataThrottled(fn_sender, data): |
|
371 | def sendDataThrottled(fn_sender, data): | |
334 | fn_sender(data) |
|
372 | fn_sender(data) | |
335 |
|
373 | |||
336 | return sendDataThrottled |
|
374 | return sendDataThrottled | |
337 |
|
375 | |||
338 |
|
376 | |||
339 | def send(self, data): |
|
377 | def send(self, data): | |
340 | # print '[sending] data=%s size=%s' % (data.keys(), len(data['times'])) |
|
378 | # print '[sending] data=%s size=%s' % (data.keys(), len(data['times'])) | |
341 | self.sender.send_pyobj(data) |
|
379 | self.sender.send_pyobj(data) | |
342 |
|
380 | |||
343 |
|
381 | |||
344 | def update(self): |
|
382 | def update(self): | |
345 | t = self.dataOut.utctime |
|
383 | t = self.dataOut.utctime | |
346 |
|
384 | |||
347 | if t in self.data['times']: |
|
385 | if t in self.data['times']: | |
348 | return |
|
386 | return | |
349 |
|
387 | |||
350 | self.data['times'].append(t) |
|
388 | self.data['times'].append(t) | |
351 | self.data['dataOut'] = self.dataOut |
|
389 | self.data['dataOut'] = self.dataOut | |
352 |
|
390 | |||
353 | for plottype in self.plottypes: |
|
391 | for plottype in self.plottypes: | |
354 | if plottype == 'spc': |
|
392 | if plottype == 'spc': | |
355 | z = self.dataOut.data_spc/self.dataOut.normFactor |
|
393 | z = self.dataOut.data_spc/self.dataOut.normFactor | |
356 | self.data[plottype] = 10*numpy.log10(z) |
|
394 | self.data[plottype] = 10*numpy.log10(z) | |
357 | self.data['noise'][t] = 10*numpy.log10(self.dataOut.getNoise()/self.dataOut.normFactor) |
|
395 | self.data['noise'][t] = 10*numpy.log10(self.dataOut.getNoise()/self.dataOut.normFactor) | |
358 | if plottype == 'cspc': |
|
396 | if plottype == 'cspc': | |
359 | jcoherence = self.dataOut.data_cspc/numpy.sqrt(self.dataOut.data_spc*self.dataOut.data_spc) |
|
397 | jcoherence = self.dataOut.data_cspc/numpy.sqrt(self.dataOut.data_spc*self.dataOut.data_spc) | |
360 | self.data['cspc_coh'] = numpy.abs(jcoherence) |
|
398 | self.data['cspc_coh'] = numpy.abs(jcoherence) | |
361 | self.data['cspc_phase'] = numpy.arctan2(jcoherence.imag, jcoherence.real)*180/numpy.pi |
|
399 | self.data['cspc_phase'] = numpy.arctan2(jcoherence.imag, jcoherence.real)*180/numpy.pi | |
362 | if plottype == 'rti': |
|
400 | if plottype == 'rti': | |
363 | self.data[plottype][t] = self.dataOut.getPower() |
|
401 | self.data[plottype][t] = self.dataOut.getPower() | |
364 | if plottype == 'snr': |
|
402 | if plottype == 'snr': | |
365 | self.data[plottype][t] = 10*numpy.log10(self.dataOut.data_SNR) |
|
403 | self.data[plottype][t] = 10*numpy.log10(self.dataOut.data_SNR) | |
366 | if plottype == 'dop': |
|
404 | if plottype == 'dop': | |
367 | self.data[plottype][t] = 10*numpy.log10(self.dataOut.data_DOP) |
|
405 | self.data[plottype][t] = 10*numpy.log10(self.dataOut.data_DOP) | |
368 | if plottype == 'mean': |
|
406 | if plottype == 'mean': | |
369 | self.data[plottype][t] = self.dataOut.data_MEAN |
|
407 | self.data[plottype][t] = self.dataOut.data_MEAN | |
370 | if plottype == 'std': |
|
408 | if plottype == 'std': | |
371 | self.data[plottype][t] = self.dataOut.data_STD |
|
409 | self.data[plottype][t] = self.dataOut.data_STD | |
372 | if plottype == 'coh': |
|
410 | if plottype == 'coh': | |
373 | self.data[plottype][t] = self.dataOut.getCoherence() |
|
411 | self.data[plottype][t] = self.dataOut.getCoherence() | |
374 | if plottype == 'phase': |
|
412 | if plottype == 'phase': | |
375 | self.data[plottype][t] = self.dataOut.getCoherence(phase=True) |
|
413 | self.data[plottype][t] = self.dataOut.getCoherence(phase=True) | |
376 | if plottype == 'output': |
|
414 | if plottype == 'output': | |
377 | self.data[plottype][t] = self.dataOut.data_output |
|
415 | self.data[plottype][t] = self.dataOut.data_output | |
378 | if plottype == 'param': |
|
416 | if plottype == 'param': | |
379 | self.data[plottype][t] = self.dataOut.data_param |
|
417 | self.data[plottype][t] = self.dataOut.data_param | |
380 | if self.realtime: |
|
418 | if self.realtime: | |
381 | self.data_web['timestamp'] = t |
|
419 | self.data_web['timestamp'] = t | |
382 | if plottype == 'spc': |
|
420 | if plottype == 'spc': | |
383 | self.data_web[plottype] = roundFloats(decimate(self.data[plottype]).tolist()) |
|
421 | self.data_web[plottype] = roundFloats(decimate(self.data[plottype]).tolist()) | |
384 | elif plottype == 'cspc': |
|
422 | elif plottype == 'cspc': | |
385 | self.data_web['cspc_coh'] = roundFloats(decimate(self.data['cspc_coh']).tolist()) |
|
423 | self.data_web['cspc_coh'] = roundFloats(decimate(self.data['cspc_coh']).tolist()) | |
386 | self.data_web['cspc_phase'] = roundFloats(decimate(self.data['cspc_phase']).tolist()) |
|
424 | self.data_web['cspc_phase'] = roundFloats(decimate(self.data['cspc_phase']).tolist()) | |
387 | elif plottype == 'noise': |
|
425 | elif plottype == 'noise': | |
388 | self.data_web['noise'] = roundFloats(self.data['noise'][t].tolist()) |
|
426 | self.data_web['noise'] = roundFloats(self.data['noise'][t].tolist()) | |
389 | else: |
|
427 | else: | |
390 | self.data_web[plottype] = roundFloats(decimate(self.data[plottype][t]).tolist()) |
|
428 | self.data_web[plottype] = roundFloats(decimate(self.data[plottype][t]).tolist()) | |
391 | self.data_web['interval'] = self.dataOut.getTimeInterval() |
|
429 | self.data_web['interval'] = self.dataOut.getTimeInterval() | |
392 | self.data_web['type'] = plottype |
|
430 | self.data_web['type'] = plottype | |
393 |
|
431 | |||
394 | def run(self): |
|
432 | def run(self): | |
395 |
|
433 | |||
396 | print '[Starting] {} from {}'.format(self.name, self.address) |
|
434 | print '[Starting] {} from {}'.format(self.name, self.address) | |
397 |
|
435 | |||
398 | self.context = zmq.Context() |
|
436 | self.context = zmq.Context() | |
399 | self.receiver = self.context.socket(zmq.PULL) |
|
437 | self.receiver = self.context.socket(zmq.PULL) | |
400 | self.receiver.bind(self.address) |
|
438 | self.receiver.bind(self.address) | |
401 | monitor = self.receiver.get_monitor_socket() |
|
439 | monitor = self.receiver.get_monitor_socket() | |
402 | self.sender = self.context.socket(zmq.PUB) |
|
440 | self.sender = self.context.socket(zmq.PUB) | |
403 | if self.realtime: |
|
441 | if self.realtime: | |
404 | self.sender_web = self.context.socket(zmq.PUB) |
|
442 | self.sender_web = self.context.socket(zmq.PUB) | |
405 | self.sender_web.connect(self.plot_address) |
|
443 | self.sender_web.connect(self.plot_address) | |
406 | time.sleep(1) |
|
444 | time.sleep(1) | |
407 |
|
445 | |||
408 | if 'server' in self.kwargs: |
|
446 | if 'server' in self.kwargs: | |
409 | self.sender.bind("ipc:///tmp/{}.plots".format(self.kwargs['server'])) |
|
447 | self.sender.bind("ipc:///tmp/{}.plots".format(self.kwargs['server'])) | |
410 | else: |
|
448 | else: | |
411 | self.sender.bind("ipc:///tmp/zmq.plots") |
|
449 | self.sender.bind("ipc:///tmp/zmq.plots") | |
412 |
|
450 | |||
413 | time.sleep(3) |
|
451 | time.sleep(3) | |
414 |
|
452 | |||
415 | t = Thread(target=self.event_monitor, args=(monitor,)) |
|
453 | t = Thread(target=self.event_monitor, args=(monitor,)) | |
416 | t.start() |
|
454 | t.start() | |
417 |
|
455 | |||
418 | while True: |
|
456 | while True: | |
419 | self.dataOut = self.receiver.recv_pyobj() |
|
457 | self.dataOut = self.receiver.recv_pyobj() | |
420 | # print '[Receiving] {} - {}'.format(self.dataOut.type, |
|
458 | # print '[Receiving] {} - {}'.format(self.dataOut.type, | |
421 | # self.dataOut.datatime.ctime()) |
|
459 | # self.dataOut.datatime.ctime()) | |
422 |
|
460 | |||
423 | self.update() |
|
461 | self.update() | |
424 |
|
462 | |||
425 | if self.dataOut.firstdata is True: |
|
463 | if self.dataOut.firstdata is True: | |
426 | self.data['STARTED'] = True |
|
464 | self.data['STARTED'] = True | |
427 |
|
465 | |||
428 | if self.dataOut.finished is True: |
|
466 | if self.dataOut.finished is True: | |
429 | self.send(self.data) |
|
467 | self.send(self.data) | |
430 | self.connections -= 1 |
|
468 | self.connections -= 1 | |
431 | if self.connections == 0 and self.started: |
|
469 | if self.connections == 0 and self.started: | |
432 | self.ended = True |
|
470 | self.ended = True | |
433 | self.data['ENDED'] = True |
|
471 | self.data['ENDED'] = True | |
434 | self.send(self.data) |
|
472 | self.send(self.data) | |
435 | self.setup() |
|
473 | self.setup() | |
436 | self.started = False |
|
474 | self.started = False | |
437 | else: |
|
475 | else: | |
438 | if self.realtime: |
|
476 | if self.realtime: | |
439 | self.send(self.data) |
|
477 | self.send(self.data) | |
440 | self.sender_web.send_string(json.dumps(self.data_web)) |
|
478 | self.sender_web.send_string(json.dumps(self.data_web)) | |
441 | else: |
|
479 | else: | |
442 | self.sendData(self.send, self.data) |
|
480 | self.sendData(self.send, self.data) | |
443 | self.started = True |
|
481 | self.started = True | |
444 |
|
482 | |||
445 | self.data['STARTED'] = False |
|
483 | self.data['STARTED'] = False | |
446 | return |
|
484 | return | |
447 |
|
485 | |||
448 | def sendToWeb(self): |
|
486 | def sendToWeb(self): | |
449 |
|
487 | |||
450 | if not self.isWebConfig: |
|
488 | if not self.isWebConfig: | |
451 | context = zmq.Context() |
|
489 | context = zmq.Context() | |
452 | sender_web_config = context.socket(zmq.PUB) |
|
490 | sender_web_config = context.socket(zmq.PUB) | |
453 | if 'tcp://' in self.plot_address: |
|
491 | if 'tcp://' in self.plot_address: | |
454 | dum, address, port = self.plot_address.split(':') |
|
492 | dum, address, port = self.plot_address.split(':') | |
455 | conf_address = '{}:{}:{}'.format(dum, address, int(port)+1) |
|
493 | conf_address = '{}:{}:{}'.format(dum, address, int(port)+1) | |
456 | else: |
|
494 | else: | |
457 | conf_address = self.plot_address + '.config' |
|
495 | conf_address = self.plot_address + '.config' | |
458 | sender_web_config.bind(conf_address) |
|
496 | sender_web_config.bind(conf_address) | |
459 | time.sleep(1) |
|
497 | time.sleep(1) | |
460 | for kwargs in self.operationKwargs.values(): |
|
498 | for kwargs in self.operationKwargs.values(): | |
461 | if 'plot' in kwargs: |
|
499 | if 'plot' in kwargs: | |
462 | print '[Sending] Config data to web for {}'.format(kwargs['code'].upper()) |
|
500 | print '[Sending] Config data to web for {}'.format(kwargs['code'].upper()) | |
463 | sender_web_config.send_string(json.dumps(kwargs)) |
|
501 | sender_web_config.send_string(json.dumps(kwargs)) | |
464 | self.isWebConfig = True |
|
502 | self.isWebConfig = True |
General Comments 0
You need to be logged in to leave comments.
Login now