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