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