@@ -1,1891 +1,1891 | |||||
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,hildebrand_sekhon |
|
5 | from schainpy.model.data.jrodata import Voltage,hildebrand_sekhon | |
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, minIndex=None, maxIndex=None): |
|
149 | def run(self, dataOut, minHei=None, maxHei=None, minIndex=None, maxIndex=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 and maxHei: |
|
167 | if minHei and maxHei: | |
168 |
|
168 | |||
169 | if (minHei < self.dataOut.heightList[0]): |
|
169 | if (minHei < self.dataOut.heightList[0]): | |
170 | minHei = self.dataOut.heightList[0] |
|
170 | minHei = self.dataOut.heightList[0] | |
171 |
|
171 | |||
172 | if (maxHei > self.dataOut.heightList[-1]): |
|
172 | if (maxHei > self.dataOut.heightList[-1]): | |
173 | maxHei = self.dataOut.heightList[-1] |
|
173 | maxHei = self.dataOut.heightList[-1] | |
174 |
|
174 | |||
175 | minIndex = 0 |
|
175 | minIndex = 0 | |
176 | maxIndex = 0 |
|
176 | maxIndex = 0 | |
177 | heights = self.dataOut.heightList |
|
177 | heights = self.dataOut.heightList | |
178 |
|
178 | |||
179 | inda = numpy.where(heights >= minHei) |
|
179 | inda = numpy.where(heights >= minHei) | |
180 | indb = numpy.where(heights <= maxHei) |
|
180 | indb = numpy.where(heights <= maxHei) | |
181 |
|
181 | |||
182 | try: |
|
182 | try: | |
183 | minIndex = inda[0][0] |
|
183 | minIndex = inda[0][0] | |
184 | except: |
|
184 | except: | |
185 | minIndex = 0 |
|
185 | minIndex = 0 | |
186 |
|
186 | |||
187 | try: |
|
187 | try: | |
188 | maxIndex = indb[0][-1] |
|
188 | maxIndex = indb[0][-1] | |
189 | except: |
|
189 | except: | |
190 | maxIndex = len(heights) |
|
190 | maxIndex = len(heights) | |
191 |
|
191 | |||
192 | self.selectHeightsByIndex(minIndex, maxIndex) |
|
192 | self.selectHeightsByIndex(minIndex, maxIndex) | |
193 |
|
193 | |||
194 | return self.dataOut |
|
194 | return self.dataOut | |
195 |
|
195 | |||
196 | def selectHeightsByIndex(self, minIndex, maxIndex): |
|
196 | def selectHeightsByIndex(self, minIndex, maxIndex): | |
197 | """ |
|
197 | """ | |
198 | Selecciona un bloque de datos en base a un grupo indices de alturas segun el rango |
|
198 | Selecciona un bloque de datos en base a un grupo indices de alturas segun el rango | |
199 | minIndex <= index <= maxIndex |
|
199 | minIndex <= index <= maxIndex | |
200 |
|
200 | |||
201 | Input: |
|
201 | Input: | |
202 | minIndex : valor de indice minimo de altura a considerar |
|
202 | minIndex : valor de indice minimo de altura a considerar | |
203 | maxIndex : valor de indice maximo de altura a considerar |
|
203 | maxIndex : valor de indice maximo de altura a considerar | |
204 |
|
204 | |||
205 | Affected: |
|
205 | Affected: | |
206 | self.dataOut.data |
|
206 | self.dataOut.data | |
207 | self.dataOut.heightList |
|
207 | self.dataOut.heightList | |
208 |
|
208 | |||
209 | Return: |
|
209 | Return: | |
210 | 1 si el metodo se ejecuto con exito caso contrario devuelve 0 |
|
210 | 1 si el metodo se ejecuto con exito caso contrario devuelve 0 | |
211 | """ |
|
211 | """ | |
212 |
|
212 | |||
213 | if self.dataOut.type == 'Voltage': |
|
213 | if self.dataOut.type == 'Voltage': | |
214 | if (minIndex < 0) or (minIndex > maxIndex): |
|
214 | if (minIndex < 0) or (minIndex > maxIndex): | |
215 | raise ValueError("Height index range (%d,%d) is not valid" % (minIndex, maxIndex)) |
|
215 | raise ValueError("Height index range (%d,%d) is not valid" % (minIndex, maxIndex)) | |
216 |
|
216 | |||
217 | if (maxIndex >= self.dataOut.nHeights): |
|
217 | if (maxIndex >= self.dataOut.nHeights): | |
218 | maxIndex = self.dataOut.nHeights |
|
218 | maxIndex = self.dataOut.nHeights | |
219 | #print("shapeeee",self.dataOut.data.shape) |
|
219 | #print("shapeeee",self.dataOut.data.shape) | |
220 | #voltage |
|
220 | #voltage | |
221 | if self.dataOut.flagDataAsBlock: |
|
221 | if self.dataOut.flagDataAsBlock: | |
222 | """ |
|
222 | """ | |
223 | Si la data es obtenida por bloques, dimension = [nChannels, nProfiles, nHeis] |
|
223 | Si la data es obtenida por bloques, dimension = [nChannels, nProfiles, nHeis] | |
224 | """ |
|
224 | """ | |
225 | data = self.dataOut.data[:,:, minIndex:maxIndex] |
|
225 | data = self.dataOut.data[:,:, minIndex:maxIndex] | |
226 | else: |
|
226 | else: | |
227 | data = self.dataOut.data[:, minIndex:maxIndex] |
|
227 | data = self.dataOut.data[:, minIndex:maxIndex] | |
228 |
|
228 | |||
229 | # firstHeight = self.dataOut.heightList[minIndex] |
|
229 | # firstHeight = self.dataOut.heightList[minIndex] | |
230 |
|
230 | |||
231 | self.dataOut.data = data |
|
231 | self.dataOut.data = data | |
232 | self.dataOut.heightList = self.dataOut.heightList[minIndex:maxIndex] |
|
232 | self.dataOut.heightList = self.dataOut.heightList[minIndex:maxIndex] | |
233 |
|
233 | |||
234 | if self.dataOut.nHeights <= 1: |
|
234 | if self.dataOut.nHeights <= 1: | |
235 | raise ValueError("selectHeights: Too few heights. Current number of heights is %d" %(self.dataOut.nHeights)) |
|
235 | raise ValueError("selectHeights: Too few heights. Current number of heights is %d" %(self.dataOut.nHeights)) | |
236 | elif self.dataOut.type == 'Spectra': |
|
236 | elif self.dataOut.type == 'Spectra': | |
237 | if (minIndex < 0) or (minIndex > maxIndex): |
|
237 | if (minIndex < 0) or (minIndex > maxIndex): | |
238 | raise ValueError("Error selecting heights: Index range (%d,%d) is not valid" % ( |
|
238 | raise ValueError("Error selecting heights: Index range (%d,%d) is not valid" % ( | |
239 | minIndex, maxIndex)) |
|
239 | minIndex, maxIndex)) | |
240 |
|
240 | |||
241 | if (maxIndex >= self.dataOut.nHeights): |
|
241 | if (maxIndex >= self.dataOut.nHeights): | |
242 | maxIndex = self.dataOut.nHeights - 1 |
|
242 | maxIndex = self.dataOut.nHeights - 1 | |
243 |
|
243 | |||
244 | # Spectra |
|
244 | # Spectra | |
245 | data_spc = self.dataOut.data_spc[:, :, minIndex:maxIndex + 1] |
|
245 | data_spc = self.dataOut.data_spc[:, :, minIndex:maxIndex + 1] | |
246 |
|
246 | |||
247 | data_cspc = None |
|
247 | data_cspc = None | |
248 | if self.dataOut.data_cspc is not None: |
|
248 | if self.dataOut.data_cspc is not None: | |
249 | data_cspc = self.dataOut.data_cspc[:, :, minIndex:maxIndex + 1] |
|
249 | data_cspc = self.dataOut.data_cspc[:, :, minIndex:maxIndex + 1] | |
250 |
|
250 | |||
251 | data_dc = None |
|
251 | data_dc = None | |
252 | if self.dataOut.data_dc is not None: |
|
252 | if self.dataOut.data_dc is not None: | |
253 | data_dc = self.dataOut.data_dc[:, minIndex:maxIndex + 1] |
|
253 | data_dc = self.dataOut.data_dc[:, minIndex:maxIndex + 1] | |
254 |
|
254 | |||
255 | self.dataOut.data_spc = data_spc |
|
255 | self.dataOut.data_spc = data_spc | |
256 | self.dataOut.data_cspc = data_cspc |
|
256 | self.dataOut.data_cspc = data_cspc | |
257 | self.dataOut.data_dc = data_dc |
|
257 | self.dataOut.data_dc = data_dc | |
258 |
|
258 | |||
259 | self.dataOut.heightList = self.dataOut.heightList[minIndex:maxIndex + 1] |
|
259 | self.dataOut.heightList = self.dataOut.heightList[minIndex:maxIndex + 1] | |
260 |
|
260 | |||
261 | return 1 |
|
261 | return 1 | |
262 |
|
262 | |||
263 |
|
263 | |||
264 | class filterByHeights(Operation): |
|
264 | class filterByHeights(Operation): | |
265 |
|
265 | |||
266 | def run(self, dataOut, window): |
|
266 | def run(self, dataOut, window): | |
267 |
|
267 | |||
268 | deltaHeight = dataOut.heightList[1] - dataOut.heightList[0] |
|
268 | deltaHeight = dataOut.heightList[1] - dataOut.heightList[0] | |
269 |
|
269 | |||
270 | if window == None: |
|
270 | if window == None: | |
271 | window = (dataOut.radarControllerHeaderObj.txA/dataOut.radarControllerHeaderObj.nBaud) / deltaHeight |
|
271 | window = (dataOut.radarControllerHeaderObj.txA/dataOut.radarControllerHeaderObj.nBaud) / deltaHeight | |
272 |
|
272 | |||
273 | newdelta = deltaHeight * window |
|
273 | newdelta = deltaHeight * window | |
274 | r = dataOut.nHeights % window |
|
274 | r = dataOut.nHeights % window | |
275 | newheights = (dataOut.nHeights-r)/window |
|
275 | newheights = (dataOut.nHeights-r)/window | |
276 |
|
276 | |||
277 | if newheights <= 1: |
|
277 | if newheights <= 1: | |
278 | raise ValueError("filterByHeights: Too few heights. Current number of heights is %d and window is %d" %(dataOut.nHeights, window)) |
|
278 | raise ValueError("filterByHeights: Too few heights. Current number of heights is %d and window is %d" %(dataOut.nHeights, window)) | |
279 |
|
279 | |||
280 | if dataOut.flagDataAsBlock: |
|
280 | if dataOut.flagDataAsBlock: | |
281 | """ |
|
281 | """ | |
282 | Si la data es obtenida por bloques, dimension = [nChannels, nProfiles, nHeis] |
|
282 | Si la data es obtenida por bloques, dimension = [nChannels, nProfiles, nHeis] | |
283 | """ |
|
283 | """ | |
284 | buffer = dataOut.data[:, :, 0:int(dataOut.nHeights-r)] |
|
284 | buffer = dataOut.data[:, :, 0:int(dataOut.nHeights-r)] | |
285 | buffer = buffer.reshape(dataOut.nChannels, dataOut.nProfiles, int(dataOut.nHeights/window), window) |
|
285 | buffer = buffer.reshape(dataOut.nChannels, dataOut.nProfiles, int(dataOut.nHeights/window), window) | |
286 | buffer = numpy.sum(buffer,3) |
|
286 | buffer = numpy.sum(buffer,3) | |
287 |
|
287 | |||
288 | else: |
|
288 | else: | |
289 | buffer = dataOut.data[:,0:int(dataOut.nHeights-r)] |
|
289 | buffer = dataOut.data[:,0:int(dataOut.nHeights-r)] | |
290 | buffer = buffer.reshape(dataOut.nChannels,int(dataOut.nHeights/window),int(window)) |
|
290 | buffer = buffer.reshape(dataOut.nChannels,int(dataOut.nHeights/window),int(window)) | |
291 | buffer = numpy.sum(buffer,2) |
|
291 | buffer = numpy.sum(buffer,2) | |
292 |
|
292 | |||
293 | dataOut.data = buffer |
|
293 | dataOut.data = buffer | |
294 | dataOut.heightList = dataOut.heightList[0] + numpy.arange( newheights )*newdelta |
|
294 | dataOut.heightList = dataOut.heightList[0] + numpy.arange( newheights )*newdelta | |
295 | dataOut.windowOfFilter = window |
|
295 | dataOut.windowOfFilter = window | |
296 |
|
296 | |||
297 | return dataOut |
|
297 | return dataOut | |
298 |
|
298 | |||
299 |
|
299 | |||
300 | class setH0(Operation): |
|
300 | class setH0(Operation): | |
301 |
|
301 | |||
302 | def run(self, dataOut, h0, deltaHeight = None): |
|
302 | def run(self, dataOut, h0, deltaHeight = None): | |
303 |
|
303 | |||
304 | if not deltaHeight: |
|
304 | if not deltaHeight: | |
305 | deltaHeight = dataOut.heightList[1] - dataOut.heightList[0] |
|
305 | deltaHeight = dataOut.heightList[1] - dataOut.heightList[0] | |
306 |
|
306 | |||
307 | nHeights = dataOut.nHeights |
|
307 | nHeights = dataOut.nHeights | |
308 |
|
308 | |||
309 | newHeiRange = h0 + numpy.arange(nHeights)*deltaHeight |
|
309 | newHeiRange = h0 + numpy.arange(nHeights)*deltaHeight | |
310 |
|
310 | |||
311 | dataOut.heightList = newHeiRange |
|
311 | dataOut.heightList = newHeiRange | |
312 | dataOut.h0 = h0 |
|
312 | dataOut.h0 = h0 | |
313 |
|
313 | |||
314 | return dataOut |
|
314 | return dataOut | |
315 |
|
315 | |||
316 |
|
316 | |||
317 | class deFlip(Operation): |
|
317 | class deFlip(Operation): | |
318 |
|
318 | |||
319 | def run(self, dataOut, channelList = []): |
|
319 | def run(self, dataOut, channelList = []): | |
320 |
|
320 | |||
321 | data = dataOut.data.copy() |
|
321 | data = dataOut.data.copy() | |
322 |
|
322 | |||
323 | if dataOut.flagDataAsBlock: |
|
323 | if dataOut.flagDataAsBlock: | |
324 | flip = self.flip |
|
324 | flip = self.flip | |
325 | profileList = list(range(dataOut.nProfiles)) |
|
325 | profileList = list(range(dataOut.nProfiles)) | |
326 |
|
326 | |||
327 | if not channelList: |
|
327 | if not channelList: | |
328 | for thisProfile in profileList: |
|
328 | for thisProfile in profileList: | |
329 | data[:,thisProfile,:] = data[:,thisProfile,:]*flip |
|
329 | data[:,thisProfile,:] = data[:,thisProfile,:]*flip | |
330 | flip *= -1.0 |
|
330 | flip *= -1.0 | |
331 | else: |
|
331 | else: | |
332 | for thisChannel in channelList: |
|
332 | for thisChannel in channelList: | |
333 | if thisChannel not in dataOut.channelList: |
|
333 | if thisChannel not in dataOut.channelList: | |
334 | continue |
|
334 | continue | |
335 |
|
335 | |||
336 | for thisProfile in profileList: |
|
336 | for thisProfile in profileList: | |
337 | data[thisChannel,thisProfile,:] = data[thisChannel,thisProfile,:]*flip |
|
337 | data[thisChannel,thisProfile,:] = data[thisChannel,thisProfile,:]*flip | |
338 | flip *= -1.0 |
|
338 | flip *= -1.0 | |
339 |
|
339 | |||
340 | self.flip = flip |
|
340 | self.flip = flip | |
341 |
|
341 | |||
342 | else: |
|
342 | else: | |
343 | if not channelList: |
|
343 | if not channelList: | |
344 | data[:,:] = data[:,:]*self.flip |
|
344 | data[:,:] = data[:,:]*self.flip | |
345 | else: |
|
345 | else: | |
346 | for thisChannel in channelList: |
|
346 | for thisChannel in channelList: | |
347 | if thisChannel not in dataOut.channelList: |
|
347 | if thisChannel not in dataOut.channelList: | |
348 | continue |
|
348 | continue | |
349 |
|
349 | |||
350 | data[thisChannel,:] = data[thisChannel,:]*self.flip |
|
350 | data[thisChannel,:] = data[thisChannel,:]*self.flip | |
351 |
|
351 | |||
352 | self.flip *= -1. |
|
352 | self.flip *= -1. | |
353 |
|
353 | |||
354 | dataOut.data = data |
|
354 | dataOut.data = data | |
355 |
|
355 | |||
356 | return dataOut |
|
356 | return dataOut | |
357 |
|
357 | |||
358 |
|
358 | |||
359 | class setAttribute(Operation): |
|
359 | class setAttribute(Operation): | |
360 | ''' |
|
360 | ''' | |
361 | Set an arbitrary attribute(s) to dataOut |
|
361 | Set an arbitrary attribute(s) to dataOut | |
362 | ''' |
|
362 | ''' | |
363 |
|
363 | |||
364 | def __init__(self): |
|
364 | def __init__(self): | |
365 |
|
365 | |||
366 | Operation.__init__(self) |
|
366 | Operation.__init__(self) | |
367 | self._ready = False |
|
367 | self._ready = False | |
368 |
|
368 | |||
369 | def run(self, dataOut, **kwargs): |
|
369 | def run(self, dataOut, **kwargs): | |
370 |
|
370 | |||
371 | for key, value in kwargs.items(): |
|
371 | for key, value in kwargs.items(): | |
372 | setattr(dataOut, key, value) |
|
372 | setattr(dataOut, key, value) | |
373 |
|
373 | |||
374 | return dataOut |
|
374 | return dataOut | |
375 |
|
375 | |||
376 |
|
376 | |||
377 | @MPDecorator |
|
377 | @MPDecorator | |
378 | class printAttribute(Operation): |
|
378 | class printAttribute(Operation): | |
379 | ''' |
|
379 | ''' | |
380 | Print an arbitrary attribute of dataOut |
|
380 | Print an arbitrary attribute of dataOut | |
381 | ''' |
|
381 | ''' | |
382 |
|
382 | |||
383 | def __init__(self): |
|
383 | def __init__(self): | |
384 |
|
384 | |||
385 | Operation.__init__(self) |
|
385 | Operation.__init__(self) | |
386 |
|
386 | |||
387 | def run(self, dataOut, attributes): |
|
387 | def run(self, dataOut, attributes): | |
388 |
|
388 | |||
389 | if isinstance(attributes, str): |
|
389 | if isinstance(attributes, str): | |
390 | attributes = [attributes] |
|
390 | attributes = [attributes] | |
391 | for attr in attributes: |
|
391 | for attr in attributes: | |
392 | if hasattr(dataOut, attr): |
|
392 | if hasattr(dataOut, attr): | |
393 | log.log(getattr(dataOut, attr), attr) |
|
393 | log.log(getattr(dataOut, attr), attr) | |
394 |
|
394 | |||
395 |
|
395 | |||
396 | class interpolateHeights(Operation): |
|
396 | class interpolateHeights(Operation): | |
397 |
|
397 | |||
398 | def run(self, dataOut, topLim, botLim): |
|
398 | def run(self, dataOut, topLim, botLim): | |
399 | #69 al 72 para julia |
|
399 | #69 al 72 para julia | |
400 | #82-84 para meteoros |
|
400 | #82-84 para meteoros | |
401 | if len(numpy.shape(dataOut.data))==2: |
|
401 | if len(numpy.shape(dataOut.data))==2: | |
402 | sampInterp = (dataOut.data[:,botLim-1] + dataOut.data[:,topLim+1])/2 |
|
402 | sampInterp = (dataOut.data[:,botLim-1] + dataOut.data[:,topLim+1])/2 | |
403 | sampInterp = numpy.transpose(numpy.tile(sampInterp,(topLim-botLim + 1,1))) |
|
403 | sampInterp = numpy.transpose(numpy.tile(sampInterp,(topLim-botLim + 1,1))) | |
404 | #dataOut.data[:,botLim:limSup+1] = sampInterp |
|
404 | #dataOut.data[:,botLim:limSup+1] = sampInterp | |
405 | dataOut.data[:,botLim:topLim+1] = sampInterp |
|
405 | dataOut.data[:,botLim:topLim+1] = sampInterp | |
406 | else: |
|
406 | else: | |
407 | nHeights = dataOut.data.shape[2] |
|
407 | nHeights = dataOut.data.shape[2] | |
408 | x = numpy.hstack((numpy.arange(botLim),numpy.arange(topLim+1,nHeights))) |
|
408 | x = numpy.hstack((numpy.arange(botLim),numpy.arange(topLim+1,nHeights))) | |
409 | y = dataOut.data[:,:,list(range(botLim))+list(range(topLim+1,nHeights))] |
|
409 | y = dataOut.data[:,:,list(range(botLim))+list(range(topLim+1,nHeights))] | |
410 | f = interpolate.interp1d(x, y, axis = 2) |
|
410 | f = interpolate.interp1d(x, y, axis = 2) | |
411 | xnew = numpy.arange(botLim,topLim+1) |
|
411 | xnew = numpy.arange(botLim,topLim+1) | |
412 | ynew = f(xnew) |
|
412 | ynew = f(xnew) | |
413 | dataOut.data[:,:,botLim:topLim+1] = ynew |
|
413 | dataOut.data[:,:,botLim:topLim+1] = ynew | |
414 |
|
414 | |||
415 | return dataOut |
|
415 | return dataOut | |
416 |
|
416 | |||
417 |
|
417 | |||
418 | class CohInt(Operation): |
|
418 | class CohInt(Operation): | |
419 |
|
419 | |||
420 | isConfig = False |
|
420 | isConfig = False | |
421 | __profIndex = 0 |
|
421 | __profIndex = 0 | |
422 | __byTime = False |
|
422 | __byTime = False | |
423 | __initime = None |
|
423 | __initime = None | |
424 | __lastdatatime = None |
|
424 | __lastdatatime = None | |
425 | __integrationtime = None |
|
425 | __integrationtime = None | |
426 | __buffer = None |
|
426 | __buffer = None | |
427 | __bufferStride = [] |
|
427 | __bufferStride = [] | |
428 | __dataReady = False |
|
428 | __dataReady = False | |
429 | __profIndexStride = 0 |
|
429 | __profIndexStride = 0 | |
430 | __dataToPutStride = False |
|
430 | __dataToPutStride = False | |
431 | n = None |
|
431 | n = None | |
432 |
|
432 | |||
433 | def __init__(self, **kwargs): |
|
433 | def __init__(self, **kwargs): | |
434 |
|
434 | |||
435 | Operation.__init__(self, **kwargs) |
|
435 | Operation.__init__(self, **kwargs) | |
436 |
|
436 | |||
437 | def setup(self, n=None, timeInterval=None, stride=None, overlapping=False, byblock=False): |
|
437 | def setup(self, n=None, timeInterval=None, stride=None, overlapping=False, byblock=False): | |
438 | """ |
|
438 | """ | |
439 | Set the parameters of the integration class. |
|
439 | Set the parameters of the integration class. | |
440 |
|
440 | |||
441 | Inputs: |
|
441 | Inputs: | |
442 |
|
442 | |||
443 | n : Number of coherent integrations |
|
443 | n : Number of coherent integrations | |
444 | timeInterval : Time of integration. If the parameter "n" is selected this one does not work |
|
444 | timeInterval : Time of integration. If the parameter "n" is selected this one does not work | |
445 | overlapping : |
|
445 | overlapping : | |
446 | """ |
|
446 | """ | |
447 |
|
447 | |||
448 | self.__initime = None |
|
448 | self.__initime = None | |
449 | self.__lastdatatime = 0 |
|
449 | self.__lastdatatime = 0 | |
450 | self.__buffer = None |
|
450 | self.__buffer = None | |
451 | self.__dataReady = False |
|
451 | self.__dataReady = False | |
452 | self.byblock = byblock |
|
452 | self.byblock = byblock | |
453 | self.stride = stride |
|
453 | self.stride = stride | |
454 |
|
454 | |||
455 | if n == None and timeInterval == None: |
|
455 | if n == None and timeInterval == None: | |
456 | raise ValueError("n or timeInterval should be specified ...") |
|
456 | raise ValueError("n or timeInterval should be specified ...") | |
457 |
|
457 | |||
458 | if n != None: |
|
458 | if n != None: | |
459 | self.n = n |
|
459 | self.n = n | |
460 | self.__byTime = False |
|
460 | self.__byTime = False | |
461 | else: |
|
461 | else: | |
462 | self.__integrationtime = timeInterval #* 60. #if (type(timeInterval)!=integer) -> change this line |
|
462 | self.__integrationtime = timeInterval #* 60. #if (type(timeInterval)!=integer) -> change this line | |
463 | self.n = 9999 |
|
463 | self.n = 9999 | |
464 | self.__byTime = True |
|
464 | self.__byTime = True | |
465 |
|
465 | |||
466 | if overlapping: |
|
466 | if overlapping: | |
467 | self.__withOverlapping = True |
|
467 | self.__withOverlapping = True | |
468 | self.__buffer = None |
|
468 | self.__buffer = None | |
469 | else: |
|
469 | else: | |
470 | self.__withOverlapping = False |
|
470 | self.__withOverlapping = False | |
471 | self.__buffer = 0 |
|
471 | self.__buffer = 0 | |
472 |
|
472 | |||
473 | self.__profIndex = 0 |
|
473 | self.__profIndex = 0 | |
474 |
|
474 | |||
475 | def putData(self, data): |
|
475 | def putData(self, data): | |
476 |
|
476 | |||
477 | """ |
|
477 | """ | |
478 | Add a profile to the __buffer and increase in one the __profileIndex |
|
478 | Add a profile to the __buffer and increase in one the __profileIndex | |
479 |
|
479 | |||
480 | """ |
|
480 | """ | |
481 |
|
481 | |||
482 | if not self.__withOverlapping: |
|
482 | if not self.__withOverlapping: | |
483 | self.__buffer += data.copy() |
|
483 | self.__buffer += data.copy() | |
484 | self.__profIndex += 1 |
|
484 | self.__profIndex += 1 | |
485 | return |
|
485 | return | |
486 |
|
486 | |||
487 | #Overlapping data |
|
487 | #Overlapping data | |
488 | nChannels, nHeis = data.shape |
|
488 | nChannels, nHeis = data.shape | |
489 | data = numpy.reshape(data, (1, nChannels, nHeis)) |
|
489 | data = numpy.reshape(data, (1, nChannels, nHeis)) | |
490 |
|
490 | |||
491 | #If the buffer is empty then it takes the data value |
|
491 | #If the buffer is empty then it takes the data value | |
492 | if self.__buffer is None: |
|
492 | if self.__buffer is None: | |
493 | self.__buffer = data |
|
493 | self.__buffer = data | |
494 | self.__profIndex += 1 |
|
494 | self.__profIndex += 1 | |
495 | return |
|
495 | return | |
496 |
|
496 | |||
497 | #If the buffer length is lower than n then stakcing the data value |
|
497 | #If the buffer length is lower than n then stakcing the data value | |
498 | if self.__profIndex < self.n: |
|
498 | if self.__profIndex < self.n: | |
499 | self.__buffer = numpy.vstack((self.__buffer, data)) |
|
499 | self.__buffer = numpy.vstack((self.__buffer, data)) | |
500 | self.__profIndex += 1 |
|
500 | self.__profIndex += 1 | |
501 | return |
|
501 | return | |
502 |
|
502 | |||
503 | #If the buffer length is equal to n then replacing the last buffer value with the data value |
|
503 | #If the buffer length is equal to n then replacing the last buffer value with the data value | |
504 | self.__buffer = numpy.roll(self.__buffer, -1, axis=0) |
|
504 | self.__buffer = numpy.roll(self.__buffer, -1, axis=0) | |
505 | self.__buffer[self.n-1] = data |
|
505 | self.__buffer[self.n-1] = data | |
506 | self.__profIndex = self.n |
|
506 | self.__profIndex = self.n | |
507 | return |
|
507 | return | |
508 |
|
508 | |||
509 |
|
509 | |||
510 | def pushData(self): |
|
510 | def pushData(self): | |
511 | """ |
|
511 | """ | |
512 | Return the sum of the last profiles and the profiles used in the sum. |
|
512 | Return the sum of the last profiles and the profiles used in the sum. | |
513 |
|
513 | |||
514 | Affected: |
|
514 | Affected: | |
515 |
|
515 | |||
516 | self.__profileIndex |
|
516 | self.__profileIndex | |
517 |
|
517 | |||
518 | """ |
|
518 | """ | |
519 |
|
519 | |||
520 | if not self.__withOverlapping: |
|
520 | if not self.__withOverlapping: | |
521 | data = self.__buffer |
|
521 | data = self.__buffer | |
522 | n = self.__profIndex |
|
522 | n = self.__profIndex | |
523 |
|
523 | |||
524 | self.__buffer = 0 |
|
524 | self.__buffer = 0 | |
525 | self.__profIndex = 0 |
|
525 | self.__profIndex = 0 | |
526 |
|
526 | |||
527 | return data, n |
|
527 | return data, n | |
528 |
|
528 | |||
529 | #Integration with Overlapping |
|
529 | #Integration with Overlapping | |
530 | data = numpy.sum(self.__buffer, axis=0) |
|
530 | data = numpy.sum(self.__buffer, axis=0) | |
531 | # print data |
|
531 | # print data | |
532 | # raise |
|
532 | # raise | |
533 | n = self.__profIndex |
|
533 | n = self.__profIndex | |
534 |
|
534 | |||
535 | return data, n |
|
535 | return data, n | |
536 |
|
536 | |||
537 | def byProfiles(self, data): |
|
537 | def byProfiles(self, data): | |
538 |
|
538 | |||
539 | self.__dataReady = False |
|
539 | self.__dataReady = False | |
540 | avgdata = None |
|
540 | avgdata = None | |
541 | # n = None |
|
541 | # n = None | |
542 | # print data |
|
542 | # print data | |
543 | # raise |
|
543 | # raise | |
544 | self.putData(data) |
|
544 | self.putData(data) | |
545 |
|
545 | |||
546 | if self.__profIndex == self.n: |
|
546 | if self.__profIndex == self.n: | |
547 | avgdata, n = self.pushData() |
|
547 | avgdata, n = self.pushData() | |
548 | self.__dataReady = True |
|
548 | self.__dataReady = True | |
549 |
|
549 | |||
550 | return avgdata |
|
550 | return avgdata | |
551 |
|
551 | |||
552 | def byTime(self, data, datatime): |
|
552 | def byTime(self, data, datatime): | |
553 |
|
553 | |||
554 | self.__dataReady = False |
|
554 | self.__dataReady = False | |
555 | avgdata = None |
|
555 | avgdata = None | |
556 | n = None |
|
556 | n = None | |
557 |
|
557 | |||
558 | self.putData(data) |
|
558 | self.putData(data) | |
559 |
|
559 | |||
560 | if (datatime - self.__initime) >= self.__integrationtime: |
|
560 | if (datatime - self.__initime) >= self.__integrationtime: | |
561 | avgdata, n = self.pushData() |
|
561 | avgdata, n = self.pushData() | |
562 | self.n = n |
|
562 | self.n = n | |
563 | self.__dataReady = True |
|
563 | self.__dataReady = True | |
564 |
|
564 | |||
565 | return avgdata |
|
565 | return avgdata | |
566 |
|
566 | |||
567 | def integrateByStride(self, data, datatime): |
|
567 | def integrateByStride(self, data, datatime): | |
568 | # print data |
|
568 | # print data | |
569 | if self.__profIndex == 0: |
|
569 | if self.__profIndex == 0: | |
570 | self.__buffer = [[data.copy(), datatime]] |
|
570 | self.__buffer = [[data.copy(), datatime]] | |
571 | else: |
|
571 | else: | |
572 | self.__buffer.append([data.copy(),datatime]) |
|
572 | self.__buffer.append([data.copy(),datatime]) | |
573 | self.__profIndex += 1 |
|
573 | self.__profIndex += 1 | |
574 | self.__dataReady = False |
|
574 | self.__dataReady = False | |
575 |
|
575 | |||
576 | if self.__profIndex == self.n * self.stride : |
|
576 | if self.__profIndex == self.n * self.stride : | |
577 | self.__dataToPutStride = True |
|
577 | self.__dataToPutStride = True | |
578 | self.__profIndexStride = 0 |
|
578 | self.__profIndexStride = 0 | |
579 | self.__profIndex = 0 |
|
579 | self.__profIndex = 0 | |
580 | self.__bufferStride = [] |
|
580 | self.__bufferStride = [] | |
581 | for i in range(self.stride): |
|
581 | for i in range(self.stride): | |
582 | current = self.__buffer[i::self.stride] |
|
582 | current = self.__buffer[i::self.stride] | |
583 | data = numpy.sum([t[0] for t in current], axis=0) |
|
583 | data = numpy.sum([t[0] for t in current], axis=0) | |
584 | avgdatatime = numpy.average([t[1] for t in current]) |
|
584 | avgdatatime = numpy.average([t[1] for t in current]) | |
585 | # print data |
|
585 | # print data | |
586 | self.__bufferStride.append((data, avgdatatime)) |
|
586 | self.__bufferStride.append((data, avgdatatime)) | |
587 |
|
587 | |||
588 | if self.__dataToPutStride: |
|
588 | if self.__dataToPutStride: | |
589 | self.__dataReady = True |
|
589 | self.__dataReady = True | |
590 | self.__profIndexStride += 1 |
|
590 | self.__profIndexStride += 1 | |
591 | if self.__profIndexStride == self.stride: |
|
591 | if self.__profIndexStride == self.stride: | |
592 | self.__dataToPutStride = False |
|
592 | self.__dataToPutStride = False | |
593 | # print self.__bufferStride[self.__profIndexStride - 1] |
|
593 | # print self.__bufferStride[self.__profIndexStride - 1] | |
594 | # raise |
|
594 | # raise | |
595 | return self.__bufferStride[self.__profIndexStride - 1] |
|
595 | return self.__bufferStride[self.__profIndexStride - 1] | |
596 |
|
596 | |||
597 |
|
597 | |||
598 | return None, None |
|
598 | return None, None | |
599 |
|
599 | |||
600 | def integrate(self, data, datatime=None): |
|
600 | def integrate(self, data, datatime=None): | |
601 |
|
601 | |||
602 | if self.__initime == None: |
|
602 | if self.__initime == None: | |
603 | self.__initime = datatime |
|
603 | self.__initime = datatime | |
604 |
|
604 | |||
605 | if self.__byTime: |
|
605 | if self.__byTime: | |
606 | avgdata = self.byTime(data, datatime) |
|
606 | avgdata = self.byTime(data, datatime) | |
607 | else: |
|
607 | else: | |
608 | avgdata = self.byProfiles(data) |
|
608 | avgdata = self.byProfiles(data) | |
609 |
|
609 | |||
610 |
|
610 | |||
611 | self.__lastdatatime = datatime |
|
611 | self.__lastdatatime = datatime | |
612 |
|
612 | |||
613 | if avgdata is None: |
|
613 | if avgdata is None: | |
614 | return None, None |
|
614 | return None, None | |
615 |
|
615 | |||
616 | avgdatatime = self.__initime |
|
616 | avgdatatime = self.__initime | |
617 |
|
617 | |||
618 | deltatime = datatime - self.__lastdatatime |
|
618 | deltatime = datatime - self.__lastdatatime | |
619 |
|
619 | |||
620 | if not self.__withOverlapping: |
|
620 | if not self.__withOverlapping: | |
621 | self.__initime = datatime |
|
621 | self.__initime = datatime | |
622 | else: |
|
622 | else: | |
623 | self.__initime += deltatime |
|
623 | self.__initime += deltatime | |
624 |
|
624 | |||
625 | return avgdata, avgdatatime |
|
625 | return avgdata, avgdatatime | |
626 |
|
626 | |||
627 | def integrateByBlock(self, dataOut): |
|
627 | def integrateByBlock(self, dataOut): | |
628 |
|
628 | |||
629 | times = int(dataOut.data.shape[1]/self.n) |
|
629 | times = int(dataOut.data.shape[1]/self.n) | |
630 | avgdata = numpy.zeros((dataOut.nChannels, times, dataOut.nHeights), dtype=numpy.complex) |
|
630 | avgdata = numpy.zeros((dataOut.nChannels, times, dataOut.nHeights), dtype=numpy.complex) | |
631 |
|
631 | |||
632 | id_min = 0 |
|
632 | id_min = 0 | |
633 | id_max = self.n |
|
633 | id_max = self.n | |
634 |
|
634 | |||
635 | for i in range(times): |
|
635 | for i in range(times): | |
636 | junk = dataOut.data[:,id_min:id_max,:] |
|
636 | junk = dataOut.data[:,id_min:id_max,:] | |
637 | avgdata[:,i,:] = junk.sum(axis=1) |
|
637 | avgdata[:,i,:] = junk.sum(axis=1) | |
638 | id_min += self.n |
|
638 | id_min += self.n | |
639 | id_max += self.n |
|
639 | id_max += self.n | |
640 |
|
640 | |||
641 | timeInterval = dataOut.ippSeconds*self.n |
|
641 | timeInterval = dataOut.ippSeconds*self.n | |
642 | avgdatatime = (times - 1) * timeInterval + dataOut.utctime |
|
642 | avgdatatime = (times - 1) * timeInterval + dataOut.utctime | |
643 | self.__dataReady = True |
|
643 | self.__dataReady = True | |
644 | return avgdata, avgdatatime |
|
644 | return avgdata, avgdatatime | |
645 |
|
645 | |||
646 | def run(self, dataOut, n=None, timeInterval=None, stride=None, overlapping=False, byblock=False, **kwargs): |
|
646 | def run(self, dataOut, n=None, timeInterval=None, stride=None, overlapping=False, byblock=False, **kwargs): | |
647 |
|
647 | |||
648 | if not self.isConfig: |
|
648 | if not self.isConfig: | |
649 | self.setup(n=n, stride=stride, timeInterval=timeInterval, overlapping=overlapping, byblock=byblock, **kwargs) |
|
649 | self.setup(n=n, stride=stride, timeInterval=timeInterval, overlapping=overlapping, byblock=byblock, **kwargs) | |
650 | self.isConfig = True |
|
650 | self.isConfig = True | |
651 |
|
651 | |||
652 | if dataOut.flagDataAsBlock: |
|
652 | if dataOut.flagDataAsBlock: | |
653 | """ |
|
653 | """ | |
654 | Si la data es leida por bloques, dimension = [nChannels, nProfiles, nHeis] |
|
654 | Si la data es leida por bloques, dimension = [nChannels, nProfiles, nHeis] | |
655 | """ |
|
655 | """ | |
656 | avgdata, avgdatatime = self.integrateByBlock(dataOut) |
|
656 | avgdata, avgdatatime = self.integrateByBlock(dataOut) | |
657 | dataOut.nProfiles /= self.n |
|
657 | dataOut.nProfiles /= self.n | |
658 | else: |
|
658 | else: | |
659 | if stride is None: |
|
659 | if stride is None: | |
660 | avgdata, avgdatatime = self.integrate(dataOut.data, dataOut.utctime) |
|
660 | avgdata, avgdatatime = self.integrate(dataOut.data, dataOut.utctime) | |
661 | else: |
|
661 | else: | |
662 | avgdata, avgdatatime = self.integrateByStride(dataOut.data, dataOut.utctime) |
|
662 | avgdata, avgdatatime = self.integrateByStride(dataOut.data, dataOut.utctime) | |
663 |
|
663 | |||
664 |
|
664 | |||
665 | # dataOut.timeInterval *= n |
|
665 | # dataOut.timeInterval *= n | |
666 | dataOut.flagNoData = True |
|
666 | dataOut.flagNoData = True | |
667 |
|
667 | |||
668 | if self.__dataReady: |
|
668 | if self.__dataReady: | |
669 | dataOut.data = avgdata |
|
669 | dataOut.data = avgdata | |
670 | if not dataOut.flagCohInt: |
|
670 | if not dataOut.flagCohInt: | |
671 | dataOut.nCohInt *= self.n |
|
671 | dataOut.nCohInt *= self.n | |
672 | dataOut.flagCohInt = True |
|
672 | dataOut.flagCohInt = True | |
673 | ####################################dataOut.utctime = avgdatatime |
|
673 | ####################################dataOut.utctime = avgdatatime | |
674 | # print avgdata, avgdatatime |
|
674 | # print avgdata, avgdatatime | |
675 | # raise |
|
675 | # raise | |
676 | # dataOut.timeInterval = dataOut.ippSeconds * dataOut.nCohInt |
|
676 | # dataOut.timeInterval = dataOut.ippSeconds * dataOut.nCohInt | |
677 | dataOut.flagNoData = False |
|
677 | dataOut.flagNoData = False | |
678 | return dataOut |
|
678 | return dataOut | |
679 |
|
679 | |||
680 | class Decoder(Operation): |
|
680 | class Decoder(Operation): | |
681 |
|
681 | |||
682 | isConfig = False |
|
682 | isConfig = False | |
683 | __profIndex = 0 |
|
683 | __profIndex = 0 | |
684 |
|
684 | |||
685 | code = None |
|
685 | code = None | |
686 |
|
686 | |||
687 | nCode = None |
|
687 | nCode = None | |
688 | nBaud = None |
|
688 | nBaud = None | |
689 |
|
689 | |||
690 | def __init__(self, **kwargs): |
|
690 | def __init__(self, **kwargs): | |
691 |
|
691 | |||
692 | Operation.__init__(self, **kwargs) |
|
692 | Operation.__init__(self, **kwargs) | |
693 |
|
693 | |||
694 | self.times = None |
|
694 | self.times = None | |
695 | self.osamp = None |
|
695 | self.osamp = None | |
696 | # self.__setValues = False |
|
696 | # self.__setValues = False | |
697 | self.isConfig = False |
|
697 | self.isConfig = False | |
698 | self.setupReq = False |
|
698 | self.setupReq = False | |
699 | def setup(self, code, osamp, dataOut): |
|
699 | def setup(self, code, osamp, dataOut): | |
700 |
|
700 | |||
701 | self.__profIndex = 0 |
|
701 | self.__profIndex = 0 | |
702 |
|
702 | |||
703 | self.code = code |
|
703 | self.code = code | |
704 |
|
704 | |||
705 | self.nCode = len(code) |
|
705 | self.nCode = len(code) | |
706 | self.nBaud = len(code[0]) |
|
706 | self.nBaud = len(code[0]) | |
707 |
|
707 | |||
708 | if (osamp != None) and (osamp >1): |
|
708 | if (osamp != None) and (osamp >1): | |
709 | self.osamp = osamp |
|
709 | self.osamp = osamp | |
710 | self.code = numpy.repeat(code, repeats=self.osamp, axis=1) |
|
710 | self.code = numpy.repeat(code, repeats=self.osamp, axis=1) | |
711 | self.nBaud = self.nBaud*self.osamp |
|
711 | self.nBaud = self.nBaud*self.osamp | |
712 |
|
712 | |||
713 | self.__nChannels = dataOut.nChannels |
|
713 | self.__nChannels = dataOut.nChannels | |
714 | self.__nProfiles = dataOut.nProfiles |
|
714 | self.__nProfiles = dataOut.nProfiles | |
715 | self.__nHeis = dataOut.nHeights |
|
715 | self.__nHeis = dataOut.nHeights | |
716 |
|
716 | |||
717 | if self.__nHeis < self.nBaud: |
|
717 | if self.__nHeis < self.nBaud: | |
718 | raise ValueError('Number of heights (%d) should be greater than number of bauds (%d)' %(self.__nHeis, self.nBaud)) |
|
718 | raise ValueError('Number of heights (%d) should be greater than number of bauds (%d)' %(self.__nHeis, self.nBaud)) | |
719 |
|
719 | |||
720 | #Frequency |
|
720 | #Frequency | |
721 | __codeBuffer = numpy.zeros((self.nCode, self.__nHeis), dtype=numpy.complex) |
|
721 | __codeBuffer = numpy.zeros((self.nCode, self.__nHeis), dtype=numpy.complex) | |
722 |
|
722 | |||
723 | __codeBuffer[:,0:self.nBaud] = self.code |
|
723 | __codeBuffer[:,0:self.nBaud] = self.code | |
724 |
|
724 | |||
725 | self.fft_code = numpy.conj(numpy.fft.fft(__codeBuffer, axis=1)) |
|
725 | self.fft_code = numpy.conj(numpy.fft.fft(__codeBuffer, axis=1)) | |
726 |
|
726 | |||
727 | if dataOut.flagDataAsBlock: |
|
727 | if dataOut.flagDataAsBlock: | |
728 |
|
728 | |||
729 | self.ndatadec = self.__nHeis #- self.nBaud + 1 |
|
729 | self.ndatadec = self.__nHeis #- self.nBaud + 1 | |
730 |
|
730 | |||
731 | self.datadecTime = numpy.zeros((self.__nChannels, self.__nProfiles, self.ndatadec), dtype=numpy.complex) |
|
731 | self.datadecTime = numpy.zeros((self.__nChannels, self.__nProfiles, self.ndatadec), dtype=numpy.complex) | |
732 |
|
732 | |||
733 | else: |
|
733 | else: | |
734 |
|
734 | |||
735 | #Time |
|
735 | #Time | |
736 | self.ndatadec = self.__nHeis #- self.nBaud + 1 |
|
736 | self.ndatadec = self.__nHeis #- self.nBaud + 1 | |
737 |
|
737 | |||
738 | self.datadecTime = numpy.zeros((self.__nChannels, self.ndatadec), dtype=numpy.complex) |
|
738 | self.datadecTime = numpy.zeros((self.__nChannels, self.ndatadec), dtype=numpy.complex) | |
739 |
|
739 | |||
740 | def __convolutionInFreq(self, data): |
|
740 | def __convolutionInFreq(self, data): | |
741 |
|
741 | |||
742 | fft_code = self.fft_code[self.__profIndex].reshape(1,-1) |
|
742 | fft_code = self.fft_code[self.__profIndex].reshape(1,-1) | |
743 |
|
743 | |||
744 | fft_data = numpy.fft.fft(data, axis=1) |
|
744 | fft_data = numpy.fft.fft(data, axis=1) | |
745 |
|
745 | |||
746 | conv = fft_data*fft_code |
|
746 | conv = fft_data*fft_code | |
747 |
|
747 | |||
748 | data = numpy.fft.ifft(conv,axis=1) |
|
748 | data = numpy.fft.ifft(conv,axis=1) | |
749 |
|
749 | |||
750 | return data |
|
750 | return data | |
751 |
|
751 | |||
752 | def __convolutionInFreqOpt(self, data): |
|
752 | def __convolutionInFreqOpt(self, data): | |
753 |
|
753 | |||
754 | raise NotImplementedError |
|
754 | raise NotImplementedError | |
755 |
|
755 | |||
756 | def __convolutionInTime(self, data): |
|
756 | def __convolutionInTime(self, data): | |
757 |
|
757 | |||
758 | code = self.code[self.__profIndex] |
|
758 | code = self.code[self.__profIndex] | |
759 | for i in range(self.__nChannels): |
|
759 | for i in range(self.__nChannels): | |
760 | self.datadecTime[i,:] = numpy.correlate(data[i,:], code, mode='full')[self.nBaud-1:] |
|
760 | self.datadecTime[i,:] = numpy.correlate(data[i,:], code, mode='full')[self.nBaud-1:] | |
761 |
|
761 | |||
762 | return self.datadecTime |
|
762 | return self.datadecTime | |
763 |
|
763 | |||
764 | def __convolutionByBlockInTime(self, data): |
|
764 | def __convolutionByBlockInTime(self, data): | |
765 |
|
765 | |||
766 | repetitions = int(self.__nProfiles / self.nCode) |
|
766 | repetitions = int(self.__nProfiles / self.nCode) | |
767 | junk = numpy.lib.stride_tricks.as_strided(self.code, (repetitions, self.code.size), (0, self.code.itemsize)) |
|
767 | junk = numpy.lib.stride_tricks.as_strided(self.code, (repetitions, self.code.size), (0, self.code.itemsize)) | |
768 | junk = junk.flatten() |
|
768 | junk = junk.flatten() | |
769 | code_block = numpy.reshape(junk, (self.nCode*repetitions, self.nBaud)) |
|
769 | code_block = numpy.reshape(junk, (self.nCode*repetitions, self.nBaud)) | |
770 | profilesList = range(self.__nProfiles) |
|
770 | profilesList = range(self.__nProfiles) | |
771 |
|
771 | |||
772 | for i in range(self.__nChannels): |
|
772 | for i in range(self.__nChannels): | |
773 | for j in profilesList: |
|
773 | for j in profilesList: | |
774 | self.datadecTime[i,j,:] = numpy.correlate(data[i,j,:], code_block[j,:], mode='full')[self.nBaud-1:] |
|
774 | self.datadecTime[i,j,:] = numpy.correlate(data[i,j,:], code_block[j,:], mode='full')[self.nBaud-1:] | |
775 | return self.datadecTime |
|
775 | return self.datadecTime | |
776 |
|
776 | |||
777 | def __convolutionByBlockInFreq(self, data): |
|
777 | def __convolutionByBlockInFreq(self, data): | |
778 |
|
778 | |||
779 | raise NotImplementedError("Decoder by frequency fro Blocks not implemented") |
|
779 | raise NotImplementedError("Decoder by frequency fro Blocks not implemented") | |
780 |
|
780 | |||
781 |
|
781 | |||
782 | fft_code = self.fft_code[self.__profIndex].reshape(1,-1) |
|
782 | fft_code = self.fft_code[self.__profIndex].reshape(1,-1) | |
783 |
|
783 | |||
784 | fft_data = numpy.fft.fft(data, axis=2) |
|
784 | fft_data = numpy.fft.fft(data, axis=2) | |
785 |
|
785 | |||
786 | conv = fft_data*fft_code |
|
786 | conv = fft_data*fft_code | |
787 |
|
787 | |||
788 | data = numpy.fft.ifft(conv,axis=2) |
|
788 | data = numpy.fft.ifft(conv,axis=2) | |
789 |
|
789 | |||
790 | return data |
|
790 | return data | |
791 |
|
791 | |||
792 |
|
792 | |||
793 | def run(self, dataOut, code=None, nCode=None, nBaud=None, mode = 0, osamp=None, times=None): |
|
793 | def run(self, dataOut, code=None, nCode=None, nBaud=None, mode = 0, osamp=None, times=None): | |
794 |
|
794 | |||
795 | if dataOut.flagDecodeData: |
|
795 | if dataOut.flagDecodeData: | |
796 | print("This data is already decoded, recoding again ...") |
|
796 | print("This data is already decoded, recoding again ...") | |
797 |
|
797 | |||
798 | if not self.isConfig: |
|
798 | if not self.isConfig: | |
799 |
|
799 | |||
800 | if code is None: |
|
800 | if code is None: | |
801 | if dataOut.code is None: |
|
801 | if dataOut.code is None: | |
802 | raise ValueError("Code could not be read from %s instance. Enter a value in Code parameter" %dataOut.type) |
|
802 | raise ValueError("Code could not be read from %s instance. Enter a value in Code parameter" %dataOut.type) | |
803 |
|
803 | |||
804 | code = dataOut.code |
|
804 | code = dataOut.code | |
805 | else: |
|
805 | else: | |
806 | code = numpy.array(code).reshape(nCode,nBaud) |
|
806 | code = numpy.array(code).reshape(nCode,nBaud) | |
807 | self.setup(code, osamp, dataOut) |
|
807 | self.setup(code, osamp, dataOut) | |
808 |
|
808 | |||
809 | self.isConfig = True |
|
809 | self.isConfig = True | |
810 |
|
810 | |||
811 | if mode == 3: |
|
811 | if mode == 3: | |
812 | sys.stderr.write("Decoder Warning: mode=%d is not valid, using mode=0\n" %mode) |
|
812 | sys.stderr.write("Decoder Warning: mode=%d is not valid, using mode=0\n" %mode) | |
813 |
|
813 | |||
814 | if times != None: |
|
814 | if times != None: | |
815 | sys.stderr.write("Decoder Warning: Argument 'times' in not used anymore\n") |
|
815 | sys.stderr.write("Decoder Warning: Argument 'times' in not used anymore\n") | |
816 |
|
816 | |||
817 | if self.code is None: |
|
817 | if self.code is None: | |
818 | print("Fail decoding: Code is not defined.") |
|
818 | print("Fail decoding: Code is not defined.") | |
819 | return |
|
819 | return | |
820 |
|
820 | |||
821 | self.__nProfiles = dataOut.nProfiles |
|
821 | self.__nProfiles = dataOut.nProfiles | |
822 | datadec = None |
|
822 | datadec = None | |
823 |
|
823 | |||
824 | if mode == 3: |
|
824 | if mode == 3: | |
825 | mode = 0 |
|
825 | mode = 0 | |
826 |
|
826 | |||
827 | if dataOut.flagDataAsBlock: |
|
827 | if dataOut.flagDataAsBlock: | |
828 | """ |
|
828 | """ | |
829 | Decoding when data have been read as block, |
|
829 | Decoding when data have been read as block, | |
830 | """ |
|
830 | """ | |
831 |
|
831 | |||
832 | if mode == 0: |
|
832 | if mode == 0: | |
833 | datadec = self.__convolutionByBlockInTime(dataOut.data) |
|
833 | datadec = self.__convolutionByBlockInTime(dataOut.data) | |
834 | if mode == 1: |
|
834 | if mode == 1: | |
835 | datadec = self.__convolutionByBlockInFreq(dataOut.data) |
|
835 | datadec = self.__convolutionByBlockInFreq(dataOut.data) | |
836 | else: |
|
836 | else: | |
837 | """ |
|
837 | """ | |
838 | Decoding when data have been read profile by profile |
|
838 | Decoding when data have been read profile by profile | |
839 | """ |
|
839 | """ | |
840 | if mode == 0: |
|
840 | if mode == 0: | |
841 | datadec = self.__convolutionInTime(dataOut.data) |
|
841 | datadec = self.__convolutionInTime(dataOut.data) | |
842 |
|
842 | |||
843 | if mode == 1: |
|
843 | if mode == 1: | |
844 | datadec = self.__convolutionInFreq(dataOut.data) |
|
844 | datadec = self.__convolutionInFreq(dataOut.data) | |
845 |
|
845 | |||
846 | if mode == 2: |
|
846 | if mode == 2: | |
847 | datadec = self.__convolutionInFreqOpt(dataOut.data) |
|
847 | datadec = self.__convolutionInFreqOpt(dataOut.data) | |
848 |
|
848 | |||
849 | if datadec is None: |
|
849 | if datadec is None: | |
850 | raise ValueError("Codification mode selected is not valid: mode=%d. Try selecting 0 or 1" %mode) |
|
850 | raise ValueError("Codification mode selected is not valid: mode=%d. Try selecting 0 or 1" %mode) | |
851 |
|
851 | |||
852 | dataOut.code = self.code |
|
852 | dataOut.code = self.code | |
853 | dataOut.nCode = self.nCode |
|
853 | dataOut.nCode = self.nCode | |
854 | dataOut.nBaud = self.nBaud |
|
854 | dataOut.nBaud = self.nBaud | |
855 |
|
855 | |||
856 | dataOut.data = datadec |
|
856 | dataOut.data = datadec | |
857 |
|
857 | |||
858 | dataOut.heightList = dataOut.heightList[0:datadec.shape[-1]] |
|
858 | dataOut.heightList = dataOut.heightList[0:datadec.shape[-1]] | |
859 |
|
859 | |||
860 | dataOut.flagDecodeData = True #asumo q la data esta decodificada |
|
860 | dataOut.flagDecodeData = True #asumo q la data esta decodificada | |
861 |
|
861 | |||
862 | if self.__profIndex == self.nCode-1: |
|
862 | if self.__profIndex == self.nCode-1: | |
863 | self.__profIndex = 0 |
|
863 | self.__profIndex = 0 | |
864 | return dataOut |
|
864 | return dataOut | |
865 |
|
865 | |||
866 | self.__profIndex += 1 |
|
866 | self.__profIndex += 1 | |
867 |
|
867 | |||
868 | return dataOut |
|
868 | return dataOut | |
869 | # dataOut.flagDeflipData = True #asumo q la data no esta sin flip |
|
869 | # dataOut.flagDeflipData = True #asumo q la data no esta sin flip | |
870 |
|
870 | |||
871 |
|
871 | |||
872 | class ProfileConcat(Operation): |
|
872 | class ProfileConcat(Operation): | |
873 |
|
873 | |||
874 | isConfig = False |
|
874 | isConfig = False | |
875 | buffer = None |
|
875 | buffer = None | |
876 |
|
876 | |||
877 | def __init__(self, **kwargs): |
|
877 | def __init__(self, **kwargs): | |
878 |
|
878 | |||
879 | Operation.__init__(self, **kwargs) |
|
879 | Operation.__init__(self, **kwargs) | |
880 | self.profileIndex = 0 |
|
880 | self.profileIndex = 0 | |
881 |
|
881 | |||
882 | def reset(self): |
|
882 | def reset(self): | |
883 | self.buffer = numpy.zeros_like(self.buffer) |
|
883 | self.buffer = numpy.zeros_like(self.buffer) | |
884 | self.start_index = 0 |
|
884 | self.start_index = 0 | |
885 | self.times = 1 |
|
885 | self.times = 1 | |
886 |
|
886 | |||
887 | def setup(self, data, m, n=1): |
|
887 | def setup(self, data, m, n=1): | |
888 | self.buffer = numpy.zeros((data.shape[0],data.shape[1]*m),dtype=type(data[0,0])) |
|
888 | self.buffer = numpy.zeros((data.shape[0],data.shape[1]*m),dtype=type(data[0,0])) | |
889 | self.nHeights = data.shape[1]#.nHeights |
|
889 | self.nHeights = data.shape[1]#.nHeights | |
890 | self.start_index = 0 |
|
890 | self.start_index = 0 | |
891 | self.times = 1 |
|
891 | self.times = 1 | |
892 |
|
892 | |||
893 | def concat(self, data): |
|
893 | def concat(self, data): | |
894 |
|
894 | |||
895 | self.buffer[:,self.start_index:self.nHeights*self.times] = data.copy() |
|
895 | self.buffer[:,self.start_index:self.nHeights*self.times] = data.copy() | |
896 | self.start_index = self.start_index + self.nHeights |
|
896 | self.start_index = self.start_index + self.nHeights | |
897 |
|
897 | |||
898 | def run(self, dataOut, m): |
|
898 | def run(self, dataOut, m): | |
899 | dataOut.flagNoData = True |
|
899 | dataOut.flagNoData = True | |
900 |
|
900 | |||
901 | if not self.isConfig: |
|
901 | if not self.isConfig: | |
902 | self.setup(dataOut.data, m, 1) |
|
902 | self.setup(dataOut.data, m, 1) | |
903 | self.isConfig = True |
|
903 | self.isConfig = True | |
904 |
|
904 | |||
905 | if dataOut.flagDataAsBlock: |
|
905 | if dataOut.flagDataAsBlock: | |
906 | raise ValueError("ProfileConcat can only be used when voltage have been read profile by profile, getBlock = False") |
|
906 | raise ValueError("ProfileConcat can only be used when voltage have been read profile by profile, getBlock = False") | |
907 |
|
907 | |||
908 | else: |
|
908 | else: | |
909 | self.concat(dataOut.data) |
|
909 | self.concat(dataOut.data) | |
910 | self.times += 1 |
|
910 | self.times += 1 | |
911 | if self.times > m: |
|
911 | if self.times > m: | |
912 | dataOut.data = self.buffer |
|
912 | dataOut.data = self.buffer | |
913 | self.reset() |
|
913 | self.reset() | |
914 | dataOut.flagNoData = False |
|
914 | dataOut.flagNoData = False | |
915 | # se deben actualizar mas propiedades del header y del objeto dataOut, por ejemplo, las alturas |
|
915 | # se deben actualizar mas propiedades del header y del objeto dataOut, por ejemplo, las alturas | |
916 | deltaHeight = dataOut.heightList[1] - dataOut.heightList[0] |
|
916 | deltaHeight = dataOut.heightList[1] - dataOut.heightList[0] | |
917 | xf = dataOut.heightList[0] + dataOut.nHeights * deltaHeight * m |
|
917 | xf = dataOut.heightList[0] + dataOut.nHeights * deltaHeight * m | |
918 | dataOut.heightList = numpy.arange(dataOut.heightList[0], xf, deltaHeight) |
|
918 | dataOut.heightList = numpy.arange(dataOut.heightList[0], xf, deltaHeight) | |
919 | dataOut.ippSeconds *= m |
|
919 | dataOut.ippSeconds *= m | |
920 | return dataOut |
|
920 | return dataOut | |
921 |
|
921 | |||
922 | class ProfileSelector(Operation): |
|
922 | class ProfileSelector(Operation): | |
923 |
|
923 | |||
924 | profileIndex = None |
|
924 | profileIndex = None | |
925 | # Tamanho total de los perfiles |
|
925 | # Tamanho total de los perfiles | |
926 | nProfiles = None |
|
926 | nProfiles = None | |
927 |
|
927 | |||
928 | def __init__(self, **kwargs): |
|
928 | def __init__(self, **kwargs): | |
929 |
|
929 | |||
930 | Operation.__init__(self, **kwargs) |
|
930 | Operation.__init__(self, **kwargs) | |
931 | self.profileIndex = 0 |
|
931 | self.profileIndex = 0 | |
932 |
|
932 | |||
933 | def incProfileIndex(self): |
|
933 | def incProfileIndex(self): | |
934 |
|
934 | |||
935 | self.profileIndex += 1 |
|
935 | self.profileIndex += 1 | |
936 |
|
936 | |||
937 | if self.profileIndex >= self.nProfiles: |
|
937 | if self.profileIndex >= self.nProfiles: | |
938 | self.profileIndex = 0 |
|
938 | self.profileIndex = 0 | |
939 |
|
939 | |||
940 | def isThisProfileInRange(self, profileIndex, minIndex, maxIndex): |
|
940 | def isThisProfileInRange(self, profileIndex, minIndex, maxIndex): | |
941 |
|
941 | |||
942 | if profileIndex < minIndex: |
|
942 | if profileIndex < minIndex: | |
943 | return False |
|
943 | return False | |
944 |
|
944 | |||
945 | if profileIndex > maxIndex: |
|
945 | if profileIndex > maxIndex: | |
946 | return False |
|
946 | return False | |
947 |
|
947 | |||
948 | return True |
|
948 | return True | |
949 |
|
949 | |||
950 | def isThisProfileInList(self, profileIndex, profileList): |
|
950 | def isThisProfileInList(self, profileIndex, profileList): | |
951 |
|
951 | |||
952 | if profileIndex not in profileList: |
|
952 | if profileIndex not in profileList: | |
953 | return False |
|
953 | return False | |
954 |
|
954 | |||
955 | return True |
|
955 | return True | |
956 |
|
956 | |||
957 | def run(self, dataOut, profileList=None, profileRangeList=None, beam=None, byblock=False, rangeList = None, nProfiles=None): |
|
957 | def run(self, dataOut, profileList=None, profileRangeList=None, beam=None, byblock=False, rangeList = None, nProfiles=None): | |
958 | #print("before",dataOut.data.shape) |
|
958 | #print("before",dataOut.data.shape) | |
959 | """ |
|
959 | """ | |
960 | ProfileSelector: |
|
960 | ProfileSelector: | |
961 |
|
961 | |||
962 | Inputs: |
|
962 | Inputs: | |
963 | profileList : Index of profiles selected. Example: profileList = (0,1,2,7,8) |
|
963 | profileList : Index of profiles selected. Example: profileList = (0,1,2,7,8) | |
964 |
|
964 | |||
965 | profileRangeList : Minimum and maximum profile indexes. Example: profileRangeList = (4, 30) |
|
965 | profileRangeList : Minimum and maximum profile indexes. Example: profileRangeList = (4, 30) | |
966 |
|
966 | |||
967 | rangeList : List of profile ranges. Example: rangeList = ((4, 30), (32, 64), (128, 256)) |
|
967 | rangeList : List of profile ranges. Example: rangeList = ((4, 30), (32, 64), (128, 256)) | |
968 |
|
968 | |||
969 | """ |
|
969 | """ | |
970 |
|
970 | |||
971 | if rangeList is not None: |
|
971 | if rangeList is not None: | |
972 | if type(rangeList[0]) not in (tuple, list): |
|
972 | if type(rangeList[0]) not in (tuple, list): | |
973 | rangeList = [rangeList] |
|
973 | rangeList = [rangeList] | |
974 |
|
974 | |||
975 | dataOut.flagNoData = True |
|
975 | dataOut.flagNoData = True | |
976 |
|
976 | |||
977 | if dataOut.flagDataAsBlock: |
|
977 | if dataOut.flagDataAsBlock: | |
978 | """ |
|
978 | """ | |
979 | data dimension = [nChannels, nProfiles, nHeis] |
|
979 | data dimension = [nChannels, nProfiles, nHeis] | |
980 | """ |
|
980 | """ | |
981 | if profileList != None: |
|
981 | if profileList != None: | |
982 | dataOut.data = dataOut.data[:,profileList,:] |
|
982 | dataOut.data = dataOut.data[:,profileList,:] | |
983 |
|
983 | |||
984 | if profileRangeList != None: |
|
984 | if profileRangeList != None: | |
985 | minIndex = profileRangeList[0] |
|
985 | minIndex = profileRangeList[0] | |
986 | maxIndex = profileRangeList[1] |
|
986 | maxIndex = profileRangeList[1] | |
987 | profileList = list(range(minIndex, maxIndex+1)) |
|
987 | profileList = list(range(minIndex, maxIndex+1)) | |
988 |
|
988 | |||
989 | dataOut.data = dataOut.data[:,minIndex:maxIndex+1,:] |
|
989 | dataOut.data = dataOut.data[:,minIndex:maxIndex+1,:] | |
990 |
|
990 | |||
991 | if rangeList != None: |
|
991 | if rangeList != None: | |
992 |
|
992 | |||
993 | profileList = [] |
|
993 | profileList = [] | |
994 |
|
994 | |||
995 | for thisRange in rangeList: |
|
995 | for thisRange in rangeList: | |
996 | minIndex = thisRange[0] |
|
996 | minIndex = thisRange[0] | |
997 | maxIndex = thisRange[1] |
|
997 | maxIndex = thisRange[1] | |
998 |
|
998 | |||
999 | profileList.extend(list(range(minIndex, maxIndex+1))) |
|
999 | profileList.extend(list(range(minIndex, maxIndex+1))) | |
1000 |
|
1000 | |||
1001 | dataOut.data = dataOut.data[:,profileList,:] |
|
1001 | dataOut.data = dataOut.data[:,profileList,:] | |
1002 |
|
1002 | |||
1003 | dataOut.nProfiles = len(profileList) |
|
1003 | dataOut.nProfiles = len(profileList) | |
1004 | dataOut.profileIndex = dataOut.nProfiles - 1 |
|
1004 | dataOut.profileIndex = dataOut.nProfiles - 1 | |
1005 | dataOut.flagNoData = False |
|
1005 | dataOut.flagNoData = False | |
1006 | #print(dataOut.data.shape) |
|
1006 | #print(dataOut.data.shape) | |
1007 | return dataOut |
|
1007 | return dataOut | |
1008 |
|
1008 | |||
1009 | """ |
|
1009 | """ | |
1010 | data dimension = [nChannels, nHeis] |
|
1010 | data dimension = [nChannels, nHeis] | |
1011 | """ |
|
1011 | """ | |
1012 |
|
1012 | |||
1013 | if profileList != None: |
|
1013 | if profileList != None: | |
1014 |
|
1014 | |||
1015 | if self.isThisProfileInList(dataOut.profileIndex, profileList): |
|
1015 | if self.isThisProfileInList(dataOut.profileIndex, profileList): | |
1016 |
|
1016 | |||
1017 | self.nProfiles = len(profileList) |
|
1017 | self.nProfiles = len(profileList) | |
1018 | dataOut.nProfiles = self.nProfiles |
|
1018 | dataOut.nProfiles = self.nProfiles | |
1019 | dataOut.profileIndex = self.profileIndex |
|
1019 | dataOut.profileIndex = self.profileIndex | |
1020 | dataOut.flagNoData = False |
|
1020 | dataOut.flagNoData = False | |
1021 |
|
1021 | |||
1022 | self.incProfileIndex() |
|
1022 | self.incProfileIndex() | |
1023 | return dataOut |
|
1023 | return dataOut | |
1024 |
|
1024 | |||
1025 | if profileRangeList != None: |
|
1025 | if profileRangeList != None: | |
1026 |
|
1026 | |||
1027 | minIndex = profileRangeList[0] |
|
1027 | minIndex = profileRangeList[0] | |
1028 | maxIndex = profileRangeList[1] |
|
1028 | maxIndex = profileRangeList[1] | |
1029 |
|
1029 | |||
1030 | if self.isThisProfileInRange(dataOut.profileIndex, minIndex, maxIndex): |
|
1030 | if self.isThisProfileInRange(dataOut.profileIndex, minIndex, maxIndex): | |
1031 |
|
1031 | |||
1032 | self.nProfiles = maxIndex - minIndex + 1 |
|
1032 | self.nProfiles = maxIndex - minIndex + 1 | |
1033 | dataOut.nProfiles = self.nProfiles |
|
1033 | dataOut.nProfiles = self.nProfiles | |
1034 | dataOut.profileIndex = self.profileIndex |
|
1034 | dataOut.profileIndex = self.profileIndex | |
1035 | dataOut.flagNoData = False |
|
1035 | dataOut.flagNoData = False | |
1036 |
|
1036 | |||
1037 | self.incProfileIndex() |
|
1037 | self.incProfileIndex() | |
1038 | return dataOut |
|
1038 | return dataOut | |
1039 |
|
1039 | |||
1040 | if rangeList != None: |
|
1040 | if rangeList != None: | |
1041 |
|
1041 | |||
1042 | nProfiles = 0 |
|
1042 | nProfiles = 0 | |
1043 |
|
1043 | |||
1044 | for thisRange in rangeList: |
|
1044 | for thisRange in rangeList: | |
1045 | minIndex = thisRange[0] |
|
1045 | minIndex = thisRange[0] | |
1046 | maxIndex = thisRange[1] |
|
1046 | maxIndex = thisRange[1] | |
1047 |
|
1047 | |||
1048 | nProfiles += maxIndex - minIndex + 1 |
|
1048 | nProfiles += maxIndex - minIndex + 1 | |
1049 |
|
1049 | |||
1050 | for thisRange in rangeList: |
|
1050 | for thisRange in rangeList: | |
1051 |
|
1051 | |||
1052 | minIndex = thisRange[0] |
|
1052 | minIndex = thisRange[0] | |
1053 | maxIndex = thisRange[1] |
|
1053 | maxIndex = thisRange[1] | |
1054 |
|
1054 | |||
1055 | if self.isThisProfileInRange(dataOut.profileIndex, minIndex, maxIndex): |
|
1055 | if self.isThisProfileInRange(dataOut.profileIndex, minIndex, maxIndex): | |
1056 |
|
1056 | |||
1057 | self.nProfiles = nProfiles |
|
1057 | self.nProfiles = nProfiles | |
1058 | dataOut.nProfiles = self.nProfiles |
|
1058 | dataOut.nProfiles = self.nProfiles | |
1059 | dataOut.profileIndex = self.profileIndex |
|
1059 | dataOut.profileIndex = self.profileIndex | |
1060 | dataOut.flagNoData = False |
|
1060 | dataOut.flagNoData = False | |
1061 |
|
1061 | |||
1062 | self.incProfileIndex() |
|
1062 | self.incProfileIndex() | |
1063 |
|
1063 | |||
1064 | break |
|
1064 | break | |
1065 |
|
1065 | |||
1066 | return dataOut |
|
1066 | return dataOut | |
1067 |
|
1067 | |||
1068 |
|
1068 | |||
1069 | if beam != None: #beam is only for AMISR data |
|
1069 | if beam != None: #beam is only for AMISR data | |
1070 | if self.isThisProfileInList(dataOut.profileIndex, dataOut.beamRangeDict[beam]): |
|
1070 | if self.isThisProfileInList(dataOut.profileIndex, dataOut.beamRangeDict[beam]): | |
1071 | dataOut.flagNoData = False |
|
1071 | dataOut.flagNoData = False | |
1072 | dataOut.profileIndex = self.profileIndex |
|
1072 | dataOut.profileIndex = self.profileIndex | |
1073 |
|
1073 | |||
1074 | self.incProfileIndex() |
|
1074 | self.incProfileIndex() | |
1075 |
|
1075 | |||
1076 | return dataOut |
|
1076 | return dataOut | |
1077 |
|
1077 | |||
1078 | raise ValueError("ProfileSelector needs profileList, profileRangeList or rangeList parameter") |
|
1078 | raise ValueError("ProfileSelector needs profileList, profileRangeList or rangeList parameter") | |
1079 |
|
1079 | |||
1080 |
|
1080 | |||
1081 | class Reshaper(Operation): |
|
1081 | class Reshaper(Operation): | |
1082 |
|
1082 | |||
1083 | def __init__(self, **kwargs): |
|
1083 | def __init__(self, **kwargs): | |
1084 |
|
1084 | |||
1085 | Operation.__init__(self, **kwargs) |
|
1085 | Operation.__init__(self, **kwargs) | |
1086 |
|
1086 | |||
1087 | self.__buffer = None |
|
1087 | self.__buffer = None | |
1088 | self.__nitems = 0 |
|
1088 | self.__nitems = 0 | |
1089 |
|
1089 | |||
1090 | def __appendProfile(self, dataOut, nTxs): |
|
1090 | def __appendProfile(self, dataOut, nTxs): | |
1091 |
|
1091 | |||
1092 | if self.__buffer is None: |
|
1092 | if self.__buffer is None: | |
1093 | shape = (dataOut.nChannels, int(dataOut.nHeights/nTxs) ) |
|
1093 | shape = (dataOut.nChannels, int(dataOut.nHeights/nTxs) ) | |
1094 | self.__buffer = numpy.empty(shape, dtype = dataOut.data.dtype) |
|
1094 | self.__buffer = numpy.empty(shape, dtype = dataOut.data.dtype) | |
1095 |
|
1095 | |||
1096 | ini = dataOut.nHeights * self.__nitems |
|
1096 | ini = dataOut.nHeights * self.__nitems | |
1097 | end = ini + dataOut.nHeights |
|
1097 | end = ini + dataOut.nHeights | |
1098 |
|
1098 | |||
1099 | self.__buffer[:, ini:end] = dataOut.data |
|
1099 | self.__buffer[:, ini:end] = dataOut.data | |
1100 |
|
1100 | |||
1101 | self.__nitems += 1 |
|
1101 | self.__nitems += 1 | |
1102 |
|
1102 | |||
1103 | return int(self.__nitems*nTxs) |
|
1103 | return int(self.__nitems*nTxs) | |
1104 |
|
1104 | |||
1105 | def __getBuffer(self): |
|
1105 | def __getBuffer(self): | |
1106 |
|
1106 | |||
1107 | if self.__nitems == int(1./self.__nTxs): |
|
1107 | if self.__nitems == int(1./self.__nTxs): | |
1108 |
|
1108 | |||
1109 | self.__nitems = 0 |
|
1109 | self.__nitems = 0 | |
1110 |
|
1110 | |||
1111 | return self.__buffer.copy() |
|
1111 | return self.__buffer.copy() | |
1112 |
|
1112 | |||
1113 | return None |
|
1113 | return None | |
1114 |
|
1114 | |||
1115 | def __checkInputs(self, dataOut, shape, nTxs): |
|
1115 | def __checkInputs(self, dataOut, shape, nTxs): | |
1116 |
|
1116 | |||
1117 | if shape is None and nTxs is None: |
|
1117 | if shape is None and nTxs is None: | |
1118 | raise ValueError("Reshaper: shape of factor should be defined") |
|
1118 | raise ValueError("Reshaper: shape of factor should be defined") | |
1119 |
|
1119 | |||
1120 | if nTxs: |
|
1120 | if nTxs: | |
1121 | if nTxs < 0: |
|
1121 | if nTxs < 0: | |
1122 | raise ValueError("nTxs should be greater than 0") |
|
1122 | raise ValueError("nTxs should be greater than 0") | |
1123 |
|
1123 | |||
1124 | if nTxs < 1 and dataOut.nProfiles % (1./nTxs) != 0: |
|
1124 | if nTxs < 1 and dataOut.nProfiles % (1./nTxs) != 0: | |
1125 | raise ValueError("nProfiles= %d is not divisibled by (1./nTxs) = %f" %(dataOut.nProfiles, (1./nTxs))) |
|
1125 | raise ValueError("nProfiles= %d is not divisibled by (1./nTxs) = %f" %(dataOut.nProfiles, (1./nTxs))) | |
1126 |
|
1126 | |||
1127 | shape = [dataOut.nChannels, dataOut.nProfiles*nTxs, dataOut.nHeights/nTxs] |
|
1127 | shape = [dataOut.nChannels, dataOut.nProfiles*nTxs, dataOut.nHeights/nTxs] | |
1128 |
|
1128 | |||
1129 | return shape, nTxs |
|
1129 | return shape, nTxs | |
1130 |
|
1130 | |||
1131 | if len(shape) != 2 and len(shape) != 3: |
|
1131 | if len(shape) != 2 and len(shape) != 3: | |
1132 | 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)) |
|
1132 | 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)) | |
1133 |
|
1133 | |||
1134 | if len(shape) == 2: |
|
1134 | if len(shape) == 2: | |
1135 | shape_tuple = [dataOut.nChannels] |
|
1135 | shape_tuple = [dataOut.nChannels] | |
1136 | shape_tuple.extend(shape) |
|
1136 | shape_tuple.extend(shape) | |
1137 | else: |
|
1137 | else: | |
1138 | shape_tuple = list(shape) |
|
1138 | shape_tuple = list(shape) | |
1139 |
|
1139 | |||
1140 | nTxs = 1.0*shape_tuple[1]/dataOut.nProfiles |
|
1140 | nTxs = 1.0*shape_tuple[1]/dataOut.nProfiles | |
1141 |
|
1141 | |||
1142 | return shape_tuple, nTxs |
|
1142 | return shape_tuple, nTxs | |
1143 |
|
1143 | |||
1144 | def run(self, dataOut, shape=None, nTxs=None): |
|
1144 | def run(self, dataOut, shape=None, nTxs=None): | |
1145 |
|
1145 | |||
1146 | shape_tuple, self.__nTxs = self.__checkInputs(dataOut, shape, nTxs) |
|
1146 | shape_tuple, self.__nTxs = self.__checkInputs(dataOut, shape, nTxs) | |
1147 |
|
1147 | |||
1148 | dataOut.flagNoData = True |
|
1148 | dataOut.flagNoData = True | |
1149 | profileIndex = None |
|
1149 | profileIndex = None | |
1150 |
|
1150 | |||
1151 | if dataOut.flagDataAsBlock: |
|
1151 | if dataOut.flagDataAsBlock: | |
1152 |
|
1152 | |||
1153 | dataOut.data = numpy.reshape(dataOut.data, shape_tuple) |
|
1153 | dataOut.data = numpy.reshape(dataOut.data, shape_tuple) | |
1154 | dataOut.flagNoData = False |
|
1154 | dataOut.flagNoData = False | |
1155 |
|
1155 | |||
1156 | profileIndex = int(dataOut.nProfiles*self.__nTxs) - 1 |
|
1156 | profileIndex = int(dataOut.nProfiles*self.__nTxs) - 1 | |
1157 |
|
1157 | |||
1158 | else: |
|
1158 | else: | |
1159 |
|
1159 | |||
1160 | if self.__nTxs < 1: |
|
1160 | if self.__nTxs < 1: | |
1161 |
|
1161 | |||
1162 | self.__appendProfile(dataOut, self.__nTxs) |
|
1162 | self.__appendProfile(dataOut, self.__nTxs) | |
1163 | new_data = self.__getBuffer() |
|
1163 | new_data = self.__getBuffer() | |
1164 |
|
1164 | |||
1165 | if new_data is not None: |
|
1165 | if new_data is not None: | |
1166 | dataOut.data = new_data |
|
1166 | dataOut.data = new_data | |
1167 | dataOut.flagNoData = False |
|
1167 | dataOut.flagNoData = False | |
1168 |
|
1168 | |||
1169 | profileIndex = dataOut.profileIndex*nTxs |
|
1169 | profileIndex = dataOut.profileIndex*nTxs | |
1170 |
|
1170 | |||
1171 | else: |
|
1171 | else: | |
1172 | raise ValueError("nTxs should be greater than 0 and lower than 1, or use VoltageReader(..., getblock=True)") |
|
1172 | raise ValueError("nTxs should be greater than 0 and lower than 1, or use VoltageReader(..., getblock=True)") | |
1173 |
|
1173 | |||
1174 | deltaHeight = dataOut.heightList[1] - dataOut.heightList[0] |
|
1174 | deltaHeight = dataOut.heightList[1] - dataOut.heightList[0] | |
1175 |
|
1175 | |||
1176 | dataOut.heightList = numpy.arange(dataOut.nHeights/self.__nTxs) * deltaHeight + dataOut.heightList[0] |
|
1176 | dataOut.heightList = numpy.arange(dataOut.nHeights/self.__nTxs) * deltaHeight + dataOut.heightList[0] | |
1177 |
|
1177 | |||
1178 | dataOut.nProfiles = int(dataOut.nProfiles*self.__nTxs) |
|
1178 | dataOut.nProfiles = int(dataOut.nProfiles*self.__nTxs) | |
1179 |
|
1179 | |||
1180 | dataOut.profileIndex = profileIndex |
|
1180 | dataOut.profileIndex = profileIndex | |
1181 |
|
1181 | |||
1182 | dataOut.ippSeconds /= self.__nTxs |
|
1182 | dataOut.ippSeconds /= self.__nTxs | |
1183 |
|
1183 | |||
1184 | return dataOut |
|
1184 | return dataOut | |
1185 |
|
1185 | |||
1186 | class SplitProfiles(Operation): |
|
1186 | class SplitProfiles(Operation): | |
1187 |
|
1187 | |||
1188 | def __init__(self, **kwargs): |
|
1188 | def __init__(self, **kwargs): | |
1189 |
|
1189 | |||
1190 | Operation.__init__(self, **kwargs) |
|
1190 | Operation.__init__(self, **kwargs) | |
1191 |
|
1191 | |||
1192 | def run(self, dataOut, n): |
|
1192 | def run(self, dataOut, n): | |
1193 |
|
1193 | |||
1194 | dataOut.flagNoData = True |
|
1194 | dataOut.flagNoData = True | |
1195 | profileIndex = None |
|
1195 | profileIndex = None | |
1196 |
|
1196 | |||
1197 | if dataOut.flagDataAsBlock: |
|
1197 | if dataOut.flagDataAsBlock: | |
1198 |
|
1198 | |||
1199 | #nchannels, nprofiles, nsamples |
|
1199 | #nchannels, nprofiles, nsamples | |
1200 | shape = dataOut.data.shape |
|
1200 | shape = dataOut.data.shape | |
1201 |
|
1201 | |||
1202 | if shape[2] % n != 0: |
|
1202 | if shape[2] % n != 0: | |
1203 | raise ValueError("Could not split the data, n=%d has to be multiple of %d" %(n, shape[2])) |
|
1203 | raise ValueError("Could not split the data, n=%d has to be multiple of %d" %(n, shape[2])) | |
1204 |
|
1204 | |||
1205 | new_shape = shape[0], shape[1]*n, int(shape[2]/n) |
|
1205 | new_shape = shape[0], shape[1]*n, int(shape[2]/n) | |
1206 |
|
1206 | |||
1207 | dataOut.data = numpy.reshape(dataOut.data, new_shape) |
|
1207 | dataOut.data = numpy.reshape(dataOut.data, new_shape) | |
1208 | dataOut.flagNoData = False |
|
1208 | dataOut.flagNoData = False | |
1209 |
|
1209 | |||
1210 | profileIndex = int(dataOut.nProfiles/n) - 1 |
|
1210 | profileIndex = int(dataOut.nProfiles/n) - 1 | |
1211 |
|
1211 | |||
1212 | else: |
|
1212 | else: | |
1213 |
|
1213 | |||
1214 | raise ValueError("Could not split the data when is read Profile by Profile. Use VoltageReader(..., getblock=True)") |
|
1214 | raise ValueError("Could not split the data when is read Profile by Profile. Use VoltageReader(..., getblock=True)") | |
1215 |
|
1215 | |||
1216 | deltaHeight = dataOut.heightList[1] - dataOut.heightList[0] |
|
1216 | deltaHeight = dataOut.heightList[1] - dataOut.heightList[0] | |
1217 |
|
1217 | |||
1218 | dataOut.heightList = numpy.arange(dataOut.nHeights/n) * deltaHeight + dataOut.heightList[0] |
|
1218 | dataOut.heightList = numpy.arange(dataOut.nHeights/n) * deltaHeight + dataOut.heightList[0] | |
1219 |
|
1219 | |||
1220 | dataOut.nProfiles = int(dataOut.nProfiles*n) |
|
1220 | dataOut.nProfiles = int(dataOut.nProfiles*n) | |
1221 |
|
1221 | |||
1222 | dataOut.profileIndex = profileIndex |
|
1222 | dataOut.profileIndex = profileIndex | |
1223 |
|
1223 | |||
1224 | dataOut.ippSeconds /= n |
|
1224 | dataOut.ippSeconds /= n | |
1225 |
|
1225 | |||
1226 | return dataOut |
|
1226 | return dataOut | |
1227 |
|
1227 | |||
1228 | class CombineProfiles(Operation): |
|
1228 | class CombineProfiles(Operation): | |
1229 | def __init__(self, **kwargs): |
|
1229 | def __init__(self, **kwargs): | |
1230 |
|
1230 | |||
1231 | Operation.__init__(self, **kwargs) |
|
1231 | Operation.__init__(self, **kwargs) | |
1232 |
|
1232 | |||
1233 | self.__remData = None |
|
1233 | self.__remData = None | |
1234 | self.__profileIndex = 0 |
|
1234 | self.__profileIndex = 0 | |
1235 |
|
1235 | |||
1236 | def run(self, dataOut, n): |
|
1236 | def run(self, dataOut, n): | |
1237 |
|
1237 | |||
1238 | dataOut.flagNoData = True |
|
1238 | dataOut.flagNoData = True | |
1239 | profileIndex = None |
|
1239 | profileIndex = None | |
1240 |
|
1240 | |||
1241 | if dataOut.flagDataAsBlock: |
|
1241 | if dataOut.flagDataAsBlock: | |
1242 |
|
1242 | |||
1243 | #nchannels, nprofiles, nsamples |
|
1243 | #nchannels, nprofiles, nsamples | |
1244 | shape = dataOut.data.shape |
|
1244 | shape = dataOut.data.shape | |
1245 | new_shape = shape[0], shape[1]/n, shape[2]*n |
|
1245 | new_shape = shape[0], shape[1]/n, shape[2]*n | |
1246 |
|
1246 | |||
1247 | if shape[1] % n != 0: |
|
1247 | if shape[1] % n != 0: | |
1248 | raise ValueError("Could not split the data, n=%d has to be multiple of %d" %(n, shape[1])) |
|
1248 | raise ValueError("Could not split the data, n=%d has to be multiple of %d" %(n, shape[1])) | |
1249 |
|
1249 | |||
1250 | dataOut.data = numpy.reshape(dataOut.data, new_shape) |
|
1250 | dataOut.data = numpy.reshape(dataOut.data, new_shape) | |
1251 | dataOut.flagNoData = False |
|
1251 | dataOut.flagNoData = False | |
1252 |
|
1252 | |||
1253 | profileIndex = int(dataOut.nProfiles*n) - 1 |
|
1253 | profileIndex = int(dataOut.nProfiles*n) - 1 | |
1254 |
|
1254 | |||
1255 | else: |
|
1255 | else: | |
1256 |
|
1256 | |||
1257 | #nchannels, nsamples |
|
1257 | #nchannels, nsamples | |
1258 | if self.__remData is None: |
|
1258 | if self.__remData is None: | |
1259 | newData = dataOut.data |
|
1259 | newData = dataOut.data | |
1260 | else: |
|
1260 | else: | |
1261 | newData = numpy.concatenate((self.__remData, dataOut.data), axis=1) |
|
1261 | newData = numpy.concatenate((self.__remData, dataOut.data), axis=1) | |
1262 |
|
1262 | |||
1263 | self.__profileIndex += 1 |
|
1263 | self.__profileIndex += 1 | |
1264 |
|
1264 | |||
1265 | if self.__profileIndex < n: |
|
1265 | if self.__profileIndex < n: | |
1266 | self.__remData = newData |
|
1266 | self.__remData = newData | |
1267 | #continue |
|
1267 | #continue | |
1268 | return |
|
1268 | return | |
1269 |
|
1269 | |||
1270 | self.__profileIndex = 0 |
|
1270 | self.__profileIndex = 0 | |
1271 | self.__remData = None |
|
1271 | self.__remData = None | |
1272 |
|
1272 | |||
1273 | dataOut.data = newData |
|
1273 | dataOut.data = newData | |
1274 | dataOut.flagNoData = False |
|
1274 | dataOut.flagNoData = False | |
1275 |
|
1275 | |||
1276 | profileIndex = dataOut.profileIndex/n |
|
1276 | profileIndex = dataOut.profileIndex/n | |
1277 |
|
1277 | |||
1278 |
|
1278 | |||
1279 | deltaHeight = dataOut.heightList[1] - dataOut.heightList[0] |
|
1279 | deltaHeight = dataOut.heightList[1] - dataOut.heightList[0] | |
1280 |
|
1280 | |||
1281 | dataOut.heightList = numpy.arange(dataOut.nHeights*n) * deltaHeight + dataOut.heightList[0] |
|
1281 | dataOut.heightList = numpy.arange(dataOut.nHeights*n) * deltaHeight + dataOut.heightList[0] | |
1282 |
|
1282 | |||
1283 | dataOut.nProfiles = int(dataOut.nProfiles/n) |
|
1283 | dataOut.nProfiles = int(dataOut.nProfiles/n) | |
1284 |
|
1284 | |||
1285 | dataOut.profileIndex = profileIndex |
|
1285 | dataOut.profileIndex = profileIndex | |
1286 |
|
1286 | |||
1287 | dataOut.ippSeconds *= n |
|
1287 | dataOut.ippSeconds *= n | |
1288 |
|
1288 | |||
1289 | return dataOut |
|
1289 | return dataOut | |
1290 |
|
1290 | |||
1291 | class PulsePair(Operation): |
|
1291 | class PulsePair(Operation): | |
1292 | ''' |
|
1292 | ''' | |
1293 | Function PulsePair(Signal Power, Velocity) |
|
1293 | Function PulsePair(Signal Power, Velocity) | |
1294 | The real component of Lag[0] provides Intensity Information |
|
1294 | The real component of Lag[0] provides Intensity Information | |
1295 | The imag component of Lag[1] Phase provides Velocity Information |
|
1295 | The imag component of Lag[1] Phase provides Velocity Information | |
1296 |
|
1296 | |||
1297 | Configuration Parameters: |
|
1297 | Configuration Parameters: | |
1298 | nPRF = Number of Several PRF |
|
1298 | nPRF = Number of Several PRF | |
1299 | theta = Degree Azimuth angel Boundaries |
|
1299 | theta = Degree Azimuth angel Boundaries | |
1300 |
|
1300 | |||
1301 | Input: |
|
1301 | Input: | |
1302 | self.dataOut |
|
1302 | self.dataOut | |
1303 | lag[N] |
|
1303 | lag[N] | |
1304 | Affected: |
|
1304 | Affected: | |
1305 | self.dataOut.spc |
|
1305 | self.dataOut.spc | |
1306 | ''' |
|
1306 | ''' | |
1307 | isConfig = False |
|
1307 | isConfig = False | |
1308 | __profIndex = 0 |
|
1308 | __profIndex = 0 | |
1309 | __initime = None |
|
1309 | __initime = None | |
1310 | __lastdatatime = None |
|
1310 | __lastdatatime = None | |
1311 | __buffer = None |
|
1311 | __buffer = None | |
1312 | noise = None |
|
1312 | noise = None | |
1313 | __dataReady = False |
|
1313 | __dataReady = False | |
1314 | n = None |
|
1314 | n = None | |
1315 | __nch = 0 |
|
1315 | __nch = 0 | |
1316 | __nHeis = 0 |
|
1316 | __nHeis = 0 | |
1317 | removeDC = False |
|
1317 | removeDC = False | |
1318 | ipp = None |
|
1318 | ipp = None | |
1319 | lambda_ = 0 |
|
1319 | lambda_ = 0 | |
1320 |
|
1320 | |||
1321 | def __init__(self,**kwargs): |
|
1321 | def __init__(self,**kwargs): | |
1322 | Operation.__init__(self,**kwargs) |
|
1322 | Operation.__init__(self,**kwargs) | |
1323 |
|
1323 | |||
1324 | def setup(self, dataOut, n = None, removeDC=False): |
|
1324 | def setup(self, dataOut, n = None, removeDC=False): | |
1325 | ''' |
|
1325 | ''' | |
1326 | n= Numero de PRF's de entrada |
|
1326 | n= Numero de PRF's de entrada | |
1327 | ''' |
|
1327 | ''' | |
1328 | self.__initime = None |
|
1328 | self.__initime = None | |
1329 | ####print("[INICIO]-setup del METODO PULSE PAIR") |
|
1329 | ####print("[INICIO]-setup del METODO PULSE PAIR") | |
1330 | self.__lastdatatime = 0 |
|
1330 | self.__lastdatatime = 0 | |
1331 | self.__dataReady = False |
|
1331 | self.__dataReady = False | |
1332 | self.__buffer = 0 |
|
1332 | self.__buffer = 0 | |
1333 | self.__profIndex = 0 |
|
1333 | self.__profIndex = 0 | |
1334 | self.noise = None |
|
1334 | self.noise = None | |
1335 | self.__nch = dataOut.nChannels |
|
1335 | self.__nch = dataOut.nChannels | |
1336 | self.__nHeis = dataOut.nHeights |
|
1336 | self.__nHeis = dataOut.nHeights | |
1337 | self.removeDC = removeDC |
|
1337 | self.removeDC = removeDC | |
1338 | self.lambda_ = 3.0e8/(9345.0e6) |
|
1338 | self.lambda_ = 3.0e8/(9345.0e6) | |
1339 | self.ippSec = dataOut.ippSeconds |
|
1339 | self.ippSec = dataOut.ippSeconds | |
1340 | self.nCohInt = dataOut.nCohInt |
|
1340 | self.nCohInt = dataOut.nCohInt | |
1341 | ####print("IPPseconds",dataOut.ippSeconds) |
|
1341 | ####print("IPPseconds",dataOut.ippSeconds) | |
1342 | ####print("ELVALOR DE n es:", n) |
|
1342 | ####print("ELVALOR DE n es:", n) | |
1343 | if n == None: |
|
1343 | if n == None: | |
1344 | raise ValueError("n should be specified.") |
|
1344 | raise ValueError("n should be specified.") | |
1345 |
|
1345 | |||
1346 | if n != None: |
|
1346 | if n != None: | |
1347 | if n<2: |
|
1347 | if n<2: | |
1348 | raise ValueError("n should be greater than 2") |
|
1348 | raise ValueError("n should be greater than 2") | |
1349 |
|
1349 | |||
1350 | self.n = n |
|
1350 | self.n = n | |
1351 | self.__nProf = n |
|
1351 | self.__nProf = n | |
1352 |
|
1352 | |||
1353 | self.__buffer = numpy.zeros((dataOut.nChannels, |
|
1353 | self.__buffer = numpy.zeros((dataOut.nChannels, | |
1354 | n, |
|
1354 | n, | |
1355 | dataOut.nHeights), |
|
1355 | dataOut.nHeights), | |
1356 | dtype='complex') |
|
1356 | dtype='complex') | |
1357 |
|
1357 | |||
1358 | def putData(self,data): |
|
1358 | def putData(self,data): | |
1359 | ''' |
|
1359 | ''' | |
1360 | Add a profile to he __buffer and increase in one the __profiel Index |
|
1360 | Add a profile to he __buffer and increase in one the __profiel Index | |
1361 | ''' |
|
1361 | ''' | |
1362 | self.__buffer[:,self.__profIndex,:]= data |
|
1362 | self.__buffer[:,self.__profIndex,:]= data | |
1363 | self.__profIndex += 1 |
|
1363 | self.__profIndex += 1 | |
1364 | return |
|
1364 | return | |
1365 |
|
1365 | |||
1366 | def pushData(self,dataOut): |
|
1366 | def pushData(self,dataOut): | |
1367 | ''' |
|
1367 | ''' | |
1368 | Return the PULSEPAIR and the profiles used in the operation |
|
1368 | Return the PULSEPAIR and the profiles used in the operation | |
1369 | Affected : self.__profileIndex |
|
1369 | Affected : self.__profileIndex | |
1370 | ''' |
|
1370 | ''' | |
1371 | #----------------- Remove DC----------------------------------- |
|
1371 | #----------------- Remove DC----------------------------------- | |
1372 | if self.removeDC==True: |
|
1372 | if self.removeDC==True: | |
1373 | mean = numpy.mean(self.__buffer,1) |
|
1373 | mean = numpy.mean(self.__buffer,1) | |
1374 | tmp = mean.reshape(self.__nch,1,self.__nHeis) |
|
1374 | tmp = mean.reshape(self.__nch,1,self.__nHeis) | |
1375 | dc= numpy.tile(tmp,[1,self.__nProf,1]) |
|
1375 | dc= numpy.tile(tmp,[1,self.__nProf,1]) | |
1376 | self.__buffer = self.__buffer - dc |
|
1376 | self.__buffer = self.__buffer - dc | |
1377 | #------------------Calculo de Potencia ------------------------ |
|
1377 | #------------------Calculo de Potencia ------------------------ | |
1378 | pair0 = self.__buffer*numpy.conj(self.__buffer) |
|
1378 | pair0 = self.__buffer*numpy.conj(self.__buffer) | |
1379 | pair0 = pair0.real |
|
1379 | pair0 = pair0.real | |
1380 | lag_0 = numpy.sum(pair0,1) |
|
1380 | lag_0 = numpy.sum(pair0,1) | |
1381 | #-----------------Calculo de Cscp------------------------------ New |
|
1381 | #-----------------Calculo de Cscp------------------------------ New | |
1382 | cspc_pair01 = self.__buffer[0]*self.__buffer[1] |
|
1382 | cspc_pair01 = self.__buffer[0]*self.__buffer[1] | |
1383 | #------------------Calculo de Ruido x canal-------------------- |
|
1383 | #------------------Calculo de Ruido x canal-------------------- | |
1384 | self.noise = numpy.zeros(self.__nch) |
|
1384 | self.noise = numpy.zeros(self.__nch) | |
1385 | for i in range(self.__nch): |
|
1385 | for i in range(self.__nch): | |
1386 | daux = numpy.sort(pair0[i,:,:],axis= None) |
|
1386 | daux = numpy.sort(pair0[i,:,:],axis= None) | |
1387 | self.noise[i]=hildebrand_sekhon( daux ,self.nCohInt) |
|
1387 | self.noise[i]=hildebrand_sekhon( daux ,self.nCohInt) | |
1388 |
|
1388 | |||
1389 | self.noise = self.noise.reshape(self.__nch,1) |
|
1389 | self.noise = self.noise.reshape(self.__nch,1) | |
1390 | self.noise = numpy.tile(self.noise,[1,self.__nHeis]) |
|
1390 | self.noise = numpy.tile(self.noise,[1,self.__nHeis]) | |
1391 | noise_buffer = self.noise.reshape(self.__nch,1,self.__nHeis) |
|
1391 | noise_buffer = self.noise.reshape(self.__nch,1,self.__nHeis) | |
1392 | noise_buffer = numpy.tile(noise_buffer,[1,self.__nProf,1]) |
|
1392 | noise_buffer = numpy.tile(noise_buffer,[1,self.__nProf,1]) | |
1393 | #------------------ Potencia recibida= P , Potencia senal = S , Ruido= N-- |
|
1393 | #------------------ Potencia recibida= P , Potencia senal = S , Ruido= N-- | |
1394 | #------------------ P= S+N ,P=lag_0/N --------------------------------- |
|
1394 | #------------------ P= S+N ,P=lag_0/N --------------------------------- | |
1395 | #-------------------- Power -------------------------------------------------- |
|
1395 | #-------------------- Power -------------------------------------------------- | |
1396 | data_power = lag_0/(self.n*self.nCohInt) |
|
1396 | data_power = lag_0/(self.n*self.nCohInt) | |
1397 | #--------------------CCF------------------------------------------------------ |
|
1397 | #--------------------CCF------------------------------------------------------ | |
1398 | data_ccf =numpy.sum(cspc_pair01,axis=0)/(self.n*self.nCohInt) |
|
1398 | data_ccf =numpy.sum(cspc_pair01,axis=0)/(self.n*self.nCohInt) | |
1399 | #------------------ Senal -------------------------------------------------- |
|
1399 | #------------------ Senal -------------------------------------------------- | |
1400 | data_intensity = pair0 - noise_buffer |
|
1400 | data_intensity = pair0 - noise_buffer | |
1401 | data_intensity = numpy.sum(data_intensity,axis=1)*(self.n*self.nCohInt)#*self.nCohInt) |
|
1401 | data_intensity = numpy.sum(data_intensity,axis=1)*(self.n*self.nCohInt)#*self.nCohInt) | |
1402 | #data_intensity = (lag_0-self.noise*self.n)*(self.n*self.nCohInt) |
|
1402 | #data_intensity = (lag_0-self.noise*self.n)*(self.n*self.nCohInt) | |
1403 | for i in range(self.__nch): |
|
1403 | for i in range(self.__nch): | |
1404 | for j in range(self.__nHeis): |
|
1404 | for j in range(self.__nHeis): | |
1405 | if data_intensity[i][j] < 0: |
|
1405 | if data_intensity[i][j] < 0: | |
1406 | data_intensity[i][j] = numpy.min(numpy.absolute(data_intensity[i][j])) |
|
1406 | data_intensity[i][j] = numpy.min(numpy.absolute(data_intensity[i][j])) | |
1407 |
|
1407 | |||
1408 | #----------------- Calculo de Frecuencia y Velocidad doppler-------- |
|
1408 | #----------------- Calculo de Frecuencia y Velocidad doppler-------- | |
1409 | pair1 = self.__buffer[:,:-1,:]*numpy.conjugate(self.__buffer[:,1:,:]) |
|
1409 | pair1 = self.__buffer[:,:-1,:]*numpy.conjugate(self.__buffer[:,1:,:]) | |
1410 | lag_1 = numpy.sum(pair1,1) |
|
1410 | lag_1 = numpy.sum(pair1,1) | |
1411 | data_freq = (-1/(2.0*math.pi*self.ippSec*self.nCohInt))*numpy.angle(lag_1) |
|
1411 | data_freq = (-1/(2.0*math.pi*self.ippSec*self.nCohInt))*numpy.angle(lag_1) | |
1412 | data_velocity = (self.lambda_/2.0)*data_freq |
|
1412 | data_velocity = (self.lambda_/2.0)*data_freq | |
1413 |
|
1413 | |||
1414 | #---------------- Potencia promedio estimada de la Senal----------- |
|
1414 | #---------------- Potencia promedio estimada de la Senal----------- | |
1415 | lag_0 = lag_0/self.n |
|
1415 | lag_0 = lag_0/self.n | |
1416 | S = lag_0-self.noise |
|
1416 | S = lag_0-self.noise | |
1417 |
|
1417 | |||
1418 | #---------------- Frecuencia Doppler promedio --------------------- |
|
1418 | #---------------- Frecuencia Doppler promedio --------------------- | |
1419 | lag_1 = lag_1/((self.n-1)*(pwcode)) |
|
1419 | lag_1 = lag_1/((self.n-1)*(pwcode)) | |
1420 | R1 = numpy.abs(lag_1) |
|
1420 | R1 = numpy.abs(lag_1) | |
1421 |
|
1421 | |||
1422 | #---------------- Calculo del SNR---------------------------------- |
|
1422 | #---------------- Calculo del SNR---------------------------------- | |
1423 | data_snrPP = S/self.noise |
|
1423 | data_snrPP = S/self.noise | |
1424 | for i in range(self.__nch): |
|
1424 | for i in range(self.__nch): | |
1425 | for j in range(self.__nHeis): |
|
1425 | for j in range(self.__nHeis): | |
1426 | if data_snrPP[i][j] < 1.e-20: |
|
1426 | if data_snrPP[i][j] < 1.e-20: | |
1427 | data_snrPP[i][j] = 1.e-20 |
|
1427 | data_snrPP[i][j] = 1.e-20 | |
1428 |
|
1428 | |||
1429 | #----------------- Calculo del ancho espectral ---------------------- |
|
1429 | #----------------- Calculo del ancho espectral ---------------------- | |
1430 | L = S/R1 |
|
1430 | L = S/R1 | |
1431 | L = numpy.where(L<0,1,L) |
|
1431 | L = numpy.where(L<0,1,L) | |
1432 | L = numpy.log(L) |
|
1432 | L = numpy.log(L) | |
1433 | tmp = numpy.sqrt(numpy.absolute(L)) |
|
1433 | tmp = numpy.sqrt(numpy.absolute(L)) | |
1434 | data_specwidth = (self.lambda_/(2*math.sqrt(2)*math.pi*self.ippSec*self.nCohInt))*tmp*numpy.sign(L) |
|
1434 | data_specwidth = (self.lambda_/(2*math.sqrt(2)*math.pi*self.ippSec*self.nCohInt))*tmp*numpy.sign(L) | |
1435 | n = self.__profIndex |
|
1435 | n = self.__profIndex | |
1436 |
|
1436 | |||
1437 | self.__buffer = numpy.zeros((self.__nch, self.__nProf,self.__nHeis), dtype='complex') |
|
1437 | self.__buffer = numpy.zeros((self.__nch, self.__nProf,self.__nHeis), dtype='complex') | |
1438 | self.__profIndex = 0 |
|
1438 | self.__profIndex = 0 | |
1439 | return data_power,data_intensity,data_velocity,data_snrPP,data_specwidth,data_ccf,n |
|
1439 | return data_power,data_intensity,data_velocity,data_snrPP,data_specwidth,data_ccf,n | |
1440 |
|
1440 | |||
1441 |
|
1441 | |||
1442 | def pulsePairbyProfiles(self,dataOut): |
|
1442 | def pulsePairbyProfiles(self,dataOut): | |
1443 |
|
1443 | |||
1444 | self.__dataReady = False |
|
1444 | self.__dataReady = False | |
1445 | data_power = None |
|
1445 | data_power = None | |
1446 | data_intensity = None |
|
1446 | data_intensity = None | |
1447 | data_velocity = None |
|
1447 | data_velocity = None | |
1448 | data_specwidth = None |
|
1448 | data_specwidth = None | |
1449 | data_snrPP = None |
|
1449 | data_snrPP = None | |
1450 | data_ccf = None |
|
1450 | data_ccf = None | |
1451 | self.putData(data=dataOut.data) |
|
1451 | self.putData(data=dataOut.data) | |
1452 | if self.__profIndex == self.n: |
|
1452 | if self.__profIndex == self.n: | |
1453 | data_power,data_intensity, data_velocity,data_snrPP,data_specwidth,data_ccf, n = self.pushData(dataOut=dataOut) |
|
1453 | data_power,data_intensity, data_velocity,data_snrPP,data_specwidth,data_ccf, n = self.pushData(dataOut=dataOut) | |
1454 | self.__dataReady = True |
|
1454 | self.__dataReady = True | |
1455 |
|
1455 | |||
1456 | return data_power, data_intensity, data_velocity, data_snrPP,data_specwidth,data_ccf |
|
1456 | return data_power, data_intensity, data_velocity, data_snrPP,data_specwidth,data_ccf | |
1457 |
|
1457 | |||
1458 |
|
1458 | |||
1459 | def pulsePairOp(self, dataOut, datatime= None): |
|
1459 | def pulsePairOp(self, dataOut, datatime= None): | |
1460 |
|
1460 | |||
1461 | if self.__initime == None: |
|
1461 | if self.__initime == None: | |
1462 | self.__initime = datatime |
|
1462 | self.__initime = datatime | |
1463 | data_power, data_intensity, data_velocity, data_snrPP,data_specwidth,data_ccf = self.pulsePairbyProfiles(dataOut) |
|
1463 | data_power, data_intensity, data_velocity, data_snrPP,data_specwidth,data_ccf = self.pulsePairbyProfiles(dataOut) | |
1464 | self.__lastdatatime = datatime |
|
1464 | self.__lastdatatime = datatime | |
1465 |
|
1465 | |||
1466 | if data_power is None: |
|
1466 | if data_power is None: | |
1467 | return None, None, None,None,None,None,None |
|
1467 | return None, None, None,None,None,None,None | |
1468 |
|
1468 | |||
1469 | avgdatatime = self.__initime |
|
1469 | avgdatatime = self.__initime | |
1470 | deltatime = datatime - self.__lastdatatime |
|
1470 | deltatime = datatime - self.__lastdatatime | |
1471 | self.__initime = datatime |
|
1471 | self.__initime = datatime | |
1472 |
|
1472 | |||
1473 | return data_power, data_intensity, data_velocity, data_snrPP,data_specwidth,data_ccf, avgdatatime |
|
1473 | return data_power, data_intensity, data_velocity, data_snrPP,data_specwidth,data_ccf, avgdatatime | |
1474 |
|
1474 | |||
1475 | def run(self, dataOut,n = None,removeDC= False, overlapping= False,**kwargs): |
|
1475 | def run(self, dataOut,n = None,removeDC= False, overlapping= False,**kwargs): | |
1476 | #print("hey") |
|
1476 | #print("hey") | |
1477 | #print(dataOut.data.shape) |
|
1477 | #print(dataOut.data.shape) | |
1478 | #exit(1) |
|
1478 | #exit(1) | |
1479 | #print(self.__profIndex) |
|
1479 | #print(self.__profIndex) | |
1480 | if not self.isConfig: |
|
1480 | if not self.isConfig: | |
1481 | self.setup(dataOut = dataOut, n = n , removeDC=removeDC , **kwargs) |
|
1481 | self.setup(dataOut = dataOut, n = n , removeDC=removeDC , **kwargs) | |
1482 | self.isConfig = True |
|
1482 | self.isConfig = True | |
1483 | data_power, data_intensity, data_velocity,data_snrPP,data_specwidth,data_ccf, avgdatatime = self.pulsePairOp(dataOut, dataOut.utctime) |
|
1483 | data_power, data_intensity, data_velocity,data_snrPP,data_specwidth,data_ccf, avgdatatime = self.pulsePairOp(dataOut, dataOut.utctime) | |
1484 | dataOut.flagNoData = True |
|
1484 | dataOut.flagNoData = True | |
1485 |
|
1485 | |||
1486 | if self.__dataReady: |
|
1486 | if self.__dataReady: | |
1487 | ###print("READY ----------------------------------") |
|
1487 | ###print("READY ----------------------------------") | |
1488 | dataOut.nCohInt *= self.n |
|
1488 | dataOut.nCohInt *= self.n | |
1489 | dataOut.dataPP_POW = data_intensity # S |
|
1489 | dataOut.dataPP_POW = data_intensity # S | |
1490 | dataOut.dataPP_POWER = data_power # P valor que corresponde a POTENCIA MOMENTO |
|
1490 | dataOut.dataPP_POWER = data_power # P valor que corresponde a POTENCIA MOMENTO | |
1491 | dataOut.dataPP_DOP = data_velocity |
|
1491 | dataOut.dataPP_DOP = data_velocity | |
1492 | dataOut.dataPP_SNR = data_snrPP |
|
1492 | dataOut.dataPP_SNR = data_snrPP | |
1493 | dataOut.dataPP_WIDTH = data_specwidth |
|
1493 | dataOut.dataPP_WIDTH = data_specwidth | |
1494 | dataOut.dataPP_CCF = data_ccf |
|
1494 | dataOut.dataPP_CCF = data_ccf | |
1495 | dataOut.PRFbyAngle = self.n #numero de PRF*cada angulo rotado que equivale a un tiempo. |
|
1495 | dataOut.PRFbyAngle = self.n #numero de PRF*cada angulo rotado que equivale a un tiempo. | |
1496 | dataOut.nProfiles = int(dataOut.nProfiles/n) |
|
1496 | dataOut.nProfiles = int(dataOut.nProfiles/n) | |
1497 | dataOut.utctime = avgdatatime |
|
1497 | dataOut.utctime = avgdatatime | |
1498 | dataOut.flagNoData = False |
|
1498 | dataOut.flagNoData = False | |
1499 | return dataOut |
|
1499 | return dataOut | |
1500 |
|
1500 | |||
1501 | class PulsePair_vRF(Operation): |
|
1501 | class PulsePair_vRF(Operation): | |
1502 | ''' |
|
1502 | ''' | |
1503 | Function PulsePair(Signal Power, Velocity) |
|
1503 | Function PulsePair(Signal Power, Velocity) | |
1504 | The real component of Lag[0] provides Intensity Information |
|
1504 | The real component of Lag[0] provides Intensity Information | |
1505 | The imag component of Lag[1] Phase provides Velocity Information |
|
1505 | The imag component of Lag[1] Phase provides Velocity Information | |
1506 |
|
1506 | |||
1507 | Configuration Parameters: |
|
1507 | Configuration Parameters: | |
1508 | nPRF = Number of Several PRF |
|
1508 | nPRF = Number of Several PRF | |
1509 | theta = Degree Azimuth angel Boundaries |
|
1509 | theta = Degree Azimuth angel Boundaries | |
1510 |
|
1510 | |||
1511 | Input: |
|
1511 | Input: | |
1512 | self.dataOut |
|
1512 | self.dataOut | |
1513 | lag[N] |
|
1513 | lag[N] | |
1514 | Affected: |
|
1514 | Affected: | |
1515 | self.dataOut.spc |
|
1515 | self.dataOut.spc | |
1516 | ''' |
|
1516 | ''' | |
1517 | isConfig = False |
|
1517 | isConfig = False | |
1518 | __profIndex = 0 |
|
1518 | __profIndex = 0 | |
1519 | __initime = None |
|
1519 | __initime = None | |
1520 | __lastdatatime = None |
|
1520 | __lastdatatime = None | |
1521 | __buffer = None |
|
1521 | __buffer = None | |
1522 | noise = None |
|
1522 | noise = None | |
1523 | __dataReady = False |
|
1523 | __dataReady = False | |
1524 | n = None |
|
1524 | n = None | |
1525 | __nch = 0 |
|
1525 | __nch = 0 | |
1526 | __nHeis = 0 |
|
1526 | __nHeis = 0 | |
1527 | removeDC = False |
|
1527 | removeDC = False | |
1528 | ipp = None |
|
1528 | ipp = None | |
1529 | lambda_ = 0 |
|
1529 | lambda_ = 0 | |
1530 |
|
1530 | |||
1531 | def __init__(self,**kwargs): |
|
1531 | def __init__(self,**kwargs): | |
1532 | Operation.__init__(self,**kwargs) |
|
1532 | Operation.__init__(self,**kwargs) | |
1533 |
|
1533 | |||
1534 | def setup(self, dataOut, n = None, removeDC=False): |
|
1534 | def setup(self, dataOut, n = None, removeDC=False): | |
1535 | ''' |
|
1535 | ''' | |
1536 | n= Numero de PRF's de entrada |
|
1536 | n= Numero de PRF's de entrada | |
1537 | ''' |
|
1537 | ''' | |
1538 | self.__initime = None |
|
1538 | self.__initime = None | |
1539 | ####print("[INICIO]-setup del METODO PULSE PAIR") |
|
1539 | ####print("[INICIO]-setup del METODO PULSE PAIR") | |
1540 | self.__lastdatatime = 0 |
|
1540 | self.__lastdatatime = 0 | |
1541 | self.__dataReady = False |
|
1541 | self.__dataReady = False | |
1542 | self.__buffer = 0 |
|
1542 | self.__buffer = 0 | |
1543 | self.__profIndex = 0 |
|
1543 | self.__profIndex = 0 | |
1544 | self.noise = None |
|
1544 | self.noise = None | |
1545 | self.__nch = dataOut.nChannels |
|
1545 | self.__nch = dataOut.nChannels | |
1546 | self.__nHeis = dataOut.nHeights |
|
1546 | self.__nHeis = dataOut.nHeights | |
1547 | self.removeDC = removeDC |
|
1547 | self.removeDC = removeDC | |
1548 | self.lambda_ = 3.0e8/(9345.0e6) |
|
1548 | self.lambda_ = 3.0e8/(9345.0e6) | |
1549 | self.ippSec = dataOut.ippSeconds |
|
1549 | self.ippSec = dataOut.ippSeconds | |
1550 | self.nCohInt = dataOut.nCohInt |
|
1550 | self.nCohInt = dataOut.nCohInt | |
1551 | ####print("IPPseconds",dataOut.ippSeconds) |
|
1551 | ####print("IPPseconds",dataOut.ippSeconds) | |
1552 | ####print("ELVALOR DE n es:", n) |
|
1552 | ####print("ELVALOR DE n es:", n) | |
1553 | if n == None: |
|
1553 | if n == None: | |
1554 | raise ValueError("n should be specified.") |
|
1554 | raise ValueError("n should be specified.") | |
1555 |
|
1555 | |||
1556 | if n != None: |
|
1556 | if n != None: | |
1557 | if n<2: |
|
1557 | if n<2: | |
1558 | raise ValueError("n should be greater than 2") |
|
1558 | raise ValueError("n should be greater than 2") | |
1559 |
|
1559 | |||
1560 | self.n = n |
|
1560 | self.n = n | |
1561 | self.__nProf = n |
|
1561 | self.__nProf = n | |
1562 |
|
1562 | |||
1563 | self.__buffer = numpy.zeros((dataOut.nChannels, |
|
1563 | self.__buffer = numpy.zeros((dataOut.nChannels, | |
1564 | n, |
|
1564 | n, | |
1565 | dataOut.nHeights), |
|
1565 | dataOut.nHeights), | |
1566 | dtype='complex') |
|
1566 | dtype='complex') | |
1567 |
|
1567 | |||
1568 | def putData(self,data): |
|
1568 | def putData(self,data): | |
1569 | ''' |
|
1569 | ''' | |
1570 | Add a profile to he __buffer and increase in one the __profiel Index |
|
1570 | Add a profile to he __buffer and increase in one the __profiel Index | |
1571 | ''' |
|
1571 | ''' | |
1572 | self.__buffer[:,self.__profIndex,:]= data |
|
1572 | self.__buffer[:,self.__profIndex,:]= data | |
1573 | self.__profIndex += 1 |
|
1573 | self.__profIndex += 1 | |
1574 | return |
|
1574 | return | |
1575 |
|
1575 | |||
1576 | def putDataByBlock(self,data,n): |
|
1576 | def putDataByBlock(self,data,n): | |
1577 | ''' |
|
1577 | ''' | |
1578 | Add a profile to he __buffer and increase in one the __profiel Index |
|
1578 | Add a profile to he __buffer and increase in one the __profiel Index | |
1579 | ''' |
|
1579 | ''' | |
1580 | self.__buffer[:]= data |
|
1580 | self.__buffer[:]= data | |
1581 | self.__profIndex = n |
|
1581 | self.__profIndex = n | |
1582 | return |
|
1582 | return | |
1583 |
|
1583 | |||
1584 | def pushData(self,dataOut): |
|
1584 | def pushData(self,dataOut): | |
1585 | ''' |
|
1585 | ''' | |
1586 | Return the PULSEPAIR and the profiles used in the operation |
|
1586 | Return the PULSEPAIR and the profiles used in the operation | |
1587 | Affected : self.__profileIndex |
|
1587 | Affected : self.__profileIndex | |
1588 | NOTA: |
|
1588 | NOTA: | |
1589 | 1.) Calculo de Potencia |
|
1589 | 1.) Calculo de Potencia | |
1590 | PdBm = 10 *log10(10*(I**2 + Q**2)) Unidades dBm |
|
1590 | PdBm = 10 *log10(10*(I**2 + Q**2)) Unidades dBm | |
1591 | self.__buffer = I + Qj |
|
1591 | self.__buffer = I + Qj | |
1592 |
|
1592 | |||
1593 | 2.) Data decodificada |
|
1593 | 2.) Data decodificada | |
1594 | Se toma como referencia el factor estimado en jrodata.py y se adiciona |
|
1594 | Se toma como referencia el factor estimado en jrodata.py y se adiciona | |
1595 | en PulsePair solo pwcode. |
|
1595 | en PulsePair solo pwcode. | |
1596 | if self.flagDecodeData: |
|
1596 | if self.flagDecodeData: | |
1597 | pwcode = numpy.sum(self.code[0]**2) |
|
1597 | pwcode = numpy.sum(self.code[0]**2) | |
1598 | normFactor = self.nProfiles * self.nIncohInt * self.nCohInt * pwcode * self.windowOfFilter |
|
1598 | normFactor = self.nProfiles * self.nIncohInt * self.nCohInt * pwcode * self.windowOfFilter | |
1599 | 3.) hildebrand_sekhon |
|
1599 | 3.) hildebrand_sekhon | |
1600 | Se pasa el arreglo de Potencia pair0 que contiene canales perfiles y altura dividiendole entre el |
|
1600 | Se pasa el arreglo de Potencia pair0 que contiene canales perfiles y altura dividiendole entre el | |
1601 | factor pwcode. |
|
1601 | factor pwcode. | |
1602 | 4.) data_power |
|
1602 | 4.) data_power | |
1603 | Este parametro esta dividido por los factores: nro. perfiles, nro intCoh y pwcode |
|
1603 | Este parametro esta dividido por los factores: nro. perfiles, nro intCoh y pwcode | |
1604 | 5.) lag_0 |
|
1604 | 5.) lag_0 | |
1605 | Este parametro esta dividido por los factores: nro. perfiles, nro intCoh y pwcode |
|
1605 | Este parametro esta dividido por los factores: nro. perfiles, nro intCoh y pwcode | |
1606 | Igual a data_power |
|
1606 | Igual a data_power | |
1607 |
|
1607 | |||
1608 | ''' |
|
1608 | ''' | |
1609 | #----------------- Remove DC----------------------------------- |
|
1609 | #----------------- Remove DC----------------------------------- | |
1610 | if self.removeDC==True: |
|
1610 | if self.removeDC==True: | |
1611 | mean = numpy.mean(self.__buffer,1) |
|
1611 | mean = numpy.mean(self.__buffer,1) | |
1612 | tmp = mean.reshape(self.__nch,1,self.__nHeis) |
|
1612 | tmp = mean.reshape(self.__nch,1,self.__nHeis) | |
1613 | dc= numpy.tile(tmp,[1,self.__nProf,1]) |
|
1613 | dc= numpy.tile(tmp,[1,self.__nProf,1]) | |
1614 | self.__buffer = self.__buffer - dc |
|
1614 | self.__buffer = self.__buffer - dc | |
1615 | #------------------Calculo de Potencia ------------------------ |
|
1615 | #------------------Calculo de Potencia ------------------------ | |
1616 | pair0 = self.__buffer*numpy.conj(self.__buffer) * 10.0 |
|
1616 | pair0 = self.__buffer*numpy.conj(self.__buffer) * 10.0 | |
1617 | pair0 = pair0.real |
|
1617 | pair0 = pair0.real | |
1618 | lag_0 = numpy.sum(pair0,1) |
|
1618 | lag_0 = numpy.sum(pair0,1) | |
1619 | #-----------------Calculo de Cscp------------------------------ New |
|
1619 | #-----------------Calculo de Cscp------------------------------ New | |
1620 | if len(self.__buffer)>1: |
|
1620 | if len(self.__buffer)>1: | |
1621 | cspc_pair01 = self.__buffer[0]*self.__buffer[1] |
|
1621 | cspc_pair01 = self.__buffer[0]*self.__buffer[1] | |
1622 | #------------------ Data Decodificada------------------------ |
|
1622 | #------------------ Data Decodificada------------------------ | |
1623 | pwcode = 1 |
|
1623 | pwcode = 1 | |
1624 | if dataOut.flagDecodeData == True: |
|
1624 | if dataOut.flagDecodeData == True: | |
1625 | pwcode = numpy.sum(dataOut.code[0]**2) |
|
1625 | pwcode = numpy.sum(dataOut.code[0]**2) | |
1626 | #------------------Calculo de Ruido x canal-------------------- |
|
1626 | #------------------Calculo de Ruido x canal-------------------- | |
1627 | self.noise = numpy.zeros(self.__nch) |
|
1627 | self.noise = numpy.zeros(self.__nch) | |
1628 | for i in range(self.__nch): |
|
1628 | for i in range(self.__nch): | |
1629 | daux = numpy.sort(pair0[i,:,:],axis= None) |
|
1629 | daux = numpy.sort(pair0[i,:,:],axis= None) | |
1630 | self.noise[i]=hildebrand_sekhon( daux/pwcode ,self.nCohInt) |
|
1630 | self.noise[i]=hildebrand_sekhon( daux/pwcode ,self.nCohInt) | |
1631 |
|
1631 | |||
1632 | self.noise = self.noise.reshape(self.__nch,1) |
|
1632 | self.noise = self.noise.reshape(self.__nch,1) | |
1633 | self.noise = numpy.tile(self.noise,[1,self.__nHeis]) |
|
1633 | self.noise = numpy.tile(self.noise,[1,self.__nHeis]) | |
1634 | noise_buffer = self.noise.reshape(self.__nch,1,self.__nHeis) |
|
1634 | noise_buffer = self.noise.reshape(self.__nch,1,self.__nHeis) | |
1635 | noise_buffer = numpy.tile(noise_buffer,[1,self.__nProf,1]) |
|
1635 | noise_buffer = numpy.tile(noise_buffer,[1,self.__nProf,1]) | |
1636 | #------------------ Potencia recibida= P , Potencia senal = S , Ruido= N-- |
|
1636 | #------------------ Potencia recibida= P , Potencia senal = S , Ruido= N-- | |
1637 | #------------------ P= S+N ,P=lag_0/N --------------------------------- |
|
1637 | #------------------ P= S+N ,P=lag_0/N --------------------------------- | |
1638 | #-------------------- Power -------------------------------------------------- |
|
1638 | #-------------------- Power -------------------------------------------------- | |
1639 | data_power = lag_0/(self.n*self.nCohInt*pwcode) |
|
1639 | data_power = lag_0/(self.n*self.nCohInt*pwcode) | |
1640 | #--------------------CCF------------------------------------------------------ |
|
1640 | #--------------------CCF------------------------------------------------------ | |
1641 |
|
1641 | |||
1642 | if len(self.__buffer)>1: |
|
1642 | if len(self.__buffer)>1: | |
1643 | data_ccf =numpy.sum(cspc_pair01,axis=0)/(self.n*self.nCohInt) |
|
1643 | data_ccf =numpy.sum(cspc_pair01,axis=0)/(self.n*self.nCohInt) | |
1644 | else: |
|
1644 | else: | |
1645 | data_ccf = 0 |
|
1645 | data_ccf = 0 | |
1646 | #------------------ Senal -------------------------------------------------- |
|
1646 | #------------------ Senal -------------------------------------------------- | |
1647 | data_intensity = pair0 - noise_buffer |
|
1647 | data_intensity = pair0/pwcode - noise_buffer | |
1648 | data_intensity = numpy.sum(data_intensity,axis=1)*(self.n*self.nCohInt)#*self.nCohInt) |
|
1648 | data_intensity = numpy.sum(data_intensity,axis=1)*(self.n*self.nCohInt)#*self.nCohInt) | |
1649 | #data_intensity = (lag_0-self.noise*self.n)*(self.n*self.nCohInt) |
|
1649 | #data_intensity = (lag_0-self.noise*self.n)*(self.n*self.nCohInt) | |
1650 | for i in range(self.__nch): |
|
1650 | for i in range(self.__nch): | |
1651 | for j in range(self.__nHeis): |
|
1651 | for j in range(self.__nHeis): | |
1652 | if data_intensity[i][j] < 0: |
|
1652 | if data_intensity[i][j] < 0: | |
1653 | data_intensity[i][j] = numpy.min(numpy.absolute(data_intensity[i][j])) |
|
1653 | data_intensity[i][j] = numpy.min(numpy.absolute(data_intensity[i][j])) | |
1654 |
|
1654 | |||
1655 | #----------------- Calculo de Frecuencia y Velocidad doppler-------- |
|
1655 | #----------------- Calculo de Frecuencia y Velocidad doppler-------- | |
1656 | pair1 = self.__buffer[:,:-1,:]*numpy.conjugate(self.__buffer[:,1:,:]) |
|
1656 | pair1 = self.__buffer[:,:-1,:]*numpy.conjugate(self.__buffer[:,1:,:]) | |
1657 | lag_1 = numpy.sum(pair1,1) |
|
1657 | lag_1 = numpy.sum(pair1,1) | |
1658 | data_freq = (-1/(2.0*math.pi*self.ippSec*self.nCohInt))*numpy.angle(lag_1) |
|
1658 | data_freq = (-1/(2.0*math.pi*self.ippSec*self.nCohInt))*numpy.angle(lag_1) | |
1659 | data_velocity = (self.lambda_/2.0)*data_freq |
|
1659 | data_velocity = (self.lambda_/2.0)*data_freq | |
1660 |
|
1660 | |||
1661 | #---------------- Potencia promedio estimada de la Senal----------- |
|
1661 | #---------------- Potencia promedio estimada de la Senal----------- | |
1662 | lag_0 = data_power |
|
1662 | lag_0 = data_power | |
1663 | S = lag_0-self.noise |
|
1663 | S = lag_0-self.noise | |
1664 |
|
1664 | |||
1665 | #---------------- Frecuencia Doppler promedio --------------------- |
|
1665 | #---------------- Frecuencia Doppler promedio --------------------- | |
1666 | lag_1 = lag_1/((self.n-1)*(pwcode)) |
|
1666 | lag_1 = lag_1/((self.n-1)*(pwcode)) | |
1667 | R1 = numpy.abs(lag_1) |
|
1667 | R1 = numpy.abs(lag_1) | |
1668 |
|
1668 | |||
1669 | #---------------- Calculo del SNR---------------------------------- |
|
1669 | #---------------- Calculo del SNR---------------------------------- | |
1670 | data_snrPP = S/self.noise |
|
1670 | data_snrPP = S/self.noise | |
1671 | for i in range(self.__nch): |
|
1671 | for i in range(self.__nch): | |
1672 | for j in range(self.__nHeis): |
|
1672 | for j in range(self.__nHeis): | |
1673 | if data_snrPP[i][j] < 1.e-20: |
|
1673 | if data_snrPP[i][j] < 1.e-20: | |
1674 | data_snrPP[i][j] = 1.e-20 |
|
1674 | data_snrPP[i][j] = 1.e-20 | |
1675 |
|
1675 | |||
1676 | #----------------- Calculo del ancho espectral ---------------------- |
|
1676 | #----------------- Calculo del ancho espectral ---------------------- | |
1677 | L = S/R1 |
|
1677 | L = S/R1 | |
1678 | L = numpy.where(L<0,1,L) |
|
1678 | L = numpy.where(L<0,1,L) | |
1679 | L = numpy.log(L) |
|
1679 | L = numpy.log(L) | |
1680 | tmp = numpy.sqrt(numpy.absolute(L)) |
|
1680 | tmp = numpy.sqrt(numpy.absolute(L)) | |
1681 | data_specwidth = (self.lambda_/(2*math.sqrt(2)*math.pi*self.ippSec*self.nCohInt))*tmp*numpy.sign(L) |
|
1681 | data_specwidth = (self.lambda_/(2*math.sqrt(2)*math.pi*self.ippSec*self.nCohInt))*tmp*numpy.sign(L) | |
1682 | n = self.__profIndex |
|
1682 | n = self.__profIndex | |
1683 |
|
1683 | |||
1684 | self.__buffer = numpy.zeros((self.__nch, self.__nProf,self.__nHeis), dtype='complex') |
|
1684 | self.__buffer = numpy.zeros((self.__nch, self.__nProf,self.__nHeis), dtype='complex') | |
1685 | self.__profIndex = 0 |
|
1685 | self.__profIndex = 0 | |
1686 | return data_power,data_intensity,data_velocity,data_snrPP,data_specwidth,data_ccf,n |
|
1686 | return data_power,data_intensity,data_velocity,data_snrPP,data_specwidth,data_ccf,n | |
1687 |
|
1687 | |||
1688 |
|
1688 | |||
1689 | def pulsePairbyProfiles(self,dataOut,n): |
|
1689 | def pulsePairbyProfiles(self,dataOut,n): | |
1690 |
|
1690 | |||
1691 | self.__dataReady = False |
|
1691 | self.__dataReady = False | |
1692 | data_power = None |
|
1692 | data_power = None | |
1693 | data_intensity = None |
|
1693 | data_intensity = None | |
1694 | data_velocity = None |
|
1694 | data_velocity = None | |
1695 | data_specwidth = None |
|
1695 | data_specwidth = None | |
1696 | data_snrPP = None |
|
1696 | data_snrPP = None | |
1697 | data_ccf = None |
|
1697 | data_ccf = None | |
1698 |
|
1698 | |||
1699 | if dataOut.flagDataAsBlock: |
|
1699 | if dataOut.flagDataAsBlock: | |
1700 | self.putDataByBlock(data=dataOut.data,n=n) |
|
1700 | self.putDataByBlock(data=dataOut.data,n=n) | |
1701 | else: |
|
1701 | else: | |
1702 | self.putData(data=dataOut.data) |
|
1702 | self.putData(data=dataOut.data) | |
1703 | if self.__profIndex == self.n: |
|
1703 | if self.__profIndex == self.n: | |
1704 | data_power,data_intensity, data_velocity,data_snrPP,data_specwidth,data_ccf, n = self.pushData(dataOut=dataOut) |
|
1704 | data_power,data_intensity, data_velocity,data_snrPP,data_specwidth,data_ccf, n = self.pushData(dataOut=dataOut) | |
1705 | self.__dataReady = True |
|
1705 | self.__dataReady = True | |
1706 |
|
1706 | |||
1707 | return data_power, data_intensity, data_velocity, data_snrPP,data_specwidth,data_ccf |
|
1707 | return data_power, data_intensity, data_velocity, data_snrPP,data_specwidth,data_ccf | |
1708 |
|
1708 | |||
1709 |
|
1709 | |||
1710 | def pulsePairOp(self, dataOut, n, datatime= None): |
|
1710 | def pulsePairOp(self, dataOut, n, datatime= None): | |
1711 |
|
1711 | |||
1712 | if self.__initime == None: |
|
1712 | if self.__initime == None: | |
1713 | self.__initime = datatime |
|
1713 | self.__initime = datatime | |
1714 | data_power, data_intensity, data_velocity, data_snrPP,data_specwidth,data_ccf = self.pulsePairbyProfiles(dataOut,n) |
|
1714 | data_power, data_intensity, data_velocity, data_snrPP,data_specwidth,data_ccf = self.pulsePairbyProfiles(dataOut,n) | |
1715 | self.__lastdatatime = datatime |
|
1715 | self.__lastdatatime = datatime | |
1716 |
|
1716 | |||
1717 | if data_power is None: |
|
1717 | if data_power is None: | |
1718 | return None, None, None,None,None,None,None |
|
1718 | return None, None, None,None,None,None,None | |
1719 |
|
1719 | |||
1720 | avgdatatime = self.__initime |
|
1720 | avgdatatime = self.__initime | |
1721 | deltatime = datatime - self.__lastdatatime |
|
1721 | deltatime = datatime - self.__lastdatatime | |
1722 | self.__initime = datatime |
|
1722 | self.__initime = datatime | |
1723 |
|
1723 | |||
1724 | return data_power, data_intensity, data_velocity, data_snrPP,data_specwidth,data_ccf, avgdatatime |
|
1724 | return data_power, data_intensity, data_velocity, data_snrPP,data_specwidth,data_ccf, avgdatatime | |
1725 |
|
1725 | |||
1726 | def run(self, dataOut,n = None,removeDC= False, overlapping= False,**kwargs): |
|
1726 | def run(self, dataOut,n = None,removeDC= False, overlapping= False,**kwargs): | |
1727 |
|
1727 | |||
1728 | if dataOut.flagDataAsBlock: |
|
1728 | if dataOut.flagDataAsBlock: | |
1729 | n = int(dataOut.nProfiles) |
|
1729 | n = int(dataOut.nProfiles) | |
1730 | #print("n",n) |
|
1730 | #print("n",n) | |
1731 |
|
1731 | |||
1732 | if not self.isConfig: |
|
1732 | if not self.isConfig: | |
1733 | self.setup(dataOut = dataOut, n = n , removeDC=removeDC , **kwargs) |
|
1733 | self.setup(dataOut = dataOut, n = n , removeDC=removeDC , **kwargs) | |
1734 | self.isConfig = True |
|
1734 | self.isConfig = True | |
1735 |
|
1735 | |||
1736 |
|
1736 | |||
1737 | data_power, data_intensity, data_velocity,data_snrPP,data_specwidth,data_ccf, avgdatatime = self.pulsePairOp(dataOut, n, dataOut.utctime) |
|
1737 | data_power, data_intensity, data_velocity,data_snrPP,data_specwidth,data_ccf, avgdatatime = self.pulsePairOp(dataOut, n, dataOut.utctime) | |
1738 |
|
1738 | |||
1739 |
|
1739 | |||
1740 | dataOut.flagNoData = True |
|
1740 | dataOut.flagNoData = True | |
1741 |
|
1741 | |||
1742 | if self.__dataReady: |
|
1742 | if self.__dataReady: | |
1743 | ###print("READY ----------------------------------") |
|
1743 | ###print("READY ----------------------------------") | |
1744 | dataOut.nCohInt *= self.n |
|
1744 | dataOut.nCohInt *= self.n | |
1745 | dataOut.dataPP_POW = data_intensity # S |
|
1745 | dataOut.dataPP_POW = data_intensity # S | |
1746 | dataOut.dataPP_POWER = data_power # P valor que corresponde a POTENCIA MOMENTO |
|
1746 | dataOut.dataPP_POWER = data_power # P valor que corresponde a POTENCIA MOMENTO | |
1747 | dataOut.dataPP_DOP = data_velocity |
|
1747 | dataOut.dataPP_DOP = data_velocity | |
1748 | dataOut.dataPP_SNR = data_snrPP |
|
1748 | dataOut.dataPP_SNR = data_snrPP | |
1749 | dataOut.dataPP_WIDTH = data_specwidth |
|
1749 | dataOut.dataPP_WIDTH = data_specwidth | |
1750 | dataOut.dataPP_CCF = data_ccf |
|
1750 | dataOut.dataPP_CCF = data_ccf | |
1751 | dataOut.PRFbyAngle = self.n #numero de PRF*cada angulo rotado que equivale a un tiempo. |
|
1751 | dataOut.PRFbyAngle = self.n #numero de PRF*cada angulo rotado que equivale a un tiempo. | |
1752 | dataOut.nProfiles = int(dataOut.nProfiles/n) |
|
1752 | dataOut.nProfiles = int(dataOut.nProfiles/n) | |
1753 | dataOut.utctime = avgdatatime |
|
1753 | dataOut.utctime = avgdatatime | |
1754 | dataOut.flagNoData = False |
|
1754 | dataOut.flagNoData = False | |
1755 | return dataOut |
|
1755 | return dataOut | |
1756 |
|
1756 | |||
1757 | # import collections |
|
1757 | # import collections | |
1758 | # from scipy.stats import mode |
|
1758 | # from scipy.stats import mode | |
1759 | # |
|
1759 | # | |
1760 | # class Synchronize(Operation): |
|
1760 | # class Synchronize(Operation): | |
1761 | # |
|
1761 | # | |
1762 | # isConfig = False |
|
1762 | # isConfig = False | |
1763 | # __profIndex = 0 |
|
1763 | # __profIndex = 0 | |
1764 | # |
|
1764 | # | |
1765 | # def __init__(self, **kwargs): |
|
1765 | # def __init__(self, **kwargs): | |
1766 | # |
|
1766 | # | |
1767 | # Operation.__init__(self, **kwargs) |
|
1767 | # Operation.__init__(self, **kwargs) | |
1768 | # # self.isConfig = False |
|
1768 | # # self.isConfig = False | |
1769 | # self.__powBuffer = None |
|
1769 | # self.__powBuffer = None | |
1770 | # self.__startIndex = 0 |
|
1770 | # self.__startIndex = 0 | |
1771 | # self.__pulseFound = False |
|
1771 | # self.__pulseFound = False | |
1772 | # |
|
1772 | # | |
1773 | # def __findTxPulse(self, dataOut, channel=0, pulse_with = None): |
|
1773 | # def __findTxPulse(self, dataOut, channel=0, pulse_with = None): | |
1774 | # |
|
1774 | # | |
1775 | # #Read data |
|
1775 | # #Read data | |
1776 | # |
|
1776 | # | |
1777 | # powerdB = dataOut.getPower(channel = channel) |
|
1777 | # powerdB = dataOut.getPower(channel = channel) | |
1778 | # noisedB = dataOut.getNoise(channel = channel)[0] |
|
1778 | # noisedB = dataOut.getNoise(channel = channel)[0] | |
1779 | # |
|
1779 | # | |
1780 | # self.__powBuffer.extend(powerdB.flatten()) |
|
1780 | # self.__powBuffer.extend(powerdB.flatten()) | |
1781 | # |
|
1781 | # | |
1782 | # dataArray = numpy.array(self.__powBuffer) |
|
1782 | # dataArray = numpy.array(self.__powBuffer) | |
1783 | # |
|
1783 | # | |
1784 | # filteredPower = numpy.correlate(dataArray, dataArray[0:self.__nSamples], "same") |
|
1784 | # filteredPower = numpy.correlate(dataArray, dataArray[0:self.__nSamples], "same") | |
1785 | # |
|
1785 | # | |
1786 | # maxValue = numpy.nanmax(filteredPower) |
|
1786 | # maxValue = numpy.nanmax(filteredPower) | |
1787 | # |
|
1787 | # | |
1788 | # if maxValue < noisedB + 10: |
|
1788 | # if maxValue < noisedB + 10: | |
1789 | # #No se encuentra ningun pulso de transmision |
|
1789 | # #No se encuentra ningun pulso de transmision | |
1790 | # return None |
|
1790 | # return None | |
1791 | # |
|
1791 | # | |
1792 | # maxValuesIndex = numpy.where(filteredPower > maxValue - 0.1*abs(maxValue))[0] |
|
1792 | # maxValuesIndex = numpy.where(filteredPower > maxValue - 0.1*abs(maxValue))[0] | |
1793 | # |
|
1793 | # | |
1794 | # if len(maxValuesIndex) < 2: |
|
1794 | # if len(maxValuesIndex) < 2: | |
1795 | # #Solo se encontro un solo pulso de transmision de un baudio, esperando por el siguiente TX |
|
1795 | # #Solo se encontro un solo pulso de transmision de un baudio, esperando por el siguiente TX | |
1796 | # return None |
|
1796 | # return None | |
1797 | # |
|
1797 | # | |
1798 | # phasedMaxValuesIndex = maxValuesIndex - self.__nSamples |
|
1798 | # phasedMaxValuesIndex = maxValuesIndex - self.__nSamples | |
1799 | # |
|
1799 | # | |
1800 | # #Seleccionar solo valores con un espaciamiento de nSamples |
|
1800 | # #Seleccionar solo valores con un espaciamiento de nSamples | |
1801 | # pulseIndex = numpy.intersect1d(maxValuesIndex, phasedMaxValuesIndex) |
|
1801 | # pulseIndex = numpy.intersect1d(maxValuesIndex, phasedMaxValuesIndex) | |
1802 | # |
|
1802 | # | |
1803 | # if len(pulseIndex) < 2: |
|
1803 | # if len(pulseIndex) < 2: | |
1804 | # #Solo se encontro un pulso de transmision con ancho mayor a 1 |
|
1804 | # #Solo se encontro un pulso de transmision con ancho mayor a 1 | |
1805 | # return None |
|
1805 | # return None | |
1806 | # |
|
1806 | # | |
1807 | # spacing = pulseIndex[1:] - pulseIndex[:-1] |
|
1807 | # spacing = pulseIndex[1:] - pulseIndex[:-1] | |
1808 | # |
|
1808 | # | |
1809 | # #remover senales que se distancien menos de 10 unidades o muestras |
|
1809 | # #remover senales que se distancien menos de 10 unidades o muestras | |
1810 | # #(No deberian existir IPP menor a 10 unidades) |
|
1810 | # #(No deberian existir IPP menor a 10 unidades) | |
1811 | # |
|
1811 | # | |
1812 | # realIndex = numpy.where(spacing > 10 )[0] |
|
1812 | # realIndex = numpy.where(spacing > 10 )[0] | |
1813 | # |
|
1813 | # | |
1814 | # if len(realIndex) < 2: |
|
1814 | # if len(realIndex) < 2: | |
1815 | # #Solo se encontro un pulso de transmision con ancho mayor a 1 |
|
1815 | # #Solo se encontro un pulso de transmision con ancho mayor a 1 | |
1816 | # return None |
|
1816 | # return None | |
1817 | # |
|
1817 | # | |
1818 | # #Eliminar pulsos anchos (deja solo la diferencia entre IPPs) |
|
1818 | # #Eliminar pulsos anchos (deja solo la diferencia entre IPPs) | |
1819 | # realPulseIndex = pulseIndex[realIndex] |
|
1819 | # realPulseIndex = pulseIndex[realIndex] | |
1820 | # |
|
1820 | # | |
1821 | # period = mode(realPulseIndex[1:] - realPulseIndex[:-1])[0][0] |
|
1821 | # period = mode(realPulseIndex[1:] - realPulseIndex[:-1])[0][0] | |
1822 | # |
|
1822 | # | |
1823 | # print "IPP = %d samples" %period |
|
1823 | # print "IPP = %d samples" %period | |
1824 | # |
|
1824 | # | |
1825 | # self.__newNSamples = dataOut.nHeights #int(period) |
|
1825 | # self.__newNSamples = dataOut.nHeights #int(period) | |
1826 | # self.__startIndex = int(realPulseIndex[0]) |
|
1826 | # self.__startIndex = int(realPulseIndex[0]) | |
1827 | # |
|
1827 | # | |
1828 | # return 1 |
|
1828 | # return 1 | |
1829 | # |
|
1829 | # | |
1830 | # |
|
1830 | # | |
1831 | # def setup(self, nSamples, nChannels, buffer_size = 4): |
|
1831 | # def setup(self, nSamples, nChannels, buffer_size = 4): | |
1832 | # |
|
1832 | # | |
1833 | # self.__powBuffer = collections.deque(numpy.zeros( buffer_size*nSamples,dtype=numpy.float), |
|
1833 | # self.__powBuffer = collections.deque(numpy.zeros( buffer_size*nSamples,dtype=numpy.float), | |
1834 | # maxlen = buffer_size*nSamples) |
|
1834 | # maxlen = buffer_size*nSamples) | |
1835 | # |
|
1835 | # | |
1836 | # bufferList = [] |
|
1836 | # bufferList = [] | |
1837 | # |
|
1837 | # | |
1838 | # for i in range(nChannels): |
|
1838 | # for i in range(nChannels): | |
1839 | # bufferByChannel = collections.deque(numpy.zeros( buffer_size*nSamples, dtype=numpy.complex) + numpy.NAN, |
|
1839 | # bufferByChannel = collections.deque(numpy.zeros( buffer_size*nSamples, dtype=numpy.complex) + numpy.NAN, | |
1840 | # maxlen = buffer_size*nSamples) |
|
1840 | # maxlen = buffer_size*nSamples) | |
1841 | # |
|
1841 | # | |
1842 | # bufferList.append(bufferByChannel) |
|
1842 | # bufferList.append(bufferByChannel) | |
1843 | # |
|
1843 | # | |
1844 | # self.__nSamples = nSamples |
|
1844 | # self.__nSamples = nSamples | |
1845 | # self.__nChannels = nChannels |
|
1845 | # self.__nChannels = nChannels | |
1846 | # self.__bufferList = bufferList |
|
1846 | # self.__bufferList = bufferList | |
1847 | # |
|
1847 | # | |
1848 | # def run(self, dataOut, channel = 0): |
|
1848 | # def run(self, dataOut, channel = 0): | |
1849 | # |
|
1849 | # | |
1850 | # if not self.isConfig: |
|
1850 | # if not self.isConfig: | |
1851 | # nSamples = dataOut.nHeights |
|
1851 | # nSamples = dataOut.nHeights | |
1852 | # nChannels = dataOut.nChannels |
|
1852 | # nChannels = dataOut.nChannels | |
1853 | # self.setup(nSamples, nChannels) |
|
1853 | # self.setup(nSamples, nChannels) | |
1854 | # self.isConfig = True |
|
1854 | # self.isConfig = True | |
1855 | # |
|
1855 | # | |
1856 | # #Append new data to internal buffer |
|
1856 | # #Append new data to internal buffer | |
1857 | # for thisChannel in range(self.__nChannels): |
|
1857 | # for thisChannel in range(self.__nChannels): | |
1858 | # bufferByChannel = self.__bufferList[thisChannel] |
|
1858 | # bufferByChannel = self.__bufferList[thisChannel] | |
1859 | # bufferByChannel.extend(dataOut.data[thisChannel]) |
|
1859 | # bufferByChannel.extend(dataOut.data[thisChannel]) | |
1860 | # |
|
1860 | # | |
1861 | # if self.__pulseFound: |
|
1861 | # if self.__pulseFound: | |
1862 | # self.__startIndex -= self.__nSamples |
|
1862 | # self.__startIndex -= self.__nSamples | |
1863 | # |
|
1863 | # | |
1864 | # #Finding Tx Pulse |
|
1864 | # #Finding Tx Pulse | |
1865 | # if not self.__pulseFound: |
|
1865 | # if not self.__pulseFound: | |
1866 | # indexFound = self.__findTxPulse(dataOut, channel) |
|
1866 | # indexFound = self.__findTxPulse(dataOut, channel) | |
1867 | # |
|
1867 | # | |
1868 | # if indexFound == None: |
|
1868 | # if indexFound == None: | |
1869 | # dataOut.flagNoData = True |
|
1869 | # dataOut.flagNoData = True | |
1870 | # return |
|
1870 | # return | |
1871 | # |
|
1871 | # | |
1872 | # self.__arrayBuffer = numpy.zeros((self.__nChannels, self.__newNSamples), dtype = numpy.complex) |
|
1872 | # self.__arrayBuffer = numpy.zeros((self.__nChannels, self.__newNSamples), dtype = numpy.complex) | |
1873 | # self.__pulseFound = True |
|
1873 | # self.__pulseFound = True | |
1874 | # self.__startIndex = indexFound |
|
1874 | # self.__startIndex = indexFound | |
1875 | # |
|
1875 | # | |
1876 | # #If pulse was found ... |
|
1876 | # #If pulse was found ... | |
1877 | # for thisChannel in range(self.__nChannels): |
|
1877 | # for thisChannel in range(self.__nChannels): | |
1878 | # bufferByChannel = self.__bufferList[thisChannel] |
|
1878 | # bufferByChannel = self.__bufferList[thisChannel] | |
1879 | # #print self.__startIndex |
|
1879 | # #print self.__startIndex | |
1880 | # x = numpy.array(bufferByChannel) |
|
1880 | # x = numpy.array(bufferByChannel) | |
1881 | # self.__arrayBuffer[thisChannel] = x[self.__startIndex:self.__startIndex+self.__newNSamples] |
|
1881 | # self.__arrayBuffer[thisChannel] = x[self.__startIndex:self.__startIndex+self.__newNSamples] | |
1882 | # |
|
1882 | # | |
1883 | # deltaHeight = dataOut.heightList[1] - dataOut.heightList[0] |
|
1883 | # deltaHeight = dataOut.heightList[1] - dataOut.heightList[0] | |
1884 | # dataOut.heightList = numpy.arange(self.__newNSamples)*deltaHeight |
|
1884 | # dataOut.heightList = numpy.arange(self.__newNSamples)*deltaHeight | |
1885 | # # dataOut.ippSeconds = (self.__newNSamples / deltaHeight)/1e6 |
|
1885 | # # dataOut.ippSeconds = (self.__newNSamples / deltaHeight)/1e6 | |
1886 | # |
|
1886 | # | |
1887 | # dataOut.data = self.__arrayBuffer |
|
1887 | # dataOut.data = self.__arrayBuffer | |
1888 | # |
|
1888 | # | |
1889 | # self.__startIndex += self.__newNSamples |
|
1889 | # self.__startIndex += self.__newNSamples | |
1890 | # |
|
1890 | # | |
1891 | # return |
|
1891 | # return |
General Comments 0
You need to be logged in to leave comments.
Login now