@@ -1,6939 +1,6944 | |||||
1 |
|
1 | |||
2 | import os |
|
2 | import os | |
3 | import sys |
|
3 | import sys | |
4 | import numpy, math |
|
4 | import numpy, math | |
5 | from scipy import interpolate |
|
5 | from scipy import interpolate | |
6 | from scipy.optimize import nnls |
|
6 | from scipy.optimize import nnls | |
7 | from schainpy.model.proc.jroproc_base import ProcessingUnit, Operation, MPDecorator |
|
7 | from schainpy.model.proc.jroproc_base import ProcessingUnit, Operation, MPDecorator | |
8 | from schainpy.model.data.jrodata import Voltage, hildebrand_sekhon |
|
8 | from schainpy.model.data.jrodata import Voltage, hildebrand_sekhon | |
9 | from schainpy.utils import log |
|
9 | from schainpy.utils import log | |
10 | from time import time, mktime, strptime, gmtime, ctime |
|
10 | from time import time, mktime, strptime, gmtime, ctime | |
11 | from scipy.optimize import least_squares |
|
11 | from scipy.optimize import least_squares | |
12 | import datetime |
|
12 | import datetime | |
13 | import csv |
|
13 | import csv | |
14 |
|
14 | |||
15 | try: |
|
15 | try: | |
16 | from schainpy.model.proc import fitacf_guess |
|
16 | from schainpy.model.proc import fitacf_guess | |
17 | from schainpy.model.proc import fitacf_fit_short |
|
17 | from schainpy.model.proc import fitacf_fit_short | |
18 | from schainpy.model.proc import fitacf_acf2 |
|
18 | from schainpy.model.proc import fitacf_acf2 | |
19 | from schainpy.model.proc import full_profile_profile |
|
19 | from schainpy.model.proc import full_profile_profile | |
20 | except: |
|
20 | except: | |
21 | log.warning('Missing Faraday fortran libs') |
|
21 | log.warning('Missing Faraday fortran libs') | |
22 |
|
22 | |||
23 | class VoltageProc(ProcessingUnit): |
|
23 | class VoltageProc(ProcessingUnit): | |
24 |
|
24 | |||
25 | def __init__(self): |
|
25 | def __init__(self): | |
26 |
|
26 | |||
27 | ProcessingUnit.__init__(self) |
|
27 | ProcessingUnit.__init__(self) | |
28 |
|
28 | |||
29 | self.dataOut = Voltage() |
|
29 | self.dataOut = Voltage() | |
30 | self.flip = 1 |
|
30 | self.flip = 1 | |
31 | self.setupReq = False |
|
31 | self.setupReq = False | |
32 | #self.dataOut.test=1 |
|
32 | #self.dataOut.test=1 | |
33 |
|
33 | |||
34 |
|
34 | |||
35 | def run(self, runNextUnit = 0): |
|
35 | def run(self, runNextUnit = 0): | |
36 | #import time |
|
36 | #import time | |
37 | #time.sleep(3) |
|
37 | #time.sleep(3) | |
38 |
|
38 | |||
39 | if self.dataIn.type == 'AMISR': |
|
39 | if self.dataIn.type == 'AMISR': | |
40 | self.__updateObjFromAmisrInput() |
|
40 | self.__updateObjFromAmisrInput() | |
41 |
|
41 | |||
42 | if self.dataIn.type == 'Voltage': |
|
42 | if self.dataIn.type == 'Voltage': | |
43 | self.dataOut.copy(self.dataIn) |
|
43 | self.dataOut.copy(self.dataIn) | |
44 | self.dataOut.runNextUnit = runNextUnit |
|
44 | self.dataOut.runNextUnit = runNextUnit | |
45 |
|
45 | |||
46 |
|
46 | |||
47 | #self.dataOut.flagNoData=True |
|
47 | #self.dataOut.flagNoData=True | |
48 | #print(self.dataOut.data[-1,:]) |
|
48 | #print(self.dataOut.data[-1,:]) | |
49 | #print(ctime(self.dataOut.utctime)) |
|
49 | #print(ctime(self.dataOut.utctime)) | |
50 | #print(self.dataOut.heightList) |
|
50 | #print(self.dataOut.heightList) | |
51 | #print(self.dataOut.nHeights) |
|
51 | #print(self.dataOut.nHeights) | |
52 | #exit(1) |
|
52 | #exit(1) | |
53 | #print(self.dataOut.data[6,:32]) |
|
53 | #print(self.dataOut.data[6,:32]) | |
54 | #print(self.dataOut.data[0,320-5:320+5-5]) |
|
54 | #print(self.dataOut.data[0,320-5:320+5-5]) | |
55 | ##print(self.dataOut.heightList[-20:]) |
|
55 | ##print(self.dataOut.heightList[-20:]) | |
56 | #print(numpy.shape(self.dataOut.data)) |
|
56 | #print(numpy.shape(self.dataOut.data)) | |
57 | #print(self.dataOut.code) |
|
57 | #print(self.dataOut.code) | |
58 | #print(numpy.shape(self.dataOut.code)) |
|
58 | #print(numpy.shape(self.dataOut.code)) | |
59 | #exit(1) |
|
59 | #exit(1) | |
60 | #print(self.dataOut.CurrentBlock) |
|
60 | #print(self.dataOut.CurrentBlock) | |
61 | #print(self.dataOut.data[0,:,0]) |
|
61 | #print(self.dataOut.data[0,:,0]) | |
62 |
|
62 | |||
63 | #print(numpy.shape(self.dataOut.data)) |
|
63 | #print(numpy.shape(self.dataOut.data)) | |
64 | #print(self.dataOut.data[0,:,1666:1666+320]) |
|
64 | #print(self.dataOut.data[0,:,1666:1666+320]) | |
65 | #exit(1) |
|
65 | #exit(1) | |
66 |
|
66 | |||
67 | #print(self.dataOut.utctime) |
|
67 | #print(self.dataOut.utctime) | |
68 | #self.dataOut.test+=1 |
|
68 | #self.dataOut.test+=1 | |
69 |
|
69 | |||
70 |
|
70 | |||
71 | def __updateObjFromAmisrInput(self): |
|
71 | def __updateObjFromAmisrInput(self): | |
72 |
|
72 | |||
73 | self.dataOut.timeZone = self.dataIn.timeZone |
|
73 | self.dataOut.timeZone = self.dataIn.timeZone | |
74 | self.dataOut.dstFlag = self.dataIn.dstFlag |
|
74 | self.dataOut.dstFlag = self.dataIn.dstFlag | |
75 | self.dataOut.errorCount = self.dataIn.errorCount |
|
75 | self.dataOut.errorCount = self.dataIn.errorCount | |
76 | self.dataOut.useLocalTime = self.dataIn.useLocalTime |
|
76 | self.dataOut.useLocalTime = self.dataIn.useLocalTime | |
77 |
|
77 | |||
78 | self.dataOut.flagNoData = self.dataIn.flagNoData |
|
78 | self.dataOut.flagNoData = self.dataIn.flagNoData | |
79 | self.dataOut.data = self.dataIn.data |
|
79 | self.dataOut.data = self.dataIn.data | |
80 | self.dataOut.utctime = self.dataIn.utctime |
|
80 | self.dataOut.utctime = self.dataIn.utctime | |
81 | self.dataOut.channelList = self.dataIn.channelList |
|
81 | self.dataOut.channelList = self.dataIn.channelList | |
82 | # self.dataOut.timeInterval = self.dataIn.timeInterval |
|
82 | # self.dataOut.timeInterval = self.dataIn.timeInterval | |
83 | self.dataOut.heightList = self.dataIn.heightList |
|
83 | self.dataOut.heightList = self.dataIn.heightList | |
84 | self.dataOut.nProfiles = self.dataIn.nProfiles |
|
84 | self.dataOut.nProfiles = self.dataIn.nProfiles | |
85 |
|
85 | |||
86 | self.dataOut.nCohInt = self.dataIn.nCohInt |
|
86 | self.dataOut.nCohInt = self.dataIn.nCohInt | |
87 | self.dataOut.ippSeconds = self.dataIn.ippSeconds |
|
87 | self.dataOut.ippSeconds = self.dataIn.ippSeconds | |
88 | self.dataOut.frequency = self.dataIn.frequency |
|
88 | self.dataOut.frequency = self.dataIn.frequency | |
89 |
|
89 | |||
90 | self.dataOut.azimuth = self.dataIn.azimuth |
|
90 | self.dataOut.azimuth = self.dataIn.azimuth | |
91 | self.dataOut.zenith = self.dataIn.zenith |
|
91 | self.dataOut.zenith = self.dataIn.zenith | |
92 |
|
92 | |||
93 | self.dataOut.beam.codeList = self.dataIn.beam.codeList |
|
93 | self.dataOut.beam.codeList = self.dataIn.beam.codeList | |
94 | self.dataOut.beam.azimuthList = self.dataIn.beam.azimuthList |
|
94 | self.dataOut.beam.azimuthList = self.dataIn.beam.azimuthList | |
95 | self.dataOut.beam.zenithList = self.dataIn.beam.zenithList |
|
95 | self.dataOut.beam.zenithList = self.dataIn.beam.zenithList | |
96 |
|
96 | |||
97 | class selectChannels(Operation): |
|
97 | class selectChannels(Operation): | |
98 |
|
98 | |||
99 | def run(self, dataOut, channelList): |
|
99 | def run(self, dataOut, channelList): | |
100 |
|
100 | |||
101 |
|
101 | |||
102 |
|
102 | |||
103 |
|
103 | |||
104 | channelIndexList = [] |
|
104 | channelIndexList = [] | |
105 | self.dataOut = dataOut |
|
105 | self.dataOut = dataOut | |
106 | for channel in channelList: |
|
106 | for channel in channelList: | |
107 | if channel not in self.dataOut.channelList: |
|
107 | if channel not in self.dataOut.channelList: | |
108 | raise ValueError("Channel %d is not in %s" % (channel, str(self.dataOut.channelList))) |
|
108 | raise ValueError("Channel %d is not in %s" % (channel, str(self.dataOut.channelList))) | |
109 |
|
109 | |||
110 | index = self.dataOut.channelList.index(channel) |
|
110 | index = self.dataOut.channelList.index(channel) | |
111 | channelIndexList.append(index) |
|
111 | channelIndexList.append(index) | |
112 | self.selectChannelsByIndex(channelIndexList) |
|
112 | self.selectChannelsByIndex(channelIndexList) | |
113 |
|
113 | |||
114 | return self.dataOut |
|
114 | return self.dataOut | |
115 |
|
115 | |||
116 |
|
116 | |||
117 | def selectChannelsByIndex(self, channelIndexList): |
|
117 | def selectChannelsByIndex(self, channelIndexList): | |
118 | """ |
|
118 | """ | |
119 | Selecciona un bloque de datos en base a canales segun el channelIndexList |
|
119 | Selecciona un bloque de datos en base a canales segun el channelIndexList | |
120 |
|
120 | |||
121 | Input: |
|
121 | Input: | |
122 | channelIndexList : lista sencilla de canales a seleccionar por ej. [2,3,7] |
|
122 | channelIndexList : lista sencilla de canales a seleccionar por ej. [2,3,7] | |
123 |
|
123 | |||
124 | Affected: |
|
124 | Affected: | |
125 | self.dataOut.data |
|
125 | self.dataOut.data | |
126 | self.dataOut.channelIndexList |
|
126 | self.dataOut.channelIndexList | |
127 | self.dataOut.nChannels |
|
127 | self.dataOut.nChannels | |
128 | self.dataOut.m_ProcessingHeader.totalSpectra |
|
128 | self.dataOut.m_ProcessingHeader.totalSpectra | |
129 | self.dataOut.systemHeaderObj.numChannels |
|
129 | self.dataOut.systemHeaderObj.numChannels | |
130 | self.dataOut.m_ProcessingHeader.blockSize |
|
130 | self.dataOut.m_ProcessingHeader.blockSize | |
131 |
|
131 | |||
132 | Return: |
|
132 | Return: | |
133 | None |
|
133 | None | |
134 | """ |
|
134 | """ | |
135 |
|
135 | |||
136 | for channelIndex in channelIndexList: |
|
136 | for channelIndex in channelIndexList: | |
137 | if channelIndex not in self.dataOut.channelIndexList: |
|
137 | if channelIndex not in self.dataOut.channelIndexList: | |
138 | raise ValueError("The value %d in channelIndexList is not valid" % channelIndex) |
|
138 | raise ValueError("The value %d in channelIndexList is not valid" % channelIndex) | |
139 |
|
139 | |||
140 | if self.dataOut.type == 'Voltage': |
|
140 | if self.dataOut.type == 'Voltage': | |
141 | if self.dataOut.flagDataAsBlock: |
|
141 | if self.dataOut.flagDataAsBlock: | |
142 | """ |
|
142 | """ | |
143 | Si la data es obtenida por bloques, dimension = [nChannels, nProfiles, nHeis] |
|
143 | Si la data es obtenida por bloques, dimension = [nChannels, nProfiles, nHeis] | |
144 | """ |
|
144 | """ | |
145 | data = self.dataOut.data[channelIndexList, :, :] |
|
145 | data = self.dataOut.data[channelIndexList, :, :] | |
146 | else: |
|
146 | else: | |
147 | data = self.dataOut.data[channelIndexList, :] |
|
147 | data = self.dataOut.data[channelIndexList, :] | |
148 |
|
148 | |||
149 | self.dataOut.data = data |
|
149 | self.dataOut.data = data | |
150 | # self.dataOut.channelList = [self.dataOut.channelList[i] for i in channelIndexList] |
|
150 | # self.dataOut.channelList = [self.dataOut.channelList[i] for i in channelIndexList] | |
151 | self.dataOut.channelList = range(len(channelIndexList)) |
|
151 | self.dataOut.channelList = range(len(channelIndexList)) | |
152 |
|
152 | |||
153 | elif self.dataOut.type == 'Spectra': |
|
153 | elif self.dataOut.type == 'Spectra': | |
154 | data_spc = self.dataOut.data_spc[channelIndexList, :] |
|
154 | data_spc = self.dataOut.data_spc[channelIndexList, :] | |
155 | data_dc = self.dataOut.data_dc[channelIndexList, :] |
|
155 | data_dc = self.dataOut.data_dc[channelIndexList, :] | |
156 |
|
156 | |||
157 | self.dataOut.data_spc = data_spc |
|
157 | self.dataOut.data_spc = data_spc | |
158 | self.dataOut.data_dc = data_dc |
|
158 | self.dataOut.data_dc = data_dc | |
159 |
|
159 | |||
160 | # self.dataOut.channelList = [self.dataOut.channelList[i] for i in channelIndexList] |
|
160 | # self.dataOut.channelList = [self.dataOut.channelList[i] for i in channelIndexList] | |
161 | self.dataOut.channelList = range(len(channelIndexList)) |
|
161 | self.dataOut.channelList = range(len(channelIndexList)) | |
162 | self.__selectPairsByChannel(channelIndexList) |
|
162 | self.__selectPairsByChannel(channelIndexList) | |
163 |
|
163 | |||
164 | return 1 |
|
164 | return 1 | |
165 |
|
165 | |||
166 | def __selectPairsByChannel(self, channelList=None): |
|
166 | def __selectPairsByChannel(self, channelList=None): | |
167 |
|
167 | |||
168 | if channelList == None: |
|
168 | if channelList == None: | |
169 | return |
|
169 | return | |
170 |
|
170 | |||
171 | pairsIndexListSelected = [] |
|
171 | pairsIndexListSelected = [] | |
172 | for pairIndex in self.dataOut.pairsIndexList: |
|
172 | for pairIndex in self.dataOut.pairsIndexList: | |
173 | # First pair |
|
173 | # First pair | |
174 | if self.dataOut.pairsList[pairIndex][0] not in channelList: |
|
174 | if self.dataOut.pairsList[pairIndex][0] not in channelList: | |
175 | continue |
|
175 | continue | |
176 | # Second pair |
|
176 | # Second pair | |
177 | if self.dataOut.pairsList[pairIndex][1] not in channelList: |
|
177 | if self.dataOut.pairsList[pairIndex][1] not in channelList: | |
178 | continue |
|
178 | continue | |
179 |
|
179 | |||
180 | pairsIndexListSelected.append(pairIndex) |
|
180 | pairsIndexListSelected.append(pairIndex) | |
181 |
|
181 | |||
182 | if not pairsIndexListSelected: |
|
182 | if not pairsIndexListSelected: | |
183 | self.dataOut.data_cspc = None |
|
183 | self.dataOut.data_cspc = None | |
184 | self.dataOut.pairsList = [] |
|
184 | self.dataOut.pairsList = [] | |
185 | return |
|
185 | return | |
186 |
|
186 | |||
187 | self.dataOut.data_cspc = self.dataOut.data_cspc[pairsIndexListSelected] |
|
187 | self.dataOut.data_cspc = self.dataOut.data_cspc[pairsIndexListSelected] | |
188 | self.dataOut.pairsList = [self.dataOut.pairsList[i] |
|
188 | self.dataOut.pairsList = [self.dataOut.pairsList[i] | |
189 | for i in pairsIndexListSelected] |
|
189 | for i in pairsIndexListSelected] | |
190 |
|
190 | |||
191 | return |
|
191 | return | |
192 |
|
192 | |||
193 | class selectHeights(Operation): |
|
193 | class selectHeights(Operation): | |
194 |
|
194 | |||
195 | def run(self, dataOut, minHei=None, maxHei=None, minIndex=None, maxIndex=None): |
|
195 | def run(self, dataOut, minHei=None, maxHei=None, minIndex=None, maxIndex=None): | |
196 | """ |
|
196 | """ | |
197 | Selecciona un bloque de datos en base a un grupo de valores de alturas segun el rango |
|
197 | Selecciona un bloque de datos en base a un grupo de valores de alturas segun el rango | |
198 | minHei <= height <= maxHei |
|
198 | minHei <= height <= maxHei | |
199 |
|
199 | |||
200 | Input: |
|
200 | Input: | |
201 | minHei : valor minimo de altura a considerar |
|
201 | minHei : valor minimo de altura a considerar | |
202 | maxHei : valor maximo de altura a considerar |
|
202 | maxHei : valor maximo de altura a considerar | |
203 |
|
203 | |||
204 | Affected: |
|
204 | Affected: | |
205 | Indirectamente son cambiados varios valores a travez del metodo selectHeightsByIndex |
|
205 | Indirectamente son cambiados varios valores a travez del metodo selectHeightsByIndex | |
206 |
|
206 | |||
207 | Return: |
|
207 | Return: | |
208 | 1 si el metodo se ejecuto con exito caso contrario devuelve 0 |
|
208 | 1 si el metodo se ejecuto con exito caso contrario devuelve 0 | |
209 | """ |
|
209 | """ | |
210 |
|
210 | |||
211 | self.dataOut = dataOut |
|
211 | self.dataOut = dataOut | |
212 |
|
212 | |||
213 | #if minHei and maxHei: |
|
213 | #if minHei and maxHei: | |
214 | if 1: |
|
214 | if 1: | |
215 | if minHei == None: |
|
215 | if minHei == None: | |
216 | minHei = self.dataOut.heightList[0] |
|
216 | minHei = self.dataOut.heightList[0] | |
217 |
|
217 | |||
218 | if maxHei == None: |
|
218 | if maxHei == None: | |
219 | maxHei = self.dataOut.heightList[-1] |
|
219 | maxHei = self.dataOut.heightList[-1] | |
220 |
|
220 | |||
221 | if (minHei < self.dataOut.heightList[0]): |
|
221 | if (minHei < self.dataOut.heightList[0]): | |
222 | minHei = self.dataOut.heightList[0] |
|
222 | minHei = self.dataOut.heightList[0] | |
223 |
|
223 | |||
224 | if (maxHei > self.dataOut.heightList[-1]): |
|
224 | if (maxHei > self.dataOut.heightList[-1]): | |
225 | maxHei = self.dataOut.heightList[-1] |
|
225 | maxHei = self.dataOut.heightList[-1] | |
226 |
|
226 | |||
227 | minIndex = 0 |
|
227 | minIndex = 0 | |
228 | maxIndex = 0 |
|
228 | maxIndex = 0 | |
229 | heights = self.dataOut.heightList |
|
229 | heights = self.dataOut.heightList | |
230 |
|
230 | |||
231 | inda = numpy.where(heights >= minHei) |
|
231 | inda = numpy.where(heights >= minHei) | |
232 | indb = numpy.where(heights <= maxHei) |
|
232 | indb = numpy.where(heights <= maxHei) | |
233 |
|
233 | |||
234 | try: |
|
234 | try: | |
235 | minIndex = inda[0][0] |
|
235 | minIndex = inda[0][0] | |
236 | except: |
|
236 | except: | |
237 | minIndex = 0 |
|
237 | minIndex = 0 | |
238 |
|
238 | |||
239 | try: |
|
239 | try: | |
240 | maxIndex = indb[0][-1] |
|
240 | maxIndex = indb[0][-1] | |
241 | except: |
|
241 | except: | |
242 | maxIndex = len(heights) |
|
242 | maxIndex = len(heights) | |
243 |
|
243 | |||
244 | self.selectHeightsByIndex(minIndex, maxIndex) |
|
244 | self.selectHeightsByIndex(minIndex, maxIndex) | |
245 | #print(self.dataOut.nHeights) |
|
245 | #print(self.dataOut.nHeights) | |
246 |
|
246 | |||
247 |
|
247 | |||
248 | return self.dataOut |
|
248 | return self.dataOut | |
249 |
|
249 | |||
250 | def selectHeightsByIndex(self, minIndex, maxIndex): |
|
250 | def selectHeightsByIndex(self, minIndex, maxIndex): | |
251 | """ |
|
251 | """ | |
252 | Selecciona un bloque de datos en base a un grupo indices de alturas segun el rango |
|
252 | Selecciona un bloque de datos en base a un grupo indices de alturas segun el rango | |
253 | minIndex <= index <= maxIndex |
|
253 | minIndex <= index <= maxIndex | |
254 |
|
254 | |||
255 | Input: |
|
255 | Input: | |
256 | minIndex : valor de indice minimo de altura a considerar |
|
256 | minIndex : valor de indice minimo de altura a considerar | |
257 | maxIndex : valor de indice maximo de altura a considerar |
|
257 | maxIndex : valor de indice maximo de altura a considerar | |
258 |
|
258 | |||
259 | Affected: |
|
259 | Affected: | |
260 | self.dataOut.data |
|
260 | self.dataOut.data | |
261 | self.dataOut.heightList |
|
261 | self.dataOut.heightList | |
262 |
|
262 | |||
263 | Return: |
|
263 | Return: | |
264 | 1 si el metodo se ejecuto con exito caso contrario devuelve 0 |
|
264 | 1 si el metodo se ejecuto con exito caso contrario devuelve 0 | |
265 | """ |
|
265 | """ | |
266 |
|
266 | |||
267 | if self.dataOut.type == 'Voltage': |
|
267 | if self.dataOut.type == 'Voltage': | |
268 | if (minIndex < 0) or (minIndex > maxIndex): |
|
268 | if (minIndex < 0) or (minIndex > maxIndex): | |
269 | raise ValueError("Height index range (%d,%d) is not valid" % (minIndex, maxIndex)) |
|
269 | raise ValueError("Height index range (%d,%d) is not valid" % (minIndex, maxIndex)) | |
270 |
|
270 | |||
271 | if (maxIndex >= self.dataOut.nHeights): |
|
271 | if (maxIndex >= self.dataOut.nHeights): | |
272 | maxIndex = self.dataOut.nHeights |
|
272 | maxIndex = self.dataOut.nHeights | |
273 |
|
273 | |||
274 | # voltage |
|
274 | # voltage | |
275 | if self.dataOut.flagDataAsBlock: |
|
275 | if self.dataOut.flagDataAsBlock: | |
276 | """ |
|
276 | """ | |
277 | Si la data es obtenida por bloques, dimension = [nChannels, nProfiles, nHeis] |
|
277 | Si la data es obtenida por bloques, dimension = [nChannels, nProfiles, nHeis] | |
278 | """ |
|
278 | """ | |
279 | data = self.dataOut.data[:, :, minIndex:maxIndex] |
|
279 | data = self.dataOut.data[:, :, minIndex:maxIndex] | |
280 | else: |
|
280 | else: | |
281 | data = self.dataOut.data[:, minIndex:maxIndex] |
|
281 | data = self.dataOut.data[:, minIndex:maxIndex] | |
282 |
|
282 | |||
283 | # firstHeight = self.dataOut.heightList[minIndex] |
|
283 | # firstHeight = self.dataOut.heightList[minIndex] | |
284 |
|
284 | |||
285 | self.dataOut.data = data |
|
285 | self.dataOut.data = data | |
286 | self.dataOut.heightList = self.dataOut.heightList[minIndex:maxIndex] |
|
286 | self.dataOut.heightList = self.dataOut.heightList[minIndex:maxIndex] | |
287 |
|
287 | |||
288 | if self.dataOut.nHeights <= 1: |
|
288 | if self.dataOut.nHeights <= 1: | |
289 | raise ValueError("selectHeights: Too few heights. Current number of heights is %d" % (self.dataOut.nHeights)) |
|
289 | raise ValueError("selectHeights: Too few heights. Current number of heights is %d" % (self.dataOut.nHeights)) | |
290 | elif self.dataOut.type == 'Spectra': |
|
290 | elif self.dataOut.type == 'Spectra': | |
291 | if (minIndex < 0) or (minIndex > maxIndex): |
|
291 | if (minIndex < 0) or (minIndex > maxIndex): | |
292 | raise ValueError("Error selecting heights: Index range (%d,%d) is not valid" % ( |
|
292 | raise ValueError("Error selecting heights: Index range (%d,%d) is not valid" % ( | |
293 | minIndex, maxIndex)) |
|
293 | minIndex, maxIndex)) | |
294 |
|
294 | |||
295 | if (maxIndex >= self.dataOut.nHeights): |
|
295 | if (maxIndex >= self.dataOut.nHeights): | |
296 | maxIndex = self.dataOut.nHeights - 1 |
|
296 | maxIndex = self.dataOut.nHeights - 1 | |
297 |
|
297 | |||
298 | # Spectra |
|
298 | # Spectra | |
299 | data_spc = self.dataOut.data_spc[:, :, minIndex:maxIndex + 1] |
|
299 | data_spc = self.dataOut.data_spc[:, :, minIndex:maxIndex + 1] | |
300 |
|
300 | |||
301 | data_cspc = None |
|
301 | data_cspc = None | |
302 | if self.dataOut.data_cspc is not None: |
|
302 | if self.dataOut.data_cspc is not None: | |
303 | data_cspc = self.dataOut.data_cspc[:, :, minIndex:maxIndex + 1] |
|
303 | data_cspc = self.dataOut.data_cspc[:, :, minIndex:maxIndex + 1] | |
304 |
|
304 | |||
305 | data_dc = None |
|
305 | data_dc = None | |
306 | if self.dataOut.data_dc is not None: |
|
306 | if self.dataOut.data_dc is not None: | |
307 | data_dc = self.dataOut.data_dc[:, minIndex:maxIndex + 1] |
|
307 | data_dc = self.dataOut.data_dc[:, minIndex:maxIndex + 1] | |
308 |
|
308 | |||
309 | self.dataOut.data_spc = data_spc |
|
309 | self.dataOut.data_spc = data_spc | |
310 | self.dataOut.data_cspc = data_cspc |
|
310 | self.dataOut.data_cspc = data_cspc | |
311 | self.dataOut.data_dc = data_dc |
|
311 | self.dataOut.data_dc = data_dc | |
312 |
|
312 | |||
313 | self.dataOut.heightList = self.dataOut.heightList[minIndex:maxIndex + 1] |
|
313 | self.dataOut.heightList = self.dataOut.heightList[minIndex:maxIndex + 1] | |
314 |
|
314 | |||
315 | return 1 |
|
315 | return 1 | |
316 |
|
316 | |||
317 |
|
317 | |||
318 | class filterByHeights(Operation): |
|
318 | class filterByHeights(Operation): | |
319 |
|
319 | |||
320 | def run(self, dataOut, window): |
|
320 | def run(self, dataOut, window): | |
321 |
|
321 | |||
322 | deltaHeight = dataOut.heightList[1] - dataOut.heightList[0] |
|
322 | deltaHeight = dataOut.heightList[1] - dataOut.heightList[0] | |
323 |
|
323 | |||
324 | if window == None: |
|
324 | if window == None: | |
325 | window = (dataOut.radarControllerHeaderObj.txA / dataOut.radarControllerHeaderObj.nBaud) / deltaHeight |
|
325 | window = (dataOut.radarControllerHeaderObj.txA / dataOut.radarControllerHeaderObj.nBaud) / deltaHeight | |
326 |
|
326 | |||
327 | newdelta = deltaHeight * window |
|
327 | newdelta = deltaHeight * window | |
328 | r = dataOut.nHeights % window |
|
328 | r = dataOut.nHeights % window | |
329 | newheights = (dataOut.nHeights - r) / window |
|
329 | newheights = (dataOut.nHeights - r) / window | |
330 |
|
330 | |||
331 | if newheights <= 1: |
|
331 | if newheights <= 1: | |
332 | raise ValueError("filterByHeights: Too few heights. Current number of heights is %d and window is %d" % (dataOut.nHeights, window)) |
|
332 | raise ValueError("filterByHeights: Too few heights. Current number of heights is %d and window is %d" % (dataOut.nHeights, window)) | |
333 |
|
333 | |||
334 | if dataOut.flagDataAsBlock: |
|
334 | if dataOut.flagDataAsBlock: | |
335 | """ |
|
335 | """ | |
336 | Si la data es obtenida por bloques, dimension = [nChannels, nProfiles, nHeis] |
|
336 | Si la data es obtenida por bloques, dimension = [nChannels, nProfiles, nHeis] | |
337 | """ |
|
337 | """ | |
338 | buffer = dataOut.data[:, :, 0:int(dataOut.nHeights - r)] |
|
338 | buffer = dataOut.data[:, :, 0:int(dataOut.nHeights - r)] | |
339 | buffer = buffer.reshape(dataOut.nChannels, dataOut.nProfiles, int(dataOut.nHeights / window), window) |
|
339 | buffer = buffer.reshape(dataOut.nChannels, dataOut.nProfiles, int(dataOut.nHeights / window), window) | |
340 | buffer = numpy.sum(buffer, 3) |
|
340 | buffer = numpy.sum(buffer, 3) | |
341 |
|
341 | |||
342 | else: |
|
342 | else: | |
343 | buffer = dataOut.data[:, 0:int(dataOut.nHeights - r)] |
|
343 | buffer = dataOut.data[:, 0:int(dataOut.nHeights - r)] | |
344 | buffer = buffer.reshape(dataOut.nChannels, int(dataOut.nHeights / window), int(window)) |
|
344 | buffer = buffer.reshape(dataOut.nChannels, int(dataOut.nHeights / window), int(window)) | |
345 | buffer = numpy.sum(buffer, 2) |
|
345 | buffer = numpy.sum(buffer, 2) | |
346 |
|
346 | |||
347 | dataOut.data = buffer |
|
347 | dataOut.data = buffer | |
348 | dataOut.heightList = dataOut.heightList[0] + numpy.arange(newheights) * newdelta |
|
348 | dataOut.heightList = dataOut.heightList[0] + numpy.arange(newheights) * newdelta | |
349 | dataOut.windowOfFilter = window |
|
349 | dataOut.windowOfFilter = window | |
350 |
|
350 | |||
351 | return dataOut |
|
351 | return dataOut | |
352 |
|
352 | |||
353 | class setOffset(Operation): |
|
353 | class setOffset(Operation): | |
354 |
|
354 | |||
355 | def run(self, dataOut, offset=None): |
|
355 | def run(self, dataOut, offset=None): | |
356 |
|
356 | |||
357 | if not offset: |
|
357 | if not offset: | |
358 | offset = 0.0 |
|
358 | offset = 0.0 | |
359 |
|
359 | |||
360 | newHeiRange = dataOut.heightList - offset |
|
360 | newHeiRange = dataOut.heightList - offset | |
361 |
|
361 | |||
362 | dataOut.heightList = newHeiRange |
|
362 | dataOut.heightList = newHeiRange | |
363 |
|
363 | |||
364 | return dataOut |
|
364 | return dataOut | |
365 |
|
365 | |||
366 | class setH0(Operation): |
|
366 | class setH0(Operation): | |
367 |
|
367 | |||
368 | def run(self, dataOut, h0, deltaHeight=None): |
|
368 | def run(self, dataOut, h0, deltaHeight=None): | |
369 |
|
369 | |||
370 | if not deltaHeight: |
|
370 | if not deltaHeight: | |
371 | deltaHeight = dataOut.heightList[1] - dataOut.heightList[0] |
|
371 | deltaHeight = dataOut.heightList[1] - dataOut.heightList[0] | |
372 |
|
372 | |||
373 | nHeights = dataOut.nHeights |
|
373 | nHeights = dataOut.nHeights | |
374 |
|
374 | |||
375 | newHeiRange = h0 + numpy.arange(nHeights) * deltaHeight |
|
375 | newHeiRange = h0 + numpy.arange(nHeights) * deltaHeight | |
376 |
|
376 | |||
377 | dataOut.heightList = newHeiRange |
|
377 | dataOut.heightList = newHeiRange | |
378 |
|
378 | |||
379 | return dataOut |
|
379 | return dataOut | |
380 |
|
380 | |||
381 |
|
381 | |||
382 | class deFlip(Operation): |
|
382 | class deFlip(Operation): | |
383 | def __init__(self): |
|
383 | def __init__(self): | |
384 |
|
384 | |||
385 | self.flip = 1 |
|
385 | self.flip = 1 | |
386 |
|
386 | |||
387 | def run(self, dataOut, channelList=[]): |
|
387 | def run(self, dataOut, channelList=[]): | |
388 |
|
388 | |||
389 | data = dataOut.data.copy() |
|
389 | data = dataOut.data.copy() | |
390 | #print(dataOut.channelList) |
|
390 | #print(dataOut.channelList) | |
391 | #exit() |
|
391 | #exit() | |
392 |
|
392 | |||
393 | if channelList==1: #PARCHE |
|
393 | if channelList==1: #PARCHE | |
394 | channelList=[1] |
|
394 | channelList=[1] | |
395 |
|
395 | |||
396 |
|
396 | |||
397 | dataOut.FlipChannels=channelList |
|
397 | dataOut.FlipChannels=channelList | |
398 | if dataOut.flagDataAsBlock: |
|
398 | if dataOut.flagDataAsBlock: | |
399 | flip = self.flip |
|
399 | flip = self.flip | |
400 | profileList = list(range(dataOut.nProfiles)) |
|
400 | profileList = list(range(dataOut.nProfiles)) | |
401 |
|
401 | |||
402 | if not channelList: |
|
402 | if not channelList: | |
403 | for thisProfile in profileList: |
|
403 | for thisProfile in profileList: | |
404 | data[:, thisProfile, :] = data[:, thisProfile, :] * flip |
|
404 | data[:, thisProfile, :] = data[:, thisProfile, :] * flip | |
405 | flip *= -1.0 |
|
405 | flip *= -1.0 | |
406 | else: |
|
406 | else: | |
407 | for thisChannel in channelList: |
|
407 | for thisChannel in channelList: | |
408 | if thisChannel not in dataOut.channelList: |
|
408 | if thisChannel not in dataOut.channelList: | |
409 | continue |
|
409 | continue | |
410 |
|
410 | |||
411 | for thisProfile in profileList: |
|
411 | for thisProfile in profileList: | |
412 | data[thisChannel, thisProfile, :] = data[thisChannel, thisProfile, :] * flip |
|
412 | data[thisChannel, thisProfile, :] = data[thisChannel, thisProfile, :] * flip | |
413 | flip *= -1.0 |
|
413 | flip *= -1.0 | |
414 |
|
414 | |||
415 | self.flip = flip |
|
415 | self.flip = flip | |
416 |
|
416 | |||
417 | else: |
|
417 | else: | |
418 | if not channelList: |
|
418 | if not channelList: | |
419 | data[:, :] = data[:, :] * self.flip |
|
419 | data[:, :] = data[:, :] * self.flip | |
420 | else: |
|
420 | else: | |
421 | #channelList=[1] |
|
421 | #channelList=[1] | |
422 | #print(self.flip) |
|
422 | #print(self.flip) | |
423 | for thisChannel in channelList: |
|
423 | for thisChannel in channelList: | |
424 | if thisChannel not in dataOut.channelList: |
|
424 | if thisChannel not in dataOut.channelList: | |
425 | continue |
|
425 | continue | |
426 |
|
426 | |||
427 | data[thisChannel, :] = data[thisChannel, :] * self.flip |
|
427 | data[thisChannel, :] = data[thisChannel, :] * self.flip | |
428 |
|
428 | |||
429 | self.flip *= -1. |
|
429 | self.flip *= -1. | |
430 |
|
430 | |||
431 | dataOut.data = data |
|
431 | dataOut.data = data | |
432 |
|
432 | |||
433 | return dataOut |
|
433 | return dataOut | |
434 |
|
434 | |||
435 | class deFlipHP(Operation): |
|
435 | class deFlipHP(Operation): | |
436 | ''' |
|
436 | ''' | |
437 | Written by R. Flores |
|
437 | Written by R. Flores | |
438 | ''' |
|
438 | ''' | |
439 | def __init__(self): |
|
439 | def __init__(self): | |
440 |
|
440 | |||
441 | self.flip = 1 |
|
441 | self.flip = 1 | |
442 |
|
442 | |||
443 | def run(self, dataOut, byHeights = False, channelList = [], HeiRangeList = None): |
|
443 | def run(self, dataOut, byHeights = False, channelList = [], HeiRangeList = None): | |
444 |
|
444 | |||
445 | data = dataOut.data.copy() |
|
445 | data = dataOut.data.copy() | |
446 |
|
446 | |||
447 | firstHeight = HeiRangeList[0] |
|
447 | firstHeight = HeiRangeList[0] | |
448 | lastHeight = HeiRangeList[1]+1 |
|
448 | lastHeight = HeiRangeList[1]+1 | |
449 |
|
449 | |||
450 | #if channelList==1: #PARCHE #Lista de un solo canal produce error |
|
450 | #if channelList==1: #PARCHE #Lista de un solo canal produce error | |
451 | #channelList=[1] |
|
451 | #channelList=[1] | |
452 |
|
452 | |||
453 | dataOut.FlipChannels=channelList |
|
453 | dataOut.FlipChannels=channelList | |
454 | if dataOut.flagDataAsBlock: |
|
454 | if dataOut.flagDataAsBlock: | |
455 | flip = self.flip |
|
455 | flip = self.flip | |
456 | profileList = list(range(dataOut.nProfiles)) |
|
456 | profileList = list(range(dataOut.nProfiles)) | |
457 |
|
457 | |||
458 | if not channelList: |
|
458 | if not channelList: | |
459 | for thisProfile in profileList: |
|
459 | for thisProfile in profileList: | |
460 | data[:,thisProfile,:] = data[:,thisProfile,:]*flip |
|
460 | data[:,thisProfile,:] = data[:,thisProfile,:]*flip | |
461 | flip *= -1.0 |
|
461 | flip *= -1.0 | |
462 | else: |
|
462 | else: | |
463 | for thisChannel in channelList: |
|
463 | for thisChannel in channelList: | |
464 | if thisChannel not in dataOut.channelList: |
|
464 | if thisChannel not in dataOut.channelList: | |
465 | continue |
|
465 | continue | |
466 | if not byHeights: |
|
466 | if not byHeights: | |
467 | for thisProfile in profileList: |
|
467 | for thisProfile in profileList: | |
468 | data[thisChannel,thisProfile,:] = data[thisChannel,thisProfile,:]*flip |
|
468 | data[thisChannel,thisProfile,:] = data[thisChannel,thisProfile,:]*flip | |
469 | flip *= -1.0 |
|
469 | flip *= -1.0 | |
470 |
|
470 | |||
471 | else: |
|
471 | else: | |
472 | firstHeight = HeiRangeList[0] |
|
472 | firstHeight = HeiRangeList[0] | |
473 | lastHeight = HeiRangeList[1]+1 |
|
473 | lastHeight = HeiRangeList[1]+1 | |
474 | flip = -1.0 |
|
474 | flip = -1.0 | |
475 | data[thisChannel,:,firstHeight:lastHeight] = data[thisChannel,:,firstHeight:lastHeight]*flip |
|
475 | data[thisChannel,:,firstHeight:lastHeight] = data[thisChannel,:,firstHeight:lastHeight]*flip | |
476 |
|
476 | |||
477 |
|
477 | |||
478 | self.flip = flip |
|
478 | self.flip = flip | |
479 |
|
479 | |||
480 | else: |
|
480 | else: | |
481 | if not channelList: |
|
481 | if not channelList: | |
482 | data[:,:] = data[:,:]*self.flip |
|
482 | data[:,:] = data[:,:]*self.flip | |
483 | else: |
|
483 | else: | |
484 | #channelList=[1] |
|
484 | #channelList=[1] | |
485 |
|
485 | |||
486 | for thisChannel in channelList: |
|
486 | for thisChannel in channelList: | |
487 | if thisChannel not in dataOut.channelList: |
|
487 | if thisChannel not in dataOut.channelList: | |
488 | continue |
|
488 | continue | |
489 |
|
489 | |||
490 | if not byHeights: |
|
490 | if not byHeights: | |
491 | data[thisChannel,:] = data[thisChannel,:]*flip |
|
491 | data[thisChannel,:] = data[thisChannel,:]*flip | |
492 |
|
492 | |||
493 | else: |
|
493 | else: | |
494 | firstHeight = HeiRangeList[0] |
|
494 | firstHeight = HeiRangeList[0] | |
495 | lastHeight = HeiRangeList[1]+1 |
|
495 | lastHeight = HeiRangeList[1]+1 | |
496 | flip = -1.0 |
|
496 | flip = -1.0 | |
497 | data[thisChannel,firstHeight:lastHeight] = data[thisChannel,firstHeight:lastHeight]*flip |
|
497 | data[thisChannel,firstHeight:lastHeight] = data[thisChannel,firstHeight:lastHeight]*flip | |
498 |
|
498 | |||
499 | #data[thisChannel,:] = data[thisChannel,:]*self.flip |
|
499 | #data[thisChannel,:] = data[thisChannel,:]*self.flip | |
500 |
|
500 | |||
501 | self.flip *= -1. |
|
501 | self.flip *= -1. | |
502 |
|
502 | |||
503 | #print(dataOut.data[0,:12,1066+2]) |
|
503 | #print(dataOut.data[0,:12,1066+2]) | |
504 | #print(dataOut.data[1,:12,1066+2]) |
|
504 | #print(dataOut.data[1,:12,1066+2]) | |
505 | dataOut.data =data |
|
505 | dataOut.data =data | |
506 | #print(dataOut.data[0,:12,1066+2]) |
|
506 | #print(dataOut.data[0,:12,1066+2]) | |
507 | #print(dataOut.data[1,:12,1066+2]) |
|
507 | #print(dataOut.data[1,:12,1066+2]) | |
508 | #exit(1) |
|
508 | #exit(1) | |
509 |
|
509 | |||
510 | return dataOut |
|
510 | return dataOut | |
511 |
|
511 | |||
512 | class setAttribute(Operation): |
|
512 | class setAttribute(Operation): | |
513 | ''' |
|
513 | ''' | |
514 | Set an arbitrary attribute(s) to dataOut |
|
514 | Set an arbitrary attribute(s) to dataOut | |
515 | ''' |
|
515 | ''' | |
516 |
|
516 | |||
517 | def __init__(self): |
|
517 | def __init__(self): | |
518 |
|
518 | |||
519 | Operation.__init__(self) |
|
519 | Operation.__init__(self) | |
520 | self._ready = False |
|
520 | self._ready = False | |
521 |
|
521 | |||
522 | def run(self, dataOut, **kwargs): |
|
522 | def run(self, dataOut, **kwargs): | |
523 |
|
523 | |||
524 | for key, value in kwargs.items(): |
|
524 | for key, value in kwargs.items(): | |
525 | setattr(dataOut, key, value) |
|
525 | setattr(dataOut, key, value) | |
526 |
|
526 | |||
527 | return dataOut |
|
527 | return dataOut | |
528 |
|
528 | |||
529 |
|
529 | |||
530 | @MPDecorator |
|
530 | @MPDecorator | |
531 | class printAttribute(Operation): |
|
531 | class printAttribute(Operation): | |
532 | ''' |
|
532 | ''' | |
533 | Print an arbitrary attribute of dataOut |
|
533 | Print an arbitrary attribute of dataOut | |
534 | ''' |
|
534 | ''' | |
535 |
|
535 | |||
536 | def __init__(self): |
|
536 | def __init__(self): | |
537 |
|
537 | |||
538 | Operation.__init__(self) |
|
538 | Operation.__init__(self) | |
539 |
|
539 | |||
540 | def run(self, dataOut, attributes): |
|
540 | def run(self, dataOut, attributes): | |
541 |
|
541 | |||
542 | if isinstance(attributes, str): |
|
542 | if isinstance(attributes, str): | |
543 | attributes = [attributes] |
|
543 | attributes = [attributes] | |
544 | for attr in attributes: |
|
544 | for attr in attributes: | |
545 | if hasattr(dataOut, attr): |
|
545 | if hasattr(dataOut, attr): | |
546 | log.log(getattr(dataOut, attr), attr) |
|
546 | log.log(getattr(dataOut, attr), attr) | |
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 LagsReshape(Operation): |
|
571 | class LagsReshape(Operation): | |
572 | ''' |
|
572 | ''' | |
573 | Written by R. Flores |
|
573 | Written by R. Flores | |
574 | ''' |
|
574 | ''' | |
575 | """Operation to reshape input data into (Channels,Profiles(with same lag),Heights,Lags) and heights reconstruction. |
|
575 | """Operation to reshape input data into (Channels,Profiles(with same lag),Heights,Lags) and heights reconstruction. | |
576 |
|
576 | |||
577 | Parameters: |
|
577 | Parameters: | |
578 | ----------- |
|
578 | ----------- | |
579 |
|
579 | |||
580 |
|
580 | |||
581 | Example |
|
581 | Example | |
582 | -------- |
|
582 | -------- | |
583 |
|
583 | |||
584 | op = proc_unit.addOperation(name='LagsReshape') |
|
584 | op = proc_unit.addOperation(name='LagsReshape') | |
585 |
|
585 | |||
586 |
|
586 | |||
587 | """ |
|
587 | """ | |
588 |
|
588 | |||
589 | def __init__(self, **kwargs): |
|
589 | def __init__(self, **kwargs): | |
590 |
|
590 | |||
591 | Operation.__init__(self, **kwargs) |
|
591 | Operation.__init__(self, **kwargs) | |
592 |
|
592 | |||
593 | self.buffer=None |
|
593 | self.buffer=None | |
594 | self.buffer_HR=None |
|
594 | self.buffer_HR=None | |
595 | self.buffer_HRonelag=None |
|
595 | self.buffer_HRonelag=None | |
596 |
|
596 | |||
597 | def LagDistribution(self,dataOut): |
|
597 | def LagDistribution(self,dataOut): | |
598 |
|
598 | |||
599 | dataOut.datapure=numpy.copy(dataOut.data[:,0:dataOut.NSCAN,:]) |
|
599 | dataOut.datapure=numpy.copy(dataOut.data[:,0:dataOut.NSCAN,:]) | |
600 | self.buffer = numpy.zeros((dataOut.nChannels, |
|
600 | self.buffer = numpy.zeros((dataOut.nChannels, | |
601 | int(dataOut.NSCAN/dataOut.DPL), |
|
601 | int(dataOut.NSCAN/dataOut.DPL), | |
602 | dataOut.nHeights,dataOut.DPL), |
|
602 | dataOut.nHeights,dataOut.DPL), | |
603 | dtype='complex') |
|
603 | dtype='complex') | |
604 |
|
604 | |||
605 | for j in range(int(self.buffer.shape[1]/2)): |
|
605 | for j in range(int(self.buffer.shape[1]/2)): | |
606 | for i in range(dataOut.DPL): |
|
606 | for i in range(dataOut.DPL): | |
607 | if j+1==int(self.buffer.shape[1]/2) and i+1==dataOut.DPL: |
|
607 | if j+1==int(self.buffer.shape[1]/2) and i+1==dataOut.DPL: | |
608 | self.buffer[:,2*j:,:,i]=dataOut.datapure[:,2*i+int(2*j*dataOut.DPL):,:] |
|
608 | self.buffer[:,2*j:,:,i]=dataOut.datapure[:,2*i+int(2*j*dataOut.DPL):,:] | |
609 | else: |
|
609 | else: | |
610 | self.buffer[:,2*j:2*(j+1),:,i]=dataOut.datapure[:,2*i+int(2*j*dataOut.DPL):2*(i+1)+int(2*j*dataOut.DPL),:] |
|
610 | self.buffer[:,2*j:2*(j+1),:,i]=dataOut.datapure[:,2*i+int(2*j*dataOut.DPL):2*(i+1)+int(2*j*dataOut.DPL),:] | |
611 |
|
611 | |||
612 | return self.buffer |
|
612 | return self.buffer | |
613 |
|
613 | |||
614 | def HeightReconstruction(self,dataOut): |
|
614 | def HeightReconstruction(self,dataOut): | |
615 |
|
615 | |||
616 | self.buffer_HR = numpy.zeros((int(dataOut.NSCAN/dataOut.DPL), |
|
616 | self.buffer_HR = numpy.zeros((int(dataOut.NSCAN/dataOut.DPL), | |
617 | dataOut.nHeights,dataOut.DPL), |
|
617 | dataOut.nHeights,dataOut.DPL), | |
618 | dtype='complex') |
|
618 | dtype='complex') | |
619 |
|
619 | |||
620 | for i in range(int(dataOut.DPL)): #Only channel B |
|
620 | for i in range(int(dataOut.DPL)): #Only channel B | |
621 | if i==0: |
|
621 | if i==0: | |
622 | self.buffer_HR[:,:,i]=dataOut.datalags[1,:,:,i] |
|
622 | self.buffer_HR[:,:,i]=dataOut.datalags[1,:,:,i] | |
623 | else: |
|
623 | else: | |
624 | self.buffer_HR[:,:,i]=self.HRonelag(dataOut,i) |
|
624 | self.buffer_HR[:,:,i]=self.HRonelag(dataOut,i) | |
625 |
|
625 | |||
626 | return self.buffer_HR |
|
626 | return self.buffer_HR | |
627 |
|
627 | |||
628 |
|
628 | |||
629 | def HRonelag(self,dataOut,whichlag): |
|
629 | def HRonelag(self,dataOut,whichlag): | |
630 | self.buffer_HRonelag = numpy.zeros((int(dataOut.NSCAN/dataOut.DPL), |
|
630 | self.buffer_HRonelag = numpy.zeros((int(dataOut.NSCAN/dataOut.DPL), | |
631 | dataOut.nHeights), |
|
631 | dataOut.nHeights), | |
632 | dtype='complex') |
|
632 | dtype='complex') | |
633 |
|
633 | |||
634 | for i in range(self.buffer_HRonelag.shape[0]): |
|
634 | for i in range(self.buffer_HRonelag.shape[0]): | |
635 | for j in range(dataOut.nHeights): |
|
635 | for j in range(dataOut.nHeights): | |
636 | if j+int(2*whichlag)<dataOut.nHeights: |
|
636 | if j+int(2*whichlag)<dataOut.nHeights: | |
637 | self.buffer_HRonelag[i,j]=dataOut.datalags[1,i,j+2*whichlag,whichlag] |
|
637 | self.buffer_HRonelag[i,j]=dataOut.datalags[1,i,j+2*whichlag,whichlag] | |
638 | else: |
|
638 | else: | |
639 | if whichlag!=10: |
|
639 | if whichlag!=10: | |
640 | self.buffer_HRonelag[i,j]=dataOut.datalags[1,i,(j+2*whichlag)%dataOut.nHeights,whichlag+1] |
|
640 | self.buffer_HRonelag[i,j]=dataOut.datalags[1,i,(j+2*whichlag)%dataOut.nHeights,whichlag+1] | |
641 | else: |
|
641 | else: | |
642 | if i+2<self.buffer_HRonelag.shape[0]: |
|
642 | if i+2<self.buffer_HRonelag.shape[0]: | |
643 | self.buffer_HRonelag[i,j]=dataOut.datalags[1,i+2,(j+2*whichlag)%dataOut.nHeights,0] |
|
643 | self.buffer_HRonelag[i,j]=dataOut.datalags[1,i+2,(j+2*whichlag)%dataOut.nHeights,0] | |
644 | else: #i+1==self.buffer_HRonelag.shape[0]: |
|
644 | else: #i+1==self.buffer_HRonelag.shape[0]: | |
645 | self.buffer_HRonelag[i,j]=dataOut.datalags[1,i,(j+2*whichlag)%dataOut.nHeights,whichlag] |
|
645 | self.buffer_HRonelag[i,j]=dataOut.datalags[1,i,(j+2*whichlag)%dataOut.nHeights,whichlag] | |
646 |
|
646 | |||
647 | return self.buffer_HRonelag |
|
647 | return self.buffer_HRonelag | |
648 |
|
648 | |||
649 |
|
649 | |||
650 |
|
650 | |||
651 | def run(self,dataOut,DPL=11,NSCAN=132): |
|
651 | def run(self,dataOut,DPL=11,NSCAN=132): | |
652 |
|
652 | |||
653 | dataOut.DPL=DPL |
|
653 | dataOut.DPL=DPL | |
654 | dataOut.NSCAN=NSCAN |
|
654 | dataOut.NSCAN=NSCAN | |
655 | dataOut.paramInterval=0#int(dataOut.nint*dataOut.header[7][0]*2 ) |
|
655 | dataOut.paramInterval=0#int(dataOut.nint*dataOut.header[7][0]*2 ) | |
656 | dataOut.lat=-11.95 |
|
656 | dataOut.lat=-11.95 | |
657 | dataOut.lon=-76.87 |
|
657 | dataOut.lon=-76.87 | |
658 | dataOut.datalags=None |
|
658 | dataOut.datalags=None | |
659 |
|
659 | |||
660 | dataOut.datalags=numpy.copy(self.LagDistribution(dataOut)) |
|
660 | dataOut.datalags=numpy.copy(self.LagDistribution(dataOut)) | |
661 | dataOut.datalags[1,:,:,:]=self.HeightReconstruction(dataOut) |
|
661 | dataOut.datalags[1,:,:,:]=self.HeightReconstruction(dataOut) | |
662 |
|
662 | |||
663 | return dataOut |
|
663 | return dataOut | |
664 |
|
664 | |||
665 | class LagsReshapeHP(Operation): |
|
665 | class LagsReshapeHP(Operation): | |
666 | ''' |
|
666 | ''' | |
667 | Written by R. Flores |
|
667 | Written by R. Flores | |
668 | ''' |
|
668 | ''' | |
669 | """Operation to reshape input data into (Channels,Profiles(with same lag),Heights,Lags) and heights reconstruction. |
|
669 | """Operation to reshape input data into (Channels,Profiles(with same lag),Heights,Lags) and heights reconstruction. | |
670 |
|
670 | |||
671 | Parameters: |
|
671 | Parameters: | |
672 | ----------- |
|
672 | ----------- | |
673 |
|
673 | |||
674 |
|
674 | |||
675 | Example |
|
675 | Example | |
676 | -------- |
|
676 | -------- | |
677 |
|
677 | |||
678 | op = proc_unit.addOperation(name='LagsReshape') |
|
678 | op = proc_unit.addOperation(name='LagsReshape') | |
679 |
|
679 | |||
680 |
|
680 | |||
681 | """ |
|
681 | """ | |
682 |
|
682 | |||
683 | def __init__(self, **kwargs): |
|
683 | def __init__(self, **kwargs): | |
684 |
|
684 | |||
685 | Operation.__init__(self, **kwargs) |
|
685 | Operation.__init__(self, **kwargs) | |
686 |
|
686 | |||
687 | self.buffer=None |
|
687 | self.buffer=None | |
688 | self.buffer_HR=None |
|
688 | self.buffer_HR=None | |
689 | self.buffer_HRonelag=None |
|
689 | self.buffer_HRonelag=None | |
690 |
|
690 | |||
691 | def LagDistribution(self,dataOut): |
|
691 | def LagDistribution(self,dataOut): | |
692 |
|
692 | |||
693 | dataOut.datapure=numpy.copy(dataOut.data[:,0:dataOut.NSCAN,:]) |
|
693 | dataOut.datapure=numpy.copy(dataOut.data[:,0:dataOut.NSCAN,:]) | |
694 | self.buffer = numpy.zeros((dataOut.nChannels, |
|
694 | self.buffer = numpy.zeros((dataOut.nChannels, | |
695 | int(dataOut.NSCAN/dataOut.DPL), |
|
695 | int(dataOut.NSCAN/dataOut.DPL), | |
696 | dataOut.nHeights,dataOut.DPL), |
|
696 | dataOut.nHeights,dataOut.DPL), | |
697 | dtype='complex') |
|
697 | dtype='complex') | |
698 |
|
698 | |||
699 | for j in range(int(self.buffer.shape[1]/2)): |
|
699 | for j in range(int(self.buffer.shape[1]/2)): | |
700 | for i in range(dataOut.DPL): |
|
700 | for i in range(dataOut.DPL): | |
701 | if j+1==int(self.buffer.shape[1]/2) and i+1==dataOut.DPL: |
|
701 | if j+1==int(self.buffer.shape[1]/2) and i+1==dataOut.DPL: | |
702 | self.buffer[:,2*j:,:,i]=dataOut.datapure[:,2*i+int(2*j*dataOut.DPL):,:] |
|
702 | self.buffer[:,2*j:,:,i]=dataOut.datapure[:,2*i+int(2*j*dataOut.DPL):,:] | |
703 | else: |
|
703 | else: | |
704 | self.buffer[:,2*j:2*(j+1),:,i]=dataOut.datapure[:,2*i+int(2*j*dataOut.DPL):2*(i+1)+int(2*j*dataOut.DPL),:] |
|
704 | self.buffer[:,2*j:2*(j+1),:,i]=dataOut.datapure[:,2*i+int(2*j*dataOut.DPL):2*(i+1)+int(2*j*dataOut.DPL),:] | |
705 |
|
705 | |||
706 | return self.buffer |
|
706 | return self.buffer | |
707 |
|
707 | |||
708 | def HeightReconstruction(self,dataOut): |
|
708 | def HeightReconstruction(self,dataOut): | |
709 |
|
709 | |||
710 | self.buffer_HR = numpy.zeros((int(dataOut.NSCAN/dataOut.DPL), |
|
710 | self.buffer_HR = numpy.zeros((int(dataOut.NSCAN/dataOut.DPL), | |
711 | dataOut.nHeights,dataOut.DPL), |
|
711 | dataOut.nHeights,dataOut.DPL), | |
712 | dtype='complex') |
|
712 | dtype='complex') | |
713 |
|
713 | |||
714 | for i in range(int(dataOut.DPL)): #Only channel B |
|
714 | for i in range(int(dataOut.DPL)): #Only channel B | |
715 | if i==0: |
|
715 | if i==0: | |
716 | self.buffer_HR[:,:,i]=dataOut.datalags[1,:,:,i] |
|
716 | self.buffer_HR[:,:,i]=dataOut.datalags[1,:,:,i] | |
717 | else: |
|
717 | else: | |
718 | self.buffer_HR[:,:,i]=self.HRonelag(dataOut,i) |
|
718 | self.buffer_HR[:,:,i]=self.HRonelag(dataOut,i) | |
719 |
|
719 | |||
720 | return self.buffer_HR |
|
720 | return self.buffer_HR | |
721 |
|
721 | |||
722 |
|
722 | |||
723 | def HRonelag(self,dataOut,whichlag): |
|
723 | def HRonelag(self,dataOut,whichlag): | |
724 | self.buffer_HRonelag = numpy.zeros((int(dataOut.NSCAN/dataOut.DPL), |
|
724 | self.buffer_HRonelag = numpy.zeros((int(dataOut.NSCAN/dataOut.DPL), | |
725 | dataOut.nHeights), |
|
725 | dataOut.nHeights), | |
726 | dtype='complex') |
|
726 | dtype='complex') | |
727 |
|
727 | |||
728 | for i in range(self.buffer_HRonelag.shape[0]): |
|
728 | for i in range(self.buffer_HRonelag.shape[0]): | |
729 | for j in range(dataOut.nHeights): |
|
729 | for j in range(dataOut.nHeights): | |
730 | if j+int(2*whichlag)<dataOut.nHeights: |
|
730 | if j+int(2*whichlag)<dataOut.nHeights: | |
731 | self.buffer_HRonelag[i,j]=dataOut.datalags[1,i,j+2*whichlag,whichlag] |
|
731 | self.buffer_HRonelag[i,j]=dataOut.datalags[1,i,j+2*whichlag,whichlag] | |
732 | else: |
|
732 | else: | |
733 | if whichlag!=10: |
|
733 | if whichlag!=10: | |
734 | self.buffer_HRonelag[i,j]=dataOut.datalags[1,i,(j+2*whichlag)%dataOut.nHeights,whichlag+1] |
|
734 | self.buffer_HRonelag[i,j]=dataOut.datalags[1,i,(j+2*whichlag)%dataOut.nHeights,whichlag+1] | |
735 | else: |
|
735 | else: | |
736 | if i+2<self.buffer_HRonelag.shape[0]: |
|
736 | if i+2<self.buffer_HRonelag.shape[0]: | |
737 | self.buffer_HRonelag[i,j]=dataOut.datalags[1,i+2,(j+2*whichlag)%dataOut.nHeights,0] |
|
737 | self.buffer_HRonelag[i,j]=dataOut.datalags[1,i+2,(j+2*whichlag)%dataOut.nHeights,0] | |
738 | else: #i+1==self.buffer_HRonelag.shape[0]: |
|
738 | else: #i+1==self.buffer_HRonelag.shape[0]: | |
739 | self.buffer_HRonelag[i,j]=dataOut.datalags[1,i,(j+2*whichlag)%dataOut.nHeights,whichlag] |
|
739 | self.buffer_HRonelag[i,j]=dataOut.datalags[1,i,(j+2*whichlag)%dataOut.nHeights,whichlag] | |
740 |
|
740 | |||
741 | return self.buffer_HRonelag |
|
741 | return self.buffer_HRonelag | |
742 |
|
742 | |||
743 |
|
743 | |||
744 |
|
744 | |||
745 | def run(self,dataOut,DPL=11,NSCAN=132): |
|
745 | def run(self,dataOut,DPL=11,NSCAN=132): | |
746 |
|
746 | |||
747 | dataOut.DPL=DPL |
|
747 | dataOut.DPL=DPL | |
748 | dataOut.NSCAN=NSCAN |
|
748 | dataOut.NSCAN=NSCAN | |
749 | dataOut.paramInterval=0#int(dataOut.nint*dataOut.header[7][0]*2 ) |
|
749 | dataOut.paramInterval=0#int(dataOut.nint*dataOut.header[7][0]*2 ) | |
750 | dataOut.lat=-11.95 |
|
750 | dataOut.lat=-11.95 | |
751 | dataOut.lon=-76.87 |
|
751 | dataOut.lon=-76.87 | |
752 | dataOut.datalags=None |
|
752 | dataOut.datalags=None | |
753 |
|
753 | |||
754 | dataOut.datalags=numpy.copy(self.LagDistribution(dataOut)) |
|
754 | dataOut.datalags=numpy.copy(self.LagDistribution(dataOut)) | |
755 | dataOut.datalags[1,:,:,:]=self.HeightReconstruction(dataOut) |
|
755 | dataOut.datalags[1,:,:,:]=self.HeightReconstruction(dataOut) | |
756 |
|
756 | |||
757 | return dataOut |
|
757 | return dataOut | |
758 |
|
758 | |||
759 | class LagsReshapeDP_V2(Operation): |
|
759 | class LagsReshapeDP_V2(Operation): | |
760 | ''' |
|
760 | ''' | |
761 | Written by R. Flores |
|
761 | Written by R. Flores | |
762 | ''' |
|
762 | ''' | |
763 | """Operation to reshape input data into (Channels,Profiles(with same lag),Heights,Lags) and heights reconstruction. |
|
763 | """Operation to reshape input data into (Channels,Profiles(with same lag),Heights,Lags) and heights reconstruction. | |
764 |
|
764 | |||
765 | Parameters: |
|
765 | Parameters: | |
766 | ----------- |
|
766 | ----------- | |
767 |
|
767 | |||
768 |
|
768 | |||
769 | Example |
|
769 | Example | |
770 | -------- |
|
770 | -------- | |
771 |
|
771 | |||
772 | op = proc_unit.addOperation(name='LagsReshape') |
|
772 | op = proc_unit.addOperation(name='LagsReshape') | |
773 |
|
773 | |||
774 |
|
774 | |||
775 | """ |
|
775 | """ | |
776 |
|
776 | |||
777 | def __init__(self, **kwargs): |
|
777 | def __init__(self, **kwargs): | |
778 |
|
778 | |||
779 | Operation.__init__(self, **kwargs) |
|
779 | Operation.__init__(self, **kwargs) | |
780 |
|
780 | |||
781 | self.buffer=None |
|
781 | self.buffer=None | |
782 | self.data_buffer = [] |
|
782 | self.data_buffer = [] | |
783 |
|
783 | |||
784 | def setup(self,dataOut,DPL,NSCAN,NLAG,NRANGE,lagind,lagfirst): |
|
784 | def setup(self,dataOut,DPL,NSCAN,NLAG,NRANGE,lagind,lagfirst): | |
785 | dataOut.DPL=DPL |
|
785 | dataOut.DPL=DPL | |
786 | dataOut.NSCAN=NSCAN |
|
786 | dataOut.NSCAN=NSCAN | |
787 | dataOut.NLAG = NLAG |
|
787 | dataOut.NLAG = NLAG | |
788 | deltaHeight = dataOut.heightList[1] - dataOut.heightList[0] |
|
788 | deltaHeight = dataOut.heightList[1] - dataOut.heightList[0] | |
789 | dataOut.NRANGE = NRANGE |
|
789 | dataOut.NRANGE = NRANGE | |
790 | dataOut.read_samples=int(dataOut.nHeights) |
|
790 | dataOut.read_samples=int(dataOut.nHeights) | |
791 | #print(dataOut.read_samples) |
|
791 | #print(dataOut.read_samples) | |
792 | #print(dataOut.nHeights) |
|
792 | #print(dataOut.nHeights) | |
793 | #exit(1) |
|
793 | #exit(1) | |
794 | dataOut.NDP = dataOut.NDT = int((dataOut.nHeights-dataOut.NRANGE)/2) |
|
794 | dataOut.NDP = dataOut.NDT = int((dataOut.nHeights-dataOut.NRANGE)/2) | |
795 | dataOut.heightList = numpy.arange(dataOut.NDP) *deltaHeight# + dataOut.heightList[0] |
|
795 | dataOut.heightList = numpy.arange(dataOut.NDP) *deltaHeight# + dataOut.heightList[0] | |
796 | #dataOut.NDP = dataOut.NDT = int(dataOut.nHeights/2)#int((dataOut.nHeights-dataOut.NRANGE)/2) |
|
796 | #dataOut.NDP = dataOut.NDT = int(dataOut.nHeights/2)#int((dataOut.nHeights-dataOut.NRANGE)/2) | |
797 | #print(dataOut.NDP) |
|
797 | #print(dataOut.NDP) | |
798 | #print(dataOut.heightList) |
|
798 | #print(dataOut.heightList) | |
799 | dataOut.paramInterval=0#int(dataOut.nint*dataOut.header[7][0]*2 ) |
|
799 | dataOut.paramInterval=0#int(dataOut.nint*dataOut.header[7][0]*2 ) | |
800 | dataOut.lat=-11.95 |
|
800 | dataOut.lat=-11.95 | |
801 | dataOut.lon=-76.87 |
|
801 | dataOut.lon=-76.87 | |
802 | dataOut.datalags=None |
|
802 | dataOut.datalags=None | |
803 | dataOut.lagind=lagind |
|
803 | dataOut.lagind=lagind | |
804 | dataOut.lagfirst=lagfirst |
|
804 | dataOut.lagfirst=lagfirst | |
805 |
|
805 | |||
806 |
|
806 | |||
807 | def LagDistribution(self,dataOut): |
|
807 | def LagDistribution(self,dataOut): | |
808 |
|
808 | |||
809 | self.buffer = numpy.zeros((dataOut.nChannels, |
|
809 | self.buffer = numpy.zeros((dataOut.nChannels, | |
810 | int(2*2*dataOut.NSCAN/dataOut.NLAG), |
|
810 | int(2*2*dataOut.NSCAN/dataOut.NLAG), | |
811 | dataOut.NDP,dataOut.DPL), |
|
811 | dataOut.NDP,dataOut.DPL), | |
812 | dtype='complex') |
|
812 | dtype='complex') | |
813 |
|
813 | |||
814 | indProfile = numpy.arange(0,dataOut.NSCAN,1)//8 |
|
814 | indProfile = numpy.arange(0,dataOut.NSCAN,1)//8 | |
815 |
|
815 | |||
816 | #dataOut.nNoiseProfiles = dataOut.nProfiles-dataOut.NSCAN |
|
816 | #dataOut.nNoiseProfiles = dataOut.nProfiles-dataOut.NSCAN | |
817 |
|
817 | |||
818 | for i in range(2): |
|
818 | for i in range(2): | |
819 | if i==0: |
|
819 | if i==0: | |
820 | aux = 0 |
|
820 | aux = 0 | |
821 | else: |
|
821 | else: | |
822 | aux =16 |
|
822 | aux =16 | |
823 | for j in range(dataOut.NDP): |
|
823 | for j in range(dataOut.NDP): | |
824 | for k in range(int(dataOut.NSCAN)): |
|
824 | for k in range(int(dataOut.NSCAN)): | |
825 |
|
825 | |||
826 | n=dataOut.lagind[k%dataOut.NLAG] |
|
826 | n=dataOut.lagind[k%dataOut.NLAG] | |
827 |
|
827 | |||
828 | data_ChA=dataOut.data[0,k,dataOut.NRANGE+j+i*dataOut.NDT]#-dataOut.dc[0] |
|
828 | data_ChA=dataOut.data[0,k,dataOut.NRANGE+j+i*dataOut.NDT]#-dataOut.dc[0] | |
829 |
|
829 | |||
830 | if dataOut.NRANGE+j+i*dataOut.NDT+2*n<dataOut.read_samples: |
|
830 | if dataOut.NRANGE+j+i*dataOut.NDT+2*n<dataOut.read_samples: | |
831 |
|
831 | |||
832 | data_ChB=dataOut.data[1,k,dataOut.NRANGE+j+i*dataOut.NDT+2*n]#-dataOut.dc[1] |
|
832 | data_ChB=dataOut.data[1,k,dataOut.NRANGE+j+i*dataOut.NDT+2*n]#-dataOut.dc[1] | |
833 | #print(data_ChB) |
|
833 | #print(data_ChB) | |
834 | #exit(1) |
|
834 | #exit(1) | |
835 | #print("*1*") |
|
835 | #print("*1*") | |
836 |
|
836 | |||
837 | else: |
|
837 | else: | |
838 | #print(i,j,n) |
|
838 | #print(i,j,n) | |
839 | #exit(1) |
|
839 | #exit(1) | |
840 |
|
840 | |||
841 | if k+1<int(dataOut.NSCAN): |
|
841 | if k+1<int(dataOut.NSCAN): | |
842 | data_ChB=dataOut.data[1,k+1,(dataOut.NRANGE+j+i*dataOut.NDT+2*n)%dataOut.NDP] |
|
842 | data_ChB=dataOut.data[1,k+1,(dataOut.NRANGE+j+i*dataOut.NDT+2*n)%dataOut.NDP] | |
843 | #print(data_ChB) |
|
843 | #print(data_ChB) | |
844 | #print("*2*") |
|
844 | #print("*2*") | |
845 | #exit(1) |
|
845 | #exit(1) | |
846 | if k+1==int(dataOut.NSCAN): |
|
846 | if k+1==int(dataOut.NSCAN): | |
847 | data_ChB=dataOut.data[1,k,(dataOut.NRANGE+j+i*dataOut.NDT+2*n)%dataOut.NDP] |
|
847 | data_ChB=dataOut.data[1,k,(dataOut.NRANGE+j+i*dataOut.NDT+2*n)%dataOut.NDP] | |
848 | #print("*3*") |
|
848 | #print("*3*") | |
849 | #if n == 7 and j == 65: |
|
849 | #if n == 7 and j == 65: | |
850 | #print(k) |
|
850 | #print(k) | |
851 | #print(data_ChB) |
|
851 | #print(data_ChB) | |
852 | #exit(1) |
|
852 | #exit(1) | |
853 | if n == 8 or n == 9 or n == 10: |
|
853 | if n == 8 or n == 9 or n == 10: | |
854 | self.buffer[0,int((aux+indProfile[k]-1)/2),j,n] = data_ChA |
|
854 | self.buffer[0,int((aux+indProfile[k]-1)/2),j,n] = data_ChA | |
855 | self.buffer[1,int((aux+indProfile[k]-1)/2),j,n] = data_ChB |
|
855 | self.buffer[1,int((aux+indProfile[k]-1)/2),j,n] = data_ChB | |
856 | elif n == 1 or n == 2 or n == 7: |
|
856 | elif n == 1 or n == 2 or n == 7: | |
857 | self.buffer[0,int((aux+indProfile[k])/2),j,n] = data_ChA |
|
857 | self.buffer[0,int((aux+indProfile[k])/2),j,n] = data_ChA | |
858 | self.buffer[1,int((aux+indProfile[k])/2),j,n] = data_ChB |
|
858 | self.buffer[1,int((aux+indProfile[k])/2),j,n] = data_ChB | |
859 | else: |
|
859 | else: | |
860 | self.buffer[0,aux+indProfile[k],j,n] = data_ChA |
|
860 | self.buffer[0,aux+indProfile[k],j,n] = data_ChA | |
861 | self.buffer[1,aux+indProfile[k],j,n] = data_ChB |
|
861 | self.buffer[1,aux+indProfile[k],j,n] = data_ChB | |
862 |
|
862 | |||
863 | #FindMe |
|
863 | #FindMe | |
864 | pa1 = 20 |
|
864 | pa1 = 20 | |
865 | pa2 = 10 |
|
865 | pa2 = 10 | |
866 |
|
866 | |||
867 | #print(self.buffer[0,:,pa1,pa2]) |
|
867 | #print(self.buffer[0,:,pa1,pa2]) | |
868 | #print(self.buffer[1,:,pa1,pa2]) |
|
868 | #print(self.buffer[1,:,pa1,pa2]) | |
869 | ''' |
|
869 | ''' | |
870 | print(sum(self.buffer[0,:,pa1,pa2])) |
|
870 | print(sum(self.buffer[0,:,pa1,pa2])) | |
871 | print(sum(self.buffer[1,:,pa1,pa2])) |
|
871 | print(sum(self.buffer[1,:,pa1,pa2])) | |
872 | #exit(1) |
|
872 | #exit(1) | |
873 | ''' |
|
873 | ''' | |
874 |
|
874 | |||
875 | ''' |
|
875 | ''' | |
876 | for pa1 in range(67): |
|
876 | for pa1 in range(67): | |
877 | print(sum(self.buffer[0,:,pa1,pa2])) |
|
877 | print(sum(self.buffer[0,:,pa1,pa2])) | |
878 | print(sum(self.buffer[1,:,pa1,pa2])) |
|
878 | print(sum(self.buffer[1,:,pa1,pa2])) | |
879 | ''' |
|
879 | ''' | |
880 |
|
880 | |||
881 | ''' |
|
881 | ''' | |
882 | import matplotlib.pyplot as plt |
|
882 | import matplotlib.pyplot as plt | |
883 | fft = numpy.fft.fft(self.buffer[0,:,pa1,pa2]) |
|
883 | fft = numpy.fft.fft(self.buffer[0,:,pa1,pa2]) | |
884 | fft2 = fft*numpy.conjugate(fft) |
|
884 | fft2 = fft*numpy.conjugate(fft) | |
885 | fft2 = fft2.real |
|
885 | fft2 = fft2.real | |
886 | fft2 = numpy.fft.fftshift(fft2) |
|
886 | fft2 = numpy.fft.fftshift(fft2) | |
887 | ''' |
|
887 | ''' | |
888 | #print("before",fft2) |
|
888 | #print("before",fft2) | |
889 | #plt.plot(fft2) |
|
889 | #plt.plot(fft2) | |
890 | #plt.show() |
|
890 | #plt.show() | |
891 | #import time |
|
891 | #import time | |
892 | #time.sleep(5) |
|
892 | #time.sleep(5) | |
893 | #plt.close('all') |
|
893 | #plt.close('all') | |
894 | #exit(1) |
|
894 | #exit(1) | |
895 | return self.buffer |
|
895 | return self.buffer | |
896 |
|
896 | |||
897 |
|
897 | |||
898 |
|
898 | |||
899 | def run(self,dataOut,DPL=11,NSCAN=128,lagind=(0,1,2,3,4,5,6,7,0,3,4,5,6,8,9,10),lagfirst=(1,1,1,1,1,1,1,1,0,0,0,0,0,1,1,1), NLAG = 16, NRANGE = 200): |
|
899 | def run(self,dataOut,DPL=11,NSCAN=128,lagind=(0,1,2,3,4,5,6,7,0,3,4,5,6,8,9,10),lagfirst=(1,1,1,1,1,1,1,1,0,0,0,0,0,1,1,1), NLAG = 16, NRANGE = 200): | |
900 |
|
900 | |||
901 | if not self.isConfig: |
|
901 | if not self.isConfig: | |
902 | self.setup(dataOut,DPL,NSCAN,NLAG,NRANGE,lagind,lagfirst) |
|
902 | self.setup(dataOut,DPL,NSCAN,NLAG,NRANGE,lagind,lagfirst) | |
903 | self.isConfig = True |
|
903 | self.isConfig = True | |
904 |
|
904 | |||
905 | #print(dataOut.data[1,:12,:15]) |
|
905 | #print(dataOut.data[1,:12,:15]) | |
906 | #exit(1) |
|
906 | #exit(1) | |
907 | #print(numpy.shape(dataOut.data)) |
|
907 | #print(numpy.shape(dataOut.data)) | |
908 | #print(dataOut.profileIndex) |
|
908 | #print(dataOut.profileIndex) | |
909 |
|
909 | |||
910 | if not dataOut.flagDataAsBlock: |
|
910 | if not dataOut.flagDataAsBlock: | |
911 |
|
911 | |||
912 | dataOut.flagNoData = True |
|
912 | dataOut.flagNoData = True | |
913 | #print("nProfiles: ",dataOut.nProfiles) |
|
913 | #print("nProfiles: ",dataOut.nProfiles) | |
914 | #if dataOut.profileIndex == 140: |
|
914 | #if dataOut.profileIndex == 140: | |
915 | #print("id: ",dataOut.profileIndex) |
|
915 | #print("id: ",dataOut.profileIndex) | |
916 | if dataOut.profileIndex == dataOut.nProfiles-1: |
|
916 | if dataOut.profileIndex == dataOut.nProfiles-1: | |
917 | #print("here") |
|
917 | #print("here") | |
918 | #print(dataOut.data.shape) |
|
918 | #print(dataOut.data.shape) | |
919 | self.data_buffer.append(dataOut.data) |
|
919 | self.data_buffer.append(dataOut.data) | |
920 | dataOut.data = numpy.transpose(numpy.array(self.data_buffer),(1,0,2)) |
|
920 | dataOut.data = numpy.transpose(numpy.array(self.data_buffer),(1,0,2)) | |
921 | #print(dataOut.data.shape) |
|
921 | #print(dataOut.data.shape) | |
922 | #print(numpy.sum(dataOut.data)) |
|
922 | #print(numpy.sum(dataOut.data)) | |
923 | #print(dataOut.data[1,100,:]) |
|
923 | #print(dataOut.data[1,100,:]) | |
924 | #exit(1) |
|
924 | #exit(1) | |
925 | dataOut.datalags = numpy.copy(self.LagDistribution(dataOut)) |
|
925 | dataOut.datalags = numpy.copy(self.LagDistribution(dataOut)) | |
926 | #print(numpy.shape(dataOut.datalags)) |
|
926 | #print(numpy.shape(dataOut.datalags)) | |
927 | #exit(1) |
|
927 | #exit(1) | |
928 | #print("AFTER RESHAPE DP") |
|
928 | #print("AFTER RESHAPE DP") | |
929 |
|
929 | |||
930 | dataOut.data = dataOut.data[:,:,200:] |
|
930 | dataOut.data = dataOut.data[:,:,200:] | |
931 | self.data_buffer = [] |
|
931 | self.data_buffer = [] | |
932 | dataOut.flagDataAsBlock = True |
|
932 | dataOut.flagDataAsBlock = True | |
933 | dataOut.flagNoData = False |
|
933 | dataOut.flagNoData = False | |
934 |
|
934 | |||
935 | deltaHeight = dataOut.heightList[1] - dataOut.heightList[0] |
|
935 | deltaHeight = dataOut.heightList[1] - dataOut.heightList[0] | |
936 | dataOut.heightList = numpy.arange(dataOut.NDP) *deltaHeight# + dataOut.heightList[0] |
|
936 | dataOut.heightList = numpy.arange(dataOut.NDP) *deltaHeight# + dataOut.heightList[0] | |
937 | #exit(1) |
|
937 | #exit(1) | |
938 | #print(numpy.sum(dataOut.datalags)) |
|
938 | #print(numpy.sum(dataOut.datalags)) | |
939 | #exit(1) |
|
939 | #exit(1) | |
940 |
|
940 | |||
941 | else: |
|
941 | else: | |
942 | self.data_buffer.append(dataOut.data) |
|
942 | self.data_buffer.append(dataOut.data) | |
943 | #print(numpy.shape(dataOut.data)) |
|
943 | #print(numpy.shape(dataOut.data)) | |
944 | #exit(1) |
|
944 | #exit(1) | |
945 | else: |
|
945 | else: | |
946 | #print(dataOut.data.shape) |
|
946 | #print(dataOut.data.shape) | |
947 | #print(numpy.sum(dataOut.data)) |
|
947 | #print(numpy.sum(dataOut.data)) | |
948 | #print(dataOut.data[1,100,:]) |
|
948 | #print(dataOut.data[1,100,:]) | |
949 | #exit(1) |
|
949 | #exit(1) | |
950 | dataOut.datalags = numpy.copy(self.LagDistribution(dataOut)) |
|
950 | dataOut.datalags = numpy.copy(self.LagDistribution(dataOut)) | |
951 | #print(dataOut.datalags.shape) |
|
951 | #print(dataOut.datalags.shape) | |
952 | dataOut.data = dataOut.data[:,:,200:] |
|
952 | dataOut.data = dataOut.data[:,:,200:] | |
953 | deltaHeight = dataOut.heightList[1] - dataOut.heightList[0] |
|
953 | deltaHeight = dataOut.heightList[1] - dataOut.heightList[0] | |
954 | dataOut.heightList = numpy.arange(dataOut.NDP) * deltaHeight# + dataOut.heightList[0] |
|
954 | dataOut.heightList = numpy.arange(dataOut.NDP) * deltaHeight# + dataOut.heightList[0] | |
955 | #print(dataOut.nHeights) |
|
955 | #print(dataOut.nHeights) | |
956 | #print(numpy.sum(dataOut.datalags)) |
|
956 | #print(numpy.sum(dataOut.datalags)) | |
957 | #exit(1) |
|
957 | #exit(1) | |
958 |
|
958 | |||
959 | return dataOut |
|
959 | return dataOut | |
960 |
|
960 | |||
961 | class CrossProdDP(Operation): |
|
961 | class CrossProdDP(Operation): | |
962 | ''' |
|
962 | ''' | |
963 | Written by R. Flores |
|
963 | Written by R. Flores | |
964 | ''' |
|
964 | ''' | |
965 | """Operation to calculate cross products of the Double Pulse Experiment. |
|
965 | """Operation to calculate cross products of the Double Pulse Experiment. | |
966 |
|
966 | |||
967 | Parameters: |
|
967 | Parameters: | |
968 | ----------- |
|
968 | ----------- | |
969 | NLAG : int |
|
969 | NLAG : int | |
970 | Number of lags Long Pulse. |
|
970 | Number of lags Long Pulse. | |
971 | NRANGE : int |
|
971 | NRANGE : int | |
972 | Number of samples for Long Pulse. |
|
972 | Number of samples for Long Pulse. | |
973 | NCAL : int |
|
973 | NCAL : int | |
974 | .* |
|
974 | .* | |
975 | DPL : int |
|
975 | DPL : int | |
976 | Number of lags Double Pulse. |
|
976 | Number of lags Double Pulse. | |
977 | NDN : int |
|
977 | NDN : int | |
978 | .* |
|
978 | .* | |
979 | NDT : int |
|
979 | NDT : int | |
980 | Number of heights for Double Pulse.* |
|
980 | Number of heights for Double Pulse.* | |
981 | NDP : int |
|
981 | NDP : int | |
982 | Number of heights for Double Pulse.* |
|
982 | Number of heights for Double Pulse.* | |
983 | NSCAN : int |
|
983 | NSCAN : int | |
984 | Number of profiles when the transmitter is on. |
|
984 | Number of profiles when the transmitter is on. | |
985 | flags_array : intlist |
|
985 | flags_array : intlist | |
986 | .* |
|
986 | .* | |
987 | NAVG : int |
|
987 | NAVG : int | |
988 | Number of blocks to be "averaged". |
|
988 | Number of blocks to be "averaged". | |
989 | nkill : int |
|
989 | nkill : int | |
990 | Number of blocks not to be considered when averaging. |
|
990 | Number of blocks not to be considered when averaging. | |
991 |
|
991 | |||
992 | Example |
|
992 | Example | |
993 | -------- |
|
993 | -------- | |
994 |
|
994 | |||
995 | op = proc_unit.addOperation(name='CrossProdDP', optype='other') |
|
995 | op = proc_unit.addOperation(name='CrossProdDP', optype='other') | |
996 | op.addParameter(name='NLAG', value='16', format='int') |
|
996 | op.addParameter(name='NLAG', value='16', format='int') | |
997 | op.addParameter(name='NRANGE', value='0', format='int') |
|
997 | op.addParameter(name='NRANGE', value='0', format='int') | |
998 | op.addParameter(name='NCAL', value='0', format='int') |
|
998 | op.addParameter(name='NCAL', value='0', format='int') | |
999 | op.addParameter(name='DPL', value='11', format='int') |
|
999 | op.addParameter(name='DPL', value='11', format='int') | |
1000 | op.addParameter(name='NDN', value='0', format='int') |
|
1000 | op.addParameter(name='NDN', value='0', format='int') | |
1001 | op.addParameter(name='NDT', value='66', format='int') |
|
1001 | op.addParameter(name='NDT', value='66', format='int') | |
1002 | op.addParameter(name='NDP', value='66', format='int') |
|
1002 | op.addParameter(name='NDP', value='66', format='int') | |
1003 | op.addParameter(name='NSCAN', value='132', format='int') |
|
1003 | op.addParameter(name='NSCAN', value='132', format='int') | |
1004 | op.addParameter(name='flags_array', value='(0, 30, 60, 90, 120, 150, 180, 210, 240, 270, 300)', format='intlist') |
|
1004 | op.addParameter(name='flags_array', value='(0, 30, 60, 90, 120, 150, 180, 210, 240, 270, 300)', format='intlist') | |
1005 | op.addParameter(name='NAVG', value='16', format='int') |
|
1005 | op.addParameter(name='NAVG', value='16', format='int') | |
1006 | op.addParameter(name='nkill', value='6', format='int') |
|
1006 | op.addParameter(name='nkill', value='6', format='int') | |
1007 |
|
1007 | |||
1008 | """ |
|
1008 | """ | |
1009 |
|
1009 | |||
1010 | def __init__(self, **kwargs): |
|
1010 | def __init__(self, **kwargs): | |
1011 |
|
1011 | |||
1012 | Operation.__init__(self, **kwargs) |
|
1012 | Operation.__init__(self, **kwargs) | |
1013 | self.bcounter=0 |
|
1013 | self.bcounter=0 | |
1014 | self.aux=1 |
|
1014 | self.aux=1 | |
1015 | self.lag_products_LP_median_estimates_aux=0 |
|
1015 | self.lag_products_LP_median_estimates_aux=0 | |
1016 |
|
1016 | |||
1017 | def set_header_output(self,dataOut): |
|
1017 | def set_header_output(self,dataOut): | |
1018 |
|
1018 | |||
1019 | dataOut.read_samples=len(dataOut.heightList)#int(dataOut.systemHeaderObj.nSamples/dataOut.windowOfFilter) |
|
1019 | dataOut.read_samples=len(dataOut.heightList)#int(dataOut.systemHeaderObj.nSamples/dataOut.windowOfFilter) | |
1020 | padding=numpy.zeros(1,'int32') |
|
1020 | padding=numpy.zeros(1,'int32') | |
1021 | hsize=numpy.zeros(1,'int32') |
|
1021 | hsize=numpy.zeros(1,'int32') | |
1022 | bufsize=numpy.zeros(1,'int32') |
|
1022 | bufsize=numpy.zeros(1,'int32') | |
1023 | nr=numpy.zeros(1,'int32') |
|
1023 | nr=numpy.zeros(1,'int32') | |
1024 | ngates=numpy.zeros(1,'int32') ### ### ### 2 |
|
1024 | ngates=numpy.zeros(1,'int32') ### ### ### 2 | |
1025 | time1=numpy.zeros(1,'uint64') # pos 3 |
|
1025 | time1=numpy.zeros(1,'uint64') # pos 3 | |
1026 | time2=numpy.zeros(1,'uint64') # pos 4 |
|
1026 | time2=numpy.zeros(1,'uint64') # pos 4 | |
1027 | lcounter=numpy.zeros(1,'int32') |
|
1027 | lcounter=numpy.zeros(1,'int32') | |
1028 | groups=numpy.zeros(1,'int32') |
|
1028 | groups=numpy.zeros(1,'int32') | |
1029 | system=numpy.zeros(4,'int8') # pos 7 |
|
1029 | system=numpy.zeros(4,'int8') # pos 7 | |
1030 | h0=numpy.zeros(1,'float32') |
|
1030 | h0=numpy.zeros(1,'float32') | |
1031 | dh=numpy.zeros(1,'float32') |
|
1031 | dh=numpy.zeros(1,'float32') | |
1032 | ipp=numpy.zeros(1,'float32') |
|
1032 | ipp=numpy.zeros(1,'float32') | |
1033 | process=numpy.zeros(1,'int32') |
|
1033 | process=numpy.zeros(1,'int32') | |
1034 | tx=numpy.zeros(1,'int32') |
|
1034 | tx=numpy.zeros(1,'int32') | |
1035 | ngates1=numpy.zeros(1,'int32') ### ### ### 13 |
|
1035 | ngates1=numpy.zeros(1,'int32') ### ### ### 13 | |
1036 | time0=numpy.zeros(1,'uint64') # pos 14 |
|
1036 | time0=numpy.zeros(1,'uint64') # pos 14 | |
1037 | nlags=numpy.zeros(1,'int32') |
|
1037 | nlags=numpy.zeros(1,'int32') | |
1038 | nlags1=numpy.zeros(1,'int32') |
|
1038 | nlags1=numpy.zeros(1,'int32') | |
1039 | txb=numpy.zeros(1,'float32') ### ### ### 17 |
|
1039 | txb=numpy.zeros(1,'float32') ### ### ### 17 | |
1040 | time3=numpy.zeros(1,'uint64') # pos 18 |
|
1040 | time3=numpy.zeros(1,'uint64') # pos 18 | |
1041 | time4=numpy.zeros(1,'uint64') # pos 19 |
|
1041 | time4=numpy.zeros(1,'uint64') # pos 19 | |
1042 | h0_=numpy.zeros(1,'float32') |
|
1042 | h0_=numpy.zeros(1,'float32') | |
1043 | dh_=numpy.zeros(1,'float32') |
|
1043 | dh_=numpy.zeros(1,'float32') | |
1044 | ipp_=numpy.zeros(1,'float32') |
|
1044 | ipp_=numpy.zeros(1,'float32') | |
1045 | txa_=numpy.zeros(1,'float32') |
|
1045 | txa_=numpy.zeros(1,'float32') | |
1046 | pad=numpy.zeros(100,'int32') |
|
1046 | pad=numpy.zeros(100,'int32') | |
1047 | nbytes=numpy.zeros(1,'int32') |
|
1047 | nbytes=numpy.zeros(1,'int32') | |
1048 | limits=numpy.zeros(1,'int32') |
|
1048 | limits=numpy.zeros(1,'int32') | |
1049 | ngroups=numpy.zeros(1,'int32') ### ### ### 27 |
|
1049 | ngroups=numpy.zeros(1,'int32') ### ### ### 27 | |
1050 |
|
1050 | |||
1051 | dataOut.header=[hsize,bufsize,nr,ngates,time1,time2, |
|
1051 | dataOut.header=[hsize,bufsize,nr,ngates,time1,time2, | |
1052 | lcounter,groups,system,h0,dh,ipp, |
|
1052 | lcounter,groups,system,h0,dh,ipp, | |
1053 | process,tx,ngates1,padding,time0,nlags, |
|
1053 | process,tx,ngates1,padding,time0,nlags, | |
1054 | nlags1,padding,txb,time3,time4,h0_,dh_, |
|
1054 | nlags1,padding,txb,time3,time4,h0_,dh_, | |
1055 | ipp_,txa_,pad,nbytes,limits,padding,ngroups] |
|
1055 | ipp_,txa_,pad,nbytes,limits,padding,ngroups] | |
1056 |
|
1056 | |||
1057 |
|
1057 | |||
1058 | #dataOut.header[1][0]=81864 |
|
1058 | #dataOut.header[1][0]=81864 | |
1059 | dataOut.FirstHeight=int(dataOut.heightList[0]) |
|
1059 | dataOut.FirstHeight=int(dataOut.heightList[0]) | |
1060 | dataOut.MAXNRANGENDT=max(dataOut.NRANGE,dataOut.NDT) |
|
1060 | dataOut.MAXNRANGENDT=max(dataOut.NRANGE,dataOut.NDT) | |
1061 | dataOut.header[3][0]=max(dataOut.NRANGE,dataOut.NDT) |
|
1061 | dataOut.header[3][0]=max(dataOut.NRANGE,dataOut.NDT) | |
1062 | dataOut.header[7][0]=dataOut.NAVG |
|
1062 | dataOut.header[7][0]=dataOut.NAVG | |
1063 | dataOut.header[9][0]=int(dataOut.heightList[0]) |
|
1063 | dataOut.header[9][0]=int(dataOut.heightList[0]) | |
1064 | dataOut.header[10][0]=dataOut.DH |
|
1064 | dataOut.header[10][0]=dataOut.DH | |
1065 | dataOut.header[17][0]=dataOut.DPL |
|
1065 | dataOut.header[17][0]=dataOut.DPL | |
1066 | dataOut.header[18][0]=dataOut.NLAG |
|
1066 | dataOut.header[18][0]=dataOut.NLAG | |
1067 | #self.header[5][0]=0 |
|
1067 | #self.header[5][0]=0 | |
1068 | dataOut.header[15][0]=dataOut.NDP |
|
1068 | dataOut.header[15][0]=dataOut.NDP | |
1069 | dataOut.header[2][0]=dataOut.NR |
|
1069 | dataOut.header[2][0]=dataOut.NR | |
1070 |
|
1070 | |||
1071 |
|
1071 | |||
1072 | def get_products_cabxys(self,dataOut): |
|
1072 | def get_products_cabxys(self,dataOut): | |
1073 |
|
1073 | |||
1074 | if self.aux==1: |
|
1074 | if self.aux==1: | |
1075 | self.set_header_output(dataOut) |
|
1075 | self.set_header_output(dataOut) | |
1076 | self.aux=0 |
|
1076 | self.aux=0 | |
1077 |
|
1077 | |||
1078 | dataOut.lags_array=[x / dataOut.DH for x in dataOut.flags_array] |
|
1078 | dataOut.lags_array=[x / dataOut.DH for x in dataOut.flags_array] | |
1079 | self.cax=numpy.zeros((dataOut.NDP,dataOut.DPL,2)) |
|
1079 | self.cax=numpy.zeros((dataOut.NDP,dataOut.DPL,2)) | |
1080 | self.cay=numpy.zeros((dataOut.NDP,dataOut.DPL,2)) |
|
1080 | self.cay=numpy.zeros((dataOut.NDP,dataOut.DPL,2)) | |
1081 | self.cbx=numpy.zeros((dataOut.NDP,dataOut.DPL,2)) |
|
1081 | self.cbx=numpy.zeros((dataOut.NDP,dataOut.DPL,2)) | |
1082 | self.cby=numpy.zeros((dataOut.NDP,dataOut.DPL,2)) |
|
1082 | self.cby=numpy.zeros((dataOut.NDP,dataOut.DPL,2)) | |
1083 | self.cax2=numpy.zeros((dataOut.NDP,dataOut.DPL,2)) |
|
1083 | self.cax2=numpy.zeros((dataOut.NDP,dataOut.DPL,2)) | |
1084 | self.cay2=numpy.zeros((dataOut.NDP,dataOut.DPL,2)) |
|
1084 | self.cay2=numpy.zeros((dataOut.NDP,dataOut.DPL,2)) | |
1085 | self.cbx2=numpy.zeros((dataOut.NDP,dataOut.DPL,2)) |
|
1085 | self.cbx2=numpy.zeros((dataOut.NDP,dataOut.DPL,2)) | |
1086 | self.cby2=numpy.zeros((dataOut.NDP,dataOut.DPL,2)) |
|
1086 | self.cby2=numpy.zeros((dataOut.NDP,dataOut.DPL,2)) | |
1087 | self.caxbx=numpy.zeros((dataOut.NDP,dataOut.DPL,2)) |
|
1087 | self.caxbx=numpy.zeros((dataOut.NDP,dataOut.DPL,2)) | |
1088 | self.caxby=numpy.zeros((dataOut.NDP,dataOut.DPL,2)) |
|
1088 | self.caxby=numpy.zeros((dataOut.NDP,dataOut.DPL,2)) | |
1089 | self.caybx=numpy.zeros((dataOut.NDP,dataOut.DPL,2)) |
|
1089 | self.caybx=numpy.zeros((dataOut.NDP,dataOut.DPL,2)) | |
1090 | self.cayby=numpy.zeros((dataOut.NDP,dataOut.DPL,2)) |
|
1090 | self.cayby=numpy.zeros((dataOut.NDP,dataOut.DPL,2)) | |
1091 | self.caxay=numpy.zeros((dataOut.NDP,dataOut.DPL,2)) |
|
1091 | self.caxay=numpy.zeros((dataOut.NDP,dataOut.DPL,2)) | |
1092 | self.cbxby=numpy.zeros((dataOut.NDP,dataOut.DPL,2)) |
|
1092 | self.cbxby=numpy.zeros((dataOut.NDP,dataOut.DPL,2)) | |
1093 |
|
1093 | |||
1094 | for i in range(2): |
|
1094 | for i in range(2): | |
1095 | for j in range(dataOut.NDP): |
|
1095 | for j in range(dataOut.NDP): | |
1096 | for k in range(int(dataOut.NSCAN/2)): |
|
1096 | for k in range(int(dataOut.NSCAN/2)): | |
1097 | n=k%dataOut.DPL |
|
1097 | n=k%dataOut.DPL | |
1098 | ax=dataOut.data[0,2*k+i,j].real |
|
1098 | ax=dataOut.data[0,2*k+i,j].real | |
1099 | ay=dataOut.data[0,2*k+i,j].imag |
|
1099 | ay=dataOut.data[0,2*k+i,j].imag | |
1100 | if j+dataOut.lags_array[n]<dataOut.NDP: |
|
1100 | if j+dataOut.lags_array[n]<dataOut.NDP: | |
1101 | bx=dataOut.data[1,2*k+i,j+int(dataOut.lags_array[n])].real |
|
1101 | bx=dataOut.data[1,2*k+i,j+int(dataOut.lags_array[n])].real | |
1102 | by=dataOut.data[1,2*k+i,j+int(dataOut.lags_array[n])].imag |
|
1102 | by=dataOut.data[1,2*k+i,j+int(dataOut.lags_array[n])].imag | |
1103 | else: |
|
1103 | else: | |
1104 | if k+1<int(dataOut.NSCAN/2): |
|
1104 | if k+1<int(dataOut.NSCAN/2): | |
1105 | bx=dataOut.data[1,2*(k+1)+i,(dataOut.NRANGE+dataOut.NCAL+j+int(dataOut.lags_array[n]))%dataOut.NDP].real |
|
1105 | bx=dataOut.data[1,2*(k+1)+i,(dataOut.NRANGE+dataOut.NCAL+j+int(dataOut.lags_array[n]))%dataOut.NDP].real | |
1106 | by=dataOut.data[1,2*(k+1)+i,(dataOut.NRANGE+dataOut.NCAL+j+int(dataOut.lags_array[n]))%dataOut.NDP].imag |
|
1106 | by=dataOut.data[1,2*(k+1)+i,(dataOut.NRANGE+dataOut.NCAL+j+int(dataOut.lags_array[n]))%dataOut.NDP].imag | |
1107 |
|
1107 | |||
1108 | if k+1==int(dataOut.NSCAN/2): |
|
1108 | if k+1==int(dataOut.NSCAN/2): | |
1109 | bx=dataOut.data[1,2*k+i,(dataOut.NRANGE+dataOut.NCAL+j+int(dataOut.lags_array[n]))%dataOut.NDP].real |
|
1109 | bx=dataOut.data[1,2*k+i,(dataOut.NRANGE+dataOut.NCAL+j+int(dataOut.lags_array[n]))%dataOut.NDP].real | |
1110 | by=dataOut.data[1,2*k+i,(dataOut.NRANGE+dataOut.NCAL+j+int(dataOut.lags_array[n]))%dataOut.NDP].imag |
|
1110 | by=dataOut.data[1,2*k+i,(dataOut.NRANGE+dataOut.NCAL+j+int(dataOut.lags_array[n]))%dataOut.NDP].imag | |
1111 |
|
1111 | |||
1112 | if(k<dataOut.DPL): |
|
1112 | if(k<dataOut.DPL): | |
1113 | self.cax[j][n][i]=ax |
|
1113 | self.cax[j][n][i]=ax | |
1114 | self.cay[j][n][i]=ay |
|
1114 | self.cay[j][n][i]=ay | |
1115 | self.cbx[j][n][i]=bx |
|
1115 | self.cbx[j][n][i]=bx | |
1116 | self.cby[j][n][i]=by |
|
1116 | self.cby[j][n][i]=by | |
1117 | self.cax2[j][n][i]=ax*ax |
|
1117 | self.cax2[j][n][i]=ax*ax | |
1118 | self.cay2[j][n][i]=ay*ay |
|
1118 | self.cay2[j][n][i]=ay*ay | |
1119 | self.cbx2[j][n][i]=bx*bx |
|
1119 | self.cbx2[j][n][i]=bx*bx | |
1120 | self.cby2[j][n][i]=by*by |
|
1120 | self.cby2[j][n][i]=by*by | |
1121 | self.caxbx[j][n][i]=ax*bx |
|
1121 | self.caxbx[j][n][i]=ax*bx | |
1122 | self.caxby[j][n][i]=ax*by |
|
1122 | self.caxby[j][n][i]=ax*by | |
1123 | self.caybx[j][n][i]=ay*bx |
|
1123 | self.caybx[j][n][i]=ay*bx | |
1124 | self.cayby[j][n][i]=ay*by |
|
1124 | self.cayby[j][n][i]=ay*by | |
1125 | self.caxay[j][n][i]=ax*ay |
|
1125 | self.caxay[j][n][i]=ax*ay | |
1126 | self.cbxby[j][n][i]=bx*by |
|
1126 | self.cbxby[j][n][i]=bx*by | |
1127 | else: |
|
1127 | else: | |
1128 | self.cax[j][n][i]+=ax |
|
1128 | self.cax[j][n][i]+=ax | |
1129 | self.cay[j][n][i]+=ay |
|
1129 | self.cay[j][n][i]+=ay | |
1130 | self.cbx[j][n][i]+=bx |
|
1130 | self.cbx[j][n][i]+=bx | |
1131 | self.cby[j][n][i]+=by |
|
1131 | self.cby[j][n][i]+=by | |
1132 | self.cax2[j][n][i]+=ax*ax |
|
1132 | self.cax2[j][n][i]+=ax*ax | |
1133 | self.cay2[j][n][i]+=ay*ay |
|
1133 | self.cay2[j][n][i]+=ay*ay | |
1134 | self.cbx2[j][n][i]+=bx*bx |
|
1134 | self.cbx2[j][n][i]+=bx*bx | |
1135 | self.cby2[j][n][i]+=by*by |
|
1135 | self.cby2[j][n][i]+=by*by | |
1136 | self.caxbx[j][n][i]+=ax*bx |
|
1136 | self.caxbx[j][n][i]+=ax*bx | |
1137 | self.caxby[j][n][i]+=ax*by |
|
1137 | self.caxby[j][n][i]+=ax*by | |
1138 | self.caybx[j][n][i]+=ay*bx |
|
1138 | self.caybx[j][n][i]+=ay*bx | |
1139 | self.cayby[j][n][i]+=ay*by |
|
1139 | self.cayby[j][n][i]+=ay*by | |
1140 | self.caxay[j][n][i]+=ax*ay |
|
1140 | self.caxay[j][n][i]+=ax*ay | |
1141 | self.cbxby[j][n][i]+=bx*by |
|
1141 | self.cbxby[j][n][i]+=bx*by | |
1142 |
|
1142 | |||
1143 |
|
1143 | |||
1144 | def medi(self,data_navg,NAVG,nkill): |
|
1144 | def medi(self,data_navg,NAVG,nkill): | |
1145 | sorts=sorted(data_navg) |
|
1145 | sorts=sorted(data_navg) | |
1146 | rsorts=numpy.arange(NAVG) |
|
1146 | rsorts=numpy.arange(NAVG) | |
1147 | result=0.0 |
|
1147 | result=0.0 | |
1148 | for k in range(NAVG): |
|
1148 | for k in range(NAVG): | |
1149 | if k>=nkill/2 and k<NAVG-nkill/2: |
|
1149 | if k>=nkill/2 and k<NAVG-nkill/2: | |
1150 | result+=sorts[k]*float(NAVG)/(float)(NAVG-nkill) |
|
1150 | result+=sorts[k]*float(NAVG)/(float)(NAVG-nkill) | |
1151 | return result |
|
1151 | return result | |
1152 |
|
1152 | |||
1153 |
|
1153 | |||
1154 | def get_dc(self,dataOut): |
|
1154 | def get_dc(self,dataOut): | |
1155 | if self.bcounter==0: |
|
1155 | if self.bcounter==0: | |
1156 | dataOut.dc=numpy.zeros(dataOut.NR,dtype='complex64') |
|
1156 | dataOut.dc=numpy.zeros(dataOut.NR,dtype='complex64') | |
1157 | def cabxys_navg(self,dataOut): |
|
1157 | def cabxys_navg(self,dataOut): | |
1158 |
|
1158 | |||
1159 |
|
1159 | |||
1160 | dataOut.header[5][0]=dataOut.TimeBlockSeconds |
|
1160 | dataOut.header[5][0]=dataOut.TimeBlockSeconds | |
1161 |
|
1161 | |||
1162 | dataOut.LastAVGDate=dataOut.TimeBlockSeconds |
|
1162 | dataOut.LastAVGDate=dataOut.TimeBlockSeconds | |
1163 |
|
1163 | |||
1164 | if self.bcounter==0: |
|
1164 | if self.bcounter==0: | |
1165 | dataOut.FirstAVGDate=dataOut.TimeBlockSeconds |
|
1165 | dataOut.FirstAVGDate=dataOut.TimeBlockSeconds | |
1166 | dataOut.header[4][0]=dataOut.header[5][0]#firsttimeofNAVG |
|
1166 | dataOut.header[4][0]=dataOut.header[5][0]#firsttimeofNAVG | |
1167 | if dataOut.CurrentBlock==1: |
|
1167 | if dataOut.CurrentBlock==1: | |
1168 | dataOut.FirstBlockDate=dataOut.TimeBlockSeconds |
|
1168 | dataOut.FirstBlockDate=dataOut.TimeBlockSeconds | |
1169 | dataOut.header[16][0]=dataOut.header[5][0]#FirsTimeOfTotalBlocks |
|
1169 | dataOut.header[16][0]=dataOut.header[5][0]#FirsTimeOfTotalBlocks | |
1170 |
|
1170 | |||
1171 | self.cax_navg=[] |
|
1171 | self.cax_navg=[] | |
1172 | self.cay_navg=[] |
|
1172 | self.cay_navg=[] | |
1173 | self.cbx_navg=[] |
|
1173 | self.cbx_navg=[] | |
1174 | self.cby_navg=[] |
|
1174 | self.cby_navg=[] | |
1175 | self.cax2_navg=[] |
|
1175 | self.cax2_navg=[] | |
1176 | self.cay2_navg=[] |
|
1176 | self.cay2_navg=[] | |
1177 | self.cbx2_navg=[] |
|
1177 | self.cbx2_navg=[] | |
1178 | self.cby2_navg=[] |
|
1178 | self.cby2_navg=[] | |
1179 | self.caxbx_navg=[] |
|
1179 | self.caxbx_navg=[] | |
1180 | self.caxby_navg=[] |
|
1180 | self.caxby_navg=[] | |
1181 | self.caybx_navg=[] |
|
1181 | self.caybx_navg=[] | |
1182 | self.cayby_navg=[] |
|
1182 | self.cayby_navg=[] | |
1183 | self.caxay_navg=[] |
|
1183 | self.caxay_navg=[] | |
1184 | self.cbxby_navg=[] |
|
1184 | self.cbxby_navg=[] | |
1185 |
|
1185 | |||
1186 | dataOut.noisevector=numpy.zeros((dataOut.MAXNRANGENDT,dataOut.NR,dataOut.NAVG),'float32') #30/03/2020 |
|
1186 | dataOut.noisevector=numpy.zeros((dataOut.MAXNRANGENDT,dataOut.NR,dataOut.NAVG),'float32') #30/03/2020 | |
1187 |
|
1187 | |||
1188 | dataOut.noisevector_=numpy.zeros((dataOut.read_samples,dataOut.NR,dataOut.NAVG),'float32') |
|
1188 | dataOut.noisevector_=numpy.zeros((dataOut.read_samples,dataOut.NR,dataOut.NAVG),'float32') | |
1189 |
|
1189 | |||
1190 | self.noisevectorizer(dataOut.NSCAN,dataOut.nProfiles,dataOut.NR,dataOut.MAXNRANGENDT,dataOut.noisevector,dataOut.data,dataOut.dc) #30/03/2020 |
|
1190 | self.noisevectorizer(dataOut.NSCAN,dataOut.nProfiles,dataOut.NR,dataOut.MAXNRANGENDT,dataOut.noisevector,dataOut.data,dataOut.dc) #30/03/2020 | |
1191 |
|
1191 | |||
1192 | self.cax_navg.append(self.cax) |
|
1192 | self.cax_navg.append(self.cax) | |
1193 | self.cay_navg.append(self.cay) |
|
1193 | self.cay_navg.append(self.cay) | |
1194 | self.cbx_navg.append(self.cbx) |
|
1194 | self.cbx_navg.append(self.cbx) | |
1195 | self.cby_navg.append(self.cby) |
|
1195 | self.cby_navg.append(self.cby) | |
1196 | self.cax2_navg.append(self.cax2) |
|
1196 | self.cax2_navg.append(self.cax2) | |
1197 | self.cay2_navg.append(self.cay2) |
|
1197 | self.cay2_navg.append(self.cay2) | |
1198 | self.cbx2_navg.append(self.cbx2) |
|
1198 | self.cbx2_navg.append(self.cbx2) | |
1199 | self.cby2_navg.append(self.cby2) |
|
1199 | self.cby2_navg.append(self.cby2) | |
1200 | self.caxbx_navg.append(self.caxbx) |
|
1200 | self.caxbx_navg.append(self.caxbx) | |
1201 | self.caxby_navg.append(self.caxby) |
|
1201 | self.caxby_navg.append(self.caxby) | |
1202 | self.caybx_navg.append(self.caybx) |
|
1202 | self.caybx_navg.append(self.caybx) | |
1203 | self.cayby_navg.append(self.cayby) |
|
1203 | self.cayby_navg.append(self.cayby) | |
1204 | self.caxay_navg.append(self.caxay) |
|
1204 | self.caxay_navg.append(self.caxay) | |
1205 | self.cbxby_navg.append(self.cbxby) |
|
1205 | self.cbxby_navg.append(self.cbxby) | |
1206 | self.bcounter+=1 |
|
1206 | self.bcounter+=1 | |
1207 |
|
1207 | |||
1208 | def noise_estimation4x_DP(self,dataOut): |
|
1208 | def noise_estimation4x_DP(self,dataOut): | |
1209 | if self.bcounter==dataOut.NAVG: |
|
1209 | if self.bcounter==dataOut.NAVG: | |
1210 | dataOut.noise_final=numpy.zeros(dataOut.NR,'float32') |
|
1210 | dataOut.noise_final=numpy.zeros(dataOut.NR,'float32') | |
1211 | snoise=numpy.zeros((dataOut.NR,dataOut.NAVG),'float32') |
|
1211 | snoise=numpy.zeros((dataOut.NR,dataOut.NAVG),'float32') | |
1212 | nvector1=numpy.zeros((dataOut.NR,dataOut.NAVG,dataOut.MAXNRANGENDT),'float32') |
|
1212 | nvector1=numpy.zeros((dataOut.NR,dataOut.NAVG,dataOut.MAXNRANGENDT),'float32') | |
1213 | for i in range(dataOut.NR): |
|
1213 | for i in range(dataOut.NR): | |
1214 | dataOut.noise_final[i]=0.0 |
|
1214 | dataOut.noise_final[i]=0.0 | |
1215 | for k in range(dataOut.NAVG): |
|
1215 | for k in range(dataOut.NAVG): | |
1216 | snoise[i][k]=0.0 |
|
1216 | snoise[i][k]=0.0 | |
1217 | for j in range(dataOut.MAXNRANGENDT): |
|
1217 | for j in range(dataOut.MAXNRANGENDT): | |
1218 | nvector1[i][k][j]= dataOut.noisevector[j][i][k]; |
|
1218 | nvector1[i][k][j]= dataOut.noisevector[j][i][k]; | |
1219 | snoise[i][k]=self.noise_hs4x(dataOut.MAXNRANGENDT, nvector1[i][k]) |
|
1219 | snoise[i][k]=self.noise_hs4x(dataOut.MAXNRANGENDT, nvector1[i][k]) | |
1220 | dataOut.noise_final[i]=self.noise_hs4x(dataOut.NAVG, snoise[i]) |
|
1220 | dataOut.noise_final[i]=self.noise_hs4x(dataOut.NAVG, snoise[i]) | |
1221 |
|
1221 | |||
1222 | def kabxys(self,dataOut): |
|
1222 | def kabxys(self,dataOut): | |
1223 |
|
1223 | |||
1224 | if self.bcounter==dataOut.NAVG: |
|
1224 | if self.bcounter==dataOut.NAVG: | |
1225 |
|
1225 | |||
1226 | dataOut.flagNoData = False |
|
1226 | dataOut.flagNoData = False | |
1227 |
|
1227 | |||
1228 | self.kax=numpy.zeros((dataOut.NDP,dataOut.DPL,2),'float32') |
|
1228 | self.kax=numpy.zeros((dataOut.NDP,dataOut.DPL,2),'float32') | |
1229 | self.kay=numpy.zeros((dataOut.NDP,dataOut.DPL,2),'float32') |
|
1229 | self.kay=numpy.zeros((dataOut.NDP,dataOut.DPL,2),'float32') | |
1230 | self.kbx=numpy.zeros((dataOut.NDP,dataOut.DPL,2),'float32') |
|
1230 | self.kbx=numpy.zeros((dataOut.NDP,dataOut.DPL,2),'float32') | |
1231 | self.kby=numpy.zeros((dataOut.NDP,dataOut.DPL,2),'float32') |
|
1231 | self.kby=numpy.zeros((dataOut.NDP,dataOut.DPL,2),'float32') | |
1232 | self.kax2=numpy.zeros((dataOut.NDP,dataOut.DPL,2),'float32') |
|
1232 | self.kax2=numpy.zeros((dataOut.NDP,dataOut.DPL,2),'float32') | |
1233 | self.kay2=numpy.zeros((dataOut.NDP,dataOut.DPL,2),'float32') |
|
1233 | self.kay2=numpy.zeros((dataOut.NDP,dataOut.DPL,2),'float32') | |
1234 | self.kbx2=numpy.zeros((dataOut.NDP,dataOut.DPL,2),'float32') |
|
1234 | self.kbx2=numpy.zeros((dataOut.NDP,dataOut.DPL,2),'float32') | |
1235 | self.kby2=numpy.zeros((dataOut.NDP,dataOut.DPL,2),'float32') |
|
1235 | self.kby2=numpy.zeros((dataOut.NDP,dataOut.DPL,2),'float32') | |
1236 | self.kaxbx=numpy.zeros((dataOut.NDP,dataOut.DPL,2),'float32') |
|
1236 | self.kaxbx=numpy.zeros((dataOut.NDP,dataOut.DPL,2),'float32') | |
1237 | self.kaxby=numpy.zeros((dataOut.NDP,dataOut.DPL,2),'float32') |
|
1237 | self.kaxby=numpy.zeros((dataOut.NDP,dataOut.DPL,2),'float32') | |
1238 | self.kaybx=numpy.zeros((dataOut.NDP,dataOut.DPL,2),'float32') |
|
1238 | self.kaybx=numpy.zeros((dataOut.NDP,dataOut.DPL,2),'float32') | |
1239 | self.kayby=numpy.zeros((dataOut.NDP,dataOut.DPL,2),'float32') |
|
1239 | self.kayby=numpy.zeros((dataOut.NDP,dataOut.DPL,2),'float32') | |
1240 | self.kaxay=numpy.zeros((dataOut.NDP,dataOut.DPL,2),'float32') |
|
1240 | self.kaxay=numpy.zeros((dataOut.NDP,dataOut.DPL,2),'float32') | |
1241 | self.kbxby=numpy.zeros((dataOut.NDP,dataOut.DPL,2),'float32') |
|
1241 | self.kbxby=numpy.zeros((dataOut.NDP,dataOut.DPL,2),'float32') | |
1242 |
|
1242 | |||
1243 | for i in range(self.cax_navg[0].shape[0]): |
|
1243 | for i in range(self.cax_navg[0].shape[0]): | |
1244 | for j in range(self.cax_navg[0].shape[1]): |
|
1244 | for j in range(self.cax_navg[0].shape[1]): | |
1245 | for k in range(self.cax_navg[0].shape[2]): |
|
1245 | for k in range(self.cax_navg[0].shape[2]): | |
1246 | data_navg=[item[i,j,k] for item in self.cax_navg] |
|
1246 | data_navg=[item[i,j,k] for item in self.cax_navg] | |
1247 | self.kax[i,j,k]=self.medi(data_navg,dataOut.NAVG,dataOut.nkill) |
|
1247 | self.kax[i,j,k]=self.medi(data_navg,dataOut.NAVG,dataOut.nkill) | |
1248 | data_navg=[item[i,j,k] for item in self.cay_navg] |
|
1248 | data_navg=[item[i,j,k] for item in self.cay_navg] | |
1249 | self.kay[i,j,k]=self.medi(data_navg,dataOut.NAVG,dataOut.nkill) |
|
1249 | self.kay[i,j,k]=self.medi(data_navg,dataOut.NAVG,dataOut.nkill) | |
1250 | data_navg=[item[i,j,k] for item in self.cbx_navg] |
|
1250 | data_navg=[item[i,j,k] for item in self.cbx_navg] | |
1251 | self.kbx[i,j,k]=self.medi(data_navg,dataOut.NAVG,dataOut.nkill) |
|
1251 | self.kbx[i,j,k]=self.medi(data_navg,dataOut.NAVG,dataOut.nkill) | |
1252 | data_navg=[item[i,j,k] for item in self.cby_navg] |
|
1252 | data_navg=[item[i,j,k] for item in self.cby_navg] | |
1253 | self.kby[i,j,k]=self.medi(data_navg,dataOut.NAVG,dataOut.nkill) |
|
1253 | self.kby[i,j,k]=self.medi(data_navg,dataOut.NAVG,dataOut.nkill) | |
1254 | data_navg=[item[i,j,k] for item in self.cax2_navg] |
|
1254 | data_navg=[item[i,j,k] for item in self.cax2_navg] | |
1255 | self.kax2[i,j,k]=self.medi(data_navg,dataOut.NAVG,dataOut.nkill) |
|
1255 | self.kax2[i,j,k]=self.medi(data_navg,dataOut.NAVG,dataOut.nkill) | |
1256 | data_navg=[item[i,j,k] for item in self.cay2_navg] |
|
1256 | data_navg=[item[i,j,k] for item in self.cay2_navg] | |
1257 | self.kay2[i,j,k]=self.medi(data_navg,dataOut.NAVG,dataOut.nkill) |
|
1257 | self.kay2[i,j,k]=self.medi(data_navg,dataOut.NAVG,dataOut.nkill) | |
1258 | data_navg=[item[i,j,k] for item in self.cbx2_navg] |
|
1258 | data_navg=[item[i,j,k] for item in self.cbx2_navg] | |
1259 | self.kbx2[i,j,k]=self.medi(data_navg,dataOut.NAVG,dataOut.nkill) |
|
1259 | self.kbx2[i,j,k]=self.medi(data_navg,dataOut.NAVG,dataOut.nkill) | |
1260 | data_navg=[item[i,j,k] for item in self.cby2_navg] |
|
1260 | data_navg=[item[i,j,k] for item in self.cby2_navg] | |
1261 | self.kby2[i,j,k]=self.medi(data_navg,dataOut.NAVG,dataOut.nkill) |
|
1261 | self.kby2[i,j,k]=self.medi(data_navg,dataOut.NAVG,dataOut.nkill) | |
1262 | data_navg=[item[i,j,k] for item in self.caxbx_navg] |
|
1262 | data_navg=[item[i,j,k] for item in self.caxbx_navg] | |
1263 | self.kaxbx[i,j,k]=self.medi(data_navg,dataOut.NAVG,dataOut.nkill) |
|
1263 | self.kaxbx[i,j,k]=self.medi(data_navg,dataOut.NAVG,dataOut.nkill) | |
1264 | data_navg=[item[i,j,k] for item in self.caxby_navg] |
|
1264 | data_navg=[item[i,j,k] for item in self.caxby_navg] | |
1265 | self.kaxby[i,j,k]=self.medi(data_navg,dataOut.NAVG,dataOut.nkill) |
|
1265 | self.kaxby[i,j,k]=self.medi(data_navg,dataOut.NAVG,dataOut.nkill) | |
1266 | data_navg=[item[i,j,k] for item in self.caybx_navg] |
|
1266 | data_navg=[item[i,j,k] for item in self.caybx_navg] | |
1267 | self.kaybx[i,j,k]=self.medi(data_navg,dataOut.NAVG,dataOut.nkill) |
|
1267 | self.kaybx[i,j,k]=self.medi(data_navg,dataOut.NAVG,dataOut.nkill) | |
1268 | data_navg=[item[i,j,k] for item in self.cayby_navg] |
|
1268 | data_navg=[item[i,j,k] for item in self.cayby_navg] | |
1269 | self.kayby[i,j,k]=self.medi(data_navg,dataOut.NAVG,dataOut.nkill) |
|
1269 | self.kayby[i,j,k]=self.medi(data_navg,dataOut.NAVG,dataOut.nkill) | |
1270 | data_navg=[item[i,j,k] for item in self.caxay_navg] |
|
1270 | data_navg=[item[i,j,k] for item in self.caxay_navg] | |
1271 | self.kaxay[i,j,k]=self.medi(data_navg,dataOut.NAVG,dataOut.nkill) |
|
1271 | self.kaxay[i,j,k]=self.medi(data_navg,dataOut.NAVG,dataOut.nkill) | |
1272 | data_navg=[item[i,j,k] for item in self.cbxby_navg] |
|
1272 | data_navg=[item[i,j,k] for item in self.cbxby_navg] | |
1273 | self.kbxby[i,j,k]=self.medi(data_navg,dataOut.NAVG,dataOut.nkill) |
|
1273 | self.kbxby[i,j,k]=self.medi(data_navg,dataOut.NAVG,dataOut.nkill) | |
1274 |
|
1274 | |||
1275 |
|
1275 | |||
1276 | dataOut.kax=self.kax |
|
1276 | dataOut.kax=self.kax | |
1277 | dataOut.kay=self.kay |
|
1277 | dataOut.kay=self.kay | |
1278 | dataOut.kbx=self.kbx |
|
1278 | dataOut.kbx=self.kbx | |
1279 | dataOut.kby=self.kby |
|
1279 | dataOut.kby=self.kby | |
1280 | dataOut.kax2=self.kax2 |
|
1280 | dataOut.kax2=self.kax2 | |
1281 | dataOut.kay2=self.kay2 |
|
1281 | dataOut.kay2=self.kay2 | |
1282 | dataOut.kbx2=self.kbx2 |
|
1282 | dataOut.kbx2=self.kbx2 | |
1283 | dataOut.kby2=self.kby2 |
|
1283 | dataOut.kby2=self.kby2 | |
1284 | dataOut.kaxbx=self.kaxbx |
|
1284 | dataOut.kaxbx=self.kaxbx | |
1285 | dataOut.kaxby=self.kaxby |
|
1285 | dataOut.kaxby=self.kaxby | |
1286 | dataOut.kaybx=self.kaybx |
|
1286 | dataOut.kaybx=self.kaybx | |
1287 | dataOut.kayby=self.kayby |
|
1287 | dataOut.kayby=self.kayby | |
1288 | dataOut.kaxay=self.kaxay |
|
1288 | dataOut.kaxay=self.kaxay | |
1289 | dataOut.kbxby=self.kbxby |
|
1289 | dataOut.kbxby=self.kbxby | |
1290 |
|
1290 | |||
1291 | self.bcounter=0 |
|
1291 | self.bcounter=0 | |
1292 |
|
1292 | |||
1293 | dataOut.crossprods=numpy.zeros((3,4,numpy.shape(dataOut.kax)[0],numpy.shape(dataOut.kax)[1],numpy.shape(dataOut.kax)[2])) |
|
1293 | dataOut.crossprods=numpy.zeros((3,4,numpy.shape(dataOut.kax)[0],numpy.shape(dataOut.kax)[1],numpy.shape(dataOut.kax)[2])) | |
1294 |
|
1294 | |||
1295 | dataOut.crossprods[0]=[dataOut.kax,dataOut.kay,dataOut.kbx,dataOut.kby] |
|
1295 | dataOut.crossprods[0]=[dataOut.kax,dataOut.kay,dataOut.kbx,dataOut.kby] | |
1296 | dataOut.crossprods[1]=[dataOut.kax2,dataOut.kay2,dataOut.kbx2,dataOut.kby2] |
|
1296 | dataOut.crossprods[1]=[dataOut.kax2,dataOut.kay2,dataOut.kbx2,dataOut.kby2] | |
1297 | dataOut.crossprods[2]=[dataOut.kaxay,dataOut.kbxby,dataOut.kaxbx,dataOut.kaxby] |
|
1297 | dataOut.crossprods[2]=[dataOut.kaxay,dataOut.kbxby,dataOut.kaxbx,dataOut.kaxby] | |
1298 | #print("before: ",self.dataOut.noise_final) |
|
1298 | #print("before: ",self.dataOut.noise_final) | |
1299 | dataOut.data_for_RTI_DP=numpy.zeros((3,dataOut.NDP)) |
|
1299 | dataOut.data_for_RTI_DP=numpy.zeros((3,dataOut.NDP)) | |
1300 | dataOut.data_for_RTI_DP[0],dataOut.data_for_RTI_DP[1],dataOut.data_for_RTI_DP[2]=self.RTI_COLUMN(dataOut.kax2,dataOut.kay2,dataOut.kbx2,dataOut.kby2,dataOut.kaxbx,dataOut.kayby,dataOut.kaybx,dataOut.kaxby, dataOut.NDP) |
|
1300 | dataOut.data_for_RTI_DP[0],dataOut.data_for_RTI_DP[1],dataOut.data_for_RTI_DP[2]=self.RTI_COLUMN(dataOut.kax2,dataOut.kay2,dataOut.kbx2,dataOut.kby2,dataOut.kaxbx,dataOut.kayby,dataOut.kaybx,dataOut.kaxby, dataOut.NDP) | |
1301 |
|
1301 | |||
1302 |
|
1302 | |||
1303 |
|
1303 | |||
1304 | def RTI_COLUMN(self,kax2,kay2,kbx2,kby2,kaxbx,kayby,kaybx,kaxby, NDP): |
|
1304 | def RTI_COLUMN(self,kax2,kay2,kbx2,kby2,kaxbx,kayby,kaybx,kaxby, NDP): | |
1305 | x00=numpy.zeros(NDP,dtype='float32') |
|
1305 | x00=numpy.zeros(NDP,dtype='float32') | |
1306 | x01=numpy.zeros(NDP,dtype='float32') |
|
1306 | x01=numpy.zeros(NDP,dtype='float32') | |
1307 | x02=numpy.zeros(NDP,dtype='float32') |
|
1307 | x02=numpy.zeros(NDP,dtype='float32') | |
1308 | for j in range(2):# first couple lags |
|
1308 | for j in range(2):# first couple lags | |
1309 | for k in range(2): #flip |
|
1309 | for k in range(2): #flip | |
1310 | for i in range(NDP): # |
|
1310 | for i in range(NDP): # | |
1311 | fx=numpy.sqrt((kaxbx[i,j,k]+kayby[i,j,k])**2+(kaybx[i,j,k]-kaxby[i,j,k])**2) |
|
1311 | fx=numpy.sqrt((kaxbx[i,j,k]+kayby[i,j,k])**2+(kaybx[i,j,k]-kaxby[i,j,k])**2) | |
1312 | x00[i]=x00[i]+(kax2[i,j,k]+kay2[i,j,k]) |
|
1312 | x00[i]=x00[i]+(kax2[i,j,k]+kay2[i,j,k]) | |
1313 | x01[i]=x01[i]+(kbx2[i,j,k]+kby2[i,j,k]) |
|
1313 | x01[i]=x01[i]+(kbx2[i,j,k]+kby2[i,j,k]) | |
1314 | x02[i]=x02[i]+fx |
|
1314 | x02[i]=x02[i]+fx | |
1315 |
|
1315 | |||
1316 | x00[i]=10.0*numpy.log10(x00[i]/512.) |
|
1316 | x00[i]=10.0*numpy.log10(x00[i]/512.) | |
1317 | x01[i]=10.0*numpy.log10(x01[i]/512.) |
|
1317 | x01[i]=10.0*numpy.log10(x01[i]/512.) | |
1318 | x02[i]=10.0*numpy.log10(x02[i]) |
|
1318 | x02[i]=10.0*numpy.log10(x02[i]) | |
1319 | return x02,x00,x01 |
|
1319 | return x02,x00,x01 | |
1320 |
|
1320 | |||
1321 |
|
1321 | |||
1322 |
|
1322 | |||
1323 |
|
1323 | |||
1324 |
|
1324 | |||
1325 |
|
1325 | |||
1326 | #30/03/2020: |
|
1326 | #30/03/2020: | |
1327 | def noisevectorizer(self,NSCAN,nProfiles,NR,MAXNRANGENDT,noisevector,data,dc): |
|
1327 | def noisevectorizer(self,NSCAN,nProfiles,NR,MAXNRANGENDT,noisevector,data,dc): | |
1328 |
|
1328 | |||
1329 | rnormalizer= 1./(float(nProfiles - NSCAN)) |
|
1329 | rnormalizer= 1./(float(nProfiles - NSCAN)) | |
1330 | #rnormalizer= float(NSCAN)/((float(nProfiles - NSCAN))*float(MAXNRANGENDT)) |
|
1330 | #rnormalizer= float(NSCAN)/((float(nProfiles - NSCAN))*float(MAXNRANGENDT)) | |
1331 | for i in range(NR): |
|
1331 | for i in range(NR): | |
1332 | for j in range(MAXNRANGENDT): |
|
1332 | for j in range(MAXNRANGENDT): | |
1333 | for k in range(NSCAN,nProfiles): |
|
1333 | for k in range(NSCAN,nProfiles): | |
1334 | #TODO:integrate just 2nd quartile gates |
|
1334 | #TODO:integrate just 2nd quartile gates | |
1335 | if k==NSCAN: |
|
1335 | if k==NSCAN: | |
1336 | noisevector[j][i][self.bcounter]=(abs(data[i][k][j]-dc[i])**2)*rnormalizer |
|
1336 | noisevector[j][i][self.bcounter]=(abs(data[i][k][j]-dc[i])**2)*rnormalizer | |
1337 | else: |
|
1337 | else: | |
1338 | noisevector[j][i][self.bcounter]+=(abs(data[i][k][j]-dc[i])**2)*rnormalizer |
|
1338 | noisevector[j][i][self.bcounter]+=(abs(data[i][k][j]-dc[i])**2)*rnormalizer | |
1339 |
|
1339 | |||
1340 |
|
1340 | |||
1341 |
|
1341 | |||
1342 |
|
1342 | |||
1343 | def noise_hs4x(self, ndatax, datax): |
|
1343 | def noise_hs4x(self, ndatax, datax): | |
1344 | divider=10#divider was originally 10 |
|
1344 | divider=10#divider was originally 10 | |
1345 | noise=0.0 |
|
1345 | noise=0.0 | |
1346 | data=numpy.zeros(ndatax,'float32') |
|
1346 | data=numpy.zeros(ndatax,'float32') | |
1347 | ndata1=int(ndatax/4) |
|
1347 | ndata1=int(ndatax/4) | |
1348 | ndata2=int(2.5*(ndatax/4.)) |
|
1348 | ndata2=int(2.5*(ndatax/4.)) | |
1349 | ndata=int(ndata2-ndata1) |
|
1349 | ndata=int(ndata2-ndata1) | |
1350 | sorts=sorted(datax) |
|
1350 | sorts=sorted(datax) | |
1351 |
|
1351 | |||
1352 | for k in range(ndata2): # select just second quartile |
|
1352 | for k in range(ndata2): # select just second quartile | |
1353 | data[k]=sorts[k+ndata1] |
|
1353 | data[k]=sorts[k+ndata1] | |
1354 | nums_min= int(ndata/divider) |
|
1354 | nums_min= int(ndata/divider) | |
1355 | if(int(ndata/divider)> 2): |
|
1355 | if(int(ndata/divider)> 2): | |
1356 | nums_min= int(ndata/divider) |
|
1356 | nums_min= int(ndata/divider) | |
1357 | else: |
|
1357 | else: | |
1358 | nums_min=2 |
|
1358 | nums_min=2 | |
1359 | sump=0.0 |
|
1359 | sump=0.0 | |
1360 | sumq=0.0 |
|
1360 | sumq=0.0 | |
1361 | j=0 |
|
1361 | j=0 | |
1362 | cont=1 |
|
1362 | cont=1 | |
1363 | while ( (cont==1) and (j<ndata)): |
|
1363 | while ( (cont==1) and (j<ndata)): | |
1364 | sump+=data[j] |
|
1364 | sump+=data[j] | |
1365 | sumq+= data[j]*data[j] |
|
1365 | sumq+= data[j]*data[j] | |
1366 | j=j+1 |
|
1366 | j=j+1 | |
1367 | if (j> nums_min): |
|
1367 | if (j> nums_min): | |
1368 | rtest= float(j/(j-1)) +1.0/ndata |
|
1368 | rtest= float(j/(j-1)) +1.0/ndata | |
1369 | if( (sumq*j) > (rtest*sump*sump ) ): |
|
1369 | if( (sumq*j) > (rtest*sump*sump ) ): | |
1370 | j=j-1 |
|
1370 | j=j-1 | |
1371 | sump-= data[j] |
|
1371 | sump-= data[j] | |
1372 | sumq-=data[j]*data[j] |
|
1372 | sumq-=data[j]*data[j] | |
1373 | cont= 0 |
|
1373 | cont= 0 | |
1374 | noise= (sump/j) |
|
1374 | noise= (sump/j) | |
1375 |
|
1375 | |||
1376 | return noise |
|
1376 | return noise | |
1377 |
|
1377 | |||
1378 |
|
1378 | |||
1379 |
|
1379 | |||
1380 | def run(self, dataOut, NLAG=16, NRANGE=0, NCAL=0, DPL=11, |
|
1380 | def run(self, dataOut, NLAG=16, NRANGE=0, NCAL=0, DPL=11, | |
1381 | NDN=0, NDT=66, NDP=66, NSCAN=132, |
|
1381 | NDN=0, NDT=66, NDP=66, NSCAN=132, | |
1382 | flags_array=(0, 30, 60, 90, 120, 150, 180, 210, 240, 270, 300), NAVG=16, nkill=6, **kwargs): |
|
1382 | flags_array=(0, 30, 60, 90, 120, 150, 180, 210, 240, 270, 300), NAVG=16, nkill=6, **kwargs): | |
1383 |
|
1383 | |||
1384 | dataOut.NLAG=NLAG |
|
1384 | dataOut.NLAG=NLAG | |
1385 | dataOut.NR=len(dataOut.channelList) |
|
1385 | dataOut.NR=len(dataOut.channelList) | |
1386 | dataOut.NRANGE=NRANGE |
|
1386 | dataOut.NRANGE=NRANGE | |
1387 | dataOut.NCAL=NCAL |
|
1387 | dataOut.NCAL=NCAL | |
1388 | dataOut.DPL=DPL |
|
1388 | dataOut.DPL=DPL | |
1389 | dataOut.NDN=NDN |
|
1389 | dataOut.NDN=NDN | |
1390 | dataOut.NDT=NDT |
|
1390 | dataOut.NDT=NDT | |
1391 | dataOut.NDP=NDP |
|
1391 | dataOut.NDP=NDP | |
1392 | dataOut.NSCAN=NSCAN |
|
1392 | dataOut.NSCAN=NSCAN | |
1393 | dataOut.DH=dataOut.heightList[1]-dataOut.heightList[0] |
|
1393 | dataOut.DH=dataOut.heightList[1]-dataOut.heightList[0] | |
1394 | dataOut.H0=int(dataOut.heightList[0]) |
|
1394 | dataOut.H0=int(dataOut.heightList[0]) | |
1395 | dataOut.flags_array=flags_array |
|
1395 | dataOut.flags_array=flags_array | |
1396 | dataOut.NAVG=NAVG |
|
1396 | dataOut.NAVG=NAVG | |
1397 | dataOut.nkill=nkill |
|
1397 | dataOut.nkill=nkill | |
1398 | dataOut.flagNoData = True |
|
1398 | dataOut.flagNoData = True | |
1399 |
|
1399 | |||
1400 | self.get_dc(dataOut) |
|
1400 | self.get_dc(dataOut) | |
1401 | self.get_products_cabxys(dataOut) |
|
1401 | self.get_products_cabxys(dataOut) | |
1402 | self.cabxys_navg(dataOut) |
|
1402 | self.cabxys_navg(dataOut) | |
1403 | self.noise_estimation4x_DP(dataOut) |
|
1403 | self.noise_estimation4x_DP(dataOut) | |
1404 | self.kabxys(dataOut) |
|
1404 | self.kabxys(dataOut) | |
1405 |
|
1405 | |||
1406 | return dataOut |
|
1406 | return dataOut | |
1407 |
|
1407 | |||
1408 |
|
1408 | |||
1409 |
|
1409 | |||
1410 | class IntegrationDP(Operation): |
|
1410 | class IntegrationDP(Operation): | |
1411 | ''' |
|
1411 | ''' | |
1412 | Written by R. Flores |
|
1412 | Written by R. Flores | |
1413 | ''' |
|
1413 | ''' | |
1414 | """Operation to integrate the Double Pulse data. |
|
1414 | """Operation to integrate the Double Pulse data. | |
1415 |
|
1415 | |||
1416 | Parameters: |
|
1416 | Parameters: | |
1417 | ----------- |
|
1417 | ----------- | |
1418 | nint : int |
|
1418 | nint : int | |
1419 | Number of integrations. |
|
1419 | Number of integrations. | |
1420 |
|
1420 | |||
1421 | Example |
|
1421 | Example | |
1422 | -------- |
|
1422 | -------- | |
1423 |
|
1423 | |||
1424 | op = proc_unit.addOperation(name='IntegrationDP', optype='other') |
|
1424 | op = proc_unit.addOperation(name='IntegrationDP', optype='other') | |
1425 | op.addParameter(name='nint', value='30', format='int') |
|
1425 | op.addParameter(name='nint', value='30', format='int') | |
1426 |
|
1426 | |||
1427 | """ |
|
1427 | """ | |
1428 |
|
1428 | |||
1429 | def __init__(self, **kwargs): |
|
1429 | def __init__(self, **kwargs): | |
1430 |
|
1430 | |||
1431 | Operation.__init__(self, **kwargs) |
|
1431 | Operation.__init__(self, **kwargs) | |
1432 |
|
1432 | |||
1433 | self.counter=0 |
|
1433 | self.counter=0 | |
1434 | self.aux=0 |
|
1434 | self.aux=0 | |
1435 | self.init_time=None |
|
1435 | self.init_time=None | |
1436 |
|
1436 | |||
1437 | def integration_for_double_pulse(self,dataOut): |
|
1437 | def integration_for_double_pulse(self,dataOut): | |
1438 |
|
1438 | |||
1439 | if self.aux==1: |
|
1439 | if self.aux==1: | |
1440 |
|
1440 | |||
1441 | dataOut.TimeBlockSeconds_for_dp_power=dataOut.utctime |
|
1441 | dataOut.TimeBlockSeconds_for_dp_power=dataOut.utctime | |
1442 | dataOut.bd_time=gmtime(dataOut.TimeBlockSeconds_for_dp_power) |
|
1442 | dataOut.bd_time=gmtime(dataOut.TimeBlockSeconds_for_dp_power) | |
1443 | dataOut.year=dataOut.bd_time.tm_year+(dataOut.bd_time.tm_yday-1)/364.0 |
|
1443 | dataOut.year=dataOut.bd_time.tm_year+(dataOut.bd_time.tm_yday-1)/364.0 | |
1444 | dataOut.ut_Faraday=dataOut.bd_time.tm_hour+dataOut.bd_time.tm_min/60.0+dataOut.bd_time.tm_sec/3600.0 |
|
1444 | dataOut.ut_Faraday=dataOut.bd_time.tm_hour+dataOut.bd_time.tm_min/60.0+dataOut.bd_time.tm_sec/3600.0 | |
1445 | self.aux=0 |
|
1445 | self.aux=0 | |
1446 |
|
1446 | |||
1447 | if self.counter==0: |
|
1447 | if self.counter==0: | |
1448 |
|
1448 | |||
1449 | tmpx=numpy.zeros((dataOut.NDP,dataOut.DPL,2),'float32') |
|
1449 | tmpx=numpy.zeros((dataOut.NDP,dataOut.DPL,2),'float32') | |
1450 | dataOut.kabxys_integrated=[tmpx,tmpx,tmpx,tmpx,tmpx,tmpx,tmpx,tmpx,tmpx,tmpx,tmpx,tmpx,tmpx,tmpx] |
|
1450 | dataOut.kabxys_integrated=[tmpx,tmpx,tmpx,tmpx,tmpx,tmpx,tmpx,tmpx,tmpx,tmpx,tmpx,tmpx,tmpx,tmpx] | |
1451 | self.init_time=dataOut.utctime |
|
1451 | self.init_time=dataOut.utctime | |
1452 |
|
1452 | |||
1453 | if self.counter < dataOut.nint: |
|
1453 | if self.counter < dataOut.nint: | |
1454 |
|
1454 | |||
1455 | dataOut.final_cross_products=[dataOut.kax,dataOut.kay,dataOut.kbx,dataOut.kby,dataOut.kax2,dataOut.kay2,dataOut.kbx2,dataOut.kby2,dataOut.kaxbx,dataOut.kaxby,dataOut.kaybx,dataOut.kayby,dataOut.kaxay,dataOut.kbxby] |
|
1455 | dataOut.final_cross_products=[dataOut.kax,dataOut.kay,dataOut.kbx,dataOut.kby,dataOut.kax2,dataOut.kay2,dataOut.kbx2,dataOut.kby2,dataOut.kaxbx,dataOut.kaxby,dataOut.kaybx,dataOut.kayby,dataOut.kaxay,dataOut.kbxby] | |
1456 |
|
1456 | |||
1457 | for ind in range(len(dataOut.kabxys_integrated)): #final cross products |
|
1457 | for ind in range(len(dataOut.kabxys_integrated)): #final cross products | |
1458 | dataOut.kabxys_integrated[ind]=dataOut.kabxys_integrated[ind]+dataOut.final_cross_products[ind] |
|
1458 | dataOut.kabxys_integrated[ind]=dataOut.kabxys_integrated[ind]+dataOut.final_cross_products[ind] | |
1459 |
|
1459 | |||
1460 | self.counter+=1 |
|
1460 | self.counter+=1 | |
1461 |
|
1461 | |||
1462 | if self.counter==dataOut.nint-1: |
|
1462 | if self.counter==dataOut.nint-1: | |
1463 | self.aux=1 |
|
1463 | self.aux=1 | |
1464 |
|
1464 | |||
1465 | if self.counter==dataOut.nint: |
|
1465 | if self.counter==dataOut.nint: | |
1466 | dataOut.flagNoData=False |
|
1466 | dataOut.flagNoData=False | |
1467 | dataOut.utctime=self.init_time |
|
1467 | dataOut.utctime=self.init_time | |
1468 | self.counter=0 |
|
1468 | self.counter=0 | |
1469 |
|
1469 | |||
1470 |
|
1470 | |||
1471 | def run(self,dataOut,nint=20): |
|
1471 | def run(self,dataOut,nint=20): | |
1472 |
|
1472 | |||
1473 | dataOut.flagNoData=True |
|
1473 | dataOut.flagNoData=True | |
1474 | dataOut.nint=nint |
|
1474 | dataOut.nint=nint | |
1475 | dataOut.paramInterval=0#int(dataOut.nint*dataOut.header[7][0]*2 ) |
|
1475 | dataOut.paramInterval=0#int(dataOut.nint*dataOut.header[7][0]*2 ) | |
1476 | dataOut.lat=-11.95 |
|
1476 | dataOut.lat=-11.95 | |
1477 | dataOut.lon=-76.87 |
|
1477 | dataOut.lon=-76.87 | |
1478 |
|
1478 | |||
1479 | self.integration_for_double_pulse(dataOut) |
|
1479 | self.integration_for_double_pulse(dataOut) | |
1480 |
|
1480 | |||
1481 | return dataOut |
|
1481 | return dataOut | |
1482 |
|
1482 | |||
1483 |
|
1483 | |||
1484 | class SumFlips(Operation): |
|
1484 | class SumFlips(Operation): | |
1485 | ''' |
|
1485 | ''' | |
1486 | Written by R. Flores |
|
1486 | Written by R. Flores | |
1487 | ''' |
|
1487 | ''' | |
1488 | """Operation to sum the flip and unflip part of certain cross products of the Double Pulse. |
|
1488 | """Operation to sum the flip and unflip part of certain cross products of the Double Pulse. | |
1489 |
|
1489 | |||
1490 | Parameters: |
|
1490 | Parameters: | |
1491 | ----------- |
|
1491 | ----------- | |
1492 | None |
|
1492 | None | |
1493 |
|
1493 | |||
1494 | Example |
|
1494 | Example | |
1495 | -------- |
|
1495 | -------- | |
1496 |
|
1496 | |||
1497 | op = proc_unit.addOperation(name='SumFlips', optype='other') |
|
1497 | op = proc_unit.addOperation(name='SumFlips', optype='other') | |
1498 |
|
1498 | |||
1499 | """ |
|
1499 | """ | |
1500 |
|
1500 | |||
1501 | def __init__(self, **kwargs): |
|
1501 | def __init__(self, **kwargs): | |
1502 |
|
1502 | |||
1503 | Operation.__init__(self, **kwargs) |
|
1503 | Operation.__init__(self, **kwargs) | |
1504 |
|
1504 | |||
1505 |
|
1505 | |||
1506 | def rint2DP(self,dataOut): |
|
1506 | def rint2DP(self,dataOut): | |
1507 |
|
1507 | |||
1508 | dataOut.rnint2=numpy.zeros(dataOut.DPL,'float32') |
|
1508 | dataOut.rnint2=numpy.zeros(dataOut.DPL,'float32') | |
1509 |
|
1509 | |||
1510 | for l in range(dataOut.DPL): |
|
1510 | for l in range(dataOut.DPL): | |
1511 |
|
1511 | |||
1512 | dataOut.rnint2[l]=1.0/(dataOut.nint*dataOut.NAVG*12.0) |
|
1512 | dataOut.rnint2[l]=1.0/(dataOut.nint*dataOut.NAVG*12.0) | |
1513 |
|
1513 | |||
1514 |
|
1514 | |||
1515 | def SumLags(self,dataOut): |
|
1515 | def SumLags(self,dataOut): | |
1516 |
|
1516 | |||
1517 | for l in range(dataOut.DPL): |
|
1517 | for l in range(dataOut.DPL): | |
1518 | dataOut.kabxys_integrated[4][:,l,0]=(dataOut.kabxys_integrated[4][:,l,0]+dataOut.kabxys_integrated[4][:,l,1])*dataOut.rnint2[l] |
|
1518 | dataOut.kabxys_integrated[4][:,l,0]=(dataOut.kabxys_integrated[4][:,l,0]+dataOut.kabxys_integrated[4][:,l,1])*dataOut.rnint2[l] | |
1519 | dataOut.kabxys_integrated[5][:,l,0]=(dataOut.kabxys_integrated[5][:,l,0]+dataOut.kabxys_integrated[5][:,l,1])*dataOut.rnint2[l] |
|
1519 | dataOut.kabxys_integrated[5][:,l,0]=(dataOut.kabxys_integrated[5][:,l,0]+dataOut.kabxys_integrated[5][:,l,1])*dataOut.rnint2[l] | |
1520 | dataOut.kabxys_integrated[6][:,l,0]=(dataOut.kabxys_integrated[6][:,l,0]+dataOut.kabxys_integrated[6][:,l,1])*dataOut.rnint2[l] |
|
1520 | dataOut.kabxys_integrated[6][:,l,0]=(dataOut.kabxys_integrated[6][:,l,0]+dataOut.kabxys_integrated[6][:,l,1])*dataOut.rnint2[l] | |
1521 | dataOut.kabxys_integrated[7][:,l,0]=(dataOut.kabxys_integrated[7][:,l,0]+dataOut.kabxys_integrated[7][:,l,1])*dataOut.rnint2[l] |
|
1521 | dataOut.kabxys_integrated[7][:,l,0]=(dataOut.kabxys_integrated[7][:,l,0]+dataOut.kabxys_integrated[7][:,l,1])*dataOut.rnint2[l] | |
1522 |
|
1522 | |||
1523 | dataOut.kabxys_integrated[8][:,l,0]=(dataOut.kabxys_integrated[8][:,l,0]-dataOut.kabxys_integrated[8][:,l,1])*dataOut.rnint2[l] |
|
1523 | dataOut.kabxys_integrated[8][:,l,0]=(dataOut.kabxys_integrated[8][:,l,0]-dataOut.kabxys_integrated[8][:,l,1])*dataOut.rnint2[l] | |
1524 | dataOut.kabxys_integrated[9][:,l,0]=(dataOut.kabxys_integrated[9][:,l,0]-dataOut.kabxys_integrated[9][:,l,1])*dataOut.rnint2[l] |
|
1524 | dataOut.kabxys_integrated[9][:,l,0]=(dataOut.kabxys_integrated[9][:,l,0]-dataOut.kabxys_integrated[9][:,l,1])*dataOut.rnint2[l] | |
1525 | dataOut.kabxys_integrated[10][:,l,0]=(dataOut.kabxys_integrated[10][:,l,0]-dataOut.kabxys_integrated[10][:,l,1])*dataOut.rnint2[l] |
|
1525 | dataOut.kabxys_integrated[10][:,l,0]=(dataOut.kabxys_integrated[10][:,l,0]-dataOut.kabxys_integrated[10][:,l,1])*dataOut.rnint2[l] | |
1526 | dataOut.kabxys_integrated[11][:,l,0]=(dataOut.kabxys_integrated[11][:,l,0]-dataOut.kabxys_integrated[11][:,l,1])*dataOut.rnint2[l] |
|
1526 | dataOut.kabxys_integrated[11][:,l,0]=(dataOut.kabxys_integrated[11][:,l,0]-dataOut.kabxys_integrated[11][:,l,1])*dataOut.rnint2[l] | |
1527 |
|
1527 | |||
1528 | def run(self,dataOut): |
|
1528 | def run(self,dataOut): | |
1529 |
|
1529 | |||
1530 | self.rint2DP(dataOut) |
|
1530 | self.rint2DP(dataOut) | |
1531 | self.SumLags(dataOut) |
|
1531 | self.SumLags(dataOut) | |
1532 |
|
1532 | |||
1533 | return dataOut |
|
1533 | return dataOut | |
1534 |
|
1534 | |||
1535 |
|
1535 | |||
1536 | class FlagBadHeights(Operation): |
|
1536 | class FlagBadHeights(Operation): | |
1537 | ''' |
|
1537 | ''' | |
1538 | Written by R. Flores |
|
1538 | Written by R. Flores | |
1539 | ''' |
|
1539 | ''' | |
1540 | """Operation to flag bad heights (bad data) of the Double Pulse. |
|
1540 | """Operation to flag bad heights (bad data) of the Double Pulse. | |
1541 |
|
1541 | |||
1542 | Parameters: |
|
1542 | Parameters: | |
1543 | ----------- |
|
1543 | ----------- | |
1544 | None |
|
1544 | None | |
1545 |
|
1545 | |||
1546 | Example |
|
1546 | Example | |
1547 | -------- |
|
1547 | -------- | |
1548 |
|
1548 | |||
1549 | op = proc_unit.addOperation(name='FlagBadHeights', optype='other') |
|
1549 | op = proc_unit.addOperation(name='FlagBadHeights', optype='other') | |
1550 |
|
1550 | |||
1551 | """ |
|
1551 | """ | |
1552 |
|
1552 | |||
1553 | def __init__(self, **kwargs): |
|
1553 | def __init__(self, **kwargs): | |
1554 |
|
1554 | |||
1555 | Operation.__init__(self, **kwargs) |
|
1555 | Operation.__init__(self, **kwargs) | |
1556 |
|
1556 | |||
1557 | def run(self,dataOut): |
|
1557 | def run(self,dataOut): | |
1558 |
|
1558 | |||
1559 | dataOut.ibad=numpy.zeros((dataOut.NDP,dataOut.DPL),'int32') |
|
1559 | dataOut.ibad=numpy.zeros((dataOut.NDP,dataOut.DPL),'int32') | |
1560 |
|
1560 | |||
1561 | for j in range(dataOut.NDP): |
|
1561 | for j in range(dataOut.NDP): | |
1562 | for l in range(dataOut.DPL): |
|
1562 | for l in range(dataOut.DPL): | |
1563 | ip1=j+dataOut.NDP*(0+2*l) |
|
1563 | ip1=j+dataOut.NDP*(0+2*l) | |
1564 |
|
1564 | |||
1565 | if( (dataOut.kabxys_integrated[5][j,l,0] <= 0.) or (dataOut.kabxys_integrated[4][j,l,0] <= 0.) or (dataOut.kabxys_integrated[7][j,l,0] <= 0.) or (dataOut.kabxys_integrated[6][j,l,0] <= 0.)): |
|
1565 | if( (dataOut.kabxys_integrated[5][j,l,0] <= 0.) or (dataOut.kabxys_integrated[4][j,l,0] <= 0.) or (dataOut.kabxys_integrated[7][j,l,0] <= 0.) or (dataOut.kabxys_integrated[6][j,l,0] <= 0.)): | |
1566 | dataOut.ibad[j][l]=1 |
|
1566 | dataOut.ibad[j][l]=1 | |
1567 | else: |
|
1567 | else: | |
1568 | dataOut.ibad[j][l]=0 |
|
1568 | dataOut.ibad[j][l]=0 | |
1569 |
|
1569 | |||
1570 | return dataOut |
|
1570 | return dataOut | |
1571 |
|
1571 | |||
1572 | class FlagBadHeightsSpectra(Operation): |
|
1572 | class FlagBadHeightsSpectra(Operation): | |
1573 | ''' |
|
1573 | ''' | |
1574 | Written by R. Flores |
|
1574 | Written by R. Flores | |
1575 | ''' |
|
1575 | ''' | |
1576 | """Operation to flag bad heights (bad data) of the Double Pulse. |
|
1576 | """Operation to flag bad heights (bad data) of the Double Pulse. | |
1577 |
|
1577 | |||
1578 | Parameters: |
|
1578 | Parameters: | |
1579 | ----------- |
|
1579 | ----------- | |
1580 | None |
|
1580 | None | |
1581 |
|
1581 | |||
1582 | Example |
|
1582 | Example | |
1583 | -------- |
|
1583 | -------- | |
1584 |
|
1584 | |||
1585 | op = proc_unit.addOperation(name='FlagBadHeightsSpectra', optype='other') |
|
1585 | op = proc_unit.addOperation(name='FlagBadHeightsSpectra', optype='other') | |
1586 |
|
1586 | |||
1587 | """ |
|
1587 | """ | |
1588 |
|
1588 | |||
1589 | def __init__(self, **kwargs): |
|
1589 | def __init__(self, **kwargs): | |
1590 |
|
1590 | |||
1591 | Operation.__init__(self, **kwargs) |
|
1591 | Operation.__init__(self, **kwargs) | |
1592 |
|
1592 | |||
1593 | def run(self,dataOut): |
|
1593 | def run(self,dataOut): | |
1594 |
|
1594 | |||
1595 | dataOut.ibad=numpy.zeros((dataOut.NDP,dataOut.DPL),'int32') |
|
1595 | dataOut.ibad=numpy.zeros((dataOut.NDP,dataOut.DPL),'int32') | |
1596 |
|
1596 | |||
1597 | for j in range(dataOut.NDP): |
|
1597 | for j in range(dataOut.NDP): | |
1598 | for l in range(dataOut.DPL): |
|
1598 | for l in range(dataOut.DPL): | |
1599 | ip1=j+dataOut.NDP*(0+2*l) |
|
1599 | ip1=j+dataOut.NDP*(0+2*l) | |
1600 |
|
1600 | |||
1601 | if( (dataOut.kabxys_integrated[4][j,l,0] <= 0.) or (dataOut.kabxys_integrated[6][j,l,0] <= 0.)): |
|
1601 | if( (dataOut.kabxys_integrated[4][j,l,0] <= 0.) or (dataOut.kabxys_integrated[6][j,l,0] <= 0.)): | |
1602 | dataOut.ibad[j][l]=1 |
|
1602 | dataOut.ibad[j][l]=1 | |
1603 | else: |
|
1603 | else: | |
1604 | dataOut.ibad[j][l]=0 |
|
1604 | dataOut.ibad[j][l]=0 | |
1605 |
|
1605 | |||
1606 | return dataOut |
|
1606 | return dataOut | |
1607 |
|
1607 | |||
1608 | class CleanCohEchoes(Operation): |
|
1608 | class CleanCohEchoes(Operation): | |
1609 | ''' |
|
1609 | ''' | |
1610 | Written by R. Flores |
|
1610 | Written by R. Flores | |
1611 | ''' |
|
1611 | ''' | |
1612 | """Operation to clean coherent echoes. |
|
1612 | """Operation to clean coherent echoes. | |
1613 |
|
1613 | |||
1614 | Parameters: |
|
1614 | Parameters: | |
1615 | ----------- |
|
1615 | ----------- | |
1616 | None |
|
1616 | None | |
1617 |
|
1617 | |||
1618 | Example |
|
1618 | Example | |
1619 | -------- |
|
1619 | -------- | |
1620 |
|
1620 | |||
1621 | op = proc_unit.addOperation(name='CleanCohEchoes') |
|
1621 | op = proc_unit.addOperation(name='CleanCohEchoes') | |
1622 |
|
1622 | |||
1623 | """ |
|
1623 | """ | |
1624 |
|
1624 | |||
1625 | def __init__(self, **kwargs): |
|
1625 | def __init__(self, **kwargs): | |
1626 |
|
1626 | |||
1627 | Operation.__init__(self, **kwargs) |
|
1627 | Operation.__init__(self, **kwargs) | |
1628 |
|
1628 | |||
1629 | def remove_coh(self,pow): |
|
1629 | def remove_coh(self,pow): | |
1630 | q75,q25 = numpy.percentile(pow,[75,25],axis=0) |
|
1630 | q75,q25 = numpy.percentile(pow,[75,25],axis=0) | |
1631 | intr_qr = q75-q25 |
|
1631 | intr_qr = q75-q25 | |
1632 |
|
1632 | |||
1633 | max = q75+(1.5*intr_qr) |
|
1633 | max = q75+(1.5*intr_qr) | |
1634 | min = q25-(1.5*intr_qr) |
|
1634 | min = q25-(1.5*intr_qr) | |
1635 |
|
1635 | |||
1636 | pow[pow > max] = numpy.nan |
|
1636 | pow[pow > max] = numpy.nan | |
1637 |
|
1637 | |||
1638 | return pow |
|
1638 | return pow | |
1639 |
|
1639 | |||
1640 | def mad_based_outlier_V0(self, points, thresh=3.5): |
|
1640 | def mad_based_outlier_V0(self, points, thresh=3.5): | |
1641 |
|
1641 | |||
1642 | if len(points.shape) == 1: |
|
1642 | if len(points.shape) == 1: | |
1643 | points = points[:,None] |
|
1643 | points = points[:,None] | |
1644 | median = numpy.nanmedian(points, axis=0) |
|
1644 | median = numpy.nanmedian(points, axis=0) | |
1645 | diff = numpy.nansum((points - median)**2, axis=-1) |
|
1645 | diff = numpy.nansum((points - median)**2, axis=-1) | |
1646 | diff = numpy.sqrt(diff) |
|
1646 | diff = numpy.sqrt(diff) | |
1647 | med_abs_deviation = numpy.nanmedian(diff) |
|
1647 | med_abs_deviation = numpy.nanmedian(diff) | |
1648 |
|
1648 | |||
1649 | modified_z_score = 0.6745 * diff / med_abs_deviation |
|
1649 | modified_z_score = 0.6745 * diff / med_abs_deviation | |
1650 |
|
1650 | |||
1651 | return modified_z_score > thresh |
|
1651 | return modified_z_score > thresh | |
1652 |
|
1652 | |||
1653 | def mad_based_outlier(self, points, thresh=3.5): |
|
1653 | def mad_based_outlier(self, points, thresh=3.5): | |
1654 |
|
1654 | |||
1655 | median = numpy.nanmedian(points) |
|
1655 | median = numpy.nanmedian(points) | |
1656 | diff = (points - median)**2 |
|
1656 | diff = (points - median)**2 | |
1657 | diff = numpy.sqrt(diff) |
|
1657 | diff = numpy.sqrt(diff) | |
1658 | med_abs_deviation = numpy.nanmedian(diff) |
|
1658 | med_abs_deviation = numpy.nanmedian(diff) | |
1659 |
|
1659 | |||
1660 | modified_z_score = 0.6745 * diff / med_abs_deviation |
|
1660 | modified_z_score = 0.6745 * diff / med_abs_deviation | |
1661 |
|
1661 | |||
1662 | return modified_z_score > thresh |
|
1662 | return modified_z_score > thresh | |
1663 |
|
1663 | |||
1664 |
|
1664 | |||
1665 |
|
1665 | |||
1666 | def removeSpreadF(self,dataOut): |
|
1666 | def removeSpreadF(self,dataOut): | |
1667 |
|
1667 | |||
1668 | #Removing outliers from the profile |
|
1668 | #Removing outliers from the profile | |
1669 | nlag = 9 |
|
1669 | nlag = 9 | |
1670 | minHei = 180 |
|
1670 | minHei = 180 | |
1671 | #maxHei = 600 |
|
1671 | #maxHei = 600 | |
1672 | maxHei = 525 |
|
1672 | maxHei = 525 | |
1673 | inda = numpy.where(dataOut.heightList >= minHei) |
|
1673 | inda = numpy.where(dataOut.heightList >= minHei) | |
1674 | indb = numpy.where(dataOut.heightList <= maxHei) |
|
1674 | indb = numpy.where(dataOut.heightList <= maxHei) | |
1675 | minIndex = inda[0][0] |
|
1675 | minIndex = inda[0][0] | |
1676 | maxIndex = indb[0][-1] |
|
1676 | maxIndex = indb[0][-1] | |
1677 | outliers_IDs = [] |
|
1677 | outliers_IDs = [] | |
1678 |
|
1678 | |||
1679 | for i in range(15): |
|
1679 | for i in range(15): | |
1680 | minIndex = 12+i#12 |
|
1680 | minIndex = 12+i#12 | |
1681 | #maxIndex = 22+i#35 |
|
1681 | #maxIndex = 22+i#35 | |
1682 | if gmtime(dataOut.utctime).tm_hour >= 23. or gmtime(dataOut.utctime).tm_hour < 3.: |
|
1682 | if gmtime(dataOut.utctime).tm_hour >= 23. or gmtime(dataOut.utctime).tm_hour < 3.: | |
1683 | maxIndex = 31+i#35 |
|
1683 | maxIndex = 31+i#35 | |
1684 | else: |
|
1684 | else: | |
1685 | maxIndex = 22+i#35 |
|
1685 | maxIndex = 22+i#35 | |
1686 | for lag in range(11): |
|
1686 | for lag in range(11): | |
1687 | outliers = self.mad_based_outlier(dataOut.kabxys_integrated[6][minIndex:maxIndex,lag,0]) |
|
1687 | outliers = self.mad_based_outlier(dataOut.kabxys_integrated[6][minIndex:maxIndex,lag,0]) | |
1688 | aux = minIndex+numpy.array(outliers.nonzero()).ravel() |
|
1688 | aux = minIndex+numpy.array(outliers.nonzero()).ravel() | |
1689 | outliers_IDs=numpy.append(outliers_IDs,aux) |
|
1689 | outliers_IDs=numpy.append(outliers_IDs,aux) | |
1690 | if outliers_IDs != []: |
|
1690 | if outliers_IDs != []: | |
1691 | outliers_IDs=numpy.array(outliers_IDs) |
|
1691 | outliers_IDs=numpy.array(outliers_IDs) | |
1692 | outliers_IDs=outliers_IDs.astype(numpy.dtype('int64')) |
|
1692 | outliers_IDs=outliers_IDs.astype(numpy.dtype('int64')) | |
1693 | (uniq, freq) = (numpy.unique(outliers_IDs, return_counts=True)) |
|
1693 | (uniq, freq) = (numpy.unique(outliers_IDs, return_counts=True)) | |
1694 | aux_arr = numpy.column_stack((uniq,freq)) |
|
1694 | aux_arr = numpy.column_stack((uniq,freq)) | |
1695 | final_index = [] |
|
1695 | final_index = [] | |
1696 | for i in range(aux_arr.shape[0]): |
|
1696 | for i in range(aux_arr.shape[0]): | |
1697 | if aux_arr[i,1] >= 3*11: |
|
1697 | if aux_arr[i,1] >= 3*11: | |
1698 | final_index.append(aux_arr[i,0]) |
|
1698 | final_index.append(aux_arr[i,0]) | |
1699 |
|
1699 | |||
1700 | if final_index != []:# and len(final_index) > 1: |
|
1700 | if final_index != []:# and len(final_index) > 1: | |
1701 | following_index = final_index[-1]+1 #Remove following index to ensure we remove remaining SpreadF |
|
1701 | following_index = final_index[-1]+1 #Remove following index to ensure we remove remaining SpreadF | |
1702 | previous_index = final_index[0]-1 #Remove previous index to ensure we remove remaning SpreadF |
|
1702 | previous_index = final_index[0]-1 #Remove previous index to ensure we remove remaning SpreadF | |
1703 | final_index = numpy.concatenate(([previous_index],final_index,[following_index])) |
|
1703 | final_index = numpy.concatenate(([previous_index],final_index,[following_index])) | |
1704 | final_index = numpy.unique(final_index) #If there was only one outlier |
|
1704 | final_index = numpy.unique(final_index) #If there was only one outlier | |
1705 | dataOut.kabxys_integrated[4][final_index,:,0] = numpy.nan |
|
1705 | dataOut.kabxys_integrated[4][final_index,:,0] = numpy.nan | |
1706 | dataOut.kabxys_integrated[6][final_index,:,0] = numpy.nan |
|
1706 | dataOut.kabxys_integrated[6][final_index,:,0] = numpy.nan | |
1707 |
|
1707 | |||
1708 | dataOut.flagSpreadF = True |
|
1708 | dataOut.flagSpreadF = True | |
1709 |
|
1709 | |||
1710 | #Removing echoes greater than 35 dB |
|
1710 | #Removing echoes greater than 35 dB | |
1711 | if hasattr(dataOut.pbn, "__len__"): |
|
1711 | if hasattr(dataOut.pbn, "__len__"): | |
1712 | maxdB = 10*numpy.log10(dataOut.pbn[0]) + 10 #Lag 0 Noise |
|
1712 | maxdB = 10*numpy.log10(dataOut.pbn[0]) + 10 #Lag 0 Noise | |
1713 | else: |
|
1713 | else: | |
1714 | maxdB = 10*numpy.log10(dataOut.pbn) + 10 |
|
1714 | maxdB = 10*numpy.log10(dataOut.pbn) + 10 | |
1715 |
|
1715 | |||
1716 | data = numpy.copy(10*numpy.log10(dataOut.kabxys_integrated[6][:,0,0])) #Lag0 ChB |
|
1716 | data = numpy.copy(10*numpy.log10(dataOut.kabxys_integrated[6][:,0,0])) #Lag0 ChB | |
1717 |
|
1717 | |||
1718 | for i in range(12,data.shape[0]): |
|
1718 | for i in range(12,data.shape[0]): | |
1719 | if data[i]>maxdB: |
|
1719 | if data[i]>maxdB: | |
1720 | dataOut.kabxys_integrated[4][i-2:i+3,:,0] = numpy.nan #Debido a que estos ecos son intensos, se |
|
1720 | dataOut.kabxys_integrated[4][i-2:i+3,:,0] = numpy.nan #Debido a que estos ecos son intensos, se | |
1721 | dataOut.kabxys_integrated[6][i-2:i+3,:,0] = numpy.nan #remueven ademΓ‘s dos muestras antes y despuΓ©s |
|
1721 | dataOut.kabxys_integrated[6][i-2:i+3,:,0] = numpy.nan #remueven ademΓ‘s dos muestras antes y despuΓ©s | |
1722 | dataOut.flagSpreadF = True |
|
1722 | dataOut.flagSpreadF = True | |
1723 |
|
1723 | |||
1724 | def run(self,dataOut): |
|
1724 | def run(self,dataOut): | |
1725 | dataOut.flagSpreadF = False |
|
1725 | dataOut.flagSpreadF = False | |
1726 | if gmtime(dataOut.utctime).tm_hour >= 23. or gmtime(dataOut.utctime).tm_hour < 11.: #18-06 LT |
|
1726 | if gmtime(dataOut.utctime).tm_hour >= 23. or gmtime(dataOut.utctime).tm_hour < 11.: #18-06 LT | |
1727 | self.removeSpreadF(dataOut) |
|
1727 | self.removeSpreadF(dataOut) | |
1728 |
|
1728 | |||
1729 | return dataOut |
|
1729 | return dataOut | |
1730 | class NoisePower(Operation): |
|
1730 | class NoisePower(Operation): | |
1731 | ''' |
|
1731 | ''' | |
1732 | Written by R. Flores |
|
1732 | Written by R. Flores | |
1733 | ''' |
|
1733 | ''' | |
1734 | """Operation to get noise power from the integrated data of the Double Pulse. |
|
1734 | """Operation to get noise power from the integrated data of the Double Pulse. | |
1735 |
|
1735 | |||
1736 | Parameters: |
|
1736 | Parameters: | |
1737 | ----------- |
|
1737 | ----------- | |
1738 | None |
|
1738 | None | |
1739 |
|
1739 | |||
1740 | Example |
|
1740 | Example | |
1741 | -------- |
|
1741 | -------- | |
1742 |
|
1742 | |||
1743 | op = proc_unit.addOperation(name='NoisePower', optype='other') |
|
1743 | op = proc_unit.addOperation(name='NoisePower', optype='other') | |
1744 |
|
1744 | |||
1745 | """ |
|
1745 | """ | |
1746 |
|
1746 | |||
1747 | def __init__(self, **kwargs): |
|
1747 | def __init__(self, **kwargs): | |
1748 |
|
1748 | |||
1749 | Operation.__init__(self, **kwargs) |
|
1749 | Operation.__init__(self, **kwargs) | |
1750 |
|
1750 | |||
1751 | def hildebrand(self,dataOut,data): |
|
1751 | def hildebrand(self,dataOut,data): | |
1752 |
|
1752 | |||
1753 | divider=10 # divider was originally 10 |
|
1753 | divider=10 # divider was originally 10 | |
1754 | noise=0.0 |
|
1754 | noise=0.0 | |
1755 | n1=0 |
|
1755 | n1=0 | |
1756 | n2=int(dataOut.NDP/2) |
|
1756 | n2=int(dataOut.NDP/2) | |
1757 | sorts= sorted(data) |
|
1757 | sorts= sorted(data) | |
1758 | nums_min= dataOut.NDP/divider |
|
1758 | nums_min= dataOut.NDP/divider | |
1759 | if((dataOut.NDP/divider)> 2): |
|
1759 | if((dataOut.NDP/divider)> 2): | |
1760 | nums_min= int(dataOut.NDP/divider) |
|
1760 | nums_min= int(dataOut.NDP/divider) | |
1761 |
|
1761 | |||
1762 | else: |
|
1762 | else: | |
1763 | nums_min=2 |
|
1763 | nums_min=2 | |
1764 | sump=0.0 |
|
1764 | sump=0.0 | |
1765 | sumq=0.0 |
|
1765 | sumq=0.0 | |
1766 | j=0 |
|
1766 | j=0 | |
1767 | cont=1 |
|
1767 | cont=1 | |
1768 | while( (cont==1) and (j<n2)): |
|
1768 | while( (cont==1) and (j<n2)): | |
1769 | sump+=sorts[j+n1] |
|
1769 | sump+=sorts[j+n1] | |
1770 | sumq+= sorts[j+n1]*sorts[j+n1] |
|
1770 | sumq+= sorts[j+n1]*sorts[j+n1] | |
1771 | t3= sump/(j+1) |
|
1771 | t3= sump/(j+1) | |
1772 | j=j+1 |
|
1772 | j=j+1 | |
1773 | if(j> nums_min): |
|
1773 | if(j> nums_min): | |
1774 | rtest= float(j/(j-1)) +1.0/dataOut.NAVG |
|
1774 | rtest= float(j/(j-1)) +1.0/dataOut.NAVG | |
1775 | t1= (sumq*j) |
|
1775 | t1= (sumq*j) | |
1776 | t2=(rtest*sump*sump) |
|
1776 | t2=(rtest*sump*sump) | |
1777 | if( (t1/t2) > 0.990): |
|
1777 | if( (t1/t2) > 0.990): | |
1778 | j=j-1 |
|
1778 | j=j-1 | |
1779 | sump-= sorts[j+n1] |
|
1779 | sump-= sorts[j+n1] | |
1780 | sumq-=sorts[j+n1]*sorts[j+n1] |
|
1780 | sumq-=sorts[j+n1]*sorts[j+n1] | |
1781 | cont= 0 |
|
1781 | cont= 0 | |
1782 |
|
1782 | |||
1783 | noise= sump/j |
|
1783 | noise= sump/j | |
1784 | stdv=numpy.sqrt((sumq- noise*noise)/(j-1)) |
|
1784 | stdv=numpy.sqrt((sumq- noise*noise)/(j-1)) | |
1785 | return noise |
|
1785 | return noise | |
1786 |
|
1786 | |||
1787 | def run(self,dataOut): |
|
1787 | def run(self,dataOut): | |
1788 |
|
1788 | |||
1789 | p=numpy.zeros((dataOut.NR,dataOut.NDP,dataOut.DPL),'float32') |
|
1789 | p=numpy.zeros((dataOut.NR,dataOut.NDP,dataOut.DPL),'float32') | |
1790 | av=numpy.zeros(dataOut.NDP,'float32') |
|
1790 | av=numpy.zeros(dataOut.NDP,'float32') | |
1791 | dataOut.pnoise=numpy.zeros(dataOut.NR,'float32') |
|
1791 | dataOut.pnoise=numpy.zeros(dataOut.NR,'float32') | |
1792 |
|
1792 | |||
1793 | p[0,:,:]=dataOut.kabxys_integrated[4][:,:,0]+dataOut.kabxys_integrated[5][:,:,0] #total power for channel 0, just pulse with non-flip |
|
1793 | p[0,:,:]=dataOut.kabxys_integrated[4][:,:,0]+dataOut.kabxys_integrated[5][:,:,0] #total power for channel 0, just pulse with non-flip | |
1794 | p[1,:,:]=dataOut.kabxys_integrated[6][:,:,0]+dataOut.kabxys_integrated[7][:,:,0] #total power for channel 1 |
|
1794 | p[1,:,:]=dataOut.kabxys_integrated[6][:,:,0]+dataOut.kabxys_integrated[7][:,:,0] #total power for channel 1 | |
1795 |
|
1795 | |||
1796 | for i in range(dataOut.NR): |
|
1796 | for i in range(dataOut.NR): | |
1797 | dataOut.pnoise[i]=0.0 |
|
1797 | dataOut.pnoise[i]=0.0 | |
1798 | for k in range(dataOut.DPL): |
|
1798 | for k in range(dataOut.DPL): | |
1799 | dataOut.pnoise[i]+= self.hildebrand(dataOut,p[i,:,k]) |
|
1799 | dataOut.pnoise[i]+= self.hildebrand(dataOut,p[i,:,k]) | |
1800 |
|
1800 | |||
1801 | dataOut.pnoise[i]=dataOut.pnoise[i]/dataOut.DPL |
|
1801 | dataOut.pnoise[i]=dataOut.pnoise[i]/dataOut.DPL | |
1802 |
|
1802 | |||
1803 |
|
1803 | |||
1804 | dataOut.pan=1.0*dataOut.pnoise[0] # weights could change |
|
1804 | dataOut.pan=1.0*dataOut.pnoise[0] # weights could change | |
1805 | dataOut.pbn=1.0*dataOut.pnoise[1] # weights could change |
|
1805 | dataOut.pbn=1.0*dataOut.pnoise[1] # weights could change | |
1806 |
|
1806 | |||
1807 | return dataOut |
|
1807 | return dataOut | |
1808 |
|
1808 | |||
1809 |
|
1809 | |||
1810 | class DoublePulseACFs(Operation): |
|
1810 | class DoublePulseACFs(Operation): | |
1811 | ''' |
|
1811 | ''' | |
1812 | Written by R. Flores |
|
1812 | Written by R. Flores | |
1813 | ''' |
|
1813 | ''' | |
1814 | """Operation to get the ACFs of the Double Pulse. |
|
1814 | """Operation to get the ACFs of the Double Pulse. | |
1815 |
|
1815 | |||
1816 | Parameters: |
|
1816 | Parameters: | |
1817 | ----------- |
|
1817 | ----------- | |
1818 | None |
|
1818 | None | |
1819 |
|
1819 | |||
1820 | Example |
|
1820 | Example | |
1821 | -------- |
|
1821 | -------- | |
1822 |
|
1822 | |||
1823 | op = proc_unit.addOperation(name='DoublePulseACFs', optype='other') |
|
1823 | op = proc_unit.addOperation(name='DoublePulseACFs', optype='other') | |
1824 |
|
1824 | |||
1825 | """ |
|
1825 | """ | |
1826 |
|
1826 | |||
1827 | def __init__(self, **kwargs): |
|
1827 | def __init__(self, **kwargs): | |
1828 |
|
1828 | |||
1829 | Operation.__init__(self, **kwargs) |
|
1829 | Operation.__init__(self, **kwargs) | |
1830 | self.aux=1 |
|
1830 | self.aux=1 | |
1831 |
|
1831 | |||
1832 | def run(self,dataOut): |
|
1832 | def run(self,dataOut): | |
1833 |
|
1833 | |||
1834 | dataOut.igcej=numpy.zeros((dataOut.NDP,dataOut.DPL),'int32') |
|
1834 | dataOut.igcej=numpy.zeros((dataOut.NDP,dataOut.DPL),'int32') | |
1835 |
|
1835 | |||
1836 | if self.aux==1: |
|
1836 | if self.aux==1: | |
1837 | dataOut.rhor=numpy.zeros((dataOut.NDP,dataOut.DPL), dtype=float) |
|
1837 | dataOut.rhor=numpy.zeros((dataOut.NDP,dataOut.DPL), dtype=float) | |
1838 | dataOut.rhoi=numpy.zeros((dataOut.NDP,dataOut.DPL), dtype=float) |
|
1838 | dataOut.rhoi=numpy.zeros((dataOut.NDP,dataOut.DPL), dtype=float) | |
1839 | dataOut.sdp=numpy.zeros((dataOut.NDP,dataOut.DPL), dtype=float) |
|
1839 | dataOut.sdp=numpy.zeros((dataOut.NDP,dataOut.DPL), dtype=float) | |
1840 | dataOut.sd=numpy.zeros((dataOut.NDP,dataOut.DPL), dtype=float) |
|
1840 | dataOut.sd=numpy.zeros((dataOut.NDP,dataOut.DPL), dtype=float) | |
1841 | dataOut.p=numpy.zeros((dataOut.NDP,dataOut.DPL), dtype=float) |
|
1841 | dataOut.p=numpy.zeros((dataOut.NDP,dataOut.DPL), dtype=float) | |
1842 | dataOut.alag=numpy.zeros(dataOut.NDP,'float32') |
|
1842 | dataOut.alag=numpy.zeros(dataOut.NDP,'float32') | |
1843 | for l in range(dataOut.DPL): |
|
1843 | for l in range(dataOut.DPL): | |
1844 | dataOut.alag[l]=l*dataOut.DH*2.0/150.0 |
|
1844 | dataOut.alag[l]=l*dataOut.DH*2.0/150.0 | |
1845 | self.aux=0 |
|
1845 | self.aux=0 | |
1846 | sn4=dataOut.pan*dataOut.pbn |
|
1846 | sn4=dataOut.pan*dataOut.pbn | |
1847 | rhorn=0 |
|
1847 | rhorn=0 | |
1848 | rhoin=0 |
|
1848 | rhoin=0 | |
1849 | panrm=numpy.zeros((dataOut.NDP,dataOut.DPL), dtype=float) |
|
1849 | panrm=numpy.zeros((dataOut.NDP,dataOut.DPL), dtype=float) | |
1850 |
|
1850 | |||
1851 | for i in range(dataOut.NDP): |
|
1851 | for i in range(dataOut.NDP): | |
1852 | for j in range(dataOut.DPL): |
|
1852 | for j in range(dataOut.DPL): | |
1853 | ################# Total power |
|
1853 | ################# Total power | |
1854 | pa=numpy.abs(dataOut.kabxys_integrated[4][i,j,0]+dataOut.kabxys_integrated[5][i,j,0]) |
|
1854 | pa=numpy.abs(dataOut.kabxys_integrated[4][i,j,0]+dataOut.kabxys_integrated[5][i,j,0]) | |
1855 | pb=numpy.abs(dataOut.kabxys_integrated[6][i,j,0]+dataOut.kabxys_integrated[7][i,j,0]) |
|
1855 | pb=numpy.abs(dataOut.kabxys_integrated[6][i,j,0]+dataOut.kabxys_integrated[7][i,j,0]) | |
1856 | st4=pa*pb |
|
1856 | st4=pa*pb | |
1857 | dataOut.p[i,j]=pa+pb-(dataOut.pan+dataOut.pbn) |
|
1857 | dataOut.p[i,j]=pa+pb-(dataOut.pan+dataOut.pbn) | |
1858 | dataOut.sdp[i,j]=2*dataOut.rnint2[j]*((pa+pb)*(pa+pb)) |
|
1858 | dataOut.sdp[i,j]=2*dataOut.rnint2[j]*((pa+pb)*(pa+pb)) | |
1859 | ## ACF |
|
1859 | ## ACF | |
1860 | rhorp=dataOut.kabxys_integrated[8][i,j,0]+dataOut.kabxys_integrated[11][i,j,0] |
|
1860 | rhorp=dataOut.kabxys_integrated[8][i,j,0]+dataOut.kabxys_integrated[11][i,j,0] | |
1861 | rhoip=dataOut.kabxys_integrated[10][i,j,0]-dataOut.kabxys_integrated[9][i,j,0] |
|
1861 | rhoip=dataOut.kabxys_integrated[10][i,j,0]-dataOut.kabxys_integrated[9][i,j,0] | |
1862 | if ((pa>dataOut.pan)&(pb>dataOut.pbn)): |
|
1862 | if ((pa>dataOut.pan)&(pb>dataOut.pbn)): | |
1863 |
|
1863 | |||
1864 | ss4=numpy.abs((pa-dataOut.pan)*(pb-dataOut.pbn)) |
|
1864 | ss4=numpy.abs((pa-dataOut.pan)*(pb-dataOut.pbn)) | |
1865 | panrm[i,j]=math.sqrt(ss4) |
|
1865 | panrm[i,j]=math.sqrt(ss4) | |
1866 | rnorm=1/panrm[i,j] |
|
1866 | rnorm=1/panrm[i,j] | |
1867 | ## ACF |
|
1867 | ## ACF | |
1868 | dataOut.rhor[i,j]=rhorp*rnorm |
|
1868 | dataOut.rhor[i,j]=rhorp*rnorm | |
1869 | dataOut.rhoi[i,j]=rhoip*rnorm |
|
1869 | dataOut.rhoi[i,j]=rhoip*rnorm | |
1870 | ############# Compute standard error for ACF |
|
1870 | ############# Compute standard error for ACF | |
1871 | stoss4=st4/ss4 |
|
1871 | stoss4=st4/ss4 | |
1872 | snoss4=sn4/ss4 |
|
1872 | snoss4=sn4/ss4 | |
1873 | rp2=((rhorp*rhorp)+(rhoip*rhoip))/st4 |
|
1873 | rp2=((rhorp*rhorp)+(rhoip*rhoip))/st4 | |
1874 | rn2=((rhorn*rhorn)+(rhoin*rhoin))/sn4 |
|
1874 | rn2=((rhorn*rhorn)+(rhoin*rhoin))/sn4 | |
1875 | rs2=(dataOut.rhor[i,j]*dataOut.rhor[i,j])+(dataOut.rhoi[i,j]*dataOut.rhoi[i,j]) |
|
1875 | rs2=(dataOut.rhor[i,j]*dataOut.rhor[i,j])+(dataOut.rhoi[i,j]*dataOut.rhoi[i,j]) | |
1876 | st=1.0+rs2*(stoss4-(2*math.sqrt(stoss4*snoss4))) |
|
1876 | st=1.0+rs2*(stoss4-(2*math.sqrt(stoss4*snoss4))) | |
1877 | stn=1.0+rs2*(snoss4-(2*math.sqrt(stoss4*snoss4))) |
|
1877 | stn=1.0+rs2*(snoss4-(2*math.sqrt(stoss4*snoss4))) | |
1878 | dataOut.sd[i,j]=((stoss4*((1.0+rp2)*st+(2.0*rp2*rs2*snoss4)-4.0*math.sqrt(rs2*rp2)))+(0.25*snoss4*((1.0+rn2)*stn+(2.0*rn2*rs2*stoss4)-4.0*math.sqrt(rs2*rn2))))*dataOut.rnint2[j] |
|
1878 | dataOut.sd[i,j]=((stoss4*((1.0+rp2)*st+(2.0*rp2*rs2*snoss4)-4.0*math.sqrt(rs2*rp2)))+(0.25*snoss4*((1.0+rn2)*stn+(2.0*rn2*rs2*stoss4)-4.0*math.sqrt(rs2*rn2))))*dataOut.rnint2[j] | |
1879 | dataOut.sd[i,j]=numpy.abs(dataOut.sd[i,j]) |
|
1879 | dataOut.sd[i,j]=numpy.abs(dataOut.sd[i,j]) | |
1880 |
|
1880 | |||
1881 | else: #default values for bad points |
|
1881 | else: #default values for bad points | |
1882 | rnorm=1/math.sqrt(st4) |
|
1882 | rnorm=1/math.sqrt(st4) | |
1883 | dataOut.sd[i,j]=1.e30 |
|
1883 | dataOut.sd[i,j]=1.e30 | |
1884 | dataOut.ibad[i,j]=4 |
|
1884 | dataOut.ibad[i,j]=4 | |
1885 | dataOut.rhor[i,j]=rhorp*rnorm |
|
1885 | dataOut.rhor[i,j]=rhorp*rnorm | |
1886 | dataOut.rhoi[i,j]=rhoip*rnorm |
|
1886 | dataOut.rhoi[i,j]=rhoip*rnorm | |
1887 | if ((pb/dataOut.pbn-1.0)>2.25*(pa/dataOut.pan-1.0)): #To flag bad points from the pulse and EEJ for lags != 0 for Channel B |
|
1887 | if ((pb/dataOut.pbn-1.0)>2.25*(pa/dataOut.pan-1.0)): #To flag bad points from the pulse and EEJ for lags != 0 for Channel B | |
1888 | #print(dataOut.heightList[i],"EJJ") |
|
1888 | #print(dataOut.heightList[i],"EJJ") | |
1889 | dataOut.igcej[i,j]=1 |
|
1889 | dataOut.igcej[i,j]=1 | |
1890 | elif ((pa/dataOut.pan-1.0)>2.25*(pb/dataOut.pbn-1.0)): |
|
1890 | elif ((pa/dataOut.pan-1.0)>2.25*(pb/dataOut.pbn-1.0)): | |
1891 | dataOut.igcej[i,j]=1 |
|
1891 | dataOut.igcej[i,j]=1 | |
1892 |
|
1892 | |||
1893 | return dataOut |
|
1893 | return dataOut | |
1894 |
|
1894 | |||
1895 | class DoublePulseACFs_PerLag(Operation): |
|
1895 | class DoublePulseACFs_PerLag(Operation): | |
1896 | ''' |
|
1896 | ''' | |
1897 | Written by R. Flores |
|
1897 | Written by R. Flores | |
1898 | ''' |
|
1898 | ''' | |
1899 | """Operation to get the ACFs of the Double Pulse. |
|
1899 | """Operation to get the ACFs of the Double Pulse. | |
1900 |
|
1900 | |||
1901 | Parameters: |
|
1901 | Parameters: | |
1902 | ----------- |
|
1902 | ----------- | |
1903 | None |
|
1903 | None | |
1904 |
|
1904 | |||
1905 | Example |
|
1905 | Example | |
1906 | -------- |
|
1906 | -------- | |
1907 |
|
1907 | |||
1908 | op = proc_unit.addOperation(name='DoublePulseACFs', optype='other') |
|
1908 | op = proc_unit.addOperation(name='DoublePulseACFs', optype='other') | |
1909 |
|
1909 | |||
1910 | """ |
|
1910 | """ | |
1911 |
|
1911 | |||
1912 | def __init__(self, **kwargs): |
|
1912 | def __init__(self, **kwargs): | |
1913 |
|
1913 | |||
1914 | Operation.__init__(self, **kwargs) |
|
1914 | Operation.__init__(self, **kwargs) | |
1915 | self.aux=1 |
|
1915 | self.aux=1 | |
1916 |
|
1916 | |||
1917 | def run(self,dataOut): |
|
1917 | def run(self,dataOut): | |
1918 |
|
1918 | |||
1919 | dataOut.igcej=numpy.zeros((dataOut.NDP,dataOut.DPL),'int32') |
|
1919 | dataOut.igcej=numpy.zeros((dataOut.NDP,dataOut.DPL),'int32') | |
1920 |
|
1920 | |||
1921 | if self.aux==1: |
|
1921 | if self.aux==1: | |
1922 | dataOut.rhor=numpy.zeros((dataOut.NDP,dataOut.DPL), dtype=float) |
|
1922 | dataOut.rhor=numpy.zeros((dataOut.NDP,dataOut.DPL), dtype=float) | |
1923 | dataOut.rhoi=numpy.zeros((dataOut.NDP,dataOut.DPL), dtype=float) |
|
1923 | dataOut.rhoi=numpy.zeros((dataOut.NDP,dataOut.DPL), dtype=float) | |
1924 | dataOut.sdp=numpy.zeros((dataOut.NDP,dataOut.DPL), dtype=float) |
|
1924 | dataOut.sdp=numpy.zeros((dataOut.NDP,dataOut.DPL), dtype=float) | |
1925 | dataOut.sd=numpy.zeros((dataOut.NDP,dataOut.DPL), dtype=float) |
|
1925 | dataOut.sd=numpy.zeros((dataOut.NDP,dataOut.DPL), dtype=float) | |
1926 | dataOut.p=numpy.zeros((dataOut.NDP,dataOut.DPL), dtype=float) |
|
1926 | dataOut.p=numpy.zeros((dataOut.NDP,dataOut.DPL), dtype=float) | |
1927 | dataOut.alag=numpy.zeros(dataOut.NDP,'float32') |
|
1927 | dataOut.alag=numpy.zeros(dataOut.NDP,'float32') | |
1928 | for l in range(dataOut.DPL): |
|
1928 | for l in range(dataOut.DPL): | |
1929 | dataOut.alag[l]=l*dataOut.DH*2.0/150.0 |
|
1929 | dataOut.alag[l]=l*dataOut.DH*2.0/150.0 | |
1930 | self.aux=0 |
|
1930 | self.aux=0 | |
1931 | sn4=dataOut.pan*dataOut.pbn |
|
1931 | sn4=dataOut.pan*dataOut.pbn | |
1932 | rhorn=0 |
|
1932 | rhorn=0 | |
1933 | rhoin=0 |
|
1933 | rhoin=0 | |
1934 | panrm=numpy.zeros((dataOut.NDP,dataOut.DPL), dtype=float) |
|
1934 | panrm=numpy.zeros((dataOut.NDP,dataOut.DPL), dtype=float) | |
1935 |
|
1935 | |||
1936 | id = numpy.where(dataOut.heightList>700)[0] |
|
1936 | id = numpy.where(dataOut.heightList>700)[0] | |
1937 |
|
1937 | |||
1938 | for i in range(dataOut.NDP): |
|
1938 | for i in range(dataOut.NDP): | |
1939 | for j in range(dataOut.DPL): |
|
1939 | for j in range(dataOut.DPL): | |
1940 | ################# Total power |
|
1940 | ################# Total power | |
1941 | pa=numpy.abs(dataOut.kabxys_integrated[4][i,j,0]+dataOut.kabxys_integrated[5][i,j,0]) |
|
1941 | pa=numpy.abs(dataOut.kabxys_integrated[4][i,j,0]+dataOut.kabxys_integrated[5][i,j,0]) | |
1942 | pb=numpy.abs(dataOut.kabxys_integrated[6][i,j,0]+dataOut.kabxys_integrated[7][i,j,0]) |
|
1942 | pb=numpy.abs(dataOut.kabxys_integrated[6][i,j,0]+dataOut.kabxys_integrated[7][i,j,0]) | |
1943 | st4=pa*pb |
|
1943 | st4=pa*pb | |
1944 | dataOut.p[i,j]=pa+pb-(dataOut.pan[j]+dataOut.pbn[j]) |
|
1944 | dataOut.p[i,j]=pa+pb-(dataOut.pan[j]+dataOut.pbn[j]) | |
1945 | dataOut.sdp[i,j]=2*dataOut.rnint2[j]*((pa+pb)*(pa+pb)) |
|
1945 | dataOut.sdp[i,j]=2*dataOut.rnint2[j]*((pa+pb)*(pa+pb)) | |
1946 | ## ACF |
|
1946 | ## ACF | |
1947 | rhorp=dataOut.kabxys_integrated[8][i,j,0]+dataOut.kabxys_integrated[11][i,j,0] |
|
1947 | rhorp=dataOut.kabxys_integrated[8][i,j,0]+dataOut.kabxys_integrated[11][i,j,0] | |
1948 | rhoip=dataOut.kabxys_integrated[10][i,j,0]-dataOut.kabxys_integrated[9][i,j,0] |
|
1948 | rhoip=dataOut.kabxys_integrated[10][i,j,0]-dataOut.kabxys_integrated[9][i,j,0] | |
1949 |
|
1949 | |||
1950 | if ((pa>dataOut.pan[j])&(pb>dataOut.pbn[j])): |
|
1950 | if ((pa>dataOut.pan[j])&(pb>dataOut.pbn[j])): | |
1951 | ss4=numpy.abs((pa-dataOut.pan[j])*(pb-dataOut.pbn[j])) |
|
1951 | ss4=numpy.abs((pa-dataOut.pan[j])*(pb-dataOut.pbn[j])) | |
1952 | panrm[i,j]=math.sqrt(ss4) |
|
1952 | panrm[i,j]=math.sqrt(ss4) | |
1953 | rnorm=1/panrm[i,j] |
|
1953 | rnorm=1/panrm[i,j] | |
1954 | ## ACF |
|
1954 | ## ACF | |
1955 | dataOut.rhor[i,j]=rhorp*rnorm |
|
1955 | dataOut.rhor[i,j]=rhorp*rnorm | |
1956 | dataOut.rhoi[i,j]=rhoip*rnorm |
|
1956 | dataOut.rhoi[i,j]=rhoip*rnorm | |
1957 | ############# Compute standard error for ACF |
|
1957 | ############# Compute standard error for ACF | |
1958 | stoss4=st4/ss4 |
|
1958 | stoss4=st4/ss4 | |
1959 | snoss4=sn4[j]/ss4 |
|
1959 | snoss4=sn4[j]/ss4 | |
1960 | rp2=((rhorp*rhorp)+(rhoip*rhoip))/st4 |
|
1960 | rp2=((rhorp*rhorp)+(rhoip*rhoip))/st4 | |
1961 | rn2=((rhorn*rhorn)+(rhoin*rhoin))/sn4[j] |
|
1961 | rn2=((rhorn*rhorn)+(rhoin*rhoin))/sn4[j] | |
1962 | rs2=(dataOut.rhor[i,j]*dataOut.rhor[i,j])+(dataOut.rhoi[i,j]*dataOut.rhoi[i,j]) |
|
1962 | rs2=(dataOut.rhor[i,j]*dataOut.rhor[i,j])+(dataOut.rhoi[i,j]*dataOut.rhoi[i,j]) | |
1963 | st=1.0+rs2*(stoss4-(2*math.sqrt(stoss4*snoss4))) |
|
1963 | st=1.0+rs2*(stoss4-(2*math.sqrt(stoss4*snoss4))) | |
1964 | stn=1.0+rs2*(snoss4-(2*math.sqrt(stoss4*snoss4))) |
|
1964 | stn=1.0+rs2*(snoss4-(2*math.sqrt(stoss4*snoss4))) | |
1965 | dataOut.sd[i,j]=((stoss4*((1.0+rp2)*st+(2.0*rp2*rs2*snoss4)-4.0*math.sqrt(rs2*rp2)))+(0.25*snoss4*((1.0+rn2)*stn+(2.0*rn2*rs2*stoss4)-4.0*math.sqrt(rs2*rn2))))*dataOut.rnint2[j] |
|
1965 | dataOut.sd[i,j]=((stoss4*((1.0+rp2)*st+(2.0*rp2*rs2*snoss4)-4.0*math.sqrt(rs2*rp2)))+(0.25*snoss4*((1.0+rn2)*stn+(2.0*rn2*rs2*stoss4)-4.0*math.sqrt(rs2*rn2))))*dataOut.rnint2[j] | |
1966 | dataOut.sd[i,j]=numpy.abs(dataOut.sd[i,j]) |
|
1966 | dataOut.sd[i,j]=numpy.abs(dataOut.sd[i,j]) | |
1967 | else: #default values for bad points |
|
1967 | else: #default values for bad points | |
1968 | rnorm=1/math.sqrt(st4) |
|
1968 | rnorm=1/math.sqrt(st4) | |
1969 | dataOut.sd[i,j]=1.e30 |
|
1969 | dataOut.sd[i,j]=1.e30 | |
1970 | dataOut.ibad[i,j]=4 |
|
1970 | dataOut.ibad[i,j]=4 | |
1971 | dataOut.rhor[i,j]=rhorp*rnorm |
|
1971 | dataOut.rhor[i,j]=rhorp*rnorm | |
1972 | dataOut.rhoi[i,j]=rhoip*rnorm |
|
1972 | dataOut.rhoi[i,j]=rhoip*rnorm | |
1973 | if ((pb/dataOut.pbn[j]-1.0)>2.25*(pa/dataOut.pan[j]-1.0)): #To flag bad points from the pulse and EEJ for lags != 0 for Channel B |
|
1973 | if ((pb/dataOut.pbn[j]-1.0)>2.25*(pa/dataOut.pan[j]-1.0)): #To flag bad points from the pulse and EEJ for lags != 0 for Channel B | |
1974 | dataOut.igcej[i,j]=1 |
|
1974 | dataOut.igcej[i,j]=1 | |
1975 |
|
1975 | |||
1976 | elif ((pa/dataOut.pan[j]-1.0)>2.25*(pb/dataOut.pbn[j]-1.0)): |
|
1976 | elif ((pa/dataOut.pan[j]-1.0)>2.25*(pb/dataOut.pbn[j]-1.0)): | |
1977 | dataOut.igcej[i,j]=1 |
|
1977 | dataOut.igcej[i,j]=1 | |
1978 |
|
1978 | |||
1979 | return dataOut |
|
1979 | return dataOut | |
1980 |
|
1980 | |||
1981 | class FaradayAngleAndDPPower(Operation): |
|
1981 | class FaradayAngleAndDPPower(Operation): | |
1982 | ''' |
|
1982 | ''' | |
1983 | Written by R. Flores |
|
1983 | Written by R. Flores | |
1984 | ''' |
|
1984 | ''' | |
1985 | """Operation to calculate Faraday angle and Double Pulse power. |
|
1985 | """Operation to calculate Faraday angle and Double Pulse power. | |
1986 |
|
1986 | |||
1987 | Parameters: |
|
1987 | Parameters: | |
1988 | ----------- |
|
1988 | ----------- | |
1989 | None |
|
1989 | None | |
1990 |
|
1990 | |||
1991 | Example |
|
1991 | Example | |
1992 | -------- |
|
1992 | -------- | |
1993 |
|
1993 | |||
1994 | op = proc_unit.addOperation(name='FaradayAngleAndDPPower', optype='other') |
|
1994 | op = proc_unit.addOperation(name='FaradayAngleAndDPPower', optype='other') | |
1995 |
|
1995 | |||
1996 | """ |
|
1996 | """ | |
1997 |
|
1997 | |||
1998 | def __init__(self, **kwargs): |
|
1998 | def __init__(self, **kwargs): | |
1999 |
|
1999 | |||
2000 | Operation.__init__(self, **kwargs) |
|
2000 | Operation.__init__(self, **kwargs) | |
2001 | self.aux=1 |
|
2001 | self.aux=1 | |
2002 |
|
2002 | |||
2003 | def run(self,dataOut): |
|
2003 | def run(self,dataOut): | |
2004 |
|
2004 | |||
2005 | if self.aux==1: |
|
2005 | if self.aux==1: | |
2006 | dataOut.h2=numpy.zeros(dataOut.MAXNRANGENDT,'float32') |
|
2006 | dataOut.h2=numpy.zeros(dataOut.MAXNRANGENDT,'float32') | |
2007 | dataOut.range1=numpy.zeros(dataOut.MAXNRANGENDT,order='F',dtype='float32') |
|
2007 | dataOut.range1=numpy.zeros(dataOut.MAXNRANGENDT,order='F',dtype='float32') | |
2008 | dataOut.sdn2=numpy.zeros(dataOut.NDP,'float32') |
|
2008 | dataOut.sdn2=numpy.zeros(dataOut.NDP,'float32') | |
2009 | dataOut.ph2=numpy.zeros(dataOut.NDP,'float32') |
|
2009 | dataOut.ph2=numpy.zeros(dataOut.NDP,'float32') | |
2010 | dataOut.sdp2=numpy.zeros(dataOut.NDP,'float32') |
|
2010 | dataOut.sdp2=numpy.zeros(dataOut.NDP,'float32') | |
2011 | dataOut.ibd=numpy.zeros(dataOut.NDP,'float32') |
|
2011 | dataOut.ibd=numpy.zeros(dataOut.NDP,'float32') | |
2012 | dataOut.phi=numpy.zeros(dataOut.NDP,'float32') |
|
2012 | dataOut.phi=numpy.zeros(dataOut.NDP,'float32') | |
2013 |
|
2013 | |||
2014 | self.aux=0 |
|
2014 | self.aux=0 | |
2015 |
|
2015 | |||
2016 | for i in range(dataOut.MAXNRANGENDT): |
|
2016 | for i in range(dataOut.MAXNRANGENDT): | |
2017 | dataOut.range1[i]=dataOut.H0 + i*dataOut.DH |
|
2017 | dataOut.range1[i]=dataOut.H0 + i*dataOut.DH | |
2018 | dataOut.h2[i]=dataOut.range1[i]**2 |
|
2018 | dataOut.h2[i]=dataOut.range1[i]**2 | |
2019 |
|
2019 | |||
2020 | for j in range(dataOut.NDP): |
|
2020 | for j in range(dataOut.NDP): | |
2021 | dataOut.ph2[j]=0. |
|
2021 | dataOut.ph2[j]=0. | |
2022 | dataOut.sdp2[j]=0. |
|
2022 | dataOut.sdp2[j]=0. | |
2023 | ri=dataOut.rhoi[j][0]/dataOut.sd[j][0] |
|
2023 | ri=dataOut.rhoi[j][0]/dataOut.sd[j][0] | |
2024 | rr=dataOut.rhor[j][0]/dataOut.sd[j][0] |
|
2024 | rr=dataOut.rhor[j][0]/dataOut.sd[j][0] | |
2025 | dataOut.sdn2[j]=1./dataOut.sd[j][0] |
|
2025 | dataOut.sdn2[j]=1./dataOut.sd[j][0] | |
2026 |
|
2026 | |||
2027 | pt=0.# // total power |
|
2027 | pt=0.# // total power | |
2028 | st=0.# // total signal |
|
2028 | st=0.# // total signal | |
2029 | ibt=0# // bad lags |
|
2029 | ibt=0# // bad lags | |
2030 | ns=0# // no. good lags |
|
2030 | ns=0# // no. good lags | |
2031 | for l in range(dataOut.DPL): |
|
2031 | for l in range(dataOut.DPL): | |
2032 | #add in other lags if outside of e-jet contamination |
|
2032 | #add in other lags if outside of e-jet contamination | |
2033 | if( (dataOut.igcej[j][l] == 0) and (dataOut.ibad[j][l] == 0) ): |
|
2033 | if( (dataOut.igcej[j][l] == 0) and (dataOut.ibad[j][l] == 0) ): | |
2034 |
|
2034 | |||
2035 | dataOut.ph2[j]+=dataOut.p[j][l]/dataOut.sdp[j][l] |
|
2035 | dataOut.ph2[j]+=dataOut.p[j][l]/dataOut.sdp[j][l] | |
2036 | dataOut.sdp2[j]=dataOut.sdp2[j]+1./dataOut.sdp[j][l] |
|
2036 | dataOut.sdp2[j]=dataOut.sdp2[j]+1./dataOut.sdp[j][l] | |
2037 | ns+=1 |
|
2037 | ns+=1 | |
2038 |
|
2038 | |||
2039 |
|
2039 | |||
2040 | pt+=dataOut.p[j][l]/dataOut.sdp[j][l] |
|
2040 | pt+=dataOut.p[j][l]/dataOut.sdp[j][l] | |
2041 | st+=1./dataOut.sdp[j][l] |
|
2041 | st+=1./dataOut.sdp[j][l] | |
2042 | ibt|=dataOut.ibad[j][l]; |
|
2042 | ibt|=dataOut.ibad[j][l]; | |
2043 | if(ns!= 0): |
|
2043 | if(ns!= 0): | |
2044 | dataOut.ibd[j]=0 |
|
2044 | dataOut.ibd[j]=0 | |
2045 | dataOut.ph2[j]=dataOut.ph2[j]/dataOut.sdp2[j] |
|
2045 | dataOut.ph2[j]=dataOut.ph2[j]/dataOut.sdp2[j] | |
2046 | dataOut.sdp2[j]=1./dataOut.sdp2[j] |
|
2046 | dataOut.sdp2[j]=1./dataOut.sdp2[j] | |
2047 | else: |
|
2047 | else: | |
2048 | dataOut.ibd[j]=ibt |
|
2048 | dataOut.ibd[j]=ibt | |
2049 | dataOut.ph2[j]=pt/st |
|
2049 | dataOut.ph2[j]=pt/st | |
2050 | dataOut.sdp2[j]=1./st |
|
2050 | dataOut.sdp2[j]=1./st | |
2051 |
|
2051 | |||
2052 | dataOut.ph2[j]=dataOut.ph2[j]*dataOut.h2[j] |
|
2052 | dataOut.ph2[j]=dataOut.ph2[j]*dataOut.h2[j] | |
2053 | dataOut.sdp2[j]=numpy.sqrt(dataOut.sdp2[j])*dataOut.h2[j] |
|
2053 | dataOut.sdp2[j]=numpy.sqrt(dataOut.sdp2[j])*dataOut.h2[j] | |
2054 | rr=rr/dataOut.sdn2[j] |
|
2054 | rr=rr/dataOut.sdn2[j] | |
2055 | ri=ri/dataOut.sdn2[j] |
|
2055 | ri=ri/dataOut.sdn2[j] | |
2056 | #rm[j]=np.sqrt(rr*rr + ri*ri) it is not used in c program |
|
2056 | #rm[j]=np.sqrt(rr*rr + ri*ri) it is not used in c program | |
2057 | dataOut.sdn2[j]=1./(dataOut.sdn2[j]*(rr*rr + ri*ri)) |
|
2057 | dataOut.sdn2[j]=1./(dataOut.sdn2[j]*(rr*rr + ri*ri)) | |
2058 | if( (ri == 0.) and (rr == 0.) ): |
|
2058 | if( (ri == 0.) and (rr == 0.) ): | |
2059 | dataOut.phi[j]=0. |
|
2059 | dataOut.phi[j]=0. | |
2060 | else: |
|
2060 | else: | |
2061 | dataOut.phi[j]=math.atan2( ri , rr ) |
|
2061 | dataOut.phi[j]=math.atan2( ri , rr ) | |
2062 |
|
2062 | |||
2063 | dataOut.flagTeTiCorrection = False |
|
2063 | dataOut.flagTeTiCorrection = False | |
2064 | return dataOut |
|
2064 | return dataOut | |
2065 |
|
2065 | |||
2066 |
|
2066 | |||
2067 | class ElectronDensityFaraday(Operation): |
|
2067 | class ElectronDensityFaraday(Operation): | |
2068 | ''' |
|
2068 | ''' | |
2069 | Written by R. Flores |
|
2069 | Written by R. Flores | |
2070 | ''' |
|
2070 | ''' | |
2071 | """Operation to calculate electron density from Faraday angle. |
|
2071 | """Operation to calculate electron density from Faraday angle. | |
2072 |
|
2072 | |||
2073 | Parameters: |
|
2073 | Parameters: | |
2074 | ----------- |
|
2074 | ----------- | |
2075 | NSHTS : int |
|
2075 | NSHTS : int | |
2076 | .* |
|
2076 | .* | |
2077 | RATE : float |
|
2077 | RATE : float | |
2078 | .* |
|
2078 | .* | |
2079 |
|
2079 | |||
2080 | Example |
|
2080 | Example | |
2081 | -------- |
|
2081 | -------- | |
2082 |
|
2082 | |||
2083 | op = proc_unit.addOperation(name='ElectronDensityFaraday', optype='other') |
|
2083 | op = proc_unit.addOperation(name='ElectronDensityFaraday', optype='other') | |
2084 | op.addParameter(name='NSHTS', value='50', format='int') |
|
2084 | op.addParameter(name='NSHTS', value='50', format='int') | |
2085 | op.addParameter(name='RATE', value='1.8978873e-6', format='float') |
|
2085 | op.addParameter(name='RATE', value='1.8978873e-6', format='float') | |
2086 |
|
2086 | |||
2087 | """ |
|
2087 | """ | |
2088 |
|
2088 | |||
2089 | def __init__(self, **kwargs): |
|
2089 | def __init__(self, **kwargs): | |
2090 |
|
2090 | |||
2091 | Operation.__init__(self, **kwargs) |
|
2091 | Operation.__init__(self, **kwargs) | |
2092 | self.aux=1 |
|
2092 | self.aux=1 | |
2093 |
|
2093 | |||
2094 | def run(self,dataOut,NSHTS=50,RATE=1.8978873e-6): |
|
2094 | def run(self,dataOut,NSHTS=50,RATE=1.8978873e-6): | |
2095 |
|
2095 | |||
2096 | dataOut.NSHTS=NSHTS |
|
2096 | dataOut.NSHTS=NSHTS | |
2097 | dataOut.RATE=RATE |
|
2097 | dataOut.RATE=RATE | |
2098 |
|
2098 | |||
2099 | if self.aux==1: |
|
2099 | if self.aux==1: | |
2100 | dataOut.dphi=numpy.zeros(dataOut.NDP,'float32') |
|
2100 | dataOut.dphi=numpy.zeros(dataOut.NDP,'float32') | |
2101 | dataOut.sdn1=numpy.zeros(dataOut.NDP,'float32') |
|
2101 | dataOut.sdn1=numpy.zeros(dataOut.NDP,'float32') | |
2102 | self.aux=0 |
|
2102 | self.aux=0 | |
2103 | theta=numpy.zeros(dataOut.NDP,dtype=numpy.complex_) |
|
2103 | theta=numpy.zeros(dataOut.NDP,dtype=numpy.complex_) | |
2104 | thetai=numpy.zeros(dataOut.NDP,dtype=numpy.complex_) |
|
2104 | thetai=numpy.zeros(dataOut.NDP,dtype=numpy.complex_) | |
2105 | # use complex numbers for phase |
|
2105 | # use complex numbers for phase | |
2106 | ''' |
|
2106 | ''' | |
2107 | for i in range(dataOut.NSHTS): |
|
2107 | for i in range(dataOut.NSHTS): | |
2108 | theta[i]=math.cos(dataOut.phi[i])+math.sin(dataOut.phi[i])*1j |
|
2108 | theta[i]=math.cos(dataOut.phi[i])+math.sin(dataOut.phi[i])*1j | |
2109 | thetai[i]=-math.sin(dataOut.phi[i])+math.cos(dataOut.phi[i])*1j |
|
2109 | thetai[i]=-math.sin(dataOut.phi[i])+math.cos(dataOut.phi[i])*1j | |
2110 | ''' #Old Method |
|
2110 | ''' #Old Method | |
2111 |
|
2111 | |||
2112 | # differentiate and convert to number density |
|
2112 | # differentiate and convert to number density | |
2113 | ndphi=dataOut.NSHTS-4 |
|
2113 | ndphi=dataOut.NSHTS-4 | |
2114 | if hasattr(dataOut, 'flagSpreadF') and dataOut.flagSpreadF: |
|
2114 | if hasattr(dataOut, 'flagSpreadF') and dataOut.flagSpreadF: | |
2115 | nanindex = numpy.argwhere(numpy.isnan(dataOut.phi)) |
|
2115 | nanindex = numpy.argwhere(numpy.isnan(dataOut.phi)) | |
2116 | i1 = nanindex[-1][0] |
|
2116 | i1 = nanindex[-1][0] | |
2117 | #Analizar cuando SpreadF es Pluma |
|
2117 | #Analizar cuando SpreadF es Pluma | |
2118 |
|
2118 | |||
2119 | dataOut.phi[i1+1:]=numpy.unwrap(dataOut.phi[i1+1:]) #Better results |
|
2119 | dataOut.phi[i1+1:]=numpy.unwrap(dataOut.phi[i1+1:]) #Better results | |
2120 | else: |
|
2120 | else: | |
2121 | dataOut.phi[:]=numpy.unwrap(dataOut.phi[:]) #Better results |
|
2121 | dataOut.phi[:]=numpy.unwrap(dataOut.phi[:]) #Better results | |
2122 | for i in range(2,dataOut.NSHTS-2): |
|
2122 | for i in range(2,dataOut.NSHTS-2): | |
2123 | fact=(-0.5/(dataOut.RATE*dataOut.DH))*dataOut.bki[i] |
|
2123 | fact=(-0.5/(dataOut.RATE*dataOut.DH))*dataOut.bki[i] | |
2124 | #print("fact: ", fact,dataOut.RATE,dataOut.DH,dataOut.bki[i]) |
|
2124 | #print("fact: ", fact,dataOut.RATE,dataOut.DH,dataOut.bki[i]) | |
2125 | #four-point derivative, no phase unwrapping necessary |
|
2125 | #four-point derivative, no phase unwrapping necessary | |
2126 | #####dataOut.dphi[i]=((((theta[i+1]-theta[i-1])+(2.0*(theta[i+2]-theta[i-2])))/thetai[i])).real/10.0 #Original from C program |
|
2126 | #####dataOut.dphi[i]=((((theta[i+1]-theta[i-1])+(2.0*(theta[i+2]-theta[i-2])))/thetai[i])).real/10.0 #Original from C program | |
2127 |
|
2127 | |||
2128 | ##dataOut.dphi[i]=((((theta[i-2]-theta[i+2])+(8.0*(theta[i+1]-theta[i-1])))/thetai[i])).real/12.0 |
|
2128 | ##dataOut.dphi[i]=((((theta[i-2]-theta[i+2])+(8.0*(theta[i+1]-theta[i-1])))/thetai[i])).real/12.0 | |
2129 | dataOut.dphi[i]=((dataOut.phi[i+1]-dataOut.phi[i-1])+(2.0*(dataOut.phi[i+2]-dataOut.phi[i-2])))/10.0 #Better results |
|
2129 | dataOut.dphi[i]=((dataOut.phi[i+1]-dataOut.phi[i-1])+(2.0*(dataOut.phi[i+2]-dataOut.phi[i-2])))/10.0 #Better results | |
2130 |
|
2130 | |||
2131 | #dataOut.dphi_uc[i] = abs(dataOut.phi[i]*dataOut.bki[i]*(-0.5)/dataOut.DH) |
|
2131 | #dataOut.dphi_uc[i] = abs(dataOut.phi[i]*dataOut.bki[i]*(-0.5)/dataOut.DH) | |
2132 | #dataOut.dphi[i]=abs(dataOut.dphi[i]*fact) |
|
2132 | #dataOut.dphi[i]=abs(dataOut.dphi[i]*fact) | |
2133 | dataOut.dphi[i]=dataOut.dphi[i]*abs(fact) |
|
2133 | dataOut.dphi[i]=dataOut.dphi[i]*abs(fact) | |
2134 | dataOut.sdn1[i]=(4.*(dataOut.sdn2[i-2]+dataOut.sdn2[i+2])+dataOut.sdn2[i-1]+dataOut.sdn2[i+1]) |
|
2134 | dataOut.sdn1[i]=(4.*(dataOut.sdn2[i-2]+dataOut.sdn2[i+2])+dataOut.sdn2[i-1]+dataOut.sdn2[i+1]) | |
2135 | dataOut.sdn1[i]=numpy.sqrt(dataOut.sdn1[i])*fact |
|
2135 | dataOut.sdn1[i]=numpy.sqrt(dataOut.sdn1[i])*fact | |
2136 |
|
2136 | |||
2137 | return dataOut |
|
2137 | return dataOut | |
2138 |
|
2138 | |||
2139 |
|
2139 | |||
2140 | class NormalizeDPPower(Operation): |
|
2140 | class NormalizeDPPower(Operation): | |
2141 | ''' |
|
2141 | ''' | |
2142 | Written by R. Flores |
|
2142 | Written by R. Flores | |
2143 | ''' |
|
2143 | ''' | |
2144 | """Operation to normalize relative electron density from power with total electron density from Faraday angle. |
|
2144 | """Operation to normalize relative electron density from power with total electron density from Faraday angle. | |
2145 |
|
2145 | |||
2146 | Parameters: |
|
2146 | Parameters: | |
2147 | ----------- |
|
2147 | ----------- | |
2148 | None |
|
2148 | None | |
2149 |
|
2149 | |||
2150 | Example |
|
2150 | Example | |
2151 | -------- |
|
2151 | -------- | |
2152 |
|
2152 | |||
2153 | op = proc_unit.addOperation(name='NormalizeDPPower', optype='other') |
|
2153 | op = proc_unit.addOperation(name='NormalizeDPPower', optype='other') | |
2154 |
|
2154 | |||
2155 | """ |
|
2155 | """ | |
2156 |
|
2156 | |||
2157 | def __init__(self, **kwargs): |
|
2157 | def __init__(self, **kwargs): | |
2158 |
|
2158 | |||
2159 | Operation.__init__(self, **kwargs) |
|
2159 | Operation.__init__(self, **kwargs) | |
2160 | self.aux=1 |
|
2160 | self.aux=1 | |
2161 |
|
2161 | |||
2162 | def normal(self,a,b,n,m): |
|
2162 | def normal(self,a,b,n,m): | |
2163 | chmin=1.0e30 |
|
2163 | chmin=1.0e30 | |
2164 | chisq=numpy.zeros(150,'float32') |
|
2164 | chisq=numpy.zeros(150,'float32') | |
2165 | temp=numpy.zeros(150,'float32') |
|
2165 | temp=numpy.zeros(150,'float32') | |
2166 |
|
2166 | |||
2167 | for i in range(2*m-1): |
|
2167 | for i in range(2*m-1): | |
2168 | an=al=be=chisq[i]=0.0 |
|
2168 | an=al=be=chisq[i]=0.0 | |
2169 | for j in range(int(n/m)): |
|
2169 | for j in range(int(n/m)): | |
2170 | k=int(j+i*n/(2*m)) |
|
2170 | k=int(j+i*n/(2*m)) | |
2171 | if(a[k]>0.0 and b[k]>0.0): |
|
2171 | if(a[k]>0.0 and b[k]>0.0): | |
2172 | al+=a[k]*b[k] |
|
2172 | al+=a[k]*b[k] | |
2173 | be+=b[k]*b[k] |
|
2173 | be+=b[k]*b[k] | |
2174 |
|
2174 | |||
2175 | if(be>0.0): |
|
2175 | if(be>0.0): | |
2176 | temp[i]=al/be |
|
2176 | temp[i]=al/be | |
2177 | else: |
|
2177 | else: | |
2178 | temp[i]=1.0 |
|
2178 | temp[i]=1.0 | |
2179 |
|
2179 | |||
2180 | for j in range(int(n/m)): |
|
2180 | for j in range(int(n/m)): | |
2181 | k=int(j+i*n/(2*m)) |
|
2181 | k=int(j+i*n/(2*m)) | |
2182 | if(a[k]>0.0 and b[k]>0.0): |
|
2182 | if(a[k]>0.0 and b[k]>0.0): | |
2183 | chisq[i]+=(numpy.log10(b[k]*temp[i]/a[k]))**2 |
|
2183 | chisq[i]+=(numpy.log10(b[k]*temp[i]/a[k]))**2 | |
2184 | an=an+1 |
|
2184 | an=an+1 | |
2185 |
|
2185 | |||
2186 | if(chisq[i]>0.0): |
|
2186 | if(chisq[i]>0.0): | |
2187 | chisq[i]/=an |
|
2187 | chisq[i]/=an | |
2188 |
|
2188 | |||
2189 | for i in range(int(2*m-1)): |
|
2189 | for i in range(int(2*m-1)): | |
2190 | if(chisq[i]<chmin and chisq[i]>1.0e-6): |
|
2190 | if(chisq[i]<chmin and chisq[i]>1.0e-6): | |
2191 | chmin=chisq[i] |
|
2191 | chmin=chisq[i] | |
2192 | cf=temp[i] |
|
2192 | cf=temp[i] | |
2193 | return cf |
|
2193 | return cf | |
2194 |
|
2194 | |||
2195 | def normalize(self,dataOut): |
|
2195 | def normalize(self,dataOut): | |
2196 |
|
2196 | |||
2197 | if self.aux==1: |
|
2197 | if self.aux==1: | |
2198 | dataOut.cf=numpy.zeros(1,'float32') |
|
2198 | dataOut.cf=numpy.zeros(1,'float32') | |
2199 | dataOut.cflast=numpy.zeros(1,'float32') |
|
2199 | dataOut.cflast=numpy.zeros(1,'float32') | |
2200 | self.aux=0 |
|
2200 | self.aux=0 | |
2201 |
|
2201 | |||
2202 | night_first=300.0 |
|
2202 | night_first=300.0 | |
2203 | night_first1= 310.0 |
|
2203 | night_first1= 310.0 | |
2204 | night_end= 450.0 |
|
2204 | night_end= 450.0 | |
2205 | day_first=250.0 |
|
2205 | day_first=250.0 | |
2206 | day_end=400.0 |
|
2206 | day_end=400.0 | |
2207 | day_first_sunrise=190.0 |
|
2207 | day_first_sunrise=190.0 | |
2208 | day_end_sunrise=280.0 |
|
2208 | day_end_sunrise=280.0 | |
2209 |
|
2209 | |||
2210 | #print(dataOut.ut_Faraday) |
|
2210 | #print(dataOut.ut_Faraday) | |
2211 | if(dataOut.ut_Faraday>4.0 and dataOut.ut_Faraday<11.0): #early |
|
2211 | if(dataOut.ut_Faraday>4.0 and dataOut.ut_Faraday<11.0): #early | |
2212 | #print("EARLY") |
|
2212 | #print("EARLY") | |
2213 | i2=(night_end-dataOut.range1[0])/dataOut.DH |
|
2213 | i2=(night_end-dataOut.range1[0])/dataOut.DH | |
2214 | i1=(night_first -dataOut.range1[0])/dataOut.DH |
|
2214 | i1=(night_first -dataOut.range1[0])/dataOut.DH | |
2215 | elif (dataOut.ut_Faraday>0.0 and dataOut.ut_Faraday<4.0): #night |
|
2215 | elif (dataOut.ut_Faraday>0.0 and dataOut.ut_Faraday<4.0): #night | |
2216 | #print("NIGHT") |
|
2216 | #print("NIGHT") | |
2217 | i2=(night_end-dataOut.range1[0])/dataOut.DH |
|
2217 | i2=(night_end-dataOut.range1[0])/dataOut.DH | |
2218 | i1=(night_first1 -dataOut.range1[0])/dataOut.DH |
|
2218 | i1=(night_first1 -dataOut.range1[0])/dataOut.DH | |
2219 | elif (dataOut.ut_Faraday>=11.0 and dataOut.ut_Faraday<13.5): #sunrise |
|
2219 | elif (dataOut.ut_Faraday>=11.0 and dataOut.ut_Faraday<13.5): #sunrise | |
2220 | #print("SUNRISE") |
|
2220 | #print("SUNRISE") | |
2221 | i2=( day_end_sunrise-dataOut.range1[0])/dataOut.DH |
|
2221 | i2=( day_end_sunrise-dataOut.range1[0])/dataOut.DH | |
2222 | i1=(day_first_sunrise - dataOut.range1[0])/dataOut.DH |
|
2222 | i1=(day_first_sunrise - dataOut.range1[0])/dataOut.DH | |
2223 | else: |
|
2223 | else: | |
2224 | #print("ELSE") |
|
2224 | #print("ELSE") | |
2225 | i2=(day_end-dataOut.range1[0])/dataOut.DH |
|
2225 | i2=(day_end-dataOut.range1[0])/dataOut.DH | |
2226 | i1=(day_first -dataOut.range1[0])/dataOut.DH |
|
2226 | i1=(day_first -dataOut.range1[0])/dataOut.DH | |
2227 | #print(i1*dataOut.DH) |
|
2227 | #print(i1*dataOut.DH) | |
2228 | #print(i2*dataOut.DH) |
|
2228 | #print(i2*dataOut.DH) | |
2229 |
|
2229 | |||
2230 | i1=int(i1) |
|
2230 | i1=int(i1) | |
2231 | i2=int(i2) |
|
2231 | i2=int(i2) | |
2232 |
|
2232 | |||
2233 | try: |
|
2233 | try: | |
2234 | dataOut.cf=self.normal(dataOut.dphi[i1::], dataOut.ph2[i1::], i2-i1, 1) |
|
2234 | dataOut.cf=self.normal(dataOut.dphi[i1::], dataOut.ph2[i1::], i2-i1, 1) | |
2235 | except: |
|
2235 | except: | |
2236 | pass |
|
2236 | pass | |
2237 |
|
2237 | |||
2238 | #print(dataOut.ph2) |
|
2238 | #print(dataOut.ph2) | |
2239 | #input() |
|
2239 | #input() | |
2240 | # in case of spread F, normalize much higher |
|
2240 | # in case of spread F, normalize much higher | |
2241 | if(dataOut.cf<dataOut.cflast[0]/10.0): |
|
2241 | if(dataOut.cf<dataOut.cflast[0]/10.0): | |
2242 | i1=(night_first1+100.-dataOut.range1[0])/dataOut.DH |
|
2242 | i1=(night_first1+100.-dataOut.range1[0])/dataOut.DH | |
2243 | i2=(night_end+100.0-dataOut.range1[0])/dataOut.DH |
|
2243 | i2=(night_end+100.0-dataOut.range1[0])/dataOut.DH | |
2244 | i1=int(i1) |
|
2244 | i1=int(i1) | |
2245 | i2=int(i2) |
|
2245 | i2=int(i2) | |
2246 | try: |
|
2246 | try: | |
2247 | dataOut.cf=self.normal(dataOut.dphi[int(i1)::], dataOut.ph2[int(i1)::], int(i2-i1), 1) |
|
2247 | dataOut.cf=self.normal(dataOut.dphi[int(i1)::], dataOut.ph2[int(i1)::], int(i2-i1), 1) | |
2248 | except: |
|
2248 | except: | |
2249 | pass |
|
2249 | pass | |
2250 |
|
2250 | |||
2251 | dataOut.cflast[0]=dataOut.cf |
|
2251 | dataOut.cflast[0]=dataOut.cf | |
2252 |
|
2252 | |||
2253 | ## normalize double pulse power and error bars to Faraday |
|
2253 | ## normalize double pulse power and error bars to Faraday | |
2254 | for i in range(dataOut.NSHTS): |
|
2254 | for i in range(dataOut.NSHTS): | |
2255 | dataOut.ph2[i]*=dataOut.cf |
|
2255 | dataOut.ph2[i]*=dataOut.cf | |
2256 | dataOut.sdp2[i]*=dataOut.cf |
|
2256 | dataOut.sdp2[i]*=dataOut.cf | |
2257 | #print(dataOut.ph2) |
|
2257 | #print(dataOut.ph2) | |
2258 | #input() |
|
2258 | #input() | |
2259 |
|
2259 | |||
2260 | for i in range(dataOut.NSHTS): |
|
2260 | for i in range(dataOut.NSHTS): | |
2261 | dataOut.ph2[i]=(max(1.0, dataOut.ph2[i])) |
|
2261 | dataOut.ph2[i]=(max(1.0, dataOut.ph2[i])) | |
2262 | dataOut.dphi[i]=(max(1.0, dataOut.dphi[i])) |
|
2262 | dataOut.dphi[i]=(max(1.0, dataOut.dphi[i])) | |
2263 |
|
2263 | |||
2264 |
|
2264 | |||
2265 | def run(self,dataOut): |
|
2265 | def run(self,dataOut): | |
2266 |
|
2266 | |||
2267 | self.normalize(dataOut) |
|
2267 | self.normalize(dataOut) | |
2268 | #print(dataOut.ph2) |
|
2268 | #print(dataOut.ph2) | |
2269 | #print(dataOut.sdp2) |
|
2269 | #print(dataOut.sdp2) | |
2270 | #input() |
|
2270 | #input() | |
2271 |
|
2271 | |||
2272 |
|
2272 | |||
2273 | return dataOut |
|
2273 | return dataOut | |
2274 |
|
2274 | |||
2275 | class NormalizeDPPowerRoberto(Operation): |
|
2275 | class NormalizeDPPowerRoberto(Operation): | |
2276 | ''' |
|
2276 | ''' | |
2277 | Written by R. Flores |
|
2277 | Written by R. Flores | |
2278 | ''' |
|
2278 | ''' | |
2279 | """Operation to normalize relative electron density from power with total electron density from Farday angle. |
|
2279 | """Operation to normalize relative electron density from power with total electron density from Farday angle. | |
2280 |
|
2280 | |||
2281 | Parameters: |
|
2281 | Parameters: | |
2282 | ----------- |
|
2282 | ----------- | |
2283 | None |
|
2283 | None | |
2284 |
|
2284 | |||
2285 | Example |
|
2285 | Example | |
2286 | -------- |
|
2286 | -------- | |
2287 |
|
2287 | |||
2288 | op = proc_unit.addOperation(name='NormalizeDPPower', optype='other') |
|
2288 | op = proc_unit.addOperation(name='NormalizeDPPower', optype='other') | |
2289 |
|
2289 | |||
2290 | """ |
|
2290 | """ | |
2291 |
|
2291 | |||
2292 | def __init__(self, **kwargs): |
|
2292 | def __init__(self, **kwargs): | |
2293 |
|
2293 | |||
2294 | Operation.__init__(self, **kwargs) |
|
2294 | Operation.__init__(self, **kwargs) | |
2295 | self.aux=1 |
|
2295 | self.aux=1 | |
2296 |
|
2296 | |||
2297 | def normal(self,a,b,n,m): |
|
2297 | def normal(self,a,b,n,m): | |
2298 | chmin=1.0e30 |
|
2298 | chmin=1.0e30 | |
2299 | chisq=numpy.zeros(150,'float32') |
|
2299 | chisq=numpy.zeros(150,'float32') | |
2300 | temp=numpy.zeros(150,'float32') |
|
2300 | temp=numpy.zeros(150,'float32') | |
2301 |
|
2301 | |||
2302 | for i in range(2*m-1): |
|
2302 | for i in range(2*m-1): | |
2303 | an=al=be=chisq[i]=0.0 |
|
2303 | an=al=be=chisq[i]=0.0 | |
2304 | for j in range(int(n/m)): |
|
2304 | for j in range(int(n/m)): | |
2305 | k=int(j+i*n/(2*m)) |
|
2305 | k=int(j+i*n/(2*m)) | |
2306 | if(a[k]>0.0 and b[k]>0.0): |
|
2306 | if(a[k]>0.0 and b[k]>0.0): | |
2307 | al+=a[k]*b[k] |
|
2307 | al+=a[k]*b[k] | |
2308 | be+=b[k]*b[k] |
|
2308 | be+=b[k]*b[k] | |
2309 |
|
2309 | |||
2310 | if(be>0.0): |
|
2310 | if(be>0.0): | |
2311 | temp[i]=al/be |
|
2311 | temp[i]=al/be | |
2312 | else: |
|
2312 | else: | |
2313 | temp[i]=1.0 |
|
2313 | temp[i]=1.0 | |
2314 |
|
2314 | |||
2315 | for j in range(int(n/m)): |
|
2315 | for j in range(int(n/m)): | |
2316 | k=int(j+i*n/(2*m)) |
|
2316 | k=int(j+i*n/(2*m)) | |
2317 | if(a[k]>0.0 and b[k]>0.0): |
|
2317 | if(a[k]>0.0 and b[k]>0.0): | |
2318 | chisq[i]+=(numpy.log10(b[k]*temp[i]/a[k]))**2 |
|
2318 | chisq[i]+=(numpy.log10(b[k]*temp[i]/a[k]))**2 | |
2319 | an=an+1 |
|
2319 | an=an+1 | |
2320 |
|
2320 | |||
2321 | if(chisq[i]>0.0): |
|
2321 | if(chisq[i]>0.0): | |
2322 | chisq[i]/=an |
|
2322 | chisq[i]/=an | |
2323 |
|
2323 | |||
2324 | for i in range(int(2*m-1)): |
|
2324 | for i in range(int(2*m-1)): | |
2325 | if(chisq[i]<chmin and chisq[i]>1.0e-6): |
|
2325 | if(chisq[i]<chmin and chisq[i]>1.0e-6): | |
2326 | chmin=chisq[i] |
|
2326 | chmin=chisq[i] | |
2327 | cf=temp[i] |
|
2327 | cf=temp[i] | |
2328 | return cf |
|
2328 | return cf | |
2329 |
|
2329 | |||
2330 | def normalize(self,dataOut): |
|
2330 | def normalize(self,dataOut): | |
2331 |
|
2331 | |||
2332 | if self.aux==1: |
|
2332 | if self.aux==1: | |
2333 | dataOut.cf=numpy.zeros(1,'float32') |
|
2333 | dataOut.cf=numpy.zeros(1,'float32') | |
2334 | dataOut.cflast=numpy.zeros(1,'float32') |
|
2334 | dataOut.cflast=numpy.zeros(1,'float32') | |
2335 | self.aux=0 |
|
2335 | self.aux=0 | |
2336 |
|
2336 | |||
2337 | night_first=300.0 |
|
2337 | night_first=300.0 | |
2338 | night_first1= 310.0 |
|
2338 | night_first1= 310.0 | |
2339 | night_end= 450.0 |
|
2339 | night_end= 450.0 | |
2340 | day_first=250.0 |
|
2340 | day_first=250.0 | |
2341 | day_end=400.0 |
|
2341 | day_end=400.0 | |
2342 | day_first_sunrise=190.0 |
|
2342 | day_first_sunrise=190.0 | |
2343 | day_end_sunrise=350.0 |
|
2343 | day_end_sunrise=350.0 | |
2344 |
|
2344 | |||
2345 | print(dataOut.ut_Faraday) |
|
2345 | print(dataOut.ut_Faraday) | |
2346 | ''' |
|
2346 | ''' | |
2347 | if(dataOut.ut_Faraday>4.0 and dataOut.ut_Faraday<11.0): #early |
|
2347 | if(dataOut.ut_Faraday>4.0 and dataOut.ut_Faraday<11.0): #early | |
2348 | print("EARLY") |
|
2348 | print("EARLY") | |
2349 | i2=(night_end-dataOut.range1[0])/dataOut.DH |
|
2349 | i2=(night_end-dataOut.range1[0])/dataOut.DH | |
2350 | i1=(night_first -dataOut.range1[0])/dataOut.DH |
|
2350 | i1=(night_first -dataOut.range1[0])/dataOut.DH | |
2351 | elif (dataOut.ut_Faraday>0.0 and dataOut.ut_Faraday<4.0): #night |
|
2351 | elif (dataOut.ut_Faraday>0.0 and dataOut.ut_Faraday<4.0): #night | |
2352 | print("NIGHT") |
|
2352 | print("NIGHT") | |
2353 | i2=(night_end-dataOut.range1[0])/dataOut.DH |
|
2353 | i2=(night_end-dataOut.range1[0])/dataOut.DH | |
2354 | i1=(night_first1 -dataOut.range1[0])/dataOut.DH |
|
2354 | i1=(night_first1 -dataOut.range1[0])/dataOut.DH | |
2355 | elif (dataOut.ut_Faraday>=11.0 and dataOut.ut_Faraday<13.5): #sunrise |
|
2355 | elif (dataOut.ut_Faraday>=11.0 and dataOut.ut_Faraday<13.5): #sunrise | |
2356 | print("SUNRISE") |
|
2356 | print("SUNRISE") | |
2357 | i2=( day_end_sunrise-dataOut.range1[0])/dataOut.DH |
|
2357 | i2=( day_end_sunrise-dataOut.range1[0])/dataOut.DH | |
2358 | i1=(day_first_sunrise - dataOut.range1[0])/dataOut.DH |
|
2358 | i1=(day_first_sunrise - dataOut.range1[0])/dataOut.DH | |
2359 | else: |
|
2359 | else: | |
2360 | print("ELSE") |
|
2360 | print("ELSE") | |
2361 | i2=(day_end-dataOut.range1[0])/dataOut.DH |
|
2361 | i2=(day_end-dataOut.range1[0])/dataOut.DH | |
2362 | i1=(day_first -dataOut.range1[0])/dataOut.DH |
|
2362 | i1=(day_first -dataOut.range1[0])/dataOut.DH | |
2363 | ''' |
|
2363 | ''' | |
2364 | i2=(420-dataOut.range1[0])/dataOut.DH |
|
2364 | i2=(420-dataOut.range1[0])/dataOut.DH | |
2365 | i1=(200 -dataOut.range1[0])/dataOut.DH |
|
2365 | i1=(200 -dataOut.range1[0])/dataOut.DH | |
2366 | print(i1*dataOut.DH) |
|
2366 | print(i1*dataOut.DH) | |
2367 | print(i2*dataOut.DH) |
|
2367 | print(i2*dataOut.DH) | |
2368 |
|
2368 | |||
2369 | i1=int(i1) |
|
2369 | i1=int(i1) | |
2370 | i2=int(i2) |
|
2370 | i2=int(i2) | |
2371 |
|
2371 | |||
2372 | try: |
|
2372 | try: | |
2373 | dataOut.cf=self.normal(dataOut.dphi[i1::], dataOut.ph2[i1::], i2-i1, 1) |
|
2373 | dataOut.cf=self.normal(dataOut.dphi[i1::], dataOut.ph2[i1::], i2-i1, 1) | |
2374 | except: |
|
2374 | except: | |
2375 | pass |
|
2375 | pass | |
2376 |
|
2376 | |||
2377 | #print(dataOut.ph2) |
|
2377 | #print(dataOut.ph2) | |
2378 | #input() |
|
2378 | #input() | |
2379 | # in case of spread F, normalize much higher |
|
2379 | # in case of spread F, normalize much higher | |
2380 | if(dataOut.cf<dataOut.cflast[0]/10.0): |
|
2380 | if(dataOut.cf<dataOut.cflast[0]/10.0): | |
2381 | i1=(night_first1+100.-dataOut.range1[0])/dataOut.DH |
|
2381 | i1=(night_first1+100.-dataOut.range1[0])/dataOut.DH | |
2382 | i2=(night_end+100.0-dataOut.range1[0])/dataOut.DH |
|
2382 | i2=(night_end+100.0-dataOut.range1[0])/dataOut.DH | |
2383 | i1=int(i1) |
|
2383 | i1=int(i1) | |
2384 | i2=int(i2) |
|
2384 | i2=int(i2) | |
2385 | try: |
|
2385 | try: | |
2386 | dataOut.cf=self.normal(dataOut.dphi[int(i1)::], dataOut.ph2[int(i1)::], int(i2-i1), 1) |
|
2386 | dataOut.cf=self.normal(dataOut.dphi[int(i1)::], dataOut.ph2[int(i1)::], int(i2-i1), 1) | |
2387 | except: |
|
2387 | except: | |
2388 | pass |
|
2388 | pass | |
2389 |
|
2389 | |||
2390 | dataOut.cflast[0]=dataOut.cf |
|
2390 | dataOut.cflast[0]=dataOut.cf | |
2391 |
|
2391 | |||
2392 | ## normalize double pulse power and error bars to Faraday |
|
2392 | ## normalize double pulse power and error bars to Faraday | |
2393 | for i in range(dataOut.NSHTS): |
|
2393 | for i in range(dataOut.NSHTS): | |
2394 | dataOut.ph2[i]*=dataOut.cf |
|
2394 | dataOut.ph2[i]*=dataOut.cf | |
2395 | dataOut.sdp2[i]*=dataOut.cf |
|
2395 | dataOut.sdp2[i]*=dataOut.cf | |
2396 | #print(dataOut.ph2) |
|
2396 | #print(dataOut.ph2) | |
2397 | #input() |
|
2397 | #input() | |
2398 |
|
2398 | |||
2399 | for i in range(dataOut.NSHTS): |
|
2399 | for i in range(dataOut.NSHTS): | |
2400 | dataOut.ph2[i]=(max(1.0, dataOut.ph2[i])) |
|
2400 | dataOut.ph2[i]=(max(1.0, dataOut.ph2[i])) | |
2401 | dataOut.dphi[i]=(max(1.0, dataOut.dphi[i])) |
|
2401 | dataOut.dphi[i]=(max(1.0, dataOut.dphi[i])) | |
2402 |
|
2402 | |||
2403 |
|
2403 | |||
2404 | def run(self,dataOut): |
|
2404 | def run(self,dataOut): | |
2405 |
|
2405 | |||
2406 | self.normalize(dataOut) |
|
2406 | self.normalize(dataOut) | |
2407 | #print(dataOut.ph2) |
|
2407 | #print(dataOut.ph2) | |
2408 | #print(dataOut.sdp2) |
|
2408 | #print(dataOut.sdp2) | |
2409 | #input() |
|
2409 | #input() | |
2410 |
|
2410 | |||
2411 |
|
2411 | |||
2412 | return dataOut |
|
2412 | return dataOut | |
2413 |
|
2413 | |||
2414 | class NormalizeDPPowerRoberto_V2(Operation): |
|
2414 | class NormalizeDPPowerRoberto_V2(Operation): | |
2415 | ''' |
|
2415 | ''' | |
2416 | Written by R. Flores |
|
2416 | Written by R. Flores | |
2417 | ''' |
|
2417 | ''' | |
2418 | """Operation to normalize relative electron density from power with total electron density from Farday angle. |
|
2418 | """Operation to normalize relative electron density from power with total electron density from Farday angle. | |
2419 |
|
2419 | |||
2420 | Parameters: |
|
2420 | Parameters: | |
2421 | ----------- |
|
2421 | ----------- | |
2422 | None |
|
2422 | None | |
2423 |
|
2423 | |||
2424 | Example |
|
2424 | Example | |
2425 | -------- |
|
2425 | -------- | |
2426 |
|
2426 | |||
2427 | op = proc_unit.addOperation(name='NormalizeDPPower', optype='other') |
|
2427 | op = proc_unit.addOperation(name='NormalizeDPPower', optype='other') | |
2428 |
|
2428 | |||
2429 | """ |
|
2429 | """ | |
2430 |
|
2430 | |||
2431 | def __init__(self, **kwargs): |
|
2431 | def __init__(self, **kwargs): | |
2432 |
|
2432 | |||
2433 | Operation.__init__(self, **kwargs) |
|
2433 | Operation.__init__(self, **kwargs) | |
2434 | self.aux=1 |
|
2434 | self.aux=1 | |
2435 |
|
2435 | |||
2436 | def normal(self,a,b,n,m): |
|
2436 | def normal(self,a,b,n,m): | |
2437 | chmin=1.0e30 |
|
2437 | chmin=1.0e30 | |
2438 | chisq=numpy.zeros(150,'float32') |
|
2438 | chisq=numpy.zeros(150,'float32') | |
2439 | temp=numpy.zeros(150,'float32') |
|
2439 | temp=numpy.zeros(150,'float32') | |
2440 |
|
2440 | |||
2441 | for i in range(2*m-1): |
|
2441 | for i in range(2*m-1): | |
2442 | an=al=be=chisq[i]=0.0 |
|
2442 | an=al=be=chisq[i]=0.0 | |
2443 | for j in range(int(n/m)): |
|
2443 | for j in range(int(n/m)): | |
2444 | k=int(j+i*n/(2*m)) |
|
2444 | k=int(j+i*n/(2*m)) | |
2445 | if(a[k]>0.0 and b[k]>0.0): |
|
2445 | if(a[k]>0.0 and b[k]>0.0): | |
2446 | al+=a[k]*b[k] |
|
2446 | al+=a[k]*b[k] | |
2447 | be+=b[k]*b[k] |
|
2447 | be+=b[k]*b[k] | |
2448 |
|
2448 | |||
2449 | if(be>0.0): |
|
2449 | if(be>0.0): | |
2450 | temp[i]=al/be |
|
2450 | temp[i]=al/be | |
2451 | else: |
|
2451 | else: | |
2452 | temp[i]=1.0 |
|
2452 | temp[i]=1.0 | |
2453 |
|
2453 | |||
2454 | for j in range(int(n/m)): |
|
2454 | for j in range(int(n/m)): | |
2455 | k=int(j+i*n/(2*m)) |
|
2455 | k=int(j+i*n/(2*m)) | |
2456 | if(a[k]>0.0 and b[k]>0.0): |
|
2456 | if(a[k]>0.0 and b[k]>0.0): | |
2457 | chisq[i]+=(numpy.log10(b[k]*temp[i]/a[k]))**2 |
|
2457 | chisq[i]+=(numpy.log10(b[k]*temp[i]/a[k]))**2 | |
2458 | an=an+1 |
|
2458 | an=an+1 | |
2459 |
|
2459 | |||
2460 | if(chisq[i]>0.0): |
|
2460 | if(chisq[i]>0.0): | |
2461 | chisq[i]/=an |
|
2461 | chisq[i]/=an | |
2462 |
|
2462 | |||
2463 | for i in range(int(2*m-1)): |
|
2463 | for i in range(int(2*m-1)): | |
2464 | if(chisq[i]<chmin and chisq[i]>1.0e-6): |
|
2464 | if(chisq[i]<chmin and chisq[i]>1.0e-6): | |
2465 | chmin=chisq[i] |
|
2465 | chmin=chisq[i] | |
2466 | cf=temp[i] |
|
2466 | cf=temp[i] | |
2467 | return cf |
|
2467 | return cf | |
2468 |
|
2468 | |||
2469 |
|
2469 | |||
2470 | def normalize(self,dataOut): |
|
2470 | def normalize(self,dataOut): | |
2471 |
|
2471 | |||
2472 | if self.aux==1: |
|
2472 | if self.aux==1: | |
2473 | dataOut.cf=numpy.zeros(1,'float32') |
|
2473 | dataOut.cf=numpy.zeros(1,'float32') | |
2474 | dataOut.cflast=numpy.zeros(1,'float32') |
|
2474 | dataOut.cflast=numpy.zeros(1,'float32') | |
2475 | self.aux=0 |
|
2475 | self.aux=0 | |
2476 |
|
2476 | |||
2477 | if (dataOut.ut_Faraday>=11.5 and dataOut.ut_Faraday<23): |
|
2477 | if (dataOut.ut_Faraday>=11.5 and dataOut.ut_Faraday<23): | |
2478 | i2=(500.-dataOut.range1[0])/dataOut.DH |
|
2478 | i2=(500.-dataOut.range1[0])/dataOut.DH | |
2479 | i1=(200.-dataOut.range1[0])/dataOut.DH |
|
2479 | i1=(200.-dataOut.range1[0])/dataOut.DH | |
2480 |
|
2480 | |||
2481 | else: |
|
2481 | else: | |
2482 | inda = numpy.where(dataOut.heightList >= 200) #200 km |
|
2482 | inda = numpy.where(dataOut.heightList >= 200) #200 km | |
2483 | minIndex = inda[0][0] |
|
2483 | minIndex = inda[0][0] | |
2484 | indb = numpy.where(dataOut.heightList < 700) # 700 km |
|
2484 | indb = numpy.where(dataOut.heightList < 700) # 700 km | |
2485 | maxIndex = indb[0][-1] |
|
2485 | maxIndex = indb[0][-1] | |
2486 |
|
2486 | |||
2487 | ph2max_idx = numpy.nanargmax(dataOut.ph2[minIndex:maxIndex]) |
|
2487 | ph2max_idx = numpy.nanargmax(dataOut.ph2[minIndex:maxIndex]) | |
2488 | ph2max_idx += minIndex |
|
2488 | ph2max_idx += minIndex | |
2489 |
|
2489 | |||
2490 | i2 = ph2max_idx + 6 |
|
2490 | i2 = ph2max_idx + 6 | |
2491 | i1 = ph2max_idx - 6 |
|
2491 | i1 = ph2max_idx - 6 | |
2492 |
|
2492 | |||
2493 | try: |
|
2493 | try: | |
2494 | dataOut.heightList[i2] |
|
2494 | dataOut.heightList[i2] | |
2495 | except: |
|
2495 | except: | |
2496 | i2 -= 1 |
|
2496 | i2 -= 1 | |
2497 |
|
2497 | |||
2498 | i1=int(i1) |
|
2498 | i1=int(i1) | |
2499 | i2=int(i2) |
|
2499 | i2=int(i2) | |
2500 |
|
2500 | |||
2501 | if dataOut.flagTeTiCorrection: |
|
2501 | if dataOut.flagTeTiCorrection: | |
2502 | for i in range(dataOut.NSHTS): |
|
2502 | for i in range(dataOut.NSHTS): | |
2503 | dataOut.ph2[i]/=dataOut.cf |
|
2503 | dataOut.ph2[i]/=dataOut.cf | |
2504 | dataOut.sdp2[i]/=dataOut.cf |
|
2504 | dataOut.sdp2[i]/=dataOut.cf | |
2505 |
|
2505 | |||
2506 | if hasattr(dataOut, 'flagSpreadF') and dataOut.flagSpreadF: |
|
2506 | if hasattr(dataOut, 'flagSpreadF') and dataOut.flagSpreadF: | |
2507 | i2=int((700-dataOut.range1[0])/dataOut.DH) |
|
2507 | i2=int((700-dataOut.range1[0])/dataOut.DH) | |
2508 | nanindex = numpy.argwhere(numpy.isnan(dataOut.ph2)) |
|
2508 | nanindex = numpy.argwhere(numpy.isnan(dataOut.ph2)) | |
2509 | i1 = nanindex[-1][0] #VER CUANDO i1>i2 |
|
2509 | i1 = nanindex[-1][0] #VER CUANDO i1>i2 | |
2510 | if i1 != numpy.shape(dataOut.heightList)[0]: |
|
2510 | if i1 != numpy.shape(dataOut.heightList)[0]: | |
2511 | i1 += 1+2 #Se suma uno para no tomar el nan, se suma 2 para no tomar datos nan de "phi" debido al calculo de la derivada |
|
2511 | i1 += 1+2 #Se suma uno para no tomar el nan, se suma 2 para no tomar datos nan de "phi" debido al calculo de la derivada | |
2512 | if i1 >= i2: |
|
2512 | if i1 >= i2: | |
2513 | i1 = i2-4 |
|
2513 | i1 = i2-4 | |
2514 |
|
2514 | |||
2515 | try: |
|
2515 | try: | |
2516 | dataOut.cf=self.normal(dataOut.dphi[i1::], dataOut.ph2[i1::], i2-i1, 1) |
|
2516 | dataOut.cf=self.normal(dataOut.dphi[i1::], dataOut.ph2[i1::], i2-i1, 1) | |
2517 |
|
2517 | |||
2518 | except: |
|
2518 | except: | |
2519 | print("except") |
|
2519 | print("except") | |
2520 | dataOut.cf = numpy.nan |
|
2520 | dataOut.cf = numpy.nan | |
2521 |
|
2521 | |||
2522 | night_first1= 300.0#350.0 |
|
2522 | night_first1= 300.0#350.0 | |
2523 | night_end= 450.0 |
|
2523 | night_end= 450.0 | |
2524 | night_first1= 220.0#350.0 |
|
2524 | night_first1= 220.0#350.0 | |
2525 | night_end= 400.0 |
|
2525 | night_end= 400.0 | |
2526 |
|
2526 | |||
2527 | if(dataOut.cf<dataOut.cflast[0]/10.0): |
|
2527 | if(dataOut.cf<dataOut.cflast[0]/10.0): | |
2528 | i1=(night_first1-dataOut.range1[0])/dataOut.DH |
|
2528 | i1=(night_first1-dataOut.range1[0])/dataOut.DH | |
2529 | i2=(night_end-dataOut.range1[0])/dataOut.DH |
|
2529 | i2=(night_end-dataOut.range1[0])/dataOut.DH | |
2530 | i1=int(i1) |
|
2530 | i1=int(i1) | |
2531 | i2=int(i2) |
|
2531 | i2=int(i2) | |
2532 | try: |
|
2532 | try: | |
2533 | dataOut.cf=self.normal(dataOut.dphi[int(i1)::], dataOut.ph2[int(i1)::], int(i2-i1), 1) |
|
2533 | dataOut.cf=self.normal(dataOut.dphi[int(i1)::], dataOut.ph2[int(i1)::], int(i2-i1), 1) | |
2534 | except: |
|
2534 | except: | |
2535 | pass |
|
2535 | pass | |
2536 |
|
2536 | |||
2537 | dataOut.cflast[0]=dataOut.cf |
|
2537 | dataOut.cflast[0]=dataOut.cf | |
2538 |
|
2538 | |||
2539 | ## normalize double pulse power and error bars to Faraday |
|
2539 | ## normalize double pulse power and error bars to Faraday | |
2540 | for i in range(dataOut.NSHTS): |
|
2540 | for i in range(dataOut.NSHTS): | |
2541 | dataOut.ph2[i]*=dataOut.cf |
|
2541 | dataOut.ph2[i]*=dataOut.cf | |
2542 | dataOut.sdp2[i]*=dataOut.cf |
|
2542 | dataOut.sdp2[i]*=dataOut.cf | |
2543 |
|
2543 | |||
2544 | for i in range(dataOut.NSHTS): |
|
2544 | for i in range(dataOut.NSHTS): | |
2545 | dataOut.ph2[i]=(max(1.0, dataOut.ph2[i])) |
|
2545 | dataOut.ph2[i]=(max(1.0, dataOut.ph2[i])) | |
2546 | dataOut.dphi[i]=(max(1.0, dataOut.dphi[i])) |
|
2546 | dataOut.dphi[i]=(max(1.0, dataOut.dphi[i])) | |
2547 |
|
2547 | |||
2548 | def run(self,dataOut): |
|
2548 | def run(self,dataOut): | |
2549 |
|
2549 | |||
2550 | self.normalize(dataOut) |
|
2550 | self.normalize(dataOut) | |
2551 |
|
2551 | |||
2552 | return dataOut |
|
2552 | return dataOut | |
2553 |
|
2553 | |||
2554 | class suppress_stdout_stderr(object): |
|
2554 | class suppress_stdout_stderr(object): | |
2555 | ''' |
|
2555 | ''' | |
2556 | A context manager for doing a "deep suppression" of stdout and stderr in |
|
2556 | A context manager for doing a "deep suppression" of stdout and stderr in | |
2557 | Python, i.e. will suppress all print, even if the print originates in a |
|
2557 | Python, i.e. will suppress all print, even if the print originates in a | |
2558 | compiled C/Fortran sub-function. |
|
2558 | compiled C/Fortran sub-function. | |
2559 | This will not suppress raised exceptions, since exceptions are printed |
|
2559 | This will not suppress raised exceptions, since exceptions are printed | |
2560 | to stderr just before a script exits, and after the context manager has |
|
2560 | to stderr just before a script exits, and after the context manager has | |
2561 | exited (at least, I think that is why it lets exceptions through). |
|
2561 | exited (at least, I think that is why it lets exceptions through). | |
2562 |
|
2562 | |||
2563 | ''' |
|
2563 | ''' | |
2564 | def __init__(self): |
|
2564 | def __init__(self): | |
2565 | # Open a pair of null files |
|
2565 | # Open a pair of null files | |
2566 | self.null_fds = [os.open(os.devnull,os.O_RDWR) for x in range(2)] |
|
2566 | self.null_fds = [os.open(os.devnull,os.O_RDWR) for x in range(2)] | |
2567 | # Save the actual stdout (1) and stderr (2) file descriptors. |
|
2567 | # Save the actual stdout (1) and stderr (2) file descriptors. | |
2568 | self.save_fds = [os.dup(1), os.dup(2)] |
|
2568 | self.save_fds = [os.dup(1), os.dup(2)] | |
2569 |
|
2569 | |||
2570 | def __enter__(self): |
|
2570 | def __enter__(self): | |
2571 | # Assign the null pointers to stdout and stderr. |
|
2571 | # Assign the null pointers to stdout and stderr. | |
2572 | os.dup2(self.null_fds[0],1) |
|
2572 | os.dup2(self.null_fds[0],1) | |
2573 | os.dup2(self.null_fds[1],2) |
|
2573 | os.dup2(self.null_fds[1],2) | |
2574 |
|
2574 | |||
2575 | def __exit__(self, *_): |
|
2575 | def __exit__(self, *_): | |
2576 | # Re-assign the real stdout/stderr back to (1) and (2) |
|
2576 | # Re-assign the real stdout/stderr back to (1) and (2) | |
2577 | os.dup2(self.save_fds[0],1) |
|
2577 | os.dup2(self.save_fds[0],1) | |
2578 | os.dup2(self.save_fds[1],2) |
|
2578 | os.dup2(self.save_fds[1],2) | |
2579 | # Close all file descriptors |
|
2579 | # Close all file descriptors | |
2580 | for fd in self.null_fds + self.save_fds: |
|
2580 | for fd in self.null_fds + self.save_fds: | |
2581 | os.close(fd) |
|
2581 | os.close(fd) | |
2582 |
|
2582 | |||
2583 |
|
2583 | |||
2584 | class DPTemperaturesEstimation(Operation): |
|
2584 | class DPTemperaturesEstimation(Operation): | |
2585 | ''' |
|
2585 | ''' | |
2586 | Written by R. Flores |
|
2586 | Written by R. Flores | |
2587 | ''' |
|
2587 | ''' | |
2588 | """Operation to estimate temperatures for Double Pulse data. |
|
2588 | """Operation to estimate temperatures for Double Pulse data. | |
2589 |
|
2589 | |||
2590 | Parameters: |
|
2590 | Parameters: | |
2591 | ----------- |
|
2591 | ----------- | |
2592 | IBITS : int |
|
2592 | IBITS : int | |
2593 | .* |
|
2593 | .* | |
2594 |
|
2594 | |||
2595 | Example |
|
2595 | Example | |
2596 | -------- |
|
2596 | -------- | |
2597 |
|
2597 | |||
2598 | op = proc_unit.addOperation(name='DPTemperaturesEstimation', optype='other') |
|
2598 | op = proc_unit.addOperation(name='DPTemperaturesEstimation', optype='other') | |
2599 | op.addParameter(name='IBITS', value='16', format='int') |
|
2599 | op.addParameter(name='IBITS', value='16', format='int') | |
2600 |
|
2600 | |||
2601 | """ |
|
2601 | """ | |
2602 |
|
2602 | |||
2603 | def __init__(self, **kwargs): |
|
2603 | def __init__(self, **kwargs): | |
2604 |
|
2604 | |||
2605 | Operation.__init__(self, **kwargs) |
|
2605 | Operation.__init__(self, **kwargs) | |
2606 |
|
2606 | |||
2607 | self.aux=1 |
|
2607 | self.aux=1 | |
2608 |
|
2608 | |||
2609 | def Estimation(self,dataOut): |
|
2609 | def Estimation(self,dataOut): | |
2610 | #with suppress_stdout_stderr(): |
|
2610 | #with suppress_stdout_stderr(): | |
2611 |
|
2611 | |||
2612 | if self.aux==1: |
|
2612 | if self.aux==1: | |
2613 | dataOut.ifit=numpy.zeros(5,order='F',dtype='int32') |
|
2613 | dataOut.ifit=numpy.zeros(5,order='F',dtype='int32') | |
2614 | dataOut.m=numpy.zeros(1,order='F',dtype='int32') |
|
2614 | dataOut.m=numpy.zeros(1,order='F',dtype='int32') | |
2615 | dataOut.te2=numpy.zeros(dataOut.NSHTS,order='F',dtype='float32') |
|
2615 | dataOut.te2=numpy.zeros(dataOut.NSHTS,order='F',dtype='float32') | |
2616 | dataOut.ti2=numpy.zeros(dataOut.NSHTS,order='F',dtype='float32') |
|
2616 | dataOut.ti2=numpy.zeros(dataOut.NSHTS,order='F',dtype='float32') | |
2617 | dataOut.ete2=numpy.zeros(dataOut.NSHTS,order='F',dtype='float32') |
|
2617 | dataOut.ete2=numpy.zeros(dataOut.NSHTS,order='F',dtype='float32') | |
2618 | dataOut.eti2=numpy.zeros(dataOut.NSHTS,order='F',dtype='float32') |
|
2618 | dataOut.eti2=numpy.zeros(dataOut.NSHTS,order='F',dtype='float32') | |
2619 |
|
2619 | |||
2620 | self.aux=0 |
|
2620 | self.aux=0 | |
2621 |
|
2621 | |||
2622 | dataOut.phy2=numpy.zeros(dataOut.NSHTS,order='F',dtype='float32') |
|
2622 | dataOut.phy2=numpy.zeros(dataOut.NSHTS,order='F',dtype='float32') | |
2623 | dataOut.ephy2=numpy.zeros(dataOut.NSHTS,order='F',dtype='float32') |
|
2623 | dataOut.ephy2=numpy.zeros(dataOut.NSHTS,order='F',dtype='float32') | |
2624 | dataOut.info2=numpy.zeros(dataOut.NDP,order='F',dtype='float32') |
|
2624 | dataOut.info2=numpy.zeros(dataOut.NDP,order='F',dtype='float32') | |
2625 | dataOut.params=numpy.zeros(10,order='F',dtype='float32') |
|
2625 | dataOut.params=numpy.zeros(10,order='F',dtype='float32') | |
2626 | dataOut.cov=numpy.zeros(dataOut.IBITS*dataOut.IBITS,order='F',dtype='float32') |
|
2626 | dataOut.cov=numpy.zeros(dataOut.IBITS*dataOut.IBITS,order='F',dtype='float32') | |
2627 | dataOut.covinv=numpy.zeros(dataOut.IBITS*dataOut.IBITS,order='F',dtype='float32') |
|
2627 | dataOut.covinv=numpy.zeros(dataOut.IBITS*dataOut.IBITS,order='F',dtype='float32') | |
2628 |
|
2628 | |||
2629 | #null_fd = os.open(os.devnull, os.O_RDWR) |
|
2629 | #null_fd = os.open(os.devnull, os.O_RDWR) | |
2630 | #os.dup2(null_fd, 1) |
|
2630 | #os.dup2(null_fd, 1) | |
2631 |
|
2631 | |||
2632 | for i in range(10,dataOut.NSHTS): #no point below 150 km |
|
2632 | for i in range(10,dataOut.NSHTS): #no point below 150 km | |
2633 |
|
2633 | |||
2634 | #some definitions |
|
2634 | #some definitions | |
2635 | iflag=0 # inicializado a cero? |
|
2635 | iflag=0 # inicializado a cero? | |
2636 | wl = 3.0 |
|
2636 | wl = 3.0 | |
2637 | x=numpy.zeros(dataOut.DPL+dataOut.IBITS,order='F',dtype='float32') |
|
2637 | x=numpy.zeros(dataOut.DPL+dataOut.IBITS,order='F',dtype='float32') | |
2638 | y=numpy.zeros(dataOut.DPL+dataOut.IBITS,order='F',dtype='float32') |
|
2638 | y=numpy.zeros(dataOut.DPL+dataOut.IBITS,order='F',dtype='float32') | |
2639 | e=numpy.zeros(dataOut.DPL+dataOut.IBITS,order='F',dtype='float32') |
|
2639 | e=numpy.zeros(dataOut.DPL+dataOut.IBITS,order='F',dtype='float32') | |
2640 | eb=numpy.zeros(5,order='F',dtype='float32') |
|
2640 | eb=numpy.zeros(5,order='F',dtype='float32') | |
2641 | zero=numpy.zeros(1,order='F',dtype='float32') |
|
2641 | zero=numpy.zeros(1,order='F',dtype='float32') | |
2642 | depth=numpy.zeros(1,order='F',dtype='float32') |
|
2642 | depth=numpy.zeros(1,order='F',dtype='float32') | |
2643 | t1=numpy.zeros(1,order='F',dtype='float32') |
|
2643 | t1=numpy.zeros(1,order='F',dtype='float32') | |
2644 | t2=numpy.zeros(1,order='F',dtype='float32') |
|
2644 | t2=numpy.zeros(1,order='F',dtype='float32') | |
2645 |
|
2645 | |||
2646 | if i>10 and l1>=0: |
|
2646 | if i>10 and l1>=0: | |
2647 | if l1==0: |
|
2647 | if l1==0: | |
2648 | l1=1 |
|
2648 | l1=1 | |
2649 |
|
2649 | |||
2650 | dataOut.cov=numpy.reshape(dataOut.cov,l1*l1) |
|
2650 | dataOut.cov=numpy.reshape(dataOut.cov,l1*l1) | |
2651 | dataOut.cov=numpy.resize(dataOut.cov,dataOut.DPL*dataOut.DPL) |
|
2651 | dataOut.cov=numpy.resize(dataOut.cov,dataOut.DPL*dataOut.DPL) | |
2652 | dataOut.covinv=numpy.reshape(dataOut.covinv,l1*l1) |
|
2652 | dataOut.covinv=numpy.reshape(dataOut.covinv,l1*l1) | |
2653 | dataOut.covinv=numpy.resize(dataOut.covinv,dataOut.DPL*dataOut.DPL) |
|
2653 | dataOut.covinv=numpy.resize(dataOut.covinv,dataOut.DPL*dataOut.DPL) | |
2654 |
|
2654 | |||
2655 | for l in range(dataOut.DPL*dataOut.DPL): |
|
2655 | for l in range(dataOut.DPL*dataOut.DPL): | |
2656 | dataOut.cov[l]=0.0 |
|
2656 | dataOut.cov[l]=0.0 | |
2657 | acfm= (dataOut.rhor[i][0])**2 + (dataOut.rhoi[i][0])**2 |
|
2657 | acfm= (dataOut.rhor[i][0])**2 + (dataOut.rhoi[i][0])**2 | |
2658 | if acfm> 0.0: |
|
2658 | if acfm> 0.0: | |
2659 | cc=dataOut.rhor[i][0]/acfm |
|
2659 | cc=dataOut.rhor[i][0]/acfm | |
2660 | ss=dataOut.rhoi[i][0]/acfm |
|
2660 | ss=dataOut.rhoi[i][0]/acfm | |
2661 | else: |
|
2661 | else: | |
2662 | cc=1. |
|
2662 | cc=1. | |
2663 | ss=0. |
|
2663 | ss=0. | |
2664 | # keep only uncontaminated data, don't pass zero lag to fitter |
|
2664 | # keep only uncontaminated data, don't pass zero lag to fitter | |
2665 | l1=0 |
|
2665 | l1=0 | |
2666 | for l in range(0+1,dataOut.DPL): |
|
2666 | for l in range(0+1,dataOut.DPL): | |
2667 | if dataOut.igcej[i][l]==0 and dataOut.ibad[i][l]==0: |
|
2667 | if dataOut.igcej[i][l]==0 and dataOut.ibad[i][l]==0: | |
2668 | y[l1]=dataOut.rhor[i][l]*cc + dataOut.rhoi[i][l]*ss |
|
2668 | y[l1]=dataOut.rhor[i][l]*cc + dataOut.rhoi[i][l]*ss | |
2669 | x[l1]=dataOut.alag[l]*1.0e-3 |
|
2669 | x[l1]=dataOut.alag[l]*1.0e-3 | |
2670 | dataOut.sd[i][l]=dataOut.sd[i][l]/((acfm)**2)# important |
|
2670 | dataOut.sd[i][l]=dataOut.sd[i][l]/((acfm)**2)# important | |
2671 | e[l1]=dataOut.sd[i][l] #this is the variance, not the st. dev. |
|
2671 | e[l1]=dataOut.sd[i][l] #this is the variance, not the st. dev. | |
2672 | l1=l1+1 |
|
2672 | l1=l1+1 | |
2673 |
|
2673 | |||
2674 | for l in range(l1*(l1+1)): |
|
2674 | for l in range(l1*(l1+1)): | |
2675 | dataOut.cov[l]=0.0 |
|
2675 | dataOut.cov[l]=0.0 | |
2676 | for l in range(l1): |
|
2676 | for l in range(l1): | |
2677 | dataOut.cov[l*(1+l1)]=e[l] |
|
2677 | dataOut.cov[l*(1+l1)]=e[l] | |
2678 | angle=dataOut.thb[i]*0.01745 |
|
2678 | angle=dataOut.thb[i]*0.01745 | |
2679 | bm=dataOut.bfm[i] |
|
2679 | bm=dataOut.bfm[i] | |
2680 | dataOut.params[0]=1.0 #norm |
|
2680 | dataOut.params[0]=1.0 #norm | |
2681 | dataOut.params[1]=1000.0 #te |
|
2681 | dataOut.params[1]=1000.0 #te | |
2682 | dataOut.params[2]=800.0 #ti |
|
2682 | dataOut.params[2]=800.0 #ti | |
2683 | dataOut.params[3]=0.00 #ph |
|
2683 | dataOut.params[3]=0.00 #ph | |
2684 | dataOut.params[4]=0.00 #phe |
|
2684 | dataOut.params[4]=0.00 #phe | |
2685 |
|
2685 | |||
2686 | if l1!=0: |
|
2686 | if l1!=0: | |
2687 | x=numpy.resize(x,l1) |
|
2687 | x=numpy.resize(x,l1) | |
2688 | y=numpy.resize(y,l1) |
|
2688 | y=numpy.resize(y,l1) | |
2689 | else: |
|
2689 | else: | |
2690 | x=numpy.resize(x,1) |
|
2690 | x=numpy.resize(x,1) | |
2691 | y=numpy.resize(y,1) |
|
2691 | y=numpy.resize(y,1) | |
2692 |
|
2692 | |||
2693 | if True: #len(y)!=0: |
|
2693 | if True: #len(y)!=0: | |
2694 | with suppress_stdout_stderr(): |
|
2694 | with suppress_stdout_stderr(): | |
2695 | fitacf_guess.guess(y,x,zero,depth,t1,t2,len(y)) |
|
2695 | fitacf_guess.guess(y,x,zero,depth,t1,t2,len(y)) | |
2696 | t2=t1/t2 |
|
2696 | t2=t1/t2 | |
2697 |
|
2697 | |||
2698 | if (t1<5000.0 and t1> 600.0): |
|
2698 | if (t1<5000.0 and t1> 600.0): | |
2699 | dataOut.params[1]=t1 |
|
2699 | dataOut.params[1]=t1 | |
2700 | dataOut.params[2]=min(t2,t1) |
|
2700 | dataOut.params[2]=min(t2,t1) | |
2701 | dataOut.ifit[1]=dataOut.ifit[2]=1 |
|
2701 | dataOut.ifit[1]=dataOut.ifit[2]=1 | |
2702 | dataOut.ifit[0]=dataOut.ifit[3]=dataOut.ifit[4]=0 |
|
2702 | dataOut.ifit[0]=dataOut.ifit[3]=dataOut.ifit[4]=0 | |
2703 |
|
2703 | |||
2704 | if dataOut.ut_Faraday<10.0 and dataOut.ut_Faraday>=0.5: |
|
2704 | if dataOut.ut_Faraday<10.0 and dataOut.ut_Faraday>=0.5: | |
2705 | dataOut.ifit[2]=0 |
|
2705 | dataOut.ifit[2]=0 | |
2706 |
|
2706 | |||
2707 | den=dataOut.ph2[i] |
|
2707 | den=dataOut.ph2[i] | |
2708 |
|
2708 | |||
2709 | if l1!=0: |
|
2709 | if l1!=0: | |
2710 | dataOut.covinv=dataOut.covinv[0:l1*l1].reshape((l1,l1)) |
|
2710 | dataOut.covinv=dataOut.covinv[0:l1*l1].reshape((l1,l1)) | |
2711 | dataOut.cov=dataOut.cov[0:l1*l1].reshape((l1,l1)) |
|
2711 | dataOut.cov=dataOut.cov[0:l1*l1].reshape((l1,l1)) | |
2712 | e=numpy.resize(e,l1) |
|
2712 | e=numpy.resize(e,l1) | |
2713 | else: |
|
2713 | else: | |
2714 | dataOut.covinv=numpy.resize(dataOut.covinv,1) |
|
2714 | dataOut.covinv=numpy.resize(dataOut.covinv,1) | |
2715 | dataOut.cov=numpy.resize(dataOut.cov,1) |
|
2715 | dataOut.cov=numpy.resize(dataOut.cov,1) | |
2716 | e=numpy.resize(e,1) |
|
2716 | e=numpy.resize(e,1) | |
2717 |
|
2717 | |||
2718 | eb=numpy.resize(eb,10) |
|
2718 | eb=numpy.resize(eb,10) | |
2719 | dataOut.ifit=numpy.resize(dataOut.ifit,10) |
|
2719 | dataOut.ifit=numpy.resize(dataOut.ifit,10) | |
|
2720 | with suppress_stdout_stderr(): | |||
2720 | dataOut.covinv,e,dataOut.params,eb,dataOut.m=fitacf_fit_short.fit(wl,x,y,dataOut.cov,dataOut.covinv,e,dataOut.params,bm,angle,den,dataOut.range1[i],dataOut.year,dataOut.ifit,dataOut.m,l1) # |
|
2721 | dataOut.covinv,e,dataOut.params,eb,dataOut.m=fitacf_fit_short.fit(wl,x,y,dataOut.cov,dataOut.covinv,e,dataOut.params,bm,angle,den,dataOut.range1[i],dataOut.year,dataOut.ifit,dataOut.m,l1) # | |
2721 | if dataOut.params[2]>dataOut.params[1]*1.05: |
|
2722 | if dataOut.params[2]>dataOut.params[1]*1.05: | |
2722 | dataOut.ifit[2]=0 |
|
2723 | dataOut.ifit[2]=0 | |
2723 | dataOut.params[1]=dataOut.params[2]=t1 |
|
2724 | dataOut.params[1]=dataOut.params[2]=t1 | |
2724 | dataOut.covinv,e,dataOut.params,eb,dataOut.m=fitacf_fit_short.fit(wl,x,y,dataOut.cov,dataOut.covinv,e,dataOut.params,bm,angle,den,dataOut.range1[i],dataOut.year,dataOut.ifit,dataOut.m,l1) # |
|
2725 | dataOut.covinv,e,dataOut.params,eb,dataOut.m=fitacf_fit_short.fit(wl,x,y,dataOut.cov,dataOut.covinv,e,dataOut.params,bm,angle,den,dataOut.range1[i],dataOut.year,dataOut.ifit,dataOut.m,l1) # | |
2725 | if (dataOut.ifit[2]==0): |
|
2726 | if (dataOut.ifit[2]==0): | |
2726 | dataOut.params[2]=dataOut.params[1] |
|
2727 | dataOut.params[2]=dataOut.params[1] | |
|
2728 | with suppress_stdout_stderr(): | |||
|
2729 | dataOut.covinv,e,dataOut.params,eb,dataOut.m=fitacf_fit_short.fit(wl,x,y,dataOut.cov,dataOut.covinv,e,dataOut.params,bm,angle,den,dataOut.range1[i],dataOut.year,dataOut.ifit,dataOut.m,l1) # | |||
|
2730 | if (dataOut.ifit[2]==0): | |||
|
2731 | dataOut.params[2]=dataOut.params[1] | |||
2727 | if (dataOut.ifit[3]==0 and iflag==0): |
|
2732 | if (dataOut.ifit[3]==0 and iflag==0): | |
2728 | dataOut.params[3]=0.0 |
|
2733 | dataOut.params[3]=0.0 | |
2729 | if (dataOut.ifit[4]==0): |
|
2734 | if (dataOut.ifit[4]==0): | |
2730 | dataOut.params[4]=0.0 |
|
2735 | dataOut.params[4]=0.0 | |
2731 | dataOut.te2[i]=dataOut.params[1] |
|
2736 | dataOut.te2[i]=dataOut.params[1] | |
2732 | dataOut.ti2[i]=dataOut.params[2] |
|
2737 | dataOut.ti2[i]=dataOut.params[2] | |
2733 | dataOut.ete2[i]=eb[1] |
|
2738 | dataOut.ete2[i]=eb[1] | |
2734 | dataOut.eti2[i]=eb[2] |
|
2739 | dataOut.eti2[i]=eb[2] | |
2735 |
|
2740 | |||
2736 | if dataOut.eti2[i]==0: |
|
2741 | if dataOut.eti2[i]==0: | |
2737 | dataOut.eti2[i]=dataOut.ete2[i] |
|
2742 | dataOut.eti2[i]=dataOut.ete2[i] | |
2738 |
|
2743 | |||
2739 | dataOut.phy2[i]=dataOut.params[3] |
|
2744 | dataOut.phy2[i]=dataOut.params[3] | |
2740 | dataOut.ephy2[i]=eb[3] |
|
2745 | dataOut.ephy2[i]=eb[3] | |
2741 | if(iflag==1): |
|
2746 | if(iflag==1): | |
2742 | dataOut.ephy2[i]=0.0 |
|
2747 | dataOut.ephy2[i]=0.0 | |
2743 |
|
2748 | |||
2744 | if (dataOut.m<=3 and dataOut.m!= 0 and dataOut.te2[i]>400.0): |
|
2749 | if (dataOut.m<=3 and dataOut.m!= 0 and dataOut.te2[i]>400.0): | |
2745 | dataOut.info2[i]=1 |
|
2750 | dataOut.info2[i]=1 | |
2746 | else: |
|
2751 | else: | |
2747 | dataOut.info2[i]=0 |
|
2752 | dataOut.info2[i]=0 | |
2748 |
|
2753 | |||
2749 | def run(self,dataOut,IBITS=16): |
|
2754 | def run(self,dataOut,IBITS=16): | |
2750 |
|
2755 | |||
2751 | dataOut.IBITS = IBITS |
|
2756 | dataOut.IBITS = IBITS | |
2752 | self.Estimation(dataOut) |
|
2757 | self.Estimation(dataOut) | |
2753 |
|
2758 | |||
2754 | return dataOut |
|
2759 | return dataOut | |
2755 |
|
2760 | |||
2756 |
|
2761 | |||
2757 | class DenCorrection(NormalizeDPPowerRoberto_V2): |
|
2762 | class DenCorrection(NormalizeDPPowerRoberto_V2): | |
2758 | ''' |
|
2763 | ''' | |
2759 | Written by R. Flores |
|
2764 | Written by R. Flores | |
2760 | ''' |
|
2765 | ''' | |
2761 | def __init__(self, **kwargs): |
|
2766 | def __init__(self, **kwargs): | |
2762 |
|
2767 | |||
2763 | Operation.__init__(self, **kwargs) |
|
2768 | Operation.__init__(self, **kwargs) | |
2764 | self.aux = 0 |
|
2769 | self.aux = 0 | |
2765 | self.csv_flag = 1 |
|
2770 | self.csv_flag = 1 | |
2766 |
|
2771 | |||
2767 | def gaussian(self, x, a, b, c): |
|
2772 | def gaussian(self, x, a, b, c): | |
2768 | val = a * numpy.exp(-(x - b)**2 / (2*c**2)) |
|
2773 | val = a * numpy.exp(-(x - b)**2 / (2*c**2)) | |
2769 | return val |
|
2774 | return val | |
2770 |
|
2775 | |||
2771 | def TeTiEstimation(self,dataOut): |
|
2776 | def TeTiEstimation(self,dataOut): | |
2772 |
|
2777 | |||
2773 | #dataOut.DPL = 2 #for MST |
|
2778 | #dataOut.DPL = 2 #for MST | |
2774 | y=numpy.zeros(dataOut.DPL,order='F',dtype='float32') |
|
2779 | y=numpy.zeros(dataOut.DPL,order='F',dtype='float32') | |
2775 |
|
2780 | |||
2776 | for i in range(dataOut.NSHTS): |
|
2781 | for i in range(dataOut.NSHTS): | |
2777 | y[0]=y[1]=dataOut.range1[i] |
|
2782 | y[0]=y[1]=dataOut.range1[i] | |
2778 |
|
2783 | |||
2779 | y = y.astype(dtype='float64',order='F') |
|
2784 | y = y.astype(dtype='float64',order='F') | |
2780 | three=int(3) |
|
2785 | three=int(3) | |
2781 | wl = 3.0 |
|
2786 | wl = 3.0 | |
2782 | tion=numpy.zeros(three,order='F',dtype='float32') |
|
2787 | tion=numpy.zeros(three,order='F',dtype='float32') | |
2783 | fion=numpy.zeros(three,order='F',dtype='float32') |
|
2788 | fion=numpy.zeros(three,order='F',dtype='float32') | |
2784 | nui=numpy.zeros(three,order='F',dtype='float32') |
|
2789 | nui=numpy.zeros(three,order='F',dtype='float32') | |
2785 | wion=numpy.zeros(three,order='F',dtype='int32') |
|
2790 | wion=numpy.zeros(three,order='F',dtype='int32') | |
2786 | bline=0.0 |
|
2791 | bline=0.0 | |
2787 | #bline=numpy.zeros(1,order='F',dtype='float32') |
|
2792 | #bline=numpy.zeros(1,order='F',dtype='float32') | |
2788 | my_aux = numpy.ones(dataOut.NSHTS,order='F',dtype='float32') |
|
2793 | my_aux = numpy.ones(dataOut.NSHTS,order='F',dtype='float32') | |
2789 | acf_Temps = numpy.ones(dataOut.NSHTS,order='F',dtype='float32')*numpy.nan |
|
2794 | acf_Temps = numpy.ones(dataOut.NSHTS,order='F',dtype='float32')*numpy.nan | |
2790 | acf_no_Temps = numpy.ones(dataOut.NSHTS,order='F',dtype='float32')*numpy.nan |
|
2795 | acf_no_Temps = numpy.ones(dataOut.NSHTS,order='F',dtype='float32')*numpy.nan | |
2791 |
|
2796 | |||
2792 | from scipy import signal |
|
2797 | from scipy import signal | |
2793 |
|
2798 | |||
2794 | def func(params): |
|
2799 | def func(params): | |
2795 | return (ratio2-self.gaussian(dataOut.heightList[:dataOut.NSHTS],params[0],params[1],params[2])) |
|
2800 | return (ratio2-self.gaussian(dataOut.heightList[:dataOut.NSHTS],params[0],params[1],params[2])) | |
2796 |
|
2801 | |||
2797 | dataOut.info2[0] = 1 |
|
2802 | dataOut.info2[0] = 1 | |
2798 | for i in range(dataOut.NSHTS): |
|
2803 | for i in range(dataOut.NSHTS): | |
2799 | if dataOut.info2[i]==1: |
|
2804 | if dataOut.info2[i]==1: | |
2800 | angle=dataOut.thb[i]*0.01745 |
|
2805 | angle=dataOut.thb[i]*0.01745 | |
2801 | nue=nui[0]=nui[1]=nui[2]=0.0#nui[3]=0.0 |
|
2806 | nue=nui[0]=nui[1]=nui[2]=0.0#nui[3]=0.0 | |
2802 | wion[0]=16 #O |
|
2807 | wion[0]=16 #O | |
2803 | wion[1]=1 #H |
|
2808 | wion[1]=1 #H | |
2804 | wion[2]=4 #He |
|
2809 | wion[2]=4 #He | |
2805 | tion[0]=tion[1]=tion[2]=dataOut.ti2[i] |
|
2810 | tion[0]=tion[1]=tion[2]=dataOut.ti2[i] | |
2806 | #tion[0]=tion[1]=tion[2]=ti2_smooth[i] |
|
2811 | #tion[0]=tion[1]=tion[2]=ti2_smooth[i] | |
2807 | fion[0]=1.0-dataOut.phy2[i] #1 |
|
2812 | fion[0]=1.0-dataOut.phy2[i] #1 | |
2808 | fion[1]=dataOut.phy2[i] #0 |
|
2813 | fion[1]=dataOut.phy2[i] #0 | |
2809 | fion[2]=0.0 #0 |
|
2814 | fion[2]=0.0 #0 | |
2810 | for j in range(dataOut.DPL): |
|
2815 | for j in range(dataOut.DPL): | |
2811 | tau=dataOut.alag[j]*1.0e-3 |
|
2816 | tau=dataOut.alag[j]*1.0e-3 | |
2812 | with suppress_stdout_stderr():#The smoothness in range of "y" depends on the smoothness of the input parameters |
|
2817 | with suppress_stdout_stderr():#The smoothness in range of "y" depends on the smoothness of the input parameters | |
2813 | y[j]=fitacf_acf2.acf2(wl,tau,dataOut.te2[i],tion,fion,nue,nui,wion,angle,dataOut.ph2[i],dataOut.bfm[i],y[j],three) |
|
2818 | y[j]=fitacf_acf2.acf2(wl,tau,dataOut.te2[i],tion,fion,nue,nui,wion,angle,dataOut.ph2[i],dataOut.bfm[i],y[j],three) | |
2814 |
|
2819 | |||
2815 | if dataOut.ut_Faraday>11.0 and dataOut.range1[i]>150.0 and dataOut.range1[i]<300.0: |
|
2820 | if dataOut.ut_Faraday>11.0 and dataOut.range1[i]>150.0 and dataOut.range1[i]<300.0: | |
2816 | tau=0.0 |
|
2821 | tau=0.0 | |
2817 | with suppress_stdout_stderr(): |
|
2822 | with suppress_stdout_stderr(): | |
2818 | bline=fitacf_acf2.acf2(wl,tau,tion,tion,fion,nue,nui,wion,angle,dataOut.ph2[i],dataOut.bfm[i],bline,three) |
|
2823 | bline=fitacf_acf2.acf2(wl,tau,tion,tion,fion,nue,nui,wion,angle,dataOut.ph2[i],dataOut.bfm[i],bline,three) | |
2819 |
|
2824 | |||
2820 | cf=min(1.2,max(1.0,bline/y[0])) #FACTOR DE EFICIENCIA |
|
2825 | cf=min(1.2,max(1.0,bline/y[0])) #FACTOR DE EFICIENCIA | |
2821 | my_aux[i] = cf |
|
2826 | my_aux[i] = cf | |
2822 | acf_Temps[i] = y[0] |
|
2827 | acf_Temps[i] = y[0] | |
2823 | acf_no_Temps[i] = bline |
|
2828 | acf_no_Temps[i] = bline | |
2824 | for j in range(1,dataOut.DPL): |
|
2829 | for j in range(1,dataOut.DPL): | |
2825 | y[j]=min(max((y[j]/y[0]),-1.0),1.0)*dataOut.DH+dataOut.range1[i] |
|
2830 | y[j]=min(max((y[j]/y[0]),-1.0),1.0)*dataOut.DH+dataOut.range1[i] | |
2826 | y[0]=dataOut.range1[i]+dataOut.DH |
|
2831 | y[0]=dataOut.range1[i]+dataOut.DH | |
2827 |
|
2832 | |||
2828 |
|
2833 | |||
2829 | ratio = my_aux-1 |
|
2834 | ratio = my_aux-1 | |
2830 | def lsq_func(params): |
|
2835 | def lsq_func(params): | |
2831 | return (ratio-self.gaussian(dataOut.heightList[:dataOut.NSHTS],params[0],params[1],params[2])) |
|
2836 | return (ratio-self.gaussian(dataOut.heightList[:dataOut.NSHTS],params[0],params[1],params[2])) | |
2832 |
|
2837 | |||
2833 | x0_value = numpy.array([max(ratio),250,20]) |
|
2838 | x0_value = numpy.array([max(ratio),250,20]) | |
2834 |
|
2839 | |||
2835 | popt = least_squares(lsq_func,x0=x0_value,verbose=0) |
|
2840 | popt = least_squares(lsq_func,x0=x0_value,verbose=0) | |
2836 |
|
2841 | |||
2837 | A = popt.x[0]; B = popt.x[1]; C = popt.x[2] |
|
2842 | A = popt.x[0]; B = popt.x[1]; C = popt.x[2] | |
2838 |
|
2843 | |||
2839 | aux = self.gaussian(dataOut.heightList[:dataOut.NSHTS], A, B, C) + 1 #ratio + 1 |
|
2844 | aux = self.gaussian(dataOut.heightList[:dataOut.NSHTS], A, B, C) + 1 #ratio + 1 | |
2840 |
|
2845 | |||
2841 | dataOut.ph2[:dataOut.NSHTS]*=aux |
|
2846 | dataOut.ph2[:dataOut.NSHTS]*=aux | |
2842 | dataOut.sdp2[:dataOut.NSHTS]*=aux |
|
2847 | dataOut.sdp2[:dataOut.NSHTS]*=aux | |
2843 |
|
2848 | |||
2844 | def run(self,dataOut,savecf=0): |
|
2849 | def run(self,dataOut,savecf=0): | |
2845 | if gmtime(dataOut.utctime).tm_hour < 24. and gmtime(dataOut.utctime).tm_hour >= 11.: |
|
2850 | if gmtime(dataOut.utctime).tm_hour < 24. and gmtime(dataOut.utctime).tm_hour >= 11.: | |
2846 | if hasattr(dataOut, 'flagSpreadF') and dataOut.flagSpreadF: |
|
2851 | if hasattr(dataOut, 'flagSpreadF') and dataOut.flagSpreadF: | |
2847 | pass |
|
2852 | pass | |
2848 | else: |
|
2853 | else: | |
2849 | self.TeTiEstimation(dataOut) |
|
2854 | self.TeTiEstimation(dataOut) | |
2850 | dataOut.flagTeTiCorrection = True |
|
2855 | dataOut.flagTeTiCorrection = True | |
2851 | self.normalize(dataOut) |
|
2856 | self.normalize(dataOut) | |
2852 |
|
2857 | |||
2853 | return dataOut |
|
2858 | return dataOut | |
2854 |
|
2859 | |||
2855 |
|
2860 | |||
2856 |
|
2861 | |||
2857 | class DataSaveCleaner(Operation): |
|
2862 | class DataSaveCleaner(Operation): | |
2858 | ''' |
|
2863 | ''' | |
2859 | Written by R. Flores |
|
2864 | Written by R. Flores | |
2860 | ''' |
|
2865 | ''' | |
2861 | def __init__(self, **kwargs): |
|
2866 | def __init__(self, **kwargs): | |
2862 |
|
2867 | |||
2863 | Operation.__init__(self, **kwargs) |
|
2868 | Operation.__init__(self, **kwargs) | |
2864 | self.csv_flag = 1 |
|
2869 | self.csv_flag = 1 | |
2865 |
|
2870 | |||
2866 | def run(self,dataOut,savecfclean=0): |
|
2871 | def run(self,dataOut,savecfclean=0): | |
2867 | dataOut.DensityFinal=numpy.zeros((1,dataOut.NDP)) |
|
2872 | dataOut.DensityFinal=numpy.zeros((1,dataOut.NDP)) | |
2868 | dataOut.dphiFinal=numpy.zeros((1,dataOut.NDP)) |
|
2873 | dataOut.dphiFinal=numpy.zeros((1,dataOut.NDP)) | |
2869 | dataOut.EDensityFinal=numpy.zeros((1,dataOut.NDP)) |
|
2874 | dataOut.EDensityFinal=numpy.zeros((1,dataOut.NDP)) | |
2870 | dataOut.ElecTempFinal=numpy.zeros((1,dataOut.NDP)) |
|
2875 | dataOut.ElecTempFinal=numpy.zeros((1,dataOut.NDP)) | |
2871 | dataOut.EElecTempFinal=numpy.zeros((1,dataOut.NDP)) |
|
2876 | dataOut.EElecTempFinal=numpy.zeros((1,dataOut.NDP)) | |
2872 | dataOut.IonTempFinal=numpy.zeros((1,dataOut.NDP)) |
|
2877 | dataOut.IonTempFinal=numpy.zeros((1,dataOut.NDP)) | |
2873 | dataOut.EIonTempFinal=numpy.zeros((1,dataOut.NDP)) |
|
2878 | dataOut.EIonTempFinal=numpy.zeros((1,dataOut.NDP)) | |
2874 | dataOut.PhyFinal=numpy.zeros((1,dataOut.NDP)) |
|
2879 | dataOut.PhyFinal=numpy.zeros((1,dataOut.NDP)) | |
2875 | dataOut.EPhyFinal=numpy.zeros((1,dataOut.NDP)) |
|
2880 | dataOut.EPhyFinal=numpy.zeros((1,dataOut.NDP)) | |
2876 |
|
2881 | |||
2877 | dataOut.DensityFinal[0]=numpy.copy(dataOut.ph2) |
|
2882 | dataOut.DensityFinal[0]=numpy.copy(dataOut.ph2) | |
2878 | dataOut.dphiFinal[0]=numpy.copy(dataOut.dphi) |
|
2883 | dataOut.dphiFinal[0]=numpy.copy(dataOut.dphi) | |
2879 | dataOut.EDensityFinal[0]=numpy.copy(dataOut.sdp2) |
|
2884 | dataOut.EDensityFinal[0]=numpy.copy(dataOut.sdp2) | |
2880 | dataOut.ElecTempFinal[0,:dataOut.NSHTS]=numpy.copy(dataOut.te2) |
|
2885 | dataOut.ElecTempFinal[0,:dataOut.NSHTS]=numpy.copy(dataOut.te2) | |
2881 | dataOut.EElecTempFinal[0,:dataOut.NSHTS]=numpy.copy(dataOut.ete2) |
|
2886 | dataOut.EElecTempFinal[0,:dataOut.NSHTS]=numpy.copy(dataOut.ete2) | |
2882 | dataOut.IonTempFinal[0,:dataOut.NSHTS]=numpy.copy(dataOut.ti2) |
|
2887 | dataOut.IonTempFinal[0,:dataOut.NSHTS]=numpy.copy(dataOut.ti2) | |
2883 | dataOut.EIonTempFinal[0,:dataOut.NSHTS]=numpy.copy(dataOut.eti2) |
|
2888 | dataOut.EIonTempFinal[0,:dataOut.NSHTS]=numpy.copy(dataOut.eti2) | |
2884 | dataOut.PhyFinal[0,:dataOut.NSHTS]=numpy.copy(dataOut.phy2) |
|
2889 | dataOut.PhyFinal[0,:dataOut.NSHTS]=numpy.copy(dataOut.phy2) | |
2885 | dataOut.EPhyFinal[0,:dataOut.NSHTS]=numpy.copy(dataOut.ephy2) |
|
2890 | dataOut.EPhyFinal[0,:dataOut.NSHTS]=numpy.copy(dataOut.ephy2) | |
2886 |
|
2891 | |||
2887 | missing=numpy.nan |
|
2892 | missing=numpy.nan | |
2888 | temp_min=100.0 |
|
2893 | temp_min=100.0 | |
2889 | temp_max=3000.0#6000.0e |
|
2894 | temp_max=3000.0#6000.0e | |
2890 | den_err_percent = 100*dataOut.EDensityFinal[0]/dataOut.DensityFinal[0] |
|
2895 | den_err_percent = 100*dataOut.EDensityFinal[0]/dataOut.DensityFinal[0] | |
2891 | max_den_err_per = 35#30 #Densidades con error mayor al 35% se setean en NaN |
|
2896 | max_den_err_per = 35#30 #Densidades con error mayor al 35% se setean en NaN | |
2892 | for i in range(dataOut.NSHTS): |
|
2897 | for i in range(dataOut.NSHTS): | |
2893 |
|
2898 | |||
2894 | if den_err_percent[i] >= max_den_err_per: |
|
2899 | if den_err_percent[i] >= max_den_err_per: | |
2895 | dataOut.DensityFinal[0,i]=dataOut.EDensityFinal[0,i]=missing |
|
2900 | dataOut.DensityFinal[0,i]=dataOut.EDensityFinal[0,i]=missing | |
2896 | if i > 40: #Alturas mayores que 600 |
|
2901 | if i > 40: #Alturas mayores que 600 | |
2897 | dataOut.DensityFinal[0,i:]=dataOut.EDensityFinal[0,i:]=missing |
|
2902 | dataOut.DensityFinal[0,i:]=dataOut.EDensityFinal[0,i:]=missing | |
2898 |
|
2903 | |||
2899 | if dataOut.info2[i]!=1: |
|
2904 | if dataOut.info2[i]!=1: | |
2900 | dataOut.ElecTempFinal[0,i]=dataOut.EElecTempFinal[0,i]=dataOut.IonTempFinal[0,i]=dataOut.EIonTempFinal[0,i]=missing |
|
2905 | dataOut.ElecTempFinal[0,i]=dataOut.EElecTempFinal[0,i]=dataOut.IonTempFinal[0,i]=dataOut.EIonTempFinal[0,i]=missing | |
2901 |
|
2906 | |||
2902 | if dataOut.ElecTempFinal[0,i]<=temp_min or dataOut.ElecTempFinal[0,i]>temp_max or dataOut.EElecTempFinal[0,i]>temp_max: |
|
2907 | if dataOut.ElecTempFinal[0,i]<=temp_min or dataOut.ElecTempFinal[0,i]>temp_max or dataOut.EElecTempFinal[0,i]>temp_max: | |
2903 |
|
2908 | |||
2904 | dataOut.ElecTempFinal[0,i]=dataOut.EElecTempFinal[0,i]=missing |
|
2909 | dataOut.ElecTempFinal[0,i]=dataOut.EElecTempFinal[0,i]=missing | |
2905 |
|
2910 | |||
2906 | if dataOut.IonTempFinal[0,i]<=temp_min or dataOut.IonTempFinal[0,i]>temp_max or dataOut.EIonTempFinal[0,i]>temp_max: |
|
2911 | if dataOut.IonTempFinal[0,i]<=temp_min or dataOut.IonTempFinal[0,i]>temp_max or dataOut.EIonTempFinal[0,i]>temp_max: | |
2907 | dataOut.IonTempFinal[0,i]=dataOut.EIonTempFinal[0,i]=missing |
|
2912 | dataOut.IonTempFinal[0,i]=dataOut.EIonTempFinal[0,i]=missing | |
2908 |
|
2913 | |||
2909 | if dataOut.lags_to_plot[i,:][~numpy.isnan(dataOut.lags_to_plot[i,:])].shape[0]<6: |
|
2914 | if dataOut.lags_to_plot[i,:][~numpy.isnan(dataOut.lags_to_plot[i,:])].shape[0]<6: | |
2910 | dataOut.ElecTempFinal[0,i]=dataOut.EElecTempFinal[0,i]=dataOut.IonTempFinal[0,i]=dataOut.EIonTempFinal[0,i]=missing |
|
2915 | dataOut.ElecTempFinal[0,i]=dataOut.EElecTempFinal[0,i]=dataOut.IonTempFinal[0,i]=dataOut.EIonTempFinal[0,i]=missing | |
2911 |
|
2916 | |||
2912 | if dataOut.ut_Faraday>4 and dataOut.ut_Faraday<11: |
|
2917 | if dataOut.ut_Faraday>4 and dataOut.ut_Faraday<11: | |
2913 | if numpy.nanmax(dataOut.acfs_error_to_plot[i,:])>=10: |
|
2918 | if numpy.nanmax(dataOut.acfs_error_to_plot[i,:])>=10: | |
2914 | dataOut.ElecTempFinal[0,i]=dataOut.EElecTempFinal[0,i]=dataOut.IonTempFinal[0,i]=dataOut.EIonTempFinal[0,i]=missing |
|
2919 | dataOut.ElecTempFinal[0,i]=dataOut.EElecTempFinal[0,i]=dataOut.IonTempFinal[0,i]=dataOut.EIonTempFinal[0,i]=missing | |
2915 |
|
2920 | |||
2916 | if dataOut.EPhyFinal[0,i]<0.0 or dataOut.EPhyFinal[0,i]>1.0: |
|
2921 | if dataOut.EPhyFinal[0,i]<0.0 or dataOut.EPhyFinal[0,i]>1.0: | |
2917 | dataOut.PhyFinal[0,i]=dataOut.EPhyFinal[0,i]=missing |
|
2922 | dataOut.PhyFinal[0,i]=dataOut.EPhyFinal[0,i]=missing | |
2918 |
|
2923 | |||
2919 | if dataOut.EDensityFinal[0,i]>0.0 and dataOut.DensityFinal[0,i]>0.0 and dataOut.DensityFinal[0,i]<9.9e6: |
|
2924 | if dataOut.EDensityFinal[0,i]>0.0 and dataOut.DensityFinal[0,i]>0.0 and dataOut.DensityFinal[0,i]<9.9e6: | |
2920 | dataOut.EDensityFinal[0,i]=max(dataOut.EDensityFinal[0,i],1000.0) |
|
2925 | dataOut.EDensityFinal[0,i]=max(dataOut.EDensityFinal[0,i],1000.0) | |
2921 | else: |
|
2926 | else: | |
2922 | dataOut.DensityFinal[0,i]=dataOut.EDensityFinal[0,i]=missing |
|
2927 | dataOut.DensityFinal[0,i]=dataOut.EDensityFinal[0,i]=missing | |
2923 |
|
2928 | |||
2924 | if dataOut.PhyFinal[0,i]==0 or dataOut.PhyFinal[0,i]>0.4: |
|
2929 | if dataOut.PhyFinal[0,i]==0 or dataOut.PhyFinal[0,i]>0.4: | |
2925 | dataOut.PhyFinal[0,i]=dataOut.EPhyFinal[0,i]=missing |
|
2930 | dataOut.PhyFinal[0,i]=dataOut.EPhyFinal[0,i]=missing | |
2926 | if dataOut.ElecTempFinal[0,i]==dataOut.IonTempFinal[0,i]: |
|
2931 | if dataOut.ElecTempFinal[0,i]==dataOut.IonTempFinal[0,i]: | |
2927 | dataOut.EElecTempFinal[0,i]=dataOut.EIonTempFinal[0,i] |
|
2932 | dataOut.EElecTempFinal[0,i]=dataOut.EIonTempFinal[0,i] | |
2928 | if numpy.isnan(dataOut.ElecTempFinal[0,i]): |
|
2933 | if numpy.isnan(dataOut.ElecTempFinal[0,i]): | |
2929 | dataOut.EElecTempFinal[0,i]=missing |
|
2934 | dataOut.EElecTempFinal[0,i]=missing | |
2930 | if numpy.isnan(dataOut.IonTempFinal[0,i]): |
|
2935 | if numpy.isnan(dataOut.IonTempFinal[0,i]): | |
2931 | dataOut.EIonTempFinal[0,i]=missing |
|
2936 | dataOut.EIonTempFinal[0,i]=missing | |
2932 | if numpy.isnan(dataOut.ElecTempFinal[0,i]) or numpy.isnan(dataOut.EElecTempFinal[0,i]): |
|
2937 | if numpy.isnan(dataOut.ElecTempFinal[0,i]) or numpy.isnan(dataOut.EElecTempFinal[0,i]): | |
2933 | dataOut.ElecTempFinal[0,i]=dataOut.EElecTempFinal[0,i]=dataOut.IonTempFinal[0,i]=dataOut.EIonTempFinal[0,i]=missing |
|
2938 | dataOut.ElecTempFinal[0,i]=dataOut.EElecTempFinal[0,i]=dataOut.IonTempFinal[0,i]=dataOut.EIonTempFinal[0,i]=missing | |
2934 |
|
2939 | |||
2935 | for i in range(12,dataOut.NSHTS-1): |
|
2940 | for i in range(12,dataOut.NSHTS-1): | |
2936 |
|
2941 | |||
2937 | if numpy.isnan(dataOut.ElecTempFinal[0,i-1]) and numpy.isnan(dataOut.ElecTempFinal[0,i+1]): |
|
2942 | if numpy.isnan(dataOut.ElecTempFinal[0,i-1]) and numpy.isnan(dataOut.ElecTempFinal[0,i+1]): | |
2938 | dataOut.ElecTempFinal[0,i]=dataOut.EElecTempFinal[0,i]=missing |
|
2943 | dataOut.ElecTempFinal[0,i]=dataOut.EElecTempFinal[0,i]=missing | |
2939 |
|
2944 | |||
2940 | if numpy.isnan(dataOut.IonTempFinal[0,i-1]) and numpy.isnan(dataOut.IonTempFinal[0,i+1]): |
|
2945 | if numpy.isnan(dataOut.IonTempFinal[0,i-1]) and numpy.isnan(dataOut.IonTempFinal[0,i+1]): | |
2941 | dataOut.IonTempFinal[0,i]=dataOut.EIonTempFinal[0,i]=missing |
|
2946 | dataOut.IonTempFinal[0,i]=dataOut.EIonTempFinal[0,i]=missing | |
2942 |
|
2947 | |||
2943 | if dataOut.ut_Faraday>4 and dataOut.ut_Faraday<11: |
|
2948 | if dataOut.ut_Faraday>4 and dataOut.ut_Faraday<11: | |
2944 |
|
2949 | |||
2945 | if numpy.isnan(dataOut.ElecTempFinal[0,i-1]) and numpy.isnan(dataOut.ElecTempFinal[0,i-2]) and numpy.isnan(dataOut.ElecTempFinal[0,i+2]) and numpy.isnan(dataOut.ElecTempFinal[0,i+3]): #and numpy.isnan(dataOut.ElecTempFinal[0,i-5]): |
|
2950 | if numpy.isnan(dataOut.ElecTempFinal[0,i-1]) and numpy.isnan(dataOut.ElecTempFinal[0,i-2]) and numpy.isnan(dataOut.ElecTempFinal[0,i+2]) and numpy.isnan(dataOut.ElecTempFinal[0,i+3]): #and numpy.isnan(dataOut.ElecTempFinal[0,i-5]): | |
2946 |
|
2951 | |||
2947 | dataOut.ElecTempFinal[0,i]=dataOut.EElecTempFinal[0,i]=missing |
|
2952 | dataOut.ElecTempFinal[0,i]=dataOut.EElecTempFinal[0,i]=missing | |
2948 | if numpy.isnan(dataOut.IonTempFinal[0,i-1]) and numpy.isnan(dataOut.IonTempFinal[0,i-2]) and numpy.isnan(dataOut.IonTempFinal[0,i+2]) and numpy.isnan(dataOut.IonTempFinal[0,i+3]): #and numpy.isnan(dataOut.IonTempFinal[0,i-5]): |
|
2953 | if numpy.isnan(dataOut.IonTempFinal[0,i-1]) and numpy.isnan(dataOut.IonTempFinal[0,i-2]) and numpy.isnan(dataOut.IonTempFinal[0,i+2]) and numpy.isnan(dataOut.IonTempFinal[0,i+3]): #and numpy.isnan(dataOut.IonTempFinal[0,i-5]): | |
2949 |
|
2954 | |||
2950 | dataOut.IonTempFinal[0,i]=dataOut.EIonTempFinal[0,i]=missing |
|
2955 | dataOut.IonTempFinal[0,i]=dataOut.EIonTempFinal[0,i]=missing | |
2951 |
|
2956 | |||
2952 | if i>25: |
|
2957 | if i>25: | |
2953 | if numpy.isnan(dataOut.ElecTempFinal[0,i-1]) and numpy.isnan(dataOut.ElecTempFinal[0,i-2]) and numpy.isnan(dataOut.ElecTempFinal[0,i-3]) and numpy.isnan(dataOut.ElecTempFinal[0,i-4]): #and numpy.isnan(dataOut.ElecTempFinal[0,i-5]): |
|
2958 | if numpy.isnan(dataOut.ElecTempFinal[0,i-1]) and numpy.isnan(dataOut.ElecTempFinal[0,i-2]) and numpy.isnan(dataOut.ElecTempFinal[0,i-3]) and numpy.isnan(dataOut.ElecTempFinal[0,i-4]): #and numpy.isnan(dataOut.ElecTempFinal[0,i-5]): | |
2954 | dataOut.ElecTempFinal[0,i]=dataOut.EElecTempFinal[0,i]=missing |
|
2959 | dataOut.ElecTempFinal[0,i]=dataOut.EElecTempFinal[0,i]=missing | |
2955 | if numpy.isnan(dataOut.IonTempFinal[0,i-1]) and numpy.isnan(dataOut.IonTempFinal[0,i-2]) and numpy.isnan(dataOut.IonTempFinal[0,i-3]) and numpy.isnan(dataOut.IonTempFinal[0,i-4]): #and numpy.isnan(dataOut.IonTempFinal[0,i-5]): |
|
2960 | if numpy.isnan(dataOut.IonTempFinal[0,i-1]) and numpy.isnan(dataOut.IonTempFinal[0,i-2]) and numpy.isnan(dataOut.IonTempFinal[0,i-3]) and numpy.isnan(dataOut.IonTempFinal[0,i-4]): #and numpy.isnan(dataOut.IonTempFinal[0,i-5]): | |
2956 |
|
2961 | |||
2957 | dataOut.IonTempFinal[0,i]=dataOut.EIonTempFinal[0,i]=missing |
|
2962 | dataOut.IonTempFinal[0,i]=dataOut.EIonTempFinal[0,i]=missing | |
2958 |
|
2963 | |||
2959 | if numpy.isnan(dataOut.ElecTempFinal[0,i]) or numpy.isnan(dataOut.EElecTempFinal[0,i]): |
|
2964 | if numpy.isnan(dataOut.ElecTempFinal[0,i]) or numpy.isnan(dataOut.EElecTempFinal[0,i]): | |
2960 |
|
2965 | |||
2961 | dataOut.ElecTempFinal[0,i]=dataOut.EElecTempFinal[0,i]=dataOut.IonTempFinal[0,i]=dataOut.EIonTempFinal[0,i]=missing |
|
2966 | dataOut.ElecTempFinal[0,i]=dataOut.EElecTempFinal[0,i]=dataOut.IonTempFinal[0,i]=dataOut.EIonTempFinal[0,i]=missing | |
2962 |
|
2967 | |||
2963 | for i in range(12,dataOut.NSHTS-1): |
|
2968 | for i in range(12,dataOut.NSHTS-1): | |
2964 |
|
2969 | |||
2965 | if numpy.isnan(dataOut.ElecTempFinal[0,i-1]) and numpy.isnan(dataOut.ElecTempFinal[0,i+1]): |
|
2970 | if numpy.isnan(dataOut.ElecTempFinal[0,i-1]) and numpy.isnan(dataOut.ElecTempFinal[0,i+1]): | |
2966 | dataOut.ElecTempFinal[0,i]=dataOut.EElecTempFinal[0,i]=missing |
|
2971 | dataOut.ElecTempFinal[0,i]=dataOut.EElecTempFinal[0,i]=missing | |
2967 |
|
2972 | |||
2968 | if numpy.isnan(dataOut.IonTempFinal[0,i-1]) and numpy.isnan(dataOut.IonTempFinal[0,i+1]): |
|
2973 | if numpy.isnan(dataOut.IonTempFinal[0,i-1]) and numpy.isnan(dataOut.IonTempFinal[0,i+1]): | |
2969 | dataOut.IonTempFinal[0,i]=dataOut.EIonTempFinal[0,i]=missing |
|
2974 | dataOut.IonTempFinal[0,i]=dataOut.EIonTempFinal[0,i]=missing | |
2970 |
|
2975 | |||
2971 | if numpy.isnan(dataOut.DensityFinal[0,i-1]) and numpy.isnan(dataOut.DensityFinal[0,i+1]): ##NEW |
|
2976 | if numpy.isnan(dataOut.DensityFinal[0,i-1]) and numpy.isnan(dataOut.DensityFinal[0,i+1]): ##NEW | |
2972 | dataOut.DensityFinal[0,i]=dataOut.EDensityFinal[0,i]=missing ##NEW |
|
2977 | dataOut.DensityFinal[0,i]=dataOut.EDensityFinal[0,i]=missing ##NEW | |
2973 |
|
2978 | |||
2974 | if numpy.isnan(dataOut.ElecTempFinal[0,i]) or numpy.isnan(dataOut.EElecTempFinal[0,i]): |
|
2979 | if numpy.isnan(dataOut.ElecTempFinal[0,i]) or numpy.isnan(dataOut.EElecTempFinal[0,i]): | |
2975 |
|
2980 | |||
2976 | dataOut.ElecTempFinal[0,i]=dataOut.EElecTempFinal[0,i]=dataOut.IonTempFinal[0,i]=dataOut.EIonTempFinal[0,i]=missing |
|
2981 | dataOut.ElecTempFinal[0,i]=dataOut.EElecTempFinal[0,i]=dataOut.IonTempFinal[0,i]=dataOut.EIonTempFinal[0,i]=missing | |
2977 |
|
2982 | |||
2978 | if numpy.count_nonzero(~numpy.isnan(dataOut.ElecTempFinal[0,12:50]))<5: |
|
2983 | if numpy.count_nonzero(~numpy.isnan(dataOut.ElecTempFinal[0,12:50]))<5: | |
2979 | dataOut.ElecTempFinal[0,:]=dataOut.EElecTempFinal[0,:]=missing |
|
2984 | dataOut.ElecTempFinal[0,:]=dataOut.EElecTempFinal[0,:]=missing | |
2980 | if numpy.count_nonzero(~numpy.isnan(dataOut.IonTempFinal[0,12:50]))<5: |
|
2985 | if numpy.count_nonzero(~numpy.isnan(dataOut.IonTempFinal[0,12:50]))<5: | |
2981 | dataOut.IonTempFinal[0,:]=dataOut.EIonTempFinal[0,:]=missing |
|
2986 | dataOut.IonTempFinal[0,:]=dataOut.EIonTempFinal[0,:]=missing | |
2982 |
|
2987 | |||
2983 |
|
2988 | |||
2984 | if numpy.count_nonzero(~numpy.isnan(dataOut.DensityFinal[0,12:50]))<=5: |
|
2989 | if numpy.count_nonzero(~numpy.isnan(dataOut.DensityFinal[0,12:50]))<=5: | |
2985 | dataOut.DensityFinal[0,:]=dataOut.EDensityFinal[0,:]=missing |
|
2990 | dataOut.DensityFinal[0,:]=dataOut.EDensityFinal[0,:]=missing | |
2986 |
|
2991 | |||
2987 | dataOut.DensityFinal[0,dataOut.NSHTS:]=missing |
|
2992 | dataOut.DensityFinal[0,dataOut.NSHTS:]=missing | |
2988 | dataOut.EDensityFinal[0,dataOut.NSHTS:]=missing |
|
2993 | dataOut.EDensityFinal[0,dataOut.NSHTS:]=missing | |
2989 | dataOut.ElecTempFinal[0,dataOut.NSHTS:]=missing |
|
2994 | dataOut.ElecTempFinal[0,dataOut.NSHTS:]=missing | |
2990 | dataOut.EElecTempFinal[0,dataOut.NSHTS:]=missing |
|
2995 | dataOut.EElecTempFinal[0,dataOut.NSHTS:]=missing | |
2991 | dataOut.IonTempFinal[0,dataOut.NSHTS:]=missing |
|
2996 | dataOut.IonTempFinal[0,dataOut.NSHTS:]=missing | |
2992 | dataOut.EIonTempFinal[0,dataOut.NSHTS:]=missing |
|
2997 | dataOut.EIonTempFinal[0,dataOut.NSHTS:]=missing | |
2993 | dataOut.PhyFinal[0,dataOut.NSHTS:]=missing |
|
2998 | dataOut.PhyFinal[0,dataOut.NSHTS:]=missing | |
2994 | dataOut.EPhyFinal[0,dataOut.NSHTS:]=missing |
|
2999 | dataOut.EPhyFinal[0,dataOut.NSHTS:]=missing | |
2995 |
|
3000 | |||
2996 | if gmtime(dataOut.utctime).tm_hour >= 13. and gmtime(dataOut.utctime).tm_hour < 21.: #07-16 LT |
|
3001 | if gmtime(dataOut.utctime).tm_hour >= 13. and gmtime(dataOut.utctime).tm_hour < 21.: #07-16 LT | |
2997 | dataOut.DensityFinal[0,:13]=missing |
|
3002 | dataOut.DensityFinal[0,:13]=missing | |
2998 | dataOut.EDensityFinal[0,:13]=missing |
|
3003 | dataOut.EDensityFinal[0,:13]=missing | |
2999 | dataOut.ElecTempFinal[0,:13]=missing |
|
3004 | dataOut.ElecTempFinal[0,:13]=missing | |
3000 | dataOut.EElecTempFinal[0,:13]=missing |
|
3005 | dataOut.EElecTempFinal[0,:13]=missing | |
3001 | dataOut.IonTempFinal[0,:13]=missing |
|
3006 | dataOut.IonTempFinal[0,:13]=missing | |
3002 | dataOut.EIonTempFinal[0,:13]=missing |
|
3007 | dataOut.EIonTempFinal[0,:13]=missing | |
3003 | dataOut.PhyFinal[0,:13]=missing |
|
3008 | dataOut.PhyFinal[0,:13]=missing | |
3004 | dataOut.EPhyFinal[0,:13]=missing |
|
3009 | dataOut.EPhyFinal[0,:13]=missing | |
3005 |
|
3010 | |||
3006 | else: |
|
3011 | else: | |
3007 | if gmtime(dataOut.utctime).tm_hour == 9 and gmtime(dataOut.utctime).tm_min == 20: |
|
3012 | if gmtime(dataOut.utctime).tm_hour == 9 and gmtime(dataOut.utctime).tm_min == 20: | |
3008 | pass |
|
3013 | pass | |
3009 | else: |
|
3014 | else: | |
3010 | dataOut.DensityFinal[0,:dataOut.min_id_eej+1]=missing |
|
3015 | dataOut.DensityFinal[0,:dataOut.min_id_eej+1]=missing | |
3011 | dataOut.EDensityFinal[0,:dataOut.min_id_eej+1]=missing |
|
3016 | dataOut.EDensityFinal[0,:dataOut.min_id_eej+1]=missing | |
3012 | dataOut.ElecTempFinal[0,:dataOut.min_id_eej+1]=missing |
|
3017 | dataOut.ElecTempFinal[0,:dataOut.min_id_eej+1]=missing | |
3013 | dataOut.EElecTempFinal[0,:dataOut.min_id_eej+1]=missing |
|
3018 | dataOut.EElecTempFinal[0,:dataOut.min_id_eej+1]=missing | |
3014 | dataOut.IonTempFinal[0,:dataOut.min_id_eej+1]=missing |
|
3019 | dataOut.IonTempFinal[0,:dataOut.min_id_eej+1]=missing | |
3015 | dataOut.EIonTempFinal[0,:dataOut.min_id_eej+1]=missing |
|
3020 | dataOut.EIonTempFinal[0,:dataOut.min_id_eej+1]=missing | |
3016 | dataOut.PhyFinal[0,:dataOut.min_id_eej+1]=missing |
|
3021 | dataOut.PhyFinal[0,:dataOut.min_id_eej+1]=missing | |
3017 | dataOut.EPhyFinal[0,:dataOut.min_id_eej+1]=missing |
|
3022 | dataOut.EPhyFinal[0,:dataOut.min_id_eej+1]=missing | |
3018 |
|
3023 | |||
3019 | dataOut.flagNoData = numpy.all(numpy.isnan(dataOut.DensityFinal)) #Si todos los valores son NaN no se prosigue |
|
3024 | dataOut.flagNoData = numpy.all(numpy.isnan(dataOut.DensityFinal)) #Si todos los valores son NaN no se prosigue | |
3020 |
|
3025 | |||
3021 | if not dataOut.flagNoData: |
|
3026 | if not dataOut.flagNoData: | |
3022 | if savecfclean: |
|
3027 | if savecfclean: | |
3023 | try: |
|
3028 | try: | |
3024 | import pandas as pd |
|
3029 | import pandas as pd | |
3025 | if self.csv_flag: |
|
3030 | if self.csv_flag: | |
3026 | if not os.path.exists("./cfclean"): |
|
3031 | if not os.path.exists("./cfclean"): | |
3027 | os.makedirs("./cfclean") |
|
3032 | os.makedirs("./cfclean") | |
3028 | self.doy_csv = datetime.datetime.fromtimestamp(dataOut.utctime).strftime('%j') |
|
3033 | self.doy_csv = datetime.datetime.fromtimestamp(dataOut.utctime).strftime('%j') | |
3029 | self.year_csv = datetime.datetime.fromtimestamp(dataOut.utctime).strftime('%Y') |
|
3034 | self.year_csv = datetime.datetime.fromtimestamp(dataOut.utctime).strftime('%Y') | |
3030 | file = open("./cfclean/cfclean{0}{1}.csv".format(self.year_csv,self.doy_csv), "x") |
|
3035 | file = open("./cfclean/cfclean{0}{1}.csv".format(self.year_csv,self.doy_csv), "x") | |
3031 | f = csv.writer(file) |
|
3036 | f = csv.writer(file) | |
3032 | f.writerow(numpy.array(["timestamp",'cf'])) |
|
3037 | f.writerow(numpy.array(["timestamp",'cf'])) | |
3033 | self.csv_flag = 0 |
|
3038 | self.csv_flag = 0 | |
3034 | print("Creating cf clean File") |
|
3039 | print("Creating cf clean File") | |
3035 | print("Writing cf clean File") |
|
3040 | print("Writing cf clean File") | |
3036 | except: |
|
3041 | except: | |
3037 | file = open("./cfclean/cfclean{0}{1}.csv".format(self.year_csv,self.doy_csv), "a") |
|
3042 | file = open("./cfclean/cfclean{0}{1}.csv".format(self.year_csv,self.doy_csv), "a") | |
3038 | f = csv.writer(file) |
|
3043 | f = csv.writer(file) | |
3039 | print("Writing cf clean File") |
|
3044 | print("Writing cf clean File") | |
3040 | cf = numpy.array([dataOut.utctime,dataOut.cf]) |
|
3045 | cf = numpy.array([dataOut.utctime,dataOut.cf]) | |
3041 | f.writerow(cf) |
|
3046 | f.writerow(cf) | |
3042 | file.close() |
|
3047 | file.close() | |
3043 |
|
3048 | |||
3044 | dataOut.flagNoData = False #Descomentar solo para ploteo #Comentar para MADWriter |
|
3049 | dataOut.flagNoData = False #Descomentar solo para ploteo #Comentar para MADWriter | |
3045 |
|
3050 | |||
3046 | dataOut.DensityFinal *= 1.e6 #Convert units to m^β»3 |
|
3051 | dataOut.DensityFinal *= 1.e6 #Convert units to m^β»3 | |
3047 | dataOut.EDensityFinal *= 1.e6 #Convert units to m^β»3 |
|
3052 | dataOut.EDensityFinal *= 1.e6 #Convert units to m^β»3 | |
3048 |
|
3053 | |||
3049 | return dataOut |
|
3054 | return dataOut | |
3050 |
|
3055 | |||
3051 |
|
3056 | |||
3052 | class DataSaveCleanerHP(Operation): |
|
3057 | class DataSaveCleanerHP(Operation): | |
3053 | ''' |
|
3058 | ''' | |
3054 | Written by R. Flores |
|
3059 | Written by R. Flores | |
3055 | ''' |
|
3060 | ''' | |
3056 | def __init__(self, **kwargs): |
|
3061 | def __init__(self, **kwargs): | |
3057 |
|
3062 | |||
3058 | Operation.__init__(self, **kwargs) |
|
3063 | Operation.__init__(self, **kwargs) | |
3059 |
|
3064 | |||
3060 | def run(self,dataOut): |
|
3065 | def run(self,dataOut): | |
3061 |
|
3066 | |||
3062 | dataOut.Density_DP=numpy.zeros(dataOut.cut) |
|
3067 | dataOut.Density_DP=numpy.zeros(dataOut.cut) | |
3063 | dataOut.EDensity_DP=numpy.zeros(dataOut.cut) |
|
3068 | dataOut.EDensity_DP=numpy.zeros(dataOut.cut) | |
3064 | dataOut.ElecTemp_DP=numpy.zeros(dataOut.cut) |
|
3069 | dataOut.ElecTemp_DP=numpy.zeros(dataOut.cut) | |
3065 | dataOut.EElecTemp_DP=numpy.zeros(dataOut.cut) |
|
3070 | dataOut.EElecTemp_DP=numpy.zeros(dataOut.cut) | |
3066 | dataOut.IonTemp_DP=numpy.zeros(dataOut.cut) |
|
3071 | dataOut.IonTemp_DP=numpy.zeros(dataOut.cut) | |
3067 | dataOut.EIonTemp_DP=numpy.zeros(dataOut.cut) |
|
3072 | dataOut.EIonTemp_DP=numpy.zeros(dataOut.cut) | |
3068 | dataOut.Phy_DP=numpy.zeros(dataOut.cut) |
|
3073 | dataOut.Phy_DP=numpy.zeros(dataOut.cut) | |
3069 | dataOut.EPhy_DP=numpy.zeros(dataOut.cut) |
|
3074 | dataOut.EPhy_DP=numpy.zeros(dataOut.cut) | |
3070 | dataOut.Phe_DP=numpy.empty(dataOut.cut) |
|
3075 | dataOut.Phe_DP=numpy.empty(dataOut.cut) | |
3071 | dataOut.EPhe_DP=numpy.empty(dataOut.cut) |
|
3076 | dataOut.EPhe_DP=numpy.empty(dataOut.cut) | |
3072 |
|
3077 | |||
3073 | dataOut.Density_DP[:]=numpy.copy(dataOut.ph2[:dataOut.cut]) |
|
3078 | dataOut.Density_DP[:]=numpy.copy(dataOut.ph2[:dataOut.cut]) | |
3074 | dataOut.EDensity_DP[:]=numpy.copy(dataOut.sdp2[:dataOut.cut]) |
|
3079 | dataOut.EDensity_DP[:]=numpy.copy(dataOut.sdp2[:dataOut.cut]) | |
3075 | dataOut.ElecTemp_DP[:]=numpy.copy(dataOut.te2[:dataOut.cut]) |
|
3080 | dataOut.ElecTemp_DP[:]=numpy.copy(dataOut.te2[:dataOut.cut]) | |
3076 | dataOut.EElecTemp_DP[:]=numpy.copy(dataOut.ete2[:dataOut.cut]) |
|
3081 | dataOut.EElecTemp_DP[:]=numpy.copy(dataOut.ete2[:dataOut.cut]) | |
3077 | dataOut.IonTemp_DP[:]=numpy.copy(dataOut.ti2[:dataOut.cut]) |
|
3082 | dataOut.IonTemp_DP[:]=numpy.copy(dataOut.ti2[:dataOut.cut]) | |
3078 | dataOut.EIonTemp_DP[:]=numpy.copy(dataOut.eti2[:dataOut.cut]) |
|
3083 | dataOut.EIonTemp_DP[:]=numpy.copy(dataOut.eti2[:dataOut.cut]) | |
3079 | dataOut.Phy_DP[:]=numpy.copy(dataOut.phy2[:dataOut.cut]) |
|
3084 | dataOut.Phy_DP[:]=numpy.copy(dataOut.phy2[:dataOut.cut]) | |
3080 | dataOut.EPhy_DP[:]=numpy.copy(dataOut.ephy2[:dataOut.cut]) |
|
3085 | dataOut.EPhy_DP[:]=numpy.copy(dataOut.ephy2[:dataOut.cut]) | |
3081 | dataOut.Phe_DP[:]=numpy.nan |
|
3086 | dataOut.Phe_DP[:]=numpy.nan | |
3082 | dataOut.EPhe_DP[:]=numpy.nan |
|
3087 | dataOut.EPhe_DP[:]=numpy.nan | |
3083 |
|
3088 | |||
3084 | missing=numpy.nan |
|
3089 | missing=numpy.nan | |
3085 | temp_min=100.0 |
|
3090 | temp_min=100.0 | |
3086 | temp_max_dp=3000.0 |
|
3091 | temp_max_dp=3000.0 | |
3087 |
|
3092 | |||
3088 | for i in range(dataOut.cut): |
|
3093 | for i in range(dataOut.cut): | |
3089 | if dataOut.info2[i]!=1: |
|
3094 | if dataOut.info2[i]!=1: | |
3090 | dataOut.ElecTemp_DP[i]=dataOut.EElecTemp_DP[i]=dataOut.IonTemp_DP[i]=dataOut.EIonTemp_DP[i]=missing |
|
3095 | dataOut.ElecTemp_DP[i]=dataOut.EElecTemp_DP[i]=dataOut.IonTemp_DP[i]=dataOut.EIonTemp_DP[i]=missing | |
3091 |
|
3096 | |||
3092 | if dataOut.ElecTemp_DP[i]<=temp_min or dataOut.ElecTemp_DP[i]>temp_max_dp or dataOut.EElecTemp_DP[i]>temp_max_dp: |
|
3097 | if dataOut.ElecTemp_DP[i]<=temp_min or dataOut.ElecTemp_DP[i]>temp_max_dp or dataOut.EElecTemp_DP[i]>temp_max_dp: | |
3093 |
|
3098 | |||
3094 | dataOut.ElecTemp_DP[i]=dataOut.EElecTemp_DP[i]=missing |
|
3099 | dataOut.ElecTemp_DP[i]=dataOut.EElecTemp_DP[i]=missing | |
3095 |
|
3100 | |||
3096 | if dataOut.IonTemp_DP[i]<=temp_min or dataOut.IonTemp_DP[i]>temp_max_dp or dataOut.EIonTemp_DP[i]>temp_max_dp: |
|
3101 | if dataOut.IonTemp_DP[i]<=temp_min or dataOut.IonTemp_DP[i]>temp_max_dp or dataOut.EIonTemp_DP[i]>temp_max_dp: | |
3097 | dataOut.IonTemp_DP[i]=dataOut.EIonTemp_DP[i]=missing |
|
3102 | dataOut.IonTemp_DP[i]=dataOut.EIonTemp_DP[i]=missing | |
3098 |
|
3103 | |||
3099 | ####################################################################################### CHECK THIS |
|
3104 | ####################################################################################### CHECK THIS | |
3100 | if dataOut.lags_to_plot[i,:][~numpy.isnan(dataOut.lags_to_plot[i,:])].shape[0]<6: |
|
3105 | if dataOut.lags_to_plot[i,:][~numpy.isnan(dataOut.lags_to_plot[i,:])].shape[0]<6: | |
3101 | dataOut.ElecTemp_DP[i]=dataOut.EElecTemp_DP[i]=dataOut.IonTemp_DP[i]=dataOut.EIonTemp_DP[i]=missing |
|
3106 | dataOut.ElecTemp_DP[i]=dataOut.EElecTemp_DP[i]=dataOut.IonTemp_DP[i]=dataOut.EIonTemp_DP[i]=missing | |
3102 |
|
3107 | |||
3103 | if dataOut.ut_Faraday>4 and dataOut.ut_Faraday<11: |
|
3108 | if dataOut.ut_Faraday>4 and dataOut.ut_Faraday<11: | |
3104 | if numpy.nanmax(dataOut.acfs_error_to_plot[i,:])>=10: |
|
3109 | if numpy.nanmax(dataOut.acfs_error_to_plot[i,:])>=10: | |
3105 | dataOut.ElecTemp_DP[i]=dataOut.EElecTemp_DP[i]=dataOut.IonTemp_DP[i]=dataOut.EIonTemp_DP[i]=missing |
|
3110 | dataOut.ElecTemp_DP[i]=dataOut.EElecTemp_DP[i]=dataOut.IonTemp_DP[i]=dataOut.EIonTemp_DP[i]=missing | |
3106 | ####################################################################################### |
|
3111 | ####################################################################################### | |
3107 |
|
3112 | |||
3108 | if dataOut.EPhy_DP[i]<0.0 or dataOut.EPhy_DP[i]>1.0: |
|
3113 | if dataOut.EPhy_DP[i]<0.0 or dataOut.EPhy_DP[i]>1.0: | |
3109 | dataOut.Phy_DP[i]=dataOut.EPhy_DP[i]=missing |
|
3114 | dataOut.Phy_DP[i]=dataOut.EPhy_DP[i]=missing | |
3110 | if dataOut.EDensity_DP[i]>0.0 and dataOut.Density_DP[i]>0.0 and dataOut.Density_DP[i]<9.9e6: |
|
3115 | if dataOut.EDensity_DP[i]>0.0 and dataOut.Density_DP[i]>0.0 and dataOut.Density_DP[i]<9.9e6: | |
3111 | dataOut.EDensity_DP[i]=max(dataOut.EDensity_DP[i],1000.0) |
|
3116 | dataOut.EDensity_DP[i]=max(dataOut.EDensity_DP[i],1000.0) | |
3112 | else: |
|
3117 | else: | |
3113 | dataOut.Density_DP[i]=dataOut.EDensity_DP[i]=missing |
|
3118 | dataOut.Density_DP[i]=dataOut.EDensity_DP[i]=missing | |
3114 | if dataOut.Phy_DP[i]==0 or dataOut.Phy_DP[i]>0.4: |
|
3119 | if dataOut.Phy_DP[i]==0 or dataOut.Phy_DP[i]>0.4: | |
3115 | dataOut.Phy_DP[i]=dataOut.EPhy_DP[i]=missing |
|
3120 | dataOut.Phy_DP[i]=dataOut.EPhy_DP[i]=missing | |
3116 | if dataOut.ElecTemp_DP[i]==dataOut.IonTemp_DP[i]: |
|
3121 | if dataOut.ElecTemp_DP[i]==dataOut.IonTemp_DP[i]: | |
3117 | dataOut.EElecTemp_DP[i]=dataOut.EIonTemp_DP[i] |
|
3122 | dataOut.EElecTemp_DP[i]=dataOut.EIonTemp_DP[i] | |
3118 | if numpy.isnan(dataOut.ElecTemp_DP[i]): |
|
3123 | if numpy.isnan(dataOut.ElecTemp_DP[i]): | |
3119 | dataOut.EElecTemp_DP[i]=missing |
|
3124 | dataOut.EElecTemp_DP[i]=missing | |
3120 | if numpy.isnan(dataOut.IonTemp_DP[i]): |
|
3125 | if numpy.isnan(dataOut.IonTemp_DP[i]): | |
3121 | dataOut.EIonTemp_DP[i]=missing |
|
3126 | dataOut.EIonTemp_DP[i]=missing | |
3122 | if numpy.isnan(dataOut.ElecTemp_DP[i]) or numpy.isnan(dataOut.EElecTemp_DP[i]): |
|
3127 | if numpy.isnan(dataOut.ElecTemp_DP[i]) or numpy.isnan(dataOut.EElecTemp_DP[i]): | |
3123 | dataOut.ElecTemp_DP[i]=dataOut.EElecTemp_DP[i]=dataOut.IonTemp_DP[i]=dataOut.EIonTemp_DP[i]=missing |
|
3128 | dataOut.ElecTemp_DP[i]=dataOut.EElecTemp_DP[i]=dataOut.IonTemp_DP[i]=dataOut.EIonTemp_DP[i]=missing | |
3124 |
|
3129 | |||
3125 |
|
3130 | |||
3126 |
|
3131 | |||
3127 | dataOut.Density_LP=numpy.zeros(dataOut.NACF-dataOut.cut) |
|
3132 | dataOut.Density_LP=numpy.zeros(dataOut.NACF-dataOut.cut) | |
3128 | dataOut.EDensity_LP=numpy.zeros(dataOut.NACF-dataOut.cut) |
|
3133 | dataOut.EDensity_LP=numpy.zeros(dataOut.NACF-dataOut.cut) | |
3129 | dataOut.ElecTemp_LP=numpy.zeros(dataOut.NACF-dataOut.cut) |
|
3134 | dataOut.ElecTemp_LP=numpy.zeros(dataOut.NACF-dataOut.cut) | |
3130 | dataOut.EElecTemp_LP=numpy.zeros(dataOut.NACF-dataOut.cut) |
|
3135 | dataOut.EElecTemp_LP=numpy.zeros(dataOut.NACF-dataOut.cut) | |
3131 | dataOut.IonTemp_LP=numpy.zeros(dataOut.NACF-dataOut.cut) |
|
3136 | dataOut.IonTemp_LP=numpy.zeros(dataOut.NACF-dataOut.cut) | |
3132 | dataOut.EIonTemp_LP=numpy.zeros(dataOut.NACF-dataOut.cut) |
|
3137 | dataOut.EIonTemp_LP=numpy.zeros(dataOut.NACF-dataOut.cut) | |
3133 | dataOut.Phy_LP=numpy.zeros(dataOut.NACF-dataOut.cut) |
|
3138 | dataOut.Phy_LP=numpy.zeros(dataOut.NACF-dataOut.cut) | |
3134 | dataOut.EPhy_LP=numpy.zeros(dataOut.NACF-dataOut.cut) |
|
3139 | dataOut.EPhy_LP=numpy.zeros(dataOut.NACF-dataOut.cut) | |
3135 | dataOut.Phe_LP=numpy.zeros(dataOut.NACF-dataOut.cut) |
|
3140 | dataOut.Phe_LP=numpy.zeros(dataOut.NACF-dataOut.cut) | |
3136 | dataOut.EPhe_LP=numpy.zeros(dataOut.NACF-dataOut.cut) |
|
3141 | dataOut.EPhe_LP=numpy.zeros(dataOut.NACF-dataOut.cut) | |
3137 |
|
3142 | |||
3138 | dataOut.Density_LP[:]=numpy.copy(dataOut.ne[dataOut.cut:dataOut.NACF]) |
|
3143 | dataOut.Density_LP[:]=numpy.copy(dataOut.ne[dataOut.cut:dataOut.NACF]) | |
3139 | dataOut.EDensity_LP[:]=numpy.copy(dataOut.ene[dataOut.cut:dataOut.NACF]) |
|
3144 | dataOut.EDensity_LP[:]=numpy.copy(dataOut.ene[dataOut.cut:dataOut.NACF]) | |
3140 | dataOut.ElecTemp_LP[:]=numpy.copy(dataOut.te[dataOut.cut:dataOut.NACF]) |
|
3145 | dataOut.ElecTemp_LP[:]=numpy.copy(dataOut.te[dataOut.cut:dataOut.NACF]) | |
3141 | dataOut.EElecTemp_LP[:]=numpy.copy(dataOut.ete[dataOut.cut:dataOut.NACF]) |
|
3146 | dataOut.EElecTemp_LP[:]=numpy.copy(dataOut.ete[dataOut.cut:dataOut.NACF]) | |
3142 | dataOut.IonTemp_LP[:]=numpy.copy(dataOut.ti[dataOut.cut:dataOut.NACF]) |
|
3147 | dataOut.IonTemp_LP[:]=numpy.copy(dataOut.ti[dataOut.cut:dataOut.NACF]) | |
3143 | dataOut.EIonTemp_LP[:]=numpy.copy(dataOut.eti[dataOut.cut:dataOut.NACF]) |
|
3148 | dataOut.EIonTemp_LP[:]=numpy.copy(dataOut.eti[dataOut.cut:dataOut.NACF]) | |
3144 | dataOut.Phy_LP[:]=numpy.copy(dataOut.ph[dataOut.cut:dataOut.NACF]) |
|
3149 | dataOut.Phy_LP[:]=numpy.copy(dataOut.ph[dataOut.cut:dataOut.NACF]) | |
3145 | dataOut.EPhy_LP[:]=numpy.copy(dataOut.eph[dataOut.cut:dataOut.NACF]) |
|
3150 | dataOut.EPhy_LP[:]=numpy.copy(dataOut.eph[dataOut.cut:dataOut.NACF]) | |
3146 | dataOut.Phe_LP[:]=numpy.copy(dataOut.phe[dataOut.cut:dataOut.NACF]) |
|
3151 | dataOut.Phe_LP[:]=numpy.copy(dataOut.phe[dataOut.cut:dataOut.NACF]) | |
3147 | dataOut.EPhe_LP[:]=numpy.copy(dataOut.ephe[dataOut.cut:dataOut.NACF]) |
|
3152 | dataOut.EPhe_LP[:]=numpy.copy(dataOut.ephe[dataOut.cut:dataOut.NACF]) | |
3148 |
|
3153 | |||
3149 | temp_max_lp=6000.0 |
|
3154 | temp_max_lp=6000.0 | |
3150 |
|
3155 | |||
3151 | for i in range(dataOut.NACF-dataOut.cut): |
|
3156 | for i in range(dataOut.NACF-dataOut.cut): | |
3152 |
|
3157 | |||
3153 | if dataOut.ElecTemp_LP[i]<=temp_min or dataOut.ElecTemp_LP[i]>temp_max_lp or dataOut.EElecTemp_LP[i]>temp_max_lp: |
|
3158 | if dataOut.ElecTemp_LP[i]<=temp_min or dataOut.ElecTemp_LP[i]>temp_max_lp or dataOut.EElecTemp_LP[i]>temp_max_lp: | |
3154 |
|
3159 | |||
3155 | dataOut.ElecTemp_LP[i]=dataOut.EElecTemp_LP[i]=missing |
|
3160 | dataOut.ElecTemp_LP[i]=dataOut.EElecTemp_LP[i]=missing | |
3156 |
|
3161 | |||
3157 | if dataOut.IonTemp_LP[i]<=temp_min or dataOut.IonTemp_LP[i]>temp_max_lp or dataOut.EIonTemp_LP[i]>temp_max_lp: |
|
3162 | if dataOut.IonTemp_LP[i]<=temp_min or dataOut.IonTemp_LP[i]>temp_max_lp or dataOut.EIonTemp_LP[i]>temp_max_lp: | |
3158 | dataOut.IonTemp_LP[i]=dataOut.EIonTemp_LP[i]=missing |
|
3163 | dataOut.IonTemp_LP[i]=dataOut.EIonTemp_LP[i]=missing | |
3159 | if dataOut.EPhy_LP[i]<0.0 or dataOut.EPhy_LP[i]>1.0: |
|
3164 | if dataOut.EPhy_LP[i]<0.0 or dataOut.EPhy_LP[i]>1.0: | |
3160 | dataOut.Phy_LP[i]=dataOut.EPhy_LP[i]=missing |
|
3165 | dataOut.Phy_LP[i]=dataOut.EPhy_LP[i]=missing | |
3161 |
|
3166 | |||
3162 | if dataOut.EPhe_LP[i]<0.0 or dataOut.EPhe_LP[i]>1.0: |
|
3167 | if dataOut.EPhe_LP[i]<0.0 or dataOut.EPhe_LP[i]>1.0: | |
3163 | dataOut.Phe_LP[i]=dataOut.EPhe_LP[i]=missing |
|
3168 | dataOut.Phe_LP[i]=dataOut.EPhe_LP[i]=missing | |
3164 | if dataOut.EDensity_LP[i]>0.0 and dataOut.Density_LP[i]>0.0 and dataOut.Density_LP[i]<9.9e6 and dataOut.EDensity_LP[i]*dataOut.Density_LP[i]<9.9e6: |
|
3169 | if dataOut.EDensity_LP[i]>0.0 and dataOut.Density_LP[i]>0.0 and dataOut.Density_LP[i]<9.9e6 and dataOut.EDensity_LP[i]*dataOut.Density_LP[i]<9.9e6: | |
3165 | dataOut.EDensity_LP[i]=max(dataOut.EDensity_LP[i],1000.0/dataOut.Density_LP[i]) |
|
3170 | dataOut.EDensity_LP[i]=max(dataOut.EDensity_LP[i],1000.0/dataOut.Density_LP[i]) | |
3166 | else: |
|
3171 | else: | |
3167 | dataOut.Density_LP[i]=missing |
|
3172 | dataOut.Density_LP[i]=missing | |
3168 | dataOut.EDensity_LP[i]=1.0 |
|
3173 | dataOut.EDensity_LP[i]=1.0 | |
3169 |
|
3174 | |||
3170 | if numpy.isnan(dataOut.Phy_LP[i]): |
|
3175 | if numpy.isnan(dataOut.Phy_LP[i]): | |
3171 | dataOut.EPhy_LP[i]=missing |
|
3176 | dataOut.EPhy_LP[i]=missing | |
3172 |
|
3177 | |||
3173 | if numpy.isnan(dataOut.Phe_LP[i]): |
|
3178 | if numpy.isnan(dataOut.Phe_LP[i]): | |
3174 | dataOut.EPhe_LP[i]=missing |
|
3179 | dataOut.EPhe_LP[i]=missing | |
3175 |
|
3180 | |||
3176 |
|
3181 | |||
3177 | if dataOut.ElecTemp_LP[i]==dataOut.IonTemp_LP[i]: |
|
3182 | if dataOut.ElecTemp_LP[i]==dataOut.IonTemp_LP[i]: | |
3178 | dataOut.EElecTemp_LP[i]=dataOut.EIonTemp_LP[i] |
|
3183 | dataOut.EElecTemp_LP[i]=dataOut.EIonTemp_LP[i] | |
3179 | if numpy.isnan(dataOut.ElecTemp_LP[i]): |
|
3184 | if numpy.isnan(dataOut.ElecTemp_LP[i]): | |
3180 | dataOut.EElecTemp_LP[i]=missing |
|
3185 | dataOut.EElecTemp_LP[i]=missing | |
3181 | if numpy.isnan(dataOut.IonTemp_LP[i]): |
|
3186 | if numpy.isnan(dataOut.IonTemp_LP[i]): | |
3182 | dataOut.EIonTemp_LP[i]=missing |
|
3187 | dataOut.EIonTemp_LP[i]=missing | |
3183 | if numpy.isnan(dataOut.ElecTemp_LP[i]) or numpy.isnan(dataOut.EElecTemp_LP[i]): |
|
3188 | if numpy.isnan(dataOut.ElecTemp_LP[i]) or numpy.isnan(dataOut.EElecTemp_LP[i]): | |
3184 | dataOut.ElecTemp_LP[i]=dataOut.EElecTemp_LP[i]=dataOut.IonTemp_LP[i]=dataOut.EIonTemp_LP[i]=missing |
|
3189 | dataOut.ElecTemp_LP[i]=dataOut.EElecTemp_LP[i]=dataOut.IonTemp_LP[i]=dataOut.EIonTemp_LP[i]=missing | |
3185 |
|
3190 | |||
3186 |
|
3191 | |||
3187 | dataOut.DensityFinal=numpy.reshape(numpy.concatenate((dataOut.Density_DP,dataOut.Density_LP)),(1,-1)) |
|
3192 | dataOut.DensityFinal=numpy.reshape(numpy.concatenate((dataOut.Density_DP,dataOut.Density_LP)),(1,-1)) | |
3188 | dataOut.EDensityFinal=numpy.reshape(numpy.concatenate((dataOut.EDensity_DP,dataOut.EDensity_LP)),(1,-1)) |
|
3193 | dataOut.EDensityFinal=numpy.reshape(numpy.concatenate((dataOut.EDensity_DP,dataOut.EDensity_LP)),(1,-1)) | |
3189 | dataOut.ElecTempFinal=numpy.reshape(numpy.concatenate((dataOut.ElecTemp_DP,dataOut.ElecTemp_LP)),(1,-1)) |
|
3194 | dataOut.ElecTempFinal=numpy.reshape(numpy.concatenate((dataOut.ElecTemp_DP,dataOut.ElecTemp_LP)),(1,-1)) | |
3190 | dataOut.EElecTempFinal=numpy.reshape(numpy.concatenate((dataOut.EElecTemp_DP,dataOut.EElecTemp_LP)),(1,-1)) |
|
3195 | dataOut.EElecTempFinal=numpy.reshape(numpy.concatenate((dataOut.EElecTemp_DP,dataOut.EElecTemp_LP)),(1,-1)) | |
3191 | dataOut.IonTempFinal=numpy.reshape(numpy.concatenate((dataOut.IonTemp_DP,dataOut.IonTemp_LP)),(1,-1)) |
|
3196 | dataOut.IonTempFinal=numpy.reshape(numpy.concatenate((dataOut.IonTemp_DP,dataOut.IonTemp_LP)),(1,-1)) | |
3192 | dataOut.EIonTempFinal=numpy.reshape(numpy.concatenate((dataOut.EIonTemp_DP,dataOut.EIonTemp_LP)),(1,-1)) |
|
3197 | dataOut.EIonTempFinal=numpy.reshape(numpy.concatenate((dataOut.EIonTemp_DP,dataOut.EIonTemp_LP)),(1,-1)) | |
3193 | dataOut.PhyFinal=numpy.reshape(numpy.concatenate((dataOut.Phy_DP,dataOut.Phy_LP)),(1,-1)) |
|
3198 | dataOut.PhyFinal=numpy.reshape(numpy.concatenate((dataOut.Phy_DP,dataOut.Phy_LP)),(1,-1)) | |
3194 | dataOut.EPhyFinal=numpy.reshape(numpy.concatenate((dataOut.EPhy_DP,dataOut.EPhy_LP)),(1,-1)) |
|
3199 | dataOut.EPhyFinal=numpy.reshape(numpy.concatenate((dataOut.EPhy_DP,dataOut.EPhy_LP)),(1,-1)) | |
3195 | dataOut.PheFinal=numpy.reshape(numpy.concatenate((dataOut.Phe_DP,dataOut.Phe_LP)),(1,-1)) |
|
3200 | dataOut.PheFinal=numpy.reshape(numpy.concatenate((dataOut.Phe_DP,dataOut.Phe_LP)),(1,-1)) | |
3196 | dataOut.EPheFinal=numpy.reshape(numpy.concatenate((dataOut.EPhe_DP,dataOut.EPhe_LP)),(1,-1)) |
|
3201 | dataOut.EPheFinal=numpy.reshape(numpy.concatenate((dataOut.EPhe_DP,dataOut.EPhe_LP)),(1,-1)) | |
3197 |
|
3202 | |||
3198 | nan_array_2=numpy.empty(dataOut.NACF-dataOut.NDP) |
|
3203 | nan_array_2=numpy.empty(dataOut.NACF-dataOut.NDP) | |
3199 | nan_array_2[:]=numpy.nan |
|
3204 | nan_array_2[:]=numpy.nan | |
3200 |
|
3205 | |||
3201 | dataOut.acfs_DP=numpy.zeros((dataOut.NACF,dataOut.DPL),'float32') |
|
3206 | dataOut.acfs_DP=numpy.zeros((dataOut.NACF,dataOut.DPL),'float32') | |
3202 | dataOut.acfs_error_DP=numpy.zeros((dataOut.NACF,dataOut.DPL),'float32') |
|
3207 | dataOut.acfs_error_DP=numpy.zeros((dataOut.NACF,dataOut.DPL),'float32') | |
3203 | acfs_dp_aux=dataOut.acfs_to_save.transpose() |
|
3208 | acfs_dp_aux=dataOut.acfs_to_save.transpose() | |
3204 | acfs_error_dp_aux=dataOut.acfs_error_to_save.transpose() |
|
3209 | acfs_error_dp_aux=dataOut.acfs_error_to_save.transpose() | |
3205 | for i in range(dataOut.DPL): |
|
3210 | for i in range(dataOut.DPL): | |
3206 | dataOut.acfs_DP[:,i]=numpy.concatenate((acfs_dp_aux[:,i],nan_array_2)) |
|
3211 | dataOut.acfs_DP[:,i]=numpy.concatenate((acfs_dp_aux[:,i],nan_array_2)) | |
3207 | dataOut.acfs_error_DP[:,i]=numpy.concatenate((acfs_error_dp_aux[:,i],nan_array_2)) |
|
3212 | dataOut.acfs_error_DP[:,i]=numpy.concatenate((acfs_error_dp_aux[:,i],nan_array_2)) | |
3208 | dataOut.acfs_DP=dataOut.acfs_DP.transpose() |
|
3213 | dataOut.acfs_DP=dataOut.acfs_DP.transpose() | |
3209 | dataOut.acfs_error_DP=dataOut.acfs_error_DP.transpose() |
|
3214 | dataOut.acfs_error_DP=dataOut.acfs_error_DP.transpose() | |
3210 |
|
3215 | |||
3211 | dataOut.acfs_LP=numpy.zeros((dataOut.NACF,dataOut.IBITS),'float32') |
|
3216 | dataOut.acfs_LP=numpy.zeros((dataOut.NACF,dataOut.IBITS),'float32') | |
3212 | dataOut.acfs_error_LP=numpy.zeros((dataOut.NACF,dataOut.IBITS),'float32') |
|
3217 | dataOut.acfs_error_LP=numpy.zeros((dataOut.NACF,dataOut.IBITS),'float32') | |
3213 |
|
3218 | |||
3214 | for i in range(dataOut.NACF): |
|
3219 | for i in range(dataOut.NACF): | |
3215 | for j in range(dataOut.IBITS): |
|
3220 | for j in range(dataOut.IBITS): | |
3216 | if numpy.abs(dataOut.errors[j,i]/dataOut.output_LP_integrated.real[0,i,0])<1.0: |
|
3221 | if numpy.abs(dataOut.errors[j,i]/dataOut.output_LP_integrated.real[0,i,0])<1.0: | |
3217 | dataOut.acfs_LP[i,j]=dataOut.output_LP_integrated.real[j,i,0]/dataOut.output_LP_integrated.real[0,i,0] |
|
3222 | dataOut.acfs_LP[i,j]=dataOut.output_LP_integrated.real[j,i,0]/dataOut.output_LP_integrated.real[0,i,0] | |
3218 | dataOut.acfs_LP[i,j]=max(min(dataOut.acfs_LP[i,j],1.0),-1.0) |
|
3223 | dataOut.acfs_LP[i,j]=max(min(dataOut.acfs_LP[i,j],1.0),-1.0) | |
3219 |
|
3224 | |||
3220 | dataOut.acfs_error_LP[i,j]=dataOut.errors[j,i]/dataOut.output_LP_integrated.real[0,i,0] |
|
3225 | dataOut.acfs_error_LP[i,j]=dataOut.errors[j,i]/dataOut.output_LP_integrated.real[0,i,0] | |
3221 | else: |
|
3226 | else: | |
3222 | dataOut.acfs_LP[i,j]=numpy.nan |
|
3227 | dataOut.acfs_LP[i,j]=numpy.nan | |
3223 |
|
3228 | |||
3224 | dataOut.acfs_error_LP[i,j]=numpy.nan |
|
3229 | dataOut.acfs_error_LP[i,j]=numpy.nan | |
3225 |
|
3230 | |||
3226 | dataOut.acfs_LP=dataOut.acfs_LP.transpose() |
|
3231 | dataOut.acfs_LP=dataOut.acfs_LP.transpose() | |
3227 | dataOut.acfs_error_LP=dataOut.acfs_error_LP.transpose() |
|
3232 | dataOut.acfs_error_LP=dataOut.acfs_error_LP.transpose() | |
3228 |
|
3233 | |||
3229 | dataOut.DensityFinal *= 1.e6 #Convert units to m^β»3 |
|
3234 | dataOut.DensityFinal *= 1.e6 #Convert units to m^β»3 | |
3230 | dataOut.EDensityFinal *= 1.e6 #Convert units to m^β»3 |
|
3235 | dataOut.EDensityFinal *= 1.e6 #Convert units to m^β»3 | |
3231 |
|
3236 | |||
3232 | return dataOut |
|
3237 | return dataOut | |
3233 |
|
3238 | |||
3234 |
|
3239 | |||
3235 | class ACFs(Operation): |
|
3240 | class ACFs(Operation): | |
3236 | ''' |
|
3241 | ''' | |
3237 | Written by R. Flores |
|
3242 | Written by R. Flores | |
3238 | ''' |
|
3243 | ''' | |
3239 | def __init__(self, **kwargs): |
|
3244 | def __init__(self, **kwargs): | |
3240 |
|
3245 | |||
3241 | Operation.__init__(self, **kwargs) |
|
3246 | Operation.__init__(self, **kwargs) | |
3242 |
|
3247 | |||
3243 | self.aux=1 |
|
3248 | self.aux=1 | |
3244 |
|
3249 | |||
3245 | def run(self,dataOut): |
|
3250 | def run(self,dataOut): | |
3246 |
|
3251 | |||
3247 | if self.aux: |
|
3252 | if self.aux: | |
3248 | self.taup=numpy.zeros(dataOut.DPL,'float32') |
|
3253 | self.taup=numpy.zeros(dataOut.DPL,'float32') | |
3249 | self.pacf=numpy.zeros(dataOut.DPL,'float32') |
|
3254 | self.pacf=numpy.zeros(dataOut.DPL,'float32') | |
3250 | self.sacf=numpy.zeros(dataOut.DPL,'float32') |
|
3255 | self.sacf=numpy.zeros(dataOut.DPL,'float32') | |
3251 |
|
3256 | |||
3252 | self.taup_full=numpy.zeros(dataOut.DPL,'float32') |
|
3257 | self.taup_full=numpy.zeros(dataOut.DPL,'float32') | |
3253 | self.pacf_full=numpy.zeros(dataOut.DPL,'float32') |
|
3258 | self.pacf_full=numpy.zeros(dataOut.DPL,'float32') | |
3254 | self.sacf_full=numpy.zeros(dataOut.DPL,'float32') |
|
3259 | self.sacf_full=numpy.zeros(dataOut.DPL,'float32') | |
3255 | self.x_igcej=numpy.zeros(dataOut.DPL,'float32') |
|
3260 | self.x_igcej=numpy.zeros(dataOut.DPL,'float32') | |
3256 | self.y_igcej=numpy.zeros(dataOut.DPL,'float32') |
|
3261 | self.y_igcej=numpy.zeros(dataOut.DPL,'float32') | |
3257 | self.x_ibad=numpy.zeros(dataOut.DPL,'float32') |
|
3262 | self.x_ibad=numpy.zeros(dataOut.DPL,'float32') | |
3258 | self.y_ibad=numpy.zeros(dataOut.DPL,'float32') |
|
3263 | self.y_ibad=numpy.zeros(dataOut.DPL,'float32') | |
3259 | self.aux=0 |
|
3264 | self.aux=0 | |
3260 |
|
3265 | |||
3261 | dataOut.acfs_to_plot=numpy.zeros((dataOut.NDP,dataOut.DPL),'float32') |
|
3266 | dataOut.acfs_to_plot=numpy.zeros((dataOut.NDP,dataOut.DPL),'float32') | |
3262 | dataOut.acfs_to_save=numpy.zeros((dataOut.NDP,dataOut.DPL),'float32') |
|
3267 | dataOut.acfs_to_save=numpy.zeros((dataOut.NDP,dataOut.DPL),'float32') | |
3263 | dataOut.acfs_error_to_plot=numpy.zeros((dataOut.NDP,dataOut.DPL),'float32') |
|
3268 | dataOut.acfs_error_to_plot=numpy.zeros((dataOut.NDP,dataOut.DPL),'float32') | |
3264 | dataOut.acfs_error_to_save=numpy.zeros((dataOut.NDP,dataOut.DPL),'float32') |
|
3269 | dataOut.acfs_error_to_save=numpy.zeros((dataOut.NDP,dataOut.DPL),'float32') | |
3265 | dataOut.lags_to_plot=numpy.zeros((dataOut.NDP,dataOut.DPL),'float32') |
|
3270 | dataOut.lags_to_plot=numpy.zeros((dataOut.NDP,dataOut.DPL),'float32') | |
3266 | dataOut.x_igcej_to_plot=numpy.zeros((dataOut.NDP,dataOut.DPL),'float32') |
|
3271 | dataOut.x_igcej_to_plot=numpy.zeros((dataOut.NDP,dataOut.DPL),'float32') | |
3267 | dataOut.x_ibad_to_plot=numpy.zeros((dataOut.NDP,dataOut.DPL),'float32') |
|
3272 | dataOut.x_ibad_to_plot=numpy.zeros((dataOut.NDP,dataOut.DPL),'float32') | |
3268 | dataOut.y_igcej_to_plot=numpy.zeros((dataOut.NDP,dataOut.DPL),'float32') |
|
3273 | dataOut.y_igcej_to_plot=numpy.zeros((dataOut.NDP,dataOut.DPL),'float32') | |
3269 | dataOut.y_ibad_to_plot=numpy.zeros((dataOut.NDP,dataOut.DPL),'float32') |
|
3274 | dataOut.y_ibad_to_plot=numpy.zeros((dataOut.NDP,dataOut.DPL),'float32') | |
3270 |
|
3275 | |||
3271 | for i in range(dataOut.NSHTS): |
|
3276 | for i in range(dataOut.NSHTS): | |
3272 |
|
3277 | |||
3273 | acfm=dataOut.rhor[i][0]**2+dataOut.rhoi[i][0]**2 |
|
3278 | acfm=dataOut.rhor[i][0]**2+dataOut.rhoi[i][0]**2 | |
3274 |
|
3279 | |||
3275 | if acfm>0: |
|
3280 | if acfm>0: | |
3276 | cc=dataOut.rhor[i][0]/acfm |
|
3281 | cc=dataOut.rhor[i][0]/acfm | |
3277 | ss=dataOut.rhoi[i][0]/acfm |
|
3282 | ss=dataOut.rhoi[i][0]/acfm | |
3278 | else: |
|
3283 | else: | |
3279 | cc=1. |
|
3284 | cc=1. | |
3280 | ss=0. |
|
3285 | ss=0. | |
3281 |
|
3286 | |||
3282 | # keep only uncontaminated data |
|
3287 | # keep only uncontaminated data | |
3283 | for l in range(dataOut.DPL): |
|
3288 | for l in range(dataOut.DPL): | |
3284 | fact=dataOut.DH |
|
3289 | fact=dataOut.DH | |
3285 | if (dataOut.igcej[i][l]==0 and dataOut.ibad[i][l]==0): |
|
3290 | if (dataOut.igcej[i][l]==0 and dataOut.ibad[i][l]==0): | |
3286 |
|
3291 | |||
3287 | self.pacf_full[l]=min(1.0,max(-1.0,(dataOut.rhor[i][l]*cc + dataOut.rhoi[i][l]*ss)))*fact+dataOut.range1[i] |
|
3292 | self.pacf_full[l]=min(1.0,max(-1.0,(dataOut.rhor[i][l]*cc + dataOut.rhoi[i][l]*ss)))*fact+dataOut.range1[i] | |
3288 | self.sacf_full[l]=min(1.0,numpy.sqrt(dataOut.sd[i][l]))*fact |
|
3293 | self.sacf_full[l]=min(1.0,numpy.sqrt(dataOut.sd[i][l]))*fact | |
3289 | self.taup_full[l]=dataOut.alag[l] |
|
3294 | self.taup_full[l]=dataOut.alag[l] | |
3290 | self.x_igcej[l]=numpy.nan |
|
3295 | self.x_igcej[l]=numpy.nan | |
3291 | self.y_igcej[l]=numpy.nan |
|
3296 | self.y_igcej[l]=numpy.nan | |
3292 | self.x_ibad[l]=numpy.nan |
|
3297 | self.x_ibad[l]=numpy.nan | |
3293 | self.y_ibad[l]=numpy.nan |
|
3298 | self.y_ibad[l]=numpy.nan | |
3294 |
|
3299 | |||
3295 | else: |
|
3300 | else: | |
3296 | self.pacf_full[l]=numpy.nan |
|
3301 | self.pacf_full[l]=numpy.nan | |
3297 | self.sacf_full[l]=numpy.nan |
|
3302 | self.sacf_full[l]=numpy.nan | |
3298 | self.taup_full[l]=numpy.nan |
|
3303 | self.taup_full[l]=numpy.nan | |
3299 |
|
3304 | |||
3300 | if dataOut.igcej[i][l]: |
|
3305 | if dataOut.igcej[i][l]: | |
3301 | self.x_igcej[l]=dataOut.alag[l] |
|
3306 | self.x_igcej[l]=dataOut.alag[l] | |
3302 | self.y_igcej[l]=dataOut.range1[i] |
|
3307 | self.y_igcej[l]=dataOut.range1[i] | |
3303 | self.x_ibad[l]=numpy.nan |
|
3308 | self.x_ibad[l]=numpy.nan | |
3304 | self.y_ibad[l]=numpy.nan |
|
3309 | self.y_ibad[l]=numpy.nan | |
3305 |
|
3310 | |||
3306 | if dataOut.ibad[i][l]: |
|
3311 | if dataOut.ibad[i][l]: | |
3307 | self.x_igcej[l]=numpy.nan |
|
3312 | self.x_igcej[l]=numpy.nan | |
3308 | self.y_igcej[l]=numpy.nan |
|
3313 | self.y_igcej[l]=numpy.nan | |
3309 | self.x_ibad[l]=dataOut.alag[l] |
|
3314 | self.x_ibad[l]=dataOut.alag[l] | |
3310 | self.y_ibad[l]=dataOut.range1[i] |
|
3315 | self.y_ibad[l]=dataOut.range1[i] | |
3311 |
|
3316 | |||
3312 | pacf_new=numpy.copy((self.pacf_full-dataOut.range1[i])/dataOut.DH) |
|
3317 | pacf_new=numpy.copy((self.pacf_full-dataOut.range1[i])/dataOut.DH) | |
3313 | sacf_new=numpy.copy(self.sacf_full/dataOut.DH) |
|
3318 | sacf_new=numpy.copy(self.sacf_full/dataOut.DH) | |
3314 | dataOut.acfs_to_save[i,:]=numpy.copy(pacf_new) |
|
3319 | dataOut.acfs_to_save[i,:]=numpy.copy(pacf_new) | |
3315 | dataOut.acfs_error_to_save[i,:]=numpy.copy(sacf_new) |
|
3320 | dataOut.acfs_error_to_save[i,:]=numpy.copy(sacf_new) | |
3316 | dataOut.acfs_to_plot[i,:]=numpy.copy(self.pacf_full) |
|
3321 | dataOut.acfs_to_plot[i,:]=numpy.copy(self.pacf_full) | |
3317 | dataOut.acfs_error_to_plot[i,:]=numpy.copy(self.sacf_full) |
|
3322 | dataOut.acfs_error_to_plot[i,:]=numpy.copy(self.sacf_full) | |
3318 | dataOut.lags_to_plot[i,:]=numpy.copy(self.taup_full) |
|
3323 | dataOut.lags_to_plot[i,:]=numpy.copy(self.taup_full) | |
3319 | dataOut.x_igcej_to_plot[i,:]=numpy.copy(self.x_igcej) |
|
3324 | dataOut.x_igcej_to_plot[i,:]=numpy.copy(self.x_igcej) | |
3320 | dataOut.x_ibad_to_plot[i,:]=numpy.copy(self.x_ibad) |
|
3325 | dataOut.x_ibad_to_plot[i,:]=numpy.copy(self.x_ibad) | |
3321 | dataOut.y_igcej_to_plot[i,:]=numpy.copy(self.y_igcej) |
|
3326 | dataOut.y_igcej_to_plot[i,:]=numpy.copy(self.y_igcej) | |
3322 | dataOut.y_ibad_to_plot[i,:]=numpy.copy(self.y_ibad) |
|
3327 | dataOut.y_ibad_to_plot[i,:]=numpy.copy(self.y_ibad) | |
3323 |
|
3328 | |||
3324 | missing=numpy.nan#-32767 |
|
3329 | missing=numpy.nan#-32767 | |
3325 |
|
3330 | |||
3326 | for i in range(dataOut.NSHTS,dataOut.NDP): |
|
3331 | for i in range(dataOut.NSHTS,dataOut.NDP): | |
3327 | for j in range(dataOut.DPL): |
|
3332 | for j in range(dataOut.DPL): | |
3328 | dataOut.acfs_to_save[i,j]=missing |
|
3333 | dataOut.acfs_to_save[i,j]=missing | |
3329 | dataOut.acfs_error_to_save[i,j]=missing |
|
3334 | dataOut.acfs_error_to_save[i,j]=missing | |
3330 | dataOut.acfs_to_plot[i,j]=missing |
|
3335 | dataOut.acfs_to_plot[i,j]=missing | |
3331 | dataOut.acfs_error_to_plot[i,j]=missing |
|
3336 | dataOut.acfs_error_to_plot[i,j]=missing | |
3332 | dataOut.lags_to_plot[i,j]=missing |
|
3337 | dataOut.lags_to_plot[i,j]=missing | |
3333 | dataOut.x_igcej_to_plot[i,j]=missing |
|
3338 | dataOut.x_igcej_to_plot[i,j]=missing | |
3334 | dataOut.x_ibad_to_plot[i,j]=missing |
|
3339 | dataOut.x_ibad_to_plot[i,j]=missing | |
3335 | dataOut.y_igcej_to_plot[i,j]=missing |
|
3340 | dataOut.y_igcej_to_plot[i,j]=missing | |
3336 | dataOut.y_ibad_to_plot[i,j]=missing |
|
3341 | dataOut.y_ibad_to_plot[i,j]=missing | |
3337 |
|
3342 | |||
3338 | dataOut.acfs_to_save=dataOut.acfs_to_save.transpose() |
|
3343 | dataOut.acfs_to_save=dataOut.acfs_to_save.transpose() | |
3339 | dataOut.acfs_error_to_save=dataOut.acfs_error_to_save.transpose() |
|
3344 | dataOut.acfs_error_to_save=dataOut.acfs_error_to_save.transpose() | |
3340 |
|
3345 | |||
3341 | return dataOut |
|
3346 | return dataOut | |
3342 |
|
3347 | |||
3343 |
|
3348 | |||
3344 | class CohInt(Operation): |
|
3349 | class CohInt(Operation): | |
3345 |
|
3350 | |||
3346 | isConfig = False |
|
3351 | isConfig = False | |
3347 | __profIndex = 0 |
|
3352 | __profIndex = 0 | |
3348 | __byTime = False |
|
3353 | __byTime = False | |
3349 | __initime = None |
|
3354 | __initime = None | |
3350 | __lastdatatime = None |
|
3355 | __lastdatatime = None | |
3351 | __integrationtime = None |
|
3356 | __integrationtime = None | |
3352 | __buffer = None |
|
3357 | __buffer = None | |
3353 | __bufferStride = [] |
|
3358 | __bufferStride = [] | |
3354 | __dataReady = False |
|
3359 | __dataReady = False | |
3355 | __profIndexStride = 0 |
|
3360 | __profIndexStride = 0 | |
3356 | __dataToPutStride = False |
|
3361 | __dataToPutStride = False | |
3357 | n = None |
|
3362 | n = None | |
3358 |
|
3363 | |||
3359 | def __init__(self, **kwargs): |
|
3364 | def __init__(self, **kwargs): | |
3360 |
|
3365 | |||
3361 | Operation.__init__(self, **kwargs) |
|
3366 | Operation.__init__(self, **kwargs) | |
3362 |
|
3367 | |||
3363 | # self.isConfig = False |
|
3368 | # self.isConfig = False | |
3364 |
|
3369 | |||
3365 | def setup(self, n=None, timeInterval=None, stride=None, overlapping=False, byblock=False): |
|
3370 | def setup(self, n=None, timeInterval=None, stride=None, overlapping=False, byblock=False): | |
3366 | """ |
|
3371 | """ | |
3367 | Set the parameters of the integration class. |
|
3372 | Set the parameters of the integration class. | |
3368 |
|
3373 | |||
3369 | Inputs: |
|
3374 | Inputs: | |
3370 |
|
3375 | |||
3371 | n : Number of coherent integrations |
|
3376 | n : Number of coherent integrations | |
3372 | timeInterval : Time of integration. If the parameter "n" is selected this one does not work |
|
3377 | timeInterval : Time of integration. If the parameter "n" is selected this one does not work | |
3373 | overlapping : |
|
3378 | overlapping : | |
3374 | """ |
|
3379 | """ | |
3375 |
|
3380 | |||
3376 | self.__initime = None |
|
3381 | self.__initime = None | |
3377 | self.__lastdatatime = 0 |
|
3382 | self.__lastdatatime = 0 | |
3378 | self.__buffer = None |
|
3383 | self.__buffer = None | |
3379 | self.__dataReady = False |
|
3384 | self.__dataReady = False | |
3380 | self.byblock = byblock |
|
3385 | self.byblock = byblock | |
3381 | self.stride = stride |
|
3386 | self.stride = stride | |
3382 |
|
3387 | |||
3383 | if n == None and timeInterval == None: |
|
3388 | if n == None and timeInterval == None: | |
3384 | raise ValueError("n or timeInterval should be specified ...") |
|
3389 | raise ValueError("n or timeInterval should be specified ...") | |
3385 |
|
3390 | |||
3386 | if n != None: |
|
3391 | if n != None: | |
3387 | self.n = n |
|
3392 | self.n = n | |
3388 | self.__byTime = False |
|
3393 | self.__byTime = False | |
3389 | else: |
|
3394 | else: | |
3390 | self.__integrationtime = timeInterval #* 60. #if (type(timeInterval)!=integer) -> change this line |
|
3395 | self.__integrationtime = timeInterval #* 60. #if (type(timeInterval)!=integer) -> change this line | |
3391 | self.n = 9999 |
|
3396 | self.n = 9999 | |
3392 | self.__byTime = True |
|
3397 | self.__byTime = True | |
3393 |
|
3398 | |||
3394 | if overlapping: |
|
3399 | if overlapping: | |
3395 | self.__withOverlapping = True |
|
3400 | self.__withOverlapping = True | |
3396 | self.__buffer = None |
|
3401 | self.__buffer = None | |
3397 | else: |
|
3402 | else: | |
3398 | self.__withOverlapping = False |
|
3403 | self.__withOverlapping = False | |
3399 | self.__buffer = 0 |
|
3404 | self.__buffer = 0 | |
3400 |
|
3405 | |||
3401 | self.__profIndex = 0 |
|
3406 | self.__profIndex = 0 | |
3402 |
|
3407 | |||
3403 | def putData(self, data): |
|
3408 | def putData(self, data): | |
3404 |
|
3409 | |||
3405 | """ |
|
3410 | """ | |
3406 | Add a profile to the __buffer and increase in one the __profileIndex |
|
3411 | Add a profile to the __buffer and increase in one the __profileIndex | |
3407 |
|
3412 | |||
3408 | """ |
|
3413 | """ | |
3409 |
|
3414 | |||
3410 | if not self.__withOverlapping: |
|
3415 | if not self.__withOverlapping: | |
3411 | self.__buffer += data.copy() |
|
3416 | self.__buffer += data.copy() | |
3412 | self.__profIndex += 1 |
|
3417 | self.__profIndex += 1 | |
3413 | return |
|
3418 | return | |
3414 |
|
3419 | |||
3415 | #Overlapping data |
|
3420 | #Overlapping data | |
3416 | nChannels, nHeis = data.shape |
|
3421 | nChannels, nHeis = data.shape | |
3417 | data = numpy.reshape(data, (1, nChannels, nHeis)) |
|
3422 | data = numpy.reshape(data, (1, nChannels, nHeis)) | |
3418 |
|
3423 | |||
3419 | #If the buffer is empty then it takes the data value |
|
3424 | #If the buffer is empty then it takes the data value | |
3420 | if self.__buffer is None: |
|
3425 | if self.__buffer is None: | |
3421 | self.__buffer = data |
|
3426 | self.__buffer = data | |
3422 | self.__profIndex += 1 |
|
3427 | self.__profIndex += 1 | |
3423 | return |
|
3428 | return | |
3424 |
|
3429 | |||
3425 | #If the buffer length is lower than n then stakcing the data value |
|
3430 | #If the buffer length is lower than n then stakcing the data value | |
3426 | if self.__profIndex < self.n: |
|
3431 | if self.__profIndex < self.n: | |
3427 | self.__buffer = numpy.vstack((self.__buffer, data)) |
|
3432 | self.__buffer = numpy.vstack((self.__buffer, data)) | |
3428 | self.__profIndex += 1 |
|
3433 | self.__profIndex += 1 | |
3429 | return |
|
3434 | return | |
3430 |
|
3435 | |||
3431 | #If the buffer length is equal to n then replacing the last buffer value with the data value |
|
3436 | #If the buffer length is equal to n then replacing the last buffer value with the data value | |
3432 | self.__buffer = numpy.roll(self.__buffer, -1, axis=0) |
|
3437 | self.__buffer = numpy.roll(self.__buffer, -1, axis=0) | |
3433 | self.__buffer[self.n-1] = data |
|
3438 | self.__buffer[self.n-1] = data | |
3434 | self.__profIndex = self.n |
|
3439 | self.__profIndex = self.n | |
3435 | return |
|
3440 | return | |
3436 |
|
3441 | |||
3437 |
|
3442 | |||
3438 | def pushData(self): |
|
3443 | def pushData(self): | |
3439 | """ |
|
3444 | """ | |
3440 | Return the sum of the last profiles and the profiles used in the sum. |
|
3445 | Return the sum of the last profiles and the profiles used in the sum. | |
3441 |
|
3446 | |||
3442 | Affected: |
|
3447 | Affected: | |
3443 |
|
3448 | |||
3444 | self.__profileIndex |
|
3449 | self.__profileIndex | |
3445 |
|
3450 | |||
3446 | """ |
|
3451 | """ | |
3447 |
|
3452 | |||
3448 | if not self.__withOverlapping: |
|
3453 | if not self.__withOverlapping: | |
3449 | data = self.__buffer |
|
3454 | data = self.__buffer | |
3450 | n = self.__profIndex |
|
3455 | n = self.__profIndex | |
3451 |
|
3456 | |||
3452 | self.__buffer = 0 |
|
3457 | self.__buffer = 0 | |
3453 | self.__profIndex = 0 |
|
3458 | self.__profIndex = 0 | |
3454 |
|
3459 | |||
3455 | return data, n |
|
3460 | return data, n | |
3456 |
|
3461 | |||
3457 | #Integration with Overlapping |
|
3462 | #Integration with Overlapping | |
3458 | data = numpy.sum(self.__buffer, axis=0) |
|
3463 | data = numpy.sum(self.__buffer, axis=0) | |
3459 | # print data |
|
3464 | # print data | |
3460 | # raise |
|
3465 | # raise | |
3461 | n = self.__profIndex |
|
3466 | n = self.__profIndex | |
3462 |
|
3467 | |||
3463 | return data, n |
|
3468 | return data, n | |
3464 |
|
3469 | |||
3465 | def byProfiles(self, data): |
|
3470 | def byProfiles(self, data): | |
3466 |
|
3471 | |||
3467 | self.__dataReady = False |
|
3472 | self.__dataReady = False | |
3468 | avgdata = None |
|
3473 | avgdata = None | |
3469 | # n = None |
|
3474 | # n = None | |
3470 | # print data |
|
3475 | # print data | |
3471 | # raise |
|
3476 | # raise | |
3472 | self.putData(data) |
|
3477 | self.putData(data) | |
3473 |
|
3478 | |||
3474 | if self.__profIndex == self.n: |
|
3479 | if self.__profIndex == self.n: | |
3475 | avgdata, n = self.pushData() |
|
3480 | avgdata, n = self.pushData() | |
3476 | self.__dataReady = True |
|
3481 | self.__dataReady = True | |
3477 |
|
3482 | |||
3478 | return avgdata |
|
3483 | return avgdata | |
3479 |
|
3484 | |||
3480 | def byTime(self, data, datatime): |
|
3485 | def byTime(self, data, datatime): | |
3481 |
|
3486 | |||
3482 | self.__dataReady = False |
|
3487 | self.__dataReady = False | |
3483 | avgdata = None |
|
3488 | avgdata = None | |
3484 | n = None |
|
3489 | n = None | |
3485 |
|
3490 | |||
3486 | self.putData(data) |
|
3491 | self.putData(data) | |
3487 |
|
3492 | |||
3488 | if (datatime - self.__initime) >= self.__integrationtime: |
|
3493 | if (datatime - self.__initime) >= self.__integrationtime: | |
3489 | avgdata, n = self.pushData() |
|
3494 | avgdata, n = self.pushData() | |
3490 | self.n = n |
|
3495 | self.n = n | |
3491 | self.__dataReady = True |
|
3496 | self.__dataReady = True | |
3492 |
|
3497 | |||
3493 | return avgdata |
|
3498 | return avgdata | |
3494 |
|
3499 | |||
3495 | def integrateByStride(self, data, datatime): |
|
3500 | def integrateByStride(self, data, datatime): | |
3496 | # print data |
|
3501 | # print data | |
3497 | if self.__profIndex == 0: |
|
3502 | if self.__profIndex == 0: | |
3498 | self.__buffer = [[data.copy(), datatime]] |
|
3503 | self.__buffer = [[data.copy(), datatime]] | |
3499 | else: |
|
3504 | else: | |
3500 | self.__buffer.append([data.copy(),datatime]) |
|
3505 | self.__buffer.append([data.copy(),datatime]) | |
3501 | self.__profIndex += 1 |
|
3506 | self.__profIndex += 1 | |
3502 | self.__dataReady = False |
|
3507 | self.__dataReady = False | |
3503 |
|
3508 | |||
3504 | if self.__profIndex == self.n * self.stride : |
|
3509 | if self.__profIndex == self.n * self.stride : | |
3505 | self.__dataToPutStride = True |
|
3510 | self.__dataToPutStride = True | |
3506 | self.__profIndexStride = 0 |
|
3511 | self.__profIndexStride = 0 | |
3507 | self.__profIndex = 0 |
|
3512 | self.__profIndex = 0 | |
3508 | self.__bufferStride = [] |
|
3513 | self.__bufferStride = [] | |
3509 | for i in range(self.stride): |
|
3514 | for i in range(self.stride): | |
3510 | current = self.__buffer[i::self.stride] |
|
3515 | current = self.__buffer[i::self.stride] | |
3511 | data = numpy.sum([t[0] for t in current], axis=0) |
|
3516 | data = numpy.sum([t[0] for t in current], axis=0) | |
3512 | avgdatatime = numpy.average([t[1] for t in current]) |
|
3517 | avgdatatime = numpy.average([t[1] for t in current]) | |
3513 | # print data |
|
3518 | # print data | |
3514 | self.__bufferStride.append((data, avgdatatime)) |
|
3519 | self.__bufferStride.append((data, avgdatatime)) | |
3515 |
|
3520 | |||
3516 | if self.__dataToPutStride: |
|
3521 | if self.__dataToPutStride: | |
3517 | self.__dataReady = True |
|
3522 | self.__dataReady = True | |
3518 | self.__profIndexStride += 1 |
|
3523 | self.__profIndexStride += 1 | |
3519 | if self.__profIndexStride == self.stride: |
|
3524 | if self.__profIndexStride == self.stride: | |
3520 | self.__dataToPutStride = False |
|
3525 | self.__dataToPutStride = False | |
3521 | # print self.__bufferStride[self.__profIndexStride - 1] |
|
3526 | # print self.__bufferStride[self.__profIndexStride - 1] | |
3522 | # raise |
|
3527 | # raise | |
3523 | return self.__bufferStride[self.__profIndexStride - 1] |
|
3528 | return self.__bufferStride[self.__profIndexStride - 1] | |
3524 |
|
3529 | |||
3525 |
|
3530 | |||
3526 | return None, None |
|
3531 | return None, None | |
3527 |
|
3532 | |||
3528 | def integrate(self, data, datatime=None): |
|
3533 | def integrate(self, data, datatime=None): | |
3529 |
|
3534 | |||
3530 | if self.__initime == None: |
|
3535 | if self.__initime == None: | |
3531 | self.__initime = datatime |
|
3536 | self.__initime = datatime | |
3532 |
|
3537 | |||
3533 | if self.__byTime: |
|
3538 | if self.__byTime: | |
3534 | avgdata = self.byTime(data, datatime) |
|
3539 | avgdata = self.byTime(data, datatime) | |
3535 | else: |
|
3540 | else: | |
3536 | avgdata = self.byProfiles(data) |
|
3541 | avgdata = self.byProfiles(data) | |
3537 |
|
3542 | |||
3538 |
|
3543 | |||
3539 | self.__lastdatatime = datatime |
|
3544 | self.__lastdatatime = datatime | |
3540 |
|
3545 | |||
3541 | if avgdata is None: |
|
3546 | if avgdata is None: | |
3542 | return None, None |
|
3547 | return None, None | |
3543 |
|
3548 | |||
3544 | avgdatatime = self.__initime |
|
3549 | avgdatatime = self.__initime | |
3545 |
|
3550 | |||
3546 | deltatime = datatime - self.__lastdatatime |
|
3551 | deltatime = datatime - self.__lastdatatime | |
3547 |
|
3552 | |||
3548 | if not self.__withOverlapping: |
|
3553 | if not self.__withOverlapping: | |
3549 | self.__initime = datatime |
|
3554 | self.__initime = datatime | |
3550 | else: |
|
3555 | else: | |
3551 | self.__initime += deltatime |
|
3556 | self.__initime += deltatime | |
3552 |
|
3557 | |||
3553 | return avgdata, avgdatatime |
|
3558 | return avgdata, avgdatatime | |
3554 |
|
3559 | |||
3555 | def integrateByBlock(self, dataOut): |
|
3560 | def integrateByBlock(self, dataOut): | |
3556 |
|
3561 | |||
3557 | times = int(dataOut.data.shape[1]/self.n) |
|
3562 | times = int(dataOut.data.shape[1]/self.n) | |
3558 | avgdata = numpy.zeros((dataOut.nChannels, times, dataOut.nHeights), dtype=complex) |
|
3563 | avgdata = numpy.zeros((dataOut.nChannels, times, dataOut.nHeights), dtype=complex) | |
3559 |
|
3564 | |||
3560 | id_min = 0 |
|
3565 | id_min = 0 | |
3561 | id_max = self.n |
|
3566 | id_max = self.n | |
3562 |
|
3567 | |||
3563 | for i in range(times): |
|
3568 | for i in range(times): | |
3564 | junk = dataOut.data[:,id_min:id_max,:] |
|
3569 | junk = dataOut.data[:,id_min:id_max,:] | |
3565 | avgdata[:,i,:] = junk.sum(axis=1) |
|
3570 | avgdata[:,i,:] = junk.sum(axis=1) | |
3566 | id_min += self.n |
|
3571 | id_min += self.n | |
3567 | id_max += self.n |
|
3572 | id_max += self.n | |
3568 |
|
3573 | |||
3569 | timeInterval = dataOut.ippSeconds*self.n |
|
3574 | timeInterval = dataOut.ippSeconds*self.n | |
3570 | avgdatatime = (times - 1) * timeInterval + dataOut.utctime |
|
3575 | avgdatatime = (times - 1) * timeInterval + dataOut.utctime | |
3571 | self.__dataReady = True |
|
3576 | self.__dataReady = True | |
3572 | return avgdata, avgdatatime |
|
3577 | return avgdata, avgdatatime | |
3573 |
|
3578 | |||
3574 | def run(self, dataOut, n=None, timeInterval=None, stride=None, overlapping=False, byblock=False, **kwargs): |
|
3579 | def run(self, dataOut, n=None, timeInterval=None, stride=None, overlapping=False, byblock=False, **kwargs): | |
3575 |
|
3580 | |||
3576 | if not self.isConfig: |
|
3581 | if not self.isConfig: | |
3577 | self.setup(n=n, stride=stride, timeInterval=timeInterval, overlapping=overlapping, byblock=byblock, **kwargs) |
|
3582 | self.setup(n=n, stride=stride, timeInterval=timeInterval, overlapping=overlapping, byblock=byblock, **kwargs) | |
3578 | self.isConfig = True |
|
3583 | self.isConfig = True | |
3579 |
|
3584 | |||
3580 | if dataOut.flagDataAsBlock: |
|
3585 | if dataOut.flagDataAsBlock: | |
3581 | """ |
|
3586 | """ | |
3582 | Si la data es leida por bloques, dimension = [nChannels, nProfiles, nHeis] |
|
3587 | Si la data es leida por bloques, dimension = [nChannels, nProfiles, nHeis] | |
3583 | """ |
|
3588 | """ | |
3584 |
|
3589 | |||
3585 | avgdata, avgdatatime = self.integrateByBlock(dataOut) |
|
3590 | avgdata, avgdatatime = self.integrateByBlock(dataOut) | |
3586 | dataOut.nProfiles /= self.n |
|
3591 | dataOut.nProfiles /= self.n | |
3587 | else: |
|
3592 | else: | |
3588 | if stride is None: |
|
3593 | if stride is None: | |
3589 | avgdata, avgdatatime = self.integrate(dataOut.data, dataOut.utctime) |
|
3594 | avgdata, avgdatatime = self.integrate(dataOut.data, dataOut.utctime) | |
3590 | else: |
|
3595 | else: | |
3591 | avgdata, avgdatatime = self.integrateByStride(dataOut.data, dataOut.utctime) |
|
3596 | avgdata, avgdatatime = self.integrateByStride(dataOut.data, dataOut.utctime) | |
3592 |
|
3597 | |||
3593 |
|
3598 | |||
3594 | # dataOut.timeInterval *= n |
|
3599 | # dataOut.timeInterval *= n | |
3595 | dataOut.flagNoData = True |
|
3600 | dataOut.flagNoData = True | |
3596 |
|
3601 | |||
3597 | if self.__dataReady: |
|
3602 | if self.__dataReady: | |
3598 | dataOut.data = avgdata |
|
3603 | dataOut.data = avgdata | |
3599 | if not dataOut.flagCohInt: |
|
3604 | if not dataOut.flagCohInt: | |
3600 | dataOut.nCohInt *= self.n |
|
3605 | dataOut.nCohInt *= self.n | |
3601 | dataOut.flagCohInt = True |
|
3606 | dataOut.flagCohInt = True | |
3602 | dataOut.utctime = avgdatatime |
|
3607 | dataOut.utctime = avgdatatime | |
3603 | # print avgdata, avgdatatime |
|
3608 | # print avgdata, avgdatatime | |
3604 | # raise |
|
3609 | # raise | |
3605 | # dataOut.timeInterval = dataOut.ippSeconds * dataOut.nCohInt |
|
3610 | # dataOut.timeInterval = dataOut.ippSeconds * dataOut.nCohInt | |
3606 | dataOut.flagNoData = False |
|
3611 | dataOut.flagNoData = False | |
3607 | return dataOut |
|
3612 | return dataOut | |
3608 |
|
3613 | |||
3609 | class TimesCode(Operation): |
|
3614 | class TimesCode(Operation): | |
3610 | ''' |
|
3615 | ''' | |
3611 | Written by R. Flores |
|
3616 | Written by R. Flores | |
3612 | ''' |
|
3617 | ''' | |
3613 | """ |
|
3618 | """ | |
3614 |
|
3619 | |||
3615 | """ |
|
3620 | """ | |
3616 |
|
3621 | |||
3617 | def __init__(self, **kwargs): |
|
3622 | def __init__(self, **kwargs): | |
3618 |
|
3623 | |||
3619 | Operation.__init__(self, **kwargs) |
|
3624 | Operation.__init__(self, **kwargs) | |
3620 |
|
3625 | |||
3621 | def run(self,dataOut,code): |
|
3626 | def run(self,dataOut,code): | |
3622 |
|
3627 | |||
3623 | #code = numpy.repeat(code, repeats=osamp, axis=1) |
|
3628 | #code = numpy.repeat(code, repeats=osamp, axis=1) | |
3624 | nCodes = numpy.shape(code)[1] |
|
3629 | nCodes = numpy.shape(code)[1] | |
3625 | #nprofcode = dataOut.nProfiles//nCodes |
|
3630 | #nprofcode = dataOut.nProfiles//nCodes | |
3626 | code = numpy.array(code) |
|
3631 | code = numpy.array(code) | |
3627 | #print("nHeights",dataOut.nHeights) |
|
3632 | #print("nHeights",dataOut.nHeights) | |
3628 | #print("nheicode",nheicode) |
|
3633 | #print("nheicode",nheicode) | |
3629 | #print("Code.Shape",numpy.shape(code)) |
|
3634 | #print("Code.Shape",numpy.shape(code)) | |
3630 | #print("Code",code[0,:]) |
|
3635 | #print("Code",code[0,:]) | |
3631 | nheicode = dataOut.nHeights//nCodes |
|
3636 | nheicode = dataOut.nHeights//nCodes | |
3632 | res = dataOut.nHeights%nCodes |
|
3637 | res = dataOut.nHeights%nCodes | |
3633 | ''' |
|
3638 | ''' | |
3634 | buffer = numpy.zeros((dataOut.nChannels, |
|
3639 | buffer = numpy.zeros((dataOut.nChannels, | |
3635 | nprofcode, |
|
3640 | nprofcode, | |
3636 | nCodes, |
|
3641 | nCodes, | |
3637 | ndataOut.nHeights), |
|
3642 | ndataOut.nHeights), | |
3638 | dtype='complex') |
|
3643 | dtype='complex') | |
3639 | ''' |
|
3644 | ''' | |
3640 | #exit(1) |
|
3645 | #exit(1) | |
3641 | #for ipr in range(dataOut.nProfiles): |
|
3646 | #for ipr in range(dataOut.nProfiles): | |
3642 | #print(dataOut.nHeights) |
|
3647 | #print(dataOut.nHeights) | |
3643 | #print(dataOut.data[0,384-2:]) |
|
3648 | #print(dataOut.data[0,384-2:]) | |
3644 | #print(dataOut.profileIndex) |
|
3649 | #print(dataOut.profileIndex) | |
3645 | #print(dataOut.data[0,:2]) |
|
3650 | #print(dataOut.data[0,:2]) | |
3646 | #print(dataOut.data[0,0:64]) |
|
3651 | #print(dataOut.data[0,0:64]) | |
3647 | #print(dataOut.data[0,64:64+64]) |
|
3652 | #print(dataOut.data[0,64:64+64]) | |
3648 | #exit(1) |
|
3653 | #exit(1) | |
3649 | for ich in range(dataOut.nChannels): |
|
3654 | for ich in range(dataOut.nChannels): | |
3650 | for ihe in range(nheicode): |
|
3655 | for ihe in range(nheicode): | |
3651 | #print(ihe*nCodes) |
|
3656 | #print(ihe*nCodes) | |
3652 | #print((ihe+1)*nCodes) |
|
3657 | #print((ihe+1)*nCodes) | |
3653 | #dataOut.data[ich,ipr,ihe*nCodes:nCodes*(ihe+1)] |
|
3658 | #dataOut.data[ich,ipr,ihe*nCodes:nCodes*(ihe+1)] | |
3654 | #code[ipr,:] |
|
3659 | #code[ipr,:] | |
3655 | #print("before",dataOut.data[ich,ipr,ihe*nCodes:nCodes*(ihe+1)]) |
|
3660 | #print("before",dataOut.data[ich,ipr,ihe*nCodes:nCodes*(ihe+1)]) | |
3656 | #dataOut.data[ich,ipr,ihe*nCodes:nCodes*(ihe+1)] = numpy.prod([dataOut.data[ich,ipr,ihe*nCodes:nCodes*(ihe+1)],code[ipr,:]],axis=0) |
|
3661 | #dataOut.data[ich,ipr,ihe*nCodes:nCodes*(ihe+1)] = numpy.prod([dataOut.data[ich,ipr,ihe*nCodes:nCodes*(ihe+1)],code[ipr,:]],axis=0) | |
3657 | dataOut.data[ich,ihe*nCodes:nCodes*(ihe+1)] = numpy.prod([dataOut.data[ich,ihe*nCodes:nCodes*(ihe+1)],code[dataOut.profileIndex,:]],axis=0) |
|
3662 | dataOut.data[ich,ihe*nCodes:nCodes*(ihe+1)] = numpy.prod([dataOut.data[ich,ihe*nCodes:nCodes*(ihe+1)],code[dataOut.profileIndex,:]],axis=0) | |
3658 |
|
3663 | |||
3659 | #print("after",dataOut.data[ich,ipr,ihe*nCodes:nCodes*(ihe+1)]) |
|
3664 | #print("after",dataOut.data[ich,ipr,ihe*nCodes:nCodes*(ihe+1)]) | |
3660 | #exit(1) |
|
3665 | #exit(1) | |
3661 | #print(dataOut.data[0,:2]) |
|
3666 | #print(dataOut.data[0,:2]) | |
3662 | #exit(1) |
|
3667 | #exit(1) | |
3663 | #print(nheicode) |
|
3668 | #print(nheicode) | |
3664 | #print((nheicode)*nCodes) |
|
3669 | #print((nheicode)*nCodes) | |
3665 | #print(((nheicode)*nCodes)+res) |
|
3670 | #print(((nheicode)*nCodes)+res) | |
3666 | if res != 0: |
|
3671 | if res != 0: | |
3667 | for ich in range(dataOut.nChannels): |
|
3672 | for ich in range(dataOut.nChannels): | |
3668 | dataOut.data[ich,nheicode*nCodes:] = numpy.prod([dataOut.data[ich,nheicode*nCodes:],code[dataOut.profileIndex,:res]],axis=0) |
|
3673 | dataOut.data[ich,nheicode*nCodes:] = numpy.prod([dataOut.data[ich,nheicode*nCodes:],code[dataOut.profileIndex,:res]],axis=0) | |
3669 |
|
3674 | |||
3670 | #pass |
|
3675 | #pass | |
3671 | #print(dataOut.data[0,384-2:]) |
|
3676 | #print(dataOut.data[0,384-2:]) | |
3672 | #exit(1) |
|
3677 | #exit(1) | |
3673 | #dataOut.data = numpy.mean(buffer,axis=1) |
|
3678 | #dataOut.data = numpy.mean(buffer,axis=1) | |
3674 | #print(numpy.shape(dataOut.data)) |
|
3679 | #print(numpy.shape(dataOut.data)) | |
3675 | #print(dataOut.nHeights) |
|
3680 | #print(dataOut.nHeights) | |
3676 | #dataOut.heightList = dataOut.heightList[0:nheicode] |
|
3681 | #dataOut.heightList = dataOut.heightList[0:nheicode] | |
3677 | #print(dataOut.nHeights) |
|
3682 | #print(dataOut.nHeights) | |
3678 | #dataOut.nHeights = numpy.shape(dataOut.data)[2] |
|
3683 | #dataOut.nHeights = numpy.shape(dataOut.data)[2] | |
3679 | #print(numpy.shape(dataOut.data)) |
|
3684 | #print(numpy.shape(dataOut.data)) | |
3680 | #exit(1) |
|
3685 | #exit(1) | |
3681 |
|
3686 | |||
3682 | return dataOut |
|
3687 | return dataOut | |
3683 |
|
3688 | |||
3684 | ''' |
|
3689 | ''' | |
3685 | class Spectrogram(Operation): |
|
3690 | class Spectrogram(Operation): | |
3686 | """ |
|
3691 | """ | |
3687 |
|
3692 | |||
3688 | """ |
|
3693 | """ | |
3689 |
|
3694 | |||
3690 | def __init__(self, **kwargs): |
|
3695 | def __init__(self, **kwargs): | |
3691 |
|
3696 | |||
3692 | Operation.__init__(self, **kwargs) |
|
3697 | Operation.__init__(self, **kwargs) | |
3693 |
|
3698 | |||
3694 |
|
3699 | |||
3695 |
|
3700 | |||
3696 | def run(self,dataOut): |
|
3701 | def run(self,dataOut): | |
3697 |
|
3702 | |||
3698 | import scipy |
|
3703 | import scipy | |
3699 |
|
3704 | |||
3700 |
|
3705 | |||
3701 |
|
3706 | |||
3702 | fs = 3200*1e-6 |
|
3707 | fs = 3200*1e-6 | |
3703 | fs = fs/64 |
|
3708 | fs = fs/64 | |
3704 | fs = 1/fs |
|
3709 | fs = 1/fs | |
3705 |
|
3710 | |||
3706 | nperseg=64 |
|
3711 | nperseg=64 | |
3707 | noverlap=48 |
|
3712 | noverlap=48 | |
3708 |
|
3713 | |||
3709 | f, t, Sxx = signal.spectrogram(x, fs, return_onesided=False, nperseg=nperseg, noverlap=noverlap, mode='complex') |
|
3714 | f, t, Sxx = signal.spectrogram(x, fs, return_onesided=False, nperseg=nperseg, noverlap=noverlap, mode='complex') | |
3710 |
|
3715 | |||
3711 |
|
3716 | |||
3712 | for ich in range(dataOut.nChannels): |
|
3717 | for ich in range(dataOut.nChannels): | |
3713 | for ihe in range(nheicode): |
|
3718 | for ihe in range(nheicode): | |
3714 |
|
3719 | |||
3715 |
|
3720 | |||
3716 | return dataOut |
|
3721 | return dataOut | |
3717 | ''' |
|
3722 | ''' | |
3718 |
|
3723 | |||
3719 |
|
3724 | |||
3720 | class RemoveDcHae(Operation): |
|
3725 | class RemoveDcHae(Operation): | |
3721 | ''' |
|
3726 | ''' | |
3722 | Written by R. Flores |
|
3727 | Written by R. Flores | |
3723 | ''' |
|
3728 | ''' | |
3724 | def __init__(self, **kwargs): |
|
3729 | def __init__(self, **kwargs): | |
3725 |
|
3730 | |||
3726 | Operation.__init__(self, **kwargs) |
|
3731 | Operation.__init__(self, **kwargs) | |
3727 | self.DcCounter = 0 |
|
3732 | self.DcCounter = 0 | |
3728 |
|
3733 | |||
3729 | def run(self, dataOut): |
|
3734 | def run(self, dataOut): | |
3730 |
|
3735 | |||
3731 | if self.DcCounter == 0: |
|
3736 | if self.DcCounter == 0: | |
3732 | dataOut.DcHae = numpy.zeros((dataOut.data.shape[0],320),dtype='complex') |
|
3737 | dataOut.DcHae = numpy.zeros((dataOut.data.shape[0],320),dtype='complex') | |
3733 | #dataOut.DcHae = [] |
|
3738 | #dataOut.DcHae = [] | |
3734 | self.DcCounter = 1 |
|
3739 | self.DcCounter = 1 | |
3735 |
|
3740 | |||
3736 | dataOut.dataaux = numpy.copy(dataOut.data) |
|
3741 | dataOut.dataaux = numpy.copy(dataOut.data) | |
3737 |
|
3742 | |||
3738 | #dataOut.DcHae += dataOut.dataaux[:,1666:1666+320] |
|
3743 | #dataOut.DcHae += dataOut.dataaux[:,1666:1666+320] | |
3739 | dataOut.DcHae += dataOut.dataaux[:,0:0+320] |
|
3744 | dataOut.DcHae += dataOut.dataaux[:,0:0+320] | |
3740 | hei = 1666 |
|
3745 | hei = 1666 | |
3741 | hei = 2000 |
|
3746 | hei = 2000 | |
3742 | hei = 1000 |
|
3747 | hei = 1000 | |
3743 | hei = 0 |
|
3748 | hei = 0 | |
3744 | #dataOut.DcHae = numpy.concatenate([dataOut.DcHae,dataOut.dataaux[0,hei]],axis = None) |
|
3749 | #dataOut.DcHae = numpy.concatenate([dataOut.DcHae,dataOut.dataaux[0,hei]],axis = None) | |
3745 |
|
3750 | |||
3746 |
|
3751 | |||
3747 |
|
3752 | |||
3748 | return dataOut |
|
3753 | return dataOut | |
3749 |
|
3754 | |||
3750 |
|
3755 | |||
3751 | class SSheightProfiles(Operation): |
|
3756 | class SSheightProfiles(Operation): | |
3752 |
|
3757 | |||
3753 | step = None |
|
3758 | step = None | |
3754 | nsamples = None |
|
3759 | nsamples = None | |
3755 | bufferShape = None |
|
3760 | bufferShape = None | |
3756 | profileShape = None |
|
3761 | profileShape = None | |
3757 | sshProfiles = None |
|
3762 | sshProfiles = None | |
3758 | profileIndex = None |
|
3763 | profileIndex = None | |
3759 |
|
3764 | |||
3760 | def __init__(self, **kwargs): |
|
3765 | def __init__(self, **kwargs): | |
3761 |
|
3766 | |||
3762 | Operation.__init__(self, **kwargs) |
|
3767 | Operation.__init__(self, **kwargs) | |
3763 | self.isConfig = False |
|
3768 | self.isConfig = False | |
3764 |
|
3769 | |||
3765 | def setup(self,dataOut ,step = None , nsamples = None): |
|
3770 | def setup(self,dataOut ,step = None , nsamples = None): | |
3766 |
|
3771 | |||
3767 | if step == None and nsamples == None: |
|
3772 | if step == None and nsamples == None: | |
3768 | #pass |
|
3773 | #pass | |
3769 | raise ValueError("step or nheights should be specified ...") |
|
3774 | raise ValueError("step or nheights should be specified ...") | |
3770 |
|
3775 | |||
3771 | self.step = step |
|
3776 | self.step = step | |
3772 | self.nsamples = nsamples |
|
3777 | self.nsamples = nsamples | |
3773 | self.__nChannels = dataOut.nChannels |
|
3778 | self.__nChannels = dataOut.nChannels | |
3774 | self.__nProfiles = dataOut.nProfiles |
|
3779 | self.__nProfiles = dataOut.nProfiles | |
3775 | self.__nHeis = dataOut.nHeights |
|
3780 | self.__nHeis = dataOut.nHeights | |
3776 | shape = dataOut.data.shape #nchannels, nprofiles, nsamples |
|
3781 | shape = dataOut.data.shape #nchannels, nprofiles, nsamples | |
3777 |
|
3782 | |||
3778 | residue = (shape[1] - self.nsamples) % self.step |
|
3783 | residue = (shape[1] - self.nsamples) % self.step | |
3779 | if residue != 0: |
|
3784 | if residue != 0: | |
3780 | 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)) |
|
3785 | 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)) | |
3781 |
|
3786 | |||
3782 | deltaHeight = dataOut.heightList[1] - dataOut.heightList[0] |
|
3787 | deltaHeight = dataOut.heightList[1] - dataOut.heightList[0] | |
3783 | numberProfile = self.nsamples |
|
3788 | numberProfile = self.nsamples | |
3784 | numberSamples = (shape[1] - self.nsamples)/self.step |
|
3789 | numberSamples = (shape[1] - self.nsamples)/self.step | |
3785 |
|
3790 | |||
3786 | self.bufferShape = int(shape[0]), int(numberSamples), int(numberProfile) # nchannels, nsamples , nprofiles |
|
3791 | self.bufferShape = int(shape[0]), int(numberSamples), int(numberProfile) # nchannels, nsamples , nprofiles | |
3787 | self.profileShape = int(shape[0]), int(numberProfile), int(numberSamples) # nchannels, nprofiles, nsamples |
|
3792 | self.profileShape = int(shape[0]), int(numberProfile), int(numberSamples) # nchannels, nprofiles, nsamples | |
3788 |
|
3793 | |||
3789 | self.buffer = numpy.zeros(self.bufferShape , dtype=complex) |
|
3794 | self.buffer = numpy.zeros(self.bufferShape , dtype=complex) | |
3790 | self.sshProfiles = numpy.zeros(self.profileShape, dtype=complex) |
|
3795 | self.sshProfiles = numpy.zeros(self.profileShape, dtype=complex) | |
3791 |
|
3796 | |||
3792 | def run(self, dataOut, step, nsamples, code = None, repeat = None): |
|
3797 | def run(self, dataOut, step, nsamples, code = None, repeat = None): | |
3793 | dataOut.flagNoData = True |
|
3798 | dataOut.flagNoData = True | |
3794 | profileIndex = None |
|
3799 | profileIndex = None | |
3795 | dataOut.flagDataAsBlock = False |
|
3800 | dataOut.flagDataAsBlock = False | |
3796 |
|
3801 | |||
3797 | if not self.isConfig: |
|
3802 | if not self.isConfig: | |
3798 | self.setup(dataOut, step=step , nsamples=nsamples) |
|
3803 | self.setup(dataOut, step=step , nsamples=nsamples) | |
3799 | self.isConfig = True |
|
3804 | self.isConfig = True | |
3800 |
|
3805 | |||
3801 | if code is not None: |
|
3806 | if code is not None: | |
3802 | code = numpy.array(code) |
|
3807 | code = numpy.array(code) | |
3803 | code_block = code |
|
3808 | code_block = code | |
3804 |
|
3809 | |||
3805 | if repeat is not None: |
|
3810 | if repeat is not None: | |
3806 | code_block = numpy.repeat(code_block, repeats=repeat, axis=1) |
|
3811 | code_block = numpy.repeat(code_block, repeats=repeat, axis=1) | |
3807 |
|
3812 | |||
3808 | for i in range(self.buffer.shape[1]): |
|
3813 | for i in range(self.buffer.shape[1]): | |
3809 | if code is not None: |
|
3814 | if code is not None: | |
3810 | #self.buffer[:,i] = dataOut.data[:,i*self.step:i*self.step + self.nsamples]*code_block[dataOut.profileIndex,:] |
|
3815 | #self.buffer[:,i] = dataOut.data[:,i*self.step:i*self.step + self.nsamples]*code_block[dataOut.profileIndex,:] | |
3811 | self.buffer[:,i] = dataOut.data[:,i*self.step:i*self.step + self.nsamples]*code_block |
|
3816 | self.buffer[:,i] = dataOut.data[:,i*self.step:i*self.step + self.nsamples]*code_block | |
3812 | else: |
|
3817 | else: | |
3813 | self.buffer[:,i] = dataOut.data[:,i*self.step:i*self.step + self.nsamples]#*code[dataOut.profileIndex,:] |
|
3818 | self.buffer[:,i] = dataOut.data[:,i*self.step:i*self.step + self.nsamples]#*code[dataOut.profileIndex,:] | |
3814 |
|
3819 | |||
3815 | for j in range(self.buffer.shape[0]): |
|
3820 | for j in range(self.buffer.shape[0]): | |
3816 | self.sshProfiles[j] = numpy.transpose(self.buffer[j]) |
|
3821 | self.sshProfiles[j] = numpy.transpose(self.buffer[j]) | |
3817 |
|
3822 | |||
3818 | profileIndex = self.nsamples |
|
3823 | profileIndex = self.nsamples | |
3819 | deltaHeight = dataOut.heightList[1] - dataOut.heightList[0] |
|
3824 | deltaHeight = dataOut.heightList[1] - dataOut.heightList[0] | |
3820 | ippSeconds = (deltaHeight*1.0e-6)/(0.15) |
|
3825 | ippSeconds = (deltaHeight*1.0e-6)/(0.15) | |
3821 |
|
3826 | |||
3822 | try: |
|
3827 | try: | |
3823 | if dataOut.concat_m is not None: |
|
3828 | if dataOut.concat_m is not None: | |
3824 | ippSeconds= ippSeconds/float(dataOut.concat_m) |
|
3829 | ippSeconds= ippSeconds/float(dataOut.concat_m) | |
3825 | except: |
|
3830 | except: | |
3826 | pass |
|
3831 | pass | |
3827 |
|
3832 | |||
3828 | dataOut.data = self.sshProfiles |
|
3833 | dataOut.data = self.sshProfiles | |
3829 | dataOut.flagNoData = False |
|
3834 | dataOut.flagNoData = False | |
3830 | dataOut.heightList = numpy.arange(self.buffer.shape[1]) *self.step*deltaHeight + dataOut.heightList[0] |
|
3835 | dataOut.heightList = numpy.arange(self.buffer.shape[1]) *self.step*deltaHeight + dataOut.heightList[0] | |
3831 | dataOut.nProfiles = int(dataOut.nProfiles*self.nsamples) |
|
3836 | dataOut.nProfiles = int(dataOut.nProfiles*self.nsamples) | |
3832 |
|
3837 | |||
3833 | dataOut.profileIndex = profileIndex |
|
3838 | dataOut.profileIndex = profileIndex | |
3834 | dataOut.flagDataAsBlock = True |
|
3839 | dataOut.flagDataAsBlock = True | |
3835 | dataOut.ippSeconds = ippSeconds |
|
3840 | dataOut.ippSeconds = ippSeconds | |
3836 | dataOut.step = self.step |
|
3841 | dataOut.step = self.step | |
3837 |
|
3842 | |||
3838 | return dataOut |
|
3843 | return dataOut | |
3839 |
|
3844 | |||
3840 | class removeDCHAE(Operation): |
|
3845 | class removeDCHAE(Operation): | |
3841 |
|
3846 | |||
3842 | def run(self, dataOut, minHei, maxHei): |
|
3847 | def run(self, dataOut, minHei, maxHei): | |
3843 |
|
3848 | |||
3844 | heights = dataOut.heightList |
|
3849 | heights = dataOut.heightList | |
3845 |
|
3850 | |||
3846 | inda = numpy.where(heights >= minHei) |
|
3851 | inda = numpy.where(heights >= minHei) | |
3847 | indb = numpy.where(heights <= maxHei) |
|
3852 | indb = numpy.where(heights <= maxHei) | |
3848 |
|
3853 | |||
3849 | minIndex = inda[0][0] |
|
3854 | minIndex = inda[0][0] | |
3850 | maxIndex = indb[0][-1] |
|
3855 | maxIndex = indb[0][-1] | |
3851 |
|
3856 | |||
3852 | dc = numpy.average(dataOut.data[:,minIndex:maxIndex],axis=1) |
|
3857 | dc = numpy.average(dataOut.data[:,minIndex:maxIndex],axis=1) | |
3853 | #print(dc.shape) |
|
3858 | #print(dc.shape) | |
3854 | dataOut.data = dataOut.data - dc[:,None] |
|
3859 | dataOut.data = dataOut.data - dc[:,None] | |
3855 | #print(aux.shape) |
|
3860 | #print(aux.shape) | |
3856 | #exit(1) |
|
3861 | #exit(1) | |
3857 |
|
3862 | |||
3858 | return dataOut |
|
3863 | return dataOut | |
3859 |
|
3864 | |||
3860 | class Decoder(Operation): |
|
3865 | class Decoder(Operation): | |
3861 |
|
3866 | |||
3862 | isConfig = False |
|
3867 | isConfig = False | |
3863 | __profIndex = 0 |
|
3868 | __profIndex = 0 | |
3864 |
|
3869 | |||
3865 | code = None |
|
3870 | code = None | |
3866 |
|
3871 | |||
3867 | nCode = None |
|
3872 | nCode = None | |
3868 | nBaud = None |
|
3873 | nBaud = None | |
3869 |
|
3874 | |||
3870 | def __init__(self, **kwargs): |
|
3875 | def __init__(self, **kwargs): | |
3871 |
|
3876 | |||
3872 | Operation.__init__(self, **kwargs) |
|
3877 | Operation.__init__(self, **kwargs) | |
3873 |
|
3878 | |||
3874 | self.times = None |
|
3879 | self.times = None | |
3875 | self.osamp = None |
|
3880 | self.osamp = None | |
3876 | # self.__setValues = False |
|
3881 | # self.__setValues = False | |
3877 | self.isConfig = False |
|
3882 | self.isConfig = False | |
3878 | self.setupReq = False |
|
3883 | self.setupReq = False | |
3879 | def setup(self, code, osamp, dataOut): |
|
3884 | def setup(self, code, osamp, dataOut): | |
3880 |
|
3885 | |||
3881 | self.__profIndex = 0 |
|
3886 | self.__profIndex = 0 | |
3882 |
|
3887 | |||
3883 | self.code = code |
|
3888 | self.code = code | |
3884 |
|
3889 | |||
3885 | self.nCode = len(code) |
|
3890 | self.nCode = len(code) | |
3886 | self.nBaud = len(code[0]) |
|
3891 | self.nBaud = len(code[0]) | |
3887 |
|
3892 | |||
3888 | if (osamp != None) and (osamp >1): |
|
3893 | if (osamp != None) and (osamp >1): | |
3889 | self.osamp = osamp |
|
3894 | self.osamp = osamp | |
3890 | self.code = numpy.repeat(code, repeats=self.osamp, axis=1) |
|
3895 | self.code = numpy.repeat(code, repeats=self.osamp, axis=1) | |
3891 | self.nBaud = self.nBaud*self.osamp |
|
3896 | self.nBaud = self.nBaud*self.osamp | |
3892 |
|
3897 | |||
3893 | self.__nChannels = dataOut.nChannels |
|
3898 | self.__nChannels = dataOut.nChannels | |
3894 | self.__nProfiles = dataOut.nProfiles |
|
3899 | self.__nProfiles = dataOut.nProfiles | |
3895 | self.__nHeis = dataOut.nHeights |
|
3900 | self.__nHeis = dataOut.nHeights | |
3896 |
|
3901 | |||
3897 | if self.__nHeis < self.nBaud: |
|
3902 | if self.__nHeis < self.nBaud: | |
3898 | raise ValueError('Number of heights (%d) should be greater than number of bauds (%d)' %(self.__nHeis, self.nBaud)) |
|
3903 | raise ValueError('Number of heights (%d) should be greater than number of bauds (%d)' %(self.__nHeis, self.nBaud)) | |
3899 |
|
3904 | |||
3900 | #Frequency |
|
3905 | #Frequency | |
3901 | __codeBuffer = numpy.zeros((self.nCode, self.__nHeis), dtype=complex) |
|
3906 | __codeBuffer = numpy.zeros((self.nCode, self.__nHeis), dtype=complex) | |
3902 |
|
3907 | |||
3903 | __codeBuffer[:,0:self.nBaud] = self.code |
|
3908 | __codeBuffer[:,0:self.nBaud] = self.code | |
3904 |
|
3909 | |||
3905 | self.fft_code = numpy.conj(numpy.fft.fft(__codeBuffer, axis=1)) |
|
3910 | self.fft_code = numpy.conj(numpy.fft.fft(__codeBuffer, axis=1)) | |
3906 |
|
3911 | |||
3907 | if dataOut.flagDataAsBlock: |
|
3912 | if dataOut.flagDataAsBlock: | |
3908 |
|
3913 | |||
3909 | self.ndatadec = self.__nHeis #- self.nBaud + 1 |
|
3914 | self.ndatadec = self.__nHeis #- self.nBaud + 1 | |
3910 |
|
3915 | |||
3911 | self.datadecTime = numpy.zeros((self.__nChannels, self.__nProfiles, self.ndatadec), dtype=complex) |
|
3916 | self.datadecTime = numpy.zeros((self.__nChannels, self.__nProfiles, self.ndatadec), dtype=complex) | |
3912 |
|
3917 | |||
3913 | else: |
|
3918 | else: | |
3914 |
|
3919 | |||
3915 | #Time |
|
3920 | #Time | |
3916 | self.ndatadec = self.__nHeis #- self.nBaud + 1 |
|
3921 | self.ndatadec = self.__nHeis #- self.nBaud + 1 | |
3917 |
|
3922 | |||
3918 |
|
3923 | |||
3919 | self.datadecTime = numpy.zeros((self.__nChannels, self.ndatadec), dtype=complex) |
|
3924 | self.datadecTime = numpy.zeros((self.__nChannels, self.ndatadec), dtype=complex) | |
3920 |
|
3925 | |||
3921 | def __convolutionInFreq(self, data): |
|
3926 | def __convolutionInFreq(self, data): | |
3922 |
|
3927 | |||
3923 | fft_code = self.fft_code[self.__profIndex].reshape(1,-1) |
|
3928 | fft_code = self.fft_code[self.__profIndex].reshape(1,-1) | |
3924 |
|
3929 | |||
3925 | fft_data = numpy.fft.fft(data, axis=1) |
|
3930 | fft_data = numpy.fft.fft(data, axis=1) | |
3926 |
|
3931 | |||
3927 | conv = fft_data*fft_code |
|
3932 | conv = fft_data*fft_code | |
3928 |
|
3933 | |||
3929 | data = numpy.fft.ifft(conv,axis=1) |
|
3934 | data = numpy.fft.ifft(conv,axis=1) | |
3930 |
|
3935 | |||
3931 | return data |
|
3936 | return data | |
3932 |
|
3937 | |||
3933 | def __convolutionInFreqOpt(self, data): |
|
3938 | def __convolutionInFreqOpt(self, data): | |
3934 |
|
3939 | |||
3935 | raise NotImplementedError |
|
3940 | raise NotImplementedError | |
3936 |
|
3941 | |||
3937 | def __convolutionInTime(self, data): |
|
3942 | def __convolutionInTime(self, data): | |
3938 |
|
3943 | |||
3939 | code = self.code[self.__profIndex] |
|
3944 | code = self.code[self.__profIndex] | |
3940 | for i in range(self.__nChannels): |
|
3945 | for i in range(self.__nChannels): | |
3941 | #aux=numpy.correlate(data[i,:], code, mode='full') |
|
3946 | #aux=numpy.correlate(data[i,:], code, mode='full') | |
3942 | #print(numpy.shape(aux)) |
|
3947 | #print(numpy.shape(aux)) | |
3943 | #print(numpy.shape(data[i,:])) |
|
3948 | #print(numpy.shape(data[i,:])) | |
3944 | #print(numpy.shape(code)) |
|
3949 | #print(numpy.shape(code)) | |
3945 | #exit(1) |
|
3950 | #exit(1) | |
3946 | self.datadecTime[i,:] = numpy.correlate(data[i,:], code, mode='full')[self.nBaud-1:] |
|
3951 | self.datadecTime[i,:] = numpy.correlate(data[i,:], code, mode='full')[self.nBaud-1:] | |
3947 |
|
3952 | |||
3948 | return self.datadecTime |
|
3953 | return self.datadecTime | |
3949 |
|
3954 | |||
3950 | def __convolutionByBlockInTime(self, data): |
|
3955 | def __convolutionByBlockInTime(self, data): | |
3951 |
|
3956 | |||
3952 | repetitions = int(self.__nProfiles / self.nCode) |
|
3957 | repetitions = int(self.__nProfiles / self.nCode) | |
3953 | junk = numpy.lib.stride_tricks.as_strided(self.code, (repetitions, self.code.size), (0, self.code.itemsize)) |
|
3958 | junk = numpy.lib.stride_tricks.as_strided(self.code, (repetitions, self.code.size), (0, self.code.itemsize)) | |
3954 | junk = junk.flatten() |
|
3959 | junk = junk.flatten() | |
3955 | code_block = numpy.reshape(junk, (self.nCode*repetitions, self.nBaud)) |
|
3960 | code_block = numpy.reshape(junk, (self.nCode*repetitions, self.nBaud)) | |
3956 | profilesList = range(self.__nProfiles) |
|
3961 | profilesList = range(self.__nProfiles) | |
3957 | #print(numpy.shape(self.datadecTime)) |
|
3962 | #print(numpy.shape(self.datadecTime)) | |
3958 | #print(numpy.shape(data)) |
|
3963 | #print(numpy.shape(data)) | |
3959 | for i in range(self.__nChannels): |
|
3964 | for i in range(self.__nChannels): | |
3960 | for j in profilesList: |
|
3965 | for j in profilesList: | |
3961 | self.datadecTime[i,j,:] = numpy.correlate(data[i,j,:], code_block[j,:], mode='full')[self.nBaud-1:] |
|
3966 | self.datadecTime[i,j,:] = numpy.correlate(data[i,j,:], code_block[j,:], mode='full')[self.nBaud-1:] | |
3962 | return self.datadecTime |
|
3967 | return self.datadecTime | |
3963 |
|
3968 | |||
3964 | def __convolutionByBlockInFreq(self, data): |
|
3969 | def __convolutionByBlockInFreq(self, data): | |
3965 |
|
3970 | |||
3966 | raise NotImplementedError("Decoder by frequency fro Blocks not implemented") |
|
3971 | raise NotImplementedError("Decoder by frequency fro Blocks not implemented") | |
3967 |
|
3972 | |||
3968 |
|
3973 | |||
3969 | fft_code = self.fft_code[self.__profIndex].reshape(1,-1) |
|
3974 | fft_code = self.fft_code[self.__profIndex].reshape(1,-1) | |
3970 |
|
3975 | |||
3971 | fft_data = numpy.fft.fft(data, axis=2) |
|
3976 | fft_data = numpy.fft.fft(data, axis=2) | |
3972 |
|
3977 | |||
3973 | conv = fft_data*fft_code |
|
3978 | conv = fft_data*fft_code | |
3974 |
|
3979 | |||
3975 | data = numpy.fft.ifft(conv,axis=2) |
|
3980 | data = numpy.fft.ifft(conv,axis=2) | |
3976 |
|
3981 | |||
3977 | return data |
|
3982 | return data | |
3978 |
|
3983 | |||
3979 |
|
3984 | |||
3980 | def run(self, dataOut, code=None, nCode=None, nBaud=None, mode = 0, osamp=None, times=None): |
|
3985 | def run(self, dataOut, code=None, nCode=None, nBaud=None, mode = 0, osamp=None, times=None): | |
3981 |
|
3986 | |||
3982 | if dataOut.flagDecodeData: |
|
3987 | if dataOut.flagDecodeData: | |
3983 | print("This data is already decoded, recoding again ...") |
|
3988 | print("This data is already decoded, recoding again ...") | |
3984 |
|
3989 | |||
3985 | if not self.isConfig: |
|
3990 | if not self.isConfig: | |
3986 |
|
3991 | |||
3987 | if code is None: |
|
3992 | if code is None: | |
3988 | if dataOut.code is None: |
|
3993 | if dataOut.code is None: | |
3989 | raise ValueError("Code could not be read from %s instance. Enter a value in Code parameter" %dataOut.type) |
|
3994 | raise ValueError("Code could not be read from %s instance. Enter a value in Code parameter" %dataOut.type) | |
3990 |
|
3995 | |||
3991 | code = dataOut.code |
|
3996 | code = dataOut.code | |
3992 | else: |
|
3997 | else: | |
3993 | code = numpy.array(code).reshape(nCode,nBaud) |
|
3998 | code = numpy.array(code).reshape(nCode,nBaud) | |
3994 | self.setup(code, osamp, dataOut) |
|
3999 | self.setup(code, osamp, dataOut) | |
3995 |
|
4000 | |||
3996 | self.isConfig = True |
|
4001 | self.isConfig = True | |
3997 |
|
4002 | |||
3998 | if mode == 3: |
|
4003 | if mode == 3: | |
3999 | sys.stderr.write("Decoder Warning: mode=%d is not valid, using mode=0\n" %mode) |
|
4004 | sys.stderr.write("Decoder Warning: mode=%d is not valid, using mode=0\n" %mode) | |
4000 |
|
4005 | |||
4001 | if times != None: |
|
4006 | if times != None: | |
4002 | sys.stderr.write("Decoder Warning: Argument 'times' in not used anymore\n") |
|
4007 | sys.stderr.write("Decoder Warning: Argument 'times' in not used anymore\n") | |
4003 |
|
4008 | |||
4004 | if self.code is None: |
|
4009 | if self.code is None: | |
4005 | print("Fail decoding: Code is not defined.") |
|
4010 | print("Fail decoding: Code is not defined.") | |
4006 | return |
|
4011 | return | |
4007 |
|
4012 | |||
4008 | self.__nProfiles = dataOut.nProfiles |
|
4013 | self.__nProfiles = dataOut.nProfiles | |
4009 | datadec = None |
|
4014 | datadec = None | |
4010 |
|
4015 | |||
4011 | if mode == 3: |
|
4016 | if mode == 3: | |
4012 | mode = 0 |
|
4017 | mode = 0 | |
4013 |
|
4018 | |||
4014 | if dataOut.flagDataAsBlock: |
|
4019 | if dataOut.flagDataAsBlock: | |
4015 | """ |
|
4020 | """ | |
4016 | Decoding when data have been read as block, |
|
4021 | Decoding when data have been read as block, | |
4017 | """ |
|
4022 | """ | |
4018 |
|
4023 | |||
4019 | if mode == 0: |
|
4024 | if mode == 0: | |
4020 | datadec = self.__convolutionByBlockInTime(dataOut.data) |
|
4025 | datadec = self.__convolutionByBlockInTime(dataOut.data) | |
4021 | if mode == 1: |
|
4026 | if mode == 1: | |
4022 | datadec = self.__convolutionByBlockInFreq(dataOut.data) |
|
4027 | datadec = self.__convolutionByBlockInFreq(dataOut.data) | |
4023 | else: |
|
4028 | else: | |
4024 | """ |
|
4029 | """ | |
4025 | Decoding when data have been read profile by profile |
|
4030 | Decoding when data have been read profile by profile | |
4026 | """ |
|
4031 | """ | |
4027 | if mode == 0: |
|
4032 | if mode == 0: | |
4028 | datadec = self.__convolutionInTime(dataOut.data) |
|
4033 | datadec = self.__convolutionInTime(dataOut.data) | |
4029 |
|
4034 | |||
4030 | if mode == 1: |
|
4035 | if mode == 1: | |
4031 | datadec = self.__convolutionInFreq(dataOut.data) |
|
4036 | datadec = self.__convolutionInFreq(dataOut.data) | |
4032 |
|
4037 | |||
4033 | if mode == 2: |
|
4038 | if mode == 2: | |
4034 | datadec = self.__convolutionInFreqOpt(dataOut.data) |
|
4039 | datadec = self.__convolutionInFreqOpt(dataOut.data) | |
4035 |
|
4040 | |||
4036 | if datadec is None: |
|
4041 | if datadec is None: | |
4037 | raise ValueError("Codification mode selected is not valid: mode=%d. Try selecting 0 or 1" %mode) |
|
4042 | raise ValueError("Codification mode selected is not valid: mode=%d. Try selecting 0 or 1" %mode) | |
4038 |
|
4043 | |||
4039 | dataOut.code = self.code |
|
4044 | dataOut.code = self.code | |
4040 | dataOut.nCode = self.nCode |
|
4045 | dataOut.nCode = self.nCode | |
4041 | dataOut.nBaud = self.nBaud |
|
4046 | dataOut.nBaud = self.nBaud | |
4042 |
|
4047 | |||
4043 | dataOut.data = datadec |
|
4048 | dataOut.data = datadec | |
4044 | #print("before",dataOut.heightList) |
|
4049 | #print("before",dataOut.heightList) | |
4045 | dataOut.heightList = dataOut.heightList[0:datadec.shape[-1]] |
|
4050 | dataOut.heightList = dataOut.heightList[0:datadec.shape[-1]] | |
4046 | #print("after",dataOut.heightList) |
|
4051 | #print("after",dataOut.heightList) | |
4047 |
|
4052 | |||
4048 | dataOut.flagDecodeData = True #asumo q la data esta decodificada |
|
4053 | dataOut.flagDecodeData = True #asumo q la data esta decodificada | |
4049 |
|
4054 | |||
4050 | if self.__profIndex == self.nCode-1: |
|
4055 | if self.__profIndex == self.nCode-1: | |
4051 | self.__profIndex = 0 |
|
4056 | self.__profIndex = 0 | |
4052 | return dataOut |
|
4057 | return dataOut | |
4053 |
|
4058 | |||
4054 | self.__profIndex += 1 |
|
4059 | self.__profIndex += 1 | |
4055 |
|
4060 | |||
4056 | #print("SHAPE",numpy.shape(dataOut.data)) |
|
4061 | #print("SHAPE",numpy.shape(dataOut.data)) | |
4057 |
|
4062 | |||
4058 | return dataOut |
|
4063 | return dataOut | |
4059 | # dataOut.flagDeflipData = True #asumo q la data no esta sin flip |
|
4064 | # dataOut.flagDeflipData = True #asumo q la data no esta sin flip | |
4060 |
|
4065 | |||
4061 | class DecoderRoll(Operation): |
|
4066 | class DecoderRoll(Operation): | |
4062 |
|
4067 | |||
4063 | isConfig = False |
|
4068 | isConfig = False | |
4064 | __profIndex = 0 |
|
4069 | __profIndex = 0 | |
4065 |
|
4070 | |||
4066 | code = None |
|
4071 | code = None | |
4067 |
|
4072 | |||
4068 | nCode = None |
|
4073 | nCode = None | |
4069 | nBaud = None |
|
4074 | nBaud = None | |
4070 |
|
4075 | |||
4071 | def __init__(self, **kwargs): |
|
4076 | def __init__(self, **kwargs): | |
4072 |
|
4077 | |||
4073 | Operation.__init__(self, **kwargs) |
|
4078 | Operation.__init__(self, **kwargs) | |
4074 |
|
4079 | |||
4075 | self.times = None |
|
4080 | self.times = None | |
4076 | self.osamp = None |
|
4081 | self.osamp = None | |
4077 | # self.__setValues = False |
|
4082 | # self.__setValues = False | |
4078 | self.isConfig = False |
|
4083 | self.isConfig = False | |
4079 | self.setupReq = False |
|
4084 | self.setupReq = False | |
4080 | def setup(self, code, osamp, dataOut): |
|
4085 | def setup(self, code, osamp, dataOut): | |
4081 |
|
4086 | |||
4082 | self.__profIndex = 0 |
|
4087 | self.__profIndex = 0 | |
4083 |
|
4088 | |||
4084 |
|
4089 | |||
4085 | self.code = code |
|
4090 | self.code = code | |
4086 |
|
4091 | |||
4087 | self.nCode = len(code) |
|
4092 | self.nCode = len(code) | |
4088 | self.nBaud = len(code[0]) |
|
4093 | self.nBaud = len(code[0]) | |
4089 |
|
4094 | |||
4090 | if (osamp != None) and (osamp >1): |
|
4095 | if (osamp != None) and (osamp >1): | |
4091 | self.osamp = osamp |
|
4096 | self.osamp = osamp | |
4092 | self.code = numpy.repeat(code, repeats=self.osamp, axis=1) |
|
4097 | self.code = numpy.repeat(code, repeats=self.osamp, axis=1) | |
4093 | self.nBaud = self.nBaud*self.osamp |
|
4098 | self.nBaud = self.nBaud*self.osamp | |
4094 |
|
4099 | |||
4095 | self.__nChannels = dataOut.nChannels |
|
4100 | self.__nChannels = dataOut.nChannels | |
4096 | self.__nProfiles = dataOut.nProfiles |
|
4101 | self.__nProfiles = dataOut.nProfiles | |
4097 | self.__nHeis = dataOut.nHeights |
|
4102 | self.__nHeis = dataOut.nHeights | |
4098 |
|
4103 | |||
4099 | if self.__nHeis < self.nBaud: |
|
4104 | if self.__nHeis < self.nBaud: | |
4100 | raise ValueError('Number of heights (%d) should be greater than number of bauds (%d)' %(self.__nHeis, self.nBaud)) |
|
4105 | raise ValueError('Number of heights (%d) should be greater than number of bauds (%d)' %(self.__nHeis, self.nBaud)) | |
4101 |
|
4106 | |||
4102 | #Frequency |
|
4107 | #Frequency | |
4103 | __codeBuffer = numpy.zeros((self.nCode, self.__nHeis), dtype=complex) |
|
4108 | __codeBuffer = numpy.zeros((self.nCode, self.__nHeis), dtype=complex) | |
4104 |
|
4109 | |||
4105 | __codeBuffer[:,0:self.nBaud] = self.code |
|
4110 | __codeBuffer[:,0:self.nBaud] = self.code | |
4106 |
|
4111 | |||
4107 | self.fft_code = numpy.conj(numpy.fft.fft(__codeBuffer, axis=1)) |
|
4112 | self.fft_code = numpy.conj(numpy.fft.fft(__codeBuffer, axis=1)) | |
4108 |
|
4113 | |||
4109 | if dataOut.flagDataAsBlock: |
|
4114 | if dataOut.flagDataAsBlock: | |
4110 |
|
4115 | |||
4111 | self.ndatadec = self.__nHeis #- self.nBaud + 1 |
|
4116 | self.ndatadec = self.__nHeis #- self.nBaud + 1 | |
4112 |
|
4117 | |||
4113 | self.datadecTime = numpy.zeros((self.__nChannels, self.__nProfiles, self.ndatadec), dtype=complex) |
|
4118 | self.datadecTime = numpy.zeros((self.__nChannels, self.__nProfiles, self.ndatadec), dtype=complex) | |
4114 |
|
4119 | |||
4115 | else: |
|
4120 | else: | |
4116 |
|
4121 | |||
4117 | #Time |
|
4122 | #Time | |
4118 | self.ndatadec = self.__nHeis #- self.nBaud + 1 |
|
4123 | self.ndatadec = self.__nHeis #- self.nBaud + 1 | |
4119 |
|
4124 | |||
4120 |
|
4125 | |||
4121 | self.datadecTime = numpy.zeros((self.__nChannels, self.ndatadec), dtype=complex) |
|
4126 | self.datadecTime = numpy.zeros((self.__nChannels, self.ndatadec), dtype=complex) | |
4122 |
|
4127 | |||
4123 | def __convolutionInFreq(self, data): |
|
4128 | def __convolutionInFreq(self, data): | |
4124 |
|
4129 | |||
4125 | fft_code = self.fft_code[self.__profIndex].reshape(1,-1) |
|
4130 | fft_code = self.fft_code[self.__profIndex].reshape(1,-1) | |
4126 |
|
4131 | |||
4127 | fft_data = numpy.fft.fft(data, axis=1) |
|
4132 | fft_data = numpy.fft.fft(data, axis=1) | |
4128 |
|
4133 | |||
4129 | conv = fft_data*fft_code |
|
4134 | conv = fft_data*fft_code | |
4130 |
|
4135 | |||
4131 | data = numpy.fft.ifft(conv,axis=1) |
|
4136 | data = numpy.fft.ifft(conv,axis=1) | |
4132 |
|
4137 | |||
4133 | return data |
|
4138 | return data | |
4134 |
|
4139 | |||
4135 | def __convolutionInFreqOpt(self, data): |
|
4140 | def __convolutionInFreqOpt(self, data): | |
4136 |
|
4141 | |||
4137 | raise NotImplementedError |
|
4142 | raise NotImplementedError | |
4138 |
|
4143 | |||
4139 | def __convolutionInTime(self, data): |
|
4144 | def __convolutionInTime(self, data): | |
4140 |
|
4145 | |||
4141 | code = self.code[self.__profIndex] |
|
4146 | code = self.code[self.__profIndex] | |
4142 | #print("code",code[0,0]) |
|
4147 | #print("code",code[0,0]) | |
4143 | for i in range(self.__nChannels): |
|
4148 | for i in range(self.__nChannels): | |
4144 | #aux=numpy.correlate(data[i,:], code, mode='full') |
|
4149 | #aux=numpy.correlate(data[i,:], code, mode='full') | |
4145 | #print(numpy.shape(aux)) |
|
4150 | #print(numpy.shape(aux)) | |
4146 | #print(numpy.shape(data[i,:])) |
|
4151 | #print(numpy.shape(data[i,:])) | |
4147 | #print(numpy.shape(code)) |
|
4152 | #print(numpy.shape(code)) | |
4148 | #exit(1) |
|
4153 | #exit(1) | |
4149 | self.datadecTime[i,:] = numpy.correlate(data[i,:], code, mode='full')[self.nBaud-1:] |
|
4154 | self.datadecTime[i,:] = numpy.correlate(data[i,:], code, mode='full')[self.nBaud-1:] | |
4150 |
|
4155 | |||
4151 | return self.datadecTime |
|
4156 | return self.datadecTime | |
4152 |
|
4157 | |||
4153 | def __convolutionByBlockInTime(self, data): |
|
4158 | def __convolutionByBlockInTime(self, data): | |
4154 |
|
4159 | |||
4155 | repetitions = int(self.__nProfiles / self.nCode) |
|
4160 | repetitions = int(self.__nProfiles / self.nCode) | |
4156 | junk = numpy.lib.stride_tricks.as_strided(self.code, (repetitions, self.code.size), (0, self.code.itemsize)) |
|
4161 | junk = numpy.lib.stride_tricks.as_strided(self.code, (repetitions, self.code.size), (0, self.code.itemsize)) | |
4157 | junk = junk.flatten() |
|
4162 | junk = junk.flatten() | |
4158 | code_block = numpy.reshape(junk, (self.nCode*repetitions, self.nBaud)) |
|
4163 | code_block = numpy.reshape(junk, (self.nCode*repetitions, self.nBaud)) | |
4159 | profilesList = range(self.__nProfiles) |
|
4164 | profilesList = range(self.__nProfiles) | |
4160 | #print(numpy.shape(self.datadecTime)) |
|
4165 | #print(numpy.shape(self.datadecTime)) | |
4161 | #print(numpy.shape(data)) |
|
4166 | #print(numpy.shape(data)) | |
4162 | for i in range(self.__nChannels): |
|
4167 | for i in range(self.__nChannels): | |
4163 | for j in profilesList: |
|
4168 | for j in profilesList: | |
4164 | self.datadecTime[i,j,:] = numpy.correlate(data[i,j,:], code_block[j,:], mode='full')[self.nBaud-1:] |
|
4169 | self.datadecTime[i,j,:] = numpy.correlate(data[i,j,:], code_block[j,:], mode='full')[self.nBaud-1:] | |
4165 | return self.datadecTime |
|
4170 | return self.datadecTime | |
4166 |
|
4171 | |||
4167 | def __convolutionByBlockInFreq(self, data): |
|
4172 | def __convolutionByBlockInFreq(self, data): | |
4168 |
|
4173 | |||
4169 | raise NotImplementedError("Decoder by frequency fro Blocks not implemented") |
|
4174 | raise NotImplementedError("Decoder by frequency fro Blocks not implemented") | |
4170 |
|
4175 | |||
4171 |
|
4176 | |||
4172 | fft_code = self.fft_code[self.__profIndex].reshape(1,-1) |
|
4177 | fft_code = self.fft_code[self.__profIndex].reshape(1,-1) | |
4173 |
|
4178 | |||
4174 | fft_data = numpy.fft.fft(data, axis=2) |
|
4179 | fft_data = numpy.fft.fft(data, axis=2) | |
4175 |
|
4180 | |||
4176 | conv = fft_data*fft_code |
|
4181 | conv = fft_data*fft_code | |
4177 |
|
4182 | |||
4178 | data = numpy.fft.ifft(conv,axis=2) |
|
4183 | data = numpy.fft.ifft(conv,axis=2) | |
4179 |
|
4184 | |||
4180 | return data |
|
4185 | return data | |
4181 |
|
4186 | |||
4182 |
|
4187 | |||
4183 | def run(self, dataOut, code=None, nCode=None, nBaud=None, mode = 0, osamp=None, times=None): |
|
4188 | def run(self, dataOut, code=None, nCode=None, nBaud=None, mode = 0, osamp=None, times=None): | |
4184 |
|
4189 | |||
4185 | if dataOut.flagDecodeData: |
|
4190 | if dataOut.flagDecodeData: | |
4186 | print("This data is already decoded, recoding again ...") |
|
4191 | print("This data is already decoded, recoding again ...") | |
4187 |
|
4192 | |||
4188 |
|
4193 | |||
4189 | roll = 0 |
|
4194 | roll = 0 | |
4190 |
|
4195 | |||
4191 | if self.isConfig: |
|
4196 | if self.isConfig: | |
4192 | code = numpy.array(code) |
|
4197 | code = numpy.array(code) | |
4193 |
|
4198 | |||
4194 | code = numpy.roll(code,roll,axis=0) |
|
4199 | code = numpy.roll(code,roll,axis=0) | |
4195 | code = numpy.reshape(code,(5,100,64)) |
|
4200 | code = numpy.reshape(code,(5,100,64)) | |
4196 | block = dataOut.CurrentBlock%5 |
|
4201 | block = dataOut.CurrentBlock%5 | |
4197 | #code = code[block-1,:,:] #NormalizeDPPower |
|
4202 | #code = code[block-1,:,:] #NormalizeDPPower | |
4198 | code = code[block-1-1,:,:] #Next Day |
|
4203 | code = code[block-1-1,:,:] #Next Day | |
4199 | self.code = numpy.repeat(code, repeats=self.osamp, axis=1) |
|
4204 | self.code = numpy.repeat(code, repeats=self.osamp, axis=1) | |
4200 |
|
4205 | |||
4201 |
|
4206 | |||
4202 | if not self.isConfig: |
|
4207 | if not self.isConfig: | |
4203 |
|
4208 | |||
4204 | if code is None: |
|
4209 | if code is None: | |
4205 | if dataOut.code is None: |
|
4210 | if dataOut.code is None: | |
4206 | raise ValueError("Code could not be read from %s instance. Enter a value in Code parameter" %dataOut.type) |
|
4211 | raise ValueError("Code could not be read from %s instance. Enter a value in Code parameter" %dataOut.type) | |
4207 |
|
4212 | |||
4208 | code = dataOut.code |
|
4213 | code = dataOut.code | |
4209 | else: |
|
4214 | else: | |
4210 | code = numpy.array(code) |
|
4215 | code = numpy.array(code) | |
4211 |
|
4216 | |||
4212 | #roll = 29 |
|
4217 | #roll = 29 | |
4213 | code = numpy.roll(code,roll,axis=0) |
|
4218 | code = numpy.roll(code,roll,axis=0) | |
4214 | code = numpy.reshape(code,(5,100,64)) |
|
4219 | code = numpy.reshape(code,(5,100,64)) | |
4215 | block = dataOut.CurrentBlock%5 |
|
4220 | block = dataOut.CurrentBlock%5 | |
4216 | code = code[block-1-1,:,:] |
|
4221 | code = code[block-1-1,:,:] | |
4217 | #print(code.shape()) |
|
4222 | #print(code.shape()) | |
4218 | #exit(1) |
|
4223 | #exit(1) | |
4219 |
|
4224 | |||
4220 | code = numpy.array(code).reshape(nCode,nBaud) |
|
4225 | code = numpy.array(code).reshape(nCode,nBaud) | |
4221 | self.setup(code, osamp, dataOut) |
|
4226 | self.setup(code, osamp, dataOut) | |
4222 |
|
4227 | |||
4223 | self.isConfig = True |
|
4228 | self.isConfig = True | |
4224 |
|
4229 | |||
4225 | if mode == 3: |
|
4230 | if mode == 3: | |
4226 | sys.stderr.write("Decoder Warning: mode=%d is not valid, using mode=0\n" %mode) |
|
4231 | sys.stderr.write("Decoder Warning: mode=%d is not valid, using mode=0\n" %mode) | |
4227 |
|
4232 | |||
4228 | if times != None: |
|
4233 | if times != None: | |
4229 | sys.stderr.write("Decoder Warning: Argument 'times' in not used anymore\n") |
|
4234 | sys.stderr.write("Decoder Warning: Argument 'times' in not used anymore\n") | |
4230 |
|
4235 | |||
4231 | if self.code is None: |
|
4236 | if self.code is None: | |
4232 | print("Fail decoding: Code is not defined.") |
|
4237 | print("Fail decoding: Code is not defined.") | |
4233 | return |
|
4238 | return | |
4234 |
|
4239 | |||
4235 | self.__nProfiles = dataOut.nProfiles |
|
4240 | self.__nProfiles = dataOut.nProfiles | |
4236 | datadec = None |
|
4241 | datadec = None | |
4237 |
|
4242 | |||
4238 | if mode == 3: |
|
4243 | if mode == 3: | |
4239 | mode = 0 |
|
4244 | mode = 0 | |
4240 |
|
4245 | |||
4241 | if dataOut.flagDataAsBlock: |
|
4246 | if dataOut.flagDataAsBlock: | |
4242 | """ |
|
4247 | """ | |
4243 | Decoding when data have been read as block, |
|
4248 | Decoding when data have been read as block, | |
4244 | """ |
|
4249 | """ | |
4245 |
|
4250 | |||
4246 | if mode == 0: |
|
4251 | if mode == 0: | |
4247 | datadec = self.__convolutionByBlockInTime(dataOut.data) |
|
4252 | datadec = self.__convolutionByBlockInTime(dataOut.data) | |
4248 | if mode == 1: |
|
4253 | if mode == 1: | |
4249 | datadec = self.__convolutionByBlockInFreq(dataOut.data) |
|
4254 | datadec = self.__convolutionByBlockInFreq(dataOut.data) | |
4250 | else: |
|
4255 | else: | |
4251 | """ |
|
4256 | """ | |
4252 | Decoding when data have been read profile by profile |
|
4257 | Decoding when data have been read profile by profile | |
4253 | """ |
|
4258 | """ | |
4254 | if mode == 0: |
|
4259 | if mode == 0: | |
4255 | datadec = self.__convolutionInTime(dataOut.data) |
|
4260 | datadec = self.__convolutionInTime(dataOut.data) | |
4256 |
|
4261 | |||
4257 | if mode == 1: |
|
4262 | if mode == 1: | |
4258 | datadec = self.__convolutionInFreq(dataOut.data) |
|
4263 | datadec = self.__convolutionInFreq(dataOut.data) | |
4259 |
|
4264 | |||
4260 | if mode == 2: |
|
4265 | if mode == 2: | |
4261 | datadec = self.__convolutionInFreqOpt(dataOut.data) |
|
4266 | datadec = self.__convolutionInFreqOpt(dataOut.data) | |
4262 |
|
4267 | |||
4263 | if datadec is None: |
|
4268 | if datadec is None: | |
4264 | raise ValueError("Codification mode selected is not valid: mode=%d. Try selecting 0 or 1" %mode) |
|
4269 | raise ValueError("Codification mode selected is not valid: mode=%d. Try selecting 0 or 1" %mode) | |
4265 |
|
4270 | |||
4266 | dataOut.code = self.code |
|
4271 | dataOut.code = self.code | |
4267 | dataOut.nCode = self.nCode |
|
4272 | dataOut.nCode = self.nCode | |
4268 | dataOut.nBaud = self.nBaud |
|
4273 | dataOut.nBaud = self.nBaud | |
4269 |
|
4274 | |||
4270 | dataOut.data = datadec |
|
4275 | dataOut.data = datadec | |
4271 | #print("before",dataOut.heightList) |
|
4276 | #print("before",dataOut.heightList) | |
4272 | dataOut.heightList = dataOut.heightList[0:datadec.shape[-1]] |
|
4277 | dataOut.heightList = dataOut.heightList[0:datadec.shape[-1]] | |
4273 | #print("after",dataOut.heightList) |
|
4278 | #print("after",dataOut.heightList) | |
4274 |
|
4279 | |||
4275 | dataOut.flagDecodeData = True #asumo q la data esta decodificada |
|
4280 | dataOut.flagDecodeData = True #asumo q la data esta decodificada | |
4276 |
|
4281 | |||
4277 | if self.__profIndex == self.nCode-1: |
|
4282 | if self.__profIndex == self.nCode-1: | |
4278 | self.__profIndex = 0 |
|
4283 | self.__profIndex = 0 | |
4279 | return dataOut |
|
4284 | return dataOut | |
4280 |
|
4285 | |||
4281 | self.__profIndex += 1 |
|
4286 | self.__profIndex += 1 | |
4282 |
|
4287 | |||
4283 | #print("SHAPE",numpy.shape(dataOut.data)) |
|
4288 | #print("SHAPE",numpy.shape(dataOut.data)) | |
4284 |
|
4289 | |||
4285 | return dataOut |
|
4290 | return dataOut | |
4286 |
|
4291 | |||
4287 |
|
4292 | |||
4288 | class ProfileConcat(Operation): |
|
4293 | class ProfileConcat(Operation): | |
4289 |
|
4294 | |||
4290 | isConfig = False |
|
4295 | isConfig = False | |
4291 | buffer = None |
|
4296 | buffer = None | |
4292 |
|
4297 | |||
4293 | def __init__(self, **kwargs): |
|
4298 | def __init__(self, **kwargs): | |
4294 |
|
4299 | |||
4295 | Operation.__init__(self, **kwargs) |
|
4300 | Operation.__init__(self, **kwargs) | |
4296 | self.profileIndex = 0 |
|
4301 | self.profileIndex = 0 | |
4297 |
|
4302 | |||
4298 | def reset(self): |
|
4303 | def reset(self): | |
4299 | self.buffer = numpy.zeros_like(self.buffer) |
|
4304 | self.buffer = numpy.zeros_like(self.buffer) | |
4300 | self.start_index = 0 |
|
4305 | self.start_index = 0 | |
4301 | self.times = 1 |
|
4306 | self.times = 1 | |
4302 |
|
4307 | |||
4303 | def setup(self, data, m, n=1): |
|
4308 | def setup(self, data, m, n=1): | |
4304 | self.buffer = numpy.zeros((data.shape[0],data.shape[1]*m),dtype=type(data[0,0])) |
|
4309 | self.buffer = numpy.zeros((data.shape[0],data.shape[1]*m),dtype=type(data[0,0])) | |
4305 | self.nHeights = data.shape[1]#.nHeights |
|
4310 | self.nHeights = data.shape[1]#.nHeights | |
4306 | self.start_index = 0 |
|
4311 | self.start_index = 0 | |
4307 | self.times = 1 |
|
4312 | self.times = 1 | |
4308 |
|
4313 | |||
4309 | def concat(self, data): |
|
4314 | def concat(self, data): | |
4310 |
|
4315 | |||
4311 | self.buffer[:,self.start_index:self.nHeights*self.times] = data.copy() |
|
4316 | self.buffer[:,self.start_index:self.nHeights*self.times] = data.copy() | |
4312 | self.start_index = self.start_index + self.nHeights |
|
4317 | self.start_index = self.start_index + self.nHeights | |
4313 |
|
4318 | |||
4314 | def run(self, dataOut, m): |
|
4319 | def run(self, dataOut, m): | |
4315 | dataOut.flagNoData = True |
|
4320 | dataOut.flagNoData = True | |
4316 |
|
4321 | |||
4317 | if not self.isConfig: |
|
4322 | if not self.isConfig: | |
4318 | self.setup(dataOut.data, m, 1) |
|
4323 | self.setup(dataOut.data, m, 1) | |
4319 | self.isConfig = True |
|
4324 | self.isConfig = True | |
4320 |
|
4325 | |||
4321 | if dataOut.flagDataAsBlock: |
|
4326 | if dataOut.flagDataAsBlock: | |
4322 | raise ValueError("ProfileConcat can only be used when voltage have been read profile by profile, getBlock = False") |
|
4327 | raise ValueError("ProfileConcat can only be used when voltage have been read profile by profile, getBlock = False") | |
4323 |
|
4328 | |||
4324 | else: |
|
4329 | else: | |
4325 | self.concat(dataOut.data) |
|
4330 | self.concat(dataOut.data) | |
4326 | self.times += 1 |
|
4331 | self.times += 1 | |
4327 | if self.times > m: |
|
4332 | if self.times > m: | |
4328 | dataOut.data = self.buffer |
|
4333 | dataOut.data = self.buffer | |
4329 | self.reset() |
|
4334 | self.reset() | |
4330 | dataOut.flagNoData = False |
|
4335 | dataOut.flagNoData = False | |
4331 | # se deben actualizar mas propiedades del header y del objeto dataOut, por ejemplo, las alturas |
|
4336 | # se deben actualizar mas propiedades del header y del objeto dataOut, por ejemplo, las alturas | |
4332 | deltaHeight = dataOut.heightList[1] - dataOut.heightList[0] |
|
4337 | deltaHeight = dataOut.heightList[1] - dataOut.heightList[0] | |
4333 | xf = dataOut.heightList[0] + dataOut.nHeights * deltaHeight * m |
|
4338 | xf = dataOut.heightList[0] + dataOut.nHeights * deltaHeight * m | |
4334 | dataOut.heightList = numpy.arange(dataOut.heightList[0], xf, deltaHeight) |
|
4339 | dataOut.heightList = numpy.arange(dataOut.heightList[0], xf, deltaHeight) | |
4335 | dataOut.ippSeconds *= m |
|
4340 | dataOut.ippSeconds *= m | |
4336 | return dataOut |
|
4341 | return dataOut | |
4337 |
|
4342 | |||
4338 | class ProfileSelector(Operation): |
|
4343 | class ProfileSelector(Operation): | |
4339 |
|
4344 | |||
4340 | profileIndex = None |
|
4345 | profileIndex = None | |
4341 | # Tamanho total de los perfiles |
|
4346 | # Tamanho total de los perfiles | |
4342 | nProfiles = None |
|
4347 | nProfiles = None | |
4343 |
|
4348 | |||
4344 | def __init__(self, **kwargs): |
|
4349 | def __init__(self, **kwargs): | |
4345 |
|
4350 | |||
4346 | Operation.__init__(self, **kwargs) |
|
4351 | Operation.__init__(self, **kwargs) | |
4347 | self.profileIndex = 0 |
|
4352 | self.profileIndex = 0 | |
4348 |
|
4353 | |||
4349 | def incProfileIndex(self): |
|
4354 | def incProfileIndex(self): | |
4350 |
|
4355 | |||
4351 | self.profileIndex += 1 |
|
4356 | self.profileIndex += 1 | |
4352 |
|
4357 | |||
4353 | if self.profileIndex >= self.nProfiles: |
|
4358 | if self.profileIndex >= self.nProfiles: | |
4354 | self.profileIndex = 0 |
|
4359 | self.profileIndex = 0 | |
4355 |
|
4360 | |||
4356 | def isThisProfileInRange(self, profileIndex, minIndex, maxIndex): |
|
4361 | def isThisProfileInRange(self, profileIndex, minIndex, maxIndex): | |
4357 |
|
4362 | |||
4358 | if profileIndex < minIndex: |
|
4363 | if profileIndex < minIndex: | |
4359 | return False |
|
4364 | return False | |
4360 |
|
4365 | |||
4361 | if profileIndex > maxIndex: |
|
4366 | if profileIndex > maxIndex: | |
4362 | return False |
|
4367 | return False | |
4363 |
|
4368 | |||
4364 | return True |
|
4369 | return True | |
4365 |
|
4370 | |||
4366 | def isThisProfileInList(self, profileIndex, profileList): |
|
4371 | def isThisProfileInList(self, profileIndex, profileList): | |
4367 |
|
4372 | |||
4368 | if profileIndex not in profileList: |
|
4373 | if profileIndex not in profileList: | |
4369 | return False |
|
4374 | return False | |
4370 |
|
4375 | |||
4371 | return True |
|
4376 | return True | |
4372 |
|
4377 | |||
4373 | def run(self, dataOut, profileList=None, profileRangeList=None, beam=None, byblock=False, rangeList = None, nProfiles=None): |
|
4378 | def run(self, dataOut, profileList=None, profileRangeList=None, beam=None, byblock=False, rangeList = None, nProfiles=None): | |
4374 |
|
4379 | |||
4375 | """ |
|
4380 | """ | |
4376 | ProfileSelector: |
|
4381 | ProfileSelector: | |
4377 |
|
4382 | |||
4378 | Inputs: |
|
4383 | Inputs: | |
4379 | profileList : Index of profiles selected. Example: profileList = (0,1,2,7,8) |
|
4384 | profileList : Index of profiles selected. Example: profileList = (0,1,2,7,8) | |
4380 |
|
4385 | |||
4381 | profileRangeList : Minimum and maximum profile indexes. Example: profileRangeList = (4, 30) |
|
4386 | profileRangeList : Minimum and maximum profile indexes. Example: profileRangeList = (4, 30) | |
4382 |
|
4387 | |||
4383 | rangeList : List of profile ranges. Example: rangeList = ((4, 30), (32, 64), (128, 256)) |
|
4388 | rangeList : List of profile ranges. Example: rangeList = ((4, 30), (32, 64), (128, 256)) | |
4384 |
|
4389 | |||
4385 | """ |
|
4390 | """ | |
4386 |
|
4391 | |||
4387 | if rangeList is not None: |
|
4392 | if rangeList is not None: | |
4388 | if type(rangeList[0]) not in (tuple, list): |
|
4393 | if type(rangeList[0]) not in (tuple, list): | |
4389 | rangeList = [rangeList] |
|
4394 | rangeList = [rangeList] | |
4390 |
|
4395 | |||
4391 | dataOut.flagNoData = True |
|
4396 | dataOut.flagNoData = True | |
4392 |
|
4397 | |||
4393 | if dataOut.flagDataAsBlock: |
|
4398 | if dataOut.flagDataAsBlock: | |
4394 | """ |
|
4399 | """ | |
4395 | data dimension = [nChannels, nProfiles, nHeis] |
|
4400 | data dimension = [nChannels, nProfiles, nHeis] | |
4396 | """ |
|
4401 | """ | |
4397 | if profileList != None: |
|
4402 | if profileList != None: | |
4398 | dataOut.data = dataOut.data[:,profileList,:] |
|
4403 | dataOut.data = dataOut.data[:,profileList,:] | |
4399 |
|
4404 | |||
4400 | if profileRangeList != None: |
|
4405 | if profileRangeList != None: | |
4401 | minIndex = profileRangeList[0] |
|
4406 | minIndex = profileRangeList[0] | |
4402 | maxIndex = profileRangeList[1] |
|
4407 | maxIndex = profileRangeList[1] | |
4403 | profileList = list(range(minIndex, maxIndex+1)) |
|
4408 | profileList = list(range(minIndex, maxIndex+1)) | |
4404 |
|
4409 | |||
4405 | dataOut.data = dataOut.data[:,minIndex:maxIndex+1,:] |
|
4410 | dataOut.data = dataOut.data[:,minIndex:maxIndex+1,:] | |
4406 |
|
4411 | |||
4407 | if rangeList != None: |
|
4412 | if rangeList != None: | |
4408 |
|
4413 | |||
4409 | profileList = [] |
|
4414 | profileList = [] | |
4410 |
|
4415 | |||
4411 | for thisRange in rangeList: |
|
4416 | for thisRange in rangeList: | |
4412 | minIndex = thisRange[0] |
|
4417 | minIndex = thisRange[0] | |
4413 | maxIndex = thisRange[1] |
|
4418 | maxIndex = thisRange[1] | |
4414 |
|
4419 | |||
4415 | profileList.extend(list(range(minIndex, maxIndex+1))) |
|
4420 | profileList.extend(list(range(minIndex, maxIndex+1))) | |
4416 |
|
4421 | |||
4417 | dataOut.data = dataOut.data[:,profileList,:] |
|
4422 | dataOut.data = dataOut.data[:,profileList,:] | |
4418 |
|
4423 | |||
4419 | dataOut.nProfiles = len(profileList) |
|
4424 | dataOut.nProfiles = len(profileList) | |
4420 | dataOut.profileIndex = dataOut.nProfiles - 1 |
|
4425 | dataOut.profileIndex = dataOut.nProfiles - 1 | |
4421 | dataOut.flagNoData = False |
|
4426 | dataOut.flagNoData = False | |
4422 |
|
4427 | |||
4423 | return dataOut |
|
4428 | return dataOut | |
4424 |
|
4429 | |||
4425 | """ |
|
4430 | """ | |
4426 | data dimension = [nChannels, nHeis] |
|
4431 | data dimension = [nChannels, nHeis] | |
4427 | """ |
|
4432 | """ | |
4428 |
|
4433 | |||
4429 | if profileList != None: |
|
4434 | if profileList != None: | |
4430 |
|
4435 | |||
4431 | if self.isThisProfileInList(dataOut.profileIndex, profileList): |
|
4436 | if self.isThisProfileInList(dataOut.profileIndex, profileList): | |
4432 |
|
4437 | |||
4433 | self.nProfiles = len(profileList) |
|
4438 | self.nProfiles = len(profileList) | |
4434 | dataOut.nProfiles = self.nProfiles |
|
4439 | dataOut.nProfiles = self.nProfiles | |
4435 | dataOut.profileIndex = self.profileIndex |
|
4440 | dataOut.profileIndex = self.profileIndex | |
4436 | dataOut.flagNoData = False |
|
4441 | dataOut.flagNoData = False | |
4437 |
|
4442 | |||
4438 | self.incProfileIndex() |
|
4443 | self.incProfileIndex() | |
4439 | return dataOut |
|
4444 | return dataOut | |
4440 |
|
4445 | |||
4441 | if profileRangeList != None: |
|
4446 | if profileRangeList != None: | |
4442 |
|
4447 | |||
4443 | minIndex = profileRangeList[0] |
|
4448 | minIndex = profileRangeList[0] | |
4444 | maxIndex = profileRangeList[1] |
|
4449 | maxIndex = profileRangeList[1] | |
4445 |
|
4450 | |||
4446 | if self.isThisProfileInRange(dataOut.profileIndex, minIndex, maxIndex): |
|
4451 | if self.isThisProfileInRange(dataOut.profileIndex, minIndex, maxIndex): | |
4447 |
|
4452 | |||
4448 | self.nProfiles = maxIndex - minIndex + 1 |
|
4453 | self.nProfiles = maxIndex - minIndex + 1 | |
4449 | dataOut.nProfiles = self.nProfiles |
|
4454 | dataOut.nProfiles = self.nProfiles | |
4450 | dataOut.profileIndex = self.profileIndex |
|
4455 | dataOut.profileIndex = self.profileIndex | |
4451 | dataOut.flagNoData = False |
|
4456 | dataOut.flagNoData = False | |
4452 |
|
4457 | |||
4453 | self.incProfileIndex() |
|
4458 | self.incProfileIndex() | |
4454 | return dataOut |
|
4459 | return dataOut | |
4455 |
|
4460 | |||
4456 | if rangeList != None: |
|
4461 | if rangeList != None: | |
4457 |
|
4462 | |||
4458 | nProfiles = 0 |
|
4463 | nProfiles = 0 | |
4459 |
|
4464 | |||
4460 | for thisRange in rangeList: |
|
4465 | for thisRange in rangeList: | |
4461 | minIndex = thisRange[0] |
|
4466 | minIndex = thisRange[0] | |
4462 | maxIndex = thisRange[1] |
|
4467 | maxIndex = thisRange[1] | |
4463 |
|
4468 | |||
4464 | nProfiles += maxIndex - minIndex + 1 |
|
4469 | nProfiles += maxIndex - minIndex + 1 | |
4465 |
|
4470 | |||
4466 | for thisRange in rangeList: |
|
4471 | for thisRange in rangeList: | |
4467 |
|
4472 | |||
4468 | minIndex = thisRange[0] |
|
4473 | minIndex = thisRange[0] | |
4469 | maxIndex = thisRange[1] |
|
4474 | maxIndex = thisRange[1] | |
4470 |
|
4475 | |||
4471 | if self.isThisProfileInRange(dataOut.profileIndex, minIndex, maxIndex): |
|
4476 | if self.isThisProfileInRange(dataOut.profileIndex, minIndex, maxIndex): | |
4472 |
|
4477 | |||
4473 | self.nProfiles = nProfiles |
|
4478 | self.nProfiles = nProfiles | |
4474 | dataOut.nProfiles = self.nProfiles |
|
4479 | dataOut.nProfiles = self.nProfiles | |
4475 | dataOut.profileIndex = self.profileIndex |
|
4480 | dataOut.profileIndex = self.profileIndex | |
4476 | dataOut.flagNoData = False |
|
4481 | dataOut.flagNoData = False | |
4477 |
|
4482 | |||
4478 | self.incProfileIndex() |
|
4483 | self.incProfileIndex() | |
4479 |
|
4484 | |||
4480 | break |
|
4485 | break | |
4481 |
|
4486 | |||
4482 | return dataOut |
|
4487 | return dataOut | |
4483 |
|
4488 | |||
4484 |
|
4489 | |||
4485 | if beam != None: #beam is only for AMISR data |
|
4490 | if beam != None: #beam is only for AMISR data | |
4486 | if self.isThisProfileInList(dataOut.profileIndex, dataOut.beamRangeDict[beam]): |
|
4491 | if self.isThisProfileInList(dataOut.profileIndex, dataOut.beamRangeDict[beam]): | |
4487 | dataOut.flagNoData = False |
|
4492 | dataOut.flagNoData = False | |
4488 | dataOut.profileIndex = self.profileIndex |
|
4493 | dataOut.profileIndex = self.profileIndex | |
4489 |
|
4494 | |||
4490 | self.incProfileIndex() |
|
4495 | self.incProfileIndex() | |
4491 |
|
4496 | |||
4492 | return dataOut |
|
4497 | return dataOut | |
4493 |
|
4498 | |||
4494 | raise ValueError("ProfileSelector needs profileList, profileRangeList or rangeList parameter") |
|
4499 | raise ValueError("ProfileSelector needs profileList, profileRangeList or rangeList parameter") | |
4495 |
|
4500 | |||
4496 | #return False |
|
4501 | #return False | |
4497 | return dataOut |
|
4502 | return dataOut | |
4498 |
|
4503 | |||
4499 | class Reshaper(Operation): |
|
4504 | class Reshaper(Operation): | |
4500 |
|
4505 | |||
4501 | def __init__(self, **kwargs): |
|
4506 | def __init__(self, **kwargs): | |
4502 |
|
4507 | |||
4503 | Operation.__init__(self, **kwargs) |
|
4508 | Operation.__init__(self, **kwargs) | |
4504 |
|
4509 | |||
4505 | self.__buffer = None |
|
4510 | self.__buffer = None | |
4506 | self.__nitems = 0 |
|
4511 | self.__nitems = 0 | |
4507 |
|
4512 | |||
4508 | def __appendProfile(self, dataOut, nTxs): |
|
4513 | def __appendProfile(self, dataOut, nTxs): | |
4509 |
|
4514 | |||
4510 | if self.__buffer is None: |
|
4515 | if self.__buffer is None: | |
4511 | shape = (dataOut.nChannels, int(dataOut.nHeights/nTxs) ) |
|
4516 | shape = (dataOut.nChannels, int(dataOut.nHeights/nTxs) ) | |
4512 | self.__buffer = numpy.empty(shape, dtype = dataOut.data.dtype) |
|
4517 | self.__buffer = numpy.empty(shape, dtype = dataOut.data.dtype) | |
4513 |
|
4518 | |||
4514 | ini = dataOut.nHeights * self.__nitems |
|
4519 | ini = dataOut.nHeights * self.__nitems | |
4515 | end = ini + dataOut.nHeights |
|
4520 | end = ini + dataOut.nHeights | |
4516 |
|
4521 | |||
4517 | self.__buffer[:, ini:end] = dataOut.data |
|
4522 | self.__buffer[:, ini:end] = dataOut.data | |
4518 |
|
4523 | |||
4519 | self.__nitems += 1 |
|
4524 | self.__nitems += 1 | |
4520 |
|
4525 | |||
4521 | return int(self.__nitems*nTxs) |
|
4526 | return int(self.__nitems*nTxs) | |
4522 |
|
4527 | |||
4523 | def __getBuffer(self): |
|
4528 | def __getBuffer(self): | |
4524 |
|
4529 | |||
4525 | if self.__nitems == int(1./self.__nTxs): |
|
4530 | if self.__nitems == int(1./self.__nTxs): | |
4526 |
|
4531 | |||
4527 | self.__nitems = 0 |
|
4532 | self.__nitems = 0 | |
4528 |
|
4533 | |||
4529 | return self.__buffer.copy() |
|
4534 | return self.__buffer.copy() | |
4530 |
|
4535 | |||
4531 | return None |
|
4536 | return None | |
4532 |
|
4537 | |||
4533 | def __checkInputs(self, dataOut, shape, nTxs): |
|
4538 | def __checkInputs(self, dataOut, shape, nTxs): | |
4534 |
|
4539 | |||
4535 | if shape is None and nTxs is None: |
|
4540 | if shape is None and nTxs is None: | |
4536 | raise ValueError("Reshaper: shape of factor should be defined") |
|
4541 | raise ValueError("Reshaper: shape of factor should be defined") | |
4537 |
|
4542 | |||
4538 | if nTxs: |
|
4543 | if nTxs: | |
4539 | if nTxs < 0: |
|
4544 | if nTxs < 0: | |
4540 | raise ValueError("nTxs should be greater than 0") |
|
4545 | raise ValueError("nTxs should be greater than 0") | |
4541 |
|
4546 | |||
4542 | if nTxs < 1 and dataOut.nProfiles % (1./nTxs) != 0: |
|
4547 | if nTxs < 1 and dataOut.nProfiles % (1./nTxs) != 0: | |
4543 | raise ValueError("nProfiles= %d is not divisibled by (1./nTxs) = %f" %(dataOut.nProfiles, (1./nTxs))) |
|
4548 | raise ValueError("nProfiles= %d is not divisibled by (1./nTxs) = %f" %(dataOut.nProfiles, (1./nTxs))) | |
4544 |
|
4549 | |||
4545 | shape = [dataOut.nChannels, dataOut.nProfiles*nTxs, dataOut.nHeights/nTxs] |
|
4550 | shape = [dataOut.nChannels, dataOut.nProfiles*nTxs, dataOut.nHeights/nTxs] | |
4546 |
|
4551 | |||
4547 | return shape, nTxs |
|
4552 | return shape, nTxs | |
4548 |
|
4553 | |||
4549 | if len(shape) != 2 and len(shape) != 3: |
|
4554 | if len(shape) != 2 and len(shape) != 3: | |
4550 | 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)) |
|
4555 | 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)) | |
4551 |
|
4556 | |||
4552 | if len(shape) == 2: |
|
4557 | if len(shape) == 2: | |
4553 | shape_tuple = [dataOut.nChannels] |
|
4558 | shape_tuple = [dataOut.nChannels] | |
4554 | shape_tuple.extend(shape) |
|
4559 | shape_tuple.extend(shape) | |
4555 | else: |
|
4560 | else: | |
4556 | shape_tuple = list(shape) |
|
4561 | shape_tuple = list(shape) | |
4557 |
|
4562 | |||
4558 | nTxs = 1.0*shape_tuple[1]/dataOut.nProfiles |
|
4563 | nTxs = 1.0*shape_tuple[1]/dataOut.nProfiles | |
4559 |
|
4564 | |||
4560 | return shape_tuple, nTxs |
|
4565 | return shape_tuple, nTxs | |
4561 |
|
4566 | |||
4562 | def run(self, dataOut, shape=None, nTxs=None): |
|
4567 | def run(self, dataOut, shape=None, nTxs=None): | |
4563 |
|
4568 | |||
4564 | shape_tuple, self.__nTxs = self.__checkInputs(dataOut, shape, nTxs) |
|
4569 | shape_tuple, self.__nTxs = self.__checkInputs(dataOut, shape, nTxs) | |
4565 |
|
4570 | |||
4566 | dataOut.flagNoData = True |
|
4571 | dataOut.flagNoData = True | |
4567 | profileIndex = None |
|
4572 | profileIndex = None | |
4568 |
|
4573 | |||
4569 | if dataOut.flagDataAsBlock: |
|
4574 | if dataOut.flagDataAsBlock: | |
4570 |
|
4575 | |||
4571 | dataOut.data = numpy.reshape(dataOut.data, shape_tuple) |
|
4576 | dataOut.data = numpy.reshape(dataOut.data, shape_tuple) | |
4572 | dataOut.flagNoData = False |
|
4577 | dataOut.flagNoData = False | |
4573 |
|
4578 | |||
4574 | profileIndex = int(dataOut.nProfiles*self.__nTxs) - 1 |
|
4579 | profileIndex = int(dataOut.nProfiles*self.__nTxs) - 1 | |
4575 |
|
4580 | |||
4576 | else: |
|
4581 | else: | |
4577 |
|
4582 | |||
4578 |
|
4583 | |||
4579 | if self.__nTxs < 1: |
|
4584 | if self.__nTxs < 1: | |
4580 |
|
4585 | |||
4581 | self.__appendProfile(dataOut, self.__nTxs) |
|
4586 | self.__appendProfile(dataOut, self.__nTxs) | |
4582 | new_data = self.__getBuffer() |
|
4587 | new_data = self.__getBuffer() | |
4583 |
|
4588 | |||
4584 | if new_data is not None: |
|
4589 | if new_data is not None: | |
4585 | dataOut.data = new_data |
|
4590 | dataOut.data = new_data | |
4586 | dataOut.flagNoData = False |
|
4591 | dataOut.flagNoData = False | |
4587 |
|
4592 | |||
4588 | profileIndex = dataOut.profileIndex*nTxs |
|
4593 | profileIndex = dataOut.profileIndex*nTxs | |
4589 |
|
4594 | |||
4590 | else: |
|
4595 | else: | |
4591 | raise ValueError("nTxs should be greater than 0 and lower than 1, or use VoltageReader(..., getblock=True)") |
|
4596 | raise ValueError("nTxs should be greater than 0 and lower than 1, or use VoltageReader(..., getblock=True)") | |
4592 |
|
4597 | |||
4593 | deltaHeight = dataOut.heightList[1] - dataOut.heightList[0] |
|
4598 | deltaHeight = dataOut.heightList[1] - dataOut.heightList[0] | |
4594 |
|
4599 | |||
4595 | dataOut.heightList = numpy.arange(dataOut.nHeights/self.__nTxs) * deltaHeight + dataOut.heightList[0] |
|
4600 | dataOut.heightList = numpy.arange(dataOut.nHeights/self.__nTxs) * deltaHeight + dataOut.heightList[0] | |
4596 |
|
4601 | |||
4597 | dataOut.nProfiles = int(dataOut.nProfiles*self.__nTxs) |
|
4602 | dataOut.nProfiles = int(dataOut.nProfiles*self.__nTxs) | |
4598 |
|
4603 | |||
4599 | dataOut.profileIndex = profileIndex |
|
4604 | dataOut.profileIndex = profileIndex | |
4600 |
|
4605 | |||
4601 | dataOut.ippSeconds /= self.__nTxs |
|
4606 | dataOut.ippSeconds /= self.__nTxs | |
4602 |
|
4607 | |||
4603 | return dataOut |
|
4608 | return dataOut | |
4604 |
|
4609 | |||
4605 | class SplitProfiles(Operation): |
|
4610 | class SplitProfiles(Operation): | |
4606 |
|
4611 | |||
4607 | def __init__(self, **kwargs): |
|
4612 | def __init__(self, **kwargs): | |
4608 |
|
4613 | |||
4609 | Operation.__init__(self, **kwargs) |
|
4614 | Operation.__init__(self, **kwargs) | |
4610 |
|
4615 | |||
4611 | def run(self, dataOut, n): |
|
4616 | def run(self, dataOut, n): | |
4612 |
|
4617 | |||
4613 | dataOut.flagNoData = True |
|
4618 | dataOut.flagNoData = True | |
4614 | profileIndex = None |
|
4619 | profileIndex = None | |
4615 |
|
4620 | |||
4616 | if dataOut.flagDataAsBlock: |
|
4621 | if dataOut.flagDataAsBlock: | |
4617 |
|
4622 | |||
4618 | #nchannels, nprofiles, nsamples |
|
4623 | #nchannels, nprofiles, nsamples | |
4619 | shape = dataOut.data.shape |
|
4624 | shape = dataOut.data.shape | |
4620 |
|
4625 | |||
4621 | if shape[2] % n != 0: |
|
4626 | if shape[2] % n != 0: | |
4622 | raise ValueError("Could not split the data, n=%d has to be multiple of %d" %(n, shape[2])) |
|
4627 | raise ValueError("Could not split the data, n=%d has to be multiple of %d" %(n, shape[2])) | |
4623 |
|
4628 | |||
4624 | new_shape = shape[0], shape[1]*n, int(shape[2]/n) |
|
4629 | new_shape = shape[0], shape[1]*n, int(shape[2]/n) | |
4625 |
|
4630 | |||
4626 | dataOut.data = numpy.reshape(dataOut.data, new_shape) |
|
4631 | dataOut.data = numpy.reshape(dataOut.data, new_shape) | |
4627 | dataOut.flagNoData = False |
|
4632 | dataOut.flagNoData = False | |
4628 |
|
4633 | |||
4629 | profileIndex = int(dataOut.nProfiles/n) - 1 |
|
4634 | profileIndex = int(dataOut.nProfiles/n) - 1 | |
4630 |
|
4635 | |||
4631 | else: |
|
4636 | else: | |
4632 |
|
4637 | |||
4633 | raise ValueError("Could not split the data when is read Profile by Profile. Use VoltageReader(..., getblock=True)") |
|
4638 | raise ValueError("Could not split the data when is read Profile by Profile. Use VoltageReader(..., getblock=True)") | |
4634 |
|
4639 | |||
4635 | deltaHeight = dataOut.heightList[1] - dataOut.heightList[0] |
|
4640 | deltaHeight = dataOut.heightList[1] - dataOut.heightList[0] | |
4636 |
|
4641 | |||
4637 | dataOut.heightList = numpy.arange(dataOut.nHeights/n) * deltaHeight + dataOut.heightList[0] |
|
4642 | dataOut.heightList = numpy.arange(dataOut.nHeights/n) * deltaHeight + dataOut.heightList[0] | |
4638 |
|
4643 | |||
4639 | dataOut.nProfiles = int(dataOut.nProfiles*n) |
|
4644 | dataOut.nProfiles = int(dataOut.nProfiles*n) | |
4640 |
|
4645 | |||
4641 | dataOut.profileIndex = profileIndex |
|
4646 | dataOut.profileIndex = profileIndex | |
4642 |
|
4647 | |||
4643 | dataOut.ippSeconds /= n |
|
4648 | dataOut.ippSeconds /= n | |
4644 |
|
4649 | |||
4645 | return dataOut |
|
4650 | return dataOut | |
4646 |
|
4651 | |||
4647 | class CombineProfiles(Operation): |
|
4652 | class CombineProfiles(Operation): | |
4648 | def __init__(self, **kwargs): |
|
4653 | def __init__(self, **kwargs): | |
4649 |
|
4654 | |||
4650 | Operation.__init__(self, **kwargs) |
|
4655 | Operation.__init__(self, **kwargs) | |
4651 |
|
4656 | |||
4652 | self.__remData = None |
|
4657 | self.__remData = None | |
4653 | self.__profileIndex = 0 |
|
4658 | self.__profileIndex = 0 | |
4654 |
|
4659 | |||
4655 | def run(self, dataOut, n): |
|
4660 | def run(self, dataOut, n): | |
4656 |
|
4661 | |||
4657 | dataOut.flagNoData = True |
|
4662 | dataOut.flagNoData = True | |
4658 | profileIndex = None |
|
4663 | profileIndex = None | |
4659 |
|
4664 | |||
4660 | if dataOut.flagDataAsBlock: |
|
4665 | if dataOut.flagDataAsBlock: | |
4661 |
|
4666 | |||
4662 | #nchannels, nprofiles, nsamples |
|
4667 | #nchannels, nprofiles, nsamples | |
4663 | shape = dataOut.data.shape |
|
4668 | shape = dataOut.data.shape | |
4664 | new_shape = shape[0], shape[1]/n, shape[2]*n |
|
4669 | new_shape = shape[0], shape[1]/n, shape[2]*n | |
4665 |
|
4670 | |||
4666 | if shape[1] % n != 0: |
|
4671 | if shape[1] % n != 0: | |
4667 | raise ValueError("Could not split the data, n=%d has to be multiple of %d" %(n, shape[1])) |
|
4672 | raise ValueError("Could not split the data, n=%d has to be multiple of %d" %(n, shape[1])) | |
4668 |
|
4673 | |||
4669 | dataOut.data = numpy.reshape(dataOut.data, new_shape) |
|
4674 | dataOut.data = numpy.reshape(dataOut.data, new_shape) | |
4670 | dataOut.flagNoData = False |
|
4675 | dataOut.flagNoData = False | |
4671 |
|
4676 | |||
4672 | profileIndex = int(dataOut.nProfiles*n) - 1 |
|
4677 | profileIndex = int(dataOut.nProfiles*n) - 1 | |
4673 |
|
4678 | |||
4674 | else: |
|
4679 | else: | |
4675 |
|
4680 | |||
4676 | #nchannels, nsamples |
|
4681 | #nchannels, nsamples | |
4677 | if self.__remData is None: |
|
4682 | if self.__remData is None: | |
4678 | newData = dataOut.data |
|
4683 | newData = dataOut.data | |
4679 | else: |
|
4684 | else: | |
4680 | newData = numpy.concatenate((self.__remData, dataOut.data), axis=1) |
|
4685 | newData = numpy.concatenate((self.__remData, dataOut.data), axis=1) | |
4681 |
|
4686 | |||
4682 | self.__profileIndex += 1 |
|
4687 | self.__profileIndex += 1 | |
4683 |
|
4688 | |||
4684 | if self.__profileIndex < n: |
|
4689 | if self.__profileIndex < n: | |
4685 | self.__remData = newData |
|
4690 | self.__remData = newData | |
4686 | #continue |
|
4691 | #continue | |
4687 | return |
|
4692 | return | |
4688 |
|
4693 | |||
4689 | self.__profileIndex = 0 |
|
4694 | self.__profileIndex = 0 | |
4690 | self.__remData = None |
|
4695 | self.__remData = None | |
4691 |
|
4696 | |||
4692 | dataOut.data = newData |
|
4697 | dataOut.data = newData | |
4693 | dataOut.flagNoData = False |
|
4698 | dataOut.flagNoData = False | |
4694 |
|
4699 | |||
4695 | profileIndex = dataOut.profileIndex/n |
|
4700 | profileIndex = dataOut.profileIndex/n | |
4696 |
|
4701 | |||
4697 |
|
4702 | |||
4698 | deltaHeight = dataOut.heightList[1] - dataOut.heightList[0] |
|
4703 | deltaHeight = dataOut.heightList[1] - dataOut.heightList[0] | |
4699 |
|
4704 | |||
4700 | dataOut.heightList = numpy.arange(dataOut.nHeights*n) * deltaHeight + dataOut.heightList[0] |
|
4705 | dataOut.heightList = numpy.arange(dataOut.nHeights*n) * deltaHeight + dataOut.heightList[0] | |
4701 |
|
4706 | |||
4702 | dataOut.nProfiles = int(dataOut.nProfiles/n) |
|
4707 | dataOut.nProfiles = int(dataOut.nProfiles/n) | |
4703 |
|
4708 | |||
4704 | dataOut.profileIndex = profileIndex |
|
4709 | dataOut.profileIndex = profileIndex | |
4705 |
|
4710 | |||
4706 | dataOut.ippSeconds *= n |
|
4711 | dataOut.ippSeconds *= n | |
4707 |
|
4712 | |||
4708 | return dataOut |
|
4713 | return dataOut | |
4709 | # import collections |
|
4714 | # import collections | |
4710 | # from scipy.stats import mode |
|
4715 | # from scipy.stats import mode | |
4711 | # |
|
4716 | # | |
4712 | # class Synchronize(Operation): |
|
4717 | # class Synchronize(Operation): | |
4713 | # |
|
4718 | # | |
4714 | # isConfig = False |
|
4719 | # isConfig = False | |
4715 | # __profIndex = 0 |
|
4720 | # __profIndex = 0 | |
4716 | # |
|
4721 | # | |
4717 | # def __init__(self, **kwargs): |
|
4722 | # def __init__(self, **kwargs): | |
4718 | # |
|
4723 | # | |
4719 | # Operation.__init__(self, **kwargs) |
|
4724 | # Operation.__init__(self, **kwargs) | |
4720 | # # self.isConfig = False |
|
4725 | # # self.isConfig = False | |
4721 | # self.__powBuffer = None |
|
4726 | # self.__powBuffer = None | |
4722 | # self.__startIndex = 0 |
|
4727 | # self.__startIndex = 0 | |
4723 | # self.__pulseFound = False |
|
4728 | # self.__pulseFound = False | |
4724 | # |
|
4729 | # | |
4725 | # def __findTxPulse(self, dataOut, channel=0, pulse_with = None): |
|
4730 | # def __findTxPulse(self, dataOut, channel=0, pulse_with = None): | |
4726 | # |
|
4731 | # | |
4727 | # #Read data |
|
4732 | # #Read data | |
4728 | # |
|
4733 | # | |
4729 | # powerdB = dataOut.getPower(channel = channel) |
|
4734 | # powerdB = dataOut.getPower(channel = channel) | |
4730 | # noisedB = dataOut.getNoise(channel = channel)[0] |
|
4735 | # noisedB = dataOut.getNoise(channel = channel)[0] | |
4731 | # |
|
4736 | # | |
4732 | # self.__powBuffer.extend(powerdB.flatten()) |
|
4737 | # self.__powBuffer.extend(powerdB.flatten()) | |
4733 | # |
|
4738 | # | |
4734 | # dataArray = numpy.array(self.__powBuffer) |
|
4739 | # dataArray = numpy.array(self.__powBuffer) | |
4735 | # |
|
4740 | # | |
4736 | # filteredPower = numpy.correlate(dataArray, dataArray[0:self.__nSamples], "same") |
|
4741 | # filteredPower = numpy.correlate(dataArray, dataArray[0:self.__nSamples], "same") | |
4737 | # |
|
4742 | # | |
4738 | # maxValue = numpy.nanmax(filteredPower) |
|
4743 | # maxValue = numpy.nanmax(filteredPower) | |
4739 | # |
|
4744 | # | |
4740 | # if maxValue < noisedB + 10: |
|
4745 | # if maxValue < noisedB + 10: | |
4741 | # #No se encuentra ningun pulso de transmision |
|
4746 | # #No se encuentra ningun pulso de transmision | |
4742 | # return None |
|
4747 | # return None | |
4743 | # |
|
4748 | # | |
4744 | # maxValuesIndex = numpy.where(filteredPower > maxValue - 0.1*abs(maxValue))[0] |
|
4749 | # maxValuesIndex = numpy.where(filteredPower > maxValue - 0.1*abs(maxValue))[0] | |
4745 | # |
|
4750 | # | |
4746 | # if len(maxValuesIndex) < 2: |
|
4751 | # if len(maxValuesIndex) < 2: | |
4747 | # #Solo se encontro un solo pulso de transmision de un baudio, esperando por el siguiente TX |
|
4752 | # #Solo se encontro un solo pulso de transmision de un baudio, esperando por el siguiente TX | |
4748 | # return None |
|
4753 | # return None | |
4749 | # |
|
4754 | # | |
4750 | # phasedMaxValuesIndex = maxValuesIndex - self.__nSamples |
|
4755 | # phasedMaxValuesIndex = maxValuesIndex - self.__nSamples | |
4751 | # |
|
4756 | # | |
4752 | # #Seleccionar solo valores con un espaciamiento de nSamples |
|
4757 | # #Seleccionar solo valores con un espaciamiento de nSamples | |
4753 | # pulseIndex = numpy.intersect1d(maxValuesIndex, phasedMaxValuesIndex) |
|
4758 | # pulseIndex = numpy.intersect1d(maxValuesIndex, phasedMaxValuesIndex) | |
4754 | # |
|
4759 | # | |
4755 | # if len(pulseIndex) < 2: |
|
4760 | # if len(pulseIndex) < 2: | |
4756 | # #Solo se encontro un pulso de transmision con ancho mayor a 1 |
|
4761 | # #Solo se encontro un pulso de transmision con ancho mayor a 1 | |
4757 | # return None |
|
4762 | # return None | |
4758 | # |
|
4763 | # | |
4759 | # spacing = pulseIndex[1:] - pulseIndex[:-1] |
|
4764 | # spacing = pulseIndex[1:] - pulseIndex[:-1] | |
4760 | # |
|
4765 | # | |
4761 | # #remover senales que se distancien menos de 10 unidades o muestras |
|
4766 | # #remover senales que se distancien menos de 10 unidades o muestras | |
4762 | # #(No deberian existir IPP menor a 10 unidades) |
|
4767 | # #(No deberian existir IPP menor a 10 unidades) | |
4763 | # |
|
4768 | # | |
4764 | # realIndex = numpy.where(spacing > 10 )[0] |
|
4769 | # realIndex = numpy.where(spacing > 10 )[0] | |
4765 | # |
|
4770 | # | |
4766 | # if len(realIndex) < 2: |
|
4771 | # if len(realIndex) < 2: | |
4767 | # #Solo se encontro un pulso de transmision con ancho mayor a 1 |
|
4772 | # #Solo se encontro un pulso de transmision con ancho mayor a 1 | |
4768 | # return None |
|
4773 | # return None | |
4769 | # |
|
4774 | # | |
4770 | # #Eliminar pulsos anchos (deja solo la diferencia entre IPPs) |
|
4775 | # #Eliminar pulsos anchos (deja solo la diferencia entre IPPs) | |
4771 | # realPulseIndex = pulseIndex[realIndex] |
|
4776 | # realPulseIndex = pulseIndex[realIndex] | |
4772 | # |
|
4777 | # | |
4773 | # period = mode(realPulseIndex[1:] - realPulseIndex[:-1])[0][0] |
|
4778 | # period = mode(realPulseIndex[1:] - realPulseIndex[:-1])[0][0] | |
4774 | # |
|
4779 | # | |
4775 | # print "IPP = %d samples" %period |
|
4780 | # print "IPP = %d samples" %period | |
4776 | # |
|
4781 | # | |
4777 | # self.__newNSamples = dataOut.nHeights #int(period) |
|
4782 | # self.__newNSamples = dataOut.nHeights #int(period) | |
4778 | # self.__startIndex = int(realPulseIndex[0]) |
|
4783 | # self.__startIndex = int(realPulseIndex[0]) | |
4779 | # |
|
4784 | # | |
4780 | # return 1 |
|
4785 | # return 1 | |
4781 | # |
|
4786 | # | |
4782 | # |
|
4787 | # | |
4783 | # def setup(self, nSamples, nChannels, buffer_size = 4): |
|
4788 | # def setup(self, nSamples, nChannels, buffer_size = 4): | |
4784 | # |
|
4789 | # | |
4785 | # self.__powBuffer = collections.deque(numpy.zeros( buffer_size*nSamples,dtype=numpy.float), |
|
4790 | # self.__powBuffer = collections.deque(numpy.zeros( buffer_size*nSamples,dtype=numpy.float), | |
4786 | # maxlen = buffer_size*nSamples) |
|
4791 | # maxlen = buffer_size*nSamples) | |
4787 | # |
|
4792 | # | |
4788 | # bufferList = [] |
|
4793 | # bufferList = [] | |
4789 | # |
|
4794 | # | |
4790 | # for i in range(nChannels): |
|
4795 | # for i in range(nChannels): | |
4791 | # bufferByChannel = collections.deque(numpy.zeros( buffer_size*nSamples, dtype=complex) + numpy.NAN, |
|
4796 | # bufferByChannel = collections.deque(numpy.zeros( buffer_size*nSamples, dtype=complex) + numpy.NAN, | |
4792 | # maxlen = buffer_size*nSamples) |
|
4797 | # maxlen = buffer_size*nSamples) | |
4793 | # |
|
4798 | # | |
4794 | # bufferList.append(bufferByChannel) |
|
4799 | # bufferList.append(bufferByChannel) | |
4795 | # |
|
4800 | # | |
4796 | # self.__nSamples = nSamples |
|
4801 | # self.__nSamples = nSamples | |
4797 | # self.__nChannels = nChannels |
|
4802 | # self.__nChannels = nChannels | |
4798 | # self.__bufferList = bufferList |
|
4803 | # self.__bufferList = bufferList | |
4799 | # |
|
4804 | # | |
4800 | # def run(self, dataOut, channel = 0): |
|
4805 | # def run(self, dataOut, channel = 0): | |
4801 | # |
|
4806 | # | |
4802 | # if not self.isConfig: |
|
4807 | # if not self.isConfig: | |
4803 | # nSamples = dataOut.nHeights |
|
4808 | # nSamples = dataOut.nHeights | |
4804 | # nChannels = dataOut.nChannels |
|
4809 | # nChannels = dataOut.nChannels | |
4805 | # self.setup(nSamples, nChannels) |
|
4810 | # self.setup(nSamples, nChannels) | |
4806 | # self.isConfig = True |
|
4811 | # self.isConfig = True | |
4807 | # |
|
4812 | # | |
4808 | # #Append new data to internal buffer |
|
4813 | # #Append new data to internal buffer | |
4809 | # for thisChannel in range(self.__nChannels): |
|
4814 | # for thisChannel in range(self.__nChannels): | |
4810 | # bufferByChannel = self.__bufferList[thisChannel] |
|
4815 | # bufferByChannel = self.__bufferList[thisChannel] | |
4811 | # bufferByChannel.extend(dataOut.data[thisChannel]) |
|
4816 | # bufferByChannel.extend(dataOut.data[thisChannel]) | |
4812 | # |
|
4817 | # | |
4813 | # if self.__pulseFound: |
|
4818 | # if self.__pulseFound: | |
4814 | # self.__startIndex -= self.__nSamples |
|
4819 | # self.__startIndex -= self.__nSamples | |
4815 | # |
|
4820 | # | |
4816 | # #Finding Tx Pulse |
|
4821 | # #Finding Tx Pulse | |
4817 | # if not self.__pulseFound: |
|
4822 | # if not self.__pulseFound: | |
4818 | # indexFound = self.__findTxPulse(dataOut, channel) |
|
4823 | # indexFound = self.__findTxPulse(dataOut, channel) | |
4819 | # |
|
4824 | # | |
4820 | # if indexFound == None: |
|
4825 | # if indexFound == None: | |
4821 | # dataOut.flagNoData = True |
|
4826 | # dataOut.flagNoData = True | |
4822 | # return |
|
4827 | # return | |
4823 | # |
|
4828 | # | |
4824 | # self.__arrayBuffer = numpy.zeros((self.__nChannels, self.__newNSamples), dtype = complex) |
|
4829 | # self.__arrayBuffer = numpy.zeros((self.__nChannels, self.__newNSamples), dtype = complex) | |
4825 | # self.__pulseFound = True |
|
4830 | # self.__pulseFound = True | |
4826 | # self.__startIndex = indexFound |
|
4831 | # self.__startIndex = indexFound | |
4827 | # |
|
4832 | # | |
4828 | # #If pulse was found ... |
|
4833 | # #If pulse was found ... | |
4829 | # for thisChannel in range(self.__nChannels): |
|
4834 | # for thisChannel in range(self.__nChannels): | |
4830 | # bufferByChannel = self.__bufferList[thisChannel] |
|
4835 | # bufferByChannel = self.__bufferList[thisChannel] | |
4831 | # #print self.__startIndex |
|
4836 | # #print self.__startIndex | |
4832 | # x = numpy.array(bufferByChannel) |
|
4837 | # x = numpy.array(bufferByChannel) | |
4833 | # self.__arrayBuffer[thisChannel] = x[self.__startIndex:self.__startIndex+self.__newNSamples] |
|
4838 | # self.__arrayBuffer[thisChannel] = x[self.__startIndex:self.__startIndex+self.__newNSamples] | |
4834 | # |
|
4839 | # | |
4835 | # deltaHeight = dataOut.heightList[1] - dataOut.heightList[0] |
|
4840 | # deltaHeight = dataOut.heightList[1] - dataOut.heightList[0] | |
4836 | # dataOut.heightList = numpy.arange(self.__newNSamples)*deltaHeight |
|
4841 | # dataOut.heightList = numpy.arange(self.__newNSamples)*deltaHeight | |
4837 | # # dataOut.ippSeconds = (self.__newNSamples / deltaHeight)/1e6 |
|
4842 | # # dataOut.ippSeconds = (self.__newNSamples / deltaHeight)/1e6 | |
4838 | # |
|
4843 | # | |
4839 | # dataOut.data = self.__arrayBuffer |
|
4844 | # dataOut.data = self.__arrayBuffer | |
4840 | # |
|
4845 | # | |
4841 | # self.__startIndex += self.__newNSamples |
|
4846 | # self.__startIndex += self.__newNSamples | |
4842 | # |
|
4847 | # | |
4843 | # return |
|
4848 | # return | |
4844 |
|
4849 | |||
4845 |
|
4850 | |||
4846 |
|
4851 | |||
4847 |
|
4852 | |||
4848 |
|
4853 | |||
4849 |
|
4854 | |||
4850 |
|
4855 | |||
4851 | ##############################LONG PULSE############################## |
|
4856 | ##############################LONG PULSE############################## | |
4852 |
|
4857 | |||
4853 |
|
4858 | |||
4854 |
|
4859 | |||
4855 | class CrossProdHybrid(CrossProdDP): |
|
4860 | class CrossProdHybrid(CrossProdDP): | |
4856 | """Operation to calculate cross products of the Hybrid Experiment. |
|
4861 | """Operation to calculate cross products of the Hybrid Experiment. | |
4857 |
|
4862 | |||
4858 | Parameters: |
|
4863 | Parameters: | |
4859 | ----------- |
|
4864 | ----------- | |
4860 | NLAG : int |
|
4865 | NLAG : int | |
4861 | Number of lags for Long Pulse. |
|
4866 | Number of lags for Long Pulse. | |
4862 | NRANGE : int |
|
4867 | NRANGE : int | |
4863 | Number of samples (heights) for Long Pulse. |
|
4868 | Number of samples (heights) for Long Pulse. | |
4864 | NCAL : int |
|
4869 | NCAL : int | |
4865 | .* |
|
4870 | .* | |
4866 | DPL : int |
|
4871 | DPL : int | |
4867 | Number of lags for Double Pulse. |
|
4872 | Number of lags for Double Pulse. | |
4868 | NDN : int |
|
4873 | NDN : int | |
4869 | .* |
|
4874 | .* | |
4870 | NDT : int |
|
4875 | NDT : int | |
4871 | Number of heights for Double Pulse.* |
|
4876 | Number of heights for Double Pulse.* | |
4872 | NDP : int |
|
4877 | NDP : int | |
4873 | Number of heights for Double Pulse.* |
|
4878 | Number of heights for Double Pulse.* | |
4874 | NSCAN : int |
|
4879 | NSCAN : int | |
4875 | Number of profiles when the transmitter is on. |
|
4880 | Number of profiles when the transmitter is on. | |
4876 | lagind : intlist |
|
4881 | lagind : intlist | |
4877 | .* |
|
4882 | .* | |
4878 | lagfirst : intlist |
|
4883 | lagfirst : intlist | |
4879 | .* |
|
4884 | .* | |
4880 | NAVG : int |
|
4885 | NAVG : int | |
4881 | Number of blocks to be "averaged". |
|
4886 | Number of blocks to be "averaged". | |
4882 | nkill : int |
|
4887 | nkill : int | |
4883 | Number of blocks not to be considered when averaging. |
|
4888 | Number of blocks not to be considered when averaging. | |
4884 |
|
4889 | |||
4885 | Example |
|
4890 | Example | |
4886 | -------- |
|
4891 | -------- | |
4887 |
|
4892 | |||
4888 | op = proc_unit.addOperation(name='CrossProdHybrid', optype='other') |
|
4893 | op = proc_unit.addOperation(name='CrossProdHybrid', optype='other') | |
4889 | op.addParameter(name='NLAG', value='16', format='int') |
|
4894 | op.addParameter(name='NLAG', value='16', format='int') | |
4890 | op.addParameter(name='NRANGE', value='200', format='int') |
|
4895 | op.addParameter(name='NRANGE', value='200', format='int') | |
4891 | op.addParameter(name='NCAL', value='0', format='int') |
|
4896 | op.addParameter(name='NCAL', value='0', format='int') | |
4892 | op.addParameter(name='DPL', value='11', format='int') |
|
4897 | op.addParameter(name='DPL', value='11', format='int') | |
4893 | op.addParameter(name='NDN', value='0', format='int') |
|
4898 | op.addParameter(name='NDN', value='0', format='int') | |
4894 | op.addParameter(name='NDT', value='67', format='int') |
|
4899 | op.addParameter(name='NDT', value='67', format='int') | |
4895 | op.addParameter(name='NDP', value='67', format='int') |
|
4900 | op.addParameter(name='NDP', value='67', format='int') | |
4896 | op.addParameter(name='NSCAN', value='128', format='int') |
|
4901 | op.addParameter(name='NSCAN', value='128', format='int') | |
4897 | op.addParameter(name='lagind', value='(0,1,2,3,4,5,6,7,0,3,4,5,6,8,9,10)', format='intlist') |
|
4902 | op.addParameter(name='lagind', value='(0,1,2,3,4,5,6,7,0,3,4,5,6,8,9,10)', format='intlist') | |
4898 | op.addParameter(name='lagfirst', value='(1,1,1,1,1,1,1,1,0,0,0,0,0,1,1,1)', format='intlist') |
|
4903 | op.addParameter(name='lagfirst', value='(1,1,1,1,1,1,1,1,0,0,0,0,0,1,1,1)', format='intlist') | |
4899 | op.addParameter(name='NAVG', value='16', format='int') |
|
4904 | op.addParameter(name='NAVG', value='16', format='int') | |
4900 | op.addParameter(name='nkill', value='6', format='int') |
|
4905 | op.addParameter(name='nkill', value='6', format='int') | |
4901 |
|
4906 | |||
4902 | """ |
|
4907 | """ | |
4903 |
|
4908 | |||
4904 | def __init__(self, **kwargs): |
|
4909 | def __init__(self, **kwargs): | |
4905 |
|
4910 | |||
4906 | Operation.__init__(self, **kwargs) |
|
4911 | Operation.__init__(self, **kwargs) | |
4907 | self.bcounter=0 |
|
4912 | self.bcounter=0 | |
4908 | self.aux=1 |
|
4913 | self.aux=1 | |
4909 | self.aux_cross_lp=1 |
|
4914 | self.aux_cross_lp=1 | |
4910 | self.lag_products_LP_median_estimates_aux=1 |
|
4915 | self.lag_products_LP_median_estimates_aux=1 | |
4911 |
|
4916 | |||
4912 | def get_products_cabxys_HP(self,dataOut): |
|
4917 | def get_products_cabxys_HP(self,dataOut): | |
4913 |
|
4918 | |||
4914 | if self.aux==1: |
|
4919 | if self.aux==1: | |
4915 | self.set_header_output(dataOut) |
|
4920 | self.set_header_output(dataOut) | |
4916 | self.aux=0 |
|
4921 | self.aux=0 | |
4917 |
|
4922 | |||
4918 | self.cax=numpy.zeros((dataOut.NDP,dataOut.DPL,2))# hp:67x11x2 dp: 66x11x2 |
|
4923 | self.cax=numpy.zeros((dataOut.NDP,dataOut.DPL,2))# hp:67x11x2 dp: 66x11x2 | |
4919 | self.cay=numpy.zeros((dataOut.NDP,dataOut.DPL,2)) |
|
4924 | self.cay=numpy.zeros((dataOut.NDP,dataOut.DPL,2)) | |
4920 | self.cbx=numpy.zeros((dataOut.NDP,dataOut.DPL,2)) |
|
4925 | self.cbx=numpy.zeros((dataOut.NDP,dataOut.DPL,2)) | |
4921 | self.cby=numpy.zeros((dataOut.NDP,dataOut.DPL,2)) |
|
4926 | self.cby=numpy.zeros((dataOut.NDP,dataOut.DPL,2)) | |
4922 | self.cax2=numpy.zeros((dataOut.NDP,dataOut.DPL,2)) |
|
4927 | self.cax2=numpy.zeros((dataOut.NDP,dataOut.DPL,2)) | |
4923 | self.cay2=numpy.zeros((dataOut.NDP,dataOut.DPL,2)) |
|
4928 | self.cay2=numpy.zeros((dataOut.NDP,dataOut.DPL,2)) | |
4924 | self.cbx2=numpy.zeros((dataOut.NDP,dataOut.DPL,2)) |
|
4929 | self.cbx2=numpy.zeros((dataOut.NDP,dataOut.DPL,2)) | |
4925 | self.cby2=numpy.zeros((dataOut.NDP,dataOut.DPL,2)) |
|
4930 | self.cby2=numpy.zeros((dataOut.NDP,dataOut.DPL,2)) | |
4926 | self.caxbx=numpy.zeros((dataOut.NDP,dataOut.DPL,2)) |
|
4931 | self.caxbx=numpy.zeros((dataOut.NDP,dataOut.DPL,2)) | |
4927 | self.caxby=numpy.zeros((dataOut.NDP,dataOut.DPL,2)) |
|
4932 | self.caxby=numpy.zeros((dataOut.NDP,dataOut.DPL,2)) | |
4928 | self.caybx=numpy.zeros((dataOut.NDP,dataOut.DPL,2)) |
|
4933 | self.caybx=numpy.zeros((dataOut.NDP,dataOut.DPL,2)) | |
4929 | self.cayby=numpy.zeros((dataOut.NDP,dataOut.DPL,2)) |
|
4934 | self.cayby=numpy.zeros((dataOut.NDP,dataOut.DPL,2)) | |
4930 | self.caxay=numpy.zeros((dataOut.NDP,dataOut.DPL,2)) |
|
4935 | self.caxay=numpy.zeros((dataOut.NDP,dataOut.DPL,2)) | |
4931 | self.cbxby=numpy.zeros((dataOut.NDP,dataOut.DPL,2)) |
|
4936 | self.cbxby=numpy.zeros((dataOut.NDP,dataOut.DPL,2)) | |
4932 | for i in range(2): # flipped and unflipped |
|
4937 | for i in range(2): # flipped and unflipped | |
4933 | for j in range(dataOut.NDP): # loop over true ranges # 67 |
|
4938 | for j in range(dataOut.NDP): # loop over true ranges # 67 | |
4934 | for k in range(int(dataOut.NSCAN)): # 128 |
|
4939 | for k in range(int(dataOut.NSCAN)): # 128 | |
4935 |
|
4940 | |||
4936 | n=dataOut.lagind[k%dataOut.NLAG] # 128=16x8 |
|
4941 | n=dataOut.lagind[k%dataOut.NLAG] # 128=16x8 | |
4937 |
|
4942 | |||
4938 | ax=dataOut.data[0,k,dataOut.NRANGE+dataOut.NCAL+j+i*dataOut.NDT].real-dataOut.dc.real[0] |
|
4943 | ax=dataOut.data[0,k,dataOut.NRANGE+dataOut.NCAL+j+i*dataOut.NDT].real-dataOut.dc.real[0] | |
4939 | ay=dataOut.data[0,k,dataOut.NRANGE+dataOut.NCAL+j+i*dataOut.NDT].imag-dataOut.dc.imag[0] |
|
4944 | ay=dataOut.data[0,k,dataOut.NRANGE+dataOut.NCAL+j+i*dataOut.NDT].imag-dataOut.dc.imag[0] | |
4940 |
|
4945 | |||
4941 | if dataOut.NRANGE+dataOut.NCAL+j+i*dataOut.NDT+2*n<dataOut.read_samples: |
|
4946 | if dataOut.NRANGE+dataOut.NCAL+j+i*dataOut.NDT+2*n<dataOut.read_samples: | |
4942 |
|
4947 | |||
4943 | bx=dataOut.data[1,k,dataOut.NRANGE+dataOut.NCAL+j+i*dataOut.NDT+2*n].real-dataOut.dc.real[1] |
|
4948 | bx=dataOut.data[1,k,dataOut.NRANGE+dataOut.NCAL+j+i*dataOut.NDT+2*n].real-dataOut.dc.real[1] | |
4944 | by=dataOut.data[1,k,dataOut.NRANGE+dataOut.NCAL+j+i*dataOut.NDT+2*n].imag-dataOut.dc.imag[1] |
|
4949 | by=dataOut.data[1,k,dataOut.NRANGE+dataOut.NCAL+j+i*dataOut.NDT+2*n].imag-dataOut.dc.imag[1] | |
4945 |
|
4950 | |||
4946 | else: |
|
4951 | else: | |
4947 |
|
4952 | |||
4948 | if k+1<int(dataOut.NSCAN): |
|
4953 | if k+1<int(dataOut.NSCAN): | |
4949 | bx=dataOut.data[1,k+1,(dataOut.NRANGE+dataOut.NCAL+j+i*dataOut.NDT+2*n)%dataOut.NDP].real |
|
4954 | bx=dataOut.data[1,k+1,(dataOut.NRANGE+dataOut.NCAL+j+i*dataOut.NDT+2*n)%dataOut.NDP].real | |
4950 | by=dataOut.data[1,k+1,(dataOut.NRANGE+dataOut.NCAL+j+i*dataOut.NDT+2*n)%dataOut.NDP].imag |
|
4955 | by=dataOut.data[1,k+1,(dataOut.NRANGE+dataOut.NCAL+j+i*dataOut.NDT+2*n)%dataOut.NDP].imag | |
4951 |
|
4956 | |||
4952 | if k+1==int(dataOut.NSCAN):## ESTO ES UN PARCHE PUES NO SE TIENE EL SIGUIENTE BLOQUE |
|
4957 | if k+1==int(dataOut.NSCAN):## ESTO ES UN PARCHE PUES NO SE TIENE EL SIGUIENTE BLOQUE | |
4953 | bx=dataOut.data[1,k,(dataOut.NRANGE+dataOut.NCAL+j+i*dataOut.NDT+2*n)%dataOut.NDP].real |
|
4958 | bx=dataOut.data[1,k,(dataOut.NRANGE+dataOut.NCAL+j+i*dataOut.NDT+2*n)%dataOut.NDP].real | |
4954 | by=dataOut.data[1,k,(dataOut.NRANGE+dataOut.NCAL+j+i*dataOut.NDT+2*n)%dataOut.NDP].imag |
|
4959 | by=dataOut.data[1,k,(dataOut.NRANGE+dataOut.NCAL+j+i*dataOut.NDT+2*n)%dataOut.NDP].imag | |
4955 |
|
4960 | |||
4956 | if(k<dataOut.NLAG and dataOut.lagfirst[k%dataOut.NLAG]==1):# if(k<16 && lagfirst[k%16]==1) |
|
4961 | if(k<dataOut.NLAG and dataOut.lagfirst[k%dataOut.NLAG]==1):# if(k<16 && lagfirst[k%16]==1) | |
4957 | self.cax[j][n][i]=ax |
|
4962 | self.cax[j][n][i]=ax | |
4958 | self.cay[j][n][i]=ay |
|
4963 | self.cay[j][n][i]=ay | |
4959 | self.cbx[j][n][i]=bx |
|
4964 | self.cbx[j][n][i]=bx | |
4960 | self.cby[j][n][i]=by |
|
4965 | self.cby[j][n][i]=by | |
4961 | self.cax2[j][n][i]=ax*ax |
|
4966 | self.cax2[j][n][i]=ax*ax | |
4962 | self.cay2[j][n][i]=ay*ay |
|
4967 | self.cay2[j][n][i]=ay*ay | |
4963 | self.cbx2[j][n][i]=bx*bx |
|
4968 | self.cbx2[j][n][i]=bx*bx | |
4964 | self.cby2[j][n][i]=by*by |
|
4969 | self.cby2[j][n][i]=by*by | |
4965 | self.caxbx[j][n][i]=ax*bx |
|
4970 | self.caxbx[j][n][i]=ax*bx | |
4966 | self.caxby[j][n][i]=ax*by |
|
4971 | self.caxby[j][n][i]=ax*by | |
4967 | self.caybx[j][n][i]=ay*bx |
|
4972 | self.caybx[j][n][i]=ay*bx | |
4968 | self.cayby[j][n][i]=ay*by |
|
4973 | self.cayby[j][n][i]=ay*by | |
4969 | self.caxay[j][n][i]=ax*ay |
|
4974 | self.caxay[j][n][i]=ax*ay | |
4970 | self.cbxby[j][n][i]=bx*by |
|
4975 | self.cbxby[j][n][i]=bx*by | |
4971 | else: |
|
4976 | else: | |
4972 | self.cax[j][n][i]+=ax |
|
4977 | self.cax[j][n][i]+=ax | |
4973 | self.cay[j][n][i]+=ay |
|
4978 | self.cay[j][n][i]+=ay | |
4974 | self.cbx[j][n][i]+=bx |
|
4979 | self.cbx[j][n][i]+=bx | |
4975 | self.cby[j][n][i]+=by |
|
4980 | self.cby[j][n][i]+=by | |
4976 | self.cax2[j][n][i]+=ax*ax |
|
4981 | self.cax2[j][n][i]+=ax*ax | |
4977 | self.cay2[j][n][i]+=ay*ay |
|
4982 | self.cay2[j][n][i]+=ay*ay | |
4978 | self.cbx2[j][n][i]+=bx*bx |
|
4983 | self.cbx2[j][n][i]+=bx*bx | |
4979 | self.cby2[j][n][i]+=by*by |
|
4984 | self.cby2[j][n][i]+=by*by | |
4980 | self.caxbx[j][n][i]+=ax*bx |
|
4985 | self.caxbx[j][n][i]+=ax*bx | |
4981 | self.caxby[j][n][i]+=ax*by |
|
4986 | self.caxby[j][n][i]+=ax*by | |
4982 | self.caybx[j][n][i]+=ay*bx |
|
4987 | self.caybx[j][n][i]+=ay*bx | |
4983 | self.cayby[j][n][i]+=ay*by |
|
4988 | self.cayby[j][n][i]+=ay*by | |
4984 | self.caxay[j][n][i]+=ax*ay |
|
4989 | self.caxay[j][n][i]+=ax*ay | |
4985 | self.cbxby[j][n][i]+=bx*by |
|
4990 | self.cbxby[j][n][i]+=bx*by | |
4986 |
|
4991 | |||
4987 |
|
4992 | |||
4988 | #print(self.cax2[2,0,1]) |
|
4993 | #print(self.cax2[2,0,1]) | |
4989 | #input() |
|
4994 | #input() | |
4990 |
|
4995 | |||
4991 |
|
4996 | |||
4992 | def lag_products_LP(self,dataOut): |
|
4997 | def lag_products_LP(self,dataOut): | |
4993 |
|
4998 | |||
4994 |
|
4999 | |||
4995 | buffer=dataOut.data |
|
5000 | buffer=dataOut.data | |
4996 | if self.aux_cross_lp==1: |
|
5001 | if self.aux_cross_lp==1: | |
4997 |
|
5002 | |||
4998 | #self.dataOut.nptsfft2=150 |
|
5003 | #self.dataOut.nptsfft2=150 | |
4999 | self.cnorm=float((dataOut.nProfiles-dataOut.NSCAN)/dataOut.NSCAN) |
|
5004 | self.cnorm=float((dataOut.nProfiles-dataOut.NSCAN)/dataOut.NSCAN) | |
5000 | self.lagp0=numpy.zeros((dataOut.NLAG,dataOut.NRANGE,dataOut.NAVG),'complex64') |
|
5005 | self.lagp0=numpy.zeros((dataOut.NLAG,dataOut.NRANGE,dataOut.NAVG),'complex64') | |
5001 | self.lagp1=numpy.zeros((dataOut.NLAG,dataOut.NRANGE,dataOut.NAVG),'complex64') |
|
5006 | self.lagp1=numpy.zeros((dataOut.NLAG,dataOut.NRANGE,dataOut.NAVG),'complex64') | |
5002 | self.lagp2=numpy.zeros((dataOut.NLAG,dataOut.NRANGE,dataOut.NAVG),'complex64') |
|
5007 | self.lagp2=numpy.zeros((dataOut.NLAG,dataOut.NRANGE,dataOut.NAVG),'complex64') | |
5003 | self.lagp3=numpy.zeros((dataOut.NLAG,dataOut.NRANGE,dataOut.NAVG),'complex64') |
|
5008 | self.lagp3=numpy.zeros((dataOut.NLAG,dataOut.NRANGE,dataOut.NAVG),'complex64') | |
5004 |
|
5009 | |||
5005 | #self.lagp4=numpy.zeros((dataOut.NLAG,dataOut.NRANGE,dataOut.NAVG),'complex64') |
|
5010 | #self.lagp4=numpy.zeros((dataOut.NLAG,dataOut.NRANGE,dataOut.NAVG),'complex64') | |
5006 | self.aux_cross_lp=0 |
|
5011 | self.aux_cross_lp=0 | |
5007 |
|
5012 | |||
5008 | #print(self.dataOut.data[0,0,0]) |
|
5013 | #print(self.dataOut.data[0,0,0]) | |
5009 |
|
5014 | |||
5010 | for i in range(dataOut.NR): |
|
5015 | for i in range(dataOut.NR): | |
5011 | #print("inside i",i) |
|
5016 | #print("inside i",i) | |
5012 | buffer_dc=dataOut.dc[i] |
|
5017 | buffer_dc=dataOut.dc[i] | |
5013 | for j in range(dataOut.NRANGE): |
|
5018 | for j in range(dataOut.NRANGE): | |
5014 |
|
5019 | |||
5015 | range_for_n=numpy.min((dataOut.NRANGE-j,dataOut.NLAG)) |
|
5020 | range_for_n=numpy.min((dataOut.NRANGE-j,dataOut.NLAG)) | |
5016 |
|
5021 | |||
5017 | buffer_aux=numpy.conj(buffer[i,:dataOut.nProfiles,j]-buffer_dc) |
|
5022 | buffer_aux=numpy.conj(buffer[i,:dataOut.nProfiles,j]-buffer_dc) | |
5018 | for n in range(range_for_n): |
|
5023 | for n in range(range_for_n): | |
5019 |
|
5024 | |||
5020 | c=(buffer_aux)*(buffer[i,:dataOut.nProfiles,j+n]-buffer_dc) |
|
5025 | c=(buffer_aux)*(buffer[i,:dataOut.nProfiles,j+n]-buffer_dc) | |
5021 |
|
5026 | |||
5022 | if i==0: |
|
5027 | if i==0: | |
5023 | self.lagp0[n][j][self.bcounter-1]=numpy.sum(c[:dataOut.NSCAN]) |
|
5028 | self.lagp0[n][j][self.bcounter-1]=numpy.sum(c[:dataOut.NSCAN]) | |
5024 | self.lagp3[n][j][self.bcounter-1]=numpy.sum(c[dataOut.NSCAN:]/self.cnorm) |
|
5029 | self.lagp3[n][j][self.bcounter-1]=numpy.sum(c[dataOut.NSCAN:]/self.cnorm) | |
5025 | elif i==1: |
|
5030 | elif i==1: | |
5026 | self.lagp1[n][j][self.bcounter-1]=numpy.sum(c[:dataOut.NSCAN]) |
|
5031 | self.lagp1[n][j][self.bcounter-1]=numpy.sum(c[:dataOut.NSCAN]) | |
5027 | elif i==2: |
|
5032 | elif i==2: | |
5028 | self.lagp2[n][j][self.bcounter-1]=numpy.sum(c[:dataOut.NSCAN]) |
|
5033 | self.lagp2[n][j][self.bcounter-1]=numpy.sum(c[:dataOut.NSCAN]) | |
5029 |
|
5034 | |||
5030 |
|
5035 | |||
5031 | self.lagp0[:,:,self.bcounter-1]=numpy.conj(self.lagp0[:,:,self.bcounter-1]) |
|
5036 | self.lagp0[:,:,self.bcounter-1]=numpy.conj(self.lagp0[:,:,self.bcounter-1]) | |
5032 | self.lagp1[:,:,self.bcounter-1]=numpy.conj(self.lagp1[:,:,self.bcounter-1]) |
|
5037 | self.lagp1[:,:,self.bcounter-1]=numpy.conj(self.lagp1[:,:,self.bcounter-1]) | |
5033 | self.lagp2[:,:,self.bcounter-1]=numpy.conj(self.lagp2[:,:,self.bcounter-1]) |
|
5038 | self.lagp2[:,:,self.bcounter-1]=numpy.conj(self.lagp2[:,:,self.bcounter-1]) | |
5034 | self.lagp3[:,:,self.bcounter-1]=numpy.conj(self.lagp3[:,:,self.bcounter-1]) |
|
5039 | self.lagp3[:,:,self.bcounter-1]=numpy.conj(self.lagp3[:,:,self.bcounter-1]) | |
5035 |
|
5040 | |||
5036 |
|
5041 | |||
5037 | def LP_median_estimates(self,dataOut): |
|
5042 | def LP_median_estimates(self,dataOut): | |
5038 |
|
5043 | |||
5039 | if self.bcounter==dataOut.NAVG: |
|
5044 | if self.bcounter==dataOut.NAVG: | |
5040 |
|
5045 | |||
5041 | if self.lag_products_LP_median_estimates_aux==1: |
|
5046 | if self.lag_products_LP_median_estimates_aux==1: | |
5042 | self.output=numpy.zeros((dataOut.NLAG,dataOut.NRANGE,dataOut.NR),'complex64') |
|
5047 | self.output=numpy.zeros((dataOut.NLAG,dataOut.NRANGE,dataOut.NR),'complex64') | |
5043 | self.lag_products_LP_median_estimates_aux=0 |
|
5048 | self.lag_products_LP_median_estimates_aux=0 | |
5044 |
|
5049 | |||
5045 |
|
5050 | |||
5046 | for i in range(dataOut.NLAG): |
|
5051 | for i in range(dataOut.NLAG): | |
5047 | for j in range(dataOut.NRANGE): |
|
5052 | for j in range(dataOut.NRANGE): | |
5048 | for l in range(4): #four outputs |
|
5053 | for l in range(4): #four outputs | |
5049 |
|
5054 | |||
5050 | for k in range(dataOut.NAVG): |
|
5055 | for k in range(dataOut.NAVG): | |
5051 |
|
5056 | |||
5052 |
|
5057 | |||
5053 | if k==0: |
|
5058 | if k==0: | |
5054 | self.output[i,j,l]=0.0+0.j |
|
5059 | self.output[i,j,l]=0.0+0.j | |
5055 |
|
5060 | |||
5056 | if l==0: |
|
5061 | if l==0: | |
5057 | self.lagp0[i,j,:]=sorted(self.lagp0[i,j,:], key=lambda x: x.real) #sorted(self.lagp0[i,j,:].real) |
|
5062 | self.lagp0[i,j,:]=sorted(self.lagp0[i,j,:], key=lambda x: x.real) #sorted(self.lagp0[i,j,:].real) | |
5058 |
|
5063 | |||
5059 | if l==1: |
|
5064 | if l==1: | |
5060 | self.lagp1[i,j,:]=sorted(self.lagp1[i,j,:], key=lambda x: x.real) #sorted(self.lagp1[i,j,:].real) |
|
5065 | self.lagp1[i,j,:]=sorted(self.lagp1[i,j,:], key=lambda x: x.real) #sorted(self.lagp1[i,j,:].real) | |
5061 |
|
5066 | |||
5062 | if l==2: |
|
5067 | if l==2: | |
5063 | self.lagp2[i,j,:]=sorted(self.lagp2[i,j,:], key=lambda x: x.real) #sorted(self.lagp2[i,j,:].real) |
|
5068 | self.lagp2[i,j,:]=sorted(self.lagp2[i,j,:], key=lambda x: x.real) #sorted(self.lagp2[i,j,:].real) | |
5064 |
|
5069 | |||
5065 | if l==3: |
|
5070 | if l==3: | |
5066 | self.lagp3[i,j,:]=sorted(self.lagp3[i,j,:], key=lambda x: x.real) #sorted(self.lagp3[i,j,:].real) |
|
5071 | self.lagp3[i,j,:]=sorted(self.lagp3[i,j,:], key=lambda x: x.real) #sorted(self.lagp3[i,j,:].real) | |
5067 |
|
5072 | |||
5068 |
|
5073 | |||
5069 |
|
5074 | |||
5070 | if k>=dataOut.nkill/2 and k<dataOut.NAVG-dataOut.nkill/2: |
|
5075 | if k>=dataOut.nkill/2 and k<dataOut.NAVG-dataOut.nkill/2: | |
5071 | if l==0: |
|
5076 | if l==0: | |
5072 |
|
5077 | |||
5073 | self.output[i,j,l]=self.output[i,j,l]+((float(dataOut.NAVG)/(float)(dataOut.NAVG-dataOut.nkill))*self.lagp0[i,j,k]) |
|
5078 | self.output[i,j,l]=self.output[i,j,l]+((float(dataOut.NAVG)/(float)(dataOut.NAVG-dataOut.nkill))*self.lagp0[i,j,k]) | |
5074 | if l==1: |
|
5079 | if l==1: | |
5075 | #print("lagp1: ",self.lagp1[0,0,:]) |
|
5080 | #print("lagp1: ",self.lagp1[0,0,:]) | |
5076 | #input() |
|
5081 | #input() | |
5077 | self.output[i,j,l]=self.output[i,j,l]+((float(dataOut.NAVG)/(float)(dataOut.NAVG-dataOut.nkill))*self.lagp1[i,j,k]) |
|
5082 | self.output[i,j,l]=self.output[i,j,l]+((float(dataOut.NAVG)/(float)(dataOut.NAVG-dataOut.nkill))*self.lagp1[i,j,k]) | |
5078 | #print("self.lagp1[i,j,k]: ",self.lagp1[i,j,k]) |
|
5083 | #print("self.lagp1[i,j,k]: ",self.lagp1[i,j,k]) | |
5079 | #input() |
|
5084 | #input() | |
5080 | if l==2: |
|
5085 | if l==2: | |
5081 | self.output[i,j,l]=self.output[i,j,l]+((float(dataOut.NAVG)/(float)(dataOut.NAVG-dataOut.nkill))*self.lagp2[i,j,k]) |
|
5086 | self.output[i,j,l]=self.output[i,j,l]+((float(dataOut.NAVG)/(float)(dataOut.NAVG-dataOut.nkill))*self.lagp2[i,j,k]) | |
5082 | if l==3: |
|
5087 | if l==3: | |
5083 |
|
5088 | |||
5084 | self.output[i,j,l]=self.output[i,j,l]+((float(dataOut.NAVG)/(float)(dataOut.NAVG-dataOut.nkill))*self.lagp3[i,j,k]) |
|
5089 | self.output[i,j,l]=self.output[i,j,l]+((float(dataOut.NAVG)/(float)(dataOut.NAVG-dataOut.nkill))*self.lagp3[i,j,k]) | |
5085 |
|
5090 | |||
5086 |
|
5091 | |||
5087 | dataOut.output_LP=self.output |
|
5092 | dataOut.output_LP=self.output | |
5088 | dataOut.data_for_RTI_LP=numpy.zeros((4,dataOut.NRANGE)) |
|
5093 | dataOut.data_for_RTI_LP=numpy.zeros((4,dataOut.NRANGE)) | |
5089 | dataOut.data_for_RTI_LP[0],dataOut.data_for_RTI_LP[1],dataOut.data_for_RTI_LP[2],dataOut.data_for_RTI_LP[3]=self.RTI_LP(dataOut.output_LP,dataOut.NRANGE) |
|
5094 | dataOut.data_for_RTI_LP[0],dataOut.data_for_RTI_LP[1],dataOut.data_for_RTI_LP[2],dataOut.data_for_RTI_LP[3]=self.RTI_LP(dataOut.output_LP,dataOut.NRANGE) | |
5090 |
|
5095 | |||
5091 |
|
5096 | |||
5092 | def get_dc(self,dataOut): |
|
5097 | def get_dc(self,dataOut): | |
5093 |
|
5098 | |||
5094 | if self.bcounter==0: |
|
5099 | if self.bcounter==0: | |
5095 | dataOut.dc=numpy.zeros(dataOut.NR,dtype='complex64') |
|
5100 | dataOut.dc=numpy.zeros(dataOut.NR,dtype='complex64') | |
5096 |
|
5101 | |||
5097 | #print(numpy.shape(dataOut.data)) |
|
5102 | #print(numpy.shape(dataOut.data)) | |
5098 | #input() |
|
5103 | #input() | |
5099 |
|
5104 | |||
5100 | dataOut.dc+=numpy.sum(dataOut.data[:,:,2*dataOut.NLAG:dataOut.NRANGE],axis=(1,2)) |
|
5105 | dataOut.dc+=numpy.sum(dataOut.data[:,:,2*dataOut.NLAG:dataOut.NRANGE],axis=(1,2)) | |
5101 |
|
5106 | |||
5102 | dataOut.dc=dataOut.dc/float(dataOut.nProfiles*(dataOut.NRANGE-2*dataOut.NLAG)) |
|
5107 | dataOut.dc=dataOut.dc/float(dataOut.nProfiles*(dataOut.NRANGE-2*dataOut.NLAG)) | |
5103 |
|
5108 | |||
5104 |
|
5109 | |||
5105 | #print("dc:",dataOut.dc[0]) |
|
5110 | #print("dc:",dataOut.dc[0]) | |
5106 |
|
5111 | |||
5107 | def get_dc_new(self,dataOut): |
|
5112 | def get_dc_new(self,dataOut): | |
5108 |
|
5113 | |||
5109 | if self.bcounter==0: |
|
5114 | if self.bcounter==0: | |
5110 | dataOut.dc_dp=numpy.zeros(dataOut.NR,dtype='complex64') |
|
5115 | dataOut.dc_dp=numpy.zeros(dataOut.NR,dtype='complex64') | |
5111 | dataOut.dc_lp=numpy.zeros(dataOut.NR,dtype='complex64') |
|
5116 | dataOut.dc_lp=numpy.zeros(dataOut.NR,dtype='complex64') | |
5112 |
|
5117 | |||
5113 | #print(numpy.shape(dataOut.data)) |
|
5118 | #print(numpy.shape(dataOut.data)) | |
5114 | #input() |
|
5119 | #input() | |
5115 |
|
5120 | |||
5116 | dataOut.dc+=numpy.sum(dataOut.data[:,:,2*dataOut.NLAG:dataOut.NRANGE],axis=(1,2)) |
|
5121 | dataOut.dc+=numpy.sum(dataOut.data[:,:,2*dataOut.NLAG:dataOut.NRANGE],axis=(1,2)) | |
5117 |
|
5122 | |||
5118 | dataOut.dc=dataOut.dc/float(dataOut.nProfiles*(dataOut.NRANGE-2*dataOut.NLAG)) |
|
5123 | dataOut.dc=dataOut.dc/float(dataOut.nProfiles*(dataOut.NRANGE-2*dataOut.NLAG)) | |
5119 |
|
5124 | |||
5120 |
|
5125 | |||
5121 | #print("dc:",dataOut.dc[0]) |
|
5126 | #print("dc:",dataOut.dc[0]) | |
5122 |
|
5127 | |||
5123 |
|
5128 | |||
5124 | def noise_estimation4x_HP(self,dataOut): |
|
5129 | def noise_estimation4x_HP(self,dataOut): | |
5125 | if self.bcounter==dataOut.NAVG: |
|
5130 | if self.bcounter==dataOut.NAVG: | |
5126 | dataOut.noise_final=numpy.zeros(dataOut.NR,'float32') |
|
5131 | dataOut.noise_final=numpy.zeros(dataOut.NR,'float32') | |
5127 | #snoise=numpy.zeros((NR,NAVG),'float32') |
|
5132 | #snoise=numpy.zeros((NR,NAVG),'float32') | |
5128 | #nvector1=numpy.zeros((NR,NAVG,MAXNRANGENDT),'float32') |
|
5133 | #nvector1=numpy.zeros((NR,NAVG,MAXNRANGENDT),'float32') | |
5129 | sorted_data=numpy.zeros((dataOut.MAXNRANGENDT,dataOut.NR,dataOut.NAVG),'float32') |
|
5134 | sorted_data=numpy.zeros((dataOut.MAXNRANGENDT,dataOut.NR,dataOut.NAVG),'float32') | |
5130 | for i in range(dataOut.NR): |
|
5135 | for i in range(dataOut.NR): | |
5131 | dataOut.noise_final[i]=0.0 |
|
5136 | dataOut.noise_final[i]=0.0 | |
5132 | for j in range(dataOut.MAXNRANGENDT): |
|
5137 | for j in range(dataOut.MAXNRANGENDT): | |
5133 | sorted_data[j,i,:]=numpy.copy(sorted(dataOut.noisevector[j,i,:])) |
|
5138 | sorted_data[j,i,:]=numpy.copy(sorted(dataOut.noisevector[j,i,:])) | |
5134 | #print(sorted(noisevector[j,i,:])) |
|
5139 | #print(sorted(noisevector[j,i,:])) | |
5135 | #input() |
|
5140 | #input() | |
5136 | l=dataOut.MAXNRANGENDT-2 |
|
5141 | l=dataOut.MAXNRANGENDT-2 | |
5137 | for k in range(dataOut.NAVG): |
|
5142 | for k in range(dataOut.NAVG): | |
5138 | if k>=dataOut.nkill/2 and k<dataOut.NAVG-dataOut.nkill/2: |
|
5143 | if k>=dataOut.nkill/2 and k<dataOut.NAVG-dataOut.nkill/2: | |
5139 | #print(k) |
|
5144 | #print(k) | |
5140 | #print(sorted_data[min(j,l),i,k]) |
|
5145 | #print(sorted_data[min(j,l),i,k]) | |
5141 | dataOut.noise_final[i]+=sorted_data[min(j,l),i,k]*float(dataOut.NAVG)/float(dataOut.NAVG-dataOut.nkill) |
|
5146 | dataOut.noise_final[i]+=sorted_data[min(j,l),i,k]*float(dataOut.NAVG)/float(dataOut.NAVG-dataOut.nkill) | |
5142 | #print(dataOut.noise_final[i]) |
|
5147 | #print(dataOut.noise_final[i]) | |
5143 | #input() |
|
5148 | #input() | |
5144 | #print(dataOut.noise_final) |
|
5149 | #print(dataOut.noise_final) | |
5145 | #input() |
|
5150 | #input() | |
5146 |
|
5151 | |||
5147 | def noisevectorizer(self,NSCAN,nProfiles,NR,MAXNRANGENDT,noisevector,data,dc): |
|
5152 | def noisevectorizer(self,NSCAN,nProfiles,NR,MAXNRANGENDT,noisevector,data,dc): | |
5148 |
|
5153 | |||
5149 | #rnormalizer= 1./(float(nProfiles - NSCAN)) |
|
5154 | #rnormalizer= 1./(float(nProfiles - NSCAN)) | |
5150 | rnormalizer= float(NSCAN)/((float(nProfiles - NSCAN))*float(MAXNRANGENDT)) |
|
5155 | rnormalizer= float(NSCAN)/((float(nProfiles - NSCAN))*float(MAXNRANGENDT)) | |
5151 | for i in range(NR): |
|
5156 | for i in range(NR): | |
5152 | for j in range(MAXNRANGENDT): |
|
5157 | for j in range(MAXNRANGENDT): | |
5153 | for k in range(NSCAN,nProfiles): |
|
5158 | for k in range(NSCAN,nProfiles): | |
5154 | #TODO:integrate just 2nd quartile gates |
|
5159 | #TODO:integrate just 2nd quartile gates | |
5155 | if k==NSCAN: |
|
5160 | if k==NSCAN: | |
5156 | noisevector[j][i][self.bcounter]=(abs(data[i][k][j]-dc[i])**2)*rnormalizer |
|
5161 | noisevector[j][i][self.bcounter]=(abs(data[i][k][j]-dc[i])**2)*rnormalizer | |
5157 | ##noisevector[j][i][iavg]=(abs(cdata[k][j][i])**2)*rnormalizer |
|
5162 | ##noisevector[j][i][iavg]=(abs(cdata[k][j][i])**2)*rnormalizer | |
5158 | else: |
|
5163 | else: | |
5159 | noisevector[j][i][self.bcounter]+=(abs(data[i][k][j]-dc[i])**2)*rnormalizer |
|
5164 | noisevector[j][i][self.bcounter]+=(abs(data[i][k][j]-dc[i])**2)*rnormalizer | |
5160 |
|
5165 | |||
5161 |
|
5166 | |||
5162 | def RTI_LP(self,output,NRANGE): |
|
5167 | def RTI_LP(self,output,NRANGE): | |
5163 | x00=numpy.zeros(NRANGE,dtype='float32') |
|
5168 | x00=numpy.zeros(NRANGE,dtype='float32') | |
5164 | x01=numpy.zeros(NRANGE,dtype='float32') |
|
5169 | x01=numpy.zeros(NRANGE,dtype='float32') | |
5165 | x02=numpy.zeros(NRANGE,dtype='float32') |
|
5170 | x02=numpy.zeros(NRANGE,dtype='float32') | |
5166 | x03=numpy.zeros(NRANGE,dtype='float32') |
|
5171 | x03=numpy.zeros(NRANGE,dtype='float32') | |
5167 |
|
5172 | |||
5168 | for i in range(2): #first couple of lags |
|
5173 | for i in range(2): #first couple of lags | |
5169 | for j in range(NRANGE): # |
|
5174 | for j in range(NRANGE): # | |
5170 | #fx=numpy.sqrt((kaxbx[i,j,k]+kayby[i,j,k])**2+(kaybx[i,j,k]-kaxby[i,j,k])**2) |
|
5175 | #fx=numpy.sqrt((kaxbx[i,j,k]+kayby[i,j,k])**2+(kaybx[i,j,k]-kaxby[i,j,k])**2) | |
5171 | x00[j]+=numpy.abs(output[i,j,0]) #Ch0 |
|
5176 | x00[j]+=numpy.abs(output[i,j,0]) #Ch0 | |
5172 | x01[j]+=numpy.abs(output[i,j,1]) #Ch1 |
|
5177 | x01[j]+=numpy.abs(output[i,j,1]) #Ch1 | |
5173 | x02[j]+=numpy.abs(output[i,j,2]) #Ch2 |
|
5178 | x02[j]+=numpy.abs(output[i,j,2]) #Ch2 | |
5174 | x03[j]+=numpy.abs(output[i,j,3]) #Ch3 |
|
5179 | x03[j]+=numpy.abs(output[i,j,3]) #Ch3 | |
5175 | #x02[i]=x02[i]+fx |
|
5180 | #x02[i]=x02[i]+fx | |
5176 |
|
5181 | |||
5177 | x00[j]=10.0*numpy.log10(x00[j]/4.) |
|
5182 | x00[j]=10.0*numpy.log10(x00[j]/4.) | |
5178 | x01[j]=10.0*numpy.log10(x01[j]/4.) |
|
5183 | x01[j]=10.0*numpy.log10(x01[j]/4.) | |
5179 | x02[j]=10.0*numpy.log10(x02[j]/4.) |
|
5184 | x02[j]=10.0*numpy.log10(x02[j]/4.) | |
5180 | x03[j]=10.0*numpy.log10(x03[j]/4.) |
|
5185 | x03[j]=10.0*numpy.log10(x03[j]/4.) | |
5181 | #x02[i]=10.0*numpy.log10(x02[i]) |
|
5186 | #x02[i]=10.0*numpy.log10(x02[i]) | |
5182 | return x00,x01,x02,x03 |
|
5187 | return x00,x01,x02,x03 | |
5183 |
|
5188 | |||
5184 | def run(self, dataOut, NLAG=None, NRANGE=None, NCAL=None, DPL=None, |
|
5189 | def run(self, dataOut, NLAG=None, NRANGE=None, NCAL=None, DPL=None, | |
5185 | NDN=None, NDT=None, NDP=None, NSCAN=None, |
|
5190 | NDN=None, NDT=None, NDP=None, NSCAN=None, | |
5186 | lagind=None, lagfirst=None, |
|
5191 | lagind=None, lagfirst=None, | |
5187 | NAVG=None, nkill=None): |
|
5192 | NAVG=None, nkill=None): | |
5188 |
|
5193 | |||
5189 | dataOut.NLAG=NLAG |
|
5194 | dataOut.NLAG=NLAG | |
5190 | dataOut.NR=len(dataOut.channelList) |
|
5195 | dataOut.NR=len(dataOut.channelList) | |
5191 | dataOut.NRANGE=NRANGE |
|
5196 | dataOut.NRANGE=NRANGE | |
5192 | dataOut.NCAL=NCAL |
|
5197 | dataOut.NCAL=NCAL | |
5193 | dataOut.DPL=DPL |
|
5198 | dataOut.DPL=DPL | |
5194 | dataOut.NDN=NDN |
|
5199 | dataOut.NDN=NDN | |
5195 | dataOut.NDT=NDT |
|
5200 | dataOut.NDT=NDT | |
5196 | dataOut.NDP=NDP |
|
5201 | dataOut.NDP=NDP | |
5197 | dataOut.NSCAN=NSCAN |
|
5202 | dataOut.NSCAN=NSCAN | |
5198 | dataOut.DH=dataOut.heightList[1]-dataOut.heightList[0] |
|
5203 | dataOut.DH=dataOut.heightList[1]-dataOut.heightList[0] | |
5199 | dataOut.H0=int(dataOut.heightList[0]) |
|
5204 | dataOut.H0=int(dataOut.heightList[0]) | |
5200 | dataOut.lagind=lagind |
|
5205 | dataOut.lagind=lagind | |
5201 | dataOut.lagfirst=lagfirst |
|
5206 | dataOut.lagfirst=lagfirst | |
5202 | dataOut.NAVG=NAVG |
|
5207 | dataOut.NAVG=NAVG | |
5203 | dataOut.nkill=nkill |
|
5208 | dataOut.nkill=nkill | |
5204 |
|
5209 | |||
5205 | dataOut.flagNoData = True |
|
5210 | dataOut.flagNoData = True | |
5206 |
|
5211 | |||
5207 | self.get_dc(dataOut) |
|
5212 | self.get_dc(dataOut) | |
5208 | self.get_products_cabxys_HP(dataOut) |
|
5213 | self.get_products_cabxys_HP(dataOut) | |
5209 | self.cabxys_navg(dataOut) |
|
5214 | self.cabxys_navg(dataOut) | |
5210 | self.lag_products_LP(dataOut) |
|
5215 | self.lag_products_LP(dataOut) | |
5211 | self.LP_median_estimates(dataOut) |
|
5216 | self.LP_median_estimates(dataOut) | |
5212 | self.noise_estimation4x_HP(dataOut) |
|
5217 | self.noise_estimation4x_HP(dataOut) | |
5213 | self.kabxys(dataOut) |
|
5218 | self.kabxys(dataOut) | |
5214 |
|
5219 | |||
5215 | return dataOut |
|
5220 | return dataOut | |
5216 |
|
5221 | |||
5217 |
|
5222 | |||
5218 | class CrossProdLP(CrossProdDP): |
|
5223 | class CrossProdLP(CrossProdDP): | |
5219 | """Operation to calculate cross products of the Hybrid Experiment. |
|
5224 | """Operation to calculate cross products of the Hybrid Experiment. | |
5220 |
|
5225 | |||
5221 | Parameters: |
|
5226 | Parameters: | |
5222 | ----------- |
|
5227 | ----------- | |
5223 | NLAG : int |
|
5228 | NLAG : int | |
5224 | Number of lags for Long Pulse. |
|
5229 | Number of lags for Long Pulse. | |
5225 | NRANGE : int |
|
5230 | NRANGE : int | |
5226 | Number of samples (heights) for Long Pulse. |
|
5231 | Number of samples (heights) for Long Pulse. | |
5227 | NCAL : int |
|
5232 | NCAL : int | |
5228 | .* |
|
5233 | .* | |
5229 | DPL : int |
|
5234 | DPL : int | |
5230 | Number of lags for Double Pulse. |
|
5235 | Number of lags for Double Pulse. | |
5231 | NDN : int |
|
5236 | NDN : int | |
5232 | .* |
|
5237 | .* | |
5233 | NDT : int |
|
5238 | NDT : int | |
5234 | Number of heights for Double Pulse.* |
|
5239 | Number of heights for Double Pulse.* | |
5235 | NDP : int |
|
5240 | NDP : int | |
5236 | Number of heights for Double Pulse.* |
|
5241 | Number of heights for Double Pulse.* | |
5237 | NSCAN : int |
|
5242 | NSCAN : int | |
5238 | Number of profiles when the transmitter is on. |
|
5243 | Number of profiles when the transmitter is on. | |
5239 | lagind : intlist |
|
5244 | lagind : intlist | |
5240 | .* |
|
5245 | .* | |
5241 | lagfirst : intlist |
|
5246 | lagfirst : intlist | |
5242 | .* |
|
5247 | .* | |
5243 | NAVG : int |
|
5248 | NAVG : int | |
5244 | Number of blocks to be "averaged". |
|
5249 | Number of blocks to be "averaged". | |
5245 | nkill : int |
|
5250 | nkill : int | |
5246 | Number of blocks not to be considered when averaging. |
|
5251 | Number of blocks not to be considered when averaging. | |
5247 |
|
5252 | |||
5248 | Example |
|
5253 | Example | |
5249 | -------- |
|
5254 | -------- | |
5250 |
|
5255 | |||
5251 | op = proc_unit.addOperation(name='CrossProdHybrid', optype='other') |
|
5256 | op = proc_unit.addOperation(name='CrossProdHybrid', optype='other') | |
5252 | op.addParameter(name='NLAG', value='16', format='int') |
|
5257 | op.addParameter(name='NLAG', value='16', format='int') | |
5253 | op.addParameter(name='NRANGE', value='200', format='int') |
|
5258 | op.addParameter(name='NRANGE', value='200', format='int') | |
5254 | op.addParameter(name='NCAL', value='0', format='int') |
|
5259 | op.addParameter(name='NCAL', value='0', format='int') | |
5255 | op.addParameter(name='DPL', value='11', format='int') |
|
5260 | op.addParameter(name='DPL', value='11', format='int') | |
5256 | op.addParameter(name='NDN', value='0', format='int') |
|
5261 | op.addParameter(name='NDN', value='0', format='int') | |
5257 | op.addParameter(name='NDT', value='67', format='int') |
|
5262 | op.addParameter(name='NDT', value='67', format='int') | |
5258 | op.addParameter(name='NDP', value='67', format='int') |
|
5263 | op.addParameter(name='NDP', value='67', format='int') | |
5259 | op.addParameter(name='NSCAN', value='128', format='int') |
|
5264 | op.addParameter(name='NSCAN', value='128', format='int') | |
5260 | op.addParameter(name='lagind', value='(0,1,2,3,4,5,6,7,0,3,4,5,6,8,9,10)', format='intlist') |
|
5265 | op.addParameter(name='lagind', value='(0,1,2,3,4,5,6,7,0,3,4,5,6,8,9,10)', format='intlist') | |
5261 | op.addParameter(name='lagfirst', value='(1,1,1,1,1,1,1,1,0,0,0,0,0,1,1,1)', format='intlist') |
|
5266 | op.addParameter(name='lagfirst', value='(1,1,1,1,1,1,1,1,0,0,0,0,0,1,1,1)', format='intlist') | |
5262 | op.addParameter(name='NAVG', value='16', format='int') |
|
5267 | op.addParameter(name='NAVG', value='16', format='int') | |
5263 | op.addParameter(name='nkill', value='6', format='int') |
|
5268 | op.addParameter(name='nkill', value='6', format='int') | |
5264 |
|
5269 | |||
5265 | """ |
|
5270 | """ | |
5266 |
|
5271 | |||
5267 | def __init__(self, **kwargs): |
|
5272 | def __init__(self, **kwargs): | |
5268 |
|
5273 | |||
5269 | Operation.__init__(self, **kwargs) |
|
5274 | Operation.__init__(self, **kwargs) | |
5270 | self.bcounter=0 |
|
5275 | self.bcounter=0 | |
5271 | self.aux=1 |
|
5276 | self.aux=1 | |
5272 | self.aux_cross_lp=1 |
|
5277 | self.aux_cross_lp=1 | |
5273 | self.lag_products_LP_median_estimates_aux=1 |
|
5278 | self.lag_products_LP_median_estimates_aux=1 | |
5274 |
|
5279 | |||
5275 |
|
5280 | |||
5276 |
|
5281 | |||
5277 | #print(self.cax2[2,0,1]) |
|
5282 | #print(self.cax2[2,0,1]) | |
5278 | #input() |
|
5283 | #input() | |
5279 |
|
5284 | |||
5280 |
|
5285 | |||
5281 | def lag_products_LP(self,dataOut): |
|
5286 | def lag_products_LP(self,dataOut): | |
5282 |
|
5287 | |||
5283 |
|
5288 | |||
5284 | buffer=dataOut.data |
|
5289 | buffer=dataOut.data | |
5285 | if self.aux_cross_lp==1: |
|
5290 | if self.aux_cross_lp==1: | |
5286 |
|
5291 | |||
5287 | #self.dataOut.nptsfft2=150 |
|
5292 | #self.dataOut.nptsfft2=150 | |
5288 | self.cnorm=float((dataOut.nProfiles-dataOut.NSCAN)/dataOut.NSCAN) |
|
5293 | self.cnorm=float((dataOut.nProfiles-dataOut.NSCAN)/dataOut.NSCAN) | |
5289 | self.lagp0=numpy.zeros((dataOut.NLAG,dataOut.NRANGE,dataOut.NAVG),'complex64') |
|
5294 | self.lagp0=numpy.zeros((dataOut.NLAG,dataOut.NRANGE,dataOut.NAVG),'complex64') | |
5290 | self.lagp1=numpy.zeros((dataOut.NLAG,dataOut.NRANGE,dataOut.NAVG),'complex64') |
|
5295 | self.lagp1=numpy.zeros((dataOut.NLAG,dataOut.NRANGE,dataOut.NAVG),'complex64') | |
5291 | self.lagp2=numpy.zeros((dataOut.NLAG,dataOut.NRANGE,dataOut.NAVG),'complex64') |
|
5296 | self.lagp2=numpy.zeros((dataOut.NLAG,dataOut.NRANGE,dataOut.NAVG),'complex64') | |
5292 | self.lagp3=numpy.zeros((dataOut.NLAG,dataOut.NRANGE,dataOut.NAVG),'complex64') |
|
5297 | self.lagp3=numpy.zeros((dataOut.NLAG,dataOut.NRANGE,dataOut.NAVG),'complex64') | |
5293 | self.lagp4=numpy.zeros((dataOut.NLAG,dataOut.NRANGE,dataOut.NAVG),'complex64') |
|
5298 | self.lagp4=numpy.zeros((dataOut.NLAG,dataOut.NRANGE,dataOut.NAVG),'complex64') | |
5294 | self.lagp5=numpy.zeros((dataOut.NLAG,dataOut.NRANGE,dataOut.NAVG),'complex64') |
|
5299 | self.lagp5=numpy.zeros((dataOut.NLAG,dataOut.NRANGE,dataOut.NAVG),'complex64') | |
5295 |
|
5300 | |||
5296 | #self.lagp4=numpy.zeros((dataOut.NLAG,dataOut.NRANGE,dataOut.NAVG),'complex64') |
|
5301 | #self.lagp4=numpy.zeros((dataOut.NLAG,dataOut.NRANGE,dataOut.NAVG),'complex64') | |
5297 | self.aux_cross_lp=0 |
|
5302 | self.aux_cross_lp=0 | |
5298 |
|
5303 | |||
5299 | dataOut.noisevector=numpy.zeros((dataOut.MAXNRANGENDT,dataOut.NR,dataOut.NAVG),'float32') |
|
5304 | dataOut.noisevector=numpy.zeros((dataOut.MAXNRANGENDT,dataOut.NR,dataOut.NAVG),'float32') | |
5300 |
|
5305 | |||
5301 | #print(self.dataOut.data[0,0,0]) |
|
5306 | #print(self.dataOut.data[0,0,0]) | |
5302 | self.noisevectorizer(dataOut.NSCAN,dataOut.nProfiles,dataOut.NR,dataOut.MAXNRANGENDT,dataOut.noisevector,dataOut.data,dataOut.dc) #30/03/2020 |
|
5307 | self.noisevectorizer(dataOut.NSCAN,dataOut.nProfiles,dataOut.NR,dataOut.MAXNRANGENDT,dataOut.noisevector,dataOut.data,dataOut.dc) #30/03/2020 | |
5303 |
|
5308 | |||
5304 |
|
5309 | |||
5305 | for i in range(dataOut.NR): |
|
5310 | for i in range(dataOut.NR): | |
5306 | #print("inside i",i) |
|
5311 | #print("inside i",i) | |
5307 | buffer_dc=dataOut.dc[i] |
|
5312 | buffer_dc=dataOut.dc[i] | |
5308 | for j in range(dataOut.NRANGE): |
|
5313 | for j in range(dataOut.NRANGE): | |
5309 |
|
5314 | |||
5310 | range_for_n=numpy.min((dataOut.NRANGE-j,dataOut.NLAG)) |
|
5315 | range_for_n=numpy.min((dataOut.NRANGE-j,dataOut.NLAG)) | |
5311 |
|
5316 | |||
5312 | buffer_aux=numpy.conj(buffer[i,:dataOut.nProfiles,j]-buffer_dc) |
|
5317 | buffer_aux=numpy.conj(buffer[i,:dataOut.nProfiles,j]-buffer_dc) | |
5313 | for n in range(range_for_n): |
|
5318 | for n in range(range_for_n): | |
5314 |
|
5319 | |||
5315 | c=(buffer_aux)*(buffer[i,:dataOut.nProfiles,j+n]-buffer_dc) |
|
5320 | c=(buffer_aux)*(buffer[i,:dataOut.nProfiles,j+n]-buffer_dc) | |
5316 |
|
5321 | |||
5317 | if i==0: |
|
5322 | if i==0: | |
5318 | self.lagp0[n][j][self.bcounter]=numpy.sum(c[:dataOut.NSCAN]) |
|
5323 | self.lagp0[n][j][self.bcounter]=numpy.sum(c[:dataOut.NSCAN]) | |
5319 | #self.lagp3[n][j][self.bcounter-1]=numpy.sum(c[dataOut.NSCAN:]/self.cnorm) |
|
5324 | #self.lagp3[n][j][self.bcounter-1]=numpy.sum(c[dataOut.NSCAN:]/self.cnorm) | |
5320 | elif i==1: |
|
5325 | elif i==1: | |
5321 | self.lagp1[n][j][self.bcounter]=numpy.sum(c[:dataOut.NSCAN]) |
|
5326 | self.lagp1[n][j][self.bcounter]=numpy.sum(c[:dataOut.NSCAN]) | |
5322 | elif i==2: |
|
5327 | elif i==2: | |
5323 | self.lagp2[n][j][self.bcounter]=numpy.sum(c[:dataOut.NSCAN]) |
|
5328 | self.lagp2[n][j][self.bcounter]=numpy.sum(c[:dataOut.NSCAN]) | |
5324 | elif i==3: |
|
5329 | elif i==3: | |
5325 | self.lagp3[n][j][self.bcounter]=numpy.sum(c[:dataOut.NSCAN]) |
|
5330 | self.lagp3[n][j][self.bcounter]=numpy.sum(c[:dataOut.NSCAN]) | |
5326 | elif i==4: |
|
5331 | elif i==4: | |
5327 | self.lagp4[n][j][self.bcounter]=numpy.sum(c[:dataOut.NSCAN]) |
|
5332 | self.lagp4[n][j][self.bcounter]=numpy.sum(c[:dataOut.NSCAN]) | |
5328 | elif i==5: |
|
5333 | elif i==5: | |
5329 | self.lagp5[n][j][self.bcounter]=numpy.sum(c[:dataOut.NSCAN]) |
|
5334 | self.lagp5[n][j][self.bcounter]=numpy.sum(c[:dataOut.NSCAN]) | |
5330 |
|
5335 | |||
5331 |
|
5336 | |||
5332 | self.lagp0[:,:,self.bcounter]=numpy.conj(self.lagp0[:,:,self.bcounter]) |
|
5337 | self.lagp0[:,:,self.bcounter]=numpy.conj(self.lagp0[:,:,self.bcounter]) | |
5333 | self.lagp1[:,:,self.bcounter]=numpy.conj(self.lagp1[:,:,self.bcounter]) |
|
5338 | self.lagp1[:,:,self.bcounter]=numpy.conj(self.lagp1[:,:,self.bcounter]) | |
5334 | self.lagp2[:,:,self.bcounter]=numpy.conj(self.lagp2[:,:,self.bcounter]) |
|
5339 | self.lagp2[:,:,self.bcounter]=numpy.conj(self.lagp2[:,:,self.bcounter]) | |
5335 | self.lagp3[:,:,self.bcounter]=numpy.conj(self.lagp3[:,:,self.bcounter]) |
|
5340 | self.lagp3[:,:,self.bcounter]=numpy.conj(self.lagp3[:,:,self.bcounter]) | |
5336 |
|
5341 | |||
5337 | self.bcounter += 1 |
|
5342 | self.bcounter += 1 | |
5338 |
|
5343 | |||
5339 |
|
5344 | |||
5340 | def LP_median_estimates(self,dataOut): |
|
5345 | def LP_median_estimates(self,dataOut): | |
5341 |
|
5346 | |||
5342 | if self.bcounter==dataOut.NAVG: |
|
5347 | if self.bcounter==dataOut.NAVG: | |
5343 | dataOut.flagNoData = False |
|
5348 | dataOut.flagNoData = False | |
5344 |
|
5349 | |||
5345 | if self.lag_products_LP_median_estimates_aux==1: |
|
5350 | if self.lag_products_LP_median_estimates_aux==1: | |
5346 | self.output=numpy.zeros((dataOut.NLAG,dataOut.NRANGE,dataOut.NR),'complex64') |
|
5351 | self.output=numpy.zeros((dataOut.NLAG,dataOut.NRANGE,dataOut.NR),'complex64') | |
5347 | self.lag_products_LP_median_estimates_aux=0 |
|
5352 | self.lag_products_LP_median_estimates_aux=0 | |
5348 |
|
5353 | |||
5349 |
|
5354 | |||
5350 | for i in range(dataOut.NLAG): |
|
5355 | for i in range(dataOut.NLAG): | |
5351 | for j in range(dataOut.NRANGE): |
|
5356 | for j in range(dataOut.NRANGE): | |
5352 | for l in range(4): #four outputs |
|
5357 | for l in range(4): #four outputs | |
5353 |
|
5358 | |||
5354 | for k in range(dataOut.NAVG): |
|
5359 | for k in range(dataOut.NAVG): | |
5355 |
|
5360 | |||
5356 |
|
5361 | |||
5357 | if k==0: |
|
5362 | if k==0: | |
5358 | self.output[i,j,l]=0.0+0.j |
|
5363 | self.output[i,j,l]=0.0+0.j | |
5359 |
|
5364 | |||
5360 | if l==0: |
|
5365 | if l==0: | |
5361 | self.lagp0[i,j,:]=sorted(self.lagp0[i,j,:], key=lambda x: x.real) #sorted(self.lagp0[i,j,:].real) |
|
5366 | self.lagp0[i,j,:]=sorted(self.lagp0[i,j,:], key=lambda x: x.real) #sorted(self.lagp0[i,j,:].real) | |
5362 |
|
5367 | |||
5363 | if l==1: |
|
5368 | if l==1: | |
5364 | self.lagp1[i,j,:]=sorted(self.lagp1[i,j,:], key=lambda x: x.real) #sorted(self.lagp1[i,j,:].real) |
|
5369 | self.lagp1[i,j,:]=sorted(self.lagp1[i,j,:], key=lambda x: x.real) #sorted(self.lagp1[i,j,:].real) | |
5365 |
|
5370 | |||
5366 | if l==2: |
|
5371 | if l==2: | |
5367 | self.lagp2[i,j,:]=sorted(self.lagp2[i,j,:], key=lambda x: x.real) #sorted(self.lagp2[i,j,:].real) |
|
5372 | self.lagp2[i,j,:]=sorted(self.lagp2[i,j,:], key=lambda x: x.real) #sorted(self.lagp2[i,j,:].real) | |
5368 |
|
5373 | |||
5369 | if l==3: |
|
5374 | if l==3: | |
5370 | self.lagp3[i,j,:]=sorted(self.lagp3[i,j,:], key=lambda x: x.real) #sorted(self.lagp3[i,j,:].real) |
|
5375 | self.lagp3[i,j,:]=sorted(self.lagp3[i,j,:], key=lambda x: x.real) #sorted(self.lagp3[i,j,:].real) | |
5371 |
|
5376 | |||
5372 |
|
5377 | |||
5373 |
|
5378 | |||
5374 | if k>=dataOut.nkill/2 and k<dataOut.NAVG-dataOut.nkill/2: |
|
5379 | if k>=dataOut.nkill/2 and k<dataOut.NAVG-dataOut.nkill/2: | |
5375 | if l==0: |
|
5380 | if l==0: | |
5376 |
|
5381 | |||
5377 | self.output[i,j,l]=self.output[i,j,l]+((float(dataOut.NAVG)/(float)(dataOut.NAVG-dataOut.nkill))*self.lagp0[i,j,k]) |
|
5382 | self.output[i,j,l]=self.output[i,j,l]+((float(dataOut.NAVG)/(float)(dataOut.NAVG-dataOut.nkill))*self.lagp0[i,j,k]) | |
5378 | if l==1: |
|
5383 | if l==1: | |
5379 | #print("lagp1: ",self.lagp1[0,0,:]) |
|
5384 | #print("lagp1: ",self.lagp1[0,0,:]) | |
5380 | #input() |
|
5385 | #input() | |
5381 | self.output[i,j,l]=self.output[i,j,l]+((float(dataOut.NAVG)/(float)(dataOut.NAVG-dataOut.nkill))*self.lagp1[i,j,k]) |
|
5386 | self.output[i,j,l]=self.output[i,j,l]+((float(dataOut.NAVG)/(float)(dataOut.NAVG-dataOut.nkill))*self.lagp1[i,j,k]) | |
5382 | #print("self.lagp1[i,j,k]: ",self.lagp1[i,j,k]) |
|
5387 | #print("self.lagp1[i,j,k]: ",self.lagp1[i,j,k]) | |
5383 | #input() |
|
5388 | #input() | |
5384 | if l==2: |
|
5389 | if l==2: | |
5385 | self.output[i,j,l]=self.output[i,j,l]+((float(dataOut.NAVG)/(float)(dataOut.NAVG-dataOut.nkill))*self.lagp2[i,j,k]) |
|
5390 | self.output[i,j,l]=self.output[i,j,l]+((float(dataOut.NAVG)/(float)(dataOut.NAVG-dataOut.nkill))*self.lagp2[i,j,k]) | |
5386 | if l==3: |
|
5391 | if l==3: | |
5387 |
|
5392 | |||
5388 | self.output[i,j,l]=self.output[i,j,l]+((float(dataOut.NAVG)/(float)(dataOut.NAVG-dataOut.nkill))*self.lagp3[i,j,k]) |
|
5393 | self.output[i,j,l]=self.output[i,j,l]+((float(dataOut.NAVG)/(float)(dataOut.NAVG-dataOut.nkill))*self.lagp3[i,j,k]) | |
5389 |
|
5394 | |||
5390 |
|
5395 | |||
5391 | dataOut.output_LP=self.output |
|
5396 | dataOut.output_LP=self.output | |
5392 | dataOut.data_for_RTI_LP=numpy.zeros((4,dataOut.NRANGE)) |
|
5397 | dataOut.data_for_RTI_LP=numpy.zeros((4,dataOut.NRANGE)) | |
5393 | dataOut.data_for_RTI_LP[0],dataOut.data_for_RTI_LP[1],dataOut.data_for_RTI_LP[2],dataOut.data_for_RTI_LP[3]=self.RTI_LP(dataOut.output_LP,dataOut.NRANGE) |
|
5398 | dataOut.data_for_RTI_LP[0],dataOut.data_for_RTI_LP[1],dataOut.data_for_RTI_LP[2],dataOut.data_for_RTI_LP[3]=self.RTI_LP(dataOut.output_LP,dataOut.NRANGE) | |
5394 |
|
5399 | |||
5395 | self.bcounter = 0 |
|
5400 | self.bcounter = 0 | |
5396 |
|
5401 | |||
5397 | def get_dc(self,dataOut): |
|
5402 | def get_dc(self,dataOut): | |
5398 |
|
5403 | |||
5399 | if self.bcounter==0: |
|
5404 | if self.bcounter==0: | |
5400 | dataOut.dc=numpy.zeros(dataOut.NR,dtype='complex64') |
|
5405 | dataOut.dc=numpy.zeros(dataOut.NR,dtype='complex64') | |
5401 |
|
5406 | |||
5402 | #print(numpy.shape(dataOut.data)) |
|
5407 | #print(numpy.shape(dataOut.data)) | |
5403 | #input() |
|
5408 | #input() | |
5404 |
|
5409 | |||
5405 | dataOut.dc+=numpy.sum(dataOut.data[:,:,2*dataOut.NLAG:dataOut.NRANGE],axis=(1,2)) |
|
5410 | dataOut.dc+=numpy.sum(dataOut.data[:,:,2*dataOut.NLAG:dataOut.NRANGE],axis=(1,2)) | |
5406 |
|
5411 | |||
5407 | dataOut.dc=dataOut.dc/float(dataOut.nProfiles*(dataOut.NRANGE-2*dataOut.NLAG)) |
|
5412 | dataOut.dc=dataOut.dc/float(dataOut.nProfiles*(dataOut.NRANGE-2*dataOut.NLAG)) | |
5408 |
|
5413 | |||
5409 |
|
5414 | |||
5410 | #print("dc:",dataOut.dc[0]) |
|
5415 | #print("dc:",dataOut.dc[0]) | |
5411 |
|
5416 | |||
5412 |
|
5417 | |||
5413 |
|
5418 | |||
5414 |
|
5419 | |||
5415 | def noise_estimation4x_HP(self,dataOut): |
|
5420 | def noise_estimation4x_HP(self,dataOut): | |
5416 | if self.bcounter==dataOut.NAVG: |
|
5421 | if self.bcounter==dataOut.NAVG: | |
5417 | dataOut.noise_final=numpy.zeros(dataOut.NR,'float32') |
|
5422 | dataOut.noise_final=numpy.zeros(dataOut.NR,'float32') | |
5418 | #snoise=numpy.zeros((NR,NAVG),'float32') |
|
5423 | #snoise=numpy.zeros((NR,NAVG),'float32') | |
5419 | #nvector1=numpy.zeros((NR,NAVG,MAXNRANGENDT),'float32') |
|
5424 | #nvector1=numpy.zeros((NR,NAVG,MAXNRANGENDT),'float32') | |
5420 | sorted_data=numpy.zeros((dataOut.MAXNRANGENDT,dataOut.NR,dataOut.NAVG),'float32') |
|
5425 | sorted_data=numpy.zeros((dataOut.MAXNRANGENDT,dataOut.NR,dataOut.NAVG),'float32') | |
5421 | for i in range(dataOut.NR): |
|
5426 | for i in range(dataOut.NR): | |
5422 | dataOut.noise_final[i]=0.0 |
|
5427 | dataOut.noise_final[i]=0.0 | |
5423 | for j in range(dataOut.MAXNRANGENDT): |
|
5428 | for j in range(dataOut.MAXNRANGENDT): | |
5424 | sorted_data[j,i,:]=numpy.copy(sorted(dataOut.noisevector[j,i,:])) |
|
5429 | sorted_data[j,i,:]=numpy.copy(sorted(dataOut.noisevector[j,i,:])) | |
5425 | #print(sorted(noisevector[j,i,:])) |
|
5430 | #print(sorted(noisevector[j,i,:])) | |
5426 | #input() |
|
5431 | #input() | |
5427 | l=dataOut.MAXNRANGENDT-2 |
|
5432 | l=dataOut.MAXNRANGENDT-2 | |
5428 | for k in range(dataOut.NAVG): |
|
5433 | for k in range(dataOut.NAVG): | |
5429 | if k>=dataOut.nkill/2 and k<dataOut.NAVG-dataOut.nkill/2: |
|
5434 | if k>=dataOut.nkill/2 and k<dataOut.NAVG-dataOut.nkill/2: | |
5430 | #print(k) |
|
5435 | #print(k) | |
5431 | #print(sorted_data[min(j,l),i,k]) |
|
5436 | #print(sorted_data[min(j,l),i,k]) | |
5432 | dataOut.noise_final[i]+=sorted_data[min(j,l),i,k]*float(dataOut.NAVG)/float(dataOut.NAVG-dataOut.nkill) |
|
5437 | dataOut.noise_final[i]+=sorted_data[min(j,l),i,k]*float(dataOut.NAVG)/float(dataOut.NAVG-dataOut.nkill) | |
5433 | #print(dataOut.noise_final[i]) |
|
5438 | #print(dataOut.noise_final[i]) | |
5434 | #input() |
|
5439 | #input() | |
5435 | #print(dataOut.noise_final) |
|
5440 | #print(dataOut.noise_final) | |
5436 | #input() |
|
5441 | #input() | |
5437 |
|
5442 | |||
5438 | def noisevectorizer(self,NSCAN,nProfiles,NR,MAXNRANGENDT,noisevector,data,dc): |
|
5443 | def noisevectorizer(self,NSCAN,nProfiles,NR,MAXNRANGENDT,noisevector,data,dc): | |
5439 |
|
5444 | |||
5440 | #rnormalizer= 1./(float(nProfiles - NSCAN)) |
|
5445 | #rnormalizer= 1./(float(nProfiles - NSCAN)) | |
5441 | #rnormalizer= float(NSCAN)/((float(nProfiles - NSCAN))*float(MAXNRANGENDT)) |
|
5446 | #rnormalizer= float(NSCAN)/((float(nProfiles - NSCAN))*float(MAXNRANGENDT)) | |
5442 | rnormalizer= float(NSCAN)/((float(1))*float(MAXNRANGENDT)) |
|
5447 | rnormalizer= float(NSCAN)/((float(1))*float(MAXNRANGENDT)) | |
5443 | for i in range(NR): |
|
5448 | for i in range(NR): | |
5444 | for j in range(MAXNRANGENDT): |
|
5449 | for j in range(MAXNRANGENDT): | |
5445 | for k in range(NSCAN,nProfiles): |
|
5450 | for k in range(NSCAN,nProfiles): | |
5446 | #TODO:integrate just 2nd quartile gates |
|
5451 | #TODO:integrate just 2nd quartile gates | |
5447 | if k==NSCAN: |
|
5452 | if k==NSCAN: | |
5448 | noisevector[j][i][self.bcounter]=(abs(data[i][k][j]-dc[i])**2)*rnormalizer |
|
5453 | noisevector[j][i][self.bcounter]=(abs(data[i][k][j]-dc[i])**2)*rnormalizer | |
5449 | ##noisevector[j][i][iavg]=(abs(cdata[k][j][i])**2)*rnormalizer |
|
5454 | ##noisevector[j][i][iavg]=(abs(cdata[k][j][i])**2)*rnormalizer | |
5450 | else: |
|
5455 | else: | |
5451 | noisevector[j][i][self.bcounter]+=(abs(data[i][k][j]-dc[i])**2)*rnormalizer |
|
5456 | noisevector[j][i][self.bcounter]+=(abs(data[i][k][j]-dc[i])**2)*rnormalizer | |
5452 |
|
5457 | |||
5453 |
|
5458 | |||
5454 | def RTI_LP(self,output,NRANGE): |
|
5459 | def RTI_LP(self,output,NRANGE): | |
5455 | x00=numpy.zeros(NRANGE,dtype='float32') |
|
5460 | x00=numpy.zeros(NRANGE,dtype='float32') | |
5456 | x01=numpy.zeros(NRANGE,dtype='float32') |
|
5461 | x01=numpy.zeros(NRANGE,dtype='float32') | |
5457 | x02=numpy.zeros(NRANGE,dtype='float32') |
|
5462 | x02=numpy.zeros(NRANGE,dtype='float32') | |
5458 | x03=numpy.zeros(NRANGE,dtype='float32') |
|
5463 | x03=numpy.zeros(NRANGE,dtype='float32') | |
5459 |
|
5464 | |||
5460 | for i in range(1): #first couple of lags |
|
5465 | for i in range(1): #first couple of lags | |
5461 | for j in range(NRANGE): # |
|
5466 | for j in range(NRANGE): # | |
5462 | #fx=numpy.sqrt((kaxbx[i,j,k]+kayby[i,j,k])**2+(kaybx[i,j,k]-kaxby[i,j,k])**2) |
|
5467 | #fx=numpy.sqrt((kaxbx[i,j,k]+kayby[i,j,k])**2+(kaybx[i,j,k]-kaxby[i,j,k])**2) | |
5463 | x00[j]+=numpy.abs(output[i,j,0]) #Ch0 |
|
5468 | x00[j]+=numpy.abs(output[i,j,0]) #Ch0 | |
5464 | x01[j]+=numpy.abs(output[i,j,1]) #Ch1 |
|
5469 | x01[j]+=numpy.abs(output[i,j,1]) #Ch1 | |
5465 | x02[j]+=numpy.abs(output[i,j,2]) #Ch2 |
|
5470 | x02[j]+=numpy.abs(output[i,j,2]) #Ch2 | |
5466 | x03[j]+=numpy.abs(output[i,j,3]) #Ch3 |
|
5471 | x03[j]+=numpy.abs(output[i,j,3]) #Ch3 | |
5467 | #x02[i]=x02[i]+fx |
|
5472 | #x02[i]=x02[i]+fx | |
5468 |
|
5473 | |||
5469 | x00[j]=10.0*numpy.log10(x00[j]/4.) |
|
5474 | x00[j]=10.0*numpy.log10(x00[j]/4.) | |
5470 | x01[j]=10.0*numpy.log10(x01[j]/4.) |
|
5475 | x01[j]=10.0*numpy.log10(x01[j]/4.) | |
5471 | x02[j]=10.0*numpy.log10(x02[j]/4.) |
|
5476 | x02[j]=10.0*numpy.log10(x02[j]/4.) | |
5472 | x03[j]=10.0*numpy.log10(x03[j]/4.) |
|
5477 | x03[j]=10.0*numpy.log10(x03[j]/4.) | |
5473 | #x02[i]=10.0*numpy.log10(x02[i]) |
|
5478 | #x02[i]=10.0*numpy.log10(x02[i]) | |
5474 | return x00,x01,x02,x03 |
|
5479 | return x00,x01,x02,x03 | |
5475 |
|
5480 | |||
5476 | def run(self, dataOut, NLAG=None, NRANGE=None, NCAL=None, DPL=None, |
|
5481 | def run(self, dataOut, NLAG=None, NRANGE=None, NCAL=None, DPL=None, | |
5477 | NDN=None, NDT=None, NDP=None, NSCAN=None, |
|
5482 | NDN=None, NDT=None, NDP=None, NSCAN=None, | |
5478 | lagind=None, lagfirst=None, |
|
5483 | lagind=None, lagfirst=None, | |
5479 | NAVG=None, nkill=None): |
|
5484 | NAVG=None, nkill=None): | |
5480 |
|
5485 | |||
5481 | dataOut.NLAG=NLAG |
|
5486 | dataOut.NLAG=NLAG | |
5482 | dataOut.NR=len(dataOut.channelList) |
|
5487 | dataOut.NR=len(dataOut.channelList) | |
5483 | #dataOut.NRANGE=NRANGE |
|
5488 | #dataOut.NRANGE=NRANGE | |
5484 | dataOut.NRANGE=dataOut.nHeights |
|
5489 | dataOut.NRANGE=dataOut.nHeights | |
5485 | dataOut.NCAL=NCAL |
|
5490 | dataOut.NCAL=NCAL | |
5486 | dataOut.DPL=DPL |
|
5491 | dataOut.DPL=DPL | |
5487 | dataOut.NDN=NDN |
|
5492 | dataOut.NDN=NDN | |
5488 | dataOut.NDT=NDT |
|
5493 | dataOut.NDT=NDT | |
5489 | dataOut.NDP=NDP |
|
5494 | dataOut.NDP=NDP | |
5490 | dataOut.NSCAN=NSCAN |
|
5495 | dataOut.NSCAN=NSCAN | |
5491 | dataOut.DH=dataOut.heightList[1]-dataOut.heightList[0] |
|
5496 | dataOut.DH=dataOut.heightList[1]-dataOut.heightList[0] | |
5492 | dataOut.H0=int(dataOut.heightList[0]) |
|
5497 | dataOut.H0=int(dataOut.heightList[0]) | |
5493 | dataOut.lagind=lagind |
|
5498 | dataOut.lagind=lagind | |
5494 | dataOut.lagfirst=lagfirst |
|
5499 | dataOut.lagfirst=lagfirst | |
5495 | dataOut.NAVG=NAVG |
|
5500 | dataOut.NAVG=NAVG | |
5496 | dataOut.nkill=nkill |
|
5501 | dataOut.nkill=nkill | |
5497 |
|
5502 | |||
5498 | dataOut.MAXNRANGENDT = dataOut.NRANGE |
|
5503 | dataOut.MAXNRANGENDT = dataOut.NRANGE | |
5499 |
|
5504 | |||
5500 | dataOut.flagNoData = True |
|
5505 | dataOut.flagNoData = True | |
5501 |
|
5506 | |||
5502 | print(self.bcounter) |
|
5507 | print(self.bcounter) | |
5503 |
|
5508 | |||
5504 | self.get_dc(dataOut) |
|
5509 | self.get_dc(dataOut) | |
5505 | self.lag_products_LP(dataOut) |
|
5510 | self.lag_products_LP(dataOut) | |
5506 | self.noise_estimation4x_HP(dataOut) |
|
5511 | self.noise_estimation4x_HP(dataOut) | |
5507 | self.LP_median_estimates(dataOut) |
|
5512 | self.LP_median_estimates(dataOut) | |
5508 |
|
5513 | |||
5509 | print("******************DONE******************") |
|
5514 | print("******************DONE******************") | |
5510 |
|
5515 | |||
5511 |
|
5516 | |||
5512 |
|
5517 | |||
5513 | return dataOut |
|
5518 | return dataOut | |
5514 |
|
5519 | |||
5515 |
|
5520 | |||
5516 | class RemoveDebris(Operation): |
|
5521 | class RemoveDebris(Operation): | |
5517 | """Operation to remove blocks where an outlier is found for Double (Long) Pulse. |
|
5522 | """Operation to remove blocks where an outlier is found for Double (Long) Pulse. | |
5518 |
|
5523 | |||
5519 | Parameters: |
|
5524 | Parameters: | |
5520 | ----------- |
|
5525 | ----------- | |
5521 | None |
|
5526 | None | |
5522 |
|
5527 | |||
5523 | Example |
|
5528 | Example | |
5524 | -------- |
|
5529 | -------- | |
5525 |
|
5530 | |||
5526 | op = proc_unit.addOperation(name='RemoveDebris', optype='other') |
|
5531 | op = proc_unit.addOperation(name='RemoveDebris', optype='other') | |
5527 |
|
5532 | |||
5528 | """ |
|
5533 | """ | |
5529 |
|
5534 | |||
5530 | def __init__(self, **kwargs): |
|
5535 | def __init__(self, **kwargs): | |
5531 |
|
5536 | |||
5532 | Operation.__init__(self, **kwargs) |
|
5537 | Operation.__init__(self, **kwargs) | |
5533 |
|
5538 | |||
5534 | def run(self,dataOut): |
|
5539 | def run(self,dataOut): | |
5535 | debris=numpy.zeros(dataOut.NRANGE,'float32') |
|
5540 | debris=numpy.zeros(dataOut.NRANGE,'float32') | |
5536 |
|
5541 | |||
5537 | for j in range(0,3): |
|
5542 | for j in range(0,3): | |
5538 | for i in range(dataOut.NRANGE): |
|
5543 | for i in range(dataOut.NRANGE): | |
5539 | if j==0: |
|
5544 | if j==0: | |
5540 | debris[i]=10*numpy.log10(numpy.abs(dataOut.output_LP[j,i,0])) |
|
5545 | debris[i]=10*numpy.log10(numpy.abs(dataOut.output_LP[j,i,0])) | |
5541 | else: |
|
5546 | else: | |
5542 | debris[i]+=10*numpy.log10(numpy.abs(dataOut.output_LP[j,i,0])) |
|
5547 | debris[i]+=10*numpy.log10(numpy.abs(dataOut.output_LP[j,i,0])) | |
5543 |
|
5548 | |||
5544 | thresh=8.0+4+4+4 |
|
5549 | thresh=8.0+4+4+4 | |
5545 | for i in range(47,100): |
|
5550 | for i in range(47,100): | |
5546 | if ((debris[i-2]+debris[i-1]+debris[i]+debris[i+1])> |
|
5551 | if ((debris[i-2]+debris[i-1]+debris[i]+debris[i+1])> | |
5547 | ((debris[i-12]+debris[i-11]+debris[i-10]+debris[i-9]+ |
|
5552 | ((debris[i-12]+debris[i-11]+debris[i-10]+debris[i-9]+ | |
5548 | debris[i+12]+debris[i+11]+debris[i+10]+debris[i+9])/2.0+ |
|
5553 | debris[i+12]+debris[i+11]+debris[i+10]+debris[i+9])/2.0+ | |
5549 | thresh)): |
|
5554 | thresh)): | |
5550 |
|
5555 | |||
5551 | dataOut.flagNoData=True |
|
5556 | dataOut.flagNoData=True | |
5552 | print("LP Debris detected at",i*15,"km") |
|
5557 | print("LP Debris detected at",i*15,"km") | |
5553 |
|
5558 | |||
5554 | debris=numpy.zeros(dataOut.NDP,dtype='float32') |
|
5559 | debris=numpy.zeros(dataOut.NDP,dtype='float32') | |
5555 | Range=numpy.arange(0,3000,15) |
|
5560 | Range=numpy.arange(0,3000,15) | |
5556 | for k in range(2): #flip |
|
5561 | for k in range(2): #flip | |
5557 | for i in range(dataOut.NDP): # |
|
5562 | for i in range(dataOut.NDP): # | |
5558 | debris[i]+=numpy.sqrt((dataOut.kaxbx[i,0,k]+dataOut.kayby[i,0,k])**2+(dataOut.kaybx[i,0,k]-dataOut.kaxby[i,0,k])**2) |
|
5563 | debris[i]+=numpy.sqrt((dataOut.kaxbx[i,0,k]+dataOut.kayby[i,0,k])**2+(dataOut.kaybx[i,0,k]-dataOut.kaxby[i,0,k])**2) | |
5559 |
|
5564 | |||
5560 | if gmtime(dataOut.utctime).tm_hour > 11: |
|
5565 | if gmtime(dataOut.utctime).tm_hour > 11: | |
5561 | for i in range(2,dataOut.NDP-2): |
|
5566 | for i in range(2,dataOut.NDP-2): | |
5562 | if (debris[i]>3.0*debris[i-2] and |
|
5567 | if (debris[i]>3.0*debris[i-2] and | |
5563 | debris[i]>3.0*debris[i+2] and |
|
5568 | debris[i]>3.0*debris[i+2] and | |
5564 | Range[i]>200.0 and Range[i]<=540.0): |
|
5569 | Range[i]>200.0 and Range[i]<=540.0): | |
5565 | dataOut.flagNoData=True |
|
5570 | dataOut.flagNoData=True | |
5566 | print("DP Debris detected at",i*15,"km") |
|
5571 | print("DP Debris detected at",i*15,"km") | |
5567 |
|
5572 | |||
5568 | return dataOut |
|
5573 | return dataOut | |
5569 |
|
5574 | |||
5570 |
|
5575 | |||
5571 | class IntegrationHP(IntegrationDP): |
|
5576 | class IntegrationHP(IntegrationDP): | |
5572 | """Operation to integrate Double Pulse and Long Pulse data. |
|
5577 | """Operation to integrate Double Pulse and Long Pulse data. | |
5573 |
|
5578 | |||
5574 | Parameters: |
|
5579 | Parameters: | |
5575 | ----------- |
|
5580 | ----------- | |
5576 | nint : int |
|
5581 | nint : int | |
5577 | Number of integrations. |
|
5582 | Number of integrations. | |
5578 |
|
5583 | |||
5579 | Example |
|
5584 | Example | |
5580 | -------- |
|
5585 | -------- | |
5581 |
|
5586 | |||
5582 | op = proc_unit.addOperation(name='IntegrationHP', optype='other') |
|
5587 | op = proc_unit.addOperation(name='IntegrationHP', optype='other') | |
5583 | op.addParameter(name='nint', value='30', format='int') |
|
5588 | op.addParameter(name='nint', value='30', format='int') | |
5584 |
|
5589 | |||
5585 | """ |
|
5590 | """ | |
5586 |
|
5591 | |||
5587 | def __init__(self, **kwargs): |
|
5592 | def __init__(self, **kwargs): | |
5588 |
|
5593 | |||
5589 | Operation.__init__(self, **kwargs) |
|
5594 | Operation.__init__(self, **kwargs) | |
5590 |
|
5595 | |||
5591 | self.counter = 0 |
|
5596 | self.counter = 0 | |
5592 | self.aux = 0 |
|
5597 | self.aux = 0 | |
5593 |
|
5598 | |||
5594 | def integration_noise(self,dataOut): |
|
5599 | def integration_noise(self,dataOut): | |
5595 |
|
5600 | |||
5596 | if self.counter == 0: |
|
5601 | if self.counter == 0: | |
5597 | dataOut.tnoise=numpy.zeros((dataOut.NR),dtype='float32') |
|
5602 | dataOut.tnoise=numpy.zeros((dataOut.NR),dtype='float32') | |
5598 |
|
5603 | |||
5599 | dataOut.tnoise+=dataOut.noise_final |
|
5604 | dataOut.tnoise+=dataOut.noise_final | |
5600 |
|
5605 | |||
5601 | def integration_for_long_pulse(self,dataOut): |
|
5606 | def integration_for_long_pulse(self,dataOut): | |
5602 |
|
5607 | |||
5603 | if self.counter == 0: |
|
5608 | if self.counter == 0: | |
5604 | dataOut.output_LP_integrated=numpy.zeros((dataOut.NLAG,dataOut.NRANGE,dataOut.NR),order='F',dtype='complex64') |
|
5609 | dataOut.output_LP_integrated=numpy.zeros((dataOut.NLAG,dataOut.NRANGE,dataOut.NR),order='F',dtype='complex64') | |
5605 |
|
5610 | |||
5606 | dataOut.output_LP_integrated+=dataOut.output_LP |
|
5611 | dataOut.output_LP_integrated+=dataOut.output_LP | |
5607 |
|
5612 | |||
5608 | def run(self,dataOut,nint=None): |
|
5613 | def run(self,dataOut,nint=None): | |
5609 |
|
5614 | |||
5610 | dataOut.flagNoData=True |
|
5615 | dataOut.flagNoData=True | |
5611 |
|
5616 | |||
5612 | dataOut.nint=nint |
|
5617 | dataOut.nint=nint | |
5613 | dataOut.paramInterval=0#int(dataOut.nint*dataOut.header[7][0]*2 ) |
|
5618 | dataOut.paramInterval=0#int(dataOut.nint*dataOut.header[7][0]*2 ) | |
5614 | dataOut.lat=-11.95 |
|
5619 | dataOut.lat=-11.95 | |
5615 | dataOut.lon=-76.87 |
|
5620 | dataOut.lon=-76.87 | |
5616 |
|
5621 | |||
5617 | self.integration_for_long_pulse(dataOut) |
|
5622 | self.integration_for_long_pulse(dataOut) | |
5618 |
|
5623 | |||
5619 | self.integration_noise(dataOut) |
|
5624 | self.integration_noise(dataOut) | |
5620 |
|
5625 | |||
5621 | if self.counter==dataOut.nint-1: |
|
5626 | if self.counter==dataOut.nint-1: | |
5622 | dataOut.nis=dataOut.NSCAN*dataOut.NAVG*dataOut.nint*10 |
|
5627 | dataOut.nis=dataOut.NSCAN*dataOut.NAVG*dataOut.nint*10 | |
5623 | dataOut.tnoise[0]*=0.995 |
|
5628 | dataOut.tnoise[0]*=0.995 | |
5624 | dataOut.tnoise[1]*=0.995 |
|
5629 | dataOut.tnoise[1]*=0.995 | |
5625 | dataOut.pan=dataOut.tnoise[0]/float(dataOut.NSCAN*dataOut.nint*dataOut.NAVG) |
|
5630 | dataOut.pan=dataOut.tnoise[0]/float(dataOut.NSCAN*dataOut.nint*dataOut.NAVG) | |
5626 | dataOut.pbn=dataOut.tnoise[1]/float(dataOut.NSCAN*dataOut.nint*dataOut.NAVG) |
|
5631 | dataOut.pbn=dataOut.tnoise[1]/float(dataOut.NSCAN*dataOut.nint*dataOut.NAVG) | |
5627 |
|
5632 | |||
5628 | self.integration_for_double_pulse(dataOut) |
|
5633 | self.integration_for_double_pulse(dataOut) | |
5629 |
|
5634 | |||
5630 |
|
5635 | |||
5631 |
|
5636 | |||
5632 | return dataOut |
|
5637 | return dataOut | |
5633 |
|
5638 | |||
5634 | class SumFlipsHP(SumFlips): |
|
5639 | class SumFlipsHP(SumFlips): | |
5635 | """Operation to sum the flip and unflip part of certain cross products of the Double Pulse. |
|
5640 | """Operation to sum the flip and unflip part of certain cross products of the Double Pulse. | |
5636 |
|
5641 | |||
5637 | Parameters: |
|
5642 | Parameters: | |
5638 | ----------- |
|
5643 | ----------- | |
5639 | None |
|
5644 | None | |
5640 |
|
5645 | |||
5641 | Example |
|
5646 | Example | |
5642 | -------- |
|
5647 | -------- | |
5643 |
|
5648 | |||
5644 | op = proc_unit.addOperation(name='SumFlipsHP', optype='other') |
|
5649 | op = proc_unit.addOperation(name='SumFlipsHP', optype='other') | |
5645 |
|
5650 | |||
5646 | """ |
|
5651 | """ | |
5647 |
|
5652 | |||
5648 | def __init__(self, **kwargs): |
|
5653 | def __init__(self, **kwargs): | |
5649 |
|
5654 | |||
5650 | Operation.__init__(self, **kwargs) |
|
5655 | Operation.__init__(self, **kwargs) | |
5651 |
|
5656 | |||
5652 | def rint2HP(self,dataOut): |
|
5657 | def rint2HP(self,dataOut): | |
5653 |
|
5658 | |||
5654 | dataOut.rnint2=numpy.zeros(dataOut.DPL,'float32') |
|
5659 | dataOut.rnint2=numpy.zeros(dataOut.DPL,'float32') | |
5655 | #print(dataOut.nint,dataOut.NAVG) |
|
5660 | #print(dataOut.nint,dataOut.NAVG) | |
5656 | for l in range(dataOut.DPL): |
|
5661 | for l in range(dataOut.DPL): | |
5657 | if(l==0 or (l>=3 and l <=6)): |
|
5662 | if(l==0 or (l>=3 and l <=6)): | |
5658 | dataOut.rnint2[l]=0.5/float(dataOut.nint*dataOut.NAVG*16.0) |
|
5663 | dataOut.rnint2[l]=0.5/float(dataOut.nint*dataOut.NAVG*16.0) | |
5659 | else: |
|
5664 | else: | |
5660 | dataOut.rnint2[l]=0.5/float(dataOut.nint*dataOut.NAVG*8.0) |
|
5665 | dataOut.rnint2[l]=0.5/float(dataOut.nint*dataOut.NAVG*8.0) | |
5661 |
|
5666 | |||
5662 | def run(self,dataOut): |
|
5667 | def run(self,dataOut): | |
5663 |
|
5668 | |||
5664 | self.rint2HP(dataOut) |
|
5669 | self.rint2HP(dataOut) | |
5665 | self.SumLags(dataOut) |
|
5670 | self.SumLags(dataOut) | |
5666 |
|
5671 | |||
5667 | hei = 2 |
|
5672 | hei = 2 | |
5668 | lag = 0 |
|
5673 | lag = 0 | |
5669 | ''' |
|
5674 | ''' | |
5670 | for hei in range(67): |
|
5675 | for hei in range(67): | |
5671 | print("hei",hei) |
|
5676 | print("hei",hei) | |
5672 | print(dataOut.kabxys_integrated[8][hei,:,0]+dataOut.kabxys_integrated[11][hei,:,0]) |
|
5677 | print(dataOut.kabxys_integrated[8][hei,:,0]+dataOut.kabxys_integrated[11][hei,:,0]) | |
5673 | print(dataOut.kabxys_integrated[10][hei,:,0]-dataOut.kabxys_integrated[9][hei,:,0]) |
|
5678 | print(dataOut.kabxys_integrated[10][hei,:,0]-dataOut.kabxys_integrated[9][hei,:,0]) | |
5674 | exit(1) |
|
5679 | exit(1) | |
5675 | ''' |
|
5680 | ''' | |
5676 | ''' |
|
5681 | ''' | |
5677 | print("b",(dataOut.kabxys_integrated[4][hei,lag,0]+dataOut.kabxys_integrated[5][hei,lag,0])) |
|
5682 | print("b",(dataOut.kabxys_integrated[4][hei,lag,0]+dataOut.kabxys_integrated[5][hei,lag,0])) | |
5678 | print((dataOut.kabxys_integrated[6][hei,lag,0]+dataOut.kabxys_integrated[7][hei,lag,0])) |
|
5683 | print((dataOut.kabxys_integrated[6][hei,lag,0]+dataOut.kabxys_integrated[7][hei,lag,0])) | |
5679 | print("c",(dataOut.kabxys_integrated[8][hei,lag,0]+dataOut.kabxys_integrated[11][hei,lag,0])) |
|
5684 | print("c",(dataOut.kabxys_integrated[8][hei,lag,0]+dataOut.kabxys_integrated[11][hei,lag,0])) | |
5680 | print((dataOut.kabxys_integrated[10][hei,lag,0]-dataOut.kabxys_integrated[9][hei,lag,0])) |
|
5685 | print((dataOut.kabxys_integrated[10][hei,lag,0]-dataOut.kabxys_integrated[9][hei,lag,0])) | |
5681 | exit(1) |
|
5686 | exit(1) | |
5682 | ''' |
|
5687 | ''' | |
5683 | #print(dataOut.rnint2) |
|
5688 | #print(dataOut.rnint2) | |
5684 | #print(numpy.sum(dataOut.kabxys_integrated[4][:,1,0]+dataOut.kabxys_integrated[5][:,1,0])) |
|
5689 | #print(numpy.sum(dataOut.kabxys_integrated[4][:,1,0]+dataOut.kabxys_integrated[5][:,1,0])) | |
5685 | #print(dataOut.nis) |
|
5690 | #print(dataOut.nis) | |
5686 | #exit(1) |
|
5691 | #exit(1) | |
5687 | return dataOut |
|
5692 | return dataOut | |
5688 |
|
5693 | |||
5689 |
|
5694 | |||
5690 | class LongPulseAnalysis(Operation): |
|
5695 | class LongPulseAnalysis(Operation): | |
5691 | """Operation to estimate ACFs, temperatures, total electron density and Hydrogen/Helium fractions from the Long Pulse data. |
|
5696 | """Operation to estimate ACFs, temperatures, total electron density and Hydrogen/Helium fractions from the Long Pulse data. | |
5692 |
|
5697 | |||
5693 | Parameters: |
|
5698 | Parameters: | |
5694 | ----------- |
|
5699 | ----------- | |
5695 | NACF : int |
|
5700 | NACF : int | |
5696 | .* |
|
5701 | .* | |
5697 |
|
5702 | |||
5698 | Example |
|
5703 | Example | |
5699 | -------- |
|
5704 | -------- | |
5700 |
|
5705 | |||
5701 | op = proc_unit.addOperation(name='LongPulseAnalysis', optype='other') |
|
5706 | op = proc_unit.addOperation(name='LongPulseAnalysis', optype='other') | |
5702 | op.addParameter(name='NACF', value='16', format='int') |
|
5707 | op.addParameter(name='NACF', value='16', format='int') | |
5703 |
|
5708 | |||
5704 | """ |
|
5709 | """ | |
5705 |
|
5710 | |||
5706 | def __init__(self, **kwargs): |
|
5711 | def __init__(self, **kwargs): | |
5707 |
|
5712 | |||
5708 | Operation.__init__(self, **kwargs) |
|
5713 | Operation.__init__(self, **kwargs) | |
5709 | self.aux=1 |
|
5714 | self.aux=1 | |
5710 |
|
5715 | |||
5711 | def run(self,dataOut,NACF): |
|
5716 | def run(self,dataOut,NACF): | |
5712 |
|
5717 | |||
5713 | dataOut.NACF=NACF |
|
5718 | dataOut.NACF=NACF | |
5714 | dataOut.heightList=dataOut.DH*(numpy.arange(dataOut.NACF)) |
|
5719 | dataOut.heightList=dataOut.DH*(numpy.arange(dataOut.NACF)) | |
5715 | anoise0=dataOut.tnoise[0] |
|
5720 | anoise0=dataOut.tnoise[0] | |
5716 | anoise1=anoise0*0.0 #seems to be noise in 1st lag 0.015 before '14 |
|
5721 | anoise1=anoise0*0.0 #seems to be noise in 1st lag 0.015 before '14 | |
5717 | #print(anoise0) |
|
5722 | #print(anoise0) | |
5718 | #exit(1) |
|
5723 | #exit(1) | |
5719 | if self.aux: |
|
5724 | if self.aux: | |
5720 | #dataOut.cut=31#26#height=31*15=465 |
|
5725 | #dataOut.cut=31#26#height=31*15=465 | |
5721 | self.cal=numpy.zeros((dataOut.NLAG),'float32') |
|
5726 | self.cal=numpy.zeros((dataOut.NLAG),'float32') | |
5722 | self.drift=numpy.zeros((200),'float32') |
|
5727 | self.drift=numpy.zeros((200),'float32') | |
5723 | self.rdrift=numpy.zeros((200),'float32') |
|
5728 | self.rdrift=numpy.zeros((200),'float32') | |
5724 | self.ddrift=numpy.zeros((200),'float32') |
|
5729 | self.ddrift=numpy.zeros((200),'float32') | |
5725 | self.sigma=numpy.zeros((dataOut.NRANGE),order='F',dtype='float32') |
|
5730 | self.sigma=numpy.zeros((dataOut.NRANGE),order='F',dtype='float32') | |
5726 | self.powera=numpy.zeros((dataOut.NRANGE),order='F',dtype='float32') |
|
5731 | self.powera=numpy.zeros((dataOut.NRANGE),order='F',dtype='float32') | |
5727 | self.powerb=numpy.zeros((dataOut.NRANGE),order='F',dtype='float32') |
|
5732 | self.powerb=numpy.zeros((dataOut.NRANGE),order='F',dtype='float32') | |
5728 | self.perror=numpy.zeros((dataOut.NRANGE),order='F',dtype='float32') |
|
5733 | self.perror=numpy.zeros((dataOut.NRANGE),order='F',dtype='float32') | |
5729 | dataOut.ene=numpy.zeros((dataOut.NRANGE),'float32') |
|
5734 | dataOut.ene=numpy.zeros((dataOut.NRANGE),'float32') | |
5730 | self.dpulse=numpy.zeros((dataOut.NACF),'float32') |
|
5735 | self.dpulse=numpy.zeros((dataOut.NACF),'float32') | |
5731 | self.lpulse=numpy.zeros((dataOut.NACF),'float32') |
|
5736 | self.lpulse=numpy.zeros((dataOut.NACF),'float32') | |
5732 | dataOut.lags_LP=numpy.zeros((dataOut.IBITS),order='F',dtype='float32') |
|
5737 | dataOut.lags_LP=numpy.zeros((dataOut.IBITS),order='F',dtype='float32') | |
5733 | self.lagp=numpy.zeros((dataOut.NACF),'float32') |
|
5738 | self.lagp=numpy.zeros((dataOut.NACF),'float32') | |
5734 | self.u=numpy.zeros((2*dataOut.NACF,2*dataOut.NACF),'float32') |
|
5739 | self.u=numpy.zeros((2*dataOut.NACF,2*dataOut.NACF),'float32') | |
5735 | dataOut.ne=numpy.zeros((dataOut.NRANGE),order='F',dtype='float32') |
|
5740 | dataOut.ne=numpy.zeros((dataOut.NRANGE),order='F',dtype='float32') | |
5736 | dataOut.te=numpy.zeros((dataOut.NACF),order='F',dtype='float32') |
|
5741 | dataOut.te=numpy.zeros((dataOut.NACF),order='F',dtype='float32') | |
5737 | dataOut.ete=numpy.zeros((dataOut.NACF),order='F',dtype='float32') |
|
5742 | dataOut.ete=numpy.zeros((dataOut.NACF),order='F',dtype='float32') | |
5738 | dataOut.ti=numpy.zeros((dataOut.NACF),order='F',dtype='float32') |
|
5743 | dataOut.ti=numpy.zeros((dataOut.NACF),order='F',dtype='float32') | |
5739 | dataOut.eti=numpy.zeros((dataOut.NACF),order='F',dtype='float32') |
|
5744 | dataOut.eti=numpy.zeros((dataOut.NACF),order='F',dtype='float32') | |
5740 | dataOut.ph=numpy.zeros((dataOut.NACF),order='F',dtype='float32') |
|
5745 | dataOut.ph=numpy.zeros((dataOut.NACF),order='F',dtype='float32') | |
5741 | dataOut.eph=numpy.zeros((dataOut.NACF),order='F',dtype='float32') |
|
5746 | dataOut.eph=numpy.zeros((dataOut.NACF),order='F',dtype='float32') | |
5742 | dataOut.phe=numpy.zeros((dataOut.NACF),order='F',dtype='float32') |
|
5747 | dataOut.phe=numpy.zeros((dataOut.NACF),order='F',dtype='float32') | |
5743 | dataOut.ephe=numpy.zeros((dataOut.NACF),order='F',dtype='float32') |
|
5748 | dataOut.ephe=numpy.zeros((dataOut.NACF),order='F',dtype='float32') | |
5744 | dataOut.errors=numpy.zeros((dataOut.IBITS,max(dataOut.NRANGE,dataOut.NSHTS)),order='F',dtype='float32') |
|
5749 | dataOut.errors=numpy.zeros((dataOut.IBITS,max(dataOut.NRANGE,dataOut.NSHTS)),order='F',dtype='float32') | |
5745 | dataOut.fit_array_real=numpy.zeros((max(dataOut.NRANGE,dataOut.NSHTS),dataOut.NLAG),order='F',dtype='float32') |
|
5750 | dataOut.fit_array_real=numpy.zeros((max(dataOut.NRANGE,dataOut.NSHTS),dataOut.NLAG),order='F',dtype='float32') | |
5746 | dataOut.status=numpy.zeros(1,'float32') |
|
5751 | dataOut.status=numpy.zeros(1,'float32') | |
5747 | dataOut.tx=240.0 #deberΓa provenir del header #hybrid |
|
5752 | dataOut.tx=240.0 #deberΓa provenir del header #hybrid | |
5748 |
|
5753 | |||
5749 | for i in range(dataOut.IBITS): |
|
5754 | for i in range(dataOut.IBITS): | |
5750 | dataOut.lags_LP[i]=float(i)*(dataOut.tx/150.0)/float(dataOut.IBITS) # (float)i*(header.tx/150.0)/(float)IBITS; |
|
5755 | dataOut.lags_LP[i]=float(i)*(dataOut.tx/150.0)/float(dataOut.IBITS) # (float)i*(header.tx/150.0)/(float)IBITS; | |
5751 |
|
5756 | |||
5752 | self.aux=0 |
|
5757 | self.aux=0 | |
5753 |
|
5758 | |||
5754 | dataOut.cut=30 |
|
5759 | dataOut.cut=30 | |
5755 | for i in range(30,15,-1): #AquΓ se calcula en donde se unirΓ‘ DP y LP en la parte final |
|
5760 | for i in range(30,15,-1): #AquΓ se calcula en donde se unirΓ‘ DP y LP en la parte final | |
5756 | if numpy.nanmax(dataOut.acfs_error_to_plot[i,:])>=10 or dataOut.info2[i]==0: |
|
5761 | if numpy.nanmax(dataOut.acfs_error_to_plot[i,:])>=10 or dataOut.info2[i]==0: | |
5757 | dataOut.cut=i-1 |
|
5762 | dataOut.cut=i-1 | |
5758 |
|
5763 | |||
5759 | for i in range(dataOut.NLAG): |
|
5764 | for i in range(dataOut.NLAG): | |
5760 | self.cal[i]=sum(dataOut.output_LP_integrated[i,:,3].real) #Lag x Height x Channel |
|
5765 | self.cal[i]=sum(dataOut.output_LP_integrated[i,:,3].real) #Lag x Height x Channel | |
5761 |
|
5766 | |||
5762 | #print(numpy.sum(self.cal)) #Coinciden |
|
5767 | #print(numpy.sum(self.cal)) #Coinciden | |
5763 | #exit(1) |
|
5768 | #exit(1) | |
5764 | self.cal/=float(dataOut.NRANGE) |
|
5769 | self.cal/=float(dataOut.NRANGE) | |
5765 | #print(anoise0) |
|
5770 | #print(anoise0) | |
5766 | #print(anoise1) |
|
5771 | #print(anoise1) | |
5767 | #exit(1) |
|
5772 | #exit(1) | |
5768 | #print("nis: ", dataOut.nis) |
|
5773 | #print("nis: ", dataOut.nis) | |
5769 | #print("pan: ", dataOut.pan) |
|
5774 | #print("pan: ", dataOut.pan) | |
5770 | #print("pbn: ", dataOut.pbn) |
|
5775 | #print("pbn: ", dataOut.pbn) | |
5771 | #print(numpy.sum(dataOut.output_LP_integrated[0,:,0])) |
|
5776 | #print(numpy.sum(dataOut.output_LP_integrated[0,:,0])) | |
5772 | ''' |
|
5777 | ''' | |
5773 | import matplotlib.pyplot as plt |
|
5778 | import matplotlib.pyplot as plt | |
5774 | plt.plot(dataOut.output_LP_integrated[:,40,0]) |
|
5779 | plt.plot(dataOut.output_LP_integrated[:,40,0]) | |
5775 | plt.show() |
|
5780 | plt.show() | |
5776 | ''' |
|
5781 | ''' | |
5777 | #print(dataOut.output_LP_integrated[0,40,0]) |
|
5782 | #print(dataOut.output_LP_integrated[0,40,0]) | |
5778 | #print(numpy.sum(dataOut.output_LP_integrated[:,0,0])) |
|
5783 | #print(numpy.sum(dataOut.output_LP_integrated[:,0,0])) | |
5779 | #exit(1) |
|
5784 | #exit(1) | |
5780 |
|
5785 | |||
5781 | #################### PROBAR MΓS INTEGRACIΓN, SINO MODIFICAR VALOR DE "NIS" #################### |
|
5786 | #################### PROBAR MΓS INTEGRACIΓN, SINO MODIFICAR VALOR DE "NIS" #################### | |
5782 | # VER dataOut.nProfiles_LP # |
|
5787 | # VER dataOut.nProfiles_LP # | |
5783 |
|
5788 | |||
5784 | ''' |
|
5789 | ''' | |
5785 | #PLOTEAR POTENCIA VS RUIDO, QUIZA SE ESTA REMOVIENDO MUCHA SEΓAL |
|
5790 | #PLOTEAR POTENCIA VS RUIDO, QUIZA SE ESTA REMOVIENDO MUCHA SEΓAL | |
5786 | #print(dataOut.heightList) |
|
5791 | #print(dataOut.heightList) | |
5787 | import matplotlib.pyplot as plt |
|
5792 | import matplotlib.pyplot as plt | |
5788 | plt.plot(10*numpy.log10(dataOut.output_LP_integrated.real[0,:,0]),dataOut.range1) |
|
5793 | plt.plot(10*numpy.log10(dataOut.output_LP_integrated.real[0,:,0]),dataOut.range1) | |
5789 | #plt.plot(10*numpy.log10(dataOut.output_LP_integrated.real[0,:,0]/dataOut.nProfiles_LP),dataOut.range1) |
|
5794 | #plt.plot(10*numpy.log10(dataOut.output_LP_integrated.real[0,:,0]/dataOut.nProfiles_LP),dataOut.range1) | |
5790 | plt.axvline(10*numpy.log10(anoise0),color='k',linestyle='dashed') |
|
5795 | plt.axvline(10*numpy.log10(anoise0),color='k',linestyle='dashed') | |
5791 | plt.grid() |
|
5796 | plt.grid() | |
5792 | plt.xlim(20,100) |
|
5797 | plt.xlim(20,100) | |
5793 | plt.show() |
|
5798 | plt.show() | |
5794 | ''' |
|
5799 | ''' | |
5795 |
|
5800 | |||
5796 |
|
5801 | |||
5797 | for j in range(dataOut.NACF+2*dataOut.IBITS+2): |
|
5802 | for j in range(dataOut.NACF+2*dataOut.IBITS+2): | |
5798 |
|
5803 | |||
5799 | dataOut.output_LP_integrated.real[0,j,0]-=anoise0 #lag0 ch0 |
|
5804 | dataOut.output_LP_integrated.real[0,j,0]-=anoise0 #lag0 ch0 | |
5800 | dataOut.output_LP_integrated.real[1,j,0]-=anoise1 #lag1 ch0 |
|
5805 | dataOut.output_LP_integrated.real[1,j,0]-=anoise1 #lag1 ch0 | |
5801 |
|
5806 | |||
5802 | for i in range(1,dataOut.NLAG): #remove cal data from certain lags |
|
5807 | for i in range(1,dataOut.NLAG): #remove cal data from certain lags | |
5803 | dataOut.output_LP_integrated.real[i,j,0]-=self.cal[i] |
|
5808 | dataOut.output_LP_integrated.real[i,j,0]-=self.cal[i] | |
5804 | k=max(j,26) #constant power below range 26 |
|
5809 | k=max(j,26) #constant power below range 26 | |
5805 | self.powera[j]=dataOut.output_LP_integrated.real[0,k,0] #Lag0 and Channel 0 |
|
5810 | self.powera[j]=dataOut.output_LP_integrated.real[0,k,0] #Lag0 and Channel 0 | |
5806 |
|
5811 | |||
5807 | ## examine drifts here - based on 60 'indep.' estimates |
|
5812 | ## examine drifts here - based on 60 'indep.' estimates | |
5808 | #print(numpy.sum(self.powera)) |
|
5813 | #print(numpy.sum(self.powera)) | |
5809 | #exit(1) |
|
5814 | #exit(1) | |
5810 | #nis=dataOut.NSCAN*dataOut.NAVG*dataOut.nint*10 |
|
5815 | #nis=dataOut.NSCAN*dataOut.NAVG*dataOut.nint*10 | |
5811 | nis = dataOut.nis |
|
5816 | nis = dataOut.nis | |
5812 | #print("nis",nis) |
|
5817 | #print("nis",nis) | |
5813 | alpha=beta=delta=0.0 |
|
5818 | alpha=beta=delta=0.0 | |
5814 | nest=0 |
|
5819 | nest=0 | |
5815 | gamma=3.0/(2.0*numpy.pi*dataOut.lags_LP[1]*1.0e-3) |
|
5820 | gamma=3.0/(2.0*numpy.pi*dataOut.lags_LP[1]*1.0e-3) | |
5816 | beta=gamma*(math.atan2(dataOut.output_LP_integrated.imag[14,0,2],dataOut.output_LP_integrated.real[14,0,2])-math.atan2(dataOut.output_LP_integrated.imag[1,0,2],dataOut.output_LP_integrated.real[1,0,2]))/13.0 |
|
5821 | beta=gamma*(math.atan2(dataOut.output_LP_integrated.imag[14,0,2],dataOut.output_LP_integrated.real[14,0,2])-math.atan2(dataOut.output_LP_integrated.imag[1,0,2],dataOut.output_LP_integrated.real[1,0,2]))/13.0 | |
5817 | #print(gamma,beta) |
|
5822 | #print(gamma,beta) | |
5818 | #exit(1) |
|
5823 | #exit(1) | |
5819 | for i in range(1,3): |
|
5824 | for i in range(1,3): | |
5820 | gamma=3.0/(2.0*numpy.pi*dataOut.lags_LP[i]*1.0e-3) |
|
5825 | gamma=3.0/(2.0*numpy.pi*dataOut.lags_LP[i]*1.0e-3) | |
5821 | #print("gamma",gamma) |
|
5826 | #print("gamma",gamma) | |
5822 | for j in range(34,44): |
|
5827 | for j in range(34,44): | |
5823 | rho2=numpy.abs(dataOut.output_LP_integrated[i,j,0])/numpy.abs(dataOut.output_LP_integrated[0,j,0]) |
|
5828 | rho2=numpy.abs(dataOut.output_LP_integrated[i,j,0])/numpy.abs(dataOut.output_LP_integrated[0,j,0]) | |
5824 | dataOut.dphi2=(1.0/rho2-1.0)/(float(2*nis)) |
|
5829 | dataOut.dphi2=(1.0/rho2-1.0)/(float(2*nis)) | |
5825 | dataOut.dphi2*=gamma**2 |
|
5830 | dataOut.dphi2*=gamma**2 | |
5826 | pest=gamma*math.atan(dataOut.output_LP_integrated.imag[i,j,0]/dataOut.output_LP_integrated.real[i,j,0]) |
|
5831 | pest=gamma*math.atan(dataOut.output_LP_integrated.imag[i,j,0]/dataOut.output_LP_integrated.real[i,j,0]) | |
5827 | #print("1",dataOut.output_LP_integrated.imag[i,j,0]) |
|
5832 | #print("1",dataOut.output_LP_integrated.imag[i,j,0]) | |
5828 | #print("2",dataOut.output_LP_integrated.real[i,j,0]) |
|
5833 | #print("2",dataOut.output_LP_integrated.real[i,j,0]) | |
5829 | self.drift[nest]=pest |
|
5834 | self.drift[nest]=pest | |
5830 | self.ddrift[nest]=dataOut.dphi2 |
|
5835 | self.ddrift[nest]=dataOut.dphi2 | |
5831 | self.rdrift[nest]=float(nest) |
|
5836 | self.rdrift[nest]=float(nest) | |
5832 | nest+=1 |
|
5837 | nest+=1 | |
5833 |
|
5838 | |||
5834 | sorted(self.drift[:nest]) |
|
5839 | sorted(self.drift[:nest]) | |
5835 |
|
5840 | |||
5836 | #print(dataOut.dphi2) |
|
5841 | #print(dataOut.dphi2) | |
5837 | #exit(1) |
|
5842 | #exit(1) | |
5838 |
|
5843 | |||
5839 | for j in range(int(nest/4),int(3*nest/4)): |
|
5844 | for j in range(int(nest/4),int(3*nest/4)): | |
5840 | #i=int(self.rdrift[j]) |
|
5845 | #i=int(self.rdrift[j]) | |
5841 | alpha+=self.drift[j]/self.ddrift[j] |
|
5846 | alpha+=self.drift[j]/self.ddrift[j] | |
5842 | delta+=1.0/self.ddrift[j] |
|
5847 | delta+=1.0/self.ddrift[j] | |
5843 |
|
5848 | |||
5844 | alpha/=delta |
|
5849 | alpha/=delta | |
5845 | delta=1./numpy.sqrt(delta) |
|
5850 | delta=1./numpy.sqrt(delta) | |
5846 | vdrift=alpha-beta |
|
5851 | vdrift=alpha-beta | |
5847 | dvdrift=delta |
|
5852 | dvdrift=delta | |
5848 |
|
5853 | |||
5849 | #need to develop estimate of complete density profile using all |
|
5854 | #need to develop estimate of complete density profile using all | |
5850 | #available data |
|
5855 | #available data | |
5851 |
|
5856 | |||
5852 | #estimate sample variances for long-pulse power profile |
|
5857 | #estimate sample variances for long-pulse power profile | |
5853 |
|
5858 | |||
5854 | #nis=dataOut.NSCAN*dataOut.NAVG*dataOut.nint |
|
5859 | #nis=dataOut.NSCAN*dataOut.NAVG*dataOut.nint | |
5855 | nis = dataOut.nis/10 |
|
5860 | nis = dataOut.nis/10 | |
5856 | #print("nis",nis) |
|
5861 | #print("nis",nis) | |
5857 |
|
5862 | |||
5858 | self.sigma[:dataOut.NACF+2*dataOut.IBITS+2]=((anoise0+self.powera[:dataOut.NACF+2*dataOut.IBITS+2])**2)/float(nis) |
|
5863 | self.sigma[:dataOut.NACF+2*dataOut.IBITS+2]=((anoise0+self.powera[:dataOut.NACF+2*dataOut.IBITS+2])**2)/float(nis) | |
5859 | #print(self.sigma) |
|
5864 | #print(self.sigma) | |
5860 | #exit(1) |
|
5865 | #exit(1) | |
5861 | ioff=1 |
|
5866 | ioff=1 | |
5862 |
|
5867 | |||
5863 | #deconvolve rectangular pulse shape from profile ==> powerb, perror |
|
5868 | #deconvolve rectangular pulse shape from profile ==> powerb, perror | |
5864 |
|
5869 | |||
5865 |
|
5870 | |||
5866 | ############# START nnlswrap############# |
|
5871 | ############# START nnlswrap############# | |
5867 |
|
5872 | |||
5868 | if dataOut.ut_Faraday>14.0: |
|
5873 | if dataOut.ut_Faraday>14.0: | |
5869 | alpha_nnlswrap=20.0 |
|
5874 | alpha_nnlswrap=20.0 | |
5870 | else: |
|
5875 | else: | |
5871 | alpha_nnlswrap=30.0 |
|
5876 | alpha_nnlswrap=30.0 | |
5872 |
|
5877 | |||
5873 | range1_nnls=dataOut.NACF |
|
5878 | range1_nnls=dataOut.NACF | |
5874 | range2_nnls=dataOut.NACF+dataOut.IBITS-1 |
|
5879 | range2_nnls=dataOut.NACF+dataOut.IBITS-1 | |
5875 |
|
5880 | |||
5876 | g_nnlswrap=numpy.zeros((range1_nnls,range2_nnls),'float32') |
|
5881 | g_nnlswrap=numpy.zeros((range1_nnls,range2_nnls),'float32') | |
5877 | a_nnlswrap=numpy.zeros((range2_nnls,range2_nnls),'float64') |
|
5882 | a_nnlswrap=numpy.zeros((range2_nnls,range2_nnls),'float64') | |
5878 |
|
5883 | |||
5879 | for i in range(range1_nnls): |
|
5884 | for i in range(range1_nnls): | |
5880 | for j in range(range2_nnls): |
|
5885 | for j in range(range2_nnls): | |
5881 | if j>=i and j<i+dataOut.IBITS: |
|
5886 | if j>=i and j<i+dataOut.IBITS: | |
5882 | g_nnlswrap[i,j]=1.0 |
|
5887 | g_nnlswrap[i,j]=1.0 | |
5883 | else: |
|
5888 | else: | |
5884 | g_nnlswrap[i,j]=0.0 |
|
5889 | g_nnlswrap[i,j]=0.0 | |
5885 |
|
5890 | |||
5886 | a_nnlswrap[:]=numpy.matmul(numpy.transpose(g_nnlswrap),g_nnlswrap) |
|
5891 | a_nnlswrap[:]=numpy.matmul(numpy.transpose(g_nnlswrap),g_nnlswrap) | |
5887 |
|
5892 | |||
5888 | numpy.fill_diagonal(a_nnlswrap,a_nnlswrap.diagonal()+alpha_nnlswrap**2) |
|
5893 | numpy.fill_diagonal(a_nnlswrap,a_nnlswrap.diagonal()+alpha_nnlswrap**2) | |
5889 |
|
5894 | |||
5890 | #ERROR ANALYSIS# |
|
5895 | #ERROR ANALYSIS# | |
5891 |
|
5896 | |||
5892 | self.perror[:range2_nnls]=0.0 |
|
5897 | self.perror[:range2_nnls]=0.0 | |
5893 | self.perror[:range2_nnls]=numpy.matmul(1./(self.sigma[dataOut.IBITS+ioff:range1_nnls+dataOut.IBITS+ioff]),g_nnlswrap**2) |
|
5898 | self.perror[:range2_nnls]=numpy.matmul(1./(self.sigma[dataOut.IBITS+ioff:range1_nnls+dataOut.IBITS+ioff]),g_nnlswrap**2) | |
5894 | self.perror[:range1_nnls]+=(alpha_nnlswrap**2)/(self.sigma[dataOut.IBITS+ioff:range1_nnls+dataOut.IBITS+ioff]) |
|
5899 | self.perror[:range1_nnls]+=(alpha_nnlswrap**2)/(self.sigma[dataOut.IBITS+ioff:range1_nnls+dataOut.IBITS+ioff]) | |
5895 | self.perror[:range2_nnls]=1.00/self.perror[:range2_nnls] |
|
5900 | self.perror[:range2_nnls]=1.00/self.perror[:range2_nnls] | |
5896 |
|
5901 | |||
5897 | b_nnlswrap=numpy.zeros(range2_nnls,'float64') |
|
5902 | b_nnlswrap=numpy.zeros(range2_nnls,'float64') | |
5898 | b_nnlswrap[:]=numpy.matmul(self.powera[dataOut.IBITS+ioff:range1_nnls+dataOut.IBITS+ioff],g_nnlswrap) #match filter alturas |
|
5903 | b_nnlswrap[:]=numpy.matmul(self.powera[dataOut.IBITS+ioff:range1_nnls+dataOut.IBITS+ioff],g_nnlswrap) #match filter alturas | |
5899 |
|
5904 | |||
5900 | x_nnlswrap=numpy.zeros(range2_nnls,'float64') |
|
5905 | x_nnlswrap=numpy.zeros(range2_nnls,'float64') | |
5901 | x_nnlswrap[:]=nnls(a_nnlswrap,b_nnlswrap)[0] |
|
5906 | x_nnlswrap[:]=nnls(a_nnlswrap,b_nnlswrap)[0] | |
5902 |
|
5907 | |||
5903 | self.powerb[:range2_nnls]=x_nnlswrap |
|
5908 | self.powerb[:range2_nnls]=x_nnlswrap | |
5904 | #print(self.powerb[40]) |
|
5909 | #print(self.powerb[40]) | |
5905 | #print(self.powerb[66]) |
|
5910 | #print(self.powerb[66]) | |
5906 | #exit(1) |
|
5911 | #exit(1) | |
5907 | #############END nnlswrap############# |
|
5912 | #############END nnlswrap############# | |
5908 | #print(numpy.sum(numpy.sqrt(self.perror[0:dataOut.NACF]))) |
|
5913 | #print(numpy.sum(numpy.sqrt(self.perror[0:dataOut.NACF]))) | |
5909 | #print(self.powerb[0:dataOut.NACF]) |
|
5914 | #print(self.powerb[0:dataOut.NACF]) | |
5910 | #exit(1) |
|
5915 | #exit(1) | |
5911 | #estimate relative error for deconvolved profile (scaling irrelevant) |
|
5916 | #estimate relative error for deconvolved profile (scaling irrelevant) | |
5912 | #print(dataOut.NACF) |
|
5917 | #print(dataOut.NACF) | |
5913 | dataOut.ene[0:dataOut.NACF]=numpy.sqrt(self.perror[0:dataOut.NACF])/self.powerb[0:dataOut.NACF] |
|
5918 | dataOut.ene[0:dataOut.NACF]=numpy.sqrt(self.perror[0:dataOut.NACF])/self.powerb[0:dataOut.NACF] | |
5914 | #print(numpy.sum(dataOut.ene)) |
|
5919 | #print(numpy.sum(dataOut.ene)) | |
5915 | #exit(1) |
|
5920 | #exit(1) | |
5916 | aux=0 |
|
5921 | aux=0 | |
5917 |
|
5922 | |||
5918 | for i in range(dataOut.IBITS,dataOut.NACF): |
|
5923 | for i in range(dataOut.IBITS,dataOut.NACF): | |
5919 | self.dpulse[i]=self.lpulse[i]=0.0 |
|
5924 | self.dpulse[i]=self.lpulse[i]=0.0 | |
5920 | for j in range(dataOut.IBITS): |
|
5925 | for j in range(dataOut.IBITS): | |
5921 | k=int(i-j) |
|
5926 | k=int(i-j) | |
5922 | if k<36-aux and k>16: |
|
5927 | if k<36-aux and k>16: | |
5923 | self.dpulse[i]+=dataOut.ph2[k]/dataOut.h2[k] |
|
5928 | self.dpulse[i]+=dataOut.ph2[k]/dataOut.h2[k] | |
5924 | elif k>=36-aux: |
|
5929 | elif k>=36-aux: | |
5925 | self.lpulse[i]+=self.powerb[k] |
|
5930 | self.lpulse[i]+=self.powerb[k] | |
5926 | self.lagp[i]=self.powera[i] |
|
5931 | self.lagp[i]=self.powera[i] | |
5927 |
|
5932 | |||
5928 | #find scale factor that best merges profiles |
|
5933 | #find scale factor that best merges profiles | |
5929 |
|
5934 | |||
5930 | qi=sum(self.dpulse[32:dataOut.NACF]**2/(self.lagp[32:dataOut.NACF]+anoise0)**2) |
|
5935 | qi=sum(self.dpulse[32:dataOut.NACF]**2/(self.lagp[32:dataOut.NACF]+anoise0)**2) | |
5931 | ri=sum((self.dpulse[32:dataOut.NACF]*self.lpulse[32:dataOut.NACF])/(self.lagp[32:dataOut.NACF]+anoise0)**2) |
|
5936 | ri=sum((self.dpulse[32:dataOut.NACF]*self.lpulse[32:dataOut.NACF])/(self.lagp[32:dataOut.NACF]+anoise0)**2) | |
5932 | si=sum((self.dpulse[32:dataOut.NACF]*self.lagp[32:dataOut.NACF])/(self.lagp[32:dataOut.NACF]+anoise0)**2) |
|
5937 | si=sum((self.dpulse[32:dataOut.NACF]*self.lagp[32:dataOut.NACF])/(self.lagp[32:dataOut.NACF]+anoise0)**2) | |
5933 | ui=sum(self.lpulse[32:dataOut.NACF]**2/(self.lagp[32:dataOut.NACF]+anoise0)**2) |
|
5938 | ui=sum(self.lpulse[32:dataOut.NACF]**2/(self.lagp[32:dataOut.NACF]+anoise0)**2) | |
5934 | vi=sum((self.lpulse[32:dataOut.NACF]*self.lagp[32:dataOut.NACF])/(self.lagp[32:dataOut.NACF]+anoise0)**2) |
|
5939 | vi=sum((self.lpulse[32:dataOut.NACF]*self.lagp[32:dataOut.NACF])/(self.lagp[32:dataOut.NACF]+anoise0)**2) | |
5935 |
|
5940 | |||
5936 | alpha=(si*ui-vi*ri)/(qi*ui-ri*ri) |
|
5941 | alpha=(si*ui-vi*ri)/(qi*ui-ri*ri) | |
5937 | beta=(qi*vi-ri*si)/(qi*ui-ri*ri) |
|
5942 | beta=(qi*vi-ri*si)/(qi*ui-ri*ri) | |
5938 |
|
5943 | |||
5939 | #form density profile estimate, merging rescaled power profiles |
|
5944 | #form density profile estimate, merging rescaled power profiles | |
5940 | #print(dataOut.h2) |
|
5945 | #print(dataOut.h2) | |
5941 | #print(numpy.sum(alpha)) |
|
5946 | #print(numpy.sum(alpha)) | |
5942 | #print(numpy.sum(dataOut.ph2)) |
|
5947 | #print(numpy.sum(dataOut.ph2)) | |
5943 | self.powerb[16:36-aux]=alpha*dataOut.ph2[16:36-aux]/dataOut.h2[16:36-aux] |
|
5948 | self.powerb[16:36-aux]=alpha*dataOut.ph2[16:36-aux]/dataOut.h2[16:36-aux] | |
5944 | self.powerb[36-aux:dataOut.NACF]*=beta |
|
5949 | self.powerb[36-aux:dataOut.NACF]*=beta | |
5945 |
|
5950 | |||
5946 | #form Ne estimate, fill in error estimate at low altitudes |
|
5951 | #form Ne estimate, fill in error estimate at low altitudes | |
5947 |
|
5952 | |||
5948 | dataOut.ene[0:36-aux]=dataOut.sdp2[0:36-aux]/dataOut.ph2[0:36-aux] |
|
5953 | dataOut.ene[0:36-aux]=dataOut.sdp2[0:36-aux]/dataOut.ph2[0:36-aux] | |
5949 | dataOut.ne[:dataOut.NACF]=self.powerb[:dataOut.NACF]*dataOut.h2[:dataOut.NACF]/alpha |
|
5954 | dataOut.ne[:dataOut.NACF]=self.powerb[:dataOut.NACF]*dataOut.h2[:dataOut.NACF]/alpha | |
5950 | #print(numpy.sum(self.powerb)) |
|
5955 | #print(numpy.sum(self.powerb)) | |
5951 | #print(numpy.sum(dataOut.ene)) |
|
5956 | #print(numpy.sum(dataOut.ene)) | |
5952 | #print(numpy.sum(dataOut.ne)) |
|
5957 | #print(numpy.sum(dataOut.ne)) | |
5953 | #exit(1) |
|
5958 | #exit(1) | |
5954 | #now do error propagation: store zero lag error covariance in u |
|
5959 | #now do error propagation: store zero lag error covariance in u | |
5955 |
|
5960 | |||
5956 | nis=dataOut.NSCAN*dataOut.NAVG*dataOut.nint/1 # DLH serious debris removal |
|
5961 | nis=dataOut.NSCAN*dataOut.NAVG*dataOut.nint/1 # DLH serious debris removal | |
5957 |
|
5962 | |||
5958 | for i in range(dataOut.NACF): |
|
5963 | for i in range(dataOut.NACF): | |
5959 | for j in range(i,dataOut.NACF): |
|
5964 | for j in range(i,dataOut.NACF): | |
5960 | if j-i>=dataOut.IBITS: |
|
5965 | if j-i>=dataOut.IBITS: | |
5961 | self.u[i,j]=0.0 |
|
5966 | self.u[i,j]=0.0 | |
5962 | else: |
|
5967 | else: | |
5963 | self.u[i,j]=dataOut.output_LP_integrated.real[j-i,i,0]**2/float(nis) |
|
5968 | self.u[i,j]=dataOut.output_LP_integrated.real[j-i,i,0]**2/float(nis) | |
5964 | self.u[i,j]*=(anoise0+dataOut.output_LP_integrated.real[0,i,0])/dataOut.output_LP_integrated.real[0,i,0] |
|
5969 | self.u[i,j]*=(anoise0+dataOut.output_LP_integrated.real[0,i,0])/dataOut.output_LP_integrated.real[0,i,0] | |
5965 | self.u[i,j]*=(anoise0+dataOut.output_LP_integrated.real[0,j,0])/dataOut.output_LP_integrated.real[0,j,0] |
|
5970 | self.u[i,j]*=(anoise0+dataOut.output_LP_integrated.real[0,j,0])/dataOut.output_LP_integrated.real[0,j,0] | |
5966 |
|
5971 | |||
5967 | self.u[j,i]=self.u[i,j] |
|
5972 | self.u[j,i]=self.u[i,j] | |
5968 |
|
5973 | |||
5969 | #now error analyis for lag product matrix (diag), place in acf_err |
|
5974 | #now error analyis for lag product matrix (diag), place in acf_err | |
5970 |
|
5975 | |||
5971 | for i in range(dataOut.NACF): |
|
5976 | for i in range(dataOut.NACF): | |
5972 | for j in range(dataOut.IBITS): |
|
5977 | for j in range(dataOut.IBITS): | |
5973 | if j==0: |
|
5978 | if j==0: | |
5974 | dataOut.errors[0,i]=numpy.sqrt(self.u[i,i]) |
|
5979 | dataOut.errors[0,i]=numpy.sqrt(self.u[i,i]) | |
5975 | else: |
|
5980 | else: | |
5976 | dataOut.errors[j,i]=numpy.sqrt(((dataOut.output_LP_integrated.real[0,i,0]+anoise0)*(dataOut.output_LP_integrated.real[0,i+j,0]+anoise0)+dataOut.output_LP_integrated.real[j,i,0]**2)/float(2*nis)) |
|
5981 | dataOut.errors[j,i]=numpy.sqrt(((dataOut.output_LP_integrated.real[0,i,0]+anoise0)*(dataOut.output_LP_integrated.real[0,i+j,0]+anoise0)+dataOut.output_LP_integrated.real[j,i,0]**2)/float(2*nis)) | |
5977 | ''' |
|
5982 | ''' | |
5978 | print(numpy.sum(dataOut.output_LP_integrated)) |
|
5983 | print(numpy.sum(dataOut.output_LP_integrated)) | |
5979 | print(numpy.sum(dataOut.errors)) |
|
5984 | print(numpy.sum(dataOut.errors)) | |
5980 | print(numpy.sum(self.powerb)) |
|
5985 | print(numpy.sum(self.powerb)) | |
5981 | print(numpy.sum(dataOut.ne)) |
|
5986 | print(numpy.sum(dataOut.ne)) | |
5982 | print(numpy.sum(dataOut.lags_LP)) |
|
5987 | print(numpy.sum(dataOut.lags_LP)) | |
5983 | print(numpy.sum(dataOut.thb)) |
|
5988 | print(numpy.sum(dataOut.thb)) | |
5984 | print(numpy.sum(dataOut.bfm)) |
|
5989 | print(numpy.sum(dataOut.bfm)) | |
5985 | print(numpy.sum(dataOut.te)) |
|
5990 | print(numpy.sum(dataOut.te)) | |
5986 | print(numpy.sum(dataOut.ete)) |
|
5991 | print(numpy.sum(dataOut.ete)) | |
5987 | print(numpy.sum(dataOut.ti)) |
|
5992 | print(numpy.sum(dataOut.ti)) | |
5988 | print(numpy.sum(dataOut.eti)) |
|
5993 | print(numpy.sum(dataOut.eti)) | |
5989 | print(numpy.sum(dataOut.ph)) |
|
5994 | print(numpy.sum(dataOut.ph)) | |
5990 | print(numpy.sum(dataOut.eph)) |
|
5995 | print(numpy.sum(dataOut.eph)) | |
5991 | print(numpy.sum(dataOut.phe)) |
|
5996 | print(numpy.sum(dataOut.phe)) | |
5992 | print(numpy.sum(dataOut.ephe)) |
|
5997 | print(numpy.sum(dataOut.ephe)) | |
5993 | print(numpy.sum(dataOut.range1)) |
|
5998 | print(numpy.sum(dataOut.range1)) | |
5994 | print(numpy.sum(dataOut.ut)) |
|
5999 | print(numpy.sum(dataOut.ut)) | |
5995 | print(numpy.sum(dataOut.NACF)) |
|
6000 | print(numpy.sum(dataOut.NACF)) | |
5996 | print(numpy.sum(dataOut.fit_array_real)) |
|
6001 | print(numpy.sum(dataOut.fit_array_real)) | |
5997 | print(numpy.sum(dataOut.status)) |
|
6002 | print(numpy.sum(dataOut.status)) | |
5998 | print(numpy.sum(dataOut.NRANGE)) |
|
6003 | print(numpy.sum(dataOut.NRANGE)) | |
5999 | print(numpy.sum(dataOut.IBITS)) |
|
6004 | print(numpy.sum(dataOut.IBITS)) | |
6000 | exit(1) |
|
6005 | exit(1) | |
6001 | ''' |
|
6006 | ''' | |
6002 | ''' |
|
6007 | ''' | |
6003 | print(dataOut.te2[13:16]) |
|
6008 | print(dataOut.te2[13:16]) | |
6004 | print(numpy.sum(dataOut.te2)) |
|
6009 | print(numpy.sum(dataOut.te2)) | |
6005 | exit(1) |
|
6010 | exit(1) | |
6006 | ''' |
|
6011 | ''' | |
6007 | #print("Success 1") |
|
6012 | #print("Success 1") | |
6008 | ###################Correlation pulse and itself |
|
6013 | ###################Correlation pulse and itself | |
6009 |
|
6014 | |||
6010 | #print(dataOut.NRANGE) |
|
6015 | #print(dataOut.NRANGE) | |
6011 | print("LP Estimation") |
|
6016 | print("LP Estimation") | |
6012 | with suppress_stdout_stderr(): |
|
6017 | with suppress_stdout_stderr(): | |
6013 | #pass |
|
6018 | #pass | |
6014 | full_profile_profile.profile(numpy.transpose(dataOut.output_LP_integrated,(2,1,0)),numpy.transpose(dataOut.errors),self.powerb,dataOut.ne,dataOut.lags_LP,dataOut.thb,dataOut.bfm,dataOut.te,dataOut.ete,dataOut.ti,dataOut.eti,dataOut.ph,dataOut.eph,dataOut.phe,dataOut.ephe,dataOut.range1,dataOut.ut,dataOut.NACF,dataOut.fit_array_real,dataOut.status,dataOut.NRANGE,dataOut.IBITS) |
|
6019 | full_profile_profile.profile(numpy.transpose(dataOut.output_LP_integrated,(2,1,0)),numpy.transpose(dataOut.errors),self.powerb,dataOut.ne,dataOut.lags_LP,dataOut.thb,dataOut.bfm,dataOut.te,dataOut.ete,dataOut.ti,dataOut.eti,dataOut.ph,dataOut.eph,dataOut.phe,dataOut.ephe,dataOut.range1,dataOut.ut,dataOut.NACF,dataOut.fit_array_real,dataOut.status,dataOut.NRANGE,dataOut.IBITS) | |
6015 |
|
6020 | |||
6016 | print("status: ",dataOut.status) |
|
6021 | print("status: ",dataOut.status) | |
6017 |
|
6022 | |||
6018 | if dataOut.status>=3.5: |
|
6023 | if dataOut.status>=3.5: | |
6019 | dataOut.te[:]=numpy.nan |
|
6024 | dataOut.te[:]=numpy.nan | |
6020 | dataOut.ete[:]=numpy.nan |
|
6025 | dataOut.ete[:]=numpy.nan | |
6021 | dataOut.ti[:]=numpy.nan |
|
6026 | dataOut.ti[:]=numpy.nan | |
6022 | dataOut.eti[:]=numpy.nan |
|
6027 | dataOut.eti[:]=numpy.nan | |
6023 | dataOut.ph[:]=numpy.nan |
|
6028 | dataOut.ph[:]=numpy.nan | |
6024 | dataOut.eph[:]=numpy.nan |
|
6029 | dataOut.eph[:]=numpy.nan | |
6025 | dataOut.phe[:]=numpy.nan |
|
6030 | dataOut.phe[:]=numpy.nan | |
6026 | dataOut.ephe[:]=numpy.nan |
|
6031 | dataOut.ephe[:]=numpy.nan | |
6027 |
|
6032 | |||
6028 | return dataOut |
|
6033 | return dataOut | |
6029 |
|
6034 | |||
6030 | class LongPulseAnalysisSpectra(Operation): |
|
6035 | class LongPulseAnalysisSpectra(Operation): | |
6031 | """Operation to estimate ACFs, temperatures, total electron density and Hydrogen/Helium fractions from the Long Pulse data. |
|
6036 | """Operation to estimate ACFs, temperatures, total electron density and Hydrogen/Helium fractions from the Long Pulse data. | |
6032 |
|
6037 | |||
6033 | Parameters: |
|
6038 | Parameters: | |
6034 | ----------- |
|
6039 | ----------- | |
6035 | NACF : int |
|
6040 | NACF : int | |
6036 | .* |
|
6041 | .* | |
6037 |
|
6042 | |||
6038 | Example |
|
6043 | Example | |
6039 | -------- |
|
6044 | -------- | |
6040 |
|
6045 | |||
6041 | op = proc_unit.addOperation(name='LongPulseAnalysis', optype='other') |
|
6046 | op = proc_unit.addOperation(name='LongPulseAnalysis', optype='other') | |
6042 | op.addParameter(name='NACF', value='16', format='int') |
|
6047 | op.addParameter(name='NACF', value='16', format='int') | |
6043 |
|
6048 | |||
6044 | """ |
|
6049 | """ | |
6045 |
|
6050 | |||
6046 | def __init__(self, **kwargs): |
|
6051 | def __init__(self, **kwargs): | |
6047 |
|
6052 | |||
6048 | Operation.__init__(self, **kwargs) |
|
6053 | Operation.__init__(self, **kwargs) | |
6049 | self.aux=1 |
|
6054 | self.aux=1 | |
6050 |
|
6055 | |||
6051 | def run(self,dataOut,NACF): |
|
6056 | def run(self,dataOut,NACF): | |
6052 |
|
6057 | |||
6053 | dataOut.NACF=NACF |
|
6058 | dataOut.NACF=NACF | |
6054 | dataOut.heightList=dataOut.DH*(numpy.arange(dataOut.NACF)) |
|
6059 | dataOut.heightList=dataOut.DH*(numpy.arange(dataOut.NACF)) | |
6055 | anoise0=dataOut.tnoise[0] |
|
6060 | anoise0=dataOut.tnoise[0] | |
6056 | anoise1=anoise0*0.0 #seems to be noise in 1st lag 0.015 before '14 |
|
6061 | anoise1=anoise0*0.0 #seems to be noise in 1st lag 0.015 before '14 | |
6057 | #print(anoise0) |
|
6062 | #print(anoise0) | |
6058 | #exit(1) |
|
6063 | #exit(1) | |
6059 | if self.aux: |
|
6064 | if self.aux: | |
6060 | #dataOut.cut=31#26#height=31*15=465 |
|
6065 | #dataOut.cut=31#26#height=31*15=465 | |
6061 | self.cal=numpy.zeros((dataOut.NLAG),'float32') |
|
6066 | self.cal=numpy.zeros((dataOut.NLAG),'float32') | |
6062 | self.drift=numpy.zeros((200),'float32') |
|
6067 | self.drift=numpy.zeros((200),'float32') | |
6063 | self.rdrift=numpy.zeros((200),'float32') |
|
6068 | self.rdrift=numpy.zeros((200),'float32') | |
6064 | self.ddrift=numpy.zeros((200),'float32') |
|
6069 | self.ddrift=numpy.zeros((200),'float32') | |
6065 | self.sigma=numpy.zeros((dataOut.NRANGE),order='F',dtype='float32') |
|
6070 | self.sigma=numpy.zeros((dataOut.NRANGE),order='F',dtype='float32') | |
6066 | self.powera=numpy.zeros((dataOut.NRANGE),order='F',dtype='float32') |
|
6071 | self.powera=numpy.zeros((dataOut.NRANGE),order='F',dtype='float32') | |
6067 | self.powerb=numpy.zeros((dataOut.NRANGE),order='F',dtype='float32') |
|
6072 | self.powerb=numpy.zeros((dataOut.NRANGE),order='F',dtype='float32') | |
6068 | self.perror=numpy.zeros((dataOut.NRANGE),order='F',dtype='float32') |
|
6073 | self.perror=numpy.zeros((dataOut.NRANGE),order='F',dtype='float32') | |
6069 | dataOut.ene=numpy.zeros((dataOut.NRANGE),'float32') |
|
6074 | dataOut.ene=numpy.zeros((dataOut.NRANGE),'float32') | |
6070 | self.dpulse=numpy.zeros((dataOut.NACF),'float32') |
|
6075 | self.dpulse=numpy.zeros((dataOut.NACF),'float32') | |
6071 | self.lpulse=numpy.zeros((dataOut.NACF),'float32') |
|
6076 | self.lpulse=numpy.zeros((dataOut.NACF),'float32') | |
6072 | dataOut.lags_LP=numpy.zeros((dataOut.IBITS),order='F',dtype='float32') |
|
6077 | dataOut.lags_LP=numpy.zeros((dataOut.IBITS),order='F',dtype='float32') | |
6073 | self.lagp=numpy.zeros((dataOut.NACF),'float32') |
|
6078 | self.lagp=numpy.zeros((dataOut.NACF),'float32') | |
6074 | self.u=numpy.zeros((2*dataOut.NACF,2*dataOut.NACF),'float32') |
|
6079 | self.u=numpy.zeros((2*dataOut.NACF,2*dataOut.NACF),'float32') | |
6075 | dataOut.ne=numpy.zeros((dataOut.NRANGE),order='F',dtype='float32') |
|
6080 | dataOut.ne=numpy.zeros((dataOut.NRANGE),order='F',dtype='float32') | |
6076 | dataOut.te=numpy.zeros((dataOut.NACF),order='F',dtype='float32') |
|
6081 | dataOut.te=numpy.zeros((dataOut.NACF),order='F',dtype='float32') | |
6077 | dataOut.ete=numpy.zeros((dataOut.NACF),order='F',dtype='float32') |
|
6082 | dataOut.ete=numpy.zeros((dataOut.NACF),order='F',dtype='float32') | |
6078 | dataOut.ti=numpy.zeros((dataOut.NACF),order='F',dtype='float32') |
|
6083 | dataOut.ti=numpy.zeros((dataOut.NACF),order='F',dtype='float32') | |
6079 | dataOut.eti=numpy.zeros((dataOut.NACF),order='F',dtype='float32') |
|
6084 | dataOut.eti=numpy.zeros((dataOut.NACF),order='F',dtype='float32') | |
6080 | dataOut.ph=numpy.zeros((dataOut.NACF),order='F',dtype='float32') |
|
6085 | dataOut.ph=numpy.zeros((dataOut.NACF),order='F',dtype='float32') | |
6081 | dataOut.eph=numpy.zeros((dataOut.NACF),order='F',dtype='float32') |
|
6086 | dataOut.eph=numpy.zeros((dataOut.NACF),order='F',dtype='float32') | |
6082 | dataOut.phe=numpy.zeros((dataOut.NACF),order='F',dtype='float32') |
|
6087 | dataOut.phe=numpy.zeros((dataOut.NACF),order='F',dtype='float32') | |
6083 | dataOut.ephe=numpy.zeros((dataOut.NACF),order='F',dtype='float32') |
|
6088 | dataOut.ephe=numpy.zeros((dataOut.NACF),order='F',dtype='float32') | |
6084 | dataOut.errors=numpy.zeros((dataOut.IBITS,max(dataOut.NRANGE,dataOut.NSHTS)),order='F',dtype='float32') |
|
6089 | dataOut.errors=numpy.zeros((dataOut.IBITS,max(dataOut.NRANGE,dataOut.NSHTS)),order='F',dtype='float32') | |
6085 | dataOut.fit_array_real=numpy.zeros((max(dataOut.NRANGE,dataOut.NSHTS),dataOut.NLAG),order='F',dtype='float32') |
|
6090 | dataOut.fit_array_real=numpy.zeros((max(dataOut.NRANGE,dataOut.NSHTS),dataOut.NLAG),order='F',dtype='float32') | |
6086 | dataOut.status=numpy.zeros(1,'float32') |
|
6091 | dataOut.status=numpy.zeros(1,'float32') | |
6087 | dataOut.tx=240.0 #deberΓa provenir del header #hybrid |
|
6092 | dataOut.tx=240.0 #deberΓa provenir del header #hybrid | |
6088 |
|
6093 | |||
6089 | for i in range(dataOut.IBITS): |
|
6094 | for i in range(dataOut.IBITS): | |
6090 | dataOut.lags_LP[i]=float(i)*(dataOut.tx/150.0)/float(dataOut.IBITS) # (float)i*(header.tx/150.0)/(float)IBITS; |
|
6095 | dataOut.lags_LP[i]=float(i)*(dataOut.tx/150.0)/float(dataOut.IBITS) # (float)i*(header.tx/150.0)/(float)IBITS; | |
6091 |
|
6096 | |||
6092 | self.aux=0 |
|
6097 | self.aux=0 | |
6093 |
|
6098 | |||
6094 | dataOut.cut=30 |
|
6099 | dataOut.cut=30 | |
6095 | for i in range(30,15,-1): #AquΓ se calcula en donde se unirΓ‘ DP y LP en la parte final |
|
6100 | for i in range(30,15,-1): #AquΓ se calcula en donde se unirΓ‘ DP y LP en la parte final | |
6096 | if numpy.nanmax(dataOut.acfs_error_to_plot[i,:])>=10 or dataOut.info2[i]==0: |
|
6101 | if numpy.nanmax(dataOut.acfs_error_to_plot[i,:])>=10 or dataOut.info2[i]==0: | |
6097 | dataOut.cut=i-1 |
|
6102 | dataOut.cut=i-1 | |
6098 |
|
6103 | |||
6099 | for i in range(dataOut.NLAG): |
|
6104 | for i in range(dataOut.NLAG): | |
6100 | self.cal[i]=sum(dataOut.output_LP_integrated[i,:,3].real) #Lag x Height x Channel |
|
6105 | self.cal[i]=sum(dataOut.output_LP_integrated[i,:,3].real) #Lag x Height x Channel | |
6101 |
|
6106 | |||
6102 | #print(numpy.sum(self.cal)) #Coinciden |
|
6107 | #print(numpy.sum(self.cal)) #Coinciden | |
6103 | #exit(1) |
|
6108 | #exit(1) | |
6104 | self.cal/=float(dataOut.NRANGE) |
|
6109 | self.cal/=float(dataOut.NRANGE) | |
6105 |
|
6110 | |||
6106 |
|
6111 | |||
6107 | #################### PROBAR MΓS INTEGRACIΓN, SINO MODIFICAR VALOR DE "NIS" #################### |
|
6112 | #################### PROBAR MΓS INTEGRACIΓN, SINO MODIFICAR VALOR DE "NIS" #################### | |
6108 | # VER dataOut.nProfiles_LP # |
|
6113 | # VER dataOut.nProfiles_LP # | |
6109 |
|
6114 | |||
6110 | ''' |
|
6115 | ''' | |
6111 | #PLOTEAR POTENCIA VS RUIDO, QUIZA SE ESTA REMOVIENDO MUCHA SEΓAL |
|
6116 | #PLOTEAR POTENCIA VS RUIDO, QUIZA SE ESTA REMOVIENDO MUCHA SEΓAL | |
6112 | #print(dataOut.heightList) |
|
6117 | #print(dataOut.heightList) | |
6113 | import matplotlib.pyplot as plt |
|
6118 | import matplotlib.pyplot as plt | |
6114 | plt.plot(10*numpy.log10(dataOut.output_LP_integrated.real[0,:,0]),dataOut.range1) |
|
6119 | plt.plot(10*numpy.log10(dataOut.output_LP_integrated.real[0,:,0]),dataOut.range1) | |
6115 | #plt.plot(10*numpy.log10(dataOut.output_LP_integrated.real[0,:,0]/dataOut.nProfiles_LP),dataOut.range1) |
|
6120 | #plt.plot(10*numpy.log10(dataOut.output_LP_integrated.real[0,:,0]/dataOut.nProfiles_LP),dataOut.range1) | |
6116 | plt.axvline(10*numpy.log10(anoise0),color='k',linestyle='dashed') |
|
6121 | plt.axvline(10*numpy.log10(anoise0),color='k',linestyle='dashed') | |
6117 | plt.grid() |
|
6122 | plt.grid() | |
6118 | plt.xlim(20,100) |
|
6123 | plt.xlim(20,100) | |
6119 | plt.show() |
|
6124 | plt.show() | |
6120 | ''' |
|
6125 | ''' | |
6121 |
|
6126 | |||
6122 |
|
6127 | |||
6123 | for j in range(dataOut.NACF+2*dataOut.IBITS+2): |
|
6128 | for j in range(dataOut.NACF+2*dataOut.IBITS+2): | |
6124 |
|
6129 | |||
6125 | dataOut.output_LP_integrated.real[0,j,0]-=anoise0 #lag0 ch0 |
|
6130 | dataOut.output_LP_integrated.real[0,j,0]-=anoise0 #lag0 ch0 | |
6126 | dataOut.output_LP_integrated.real[1,j,0]-=anoise1 #lag1 ch0 |
|
6131 | dataOut.output_LP_integrated.real[1,j,0]-=anoise1 #lag1 ch0 | |
6127 |
|
6132 | |||
6128 | for i in range(1,dataOut.NLAG): #remove cal data from certain lags |
|
6133 | for i in range(1,dataOut.NLAG): #remove cal data from certain lags | |
6129 | dataOut.output_LP_integrated.real[i,j,0]-=self.cal[i] |
|
6134 | dataOut.output_LP_integrated.real[i,j,0]-=self.cal[i] | |
6130 | k=max(j,26) #constant power below range 26 |
|
6135 | k=max(j,26) #constant power below range 26 | |
6131 | self.powera[j]=dataOut.output_LP_integrated.real[0,k,0] #Lag0 and Channel 0 |
|
6136 | self.powera[j]=dataOut.output_LP_integrated.real[0,k,0] #Lag0 and Channel 0 | |
6132 |
|
6137 | |||
6133 | ## examine drifts here - based on 60 'indep.' estimates |
|
6138 | ## examine drifts here - based on 60 'indep.' estimates | |
6134 | #print(numpy.sum(self.powera)) |
|
6139 | #print(numpy.sum(self.powera)) | |
6135 | #exit(1) |
|
6140 | #exit(1) | |
6136 | #nis=dataOut.NSCAN*dataOut.NAVG*dataOut.nint*10 |
|
6141 | #nis=dataOut.NSCAN*dataOut.NAVG*dataOut.nint*10 | |
6137 | nis = dataOut.nis |
|
6142 | nis = dataOut.nis | |
6138 | #print("nis",nis) |
|
6143 | #print("nis",nis) | |
6139 | alpha=beta=delta=0.0 |
|
6144 | alpha=beta=delta=0.0 | |
6140 | nest=0 |
|
6145 | nest=0 | |
6141 | gamma=3.0/(2.0*numpy.pi*dataOut.lags_LP[1]*1.0e-3) |
|
6146 | gamma=3.0/(2.0*numpy.pi*dataOut.lags_LP[1]*1.0e-3) | |
6142 | beta=gamma*(math.atan2(dataOut.output_LP_integrated.imag[14,0,2],dataOut.output_LP_integrated.real[14,0,2])-math.atan2(dataOut.output_LP_integrated.imag[1,0,2],dataOut.output_LP_integrated.real[1,0,2]))/13.0 |
|
6147 | beta=gamma*(math.atan2(dataOut.output_LP_integrated.imag[14,0,2],dataOut.output_LP_integrated.real[14,0,2])-math.atan2(dataOut.output_LP_integrated.imag[1,0,2],dataOut.output_LP_integrated.real[1,0,2]))/13.0 | |
6143 | #print(gamma,beta) |
|
6148 | #print(gamma,beta) | |
6144 | #exit(1) |
|
6149 | #exit(1) | |
6145 | for i in range(1,3): |
|
6150 | for i in range(1,3): | |
6146 | gamma=3.0/(2.0*numpy.pi*dataOut.lags_LP[i]*1.0e-3) |
|
6151 | gamma=3.0/(2.0*numpy.pi*dataOut.lags_LP[i]*1.0e-3) | |
6147 | #print("gamma",gamma) |
|
6152 | #print("gamma",gamma) | |
6148 | for j in range(34,44): |
|
6153 | for j in range(34,44): | |
6149 | rho2=numpy.abs(dataOut.output_LP_integrated[i,j,0])/numpy.abs(dataOut.output_LP_integrated[0,j,0]) |
|
6154 | rho2=numpy.abs(dataOut.output_LP_integrated[i,j,0])/numpy.abs(dataOut.output_LP_integrated[0,j,0]) | |
6150 | dataOut.dphi2=(1.0/rho2-1.0)/(float(2*nis)) |
|
6155 | dataOut.dphi2=(1.0/rho2-1.0)/(float(2*nis)) | |
6151 | dataOut.dphi2*=gamma**2 |
|
6156 | dataOut.dphi2*=gamma**2 | |
6152 | pest=gamma*math.atan(dataOut.output_LP_integrated.imag[i,j,0]/dataOut.output_LP_integrated.real[i,j,0]) |
|
6157 | pest=gamma*math.atan(dataOut.output_LP_integrated.imag[i,j,0]/dataOut.output_LP_integrated.real[i,j,0]) | |
6153 | #print("1",dataOut.output_LP_integrated.imag[i,j,0]) |
|
6158 | #print("1",dataOut.output_LP_integrated.imag[i,j,0]) | |
6154 | #print("2",dataOut.output_LP_integrated.real[i,j,0]) |
|
6159 | #print("2",dataOut.output_LP_integrated.real[i,j,0]) | |
6155 | self.drift[nest]=pest |
|
6160 | self.drift[nest]=pest | |
6156 | self.ddrift[nest]=dataOut.dphi2 |
|
6161 | self.ddrift[nest]=dataOut.dphi2 | |
6157 | self.rdrift[nest]=float(nest) |
|
6162 | self.rdrift[nest]=float(nest) | |
6158 | nest+=1 |
|
6163 | nest+=1 | |
6159 |
|
6164 | |||
6160 | sorted(self.drift[:nest]) |
|
6165 | sorted(self.drift[:nest]) | |
6161 |
|
6166 | |||
6162 | #print(dataOut.dphi2) |
|
6167 | #print(dataOut.dphi2) | |
6163 | #exit(1) |
|
6168 | #exit(1) | |
6164 |
|
6169 | |||
6165 | for j in range(int(nest/4),int(3*nest/4)): |
|
6170 | for j in range(int(nest/4),int(3*nest/4)): | |
6166 | #i=int(self.rdrift[j]) |
|
6171 | #i=int(self.rdrift[j]) | |
6167 | alpha+=self.drift[j]/self.ddrift[j] |
|
6172 | alpha+=self.drift[j]/self.ddrift[j] | |
6168 | delta+=1.0/self.ddrift[j] |
|
6173 | delta+=1.0/self.ddrift[j] | |
6169 |
|
6174 | |||
6170 | alpha/=delta |
|
6175 | alpha/=delta | |
6171 | delta=1./numpy.sqrt(delta) |
|
6176 | delta=1./numpy.sqrt(delta) | |
6172 | vdrift=alpha-beta |
|
6177 | vdrift=alpha-beta | |
6173 | dvdrift=delta |
|
6178 | dvdrift=delta | |
6174 |
|
6179 | |||
6175 | #need to develop estimate of complete density profile using all |
|
6180 | #need to develop estimate of complete density profile using all | |
6176 | #available data |
|
6181 | #available data | |
6177 |
|
6182 | |||
6178 | #estimate sample variances for long-pulse power profile |
|
6183 | #estimate sample variances for long-pulse power profile | |
6179 |
|
6184 | |||
6180 | #nis=dataOut.NSCAN*dataOut.NAVG*dataOut.nint |
|
6185 | #nis=dataOut.NSCAN*dataOut.NAVG*dataOut.nint | |
6181 | nis = dataOut.nis/10 |
|
6186 | nis = dataOut.nis/10 | |
6182 | #print("nis",nis) |
|
6187 | #print("nis",nis) | |
6183 |
|
6188 | |||
6184 | self.sigma[:dataOut.NACF+2*dataOut.IBITS+2]=((anoise0+self.powera[:dataOut.NACF+2*dataOut.IBITS+2])**2)/float(nis) |
|
6189 | self.sigma[:dataOut.NACF+2*dataOut.IBITS+2]=((anoise0+self.powera[:dataOut.NACF+2*dataOut.IBITS+2])**2)/float(nis) | |
6185 | #print(self.sigma) |
|
6190 | #print(self.sigma) | |
6186 | #exit(1) |
|
6191 | #exit(1) | |
6187 | ioff=1 |
|
6192 | ioff=1 | |
6188 |
|
6193 | |||
6189 | #deconvolve rectangular pulse shape from profile ==> powerb, perror |
|
6194 | #deconvolve rectangular pulse shape from profile ==> powerb, perror | |
6190 |
|
6195 | |||
6191 | ''' |
|
6196 | ''' | |
6192 | ############# START nnlswrap############# |
|
6197 | ############# START nnlswrap############# | |
6193 |
|
6198 | |||
6194 | if dataOut.ut_Faraday>14.0: |
|
6199 | if dataOut.ut_Faraday>14.0: | |
6195 | alpha_nnlswrap=20.0 |
|
6200 | alpha_nnlswrap=20.0 | |
6196 | else: |
|
6201 | else: | |
6197 | alpha_nnlswrap=30.0 |
|
6202 | alpha_nnlswrap=30.0 | |
6198 |
|
6203 | |||
6199 | range1_nnls=dataOut.NACF |
|
6204 | range1_nnls=dataOut.NACF | |
6200 | range2_nnls=dataOut.NACF+dataOut.IBITS-1 |
|
6205 | range2_nnls=dataOut.NACF+dataOut.IBITS-1 | |
6201 |
|
6206 | |||
6202 | g_nnlswrap=numpy.zeros((range1_nnls,range2_nnls),'float32') |
|
6207 | g_nnlswrap=numpy.zeros((range1_nnls,range2_nnls),'float32') | |
6203 | a_nnlswrap=numpy.zeros((range2_nnls,range2_nnls),'float64') |
|
6208 | a_nnlswrap=numpy.zeros((range2_nnls,range2_nnls),'float64') | |
6204 |
|
6209 | |||
6205 | for i in range(range1_nnls): |
|
6210 | for i in range(range1_nnls): | |
6206 | for j in range(range2_nnls): |
|
6211 | for j in range(range2_nnls): | |
6207 | if j>=i and j<i+dataOut.IBITS: |
|
6212 | if j>=i and j<i+dataOut.IBITS: | |
6208 | g_nnlswrap[i,j]=1.0 |
|
6213 | g_nnlswrap[i,j]=1.0 | |
6209 | else: |
|
6214 | else: | |
6210 | g_nnlswrap[i,j]=0.0 |
|
6215 | g_nnlswrap[i,j]=0.0 | |
6211 |
|
6216 | |||
6212 | a_nnlswrap[:]=numpy.matmul(numpy.transpose(g_nnlswrap),g_nnlswrap) |
|
6217 | a_nnlswrap[:]=numpy.matmul(numpy.transpose(g_nnlswrap),g_nnlswrap) | |
6213 |
|
6218 | |||
6214 | numpy.fill_diagonal(a_nnlswrap,a_nnlswrap.diagonal()+alpha_nnlswrap**2) |
|
6219 | numpy.fill_diagonal(a_nnlswrap,a_nnlswrap.diagonal()+alpha_nnlswrap**2) | |
6215 |
|
6220 | |||
6216 | #ERROR ANALYSIS# |
|
6221 | #ERROR ANALYSIS# | |
6217 |
|
6222 | |||
6218 | self.perror[:range2_nnls]=0.0 |
|
6223 | self.perror[:range2_nnls]=0.0 | |
6219 | self.perror[:range2_nnls]=numpy.matmul(1./(self.sigma[dataOut.IBITS+ioff:range1_nnls+dataOut.IBITS+ioff]),g_nnlswrap**2) |
|
6224 | self.perror[:range2_nnls]=numpy.matmul(1./(self.sigma[dataOut.IBITS+ioff:range1_nnls+dataOut.IBITS+ioff]),g_nnlswrap**2) | |
6220 | self.perror[:range1_nnls]+=(alpha_nnlswrap**2)/(self.sigma[dataOut.IBITS+ioff:range1_nnls+dataOut.IBITS+ioff]) |
|
6225 | self.perror[:range1_nnls]+=(alpha_nnlswrap**2)/(self.sigma[dataOut.IBITS+ioff:range1_nnls+dataOut.IBITS+ioff]) | |
6221 | self.perror[:range2_nnls]=1.00/self.perror[:range2_nnls] |
|
6226 | self.perror[:range2_nnls]=1.00/self.perror[:range2_nnls] | |
6222 |
|
6227 | |||
6223 | b_nnlswrap=numpy.zeros(range2_nnls,'float64') |
|
6228 | b_nnlswrap=numpy.zeros(range2_nnls,'float64') | |
6224 | b_nnlswrap[:]=numpy.matmul(self.powera[dataOut.IBITS+ioff:range1_nnls+dataOut.IBITS+ioff],g_nnlswrap) |
|
6229 | b_nnlswrap[:]=numpy.matmul(self.powera[dataOut.IBITS+ioff:range1_nnls+dataOut.IBITS+ioff],g_nnlswrap) | |
6225 |
|
6230 | |||
6226 | x_nnlswrap=numpy.zeros(range2_nnls,'float64') |
|
6231 | x_nnlswrap=numpy.zeros(range2_nnls,'float64') | |
6227 | x_nnlswrap[:]=nnls(a_nnlswrap,b_nnlswrap)[0] |
|
6232 | x_nnlswrap[:]=nnls(a_nnlswrap,b_nnlswrap)[0] | |
6228 |
|
6233 | |||
6229 | self.powerb[:range2_nnls]=x_nnlswrap |
|
6234 | self.powerb[:range2_nnls]=x_nnlswrap | |
6230 | #print(self.powerb[40]) |
|
6235 | #print(self.powerb[40]) | |
6231 | #print(self.powerb[66]) |
|
6236 | #print(self.powerb[66]) | |
6232 | #exit(1) |
|
6237 | #exit(1) | |
6233 | #############END nnlswrap############# |
|
6238 | #############END nnlswrap############# | |
6234 | ''' |
|
6239 | ''' | |
6235 | self.powerb[:] = self.powera |
|
6240 | self.powerb[:] = self.powera | |
6236 | self.perror[:] = 0. |
|
6241 | self.perror[:] = 0. | |
6237 | #print(numpy.sum(numpy.sqrt(self.perror[0:dataOut.NACF]))) |
|
6242 | #print(numpy.sum(numpy.sqrt(self.perror[0:dataOut.NACF]))) | |
6238 | #print(self.powerb[0:dataOut.NACF]) |
|
6243 | #print(self.powerb[0:dataOut.NACF]) | |
6239 | #exit(1) |
|
6244 | #exit(1) | |
6240 | #estimate relative error for deconvolved profile (scaling irrelevant) |
|
6245 | #estimate relative error for deconvolved profile (scaling irrelevant) | |
6241 | #print(dataOut.NACF) |
|
6246 | #print(dataOut.NACF) | |
6242 | dataOut.ene[0:dataOut.NACF]=numpy.sqrt(self.perror[0:dataOut.NACF])/self.powerb[0:dataOut.NACF] |
|
6247 | dataOut.ene[0:dataOut.NACF]=numpy.sqrt(self.perror[0:dataOut.NACF])/self.powerb[0:dataOut.NACF] | |
6243 | #print(numpy.sum(dataOut.ene)) |
|
6248 | #print(numpy.sum(dataOut.ene)) | |
6244 | #exit(1) |
|
6249 | #exit(1) | |
6245 | aux=0 |
|
6250 | aux=0 | |
6246 |
|
6251 | |||
6247 | for i in range(dataOut.IBITS,dataOut.NACF): |
|
6252 | for i in range(dataOut.IBITS,dataOut.NACF): | |
6248 | self.dpulse[i]=self.lpulse[i]=0.0 |
|
6253 | self.dpulse[i]=self.lpulse[i]=0.0 | |
6249 | for j in range(dataOut.IBITS): |
|
6254 | for j in range(dataOut.IBITS): | |
6250 | k=int(i-j) |
|
6255 | k=int(i-j) | |
6251 | if k<36-aux and k>16: |
|
6256 | if k<36-aux and k>16: | |
6252 | self.dpulse[i]+=dataOut.ph2[k]/dataOut.h2[k] |
|
6257 | self.dpulse[i]+=dataOut.ph2[k]/dataOut.h2[k] | |
6253 | elif k>=36-aux: |
|
6258 | elif k>=36-aux: | |
6254 | self.lpulse[i]+=self.powerb[k] |
|
6259 | self.lpulse[i]+=self.powerb[k] | |
6255 | self.lagp[i]=self.powera[i] |
|
6260 | self.lagp[i]=self.powera[i] | |
6256 |
|
6261 | |||
6257 | #find scale factor that best merges profiles |
|
6262 | #find scale factor that best merges profiles | |
6258 |
|
6263 | |||
6259 | qi=sum(self.dpulse[32:dataOut.NACF]**2/(self.lagp[32:dataOut.NACF]+anoise0)**2) |
|
6264 | qi=sum(self.dpulse[32:dataOut.NACF]**2/(self.lagp[32:dataOut.NACF]+anoise0)**2) | |
6260 | ri=sum((self.dpulse[32:dataOut.NACF]*self.lpulse[32:dataOut.NACF])/(self.lagp[32:dataOut.NACF]+anoise0)**2) |
|
6265 | ri=sum((self.dpulse[32:dataOut.NACF]*self.lpulse[32:dataOut.NACF])/(self.lagp[32:dataOut.NACF]+anoise0)**2) | |
6261 | si=sum((self.dpulse[32:dataOut.NACF]*self.lagp[32:dataOut.NACF])/(self.lagp[32:dataOut.NACF]+anoise0)**2) |
|
6266 | si=sum((self.dpulse[32:dataOut.NACF]*self.lagp[32:dataOut.NACF])/(self.lagp[32:dataOut.NACF]+anoise0)**2) | |
6262 | ui=sum(self.lpulse[32:dataOut.NACF]**2/(self.lagp[32:dataOut.NACF]+anoise0)**2) |
|
6267 | ui=sum(self.lpulse[32:dataOut.NACF]**2/(self.lagp[32:dataOut.NACF]+anoise0)**2) | |
6263 | vi=sum((self.lpulse[32:dataOut.NACF]*self.lagp[32:dataOut.NACF])/(self.lagp[32:dataOut.NACF]+anoise0)**2) |
|
6268 | vi=sum((self.lpulse[32:dataOut.NACF]*self.lagp[32:dataOut.NACF])/(self.lagp[32:dataOut.NACF]+anoise0)**2) | |
6264 |
|
6269 | |||
6265 | alpha=(si*ui-vi*ri)/(qi*ui-ri*ri) |
|
6270 | alpha=(si*ui-vi*ri)/(qi*ui-ri*ri) | |
6266 | beta=(qi*vi-ri*si)/(qi*ui-ri*ri) |
|
6271 | beta=(qi*vi-ri*si)/(qi*ui-ri*ri) | |
6267 |
|
6272 | |||
6268 | #form density profile estimate, merging rescaled power profiles |
|
6273 | #form density profile estimate, merging rescaled power profiles | |
6269 | #print(dataOut.h2) |
|
6274 | #print(dataOut.h2) | |
6270 | #print(numpy.sum(alpha)) |
|
6275 | #print(numpy.sum(alpha)) | |
6271 | #print(numpy.sum(dataOut.ph2)) |
|
6276 | #print(numpy.sum(dataOut.ph2)) | |
6272 | self.powerb[16:36-aux]=alpha*dataOut.ph2[16:36-aux]/dataOut.h2[16:36-aux] |
|
6277 | self.powerb[16:36-aux]=alpha*dataOut.ph2[16:36-aux]/dataOut.h2[16:36-aux] | |
6273 | self.powerb[36-aux:dataOut.NACF]*=beta |
|
6278 | self.powerb[36-aux:dataOut.NACF]*=beta | |
6274 |
|
6279 | |||
6275 | #form Ne estimate, fill in error estimate at low altitudes |
|
6280 | #form Ne estimate, fill in error estimate at low altitudes | |
6276 |
|
6281 | |||
6277 | dataOut.ene[0:36-aux]=dataOut.sdp2[0:36-aux]/dataOut.ph2[0:36-aux] |
|
6282 | dataOut.ene[0:36-aux]=dataOut.sdp2[0:36-aux]/dataOut.ph2[0:36-aux] | |
6278 | dataOut.ne[:dataOut.NACF]=self.powerb[:dataOut.NACF]*dataOut.h2[:dataOut.NACF]/alpha |
|
6283 | dataOut.ne[:dataOut.NACF]=self.powerb[:dataOut.NACF]*dataOut.h2[:dataOut.NACF]/alpha | |
6279 | #print(numpy.sum(self.powerb)) |
|
6284 | #print(numpy.sum(self.powerb)) | |
6280 | #print(numpy.sum(dataOut.ene)) |
|
6285 | #print(numpy.sum(dataOut.ene)) | |
6281 | #print(numpy.sum(dataOut.ne)) |
|
6286 | #print(numpy.sum(dataOut.ne)) | |
6282 | #exit(1) |
|
6287 | #exit(1) | |
6283 | #now do error propagation: store zero lag error covariance in u |
|
6288 | #now do error propagation: store zero lag error covariance in u | |
6284 |
|
6289 | |||
6285 | nis=dataOut.NSCAN*dataOut.NAVG*dataOut.nint/1 # DLH serious debris removal |
|
6290 | nis=dataOut.NSCAN*dataOut.NAVG*dataOut.nint/1 # DLH serious debris removal | |
6286 |
|
6291 | |||
6287 | for i in range(dataOut.NACF): |
|
6292 | for i in range(dataOut.NACF): | |
6288 | for j in range(i,dataOut.NACF): |
|
6293 | for j in range(i,dataOut.NACF): | |
6289 | if j-i>=dataOut.IBITS: |
|
6294 | if j-i>=dataOut.IBITS: | |
6290 | self.u[i,j]=0.0 |
|
6295 | self.u[i,j]=0.0 | |
6291 | else: |
|
6296 | else: | |
6292 | self.u[i,j]=dataOut.output_LP_integrated.real[j-i,i,0]**2/float(nis) |
|
6297 | self.u[i,j]=dataOut.output_LP_integrated.real[j-i,i,0]**2/float(nis) | |
6293 | self.u[i,j]*=(anoise0+dataOut.output_LP_integrated.real[0,i,0])/dataOut.output_LP_integrated.real[0,i,0] |
|
6298 | self.u[i,j]*=(anoise0+dataOut.output_LP_integrated.real[0,i,0])/dataOut.output_LP_integrated.real[0,i,0] | |
6294 | self.u[i,j]*=(anoise0+dataOut.output_LP_integrated.real[0,j,0])/dataOut.output_LP_integrated.real[0,j,0] |
|
6299 | self.u[i,j]*=(anoise0+dataOut.output_LP_integrated.real[0,j,0])/dataOut.output_LP_integrated.real[0,j,0] | |
6295 |
|
6300 | |||
6296 | self.u[j,i]=self.u[i,j] |
|
6301 | self.u[j,i]=self.u[i,j] | |
6297 |
|
6302 | |||
6298 | #now error analyis for lag product matrix (diag), place in acf_err |
|
6303 | #now error analyis for lag product matrix (diag), place in acf_err | |
6299 |
|
6304 | |||
6300 | for i in range(dataOut.NACF): |
|
6305 | for i in range(dataOut.NACF): | |
6301 | for j in range(dataOut.IBITS): |
|
6306 | for j in range(dataOut.IBITS): | |
6302 | if j==0: |
|
6307 | if j==0: | |
6303 | dataOut.errors[0,i]=numpy.sqrt(self.u[i,i]) |
|
6308 | dataOut.errors[0,i]=numpy.sqrt(self.u[i,i]) | |
6304 | else: |
|
6309 | else: | |
6305 | dataOut.errors[j,i]=numpy.sqrt(((dataOut.output_LP_integrated.real[0,i,0]+anoise0)*(dataOut.output_LP_integrated.real[0,i+j,0]+anoise0)+dataOut.output_LP_integrated.real[j,i,0]**2)/float(2*nis)) |
|
6310 | dataOut.errors[j,i]=numpy.sqrt(((dataOut.output_LP_integrated.real[0,i,0]+anoise0)*(dataOut.output_LP_integrated.real[0,i+j,0]+anoise0)+dataOut.output_LP_integrated.real[j,i,0]**2)/float(2*nis)) | |
6306 |
|
6311 | |||
6307 | print("Success") |
|
6312 | print("Success") | |
6308 | #print(dataOut.NRANGE) |
|
6313 | #print(dataOut.NRANGE) | |
6309 | with suppress_stdout_stderr(): |
|
6314 | with suppress_stdout_stderr(): | |
6310 | pass |
|
6315 | pass | |
6311 | #full_profile_profile.profile(numpy.transpose(dataOut.output_LP_integrated,(2,1,0)),numpy.transpose(dataOut.errors),self.powerb,dataOut.ne,dataOut.lags_LP,dataOut.thb,dataOut.bfm,dataOut.te,dataOut.ete,dataOut.ti,dataOut.eti,dataOut.ph,dataOut.eph,dataOut.phe,dataOut.ephe,dataOut.range1,dataOut.ut,dataOut.NACF,dataOut.fit_array_real,dataOut.status,dataOut.NRANGE,dataOut.IBITS) |
|
6316 | #full_profile_profile.profile(numpy.transpose(dataOut.output_LP_integrated,(2,1,0)),numpy.transpose(dataOut.errors),self.powerb,dataOut.ne,dataOut.lags_LP,dataOut.thb,dataOut.bfm,dataOut.te,dataOut.ete,dataOut.ti,dataOut.eti,dataOut.ph,dataOut.eph,dataOut.phe,dataOut.ephe,dataOut.range1,dataOut.ut,dataOut.NACF,dataOut.fit_array_real,dataOut.status,dataOut.NRANGE,dataOut.IBITS) | |
6312 |
|
6317 | |||
6313 | print("status: ",dataOut.status) |
|
6318 | print("status: ",dataOut.status) | |
6314 |
|
6319 | |||
6315 | if dataOut.status>=3.5: |
|
6320 | if dataOut.status>=3.5: | |
6316 | dataOut.te[:]=numpy.nan |
|
6321 | dataOut.te[:]=numpy.nan | |
6317 | dataOut.ete[:]=numpy.nan |
|
6322 | dataOut.ete[:]=numpy.nan | |
6318 | dataOut.ti[:]=numpy.nan |
|
6323 | dataOut.ti[:]=numpy.nan | |
6319 | dataOut.eti[:]=numpy.nan |
|
6324 | dataOut.eti[:]=numpy.nan | |
6320 | dataOut.ph[:]=numpy.nan |
|
6325 | dataOut.ph[:]=numpy.nan | |
6321 | dataOut.eph[:]=numpy.nan |
|
6326 | dataOut.eph[:]=numpy.nan | |
6322 | dataOut.phe[:]=numpy.nan |
|
6327 | dataOut.phe[:]=numpy.nan | |
6323 | dataOut.ephe[:]=numpy.nan |
|
6328 | dataOut.ephe[:]=numpy.nan | |
6324 |
|
6329 | |||
6325 | return dataOut |
|
6330 | return dataOut | |
6326 |
|
6331 | |||
6327 | class LongPulseAnalysis_V2(Operation): |
|
6332 | class LongPulseAnalysis_V2(Operation): | |
6328 | """Operation to estimate ACFs, temperatures, total electron density and Hydrogen/Helium fractions from the Long Pulse data. |
|
6333 | """Operation to estimate ACFs, temperatures, total electron density and Hydrogen/Helium fractions from the Long Pulse data. | |
6329 |
|
6334 | |||
6330 | Parameters: |
|
6335 | Parameters: | |
6331 | ----------- |
|
6336 | ----------- | |
6332 | NACF : int |
|
6337 | NACF : int | |
6333 | .* |
|
6338 | .* | |
6334 |
|
6339 | |||
6335 | Example |
|
6340 | Example | |
6336 | -------- |
|
6341 | -------- | |
6337 |
|
6342 | |||
6338 | op = proc_unit.addOperation(name='LongPulseAnalysis', optype='other') |
|
6343 | op = proc_unit.addOperation(name='LongPulseAnalysis', optype='other') | |
6339 | op.addParameter(name='NACF', value='16', format='int') |
|
6344 | op.addParameter(name='NACF', value='16', format='int') | |
6340 |
|
6345 | |||
6341 | """ |
|
6346 | """ | |
6342 |
|
6347 | |||
6343 | def __init__(self, **kwargs): |
|
6348 | def __init__(self, **kwargs): | |
6344 |
|
6349 | |||
6345 | Operation.__init__(self, **kwargs) |
|
6350 | Operation.__init__(self, **kwargs) | |
6346 | self.aux=1 |
|
6351 | self.aux=1 | |
6347 |
|
6352 | |||
6348 | def run(self,dataOut,NACF): |
|
6353 | def run(self,dataOut,NACF): | |
6349 |
|
6354 | |||
6350 | dataOut.NACF=NACF |
|
6355 | dataOut.NACF=NACF | |
6351 | dataOut.heightList=dataOut.DH*(numpy.arange(dataOut.NACF)) |
|
6356 | dataOut.heightList=dataOut.DH*(numpy.arange(dataOut.NACF)) | |
6352 | anoise0=dataOut.tnoise[0] |
|
6357 | anoise0=dataOut.tnoise[0] | |
6353 | anoise1=anoise0*0.0 #seems to be noise in 1st lag 0.015 before '14 |
|
6358 | anoise1=anoise0*0.0 #seems to be noise in 1st lag 0.015 before '14 | |
6354 | #print(anoise0) |
|
6359 | #print(anoise0) | |
6355 | #exit(1) |
|
6360 | #exit(1) | |
6356 | if self.aux: |
|
6361 | if self.aux: | |
6357 | #dataOut.cut=31#26#height=31*15=465 |
|
6362 | #dataOut.cut=31#26#height=31*15=465 | |
6358 | self.cal=numpy.zeros((dataOut.NLAG),'float32') |
|
6363 | self.cal=numpy.zeros((dataOut.NLAG),'float32') | |
6359 | self.drift=numpy.zeros((200),'float32') |
|
6364 | self.drift=numpy.zeros((200),'float32') | |
6360 | self.rdrift=numpy.zeros((200),'float32') |
|
6365 | self.rdrift=numpy.zeros((200),'float32') | |
6361 | self.ddrift=numpy.zeros((200),'float32') |
|
6366 | self.ddrift=numpy.zeros((200),'float32') | |
6362 | self.sigma=numpy.zeros((dataOut.NRANGE),order='F',dtype='float32') |
|
6367 | self.sigma=numpy.zeros((dataOut.NRANGE),order='F',dtype='float32') | |
6363 | self.powera=numpy.zeros((dataOut.NRANGE),order='F',dtype='float32') |
|
6368 | self.powera=numpy.zeros((dataOut.NRANGE),order='F',dtype='float32') | |
6364 | self.powerb=numpy.zeros((dataOut.NRANGE),order='F',dtype='float32') |
|
6369 | self.powerb=numpy.zeros((dataOut.NRANGE),order='F',dtype='float32') | |
6365 | self.perror=numpy.zeros((dataOut.NRANGE),order='F',dtype='float32') |
|
6370 | self.perror=numpy.zeros((dataOut.NRANGE),order='F',dtype='float32') | |
6366 | dataOut.ene=numpy.zeros((dataOut.NRANGE),'float32') |
|
6371 | dataOut.ene=numpy.zeros((dataOut.NRANGE),'float32') | |
6367 | self.dpulse=numpy.zeros((dataOut.NACF),'float32') |
|
6372 | self.dpulse=numpy.zeros((dataOut.NACF),'float32') | |
6368 | self.lpulse=numpy.zeros((dataOut.NACF),'float32') |
|
6373 | self.lpulse=numpy.zeros((dataOut.NACF),'float32') | |
6369 | dataOut.lags_LP=numpy.zeros((dataOut.IBITS),order='F',dtype='float32') |
|
6374 | dataOut.lags_LP=numpy.zeros((dataOut.IBITS),order='F',dtype='float32') | |
6370 | self.lagp=numpy.zeros((dataOut.NACF),'float32') |
|
6375 | self.lagp=numpy.zeros((dataOut.NACF),'float32') | |
6371 | self.u=numpy.zeros((2*dataOut.NACF,2*dataOut.NACF),'float32') |
|
6376 | self.u=numpy.zeros((2*dataOut.NACF,2*dataOut.NACF),'float32') | |
6372 | dataOut.ne=numpy.zeros((dataOut.NRANGE),order='F',dtype='float32') |
|
6377 | dataOut.ne=numpy.zeros((dataOut.NRANGE),order='F',dtype='float32') | |
6373 | dataOut.te=numpy.zeros((dataOut.NACF),order='F',dtype='float32') |
|
6378 | dataOut.te=numpy.zeros((dataOut.NACF),order='F',dtype='float32') | |
6374 | dataOut.ete=numpy.zeros((dataOut.NACF),order='F',dtype='float32') |
|
6379 | dataOut.ete=numpy.zeros((dataOut.NACF),order='F',dtype='float32') | |
6375 | dataOut.ti=numpy.zeros((dataOut.NACF),order='F',dtype='float32') |
|
6380 | dataOut.ti=numpy.zeros((dataOut.NACF),order='F',dtype='float32') | |
6376 | dataOut.eti=numpy.zeros((dataOut.NACF),order='F',dtype='float32') |
|
6381 | dataOut.eti=numpy.zeros((dataOut.NACF),order='F',dtype='float32') | |
6377 | dataOut.ph=numpy.zeros((dataOut.NACF),order='F',dtype='float32') |
|
6382 | dataOut.ph=numpy.zeros((dataOut.NACF),order='F',dtype='float32') | |
6378 | dataOut.eph=numpy.zeros((dataOut.NACF),order='F',dtype='float32') |
|
6383 | dataOut.eph=numpy.zeros((dataOut.NACF),order='F',dtype='float32') | |
6379 | dataOut.phe=numpy.zeros((dataOut.NACF),order='F',dtype='float32') |
|
6384 | dataOut.phe=numpy.zeros((dataOut.NACF),order='F',dtype='float32') | |
6380 | dataOut.ephe=numpy.zeros((dataOut.NACF),order='F',dtype='float32') |
|
6385 | dataOut.ephe=numpy.zeros((dataOut.NACF),order='F',dtype='float32') | |
6381 | dataOut.errors=numpy.zeros((dataOut.IBITS,max(dataOut.NRANGE,dataOut.NSHTS)),order='F',dtype='float32') |
|
6386 | dataOut.errors=numpy.zeros((dataOut.IBITS,max(dataOut.NRANGE,dataOut.NSHTS)),order='F',dtype='float32') | |
6382 | dataOut.fit_array_real=numpy.zeros((max(dataOut.NRANGE,dataOut.NSHTS),dataOut.NLAG),order='F',dtype='float32') |
|
6387 | dataOut.fit_array_real=numpy.zeros((max(dataOut.NRANGE,dataOut.NSHTS),dataOut.NLAG),order='F',dtype='float32') | |
6383 | dataOut.status=numpy.zeros(1,'float32') |
|
6388 | dataOut.status=numpy.zeros(1,'float32') | |
6384 | dataOut.tx=240.0 #deberΓa provenir del header #hybrid |
|
6389 | dataOut.tx=240.0 #deberΓa provenir del header #hybrid | |
6385 |
|
6390 | |||
6386 | for i in range(dataOut.IBITS): |
|
6391 | for i in range(dataOut.IBITS): | |
6387 | dataOut.lags_LP[i]=float(i)*(dataOut.tx/150.0)/float(dataOut.IBITS) # (float)i*(header.tx/150.0)/(float)IBITS; |
|
6392 | dataOut.lags_LP[i]=float(i)*(dataOut.tx/150.0)/float(dataOut.IBITS) # (float)i*(header.tx/150.0)/(float)IBITS; | |
6388 |
|
6393 | |||
6389 | self.aux=0 |
|
6394 | self.aux=0 | |
6390 |
|
6395 | |||
6391 | dataOut.cut=30 |
|
6396 | dataOut.cut=30 | |
6392 | for i in range(30,15,-1): |
|
6397 | for i in range(30,15,-1): | |
6393 | if numpy.nanmax(dataOut.acfs_error_to_plot[i,:])>=10 or dataOut.info2[i]==0: |
|
6398 | if numpy.nanmax(dataOut.acfs_error_to_plot[i,:])>=10 or dataOut.info2[i]==0: | |
6394 | dataOut.cut=i-1 |
|
6399 | dataOut.cut=i-1 | |
6395 |
|
6400 | |||
6396 | for i in range(dataOut.NLAG): |
|
6401 | for i in range(dataOut.NLAG): | |
6397 | self.cal[i]=sum(dataOut.output_LP_integrated[i,:,3].real) |
|
6402 | self.cal[i]=sum(dataOut.output_LP_integrated[i,:,3].real) | |
6398 |
|
6403 | |||
6399 | #print(numpy.sum(self.cal)) #Coinciden |
|
6404 | #print(numpy.sum(self.cal)) #Coinciden | |
6400 | #exit(1) |
|
6405 | #exit(1) | |
6401 | self.cal/=float(dataOut.NRANGE) |
|
6406 | self.cal/=float(dataOut.NRANGE) | |
6402 | #print(anoise0) |
|
6407 | #print(anoise0) | |
6403 | #print(anoise1) |
|
6408 | #print(anoise1) | |
6404 | #exit(1) |
|
6409 | #exit(1) | |
6405 |
|
6410 | |||
6406 | for j in range(dataOut.NACF+2*dataOut.IBITS+2): |
|
6411 | for j in range(dataOut.NACF+2*dataOut.IBITS+2): | |
6407 |
|
6412 | |||
6408 | dataOut.output_LP_integrated.real[0,j,0]-=anoise0 #lag0 ch0 |
|
6413 | dataOut.output_LP_integrated.real[0,j,0]-=anoise0 #lag0 ch0 | |
6409 | dataOut.output_LP_integrated.real[1,j,0]-=anoise1 #lag1 ch0 |
|
6414 | dataOut.output_LP_integrated.real[1,j,0]-=anoise1 #lag1 ch0 | |
6410 |
|
6415 | |||
6411 | for i in range(1,dataOut.NLAG): #remove cal data from certain lags |
|
6416 | for i in range(1,dataOut.NLAG): #remove cal data from certain lags | |
6412 | dataOut.output_LP_integrated.real[i,j,0]-=self.cal[i] |
|
6417 | dataOut.output_LP_integrated.real[i,j,0]-=self.cal[i] | |
6413 | k=max(j,26) #constant power below range 26 |
|
6418 | k=max(j,26) #constant power below range 26 | |
6414 | self.powera[j]=dataOut.output_LP_integrated.real[0,k,0] |
|
6419 | self.powera[j]=dataOut.output_LP_integrated.real[0,k,0] | |
6415 |
|
6420 | |||
6416 | ## examine drifts here - based on 60 'indep.' estimates |
|
6421 | ## examine drifts here - based on 60 'indep.' estimates | |
6417 | #print(numpy.sum(self.powera)) |
|
6422 | #print(numpy.sum(self.powera)) | |
6418 | #exit(1) |
|
6423 | #exit(1) | |
6419 | #nis=dataOut.NSCAN*dataOut.NAVG*dataOut.nint*10 |
|
6424 | #nis=dataOut.NSCAN*dataOut.NAVG*dataOut.nint*10 | |
6420 | nis = dataOut.nis |
|
6425 | nis = dataOut.nis | |
6421 | #print("nis",nis) |
|
6426 | #print("nis",nis) | |
6422 | alpha=beta=delta=0.0 |
|
6427 | alpha=beta=delta=0.0 | |
6423 | nest=0 |
|
6428 | nest=0 | |
6424 | gamma=3.0/(2.0*numpy.pi*dataOut.lags_LP[1]*1.0e-3) |
|
6429 | gamma=3.0/(2.0*numpy.pi*dataOut.lags_LP[1]*1.0e-3) | |
6425 | beta=gamma*(math.atan2(dataOut.output_LP_integrated.imag[14,0,2],dataOut.output_LP_integrated.real[14,0,2])-math.atan2(dataOut.output_LP_integrated.imag[1,0,2],dataOut.output_LP_integrated.real[1,0,2]))/13.0 |
|
6430 | beta=gamma*(math.atan2(dataOut.output_LP_integrated.imag[14,0,2],dataOut.output_LP_integrated.real[14,0,2])-math.atan2(dataOut.output_LP_integrated.imag[1,0,2],dataOut.output_LP_integrated.real[1,0,2]))/13.0 | |
6426 | #print(gamma,beta) |
|
6431 | #print(gamma,beta) | |
6427 | #exit(1) |
|
6432 | #exit(1) | |
6428 | for i in range(1,3): |
|
6433 | for i in range(1,3): | |
6429 | gamma=3.0/(2.0*numpy.pi*dataOut.lags_LP[i]*1.0e-3) |
|
6434 | gamma=3.0/(2.0*numpy.pi*dataOut.lags_LP[i]*1.0e-3) | |
6430 | #print("gamma",gamma) |
|
6435 | #print("gamma",gamma) | |
6431 | for j in range(34,44): |
|
6436 | for j in range(34,44): | |
6432 | rho2=numpy.abs(dataOut.output_LP_integrated[i,j,0])/numpy.abs(dataOut.output_LP_integrated[0,j,0]) |
|
6437 | rho2=numpy.abs(dataOut.output_LP_integrated[i,j,0])/numpy.abs(dataOut.output_LP_integrated[0,j,0]) | |
6433 | dataOut.dphi2=(1.0/rho2-1.0)/(float(2*nis)) |
|
6438 | dataOut.dphi2=(1.0/rho2-1.0)/(float(2*nis)) | |
6434 | dataOut.dphi2*=gamma**2 |
|
6439 | dataOut.dphi2*=gamma**2 | |
6435 | pest=gamma*math.atan(dataOut.output_LP_integrated.imag[i,j,0]/dataOut.output_LP_integrated.real[i,j,0]) |
|
6440 | pest=gamma*math.atan(dataOut.output_LP_integrated.imag[i,j,0]/dataOut.output_LP_integrated.real[i,j,0]) | |
6436 | #print("1",dataOut.output_LP_integrated.imag[i,j,0]) |
|
6441 | #print("1",dataOut.output_LP_integrated.imag[i,j,0]) | |
6437 | #print("2",dataOut.output_LP_integrated.real[i,j,0]) |
|
6442 | #print("2",dataOut.output_LP_integrated.real[i,j,0]) | |
6438 | self.drift[nest]=pest |
|
6443 | self.drift[nest]=pest | |
6439 | self.ddrift[nest]=dataOut.dphi2 |
|
6444 | self.ddrift[nest]=dataOut.dphi2 | |
6440 | self.rdrift[nest]=float(nest) |
|
6445 | self.rdrift[nest]=float(nest) | |
6441 | nest+=1 |
|
6446 | nest+=1 | |
6442 |
|
6447 | |||
6443 | sorted(self.drift[:nest]) |
|
6448 | sorted(self.drift[:nest]) | |
6444 |
|
6449 | |||
6445 | #print(dataOut.dphi2) |
|
6450 | #print(dataOut.dphi2) | |
6446 | #exit(1) |
|
6451 | #exit(1) | |
6447 |
|
6452 | |||
6448 | for j in range(int(nest/4),int(3*nest/4)): |
|
6453 | for j in range(int(nest/4),int(3*nest/4)): | |
6449 | #i=int(self.rdrift[j]) |
|
6454 | #i=int(self.rdrift[j]) | |
6450 | alpha+=self.drift[j]/self.ddrift[j] |
|
6455 | alpha+=self.drift[j]/self.ddrift[j] | |
6451 | delta+=1.0/self.ddrift[j] |
|
6456 | delta+=1.0/self.ddrift[j] | |
6452 |
|
6457 | |||
6453 | alpha/=delta |
|
6458 | alpha/=delta | |
6454 | delta=1./numpy.sqrt(delta) |
|
6459 | delta=1./numpy.sqrt(delta) | |
6455 | vdrift=alpha-beta |
|
6460 | vdrift=alpha-beta | |
6456 | dvdrift=delta |
|
6461 | dvdrift=delta | |
6457 |
|
6462 | |||
6458 | #need to develop estimate of complete density profile using all |
|
6463 | #need to develop estimate of complete density profile using all | |
6459 | #available data |
|
6464 | #available data | |
6460 |
|
6465 | |||
6461 | #estimate sample variances for long-pulse power profile |
|
6466 | #estimate sample variances for long-pulse power profile | |
6462 |
|
6467 | |||
6463 | #nis=dataOut.NSCAN*dataOut.NAVG*dataOut.nint |
|
6468 | #nis=dataOut.NSCAN*dataOut.NAVG*dataOut.nint | |
6464 | nis = dataOut.nis/10 |
|
6469 | nis = dataOut.nis/10 | |
6465 | #print("nis",nis) |
|
6470 | #print("nis",nis) | |
6466 |
|
6471 | |||
6467 | self.sigma[:dataOut.NACF+2*dataOut.IBITS+2]=((anoise0+self.powera[:dataOut.NACF+2*dataOut.IBITS+2])**2)/float(nis) |
|
6472 | self.sigma[:dataOut.NACF+2*dataOut.IBITS+2]=((anoise0+self.powera[:dataOut.NACF+2*dataOut.IBITS+2])**2)/float(nis) | |
6468 | #print(self.sigma) |
|
6473 | #print(self.sigma) | |
6469 | #exit(1) |
|
6474 | #exit(1) | |
6470 | ioff=1 |
|
6475 | ioff=1 | |
6471 |
|
6476 | |||
6472 | #deconvolve rectangular pulse shape from profile ==> powerb, perror |
|
6477 | #deconvolve rectangular pulse shape from profile ==> powerb, perror | |
6473 |
|
6478 | |||
6474 |
|
6479 | |||
6475 | ############# START nnlswrap############# |
|
6480 | ############# START nnlswrap############# | |
6476 |
|
6481 | |||
6477 | if dataOut.ut_Faraday>14.0: |
|
6482 | if dataOut.ut_Faraday>14.0: | |
6478 | alpha_nnlswrap=20.0 |
|
6483 | alpha_nnlswrap=20.0 | |
6479 | else: |
|
6484 | else: | |
6480 | alpha_nnlswrap=30.0 |
|
6485 | alpha_nnlswrap=30.0 | |
6481 |
|
6486 | |||
6482 | range1_nnls=dataOut.NACF |
|
6487 | range1_nnls=dataOut.NACF | |
6483 | range2_nnls=dataOut.NACF+dataOut.IBITS-1 |
|
6488 | range2_nnls=dataOut.NACF+dataOut.IBITS-1 | |
6484 |
|
6489 | |||
6485 | g_nnlswrap=numpy.zeros((range1_nnls,range2_nnls),'float32') |
|
6490 | g_nnlswrap=numpy.zeros((range1_nnls,range2_nnls),'float32') | |
6486 | a_nnlswrap=numpy.zeros((range2_nnls,range2_nnls),'float64') |
|
6491 | a_nnlswrap=numpy.zeros((range2_nnls,range2_nnls),'float64') | |
6487 |
|
6492 | |||
6488 | for i in range(range1_nnls): |
|
6493 | for i in range(range1_nnls): | |
6489 | for j in range(range2_nnls): |
|
6494 | for j in range(range2_nnls): | |
6490 | if j>=i and j<i+dataOut.IBITS: |
|
6495 | if j>=i and j<i+dataOut.IBITS: | |
6491 | g_nnlswrap[i,j]=1.0 |
|
6496 | g_nnlswrap[i,j]=1.0 | |
6492 | else: |
|
6497 | else: | |
6493 | g_nnlswrap[i,j]=0.0 |
|
6498 | g_nnlswrap[i,j]=0.0 | |
6494 |
|
6499 | |||
6495 | a_nnlswrap[:]=numpy.matmul(numpy.transpose(g_nnlswrap),g_nnlswrap) |
|
6500 | a_nnlswrap[:]=numpy.matmul(numpy.transpose(g_nnlswrap),g_nnlswrap) | |
6496 |
|
6501 | |||
6497 | numpy.fill_diagonal(a_nnlswrap,a_nnlswrap.diagonal()+alpha_nnlswrap**2) |
|
6502 | numpy.fill_diagonal(a_nnlswrap,a_nnlswrap.diagonal()+alpha_nnlswrap**2) | |
6498 |
|
6503 | |||
6499 | #ERROR ANALYSIS# |
|
6504 | #ERROR ANALYSIS# | |
6500 |
|
6505 | |||
6501 | self.perror[:range2_nnls]=0.0 |
|
6506 | self.perror[:range2_nnls]=0.0 | |
6502 | self.perror[:range2_nnls]=numpy.matmul(1./(self.sigma[dataOut.IBITS+ioff:range1_nnls+dataOut.IBITS+ioff]),g_nnlswrap**2) |
|
6507 | self.perror[:range2_nnls]=numpy.matmul(1./(self.sigma[dataOut.IBITS+ioff:range1_nnls+dataOut.IBITS+ioff]),g_nnlswrap**2) | |
6503 | self.perror[:range1_nnls]+=(alpha_nnlswrap**2)/(self.sigma[dataOut.IBITS+ioff:range1_nnls+dataOut.IBITS+ioff]) |
|
6508 | self.perror[:range1_nnls]+=(alpha_nnlswrap**2)/(self.sigma[dataOut.IBITS+ioff:range1_nnls+dataOut.IBITS+ioff]) | |
6504 | self.perror[:range2_nnls]=1.00/self.perror[:range2_nnls] |
|
6509 | self.perror[:range2_nnls]=1.00/self.perror[:range2_nnls] | |
6505 |
|
6510 | |||
6506 | b_nnlswrap=numpy.zeros(range2_nnls,'float64') |
|
6511 | b_nnlswrap=numpy.zeros(range2_nnls,'float64') | |
6507 | b_nnlswrap[:]=numpy.matmul(self.powera[dataOut.IBITS+ioff:range1_nnls+dataOut.IBITS+ioff],g_nnlswrap) |
|
6512 | b_nnlswrap[:]=numpy.matmul(self.powera[dataOut.IBITS+ioff:range1_nnls+dataOut.IBITS+ioff],g_nnlswrap) | |
6508 |
|
6513 | |||
6509 | x_nnlswrap=numpy.zeros(range2_nnls,'float64') |
|
6514 | x_nnlswrap=numpy.zeros(range2_nnls,'float64') | |
6510 | x_nnlswrap[:]=nnls(a_nnlswrap,b_nnlswrap)[0] |
|
6515 | x_nnlswrap[:]=nnls(a_nnlswrap,b_nnlswrap)[0] | |
6511 |
|
6516 | |||
6512 | self.powerb[:range2_nnls]=x_nnlswrap |
|
6517 | self.powerb[:range2_nnls]=x_nnlswrap | |
6513 | #print(self.powerb[40]) |
|
6518 | #print(self.powerb[40]) | |
6514 | #print(self.powerb[66]) |
|
6519 | #print(self.powerb[66]) | |
6515 | #exit(1) |
|
6520 | #exit(1) | |
6516 | #############END nnlswrap############# |
|
6521 | #############END nnlswrap############# | |
6517 | #print(numpy.sum(numpy.sqrt(self.perror[0:dataOut.NACF]))) |
|
6522 | #print(numpy.sum(numpy.sqrt(self.perror[0:dataOut.NACF]))) | |
6518 | #print(self.powerb[0:dataOut.NACF]) |
|
6523 | #print(self.powerb[0:dataOut.NACF]) | |
6519 | #exit(1) |
|
6524 | #exit(1) | |
6520 | #estimate relative error for deconvolved profile (scaling irrelevant) |
|
6525 | #estimate relative error for deconvolved profile (scaling irrelevant) | |
6521 | #print(dataOut.NACF) |
|
6526 | #print(dataOut.NACF) | |
6522 | dataOut.ene[0:dataOut.NACF]=numpy.sqrt(self.perror[0:dataOut.NACF])/self.powerb[0:dataOut.NACF] |
|
6527 | dataOut.ene[0:dataOut.NACF]=numpy.sqrt(self.perror[0:dataOut.NACF])/self.powerb[0:dataOut.NACF] | |
6523 | #print(numpy.sum(dataOut.ene)) |
|
6528 | #print(numpy.sum(dataOut.ene)) | |
6524 | #exit(1) |
|
6529 | #exit(1) | |
6525 | aux=0 |
|
6530 | aux=0 | |
6526 |
|
6531 | |||
6527 | for i in range(dataOut.IBITS,dataOut.NACF): |
|
6532 | for i in range(dataOut.IBITS,dataOut.NACF): | |
6528 | self.dpulse[i]=self.lpulse[i]=0.0 |
|
6533 | self.dpulse[i]=self.lpulse[i]=0.0 | |
6529 | for j in range(dataOut.IBITS): |
|
6534 | for j in range(dataOut.IBITS): | |
6530 | k=int(i-j) |
|
6535 | k=int(i-j) | |
6531 | if k<36-aux and k>16: |
|
6536 | if k<36-aux and k>16: | |
6532 | self.dpulse[i]+=dataOut.ph2[k]/dataOut.h2[k] |
|
6537 | self.dpulse[i]+=dataOut.ph2[k]/dataOut.h2[k] | |
6533 | elif k>=36-aux: |
|
6538 | elif k>=36-aux: | |
6534 | self.lpulse[i]+=self.powerb[k] |
|
6539 | self.lpulse[i]+=self.powerb[k] | |
6535 | self.lagp[i]=self.powera[i] |
|
6540 | self.lagp[i]=self.powera[i] | |
6536 |
|
6541 | |||
6537 | #find scale factor that best merges profiles |
|
6542 | #find scale factor that best merges profiles | |
6538 |
|
6543 | |||
6539 | qi=sum(self.dpulse[32:dataOut.NACF]**2/(self.lagp[32:dataOut.NACF]+anoise0)**2) |
|
6544 | qi=sum(self.dpulse[32:dataOut.NACF]**2/(self.lagp[32:dataOut.NACF]+anoise0)**2) | |
6540 | ri=sum((self.dpulse[32:dataOut.NACF]*self.lpulse[32:dataOut.NACF])/(self.lagp[32:dataOut.NACF]+anoise0)**2) |
|
6545 | ri=sum((self.dpulse[32:dataOut.NACF]*self.lpulse[32:dataOut.NACF])/(self.lagp[32:dataOut.NACF]+anoise0)**2) | |
6541 | si=sum((self.dpulse[32:dataOut.NACF]*self.lagp[32:dataOut.NACF])/(self.lagp[32:dataOut.NACF]+anoise0)**2) |
|
6546 | si=sum((self.dpulse[32:dataOut.NACF]*self.lagp[32:dataOut.NACF])/(self.lagp[32:dataOut.NACF]+anoise0)**2) | |
6542 | ui=sum(self.lpulse[32:dataOut.NACF]**2/(self.lagp[32:dataOut.NACF]+anoise0)**2) |
|
6547 | ui=sum(self.lpulse[32:dataOut.NACF]**2/(self.lagp[32:dataOut.NACF]+anoise0)**2) | |
6543 | vi=sum((self.lpulse[32:dataOut.NACF]*self.lagp[32:dataOut.NACF])/(self.lagp[32:dataOut.NACF]+anoise0)**2) |
|
6548 | vi=sum((self.lpulse[32:dataOut.NACF]*self.lagp[32:dataOut.NACF])/(self.lagp[32:dataOut.NACF]+anoise0)**2) | |
6544 |
|
6549 | |||
6545 | alpha=(si*ui-vi*ri)/(qi*ui-ri*ri) |
|
6550 | alpha=(si*ui-vi*ri)/(qi*ui-ri*ri) | |
6546 | beta=(qi*vi-ri*si)/(qi*ui-ri*ri) |
|
6551 | beta=(qi*vi-ri*si)/(qi*ui-ri*ri) | |
6547 |
|
6552 | |||
6548 | #form density profile estimate, merging rescaled power profiles |
|
6553 | #form density profile estimate, merging rescaled power profiles | |
6549 | #print(dataOut.h2) |
|
6554 | #print(dataOut.h2) | |
6550 | #print(numpy.sum(alpha)) |
|
6555 | #print(numpy.sum(alpha)) | |
6551 | #print(numpy.sum(dataOut.ph2)) |
|
6556 | #print(numpy.sum(dataOut.ph2)) | |
6552 | self.powerb[16:36-aux]=alpha*dataOut.ph2[16:36-aux]/dataOut.h2[16:36-aux] |
|
6557 | self.powerb[16:36-aux]=alpha*dataOut.ph2[16:36-aux]/dataOut.h2[16:36-aux] | |
6553 | self.powerb[36-aux:dataOut.NACF]*=beta |
|
6558 | self.powerb[36-aux:dataOut.NACF]*=beta | |
6554 |
|
6559 | |||
6555 | #form Ne estimate, fill in error estimate at low altitudes |
|
6560 | #form Ne estimate, fill in error estimate at low altitudes | |
6556 |
|
6561 | |||
6557 | dataOut.ene[0:36-aux]=dataOut.sdp2[0:36-aux]/dataOut.ph2[0:36-aux] |
|
6562 | dataOut.ene[0:36-aux]=dataOut.sdp2[0:36-aux]/dataOut.ph2[0:36-aux] | |
6558 | dataOut.ne[:dataOut.NACF]=self.powerb[:dataOut.NACF]*dataOut.h2[:dataOut.NACF]/alpha |
|
6563 | dataOut.ne[:dataOut.NACF]=self.powerb[:dataOut.NACF]*dataOut.h2[:dataOut.NACF]/alpha | |
6559 | #print(numpy.sum(self.powerb)) |
|
6564 | #print(numpy.sum(self.powerb)) | |
6560 | #print(numpy.sum(dataOut.ene)) |
|
6565 | #print(numpy.sum(dataOut.ene)) | |
6561 | #print(numpy.sum(dataOut.ne)) |
|
6566 | #print(numpy.sum(dataOut.ne)) | |
6562 | #exit(1) |
|
6567 | #exit(1) | |
6563 | #now do error propagation: store zero lag error covariance in u |
|
6568 | #now do error propagation: store zero lag error covariance in u | |
6564 |
|
6569 | |||
6565 | nis=dataOut.NSCAN*dataOut.NAVG*dataOut.nint/1 # DLH serious debris removal |
|
6570 | nis=dataOut.NSCAN*dataOut.NAVG*dataOut.nint/1 # DLH serious debris removal | |
6566 |
|
6571 | |||
6567 | for i in range(dataOut.NACF): |
|
6572 | for i in range(dataOut.NACF): | |
6568 | for j in range(i,dataOut.NACF): |
|
6573 | for j in range(i,dataOut.NACF): | |
6569 | if j-i>=dataOut.IBITS: |
|
6574 | if j-i>=dataOut.IBITS: | |
6570 | self.u[i,j]=0.0 |
|
6575 | self.u[i,j]=0.0 | |
6571 | else: |
|
6576 | else: | |
6572 | self.u[i,j]=dataOut.output_LP_integrated.real[j-i,i,0]**2/float(nis) |
|
6577 | self.u[i,j]=dataOut.output_LP_integrated.real[j-i,i,0]**2/float(nis) | |
6573 | self.u[i,j]*=(anoise0+dataOut.output_LP_integrated.real[0,i,0])/dataOut.output_LP_integrated.real[0,i,0] |
|
6578 | self.u[i,j]*=(anoise0+dataOut.output_LP_integrated.real[0,i,0])/dataOut.output_LP_integrated.real[0,i,0] | |
6574 | self.u[i,j]*=(anoise0+dataOut.output_LP_integrated.real[0,j,0])/dataOut.output_LP_integrated.real[0,j,0] |
|
6579 | self.u[i,j]*=(anoise0+dataOut.output_LP_integrated.real[0,j,0])/dataOut.output_LP_integrated.real[0,j,0] | |
6575 |
|
6580 | |||
6576 | self.u[j,i]=self.u[i,j] |
|
6581 | self.u[j,i]=self.u[i,j] | |
6577 |
|
6582 | |||
6578 | #now error analyis for lag product matrix (diag), place in acf_err |
|
6583 | #now error analyis for lag product matrix (diag), place in acf_err | |
6579 |
|
6584 | |||
6580 | for i in range(dataOut.NACF): |
|
6585 | for i in range(dataOut.NACF): | |
6581 | for j in range(dataOut.IBITS): |
|
6586 | for j in range(dataOut.IBITS): | |
6582 | if j==0: |
|
6587 | if j==0: | |
6583 | dataOut.errors[0,i]=numpy.sqrt(self.u[i,i]) |
|
6588 | dataOut.errors[0,i]=numpy.sqrt(self.u[i,i]) | |
6584 | else: |
|
6589 | else: | |
6585 | dataOut.errors[j,i]=numpy.sqrt(((dataOut.output_LP_integrated.real[0,i,0]+anoise0)*(dataOut.output_LP_integrated.real[0,i+j,0]+anoise0)+dataOut.output_LP_integrated.real[j,i,0]**2)/float(2*nis)) |
|
6590 | dataOut.errors[j,i]=numpy.sqrt(((dataOut.output_LP_integrated.real[0,i,0]+anoise0)*(dataOut.output_LP_integrated.real[0,i+j,0]+anoise0)+dataOut.output_LP_integrated.real[j,i,0]**2)/float(2*nis)) | |
6586 |
|
6591 | |||
6587 | print("Success") |
|
6592 | print("Success") | |
6588 | with suppress_stdout_stderr(): |
|
6593 | with suppress_stdout_stderr(): | |
6589 | #pass |
|
6594 | #pass | |
6590 | full_profile_profile.profile(numpy.transpose(dataOut.output_LP_integrated,(2,1,0)),numpy.transpose(dataOut.errors),self.powerb,dataOut.ne,dataOut.lags_LP,dataOut.thb,dataOut.bfm,dataOut.te,dataOut.ete,dataOut.ti,dataOut.eti,dataOut.ph,dataOut.eph,dataOut.phe,dataOut.ephe,dataOut.range1,dataOut.ut,dataOut.NACF,dataOut.fit_array_real,dataOut.status,dataOut.NRANGE,dataOut.IBITS) |
|
6595 | full_profile_profile.profile(numpy.transpose(dataOut.output_LP_integrated,(2,1,0)),numpy.transpose(dataOut.errors),self.powerb,dataOut.ne,dataOut.lags_LP,dataOut.thb,dataOut.bfm,dataOut.te,dataOut.ete,dataOut.ti,dataOut.eti,dataOut.ph,dataOut.eph,dataOut.phe,dataOut.ephe,dataOut.range1,dataOut.ut,dataOut.NACF,dataOut.fit_array_real,dataOut.status,dataOut.NRANGE,dataOut.IBITS) | |
6591 |
|
6596 | |||
6592 | if dataOut.status>=3.5: |
|
6597 | if dataOut.status>=3.5: | |
6593 | dataOut.te[:]=numpy.nan |
|
6598 | dataOut.te[:]=numpy.nan | |
6594 | dataOut.ete[:]=numpy.nan |
|
6599 | dataOut.ete[:]=numpy.nan | |
6595 | dataOut.ti[:]=numpy.nan |
|
6600 | dataOut.ti[:]=numpy.nan | |
6596 | dataOut.eti[:]=numpy.nan |
|
6601 | dataOut.eti[:]=numpy.nan | |
6597 | dataOut.ph[:]=numpy.nan |
|
6602 | dataOut.ph[:]=numpy.nan | |
6598 | dataOut.eph[:]=numpy.nan |
|
6603 | dataOut.eph[:]=numpy.nan | |
6599 | dataOut.phe[:]=numpy.nan |
|
6604 | dataOut.phe[:]=numpy.nan | |
6600 | dataOut.ephe[:]=numpy.nan |
|
6605 | dataOut.ephe[:]=numpy.nan | |
6601 |
|
6606 | |||
6602 | return dataOut |
|
6607 | return dataOut | |
6603 |
|
6608 | |||
6604 | class PulsePairVoltage(Operation): |
|
6609 | class PulsePairVoltage(Operation): | |
6605 | ''' |
|
6610 | ''' | |
6606 | Function PulsePair(Signal Power, Velocity) |
|
6611 | Function PulsePair(Signal Power, Velocity) | |
6607 | The real component of Lag[0] provides Intensity Information |
|
6612 | The real component of Lag[0] provides Intensity Information | |
6608 | The imag component of Lag[1] Phase provides Velocity Information |
|
6613 | The imag component of Lag[1] Phase provides Velocity Information | |
6609 |
|
6614 | |||
6610 | Configuration Parameters: |
|
6615 | Configuration Parameters: | |
6611 | nPRF = Number of Several PRF |
|
6616 | nPRF = Number of Several PRF | |
6612 | theta = Degree Azimuth angel Boundaries |
|
6617 | theta = Degree Azimuth angel Boundaries | |
6613 |
|
6618 | |||
6614 | Input: |
|
6619 | Input: | |
6615 | self.dataOut |
|
6620 | self.dataOut | |
6616 | lag[N] |
|
6621 | lag[N] | |
6617 | Affected: |
|
6622 | Affected: | |
6618 | self.dataOut.spc |
|
6623 | self.dataOut.spc | |
6619 | ''' |
|
6624 | ''' | |
6620 | isConfig = False |
|
6625 | isConfig = False | |
6621 | __profIndex = 0 |
|
6626 | __profIndex = 0 | |
6622 | __initime = None |
|
6627 | __initime = None | |
6623 | __lastdatatime = None |
|
6628 | __lastdatatime = None | |
6624 | __buffer = None |
|
6629 | __buffer = None | |
6625 | noise = None |
|
6630 | noise = None | |
6626 | __dataReady = False |
|
6631 | __dataReady = False | |
6627 | n = None |
|
6632 | n = None | |
6628 | __nch = 0 |
|
6633 | __nch = 0 | |
6629 | __nHeis = 0 |
|
6634 | __nHeis = 0 | |
6630 | removeDC = False |
|
6635 | removeDC = False | |
6631 | ipp = None |
|
6636 | ipp = None | |
6632 | lambda_ = 0 |
|
6637 | lambda_ = 0 | |
6633 |
|
6638 | |||
6634 | def __init__(self, **kwargs): |
|
6639 | def __init__(self, **kwargs): | |
6635 | Operation.__init__(self, **kwargs) |
|
6640 | Operation.__init__(self, **kwargs) | |
6636 |
|
6641 | |||
6637 | def setup(self, dataOut, n=None, removeDC=False): |
|
6642 | def setup(self, dataOut, n=None, removeDC=False): | |
6638 | ''' |
|
6643 | ''' | |
6639 | n= Numero de PRF's de entrada |
|
6644 | n= Numero de PRF's de entrada | |
6640 | ''' |
|
6645 | ''' | |
6641 | self.__initime = None |
|
6646 | self.__initime = None | |
6642 | self.__lastdatatime = 0 |
|
6647 | self.__lastdatatime = 0 | |
6643 | self.__dataReady = False |
|
6648 | self.__dataReady = False | |
6644 | self.__buffer = 0 |
|
6649 | self.__buffer = 0 | |
6645 | self.__profIndex = 0 |
|
6650 | self.__profIndex = 0 | |
6646 | self.noise = None |
|
6651 | self.noise = None | |
6647 | self.__nch = dataOut.nChannels |
|
6652 | self.__nch = dataOut.nChannels | |
6648 | self.__nHeis = dataOut.nHeights |
|
6653 | self.__nHeis = dataOut.nHeights | |
6649 | self.removeDC = removeDC |
|
6654 | self.removeDC = removeDC | |
6650 | self.lambda_ = 3.0e8 / (9345.0e6) |
|
6655 | self.lambda_ = 3.0e8 / (9345.0e6) | |
6651 | self.ippSec = dataOut.ippSeconds |
|
6656 | self.ippSec = dataOut.ippSeconds | |
6652 | self.nCohInt = dataOut.nCohInt |
|
6657 | self.nCohInt = dataOut.nCohInt | |
6653 | print("IPPseconds", dataOut.ippSeconds) |
|
6658 | print("IPPseconds", dataOut.ippSeconds) | |
6654 |
|
6659 | |||
6655 | print("ELVALOR DE n es:", n) |
|
6660 | print("ELVALOR DE n es:", n) | |
6656 | if n == None: |
|
6661 | if n == None: | |
6657 | raise ValueError("n should be specified.") |
|
6662 | raise ValueError("n should be specified.") | |
6658 |
|
6663 | |||
6659 | if n != None: |
|
6664 | if n != None: | |
6660 | if n < 2: |
|
6665 | if n < 2: | |
6661 | raise ValueError("n should be greater than 2") |
|
6666 | raise ValueError("n should be greater than 2") | |
6662 |
|
6667 | |||
6663 | self.n = n |
|
6668 | self.n = n | |
6664 | self.__nProf = n |
|
6669 | self.__nProf = n | |
6665 |
|
6670 | |||
6666 | self.__buffer = numpy.zeros((dataOut.nChannels, |
|
6671 | self.__buffer = numpy.zeros((dataOut.nChannels, | |
6667 | n, |
|
6672 | n, | |
6668 | dataOut.nHeights), |
|
6673 | dataOut.nHeights), | |
6669 | dtype='complex') |
|
6674 | dtype='complex') | |
6670 |
|
6675 | |||
6671 | def putData(self, data): |
|
6676 | def putData(self, data): | |
6672 | ''' |
|
6677 | ''' | |
6673 | Add a profile to he __buffer and increase in one the __profiel Index |
|
6678 | Add a profile to he __buffer and increase in one the __profiel Index | |
6674 | ''' |
|
6679 | ''' | |
6675 | self.__buffer[:, self.__profIndex, :] = data |
|
6680 | self.__buffer[:, self.__profIndex, :] = data | |
6676 | self.__profIndex += 1 |
|
6681 | self.__profIndex += 1 | |
6677 | return |
|
6682 | return | |
6678 |
|
6683 | |||
6679 | def pushData(self, dataOut): |
|
6684 | def pushData(self, dataOut): | |
6680 | ''' |
|
6685 | ''' | |
6681 | Return the PULSEPAIR and the profiles used in the operation |
|
6686 | Return the PULSEPAIR and the profiles used in the operation | |
6682 | Affected : self.__profileIndex |
|
6687 | Affected : self.__profileIndex | |
6683 | ''' |
|
6688 | ''' | |
6684 | #----------------- Remove DC----------------------------------- |
|
6689 | #----------------- Remove DC----------------------------------- | |
6685 | if self.removeDC == True: |
|
6690 | if self.removeDC == True: | |
6686 | mean = numpy.mean(self.__buffer, 1) |
|
6691 | mean = numpy.mean(self.__buffer, 1) | |
6687 | tmp = mean.reshape(self.__nch, 1, self.__nHeis) |
|
6692 | tmp = mean.reshape(self.__nch, 1, self.__nHeis) | |
6688 | dc = numpy.tile(tmp, [1, self.__nProf, 1]) |
|
6693 | dc = numpy.tile(tmp, [1, self.__nProf, 1]) | |
6689 | self.__buffer = self.__buffer - dc |
|
6694 | self.__buffer = self.__buffer - dc | |
6690 | #------------------Calculo de Potencia ------------------------ |
|
6695 | #------------------Calculo de Potencia ------------------------ | |
6691 | pair0 = self.__buffer * numpy.conj(self.__buffer) |
|
6696 | pair0 = self.__buffer * numpy.conj(self.__buffer) | |
6692 | pair0 = pair0.real |
|
6697 | pair0 = pair0.real | |
6693 | lag_0 = numpy.sum(pair0, 1) |
|
6698 | lag_0 = numpy.sum(pair0, 1) | |
6694 | #------------------Calculo de Ruido x canal-------------------- |
|
6699 | #------------------Calculo de Ruido x canal-------------------- | |
6695 | self.noise = numpy.zeros(self.__nch) |
|
6700 | self.noise = numpy.zeros(self.__nch) | |
6696 | for i in range(self.__nch): |
|
6701 | for i in range(self.__nch): | |
6697 | daux = numpy.sort(pair0[i, :, :], axis=None) |
|
6702 | daux = numpy.sort(pair0[i, :, :], axis=None) | |
6698 | self.noise[i] = hildebrand_sekhon(daux , self.nCohInt) |
|
6703 | self.noise[i] = hildebrand_sekhon(daux , self.nCohInt) | |
6699 |
|
6704 | |||
6700 | self.noise = self.noise.reshape(self.__nch, 1) |
|
6705 | self.noise = self.noise.reshape(self.__nch, 1) | |
6701 | self.noise = numpy.tile(self.noise, [1, self.__nHeis]) |
|
6706 | self.noise = numpy.tile(self.noise, [1, self.__nHeis]) | |
6702 | noise_buffer = self.noise.reshape(self.__nch, 1, self.__nHeis) |
|
6707 | noise_buffer = self.noise.reshape(self.__nch, 1, self.__nHeis) | |
6703 | noise_buffer = numpy.tile(noise_buffer, [1, self.__nProf, 1]) |
|
6708 | noise_buffer = numpy.tile(noise_buffer, [1, self.__nProf, 1]) | |
6704 | #------------------ Potencia recibida= P , Potencia senal = S , Ruido= N-- |
|
6709 | #------------------ Potencia recibida= P , Potencia senal = S , Ruido= N-- | |
6705 | #------------------ P= S+N ,P=lag_0/N --------------------------------- |
|
6710 | #------------------ P= S+N ,P=lag_0/N --------------------------------- | |
6706 | #-------------------- Power -------------------------------------------------- |
|
6711 | #-------------------- Power -------------------------------------------------- | |
6707 | data_power = lag_0 / (self.n * self.nCohInt) |
|
6712 | data_power = lag_0 / (self.n * self.nCohInt) | |
6708 | #------------------ Senal --------------------------------------------------- |
|
6713 | #------------------ Senal --------------------------------------------------- | |
6709 | data_intensity = pair0 - noise_buffer |
|
6714 | data_intensity = pair0 - noise_buffer | |
6710 | data_intensity = numpy.sum(data_intensity, axis=1) * (self.n * self.nCohInt) # *self.nCohInt) |
|
6715 | data_intensity = numpy.sum(data_intensity, axis=1) * (self.n * self.nCohInt) # *self.nCohInt) | |
6711 | # data_intensity = (lag_0-self.noise*self.n)*(self.n*self.nCohInt) |
|
6716 | # data_intensity = (lag_0-self.noise*self.n)*(self.n*self.nCohInt) | |
6712 | for i in range(self.__nch): |
|
6717 | for i in range(self.__nch): | |
6713 | for j in range(self.__nHeis): |
|
6718 | for j in range(self.__nHeis): | |
6714 | if data_intensity[i][j] < 0: |
|
6719 | if data_intensity[i][j] < 0: | |
6715 | data_intensity[i][j] = numpy.min(numpy.absolute(data_intensity[i][j])) |
|
6720 | data_intensity[i][j] = numpy.min(numpy.absolute(data_intensity[i][j])) | |
6716 |
|
6721 | |||
6717 | #----------------- Calculo de Frecuencia y Velocidad doppler-------- |
|
6722 | #----------------- Calculo de Frecuencia y Velocidad doppler-------- | |
6718 | pair1 = self.__buffer[:, :-1, :] * numpy.conjugate(self.__buffer[:, 1:, :]) |
|
6723 | pair1 = self.__buffer[:, :-1, :] * numpy.conjugate(self.__buffer[:, 1:, :]) | |
6719 | lag_1 = numpy.sum(pair1, 1) |
|
6724 | lag_1 = numpy.sum(pair1, 1) | |
6720 | data_freq = (-1 / (2.0 * math.pi * self.ippSec * self.nCohInt)) * numpy.angle(lag_1) |
|
6725 | data_freq = (-1 / (2.0 * math.pi * self.ippSec * self.nCohInt)) * numpy.angle(lag_1) | |
6721 | data_velocity = (self.lambda_ / 2.0) * data_freq |
|
6726 | data_velocity = (self.lambda_ / 2.0) * data_freq | |
6722 |
|
6727 | |||
6723 | #---------------- Potencia promedio estimada de la Senal----------- |
|
6728 | #---------------- Potencia promedio estimada de la Senal----------- | |
6724 | lag_0 = lag_0 / self.n |
|
6729 | lag_0 = lag_0 / self.n | |
6725 | S = lag_0 - self.noise |
|
6730 | S = lag_0 - self.noise | |
6726 |
|
6731 | |||
6727 | #---------------- Frecuencia Doppler promedio --------------------- |
|
6732 | #---------------- Frecuencia Doppler promedio --------------------- | |
6728 | lag_1 = lag_1 / (self.n - 1) |
|
6733 | lag_1 = lag_1 / (self.n - 1) | |
6729 | R1 = numpy.abs(lag_1) |
|
6734 | R1 = numpy.abs(lag_1) | |
6730 |
|
6735 | |||
6731 | #---------------- Calculo del SNR---------------------------------- |
|
6736 | #---------------- Calculo del SNR---------------------------------- | |
6732 | data_snrPP = S / self.noise |
|
6737 | data_snrPP = S / self.noise | |
6733 | for i in range(self.__nch): |
|
6738 | for i in range(self.__nch): | |
6734 | for j in range(self.__nHeis): |
|
6739 | for j in range(self.__nHeis): | |
6735 | if data_snrPP[i][j] < 1.e-20: |
|
6740 | if data_snrPP[i][j] < 1.e-20: | |
6736 | data_snrPP[i][j] = 1.e-20 |
|
6741 | data_snrPP[i][j] = 1.e-20 | |
6737 |
|
6742 | |||
6738 | #----------------- Calculo del ancho espectral ---------------------- |
|
6743 | #----------------- Calculo del ancho espectral ---------------------- | |
6739 | L = S / R1 |
|
6744 | L = S / R1 | |
6740 | L = numpy.where(L < 0, 1, L) |
|
6745 | L = numpy.where(L < 0, 1, L) | |
6741 | L = numpy.log(L) |
|
6746 | L = numpy.log(L) | |
6742 | tmp = numpy.sqrt(numpy.absolute(L)) |
|
6747 | tmp = numpy.sqrt(numpy.absolute(L)) | |
6743 | data_specwidth = (self.lambda_ / (2 * math.sqrt(2) * math.pi * self.ippSec * self.nCohInt)) * tmp * numpy.sign(L) |
|
6748 | data_specwidth = (self.lambda_ / (2 * math.sqrt(2) * math.pi * self.ippSec * self.nCohInt)) * tmp * numpy.sign(L) | |
6744 | n = self.__profIndex |
|
6749 | n = self.__profIndex | |
6745 |
|
6750 | |||
6746 | self.__buffer = numpy.zeros((self.__nch, self.__nProf, self.__nHeis), dtype='complex') |
|
6751 | self.__buffer = numpy.zeros((self.__nch, self.__nProf, self.__nHeis), dtype='complex') | |
6747 | self.__profIndex = 0 |
|
6752 | self.__profIndex = 0 | |
6748 | return data_power, data_intensity, data_velocity, data_snrPP, data_specwidth, n |
|
6753 | return data_power, data_intensity, data_velocity, data_snrPP, data_specwidth, n | |
6749 |
|
6754 | |||
6750 |
|
6755 | |||
6751 | def pulsePairbyProfiles(self, dataOut): |
|
6756 | def pulsePairbyProfiles(self, dataOut): | |
6752 |
|
6757 | |||
6753 | self.__dataReady = False |
|
6758 | self.__dataReady = False | |
6754 | data_power = None |
|
6759 | data_power = None | |
6755 | data_intensity = None |
|
6760 | data_intensity = None | |
6756 | data_velocity = None |
|
6761 | data_velocity = None | |
6757 | data_specwidth = None |
|
6762 | data_specwidth = None | |
6758 | data_snrPP = None |
|
6763 | data_snrPP = None | |
6759 | self.putData(data=dataOut.data) |
|
6764 | self.putData(data=dataOut.data) | |
6760 | if self.__profIndex == self.n: |
|
6765 | if self.__profIndex == self.n: | |
6761 | data_power, data_intensity, data_velocity, data_snrPP, data_specwidth, n = self.pushData(dataOut=dataOut) |
|
6766 | data_power, data_intensity, data_velocity, data_snrPP, data_specwidth, n = self.pushData(dataOut=dataOut) | |
6762 | self.__dataReady = True |
|
6767 | self.__dataReady = True | |
6763 |
|
6768 | |||
6764 | return data_power, data_intensity, data_velocity, data_snrPP, data_specwidth |
|
6769 | return data_power, data_intensity, data_velocity, data_snrPP, data_specwidth | |
6765 |
|
6770 | |||
6766 |
|
6771 | |||
6767 | def pulsePairOp(self, dataOut, datatime=None): |
|
6772 | def pulsePairOp(self, dataOut, datatime=None): | |
6768 |
|
6773 | |||
6769 | if self.__initime == None: |
|
6774 | if self.__initime == None: | |
6770 | self.__initime = datatime |
|
6775 | self.__initime = datatime | |
6771 | data_power, data_intensity, data_velocity, data_snrPP, data_specwidth = self.pulsePairbyProfiles(dataOut) |
|
6776 | data_power, data_intensity, data_velocity, data_snrPP, data_specwidth = self.pulsePairbyProfiles(dataOut) | |
6772 | self.__lastdatatime = datatime |
|
6777 | self.__lastdatatime = datatime | |
6773 |
|
6778 | |||
6774 | if data_power is None: |
|
6779 | if data_power is None: | |
6775 | return None, None, None, None, None, None |
|
6780 | return None, None, None, None, None, None | |
6776 |
|
6781 | |||
6777 | avgdatatime = self.__initime |
|
6782 | avgdatatime = self.__initime | |
6778 | deltatime = datatime - self.__lastdatatime |
|
6783 | deltatime = datatime - self.__lastdatatime | |
6779 | self.__initime = datatime |
|
6784 | self.__initime = datatime | |
6780 |
|
6785 | |||
6781 | return data_power, data_intensity, data_velocity, data_snrPP, data_specwidth, avgdatatime |
|
6786 | return data_power, data_intensity, data_velocity, data_snrPP, data_specwidth, avgdatatime | |
6782 |
|
6787 | |||
6783 | def run(self, dataOut, n=None, removeDC=False, overlapping=False, **kwargs): |
|
6788 | def run(self, dataOut, n=None, removeDC=False, overlapping=False, **kwargs): | |
6784 |
|
6789 | |||
6785 | if not self.isConfig: |
|
6790 | if not self.isConfig: | |
6786 | self.setup(dataOut=dataOut, n=n , removeDC=removeDC , **kwargs) |
|
6791 | self.setup(dataOut=dataOut, n=n , removeDC=removeDC , **kwargs) | |
6787 | self.isConfig = True |
|
6792 | self.isConfig = True | |
6788 | data_power, data_intensity, data_velocity, data_snrPP, data_specwidth, avgdatatime = self.pulsePairOp(dataOut, dataOut.utctime) |
|
6793 | data_power, data_intensity, data_velocity, data_snrPP, data_specwidth, avgdatatime = self.pulsePairOp(dataOut, dataOut.utctime) | |
6789 | dataOut.flagNoData = True |
|
6794 | dataOut.flagNoData = True | |
6790 |
|
6795 | |||
6791 | if self.__dataReady: |
|
6796 | if self.__dataReady: | |
6792 | dataOut.nCohInt *= self.n |
|
6797 | dataOut.nCohInt *= self.n | |
6793 | dataOut.dataPP_POW = data_intensity # S |
|
6798 | dataOut.dataPP_POW = data_intensity # S | |
6794 | dataOut.dataPP_POWER = data_power # P |
|
6799 | dataOut.dataPP_POWER = data_power # P | |
6795 | dataOut.dataPP_DOP = data_velocity |
|
6800 | dataOut.dataPP_DOP = data_velocity | |
6796 | dataOut.dataPP_SNR = data_snrPP |
|
6801 | dataOut.dataPP_SNR = data_snrPP | |
6797 | dataOut.dataPP_WIDTH = data_specwidth |
|
6802 | dataOut.dataPP_WIDTH = data_specwidth | |
6798 | dataOut.PRFbyAngle = self.n # numero de PRF*cada angulo rotado que equivale a un tiempo. |
|
6803 | dataOut.PRFbyAngle = self.n # numero de PRF*cada angulo rotado que equivale a un tiempo. | |
6799 | dataOut.utctime = avgdatatime |
|
6804 | dataOut.utctime = avgdatatime | |
6800 | dataOut.flagNoData = False |
|
6805 | dataOut.flagNoData = False | |
6801 | return dataOut |
|
6806 | return dataOut | |
6802 |
|
6807 | |||
6803 |
|
6808 | |||
6804 |
|
6809 | |||
6805 | # import collections |
|
6810 | # import collections | |
6806 | # from scipy.stats import mode |
|
6811 | # from scipy.stats import mode | |
6807 | # |
|
6812 | # | |
6808 | # class Synchronize(Operation): |
|
6813 | # class Synchronize(Operation): | |
6809 | # |
|
6814 | # | |
6810 | # isConfig = False |
|
6815 | # isConfig = False | |
6811 | # __profIndex = 0 |
|
6816 | # __profIndex = 0 | |
6812 | # |
|
6817 | # | |
6813 | # def __init__(self, **kwargs): |
|
6818 | # def __init__(self, **kwargs): | |
6814 | # |
|
6819 | # | |
6815 | # Operation.__init__(self, **kwargs) |
|
6820 | # Operation.__init__(self, **kwargs) | |
6816 | # # self.isConfig = False |
|
6821 | # # self.isConfig = False | |
6817 | # self.__powBuffer = None |
|
6822 | # self.__powBuffer = None | |
6818 | # self.__startIndex = 0 |
|
6823 | # self.__startIndex = 0 | |
6819 | # self.__pulseFound = False |
|
6824 | # self.__pulseFound = False | |
6820 | # |
|
6825 | # | |
6821 | # def __findTxPulse(self, dataOut, channel=0, pulse_with = None): |
|
6826 | # def __findTxPulse(self, dataOut, channel=0, pulse_with = None): | |
6822 | # |
|
6827 | # | |
6823 | # #Read data |
|
6828 | # #Read data | |
6824 | # |
|
6829 | # | |
6825 | # powerdB = dataOut.getPower(channel = channel) |
|
6830 | # powerdB = dataOut.getPower(channel = channel) | |
6826 | # noisedB = dataOut.getNoise(channel = channel)[0] |
|
6831 | # noisedB = dataOut.getNoise(channel = channel)[0] | |
6827 | # |
|
6832 | # | |
6828 | # self.__powBuffer.extend(powerdB.flatten()) |
|
6833 | # self.__powBuffer.extend(powerdB.flatten()) | |
6829 | # |
|
6834 | # | |
6830 | # dataArray = numpy.array(self.__powBuffer) |
|
6835 | # dataArray = numpy.array(self.__powBuffer) | |
6831 | # |
|
6836 | # | |
6832 | # filteredPower = numpy.correlate(dataArray, dataArray[0:self.__nSamples], "same") |
|
6837 | # filteredPower = numpy.correlate(dataArray, dataArray[0:self.__nSamples], "same") | |
6833 | # |
|
6838 | # | |
6834 | # maxValue = numpy.nanmax(filteredPower) |
|
6839 | # maxValue = numpy.nanmax(filteredPower) | |
6835 | # |
|
6840 | # | |
6836 | # if maxValue < noisedB + 10: |
|
6841 | # if maxValue < noisedB + 10: | |
6837 | # #No se encuentra ningun pulso de transmision |
|
6842 | # #No se encuentra ningun pulso de transmision | |
6838 | # return None |
|
6843 | # return None | |
6839 | # |
|
6844 | # | |
6840 | # maxValuesIndex = numpy.where(filteredPower > maxValue - 0.1*abs(maxValue))[0] |
|
6845 | # maxValuesIndex = numpy.where(filteredPower > maxValue - 0.1*abs(maxValue))[0] | |
6841 | # |
|
6846 | # | |
6842 | # if len(maxValuesIndex) < 2: |
|
6847 | # if len(maxValuesIndex) < 2: | |
6843 | # #Solo se encontro un solo pulso de transmision de un baudio, esperando por el siguiente TX |
|
6848 | # #Solo se encontro un solo pulso de transmision de un baudio, esperando por el siguiente TX | |
6844 | # return None |
|
6849 | # return None | |
6845 | # |
|
6850 | # | |
6846 | # phasedMaxValuesIndex = maxValuesIndex - self.__nSamples |
|
6851 | # phasedMaxValuesIndex = maxValuesIndex - self.__nSamples | |
6847 | # |
|
6852 | # | |
6848 | # #Seleccionar solo valores con un espaciamiento de nSamples |
|
6853 | # #Seleccionar solo valores con un espaciamiento de nSamples | |
6849 | # pulseIndex = numpy.intersect1d(maxValuesIndex, phasedMaxValuesIndex) |
|
6854 | # pulseIndex = numpy.intersect1d(maxValuesIndex, phasedMaxValuesIndex) | |
6850 | # |
|
6855 | # | |
6851 | # if len(pulseIndex) < 2: |
|
6856 | # if len(pulseIndex) < 2: | |
6852 | # #Solo se encontro un pulso de transmision con ancho mayor a 1 |
|
6857 | # #Solo se encontro un pulso de transmision con ancho mayor a 1 | |
6853 | # return None |
|
6858 | # return None | |
6854 | # |
|
6859 | # | |
6855 | # spacing = pulseIndex[1:] - pulseIndex[:-1] |
|
6860 | # spacing = pulseIndex[1:] - pulseIndex[:-1] | |
6856 | # |
|
6861 | # | |
6857 | # #remover senales que se distancien menos de 10 unidades o muestras |
|
6862 | # #remover senales que se distancien menos de 10 unidades o muestras | |
6858 | # #(No deberian existir IPP menor a 10 unidades) |
|
6863 | # #(No deberian existir IPP menor a 10 unidades) | |
6859 | # |
|
6864 | # | |
6860 | # realIndex = numpy.where(spacing > 10 )[0] |
|
6865 | # realIndex = numpy.where(spacing > 10 )[0] | |
6861 | # |
|
6866 | # | |
6862 | # if len(realIndex) < 2: |
|
6867 | # if len(realIndex) < 2: | |
6863 | # #Solo se encontro un pulso de transmision con ancho mayor a 1 |
|
6868 | # #Solo se encontro un pulso de transmision con ancho mayor a 1 | |
6864 | # return None |
|
6869 | # return None | |
6865 | # |
|
6870 | # | |
6866 | # #Eliminar pulsos anchos (deja solo la diferencia entre IPPs) |
|
6871 | # #Eliminar pulsos anchos (deja solo la diferencia entre IPPs) | |
6867 | # realPulseIndex = pulseIndex[realIndex] |
|
6872 | # realPulseIndex = pulseIndex[realIndex] | |
6868 | # |
|
6873 | # | |
6869 | # period = mode(realPulseIndex[1:] - realPulseIndex[:-1])[0][0] |
|
6874 | # period = mode(realPulseIndex[1:] - realPulseIndex[:-1])[0][0] | |
6870 | # |
|
6875 | # | |
6871 | # print "IPP = %d samples" %period |
|
6876 | # print "IPP = %d samples" %period | |
6872 | # |
|
6877 | # | |
6873 | # self.__newNSamples = dataOut.nHeights #int(period) |
|
6878 | # self.__newNSamples = dataOut.nHeights #int(period) | |
6874 | # self.__startIndex = int(realPulseIndex[0]) |
|
6879 | # self.__startIndex = int(realPulseIndex[0]) | |
6875 | # |
|
6880 | # | |
6876 | # return 1 |
|
6881 | # return 1 | |
6877 | # |
|
6882 | # | |
6878 | # |
|
6883 | # | |
6879 | # def setup(self, nSamples, nChannels, buffer_size = 4): |
|
6884 | # def setup(self, nSamples, nChannels, buffer_size = 4): | |
6880 | # |
|
6885 | # | |
6881 | # self.__powBuffer = collections.deque(numpy.zeros( buffer_size*nSamples,dtype=numpy.float), |
|
6886 | # self.__powBuffer = collections.deque(numpy.zeros( buffer_size*nSamples,dtype=numpy.float), | |
6882 | # maxlen = buffer_size*nSamples) |
|
6887 | # maxlen = buffer_size*nSamples) | |
6883 | # |
|
6888 | # | |
6884 | # bufferList = [] |
|
6889 | # bufferList = [] | |
6885 | # |
|
6890 | # | |
6886 | # for i in range(nChannels): |
|
6891 | # for i in range(nChannels): | |
6887 | # bufferByChannel = collections.deque(numpy.zeros( buffer_size*nSamples, dtype=complex) + numpy.NAN, |
|
6892 | # bufferByChannel = collections.deque(numpy.zeros( buffer_size*nSamples, dtype=complex) + numpy.NAN, | |
6888 | # maxlen = buffer_size*nSamples) |
|
6893 | # maxlen = buffer_size*nSamples) | |
6889 | # |
|
6894 | # | |
6890 | # bufferList.append(bufferByChannel) |
|
6895 | # bufferList.append(bufferByChannel) | |
6891 | # |
|
6896 | # | |
6892 | # self.__nSamples = nSamples |
|
6897 | # self.__nSamples = nSamples | |
6893 | # self.__nChannels = nChannels |
|
6898 | # self.__nChannels = nChannels | |
6894 | # self.__bufferList = bufferList |
|
6899 | # self.__bufferList = bufferList | |
6895 | # |
|
6900 | # | |
6896 | # def run(self, dataOut, channel = 0): |
|
6901 | # def run(self, dataOut, channel = 0): | |
6897 | # |
|
6902 | # | |
6898 | # if not self.isConfig: |
|
6903 | # if not self.isConfig: | |
6899 | # nSamples = dataOut.nHeights |
|
6904 | # nSamples = dataOut.nHeights | |
6900 | # nChannels = dataOut.nChannels |
|
6905 | # nChannels = dataOut.nChannels | |
6901 | # self.setup(nSamples, nChannels) |
|
6906 | # self.setup(nSamples, nChannels) | |
6902 | # self.isConfig = True |
|
6907 | # self.isConfig = True | |
6903 | # |
|
6908 | # | |
6904 | # #Append new data to internal buffer |
|
6909 | # #Append new data to internal buffer | |
6905 | # for thisChannel in range(self.__nChannels): |
|
6910 | # for thisChannel in range(self.__nChannels): | |
6906 | # bufferByChannel = self.__bufferList[thisChannel] |
|
6911 | # bufferByChannel = self.__bufferList[thisChannel] | |
6907 | # bufferByChannel.extend(dataOut.data[thisChannel]) |
|
6912 | # bufferByChannel.extend(dataOut.data[thisChannel]) | |
6908 | # |
|
6913 | # | |
6909 | # if self.__pulseFound: |
|
6914 | # if self.__pulseFound: | |
6910 | # self.__startIndex -= self.__nSamples |
|
6915 | # self.__startIndex -= self.__nSamples | |
6911 | # |
|
6916 | # | |
6912 | # #Finding Tx Pulse |
|
6917 | # #Finding Tx Pulse | |
6913 | # if not self.__pulseFound: |
|
6918 | # if not self.__pulseFound: | |
6914 | # indexFound = self.__findTxPulse(dataOut, channel) |
|
6919 | # indexFound = self.__findTxPulse(dataOut, channel) | |
6915 | # |
|
6920 | # | |
6916 | # if indexFound == None: |
|
6921 | # if indexFound == None: | |
6917 | # dataOut.flagNoData = True |
|
6922 | # dataOut.flagNoData = True | |
6918 | # return |
|
6923 | # return | |
6919 | # |
|
6924 | # | |
6920 | # self.__arrayBuffer = numpy.zeros((self.__nChannels, self.__newNSamples), dtype = complex) |
|
6925 | # self.__arrayBuffer = numpy.zeros((self.__nChannels, self.__newNSamples), dtype = complex) | |
6921 | # self.__pulseFound = True |
|
6926 | # self.__pulseFound = True | |
6922 | # self.__startIndex = indexFound |
|
6927 | # self.__startIndex = indexFound | |
6923 | # |
|
6928 | # | |
6924 | # #If pulse was found ... |
|
6929 | # #If pulse was found ... | |
6925 | # for thisChannel in range(self.__nChannels): |
|
6930 | # for thisChannel in range(self.__nChannels): | |
6926 | # bufferByChannel = self.__bufferList[thisChannel] |
|
6931 | # bufferByChannel = self.__bufferList[thisChannel] | |
6927 | # #print self.__startIndex |
|
6932 | # #print self.__startIndex | |
6928 | # x = numpy.array(bufferByChannel) |
|
6933 | # x = numpy.array(bufferByChannel) | |
6929 | # self.__arrayBuffer[thisChannel] = x[self.__startIndex:self.__startIndex+self.__newNSamples] |
|
6934 | # self.__arrayBuffer[thisChannel] = x[self.__startIndex:self.__startIndex+self.__newNSamples] | |
6930 | # |
|
6935 | # | |
6931 | # deltaHeight = dataOut.heightList[1] - dataOut.heightList[0] |
|
6936 | # deltaHeight = dataOut.heightList[1] - dataOut.heightList[0] | |
6932 | # dataOut.heightList = numpy.arange(self.__newNSamples)*deltaHeight |
|
6937 | # dataOut.heightList = numpy.arange(self.__newNSamples)*deltaHeight | |
6933 | # # dataOut.ippSeconds = (self.__newNSamples / deltaHeight)/1e6 |
|
6938 | # # dataOut.ippSeconds = (self.__newNSamples / deltaHeight)/1e6 | |
6934 | # |
|
6939 | # | |
6935 | # dataOut.data = self.__arrayBuffer |
|
6940 | # dataOut.data = self.__arrayBuffer | |
6936 | # |
|
6941 | # | |
6937 | # self.__startIndex += self.__newNSamples |
|
6942 | # self.__startIndex += self.__newNSamples | |
6938 | # |
|
6943 | # | |
6939 | # return |
|
6944 | # return |
General Comments 0
You need to be logged in to leave comments.
Login now