##// END OF EJS Templates
Update jroproc_base.py Queue size y jroproc_spectra.py
Alexander Valdez -
r1668:8880a814f9ea
parent child
Show More
@@ -1,203 +1,203
1 '''
1 '''
2 Base clases to create Processing units and operations, the MPDecorator
2 Base clases to create Processing units and operations, the MPDecorator
3 must be used in plotting and writing operations to allow to run as an
3 must be used in plotting and writing operations to allow to run as an
4 external process.
4 external process.
5 '''
5 '''
6
6 # repositorio master
7 import inspect
7 import inspect
8 import zmq
8 import zmq
9 import time
9 import time
10 import pickle
10 import pickle
11 import traceback
11 import traceback
12 from threading import Thread
12 from threading import Thread
13 from multiprocessing import Process, Queue
13 from multiprocessing import Process, Queue
14 from schainpy.utils import log
14 from schainpy.utils import log
15
15
16
16
17 class ProcessingUnit(object):
17 class ProcessingUnit(object):
18 '''
18 '''
19 Base class to create Signal Chain Units
19 Base class to create Signal Chain Units
20 '''
20 '''
21
21
22 proc_type = 'processing'
22 proc_type = 'processing'
23
23
24 def __init__(self):
24 def __init__(self):
25
25
26 self.dataIn = None
26 self.dataIn = None
27 self.dataOut = None
27 self.dataOut = None
28 self.isConfig = False
28 self.isConfig = False
29 self.operations = []
29 self.operations = []
30
30
31 def setInput(self, unit):
31 def setInput(self, unit):
32
32
33 self.dataIn = unit.dataOut
33 self.dataIn = unit.dataOut
34
34
35 def getAllowedArgs(self):
35 def getAllowedArgs(self):
36 if hasattr(self, '__attrs__'):
36 if hasattr(self, '__attrs__'):
37 return self.__attrs__
37 return self.__attrs__
38 else:
38 else:
39 return inspect.getargspec(self.run).args
39 return inspect.getargspec(self.run).args
40
40
41 def addOperation(self, conf, operation):
41 def addOperation(self, conf, operation):
42 '''
42 '''
43 '''
43 '''
44
44
45 self.operations.append((operation, conf.type, conf.getKwargs()))
45 self.operations.append((operation, conf.type, conf.getKwargs()))
46
46
47 def getOperationObj(self, objId):
47 def getOperationObj(self, objId):
48
48
49 if objId not in list(self.operations.keys()):
49 if objId not in list(self.operations.keys()):
50 return None
50 return None
51
51
52 return self.operations[objId]
52 return self.operations[objId]
53
53
54 def call(self, **kwargs):
54 def call(self, **kwargs):
55 '''
55 '''
56 '''
56 '''
57
57
58 try:
58 try:
59 if self.dataIn is not None and self.dataIn.flagNoData and not self.dataIn.error:
59 if self.dataIn is not None and self.dataIn.flagNoData and not self.dataIn.error:
60 return self.dataIn.isReady()
60 return self.dataIn.isReady()
61 elif self.dataIn is None or not self.dataIn.error:
61 elif self.dataIn is None or not self.dataIn.error:
62 self.run(**kwargs)
62 self.run(**kwargs)
63 elif self.dataIn.error:
63 elif self.dataIn.error:
64 self.dataOut.error = self.dataIn.error
64 self.dataOut.error = self.dataIn.error
65 self.dataOut.flagNoData = True
65 self.dataOut.flagNoData = True
66 except:
66 except:
67 err = traceback.format_exc()
67 err = traceback.format_exc()
68 if 'SchainWarning' in err:
68 if 'SchainWarning' in err:
69 log.warning(err.split('SchainWarning:')[-1].split('\n')[0].strip(), self.name)
69 log.warning(err.split('SchainWarning:')[-1].split('\n')[0].strip(), self.name)
70 elif 'SchainError' in err:
70 elif 'SchainError' in err:
71 log.error(err.split('SchainError:')[-1].split('\n')[0].strip(), self.name)
71 log.error(err.split('SchainError:')[-1].split('\n')[0].strip(), self.name)
72 else:
72 else:
73 log.error(err, self.name)
73 log.error(err, self.name)
74 self.dataOut.error = True
74 self.dataOut.error = True
75
75
76 for op, optype, opkwargs in self.operations:
76 for op, optype, opkwargs in self.operations:
77 if optype == 'other' and not self.dataOut.flagNoData:
77 if optype == 'other' and not self.dataOut.flagNoData:
78 self.dataOut = op.run(self.dataOut, **opkwargs)
78 self.dataOut = op.run(self.dataOut, **opkwargs)
79 elif optype == 'external' and not self.dataOut.flagNoData:
79 elif optype == 'external' and not self.dataOut.flagNoData:
80 op.queue.put(self.dataOut)
80 op.queue.put(self.dataOut)
81 elif optype == 'external' and self.dataOut.error:
81 elif optype == 'external' and self.dataOut.error:
82 op.queue.put(self.dataOut)
82 op.queue.put(self.dataOut)
83
83
84 return 'Error' if self.dataOut.error else self.dataOut.isReady()
84 return 'Error' if self.dataOut.error else self.dataOut.isReady()
85
85
86 def setup(self):
86 def setup(self):
87
87
88 raise NotImplementedError
88 raise NotImplementedError
89
89
90 def run(self):
90 def run(self):
91
91
92 raise NotImplementedError
92 raise NotImplementedError
93
93
94 def close(self):
94 def close(self):
95
95
96 return
96 return
97
97
98
98
99 class Operation(object):
99 class Operation(object):
100
100
101 '''
101 '''
102 '''
102 '''
103
103
104 proc_type = 'operation'
104 proc_type = 'operation'
105
105
106 def __init__(self):
106 def __init__(self):
107
107
108 self.id = None
108 self.id = None
109 self.isConfig = False
109 self.isConfig = False
110
110
111 if not hasattr(self, 'name'):
111 if not hasattr(self, 'name'):
112 self.name = self.__class__.__name__
112 self.name = self.__class__.__name__
113
113
114 def getAllowedArgs(self):
114 def getAllowedArgs(self):
115 if hasattr(self, '__attrs__'):
115 if hasattr(self, '__attrs__'):
116 return self.__attrs__
116 return self.__attrs__
117 else:
117 else:
118 return inspect.getargspec(self.run).args
118 return inspect.getargspec(self.run).args
119
119
120 def setup(self):
120 def setup(self):
121
121
122 self.isConfig = True
122 self.isConfig = True
123
123
124 raise NotImplementedError
124 raise NotImplementedError
125
125
126 def run(self, dataIn, **kwargs):
126 def run(self, dataIn, **kwargs):
127 """
127 """
128 Realiza las operaciones necesarias sobre la dataIn.data y actualiza los
128 Realiza las operaciones necesarias sobre la dataIn.data y actualiza los
129 atributos del objeto dataIn.
129 atributos del objeto dataIn.
130
130
131 Input:
131 Input:
132
132
133 dataIn : objeto del tipo JROData
133 dataIn : objeto del tipo JROData
134
134
135 Return:
135 Return:
136
136
137 None
137 None
138
138
139 Affected:
139 Affected:
140 __buffer : buffer de recepcion de datos.
140 __buffer : buffer de recepcion de datos.
141
141
142 """
142 """
143 if not self.isConfig:
143 if not self.isConfig:
144 self.setup(**kwargs)
144 self.setup(**kwargs)
145
145
146 raise NotImplementedError
146 raise NotImplementedError
147
147
148 def close(self):
148 def close(self):
149
149
150 return
150 return
151
151
152
152
153 def MPDecorator(BaseClass):
153 def MPDecorator(BaseClass):
154 """
154 """
155 Multiprocessing class decorator
155 Multiprocessing class decorator
156
156
157 This function add multiprocessing features to a BaseClass.
157 This function add multiprocessing features to a BaseClass.
158 """
158 """
159
159
160 class MPClass(BaseClass, Process):
160 class MPClass(BaseClass, Process):
161
161
162 def __init__(self, *args, **kwargs):
162 def __init__(self, *args, **kwargs):
163 super(MPClass, self).__init__()
163 super(MPClass, self).__init__()
164 Process.__init__(self)
164 Process.__init__(self)
165
165
166 self.args = args
166 self.args = args
167 self.kwargs = kwargs
167 self.kwargs = kwargs
168 self.t = time.time()
168 self.t = time.time()
169 self.op_type = 'external'
169 self.op_type = 'external'
170 self.name = BaseClass.__name__
170 self.name = BaseClass.__name__
171 self.__doc__ = BaseClass.__doc__
171 self.__doc__ = BaseClass.__doc__
172
172
173 if 'plot' in self.name.lower() and not self.name.endswith('_'):
173 if 'plot' in self.name.lower() and not self.name.endswith('_'):
174 self.name = '{}{}'.format(self.CODE.upper(), 'Plot')
174 self.name = '{}{}'.format(self.CODE.upper(), 'Plot')
175
175
176 self.start_time = time.time()
176 self.start_time = time.time()
177 self.err_queue = args[3]
177 self.err_queue = args[3]
178 self.queue = Queue(maxsize=1)
178 self.queue = Queue(maxsize=1)
179 self.myrun = BaseClass.run
179 self.myrun = BaseClass.run
180
180
181 def run(self):
181 def run(self):
182
182
183 while True:
183 while True:
184
184
185 dataOut = self.queue.get()
185 dataOut = self.queue.get()
186
186
187 if not dataOut.error:
187 if not dataOut.error:
188 try:
188 try:
189 BaseClass.run(self, dataOut, **self.kwargs)
189 BaseClass.run(self, dataOut, **self.kwargs)
190 except:
190 except:
191 err = traceback.format_exc()
191 err = traceback.format_exc()
192 log.error(err, self.name)
192 log.error(err, self.name)
193 else:
193 else:
194 break
194 break
195
195
196 self.close()
196 self.close()
197
197
198 def close(self):
198 def close(self):
199
199
200 BaseClass.close(self)
200 BaseClass.close(self)
201 log.success('Done...(Time:{:4.2f} secs)'.format(time.time()-self.start_time), self.name)
201 log.success('Done...(Time:{:4.2f} secs)'.format(time.time()-self.start_time), self.name)
202
202
203 return MPClass
203 return MPClass
@@ -1,898 +1,931
1 # Copyright (c) 2012-2020 Jicamarca Radio Observatory
1 # Copyright (c) 2012-2020 Jicamarca Radio Observatory
2 # All rights reserved.
2 # All rights reserved.
3 #
3 #
4 # Distributed under the terms of the BSD 3-clause license.
4 # Distributed under the terms of the BSD 3-clause license.
5 """Spectra processing Unit and operations
5 """Spectra processing Unit and operations
6
6
7 Here you will find the processing unit `SpectraProc` and several operations
7 Here you will find the processing unit `SpectraProc` and several operations
8 to work with Spectra data type
8 to work with Spectra data type
9 """
9 """
10
10
11 import time
11 import time
12 import itertools
12 import itertools
13
14 import numpy
13 import numpy
15 # repositorio
14 # repositorio
16 from schainpy.model.proc.jroproc_base import ProcessingUnit, MPDecorator, Operation
15 from schainpy.model.proc.jroproc_base import ProcessingUnit, MPDecorator, Operation
17 from schainpy.model.data.jrodata import Spectra
16 from schainpy.model.data.jrodata import Spectra
18 from schainpy.model.data.jrodata import hildebrand_sekhon
17 from schainpy.model.data.jrodata import hildebrand_sekhon
19 from schainpy.utils import log
18 from schainpy.utils import log
20
19
21
20
22 class SpectraProc(ProcessingUnit):
21 class SpectraProc(ProcessingUnit):
23
22
24 def __init__(self):
23 def __init__(self):
25
24
26 ProcessingUnit.__init__(self)
25 ProcessingUnit.__init__(self)
27
26
28 self.buffer = None
27 self.buffer = None
29 self.firstdatatime = None
28 self.firstdatatime = None
30 self.profIndex = 0
29 self.profIndex = 0
31 self.dataOut = Spectra()
30 self.dataOut = Spectra()
32 self.id_min = None
31 self.id_min = None
33 self.id_max = None
32 self.id_max = None
34 self.setupReq = False #Agregar a todas las unidades de proc
33 self.setupReq = False #Agregar a todas las unidades de proc
35
34
36 def __updateSpecFromVoltage(self):
35 def __updateSpecFromVoltage(self):
37
36
38 self.dataOut.timeZone = self.dataIn.timeZone
37 self.dataOut.timeZone = self.dataIn.timeZone
39 self.dataOut.dstFlag = self.dataIn.dstFlag
38 self.dataOut.dstFlag = self.dataIn.dstFlag
40 self.dataOut.errorCount = self.dataIn.errorCount
39 self.dataOut.errorCount = self.dataIn.errorCount
41 self.dataOut.useLocalTime = self.dataIn.useLocalTime
40 self.dataOut.useLocalTime = self.dataIn.useLocalTime
42 try:
41 try:
43 self.dataOut.processingHeaderObj = self.dataIn.processingHeaderObj.copy()
42 self.dataOut.processingHeaderObj = self.dataIn.processingHeaderObj.copy()
44 except:
43 except:
45 pass
44 pass
46 self.dataOut.radarControllerHeaderObj = self.dataIn.radarControllerHeaderObj.copy()
45 self.dataOut.radarControllerHeaderObj = self.dataIn.radarControllerHeaderObj.copy()
47 self.dataOut.systemHeaderObj = self.dataIn.systemHeaderObj.copy()
46 self.dataOut.systemHeaderObj = self.dataIn.systemHeaderObj.copy()
48 self.dataOut.channelList = self.dataIn.channelList
47 self.dataOut.channelList = self.dataIn.channelList
49 self.dataOut.heightList = self.dataIn.heightList
48 self.dataOut.heightList = self.dataIn.heightList
50 self.dataOut.dtype = numpy.dtype([('real', '<f4'), ('imag', '<f4')])
49 self.dataOut.dtype = numpy.dtype([('real', '<f4'), ('imag', '<f4')])
51 self.dataOut.nProfiles = self.dataOut.nFFTPoints
50 self.dataOut.nProfiles = self.dataOut.nFFTPoints
52 self.dataOut.flagDiscontinuousBlock = self.dataIn.flagDiscontinuousBlock
51 self.dataOut.flagDiscontinuousBlock = self.dataIn.flagDiscontinuousBlock
53 self.dataOut.utctime = self.firstdatatime
52 self.dataOut.utctime = self.firstdatatime
54 self.dataOut.flagDecodeData = self.dataIn.flagDecodeData
53 self.dataOut.flagDecodeData = self.dataIn.flagDecodeData
55 self.dataOut.flagDeflipData = self.dataIn.flagDeflipData
54 self.dataOut.flagDeflipData = self.dataIn.flagDeflipData
56 self.dataOut.flagShiftFFT = False
55 self.dataOut.flagShiftFFT = False
57 self.dataOut.nCohInt = self.dataIn.nCohInt
56 self.dataOut.nCohInt = self.dataIn.nCohInt
58 self.dataOut.nIncohInt = 1
57 self.dataOut.nIncohInt = 1
59 self.dataOut.windowOfFilter = self.dataIn.windowOfFilter
58 self.dataOut.windowOfFilter = self.dataIn.windowOfFilter
60 self.dataOut.frequency = self.dataIn.frequency
59 self.dataOut.frequency = self.dataIn.frequency
61 self.dataOut.realtime = self.dataIn.realtime
60 self.dataOut.realtime = self.dataIn.realtime
62 self.dataOut.azimuth = self.dataIn.azimuth
61 self.dataOut.azimuth = self.dataIn.azimuth
63 self.dataOut.zenith = self.dataIn.zenith
62 self.dataOut.zenith = self.dataIn.zenith
64 self.dataOut.beam.codeList = self.dataIn.beam.codeList
63 self.dataOut.beam.codeList = self.dataIn.beam.codeList
65 self.dataOut.beam.azimuthList = self.dataIn.beam.azimuthList
64 self.dataOut.beam.azimuthList = self.dataIn.beam.azimuthList
66 self.dataOut.beam.zenithList = self.dataIn.beam.zenithList
65 self.dataOut.beam.zenithList = self.dataIn.beam.zenithList
67
66
68 def __getFft(self):
67 def __getFft(self):
69 """
68 """
70 Convierte valores de Voltaje a Spectra
69 Convierte valores de Voltaje a Spectra
71
70
72 Affected:
71 Affected:
73 self.dataOut.data_spc
72 self.dataOut.data_spc
74 self.dataOut.data_cspc
73 self.dataOut.data_cspc
75 self.dataOut.data_dc
74 self.dataOut.data_dc
76 self.dataOut.heightList
75 self.dataOut.heightList
77 self.profIndex
76 self.profIndex
78 self.buffer
77 self.buffer
79 self.dataOut.flagNoData
78 self.dataOut.flagNoData
80 """
79 """
81 fft_volt = numpy.fft.fft(
80 fft_volt = numpy.fft.fft(
82 self.buffer, n=self.dataOut.nFFTPoints, axis=1)
81 self.buffer, n=self.dataOut.nFFTPoints, axis=1)
83 fft_volt = fft_volt.astype(numpy.dtype('complex'))
82 fft_volt = fft_volt.astype(numpy.dtype('complex'))
84 dc = fft_volt[:, 0, :]
83 dc = fft_volt[:, 0, :]
85
84
86 # calculo de self-spectra
85 # calculo de self-spectra
87 fft_volt = numpy.fft.fftshift(fft_volt, axes=(1,))
86 fft_volt = numpy.fft.fftshift(fft_volt, axes=(1,))
88 spc = fft_volt * numpy.conjugate(fft_volt)
87 spc = fft_volt * numpy.conjugate(fft_volt)
89 spc = spc.real
88 spc = spc.real
90
89
91 blocksize = 0
90 blocksize = 0
92 blocksize += dc.size
91 blocksize += dc.size
93 blocksize += spc.size
92 blocksize += spc.size
94
93
95 cspc = None
94 cspc = None
96 pairIndex = 0
95 pairIndex = 0
97 if self.dataOut.pairsList != None:
96 if self.dataOut.pairsList != None:
98 # calculo de cross-spectra
97 # calculo de cross-spectra
99 cspc = numpy.zeros(
98 cspc = numpy.zeros(
100 (self.dataOut.nPairs, self.dataOut.nFFTPoints, self.dataOut.nHeights), dtype='complex')
99 (self.dataOut.nPairs, self.dataOut.nFFTPoints, self.dataOut.nHeights), dtype='complex')
101 for pair in self.dataOut.pairsList:
100 for pair in self.dataOut.pairsList:
102 if pair[0] not in self.dataOut.channelList:
101 if pair[0] not in self.dataOut.channelList:
103 raise ValueError("Error getting CrossSpectra: pair 0 of %s is not in channelList = %s" % (
102 raise ValueError("Error getting CrossSpectra: pair 0 of %s is not in channelList = %s" % (
104 str(pair), str(self.dataOut.channelList)))
103 str(pair), str(self.dataOut.channelList)))
105 if pair[1] not in self.dataOut.channelList:
104 if pair[1] not in self.dataOut.channelList:
106 raise ValueError("Error getting CrossSpectra: pair 1 of %s is not in channelList = %s" % (
105 raise ValueError("Error getting CrossSpectra: pair 1 of %s is not in channelList = %s" % (
107 str(pair), str(self.dataOut.channelList)))
106 str(pair), str(self.dataOut.channelList)))
108
107
109 cspc[pairIndex, :, :] = fft_volt[pair[0], :, :] * \
108 cspc[pairIndex, :, :] = fft_volt[pair[0], :, :] * \
110 numpy.conjugate(fft_volt[pair[1], :, :])
109 numpy.conjugate(fft_volt[pair[1], :, :])
111 pairIndex += 1
110 pairIndex += 1
112 blocksize += cspc.size
111 blocksize += cspc.size
113
112
114 self.dataOut.data_spc = spc
113 self.dataOut.data_spc = spc
115 self.dataOut.data_cspc = cspc
114 self.dataOut.data_cspc = cspc
116 self.dataOut.data_dc = dc
115 self.dataOut.data_dc = dc
117 self.dataOut.blockSize = blocksize
116 self.dataOut.blockSize = blocksize
118 self.dataOut.flagShiftFFT = False
117 self.dataOut.flagShiftFFT = False
119
118
120 def run(self, nProfiles=None, nFFTPoints=None, pairsList=None, ippFactor=None, shift_fft=False):
119 def run(self, nProfiles=None, nFFTPoints=None, pairsList=None, ippFactor=None, shift_fft=False):
121
120
122 if self.dataIn.type == "Spectra":
121 if self.dataIn.type == "Spectra":
123 self.dataOut.copy(self.dataIn)
122 self.dataOut.copy(self.dataIn)
124 if shift_fft:
123 if shift_fft:
125 #desplaza a la derecha en el eje 2 determinadas posiciones
124 #desplaza a la derecha en el eje 2 determinadas posiciones
126 shift = int(self.dataOut.nFFTPoints/2)
125 shift = int(self.dataOut.nFFTPoints/2)
127 self.dataOut.data_spc = numpy.roll(self.dataOut.data_spc, shift , axis=1)
126 self.dataOut.data_spc = numpy.roll(self.dataOut.data_spc, shift , axis=1)
128
127
129 if self.dataOut.data_cspc is not None:
128 if self.dataOut.data_cspc is not None:
130 #desplaza a la derecha en el eje 2 determinadas posiciones
129 #desplaza a la derecha en el eje 2 determinadas posiciones
131 self.dataOut.data_cspc = numpy.roll(self.dataOut.data_cspc, shift, axis=1)
130 self.dataOut.data_cspc = numpy.roll(self.dataOut.data_cspc, shift, axis=1)
132 if pairsList:
131 if pairsList:
133 self.__selectPairs(pairsList)
132 self.__selectPairs(pairsList)
134
133
135 elif self.dataIn.type == "Voltage":
134 elif self.dataIn.type == "Voltage":
136
135
137 self.dataOut.flagNoData = True
136 self.dataOut.flagNoData = True
138
137
139 if nFFTPoints == None:
138 if nFFTPoints == None:
140 raise ValueError("This SpectraProc.run() need nFFTPoints input variable")
139 raise ValueError("This SpectraProc.run() need nFFTPoints input variable")
141
140
142 if nProfiles == None:
141 if nProfiles == None:
143 nProfiles = nFFTPoints
142 nProfiles = nFFTPoints
144
143
145 if ippFactor == None:
144 if ippFactor == None:
146 self.dataOut.ippFactor = 1
145 self.dataOut.ippFactor = 1
147
146
148 self.dataOut.nFFTPoints = nFFTPoints
147 self.dataOut.nFFTPoints = nFFTPoints
149
148
150 if self.buffer is None:
149 if self.buffer is None:
151 self.buffer = numpy.zeros((self.dataIn.nChannels,
150 self.buffer = numpy.zeros((self.dataIn.nChannels,
152 nProfiles,
151 nProfiles,
153 self.dataIn.nHeights),
152 self.dataIn.nHeights),
154 dtype='complex')
153 dtype='complex')
155
154
156 if self.dataIn.flagDataAsBlock:
155 if self.dataIn.flagDataAsBlock:
157 nVoltProfiles = self.dataIn.data.shape[1]
156 nVoltProfiles = self.dataIn.data.shape[1]
158
159 if nVoltProfiles == nProfiles:
157 if nVoltProfiles == nProfiles:
160 self.buffer = self.dataIn.data.copy()
158 self.buffer = self.dataIn.data.copy()
161 self.profIndex = nVoltProfiles
159 self.profIndex = nVoltProfiles
162
160
163 elif nVoltProfiles < nProfiles:
161 elif nVoltProfiles < nProfiles:
164
162
165 if self.profIndex == 0:
163 if self.profIndex == 0:
166 self.id_min = 0
164 self.id_min = 0
167 self.id_max = nVoltProfiles
165 self.id_max = nVoltProfiles
168
166
169 self.buffer[:, self.id_min:self.id_max,
167 self.buffer[:, self.id_min:self.id_max,
170 :] = self.dataIn.data
168 :] = self.dataIn.data
171 self.profIndex += nVoltProfiles
169 self.profIndex += nVoltProfiles
172 self.id_min += nVoltProfiles
170 self.id_min += nVoltProfiles
173 self.id_max += nVoltProfiles
171 self.id_max += nVoltProfiles
172 elif nVoltProfiles > nProfiles:
173 self.reader.bypass = True
174 if self.profIndex == 0:
175 self.id_min = 0
176 self.id_max = nProfiles
177
178 self.buffer = self.dataIn.data[:, self.id_min:self.id_max,:]
179 self.profIndex += nProfiles
180 self.id_min += nProfiles
181 self.id_max += nProfiles
182 if self.id_max == nVoltProfiles:
183 self.reader.bypass = False
184
174 else:
185 else:
175 raise ValueError("The type object %s has %d profiles, it should just has %d profiles" % (
186 raise ValueError("The type object %s has %d profiles, it should just has %d profiles" % (
176 self.dataIn.type, self.dataIn.data.shape[1], nProfiles))
187 self.dataIn.type, self.dataIn.data.shape[1], nProfiles))
177 self.dataOut.flagNoData = True
188 self.dataOut.flagNoData = True
178 else:
189 else:
179 self.buffer[:, self.profIndex, :] = self.dataIn.data.copy()
190 self.buffer[:, self.profIndex, :] = self.dataIn.data.copy()
180 self.profIndex += 1
191 self.profIndex += 1
181
192
182 if self.firstdatatime == None:
193 if self.firstdatatime == None:
183 self.firstdatatime = self.dataIn.utctime
194 self.firstdatatime = self.dataIn.utctime
184
195
185 if self.profIndex == nProfiles:
196 if self.profIndex == nProfiles:
186 self.__updateSpecFromVoltage()
197 self.__updateSpecFromVoltage()
187 if pairsList == None:
198 if pairsList == None:
188 self.dataOut.pairsList = [pair for pair in itertools.combinations(self.dataOut.channelList, 2)]
199 self.dataOut.pairsList = [pair for pair in itertools.combinations(self.dataOut.channelList, 2)]
189 else:
200 else:
190 self.dataOut.pairsList = pairsList
201 self.dataOut.pairsList = pairsList
191 self.__getFft()
202 self.__getFft()
192 self.dataOut.flagNoData = False
203 self.dataOut.flagNoData = False
193 self.firstdatatime = None
204 self.firstdatatime = None
205 if not self.reader.bypass:
194 self.profIndex = 0
206 self.profIndex = 0
195 else:
207 else:
196 raise ValueError("The type of input object '%s' is not valid".format(
208 raise ValueError("The type of input object '%s' is not valid".format(
197 self.dataIn.type))
209 self.dataIn.type))
198
210
199 def __selectPairs(self, pairsList):
211 def __selectPairs(self, pairsList):
200
212
201 if not pairsList:
213 if not pairsList:
202 return
214 return
203
215
204 pairs = []
216 pairs = []
205 pairsIndex = []
217 pairsIndex = []
206
218
207 for pair in pairsList:
219 for pair in pairsList:
208 if pair[0] not in self.dataOut.channelList or pair[1] not in self.dataOut.channelList:
220 if pair[0] not in self.dataOut.channelList or pair[1] not in self.dataOut.channelList:
209 continue
221 continue
210 pairs.append(pair)
222 pairs.append(pair)
211 pairsIndex.append(pairs.index(pair))
223 pairsIndex.append(pairs.index(pair))
212
224
213 self.dataOut.data_cspc = self.dataOut.data_cspc[pairsIndex]
225 self.dataOut.data_cspc = self.dataOut.data_cspc[pairsIndex]
214 self.dataOut.pairsList = pairs
226 self.dataOut.pairsList = pairs
215
227
216 return
228 return
217
229
218 def selectFFTs(self, minFFT, maxFFT ):
230 def selectFFTs(self, minFFT, maxFFT):
219 """
231 """
220 Selecciona un bloque de datos en base a un grupo de valores de puntos FFTs segun el rango
232 Selecciona un bloque de datos en base a un grupo de valores de puntos FFTs segun el rango
221 minFFT<= FFT <= maxFFT
233 minFFT<= FFT <= maxFFT
222 """
234 """
223
235
224 if (minFFT > maxFFT):
236 if (minFFT > maxFFT):
225 raise ValueError("Error selecting heights: Height range (%d,%d) is not valid" % (minFFT, maxFFT))
237 raise ValueError("Error selecting heights: Height range (%d,%d) is not valid" % (minFFT, maxFFT))
226
238
227 if (minFFT < self.dataOut.getFreqRange()[0]):
239 if (minFFT < self.dataOut.getFreqRange()[0]):
228 minFFT = self.dataOut.getFreqRange()[0]
240 minFFT = self.dataOut.getFreqRange()[0]
229
241
230 if (maxFFT > self.dataOut.getFreqRange()[-1]):
242 if (maxFFT > self.dataOut.getFreqRange()[-1]):
231 maxFFT = self.dataOut.getFreqRange()[-1]
243 maxFFT = self.dataOut.getFreqRange()[-1]
232
244
233 minIndex = 0
245 minIndex = 0
234 maxIndex = 0
246 maxIndex = 0
235 FFTs = self.dataOut.getFreqRange()
247 FFTs = self.dataOut.getFreqRange()
236
248
237 inda = numpy.where(FFTs >= minFFT)
249 inda = numpy.where(FFTs >= minFFT)
238 indb = numpy.where(FFTs <= maxFFT)
250 indb = numpy.where(FFTs <= maxFFT)
239
251
240 try:
252 try:
241 minIndex = inda[0][0]
253 minIndex = inda[0][0]
242 except:
254 except:
243 minIndex = 0
255 minIndex = 0
244
256
245 try:
257 try:
246 maxIndex = indb[0][-1]
258 maxIndex = indb[0][-1]
247 except:
259 except:
248 maxIndex = len(FFTs)
260 maxIndex = len(FFTs)
249
261
250 self.selectFFTsByIndex(minIndex, maxIndex)
262 self.selectFFTsByIndex(minIndex, maxIndex)
251
263
252 return 1
264 return 1
253
265
254 def getBeaconSignal(self, tauindex=0, channelindex=0, hei_ref=None):
266 def getBeaconSignal(self, tauindex=0, channelindex=0, hei_ref=None):
255 newheis = numpy.where(
267 newheis = numpy.where(
256 self.dataOut.heightList > self.dataOut.radarControllerHeaderObj.Taus[tauindex])
268 self.dataOut.heightList > self.dataOut.radarControllerHeaderObj.Taus[tauindex])
257
269
258 if hei_ref != None:
270 if hei_ref != None:
259 newheis = numpy.where(self.dataOut.heightList > hei_ref)
271 newheis = numpy.where(self.dataOut.heightList > hei_ref)
260
272
261 minIndex = min(newheis[0])
273 minIndex = min(newheis[0])
262 maxIndex = max(newheis[0])
274 maxIndex = max(newheis[0])
263 data_spc = self.dataOut.data_spc[:, :, minIndex:maxIndex + 1]
275 data_spc = self.dataOut.data_spc[:, :, minIndex:maxIndex + 1]
264 heightList = self.dataOut.heightList[minIndex:maxIndex + 1]
276 heightList = self.dataOut.heightList[minIndex:maxIndex + 1]
265
277
266 # determina indices
278 # determina indices
267 nheis = int(self.dataOut.radarControllerHeaderObj.txB /
279 nheis = int(self.dataOut.radarControllerHeaderObj.txB /
268 (self.dataOut.heightList[1] - self.dataOut.heightList[0]))
280 (self.dataOut.heightList[1] - self.dataOut.heightList[0]))
269 avg_dB = 10 * \
281 avg_dB = 10 * \
270 numpy.log10(numpy.sum(data_spc[channelindex, :, :], axis=0))
282 numpy.log10(numpy.sum(data_spc[channelindex, :, :], axis=0))
271 beacon_dB = numpy.sort(avg_dB)[-nheis:]
283 beacon_dB = numpy.sort(avg_dB)[-nheis:]
272 beacon_heiIndexList = []
284 beacon_heiIndexList = []
273 for val in avg_dB.tolist():
285 for val in avg_dB.tolist():
274 if val >= beacon_dB[0]:
286 if val >= beacon_dB[0]:
275 beacon_heiIndexList.append(avg_dB.tolist().index(val))
287 beacon_heiIndexList.append(avg_dB.tolist().index(val))
276
288
277 #data_spc = data_spc[:,:,beacon_heiIndexList]
278 data_cspc = None
289 data_cspc = None
279 if self.dataOut.data_cspc is not None:
290 if self.dataOut.data_cspc is not None:
280 data_cspc = self.dataOut.data_cspc[:, :, minIndex:maxIndex + 1]
291 data_cspc = self.dataOut.data_cspc[:, :, minIndex:maxIndex + 1]
281 #data_cspc = data_cspc[:,:,beacon_heiIndexList]
282
292
283 data_dc = None
293 data_dc = None
284 if self.dataOut.data_dc is not None:
294 if self.dataOut.data_dc is not None:
285 data_dc = self.dataOut.data_dc[:, minIndex:maxIndex + 1]
295 data_dc = self.dataOut.data_dc[:, minIndex:maxIndex + 1]
286 #data_dc = data_dc[:,beacon_heiIndexList]
287
296
288 self.dataOut.data_spc = data_spc
297 self.dataOut.data_spc = data_spc
289 self.dataOut.data_cspc = data_cspc
298 self.dataOut.data_cspc = data_cspc
290 self.dataOut.data_dc = data_dc
299 self.dataOut.data_dc = data_dc
291 self.dataOut.heightList = heightList
300 self.dataOut.heightList = heightList
292 self.dataOut.beacon_heiIndexList = beacon_heiIndexList
301 self.dataOut.beacon_heiIndexList = beacon_heiIndexList
293
302
294 return 1
303 return 1
295
304
296 def selectFFTsByIndex(self, minIndex, maxIndex):
305 def selectFFTsByIndex(self, minIndex, maxIndex):
297 """
306 """
298
307
299 """
308 """
300
309
301 if (minIndex < 0) or (minIndex > maxIndex):
310 if (minIndex < 0) or (minIndex > maxIndex):
302 raise ValueError("Error selecting heights: Index range (%d,%d) is not valid" % (minIndex, maxIndex))
311 raise ValueError("Error selecting heights: Index range (%d,%d) is not valid" % (minIndex, maxIndex))
303
312
304 if (maxIndex >= self.dataOut.nProfiles):
313 if (maxIndex >= self.dataOut.nProfiles):
305 maxIndex = self.dataOut.nProfiles-1
314 maxIndex = self.dataOut.nProfiles-1
306
315
307 #Spectra
316 #Spectra
308 data_spc = self.dataOut.data_spc[:,minIndex:maxIndex+1,:]
317 data_spc = self.dataOut.data_spc[:,minIndex:maxIndex+1,:]
309
318
310 data_cspc = None
319 data_cspc = None
311 if self.dataOut.data_cspc is not None:
320 if self.dataOut.data_cspc is not None:
312 data_cspc = self.dataOut.data_cspc[:,minIndex:maxIndex+1,:]
321 data_cspc = self.dataOut.data_cspc[:,minIndex:maxIndex+1,:]
313
322
314 data_dc = None
323 data_dc = None
315 if self.dataOut.data_dc is not None:
324 if self.dataOut.data_dc is not None:
316 data_dc = self.dataOut.data_dc[minIndex:maxIndex+1,:]
325 data_dc = self.dataOut.data_dc[minIndex:maxIndex+1,:]
317
326
318 self.dataOut.data_spc = data_spc
327 self.dataOut.data_spc = data_spc
319 self.dataOut.data_cspc = data_cspc
328 self.dataOut.data_cspc = data_cspc
320 self.dataOut.data_dc = data_dc
329 self.dataOut.data_dc = data_dc
321
330
322 self.dataOut.ippSeconds = self.dataOut.ippSeconds*(self.dataOut.nFFTPoints / numpy.shape(data_cspc)[1])
331 self.dataOut.ippSeconds = self.dataOut.ippSeconds*(self.dataOut.nFFTPoints / numpy.shape(data_cspc)[1])
323 self.dataOut.nFFTPoints = numpy.shape(data_cspc)[1]
332 self.dataOut.nFFTPoints = numpy.shape(data_cspc)[1]
324 self.dataOut.profilesPerBlock = numpy.shape(data_cspc)[1]
333 self.dataOut.profilesPerBlock = numpy.shape(data_cspc)[1]
325
334
326 return 1
335 return 1
327
336
328 def getNoise(self, minHei=None, maxHei=None, minVel=None, maxVel=None):
337 def getNoise(self, minHei=None, maxHei=None, minVel=None, maxVel=None):
329 # validacion de rango
338 # validacion de rango
330 if minHei == None:
339 if minHei == None:
331 minHei = self.dataOut.heightList[0]
340 minHei = self.dataOut.heightList[0]
332
341
333 if maxHei == None:
342 if maxHei == None:
334 maxHei = self.dataOut.heightList[-1]
343 maxHei = self.dataOut.heightList[-1]
335
344
336 if (minHei < self.dataOut.heightList[0]) or (minHei > maxHei):
345 if (minHei < self.dataOut.heightList[0]) or (minHei > maxHei):
337 print('minHei: %.2f is out of the heights range' % (minHei))
346 print('minHei: %.2f is out of the heights range' % (minHei))
338 print('minHei is setting to %.2f' % (self.dataOut.heightList[0]))
347 print('minHei is setting to %.2f' % (self.dataOut.heightList[0]))
339 minHei = self.dataOut.heightList[0]
348 minHei = self.dataOut.heightList[0]
340
349
341 if (maxHei > self.dataOut.heightList[-1]) or (maxHei < minHei):
350 if (maxHei > self.dataOut.heightList[-1]) or (maxHei < minHei):
342 print('maxHei: %.2f is out of the heights range' % (maxHei))
351 print('maxHei: %.2f is out of the heights range' % (maxHei))
343 print('maxHei is setting to %.2f' % (self.dataOut.heightList[-1]))
352 print('maxHei is setting to %.2f' % (self.dataOut.heightList[-1]))
344 maxHei = self.dataOut.heightList[-1]
353 maxHei = self.dataOut.heightList[-1]
345
354
346 # validacion de velocidades
355 # validacion de velocidades
347 velrange = self.dataOut.getVelRange(1)
356 velrange = self.dataOut.getVelRange(1)
348
357
349 if minVel == None:
358 if minVel == None:
350 minVel = velrange[0]
359 minVel = velrange[0]
351
360
352 if maxVel == None:
361 if maxVel == None:
353 maxVel = velrange[-1]
362 maxVel = velrange[-1]
354
363
355 if (minVel < velrange[0]) or (minVel > maxVel):
364 if (minVel < velrange[0]) or (minVel > maxVel):
356 print('minVel: %.2f is out of the velocity range' % (minVel))
365 print('minVel: %.2f is out of the velocity range' % (minVel))
357 print('minVel is setting to %.2f' % (velrange[0]))
366 print('minVel is setting to %.2f' % (velrange[0]))
358 minVel = velrange[0]
367 minVel = velrange[0]
359
368
360 if (maxVel > velrange[-1]) or (maxVel < minVel):
369 if (maxVel > velrange[-1]) or (maxVel < minVel):
361 print('maxVel: %.2f is out of the velocity range' % (maxVel))
370 print('maxVel: %.2f is out of the velocity range' % (maxVel))
362 print('maxVel is setting to %.2f' % (velrange[-1]))
371 print('maxVel is setting to %.2f' % (velrange[-1]))
363 maxVel = velrange[-1]
372 maxVel = velrange[-1]
364
373
365 # seleccion de indices para rango
374 # seleccion de indices para rango
366 minIndex = 0
375 minIndex = 0
367 maxIndex = 0
376 maxIndex = 0
368 heights = self.dataOut.heightList
377 heights = self.dataOut.heightList
369
378
370 inda = numpy.where(heights >= minHei)
379 inda = numpy.where(heights >= minHei)
371 indb = numpy.where(heights <= maxHei)
380 indb = numpy.where(heights <= maxHei)
372
381
373 try:
382 try:
374 minIndex = inda[0][0]
383 minIndex = inda[0][0]
375 except:
384 except:
376 minIndex = 0
385 minIndex = 0
377
386
378 try:
387 try:
379 maxIndex = indb[0][-1]
388 maxIndex = indb[0][-1]
380 except:
389 except:
381 maxIndex = len(heights)
390 maxIndex = len(heights)
382
391
383 if (minIndex < 0) or (minIndex > maxIndex):
392 if (minIndex < 0) or (minIndex > maxIndex):
384 raise ValueError("some value in (%d,%d) is not valid" % (
393 raise ValueError("some value in (%d,%d) is not valid" % (
385 minIndex, maxIndex))
394 minIndex, maxIndex))
386
395
387 if (maxIndex >= self.dataOut.nHeights):
396 if (maxIndex >= self.dataOut.nHeights):
388 maxIndex = self.dataOut.nHeights - 1
397 maxIndex = self.dataOut.nHeights - 1
389
398
390 # seleccion de indices para velocidades
399 # seleccion de indices para velocidades
391 indminvel = numpy.where(velrange >= minVel)
400 indminvel = numpy.where(velrange >= minVel)
392 indmaxvel = numpy.where(velrange <= maxVel)
401 indmaxvel = numpy.where(velrange <= maxVel)
393 try:
402 try:
394 minIndexVel = indminvel[0][0]
403 minIndexVel = indminvel[0][0]
395 except:
404 except:
396 minIndexVel = 0
405 minIndexVel = 0
397
406
398 try:
407 try:
399 maxIndexVel = indmaxvel[0][-1]
408 maxIndexVel = indmaxvel[0][-1]
400 except:
409 except:
401 maxIndexVel = len(velrange)
410 maxIndexVel = len(velrange)
402
411
403 # seleccion del espectro
412 # seleccion del espectro
404 data_spc = self.dataOut.data_spc[:,
413 data_spc = self.dataOut.data_spc[:,
405 minIndexVel:maxIndexVel + 1, minIndex:maxIndex + 1]
414 minIndexVel:maxIndexVel + 1, minIndex:maxIndex + 1]
406 # estimacion de ruido
415 # estimacion de ruido
407 noise = numpy.zeros(self.dataOut.nChannels)
416 noise = numpy.zeros(self.dataOut.nChannels)
408
417
409 for channel in range(self.dataOut.nChannels):
418 for channel in range(self.dataOut.nChannels):
410 daux = data_spc[channel, :, :]
419 daux = data_spc[channel, :, :]
411 sortdata = numpy.sort(daux, axis=None)
420 sortdata = numpy.sort(daux, axis=None)
412 noise[channel] = hildebrand_sekhon(sortdata, self.dataOut.nIncohInt)
421 noise[channel] = hildebrand_sekhon(sortdata, self.dataOut.nIncohInt)
413
422
414 self.dataOut.noise_estimation = noise.copy()
423 self.dataOut.noise_estimation = noise.copy()
415
424
416 return 1
425 return 1
417
426
418 class removeDC(Operation):
427 class removeDC(Operation):
419
428
420 def run(self, dataOut, mode=2):
429 def run(self, dataOut, mode=2):
421 self.dataOut = dataOut
430 self.dataOut = dataOut
422 jspectra = self.dataOut.data_spc
431 jspectra = self.dataOut.data_spc
423 jcspectra = self.dataOut.data_cspc
432 jcspectra = self.dataOut.data_cspc
424
433
425 num_chan = jspectra.shape[0]
434 num_chan = jspectra.shape[0]
426 num_hei = jspectra.shape[2]
435 num_hei = jspectra.shape[2]
427
436
428 if jcspectra is not None:
437 if jcspectra is not None:
429 jcspectraExist = True
438 jcspectraExist = True
430 num_pairs = jcspectra.shape[0]
439 num_pairs = jcspectra.shape[0]
431 else:
440 else:
432 jcspectraExist = False
441 jcspectraExist = False
433
442
434 freq_dc = int(jspectra.shape[1] / 2)
443 freq_dc = int(jspectra.shape[1] / 2)
435 ind_vel = numpy.array([-2, -1, 1, 2]) + freq_dc
444 ind_vel = numpy.array([-2, -1, 1, 2]) + freq_dc
436 ind_vel = ind_vel.astype(int)
445 ind_vel = ind_vel.astype(int)
437
446
438 if ind_vel[0] < 0:
447 if ind_vel[0] < 0:
439 ind_vel[list(range(0, 1))] = ind_vel[list(range(0, 1))] + self.num_prof
448 ind_vel[list(range(0, 1))] = ind_vel[list(range(0, 1))] + self.num_prof
440
449
441 if mode == 1:
450 if mode == 1:
442 jspectra[:, freq_dc, :] = (
451 jspectra[:, freq_dc, :] = (
443 jspectra[:, ind_vel[1], :] + jspectra[:, ind_vel[2], :]) / 2 # CORRECCION
452 jspectra[:, ind_vel[1], :] + jspectra[:, ind_vel[2], :]) / 2 # CORRECCION
444
453
445 if jcspectraExist:
454 if jcspectraExist:
446 jcspectra[:, freq_dc, :] = (
455 jcspectra[:, freq_dc, :] = (
447 jcspectra[:, ind_vel[1], :] + jcspectra[:, ind_vel[2], :]) / 2
456 jcspectra[:, ind_vel[1], :] + jcspectra[:, ind_vel[2], :]) / 2
448
457
449 if mode == 2:
458 if mode == 2:
450
459
451 vel = numpy.array([-2, -1, 1, 2])
460 vel = numpy.array([-2, -1, 1, 2])
452 xx = numpy.zeros([4, 4])
461 xx = numpy.zeros([4, 4])
453
462
454 for fil in range(4):
463 for fil in range(4):
455 xx[fil, :] = vel[fil]**numpy.asarray(list(range(4)))
464 xx[fil, :] = vel[fil]**numpy.asarray(list(range(4)))
456
465
457 xx_inv = numpy.linalg.inv(xx)
466 xx_inv = numpy.linalg.inv(xx)
458 xx_aux = xx_inv[0, :]
467 xx_aux = xx_inv[0, :]
459
468
460 for ich in range(num_chan):
469 for ich in range(num_chan):
461 yy = jspectra[ich, ind_vel, :]
470 yy = jspectra[ich, ind_vel, :]
462 jspectra[ich, freq_dc, :] = numpy.dot(xx_aux, yy)
471 jspectra[ich, freq_dc, :] = numpy.dot(xx_aux, yy)
463
472
464 junkid = jspectra[ich, freq_dc, :] <= 0
473 junkid = jspectra[ich, freq_dc, :] <= 0
465 cjunkid = sum(junkid)
474 cjunkid = sum(junkid)
466
475
467 if cjunkid.any():
476 if cjunkid.any():
468 jspectra[ich, freq_dc, junkid.nonzero()] = (
477 jspectra[ich, freq_dc, junkid.nonzero()] = (
469 jspectra[ich, ind_vel[1], junkid] + jspectra[ich, ind_vel[2], junkid]) / 2
478 jspectra[ich, ind_vel[1], junkid] + jspectra[ich, ind_vel[2], junkid]) / 2
470
479
471 if jcspectraExist:
480 if jcspectraExist:
472 for ip in range(num_pairs):
481 for ip in range(num_pairs):
473 yy = jcspectra[ip, ind_vel, :]
482 yy = jcspectra[ip, ind_vel, :]
474 jcspectra[ip, freq_dc, :] = numpy.dot(xx_aux, yy)
483 jcspectra[ip, freq_dc, :] = numpy.dot(xx_aux, yy)
475
484
476 self.dataOut.data_spc = jspectra
485 self.dataOut.data_spc = jspectra
477 self.dataOut.data_cspc = jcspectra
486 self.dataOut.data_cspc = jcspectra
478
487
479 return self.dataOut
488 return self.dataOut
480
489
481 class removeInterference(Operation):
490 class removeInterference(Operation):
482
491
483 def removeInterference2(self):
492 def removeInterference2(self):
484
493
485 cspc = self.dataOut.data_cspc
494 cspc = self.dataOut.data_cspc
486 spc = self.dataOut.data_spc
495 spc = self.dataOut.data_spc
487 Heights = numpy.arange(cspc.shape[2])
496 Heights = numpy.arange(cspc.shape[2])
488 realCspc = numpy.abs(cspc)
497 realCspc = numpy.abs(cspc)
489
498
490 for i in range(cspc.shape[0]):
499 for i in range(cspc.shape[0]):
491 LinePower= numpy.sum(realCspc[i], axis=0)
500 LinePower= numpy.sum(realCspc[i], axis=0)
492 Threshold = numpy.amax(LinePower)-numpy.sort(LinePower)[len(Heights)-int(len(Heights)*0.1)]
501 Threshold = numpy.amax(LinePower)-numpy.sort(LinePower)[len(Heights)-int(len(Heights)*0.1)]
493 SelectedHeights = Heights[ numpy.where( LinePower < Threshold ) ]
502 SelectedHeights = Heights[ numpy.where(LinePower < Threshold) ]
494 InterferenceSum = numpy.sum( realCspc[i,:,SelectedHeights], axis=0 )
503 InterferenceSum = numpy.sum(realCspc[i,:,SelectedHeights],axis=0)
495 InterferenceThresholdMin = numpy.sort(InterferenceSum)[int(len(InterferenceSum)*0.98)]
504 InterferenceThresholdMin = numpy.sort(InterferenceSum)[int(len(InterferenceSum)*0.98)]
496 InterferenceThresholdMax = numpy.sort(InterferenceSum)[int(len(InterferenceSum)*0.99)]
505 InterferenceThresholdMax = numpy.sort(InterferenceSum)[int(len(InterferenceSum)*0.99)]
497
506
498
507
499 InterferenceRange = numpy.where( ([InterferenceSum > InterferenceThresholdMin]))# , InterferenceSum < InterferenceThresholdMax]) )
508 InterferenceRange = numpy.where(([InterferenceSum > InterferenceThresholdMin]))# , InterferenceSum < InterferenceThresholdMax]) )
500 #InterferenceRange = numpy.where( ([InterferenceRange < InterferenceThresholdMax]))
509 #InterferenceRange = numpy.where( ([InterferenceRange < InterferenceThresholdMax]))
501 if len(InterferenceRange)<int(cspc.shape[1]*0.3):
510 if len(InterferenceRange)<int(cspc.shape[1]*0.3):
502 cspc[i,InterferenceRange,:] = numpy.NaN
511 cspc[i,InterferenceRange,:] = numpy.NaN
503
512
504 self.dataOut.data_cspc = cspc
513 self.dataOut.data_cspc = cspc
505
514
506 def removeInterference(self, interf = 2, hei_interf = None, nhei_interf = None, offhei_interf = None):
515 def removeInterference(self, interf=2, hei_interf=None, nhei_interf=None, offhei_interf=None):
507
516
508 jspectra = self.dataOut.data_spc
517 jspectra = self.dataOut.data_spc
509 jcspectra = self.dataOut.data_cspc
518 jcspectra = self.dataOut.data_cspc
510 jnoise = self.dataOut.getNoise()
519 jnoise = self.dataOut.getNoise()
511 num_incoh = self.dataOut.nIncohInt
520 num_incoh = self.dataOut.nIncohInt
512
521
513 num_channel = jspectra.shape[0]
522 num_channel = jspectra.shape[0]
514 num_prof = jspectra.shape[1]
523 num_prof = jspectra.shape[1]
515 num_hei = jspectra.shape[2]
524 num_hei = jspectra.shape[2]
516
525
517 # hei_interf
526 # hei_interf
518 if hei_interf is None:
527 if hei_interf is None:
519 count_hei = int(num_hei / 2)
528 count_hei = int(num_hei / 2)
520 hei_interf = numpy.asmatrix(list(range(count_hei))) + num_hei - count_hei
529 hei_interf = numpy.asmatrix(list(range(count_hei))) + num_hei - count_hei
521 hei_interf = numpy.asarray(hei_interf)[0]
530 hei_interf = numpy.asarray(hei_interf)[0]
522 # nhei_interf
531 # nhei_interf
523 if (nhei_interf == None):
532 if (nhei_interf == None):
524 nhei_interf = 5
533 nhei_interf = 5
525 if (nhei_interf < 1):
534 if (nhei_interf < 1):
526 nhei_interf = 1
535 nhei_interf = 1
527 if (nhei_interf > count_hei):
536 if (nhei_interf > count_hei):
528 nhei_interf = count_hei
537 nhei_interf = count_hei
529 if (offhei_interf == None):
538 if (offhei_interf == None):
530 offhei_interf = 0
539 offhei_interf = 0
531
540
532 ind_hei = list(range(num_hei))
541 ind_hei = list(range(num_hei))
533 # mask_prof = numpy.asarray(range(num_prof - 2)) + 1
542 # mask_prof = numpy.asarray(range(num_prof - 2)) + 1
534 # mask_prof[range(num_prof/2 - 1,len(mask_prof))] += 1
543 # mask_prof[range(num_prof/2 - 1,len(mask_prof))] += 1
535 mask_prof = numpy.asarray(list(range(num_prof)))
544 mask_prof = numpy.asarray(list(range(num_prof)))
536 num_mask_prof = mask_prof.size
545 num_mask_prof = mask_prof.size
537 comp_mask_prof = [0, num_prof / 2]
546 comp_mask_prof = [0, num_prof / 2]
538
547
539 # noise_exist: Determina si la variable jnoise ha sido definida y contiene la informacion del ruido de cada canal
548 # noise_exist: Determina si la variable jnoise ha sido definida y contiene la informacion del ruido de cada canal
540 if (jnoise.size < num_channel or numpy.isnan(jnoise).any()):
549 if (jnoise.size < num_channel or numpy.isnan(jnoise).any()):
541 jnoise = numpy.nan
550 jnoise = numpy.nan
542 noise_exist = jnoise[0] < numpy.Inf
551 noise_exist = jnoise[0] < numpy.Inf
543
552
544 # Subrutina de Remocion de la Interferencia
553 # Subrutina de Remocion de la Interferencia
545 for ich in range(num_channel):
554 for ich in range(num_channel):
546 # Se ordena los espectros segun su potencia (menor a mayor)
555 # Se ordena los espectros segun su potencia (menor a mayor)
547 power = jspectra[ich, mask_prof, :]
556 power = jspectra[ich, mask_prof, :]
548 power = power[:, hei_interf]
557 power = power[:, hei_interf]
549 power = power.sum(axis=0)
558 power = power.sum(axis=0)
550 psort = power.ravel().argsort()
559 psort = power.ravel().argsort()
551
560
552 # Se estima la interferencia promedio en los Espectros de Potencia empleando
561 # Se estima la interferencia promedio en los Espectros de Potencia empleando
553 junkspc_interf = jspectra[ich, :, hei_interf[psort[list(range(
562 junkspc_interf = jspectra[ich, :, hei_interf[psort[list(range(
554 offhei_interf, nhei_interf + offhei_interf))]]]
563 offhei_interf, nhei_interf + offhei_interf))]]]
555
564
556 if noise_exist:
565 if noise_exist:
557 # tmp_noise = jnoise[ich] / num_prof
566 # tmp_noise = jnoise[ich] / num_prof
558 tmp_noise = jnoise[ich]
567 tmp_noise = jnoise[ich]
559 junkspc_interf = junkspc_interf - tmp_noise
568 junkspc_interf = junkspc_interf - tmp_noise
560 #junkspc_interf[:,comp_mask_prof] = 0
569 #junkspc_interf[:,comp_mask_prof] = 0
561
570
562 jspc_interf = junkspc_interf.sum(axis=0) / nhei_interf
571 jspc_interf = junkspc_interf.sum(axis=0) / nhei_interf
563 jspc_interf = jspc_interf.transpose()
572 jspc_interf = jspc_interf.transpose()
564 # Calculando el espectro de interferencia promedio
573 # Calculando el espectro de interferencia promedio
565 noiseid = numpy.where(
574 noiseid = numpy.where(
566 jspc_interf <= tmp_noise / numpy.sqrt(num_incoh))
575 jspc_interf <= tmp_noise / numpy.sqrt(num_incoh))
567 noiseid = noiseid[0]
576 noiseid = noiseid[0]
568 cnoiseid = noiseid.size
577 cnoiseid = noiseid.size
569 interfid = numpy.where(
578 interfid = numpy.where(
570 jspc_interf > tmp_noise / numpy.sqrt(num_incoh))
579 jspc_interf > tmp_noise / numpy.sqrt(num_incoh))
571 interfid = interfid[0]
580 interfid = interfid[0]
572 cinterfid = interfid.size
581 cinterfid = interfid.size
573
582
574 if (cnoiseid > 0):
583 if (cnoiseid > 0):
575 jspc_interf[noiseid] = 0
584 jspc_interf[noiseid] = 0
576
585
577 # Expandiendo los perfiles a limpiar
586 # Expandiendo los perfiles a limpiar
578 if (cinterfid > 0):
587 if (cinterfid > 0):
579 new_interfid = (
588 new_interfid = (
580 numpy.r_[interfid - 1, interfid, interfid + 1] + num_prof) % num_prof
589 numpy.r_[interfid - 1, interfid, interfid + 1] + num_prof) % num_prof
581 new_interfid = numpy.asarray(new_interfid)
590 new_interfid = numpy.asarray(new_interfid)
582 new_interfid = {x for x in new_interfid}
591 new_interfid = {x for x in new_interfid}
583 new_interfid = numpy.array(list(new_interfid))
592 new_interfid = numpy.array(list(new_interfid))
584 new_cinterfid = new_interfid.size
593 new_cinterfid = new_interfid.size
585 else:
594 else:
586 new_cinterfid = 0
595 new_cinterfid = 0
587
596
588 for ip in range(new_cinterfid):
597 for ip in range(new_cinterfid):
589 ind = junkspc_interf[:, new_interfid[ip]].ravel().argsort()
598 ind = junkspc_interf[:, new_interfid[ip]].ravel().argsort()
590 jspc_interf[new_interfid[ip]
599 jspc_interf[new_interfid[ip]
591 ] = junkspc_interf[ind[nhei_interf // 2], new_interfid[ip]]
600 ] = junkspc_interf[ind[nhei_interf // 2], new_interfid[ip]]
592
601
593 jspectra[ich, :, ind_hei] = jspectra[ich, :,
602 jspectra[ich, :, ind_hei] = jspectra[ich, :,
594 ind_hei] - jspc_interf # Corregir indices
603 ind_hei] - jspc_interf # Corregir indices
595
604
596 # Removiendo la interferencia del punto de mayor interferencia
605 # Removiendo la interferencia del punto de mayor interferencia
597 ListAux = jspc_interf[mask_prof].tolist()
606 ListAux = jspc_interf[mask_prof].tolist()
598 maxid = ListAux.index(max(ListAux))
607 maxid = ListAux.index(max(ListAux))
599
608
600 if cinterfid > 0:
609 if cinterfid > 0:
601 for ip in range(cinterfid * (interf == 2) - 1):
610 for ip in range(cinterfid * (interf == 2) - 1):
602 ind = (jspectra[ich, interfid[ip], :] < tmp_noise *
611 ind = (jspectra[ich, interfid[ip], :] < tmp_noise *
603 (1 + 1 / numpy.sqrt(num_incoh))).nonzero()
612 (1 + 1 / numpy.sqrt(num_incoh))).nonzero()
604 cind = len(ind)
613 cind = len(ind)
605
614
606 if (cind > 0):
615 if (cind > 0):
607 jspectra[ich, interfid[ip], ind] = tmp_noise * \
616 jspectra[ich, interfid[ip], ind] = tmp_noise * \
608 (1 + (numpy.random.uniform(cind) - 0.5) /
617 (1 + (numpy.random.uniform(cind) - 0.5) /
609 numpy.sqrt(num_incoh))
618 numpy.sqrt(num_incoh))
610
619
611 ind = numpy.array([-2, -1, 1, 2])
620 ind = numpy.array([-2, -1, 1, 2])
612 xx = numpy.zeros([4, 4])
621 xx = numpy.zeros([4, 4])
613
622
614 for id1 in range(4):
623 for id1 in range(4):
615 xx[:, id1] = ind[id1]**numpy.asarray(list(range(4)))
624 xx[:, id1] = ind[id1]**numpy.asarray(list(range(4)))
616
625
617 xx_inv = numpy.linalg.inv(xx)
626 xx_inv = numpy.linalg.inv(xx)
618 xx = xx_inv[:, 0]
627 xx = xx_inv[:, 0]
619 ind = (ind + maxid + num_mask_prof) % num_mask_prof
628 ind = (ind + maxid + num_mask_prof) % num_mask_prof
620 yy = jspectra[ich, mask_prof[ind], :]
629 yy = jspectra[ich, mask_prof[ind], :]
621 jspectra[ich, mask_prof[maxid], :] = numpy.dot(
630 jspectra[ich, mask_prof[maxid], :] = numpy.dot(
622 yy.transpose(), xx)
631 yy.transpose(), xx)
623
632
624 indAux = (jspectra[ich, :, :] < tmp_noise *
633 indAux = (jspectra[ich, :, :] < tmp_noise *
625 (1 - 1 / numpy.sqrt(num_incoh))).nonzero()
634 (1 - 1 / numpy.sqrt(num_incoh))).nonzero()
626 jspectra[ich, indAux[0], indAux[1]] = tmp_noise * \
635 jspectra[ich, indAux[0], indAux[1]] = tmp_noise * \
627 (1 - 1 / numpy.sqrt(num_incoh))
636 (1 - 1 / numpy.sqrt(num_incoh))
628
637
629 # Remocion de Interferencia en el Cross Spectra
638 # Remocion de Interferencia en el Cross Spectra
630 if jcspectra is None:
639 if jcspectra is None:
631 return jspectra, jcspectra
640 return jspectra, jcspectra
632 num_pairs = int(jcspectra.size / (num_prof * num_hei))
641 num_pairs = int(jcspectra.size / (num_prof * num_hei))
633 jcspectra = jcspectra.reshape(num_pairs, num_prof, num_hei)
642 jcspectra = jcspectra.reshape(num_pairs, num_prof, num_hei)
634
643
635 for ip in range(num_pairs):
644 for ip in range(num_pairs):
636
645
637 #-------------------------------------------
646 #-------------------------------------------
638
647
639 cspower = numpy.abs(jcspectra[ip, mask_prof, :])
648 cspower = numpy.abs(jcspectra[ip, mask_prof, :])
640 cspower = cspower[:, hei_interf]
649 cspower = cspower[:, hei_interf]
641 cspower = cspower.sum(axis=0)
650 cspower = cspower.sum(axis=0)
642
651
643 cspsort = cspower.ravel().argsort()
652 cspsort = cspower.ravel().argsort()
644 junkcspc_interf = jcspectra[ip, :, hei_interf[cspsort[list(range(
653 junkcspc_interf = jcspectra[ip, :, hei_interf[cspsort[list(range(
645 offhei_interf, nhei_interf + offhei_interf))]]]
654 offhei_interf, nhei_interf + offhei_interf))]]]
646 junkcspc_interf = junkcspc_interf.transpose()
655 junkcspc_interf = junkcspc_interf.transpose()
647 jcspc_interf = junkcspc_interf.sum(axis=1) / nhei_interf
656 jcspc_interf = junkcspc_interf.sum(axis=1) / nhei_interf
648
657
649 ind = numpy.abs(jcspc_interf[mask_prof]).ravel().argsort()
658 ind = numpy.abs(jcspc_interf[mask_prof]).ravel().argsort()
650
659
651 median_real = int(numpy.median(numpy.real(
660 median_real = int(numpy.median(numpy.real(
652 junkcspc_interf[mask_prof[ind[list(range(3 * num_prof // 4))]], :])))
661 junkcspc_interf[mask_prof[ind[list(range(3 * num_prof // 4))]], :])))
653 median_imag = int(numpy.median(numpy.imag(
662 median_imag = int(numpy.median(numpy.imag(
654 junkcspc_interf[mask_prof[ind[list(range(3 * num_prof // 4))]], :])))
663 junkcspc_interf[mask_prof[ind[list(range(3 * num_prof // 4))]], :])))
655 comp_mask_prof = [int(e) for e in comp_mask_prof]
664 comp_mask_prof = [int(e) for e in comp_mask_prof]
656 junkcspc_interf[comp_mask_prof, :] = numpy.complex(
665 junkcspc_interf[comp_mask_prof, :] = numpy.complex(
657 median_real, median_imag)
666 median_real, median_imag)
658
667
659 for iprof in range(num_prof):
668 for iprof in range(num_prof):
660 ind = numpy.abs(junkcspc_interf[iprof, :]).ravel().argsort()
669 ind = numpy.abs(junkcspc_interf[iprof, :]).ravel().argsort()
661 jcspc_interf[iprof] = junkcspc_interf[iprof, ind[nhei_interf // 2]]
670 jcspc_interf[iprof] = junkcspc_interf[iprof, ind[nhei_interf // 2]]
662
671
663 # Removiendo la Interferencia
672 # Removiendo la Interferencia
664 jcspectra[ip, :, ind_hei] = jcspectra[ip,
673 jcspectra[ip, :, ind_hei] = jcspectra[ip,
665 :, ind_hei] - jcspc_interf
674 :, ind_hei] - jcspc_interf
666
675
667 ListAux = numpy.abs(jcspc_interf[mask_prof]).tolist()
676 ListAux = numpy.abs(jcspc_interf[mask_prof]).tolist()
668 maxid = ListAux.index(max(ListAux))
677 maxid = ListAux.index(max(ListAux))
669
678
670 ind = numpy.array([-2, -1, 1, 2])
679 ind = numpy.array([-2, -1, 1, 2])
671 xx = numpy.zeros([4, 4])
680 xx = numpy.zeros([4, 4])
672
681
673 for id1 in range(4):
682 for id1 in range(4):
674 xx[:, id1] = ind[id1]**numpy.asarray(list(range(4)))
683 xx[:, id1] = ind[id1]**numpy.asarray(list(range(4)))
675
684
676 xx_inv = numpy.linalg.inv(xx)
685 xx_inv = numpy.linalg.inv(xx)
677 xx = xx_inv[:, 0]
686 xx = xx_inv[:, 0]
678
687
679 ind = (ind + maxid + num_mask_prof) % num_mask_prof
688 ind = (ind + maxid + num_mask_prof) % num_mask_prof
680 yy = jcspectra[ip, mask_prof[ind], :]
689 yy = jcspectra[ip, mask_prof[ind], :]
681 jcspectra[ip, mask_prof[maxid], :] = numpy.dot(yy.transpose(), xx)
690 jcspectra[ip, mask_prof[maxid], :] = numpy.dot(yy.transpose(), xx)
682
691
683 # Guardar Resultados
692 # Guardar Resultados
684 self.dataOut.data_spc = jspectra
693 self.dataOut.data_spc = jspectra
685 self.dataOut.data_cspc = jcspectra
694 self.dataOut.data_cspc = jcspectra
686
695
687 return 1
696 return 1
688
697
689 def run(self, dataOut, interf = 2,hei_interf = None, nhei_interf = None, offhei_interf = None, mode=1):
698 def run(self, dataOut, interf=2,hei_interf=None, nhei_interf=None, offhei_interf=None, mode=1):
690
699
691 self.dataOut = dataOut
700 self.dataOut = dataOut
692
701
693 if mode == 1:
702 if mode == 1:
694 self.removeInterference(interf = 2,hei_interf = None, nhei_interf = None, offhei_interf = None)
703 self.removeInterference(interf=2,hei_interf=None, nhei_interf=None, offhei_interf=None)
695 elif mode == 2:
704 elif mode == 2:
696 self.removeInterference2()
705 self.removeInterference2()
697
706
698 return self.dataOut
707 return self.dataOut
699
708
700
709
710 class deflip(Operation):
711
712 def run(self, dataOut):
713 # arreglo 1: (num_chan, num_profiles, num_heights)
714 self.dataOut = dataOut
715
716 # JULIA-oblicua, indice 2
717 # arreglo 2: (num_profiles, num_heights)
718 jspectra = self.dataOut.data_spc[2]
719 jspectra_tmp=numpy.zeros(jspectra.shape)
720 num_profiles=jspectra.shape[0]
721 freq_dc = int(num_profiles / 2)
722 # Flip con for
723 for j in range(num_profiles):
724 jspectra_tmp[num_profiles-j-1]= jspectra[j]
725 # Intercambio perfil de DC con perfil inmediato anterior
726 jspectra_tmp[freq_dc-1]= jspectra[freq_dc-1]
727 jspectra_tmp[freq_dc]= jspectra[freq_dc]
728 # canal modificado es re-escrito en el arreglo de canales
729 self.dataOut.data_spc[2] = jspectra_tmp
730
731 return self.dataOut
732
733
701 class IncohInt(Operation):
734 class IncohInt(Operation):
702
735
703 __profIndex = 0
736 __profIndex = 0
704 __withOverapping = False
737 __withOverapping = False
705
738
706 __byTime = False
739 __byTime = False
707 __initime = None
740 __initime = None
708 __lastdatatime = None
741 __lastdatatime = None
709 __integrationtime = None
742 __integrationtime = None
710
743
711 __buffer_spc = None
744 __buffer_spc = None
712 __buffer_cspc = None
745 __buffer_cspc = None
713 __buffer_dc = None
746 __buffer_dc = None
714
747
715 __dataReady = False
748 __dataReady = False
716
749
717 __timeInterval = None
750 __timeInterval = None
718
751
719 n = None
752 n = None
720
753
721 def __init__(self):
754 def __init__(self):
722
755
723 Operation.__init__(self)
756 Operation.__init__(self)
724
757
725 def setup(self, n=None, timeInterval=None, overlapping=False):
758 def setup(self, n=None, timeInterval=None, overlapping=False):
726 """
759 """
727 Set the parameters of the integration class.
760 Set the parameters of the integration class.
728
761
729 Inputs:
762 Inputs:
730
763
731 n : Number of coherent integrations
764 n : Number of coherent integrations
732 timeInterval : Time of integration. If the parameter "n" is selected this one does not work
765 timeInterval : Time of integration. If the parameter "n" is selected this one does not work
733 overlapping :
766 overlapping :
734
767
735 """
768 """
736
769
737 self.__initime = None
770 self.__initime = None
738 self.__lastdatatime = 0
771 self.__lastdatatime = 0
739
772
740 self.__buffer_spc = 0
773 self.__buffer_spc = 0
741 self.__buffer_cspc = 0
774 self.__buffer_cspc = 0
742 self.__buffer_dc = 0
775 self.__buffer_dc = 0
743
776
744 self.__profIndex = 0
777 self.__profIndex = 0
745 self.__dataReady = False
778 self.__dataReady = False
746 self.__byTime = False
779 self.__byTime = False
747
780
748 if n is None and timeInterval is None:
781 if n is None and timeInterval is None:
749 raise ValueError("n or timeInterval should be specified ...")
782 raise ValueError("n or timeInterval should be specified ...")
750
783
751 if n is not None:
784 if n is not None:
752 self.n = int(n)
785 self.n = int(n)
753 else:
786 else:
754
787
755 self.__integrationtime = int(timeInterval)
788 self.__integrationtime = int(timeInterval)
756 self.n = None
789 self.n = None
757 self.__byTime = True
790 self.__byTime = True
758
791
759 def putData(self, data_spc, data_cspc, data_dc):
792 def putData(self, data_spc, data_cspc, data_dc):
760 """
793 """
761 Add a profile to the __buffer_spc and increase in one the __profileIndex
794 Add a profile to the __buffer_spc and increase in one the __profileIndex
762
795
763 """
796 """
764
797
765 self.__buffer_spc += data_spc
798 self.__buffer_spc += data_spc
766
799
767 if data_cspc is None:
800 if data_cspc is None:
768 self.__buffer_cspc = None
801 self.__buffer_cspc = None
769 else:
802 else:
770 self.__buffer_cspc += data_cspc
803 self.__buffer_cspc += data_cspc
771
804
772 if data_dc is None:
805 if data_dc is None:
773 self.__buffer_dc = None
806 self.__buffer_dc = None
774 else:
807 else:
775 self.__buffer_dc += data_dc
808 self.__buffer_dc += data_dc
776
809
777 self.__profIndex += 1
810 self.__profIndex += 1
778
811
779 return
812 return
780
813
781 def pushData(self):
814 def pushData(self):
782 """
815 """
783 Return the sum of the last profiles and the profiles used in the sum.
816 Return the sum of the last profiles and the profiles used in the sum.
784
817
785 Affected:
818 Affected:
786
819
787 self.__profileIndex
820 self.__profileIndex
788
821
789 """
822 """
790
823
791 data_spc = self.__buffer_spc
824 data_spc = self.__buffer_spc
792 data_cspc = self.__buffer_cspc
825 data_cspc = self.__buffer_cspc
793 data_dc = self.__buffer_dc
826 data_dc = self.__buffer_dc
794 n = self.__profIndex
827 n = self.__profIndex
795
828
796 self.__buffer_spc = 0
829 self.__buffer_spc = 0
797 self.__buffer_cspc = 0
830 self.__buffer_cspc = 0
798 self.__buffer_dc = 0
831 self.__buffer_dc = 0
799 self.__profIndex = 0
832 self.__profIndex = 0
800
833
801 return data_spc, data_cspc, data_dc, n
834 return data_spc, data_cspc, data_dc, n
802
835
803 def byProfiles(self, *args):
836 def byProfiles(self, *args):
804
837
805 self.__dataReady = False
838 self.__dataReady = False
806 avgdata_spc = None
839 avgdata_spc = None
807 avgdata_cspc = None
840 avgdata_cspc = None
808 avgdata_dc = None
841 avgdata_dc = None
809
842
810 self.putData(*args)
843 self.putData(*args)
811
844
812 if self.__profIndex == self.n:
845 if self.__profIndex == self.n:
813
846
814 avgdata_spc, avgdata_cspc, avgdata_dc, n = self.pushData()
847 avgdata_spc, avgdata_cspc, avgdata_dc, n = self.pushData()
815 self.n = n
848 self.n = n
816 self.__dataReady = True
849 self.__dataReady = True
817
850
818 return avgdata_spc, avgdata_cspc, avgdata_dc
851 return avgdata_spc, avgdata_cspc, avgdata_dc
819
852
820 def byTime(self, datatime, *args):
853 def byTime(self, datatime, *args):
821
854
822 self.__dataReady = False
855 self.__dataReady = False
823 avgdata_spc = None
856 avgdata_spc = None
824 avgdata_cspc = None
857 avgdata_cspc = None
825 avgdata_dc = None
858 avgdata_dc = None
826
859
827 self.putData(*args)
860 self.putData(*args)
828
861
829 if (datatime - self.__initime) >= self.__integrationtime:
862 if (datatime - self.__initime) >= self.__integrationtime:
830 avgdata_spc, avgdata_cspc, avgdata_dc, n = self.pushData()
863 avgdata_spc, avgdata_cspc, avgdata_dc, n = self.pushData()
831 self.n = n
864 self.n = n
832 self.__dataReady = True
865 self.__dataReady = True
833
866
834 return avgdata_spc, avgdata_cspc, avgdata_dc
867 return avgdata_spc, avgdata_cspc, avgdata_dc
835
868
836 def integrate(self, datatime, *args):
869 def integrate(self, datatime, *args):
837
870
838 if self.__profIndex == 0:
871 if self.__profIndex == 0:
839 self.__initime = datatime
872 self.__initime = datatime
840
873
841 if self.__byTime:
874 if self.__byTime:
842 avgdata_spc, avgdata_cspc, avgdata_dc = self.byTime(
875 avgdata_spc, avgdata_cspc, avgdata_dc = self.byTime(
843 datatime, *args)
876 datatime, *args)
844 else:
877 else:
845 avgdata_spc, avgdata_cspc, avgdata_dc = self.byProfiles(*args)
878 avgdata_spc, avgdata_cspc, avgdata_dc = self.byProfiles(*args)
846
879
847 if not self.__dataReady:
880 if not self.__dataReady:
848 return None, None, None, None
881 return None, None, None, None
849
882
850 return self.__initime, avgdata_spc, avgdata_cspc, avgdata_dc
883 return self.__initime, avgdata_spc, avgdata_cspc, avgdata_dc
851
884
852 def run(self, dataOut, n=None, timeInterval=None, overlapping=False):
885 def run(self, dataOut, n=None, timeInterval=None, overlapping=False):
853 if n == 1:
886 if n == 1:
854 return dataOut
887 return dataOut
855
888
856 dataOut.flagNoData = True
889 dataOut.flagNoData = True
857
890
858 if not self.isConfig:
891 if not self.isConfig:
859 self.setup(n, timeInterval, overlapping)
892 self.setup(n, timeInterval, overlapping)
860 self.isConfig = True
893 self.isConfig = True
861
894
862 avgdatatime, avgdata_spc, avgdata_cspc, avgdata_dc = self.integrate(dataOut.utctime,
895 avgdatatime, avgdata_spc, avgdata_cspc, avgdata_dc = self.integrate(dataOut.utctime,
863 dataOut.data_spc,
896 dataOut.data_spc,
864 dataOut.data_cspc,
897 dataOut.data_cspc,
865 dataOut.data_dc)
898 dataOut.data_dc)
866
899
867 if self.__dataReady:
900 if self.__dataReady:
868
901
869 dataOut.data_spc = avgdata_spc
902 dataOut.data_spc = avgdata_spc
870 dataOut.data_cspc = avgdata_cspc
903 dataOut.data_cspc = avgdata_cspc
871 dataOut.data_dc = avgdata_dc
904 dataOut.data_dc = avgdata_dc
872 dataOut.nIncohInt *= self.n
905 dataOut.nIncohInt *= self.n
873 dataOut.utctime = avgdatatime
906 dataOut.utctime = avgdatatime
874 dataOut.flagNoData = False
907 dataOut.flagNoData = False
875
908
876 return dataOut
909 return dataOut
877
910
878 class dopplerFlip(Operation):
911 class dopplerFlip(Operation):
879
912
880 def run(self, dataOut):
913 def run(self, dataOut):
881 # arreglo 1: (num_chan, num_profiles, num_heights)
914 # arreglo 1: (num_chan, num_profiles, num_heights)
882 self.dataOut = dataOut
915 self.dataOut = dataOut
883 # JULIA-oblicua, indice 2
916 # JULIA-oblicua, indice 2
884 # arreglo 2: (num_profiles, num_heights)
917 # arreglo 2: (num_profiles, num_heights)
885 jspectra = self.dataOut.data_spc[2]
918 jspectra = self.dataOut.data_spc[2]
886 jspectra_tmp = numpy.zeros(jspectra.shape)
919 jspectra_tmp = numpy.zeros(jspectra.shape)
887 num_profiles = jspectra.shape[0]
920 num_profiles = jspectra.shape[0]
888 freq_dc = int(num_profiles / 2)
921 freq_dc = int(num_profiles / 2)
889 # Flip con for
922 # Flip con for
890 for j in range(num_profiles):
923 for j in range(num_profiles):
891 jspectra_tmp[num_profiles-j-1]= jspectra[j]
924 jspectra_tmp[num_profiles-j-1]= jspectra[j]
892 # Intercambio perfil de DC con perfil inmediato anterior
925 # Intercambio perfil de DC con perfil inmediato anterior
893 jspectra_tmp[freq_dc-1]= jspectra[freq_dc-1]
926 jspectra_tmp[freq_dc-1]= jspectra[freq_dc-1]
894 jspectra_tmp[freq_dc]= jspectra[freq_dc]
927 jspectra_tmp[freq_dc]= jspectra[freq_dc]
895 # canal modificado es re-escrito en el arreglo de canales
928 # canal modificado es re-escrito en el arreglo de canales
896 self.dataOut.data_spc[2] = jspectra_tmp
929 self.dataOut.data_spc[2] = jspectra_tmp
897
930
898 return self.dataOut No newline at end of file
931 return self.dataOut
General Comments 0
You need to be logged in to leave comments. Login now