@@ -1,3249 +1,3250 | |||||
1 | import sys |
|
1 | import sys | |
2 | import numpy,math |
|
2 | import numpy,math | |
3 | from scipy import interpolate |
|
3 | from scipy import interpolate | |
4 | from schainpy.model.proc.jroproc_base import ProcessingUnit, Operation, MPDecorator |
|
4 | from schainpy.model.proc.jroproc_base import ProcessingUnit, Operation, MPDecorator | |
5 | from schainpy.model.data.jrodata import Voltage,hildebrand_sekhon |
|
5 | from schainpy.model.data.jrodata import Voltage,hildebrand_sekhon | |
6 | from schainpy.utils import log |
|
6 | from schainpy.utils import log | |
7 | from schainpy.model.io.utilsIO import getHei_index |
|
7 | from schainpy.model.io.utilsIO import getHei_index | |
8 | from time import time |
|
8 | from time import time | |
9 | import datetime |
|
9 | import datetime | |
10 | import numpy |
|
10 | import numpy | |
11 | #import copy |
|
11 | #import copy | |
12 | from schainpy.model.data import _noise |
|
12 | from schainpy.model.data import _noise | |
13 |
|
13 | |||
14 | from matplotlib import pyplot as plt |
|
14 | from matplotlib import pyplot as plt | |
15 |
|
15 | |||
16 | class VoltageProc(ProcessingUnit): |
|
16 | class VoltageProc(ProcessingUnit): | |
17 |
|
17 | |||
18 | def __init__(self): |
|
18 | def __init__(self): | |
19 |
|
19 | |||
20 | ProcessingUnit.__init__(self) |
|
20 | ProcessingUnit.__init__(self) | |
21 |
|
21 | |||
22 | self.dataOut = Voltage() |
|
22 | self.dataOut = Voltage() | |
23 | self.flip = 1 |
|
23 | self.flip = 1 | |
24 | self.setupReq = False |
|
24 | self.setupReq = False | |
25 |
|
25 | |||
26 | def run(self): |
|
26 | def run(self): | |
27 | #print("running volt proc") |
|
27 | #print("running volt proc") | |
28 |
|
28 | |||
29 | if self.dataIn.type == 'AMISR': |
|
29 | if self.dataIn.type == 'AMISR': | |
30 | self.__updateObjFromAmisrInput() |
|
30 | self.__updateObjFromAmisrInput() | |
31 |
|
31 | |||
32 | if self.dataOut.buffer_empty: |
|
32 | if self.dataOut.buffer_empty: | |
33 | if self.dataIn.type == 'Voltage': |
|
33 | if self.dataIn.type == 'Voltage': | |
34 | self.dataOut.copy(self.dataIn) |
|
34 | self.dataOut.copy(self.dataIn) | |
35 | self.dataOut.radarControllerHeaderObj = self.dataIn.radarControllerHeaderObj.copy() |
|
35 | self.dataOut.radarControllerHeaderObj = self.dataIn.radarControllerHeaderObj.copy() | |
36 | self.dataOut.ippSeconds = self.dataIn.ippSeconds |
|
36 | self.dataOut.ippSeconds = self.dataIn.ippSeconds | |
37 | self.dataOut.ipp = self.dataIn.ipp |
|
37 | self.dataOut.ipp = self.dataIn.ipp | |
38 |
|
38 | |||
39 | #update Processing Header: |
|
39 | #update Processing Header: | |
40 | self.dataOut.processingHeaderObj.heightList = self.dataOut.heightList |
|
40 | self.dataOut.processingHeaderObj.heightList = self.dataOut.heightList | |
41 | self.dataOut.processingHeaderObj.ipp = self.dataOut.ipp |
|
41 | self.dataOut.processingHeaderObj.ipp = self.dataOut.ipp | |
42 | self.dataOut.processingHeaderObj.nCohInt = self.dataOut.nCohInt |
|
42 | self.dataOut.processingHeaderObj.nCohInt = self.dataOut.nCohInt | |
43 | self.dataOut.processingHeaderObj.dtype = self.dataOut.type |
|
43 | self.dataOut.processingHeaderObj.dtype = self.dataOut.type | |
44 | self.dataOut.processingHeaderObj.channelList = self.dataOut.channelList |
|
44 | self.dataOut.processingHeaderObj.channelList = self.dataOut.channelList | |
45 | self.dataOut.processingHeaderObj.azimuthList = self.dataOut.azimuthList |
|
45 | self.dataOut.processingHeaderObj.azimuthList = self.dataOut.azimuthList | |
46 | self.dataOut.processingHeaderObj.elevationList = self.dataOut.elevationList |
|
46 | self.dataOut.processingHeaderObj.elevationList = self.dataOut.elevationList | |
47 | self.dataOut.processingHeaderObj.codeList = self.dataOut.nChannels |
|
47 | self.dataOut.processingHeaderObj.codeList = self.dataOut.nChannels | |
48 | self.dataOut.processingHeaderObj.heightList = self.dataOut.heightList |
|
48 | self.dataOut.processingHeaderObj.heightList = self.dataOut.heightList | |
49 | self.dataOut.processingHeaderObj.heightResolution = self.dataOut.heightList[1] - self.dataOut.heightList[0] |
|
49 | self.dataOut.processingHeaderObj.heightResolution = self.dataOut.heightList[1] - self.dataOut.heightList[0] | |
50 |
|
50 | |||
51 |
|
51 | |||
52 |
|
52 | |||
53 | def __updateObjFromAmisrInput(self): |
|
53 | def __updateObjFromAmisrInput(self): | |
54 |
|
54 | |||
55 | self.dataOut.timeZone = self.dataIn.timeZone |
|
55 | self.dataOut.timeZone = self.dataIn.timeZone | |
56 | self.dataOut.dstFlag = self.dataIn.dstFlag |
|
56 | self.dataOut.dstFlag = self.dataIn.dstFlag | |
57 | self.dataOut.errorCount = self.dataIn.errorCount |
|
57 | self.dataOut.errorCount = self.dataIn.errorCount | |
58 | self.dataOut.useLocalTime = self.dataIn.useLocalTime |
|
58 | self.dataOut.useLocalTime = self.dataIn.useLocalTime | |
59 |
|
59 | |||
60 | self.dataOut.flagNoData = self.dataIn.flagNoData |
|
60 | self.dataOut.flagNoData = self.dataIn.flagNoData | |
61 | self.dataOut.data = self.dataIn.data |
|
61 | self.dataOut.data = self.dataIn.data | |
62 | self.dataOut.utctime = self.dataIn.utctime |
|
62 | self.dataOut.utctime = self.dataIn.utctime | |
63 | self.dataOut.channelList = self.dataIn.channelList |
|
63 | self.dataOut.channelList = self.dataIn.channelList | |
64 | #self.dataOut.timeInterval = self.dataIn.timeInterval |
|
64 | #self.dataOut.timeInterval = self.dataIn.timeInterval | |
65 | self.dataOut.heightList = self.dataIn.heightList |
|
65 | self.dataOut.heightList = self.dataIn.heightList | |
66 | self.dataOut.nProfiles = self.dataIn.nProfiles |
|
66 | self.dataOut.nProfiles = self.dataIn.nProfiles | |
67 |
|
67 | |||
68 | self.dataOut.nCohInt = self.dataIn.nCohInt |
|
68 | self.dataOut.nCohInt = self.dataIn.nCohInt | |
69 | self.dataOut.ippSeconds = self.dataIn.ippSeconds |
|
69 | self.dataOut.ippSeconds = self.dataIn.ippSeconds | |
70 | self.dataOut.frequency = self.dataIn.frequency |
|
70 | self.dataOut.frequency = self.dataIn.frequency | |
71 |
|
71 | |||
72 | self.dataOut.azimuth = self.dataIn.azimuth |
|
72 | self.dataOut.azimuth = self.dataIn.azimuth | |
73 | self.dataOut.zenith = self.dataIn.zenith |
|
73 | self.dataOut.zenith = self.dataIn.zenith | |
74 |
|
74 | |||
75 | self.dataOut.beam.codeList = self.dataIn.beam.codeList |
|
75 | self.dataOut.beam.codeList = self.dataIn.beam.codeList | |
76 | self.dataOut.beam.azimuthList = self.dataIn.beam.azimuthList |
|
76 | self.dataOut.beam.azimuthList = self.dataIn.beam.azimuthList | |
77 | self.dataOut.beam.zenithList = self.dataIn.beam.zenithList |
|
77 | self.dataOut.beam.zenithList = self.dataIn.beam.zenithList | |
78 |
|
78 | |||
79 |
|
79 | |||
80 | class selectChannels(Operation): |
|
80 | class selectChannels(Operation): | |
81 |
|
81 | |||
82 | def run(self, dataOut, channelList=[]): |
|
82 | def run(self, dataOut, channelList=[]): | |
83 |
|
83 | |||
84 | if isinstance(channelList, int): |
|
84 | if isinstance(channelList, int): | |
85 | channelList = [channelList] |
|
85 | channelList = [channelList] | |
86 |
|
86 | |||
87 | self.channelList = channelList |
|
87 | self.channelList = channelList | |
88 | if len(self.channelList) == 0: |
|
88 | if len(self.channelList) == 0: | |
89 | print("Missing channelList") |
|
89 | print("Missing channelList") | |
90 | return dataOut |
|
90 | return dataOut | |
91 | channelIndexList = [] |
|
91 | channelIndexList = [] | |
92 | if not dataOut.buffer_empty: # cuando se usa proc volts como buffer de datos |
|
92 | if not dataOut.buffer_empty: # cuando se usa proc volts como buffer de datos | |
93 | return dataOut |
|
93 | return dataOut | |
94 | #print("channel List: ", dataOut.channelList) |
|
94 | #print("channel List: ", dataOut.channelList) | |
95 | if type(dataOut.channelList) is not list: #leer array desde HDF5 |
|
95 | if type(dataOut.channelList) is not list: #leer array desde HDF5 | |
96 | try: |
|
96 | try: | |
97 | dataOut.channelList = dataOut.channelList.tolist() |
|
97 | dataOut.channelList = dataOut.channelList.tolist() | |
98 | except Exception as e: |
|
98 | except Exception as e: | |
99 | print("Select Channels: ",e) |
|
99 | print("Select Channels: ",e) | |
100 | for channel in self.channelList: |
|
100 | for channel in self.channelList: | |
101 | if channel not in dataOut.channelList: |
|
101 | if channel not in dataOut.channelList: | |
102 | raise ValueError("Channel %d is not in %s" %(channel, str(dataOut.channelList))) |
|
102 | raise ValueError("Channel %d is not in %s" %(channel, str(dataOut.channelList))) | |
103 |
|
103 | |||
104 | index = dataOut.channelList.index(channel) |
|
104 | index = dataOut.channelList.index(channel) | |
105 | channelIndexList.append(index) |
|
105 | channelIndexList.append(index) | |
106 |
|
106 | |||
107 | dataOut = self.selectChannelsByIndex(dataOut,channelIndexList) |
|
107 | dataOut = self.selectChannelsByIndex(dataOut,channelIndexList) | |
108 |
|
108 | |||
109 | #update Processing Header: |
|
109 | #update Processing Header: | |
110 | dataOut.processingHeaderObj.channelList = dataOut.channelList |
|
110 | dataOut.processingHeaderObj.channelList = dataOut.channelList | |
111 | dataOut.processingHeaderObj.elevationList = dataOut.elevationList |
|
111 | dataOut.processingHeaderObj.elevationList = dataOut.elevationList | |
112 | dataOut.processingHeaderObj.azimuthList = dataOut.azimuthList |
|
112 | dataOut.processingHeaderObj.azimuthList = dataOut.azimuthList | |
113 | dataOut.processingHeaderObj.codeList = dataOut.codeList |
|
113 | dataOut.processingHeaderObj.codeList = dataOut.codeList | |
114 | dataOut.processingHeaderObj.nChannels = len(dataOut.channelList) |
|
114 | dataOut.processingHeaderObj.nChannels = len(dataOut.channelList) | |
115 |
|
115 | |||
116 | return dataOut |
|
116 | return dataOut | |
117 |
|
117 | |||
118 | def selectChannelsByIndex(self, dataOut, channelIndexList): |
|
118 | def selectChannelsByIndex(self, dataOut, channelIndexList): | |
119 | """ |
|
119 | """ | |
120 | Selecciona un bloque de datos en base a canales segun el channelIndexList |
|
120 | Selecciona un bloque de datos en base a canales segun el channelIndexList | |
121 |
|
121 | |||
122 | Input: |
|
122 | Input: | |
123 | channelIndexList : lista sencilla de canales a seleccionar por ej. [2,3,7] |
|
123 | channelIndexList : lista sencilla de canales a seleccionar por ej. [2,3,7] | |
124 |
|
124 | |||
125 | Affected: |
|
125 | Affected: | |
126 | dataOut.data |
|
126 | dataOut.data | |
127 | dataOut.channelIndexList |
|
127 | dataOut.channelIndexList | |
128 | dataOut.nChannels |
|
128 | dataOut.nChannels | |
129 | dataOut.m_ProcessingHeader.totalSpectra |
|
129 | dataOut.m_ProcessingHeader.totalSpectra | |
130 | dataOut.systemHeaderObj.numChannels |
|
130 | dataOut.systemHeaderObj.numChannels | |
131 | dataOut.m_ProcessingHeader.blockSize |
|
131 | dataOut.m_ProcessingHeader.blockSize | |
132 |
|
132 | |||
133 | Return: |
|
133 | Return: | |
134 | None |
|
134 | None | |
135 | """ |
|
135 | """ | |
136 | #print("selectChannelsByIndex") |
|
136 | #print("selectChannelsByIndex") | |
137 | # for channelIndex in channelIndexList: |
|
137 | # for channelIndex in channelIndexList: | |
138 | # if channelIndex not in dataOut.channelIndexList: |
|
138 | # if channelIndex not in dataOut.channelIndexList: | |
139 | # raise ValueError("The value %d in channelIndexList is not valid" %channelIndex) |
|
139 | # raise ValueError("The value %d in channelIndexList is not valid" %channelIndex) | |
140 |
|
140 | |||
141 | if dataOut.type == 'Voltage': |
|
141 | if dataOut.type == 'Voltage': | |
142 | if dataOut.flagDataAsBlock: |
|
142 | if dataOut.flagDataAsBlock: | |
143 | """ |
|
143 | """ | |
144 | Si la data es obtenida por bloques, dimension = [nChannels, nProfiles, nHeis] |
|
144 | Si la data es obtenida por bloques, dimension = [nChannels, nProfiles, nHeis] | |
145 | """ |
|
145 | """ | |
146 | data = dataOut.data[channelIndexList,:,:] |
|
146 | data = dataOut.data[channelIndexList,:,:] | |
147 | else: |
|
147 | else: | |
148 | data = dataOut.data[channelIndexList,:] |
|
148 | data = dataOut.data[channelIndexList,:] | |
149 |
|
149 | |||
150 | dataOut.data = data |
|
150 | dataOut.data = data | |
151 | # dataOut.channelList = [dataOut.channelList[i] for i in channelIndexList] |
|
151 | # dataOut.channelList = [dataOut.channelList[i] for i in channelIndexList] | |
152 | dataOut.channelList = [n for n in range(len(channelIndexList))] |
|
152 | dataOut.channelList = [n for n in range(len(channelIndexList))] | |
153 |
|
153 | |||
154 | elif dataOut.type == 'Spectra': |
|
154 | elif dataOut.type == 'Spectra': | |
155 | if hasattr(dataOut, 'data_spc'): |
|
155 | if hasattr(dataOut, 'data_spc'): | |
156 | if dataOut.data_spc is None: |
|
156 | if dataOut.data_spc is None: | |
157 | raise ValueError("data_spc is None") |
|
157 | raise ValueError("data_spc is None") | |
158 | return dataOut |
|
158 | return dataOut | |
159 | else: |
|
159 | else: | |
160 | data_spc = dataOut.data_spc[channelIndexList, :] |
|
160 | data_spc = dataOut.data_spc[channelIndexList, :] | |
161 | dataOut.data_spc = data_spc |
|
161 | dataOut.data_spc = data_spc | |
162 |
|
162 | |||
163 | # if hasattr(dataOut, 'data_dc') :# and |
|
163 | # if hasattr(dataOut, 'data_dc') :# and | |
164 | # if dataOut.data_dc is None: |
|
164 | # if dataOut.data_dc is None: | |
165 | # raise ValueError("data_dc is None") |
|
165 | # raise ValueError("data_dc is None") | |
166 | # return dataOut |
|
166 | # return dataOut | |
167 | # else: |
|
167 | # else: | |
168 | # data_dc = dataOut.data_dc[channelIndexList, :] |
|
168 | # data_dc = dataOut.data_dc[channelIndexList, :] | |
169 | # dataOut.data_dc = data_dc |
|
169 | # dataOut.data_dc = data_dc | |
170 | # dataOut.channelList = [dataOut.channelList[i] for i in channelIndexList] |
|
170 | # dataOut.channelList = [dataOut.channelList[i] for i in channelIndexList] | |
171 | dataOut.channelList = channelIndexList |
|
171 | dataOut.channelList = channelIndexList | |
172 | dataOut = self.__selectPairsByChannel(dataOut,channelIndexList) |
|
172 | dataOut = self.__selectPairsByChannel(dataOut,channelIndexList) | |
173 |
|
173 | |||
174 | # channelIndexList = numpy.asarray(channelIndexList) |
|
174 | # channelIndexList = numpy.asarray(channelIndexList) | |
175 | dataOut.elevationList = numpy.asarray(dataOut.elevationList) |
|
175 | dataOut.elevationList = numpy.asarray(dataOut.elevationList) | |
176 | dataOut.azimuthList = numpy.asarray(dataOut.azimuthList) |
|
176 | dataOut.azimuthList = numpy.asarray(dataOut.azimuthList) | |
177 | dataOut.codeList = numpy.asarray(dataOut.codeList) |
|
177 | dataOut.codeList = numpy.asarray(dataOut.codeList) | |
178 | if (len(dataOut.elevationList) > 0): |
|
178 | if (len(dataOut.elevationList) > 0): | |
179 | dataOut.elevationList = dataOut.elevationList[channelIndexList] |
|
179 | dataOut.elevationList = dataOut.elevationList[channelIndexList] | |
180 | dataOut.azimuthList = dataOut.azimuthList[channelIndexList] |
|
180 | dataOut.azimuthList = dataOut.azimuthList[channelIndexList] | |
181 | dataOut.codeList = dataOut.codeList[channelIndexList] |
|
181 | dataOut.codeList = dataOut.codeList[channelIndexList] | |
182 |
|
182 | |||
183 | return dataOut |
|
183 | return dataOut | |
184 |
|
184 | |||
185 | def __selectPairsByChannel(self, dataOut, channelList=None): |
|
185 | def __selectPairsByChannel(self, dataOut, channelList=None): | |
186 | #print("__selectPairsByChannel") |
|
186 | #print("__selectPairsByChannel") | |
187 | if channelList == None: |
|
187 | if channelList == None: | |
188 | return |
|
188 | return | |
189 |
|
189 | |||
190 | pairsIndexListSelected = [] |
|
190 | pairsIndexListSelected = [] | |
191 | for pairIndex in dataOut.pairsIndexList: |
|
191 | for pairIndex in dataOut.pairsIndexList: | |
192 | # First pair |
|
192 | # First pair | |
193 | if dataOut.pairsList[pairIndex][0] not in channelList: |
|
193 | if dataOut.pairsList[pairIndex][0] not in channelList: | |
194 | continue |
|
194 | continue | |
195 | # Second pair |
|
195 | # Second pair | |
196 | if dataOut.pairsList[pairIndex][1] not in channelList: |
|
196 | if dataOut.pairsList[pairIndex][1] not in channelList: | |
197 | continue |
|
197 | continue | |
198 |
|
198 | |||
199 | pairsIndexListSelected.append(pairIndex) |
|
199 | pairsIndexListSelected.append(pairIndex) | |
200 | if not pairsIndexListSelected: |
|
200 | if not pairsIndexListSelected: | |
201 | dataOut.data_cspc = None |
|
201 | dataOut.data_cspc = None | |
202 | dataOut.pairsList = [] |
|
202 | dataOut.pairsList = [] | |
203 | return |
|
203 | return | |
204 |
|
204 | |||
205 | dataOut.data_cspc = dataOut.data_cspc[pairsIndexListSelected] |
|
205 | dataOut.data_cspc = dataOut.data_cspc[pairsIndexListSelected] | |
206 | dataOut.pairsList = [dataOut.pairsList[i] |
|
206 | dataOut.pairsList = [dataOut.pairsList[i] | |
207 | for i in pairsIndexListSelected] |
|
207 | for i in pairsIndexListSelected] | |
208 |
|
208 | |||
209 | return dataOut |
|
209 | return dataOut | |
210 |
|
210 | |||
211 | class selectHeights(Operation): |
|
211 | class selectHeights(Operation): | |
212 |
|
212 | |||
213 | def run(self, dataOut, minHei=None, maxHei=None, minIndex=None, maxIndex=None): |
|
213 | def run(self, dataOut, minHei=None, maxHei=None, minIndex=None, maxIndex=None): | |
214 | """ |
|
214 | """ | |
215 | Selecciona un bloque de datos en base a un grupo de valores de alturas segun el rango |
|
215 | Selecciona un bloque de datos en base a un grupo de valores de alturas segun el rango | |
216 | minHei <= height <= maxHei |
|
216 | minHei <= height <= maxHei | |
217 |
|
217 | |||
218 | Input: |
|
218 | Input: | |
219 | minHei : valor minimo de altura a considerar |
|
219 | minHei : valor minimo de altura a considerar | |
220 | maxHei : valor maximo de altura a considerar |
|
220 | maxHei : valor maximo de altura a considerar | |
221 |
|
221 | |||
222 | Affected: |
|
222 | Affected: | |
223 | Indirectamente son cambiados varios valores a travez del metodo selectHeightsByIndex |
|
223 | Indirectamente son cambiados varios valores a travez del metodo selectHeightsByIndex | |
224 |
|
224 | |||
225 | Return: |
|
225 | Return: | |
226 | 1 si el metodo se ejecuto con exito caso contrario devuelve 0 |
|
226 | 1 si el metodo se ejecuto con exito caso contrario devuelve 0 | |
227 | """ |
|
227 | """ | |
228 |
|
228 | |||
229 | self.dataOut = dataOut |
|
229 | self.dataOut = dataOut | |
230 |
|
230 | |||
231 | if minHei and maxHei: |
|
231 | if minHei and maxHei: | |
232 |
|
232 | |||
233 | if (minHei < dataOut.heightList[0]): |
|
233 | if (minHei < dataOut.heightList[0]): | |
234 | minHei = dataOut.heightList[0] |
|
234 | minHei = dataOut.heightList[0] | |
235 |
|
235 | |||
236 | if (maxHei > dataOut.heightList[-1]): |
|
236 | if (maxHei > dataOut.heightList[-1]): | |
237 | maxHei = dataOut.heightList[-1] |
|
237 | maxHei = dataOut.heightList[-1] | |
238 |
|
238 | |||
239 | minIndex = 0 |
|
239 | minIndex = 0 | |
240 | maxIndex = 0 |
|
240 | maxIndex = 0 | |
241 | heights = dataOut.heightList |
|
241 | heights = dataOut.heightList | |
242 |
|
242 | |||
243 | inda = numpy.where(heights >= minHei) |
|
243 | inda = numpy.where(heights >= minHei) | |
244 | indb = numpy.where(heights <= maxHei) |
|
244 | indb = numpy.where(heights <= maxHei) | |
245 |
|
245 | |||
246 | try: |
|
246 | try: | |
247 | minIndex = inda[0][0] |
|
247 | minIndex = inda[0][0] | |
248 | except: |
|
248 | except: | |
249 | minIndex = 0 |
|
249 | minIndex = 0 | |
250 |
|
250 | |||
251 | try: |
|
251 | try: | |
252 | maxIndex = indb[0][-1] |
|
252 | maxIndex = indb[0][-1] | |
253 | except: |
|
253 | except: | |
254 | maxIndex = len(heights) |
|
254 | maxIndex = len(heights) | |
255 |
|
255 | |||
256 | self.selectHeightsByIndex(minIndex, maxIndex) |
|
256 | self.selectHeightsByIndex(minIndex, maxIndex) | |
257 |
|
257 | |||
258 | #update Processing Header: |
|
258 | #update Processing Header: | |
259 | dataOut.processingHeaderObj.heightList = dataOut.heightList |
|
259 | dataOut.processingHeaderObj.heightList = dataOut.heightList | |
260 |
|
260 | |||
261 |
|
261 | |||
262 |
|
262 | |||
263 | return dataOut |
|
263 | return dataOut | |
264 |
|
264 | |||
265 | def selectHeightsByIndex(self, minIndex, maxIndex): |
|
265 | def selectHeightsByIndex(self, minIndex, maxIndex): | |
266 | """ |
|
266 | """ | |
267 | Selecciona un bloque de datos en base a un grupo indices de alturas segun el rango |
|
267 | Selecciona un bloque de datos en base a un grupo indices de alturas segun el rango | |
268 | minIndex <= index <= maxIndex |
|
268 | minIndex <= index <= maxIndex | |
269 |
|
269 | |||
270 | Input: |
|
270 | Input: | |
271 | minIndex : valor de indice minimo de altura a considerar |
|
271 | minIndex : valor de indice minimo de altura a considerar | |
272 | maxIndex : valor de indice maximo de altura a considerar |
|
272 | maxIndex : valor de indice maximo de altura a considerar | |
273 |
|
273 | |||
274 | Affected: |
|
274 | Affected: | |
275 | self.dataOut.data |
|
275 | self.dataOut.data | |
276 | self.dataOut.heightList |
|
276 | self.dataOut.heightList | |
277 |
|
277 | |||
278 | Return: |
|
278 | Return: | |
279 | 1 si el metodo se ejecuto con exito caso contrario devuelve 0 |
|
279 | 1 si el metodo se ejecuto con exito caso contrario devuelve 0 | |
280 | """ |
|
280 | """ | |
281 |
|
281 | |||
282 | if self.dataOut.type == 'Voltage': |
|
282 | if self.dataOut.type == 'Voltage': | |
283 | if (minIndex < 0) or (minIndex > maxIndex): |
|
283 | if (minIndex < 0) or (minIndex > maxIndex): | |
284 | raise ValueError("Height index range (%d,%d) is not valid" % (minIndex, maxIndex)) |
|
284 | raise ValueError("Height index range (%d,%d) is not valid" % (minIndex, maxIndex)) | |
285 |
|
285 | |||
286 | if (maxIndex >= self.dataOut.nHeights): |
|
286 | if (maxIndex >= self.dataOut.nHeights): | |
287 | maxIndex = self.dataOut.nHeights |
|
287 | maxIndex = self.dataOut.nHeights | |
288 |
|
288 | |||
289 | #voltage |
|
289 | #voltage | |
290 | if self.dataOut.flagDataAsBlock: |
|
290 | if self.dataOut.flagDataAsBlock: | |
291 | """ |
|
291 | """ | |
292 | Si la data es obtenida por bloques, dimension = [nChannels, nProfiles, nHeis] |
|
292 | Si la data es obtenida por bloques, dimension = [nChannels, nProfiles, nHeis] | |
293 | """ |
|
293 | """ | |
294 | data = self.dataOut.data[:,:, minIndex:maxIndex] |
|
294 | data = self.dataOut.data[:,:, minIndex:maxIndex] | |
295 | else: |
|
295 | else: | |
296 | data = self.dataOut.data[:, minIndex:maxIndex] |
|
296 | data = self.dataOut.data[:, minIndex:maxIndex] | |
297 |
|
297 | |||
298 | # firstHeight = self.dataOut.heightList[minIndex] |
|
298 | # firstHeight = self.dataOut.heightList[minIndex] | |
299 |
|
299 | |||
300 | self.dataOut.data = data |
|
300 | self.dataOut.data = data | |
301 | self.dataOut.heightList = self.dataOut.heightList[minIndex:maxIndex] |
|
301 | self.dataOut.heightList = self.dataOut.heightList[minIndex:maxIndex] | |
302 |
|
302 | |||
303 | if self.dataOut.nHeights <= 1: |
|
303 | if self.dataOut.nHeights <= 1: | |
304 | raise ValueError("selectHeights: Too few heights. Current number of heights is %d" %(self.dataOut.nHeights)) |
|
304 | raise ValueError("selectHeights: Too few heights. Current number of heights is %d" %(self.dataOut.nHeights)) | |
305 | elif self.dataOut.type == 'Spectra': |
|
305 | elif self.dataOut.type == 'Spectra': | |
306 | if (minIndex < 0) or (minIndex > maxIndex): |
|
306 | if (minIndex < 0) or (minIndex > maxIndex): | |
307 | raise ValueError("Error selecting heights: Index range (%d,%d) is not valid" % ( |
|
307 | raise ValueError("Error selecting heights: Index range (%d,%d) is not valid" % ( | |
308 | minIndex, maxIndex)) |
|
308 | minIndex, maxIndex)) | |
309 |
|
309 | |||
310 | if (maxIndex >= self.dataOut.nHeights): |
|
310 | if (maxIndex >= self.dataOut.nHeights): | |
311 | maxIndex = self.dataOut.nHeights - 1 |
|
311 | maxIndex = self.dataOut.nHeights - 1 | |
312 |
|
312 | |||
313 | # Spectra |
|
313 | # Spectra | |
314 | data_spc = self.dataOut.data_spc[:, :, minIndex:maxIndex + 1] |
|
314 | data_spc = self.dataOut.data_spc[:, :, minIndex:maxIndex + 1] | |
315 |
|
315 | |||
316 | data_cspc = None |
|
316 | data_cspc = None | |
317 | if self.dataOut.data_cspc is not None: |
|
317 | if self.dataOut.data_cspc is not None: | |
318 | data_cspc = self.dataOut.data_cspc[:, :, minIndex:maxIndex + 1] |
|
318 | data_cspc = self.dataOut.data_cspc[:, :, minIndex:maxIndex + 1] | |
319 |
|
319 | |||
320 | data_dc = None |
|
320 | data_dc = None | |
321 | if self.dataOut.data_dc is not None: |
|
321 | if self.dataOut.data_dc is not None: | |
322 | data_dc = self.dataOut.data_dc[:, minIndex:maxIndex + 1] |
|
322 | data_dc = self.dataOut.data_dc[:, minIndex:maxIndex + 1] | |
323 |
|
323 | |||
324 | self.dataOut.data_spc = data_spc |
|
324 | self.dataOut.data_spc = data_spc | |
325 | self.dataOut.data_cspc = data_cspc |
|
325 | self.dataOut.data_cspc = data_cspc | |
326 | self.dataOut.data_dc = data_dc |
|
326 | self.dataOut.data_dc = data_dc | |
327 |
|
327 | |||
328 | self.dataOut.heightList = self.dataOut.heightList[minIndex:maxIndex + 1] |
|
328 | self.dataOut.heightList = self.dataOut.heightList[minIndex:maxIndex + 1] | |
329 |
|
329 | |||
330 | return 1 |
|
330 | return 1 | |
331 |
|
331 | |||
332 |
|
332 | |||
333 | class filterByHeights(Operation): |
|
333 | class filterByHeights(Operation): | |
334 | ifConfig=False |
|
334 | ifConfig=False | |
335 | deltaHeight = None |
|
335 | deltaHeight = None | |
336 | newdelta=None |
|
336 | newdelta=None | |
337 | newheights=None |
|
337 | newheights=None | |
338 | r=None |
|
338 | r=None | |
339 | h0=None |
|
339 | h0=None | |
340 | nHeights=None |
|
340 | nHeights=None | |
341 | def run(self, dataOut, window): |
|
341 | def run(self, dataOut, window): | |
342 |
|
342 | |||
343 |
|
343 | |||
344 | # print("1",dataOut.data.shape) |
|
344 | # print("1",dataOut.data.shape) | |
345 | # print(dataOut.nHeights) |
|
345 | # print(dataOut.nHeights) | |
346 | if window == None: |
|
346 | if window == None: | |
347 | window = (dataOut.radarControllerHeaderObj.txA/dataOut.radarControllerHeaderObj.nBaud) / self.deltaHeight |
|
347 | window = (dataOut.radarControllerHeaderObj.txA/dataOut.radarControllerHeaderObj.nBaud) / self.deltaHeight | |
348 |
|
348 | |||
349 | if not self.ifConfig: #and dataOut.useInputBuffer: |
|
349 | if not self.ifConfig: #and dataOut.useInputBuffer: | |
350 | self.deltaHeight = dataOut.heightList[1] - dataOut.heightList[0] |
|
350 | self.deltaHeight = dataOut.heightList[1] - dataOut.heightList[0] | |
351 | self.ifConfig = True |
|
351 | self.ifConfig = True | |
352 | self.newdelta = self.deltaHeight * window |
|
352 | self.newdelta = self.deltaHeight * window | |
353 | self.r = dataOut.nHeights % window |
|
353 | self.r = dataOut.nHeights % window | |
354 | self.newheights = (dataOut.nHeights-self.r)/window |
|
354 | self.newheights = (dataOut.nHeights-self.r)/window | |
355 | self.h0 = dataOut.heightList[0] |
|
355 | self.h0 = dataOut.heightList[0] | |
356 | self.nHeights = dataOut.nHeights |
|
356 | self.nHeights = dataOut.nHeights | |
357 | if self.newheights <= 1: |
|
357 | if self.newheights <= 1: | |
358 | raise ValueError("filterByHeights: Too few heights. Current number of heights is %d and window is %d" %(dataOut.nHeights, window)) |
|
358 | raise ValueError("filterByHeights: Too few heights. Current number of heights is %d and window is %d" %(dataOut.nHeights, window)) | |
359 |
|
359 | |||
360 | if dataOut.flagDataAsBlock: |
|
360 | if dataOut.flagDataAsBlock: | |
361 | """ |
|
361 | """ | |
362 | Si la data es obtenida por bloques, dimension = [nChannels, nProfiles, nHeis] |
|
362 | Si la data es obtenida por bloques, dimension = [nChannels, nProfiles, nHeis] | |
363 | """ |
|
363 | """ | |
364 | buffer = dataOut.data[:, :, 0:int(self.nHeights-self.r)] |
|
364 | buffer = dataOut.data[:, :, 0:int(self.nHeights-self.r)] | |
365 | buffer = buffer.reshape(dataOut.nChannels, dataOut.nProfiles, int(self.nHeights/window), window) |
|
365 | buffer = buffer.reshape(dataOut.nChannels, dataOut.nProfiles, int(self.nHeights/window), window) | |
366 | buffer = numpy.sum(buffer,3) |
|
366 | buffer = numpy.sum(buffer,3) | |
367 |
|
367 | |||
368 | else: |
|
368 | else: | |
369 | buffer = dataOut.data[:,0:int(self.nHeights-self.r)] |
|
369 | buffer = dataOut.data[:,0:int(self.nHeights-self.r)] | |
370 | buffer = buffer.reshape(dataOut.nChannels,int(self.nHeights/window),int(window)) |
|
370 | buffer = buffer.reshape(dataOut.nChannels,int(self.nHeights/window),int(window)) | |
371 | buffer = numpy.sum(buffer,2) |
|
371 | buffer = numpy.sum(buffer,2) | |
372 |
|
372 | |||
373 | dataOut.data = buffer |
|
373 | dataOut.data = buffer | |
374 | dataOut.heightList = self.h0 + numpy.arange( self.newheights )*self.newdelta |
|
374 | dataOut.heightList = self.h0 + numpy.arange( self.newheights )*self.newdelta | |
375 | dataOut.windowOfFilter = window |
|
375 | dataOut.windowOfFilter = window | |
376 |
|
376 | |||
377 | #update Processing Header: |
|
377 | #update Processing Header: | |
378 | dataOut.processingHeaderObj.heightList = dataOut.heightList |
|
378 | dataOut.processingHeaderObj.heightList = dataOut.heightList | |
379 | dataOut.processingHeaderObj.nWindows = window |
|
379 | dataOut.processingHeaderObj.nWindows = window | |
380 |
|
380 | |||
381 | return dataOut |
|
381 | return dataOut | |
382 |
|
382 | |||
383 |
|
383 | |||
384 |
|
384 | |||
385 | class setH0(Operation): |
|
385 | class setH0(Operation): | |
386 |
|
386 | |||
387 | def run(self, dataOut, h0, deltaHeight = None): |
|
387 | def run(self, dataOut, h0, deltaHeight = None): | |
388 |
|
388 | |||
389 | if not deltaHeight: |
|
389 | if not deltaHeight: | |
390 | deltaHeight = dataOut.heightList[1] - dataOut.heightList[0] |
|
390 | deltaHeight = dataOut.heightList[1] - dataOut.heightList[0] | |
391 |
|
391 | |||
392 | nHeights = dataOut.nHeights |
|
392 | nHeights = dataOut.nHeights | |
393 |
|
393 | |||
394 | newHeiRange = h0 + numpy.arange(nHeights)*deltaHeight |
|
394 | newHeiRange = h0 + numpy.arange(nHeights)*deltaHeight | |
395 |
|
395 | |||
396 | dataOut.heightList = newHeiRange |
|
396 | dataOut.heightList = newHeiRange | |
397 |
|
397 | |||
398 | #update Processing Header: |
|
398 | #update Processing Header: | |
399 | dataOut.processingHeaderObj.heightList = dataOut.heightList |
|
399 | dataOut.processingHeaderObj.heightList = dataOut.heightList | |
400 |
|
400 | |||
401 | return dataOut |
|
401 | return dataOut | |
402 |
|
402 | |||
403 |
|
403 | |||
404 | class deFlip(Operation): |
|
404 | class deFlip(Operation): | |
405 |
|
405 | |||
406 | def run(self, dataOut, channelList = []): |
|
406 | def run(self, dataOut, channelList = []): | |
407 |
|
407 | |||
408 | data = dataOut.data.copy() |
|
408 | data = dataOut.data.copy() | |
409 |
|
409 | |||
410 | if dataOut.flagDataAsBlock: |
|
410 | if dataOut.flagDataAsBlock: | |
411 | flip = self.flip |
|
411 | flip = self.flip | |
412 | profileList = list(range(dataOut.nProfiles)) |
|
412 | profileList = list(range(dataOut.nProfiles)) | |
413 |
|
413 | |||
414 | if not channelList: |
|
414 | if not channelList: | |
415 | for thisProfile in profileList: |
|
415 | for thisProfile in profileList: | |
416 | data[:,thisProfile,:] = data[:,thisProfile,:]*flip |
|
416 | data[:,thisProfile,:] = data[:,thisProfile,:]*flip | |
417 | flip *= -1.0 |
|
417 | flip *= -1.0 | |
418 | else: |
|
418 | else: | |
419 | for thisChannel in channelList: |
|
419 | for thisChannel in channelList: | |
420 | if thisChannel not in dataOut.channelList: |
|
420 | if thisChannel not in dataOut.channelList: | |
421 | continue |
|
421 | continue | |
422 |
|
422 | |||
423 | for thisProfile in profileList: |
|
423 | for thisProfile in profileList: | |
424 | data[thisChannel,thisProfile,:] = data[thisChannel,thisProfile,:]*flip |
|
424 | data[thisChannel,thisProfile,:] = data[thisChannel,thisProfile,:]*flip | |
425 | flip *= -1.0 |
|
425 | flip *= -1.0 | |
426 |
|
426 | |||
427 | self.flip = flip |
|
427 | self.flip = flip | |
428 |
|
428 | |||
429 | else: |
|
429 | else: | |
430 | if not channelList: |
|
430 | if not channelList: | |
431 | data[:,:] = data[:,:]*self.flip |
|
431 | data[:,:] = data[:,:]*self.flip | |
432 | else: |
|
432 | else: | |
433 | for thisChannel in channelList: |
|
433 | for thisChannel in channelList: | |
434 | if thisChannel not in dataOut.channelList: |
|
434 | if thisChannel not in dataOut.channelList: | |
435 | continue |
|
435 | continue | |
436 |
|
436 | |||
437 | data[thisChannel,:] = data[thisChannel,:]*self.flip |
|
437 | data[thisChannel,:] = data[thisChannel,:]*self.flip | |
438 |
|
438 | |||
439 | self.flip *= -1. |
|
439 | self.flip *= -1. | |
440 |
|
440 | |||
441 | dataOut.data = data |
|
441 | dataOut.data = data | |
442 |
|
442 | |||
443 | return dataOut |
|
443 | return dataOut | |
444 |
|
444 | |||
445 |
|
445 | |||
446 | class setAttribute(Operation): |
|
446 | class setAttribute(Operation): | |
447 | ''' |
|
447 | ''' | |
448 | Set an arbitrary attribute(s) to dataOut |
|
448 | Set an arbitrary attribute(s) to dataOut | |
449 | ''' |
|
449 | ''' | |
450 |
|
450 | |||
451 | def __init__(self): |
|
451 | def __init__(self): | |
452 |
|
452 | |||
453 | Operation.__init__(self) |
|
453 | Operation.__init__(self) | |
454 | self._ready = False |
|
454 | self._ready = False | |
455 |
|
455 | |||
456 | def run(self, dataOut, **kwargs): |
|
456 | def run(self, dataOut, **kwargs): | |
457 |
|
457 | |||
458 | for key, value in kwargs.items(): |
|
458 | for key, value in kwargs.items(): | |
459 | setattr(dataOut, key, value) |
|
459 | setattr(dataOut, key, value) | |
460 |
|
460 | |||
461 | return dataOut |
|
461 | return dataOut | |
462 |
|
462 | |||
463 |
|
463 | |||
464 | @MPDecorator |
|
464 | @MPDecorator | |
465 | class printAttribute(Operation): |
|
465 | class printAttribute(Operation): | |
466 | ''' |
|
466 | ''' | |
467 | Print an arbitrary attribute of dataOut |
|
467 | Print an arbitrary attribute of dataOut | |
468 | ''' |
|
468 | ''' | |
469 |
|
469 | |||
470 | def __init__(self): |
|
470 | def __init__(self): | |
471 |
|
471 | |||
472 | Operation.__init__(self) |
|
472 | Operation.__init__(self) | |
473 |
|
473 | |||
474 | def run(self, dataOut, attributes): |
|
474 | def run(self, dataOut, attributes): | |
475 |
|
475 | |||
476 | if isinstance(attributes, str): |
|
476 | if isinstance(attributes, str): | |
477 | attributes = [attributes] |
|
477 | attributes = [attributes] | |
478 | for attr in attributes: |
|
478 | for attr in attributes: | |
479 | if hasattr(dataOut, attr): |
|
479 | if hasattr(dataOut, attr): | |
480 | log.log(getattr(dataOut, attr), attr) |
|
480 | log.log(getattr(dataOut, attr), attr) | |
481 |
|
481 | |||
482 | class cleanHeightsInterf(Operation): |
|
482 | class cleanHeightsInterf(Operation): | |
483 | __slots__ =('heights_indx', 'repeats', 'step', 'factor', 'idate', 'idxs','config','wMask') |
|
483 | __slots__ =('heights_indx', 'repeats', 'step', 'factor', 'idate', 'idxs','config','wMask') | |
484 | def __init__(self): |
|
484 | def __init__(self): | |
485 | self.repeats = 0 |
|
485 | self.repeats = 0 | |
486 | self.factor=1 |
|
486 | self.factor=1 | |
487 | self.wMask = None |
|
487 | self.wMask = None | |
488 | self.config = False |
|
488 | self.config = False | |
489 | self.idxs = None |
|
489 | self.idxs = None | |
490 | self.heights_indx = None |
|
490 | self.heights_indx = None | |
491 |
|
491 | |||
492 | def run(self, dataOut, heightsList, repeats=0, step=0, factor=1, idate=None, startH=None, endH=None): |
|
492 | def run(self, dataOut, heightsList, repeats=0, step=0, factor=1, idate=None, startH=None, endH=None): | |
493 |
|
493 | |||
494 | #print(dataOut.data.shape) |
|
494 | #print(dataOut.data.shape) | |
495 |
|
495 | |||
496 | startTime = datetime.datetime.combine(idate,startH) |
|
496 | startTime = datetime.datetime.combine(idate,startH) | |
497 | endTime = datetime.datetime.combine(idate,endH) |
|
497 | endTime = datetime.datetime.combine(idate,endH) | |
498 | currentTime = datetime.datetime.fromtimestamp(dataOut.utctime) |
|
498 | currentTime = datetime.datetime.fromtimestamp(dataOut.utctime) | |
499 |
|
499 | |||
500 | if currentTime < startTime or currentTime > endTime: |
|
500 | if currentTime < startTime or currentTime > endTime: | |
501 | return dataOut |
|
501 | return dataOut | |
502 | if not self.config: |
|
502 | if not self.config: | |
503 |
|
503 | |||
504 | #print(wMask) |
|
504 | #print(wMask) | |
505 | heights = [float(hei) for hei in heightsList] |
|
505 | heights = [float(hei) for hei in heightsList] | |
506 | for r in range(repeats): |
|
506 | for r in range(repeats): | |
507 | heights += [ (h+(step*(r+1))) for h in heights] |
|
507 | heights += [ (h+(step*(r+1))) for h in heights] | |
508 | #print(heights) |
|
508 | #print(heights) | |
509 | heiList = dataOut.heightList |
|
509 | heiList = dataOut.heightList | |
510 | self.heights_indx = [getHei_index(h,h,heiList)[0] for h in heights] |
|
510 | self.heights_indx = [getHei_index(h,h,heiList)[0] for h in heights] | |
511 |
|
511 | |||
512 | self.wMask = numpy.asarray(factor) |
|
512 | self.wMask = numpy.asarray(factor) | |
513 | self.wMask = numpy.tile(self.wMask,(repeats+2)) |
|
513 | self.wMask = numpy.tile(self.wMask,(repeats+2)) | |
514 | self.config = True |
|
514 | self.config = True | |
515 |
|
515 | |||
516 | """ |
|
516 | """ | |
517 | getNoisebyHildebrand(self, channel=None, ymin_index=None, ymax_index=None) |
|
517 | getNoisebyHildebrand(self, channel=None, ymin_index=None, ymax_index=None) | |
518 | """ |
|
518 | """ | |
519 | #print(self.noise =10*numpy.log10(dataOut.getNoisebyHildebrand(ymin_index=self.min_ref, ymax_index=self.max_ref))) |
|
519 | #print(self.noise =10*numpy.log10(dataOut.getNoisebyHildebrand(ymin_index=self.min_ref, ymax_index=self.max_ref))) | |
520 |
|
520 | |||
521 |
|
521 | |||
522 | for ch in range(dataOut.data.shape[0]): |
|
522 | for ch in range(dataOut.data.shape[0]): | |
523 | i = 0 |
|
523 | i = 0 | |
524 |
|
524 | |||
525 |
|
525 | |||
526 | for hei in self.heights_indx: |
|
526 | for hei in self.heights_indx: | |
527 | h = hei - 1 |
|
527 | h = hei - 1 | |
528 |
|
528 | |||
529 |
|
529 | |||
530 | if dataOut.data.ndim < 3: |
|
530 | if dataOut.data.ndim < 3: | |
531 | module = numpy.absolute(dataOut.data[ch,h]) |
|
531 | module = numpy.absolute(dataOut.data[ch,h]) | |
532 | prev_h1 = numpy.absolute(dataOut.data[ch,h-1]) |
|
532 | prev_h1 = numpy.absolute(dataOut.data[ch,h-1]) | |
533 | dataOut.data[ch,h] = (dataOut.data[ch,h])/module * prev_h1 |
|
533 | dataOut.data[ch,h] = (dataOut.data[ch,h])/module * prev_h1 | |
534 |
|
534 | |||
535 | #dataOut.data[ch,hei-1] = (dataOut.data[ch,hei-1])*self.wMask[i] |
|
535 | #dataOut.data[ch,hei-1] = (dataOut.data[ch,hei-1])*self.wMask[i] | |
536 | else: |
|
536 | else: | |
537 | module = numpy.absolute(dataOut.data[ch,:,h]) |
|
537 | module = numpy.absolute(dataOut.data[ch,:,h]) | |
538 | prev_h1 = numpy.absolute(dataOut.data[ch,:,h-1]) |
|
538 | prev_h1 = numpy.absolute(dataOut.data[ch,:,h-1]) | |
539 | dataOut.data[ch,:,h] = (dataOut.data[ch,:,h])/module * prev_h1 |
|
539 | dataOut.data[ch,:,h] = (dataOut.data[ch,:,h])/module * prev_h1 | |
540 | #dataOut.data[ch,:,hei-1] = (dataOut.data[ch,:,hei-1])*self.wMask[i] |
|
540 | #dataOut.data[ch,:,hei-1] = (dataOut.data[ch,:,hei-1])*self.wMask[i] | |
541 | #print("done") |
|
541 | #print("done") | |
542 | i += 1 |
|
542 | i += 1 | |
543 |
|
543 | |||
544 |
|
544 | |||
545 | return dataOut |
|
545 | return dataOut | |
546 |
|
546 | |||
547 |
|
547 | |||
548 |
|
548 | |||
549 | class interpolateHeights(Operation): |
|
549 | class interpolateHeights(Operation): | |
550 |
|
550 | |||
551 | def run(self, dataOut, topLim, botLim): |
|
551 | def run(self, dataOut, topLim, botLim): | |
552 | #69 al 72 para julia |
|
552 | #69 al 72 para julia | |
553 | #82-84 para meteoros |
|
553 | #82-84 para meteoros | |
554 | if len(numpy.shape(dataOut.data))==2: |
|
554 | if len(numpy.shape(dataOut.data))==2: | |
555 | sampInterp = (dataOut.data[:,botLim-1] + dataOut.data[:,topLim+1])/2 |
|
555 | sampInterp = (dataOut.data[:,botLim-1] + dataOut.data[:,topLim+1])/2 | |
556 | sampInterp = numpy.transpose(numpy.tile(sampInterp,(topLim-botLim + 1,1))) |
|
556 | sampInterp = numpy.transpose(numpy.tile(sampInterp,(topLim-botLim + 1,1))) | |
557 | #dataOut.data[:,botLim:limSup+1] = sampInterp |
|
557 | #dataOut.data[:,botLim:limSup+1] = sampInterp | |
558 | dataOut.data[:,botLim:topLim+1] = sampInterp |
|
558 | dataOut.data[:,botLim:topLim+1] = sampInterp | |
559 | else: |
|
559 | else: | |
560 | nHeights = dataOut.data.shape[2] |
|
560 | nHeights = dataOut.data.shape[2] | |
561 | x = numpy.hstack((numpy.arange(botLim),numpy.arange(topLim+1,nHeights))) |
|
561 | x = numpy.hstack((numpy.arange(botLim),numpy.arange(topLim+1,nHeights))) | |
562 | y = dataOut.data[:,:,list(range(botLim))+list(range(topLim+1,nHeights))] |
|
562 | y = dataOut.data[:,:,list(range(botLim))+list(range(topLim+1,nHeights))] | |
563 | f = interpolate.interp1d(x, y, axis = 2) |
|
563 | f = interpolate.interp1d(x, y, axis = 2) | |
564 | xnew = numpy.arange(botLim,topLim+1) |
|
564 | xnew = numpy.arange(botLim,topLim+1) | |
565 | ynew = f(xnew) |
|
565 | ynew = f(xnew) | |
566 | dataOut.data[:,:,botLim:topLim+1] = ynew |
|
566 | dataOut.data[:,:,botLim:topLim+1] = ynew | |
567 |
|
567 | |||
568 | return dataOut |
|
568 | return dataOut | |
569 |
|
569 | |||
570 |
|
570 | |||
571 | class CohInt(Operation): |
|
571 | class CohInt(Operation): | |
572 |
|
572 | |||
573 | isConfig = False |
|
573 | isConfig = False | |
574 | __profIndex = 0 |
|
574 | __profIndex = 0 | |
575 | __byTime = False |
|
575 | __byTime = False | |
576 | __initime = None |
|
576 | __initime = None | |
577 | __lastdatatime = None |
|
577 | __lastdatatime = None | |
578 | __integrationtime = None |
|
578 | __integrationtime = None | |
579 | __buffer = None |
|
579 | __buffer = None | |
580 | __bufferStride = [] |
|
580 | __bufferStride = [] | |
581 | __dataReady = False |
|
581 | __dataReady = False | |
582 | __profIndexStride = 0 |
|
582 | __profIndexStride = 0 | |
583 | __dataToPutStride = False |
|
583 | __dataToPutStride = False | |
584 | n = None |
|
584 | n = None | |
585 |
|
585 | |||
586 | def __init__(self, **kwargs): |
|
586 | def __init__(self, **kwargs): | |
587 |
|
587 | |||
588 | Operation.__init__(self, **kwargs) |
|
588 | Operation.__init__(self, **kwargs) | |
589 |
|
589 | |||
590 | def setup(self, n=None, timeInterval=None, stride=None, overlapping=False, byblock=False): |
|
590 | def setup(self, n=None, timeInterval=None, stride=None, overlapping=False, byblock=False): | |
591 | """ |
|
591 | """ | |
592 | Set the parameters of the integration class. |
|
592 | Set the parameters of the integration class. | |
593 |
|
593 | |||
594 | Inputs: |
|
594 | Inputs: | |
595 |
|
595 | |||
596 | n : Number of coherent integrations |
|
596 | n : Number of coherent integrations | |
597 | timeInterval : Time of integration. If the parameter "n" is selected this one does not work |
|
597 | timeInterval : Time of integration. If the parameter "n" is selected this one does not work | |
598 | overlapping : |
|
598 | overlapping : | |
599 | """ |
|
599 | """ | |
600 |
|
600 | |||
601 | self.__initime = None |
|
601 | self.__initime = None | |
602 | self.__lastdatatime = 0 |
|
602 | self.__lastdatatime = 0 | |
603 | self.__buffer = None |
|
603 | self.__buffer = None | |
604 | self.__dataReady = False |
|
604 | self.__dataReady = False | |
605 | self.byblock = byblock |
|
605 | self.byblock = byblock | |
606 | self.stride = stride |
|
606 | self.stride = stride | |
607 |
|
607 | |||
608 | if n == None and timeInterval == None: |
|
608 | if n == None and timeInterval == None: | |
609 | raise ValueError("n or timeInterval should be specified ...") |
|
609 | raise ValueError("n or timeInterval should be specified ...") | |
610 |
|
610 | |||
611 | if n != None: |
|
611 | if n != None: | |
612 | self.n = n |
|
612 | self.n = n | |
613 | self.__byTime = False |
|
613 | self.__byTime = False | |
614 | else: |
|
614 | else: | |
615 | self.__integrationtime = timeInterval #* 60. #if (type(timeInterval)!=integer) -> change this line |
|
615 | self.__integrationtime = timeInterval #* 60. #if (type(timeInterval)!=integer) -> change this line | |
616 | self.n = 9999 |
|
616 | self.n = 9999 | |
617 | self.__byTime = True |
|
617 | self.__byTime = True | |
618 |
|
618 | |||
619 | if overlapping: |
|
619 | if overlapping: | |
620 | self.__withOverlapping = True |
|
620 | self.__withOverlapping = True | |
621 | self.__buffer = None |
|
621 | self.__buffer = None | |
622 | else: |
|
622 | else: | |
623 | self.__withOverlapping = False |
|
623 | self.__withOverlapping = False | |
624 | self.__buffer = 0 |
|
624 | self.__buffer = 0 | |
625 |
|
625 | |||
626 | self.__profIndex = 0 |
|
626 | self.__profIndex = 0 | |
627 |
|
627 | |||
628 | def putData(self, data): |
|
628 | def putData(self, data): | |
629 |
|
629 | |||
630 | """ |
|
630 | """ | |
631 | Add a profile to the __buffer and increase in one the __profileIndex |
|
631 | Add a profile to the __buffer and increase in one the __profileIndex | |
632 |
|
632 | |||
633 | """ |
|
633 | """ | |
634 |
|
634 | |||
635 | if not self.__withOverlapping: |
|
635 | if not self.__withOverlapping: | |
636 | self.__buffer += data.copy() |
|
636 | self.__buffer += data.copy() | |
637 | self.__profIndex += 1 |
|
637 | self.__profIndex += 1 | |
638 | return |
|
638 | return | |
639 |
|
639 | |||
640 | #Overlapping data |
|
640 | #Overlapping data | |
641 | nChannels, nHeis = data.shape |
|
641 | nChannels, nHeis = data.shape | |
642 | data = numpy.reshape(data, (1, nChannels, nHeis)) |
|
642 | data = numpy.reshape(data, (1, nChannels, nHeis)) | |
643 |
|
643 | |||
644 | #If the buffer is empty then it takes the data value |
|
644 | #If the buffer is empty then it takes the data value | |
645 | if self.__buffer is None: |
|
645 | if self.__buffer is None: | |
646 | self.__buffer = data |
|
646 | self.__buffer = data | |
647 | self.__profIndex += 1 |
|
647 | self.__profIndex += 1 | |
648 | return |
|
648 | return | |
649 |
|
649 | |||
650 | #If the buffer length is lower than n then stakcing the data value |
|
650 | #If the buffer length is lower than n then stakcing the data value | |
651 | if self.__profIndex < self.n: |
|
651 | if self.__profIndex < self.n: | |
652 | self.__buffer = numpy.vstack((self.__buffer, data)) |
|
652 | self.__buffer = numpy.vstack((self.__buffer, data)) | |
653 | self.__profIndex += 1 |
|
653 | self.__profIndex += 1 | |
654 | return |
|
654 | return | |
655 |
|
655 | |||
656 | #If the buffer length is equal to n then replacing the last buffer value with the data value |
|
656 | #If the buffer length is equal to n then replacing the last buffer value with the data value | |
657 | self.__buffer = numpy.roll(self.__buffer, -1, axis=0) |
|
657 | self.__buffer = numpy.roll(self.__buffer, -1, axis=0) | |
658 | self.__buffer[self.n-1] = data |
|
658 | self.__buffer[self.n-1] = data | |
659 | self.__profIndex = self.n |
|
659 | self.__profIndex = self.n | |
660 | return |
|
660 | return | |
661 |
|
661 | |||
662 |
|
662 | |||
663 | def pushData(self): |
|
663 | def pushData(self): | |
664 | """ |
|
664 | """ | |
665 | Return the sum of the last profiles and the profiles used in the sum. |
|
665 | Return the sum of the last profiles and the profiles used in the sum. | |
666 |
|
666 | |||
667 | Affected: |
|
667 | Affected: | |
668 |
|
668 | |||
669 | self.__profileIndex |
|
669 | self.__profileIndex | |
670 |
|
670 | |||
671 | """ |
|
671 | """ | |
672 |
|
672 | |||
673 | if not self.__withOverlapping: |
|
673 | if not self.__withOverlapping: | |
674 | data = self.__buffer |
|
674 | data = self.__buffer | |
675 | n = self.__profIndex |
|
675 | n = self.__profIndex | |
676 |
|
676 | |||
677 | self.__buffer = 0 |
|
677 | self.__buffer = 0 | |
678 | self.__profIndex = 0 |
|
678 | self.__profIndex = 0 | |
679 |
|
679 | |||
680 | return data, n |
|
680 | return data, n | |
681 |
|
681 | |||
682 | #Integration with Overlapping |
|
682 | #Integration with Overlapping | |
683 | data = numpy.sum(self.__buffer, axis=0) |
|
683 | data = numpy.sum(self.__buffer, axis=0) | |
684 | # print data |
|
684 | # print data | |
685 | # raise |
|
685 | # raise | |
686 | n = self.__profIndex |
|
686 | n = self.__profIndex | |
687 |
|
687 | |||
688 | return data, n |
|
688 | return data, n | |
689 |
|
689 | |||
690 | def byProfiles(self, data): |
|
690 | def byProfiles(self, data): | |
691 |
|
691 | |||
692 | self.__dataReady = False |
|
692 | self.__dataReady = False | |
693 | avgdata = None |
|
693 | avgdata = None | |
694 | # n = None |
|
694 | # n = None | |
695 | # print data |
|
695 | # print data | |
696 | # raise |
|
696 | # raise | |
697 | self.putData(data) |
|
697 | self.putData(data) | |
698 |
|
698 | |||
699 | if self.__profIndex == self.n: |
|
699 | if self.__profIndex == self.n: | |
700 | avgdata, n = self.pushData() |
|
700 | avgdata, n = self.pushData() | |
701 | self.__dataReady = True |
|
701 | self.__dataReady = True | |
702 |
|
702 | |||
703 | return avgdata |
|
703 | return avgdata | |
704 |
|
704 | |||
705 | def byTime(self, data, datatime): |
|
705 | def byTime(self, data, datatime): | |
706 |
|
706 | |||
707 | self.__dataReady = False |
|
707 | self.__dataReady = False | |
708 | avgdata = None |
|
708 | avgdata = None | |
709 | n = None |
|
709 | n = None | |
710 |
|
710 | |||
711 | self.putData(data) |
|
711 | self.putData(data) | |
712 |
|
712 | |||
713 | if (datatime - self.__initime) >= self.__integrationtime: |
|
713 | if (datatime - self.__initime) >= self.__integrationtime: | |
714 | avgdata, n = self.pushData() |
|
714 | avgdata, n = self.pushData() | |
715 | self.n = n |
|
715 | self.n = n | |
716 | self.__dataReady = True |
|
716 | self.__dataReady = True | |
717 |
|
717 | |||
718 | return avgdata |
|
718 | return avgdata | |
719 |
|
719 | |||
720 | def integrateByStride(self, data, datatime): |
|
720 | def integrateByStride(self, data, datatime): | |
721 | # print data |
|
721 | # print data | |
722 | if self.__profIndex == 0: |
|
722 | if self.__profIndex == 0: | |
723 | self.__buffer = [[data.copy(), datatime]] |
|
723 | self.__buffer = [[data.copy(), datatime]] | |
724 | else: |
|
724 | else: | |
725 | self.__buffer.append([data.copy(),datatime]) |
|
725 | self.__buffer.append([data.copy(),datatime]) | |
726 | self.__profIndex += 1 |
|
726 | self.__profIndex += 1 | |
727 | self.__dataReady = False |
|
727 | self.__dataReady = False | |
728 |
|
728 | |||
729 | if self.__profIndex == self.n * self.stride : |
|
729 | if self.__profIndex == self.n * self.stride : | |
730 | self.__dataToPutStride = True |
|
730 | self.__dataToPutStride = True | |
731 | self.__profIndexStride = 0 |
|
731 | self.__profIndexStride = 0 | |
732 | self.__profIndex = 0 |
|
732 | self.__profIndex = 0 | |
733 | self.__bufferStride = [] |
|
733 | self.__bufferStride = [] | |
734 | for i in range(self.stride): |
|
734 | for i in range(self.stride): | |
735 | current = self.__buffer[i::self.stride] |
|
735 | current = self.__buffer[i::self.stride] | |
736 | data = numpy.sum([t[0] for t in current], axis=0) |
|
736 | data = numpy.sum([t[0] for t in current], axis=0) | |
737 | avgdatatime = numpy.average([t[1] for t in current]) |
|
737 | avgdatatime = numpy.average([t[1] for t in current]) | |
738 | # print data |
|
738 | # print data | |
739 | self.__bufferStride.append((data, avgdatatime)) |
|
739 | self.__bufferStride.append((data, avgdatatime)) | |
740 |
|
740 | |||
741 | if self.__dataToPutStride: |
|
741 | if self.__dataToPutStride: | |
742 | self.__dataReady = True |
|
742 | self.__dataReady = True | |
743 | self.__profIndexStride += 1 |
|
743 | self.__profIndexStride += 1 | |
744 | if self.__profIndexStride == self.stride: |
|
744 | if self.__profIndexStride == self.stride: | |
745 | self.__dataToPutStride = False |
|
745 | self.__dataToPutStride = False | |
746 | # print self.__bufferStride[self.__profIndexStride - 1] |
|
746 | # print self.__bufferStride[self.__profIndexStride - 1] | |
747 | # raise |
|
747 | # raise | |
748 | return self.__bufferStride[self.__profIndexStride - 1] |
|
748 | return self.__bufferStride[self.__profIndexStride - 1] | |
749 |
|
749 | |||
750 |
|
750 | |||
751 | return None, None |
|
751 | return None, None | |
752 |
|
752 | |||
753 | def integrate(self, data, datatime=None): |
|
753 | def integrate(self, data, datatime=None): | |
754 |
|
754 | |||
755 | if self.__initime == None: |
|
755 | if self.__initime == None: | |
756 | self.__initime = datatime |
|
756 | self.__initime = datatime | |
757 |
|
757 | |||
758 | if self.__byTime: |
|
758 | if self.__byTime: | |
759 | avgdata = self.byTime(data, datatime) |
|
759 | avgdata = self.byTime(data, datatime) | |
760 | else: |
|
760 | else: | |
761 | avgdata = self.byProfiles(data) |
|
761 | avgdata = self.byProfiles(data) | |
762 |
|
762 | |||
763 |
|
763 | |||
764 | self.__lastdatatime = datatime |
|
764 | self.__lastdatatime = datatime | |
765 |
|
765 | |||
766 | if avgdata is None: |
|
766 | if avgdata is None: | |
767 | return None, None |
|
767 | return None, None | |
768 |
|
768 | |||
769 | avgdatatime = self.__initime |
|
769 | avgdatatime = self.__initime | |
770 |
|
770 | |||
771 | deltatime = datatime - self.__lastdatatime |
|
771 | deltatime = datatime - self.__lastdatatime | |
772 |
|
772 | |||
773 | if not self.__withOverlapping: |
|
773 | if not self.__withOverlapping: | |
774 | self.__initime = datatime |
|
774 | self.__initime = datatime | |
775 | else: |
|
775 | else: | |
776 | self.__initime += deltatime |
|
776 | self.__initime += deltatime | |
777 |
|
777 | |||
778 | return avgdata, avgdatatime |
|
778 | return avgdata, avgdatatime | |
779 |
|
779 | |||
780 | def integrateByBlock(self, dataOut): |
|
780 | def integrateByBlock(self, dataOut): | |
781 |
|
781 | |||
782 | times = int(dataOut.data.shape[1]/self.n) |
|
782 | times = int(dataOut.data.shape[1]/self.n) | |
783 | avgdata = numpy.zeros((dataOut.nChannels, times, dataOut.nHeights), dtype=numpy.complex) |
|
783 | avgdata = numpy.zeros((dataOut.nChannels, times, dataOut.nHeights), dtype=numpy.complex) | |
784 |
|
784 | |||
785 | id_min = 0 |
|
785 | id_min = 0 | |
786 | id_max = self.n |
|
786 | id_max = self.n | |
787 |
|
787 | |||
788 | for i in range(times): |
|
788 | for i in range(times): | |
789 | junk = dataOut.data[:,id_min:id_max,:] |
|
789 | junk = dataOut.data[:,id_min:id_max,:] | |
790 | avgdata[:,i,:] = junk.sum(axis=1) |
|
790 | avgdata[:,i,:] = junk.sum(axis=1) | |
791 | id_min += self.n |
|
791 | id_min += self.n | |
792 | id_max += self.n |
|
792 | id_max += self.n | |
793 |
|
793 | |||
794 | timeInterval = dataOut.ippSeconds*self.n |
|
794 | timeInterval = dataOut.ippSeconds*self.n | |
795 | avgdatatime = (times - 1) * timeInterval + dataOut.utctime |
|
795 | avgdatatime = (times - 1) * timeInterval + dataOut.utctime | |
796 | self.__dataReady = True |
|
796 | self.__dataReady = True | |
797 | return avgdata, avgdatatime |
|
797 | return avgdata, avgdatatime | |
798 |
|
798 | |||
799 | def run(self, dataOut, n=None, timeInterval=None, stride=None, overlapping=False, byblock=False, **kwargs): |
|
799 | def run(self, dataOut, n=None, timeInterval=None, stride=None, overlapping=False, byblock=False, **kwargs): | |
800 |
|
800 | |||
801 | if not self.isConfig: |
|
801 | if not self.isConfig: | |
802 | self.setup(n=n, stride=stride, timeInterval=timeInterval, overlapping=overlapping, byblock=byblock, **kwargs) |
|
802 | self.setup(n=n, stride=stride, timeInterval=timeInterval, overlapping=overlapping, byblock=byblock, **kwargs) | |
803 | self.isConfig = True |
|
803 | self.isConfig = True | |
804 |
|
804 | |||
805 | if dataOut.flagDataAsBlock: |
|
805 | if dataOut.flagDataAsBlock: | |
806 | """ |
|
806 | """ | |
807 | Si la data es leida por bloques, dimension = [nChannels, nProfiles, nHeis] |
|
807 | Si la data es leida por bloques, dimension = [nChannels, nProfiles, nHeis] | |
808 | """ |
|
808 | """ | |
809 | avgdata, avgdatatime = self.integrateByBlock(dataOut) |
|
809 | avgdata, avgdatatime = self.integrateByBlock(dataOut) | |
810 | dataOut.nProfiles /= self.n |
|
810 | dataOut.nProfiles /= self.n | |
811 | else: |
|
811 | else: | |
812 | if stride is None: |
|
812 | if stride is None: | |
813 | avgdata, avgdatatime = self.integrate(dataOut.data, dataOut.utctime) |
|
813 | avgdata, avgdatatime = self.integrate(dataOut.data, dataOut.utctime) | |
814 | else: |
|
814 | else: | |
815 | avgdata, avgdatatime = self.integrateByStride(dataOut.data, dataOut.utctime) |
|
815 | avgdata, avgdatatime = self.integrateByStride(dataOut.data, dataOut.utctime) | |
816 |
|
816 | |||
817 |
|
817 | |||
818 | # dataOut.timeInterval *= n |
|
818 | # dataOut.timeInterval *= n | |
819 | dataOut.flagNoData = True |
|
819 | dataOut.flagNoData = True | |
820 |
|
820 | |||
821 | if self.__dataReady: |
|
821 | if self.__dataReady: | |
822 | dataOut.data = avgdata |
|
822 | dataOut.data = avgdata | |
823 | if not dataOut.flagCohInt: |
|
823 | if not dataOut.flagCohInt: | |
824 | dataOut.nCohInt *= self.n |
|
824 | dataOut.nCohInt *= self.n | |
825 | dataOut.flagCohInt = True |
|
825 | dataOut.flagCohInt = True | |
826 | dataOut.utctime = avgdatatime |
|
826 | dataOut.utctime = avgdatatime | |
827 | # print avgdata, avgdatatime |
|
827 | # print avgdata, avgdatatime | |
828 | # raise |
|
828 | # raise | |
829 | # dataOut.timeInterval = dataOut.ippSeconds * dataOut.nCohInt |
|
829 | # dataOut.timeInterval = dataOut.ippSeconds * dataOut.nCohInt | |
830 | dataOut.flagNoData = False |
|
830 | dataOut.flagNoData = False | |
831 |
|
831 | |||
832 | #update Processing Header: |
|
832 | #update Processing Header: | |
833 | dataOut.processingHeaderObj.nCohInt = dataOut.nCohInt |
|
833 | dataOut.processingHeaderObj.nCohInt = dataOut.nCohInt | |
834 |
|
834 | |||
835 |
|
835 | |||
836 | return dataOut |
|
836 | return dataOut | |
837 |
|
837 | |||
838 | class Decoder(Operation): |
|
838 | class Decoder(Operation): | |
839 |
|
839 | |||
840 | isConfig = False |
|
840 | isConfig = False | |
841 | __profIndex = 0 |
|
841 | __profIndex = 0 | |
842 |
|
842 | |||
843 | code = None |
|
843 | code = None | |
844 |
|
844 | |||
845 | nCode = None |
|
845 | nCode = None | |
846 | nBaud = None |
|
846 | nBaud = None | |
847 |
|
847 | |||
848 | def __init__(self, **kwargs): |
|
848 | def __init__(self, **kwargs): | |
849 |
|
849 | |||
850 | Operation.__init__(self, **kwargs) |
|
850 | Operation.__init__(self, **kwargs) | |
851 |
|
851 | |||
852 | self.times = None |
|
852 | self.times = None | |
853 | self.osamp = None |
|
853 | self.osamp = None | |
854 | # self.__setValues = False |
|
854 | # self.__setValues = False | |
855 | self.isConfig = False |
|
855 | self.isConfig = False | |
856 | self.setupReq = False |
|
856 | self.setupReq = False | |
857 | def setup(self, code, osamp, dataOut): |
|
857 | def setup(self, code, osamp, dataOut): | |
858 |
|
858 | |||
859 | self.__profIndex = 0 |
|
859 | self.__profIndex = 0 | |
860 |
|
860 | |||
861 | self.code = code |
|
861 | self.code = code | |
862 |
|
862 | |||
863 | self.nCode = len(code) |
|
863 | self.nCode = len(code) | |
864 | self.nBaud = len(code[0]) |
|
864 | self.nBaud = len(code[0]) | |
865 | if (osamp != None) and (osamp >1): |
|
865 | if (osamp != None) and (osamp >1): | |
866 | self.osamp = osamp |
|
866 | self.osamp = osamp | |
867 | self.code = numpy.repeat(code, repeats=self.osamp, axis=1) |
|
867 | self.code = numpy.repeat(code, repeats=self.osamp, axis=1) | |
868 | self.nBaud = self.nBaud*self.osamp |
|
868 | self.nBaud = self.nBaud*self.osamp | |
869 |
|
869 | |||
870 | self.__nChannels = dataOut.nChannels |
|
870 | self.__nChannels = dataOut.nChannels | |
871 | self.__nProfiles = dataOut.nProfiles |
|
871 | self.__nProfiles = dataOut.nProfiles | |
872 | self.__nHeis = dataOut.nHeights |
|
872 | self.__nHeis = dataOut.nHeights | |
873 |
|
873 | |||
874 | if self.__nHeis < self.nBaud: |
|
874 | if self.__nHeis < self.nBaud: | |
875 | raise ValueError('Number of heights (%d) should be greater than number of bauds (%d)' %(self.__nHeis, self.nBaud)) |
|
875 | raise ValueError('Number of heights (%d) should be greater than number of bauds (%d)' %(self.__nHeis, self.nBaud)) | |
876 |
|
876 | |||
877 | #Frequency |
|
877 | #Frequency | |
878 | __codeBuffer = numpy.zeros((self.nCode, self.__nHeis), dtype=numpy.complex) |
|
878 | __codeBuffer = numpy.zeros((self.nCode, self.__nHeis), dtype=numpy.complex) | |
879 |
|
879 | |||
880 | __codeBuffer[:,0:self.nBaud] = self.code |
|
880 | __codeBuffer[:,0:self.nBaud] = self.code | |
881 |
|
881 | |||
882 | self.fft_code = numpy.conj(numpy.fft.fft(__codeBuffer, axis=1)) |
|
882 | self.fft_code = numpy.conj(numpy.fft.fft(__codeBuffer, axis=1)) | |
883 |
|
883 | |||
884 | if dataOut.flagDataAsBlock: |
|
884 | if dataOut.flagDataAsBlock: | |
885 |
|
885 | |||
886 | self.ndatadec = self.__nHeis #- self.nBaud + 1 |
|
886 | self.ndatadec = self.__nHeis #- self.nBaud + 1 | |
887 |
|
887 | |||
888 | self.datadecTime = numpy.zeros((self.__nChannels, self.__nProfiles, self.ndatadec), dtype=numpy.complex) |
|
888 | self.datadecTime = numpy.zeros((self.__nChannels, self.__nProfiles, self.ndatadec), dtype=numpy.complex) | |
889 |
|
889 | |||
890 | else: |
|
890 | else: | |
891 |
|
891 | |||
892 | #Time |
|
892 | #Time | |
893 | self.ndatadec = self.__nHeis #- self.nBaud + 1 |
|
893 | self.ndatadec = self.__nHeis #- self.nBaud + 1 | |
894 |
|
894 | |||
895 | self.datadecTime = numpy.zeros((self.__nChannels, self.ndatadec), dtype=numpy.complex) |
|
895 | self.datadecTime = numpy.zeros((self.__nChannels, self.ndatadec), dtype=numpy.complex) | |
896 |
|
896 | |||
897 | def __convolutionInFreq(self, data): |
|
897 | def __convolutionInFreq(self, data): | |
898 |
|
898 | |||
899 | fft_code = self.fft_code[self.__profIndex].reshape(1,-1) |
|
899 | fft_code = self.fft_code[self.__profIndex].reshape(1,-1) | |
900 |
|
900 | |||
901 | fft_data = numpy.fft.fft(data, axis=1) |
|
901 | fft_data = numpy.fft.fft(data, axis=1) | |
902 |
|
902 | |||
903 | conv = fft_data*fft_code |
|
903 | conv = fft_data*fft_code | |
904 |
|
904 | |||
905 | data = numpy.fft.ifft(conv,axis=1) |
|
905 | data = numpy.fft.ifft(conv,axis=1) | |
906 |
|
906 | |||
907 | return data |
|
907 | return data | |
908 |
|
908 | |||
909 | def __convolutionInFreqOpt(self, data): |
|
909 | def __convolutionInFreqOpt(self, data): | |
910 |
|
910 | |||
911 | raise NotImplementedError |
|
911 | raise NotImplementedError | |
912 |
|
912 | |||
913 | def __convolutionInTime(self, data): |
|
913 | def __convolutionInTime(self, data): | |
914 |
|
914 | |||
915 | code = self.code[self.__profIndex] |
|
915 | code = self.code[self.__profIndex] | |
916 | for i in range(self.__nChannels): |
|
916 | for i in range(self.__nChannels): | |
917 | self.datadecTime[i,:] = numpy.correlate(data[i,:], code, mode='full')[self.nBaud-1:] |
|
917 | self.datadecTime[i,:] = numpy.correlate(data[i,:], code, mode='full')[self.nBaud-1:] | |
918 |
|
918 | |||
919 | return self.datadecTime |
|
919 | return self.datadecTime | |
920 |
|
920 | |||
921 | def __convolutionByBlockInTime(self, data): |
|
921 | def __convolutionByBlockInTime(self, data): | |
922 |
|
922 | |||
923 | repetitions = int(self.__nProfiles / self.nCode) |
|
923 | repetitions = int(self.__nProfiles / self.nCode) | |
924 | junk = numpy.lib.stride_tricks.as_strided(self.code, (repetitions, self.code.size), (0, self.code.itemsize)) |
|
924 | junk = numpy.lib.stride_tricks.as_strided(self.code, (repetitions, self.code.size), (0, self.code.itemsize)) | |
925 | junk = junk.flatten() |
|
925 | junk = junk.flatten() | |
926 | code_block = numpy.reshape(junk, (self.nCode*repetitions, self.nBaud)) |
|
926 | code_block = numpy.reshape(junk, (self.nCode*repetitions, self.nBaud)) | |
927 | profilesList = range(self.__nProfiles) |
|
927 | profilesList = range(self.__nProfiles) | |
928 |
|
928 | |||
929 | for i in range(self.__nChannels): |
|
929 | for i in range(self.__nChannels): | |
930 | for j in profilesList: |
|
930 | for j in profilesList: | |
931 | self.datadecTime[i,j,:] = numpy.correlate(data[i,j,:], code_block[j,:], mode='full')[self.nBaud-1:] |
|
931 | self.datadecTime[i,j,:] = numpy.correlate(data[i,j,:], code_block[j,:], mode='full')[self.nBaud-1:] | |
932 | return self.datadecTime |
|
932 | return self.datadecTime | |
933 |
|
933 | |||
934 | def __convolutionByBlockInFreq(self, data): |
|
934 | def __convolutionByBlockInFreq(self, data): | |
935 |
|
935 | |||
936 | raise NotImplementedError("Decoder by frequency fro Blocks not implemented") |
|
936 | raise NotImplementedError("Decoder by frequency fro Blocks not implemented") | |
937 |
|
937 | |||
938 |
|
938 | |||
939 | fft_code = self.fft_code[self.__profIndex].reshape(1,-1) |
|
939 | fft_code = self.fft_code[self.__profIndex].reshape(1,-1) | |
940 |
|
940 | |||
941 | fft_data = numpy.fft.fft(data, axis=2) |
|
941 | fft_data = numpy.fft.fft(data, axis=2) | |
942 |
|
942 | |||
943 | conv = fft_data*fft_code |
|
943 | conv = fft_data*fft_code | |
944 |
|
944 | |||
945 | data = numpy.fft.ifft(conv,axis=2) |
|
945 | data = numpy.fft.ifft(conv,axis=2) | |
946 |
|
946 | |||
947 | return data |
|
947 | return data | |
948 |
|
948 | |||
949 |
|
949 | |||
950 | def run(self, dataOut, code=None, nCode=None, nBaud=None, mode = 0, osamp=None, times=None): |
|
950 | def run(self, dataOut, code=None, nCode=None, nBaud=None, mode = 0, osamp=None, times=None): | |
951 |
|
951 | |||
952 | if dataOut.flagDecodeData: |
|
952 | if dataOut.flagDecodeData: | |
953 | print("This data is already decoded, recoding again ...") |
|
953 | print("This data is already decoded, recoding again ...") | |
954 |
|
954 | |||
955 | if not self.isConfig: |
|
955 | if not self.isConfig: | |
956 |
|
956 | |||
957 | if code is None: |
|
957 | if code is None: | |
958 | if dataOut.code is None: |
|
958 | if dataOut.code is None: | |
959 | raise ValueError("Code could not be read from %s instance. Enter a value in Code parameter" %dataOut.type) |
|
959 | raise ValueError("Code could not be read from %s instance. Enter a value in Code parameter" %dataOut.type) | |
960 |
|
960 | |||
961 | code = dataOut.code |
|
961 | code = dataOut.code | |
962 | else: |
|
962 | else: | |
963 | code = numpy.array(code).reshape(nCode,nBaud) |
|
963 | code = numpy.array(code).reshape(nCode,nBaud) | |
964 | self.setup(code, osamp, dataOut) |
|
964 | self.setup(code, osamp, dataOut) | |
965 |
|
965 | |||
966 | self.isConfig = True |
|
966 | self.isConfig = True | |
967 |
|
967 | |||
968 | if mode == 3: |
|
968 | if mode == 3: | |
969 | sys.stderr.write("Decoder Warning: mode=%d is not valid, using mode=0\n" %mode) |
|
969 | sys.stderr.write("Decoder Warning: mode=%d is not valid, using mode=0\n" %mode) | |
970 |
|
970 | |||
971 | if times != None: |
|
971 | if times != None: | |
972 | sys.stderr.write("Decoder Warning: Argument 'times' in not used anymore\n") |
|
972 | sys.stderr.write("Decoder Warning: Argument 'times' in not used anymore\n") | |
973 |
|
973 | |||
974 | if self.code is None: |
|
974 | if self.code is None: | |
975 | print("Fail decoding: Code is not defined.") |
|
975 | print("Fail decoding: Code is not defined.") | |
976 | return |
|
976 | return | |
977 |
|
977 | |||
978 | self.__nProfiles = dataOut.nProfiles |
|
978 | self.__nProfiles = dataOut.nProfiles | |
979 | datadec = None |
|
979 | datadec = None | |
980 |
|
980 | |||
981 | if mode == 3: |
|
981 | if mode == 3: | |
982 | mode = 0 |
|
982 | mode = 0 | |
983 |
|
983 | |||
984 | if dataOut.flagDataAsBlock: |
|
984 | if dataOut.flagDataAsBlock: | |
985 | """ |
|
985 | """ | |
986 | Decoding when data have been read as block, |
|
986 | Decoding when data have been read as block, | |
987 | """ |
|
987 | """ | |
988 |
|
988 | |||
989 | if mode == 0: |
|
989 | if mode == 0: | |
990 | datadec = self.__convolutionByBlockInTime(dataOut.data) |
|
990 | datadec = self.__convolutionByBlockInTime(dataOut.data) | |
991 | if mode == 1: |
|
991 | if mode == 1: | |
992 | datadec = self.__convolutionByBlockInFreq(dataOut.data) |
|
992 | datadec = self.__convolutionByBlockInFreq(dataOut.data) | |
993 | else: |
|
993 | else: | |
994 | """ |
|
994 | """ | |
995 | Decoding when data have been read profile by profile |
|
995 | Decoding when data have been read profile by profile | |
996 | """ |
|
996 | """ | |
997 | if mode == 0: |
|
997 | if mode == 0: | |
998 | datadec = self.__convolutionInTime(dataOut.data) |
|
998 | datadec = self.__convolutionInTime(dataOut.data) | |
999 |
|
999 | |||
1000 | if mode == 1: |
|
1000 | if mode == 1: | |
1001 | datadec = self.__convolutionInFreq(dataOut.data) |
|
1001 | datadec = self.__convolutionInFreq(dataOut.data) | |
1002 |
|
1002 | |||
1003 | if mode == 2: |
|
1003 | if mode == 2: | |
1004 | datadec = self.__convolutionInFreqOpt(dataOut.data) |
|
1004 | datadec = self.__convolutionInFreqOpt(dataOut.data) | |
1005 |
|
1005 | |||
1006 | if datadec is None: |
|
1006 | if datadec is None: | |
1007 | raise ValueError("Codification mode selected is not valid: mode=%d. Try selecting 0 or 1" %mode) |
|
1007 | raise ValueError("Codification mode selected is not valid: mode=%d. Try selecting 0 or 1" %mode) | |
1008 |
|
1008 | |||
1009 | dataOut.code = self.code |
|
1009 | dataOut.code = self.code | |
1010 | dataOut.nCode = self.nCode |
|
1010 | dataOut.nCode = self.nCode | |
1011 | dataOut.nBaud = self.nBaud |
|
1011 | dataOut.nBaud = self.nBaud | |
1012 |
|
1012 | |||
1013 | dataOut.data = datadec |
|
1013 | dataOut.data = datadec | |
1014 | dataOut.heightList = dataOut.heightList[0:datadec.shape[-1]] |
|
1014 | dataOut.heightList = dataOut.heightList[0:datadec.shape[-1]] | |
1015 | dataOut.flagDecodeData = True #asumo q la data esta decodificada |
|
1015 | dataOut.flagDecodeData = True #asumo q la data esta decodificada | |
1016 |
|
1016 | |||
1017 |
|
1017 | |||
1018 | #update Processing Header: |
|
1018 | #update Processing Header: | |
1019 | dataOut.radarControllerHeaderObj.code = self.code |
|
1019 | dataOut.radarControllerHeaderObj.code = self.code | |
1020 | dataOut.radarControllerHeaderObj.nCode = self.nCode |
|
1020 | dataOut.radarControllerHeaderObj.nCode = self.nCode | |
1021 | dataOut.radarControllerHeaderObj.nBaud = self.nBaud |
|
1021 | dataOut.radarControllerHeaderObj.nBaud = self.nBaud | |
1022 | dataOut.radarControllerHeaderObj.nOsamp = osamp |
|
1022 | dataOut.radarControllerHeaderObj.nOsamp = osamp | |
1023 | #update Processing Header: |
|
1023 | #update Processing Header: | |
1024 | dataOut.processingHeaderObj.heightList = dataOut.heightList |
|
1024 | dataOut.processingHeaderObj.heightList = dataOut.heightList | |
1025 | dataOut.processingHeaderObj.heightResolution = dataOut.heightList[1]-dataOut.heightList[0] |
|
1025 | dataOut.processingHeaderObj.heightResolution = dataOut.heightList[1]-dataOut.heightList[0] | |
1026 |
|
1026 | |||
1027 | if self.__profIndex == self.nCode-1: |
|
1027 | if self.__profIndex == self.nCode-1: | |
1028 | self.__profIndex = 0 |
|
1028 | self.__profIndex = 0 | |
1029 | return dataOut |
|
1029 | return dataOut | |
1030 |
|
1030 | |||
1031 | self.__profIndex += 1 |
|
1031 | self.__profIndex += 1 | |
1032 |
|
1032 | |||
1033 | return dataOut |
|
1033 | return dataOut | |
1034 |
|
1034 | |||
1035 | class ProfileConcat(Operation): |
|
1035 | class ProfileConcat(Operation): | |
1036 |
|
1036 | |||
1037 | isConfig = False |
|
1037 | isConfig = False | |
1038 | buffer = None |
|
1038 | buffer = None | |
1039 |
|
1039 | |||
1040 | def __init__(self, **kwargs): |
|
1040 | def __init__(self, **kwargs): | |
1041 |
|
1041 | |||
1042 | Operation.__init__(self, **kwargs) |
|
1042 | Operation.__init__(self, **kwargs) | |
1043 | self.profileIndex = 0 |
|
1043 | self.profileIndex = 0 | |
1044 |
|
1044 | |||
1045 | def reset(self): |
|
1045 | def reset(self): | |
1046 | self.buffer = numpy.zeros_like(self.buffer) |
|
1046 | self.buffer = numpy.zeros_like(self.buffer) | |
1047 | self.start_index = 0 |
|
1047 | self.start_index = 0 | |
1048 | self.times = 1 |
|
1048 | self.times = 1 | |
1049 |
|
1049 | |||
1050 | def setup(self, data, m, n=1): |
|
1050 | def setup(self, data, m, n=1): | |
1051 | self.buffer = numpy.zeros((data.shape[0],data.shape[1]*m),dtype=type(data[0,0])) |
|
1051 | self.buffer = numpy.zeros((data.shape[0],data.shape[1]*m),dtype=type(data[0,0])) | |
1052 | self.nHeights = data.shape[1]#.nHeights |
|
1052 | self.nHeights = data.shape[1]#.nHeights | |
1053 | self.start_index = 0 |
|
1053 | self.start_index = 0 | |
1054 | self.times = 1 |
|
1054 | self.times = 1 | |
1055 |
|
1055 | |||
1056 | def concat(self, data): |
|
1056 | def concat(self, data): | |
1057 |
|
1057 | |||
1058 | self.buffer[:,self.start_index:self.nHeights*self.times] = data.copy() |
|
1058 | self.buffer[:,self.start_index:self.nHeights*self.times] = data.copy() | |
1059 | self.start_index = self.start_index + self.nHeights |
|
1059 | self.start_index = self.start_index + self.nHeights | |
1060 |
|
1060 | |||
1061 | def run(self, dataOut, m): |
|
1061 | def run(self, dataOut, m): | |
1062 | dataOut.flagNoData = True |
|
1062 | dataOut.flagNoData = True | |
1063 |
|
1063 | |||
1064 | if not self.isConfig: |
|
1064 | if not self.isConfig: | |
1065 | self.setup(dataOut.data, m, 1) |
|
1065 | self.setup(dataOut.data, m, 1) | |
1066 | self.isConfig = True |
|
1066 | self.isConfig = True | |
1067 |
|
1067 | |||
1068 | if dataOut.flagDataAsBlock: |
|
1068 | if dataOut.flagDataAsBlock: | |
1069 | raise ValueError("ProfileConcat can only be used when voltage have been read profile by profile, getBlock = False") |
|
1069 | raise ValueError("ProfileConcat can only be used when voltage have been read profile by profile, getBlock = False") | |
1070 |
|
1070 | |||
1071 | else: |
|
1071 | else: | |
1072 | self.concat(dataOut.data) |
|
1072 | self.concat(dataOut.data) | |
1073 | self.times += 1 |
|
1073 | self.times += 1 | |
1074 | if self.times > m: |
|
1074 | if self.times > m: | |
1075 | dataOut.data = self.buffer |
|
1075 | dataOut.data = self.buffer | |
1076 | self.reset() |
|
1076 | self.reset() | |
1077 | dataOut.flagNoData = False |
|
1077 | dataOut.flagNoData = False | |
1078 | # se deben actualizar mas propiedades del header y del objeto dataOut, por ejemplo, las alturas |
|
1078 | # se deben actualizar mas propiedades del header y del objeto dataOut, por ejemplo, las alturas | |
1079 | deltaHeight = dataOut.heightList[1] - dataOut.heightList[0] |
|
1079 | deltaHeight = dataOut.heightList[1] - dataOut.heightList[0] | |
1080 | xf = dataOut.heightList[0] + dataOut.nHeights * deltaHeight * m |
|
1080 | xf = dataOut.heightList[0] + dataOut.nHeights * deltaHeight * m | |
1081 | dataOut.heightList = numpy.arange(dataOut.heightList[0], xf, deltaHeight) |
|
1081 | dataOut.heightList = numpy.arange(dataOut.heightList[0], xf, deltaHeight) | |
1082 | dataOut.ippSeconds *= m |
|
1082 | dataOut.ippSeconds *= m | |
1083 |
|
1083 | |||
1084 | #update Processing Header: |
|
1084 | #update Processing Header: | |
1085 | dataOut.processingHeaderObj.heightList = dataOut.heightList |
|
1085 | dataOut.processingHeaderObj.heightList = dataOut.heightList | |
1086 | dataOut.processingHeaderObj.ipp = dataOut.ippSeconds |
|
1086 | dataOut.processingHeaderObj.ipp = dataOut.ippSeconds | |
1087 |
|
1087 | |||
1088 | return dataOut |
|
1088 | return dataOut | |
1089 |
|
1089 | |||
1090 | class ProfileSelector(Operation): |
|
1090 | class ProfileSelector(Operation): | |
1091 |
|
1091 | |||
1092 | profileIndex = None |
|
1092 | profileIndex = None | |
1093 | # Tamanho total de los perfiles |
|
1093 | # Tamanho total de los perfiles | |
1094 | nProfiles = None |
|
1094 | nProfiles = None | |
1095 |
|
1095 | |||
1096 | def __init__(self, **kwargs): |
|
1096 | def __init__(self, **kwargs): | |
1097 |
|
1097 | |||
1098 | Operation.__init__(self, **kwargs) |
|
1098 | Operation.__init__(self, **kwargs) | |
1099 | self.profileIndex = 0 |
|
1099 | self.profileIndex = 0 | |
1100 |
|
1100 | |||
1101 | def incProfileIndex(self): |
|
1101 | def incProfileIndex(self): | |
1102 |
|
1102 | |||
1103 | self.profileIndex += 1 |
|
1103 | self.profileIndex += 1 | |
1104 |
|
1104 | |||
1105 | if self.profileIndex >= self.nProfiles: |
|
1105 | if self.profileIndex >= self.nProfiles: | |
1106 | self.profileIndex = 0 |
|
1106 | self.profileIndex = 0 | |
1107 |
|
1107 | |||
1108 | def isThisProfileInRange(self, profileIndex, minIndex, maxIndex): |
|
1108 | def isThisProfileInRange(self, profileIndex, minIndex, maxIndex): | |
1109 |
|
1109 | |||
1110 | if profileIndex < minIndex: |
|
1110 | if profileIndex < minIndex: | |
1111 | return False |
|
1111 | return False | |
1112 |
|
1112 | |||
1113 | if profileIndex > maxIndex: |
|
1113 | if profileIndex > maxIndex: | |
1114 | return False |
|
1114 | return False | |
1115 |
|
1115 | |||
1116 | return True |
|
1116 | return True | |
1117 |
|
1117 | |||
1118 | def isThisProfileInList(self, profileIndex, profileList): |
|
1118 | def isThisProfileInList(self, profileIndex, profileList): | |
1119 |
|
1119 | |||
1120 | if profileIndex not in profileList: |
|
1120 | if profileIndex not in profileList: | |
1121 | return False |
|
1121 | return False | |
1122 |
|
1122 | |||
1123 | return True |
|
1123 | return True | |
1124 |
|
1124 | |||
1125 | def run(self, dataOut, profileList=None, profileRangeList=None, beam=None, byblock=False, rangeList = None, nProfiles=None): |
|
1125 | def run(self, dataOut, profileList=None, profileRangeList=None, beam=None, byblock=False, rangeList = None, nProfiles=None): | |
1126 |
|
1126 | |||
1127 | """ |
|
1127 | """ | |
1128 | ProfileSelector: |
|
1128 | ProfileSelector: | |
1129 |
|
1129 | |||
1130 | Inputs: |
|
1130 | Inputs: | |
1131 | profileList : Index of profiles selected. Example: profileList = (0,1,2,7,8) |
|
1131 | profileList : Index of profiles selected. Example: profileList = (0,1,2,7,8) | |
1132 |
|
1132 | |||
1133 | profileRangeList : Minimum and maximum profile indexes. Example: profileRangeList = (4, 30) |
|
1133 | profileRangeList : Minimum and maximum profile indexes. Example: profileRangeList = (4, 30) | |
1134 |
|
1134 | |||
1135 | rangeList : List of profile ranges. Example: rangeList = ((4, 30), (32, 64), (128, 256)) |
|
1135 | rangeList : List of profile ranges. Example: rangeList = ((4, 30), (32, 64), (128, 256)) | |
1136 |
|
1136 | |||
1137 | """ |
|
1137 | """ | |
1138 |
|
1138 | |||
1139 | if rangeList is not None: |
|
1139 | if rangeList is not None: | |
1140 | if type(rangeList[0]) not in (tuple, list): |
|
1140 | if type(rangeList[0]) not in (tuple, list): | |
1141 | rangeList = [rangeList] |
|
1141 | rangeList = [rangeList] | |
1142 |
|
1142 | |||
1143 | dataOut.flagNoData = True |
|
1143 | dataOut.flagNoData = True | |
1144 |
|
1144 | |||
1145 | if dataOut.flagDataAsBlock: |
|
1145 | if dataOut.flagDataAsBlock: | |
1146 | """ |
|
1146 | """ | |
1147 | data dimension = [nChannels, nProfiles, nHeis] |
|
1147 | data dimension = [nChannels, nProfiles, nHeis] | |
1148 | """ |
|
1148 | """ | |
1149 | if profileList != None: |
|
1149 | if profileList != None: | |
1150 | dataOut.data = dataOut.data[:,profileList,:] |
|
1150 | dataOut.data = dataOut.data[:,profileList,:] | |
1151 |
|
1151 | |||
1152 | if profileRangeList != None: |
|
1152 | if profileRangeList != None: | |
1153 | minIndex = profileRangeList[0] |
|
1153 | minIndex = profileRangeList[0] | |
1154 | maxIndex = profileRangeList[1] |
|
1154 | maxIndex = profileRangeList[1] | |
1155 | profileList = list(range(minIndex, maxIndex+1)) |
|
1155 | profileList = list(range(minIndex, maxIndex+1)) | |
1156 |
|
1156 | |||
1157 | dataOut.data = dataOut.data[:,minIndex:maxIndex+1,:] |
|
1157 | dataOut.data = dataOut.data[:,minIndex:maxIndex+1,:] | |
1158 |
|
1158 | |||
1159 | if rangeList != None: |
|
1159 | if rangeList != None: | |
1160 |
|
1160 | |||
1161 | profileList = [] |
|
1161 | profileList = [] | |
1162 |
|
1162 | |||
1163 | for thisRange in rangeList: |
|
1163 | for thisRange in rangeList: | |
1164 | minIndex = thisRange[0] |
|
1164 | minIndex = thisRange[0] | |
1165 | maxIndex = thisRange[1] |
|
1165 | maxIndex = thisRange[1] | |
1166 |
|
1166 | |||
1167 | profileList.extend(list(range(minIndex, maxIndex+1))) |
|
1167 | profileList.extend(list(range(minIndex, maxIndex+1))) | |
1168 |
|
1168 | |||
1169 | dataOut.data = dataOut.data[:,profileList,:] |
|
1169 | dataOut.data = dataOut.data[:,profileList,:] | |
1170 |
|
1170 | |||
1171 | dataOut.nProfiles = len(profileList) |
|
1171 | dataOut.nProfiles = len(profileList) | |
1172 | dataOut.profileIndex = dataOut.nProfiles - 1 |
|
1172 | dataOut.profileIndex = dataOut.nProfiles - 1 | |
1173 | dataOut.flagNoData = False |
|
1173 | dataOut.flagNoData = False | |
1174 |
|
1174 | |||
1175 | return dataOut |
|
1175 | return dataOut | |
1176 |
|
1176 | |||
1177 | """ |
|
1177 | """ | |
1178 | data dimension = [nChannels, nHeis] |
|
1178 | data dimension = [nChannels, nHeis] | |
1179 | """ |
|
1179 | """ | |
1180 |
|
1180 | |||
1181 | if profileList != None: |
|
1181 | if profileList != None: | |
1182 |
|
1182 | |||
1183 | if self.isThisProfileInList(dataOut.profileIndex, profileList): |
|
1183 | if self.isThisProfileInList(dataOut.profileIndex, profileList): | |
1184 |
|
1184 | |||
1185 | self.nProfiles = len(profileList) |
|
1185 | self.nProfiles = len(profileList) | |
1186 | dataOut.nProfiles = self.nProfiles |
|
1186 | dataOut.nProfiles = self.nProfiles | |
1187 | dataOut.profileIndex = self.profileIndex |
|
1187 | dataOut.profileIndex = self.profileIndex | |
1188 | dataOut.flagNoData = False |
|
1188 | dataOut.flagNoData = False | |
1189 |
|
1189 | |||
1190 | self.incProfileIndex() |
|
1190 | self.incProfileIndex() | |
1191 | return dataOut |
|
1191 | return dataOut | |
1192 |
|
1192 | |||
1193 | if profileRangeList != None: |
|
1193 | if profileRangeList != None: | |
1194 |
|
1194 | |||
1195 | minIndex = profileRangeList[0] |
|
1195 | minIndex = profileRangeList[0] | |
1196 | maxIndex = profileRangeList[1] |
|
1196 | maxIndex = profileRangeList[1] | |
1197 |
|
1197 | |||
1198 | if self.isThisProfileInRange(dataOut.profileIndex, minIndex, maxIndex): |
|
1198 | if self.isThisProfileInRange(dataOut.profileIndex, minIndex, maxIndex): | |
1199 |
|
1199 | |||
1200 | self.nProfiles = maxIndex - minIndex + 1 |
|
1200 | self.nProfiles = maxIndex - minIndex + 1 | |
1201 | dataOut.nProfiles = self.nProfiles |
|
1201 | dataOut.nProfiles = self.nProfiles | |
1202 | dataOut.profileIndex = self.profileIndex |
|
1202 | dataOut.profileIndex = self.profileIndex | |
1203 | dataOut.flagNoData = False |
|
1203 | dataOut.flagNoData = False | |
1204 |
|
1204 | |||
1205 | self.incProfileIndex() |
|
1205 | self.incProfileIndex() | |
1206 | return dataOut |
|
1206 | return dataOut | |
1207 |
|
1207 | |||
1208 | if rangeList != None: |
|
1208 | if rangeList != None: | |
1209 |
|
1209 | |||
1210 | nProfiles = 0 |
|
1210 | nProfiles = 0 | |
1211 |
|
1211 | |||
1212 | for thisRange in rangeList: |
|
1212 | for thisRange in rangeList: | |
1213 | minIndex = thisRange[0] |
|
1213 | minIndex = thisRange[0] | |
1214 | maxIndex = thisRange[1] |
|
1214 | maxIndex = thisRange[1] | |
1215 |
|
1215 | |||
1216 | nProfiles += maxIndex - minIndex + 1 |
|
1216 | nProfiles += maxIndex - minIndex + 1 | |
1217 |
|
1217 | |||
1218 | for thisRange in rangeList: |
|
1218 | for thisRange in rangeList: | |
1219 |
|
1219 | |||
1220 | minIndex = thisRange[0] |
|
1220 | minIndex = thisRange[0] | |
1221 | maxIndex = thisRange[1] |
|
1221 | maxIndex = thisRange[1] | |
1222 |
|
1222 | |||
1223 | if self.isThisProfileInRange(dataOut.profileIndex, minIndex, maxIndex): |
|
1223 | if self.isThisProfileInRange(dataOut.profileIndex, minIndex, maxIndex): | |
1224 |
|
1224 | |||
1225 | self.nProfiles = nProfiles |
|
1225 | self.nProfiles = nProfiles | |
1226 | dataOut.nProfiles = self.nProfiles |
|
1226 | dataOut.nProfiles = self.nProfiles | |
1227 | dataOut.profileIndex = self.profileIndex |
|
1227 | dataOut.profileIndex = self.profileIndex | |
1228 | dataOut.flagNoData = False |
|
1228 | dataOut.flagNoData = False | |
1229 |
|
1229 | |||
1230 | self.incProfileIndex() |
|
1230 | self.incProfileIndex() | |
1231 |
|
1231 | |||
1232 | break |
|
1232 | break | |
1233 |
|
1233 | |||
1234 | return dataOut |
|
1234 | return dataOut | |
1235 |
|
1235 | |||
1236 |
|
1236 | |||
1237 | if beam != None: #beam is only for AMISR data |
|
1237 | if beam != None: #beam is only for AMISR data | |
1238 | if self.isThisProfileInList(dataOut.profileIndex, dataOut.beamRangeDict[beam]): |
|
1238 | if self.isThisProfileInList(dataOut.profileIndex, dataOut.beamRangeDict[beam]): | |
1239 | dataOut.flagNoData = False |
|
1239 | dataOut.flagNoData = False | |
1240 | dataOut.profileIndex = self.profileIndex |
|
1240 | dataOut.profileIndex = self.profileIndex | |
1241 |
|
1241 | |||
1242 | self.incProfileIndex() |
|
1242 | self.incProfileIndex() | |
1243 |
|
1243 | |||
1244 | return dataOut |
|
1244 | return dataOut | |
1245 |
|
1245 | |||
1246 | raise ValueError("ProfileSelector needs profileList, profileRangeList or rangeList parameter") |
|
1246 | raise ValueError("ProfileSelector needs profileList, profileRangeList or rangeList parameter") | |
1247 |
|
1247 | |||
1248 |
|
1248 | |||
1249 | class Reshaper(Operation): |
|
1249 | class Reshaper(Operation): | |
1250 |
|
1250 | |||
1251 | def __init__(self, **kwargs): |
|
1251 | def __init__(self, **kwargs): | |
1252 |
|
1252 | |||
1253 | Operation.__init__(self, **kwargs) |
|
1253 | Operation.__init__(self, **kwargs) | |
1254 |
|
1254 | |||
1255 | self.__buffer = None |
|
1255 | self.__buffer = None | |
1256 | self.__nitems = 0 |
|
1256 | self.__nitems = 0 | |
1257 |
|
1257 | |||
1258 | def __appendProfile(self, dataOut, nTxs): |
|
1258 | def __appendProfile(self, dataOut, nTxs): | |
1259 |
|
1259 | |||
1260 | if self.__buffer is None: |
|
1260 | if self.__buffer is None: | |
1261 | shape = (dataOut.nChannels, int(dataOut.nHeights/nTxs) ) |
|
1261 | shape = (dataOut.nChannels, int(dataOut.nHeights/nTxs) ) | |
1262 | self.__buffer = numpy.empty(shape, dtype = dataOut.data.dtype) |
|
1262 | self.__buffer = numpy.empty(shape, dtype = dataOut.data.dtype) | |
1263 |
|
1263 | |||
1264 | ini = dataOut.nHeights * self.__nitems |
|
1264 | ini = dataOut.nHeights * self.__nitems | |
1265 | end = ini + dataOut.nHeights |
|
1265 | end = ini + dataOut.nHeights | |
1266 |
|
1266 | |||
1267 | self.__buffer[:, ini:end] = dataOut.data |
|
1267 | self.__buffer[:, ini:end] = dataOut.data | |
1268 |
|
1268 | |||
1269 | self.__nitems += 1 |
|
1269 | self.__nitems += 1 | |
1270 |
|
1270 | |||
1271 | return int(self.__nitems*nTxs) |
|
1271 | return int(self.__nitems*nTxs) | |
1272 |
|
1272 | |||
1273 | def __getBuffer(self): |
|
1273 | def __getBuffer(self): | |
1274 |
|
1274 | |||
1275 | if self.__nitems == int(1./self.__nTxs): |
|
1275 | if self.__nitems == int(1./self.__nTxs): | |
1276 |
|
1276 | |||
1277 | self.__nitems = 0 |
|
1277 | self.__nitems = 0 | |
1278 |
|
1278 | |||
1279 | return self.__buffer.copy() |
|
1279 | return self.__buffer.copy() | |
1280 |
|
1280 | |||
1281 | return None |
|
1281 | return None | |
1282 |
|
1282 | |||
1283 | def __checkInputs(self, dataOut, shape, nTxs): |
|
1283 | def __checkInputs(self, dataOut, shape, nTxs): | |
1284 |
|
1284 | |||
1285 | if shape is None and nTxs is None: |
|
1285 | if shape is None and nTxs is None: | |
1286 | raise ValueError("Reshaper: shape of factor should be defined") |
|
1286 | raise ValueError("Reshaper: shape of factor should be defined") | |
1287 |
|
1287 | |||
1288 | if nTxs: |
|
1288 | if nTxs: | |
1289 | if nTxs < 0: |
|
1289 | if nTxs < 0: | |
1290 | raise ValueError("nTxs should be greater than 0") |
|
1290 | raise ValueError("nTxs should be greater than 0") | |
1291 |
|
1291 | |||
1292 | if nTxs < 1 and dataOut.nProfiles % (1./nTxs) != 0: |
|
1292 | if nTxs < 1 and dataOut.nProfiles % (1./nTxs) != 0: | |
1293 | raise ValueError("nProfiles= %d is not divisibled by (1./nTxs) = %f" %(dataOut.nProfiles, (1./nTxs))) |
|
1293 | raise ValueError("nProfiles= %d is not divisibled by (1./nTxs) = %f" %(dataOut.nProfiles, (1./nTxs))) | |
1294 |
|
1294 | |||
1295 | shape = [dataOut.nChannels, dataOut.nProfiles*nTxs, dataOut.nHeights/nTxs] |
|
1295 | shape = [dataOut.nChannels, dataOut.nProfiles*nTxs, dataOut.nHeights/nTxs] | |
1296 |
|
1296 | |||
1297 | return shape, nTxs |
|
1297 | return shape, nTxs | |
1298 |
|
1298 | |||
1299 | if len(shape) != 2 and len(shape) != 3: |
|
1299 | if len(shape) != 2 and len(shape) != 3: | |
1300 | 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)) |
|
1300 | 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)) | |
1301 |
|
1301 | |||
1302 | if len(shape) == 2: |
|
1302 | if len(shape) == 2: | |
1303 | shape_tuple = [dataOut.nChannels] |
|
1303 | shape_tuple = [dataOut.nChannels] | |
1304 | shape_tuple.extend(shape) |
|
1304 | shape_tuple.extend(shape) | |
1305 | else: |
|
1305 | else: | |
1306 | shape_tuple = list(shape) |
|
1306 | shape_tuple = list(shape) | |
1307 |
|
1307 | |||
1308 | nTxs = 1.0*shape_tuple[1]/dataOut.nProfiles |
|
1308 | nTxs = 1.0*shape_tuple[1]/dataOut.nProfiles | |
1309 |
|
1309 | |||
1310 | return shape_tuple, nTxs |
|
1310 | return shape_tuple, nTxs | |
1311 |
|
1311 | |||
1312 | def run(self, dataOut, shape=None, nTxs=None): |
|
1312 | def run(self, dataOut, shape=None, nTxs=None): | |
1313 |
|
1313 | |||
1314 | shape_tuple, self.__nTxs = self.__checkInputs(dataOut, shape, nTxs) |
|
1314 | shape_tuple, self.__nTxs = self.__checkInputs(dataOut, shape, nTxs) | |
1315 |
|
1315 | |||
1316 | dataOut.flagNoData = True |
|
1316 | dataOut.flagNoData = True | |
1317 | profileIndex = None |
|
1317 | profileIndex = None | |
1318 |
|
1318 | |||
1319 | if dataOut.flagDataAsBlock: |
|
1319 | if dataOut.flagDataAsBlock: | |
1320 |
|
1320 | |||
1321 | dataOut.data = numpy.reshape(dataOut.data, shape_tuple) |
|
1321 | dataOut.data = numpy.reshape(dataOut.data, shape_tuple) | |
1322 | dataOut.flagNoData = False |
|
1322 | dataOut.flagNoData = False | |
1323 |
|
1323 | |||
1324 | profileIndex = int(dataOut.nProfiles*self.__nTxs) - 1 |
|
1324 | profileIndex = int(dataOut.nProfiles*self.__nTxs) - 1 | |
1325 |
|
1325 | |||
1326 | else: |
|
1326 | else: | |
1327 |
|
1327 | |||
1328 | if self.__nTxs < 1: |
|
1328 | if self.__nTxs < 1: | |
1329 |
|
1329 | |||
1330 | self.__appendProfile(dataOut, self.__nTxs) |
|
1330 | self.__appendProfile(dataOut, self.__nTxs) | |
1331 | new_data = self.__getBuffer() |
|
1331 | new_data = self.__getBuffer() | |
1332 |
|
1332 | |||
1333 | if new_data is not None: |
|
1333 | if new_data is not None: | |
1334 | dataOut.data = new_data |
|
1334 | dataOut.data = new_data | |
1335 | dataOut.flagNoData = False |
|
1335 | dataOut.flagNoData = False | |
1336 |
|
1336 | |||
1337 | profileIndex = dataOut.profileIndex*nTxs |
|
1337 | profileIndex = dataOut.profileIndex*nTxs | |
1338 |
|
1338 | |||
1339 | else: |
|
1339 | else: | |
1340 | raise ValueError("nTxs should be greater than 0 and lower than 1, or use VoltageReader(..., getblock=True)") |
|
1340 | raise ValueError("nTxs should be greater than 0 and lower than 1, or use VoltageReader(..., getblock=True)") | |
1341 |
|
1341 | |||
1342 | deltaHeight = dataOut.heightList[1] - dataOut.heightList[0] |
|
1342 | deltaHeight = dataOut.heightList[1] - dataOut.heightList[0] | |
1343 |
|
1343 | |||
1344 | dataOut.heightList = numpy.arange(dataOut.nHeights/self.__nTxs) * deltaHeight + dataOut.heightList[0] |
|
1344 | dataOut.heightList = numpy.arange(dataOut.nHeights/self.__nTxs) * deltaHeight + dataOut.heightList[0] | |
1345 |
|
1345 | |||
1346 | dataOut.nProfiles = int(dataOut.nProfiles*self.__nTxs) |
|
1346 | dataOut.nProfiles = int(dataOut.nProfiles*self.__nTxs) | |
1347 |
|
1347 | |||
1348 | dataOut.profileIndex = profileIndex |
|
1348 | dataOut.profileIndex = profileIndex | |
1349 |
|
1349 | |||
1350 | dataOut.ippSeconds /= self.__nTxs |
|
1350 | dataOut.ippSeconds /= self.__nTxs | |
1351 |
|
1351 | |||
1352 | return dataOut |
|
1352 | return dataOut | |
1353 |
|
1353 | |||
1354 | class SplitProfiles(Operation): |
|
1354 | class SplitProfiles(Operation): | |
1355 |
|
1355 | |||
1356 | def __init__(self, **kwargs): |
|
1356 | def __init__(self, **kwargs): | |
1357 |
|
1357 | |||
1358 | Operation.__init__(self, **kwargs) |
|
1358 | Operation.__init__(self, **kwargs) | |
1359 |
|
1359 | |||
1360 | def run(self, dataOut, n): |
|
1360 | def run(self, dataOut, n): | |
1361 |
|
1361 | |||
1362 | dataOut.flagNoData = True |
|
1362 | dataOut.flagNoData = True | |
1363 | profileIndex = None |
|
1363 | profileIndex = None | |
1364 |
|
1364 | |||
1365 | if dataOut.flagDataAsBlock: |
|
1365 | if dataOut.flagDataAsBlock: | |
1366 |
|
1366 | |||
1367 | #nchannels, nprofiles, nsamples |
|
1367 | #nchannels, nprofiles, nsamples | |
1368 | shape = dataOut.data.shape |
|
1368 | shape = dataOut.data.shape | |
1369 |
|
1369 | |||
1370 | if shape[2] % n != 0: |
|
1370 | if shape[2] % n != 0: | |
1371 | raise ValueError("Could not split the data, n=%d has to be multiple of %d" %(n, shape[2])) |
|
1371 | raise ValueError("Could not split the data, n=%d has to be multiple of %d" %(n, shape[2])) | |
1372 |
|
1372 | |||
1373 | new_shape = shape[0], shape[1]*n, int(shape[2]/n) |
|
1373 | new_shape = shape[0], shape[1]*n, int(shape[2]/n) | |
1374 |
|
1374 | |||
1375 | dataOut.data = numpy.reshape(dataOut.data, new_shape) |
|
1375 | dataOut.data = numpy.reshape(dataOut.data, new_shape) | |
1376 | dataOut.flagNoData = False |
|
1376 | dataOut.flagNoData = False | |
1377 |
|
1377 | |||
1378 | profileIndex = int(dataOut.nProfiles/n) - 1 |
|
1378 | profileIndex = int(dataOut.nProfiles/n) - 1 | |
1379 |
|
1379 | |||
1380 | else: |
|
1380 | else: | |
1381 |
|
1381 | |||
1382 | raise ValueError("Could not split the data when is read Profile by Profile. Use VoltageReader(..., getblock=True)") |
|
1382 | raise ValueError("Could not split the data when is read Profile by Profile. Use VoltageReader(..., getblock=True)") | |
1383 |
|
1383 | |||
1384 | deltaHeight = dataOut.heightList[1] - dataOut.heightList[0] |
|
1384 | deltaHeight = dataOut.heightList[1] - dataOut.heightList[0] | |
1385 |
|
1385 | |||
1386 | dataOut.heightList = numpy.arange(dataOut.nHeights/n) * deltaHeight + dataOut.heightList[0] |
|
1386 | dataOut.heightList = numpy.arange(dataOut.nHeights/n) * deltaHeight + dataOut.heightList[0] | |
1387 |
|
1387 | |||
1388 | dataOut.nProfiles = int(dataOut.nProfiles*n) |
|
1388 | dataOut.nProfiles = int(dataOut.nProfiles*n) | |
1389 |
|
1389 | |||
1390 | dataOut.profileIndex = profileIndex |
|
1390 | dataOut.profileIndex = profileIndex | |
1391 |
|
1391 | |||
1392 | dataOut.ippSeconds /= n |
|
1392 | dataOut.ippSeconds /= n | |
1393 |
|
1393 | |||
1394 | return dataOut |
|
1394 | return dataOut | |
1395 |
|
1395 | |||
1396 | class CombineProfiles(Operation): |
|
1396 | class CombineProfiles(Operation): | |
1397 | def __init__(self, **kwargs): |
|
1397 | def __init__(self, **kwargs): | |
1398 |
|
1398 | |||
1399 | Operation.__init__(self, **kwargs) |
|
1399 | Operation.__init__(self, **kwargs) | |
1400 |
|
1400 | |||
1401 | self.__remData = None |
|
1401 | self.__remData = None | |
1402 | self.__profileIndex = 0 |
|
1402 | self.__profileIndex = 0 | |
1403 |
|
1403 | |||
1404 | def run(self, dataOut, n): |
|
1404 | def run(self, dataOut, n): | |
1405 |
|
1405 | |||
1406 | dataOut.flagNoData = True |
|
1406 | dataOut.flagNoData = True | |
1407 | profileIndex = None |
|
1407 | profileIndex = None | |
1408 |
|
1408 | |||
1409 | if dataOut.flagDataAsBlock: |
|
1409 | if dataOut.flagDataAsBlock: | |
1410 |
|
1410 | |||
1411 | #nchannels, nprofiles, nsamples |
|
1411 | #nchannels, nprofiles, nsamples | |
1412 | shape = dataOut.data.shape |
|
1412 | shape = dataOut.data.shape | |
1413 | new_shape = shape[0], shape[1]/n, shape[2]*n |
|
1413 | new_shape = shape[0], shape[1]/n, shape[2]*n | |
1414 |
|
1414 | |||
1415 | if shape[1] % n != 0: |
|
1415 | if shape[1] % n != 0: | |
1416 | raise ValueError("Could not split the data, n=%d has to be multiple of %d" %(n, shape[1])) |
|
1416 | raise ValueError("Could not split the data, n=%d has to be multiple of %d" %(n, shape[1])) | |
1417 |
|
1417 | |||
1418 | dataOut.data = numpy.reshape(dataOut.data, new_shape) |
|
1418 | dataOut.data = numpy.reshape(dataOut.data, new_shape) | |
1419 | dataOut.flagNoData = False |
|
1419 | dataOut.flagNoData = False | |
1420 |
|
1420 | |||
1421 | profileIndex = int(dataOut.nProfiles*n) - 1 |
|
1421 | profileIndex = int(dataOut.nProfiles*n) - 1 | |
1422 |
|
1422 | |||
1423 | else: |
|
1423 | else: | |
1424 |
|
1424 | |||
1425 | #nchannels, nsamples |
|
1425 | #nchannels, nsamples | |
1426 | if self.__remData is None: |
|
1426 | if self.__remData is None: | |
1427 | newData = dataOut.data |
|
1427 | newData = dataOut.data | |
1428 | else: |
|
1428 | else: | |
1429 | newData = numpy.concatenate((self.__remData, dataOut.data), axis=1) |
|
1429 | newData = numpy.concatenate((self.__remData, dataOut.data), axis=1) | |
1430 |
|
1430 | |||
1431 | self.__profileIndex += 1 |
|
1431 | self.__profileIndex += 1 | |
1432 |
|
1432 | |||
1433 | if self.__profileIndex < n: |
|
1433 | if self.__profileIndex < n: | |
1434 | self.__remData = newData |
|
1434 | self.__remData = newData | |
1435 | #continue |
|
1435 | #continue | |
1436 | return |
|
1436 | return | |
1437 |
|
1437 | |||
1438 | self.__profileIndex = 0 |
|
1438 | self.__profileIndex = 0 | |
1439 | self.__remData = None |
|
1439 | self.__remData = None | |
1440 |
|
1440 | |||
1441 | dataOut.data = newData |
|
1441 | dataOut.data = newData | |
1442 | dataOut.flagNoData = False |
|
1442 | dataOut.flagNoData = False | |
1443 |
|
1443 | |||
1444 | profileIndex = dataOut.profileIndex/n |
|
1444 | profileIndex = dataOut.profileIndex/n | |
1445 |
|
1445 | |||
1446 |
|
1446 | |||
1447 | deltaHeight = dataOut.heightList[1] - dataOut.heightList[0] |
|
1447 | deltaHeight = dataOut.heightList[1] - dataOut.heightList[0] | |
1448 |
|
1448 | |||
1449 | dataOut.heightList = numpy.arange(dataOut.nHeights*n) * deltaHeight + dataOut.heightList[0] |
|
1449 | dataOut.heightList = numpy.arange(dataOut.nHeights*n) * deltaHeight + dataOut.heightList[0] | |
1450 |
|
1450 | |||
1451 | dataOut.nProfiles = int(dataOut.nProfiles/n) |
|
1451 | dataOut.nProfiles = int(dataOut.nProfiles/n) | |
1452 |
|
1452 | |||
1453 | dataOut.profileIndex = profileIndex |
|
1453 | dataOut.profileIndex = profileIndex | |
1454 |
|
1454 | |||
1455 | dataOut.ippSeconds *= n |
|
1455 | dataOut.ippSeconds *= n | |
1456 |
|
1456 | |||
1457 | return dataOut |
|
1457 | return dataOut | |
1458 |
|
1458 | |||
1459 | class PulsePairVoltage(Operation): |
|
1459 | class PulsePairVoltage(Operation): | |
1460 | ''' |
|
1460 | ''' | |
1461 | Function PulsePair(Signal Power, Velocity) |
|
1461 | Function PulsePair(Signal Power, Velocity) | |
1462 | The real component of Lag[0] provides Intensity Information |
|
1462 | The real component of Lag[0] provides Intensity Information | |
1463 | The imag component of Lag[1] Phase provides Velocity Information |
|
1463 | The imag component of Lag[1] Phase provides Velocity Information | |
1464 |
|
1464 | |||
1465 | Configuration Parameters: |
|
1465 | Configuration Parameters: | |
1466 | nPRF = Number of Several PRF |
|
1466 | nPRF = Number of Several PRF | |
1467 | theta = Degree Azimuth angel Boundaries |
|
1467 | theta = Degree Azimuth angel Boundaries | |
1468 |
|
1468 | |||
1469 | Input: |
|
1469 | Input: | |
1470 | self.dataOut |
|
1470 | self.dataOut | |
1471 | lag[N] |
|
1471 | lag[N] | |
1472 | Affected: |
|
1472 | Affected: | |
1473 | self.dataOut.spc |
|
1473 | self.dataOut.spc | |
1474 | ''' |
|
1474 | ''' | |
1475 | isConfig = False |
|
1475 | isConfig = False | |
1476 | __profIndex = 0 |
|
1476 | __profIndex = 0 | |
1477 | __initime = None |
|
1477 | __initime = None | |
1478 | __lastdatatime = None |
|
1478 | __lastdatatime = None | |
1479 | __buffer = None |
|
1479 | __buffer = None | |
1480 | noise = None |
|
1480 | noise = None | |
1481 | __dataReady = False |
|
1481 | __dataReady = False | |
1482 | n = None |
|
1482 | n = None | |
1483 | __nch = 0 |
|
1483 | __nch = 0 | |
1484 | __nHeis = 0 |
|
1484 | __nHeis = 0 | |
1485 | removeDC = False |
|
1485 | removeDC = False | |
1486 | ipp = None |
|
1486 | ipp = None | |
1487 | lambda_ = 0 |
|
1487 | lambda_ = 0 | |
1488 |
|
1488 | |||
1489 | def __init__(self,**kwargs): |
|
1489 | def __init__(self,**kwargs): | |
1490 | Operation.__init__(self,**kwargs) |
|
1490 | Operation.__init__(self,**kwargs) | |
1491 |
|
1491 | |||
1492 | def setup(self, dataOut, n = None, removeDC=False): |
|
1492 | def setup(self, dataOut, n = None, removeDC=False): | |
1493 | ''' |
|
1493 | ''' | |
1494 | n= Numero de PRF's de entrada |
|
1494 | n= Numero de PRF's de entrada | |
1495 | ''' |
|
1495 | ''' | |
1496 | self.__initime = None |
|
1496 | self.__initime = None | |
1497 | self.__lastdatatime = 0 |
|
1497 | self.__lastdatatime = 0 | |
1498 | self.__dataReady = False |
|
1498 | self.__dataReady = False | |
1499 | self.__buffer = 0 |
|
1499 | self.__buffer = 0 | |
1500 | self.__profIndex = 0 |
|
1500 | self.__profIndex = 0 | |
1501 | self.noise = None |
|
1501 | self.noise = None | |
1502 | self.__nch = dataOut.nChannels |
|
1502 | self.__nch = dataOut.nChannels | |
1503 | self.__nHeis = dataOut.nHeights |
|
1503 | self.__nHeis = dataOut.nHeights | |
1504 | self.removeDC = removeDC |
|
1504 | self.removeDC = removeDC | |
1505 | self.lambda_ = 3.0e8/(9345.0e6) |
|
1505 | self.lambda_ = 3.0e8/(9345.0e6) | |
1506 | self.ippSec = dataOut.ippSeconds |
|
1506 | self.ippSec = dataOut.ippSeconds | |
1507 | self.nCohInt = dataOut.nCohInt |
|
1507 | self.nCohInt = dataOut.nCohInt | |
1508 |
|
1508 | |||
1509 | if n == None: |
|
1509 | if n == None: | |
1510 | raise ValueError("n should be specified.") |
|
1510 | raise ValueError("n should be specified.") | |
1511 |
|
1511 | |||
1512 | if n != None: |
|
1512 | if n != None: | |
1513 | if n<2: |
|
1513 | if n<2: | |
1514 | raise ValueError("n should be greater than 2") |
|
1514 | raise ValueError("n should be greater than 2") | |
1515 |
|
1515 | |||
1516 | self.n = n |
|
1516 | self.n = n | |
1517 | self.__nProf = n |
|
1517 | self.__nProf = n | |
1518 |
|
1518 | |||
1519 | self.__buffer = numpy.zeros((dataOut.nChannels, |
|
1519 | self.__buffer = numpy.zeros((dataOut.nChannels, | |
1520 | n, |
|
1520 | n, | |
1521 | dataOut.nHeights), |
|
1521 | dataOut.nHeights), | |
1522 | dtype='complex') |
|
1522 | dtype='complex') | |
1523 |
|
1523 | |||
1524 | def putData(self,data): |
|
1524 | def putData(self,data): | |
1525 | ''' |
|
1525 | ''' | |
1526 | Add a profile to he __buffer and increase in one the __profiel Index |
|
1526 | Add a profile to he __buffer and increase in one the __profiel Index | |
1527 | ''' |
|
1527 | ''' | |
1528 | self.__buffer[:,self.__profIndex,:]= data |
|
1528 | self.__buffer[:,self.__profIndex,:]= data | |
1529 | self.__profIndex += 1 |
|
1529 | self.__profIndex += 1 | |
1530 | return |
|
1530 | return | |
1531 |
|
1531 | |||
1532 | def pushData(self,dataOut): |
|
1532 | def pushData(self,dataOut): | |
1533 | ''' |
|
1533 | ''' | |
1534 | Return the PULSEPAIR and the profiles used in the operation |
|
1534 | Return the PULSEPAIR and the profiles used in the operation | |
1535 | Affected : self.__profileIndex |
|
1535 | Affected : self.__profileIndex | |
1536 | ''' |
|
1536 | ''' | |
1537 | #----------------- Remove DC----------------------------------- |
|
1537 | #----------------- Remove DC----------------------------------- | |
1538 | if self.removeDC==True: |
|
1538 | if self.removeDC==True: | |
1539 | mean = numpy.mean(self.__buffer,1) |
|
1539 | mean = numpy.mean(self.__buffer,1) | |
1540 | tmp = mean.reshape(self.__nch,1,self.__nHeis) |
|
1540 | tmp = mean.reshape(self.__nch,1,self.__nHeis) | |
1541 | dc= numpy.tile(tmp,[1,self.__nProf,1]) |
|
1541 | dc= numpy.tile(tmp,[1,self.__nProf,1]) | |
1542 | self.__buffer = self.__buffer - dc |
|
1542 | self.__buffer = self.__buffer - dc | |
1543 | #------------------Calculo de Potencia ------------------------ |
|
1543 | #------------------Calculo de Potencia ------------------------ | |
1544 | pair0 = self.__buffer*numpy.conj(self.__buffer) |
|
1544 | pair0 = self.__buffer*numpy.conj(self.__buffer) | |
1545 | pair0 = pair0.real |
|
1545 | pair0 = pair0.real | |
1546 | lag_0 = numpy.sum(pair0,1) |
|
1546 | lag_0 = numpy.sum(pair0,1) | |
1547 | #------------------Calculo de Ruido x canal-------------------- |
|
1547 | #------------------Calculo de Ruido x canal-------------------- | |
1548 | self.noise = numpy.zeros(self.__nch) |
|
1548 | self.noise = numpy.zeros(self.__nch) | |
1549 | for i in range(self.__nch): |
|
1549 | for i in range(self.__nch): | |
1550 | daux = numpy.sort(pair0[i,:,:],axis= None) |
|
1550 | daux = numpy.sort(pair0[i,:,:],axis= None) | |
1551 | self.noise[i]=hildebrand_sekhon( daux ,self.nCohInt) |
|
1551 | self.noise[i]=hildebrand_sekhon( daux ,self.nCohInt) | |
1552 |
|
1552 | |||
1553 | self.noise = self.noise.reshape(self.__nch,1) |
|
1553 | self.noise = self.noise.reshape(self.__nch,1) | |
1554 | self.noise = numpy.tile(self.noise,[1,self.__nHeis]) |
|
1554 | self.noise = numpy.tile(self.noise,[1,self.__nHeis]) | |
1555 | noise_buffer = self.noise.reshape(self.__nch,1,self.__nHeis) |
|
1555 | noise_buffer = self.noise.reshape(self.__nch,1,self.__nHeis) | |
1556 | noise_buffer = numpy.tile(noise_buffer,[1,self.__nProf,1]) |
|
1556 | noise_buffer = numpy.tile(noise_buffer,[1,self.__nProf,1]) | |
1557 | #------------------ Potencia recibida= P , Potencia senal = S , Ruido= N-- |
|
1557 | #------------------ Potencia recibida= P , Potencia senal = S , Ruido= N-- | |
1558 | #------------------ P= S+N ,P=lag_0/N --------------------------------- |
|
1558 | #------------------ P= S+N ,P=lag_0/N --------------------------------- | |
1559 | #-------------------- Power -------------------------------------------------- |
|
1559 | #-------------------- Power -------------------------------------------------- | |
1560 | data_power = lag_0/(self.n*self.nCohInt) |
|
1560 | data_power = lag_0/(self.n*self.nCohInt) | |
1561 | #------------------ Senal --------------------------------------------------- |
|
1561 | #------------------ Senal --------------------------------------------------- | |
1562 | data_intensity = pair0 - noise_buffer |
|
1562 | data_intensity = pair0 - noise_buffer | |
1563 | data_intensity = numpy.sum(data_intensity,axis=1)*(self.n*self.nCohInt)#*self.nCohInt) |
|
1563 | data_intensity = numpy.sum(data_intensity,axis=1)*(self.n*self.nCohInt)#*self.nCohInt) | |
1564 | #data_intensity = (lag_0-self.noise*self.n)*(self.n*self.nCohInt) |
|
1564 | #data_intensity = (lag_0-self.noise*self.n)*(self.n*self.nCohInt) | |
1565 | for i in range(self.__nch): |
|
1565 | for i in range(self.__nch): | |
1566 | for j in range(self.__nHeis): |
|
1566 | for j in range(self.__nHeis): | |
1567 | if data_intensity[i][j] < 0: |
|
1567 | if data_intensity[i][j] < 0: | |
1568 | data_intensity[i][j] = numpy.min(numpy.absolute(data_intensity[i][j])) |
|
1568 | data_intensity[i][j] = numpy.min(numpy.absolute(data_intensity[i][j])) | |
1569 |
|
1569 | |||
1570 | #----------------- Calculo de Frecuencia y Velocidad doppler-------- |
|
1570 | #----------------- Calculo de Frecuencia y Velocidad doppler-------- | |
1571 | pair1 = self.__buffer[:,:-1,:]*numpy.conjugate(self.__buffer[:,1:,:]) |
|
1571 | pair1 = self.__buffer[:,:-1,:]*numpy.conjugate(self.__buffer[:,1:,:]) | |
1572 | lag_1 = numpy.sum(pair1,1) |
|
1572 | lag_1 = numpy.sum(pair1,1) | |
1573 | data_freq = (-1/(2.0*math.pi*self.ippSec*self.nCohInt))*numpy.angle(lag_1) |
|
1573 | data_freq = (-1/(2.0*math.pi*self.ippSec*self.nCohInt))*numpy.angle(lag_1) | |
1574 | data_velocity = (self.lambda_/2.0)*data_freq |
|
1574 | data_velocity = (self.lambda_/2.0)*data_freq | |
1575 |
|
1575 | |||
1576 | #---------------- Potencia promedio estimada de la Senal----------- |
|
1576 | #---------------- Potencia promedio estimada de la Senal----------- | |
1577 | lag_0 = lag_0/self.n |
|
1577 | lag_0 = lag_0/self.n | |
1578 | S = lag_0-self.noise |
|
1578 | S = lag_0-self.noise | |
1579 |
|
1579 | |||
1580 | #---------------- Frecuencia Doppler promedio --------------------- |
|
1580 | #---------------- Frecuencia Doppler promedio --------------------- | |
1581 | lag_1 = lag_1/(self.n-1) |
|
1581 | lag_1 = lag_1/(self.n-1) | |
1582 | R1 = numpy.abs(lag_1) |
|
1582 | R1 = numpy.abs(lag_1) | |
1583 |
|
1583 | |||
1584 | #---------------- Calculo del SNR---------------------------------- |
|
1584 | #---------------- Calculo del SNR---------------------------------- | |
1585 | data_snrPP = S/self.noise |
|
1585 | data_snrPP = S/self.noise | |
1586 | for i in range(self.__nch): |
|
1586 | for i in range(self.__nch): | |
1587 | for j in range(self.__nHeis): |
|
1587 | for j in range(self.__nHeis): | |
1588 | if data_snrPP[i][j] < 1.e-20: |
|
1588 | if data_snrPP[i][j] < 1.e-20: | |
1589 | data_snrPP[i][j] = 1.e-20 |
|
1589 | data_snrPP[i][j] = 1.e-20 | |
1590 |
|
1590 | |||
1591 | #----------------- Calculo del ancho espectral ---------------------- |
|
1591 | #----------------- Calculo del ancho espectral ---------------------- | |
1592 | L = S/R1 |
|
1592 | L = S/R1 | |
1593 | L = numpy.where(L<0,1,L) |
|
1593 | L = numpy.where(L<0,1,L) | |
1594 | L = numpy.log(L) |
|
1594 | L = numpy.log(L) | |
1595 | tmp = numpy.sqrt(numpy.absolute(L)) |
|
1595 | tmp = numpy.sqrt(numpy.absolute(L)) | |
1596 | data_specwidth = (self.lambda_/(2*math.sqrt(2)*math.pi*self.ippSec*self.nCohInt))*tmp*numpy.sign(L) |
|
1596 | data_specwidth = (self.lambda_/(2*math.sqrt(2)*math.pi*self.ippSec*self.nCohInt))*tmp*numpy.sign(L) | |
1597 | n = self.__profIndex |
|
1597 | n = self.__profIndex | |
1598 |
|
1598 | |||
1599 | self.__buffer = numpy.zeros((self.__nch, self.__nProf,self.__nHeis), dtype='complex') |
|
1599 | self.__buffer = numpy.zeros((self.__nch, self.__nProf,self.__nHeis), dtype='complex') | |
1600 | self.__profIndex = 0 |
|
1600 | self.__profIndex = 0 | |
1601 | return data_power,data_intensity,data_velocity,data_snrPP,data_specwidth,n |
|
1601 | return data_power,data_intensity,data_velocity,data_snrPP,data_specwidth,n | |
1602 |
|
1602 | |||
1603 |
|
1603 | |||
1604 | def pulsePairbyProfiles(self,dataOut): |
|
1604 | def pulsePairbyProfiles(self,dataOut): | |
1605 |
|
1605 | |||
1606 | self.__dataReady = False |
|
1606 | self.__dataReady = False | |
1607 | data_power = None |
|
1607 | data_power = None | |
1608 | data_intensity = None |
|
1608 | data_intensity = None | |
1609 | data_velocity = None |
|
1609 | data_velocity = None | |
1610 | data_specwidth = None |
|
1610 | data_specwidth = None | |
1611 | data_snrPP = None |
|
1611 | data_snrPP = None | |
1612 | self.putData(data=dataOut.data) |
|
1612 | self.putData(data=dataOut.data) | |
1613 | if self.__profIndex == self.n: |
|
1613 | if self.__profIndex == self.n: | |
1614 | data_power,data_intensity, data_velocity,data_snrPP,data_specwidth, n = self.pushData(dataOut=dataOut) |
|
1614 | data_power,data_intensity, data_velocity,data_snrPP,data_specwidth, n = self.pushData(dataOut=dataOut) | |
1615 | self.__dataReady = True |
|
1615 | self.__dataReady = True | |
1616 |
|
1616 | |||
1617 | return data_power, data_intensity, data_velocity, data_snrPP, data_specwidth |
|
1617 | return data_power, data_intensity, data_velocity, data_snrPP, data_specwidth | |
1618 |
|
1618 | |||
1619 |
|
1619 | |||
1620 | def pulsePairOp(self, dataOut, datatime= None): |
|
1620 | def pulsePairOp(self, dataOut, datatime= None): | |
1621 |
|
1621 | |||
1622 | if self.__initime == None: |
|
1622 | if self.__initime == None: | |
1623 | self.__initime = datatime |
|
1623 | self.__initime = datatime | |
1624 | data_power, data_intensity, data_velocity, data_snrPP, data_specwidth = self.pulsePairbyProfiles(dataOut) |
|
1624 | data_power, data_intensity, data_velocity, data_snrPP, data_specwidth = self.pulsePairbyProfiles(dataOut) | |
1625 | self.__lastdatatime = datatime |
|
1625 | self.__lastdatatime = datatime | |
1626 |
|
1626 | |||
1627 | if data_power is None: |
|
1627 | if data_power is None: | |
1628 | return None, None, None,None,None,None |
|
1628 | return None, None, None,None,None,None | |
1629 |
|
1629 | |||
1630 | avgdatatime = self.__initime |
|
1630 | avgdatatime = self.__initime | |
1631 | deltatime = datatime - self.__lastdatatime |
|
1631 | deltatime = datatime - self.__lastdatatime | |
1632 | self.__initime = datatime |
|
1632 | self.__initime = datatime | |
1633 |
|
1633 | |||
1634 | return data_power, data_intensity, data_velocity, data_snrPP, data_specwidth, avgdatatime |
|
1634 | return data_power, data_intensity, data_velocity, data_snrPP, data_specwidth, avgdatatime | |
1635 |
|
1635 | |||
1636 | def run(self, dataOut,n = None,removeDC= False, overlapping= False,**kwargs): |
|
1636 | def run(self, dataOut,n = None,removeDC= False, overlapping= False,**kwargs): | |
1637 |
|
1637 | |||
1638 | if not self.isConfig: |
|
1638 | if not self.isConfig: | |
1639 | self.setup(dataOut = dataOut, n = n , removeDC=removeDC , **kwargs) |
|
1639 | self.setup(dataOut = dataOut, n = n , removeDC=removeDC , **kwargs) | |
1640 | self.isConfig = True |
|
1640 | self.isConfig = True | |
1641 | data_power, data_intensity, data_velocity,data_snrPP,data_specwidth, avgdatatime = self.pulsePairOp(dataOut, dataOut.utctime) |
|
1641 | data_power, data_intensity, data_velocity,data_snrPP,data_specwidth, avgdatatime = self.pulsePairOp(dataOut, dataOut.utctime) | |
1642 | dataOut.flagNoData = True |
|
1642 | dataOut.flagNoData = True | |
1643 |
|
1643 | |||
1644 | if self.__dataReady: |
|
1644 | if self.__dataReady: | |
1645 | dataOut.nCohInt *= self.n |
|
1645 | dataOut.nCohInt *= self.n | |
1646 | dataOut.dataPP_POW = data_intensity # S |
|
1646 | dataOut.dataPP_POW = data_intensity # S | |
1647 | dataOut.dataPP_POWER = data_power # P |
|
1647 | dataOut.dataPP_POWER = data_power # P | |
1648 | dataOut.dataPP_DOP = data_velocity |
|
1648 | dataOut.dataPP_DOP = data_velocity | |
1649 | dataOut.dataPP_SNR = data_snrPP |
|
1649 | dataOut.dataPP_SNR = data_snrPP | |
1650 | dataOut.dataPP_WIDTH = data_specwidth |
|
1650 | dataOut.dataPP_WIDTH = data_specwidth | |
1651 | dataOut.PRFbyAngle = self.n #numero de PRF*cada angulo rotado que equivale a un tiempo. |
|
1651 | dataOut.PRFbyAngle = self.n #numero de PRF*cada angulo rotado que equivale a un tiempo. | |
1652 | dataOut.utctime = avgdatatime |
|
1652 | dataOut.utctime = avgdatatime | |
1653 | dataOut.flagNoData = False |
|
1653 | dataOut.flagNoData = False | |
1654 | return dataOut |
|
1654 | return dataOut | |
1655 |
|
1655 | |||
1656 |
|
1656 | |||
1657 |
|
1657 | |||
1658 | # import collections |
|
1658 | # import collections | |
1659 | # from scipy.stats import mode |
|
1659 | # from scipy.stats import mode | |
1660 | # |
|
1660 | # | |
1661 | # class Synchronize(Operation): |
|
1661 | # class Synchronize(Operation): | |
1662 | # |
|
1662 | # | |
1663 | # isConfig = False |
|
1663 | # isConfig = False | |
1664 | # __profIndex = 0 |
|
1664 | # __profIndex = 0 | |
1665 | # |
|
1665 | # | |
1666 | # def __init__(self, **kwargs): |
|
1666 | # def __init__(self, **kwargs): | |
1667 | # |
|
1667 | # | |
1668 | # Operation.__init__(self, **kwargs) |
|
1668 | # Operation.__init__(self, **kwargs) | |
1669 | # # self.isConfig = False |
|
1669 | # # self.isConfig = False | |
1670 | # self.__powBuffer = None |
|
1670 | # self.__powBuffer = None | |
1671 | # self.__startIndex = 0 |
|
1671 | # self.__startIndex = 0 | |
1672 | # self.__pulseFound = False |
|
1672 | # self.__pulseFound = False | |
1673 | # |
|
1673 | # | |
1674 | # def __findTxPulse(self, dataOut, channel=0, pulse_with = None): |
|
1674 | # def __findTxPulse(self, dataOut, channel=0, pulse_with = None): | |
1675 | # |
|
1675 | # | |
1676 | # #Read data |
|
1676 | # #Read data | |
1677 | # |
|
1677 | # | |
1678 | # powerdB = dataOut.getPower(channel = channel) |
|
1678 | # powerdB = dataOut.getPower(channel = channel) | |
1679 | # noisedB = dataOut.getNoise(channel = channel)[0] |
|
1679 | # noisedB = dataOut.getNoise(channel = channel)[0] | |
1680 | # |
|
1680 | # | |
1681 | # self.__powBuffer.extend(powerdB.flatten()) |
|
1681 | # self.__powBuffer.extend(powerdB.flatten()) | |
1682 | # |
|
1682 | # | |
1683 | # dataArray = numpy.array(self.__powBuffer) |
|
1683 | # dataArray = numpy.array(self.__powBuffer) | |
1684 | # |
|
1684 | # | |
1685 | # filteredPower = numpy.correlate(dataArray, dataArray[0:self.__nSamples], "same") |
|
1685 | # filteredPower = numpy.correlate(dataArray, dataArray[0:self.__nSamples], "same") | |
1686 | # |
|
1686 | # | |
1687 | # maxValue = numpy.nanmax(filteredPower) |
|
1687 | # maxValue = numpy.nanmax(filteredPower) | |
1688 | # |
|
1688 | # | |
1689 | # if maxValue < noisedB + 10: |
|
1689 | # if maxValue < noisedB + 10: | |
1690 | # #No se encuentra ningun pulso de transmision |
|
1690 | # #No se encuentra ningun pulso de transmision | |
1691 | # return None |
|
1691 | # return None | |
1692 | # |
|
1692 | # | |
1693 | # maxValuesIndex = numpy.where(filteredPower > maxValue - 0.1*abs(maxValue))[0] |
|
1693 | # maxValuesIndex = numpy.where(filteredPower > maxValue - 0.1*abs(maxValue))[0] | |
1694 | # |
|
1694 | # | |
1695 | # if len(maxValuesIndex) < 2: |
|
1695 | # if len(maxValuesIndex) < 2: | |
1696 | # #Solo se encontro un solo pulso de transmision de un baudio, esperando por el siguiente TX |
|
1696 | # #Solo se encontro un solo pulso de transmision de un baudio, esperando por el siguiente TX | |
1697 | # return None |
|
1697 | # return None | |
1698 | # |
|
1698 | # | |
1699 | # phasedMaxValuesIndex = maxValuesIndex - self.__nSamples |
|
1699 | # phasedMaxValuesIndex = maxValuesIndex - self.__nSamples | |
1700 | # |
|
1700 | # | |
1701 | # #Seleccionar solo valores con un espaciamiento de nSamples |
|
1701 | # #Seleccionar solo valores con un espaciamiento de nSamples | |
1702 | # pulseIndex = numpy.intersect1d(maxValuesIndex, phasedMaxValuesIndex) |
|
1702 | # pulseIndex = numpy.intersect1d(maxValuesIndex, phasedMaxValuesIndex) | |
1703 | # |
|
1703 | # | |
1704 | # if len(pulseIndex) < 2: |
|
1704 | # if len(pulseIndex) < 2: | |
1705 | # #Solo se encontro un pulso de transmision con ancho mayor a 1 |
|
1705 | # #Solo se encontro un pulso de transmision con ancho mayor a 1 | |
1706 | # return None |
|
1706 | # return None | |
1707 | # |
|
1707 | # | |
1708 | # spacing = pulseIndex[1:] - pulseIndex[:-1] |
|
1708 | # spacing = pulseIndex[1:] - pulseIndex[:-1] | |
1709 | # |
|
1709 | # | |
1710 | # #remover senales que se distancien menos de 10 unidades o muestras |
|
1710 | # #remover senales que se distancien menos de 10 unidades o muestras | |
1711 | # #(No deberian existir IPP menor a 10 unidades) |
|
1711 | # #(No deberian existir IPP menor a 10 unidades) | |
1712 | # |
|
1712 | # | |
1713 | # realIndex = numpy.where(spacing > 10 )[0] |
|
1713 | # realIndex = numpy.where(spacing > 10 )[0] | |
1714 | # |
|
1714 | # | |
1715 | # if len(realIndex) < 2: |
|
1715 | # if len(realIndex) < 2: | |
1716 | # #Solo se encontro un pulso de transmision con ancho mayor a 1 |
|
1716 | # #Solo se encontro un pulso de transmision con ancho mayor a 1 | |
1717 | # return None |
|
1717 | # return None | |
1718 | # |
|
1718 | # | |
1719 | # #Eliminar pulsos anchos (deja solo la diferencia entre IPPs) |
|
1719 | # #Eliminar pulsos anchos (deja solo la diferencia entre IPPs) | |
1720 | # realPulseIndex = pulseIndex[realIndex] |
|
1720 | # realPulseIndex = pulseIndex[realIndex] | |
1721 | # |
|
1721 | # | |
1722 | # period = mode(realPulseIndex[1:] - realPulseIndex[:-1])[0][0] |
|
1722 | # period = mode(realPulseIndex[1:] - realPulseIndex[:-1])[0][0] | |
1723 | # |
|
1723 | # | |
1724 | # print "IPP = %d samples" %period |
|
1724 | # print "IPP = %d samples" %period | |
1725 | # |
|
1725 | # | |
1726 | # self.__newNSamples = dataOut.nHeights #int(period) |
|
1726 | # self.__newNSamples = dataOut.nHeights #int(period) | |
1727 | # self.__startIndex = int(realPulseIndex[0]) |
|
1727 | # self.__startIndex = int(realPulseIndex[0]) | |
1728 | # |
|
1728 | # | |
1729 | # return 1 |
|
1729 | # return 1 | |
1730 | # |
|
1730 | # | |
1731 | # |
|
1731 | # | |
1732 | # def setup(self, nSamples, nChannels, buffer_size = 4): |
|
1732 | # def setup(self, nSamples, nChannels, buffer_size = 4): | |
1733 | # |
|
1733 | # | |
1734 | # self.__powBuffer = collections.deque(numpy.zeros( buffer_size*nSamples,dtype=numpy.float), |
|
1734 | # self.__powBuffer = collections.deque(numpy.zeros( buffer_size*nSamples,dtype=numpy.float), | |
1735 | # maxlen = buffer_size*nSamples) |
|
1735 | # maxlen = buffer_size*nSamples) | |
1736 | # |
|
1736 | # | |
1737 | # bufferList = [] |
|
1737 | # bufferList = [] | |
1738 | # |
|
1738 | # | |
1739 | # for i in range(nChannels): |
|
1739 | # for i in range(nChannels): | |
1740 | # bufferByChannel = collections.deque(numpy.zeros( buffer_size*nSamples, dtype=numpy.complex) + numpy.NAN, |
|
1740 | # bufferByChannel = collections.deque(numpy.zeros( buffer_size*nSamples, dtype=numpy.complex) + numpy.NAN, | |
1741 | # maxlen = buffer_size*nSamples) |
|
1741 | # maxlen = buffer_size*nSamples) | |
1742 | # |
|
1742 | # | |
1743 | # bufferList.append(bufferByChannel) |
|
1743 | # bufferList.append(bufferByChannel) | |
1744 | # |
|
1744 | # | |
1745 | # self.__nSamples = nSamples |
|
1745 | # self.__nSamples = nSamples | |
1746 | # self.__nChannels = nChannels |
|
1746 | # self.__nChannels = nChannels | |
1747 | # self.__bufferList = bufferList |
|
1747 | # self.__bufferList = bufferList | |
1748 | # |
|
1748 | # | |
1749 | # def run(self, dataOut, channel = 0): |
|
1749 | # def run(self, dataOut, channel = 0): | |
1750 | # |
|
1750 | # | |
1751 | # if not self.isConfig: |
|
1751 | # if not self.isConfig: | |
1752 | # nSamples = dataOut.nHeights |
|
1752 | # nSamples = dataOut.nHeights | |
1753 | # nChannels = dataOut.nChannels |
|
1753 | # nChannels = dataOut.nChannels | |
1754 | # self.setup(nSamples, nChannels) |
|
1754 | # self.setup(nSamples, nChannels) | |
1755 | # self.isConfig = True |
|
1755 | # self.isConfig = True | |
1756 | # |
|
1756 | # | |
1757 | # #Append new data to internal buffer |
|
1757 | # #Append new data to internal buffer | |
1758 | # for thisChannel in range(self.__nChannels): |
|
1758 | # for thisChannel in range(self.__nChannels): | |
1759 | # bufferByChannel = self.__bufferList[thisChannel] |
|
1759 | # bufferByChannel = self.__bufferList[thisChannel] | |
1760 | # bufferByChannel.extend(dataOut.data[thisChannel]) |
|
1760 | # bufferByChannel.extend(dataOut.data[thisChannel]) | |
1761 | # |
|
1761 | # | |
1762 | # if self.__pulseFound: |
|
1762 | # if self.__pulseFound: | |
1763 | # self.__startIndex -= self.__nSamples |
|
1763 | # self.__startIndex -= self.__nSamples | |
1764 | # |
|
1764 | # | |
1765 | # #Finding Tx Pulse |
|
1765 | # #Finding Tx Pulse | |
1766 | # if not self.__pulseFound: |
|
1766 | # if not self.__pulseFound: | |
1767 | # indexFound = self.__findTxPulse(dataOut, channel) |
|
1767 | # indexFound = self.__findTxPulse(dataOut, channel) | |
1768 | # |
|
1768 | # | |
1769 | # if indexFound == None: |
|
1769 | # if indexFound == None: | |
1770 | # dataOut.flagNoData = True |
|
1770 | # dataOut.flagNoData = True | |
1771 | # return |
|
1771 | # return | |
1772 | # |
|
1772 | # | |
1773 | # self.__arrayBuffer = numpy.zeros((self.__nChannels, self.__newNSamples), dtype = numpy.complex) |
|
1773 | # self.__arrayBuffer = numpy.zeros((self.__nChannels, self.__newNSamples), dtype = numpy.complex) | |
1774 | # self.__pulseFound = True |
|
1774 | # self.__pulseFound = True | |
1775 | # self.__startIndex = indexFound |
|
1775 | # self.__startIndex = indexFound | |
1776 | # |
|
1776 | # | |
1777 | # #If pulse was found ... |
|
1777 | # #If pulse was found ... | |
1778 | # for thisChannel in range(self.__nChannels): |
|
1778 | # for thisChannel in range(self.__nChannels): | |
1779 | # bufferByChannel = self.__bufferList[thisChannel] |
|
1779 | # bufferByChannel = self.__bufferList[thisChannel] | |
1780 | # #print self.__startIndex |
|
1780 | # #print self.__startIndex | |
1781 | # x = numpy.array(bufferByChannel) |
|
1781 | # x = numpy.array(bufferByChannel) | |
1782 | # self.__arrayBuffer[thisChannel] = x[self.__startIndex:self.__startIndex+self.__newNSamples] |
|
1782 | # self.__arrayBuffer[thisChannel] = x[self.__startIndex:self.__startIndex+self.__newNSamples] | |
1783 | # |
|
1783 | # | |
1784 | # deltaHeight = dataOut.heightList[1] - dataOut.heightList[0] |
|
1784 | # deltaHeight = dataOut.heightList[1] - dataOut.heightList[0] | |
1785 | # dataOut.heightList = numpy.arange(self.__newNSamples)*deltaHeight |
|
1785 | # dataOut.heightList = numpy.arange(self.__newNSamples)*deltaHeight | |
1786 | # # dataOut.ippSeconds = (self.__newNSamples / deltaHeight)/1e6 |
|
1786 | # # dataOut.ippSeconds = (self.__newNSamples / deltaHeight)/1e6 | |
1787 | # |
|
1787 | # | |
1788 | # dataOut.data = self.__arrayBuffer |
|
1788 | # dataOut.data = self.__arrayBuffer | |
1789 | # |
|
1789 | # | |
1790 | # self.__startIndex += self.__newNSamples |
|
1790 | # self.__startIndex += self.__newNSamples | |
1791 | # |
|
1791 | # | |
1792 | # return |
|
1792 | # return | |
1793 | class SSheightProfiles(Operation): |
|
1793 | class SSheightProfiles(Operation): | |
1794 |
|
1794 | |||
1795 | step = None |
|
1795 | step = None | |
1796 | nsamples = None |
|
1796 | nsamples = None | |
1797 | bufferShape = None |
|
1797 | bufferShape = None | |
1798 | profileShape = None |
|
1798 | profileShape = None | |
1799 | sshProfiles = None |
|
1799 | sshProfiles = None | |
1800 | profileIndex = None |
|
1800 | profileIndex = None | |
1801 |
|
1801 | |||
1802 | def __init__(self, **kwargs): |
|
1802 | def __init__(self, **kwargs): | |
1803 |
|
1803 | |||
1804 | Operation.__init__(self, **kwargs) |
|
1804 | Operation.__init__(self, **kwargs) | |
1805 | self.isConfig = False |
|
1805 | self.isConfig = False | |
1806 |
|
1806 | |||
1807 | def setup(self,dataOut ,step = None , nsamples = None): |
|
1807 | def setup(self,dataOut ,step = None , nsamples = None): | |
1808 |
|
1808 | |||
1809 | if step == None and nsamples == None: |
|
1809 | if step == None and nsamples == None: | |
1810 | raise ValueError("step or nheights should be specified ...") |
|
1810 | raise ValueError("step or nheights should be specified ...") | |
1811 |
|
1811 | |||
1812 | self.step = step |
|
1812 | self.step = step | |
1813 | self.nsamples = nsamples |
|
1813 | self.nsamples = nsamples | |
1814 | self.__nChannels = dataOut.nChannels |
|
1814 | self.__nChannels = dataOut.nChannels | |
1815 | self.__nProfiles = dataOut.nProfiles |
|
1815 | self.__nProfiles = dataOut.nProfiles | |
1816 | self.__nHeis = dataOut.nHeights |
|
1816 | self.__nHeis = dataOut.nHeights | |
1817 | shape = dataOut.data.shape #nchannels, nprofiles, nsamples |
|
1817 | shape = dataOut.data.shape #nchannels, nprofiles, nsamples | |
1818 |
|
1818 | |||
1819 | residue = (shape[1] - self.nsamples) % self.step |
|
1819 | residue = (shape[1] - self.nsamples) % self.step | |
1820 | if residue != 0: |
|
1820 | if residue != 0: | |
1821 | print("The residue is %d, step=%d should be multiple of %d to avoid loss of %d samples"%(residue,step,shape[1] - self.nsamples,residue)) |
|
1821 | print("The residue is %d, step=%d should be multiple of %d to avoid loss of %d samples"%(residue,step,shape[1] - self.nsamples,residue)) | |
1822 |
|
1822 | |||
1823 | deltaHeight = dataOut.heightList[1] - dataOut.heightList[0] |
|
1823 | deltaHeight = dataOut.heightList[1] - dataOut.heightList[0] | |
1824 | numberProfile = self.nsamples |
|
1824 | numberProfile = self.nsamples | |
1825 | numberSamples = (shape[1] - self.nsamples)/self.step |
|
1825 | numberSamples = (shape[1] - self.nsamples)/self.step | |
1826 |
|
1826 | |||
1827 | self.bufferShape = int(shape[0]), int(numberSamples), int(numberProfile) # nchannels, nsamples , nprofiles |
|
1827 | self.bufferShape = int(shape[0]), int(numberSamples), int(numberProfile) # nchannels, nsamples , nprofiles | |
1828 | self.profileShape = int(shape[0]), int(numberProfile), int(numberSamples) # nchannels, nprofiles, nsamples |
|
1828 | self.profileShape = int(shape[0]), int(numberProfile), int(numberSamples) # nchannels, nprofiles, nsamples | |
1829 |
|
1829 | |||
1830 | self.buffer = numpy.zeros(self.bufferShape , dtype=numpy.complex) |
|
1830 | self.buffer = numpy.zeros(self.bufferShape , dtype=numpy.complex) | |
1831 | self.sshProfiles = numpy.zeros(self.profileShape, dtype=numpy.complex) |
|
1831 | self.sshProfiles = numpy.zeros(self.profileShape, dtype=numpy.complex) | |
1832 |
|
1832 | |||
1833 | def run(self, dataOut, step, nsamples, code = None, repeat = None): |
|
1833 | def run(self, dataOut, step, nsamples, code = None, repeat = None): | |
1834 | dataOut.flagNoData = True |
|
1834 | dataOut.flagNoData = True | |
1835 |
|
1835 | |||
1836 | profileIndex = None |
|
1836 | profileIndex = None | |
1837 | #print("nProfiles, nHeights ",dataOut.nProfiles, dataOut.nHeights) |
|
1837 | #print("nProfiles, nHeights ",dataOut.nProfiles, dataOut.nHeights) | |
1838 | #print(dataOut.getFreqRange(1)/1000.) |
|
1838 | #print(dataOut.getFreqRange(1)/1000.) | |
1839 | #exit(1) |
|
1839 | #exit(1) | |
1840 | if dataOut.flagDataAsBlock: |
|
1840 | if dataOut.flagDataAsBlock: | |
1841 | dataOut.data = numpy.average(dataOut.data,axis=1) |
|
1841 | dataOut.data = numpy.average(dataOut.data,axis=1) | |
1842 | #print("jee") |
|
1842 | #print("jee") | |
1843 | dataOut.flagDataAsBlock = False |
|
1843 | dataOut.flagDataAsBlock = False | |
1844 | if not self.isConfig: |
|
1844 | if not self.isConfig: | |
1845 | self.setup(dataOut, step=step , nsamples=nsamples) |
|
1845 | self.setup(dataOut, step=step , nsamples=nsamples) | |
1846 | #print("Setup done") |
|
1846 | #print("Setup done") | |
1847 | self.isConfig = True |
|
1847 | self.isConfig = True | |
1848 |
|
1848 | |||
1849 |
|
1849 | |||
1850 | if code is not None: |
|
1850 | if code is not None: | |
1851 | code = numpy.array(code) |
|
1851 | code = numpy.array(code) | |
1852 | code_block = code |
|
1852 | code_block = code | |
1853 |
|
1853 | |||
1854 | if repeat is not None: |
|
1854 | if repeat is not None: | |
1855 | code_block = numpy.repeat(code_block, repeats=repeat, axis=1) |
|
1855 | code_block = numpy.repeat(code_block, repeats=repeat, axis=1) | |
1856 | #print(code_block.shape) |
|
1856 | #print(code_block.shape) | |
1857 | for i in range(self.buffer.shape[1]): |
|
1857 | for i in range(self.buffer.shape[1]): | |
1858 |
|
1858 | |||
1859 | if code is not None: |
|
1859 | if code is not None: | |
1860 | self.buffer[:,i] = dataOut.data[:,i*self.step:i*self.step + self.nsamples]*code_block |
|
1860 | self.buffer[:,i] = dataOut.data[:,i*self.step:i*self.step + self.nsamples]*code_block | |
1861 |
|
1861 | |||
1862 | else: |
|
1862 | else: | |
1863 |
|
1863 | |||
1864 | self.buffer[:,i] = dataOut.data[:,i*self.step:i*self.step + self.nsamples]#*code[dataOut.profileIndex,:] |
|
1864 | self.buffer[:,i] = dataOut.data[:,i*self.step:i*self.step + self.nsamples]#*code[dataOut.profileIndex,:] | |
1865 |
|
1865 | |||
1866 | #self.buffer[:,j,self.__nHeis-j*self.step - self.nheights:self.__nHeis-j*self.step] = numpy.flip(dataOut.data[:,j*self.step:j*self.step + self.nheights]) |
|
1866 | #self.buffer[:,j,self.__nHeis-j*self.step - self.nheights:self.__nHeis-j*self.step] = numpy.flip(dataOut.data[:,j*self.step:j*self.step + self.nheights]) | |
1867 |
|
1867 | |||
1868 | for j in range(self.buffer.shape[0]): |
|
1868 | for j in range(self.buffer.shape[0]): | |
1869 | self.sshProfiles[j] = numpy.transpose(self.buffer[j]) |
|
1869 | self.sshProfiles[j] = numpy.transpose(self.buffer[j]) | |
1870 |
|
1870 | |||
1871 | profileIndex = self.nsamples |
|
1871 | profileIndex = self.nsamples | |
1872 | deltaHeight = dataOut.heightList[1] - dataOut.heightList[0] |
|
1872 | deltaHeight = dataOut.heightList[1] - dataOut.heightList[0] | |
1873 | ippSeconds = (deltaHeight*1.0e-6)/(0.15) |
|
1873 | ippSeconds = (deltaHeight*1.0e-6)/(0.15) | |
1874 | #print("ippSeconds, dH: ",ippSeconds,deltaHeight) |
|
1874 | #print("ippSeconds, dH: ",ippSeconds,deltaHeight) | |
1875 | try: |
|
1875 | try: | |
1876 | if dataOut.concat_m is not None: |
|
1876 | if dataOut.concat_m is not None: | |
1877 | ippSeconds= ippSeconds/float(dataOut.concat_m) |
|
1877 | ippSeconds= ippSeconds/float(dataOut.concat_m) | |
1878 | #print "Profile concat %d"%dataOut.concat_m |
|
1878 | #print "Profile concat %d"%dataOut.concat_m | |
1879 | except: |
|
1879 | except: | |
1880 | pass |
|
1880 | pass | |
1881 |
|
1881 | |||
1882 | dataOut.data = self.sshProfiles |
|
1882 | dataOut.data = self.sshProfiles | |
1883 | dataOut.flagNoData = False |
|
1883 | dataOut.flagNoData = False | |
1884 | dataOut.heightList = numpy.arange(self.buffer.shape[1]) *self.step*deltaHeight + dataOut.heightList[0] |
|
1884 | dataOut.heightList = numpy.arange(self.buffer.shape[1]) *self.step*deltaHeight + dataOut.heightList[0] | |
1885 | dataOut.nProfiles = int(dataOut.nProfiles*self.nsamples) |
|
1885 | dataOut.nProfiles = int(dataOut.nProfiles*self.nsamples) | |
1886 |
|
1886 | |||
1887 | dataOut.profileIndex = profileIndex |
|
1887 | dataOut.profileIndex = profileIndex | |
1888 | dataOut.flagDataAsBlock = True |
|
1888 | dataOut.flagDataAsBlock = True | |
1889 | dataOut.ippSeconds = ippSeconds |
|
1889 | dataOut.ippSeconds = ippSeconds | |
1890 | dataOut.step = self.step |
|
1890 | dataOut.step = self.step | |
1891 | #print(numpy.shape(dataOut.data)) |
|
1891 | #print(numpy.shape(dataOut.data)) | |
1892 | #exit(1) |
|
1892 | #exit(1) | |
1893 | #print("new data shape and time:", dataOut.data.shape, dataOut.utctime) |
|
1893 | #print("new data shape and time:", dataOut.data.shape, dataOut.utctime) | |
1894 |
|
1894 | |||
1895 | return dataOut |
|
1895 | return dataOut | |
1896 | ################################################################################3############################3 |
|
1896 | ################################################################################3############################3 | |
1897 | ################################################################################3############################3 |
|
1897 | ################################################################################3############################3 | |
1898 | ################################################################################3############################3 |
|
1898 | ################################################################################3############################3 | |
1899 | ################################################################################3############################3 |
|
1899 | ################################################################################3############################3 | |
1900 |
|
1900 | |||
1901 | class SSheightProfiles2(Operation): |
|
1901 | class SSheightProfiles2(Operation): | |
1902 | ''' |
|
1902 | ''' | |
1903 | Procesa por perfiles y por bloques |
|
1903 | Procesa por perfiles y por bloques | |
1904 | VersiΓ³n corregida y actualizada para trabajar con RemoveProfileSats2 |
|
1904 | VersiΓ³n corregida y actualizada para trabajar con RemoveProfileSats2 | |
1905 | Usar esto |
|
1905 | Usar esto | |
1906 | ''' |
|
1906 | ''' | |
1907 |
|
1907 | |||
1908 |
|
1908 | |||
1909 | bufferShape = None |
|
1909 | bufferShape = None | |
1910 | profileShape = None |
|
1910 | profileShape = None | |
1911 | sshProfiles = None |
|
1911 | sshProfiles = None | |
1912 | profileIndex = None |
|
1912 | profileIndex = None | |
1913 | #nsamples = None |
|
1913 | #nsamples = None | |
1914 | #step = None |
|
1914 | #step = None | |
1915 | #deltaHeight = None |
|
1915 | #deltaHeight = None | |
1916 | #init_range = None |
|
1916 | #init_range = None | |
1917 | __slots__ = ('step', 'nsamples', 'deltaHeight', 'init_range', 'isConfig', '__nChannels', |
|
1917 | __slots__ = ('step', 'nsamples', 'deltaHeight', 'init_range', 'isConfig', '__nChannels', | |
1918 | '__nProfiles', '__nHeis', 'deltaHeight', 'new_nHeights') |
|
1918 | '__nProfiles', '__nHeis', 'deltaHeight', 'new_nHeights') | |
1919 |
|
1919 | |||
1920 | def __init__(self, **kwargs): |
|
1920 | def __init__(self, **kwargs): | |
1921 |
|
1921 | |||
1922 | Operation.__init__(self, **kwargs) |
|
1922 | Operation.__init__(self, **kwargs) | |
1923 | self.isConfig = False |
|
1923 | self.isConfig = False | |
1924 |
|
1924 | |||
1925 | def setup(self,dataOut ,step = None , nsamples = None): |
|
1925 | def setup(self,dataOut ,step = None , nsamples = None): | |
1926 |
|
1926 | |||
1927 | if step == None and nsamples == None: |
|
1927 | if step == None and nsamples == None: | |
1928 | raise ValueError("step or nheights should be specified ...") |
|
1928 | raise ValueError("step or nheights should be specified ...") | |
1929 |
|
1929 | |||
1930 | self.step = step |
|
1930 | self.step = step | |
1931 | self.nsamples = nsamples |
|
1931 | self.nsamples = nsamples | |
1932 | self.__nChannels = int(dataOut.nChannels) |
|
1932 | self.__nChannels = int(dataOut.nChannels) | |
1933 | self.__nProfiles = int(dataOut.nProfiles) |
|
1933 | self.__nProfiles = int(dataOut.nProfiles) | |
1934 | self.__nHeis = int(dataOut.nHeights) |
|
1934 | self.__nHeis = int(dataOut.nHeights) | |
1935 |
|
1935 | |||
1936 | residue = (self.__nHeis - self.nsamples) % self.step |
|
1936 | residue = (self.__nHeis - self.nsamples) % self.step | |
1937 | if residue != 0: |
|
1937 | if residue != 0: | |
1938 | print("The residue is %d, step=%d should be multiple of %d to avoid loss of %d samples"%(residue,step,self.__nProfiles - self.nsamples,residue)) |
|
1938 | print("The residue is %d, step=%d should be multiple of %d to avoid loss of %d samples"%(residue,step,self.__nProfiles - self.nsamples,residue)) | |
1939 |
|
1939 | |||
1940 | self.deltaHeight = dataOut.heightList[1] - dataOut.heightList[0] |
|
1940 | self.deltaHeight = dataOut.heightList[1] - dataOut.heightList[0] | |
1941 | self.init_range = dataOut.heightList[0] |
|
1941 | self.init_range = dataOut.heightList[0] | |
1942 | #numberProfile = self.nsamples |
|
1942 | #numberProfile = self.nsamples | |
1943 | numberSamples = (self.__nHeis - self.nsamples)/self.step |
|
1943 | numberSamples = (self.__nHeis - self.nsamples)/self.step | |
1944 |
|
1944 | |||
1945 | self.new_nHeights = numberSamples |
|
1945 | self.new_nHeights = numberSamples | |
1946 |
|
1946 | |||
1947 | self.bufferShape = int(self.__nChannels), int(numberSamples), int(self.nsamples) # nchannels, nsamples , nprofiles |
|
1947 | self.bufferShape = int(self.__nChannels), int(numberSamples), int(self.nsamples) # nchannels, nsamples , nprofiles | |
1948 | self.profileShape = int(self.__nChannels), int(self.nsamples), int(numberSamples) # nchannels, nprofiles, nsamples |
|
1948 | self.profileShape = int(self.__nChannels), int(self.nsamples), int(numberSamples) # nchannels, nprofiles, nsamples | |
1949 |
|
1949 | |||
1950 | self.buffer = numpy.zeros(self.bufferShape , dtype=numpy.complex) |
|
1950 | self.buffer = numpy.zeros(self.bufferShape , dtype=numpy.complex) | |
1951 | self.sshProfiles = numpy.zeros(self.profileShape, dtype=numpy.complex) |
|
1951 | self.sshProfiles = numpy.zeros(self.profileShape, dtype=numpy.complex) | |
1952 |
|
1952 | |||
1953 | def getNewProfiles(self, data, code=None, repeat=None): |
|
1953 | def getNewProfiles(self, data, code=None, repeat=None): | |
1954 |
|
1954 | |||
1955 | if code is not None: |
|
1955 | if code is not None: | |
1956 | code = numpy.array(code) |
|
1956 | code = numpy.array(code) | |
1957 | code_block = code |
|
1957 | code_block = code | |
1958 |
|
1958 | |||
1959 | if repeat is not None: |
|
1959 | if repeat is not None: | |
1960 | code_block = numpy.repeat(code_block, repeats=repeat, axis=1) |
|
1960 | code_block = numpy.repeat(code_block, repeats=repeat, axis=1) | |
1961 | if data.ndim < 3: |
|
1961 | if data.ndim < 3: | |
1962 | data = data.reshape(self.__nChannels,1,self.__nHeis ) |
|
1962 | data = data.reshape(self.__nChannels,1,self.__nHeis ) | |
1963 | #print("buff, data, :",self.buffer.shape, data.shape,self.sshProfiles.shape, code_block.shape) |
|
1963 | #print("buff, data, :",self.buffer.shape, data.shape,self.sshProfiles.shape, code_block.shape) | |
1964 | for ch in range(self.__nChannels): |
|
1964 | for ch in range(self.__nChannels): | |
1965 | for i in range(int(self.new_nHeights)): #nuevas alturas |
|
1965 | for i in range(int(self.new_nHeights)): #nuevas alturas | |
1966 | if code is not None: |
|
1966 | if code is not None: | |
1967 | self.buffer[ch,i,:] = data[ch,:,i*self.step:i*self.step + self.nsamples]*code_block |
|
1967 | self.buffer[ch,i,:] = data[ch,:,i*self.step:i*self.step + self.nsamples]*code_block | |
1968 | else: |
|
1968 | else: | |
1969 | self.buffer[ch,i,:] = data[ch,:,i*self.step:i*self.step + self.nsamples]#*code[dataOut.profileIndex,:] |
|
1969 | self.buffer[ch,i,:] = data[ch,:,i*self.step:i*self.step + self.nsamples]#*code[dataOut.profileIndex,:] | |
1970 |
|
1970 | |||
1971 | for j in range(self.__nChannels): #en los cananles |
|
1971 | for j in range(self.__nChannels): #en los cananles | |
1972 | self.sshProfiles[j,:,:] = numpy.transpose(self.buffer[j,:,:]) |
|
1972 | self.sshProfiles[j,:,:] = numpy.transpose(self.buffer[j,:,:]) | |
1973 | #print("new profs Done") |
|
1973 | #print("new profs Done") | |
1974 |
|
1974 | |||
1975 |
|
1975 | |||
1976 |
|
1976 | |||
1977 | def run(self, dataOut, step, nsamples, code = None, repeat = None): |
|
1977 | def run(self, dataOut, step, nsamples, code = None, repeat = None): | |
1978 | # print("running") |
|
1978 | # print("running") | |
1979 | if dataOut.flagNoData == True: |
|
1979 | if dataOut.flagNoData == True: | |
1980 | return dataOut |
|
1980 | return dataOut | |
1981 | dataOut.flagNoData = True |
|
1981 | dataOut.flagNoData = True | |
1982 | #print("init data shape:", dataOut.data.shape) |
|
1982 | #print("init data shape:", dataOut.data.shape) | |
1983 | #print("ch: {} prof: {} hs: {}".format(int(dataOut.nChannels), |
|
1983 | #print("ch: {} prof: {} hs: {}".format(int(dataOut.nChannels), | |
1984 | # int(dataOut.nProfiles),int(dataOut.nHeights))) |
|
1984 | # int(dataOut.nProfiles),int(dataOut.nHeights))) | |
1985 |
|
1985 | |||
1986 | profileIndex = None |
|
1986 | profileIndex = None | |
1987 | # if not dataOut.flagDataAsBlock: |
|
1987 | # if not dataOut.flagDataAsBlock: | |
1988 | # dataOut.nProfiles = 1 |
|
1988 | # dataOut.nProfiles = 1 | |
1989 |
|
1989 | |||
1990 | if not self.isConfig: |
|
1990 | if not self.isConfig: | |
1991 | self.setup(dataOut, step=step , nsamples=nsamples) |
|
1991 | self.setup(dataOut, step=step , nsamples=nsamples) | |
1992 | #print("Setup done") |
|
1992 | #print("Setup done") | |
1993 | self.isConfig = True |
|
1993 | self.isConfig = True | |
1994 |
|
1994 | |||
1995 | dataBlock = None |
|
1995 | dataBlock = None | |
1996 |
|
1996 | |||
1997 | nprof = 1 |
|
1997 | nprof = 1 | |
1998 | if dataOut.flagDataAsBlock: |
|
1998 | if dataOut.flagDataAsBlock: | |
1999 | nprof = int(dataOut.nProfiles) |
|
1999 | nprof = int(dataOut.nProfiles) | |
2000 |
|
2000 | |||
2001 | #print("dataOut nProfiles:", dataOut.nProfiles) |
|
2001 | #print("dataOut nProfiles:", dataOut.nProfiles) | |
2002 | for profile in range(nprof): |
|
2002 | for profile in range(nprof): | |
2003 | if dataOut.flagDataAsBlock: |
|
2003 | if dataOut.flagDataAsBlock: | |
2004 | #print("read blocks") |
|
2004 | #print("read blocks") | |
2005 | self.getNewProfiles(dataOut.data[:,profile,:], code=code, repeat=repeat) |
|
2005 | self.getNewProfiles(dataOut.data[:,profile,:], code=code, repeat=repeat) | |
2006 | else: |
|
2006 | else: | |
2007 | #print("read profiles") |
|
2007 | #print("read profiles") | |
2008 | self.getNewProfiles(dataOut.data, code=code, repeat=repeat) #only one channe |
|
2008 | self.getNewProfiles(dataOut.data, code=code, repeat=repeat) #only one channe | |
2009 | if profile == 0: |
|
2009 | if profile == 0: | |
2010 | dataBlock = self.sshProfiles.copy() |
|
2010 | dataBlock = self.sshProfiles.copy() | |
2011 | else: #by blocks |
|
2011 | else: #by blocks | |
2012 | dataBlock = numpy.concatenate((dataBlock,self.sshProfiles), axis=1) #profile axis |
|
2012 | dataBlock = numpy.concatenate((dataBlock,self.sshProfiles), axis=1) #profile axis | |
2013 | #print("by blocks: ",dataBlock.shape, self.sshProfiles.shape) |
|
2013 | #print("by blocks: ",dataBlock.shape, self.sshProfiles.shape) | |
2014 |
|
2014 | |||
2015 | profileIndex = self.nsamples |
|
2015 | profileIndex = self.nsamples | |
2016 | #deltaHeight = dataOut.heightList[1] - dataOut.heightList[0] |
|
2016 | #deltaHeight = dataOut.heightList[1] - dataOut.heightList[0] | |
2017 | ippSeconds = (self.deltaHeight*1.0e-6)/(0.15) |
|
2017 | ippSeconds = (self.deltaHeight*1.0e-6)/(0.15) | |
2018 |
|
2018 | |||
2019 |
|
2019 | |||
2020 | dataOut.data = dataBlock |
|
2020 | dataOut.data = dataBlock | |
2021 | #print("show me: ",self.step,self.deltaHeight, dataOut.heightList, self.new_nHeights) |
|
2021 | #print("show me: ",self.step,self.deltaHeight, dataOut.heightList, self.new_nHeights) | |
2022 | dataOut.heightList = numpy.arange(int(self.new_nHeights)) *self.step*self.deltaHeight + self.init_range |
|
2022 | dataOut.heightList = numpy.arange(int(self.new_nHeights)) *self.step*self.deltaHeight + self.init_range | |
2023 | dataOut.sampled_heightsFFT = self.nsamples |
|
2023 | dataOut.sampled_heightsFFT = self.nsamples | |
2024 | dataOut.ippSeconds = ippSeconds |
|
2024 | dataOut.ippSeconds = ippSeconds | |
2025 | dataOut.step = self.step |
|
2025 | dataOut.step = self.step | |
2026 | dataOut.deltaHeight = self.step*self.deltaHeight |
|
2026 | dataOut.deltaHeight = self.step*self.deltaHeight | |
2027 | dataOut.flagNoData = False |
|
2027 | dataOut.flagNoData = False | |
2028 | if dataOut.flagDataAsBlock: |
|
2028 | if dataOut.flagDataAsBlock: | |
2029 | dataOut.nProfiles = int(dataOut.nProfiles*self.nsamples) |
|
2029 | dataOut.nProfiles = int(dataOut.nProfiles*self.nsamples) | |
2030 |
|
2030 | |||
2031 | else: |
|
2031 | else: | |
2032 | dataOut.nProfiles = int(self.nsamples) |
|
2032 | dataOut.nProfiles = int(self.nsamples) | |
2033 | dataOut.profileIndex = dataOut.nProfiles |
|
2033 | dataOut.profileIndex = dataOut.nProfiles | |
2034 | dataOut.flagDataAsBlock = True |
|
2034 | dataOut.flagDataAsBlock = True | |
2035 |
|
2035 | |||
2036 | dataBlock = None |
|
2036 | dataBlock = None | |
2037 |
|
2037 | |||
2038 | #print("new data shape:", dataOut.data.shape, dataOut.utctime) |
|
2038 | #print("new data shape:", dataOut.data.shape, dataOut.utctime) | |
2039 |
|
2039 | |||
2040 | #update Processing Header: |
|
2040 | #update Processing Header: | |
2041 | dataOut.processingHeaderObj.heightList = dataOut.heightList |
|
2041 | dataOut.processingHeaderObj.heightList = dataOut.heightList | |
2042 | dataOut.processingHeaderObj.ipp = ippSeconds |
|
2042 | dataOut.processingHeaderObj.ipp = ippSeconds | |
2043 | dataOut.processingHeaderObj.heightResolution = dataOut.deltaHeight |
|
2043 | dataOut.processingHeaderObj.heightResolution = dataOut.deltaHeight | |
2044 | #dataOut.processingHeaderObj.profilesPerBlock = nProfiles |
|
2044 | #dataOut.processingHeaderObj.profilesPerBlock = nProfiles | |
2045 |
|
2045 | |||
2046 | # # dataOut.data = CH, PROFILES, HEIGHTS |
|
2046 | # # dataOut.data = CH, PROFILES, HEIGHTS | |
2047 | #print(dataOut.data .shape) |
|
2047 | #print(dataOut.data .shape) | |
2048 | if dataOut.flagProfilesByRange: |
|
2048 | if dataOut.flagProfilesByRange: | |
2049 | # #assuming the same remotion for all channels |
|
2049 | # #assuming the same remotion for all channels | |
2050 | aux = [ self.nsamples - numpy.count_nonzero(dataOut.data[0, :, h]==0) for h in range(len(dataOut.heightList))] |
|
2050 | aux = [ self.nsamples - numpy.count_nonzero(dataOut.data[0, :, h]==0) for h in range(len(dataOut.heightList))] | |
2051 | dataOut.nProfilesByRange = (numpy.asarray(aux)).reshape((1,len(dataOut.heightList) )) |
|
2051 | dataOut.nProfilesByRange = (numpy.asarray(aux)).reshape((1,len(dataOut.heightList) )) | |
2052 | #print(dataOut.nProfilesByRange.shape) |
|
2052 | #print(dataOut.nProfilesByRange.shape) | |
2053 | else: |
|
2053 | else: | |
2054 | dataOut.nProfilesByRange = numpy.ones((1, len(dataOut.heightList)))*dataOut.nProfiles |
|
2054 | dataOut.nProfilesByRange = numpy.ones((1, len(dataOut.heightList)))*dataOut.nProfiles | |
2055 | return dataOut |
|
2055 | return dataOut | |
2056 |
|
2056 | |||
2057 |
|
2057 | |||
2058 |
|
2058 | |||
2059 | class RemoveProfileSats(Operation): |
|
2059 | class RemoveProfileSats(Operation): | |
2060 | ''' |
|
2060 | ''' | |
2061 | Escrito: Joab Apaza |
|
2061 | Escrito: Joab Apaza | |
2062 |
|
2062 | |||
2063 | Omite los perfiles contaminados con seΓ±al de satΓ©lites, usando una altura de referencia |
|
2063 | Omite los perfiles contaminados con seΓ±al de satΓ©lites, usando una altura de referencia | |
2064 | In: minHei = min_sat_range |
|
2064 | In: minHei = min_sat_range | |
2065 | max_sat_range |
|
2065 | max_sat_range | |
2066 | min_hei_ref |
|
2066 | min_hei_ref | |
2067 | max_hei_ref |
|
2067 | max_hei_ref | |
2068 | th = diference between profiles mean, ref and sats |
|
2068 | th = diference between profiles mean, ref and sats | |
2069 | Out: |
|
2069 | Out: | |
2070 | profile clean |
|
2070 | profile clean | |
2071 | ''' |
|
2071 | ''' | |
2072 |
|
2072 | |||
2073 |
|
2073 | |||
2074 | __buffer_data = [] |
|
2074 | __buffer_data = [] | |
2075 | __buffer_times = [] |
|
2075 | __buffer_times = [] | |
2076 |
|
2076 | |||
2077 | buffer = None |
|
2077 | buffer = None | |
2078 |
|
2078 | |||
2079 | outliers_IDs_list = [] |
|
2079 | outliers_IDs_list = [] | |
2080 |
|
2080 | |||
2081 |
|
2081 | |||
2082 | __slots__ = ('n','navg','profileMargin','thHistOutlier','minHei_idx','maxHei_idx','nHeights', |
|
2082 | __slots__ = ('n','navg','profileMargin','thHistOutlier','minHei_idx','maxHei_idx','nHeights', | |
2083 | 'first_utcBlock','__profIndex','init_prof','end_prof','lenProfileOut','nChannels', |
|
2083 | 'first_utcBlock','__profIndex','init_prof','end_prof','lenProfileOut','nChannels', | |
2084 | '__count_exec','__initime','__dataReady','__ipp', 'minRef', 'maxRef', 'thdB') |
|
2084 | '__count_exec','__initime','__dataReady','__ipp', 'minRef', 'maxRef', 'thdB') | |
2085 | def __init__(self, **kwargs): |
|
2085 | def __init__(self, **kwargs): | |
2086 |
|
2086 | |||
2087 | Operation.__init__(self, **kwargs) |
|
2087 | Operation.__init__(self, **kwargs) | |
2088 | self.isConfig = False |
|
2088 | self.isConfig = False | |
2089 |
|
2089 | |||
2090 | def setup(self,dataOut, n=None , navg=0.8, profileMargin=50,thHistOutlier=15, |
|
2090 | def setup(self,dataOut, n=None , navg=0.8, profileMargin=50,thHistOutlier=15, | |
2091 | minHei=None, maxHei=None, minRef=None, maxRef=None, thdB=10): |
|
2091 | minHei=None, maxHei=None, minRef=None, maxRef=None, thdB=10): | |
2092 |
|
2092 | |||
2093 | if n == None and timeInterval == None: |
|
2093 | if n == None and timeInterval == None: | |
2094 | raise ValueError("nprofiles or timeInterval should be specified ...") |
|
2094 | raise ValueError("nprofiles or timeInterval should be specified ...") | |
2095 |
|
2095 | |||
2096 | if n != None: |
|
2096 | if n != None: | |
2097 | self.n = n |
|
2097 | self.n = n | |
2098 |
|
2098 | |||
2099 | self.navg = navg |
|
2099 | self.navg = navg | |
2100 | self.profileMargin = profileMargin |
|
2100 | self.profileMargin = profileMargin | |
2101 | self.thHistOutlier = thHistOutlier |
|
2101 | self.thHistOutlier = thHistOutlier | |
2102 | self.__profIndex = 0 |
|
2102 | self.__profIndex = 0 | |
2103 | self.buffer = None |
|
2103 | self.buffer = None | |
2104 | self._ipp = dataOut.ippSeconds |
|
2104 | self._ipp = dataOut.ippSeconds | |
2105 | self.n_prof_released = 0 |
|
2105 | self.n_prof_released = 0 | |
2106 | self.heightList = dataOut.heightList |
|
2106 | self.heightList = dataOut.heightList | |
2107 | self.init_prof = 0 |
|
2107 | self.init_prof = 0 | |
2108 | self.end_prof = 0 |
|
2108 | self.end_prof = 0 | |
2109 | self.__count_exec = 0 |
|
2109 | self.__count_exec = 0 | |
2110 | self.__profIndex = 0 |
|
2110 | self.__profIndex = 0 | |
2111 | self.first_utcBlock = None |
|
2111 | self.first_utcBlock = None | |
2112 | #self.__dh = dataOut.heightList[1] - dataOut.heightList[0] |
|
2112 | #self.__dh = dataOut.heightList[1] - dataOut.heightList[0] | |
2113 | minHei = minHei |
|
2113 | minHei = minHei | |
2114 | maxHei = maxHei |
|
2114 | maxHei = maxHei | |
2115 | if minHei==None : |
|
2115 | if minHei==None : | |
2116 | minHei = dataOut.heightList[0] |
|
2116 | minHei = dataOut.heightList[0] | |
2117 | if maxHei==None : |
|
2117 | if maxHei==None : | |
2118 | maxHei = dataOut.heightList[-1] |
|
2118 | maxHei = dataOut.heightList[-1] | |
2119 | self.minHei_idx,self.maxHei_idx = getHei_index(minHei, maxHei, dataOut.heightList) |
|
2119 | self.minHei_idx,self.maxHei_idx = getHei_index(minHei, maxHei, dataOut.heightList) | |
2120 | self.min_ref, self.max_ref = getHei_index(minRef, maxRef, dataOut.heightList) |
|
2120 | self.min_ref, self.max_ref = getHei_index(minRef, maxRef, dataOut.heightList) | |
2121 | self.nChannels = dataOut.nChannels |
|
2121 | self.nChannels = dataOut.nChannels | |
2122 | self.nHeights = dataOut.nHeights |
|
2122 | self.nHeights = dataOut.nHeights | |
2123 | self.test_counter = 0 |
|
2123 | self.test_counter = 0 | |
2124 | self.thdB = thdB |
|
2124 | self.thdB = thdB | |
2125 |
|
2125 | |||
2126 | def filterSatsProfiles(self): |
|
2126 | def filterSatsProfiles(self): | |
2127 | data = self.__buffer_data |
|
2127 | data = self.__buffer_data | |
2128 | #print(data.shape) |
|
2128 | #print(data.shape) | |
2129 | nChannels, profiles, heights = data.shape |
|
2129 | nChannels, profiles, heights = data.shape | |
2130 | indexes=numpy.zeros([], dtype=int) |
|
2130 | indexes=numpy.zeros([], dtype=int) | |
2131 | outliers_IDs=[] |
|
2131 | outliers_IDs=[] | |
2132 | for c in range(nChannels): |
|
2132 | for c in range(nChannels): | |
2133 | #print(self.min_ref,self.max_ref) |
|
2133 | #print(self.min_ref,self.max_ref) | |
2134 | noise_ref = 10* numpy.log10((data[c,:,self.min_ref:self.max_ref] * numpy.conjugate(data[c,:,self.min_ref:self.max_ref])).real) |
|
2134 | noise_ref = 10* numpy.log10((data[c,:,self.min_ref:self.max_ref] * numpy.conjugate(data[c,:,self.min_ref:self.max_ref])).real) | |
2135 | #print("Noise ",numpy.percentile(noise_ref,95)) |
|
2135 | #print("Noise ",numpy.percentile(noise_ref,95)) | |
2136 | p95 = numpy.percentile(noise_ref,95) |
|
2136 | p95 = numpy.percentile(noise_ref,95) | |
2137 | noise_ref = noise_ref.mean() |
|
2137 | noise_ref = noise_ref.mean() | |
2138 | #print("Noise ",noise_ref |
|
2138 | #print("Noise ",noise_ref | |
2139 |
|
2139 | |||
2140 |
|
2140 | |||
2141 | for h in range(self.minHei_idx, self.maxHei_idx): |
|
2141 | for h in range(self.minHei_idx, self.maxHei_idx): | |
2142 | power = 10* numpy.log10((data[c,:,h] * numpy.conjugate(data[c,:,h])).real) |
|
2142 | power = 10* numpy.log10((data[c,:,h] * numpy.conjugate(data[c,:,h])).real) | |
2143 | #th = noise_ref + self.thdB |
|
2143 | #th = noise_ref + self.thdB | |
2144 | th = noise_ref + 1.5*(p95-noise_ref) |
|
2144 | th = noise_ref + 1.5*(p95-noise_ref) | |
2145 | index = numpy.where(power > th ) |
|
2145 | index = numpy.where(power > th ) | |
2146 | if index[0].size > 10 and index[0].size < int(self.navg*profiles): |
|
2146 | if index[0].size > 10 and index[0].size < int(self.navg*profiles): | |
2147 | indexes = numpy.append(indexes, index[0]) |
|
2147 | indexes = numpy.append(indexes, index[0]) | |
2148 | #print(index[0]) |
|
2148 | #print(index[0]) | |
2149 | #print(index[0]) |
|
2149 | #print(index[0]) | |
2150 |
|
2150 | |||
2151 | # fig,ax = plt.subplots() |
|
2151 | # fig,ax = plt.subplots() | |
2152 | # #ax.set_title(str(k)+" "+str(j)) |
|
2152 | # #ax.set_title(str(k)+" "+str(j)) | |
2153 | # x=range(len(power)) |
|
2153 | # x=range(len(power)) | |
2154 | # ax.scatter(x,power) |
|
2154 | # ax.scatter(x,power) | |
2155 | # #ax.axvline(index) |
|
2155 | # #ax.axvline(index) | |
2156 | # plt.grid() |
|
2156 | # plt.grid() | |
2157 | # plt.show() |
|
2157 | # plt.show() | |
2158 | #print(indexes) |
|
2158 | #print(indexes) | |
2159 |
|
2159 | |||
2160 | #outliers_IDs = outliers_IDs.astype(numpy.dtype('int64')) |
|
2160 | #outliers_IDs = outliers_IDs.astype(numpy.dtype('int64')) | |
2161 | #outliers_IDs = numpy.unique(outliers_IDs) |
|
2161 | #outliers_IDs = numpy.unique(outliers_IDs) | |
2162 |
|
2162 | |||
2163 | outs_lines = numpy.unique(indexes) |
|
2163 | outs_lines = numpy.unique(indexes) | |
2164 |
|
2164 | |||
2165 |
|
2165 | |||
2166 | #Agrupando el histograma de outliers, |
|
2166 | #Agrupando el histograma de outliers, | |
2167 | my_bins = numpy.linspace(0,int(profiles), int(profiles/100), endpoint=True) |
|
2167 | my_bins = numpy.linspace(0,int(profiles), int(profiles/100), endpoint=True) | |
2168 |
|
2168 | |||
2169 |
|
2169 | |||
2170 | hist, bins = numpy.histogram(outs_lines,bins=my_bins) |
|
2170 | hist, bins = numpy.histogram(outs_lines,bins=my_bins) | |
2171 | hist_outliers_indexes = numpy.where(hist > self.thHistOutlier) #es outlier |
|
2171 | hist_outliers_indexes = numpy.where(hist > self.thHistOutlier) #es outlier | |
2172 | hist_outliers_indexes = hist_outliers_indexes[0] |
|
2172 | hist_outliers_indexes = hist_outliers_indexes[0] | |
2173 | # if len(hist_outliers_indexes>0): |
|
2173 | # if len(hist_outliers_indexes>0): | |
2174 | # hist_outliers_indexes = numpy.append(hist_outliers_indexes,hist_outliers_indexes[-1]+1) |
|
2174 | # hist_outliers_indexes = numpy.append(hist_outliers_indexes,hist_outliers_indexes[-1]+1) | |
2175 | #print(hist_outliers_indexes) |
|
2175 | #print(hist_outliers_indexes) | |
2176 | #print(bins, hist_outliers_indexes) |
|
2176 | #print(bins, hist_outliers_indexes) | |
2177 | bins_outliers_indexes = [int(i) for i in (bins[hist_outliers_indexes])] # |
|
2177 | bins_outliers_indexes = [int(i) for i in (bins[hist_outliers_indexes])] # | |
2178 | outlier_loc_index = [] |
|
2178 | outlier_loc_index = [] | |
2179 | # for n in range(len(bins_outliers_indexes)): |
|
2179 | # for n in range(len(bins_outliers_indexes)): | |
2180 | # for e in range(bins_outliers_indexes[n]-self.profileMargin,bins_outliers_indexes[n]+ self.profileMargin): |
|
2180 | # for e in range(bins_outliers_indexes[n]-self.profileMargin,bins_outliers_indexes[n]+ self.profileMargin): | |
2181 | # outlier_loc_index.append(e) |
|
2181 | # outlier_loc_index.append(e) | |
2182 | outlier_loc_index = [e for n in range(len(bins_outliers_indexes)) for e in range(bins_outliers_indexes[n]-self.profileMargin,bins_outliers_indexes[n]+ profiles//100 + self.profileMargin) ] |
|
2182 | outlier_loc_index = [e for n in range(len(bins_outliers_indexes)) for e in range(bins_outliers_indexes[n]-self.profileMargin,bins_outliers_indexes[n]+ profiles//100 + self.profileMargin) ] | |
2183 | outlier_loc_index = numpy.asarray(outlier_loc_index) |
|
2183 | outlier_loc_index = numpy.asarray(outlier_loc_index) | |
2184 |
|
2184 | |||
2185 |
|
2185 | |||
2186 |
|
2186 | |||
2187 |
|
2187 | |||
2188 | #print("outliers Ids: ", outlier_loc_index, outlier_loc_index.shape) |
|
2188 | #print("outliers Ids: ", outlier_loc_index, outlier_loc_index.shape) | |
2189 | outlier_loc_index = outlier_loc_index[ (outlier_loc_index >= 0) & (outlier_loc_index<profiles)] |
|
2189 | outlier_loc_index = outlier_loc_index[ (outlier_loc_index >= 0) & (outlier_loc_index<profiles)] | |
2190 | #print("outliers final: ", outlier_loc_index) |
|
2190 | #print("outliers final: ", outlier_loc_index) | |
2191 |
|
2191 | |||
2192 | from matplotlib import pyplot as plt |
|
2192 | from matplotlib import pyplot as plt | |
2193 | x, y = numpy.meshgrid(numpy.arange(profiles), self.heightList) |
|
2193 | x, y = numpy.meshgrid(numpy.arange(profiles), self.heightList) | |
2194 | fig, ax = plt.subplots(1,2,figsize=(8, 6)) |
|
2194 | fig, ax = plt.subplots(1,2,figsize=(8, 6)) | |
2195 | dat = data[0,:,:].real |
|
2195 | dat = data[0,:,:].real | |
2196 | dat = 10* numpy.log10((data[0,:,:] * numpy.conjugate(data[0,:,:])).real) |
|
2196 | dat = 10* numpy.log10((data[0,:,:] * numpy.conjugate(data[0,:,:])).real) | |
2197 | m = numpy.nanmean(dat) |
|
2197 | m = numpy.nanmean(dat) | |
2198 | o = numpy.nanstd(dat) |
|
2198 | o = numpy.nanstd(dat) | |
2199 | #print(m, o, x.shape, y.shape) |
|
2199 | #print(m, o, x.shape, y.shape) | |
2200 | #c = ax[0].pcolormesh(x, y, dat.T, cmap ='YlGnBu', vmin = (m-2*o), vmax = (m+2*o)) |
|
2200 | #c = ax[0].pcolormesh(x, y, dat.T, cmap ='YlGnBu', vmin = (m-2*o), vmax = (m+2*o)) | |
2201 | c = ax[0].pcolormesh(x, y, dat.T, cmap ='YlGnBu', vmin = 50, vmax = 75) |
|
2201 | c = ax[0].pcolormesh(x, y, dat.T, cmap ='YlGnBu', vmin = 50, vmax = 75) | |
2202 | ax[0].vlines(outs_lines,200,600, linestyles='dashed', label = 'outs', color='w') |
|
2202 | ax[0].vlines(outs_lines,200,600, linestyles='dashed', label = 'outs', color='w') | |
2203 | fig.colorbar(c) |
|
2203 | fig.colorbar(c) | |
2204 | ax[0].vlines(outlier_loc_index,650,750, linestyles='dashed', label = 'outs', color='r') |
|
2204 | ax[0].vlines(outlier_loc_index,650,750, linestyles='dashed', label = 'outs', color='r') | |
2205 | ax[1].hist(outs_lines,bins=my_bins) |
|
2205 | ax[1].hist(outs_lines,bins=my_bins) | |
2206 | plt.show() |
|
2206 | plt.show() | |
2207 |
|
2207 | |||
2208 |
|
2208 | |||
2209 | self.outliers_IDs_list = outlier_loc_index |
|
2209 | self.outliers_IDs_list = outlier_loc_index | |
2210 | #print("outs list: ", self.outliers_IDs_list) |
|
2210 | #print("outs list: ", self.outliers_IDs_list) | |
2211 | return data |
|
2211 | return data | |
2212 |
|
2212 | |||
2213 |
|
2213 | |||
2214 |
|
2214 | |||
2215 | def fillBuffer(self, data, datatime): |
|
2215 | def fillBuffer(self, data, datatime): | |
2216 |
|
2216 | |||
2217 | if self.__profIndex == 0: |
|
2217 | if self.__profIndex == 0: | |
2218 | self.__buffer_data = data.copy() |
|
2218 | self.__buffer_data = data.copy() | |
2219 |
|
2219 | |||
2220 | else: |
|
2220 | else: | |
2221 | self.__buffer_data = numpy.concatenate((self.__buffer_data,data), axis=1)#en perfiles |
|
2221 | self.__buffer_data = numpy.concatenate((self.__buffer_data,data), axis=1)#en perfiles | |
2222 | self.__profIndex += 1 |
|
2222 | self.__profIndex += 1 | |
2223 | self.__buffer_times.append(datatime) |
|
2223 | self.__buffer_times.append(datatime) | |
2224 |
|
2224 | |||
2225 | def getData(self, data, datatime=None): |
|
2225 | def getData(self, data, datatime=None): | |
2226 |
|
2226 | |||
2227 | if self.__profIndex == 0: |
|
2227 | if self.__profIndex == 0: | |
2228 | self.__initime = datatime |
|
2228 | self.__initime = datatime | |
2229 |
|
2229 | |||
2230 |
|
2230 | |||
2231 | self.__dataReady = False |
|
2231 | self.__dataReady = False | |
2232 |
|
2232 | |||
2233 | self.fillBuffer(data, datatime) |
|
2233 | self.fillBuffer(data, datatime) | |
2234 | dataBlock = None |
|
2234 | dataBlock = None | |
2235 |
|
2235 | |||
2236 | if self.__profIndex == self.n: |
|
2236 | if self.__profIndex == self.n: | |
2237 | #print("apnd : ",data) |
|
2237 | #print("apnd : ",data) | |
2238 | dataBlock = self.filterSatsProfiles() |
|
2238 | dataBlock = self.filterSatsProfiles() | |
2239 | self.__dataReady = True |
|
2239 | self.__dataReady = True | |
2240 |
|
2240 | |||
2241 | return dataBlock |
|
2241 | return dataBlock | |
2242 |
|
2242 | |||
2243 | if dataBlock is None: |
|
2243 | if dataBlock is None: | |
2244 | return None, None |
|
2244 | return None, None | |
2245 |
|
2245 | |||
2246 |
|
2246 | |||
2247 |
|
2247 | |||
2248 | return dataBlock |
|
2248 | return dataBlock | |
2249 |
|
2249 | |||
2250 | def releaseBlock(self): |
|
2250 | def releaseBlock(self): | |
2251 |
|
2251 | |||
2252 | if self.n % self.lenProfileOut != 0: |
|
2252 | if self.n % self.lenProfileOut != 0: | |
2253 | raise ValueError("lenProfileOut %d must be submultiple of nProfiles %d" %(self.lenProfileOut, self.n)) |
|
2253 | raise ValueError("lenProfileOut %d must be submultiple of nProfiles %d" %(self.lenProfileOut, self.n)) | |
2254 | return None |
|
2254 | return None | |
2255 |
|
2255 | |||
2256 | data = self.buffer[:,self.init_prof:self.end_prof:,:] #ch, prof, alt |
|
2256 | data = self.buffer[:,self.init_prof:self.end_prof:,:] #ch, prof, alt | |
2257 |
|
2257 | |||
2258 | self.init_prof = self.end_prof |
|
2258 | self.init_prof = self.end_prof | |
2259 | self.end_prof += self.lenProfileOut |
|
2259 | self.end_prof += self.lenProfileOut | |
2260 | #print("data release shape: ",dataOut.data.shape, self.end_prof) |
|
2260 | #print("data release shape: ",dataOut.data.shape, self.end_prof) | |
2261 | self.n_prof_released += 1 |
|
2261 | self.n_prof_released += 1 | |
2262 |
|
2262 | |||
2263 | return data |
|
2263 | return data | |
2264 |
|
2264 | |||
2265 | def run(self, dataOut, n=None, navg=0.8, nProfilesOut=1, profile_margin=50, |
|
2265 | def run(self, dataOut, n=None, navg=0.8, nProfilesOut=1, profile_margin=50, | |
2266 | th_hist_outlier=15,minHei=None, maxHei=None, minRef=None, maxRef=None, thdB=10): |
|
2266 | th_hist_outlier=15,minHei=None, maxHei=None, minRef=None, maxRef=None, thdB=10): | |
2267 |
|
2267 | |||
2268 | if not self.isConfig: |
|
2268 | if not self.isConfig: | |
2269 | #print("init p idx: ", dataOut.profileIndex ) |
|
2269 | #print("init p idx: ", dataOut.profileIndex ) | |
2270 | self.setup(dataOut,n=n, navg=navg,profileMargin=profile_margin,thHistOutlier=th_hist_outlier, |
|
2270 | self.setup(dataOut,n=n, navg=navg,profileMargin=profile_margin,thHistOutlier=th_hist_outlier, | |
2271 | minHei=minHei, maxHei=maxHei, minRef=minRef, maxRef=maxRef, thdB=thdB) |
|
2271 | minHei=minHei, maxHei=maxHei, minRef=minRef, maxRef=maxRef, thdB=thdB) | |
2272 | self.isConfig = True |
|
2272 | self.isConfig = True | |
2273 |
|
2273 | |||
2274 | dataBlock = None |
|
2274 | dataBlock = None | |
2275 |
|
2275 | |||
2276 | if not dataOut.buffer_empty: #hay datos acumulados |
|
2276 | if not dataOut.buffer_empty: #hay datos acumulados | |
2277 |
|
2277 | |||
2278 | if self.init_prof == 0: |
|
2278 | if self.init_prof == 0: | |
2279 | self.n_prof_released = 0 |
|
2279 | self.n_prof_released = 0 | |
2280 | self.lenProfileOut = nProfilesOut |
|
2280 | self.lenProfileOut = nProfilesOut | |
2281 | dataOut.flagNoData = False |
|
2281 | dataOut.flagNoData = False | |
2282 | #print("tp 2 ",dataOut.data.shape) |
|
2282 | #print("tp 2 ",dataOut.data.shape) | |
2283 |
|
2283 | |||
2284 | self.init_prof = 0 |
|
2284 | self.init_prof = 0 | |
2285 | self.end_prof = self.lenProfileOut |
|
2285 | self.end_prof = self.lenProfileOut | |
2286 |
|
2286 | |||
2287 | dataOut.nProfiles = self.lenProfileOut |
|
2287 | dataOut.nProfiles = self.lenProfileOut | |
2288 | if nProfilesOut == 1: |
|
2288 | if nProfilesOut == 1: | |
2289 | dataOut.flagDataAsBlock = False |
|
2289 | dataOut.flagDataAsBlock = False | |
2290 | else: |
|
2290 | else: | |
2291 | dataOut.flagDataAsBlock = True |
|
2291 | dataOut.flagDataAsBlock = True | |
2292 | #print("prof: ",self.init_prof) |
|
2292 | #print("prof: ",self.init_prof) | |
2293 | dataOut.flagNoData = False |
|
2293 | dataOut.flagNoData = False | |
2294 | if numpy.isin(self.n_prof_released, self.outliers_IDs_list): |
|
2294 | if numpy.isin(self.n_prof_released, self.outliers_IDs_list): | |
2295 | #print("omitting: ", self.n_prof_released) |
|
2295 | #print("omitting: ", self.n_prof_released) | |
2296 | dataOut.flagNoData = True |
|
2296 | dataOut.flagNoData = True | |
2297 | dataOut.ippSeconds = self._ipp |
|
2297 | dataOut.ippSeconds = self._ipp | |
2298 | dataOut.utctime = self.first_utcBlock + self.init_prof*self._ipp |
|
2298 | dataOut.utctime = self.first_utcBlock + self.init_prof*self._ipp | |
2299 | # print("time: ", dataOut.utctime, self.first_utcBlock, self.init_prof,self._ipp,dataOut.ippSeconds) |
|
2299 | # print("time: ", dataOut.utctime, self.first_utcBlock, self.init_prof,self._ipp,dataOut.ippSeconds) | |
2300 | #dataOut.data = self.releaseBlock() |
|
2300 | #dataOut.data = self.releaseBlock() | |
2301 | #########################################################3 |
|
2301 | #########################################################3 | |
2302 | if self.n % self.lenProfileOut != 0: |
|
2302 | if self.n % self.lenProfileOut != 0: | |
2303 | raise ValueError("lenProfileOut %d must be submultiple of nProfiles %d" %(self.lenProfileOut, self.n)) |
|
2303 | raise ValueError("lenProfileOut %d must be submultiple of nProfiles %d" %(self.lenProfileOut, self.n)) | |
2304 | return None |
|
2304 | return None | |
2305 |
|
2305 | |||
2306 | dataOut.data = None |
|
2306 | dataOut.data = None | |
2307 |
|
2307 | |||
2308 | if nProfilesOut == 1: |
|
2308 | if nProfilesOut == 1: | |
2309 | dataOut.data = self.buffer[:,self.end_prof-1,:] #ch, prof, alt |
|
2309 | dataOut.data = self.buffer[:,self.end_prof-1,:] #ch, prof, alt | |
2310 | else: |
|
2310 | else: | |
2311 | dataOut.data = self.buffer[:,self.init_prof:self.end_prof,:] #ch, prof, alt |
|
2311 | dataOut.data = self.buffer[:,self.init_prof:self.end_prof,:] #ch, prof, alt | |
2312 |
|
2312 | |||
2313 | self.init_prof = self.end_prof |
|
2313 | self.init_prof = self.end_prof | |
2314 | self.end_prof += self.lenProfileOut |
|
2314 | self.end_prof += self.lenProfileOut | |
2315 | #print("data release shape: ",dataOut.data.shape, self.end_prof, dataOut.flagNoData) |
|
2315 | #print("data release shape: ",dataOut.data.shape, self.end_prof, dataOut.flagNoData) | |
2316 | self.n_prof_released += 1 |
|
2316 | self.n_prof_released += 1 | |
2317 |
|
2317 | |||
2318 | if self.end_prof >= (self.n +self.lenProfileOut): |
|
2318 | if self.end_prof >= (self.n +self.lenProfileOut): | |
2319 |
|
2319 | |||
2320 | self.init_prof = 0 |
|
2320 | self.init_prof = 0 | |
2321 | self.__profIndex = 0 |
|
2321 | self.__profIndex = 0 | |
2322 | self.buffer = None |
|
2322 | self.buffer = None | |
2323 | dataOut.buffer_empty = True |
|
2323 | dataOut.buffer_empty = True | |
2324 | self.outliers_IDs_list = [] |
|
2324 | self.outliers_IDs_list = [] | |
2325 | self.n_prof_released = 0 |
|
2325 | self.n_prof_released = 0 | |
2326 | dataOut.flagNoData = False #enviar ultimo aunque sea outlier :( |
|
2326 | dataOut.flagNoData = False #enviar ultimo aunque sea outlier :( | |
2327 | #print("cleaning...", dataOut.buffer_empty) |
|
2327 | #print("cleaning...", dataOut.buffer_empty) | |
2328 | dataOut.profileIndex = 0 #self.lenProfileOut |
|
2328 | dataOut.profileIndex = 0 #self.lenProfileOut | |
2329 | #################################################################### |
|
2329 | #################################################################### | |
2330 | return dataOut |
|
2330 | return dataOut | |
2331 |
|
2331 | |||
2332 |
|
2332 | |||
2333 | #print("tp 223 ",dataOut.data.shape) |
|
2333 | #print("tp 223 ",dataOut.data.shape) | |
2334 | dataOut.flagNoData = True |
|
2334 | dataOut.flagNoData = True | |
2335 |
|
2335 | |||
2336 |
|
2336 | |||
2337 |
|
2337 | |||
2338 | try: |
|
2338 | try: | |
2339 | #dataBlock = self.getData(dataOut.data.reshape(self.nChannels,1,self.nHeights), dataOut.utctime) |
|
2339 | #dataBlock = self.getData(dataOut.data.reshape(self.nChannels,1,self.nHeights), dataOut.utctime) | |
2340 | dataBlock = self.getData(numpy.reshape(dataOut.data,(self.nChannels,1,self.nHeights)), dataOut.utctime) |
|
2340 | dataBlock = self.getData(numpy.reshape(dataOut.data,(self.nChannels,1,self.nHeights)), dataOut.utctime) | |
2341 | self.__count_exec +=1 |
|
2341 | self.__count_exec +=1 | |
2342 | except Exception as e: |
|
2342 | except Exception as e: | |
2343 | print("Error getting profiles data",self.__count_exec ) |
|
2343 | print("Error getting profiles data",self.__count_exec ) | |
2344 | print(e) |
|
2344 | print(e) | |
2345 | sys.exit() |
|
2345 | sys.exit() | |
2346 |
|
2346 | |||
2347 | if self.__dataReady: |
|
2347 | if self.__dataReady: | |
2348 | #print("omitting: ", len(self.outliers_IDs_list)) |
|
2348 | #print("omitting: ", len(self.outliers_IDs_list)) | |
2349 | self.__count_exec = 0 |
|
2349 | self.__count_exec = 0 | |
2350 | #dataOut.data = |
|
2350 | #dataOut.data = | |
2351 | #self.buffer = numpy.flip(dataBlock, axis=1) |
|
2351 | #self.buffer = numpy.flip(dataBlock, axis=1) | |
2352 | self.buffer = dataBlock |
|
2352 | self.buffer = dataBlock | |
2353 | self.first_utcBlock = self.__initime |
|
2353 | self.first_utcBlock = self.__initime | |
2354 | dataOut.utctime = self.__initime |
|
2354 | dataOut.utctime = self.__initime | |
2355 | dataOut.nProfiles = self.__profIndex |
|
2355 | dataOut.nProfiles = self.__profIndex | |
2356 | #dataOut.flagNoData = False |
|
2356 | #dataOut.flagNoData = False | |
2357 | self.init_prof = 0 |
|
2357 | self.init_prof = 0 | |
2358 | self.__profIndex = 0 |
|
2358 | self.__profIndex = 0 | |
2359 | self.__initime = None |
|
2359 | self.__initime = None | |
2360 | dataBlock = None |
|
2360 | dataBlock = None | |
2361 | self.__buffer_times = [] |
|
2361 | self.__buffer_times = [] | |
2362 | dataOut.error = False |
|
2362 | dataOut.error = False | |
2363 | dataOut.useInputBuffer = True |
|
2363 | dataOut.useInputBuffer = True | |
2364 | dataOut.buffer_empty = False |
|
2364 | dataOut.buffer_empty = False | |
2365 | #print("1 ch: {} prof: {} hs: {}".format(int(dataOut.nChannels),int(dataOut.nProfiles),int(dataOut.nHeights))) |
|
2365 | #print("1 ch: {} prof: {} hs: {}".format(int(dataOut.nChannels),int(dataOut.nProfiles),int(dataOut.nHeights))) | |
2366 |
|
2366 | |||
2367 |
|
2367 | |||
2368 |
|
2368 | |||
2369 | #print(self.__count_exec) |
|
2369 | #print(self.__count_exec) | |
2370 |
|
2370 | |||
2371 | return dataOut |
|
2371 | return dataOut | |
2372 |
|
2372 | |||
2373 |
|
2373 | |||
2374 | class RemoveProfileSats2(Operation): |
|
2374 | class RemoveProfileSats2(Operation): | |
2375 | ''' |
|
2375 | ''' | |
2376 | Escrito: Joab Apaza |
|
2376 | Escrito: Joab Apaza | |
2377 |
|
2377 | |||
2378 | Omite los perfiles contaminados con seΓ±al de satΓ©lites, usando una altura de referencia |
|
2378 | Omite los perfiles contaminados con seΓ±al de satΓ©lites, usando una altura de referencia | |
2379 | promedia todas las alturas para los cΓ‘lculos |
|
2379 | promedia todas las alturas para los cΓ‘lculos | |
2380 | In: |
|
2380 | In: | |
2381 | n = Cantidad de perfiles que se acumularan, usualmente 10 segundos |
|
2381 | n = Cantidad de perfiles que se acumularan, usualmente 10 segundos | |
2382 | navg = Porcentaje de perfiles que puede considerarse como satΓ©lite, mΓ‘ximo 90% |
|
2382 | navg = Porcentaje de perfiles que puede considerarse como satΓ©lite, mΓ‘ximo 90% | |
2383 | minHei = |
|
2383 | minHei = | |
2384 | minRef = |
|
2384 | minRef = | |
2385 | maxRef = |
|
2385 | maxRef = | |
2386 | nBins = |
|
2386 | nBins = | |
2387 | profile_margin = |
|
2387 | profile_margin = | |
2388 | th_hist_outlier = |
|
2388 | th_hist_outlier = | |
2389 | nProfilesOut = |
|
2389 | nProfilesOut = | |
2390 |
|
2390 | |||
2391 | Pensado para remover interferencias de las YAGI, se puede adaptar a otras interferencias |
|
2391 | Pensado para remover interferencias de las YAGI, se puede adaptar a otras interferencias | |
2392 |
|
2392 | |||
2393 | remYagi = Activa la funcion de remociΓ³n de interferencias de la YAGI |
|
2393 | remYagi = Activa la funcion de remociΓ³n de interferencias de la YAGI | |
2394 | nProfYagi = Cantidad de perfiles que son afectados, acorde NTX de la YAGI |
|
2394 | nProfYagi = Cantidad de perfiles que son afectados, acorde NTX de la YAGI | |
2395 | offYagi = |
|
2395 | offYagi = | |
2396 | minHJULIA = Altura mΓnima donde aparece la seΓ±al referencia de JULIA (-50) |
|
2396 | minHJULIA = Altura mΓnima donde aparece la seΓ±al referencia de JULIA (-50) | |
2397 | maxHJULIA = Altura mΓ‘xima donde aparece la seΓ±al referencia de JULIA (-15) |
|
2397 | maxHJULIA = Altura mΓ‘xima donde aparece la seΓ±al referencia de JULIA (-15) | |
2398 |
|
2398 | |||
2399 | debug = Activa los grΓ‘ficos, recomendable ejecutar para ajustar los parΓ‘metros |
|
2399 | debug = Activa los grΓ‘ficos, recomendable ejecutar para ajustar los parΓ‘metros | |
2400 | para un experimento en especΓfico. |
|
2400 | para un experimento en especΓfico. | |
2401 |
|
2401 | |||
2402 | ** se modifica para remover interferencias puntuales, es decir, desde otros radares. |
|
2402 | ** se modifica para remover interferencias puntuales, es decir, desde otros radares. | |
2403 | Inicialmente se ha configurado para omitir tambiΓ©n los perfiles de la YAGI en los datos |
|
2403 | Inicialmente se ha configurado para omitir tambiΓ©n los perfiles de la YAGI en los datos | |
2404 | de AMISR-ISR. |
|
2404 | de AMISR-ISR. | |
2405 |
|
2405 | |||
2406 | Out: |
|
2406 | Out: | |
2407 | profile clean |
|
2407 | profile clean | |
2408 | ''' |
|
2408 | ''' | |
2409 |
|
2409 | |||
2410 |
|
2410 | |||
2411 | __buffer_data = [] |
|
2411 | __buffer_data = [] | |
2412 | __buffer_times = [] |
|
2412 | __buffer_times = [] | |
2413 |
|
2413 | |||
2414 | buffer = None |
|
2414 | buffer = None | |
2415 |
|
2415 | |||
2416 | outliers_IDs_list = [] |
|
2416 | outliers_IDs_list = [] | |
2417 |
|
2417 | |||
2418 |
|
2418 | |||
2419 | __slots__ = ('n','navg','profileMargin','thHistOutlier','minHei_idx','maxHei_idx','nHeights', |
|
2419 | __slots__ = ('n','navg','profileMargin','thHistOutlier','minHei_idx','maxHei_idx','nHeights', | |
2420 | 'first_utcBlock','__profIndex','init_prof','end_prof','lenProfileOut','nChannels','cohFactor', |
|
2420 | 'first_utcBlock','__profIndex','init_prof','end_prof','lenProfileOut','nChannels','cohFactor', | |
2421 | '__count_exec','__initime','__dataReady','__ipp', 'minRef', 'maxRef', 'debug','prev_pnoise','thfactor') |
|
2421 | '__count_exec','__initime','__dataReady','__ipp', 'minRef', 'maxRef', 'debug','prev_pnoise','thfactor') | |
2422 | def __init__(self, **kwargs): |
|
2422 | def __init__(self, **kwargs): | |
2423 |
|
2423 | |||
2424 | Operation.__init__(self, **kwargs) |
|
2424 | Operation.__init__(self, **kwargs) | |
2425 | self.isConfig = False |
|
2425 | self.isConfig = False | |
2426 | self.currentTime = None |
|
2426 | self.currentTime = None | |
2427 |
|
2427 | |||
2428 | def setup(self,dataOut, n=None , navg=0.9, profileMargin=50,thHistOutlier=15,minHei=None, maxHei=None, nBins=10, |
|
2428 | def setup(self,dataOut, n=None , navg=0.9, profileMargin=50,thHistOutlier=15,minHei=None, maxHei=None, nBins=10, | |
2429 | minRef=None, maxRef=None, debug=False, remYagi=False, nProfYagi = 0, offYagi=0, minHJULIA=None, maxHJULIA=None, |
|
2429 | minRef=None, maxRef=None, debug=False, remYagi=False, nProfYagi = 0, offYagi=0, minHJULIA=None, maxHJULIA=None, | |
2430 | idate=None,startH=None,endH=None, thfactor=1 ): |
|
2430 | idate=None,startH=None,endH=None, thfactor=1 ): | |
2431 |
|
2431 | |||
2432 | if n == None and timeInterval == None: |
|
2432 | if n == None and timeInterval == None: | |
2433 | raise ValueError("nprofiles or timeInterval should be specified ...") |
|
2433 | raise ValueError("nprofiles or timeInterval should be specified ...") | |
2434 |
|
2434 | |||
2435 | if n != None: |
|
2435 | if n != None: | |
2436 | self.n = n |
|
2436 | self.n = n | |
2437 |
|
2437 | |||
2438 | self.navg = navg |
|
2438 | self.navg = navg | |
2439 | self.profileMargin = profileMargin |
|
2439 | self.profileMargin = profileMargin | |
2440 | self.thHistOutlier = thHistOutlier |
|
2440 | self.thHistOutlier = thHistOutlier | |
2441 | self.__profIndex = 0 |
|
2441 | self.__profIndex = 0 | |
2442 | self.buffer = None |
|
2442 | self.buffer = None | |
2443 | self._ipp = dataOut.ippSeconds |
|
2443 | self._ipp = dataOut.ippSeconds | |
2444 | self.n_prof_released = 0 |
|
2444 | self.n_prof_released = 0 | |
2445 | self.heightList = dataOut.heightList |
|
2445 | self.heightList = dataOut.heightList | |
2446 | self.init_prof = 0 |
|
2446 | self.init_prof = 0 | |
2447 | self.end_prof = 0 |
|
2447 | self.end_prof = 0 | |
2448 | self.__count_exec = 0 |
|
2448 | self.__count_exec = 0 | |
2449 | self.__profIndex = 0 |
|
2449 | self.__profIndex = 0 | |
2450 | self.first_utcBlock = None |
|
2450 | self.first_utcBlock = None | |
2451 | self.prev_pnoise = None |
|
2451 | self.prev_pnoise = None | |
2452 | self.nBins = nBins |
|
2452 | self.nBins = nBins | |
2453 | self.thfactor = thfactor |
|
2453 | self.thfactor = thfactor | |
2454 | #self.__dh = dataOut.heightList[1] - dataOut.heightList[0] |
|
2454 | #self.__dh = dataOut.heightList[1] - dataOut.heightList[0] | |
2455 | minHei = minHei |
|
2455 | minHei = minHei | |
2456 | maxHei = maxHei |
|
2456 | maxHei = maxHei | |
2457 | if minHei==None : |
|
2457 | if minHei==None : | |
2458 | minHei = dataOut.heightList[0] |
|
2458 | minHei = dataOut.heightList[0] | |
2459 | if maxHei==None : |
|
2459 | if maxHei==None : | |
2460 | maxHei = dataOut.heightList[-1] |
|
2460 | maxHei = dataOut.heightList[-1] | |
2461 | self.minHei_idx,self.maxHei_idx = getHei_index(minHei, maxHei, dataOut.heightList) |
|
2461 | self.minHei_idx,self.maxHei_idx = getHei_index(minHei, maxHei, dataOut.heightList) | |
2462 | self.min_ref, self.max_ref = getHei_index(minRef, maxRef, dataOut.heightList) |
|
2462 | self.min_ref, self.max_ref = getHei_index(minRef, maxRef, dataOut.heightList) | |
2463 | self.nChannels = dataOut.nChannels |
|
2463 | self.nChannels = dataOut.nChannels | |
2464 | self.nHeights = dataOut.nHeights |
|
2464 | self.nHeights = dataOut.nHeights | |
2465 | self.test_counter = 0 |
|
2465 | self.test_counter = 0 | |
2466 | self.debug = debug |
|
2466 | self.debug = debug | |
2467 | self.remYagi = remYagi |
|
2467 | self.remYagi = remYagi | |
2468 | self.cohFactor = dataOut.nCohInt |
|
2468 | self.cohFactor = dataOut.nCohInt | |
2469 | if self.remYagi : |
|
2469 | if self.remYagi : | |
2470 | if minHJULIA==None or maxHJULIA==None: |
|
2470 | if minHJULIA==None or maxHJULIA==None: | |
2471 | raise ValueError("Parameters minHYagi and minHYagi are necessary!") |
|
2471 | raise ValueError("Parameters minHYagi and minHYagi are necessary!") | |
2472 | return |
|
2472 | return | |
2473 | if idate==None or startH==None or endH==None: |
|
2473 | if idate==None or startH==None or endH==None: | |
2474 | raise ValueError("Date and hour parameters are necessary!") |
|
2474 | raise ValueError("Date and hour parameters are necessary!") | |
2475 | return |
|
2475 | return | |
2476 | self.minHJULIA_idx,self.maxHJULIA_idx = getHei_index(minHJULIA, maxHJULIA, dataOut.heightList) |
|
2476 | self.minHJULIA_idx,self.maxHJULIA_idx = getHei_index(minHJULIA, maxHJULIA, dataOut.heightList) | |
2477 | self.offYagi = offYagi |
|
2477 | self.offYagi = offYagi | |
2478 | self.nTxYagi = nProfYagi |
|
2478 | self.nTxYagi = nProfYagi | |
2479 |
|
2479 | |||
2480 | self.startTime = datetime.datetime.combine(idate,startH) |
|
2480 | self.startTime = datetime.datetime.combine(idate,startH) | |
2481 | self.endTime = datetime.datetime.combine(idate,endH) |
|
2481 | self.endTime = datetime.datetime.combine(idate,endH) | |
2482 |
|
2482 | |||
2483 | log.warning("Be careful with the selection of parameters for sats removal! It is avisable to \ |
|
2483 | log.warning("Be careful with the selection of parameters for sats removal! It is avisable to \ | |
2484 | activate the debug parameter in this operation for calibration", self.name) |
|
2484 | activate the debug parameter in this operation for calibration", self.name) | |
2485 |
|
2485 | |||
2486 |
|
2486 | |||
2487 | def filterSatsProfiles(self): |
|
2487 | def filterSatsProfiles(self): | |
2488 |
|
2488 | |||
2489 | data = self.__buffer_data.copy() |
|
2489 | data = self.__buffer_data.copy() | |
2490 | #print(data.shape) |
|
2490 | #print(data.shape) | |
2491 | nChannels, profiles, heights = data.shape |
|
2491 | nChannels, profiles, heights = data.shape | |
2492 | indexes=numpy.zeros([], dtype=int) |
|
2492 | indexes=numpy.zeros([], dtype=int) | |
2493 | indexes = numpy.delete(indexes,0) |
|
2493 | indexes = numpy.delete(indexes,0) | |
2494 |
|
2494 | |||
2495 | indexesYagi=numpy.zeros([], dtype=int) |
|
2495 | indexesYagi=numpy.zeros([], dtype=int) | |
2496 | indexesYagi = numpy.delete(indexesYagi,0) |
|
2496 | indexesYagi = numpy.delete(indexesYagi,0) | |
2497 |
|
2497 | |||
2498 | indexesYagi_up=numpy.zeros([], dtype=int) |
|
2498 | indexesYagi_up=numpy.zeros([], dtype=int) | |
2499 | indexesYagi_up = numpy.delete(indexesYagi_up,0) |
|
2499 | indexesYagi_up = numpy.delete(indexesYagi_up,0) | |
2500 | indexesYagi_down=numpy.zeros([], dtype=int) |
|
2500 | indexesYagi_down=numpy.zeros([], dtype=int) | |
2501 | indexesYagi_down = numpy.delete(indexesYagi_down,0) |
|
2501 | indexesYagi_down = numpy.delete(indexesYagi_down,0) | |
2502 |
|
2502 | |||
2503 |
|
2503 | |||
2504 | indexesJULIA=numpy.zeros([], dtype=int) |
|
2504 | indexesJULIA=numpy.zeros([], dtype=int) | |
2505 | indexesJULIA = numpy.delete(indexesJULIA,0) |
|
2505 | indexesJULIA = numpy.delete(indexesJULIA,0) | |
2506 |
|
2506 | |||
2507 | outliers_IDs=[] |
|
2507 | outliers_IDs=[] | |
2508 |
|
2508 | |||
2509 | div = profiles//self.nBins |
|
2509 | div = profiles//self.nBins | |
2510 |
|
2510 | |||
2511 | for c in range(nChannels): |
|
2511 | for c in range(nChannels): | |
2512 | #print(self.min_ref,self.max_ref) |
|
2512 | #print(self.min_ref,self.max_ref) | |
2513 |
|
2513 | |||
2514 | import scipy.signal |
|
2514 | import scipy.signal | |
2515 | b, a = scipy.signal.butter(3, 0.5) |
|
2515 | b, a = scipy.signal.butter(3, 0.5) | |
2516 | #noise_ref = (data[c,:,self.min_ref:self.max_ref] * numpy.conjugate(data[c,:,self.min_ref:self.max_ref])) |
|
2516 | #noise_ref = (data[c,:,self.min_ref:self.max_ref] * numpy.conjugate(data[c,:,self.min_ref:self.max_ref])) | |
2517 | noise_ref = numpy.abs(data[c,:,self.min_ref:self.max_ref]) |
|
2517 | noise_ref = numpy.abs(data[c,:,self.min_ref:self.max_ref]) | |
2518 | lnoise = len(noise_ref[0,:]) |
|
2518 | lnoise = len(noise_ref[0,:]) | |
2519 | #print(noise_ref.shape) |
|
2519 | #print(noise_ref.shape) | |
2520 | noise_ref = noise_ref.mean(axis=1) |
|
2520 | noise_ref = noise_ref.mean(axis=1) | |
2521 | #fnoise = noise_ref |
|
2521 | #fnoise = noise_ref | |
2522 | fnoise = scipy.signal.filtfilt(b, a, noise_ref) |
|
2522 | fnoise = scipy.signal.filtfilt(b, a, noise_ref) | |
2523 | #noise_refdB = 10* numpy.log10(noise_ref) |
|
2523 | #noise_refdB = 10* numpy.log10(noise_ref) | |
2524 | #print("Noise ",numpy.percentile(noise_ref,95)) |
|
2524 | #print("Noise ",numpy.percentile(noise_ref,95)) | |
2525 | p95 = numpy.percentile(fnoise,95) |
|
2525 | p95 = numpy.percentile(fnoise,95) | |
2526 | mean_noise = fnoise.mean() |
|
2526 | mean_noise = fnoise.mean() | |
2527 |
|
2527 | |||
2528 | if self.prev_pnoise != None: |
|
2528 | if self.prev_pnoise != None: | |
2529 | if mean_noise < (1.1 * self.prev_pnoise) and mean_noise > (0.9 * self.prev_pnoise): |
|
2529 | if mean_noise < (1.1 * self.prev_pnoise) and mean_noise > (0.9 * self.prev_pnoise): | |
2530 | mean_noise = 0.9*mean_noise + 0.1*self.prev_pnoise |
|
2530 | mean_noise = 0.9*mean_noise + 0.1*self.prev_pnoise | |
2531 | self.prev_pnoise = mean_noise |
|
2531 | self.prev_pnoise = mean_noise | |
2532 | else: |
|
2532 | else: | |
2533 | mean_noise = self.prev_pnoise |
|
2533 | mean_noise = self.prev_pnoise | |
2534 | else: |
|
2534 | else: | |
2535 | self.prev_pnoise = mean_noise |
|
2535 | self.prev_pnoise = mean_noise | |
2536 |
|
2536 | |||
2537 | std = fnoise.std()+ fnoise.mean() |
|
2537 | std = fnoise.std()+ fnoise.mean() | |
2538 |
|
2538 | |||
2539 |
|
2539 | |||
2540 |
|
2540 | |||
2541 | #power = (data[c,:,self.minHei_idx:self.maxHei_idx] * numpy.conjugate(data[c,:,self.minHei_idx:self.maxHei_idx])) |
|
2541 | #power = (data[c,:,self.minHei_idx:self.maxHei_idx] * numpy.conjugate(data[c,:,self.minHei_idx:self.maxHei_idx])) | |
2542 | power = numpy.abs(data[c,:,self.minHei_idx:self.maxHei_idx]) |
|
2542 | power = numpy.abs(data[c,:,self.minHei_idx:self.maxHei_idx]) | |
2543 | npower = len(power[0,:]) |
|
2543 | npower = len(power[0,:]) | |
2544 | #print(power.shape) |
|
2544 | #print(power.shape) | |
2545 | power = power.mean(axis=1) |
|
2545 | power = power.mean(axis=1) | |
2546 |
|
2546 | |||
2547 | fpower = scipy.signal.filtfilt(b, a, power) |
|
2547 | fpower = scipy.signal.filtfilt(b, a, power) | |
2548 | #print(power.shape) |
|
2548 | #print(power.shape) | |
2549 | #powerdB = 10* numpy.log10(power) |
|
2549 | #powerdB = 10* numpy.log10(power) | |
2550 |
|
2550 | |||
2551 | #th = p95 * self.thfactor |
|
2551 | #th = p95 * self.thfactor | |
2552 | th = mean_noise * self.thfactor |
|
2552 | th = mean_noise * self.thfactor | |
2553 |
|
2553 | |||
2554 | index = numpy.where(fpower > th ) |
|
2554 | index = numpy.where(fpower > th ) | |
2555 | #print("Noise ",mean_noise, p95) |
|
2555 | #print("Noise ",mean_noise, p95) | |
2556 | #print(index) |
|
2556 | #print(index) | |
2557 |
|
2557 | |||
2558 |
|
2558 | |||
2559 |
|
2559 | |||
2560 | if index[0].size <= int(self.navg*profiles): #outliers from sats |
|
2560 | if index[0].size <= int(self.navg*profiles): #outliers from sats | |
2561 | indexes = numpy.append(indexes, index[0]) |
|
2561 | indexes = numpy.append(indexes, index[0]) | |
2562 |
|
2562 | |||
2563 | index2low = numpy.where(fpower < (th*0.5 )) #outliers from no TX |
|
2563 | index2low = numpy.where(fpower < (th*0.5 )) #outliers from no TX | |
2564 | if index2low[0].size <= int(self.navg*profiles): |
|
2564 | if index2low[0].size <= int(self.navg*profiles): | |
2565 | indexes = numpy.append(indexes, index2low[0]) |
|
2565 | indexes = numpy.append(indexes, index2low[0]) | |
2566 |
|
2566 | |||
2567 | #print("sdas ", noise_ref.mean()) |
|
2567 | #print("sdas ", noise_ref.mean()) | |
2568 |
|
2568 | |||
2569 | if self.remYagi : |
|
2569 | if self.remYagi : | |
2570 | #print(self.minHJULIA_idx, self.maxHJULIA_idx) |
|
2570 | #print(self.minHJULIA_idx, self.maxHJULIA_idx) | |
2571 | powerJULIA = (data[c,:,self.minHJULIA_idx:self.maxHJULIA_idx] * numpy.conjugate(data[c,:,self.minHJULIA_idx:self.maxHJULIA_idx])).real |
|
2571 | powerJULIA = (data[c,:,self.minHJULIA_idx:self.maxHJULIA_idx] * numpy.conjugate(data[c,:,self.minHJULIA_idx:self.maxHJULIA_idx])).real | |
2572 | powerJULIA = powerJULIA.mean(axis=1) |
|
2572 | powerJULIA = powerJULIA.mean(axis=1) | |
2573 | th_JULIA = powerJULIA.mean()*0.85 |
|
2573 | th_JULIA = powerJULIA.mean()*0.85 | |
2574 | indexJULIA = numpy.where(powerJULIA >= th_JULIA ) |
|
2574 | indexJULIA = numpy.where(powerJULIA >= th_JULIA ) | |
2575 |
|
2575 | |||
2576 | indexesJULIA= numpy.append(indexesJULIA, indexJULIA[0]) |
|
2576 | indexesJULIA= numpy.append(indexesJULIA, indexJULIA[0]) | |
2577 |
|
2577 | |||
2578 | # fig, ax = plt.subplots() |
|
2578 | # fig, ax = plt.subplots() | |
2579 | # ax.plot(powerJULIA) |
|
2579 | # ax.plot(powerJULIA) | |
2580 | # ax.axhline(th_JULIA, color='r') |
|
2580 | # ax.axhline(th_JULIA, color='r') | |
2581 | # plt.grid() |
|
2581 | # plt.grid() | |
2582 | # plt.show() |
|
2582 | # plt.show() | |
2583 |
|
2583 | |||
2584 | if self.debug: |
|
2584 | if self.debug: | |
2585 | fig, ax = plt.subplots() |
|
2585 | fig, ax = plt.subplots() | |
2586 | ax.plot(fpower, label="power") |
|
2586 | ax.plot(fpower, label="power") | |
2587 | #ax.plot(fnoise, label="noise ref") |
|
2587 | #ax.plot(fnoise, label="noise ref") | |
2588 | ax.axhline(th, color='g', label="th") |
|
2588 | ax.axhline(th, color='g', label="th") | |
2589 | #ax.axhline(std, color='b', label="mean") |
|
2589 | #ax.axhline(std, color='b', label="mean") | |
2590 | ax.legend() |
|
2590 | ax.legend() | |
2591 | plt.grid() |
|
2591 | plt.grid() | |
2592 | plt.show() |
|
2592 | plt.show() | |
2593 |
|
2593 | |||
2594 | #print(indexes) |
|
2594 | #print(indexes) | |
2595 |
|
2595 | |||
2596 | #outliers_IDs = outliers_IDs.astype(numpy.dtype('int64')) |
|
2596 | #outliers_IDs = outliers_IDs.astype(numpy.dtype('int64')) | |
2597 | #outliers_IDs = numpy.unique(outliers_IDs) |
|
2597 | #outliers_IDs = numpy.unique(outliers_IDs) | |
2598 | # print(indexesJULIA) |
|
2598 | # print(indexesJULIA) | |
2599 | if len(indexesJULIA > 1): |
|
2599 | if len(indexesJULIA > 1): | |
2600 | iJ = indexesJULIA |
|
2600 | iJ = indexesJULIA | |
2601 | locs = [ (iJ[n]-iJ[n-1]) > 5 for n in range(len(iJ))] |
|
2601 | locs = [ (iJ[n]-iJ[n-1]) > 5 for n in range(len(iJ))] | |
2602 | locs_2 = numpy.where(locs)[0] |
|
2602 | locs_2 = numpy.where(locs)[0] | |
2603 | #print(locs_2, indexesJULIA[locs_2-1]) |
|
2603 | #print(locs_2, indexesJULIA[locs_2-1]) | |
2604 | indexesYagi_up = numpy.append(indexesYagi_up, indexesJULIA[locs_2-1]) |
|
2604 | indexesYagi_up = numpy.append(indexesYagi_up, indexesJULIA[locs_2-1]) | |
2605 | indexesYagi_down = numpy.append(indexesYagi_down, indexesJULIA[locs_2]) |
|
2605 | indexesYagi_down = numpy.append(indexesYagi_down, indexesJULIA[locs_2]) | |
2606 |
|
2606 | |||
2607 |
|
2607 | |||
2608 | indexesYagi_up = numpy.append(indexesYagi_up,indexesJULIA[-1]) |
|
2608 | indexesYagi_up = numpy.append(indexesYagi_up,indexesJULIA[-1]) | |
2609 | indexesYagi_down = numpy.append(indexesYagi_down,indexesJULIA[0]) |
|
2609 | indexesYagi_down = numpy.append(indexesYagi_down,indexesJULIA[0]) | |
2610 |
|
2610 | |||
2611 | indexesYagi_up = numpy.unique(indexesYagi_up) |
|
2611 | indexesYagi_up = numpy.unique(indexesYagi_up) | |
2612 | indexesYagi_down = numpy.unique(indexesYagi_down) |
|
2612 | indexesYagi_down = numpy.unique(indexesYagi_down) | |
2613 |
|
2613 | |||
2614 |
|
2614 | |||
2615 | aux_ind = [ numpy.arange( (self.offYagi + k)+1, (self.offYagi + k + self.nTxYagi)+1, 1, dtype=int) for k in indexesYagi_up] |
|
2615 | aux_ind = [ numpy.arange( (self.offYagi + k)+1, (self.offYagi + k + self.nTxYagi)+1, 1, dtype=int) for k in indexesYagi_up] | |
2616 | indexesYagi_up = (numpy.asarray(aux_ind)).flatten() |
|
2616 | indexesYagi_up = (numpy.asarray(aux_ind)).flatten() | |
2617 |
|
2617 | |||
2618 | aux_ind2 = [ numpy.arange( (k - self.nTxYagi)+1, k+1 , 1, dtype=int) for k in indexesYagi_down] |
|
2618 | aux_ind2 = [ numpy.arange( (k - self.nTxYagi)+1, k+1 , 1, dtype=int) for k in indexesYagi_down] | |
2619 | indexesYagi_down = (numpy.asarray(aux_ind2)).flatten() |
|
2619 | indexesYagi_down = (numpy.asarray(aux_ind2)).flatten() | |
2620 |
|
2620 | |||
2621 | indexesYagi = numpy.append(indexesYagi,indexesYagi_up) |
|
2621 | indexesYagi = numpy.append(indexesYagi,indexesYagi_up) | |
2622 | indexesYagi = numpy.append(indexesYagi,indexesYagi_down) |
|
2622 | indexesYagi = numpy.append(indexesYagi,indexesYagi_down) | |
2623 |
|
2623 | |||
2624 |
|
2624 | |||
2625 | indexesYagi = indexesYagi[ (indexesYagi >= 0) & (indexesYagi<profiles)] |
|
2625 | indexesYagi = indexesYagi[ (indexesYagi >= 0) & (indexesYagi<profiles)] | |
2626 | indexesYagi = numpy.unique(indexesYagi) |
|
2626 | indexesYagi = numpy.unique(indexesYagi) | |
2627 |
|
2627 | |||
2628 | #print("indexes: " ,indexes) |
|
2628 | #print("indexes: " ,indexes) | |
2629 | outs_lines = numpy.unique(indexes) |
|
2629 | outs_lines = numpy.unique(indexes) | |
2630 | #print(outs_lines) |
|
2630 | #print(outs_lines) | |
2631 |
|
2631 | |||
2632 | #Agrupando el histograma de outliers, |
|
2632 | #Agrupando el histograma de outliers, | |
2633 | my_bins = numpy.linspace(0,int(profiles), div, endpoint=True) |
|
2633 | my_bins = numpy.linspace(0,int(profiles), div, endpoint=True) | |
2634 |
|
2634 | |||
2635 |
|
2635 | |||
2636 | hist, bins = numpy.histogram(outs_lines,bins=my_bins) |
|
2636 | hist, bins = numpy.histogram(outs_lines,bins=my_bins) | |
2637 | #print("hist: ",hist) |
|
2637 | #print("hist: ",hist) | |
2638 | hist_outliers_indexes = numpy.where(hist >= self.thHistOutlier)[0] #es outlier |
|
2638 | hist_outliers_indexes = numpy.where(hist >= self.thHistOutlier)[0] #es outlier | |
2639 | # print(hist_outliers_indexes) |
|
2639 | # print(hist_outliers_indexes) | |
2640 | if len(hist_outliers_indexes>0): |
|
2640 | if len(hist_outliers_indexes>0): | |
2641 | hist_outliers_indexes = numpy.append(hist_outliers_indexes,hist_outliers_indexes[-1]+1) |
|
2641 | hist_outliers_indexes = numpy.append(hist_outliers_indexes,hist_outliers_indexes[-1]+1) | |
2642 |
|
2642 | |||
2643 | bins_outliers_indexes = [int(i)+1 for i in (bins[hist_outliers_indexes])] # |
|
2643 | bins_outliers_indexes = [int(i)+1 for i in (bins[hist_outliers_indexes])] # | |
2644 | outlier_loc_index = [] |
|
2644 | outlier_loc_index = [] | |
2645 | #print("out indexes ", bins_outliers_indexes) |
|
2645 | #print("out indexes ", bins_outliers_indexes) | |
2646 |
|
2646 | |||
2647 | # if len(bins_outliers_indexes) <= 2: |
|
2647 | # if len(bins_outliers_indexes) <= 2: | |
2648 | # extprof = 0 |
|
2648 | # extprof = 0 | |
2649 | # else: |
|
2649 | # else: | |
2650 | # extprof = self.profileMargin |
|
2650 | # extprof = self.profileMargin | |
2651 |
|
2651 | |||
2652 | extprof = self.profileMargin |
|
2652 | extprof = self.profileMargin | |
2653 |
|
2653 | |||
2654 | outlier_loc_index = [e for n in range(len(bins_outliers_indexes)) for e in range(bins_outliers_indexes[n]-extprof,bins_outliers_indexes[n] + extprof) ] |
|
2654 | outlier_loc_index = [e for n in range(len(bins_outliers_indexes)) for e in range(bins_outliers_indexes[n]-extprof,bins_outliers_indexes[n] + extprof) ] | |
2655 | outlier_loc_index = numpy.asarray(outlier_loc_index) |
|
2655 | outlier_loc_index = numpy.asarray(outlier_loc_index) | |
2656 | # if len(outlier_loc_index)>1: |
|
2656 | # if len(outlier_loc_index)>1: | |
2657 | # ipmax = numpy.where(fpower==fpower.max())[0] |
|
2657 | # ipmax = numpy.where(fpower==fpower.max())[0] | |
2658 | # print("pmax: ",ipmax) |
|
2658 | # print("pmax: ",ipmax) | |
2659 |
|
2659 | |||
2660 |
|
2660 | |||
2661 |
|
2661 | |||
2662 |
|
2662 | |||
2663 | #print("outliers Ids: ", outlier_loc_index, outlier_loc_index.shape) |
|
2663 | #print("outliers Ids: ", outlier_loc_index, outlier_loc_index.shape) | |
2664 | outlier_loc_index = outlier_loc_index[ (outlier_loc_index >= 0) & (outlier_loc_index<profiles)] |
|
2664 | outlier_loc_index = outlier_loc_index[ (outlier_loc_index >= 0) & (outlier_loc_index<profiles)] | |
2665 | #print("outliers final: ", outlier_loc_index) |
|
2665 | #print("outliers final: ", outlier_loc_index) | |
2666 |
|
2666 | |||
2667 |
|
2667 | |||
2668 | if self.debug: |
|
2668 | if self.debug: | |
2669 | x, y = numpy.meshgrid(numpy.arange(profiles), self.heightList) |
|
2669 | x, y = numpy.meshgrid(numpy.arange(profiles), self.heightList) | |
2670 | fig, ax = plt.subplots(nChannels,2,figsize=(8, 6)) |
|
2670 | fig, ax = plt.subplots(nChannels,2,figsize=(8, 6)) | |
2671 |
|
2671 | |||
2672 | for i in range(nChannels): |
|
2672 | for i in range(nChannels): | |
2673 | dat = data[i,:,:].real |
|
2673 | dat = data[i,:,:].real | |
2674 | dat = 10* numpy.log10((data[i,:,:] * numpy.conjugate(data[i,:,:])).real) |
|
2674 | dat = 10* numpy.log10((data[i,:,:] * numpy.conjugate(data[i,:,:])).real) | |
2675 | m = numpy.nanmean(dat) |
|
2675 | m = numpy.nanmean(dat) | |
2676 | o = numpy.nanstd(dat) |
|
2676 | o = numpy.nanstd(dat) | |
2677 | if nChannels>1: |
|
2677 | if nChannels>1: | |
2678 | c = ax[i][0].pcolormesh(x, y, dat.T, cmap ='jet', vmin = 60, vmax = 70) |
|
2678 | c = ax[i][0].pcolormesh(x, y, dat.T, cmap ='jet', vmin = 60, vmax = 70) | |
2679 | ax[i][0].vlines(outs_lines,650,700, linestyles='dashed', label = 'outs', color='w') |
|
2679 | ax[i][0].vlines(outs_lines,650,700, linestyles='dashed', label = 'outs', color='w') | |
2680 | #fig.colorbar(c) |
|
2680 | #fig.colorbar(c) | |
2681 | ax[i][0].vlines(outlier_loc_index,700,750, linestyles='dashed', label = 'outs', color='r') |
|
2681 | ax[i][0].vlines(outlier_loc_index,700,750, linestyles='dashed', label = 'outs', color='r') | |
2682 | ax[i][1].hist(outs_lines,bins=my_bins) |
|
2682 | ax[i][1].hist(outs_lines,bins=my_bins) | |
2683 | if self.remYagi : |
|
2683 | if self.remYagi : | |
2684 | ax[0].vlines(indexesYagi,750,850, linestyles='dashed', label = 'yagi', color='m') |
|
2684 | ax[0].vlines(indexesYagi,750,850, linestyles='dashed', label = 'yagi', color='m') | |
2685 | else: |
|
2685 | else: | |
2686 | c = ax[0].pcolormesh(x, y, dat.T, cmap ='jet', vmin = 60, vmax = (70+2*self.cohFactor)) |
|
2686 | c = ax[0].pcolormesh(x, y, dat.T, cmap ='jet', vmin = 60, vmax = (70+2*self.cohFactor)) | |
2687 | ax[0].vlines(outs_lines,650,700, linestyles='dashed', label = 'outs', color='w') |
|
2687 | ax[0].vlines(outs_lines,650,700, linestyles='dashed', label = 'outs', color='w') | |
2688 | #fig.colorbar(c) |
|
2688 | #fig.colorbar(c) | |
2689 | ax[0].vlines(outlier_loc_index,700,750, linestyles='dashed', label = 'outs', color='r') |
|
2689 | ax[0].vlines(outlier_loc_index,700,750, linestyles='dashed', label = 'outs', color='r') | |
2690 |
|
2690 | |||
2691 | ax[1].hist(outs_lines,bins=my_bins) |
|
2691 | ax[1].hist(outs_lines,bins=my_bins) | |
2692 | if self.remYagi : |
|
2692 | if self.remYagi : | |
2693 | ax[0].vlines(indexesYagi,750,850, linestyles='dashed', label = 'yagi', color='m') |
|
2693 | ax[0].vlines(indexesYagi,750,850, linestyles='dashed', label = 'yagi', color='m') | |
2694 | plt.show() |
|
2694 | plt.show() | |
2695 |
|
2695 | |||
2696 |
|
2696 | |||
2697 |
|
2697 | |||
2698 |
|
2698 | |||
2699 | if self.remYagi and (self.currentTime < self.startTime and self.currentTime < self.endTime): |
|
2699 | if self.remYagi and (self.currentTime < self.startTime and self.currentTime < self.endTime): | |
2700 | outlier_loc_index = numpy.append(outlier_loc_index,indexesYagi) |
|
2700 | outlier_loc_index = numpy.append(outlier_loc_index,indexesYagi) | |
2701 |
|
2701 | |||
2702 | self.outliers_IDs_list = numpy.unique(outlier_loc_index) |
|
2702 | self.outliers_IDs_list = numpy.unique(outlier_loc_index) | |
2703 |
|
2703 | |||
2704 | #print("outs list: ", self.outliers_IDs_list) |
|
2704 | #print("outs list: ", self.outliers_IDs_list) | |
2705 | return self.__buffer_data |
|
2705 | return self.__buffer_data | |
2706 |
|
2706 | |||
2707 |
|
2707 | |||
2708 |
|
2708 | |||
2709 | def fillBuffer(self, data, datatime): |
|
2709 | def fillBuffer(self, data, datatime): | |
2710 |
|
2710 | |||
2711 | if self.__profIndex == 0: |
|
2711 | if self.__profIndex == 0: | |
2712 | self.__buffer_data = data.copy() |
|
2712 | self.__buffer_data = data.copy() | |
2713 |
|
2713 | |||
2714 | else: |
|
2714 | else: | |
2715 | self.__buffer_data = numpy.concatenate((self.__buffer_data,data), axis=1)#en perfiles |
|
2715 | self.__buffer_data = numpy.concatenate((self.__buffer_data,data), axis=1)#en perfiles | |
2716 | self.__profIndex += 1 |
|
2716 | self.__profIndex += 1 | |
2717 | self.__buffer_times.append(datatime) |
|
2717 | self.__buffer_times.append(datatime) | |
2718 |
|
2718 | |||
2719 | def getData(self, data, datatime=None): |
|
2719 | def getData(self, data, datatime=None): | |
2720 |
|
2720 | |||
2721 | if self.__profIndex == 0: |
|
2721 | if self.__profIndex == 0: | |
2722 | self.__initime = datatime |
|
2722 | self.__initime = datatime | |
2723 |
|
2723 | |||
2724 |
|
2724 | |||
2725 | self.__dataReady = False |
|
2725 | self.__dataReady = False | |
2726 |
|
2726 | |||
2727 | self.fillBuffer(data, datatime) |
|
2727 | self.fillBuffer(data, datatime) | |
2728 | dataBlock = None |
|
2728 | dataBlock = None | |
2729 |
|
2729 | |||
2730 | if self.__profIndex == self.n: |
|
2730 | if self.__profIndex == self.n: | |
2731 | #print("apnd : ",data) |
|
2731 | #print("apnd : ",data) | |
2732 | dataBlock = self.filterSatsProfiles() |
|
2732 | dataBlock = self.filterSatsProfiles() | |
2733 | self.__dataReady = True |
|
2733 | self.__dataReady = True | |
2734 |
|
2734 | |||
2735 | return dataBlock |
|
2735 | return dataBlock | |
2736 |
|
2736 | |||
2737 | if dataBlock is None: |
|
2737 | if dataBlock is None: | |
2738 | return None, None |
|
2738 | return None, None | |
2739 |
|
2739 | |||
2740 |
|
2740 | |||
2741 |
|
2741 | |||
2742 | return dataBlock |
|
2742 | return dataBlock | |
2743 |
|
2743 | |||
2744 | def releaseBlock(self): |
|
2744 | def releaseBlock(self): | |
2745 |
|
2745 | |||
2746 | if self.n % self.lenProfileOut != 0: |
|
2746 | if self.n % self.lenProfileOut != 0: | |
2747 | raise ValueError("lenProfileOut %d must be submultiple of nProfiles %d" %(self.lenProfileOut, self.n)) |
|
2747 | raise ValueError("lenProfileOut %d must be submultiple of nProfiles %d" %(self.lenProfileOut, self.n)) | |
2748 | return None |
|
2748 | return None | |
2749 |
|
2749 | |||
2750 | data = self.buffer[:,self.init_prof:self.end_prof:,:] #ch, prof, alt |
|
2750 | data = self.buffer[:,self.init_prof:self.end_prof:,:] #ch, prof, alt | |
2751 |
|
2751 | |||
2752 | self.init_prof = self.end_prof |
|
2752 | self.init_prof = self.end_prof | |
2753 | self.end_prof += self.lenProfileOut |
|
2753 | self.end_prof += self.lenProfileOut | |
2754 | #print("data release shape: ",dataOut.data.shape, self.end_prof) |
|
2754 | #print("data release shape: ",dataOut.data.shape, self.end_prof) | |
2755 | self.n_prof_released += 1 |
|
2755 | self.n_prof_released += 1 | |
2756 |
|
2756 | |||
2757 | return data |
|
2757 | return data | |
2758 |
|
2758 | |||
2759 | def run(self, dataOut, n=None, navg=0.9, nProfilesOut=1, profile_margin=50, th_hist_outlier=15,minHei=None,nBins=10, |
|
2759 | def run(self, dataOut, n=None, navg=0.9, nProfilesOut=1, profile_margin=50, th_hist_outlier=15,minHei=None,nBins=10, | |
2760 | maxHei=None, minRef=None, maxRef=None, debug=False, remYagi=False, nProfYagi = 0, offYagi=0, minHJULIA=None, maxHJULIA=None, |
|
2760 | maxHei=None, minRef=None, maxRef=None, debug=False, remYagi=False, nProfYagi = 0, offYagi=0, minHJULIA=None, maxHJULIA=None, | |
2761 | idate=None,startH=None,endH=None, thfactor=1): |
|
2761 | idate=None,startH=None,endH=None, thfactor=1): | |
2762 |
|
2762 | |||
2763 | if not self.isConfig: |
|
2763 | if not self.isConfig: | |
2764 | #print("init p idx: ", dataOut.profileIndex ) |
|
2764 | #print("init p idx: ", dataOut.profileIndex ) | |
2765 | self.setup(dataOut,n=n, navg=navg,profileMargin=profile_margin,thHistOutlier=th_hist_outlier,minHei=minHei, |
|
2765 | self.setup(dataOut,n=n, navg=navg,profileMargin=profile_margin,thHistOutlier=th_hist_outlier,minHei=minHei, | |
2766 | nBins=10, maxHei=maxHei, minRef=minRef, maxRef=maxRef, debug=debug, remYagi=remYagi, nProfYagi = nProfYagi, |
|
2766 | nBins=10, maxHei=maxHei, minRef=minRef, maxRef=maxRef, debug=debug, remYagi=remYagi, nProfYagi = nProfYagi, | |
2767 | offYagi=offYagi, minHJULIA=minHJULIA,maxHJULIA=maxHJULIA,idate=idate,startH=startH,endH=endH, thfactor=thfactor) |
|
2767 | offYagi=offYagi, minHJULIA=minHJULIA,maxHJULIA=maxHJULIA,idate=idate,startH=startH,endH=endH, thfactor=thfactor) | |
2768 |
|
2768 | |||
2769 | self.isConfig = True |
|
2769 | self.isConfig = True | |
2770 |
|
2770 | |||
2771 | dataBlock = None |
|
2771 | dataBlock = None | |
2772 | self.currentTime = datetime.datetime.fromtimestamp(dataOut.utctime) |
|
2772 | self.currentTime = datetime.datetime.fromtimestamp(dataOut.utctime) | |
2773 |
|
2773 | |||
2774 | if not dataOut.buffer_empty: #hay datos acumulados |
|
2774 | if not dataOut.buffer_empty: #hay datos acumulados | |
2775 |
|
2775 | |||
2776 | if self.init_prof == 0: |
|
2776 | if self.init_prof == 0: | |
2777 | self.n_prof_released = 0 |
|
2777 | self.n_prof_released = 0 | |
2778 | self.lenProfileOut = nProfilesOut |
|
2778 | self.lenProfileOut = nProfilesOut | |
2779 | dataOut.flagNoData = False |
|
2779 | dataOut.flagNoData = False | |
2780 | #print("tp 2 ",dataOut.data.shape) |
|
2780 | #print("tp 2 ",dataOut.data.shape) | |
2781 |
|
2781 | |||
2782 | self.init_prof = 0 |
|
2782 | self.init_prof = 0 | |
2783 | self.end_prof = self.lenProfileOut |
|
2783 | self.end_prof = self.lenProfileOut | |
2784 |
|
2784 | |||
2785 | dataOut.nProfiles = self.lenProfileOut |
|
2785 | dataOut.nProfiles = self.lenProfileOut | |
2786 | if nProfilesOut == 1: |
|
2786 | if nProfilesOut == 1: | |
2787 | dataOut.flagDataAsBlock = False |
|
2787 | dataOut.flagDataAsBlock = False | |
2788 | else: |
|
2788 | else: | |
2789 | dataOut.flagDataAsBlock = True |
|
2789 | dataOut.flagDataAsBlock = True | |
2790 | #print("prof: ",self.init_prof) |
|
2790 | #print("prof: ",self.init_prof) | |
2791 | dataOut.flagNoData = False |
|
2791 | dataOut.flagNoData = False | |
2792 | if numpy.isin(self.n_prof_released, self.outliers_IDs_list): |
|
2792 | if numpy.isin(self.n_prof_released, self.outliers_IDs_list): | |
2793 | #print("omitting: ", self.n_prof_released) |
|
2793 | #print("omitting: ", self.n_prof_released) | |
2794 | dataOut.flagNoData = True |
|
2794 | dataOut.flagNoData = True | |
2795 | dataOut.ippSeconds = self._ipp |
|
2795 | dataOut.ippSeconds = self._ipp | |
2796 | dataOut.utctime = self.first_utcBlock + self.init_prof*self._ipp |
|
2796 | dataOut.utctime = self.first_utcBlock + self.init_prof*self._ipp | |
2797 | # print("time: ", dataOut.utctime, self.first_utcBlock, self.init_prof,self._ipp,dataOut.ippSeconds) |
|
2797 | # print("time: ", dataOut.utctime, self.first_utcBlock, self.init_prof,self._ipp,dataOut.ippSeconds) | |
2798 | #dataOut.data = self.releaseBlock() |
|
2798 | #dataOut.data = self.releaseBlock() | |
2799 | #########################################################3 |
|
2799 | #########################################################3 | |
2800 | if self.n % self.lenProfileOut != 0: |
|
2800 | if self.n % self.lenProfileOut != 0: | |
2801 | raise ValueError("lenProfileOut %d must be submultiple of nProfiles %d" %(self.lenProfileOut, self.n)) |
|
2801 | raise ValueError("lenProfileOut %d must be submultiple of nProfiles %d" %(self.lenProfileOut, self.n)) | |
2802 | return None |
|
2802 | return None | |
2803 |
|
2803 | |||
2804 | dataOut.data = None |
|
2804 | dataOut.data = None | |
2805 |
|
2805 | |||
2806 | if nProfilesOut == 1: |
|
2806 | if nProfilesOut == 1: | |
2807 | dataOut.data = self.buffer[:,self.end_prof-1,:] #ch, prof, alt |
|
2807 | dataOut.data = self.buffer[:,self.end_prof-1,:] #ch, prof, alt | |
2808 | else: |
|
2808 | else: | |
2809 | dataOut.data = self.buffer[:,self.init_prof:self.end_prof,:] #ch, prof, alt |
|
2809 | dataOut.data = self.buffer[:,self.init_prof:self.end_prof,:] #ch, prof, alt | |
2810 |
|
2810 | |||
2811 | self.init_prof = self.end_prof |
|
2811 | self.init_prof = self.end_prof | |
2812 | self.end_prof += self.lenProfileOut |
|
2812 | self.end_prof += self.lenProfileOut | |
2813 | #print("data release shape: ",dataOut.data.shape, self.end_prof, dataOut.flagNoData) |
|
2813 | #print("data release shape: ",dataOut.data.shape, self.end_prof, dataOut.flagNoData) | |
2814 | self.n_prof_released += 1 |
|
2814 | self.n_prof_released += 1 | |
2815 |
|
2815 | |||
2816 | if self.end_prof >= (self.n +self.lenProfileOut): |
|
2816 | if self.end_prof >= (self.n +self.lenProfileOut): | |
2817 |
|
2817 | |||
2818 | self.init_prof = 0 |
|
2818 | self.init_prof = 0 | |
2819 | self.__profIndex = 0 |
|
2819 | self.__profIndex = 0 | |
2820 | self.buffer = None |
|
2820 | self.buffer = None | |
2821 | dataOut.buffer_empty = True |
|
2821 | dataOut.buffer_empty = True | |
2822 | self.outliers_IDs_list = [] |
|
2822 | self.outliers_IDs_list = [] | |
2823 | self.n_prof_released = 0 |
|
2823 | self.n_prof_released = 0 | |
2824 | dataOut.flagNoData = False #enviar ultimo aunque sea outlier :( |
|
2824 | dataOut.flagNoData = False #enviar ultimo aunque sea outlier :( | |
2825 | #print("cleaning...", dataOut.buffer_empty) |
|
2825 | #print("cleaning...", dataOut.buffer_empty) | |
2826 | dataOut.profileIndex = self.__profIndex |
|
2826 | dataOut.profileIndex = self.__profIndex | |
2827 | #################################################################### |
|
2827 | #################################################################### | |
2828 | return dataOut |
|
2828 | return dataOut | |
2829 |
|
2829 | |||
2830 |
|
2830 | |||
2831 | #print("tp 223 ",dataOut.data.shape) |
|
2831 | #print("tp 223 ",dataOut.data.shape) | |
2832 | dataOut.flagNoData = True |
|
2832 | dataOut.flagNoData = True | |
2833 |
|
2833 | |||
2834 |
|
2834 | |||
2835 |
|
2835 | |||
2836 | try: |
|
2836 | try: | |
2837 | #dataBlock = self.getData(dataOut.data.reshape(self.nChannels,1,self.nHeights), dataOut.utctime) |
|
2837 | #dataBlock = self.getData(dataOut.data.reshape(self.nChannels,1,self.nHeights), dataOut.utctime) | |
2838 | dataBlock = self.getData(numpy.reshape(dataOut.data,(self.nChannels,1,self.nHeights)), dataOut.utctime) |
|
2838 | dataBlock = self.getData(numpy.reshape(dataOut.data,(self.nChannels,1,self.nHeights)), dataOut.utctime) | |
2839 | self.__count_exec +=1 |
|
2839 | self.__count_exec +=1 | |
2840 | except Exception as e: |
|
2840 | except Exception as e: | |
2841 | print("Error getting profiles data",self.__count_exec ) |
|
2841 | print("Error getting profiles data",self.__count_exec ) | |
2842 | print(e) |
|
2842 | print(e) | |
2843 | sys.exit() |
|
2843 | sys.exit() | |
2844 |
|
2844 | |||
2845 | if self.__dataReady: |
|
2845 | if self.__dataReady: | |
2846 | #print("omitting: ", len(self.outliers_IDs_list)) |
|
2846 | #print("omitting: ", len(self.outliers_IDs_list)) | |
2847 | self.__count_exec = 0 |
|
2847 | self.__count_exec = 0 | |
2848 | #dataOut.data = |
|
2848 | #dataOut.data = | |
2849 | #self.buffer = numpy.flip(dataBlock, axis=1) |
|
2849 | #self.buffer = numpy.flip(dataBlock, axis=1) | |
2850 | self.buffer = dataBlock |
|
2850 | self.buffer = dataBlock | |
2851 | self.first_utcBlock = self.__initime |
|
2851 | self.first_utcBlock = self.__initime | |
2852 | dataOut.utctime = self.__initime |
|
2852 | dataOut.utctime = self.__initime | |
2853 | dataOut.nProfiles = self.__profIndex |
|
2853 | dataOut.nProfiles = self.__profIndex | |
2854 | #dataOut.flagNoData = False |
|
2854 | #dataOut.flagNoData = False | |
2855 | self.init_prof = 0 |
|
2855 | self.init_prof = 0 | |
2856 | self.__profIndex = 0 |
|
2856 | self.__profIndex = 0 | |
2857 | self.__initime = None |
|
2857 | self.__initime = None | |
2858 | dataBlock = None |
|
2858 | dataBlock = None | |
2859 | self.__buffer_times = [] |
|
2859 | self.__buffer_times = [] | |
2860 | dataOut.error = False |
|
2860 | dataOut.error = False | |
2861 | dataOut.useInputBuffer = True |
|
2861 | dataOut.useInputBuffer = True | |
2862 | dataOut.buffer_empty = False |
|
2862 | dataOut.buffer_empty = False | |
2863 | #print("1 ch: {} prof: {} hs: {}".format(int(dataOut.nChannels),int(dataOut.nProfiles),int(dataOut.nHeights))) |
|
2863 | #print("1 ch: {} prof: {} hs: {}".format(int(dataOut.nChannels),int(dataOut.nProfiles),int(dataOut.nHeights))) | |
2864 |
|
2864 | |||
2865 |
|
2865 | |||
2866 |
|
2866 | |||
2867 | #print(self.__count_exec) |
|
2867 | #print(self.__count_exec) | |
2868 |
|
2868 | |||
2869 | return dataOut |
|
2869 | return dataOut | |
2870 |
|
2870 | |||
2871 |
|
2871 | |||
2872 |
|
2872 | |||
2873 |
|
2873 | |||
2874 | class remHeightsIppInterf(Operation): |
|
2874 | class remHeightsIppInterf(Operation): | |
2875 |
|
2875 | |||
2876 | def __init__(self, **kwargs): |
|
2876 | def __init__(self, **kwargs): | |
2877 |
|
2877 | |||
2878 |
|
2878 | |||
2879 | Operation.__init__(self, **kwargs) |
|
2879 | Operation.__init__(self, **kwargs) | |
2880 |
|
2880 | |||
2881 | self.isConfig = False |
|
2881 | self.isConfig = False | |
2882 |
|
2882 | |||
2883 | self.heights_indx = None |
|
2883 | self.heights_indx = None | |
2884 | self.heightsList = [] |
|
2884 | self.heightsList = [] | |
2885 |
|
2885 | |||
2886 | self.ipp1 = None |
|
2886 | self.ipp1 = None | |
2887 | self.ipp2 = None |
|
2887 | self.ipp2 = None | |
2888 | self.tx1 = None |
|
2888 | self.tx1 = None | |
2889 | self.tx2 = None |
|
2889 | self.tx2 = None | |
2890 | self.dh1 = None |
|
2890 | self.dh1 = None | |
2891 |
|
2891 | |||
2892 |
|
2892 | |||
2893 | def setup(self, dataOut, ipp1=None, ipp2=None, tx1=None, tx2=None, dh1=None, |
|
2893 | def setup(self, dataOut, ipp1=None, ipp2=None, tx1=None, tx2=None, dh1=None, | |
2894 | idate=None, startH=None, endH=None): |
|
2894 | idate=None, startH=None, endH=None): | |
2895 |
|
2895 | |||
2896 |
|
2896 | |||
2897 | self.ipp1 = ipp1 |
|
2897 | self.ipp1 = ipp1 | |
2898 | self.ipp2 = ipp2 |
|
2898 | self.ipp2 = ipp2 | |
2899 | self.tx1 = tx1 |
|
2899 | self.tx1 = tx1 | |
2900 | self.tx2 = tx2 |
|
2900 | self.tx2 = tx2 | |
2901 | self.dh1 = dh1 |
|
2901 | self.dh1 = dh1 | |
2902 |
|
2902 | |||
2903 | _maxIpp1R = dataOut.heightList.max() |
|
2903 | _maxIpp1R = dataOut.heightList.max() | |
2904 |
|
2904 | |||
2905 | _n_repeats = int(_maxIpp1R / ipp2) |
|
2905 | _n_repeats = int(_maxIpp1R / ipp2) | |
2906 | _init_hIntf = (tx1 + ipp2/2)+ dh1 |
|
2906 | _init_hIntf = (tx1 + ipp2/2)+ dh1 | |
2907 | _n_hIntf = int(tx2 / dh1) |
|
2907 | _n_hIntf = int(tx2 / dh1) | |
2908 |
|
2908 | |||
2909 | self.heightsList = [_init_hIntf+n*ipp2 for n in range(_n_repeats) ] |
|
2909 | self.heightsList = [_init_hIntf+n*ipp2 for n in range(_n_repeats) ] | |
2910 | heiList = dataOut.heightList |
|
2910 | heiList = dataOut.heightList | |
2911 | self.heights_indx = [getHei_index(h,h,heiList)[0] for h in self.heightsList] |
|
2911 | self.heights_indx = [getHei_index(h,h,heiList)[0] for h in self.heightsList] | |
2912 |
|
2912 | |||
2913 | self.heights_indx = [ numpy.asarray([k for k in range(_n_hIntf+2)])+(getHei_index(h,h,heiList)[0] -1) for h in self.heightsList] |
|
2913 | self.heights_indx = [ numpy.asarray([k for k in range(_n_hIntf+2)])+(getHei_index(h,h,heiList)[0] -1) for h in self.heightsList] | |
2914 |
|
2914 | |||
2915 | self.heights_indx = numpy.asarray(self.heights_indx ) |
|
2915 | self.heights_indx = numpy.asarray(self.heights_indx ) | |
2916 | self.isConfig = True |
|
2916 | self.isConfig = True | |
2917 | self.startTime = datetime.datetime.combine(idate,startH) |
|
2917 | self.startTime = datetime.datetime.combine(idate,startH) | |
2918 | self.endTime = datetime.datetime.combine(idate,endH) |
|
2918 | self.endTime = datetime.datetime.combine(idate,endH) | |
2919 | #print(self.startTime, self.endTime) |
|
2919 | #print(self.startTime, self.endTime) | |
2920 | #print("nrepeats: ", _n_repeats, " _nH: ",_n_hIntf ) |
|
2920 | #print("nrepeats: ", _n_repeats, " _nH: ",_n_hIntf ) | |
2921 |
|
2921 | |||
2922 | log.warning("Heights set to zero (km): ", self.name) |
|
2922 | log.warning("Heights set to zero (km): ", self.name) | |
2923 | log.warning(str((dataOut.heightList[self.heights_indx].flatten())), self.name) |
|
2923 | log.warning(str((dataOut.heightList[self.heights_indx].flatten())), self.name) | |
2924 | log.warning("Be careful with the selection of heights for noise calculation!") |
|
2924 | log.warning("Be careful with the selection of heights for noise calculation!") | |
2925 |
|
2925 | |||
2926 | def run(self, dataOut, ipp1=None, ipp2=None, tx1=None, tx2=None, dh1=None, idate=None, |
|
2926 | def run(self, dataOut, ipp1=None, ipp2=None, tx1=None, tx2=None, dh1=None, idate=None, | |
2927 | startH=None, endH=None): |
|
2927 | startH=None, endH=None): | |
2928 | #print(locals().values()) |
|
2928 | #print(locals().values()) | |
2929 | if None in locals().values(): |
|
2929 | if None in locals().values(): | |
2930 | log.warning('Missing kwargs, invalid values """None""" ', self.name) |
|
2930 | log.warning('Missing kwargs, invalid values """None""" ', self.name) | |
2931 | return dataOut |
|
2931 | return dataOut | |
2932 |
|
2932 | |||
2933 |
|
2933 | |||
2934 | if not self.isConfig: |
|
2934 | if not self.isConfig: | |
2935 | self.setup(dataOut, ipp1=ipp1, ipp2=ipp2, tx1=tx1, tx2=tx2, dh1=dh1, |
|
2935 | self.setup(dataOut, ipp1=ipp1, ipp2=ipp2, tx1=tx1, tx2=tx2, dh1=dh1, | |
2936 | idate=idate, startH=startH, endH=endH) |
|
2936 | idate=idate, startH=startH, endH=endH) | |
2937 |
|
2937 | |||
2938 | dataOut.flagProfilesByRange = False |
|
2938 | dataOut.flagProfilesByRange = False | |
2939 | currentTime = datetime.datetime.fromtimestamp(dataOut.utctime) |
|
2939 | currentTime = datetime.datetime.fromtimestamp(dataOut.utctime) | |
2940 |
|
2940 | |||
2941 | if currentTime < self.startTime or currentTime > self.endTime: |
|
2941 | if currentTime < self.startTime or currentTime > self.endTime: | |
2942 | return dataOut |
|
2942 | return dataOut | |
2943 |
|
2943 | |||
2944 | for ch in range(dataOut.data.shape[0]): |
|
2944 | for ch in range(dataOut.data.shape[0]): | |
2945 |
|
2945 | |||
2946 | for hk in self.heights_indx.flatten(): |
|
2946 | for hk in self.heights_indx.flatten(): | |
2947 | if dataOut.data.ndim < 3: |
|
2947 | if dataOut.data.ndim < 3: | |
2948 | dataOut.data[ch,hk] = 0.0 + 0.0j |
|
2948 | dataOut.data[ch,hk] = 0.0 + 0.0j | |
2949 | else: |
|
2949 | else: | |
2950 | dataOut.data[ch,:,hk] = 0.0 + 0.0j |
|
2950 | dataOut.data[ch,:,hk] = 0.0 + 0.0j | |
2951 |
|
2951 | |||
2952 | dataOut.flagProfilesByRange = True |
|
2952 | dataOut.flagProfilesByRange = True | |
2953 |
|
2953 | |||
2954 | return dataOut |
|
2954 | return dataOut | |
2955 |
|
2955 | |||
2956 |
|
2956 | |||
2957 |
|
2957 | |||
2958 |
|
2958 | |||
2959 | class profiles2Block(Operation): |
|
2959 | class profiles2Block(Operation): | |
2960 | ''' |
|
2960 | ''' | |
2961 | Escrito: Joab Apaza |
|
2961 | Escrito: Joab Apaza | |
2962 |
|
2962 | |||
2963 | genera un bloque de perfiles |
|
2963 | genera un bloque de perfiles | |
2964 |
|
2964 | |||
2965 |
|
2965 | |||
2966 | Out: |
|
2966 | Out: | |
2967 | block |
|
2967 | block | |
2968 | ''' |
|
2968 | ''' | |
2969 |
|
2969 | |||
2970 | isConfig = False |
|
2970 | isConfig = False | |
2971 | __buffer_data = [] |
|
2971 | __buffer_data = [] | |
2972 | __buffer_times = [] |
|
2972 | __buffer_times = [] | |
2973 | __profIndex = 0 |
|
2973 | __profIndex = 0 | |
2974 | __byTime = False |
|
2974 | __byTime = False | |
2975 | __initime = None |
|
2975 | __initime = None | |
2976 | __lastdatatime = None |
|
2976 | __lastdatatime = None | |
2977 | buffer = None |
|
2977 | buffer = None | |
2978 | n = None |
|
2978 | n = None | |
2979 | __dataReady = False |
|
2979 | __dataReady = False | |
2980 | __nChannels = None |
|
2980 | __nChannels = None | |
2981 | __nHeis = None |
|
2981 | __nHeis = None | |
2982 |
|
2982 | |||
2983 | def __init__(self, **kwargs): |
|
2983 | def __init__(self, **kwargs): | |
2984 |
|
2984 | |||
2985 | Operation.__init__(self, **kwargs) |
|
2985 | Operation.__init__(self, **kwargs) | |
2986 | self.isConfig = False |
|
2986 | self.isConfig = False | |
2987 |
|
2987 | |||
2988 | def setup(self,n=None, timeInterval=None): |
|
2988 | def setup(self,n=None, timeInterval=None): | |
2989 |
|
2989 | |||
2990 | if n == None and timeInterval == None: |
|
2990 | if n == None and timeInterval == None: | |
2991 | raise ValueError("n or timeInterval should be specified ...") |
|
2991 | raise ValueError("n or timeInterval should be specified ...") | |
2992 |
|
2992 | |||
2993 | if n != None: |
|
2993 | if n != None: | |
2994 | self.n = n |
|
2994 | self.n = n | |
2995 | self.__byTime = False |
|
2995 | self.__byTime = False | |
2996 | else: |
|
2996 | else: | |
2997 | self.__integrationtime = timeInterval #* 60. #if (type(timeInterval)!=integer) -> change this line |
|
2997 | self.__integrationtime = timeInterval #* 60. #if (type(timeInterval)!=integer) -> change this line | |
2998 | self.n = 9999 |
|
2998 | self.n = 9999 | |
2999 | self.__byTime = True |
|
2999 | self.__byTime = True | |
3000 |
|
3000 | |||
3001 | self.__profIndex = 0 |
|
3001 | self.__profIndex = 0 | |
3002 |
|
3002 | |||
3003 |
|
3003 | |||
3004 | def fillBuffer(self, data, datatime): |
|
3004 | def fillBuffer(self, data, datatime): | |
3005 |
|
3005 | |||
3006 | if self.__profIndex == 0: |
|
3006 | if self.__profIndex == 0: | |
3007 | self.__buffer_data = data.copy() |
|
3007 | self.__buffer_data = data.copy() | |
3008 |
|
3008 | |||
3009 | else: |
|
3009 | else: | |
3010 | self.__buffer_data = numpy.concatenate((self.__buffer_data,data), axis=1)#en perfiles |
|
3010 | self.__buffer_data = numpy.concatenate((self.__buffer_data,data), axis=1)#en perfiles | |
3011 | self.__profIndex += 1 |
|
3011 | self.__profIndex += 1 | |
3012 | self.__buffer_times.append(datatime) |
|
3012 | self.__buffer_times.append(datatime) | |
3013 |
|
3013 | |||
3014 | def getData(self, data, datatime=None): |
|
3014 | def getData(self, data, datatime=None): | |
3015 | if self.__initime == None: |
|
3015 | if self.__initime == None: | |
3016 | self.__initime = datatime |
|
3016 | self.__initime = datatime | |
3017 |
|
3017 | |||
3018 | if data.ndim < 3: |
|
3018 | if data.ndim < 3: | |
3019 | data = data.reshape(self.__nChannels,1,self.__nHeis ) |
|
3019 | data = data.reshape(self.__nChannels,1,self.__nHeis ) | |
3020 |
|
3020 | |||
3021 | if self.__byTime: |
|
3021 | if self.__byTime: | |
3022 | dataBlock = self.byTime(data, datatime) |
|
3022 | dataBlock = self.byTime(data, datatime) | |
3023 | else: |
|
3023 | else: | |
3024 | dataBlock = self.byProfiles(data, datatime) |
|
3024 | dataBlock = self.byProfiles(data, datatime) | |
3025 |
|
3025 | |||
3026 |
|
3026 | |||
3027 | self.__lastdatatime = datatime |
|
3027 | self.__lastdatatime = datatime | |
3028 |
|
3028 | |||
3029 | if dataBlock is None: |
|
3029 | if dataBlock is None: | |
3030 | return None, None |
|
3030 | return None, None | |
3031 |
|
3031 | |||
3032 | return dataBlock, self.__buffer_times |
|
3032 | return dataBlock, self.__buffer_times | |
3033 |
|
3033 | |||
3034 | def byProfiles(self, data, datatime): |
|
3034 | def byProfiles(self, data, datatime): | |
3035 |
|
3035 | |||
3036 | self.__dataReady = False |
|
3036 | self.__dataReady = False | |
3037 | dataBlock = None |
|
3037 | dataBlock = None | |
3038 | # n = None |
|
3038 | # n = None | |
3039 | # print data |
|
3039 | # print data | |
3040 | # raise |
|
3040 | # raise | |
3041 | self.fillBuffer(data, datatime) |
|
3041 | self.fillBuffer(data, datatime) | |
3042 |
|
3042 | |||
3043 | if self.__profIndex == self.n: |
|
3043 | if self.__profIndex == self.n: | |
3044 | dataBlock = self.__buffer_data |
|
3044 | dataBlock = self.__buffer_data | |
3045 | self.__dataReady = True |
|
3045 | self.__dataReady = True | |
3046 |
|
3046 | |||
3047 | return dataBlock |
|
3047 | return dataBlock | |
3048 |
|
3048 | |||
3049 | def byTime(self, data, datatime): |
|
3049 | def byTime(self, data, datatime): | |
3050 |
|
3050 | |||
3051 | self.__dataReady = False |
|
3051 | self.__dataReady = False | |
3052 | dataBlock = None |
|
3052 | dataBlock = None | |
3053 | n = None |
|
3053 | n = None | |
3054 |
|
3054 | |||
3055 | self.fillBuffer(data, datatime) |
|
3055 | self.fillBuffer(data, datatime) | |
3056 |
|
3056 | |||
3057 | if (datatime - self.__initime) >= self.__integrationtime: |
|
3057 | if (datatime - self.__initime) >= self.__integrationtime: | |
3058 | dataBlock = self.__buffer_data |
|
3058 | dataBlock = self.__buffer_data | |
3059 | self.n = self.__profIndex |
|
3059 | self.n = self.__profIndex | |
3060 | self.__dataReady = True |
|
3060 | self.__dataReady = True | |
3061 |
|
3061 | |||
3062 | return dataBlock |
|
3062 | return dataBlock | |
3063 |
|
3063 | |||
3064 |
|
3064 | |||
3065 | def run(self, dataOut, n=None, timeInterval=None, **kwargs): |
|
3065 | def run(self, dataOut, n=None, timeInterval=None, **kwargs): | |
3066 |
|
3066 | |||
3067 | if not self.isConfig: |
|
3067 | if not self.isConfig: | |
3068 | self.setup(n=n, timeInterval=timeInterval, **kwargs) |
|
3068 | self.setup(n=n, timeInterval=timeInterval, **kwargs) | |
3069 | self.__nChannels = dataOut.nChannels |
|
3069 | self.__nChannels = dataOut.nChannels | |
3070 | self.__nHeis = len(dataOut.heightList) |
|
3070 | self.__nHeis = len(dataOut.heightList) | |
3071 | self.isConfig = True |
|
3071 | self.isConfig = True | |
3072 |
|
3072 | |||
3073 | if dataOut.flagDataAsBlock: |
|
3073 | if dataOut.flagDataAsBlock: | |
3074 | """ |
|
3074 | """ | |
3075 | Si la data es leida por bloques, dimension = [nChannels, nProfiles, nHeis] |
|
3075 | Si la data es leida por bloques, dimension = [nChannels, nProfiles, nHeis] | |
3076 | """ |
|
3076 | """ | |
3077 | raise ValueError("The data is already a block") |
|
3077 | raise ValueError("The data is already a block") | |
3078 | return |
|
3078 | return | |
3079 | else: |
|
3079 | else: | |
3080 |
|
3080 | |||
3081 | dataBlock, timeBlock = self.getData(dataOut.data, dataOut.utctime) |
|
3081 | dataBlock, timeBlock = self.getData(dataOut.data, dataOut.utctime) | |
3082 |
|
3082 | |||
3083 |
|
3083 | |||
3084 | # print(dataOut.data.shape) |
|
3084 | # print(dataOut.data.shape) | |
3085 | # dataOut.timeInterval *= n |
|
3085 | # dataOut.timeInterval *= n | |
3086 | dataOut.flagNoData = True |
|
3086 | dataOut.flagNoData = True | |
3087 |
|
3087 | |||
3088 | if self.__dataReady: |
|
3088 | if self.__dataReady: | |
3089 | dataOut.data = dataBlock |
|
3089 | dataOut.data = dataBlock | |
3090 | dataOut.flagDataAsBlock = True |
|
3090 | dataOut.flagDataAsBlock = True | |
3091 | dataOut.utctime = timeBlock[-1] |
|
3091 | dataOut.utctime = timeBlock[-1] | |
3092 | dataOut.nProfiles = self.__profIndex |
|
3092 | dataOut.nProfiles = self.__profIndex | |
3093 | # print avgdata, avgdatatime |
|
3093 | # print avgdata, avgdatatime | |
3094 | # raise |
|
3094 | # raise | |
3095 | dataOut.flagNoData = False |
|
3095 | dataOut.flagNoData = False | |
3096 | self.__profIndex = 0 |
|
3096 | self.__profIndex = 0 | |
3097 | self.__initime = None |
|
3097 | self.__initime = None | |
3098 | #update Processing Header: |
|
3098 | #update Processing Header: | |
3099 | # print(dataOut.data.shape) |
|
3099 | # print(dataOut.data.shape) | |
3100 |
|
3100 | |||
3101 | return dataOut |
|
3101 | return dataOut | |
3102 |
|
3102 | |||
3103 |
|
3103 | |||
3104 | class remFaradayProfiles(Operation): |
|
3104 | class remFaradayProfiles(Operation): | |
3105 |
|
3105 | |||
3106 | def __init__(self, **kwargs): |
|
3106 | def __init__(self, **kwargs): | |
3107 |
|
3107 | |||
3108 |
|
3108 | |||
3109 | Operation.__init__(self, **kwargs) |
|
3109 | Operation.__init__(self, **kwargs) | |
3110 |
|
3110 | |||
3111 | self.isConfig = False |
|
3111 | self.isConfig = False | |
3112 |
|
3112 | |||
3113 | self.nprofile2 = 0 |
|
3113 | self.nprofile2 = 0 | |
3114 | self.profile = 0 |
|
3114 | self.profile = 0 | |
3115 | self.flagRun = False |
|
3115 | self.flagRun = False | |
3116 | self.flagRemove = False |
|
3116 | self.flagRemove = False | |
3117 | self.k = 0 |
|
3117 | self.k = 0 | |
3118 |
|
3118 | |||
3119 | def setup(self, channel,nChannels=5, nProfiles=300,nBlocks=100, nIpp2=300, nTx2=132, nTaus=22, offTaus=14, iTaus=8, |
|
3119 | def setup(self, channel,nChannels=5, nProfiles=300,nBlocks=100, nIpp2=300, nTx2=132, nTaus=22, offTaus=14, iTaus=8, | |
3120 | nfft=1): |
|
3120 | nfft=1): | |
3121 | ''' |
|
3121 | ''' | |
3122 | nProfiles = amisr profiles per block -> raw data |
|
3122 | nProfiles = amisr profiles per block -> raw data | |
3123 | nIpp1 = number of profiles in one AMISR sync |
|
3123 | nIpp1 = number of profiles in one AMISR sync | |
3124 | nIpp2 = number of profiles in one Jicamarca sync |
|
3124 | nIpp2 = number of profiles in one Jicamarca sync | |
3125 | nTx2 = number of profiles transmited for Faraday Experiment |
|
3125 | nTx2 = number of profiles transmited for Faraday Experiment | |
3126 | nTaus = Total profiles for lags |
|
3126 | nTaus = Total profiles for lags | |
3127 | offTaus = where starts the interference, (profile) |
|
3127 | offTaus = where starts the interference, (profile) | |
3128 | iTaus = lenght of the interference |
|
3128 | iTaus = lenght of the interference | |
3129 | irepeat = number of repetition of the Taus |
|
3129 | irepeat = number of repetition of the Taus | |
3130 | ''' |
|
3130 | ''' | |
3131 | self.nIpp2 = nIpp2 |
|
3131 | self.nIpp2 = nIpp2 | |
3132 | self.channel = channel |
|
3132 | self.channel = channel | |
3133 | self.nChannels = nChannels |
|
3133 | self.nChannels = nChannels | |
3134 | self.nTx2 = nTx2 |
|
3134 | self.nTx2 = nTx2 | |
3135 | self.nTaus = nTaus |
|
3135 | self.nTaus = nTaus | |
3136 |
|
3136 | |||
3137 |
|
3137 | |||
3138 | booldataset = numpy.ones( (nBlocks, nProfiles) ) |
|
3138 | booldataset = numpy.ones( (nBlocks, nProfiles) ) | |
3139 | self.profilesFlag = None |
|
3139 | self.profilesFlag = None | |
3140 | #marking the afected profiles |
|
3140 | #marking the afected profiles | |
3141 | f_iTaus=False |
|
3141 | f_iTaus=False | |
3142 | f_ntx = False |
|
3142 | f_ntx = False | |
3143 | fi = 0 |
|
3143 | fi = 0 | |
3144 | k = 0 |
|
3144 | k = 0 | |
3145 | kt =0 |
|
3145 | kt =0 | |
3146 | fi_reps = 0 |
|
3146 | fi_reps = 0 | |
3147 | for i in range(nBlocks): |
|
3147 | for i in range(nBlocks): | |
3148 | for j in range(nProfiles): |
|
3148 | for j in range(nProfiles): | |
3149 | # fi 0---nTaus |
|
3149 | # fi 0---nTaus | |
3150 | # |
|
3150 | # | |
3151 | if k%nIpp2==0: #each sync PPs or 2, 3, or 5 |
|
3151 | if k%nIpp2==0: #each sync PPs or 2, 3, or 5 | |
3152 | f_ntx = True |
|
3152 | f_ntx = True | |
3153 | kt = 0 |
|
3153 | kt = 0 | |
3154 | if f_ntx: |
|
3154 | if f_ntx: | |
3155 |
|
3155 | |||
3156 | if kt%nTaus==0: #each sequence of Taus |
|
3156 | if kt%nTaus==0: #each sequence of Taus | |
3157 | f_iTaus = True |
|
3157 | f_iTaus = True | |
3158 | fi = 0 |
|
3158 | fi = 0 | |
3159 |
|
3159 | |||
3160 | if f_iTaus: |
|
3160 | if f_iTaus: | |
3161 |
if fi > offTaus |
|
3161 | if fi > offTaus: | |
3162 | booldataset[i, j]=0 #Afected profile |
|
3162 | booldataset[i, j]=0 #Afected profile | |
3163 | fi += 1 |
|
3163 | fi += 1 | |
3164 |
if fi == nTaus |
|
3164 | if fi == nTaus: #restart the taus sequence | |
3165 | fi = 0 |
|
3165 | fi = 0 | |
3166 | f_iTaus = False |
|
3166 | f_iTaus = False | |
3167 | fi_reps += 1 |
|
3167 | fi_reps += 1 | |
3168 | if fi_reps == (nTx2/nTaus): |
|
3168 | if fi_reps == (nTx2/nTaus): | |
3169 | fi = 0 |
|
3169 | fi = 0 | |
3170 | fi_reps = 0 |
|
3170 | fi_reps = 0 | |
3171 | f_ntx=False |
|
3171 | f_ntx=False | |
|
3172 | #break | |||
3172 | kt += 1 |
|
3173 | kt += 1 | |
3173 | k += 1 |
|
3174 | k += 1 | |
3174 |
|
3175 | |||
3175 | # fig = plt.figure() |
|
3176 | # fig = plt.figure() | |
3176 | # ax = fig.add_subplot(111) |
|
3177 | # ax = fig.add_subplot(111) | |
3177 | # cax = ax.pcolormesh(booldataset, cmap='plasma') |
|
3178 | # cax = ax.pcolormesh(booldataset, cmap='plasma') | |
3178 | # cbar = fig.colorbar(cax) |
|
3179 | # cbar = fig.colorbar(cax) | |
3179 | # plt.show() |
|
3180 | # plt.show() | |
3180 |
|
3181 | |||
3181 |
|
3182 | |||
3182 | #reshape the Flag as AMISR reader |
|
3183 | #reshape the Flag as AMISR reader | |
3183 |
|
3184 | |||
3184 | profPerCH = int( (nProfiles) / (nfft*nChannels)) |
|
3185 | profPerCH = int( (nProfiles) / (nfft*nChannels)) | |
3185 | new_block = numpy.empty( (nBlocks, nChannels, int(nProfiles/nChannels) ) ) |
|
3186 | new_block = numpy.empty( (nBlocks, nChannels, int(nProfiles/nChannels) ) ) | |
3186 | # print(new_block.shape, profPerCH) |
|
3187 | # print(new_block.shape, profPerCH) | |
3187 | for thisChannel in range(nChannels): |
|
3188 | for thisChannel in range(nChannels): | |
3188 |
|
3189 | |||
3189 | ich = thisChannel |
|
3190 | ich = thisChannel | |
3190 |
|
3191 | |||
3191 | idx_ch = [nfft*(ich + nChannels*k) for k in range(profPerCH)] |
|
3192 | idx_ch = [nfft*(ich + nChannels*k) for k in range(profPerCH)] | |
3192 | #print(idx_ch) |
|
3193 | #print(idx_ch) | |
3193 | if nfft > 1: |
|
3194 | if nfft > 1: | |
3194 | aux = [numpy.arange(i, i+nfft) for i in idx_ch] |
|
3195 | aux = [numpy.arange(i, i+nfft) for i in idx_ch] | |
3195 | idx_ch = None |
|
3196 | idx_ch = None | |
3196 | idx_ch =aux |
|
3197 | idx_ch =aux | |
3197 | idx_ch = numpy.array(idx_ch, dtype=int).flatten() |
|
3198 | idx_ch = numpy.array(idx_ch, dtype=int).flatten() | |
3198 | else: |
|
3199 | else: | |
3199 | idx_ch = numpy.array(idx_ch, dtype=int) |
|
3200 | idx_ch = numpy.array(idx_ch, dtype=int) | |
3200 |
|
3201 | |||
3201 | new_block[:,ich,:] = booldataset[:,idx_ch] |
|
3202 | new_block[:,ich,:] = booldataset[:,idx_ch] | |
3202 |
|
3203 | |||
3203 | new_block = numpy.transpose(new_block, (1,0,2)) |
|
3204 | new_block = numpy.transpose(new_block, (1,0,2)) | |
3204 |
|
|
3205 | new_block = numpy.reshape(new_block, (nChannels,-1)) | |
3205 | new_block = numpy.reshape(new_block, (nChannels,profPerCH*nBlocks)) |
|
3206 | #new_block = numpy.reshape(new_block, (nChannels,profPerCH*nBlocks)) | |
3206 | self.profilesFlag = new_block.copy() |
|
3207 | self.profilesFlag = new_block.copy() | |
3207 |
|
3208 | |||
3208 | # fig = plt.figure() |
|
3209 | # fig = plt.figure() | |
3209 | # ax = fig.add_subplot(111) |
|
3210 | # ax = fig.add_subplot(111) | |
3210 | # cax = ax.pcolormesh(new_block, cmap='plasma') |
|
3211 | # cax = ax.pcolormesh(new_block, cmap='plasma') | |
3211 | # cbar = fig.colorbar(cax) |
|
3212 | # cbar = fig.colorbar(cax) | |
3212 | # plt.show() |
|
3213 | # plt.show() | |
3213 |
|
3214 | |||
3214 | self.isConfig = True |
|
3215 | self.isConfig = True | |
3215 |
|
3216 | |||
3216 |
|
3217 | |||
3217 | def run(self,dataOut, channel=0, nChannels=5, nProfiles=300,nBlocks=100,nIpp1=100, |
|
3218 | def run(self,dataOut, channel=0, nChannels=5, nProfiles=300,nBlocks=100,nIpp1=100, | |
3218 |
nIpp2=300, nTx2=132, nTaus=22, offTaus= |
|
3219 | nIpp2=300, nTx2=132, nTaus=22, offTaus=12, iTaus=10, nfft=1 ,offIpp=0): | |
3219 |
|
3220 | |||
3220 | dataOut.flagNoData = False |
|
3221 | dataOut.flagNoData = False | |
3221 |
|
3222 | |||
3222 | if not self.isConfig: |
|
3223 | if not self.isConfig: | |
3223 | self.setup(channel,nChannels=nChannels, nProfiles=nProfiles,nBlocks=nBlocks, nIpp2=nIpp2, |
|
3224 | self.setup(channel,nChannels=nChannels, nProfiles=nProfiles,nBlocks=nBlocks, nIpp2=nIpp2, | |
3224 | nTx2=nTx2, nTaus=nTaus, offTaus=offTaus, iTaus=iTaus, nfft=nfft) |
|
3225 | nTx2=nTx2, nTaus=nTaus, offTaus=offTaus, iTaus=iTaus, nfft=nfft) | |
3225 | #print("Setup Done") |
|
3226 | #print("Setup Done") | |
3226 | #print(offIpp*nIpp1/nChannels) |
|
3227 | #print(offIpp*nIpp1/nChannels) | |
3227 | if not self.flagRun: |
|
3228 | if not self.flagRun: | |
3228 | if self.nprofile2 < offIpp*nIpp1/nChannels : |
|
3229 | if self.nprofile2 < offIpp*nIpp1/nChannels : | |
3229 | self.nprofile2 += 1 |
|
3230 | self.nprofile2 += 1 | |
3230 | return dataOut |
|
3231 | return dataOut | |
3231 | else: |
|
3232 | else: | |
3232 | self.flagRun = True |
|
3233 | self.flagRun = True | |
3233 | self.profile = 0 |
|
3234 | self.profile = 0 | |
3234 |
|
3235 | |||
3235 | #check profile ## Faraday interference |
|
3236 | #check profile ## Faraday interference | |
3236 | if self.profilesFlag[channel, self.profile]==0: |
|
3237 | if self.profilesFlag[channel, self.profile]==0: | |
3237 | dataOut.flagNoData = True # do not pass this profile |
|
3238 | dataOut.flagNoData = True # do not pass this profile | |
3238 |
|
3239 | |||
3239 | self.profile +=1 |
|
3240 | self.profile +=1 | |
3240 |
|
3241 | |||
3241 |
|
3242 | |||
3242 | self.nprofile2 +=1 |
|
3243 | self.nprofile2 +=1 | |
3243 |
|
3244 | |||
3244 | if self.nprofile2 == int((nProfiles*nBlocks)/self.nChannels): |
|
3245 | if self.nprofile2 == int((nProfiles*nBlocks)/self.nChannels): | |
3245 | self.nprofile2 = 0 |
|
3246 | self.nprofile2 = 0 | |
3246 | self.profile = 0 |
|
3247 | self.profile = 0 | |
3247 | self.flagRun = False |
|
3248 | self.flagRun = False | |
3248 |
|
3249 | |||
3249 | return dataOut No newline at end of file |
|
3250 | return dataOut |
General Comments 0
You need to be logged in to leave comments.
Login now