##// END OF EJS Templates
Ultimo avance simulador y pruebas de procesaiento Weather Radar
avaldez -
r1294:575339b32691 v3.0-devel-wrc
parent child
Show More
@@ -1,1372 +1,1372
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 import json
10 import json
11
11
12 from schainpy.utils import log
12 from schainpy.utils import log
13 from .jroheaderIO import SystemHeader, RadarControllerHeader
13 from .jroheaderIO import SystemHeader, RadarControllerHeader
14
14
15
15
16 def getNumpyDtype(dataTypeCode):
16 def getNumpyDtype(dataTypeCode):
17
17
18 if dataTypeCode == 0:
18 if dataTypeCode == 0:
19 numpyDtype = numpy.dtype([('real', '<i1'), ('imag', '<i1')])
19 numpyDtype = numpy.dtype([('real', '<i1'), ('imag', '<i1')])
20 elif dataTypeCode == 1:
20 elif dataTypeCode == 1:
21 numpyDtype = numpy.dtype([('real', '<i2'), ('imag', '<i2')])
21 numpyDtype = numpy.dtype([('real', '<i2'), ('imag', '<i2')])
22 elif dataTypeCode == 2:
22 elif dataTypeCode == 2:
23 numpyDtype = numpy.dtype([('real', '<i4'), ('imag', '<i4')])
23 numpyDtype = numpy.dtype([('real', '<i4'), ('imag', '<i4')])
24 elif dataTypeCode == 3:
24 elif dataTypeCode == 3:
25 numpyDtype = numpy.dtype([('real', '<i8'), ('imag', '<i8')])
25 numpyDtype = numpy.dtype([('real', '<i8'), ('imag', '<i8')])
26 elif dataTypeCode == 4:
26 elif dataTypeCode == 4:
27 numpyDtype = numpy.dtype([('real', '<f4'), ('imag', '<f4')])
27 numpyDtype = numpy.dtype([('real', '<f4'), ('imag', '<f4')])
28 elif dataTypeCode == 5:
28 elif dataTypeCode == 5:
29 numpyDtype = numpy.dtype([('real', '<f8'), ('imag', '<f8')])
29 numpyDtype = numpy.dtype([('real', '<f8'), ('imag', '<f8')])
30 else:
30 else:
31 raise ValueError('dataTypeCode was not defined')
31 raise ValueError('dataTypeCode was not defined')
32
32
33 return numpyDtype
33 return numpyDtype
34
34
35
35
36 def getDataTypeCode(numpyDtype):
36 def getDataTypeCode(numpyDtype):
37
37
38 if numpyDtype == numpy.dtype([('real', '<i1'), ('imag', '<i1')]):
38 if numpyDtype == numpy.dtype([('real', '<i1'), ('imag', '<i1')]):
39 datatype = 0
39 datatype = 0
40 elif numpyDtype == numpy.dtype([('real', '<i2'), ('imag', '<i2')]):
40 elif numpyDtype == numpy.dtype([('real', '<i2'), ('imag', '<i2')]):
41 datatype = 1
41 datatype = 1
42 elif numpyDtype == numpy.dtype([('real', '<i4'), ('imag', '<i4')]):
42 elif numpyDtype == numpy.dtype([('real', '<i4'), ('imag', '<i4')]):
43 datatype = 2
43 datatype = 2
44 elif numpyDtype == numpy.dtype([('real', '<i8'), ('imag', '<i8')]):
44 elif numpyDtype == numpy.dtype([('real', '<i8'), ('imag', '<i8')]):
45 datatype = 3
45 datatype = 3
46 elif numpyDtype == numpy.dtype([('real', '<f4'), ('imag', '<f4')]):
46 elif numpyDtype == numpy.dtype([('real', '<f4'), ('imag', '<f4')]):
47 datatype = 4
47 datatype = 4
48 elif numpyDtype == numpy.dtype([('real', '<f8'), ('imag', '<f8')]):
48 elif numpyDtype == numpy.dtype([('real', '<f8'), ('imag', '<f8')]):
49 datatype = 5
49 datatype = 5
50 else:
50 else:
51 datatype = None
51 datatype = None
52
52
53 return datatype
53 return datatype
54
54
55
55
56 def hildebrand_sekhon(data, navg):
56 def hildebrand_sekhon(data, navg):
57 """
57 """
58 This method is for the objective determination of the noise level in Doppler spectra. This
58 This method is for the objective determination of the noise level in Doppler spectra. This
59 implementation technique is based on the fact that the standard deviation of the spectral
59 implementation technique is based on the fact that the standard deviation of the spectral
60 densities is equal to the mean spectral density for white Gaussian noise
60 densities is equal to the mean spectral density for white Gaussian noise
61
61
62 Inputs:
62 Inputs:
63 Data : heights
63 Data : heights
64 navg : numbers of averages
64 navg : numbers of averages
65
65
66 Return:
66 Return:
67 mean : noise's level
67 mean : noise's level
68 """
68 """
69
69
70 sortdata = numpy.sort(data, axis=None)
70 sortdata = numpy.sort(data, axis=None)
71 lenOfData = len(sortdata)
71 lenOfData = len(sortdata)
72 nums_min = lenOfData*0.2
72 nums_min = lenOfData*0.2
73
73
74 if nums_min <= 5:
74 if nums_min <= 5:
75
75
76 nums_min = 5
76 nums_min = 5
77
77
78 sump = 0.
78 sump = 0.
79 sumq = 0.
79 sumq = 0.
80
80
81 j = 0
81 j = 0
82 cont = 1
82 cont = 1
83
83
84 while((cont == 1)and(j < lenOfData)):
84 while((cont == 1)and(j < lenOfData)):
85
85
86 sump += sortdata[j]
86 sump += sortdata[j]
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
103
104 class Beam:
104 class Beam:
105
105
106 def __init__(self):
106 def __init__(self):
107 self.codeList = []
107 self.codeList = []
108 self.azimuthList = []
108 self.azimuthList = []
109 self.zenithList = []
109 self.zenithList = []
110
110
111
111
112 class GenericData(object):
112 class GenericData(object):
113
113
114 flagNoData = True
114 flagNoData = True
115
115
116 def copy(self, inputObj=None):
116 def copy(self, inputObj=None):
117
117
118 if inputObj == None:
118 if inputObj == None:
119 return copy.deepcopy(self)
119 return copy.deepcopy(self)
120
120
121 for key in list(inputObj.__dict__.keys()):
121 for key in list(inputObj.__dict__.keys()):
122
122
123 attribute = inputObj.__dict__[key]
123 attribute = inputObj.__dict__[key]
124
124
125 # If this attribute is a tuple or list
125 # If this attribute is a tuple or list
126 if type(inputObj.__dict__[key]) in (tuple, list):
126 if type(inputObj.__dict__[key]) in (tuple, list):
127 self.__dict__[key] = attribute[:]
127 self.__dict__[key] = attribute[:]
128 continue
128 continue
129
129
130 # If this attribute is another object or instance
130 # If this attribute is another object or instance
131 if hasattr(attribute, '__dict__'):
131 if hasattr(attribute, '__dict__'):
132 self.__dict__[key] = attribute.copy()
132 self.__dict__[key] = attribute.copy()
133 continue
133 continue
134
134
135 self.__dict__[key] = inputObj.__dict__[key]
135 self.__dict__[key] = inputObj.__dict__[key]
136
136
137 def deepcopy(self):
137 def deepcopy(self):
138
138
139 return copy.deepcopy(self)
139 return copy.deepcopy(self)
140
140
141 def isEmpty(self):
141 def isEmpty(self):
142
142
143 return self.flagNoData
143 return self.flagNoData
144
144
145
145
146 class JROData(GenericData):
146 class JROData(GenericData):
147
147
148 # m_BasicHeader = BasicHeader()
148 # m_BasicHeader = BasicHeader()
149 # m_ProcessingHeader = ProcessingHeader()
149 # m_ProcessingHeader = ProcessingHeader()
150
150
151 systemHeaderObj = SystemHeader()
151 systemHeaderObj = SystemHeader()
152 radarControllerHeaderObj = RadarControllerHeader()
152 radarControllerHeaderObj = RadarControllerHeader()
153 # data = None
153 # data = None
154 type = None
154 type = None
155 datatype = None # dtype but in string
155 datatype = None # dtype but in string
156 # dtype = None
156 # dtype = None
157 # nChannels = None
157 # nChannels = None
158 # nHeights = None
158 # nHeights = None
159 nProfiles = None
159 nProfiles = None
160 heightList = None
160 heightList = None
161 channelList = None
161 channelList = None
162 flagDiscontinuousBlock = False
162 flagDiscontinuousBlock = False
163 useLocalTime = False
163 useLocalTime = False
164 utctime = None
164 utctime = None
165 timeZone = None
165 timeZone = None
166 dstFlag = None
166 dstFlag = None
167 errorCount = None
167 errorCount = None
168 blocksize = None
168 blocksize = None
169 # nCode = None
169 # nCode = None
170 # nBaud = None
170 # nBaud = None
171 # code = None
171 # code = None
172 flagDecodeData = False # asumo q la data no esta decodificada
172 flagDecodeData = False # asumo q la data no esta decodificada
173 flagDeflipData = False # asumo q la data no esta sin flip
173 flagDeflipData = False # asumo q la data no esta sin flip
174 flagShiftFFT = False
174 flagShiftFFT = False
175 # ippSeconds = None
175 # ippSeconds = None
176 # timeInterval = None
176 # timeInterval = None
177 nCohInt = None
177 nCohInt = None
178 # noise = None
178 # noise = None
179 windowOfFilter = 1
179 windowOfFilter = 1
180 # Speed of ligth
180 # Speed of ligth
181 C = 3e8
181 C = 3e8
182 frequency = 49.92e6
182 frequency = 49.92e6
183 realtime = False
183 realtime = False
184 beacon_heiIndexList = None
184 beacon_heiIndexList = None
185 last_block = None
185 last_block = None
186 blocknow = None
186 blocknow = None
187 azimuth = None
187 azimuth = None
188 zenith = None
188 zenith = None
189 beam = Beam()
189 beam = Beam()
190 profileIndex = None
190 profileIndex = None
191 error = None
191 error = None
192 data = None
192 data = None
193 nmodes = None
193 nmodes = None
194
194
195 def __str__(self):
195 def __str__(self):
196
196
197 return '{} - {}'.format(self.type, self.getDatatime())
197 return '{} - {}'.format(self.type, self.getDatatime())
198
198
199 def getNoise(self):
199 def getNoise(self):
200
200
201 raise NotImplementedError
201 raise NotImplementedError
202
202
203 def getNChannels(self):
203 def getNChannels(self):
204
204
205 return len(self.channelList)
205 return len(self.channelList)
206
206
207 def getChannelIndexList(self):
207 def getChannelIndexList(self):
208
208
209 return list(range(self.nChannels))
209 return list(range(self.nChannels))
210
210
211 def getNHeights(self):
211 def getNHeights(self):
212
212
213 return len(self.heightList)
213 return len(self.heightList)
214
214
215 def getHeiRange(self, extrapoints=0):
215 def getHeiRange(self, extrapoints=0):
216
216
217 heis = self.heightList
217 heis = self.heightList
218 # deltah = self.heightList[1] - self.heightList[0]
218 # deltah = self.heightList[1] - self.heightList[0]
219 #
219 #
220 # heis.append(self.heightList[-1])
220 # heis.append(self.heightList[-1])
221
221
222 return heis
222 return heis
223
223
224 def getDeltaH(self):
224 def getDeltaH(self):
225
225
226 delta = self.heightList[1] - self.heightList[0]
226 delta = self.heightList[1] - self.heightList[0]
227
227
228 return delta
228 return delta
229
229
230 def getltctime(self):
230 def getltctime(self):
231
231
232 if self.useLocalTime:
232 if self.useLocalTime:
233 return self.utctime - self.timeZone * 60
233 return self.utctime - self.timeZone * 60
234
234
235 return self.utctime
235 return self.utctime
236
236
237 def getDatatime(self):
237 def getDatatime(self):
238
238
239 datatimeValue = datetime.datetime.utcfromtimestamp(self.ltctime)
239 datatimeValue = datetime.datetime.utcfromtimestamp(self.ltctime)
240 return datatimeValue
240 return datatimeValue
241
241
242 def getTimeRange(self):
242 def getTimeRange(self):
243
243
244 datatime = []
244 datatime = []
245
245
246 datatime.append(self.ltctime)
246 datatime.append(self.ltctime)
247 datatime.append(self.ltctime + self.timeInterval + 1)
247 datatime.append(self.ltctime + self.timeInterval + 1)
248
248
249 datatime = numpy.array(datatime)
249 datatime = numpy.array(datatime)
250
250
251 return datatime
251 return datatime
252
252
253 def getFmaxTimeResponse(self):
253 def getFmaxTimeResponse(self):
254
254
255 period = (10**-6) * self.getDeltaH() / (0.15)
255 period = (10**-6) * self.getDeltaH() / (0.15)
256
256
257 PRF = 1. / (period * self.nCohInt)
257 PRF = 1. / (period * self.nCohInt)
258
258
259 fmax = PRF
259 fmax = PRF
260
260
261 return fmax
261 return fmax
262
262
263 def getFmax(self):
263 def getFmax(self):
264 PRF = 1. / (self.ippSeconds * self.nCohInt)
264 PRF = 1. / (self.ippSeconds * self.nCohInt)
265
265
266 fmax = PRF
266 fmax = PRF
267 return fmax
267 return fmax
268
268
269 def getVmax(self):
269 def getVmax(self):
270
270 #print("frequency",self.frequency)
271 _lambda = self.C / self.frequency
271 _lambda = self.C / self.frequency
272
272
273 vmax = self.getFmax() * _lambda / 2
273 vmax = self.getFmax() * _lambda / 2
274
274
275 return vmax
275 return vmax
276
276
277 def get_ippSeconds(self):
277 def get_ippSeconds(self):
278 '''
278 '''
279 '''
279 '''
280 return self.radarControllerHeaderObj.ippSeconds
280 return self.radarControllerHeaderObj.ippSeconds
281
281
282 def set_ippSeconds(self, ippSeconds):
282 def set_ippSeconds(self, ippSeconds):
283 '''
283 '''
284 '''
284 '''
285
285
286 self.radarControllerHeaderObj.ippSeconds = ippSeconds
286 self.radarControllerHeaderObj.ippSeconds = ippSeconds
287
287
288 return
288 return
289
289
290 def get_dtype(self):
290 def get_dtype(self):
291 '''
291 '''
292 '''
292 '''
293 return getNumpyDtype(self.datatype)
293 return getNumpyDtype(self.datatype)
294
294
295 def set_dtype(self, numpyDtype):
295 def set_dtype(self, numpyDtype):
296 '''
296 '''
297 '''
297 '''
298
298
299 self.datatype = getDataTypeCode(numpyDtype)
299 self.datatype = getDataTypeCode(numpyDtype)
300
300
301 def get_code(self):
301 def get_code(self):
302 '''
302 '''
303 '''
303 '''
304 return self.radarControllerHeaderObj.code
304 return self.radarControllerHeaderObj.code
305
305
306 def set_code(self, code):
306 def set_code(self, code):
307 '''
307 '''
308 '''
308 '''
309 self.radarControllerHeaderObj.code = code
309 self.radarControllerHeaderObj.code = code
310
310
311 return
311 return
312
312
313 def get_ncode(self):
313 def get_ncode(self):
314 '''
314 '''
315 '''
315 '''
316 return self.radarControllerHeaderObj.nCode
316 return self.radarControllerHeaderObj.nCode
317
317
318 def set_ncode(self, nCode):
318 def set_ncode(self, nCode):
319 '''
319 '''
320 '''
320 '''
321 self.radarControllerHeaderObj.nCode = nCode
321 self.radarControllerHeaderObj.nCode = nCode
322
322
323 return
323 return
324
324
325 def get_nbaud(self):
325 def get_nbaud(self):
326 '''
326 '''
327 '''
327 '''
328 return self.radarControllerHeaderObj.nBaud
328 return self.radarControllerHeaderObj.nBaud
329
329
330 def set_nbaud(self, nBaud):
330 def set_nbaud(self, nBaud):
331 '''
331 '''
332 '''
332 '''
333 self.radarControllerHeaderObj.nBaud = nBaud
333 self.radarControllerHeaderObj.nBaud = nBaud
334
334
335 return
335 return
336
336
337 nChannels = property(getNChannels, "I'm the 'nChannel' property.")
337 nChannels = property(getNChannels, "I'm the 'nChannel' property.")
338 channelIndexList = property(
338 channelIndexList = property(
339 getChannelIndexList, "I'm the 'channelIndexList' property.")
339 getChannelIndexList, "I'm the 'channelIndexList' property.")
340 nHeights = property(getNHeights, "I'm the 'nHeights' property.")
340 nHeights = property(getNHeights, "I'm the 'nHeights' property.")
341 #noise = property(getNoise, "I'm the 'nHeights' property.")
341 #noise = property(getNoise, "I'm the 'nHeights' property.")
342 datatime = property(getDatatime, "I'm the 'datatime' property")
342 datatime = property(getDatatime, "I'm the 'datatime' property")
343 ltctime = property(getltctime, "I'm the 'ltctime' property")
343 ltctime = property(getltctime, "I'm the 'ltctime' property")
344 ippSeconds = property(get_ippSeconds, set_ippSeconds)
344 ippSeconds = property(get_ippSeconds, set_ippSeconds)
345 dtype = property(get_dtype, set_dtype)
345 dtype = property(get_dtype, set_dtype)
346 # timeInterval = property(getTimeInterval, "I'm the 'timeInterval' property")
346 # timeInterval = property(getTimeInterval, "I'm the 'timeInterval' property")
347 code = property(get_code, set_code)
347 code = property(get_code, set_code)
348 nCode = property(get_ncode, set_ncode)
348 nCode = property(get_ncode, set_ncode)
349 nBaud = property(get_nbaud, set_nbaud)
349 nBaud = property(get_nbaud, set_nbaud)
350
350
351
351
352 class Voltage(JROData):
352 class Voltage(JROData):
353
353
354 # data es un numpy array de 2 dmensiones (canales, alturas)
354 # data es un numpy array de 2 dmensiones (canales, alturas)
355 data = None
355 data = None
356
356
357 def __init__(self):
357 def __init__(self):
358 '''
358 '''
359 Constructor
359 Constructor
360 '''
360 '''
361
361
362 self.useLocalTime = True
362 self.useLocalTime = True
363 self.radarControllerHeaderObj = RadarControllerHeader()
363 self.radarControllerHeaderObj = RadarControllerHeader()
364 self.systemHeaderObj = SystemHeader()
364 self.systemHeaderObj = SystemHeader()
365 self.type = "Voltage"
365 self.type = "Voltage"
366 self.data = None
366 self.data = None
367 # self.dtype = None
367 # self.dtype = None
368 # self.nChannels = 0
368 # self.nChannels = 0
369 # self.nHeights = 0
369 # self.nHeights = 0
370 self.nProfiles = None
370 self.nProfiles = None
371 self.heightList = None
371 self.heightList = None
372 self.channelList = None
372 self.channelList = None
373 # self.channelIndexList = None
373 # self.channelIndexList = None
374 self.flagNoData = True
374 self.flagNoData = True
375 self.flagDiscontinuousBlock = False
375 self.flagDiscontinuousBlock = False
376 self.utctime = None
376 self.utctime = None
377 self.timeZone = None
377 self.timeZone = None
378 self.dstFlag = None
378 self.dstFlag = None
379 self.errorCount = None
379 self.errorCount = None
380 self.nCohInt = None
380 self.nCohInt = None
381 self.blocksize = None
381 self.blocksize = None
382 self.flagDecodeData = False # asumo q la data no esta decodificada
382 self.flagDecodeData = False # asumo q la data no esta decodificada
383 self.flagDeflipData = False # asumo q la data no esta sin flip
383 self.flagDeflipData = False # asumo q la data no esta sin flip
384 self.flagShiftFFT = False
384 self.flagShiftFFT = False
385 self.flagDataAsBlock = False # Asumo que la data es leida perfil a perfil
385 self.flagDataAsBlock = False # Asumo que la data es leida perfil a perfil
386 self.profileIndex = 0
386 self.profileIndex = 0
387
387
388 def getNoisebyHildebrand(self, channel=None):
388 def getNoisebyHildebrand(self, channel=None):
389 """
389 """
390 Determino el nivel de ruido usando el metodo Hildebrand-Sekhon
390 Determino el nivel de ruido usando el metodo Hildebrand-Sekhon
391
391
392 Return:
392 Return:
393 noiselevel
393 noiselevel
394 """
394 """
395
395
396 if channel != None:
396 if channel != None:
397 data = self.data[channel]
397 data = self.data[channel]
398 nChannels = 1
398 nChannels = 1
399 else:
399 else:
400 data = self.data
400 data = self.data
401 nChannels = self.nChannels
401 nChannels = self.nChannels
402
402
403 noise = numpy.zeros(nChannels)
403 noise = numpy.zeros(nChannels)
404 power = data * numpy.conjugate(data)
404 power = data * numpy.conjugate(data)
405
405
406 for thisChannel in range(nChannels):
406 for thisChannel in range(nChannels):
407 if nChannels == 1:
407 if nChannels == 1:
408 daux = power[:].real
408 daux = power[:].real
409 else:
409 else:
410 daux = power[thisChannel, :].real
410 daux = power[thisChannel, :].real
411 noise[thisChannel] = hildebrand_sekhon(daux, self.nCohInt)
411 noise[thisChannel] = hildebrand_sekhon(daux, self.nCohInt)
412
412
413 return noise
413 return noise
414
414
415 def getNoise(self, type=1, channel=None):
415 def getNoise(self, type=1, channel=None):
416
416
417 if type == 1:
417 if type == 1:
418 noise = self.getNoisebyHildebrand(channel)
418 noise = self.getNoisebyHildebrand(channel)
419
419
420 return noise
420 return noise
421
421
422 def getPower(self, channel=None):
422 def getPower(self, channel=None):
423
423
424 if channel != None:
424 if channel != None:
425 data = self.data[channel]
425 data = self.data[channel]
426 else:
426 else:
427 data = self.data
427 data = self.data
428
428
429 power = data * numpy.conjugate(data)
429 power = data * numpy.conjugate(data)
430 powerdB = 10 * numpy.log10(power.real)
430 powerdB = 10 * numpy.log10(power.real)
431 powerdB = numpy.squeeze(powerdB)
431 powerdB = numpy.squeeze(powerdB)
432
432
433 return powerdB
433 return powerdB
434
434
435 def getTimeInterval(self):
435 def getTimeInterval(self):
436
436
437 timeInterval = self.ippSeconds * self.nCohInt
437 timeInterval = self.ippSeconds * self.nCohInt
438
438
439 return timeInterval
439 return timeInterval
440
440
441 noise = property(getNoise, "I'm the 'nHeights' property.")
441 noise = property(getNoise, "I'm the 'nHeights' property.")
442 timeInterval = property(getTimeInterval, "I'm the 'timeInterval' property")
442 timeInterval = property(getTimeInterval, "I'm the 'timeInterval' property")
443
443
444
444
445 class Spectra(JROData):
445 class Spectra(JROData):
446
446
447 # data spc es un numpy array de 2 dmensiones (canales, perfiles, alturas)
447 # data spc es un numpy array de 2 dmensiones (canales, perfiles, alturas)
448 data_spc = None
448 data_spc = None
449 # data cspc es un numpy array de 2 dmensiones (canales, pares, alturas)
449 # data cspc es un numpy array de 2 dmensiones (canales, pares, alturas)
450 data_cspc = None
450 data_cspc = None
451 # data dc es un numpy array de 2 dmensiones (canales, alturas)
451 # data dc es un numpy array de 2 dmensiones (canales, alturas)
452 data_dc = None
452 data_dc = None
453 # data power
453 # data power
454 data_pwr = None
454 data_pwr = None
455 nFFTPoints = None
455 nFFTPoints = None
456 # nPairs = None
456 # nPairs = None
457 pairsList = None
457 pairsList = None
458 nIncohInt = None
458 nIncohInt = None
459 wavelength = None # Necesario para cacular el rango de velocidad desde la frecuencia
459 wavelength = None # Necesario para cacular el rango de velocidad desde la frecuencia
460 nCohInt = None # se requiere para determinar el valor de timeInterval
460 nCohInt = None # se requiere para determinar el valor de timeInterval
461 ippFactor = None
461 ippFactor = None
462 profileIndex = 0
462 profileIndex = 0
463 plotting = "spectra"
463 plotting = "spectra"
464
464
465 def __init__(self):
465 def __init__(self):
466 '''
466 '''
467 Constructor
467 Constructor
468 '''
468 '''
469
469
470 self.useLocalTime = True
470 self.useLocalTime = True
471 self.radarControllerHeaderObj = RadarControllerHeader()
471 self.radarControllerHeaderObj = RadarControllerHeader()
472 self.systemHeaderObj = SystemHeader()
472 self.systemHeaderObj = SystemHeader()
473 self.type = "Spectra"
473 self.type = "Spectra"
474 # self.data = None
474 # self.data = None
475 # self.dtype = None
475 # self.dtype = None
476 # self.nChannels = 0
476 # self.nChannels = 0
477 # self.nHeights = 0
477 # self.nHeights = 0
478 self.nProfiles = None
478 self.nProfiles = None
479 self.heightList = None
479 self.heightList = None
480 self.channelList = None
480 self.channelList = None
481 # self.channelIndexList = None
481 # self.channelIndexList = None
482 self.pairsList = None
482 self.pairsList = None
483 self.flagNoData = True
483 self.flagNoData = True
484 self.flagDiscontinuousBlock = False
484 self.flagDiscontinuousBlock = False
485 self.utctime = None
485 self.utctime = None
486 self.nCohInt = None
486 self.nCohInt = None
487 self.nIncohInt = None
487 self.nIncohInt = None
488 self.blocksize = None
488 self.blocksize = None
489 self.nFFTPoints = None
489 self.nFFTPoints = None
490 self.wavelength = None
490 self.wavelength = None
491 self.flagDecodeData = False # asumo q la data no esta decodificada
491 self.flagDecodeData = False # asumo q la data no esta decodificada
492 self.flagDeflipData = False # asumo q la data no esta sin flip
492 self.flagDeflipData = False # asumo q la data no esta sin flip
493 self.flagShiftFFT = False
493 self.flagShiftFFT = False
494 self.ippFactor = 1
494 self.ippFactor = 1
495 #self.noise = None
495 #self.noise = None
496 self.beacon_heiIndexList = []
496 self.beacon_heiIndexList = []
497 self.noise_estimation = None
497 self.noise_estimation = None
498
498
499 def getNoisebyHildebrand(self, xmin_index=None, xmax_index=None, ymin_index=None, ymax_index=None):
499 def getNoisebyHildebrand(self, xmin_index=None, xmax_index=None, ymin_index=None, ymax_index=None):
500 """
500 """
501 Determino el nivel de ruido usando el metodo Hildebrand-Sekhon
501 Determino el nivel de ruido usando el metodo Hildebrand-Sekhon
502
502
503 Return:
503 Return:
504 noiselevel
504 noiselevel
505 """
505 """
506
506
507 noise = numpy.zeros(self.nChannels)
507 noise = numpy.zeros(self.nChannels)
508
508
509 for channel in range(self.nChannels):
509 for channel in range(self.nChannels):
510 daux = self.data_spc[channel,
510 daux = self.data_spc[channel,
511 xmin_index:xmax_index, ymin_index:ymax_index]
511 xmin_index:xmax_index, ymin_index:ymax_index]
512 noise[channel] = hildebrand_sekhon(daux, self.nIncohInt)
512 noise[channel] = hildebrand_sekhon(daux, self.nIncohInt)
513
513
514 return noise
514 return noise
515
515
516 def getNoise(self, xmin_index=None, xmax_index=None, ymin_index=None, ymax_index=None):
516 def getNoise(self, xmin_index=None, xmax_index=None, ymin_index=None, ymax_index=None):
517
517
518 if self.noise_estimation is not None:
518 if self.noise_estimation is not None:
519 # this was estimated by getNoise Operation defined in jroproc_spectra.py
519 # this was estimated by getNoise Operation defined in jroproc_spectra.py
520 return self.noise_estimation
520 return self.noise_estimation
521 else:
521 else:
522 noise = self.getNoisebyHildebrand(
522 noise = self.getNoisebyHildebrand(
523 xmin_index, xmax_index, ymin_index, ymax_index)
523 xmin_index, xmax_index, ymin_index, ymax_index)
524 return noise
524 return noise
525
525
526 def getFreqRangeTimeResponse(self, extrapoints=0):
526 def getFreqRangeTimeResponse(self, extrapoints=0):
527
527
528 deltafreq = self.getFmaxTimeResponse() / (self.nFFTPoints * self.ippFactor)
528 deltafreq = self.getFmaxTimeResponse() / (self.nFFTPoints * self.ippFactor)
529 freqrange = deltafreq * (numpy.arange(self.nFFTPoints + extrapoints) -self.nFFTPoints / 2.) - deltafreq / 2
529 freqrange = deltafreq * (numpy.arange(self.nFFTPoints + extrapoints) -self.nFFTPoints / 2.) - deltafreq / 2
530
530
531 return freqrange
531 return freqrange
532
532
533 def getAcfRange(self, extrapoints=0):
533 def getAcfRange(self, extrapoints=0):
534
534
535 deltafreq = 10. / (self.getFmax() / (self.nFFTPoints * self.ippFactor))
535 deltafreq = 10. / (self.getFmax() / (self.nFFTPoints * self.ippFactor))
536 freqrange = deltafreq * (numpy.arange(self.nFFTPoints + extrapoints) -self.nFFTPoints / 2.) - deltafreq / 2
536 freqrange = deltafreq * (numpy.arange(self.nFFTPoints + extrapoints) -self.nFFTPoints / 2.) - deltafreq / 2
537
537
538 return freqrange
538 return freqrange
539
539
540 def getFreqRange(self, extrapoints=0):
540 def getFreqRange(self, extrapoints=0):
541
541
542 deltafreq = self.getFmax() / (self.nFFTPoints * self.ippFactor)
542 deltafreq = self.getFmax() / (self.nFFTPoints * self.ippFactor)
543 freqrange = deltafreq * (numpy.arange(self.nFFTPoints + extrapoints) -self.nFFTPoints / 2.) - deltafreq / 2
543 freqrange = deltafreq * (numpy.arange(self.nFFTPoints + extrapoints) -self.nFFTPoints / 2.) - deltafreq / 2
544
544
545 return freqrange
545 return freqrange
546
546
547 def getVelRange(self, extrapoints=0):
547 def getVelRange(self, extrapoints=0):
548
548
549 deltav = self.getVmax() / (self.nFFTPoints * self.ippFactor)
549 deltav = self.getVmax() / (self.nFFTPoints * self.ippFactor)
550 velrange = deltav * (numpy.arange(self.nFFTPoints + extrapoints) - self.nFFTPoints / 2.)
550 velrange = deltav * (numpy.arange(self.nFFTPoints + extrapoints) - self.nFFTPoints / 2.)
551
551
552 if self.nmodes:
552 if self.nmodes:
553 return velrange/self.nmodes
553 return velrange/self.nmodes
554 else:
554 else:
555 return velrange
555 return velrange
556
556
557 def getNPairs(self):
557 def getNPairs(self):
558
558
559 return len(self.pairsList)
559 return len(self.pairsList)
560
560
561 def getPairsIndexList(self):
561 def getPairsIndexList(self):
562
562
563 return list(range(self.nPairs))
563 return list(range(self.nPairs))
564
564
565 def getNormFactor(self):
565 def getNormFactor(self):
566
566
567 pwcode = 1
567 pwcode = 1
568
568
569 if self.flagDecodeData:
569 if self.flagDecodeData:
570 pwcode = numpy.sum(self.code[0]**2)
570 pwcode = numpy.sum(self.code[0]**2)
571 #normFactor = min(self.nFFTPoints,self.nProfiles)*self.nIncohInt*self.nCohInt*pwcode*self.windowOfFilter
571 #normFactor = min(self.nFFTPoints,self.nProfiles)*self.nIncohInt*self.nCohInt*pwcode*self.windowOfFilter
572 normFactor = self.nProfiles * self.nIncohInt * self.nCohInt * pwcode * self.windowOfFilter
572 normFactor = self.nProfiles * self.nIncohInt * self.nCohInt * pwcode * self.windowOfFilter
573
573
574 return normFactor
574 return normFactor
575
575
576 def getFlagCspc(self):
576 def getFlagCspc(self):
577
577
578 if self.data_cspc is None:
578 if self.data_cspc is None:
579 return True
579 return True
580
580
581 return False
581 return False
582
582
583 def getFlagDc(self):
583 def getFlagDc(self):
584
584
585 if self.data_dc is None:
585 if self.data_dc is None:
586 return True
586 return True
587
587
588 return False
588 return False
589
589
590 def getTimeInterval(self):
590 def getTimeInterval(self):
591
591
592 timeInterval = self.ippSeconds * self.nCohInt * self.nIncohInt * self.nProfiles * self.ippFactor
592 timeInterval = self.ippSeconds * self.nCohInt * self.nIncohInt * self.nProfiles * self.ippFactor
593 if self.nmodes:
593 if self.nmodes:
594 return self.nmodes*timeInterval
594 return self.nmodes*timeInterval
595 else:
595 else:
596 return timeInterval
596 return timeInterval
597
597
598 def getPower(self):
598 def getPower(self):
599
599
600 factor = self.normFactor
600 factor = self.normFactor
601 z = self.data_spc / factor
601 z = self.data_spc / factor
602 z = numpy.where(numpy.isfinite(z), z, numpy.NAN)
602 z = numpy.where(numpy.isfinite(z), z, numpy.NAN)
603 avg = numpy.average(z, axis=1)
603 avg = numpy.average(z, axis=1)
604
604
605 return 10 * numpy.log10(avg)
605 return 10 * numpy.log10(avg)
606
606
607 def getCoherence(self, pairsList=None, phase=False):
607 def getCoherence(self, pairsList=None, phase=False):
608
608
609 z = []
609 z = []
610 if pairsList is None:
610 if pairsList is None:
611 pairsIndexList = self.pairsIndexList
611 pairsIndexList = self.pairsIndexList
612 else:
612 else:
613 pairsIndexList = []
613 pairsIndexList = []
614 for pair in pairsList:
614 for pair in pairsList:
615 if pair not in self.pairsList:
615 if pair not in self.pairsList:
616 raise ValueError("Pair %s is not in dataOut.pairsList" % (
616 raise ValueError("Pair %s is not in dataOut.pairsList" % (
617 pair))
617 pair))
618 pairsIndexList.append(self.pairsList.index(pair))
618 pairsIndexList.append(self.pairsList.index(pair))
619 for i in range(len(pairsIndexList)):
619 for i in range(len(pairsIndexList)):
620 pair = self.pairsList[pairsIndexList[i]]
620 pair = self.pairsList[pairsIndexList[i]]
621 ccf = numpy.average(self.data_cspc[pairsIndexList[i], :, :], axis=0)
621 ccf = numpy.average(self.data_cspc[pairsIndexList[i], :, :], axis=0)
622 powa = numpy.average(self.data_spc[pair[0], :, :], axis=0)
622 powa = numpy.average(self.data_spc[pair[0], :, :], axis=0)
623 powb = numpy.average(self.data_spc[pair[1], :, :], axis=0)
623 powb = numpy.average(self.data_spc[pair[1], :, :], axis=0)
624 avgcoherenceComplex = ccf / numpy.sqrt(powa * powb)
624 avgcoherenceComplex = ccf / numpy.sqrt(powa * powb)
625 if phase:
625 if phase:
626 data = numpy.arctan2(avgcoherenceComplex.imag,
626 data = numpy.arctan2(avgcoherenceComplex.imag,
627 avgcoherenceComplex.real) * 180 / numpy.pi
627 avgcoherenceComplex.real) * 180 / numpy.pi
628 else:
628 else:
629 data = numpy.abs(avgcoherenceComplex)
629 data = numpy.abs(avgcoherenceComplex)
630
630
631 z.append(data)
631 z.append(data)
632
632
633 return numpy.array(z)
633 return numpy.array(z)
634
634
635 def setValue(self, value):
635 def setValue(self, value):
636
636
637 print("This property should not be initialized")
637 print("This property should not be initialized")
638
638
639 return
639 return
640
640
641 nPairs = property(getNPairs, setValue, "I'm the 'nPairs' property.")
641 nPairs = property(getNPairs, setValue, "I'm the 'nPairs' property.")
642 pairsIndexList = property(
642 pairsIndexList = property(
643 getPairsIndexList, setValue, "I'm the 'pairsIndexList' property.")
643 getPairsIndexList, setValue, "I'm the 'pairsIndexList' property.")
644 normFactor = property(getNormFactor, setValue,
644 normFactor = property(getNormFactor, setValue,
645 "I'm the 'getNormFactor' property.")
645 "I'm the 'getNormFactor' property.")
646 flag_cspc = property(getFlagCspc, setValue)
646 flag_cspc = property(getFlagCspc, setValue)
647 flag_dc = property(getFlagDc, setValue)
647 flag_dc = property(getFlagDc, setValue)
648 noise = property(getNoise, setValue, "I'm the 'nHeights' property.")
648 noise = property(getNoise, setValue, "I'm the 'nHeights' property.")
649 timeInterval = property(getTimeInterval, setValue,
649 timeInterval = property(getTimeInterval, setValue,
650 "I'm the 'timeInterval' property")
650 "I'm the 'timeInterval' property")
651
651
652
652
653 class SpectraHeis(Spectra):
653 class SpectraHeis(Spectra):
654
654
655 data_spc = None
655 data_spc = None
656 data_cspc = None
656 data_cspc = None
657 data_dc = None
657 data_dc = None
658 nFFTPoints = None
658 nFFTPoints = None
659 # nPairs = None
659 # nPairs = None
660 pairsList = None
660 pairsList = None
661 nCohInt = None
661 nCohInt = None
662 nIncohInt = None
662 nIncohInt = None
663
663
664 def __init__(self):
664 def __init__(self):
665
665
666 self.radarControllerHeaderObj = RadarControllerHeader()
666 self.radarControllerHeaderObj = RadarControllerHeader()
667
667
668 self.systemHeaderObj = SystemHeader()
668 self.systemHeaderObj = SystemHeader()
669
669
670 self.type = "SpectraHeis"
670 self.type = "SpectraHeis"
671
671
672 # self.dtype = None
672 # self.dtype = None
673
673
674 # self.nChannels = 0
674 # self.nChannels = 0
675
675
676 # self.nHeights = 0
676 # self.nHeights = 0
677
677
678 self.nProfiles = None
678 self.nProfiles = None
679
679
680 self.heightList = None
680 self.heightList = None
681
681
682 self.channelList = None
682 self.channelList = None
683
683
684 # self.channelIndexList = None
684 # self.channelIndexList = None
685
685
686 self.flagNoData = True
686 self.flagNoData = True
687
687
688 self.flagDiscontinuousBlock = False
688 self.flagDiscontinuousBlock = False
689
689
690 # self.nPairs = 0
690 # self.nPairs = 0
691
691
692 self.utctime = None
692 self.utctime = None
693
693
694 self.blocksize = None
694 self.blocksize = None
695
695
696 self.profileIndex = 0
696 self.profileIndex = 0
697
697
698 self.nCohInt = 1
698 self.nCohInt = 1
699
699
700 self.nIncohInt = 1
700 self.nIncohInt = 1
701
701
702 def getNormFactor(self):
702 def getNormFactor(self):
703 pwcode = 1
703 pwcode = 1
704 if self.flagDecodeData:
704 if self.flagDecodeData:
705 pwcode = numpy.sum(self.code[0]**2)
705 pwcode = numpy.sum(self.code[0]**2)
706
706
707 normFactor = self.nIncohInt * self.nCohInt * pwcode
707 normFactor = self.nIncohInt * self.nCohInt * pwcode
708
708
709 return normFactor
709 return normFactor
710
710
711 def getTimeInterval(self):
711 def getTimeInterval(self):
712
712
713 timeInterval = self.ippSeconds * self.nCohInt * self.nIncohInt
713 timeInterval = self.ippSeconds * self.nCohInt * self.nIncohInt
714
714
715 return timeInterval
715 return timeInterval
716
716
717 normFactor = property(getNormFactor, "I'm the 'getNormFactor' property.")
717 normFactor = property(getNormFactor, "I'm the 'getNormFactor' property.")
718 timeInterval = property(getTimeInterval, "I'm the 'timeInterval' property")
718 timeInterval = property(getTimeInterval, "I'm the 'timeInterval' property")
719
719
720
720
721 class Fits(JROData):
721 class Fits(JROData):
722
722
723 heightList = None
723 heightList = None
724 channelList = None
724 channelList = None
725 flagNoData = True
725 flagNoData = True
726 flagDiscontinuousBlock = False
726 flagDiscontinuousBlock = False
727 useLocalTime = False
727 useLocalTime = False
728 utctime = None
728 utctime = None
729 timeZone = None
729 timeZone = None
730 # ippSeconds = None
730 # ippSeconds = None
731 # timeInterval = None
731 # timeInterval = None
732 nCohInt = None
732 nCohInt = None
733 nIncohInt = None
733 nIncohInt = None
734 noise = None
734 noise = None
735 windowOfFilter = 1
735 windowOfFilter = 1
736 # Speed of ligth
736 # Speed of ligth
737 C = 3e8
737 C = 3e8
738 frequency = 49.92e6
738 frequency = 49.92e6
739 realtime = False
739 realtime = False
740
740
741 def __init__(self):
741 def __init__(self):
742
742
743 self.type = "Fits"
743 self.type = "Fits"
744
744
745 self.nProfiles = None
745 self.nProfiles = None
746
746
747 self.heightList = None
747 self.heightList = None
748
748
749 self.channelList = None
749 self.channelList = None
750
750
751 # self.channelIndexList = None
751 # self.channelIndexList = None
752
752
753 self.flagNoData = True
753 self.flagNoData = True
754
754
755 self.utctime = None
755 self.utctime = None
756
756
757 self.nCohInt = 1
757 self.nCohInt = 1
758
758
759 self.nIncohInt = 1
759 self.nIncohInt = 1
760
760
761 self.useLocalTime = True
761 self.useLocalTime = True
762
762
763 self.profileIndex = 0
763 self.profileIndex = 0
764
764
765 # self.utctime = None
765 # self.utctime = None
766 # self.timeZone = None
766 # self.timeZone = None
767 # self.ltctime = None
767 # self.ltctime = None
768 # self.timeInterval = None
768 # self.timeInterval = None
769 # self.header = None
769 # self.header = None
770 # self.data_header = None
770 # self.data_header = None
771 # self.data = None
771 # self.data = None
772 # self.datatime = None
772 # self.datatime = None
773 # self.flagNoData = False
773 # self.flagNoData = False
774 # self.expName = ''
774 # self.expName = ''
775 # self.nChannels = None
775 # self.nChannels = None
776 # self.nSamples = None
776 # self.nSamples = None
777 # self.dataBlocksPerFile = None
777 # self.dataBlocksPerFile = None
778 # self.comments = ''
778 # self.comments = ''
779 #
779 #
780
780
781 def getltctime(self):
781 def getltctime(self):
782
782
783 if self.useLocalTime:
783 if self.useLocalTime:
784 return self.utctime - self.timeZone * 60
784 return self.utctime - self.timeZone * 60
785
785
786 return self.utctime
786 return self.utctime
787
787
788 def getDatatime(self):
788 def getDatatime(self):
789
789
790 datatime = datetime.datetime.utcfromtimestamp(self.ltctime)
790 datatime = datetime.datetime.utcfromtimestamp(self.ltctime)
791 return datatime
791 return datatime
792
792
793 def getTimeRange(self):
793 def getTimeRange(self):
794
794
795 datatime = []
795 datatime = []
796
796
797 datatime.append(self.ltctime)
797 datatime.append(self.ltctime)
798 datatime.append(self.ltctime + self.timeInterval)
798 datatime.append(self.ltctime + self.timeInterval)
799
799
800 datatime = numpy.array(datatime)
800 datatime = numpy.array(datatime)
801
801
802 return datatime
802 return datatime
803
803
804 def getHeiRange(self):
804 def getHeiRange(self):
805
805
806 heis = self.heightList
806 heis = self.heightList
807
807
808 return heis
808 return heis
809
809
810 def getNHeights(self):
810 def getNHeights(self):
811
811
812 return len(self.heightList)
812 return len(self.heightList)
813
813
814 def getNChannels(self):
814 def getNChannels(self):
815
815
816 return len(self.channelList)
816 return len(self.channelList)
817
817
818 def getChannelIndexList(self):
818 def getChannelIndexList(self):
819
819
820 return list(range(self.nChannels))
820 return list(range(self.nChannels))
821
821
822 def getNoise(self, type=1):
822 def getNoise(self, type=1):
823
823
824 #noise = numpy.zeros(self.nChannels)
824 #noise = numpy.zeros(self.nChannels)
825
825
826 if type == 1:
826 if type == 1:
827 noise = self.getNoisebyHildebrand()
827 noise = self.getNoisebyHildebrand()
828
828
829 if type == 2:
829 if type == 2:
830 noise = self.getNoisebySort()
830 noise = self.getNoisebySort()
831
831
832 if type == 3:
832 if type == 3:
833 noise = self.getNoisebyWindow()
833 noise = self.getNoisebyWindow()
834
834
835 return noise
835 return noise
836
836
837 def getTimeInterval(self):
837 def getTimeInterval(self):
838
838
839 timeInterval = self.ippSeconds * self.nCohInt * self.nIncohInt
839 timeInterval = self.ippSeconds * self.nCohInt * self.nIncohInt
840
840
841 return timeInterval
841 return timeInterval
842
842
843 def get_ippSeconds(self):
843 def get_ippSeconds(self):
844 '''
844 '''
845 '''
845 '''
846 return self.ipp_sec
846 return self.ipp_sec
847
847
848
848
849 datatime = property(getDatatime, "I'm the 'datatime' property")
849 datatime = property(getDatatime, "I'm the 'datatime' property")
850 nHeights = property(getNHeights, "I'm the 'nHeights' property.")
850 nHeights = property(getNHeights, "I'm the 'nHeights' property.")
851 nChannels = property(getNChannels, "I'm the 'nChannel' property.")
851 nChannels = property(getNChannels, "I'm the 'nChannel' property.")
852 channelIndexList = property(
852 channelIndexList = property(
853 getChannelIndexList, "I'm the 'channelIndexList' property.")
853 getChannelIndexList, "I'm the 'channelIndexList' property.")
854 noise = property(getNoise, "I'm the 'nHeights' property.")
854 noise = property(getNoise, "I'm the 'nHeights' property.")
855
855
856 ltctime = property(getltctime, "I'm the 'ltctime' property")
856 ltctime = property(getltctime, "I'm the 'ltctime' property")
857 timeInterval = property(getTimeInterval, "I'm the 'timeInterval' property")
857 timeInterval = property(getTimeInterval, "I'm the 'timeInterval' property")
858 ippSeconds = property(get_ippSeconds, '')
858 ippSeconds = property(get_ippSeconds, '')
859
859
860 class Correlation(JROData):
860 class Correlation(JROData):
861
861
862 noise = None
862 noise = None
863 SNR = None
863 SNR = None
864 #--------------------------------------------------
864 #--------------------------------------------------
865 mode = None
865 mode = None
866 split = False
866 split = False
867 data_cf = None
867 data_cf = None
868 lags = None
868 lags = None
869 lagRange = None
869 lagRange = None
870 pairsList = None
870 pairsList = None
871 normFactor = None
871 normFactor = None
872 #--------------------------------------------------
872 #--------------------------------------------------
873 # calculateVelocity = None
873 # calculateVelocity = None
874 nLags = None
874 nLags = None
875 nPairs = None
875 nPairs = None
876 nAvg = None
876 nAvg = None
877
877
878 def __init__(self):
878 def __init__(self):
879 '''
879 '''
880 Constructor
880 Constructor
881 '''
881 '''
882 self.radarControllerHeaderObj = RadarControllerHeader()
882 self.radarControllerHeaderObj = RadarControllerHeader()
883
883
884 self.systemHeaderObj = SystemHeader()
884 self.systemHeaderObj = SystemHeader()
885
885
886 self.type = "Correlation"
886 self.type = "Correlation"
887
887
888 self.data = None
888 self.data = None
889
889
890 self.dtype = None
890 self.dtype = None
891
891
892 self.nProfiles = None
892 self.nProfiles = None
893
893
894 self.heightList = None
894 self.heightList = None
895
895
896 self.channelList = None
896 self.channelList = None
897
897
898 self.flagNoData = True
898 self.flagNoData = True
899
899
900 self.flagDiscontinuousBlock = False
900 self.flagDiscontinuousBlock = False
901
901
902 self.utctime = None
902 self.utctime = None
903
903
904 self.timeZone = None
904 self.timeZone = None
905
905
906 self.dstFlag = None
906 self.dstFlag = None
907
907
908 self.errorCount = None
908 self.errorCount = None
909
909
910 self.blocksize = None
910 self.blocksize = None
911
911
912 self.flagDecodeData = False # asumo q la data no esta decodificada
912 self.flagDecodeData = False # asumo q la data no esta decodificada
913
913
914 self.flagDeflipData = False # asumo q la data no esta sin flip
914 self.flagDeflipData = False # asumo q la data no esta sin flip
915
915
916 self.pairsList = None
916 self.pairsList = None
917
917
918 self.nPoints = None
918 self.nPoints = None
919
919
920 def getPairsList(self):
920 def getPairsList(self):
921
921
922 return self.pairsList
922 return self.pairsList
923
923
924 def getNoise(self, mode=2):
924 def getNoise(self, mode=2):
925
925
926 indR = numpy.where(self.lagR == 0)[0][0]
926 indR = numpy.where(self.lagR == 0)[0][0]
927 indT = numpy.where(self.lagT == 0)[0][0]
927 indT = numpy.where(self.lagT == 0)[0][0]
928
928
929 jspectra0 = self.data_corr[:, :, indR, :]
929 jspectra0 = self.data_corr[:, :, indR, :]
930 jspectra = copy.copy(jspectra0)
930 jspectra = copy.copy(jspectra0)
931
931
932 num_chan = jspectra.shape[0]
932 num_chan = jspectra.shape[0]
933 num_hei = jspectra.shape[2]
933 num_hei = jspectra.shape[2]
934
934
935 freq_dc = jspectra.shape[1] / 2
935 freq_dc = jspectra.shape[1] / 2
936 ind_vel = numpy.array([-2, -1, 1, 2]) + freq_dc
936 ind_vel = numpy.array([-2, -1, 1, 2]) + freq_dc
937
937
938 if ind_vel[0] < 0:
938 if ind_vel[0] < 0:
939 ind_vel[list(range(0, 1))] = ind_vel[list(
939 ind_vel[list(range(0, 1))] = ind_vel[list(
940 range(0, 1))] + self.num_prof
940 range(0, 1))] + self.num_prof
941
941
942 if mode == 1:
942 if mode == 1:
943 jspectra[:, freq_dc, :] = (
943 jspectra[:, freq_dc, :] = (
944 jspectra[:, ind_vel[1], :] + jspectra[:, ind_vel[2], :]) / 2 # CORRECCION
944 jspectra[:, ind_vel[1], :] + jspectra[:, ind_vel[2], :]) / 2 # CORRECCION
945
945
946 if mode == 2:
946 if mode == 2:
947
947
948 vel = numpy.array([-2, -1, 1, 2])
948 vel = numpy.array([-2, -1, 1, 2])
949 xx = numpy.zeros([4, 4])
949 xx = numpy.zeros([4, 4])
950
950
951 for fil in range(4):
951 for fil in range(4):
952 xx[fil, :] = vel[fil]**numpy.asarray(list(range(4)))
952 xx[fil, :] = vel[fil]**numpy.asarray(list(range(4)))
953
953
954 xx_inv = numpy.linalg.inv(xx)
954 xx_inv = numpy.linalg.inv(xx)
955 xx_aux = xx_inv[0, :]
955 xx_aux = xx_inv[0, :]
956
956
957 for ich in range(num_chan):
957 for ich in range(num_chan):
958 yy = jspectra[ich, ind_vel, :]
958 yy = jspectra[ich, ind_vel, :]
959 jspectra[ich, freq_dc, :] = numpy.dot(xx_aux, yy)
959 jspectra[ich, freq_dc, :] = numpy.dot(xx_aux, yy)
960
960
961 junkid = jspectra[ich, freq_dc, :] <= 0
961 junkid = jspectra[ich, freq_dc, :] <= 0
962 cjunkid = sum(junkid)
962 cjunkid = sum(junkid)
963
963
964 if cjunkid.any():
964 if cjunkid.any():
965 jspectra[ich, freq_dc, junkid.nonzero()] = (
965 jspectra[ich, freq_dc, junkid.nonzero()] = (
966 jspectra[ich, ind_vel[1], junkid] + jspectra[ich, ind_vel[2], junkid]) / 2
966 jspectra[ich, ind_vel[1], junkid] + jspectra[ich, ind_vel[2], junkid]) / 2
967
967
968 noise = jspectra0[:, freq_dc, :] - jspectra[:, freq_dc, :]
968 noise = jspectra0[:, freq_dc, :] - jspectra[:, freq_dc, :]
969
969
970 return noise
970 return noise
971
971
972 def getTimeInterval(self):
972 def getTimeInterval(self):
973
973
974 timeInterval = self.ippSeconds * self.nCohInt * self.nProfiles
974 timeInterval = self.ippSeconds * self.nCohInt * self.nProfiles
975
975
976 return timeInterval
976 return timeInterval
977
977
978 def splitFunctions(self):
978 def splitFunctions(self):
979
979
980 pairsList = self.pairsList
980 pairsList = self.pairsList
981 ccf_pairs = []
981 ccf_pairs = []
982 acf_pairs = []
982 acf_pairs = []
983 ccf_ind = []
983 ccf_ind = []
984 acf_ind = []
984 acf_ind = []
985 for l in range(len(pairsList)):
985 for l in range(len(pairsList)):
986 chan0 = pairsList[l][0]
986 chan0 = pairsList[l][0]
987 chan1 = pairsList[l][1]
987 chan1 = pairsList[l][1]
988
988
989 # Obteniendo pares de Autocorrelacion
989 # Obteniendo pares de Autocorrelacion
990 if chan0 == chan1:
990 if chan0 == chan1:
991 acf_pairs.append(chan0)
991 acf_pairs.append(chan0)
992 acf_ind.append(l)
992 acf_ind.append(l)
993 else:
993 else:
994 ccf_pairs.append(pairsList[l])
994 ccf_pairs.append(pairsList[l])
995 ccf_ind.append(l)
995 ccf_ind.append(l)
996
996
997 data_acf = self.data_cf[acf_ind]
997 data_acf = self.data_cf[acf_ind]
998 data_ccf = self.data_cf[ccf_ind]
998 data_ccf = self.data_cf[ccf_ind]
999
999
1000 return acf_ind, ccf_ind, acf_pairs, ccf_pairs, data_acf, data_ccf
1000 return acf_ind, ccf_ind, acf_pairs, ccf_pairs, data_acf, data_ccf
1001
1001
1002 def getNormFactor(self):
1002 def getNormFactor(self):
1003 acf_ind, ccf_ind, acf_pairs, ccf_pairs, data_acf, data_ccf = self.splitFunctions()
1003 acf_ind, ccf_ind, acf_pairs, ccf_pairs, data_acf, data_ccf = self.splitFunctions()
1004 acf_pairs = numpy.array(acf_pairs)
1004 acf_pairs = numpy.array(acf_pairs)
1005 normFactor = numpy.zeros((self.nPairs, self.nHeights))
1005 normFactor = numpy.zeros((self.nPairs, self.nHeights))
1006
1006
1007 for p in range(self.nPairs):
1007 for p in range(self.nPairs):
1008 pair = self.pairsList[p]
1008 pair = self.pairsList[p]
1009
1009
1010 ch0 = pair[0]
1010 ch0 = pair[0]
1011 ch1 = pair[1]
1011 ch1 = pair[1]
1012
1012
1013 ch0_max = numpy.max(data_acf[acf_pairs == ch0, :, :], axis=1)
1013 ch0_max = numpy.max(data_acf[acf_pairs == ch0, :, :], axis=1)
1014 ch1_max = numpy.max(data_acf[acf_pairs == ch1, :, :], axis=1)
1014 ch1_max = numpy.max(data_acf[acf_pairs == ch1, :, :], axis=1)
1015 normFactor[p, :] = numpy.sqrt(ch0_max * ch1_max)
1015 normFactor[p, :] = numpy.sqrt(ch0_max * ch1_max)
1016
1016
1017 return normFactor
1017 return normFactor
1018
1018
1019 timeInterval = property(getTimeInterval, "I'm the 'timeInterval' property")
1019 timeInterval = property(getTimeInterval, "I'm the 'timeInterval' property")
1020 normFactor = property(getNormFactor, "I'm the 'normFactor property'")
1020 normFactor = property(getNormFactor, "I'm the 'normFactor property'")
1021
1021
1022
1022
1023 class Parameters(Spectra):
1023 class Parameters(Spectra):
1024
1024
1025 experimentInfo = None # Information about the experiment
1025 experimentInfo = None # Information about the experiment
1026 # Information from previous data
1026 # Information from previous data
1027 inputUnit = None # Type of data to be processed
1027 inputUnit = None # Type of data to be processed
1028 operation = None # Type of operation to parametrize
1028 operation = None # Type of operation to parametrize
1029 # normFactor = None #Normalization Factor
1029 # normFactor = None #Normalization Factor
1030 groupList = None # List of Pairs, Groups, etc
1030 groupList = None # List of Pairs, Groups, etc
1031 # Parameters
1031 # Parameters
1032 data_param = None # Parameters obtained
1032 data_param = None # Parameters obtained
1033 data_pre = None # Data Pre Parametrization
1033 data_pre = None # Data Pre Parametrization
1034 data_SNR = None # Signal to Noise Ratio
1034 data_SNR = None # Signal to Noise Ratio
1035 # heightRange = None #Heights
1035 # heightRange = None #Heights
1036 abscissaList = None # Abscissa, can be velocities, lags or time
1036 abscissaList = None # Abscissa, can be velocities, lags or time
1037 # noise = None #Noise Potency
1037 # noise = None #Noise Potency
1038 utctimeInit = None # Initial UTC time
1038 utctimeInit = None # Initial UTC time
1039 paramInterval = None # Time interval to calculate Parameters in seconds
1039 paramInterval = None # Time interval to calculate Parameters in seconds
1040 useLocalTime = True
1040 useLocalTime = True
1041 # Fitting
1041 # Fitting
1042 data_error = None # Error of the estimation
1042 data_error = None # Error of the estimation
1043 constants = None
1043 constants = None
1044 library = None
1044 library = None
1045 # Output signal
1045 # Output signal
1046 outputInterval = None # Time interval to calculate output signal in seconds
1046 outputInterval = None # Time interval to calculate output signal in seconds
1047 data_output = None # Out signal
1047 data_output = None # Out signal
1048 nAvg = None
1048 nAvg = None
1049 noise_estimation = None
1049 noise_estimation = None
1050 GauSPC = None # Fit gaussian SPC
1050 GauSPC = None # Fit gaussian SPC
1051
1051
1052 def __init__(self):
1052 def __init__(self):
1053 '''
1053 '''
1054 Constructor
1054 Constructor
1055 '''
1055 '''
1056 self.radarControllerHeaderObj = RadarControllerHeader()
1056 self.radarControllerHeaderObj = RadarControllerHeader()
1057
1057
1058 self.systemHeaderObj = SystemHeader()
1058 self.systemHeaderObj = SystemHeader()
1059
1059
1060 self.type = "Parameters"
1060 self.type = "Parameters"
1061
1061
1062 def getTimeRange1(self, interval):
1062 def getTimeRange1(self, interval):
1063
1063
1064 datatime = []
1064 datatime = []
1065
1065
1066 if self.useLocalTime:
1066 if self.useLocalTime:
1067 time1 = self.utctimeInit - self.timeZone * 60
1067 time1 = self.utctimeInit - self.timeZone * 60
1068 else:
1068 else:
1069 time1 = self.utctimeInit
1069 time1 = self.utctimeInit
1070
1070
1071 datatime.append(time1)
1071 datatime.append(time1)
1072 datatime.append(time1 + interval)
1072 datatime.append(time1 + interval)
1073 datatime = numpy.array(datatime)
1073 datatime = numpy.array(datatime)
1074
1074
1075 return datatime
1075 return datatime
1076
1076
1077 def getTimeInterval(self):
1077 def getTimeInterval(self):
1078
1078
1079 if hasattr(self, 'timeInterval1'):
1079 if hasattr(self, 'timeInterval1'):
1080 return self.timeInterval1
1080 return self.timeInterval1
1081 else:
1081 else:
1082 return self.paramInterval
1082 return self.paramInterval
1083
1083
1084 def setValue(self, value):
1084 def setValue(self, value):
1085
1085
1086 print("This property should not be initialized")
1086 print("This property should not be initialized")
1087
1087
1088 return
1088 return
1089
1089
1090 def getNoise(self):
1090 def getNoise(self):
1091
1091
1092 return self.spc_noise
1092 return self.spc_noise
1093
1093
1094 timeInterval = property(getTimeInterval)
1094 timeInterval = property(getTimeInterval)
1095 noise = property(getNoise, setValue, "I'm the 'Noise' property.")
1095 noise = property(getNoise, setValue, "I'm the 'Noise' property.")
1096
1096
1097
1097
1098 class PlotterData(object):
1098 class PlotterData(object):
1099 '''
1099 '''
1100 Object to hold data to be plotted
1100 Object to hold data to be plotted
1101 '''
1101 '''
1102
1102
1103 MAXNUMX = 100
1103 MAXNUMX = 100
1104 MAXNUMY = 100
1104 MAXNUMY = 100
1105
1105
1106 def __init__(self, code, throttle_value, exp_code, buffering=True, snr=False):
1106 def __init__(self, code, throttle_value, exp_code, buffering=True, snr=False):
1107
1107
1108 self.key = code
1108 self.key = code
1109 self.throttle = throttle_value
1109 self.throttle = throttle_value
1110 self.exp_code = exp_code
1110 self.exp_code = exp_code
1111 self.buffering = buffering
1111 self.buffering = buffering
1112 self.ready = False
1112 self.ready = False
1113 self.localtime = False
1113 self.localtime = False
1114 self.data = {}
1114 self.data = {}
1115 self.meta = {}
1115 self.meta = {}
1116 self.__times = []
1116 self.__times = []
1117 self.__heights = []
1117 self.__heights = []
1118
1118
1119 if 'snr' in code:
1119 if 'snr' in code:
1120 self.plottypes = ['snr']
1120 self.plottypes = ['snr']
1121 elif code == 'spc':
1121 elif code == 'spc':
1122 self.plottypes = ['spc', 'noise', 'rti']
1122 self.plottypes = ['spc', 'noise', 'rti']
1123 elif code == 'rti':
1123 elif code == 'rti':
1124 self.plottypes = ['noise', 'rti']
1124 self.plottypes = ['noise', 'rti']
1125 else:
1125 else:
1126 self.plottypes = [code]
1126 self.plottypes = [code]
1127
1127
1128 if 'snr' not in self.plottypes and snr:
1128 if 'snr' not in self.plottypes and snr:
1129 self.plottypes.append('snr')
1129 self.plottypes.append('snr')
1130
1130
1131 for plot in self.plottypes:
1131 for plot in self.plottypes:
1132 self.data[plot] = {}
1132 self.data[plot] = {}
1133
1133
1134 def __str__(self):
1134 def __str__(self):
1135 dum = ['{}{}'.format(key, self.shape(key)) for key in self.data]
1135 dum = ['{}{}'.format(key, self.shape(key)) for key in self.data]
1136 return 'Data[{}][{}]'.format(';'.join(dum), len(self.__times))
1136 return 'Data[{}][{}]'.format(';'.join(dum), len(self.__times))
1137
1137
1138 def __len__(self):
1138 def __len__(self):
1139 return len(self.__times)
1139 return len(self.__times)
1140
1140
1141 def __getitem__(self, key):
1141 def __getitem__(self, key):
1142
1142
1143 if key not in self.data:
1143 if key not in self.data:
1144 raise KeyError(log.error('Missing key: {}'.format(key)))
1144 raise KeyError(log.error('Missing key: {}'.format(key)))
1145 if 'spc' in key or not self.buffering:
1145 if 'spc' in key or not self.buffering:
1146 ret = self.data[key]
1146 ret = self.data[key]
1147 elif 'scope' in key:
1147 elif 'scope' in key:
1148 ret = numpy.array(self.data[key][float(self.tm)])
1148 ret = numpy.array(self.data[key][float(self.tm)])
1149 else:
1149 else:
1150 ret = numpy.array([self.data[key][x] for x in self.times])
1150 ret = numpy.array([self.data[key][x] for x in self.times])
1151 if ret.ndim > 1:
1151 if ret.ndim > 1:
1152 ret = numpy.swapaxes(ret, 0, 1)
1152 ret = numpy.swapaxes(ret, 0, 1)
1153 return ret
1153 return ret
1154
1154
1155 def __contains__(self, key):
1155 def __contains__(self, key):
1156 return key in self.data
1156 return key in self.data
1157
1157
1158 def setup(self):
1158 def setup(self):
1159 '''
1159 '''
1160 Configure object
1160 Configure object
1161 '''
1161 '''
1162
1162
1163 self.type = ''
1163 self.type = ''
1164 self.ready = False
1164 self.ready = False
1165 self.data = {}
1165 self.data = {}
1166 self.__times = []
1166 self.__times = []
1167 self.__heights = []
1167 self.__heights = []
1168 self.__all_heights = set()
1168 self.__all_heights = set()
1169 for plot in self.plottypes:
1169 for plot in self.plottypes:
1170 if 'snr' in plot:
1170 if 'snr' in plot:
1171 plot = 'snr'
1171 plot = 'snr'
1172 elif 'spc_moments' == plot:
1172 elif 'spc_moments' == plot:
1173 plot = 'moments'
1173 plot = 'moments'
1174 self.data[plot] = {}
1174 self.data[plot] = {}
1175
1175
1176 if 'spc' in self.data or 'rti' in self.data or 'cspc' in self.data or 'moments' in self.data:
1176 if 'spc' in self.data or 'rti' in self.data or 'cspc' in self.data or 'moments' in self.data:
1177 self.data['noise'] = {}
1177 self.data['noise'] = {}
1178 self.data['rti'] = {}
1178 self.data['rti'] = {}
1179 if 'noise' not in self.plottypes:
1179 if 'noise' not in self.plottypes:
1180 self.plottypes.append('noise')
1180 self.plottypes.append('noise')
1181 if 'rti' not in self.plottypes:
1181 if 'rti' not in self.plottypes:
1182 self.plottypes.append('rti')
1182 self.plottypes.append('rti')
1183
1183
1184 def shape(self, key):
1184 def shape(self, key):
1185 '''
1185 '''
1186 Get the shape of the one-element data for the given key
1186 Get the shape of the one-element data for the given key
1187 '''
1187 '''
1188
1188
1189 if len(self.data[key]):
1189 if len(self.data[key]):
1190 if 'spc' in key or not self.buffering:
1190 if 'spc' in key or not self.buffering:
1191 return self.data[key].shape
1191 return self.data[key].shape
1192 return self.data[key][self.__times[0]].shape
1192 return self.data[key][self.__times[0]].shape
1193 return (0,)
1193 return (0,)
1194
1194
1195 def update(self, dataOut, tm):
1195 def update(self, dataOut, tm):
1196 '''
1196 '''
1197 Update data object with new dataOut
1197 Update data object with new dataOut
1198 '''
1198 '''
1199
1199
1200 if tm in self.__times:
1200 if tm in self.__times:
1201 return
1201 return
1202 self.profileIndex = dataOut.profileIndex
1202 self.profileIndex = dataOut.profileIndex
1203 self.tm = tm
1203 self.tm = tm
1204 self.type = dataOut.type
1204 self.type = dataOut.type
1205 self.parameters = getattr(dataOut, 'parameters', [])
1205 self.parameters = getattr(dataOut, 'parameters', [])
1206
1206
1207 if hasattr(dataOut, 'meta'):
1207 if hasattr(dataOut, 'meta'):
1208 self.meta.update(dataOut.meta)
1208 self.meta.update(dataOut.meta)
1209
1209
1210 self.pairs = dataOut.pairsList
1210 self.pairs = dataOut.pairsList
1211 self.interval = dataOut.getTimeInterval()
1211 self.interval = dataOut.getTimeInterval()
1212 self.localtime = dataOut.useLocalTime
1212 self.localtime = dataOut.useLocalTime
1213 if 'spc' in self.plottypes or 'cspc' in self.plottypes or 'spc_moments' in self.plottypes:
1213 if 'spc' in self.plottypes or 'cspc' in self.plottypes or 'spc_moments' in self.plottypes:
1214 self.xrange = (dataOut.getFreqRange(1)/1000.,
1214 self.xrange = (dataOut.getFreqRange(1)/1000.,
1215 dataOut.getAcfRange(1), dataOut.getVelRange(1))
1215 dataOut.getAcfRange(1), dataOut.getVelRange(1))
1216 self.factor = dataOut.normFactor
1216 self.factor = dataOut.normFactor
1217 self.__heights.append(dataOut.heightList)
1217 self.__heights.append(dataOut.heightList)
1218 self.__all_heights.update(dataOut.heightList)
1218 self.__all_heights.update(dataOut.heightList)
1219 self.__times.append(tm)
1219 self.__times.append(tm)
1220
1220
1221 for plot in self.plottypes:
1221 for plot in self.plottypes:
1222 if plot in ('spc', 'spc_moments'):
1222 if plot in ('spc', 'spc_moments'):
1223 z = dataOut.data_spc/dataOut.normFactor
1223 z = dataOut.data_spc/dataOut.normFactor
1224 buffer = 10*numpy.log10(z)
1224 buffer = 10*numpy.log10(z)
1225 if plot == 'cspc':
1225 if plot == 'cspc':
1226 z = dataOut.data_spc/dataOut.normFactor
1226 z = dataOut.data_spc/dataOut.normFactor
1227 buffer = (dataOut.data_spc, dataOut.data_cspc)
1227 buffer = (dataOut.data_spc, dataOut.data_cspc)
1228 if plot == 'noise':
1228 if plot == 'noise':
1229 buffer = 10*numpy.log10(dataOut.getNoise()/dataOut.normFactor)
1229 buffer = 10*numpy.log10(dataOut.getNoise()/dataOut.normFactor)
1230 if plot == 'rti':
1230 if plot == 'rti':
1231 buffer = dataOut.getPower()
1231 buffer = dataOut.getPower()
1232 if plot == 'snr_db':
1232 if plot == 'snr_db':
1233 buffer = dataOut.data_SNR
1233 buffer = dataOut.data_SNR
1234 if plot == 'snr':
1234 if plot == 'snr':
1235 buffer = 10*numpy.log10(dataOut.data_SNR)
1235 buffer = 10*numpy.log10(dataOut.data_SNR)
1236 if plot == 'dop':
1236 if plot == 'dop':
1237 buffer = dataOut.data_DOP
1237 buffer = dataOut.data_DOP
1238 if plot == 'pow':
1238 if plot == 'pow':
1239 buffer = 10*numpy.log10(dataOut.data_POW)
1239 buffer = 10*numpy.log10(dataOut.data_POW)
1240 if plot == 'width':
1240 if plot == 'width':
1241 buffer = dataOut.data_WIDTH
1241 buffer = dataOut.data_WIDTH
1242 if plot == 'coh':
1242 if plot == 'coh':
1243 buffer = dataOut.getCoherence()
1243 buffer = dataOut.getCoherence()
1244 if plot == 'phase':
1244 if plot == 'phase':
1245 buffer = dataOut.getCoherence(phase=True)
1245 buffer = dataOut.getCoherence(phase=True)
1246 if plot == 'output':
1246 if plot == 'output':
1247 buffer = dataOut.data_output
1247 buffer = dataOut.data_output
1248 if plot == 'param':
1248 if plot == 'param':
1249 buffer = dataOut.data_param
1249 buffer = dataOut.data_param
1250 if plot == 'scope':
1250 if plot == 'scope':
1251 buffer = dataOut.data
1251 buffer = dataOut.data
1252 self.flagDataAsBlock = dataOut.flagDataAsBlock
1252 self.flagDataAsBlock = dataOut.flagDataAsBlock
1253 self.nProfiles = dataOut.nProfiles
1253 self.nProfiles = dataOut.nProfiles
1254
1254
1255 if plot == 'spc':
1255 if plot == 'spc':
1256 self.data['spc'] = buffer
1256 self.data['spc'] = buffer
1257 elif plot == 'cspc':
1257 elif plot == 'cspc':
1258 self.data['spc'] = buffer[0]
1258 self.data['spc'] = buffer[0]
1259 self.data['cspc'] = buffer[1]
1259 self.data['cspc'] = buffer[1]
1260 elif plot == 'spc_moments':
1260 elif plot == 'spc_moments':
1261 self.data['spc'] = buffer
1261 self.data['spc'] = buffer
1262 self.data['moments'][tm] = dataOut.moments
1262 self.data['moments'][tm] = dataOut.moments
1263 else:
1263 else:
1264 if self.buffering:
1264 if self.buffering:
1265 self.data[plot][tm] = buffer
1265 self.data[plot][tm] = buffer
1266 else:
1266 else:
1267 self.data[plot] = buffer
1267 self.data[plot] = buffer
1268
1268
1269 if dataOut.channelList is None:
1269 if dataOut.channelList is None:
1270 self.channels = range(buffer.shape[0])
1270 self.channels = range(buffer.shape[0])
1271 else:
1271 else:
1272 self.channels = dataOut.channelList
1272 self.channels = dataOut.channelList
1273
1273
1274 def normalize_heights(self):
1274 def normalize_heights(self):
1275 '''
1275 '''
1276 Ensure same-dimension of the data for different heighList
1276 Ensure same-dimension of the data for different heighList
1277 '''
1277 '''
1278
1278
1279 H = numpy.array(list(self.__all_heights))
1279 H = numpy.array(list(self.__all_heights))
1280 H.sort()
1280 H.sort()
1281 for key in self.data:
1281 for key in self.data:
1282 shape = self.shape(key)[:-1] + H.shape
1282 shape = self.shape(key)[:-1] + H.shape
1283 for tm, obj in list(self.data[key].items()):
1283 for tm, obj in list(self.data[key].items()):
1284 h = self.__heights[self.__times.index(tm)]
1284 h = self.__heights[self.__times.index(tm)]
1285 if H.size == h.size:
1285 if H.size == h.size:
1286 continue
1286 continue
1287 index = numpy.where(numpy.in1d(H, h))[0]
1287 index = numpy.where(numpy.in1d(H, h))[0]
1288 dummy = numpy.zeros(shape) + numpy.nan
1288 dummy = numpy.zeros(shape) + numpy.nan
1289 if len(shape) == 2:
1289 if len(shape) == 2:
1290 dummy[:, index] = obj
1290 dummy[:, index] = obj
1291 else:
1291 else:
1292 dummy[index] = obj
1292 dummy[index] = obj
1293 self.data[key][tm] = dummy
1293 self.data[key][tm] = dummy
1294
1294
1295 self.__heights = [H for tm in self.__times]
1295 self.__heights = [H for tm in self.__times]
1296
1296
1297 def jsonify(self, plot_name, plot_type, decimate=False):
1297 def jsonify(self, plot_name, plot_type, decimate=False):
1298 '''
1298 '''
1299 Convert data to json
1299 Convert data to json
1300 '''
1300 '''
1301
1301
1302 tm = self.times[-1]
1302 tm = self.times[-1]
1303 dy = int(self.heights.size/self.MAXNUMY) + 1
1303 dy = int(self.heights.size/self.MAXNUMY) + 1
1304 if self.key in ('spc', 'cspc') or not self.buffering:
1304 if self.key in ('spc', 'cspc') or not self.buffering:
1305 dx = int(self.data[self.key].shape[1]/self.MAXNUMX) + 1
1305 dx = int(self.data[self.key].shape[1]/self.MAXNUMX) + 1
1306 data = self.roundFloats(
1306 data = self.roundFloats(
1307 self.data[self.key][::, ::dx, ::dy].tolist())
1307 self.data[self.key][::, ::dx, ::dy].tolist())
1308 else:
1308 else:
1309 data = self.roundFloats(self.data[self.key][tm].tolist())
1309 data = self.roundFloats(self.data[self.key][tm].tolist())
1310 if self.key is 'noise':
1310 if self.key is 'noise':
1311 data = [[x] for x in data]
1311 data = [[x] for x in data]
1312
1312
1313 meta = {}
1313 meta = {}
1314 ret = {
1314 ret = {
1315 'plot': plot_name,
1315 'plot': plot_name,
1316 'code': self.exp_code,
1316 'code': self.exp_code,
1317 'time': float(tm),
1317 'time': float(tm),
1318 'data': data,
1318 'data': data,
1319 }
1319 }
1320 meta['type'] = plot_type
1320 meta['type'] = plot_type
1321 meta['interval'] = float(self.interval)
1321 meta['interval'] = float(self.interval)
1322 meta['localtime'] = self.localtime
1322 meta['localtime'] = self.localtime
1323 meta['yrange'] = self.roundFloats(self.heights[::dy].tolist())
1323 meta['yrange'] = self.roundFloats(self.heights[::dy].tolist())
1324 if 'spc' in self.data or 'cspc' in self.data:
1324 if 'spc' in self.data or 'cspc' in self.data:
1325 meta['xrange'] = self.roundFloats(self.xrange[2][::dx].tolist())
1325 meta['xrange'] = self.roundFloats(self.xrange[2][::dx].tolist())
1326 else:
1326 else:
1327 meta['xrange'] = []
1327 meta['xrange'] = []
1328
1328
1329 meta.update(self.meta)
1329 meta.update(self.meta)
1330 ret['metadata'] = meta
1330 ret['metadata'] = meta
1331 return json.dumps(ret)
1331 return json.dumps(ret)
1332
1332
1333 @property
1333 @property
1334 def times(self):
1334 def times(self):
1335 '''
1335 '''
1336 Return the list of times of the current data
1336 Return the list of times of the current data
1337 '''
1337 '''
1338
1338
1339 ret = numpy.array(self.__times)
1339 ret = numpy.array(self.__times)
1340 ret.sort()
1340 ret.sort()
1341 return ret
1341 return ret
1342
1342
1343 @property
1343 @property
1344 def min_time(self):
1344 def min_time(self):
1345 '''
1345 '''
1346 Return the minimun time value
1346 Return the minimun time value
1347 '''
1347 '''
1348
1348
1349 return self.times[0]
1349 return self.times[0]
1350
1350
1351 @property
1351 @property
1352 def max_time(self):
1352 def max_time(self):
1353 '''
1353 '''
1354 Return the maximun time value
1354 Return the maximun time value
1355 '''
1355 '''
1356
1356
1357 return self.times[-1]
1357 return self.times[-1]
1358
1358
1359 @property
1359 @property
1360 def heights(self):
1360 def heights(self):
1361 '''
1361 '''
1362 Return the list of heights of the current data
1362 Return the list of heights of the current data
1363 '''
1363 '''
1364
1364
1365 return numpy.array(self.__heights[-1])
1365 return numpy.array(self.__heights[-1])
1366
1366
1367 @staticmethod
1367 @staticmethod
1368 def roundFloats(obj):
1368 def roundFloats(obj):
1369 if isinstance(obj, list):
1369 if isinstance(obj, list):
1370 return list(map(PlotterData.roundFloats, obj))
1370 return list(map(PlotterData.roundFloats, obj))
1371 elif isinstance(obj, float):
1371 elif isinstance(obj, float):
1372 return round(obj, 2)
1372 return round(obj, 2)
@@ -1,295 +1,581
1 '''
1 '''
2 Created on Jul 9, 2014
2 Created on Jul 9, 2014
3
3
4 @author: roj-idl71
4 @author: roj-idl71
5 '''
5 '''
6 import os
6 import os
7 import datetime
7 import datetime
8 import numpy
8 import numpy
9 from schainpy.model.proc.jroproc_base import ProcessingUnit, Operation, MPDecorator #YONG
9 from schainpy.model.proc.jroproc_base import ProcessingUnit, Operation, MPDecorator #YONG
10 from schainpy.utils import log
10 from schainpy.utils import log
11 from .figure import Figure
11 from .figure import Figure
12
12
13
13
14 @MPDecorator
14 @MPDecorator
15 class Scope_(Figure):
15 class Scope_(Figure):
16
16
17 isConfig = None
17 isConfig = None
18
18
19 def __init__(self):#, **kwargs): #YONG
19 def __init__(self):#, **kwargs): #YONG
20 Figure.__init__(self)#, **kwargs)
20 Figure.__init__(self)#, **kwargs)
21 self.isConfig = False
21 self.isConfig = False
22 self.WIDTH = 300
22 self.WIDTH = 300
23 self.HEIGHT = 200
23 self.HEIGHT = 200
24 self.counter_imagwr = 0
24 self.counter_imagwr = 0
25
25
26 def getSubplots(self):
26 def getSubplots(self):
27
27
28 nrow = self.nplots
28 nrow = self.nplots
29 ncol = 3
29 ncol = 3
30 return nrow, ncol
30 return nrow, ncol
31
31
32 def setup(self, id, nplots, wintitle, show):
32 def setup(self, id, nplots, wintitle, show):
33
33
34 self.nplots = nplots
34 self.nplots = nplots
35
35
36 self.createFigure(id=id,
36 self.createFigure(id=id,
37 wintitle=wintitle,
37 wintitle=wintitle,
38 show=show)
38 show=show)
39
39
40 nrow,ncol = self.getSubplots()
40 nrow,ncol = self.getSubplots()
41 colspan = 3
41 colspan = 3
42 rowspan = 1
42 rowspan = 1
43
43
44 for i in range(nplots):
44 for i in range(nplots):
45 self.addAxes(nrow, ncol, i, 0, colspan, rowspan)
45 self.addAxes(nrow, ncol, i, 0, colspan, rowspan)
46
46
47 def plot_iq(self, x, y, id, channelIndexList, thisDatetime, wintitle, show, xmin, xmax, ymin, ymax):
47 def plot_iq(self, x, y, id, channelIndexList, thisDatetime, wintitle, show, xmin, xmax, ymin, ymax):
48 yreal = y[channelIndexList,:].real
48 yreal = y[channelIndexList,:].real
49 yimag = y[channelIndexList,:].imag
49 yimag = y[channelIndexList,:].imag
50
50
51 title = wintitle + " Scope: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
51 title = wintitle + " Scope: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
52 xlabel = "Range (Km)"
52 xlabel = "Range (Km)"
53 ylabel = "Intensity - IQ"
53 ylabel = "Intensity - IQ"
54
54
55 if not self.isConfig:
55 if not self.isConfig:
56 nplots = len(channelIndexList)
56 nplots = len(channelIndexList)
57
57
58 self.setup(id=id,
58 self.setup(id=id,
59 nplots=nplots,
59 nplots=nplots,
60 wintitle='',
60 wintitle='',
61 show=show)
61 show=show)
62
62
63 if xmin == None: xmin = numpy.nanmin(x)
63 if xmin == None: xmin = numpy.nanmin(x)
64 if xmax == None: xmax = numpy.nanmax(x)
64 if xmax == None: xmax = numpy.nanmax(x)
65 if ymin == None: ymin = min(numpy.nanmin(yreal),numpy.nanmin(yimag))
65 if ymin == None: ymin = min(numpy.nanmin(yreal),numpy.nanmin(yimag))
66 if ymax == None: ymax = max(numpy.nanmax(yreal),numpy.nanmax(yimag))
66 if ymax == None: ymax = max(numpy.nanmax(yreal),numpy.nanmax(yimag))
67
67
68 self.isConfig = True
68 self.isConfig = True
69
69
70 self.setWinTitle(title)
70 self.setWinTitle(title)
71
71
72 for i in range(len(self.axesList)):
72 for i in range(len(self.axesList)):
73 title = "Channel %d" %(i)
73 title = "Channel %d" %(i)
74 axes = self.axesList[i]
74 axes = self.axesList[i]
75
75
76 axes.pline(x, yreal[i,:],
76 axes.pline(x, yreal[i,:],
77 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax,
77 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax,
78 xlabel=xlabel, ylabel=ylabel, title=title)
78 xlabel=xlabel, ylabel=ylabel, title=title)
79
79
80 axes.addpline(x, yimag[i,:], idline=1, color="red", linestyle="solid", lw=2)
80 axes.addpline(x, yimag[i,:], idline=1, color="red", linestyle="solid", lw=2)
81
81
82 def plot_power(self, x, y, id, channelIndexList, thisDatetime, wintitle, show, xmin, xmax, ymin, ymax):
82 def plot_power(self, x, y, id, channelIndexList, thisDatetime, wintitle, show, xmin, xmax, ymin, ymax):
83 y = y[channelIndexList,:] * numpy.conjugate(y[channelIndexList,:])
83 y = y[channelIndexList,:] * numpy.conjugate(y[channelIndexList,:])
84 yreal = y.real
84 yreal = y.real
85
85
86 title = wintitle + " Scope: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
86 title = wintitle + " Scope: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
87 xlabel = "Range (Km)"
87 xlabel = "Range (Km)"
88 ylabel = "Intensity"
88 ylabel = "Intensity"
89
89
90 if not self.isConfig:
90 if not self.isConfig:
91 nplots = len(channelIndexList)
91 nplots = len(channelIndexList)
92
92
93 self.setup(id=id,
93 self.setup(id=id,
94 nplots=nplots,
94 nplots=nplots,
95 wintitle='',
95 wintitle='',
96 show=show)
96 show=show)
97
97
98 if xmin == None: xmin = numpy.nanmin(x)
98 if xmin == None: xmin = numpy.nanmin(x)
99 if xmax == None: xmax = numpy.nanmax(x)
99 if xmax == None: xmax = numpy.nanmax(x)
100 if ymin == None: ymin = numpy.nanmin(yreal)
100 if ymin == None: ymin = numpy.nanmin(yreal)
101 if ymax == None: ymax = numpy.nanmax(yreal)
101 if ymax == None: ymax = numpy.nanmax(yreal)
102
102
103
103 self.isConfig = True
104 self.isConfig = True
104
105
105 self.setWinTitle(title)
106 self.setWinTitle(title)
106
107
107 for i in range(len(self.axesList)):
108 for i in range(len(self.axesList)):
108 title = "Channel %d" %(i)
109 title = "Channel %d" %(i)
109 axes = self.axesList[i]
110 axes = self.axesList[i]
110 ychannel = yreal[i,:]
111 ychannel = yreal[i,:]
111 axes.pline(x, ychannel,
112 axes.pline(x, ychannel,
112 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax,
113 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax,
113 xlabel=xlabel, ylabel=ylabel, title=title)
114 xlabel=xlabel, ylabel=ylabel, title=title)
114
115
115 def plot_weatherpower(self, x, y, id, channelIndexList, thisDatetime, wintitle, show, xmin, xmax, ymin, ymax):
116 def plot_weatherpower(self, x, y, id, channelIndexList, thisDatetime, wintitle, show, xmin, xmax, ymin, ymax):
116 y = y[channelIndexList,:]
117 yreal = y
118
117
118 #x = x[channelIndexList,:]
119 y = y[channelIndexList,:].real
120 y = 10*numpy.log10(y)
119 title = wintitle + " Scope: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
121 title = wintitle + " Scope: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
120 xlabel = "Range (Km)"
122 xlabel = "Range (Km)"
121 ylabel = "Intensity"
123 ylabel = "Intensity"
122
124
123 if not self.isConfig:
125 if not self.isConfig:
124 nplots = len(channelIndexList)
126 nplots = len(channelIndexList)
125
127
126 self.setup(id=id,
128 self.setup(id=id,
127 nplots=nplots,
129 nplots=nplots,
128 wintitle='',
130 wintitle='',
129 show=show)
131 show=show)
130
132
131 if xmin == None: xmin = numpy.nanmin(x)
133 if xmin == None: xmin = numpy.nanmin(x)
132 if xmax == None: xmax = numpy.nanmax(x)
134 if xmax == None: xmax = numpy.nanmax(x)
133 if ymin == None: ymin = numpy.nanmin(yreal)
135 if ymin == None: ymin = numpy.nanmin(y)
134 if ymax == None: ymax = numpy.nanmax(yreal)
136 if ymax == None: ymax = numpy.nanmax(y)
137 #print (xmin,xmax)
135
138
136 self.isConfig = True
139 self.isConfig = True
137
140
138 self.setWinTitle(title)
141 self.setWinTitle(title)
139
142
140 for i in range(len(self.axesList)):
143 for i in range(len(self.axesList)):
141 title = "Channel %d" %(i)
144 title = "Channel %d" %(i)
142 axes = self.axesList[i]
145 axes = self.axesList[i]
143 ychannel = yreal[i,:]
146 #print(numpy.nanmax(x))
147 ychannel = y[i,:]
148 #ychannel = yreal[i,:]
144 axes.pline(x, ychannel,
149 axes.pline(x, ychannel,
145 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax,
150 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax,
146 xlabel=xlabel, ylabel=ylabel, title=title)
151 xlabel=xlabel, ylabel=ylabel, title=title)
147
152
153 def plot_weathervelocity(self, x, y, id, channelIndexList, thisDatetime, wintitle, show, xmin, xmax, ymin, ymax):
154 #print(channelIndexList)
155 x = x[channelIndexList,:]
156
157 title = wintitle + " Scope: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
158 xlabel = "Velocity (m/s)"
159 ylabel = "Range (Km)"
160
161 if not self.isConfig:
162 nplots = len(channelIndexList)
163
164 self.setup(id=id,
165 nplots=nplots,
166 wintitle='',
167 show=show)
168
169 if xmin == None: xmin = numpy.nanmin(x)
170 if xmax == None: xmax = numpy.nanmax(x)
171 if ymin == None: ymin = numpy.nanmin(y)
172 if ymax == None: ymax = numpy.nanmax(y)
173 print (xmin,xmax)
174
175 self.isConfig = True
176
177 self.setWinTitle(title)
178
179 for i in range(len(self.axesList)):
180 title = "Channel %d" %(i)
181 axes = self.axesList[i]
182 #print(numpy.nanmax(x))
183 xchannel = x[i,:]
184 #ychannel = yreal[i,:]
185 axes.pline(xchannel, y,
186 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax,
187 xlabel=xlabel, ylabel=ylabel, title=title)
148
188
149
189
150 def run(self, dataOut, id, wintitle="", channelList=None,
190 def run(self, dataOut, id, wintitle="", channelList=None,
151 xmin=None, xmax=None, ymin=None, ymax=None, save=False,
191 xmin=None, xmax=None, ymin=None, ymax=None, save=False,
152 figpath='./', figfile=None, show=True, wr_period=1,
192 figpath='./', figfile=None, show=True, wr_period=1,
153 ftp=False, server=None, folder=None, username=None, password=None, type='power', **kwargs):
193 ftp=False, server=None, folder=None, username=None, password=None, type='power', **kwargs):
154
194
155 """
195 """
156
196
157 Input:
197 Input:
158 dataOut :
198 dataOut :
159 id :
199 id :
160 wintitle :
200 wintitle :
161 channelList :
201 channelList :
162 xmin : None,
202 xmin : None,
163 xmax : None,
203 xmax : None,
164 ymin : None,
204 ymin : None,
165 ymax : None,
205 ymax : None,
166 """
206 """
167 if dataOut.flagNoData:
207 if dataOut.flagNoData:
168 return dataOut
208 return dataOut
169
209
170 if channelList == None:
210 if channelList == None:
171 channelIndexList = dataOut.channelIndexList
211 channelIndexList = dataOut.channelIndexList
172 else:
212 else:
173 channelIndexList = []
213 channelIndexList = []
174 for channel in channelList:
214 for channel in channelList:
175 if channel not in dataOut.channelList:
215 if channel not in dataOut.channelList:
176 raise ValueError("Channel %d is not in dataOut.channelList")
216 raise ValueError("Channel %d is not in dataOut.channelList")
177 channelIndexList.append(dataOut.channelList.index(channel))
217 channelIndexList.append(dataOut.channelList.index(channel))
178
218
179 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0])
219 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0])
180 #print("***************** PLOTEO **************************")
220 #print("***************** PLOTEO **************************")
181 #print(dataOut.nProfiles)
221 #print(dataOut.nProfiles)
182 #print(dataOut.heightList.shape)
222 #print(dataOut.heightList.shape)
183 #print(dataOut.data.shape)
223 #print(dataOut.data.shape)
184 if dataOut.flagDataAsBlock:
224 if dataOut.flagDataAsBlock:
185
225
186 for i in range(dataOut.nProfiles):
226 for i in range(dataOut.nProfiles):
187
227
188 wintitle1 = wintitle + " [Profile = %d] " %i
228 wintitle1 = wintitle + " [Profile = %d] " %i
189
229
190 if type == "power":
230 if type == "power":
191 self.plot_power(dataOut.heightList,
231 self.plot_power(dataOut.heightList,
192 dataOut.data[:,i,:],
232 dataOut.data[:,i,:],
193 id,
233 id,
194 channelIndexList,
234 channelIndexList,
195 thisDatetime,
235 thisDatetime,
196 wintitle1,
236 wintitle1,
197 show,
237 show,
198 xmin,
238 xmin,
199 xmax,
239 xmax,
200 ymin,
240 ymin,
201 ymax)
241 ymax)
202
242
203 if type == "weatherpower":
243 if type == "weatherpower":
204 self.plot_weatherpower(dataOut.heightList,
244 self.plot_weatherpower(dataOut.heightList,
205 dataOut.data[:,i,:],
245 dataOut.data[:,i,:],
206 id,
246 id,
207 channelIndexList,
247 channelIndexList,
208 thisDatetime,
248 thisDatetime,
209 wintitle1,
249 wintitle,
210 show,
250 show,
211 xmin,
251 xmin,
212 xmax,
252 xmax,
213 ymin,
253 ymin,
214 ymax)
254 ymax)
215
255
216 if type == "weathervelocity":
256 if type == "weathervelocity":
217 self.plot_weatherpower(dataOut.heightList,
257 self.plot_weathervelocity(dataOut.data_velocity[:,i,:],
218 dataOut.data_velocity[:,i,:],
258 dataOut.heightList,
219 id,
259 id,
220 channelIndexList,
260 channelIndexList,
221 thisDatetime,
261 thisDatetime,
222 wintitle1,
262 wintitle1,
223 show,
263 show,
224 xmin,
264 xmin,
225 xmax,
265 xmax,
226 ymin,
266 ymin,
227 ymax)
267 ymax)
228
268
229 if type == "iq":
269 if type == "iq":
230 self.plot_iq(dataOut.heightList,
270 self.plot_iq(dataOut.heightList,
231 dataOut.data[:,i,:],
271 dataOut.data[:,i,:],
232 id,
272 id,
233 channelIndexList,
273 channelIndexList,
234 thisDatetime,
274 thisDatetime,
235 wintitle1,
275 wintitle1,
236 show,
276 show,
237 xmin,
277 xmin,
238 xmax,
278 xmax,
239 ymin,
279 ymin,
240 ymax)
280 ymax)
241
281
242 self.draw()
282 self.draw()
243
283
244 str_datetime = thisDatetime.strftime("%Y%m%d_%H%M%S")
284 str_datetime = thisDatetime.strftime("%Y%m%d_%H%M%S")
245 figfile = self.getFilename(name = str_datetime) + "_" + str(i)
285 figfile = self.getFilename(name = str_datetime) + "_" + str(i)
246
286
247 self.save(figpath=figpath,
287 self.save(figpath=figpath,
248 figfile=figfile,
288 figfile=figfile,
249 save=save,
289 save=save,
250 ftp=ftp,
290 ftp=ftp,
251 wr_period=wr_period,
291 wr_period=wr_period,
252 thisDatetime=thisDatetime)
292 thisDatetime=thisDatetime)
253
293
254 else:
294 else:
255 wintitle += " [Profile = %d] " %dataOut.profileIndex
295 wintitle += " [Profile = %d] " %dataOut.profileIndex
256
296
257 if type == "power":
297 if type == "power":
258 self.plot_power(dataOut.heightList,
298 self.plot_power(dataOut.heightList,
259 dataOut.data,
299 dataOut.data,
260 id,
300 id,
261 channelIndexList,
301 channelIndexList,
262 thisDatetime,
302 thisDatetime,
263 wintitle,
303 wintitle,
264 show,
304 show,
265 xmin,
305 xmin,
266 xmax,
306 xmax,
267 ymin,
307 ymin,
268 ymax)
308 ymax)
269
309
270 if type == "iq":
310 if type == "iq":
271 self.plot_iq(dataOut.heightList,
311 self.plot_iq(dataOut.heightList,
272 dataOut.data,
312 dataOut.data,
273 id,
313 id,
274 channelIndexList,
314 channelIndexList,
275 thisDatetime,
315 thisDatetime,
276 wintitle,
316 wintitle,
277 show,
317 show,
278 xmin,
318 xmin,
279 xmax,
319 xmax,
280 ymin,
320 ymin,
281 ymax)
321 ymax)
282
322
323 if type== "weatherpower":
324 self.plot_weatherpower(dataOut.heightList,
325 dataOut.data,
326 id,
327 channelIndexList,
328 thisDatetime,
329 wintitle,
330 show,
331 xmin,
332 xmax,
333 ymin,
334 ymax)
335 if type== "weathervelocity":
336 self.plot_weathervelocity(dataOut.data_velocity,
337 dataOut.heightList,
338 id,
339 channelIndexList,
340 thisDatetime,
341 wintitle,
342 show,
343 xmin,
344 xmax,
345 ymin,
346 ymax)
347
283 self.draw()
348 self.draw()
284
349
285 str_datetime = thisDatetime.strftime("%Y%m%d_%H%M%S") + "_" + str(dataOut.profileIndex)
350 str_datetime = thisDatetime.strftime("%Y%m%d_%H%M%S") + "_" + str(dataOut.profileIndex)
286 figfile = self.getFilename(name = str_datetime)
351 figfile = self.getFilename(name = str_datetime)
287
352
288 self.save(figpath=figpath,
353 self.save(figpath=figpath,
289 figfile=figfile,
354 figfile=figfile,
290 save=save,
355 save=save,
291 ftp=ftp,
356 ftp=ftp,
292 wr_period=wr_period,
357 wr_period=wr_period,
293 thisDatetime=thisDatetime)
358 thisDatetime=thisDatetime)
294
359
295 return dataOut
360 return dataOut
361
362
363
364 @MPDecorator
365 class TimePlot_(Figure):
366
367 __isConfig = None
368 __nsubplots = None
369
370 WIDTHPROF = None
371 HEIGHTPROF = None
372 PREFIX = 'time'
373
374 def __init__(self):
375
376 Figure.__init__(self)
377 self.timerange = None
378 self.isConfig = False
379 self.__nsubplots = 1
380
381 self.WIDTH = 800
382 self.HEIGHT = 250
383 self.WIDTHPROF = 120
384 self.HEIGHTPROF = 0
385 self.counter_imagwr = 0
386
387 self.PLOT_CODE = RTIVOLT_CODE
388
389 self.FTP_WEI = None
390 self.EXP_CODE = None
391 self.SUB_EXP_CODE = None
392 self.PLOT_POS = None
393 self.tmin = None
394 self.tmax = None
395
396 self.xmin = None
397 self.xmax = None
398
399 self.figfile = None
400
401 def getSubplots(self):
402
403 ncol = 1
404 nrow = self.nplots
405
406 return nrow, ncol
407
408 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
409
410 self.__showprofile = showprofile
411 self.nplots = nplots
412
413 ncolspan = 1
414 colspan = 1
415 if showprofile:
416 ncolspan = 7
417 colspan = 6
418 self.__nsubplots = 2
419
420 self.createFigure(id = id,
421 wintitle = wintitle,
422 widthplot = self.WIDTH + self.WIDTHPROF,
423 heightplot = self.HEIGHT + self.HEIGHTPROF,
424 show=show)
425
426 nrow, ncol = self.getSubplots()
427
428 counter = 0
429 for y in range(nrow):
430 for x in range(ncol):
431
432 if counter >= self.nplots:
433 break
434
435 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
436
437 if showprofile:
438 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1)
439
440 counter += 1
441
442 def run(self, dataOut, id, wintitle="", channelList=None, showprofile='True',
443 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,type="intensity",
444 timerange=None, colormap='jet',
445 save=False, figpath='./', lastone=0,figfile=None, ftp=False, wr_period=1, show=True,
446 server=None, folder=None, username=None, password=None,
447 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0, normFactor=None, HEIGHT=None):
448
449 """
450
451 Input:
452 dataOut :
453 id :
454 wintitle :
455 channelList :
456 showProfile :
457 xmin : None,
458 xmax : None,
459 ymin : None,
460 ymax : None,
461 zmin : None,
462 zmax : None
463 """
464 print("estoy aqui :D")
465 if dataOut.flagNoData:
466 return dataOut
467
468 #colormap = kwargs.get('colormap', 'jet')
469 if HEIGHT is not None:
470 self.HEIGHT = HEIGHT
471
472 if not isTimeInHourRange(dataOut.datatime, xmin, xmax):
473 return
474
475 if channelList == None:
476 channelIndexList = dataOut.channelIndexList
477 else:
478 channelIndexList = []
479 for channel in channelList:
480 if channel not in dataOut.channelList:
481 raise ValueError("Channel %d is not in dataOut.channelList")
482 channelIndexList.append(dataOut.channelList.index(channel))
483
484 if normFactor is None:
485 factor = dataOut.normFactor
486 else:
487 factor = normFactor
488
489 #factor = dataOut.normFactor
490 x = dataOut.getTimeRange()
491 y = dataOut.getHeiRange()
492 if type=="intensity":
493 z = dataOut.data_intensity/factor
494 z = numpy.where(numpy.isfinite(z), z, numpy.NAN)
495 avgdB = numpy.average(z, axis=1)
496 avgdB = 10.*numpy.log10(avg)
497 else:
498 z= dataOut.data_velocity
499 avgdB = numpy.average(z, axis=1)
500
501 # avgdB = dataOut.getPower()
502
503
504 thisDatetime = dataOut.datatime
505 #thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0])
506 title = wintitle + " RTI" #: %s" %(thisDatetime.strftime("%d-%b-%Y"))
507 xlabel = ""
508 ylabel = "Range (Km)"
509
510 update_figfile = False
511
512 if self.xmax is not None and dataOut.ltctime >= self.xmax: #yong
513 self.counter_imagwr = wr_period
514 self.isConfig = False
515 update_figfile = True
516
517 if not self.isConfig:
518
519 nplots = len(channelIndexList)
520
521 self.setup(id=id,
522 nplots=nplots,
523 wintitle=wintitle,
524 showprofile=showprofile,
525 show=show)
526
527 if timerange != None:
528 self.timerange = timerange
529
530 self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange)
531
532 noise = dataOut.noise/factor
533 noisedB = 10*numpy.log10(noise)
534
535 if ymin == None: ymin = numpy.nanmin(y)
536 if ymax == None: ymax = numpy.nanmax(y)
537 if zmin == None: zmin = numpy.floor(numpy.nanmin(noisedB)) - 3
538 if zmax == None: zmax = numpy.ceil(numpy.nanmax(avgdB)) + 3
539
540 self.FTP_WEI = ftp_wei
541 self.EXP_CODE = exp_code
542 self.SUB_EXP_CODE = sub_exp_code
543 self.PLOT_POS = plot_pos
544
545 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
546 self.isConfig = True
547 self.figfile = figfile
548 update_figfile = True
549
550 self.setWinTitle(title)
551
552 for i in range(self.nplots):
553 index = channelIndexList[i]
554 title = "Channel %d: %s" %(dataOut.channelList[index], thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
555 if ((dataOut.azimuth!=None) and (dataOut.zenith!=None)):
556 title = title + '_' + 'azimuth,zenith=%2.2f,%2.2f'%(dataOut.azimuth, dataOut.zenith)
557 axes = self.axesList[i*self.__nsubplots]
558 zdB = avgdB[index].reshape((1,-1))
559 axes.pcolorbuffer(x, y, zdB,
560 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
561 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
562 ticksize=9, cblabel='', cbsize="1%", colormap=colormap)
563
564 if self.__showprofile:
565 axes = self.axesList[i*self.__nsubplots +1]
566 axes.pline(avgdB[index], y,
567 xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax,
568 xlabel='dB', ylabel='', title='',
569 ytick_visible=False,
570 grid='x')
571
572 self.draw()
573
574 self.save(figpath=figpath,
575 figfile=figfile,
576 save=save,
577 ftp=ftp,
578 wr_period=wr_period,
579 thisDatetime=thisDatetime,
580 update_figfile=update_figfile)
581 return dataOut
@@ -1,30 +1,31
1 '''
1 '''
2 @author: roj-idl71
2 @author: roj-idl71
3 '''
3 '''
4 #USED IN jroplot_spectra.py
4 #USED IN jroplot_spectra.py
5 RTI_CODE = 0 #Range time intensity (RTI).
5 RTI_CODE = 0 #Range time intensity (RTI).
6 SPEC_CODE = 1 #Spectra (and Cross-spectra) information.
6 SPEC_CODE = 1 #Spectra (and Cross-spectra) information.
7 CROSS_CODE = 2 #Cross-Correlation information.
7 CROSS_CODE = 2 #Cross-Correlation information.
8 COH_CODE = 3 #Coherence map.
8 COH_CODE = 3 #Coherence map.
9 BASE_CODE = 4 #Base lines graphic.
9 BASE_CODE = 4 #Base lines graphic.
10 ROW_CODE = 5 #Row Spectra.
10 ROW_CODE = 5 #Row Spectra.
11 TOTAL_CODE = 6 #Total Power.
11 TOTAL_CODE = 6 #Total Power.
12 DRIFT_CODE = 7 #Drifts graphics.
12 DRIFT_CODE = 7 #Drifts graphics.
13 HEIGHT_CODE = 8 #Height profile.
13 HEIGHT_CODE = 8 #Height profile.
14 PHASE_CODE = 9 #Signal Phase.
14 PHASE_CODE = 9 #Signal Phase.
15
15
16 POWER_CODE = 16
16 POWER_CODE = 16
17 NOISE_CODE = 17
17 NOISE_CODE = 17
18 BEACON_CODE = 18
18 BEACON_CODE = 18
19
19
20 #USED IN jroplot_parameters.py
20 #USED IN jroplot_parameters.py
21 WIND_CODE = 22
21 WIND_CODE = 22
22 MSKYMAP_CODE = 23
22 MSKYMAP_CODE = 23
23 MPHASE_CODE = 24
23 MPHASE_CODE = 24
24
24
25 MOMENTS_CODE = 25
25 MOMENTS_CODE = 25
26 PARMS_CODE = 26
26 PARMS_CODE = 26
27 SPECFIT_CODE = 27
27 SPECFIT_CODE = 27
28 EWDRIFT_CODE = 28
28 EWDRIFT_CODE = 28
29
29
30 WPO_CODE = 29 #Weather Intensity - Power
30 WPO_CODE = 29 #Weather Intensity - Power
31 RTIVOLT_CODE = 30
@@ -1,480 +1,496
1 import numpy,math,random,time
1 import numpy,math,random,time
2 import zmq
2 import zmq
3 import tempfile
3 import tempfile
4 from io import StringIO
4 from io import StringIO
5 ########## 1 Heredamos JRODatareader
5 ########## 1 Heredamos JRODatareader
6 from schainpy.model.io.jroIO_base import *
6 from schainpy.model.io.jroIO_base import *
7 ########## 2 Heredamos las propiedades de ProcessingUnit
7 ########## 2 Heredamos las propiedades de ProcessingUnit
8 from schainpy.model.proc.jroproc_base import ProcessingUnit,Operation,MPDecorator
8 from schainpy.model.proc.jroproc_base import ProcessingUnit,Operation,MPDecorator
9 ########## 3 Importaremos las clases BascicHeader, SystemHeader, RadarControlHeader, ProcessingHeader
9 ########## 3 Importaremos las clases BascicHeader, SystemHeader, RadarControlHeader, ProcessingHeader
10 from schainpy.model.data.jroheaderIO import PROCFLAG, BasicHeader,SystemHeader,RadarControllerHeader, ProcessingHeader
10 from schainpy.model.data.jroheaderIO import PROCFLAG, BasicHeader,SystemHeader,RadarControllerHeader, ProcessingHeader
11 ########## 4 Importaremos el objeto Voltge
11 ########## 4 Importaremos el objeto Voltge
12 from schainpy.model.data.jrodata import Voltage
12 from schainpy.model.data.jrodata import Voltage
13
13
14 @MPDecorator
14 @MPDecorator
15 class SimulatorReader(JRODataReader, ProcessingUnit):
15 class SimulatorReader(JRODataReader, ProcessingUnit):
16 incIntFactor = 1
16 incIntFactor = 1
17 nFFTPoints = 0
17 nFFTPoints = 0
18 FixPP_IncInt = 1
18 FixPP_IncInt = 1
19 FixRCP_IPP = 1000
19 FixRCP_IPP = 1000
20 FixPP_CohInt = 1
20 FixPP_CohInt = 1
21 Tau_0 = 250
21 Tau_0 = 250
22 AcqH0_0 = 70
22 AcqH0_0 = 70
23 H0 = AcqH0_0
23 H0 = AcqH0_0
24 AcqDH_0 = 1.25
24 AcqDH_0 = 1.25
25 DH0 = AcqDH_0
25 DH0 = AcqDH_0
26 Bauds = 32
26 Bauds = 32
27 BaudWidth = None
27 BaudWidth = None
28 FixRCP_TXA = 40
28 FixRCP_TXA = 40
29 FixRCP_TXB = 70
29 FixRCP_TXB = 70
30 fAngle = 2.0*math.pi*(1/16)
30 fAngle = 2.0*math.pi*(1/16)
31 DC_level = 500
31 DC_level = 500
32 stdev = 8
32 stdev = 8
33 Num_Codes = 2
33 Num_Codes = 2
34 #code0 = numpy.array([1,1,1,0,1,1,0,1,1,1,1,0,0,0,1,0,1,1,1,0,1,1,0,1,0,0,0,1,1,1,0,1])
34 #code0 = numpy.array([1,1,1,0,1,1,0,1,1,1,1,0,0,0,1,0,1,1,1,0,1,1,0,1,0,0,0,1,1,1,0,1])
35 #code1 = numpy.array([1,1,1,0,1,1,0,1,1,1,1,0,0,0,1,0,0,0,0,1,0,0,1,0,1,1,1,0,0,0,1,0])
35 #code1 = numpy.array([1,1,1,0,1,1,0,1,1,1,1,0,0,0,1,0,0,0,0,1,0,0,1,0,1,1,1,0,0,0,1,0])
36 #Dyn_snCode = numpy.array([Num_Codes,Bauds])
36 #Dyn_snCode = numpy.array([Num_Codes,Bauds])
37 Dyn_snCode = None
37 Dyn_snCode = None
38 Samples = 200
38 Samples = 200
39 channels = 5
39 channels = 5
40 pulses = None
40 pulses = None
41 Reference = None
41 Reference = None
42 pulse_size = None
42 pulse_size = None
43 prof_gen = None
43 prof_gen = None
44 Fdoppler = 100
44 Fdoppler = 100
45 Hdoppler = 36
45 Hdoppler = 36
46 Adoppler = 300
47 frequency = 9345
46 def __init__(self):
48 def __init__(self):
47 """
49 """
48 Inicializador de la clases SimulatorReader para
50 Inicializador de la clases SimulatorReader para
49 generar datos de voltage simulados.
51 generar datos de voltage simulados.
50 Input:
52 Input:
51 dataOut: Objeto de la clase Voltage.
53 dataOut: Objeto de la clase Voltage.
52 Este Objeto sera utilizado apra almacenar
54 Este Objeto sera utilizado apra almacenar
53 un perfil de datos cada vez qe se haga psiversho
55 un perfil de datos cada vez qe se haga psiversho
54 un requerimiento (getData)
56 un requerimiento (getData)
55 """
57 """
56 ProcessingUnit.__init__(self)
58 ProcessingUnit.__init__(self)
57 print(" [ START ] init - Metodo Simulator Reader")
59 print(" [ START ] init - Metodo Simulator Reader")
58
60
59 self.isConfig = False
61 self.isConfig = False
60 self.basicHeaderObj = BasicHeader(LOCALTIME)
62 self.basicHeaderObj = BasicHeader(LOCALTIME)
61 self.systemHeaderObj = SystemHeader()
63 self.systemHeaderObj = SystemHeader()
62 self.radarControllerHeaderObj = RadarControllerHeader()
64 self.radarControllerHeaderObj = RadarControllerHeader()
63 self.processingHeaderObj = ProcessingHeader()
65 self.processingHeaderObj = ProcessingHeader()
64 self.profileIndex = 2**32-1
66 self.profileIndex = 2**32-1
65 self.dataOut = Voltage()
67 self.dataOut = Voltage()
66 #code0 = numpy.array([1,1,1,0,1,1,0,1,1,1,1,0,0,0,1,0,1,1,1,0,1,1,0,1,0,0,0,1,1,1,0,1])
68 #code0 = numpy.array([1,1,1,0,1,1,0,1,1,1,1,0,0,0,1,0,1,1,1,0,1,1,0,1,0,0,0,1,1,1,0,1])
67 code0 = numpy.array([1,1,1,-1,1,1,-1,1,1,1,1,-1,-1,-1,1,-1,1,1,1,-1,1,1,-1,1,-1,-1,-1,1,1,1,-1,1])
69 code0 = numpy.array([1,1,1,-1,1,1,-1,1,1,1,1,-1,-1,-1,1,-1,1,1,1,-1,1,1,-1,1,-1,-1,-1,1,1,1,-1,1])
68 #code1 = numpy.array([1,1,1,0,1,1,0,1,1,1,1,0,0,0,1,0,0,0,0,1,0,0,1,0,1,1,1,0,0,0,1,0])
70 #code1 = numpy.array([1,1,1,0,1,1,0,1,1,1,1,0,0,0,1,0,0,0,0,1,0,0,1,0,1,1,1,0,0,0,1,0])
69 code1 = numpy.array([1,1,1,-1,1,1,-1,1,1,1,1,-1,-1,-1,1,-1,-1,-1,-1,1,-1,-1,1,-1,1,1,1,-1,-1,-1,1,-1])
71 code1 = numpy.array([1,1,1,-1,1,1,-1,1,1,1,1,-1,-1,-1,1,-1,-1,-1,-1,1,-1,-1,1,-1,1,1,1,-1,-1,-1,1,-1])
70 #self.Dyn_snCode = numpy.array([code0,code1])
72 #self.Dyn_snCode = numpy.array([code0,code1])
71 self.Dyn_snCode = None
73 self.Dyn_snCode = None
72 print(" [ END ] init - Metodo simulator Reader" )
74 print(" [ END ] init - Metodo simulator Reader" )
73
75
74
76
75 def __hasNotDataInBuffer(self):
77 def __hasNotDataInBuffer(self):
76
78
77 if self.profileIndex >= self.processingHeaderObj.profilesPerBlock* self.nTxs:
79 if self.profileIndex >= self.processingHeaderObj.profilesPerBlock* self.nTxs:
78 if self.nReadBlocks>0:
80 if self.nReadBlocks>0:
79 tmp = self.dataOut.utctime
81 tmp = self.dataOut.utctime
80 tmp_utc = int(self.dataOut.utctime)
82 tmp_utc = int(self.dataOut.utctime)
81 tmp_milisecond = int((tmp-tmp_utc)*1000)
83 tmp_milisecond = int((tmp-tmp_utc)*1000)
82 self.basicHeaderObj.utc = tmp_utc
84 self.basicHeaderObj.utc = tmp_utc
83 self.basicHeaderObj.miliSecond= tmp_milisecond
85 self.basicHeaderObj.miliSecond= tmp_milisecond
84 return 1
86 return 1
85 return 0
87 return 0
86
88
87
89
88 def setNextFile(self):
90 def setNextFile(self):
89 """Set the next file to be readed open it and parse de file header"""
91 """Set the next file to be readed open it and parse de file header"""
90
92
91 if (self.nReadBlocks >= self.processingHeaderObj.dataBlocksPerFile):
93 if (self.nReadBlocks >= self.processingHeaderObj.dataBlocksPerFile):
92 print('------------------- [Opening file] ------------------------------')
94 self.nReadFiles=self.nReadFiles+1
95 print('------------------- [Opening file] ------------------------------',self.nReadFiles)
93 self.nReadBlocks = 0
96 self.nReadBlocks = 0
94
97
95 def __setNewBlock(self):
98 def __setNewBlock(self):
96
99
97 self.setNextFile()
100 self.setNextFile()
98 if self.flagIsNewFile:
101 if self.flagIsNewFile:
99 return 1
102 return 1
100
103
101 def readNextBlock(self):
104 def readNextBlock(self):
102 while True:
105 while True:
103 self.__setNewBlock()
106 self.__setNewBlock()
104 if not(self.readBlock()):
107 if not(self.readBlock()):
105 return 0
108 return 0
106 self.getBasicHeader()
109 self.getBasicHeader()
107 break
110 break
108 if self.verbose:
111 if self.verbose:
109 print("[Reading] Block No. %d/%d -> %s" %(self.nReadBlocks,
112 print("[Reading] Block No. %d/%d -> %s" %(self.nReadBlocks,
110 self.processingHeaderObj.dataBlocksPerFile,
113 self.processingHeaderObj.dataBlocksPerFile,
111 self.dataOut.datatime.ctime()) )
114 self.dataOut.datatime.ctime()) )
112 return 1
115 return 1
113
116
114 def getFirstHeader(self):
117 def getFirstHeader(self):
115 self.getBasicHeader()
118 self.getBasicHeader()
116 self.dataOut.processingHeaderObj = self.processingHeaderObj.copy()
119 self.dataOut.processingHeaderObj = self.processingHeaderObj.copy()
117 self.dataOut.systemHeaderObj = self.systemHeaderObj.copy()
120 self.dataOut.systemHeaderObj = self.systemHeaderObj.copy()
118 self.dataOut.radarControllerHeaderObj = self.radarControllerHeaderObj.copy()
121 self.dataOut.radarControllerHeaderObj = self.radarControllerHeaderObj.copy()
119 #ADD NEW
122 #ADD NEW
120 self.dataOut.nProfiles = self.processingHeaderObj.profilesPerBlock
123 self.dataOut.nProfiles = self.processingHeaderObj.profilesPerBlock
121 self.dataOut.heightList = numpy.arange(self.processingHeaderObj.nHeights) * self.processingHeaderObj.deltaHeight + self.processingHeaderObj.firstHeight
124 self.dataOut.heightList = numpy.arange(self.processingHeaderObj.nHeights) * self.processingHeaderObj.deltaHeight + self.processingHeaderObj.firstHeight
122 self.dataOut.channelList = list(range(self.systemHeaderObj.nChannels))
125 self.dataOut.channelList = list(range(self.systemHeaderObj.nChannels))
123 self.dataOut.nCohInt = self.processingHeaderObj.nCohInt
126 self.dataOut.nCohInt = self.processingHeaderObj.nCohInt
124 # asumo q la data no esta decodificada
127 # asumo q la data no esta decodificada
125 self.dataOut.flagDecodeData = self.processingHeaderObj.flag_decode
128 self.dataOut.flagDecodeData = self.processingHeaderObj.flag_decode
126 # asumo q la data no esta sin flip
129 # asumo q la data no esta sin flip
127 self.dataOut.flagDeflipData = self.processingHeaderObj.flag_deflip
130 self.dataOut.flagDeflipData = self.processingHeaderObj.flag_deflip
128 self.dataOut.flagShiftFFT = self.processingHeaderObj.shif_fft
131 self.dataOut.flagShiftFFT = self.processingHeaderObj.shif_fft
132 #
133 self.dataOut.frequency = self.frequency
129
134
130 def getBasicHeader(self):
135 def getBasicHeader(self):
131
136
132 self.dataOut.utctime = self.basicHeaderObj.utc + self.basicHeaderObj.miliSecond / \
137 self.dataOut.utctime = self.basicHeaderObj.utc + self.basicHeaderObj.miliSecond / \
133 1000. + self.profileIndex * self.radarControllerHeaderObj.ippSeconds
138 1000. + self.profileIndex * self.radarControllerHeaderObj.ippSeconds
134
139
135 self.dataOut.flagDiscontinuousBlock = self.flagDiscontinuousBlock
140 self.dataOut.flagDiscontinuousBlock = self.flagDiscontinuousBlock
136
141
137 self.dataOut.timeZone = self.basicHeaderObj.timeZone
142 self.dataOut.timeZone = self.basicHeaderObj.timeZone
138
143
139 self.dataOut.dstFlag = self.basicHeaderObj.dstFlag
144 self.dataOut.dstFlag = self.basicHeaderObj.dstFlag
140
145
141 self.dataOut.errorCount = self.basicHeaderObj.errorCount
146 self.dataOut.errorCount = self.basicHeaderObj.errorCount
142
147
143 self.dataOut.useLocalTime = self.basicHeaderObj.useLocalTime
148 self.dataOut.useLocalTime = self.basicHeaderObj.useLocalTime
144
149
145 self.dataOut.ippSeconds = self.radarControllerHeaderObj.ippSeconds / self.nTxs
150 self.dataOut.ippSeconds = self.radarControllerHeaderObj.ippSeconds / self.nTxs
146
151
147 def reshapeData(self):
152 def reshapeData(self):
148 if self.nTxs==1:
153 if self.nTxs==1:
149 return
154 return
150
155
151 def readBlock(self):
156 def readBlock(self):
152
157
153 self.jro_GenerateBlockOfData(Samples= self.samples,DC_level=self.DC_level,
158 self.jro_GenerateBlockOfData(Samples= self.samples,DC_level=self.DC_level,
154 stdev=self.stdev,Reference= self.Reference,
159 stdev=self.stdev,Reference= self.Reference,
155 pulses = self.pulses,Num_Codes=self.Num_Codes,
160 pulses = self.pulses,Num_Codes=self.Num_Codes,
156 pulse_size=self.pulse_size,prof_gen=self.profiles,
161 pulse_size=self.pulse_size,prof_gen=self.profiles,
157 H0=self.H0,DH0=self.DH0)
162 H0=self.H0,DH0=self.DH0)
158
163
159 self.profileIndex = 0
164 self.profileIndex = 0
160 self.flagIsNewFile = 0
165 self.flagIsNewFile = 0
161 self.flagIsNewBlock = 1
166 self.flagIsNewBlock = 1
162 self.nTotalBlocks += 1
167 self.nTotalBlocks += 1
163 self.nReadBlocks += 1
168 self.nReadBlocks += 1
164
169
165 return 1
170 return 1
166
171
167
172
168 def getData(self): ### metodo propio de VoltageReader
173 def getData(self): ### metodo propio de VoltageReader
169
174
170 if self.flagNoMoreFiles:
175 if self.flagNoMoreFiles:
171 self.dataOut.flagNodata = True
176 self.dataOut.flagNodata = True
172 self.flagDiscontinuousBlock = 0
177 self.flagDiscontinuousBlock = 0
173 self.flagIsNewBlock = 0
178 self.flagIsNewBlock = 0
174 if self.__hasNotDataInBuffer(): # aqui es verdad
179 if self.__hasNotDataInBuffer(): # aqui es verdad
175 if not(self.readNextBlock()): # return 1 y por eso el if not salta a getBasic Header
180 if not(self.readNextBlock()): # return 1 y por eso el if not salta a getBasic Header
176 return 0
181 return 0
177 self.getFirstHeader() # atributo
182 self.getFirstHeader() # atributo
178 self.reshapeData() # nTxx1 =1 return , n
183 self.reshapeData() # nTxx1 =1 return , n
179
184
180 if not self.getByBlock:
185 if not self.getByBlock:
181 self.dataOut.flagDataAsBlock = False
186 self.dataOut.flagDataAsBlock = False
182 self.dataOut.data = self.datablock[:, self.profileIndex, :]
187 self.dataOut.data = self.datablock[:, self.profileIndex, :]
183 self.dataOut.profileIndex = self.profileIndex
188 self.dataOut.profileIndex = self.profileIndex
184 self.profileIndex += 1
189 self.profileIndex += 1
185 else:
190 else:
186 pass
191 pass
187 self.dataOut.flagNoData = False
192 self.dataOut.flagNoData = False
188 self.getBasicHeader()
193 self.getBasicHeader()
189 self.dataOut.realtime = self.online
194 self.dataOut.realtime = self.online
190 return self.dataOut.data
195 return self.dataOut.data
191
196
192 def set_kwargs(self, **kwargs):
197 def set_kwargs(self, **kwargs):
193 for key, value in kwargs.items():
198 for key, value in kwargs.items():
194 setattr(self, key, value)
199 setattr(self, key, value)
195
200
196 def set_RCH(self, expType=2, nTx=1,ipp=None, txA=0, txB=0,
201 def set_RCH(self, expType=2, nTx=1,ipp=None, txA=0, txB=0,
197 nWindows=None, nHeights=None, firstHeight=None, deltaHeight=None,
202 nWindows=None, nHeights=None, firstHeight=None, deltaHeight=None,
198 numTaus=0, line6Function=0, line5Function=0, fClock=None,
203 numTaus=0, line6Function=0, line5Function=0, fClock=None,
199 prePulseBefore=0, prePulseAfter=0,
204 prePulseBefore=0, prePulseAfter=0,
200 codeType=0, nCode=0, nBaud=0, code=None,
205 codeType=0, nCode=0, nBaud=0, code=None,
201 flip1=0, flip2=0):
206 flip1=0, flip2=0):
202
207
203 self.radarControllerHeaderObj.expType = expType
208 self.radarControllerHeaderObj.expType = expType
204 self.radarControllerHeaderObj.nTx = nTx
209 self.radarControllerHeaderObj.nTx = nTx
205 self.radarControllerHeaderObj.ipp = float(ipp)
210 self.radarControllerHeaderObj.ipp = float(ipp)
206 self.radarControllerHeaderObj.txA = float(txA)
211 self.radarControllerHeaderObj.txA = float(txA)
207 self.radarControllerHeaderObj.txB = float(txB)
212 self.radarControllerHeaderObj.txB = float(txB)
208 self.radarControllerHeaderObj.rangeIPP = ipp
213 self.radarControllerHeaderObj.rangeIPP = ipp
209 self.radarControllerHeaderObj.rangeTxA = txA
214 self.radarControllerHeaderObj.rangeTxA = txA
210 self.radarControllerHeaderObj.rangeTxB = txB
215 self.radarControllerHeaderObj.rangeTxB = txB
211
216
212 self.radarControllerHeaderObj.nHeights = int(nHeights)
217 self.radarControllerHeaderObj.nHeights = int(nHeights)
213 self.radarControllerHeaderObj.firstHeight = numpy.array([firstHeight])
218 self.radarControllerHeaderObj.firstHeight = numpy.array([firstHeight])
214 self.radarControllerHeaderObj.deltaHeight = numpy.array([deltaHeight])
219 self.radarControllerHeaderObj.deltaHeight = numpy.array([deltaHeight])
215 self.radarControllerHeaderObj.samplesWin = numpy.array([nHeights])
220 self.radarControllerHeaderObj.samplesWin = numpy.array([nHeights])
216
221
217
222
218 self.radarControllerHeaderObj.nWindows = nWindows
223 self.radarControllerHeaderObj.nWindows = nWindows
219 self.radarControllerHeaderObj.numTaus = numTaus
224 self.radarControllerHeaderObj.numTaus = numTaus
220 self.radarControllerHeaderObj.codeType = codeType
225 self.radarControllerHeaderObj.codeType = codeType
221 self.radarControllerHeaderObj.line6Function = line6Function
226 self.radarControllerHeaderObj.line6Function = line6Function
222 self.radarControllerHeaderObj.line5Function = line5Function
227 self.radarControllerHeaderObj.line5Function = line5Function
223 self.radarControllerHeaderObj.fclock = fClock
228 self.radarControllerHeaderObj.fclock = fClock
224 self.radarControllerHeaderObj.prePulseBefore= prePulseBefore
229 self.radarControllerHeaderObj.prePulseBefore= prePulseBefore
225 self.radarControllerHeaderObj.prePulseAfter = prePulseAfter
230 self.radarControllerHeaderObj.prePulseAfter = prePulseAfter
226
231
227 self.radarControllerHeaderObj.nCode = nCode
232 self.radarControllerHeaderObj.nCode = nCode
228 self.radarControllerHeaderObj.nBaud = nBaud
233 self.radarControllerHeaderObj.nBaud = nBaud
229 self.radarControllerHeaderObj.code = code
234 self.radarControllerHeaderObj.code = code
230 self.radarControllerHeaderObj.flip1 = flip1
235 self.radarControllerHeaderObj.flip1 = flip1
231 self.radarControllerHeaderObj.flip2 = flip2
236 self.radarControllerHeaderObj.flip2 = flip2
232
237
233 self.radarControllerHeaderObj.code_size = int(numpy.ceil(nBaud / 32.)) * nCode * 4
238 self.radarControllerHeaderObj.code_size = int(numpy.ceil(nBaud / 32.)) * nCode * 4
234
239
235 if fClock is None and deltaHeight is not None:
240 if fClock is None and deltaHeight is not None:
236 self.fClock = 0.15 / (deltaHeight * 1e-6)
241 self.fClock = 0.15 / (deltaHeight * 1e-6)
237
242
238 def set_PH(self, dtype=0, blockSize=0, profilesPerBlock=0,
243 def set_PH(self, dtype=0, blockSize=0, profilesPerBlock=0,
239 dataBlocksPerFile=0, nWindows=0, processFlags=0, nCohInt=0,
244 dataBlocksPerFile=0, nWindows=0, processFlags=0, nCohInt=0,
240 nIncohInt=0, totalSpectra=0, nHeights=0, firstHeight=0,
245 nIncohInt=0, totalSpectra=0, nHeights=0, firstHeight=0,
241 deltaHeight=0, samplesWin=0, spectraComb=0, nCode=0,
246 deltaHeight=0, samplesWin=0, spectraComb=0, nCode=0,
242 code=0, nBaud=None, shif_fft=False, flag_dc=False,
247 code=0, nBaud=None, shif_fft=False, flag_dc=False,
243 flag_cspc=False, flag_decode=False, flag_deflip=False):
248 flag_cspc=False, flag_decode=False, flag_deflip=False):
244
249
245 self.processingHeaderObj.profilesPerBlock = profilesPerBlock
250 self.processingHeaderObj.profilesPerBlock = profilesPerBlock
246 self.processingHeaderObj.dataBlocksPerFile = dataBlocksPerFile
251 self.processingHeaderObj.dataBlocksPerFile = dataBlocksPerFile
247 self.processingHeaderObj.nWindows = nWindows
252 self.processingHeaderObj.nWindows = nWindows
248 self.processingHeaderObj.nCohInt = nCohInt
253 self.processingHeaderObj.nCohInt = nCohInt
249 self.processingHeaderObj.nIncohInt = nIncohInt
254 self.processingHeaderObj.nIncohInt = nIncohInt
250 self.processingHeaderObj.totalSpectra = totalSpectra
255 self.processingHeaderObj.totalSpectra = totalSpectra
251 self.processingHeaderObj.nHeights = int(nHeights)
256 self.processingHeaderObj.nHeights = int(nHeights)
252 self.processingHeaderObj.firstHeight = firstHeight
257 self.processingHeaderObj.firstHeight = firstHeight
253 self.processingHeaderObj.deltaHeight = deltaHeight
258 self.processingHeaderObj.deltaHeight = deltaHeight
254 self.processingHeaderObj.samplesWin = nHeights
259 self.processingHeaderObj.samplesWin = nHeights
255
260
256 def set_BH(self, utc = 0, miliSecond = 0, timeZone = 0):
261 def set_BH(self, utc = 0, miliSecond = 0, timeZone = 0):
257 self.basicHeaderObj.utc = utc
262 self.basicHeaderObj.utc = utc
258 self.basicHeaderObj.miliSecond = miliSecond
263 self.basicHeaderObj.miliSecond = miliSecond
259 self.basicHeaderObj.timeZone = timeZone
264 self.basicHeaderObj.timeZone = timeZone
260
265
261 def set_SH(self, nSamples=0, nProfiles=0, nChannels=0, adcResolution=14, pciDioBusWidth=0):
266 def set_SH(self, nSamples=0, nProfiles=0, nChannels=0, adcResolution=14, pciDioBusWidth=0):
262 self.systemHeaderObj.nSamples = nSamples
267 self.systemHeaderObj.nSamples = nSamples
263 self.systemHeaderObj.nProfiles = nProfiles
268 self.systemHeaderObj.nProfiles = nProfiles
264 self.systemHeaderObj.nChannels = nChannels
269 self.systemHeaderObj.nChannels = nChannels
265 self.systemHeaderObj.adcResolution = adcResolution
270 self.systemHeaderObj.adcResolution = adcResolution
266 self.systemHeaderObj.pciDioBusWidth = pciDioBusWidth
271 self.systemHeaderObj.pciDioBusWidth = pciDioBusWidth
267
272
268 def setup(self,incIntFactor= 1, nFFTPoints = 0, FixPP_IncInt=1,FixRCP_IPP=1000,
273 def setup(self,frequency=49.92e6,incIntFactor= 1, nFFTPoints = 0, FixPP_IncInt=1,FixRCP_IPP=1000,
269 FixPP_CohInt= 1,Tau_0= 250,AcqH0_0 = 70 ,AcqDH_0=1.25, Bauds= 32,
274 FixPP_CohInt= 1,Tau_0= 250,AcqH0_0 = 70 ,AcqDH_0=1.25, Bauds= 32,
270 FixRCP_TXA = 40, FixRCP_TXB = 50, fAngle = 2.0*math.pi*(1/16),DC_level= 500,
275 FixRCP_TXA = 40, FixRCP_TXB = 50, fAngle = 2.0*math.pi*(1/16),DC_level= 50,
271 stdev= 8,Num_Codes = 1 , Dyn_snCode = None, samples=200,channels=1,Fdoppler=20,Hdoppler=36,
276 stdev= 8,Num_Codes = 1 , Dyn_snCode = None, samples=200,
277 channels=2,Fdoppler=20,Hdoppler=36,Adoppler=500,
272 **kwargs):
278 **kwargs):
273
279
274 self.set_kwargs(**kwargs)
280 self.set_kwargs(**kwargs)
275 self.nReadBlocks = 0
281 self.nReadBlocks = 0
282 self.nReadFiles = 1
283 print('------------------- [Opening file: ] ------------------------------',self.nReadFiles)
284
276 tmp = time.time()
285 tmp = time.time()
277 tmp_utc = int(tmp)
286 tmp_utc = int(tmp)
278 tmp_milisecond = int((tmp-tmp_utc)*1000)
287 tmp_milisecond = int((tmp-tmp_utc)*1000)
279 print(" SETUP -basicHeaderObj.utc",datetime.datetime.utcfromtimestamp(tmp))
288 print(" SETUP -basicHeaderObj.utc",datetime.datetime.utcfromtimestamp(tmp))
280 if Dyn_snCode is None:
289 if Dyn_snCode is None:
281 Num_Codes=1
290 Num_Codes=1
282 Bauds =1
291 Bauds =1
283
292
284
293
285
294
286 self.set_BH(utc= tmp_utc,miliSecond= tmp_milisecond,timeZone=300 )
295 self.set_BH(utc= tmp_utc,miliSecond= tmp_milisecond,timeZone=300 )
287
296
288 self.set_RCH( expType=0, nTx=150,ipp=FixRCP_IPP, txA=FixRCP_TXA, txB= FixRCP_TXB,
297 self.set_RCH( expType=0, nTx=150,ipp=FixRCP_IPP, txA=FixRCP_TXA, txB= FixRCP_TXB,
289 nWindows=1 , nHeights=samples, firstHeight=AcqH0_0, deltaHeight=AcqDH_0,
298 nWindows=1 , nHeights=samples, firstHeight=AcqH0_0, deltaHeight=AcqDH_0,
290 numTaus=1, line6Function=0, line5Function=0, fClock=None,
299 numTaus=1, line6Function=0, line5Function=0, fClock=None,
291 prePulseBefore=0, prePulseAfter=0,
300 prePulseBefore=0, prePulseAfter=0,
292 codeType=14, nCode=Num_Codes, nBaud=32, code=Dyn_snCode,
301 codeType=14, nCode=Num_Codes, nBaud=32, code=Dyn_snCode,
293 flip1=0, flip2=0)
302 flip1=0, flip2=0)
294
303
295 self.set_PH(dtype=0, blockSize=0, profilesPerBlock=300,
304 self.set_PH(dtype=0, blockSize=0, profilesPerBlock=300,
296 dataBlocksPerFile=120, nWindows=1, processFlags=0, nCohInt=1,
305 dataBlocksPerFile=120, nWindows=1, processFlags=0, nCohInt=1,
297 nIncohInt=1, totalSpectra=0, nHeights=samples, firstHeight=AcqH0_0,
306 nIncohInt=1, totalSpectra=0, nHeights=samples, firstHeight=AcqH0_0,
298 deltaHeight=AcqDH_0, samplesWin=samples, spectraComb=0, nCode=0,
307 deltaHeight=AcqDH_0, samplesWin=samples, spectraComb=0, nCode=0,
299 code=0, nBaud=None, shif_fft=False, flag_dc=False,
308 code=0, nBaud=None, shif_fft=False, flag_dc=False,
300 flag_cspc=False, flag_decode=False, flag_deflip=False)
309 flag_cspc=False, flag_decode=False, flag_deflip=False)
301
310
302 self.set_SH(nSamples=samples, nProfiles=300, nChannels=channels)
311 self.set_SH(nSamples=samples, nProfiles=300, nChannels=channels)
303
312
313
314 self.frequency = frequency
304 self.incIntFactor = incIntFactor
315 self.incIntFactor = incIntFactor
305 self.nFFTPoints = nFFTPoints
316 self.nFFTPoints = nFFTPoints
306 self.FixPP_IncInt = FixPP_IncInt
317 self.FixPP_IncInt = FixPP_IncInt
307 self.FixRCP_IPP = FixRCP_IPP
318 self.FixRCP_IPP = FixRCP_IPP
308 self.FixPP_CohInt = FixPP_CohInt
319 self.FixPP_CohInt = FixPP_CohInt
309 self.Tau_0 = Tau_0
320 self.Tau_0 = Tau_0
310 self.AcqH0_0 = AcqH0_0
321 self.AcqH0_0 = AcqH0_0
311 self.H0 = AcqH0_0
322 self.H0 = AcqH0_0
312 self.AcqDH_0 = AcqDH_0
323 self.AcqDH_0 = AcqDH_0
313 self.DH0 = AcqDH_0
324 self.DH0 = AcqDH_0
314 self.Bauds = Bauds
325 self.Bauds = Bauds
315 self.FixRCP_TXA = FixRCP_TXA
326 self.FixRCP_TXA = FixRCP_TXA
316 self.FixRCP_TXB = FixRCP_TXB
327 self.FixRCP_TXB = FixRCP_TXB
317 self.fAngle = fAngle
328 self.fAngle = fAngle
318 self.DC_level = DC_level
329 self.DC_level = DC_level
319 self.stdev = stdev
330 self.stdev = stdev
320 self.Num_Codes = Num_Codes
331 self.Num_Codes = Num_Codes
321 self.Dyn_snCode = Dyn_snCode
332 self.Dyn_snCode = Dyn_snCode
322 self.samples = samples
333 self.samples = samples
323 self.channels = channels
334 self.channels = channels
324 self.profiles = None
335 self.profiles = None
325 self.m_nReference = None
336 self.m_nReference = None
326 self.Baudwidth = None
337 self.Baudwidth = None
327 self.Fdoppler = Fdoppler
338 self.Fdoppler = Fdoppler
328 self.Hdoppler = Hdoppler
339 self.Hdoppler = Hdoppler
340 self.Adoppler = Adoppler
329
341
330 print("IPP ", self.FixRCP_IPP)
342 print("IPP ", self.FixRCP_IPP)
331 print("Tau_0 ",self.Tau_0)
343 print("Tau_0 ",self.Tau_0)
332 print("AcqH0_0",self.AcqH0_0)
344 print("AcqH0_0",self.AcqH0_0)
333 print("samples,window ",self.samples)
345 print("samples,window ",self.samples)
334 print("AcqDH_0",AcqDH_0)
346 print("AcqDH_0",AcqDH_0)
335 print("FixRCP_TXA",self.FixRCP_TXA)
347 print("FixRCP_TXA",self.FixRCP_TXA)
336 print("FixRCP_TXB",self.FixRCP_TXB)
348 print("FixRCP_TXB",self.FixRCP_TXB)
337 print("Dyn_snCode",Dyn_snCode)
349 print("Dyn_snCode",Dyn_snCode)
338 print("Fdoppler", Fdoppler)
350 print("Fdoppler", Fdoppler)
339 print("Hdoppler",Hdoppler)
351 print("Hdoppler",Hdoppler)
352 print("Vdopplermax",Fdoppler*(3.0e8/self.frequency)/2.0)
340
353
341 self.init_acquisition()
354 self.init_acquisition()
342 self.pulses,self.pulse_size=self.init_pulse(Num_Codes=self.Num_Codes,Bauds=self.Bauds,BaudWidth=self.BaudWidth,Dyn_snCode=Dyn_snCode)
355 self.pulses,self.pulse_size=self.init_pulse(Num_Codes=self.Num_Codes,Bauds=self.Bauds,BaudWidth=self.BaudWidth,Dyn_snCode=Dyn_snCode)
343 print(" [ END ] - SETUP metodo")
356 print(" [ END ] - SETUP metodo")
344 return
357 return
345
358
346 def run(self,**kwargs): # metodo propio
359 def run(self,**kwargs): # metodo propio
347 if not(self.isConfig):
360 if not(self.isConfig):
348 self.setup(**kwargs)
361 self.setup(**kwargs)
349 self.isConfig = True
362 self.isConfig = True
350 self.getData()
363 self.getData()
351
364
352 ##################################################################
365 ##################################################################
353 ###### Aqui ingresamos las clases y metodos propios del simulador
366 ###### Aqui ingresamos las clases y metodos propios del simulador
354 ##################################################################
367 ##################################################################
355
368
356 #############################################
369 #############################################
357 ############## INIT_ACQUISITION##############
370 ############## INIT_ACQUISITION##############
358 #############################################
371 #############################################
359 def init_acquisition(self):
372 def init_acquisition(self):
360
373
361 if self.nFFTPoints != 0:
374 if self.nFFTPoints != 0:
362 self.incIntFactor = m_nProfilesperBlock/self.nFFTPoints
375 self.incIntFactor = m_nProfilesperBlock/self.nFFTPoints
363 if (self.FixPP_IncInt > self.incIntFactor):
376 if (self.FixPP_IncInt > self.incIntFactor):
364 self.incIntFactor = self.FixPP_IncInt/ self.incIntFactor
377 self.incIntFactor = self.FixPP_IncInt/ self.incIntFactor
365 elif(self.FixPP_IncInt< self.incIntFactor):
378 elif(self.FixPP_IncInt< self.incIntFactor):
366 print("False alert...")
379 print("False alert...")
367
380
368 ProfilesperBlock = self.processingHeaderObj.profilesPerBlock
381 ProfilesperBlock = self.processingHeaderObj.profilesPerBlock
369
382
370 self.timeperblock =int(((self.FixRCP_IPP
383 self.timeperblock =int(((self.FixRCP_IPP
371 *ProfilesperBlock
384 *ProfilesperBlock
372 *self.FixPP_CohInt
385 *self.FixPP_CohInt
373 *self.incIntFactor)
386 *self.incIntFactor)
374 /150.0)
387 /150.0)
375 *0.9
388 *0.9
376 +0.5)
389 +0.5)
377 # para cada canal
390 # para cada canal
378 self.profiles = ProfilesperBlock*self.FixPP_CohInt
391 self.profiles = ProfilesperBlock*self.FixPP_CohInt
379 self.profiles = ProfilesperBlock
392 self.profiles = ProfilesperBlock
380 self.Reference = int((self.Tau_0-self.AcqH0_0)/(self.AcqDH_0)+0.5)
393 self.Reference = int((self.Tau_0-self.AcqH0_0)/(self.AcqDH_0)+0.5)
381 self.BaudWidth = int((self.FixRCP_TXA/self.AcqDH_0)/self.Bauds + 0.5 )
394 self.BaudWidth = int((self.FixRCP_TXA/self.AcqDH_0)/self.Bauds + 0.5 )
382
395
383 if (self.BaudWidth==0):
396 if (self.BaudWidth==0):
384 self.BaudWidth=1
397 self.BaudWidth=1
385 #################################################################
398 #################################################################
386 ####################### init_pulse ##############################
399 ####################### init_pulse ##############################
387 ################################################################
400 ################################################################
388
401
389 def init_pulse(self,Num_Codes=Num_Codes,Bauds=Bauds,BaudWidth=BaudWidth,Dyn_snCode=Dyn_snCode):
402 def init_pulse(self,Num_Codes=Num_Codes,Bauds=Bauds,BaudWidth=BaudWidth,Dyn_snCode=Dyn_snCode):
390
403
391 Num_Codes = Num_Codes
404 Num_Codes = Num_Codes
392 Bauds = Bauds
405 Bauds = Bauds
393 BaudWidth = BaudWidth
406 BaudWidth = BaudWidth
394 Dyn_snCode = Dyn_snCode
407 Dyn_snCode = Dyn_snCode
395
408
396 if Dyn_snCode:
409 if Dyn_snCode:
397 print("EXISTE")
410 print("EXISTE")
398 else:
411 else:
399 print("No existe")
412 print("No existe")
400
413
401 if Dyn_snCode: # if Bauds:
414 if Dyn_snCode: # if Bauds:
402 pulses = list(range(0,Num_Codes))
415 pulses = list(range(0,Num_Codes))
403 num_codes = Num_Codes
416 num_codes = Num_Codes
404 for i in range(num_codes):
417 for i in range(num_codes):
405 pulse_size = Bauds*BaudWidth
418 pulse_size = Bauds*BaudWidth
406 pulses[i] = numpy.zeros(pulse_size)
419 pulses[i] = numpy.zeros(pulse_size)
407 for j in range(Bauds):
420 for j in range(Bauds):
408 for k in range(BaudWidth):
421 for k in range(BaudWidth):
409 pulses[i][j*BaudWidth+k] = int(Dyn_snCode[i][j]*600)
422 pulses[i][j*BaudWidth+k] = int(Dyn_snCode[i][j]*600)
410 else:
423 else:
411 print("sin code")
424 print("sin code")
412 pulses = list(range(1))
425 pulses = list(range(1))
413 pulse_size = int(self.FixRCP_TXB/0.15+0.5)
426 pulse_size = int(self.FixRCP_TXB/0.15+0.5)
414 pulses[0] = numpy.ones(pulse_size)
427 pulses[0] = numpy.ones(pulse_size)
415 pulses = 600*pulses[0]
428 pulses = 600*pulses[0]
416
429
417 return pulses,pulse_size
430 return pulses,pulse_size
418
431
419 #################################################################
432 #################################################################
420 ##################### Generate block data
433 ##################### Generate block data
421 ################################################################
434 ################################################################
422
435
423 def jro_GenerateBlockOfData(self,Samples=Samples,DC_level= DC_level,stdev=stdev,
436 def jro_GenerateBlockOfData(self,Samples=Samples,DC_level= DC_level,stdev=stdev,
424 Reference= Reference,pulses= pulses,
437 Reference= Reference,pulses= pulses,
425 Num_Codes= Num_Codes,pulse_size=pulse_size,
438 Num_Codes= Num_Codes,pulse_size=pulse_size,
426 prof_gen= prof_gen,H0 = H0,DH0=DH0,Fdoppler= Fdoppler,Hdoppler=Hdoppler):
439 prof_gen= prof_gen,H0 = H0,DH0=DH0,
440 Adoppler=Adoppler,Fdoppler= Fdoppler,Hdoppler=Hdoppler):
427 Samples = Samples
441 Samples = Samples
428 DC_level = DC_level
442 DC_level = DC_level
429 stdev = stdev
443 stdev = stdev
430 m_nR = Reference
444 m_nR = Reference
431 pulses = pulses
445 pulses = pulses
432 num_codes = Num_Codes
446 num_codes = Num_Codes
433 ps = pulse_size
447 ps = pulse_size
434 prof_gen = prof_gen
448 prof_gen = prof_gen
435 channels = self.channels
449 channels = self.channels
436 H0 = H0
450 H0 = H0
437 DH0 = DH0
451 DH0 = DH0
438 ippSec = self.radarControllerHeaderObj.ippSeconds
452 ippSec = self.radarControllerHeaderObj.ippSeconds
439 Fdoppler = self.Fdoppler
453 Fdoppler = self.Fdoppler
440 Hdoppler = self.Hdoppler
454 Hdoppler = self.Hdoppler
455 Adoppler = self.Adoppler
441
456
442 self.datablock = numpy.zeros([channels,prof_gen,Samples],dtype= numpy.complex64)
457 self.datablock = numpy.zeros([channels,prof_gen,Samples],dtype= numpy.complex64)
443 for i in range(channels):
458 for i in range(channels):
444 for k in range(prof_gen):
459 for k in range(prof_gen):
445 #Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·NOISEΒ·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·
460 #Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·NOISEΒ·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·
446 Noise_r = numpy.random.normal(DC_level,stdev,Samples)
461 Noise_r = numpy.random.normal(DC_level,stdev,Samples)
447 Noise_i = numpy.random.normal(DC_level,stdev,Samples)
462 Noise_i = numpy.random.normal(DC_level,stdev,Samples)
448 Noise = numpy.zeros(Samples,dtype=complex)
463 Noise = numpy.zeros(Samples,dtype=complex)
449 Noise.real = Noise_r
464 Noise.real = Noise_r
450 Noise.imag = Noise_i
465 Noise.imag = Noise_i
451 #Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·PULSOSΒ·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·
466 #Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·PULSOSΒ·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·
452 Pulso = numpy.zeros(pulse_size,dtype=complex)
467 Pulso = numpy.zeros(pulse_size,dtype=complex)
453 Pulso.real = pulses[k%num_codes]
468 Pulso.real = pulses[k%num_codes]
454 Pulso.imag = pulses[k%num_codes]
469 Pulso.imag = pulses[k%num_codes]
455 #Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β· PULSES+NOISEΒ·Β·Β·Β·Β·Β·Β·Β·Β·Β·
470 #Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β· PULSES+NOISEΒ·Β·Β·Β·Β·Β·Β·Β·Β·Β·
456 InBuffer = numpy.zeros(Samples,dtype=complex)
471 InBuffer = numpy.zeros(Samples,dtype=complex)
457 InBuffer[m_nR:m_nR+ps] = Pulso
472 InBuffer[m_nR:m_nR+ps] = Pulso
458 InBuffer = Noise+ InBuffer
473 InBuffer = InBuffer+Noise
459 #Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β· ANGLE Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·
474 #Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β· ANGLE Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·
460 InBuffer.real[m_nR:m_nR+ps] = InBuffer.real[m_nR:m_nR+ps]*(math.cos( self.fAngle)*5)
475 InBuffer.real[m_nR:m_nR+ps] = InBuffer.real[m_nR:m_nR+ps]*(math.cos( self.fAngle)*5)
461 InBuffer.imag[m_nR:m_nR+ps] = InBuffer.imag[m_nR:m_nR+ps]*(math.sin( self.fAngle)*5)
476 InBuffer.imag[m_nR:m_nR+ps] = InBuffer.imag[m_nR:m_nR+ps]*(math.sin( self.fAngle)*5)
462 InBuffer=InBuffer
477 InBuffer=InBuffer
463 self.datablock[i][k]= InBuffer
478 self.datablock[i][k]= InBuffer
464 #plot_cts(InBuffer,H0=H0,DH0=DH0)
479 #plot_cts(InBuffer,H0=H0,DH0=DH0)
465 #wave_fft(x=InBuffer,plot_show=True)
480 #wave_fft(x=InBuffer,plot_show=True)
466 #time.sleep(1)
481 #time.sleep(1)
467 #Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·DOPPLER SIGNAL...............................................
482 #Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·DOPPLER SIGNAL...............................................
468 time_vec = numpy.linspace(0,(prof_gen-1)*ippSec,int(prof_gen))+self.nReadBlocks*ippSec*prof_gen
483 time_vec = numpy.linspace(0,(prof_gen-1)*ippSec,int(prof_gen))+self.nReadBlocks*ippSec*prof_gen+(self.nReadFiles-1)*ippSec*prof_gen
469 fd = Fdoppler #+(600.0/120)*self.nReadBlocks
484 fd = Fdoppler #+(600.0/120)*self.nReadBlocks
470 d_signal = 650*numpy.array(numpy.exp(1.0j*2.0*math.pi*fd*time_vec),dtype=numpy.complex64)
485 d_signal = Adoppler*numpy.array(numpy.exp(1.0j*2.0*math.pi*fd*time_vec),dtype=numpy.complex64)
471 #Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β· DATABLOCK + DOPPLERΒ·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·...........................
486 #Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β· DATABLOCK + DOPPLERΒ·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·...........................
472 HD=int(Hdoppler/self.AcqDH_0)
487 HD=int(Hdoppler/self.AcqDH_0)
473 self.datablock[0,:,HD]=self.datablock[0,:,HD]+ d_signal # RESULT
488 for i in range(12):
489 self.datablock[:,:,HD+i]=self.datablock[:,:,HD+i]+ d_signal # RESULT
474 '''
490 '''
475 a= numpy.zeros(10)
491 a= numpy.zeros(10)
476 for i in range(10):
492 for i in range(10):
477 a[i]=i+self.nReadBlocks+20
493 a[i]=i+self.nReadBlocks+20
478 for i in a:
494 for i in a:
479 self.datablock[0,:,int(i)]=self.datablock[0,:,int(i)]+ d_signal # RESULT
495 self.datablock[0,:,int(i)]=self.datablock[0,:,int(i)]+ d_signal # RESULT
480 '''
496 '''
@@ -1,1266 +1,1266
1 import itertools
1 import itertools
2
2
3 import numpy
3 import numpy
4
4
5 from schainpy.model.proc.jroproc_base import ProcessingUnit, MPDecorator, Operation
5 from schainpy.model.proc.jroproc_base import ProcessingUnit, MPDecorator, Operation
6 from schainpy.model.data.jrodata import Spectra
6 from schainpy.model.data.jrodata import Spectra
7 from schainpy.model.data.jrodata import hildebrand_sekhon
7 from schainpy.model.data.jrodata import hildebrand_sekhon
8 from schainpy.utils import log
8 from schainpy.utils import log
9
9
10 @MPDecorator
10 @MPDecorator
11 class SpectraProc(ProcessingUnit):
11 class SpectraProc(ProcessingUnit):
12
12
13
13
14 def __init__(self):
14 def __init__(self):
15
15
16 ProcessingUnit.__init__(self)
16 ProcessingUnit.__init__(self)
17
17
18 self.buffer = None
18 self.buffer = None
19 self.firstdatatime = None
19 self.firstdatatime = None
20 self.profIndex = 0
20 self.profIndex = 0
21 self.dataOut = Spectra()
21 self.dataOut = Spectra()
22 self.id_min = None
22 self.id_min = None
23 self.id_max = None
23 self.id_max = None
24 self.setupReq = False #Agregar a todas las unidades de proc
24 self.setupReq = False #Agregar a todas las unidades de proc
25
25
26 def __updateSpecFromVoltage(self):
26 def __updateSpecFromVoltage(self):
27
27
28 self.dataOut.timeZone = self.dataIn.timeZone
28 self.dataOut.timeZone = self.dataIn.timeZone
29 self.dataOut.dstFlag = self.dataIn.dstFlag
29 self.dataOut.dstFlag = self.dataIn.dstFlag
30 self.dataOut.errorCount = self.dataIn.errorCount
30 self.dataOut.errorCount = self.dataIn.errorCount
31 self.dataOut.useLocalTime = self.dataIn.useLocalTime
31 self.dataOut.useLocalTime = self.dataIn.useLocalTime
32 try:
32 try:
33 self.dataOut.processingHeaderObj = self.dataIn.processingHeaderObj.copy()
33 self.dataOut.processingHeaderObj = self.dataIn.processingHeaderObj.copy()
34 except:
34 except:
35 pass
35 pass
36 self.dataOut.radarControllerHeaderObj = self.dataIn.radarControllerHeaderObj.copy()
36 self.dataOut.radarControllerHeaderObj = self.dataIn.radarControllerHeaderObj.copy()
37 self.dataOut.systemHeaderObj = self.dataIn.systemHeaderObj.copy()
37 self.dataOut.systemHeaderObj = self.dataIn.systemHeaderObj.copy()
38 self.dataOut.channelList = self.dataIn.channelList
38 self.dataOut.channelList = self.dataIn.channelList
39 self.dataOut.heightList = self.dataIn.heightList
39 self.dataOut.heightList = self.dataIn.heightList
40 self.dataOut.dtype = numpy.dtype([('real', '<f4'), ('imag', '<f4')])
40 self.dataOut.dtype = numpy.dtype([('real', '<f4'), ('imag', '<f4')])
41
41
42 self.dataOut.nBaud = self.dataIn.nBaud
42 self.dataOut.nBaud = self.dataIn.nBaud
43 self.dataOut.nCode = self.dataIn.nCode
43 self.dataOut.nCode = self.dataIn.nCode
44 self.dataOut.code = self.dataIn.code
44 self.dataOut.code = self.dataIn.code
45 self.dataOut.nProfiles = self.dataOut.nFFTPoints
45 self.dataOut.nProfiles = self.dataOut.nFFTPoints
46
46
47 self.dataOut.flagDiscontinuousBlock = self.dataIn.flagDiscontinuousBlock
47 self.dataOut.flagDiscontinuousBlock = self.dataIn.flagDiscontinuousBlock
48 self.dataOut.utctime = self.firstdatatime
48 self.dataOut.utctime = self.firstdatatime
49 # asumo q la data esta decodificada
49 # asumo q la data esta decodificada
50 self.dataOut.flagDecodeData = self.dataIn.flagDecodeData
50 self.dataOut.flagDecodeData = self.dataIn.flagDecodeData
51 # asumo q la data esta sin flip
51 # asumo q la data esta sin flip
52 self.dataOut.flagDeflipData = self.dataIn.flagDeflipData
52 self.dataOut.flagDeflipData = self.dataIn.flagDeflipData
53 self.dataOut.flagShiftFFT = False
53 self.dataOut.flagShiftFFT = False
54
54
55 self.dataOut.nCohInt = self.dataIn.nCohInt
55 self.dataOut.nCohInt = self.dataIn.nCohInt
56 self.dataOut.nIncohInt = 1
56 self.dataOut.nIncohInt = 1
57
57
58 self.dataOut.windowOfFilter = self.dataIn.windowOfFilter
58 self.dataOut.windowOfFilter = self.dataIn.windowOfFilter
59
59
60 self.dataOut.frequency = self.dataIn.frequency
60 self.dataOut.frequency = self.dataIn.frequency
61 self.dataOut.realtime = self.dataIn.realtime
61 self.dataOut.realtime = self.dataIn.realtime
62
62
63 self.dataOut.azimuth = self.dataIn.azimuth
63 self.dataOut.azimuth = self.dataIn.azimuth
64 self.dataOut.zenith = self.dataIn.zenith
64 self.dataOut.zenith = self.dataIn.zenith
65
65
66 self.dataOut.beam.codeList = self.dataIn.beam.codeList
66 self.dataOut.beam.codeList = self.dataIn.beam.codeList
67 self.dataOut.beam.azimuthList = self.dataIn.beam.azimuthList
67 self.dataOut.beam.azimuthList = self.dataIn.beam.azimuthList
68 self.dataOut.beam.zenithList = self.dataIn.beam.zenithList
68 self.dataOut.beam.zenithList = self.dataIn.beam.zenithList
69
69
70 def __getFft(self):
70 def __getFft(self):
71 """
71 """
72 Convierte valores de Voltaje a Spectra
72 Convierte valores de Voltaje a Spectra
73
73
74 Affected:
74 Affected:
75 self.dataOut.data_spc
75 self.dataOut.data_spc
76 self.dataOut.data_cspc
76 self.dataOut.data_cspc
77 self.dataOut.data_dc
77 self.dataOut.data_dc
78 self.dataOut.heightList
78 self.dataOut.heightList
79 self.profIndex
79 self.profIndex
80 self.buffer
80 self.buffer
81 self.dataOut.flagNoData
81 self.dataOut.flagNoData
82 """
82 """
83 fft_volt = numpy.fft.fft(
83 fft_volt = numpy.fft.fft(
84 self.buffer, n=self.dataOut.nFFTPoints, axis=1)
84 self.buffer, n=self.dataOut.nFFTPoints, axis=1)
85 fft_volt = fft_volt.astype(numpy.dtype('complex'))
85 fft_volt = fft_volt.astype(numpy.dtype('complex'))
86 dc = fft_volt[:, 0, :]
86 dc = fft_volt[:, 0, :]
87
87
88 # calculo de self-spectra
88 # calculo de self-spectra
89 fft_volt = numpy.fft.fftshift(fft_volt, axes=(1,))
89 fft_volt = numpy.fft.fftshift(fft_volt, axes=(1,))
90 spc = fft_volt * numpy.conjugate(fft_volt)
90 spc = fft_volt * numpy.conjugate(fft_volt)
91 #print("spcch0",spc[0])
91 #print("spcch0",spc[0])
92 spc = spc.real
92 spc = spc.real
93
93
94 blocksize = 0
94 blocksize = 0
95 blocksize += dc.size
95 blocksize += dc.size
96 blocksize += spc.size
96 blocksize += spc.size
97
97
98 #print("spc :",spc.shape)
98 #print("spc :",spc.shape)
99 data_wr = None
99 data_wr = None
100 if self.dataOut.flagWR:
100 if self.dataOut.flagWR:
101 data_wr = fft_volt
101 data_wr = self.buffer
102 blocksize = fft_volt.size
102 blocksize = fft_volt.size
103
103
104 cspc = None
104 cspc = None
105 pairIndex = 0
105 pairIndex = 0
106 if self.dataOut.pairsList != None:
106 if self.dataOut.pairsList != None:
107 # calculo de cross-spectra
107 # calculo de cross-spectra
108 cspc = numpy.zeros(
108 cspc = numpy.zeros(
109 (self.dataOut.nPairs, self.dataOut.nFFTPoints, self.dataOut.nHeights), dtype='complex')
109 (self.dataOut.nPairs, self.dataOut.nFFTPoints, self.dataOut.nHeights), dtype='complex')
110 for pair in self.dataOut.pairsList:
110 for pair in self.dataOut.pairsList:
111 if pair[0] not in self.dataOut.channelList:
111 if pair[0] not in self.dataOut.channelList:
112 raise ValueError("Error getting CrossSpectra: pair 0 of %s is not in channelList = %s" % (
112 raise ValueError("Error getting CrossSpectra: pair 0 of %s is not in channelList = %s" % (
113 str(pair), str(self.dataOut.channelList)))
113 str(pair), str(self.dataOut.channelList)))
114 if pair[1] not in self.dataOut.channelList:
114 if pair[1] not in self.dataOut.channelList:
115 raise ValueError("Error getting CrossSpectra: pair 1 of %s is not in channelList = %s" % (
115 raise ValueError("Error getting CrossSpectra: pair 1 of %s is not in channelList = %s" % (
116 str(pair), str(self.dataOut.channelList)))
116 str(pair), str(self.dataOut.channelList)))
117
117
118 cspc[pairIndex, :, :] = fft_volt[pair[0], :, :] * \
118 cspc[pairIndex, :, :] = fft_volt[pair[0], :, :] * \
119 numpy.conjugate(fft_volt[pair[1], :, :])
119 numpy.conjugate(fft_volt[pair[1], :, :])
120 pairIndex += 1
120 pairIndex += 1
121 blocksize += cspc.size
121 blocksize += cspc.size
122
122
123 self.dataOut.data_spc = spc
123 self.dataOut.data_spc = spc
124 self.dataOut.data_cspc = cspc
124 self.dataOut.data_cspc = cspc
125 self.dataOut.data_wr = data_wr
125 self.dataOut.data_wr = data_wr
126 self.dataOut.data_dc = dc
126 self.dataOut.data_dc = dc
127 self.dataOut.blockSize = blocksize
127 self.dataOut.blockSize = blocksize
128 self.dataOut.flagShiftFFT = False
128 self.dataOut.flagShiftFFT = False
129
129
130 def run(self, nProfiles=None, nFFTPoints=None, pairsList=[], ippFactor=None, shift_fft=False,flagWR= 0):
130 def run(self, nProfiles=None, nFFTPoints=None, pairsList=[], ippFactor=None, shift_fft=False,flagWR= 0):
131
131
132 self.dataOut.flagWR = flagWR
132 self.dataOut.flagWR = flagWR
133
133
134 if self.dataIn.type == "Spectra":
134 if self.dataIn.type == "Spectra":
135 self.dataOut.copy(self.dataIn)
135 self.dataOut.copy(self.dataIn)
136
136
137 if shift_fft:
137 if shift_fft:
138 #desplaza a la derecha en el eje 2 determinadas posiciones
138 #desplaza a la derecha en el eje 2 determinadas posiciones
139 shift = int(self.dataOut.nFFTPoints/2)
139 shift = int(self.dataOut.nFFTPoints/2)
140 self.dataOut.data_spc = numpy.roll(self.dataOut.data_spc, shift , axis=1)
140 self.dataOut.data_spc = numpy.roll(self.dataOut.data_spc, shift , axis=1)
141
141
142 if self.dataOut.data_cspc is not None:
142 if self.dataOut.data_cspc is not None:
143 #desplaza a la derecha en el eje 2 determinadas posiciones
143 #desplaza a la derecha en el eje 2 determinadas posiciones
144 self.dataOut.data_cspc = numpy.roll(self.dataOut.data_cspc, shift, axis=1)
144 self.dataOut.data_cspc = numpy.roll(self.dataOut.data_cspc, shift, axis=1)
145
145
146 return True
146 return True
147
147
148 if self.dataIn.type == "Voltage":
148 if self.dataIn.type == "Voltage":
149 #print("VOLTAGE INPUT SPECTRA")
149 #print("VOLTAGE INPUT SPECTRA")
150 self.dataOut.flagNoData = True
150 self.dataOut.flagNoData = True
151
151
152 if nFFTPoints == None:
152 if nFFTPoints == None:
153 raise ValueError("This SpectraProc.run() need nFFTPoints input variable")
153 raise ValueError("This SpectraProc.run() need nFFTPoints input variable")
154
154
155 if nProfiles == None:
155 if nProfiles == None:
156 nProfiles = nFFTPoints
156 nProfiles = nFFTPoints
157
157
158 if ippFactor == None:
158 if ippFactor == None:
159 ippFactor = 1
159 ippFactor = 1
160
160
161 self.dataOut.ippFactor = ippFactor
161 self.dataOut.ippFactor = ippFactor
162
162
163 self.dataOut.nFFTPoints = nFFTPoints
163 self.dataOut.nFFTPoints = nFFTPoints
164 self.dataOut.pairsList = pairsList
164 self.dataOut.pairsList = pairsList
165
165
166 if self.buffer is None:
166 if self.buffer is None:
167 self.buffer = numpy.zeros((self.dataIn.nChannels,
167 self.buffer = numpy.zeros((self.dataIn.nChannels,
168 nProfiles,
168 nProfiles,
169 self.dataIn.nHeights),
169 self.dataIn.nHeights),
170 dtype='complex')
170 dtype='complex')
171 #print("buffer :",self.buffer.shape)
171 #print("buffer :",self.buffer.shape)
172
172
173 if self.dataIn.flagDataAsBlock:
173 if self.dataIn.flagDataAsBlock:
174 nVoltProfiles = self.dataIn.data.shape[1]
174 nVoltProfiles = self.dataIn.data.shape[1]
175
175
176 if nVoltProfiles == nProfiles:
176 if nVoltProfiles == nProfiles:
177 self.buffer = self.dataIn.data.copy()
177 self.buffer = self.dataIn.data.copy()
178 self.profIndex = nVoltProfiles
178 self.profIndex = nVoltProfiles
179
179
180 elif nVoltProfiles < nProfiles:
180 elif nVoltProfiles < nProfiles:
181
181
182 if self.profIndex == 0:
182 if self.profIndex == 0:
183 self.id_min = 0
183 self.id_min = 0
184 self.id_max = nVoltProfiles
184 self.id_max = nVoltProfiles
185
185
186 self.buffer[:, self.id_min:self.id_max,
186 self.buffer[:, self.id_min:self.id_max,
187 :] = self.dataIn.data
187 :] = self.dataIn.data
188 self.profIndex += nVoltProfiles
188 self.profIndex += nVoltProfiles
189 self.id_min += nVoltProfiles
189 self.id_min += nVoltProfiles
190 self.id_max += nVoltProfiles
190 self.id_max += nVoltProfiles
191 else:
191 else:
192 raise ValueError("The type object %s has %d profiles, it should just has %d profiles" % (
192 raise ValueError("The type object %s has %d profiles, it should just has %d profiles" % (
193 self.dataIn.type, self.dataIn.data.shape[1], nProfiles))
193 self.dataIn.type, self.dataIn.data.shape[1], nProfiles))
194 self.dataOut.flagNoData = True
194 self.dataOut.flagNoData = True
195 return 0
195 return 0
196 else:
196 else:
197 #print("Spectra ",self.profIndex)
197 #print("Spectra ",self.profIndex)
198 self.buffer[:, self.profIndex, :] = self.dataIn.data.copy()
198 self.buffer[:, self.profIndex, :] = self.dataIn.data.copy()
199 self.profIndex += 1
199 self.profIndex += 1
200
200
201 if self.firstdatatime == None:
201 if self.firstdatatime == None:
202 self.firstdatatime = self.dataIn.utctime
202 self.firstdatatime = self.dataIn.utctime
203
203
204 if self.profIndex == nProfiles:
204 if self.profIndex == nProfiles:
205 self.__updateSpecFromVoltage()
205 self.__updateSpecFromVoltage()
206 self.__getFft()
206 self.__getFft()
207 #print(" DATAOUT SHAPE SPEC",self.dataOut.data_spc.shape)
207 #print(" DATAOUT SHAPE SPEC",self.dataOut.data_spc.shape)
208
208
209 self.dataOut.flagNoData = False
209 self.dataOut.flagNoData = False
210 self.firstdatatime = None
210 self.firstdatatime = None
211 self.profIndex = 0
211 self.profIndex = 0
212
212
213 return True
213 return True
214
214
215 raise ValueError("The type of input object '%s' is not valid" % (
215 raise ValueError("The type of input object '%s' is not valid" % (
216 self.dataIn.type))
216 self.dataIn.type))
217
217
218 def __selectPairs(self, pairsList):
218 def __selectPairs(self, pairsList):
219
219
220 if not pairsList:
220 if not pairsList:
221 return
221 return
222
222
223 pairs = []
223 pairs = []
224 pairsIndex = []
224 pairsIndex = []
225
225
226 for pair in pairsList:
226 for pair in pairsList:
227 if pair[0] not in self.dataOut.channelList or pair[1] not in self.dataOut.channelList:
227 if pair[0] not in self.dataOut.channelList or pair[1] not in self.dataOut.channelList:
228 continue
228 continue
229 pairs.append(pair)
229 pairs.append(pair)
230 pairsIndex.append(pairs.index(pair))
230 pairsIndex.append(pairs.index(pair))
231
231
232 self.dataOut.data_cspc = self.dataOut.data_cspc[pairsIndex]
232 self.dataOut.data_cspc = self.dataOut.data_cspc[pairsIndex]
233 self.dataOut.pairsList = pairs
233 self.dataOut.pairsList = pairs
234
234
235 return
235 return
236
236
237 def __selectPairsByChannel(self, channelList=None):
237 def __selectPairsByChannel(self, channelList=None):
238
238
239 if channelList == None:
239 if channelList == None:
240 return
240 return
241
241
242 pairsIndexListSelected = []
242 pairsIndexListSelected = []
243 for pairIndex in self.dataOut.pairsIndexList:
243 for pairIndex in self.dataOut.pairsIndexList:
244 # First pair
244 # First pair
245 if self.dataOut.pairsList[pairIndex][0] not in channelList:
245 if self.dataOut.pairsList[pairIndex][0] not in channelList:
246 continue
246 continue
247 # Second pair
247 # Second pair
248 if self.dataOut.pairsList[pairIndex][1] not in channelList:
248 if self.dataOut.pairsList[pairIndex][1] not in channelList:
249 continue
249 continue
250
250
251 pairsIndexListSelected.append(pairIndex)
251 pairsIndexListSelected.append(pairIndex)
252
252
253 if not pairsIndexListSelected:
253 if not pairsIndexListSelected:
254 self.dataOut.data_cspc = None
254 self.dataOut.data_cspc = None
255 self.dataOut.pairsList = []
255 self.dataOut.pairsList = []
256 return
256 return
257
257
258 self.dataOut.data_cspc = self.dataOut.data_cspc[pairsIndexListSelected]
258 self.dataOut.data_cspc = self.dataOut.data_cspc[pairsIndexListSelected]
259 self.dataOut.pairsList = [self.dataOut.pairsList[i]
259 self.dataOut.pairsList = [self.dataOut.pairsList[i]
260 for i in pairsIndexListSelected]
260 for i in pairsIndexListSelected]
261
261
262 return
262 return
263
263
264 def selectChannels(self, channelList):
264 def selectChannels(self, channelList):
265
265
266 channelIndexList = []
266 channelIndexList = []
267
267
268 for channel in channelList:
268 for channel in channelList:
269 if channel not in self.dataOut.channelList:
269 if channel not in self.dataOut.channelList:
270 raise ValueError("Error selecting channels, Channel %d is not valid.\nAvailable channels = %s" % (
270 raise ValueError("Error selecting channels, Channel %d is not valid.\nAvailable channels = %s" % (
271 channel, str(self.dataOut.channelList)))
271 channel, str(self.dataOut.channelList)))
272
272
273 index = self.dataOut.channelList.index(channel)
273 index = self.dataOut.channelList.index(channel)
274 channelIndexList.append(index)
274 channelIndexList.append(index)
275
275
276 self.selectChannelsByIndex(channelIndexList)
276 self.selectChannelsByIndex(channelIndexList)
277
277
278 def selectChannelsByIndex(self, channelIndexList):
278 def selectChannelsByIndex(self, channelIndexList):
279 """
279 """
280 Selecciona un bloque de datos en base a canales segun el channelIndexList
280 Selecciona un bloque de datos en base a canales segun el channelIndexList
281
281
282 Input:
282 Input:
283 channelIndexList : lista sencilla de canales a seleccionar por ej. [2,3,7]
283 channelIndexList : lista sencilla de canales a seleccionar por ej. [2,3,7]
284
284
285 Affected:
285 Affected:
286 self.dataOut.data_spc
286 self.dataOut.data_spc
287 self.dataOut.channelIndexList
287 self.dataOut.channelIndexList
288 self.dataOut.nChannels
288 self.dataOut.nChannels
289
289
290 Return:
290 Return:
291 None
291 None
292 """
292 """
293
293
294 for channelIndex in channelIndexList:
294 for channelIndex in channelIndexList:
295 if channelIndex not in self.dataOut.channelIndexList:
295 if channelIndex not in self.dataOut.channelIndexList:
296 raise ValueError("Error selecting channels: The value %d in channelIndexList is not valid.\nAvailable channel indexes = " % (
296 raise ValueError("Error selecting channels: The value %d in channelIndexList is not valid.\nAvailable channel indexes = " % (
297 channelIndex, self.dataOut.channelIndexList))
297 channelIndex, self.dataOut.channelIndexList))
298
298
299 data_spc = self.dataOut.data_spc[channelIndexList, :]
299 data_spc = self.dataOut.data_spc[channelIndexList, :]
300 data_dc = self.dataOut.data_dc[channelIndexList, :]
300 data_dc = self.dataOut.data_dc[channelIndexList, :]
301
301
302 self.dataOut.data_spc = data_spc
302 self.dataOut.data_spc = data_spc
303 self.dataOut.data_dc = data_dc
303 self.dataOut.data_dc = data_dc
304
304
305 # self.dataOut.channelList = [self.dataOut.channelList[i] for i in channelIndexList]
305 # self.dataOut.channelList = [self.dataOut.channelList[i] for i in channelIndexList]
306 self.dataOut.channelList = range(len(channelIndexList))
306 self.dataOut.channelList = range(len(channelIndexList))
307 self.__selectPairsByChannel(channelIndexList)
307 self.__selectPairsByChannel(channelIndexList)
308
308
309 return 1
309 return 1
310
310
311
311
312 def selectFFTs(self, minFFT, maxFFT ):
312 def selectFFTs(self, minFFT, maxFFT ):
313 """
313 """
314 Selecciona un bloque de datos en base a un grupo de valores de puntos FFTs segun el rango
314 Selecciona un bloque de datos en base a un grupo de valores de puntos FFTs segun el rango
315 minFFT<= FFT <= maxFFT
315 minFFT<= FFT <= maxFFT
316 """
316 """
317
317
318 if (minFFT > maxFFT):
318 if (minFFT > maxFFT):
319 raise ValueError("Error selecting heights: Height range (%d,%d) is not valid" % (minFFT, maxFFT))
319 raise ValueError("Error selecting heights: Height range (%d,%d) is not valid" % (minFFT, maxFFT))
320
320
321 if (minFFT < self.dataOut.getFreqRange()[0]):
321 if (minFFT < self.dataOut.getFreqRange()[0]):
322 minFFT = self.dataOut.getFreqRange()[0]
322 minFFT = self.dataOut.getFreqRange()[0]
323
323
324 if (maxFFT > self.dataOut.getFreqRange()[-1]):
324 if (maxFFT > self.dataOut.getFreqRange()[-1]):
325 maxFFT = self.dataOut.getFreqRange()[-1]
325 maxFFT = self.dataOut.getFreqRange()[-1]
326
326
327 minIndex = 0
327 minIndex = 0
328 maxIndex = 0
328 maxIndex = 0
329 FFTs = self.dataOut.getFreqRange()
329 FFTs = self.dataOut.getFreqRange()
330
330
331 inda = numpy.where(FFTs >= minFFT)
331 inda = numpy.where(FFTs >= minFFT)
332 indb = numpy.where(FFTs <= maxFFT)
332 indb = numpy.where(FFTs <= maxFFT)
333
333
334 try:
334 try:
335 minIndex = inda[0][0]
335 minIndex = inda[0][0]
336 except:
336 except:
337 minIndex = 0
337 minIndex = 0
338
338
339 try:
339 try:
340 maxIndex = indb[0][-1]
340 maxIndex = indb[0][-1]
341 except:
341 except:
342 maxIndex = len(FFTs)
342 maxIndex = len(FFTs)
343
343
344 self.selectFFTsByIndex(minIndex, maxIndex)
344 self.selectFFTsByIndex(minIndex, maxIndex)
345
345
346 return 1
346 return 1
347
347
348
348
349 def setH0(self, h0, deltaHeight = None):
349 def setH0(self, h0, deltaHeight = None):
350
350
351 if not deltaHeight:
351 if not deltaHeight:
352 deltaHeight = self.dataOut.heightList[1] - self.dataOut.heightList[0]
352 deltaHeight = self.dataOut.heightList[1] - self.dataOut.heightList[0]
353
353
354 nHeights = self.dataOut.nHeights
354 nHeights = self.dataOut.nHeights
355
355
356 newHeiRange = h0 + numpy.arange(nHeights)*deltaHeight
356 newHeiRange = h0 + numpy.arange(nHeights)*deltaHeight
357
357
358 self.dataOut.heightList = newHeiRange
358 self.dataOut.heightList = newHeiRange
359
359
360
360
361 def selectHeights(self, minHei, maxHei):
361 def selectHeights(self, minHei, maxHei):
362 """
362 """
363 Selecciona un bloque de datos en base a un grupo de valores de alturas segun el rango
363 Selecciona un bloque de datos en base a un grupo de valores de alturas segun el rango
364 minHei <= height <= maxHei
364 minHei <= height <= maxHei
365
365
366 Input:
366 Input:
367 minHei : valor minimo de altura a considerar
367 minHei : valor minimo de altura a considerar
368 maxHei : valor maximo de altura a considerar
368 maxHei : valor maximo de altura a considerar
369
369
370 Affected:
370 Affected:
371 Indirectamente son cambiados varios valores a travez del metodo selectHeightsByIndex
371 Indirectamente son cambiados varios valores a travez del metodo selectHeightsByIndex
372
372
373 Return:
373 Return:
374 1 si el metodo se ejecuto con exito caso contrario devuelve 0
374 1 si el metodo se ejecuto con exito caso contrario devuelve 0
375 """
375 """
376
376
377
377
378 if (minHei > maxHei):
378 if (minHei > maxHei):
379 raise ValueError("Error selecting heights: Height range (%d,%d) is not valid" % (minHei, maxHei))
379 raise ValueError("Error selecting heights: Height range (%d,%d) is not valid" % (minHei, maxHei))
380
380
381 if (minHei < self.dataOut.heightList[0]):
381 if (minHei < self.dataOut.heightList[0]):
382 minHei = self.dataOut.heightList[0]
382 minHei = self.dataOut.heightList[0]
383
383
384 if (maxHei > self.dataOut.heightList[-1]):
384 if (maxHei > self.dataOut.heightList[-1]):
385 maxHei = self.dataOut.heightList[-1]
385 maxHei = self.dataOut.heightList[-1]
386
386
387 minIndex = 0
387 minIndex = 0
388 maxIndex = 0
388 maxIndex = 0
389 heights = self.dataOut.heightList
389 heights = self.dataOut.heightList
390
390
391 inda = numpy.where(heights >= minHei)
391 inda = numpy.where(heights >= minHei)
392 indb = numpy.where(heights <= maxHei)
392 indb = numpy.where(heights <= maxHei)
393
393
394 try:
394 try:
395 minIndex = inda[0][0]
395 minIndex = inda[0][0]
396 except:
396 except:
397 minIndex = 0
397 minIndex = 0
398
398
399 try:
399 try:
400 maxIndex = indb[0][-1]
400 maxIndex = indb[0][-1]
401 except:
401 except:
402 maxIndex = len(heights)
402 maxIndex = len(heights)
403
403
404 self.selectHeightsByIndex(minIndex, maxIndex)
404 self.selectHeightsByIndex(minIndex, maxIndex)
405
405
406
406
407 return 1
407 return 1
408
408
409 def getBeaconSignal(self, tauindex=0, channelindex=0, hei_ref=None):
409 def getBeaconSignal(self, tauindex=0, channelindex=0, hei_ref=None):
410 newheis = numpy.where(
410 newheis = numpy.where(
411 self.dataOut.heightList > self.dataOut.radarControllerHeaderObj.Taus[tauindex])
411 self.dataOut.heightList > self.dataOut.radarControllerHeaderObj.Taus[tauindex])
412
412
413 if hei_ref != None:
413 if hei_ref != None:
414 newheis = numpy.where(self.dataOut.heightList > hei_ref)
414 newheis = numpy.where(self.dataOut.heightList > hei_ref)
415
415
416 minIndex = min(newheis[0])
416 minIndex = min(newheis[0])
417 maxIndex = max(newheis[0])
417 maxIndex = max(newheis[0])
418 data_spc = self.dataOut.data_spc[:, :, minIndex:maxIndex + 1]
418 data_spc = self.dataOut.data_spc[:, :, minIndex:maxIndex + 1]
419 heightList = self.dataOut.heightList[minIndex:maxIndex + 1]
419 heightList = self.dataOut.heightList[minIndex:maxIndex + 1]
420
420
421 # determina indices
421 # determina indices
422 nheis = int(self.dataOut.radarControllerHeaderObj.txB /
422 nheis = int(self.dataOut.radarControllerHeaderObj.txB /
423 (self.dataOut.heightList[1] - self.dataOut.heightList[0]))
423 (self.dataOut.heightList[1] - self.dataOut.heightList[0]))
424 avg_dB = 10 * \
424 avg_dB = 10 * \
425 numpy.log10(numpy.sum(data_spc[channelindex, :, :], axis=0))
425 numpy.log10(numpy.sum(data_spc[channelindex, :, :], axis=0))
426 beacon_dB = numpy.sort(avg_dB)[-nheis:]
426 beacon_dB = numpy.sort(avg_dB)[-nheis:]
427 beacon_heiIndexList = []
427 beacon_heiIndexList = []
428 for val in avg_dB.tolist():
428 for val in avg_dB.tolist():
429 if val >= beacon_dB[0]:
429 if val >= beacon_dB[0]:
430 beacon_heiIndexList.append(avg_dB.tolist().index(val))
430 beacon_heiIndexList.append(avg_dB.tolist().index(val))
431
431
432 #data_spc = data_spc[:,:,beacon_heiIndexList]
432 #data_spc = data_spc[:,:,beacon_heiIndexList]
433 data_cspc = None
433 data_cspc = None
434 if self.dataOut.data_cspc is not None:
434 if self.dataOut.data_cspc is not None:
435 data_cspc = self.dataOut.data_cspc[:, :, minIndex:maxIndex + 1]
435 data_cspc = self.dataOut.data_cspc[:, :, minIndex:maxIndex + 1]
436 #data_cspc = data_cspc[:,:,beacon_heiIndexList]
436 #data_cspc = data_cspc[:,:,beacon_heiIndexList]
437
437
438 data_dc = None
438 data_dc = None
439 if self.dataOut.data_dc is not None:
439 if self.dataOut.data_dc is not None:
440 data_dc = self.dataOut.data_dc[:, minIndex:maxIndex + 1]
440 data_dc = self.dataOut.data_dc[:, minIndex:maxIndex + 1]
441 #data_dc = data_dc[:,beacon_heiIndexList]
441 #data_dc = data_dc[:,beacon_heiIndexList]
442
442
443 self.dataOut.data_spc = data_spc
443 self.dataOut.data_spc = data_spc
444 self.dataOut.data_cspc = data_cspc
444 self.dataOut.data_cspc = data_cspc
445 self.dataOut.data_dc = data_dc
445 self.dataOut.data_dc = data_dc
446 self.dataOut.heightList = heightList
446 self.dataOut.heightList = heightList
447 self.dataOut.beacon_heiIndexList = beacon_heiIndexList
447 self.dataOut.beacon_heiIndexList = beacon_heiIndexList
448
448
449 return 1
449 return 1
450
450
451 def selectFFTsByIndex(self, minIndex, maxIndex):
451 def selectFFTsByIndex(self, minIndex, maxIndex):
452 """
452 """
453
453
454 """
454 """
455
455
456 if (minIndex < 0) or (minIndex > maxIndex):
456 if (minIndex < 0) or (minIndex > maxIndex):
457 raise ValueError("Error selecting heights: Index range (%d,%d) is not valid" % (minIndex, maxIndex))
457 raise ValueError("Error selecting heights: Index range (%d,%d) is not valid" % (minIndex, maxIndex))
458
458
459 if (maxIndex >= self.dataOut.nProfiles):
459 if (maxIndex >= self.dataOut.nProfiles):
460 maxIndex = self.dataOut.nProfiles-1
460 maxIndex = self.dataOut.nProfiles-1
461
461
462 #Spectra
462 #Spectra
463 data_spc = self.dataOut.data_spc[:,minIndex:maxIndex+1,:]
463 data_spc = self.dataOut.data_spc[:,minIndex:maxIndex+1,:]
464
464
465 data_cspc = None
465 data_cspc = None
466 if self.dataOut.data_cspc is not None:
466 if self.dataOut.data_cspc is not None:
467 data_cspc = self.dataOut.data_cspc[:,minIndex:maxIndex+1,:]
467 data_cspc = self.dataOut.data_cspc[:,minIndex:maxIndex+1,:]
468
468
469 data_dc = None
469 data_dc = None
470 if self.dataOut.data_dc is not None:
470 if self.dataOut.data_dc is not None:
471 data_dc = self.dataOut.data_dc[minIndex:maxIndex+1,:]
471 data_dc = self.dataOut.data_dc[minIndex:maxIndex+1,:]
472
472
473 self.dataOut.data_spc = data_spc
473 self.dataOut.data_spc = data_spc
474 self.dataOut.data_cspc = data_cspc
474 self.dataOut.data_cspc = data_cspc
475 self.dataOut.data_dc = data_dc
475 self.dataOut.data_dc = data_dc
476
476
477 self.dataOut.ippSeconds = self.dataOut.ippSeconds*(self.dataOut.nFFTPoints / numpy.shape(data_cspc)[1])
477 self.dataOut.ippSeconds = self.dataOut.ippSeconds*(self.dataOut.nFFTPoints / numpy.shape(data_cspc)[1])
478 self.dataOut.nFFTPoints = numpy.shape(data_cspc)[1]
478 self.dataOut.nFFTPoints = numpy.shape(data_cspc)[1]
479 self.dataOut.profilesPerBlock = numpy.shape(data_cspc)[1]
479 self.dataOut.profilesPerBlock = numpy.shape(data_cspc)[1]
480
480
481 return 1
481 return 1
482
482
483
483
484
484
485 def selectHeightsByIndex(self, minIndex, maxIndex):
485 def selectHeightsByIndex(self, minIndex, maxIndex):
486 """
486 """
487 Selecciona un bloque de datos en base a un grupo indices de alturas segun el rango
487 Selecciona un bloque de datos en base a un grupo indices de alturas segun el rango
488 minIndex <= index <= maxIndex
488 minIndex <= index <= maxIndex
489
489
490 Input:
490 Input:
491 minIndex : valor de indice minimo de altura a considerar
491 minIndex : valor de indice minimo de altura a considerar
492 maxIndex : valor de indice maximo de altura a considerar
492 maxIndex : valor de indice maximo de altura a considerar
493
493
494 Affected:
494 Affected:
495 self.dataOut.data_spc
495 self.dataOut.data_spc
496 self.dataOut.data_cspc
496 self.dataOut.data_cspc
497 self.dataOut.data_dc
497 self.dataOut.data_dc
498 self.dataOut.heightList
498 self.dataOut.heightList
499
499
500 Return:
500 Return:
501 1 si el metodo se ejecuto con exito caso contrario devuelve 0
501 1 si el metodo se ejecuto con exito caso contrario devuelve 0
502 """
502 """
503
503
504 if (minIndex < 0) or (minIndex > maxIndex):
504 if (minIndex < 0) or (minIndex > maxIndex):
505 raise ValueError("Error selecting heights: Index range (%d,%d) is not valid" % (
505 raise ValueError("Error selecting heights: Index range (%d,%d) is not valid" % (
506 minIndex, maxIndex))
506 minIndex, maxIndex))
507
507
508 if (maxIndex >= self.dataOut.nHeights):
508 if (maxIndex >= self.dataOut.nHeights):
509 maxIndex = self.dataOut.nHeights - 1
509 maxIndex = self.dataOut.nHeights - 1
510
510
511 # Spectra
511 # Spectra
512 data_spc = self.dataOut.data_spc[:, :, minIndex:maxIndex + 1]
512 data_spc = self.dataOut.data_spc[:, :, minIndex:maxIndex + 1]
513
513
514 data_cspc = None
514 data_cspc = None
515 if self.dataOut.data_cspc is not None:
515 if self.dataOut.data_cspc is not None:
516 data_cspc = self.dataOut.data_cspc[:, :, minIndex:maxIndex + 1]
516 data_cspc = self.dataOut.data_cspc[:, :, minIndex:maxIndex + 1]
517
517
518 data_dc = None
518 data_dc = None
519 if self.dataOut.data_dc is not None:
519 if self.dataOut.data_dc is not None:
520 data_dc = self.dataOut.data_dc[:, minIndex:maxIndex + 1]
520 data_dc = self.dataOut.data_dc[:, minIndex:maxIndex + 1]
521
521
522 self.dataOut.data_spc = data_spc
522 self.dataOut.data_spc = data_spc
523 self.dataOut.data_cspc = data_cspc
523 self.dataOut.data_cspc = data_cspc
524 self.dataOut.data_dc = data_dc
524 self.dataOut.data_dc = data_dc
525
525
526 self.dataOut.heightList = self.dataOut.heightList[minIndex:maxIndex + 1]
526 self.dataOut.heightList = self.dataOut.heightList[minIndex:maxIndex + 1]
527
527
528 return 1
528 return 1
529
529
530 def removeDC(self, mode=2):
530 def removeDC(self, mode=2):
531 jspectra = self.dataOut.data_spc
531 jspectra = self.dataOut.data_spc
532 jcspectra = self.dataOut.data_cspc
532 jcspectra = self.dataOut.data_cspc
533
533
534 num_chan = jspectra.shape[0]
534 num_chan = jspectra.shape[0]
535 num_hei = jspectra.shape[2]
535 num_hei = jspectra.shape[2]
536
536
537 if jcspectra is not None:
537 if jcspectra is not None:
538 jcspectraExist = True
538 jcspectraExist = True
539 num_pairs = jcspectra.shape[0]
539 num_pairs = jcspectra.shape[0]
540 else:
540 else:
541 jcspectraExist = False
541 jcspectraExist = False
542
542
543 freq_dc = int(jspectra.shape[1] / 2)
543 freq_dc = int(jspectra.shape[1] / 2)
544 ind_vel = numpy.array([-2, -1, 1, 2]) + freq_dc
544 ind_vel = numpy.array([-2, -1, 1, 2]) + freq_dc
545 ind_vel = ind_vel.astype(int)
545 ind_vel = ind_vel.astype(int)
546
546
547 if ind_vel[0] < 0:
547 if ind_vel[0] < 0:
548 ind_vel[list(range(0, 1))] = ind_vel[list(range(0, 1))] + self.num_prof
548 ind_vel[list(range(0, 1))] = ind_vel[list(range(0, 1))] + self.num_prof
549
549
550 if mode == 1:
550 if mode == 1:
551 jspectra[:, freq_dc, :] = (
551 jspectra[:, freq_dc, :] = (
552 jspectra[:, ind_vel[1], :] + jspectra[:, ind_vel[2], :]) / 2 # CORRECCION
552 jspectra[:, ind_vel[1], :] + jspectra[:, ind_vel[2], :]) / 2 # CORRECCION
553
553
554 if jcspectraExist:
554 if jcspectraExist:
555 jcspectra[:, freq_dc, :] = (
555 jcspectra[:, freq_dc, :] = (
556 jcspectra[:, ind_vel[1], :] + jcspectra[:, ind_vel[2], :]) / 2
556 jcspectra[:, ind_vel[1], :] + jcspectra[:, ind_vel[2], :]) / 2
557
557
558 if mode == 2:
558 if mode == 2:
559
559
560 vel = numpy.array([-2, -1, 1, 2])
560 vel = numpy.array([-2, -1, 1, 2])
561 xx = numpy.zeros([4, 4])
561 xx = numpy.zeros([4, 4])
562
562
563 for fil in range(4):
563 for fil in range(4):
564 xx[fil, :] = vel[fil]**numpy.asarray(list(range(4)))
564 xx[fil, :] = vel[fil]**numpy.asarray(list(range(4)))
565
565
566 xx_inv = numpy.linalg.inv(xx)
566 xx_inv = numpy.linalg.inv(xx)
567 xx_aux = xx_inv[0, :]
567 xx_aux = xx_inv[0, :]
568
568
569 for ich in range(num_chan):
569 for ich in range(num_chan):
570 yy = jspectra[ich, ind_vel, :]
570 yy = jspectra[ich, ind_vel, :]
571 jspectra[ich, freq_dc, :] = numpy.dot(xx_aux, yy)
571 jspectra[ich, freq_dc, :] = numpy.dot(xx_aux, yy)
572
572
573 junkid = jspectra[ich, freq_dc, :] <= 0
573 junkid = jspectra[ich, freq_dc, :] <= 0
574 cjunkid = sum(junkid)
574 cjunkid = sum(junkid)
575
575
576 if cjunkid.any():
576 if cjunkid.any():
577 jspectra[ich, freq_dc, junkid.nonzero()] = (
577 jspectra[ich, freq_dc, junkid.nonzero()] = (
578 jspectra[ich, ind_vel[1], junkid] + jspectra[ich, ind_vel[2], junkid]) / 2
578 jspectra[ich, ind_vel[1], junkid] + jspectra[ich, ind_vel[2], junkid]) / 2
579
579
580 if jcspectraExist:
580 if jcspectraExist:
581 for ip in range(num_pairs):
581 for ip in range(num_pairs):
582 yy = jcspectra[ip, ind_vel, :]
582 yy = jcspectra[ip, ind_vel, :]
583 jcspectra[ip, freq_dc, :] = numpy.dot(xx_aux, yy)
583 jcspectra[ip, freq_dc, :] = numpy.dot(xx_aux, yy)
584
584
585 self.dataOut.data_spc = jspectra
585 self.dataOut.data_spc = jspectra
586 self.dataOut.data_cspc = jcspectra
586 self.dataOut.data_cspc = jcspectra
587
587
588 return 1
588 return 1
589
589
590 def removeInterference2(self):
590 def removeInterference2(self):
591
591
592 cspc = self.dataOut.data_cspc
592 cspc = self.dataOut.data_cspc
593 spc = self.dataOut.data_spc
593 spc = self.dataOut.data_spc
594 Heights = numpy.arange(cspc.shape[2])
594 Heights = numpy.arange(cspc.shape[2])
595 realCspc = numpy.abs(cspc)
595 realCspc = numpy.abs(cspc)
596
596
597 for i in range(cspc.shape[0]):
597 for i in range(cspc.shape[0]):
598 LinePower= numpy.sum(realCspc[i], axis=0)
598 LinePower= numpy.sum(realCspc[i], axis=0)
599 Threshold = numpy.amax(LinePower)-numpy.sort(LinePower)[len(Heights)-int(len(Heights)*0.1)]
599 Threshold = numpy.amax(LinePower)-numpy.sort(LinePower)[len(Heights)-int(len(Heights)*0.1)]
600 SelectedHeights = Heights[ numpy.where( LinePower < Threshold ) ]
600 SelectedHeights = Heights[ numpy.where( LinePower < Threshold ) ]
601 InterferenceSum = numpy.sum( realCspc[i,:,SelectedHeights], axis=0 )
601 InterferenceSum = numpy.sum( realCspc[i,:,SelectedHeights], axis=0 )
602 InterferenceThresholdMin = numpy.sort(InterferenceSum)[int(len(InterferenceSum)*0.98)]
602 InterferenceThresholdMin = numpy.sort(InterferenceSum)[int(len(InterferenceSum)*0.98)]
603 InterferenceThresholdMax = numpy.sort(InterferenceSum)[int(len(InterferenceSum)*0.99)]
603 InterferenceThresholdMax = numpy.sort(InterferenceSum)[int(len(InterferenceSum)*0.99)]
604
604
605
605
606 InterferenceRange = numpy.where( ([InterferenceSum > InterferenceThresholdMin]))# , InterferenceSum < InterferenceThresholdMax]) )
606 InterferenceRange = numpy.where( ([InterferenceSum > InterferenceThresholdMin]))# , InterferenceSum < InterferenceThresholdMax]) )
607 #InterferenceRange = numpy.where( ([InterferenceRange < InterferenceThresholdMax]))
607 #InterferenceRange = numpy.where( ([InterferenceRange < InterferenceThresholdMax]))
608 if len(InterferenceRange)<int(cspc.shape[1]*0.3):
608 if len(InterferenceRange)<int(cspc.shape[1]*0.3):
609 cspc[i,InterferenceRange,:] = numpy.NaN
609 cspc[i,InterferenceRange,:] = numpy.NaN
610
610
611
611
612
612
613 self.dataOut.data_cspc = cspc
613 self.dataOut.data_cspc = cspc
614
614
615 def removeInterference(self, interf = 2,hei_interf = None, nhei_interf = None, offhei_interf = None):
615 def removeInterference(self, interf = 2,hei_interf = None, nhei_interf = None, offhei_interf = None):
616
616
617 jspectra = self.dataOut.data_spc
617 jspectra = self.dataOut.data_spc
618 jcspectra = self.dataOut.data_cspc
618 jcspectra = self.dataOut.data_cspc
619 jnoise = self.dataOut.getNoise()
619 jnoise = self.dataOut.getNoise()
620 num_incoh = self.dataOut.nIncohInt
620 num_incoh = self.dataOut.nIncohInt
621
621
622 num_channel = jspectra.shape[0]
622 num_channel = jspectra.shape[0]
623 num_prof = jspectra.shape[1]
623 num_prof = jspectra.shape[1]
624 num_hei = jspectra.shape[2]
624 num_hei = jspectra.shape[2]
625
625
626 # hei_interf
626 # hei_interf
627 if hei_interf is None:
627 if hei_interf is None:
628 count_hei = int(num_hei / 2)
628 count_hei = int(num_hei / 2)
629 hei_interf = numpy.asmatrix(list(range(count_hei))) + num_hei - count_hei
629 hei_interf = numpy.asmatrix(list(range(count_hei))) + num_hei - count_hei
630 hei_interf = numpy.asarray(hei_interf)[0]
630 hei_interf = numpy.asarray(hei_interf)[0]
631 # nhei_interf
631 # nhei_interf
632 if (nhei_interf == None):
632 if (nhei_interf == None):
633 nhei_interf = 5
633 nhei_interf = 5
634 if (nhei_interf < 1):
634 if (nhei_interf < 1):
635 nhei_interf = 1
635 nhei_interf = 1
636 if (nhei_interf > count_hei):
636 if (nhei_interf > count_hei):
637 nhei_interf = count_hei
637 nhei_interf = count_hei
638 if (offhei_interf == None):
638 if (offhei_interf == None):
639 offhei_interf = 0
639 offhei_interf = 0
640
640
641 ind_hei = list(range(num_hei))
641 ind_hei = list(range(num_hei))
642 # mask_prof = numpy.asarray(range(num_prof - 2)) + 1
642 # mask_prof = numpy.asarray(range(num_prof - 2)) + 1
643 # mask_prof[range(num_prof/2 - 1,len(mask_prof))] += 1
643 # mask_prof[range(num_prof/2 - 1,len(mask_prof))] += 1
644 mask_prof = numpy.asarray(list(range(num_prof)))
644 mask_prof = numpy.asarray(list(range(num_prof)))
645 num_mask_prof = mask_prof.size
645 num_mask_prof = mask_prof.size
646 comp_mask_prof = [0, num_prof / 2]
646 comp_mask_prof = [0, num_prof / 2]
647
647
648 # noise_exist: Determina si la variable jnoise ha sido definida y contiene la informacion del ruido de cada canal
648 # noise_exist: Determina si la variable jnoise ha sido definida y contiene la informacion del ruido de cada canal
649 if (jnoise.size < num_channel or numpy.isnan(jnoise).any()):
649 if (jnoise.size < num_channel or numpy.isnan(jnoise).any()):
650 jnoise = numpy.nan
650 jnoise = numpy.nan
651 noise_exist = jnoise[0] < numpy.Inf
651 noise_exist = jnoise[0] < numpy.Inf
652
652
653 # Subrutina de Remocion de la Interferencia
653 # Subrutina de Remocion de la Interferencia
654 for ich in range(num_channel):
654 for ich in range(num_channel):
655 # Se ordena los espectros segun su potencia (menor a mayor)
655 # Se ordena los espectros segun su potencia (menor a mayor)
656 power = jspectra[ich, mask_prof, :]
656 power = jspectra[ich, mask_prof, :]
657 power = power[:, hei_interf]
657 power = power[:, hei_interf]
658 power = power.sum(axis=0)
658 power = power.sum(axis=0)
659 psort = power.ravel().argsort()
659 psort = power.ravel().argsort()
660
660
661 # Se estima la interferencia promedio en los Espectros de Potencia empleando
661 # Se estima la interferencia promedio en los Espectros de Potencia empleando
662 junkspc_interf = jspectra[ich, :, hei_interf[psort[list(range(
662 junkspc_interf = jspectra[ich, :, hei_interf[psort[list(range(
663 offhei_interf, nhei_interf + offhei_interf))]]]
663 offhei_interf, nhei_interf + offhei_interf))]]]
664
664
665 if noise_exist:
665 if noise_exist:
666 # tmp_noise = jnoise[ich] / num_prof
666 # tmp_noise = jnoise[ich] / num_prof
667 tmp_noise = jnoise[ich]
667 tmp_noise = jnoise[ich]
668 junkspc_interf = junkspc_interf - tmp_noise
668 junkspc_interf = junkspc_interf - tmp_noise
669 #junkspc_interf[:,comp_mask_prof] = 0
669 #junkspc_interf[:,comp_mask_prof] = 0
670
670
671 jspc_interf = junkspc_interf.sum(axis=0) / nhei_interf
671 jspc_interf = junkspc_interf.sum(axis=0) / nhei_interf
672 jspc_interf = jspc_interf.transpose()
672 jspc_interf = jspc_interf.transpose()
673 # Calculando el espectro de interferencia promedio
673 # Calculando el espectro de interferencia promedio
674 noiseid = numpy.where(
674 noiseid = numpy.where(
675 jspc_interf <= tmp_noise / numpy.sqrt(num_incoh))
675 jspc_interf <= tmp_noise / numpy.sqrt(num_incoh))
676 noiseid = noiseid[0]
676 noiseid = noiseid[0]
677 cnoiseid = noiseid.size
677 cnoiseid = noiseid.size
678 interfid = numpy.where(
678 interfid = numpy.where(
679 jspc_interf > tmp_noise / numpy.sqrt(num_incoh))
679 jspc_interf > tmp_noise / numpy.sqrt(num_incoh))
680 interfid = interfid[0]
680 interfid = interfid[0]
681 cinterfid = interfid.size
681 cinterfid = interfid.size
682
682
683 if (cnoiseid > 0):
683 if (cnoiseid > 0):
684 jspc_interf[noiseid] = 0
684 jspc_interf[noiseid] = 0
685
685
686 # Expandiendo los perfiles a limpiar
686 # Expandiendo los perfiles a limpiar
687 if (cinterfid > 0):
687 if (cinterfid > 0):
688 new_interfid = (
688 new_interfid = (
689 numpy.r_[interfid - 1, interfid, interfid + 1] + num_prof) % num_prof
689 numpy.r_[interfid - 1, interfid, interfid + 1] + num_prof) % num_prof
690 new_interfid = numpy.asarray(new_interfid)
690 new_interfid = numpy.asarray(new_interfid)
691 new_interfid = {x for x in new_interfid}
691 new_interfid = {x for x in new_interfid}
692 new_interfid = numpy.array(list(new_interfid))
692 new_interfid = numpy.array(list(new_interfid))
693 new_cinterfid = new_interfid.size
693 new_cinterfid = new_interfid.size
694 else:
694 else:
695 new_cinterfid = 0
695 new_cinterfid = 0
696
696
697 for ip in range(new_cinterfid):
697 for ip in range(new_cinterfid):
698 ind = junkspc_interf[:, new_interfid[ip]].ravel().argsort()
698 ind = junkspc_interf[:, new_interfid[ip]].ravel().argsort()
699 jspc_interf[new_interfid[ip]
699 jspc_interf[new_interfid[ip]
700 ] = junkspc_interf[ind[nhei_interf // 2], new_interfid[ip]]
700 ] = junkspc_interf[ind[nhei_interf // 2], new_interfid[ip]]
701
701
702 jspectra[ich, :, ind_hei] = jspectra[ich, :,
702 jspectra[ich, :, ind_hei] = jspectra[ich, :,
703 ind_hei] - jspc_interf # Corregir indices
703 ind_hei] - jspc_interf # Corregir indices
704
704
705 # Removiendo la interferencia del punto de mayor interferencia
705 # Removiendo la interferencia del punto de mayor interferencia
706 ListAux = jspc_interf[mask_prof].tolist()
706 ListAux = jspc_interf[mask_prof].tolist()
707 maxid = ListAux.index(max(ListAux))
707 maxid = ListAux.index(max(ListAux))
708
708
709 if cinterfid > 0:
709 if cinterfid > 0:
710 for ip in range(cinterfid * (interf == 2) - 1):
710 for ip in range(cinterfid * (interf == 2) - 1):
711 ind = (jspectra[ich, interfid[ip], :] < tmp_noise *
711 ind = (jspectra[ich, interfid[ip], :] < tmp_noise *
712 (1 + 1 / numpy.sqrt(num_incoh))).nonzero()
712 (1 + 1 / numpy.sqrt(num_incoh))).nonzero()
713 cind = len(ind)
713 cind = len(ind)
714
714
715 if (cind > 0):
715 if (cind > 0):
716 jspectra[ich, interfid[ip], ind] = tmp_noise * \
716 jspectra[ich, interfid[ip], ind] = tmp_noise * \
717 (1 + (numpy.random.uniform(cind) - 0.5) /
717 (1 + (numpy.random.uniform(cind) - 0.5) /
718 numpy.sqrt(num_incoh))
718 numpy.sqrt(num_incoh))
719
719
720 ind = numpy.array([-2, -1, 1, 2])
720 ind = numpy.array([-2, -1, 1, 2])
721 xx = numpy.zeros([4, 4])
721 xx = numpy.zeros([4, 4])
722
722
723 for id1 in range(4):
723 for id1 in range(4):
724 xx[:, id1] = ind[id1]**numpy.asarray(list(range(4)))
724 xx[:, id1] = ind[id1]**numpy.asarray(list(range(4)))
725
725
726 xx_inv = numpy.linalg.inv(xx)
726 xx_inv = numpy.linalg.inv(xx)
727 xx = xx_inv[:, 0]
727 xx = xx_inv[:, 0]
728 ind = (ind + maxid + num_mask_prof) % num_mask_prof
728 ind = (ind + maxid + num_mask_prof) % num_mask_prof
729 yy = jspectra[ich, mask_prof[ind], :]
729 yy = jspectra[ich, mask_prof[ind], :]
730 jspectra[ich, mask_prof[maxid], :] = numpy.dot(
730 jspectra[ich, mask_prof[maxid], :] = numpy.dot(
731 yy.transpose(), xx)
731 yy.transpose(), xx)
732
732
733 indAux = (jspectra[ich, :, :] < tmp_noise *
733 indAux = (jspectra[ich, :, :] < tmp_noise *
734 (1 - 1 / numpy.sqrt(num_incoh))).nonzero()
734 (1 - 1 / numpy.sqrt(num_incoh))).nonzero()
735 jspectra[ich, indAux[0], indAux[1]] = tmp_noise * \
735 jspectra[ich, indAux[0], indAux[1]] = tmp_noise * \
736 (1 - 1 / numpy.sqrt(num_incoh))
736 (1 - 1 / numpy.sqrt(num_incoh))
737
737
738 # Remocion de Interferencia en el Cross Spectra
738 # Remocion de Interferencia en el Cross Spectra
739 if jcspectra is None:
739 if jcspectra is None:
740 return jspectra, jcspectra
740 return jspectra, jcspectra
741 num_pairs = int(jcspectra.size / (num_prof * num_hei))
741 num_pairs = int(jcspectra.size / (num_prof * num_hei))
742 jcspectra = jcspectra.reshape(num_pairs, num_prof, num_hei)
742 jcspectra = jcspectra.reshape(num_pairs, num_prof, num_hei)
743
743
744 for ip in range(num_pairs):
744 for ip in range(num_pairs):
745
745
746 #-------------------------------------------
746 #-------------------------------------------
747
747
748 cspower = numpy.abs(jcspectra[ip, mask_prof, :])
748 cspower = numpy.abs(jcspectra[ip, mask_prof, :])
749 cspower = cspower[:, hei_interf]
749 cspower = cspower[:, hei_interf]
750 cspower = cspower.sum(axis=0)
750 cspower = cspower.sum(axis=0)
751
751
752 cspsort = cspower.ravel().argsort()
752 cspsort = cspower.ravel().argsort()
753 junkcspc_interf = jcspectra[ip, :, hei_interf[cspsort[list(range(
753 junkcspc_interf = jcspectra[ip, :, hei_interf[cspsort[list(range(
754 offhei_interf, nhei_interf + offhei_interf))]]]
754 offhei_interf, nhei_interf + offhei_interf))]]]
755 junkcspc_interf = junkcspc_interf.transpose()
755 junkcspc_interf = junkcspc_interf.transpose()
756 jcspc_interf = junkcspc_interf.sum(axis=1) / nhei_interf
756 jcspc_interf = junkcspc_interf.sum(axis=1) / nhei_interf
757
757
758 ind = numpy.abs(jcspc_interf[mask_prof]).ravel().argsort()
758 ind = numpy.abs(jcspc_interf[mask_prof]).ravel().argsort()
759
759
760 median_real = int(numpy.median(numpy.real(
760 median_real = int(numpy.median(numpy.real(
761 junkcspc_interf[mask_prof[ind[list(range(3 * num_prof // 4))]], :])))
761 junkcspc_interf[mask_prof[ind[list(range(3 * num_prof // 4))]], :])))
762 median_imag = int(numpy.median(numpy.imag(
762 median_imag = int(numpy.median(numpy.imag(
763 junkcspc_interf[mask_prof[ind[list(range(3 * num_prof // 4))]], :])))
763 junkcspc_interf[mask_prof[ind[list(range(3 * num_prof // 4))]], :])))
764 comp_mask_prof = [int(e) for e in comp_mask_prof]
764 comp_mask_prof = [int(e) for e in comp_mask_prof]
765 junkcspc_interf[comp_mask_prof, :] = numpy.complex(
765 junkcspc_interf[comp_mask_prof, :] = numpy.complex(
766 median_real, median_imag)
766 median_real, median_imag)
767
767
768 for iprof in range(num_prof):
768 for iprof in range(num_prof):
769 ind = numpy.abs(junkcspc_interf[iprof, :]).ravel().argsort()
769 ind = numpy.abs(junkcspc_interf[iprof, :]).ravel().argsort()
770 jcspc_interf[iprof] = junkcspc_interf[iprof, ind[nhei_interf // 2]]
770 jcspc_interf[iprof] = junkcspc_interf[iprof, ind[nhei_interf // 2]]
771
771
772 # Removiendo la Interferencia
772 # Removiendo la Interferencia
773 jcspectra[ip, :, ind_hei] = jcspectra[ip,
773 jcspectra[ip, :, ind_hei] = jcspectra[ip,
774 :, ind_hei] - jcspc_interf
774 :, ind_hei] - jcspc_interf
775
775
776 ListAux = numpy.abs(jcspc_interf[mask_prof]).tolist()
776 ListAux = numpy.abs(jcspc_interf[mask_prof]).tolist()
777 maxid = ListAux.index(max(ListAux))
777 maxid = ListAux.index(max(ListAux))
778
778
779 ind = numpy.array([-2, -1, 1, 2])
779 ind = numpy.array([-2, -1, 1, 2])
780 xx = numpy.zeros([4, 4])
780 xx = numpy.zeros([4, 4])
781
781
782 for id1 in range(4):
782 for id1 in range(4):
783 xx[:, id1] = ind[id1]**numpy.asarray(list(range(4)))
783 xx[:, id1] = ind[id1]**numpy.asarray(list(range(4)))
784
784
785 xx_inv = numpy.linalg.inv(xx)
785 xx_inv = numpy.linalg.inv(xx)
786 xx = xx_inv[:, 0]
786 xx = xx_inv[:, 0]
787
787
788 ind = (ind + maxid + num_mask_prof) % num_mask_prof
788 ind = (ind + maxid + num_mask_prof) % num_mask_prof
789 yy = jcspectra[ip, mask_prof[ind], :]
789 yy = jcspectra[ip, mask_prof[ind], :]
790 jcspectra[ip, mask_prof[maxid], :] = numpy.dot(yy.transpose(), xx)
790 jcspectra[ip, mask_prof[maxid], :] = numpy.dot(yy.transpose(), xx)
791
791
792 # Guardar Resultados
792 # Guardar Resultados
793 self.dataOut.data_spc = jspectra
793 self.dataOut.data_spc = jspectra
794 self.dataOut.data_cspc = jcspectra
794 self.dataOut.data_cspc = jcspectra
795
795
796 return 1
796 return 1
797
797
798 def setRadarFrequency(self, frequency=None):
798 def setRadarFrequency(self, frequency=None):
799
799
800 if frequency != None:
800 if frequency != None:
801 self.dataOut.frequency = frequency
801 self.dataOut.frequency = frequency
802
802
803 return 1
803 return 1
804
804
805 def getNoise(self, minHei=None, maxHei=None, minVel=None, maxVel=None):
805 def getNoise(self, minHei=None, maxHei=None, minVel=None, maxVel=None):
806 # validacion de rango
806 # validacion de rango
807 if minHei == None:
807 if minHei == None:
808 minHei = self.dataOut.heightList[0]
808 minHei = self.dataOut.heightList[0]
809
809
810 if maxHei == None:
810 if maxHei == None:
811 maxHei = self.dataOut.heightList[-1]
811 maxHei = self.dataOut.heightList[-1]
812
812
813 if (minHei < self.dataOut.heightList[0]) or (minHei > maxHei):
813 if (minHei < self.dataOut.heightList[0]) or (minHei > maxHei):
814 print('minHei: %.2f is out of the heights range' % (minHei))
814 print('minHei: %.2f is out of the heights range' % (minHei))
815 print('minHei is setting to %.2f' % (self.dataOut.heightList[0]))
815 print('minHei is setting to %.2f' % (self.dataOut.heightList[0]))
816 minHei = self.dataOut.heightList[0]
816 minHei = self.dataOut.heightList[0]
817
817
818 if (maxHei > self.dataOut.heightList[-1]) or (maxHei < minHei):
818 if (maxHei > self.dataOut.heightList[-1]) or (maxHei < minHei):
819 print('maxHei: %.2f is out of the heights range' % (maxHei))
819 print('maxHei: %.2f is out of the heights range' % (maxHei))
820 print('maxHei is setting to %.2f' % (self.dataOut.heightList[-1]))
820 print('maxHei is setting to %.2f' % (self.dataOut.heightList[-1]))
821 maxHei = self.dataOut.heightList[-1]
821 maxHei = self.dataOut.heightList[-1]
822
822
823 # validacion de velocidades
823 # validacion de velocidades
824 velrange = self.dataOut.getVelRange(1)
824 velrange = self.dataOut.getVelRange(1)
825
825
826 if minVel == None:
826 if minVel == None:
827 minVel = velrange[0]
827 minVel = velrange[0]
828
828
829 if maxVel == None:
829 if maxVel == None:
830 maxVel = velrange[-1]
830 maxVel = velrange[-1]
831
831
832 if (minVel < velrange[0]) or (minVel > maxVel):
832 if (minVel < velrange[0]) or (minVel > maxVel):
833 print('minVel: %.2f is out of the velocity range' % (minVel))
833 print('minVel: %.2f is out of the velocity range' % (minVel))
834 print('minVel is setting to %.2f' % (velrange[0]))
834 print('minVel is setting to %.2f' % (velrange[0]))
835 minVel = velrange[0]
835 minVel = velrange[0]
836
836
837 if (maxVel > velrange[-1]) or (maxVel < minVel):
837 if (maxVel > velrange[-1]) or (maxVel < minVel):
838 print('maxVel: %.2f is out of the velocity range' % (maxVel))
838 print('maxVel: %.2f is out of the velocity range' % (maxVel))
839 print('maxVel is setting to %.2f' % (velrange[-1]))
839 print('maxVel is setting to %.2f' % (velrange[-1]))
840 maxVel = velrange[-1]
840 maxVel = velrange[-1]
841
841
842 # seleccion de indices para rango
842 # seleccion de indices para rango
843 minIndex = 0
843 minIndex = 0
844 maxIndex = 0
844 maxIndex = 0
845 heights = self.dataOut.heightList
845 heights = self.dataOut.heightList
846
846
847 inda = numpy.where(heights >= minHei)
847 inda = numpy.where(heights >= minHei)
848 indb = numpy.where(heights <= maxHei)
848 indb = numpy.where(heights <= maxHei)
849
849
850 try:
850 try:
851 minIndex = inda[0][0]
851 minIndex = inda[0][0]
852 except:
852 except:
853 minIndex = 0
853 minIndex = 0
854
854
855 try:
855 try:
856 maxIndex = indb[0][-1]
856 maxIndex = indb[0][-1]
857 except:
857 except:
858 maxIndex = len(heights)
858 maxIndex = len(heights)
859
859
860 if (minIndex < 0) or (minIndex > maxIndex):
860 if (minIndex < 0) or (minIndex > maxIndex):
861 raise ValueError("some value in (%d,%d) is not valid" % (
861 raise ValueError("some value in (%d,%d) is not valid" % (
862 minIndex, maxIndex))
862 minIndex, maxIndex))
863
863
864 if (maxIndex >= self.dataOut.nHeights):
864 if (maxIndex >= self.dataOut.nHeights):
865 maxIndex = self.dataOut.nHeights - 1
865 maxIndex = self.dataOut.nHeights - 1
866
866
867 # seleccion de indices para velocidades
867 # seleccion de indices para velocidades
868 indminvel = numpy.where(velrange >= minVel)
868 indminvel = numpy.where(velrange >= minVel)
869 indmaxvel = numpy.where(velrange <= maxVel)
869 indmaxvel = numpy.where(velrange <= maxVel)
870 try:
870 try:
871 minIndexVel = indminvel[0][0]
871 minIndexVel = indminvel[0][0]
872 except:
872 except:
873 minIndexVel = 0
873 minIndexVel = 0
874
874
875 try:
875 try:
876 maxIndexVel = indmaxvel[0][-1]
876 maxIndexVel = indmaxvel[0][-1]
877 except:
877 except:
878 maxIndexVel = len(velrange)
878 maxIndexVel = len(velrange)
879
879
880 # seleccion del espectro
880 # seleccion del espectro
881 data_spc = self.dataOut.data_spc[:,
881 data_spc = self.dataOut.data_spc[:,
882 minIndexVel:maxIndexVel + 1, minIndex:maxIndex + 1]
882 minIndexVel:maxIndexVel + 1, minIndex:maxIndex + 1]
883 # estimacion de ruido
883 # estimacion de ruido
884 noise = numpy.zeros(self.dataOut.nChannels)
884 noise = numpy.zeros(self.dataOut.nChannels)
885
885
886 for channel in range(self.dataOut.nChannels):
886 for channel in range(self.dataOut.nChannels):
887 daux = data_spc[channel, :, :]
887 daux = data_spc[channel, :, :]
888 noise[channel] = hildebrand_sekhon(daux, self.dataOut.nIncohInt)
888 noise[channel] = hildebrand_sekhon(daux, self.dataOut.nIncohInt)
889
889
890 self.dataOut.noise_estimation = noise.copy()
890 self.dataOut.noise_estimation = noise.copy()
891
891
892 return 1
892 return 1
893
893
894
894
895 class IncohInt(Operation):
895 class IncohInt(Operation):
896
896
897 __profIndex = 0
897 __profIndex = 0
898 __withOverapping = False
898 __withOverapping = False
899
899
900 __byTime = False
900 __byTime = False
901 __initime = None
901 __initime = None
902 __lastdatatime = None
902 __lastdatatime = None
903 __integrationtime = None
903 __integrationtime = None
904
904
905 __buffer_spc = None
905 __buffer_spc = None
906 __buffer_cspc = None
906 __buffer_cspc = None
907 __buffer_dc = None
907 __buffer_dc = None
908
908
909 __dataReady = False
909 __dataReady = False
910
910
911 __timeInterval = None
911 __timeInterval = None
912
912
913 n = None
913 n = None
914
914
915 def __init__(self):
915 def __init__(self):
916
916
917 Operation.__init__(self)
917 Operation.__init__(self)
918
918
919 def setup(self, n=None, timeInterval=None, overlapping=False):
919 def setup(self, n=None, timeInterval=None, overlapping=False):
920 """
920 """
921 Set the parameters of the integration class.
921 Set the parameters of the integration class.
922
922
923 Inputs:
923 Inputs:
924
924
925 n : Number of coherent integrations
925 n : Number of coherent integrations
926 timeInterval : Time of integration. If the parameter "n" is selected this one does not work
926 timeInterval : Time of integration. If the parameter "n" is selected this one does not work
927 overlapping :
927 overlapping :
928
928
929 """
929 """
930
930
931 self.__initime = None
931 self.__initime = None
932 self.__lastdatatime = 0
932 self.__lastdatatime = 0
933
933
934 self.__buffer_spc = 0
934 self.__buffer_spc = 0
935 self.__buffer_cspc = 0
935 self.__buffer_cspc = 0
936 self.__buffer_dc = 0
936 self.__buffer_dc = 0
937
937
938 self.__profIndex = 0
938 self.__profIndex = 0
939 self.__dataReady = False
939 self.__dataReady = False
940 self.__byTime = False
940 self.__byTime = False
941
941
942 if n is None and timeInterval is None:
942 if n is None and timeInterval is None:
943 raise ValueError("n or timeInterval should be specified ...")
943 raise ValueError("n or timeInterval should be specified ...")
944
944
945 if n is not None:
945 if n is not None:
946 self.n = int(n)
946 self.n = int(n)
947 else:
947 else:
948
948
949 self.__integrationtime = int(timeInterval)
949 self.__integrationtime = int(timeInterval)
950 self.n = None
950 self.n = None
951 self.__byTime = True
951 self.__byTime = True
952
952
953 def putData(self, data_spc, data_cspc, data_dc):
953 def putData(self, data_spc, data_cspc, data_dc):
954 """
954 """
955 Add a profile to the __buffer_spc and increase in one the __profileIndex
955 Add a profile to the __buffer_spc and increase in one the __profileIndex
956
956
957 """
957 """
958 print("profIndex: ",self.__profIndex)
958 print("profIndex: ",self.__profIndex)
959 print("data_spc.shape: ",data_spc.shape)
959 print("data_spc.shape: ",data_spc.shape)
960 print("data_spc.shape: ",data_spc[0,0,:])
960 print("data_spc.shape: ",data_spc[0,0,:])
961
961
962 self.__buffer_spc += data_spc
962 self.__buffer_spc += data_spc
963
963
964 if data_cspc is None:
964 if data_cspc is None:
965 self.__buffer_cspc = None
965 self.__buffer_cspc = None
966 else:
966 else:
967 self.__buffer_cspc += data_cspc
967 self.__buffer_cspc += data_cspc
968
968
969 if data_dc is None:
969 if data_dc is None:
970 self.__buffer_dc = None
970 self.__buffer_dc = None
971 else:
971 else:
972 self.__buffer_dc += data_dc
972 self.__buffer_dc += data_dc
973
973
974 self.__profIndex += 1
974 self.__profIndex += 1
975
975
976 return
976 return
977
977
978 def pushData(self):
978 def pushData(self):
979 """
979 """
980 Return the sum of the last profiles and the profiles used in the sum.
980 Return the sum of the last profiles and the profiles used in the sum.
981
981
982 Affected:
982 Affected:
983
983
984 self.__profileIndex
984 self.__profileIndex
985
985
986 """
986 """
987
987
988 data_spc = self.__buffer_spc
988 data_spc = self.__buffer_spc
989 data_cspc = self.__buffer_cspc
989 data_cspc = self.__buffer_cspc
990 data_dc = self.__buffer_dc
990 data_dc = self.__buffer_dc
991 n = self.__profIndex
991 n = self.__profIndex
992
992
993 self.__buffer_spc = 0
993 self.__buffer_spc = 0
994 self.__buffer_cspc = 0
994 self.__buffer_cspc = 0
995 self.__buffer_dc = 0
995 self.__buffer_dc = 0
996 self.__profIndex = 0
996 self.__profIndex = 0
997
997
998 return data_spc, data_cspc, data_dc, n
998 return data_spc, data_cspc, data_dc, n
999
999
1000 def byProfiles(self, *args):
1000 def byProfiles(self, *args):
1001
1001
1002 self.__dataReady = False
1002 self.__dataReady = False
1003 avgdata_spc = None
1003 avgdata_spc = None
1004 avgdata_cspc = None
1004 avgdata_cspc = None
1005 avgdata_dc = None
1005 avgdata_dc = None
1006
1006
1007 self.putData(*args)
1007 self.putData(*args)
1008
1008
1009 if self.__profIndex == self.n:
1009 if self.__profIndex == self.n:
1010
1010
1011 avgdata_spc, avgdata_cspc, avgdata_dc, n = self.pushData()
1011 avgdata_spc, avgdata_cspc, avgdata_dc, n = self.pushData()
1012 self.n = n
1012 self.n = n
1013 self.__dataReady = True
1013 self.__dataReady = True
1014
1014
1015 return avgdata_spc, avgdata_cspc, avgdata_dc
1015 return avgdata_spc, avgdata_cspc, avgdata_dc
1016
1016
1017 def byTime(self, datatime, *args):
1017 def byTime(self, datatime, *args):
1018
1018
1019 self.__dataReady = False
1019 self.__dataReady = False
1020 avgdata_spc = None
1020 avgdata_spc = None
1021 avgdata_cspc = None
1021 avgdata_cspc = None
1022 avgdata_dc = None
1022 avgdata_dc = None
1023
1023
1024 self.putData(*args)
1024 self.putData(*args)
1025
1025
1026 if (datatime - self.__initime) >= self.__integrationtime:
1026 if (datatime - self.__initime) >= self.__integrationtime:
1027 avgdata_spc, avgdata_cspc, avgdata_dc, n = self.pushData()
1027 avgdata_spc, avgdata_cspc, avgdata_dc, n = self.pushData()
1028 self.n = n
1028 self.n = n
1029 self.__dataReady = True
1029 self.__dataReady = True
1030
1030
1031 return avgdata_spc, avgdata_cspc, avgdata_dc
1031 return avgdata_spc, avgdata_cspc, avgdata_dc
1032
1032
1033 def integrate(self, datatime, *args):
1033 def integrate(self, datatime, *args):
1034
1034
1035 if self.__profIndex == 0:
1035 if self.__profIndex == 0:
1036 self.__initime = datatime
1036 self.__initime = datatime
1037
1037
1038 if self.__byTime:
1038 if self.__byTime:
1039 avgdata_spc, avgdata_cspc, avgdata_dc = self.byTime(
1039 avgdata_spc, avgdata_cspc, avgdata_dc = self.byTime(
1040 datatime, *args)
1040 datatime, *args)
1041 else:
1041 else:
1042 avgdata_spc, avgdata_cspc, avgdata_dc = self.byProfiles(*args)
1042 avgdata_spc, avgdata_cspc, avgdata_dc = self.byProfiles(*args)
1043
1043
1044 if not self.__dataReady:
1044 if not self.__dataReady:
1045 return None, None, None, None
1045 return None, None, None, None
1046
1046
1047 return self.__initime, avgdata_spc, avgdata_cspc, avgdata_dc
1047 return self.__initime, avgdata_spc, avgdata_cspc, avgdata_dc
1048
1048
1049 def run(self, dataOut, n=None, timeInterval=None, overlapping=False):
1049 def run(self, dataOut, n=None, timeInterval=None, overlapping=False):
1050 if n == 1:
1050 if n == 1:
1051 return
1051 return
1052
1052
1053 dataOut.flagNoData = True
1053 dataOut.flagNoData = True
1054
1054
1055 if not self.isConfig:
1055 if not self.isConfig:
1056 self.setup(n, timeInterval, overlapping)
1056 self.setup(n, timeInterval, overlapping)
1057 self.isConfig = True
1057 self.isConfig = True
1058
1058
1059 avgdatatime, avgdata_spc, avgdata_cspc, avgdata_dc = self.integrate(dataOut.utctime,
1059 avgdatatime, avgdata_spc, avgdata_cspc, avgdata_dc = self.integrate(dataOut.utctime,
1060 dataOut.data_spc,
1060 dataOut.data_spc,
1061 dataOut.data_cspc,
1061 dataOut.data_cspc,
1062 dataOut.data_dc)
1062 dataOut.data_dc)
1063
1063
1064 if self.__dataReady:
1064 if self.__dataReady:
1065
1065
1066 dataOut.data_spc = avgdata_spc
1066 dataOut.data_spc = avgdata_spc
1067 dataOut.data_cspc = avgdata_cspc
1067 dataOut.data_cspc = avgdata_cspc
1068 dataOut.data_dc = avgdata_dc
1068 dataOut.data_dc = avgdata_dc
1069 dataOut.nIncohInt *= self.n
1069 dataOut.nIncohInt *= self.n
1070 dataOut.utctime = avgdatatime
1070 dataOut.utctime = avgdatatime
1071 dataOut.flagNoData = False
1071 dataOut.flagNoData = False
1072
1072
1073 return dataOut
1073 return dataOut
1074
1074
1075
1075
1076 class PulsePair(Operation):
1076 class PulsePair(Operation):
1077 isConfig = False
1077 isConfig = False
1078 __profIndex = 0
1078 __profIndex = 0
1079 __profIndex2 = 0
1079 __profIndex2 = 0
1080 __initime = None
1080 __initime = None
1081 __lastdatatime = None
1081 __lastdatatime = None
1082 __buffer = None
1082 __buffer = None
1083 __buffer2 = []
1083 __buffer2 = []
1084 __buffer3 = None
1084 __buffer3 = None
1085 __dataReady = False
1085 __dataReady = False
1086 n = None
1086 n = None
1087
1087
1088 __nch =0
1088 __nch =0
1089 __nProf =0
1089 __nProf =0
1090 __nHeis =0
1090 __nHeis =0
1091
1091
1092 def __init__(self,**kwargs):
1092 def __init__(self,**kwargs):
1093 Operation.__init__(self,**kwargs)
1093 Operation.__init__(self,**kwargs)
1094
1094
1095 def setup(self,dataOut,n =None, m = None):
1095 def setup(self,dataOut,n =None, m = None):
1096
1096
1097 self.__initime = None
1097 self.__initime = None
1098 self.__lastdatatime = 0
1098 self.__lastdatatime = 0
1099 self.__buffer = 0
1099 self.__buffer = 0
1100 self.__bufferV = 0
1100 self.__bufferV = 0
1101 #self.__buffer2 = []
1101 #self.__buffer2 = []
1102 self.__buffer3 = 0
1102 self.__buffer3 = 0
1103 self.__dataReady = False
1103 self.__dataReady = False
1104 self.__profIndex = 0
1104 self.__profIndex = 0
1105 self.__profIndex2 = 0
1105 self.__profIndex2 = 0
1106 self.count = 0
1106 self.count = 0
1107
1107
1108
1108
1109 self.__nch = dataOut.nChannels
1109 self.__nch = dataOut.nChannels
1110 self.__nHeis = dataOut.nHeights
1110 self.__nHeis = dataOut.nHeights
1111 self.__nProf = dataOut.nProfiles
1111 self.__nProf = dataOut.nProfiles
1112 self.__nFFT = dataOut.nFFTPoints
1112 self.__nFFT = dataOut.nFFTPoints
1113 #print("Valores de Ch,Samples,Perfiles,nFFT",self.__nch,self.__nHeis,self.__nProf, self.__nFFT)
1113 #print("Valores de Ch,Samples,Perfiles,nFFT",self.__nch,self.__nHeis,self.__nProf, self.__nFFT)
1114 #print("EL VALOR DE n es:",n)
1114 #print("EL VALOR DE n es:",n)
1115 if n == None:
1115 if n == None:
1116 raise ValueError("n Should be specified.")
1116 raise ValueError("n Should be specified.")
1117
1117
1118 if n != None:
1118 if n != None:
1119 if n<2:
1119 if n<2:
1120 raise ValueError("n Should be greather than 2 ")
1120 raise ValueError("n Should be greather than 2 ")
1121 self.n = n
1121 self.n = n
1122 if m == None:
1122 if m == None:
1123 m = n
1123 m = n
1124 if m != None:
1124 if m != None:
1125 if m<2:
1125 if m<2:
1126 raise ValueError("n Should be greather than 2 ")
1126 raise ValueError("n Should be greather than 2 ")
1127
1127
1128 self.m = m
1128 self.m = m
1129 self.__buffer2 = numpy.zeros((self.__nch,self.m,self.__nHeis))
1129 self.__buffer2 = numpy.zeros((self.__nch,self.m,self.__nHeis))
1130 self.__bufferV2 = numpy.zeros((self.__nch,self.m,self.__nHeis))
1130 self.__bufferV2 = numpy.zeros((self.__nch,self.m,self.__nHeis))
1131
1131
1132
1132
1133
1133
1134 def putData(self,data):
1134 def putData(self,data):
1135 #print("###################################################")
1135 #print("###################################################")
1136 '''
1136 '''
1137 data_tmp = numpy.zeros(self.__nch,self.n,self.__nHeis, dtype= complex)
1137 data_tmp = numpy.zeros(self.__nch,self.n,self.__nHeis, dtype= complex)
1138 if self.count < self.__nProf:
1138 if self.count < self.__nProf:
1139
1139
1140 for i in range(self.n):
1140 for i in range(self.n):
1141 data_tmp[:,i,:] = data[:,i+self.count,:]
1141 data_tmp[:,i,:] = data[:,i+self.count,:]
1142
1142
1143 self.__buffer = data_tmp*numpy.conjugate(data_tmp)
1143 self.__buffer = data_tmp*numpy.conjugate(data_tmp)
1144
1144
1145
1145
1146 #####self.__buffer = data*numpy.conjugate(data)
1146 #####self.__buffer = data*numpy.conjugate(data)
1147 #####self.__bufferV = data[:,(self.__nProf-1):,:]*numpy.conjugate(data[:,1:,:])
1147 #####self.__bufferV = data[:,(self.__nProf-1):,:]*numpy.conjugate(data[:,1:,:])
1148
1148
1149 #self.__buffer2.append(numpy.conjugate(data))
1149 #self.__buffer2.append(numpy.conjugate(data))
1150
1150
1151 #####self.__profIndex = data.shape[1]
1151 #####self.__profIndex = data.shape[1]
1152 self.count = self.count + self.n -1
1152 self.count = self.count + self.n -1
1153 self.__profIndex = self.n
1153 self.__profIndex = self.n
1154 '''
1154 '''
1155 self.__buffer = data*numpy.conjugate(data)
1155 self.__buffer = data*numpy.conjugate(data)
1156 self.__bufferV = data[:,(self.__nProf-1):,:]*numpy.conjugate(data[:,1:,:])
1156 self.__bufferV = data[:,(self.__nProf-1):,:]*numpy.conjugate(data[:,1:,:])
1157 self.__profIndex = self.n
1157 self.__profIndex = self.n
1158 #print("spcch0",self.__buffer)
1158 #print("spcch0",self.__buffer)
1159 return
1159 return
1160
1160
1161 def pushData(self):
1161 def pushData(self):
1162
1162
1163 data_I = numpy.zeros((self.__nch,self.__nHeis))
1163 data_I = numpy.zeros((self.__nch,self.__nHeis))
1164 data_IV = numpy.zeros((self.__nch,self.__nHeis))
1164 data_IV = numpy.zeros((self.__nch,self.__nHeis))
1165
1165
1166 for i in range(self.__nch):
1166 for i in range(self.__nch):
1167 data_I[i,:] = numpy.sum(self.__buffer[i],axis=0)/self.n
1167 data_I[i,:] = numpy.sum(self.__buffer[i],axis=0)/self.n
1168 data_IV[i,:] = numpy.sum(self.__bufferV[i],axis=0)/(self.n-1)
1168 data_IV[i,:] = numpy.sum(self.__bufferV[i],axis=0)/(self.n-1)
1169 ##print("******")
1169 ##print("******")
1170 #print("data_I",data_I[0])
1170 #print("data_I",data_I[0])
1171 #print(self.__buffer.shape)
1171 #print(self.__buffer.shape)
1172 #a=numpy.average(self.__buffer,axis=1)
1172 #a=numpy.average(self.__buffer,axis=1)
1173 #print("average", a)
1173 #print("average", a)
1174 n = self.__profIndex
1174 n = self.__profIndex
1175 ####data_intensity = numpy.sum(numpy.sum(self.__buffer,axis=0),axis=0)/self.n
1175 ####data_intensity = numpy.sum(numpy.sum(self.__buffer,axis=0),axis=0)/self.n
1176 #print("data_intensity push data",data_intensity.shape)
1176 #print("data_intensity push data",data_intensity.shape)
1177 #data_velocity = self.__buffer3/(self.n-1)
1177 #data_velocity = self.__buffer3/(self.n-1)
1178 ####n = self.__profIndex
1178 ####n = self.__profIndex
1179
1179
1180 self.__buffer = 0
1180 self.__buffer = 0
1181 self.__buffer3 = 0
1181 self.__buffer3 = 0
1182 self.__profIndex = 0
1182 self.__profIndex = 0
1183
1183
1184 #return data_intensity,data_velocity,n
1184 #return data_intensity,data_velocity,n
1185 return data_I,data_IV,n
1185 return data_I,data_IV,n
1186
1186
1187 def pulsePairbyProfiles(self,data):
1187 def pulsePairbyProfiles(self,data):
1188 self.__dataReady = False
1188 self.__dataReady = False
1189 data_intensity = None
1189 data_intensity = None
1190 data_velocity = None
1190 data_velocity = None
1191
1191
1192 self.putData(data)
1192 self.putData(data)
1193
1193
1194 if self.__profIndex == self.n:
1194 if self.__profIndex == self.n:
1195 #data_intensity,data_velocity,n = self.pushData()
1195 #data_intensity,data_velocity,n = self.pushData()
1196 data_intensity,data_velocity,n = self.pushData()
1196 data_intensity,data_velocity,n = self.pushData()
1197 #print(data_intensity.shape)
1197 #print(data_intensity.shape)
1198 #print("self.__profIndex2", self.__profIndex2)
1198 #print("self.__profIndex2", self.__profIndex2)
1199 if self.__profIndex2 == 0:
1199 if self.__profIndex2 == 0:
1200 #print("PRIMERA VEZ")
1200 #print("PRIMERA VEZ")
1201 #print("self.__buffer2",self.__buffer2)
1201 #print("self.__buffer2",self.__buffer2)
1202 for i in range(self.__nch):
1202 for i in range(self.__nch):
1203 self.__buffer2[i][self.__profIndex2] = data_intensity[i]
1203 self.__buffer2[i][self.__profIndex2] = data_intensity[i]
1204 self.__bufferV2[i][self.__profIndex2] = data_velocity[i]
1204 self.__bufferV2[i][self.__profIndex2] = data_velocity[i]
1205 self.__profIndex2 += 1
1205 self.__profIndex2 += 1
1206 return None,None
1206 return None,None
1207
1207
1208 if self.__profIndex2 > 0:
1208 if self.__profIndex2 > 0:
1209 for i in range(self.__nch):
1209 for i in range(self.__nch):
1210 self.__buffer2[i][self.__profIndex2] = data_intensity[i]
1210 self.__buffer2[i][self.__profIndex2] = data_intensity[i]
1211 self.__bufferV2[i][self.__profIndex2] = data_velocity[i]
1211 self.__bufferV2[i][self.__profIndex2] = data_velocity[i]
1212 #print("Dentro del bucle",self.__buffer2)
1212 #print("Dentro del bucle",self.__buffer2)
1213 self.__profIndex2 += 1
1213 self.__profIndex2 += 1
1214 if self.__profIndex2 == self.m :
1214 if self.__profIndex2 == self.m :
1215 data_i = self.__buffer2
1215 data_i = self.__buffer2
1216 data_v = self.__bufferV2
1216 data_v = self.__bufferV2
1217 #print(data_i.shape)
1217 #print(data_i.shape)
1218 self.__dataReady = True
1218 self.__dataReady = True
1219 self.__profIndex2 = 0
1219 self.__profIndex2 = 0
1220 self.__buffer2 = numpy.zeros((self.__nch,self.m,self.__nHeis))
1220 self.__buffer2 = numpy.zeros((self.__nch,self.m,self.__nHeis))
1221 self.__bufferV2 = numpy.zeros((self.__nch,self.m,self.__nHeis))
1221 self.__bufferV2 = numpy.zeros((self.__nch,self.m,self.__nHeis))
1222 return data_i,data_v
1222 return data_i,data_v
1223 return None,None
1223 return None,None
1224
1224
1225 def pulsePairOp(self,data,datatime=None):
1225 def pulsePairOp(self,data,datatime=None):
1226 if self.__initime == None:
1226 if self.__initime == None:
1227 self.__initime = datatime
1227 self.__initime = datatime
1228
1228
1229 data_intensity,data_velocity = self.pulsePairbyProfiles(data)
1229 data_intensity,data_velocity = self.pulsePairbyProfiles(data)
1230 self.__lastdatatime = datatime
1230 self.__lastdatatime = datatime
1231
1231
1232 if data_intensity is None:
1232 if data_intensity is None:
1233 return None,None,None
1233 return None,None,None
1234
1234
1235 avgdatatime = self.__initime
1235 avgdatatime = self.__initime
1236 self.__initime = datatime
1236 self.__initime = datatime
1237
1237
1238 return data_intensity,data_velocity,avgdatatime
1238 return data_intensity,data_velocity,avgdatatime
1239
1239
1240 def run(self,dataOut,n =None,m=None):
1240 def run(self,dataOut,n =None,m=None):
1241
1241
1242 if not self.isConfig:
1242 if not self.isConfig:
1243 self.setup(dataOut = dataOut, n = n, m = m)
1243 self.setup(dataOut = dataOut, n = n, m = m)
1244 self.isConfig = True
1244 self.isConfig = True
1245
1245
1246 data_intensity,data_velocity,avgdatatime = self.pulsePairOp(dataOut.data_wr,dataOut.utctime)
1246 data_intensity,data_velocity,avgdatatime = self.pulsePairOp(dataOut.data_wr,dataOut.utctime)
1247 dataOut.flagNoData = True
1247 dataOut.flagNoData = True
1248
1248
1249 if self.__dataReady:
1249 if self.__dataReady:
1250 #print(" DATA " , data_intensity.shape)
1250 #print(" DATA " , data_intensity.shape)
1251 #dataOut.data = numpy.array([data_intensity])#aqui amigo revisa
1251 #dataOut.data = numpy.array([data_intensity])#aqui amigo revisa
1252 #tmp = numpy.zeros([1,data_intensity.shape[0],data_intensity.shape[1]])
1252 #tmp = numpy.zeros([1,data_intensity.shape[0],data_intensity.shape[1]])
1253 #tmp[0] = data_intensity
1253 #tmp[0] = data_intensity
1254 dataOut.data = data_intensity
1254 dataOut.data = data_intensity
1255 dataOut.data_velocity = data_velocity
1255 dataOut.data_velocity = data_velocity
1256 #dataOut.data = tmp
1256 #dataOut.data = tmp
1257 #print(" DATA " , dataOut.data.shape)
1257 #print(" DATA " , dataOut.data.shape)
1258 dataOut.nIncohInt *= self.n
1258 dataOut.nIncohInt *= self.n
1259 dataOut.nProfiles = self.m
1259 dataOut.nProfiles = self.m
1260 dataOut.nFFTPoints = self.m
1260 dataOut.nFFTPoints = self.m
1261 #dataOut.data_intensity = data_intensity
1261 #dataOut.data_intensity = data_intensity
1262 dataOut.PRFbyAngle = self.n
1262 dataOut.PRFbyAngle = self.n
1263 dataOut.utctime = avgdatatime
1263 dataOut.utctime = avgdatatime
1264 dataOut.flagNoData = False
1264 dataOut.flagNoData = False
1265 #####print("TIEMPO: ",dataOut.utctime)
1265 #####print("TIEMPO: ",dataOut.utctime)
1266 return dataOut
1266 return dataOut
@@ -1,1623 +1,1431
1 import sys
1 import sys
2 import numpy
2 import time
3 import numpy,math
3 from scipy import interpolate
4 from scipy import interpolate
4 from schainpy.model.proc.jroproc_base import ProcessingUnit, Operation, MPDecorator
5 from schainpy.model.proc.jroproc_base import ProcessingUnit, Operation, MPDecorator
5 from schainpy.model.data.jrodata import Voltage
6 from schainpy.model.data.jrodata import Voltage
6 from schainpy.utils import log
7 from schainpy.utils import log
7 from time import time
8 from time import time
8
9
9
10
10 @MPDecorator
11 @MPDecorator
11 class VoltageProc(ProcessingUnit):
12 class VoltageProc(ProcessingUnit):
12
13
13 def __init__(self):
14 def __init__(self):
14
15
15 ProcessingUnit.__init__(self)
16 ProcessingUnit.__init__(self)
16
17
17 self.dataOut = Voltage()
18 self.dataOut = Voltage()
18 self.flip = 1
19 self.flip = 1
19 self.setupReq = False
20 self.setupReq = False
20
21
21 def run(self):
22 def run(self):
22
23
23 if self.dataIn.type == 'AMISR':
24 if self.dataIn.type == 'AMISR':
24 self.__updateObjFromAmisrInput()
25 self.__updateObjFromAmisrInput()
25
26
26 if self.dataIn.type == 'Voltage':
27 if self.dataIn.type == 'Voltage':
27 self.dataOut.copy(self.dataIn)
28 self.dataOut.copy(self.dataIn)
28
29
29 # self.dataOut.copy(self.dataIn)
30 # self.dataOut.copy(self.dataIn)
30
31
31 def __updateObjFromAmisrInput(self):
32 def __updateObjFromAmisrInput(self):
32
33
33 self.dataOut.timeZone = self.dataIn.timeZone
34 self.dataOut.timeZone = self.dataIn.timeZone
34 self.dataOut.dstFlag = self.dataIn.dstFlag
35 self.dataOut.dstFlag = self.dataIn.dstFlag
35 self.dataOut.errorCount = self.dataIn.errorCount
36 self.dataOut.errorCount = self.dataIn.errorCount
36 self.dataOut.useLocalTime = self.dataIn.useLocalTime
37 self.dataOut.useLocalTime = self.dataIn.useLocalTime
37
38
38 self.dataOut.flagNoData = self.dataIn.flagNoData
39 self.dataOut.flagNoData = self.dataIn.flagNoData
39 self.dataOut.data = self.dataIn.data
40 self.dataOut.data = self.dataIn.data
40 self.dataOut.utctime = self.dataIn.utctime
41 self.dataOut.utctime = self.dataIn.utctime
41 self.dataOut.channelList = self.dataIn.channelList
42 self.dataOut.channelList = self.dataIn.channelList
42 #self.dataOut.timeInterval = self.dataIn.timeInterval
43 #self.dataOut.timeInterval = self.dataIn.timeInterval
43 self.dataOut.heightList = self.dataIn.heightList
44 self.dataOut.heightList = self.dataIn.heightList
44 self.dataOut.nProfiles = self.dataIn.nProfiles
45 self.dataOut.nProfiles = self.dataIn.nProfiles
45
46
46 self.dataOut.nCohInt = self.dataIn.nCohInt
47 self.dataOut.nCohInt = self.dataIn.nCohInt
47 self.dataOut.ippSeconds = self.dataIn.ippSeconds
48 self.dataOut.ippSeconds = self.dataIn.ippSeconds
48 self.dataOut.frequency = self.dataIn.frequency
49 self.dataOut.frequency = self.dataIn.frequency
49
50
50 self.dataOut.azimuth = self.dataIn.azimuth
51 self.dataOut.azimuth = self.dataIn.azimuth
51 self.dataOut.zenith = self.dataIn.zenith
52 self.dataOut.zenith = self.dataIn.zenith
52
53
53 self.dataOut.beam.codeList = self.dataIn.beam.codeList
54 self.dataOut.beam.codeList = self.dataIn.beam.codeList
54 self.dataOut.beam.azimuthList = self.dataIn.beam.azimuthList
55 self.dataOut.beam.azimuthList = self.dataIn.beam.azimuthList
55 self.dataOut.beam.zenithList = self.dataIn.beam.zenithList
56 self.dataOut.beam.zenithList = self.dataIn.beam.zenithList
56 #
57 #
57 # pass#
58 # pass#
58 #
59 #
59 # def init(self):
60 # def init(self):
60 #
61 #
61 #
62 #
62 # if self.dataIn.type == 'AMISR':
63 # if self.dataIn.type == 'AMISR':
63 # self.__updateObjFromAmisrInput()
64 # self.__updateObjFromAmisrInput()
64 #
65 #
65 # if self.dataIn.type == 'Voltage':
66 # if self.dataIn.type == 'Voltage':
66 # self.dataOut.copy(self.dataIn)
67 # self.dataOut.copy(self.dataIn)
67 # # No necesita copiar en cada init() los atributos de dataIn
68 # # No necesita copiar en cada init() los atributos de dataIn
68 # # la copia deberia hacerse por cada nuevo bloque de datos
69 # # la copia deberia hacerse por cada nuevo bloque de datos
69
70
70 def selectChannels(self, channelList):
71 def selectChannels(self, channelList):
71
72
72 channelIndexList = []
73 channelIndexList = []
73
74
74 for channel in channelList:
75 for channel in channelList:
75 if channel not in self.dataOut.channelList:
76 if channel not in self.dataOut.channelList:
76 raise ValueError("Channel %d is not in %s" %(channel, str(self.dataOut.channelList)))
77 raise ValueError("Channel %d is not in %s" %(channel, str(self.dataOut.channelList)))
77
78
78 index = self.dataOut.channelList.index(channel)
79 index = self.dataOut.channelList.index(channel)
79 channelIndexList.append(index)
80 channelIndexList.append(index)
80
81
81 self.selectChannelsByIndex(channelIndexList)
82 self.selectChannelsByIndex(channelIndexList)
82
83
83 def selectChannelsByIndex(self, channelIndexList):
84 def selectChannelsByIndex(self, channelIndexList):
84 """
85 """
85 Selecciona un bloque de datos en base a canales segun el channelIndexList
86 Selecciona un bloque de datos en base a canales segun el channelIndexList
86
87
87 Input:
88 Input:
88 channelIndexList : lista sencilla de canales a seleccionar por ej. [2,3,7]
89 channelIndexList : lista sencilla de canales a seleccionar por ej. [2,3,7]
89
90
90 Affected:
91 Affected:
91 self.dataOut.data
92 self.dataOut.data
92 self.dataOut.channelIndexList
93 self.dataOut.channelIndexList
93 self.dataOut.nChannels
94 self.dataOut.nChannels
94 self.dataOut.m_ProcessingHeader.totalSpectra
95 self.dataOut.m_ProcessingHeader.totalSpectra
95 self.dataOut.systemHeaderObj.numChannels
96 self.dataOut.systemHeaderObj.numChannels
96 self.dataOut.m_ProcessingHeader.blockSize
97 self.dataOut.m_ProcessingHeader.blockSize
97
98
98 Return:
99 Return:
99 None
100 None
100 """
101 """
101
102
102 for channelIndex in channelIndexList:
103 for channelIndex in channelIndexList:
103 if channelIndex not in self.dataOut.channelIndexList:
104 if channelIndex not in self.dataOut.channelIndexList:
104 print(channelIndexList)
105 print(channelIndexList)
105 raise ValueError("The value %d in channelIndexList is not valid" %channelIndex)
106 raise ValueError("The value %d in channelIndexList is not valid" %channelIndex)
106
107
107 if self.dataOut.flagDataAsBlock:
108 if self.dataOut.flagDataAsBlock:
108 """
109 """
109 Si la data es obtenida por bloques, dimension = [nChannels, nProfiles, nHeis]
110 Si la data es obtenida por bloques, dimension = [nChannels, nProfiles, nHeis]
110 """
111 """
111 data = self.dataOut.data[channelIndexList,:,:]
112 data = self.dataOut.data[channelIndexList,:,:]
112 else:
113 else:
113 data = self.dataOut.data[channelIndexList,:]
114 data = self.dataOut.data[channelIndexList,:]
114
115
115 self.dataOut.data = data
116 self.dataOut.data = data
116 # self.dataOut.channelList = [self.dataOut.channelList[i] for i in channelIndexList]
117 # self.dataOut.channelList = [self.dataOut.channelList[i] for i in channelIndexList]
117 self.dataOut.channelList = range(len(channelIndexList))
118 self.dataOut.channelList = range(len(channelIndexList))
118
119
119 return 1
120 return 1
120
121
121 def selectHeights(self, minHei=None, maxHei=None):
122 def selectHeights(self, minHei=None, maxHei=None):
122 """
123 """
123 Selecciona un bloque de datos en base a un grupo de valores de alturas segun el rango
124 Selecciona un bloque de datos en base a un grupo de valores de alturas segun el rango
124 minHei <= height <= maxHei
125 minHei <= height <= maxHei
125
126
126 Input:
127 Input:
127 minHei : valor minimo de altura a considerar
128 minHei : valor minimo de altura a considerar
128 maxHei : valor maximo de altura a considerar
129 maxHei : valor maximo de altura a considerar
129
130
130 Affected:
131 Affected:
131 Indirectamente son cambiados varios valores a travez del metodo selectHeightsByIndex
132 Indirectamente son cambiados varios valores a travez del metodo selectHeightsByIndex
132
133
133 Return:
134 Return:
134 1 si el metodo se ejecuto con exito caso contrario devuelve 0
135 1 si el metodo se ejecuto con exito caso contrario devuelve 0
135 """
136 """
136
137
137 if minHei == None:
138 if minHei == None:
138 minHei = self.dataOut.heightList[0]
139 minHei = self.dataOut.heightList[0]
139
140
140 if maxHei == None:
141 if maxHei == None:
141 maxHei = self.dataOut.heightList[-1]
142 maxHei = self.dataOut.heightList[-1]
142
143
143 if (minHei < self.dataOut.heightList[0]):
144 if (minHei < self.dataOut.heightList[0]):
144 minHei = self.dataOut.heightList[0]
145 minHei = self.dataOut.heightList[0]
145
146
146 if (maxHei > self.dataOut.heightList[-1]):
147 if (maxHei > self.dataOut.heightList[-1]):
147 maxHei = self.dataOut.heightList[-1]
148 maxHei = self.dataOut.heightList[-1]
148
149
149 minIndex = 0
150 minIndex = 0
150 maxIndex = 0
151 maxIndex = 0
151 heights = self.dataOut.heightList
152 heights = self.dataOut.heightList
152
153
153 inda = numpy.where(heights >= minHei)
154 inda = numpy.where(heights >= minHei)
154 indb = numpy.where(heights <= maxHei)
155 indb = numpy.where(heights <= maxHei)
155
156
156 try:
157 try:
157 minIndex = inda[0][0]
158 minIndex = inda[0][0]
158 except:
159 except:
159 minIndex = 0
160 minIndex = 0
160
161
161 try:
162 try:
162 maxIndex = indb[0][-1]
163 maxIndex = indb[0][-1]
163 except:
164 except:
164 maxIndex = len(heights)
165 maxIndex = len(heights)
165
166
166 self.selectHeightsByIndex(minIndex, maxIndex)
167 self.selectHeightsByIndex(minIndex, maxIndex)
167
168
168 return 1
169 return 1
169
170
170
171
171 def selectHeightsByIndex(self, minIndex, maxIndex):
172 def selectHeightsByIndex(self, minIndex, maxIndex):
172 """
173 """
173 Selecciona un bloque de datos en base a un grupo indices de alturas segun el rango
174 Selecciona un bloque de datos en base a un grupo indices de alturas segun el rango
174 minIndex <= index <= maxIndex
175 minIndex <= index <= maxIndex
175
176
176 Input:
177 Input:
177 minIndex : valor de indice minimo de altura a considerar
178 minIndex : valor de indice minimo de altura a considerar
178 maxIndex : valor de indice maximo de altura a considerar
179 maxIndex : valor de indice maximo de altura a considerar
179
180
180 Affected:
181 Affected:
181 self.dataOut.data
182 self.dataOut.data
182 self.dataOut.heightList
183 self.dataOut.heightList
183
184
184 Return:
185 Return:
185 1 si el metodo se ejecuto con exito caso contrario devuelve 0
186 1 si el metodo se ejecuto con exito caso contrario devuelve 0
186 """
187 """
187
188
188 if (minIndex < 0) or (minIndex > maxIndex):
189 if (minIndex < 0) or (minIndex > maxIndex):
189 raise ValueError("Height index range (%d,%d) is not valid" % (minIndex, maxIndex))
190 raise ValueError("Height index range (%d,%d) is not valid" % (minIndex, maxIndex))
190
191
191 if (maxIndex >= self.dataOut.nHeights):
192 if (maxIndex >= self.dataOut.nHeights):
192 maxIndex = self.dataOut.nHeights
193 maxIndex = self.dataOut.nHeights
193
194
194 #voltage
195 #voltage
195 if self.dataOut.flagDataAsBlock:
196 if self.dataOut.flagDataAsBlock:
196 """
197 """
197 Si la data es obtenida por bloques, dimension = [nChannels, nProfiles, nHeis]
198 Si la data es obtenida por bloques, dimension = [nChannels, nProfiles, nHeis]
198 """
199 """
199 data = self.dataOut.data[:,:, minIndex:maxIndex]
200 data = self.dataOut.data[:,:, minIndex:maxIndex]
200 else:
201 else:
201 data = self.dataOut.data[:, minIndex:maxIndex]
202 data = self.dataOut.data[:, minIndex:maxIndex]
202
203
203 # firstHeight = self.dataOut.heightList[minIndex]
204 # firstHeight = self.dataOut.heightList[minIndex]
204
205
205 self.dataOut.data = data
206 self.dataOut.data = data
206 self.dataOut.heightList = self.dataOut.heightList[minIndex:maxIndex]
207 self.dataOut.heightList = self.dataOut.heightList[minIndex:maxIndex]
207
208
208 if self.dataOut.nHeights <= 1:
209 if self.dataOut.nHeights <= 1:
209 raise ValueError("selectHeights: Too few heights. Current number of heights is %d" %(self.dataOut.nHeights))
210 raise ValueError("selectHeights: Too few heights. Current number of heights is %d" %(self.dataOut.nHeights))
210
211
211 return 1
212 return 1
212
213
213
214
214 def filterByHeights(self, window):
215 def filterByHeights(self, window):
215
216
216 deltaHeight = self.dataOut.heightList[1] - self.dataOut.heightList[0]
217 deltaHeight = self.dataOut.heightList[1] - self.dataOut.heightList[0]
217
218
218 if window == None:
219 if window == None:
219 window = (self.dataOut.radarControllerHeaderObj.txA/self.dataOut.radarControllerHeaderObj.nBaud) / deltaHeight
220 window = (self.dataOut.radarControllerHeaderObj.txA/self.dataOut.radarControllerHeaderObj.nBaud) / deltaHeight
220
221
221 newdelta = deltaHeight * window
222 newdelta = deltaHeight * window
222 r = self.dataOut.nHeights % window
223 r = self.dataOut.nHeights % window
223 newheights = (self.dataOut.nHeights-r)/window
224 newheights = (self.dataOut.nHeights-r)/window
224
225
225 if newheights <= 1:
226 if newheights <= 1:
226 raise ValueError("filterByHeights: Too few heights. Current number of heights is %d and window is %d" %(self.dataOut.nHeights, window))
227 raise ValueError("filterByHeights: Too few heights. Current number of heights is %d and window is %d" %(self.dataOut.nHeights, window))
227
228
228 if self.dataOut.flagDataAsBlock:
229 if self.dataOut.flagDataAsBlock:
229 """
230 """
230 Si la data es obtenida por bloques, dimension = [nChannels, nProfiles, nHeis]
231 Si la data es obtenida por bloques, dimension = [nChannels, nProfiles, nHeis]
231 """
232 """
232 buffer = self.dataOut.data[:, :, 0:int(self.dataOut.nHeights-r)]
233 buffer = self.dataOut.data[:, :, 0:int(self.dataOut.nHeights-r)]
233 buffer = buffer.reshape(self.dataOut.nChannels, self.dataOut.nProfiles, int(self.dataOut.nHeights/window), window)
234 buffer = buffer.reshape(self.dataOut.nChannels, self.dataOut.nProfiles, int(self.dataOut.nHeights/window), window)
234 buffer = numpy.sum(buffer,3)
235 buffer = numpy.sum(buffer,3)
235
236
236 else:
237 else:
237 buffer = self.dataOut.data[:,0:int(self.dataOut.nHeights-r)]
238 buffer = self.dataOut.data[:,0:int(self.dataOut.nHeights-r)]
238 buffer = buffer.reshape(self.dataOut.nChannels,int(self.dataOut.nHeights/window),int(window))
239 buffer = buffer.reshape(self.dataOut.nChannels,int(self.dataOut.nHeights/window),int(window))
239 buffer = numpy.sum(buffer,2)
240 buffer = numpy.sum(buffer,2)
240
241
241 self.dataOut.data = buffer
242 self.dataOut.data = buffer
242 self.dataOut.heightList = self.dataOut.heightList[0] + numpy.arange( newheights )*newdelta
243 self.dataOut.heightList = self.dataOut.heightList[0] + numpy.arange( newheights )*newdelta
243 self.dataOut.windowOfFilter = window
244 self.dataOut.windowOfFilter = window
244
245
245 def setH0(self, h0, deltaHeight = None):
246 def setH0(self, h0, deltaHeight = None):
246
247
247 if not deltaHeight:
248 if not deltaHeight:
248 deltaHeight = self.dataOut.heightList[1] - self.dataOut.heightList[0]
249 deltaHeight = self.dataOut.heightList[1] - self.dataOut.heightList[0]
249
250
250 nHeights = self.dataOut.nHeights
251 nHeights = self.dataOut.nHeights
251
252
252 newHeiRange = h0 + numpy.arange(nHeights)*deltaHeight
253 newHeiRange = h0 + numpy.arange(nHeights)*deltaHeight
253
254
254 self.dataOut.heightList = newHeiRange
255 self.dataOut.heightList = newHeiRange
255
256
256 def deFlip(self, channelList = []):
257 def deFlip(self, channelList = []):
257
258
258 data = self.dataOut.data.copy()
259 data = self.dataOut.data.copy()
259
260
260 if self.dataOut.flagDataAsBlock:
261 if self.dataOut.flagDataAsBlock:
261 flip = self.flip
262 flip = self.flip
262 profileList = list(range(self.dataOut.nProfiles))
263 profileList = list(range(self.dataOut.nProfiles))
263
264
264 if not channelList:
265 if not channelList:
265 for thisProfile in profileList:
266 for thisProfile in profileList:
266 data[:,thisProfile,:] = data[:,thisProfile,:]*flip
267 data[:,thisProfile,:] = data[:,thisProfile,:]*flip
267 flip *= -1.0
268 flip *= -1.0
268 else:
269 else:
269 for thisChannel in channelList:
270 for thisChannel in channelList:
270 if thisChannel not in self.dataOut.channelList:
271 if thisChannel not in self.dataOut.channelList:
271 continue
272 continue
272
273
273 for thisProfile in profileList:
274 for thisProfile in profileList:
274 data[thisChannel,thisProfile,:] = data[thisChannel,thisProfile,:]*flip
275 data[thisChannel,thisProfile,:] = data[thisChannel,thisProfile,:]*flip
275 flip *= -1.0
276 flip *= -1.0
276
277
277 self.flip = flip
278 self.flip = flip
278
279
279 else:
280 else:
280 if not channelList:
281 if not channelList:
281 data[:,:] = data[:,:]*self.flip
282 data[:,:] = data[:,:]*self.flip
282 else:
283 else:
283 for thisChannel in channelList:
284 for thisChannel in channelList:
284 if thisChannel not in self.dataOut.channelList:
285 if thisChannel not in self.dataOut.channelList:
285 continue
286 continue
286
287
287 data[thisChannel,:] = data[thisChannel,:]*self.flip
288 data[thisChannel,:] = data[thisChannel,:]*self.flip
288
289
289 self.flip *= -1.
290 self.flip *= -1.
290
291
291 self.dataOut.data = data
292 self.dataOut.data = data
292
293
293 def setRadarFrequency(self, frequency=None):
294 def setRadarFrequency(self, frequency=None):
294
295
295 if frequency != None:
296 if frequency != None:
296 self.dataOut.frequency = frequency
297 self.dataOut.frequency = frequency
297
298
298 return 1
299 return 1
299
300
300 def interpolateHeights(self, topLim, botLim):
301 def interpolateHeights(self, topLim, botLim):
301 #69 al 72 para julia
302 #69 al 72 para julia
302 #82-84 para meteoros
303 #82-84 para meteoros
303 if len(numpy.shape(self.dataOut.data))==2:
304 if len(numpy.shape(self.dataOut.data))==2:
304 sampInterp = (self.dataOut.data[:,botLim-1] + self.dataOut.data[:,topLim+1])/2
305 sampInterp = (self.dataOut.data[:,botLim-1] + self.dataOut.data[:,topLim+1])/2
305 sampInterp = numpy.transpose(numpy.tile(sampInterp,(topLim-botLim + 1,1)))
306 sampInterp = numpy.transpose(numpy.tile(sampInterp,(topLim-botLim + 1,1)))
306 #self.dataOut.data[:,botLim:limSup+1] = sampInterp
307 #self.dataOut.data[:,botLim:limSup+1] = sampInterp
307 self.dataOut.data[:,botLim:topLim+1] = sampInterp
308 self.dataOut.data[:,botLim:topLim+1] = sampInterp
308 else:
309 else:
309 nHeights = self.dataOut.data.shape[2]
310 nHeights = self.dataOut.data.shape[2]
310 x = numpy.hstack((numpy.arange(botLim),numpy.arange(topLim+1,nHeights)))
311 x = numpy.hstack((numpy.arange(botLim),numpy.arange(topLim+1,nHeights)))
311 y = self.dataOut.data[:,:,list(range(botLim))+list(range(topLim+1,nHeights))]
312 y = self.dataOut.data[:,:,list(range(botLim))+list(range(topLim+1,nHeights))]
312 f = interpolate.interp1d(x, y, axis = 2)
313 f = interpolate.interp1d(x, y, axis = 2)
313 xnew = numpy.arange(botLim,topLim+1)
314 xnew = numpy.arange(botLim,topLim+1)
314 ynew = f(xnew)
315 ynew = f(xnew)
315
316
316 self.dataOut.data[:,:,botLim:topLim+1] = ynew
317 self.dataOut.data[:,:,botLim:topLim+1] = ynew
317
318
318 # import collections
319 # import collections
319
320
320 class CohInt(Operation):
321 class CohInt(Operation):
321
322
322 isConfig = False
323 isConfig = False
323 __profIndex = 0
324 __profIndex = 0
324 __byTime = False
325 __byTime = False
325 __initime = None
326 __initime = None
326 __lastdatatime = None
327 __lastdatatime = None
327 __integrationtime = None
328 __integrationtime = None
328 __buffer = None
329 __buffer = None
329 __bufferStride = []
330 __bufferStride = []
330 __dataReady = False
331 __dataReady = False
331 __profIndexStride = 0
332 __profIndexStride = 0
332 __dataToPutStride = False
333 __dataToPutStride = False
333 n = None
334 n = None
334
335
335 def __init__(self, **kwargs):
336 def __init__(self, **kwargs):
336
337
337 Operation.__init__(self, **kwargs)
338 Operation.__init__(self, **kwargs)
338
339
339 # self.isConfig = False
340 # self.isConfig = False
340
341
341 def setup(self, n=None, timeInterval=None, stride=None, overlapping=False, byblock=False):
342 def setup(self, n=None, timeInterval=None, stride=None, overlapping=False, byblock=False):
342 """
343 """
343 Set the parameters of the integration class.
344 Set the parameters of the integration class.
344
345
345 Inputs:
346 Inputs:
346
347
347 n : Number of coherent integrations
348 n : Number of coherent integrations
348 timeInterval : Time of integration. If the parameter "n" is selected this one does not work
349 timeInterval : Time of integration. If the parameter "n" is selected this one does not work
349 overlapping :
350 overlapping :
350 """
351 """
351
352
352 self.__initime = None
353 self.__initime = None
353 self.__lastdatatime = 0
354 self.__lastdatatime = 0
354 self.__buffer = None
355 self.__buffer = None
355 self.__dataReady = False
356 self.__dataReady = False
356 self.byblock = byblock
357 self.byblock = byblock
357 self.stride = stride
358 self.stride = stride
358
359
359 if n == None and timeInterval == None:
360 if n == None and timeInterval == None:
360 raise ValueError("n or timeInterval should be specified ...")
361 raise ValueError("n or timeInterval should be specified ...")
361
362
362 if n != None:
363 if n != None:
363 self.n = n
364 self.n = n
364 self.__byTime = False
365 self.__byTime = False
365 else:
366 else:
366 self.__integrationtime = timeInterval #* 60. #if (type(timeInterval)!=integer) -> change this line
367 self.__integrationtime = timeInterval #* 60. #if (type(timeInterval)!=integer) -> change this line
367 self.n = 9999
368 self.n = 9999
368 self.__byTime = True
369 self.__byTime = True
369
370
370 if overlapping:
371 if overlapping:
371 self.__withOverlapping = True
372 self.__withOverlapping = True
372 self.__buffer = None
373 self.__buffer = None
373 else:
374 else:
374 self.__withOverlapping = False
375 self.__withOverlapping = False
375 self.__buffer = 0
376 self.__buffer = 0
376
377
377 self.__profIndex = 0
378 self.__profIndex = 0
378
379
379 def putData(self, data):
380 def putData(self, data):
380
381
381 """
382 """
382 Add a profile to the __buffer and increase in one the __profileIndex
383 Add a profile to the __buffer and increase in one the __profileIndex
383
384
384 """
385 """
385
386
386 if not self.__withOverlapping:
387 if not self.__withOverlapping:
387 print("inside over")
388 #print("inside over")
388 self.__buffer += data.copy()
389 self.__buffer += data.copy()
389 self.__profIndex += 1
390 self.__profIndex += 1
390 return
391 return
391
392
392 #Overlapping data
393 #Overlapping data
393 nChannels, nHeis = data.shape
394 nChannels, nHeis = data.shape
394 print("show me the light",data.shape)
395 #print("show me the light",data.shape)
395 data = numpy.reshape(data, (1, nChannels, nHeis))
396 data = numpy.reshape(data, (1, nChannels, nHeis))
396 print(data.shape)
397 #print(data.shape)
397 #If the buffer is empty then it takes the data value
398 #If the buffer is empty then it takes the data value
398 if self.__buffer is None:
399 if self.__buffer is None:
399 self.__buffer = data
400 self.__buffer = data
400 self.__profIndex += 1
401 self.__profIndex += 1
401 return
402 return
402
403
403 #If the buffer length is lower than n then stakcing the data value
404 #If the buffer length is lower than n then stakcing the data value
404 if self.__profIndex < self.n:
405 if self.__profIndex < self.n:
405 self.__buffer = numpy.vstack((self.__buffer, data))
406 self.__buffer = numpy.vstack((self.__buffer, data))
406 self.__profIndex += 1
407 self.__profIndex += 1
407 return
408 return
408
409
409 #If the buffer length is equal to n then replacing the last buffer value with the data value
410 #If the buffer length is equal to n then replacing the last buffer value with the data value
410 self.__buffer = numpy.roll(self.__buffer, -1, axis=0)
411 self.__buffer = numpy.roll(self.__buffer, -1, axis=0)
411 self.__buffer[self.n-1] = data
412 self.__buffer[self.n-1] = data
412 self.__profIndex = self.n
413 self.__profIndex = self.n
413 return
414 return
414
415
415
416
416 def pushData(self):
417 def pushData(self):
417 """
418 """
418 Return the sum of the last profiles and the profiles used in the sum.
419 Return the sum of the last profiles and the profiles used in the sum.
419
420
420 Affected:
421 Affected:
421
422
422 self.__profileIndex
423 self.__profileIndex
423
424
424 """
425 """
425
426
426 if not self.__withOverlapping:
427 if not self.__withOverlapping:
427 #print("ahora que fue")
428 print("ahora que fue")
428 data = self.__buffer
429 data = self.__buffer
429 n = self.__profIndex
430 n = self.__profIndex
430
431
431 self.__buffer = 0
432 self.__buffer = 0
432 self.__profIndex = 0
433 self.__profIndex = 0
433
434
434 return data, n
435 return data, n
435
436
436 #print("cual funciona")
437 #print("cual funciona")
437 #Integration with Overlapping
438 #Integration with Overlapping
438 data = numpy.sum(self.__buffer, axis=0)
439 data = numpy.sum(self.__buffer, axis=0)
439 # print data
440 # print data
440 # raise
441 # raise
441 n = self.__profIndex
442 n = self.__profIndex
442
443
443 return data, n
444 return data, n
444
445
445 def byProfiles(self, data):
446 def byProfiles(self, data):
446
447
447 self.__dataReady = False
448 self.__dataReady = False
448 avgdata = None
449 avgdata = None
449 # n = None
450 # n = None
450 # print data
451 # print data
451 # raise
452 # raise
452 #print("beforeputdata")
453 #print("beforeputdata")
453 self.putData(data)
454 self.putData(data)
454
455
455 if self.__profIndex == self.n:
456 if self.__profIndex == self.n:
456 avgdata, n = self.pushData()
457 avgdata, n = self.pushData()
457 self.__dataReady = True
458 self.__dataReady = True
458
459
459 return avgdata
460 return avgdata
460
461
461 def byTime(self, data, datatime):
462 def byTime(self, data, datatime):
462
463
463 self.__dataReady = False
464 self.__dataReady = False
464 avgdata = None
465 avgdata = None
465 n = None
466 n = None
466
467
467 self.putData(data)
468 self.putData(data)
468
469
469 if (datatime - self.__initime) >= self.__integrationtime:
470 if (datatime - self.__initime) >= self.__integrationtime:
470 avgdata, n = self.pushData()
471 avgdata, n = self.pushData()
471 self.n = n
472 self.n = n
472 self.__dataReady = True
473 self.__dataReady = True
473
474
474 return avgdata
475 return avgdata
475
476
476 def integrateByStride(self, data, datatime):
477 def integrateByStride(self, data, datatime):
477 # print data
478 # print data
478 if self.__profIndex == 0:
479 if self.__profIndex == 0:
479 self.__buffer = [[data.copy(), datatime]]
480 self.__buffer = [[data.copy(), datatime]]
480 else:
481 else:
481 self.__buffer.append([data.copy(),datatime])
482 self.__buffer.append([data.copy(),datatime])
482 self.__profIndex += 1
483 self.__profIndex += 1
483 self.__dataReady = False
484 self.__dataReady = False
484
485
485 if self.__profIndex == self.n * self.stride :
486 if self.__profIndex == self.n * self.stride :
486 self.__dataToPutStride = True
487 self.__dataToPutStride = True
487 self.__profIndexStride = 0
488 self.__profIndexStride = 0
488 self.__profIndex = 0
489 self.__profIndex = 0
489 self.__bufferStride = []
490 self.__bufferStride = []
490 for i in range(self.stride):
491 for i in range(self.stride):
491 current = self.__buffer[i::self.stride]
492 current = self.__buffer[i::self.stride]
492 data = numpy.sum([t[0] for t in current], axis=0)
493 data = numpy.sum([t[0] for t in current], axis=0)
493 avgdatatime = numpy.average([t[1] for t in current])
494 avgdatatime = numpy.average([t[1] for t in current])
494 # print data
495 # print data
495 self.__bufferStride.append((data, avgdatatime))
496 self.__bufferStride.append((data, avgdatatime))
496
497
497 if self.__dataToPutStride:
498 if self.__dataToPutStride:
498 self.__dataReady = True
499 self.__dataReady = True
499 self.__profIndexStride += 1
500 self.__profIndexStride += 1
500 if self.__profIndexStride == self.stride:
501 if self.__profIndexStride == self.stride:
501 self.__dataToPutStride = False
502 self.__dataToPutStride = False
502 # print self.__bufferStride[self.__profIndexStride - 1]
503 # print self.__bufferStride[self.__profIndexStride - 1]
503 # raise
504 # raise
504 return self.__bufferStride[self.__profIndexStride - 1]
505 return self.__bufferStride[self.__profIndexStride - 1]
505
506
506
507
507 return None, None
508 return None, None
508
509
509 def integrate(self, data, datatime=None):
510 def integrate(self, data, datatime=None):
510
511
511 if self.__initime == None:
512 if self.__initime == None:
512 self.__initime = datatime
513 self.__initime = datatime
513
514
514 if self.__byTime:
515 if self.__byTime:
515 avgdata = self.byTime(data, datatime)
516 avgdata = self.byTime(data, datatime)
516 else:
517 else:
517 avgdata = self.byProfiles(data)
518 avgdata = self.byProfiles(data)
518
519
519
520
520 self.__lastdatatime = datatime
521 self.__lastdatatime = datatime
521
522
522 if avgdata is None:
523 if avgdata is None:
523 return None, None
524 return None, None
524
525
525 avgdatatime = self.__initime
526 avgdatatime = self.__initime
526
527
527 deltatime = datatime - self.__lastdatatime
528 deltatime = datatime - self.__lastdatatime
528
529
529 if not self.__withOverlapping:
530 if not self.__withOverlapping:
530 self.__initime = datatime
531 self.__initime = datatime
531 else:
532 else:
532 self.__initime += deltatime
533 self.__initime += deltatime
533
534
534 return avgdata, avgdatatime
535 return avgdata, avgdatatime
535
536
536 def integrateByBlock(self, dataOut):
537 def integrateByBlock(self, dataOut):
537
538
538 times = int(dataOut.data.shape[1]/self.n)
539 times = int(dataOut.data.shape[1]/self.n)
539 avgdata = numpy.zeros((dataOut.nChannels, times, dataOut.nHeights), dtype=numpy.complex)
540 avgdata = numpy.zeros((dataOut.nChannels, times, dataOut.nHeights), dtype=numpy.complex)
540
541
541 id_min = 0
542 id_min = 0
542 id_max = self.n
543 id_max = self.n
543
544
544 for i in range(times):
545 for i in range(times):
545 junk = dataOut.data[:,id_min:id_max,:]
546 junk = dataOut.data[:,id_min:id_max,:]
546 avgdata[:,i,:] = junk.sum(axis=1)
547 avgdata[:,i,:] = junk.sum(axis=1)
547 id_min += self.n
548 id_min += self.n
548 id_max += self.n
549 id_max += self.n
549
550
550 timeInterval = dataOut.ippSeconds*self.n
551 timeInterval = dataOut.ippSeconds*self.n
551 avgdatatime = (times - 1) * timeInterval + dataOut.utctime
552 avgdatatime = (times - 1) * timeInterval + dataOut.utctime
552 self.__dataReady = True
553 self.__dataReady = True
553 return avgdata, avgdatatime
554 return avgdata, avgdatatime
554
555
555 def run(self, dataOut, n=None, timeInterval=None, stride=None, overlapping=False, byblock=False, **kwargs):
556 def run(self, dataOut, n=None, timeInterval=None, stride=None, overlapping=False, byblock=False, **kwargs):
556
557
557 if not self.isConfig:
558 if not self.isConfig:
558 self.setup(n=n, stride=stride, timeInterval=timeInterval, overlapping=overlapping, byblock=byblock, **kwargs)
559 self.setup(n=n, stride=stride, timeInterval=timeInterval, overlapping=overlapping, byblock=byblock, **kwargs)
559 self.isConfig = True
560 self.isConfig = True
560
561
561 if dataOut.flagDataAsBlock:
562 if dataOut.flagDataAsBlock:
562 """
563 """
563 Si la data es leida por bloques, dimension = [nChannels, nProfiles, nHeis]
564 Si la data es leida por bloques, dimension = [nChannels, nProfiles, nHeis]
564 """
565 """
565 avgdata, avgdatatime = self.integrateByBlock(dataOut)
566 avgdata, avgdatatime = self.integrateByBlock(dataOut)
566 dataOut.nProfiles /= self.n
567 dataOut.nProfiles /= self.n
567 else:
568 else:
568 if stride is None:
569 if stride is None:
569 avgdata, avgdatatime = self.integrate(dataOut.data, dataOut.utctime)
570 avgdata, avgdatatime = self.integrate(dataOut.data, dataOut.utctime)
570 else:
571 else:
571 avgdata, avgdatatime = self.integrateByStride(dataOut.data, dataOut.utctime)
572 avgdata, avgdatatime = self.integrateByStride(dataOut.data, dataOut.utctime)
572
573
573
574
574 # dataOut.timeInterval *= n
575 # dataOut.timeInterval *= n
575 dataOut.flagNoData = True
576 dataOut.flagNoData = True
576
577
577 if self.__dataReady:
578 if self.__dataReady:
578 dataOut.data = avgdata
579 dataOut.data = avgdata
579 dataOut.nCohInt *= self.n
580 dataOut.nCohInt *= self.n
580 dataOut.utctime = avgdatatime
581 dataOut.utctime = avgdatatime
581 # print avgdata, avgdatatime
582 # print avgdata, avgdatatime
582 # raise
583 # raise
583 # dataOut.timeInterval = dataOut.ippSeconds * dataOut.nCohInt
584 # dataOut.timeInterval = dataOut.ippSeconds * dataOut.nCohInt
584 dataOut.flagNoData = False
585 dataOut.flagNoData = False
585 return dataOut
586 return dataOut
586
587
587 class Decoder(Operation):
588 class Decoder(Operation):
588
589
589 isConfig = False
590 isConfig = False
590 __profIndex = 0
591 __profIndex = 0
591
592
592 code = None
593 code = None
593
594
594 nCode = None
595 nCode = None
595 nBaud = None
596 nBaud = None
596
597
597 def __init__(self, **kwargs):
598 def __init__(self, **kwargs):
598
599
599 Operation.__init__(self, **kwargs)
600 Operation.__init__(self, **kwargs)
600
601
601 self.times = None
602 self.times = None
602 self.osamp = None
603 self.osamp = None
603 # self.__setValues = False
604 # self.__setValues = False
604 self.isConfig = False
605 self.isConfig = False
605 self.setupReq = False
606 self.setupReq = False
606 def setup(self, code, osamp, dataOut):
607 def setup(self, code, osamp, dataOut):
607
608
608 self.__profIndex = 0
609 self.__profIndex = 0
609
610
610 self.code = code
611 self.code = code
611
612
612 self.nCode = len(code)
613 self.nCode = len(code)
613 self.nBaud = len(code[0])
614 self.nBaud = len(code[0])
614
615
615 if (osamp != None) and (osamp >1):
616 if (osamp != None) and (osamp >1):
616 self.osamp = osamp
617 self.osamp = osamp
617 self.code = numpy.repeat(code, repeats=self.osamp, axis=1)
618 self.code = numpy.repeat(code, repeats=self.osamp, axis=1)
618 self.nBaud = self.nBaud*self.osamp
619 self.nBaud = self.nBaud*self.osamp
619
620
620 self.__nChannels = dataOut.nChannels
621 self.__nChannels = dataOut.nChannels
621 self.__nProfiles = dataOut.nProfiles
622 self.__nProfiles = dataOut.nProfiles
622 self.__nHeis = dataOut.nHeights
623 self.__nHeis = dataOut.nHeights
623
624
624 if self.__nHeis < self.nBaud:
625 if self.__nHeis < self.nBaud:
625 raise ValueError('Number of heights (%d) should be greater than number of bauds (%d)' %(self.__nHeis, self.nBaud))
626 raise ValueError('Number of heights (%d) should be greater than number of bauds (%d)' %(self.__nHeis, self.nBaud))
626
627
627 #Frequency
628 #Frequency
628 __codeBuffer = numpy.zeros((self.nCode, self.__nHeis), dtype=numpy.complex)
629 __codeBuffer = numpy.zeros((self.nCode, self.__nHeis), dtype=numpy.complex)
629
630
630 __codeBuffer[:,0:self.nBaud] = self.code
631 __codeBuffer[:,0:self.nBaud] = self.code
631
632
632 self.fft_code = numpy.conj(numpy.fft.fft(__codeBuffer, axis=1))
633 self.fft_code = numpy.conj(numpy.fft.fft(__codeBuffer, axis=1))
633
634
634 if dataOut.flagDataAsBlock:
635 if dataOut.flagDataAsBlock:
635
636
636 self.ndatadec = self.__nHeis #- self.nBaud + 1
637 self.ndatadec = self.__nHeis #- self.nBaud + 1
637
638
638 self.datadecTime = numpy.zeros((self.__nChannels, self.__nProfiles, self.ndatadec), dtype=numpy.complex)
639 self.datadecTime = numpy.zeros((self.__nChannels, self.__nProfiles, self.ndatadec), dtype=numpy.complex)
639
640
640 else:
641 else:
641
642
642 #Time
643 #Time
643 self.ndatadec = self.__nHeis #- self.nBaud + 1
644 self.ndatadec = self.__nHeis #- self.nBaud + 1
644
645
645 self.datadecTime = numpy.zeros((self.__nChannels, self.ndatadec), dtype=numpy.complex)
646 self.datadecTime = numpy.zeros((self.__nChannels, self.ndatadec), dtype=numpy.complex)
646
647
647 def __convolutionInFreq(self, data):
648 def __convolutionInFreq(self, data):
648
649
649 fft_code = self.fft_code[self.__profIndex].reshape(1,-1)
650 fft_code = self.fft_code[self.__profIndex].reshape(1,-1)
650
651
651 fft_data = numpy.fft.fft(data, axis=1)
652 fft_data = numpy.fft.fft(data, axis=1)
652
653
653 conv = fft_data*fft_code
654 conv = fft_data*fft_code
654
655
655 data = numpy.fft.ifft(conv,axis=1)
656 data = numpy.fft.ifft(conv,axis=1)
656
657
657 return data
658 return data
658
659
659 def __convolutionInFreqOpt(self, data):
660 def __convolutionInFreqOpt(self, data):
660
661
661 raise NotImplementedError
662 raise NotImplementedError
662
663
663 def __convolutionInTime(self, data):
664 def __convolutionInTime(self, data):
664
665
665 code = self.code[self.__profIndex]
666 code = self.code[self.__profIndex]
666 for i in range(self.__nChannels):
667 for i in range(self.__nChannels):
667 self.datadecTime[i,:] = numpy.correlate(data[i,:], code, mode='full')[self.nBaud-1:]
668 self.datadecTime[i,:] = numpy.correlate(data[i,:], code, mode='full')[self.nBaud-1:]
668
669
669 return self.datadecTime
670 return self.datadecTime
670
671
671 def __convolutionByBlockInTime(self, data):
672 def __convolutionByBlockInTime(self, data):
672
673
673 repetitions = int(self.__nProfiles / self.nCode)
674 repetitions = int(self.__nProfiles / self.nCode)
674 junk = numpy.lib.stride_tricks.as_strided(self.code, (repetitions, self.code.size), (0, self.code.itemsize))
675 junk = numpy.lib.stride_tricks.as_strided(self.code, (repetitions, self.code.size), (0, self.code.itemsize))
675 junk = junk.flatten()
676 junk = junk.flatten()
676 code_block = numpy.reshape(junk, (self.nCode*repetitions, self.nBaud))
677 code_block = numpy.reshape(junk, (self.nCode*repetitions, self.nBaud))
677 profilesList = range(self.__nProfiles)
678 profilesList = range(self.__nProfiles)
678
679
679 for i in range(self.__nChannels):
680 for i in range(self.__nChannels):
680 for j in profilesList:
681 for j in profilesList:
681 self.datadecTime[i,j,:] = numpy.correlate(data[i,j,:], code_block[j,:], mode='full')[self.nBaud-1:]
682 self.datadecTime[i,j,:] = numpy.correlate(data[i,j,:], code_block[j,:], mode='full')[self.nBaud-1:]
682 return self.datadecTime
683 return self.datadecTime
683
684
684 def __convolutionByBlockInFreq(self, data):
685 def __convolutionByBlockInFreq(self, data):
685
686
686 raise NotImplementedError("Decoder by frequency fro Blocks not implemented")
687 raise NotImplementedError("Decoder by frequency fro Blocks not implemented")
687
688
688
689
689 fft_code = self.fft_code[self.__profIndex].reshape(1,-1)
690 fft_code = self.fft_code[self.__profIndex].reshape(1,-1)
690
691
691 fft_data = numpy.fft.fft(data, axis=2)
692 fft_data = numpy.fft.fft(data, axis=2)
692
693
693 conv = fft_data*fft_code
694 conv = fft_data*fft_code
694
695
695 data = numpy.fft.ifft(conv,axis=2)
696 data = numpy.fft.ifft(conv,axis=2)
696
697
697 return data
698 return data
698
699
699
700
700 def run(self, dataOut, code=None, nCode=None, nBaud=None, mode = 0, osamp=None, times=None):
701 def run(self, dataOut, code=None, nCode=None, nBaud=None, mode = 0, osamp=None, times=None):
701
702
702 if dataOut.flagDecodeData:
703 if dataOut.flagDecodeData:
703 print("This data is already decoded, recoding again ...")
704 print("This data is already decoded, recoding again ...")
704
705
705 if not self.isConfig:
706 if not self.isConfig:
706
707
707 if code is None:
708 if code is None:
708 if dataOut.code is None:
709 if dataOut.code is None:
709 raise ValueError("Code could not be read from %s instance. Enter a value in Code parameter" %dataOut.type)
710 raise ValueError("Code could not be read from %s instance. Enter a value in Code parameter" %dataOut.type)
710
711
711 code = dataOut.code
712 code = dataOut.code
712 else:
713 else:
713 code = numpy.array(code).reshape(nCode,nBaud)
714 code = numpy.array(code).reshape(nCode,nBaud)
714 self.setup(code, osamp, dataOut)
715 self.setup(code, osamp, dataOut)
715
716
716 self.isConfig = True
717 self.isConfig = True
717
718
718 if mode == 3:
719 if mode == 3:
719 sys.stderr.write("Decoder Warning: mode=%d is not valid, using mode=0\n" %mode)
720 sys.stderr.write("Decoder Warning: mode=%d is not valid, using mode=0\n" %mode)
720
721
721 if times != None:
722 if times != None:
722 sys.stderr.write("Decoder Warning: Argument 'times' in not used anymore\n")
723 sys.stderr.write("Decoder Warning: Argument 'times' in not used anymore\n")
723
724
724 if self.code is None:
725 if self.code is None:
725 print("Fail decoding: Code is not defined.")
726 print("Fail decoding: Code is not defined.")
726 return
727 return
727
728
728 self.__nProfiles = dataOut.nProfiles
729 self.__nProfiles = dataOut.nProfiles
729 datadec = None
730 datadec = None
730
731
731 if mode == 3:
732 if mode == 3:
732 mode = 0
733 mode = 0
733
734
734 if dataOut.flagDataAsBlock:
735 if dataOut.flagDataAsBlock:
735 """
736 """
736 Decoding when data have been read as block,
737 Decoding when data have been read as block,
737 """
738 """
738
739
739 if mode == 0:
740 if mode == 0:
740 datadec = self.__convolutionByBlockInTime(dataOut.data)
741 datadec = self.__convolutionByBlockInTime(dataOut.data)
741 if mode == 1:
742 if mode == 1:
742 datadec = self.__convolutionByBlockInFreq(dataOut.data)
743 datadec = self.__convolutionByBlockInFreq(dataOut.data)
743 else:
744 else:
744 """
745 """
745 Decoding when data have been read profile by profile
746 Decoding when data have been read profile by profile
746 """
747 """
747 if mode == 0:
748 if mode == 0:
748 datadec = self.__convolutionInTime(dataOut.data)
749 datadec = self.__convolutionInTime(dataOut.data)
749
750
750 if mode == 1:
751 if mode == 1:
751 datadec = self.__convolutionInFreq(dataOut.data)
752 datadec = self.__convolutionInFreq(dataOut.data)
752
753
753 if mode == 2:
754 if mode == 2:
754 datadec = self.__convolutionInFreqOpt(dataOut.data)
755 datadec = self.__convolutionInFreqOpt(dataOut.data)
755
756
756 if datadec is None:
757 if datadec is None:
757 raise ValueError("Codification mode selected is not valid: mode=%d. Try selecting 0 or 1" %mode)
758 raise ValueError("Codification mode selected is not valid: mode=%d. Try selecting 0 or 1" %mode)
758
759
759 dataOut.code = self.code
760 dataOut.code = self.code
760 dataOut.nCode = self.nCode
761 dataOut.nCode = self.nCode
761 dataOut.nBaud = self.nBaud
762 dataOut.nBaud = self.nBaud
762
763
763 dataOut.data = datadec
764 dataOut.data = datadec
764
765
765 dataOut.heightList = dataOut.heightList[0:datadec.shape[-1]]
766 dataOut.heightList = dataOut.heightList[0:datadec.shape[-1]]
766
767
767 dataOut.flagDecodeData = True #asumo q la data esta decodificada
768 dataOut.flagDecodeData = True #asumo q la data esta decodificada
768
769
769 if self.__profIndex == self.nCode-1:
770 if self.__profIndex == self.nCode-1:
770 self.__profIndex = 0
771 self.__profIndex = 0
771 return dataOut
772 return dataOut
772
773
773 self.__profIndex += 1
774 self.__profIndex += 1
774
775
775 return dataOut
776 return dataOut
776 # dataOut.flagDeflipData = True #asumo q la data no esta sin flip
777 # dataOut.flagDeflipData = True #asumo q la data no esta sin flip
777
778
778
779
779 class ProfileConcat(Operation):
780 class ProfileConcat(Operation):
780
781
781 isConfig = False
782 isConfig = False
782 buffer = None
783 buffer = None
783
784
784 def __init__(self, **kwargs):
785 def __init__(self, **kwargs):
785
786
786 Operation.__init__(self, **kwargs)
787 Operation.__init__(self, **kwargs)
787 self.profileIndex = 0
788 self.profileIndex = 0
788
789
789 def reset(self):
790 def reset(self):
790 self.buffer = numpy.zeros_like(self.buffer)
791 self.buffer = numpy.zeros_like(self.buffer)
791 self.start_index = 0
792 self.start_index = 0
792 self.times = 1
793 self.times = 1
793
794
794 def setup(self, data, m, n=1):
795 def setup(self, data, m, n=1):
795 self.buffer = numpy.zeros((data.shape[0],data.shape[1]*m),dtype=type(data[0,0]))
796 self.buffer = numpy.zeros((data.shape[0],data.shape[1]*m),dtype=type(data[0,0]))
796 self.nHeights = data.shape[1]#.nHeights
797 self.nHeights = data.shape[1]#.nHeights
797 self.start_index = 0
798 self.start_index = 0
798 self.times = 1
799 self.times = 1
799
800
800 def concat(self, data):
801 def concat(self, data):
801
802
802 self.buffer[:,self.start_index:self.nHeights*self.times] = data.copy()
803 self.buffer[:,self.start_index:self.nHeights*self.times] = data.copy()
803 self.start_index = self.start_index + self.nHeights
804 self.start_index = self.start_index + self.nHeights
804
805
805 def run(self, dataOut, m):
806 def run(self, dataOut, m):
806 dataOut.flagNoData = True
807 dataOut.flagNoData = True
807
808
808 if not self.isConfig:
809 if not self.isConfig:
809 self.setup(dataOut.data, m, 1)
810 self.setup(dataOut.data, m, 1)
810 self.isConfig = True
811 self.isConfig = True
811
812
812 if dataOut.flagDataAsBlock:
813 if dataOut.flagDataAsBlock:
813 raise ValueError("ProfileConcat can only be used when voltage have been read profile by profile, getBlock = False")
814 raise ValueError("ProfileConcat can only be used when voltage have been read profile by profile, getBlock = False")
814
815
815 else:
816 else:
816 self.concat(dataOut.data)
817 self.concat(dataOut.data)
817 self.times += 1
818 self.times += 1
818 if self.times > m:
819 if self.times > m:
819 dataOut.data = self.buffer
820 dataOut.data = self.buffer
820 self.reset()
821 self.reset()
821 dataOut.flagNoData = False
822 dataOut.flagNoData = False
822 # se deben actualizar mas propiedades del header y del objeto dataOut, por ejemplo, las alturas
823 # se deben actualizar mas propiedades del header y del objeto dataOut, por ejemplo, las alturas
823 deltaHeight = dataOut.heightList[1] - dataOut.heightList[0]
824 deltaHeight = dataOut.heightList[1] - dataOut.heightList[0]
824 xf = dataOut.heightList[0] + dataOut.nHeights * deltaHeight * m
825 xf = dataOut.heightList[0] + dataOut.nHeights * deltaHeight * m
825 dataOut.heightList = numpy.arange(dataOut.heightList[0], xf, deltaHeight)
826 dataOut.heightList = numpy.arange(dataOut.heightList[0], xf, deltaHeight)
826 dataOut.ippSeconds *= m
827 dataOut.ippSeconds *= m
827 return dataOut
828 return dataOut
828
829
829 class ProfileSelector(Operation):
830 class ProfileSelector(Operation):
830
831
831 profileIndex = None
832 profileIndex = None
832 # Tamanho total de los perfiles
833 # Tamanho total de los perfiles
833 nProfiles = None
834 nProfiles = None
834
835
835 def __init__(self, **kwargs):
836 def __init__(self, **kwargs):
836
837
837 Operation.__init__(self, **kwargs)
838 Operation.__init__(self, **kwargs)
838 self.profileIndex = 0
839 self.profileIndex = 0
839
840
840 def incProfileIndex(self):
841 def incProfileIndex(self):
841
842
842 self.profileIndex += 1
843 self.profileIndex += 1
843
844
844 if self.profileIndex >= self.nProfiles:
845 if self.profileIndex >= self.nProfiles:
845 self.profileIndex = 0
846 self.profileIndex = 0
846
847
847 def isThisProfileInRange(self, profileIndex, minIndex, maxIndex):
848 def isThisProfileInRange(self, profileIndex, minIndex, maxIndex):
848
849
849 if profileIndex < minIndex:
850 if profileIndex < minIndex:
850 return False
851 return False
851
852
852 if profileIndex > maxIndex:
853 if profileIndex > maxIndex:
853 return False
854 return False
854
855
855 return True
856 return True
856
857
857 def isThisProfileInList(self, profileIndex, profileList):
858 def isThisProfileInList(self, profileIndex, profileList):
858
859
859 if profileIndex not in profileList:
860 if profileIndex not in profileList:
860 return False
861 return False
861
862
862 return True
863 return True
863
864
864 def run(self, dataOut, profileList=None, profileRangeList=None, beam=None, byblock=False, rangeList = None, nProfiles=None):
865 def run(self, dataOut, profileList=None, profileRangeList=None, beam=None, byblock=False, rangeList = None, nProfiles=None):
865
866
866 """
867 """
867 ProfileSelector:
868 ProfileSelector:
868
869
869 Inputs:
870 Inputs:
870 profileList : Index of profiles selected. Example: profileList = (0,1,2,7,8)
871 profileList : Index of profiles selected. Example: profileList = (0,1,2,7,8)
871
872
872 profileRangeList : Minimum and maximum profile indexes. Example: profileRangeList = (4, 30)
873 profileRangeList : Minimum and maximum profile indexes. Example: profileRangeList = (4, 30)
873
874
874 rangeList : List of profile ranges. Example: rangeList = ((4, 30), (32, 64), (128, 256))
875 rangeList : List of profile ranges. Example: rangeList = ((4, 30), (32, 64), (128, 256))
875
876
876 """
877 """
877
878
878 if rangeList is not None:
879 if rangeList is not None:
879 if type(rangeList[0]) not in (tuple, list):
880 if type(rangeList[0]) not in (tuple, list):
880 rangeList = [rangeList]
881 rangeList = [rangeList]
881
882
882 dataOut.flagNoData = True
883 dataOut.flagNoData = True
883
884
884 if dataOut.flagDataAsBlock:
885 if dataOut.flagDataAsBlock:
885 """
886 """
886 data dimension = [nChannels, nProfiles, nHeis]
887 data dimension = [nChannels, nProfiles, nHeis]
887 """
888 """
888 if profileList != None:
889 if profileList != None:
889 dataOut.data = dataOut.data[:,profileList,:]
890 dataOut.data = dataOut.data[:,profileList,:]
890
891
891 if profileRangeList != None:
892 if profileRangeList != None:
892 minIndex = profileRangeList[0]
893 minIndex = profileRangeList[0]
893 maxIndex = profileRangeList[1]
894 maxIndex = profileRangeList[1]
894 profileList = list(range(minIndex, maxIndex+1))
895 profileList = list(range(minIndex, maxIndex+1))
895
896
896 dataOut.data = dataOut.data[:,minIndex:maxIndex+1,:]
897 dataOut.data = dataOut.data[:,minIndex:maxIndex+1,:]
897
898
898 if rangeList != None:
899 if rangeList != None:
899
900
900 profileList = []
901 profileList = []
901
902
902 for thisRange in rangeList:
903 for thisRange in rangeList:
903 minIndex = thisRange[0]
904 minIndex = thisRange[0]
904 maxIndex = thisRange[1]
905 maxIndex = thisRange[1]
905
906
906 profileList.extend(list(range(minIndex, maxIndex+1)))
907 profileList.extend(list(range(minIndex, maxIndex+1)))
907
908
908 dataOut.data = dataOut.data[:,profileList,:]
909 dataOut.data = dataOut.data[:,profileList,:]
909
910
910 dataOut.nProfiles = len(profileList)
911 dataOut.nProfiles = len(profileList)
911 dataOut.profileIndex = dataOut.nProfiles - 1
912 dataOut.profileIndex = dataOut.nProfiles - 1
912 dataOut.flagNoData = False
913 dataOut.flagNoData = False
913
914
914 return dataOut
915 return dataOut
915
916
916 """
917 """
917 data dimension = [nChannels, nHeis]
918 data dimension = [nChannels, nHeis]
918 """
919 """
919
920
920 if profileList != None:
921 if profileList != None:
921
922
922 if self.isThisProfileInList(dataOut.profileIndex, profileList):
923 if self.isThisProfileInList(dataOut.profileIndex, profileList):
923
924
924 self.nProfiles = len(profileList)
925 self.nProfiles = len(profileList)
925 dataOut.nProfiles = self.nProfiles
926 dataOut.nProfiles = self.nProfiles
926 dataOut.profileIndex = self.profileIndex
927 dataOut.profileIndex = self.profileIndex
927 dataOut.flagNoData = False
928 dataOut.flagNoData = False
928
929
929 self.incProfileIndex()
930 self.incProfileIndex()
930 return dataOut
931 return dataOut
931
932
932 if profileRangeList != None:
933 if profileRangeList != None:
933
934
934 minIndex = profileRangeList[0]
935 minIndex = profileRangeList[0]
935 maxIndex = profileRangeList[1]
936 maxIndex = profileRangeList[1]
936
937
937 if self.isThisProfileInRange(dataOut.profileIndex, minIndex, maxIndex):
938 if self.isThisProfileInRange(dataOut.profileIndex, minIndex, maxIndex):
938
939
939 self.nProfiles = maxIndex - minIndex + 1
940 self.nProfiles = maxIndex - minIndex + 1
940 dataOut.nProfiles = self.nProfiles
941 dataOut.nProfiles = self.nProfiles
941 dataOut.profileIndex = self.profileIndex
942 dataOut.profileIndex = self.profileIndex
942 dataOut.flagNoData = False
943 dataOut.flagNoData = False
943
944
944 self.incProfileIndex()
945 self.incProfileIndex()
945 return dataOut
946 return dataOut
946
947
947 if rangeList != None:
948 if rangeList != None:
948
949
949 nProfiles = 0
950 nProfiles = 0
950
951
951 for thisRange in rangeList:
952 for thisRange in rangeList:
952 minIndex = thisRange[0]
953 minIndex = thisRange[0]
953 maxIndex = thisRange[1]
954 maxIndex = thisRange[1]
954
955
955 nProfiles += maxIndex - minIndex + 1
956 nProfiles += maxIndex - minIndex + 1
956
957
957 for thisRange in rangeList:
958 for thisRange in rangeList:
958
959
959 minIndex = thisRange[0]
960 minIndex = thisRange[0]
960 maxIndex = thisRange[1]
961 maxIndex = thisRange[1]
961
962
962 if self.isThisProfileInRange(dataOut.profileIndex, minIndex, maxIndex):
963 if self.isThisProfileInRange(dataOut.profileIndex, minIndex, maxIndex):
963
964
964 self.nProfiles = nProfiles
965 self.nProfiles = nProfiles
965 dataOut.nProfiles = self.nProfiles
966 dataOut.nProfiles = self.nProfiles
966 dataOut.profileIndex = self.profileIndex
967 dataOut.profileIndex = self.profileIndex
967 dataOut.flagNoData = False
968 dataOut.flagNoData = False
968
969
969 self.incProfileIndex()
970 self.incProfileIndex()
970
971
971 break
972 break
972
973
973 return dataOut
974 return dataOut
974
975
975
976
976 if beam != None: #beam is only for AMISR data
977 if beam != None: #beam is only for AMISR data
977 if self.isThisProfileInList(dataOut.profileIndex, dataOut.beamRangeDict[beam]):
978 if self.isThisProfileInList(dataOut.profileIndex, dataOut.beamRangeDict[beam]):
978 dataOut.flagNoData = False
979 dataOut.flagNoData = False
979 dataOut.profileIndex = self.profileIndex
980 dataOut.profileIndex = self.profileIndex
980
981
981 self.incProfileIndex()
982 self.incProfileIndex()
982
983
983 return dataOut
984 return dataOut
984
985
985 raise ValueError("ProfileSelector needs profileList, profileRangeList or rangeList parameter")
986 raise ValueError("ProfileSelector needs profileList, profileRangeList or rangeList parameter")
986
987
987 #return False
988 #return False
988 return dataOut
989 return dataOut
989
990
990 class Reshaper(Operation):
991 class Reshaper(Operation):
991
992
992 def __init__(self, **kwargs):
993 def __init__(self, **kwargs):
993
994
994 Operation.__init__(self, **kwargs)
995 Operation.__init__(self, **kwargs)
995
996
996 self.__buffer = None
997 self.__buffer = None
997 self.__nitems = 0
998 self.__nitems = 0
998
999
999 def __appendProfile(self, dataOut, nTxs):
1000 def __appendProfile(self, dataOut, nTxs):
1000
1001
1001 if self.__buffer is None:
1002 if self.__buffer is None:
1002 shape = (dataOut.nChannels, int(dataOut.nHeights/nTxs) )
1003 shape = (dataOut.nChannels, int(dataOut.nHeights/nTxs) )
1003 self.__buffer = numpy.empty(shape, dtype = dataOut.data.dtype)
1004 self.__buffer = numpy.empty(shape, dtype = dataOut.data.dtype)
1004
1005
1005 ini = dataOut.nHeights * self.__nitems
1006 ini = dataOut.nHeights * self.__nitems
1006 end = ini + dataOut.nHeights
1007 end = ini + dataOut.nHeights
1007
1008
1008 self.__buffer[:, ini:end] = dataOut.data
1009 self.__buffer[:, ini:end] = dataOut.data
1009
1010
1010 self.__nitems += 1
1011 self.__nitems += 1
1011
1012
1012 return int(self.__nitems*nTxs)
1013 return int(self.__nitems*nTxs)
1013
1014
1014 def __getBuffer(self):
1015 def __getBuffer(self):
1015
1016
1016 if self.__nitems == int(1./self.__nTxs):
1017 if self.__nitems == int(1./self.__nTxs):
1017
1018
1018 self.__nitems = 0
1019 self.__nitems = 0
1019
1020
1020 return self.__buffer.copy()
1021 return self.__buffer.copy()
1021
1022
1022 return None
1023 return None
1023
1024
1024 def __checkInputs(self, dataOut, shape, nTxs):
1025 def __checkInputs(self, dataOut, shape, nTxs):
1025
1026
1026 if shape is None and nTxs is None:
1027 if shape is None and nTxs is None:
1027 raise ValueError("Reshaper: shape of factor should be defined")
1028 raise ValueError("Reshaper: shape of factor should be defined")
1028
1029
1029 if nTxs:
1030 if nTxs:
1030 if nTxs < 0:
1031 if nTxs < 0:
1031 raise ValueError("nTxs should be greater than 0")
1032 raise ValueError("nTxs should be greater than 0")
1032
1033
1033 if nTxs < 1 and dataOut.nProfiles % (1./nTxs) != 0:
1034 if nTxs < 1 and dataOut.nProfiles % (1./nTxs) != 0:
1034 raise ValueError("nProfiles= %d is not divisibled by (1./nTxs) = %f" %(dataOut.nProfiles, (1./nTxs)))
1035 raise ValueError("nProfiles= %d is not divisibled by (1./nTxs) = %f" %(dataOut.nProfiles, (1./nTxs)))
1035
1036
1036 shape = [dataOut.nChannels, dataOut.nProfiles*nTxs, dataOut.nHeights/nTxs]
1037 shape = [dataOut.nChannels, dataOut.nProfiles*nTxs, dataOut.nHeights/nTxs]
1037
1038
1038 return shape, nTxs
1039 return shape, nTxs
1039
1040
1040 if len(shape) != 2 and len(shape) != 3:
1041 if len(shape) != 2 and len(shape) != 3:
1041 raise ValueError("shape dimension should be equal to 2 or 3. shape = (nProfiles, nHeis) or (nChannels, nProfiles, nHeis). Actually shape = (%d, %d, %d)" %(dataOut.nChannels, dataOut.nProfiles, dataOut.nHeights))
1042 raise ValueError("shape dimension should be equal to 2 or 3. shape = (nProfiles, nHeis) or (nChannels, nProfiles, nHeis). Actually shape = (%d, %d, %d)" %(dataOut.nChannels, dataOut.nProfiles, dataOut.nHeights))
1042
1043
1043 if len(shape) == 2:
1044 if len(shape) == 2:
1044 shape_tuple = [dataOut.nChannels]
1045 shape_tuple = [dataOut.nChannels]
1045 shape_tuple.extend(shape)
1046 shape_tuple.extend(shape)
1046 else:
1047 else:
1047 shape_tuple = list(shape)
1048 shape_tuple = list(shape)
1048
1049
1049 nTxs = 1.0*shape_tuple[1]/dataOut.nProfiles
1050 nTxs = 1.0*shape_tuple[1]/dataOut.nProfiles
1050
1051
1051 return shape_tuple, nTxs
1052 return shape_tuple, nTxs
1052
1053
1053 def run(self, dataOut, shape=None, nTxs=None):
1054 def run(self, dataOut, shape=None, nTxs=None):
1054
1055
1055 shape_tuple, self.__nTxs = self.__checkInputs(dataOut, shape, nTxs)
1056 shape_tuple, self.__nTxs = self.__checkInputs(dataOut, shape, nTxs)
1056
1057
1057 dataOut.flagNoData = True
1058 dataOut.flagNoData = True
1058 profileIndex = None
1059 profileIndex = None
1059
1060
1060 if dataOut.flagDataAsBlock:
1061 if dataOut.flagDataAsBlock:
1061
1062
1062 dataOut.data = numpy.reshape(dataOut.data, shape_tuple)
1063 dataOut.data = numpy.reshape(dataOut.data, shape_tuple)
1063 dataOut.flagNoData = False
1064 dataOut.flagNoData = False
1064
1065
1065 profileIndex = int(dataOut.nProfiles*self.__nTxs) - 1
1066 profileIndex = int(dataOut.nProfiles*self.__nTxs) - 1
1066
1067
1067 else:
1068 else:
1068
1069
1069 if self.__nTxs < 1:
1070 if self.__nTxs < 1:
1070
1071
1071 self.__appendProfile(dataOut, self.__nTxs)
1072 self.__appendProfile(dataOut, self.__nTxs)
1072 new_data = self.__getBuffer()
1073 new_data = self.__getBuffer()
1073
1074
1074 if new_data is not None:
1075 if new_data is not None:
1075 dataOut.data = new_data
1076 dataOut.data = new_data
1076 dataOut.flagNoData = False
1077 dataOut.flagNoData = False
1077
1078
1078 profileIndex = dataOut.profileIndex*nTxs
1079 profileIndex = dataOut.profileIndex*nTxs
1079
1080
1080 else:
1081 else:
1081 raise ValueError("nTxs should be greater than 0 and lower than 1, or use VoltageReader(..., getblock=True)")
1082 raise ValueError("nTxs should be greater than 0 and lower than 1, or use VoltageReader(..., getblock=True)")
1082
1083
1083 deltaHeight = dataOut.heightList[1] - dataOut.heightList[0]
1084 deltaHeight = dataOut.heightList[1] - dataOut.heightList[0]
1084
1085
1085 dataOut.heightList = numpy.arange(dataOut.nHeights/self.__nTxs) * deltaHeight + dataOut.heightList[0]
1086 dataOut.heightList = numpy.arange(dataOut.nHeights/self.__nTxs) * deltaHeight + dataOut.heightList[0]
1086
1087
1087 dataOut.nProfiles = int(dataOut.nProfiles*self.__nTxs)
1088 dataOut.nProfiles = int(dataOut.nProfiles*self.__nTxs)
1088
1089
1089 dataOut.profileIndex = profileIndex
1090 dataOut.profileIndex = profileIndex
1090
1091
1091 dataOut.ippSeconds /= self.__nTxs
1092 dataOut.ippSeconds /= self.__nTxs
1092
1093
1093 return dataOut
1094 return dataOut
1094
1095
1095 class SplitProfiles(Operation):
1096 class SplitProfiles(Operation):
1096
1097
1097 def __init__(self, **kwargs):
1098 def __init__(self, **kwargs):
1098
1099
1099 Operation.__init__(self, **kwargs)
1100 Operation.__init__(self, **kwargs)
1100
1101
1101 def run(self, dataOut, n):
1102 def run(self, dataOut, n):
1102
1103
1103 dataOut.flagNoData = True
1104 dataOut.flagNoData = True
1104 profileIndex = None
1105 profileIndex = None
1105
1106
1106 if dataOut.flagDataAsBlock:
1107 if dataOut.flagDataAsBlock:
1107
1108
1108 #nchannels, nprofiles, nsamples
1109 #nchannels, nprofiles, nsamples
1109 shape = dataOut.data.shape
1110 shape = dataOut.data.shape
1110
1111
1111 if shape[2] % n != 0:
1112 if shape[2] % n != 0:
1112 raise ValueError("Could not split the data, n=%d has to be multiple of %d" %(n, shape[2]))
1113 raise ValueError("Could not split the data, n=%d has to be multiple of %d" %(n, shape[2]))
1113
1114
1114 new_shape = shape[0], shape[1]*n, int(shape[2]/n)
1115 new_shape = shape[0], shape[1]*n, int(shape[2]/n)
1115
1116
1116 dataOut.data = numpy.reshape(dataOut.data, new_shape)
1117 dataOut.data = numpy.reshape(dataOut.data, new_shape)
1117 dataOut.flagNoData = False
1118 dataOut.flagNoData = False
1118
1119
1119 profileIndex = int(dataOut.nProfiles/n) - 1
1120 profileIndex = int(dataOut.nProfiles/n) - 1
1120
1121
1121 else:
1122 else:
1122
1123
1123 raise ValueError("Could not split the data when is read Profile by Profile. Use VoltageReader(..., getblock=True)")
1124 raise ValueError("Could not split the data when is read Profile by Profile. Use VoltageReader(..., getblock=True)")
1124
1125
1125 deltaHeight = dataOut.heightList[1] - dataOut.heightList[0]
1126 deltaHeight = dataOut.heightList[1] - dataOut.heightList[0]
1126
1127
1127 dataOut.heightList = numpy.arange(dataOut.nHeights/n) * deltaHeight + dataOut.heightList[0]
1128 dataOut.heightList = numpy.arange(dataOut.nHeights/n) * deltaHeight + dataOut.heightList[0]
1128
1129
1129 dataOut.nProfiles = int(dataOut.nProfiles*n)
1130 dataOut.nProfiles = int(dataOut.nProfiles*n)
1130
1131
1131 dataOut.profileIndex = profileIndex
1132 dataOut.profileIndex = profileIndex
1132
1133
1133 dataOut.ippSeconds /= n
1134 dataOut.ippSeconds /= n
1134
1135
1135 return dataOut
1136 return dataOut
1136
1137
1137 class CombineProfiles(Operation):
1138 class CombineProfiles(Operation):
1138 def __init__(self, **kwargs):
1139 def __init__(self, **kwargs):
1139
1140
1140 Operation.__init__(self, **kwargs)
1141 Operation.__init__(self, **kwargs)
1141
1142
1142 self.__remData = None
1143 self.__remData = None
1143 self.__profileIndex = 0
1144 self.__profileIndex = 0
1144
1145
1145 def run(self, dataOut, n):
1146 def run(self, dataOut, n):
1146
1147
1147 dataOut.flagNoData = True
1148 dataOut.flagNoData = True
1148 profileIndex = None
1149 profileIndex = None
1149
1150
1150 if dataOut.flagDataAsBlock:
1151 if dataOut.flagDataAsBlock:
1151
1152
1152 #nchannels, nprofiles, nsamples
1153 #nchannels, nprofiles, nsamples
1153 shape = dataOut.data.shape
1154 shape = dataOut.data.shape
1154 new_shape = shape[0], shape[1]/n, shape[2]*n
1155 new_shape = shape[0], shape[1]/n, shape[2]*n
1155
1156
1156 if shape[1] % n != 0:
1157 if shape[1] % n != 0:
1157 raise ValueError("Could not split the data, n=%d has to be multiple of %d" %(n, shape[1]))
1158 raise ValueError("Could not split the data, n=%d has to be multiple of %d" %(n, shape[1]))
1158
1159
1159 dataOut.data = numpy.reshape(dataOut.data, new_shape)
1160 dataOut.data = numpy.reshape(dataOut.data, new_shape)
1160 dataOut.flagNoData = False
1161 dataOut.flagNoData = False
1161
1162
1162 profileIndex = int(dataOut.nProfiles*n) - 1
1163 profileIndex = int(dataOut.nProfiles*n) - 1
1163
1164
1164 else:
1165 else:
1165
1166
1166 #nchannels, nsamples
1167 #nchannels, nsamples
1167 if self.__remData is None:
1168 if self.__remData is None:
1168 newData = dataOut.data
1169 newData = dataOut.data
1169 else:
1170 else:
1170 newData = numpy.concatenate((self.__remData, dataOut.data), axis=1)
1171 newData = numpy.concatenate((self.__remData, dataOut.data), axis=1)
1171
1172
1172 self.__profileIndex += 1
1173 self.__profileIndex += 1
1173
1174
1174 if self.__profileIndex < n:
1175 if self.__profileIndex < n:
1175 self.__remData = newData
1176 self.__remData = newData
1176 #continue
1177 #continue
1177 return
1178 return
1178
1179
1179 self.__profileIndex = 0
1180 self.__profileIndex = 0
1180 self.__remData = None
1181 self.__remData = None
1181
1182
1182 dataOut.data = newData
1183 dataOut.data = newData
1183 dataOut.flagNoData = False
1184 dataOut.flagNoData = False
1184
1185
1185 profileIndex = dataOut.profileIndex/n
1186 profileIndex = dataOut.profileIndex/n
1186
1187
1187
1188
1188 deltaHeight = dataOut.heightList[1] - dataOut.heightList[0]
1189 deltaHeight = dataOut.heightList[1] - dataOut.heightList[0]
1189
1190
1190 dataOut.heightList = numpy.arange(dataOut.nHeights*n) * deltaHeight + dataOut.heightList[0]
1191 dataOut.heightList = numpy.arange(dataOut.nHeights*n) * deltaHeight + dataOut.heightList[0]
1191
1192
1192 dataOut.nProfiles = int(dataOut.nProfiles/n)
1193 dataOut.nProfiles = int(dataOut.nProfiles/n)
1193
1194
1194 dataOut.profileIndex = profileIndex
1195 dataOut.profileIndex = profileIndex
1195
1196
1196 dataOut.ippSeconds *= n
1197 dataOut.ippSeconds *= n
1197
1198
1198 return dataOut
1199 return dataOut
1199
1200
1200
1201
1201
1202
1202 class CreateBlockVoltage(Operation):
1203 class CreateBlockVoltage(Operation):
1203
1204
1204 isConfig = False
1205 isConfig = False
1205 __Index = 0
1206 __Index = 0
1206 bufferShape = None
1207 bufferShape = None
1207 buffer = None
1208 buffer = None
1208 firstdatatime = None
1209 firstdatatime = None
1209
1210
1210 def __init__(self,**kwargs):
1211 def __init__(self,**kwargs):
1211 Operation.__init__(self,**kwargs)
1212 Operation.__init__(self,**kwargs)
1212 self.isConfig = False
1213 self.isConfig = False
1213 self.__Index = 0
1214 self.__Index = 0
1214 self.firstdatatime = None
1215 self.firstdatatime = None
1215
1216
1216 def setup(self,dataOut, m = None ):
1217 def setup(self,dataOut, m = None ):
1217 '''
1218 '''
1218 m= Numero perfiles
1219 m= Numero perfiles
1219 '''
1220 '''
1220 #print("CONFIGURANDO CBV")
1221 #print("CONFIGURANDO CBV")
1221 self.__nChannels = dataOut.nChannels
1222 self.__nChannels = dataOut.nChannels
1222 self.__nHeis = dataOut.nHeights
1223 self.__nHeis = dataOut.nHeights
1223 shape = dataOut.data.shape #nchannels, nprofiles, nsamples
1224 shape = dataOut.data.shape #nchannels, nprofiles, nsamples
1224 #print("input nChannels",self.__nChannels)
1225 #print("input nChannels",self.__nChannels)
1225 #print("input nHeis",self.__nHeis)
1226 #print("input nHeis",self.__nHeis)
1226 #print("SETUP CREATE BLOCK VOLTAGE")
1227 #print("SETUP CREATE BLOCK VOLTAGE")
1227 #print("input Shape",shape)
1228 #print("input Shape",shape)
1228 #print("dataOut.nProfiles",dataOut.nProfiles)
1229 #print("dataOut.nProfiles",dataOut.nProfiles)
1229 numberSamples = self.__nHeis
1230 numberSamples = self.__nHeis
1230 numberProfile = int(m)
1231 numberProfile = int(m)
1231 dataOut.nProfiles = numberProfile
1232 dataOut.nProfiles = numberProfile
1232 #print("new numberProfile",numberProfile)
1233 #print("new numberProfile",numberProfile)
1233 #print("new numberSamples",numberSamples)
1234 #print("new numberSamples",numberSamples)
1234
1235
1235 self.bufferShape = shape[0], numberProfile, numberSamples # nchannels,nprofiles,nsamples
1236 self.bufferShape = shape[0], numberProfile, numberSamples # nchannels,nprofiles,nsamples
1236 self.buffer = numpy.zeros((self.bufferShape))
1237 self.buffer = numpy.zeros([shape[0], numberProfile, numberSamples])
1237 self.bufferVel = numpy.zeros((self.bufferShape))
1238 self.bufferVel = numpy.zeros([shape[0], numberProfile, numberSamples])
1238
1239
1239 def run(self, dataOut, m=None):
1240 def run(self, dataOut, m=None):
1240 #print("RUN")
1241 #print("RUN")
1241 dataOut.flagNoData = True
1242 dataOut.flagNoData = True
1242 dataOut.flagDataAsBlock = False
1243 dataOut.flagDataAsBlock = False
1243 #print("BLOCK INDEX ",self.__Index)
1244 #print("BLOCK INDEX ",self.__Index)
1244
1245
1245 if not self.isConfig:
1246 if not self.isConfig:
1246 self.setup(dataOut, m= m)
1247 self.setup(dataOut, m= m)
1247 self.isConfig = True
1248 self.isConfig = True
1248 if self.__Index < m:
1249 if self.__Index < m:
1249 #print("PROFINDEX BLOCK CBV",self.__Index)
1250 #print("PROFINDEX BLOCK CBV",self.__Index)
1250 self.buffer[:,self.__Index,:] = dataOut.data
1251 self.buffer[:,self.__Index,:] = dataOut.data
1252 #corregir porque debe tener un perfil menos ojo
1251 self.bufferVel[:,self.__Index,:] = dataOut.data_velocity
1253 self.bufferVel[:,self.__Index,:] = dataOut.data_velocity
1252 self.__Index += 1
1254 self.__Index += 1
1253 dataOut.flagNoData = True
1255 dataOut.flagNoData = True
1254
1256
1255 if self.firstdatatime == None:
1257 if self.firstdatatime == None:
1256 self.firstdatatime = dataOut.utctime
1258 self.firstdatatime = dataOut.utctime
1257
1259
1258 if self.__Index == m:
1260 if self.__Index == m:
1259 #print("**********************************************")
1261 #print("**********************************************")
1260 #print("self.buffer.shape ",self.buffer.shape)
1262 #print("self.buffer.shape ",self.buffer.shape)
1261 #print("##############",self.firstdatatime)
1263 #print("##############",self.firstdatatime)
1262 ##print("*********************************************")
1264 ##print("*********************************************")
1263 ##print("*********************************************")
1265 ##print("*********************************************")
1264 ##print("******* nProfiles *******", dataOut.nProfiles)
1266 ##print("******* nProfiles *******", dataOut.nProfiles)
1265 ##print("*********************************************")
1267 ##print("*********************************************")
1266 ##print("*********************************************")
1268 ##print("*********************************************")
1267 dataOut.data = self.buffer
1269 dataOut.data = self.buffer
1268 dataOut.data_velocity = self.bufferVel
1270 dataOut.data_velocity = self.bufferVel
1269 dataOut.utctime = self.firstdatatime
1271 dataOut.utctime = self.firstdatatime
1270 dataOut.nProfiles = m
1272 dataOut.nProfiles = m
1271 self.firstdatatime = None
1273 self.firstdatatime = None
1272 dataOut.flagNoData = False
1274 dataOut.flagNoData = False
1273 dataOut.flagDataAsBlock = True
1275 dataOut.flagDataAsBlock = True
1274 self.__Index = 0
1276 self.__Index = 0
1275 dataOut.identifierWR = True
1277 dataOut.identifierWR = True
1276 return dataOut
1278 return dataOut
1277
1279
1278 class PulsePairVoltage(Operation):
1280 class PulsePairVoltage(Operation):
1279 '''
1281 '''
1280 Function PulsePair(Signal Power, Velocity)
1282 Function PulsePair(Signal Power, Velocity)
1281 The real component of Lag[0] provides Intensity Information
1283 The real component of Lag[0] provides Intensity Information
1282 The imag component of Lag[1] Phase provides Velocity Information
1284 The imag component of Lag[1] Phase provides Velocity Information
1283
1285
1284 Configuration Parameters:
1286 Configuration Parameters:
1285 nPRF = Number of Several PRF
1287 nPRF = Number of Several PRF
1286 theta = Degree Azimuth angel Boundaries
1288 theta = Degree Azimuth angel Boundaries
1287
1289
1288 Input:
1290 Input:
1289 self.dataOut
1291 self.dataOut
1290 lag[N]
1292 lag[N]
1291 Affected:
1293 Affected:
1292 self.dataOut.spc
1294 self.dataOut.spc
1293 '''
1295 '''
1294 isConfig = False
1296 isConfig = False
1295 __profIndex = 0
1297 __profIndex = 0
1296 __initime = None
1298 __initime = None
1297 __lastdatatime = None
1299 __lastdatatime = None
1298 __buffer = None
1300 __buffer = None
1299 __buffer2 = []
1301 __buffer2 = []
1300 __buffer3 = None
1302 __buffer3 = None
1301 __dataReady = False
1303 __dataReady = False
1302 n = None
1304 n = None
1303 __nch = 0
1305 __nch = 0
1304 __nHeis = 0
1306 __nHeis = 0
1307 removeDC = False
1308 ipp = None
1309 lambda_ = 0
1305
1310
1306 def __init__(self,**kwargs):
1311 def __init__(self,**kwargs):
1307 Operation.__init__(self,**kwargs)
1312 Operation.__init__(self,**kwargs)
1308
1313
1309 def setup(self, dataOut, n = None ):
1314 def setup(self, dataOut, n = None, removeDC=False):
1310 '''
1315 '''
1311 n= Numero de PRF's de entrada
1316 n= Numero de PRF's de entrada
1312 '''
1317 '''
1313 self.__initime = None
1318 self.__initime = None
1314 self.__lastdatatime = 0
1319 self.__lastdatatime = 0
1315 self.__dataReady = False
1320 self.__dataReady = False
1316 self.__buffer = 0
1321 self.__buffer = 0
1317 self.__buffer2 = []
1322 self.__buffer2 = []
1318 self.__buffer3 = 0
1323 self.__buffer3 = 0
1319 self.__profIndex = 0
1324 self.__profIndex = 0
1320
1325
1321 self.__nch = dataOut.nChannels
1326 self.__nch = dataOut.nChannels
1322 self.__nHeis = dataOut.nHeights
1327 self.__nHeis = dataOut.nHeights
1328 self.removeDC = removeDC
1329 self.lambda_ = 3.0e8/(9345.0e6)
1330 self.ippSec = dataOut.ippSeconds
1331 print("IPPseconds",dataOut.ippSeconds)
1323
1332
1324 print("ELVALOR DE n es:", n)
1333 print("ELVALOR DE n es:", n)
1325 if n == None:
1334 if n == None:
1326 raise ValueError("n should be specified.")
1335 raise ValueError("n should be specified.")
1327
1336
1328 if n != None:
1337 if n != None:
1329 if n<2:
1338 if n<2:
1330 raise ValueError("n should be greater than 2")
1339 raise ValueError("n should be greater than 2")
1331
1340
1332 self.n = n
1341 self.n = n
1333 self.__nProf = n
1342 self.__nProf = n
1334 '''
1335 if overlapping:
1336 self.__withOverlapping = True
1337 self.__buffer = None
1338
1343
1339 else:
1344 self.__buffer = numpy.zeros((dataOut.nChannels,
1340 #print ("estoy sin __withO")
1345 n,
1341 self.__withOverlapping = False
1346 dataOut.nHeights),
1342 self.__buffer = 0
1347 dtype='complex')
1343 self.__buffer2 = []
1348
1344 self.__buffer3 = 0
1349
1345 '''
1346
1350
1347 def putData(self,data):
1351 def putData(self,data):
1348 '''
1352 '''
1349 Add a profile to he __buffer and increase in one the __profiel Index
1353 Add a profile to he __buffer and increase in one the __profiel Index
1350 '''
1354 '''
1351 #print("self.__profIndex :",self.__profIndex)
1355 self.__buffer[:,self.__profIndex,:]= data
1352 self.__buffer += data*numpy.conjugate(data)
1353 self.__buffer2.append(numpy.conjugate(data))
1354 if self.__profIndex > 0:
1355 self.__buffer3 += self.__buffer2[self.__profIndex-1]*data
1356 self.__profIndex += 1
1356 self.__profIndex += 1
1357 return
1357 return
1358 '''
1359 if not self.__withOverlapping:
1360 #print("Putdata inside over")
1361 self.__buffer += data* numpy.conjugate(data)
1362 self.__buffer2.append(numpy.conjugate(data))
1363
1364 if self.__profIndex >0:
1365 self.__buffer3 += self.__buffer2[self.__profIndex-1]*data
1366 self.__profIndex += 1
1367 return
1368
1369 if self.__buffer is None:
1370 #print("aqui bro")
1371 self.__buffer = data* numpy.conjugate(data)
1372 self.__buffer2.append(numpy.conjugate(data))
1373 self.__profIndex += 1
1374
1375 return
1376
1377 if self.__profIndex < self.n:
1378 self.__buffer = numpy.vstack(self.__buffer,data* numpy.conjugate(data))
1379 self.__buffer2.append(numpy.conjugate(data))
1380
1381 if self.__profIndex == 1:
1382 self.__buffer3 = self.__buffer2[self.__profIndex -1] * data
1383 else:
1384 self.__buffer3 = numpy.vstack(self.__buffer3, self.__buffer2[self.profIndex-1]*data)
1385
1386 self.__profIndex += 1
1387 return
1388 '''
1389
1358
1390 def pushData(self):
1359 def pushData(self):
1391 '''
1360 '''
1392 Return the PULSEPAIR and the profiles used in the operation
1361 Return the PULSEPAIR and the profiles used in the operation
1393 Affected : self.__profileIndex
1362 Affected : self.__profileIndex
1394 '''
1363 '''
1395 #print("************************************************")
1364
1396 #print("push data int vel n")
1365 if self.removeDC==True:
1397 data_intensity = self.__buffer/self.n
1366 mean = numpy.mean(self.__buffer,1)
1398 data_velocity = self.__buffer3/(self.n-1)
1367 tmp = mean.reshape(self.__nch,1,self.__nHeis)
1368 dc= numpy.tile(tmp,[1,self.__nProf,1])
1369 self.__buffer = self.__buffer - dc
1370
1371 data_intensity = numpy.sum(self.__buffer*numpy.conj(self.__buffer),1)/self.n
1372 pair1 = self.__buffer[:,1:,:]*numpy.conjugate(self.__buffer[:,:-1,:])
1373 angle=numpy.angle(numpy.sum(pair1,1))*180/(math.pi)
1374 #print(angle.shape)#print("__ANGLE__") #print("angle",angle[:,:10])
1375 data_velocity = (self.lambda_/(4*math.pi*self.ippSec))*numpy.angle(numpy.sum(pair1,1))
1399 n = self.__profIndex
1376 n = self.__profIndex
1400
1377
1401 self.__buffer = 0
1378 self.__buffer = numpy.zeros((self.__nch, self.__nProf,self.__nHeis), dtype='complex')
1402 self.__buffer2 = []
1403 self.__buffer3 = 0
1404 self.__profIndex = 0
1379 self.__profIndex = 0
1405
1380 return data_intensity,data_velocity,n
1406 return data_intensity, data_velocity,n
1407 '''
1408 if not self.__withOverlapping:
1409 #print("ahora que fue")
1410 data_intensity = self.__buffer/self.n
1411 data_velocity = self.__buffer3/(self.n-1)
1412 n = self.__profIndex
1413
1414 self.__buffer = 0
1415 self.__buffer2 = []
1416 self.__buffer3 = 0
1417 self.__profIndex = 0
1418 return data_intensity, data_velocity,n
1419
1420 data_intensity = numpy.sum(self.__buffer,axis = 0)
1421 data_velocity = numpy.sum(self.__buffer3,axis = 0)
1422 n = self.__profIndex
1423 #self.__buffer = 0
1424 #self.__buffer2 = []
1425 #self.__buffer3 = 0
1426 #self.__profIndex = 0
1427 return data_intensity, data_velocity,n
1428 '''
1429
1381
1430 def pulsePairbyProfiles(self,data):
1382 def pulsePairbyProfiles(self,data):
1431
1383
1432 self.__dataReady = False
1384 self.__dataReady = False
1433 data_intensity = None
1385 data_intensity = None
1434 data_velocity = None
1386 data_velocity = None
1435 #print("beforeputada")
1436 self.putData(data)
1387 self.putData(data)
1437 #print("ProfileIndex:",self.__profIndex)
1438 if self.__profIndex == self.n:
1388 if self.__profIndex == self.n:
1439 data_intensity, data_velocity, n = self.pushData()
1389 data_intensity, data_velocity, n = self.pushData()
1440 self.__dataReady = True
1390 self.__dataReady = True
1441 #print("-----------------------------------------------")
1391
1442 #print("data_intensity",data_intensity.shape,"data_velocity",data_velocity.shape)
1443 return data_intensity, data_velocity
1392 return data_intensity, data_velocity
1444
1393
1445 def pulsePairOp(self, data, datatime= None):
1394 def pulsePairOp(self, data, datatime= None):
1446
1395
1447 if self.__initime == None:
1396 if self.__initime == None:
1448 self.__initime = datatime
1397 self.__initime = datatime
1449
1398
1450 data_intensity, data_velocity = self.pulsePairbyProfiles(data)
1399 data_intensity, data_velocity = self.pulsePairbyProfiles(data)
1451 self.__lastdatatime = datatime
1400 self.__lastdatatime = datatime
1452
1401
1453 if data_intensity is None:
1402 if data_intensity is None:
1454 return None, None, None
1403 return None, None, None
1455
1404
1456 avgdatatime = self.__initime
1405 avgdatatime = self.__initime
1457 deltatime = datatime - self.__lastdatatime
1406 deltatime = datatime - self.__lastdatatime
1458 self.__initime = datatime
1407 self.__initime = datatime
1459 '''
1408
1460 if not self.__withOverlapping:
1461 self.__initime = datatime
1462 else:
1463 self.__initime += deltatime
1464 '''
1465 return data_intensity, data_velocity, avgdatatime
1409 return data_intensity, data_velocity, avgdatatime
1466
1410
1467 def run(self, dataOut,n = None, overlapping= False,**kwargs):
1411 def run(self, dataOut,n = None,removeDC= False, overlapping= False,**kwargs):
1468
1412
1469 if not self.isConfig:
1413 if not self.isConfig:
1470 self.setup(dataOut = dataOut, n = n , **kwargs)
1414 self.setup(dataOut = dataOut, n = n , removeDC=removeDC , **kwargs)
1471 self.isConfig = True
1415 self.isConfig = True
1472 #print("*******************")
1416 #print("*******************")
1473 #print("print Shape input data:",dataOut.data.shape)
1417 #print("print Shape input data:",dataOut.data.shape)
1474 data_intensity, data_velocity, avgdatatime = self.pulsePairOp(dataOut.data, dataOut.utctime)
1418 data_intensity, data_velocity, avgdatatime = self.pulsePairOp(dataOut.data, dataOut.utctime)
1475 dataOut.flagNoData = True
1419 dataOut.flagNoData = True
1476
1420
1477 if self.__dataReady:
1421 if self.__dataReady:
1478 #print("#------------------------------------------------------")
1422 #print("#------------------------------------------------------")
1479 #print("data_ready",data_intensity.shape)
1423 #print("data_ready",data_intensity.shape)
1480 dataOut.data = data_intensity #valor para plotear RTI
1424 dataOut.data = data_intensity #valor para plotear RTI
1481 dataOut.nCohInt *= self.n
1425 dataOut.nCohInt *= self.n
1482 dataOut.data_intensity = data_intensity #valor para intensidad
1426 dataOut.data_intensity = data_intensity #valor para intensidad
1483 dataOut.data_velocity = data_velocity #valor para velocidad
1427 dataOut.data_velocity = data_velocity #valor para velocidad
1484 dataOut.PRFbyAngle = self.n #numero de PRF*cada angulo rotado que equivale a un tiempo.
1428 dataOut.PRFbyAngle = self.n #numero de PRF*cada angulo rotado que equivale a un tiempo.
1485 dataOut.utctime = avgdatatime
1429 dataOut.utctime = avgdatatime
1486 dataOut.flagNoData = False
1430 dataOut.flagNoData = False
1487 return dataOut
1431 return dataOut
1488
1489 # import collections
1490 # from scipy.stats import mode
1491 #
1492 # class Synchronize(Operation):
1493 #
1494 # isConfig = False
1495 # __profIndex = 0
1496 #
1497 # def __init__(self, **kwargs):
1498 #
1499 # Operation.__init__(self, **kwargs)
1500 # # self.isConfig = False
1501 # self.__powBuffer = None
1502 # self.__startIndex = 0
1503 # self.__pulseFound = False
1504 #
1505 # def __findTxPulse(self, dataOut, channel=0, pulse_with = None):
1506 #
1507 # #Read data
1508 #
1509 # powerdB = dataOut.getPower(channel = channel)
1510 # noisedB = dataOut.getNoise(channel = channel)[0]
1511 #
1512 # self.__powBuffer.extend(powerdB.flatten())
1513 #
1514 # dataArray = numpy.array(self.__powBuffer)
1515 #
1516 # filteredPower = numpy.correlate(dataArray, dataArray[0:self.__nSamples], "same")
1517 #
1518 # maxValue = numpy.nanmax(filteredPower)
1519 #
1520 # if maxValue < noisedB + 10:
1521 # #No se encuentra ningun pulso de transmision
1522 # return None
1523 #
1524 # maxValuesIndex = numpy.where(filteredPower > maxValue - 0.1*abs(maxValue))[0]
1525 #
1526 # if len(maxValuesIndex) < 2:
1527 # #Solo se encontro un solo pulso de transmision de un baudio, esperando por el siguiente TX
1528 # return None
1529 #
1530 # phasedMaxValuesIndex = maxValuesIndex - self.__nSamples
1531 #
1532 # #Seleccionar solo valores con un espaciamiento de nSamples
1533 # pulseIndex = numpy.intersect1d(maxValuesIndex, phasedMaxValuesIndex)
1534 #
1535 # if len(pulseIndex) < 2:
1536 # #Solo se encontro un pulso de transmision con ancho mayor a 1
1537 # return None
1538 #
1539 # spacing = pulseIndex[1:] - pulseIndex[:-1]
1540 #
1541 # #remover senales que se distancien menos de 10 unidades o muestras
1542 # #(No deberian existir IPP menor a 10 unidades)
1543 #
1544 # realIndex = numpy.where(spacing > 10 )[0]
1545 #
1546 # if len(realIndex) < 2:
1547 # #Solo se encontro un pulso de transmision con ancho mayor a 1
1548 # return None
1549 #
1550 # #Eliminar pulsos anchos (deja solo la diferencia entre IPPs)
1551 # realPulseIndex = pulseIndex[realIndex]
1552 #
1553 # period = mode(realPulseIndex[1:] - realPulseIndex[:-1])[0][0]
1554 #
1555 # print "IPP = %d samples" %period
1556 #
1557 # self.__newNSamples = dataOut.nHeights #int(period)
1558 # self.__startIndex = int(realPulseIndex[0])
1559 #
1560 # return 1
1561 #
1562 #
1563 # def setup(self, nSamples, nChannels, buffer_size = 4):
1564 #
1565 # self.__powBuffer = collections.deque(numpy.zeros( buffer_size*nSamples,dtype=numpy.float),
1566 # maxlen = buffer_size*nSamples)
1567 #
1568 # bufferList = []
1569 #
1570 # for i in range(nChannels):
1571 # bufferByChannel = collections.deque(numpy.zeros( buffer_size*nSamples, dtype=numpy.complex) + numpy.NAN,
1572 # maxlen = buffer_size*nSamples)
1573 #
1574 # bufferList.append(bufferByChannel)
1575 #
1576 # self.__nSamples = nSamples
1577 # self.__nChannels = nChannels
1578 # self.__bufferList = bufferList
1579 #
1580 # def run(self, dataOut, channel = 0):
1581 #
1582 # if not self.isConfig:
1583 # nSamples = dataOut.nHeights
1584 # nChannels = dataOut.nChannels
1585 # self.setup(nSamples, nChannels)
1586 # self.isConfig = True
1587 #
1588 # #Append new data to internal buffer
1589 # for thisChannel in range(self.__nChannels):
1590 # bufferByChannel = self.__bufferList[thisChannel]
1591 # bufferByChannel.extend(dataOut.data[thisChannel])
1592 #
1593 # if self.__pulseFound:
1594 # self.__startIndex -= self.__nSamples
1595 #
1596 # #Finding Tx Pulse
1597 # if not self.__pulseFound:
1598 # indexFound = self.__findTxPulse(dataOut, channel)
1599 #
1600 # if indexFound == None:
1601 # dataOut.flagNoData = True
1602 # return
1603 #
1604 # self.__arrayBuffer = numpy.zeros((self.__nChannels, self.__newNSamples), dtype = numpy.complex)
1605 # self.__pulseFound = True
1606 # self.__startIndex = indexFound
1607 #
1608 # #If pulse was found ...
1609 # for thisChannel in range(self.__nChannels):
1610 # bufferByChannel = self.__bufferList[thisChannel]
1611 # #print self.__startIndex
1612 # x = numpy.array(bufferByChannel)
1613 # self.__arrayBuffer[thisChannel] = x[self.__startIndex:self.__startIndex+self.__newNSamples]
1614 #
1615 # deltaHeight = dataOut.heightList[1] - dataOut.heightList[0]
1616 # dataOut.heightList = numpy.arange(self.__newNSamples)*deltaHeight
1617 # # dataOut.ippSeconds = (self.__newNSamples / deltaHeight)/1e6
1618 #
1619 # dataOut.data = self.__arrayBuffer
1620 #
1621 # self.__startIndex += self.__newNSamples
1622 #
1623 # return
General Comments 0
You need to be logged in to leave comments. Login now