##// END OF EJS Templates
prueba de con ancho espectral y adicion de snr
avaldez -
r1307:7a6e3ce2f2d5
parent child
Show More
@@ -1,526 +1,512
1 import numpy,math,random,time
1 import numpy,math,random,time
2 #---------------1 Heredamos JRODatareader
2 #---------------1 Heredamos JRODatareader
3 from schainpy.model.io.jroIO_base import *
3 from schainpy.model.io.jroIO_base import *
4 #---------------2 Heredamos las propiedades de ProcessingUnit
4 #---------------2 Heredamos las propiedades de ProcessingUnit
5 from schainpy.model.proc.jroproc_base import ProcessingUnit,Operation,MPDecorator
5 from schainpy.model.proc.jroproc_base import ProcessingUnit,Operation,MPDecorator
6 #---------------3 Importaremos las clases BascicHeader, SystemHeader, RadarControlHeader, ProcessingHeader
6 #---------------3 Importaremos las clases BascicHeader, SystemHeader, RadarControlHeader, ProcessingHeader
7 from schainpy.model.data.jroheaderIO import PROCFLAG, BasicHeader,SystemHeader,RadarControllerHeader, ProcessingHeader
7 from schainpy.model.data.jroheaderIO import PROCFLAG, BasicHeader,SystemHeader,RadarControllerHeader, ProcessingHeader
8 #---------------4 Importaremos el objeto Voltge
8 #---------------4 Importaremos el objeto Voltge
9 from schainpy.model.data.jrodata import Voltage
9 from schainpy.model.data.jrodata import Voltage
10
10
11 class SimulatorReader(JRODataReader, ProcessingUnit):
11 class SimulatorReader(JRODataReader, ProcessingUnit):
12 incIntFactor = 1
12 incIntFactor = 1
13 nFFTPoints = 0
13 nFFTPoints = 0
14 FixPP_IncInt = 1
14 FixPP_IncInt = 1
15 FixRCP_IPP = 1000
15 FixRCP_IPP = 1000
16 FixPP_CohInt = 1
16 FixPP_CohInt = 1
17 Tau_0 = 250
17 Tau_0 = 250
18 AcqH0_0 = 70
18 AcqH0_0 = 70
19 H0 = AcqH0_0
19 H0 = AcqH0_0
20 AcqDH_0 = 1.25
20 AcqDH_0 = 1.25
21 DH0 = AcqDH_0
21 DH0 = AcqDH_0
22 Bauds = 32
22 Bauds = 32
23 BaudWidth = None
23 BaudWidth = None
24 FixRCP_TXA = 40
24 FixRCP_TXA = 40
25 FixRCP_TXB = 70
25 FixRCP_TXB = 70
26 fAngle = 2.0*math.pi*(1/16)
26 fAngle = 2.0*math.pi*(1/16)
27 DC_level = 500
27 DC_level = 500
28 stdev = 8
28 stdev = 8
29 Num_Codes = 2
29 Num_Codes = 2
30 #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])
30 #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])
31 #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])
31 #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])
32 #Dyn_snCode = numpy.array([Num_Codes,Bauds])
32 #Dyn_snCode = numpy.array([Num_Codes,Bauds])
33 Dyn_snCode = None
33 Dyn_snCode = None
34 Samples = 200
34 Samples = 200
35 channels = 2
35 channels = 2
36 pulses = None
36 pulses = None
37 Reference = None
37 Reference = None
38 pulse_size = None
38 pulse_size = None
39 prof_gen = None
39 prof_gen = None
40 Fdoppler = 100
40 Fdoppler = 100
41 Hdoppler = 36
41 Hdoppler = 36
42 Adoppler = 300
42 Adoppler = 300
43 frequency = 9345
43 frequency = 9345
44 nTotalReadFiles = 1000
44 nTotalReadFiles = 1000
45
45
46 def __init__(self):
46 def __init__(self):
47 """
47 """
48 Inicializador de la clases SimulatorReader para
48 Inicializador de la clases SimulatorReader para
49 generar datos de voltage simulados.
49 generar datos de voltage simulados.
50 Input:
50 Input:
51 dataOut: Objeto de la clase Voltage.
51 dataOut: Objeto de la clase Voltage.
52 Este Objeto sera utilizado apra almacenar
52 Este Objeto sera utilizado apra almacenar
53 un perfil de datos cada vez qe se haga
53 un perfil de datos cada vez qe se haga
54 un requerimiento (getData)
54 un requerimiento (getData)
55 """
55 """
56 ProcessingUnit.__init__(self)
56 ProcessingUnit.__init__(self)
57 print(" [ START ] init - Metodo Simulator Reader")
57 print(" [ START ] init - Metodo Simulator Reader")
58
58
59 self.isConfig = False
59 self.isConfig = False
60 self.basicHeaderObj = BasicHeader(LOCALTIME)
60 self.basicHeaderObj = BasicHeader(LOCALTIME)
61 self.systemHeaderObj = SystemHeader()
61 self.systemHeaderObj = SystemHeader()
62 self.radarControllerHeaderObj = RadarControllerHeader()
62 self.radarControllerHeaderObj = RadarControllerHeader()
63 self.processingHeaderObj = ProcessingHeader()
63 self.processingHeaderObj = ProcessingHeader()
64 self.profileIndex = 2**32-1
64 self.profileIndex = 2**32-1
65 self.dataOut = Voltage()
65 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])
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])
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])
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])
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])
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])
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])
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])
70 #self.Dyn_snCode = numpy.array([code0,code1])
70 #self.Dyn_snCode = numpy.array([code0,code1])
71 self.Dyn_snCode = None
71 self.Dyn_snCode = None
72
72
73 def set_kwargs(self, **kwargs):
73 def set_kwargs(self, **kwargs):
74 for key, value in kwargs.items():
74 for key, value in kwargs.items():
75 setattr(self, key, value)
75 setattr(self, key, value)
76
76
77 def __hasNotDataInBuffer(self):
77 def __hasNotDataInBuffer(self):
78
78
79 if self.profileIndex >= self.processingHeaderObj.profilesPerBlock* self.nTxs:
79 if self.profileIndex >= self.processingHeaderObj.profilesPerBlock* self.nTxs:
80 if self.nReadBlocks>0:
80 if self.nReadBlocks>0:
81 tmp = self.dataOut.utctime
81 tmp = self.dataOut.utctime
82 tmp_utc = int(self.dataOut.utctime)
82 tmp_utc = int(self.dataOut.utctime)
83 tmp_milisecond = int((tmp-tmp_utc)*1000)
83 tmp_milisecond = int((tmp-tmp_utc)*1000)
84 self.basicHeaderObj.utc = tmp_utc
84 self.basicHeaderObj.utc = tmp_utc
85 self.basicHeaderObj.miliSecond= tmp_milisecond
85 self.basicHeaderObj.miliSecond= tmp_milisecond
86 return 1
86 return 1
87 return 0
87 return 0
88
88
89 def setNextFile(self):
89 def setNextFile(self):
90 """Set the next file to be readed open it and parse de file header"""
90 """Set the next file to be readed open it and parse de file header"""
91
91
92 if (self.nReadBlocks >= self.processingHeaderObj.dataBlocksPerFile):
92 if (self.nReadBlocks >= self.processingHeaderObj.dataBlocksPerFile):
93 self.nReadFiles=self.nReadFiles+1
93 self.nReadFiles=self.nReadFiles+1
94 if self.nReadFiles > self.nTotalReadFiles:
94 if self.nReadFiles > self.nTotalReadFiles:
95 self.flagNoMoreFiles=1
95 self.flagNoMoreFiles=1
96 raise schainpy.admin.SchainWarning('No more files to read')
96 raise schainpy.admin.SchainWarning('No more files to read')
97
97
98 print('------------------- [Opening file] ------------------------------',self.nReadFiles)
98 print('------------------- [Opening file] ------------------------------',self.nReadFiles)
99 self.nReadBlocks = 0
99 self.nReadBlocks = 0
100 #if self.nReadBlocks==0:
100 #if self.nReadBlocks==0:
101 # self.readFirstHeader()
101 # self.readFirstHeader()
102
102
103 def __setNewBlock(self):
103 def __setNewBlock(self):
104 self.setNextFile()
104 self.setNextFile()
105 if self.flagIsNewFile:
105 if self.flagIsNewFile:
106 return 1
106 return 1
107
107
108 def readNextBlock(self):
108 def readNextBlock(self):
109 while True:
109 while True:
110 self.__setNewBlock()
110 self.__setNewBlock()
111 if not(self.readBlock()):
111 if not(self.readBlock()):
112 return 0
112 return 0
113 self.getBasicHeader()
113 self.getBasicHeader()
114 break
114 break
115 if self.verbose:
115 if self.verbose:
116 print("[Reading] Block No. %d/%d -> %s" %(self.nReadBlocks,
116 print("[Reading] Block No. %d/%d -> %s" %(self.nReadBlocks,
117 self.processingHeaderObj.dataBlocksPerFile,
117 self.processingHeaderObj.dataBlocksPerFile,
118 self.dataOut.datatime.ctime()) )
118 self.dataOut.datatime.ctime()) )
119 return 1
119 return 1
120
120
121 def getFirstHeader(self):
121 def getFirstHeader(self):
122 self.getBasicHeader()
122 self.getBasicHeader()
123 self.dataOut.processingHeaderObj = self.processingHeaderObj.copy()
123 self.dataOut.processingHeaderObj = self.processingHeaderObj.copy()
124 self.dataOut.systemHeaderObj = self.systemHeaderObj.copy()
124 self.dataOut.systemHeaderObj = self.systemHeaderObj.copy()
125 self.dataOut.radarControllerHeaderObj = self.radarControllerHeaderObj.copy()
125 self.dataOut.radarControllerHeaderObj = self.radarControllerHeaderObj.copy()
126 self.dataOut.dtype = self.dtype
126 self.dataOut.dtype = self.dtype
127
127
128 self.dataOut.nProfiles = self.processingHeaderObj.profilesPerBlock
128 self.dataOut.nProfiles = self.processingHeaderObj.profilesPerBlock
129 self.dataOut.heightList = numpy.arange(self.processingHeaderObj.nHeights) * self.processingHeaderObj.deltaHeight + self.processingHeaderObj.firstHeight
129 self.dataOut.heightList = numpy.arange(self.processingHeaderObj.nHeights) * self.processingHeaderObj.deltaHeight + self.processingHeaderObj.firstHeight
130 self.dataOut.channelList = list(range(self.systemHeaderObj.nChannels))
130 self.dataOut.channelList = list(range(self.systemHeaderObj.nChannels))
131 self.dataOut.nCohInt = self.processingHeaderObj.nCohInt
131 self.dataOut.nCohInt = self.processingHeaderObj.nCohInt
132 # asumo q la data no esta decodificada
132 # asumo q la data no esta decodificada
133 self.dataOut.flagDecodeData = self.processingHeaderObj.flag_decode
133 self.dataOut.flagDecodeData = self.processingHeaderObj.flag_decode
134 # asumo q la data no esta sin flip
134 # asumo q la data no esta sin flip
135 self.dataOut.flagDeflipData = self.processingHeaderObj.flag_deflip
135 self.dataOut.flagDeflipData = self.processingHeaderObj.flag_deflip
136 self.dataOut.flagShiftFFT = self.processingHeaderObj.shif_fft
136 self.dataOut.flagShiftFFT = self.processingHeaderObj.shif_fft
137 self.dataOut.frequency = self.frequency
137 self.dataOut.frequency = self.frequency
138
138
139 def getBasicHeader(self):
139 def getBasicHeader(self):
140 self.dataOut.utctime = self.basicHeaderObj.utc + self.basicHeaderObj.miliSecond / \
140 self.dataOut.utctime = self.basicHeaderObj.utc + self.basicHeaderObj.miliSecond / \
141 1000. + self.profileIndex * self.radarControllerHeaderObj.ippSeconds
141 1000. + self.profileIndex * self.radarControllerHeaderObj.ippSeconds
142
142
143 self.dataOut.flagDiscontinuousBlock = self.flagDiscontinuousBlock
143 self.dataOut.flagDiscontinuousBlock = self.flagDiscontinuousBlock
144 self.dataOut.timeZone = self.basicHeaderObj.timeZone
144 self.dataOut.timeZone = self.basicHeaderObj.timeZone
145 self.dataOut.dstFlag = self.basicHeaderObj.dstFlag
145 self.dataOut.dstFlag = self.basicHeaderObj.dstFlag
146 self.dataOut.errorCount = self.basicHeaderObj.errorCount
146 self.dataOut.errorCount = self.basicHeaderObj.errorCount
147 self.dataOut.useLocalTime = self.basicHeaderObj.useLocalTime
147 self.dataOut.useLocalTime = self.basicHeaderObj.useLocalTime
148 self.dataOut.ippSeconds = self.radarControllerHeaderObj.ippSeconds / self.nTxs
148 self.dataOut.ippSeconds = self.radarControllerHeaderObj.ippSeconds / self.nTxs
149
149
150 def readFirstHeader(self):
150 def readFirstHeader(self):
151
151
152 datatype = int(numpy.log2((self.processingHeaderObj.processFlags &
152 datatype = int(numpy.log2((self.processingHeaderObj.processFlags &
153 PROCFLAG.DATATYPE_MASK)) - numpy.log2(PROCFLAG.DATATYPE_CHAR))
153 PROCFLAG.DATATYPE_MASK)) - numpy.log2(PROCFLAG.DATATYPE_CHAR))
154 if datatype == 0:
154 if datatype == 0:
155 datatype_str = numpy.dtype([('real', '<i1'), ('imag', '<i1')])
155 datatype_str = numpy.dtype([('real', '<i1'), ('imag', '<i1')])
156 elif datatype == 1:
156 elif datatype == 1:
157 datatype_str = numpy.dtype([('real', '<i2'), ('imag', '<i2')])
157 datatype_str = numpy.dtype([('real', '<i2'), ('imag', '<i2')])
158 elif datatype == 2:
158 elif datatype == 2:
159 datatype_str = numpy.dtype([('real', '<i4'), ('imag', '<i4')])
159 datatype_str = numpy.dtype([('real', '<i4'), ('imag', '<i4')])
160 elif datatype == 3:
160 elif datatype == 3:
161 datatype_str = numpy.dtype([('real', '<i8'), ('imag', '<i8')])
161 datatype_str = numpy.dtype([('real', '<i8'), ('imag', '<i8')])
162 elif datatype == 4:
162 elif datatype == 4:
163 datatype_str = numpy.dtype([('real', '<f4'), ('imag', '<f4')])
163 datatype_str = numpy.dtype([('real', '<f4'), ('imag', '<f4')])
164 elif datatype == 5:
164 elif datatype == 5:
165 datatype_str = numpy.dtype([('real', '<f8'), ('imag', '<f8')])
165 datatype_str = numpy.dtype([('real', '<f8'), ('imag', '<f8')])
166 else:
166 else:
167 raise ValueError('Data type was not defined')
167 raise ValueError('Data type was not defined')
168
168
169 self.dtype = datatype_str
169 self.dtype = datatype_str
170
170
171
171
172 def set_RCH(self, expType=2, nTx=1,ipp=None, txA=0, txB=0,
172 def set_RCH(self, expType=2, nTx=1,ipp=None, txA=0, txB=0,
173 nWindows=None, nHeights=None, firstHeight=None, deltaHeight=None,
173 nWindows=None, nHeights=None, firstHeight=None, deltaHeight=None,
174 numTaus=0, line6Function=0, line5Function=0, fClock=None,
174 numTaus=0, line6Function=0, line5Function=0, fClock=None,
175 prePulseBefore=0, prePulseAfter=0,
175 prePulseBefore=0, prePulseAfter=0,
176 codeType=0, nCode=0, nBaud=0, code=None,
176 codeType=0, nCode=0, nBaud=0, code=None,
177 flip1=0, flip2=0,Taus=0):
177 flip1=0, flip2=0,Taus=0):
178 self.radarControllerHeaderObj.expType = expType
178 self.radarControllerHeaderObj.expType = expType
179 self.radarControllerHeaderObj.nTx = nTx
179 self.radarControllerHeaderObj.nTx = nTx
180 self.radarControllerHeaderObj.ipp = float(ipp)
180 self.radarControllerHeaderObj.ipp = float(ipp)
181 self.radarControllerHeaderObj.txA = float(txA)
181 self.radarControllerHeaderObj.txA = float(txA)
182 self.radarControllerHeaderObj.txB = float(txB)
182 self.radarControllerHeaderObj.txB = float(txB)
183 self.radarControllerHeaderObj.rangeIpp = b'A\n'#ipp
183 self.radarControllerHeaderObj.rangeIpp = b'A\n'#ipp
184 self.radarControllerHeaderObj.rangeTxA = b''
184 self.radarControllerHeaderObj.rangeTxA = b''
185 self.radarControllerHeaderObj.rangeTxB = b''
185 self.radarControllerHeaderObj.rangeTxB = b''
186
186
187 self.radarControllerHeaderObj.nHeights = int(nHeights)
187 self.radarControllerHeaderObj.nHeights = int(nHeights)
188 self.radarControllerHeaderObj.firstHeight = numpy.array([firstHeight])
188 self.radarControllerHeaderObj.firstHeight = numpy.array([firstHeight])
189 self.radarControllerHeaderObj.deltaHeight = numpy.array([deltaHeight])
189 self.radarControllerHeaderObj.deltaHeight = numpy.array([deltaHeight])
190 self.radarControllerHeaderObj.samplesWin = numpy.array([nHeights])
190 self.radarControllerHeaderObj.samplesWin = numpy.array([nHeights])
191
191
192
192
193 self.radarControllerHeaderObj.nWindows = nWindows
193 self.radarControllerHeaderObj.nWindows = nWindows
194 self.radarControllerHeaderObj.numTaus = numTaus
194 self.radarControllerHeaderObj.numTaus = numTaus
195 self.radarControllerHeaderObj.codeType = codeType
195 self.radarControllerHeaderObj.codeType = codeType
196 self.radarControllerHeaderObj.line6Function = line6Function
196 self.radarControllerHeaderObj.line6Function = line6Function
197 self.radarControllerHeaderObj.line5Function = line5Function
197 self.radarControllerHeaderObj.line5Function = line5Function
198 #self.radarControllerHeaderObj.fClock = fClock
198 #self.radarControllerHeaderObj.fClock = fClock
199 self.radarControllerHeaderObj.prePulseBefore= prePulseBefore
199 self.radarControllerHeaderObj.prePulseBefore= prePulseBefore
200 self.radarControllerHeaderObj.prePulseAfter = prePulseAfter
200 self.radarControllerHeaderObj.prePulseAfter = prePulseAfter
201
201
202 self.radarControllerHeaderObj.flip1 = flip1
202 self.radarControllerHeaderObj.flip1 = flip1
203 self.radarControllerHeaderObj.flip2 = flip2
203 self.radarControllerHeaderObj.flip2 = flip2
204
204
205 self.radarControllerHeaderObj.code_size = 0
205 self.radarControllerHeaderObj.code_size = 0
206 if self.radarControllerHeaderObj.codeType != 0:
206 if self.radarControllerHeaderObj.codeType != 0:
207 self.radarControllerHeaderObj.nCode = nCode
207 self.radarControllerHeaderObj.nCode = nCode
208 self.radarControllerHeaderObj.nBaud = nBaud
208 self.radarControllerHeaderObj.nBaud = nBaud
209 self.radarControllerHeaderObj.code = code
209 self.radarControllerHeaderObj.code = code
210 self.radarControllerHeaderObj.code_size = int(numpy.ceil(nBaud / 32.)) * nCode * 4
210 self.radarControllerHeaderObj.code_size = int(numpy.ceil(nBaud / 32.)) * nCode * 4
211
211
212 if fClock is None and deltaHeight is not None:
212 if fClock is None and deltaHeight is not None:
213 self.fClock = 0.15 / (deltaHeight * 1e-6)
213 self.fClock = 0.15 / (deltaHeight * 1e-6)
214 self.radarControllerHeaderObj.fClock = self.fClock
214 self.radarControllerHeaderObj.fClock = self.fClock
215 if numTaus==0:
215 if numTaus==0:
216 self.radarControllerHeaderObj.Taus = numpy.array(0,'<f4')
216 self.radarControllerHeaderObj.Taus = numpy.array(0,'<f4')
217 else:
217 else:
218 self.radarControllerHeaderObj.Taus = numpy.array(Taus,'<f4')
218 self.radarControllerHeaderObj.Taus = numpy.array(Taus,'<f4')
219
219
220 def set_PH(self, dtype=0, blockSize=0, profilesPerBlock=0,
220 def set_PH(self, dtype=0, blockSize=0, profilesPerBlock=0,
221 dataBlocksPerFile=0, nWindows=0, processFlags=0, nCohInt=0,
221 dataBlocksPerFile=0, nWindows=0, processFlags=0, nCohInt=0,
222 nIncohInt=0, totalSpectra=0, nHeights=0, firstHeight=0,
222 nIncohInt=0, totalSpectra=0, nHeights=0, firstHeight=0,
223 deltaHeight=0, samplesWin=0, spectraComb=0, nCode=0,
223 deltaHeight=0, samplesWin=0, spectraComb=0, nCode=0,
224 code=0, nBaud=None, shif_fft=False, flag_dc=False,
224 code=0, nBaud=None, shif_fft=False, flag_dc=False,
225 flag_cspc=False, flag_decode=False, flag_deflip=False):
225 flag_cspc=False, flag_decode=False, flag_deflip=False):
226
226
227 self.processingHeaderObj.dtype = dtype
227 self.processingHeaderObj.dtype = dtype
228 self.processingHeaderObj.profilesPerBlock = profilesPerBlock
228 self.processingHeaderObj.profilesPerBlock = profilesPerBlock
229 self.processingHeaderObj.dataBlocksPerFile = dataBlocksPerFile
229 self.processingHeaderObj.dataBlocksPerFile = dataBlocksPerFile
230 self.processingHeaderObj.nWindows = nWindows
230 self.processingHeaderObj.nWindows = nWindows
231 self.processingHeaderObj.processFlags = processFlags
231 self.processingHeaderObj.processFlags = processFlags
232 self.processingHeaderObj.nCohInt = nCohInt
232 self.processingHeaderObj.nCohInt = nCohInt
233 self.processingHeaderObj.nIncohInt = nIncohInt
233 self.processingHeaderObj.nIncohInt = nIncohInt
234 self.processingHeaderObj.totalSpectra = totalSpectra
234 self.processingHeaderObj.totalSpectra = totalSpectra
235
235
236 self.processingHeaderObj.nHeights = int(nHeights)
236 self.processingHeaderObj.nHeights = int(nHeights)
237 self.processingHeaderObj.firstHeight = firstHeight#numpy.array([firstHeight])#firstHeight
237 self.processingHeaderObj.firstHeight = firstHeight#numpy.array([firstHeight])#firstHeight
238 self.processingHeaderObj.deltaHeight = deltaHeight#numpy.array([deltaHeight])#deltaHeight
238 self.processingHeaderObj.deltaHeight = deltaHeight#numpy.array([deltaHeight])#deltaHeight
239 self.processingHeaderObj.samplesWin = nHeights#numpy.array([nHeights])#nHeights
239 self.processingHeaderObj.samplesWin = nHeights#numpy.array([nHeights])#nHeights
240
240
241 def set_BH(self, utc = 0, miliSecond = 0, timeZone = 0):
241 def set_BH(self, utc = 0, miliSecond = 0, timeZone = 0):
242 self.basicHeaderObj.utc = utc
242 self.basicHeaderObj.utc = utc
243 self.basicHeaderObj.miliSecond = miliSecond
243 self.basicHeaderObj.miliSecond = miliSecond
244 self.basicHeaderObj.timeZone = timeZone
244 self.basicHeaderObj.timeZone = timeZone
245
245
246 def set_SH(self, nSamples=0, nProfiles=0, nChannels=0, adcResolution=14, pciDioBusWidth=32):
246 def set_SH(self, nSamples=0, nProfiles=0, nChannels=0, adcResolution=14, pciDioBusWidth=32):
247 #self.systemHeaderObj.size = size
247 #self.systemHeaderObj.size = size
248 self.systemHeaderObj.nSamples = nSamples
248 self.systemHeaderObj.nSamples = nSamples
249 self.systemHeaderObj.nProfiles = nProfiles
249 self.systemHeaderObj.nProfiles = nProfiles
250 self.systemHeaderObj.nChannels = nChannels
250 self.systemHeaderObj.nChannels = nChannels
251 self.systemHeaderObj.adcResolution = adcResolution
251 self.systemHeaderObj.adcResolution = adcResolution
252 self.systemHeaderObj.pciDioBusWidth = pciDioBusWidth
252 self.systemHeaderObj.pciDioBusWidth = pciDioBusWidth
253
253
254 def init_acquisition(self):
254 def init_acquisition(self):
255
255
256 if self.nFFTPoints != 0:
256 if self.nFFTPoints != 0:
257 self.incIntFactor = m_nProfilesperBlock/self.nFFTPoints
257 self.incIntFactor = m_nProfilesperBlock/self.nFFTPoints
258 if (self.FixPP_IncInt > self.incIntFactor):
258 if (self.FixPP_IncInt > self.incIntFactor):
259 self.incIntFactor = self.FixPP_IncInt/ self.incIntFactor
259 self.incIntFactor = self.FixPP_IncInt/ self.incIntFactor
260 elif(self.FixPP_IncInt< self.incIntFactor):
260 elif(self.FixPP_IncInt< self.incIntFactor):
261 print("False alert...")
261 print("False alert...")
262
262
263 ProfilesperBlock = self.processingHeaderObj.profilesPerBlock
263 ProfilesperBlock = self.processingHeaderObj.profilesPerBlock
264
264
265 self.timeperblock =int(((self.FixRCP_IPP
265 self.timeperblock =int(((self.FixRCP_IPP
266 *ProfilesperBlock
266 *ProfilesperBlock
267 *self.FixPP_CohInt
267 *self.FixPP_CohInt
268 *self.incIntFactor)
268 *self.incIntFactor)
269 /150.0)
269 /150.0)
270 *0.9
270 *0.9
271 +0.5)
271 +0.5)
272 # para cada canal
272 # para cada canal
273 self.profiles = ProfilesperBlock*self.FixPP_CohInt
273 self.profiles = ProfilesperBlock*self.FixPP_CohInt
274 self.profiles = ProfilesperBlock
274 self.profiles = ProfilesperBlock
275 self.Reference = int((self.Tau_0-self.AcqH0_0)/(self.AcqDH_0)+0.5)
275 self.Reference = int((self.Tau_0-self.AcqH0_0)/(self.AcqDH_0)+0.5)
276 self.BaudWidth = int((self.FixRCP_TXA/self.AcqDH_0)/self.Bauds + 0.5 )
276 self.BaudWidth = int((self.FixRCP_TXA/self.AcqDH_0)/self.Bauds + 0.5 )
277
277
278 if (self.BaudWidth==0):
278 if (self.BaudWidth==0):
279 self.BaudWidth=1
279 self.BaudWidth=1
280
280
281 def init_pulse(self,Num_Codes=Num_Codes,Bauds=Bauds,BaudWidth=BaudWidth,Dyn_snCode=Dyn_snCode):
281 def init_pulse(self,Num_Codes=Num_Codes,Bauds=Bauds,BaudWidth=BaudWidth,Dyn_snCode=Dyn_snCode):
282
282
283 Num_Codes = Num_Codes
283 Num_Codes = Num_Codes
284 Bauds = Bauds
284 Bauds = Bauds
285 BaudWidth = BaudWidth
285 BaudWidth = BaudWidth
286 Dyn_snCode = Dyn_snCode
286 Dyn_snCode = Dyn_snCode
287
287
288 if Dyn_snCode:
288 if Dyn_snCode:
289 print("EXISTE")
289 print("EXISTE")
290 else:
290 else:
291 print("No existe")
291 print("No existe")
292
292
293 if Dyn_snCode: # if Bauds:
293 if Dyn_snCode: # if Bauds:
294 pulses = list(range(0,Num_Codes))
294 pulses = list(range(0,Num_Codes))
295 num_codes = Num_Codes
295 num_codes = Num_Codes
296 for i in range(num_codes):
296 for i in range(num_codes):
297 pulse_size = Bauds*BaudWidth
297 pulse_size = Bauds*BaudWidth
298 pulses[i] = numpy.zeros(pulse_size)
298 pulses[i] = numpy.zeros(pulse_size)
299 for j in range(Bauds):
299 for j in range(Bauds):
300 for k in range(BaudWidth):
300 for k in range(BaudWidth):
301 pulses[i][j*BaudWidth+k] = int(Dyn_snCode[i][j]*600)
301 pulses[i][j*BaudWidth+k] = int(Dyn_snCode[i][j]*600)
302 else:
302 else:
303 print("sin code")
303 print("sin code")
304 pulses = list(range(1))
304 pulses = list(range(1))
305 if self.AcqDH_0>0.149:
305 if self.AcqDH_0>0.149:
306 pulse_size = int(self.FixRCP_TXB/0.15+0.5)
306 pulse_size = int(self.FixRCP_TXB/0.15+0.5)
307 else:
307 else:
308 pulse_size = int((self.FixRCP_TXB/self.AcqDH_0)+0.5) #0.0375
308 pulse_size = int((self.FixRCP_TXB/self.AcqDH_0)+0.5) #0.0375
309 pulses[0] = numpy.ones(pulse_size)
309 pulses[0] = numpy.ones(pulse_size)
310 pulses = 600*pulses[0]
310 pulses = 600*pulses[0]
311
311
312 return pulses,pulse_size
312 return pulses,pulse_size
313
313
314 def jro_GenerateBlockOfData(self,Samples=Samples,DC_level= DC_level,stdev=stdev,
314 def jro_GenerateBlockOfData(self,Samples=Samples,DC_level= DC_level,stdev=stdev,
315 Reference= Reference,pulses= pulses,
315 Reference= Reference,pulses= pulses,
316 Num_Codes= Num_Codes,pulse_size=pulse_size,
316 Num_Codes= Num_Codes,pulse_size=pulse_size,
317 prof_gen= prof_gen,H0 = H0,DH0=DH0,
317 prof_gen= prof_gen,H0 = H0,DH0=DH0,
318 Adoppler=Adoppler,Fdoppler= Fdoppler,Hdoppler=Hdoppler):
318 Adoppler=Adoppler,Fdoppler= Fdoppler,Hdoppler=Hdoppler):
319 Samples = Samples
319 Samples = Samples
320 DC_level = DC_level
320 DC_level = DC_level
321 stdev = stdev
321 stdev = stdev
322 m_nR = Reference
322 m_nR = Reference
323 pulses = pulses
323 pulses = pulses
324 num_codes = Num_Codes
324 num_codes = Num_Codes
325 ps = pulse_size
325 ps = pulse_size
326 prof_gen = prof_gen
326 prof_gen = prof_gen
327 channels = self.channels
327 channels = self.channels
328 H0 = H0
328 H0 = H0
329 DH0 = DH0
329 DH0 = DH0
330 ippSec = self.radarControllerHeaderObj.ippSeconds
330 ippSec = self.radarControllerHeaderObj.ippSeconds
331 Fdoppler = self.Fdoppler
331 Fdoppler = self.Fdoppler
332 Hdoppler = self.Hdoppler
332 Hdoppler = self.Hdoppler
333 Adoppler = self.Adoppler
333 Adoppler = self.Adoppler
334
334
335 self.datablock = numpy.zeros([channels,prof_gen,Samples],dtype= numpy.complex64)
335 self.datablock = numpy.zeros([channels,prof_gen,Samples],dtype= numpy.complex64)
336 for i in range(channels):
336 for i in range(channels):
337 for k in range(prof_gen):
337 for k in range(prof_gen):
338 #Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·NOISEΒ·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·
338 #Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·NOISEΒ·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·
339 Noise_r = numpy.random.normal(DC_level,stdev,Samples)
339 Noise_r = numpy.random.normal(DC_level,stdev,Samples)
340 Noise_i = numpy.random.normal(DC_level,stdev,Samples)
340 Noise_i = numpy.random.normal(DC_level,stdev,Samples)
341 Noise = numpy.zeros(Samples,dtype=complex)
341 Noise = numpy.zeros(Samples,dtype=complex)
342 Noise.real = Noise_r
342 Noise.real = Noise_r
343 Noise.imag = Noise_i
343 Noise.imag = Noise_i
344 #Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·PULSOSΒ·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·
344 #Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·PULSOSΒ·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·
345 Pulso = numpy.zeros(pulse_size,dtype=complex)
345 Pulso = numpy.zeros(pulse_size,dtype=complex)
346 Pulso.real = pulses[k%num_codes]
346 Pulso.real = pulses[k%num_codes]
347 Pulso.imag = pulses[k%num_codes]
347 Pulso.imag = pulses[k%num_codes]
348 #Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β· PULSES+NOISEΒ·Β·Β·Β·Β·Β·Β·Β·Β·Β·
348 #Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β· PULSES+NOISEΒ·Β·Β·Β·Β·Β·Β·Β·Β·Β·
349 InBuffer = numpy.zeros(Samples,dtype=complex)
349 InBuffer = numpy.zeros(Samples,dtype=complex)
350 InBuffer[m_nR:m_nR+ps] = Pulso
350 InBuffer[m_nR:m_nR+ps] = Pulso
351 InBuffer = InBuffer+Noise
351 InBuffer = InBuffer+Noise
352 #Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β· ANGLE Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·
352 #Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β· ANGLE Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·
353 InBuffer.real[m_nR:m_nR+ps] = InBuffer.real[m_nR:m_nR+ps]*(math.cos( self.fAngle)*5)
353 InBuffer.real[m_nR:m_nR+ps] = InBuffer.real[m_nR:m_nR+ps]*(math.cos( self.fAngle)*5)
354 InBuffer.imag[m_nR:m_nR+ps] = InBuffer.imag[m_nR:m_nR+ps]*(math.sin( self.fAngle)*5)
354 InBuffer.imag[m_nR:m_nR+ps] = InBuffer.imag[m_nR:m_nR+ps]*(math.sin( self.fAngle)*5)
355 InBuffer=InBuffer
355 InBuffer=InBuffer
356 self.datablock[i][k]= InBuffer
356 self.datablock[i][k]= InBuffer
357 #plot_cts(InBuffer,H0=H0,DH0=DH0)
357
358 #wave_fft(x=InBuffer,plot_show=True)
359 #time.sleep(1)
360 #Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·DOPPLER SIGNAL...............................................
358 #Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·DOPPLER SIGNAL...............................................
361 time_vec = numpy.linspace(0,(prof_gen-1)*ippSec,int(prof_gen))+self.nReadBlocks*ippSec*prof_gen+(self.nReadFiles-1)*ippSec*prof_gen
359 time_vec = numpy.linspace(0,(prof_gen-1)*ippSec,int(prof_gen))+self.nReadBlocks*ippSec*prof_gen+(self.nReadFiles-1)*ippSec*prof_gen
362 fd = Fdoppler #+(600.0/120)*self.nReadBlocks
360 fd = Fdoppler #+(600.0/120)*self.nReadBlocks
363 d_signal = Adoppler*numpy.array(numpy.exp(1.0j*2.0*math.pi*fd*time_vec),dtype=numpy.complex64)
361 d_signal = Adoppler*numpy.array(numpy.exp(1.0j*2.0*math.pi*fd*time_vec),dtype=numpy.complex64)
364 #Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·SeΓ±al con ancho espectralΒ·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·
362 #Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·SeΓ±al con ancho espectralΒ·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·
365 #specw_sig = numpy.zeros(int(prof_gen),dtype=complex)
363 #specw_sig = numpy.linspace(-149,150,300)
366 #specw_sig.real[200:200+100] = 1*numpy.ones(100)
364 #w = 8
367 #specw_sig.imag[200:200+100] = 1*numpy.ones(100)
365 #A = 20
368 # w=2
366 #specw_sig = specw_sig/w
369 specw_sig = numpy.linspace(-149,150,300)
367 #specw_sig = numpy.sinc(specw_sig)
370 w = 3
368 #specw_sig = A*numpy.array(specw_sig,dtype=numpy.complex64)
371 A = 10
372 specw_sig = specw_sig/w
373 specw_sig = numpy.sinc(specw_sig)
374 specw_sig = A*numpy.array(specw_sig,dtype=numpy.complex64)
375 #Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β· DATABLOCK + DOPPLERΒ·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·
369 #Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β· DATABLOCK + DOPPLERΒ·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·
376 HD=int(Hdoppler/self.AcqDH_0)
370 HD=int(Hdoppler/self.AcqDH_0)
377 for i in range(12):
371 for i in range(12):
378 self.datablock[0,:,HD+i]=self.datablock[0,:,HD+i]+ d_signal# RESULT
372 self.datablock[0,:,HD+i]=self.datablock[0,:,HD+i]+ d_signal# RESULT
379
373 #Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β· DATABLOCK + DOPPLER*Sinc(x)Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·
380 HD=int(Hdoppler/self.AcqDH_0)
374 #HD=int(Hdoppler/self.AcqDH_0)
381 HD=int(HD/2)
375 #HD=int(HD/2)
382 for i in range(12):
376 #for i in range(12):
383 self.datablock[0,:,HD+i]=self.datablock[0,:,HD+i]+ specw_sig*d_signal# RESULT
377 # self.datablock[0,:,HD+i]=self.datablock[0,:,HD+i]+ specw_sig*d_signal# RESULT
384
385 '''
386 a= numpy.zeros(10)
387 for i in range(10):
388 a[i]=i+self.nReadBlocks+20
389 for i in a:
390 self.datablock[0,:,int(i)]=self.datablock[0,:,int(i)]+ d_signal # RESULT
391 '''
392
378
393 def readBlock(self):
379 def readBlock(self):
394
380
395 self.jro_GenerateBlockOfData(Samples= self.samples,DC_level=self.DC_level,
381 self.jro_GenerateBlockOfData(Samples= self.samples,DC_level=self.DC_level,
396 stdev=self.stdev,Reference= self.Reference,
382 stdev=self.stdev,Reference= self.Reference,
397 pulses = self.pulses,Num_Codes=self.Num_Codes,
383 pulses = self.pulses,Num_Codes=self.Num_Codes,
398 pulse_size=self.pulse_size,prof_gen=self.profiles,
384 pulse_size=self.pulse_size,prof_gen=self.profiles,
399 H0=self.H0,DH0=self.DH0)
385 H0=self.H0,DH0=self.DH0)
400
386
401 self.profileIndex = 0
387 self.profileIndex = 0
402 self.flagIsNewFile = 0
388 self.flagIsNewFile = 0
403 self.flagIsNewBlock = 1
389 self.flagIsNewBlock = 1
404 self.nTotalBlocks += 1
390 self.nTotalBlocks += 1
405 self.nReadBlocks += 1
391 self.nReadBlocks += 1
406
392
407 return 1
393 return 1
408
394
409
395
410 def getData(self):
396 def getData(self):
411 if self.flagNoMoreFiles:
397 if self.flagNoMoreFiles:
412 self.dataOut.flagNodata = True
398 self.dataOut.flagNodata = True
413 return 0
399 return 0
414 self.flagDiscontinuousBlock = 0
400 self.flagDiscontinuousBlock = 0
415 self.flagIsNewBlock = 0
401 self.flagIsNewBlock = 0
416 if self.__hasNotDataInBuffer(): # aqui es verdad
402 if self.__hasNotDataInBuffer(): # aqui es verdad
417 if not(self.readNextBlock()): # return 1 y por eso el if not salta a getBasic Header
403 if not(self.readNextBlock()): # return 1 y por eso el if not salta a getBasic Header
418 return 0
404 return 0
419 self.getFirstHeader() # atributo
405 self.getFirstHeader() # atributo
420
406
421 if not self.getByBlock:
407 if not self.getByBlock:
422 self.dataOut.flagDataAsBlock = False
408 self.dataOut.flagDataAsBlock = False
423 self.dataOut.data = self.datablock[:, self.profileIndex, :]
409 self.dataOut.data = self.datablock[:, self.profileIndex, :]
424 self.dataOut.profileIndex = self.profileIndex
410 self.dataOut.profileIndex = self.profileIndex
425 self.profileIndex += 1
411 self.profileIndex += 1
426 else:
412 else:
427 pass
413 pass
428 self.dataOut.flagNoData = False
414 self.dataOut.flagNoData = False
429 self.getBasicHeader()
415 self.getBasicHeader()
430 self.dataOut.realtime = self.online
416 self.dataOut.realtime = self.online
431 return self.dataOut.data
417 return self.dataOut.data
432
418
433
419
434 def setup(self,frequency=49.92e6,incIntFactor= 1, nFFTPoints = 0, FixPP_IncInt=1,FixRCP_IPP=1000,
420 def setup(self,frequency=49.92e6,incIntFactor= 1, nFFTPoints = 0, FixPP_IncInt=1,FixRCP_IPP=1000,
435 FixPP_CohInt= 1,Tau_0= 250,AcqH0_0 = 70 ,AcqDH_0=1.25, Bauds= 32,
421 FixPP_CohInt= 1,Tau_0= 250,AcqH0_0 = 70 ,AcqDH_0=1.25, Bauds= 32,
436 FixRCP_TXA = 40, FixRCP_TXB = 50, fAngle = 2.0*math.pi*(1/16),DC_level= 50,
422 FixRCP_TXA = 40, FixRCP_TXB = 50, fAngle = 2.0*math.pi*(1/16),DC_level= 50,
437 stdev= 8,Num_Codes = 1 , Dyn_snCode = None, samples=200,
423 stdev= 8,Num_Codes = 1 , Dyn_snCode = None, samples=200,
438 channels=2,Fdoppler=20,Hdoppler=36,Adoppler=500,nTotalReadFiles=10000,
424 channels=2,Fdoppler=20,Hdoppler=36,Adoppler=500,nTotalReadFiles=10000,
439 **kwargs):
425 **kwargs):
440
426
441 self.set_kwargs(**kwargs)
427 self.set_kwargs(**kwargs)
442 self.nReadBlocks = 0
428 self.nReadBlocks = 0
443 self.nReadFiles = 1
429 self.nReadFiles = 1
444 print('------------------- [Opening file: ] ------------------------------',self.nReadFiles)
430 print('------------------- [Opening file: ] ------------------------------',self.nReadFiles)
445
431
446 tmp = time.time()
432 tmp = time.time()
447 tmp_utc = int(tmp)
433 tmp_utc = int(tmp)
448 tmp_milisecond = int((tmp-tmp_utc)*1000)
434 tmp_milisecond = int((tmp-tmp_utc)*1000)
449 print(" SETUP -basicHeaderObj.utc",datetime.datetime.utcfromtimestamp(tmp))
435 print(" SETUP -basicHeaderObj.utc",datetime.datetime.utcfromtimestamp(tmp))
450 if Dyn_snCode is None:
436 if Dyn_snCode is None:
451 Num_Codes=1
437 Num_Codes=1
452 Bauds =1
438 Bauds =1
453
439
454
440
455
441
456 self.set_BH(utc= tmp_utc,miliSecond= tmp_milisecond,timeZone=300 )
442 self.set_BH(utc= tmp_utc,miliSecond= tmp_milisecond,timeZone=300 )
457 self.set_RCH( expType=0, nTx=150,ipp=FixRCP_IPP, txA=FixRCP_TXA, txB= FixRCP_TXB,
443 self.set_RCH( expType=0, nTx=150,ipp=FixRCP_IPP, txA=FixRCP_TXA, txB= FixRCP_TXB,
458 nWindows=1 , nHeights=samples, firstHeight=AcqH0_0, deltaHeight=AcqDH_0,
444 nWindows=1 , nHeights=samples, firstHeight=AcqH0_0, deltaHeight=AcqDH_0,
459 numTaus=1, line6Function=0, line5Function=0, fClock=None,
445 numTaus=1, line6Function=0, line5Function=0, fClock=None,
460 prePulseBefore=0, prePulseAfter=0,
446 prePulseBefore=0, prePulseAfter=0,
461 codeType=0, nCode=Num_Codes, nBaud=32, code=Dyn_snCode,
447 codeType=0, nCode=Num_Codes, nBaud=32, code=Dyn_snCode,
462 flip1=0, flip2=0,Taus=Tau_0)
448 flip1=0, flip2=0,Taus=Tau_0)
463
449
464 self.set_PH(dtype=0, blockSize=0, profilesPerBlock=300,
450 self.set_PH(dtype=0, blockSize=0, profilesPerBlock=300,
465 dataBlocksPerFile=120, nWindows=1, processFlags=numpy.array([1024]), nCohInt=1,
451 dataBlocksPerFile=120, nWindows=1, processFlags=numpy.array([1024]), nCohInt=1,
466 nIncohInt=1, totalSpectra=0, nHeights=samples, firstHeight=AcqH0_0,
452 nIncohInt=1, totalSpectra=0, nHeights=samples, firstHeight=AcqH0_0,
467 deltaHeight=AcqDH_0, samplesWin=samples, spectraComb=0, nCode=0,
453 deltaHeight=AcqDH_0, samplesWin=samples, spectraComb=0, nCode=0,
468 code=0, nBaud=None, shif_fft=False, flag_dc=False,
454 code=0, nBaud=None, shif_fft=False, flag_dc=False,
469 flag_cspc=False, flag_decode=False, flag_deflip=False)
455 flag_cspc=False, flag_decode=False, flag_deflip=False)
470
456
471 self.set_SH(nSamples=samples, nProfiles=300, nChannels=channels)
457 self.set_SH(nSamples=samples, nProfiles=300, nChannels=channels)
472
458
473 self.readFirstHeader()
459 self.readFirstHeader()
474
460
475 self.frequency = frequency
461 self.frequency = frequency
476 self.incIntFactor = incIntFactor
462 self.incIntFactor = incIntFactor
477 self.nFFTPoints = nFFTPoints
463 self.nFFTPoints = nFFTPoints
478 self.FixPP_IncInt = FixPP_IncInt
464 self.FixPP_IncInt = FixPP_IncInt
479 self.FixRCP_IPP = FixRCP_IPP
465 self.FixRCP_IPP = FixRCP_IPP
480 self.FixPP_CohInt = FixPP_CohInt
466 self.FixPP_CohInt = FixPP_CohInt
481 self.Tau_0 = Tau_0
467 self.Tau_0 = Tau_0
482 self.AcqH0_0 = AcqH0_0
468 self.AcqH0_0 = AcqH0_0
483 self.H0 = AcqH0_0
469 self.H0 = AcqH0_0
484 self.AcqDH_0 = AcqDH_0
470 self.AcqDH_0 = AcqDH_0
485 self.DH0 = AcqDH_0
471 self.DH0 = AcqDH_0
486 self.Bauds = Bauds
472 self.Bauds = Bauds
487 self.FixRCP_TXA = FixRCP_TXA
473 self.FixRCP_TXA = FixRCP_TXA
488 self.FixRCP_TXB = FixRCP_TXB
474 self.FixRCP_TXB = FixRCP_TXB
489 self.fAngle = fAngle
475 self.fAngle = fAngle
490 self.DC_level = DC_level
476 self.DC_level = DC_level
491 self.stdev = stdev
477 self.stdev = stdev
492 self.Num_Codes = Num_Codes
478 self.Num_Codes = Num_Codes
493 self.Dyn_snCode = Dyn_snCode
479 self.Dyn_snCode = Dyn_snCode
494 self.samples = samples
480 self.samples = samples
495 self.channels = channels
481 self.channels = channels
496 self.profiles = None
482 self.profiles = None
497 self.m_nReference = None
483 self.m_nReference = None
498 self.Baudwidth = None
484 self.Baudwidth = None
499 self.Fdoppler = Fdoppler
485 self.Fdoppler = Fdoppler
500 self.Hdoppler = Hdoppler
486 self.Hdoppler = Hdoppler
501 self.Adoppler = Adoppler
487 self.Adoppler = Adoppler
502 self.nTotalReadFiles = int(nTotalReadFiles)
488 self.nTotalReadFiles = int(nTotalReadFiles)
503
489
504 print("IPP ", self.FixRCP_IPP)
490 print("IPP ", self.FixRCP_IPP)
505 print("Tau_0 ",self.Tau_0)
491 print("Tau_0 ",self.Tau_0)
506 print("AcqH0_0",self.AcqH0_0)
492 print("AcqH0_0",self.AcqH0_0)
507 print("samples,window ",self.samples)
493 print("samples,window ",self.samples)
508 print("AcqDH_0",AcqDH_0)
494 print("AcqDH_0",AcqDH_0)
509 print("FixRCP_TXA",self.FixRCP_TXA)
495 print("FixRCP_TXA",self.FixRCP_TXA)
510 print("FixRCP_TXB",self.FixRCP_TXB)
496 print("FixRCP_TXB",self.FixRCP_TXB)
511 print("Dyn_snCode",Dyn_snCode)
497 print("Dyn_snCode",Dyn_snCode)
512 print("Fdoppler", Fdoppler)
498 print("Fdoppler", Fdoppler)
513 print("Hdoppler",Hdoppler)
499 print("Hdoppler",Hdoppler)
514 print("Vdopplermax",Fdoppler*(3.0e8/self.frequency)/2.0)
500 print("Vdopplermax",Fdoppler*(3.0e8/self.frequency)/2.0)
515 print("nTotalReadFiles", nTotalReadFiles)
501 print("nTotalReadFiles", nTotalReadFiles)
516
502
517 self.init_acquisition()
503 self.init_acquisition()
518 self.pulses,self.pulse_size=self.init_pulse(Num_Codes=self.Num_Codes,Bauds=self.Bauds,BaudWidth=self.BaudWidth,Dyn_snCode=Dyn_snCode)
504 self.pulses,self.pulse_size=self.init_pulse(Num_Codes=self.Num_Codes,Bauds=self.Bauds,BaudWidth=self.BaudWidth,Dyn_snCode=Dyn_snCode)
519 print(" [ END ] - SETUP metodo")
505 print(" [ END ] - SETUP metodo")
520 return
506 return
521
507
522 def run(self,**kwargs): # metodo propio
508 def run(self,**kwargs): # metodo propio
523 if not(self.isConfig):
509 if not(self.isConfig):
524 self.setup(**kwargs)
510 self.setup(**kwargs)
525 self.isConfig = True
511 self.isConfig = True
526 self.getData()
512 self.getData()
@@ -1,1581 +1,1587
1 import sys
1 import sys
2 import numpy,math
2 import numpy,math
3 from scipy import interpolate
3 from scipy import interpolate
4 from schainpy.model.proc.jroproc_base import ProcessingUnit, Operation, MPDecorator
4 from schainpy.model.proc.jroproc_base import ProcessingUnit, Operation, MPDecorator
5 from schainpy.model.data.jrodata import Voltage
5 from schainpy.model.data.jrodata import Voltage
6 from schainpy.utils import log
6 from schainpy.utils import log
7 from time import time
7 from time import time
8
8
9
9
10
10
11 class VoltageProc(ProcessingUnit):
11 class VoltageProc(ProcessingUnit):
12
12
13 def __init__(self):
13 def __init__(self):
14
14
15 ProcessingUnit.__init__(self)
15 ProcessingUnit.__init__(self)
16
16
17 self.dataOut = Voltage()
17 self.dataOut = Voltage()
18 self.flip = 1
18 self.flip = 1
19 self.setupReq = False
19 self.setupReq = False
20
20
21 def run(self):
21 def run(self):
22
22
23 if self.dataIn.type == 'AMISR':
23 if self.dataIn.type == 'AMISR':
24 self.__updateObjFromAmisrInput()
24 self.__updateObjFromAmisrInput()
25
25
26 if self.dataIn.type == 'Voltage':
26 if self.dataIn.type == 'Voltage':
27 self.dataOut.copy(self.dataIn)
27 self.dataOut.copy(self.dataIn)
28
28
29 def __updateObjFromAmisrInput(self):
29 def __updateObjFromAmisrInput(self):
30
30
31 self.dataOut.timeZone = self.dataIn.timeZone
31 self.dataOut.timeZone = self.dataIn.timeZone
32 self.dataOut.dstFlag = self.dataIn.dstFlag
32 self.dataOut.dstFlag = self.dataIn.dstFlag
33 self.dataOut.errorCount = self.dataIn.errorCount
33 self.dataOut.errorCount = self.dataIn.errorCount
34 self.dataOut.useLocalTime = self.dataIn.useLocalTime
34 self.dataOut.useLocalTime = self.dataIn.useLocalTime
35
35
36 self.dataOut.flagNoData = self.dataIn.flagNoData
36 self.dataOut.flagNoData = self.dataIn.flagNoData
37 self.dataOut.data = self.dataIn.data
37 self.dataOut.data = self.dataIn.data
38 self.dataOut.utctime = self.dataIn.utctime
38 self.dataOut.utctime = self.dataIn.utctime
39 self.dataOut.channelList = self.dataIn.channelList
39 self.dataOut.channelList = self.dataIn.channelList
40 #self.dataOut.timeInterval = self.dataIn.timeInterval
40 #self.dataOut.timeInterval = self.dataIn.timeInterval
41 self.dataOut.heightList = self.dataIn.heightList
41 self.dataOut.heightList = self.dataIn.heightList
42 self.dataOut.nProfiles = self.dataIn.nProfiles
42 self.dataOut.nProfiles = self.dataIn.nProfiles
43
43
44 self.dataOut.nCohInt = self.dataIn.nCohInt
44 self.dataOut.nCohInt = self.dataIn.nCohInt
45 self.dataOut.ippSeconds = self.dataIn.ippSeconds
45 self.dataOut.ippSeconds = self.dataIn.ippSeconds
46 self.dataOut.frequency = self.dataIn.frequency
46 self.dataOut.frequency = self.dataIn.frequency
47
47
48 self.dataOut.azimuth = self.dataIn.azimuth
48 self.dataOut.azimuth = self.dataIn.azimuth
49 self.dataOut.zenith = self.dataIn.zenith
49 self.dataOut.zenith = self.dataIn.zenith
50
50
51 self.dataOut.beam.codeList = self.dataIn.beam.codeList
51 self.dataOut.beam.codeList = self.dataIn.beam.codeList
52 self.dataOut.beam.azimuthList = self.dataIn.beam.azimuthList
52 self.dataOut.beam.azimuthList = self.dataIn.beam.azimuthList
53 self.dataOut.beam.zenithList = self.dataIn.beam.zenithList
53 self.dataOut.beam.zenithList = self.dataIn.beam.zenithList
54
54
55
55
56 class selectChannels(Operation):
56 class selectChannels(Operation):
57
57
58 def run(self, dataOut, channelList):
58 def run(self, dataOut, channelList):
59
59
60 channelIndexList = []
60 channelIndexList = []
61 self.dataOut = dataOut
61 self.dataOut = dataOut
62 for channel in channelList:
62 for channel in channelList:
63 if channel not in self.dataOut.channelList:
63 if channel not in self.dataOut.channelList:
64 raise ValueError("Channel %d is not in %s" %(channel, str(self.dataOut.channelList)))
64 raise ValueError("Channel %d is not in %s" %(channel, str(self.dataOut.channelList)))
65
65
66 index = self.dataOut.channelList.index(channel)
66 index = self.dataOut.channelList.index(channel)
67 channelIndexList.append(index)
67 channelIndexList.append(index)
68 self.selectChannelsByIndex(channelIndexList)
68 self.selectChannelsByIndex(channelIndexList)
69 return self.dataOut
69 return self.dataOut
70
70
71 def selectChannelsByIndex(self, channelIndexList):
71 def selectChannelsByIndex(self, channelIndexList):
72 """
72 """
73 Selecciona un bloque de datos en base a canales segun el channelIndexList
73 Selecciona un bloque de datos en base a canales segun el channelIndexList
74
74
75 Input:
75 Input:
76 channelIndexList : lista sencilla de canales a seleccionar por ej. [2,3,7]
76 channelIndexList : lista sencilla de canales a seleccionar por ej. [2,3,7]
77
77
78 Affected:
78 Affected:
79 self.dataOut.data
79 self.dataOut.data
80 self.dataOut.channelIndexList
80 self.dataOut.channelIndexList
81 self.dataOut.nChannels
81 self.dataOut.nChannels
82 self.dataOut.m_ProcessingHeader.totalSpectra
82 self.dataOut.m_ProcessingHeader.totalSpectra
83 self.dataOut.systemHeaderObj.numChannels
83 self.dataOut.systemHeaderObj.numChannels
84 self.dataOut.m_ProcessingHeader.blockSize
84 self.dataOut.m_ProcessingHeader.blockSize
85
85
86 Return:
86 Return:
87 None
87 None
88 """
88 """
89
89
90 for channelIndex in channelIndexList:
90 for channelIndex in channelIndexList:
91 if channelIndex not in self.dataOut.channelIndexList:
91 if channelIndex not in self.dataOut.channelIndexList:
92 raise ValueError("The value %d in channelIndexList is not valid" %channelIndex)
92 raise ValueError("The value %d in channelIndexList is not valid" %channelIndex)
93
93
94 if self.dataOut.type == 'Voltage':
94 if self.dataOut.type == 'Voltage':
95 if self.dataOut.flagDataAsBlock:
95 if self.dataOut.flagDataAsBlock:
96 """
96 """
97 Si la data es obtenida por bloques, dimension = [nChannels, nProfiles, nHeis]
97 Si la data es obtenida por bloques, dimension = [nChannels, nProfiles, nHeis]
98 """
98 """
99 data = self.dataOut.data[channelIndexList,:,:]
99 data = self.dataOut.data[channelIndexList,:,:]
100 else:
100 else:
101 data = self.dataOut.data[channelIndexList,:]
101 data = self.dataOut.data[channelIndexList,:]
102
102
103 self.dataOut.data = data
103 self.dataOut.data = data
104 # self.dataOut.channelList = [self.dataOut.channelList[i] for i in channelIndexList]
104 # self.dataOut.channelList = [self.dataOut.channelList[i] for i in channelIndexList]
105 self.dataOut.channelList = range(len(channelIndexList))
105 self.dataOut.channelList = range(len(channelIndexList))
106
106
107 elif self.dataOut.type == 'Spectra':
107 elif self.dataOut.type == 'Spectra':
108 data_spc = self.dataOut.data_spc[channelIndexList, :]
108 data_spc = self.dataOut.data_spc[channelIndexList, :]
109 data_dc = self.dataOut.data_dc[channelIndexList, :]
109 data_dc = self.dataOut.data_dc[channelIndexList, :]
110
110
111 self.dataOut.data_spc = data_spc
111 self.dataOut.data_spc = data_spc
112 self.dataOut.data_dc = data_dc
112 self.dataOut.data_dc = data_dc
113
113
114 # self.dataOut.channelList = [self.dataOut.channelList[i] for i in channelIndexList]
114 # self.dataOut.channelList = [self.dataOut.channelList[i] for i in channelIndexList]
115 self.dataOut.channelList = range(len(channelIndexList))
115 self.dataOut.channelList = range(len(channelIndexList))
116 self.__selectPairsByChannel(channelIndexList)
116 self.__selectPairsByChannel(channelIndexList)
117
117
118 return 1
118 return 1
119
119
120 def __selectPairsByChannel(self, channelList=None):
120 def __selectPairsByChannel(self, channelList=None):
121
121
122 if channelList == None:
122 if channelList == None:
123 return
123 return
124
124
125 pairsIndexListSelected = []
125 pairsIndexListSelected = []
126 for pairIndex in self.dataOut.pairsIndexList:
126 for pairIndex in self.dataOut.pairsIndexList:
127 # First pair
127 # First pair
128 if self.dataOut.pairsList[pairIndex][0] not in channelList:
128 if self.dataOut.pairsList[pairIndex][0] not in channelList:
129 continue
129 continue
130 # Second pair
130 # Second pair
131 if self.dataOut.pairsList[pairIndex][1] not in channelList:
131 if self.dataOut.pairsList[pairIndex][1] not in channelList:
132 continue
132 continue
133
133
134 pairsIndexListSelected.append(pairIndex)
134 pairsIndexListSelected.append(pairIndex)
135
135
136 if not pairsIndexListSelected:
136 if not pairsIndexListSelected:
137 self.dataOut.data_cspc = None
137 self.dataOut.data_cspc = None
138 self.dataOut.pairsList = []
138 self.dataOut.pairsList = []
139 return
139 return
140
140
141 self.dataOut.data_cspc = self.dataOut.data_cspc[pairsIndexListSelected]
141 self.dataOut.data_cspc = self.dataOut.data_cspc[pairsIndexListSelected]
142 self.dataOut.pairsList = [self.dataOut.pairsList[i]
142 self.dataOut.pairsList = [self.dataOut.pairsList[i]
143 for i in pairsIndexListSelected]
143 for i in pairsIndexListSelected]
144
144
145 return
145 return
146
146
147 class selectHeights(Operation):
147 class selectHeights(Operation):
148
148
149 def run(self, dataOut, minHei=None, maxHei=None):
149 def run(self, dataOut, minHei=None, maxHei=None):
150 """
150 """
151 Selecciona un bloque de datos en base a un grupo de valores de alturas segun el rango
151 Selecciona un bloque de datos en base a un grupo de valores de alturas segun el rango
152 minHei <= height <= maxHei
152 minHei <= height <= maxHei
153
153
154 Input:
154 Input:
155 minHei : valor minimo de altura a considerar
155 minHei : valor minimo de altura a considerar
156 maxHei : valor maximo de altura a considerar
156 maxHei : valor maximo de altura a considerar
157
157
158 Affected:
158 Affected:
159 Indirectamente son cambiados varios valores a travez del metodo selectHeightsByIndex
159 Indirectamente son cambiados varios valores a travez del metodo selectHeightsByIndex
160
160
161 Return:
161 Return:
162 1 si el metodo se ejecuto con exito caso contrario devuelve 0
162 1 si el metodo se ejecuto con exito caso contrario devuelve 0
163 """
163 """
164
164
165 self.dataOut = dataOut
165 self.dataOut = dataOut
166
166
167 if minHei == None:
167 if minHei == None:
168 minHei = self.dataOut.heightList[0]
168 minHei = self.dataOut.heightList[0]
169
169
170 if maxHei == None:
170 if maxHei == None:
171 maxHei = self.dataOut.heightList[-1]
171 maxHei = self.dataOut.heightList[-1]
172
172
173 if (minHei < self.dataOut.heightList[0]):
173 if (minHei < self.dataOut.heightList[0]):
174 minHei = self.dataOut.heightList[0]
174 minHei = self.dataOut.heightList[0]
175
175
176 if (maxHei > self.dataOut.heightList[-1]):
176 if (maxHei > self.dataOut.heightList[-1]):
177 maxHei = self.dataOut.heightList[-1]
177 maxHei = self.dataOut.heightList[-1]
178
178
179 minIndex = 0
179 minIndex = 0
180 maxIndex = 0
180 maxIndex = 0
181 heights = self.dataOut.heightList
181 heights = self.dataOut.heightList
182
182
183 inda = numpy.where(heights >= minHei)
183 inda = numpy.where(heights >= minHei)
184 indb = numpy.where(heights <= maxHei)
184 indb = numpy.where(heights <= maxHei)
185
185
186 try:
186 try:
187 minIndex = inda[0][0]
187 minIndex = inda[0][0]
188 except:
188 except:
189 minIndex = 0
189 minIndex = 0
190
190
191 try:
191 try:
192 maxIndex = indb[0][-1]
192 maxIndex = indb[0][-1]
193 except:
193 except:
194 maxIndex = len(heights)
194 maxIndex = len(heights)
195
195
196 self.selectHeightsByIndex(minIndex, maxIndex)
196 self.selectHeightsByIndex(minIndex, maxIndex)
197
197
198 return self.dataOut
198 return self.dataOut
199
199
200 def selectHeightsByIndex(self, minIndex, maxIndex):
200 def selectHeightsByIndex(self, minIndex, maxIndex):
201 """
201 """
202 Selecciona un bloque de datos en base a un grupo indices de alturas segun el rango
202 Selecciona un bloque de datos en base a un grupo indices de alturas segun el rango
203 minIndex <= index <= maxIndex
203 minIndex <= index <= maxIndex
204
204
205 Input:
205 Input:
206 minIndex : valor de indice minimo de altura a considerar
206 minIndex : valor de indice minimo de altura a considerar
207 maxIndex : valor de indice maximo de altura a considerar
207 maxIndex : valor de indice maximo de altura a considerar
208
208
209 Affected:
209 Affected:
210 self.dataOut.data
210 self.dataOut.data
211 self.dataOut.heightList
211 self.dataOut.heightList
212
212
213 Return:
213 Return:
214 1 si el metodo se ejecuto con exito caso contrario devuelve 0
214 1 si el metodo se ejecuto con exito caso contrario devuelve 0
215 """
215 """
216
216
217 if self.dataOut.type == 'Voltage':
217 if self.dataOut.type == 'Voltage':
218 if (minIndex < 0) or (minIndex > maxIndex):
218 if (minIndex < 0) or (minIndex > maxIndex):
219 raise ValueError("Height index range (%d,%d) is not valid" % (minIndex, maxIndex))
219 raise ValueError("Height index range (%d,%d) is not valid" % (minIndex, maxIndex))
220
220
221 if (maxIndex >= self.dataOut.nHeights):
221 if (maxIndex >= self.dataOut.nHeights):
222 maxIndex = self.dataOut.nHeights
222 maxIndex = self.dataOut.nHeights
223
223
224 #voltage
224 #voltage
225 if self.dataOut.flagDataAsBlock:
225 if self.dataOut.flagDataAsBlock:
226 """
226 """
227 Si la data es obtenida por bloques, dimension = [nChannels, nProfiles, nHeis]
227 Si la data es obtenida por bloques, dimension = [nChannels, nProfiles, nHeis]
228 """
228 """
229 data = self.dataOut.data[:,:, minIndex:maxIndex]
229 data = self.dataOut.data[:,:, minIndex:maxIndex]
230 else:
230 else:
231 data = self.dataOut.data[:, minIndex:maxIndex]
231 data = self.dataOut.data[:, minIndex:maxIndex]
232
232
233 # firstHeight = self.dataOut.heightList[minIndex]
233 # firstHeight = self.dataOut.heightList[minIndex]
234
234
235 self.dataOut.data = data
235 self.dataOut.data = data
236 self.dataOut.heightList = self.dataOut.heightList[minIndex:maxIndex]
236 self.dataOut.heightList = self.dataOut.heightList[minIndex:maxIndex]
237
237
238 if self.dataOut.nHeights <= 1:
238 if self.dataOut.nHeights <= 1:
239 raise ValueError("selectHeights: Too few heights. Current number of heights is %d" %(self.dataOut.nHeights))
239 raise ValueError("selectHeights: Too few heights. Current number of heights is %d" %(self.dataOut.nHeights))
240 elif self.dataOut.type == 'Spectra':
240 elif self.dataOut.type == 'Spectra':
241 if (minIndex < 0) or (minIndex > maxIndex):
241 if (minIndex < 0) or (minIndex > maxIndex):
242 raise ValueError("Error selecting heights: Index range (%d,%d) is not valid" % (
242 raise ValueError("Error selecting heights: Index range (%d,%d) is not valid" % (
243 minIndex, maxIndex))
243 minIndex, maxIndex))
244
244
245 if (maxIndex >= self.dataOut.nHeights):
245 if (maxIndex >= self.dataOut.nHeights):
246 maxIndex = self.dataOut.nHeights - 1
246 maxIndex = self.dataOut.nHeights - 1
247
247
248 # Spectra
248 # Spectra
249 data_spc = self.dataOut.data_spc[:, :, minIndex:maxIndex + 1]
249 data_spc = self.dataOut.data_spc[:, :, minIndex:maxIndex + 1]
250
250
251 data_cspc = None
251 data_cspc = None
252 if self.dataOut.data_cspc is not None:
252 if self.dataOut.data_cspc is not None:
253 data_cspc = self.dataOut.data_cspc[:, :, minIndex:maxIndex + 1]
253 data_cspc = self.dataOut.data_cspc[:, :, minIndex:maxIndex + 1]
254
254
255 data_dc = None
255 data_dc = None
256 if self.dataOut.data_dc is not None:
256 if self.dataOut.data_dc is not None:
257 data_dc = self.dataOut.data_dc[:, minIndex:maxIndex + 1]
257 data_dc = self.dataOut.data_dc[:, minIndex:maxIndex + 1]
258
258
259 self.dataOut.data_spc = data_spc
259 self.dataOut.data_spc = data_spc
260 self.dataOut.data_cspc = data_cspc
260 self.dataOut.data_cspc = data_cspc
261 self.dataOut.data_dc = data_dc
261 self.dataOut.data_dc = data_dc
262
262
263 self.dataOut.heightList = self.dataOut.heightList[minIndex:maxIndex + 1]
263 self.dataOut.heightList = self.dataOut.heightList[minIndex:maxIndex + 1]
264
264
265 return 1
265 return 1
266
266
267
267
268 class filterByHeights(Operation):
268 class filterByHeights(Operation):
269
269
270 def run(self, dataOut, window):
270 def run(self, dataOut, window):
271
271
272 deltaHeight = dataOut.heightList[1] - dataOut.heightList[0]
272 deltaHeight = dataOut.heightList[1] - dataOut.heightList[0]
273
273
274 if window == None:
274 if window == None:
275 window = (dataOut.radarControllerHeaderObj.txA/dataOut.radarControllerHeaderObj.nBaud) / deltaHeight
275 window = (dataOut.radarControllerHeaderObj.txA/dataOut.radarControllerHeaderObj.nBaud) / deltaHeight
276
276
277 newdelta = deltaHeight * window
277 newdelta = deltaHeight * window
278 r = dataOut.nHeights % window
278 r = dataOut.nHeights % window
279 newheights = (dataOut.nHeights-r)/window
279 newheights = (dataOut.nHeights-r)/window
280
280
281 if newheights <= 1:
281 if newheights <= 1:
282 raise ValueError("filterByHeights: Too few heights. Current number of heights is %d and window is %d" %(dataOut.nHeights, window))
282 raise ValueError("filterByHeights: Too few heights. Current number of heights is %d and window is %d" %(dataOut.nHeights, window))
283
283
284 if dataOut.flagDataAsBlock:
284 if dataOut.flagDataAsBlock:
285 """
285 """
286 Si la data es obtenida por bloques, dimension = [nChannels, nProfiles, nHeis]
286 Si la data es obtenida por bloques, dimension = [nChannels, nProfiles, nHeis]
287 """
287 """
288 buffer = dataOut.data[:, :, 0:int(dataOut.nHeights-r)]
288 buffer = dataOut.data[:, :, 0:int(dataOut.nHeights-r)]
289 buffer = buffer.reshape(dataOut.nChannels, dataOut.nProfiles, int(dataOut.nHeights/window), window)
289 buffer = buffer.reshape(dataOut.nChannels, dataOut.nProfiles, int(dataOut.nHeights/window), window)
290 buffer = numpy.sum(buffer,3)
290 buffer = numpy.sum(buffer,3)
291
291
292 else:
292 else:
293 buffer = dataOut.data[:,0:int(dataOut.nHeights-r)]
293 buffer = dataOut.data[:,0:int(dataOut.nHeights-r)]
294 buffer = buffer.reshape(dataOut.nChannels,int(dataOut.nHeights/window),int(window))
294 buffer = buffer.reshape(dataOut.nChannels,int(dataOut.nHeights/window),int(window))
295 buffer = numpy.sum(buffer,2)
295 buffer = numpy.sum(buffer,2)
296
296
297 dataOut.data = buffer
297 dataOut.data = buffer
298 dataOut.heightList = dataOut.heightList[0] + numpy.arange( newheights )*newdelta
298 dataOut.heightList = dataOut.heightList[0] + numpy.arange( newheights )*newdelta
299 dataOut.windowOfFilter = window
299 dataOut.windowOfFilter = window
300
300
301 return dataOut
301 return dataOut
302
302
303
303
304 class setH0(Operation):
304 class setH0(Operation):
305
305
306 def run(self, dataOut, h0, deltaHeight = None):
306 def run(self, dataOut, h0, deltaHeight = None):
307
307
308 if not deltaHeight:
308 if not deltaHeight:
309 deltaHeight = dataOut.heightList[1] - dataOut.heightList[0]
309 deltaHeight = dataOut.heightList[1] - dataOut.heightList[0]
310
310
311 nHeights = dataOut.nHeights
311 nHeights = dataOut.nHeights
312
312
313 newHeiRange = h0 + numpy.arange(nHeights)*deltaHeight
313 newHeiRange = h0 + numpy.arange(nHeights)*deltaHeight
314
314
315 dataOut.heightList = newHeiRange
315 dataOut.heightList = newHeiRange
316
316
317 return dataOut
317 return dataOut
318
318
319
319
320 class deFlip(Operation):
320 class deFlip(Operation):
321
321
322 def run(self, dataOut, channelList = []):
322 def run(self, dataOut, channelList = []):
323
323
324 data = dataOut.data.copy()
324 data = dataOut.data.copy()
325
325
326 if dataOut.flagDataAsBlock:
326 if dataOut.flagDataAsBlock:
327 flip = self.flip
327 flip = self.flip
328 profileList = list(range(dataOut.nProfiles))
328 profileList = list(range(dataOut.nProfiles))
329
329
330 if not channelList:
330 if not channelList:
331 for thisProfile in profileList:
331 for thisProfile in profileList:
332 data[:,thisProfile,:] = data[:,thisProfile,:]*flip
332 data[:,thisProfile,:] = data[:,thisProfile,:]*flip
333 flip *= -1.0
333 flip *= -1.0
334 else:
334 else:
335 for thisChannel in channelList:
335 for thisChannel in channelList:
336 if thisChannel not in dataOut.channelList:
336 if thisChannel not in dataOut.channelList:
337 continue
337 continue
338
338
339 for thisProfile in profileList:
339 for thisProfile in profileList:
340 data[thisChannel,thisProfile,:] = data[thisChannel,thisProfile,:]*flip
340 data[thisChannel,thisProfile,:] = data[thisChannel,thisProfile,:]*flip
341 flip *= -1.0
341 flip *= -1.0
342
342
343 self.flip = flip
343 self.flip = flip
344
344
345 else:
345 else:
346 if not channelList:
346 if not channelList:
347 data[:,:] = data[:,:]*self.flip
347 data[:,:] = data[:,:]*self.flip
348 else:
348 else:
349 for thisChannel in channelList:
349 for thisChannel in channelList:
350 if thisChannel not in dataOut.channelList:
350 if thisChannel not in dataOut.channelList:
351 continue
351 continue
352
352
353 data[thisChannel,:] = data[thisChannel,:]*self.flip
353 data[thisChannel,:] = data[thisChannel,:]*self.flip
354
354
355 self.flip *= -1.
355 self.flip *= -1.
356
356
357 dataOut.data = data
357 dataOut.data = data
358
358
359 return dataOut
359 return dataOut
360
360
361
361
362 class setAttribute(Operation):
362 class setAttribute(Operation):
363 '''
363 '''
364 Set an arbitrary attribute(s) to dataOut
364 Set an arbitrary attribute(s) to dataOut
365 '''
365 '''
366
366
367 def __init__(self):
367 def __init__(self):
368
368
369 Operation.__init__(self)
369 Operation.__init__(self)
370 self._ready = False
370 self._ready = False
371
371
372 def run(self, dataOut, **kwargs):
372 def run(self, dataOut, **kwargs):
373
373
374 for key, value in kwargs.items():
374 for key, value in kwargs.items():
375 setattr(dataOut, key, value)
375 setattr(dataOut, key, value)
376
376
377 return dataOut
377 return dataOut
378
378
379
379
380 class interpolateHeights(Operation):
380 class interpolateHeights(Operation):
381
381
382 def run(self, dataOut, topLim, botLim):
382 def run(self, dataOut, topLim, botLim):
383 #69 al 72 para julia
383 #69 al 72 para julia
384 #82-84 para meteoros
384 #82-84 para meteoros
385 if len(numpy.shape(dataOut.data))==2:
385 if len(numpy.shape(dataOut.data))==2:
386 sampInterp = (dataOut.data[:,botLim-1] + dataOut.data[:,topLim+1])/2
386 sampInterp = (dataOut.data[:,botLim-1] + dataOut.data[:,topLim+1])/2
387 sampInterp = numpy.transpose(numpy.tile(sampInterp,(topLim-botLim + 1,1)))
387 sampInterp = numpy.transpose(numpy.tile(sampInterp,(topLim-botLim + 1,1)))
388 #dataOut.data[:,botLim:limSup+1] = sampInterp
388 #dataOut.data[:,botLim:limSup+1] = sampInterp
389 dataOut.data[:,botLim:topLim+1] = sampInterp
389 dataOut.data[:,botLim:topLim+1] = sampInterp
390 else:
390 else:
391 nHeights = dataOut.data.shape[2]
391 nHeights = dataOut.data.shape[2]
392 x = numpy.hstack((numpy.arange(botLim),numpy.arange(topLim+1,nHeights)))
392 x = numpy.hstack((numpy.arange(botLim),numpy.arange(topLim+1,nHeights)))
393 y = dataOut.data[:,:,list(range(botLim))+list(range(topLim+1,nHeights))]
393 y = dataOut.data[:,:,list(range(botLim))+list(range(topLim+1,nHeights))]
394 f = interpolate.interp1d(x, y, axis = 2)
394 f = interpolate.interp1d(x, y, axis = 2)
395 xnew = numpy.arange(botLim,topLim+1)
395 xnew = numpy.arange(botLim,topLim+1)
396 ynew = f(xnew)
396 ynew = f(xnew)
397 dataOut.data[:,:,botLim:topLim+1] = ynew
397 dataOut.data[:,:,botLim:topLim+1] = ynew
398
398
399 return dataOut
399 return dataOut
400
400
401
401
402 class CohInt(Operation):
402 class CohInt(Operation):
403
403
404 isConfig = False
404 isConfig = False
405 __profIndex = 0
405 __profIndex = 0
406 __byTime = False
406 __byTime = False
407 __initime = None
407 __initime = None
408 __lastdatatime = None
408 __lastdatatime = None
409 __integrationtime = None
409 __integrationtime = None
410 __buffer = None
410 __buffer = None
411 __bufferStride = []
411 __bufferStride = []
412 __dataReady = False
412 __dataReady = False
413 __profIndexStride = 0
413 __profIndexStride = 0
414 __dataToPutStride = False
414 __dataToPutStride = False
415 n = None
415 n = None
416
416
417 def __init__(self, **kwargs):
417 def __init__(self, **kwargs):
418
418
419 Operation.__init__(self, **kwargs)
419 Operation.__init__(self, **kwargs)
420
420
421 # self.isConfig = False
421 # self.isConfig = False
422
422
423 def setup(self, n=None, timeInterval=None, stride=None, overlapping=False, byblock=False):
423 def setup(self, n=None, timeInterval=None, stride=None, overlapping=False, byblock=False):
424 """
424 """
425 Set the parameters of the integration class.
425 Set the parameters of the integration class.
426
426
427 Inputs:
427 Inputs:
428
428
429 n : Number of coherent integrations
429 n : Number of coherent integrations
430 timeInterval : Time of integration. If the parameter "n" is selected this one does not work
430 timeInterval : Time of integration. If the parameter "n" is selected this one does not work
431 overlapping :
431 overlapping :
432 """
432 """
433
433
434 self.__initime = None
434 self.__initime = None
435 self.__lastdatatime = 0
435 self.__lastdatatime = 0
436 self.__buffer = None
436 self.__buffer = None
437 self.__dataReady = False
437 self.__dataReady = False
438 self.byblock = byblock
438 self.byblock = byblock
439 self.stride = stride
439 self.stride = stride
440
440
441 if n == None and timeInterval == None:
441 if n == None and timeInterval == None:
442 raise ValueError("n or timeInterval should be specified ...")
442 raise ValueError("n or timeInterval should be specified ...")
443
443
444 if n != None:
444 if n != None:
445 self.n = n
445 self.n = n
446 self.__byTime = False
446 self.__byTime = False
447 else:
447 else:
448 self.__integrationtime = timeInterval #* 60. #if (type(timeInterval)!=integer) -> change this line
448 self.__integrationtime = timeInterval #* 60. #if (type(timeInterval)!=integer) -> change this line
449 self.n = 9999
449 self.n = 9999
450 self.__byTime = True
450 self.__byTime = True
451
451
452 if overlapping:
452 if overlapping:
453 self.__withOverlapping = True
453 self.__withOverlapping = True
454 self.__buffer = None
454 self.__buffer = None
455 else:
455 else:
456 self.__withOverlapping = False
456 self.__withOverlapping = False
457 self.__buffer = 0
457 self.__buffer = 0
458
458
459 self.__profIndex = 0
459 self.__profIndex = 0
460
460
461 def putData(self, data):
461 def putData(self, data):
462
462
463 """
463 """
464 Add a profile to the __buffer and increase in one the __profileIndex
464 Add a profile to the __buffer and increase in one the __profileIndex
465
465
466 """
466 """
467
467
468 if not self.__withOverlapping:
468 if not self.__withOverlapping:
469 self.__buffer += data.copy()
469 self.__buffer += data.copy()
470 self.__profIndex += 1
470 self.__profIndex += 1
471 return
471 return
472
472
473 #Overlapping data
473 #Overlapping data
474 nChannels, nHeis = data.shape
474 nChannels, nHeis = data.shape
475 data = numpy.reshape(data, (1, nChannels, nHeis))
475 data = numpy.reshape(data, (1, nChannels, nHeis))
476
476
477 #If the buffer is empty then it takes the data value
477 #If the buffer is empty then it takes the data value
478 if self.__buffer is None:
478 if self.__buffer is None:
479 self.__buffer = data
479 self.__buffer = data
480 self.__profIndex += 1
480 self.__profIndex += 1
481 return
481 return
482
482
483 #If the buffer length is lower than n then stakcing the data value
483 #If the buffer length is lower than n then stakcing the data value
484 if self.__profIndex < self.n:
484 if self.__profIndex < self.n:
485 self.__buffer = numpy.vstack((self.__buffer, data))
485 self.__buffer = numpy.vstack((self.__buffer, data))
486 self.__profIndex += 1
486 self.__profIndex += 1
487 return
487 return
488
488
489 #If the buffer length is equal to n then replacing the last buffer value with the data value
489 #If the buffer length is equal to n then replacing the last buffer value with the data value
490 self.__buffer = numpy.roll(self.__buffer, -1, axis=0)
490 self.__buffer = numpy.roll(self.__buffer, -1, axis=0)
491 self.__buffer[self.n-1] = data
491 self.__buffer[self.n-1] = data
492 self.__profIndex = self.n
492 self.__profIndex = self.n
493 return
493 return
494
494
495
495
496 def pushData(self):
496 def pushData(self):
497 """
497 """
498 Return the sum of the last profiles and the profiles used in the sum.
498 Return the sum of the last profiles and the profiles used in the sum.
499
499
500 Affected:
500 Affected:
501
501
502 self.__profileIndex
502 self.__profileIndex
503
503
504 """
504 """
505
505
506 if not self.__withOverlapping:
506 if not self.__withOverlapping:
507 data = self.__buffer
507 data = self.__buffer
508 n = self.__profIndex
508 n = self.__profIndex
509
509
510 self.__buffer = 0
510 self.__buffer = 0
511 self.__profIndex = 0
511 self.__profIndex = 0
512
512
513 return data, n
513 return data, n
514
514
515 #Integration with Overlapping
515 #Integration with Overlapping
516 data = numpy.sum(self.__buffer, axis=0)
516 data = numpy.sum(self.__buffer, axis=0)
517 # print data
517 # print data
518 # raise
518 # raise
519 n = self.__profIndex
519 n = self.__profIndex
520
520
521 return data, n
521 return data, n
522
522
523 def byProfiles(self, data):
523 def byProfiles(self, data):
524
524
525 self.__dataReady = False
525 self.__dataReady = False
526 avgdata = None
526 avgdata = None
527 # n = None
527 # n = None
528 # print data
528 # print data
529 # raise
529 # raise
530 self.putData(data)
530 self.putData(data)
531
531
532 if self.__profIndex == self.n:
532 if self.__profIndex == self.n:
533 avgdata, n = self.pushData()
533 avgdata, n = self.pushData()
534 self.__dataReady = True
534 self.__dataReady = True
535
535
536 return avgdata
536 return avgdata
537
537
538 def byTime(self, data, datatime):
538 def byTime(self, data, datatime):
539
539
540 self.__dataReady = False
540 self.__dataReady = False
541 avgdata = None
541 avgdata = None
542 n = None
542 n = None
543
543
544 self.putData(data)
544 self.putData(data)
545
545
546 if (datatime - self.__initime) >= self.__integrationtime:
546 if (datatime - self.__initime) >= self.__integrationtime:
547 avgdata, n = self.pushData()
547 avgdata, n = self.pushData()
548 self.n = n
548 self.n = n
549 self.__dataReady = True
549 self.__dataReady = True
550
550
551 return avgdata
551 return avgdata
552
552
553 def integrateByStride(self, data, datatime):
553 def integrateByStride(self, data, datatime):
554 # print data
554 # print data
555 if self.__profIndex == 0:
555 if self.__profIndex == 0:
556 self.__buffer = [[data.copy(), datatime]]
556 self.__buffer = [[data.copy(), datatime]]
557 else:
557 else:
558 self.__buffer.append([data.copy(),datatime])
558 self.__buffer.append([data.copy(),datatime])
559 self.__profIndex += 1
559 self.__profIndex += 1
560 self.__dataReady = False
560 self.__dataReady = False
561
561
562 if self.__profIndex == self.n * self.stride :
562 if self.__profIndex == self.n * self.stride :
563 self.__dataToPutStride = True
563 self.__dataToPutStride = True
564 self.__profIndexStride = 0
564 self.__profIndexStride = 0
565 self.__profIndex = 0
565 self.__profIndex = 0
566 self.__bufferStride = []
566 self.__bufferStride = []
567 for i in range(self.stride):
567 for i in range(self.stride):
568 current = self.__buffer[i::self.stride]
568 current = self.__buffer[i::self.stride]
569 data = numpy.sum([t[0] for t in current], axis=0)
569 data = numpy.sum([t[0] for t in current], axis=0)
570 avgdatatime = numpy.average([t[1] for t in current])
570 avgdatatime = numpy.average([t[1] for t in current])
571 # print data
571 # print data
572 self.__bufferStride.append((data, avgdatatime))
572 self.__bufferStride.append((data, avgdatatime))
573
573
574 if self.__dataToPutStride:
574 if self.__dataToPutStride:
575 self.__dataReady = True
575 self.__dataReady = True
576 self.__profIndexStride += 1
576 self.__profIndexStride += 1
577 if self.__profIndexStride == self.stride:
577 if self.__profIndexStride == self.stride:
578 self.__dataToPutStride = False
578 self.__dataToPutStride = False
579 # print self.__bufferStride[self.__profIndexStride - 1]
579 # print self.__bufferStride[self.__profIndexStride - 1]
580 # raise
580 # raise
581 return self.__bufferStride[self.__profIndexStride - 1]
581 return self.__bufferStride[self.__profIndexStride - 1]
582
582
583
583
584 return None, None
584 return None, None
585
585
586 def integrate(self, data, datatime=None):
586 def integrate(self, data, datatime=None):
587
587
588 if self.__initime == None:
588 if self.__initime == None:
589 self.__initime = datatime
589 self.__initime = datatime
590
590
591 if self.__byTime:
591 if self.__byTime:
592 avgdata = self.byTime(data, datatime)
592 avgdata = self.byTime(data, datatime)
593 else:
593 else:
594 avgdata = self.byProfiles(data)
594 avgdata = self.byProfiles(data)
595
595
596
596
597 self.__lastdatatime = datatime
597 self.__lastdatatime = datatime
598
598
599 if avgdata is None:
599 if avgdata is None:
600 return None, None
600 return None, None
601
601
602 avgdatatime = self.__initime
602 avgdatatime = self.__initime
603
603
604 deltatime = datatime - self.__lastdatatime
604 deltatime = datatime - self.__lastdatatime
605
605
606 if not self.__withOverlapping:
606 if not self.__withOverlapping:
607 self.__initime = datatime
607 self.__initime = datatime
608 else:
608 else:
609 self.__initime += deltatime
609 self.__initime += deltatime
610
610
611 return avgdata, avgdatatime
611 return avgdata, avgdatatime
612
612
613 def integrateByBlock(self, dataOut):
613 def integrateByBlock(self, dataOut):
614
614
615 times = int(dataOut.data.shape[1]/self.n)
615 times = int(dataOut.data.shape[1]/self.n)
616 avgdata = numpy.zeros((dataOut.nChannels, times, dataOut.nHeights), dtype=numpy.complex)
616 avgdata = numpy.zeros((dataOut.nChannels, times, dataOut.nHeights), dtype=numpy.complex)
617
617
618 id_min = 0
618 id_min = 0
619 id_max = self.n
619 id_max = self.n
620
620
621 for i in range(times):
621 for i in range(times):
622 junk = dataOut.data[:,id_min:id_max,:]
622 junk = dataOut.data[:,id_min:id_max,:]
623 avgdata[:,i,:] = junk.sum(axis=1)
623 avgdata[:,i,:] = junk.sum(axis=1)
624 id_min += self.n
624 id_min += self.n
625 id_max += self.n
625 id_max += self.n
626
626
627 timeInterval = dataOut.ippSeconds*self.n
627 timeInterval = dataOut.ippSeconds*self.n
628 avgdatatime = (times - 1) * timeInterval + dataOut.utctime
628 avgdatatime = (times - 1) * timeInterval + dataOut.utctime
629 self.__dataReady = True
629 self.__dataReady = True
630 return avgdata, avgdatatime
630 return avgdata, avgdatatime
631
631
632 def run(self, dataOut, n=None, timeInterval=None, stride=None, overlapping=False, byblock=False, **kwargs):
632 def run(self, dataOut, n=None, timeInterval=None, stride=None, overlapping=False, byblock=False, **kwargs):
633
633
634 if not self.isConfig:
634 if not self.isConfig:
635 self.setup(n=n, stride=stride, timeInterval=timeInterval, overlapping=overlapping, byblock=byblock, **kwargs)
635 self.setup(n=n, stride=stride, timeInterval=timeInterval, overlapping=overlapping, byblock=byblock, **kwargs)
636 self.isConfig = True
636 self.isConfig = True
637
637
638 if dataOut.flagDataAsBlock:
638 if dataOut.flagDataAsBlock:
639 """
639 """
640 Si la data es leida por bloques, dimension = [nChannels, nProfiles, nHeis]
640 Si la data es leida por bloques, dimension = [nChannels, nProfiles, nHeis]
641 """
641 """
642 avgdata, avgdatatime = self.integrateByBlock(dataOut)
642 avgdata, avgdatatime = self.integrateByBlock(dataOut)
643 dataOut.nProfiles /= self.n
643 dataOut.nProfiles /= self.n
644 else:
644 else:
645 if stride is None:
645 if stride is None:
646 avgdata, avgdatatime = self.integrate(dataOut.data, dataOut.utctime)
646 avgdata, avgdatatime = self.integrate(dataOut.data, dataOut.utctime)
647 else:
647 else:
648 avgdata, avgdatatime = self.integrateByStride(dataOut.data, dataOut.utctime)
648 avgdata, avgdatatime = self.integrateByStride(dataOut.data, dataOut.utctime)
649
649
650
650
651 # dataOut.timeInterval *= n
651 # dataOut.timeInterval *= n
652 dataOut.flagNoData = True
652 dataOut.flagNoData = True
653
653
654 if self.__dataReady:
654 if self.__dataReady:
655 dataOut.data = avgdata
655 dataOut.data = avgdata
656 dataOut.nCohInt *= self.n
656 dataOut.nCohInt *= self.n
657 dataOut.utctime = avgdatatime
657 dataOut.utctime = avgdatatime
658 # print avgdata, avgdatatime
658 # print avgdata, avgdatatime
659 # raise
659 # raise
660 # dataOut.timeInterval = dataOut.ippSeconds * dataOut.nCohInt
660 # dataOut.timeInterval = dataOut.ippSeconds * dataOut.nCohInt
661 dataOut.flagNoData = False
661 dataOut.flagNoData = False
662 return dataOut
662 return dataOut
663
663
664 class Decoder(Operation):
664 class Decoder(Operation):
665
665
666 isConfig = False
666 isConfig = False
667 __profIndex = 0
667 __profIndex = 0
668
668
669 code = None
669 code = None
670
670
671 nCode = None
671 nCode = None
672 nBaud = None
672 nBaud = None
673
673
674 def __init__(self, **kwargs):
674 def __init__(self, **kwargs):
675
675
676 Operation.__init__(self, **kwargs)
676 Operation.__init__(self, **kwargs)
677
677
678 self.times = None
678 self.times = None
679 self.osamp = None
679 self.osamp = None
680 # self.__setValues = False
680 # self.__setValues = False
681 self.isConfig = False
681 self.isConfig = False
682 self.setupReq = False
682 self.setupReq = False
683 def setup(self, code, osamp, dataOut):
683 def setup(self, code, osamp, dataOut):
684
684
685 self.__profIndex = 0
685 self.__profIndex = 0
686
686
687 self.code = code
687 self.code = code
688
688
689 self.nCode = len(code)
689 self.nCode = len(code)
690 self.nBaud = len(code[0])
690 self.nBaud = len(code[0])
691
691
692 if (osamp != None) and (osamp >1):
692 if (osamp != None) and (osamp >1):
693 self.osamp = osamp
693 self.osamp = osamp
694 self.code = numpy.repeat(code, repeats=self.osamp, axis=1)
694 self.code = numpy.repeat(code, repeats=self.osamp, axis=1)
695 self.nBaud = self.nBaud*self.osamp
695 self.nBaud = self.nBaud*self.osamp
696
696
697 self.__nChannels = dataOut.nChannels
697 self.__nChannels = dataOut.nChannels
698 self.__nProfiles = dataOut.nProfiles
698 self.__nProfiles = dataOut.nProfiles
699 self.__nHeis = dataOut.nHeights
699 self.__nHeis = dataOut.nHeights
700
700
701 if self.__nHeis < self.nBaud:
701 if self.__nHeis < self.nBaud:
702 raise ValueError('Number of heights (%d) should be greater than number of bauds (%d)' %(self.__nHeis, self.nBaud))
702 raise ValueError('Number of heights (%d) should be greater than number of bauds (%d)' %(self.__nHeis, self.nBaud))
703
703
704 #Frequency
704 #Frequency
705 __codeBuffer = numpy.zeros((self.nCode, self.__nHeis), dtype=numpy.complex)
705 __codeBuffer = numpy.zeros((self.nCode, self.__nHeis), dtype=numpy.complex)
706
706
707 __codeBuffer[:,0:self.nBaud] = self.code
707 __codeBuffer[:,0:self.nBaud] = self.code
708
708
709 self.fft_code = numpy.conj(numpy.fft.fft(__codeBuffer, axis=1))
709 self.fft_code = numpy.conj(numpy.fft.fft(__codeBuffer, axis=1))
710
710
711 if dataOut.flagDataAsBlock:
711 if dataOut.flagDataAsBlock:
712
712
713 self.ndatadec = self.__nHeis #- self.nBaud + 1
713 self.ndatadec = self.__nHeis #- self.nBaud + 1
714
714
715 self.datadecTime = numpy.zeros((self.__nChannels, self.__nProfiles, self.ndatadec), dtype=numpy.complex)
715 self.datadecTime = numpy.zeros((self.__nChannels, self.__nProfiles, self.ndatadec), dtype=numpy.complex)
716
716
717 else:
717 else:
718
718
719 #Time
719 #Time
720 self.ndatadec = self.__nHeis #- self.nBaud + 1
720 self.ndatadec = self.__nHeis #- self.nBaud + 1
721
721
722 self.datadecTime = numpy.zeros((self.__nChannels, self.ndatadec), dtype=numpy.complex)
722 self.datadecTime = numpy.zeros((self.__nChannels, self.ndatadec), dtype=numpy.complex)
723
723
724 def __convolutionInFreq(self, data):
724 def __convolutionInFreq(self, data):
725
725
726 fft_code = self.fft_code[self.__profIndex].reshape(1,-1)
726 fft_code = self.fft_code[self.__profIndex].reshape(1,-1)
727
727
728 fft_data = numpy.fft.fft(data, axis=1)
728 fft_data = numpy.fft.fft(data, axis=1)
729
729
730 conv = fft_data*fft_code
730 conv = fft_data*fft_code
731
731
732 data = numpy.fft.ifft(conv,axis=1)
732 data = numpy.fft.ifft(conv,axis=1)
733
733
734 return data
734 return data
735
735
736 def __convolutionInFreqOpt(self, data):
736 def __convolutionInFreqOpt(self, data):
737
737
738 raise NotImplementedError
738 raise NotImplementedError
739
739
740 def __convolutionInTime(self, data):
740 def __convolutionInTime(self, data):
741
741
742 code = self.code[self.__profIndex]
742 code = self.code[self.__profIndex]
743 for i in range(self.__nChannels):
743 for i in range(self.__nChannels):
744 self.datadecTime[i,:] = numpy.correlate(data[i,:], code, mode='full')[self.nBaud-1:]
744 self.datadecTime[i,:] = numpy.correlate(data[i,:], code, mode='full')[self.nBaud-1:]
745
745
746 return self.datadecTime
746 return self.datadecTime
747
747
748 def __convolutionByBlockInTime(self, data):
748 def __convolutionByBlockInTime(self, data):
749
749
750 repetitions = int(self.__nProfiles / self.nCode)
750 repetitions = int(self.__nProfiles / self.nCode)
751 junk = numpy.lib.stride_tricks.as_strided(self.code, (repetitions, self.code.size), (0, self.code.itemsize))
751 junk = numpy.lib.stride_tricks.as_strided(self.code, (repetitions, self.code.size), (0, self.code.itemsize))
752 junk = junk.flatten()
752 junk = junk.flatten()
753 code_block = numpy.reshape(junk, (self.nCode*repetitions, self.nBaud))
753 code_block = numpy.reshape(junk, (self.nCode*repetitions, self.nBaud))
754 profilesList = range(self.__nProfiles)
754 profilesList = range(self.__nProfiles)
755
755
756 for i in range(self.__nChannels):
756 for i in range(self.__nChannels):
757 for j in profilesList:
757 for j in profilesList:
758 self.datadecTime[i,j,:] = numpy.correlate(data[i,j,:], code_block[j,:], mode='full')[self.nBaud-1:]
758 self.datadecTime[i,j,:] = numpy.correlate(data[i,j,:], code_block[j,:], mode='full')[self.nBaud-1:]
759 return self.datadecTime
759 return self.datadecTime
760
760
761 def __convolutionByBlockInFreq(self, data):
761 def __convolutionByBlockInFreq(self, data):
762
762
763 raise NotImplementedError("Decoder by frequency fro Blocks not implemented")
763 raise NotImplementedError("Decoder by frequency fro Blocks not implemented")
764
764
765
765
766 fft_code = self.fft_code[self.__profIndex].reshape(1,-1)
766 fft_code = self.fft_code[self.__profIndex].reshape(1,-1)
767
767
768 fft_data = numpy.fft.fft(data, axis=2)
768 fft_data = numpy.fft.fft(data, axis=2)
769
769
770 conv = fft_data*fft_code
770 conv = fft_data*fft_code
771
771
772 data = numpy.fft.ifft(conv,axis=2)
772 data = numpy.fft.ifft(conv,axis=2)
773
773
774 return data
774 return data
775
775
776
776
777 def run(self, dataOut, code=None, nCode=None, nBaud=None, mode = 0, osamp=None, times=None):
777 def run(self, dataOut, code=None, nCode=None, nBaud=None, mode = 0, osamp=None, times=None):
778
778
779 if dataOut.flagDecodeData:
779 if dataOut.flagDecodeData:
780 print("This data is already decoded, recoding again ...")
780 print("This data is already decoded, recoding again ...")
781
781
782 if not self.isConfig:
782 if not self.isConfig:
783
783
784 if code is None:
784 if code is None:
785 if dataOut.code is None:
785 if dataOut.code is None:
786 raise ValueError("Code could not be read from %s instance. Enter a value in Code parameter" %dataOut.type)
786 raise ValueError("Code could not be read from %s instance. Enter a value in Code parameter" %dataOut.type)
787
787
788 code = dataOut.code
788 code = dataOut.code
789 else:
789 else:
790 code = numpy.array(code).reshape(nCode,nBaud)
790 code = numpy.array(code).reshape(nCode,nBaud)
791 self.setup(code, osamp, dataOut)
791 self.setup(code, osamp, dataOut)
792
792
793 self.isConfig = True
793 self.isConfig = True
794
794
795 if mode == 3:
795 if mode == 3:
796 sys.stderr.write("Decoder Warning: mode=%d is not valid, using mode=0\n" %mode)
796 sys.stderr.write("Decoder Warning: mode=%d is not valid, using mode=0\n" %mode)
797
797
798 if times != None:
798 if times != None:
799 sys.stderr.write("Decoder Warning: Argument 'times' in not used anymore\n")
799 sys.stderr.write("Decoder Warning: Argument 'times' in not used anymore\n")
800
800
801 if self.code is None:
801 if self.code is None:
802 print("Fail decoding: Code is not defined.")
802 print("Fail decoding: Code is not defined.")
803 return
803 return
804
804
805 self.__nProfiles = dataOut.nProfiles
805 self.__nProfiles = dataOut.nProfiles
806 datadec = None
806 datadec = None
807
807
808 if mode == 3:
808 if mode == 3:
809 mode = 0
809 mode = 0
810
810
811 if dataOut.flagDataAsBlock:
811 if dataOut.flagDataAsBlock:
812 """
812 """
813 Decoding when data have been read as block,
813 Decoding when data have been read as block,
814 """
814 """
815
815
816 if mode == 0:
816 if mode == 0:
817 datadec = self.__convolutionByBlockInTime(dataOut.data)
817 datadec = self.__convolutionByBlockInTime(dataOut.data)
818 if mode == 1:
818 if mode == 1:
819 datadec = self.__convolutionByBlockInFreq(dataOut.data)
819 datadec = self.__convolutionByBlockInFreq(dataOut.data)
820 else:
820 else:
821 """
821 """
822 Decoding when data have been read profile by profile
822 Decoding when data have been read profile by profile
823 """
823 """
824 if mode == 0:
824 if mode == 0:
825 datadec = self.__convolutionInTime(dataOut.data)
825 datadec = self.__convolutionInTime(dataOut.data)
826
826
827 if mode == 1:
827 if mode == 1:
828 datadec = self.__convolutionInFreq(dataOut.data)
828 datadec = self.__convolutionInFreq(dataOut.data)
829
829
830 if mode == 2:
830 if mode == 2:
831 datadec = self.__convolutionInFreqOpt(dataOut.data)
831 datadec = self.__convolutionInFreqOpt(dataOut.data)
832
832
833 if datadec is None:
833 if datadec is None:
834 raise ValueError("Codification mode selected is not valid: mode=%d. Try selecting 0 or 1" %mode)
834 raise ValueError("Codification mode selected is not valid: mode=%d. Try selecting 0 or 1" %mode)
835
835
836 dataOut.code = self.code
836 dataOut.code = self.code
837 dataOut.nCode = self.nCode
837 dataOut.nCode = self.nCode
838 dataOut.nBaud = self.nBaud
838 dataOut.nBaud = self.nBaud
839
839
840 dataOut.data = datadec
840 dataOut.data = datadec
841
841
842 dataOut.heightList = dataOut.heightList[0:datadec.shape[-1]]
842 dataOut.heightList = dataOut.heightList[0:datadec.shape[-1]]
843
843
844 dataOut.flagDecodeData = True #asumo q la data esta decodificada
844 dataOut.flagDecodeData = True #asumo q la data esta decodificada
845
845
846 if self.__profIndex == self.nCode-1:
846 if self.__profIndex == self.nCode-1:
847 self.__profIndex = 0
847 self.__profIndex = 0
848 return dataOut
848 return dataOut
849
849
850 self.__profIndex += 1
850 self.__profIndex += 1
851
851
852 return dataOut
852 return dataOut
853 # dataOut.flagDeflipData = True #asumo q la data no esta sin flip
853 # dataOut.flagDeflipData = True #asumo q la data no esta sin flip
854
854
855
855
856 class ProfileConcat(Operation):
856 class ProfileConcat(Operation):
857
857
858 isConfig = False
858 isConfig = False
859 buffer = None
859 buffer = None
860
860
861 def __init__(self, **kwargs):
861 def __init__(self, **kwargs):
862
862
863 Operation.__init__(self, **kwargs)
863 Operation.__init__(self, **kwargs)
864 self.profileIndex = 0
864 self.profileIndex = 0
865
865
866 def reset(self):
866 def reset(self):
867 self.buffer = numpy.zeros_like(self.buffer)
867 self.buffer = numpy.zeros_like(self.buffer)
868 self.start_index = 0
868 self.start_index = 0
869 self.times = 1
869 self.times = 1
870
870
871 def setup(self, data, m, n=1):
871 def setup(self, data, m, n=1):
872 self.buffer = numpy.zeros((data.shape[0],data.shape[1]*m),dtype=type(data[0,0]))
872 self.buffer = numpy.zeros((data.shape[0],data.shape[1]*m),dtype=type(data[0,0]))
873 self.nHeights = data.shape[1]#.nHeights
873 self.nHeights = data.shape[1]#.nHeights
874 self.start_index = 0
874 self.start_index = 0
875 self.times = 1
875 self.times = 1
876
876
877 def concat(self, data):
877 def concat(self, data):
878
878
879 self.buffer[:,self.start_index:self.nHeights*self.times] = data.copy()
879 self.buffer[:,self.start_index:self.nHeights*self.times] = data.copy()
880 self.start_index = self.start_index + self.nHeights
880 self.start_index = self.start_index + self.nHeights
881
881
882 def run(self, dataOut, m):
882 def run(self, dataOut, m):
883 dataOut.flagNoData = True
883 dataOut.flagNoData = True
884
884
885 if not self.isConfig:
885 if not self.isConfig:
886 self.setup(dataOut.data, m, 1)
886 self.setup(dataOut.data, m, 1)
887 self.isConfig = True
887 self.isConfig = True
888
888
889 if dataOut.flagDataAsBlock:
889 if dataOut.flagDataAsBlock:
890 raise ValueError("ProfileConcat can only be used when voltage have been read profile by profile, getBlock = False")
890 raise ValueError("ProfileConcat can only be used when voltage have been read profile by profile, getBlock = False")
891
891
892 else:
892 else:
893 self.concat(dataOut.data)
893 self.concat(dataOut.data)
894 self.times += 1
894 self.times += 1
895 if self.times > m:
895 if self.times > m:
896 dataOut.data = self.buffer
896 dataOut.data = self.buffer
897 self.reset()
897 self.reset()
898 dataOut.flagNoData = False
898 dataOut.flagNoData = False
899 # se deben actualizar mas propiedades del header y del objeto dataOut, por ejemplo, las alturas
899 # se deben actualizar mas propiedades del header y del objeto dataOut, por ejemplo, las alturas
900 deltaHeight = dataOut.heightList[1] - dataOut.heightList[0]
900 deltaHeight = dataOut.heightList[1] - dataOut.heightList[0]
901 xf = dataOut.heightList[0] + dataOut.nHeights * deltaHeight * m
901 xf = dataOut.heightList[0] + dataOut.nHeights * deltaHeight * m
902 dataOut.heightList = numpy.arange(dataOut.heightList[0], xf, deltaHeight)
902 dataOut.heightList = numpy.arange(dataOut.heightList[0], xf, deltaHeight)
903 dataOut.ippSeconds *= m
903 dataOut.ippSeconds *= m
904 return dataOut
904 return dataOut
905
905
906 class ProfileSelector(Operation):
906 class ProfileSelector(Operation):
907
907
908 profileIndex = None
908 profileIndex = None
909 # Tamanho total de los perfiles
909 # Tamanho total de los perfiles
910 nProfiles = None
910 nProfiles = None
911
911
912 def __init__(self, **kwargs):
912 def __init__(self, **kwargs):
913
913
914 Operation.__init__(self, **kwargs)
914 Operation.__init__(self, **kwargs)
915 self.profileIndex = 0
915 self.profileIndex = 0
916
916
917 def incProfileIndex(self):
917 def incProfileIndex(self):
918
918
919 self.profileIndex += 1
919 self.profileIndex += 1
920
920
921 if self.profileIndex >= self.nProfiles:
921 if self.profileIndex >= self.nProfiles:
922 self.profileIndex = 0
922 self.profileIndex = 0
923
923
924 def isThisProfileInRange(self, profileIndex, minIndex, maxIndex):
924 def isThisProfileInRange(self, profileIndex, minIndex, maxIndex):
925
925
926 if profileIndex < minIndex:
926 if profileIndex < minIndex:
927 return False
927 return False
928
928
929 if profileIndex > maxIndex:
929 if profileIndex > maxIndex:
930 return False
930 return False
931
931
932 return True
932 return True
933
933
934 def isThisProfileInList(self, profileIndex, profileList):
934 def isThisProfileInList(self, profileIndex, profileList):
935
935
936 if profileIndex not in profileList:
936 if profileIndex not in profileList:
937 return False
937 return False
938
938
939 return True
939 return True
940
940
941 def run(self, dataOut, profileList=None, profileRangeList=None, beam=None, byblock=False, rangeList = None, nProfiles=None):
941 def run(self, dataOut, profileList=None, profileRangeList=None, beam=None, byblock=False, rangeList = None, nProfiles=None):
942
942
943 """
943 """
944 ProfileSelector:
944 ProfileSelector:
945
945
946 Inputs:
946 Inputs:
947 profileList : Index of profiles selected. Example: profileList = (0,1,2,7,8)
947 profileList : Index of profiles selected. Example: profileList = (0,1,2,7,8)
948
948
949 profileRangeList : Minimum and maximum profile indexes. Example: profileRangeList = (4, 30)
949 profileRangeList : Minimum and maximum profile indexes. Example: profileRangeList = (4, 30)
950
950
951 rangeList : List of profile ranges. Example: rangeList = ((4, 30), (32, 64), (128, 256))
951 rangeList : List of profile ranges. Example: rangeList = ((4, 30), (32, 64), (128, 256))
952
952
953 """
953 """
954
954
955 if rangeList is not None:
955 if rangeList is not None:
956 if type(rangeList[0]) not in (tuple, list):
956 if type(rangeList[0]) not in (tuple, list):
957 rangeList = [rangeList]
957 rangeList = [rangeList]
958
958
959 dataOut.flagNoData = True
959 dataOut.flagNoData = True
960
960
961 if dataOut.flagDataAsBlock:
961 if dataOut.flagDataAsBlock:
962 """
962 """
963 data dimension = [nChannels, nProfiles, nHeis]
963 data dimension = [nChannels, nProfiles, nHeis]
964 """
964 """
965 if profileList != None:
965 if profileList != None:
966 dataOut.data = dataOut.data[:,profileList,:]
966 dataOut.data = dataOut.data[:,profileList,:]
967
967
968 if profileRangeList != None:
968 if profileRangeList != None:
969 minIndex = profileRangeList[0]
969 minIndex = profileRangeList[0]
970 maxIndex = profileRangeList[1]
970 maxIndex = profileRangeList[1]
971 profileList = list(range(minIndex, maxIndex+1))
971 profileList = list(range(minIndex, maxIndex+1))
972
972
973 dataOut.data = dataOut.data[:,minIndex:maxIndex+1,:]
973 dataOut.data = dataOut.data[:,minIndex:maxIndex+1,:]
974
974
975 if rangeList != None:
975 if rangeList != None:
976
976
977 profileList = []
977 profileList = []
978
978
979 for thisRange in rangeList:
979 for thisRange in rangeList:
980 minIndex = thisRange[0]
980 minIndex = thisRange[0]
981 maxIndex = thisRange[1]
981 maxIndex = thisRange[1]
982
982
983 profileList.extend(list(range(minIndex, maxIndex+1)))
983 profileList.extend(list(range(minIndex, maxIndex+1)))
984
984
985 dataOut.data = dataOut.data[:,profileList,:]
985 dataOut.data = dataOut.data[:,profileList,:]
986
986
987 dataOut.nProfiles = len(profileList)
987 dataOut.nProfiles = len(profileList)
988 dataOut.profileIndex = dataOut.nProfiles - 1
988 dataOut.profileIndex = dataOut.nProfiles - 1
989 dataOut.flagNoData = False
989 dataOut.flagNoData = False
990
990
991 return dataOut
991 return dataOut
992
992
993 """
993 """
994 data dimension = [nChannels, nHeis]
994 data dimension = [nChannels, nHeis]
995 """
995 """
996
996
997 if profileList != None:
997 if profileList != None:
998
998
999 if self.isThisProfileInList(dataOut.profileIndex, profileList):
999 if self.isThisProfileInList(dataOut.profileIndex, profileList):
1000
1000
1001 self.nProfiles = len(profileList)
1001 self.nProfiles = len(profileList)
1002 dataOut.nProfiles = self.nProfiles
1002 dataOut.nProfiles = self.nProfiles
1003 dataOut.profileIndex = self.profileIndex
1003 dataOut.profileIndex = self.profileIndex
1004 dataOut.flagNoData = False
1004 dataOut.flagNoData = False
1005
1005
1006 self.incProfileIndex()
1006 self.incProfileIndex()
1007 return dataOut
1007 return dataOut
1008
1008
1009 if profileRangeList != None:
1009 if profileRangeList != None:
1010
1010
1011 minIndex = profileRangeList[0]
1011 minIndex = profileRangeList[0]
1012 maxIndex = profileRangeList[1]
1012 maxIndex = profileRangeList[1]
1013
1013
1014 if self.isThisProfileInRange(dataOut.profileIndex, minIndex, maxIndex):
1014 if self.isThisProfileInRange(dataOut.profileIndex, minIndex, maxIndex):
1015
1015
1016 self.nProfiles = maxIndex - minIndex + 1
1016 self.nProfiles = maxIndex - minIndex + 1
1017 dataOut.nProfiles = self.nProfiles
1017 dataOut.nProfiles = self.nProfiles
1018 dataOut.profileIndex = self.profileIndex
1018 dataOut.profileIndex = self.profileIndex
1019 dataOut.flagNoData = False
1019 dataOut.flagNoData = False
1020
1020
1021 self.incProfileIndex()
1021 self.incProfileIndex()
1022 return dataOut
1022 return dataOut
1023
1023
1024 if rangeList != None:
1024 if rangeList != None:
1025
1025
1026 nProfiles = 0
1026 nProfiles = 0
1027
1027
1028 for thisRange in rangeList:
1028 for thisRange in rangeList:
1029 minIndex = thisRange[0]
1029 minIndex = thisRange[0]
1030 maxIndex = thisRange[1]
1030 maxIndex = thisRange[1]
1031
1031
1032 nProfiles += maxIndex - minIndex + 1
1032 nProfiles += maxIndex - minIndex + 1
1033
1033
1034 for thisRange in rangeList:
1034 for thisRange in rangeList:
1035
1035
1036 minIndex = thisRange[0]
1036 minIndex = thisRange[0]
1037 maxIndex = thisRange[1]
1037 maxIndex = thisRange[1]
1038
1038
1039 if self.isThisProfileInRange(dataOut.profileIndex, minIndex, maxIndex):
1039 if self.isThisProfileInRange(dataOut.profileIndex, minIndex, maxIndex):
1040
1040
1041 self.nProfiles = nProfiles
1041 self.nProfiles = nProfiles
1042 dataOut.nProfiles = self.nProfiles
1042 dataOut.nProfiles = self.nProfiles
1043 dataOut.profileIndex = self.profileIndex
1043 dataOut.profileIndex = self.profileIndex
1044 dataOut.flagNoData = False
1044 dataOut.flagNoData = False
1045
1045
1046 self.incProfileIndex()
1046 self.incProfileIndex()
1047
1047
1048 break
1048 break
1049
1049
1050 return dataOut
1050 return dataOut
1051
1051
1052
1052
1053 if beam != None: #beam is only for AMISR data
1053 if beam != None: #beam is only for AMISR data
1054 if self.isThisProfileInList(dataOut.profileIndex, dataOut.beamRangeDict[beam]):
1054 if self.isThisProfileInList(dataOut.profileIndex, dataOut.beamRangeDict[beam]):
1055 dataOut.flagNoData = False
1055 dataOut.flagNoData = False
1056 dataOut.profileIndex = self.profileIndex
1056 dataOut.profileIndex = self.profileIndex
1057
1057
1058 self.incProfileIndex()
1058 self.incProfileIndex()
1059
1059
1060 return dataOut
1060 return dataOut
1061
1061
1062 raise ValueError("ProfileSelector needs profileList, profileRangeList or rangeList parameter")
1062 raise ValueError("ProfileSelector needs profileList, profileRangeList or rangeList parameter")
1063
1063
1064
1064
1065 class Reshaper(Operation):
1065 class Reshaper(Operation):
1066
1066
1067 def __init__(self, **kwargs):
1067 def __init__(self, **kwargs):
1068
1068
1069 Operation.__init__(self, **kwargs)
1069 Operation.__init__(self, **kwargs)
1070
1070
1071 self.__buffer = None
1071 self.__buffer = None
1072 self.__nitems = 0
1072 self.__nitems = 0
1073
1073
1074 def __appendProfile(self, dataOut, nTxs):
1074 def __appendProfile(self, dataOut, nTxs):
1075
1075
1076 if self.__buffer is None:
1076 if self.__buffer is None:
1077 shape = (dataOut.nChannels, int(dataOut.nHeights/nTxs) )
1077 shape = (dataOut.nChannels, int(dataOut.nHeights/nTxs) )
1078 self.__buffer = numpy.empty(shape, dtype = dataOut.data.dtype)
1078 self.__buffer = numpy.empty(shape, dtype = dataOut.data.dtype)
1079
1079
1080 ini = dataOut.nHeights * self.__nitems
1080 ini = dataOut.nHeights * self.__nitems
1081 end = ini + dataOut.nHeights
1081 end = ini + dataOut.nHeights
1082
1082
1083 self.__buffer[:, ini:end] = dataOut.data
1083 self.__buffer[:, ini:end] = dataOut.data
1084
1084
1085 self.__nitems += 1
1085 self.__nitems += 1
1086
1086
1087 return int(self.__nitems*nTxs)
1087 return int(self.__nitems*nTxs)
1088
1088
1089 def __getBuffer(self):
1089 def __getBuffer(self):
1090
1090
1091 if self.__nitems == int(1./self.__nTxs):
1091 if self.__nitems == int(1./self.__nTxs):
1092
1092
1093 self.__nitems = 0
1093 self.__nitems = 0
1094
1094
1095 return self.__buffer.copy()
1095 return self.__buffer.copy()
1096
1096
1097 return None
1097 return None
1098
1098
1099 def __checkInputs(self, dataOut, shape, nTxs):
1099 def __checkInputs(self, dataOut, shape, nTxs):
1100
1100
1101 if shape is None and nTxs is None:
1101 if shape is None and nTxs is None:
1102 raise ValueError("Reshaper: shape of factor should be defined")
1102 raise ValueError("Reshaper: shape of factor should be defined")
1103
1103
1104 if nTxs:
1104 if nTxs:
1105 if nTxs < 0:
1105 if nTxs < 0:
1106 raise ValueError("nTxs should be greater than 0")
1106 raise ValueError("nTxs should be greater than 0")
1107
1107
1108 if nTxs < 1 and dataOut.nProfiles % (1./nTxs) != 0:
1108 if nTxs < 1 and dataOut.nProfiles % (1./nTxs) != 0:
1109 raise ValueError("nProfiles= %d is not divisibled by (1./nTxs) = %f" %(dataOut.nProfiles, (1./nTxs)))
1109 raise ValueError("nProfiles= %d is not divisibled by (1./nTxs) = %f" %(dataOut.nProfiles, (1./nTxs)))
1110
1110
1111 shape = [dataOut.nChannels, dataOut.nProfiles*nTxs, dataOut.nHeights/nTxs]
1111 shape = [dataOut.nChannels, dataOut.nProfiles*nTxs, dataOut.nHeights/nTxs]
1112
1112
1113 return shape, nTxs
1113 return shape, nTxs
1114
1114
1115 if len(shape) != 2 and len(shape) != 3:
1115 if len(shape) != 2 and len(shape) != 3:
1116 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))
1116 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))
1117
1117
1118 if len(shape) == 2:
1118 if len(shape) == 2:
1119 shape_tuple = [dataOut.nChannels]
1119 shape_tuple = [dataOut.nChannels]
1120 shape_tuple.extend(shape)
1120 shape_tuple.extend(shape)
1121 else:
1121 else:
1122 shape_tuple = list(shape)
1122 shape_tuple = list(shape)
1123
1123
1124 nTxs = 1.0*shape_tuple[1]/dataOut.nProfiles
1124 nTxs = 1.0*shape_tuple[1]/dataOut.nProfiles
1125
1125
1126 return shape_tuple, nTxs
1126 return shape_tuple, nTxs
1127
1127
1128 def run(self, dataOut, shape=None, nTxs=None):
1128 def run(self, dataOut, shape=None, nTxs=None):
1129
1129
1130 shape_tuple, self.__nTxs = self.__checkInputs(dataOut, shape, nTxs)
1130 shape_tuple, self.__nTxs = self.__checkInputs(dataOut, shape, nTxs)
1131
1131
1132 dataOut.flagNoData = True
1132 dataOut.flagNoData = True
1133 profileIndex = None
1133 profileIndex = None
1134
1134
1135 if dataOut.flagDataAsBlock:
1135 if dataOut.flagDataAsBlock:
1136
1136
1137 dataOut.data = numpy.reshape(dataOut.data, shape_tuple)
1137 dataOut.data = numpy.reshape(dataOut.data, shape_tuple)
1138 dataOut.flagNoData = False
1138 dataOut.flagNoData = False
1139
1139
1140 profileIndex = int(dataOut.nProfiles*self.__nTxs) - 1
1140 profileIndex = int(dataOut.nProfiles*self.__nTxs) - 1
1141
1141
1142 else:
1142 else:
1143
1143
1144 if self.__nTxs < 1:
1144 if self.__nTxs < 1:
1145
1145
1146 self.__appendProfile(dataOut, self.__nTxs)
1146 self.__appendProfile(dataOut, self.__nTxs)
1147 new_data = self.__getBuffer()
1147 new_data = self.__getBuffer()
1148
1148
1149 if new_data is not None:
1149 if new_data is not None:
1150 dataOut.data = new_data
1150 dataOut.data = new_data
1151 dataOut.flagNoData = False
1151 dataOut.flagNoData = False
1152
1152
1153 profileIndex = dataOut.profileIndex*nTxs
1153 profileIndex = dataOut.profileIndex*nTxs
1154
1154
1155 else:
1155 else:
1156 raise ValueError("nTxs should be greater than 0 and lower than 1, or use VoltageReader(..., getblock=True)")
1156 raise ValueError("nTxs should be greater than 0 and lower than 1, or use VoltageReader(..., getblock=True)")
1157
1157
1158 deltaHeight = dataOut.heightList[1] - dataOut.heightList[0]
1158 deltaHeight = dataOut.heightList[1] - dataOut.heightList[0]
1159
1159
1160 dataOut.heightList = numpy.arange(dataOut.nHeights/self.__nTxs) * deltaHeight + dataOut.heightList[0]
1160 dataOut.heightList = numpy.arange(dataOut.nHeights/self.__nTxs) * deltaHeight + dataOut.heightList[0]
1161
1161
1162 dataOut.nProfiles = int(dataOut.nProfiles*self.__nTxs)
1162 dataOut.nProfiles = int(dataOut.nProfiles*self.__nTxs)
1163
1163
1164 dataOut.profileIndex = profileIndex
1164 dataOut.profileIndex = profileIndex
1165
1165
1166 dataOut.ippSeconds /= self.__nTxs
1166 dataOut.ippSeconds /= self.__nTxs
1167
1167
1168 return dataOut
1168 return dataOut
1169
1169
1170 class SplitProfiles(Operation):
1170 class SplitProfiles(Operation):
1171
1171
1172 def __init__(self, **kwargs):
1172 def __init__(self, **kwargs):
1173
1173
1174 Operation.__init__(self, **kwargs)
1174 Operation.__init__(self, **kwargs)
1175
1175
1176 def run(self, dataOut, n):
1176 def run(self, dataOut, n):
1177
1177
1178 dataOut.flagNoData = True
1178 dataOut.flagNoData = True
1179 profileIndex = None
1179 profileIndex = None
1180
1180
1181 if dataOut.flagDataAsBlock:
1181 if dataOut.flagDataAsBlock:
1182
1182
1183 #nchannels, nprofiles, nsamples
1183 #nchannels, nprofiles, nsamples
1184 shape = dataOut.data.shape
1184 shape = dataOut.data.shape
1185
1185
1186 if shape[2] % n != 0:
1186 if shape[2] % n != 0:
1187 raise ValueError("Could not split the data, n=%d has to be multiple of %d" %(n, shape[2]))
1187 raise ValueError("Could not split the data, n=%d has to be multiple of %d" %(n, shape[2]))
1188
1188
1189 new_shape = shape[0], shape[1]*n, int(shape[2]/n)
1189 new_shape = shape[0], shape[1]*n, int(shape[2]/n)
1190
1190
1191 dataOut.data = numpy.reshape(dataOut.data, new_shape)
1191 dataOut.data = numpy.reshape(dataOut.data, new_shape)
1192 dataOut.flagNoData = False
1192 dataOut.flagNoData = False
1193
1193
1194 profileIndex = int(dataOut.nProfiles/n) - 1
1194 profileIndex = int(dataOut.nProfiles/n) - 1
1195
1195
1196 else:
1196 else:
1197
1197
1198 raise ValueError("Could not split the data when is read Profile by Profile. Use VoltageReader(..., getblock=True)")
1198 raise ValueError("Could not split the data when is read Profile by Profile. Use VoltageReader(..., getblock=True)")
1199
1199
1200 deltaHeight = dataOut.heightList[1] - dataOut.heightList[0]
1200 deltaHeight = dataOut.heightList[1] - dataOut.heightList[0]
1201
1201
1202 dataOut.heightList = numpy.arange(dataOut.nHeights/n) * deltaHeight + dataOut.heightList[0]
1202 dataOut.heightList = numpy.arange(dataOut.nHeights/n) * deltaHeight + dataOut.heightList[0]
1203
1203
1204 dataOut.nProfiles = int(dataOut.nProfiles*n)
1204 dataOut.nProfiles = int(dataOut.nProfiles*n)
1205
1205
1206 dataOut.profileIndex = profileIndex
1206 dataOut.profileIndex = profileIndex
1207
1207
1208 dataOut.ippSeconds /= n
1208 dataOut.ippSeconds /= n
1209
1209
1210 return dataOut
1210 return dataOut
1211
1211
1212 class CombineProfiles(Operation):
1212 class CombineProfiles(Operation):
1213 def __init__(self, **kwargs):
1213 def __init__(self, **kwargs):
1214
1214
1215 Operation.__init__(self, **kwargs)
1215 Operation.__init__(self, **kwargs)
1216
1216
1217 self.__remData = None
1217 self.__remData = None
1218 self.__profileIndex = 0
1218 self.__profileIndex = 0
1219
1219
1220 def run(self, dataOut, n):
1220 def run(self, dataOut, n):
1221
1221
1222 dataOut.flagNoData = True
1222 dataOut.flagNoData = True
1223 profileIndex = None
1223 profileIndex = None
1224
1224
1225 if dataOut.flagDataAsBlock:
1225 if dataOut.flagDataAsBlock:
1226
1226
1227 #nchannels, nprofiles, nsamples
1227 #nchannels, nprofiles, nsamples
1228 shape = dataOut.data.shape
1228 shape = dataOut.data.shape
1229 new_shape = shape[0], shape[1]/n, shape[2]*n
1229 new_shape = shape[0], shape[1]/n, shape[2]*n
1230
1230
1231 if shape[1] % n != 0:
1231 if shape[1] % n != 0:
1232 raise ValueError("Could not split the data, n=%d has to be multiple of %d" %(n, shape[1]))
1232 raise ValueError("Could not split the data, n=%d has to be multiple of %d" %(n, shape[1]))
1233
1233
1234 dataOut.data = numpy.reshape(dataOut.data, new_shape)
1234 dataOut.data = numpy.reshape(dataOut.data, new_shape)
1235 dataOut.flagNoData = False
1235 dataOut.flagNoData = False
1236
1236
1237 profileIndex = int(dataOut.nProfiles*n) - 1
1237 profileIndex = int(dataOut.nProfiles*n) - 1
1238
1238
1239 else:
1239 else:
1240
1240
1241 #nchannels, nsamples
1241 #nchannels, nsamples
1242 if self.__remData is None:
1242 if self.__remData is None:
1243 newData = dataOut.data
1243 newData = dataOut.data
1244 else:
1244 else:
1245 newData = numpy.concatenate((self.__remData, dataOut.data), axis=1)
1245 newData = numpy.concatenate((self.__remData, dataOut.data), axis=1)
1246
1246
1247 self.__profileIndex += 1
1247 self.__profileIndex += 1
1248
1248
1249 if self.__profileIndex < n:
1249 if self.__profileIndex < n:
1250 self.__remData = newData
1250 self.__remData = newData
1251 #continue
1251 #continue
1252 return
1252 return
1253
1253
1254 self.__profileIndex = 0
1254 self.__profileIndex = 0
1255 self.__remData = None
1255 self.__remData = None
1256
1256
1257 dataOut.data = newData
1257 dataOut.data = newData
1258 dataOut.flagNoData = False
1258 dataOut.flagNoData = False
1259
1259
1260 profileIndex = dataOut.profileIndex/n
1260 profileIndex = dataOut.profileIndex/n
1261
1261
1262
1262
1263 deltaHeight = dataOut.heightList[1] - dataOut.heightList[0]
1263 deltaHeight = dataOut.heightList[1] - dataOut.heightList[0]
1264
1264
1265 dataOut.heightList = numpy.arange(dataOut.nHeights*n) * deltaHeight + dataOut.heightList[0]
1265 dataOut.heightList = numpy.arange(dataOut.nHeights*n) * deltaHeight + dataOut.heightList[0]
1266
1266
1267 dataOut.nProfiles = int(dataOut.nProfiles/n)
1267 dataOut.nProfiles = int(dataOut.nProfiles/n)
1268
1268
1269 dataOut.profileIndex = profileIndex
1269 dataOut.profileIndex = profileIndex
1270
1270
1271 dataOut.ippSeconds *= n
1271 dataOut.ippSeconds *= n
1272
1272
1273 return dataOut
1273 return dataOut
1274
1274
1275 class PulsePairVoltage(Operation):
1275 class PulsePairVoltage(Operation):
1276 '''
1276 '''
1277 Function PulsePair(Signal Power, Velocity)
1277 Function PulsePair(Signal Power, Velocity)
1278 The real component of Lag[0] provides Intensity Information
1278 The real component of Lag[0] provides Intensity Information
1279 The imag component of Lag[1] Phase provides Velocity Information
1279 The imag component of Lag[1] Phase provides Velocity Information
1280
1280
1281 Configuration Parameters:
1281 Configuration Parameters:
1282 nPRF = Number of Several PRF
1282 nPRF = Number of Several PRF
1283 theta = Degree Azimuth angel Boundaries
1283 theta = Degree Azimuth angel Boundaries
1284
1284
1285 Input:
1285 Input:
1286 self.dataOut
1286 self.dataOut
1287 lag[N]
1287 lag[N]
1288 Affected:
1288 Affected:
1289 self.dataOut.spc
1289 self.dataOut.spc
1290 '''
1290 '''
1291 isConfig = False
1291 isConfig = False
1292 __profIndex = 0
1292 __profIndex = 0
1293 __initime = None
1293 __initime = None
1294 __lastdatatime = None
1294 __lastdatatime = None
1295 __buffer = None
1295 __buffer = None
1296 noise = None
1296 noise = None
1297 __dataReady = False
1297 __dataReady = False
1298 n = None
1298 n = None
1299 __nch = 0
1299 __nch = 0
1300 __nHeis = 0
1300 __nHeis = 0
1301 removeDC = False
1301 removeDC = False
1302 ipp = None
1302 ipp = None
1303 lambda_ = 0
1303 lambda_ = 0
1304
1304
1305 def __init__(self,**kwargs):
1305 def __init__(self,**kwargs):
1306 Operation.__init__(self,**kwargs)
1306 Operation.__init__(self,**kwargs)
1307
1307
1308 def setup(self, dataOut, n = None, removeDC=False):
1308 def setup(self, dataOut, n = None, removeDC=False):
1309 '''
1309 '''
1310 n= Numero de PRF's de entrada
1310 n= Numero de PRF's de entrada
1311 '''
1311 '''
1312 self.__initime = None
1312 self.__initime = None
1313 self.__lastdatatime = 0
1313 self.__lastdatatime = 0
1314 self.__dataReady = False
1314 self.__dataReady = False
1315 self.__buffer = 0
1315 self.__buffer = 0
1316 self.__profIndex = 0
1316 self.__profIndex = 0
1317 self.noise = None
1317 self.noise = None
1318 self.__nch = dataOut.nChannels
1318 self.__nch = dataOut.nChannels
1319 self.__nHeis = dataOut.nHeights
1319 self.__nHeis = dataOut.nHeights
1320 self.removeDC = removeDC
1320 self.removeDC = removeDC
1321 self.lambda_ = 3.0e8/(9345.0e6)
1321 self.lambda_ = 3.0e8/(9345.0e6)
1322 self.ippSec = dataOut.ippSeconds
1322 self.ippSec = dataOut.ippSeconds
1323 self.nCohInt = dataOut.nCohInt
1323 self.nCohInt = dataOut.nCohInt
1324 print("IPPseconds",dataOut.ippSeconds)
1324 print("IPPseconds",dataOut.ippSeconds)
1325
1325
1326 print("ELVALOR DE n es:", n)
1326 print("ELVALOR DE n es:", n)
1327 if n == None:
1327 if n == None:
1328 raise ValueError("n should be specified.")
1328 raise ValueError("n should be specified.")
1329
1329
1330 if n != None:
1330 if n != None:
1331 if n<2:
1331 if n<2:
1332 raise ValueError("n should be greater than 2")
1332 raise ValueError("n should be greater than 2")
1333
1333
1334 self.n = n
1334 self.n = n
1335 self.__nProf = n
1335 self.__nProf = n
1336
1336
1337 self.__buffer = numpy.zeros((dataOut.nChannels,
1337 self.__buffer = numpy.zeros((dataOut.nChannels,
1338 n,
1338 n,
1339 dataOut.nHeights),
1339 dataOut.nHeights),
1340 dtype='complex')
1340 dtype='complex')
1341 self.noise = numpy.zeros([self.__nch,self.__nHeis])
1341 #self.noise = numpy.zeros([self.__nch,self.__nHeis])
1342 for i in range(self.__nch):
1342 #for i in range(self.__nch):
1343 self.noise[i]=dataOut.getNoise(channel=i)
1343 # self.noise[i]=dataOut.getNoise(channel=i)
1344
1344
1345 def putData(self,data):
1345 def putData(self,data):
1346 '''
1346 '''
1347 Add a profile to he __buffer and increase in one the __profiel Index
1347 Add a profile to he __buffer and increase in one the __profiel Index
1348 '''
1348 '''
1349 self.__buffer[:,self.__profIndex,:]= data
1349 self.__buffer[:,self.__profIndex,:]= data
1350 self.__profIndex += 1
1350 self.__profIndex += 1
1351 return
1351 return
1352
1352
1353 def pushData(self):
1353 def pushData(self,dataOut):
1354 '''
1354 '''
1355 Return the PULSEPAIR and the profiles used in the operation
1355 Return the PULSEPAIR and the profiles used in the operation
1356 Affected : self.__profileIndex
1356 Affected : self.__profileIndex
1357 '''
1357 '''
1358
1359 if self.removeDC==True:
1358 if self.removeDC==True:
1360 mean = numpy.mean(self.__buffer,1)
1359 mean = numpy.mean(self.__buffer,1)
1361 tmp = mean.reshape(self.__nch,1,self.__nHeis)
1360 tmp = mean.reshape(self.__nch,1,self.__nHeis)
1362 dc= numpy.tile(tmp,[1,self.__nProf,1])
1361 dc= numpy.tile(tmp,[1,self.__nProf,1])
1363 self.__buffer = self.__buffer - dc
1362 self.__buffer = self.__buffer - dc
1364
1363
1365 lag_0 = numpy.sum(self.__buffer*numpy.conj(self.__buffer),1)
1364 lag_0 = numpy.sum(self.__buffer*numpy.conj(self.__buffer),1)
1366 data_intensity = lag_0/(self.n*self.nCohInt)#*self.nCohInt)
1365 data_intensity = lag_0/(self.n*self.nCohInt)#*self.nCohInt)
1367
1366
1368 pair1 = self.__buffer[:,:-1,:]*numpy.conjugate(self.__buffer[:,1:,:])
1367 pair1 = self.__buffer[:,:-1,:]*numpy.conjugate(self.__buffer[:,1:,:])
1369 lag_1 = numpy.sum(pair1,1)
1368 lag_1 = numpy.sum(pair1,1)
1370 #angle = numpy.angle(numpy.sum(pair1,1))*180/(math.pi)
1369 #angle = numpy.angle(numpy.sum(pair1,1))*180/(math.pi)
1371 data_velocity = (-1.0*self.lambda_/(4*math.pi*self.ippSec))*numpy.angle(lag_1)#self.ippSec*self.nCohInt
1370 data_velocity = (-1.0*self.lambda_/(4*math.pi*self.ippSec))*numpy.angle(lag_1)#self.ippSec*self.nCohInt
1372
1371
1372 self.noise = numpy.zeros([self.__nch,self.__nHeis])
1373 for i in range(self.__nch):
1374 self.noise[i]=dataOut.getNoise(channel=i)
1375
1373 lag_0 = lag_0.real/(self.n)
1376 lag_0 = lag_0.real/(self.n)
1374 lag_1 = lag_1/(self.n-1)
1377 lag_1 = lag_1/(self.n-1)
1375 R1 = numpy.abs(lag_1)
1378 R1 = numpy.abs(lag_1)
1376 S = (lag_0-self.noise)
1379 S = (lag_0-self.noise)
1377 #k = R1/S
1380
1378 #k = 1-k
1381 data_snrPP = S/self.noise
1379 #k =numpy.absolute(k)
1382 data_snrPP = numpy.where(data_snrPP<0,1,data_snrPP)
1380 #k =numpy.sqrt(k)
1383
1381 L = S/R1
1384 L = S/R1
1382 #print("L",L[0])
1383 L = numpy.where(L<0,1,L)
1385 L = numpy.where(L<0,1,L)
1384 L = numpy.log(L)
1386 L = numpy.log(L)
1387
1385 tmp = numpy.sqrt(numpy.absolute(L))
1388 tmp = numpy.sqrt(numpy.absolute(L))
1389
1386 data_specwidth = (self.lambda_/(2*math.sqrt(2)*math.pi*self.ippSec))*tmp*numpy.sign(L)
1390 data_specwidth = (self.lambda_/(2*math.sqrt(2)*math.pi*self.ippSec))*tmp*numpy.sign(L)
1387 #data_specwidth = (self.lambda_/(2*math.sqrt(2)*math.pi*self.ippSec))*k
1391 #data_specwidth = (self.lambda_/(2*math.sqrt(2)*math.pi*self.ippSec))*k
1388 n = self.__profIndex
1392 n = self.__profIndex
1389
1393
1390 self.__buffer = numpy.zeros((self.__nch, self.__nProf,self.__nHeis), dtype='complex')
1394 self.__buffer = numpy.zeros((self.__nch, self.__nProf,self.__nHeis), dtype='complex')
1391 self.__profIndex = 0
1395 self.__profIndex = 0
1392 return data_intensity,data_velocity,data_specwidth,n
1396 return data_intensity,data_velocity,data_snrPP,data_specwidth,n
1393
1397
1394 def pulsePairbyProfiles(self,data):
1398 def pulsePairbyProfiles(self,dataOut):
1395
1399
1396 self.__dataReady = False
1400 self.__dataReady = False
1397 data_intensity = None
1401 data_intensity = None
1398 data_velocity = None
1402 data_velocity = None
1399 data_specwidth = None
1403 data_specwidth = None
1400 self.putData(data)
1404 data_snrPP = None
1405 self.putData(data=dataOut.data)
1401 if self.__profIndex == self.n:
1406 if self.__profIndex == self.n:
1402 #self.noise = numpy.zeros([self.__nch,self.__nHeis])
1407 #self.noise = numpy.zeros([self.__nch,self.__nHeis])
1403 #for i in range(self.__nch):
1408 #for i in range(self.__nch):
1404 # self.noise[i]=data.getNoise(channel=i)
1409 # self.noise[i]=data.getNoise(channel=i)
1405 #print(self.noise.shape)
1410 #print(self.noise.shape)
1406 data_intensity, data_velocity,data_specwidth, n = self.pushData()
1411 data_intensity, data_velocity,data_snrPP,data_specwidth, n = self.pushData(dataOut=dataOut)
1407 self.__dataReady = True
1412 self.__dataReady = True
1408
1413
1409 return data_intensity, data_velocity,data_specwidth
1414 return data_intensity, data_velocity,data_snrPP,data_specwidth
1410
1415
1411 def pulsePairOp(self, data, datatime= None):
1416 def pulsePairOp(self, dataOut, datatime= None):
1412
1417
1413 if self.__initime == None:
1418 if self.__initime == None:
1414 self.__initime = datatime
1419 self.__initime = datatime
1415
1420 #print("hola")
1416 data_intensity, data_velocity,data_specwidth = self.pulsePairbyProfiles(data)
1421 data_intensity, data_velocity,data_snrPP,data_specwidth = self.pulsePairbyProfiles(dataOut)
1417 self.__lastdatatime = datatime
1422 self.__lastdatatime = datatime
1418
1423
1419 if data_intensity is None:
1424 if data_intensity is None:
1420 return None, None,None, None
1425 return None, None,None,None,None
1421
1426
1422 avgdatatime = self.__initime
1427 avgdatatime = self.__initime
1423 deltatime = datatime - self.__lastdatatime
1428 deltatime = datatime - self.__lastdatatime
1424 self.__initime = datatime
1429 self.__initime = datatime
1425
1430
1426 return data_intensity, data_velocity,data_specwidth,avgdatatime
1431 return data_intensity, data_velocity,data_snrPP,data_specwidth,avgdatatime
1427
1432
1428 def run(self, dataOut,n = None,removeDC= False, overlapping= False,**kwargs):
1433 def run(self, dataOut,n = None,removeDC= False, overlapping= False,**kwargs):
1429
1434
1430 if not self.isConfig:
1435 if not self.isConfig:
1431 self.setup(dataOut = dataOut, n = n , removeDC=removeDC , **kwargs)
1436 self.setup(dataOut = dataOut, n = n , removeDC=removeDC , **kwargs)
1432 self.isConfig = True
1437 self.isConfig = True
1433 data_intensity, data_velocity,data_specwidth, avgdatatime = self.pulsePairOp(dataOut.data, dataOut.utctime)
1438 data_intensity, data_velocity,data_snrPP,data_specwidth, avgdatatime = self.pulsePairOp(dataOut, dataOut.utctime)
1434 dataOut.flagNoData = True
1439 dataOut.flagNoData = True
1435
1440
1436 if self.__dataReady:
1441 if self.__dataReady:
1437 dataOut.nCohInt *= self.n
1442 dataOut.nCohInt *= self.n
1438 dataOut.data_intensity = data_intensity #valor para intensidad
1443 dataOut.data_intensity = data_intensity #valor para intensidad
1439 dataOut.data_velocity = data_velocity #valor para velocidad
1444 dataOut.data_velocity = data_velocity #valor para velocidad
1445 dataOut.data_snrPP = data_snrPP # valor para snr
1440 dataOut.data_specwidth = data_specwidth
1446 dataOut.data_specwidth = data_specwidth
1441 dataOut.PRFbyAngle = self.n #numero de PRF*cada angulo rotado que equivale a un tiempo.
1447 dataOut.PRFbyAngle = self.n #numero de PRF*cada angulo rotado que equivale a un tiempo.
1442 dataOut.utctime = avgdatatime
1448 dataOut.utctime = avgdatatime
1443 dataOut.flagNoData = False
1449 dataOut.flagNoData = False
1444 return dataOut
1450 return dataOut
1445
1451
1446
1452
1447 # import collections
1453 # import collections
1448 # from scipy.stats import mode
1454 # from scipy.stats import mode
1449 #
1455 #
1450 # class Synchronize(Operation):
1456 # class Synchronize(Operation):
1451 #
1457 #
1452 # isConfig = False
1458 # isConfig = False
1453 # __profIndex = 0
1459 # __profIndex = 0
1454 #
1460 #
1455 # def __init__(self, **kwargs):
1461 # def __init__(self, **kwargs):
1456 #
1462 #
1457 # Operation.__init__(self, **kwargs)
1463 # Operation.__init__(self, **kwargs)
1458 # # self.isConfig = False
1464 # # self.isConfig = False
1459 # self.__powBuffer = None
1465 # self.__powBuffer = None
1460 # self.__startIndex = 0
1466 # self.__startIndex = 0
1461 # self.__pulseFound = False
1467 # self.__pulseFound = False
1462 #
1468 #
1463 # def __findTxPulse(self, dataOut, channel=0, pulse_with = None):
1469 # def __findTxPulse(self, dataOut, channel=0, pulse_with = None):
1464 #
1470 #
1465 # #Read data
1471 # #Read data
1466 #
1472 #
1467 # powerdB = dataOut.getPower(channel = channel)
1473 # powerdB = dataOut.getPower(channel = channel)
1468 # noisedB = dataOut.getNoise(channel = channel)[0]
1474 # noisedB = dataOut.getNoise(channel = channel)[0]
1469 #
1475 #
1470 # self.__powBuffer.extend(powerdB.flatten())
1476 # self.__powBuffer.extend(powerdB.flatten())
1471 #
1477 #
1472 # dataArray = numpy.array(self.__powBuffer)
1478 # dataArray = numpy.array(self.__powBuffer)
1473 #
1479 #
1474 # filteredPower = numpy.correlate(dataArray, dataArray[0:self.__nSamples], "same")
1480 # filteredPower = numpy.correlate(dataArray, dataArray[0:self.__nSamples], "same")
1475 #
1481 #
1476 # maxValue = numpy.nanmax(filteredPower)
1482 # maxValue = numpy.nanmax(filteredPower)
1477 #
1483 #
1478 # if maxValue < noisedB + 10:
1484 # if maxValue < noisedB + 10:
1479 # #No se encuentra ningun pulso de transmision
1485 # #No se encuentra ningun pulso de transmision
1480 # return None
1486 # return None
1481 #
1487 #
1482 # maxValuesIndex = numpy.where(filteredPower > maxValue - 0.1*abs(maxValue))[0]
1488 # maxValuesIndex = numpy.where(filteredPower > maxValue - 0.1*abs(maxValue))[0]
1483 #
1489 #
1484 # if len(maxValuesIndex) < 2:
1490 # if len(maxValuesIndex) < 2:
1485 # #Solo se encontro un solo pulso de transmision de un baudio, esperando por el siguiente TX
1491 # #Solo se encontro un solo pulso de transmision de un baudio, esperando por el siguiente TX
1486 # return None
1492 # return None
1487 #
1493 #
1488 # phasedMaxValuesIndex = maxValuesIndex - self.__nSamples
1494 # phasedMaxValuesIndex = maxValuesIndex - self.__nSamples
1489 #
1495 #
1490 # #Seleccionar solo valores con un espaciamiento de nSamples
1496 # #Seleccionar solo valores con un espaciamiento de nSamples
1491 # pulseIndex = numpy.intersect1d(maxValuesIndex, phasedMaxValuesIndex)
1497 # pulseIndex = numpy.intersect1d(maxValuesIndex, phasedMaxValuesIndex)
1492 #
1498 #
1493 # if len(pulseIndex) < 2:
1499 # if len(pulseIndex) < 2:
1494 # #Solo se encontro un pulso de transmision con ancho mayor a 1
1500 # #Solo se encontro un pulso de transmision con ancho mayor a 1
1495 # return None
1501 # return None
1496 #
1502 #
1497 # spacing = pulseIndex[1:] - pulseIndex[:-1]
1503 # spacing = pulseIndex[1:] - pulseIndex[:-1]
1498 #
1504 #
1499 # #remover senales que se distancien menos de 10 unidades o muestras
1505 # #remover senales que se distancien menos de 10 unidades o muestras
1500 # #(No deberian existir IPP menor a 10 unidades)
1506 # #(No deberian existir IPP menor a 10 unidades)
1501 #
1507 #
1502 # realIndex = numpy.where(spacing > 10 )[0]
1508 # realIndex = numpy.where(spacing > 10 )[0]
1503 #
1509 #
1504 # if len(realIndex) < 2:
1510 # if len(realIndex) < 2:
1505 # #Solo se encontro un pulso de transmision con ancho mayor a 1
1511 # #Solo se encontro un pulso de transmision con ancho mayor a 1
1506 # return None
1512 # return None
1507 #
1513 #
1508 # #Eliminar pulsos anchos (deja solo la diferencia entre IPPs)
1514 # #Eliminar pulsos anchos (deja solo la diferencia entre IPPs)
1509 # realPulseIndex = pulseIndex[realIndex]
1515 # realPulseIndex = pulseIndex[realIndex]
1510 #
1516 #
1511 # period = mode(realPulseIndex[1:] - realPulseIndex[:-1])[0][0]
1517 # period = mode(realPulseIndex[1:] - realPulseIndex[:-1])[0][0]
1512 #
1518 #
1513 # print "IPP = %d samples" %period
1519 # print "IPP = %d samples" %period
1514 #
1520 #
1515 # self.__newNSamples = dataOut.nHeights #int(period)
1521 # self.__newNSamples = dataOut.nHeights #int(period)
1516 # self.__startIndex = int(realPulseIndex[0])
1522 # self.__startIndex = int(realPulseIndex[0])
1517 #
1523 #
1518 # return 1
1524 # return 1
1519 #
1525 #
1520 #
1526 #
1521 # def setup(self, nSamples, nChannels, buffer_size = 4):
1527 # def setup(self, nSamples, nChannels, buffer_size = 4):
1522 #
1528 #
1523 # self.__powBuffer = collections.deque(numpy.zeros( buffer_size*nSamples,dtype=numpy.float),
1529 # self.__powBuffer = collections.deque(numpy.zeros( buffer_size*nSamples,dtype=numpy.float),
1524 # maxlen = buffer_size*nSamples)
1530 # maxlen = buffer_size*nSamples)
1525 #
1531 #
1526 # bufferList = []
1532 # bufferList = []
1527 #
1533 #
1528 # for i in range(nChannels):
1534 # for i in range(nChannels):
1529 # bufferByChannel = collections.deque(numpy.zeros( buffer_size*nSamples, dtype=numpy.complex) + numpy.NAN,
1535 # bufferByChannel = collections.deque(numpy.zeros( buffer_size*nSamples, dtype=numpy.complex) + numpy.NAN,
1530 # maxlen = buffer_size*nSamples)
1536 # maxlen = buffer_size*nSamples)
1531 #
1537 #
1532 # bufferList.append(bufferByChannel)
1538 # bufferList.append(bufferByChannel)
1533 #
1539 #
1534 # self.__nSamples = nSamples
1540 # self.__nSamples = nSamples
1535 # self.__nChannels = nChannels
1541 # self.__nChannels = nChannels
1536 # self.__bufferList = bufferList
1542 # self.__bufferList = bufferList
1537 #
1543 #
1538 # def run(self, dataOut, channel = 0):
1544 # def run(self, dataOut, channel = 0):
1539 #
1545 #
1540 # if not self.isConfig:
1546 # if not self.isConfig:
1541 # nSamples = dataOut.nHeights
1547 # nSamples = dataOut.nHeights
1542 # nChannels = dataOut.nChannels
1548 # nChannels = dataOut.nChannels
1543 # self.setup(nSamples, nChannels)
1549 # self.setup(nSamples, nChannels)
1544 # self.isConfig = True
1550 # self.isConfig = True
1545 #
1551 #
1546 # #Append new data to internal buffer
1552 # #Append new data to internal buffer
1547 # for thisChannel in range(self.__nChannels):
1553 # for thisChannel in range(self.__nChannels):
1548 # bufferByChannel = self.__bufferList[thisChannel]
1554 # bufferByChannel = self.__bufferList[thisChannel]
1549 # bufferByChannel.extend(dataOut.data[thisChannel])
1555 # bufferByChannel.extend(dataOut.data[thisChannel])
1550 #
1556 #
1551 # if self.__pulseFound:
1557 # if self.__pulseFound:
1552 # self.__startIndex -= self.__nSamples
1558 # self.__startIndex -= self.__nSamples
1553 #
1559 #
1554 # #Finding Tx Pulse
1560 # #Finding Tx Pulse
1555 # if not self.__pulseFound:
1561 # if not self.__pulseFound:
1556 # indexFound = self.__findTxPulse(dataOut, channel)
1562 # indexFound = self.__findTxPulse(dataOut, channel)
1557 #
1563 #
1558 # if indexFound == None:
1564 # if indexFound == None:
1559 # dataOut.flagNoData = True
1565 # dataOut.flagNoData = True
1560 # return
1566 # return
1561 #
1567 #
1562 # self.__arrayBuffer = numpy.zeros((self.__nChannels, self.__newNSamples), dtype = numpy.complex)
1568 # self.__arrayBuffer = numpy.zeros((self.__nChannels, self.__newNSamples), dtype = numpy.complex)
1563 # self.__pulseFound = True
1569 # self.__pulseFound = True
1564 # self.__startIndex = indexFound
1570 # self.__startIndex = indexFound
1565 #
1571 #
1566 # #If pulse was found ...
1572 # #If pulse was found ...
1567 # for thisChannel in range(self.__nChannels):
1573 # for thisChannel in range(self.__nChannels):
1568 # bufferByChannel = self.__bufferList[thisChannel]
1574 # bufferByChannel = self.__bufferList[thisChannel]
1569 # #print self.__startIndex
1575 # #print self.__startIndex
1570 # x = numpy.array(bufferByChannel)
1576 # x = numpy.array(bufferByChannel)
1571 # self.__arrayBuffer[thisChannel] = x[self.__startIndex:self.__startIndex+self.__newNSamples]
1577 # self.__arrayBuffer[thisChannel] = x[self.__startIndex:self.__startIndex+self.__newNSamples]
1572 #
1578 #
1573 # deltaHeight = dataOut.heightList[1] - dataOut.heightList[0]
1579 # deltaHeight = dataOut.heightList[1] - dataOut.heightList[0]
1574 # dataOut.heightList = numpy.arange(self.__newNSamples)*deltaHeight
1580 # dataOut.heightList = numpy.arange(self.__newNSamples)*deltaHeight
1575 # # dataOut.ippSeconds = (self.__newNSamples / deltaHeight)/1e6
1581 # # dataOut.ippSeconds = (self.__newNSamples / deltaHeight)/1e6
1576 #
1582 #
1577 # dataOut.data = self.__arrayBuffer
1583 # dataOut.data = self.__arrayBuffer
1578 #
1584 #
1579 # self.__startIndex += self.__newNSamples
1585 # self.__startIndex += self.__newNSamples
1580 #
1586 #
1581 # return
1587 # return
General Comments 0
You need to be logged in to leave comments. Login now