The requested changes are too big and content was truncated. Show full diff
@@ -1,8 +1,8 | |||||
1 | """Signal chain python package""" |
|
1 | """Signal chain python package""" | |
2 |
|
2 | |||
3 | try: |
|
3 | try: | |
4 | from schainpy.controller import Project |
|
4 | from schainpy.controller import Project | |
5 | except: |
|
5 | except: | |
6 | pass |
|
6 | pass | |
7 |
|
7 | |||
8 |
__version__ = '3.0.0b |
|
8 | __version__ = '3.0.0b6' |
@@ -1,1193 +1,1066 | |||||
1 | # Copyright (c) 2012-2020 Jicamarca Radio Observatory |
|
1 | # Copyright (c) 2012-2020 Jicamarca Radio Observatory | |
2 | # All rights reserved. |
|
2 | # All rights reserved. | |
3 | # |
|
3 | # | |
4 | # Distributed under the terms of the BSD 3-clause license. |
|
4 | # Distributed under the terms of the BSD 3-clause license. | |
5 | """Definition of diferent Data objects for different types of data |
|
5 | """Definition of diferent Data objects for different types of data | |
6 |
|
6 | |||
7 | Here you will find the diferent data objects for the different types |
|
7 | Here you will find the diferent data objects for the different types | |
8 | of data, this data objects must be used as dataIn or dataOut objects in |
|
8 | of data, this data objects must be used as dataIn or dataOut objects in | |
9 | processing units and operations. Currently the supported data objects are: |
|
9 | processing units and operations. Currently the supported data objects are: | |
10 | Voltage, Spectra, SpectraHeis, Fits, Correlation and Parameters |
|
10 | Voltage, Spectra, SpectraHeis, Fits, Correlation and Parameters | |
11 | """ |
|
11 | """ | |
12 |
|
12 | |||
13 | import copy |
|
13 | import copy | |
14 | import numpy |
|
14 | import numpy | |
15 | import datetime |
|
15 | import datetime | |
16 | import json |
|
16 | import json | |
17 |
|
17 | |||
18 | import schainpy.admin |
|
18 | import schainpy.admin | |
19 | from schainpy.utils import log |
|
19 | from schainpy.utils import log | |
20 | from .jroheaderIO import SystemHeader, RadarControllerHeader |
|
20 | from .jroheaderIO import SystemHeader, RadarControllerHeader | |
21 | from schainpy.model.data import _noise |
|
21 | from schainpy.model.data import _noise | |
22 |
|
22 | |||
23 |
|
23 | |||
24 | def getNumpyDtype(dataTypeCode): |
|
24 | def getNumpyDtype(dataTypeCode): | |
25 |
|
25 | |||
26 | if dataTypeCode == 0: |
|
26 | if dataTypeCode == 0: | |
27 | numpyDtype = numpy.dtype([('real', '<i1'), ('imag', '<i1')]) |
|
27 | numpyDtype = numpy.dtype([('real', '<i1'), ('imag', '<i1')]) | |
28 | elif dataTypeCode == 1: |
|
28 | elif dataTypeCode == 1: | |
29 | numpyDtype = numpy.dtype([('real', '<i2'), ('imag', '<i2')]) |
|
29 | numpyDtype = numpy.dtype([('real', '<i2'), ('imag', '<i2')]) | |
30 | elif dataTypeCode == 2: |
|
30 | elif dataTypeCode == 2: | |
31 | numpyDtype = numpy.dtype([('real', '<i4'), ('imag', '<i4')]) |
|
31 | numpyDtype = numpy.dtype([('real', '<i4'), ('imag', '<i4')]) | |
32 | elif dataTypeCode == 3: |
|
32 | elif dataTypeCode == 3: | |
33 | numpyDtype = numpy.dtype([('real', '<i8'), ('imag', '<i8')]) |
|
33 | numpyDtype = numpy.dtype([('real', '<i8'), ('imag', '<i8')]) | |
34 | elif dataTypeCode == 4: |
|
34 | elif dataTypeCode == 4: | |
35 | numpyDtype = numpy.dtype([('real', '<f4'), ('imag', '<f4')]) |
|
35 | numpyDtype = numpy.dtype([('real', '<f4'), ('imag', '<f4')]) | |
36 | elif dataTypeCode == 5: |
|
36 | elif dataTypeCode == 5: | |
37 | numpyDtype = numpy.dtype([('real', '<f8'), ('imag', '<f8')]) |
|
37 | numpyDtype = numpy.dtype([('real', '<f8'), ('imag', '<f8')]) | |
38 | else: |
|
38 | else: | |
39 | raise ValueError('dataTypeCode was not defined') |
|
39 | raise ValueError('dataTypeCode was not defined') | |
40 |
|
40 | |||
41 | return numpyDtype |
|
41 | return numpyDtype | |
42 |
|
42 | |||
43 |
|
43 | |||
44 | def getDataTypeCode(numpyDtype): |
|
44 | def getDataTypeCode(numpyDtype): | |
45 |
|
45 | |||
46 | if numpyDtype == numpy.dtype([('real', '<i1'), ('imag', '<i1')]): |
|
46 | if numpyDtype == numpy.dtype([('real', '<i1'), ('imag', '<i1')]): | |
47 | datatype = 0 |
|
47 | datatype = 0 | |
48 | elif numpyDtype == numpy.dtype([('real', '<i2'), ('imag', '<i2')]): |
|
48 | elif numpyDtype == numpy.dtype([('real', '<i2'), ('imag', '<i2')]): | |
49 | datatype = 1 |
|
49 | datatype = 1 | |
50 | elif numpyDtype == numpy.dtype([('real', '<i4'), ('imag', '<i4')]): |
|
50 | elif numpyDtype == numpy.dtype([('real', '<i4'), ('imag', '<i4')]): | |
51 | datatype = 2 |
|
51 | datatype = 2 | |
52 | elif numpyDtype == numpy.dtype([('real', '<i8'), ('imag', '<i8')]): |
|
52 | elif numpyDtype == numpy.dtype([('real', '<i8'), ('imag', '<i8')]): | |
53 | datatype = 3 |
|
53 | datatype = 3 | |
54 | elif numpyDtype == numpy.dtype([('real', '<f4'), ('imag', '<f4')]): |
|
54 | elif numpyDtype == numpy.dtype([('real', '<f4'), ('imag', '<f4')]): | |
55 | datatype = 4 |
|
55 | datatype = 4 | |
56 | elif numpyDtype == numpy.dtype([('real', '<f8'), ('imag', '<f8')]): |
|
56 | elif numpyDtype == numpy.dtype([('real', '<f8'), ('imag', '<f8')]): | |
57 | datatype = 5 |
|
57 | datatype = 5 | |
58 | else: |
|
58 | else: | |
59 | datatype = None |
|
59 | datatype = None | |
60 |
|
60 | |||
61 | return datatype |
|
61 | return datatype | |
62 |
|
62 | |||
63 |
|
63 | |||
64 | def hildebrand_sekhon(data, navg): |
|
64 | def hildebrand_sekhon(data, navg): | |
65 | """ |
|
65 | """ | |
66 | This method is for the objective determination of the noise level in Doppler spectra. This |
|
66 | This method is for the objective determination of the noise level in Doppler spectra. This | |
67 | implementation technique is based on the fact that the standard deviation of the spectral |
|
67 | implementation technique is based on the fact that the standard deviation of the spectral | |
68 | densities is equal to the mean spectral density for white Gaussian noise |
|
68 | densities is equal to the mean spectral density for white Gaussian noise | |
69 |
|
69 | |||
70 | Inputs: |
|
70 | Inputs: | |
71 | Data : heights |
|
71 | Data : heights | |
72 | navg : numbers of averages |
|
72 | navg : numbers of averages | |
73 |
|
73 | |||
74 | Return: |
|
74 | Return: | |
75 | mean : noise's level |
|
75 | mean : noise's level | |
76 | """ |
|
76 | """ | |
77 |
|
77 | |||
78 | sortdata = numpy.sort(data, axis=None) |
|
78 | sortdata = numpy.sort(data, axis=None) | |
79 | ''' |
|
79 | ''' | |
80 | lenOfData = len(sortdata) |
|
80 | lenOfData = len(sortdata) | |
81 | nums_min = lenOfData*0.2 |
|
81 | nums_min = lenOfData*0.2 | |
82 |
|
82 | |||
83 | if nums_min <= 5: |
|
83 | if nums_min <= 5: | |
84 |
|
84 | |||
85 | nums_min = 5 |
|
85 | nums_min = 5 | |
86 |
|
86 | |||
87 | sump = 0. |
|
87 | sump = 0. | |
88 | sumq = 0. |
|
88 | sumq = 0. | |
89 |
|
89 | |||
90 | j = 0 |
|
90 | j = 0 | |
91 | cont = 1 |
|
91 | cont = 1 | |
92 |
|
92 | |||
93 | while((cont == 1)and(j < lenOfData)): |
|
93 | while((cont == 1)and(j < lenOfData)): | |
94 |
|
94 | |||
95 | sump += sortdata[j] |
|
95 | sump += sortdata[j] | |
96 | sumq += sortdata[j]**2 |
|
96 | sumq += sortdata[j]**2 | |
97 |
|
97 | |||
98 | if j > nums_min: |
|
98 | if j > nums_min: | |
99 | rtest = float(j)/(j-1) + 1.0/navg |
|
99 | rtest = float(j)/(j-1) + 1.0/navg | |
100 | if ((sumq*j) > (rtest*sump**2)): |
|
100 | if ((sumq*j) > (rtest*sump**2)): | |
101 | j = j - 1 |
|
101 | j = j - 1 | |
102 | sump = sump - sortdata[j] |
|
102 | sump = sump - sortdata[j] | |
103 | sumq = sumq - sortdata[j]**2 |
|
103 | sumq = sumq - sortdata[j]**2 | |
104 | cont = 0 |
|
104 | cont = 0 | |
105 |
|
105 | |||
106 | j += 1 |
|
106 | j += 1 | |
107 |
|
107 | |||
108 | lnoise = sump / j |
|
108 | lnoise = sump / j | |
109 | ''' |
|
109 | ''' | |
110 | return _noise.hildebrand_sekhon(sortdata, navg) |
|
110 | return _noise.hildebrand_sekhon(sortdata, navg) | |
111 |
|
111 | |||
112 |
|
112 | |||
113 | class Beam: |
|
113 | class Beam: | |
114 |
|
114 | |||
115 | def __init__(self): |
|
115 | def __init__(self): | |
116 | self.codeList = [] |
|
116 | self.codeList = [] | |
117 | self.azimuthList = [] |
|
117 | self.azimuthList = [] | |
118 | self.zenithList = [] |
|
118 | self.zenithList = [] | |
119 |
|
119 | |||
120 |
|
120 | |||
121 | class GenericData(object): |
|
121 | class GenericData(object): | |
122 |
|
122 | |||
123 | flagNoData = True |
|
123 | flagNoData = True | |
124 |
|
124 | |||
125 | def copy(self, inputObj=None): |
|
125 | def copy(self, inputObj=None): | |
126 |
|
126 | |||
127 | if inputObj == None: |
|
127 | if inputObj == None: | |
128 | return copy.deepcopy(self) |
|
128 | return copy.deepcopy(self) | |
129 |
|
129 | |||
130 | for key in list(inputObj.__dict__.keys()): |
|
130 | for key in list(inputObj.__dict__.keys()): | |
131 |
|
131 | |||
132 | attribute = inputObj.__dict__[key] |
|
132 | attribute = inputObj.__dict__[key] | |
133 |
|
133 | |||
134 | # If this attribute is a tuple or list |
|
134 | # If this attribute is a tuple or list | |
135 | if type(inputObj.__dict__[key]) in (tuple, list): |
|
135 | if type(inputObj.__dict__[key]) in (tuple, list): | |
136 | self.__dict__[key] = attribute[:] |
|
136 | self.__dict__[key] = attribute[:] | |
137 | continue |
|
137 | continue | |
138 |
|
138 | |||
139 | # If this attribute is another object or instance |
|
139 | # If this attribute is another object or instance | |
140 | if hasattr(attribute, '__dict__'): |
|
140 | if hasattr(attribute, '__dict__'): | |
141 | self.__dict__[key] = attribute.copy() |
|
141 | self.__dict__[key] = attribute.copy() | |
142 | continue |
|
142 | continue | |
143 |
|
143 | |||
144 | self.__dict__[key] = inputObj.__dict__[key] |
|
144 | self.__dict__[key] = inputObj.__dict__[key] | |
145 |
|
145 | |||
146 | def deepcopy(self): |
|
146 | def deepcopy(self): | |
147 |
|
147 | |||
148 | return copy.deepcopy(self) |
|
148 | return copy.deepcopy(self) | |
149 |
|
149 | |||
150 | def isEmpty(self): |
|
150 | def isEmpty(self): | |
151 |
|
151 | |||
152 | return self.flagNoData |
|
152 | return self.flagNoData | |
153 |
|
153 | |||
154 | def isReady(self): |
|
154 | def isReady(self): | |
155 |
|
155 | |||
156 | return not self.flagNoData |
|
156 | return not self.flagNoData | |
157 |
|
157 | |||
158 |
|
158 | |||
159 | class JROData(GenericData): |
|
159 | class JROData(GenericData): | |
160 |
|
160 | |||
161 | systemHeaderObj = SystemHeader() |
|
161 | systemHeaderObj = SystemHeader() | |
162 | radarControllerHeaderObj = RadarControllerHeader() |
|
162 | radarControllerHeaderObj = RadarControllerHeader() | |
163 | type = None |
|
163 | type = None | |
164 | datatype = None # dtype but in string |
|
164 | datatype = None # dtype but in string | |
165 | nProfiles = None |
|
165 | nProfiles = None | |
166 | heightList = None |
|
166 | heightList = None | |
167 | channelList = None |
|
167 | channelList = None | |
168 | flagDiscontinuousBlock = False |
|
168 | flagDiscontinuousBlock = False | |
169 | useLocalTime = False |
|
169 | useLocalTime = False | |
170 | utctime = None |
|
170 | utctime = None | |
171 | timeZone = None |
|
171 | timeZone = None | |
172 | dstFlag = None |
|
172 | dstFlag = None | |
173 | errorCount = None |
|
173 | errorCount = None | |
174 | blocksize = None |
|
174 | blocksize = None | |
175 | flagDecodeData = False # asumo q la data no esta decodificada |
|
175 | flagDecodeData = False # asumo q la data no esta decodificada | |
176 | flagDeflipData = False # asumo q la data no esta sin flip |
|
176 | flagDeflipData = False # asumo q la data no esta sin flip | |
177 | flagShiftFFT = False |
|
177 | flagShiftFFT = False | |
178 | nCohInt = None |
|
178 | nCohInt = None | |
179 | windowOfFilter = 1 |
|
179 | windowOfFilter = 1 | |
180 | C = 3e8 |
|
180 | C = 3e8 | |
181 | frequency = 49.92e6 |
|
181 | frequency = 49.92e6 | |
182 | realtime = False |
|
182 | realtime = False | |
183 | beacon_heiIndexList = None |
|
183 | beacon_heiIndexList = None | |
184 | last_block = None |
|
184 | last_block = None | |
185 | blocknow = None |
|
185 | blocknow = None | |
186 | azimuth = None |
|
186 | azimuth = None | |
187 | zenith = None |
|
187 | zenith = None | |
188 | beam = Beam() |
|
188 | beam = Beam() | |
189 | profileIndex = None |
|
189 | profileIndex = None | |
190 | error = None |
|
190 | error = None | |
191 | data = None |
|
191 | data = None | |
192 | nmodes = None |
|
192 | nmodes = None | |
193 | metadata_list = ['heightList', 'timeZone', 'type'] |
|
193 | metadata_list = ['heightList', 'timeZone', 'type'] | |
194 |
|
194 | |||
195 | def __str__(self): |
|
195 | def __str__(self): | |
196 |
|
196 | |||
197 | return '{} - {}'.format(self.type, self.datatime()) |
|
197 | return '{} - {}'.format(self.type, self.datatime()) | |
198 |
|
198 | |||
199 | def getNoise(self): |
|
199 | def getNoise(self): | |
200 |
|
200 | |||
201 | raise NotImplementedError |
|
201 | raise NotImplementedError | |
202 |
|
202 | |||
203 | @property |
|
203 | @property | |
204 | def nChannels(self): |
|
204 | def nChannels(self): | |
205 |
|
205 | |||
206 | return len(self.channelList) |
|
206 | return len(self.channelList) | |
207 |
|
207 | |||
208 | @property |
|
208 | @property | |
209 | def channelIndexList(self): |
|
209 | def channelIndexList(self): | |
210 |
|
210 | |||
211 | return list(range(self.nChannels)) |
|
211 | return list(range(self.nChannels)) | |
212 |
|
212 | |||
213 | @property |
|
213 | @property | |
214 | def nHeights(self): |
|
214 | def nHeights(self): | |
215 |
|
215 | |||
216 | return len(self.heightList) |
|
216 | return len(self.heightList) | |
217 |
|
217 | |||
218 | def getDeltaH(self): |
|
218 | def getDeltaH(self): | |
219 |
|
219 | |||
220 | return self.heightList[1] - self.heightList[0] |
|
220 | return self.heightList[1] - self.heightList[0] | |
221 |
|
221 | |||
222 | @property |
|
222 | @property | |
223 | def ltctime(self): |
|
223 | def ltctime(self): | |
224 |
|
224 | |||
225 | if self.useLocalTime: |
|
225 | if self.useLocalTime: | |
226 | return self.utctime - self.timeZone * 60 |
|
226 | return self.utctime - self.timeZone * 60 | |
227 |
|
227 | |||
228 | return self.utctime |
|
228 | return self.utctime | |
229 |
|
229 | |||
230 | @property |
|
230 | @property | |
231 | def datatime(self): |
|
231 | def datatime(self): | |
232 |
|
232 | |||
233 | datatimeValue = datetime.datetime.utcfromtimestamp(self.ltctime) |
|
233 | datatimeValue = datetime.datetime.utcfromtimestamp(self.ltctime) | |
234 | return datatimeValue |
|
234 | return datatimeValue | |
235 |
|
235 | |||
236 | def getTimeRange(self): |
|
236 | def getTimeRange(self): | |
237 |
|
237 | |||
238 | datatime = [] |
|
238 | datatime = [] | |
239 |
|
239 | |||
240 | datatime.append(self.ltctime) |
|
240 | datatime.append(self.ltctime) | |
241 | datatime.append(self.ltctime + self.timeInterval + 1) |
|
241 | datatime.append(self.ltctime + self.timeInterval + 1) | |
242 |
|
242 | |||
243 | datatime = numpy.array(datatime) |
|
243 | datatime = numpy.array(datatime) | |
244 |
|
244 | |||
245 | return datatime |
|
245 | return datatime | |
246 |
|
246 | |||
247 | def getFmaxTimeResponse(self): |
|
247 | def getFmaxTimeResponse(self): | |
248 |
|
248 | |||
249 | period = (10**-6) * self.getDeltaH() / (0.15) |
|
249 | period = (10**-6) * self.getDeltaH() / (0.15) | |
250 |
|
250 | |||
251 | PRF = 1. / (period * self.nCohInt) |
|
251 | PRF = 1. / (period * self.nCohInt) | |
252 |
|
252 | |||
253 | fmax = PRF |
|
253 | fmax = PRF | |
254 |
|
254 | |||
255 | return fmax |
|
255 | return fmax | |
256 |
|
256 | |||
257 | def getFmax(self): |
|
257 | def getFmax(self): | |
258 | PRF = 1. / (self.ippSeconds * self.nCohInt) |
|
258 | PRF = 1. / (self.ippSeconds * self.nCohInt) | |
259 |
|
259 | |||
260 | fmax = PRF |
|
260 | fmax = PRF | |
261 | return fmax |
|
261 | return fmax | |
262 |
|
262 | |||
263 | def getVmax(self): |
|
263 | def getVmax(self): | |
264 |
|
264 | |||
265 | _lambda = self.C / self.frequency |
|
265 | _lambda = self.C / self.frequency | |
266 |
|
266 | |||
267 | vmax = self.getFmax() * _lambda / 2 |
|
267 | vmax = self.getFmax() * _lambda / 2 | |
268 |
|
268 | |||
269 | return vmax |
|
269 | return vmax | |
270 |
|
270 | |||
271 | @property |
|
271 | @property | |
272 | def ippSeconds(self): |
|
272 | def ippSeconds(self): | |
273 | ''' |
|
273 | ''' | |
274 | ''' |
|
274 | ''' | |
275 | return self.radarControllerHeaderObj.ippSeconds |
|
275 | return self.radarControllerHeaderObj.ippSeconds | |
276 |
|
276 | |||
277 | @ippSeconds.setter |
|
277 | @ippSeconds.setter | |
278 | def ippSeconds(self, ippSeconds): |
|
278 | def ippSeconds(self, ippSeconds): | |
279 | ''' |
|
279 | ''' | |
280 | ''' |
|
280 | ''' | |
281 | self.radarControllerHeaderObj.ippSeconds = ippSeconds |
|
281 | self.radarControllerHeaderObj.ippSeconds = ippSeconds | |
282 |
|
282 | |||
283 | @property |
|
283 | @property | |
284 | def code(self): |
|
284 | def code(self): | |
285 | ''' |
|
285 | ''' | |
286 | ''' |
|
286 | ''' | |
287 | return self.radarControllerHeaderObj.code |
|
287 | return self.radarControllerHeaderObj.code | |
288 |
|
288 | |||
289 | @code.setter |
|
289 | @code.setter | |
290 | def code(self, code): |
|
290 | def code(self, code): | |
291 | ''' |
|
291 | ''' | |
292 | ''' |
|
292 | ''' | |
293 | self.radarControllerHeaderObj.code = code |
|
293 | self.radarControllerHeaderObj.code = code | |
294 |
|
294 | |||
295 | @property |
|
295 | @property | |
296 | def nCode(self): |
|
296 | def nCode(self): | |
297 | ''' |
|
297 | ''' | |
298 | ''' |
|
298 | ''' | |
299 | return self.radarControllerHeaderObj.nCode |
|
299 | return self.radarControllerHeaderObj.nCode | |
300 |
|
300 | |||
301 | @nCode.setter |
|
301 | @nCode.setter | |
302 | def nCode(self, ncode): |
|
302 | def nCode(self, ncode): | |
303 | ''' |
|
303 | ''' | |
304 | ''' |
|
304 | ''' | |
305 | self.radarControllerHeaderObj.nCode = ncode |
|
305 | self.radarControllerHeaderObj.nCode = ncode | |
306 |
|
306 | |||
307 | @property |
|
307 | @property | |
308 | def nBaud(self): |
|
308 | def nBaud(self): | |
309 | ''' |
|
309 | ''' | |
310 | ''' |
|
310 | ''' | |
311 | return self.radarControllerHeaderObj.nBaud |
|
311 | return self.radarControllerHeaderObj.nBaud | |
312 |
|
312 | |||
313 | @nBaud.setter |
|
313 | @nBaud.setter | |
314 | def nBaud(self, nbaud): |
|
314 | def nBaud(self, nbaud): | |
315 | ''' |
|
315 | ''' | |
316 | ''' |
|
316 | ''' | |
317 | self.radarControllerHeaderObj.nBaud = nbaud |
|
317 | self.radarControllerHeaderObj.nBaud = nbaud | |
318 |
|
318 | |||
319 | @property |
|
319 | @property | |
320 | def ipp(self): |
|
320 | def ipp(self): | |
321 | ''' |
|
321 | ''' | |
322 | ''' |
|
322 | ''' | |
323 | return self.radarControllerHeaderObj.ipp |
|
323 | return self.radarControllerHeaderObj.ipp | |
324 |
|
324 | |||
325 | @ipp.setter |
|
325 | @ipp.setter | |
326 | def ipp(self, ipp): |
|
326 | def ipp(self, ipp): | |
327 | ''' |
|
327 | ''' | |
328 | ''' |
|
328 | ''' | |
329 | self.radarControllerHeaderObj.ipp = ipp |
|
329 | self.radarControllerHeaderObj.ipp = ipp | |
330 |
|
330 | |||
331 | @property |
|
331 | @property | |
332 | def metadata(self): |
|
332 | def metadata(self): | |
333 | ''' |
|
333 | ''' | |
334 | ''' |
|
334 | ''' | |
335 |
|
335 | |||
336 | return {attr: getattr(self, attr) for attr in self.metadata_list} |
|
336 | return {attr: getattr(self, attr) for attr in self.metadata_list} | |
337 |
|
337 | |||
338 |
|
338 | |||
339 | class Voltage(JROData): |
|
339 | class Voltage(JROData): | |
340 |
|
340 | |||
341 | dataPP_POW = None |
|
341 | dataPP_POW = None | |
342 | dataPP_DOP = None |
|
342 | dataPP_DOP = None | |
343 | dataPP_WIDTH = None |
|
343 | dataPP_WIDTH = None | |
344 | dataPP_SNR = None |
|
344 | dataPP_SNR = None | |
345 |
|
345 | |||
346 | def __init__(self): |
|
346 | def __init__(self): | |
347 | ''' |
|
347 | ''' | |
348 | Constructor |
|
348 | Constructor | |
349 | ''' |
|
349 | ''' | |
350 |
|
350 | |||
351 | self.useLocalTime = True |
|
351 | self.useLocalTime = True | |
352 | self.radarControllerHeaderObj = RadarControllerHeader() |
|
352 | self.radarControllerHeaderObj = RadarControllerHeader() | |
353 | self.systemHeaderObj = SystemHeader() |
|
353 | self.systemHeaderObj = SystemHeader() | |
354 | self.type = "Voltage" |
|
354 | self.type = "Voltage" | |
355 | self.data = None |
|
355 | self.data = None | |
356 | self.nProfiles = None |
|
356 | self.nProfiles = None | |
357 | self.heightList = None |
|
357 | self.heightList = None | |
358 | self.channelList = None |
|
358 | self.channelList = None | |
359 | self.flagNoData = True |
|
359 | self.flagNoData = True | |
360 | self.flagDiscontinuousBlock = False |
|
360 | self.flagDiscontinuousBlock = False | |
361 | self.utctime = None |
|
361 | self.utctime = None | |
362 | self.timeZone = 0 |
|
362 | self.timeZone = 0 | |
363 | self.dstFlag = None |
|
363 | self.dstFlag = None | |
364 | self.errorCount = None |
|
364 | self.errorCount = None | |
365 | self.nCohInt = None |
|
365 | self.nCohInt = None | |
366 | self.blocksize = None |
|
366 | self.blocksize = None | |
367 | self.flagCohInt = False |
|
367 | self.flagCohInt = False | |
368 | self.flagDecodeData = False # asumo q la data no esta decodificada |
|
368 | self.flagDecodeData = False # asumo q la data no esta decodificada | |
369 | self.flagDeflipData = False # asumo q la data no esta sin flip |
|
369 | self.flagDeflipData = False # asumo q la data no esta sin flip | |
370 | self.flagShiftFFT = False |
|
370 | self.flagShiftFFT = False | |
371 | self.flagDataAsBlock = False # Asumo que la data es leida perfil a perfil |
|
371 | self.flagDataAsBlock = False # Asumo que la data es leida perfil a perfil | |
372 | self.profileIndex = 0 |
|
372 | self.profileIndex = 0 | |
373 | self.metadata_list = ['type', 'heightList', 'timeZone', 'nProfiles', 'channelList', 'nCohInt', |
|
373 | self.metadata_list = ['type', 'heightList', 'timeZone', 'nProfiles', 'channelList', 'nCohInt', | |
374 | 'code', 'nCode', 'nBaud', 'ippSeconds', 'ipp'] |
|
374 | 'code', 'nCode', 'nBaud', 'ippSeconds', 'ipp'] | |
375 |
|
375 | |||
376 | def getNoisebyHildebrand(self, channel=None): |
|
376 | def getNoisebyHildebrand(self, channel=None): | |
377 | """ |
|
377 | """ | |
378 | Determino el nivel de ruido usando el metodo Hildebrand-Sekhon |
|
378 | Determino el nivel de ruido usando el metodo Hildebrand-Sekhon | |
379 |
|
379 | |||
380 | Return: |
|
380 | Return: | |
381 | noiselevel |
|
381 | noiselevel | |
382 | """ |
|
382 | """ | |
383 |
|
383 | |||
384 | if channel != None: |
|
384 | if channel != None: | |
385 | data = self.data[channel] |
|
385 | data = self.data[channel] | |
386 | nChannels = 1 |
|
386 | nChannels = 1 | |
387 | else: |
|
387 | else: | |
388 | data = self.data |
|
388 | data = self.data | |
389 | nChannels = self.nChannels |
|
389 | nChannels = self.nChannels | |
390 |
|
390 | |||
391 | noise = numpy.zeros(nChannels) |
|
391 | noise = numpy.zeros(nChannels) | |
392 | power = data * numpy.conjugate(data) |
|
392 | power = data * numpy.conjugate(data) | |
393 |
|
393 | |||
394 | for thisChannel in range(nChannels): |
|
394 | for thisChannel in range(nChannels): | |
395 | if nChannels == 1: |
|
395 | if nChannels == 1: | |
396 | daux = power[:].real |
|
396 | daux = power[:].real | |
397 | else: |
|
397 | else: | |
398 | daux = power[thisChannel, :].real |
|
398 | daux = power[thisChannel, :].real | |
399 | noise[thisChannel] = hildebrand_sekhon(daux, self.nCohInt) |
|
399 | noise[thisChannel] = hildebrand_sekhon(daux, self.nCohInt) | |
400 |
|
400 | |||
401 | return noise |
|
401 | return noise | |
402 |
|
402 | |||
403 | def getNoise(self, type=1, channel=None): |
|
403 | def getNoise(self, type=1, channel=None): | |
404 |
|
404 | |||
405 | if type == 1: |
|
405 | if type == 1: | |
406 | noise = self.getNoisebyHildebrand(channel) |
|
406 | noise = self.getNoisebyHildebrand(channel) | |
407 |
|
407 | |||
408 | return noise |
|
408 | return noise | |
409 |
|
409 | |||
410 | def getPower(self, channel=None): |
|
410 | def getPower(self, channel=None): | |
411 |
|
411 | |||
412 | if channel != None: |
|
412 | if channel != None: | |
413 | data = self.data[channel] |
|
413 | data = self.data[channel] | |
414 | else: |
|
414 | else: | |
415 | data = self.data |
|
415 | data = self.data | |
416 |
|
416 | |||
417 | power = data * numpy.conjugate(data) |
|
417 | power = data * numpy.conjugate(data) | |
418 | powerdB = 10 * numpy.log10(power.real) |
|
418 | powerdB = 10 * numpy.log10(power.real) | |
419 | powerdB = numpy.squeeze(powerdB) |
|
419 | powerdB = numpy.squeeze(powerdB) | |
420 |
|
420 | |||
421 | return powerdB |
|
421 | return powerdB | |
422 |
|
422 | |||
423 | @property |
|
423 | @property | |
424 | def timeInterval(self): |
|
424 | def timeInterval(self): | |
425 |
|
425 | |||
426 | return self.ippSeconds * self.nCohInt |
|
426 | return self.ippSeconds * self.nCohInt | |
427 |
|
427 | |||
428 | noise = property(getNoise, "I'm the 'nHeights' property.") |
|
428 | noise = property(getNoise, "I'm the 'nHeights' property.") | |
429 |
|
429 | |||
430 |
|
430 | |||
431 | class Spectra(JROData): |
|
431 | class Spectra(JROData): | |
432 |
|
432 | |||
433 | def __init__(self): |
|
433 | def __init__(self): | |
434 | ''' |
|
434 | ''' | |
435 | Constructor |
|
435 | Constructor | |
436 | ''' |
|
436 | ''' | |
437 |
|
437 | |||
438 | self.useLocalTime = True |
|
438 | self.useLocalTime = True | |
439 | self.radarControllerHeaderObj = RadarControllerHeader() |
|
439 | self.radarControllerHeaderObj = RadarControllerHeader() | |
440 | self.systemHeaderObj = SystemHeader() |
|
440 | self.systemHeaderObj = SystemHeader() | |
441 | self.type = "Spectra" |
|
441 | self.type = "Spectra" | |
442 | self.timeZone = 0 |
|
442 | self.timeZone = 0 | |
443 | self.nProfiles = None |
|
443 | self.nProfiles = None | |
444 | self.heightList = None |
|
444 | self.heightList = None | |
445 | self.channelList = None |
|
445 | self.channelList = None | |
446 | self.pairsList = None |
|
446 | self.pairsList = None | |
447 | self.flagNoData = True |
|
447 | self.flagNoData = True | |
448 | self.flagDiscontinuousBlock = False |
|
448 | self.flagDiscontinuousBlock = False | |
449 | self.utctime = None |
|
449 | self.utctime = None | |
450 | self.nCohInt = None |
|
450 | self.nCohInt = None | |
451 | self.nIncohInt = None |
|
451 | self.nIncohInt = None | |
452 | self.blocksize = None |
|
452 | self.blocksize = None | |
453 | self.nFFTPoints = None |
|
453 | self.nFFTPoints = None | |
454 | self.wavelength = None |
|
454 | self.wavelength = None | |
455 | self.flagDecodeData = False # asumo q la data no esta decodificada |
|
455 | self.flagDecodeData = False # asumo q la data no esta decodificada | |
456 | self.flagDeflipData = False # asumo q la data no esta sin flip |
|
456 | self.flagDeflipData = False # asumo q la data no esta sin flip | |
457 | self.flagShiftFFT = False |
|
457 | self.flagShiftFFT = False | |
458 | self.ippFactor = 1 |
|
458 | self.ippFactor = 1 | |
459 | self.beacon_heiIndexList = [] |
|
459 | self.beacon_heiIndexList = [] | |
460 | self.noise_estimation = None |
|
460 | self.noise_estimation = None | |
461 | self.metadata_list = ['type', 'heightList', 'timeZone', 'pairsList', 'channelList', 'nCohInt', |
|
461 | self.metadata_list = ['type', 'heightList', 'timeZone', 'pairsList', 'channelList', 'nCohInt', | |
462 | 'code', 'nCode', 'nBaud', 'ippSeconds', 'ipp','nIncohInt', 'nFFTPoints', 'nProfiles'] |
|
462 | 'code', 'nCode', 'nBaud', 'ippSeconds', 'ipp','nIncohInt', 'nFFTPoints', 'nProfiles'] | |
463 |
|
463 | |||
464 | def getNoisebyHildebrand(self, xmin_index=None, xmax_index=None, ymin_index=None, ymax_index=None): |
|
464 | def getNoisebyHildebrand(self, xmin_index=None, xmax_index=None, ymin_index=None, ymax_index=None): | |
465 | """ |
|
465 | """ | |
466 | Determino el nivel de ruido usando el metodo Hildebrand-Sekhon |
|
466 | Determino el nivel de ruido usando el metodo Hildebrand-Sekhon | |
467 |
|
467 | |||
468 | Return: |
|
468 | Return: | |
469 | noiselevel |
|
469 | noiselevel | |
470 | """ |
|
470 | """ | |
471 |
|
471 | |||
472 | noise = numpy.zeros(self.nChannels) |
|
472 | noise = numpy.zeros(self.nChannels) | |
473 |
|
473 | |||
474 | for channel in range(self.nChannels): |
|
474 | for channel in range(self.nChannels): | |
475 | daux = self.data_spc[channel, |
|
475 | daux = self.data_spc[channel, | |
476 | xmin_index:xmax_index, ymin_index:ymax_index] |
|
476 | xmin_index:xmax_index, ymin_index:ymax_index] | |
477 | noise[channel] = hildebrand_sekhon(daux, self.nIncohInt) |
|
477 | noise[channel] = hildebrand_sekhon(daux, self.nIncohInt) | |
478 |
|
478 | |||
479 | return noise |
|
479 | return noise | |
480 |
|
480 | |||
481 | def getNoise(self, xmin_index=None, xmax_index=None, ymin_index=None, ymax_index=None): |
|
481 | def getNoise(self, xmin_index=None, xmax_index=None, ymin_index=None, ymax_index=None): | |
482 |
|
482 | |||
483 | if self.noise_estimation is not None: |
|
483 | if self.noise_estimation is not None: | |
484 | # this was estimated by getNoise Operation defined in jroproc_spectra.py |
|
484 | # this was estimated by getNoise Operation defined in jroproc_spectra.py | |
485 | return self.noise_estimation |
|
485 | return self.noise_estimation | |
486 | else: |
|
486 | else: | |
487 | noise = self.getNoisebyHildebrand( |
|
487 | noise = self.getNoisebyHildebrand( | |
488 | xmin_index, xmax_index, ymin_index, ymax_index) |
|
488 | xmin_index, xmax_index, ymin_index, ymax_index) | |
489 | return noise |
|
489 | return noise | |
490 |
|
490 | |||
491 | def getFreqRangeTimeResponse(self, extrapoints=0): |
|
491 | def getFreqRangeTimeResponse(self, extrapoints=0): | |
492 |
|
492 | |||
493 | deltafreq = self.getFmaxTimeResponse() / (self.nFFTPoints * self.ippFactor) |
|
493 | deltafreq = self.getFmaxTimeResponse() / (self.nFFTPoints * self.ippFactor) | |
494 | freqrange = deltafreq * (numpy.arange(self.nFFTPoints + extrapoints) - self.nFFTPoints / 2.) - deltafreq / 2 |
|
494 | freqrange = deltafreq * (numpy.arange(self.nFFTPoints + extrapoints) - self.nFFTPoints / 2.) - deltafreq / 2 | |
495 |
|
495 | |||
496 | return freqrange |
|
496 | return freqrange | |
497 |
|
497 | |||
498 | def getAcfRange(self, extrapoints=0): |
|
498 | def getAcfRange(self, extrapoints=0): | |
499 |
|
499 | |||
500 | deltafreq = 10. / (self.getFmax() / (self.nFFTPoints * self.ippFactor)) |
|
500 | deltafreq = 10. / (self.getFmax() / (self.nFFTPoints * self.ippFactor)) | |
501 | freqrange = deltafreq * (numpy.arange(self.nFFTPoints + extrapoints) -self.nFFTPoints / 2.) - deltafreq / 2 |
|
501 | freqrange = deltafreq * (numpy.arange(self.nFFTPoints + extrapoints) -self.nFFTPoints / 2.) - deltafreq / 2 | |
502 |
|
502 | |||
503 | return freqrange |
|
503 | return freqrange | |
504 |
|
504 | |||
505 | def getFreqRange(self, extrapoints=0): |
|
505 | def getFreqRange(self, extrapoints=0): | |
506 |
|
506 | |||
507 | deltafreq = self.getFmax() / (self.nFFTPoints * self.ippFactor) |
|
507 | deltafreq = self.getFmax() / (self.nFFTPoints * self.ippFactor) | |
508 | freqrange = deltafreq * (numpy.arange(self.nFFTPoints + extrapoints) -self.nFFTPoints / 2.) - deltafreq / 2 |
|
508 | freqrange = deltafreq * (numpy.arange(self.nFFTPoints + extrapoints) -self.nFFTPoints / 2.) - deltafreq / 2 | |
509 |
|
509 | |||
510 | return freqrange |
|
510 | return freqrange | |
511 |
|
511 | |||
512 | def getVelRange(self, extrapoints=0): |
|
512 | def getVelRange(self, extrapoints=0): | |
513 |
|
513 | |||
514 | deltav = self.getVmax() / (self.nFFTPoints * self.ippFactor) |
|
514 | deltav = self.getVmax() / (self.nFFTPoints * self.ippFactor) | |
515 | velrange = deltav * (numpy.arange(self.nFFTPoints + extrapoints) - self.nFFTPoints / 2.) |
|
515 | velrange = deltav * (numpy.arange(self.nFFTPoints + extrapoints) - self.nFFTPoints / 2.) | |
516 |
|
516 | |||
517 | if self.nmodes: |
|
517 | if self.nmodes: | |
518 | return velrange/self.nmodes |
|
518 | return velrange/self.nmodes | |
519 | else: |
|
519 | else: | |
520 | return velrange |
|
520 | return velrange | |
521 |
|
521 | |||
522 | @property |
|
522 | @property | |
523 | def nPairs(self): |
|
523 | def nPairs(self): | |
524 |
|
524 | |||
525 | return len(self.pairsList) |
|
525 | return len(self.pairsList) | |
526 |
|
526 | |||
527 | @property |
|
527 | @property | |
528 | def pairsIndexList(self): |
|
528 | def pairsIndexList(self): | |
529 |
|
529 | |||
530 | return list(range(self.nPairs)) |
|
530 | return list(range(self.nPairs)) | |
531 |
|
531 | |||
532 | @property |
|
532 | @property | |
533 | def normFactor(self): |
|
533 | def normFactor(self): | |
534 |
|
534 | |||
535 | pwcode = 1 |
|
535 | pwcode = 1 | |
536 |
|
536 | |||
537 | if self.flagDecodeData: |
|
537 | if self.flagDecodeData: | |
538 | pwcode = numpy.sum(self.code[0]**2) |
|
538 | pwcode = numpy.sum(self.code[0]**2) | |
539 | #normFactor = min(self.nFFTPoints,self.nProfiles)*self.nIncohInt*self.nCohInt*pwcode*self.windowOfFilter |
|
539 | #normFactor = min(self.nFFTPoints,self.nProfiles)*self.nIncohInt*self.nCohInt*pwcode*self.windowOfFilter | |
540 | normFactor = self.nProfiles * self.nIncohInt * self.nCohInt * pwcode * self.windowOfFilter |
|
540 | normFactor = self.nProfiles * self.nIncohInt * self.nCohInt * pwcode * self.windowOfFilter | |
541 |
|
541 | |||
542 | return normFactor |
|
542 | return normFactor | |
543 |
|
543 | |||
544 | @property |
|
544 | @property | |
545 | def flag_cspc(self): |
|
545 | def flag_cspc(self): | |
546 |
|
546 | |||
547 | if self.data_cspc is None: |
|
547 | if self.data_cspc is None: | |
548 | return True |
|
548 | return True | |
549 |
|
549 | |||
550 | return False |
|
550 | return False | |
551 |
|
551 | |||
552 | @property |
|
552 | @property | |
553 | def flag_dc(self): |
|
553 | def flag_dc(self): | |
554 |
|
554 | |||
555 | if self.data_dc is None: |
|
555 | if self.data_dc is None: | |
556 | return True |
|
556 | return True | |
557 |
|
557 | |||
558 | return False |
|
558 | return False | |
559 |
|
559 | |||
560 | @property |
|
560 | @property | |
561 | def timeInterval(self): |
|
561 | def timeInterval(self): | |
562 |
|
562 | |||
563 | timeInterval = self.ippSeconds * self.nCohInt * self.nIncohInt * self.nProfiles * self.ippFactor |
|
563 | timeInterval = self.ippSeconds * self.nCohInt * self.nIncohInt * self.nProfiles * self.ippFactor | |
564 | if self.nmodes: |
|
564 | if self.nmodes: | |
565 | return self.nmodes*timeInterval |
|
565 | return self.nmodes*timeInterval | |
566 | else: |
|
566 | else: | |
567 | return timeInterval |
|
567 | return timeInterval | |
568 |
|
568 | |||
569 | def getPower(self): |
|
569 | def getPower(self): | |
570 |
|
570 | |||
571 | factor = self.normFactor |
|
571 | factor = self.normFactor | |
572 | z = self.data_spc / factor |
|
572 | z = self.data_spc / factor | |
573 | z = numpy.where(numpy.isfinite(z), z, numpy.NAN) |
|
573 | z = numpy.where(numpy.isfinite(z), z, numpy.NAN) | |
574 | avg = numpy.average(z, axis=1) |
|
574 | avg = numpy.average(z, axis=1) | |
575 |
|
575 | |||
576 | return 10 * numpy.log10(avg) |
|
576 | return 10 * numpy.log10(avg) | |
577 |
|
577 | |||
578 | def getCoherence(self, pairsList=None, phase=False): |
|
578 | def getCoherence(self, pairsList=None, phase=False): | |
579 |
|
579 | |||
580 | z = [] |
|
580 | z = [] | |
581 | if pairsList is None: |
|
581 | if pairsList is None: | |
582 | pairsIndexList = self.pairsIndexList |
|
582 | pairsIndexList = self.pairsIndexList | |
583 | else: |
|
583 | else: | |
584 | pairsIndexList = [] |
|
584 | pairsIndexList = [] | |
585 | for pair in pairsList: |
|
585 | for pair in pairsList: | |
586 | if pair not in self.pairsList: |
|
586 | if pair not in self.pairsList: | |
587 | raise ValueError("Pair %s is not in dataOut.pairsList" % ( |
|
587 | raise ValueError("Pair %s is not in dataOut.pairsList" % ( | |
588 | pair)) |
|
588 | pair)) | |
589 | pairsIndexList.append(self.pairsList.index(pair)) |
|
589 | pairsIndexList.append(self.pairsList.index(pair)) | |
590 | for i in range(len(pairsIndexList)): |
|
590 | for i in range(len(pairsIndexList)): | |
591 | pair = self.pairsList[pairsIndexList[i]] |
|
591 | pair = self.pairsList[pairsIndexList[i]] | |
592 | ccf = numpy.average(self.data_cspc[pairsIndexList[i], :, :], axis=0) |
|
592 | ccf = numpy.average(self.data_cspc[pairsIndexList[i], :, :], axis=0) | |
593 | powa = numpy.average(self.data_spc[pair[0], :, :], axis=0) |
|
593 | powa = numpy.average(self.data_spc[pair[0], :, :], axis=0) | |
594 | powb = numpy.average(self.data_spc[pair[1], :, :], axis=0) |
|
594 | powb = numpy.average(self.data_spc[pair[1], :, :], axis=0) | |
595 | avgcoherenceComplex = ccf / numpy.sqrt(powa * powb) |
|
595 | avgcoherenceComplex = ccf / numpy.sqrt(powa * powb) | |
596 | if phase: |
|
596 | if phase: | |
597 | data = numpy.arctan2(avgcoherenceComplex.imag, |
|
597 | data = numpy.arctan2(avgcoherenceComplex.imag, | |
598 | avgcoherenceComplex.real) * 180 / numpy.pi |
|
598 | avgcoherenceComplex.real) * 180 / numpy.pi | |
599 | else: |
|
599 | else: | |
600 | data = numpy.abs(avgcoherenceComplex) |
|
600 | data = numpy.abs(avgcoherenceComplex) | |
601 |
|
601 | |||
602 | z.append(data) |
|
602 | z.append(data) | |
603 |
|
603 | |||
604 | return numpy.array(z) |
|
604 | return numpy.array(z) | |
605 |
|
605 | |||
606 | def setValue(self, value): |
|
606 | def setValue(self, value): | |
607 |
|
607 | |||
608 | print("This property should not be initialized") |
|
608 | print("This property should not be initialized") | |
609 |
|
609 | |||
610 | return |
|
610 | return | |
611 |
|
611 | |||
612 | noise = property(getNoise, setValue, "I'm the 'nHeights' property.") |
|
612 | noise = property(getNoise, setValue, "I'm the 'nHeights' property.") | |
613 |
|
613 | |||
614 |
|
614 | |||
615 | class SpectraHeis(Spectra): |
|
615 | class SpectraHeis(Spectra): | |
616 |
|
616 | |||
617 | def __init__(self): |
|
617 | def __init__(self): | |
618 |
|
618 | |||
619 | self.radarControllerHeaderObj = RadarControllerHeader() |
|
619 | self.radarControllerHeaderObj = RadarControllerHeader() | |
620 | self.systemHeaderObj = SystemHeader() |
|
620 | self.systemHeaderObj = SystemHeader() | |
621 | self.type = "SpectraHeis" |
|
621 | self.type = "SpectraHeis" | |
622 | self.nProfiles = None |
|
622 | self.nProfiles = None | |
623 | self.heightList = None |
|
623 | self.heightList = None | |
624 | self.channelList = None |
|
624 | self.channelList = None | |
625 | self.flagNoData = True |
|
625 | self.flagNoData = True | |
626 | self.flagDiscontinuousBlock = False |
|
626 | self.flagDiscontinuousBlock = False | |
627 | self.utctime = None |
|
627 | self.utctime = None | |
628 | self.blocksize = None |
|
628 | self.blocksize = None | |
629 | self.profileIndex = 0 |
|
629 | self.profileIndex = 0 | |
630 | self.nCohInt = 1 |
|
630 | self.nCohInt = 1 | |
631 | self.nIncohInt = 1 |
|
631 | self.nIncohInt = 1 | |
632 |
|
632 | |||
633 | @property |
|
633 | @property | |
634 | def normFactor(self): |
|
634 | def normFactor(self): | |
635 | pwcode = 1 |
|
635 | pwcode = 1 | |
636 | if self.flagDecodeData: |
|
636 | if self.flagDecodeData: | |
637 | pwcode = numpy.sum(self.code[0]**2) |
|
637 | pwcode = numpy.sum(self.code[0]**2) | |
638 |
|
638 | |||
639 | normFactor = self.nIncohInt * self.nCohInt * pwcode |
|
639 | normFactor = self.nIncohInt * self.nCohInt * pwcode | |
640 |
|
640 | |||
641 | return normFactor |
|
641 | return normFactor | |
642 |
|
642 | |||
643 | @property |
|
643 | @property | |
644 | def timeInterval(self): |
|
644 | def timeInterval(self): | |
645 |
|
645 | |||
646 | return self.ippSeconds * self.nCohInt * self.nIncohInt |
|
646 | return self.ippSeconds * self.nCohInt * self.nIncohInt | |
647 |
|
647 | |||
648 |
|
648 | |||
649 | class Fits(JROData): |
|
649 | class Fits(JROData): | |
650 |
|
650 | |||
651 | def __init__(self): |
|
651 | def __init__(self): | |
652 |
|
652 | |||
653 | self.type = "Fits" |
|
653 | self.type = "Fits" | |
654 | self.nProfiles = None |
|
654 | self.nProfiles = None | |
655 | self.heightList = None |
|
655 | self.heightList = None | |
656 | self.channelList = None |
|
656 | self.channelList = None | |
657 | self.flagNoData = True |
|
657 | self.flagNoData = True | |
658 | self.utctime = None |
|
658 | self.utctime = None | |
659 | self.nCohInt = 1 |
|
659 | self.nCohInt = 1 | |
660 | self.nIncohInt = 1 |
|
660 | self.nIncohInt = 1 | |
661 | self.useLocalTime = True |
|
661 | self.useLocalTime = True | |
662 | self.profileIndex = 0 |
|
662 | self.profileIndex = 0 | |
663 | self.timeZone = 0 |
|
663 | self.timeZone = 0 | |
664 |
|
664 | |||
665 | def getTimeRange(self): |
|
665 | def getTimeRange(self): | |
666 |
|
666 | |||
667 | datatime = [] |
|
667 | datatime = [] | |
668 |
|
668 | |||
669 | datatime.append(self.ltctime) |
|
669 | datatime.append(self.ltctime) | |
670 | datatime.append(self.ltctime + self.timeInterval) |
|
670 | datatime.append(self.ltctime + self.timeInterval) | |
671 |
|
671 | |||
672 | datatime = numpy.array(datatime) |
|
672 | datatime = numpy.array(datatime) | |
673 |
|
673 | |||
674 | return datatime |
|
674 | return datatime | |
675 |
|
675 | |||
676 | def getChannelIndexList(self): |
|
676 | def getChannelIndexList(self): | |
677 |
|
677 | |||
678 | return list(range(self.nChannels)) |
|
678 | return list(range(self.nChannels)) | |
679 |
|
679 | |||
680 | def getNoise(self, type=1): |
|
680 | def getNoise(self, type=1): | |
681 |
|
681 | |||
682 |
|
682 | |||
683 | if type == 1: |
|
683 | if type == 1: | |
684 | noise = self.getNoisebyHildebrand() |
|
684 | noise = self.getNoisebyHildebrand() | |
685 |
|
685 | |||
686 | if type == 2: |
|
686 | if type == 2: | |
687 | noise = self.getNoisebySort() |
|
687 | noise = self.getNoisebySort() | |
688 |
|
688 | |||
689 | if type == 3: |
|
689 | if type == 3: | |
690 | noise = self.getNoisebyWindow() |
|
690 | noise = self.getNoisebyWindow() | |
691 |
|
691 | |||
692 | return noise |
|
692 | return noise | |
693 |
|
693 | |||
694 | @property |
|
694 | @property | |
695 | def timeInterval(self): |
|
695 | def timeInterval(self): | |
696 |
|
696 | |||
697 | timeInterval = self.ippSeconds * self.nCohInt * self.nIncohInt |
|
697 | timeInterval = self.ippSeconds * self.nCohInt * self.nIncohInt | |
698 |
|
698 | |||
699 | return timeInterval |
|
699 | return timeInterval | |
700 |
|
700 | |||
701 | @property |
|
701 | @property | |
702 | def ippSeconds(self): |
|
702 | def ippSeconds(self): | |
703 | ''' |
|
703 | ''' | |
704 | ''' |
|
704 | ''' | |
705 | return self.ipp_sec |
|
705 | return self.ipp_sec | |
706 |
|
706 | |||
707 | noise = property(getNoise, "I'm the 'nHeights' property.") |
|
707 | noise = property(getNoise, "I'm the 'nHeights' property.") | |
708 |
|
708 | |||
709 |
|
709 | |||
710 | class Correlation(JROData): |
|
710 | class Correlation(JROData): | |
711 |
|
711 | |||
712 | def __init__(self): |
|
712 | def __init__(self): | |
713 | ''' |
|
713 | ''' | |
714 | Constructor |
|
714 | Constructor | |
715 | ''' |
|
715 | ''' | |
716 | self.radarControllerHeaderObj = RadarControllerHeader() |
|
716 | self.radarControllerHeaderObj = RadarControllerHeader() | |
717 | self.systemHeaderObj = SystemHeader() |
|
717 | self.systemHeaderObj = SystemHeader() | |
718 | self.type = "Correlation" |
|
718 | self.type = "Correlation" | |
719 | self.data = None |
|
719 | self.data = None | |
720 | self.dtype = None |
|
720 | self.dtype = None | |
721 | self.nProfiles = None |
|
721 | self.nProfiles = None | |
722 | self.heightList = None |
|
722 | self.heightList = None | |
723 | self.channelList = None |
|
723 | self.channelList = None | |
724 | self.flagNoData = True |
|
724 | self.flagNoData = True | |
725 | self.flagDiscontinuousBlock = False |
|
725 | self.flagDiscontinuousBlock = False | |
726 | self.utctime = None |
|
726 | self.utctime = None | |
727 | self.timeZone = 0 |
|
727 | self.timeZone = 0 | |
728 | self.dstFlag = None |
|
728 | self.dstFlag = None | |
729 | self.errorCount = None |
|
729 | self.errorCount = None | |
730 | self.blocksize = None |
|
730 | self.blocksize = None | |
731 | self.flagDecodeData = False # asumo q la data no esta decodificada |
|
731 | self.flagDecodeData = False # asumo q la data no esta decodificada | |
732 | self.flagDeflipData = False # asumo q la data no esta sin flip |
|
732 | self.flagDeflipData = False # asumo q la data no esta sin flip | |
733 | self.pairsList = None |
|
733 | self.pairsList = None | |
734 | self.nPoints = None |
|
734 | self.nPoints = None | |
735 |
|
735 | |||
736 | def getPairsList(self): |
|
736 | def getPairsList(self): | |
737 |
|
737 | |||
738 | return self.pairsList |
|
738 | return self.pairsList | |
739 |
|
739 | |||
740 | def getNoise(self, mode=2): |
|
740 | def getNoise(self, mode=2): | |
741 |
|
741 | |||
742 | indR = numpy.where(self.lagR == 0)[0][0] |
|
742 | indR = numpy.where(self.lagR == 0)[0][0] | |
743 | indT = numpy.where(self.lagT == 0)[0][0] |
|
743 | indT = numpy.where(self.lagT == 0)[0][0] | |
744 |
|
744 | |||
745 | jspectra0 = self.data_corr[:, :, indR, :] |
|
745 | jspectra0 = self.data_corr[:, :, indR, :] | |
746 | jspectra = copy.copy(jspectra0) |
|
746 | jspectra = copy.copy(jspectra0) | |
747 |
|
747 | |||
748 | num_chan = jspectra.shape[0] |
|
748 | num_chan = jspectra.shape[0] | |
749 | num_hei = jspectra.shape[2] |
|
749 | num_hei = jspectra.shape[2] | |
750 |
|
750 | |||
751 | freq_dc = jspectra.shape[1] / 2 |
|
751 | freq_dc = jspectra.shape[1] / 2 | |
752 | ind_vel = numpy.array([-2, -1, 1, 2]) + freq_dc |
|
752 | ind_vel = numpy.array([-2, -1, 1, 2]) + freq_dc | |
753 |
|
753 | |||
754 | if ind_vel[0] < 0: |
|
754 | if ind_vel[0] < 0: | |
755 | ind_vel[list(range(0, 1))] = ind_vel[list( |
|
755 | ind_vel[list(range(0, 1))] = ind_vel[list( | |
756 | range(0, 1))] + self.num_prof |
|
756 | range(0, 1))] + self.num_prof | |
757 |
|
757 | |||
758 | if mode == 1: |
|
758 | if mode == 1: | |
759 | jspectra[:, freq_dc, :] = ( |
|
759 | jspectra[:, freq_dc, :] = ( | |
760 | jspectra[:, ind_vel[1], :] + jspectra[:, ind_vel[2], :]) / 2 # CORRECCION |
|
760 | jspectra[:, ind_vel[1], :] + jspectra[:, ind_vel[2], :]) / 2 # CORRECCION | |
761 |
|
761 | |||
762 | if mode == 2: |
|
762 | if mode == 2: | |
763 |
|
763 | |||
764 | vel = numpy.array([-2, -1, 1, 2]) |
|
764 | vel = numpy.array([-2, -1, 1, 2]) | |
765 | xx = numpy.zeros([4, 4]) |
|
765 | xx = numpy.zeros([4, 4]) | |
766 |
|
766 | |||
767 | for fil in range(4): |
|
767 | for fil in range(4): | |
768 | xx[fil, :] = vel[fil]**numpy.asarray(list(range(4))) |
|
768 | xx[fil, :] = vel[fil]**numpy.asarray(list(range(4))) | |
769 |
|
769 | |||
770 | xx_inv = numpy.linalg.inv(xx) |
|
770 | xx_inv = numpy.linalg.inv(xx) | |
771 | xx_aux = xx_inv[0, :] |
|
771 | xx_aux = xx_inv[0, :] | |
772 |
|
772 | |||
773 | for ich in range(num_chan): |
|
773 | for ich in range(num_chan): | |
774 | yy = jspectra[ich, ind_vel, :] |
|
774 | yy = jspectra[ich, ind_vel, :] | |
775 | jspectra[ich, freq_dc, :] = numpy.dot(xx_aux, yy) |
|
775 | jspectra[ich, freq_dc, :] = numpy.dot(xx_aux, yy) | |
776 |
|
776 | |||
777 | junkid = jspectra[ich, freq_dc, :] <= 0 |
|
777 | junkid = jspectra[ich, freq_dc, :] <= 0 | |
778 | cjunkid = sum(junkid) |
|
778 | cjunkid = sum(junkid) | |
779 |
|
779 | |||
780 | if cjunkid.any(): |
|
780 | if cjunkid.any(): | |
781 | jspectra[ich, freq_dc, junkid.nonzero()] = ( |
|
781 | jspectra[ich, freq_dc, junkid.nonzero()] = ( | |
782 | jspectra[ich, ind_vel[1], junkid] + jspectra[ich, ind_vel[2], junkid]) / 2 |
|
782 | jspectra[ich, ind_vel[1], junkid] + jspectra[ich, ind_vel[2], junkid]) / 2 | |
783 |
|
783 | |||
784 | noise = jspectra0[:, freq_dc, :] - jspectra[:, freq_dc, :] |
|
784 | noise = jspectra0[:, freq_dc, :] - jspectra[:, freq_dc, :] | |
785 |
|
785 | |||
786 | return noise |
|
786 | return noise | |
787 |
|
787 | |||
788 | @property |
|
788 | @property | |
789 | def timeInterval(self): |
|
789 | def timeInterval(self): | |
790 |
|
790 | |||
791 | return self.ippSeconds * self.nCohInt * self.nProfiles |
|
791 | return self.ippSeconds * self.nCohInt * self.nProfiles | |
792 |
|
792 | |||
793 | def splitFunctions(self): |
|
793 | def splitFunctions(self): | |
794 |
|
794 | |||
795 | pairsList = self.pairsList |
|
795 | pairsList = self.pairsList | |
796 | ccf_pairs = [] |
|
796 | ccf_pairs = [] | |
797 | acf_pairs = [] |
|
797 | acf_pairs = [] | |
798 | ccf_ind = [] |
|
798 | ccf_ind = [] | |
799 | acf_ind = [] |
|
799 | acf_ind = [] | |
800 | for l in range(len(pairsList)): |
|
800 | for l in range(len(pairsList)): | |
801 | chan0 = pairsList[l][0] |
|
801 | chan0 = pairsList[l][0] | |
802 | chan1 = pairsList[l][1] |
|
802 | chan1 = pairsList[l][1] | |
803 |
|
803 | |||
804 | # Obteniendo pares de Autocorrelacion |
|
804 | # Obteniendo pares de Autocorrelacion | |
805 | if chan0 == chan1: |
|
805 | if chan0 == chan1: | |
806 | acf_pairs.append(chan0) |
|
806 | acf_pairs.append(chan0) | |
807 | acf_ind.append(l) |
|
807 | acf_ind.append(l) | |
808 | else: |
|
808 | else: | |
809 | ccf_pairs.append(pairsList[l]) |
|
809 | ccf_pairs.append(pairsList[l]) | |
810 | ccf_ind.append(l) |
|
810 | ccf_ind.append(l) | |
811 |
|
811 | |||
812 | data_acf = self.data_cf[acf_ind] |
|
812 | data_acf = self.data_cf[acf_ind] | |
813 | data_ccf = self.data_cf[ccf_ind] |
|
813 | data_ccf = self.data_cf[ccf_ind] | |
814 |
|
814 | |||
815 | return acf_ind, ccf_ind, acf_pairs, ccf_pairs, data_acf, data_ccf |
|
815 | return acf_ind, ccf_ind, acf_pairs, ccf_pairs, data_acf, data_ccf | |
816 |
|
816 | |||
817 | @property |
|
817 | @property | |
818 | def normFactor(self): |
|
818 | def normFactor(self): | |
819 | acf_ind, ccf_ind, acf_pairs, ccf_pairs, data_acf, data_ccf = self.splitFunctions() |
|
819 | acf_ind, ccf_ind, acf_pairs, ccf_pairs, data_acf, data_ccf = self.splitFunctions() | |
820 | acf_pairs = numpy.array(acf_pairs) |
|
820 | acf_pairs = numpy.array(acf_pairs) | |
821 | normFactor = numpy.zeros((self.nPairs, self.nHeights)) |
|
821 | normFactor = numpy.zeros((self.nPairs, self.nHeights)) | |
822 |
|
822 | |||
823 | for p in range(self.nPairs): |
|
823 | for p in range(self.nPairs): | |
824 | pair = self.pairsList[p] |
|
824 | pair = self.pairsList[p] | |
825 |
|
825 | |||
826 | ch0 = pair[0] |
|
826 | ch0 = pair[0] | |
827 | ch1 = pair[1] |
|
827 | ch1 = pair[1] | |
828 |
|
828 | |||
829 | ch0_max = numpy.max(data_acf[acf_pairs == ch0, :, :], axis=1) |
|
829 | ch0_max = numpy.max(data_acf[acf_pairs == ch0, :, :], axis=1) | |
830 | ch1_max = numpy.max(data_acf[acf_pairs == ch1, :, :], axis=1) |
|
830 | ch1_max = numpy.max(data_acf[acf_pairs == ch1, :, :], axis=1) | |
831 | normFactor[p, :] = numpy.sqrt(ch0_max * ch1_max) |
|
831 | normFactor[p, :] = numpy.sqrt(ch0_max * ch1_max) | |
832 |
|
832 | |||
833 | return normFactor |
|
833 | return normFactor | |
834 |
|
834 | |||
835 |
|
835 | |||
836 | class Parameters(Spectra): |
|
836 | class Parameters(Spectra): | |
837 |
|
837 | |||
838 | groupList = None # List of Pairs, Groups, etc |
|
838 | groupList = None # List of Pairs, Groups, etc | |
839 | data_param = None # Parameters obtained |
|
839 | data_param = None # Parameters obtained | |
840 | data_pre = None # Data Pre Parametrization |
|
840 | data_pre = None # Data Pre Parametrization | |
841 | data_SNR = None # Signal to Noise Ratio |
|
841 | data_SNR = None # Signal to Noise Ratio | |
842 | abscissaList = None # Abscissa, can be velocities, lags or time |
|
842 | abscissaList = None # Abscissa, can be velocities, lags or time | |
843 | utctimeInit = None # Initial UTC time |
|
843 | utctimeInit = None # Initial UTC time | |
844 | paramInterval = None # Time interval to calculate Parameters in seconds |
|
844 | paramInterval = None # Time interval to calculate Parameters in seconds | |
845 | useLocalTime = True |
|
845 | useLocalTime = True | |
846 | # Fitting |
|
846 | # Fitting | |
847 | data_error = None # Error of the estimation |
|
847 | data_error = None # Error of the estimation | |
848 | constants = None |
|
848 | constants = None | |
849 | library = None |
|
849 | library = None | |
850 | # Output signal |
|
850 | # Output signal | |
851 | outputInterval = None # Time interval to calculate output signal in seconds |
|
851 | outputInterval = None # Time interval to calculate output signal in seconds | |
852 | data_output = None # Out signal |
|
852 | data_output = None # Out signal | |
853 | nAvg = None |
|
853 | nAvg = None | |
854 | noise_estimation = None |
|
854 | noise_estimation = None | |
855 | GauSPC = None # Fit gaussian SPC |
|
855 | GauSPC = None # Fit gaussian SPC | |
856 |
|
856 | |||
857 | def __init__(self): |
|
857 | def __init__(self): | |
858 | ''' |
|
858 | ''' | |
859 | Constructor |
|
859 | Constructor | |
860 | ''' |
|
860 | ''' | |
861 | self.radarControllerHeaderObj = RadarControllerHeader() |
|
861 | self.radarControllerHeaderObj = RadarControllerHeader() | |
862 | self.systemHeaderObj = SystemHeader() |
|
862 | self.systemHeaderObj = SystemHeader() | |
863 | self.type = "Parameters" |
|
863 | self.type = "Parameters" | |
864 | self.timeZone = 0 |
|
864 | self.timeZone = 0 | |
865 |
|
865 | |||
866 | def getTimeRange1(self, interval): |
|
866 | def getTimeRange1(self, interval): | |
867 |
|
867 | |||
868 | datatime = [] |
|
868 | datatime = [] | |
869 |
|
869 | |||
870 | if self.useLocalTime: |
|
870 | if self.useLocalTime: | |
871 | time1 = self.utctimeInit - self.timeZone * 60 |
|
871 | time1 = self.utctimeInit - self.timeZone * 60 | |
872 | else: |
|
872 | else: | |
873 | time1 = self.utctimeInit |
|
873 | time1 = self.utctimeInit | |
874 |
|
874 | |||
875 | datatime.append(time1) |
|
875 | datatime.append(time1) | |
876 | datatime.append(time1 + interval) |
|
876 | datatime.append(time1 + interval) | |
877 | datatime = numpy.array(datatime) |
|
877 | datatime = numpy.array(datatime) | |
878 |
|
878 | |||
879 | return datatime |
|
879 | return datatime | |
880 |
|
880 | |||
881 | @property |
|
881 | @property | |
882 | def timeInterval(self): |
|
882 | def timeInterval(self): | |
883 |
|
883 | |||
884 | if hasattr(self, 'timeInterval1'): |
|
884 | if hasattr(self, 'timeInterval1'): | |
885 | return self.timeInterval1 |
|
885 | return self.timeInterval1 | |
886 | else: |
|
886 | else: | |
887 | return self.paramInterval |
|
887 | return self.paramInterval | |
888 |
|
888 | |||
889 | def setValue(self, value): |
|
889 | def setValue(self, value): | |
890 |
|
890 | |||
891 | print("This property should not be initialized") |
|
891 | print("This property should not be initialized") | |
892 |
|
892 | |||
893 | return |
|
893 | return | |
894 |
|
894 | |||
895 | def getNoise(self): |
|
895 | def getNoise(self): | |
896 |
|
896 | |||
897 | return self.spc_noise |
|
897 | return self.spc_noise | |
898 |
|
898 | |||
899 | noise = property(getNoise, setValue, "I'm the 'Noise' property.") |
|
899 | noise = property(getNoise, setValue, "I'm the 'Noise' property.") | |
900 |
|
900 | |||
901 |
|
901 | |||
902 | class PlotterData(object): |
|
902 | class PlotterData(object): | |
903 | ''' |
|
903 | ''' | |
904 | Object to hold data to be plotted |
|
904 | Object to hold data to be plotted | |
905 | ''' |
|
905 | ''' | |
906 |
|
906 | |||
907 | MAXNUMX = 200 |
|
907 | MAXNUMX = 200 | |
908 | MAXNUMY = 200 |
|
908 | MAXNUMY = 200 | |
909 |
|
909 | |||
910 |
def __init__(self, code, |
|
910 | def __init__(self, code, exp_code, localtime=True): | |
911 |
|
911 | |||
912 | self.key = code |
|
912 | self.key = code | |
913 | self.throttle = throttle_value |
|
|||
914 | self.exp_code = exp_code |
|
913 | self.exp_code = exp_code | |
915 | self.buffering = buffering |
|
|||
916 | self.ready = False |
|
914 | self.ready = False | |
917 | self.flagNoData = False |
|
915 | self.flagNoData = False | |
918 | self.localtime = localtime |
|
916 | self.localtime = localtime | |
919 | self.data = {} |
|
917 | self.data = {} | |
920 | self.meta = {} |
|
918 | self.meta = {} | |
921 | self.__heights = [] |
|
919 | self.__heights = [] | |
922 |
|
920 | |||
923 | if 'snr' in code: |
|
|||
924 | self.plottypes = ['snr'] |
|
|||
925 | elif code == 'spc': |
|
|||
926 | self.plottypes = ['spc', 'noise', 'rti'] |
|
|||
927 | elif code == 'cspc': |
|
|||
928 | self.plottypes = ['cspc', 'spc', 'noise', 'rti'] |
|
|||
929 | elif code == 'rti': |
|
|||
930 | self.plottypes = ['noise', 'rti'] |
|
|||
931 | else: |
|
|||
932 | self.plottypes = [code] |
|
|||
933 |
|
||||
934 | if 'snr' not in self.plottypes and snr: |
|
|||
935 | self.plottypes.append('snr') |
|
|||
936 |
|
||||
937 | for plot in self.plottypes: |
|
|||
938 | self.data[plot] = {} |
|
|||
939 |
|
||||
940 | def __str__(self): |
|
921 | def __str__(self): | |
941 | dum = ['{}{}'.format(key, self.shape(key)) for key in self.data] |
|
922 | dum = ['{}{}'.format(key, self.shape(key)) for key in self.data] | |
942 | return 'Data[{}][{}]'.format(';'.join(dum), len(self.times)) |
|
923 | return 'Data[{}][{}]'.format(';'.join(dum), len(self.times)) | |
943 |
|
924 | |||
944 | def __len__(self): |
|
925 | def __len__(self): | |
945 |
return len(self.data |
|
926 | return len(self.data) | |
946 |
|
927 | |||
947 | def __getitem__(self, key): |
|
928 | def __getitem__(self, key): | |
948 |
|
929 | if isinstance(key, int): | ||
949 | if key not in self.data: |
|
930 | return self.data[self.times[key]] | |
950 | raise KeyError(log.error('Missing key: {}'.format(key))) |
|
931 | elif isinstance(key, str): | |
951 | if 'spc' in key or not self.buffering: |
|
932 | ret = numpy.array([self.data[x][key] for x in self.times]) | |
952 | ret = self.data[key][self.tm] |
|
|||
953 | elif 'scope' in key: |
|
|||
954 | ret = numpy.array(self.data[key][float(self.tm)]) |
|
|||
955 | else: |
|
|||
956 | ret = numpy.array([self.data[key][x] for x in self.times]) |
|
|||
957 | if ret.ndim > 1: |
|
933 | if ret.ndim > 1: | |
958 | ret = numpy.swapaxes(ret, 0, 1) |
|
934 | ret = numpy.swapaxes(ret, 0, 1) | |
959 | return ret |
|
935 | return ret | |
960 |
|
936 | |||
961 | def __contains__(self, key): |
|
937 | def __contains__(self, key): | |
962 | return key in self.data |
|
938 | return key in self.data[self.min_time] | |
963 |
|
939 | |||
964 | def setup(self): |
|
940 | def setup(self): | |
965 | ''' |
|
941 | ''' | |
966 | Configure object |
|
942 | Configure object | |
967 | ''' |
|
943 | ''' | |
968 | self.type = '' |
|
944 | self.type = '' | |
969 | self.ready = False |
|
945 | self.ready = False | |
970 | del self.data |
|
946 | del self.data | |
971 | self.data = {} |
|
947 | self.data = {} | |
972 | self.__heights = [] |
|
948 | self.__heights = [] | |
973 | self.__all_heights = set() |
|
949 | self.__all_heights = set() | |
974 | for plot in self.plottypes: |
|
|||
975 | if 'snr' in plot: |
|
|||
976 | plot = 'snr' |
|
|||
977 | elif 'spc_moments' == plot: |
|
|||
978 | plot = 'moments' |
|
|||
979 | self.data[plot] = {} |
|
|||
980 |
|
||||
981 | if 'spc' in self.data or 'rti' in self.data or 'cspc' in self.data or 'moments' in self.data: |
|
|||
982 | self.data['noise'] = {} |
|
|||
983 | self.data['rti'] = {} |
|
|||
984 | if 'noise' not in self.plottypes: |
|
|||
985 | self.plottypes.append('noise') |
|
|||
986 | if 'rti' not in self.plottypes: |
|
|||
987 | self.plottypes.append('rti') |
|
|||
988 |
|
950 | |||
989 | def shape(self, key): |
|
951 | def shape(self, key): | |
990 | ''' |
|
952 | ''' | |
991 | Get the shape of the one-element data for the given key |
|
953 | Get the shape of the one-element data for the given key | |
992 | ''' |
|
954 | ''' | |
993 |
|
955 | |||
994 | if len(self.data[key]): |
|
956 | if len(self.data[self.min_time][key]): | |
995 | if 'spc' in key or not self.buffering: |
|
957 | return self.data[self.min_time][key].shape | |
996 | return self.data[key].shape |
|
|||
997 | return self.data[key][self.times[0]].shape |
|
|||
998 | return (0,) |
|
958 | return (0,) | |
999 |
|
959 | |||
1000 |
def update(self, data |
|
960 | def update(self, data, tm, meta={}): | |
1001 | ''' |
|
961 | ''' | |
1002 | Update data object with new dataOut |
|
962 | Update data object with new dataOut | |
1003 | ''' |
|
963 | ''' | |
1004 |
|
964 | |||
1005 | self.profileIndex = dataOut.profileIndex |
|
965 | self.data[tm] = data | |
1006 | self.tm = tm |
|
966 | ||
1007 | self.type = dataOut.type |
|
967 | for key, value in meta.items(): | |
1008 | self.parameters = getattr(dataOut, 'parameters', []) |
|
968 | setattr(self, key, value) | |
1009 |
|
||||
1010 | if hasattr(dataOut, 'meta'): |
|
|||
1011 | self.meta.update(dataOut.meta) |
|
|||
1012 |
|
||||
1013 | if hasattr(dataOut, 'pairsList'): |
|
|||
1014 | self.pairs = dataOut.pairsList |
|
|||
1015 |
|
||||
1016 | self.interval = dataOut.timeInterval |
|
|||
1017 | if True in ['spc' in ptype for ptype in self.plottypes]: |
|
|||
1018 | self.xrange = (dataOut.getFreqRange(1)/1000., |
|
|||
1019 | dataOut.getAcfRange(1), dataOut.getVelRange(1)) |
|
|||
1020 | self.__heights.append(dataOut.heightList) |
|
|||
1021 | self.__all_heights.update(dataOut.heightList) |
|
|||
1022 |
|
||||
1023 | for plot in self.plottypes: |
|
|||
1024 | if plot in ('spc', 'spc_moments', 'spc_cut'): |
|
|||
1025 | z = dataOut.data_spc/dataOut.normFactor |
|
|||
1026 | buffer = 10*numpy.log10(z) |
|
|||
1027 | if plot == 'cspc': |
|
|||
1028 | buffer = (dataOut.data_spc, dataOut.data_cspc) |
|
|||
1029 | if plot == 'noise': |
|
|||
1030 | buffer = 10*numpy.log10(dataOut.getNoise()/dataOut.normFactor) |
|
|||
1031 | if plot in ('rti', 'spcprofile'): |
|
|||
1032 | buffer = dataOut.getPower() |
|
|||
1033 | if plot == 'snr_db': |
|
|||
1034 | buffer = dataOut.data_SNR |
|
|||
1035 | if plot == 'snr': |
|
|||
1036 | buffer = 10*numpy.log10(dataOut.data_SNR) |
|
|||
1037 | if plot == 'dop': |
|
|||
1038 | buffer = dataOut.data_DOP |
|
|||
1039 | if plot == 'pow': |
|
|||
1040 | buffer = 10*numpy.log10(dataOut.data_POW) |
|
|||
1041 | if plot == 'width': |
|
|||
1042 | buffer = dataOut.data_WIDTH |
|
|||
1043 | if plot == 'coh': |
|
|||
1044 | buffer = dataOut.getCoherence() |
|
|||
1045 | if plot == 'phase': |
|
|||
1046 | buffer = dataOut.getCoherence(phase=True) |
|
|||
1047 | if plot == 'output': |
|
|||
1048 | buffer = dataOut.data_output |
|
|||
1049 | if plot == 'param': |
|
|||
1050 | buffer = dataOut.data_param |
|
|||
1051 | if plot == 'scope': |
|
|||
1052 | buffer = dataOut.data |
|
|||
1053 | self.flagDataAsBlock = dataOut.flagDataAsBlock |
|
|||
1054 | self.nProfiles = dataOut.nProfiles |
|
|||
1055 | if plot == 'pp_power': |
|
|||
1056 | buffer = dataOut.dataPP_POWER |
|
|||
1057 | self.flagDataAsBlock = dataOut.flagDataAsBlock |
|
|||
1058 | self.nProfiles = dataOut.nProfiles |
|
|||
1059 | if plot == 'pp_signal': |
|
|||
1060 | buffer = dataOut.dataPP_POW |
|
|||
1061 | self.flagDataAsBlock = dataOut.flagDataAsBlock |
|
|||
1062 | self.nProfiles = dataOut.nProfiles |
|
|||
1063 | if plot == 'pp_velocity': |
|
|||
1064 | buffer = dataOut.dataPP_DOP |
|
|||
1065 | self.flagDataAsBlock = dataOut.flagDataAsBlock |
|
|||
1066 | self.nProfiles = dataOut.nProfiles |
|
|||
1067 | if plot == 'pp_specwidth': |
|
|||
1068 | buffer = dataOut.dataPP_WIDTH |
|
|||
1069 | self.flagDataAsBlock = dataOut.flagDataAsBlock |
|
|||
1070 | self.nProfiles = dataOut.nProfiles |
|
|||
1071 |
|
||||
1072 | if plot == 'spc': |
|
|||
1073 | self.data['spc'][tm] = buffer |
|
|||
1074 | elif plot == 'cspc': |
|
|||
1075 | self.data['cspc'][tm] = buffer |
|
|||
1076 | elif plot == 'spc_moments': |
|
|||
1077 | self.data['spc'][tm] = buffer |
|
|||
1078 | self.data['moments'][tm] = dataOut.moments |
|
|||
1079 | else: |
|
|||
1080 | if self.buffering: |
|
|||
1081 | self.data[plot][tm] = buffer |
|
|||
1082 | else: |
|
|||
1083 | self.data[plot][tm] = buffer |
|
|||
1084 |
|
||||
1085 | if dataOut.channelList is None: |
|
|||
1086 | self.channels = range(buffer.shape[0]) |
|
|||
1087 | else: |
|
|||
1088 | self.channels = dataOut.channelList |
|
|||
1089 |
|
||||
1090 | if buffer is None: |
|
|||
1091 | self.flagNoData = True |
|
|||
1092 | raise schainpy.admin.SchainWarning('Attribute data_{} is empty'.format(self.key)) |
|
|||
1093 |
|
969 | |||
1094 | def normalize_heights(self): |
|
970 | def normalize_heights(self): | |
1095 | ''' |
|
971 | ''' | |
1096 | Ensure same-dimension of the data for different heighList |
|
972 | Ensure same-dimension of the data for different heighList | |
1097 | ''' |
|
973 | ''' | |
1098 |
|
974 | |||
1099 | H = numpy.array(list(self.__all_heights)) |
|
975 | H = numpy.array(list(self.__all_heights)) | |
1100 | H.sort() |
|
976 | H.sort() | |
1101 | for key in self.data: |
|
977 | for key in self.data: | |
1102 | shape = self.shape(key)[:-1] + H.shape |
|
978 | shape = self.shape(key)[:-1] + H.shape | |
1103 | for tm, obj in list(self.data[key].items()): |
|
979 | for tm, obj in list(self.data[key].items()): | |
1104 | h = self.__heights[self.times.tolist().index(tm)] |
|
980 | h = self.__heights[self.times.tolist().index(tm)] | |
1105 | if H.size == h.size: |
|
981 | if H.size == h.size: | |
1106 | continue |
|
982 | continue | |
1107 | index = numpy.where(numpy.in1d(H, h))[0] |
|
983 | index = numpy.where(numpy.in1d(H, h))[0] | |
1108 | dummy = numpy.zeros(shape) + numpy.nan |
|
984 | dummy = numpy.zeros(shape) + numpy.nan | |
1109 | if len(shape) == 2: |
|
985 | if len(shape) == 2: | |
1110 | dummy[:, index] = obj |
|
986 | dummy[:, index] = obj | |
1111 | else: |
|
987 | else: | |
1112 | dummy[index] = obj |
|
988 | dummy[index] = obj | |
1113 | self.data[key][tm] = dummy |
|
989 | self.data[key][tm] = dummy | |
1114 |
|
990 | |||
1115 | self.__heights = [H for tm in self.times] |
|
991 | self.__heights = [H for tm in self.times] | |
1116 |
|
992 | |||
1117 | def jsonify(self, tm, plot_name, plot_type, decimate=False): |
|
993 | def jsonify(self, tm, plot_name, plot_type, decimate=False): | |
1118 | ''' |
|
994 | ''' | |
1119 | Convert data to json |
|
995 | Convert data to json | |
1120 | ''' |
|
996 | ''' | |
1121 |
|
997 | |||
1122 | dy = int(self.heights.size/self.MAXNUMY) + 1 |
|
998 | meta = {} | |
1123 | if self.key in ('spc', 'cspc'): |
|
999 | meta['xrange'] = [] | |
1124 |
|
|
1000 | dy = int(len(self.yrange)/self.MAXNUMY) + 1 | |
|
1001 | tmp = self.data[tm][self.key] | |||
|
1002 | shape = tmp.shape | |||
|
1003 | if len(shape) == 2: | |||
|
1004 | data = self.roundFloats(self.data[tm][self.key][::, ::dy].tolist()) | |||
|
1005 | elif len(shape) == 3: | |||
|
1006 | dx = int(self.data[tm][self.key].shape[1]/self.MAXNUMX) + 1 | |||
1125 | data = self.roundFloats( |
|
1007 | data = self.roundFloats( | |
1126 |
self.data[self.key |
|
1008 | self.data[tm][self.key][::, ::dx, ::dy].tolist()) | |
|
1009 | meta['xrange'] = self.roundFloats(self.xrange[2][::dx].tolist()) | |||
1127 | else: |
|
1010 | else: | |
1128 | if self.key is 'noise': |
|
1011 | data = self.roundFloats(self.data[tm][self.key].tolist()) | |
1129 | data = [[x] for x in self.roundFloats(self.data[self.key][tm].tolist())] |
|
1012 | ||
1130 | else: |
|
|||
1131 | data = self.roundFloats(self.data[self.key][tm][::, ::dy].tolist()) |
|
|||
1132 |
|
||||
1133 | meta = {} |
|
|||
1134 | ret = { |
|
1013 | ret = { | |
1135 | 'plot': plot_name, |
|
1014 | 'plot': plot_name, | |
1136 | 'code': self.exp_code, |
|
1015 | 'code': self.exp_code, | |
1137 | 'time': float(tm), |
|
1016 | 'time': float(tm), | |
1138 | 'data': data, |
|
1017 | 'data': data, | |
1139 | } |
|
1018 | } | |
1140 | meta['type'] = plot_type |
|
1019 | meta['type'] = plot_type | |
1141 | meta['interval'] = float(self.interval) |
|
1020 | meta['interval'] = float(self.interval) | |
1142 | meta['localtime'] = self.localtime |
|
1021 | meta['localtime'] = self.localtime | |
1143 |
meta['yrange'] = self.roundFloats(self. |
|
1022 | meta['yrange'] = self.roundFloats(self.yrange[::dy].tolist()) | |
1144 | if 'spc' in self.data or 'cspc' in self.data: |
|
|||
1145 | meta['xrange'] = self.roundFloats(self.xrange[2][::dx].tolist()) |
|
|||
1146 | else: |
|
|||
1147 | meta['xrange'] = [] |
|
|||
1148 |
|
||||
1149 | meta.update(self.meta) |
|
1023 | meta.update(self.meta) | |
1150 | ret['metadata'] = meta |
|
1024 | ret['metadata'] = meta | |
1151 | return json.dumps(ret) |
|
1025 | return json.dumps(ret) | |
1152 |
|
1026 | |||
1153 | @property |
|
1027 | @property | |
1154 | def times(self): |
|
1028 | def times(self): | |
1155 | ''' |
|
1029 | ''' | |
1156 | Return the list of times of the current data |
|
1030 | Return the list of times of the current data | |
1157 | ''' |
|
1031 | ''' | |
1158 |
|
1032 | |||
1159 |
ret = |
|
1033 | ret = [t for t in self.data] | |
1160 | if self: |
|
1034 | ret.sort() | |
1161 | ret.sort() |
|
1035 | return numpy.array(ret) | |
1162 | return ret |
|
|||
1163 |
|
1036 | |||
1164 | @property |
|
1037 | @property | |
1165 | def min_time(self): |
|
1038 | def min_time(self): | |
1166 | ''' |
|
1039 | ''' | |
1167 | Return the minimun time value |
|
1040 | Return the minimun time value | |
1168 | ''' |
|
1041 | ''' | |
1169 |
|
1042 | |||
1170 | return self.times[0] |
|
1043 | return self.times[0] | |
1171 |
|
1044 | |||
1172 | @property |
|
1045 | @property | |
1173 | def max_time(self): |
|
1046 | def max_time(self): | |
1174 | ''' |
|
1047 | ''' | |
1175 | Return the maximun time value |
|
1048 | Return the maximun time value | |
1176 | ''' |
|
1049 | ''' | |
1177 |
|
1050 | |||
1178 | return self.times[-1] |
|
1051 | return self.times[-1] | |
1179 |
|
1052 | |||
1180 | @property |
|
1053 | # @property | |
1181 | def heights(self): |
|
1054 | # def heights(self): | |
1182 | ''' |
|
1055 | # ''' | |
1183 | Return the list of heights of the current data |
|
1056 | # Return the list of heights of the current data | |
1184 |
|
|
1057 | # ''' | |
1185 |
|
1058 | |||
1186 | return numpy.array(self.__heights[-1]) |
|
1059 | # return numpy.array(self.__heights[-1]) | |
1187 |
|
1060 | |||
1188 | @staticmethod |
|
1061 | @staticmethod | |
1189 | def roundFloats(obj): |
|
1062 | def roundFloats(obj): | |
1190 | if isinstance(obj, list): |
|
1063 | if isinstance(obj, list): | |
1191 | return list(map(PlotterData.roundFloats, obj)) |
|
1064 | return list(map(PlotterData.roundFloats, obj)) | |
1192 | elif isinstance(obj, float): |
|
1065 | elif isinstance(obj, float): | |
1193 | return round(obj, 2) |
|
1066 | return round(obj, 2) |
@@ -1,906 +1,906 | |||||
1 | ''' |
|
1 | ''' | |
2 |
|
2 | |||
3 | $Author: murco $ |
|
3 | $Author: murco $ | |
4 | $Id: JROHeaderIO.py 151 2012-10-31 19:00:51Z murco $ |
|
4 | $Id: JROHeaderIO.py 151 2012-10-31 19:00:51Z murco $ | |
5 | ''' |
|
5 | ''' | |
6 | import sys |
|
6 | import sys | |
7 | import numpy |
|
7 | import numpy | |
8 | import copy |
|
8 | import copy | |
9 | import datetime |
|
9 | import datetime | |
10 | import inspect |
|
10 | import inspect | |
11 | from schainpy.utils import log |
|
11 | from schainpy.utils import log | |
12 |
|
12 | |||
13 | SPEED_OF_LIGHT = 299792458 |
|
13 | SPEED_OF_LIGHT = 299792458 | |
14 | SPEED_OF_LIGHT = 3e8 |
|
14 | SPEED_OF_LIGHT = 3e8 | |
15 |
|
15 | |||
16 | BASIC_STRUCTURE = numpy.dtype([ |
|
16 | BASIC_STRUCTURE = numpy.dtype([ | |
17 | ('nSize', '<u4'), |
|
17 | ('nSize', '<u4'), | |
18 | ('nVersion', '<u2'), |
|
18 | ('nVersion', '<u2'), | |
19 | ('nDataBlockId', '<u4'), |
|
19 | ('nDataBlockId', '<u4'), | |
20 | ('nUtime', '<u4'), |
|
20 | ('nUtime', '<u4'), | |
21 | ('nMilsec', '<u2'), |
|
21 | ('nMilsec', '<u2'), | |
22 | ('nTimezone', '<i2'), |
|
22 | ('nTimezone', '<i2'), | |
23 | ('nDstflag', '<i2'), |
|
23 | ('nDstflag', '<i2'), | |
24 | ('nErrorCount', '<u4') |
|
24 | ('nErrorCount', '<u4') | |
25 | ]) |
|
25 | ]) | |
26 |
|
26 | |||
27 | SYSTEM_STRUCTURE = numpy.dtype([ |
|
27 | SYSTEM_STRUCTURE = numpy.dtype([ | |
28 | ('nSize', '<u4'), |
|
28 | ('nSize', '<u4'), | |
29 | ('nNumSamples', '<u4'), |
|
29 | ('nNumSamples', '<u4'), | |
30 | ('nNumProfiles', '<u4'), |
|
30 | ('nNumProfiles', '<u4'), | |
31 | ('nNumChannels', '<u4'), |
|
31 | ('nNumChannels', '<u4'), | |
32 | ('nADCResolution', '<u4'), |
|
32 | ('nADCResolution', '<u4'), | |
33 | ('nPCDIOBusWidth', '<u4'), |
|
33 | ('nPCDIOBusWidth', '<u4'), | |
34 | ]) |
|
34 | ]) | |
35 |
|
35 | |||
36 | RADAR_STRUCTURE = numpy.dtype([ |
|
36 | RADAR_STRUCTURE = numpy.dtype([ | |
37 | ('nSize', '<u4'), |
|
37 | ('nSize', '<u4'), | |
38 | ('nExpType', '<u4'), |
|
38 | ('nExpType', '<u4'), | |
39 | ('nNTx', '<u4'), |
|
39 | ('nNTx', '<u4'), | |
40 | ('fIpp', '<f4'), |
|
40 | ('fIpp', '<f4'), | |
41 | ('fTxA', '<f4'), |
|
41 | ('fTxA', '<f4'), | |
42 | ('fTxB', '<f4'), |
|
42 | ('fTxB', '<f4'), | |
43 | ('nNumWindows', '<u4'), |
|
43 | ('nNumWindows', '<u4'), | |
44 | ('nNumTaus', '<u4'), |
|
44 | ('nNumTaus', '<u4'), | |
45 | ('nCodeType', '<u4'), |
|
45 | ('nCodeType', '<u4'), | |
46 | ('nLine6Function', '<u4'), |
|
46 | ('nLine6Function', '<u4'), | |
47 | ('nLine5Function', '<u4'), |
|
47 | ('nLine5Function', '<u4'), | |
48 | ('fClock', '<f4'), |
|
48 | ('fClock', '<f4'), | |
49 | ('nPrePulseBefore', '<u4'), |
|
49 | ('nPrePulseBefore', '<u4'), | |
50 | ('nPrePulseAfter', '<u4'), |
|
50 | ('nPrePulseAfter', '<u4'), | |
51 | ('sRangeIPP', '<a20'), |
|
51 | ('sRangeIPP', '<a20'), | |
52 | ('sRangeTxA', '<a20'), |
|
52 | ('sRangeTxA', '<a20'), | |
53 | ('sRangeTxB', '<a20'), |
|
53 | ('sRangeTxB', '<a20'), | |
54 | ]) |
|
54 | ]) | |
55 |
|
55 | |||
56 | SAMPLING_STRUCTURE = numpy.dtype( |
|
56 | SAMPLING_STRUCTURE = numpy.dtype( | |
57 | [('h0', '<f4'), ('dh', '<f4'), ('nsa', '<u4')]) |
|
57 | [('h0', '<f4'), ('dh', '<f4'), ('nsa', '<u4')]) | |
58 |
|
58 | |||
59 |
|
59 | |||
60 | PROCESSING_STRUCTURE = numpy.dtype([ |
|
60 | PROCESSING_STRUCTURE = numpy.dtype([ | |
61 | ('nSize', '<u4'), |
|
61 | ('nSize', '<u4'), | |
62 | ('nDataType', '<u4'), |
|
62 | ('nDataType', '<u4'), | |
63 | ('nSizeOfDataBlock', '<u4'), |
|
63 | ('nSizeOfDataBlock', '<u4'), | |
64 | ('nProfilesperBlock', '<u4'), |
|
64 | ('nProfilesperBlock', '<u4'), | |
65 | ('nDataBlocksperFile', '<u4'), |
|
65 | ('nDataBlocksperFile', '<u4'), | |
66 | ('nNumWindows', '<u4'), |
|
66 | ('nNumWindows', '<u4'), | |
67 | ('nProcessFlags', '<u4'), |
|
67 | ('nProcessFlags', '<u4'), | |
68 | ('nCoherentIntegrations', '<u4'), |
|
68 | ('nCoherentIntegrations', '<u4'), | |
69 | ('nIncoherentIntegrations', '<u4'), |
|
69 | ('nIncoherentIntegrations', '<u4'), | |
70 | ('nTotalSpectra', '<u4') |
|
70 | ('nTotalSpectra', '<u4') | |
71 | ]) |
|
71 | ]) | |
72 |
|
72 | |||
73 |
|
73 | |||
74 | class Header(object): |
|
74 | class Header(object): | |
75 |
|
75 | |||
76 | def __init__(self): |
|
76 | def __init__(self): | |
77 | raise NotImplementedError |
|
77 | raise NotImplementedError | |
78 |
|
78 | |||
79 | def copy(self): |
|
79 | def copy(self): | |
80 | return copy.deepcopy(self) |
|
80 | return copy.deepcopy(self) | |
81 |
|
81 | |||
82 | def read(self): |
|
82 | def read(self): | |
83 |
|
83 | |||
84 | raise NotImplementedError |
|
84 | raise NotImplementedError | |
85 |
|
85 | |||
86 | def write(self): |
|
86 | def write(self): | |
87 |
|
87 | |||
88 | raise NotImplementedError |
|
88 | raise NotImplementedError | |
89 |
|
89 | |||
90 | def getAllowedArgs(self): |
|
90 | def getAllowedArgs(self): | |
91 | args = inspect.getargspec(self.__init__).args |
|
91 | args = inspect.getargspec(self.__init__).args | |
92 | try: |
|
92 | try: | |
93 | args.remove('self') |
|
93 | args.remove('self') | |
94 | except: |
|
94 | except: | |
95 | pass |
|
95 | pass | |
96 | return args |
|
96 | return args | |
97 |
|
97 | |||
98 | def getAsDict(self): |
|
98 | def getAsDict(self): | |
99 | args = self.getAllowedArgs() |
|
99 | args = self.getAllowedArgs() | |
100 | asDict = {} |
|
100 | asDict = {} | |
101 | for x in args: |
|
101 | for x in args: | |
102 | asDict[x] = self[x] |
|
102 | asDict[x] = self[x] | |
103 | return asDict |
|
103 | return asDict | |
104 |
|
104 | |||
105 | def __getitem__(self, name): |
|
105 | def __getitem__(self, name): | |
106 | return getattr(self, name) |
|
106 | return getattr(self, name) | |
107 |
|
107 | |||
108 | def printInfo(self): |
|
108 | def printInfo(self): | |
109 |
|
109 | |||
110 | message = "#" * 50 + "\n" |
|
110 | message = "#" * 50 + "\n" | |
111 | message += self.__class__.__name__.upper() + "\n" |
|
111 | message += self.__class__.__name__.upper() + "\n" | |
112 | message += "#" * 50 + "\n" |
|
112 | message += "#" * 50 + "\n" | |
113 |
|
113 | |||
114 | keyList = list(self.__dict__.keys()) |
|
114 | keyList = list(self.__dict__.keys()) | |
115 | keyList.sort() |
|
115 | keyList.sort() | |
116 |
|
116 | |||
117 | for key in keyList: |
|
117 | for key in keyList: | |
118 | message += "%s = %s" % (key, self.__dict__[key]) + "\n" |
|
118 | message += "%s = %s" % (key, self.__dict__[key]) + "\n" | |
119 |
|
119 | |||
120 | if "size" not in keyList: |
|
120 | if "size" not in keyList: | |
121 | attr = getattr(self, "size") |
|
121 | attr = getattr(self, "size") | |
122 |
|
122 | |||
123 | if attr: |
|
123 | if attr: | |
124 | message += "%s = %s" % ("size", attr) + "\n" |
|
124 | message += "%s = %s" % ("size", attr) + "\n" | |
125 |
|
125 | |||
126 | print(message) |
|
126 | print(message) | |
127 |
|
127 | |||
128 |
|
128 | |||
129 | class BasicHeader(Header): |
|
129 | class BasicHeader(Header): | |
130 |
|
130 | |||
131 | size = None |
|
131 | size = None | |
132 | version = None |
|
132 | version = None | |
133 | dataBlock = None |
|
133 | dataBlock = None | |
134 | utc = None |
|
134 | utc = None | |
135 | ltc = None |
|
135 | ltc = None | |
136 | miliSecond = None |
|
136 | miliSecond = None | |
137 | timeZone = None |
|
137 | timeZone = None | |
138 | dstFlag = None |
|
138 | dstFlag = None | |
139 | errorCount = None |
|
139 | errorCount = None | |
140 | datatime = None |
|
140 | datatime = None | |
141 | structure = BASIC_STRUCTURE |
|
141 | structure = BASIC_STRUCTURE | |
142 | __LOCALTIME = None |
|
142 | __LOCALTIME = None | |
143 |
|
143 | |||
144 | def __init__(self, useLocalTime=True): |
|
144 | def __init__(self, useLocalTime=True): | |
145 |
|
145 | |||
146 | self.size = 24 |
|
146 | self.size = 24 | |
147 | self.version = 0 |
|
147 | self.version = 0 | |
148 | self.dataBlock = 0 |
|
148 | self.dataBlock = 0 | |
149 | self.utc = 0 |
|
149 | self.utc = 0 | |
150 | self.miliSecond = 0 |
|
150 | self.miliSecond = 0 | |
151 | self.timeZone = 0 |
|
151 | self.timeZone = 0 | |
152 | self.dstFlag = 0 |
|
152 | self.dstFlag = 0 | |
153 | self.errorCount = 0 |
|
153 | self.errorCount = 0 | |
154 |
|
154 | |||
155 | self.useLocalTime = useLocalTime |
|
155 | self.useLocalTime = useLocalTime | |
156 |
|
156 | |||
157 | def read(self, fp): |
|
157 | def read(self, fp): | |
158 |
|
158 | |||
159 | self.length = 0 |
|
159 | self.length = 0 | |
160 | try: |
|
160 | try: | |
161 | if hasattr(fp, 'read'): |
|
161 | if hasattr(fp, 'read'): | |
162 | header = numpy.fromfile(fp, BASIC_STRUCTURE, 1) |
|
162 | header = numpy.fromfile(fp, BASIC_STRUCTURE, 1) | |
163 | else: |
|
163 | else: | |
164 | header = numpy.fromstring(fp, BASIC_STRUCTURE, 1) |
|
164 | header = numpy.fromstring(fp, BASIC_STRUCTURE, 1) | |
165 | except Exception as e: |
|
165 | except Exception as e: | |
166 | print("BasicHeader: ") |
|
166 | print("BasicHeader: ") | |
167 | print(e) |
|
167 | print(e) | |
168 | return 0 |
|
168 | return 0 | |
169 |
|
169 | |||
170 | self.size = int(header['nSize'][0]) |
|
170 | self.size = int(header['nSize'][0]) | |
171 | self.version = int(header['nVersion'][0]) |
|
171 | self.version = int(header['nVersion'][0]) | |
172 | self.dataBlock = int(header['nDataBlockId'][0]) |
|
172 | self.dataBlock = int(header['nDataBlockId'][0]) | |
173 | self.utc = int(header['nUtime'][0]) |
|
173 | self.utc = int(header['nUtime'][0]) | |
174 | self.miliSecond = int(header['nMilsec'][0]) |
|
174 | self.miliSecond = int(header['nMilsec'][0]) | |
175 | self.timeZone = int(header['nTimezone'][0]) |
|
175 | self.timeZone = int(header['nTimezone'][0]) | |
176 | self.dstFlag = int(header['nDstflag'][0]) |
|
176 | self.dstFlag = int(header['nDstflag'][0]) | |
177 | self.errorCount = int(header['nErrorCount'][0]) |
|
177 | self.errorCount = int(header['nErrorCount'][0]) | |
178 |
|
178 | |||
179 | if self.size < 24: |
|
179 | if self.size < 24: | |
180 | return 0 |
|
180 | return 0 | |
181 |
|
181 | |||
182 | self.length = header.nbytes |
|
182 | self.length = header.nbytes | |
183 | return 1 |
|
183 | return 1 | |
184 |
|
184 | |||
185 | def write(self, fp): |
|
185 | def write(self, fp): | |
186 |
|
186 | |||
187 | headerTuple = (self.size, self.version, self.dataBlock, self.utc, |
|
187 | headerTuple = (self.size, self.version, self.dataBlock, self.utc, | |
188 | self.miliSecond, self.timeZone, self.dstFlag, self.errorCount) |
|
188 | self.miliSecond, self.timeZone, self.dstFlag, self.errorCount) | |
189 | header = numpy.array(headerTuple, BASIC_STRUCTURE) |
|
189 | header = numpy.array(headerTuple, BASIC_STRUCTURE) | |
190 | header.tofile(fp) |
|
190 | header.tofile(fp) | |
191 |
|
191 | |||
192 | return 1 |
|
192 | return 1 | |
193 |
|
193 | |||
194 | def get_ltc(self): |
|
194 | def get_ltc(self): | |
195 |
|
195 | |||
196 | return self.utc - self.timeZone * 60 |
|
196 | return self.utc - self.timeZone * 60 | |
197 |
|
197 | |||
198 | def set_ltc(self, value): |
|
198 | def set_ltc(self, value): | |
199 |
|
199 | |||
200 | self.utc = value + self.timeZone * 60 |
|
200 | self.utc = value + self.timeZone * 60 | |
201 |
|
201 | |||
202 | def get_datatime(self): |
|
202 | def get_datatime(self): | |
203 |
|
203 | |||
204 | return datetime.datetime.utcfromtimestamp(self.ltc) |
|
204 | return datetime.datetime.utcfromtimestamp(self.ltc) | |
205 |
|
205 | |||
206 | ltc = property(get_ltc, set_ltc) |
|
206 | ltc = property(get_ltc, set_ltc) | |
207 | datatime = property(get_datatime) |
|
207 | datatime = property(get_datatime) | |
208 |
|
208 | |||
209 |
|
209 | |||
210 | class SystemHeader(Header): |
|
210 | class SystemHeader(Header): | |
211 |
|
211 | |||
212 | size = None |
|
212 | size = None | |
213 | nSamples = None |
|
213 | nSamples = None | |
214 | nProfiles = None |
|
214 | nProfiles = None | |
215 | nChannels = None |
|
215 | nChannels = None | |
216 | adcResolution = None |
|
216 | adcResolution = None | |
217 | pciDioBusWidth = None |
|
217 | pciDioBusWidth = None | |
218 | structure = SYSTEM_STRUCTURE |
|
218 | structure = SYSTEM_STRUCTURE | |
219 |
|
219 | |||
220 | def __init__(self, nSamples=0, nProfiles=0, nChannels=0, adcResolution=14, pciDioBusWidth=0): |
|
220 | def __init__(self, nSamples=0, nProfiles=0, nChannels=0, adcResolution=14, pciDioBusWidth=0): | |
221 |
|
221 | |||
222 | self.size = 24 |
|
222 | self.size = 24 | |
223 | self.nSamples = nSamples |
|
223 | self.nSamples = nSamples | |
224 | self.nProfiles = nProfiles |
|
224 | self.nProfiles = nProfiles | |
225 | self.nChannels = nChannels |
|
225 | self.nChannels = nChannels | |
226 | self.adcResolution = adcResolution |
|
226 | self.adcResolution = adcResolution | |
227 | self.pciDioBusWidth = pciDioBusWidth |
|
227 | self.pciDioBusWidth = pciDioBusWidth | |
228 |
|
228 | |||
229 | def read(self, fp): |
|
229 | def read(self, fp): | |
230 | self.length = 0 |
|
230 | self.length = 0 | |
231 | try: |
|
231 | try: | |
232 | startFp = fp.tell() |
|
232 | startFp = fp.tell() | |
233 | except Exception as e: |
|
233 | except Exception as e: | |
234 | startFp = None |
|
234 | startFp = None | |
235 | pass |
|
235 | pass | |
236 |
|
236 | |||
237 | try: |
|
237 | try: | |
238 | if hasattr(fp, 'read'): |
|
238 | if hasattr(fp, 'read'): | |
239 | header = numpy.fromfile(fp, SYSTEM_STRUCTURE, 1) |
|
239 | header = numpy.fromfile(fp, SYSTEM_STRUCTURE, 1) | |
240 | else: |
|
240 | else: | |
241 | header = numpy.fromstring(fp, SYSTEM_STRUCTURE, 1) |
|
241 | header = numpy.fromstring(fp, SYSTEM_STRUCTURE, 1) | |
242 | except Exception as e: |
|
242 | except Exception as e: | |
243 | print("System Header: " + str(e)) |
|
243 | print("System Header: " + str(e)) | |
244 | return 0 |
|
244 | return 0 | |
245 |
|
245 | |||
246 | self.size = header['nSize'][0] |
|
246 | self.size = header['nSize'][0] | |
247 | self.nSamples = header['nNumSamples'][0] |
|
247 | self.nSamples = header['nNumSamples'][0] | |
248 | self.nProfiles = header['nNumProfiles'][0] |
|
248 | self.nProfiles = header['nNumProfiles'][0] | |
249 | self.nChannels = header['nNumChannels'][0] |
|
249 | self.nChannels = header['nNumChannels'][0] | |
250 | self.adcResolution = header['nADCResolution'][0] |
|
250 | self.adcResolution = header['nADCResolution'][0] | |
251 | self.pciDioBusWidth = header['nPCDIOBusWidth'][0] |
|
251 | self.pciDioBusWidth = header['nPCDIOBusWidth'][0] | |
252 |
|
252 | |||
253 | if startFp is not None: |
|
253 | if startFp is not None: | |
254 | endFp = self.size + startFp |
|
254 | endFp = self.size + startFp | |
255 |
|
255 | |||
256 | if fp.tell() > endFp: |
|
256 | if fp.tell() > endFp: | |
257 | sys.stderr.write( |
|
257 | sys.stderr.write( | |
258 | "Warning %s: Size value read from System Header is lower than it has to be\n" % fp.name) |
|
258 | "Warning %s: Size value read from System Header is lower than it has to be\n" % fp.name) | |
259 | return 0 |
|
259 | return 0 | |
260 |
|
260 | |||
261 | if fp.tell() < endFp: |
|
261 | if fp.tell() < endFp: | |
262 | sys.stderr.write( |
|
262 | sys.stderr.write( | |
263 | "Warning %s: Size value read from System Header size is greater than it has to be\n" % fp.name) |
|
263 | "Warning %s: Size value read from System Header size is greater than it has to be\n" % fp.name) | |
264 | return 0 |
|
264 | return 0 | |
265 |
|
265 | |||
266 | self.length = header.nbytes |
|
266 | self.length = header.nbytes | |
267 | return 1 |
|
267 | return 1 | |
268 |
|
268 | |||
269 | def write(self, fp): |
|
269 | def write(self, fp): | |
270 |
|
270 | |||
271 | headerTuple = (self.size, self.nSamples, self.nProfiles, |
|
271 | headerTuple = (self.size, self.nSamples, self.nProfiles, | |
272 | self.nChannels, self.adcResolution, self.pciDioBusWidth) |
|
272 | self.nChannels, self.adcResolution, self.pciDioBusWidth) | |
273 | header = numpy.array(headerTuple, SYSTEM_STRUCTURE) |
|
273 | header = numpy.array(headerTuple, SYSTEM_STRUCTURE) | |
274 | header.tofile(fp) |
|
274 | header.tofile(fp) | |
275 |
|
275 | |||
276 | return 1 |
|
276 | return 1 | |
277 |
|
277 | |||
278 |
|
278 | |||
279 | class RadarControllerHeader(Header): |
|
279 | class RadarControllerHeader(Header): | |
280 |
|
280 | |||
281 | expType = None |
|
281 | expType = None | |
282 | nTx = None |
|
282 | nTx = None | |
283 | ipp = None |
|
283 | ipp = None | |
284 | txA = None |
|
284 | txA = None | |
285 | txB = None |
|
285 | txB = None | |
286 | nWindows = None |
|
286 | nWindows = None | |
287 | numTaus = None |
|
287 | numTaus = None | |
288 | codeType = None |
|
288 | codeType = None | |
289 | line6Function = None |
|
289 | line6Function = None | |
290 | line5Function = None |
|
290 | line5Function = None | |
291 | fClock = None |
|
291 | fClock = None | |
292 | prePulseBefore = None |
|
292 | prePulseBefore = None | |
293 | prePulseAfter = None |
|
293 | prePulseAfter = None | |
294 | rangeIpp = None |
|
294 | rangeIpp = None | |
295 | rangeTxA = None |
|
295 | rangeTxA = None | |
296 | rangeTxB = None |
|
296 | rangeTxB = None | |
297 | structure = RADAR_STRUCTURE |
|
297 | structure = RADAR_STRUCTURE | |
298 | __size = None |
|
298 | __size = None | |
299 |
|
299 | |||
300 | def __init__(self, expType=2, nTx=1, |
|
300 | def __init__(self, expType=2, nTx=1, | |
301 | ipp=None, txA=0, txB=0, |
|
301 | ipp=None, txA=0, txB=0, | |
302 | nWindows=None, nHeights=None, firstHeight=None, deltaHeight=None, |
|
302 | nWindows=None, nHeights=None, firstHeight=None, deltaHeight=None, | |
303 | numTaus=0, line6Function=0, line5Function=0, fClock=None, |
|
303 | numTaus=0, line6Function=0, line5Function=0, fClock=None, | |
304 | prePulseBefore=0, prePulseAfter=0, |
|
304 | prePulseBefore=0, prePulseAfter=0, | |
305 |
codeType=0, nCode=0, nBaud=0, code= |
|
305 | codeType=0, nCode=0, nBaud=0, code=[], | |
306 | flip1=0, flip2=0): |
|
306 | flip1=0, flip2=0): | |
307 |
|
307 | |||
308 | # self.size = 116 |
|
308 | # self.size = 116 | |
309 | self.expType = expType |
|
309 | self.expType = expType | |
310 | self.nTx = nTx |
|
310 | self.nTx = nTx | |
311 | self.ipp = ipp |
|
311 | self.ipp = ipp | |
312 | self.txA = txA |
|
312 | self.txA = txA | |
313 | self.txB = txB |
|
313 | self.txB = txB | |
314 | self.rangeIpp = ipp |
|
314 | self.rangeIpp = ipp | |
315 | self.rangeTxA = txA |
|
315 | self.rangeTxA = txA | |
316 | self.rangeTxB = txB |
|
316 | self.rangeTxB = txB | |
317 |
|
317 | |||
318 | self.nWindows = nWindows |
|
318 | self.nWindows = nWindows | |
319 | self.numTaus = numTaus |
|
319 | self.numTaus = numTaus | |
320 | self.codeType = codeType |
|
320 | self.codeType = codeType | |
321 | self.line6Function = line6Function |
|
321 | self.line6Function = line6Function | |
322 | self.line5Function = line5Function |
|
322 | self.line5Function = line5Function | |
323 | self.fClock = fClock |
|
323 | self.fClock = fClock | |
324 | self.prePulseBefore = prePulseBefore |
|
324 | self.prePulseBefore = prePulseBefore | |
325 | self.prePulseAfter = prePulseAfter |
|
325 | self.prePulseAfter = prePulseAfter | |
326 |
|
326 | |||
327 | self.nHeights = nHeights |
|
327 | self.nHeights = nHeights | |
328 | self.firstHeight = firstHeight |
|
328 | self.firstHeight = firstHeight | |
329 | self.deltaHeight = deltaHeight |
|
329 | self.deltaHeight = deltaHeight | |
330 | self.samplesWin = nHeights |
|
330 | self.samplesWin = nHeights | |
331 |
|
331 | |||
332 | self.nCode = nCode |
|
332 | self.nCode = nCode | |
333 | self.nBaud = nBaud |
|
333 | self.nBaud = nBaud | |
334 | self.code = code |
|
334 | self.code = code | |
335 | self.flip1 = flip1 |
|
335 | self.flip1 = flip1 | |
336 | self.flip2 = flip2 |
|
336 | self.flip2 = flip2 | |
337 |
|
337 | |||
338 | self.code_size = int(numpy.ceil(self.nBaud / 32.)) * self.nCode * 4 |
|
338 | self.code_size = int(numpy.ceil(self.nBaud / 32.)) * self.nCode * 4 | |
339 | # self.dynamic = numpy.array([],numpy.dtype('byte')) |
|
339 | # self.dynamic = numpy.array([],numpy.dtype('byte')) | |
340 |
|
340 | |||
341 | if self.fClock is None and self.deltaHeight is not None: |
|
341 | if self.fClock is None and self.deltaHeight is not None: | |
342 | self.fClock = 0.15 / (deltaHeight * 1e-6) # 0.15Km / (height * 1u) |
|
342 | self.fClock = 0.15 / (deltaHeight * 1e-6) # 0.15Km / (height * 1u) | |
343 |
|
343 | |||
344 | def read(self, fp): |
|
344 | def read(self, fp): | |
345 | self.length = 0 |
|
345 | self.length = 0 | |
346 | try: |
|
346 | try: | |
347 | startFp = fp.tell() |
|
347 | startFp = fp.tell() | |
348 | except Exception as e: |
|
348 | except Exception as e: | |
349 | startFp = None |
|
349 | startFp = None | |
350 | pass |
|
350 | pass | |
351 |
|
351 | |||
352 | try: |
|
352 | try: | |
353 | if hasattr(fp, 'read'): |
|
353 | if hasattr(fp, 'read'): | |
354 | header = numpy.fromfile(fp, RADAR_STRUCTURE, 1) |
|
354 | header = numpy.fromfile(fp, RADAR_STRUCTURE, 1) | |
355 | else: |
|
355 | else: | |
356 | header = numpy.fromstring(fp, RADAR_STRUCTURE, 1) |
|
356 | header = numpy.fromstring(fp, RADAR_STRUCTURE, 1) | |
357 | self.length += header.nbytes |
|
357 | self.length += header.nbytes | |
358 | except Exception as e: |
|
358 | except Exception as e: | |
359 | print("RadarControllerHeader: " + str(e)) |
|
359 | print("RadarControllerHeader: " + str(e)) | |
360 | return 0 |
|
360 | return 0 | |
361 |
|
361 | |||
362 | size = int(header['nSize'][0]) |
|
362 | size = int(header['nSize'][0]) | |
363 | self.expType = int(header['nExpType'][0]) |
|
363 | self.expType = int(header['nExpType'][0]) | |
364 | self.nTx = int(header['nNTx'][0]) |
|
364 | self.nTx = int(header['nNTx'][0]) | |
365 | self.ipp = float(header['fIpp'][0]) |
|
365 | self.ipp = float(header['fIpp'][0]) | |
366 | self.txA = float(header['fTxA'][0]) |
|
366 | self.txA = float(header['fTxA'][0]) | |
367 | self.txB = float(header['fTxB'][0]) |
|
367 | self.txB = float(header['fTxB'][0]) | |
368 | self.nWindows = int(header['nNumWindows'][0]) |
|
368 | self.nWindows = int(header['nNumWindows'][0]) | |
369 | self.numTaus = int(header['nNumTaus'][0]) |
|
369 | self.numTaus = int(header['nNumTaus'][0]) | |
370 | self.codeType = int(header['nCodeType'][0]) |
|
370 | self.codeType = int(header['nCodeType'][0]) | |
371 | self.line6Function = int(header['nLine6Function'][0]) |
|
371 | self.line6Function = int(header['nLine6Function'][0]) | |
372 | self.line5Function = int(header['nLine5Function'][0]) |
|
372 | self.line5Function = int(header['nLine5Function'][0]) | |
373 | self.fClock = float(header['fClock'][0]) |
|
373 | self.fClock = float(header['fClock'][0]) | |
374 | self.prePulseBefore = int(header['nPrePulseBefore'][0]) |
|
374 | self.prePulseBefore = int(header['nPrePulseBefore'][0]) | |
375 | self.prePulseAfter = int(header['nPrePulseAfter'][0]) |
|
375 | self.prePulseAfter = int(header['nPrePulseAfter'][0]) | |
376 | self.rangeIpp = header['sRangeIPP'][0] |
|
376 | self.rangeIpp = header['sRangeIPP'][0] | |
377 | self.rangeTxA = header['sRangeTxA'][0] |
|
377 | self.rangeTxA = header['sRangeTxA'][0] | |
378 | self.rangeTxB = header['sRangeTxB'][0] |
|
378 | self.rangeTxB = header['sRangeTxB'][0] | |
379 |
|
379 | |||
380 | try: |
|
380 | try: | |
381 | if hasattr(fp, 'read'): |
|
381 | if hasattr(fp, 'read'): | |
382 | samplingWindow = numpy.fromfile( |
|
382 | samplingWindow = numpy.fromfile( | |
383 | fp, SAMPLING_STRUCTURE, self.nWindows) |
|
383 | fp, SAMPLING_STRUCTURE, self.nWindows) | |
384 | else: |
|
384 | else: | |
385 | samplingWindow = numpy.fromstring( |
|
385 | samplingWindow = numpy.fromstring( | |
386 | fp[self.length:], SAMPLING_STRUCTURE, self.nWindows) |
|
386 | fp[self.length:], SAMPLING_STRUCTURE, self.nWindows) | |
387 | self.length += samplingWindow.nbytes |
|
387 | self.length += samplingWindow.nbytes | |
388 | except Exception as e: |
|
388 | except Exception as e: | |
389 | print("RadarControllerHeader: " + str(e)) |
|
389 | print("RadarControllerHeader: " + str(e)) | |
390 | return 0 |
|
390 | return 0 | |
391 | self.nHeights = int(numpy.sum(samplingWindow['nsa'])) |
|
391 | self.nHeights = int(numpy.sum(samplingWindow['nsa'])) | |
392 | self.firstHeight = samplingWindow['h0'] |
|
392 | self.firstHeight = samplingWindow['h0'] | |
393 | self.deltaHeight = samplingWindow['dh'] |
|
393 | self.deltaHeight = samplingWindow['dh'] | |
394 | self.samplesWin = samplingWindow['nsa'] |
|
394 | self.samplesWin = samplingWindow['nsa'] | |
395 |
|
395 | |||
396 | try: |
|
396 | try: | |
397 | if hasattr(fp, 'read'): |
|
397 | if hasattr(fp, 'read'): | |
398 | self.Taus = numpy.fromfile(fp, '<f4', self.numTaus) |
|
398 | self.Taus = numpy.fromfile(fp, '<f4', self.numTaus) | |
399 | else: |
|
399 | else: | |
400 | self.Taus = numpy.fromstring( |
|
400 | self.Taus = numpy.fromstring( | |
401 | fp[self.length:], '<f4', self.numTaus) |
|
401 | fp[self.length:], '<f4', self.numTaus) | |
402 | self.length += self.Taus.nbytes |
|
402 | self.length += self.Taus.nbytes | |
403 | except Exception as e: |
|
403 | except Exception as e: | |
404 | print("RadarControllerHeader: " + str(e)) |
|
404 | print("RadarControllerHeader: " + str(e)) | |
405 | return 0 |
|
405 | return 0 | |
406 |
|
406 | |||
407 | self.code_size = 0 |
|
407 | self.code_size = 0 | |
408 | if self.codeType != 0: |
|
408 | if self.codeType != 0: | |
409 |
|
409 | |||
410 | try: |
|
410 | try: | |
411 | if hasattr(fp, 'read'): |
|
411 | if hasattr(fp, 'read'): | |
412 | self.nCode = numpy.fromfile(fp, '<u4', 1)[0] |
|
412 | self.nCode = numpy.fromfile(fp, '<u4', 1)[0] | |
413 | self.length += self.nCode.nbytes |
|
413 | self.length += self.nCode.nbytes | |
414 | self.nBaud = numpy.fromfile(fp, '<u4', 1)[0] |
|
414 | self.nBaud = numpy.fromfile(fp, '<u4', 1)[0] | |
415 | self.length += self.nBaud.nbytes |
|
415 | self.length += self.nBaud.nbytes | |
416 | else: |
|
416 | else: | |
417 | self.nCode = numpy.fromstring( |
|
417 | self.nCode = numpy.fromstring( | |
418 | fp[self.length:], '<u4', 1)[0] |
|
418 | fp[self.length:], '<u4', 1)[0] | |
419 | self.length += self.nCode.nbytes |
|
419 | self.length += self.nCode.nbytes | |
420 | self.nBaud = numpy.fromstring( |
|
420 | self.nBaud = numpy.fromstring( | |
421 | fp[self.length:], '<u4', 1)[0] |
|
421 | fp[self.length:], '<u4', 1)[0] | |
422 | self.length += self.nBaud.nbytes |
|
422 | self.length += self.nBaud.nbytes | |
423 | except Exception as e: |
|
423 | except Exception as e: | |
424 | print("RadarControllerHeader: " + str(e)) |
|
424 | print("RadarControllerHeader: " + str(e)) | |
425 | return 0 |
|
425 | return 0 | |
426 | code = numpy.empty([self.nCode, self.nBaud], dtype='i1') |
|
426 | code = numpy.empty([self.nCode, self.nBaud], dtype='i1') | |
427 |
|
427 | |||
428 | for ic in range(self.nCode): |
|
428 | for ic in range(self.nCode): | |
429 | try: |
|
429 | try: | |
430 | if hasattr(fp, 'read'): |
|
430 | if hasattr(fp, 'read'): | |
431 | temp = numpy.fromfile(fp, 'u4', int( |
|
431 | temp = numpy.fromfile(fp, 'u4', int( | |
432 | numpy.ceil(self.nBaud / 32.))) |
|
432 | numpy.ceil(self.nBaud / 32.))) | |
433 | else: |
|
433 | else: | |
434 | temp = numpy.fromstring( |
|
434 | temp = numpy.fromstring( | |
435 | fp, 'u4', int(numpy.ceil(self.nBaud / 32.))) |
|
435 | fp, 'u4', int(numpy.ceil(self.nBaud / 32.))) | |
436 | self.length += temp.nbytes |
|
436 | self.length += temp.nbytes | |
437 | except Exception as e: |
|
437 | except Exception as e: | |
438 | print("RadarControllerHeader: " + str(e)) |
|
438 | print("RadarControllerHeader: " + str(e)) | |
439 | return 0 |
|
439 | return 0 | |
440 |
|
440 | |||
441 | for ib in range(self.nBaud - 1, -1, -1): |
|
441 | for ib in range(self.nBaud - 1, -1, -1): | |
442 | code[ic, ib] = temp[int(ib / 32)] % 2 |
|
442 | code[ic, ib] = temp[int(ib / 32)] % 2 | |
443 | temp[int(ib / 32)] = temp[int(ib / 32)] / 2 |
|
443 | temp[int(ib / 32)] = temp[int(ib / 32)] / 2 | |
444 |
|
444 | |||
445 | self.code = 2.0 * code - 1.0 |
|
445 | self.code = 2.0 * code - 1.0 | |
446 | self.code_size = int(numpy.ceil(self.nBaud / 32.)) * self.nCode * 4 |
|
446 | self.code_size = int(numpy.ceil(self.nBaud / 32.)) * self.nCode * 4 | |
447 |
|
447 | |||
448 | # if self.line5Function == RCfunction.FLIP: |
|
448 | # if self.line5Function == RCfunction.FLIP: | |
449 | # self.flip1 = numpy.fromfile(fp,'<u4',1) |
|
449 | # self.flip1 = numpy.fromfile(fp,'<u4',1) | |
450 | # |
|
450 | # | |
451 | # if self.line6Function == RCfunction.FLIP: |
|
451 | # if self.line6Function == RCfunction.FLIP: | |
452 | # self.flip2 = numpy.fromfile(fp,'<u4',1) |
|
452 | # self.flip2 = numpy.fromfile(fp,'<u4',1) | |
453 | if startFp is not None: |
|
453 | if startFp is not None: | |
454 | endFp = size + startFp |
|
454 | endFp = size + startFp | |
455 |
|
455 | |||
456 | if fp.tell() != endFp: |
|
456 | if fp.tell() != endFp: | |
457 | # fp.seek(endFp) |
|
457 | # fp.seek(endFp) | |
458 | print("%s: Radar Controller Header size is not consistent: from data [%d] != from header field [%d]" % (fp.name, fp.tell() - startFp, size)) |
|
458 | print("%s: Radar Controller Header size is not consistent: from data [%d] != from header field [%d]" % (fp.name, fp.tell() - startFp, size)) | |
459 | # return 0 |
|
459 | # return 0 | |
460 |
|
460 | |||
461 | if fp.tell() > endFp: |
|
461 | if fp.tell() > endFp: | |
462 | sys.stderr.write( |
|
462 | sys.stderr.write( | |
463 | "Warning %s: Size value read from Radar Controller header is lower than it has to be\n" % fp.name) |
|
463 | "Warning %s: Size value read from Radar Controller header is lower than it has to be\n" % fp.name) | |
464 | # return 0 |
|
464 | # return 0 | |
465 |
|
465 | |||
466 | if fp.tell() < endFp: |
|
466 | if fp.tell() < endFp: | |
467 | sys.stderr.write( |
|
467 | sys.stderr.write( | |
468 | "Warning %s: Size value read from Radar Controller header is greater than it has to be\n" % fp.name) |
|
468 | "Warning %s: Size value read from Radar Controller header is greater than it has to be\n" % fp.name) | |
469 |
|
469 | |||
470 | return 1 |
|
470 | return 1 | |
471 |
|
471 | |||
472 | def write(self, fp): |
|
472 | def write(self, fp): | |
473 |
|
473 | |||
474 | headerTuple = (self.size, |
|
474 | headerTuple = (self.size, | |
475 | self.expType, |
|
475 | self.expType, | |
476 | self.nTx, |
|
476 | self.nTx, | |
477 | self.ipp, |
|
477 | self.ipp, | |
478 | self.txA, |
|
478 | self.txA, | |
479 | self.txB, |
|
479 | self.txB, | |
480 | self.nWindows, |
|
480 | self.nWindows, | |
481 | self.numTaus, |
|
481 | self.numTaus, | |
482 | self.codeType, |
|
482 | self.codeType, | |
483 | self.line6Function, |
|
483 | self.line6Function, | |
484 | self.line5Function, |
|
484 | self.line5Function, | |
485 | self.fClock, |
|
485 | self.fClock, | |
486 | self.prePulseBefore, |
|
486 | self.prePulseBefore, | |
487 | self.prePulseAfter, |
|
487 | self.prePulseAfter, | |
488 | self.rangeIpp, |
|
488 | self.rangeIpp, | |
489 | self.rangeTxA, |
|
489 | self.rangeTxA, | |
490 | self.rangeTxB) |
|
490 | self.rangeTxB) | |
491 |
|
491 | |||
492 | header = numpy.array(headerTuple, RADAR_STRUCTURE) |
|
492 | header = numpy.array(headerTuple, RADAR_STRUCTURE) | |
493 | header.tofile(fp) |
|
493 | header.tofile(fp) | |
494 |
|
494 | |||
495 | sampleWindowTuple = ( |
|
495 | sampleWindowTuple = ( | |
496 | self.firstHeight, self.deltaHeight, self.samplesWin) |
|
496 | self.firstHeight, self.deltaHeight, self.samplesWin) | |
497 | samplingWindow = numpy.array(sampleWindowTuple, SAMPLING_STRUCTURE) |
|
497 | samplingWindow = numpy.array(sampleWindowTuple, SAMPLING_STRUCTURE) | |
498 | samplingWindow.tofile(fp) |
|
498 | samplingWindow.tofile(fp) | |
499 |
|
499 | |||
500 | if self.numTaus > 0: |
|
500 | if self.numTaus > 0: | |
501 | self.Taus.tofile(fp) |
|
501 | self.Taus.tofile(fp) | |
502 |
|
502 | |||
503 | if self.codeType != 0: |
|
503 | if self.codeType != 0: | |
504 | nCode = numpy.array(self.nCode, '<u4') |
|
504 | nCode = numpy.array(self.nCode, '<u4') | |
505 | nCode.tofile(fp) |
|
505 | nCode.tofile(fp) | |
506 | nBaud = numpy.array(self.nBaud, '<u4') |
|
506 | nBaud = numpy.array(self.nBaud, '<u4') | |
507 | nBaud.tofile(fp) |
|
507 | nBaud.tofile(fp) | |
508 | code1 = (self.code + 1.0) / 2. |
|
508 | code1 = (self.code + 1.0) / 2. | |
509 |
|
509 | |||
510 | for ic in range(self.nCode): |
|
510 | for ic in range(self.nCode): | |
511 | tempx = numpy.zeros(int(numpy.ceil(self.nBaud / 32.))) |
|
511 | tempx = numpy.zeros(int(numpy.ceil(self.nBaud / 32.))) | |
512 | start = 0 |
|
512 | start = 0 | |
513 | end = 32 |
|
513 | end = 32 | |
514 | for i in range(len(tempx)): |
|
514 | for i in range(len(tempx)): | |
515 | code_selected = code1[ic, start:end] |
|
515 | code_selected = code1[ic, start:end] | |
516 | for j in range(len(code_selected) - 1, -1, -1): |
|
516 | for j in range(len(code_selected) - 1, -1, -1): | |
517 | if code_selected[j] == 1: |
|
517 | if code_selected[j] == 1: | |
518 | tempx[i] = tempx[i] + \ |
|
518 | tempx[i] = tempx[i] + \ | |
519 | 2**(len(code_selected) - 1 - j) |
|
519 | 2**(len(code_selected) - 1 - j) | |
520 | start = start + 32 |
|
520 | start = start + 32 | |
521 | end = end + 32 |
|
521 | end = end + 32 | |
522 |
|
522 | |||
523 | tempx = tempx.astype('u4') |
|
523 | tempx = tempx.astype('u4') | |
524 | tempx.tofile(fp) |
|
524 | tempx.tofile(fp) | |
525 |
|
525 | |||
526 | # if self.line5Function == RCfunction.FLIP: |
|
526 | # if self.line5Function == RCfunction.FLIP: | |
527 | # self.flip1.tofile(fp) |
|
527 | # self.flip1.tofile(fp) | |
528 | # |
|
528 | # | |
529 | # if self.line6Function == RCfunction.FLIP: |
|
529 | # if self.line6Function == RCfunction.FLIP: | |
530 | # self.flip2.tofile(fp) |
|
530 | # self.flip2.tofile(fp) | |
531 |
|
531 | |||
532 | return 1 |
|
532 | return 1 | |
533 |
|
533 | |||
534 | def get_ippSeconds(self): |
|
534 | def get_ippSeconds(self): | |
535 | ''' |
|
535 | ''' | |
536 | ''' |
|
536 | ''' | |
537 | ippSeconds = 2.0 * 1000 * self.ipp / SPEED_OF_LIGHT |
|
537 | ippSeconds = 2.0 * 1000 * self.ipp / SPEED_OF_LIGHT | |
538 |
|
538 | |||
539 | return ippSeconds |
|
539 | return ippSeconds | |
540 |
|
540 | |||
541 | def set_ippSeconds(self, ippSeconds): |
|
541 | def set_ippSeconds(self, ippSeconds): | |
542 | ''' |
|
542 | ''' | |
543 | ''' |
|
543 | ''' | |
544 |
|
544 | |||
545 | self.ipp = ippSeconds * SPEED_OF_LIGHT / (2.0 * 1000) |
|
545 | self.ipp = ippSeconds * SPEED_OF_LIGHT / (2.0 * 1000) | |
546 |
|
546 | |||
547 | return |
|
547 | return | |
548 |
|
548 | |||
549 | def get_size(self): |
|
549 | def get_size(self): | |
550 |
|
550 | |||
551 | self.__size = 116 + 12 * self.nWindows + 4 * self.numTaus |
|
551 | self.__size = 116 + 12 * self.nWindows + 4 * self.numTaus | |
552 |
|
552 | |||
553 | if self.codeType != 0: |
|
553 | if self.codeType != 0: | |
554 | self.__size += 4 + 4 + 4 * self.nCode * \ |
|
554 | self.__size += 4 + 4 + 4 * self.nCode * \ | |
555 | numpy.ceil(self.nBaud / 32.) |
|
555 | numpy.ceil(self.nBaud / 32.) | |
556 |
|
556 | |||
557 | return self.__size |
|
557 | return self.__size | |
558 |
|
558 | |||
559 | def set_size(self, value): |
|
559 | def set_size(self, value): | |
560 |
|
560 | |||
561 | raise IOError("size is a property and it cannot be set, just read") |
|
561 | raise IOError("size is a property and it cannot be set, just read") | |
562 |
|
562 | |||
563 | return |
|
563 | return | |
564 |
|
564 | |||
565 | ippSeconds = property(get_ippSeconds, set_ippSeconds) |
|
565 | ippSeconds = property(get_ippSeconds, set_ippSeconds) | |
566 | size = property(get_size, set_size) |
|
566 | size = property(get_size, set_size) | |
567 |
|
567 | |||
568 |
|
568 | |||
569 | class ProcessingHeader(Header): |
|
569 | class ProcessingHeader(Header): | |
570 |
|
570 | |||
571 | # size = None |
|
571 | # size = None | |
572 | dtype = None |
|
572 | dtype = None | |
573 | blockSize = None |
|
573 | blockSize = None | |
574 | profilesPerBlock = None |
|
574 | profilesPerBlock = None | |
575 | dataBlocksPerFile = None |
|
575 | dataBlocksPerFile = None | |
576 | nWindows = None |
|
576 | nWindows = None | |
577 | processFlags = None |
|
577 | processFlags = None | |
578 | nCohInt = None |
|
578 | nCohInt = None | |
579 | nIncohInt = None |
|
579 | nIncohInt = None | |
580 | totalSpectra = None |
|
580 | totalSpectra = None | |
581 | structure = PROCESSING_STRUCTURE |
|
581 | structure = PROCESSING_STRUCTURE | |
582 | flag_dc = None |
|
582 | flag_dc = None | |
583 | flag_cspc = None |
|
583 | flag_cspc = None | |
584 |
|
584 | |||
585 | def __init__(self, dtype=0, blockSize=0, profilesPerBlock=0, dataBlocksPerFile=0, nWindows=0, processFlags=0, nCohInt=0, |
|
585 | def __init__(self, dtype=0, blockSize=0, profilesPerBlock=0, dataBlocksPerFile=0, nWindows=0, processFlags=0, nCohInt=0, | |
586 | nIncohInt=0, totalSpectra=0, nHeights=0, firstHeight=0, deltaHeight=0, samplesWin=0, spectraComb=0, nCode=0, |
|
586 | nIncohInt=0, totalSpectra=0, nHeights=0, firstHeight=0, deltaHeight=0, samplesWin=0, spectraComb=0, nCode=0, | |
587 | code=0, nBaud=None, shif_fft=False, flag_dc=False, flag_cspc=False, flag_decode=False, flag_deflip=False |
|
587 | code=0, nBaud=None, shif_fft=False, flag_dc=False, flag_cspc=False, flag_decode=False, flag_deflip=False | |
588 | ): |
|
588 | ): | |
589 |
|
589 | |||
590 | # self.size = 0 |
|
590 | # self.size = 0 | |
591 | self.dtype = dtype |
|
591 | self.dtype = dtype | |
592 | self.blockSize = blockSize |
|
592 | self.blockSize = blockSize | |
593 | self.profilesPerBlock = 0 |
|
593 | self.profilesPerBlock = 0 | |
594 | self.dataBlocksPerFile = 0 |
|
594 | self.dataBlocksPerFile = 0 | |
595 | self.nWindows = 0 |
|
595 | self.nWindows = 0 | |
596 | self.processFlags = 0 |
|
596 | self.processFlags = 0 | |
597 | self.nCohInt = 0 |
|
597 | self.nCohInt = 0 | |
598 | self.nIncohInt = 0 |
|
598 | self.nIncohInt = 0 | |
599 | self.totalSpectra = 0 |
|
599 | self.totalSpectra = 0 | |
600 |
|
600 | |||
601 | self.nHeights = 0 |
|
601 | self.nHeights = 0 | |
602 | self.firstHeight = 0 |
|
602 | self.firstHeight = 0 | |
603 | self.deltaHeight = 0 |
|
603 | self.deltaHeight = 0 | |
604 | self.samplesWin = 0 |
|
604 | self.samplesWin = 0 | |
605 | self.spectraComb = 0 |
|
605 | self.spectraComb = 0 | |
606 | self.nCode = None |
|
606 | self.nCode = None | |
607 | self.code = None |
|
607 | self.code = None | |
608 | self.nBaud = None |
|
608 | self.nBaud = None | |
609 |
|
609 | |||
610 | self.shif_fft = False |
|
610 | self.shif_fft = False | |
611 | self.flag_dc = False |
|
611 | self.flag_dc = False | |
612 | self.flag_cspc = False |
|
612 | self.flag_cspc = False | |
613 | self.flag_decode = False |
|
613 | self.flag_decode = False | |
614 | self.flag_deflip = False |
|
614 | self.flag_deflip = False | |
615 | self.length = 0 |
|
615 | self.length = 0 | |
616 |
|
616 | |||
617 | def read(self, fp): |
|
617 | def read(self, fp): | |
618 | self.length = 0 |
|
618 | self.length = 0 | |
619 | try: |
|
619 | try: | |
620 | startFp = fp.tell() |
|
620 | startFp = fp.tell() | |
621 | except Exception as e: |
|
621 | except Exception as e: | |
622 | startFp = None |
|
622 | startFp = None | |
623 | pass |
|
623 | pass | |
624 |
|
624 | |||
625 | try: |
|
625 | try: | |
626 | if hasattr(fp, 'read'): |
|
626 | if hasattr(fp, 'read'): | |
627 | header = numpy.fromfile(fp, PROCESSING_STRUCTURE, 1) |
|
627 | header = numpy.fromfile(fp, PROCESSING_STRUCTURE, 1) | |
628 | else: |
|
628 | else: | |
629 | header = numpy.fromstring(fp, PROCESSING_STRUCTURE, 1) |
|
629 | header = numpy.fromstring(fp, PROCESSING_STRUCTURE, 1) | |
630 | self.length += header.nbytes |
|
630 | self.length += header.nbytes | |
631 | except Exception as e: |
|
631 | except Exception as e: | |
632 | print("ProcessingHeader: " + str(e)) |
|
632 | print("ProcessingHeader: " + str(e)) | |
633 | return 0 |
|
633 | return 0 | |
634 |
|
634 | |||
635 | size = int(header['nSize'][0]) |
|
635 | size = int(header['nSize'][0]) | |
636 | self.dtype = int(header['nDataType'][0]) |
|
636 | self.dtype = int(header['nDataType'][0]) | |
637 | self.blockSize = int(header['nSizeOfDataBlock'][0]) |
|
637 | self.blockSize = int(header['nSizeOfDataBlock'][0]) | |
638 | self.profilesPerBlock = int(header['nProfilesperBlock'][0]) |
|
638 | self.profilesPerBlock = int(header['nProfilesperBlock'][0]) | |
639 | self.dataBlocksPerFile = int(header['nDataBlocksperFile'][0]) |
|
639 | self.dataBlocksPerFile = int(header['nDataBlocksperFile'][0]) | |
640 | self.nWindows = int(header['nNumWindows'][0]) |
|
640 | self.nWindows = int(header['nNumWindows'][0]) | |
641 | self.processFlags = header['nProcessFlags'] |
|
641 | self.processFlags = header['nProcessFlags'] | |
642 | self.nCohInt = int(header['nCoherentIntegrations'][0]) |
|
642 | self.nCohInt = int(header['nCoherentIntegrations'][0]) | |
643 | self.nIncohInt = int(header['nIncoherentIntegrations'][0]) |
|
643 | self.nIncohInt = int(header['nIncoherentIntegrations'][0]) | |
644 | self.totalSpectra = int(header['nTotalSpectra'][0]) |
|
644 | self.totalSpectra = int(header['nTotalSpectra'][0]) | |
645 |
|
645 | |||
646 | try: |
|
646 | try: | |
647 | if hasattr(fp, 'read'): |
|
647 | if hasattr(fp, 'read'): | |
648 | samplingWindow = numpy.fromfile( |
|
648 | samplingWindow = numpy.fromfile( | |
649 | fp, SAMPLING_STRUCTURE, self.nWindows) |
|
649 | fp, SAMPLING_STRUCTURE, self.nWindows) | |
650 | else: |
|
650 | else: | |
651 | samplingWindow = numpy.fromstring( |
|
651 | samplingWindow = numpy.fromstring( | |
652 | fp[self.length:], SAMPLING_STRUCTURE, self.nWindows) |
|
652 | fp[self.length:], SAMPLING_STRUCTURE, self.nWindows) | |
653 | self.length += samplingWindow.nbytes |
|
653 | self.length += samplingWindow.nbytes | |
654 | except Exception as e: |
|
654 | except Exception as e: | |
655 | print("ProcessingHeader: " + str(e)) |
|
655 | print("ProcessingHeader: " + str(e)) | |
656 | return 0 |
|
656 | return 0 | |
657 |
|
657 | |||
658 | self.nHeights = int(numpy.sum(samplingWindow['nsa'])) |
|
658 | self.nHeights = int(numpy.sum(samplingWindow['nsa'])) | |
659 | self.firstHeight = float(samplingWindow['h0'][0]) |
|
659 | self.firstHeight = float(samplingWindow['h0'][0]) | |
660 | self.deltaHeight = float(samplingWindow['dh'][0]) |
|
660 | self.deltaHeight = float(samplingWindow['dh'][0]) | |
661 | self.samplesWin = samplingWindow['nsa'][0] |
|
661 | self.samplesWin = samplingWindow['nsa'][0] | |
662 |
|
662 | |||
663 | try: |
|
663 | try: | |
664 | if hasattr(fp, 'read'): |
|
664 | if hasattr(fp, 'read'): | |
665 | self.spectraComb = numpy.fromfile( |
|
665 | self.spectraComb = numpy.fromfile( | |
666 | fp, 'u1', 2 * self.totalSpectra) |
|
666 | fp, 'u1', 2 * self.totalSpectra) | |
667 | else: |
|
667 | else: | |
668 | self.spectraComb = numpy.fromstring( |
|
668 | self.spectraComb = numpy.fromstring( | |
669 | fp[self.length:], 'u1', 2 * self.totalSpectra) |
|
669 | fp[self.length:], 'u1', 2 * self.totalSpectra) | |
670 | self.length += self.spectraComb.nbytes |
|
670 | self.length += self.spectraComb.nbytes | |
671 | except Exception as e: |
|
671 | except Exception as e: | |
672 | print("ProcessingHeader: " + str(e)) |
|
672 | print("ProcessingHeader: " + str(e)) | |
673 | return 0 |
|
673 | return 0 | |
674 |
|
674 | |||
675 | if ((self.processFlags & PROCFLAG.DEFINE_PROCESS_CODE) == PROCFLAG.DEFINE_PROCESS_CODE): |
|
675 | if ((self.processFlags & PROCFLAG.DEFINE_PROCESS_CODE) == PROCFLAG.DEFINE_PROCESS_CODE): | |
676 | self.nCode = int(numpy.fromfile(fp, '<u4', 1)) |
|
676 | self.nCode = int(numpy.fromfile(fp, '<u4', 1)) | |
677 | self.nBaud = int(numpy.fromfile(fp, '<u4', 1)) |
|
677 | self.nBaud = int(numpy.fromfile(fp, '<u4', 1)) | |
678 | self.code = numpy.fromfile( |
|
678 | self.code = numpy.fromfile( | |
679 | fp, '<f4', self.nCode * self.nBaud).reshape(self.nCode, self.nBaud) |
|
679 | fp, '<f4', self.nCode * self.nBaud).reshape(self.nCode, self.nBaud) | |
680 |
|
680 | |||
681 | if ((self.processFlags & PROCFLAG.EXP_NAME_ESP) == PROCFLAG.EXP_NAME_ESP): |
|
681 | if ((self.processFlags & PROCFLAG.EXP_NAME_ESP) == PROCFLAG.EXP_NAME_ESP): | |
682 | exp_name_len = int(numpy.fromfile(fp, '<u4', 1)) |
|
682 | exp_name_len = int(numpy.fromfile(fp, '<u4', 1)) | |
683 | exp_name = numpy.fromfile(fp, 'u1', exp_name_len + 1) |
|
683 | exp_name = numpy.fromfile(fp, 'u1', exp_name_len + 1) | |
684 |
|
684 | |||
685 | if ((self.processFlags & PROCFLAG.SHIFT_FFT_DATA) == PROCFLAG.SHIFT_FFT_DATA): |
|
685 | if ((self.processFlags & PROCFLAG.SHIFT_FFT_DATA) == PROCFLAG.SHIFT_FFT_DATA): | |
686 | self.shif_fft = True |
|
686 | self.shif_fft = True | |
687 | else: |
|
687 | else: | |
688 | self.shif_fft = False |
|
688 | self.shif_fft = False | |
689 |
|
689 | |||
690 | if ((self.processFlags & PROCFLAG.SAVE_CHANNELS_DC) == PROCFLAG.SAVE_CHANNELS_DC): |
|
690 | if ((self.processFlags & PROCFLAG.SAVE_CHANNELS_DC) == PROCFLAG.SAVE_CHANNELS_DC): | |
691 | self.flag_dc = True |
|
691 | self.flag_dc = True | |
692 | else: |
|
692 | else: | |
693 | self.flag_dc = False |
|
693 | self.flag_dc = False | |
694 |
|
694 | |||
695 | if ((self.processFlags & PROCFLAG.DECODE_DATA) == PROCFLAG.DECODE_DATA): |
|
695 | if ((self.processFlags & PROCFLAG.DECODE_DATA) == PROCFLAG.DECODE_DATA): | |
696 | self.flag_decode = True |
|
696 | self.flag_decode = True | |
697 | else: |
|
697 | else: | |
698 | self.flag_decode = False |
|
698 | self.flag_decode = False | |
699 |
|
699 | |||
700 | if ((self.processFlags & PROCFLAG.DEFLIP_DATA) == PROCFLAG.DEFLIP_DATA): |
|
700 | if ((self.processFlags & PROCFLAG.DEFLIP_DATA) == PROCFLAG.DEFLIP_DATA): | |
701 | self.flag_deflip = True |
|
701 | self.flag_deflip = True | |
702 | else: |
|
702 | else: | |
703 | self.flag_deflip = False |
|
703 | self.flag_deflip = False | |
704 |
|
704 | |||
705 | nChannels = 0 |
|
705 | nChannels = 0 | |
706 | nPairs = 0 |
|
706 | nPairs = 0 | |
707 | pairList = [] |
|
707 | pairList = [] | |
708 |
|
708 | |||
709 | for i in range(0, self.totalSpectra * 2, 2): |
|
709 | for i in range(0, self.totalSpectra * 2, 2): | |
710 | if self.spectraComb[i] == self.spectraComb[i + 1]: |
|
710 | if self.spectraComb[i] == self.spectraComb[i + 1]: | |
711 | nChannels = nChannels + 1 # par de canales iguales |
|
711 | nChannels = nChannels + 1 # par de canales iguales | |
712 | else: |
|
712 | else: | |
713 | nPairs = nPairs + 1 # par de canales diferentes |
|
713 | nPairs = nPairs + 1 # par de canales diferentes | |
714 | pairList.append((self.spectraComb[i], self.spectraComb[i + 1])) |
|
714 | pairList.append((self.spectraComb[i], self.spectraComb[i + 1])) | |
715 |
|
715 | |||
716 | self.flag_cspc = False |
|
716 | self.flag_cspc = False | |
717 | if nPairs > 0: |
|
717 | if nPairs > 0: | |
718 | self.flag_cspc = True |
|
718 | self.flag_cspc = True | |
719 |
|
719 | |||
720 | if startFp is not None: |
|
720 | if startFp is not None: | |
721 | endFp = size + startFp |
|
721 | endFp = size + startFp | |
722 | if fp.tell() > endFp: |
|
722 | if fp.tell() > endFp: | |
723 | sys.stderr.write( |
|
723 | sys.stderr.write( | |
724 | "Warning: Processing header size is lower than it has to be") |
|
724 | "Warning: Processing header size is lower than it has to be") | |
725 | return 0 |
|
725 | return 0 | |
726 |
|
726 | |||
727 | if fp.tell() < endFp: |
|
727 | if fp.tell() < endFp: | |
728 | sys.stderr.write( |
|
728 | sys.stderr.write( | |
729 | "Warning: Processing header size is greater than it is considered") |
|
729 | "Warning: Processing header size is greater than it is considered") | |
730 |
|
730 | |||
731 | return 1 |
|
731 | return 1 | |
732 |
|
732 | |||
733 | def write(self, fp): |
|
733 | def write(self, fp): | |
734 | # Clear DEFINE_PROCESS_CODE |
|
734 | # Clear DEFINE_PROCESS_CODE | |
735 | self.processFlags = self.processFlags & (~PROCFLAG.DEFINE_PROCESS_CODE) |
|
735 | self.processFlags = self.processFlags & (~PROCFLAG.DEFINE_PROCESS_CODE) | |
736 |
|
736 | |||
737 | headerTuple = (self.size, |
|
737 | headerTuple = (self.size, | |
738 | self.dtype, |
|
738 | self.dtype, | |
739 | self.blockSize, |
|
739 | self.blockSize, | |
740 | self.profilesPerBlock, |
|
740 | self.profilesPerBlock, | |
741 | self.dataBlocksPerFile, |
|
741 | self.dataBlocksPerFile, | |
742 | self.nWindows, |
|
742 | self.nWindows, | |
743 | self.processFlags, |
|
743 | self.processFlags, | |
744 | self.nCohInt, |
|
744 | self.nCohInt, | |
745 | self.nIncohInt, |
|
745 | self.nIncohInt, | |
746 | self.totalSpectra) |
|
746 | self.totalSpectra) | |
747 |
|
747 | |||
748 | header = numpy.array(headerTuple, PROCESSING_STRUCTURE) |
|
748 | header = numpy.array(headerTuple, PROCESSING_STRUCTURE) | |
749 | header.tofile(fp) |
|
749 | header.tofile(fp) | |
750 |
|
750 | |||
751 | if self.nWindows != 0: |
|
751 | if self.nWindows != 0: | |
752 | sampleWindowTuple = ( |
|
752 | sampleWindowTuple = ( | |
753 | self.firstHeight, self.deltaHeight, self.samplesWin) |
|
753 | self.firstHeight, self.deltaHeight, self.samplesWin) | |
754 | samplingWindow = numpy.array(sampleWindowTuple, SAMPLING_STRUCTURE) |
|
754 | samplingWindow = numpy.array(sampleWindowTuple, SAMPLING_STRUCTURE) | |
755 | samplingWindow.tofile(fp) |
|
755 | samplingWindow.tofile(fp) | |
756 |
|
756 | |||
757 | if self.totalSpectra != 0: |
|
757 | if self.totalSpectra != 0: | |
758 | # spectraComb = numpy.array([],numpy.dtype('u1')) |
|
758 | # spectraComb = numpy.array([],numpy.dtype('u1')) | |
759 | spectraComb = self.spectraComb |
|
759 | spectraComb = self.spectraComb | |
760 | spectraComb.tofile(fp) |
|
760 | spectraComb.tofile(fp) | |
761 |
|
761 | |||
762 | # if self.processFlags & PROCFLAG.DEFINE_PROCESS_CODE == PROCFLAG.DEFINE_PROCESS_CODE: |
|
762 | # if self.processFlags & PROCFLAG.DEFINE_PROCESS_CODE == PROCFLAG.DEFINE_PROCESS_CODE: | |
763 | # nCode = numpy.array([self.nCode], numpy.dtype('u4')) #Probar con un dato que almacene codigo, hasta el momento no se hizo la prueba |
|
763 | # nCode = numpy.array([self.nCode], numpy.dtype('u4')) #Probar con un dato que almacene codigo, hasta el momento no se hizo la prueba | |
764 | # nCode.tofile(fp) |
|
764 | # nCode.tofile(fp) | |
765 | # |
|
765 | # | |
766 | # nBaud = numpy.array([self.nBaud], numpy.dtype('u4')) |
|
766 | # nBaud = numpy.array([self.nBaud], numpy.dtype('u4')) | |
767 | # nBaud.tofile(fp) |
|
767 | # nBaud.tofile(fp) | |
768 | # |
|
768 | # | |
769 | # code = self.code.reshape(self.nCode*self.nBaud) |
|
769 | # code = self.code.reshape(self.nCode*self.nBaud) | |
770 | # code = code.astype(numpy.dtype('<f4')) |
|
770 | # code = code.astype(numpy.dtype('<f4')) | |
771 | # code.tofile(fp) |
|
771 | # code.tofile(fp) | |
772 |
|
772 | |||
773 | return 1 |
|
773 | return 1 | |
774 |
|
774 | |||
775 | def get_size(self): |
|
775 | def get_size(self): | |
776 |
|
776 | |||
777 | self.__size = 40 + 12 * self.nWindows + 2 * self.totalSpectra |
|
777 | self.__size = 40 + 12 * self.nWindows + 2 * self.totalSpectra | |
778 |
|
778 | |||
779 | # if self.processFlags & PROCFLAG.DEFINE_PROCESS_CODE == PROCFLAG.DEFINE_PROCESS_CODE: |
|
779 | # if self.processFlags & PROCFLAG.DEFINE_PROCESS_CODE == PROCFLAG.DEFINE_PROCESS_CODE: | |
780 | # self.__size += 4 + 4 + 4*self.nCode*numpy.ceil(self.nBaud/32.) |
|
780 | # self.__size += 4 + 4 + 4*self.nCode*numpy.ceil(self.nBaud/32.) | |
781 | # self.__size += 4 + 4 + 4 * self.nCode * self.nBaud |
|
781 | # self.__size += 4 + 4 + 4 * self.nCode * self.nBaud | |
782 |
|
782 | |||
783 | return self.__size |
|
783 | return self.__size | |
784 |
|
784 | |||
785 | def set_size(self, value): |
|
785 | def set_size(self, value): | |
786 |
|
786 | |||
787 | raise IOError("size is a property and it cannot be set, just read") |
|
787 | raise IOError("size is a property and it cannot be set, just read") | |
788 |
|
788 | |||
789 | return |
|
789 | return | |
790 |
|
790 | |||
791 | size = property(get_size, set_size) |
|
791 | size = property(get_size, set_size) | |
792 |
|
792 | |||
793 |
|
793 | |||
794 | class RCfunction: |
|
794 | class RCfunction: | |
795 | NONE = 0 |
|
795 | NONE = 0 | |
796 | FLIP = 1 |
|
796 | FLIP = 1 | |
797 | CODE = 2 |
|
797 | CODE = 2 | |
798 | SAMPLING = 3 |
|
798 | SAMPLING = 3 | |
799 | LIN6DIV256 = 4 |
|
799 | LIN6DIV256 = 4 | |
800 | SYNCHRO = 5 |
|
800 | SYNCHRO = 5 | |
801 |
|
801 | |||
802 |
|
802 | |||
803 | class nCodeType: |
|
803 | class nCodeType: | |
804 | NONE = 0 |
|
804 | NONE = 0 | |
805 | USERDEFINE = 1 |
|
805 | USERDEFINE = 1 | |
806 | BARKER2 = 2 |
|
806 | BARKER2 = 2 | |
807 | BARKER3 = 3 |
|
807 | BARKER3 = 3 | |
808 | BARKER4 = 4 |
|
808 | BARKER4 = 4 | |
809 | BARKER5 = 5 |
|
809 | BARKER5 = 5 | |
810 | BARKER7 = 6 |
|
810 | BARKER7 = 6 | |
811 | BARKER11 = 7 |
|
811 | BARKER11 = 7 | |
812 | BARKER13 = 8 |
|
812 | BARKER13 = 8 | |
813 | AC128 = 9 |
|
813 | AC128 = 9 | |
814 | COMPLEMENTARYCODE2 = 10 |
|
814 | COMPLEMENTARYCODE2 = 10 | |
815 | COMPLEMENTARYCODE4 = 11 |
|
815 | COMPLEMENTARYCODE4 = 11 | |
816 | COMPLEMENTARYCODE8 = 12 |
|
816 | COMPLEMENTARYCODE8 = 12 | |
817 | COMPLEMENTARYCODE16 = 13 |
|
817 | COMPLEMENTARYCODE16 = 13 | |
818 | COMPLEMENTARYCODE32 = 14 |
|
818 | COMPLEMENTARYCODE32 = 14 | |
819 | COMPLEMENTARYCODE64 = 15 |
|
819 | COMPLEMENTARYCODE64 = 15 | |
820 | COMPLEMENTARYCODE128 = 16 |
|
820 | COMPLEMENTARYCODE128 = 16 | |
821 | CODE_BINARY28 = 17 |
|
821 | CODE_BINARY28 = 17 | |
822 |
|
822 | |||
823 |
|
823 | |||
824 | class PROCFLAG: |
|
824 | class PROCFLAG: | |
825 |
|
825 | |||
826 | COHERENT_INTEGRATION = numpy.uint32(0x00000001) |
|
826 | COHERENT_INTEGRATION = numpy.uint32(0x00000001) | |
827 | DECODE_DATA = numpy.uint32(0x00000002) |
|
827 | DECODE_DATA = numpy.uint32(0x00000002) | |
828 | SPECTRA_CALC = numpy.uint32(0x00000004) |
|
828 | SPECTRA_CALC = numpy.uint32(0x00000004) | |
829 | INCOHERENT_INTEGRATION = numpy.uint32(0x00000008) |
|
829 | INCOHERENT_INTEGRATION = numpy.uint32(0x00000008) | |
830 | POST_COHERENT_INTEGRATION = numpy.uint32(0x00000010) |
|
830 | POST_COHERENT_INTEGRATION = numpy.uint32(0x00000010) | |
831 | SHIFT_FFT_DATA = numpy.uint32(0x00000020) |
|
831 | SHIFT_FFT_DATA = numpy.uint32(0x00000020) | |
832 |
|
832 | |||
833 | DATATYPE_CHAR = numpy.uint32(0x00000040) |
|
833 | DATATYPE_CHAR = numpy.uint32(0x00000040) | |
834 | DATATYPE_SHORT = numpy.uint32(0x00000080) |
|
834 | DATATYPE_SHORT = numpy.uint32(0x00000080) | |
835 | DATATYPE_LONG = numpy.uint32(0x00000100) |
|
835 | DATATYPE_LONG = numpy.uint32(0x00000100) | |
836 | DATATYPE_INT64 = numpy.uint32(0x00000200) |
|
836 | DATATYPE_INT64 = numpy.uint32(0x00000200) | |
837 | DATATYPE_FLOAT = numpy.uint32(0x00000400) |
|
837 | DATATYPE_FLOAT = numpy.uint32(0x00000400) | |
838 | DATATYPE_DOUBLE = numpy.uint32(0x00000800) |
|
838 | DATATYPE_DOUBLE = numpy.uint32(0x00000800) | |
839 |
|
839 | |||
840 | DATAARRANGE_CONTIGUOUS_CH = numpy.uint32(0x00001000) |
|
840 | DATAARRANGE_CONTIGUOUS_CH = numpy.uint32(0x00001000) | |
841 | DATAARRANGE_CONTIGUOUS_H = numpy.uint32(0x00002000) |
|
841 | DATAARRANGE_CONTIGUOUS_H = numpy.uint32(0x00002000) | |
842 | DATAARRANGE_CONTIGUOUS_P = numpy.uint32(0x00004000) |
|
842 | DATAARRANGE_CONTIGUOUS_P = numpy.uint32(0x00004000) | |
843 |
|
843 | |||
844 | SAVE_CHANNELS_DC = numpy.uint32(0x00008000) |
|
844 | SAVE_CHANNELS_DC = numpy.uint32(0x00008000) | |
845 | DEFLIP_DATA = numpy.uint32(0x00010000) |
|
845 | DEFLIP_DATA = numpy.uint32(0x00010000) | |
846 | DEFINE_PROCESS_CODE = numpy.uint32(0x00020000) |
|
846 | DEFINE_PROCESS_CODE = numpy.uint32(0x00020000) | |
847 |
|
847 | |||
848 | ACQ_SYS_NATALIA = numpy.uint32(0x00040000) |
|
848 | ACQ_SYS_NATALIA = numpy.uint32(0x00040000) | |
849 | ACQ_SYS_ECHOTEK = numpy.uint32(0x00080000) |
|
849 | ACQ_SYS_ECHOTEK = numpy.uint32(0x00080000) | |
850 | ACQ_SYS_ADRXD = numpy.uint32(0x000C0000) |
|
850 | ACQ_SYS_ADRXD = numpy.uint32(0x000C0000) | |
851 | ACQ_SYS_JULIA = numpy.uint32(0x00100000) |
|
851 | ACQ_SYS_JULIA = numpy.uint32(0x00100000) | |
852 | ACQ_SYS_XXXXXX = numpy.uint32(0x00140000) |
|
852 | ACQ_SYS_XXXXXX = numpy.uint32(0x00140000) | |
853 |
|
853 | |||
854 | EXP_NAME_ESP = numpy.uint32(0x00200000) |
|
854 | EXP_NAME_ESP = numpy.uint32(0x00200000) | |
855 | CHANNEL_NAMES_ESP = numpy.uint32(0x00400000) |
|
855 | CHANNEL_NAMES_ESP = numpy.uint32(0x00400000) | |
856 |
|
856 | |||
857 | OPERATION_MASK = numpy.uint32(0x0000003F) |
|
857 | OPERATION_MASK = numpy.uint32(0x0000003F) | |
858 | DATATYPE_MASK = numpy.uint32(0x00000FC0) |
|
858 | DATATYPE_MASK = numpy.uint32(0x00000FC0) | |
859 | DATAARRANGE_MASK = numpy.uint32(0x00007000) |
|
859 | DATAARRANGE_MASK = numpy.uint32(0x00007000) | |
860 | ACQ_SYS_MASK = numpy.uint32(0x001C0000) |
|
860 | ACQ_SYS_MASK = numpy.uint32(0x001C0000) | |
861 |
|
861 | |||
862 |
|
862 | |||
863 | dtype0 = numpy.dtype([('real', '<i1'), ('imag', '<i1')]) |
|
863 | dtype0 = numpy.dtype([('real', '<i1'), ('imag', '<i1')]) | |
864 | dtype1 = numpy.dtype([('real', '<i2'), ('imag', '<i2')]) |
|
864 | dtype1 = numpy.dtype([('real', '<i2'), ('imag', '<i2')]) | |
865 | dtype2 = numpy.dtype([('real', '<i4'), ('imag', '<i4')]) |
|
865 | dtype2 = numpy.dtype([('real', '<i4'), ('imag', '<i4')]) | |
866 | dtype3 = numpy.dtype([('real', '<i8'), ('imag', '<i8')]) |
|
866 | dtype3 = numpy.dtype([('real', '<i8'), ('imag', '<i8')]) | |
867 | dtype4 = numpy.dtype([('real', '<f4'), ('imag', '<f4')]) |
|
867 | dtype4 = numpy.dtype([('real', '<f4'), ('imag', '<f4')]) | |
868 | dtype5 = numpy.dtype([('real', '<f8'), ('imag', '<f8')]) |
|
868 | dtype5 = numpy.dtype([('real', '<f8'), ('imag', '<f8')]) | |
869 |
|
869 | |||
870 | NUMPY_DTYPE_LIST = [dtype0, dtype1, dtype2, dtype3, dtype4, dtype5] |
|
870 | NUMPY_DTYPE_LIST = [dtype0, dtype1, dtype2, dtype3, dtype4, dtype5] | |
871 |
|
871 | |||
872 | PROCFLAG_DTYPE_LIST = [PROCFLAG.DATATYPE_CHAR, |
|
872 | PROCFLAG_DTYPE_LIST = [PROCFLAG.DATATYPE_CHAR, | |
873 | PROCFLAG.DATATYPE_SHORT, |
|
873 | PROCFLAG.DATATYPE_SHORT, | |
874 | PROCFLAG.DATATYPE_LONG, |
|
874 | PROCFLAG.DATATYPE_LONG, | |
875 | PROCFLAG.DATATYPE_INT64, |
|
875 | PROCFLAG.DATATYPE_INT64, | |
876 | PROCFLAG.DATATYPE_FLOAT, |
|
876 | PROCFLAG.DATATYPE_FLOAT, | |
877 | PROCFLAG.DATATYPE_DOUBLE] |
|
877 | PROCFLAG.DATATYPE_DOUBLE] | |
878 |
|
878 | |||
879 | DTYPE_WIDTH = [1, 2, 4, 8, 4, 8] |
|
879 | DTYPE_WIDTH = [1, 2, 4, 8, 4, 8] | |
880 |
|
880 | |||
881 |
|
881 | |||
882 | def get_dtype_index(numpy_dtype): |
|
882 | def get_dtype_index(numpy_dtype): | |
883 |
|
883 | |||
884 | index = None |
|
884 | index = None | |
885 |
|
885 | |||
886 | for i in range(len(NUMPY_DTYPE_LIST)): |
|
886 | for i in range(len(NUMPY_DTYPE_LIST)): | |
887 | if numpy_dtype == NUMPY_DTYPE_LIST[i]: |
|
887 | if numpy_dtype == NUMPY_DTYPE_LIST[i]: | |
888 | index = i |
|
888 | index = i | |
889 | break |
|
889 | break | |
890 |
|
890 | |||
891 | return index |
|
891 | return index | |
892 |
|
892 | |||
893 |
|
893 | |||
894 | def get_numpy_dtype(index): |
|
894 | def get_numpy_dtype(index): | |
895 |
|
895 | |||
896 | return NUMPY_DTYPE_LIST[index] |
|
896 | return NUMPY_DTYPE_LIST[index] | |
897 |
|
897 | |||
898 |
|
898 | |||
899 | def get_procflag_dtype(index): |
|
899 | def get_procflag_dtype(index): | |
900 |
|
900 | |||
901 | return PROCFLAG_DTYPE_LIST[index] |
|
901 | return PROCFLAG_DTYPE_LIST[index] | |
902 |
|
902 | |||
903 |
|
903 | |||
904 | def get_dtype_width(index): |
|
904 | def get_dtype_width(index): | |
905 |
|
905 | |||
906 | return DTYPE_WIDTH[index] No newline at end of file |
|
906 | return DTYPE_WIDTH[index] |
@@ -1,665 +1,688 | |||||
1 | # Copyright (c) 2012-2020 Jicamarca Radio Observatory |
|
1 | # Copyright (c) 2012-2020 Jicamarca Radio Observatory | |
2 | # All rights reserved. |
|
2 | # All rights reserved. | |
3 | # |
|
3 | # | |
4 | # Distributed under the terms of the BSD 3-clause license. |
|
4 | # Distributed under the terms of the BSD 3-clause license. | |
5 | """Base class to create plot operations |
|
5 | """Base class to create plot operations | |
6 |
|
6 | |||
7 | """ |
|
7 | """ | |
8 |
|
8 | |||
9 | import os |
|
9 | import os | |
10 | import sys |
|
10 | import sys | |
11 | import zmq |
|
11 | import zmq | |
12 | import time |
|
12 | import time | |
13 | import numpy |
|
13 | import numpy | |
14 | import datetime |
|
14 | import datetime | |
15 |
from |
|
15 | from collections import deque | |
16 | from functools import wraps |
|
16 | from functools import wraps | |
17 | from threading import Thread |
|
17 | from threading import Thread | |
18 | import matplotlib |
|
18 | import matplotlib | |
19 |
|
19 | |||
20 | if 'BACKEND' in os.environ: |
|
20 | if 'BACKEND' in os.environ: | |
21 | matplotlib.use(os.environ['BACKEND']) |
|
21 | matplotlib.use(os.environ['BACKEND']) | |
22 | elif 'linux' in sys.platform: |
|
22 | elif 'linux' in sys.platform: | |
23 | matplotlib.use("TkAgg") |
|
23 | matplotlib.use("TkAgg") | |
24 | elif 'darwin' in sys.platform: |
|
24 | elif 'darwin' in sys.platform: | |
25 |
matplotlib.use(' |
|
25 | matplotlib.use('MacOSX') | |
26 | else: |
|
26 | else: | |
27 | from schainpy.utils import log |
|
27 | from schainpy.utils import log | |
28 | log.warning('Using default Backend="Agg"', 'INFO') |
|
28 | log.warning('Using default Backend="Agg"', 'INFO') | |
29 | matplotlib.use('Agg') |
|
29 | matplotlib.use('Agg') | |
30 |
|
30 | |||
31 | import matplotlib.pyplot as plt |
|
31 | import matplotlib.pyplot as plt | |
32 | from matplotlib.patches import Polygon |
|
32 | from matplotlib.patches import Polygon | |
33 | from mpl_toolkits.axes_grid1 import make_axes_locatable |
|
33 | from mpl_toolkits.axes_grid1 import make_axes_locatable | |
34 | from matplotlib.ticker import FuncFormatter, LinearLocator, MultipleLocator |
|
34 | from matplotlib.ticker import FuncFormatter, LinearLocator, MultipleLocator | |
35 |
|
35 | |||
36 | from schainpy.model.data.jrodata import PlotterData |
|
36 | from schainpy.model.data.jrodata import PlotterData | |
37 | from schainpy.model.proc.jroproc_base import ProcessingUnit, Operation, MPDecorator |
|
37 | from schainpy.model.proc.jroproc_base import ProcessingUnit, Operation, MPDecorator | |
38 | from schainpy.utils import log |
|
38 | from schainpy.utils import log | |
39 |
|
39 | |||
40 | jet_values = matplotlib.pyplot.get_cmap('jet', 100)(numpy.arange(100))[10:90] |
|
40 | jet_values = matplotlib.pyplot.get_cmap('jet', 100)(numpy.arange(100))[10:90] | |
41 | blu_values = matplotlib.pyplot.get_cmap( |
|
41 | blu_values = matplotlib.pyplot.get_cmap( | |
42 | 'seismic_r', 20)(numpy.arange(20))[10:15] |
|
42 | 'seismic_r', 20)(numpy.arange(20))[10:15] | |
43 | ncmap = matplotlib.colors.LinearSegmentedColormap.from_list( |
|
43 | ncmap = matplotlib.colors.LinearSegmentedColormap.from_list( | |
44 | 'jro', numpy.vstack((blu_values, jet_values))) |
|
44 | 'jro', numpy.vstack((blu_values, jet_values))) | |
45 | matplotlib.pyplot.register_cmap(cmap=ncmap) |
|
45 | matplotlib.pyplot.register_cmap(cmap=ncmap) | |
46 |
|
46 | |||
47 | CMAPS = [plt.get_cmap(s) for s in ('jro', 'jet', 'viridis', |
|
47 | CMAPS = [plt.get_cmap(s) for s in ('jro', 'jet', 'viridis', | |
48 | 'plasma', 'inferno', 'Greys', 'seismic', 'bwr', 'coolwarm')] |
|
48 | 'plasma', 'inferno', 'Greys', 'seismic', 'bwr', 'coolwarm')] | |
49 |
|
49 | |||
50 | EARTH_RADIUS = 6.3710e3 |
|
50 | EARTH_RADIUS = 6.3710e3 | |
51 |
|
51 | |||
52 | def ll2xy(lat1, lon1, lat2, lon2): |
|
52 | def ll2xy(lat1, lon1, lat2, lon2): | |
53 |
|
53 | |||
54 | p = 0.017453292519943295 |
|
54 | p = 0.017453292519943295 | |
55 | a = 0.5 - numpy.cos((lat2 - lat1) * p)/2 + numpy.cos(lat1 * p) * \ |
|
55 | a = 0.5 - numpy.cos((lat2 - lat1) * p)/2 + numpy.cos(lat1 * p) * \ | |
56 | numpy.cos(lat2 * p) * (1 - numpy.cos((lon2 - lon1) * p)) / 2 |
|
56 | numpy.cos(lat2 * p) * (1 - numpy.cos((lon2 - lon1) * p)) / 2 | |
57 | r = 12742 * numpy.arcsin(numpy.sqrt(a)) |
|
57 | r = 12742 * numpy.arcsin(numpy.sqrt(a)) | |
58 | theta = numpy.arctan2(numpy.sin((lon2-lon1)*p)*numpy.cos(lat2*p), numpy.cos(lat1*p) |
|
58 | theta = numpy.arctan2(numpy.sin((lon2-lon1)*p)*numpy.cos(lat2*p), numpy.cos(lat1*p) | |
59 | * numpy.sin(lat2*p)-numpy.sin(lat1*p)*numpy.cos(lat2*p)*numpy.cos((lon2-lon1)*p)) |
|
59 | * numpy.sin(lat2*p)-numpy.sin(lat1*p)*numpy.cos(lat2*p)*numpy.cos((lon2-lon1)*p)) | |
60 | theta = -theta + numpy.pi/2 |
|
60 | theta = -theta + numpy.pi/2 | |
61 | return r*numpy.cos(theta), r*numpy.sin(theta) |
|
61 | return r*numpy.cos(theta), r*numpy.sin(theta) | |
62 |
|
62 | |||
63 |
|
63 | |||
64 | def km2deg(km): |
|
64 | def km2deg(km): | |
65 | ''' |
|
65 | ''' | |
66 | Convert distance in km to degrees |
|
66 | Convert distance in km to degrees | |
67 | ''' |
|
67 | ''' | |
68 |
|
68 | |||
69 | return numpy.rad2deg(km/EARTH_RADIUS) |
|
69 | return numpy.rad2deg(km/EARTH_RADIUS) | |
70 |
|
70 | |||
71 |
|
71 | |||
72 | def figpause(interval): |
|
72 | def figpause(interval): | |
73 | backend = plt.rcParams['backend'] |
|
73 | backend = plt.rcParams['backend'] | |
74 | if backend in matplotlib.rcsetup.interactive_bk: |
|
74 | if backend in matplotlib.rcsetup.interactive_bk: | |
75 | figManager = matplotlib._pylab_helpers.Gcf.get_active() |
|
75 | figManager = matplotlib._pylab_helpers.Gcf.get_active() | |
76 | if figManager is not None: |
|
76 | if figManager is not None: | |
77 | canvas = figManager.canvas |
|
77 | canvas = figManager.canvas | |
78 | if canvas.figure.stale: |
|
78 | if canvas.figure.stale: | |
79 | canvas.draw() |
|
79 | canvas.draw() | |
80 | try: |
|
80 | try: | |
81 | canvas.start_event_loop(interval) |
|
81 | canvas.start_event_loop(interval) | |
82 | except: |
|
82 | except: | |
83 | pass |
|
83 | pass | |
84 | return |
|
84 | return | |
85 |
|
85 | |||
86 |
|
||||
87 | def popup(message): |
|
86 | def popup(message): | |
88 | ''' |
|
87 | ''' | |
89 | ''' |
|
88 | ''' | |
90 |
|
89 | |||
91 | fig = plt.figure(figsize=(12, 8), facecolor='r') |
|
90 | fig = plt.figure(figsize=(12, 8), facecolor='r') | |
92 | text = '\n'.join([s.strip() for s in message.split(':')]) |
|
91 | text = '\n'.join([s.strip() for s in message.split(':')]) | |
93 | fig.text(0.01, 0.5, text, ha='left', va='center', |
|
92 | fig.text(0.01, 0.5, text, ha='left', va='center', | |
94 | size='20', weight='heavy', color='w') |
|
93 | size='20', weight='heavy', color='w') | |
95 | fig.show() |
|
94 | fig.show() | |
96 | figpause(1000) |
|
95 | figpause(1000) | |
97 |
|
96 | |||
98 |
|
97 | |||
99 | class Throttle(object): |
|
98 | class Throttle(object): | |
100 | ''' |
|
99 | ''' | |
101 | Decorator that prevents a function from being called more than once every |
|
100 | Decorator that prevents a function from being called more than once every | |
102 | time period. |
|
101 | time period. | |
103 | To create a function that cannot be called more than once a minute, but |
|
102 | To create a function that cannot be called more than once a minute, but | |
104 | will sleep until it can be called: |
|
103 | will sleep until it can be called: | |
105 | @Throttle(minutes=1) |
|
104 | @Throttle(minutes=1) | |
106 | def foo(): |
|
105 | def foo(): | |
107 | pass |
|
106 | pass | |
108 |
|
107 | |||
109 | for i in range(10): |
|
108 | for i in range(10): | |
110 | foo() |
|
109 | foo() | |
111 | print "This function has run %s times." % i |
|
110 | print "This function has run %s times." % i | |
112 | ''' |
|
111 | ''' | |
113 |
|
112 | |||
114 | def __init__(self, seconds=0, minutes=0, hours=0): |
|
113 | def __init__(self, seconds=0, minutes=0, hours=0): | |
115 | self.throttle_period = datetime.timedelta( |
|
114 | self.throttle_period = datetime.timedelta( | |
116 | seconds=seconds, minutes=minutes, hours=hours |
|
115 | seconds=seconds, minutes=minutes, hours=hours | |
117 | ) |
|
116 | ) | |
118 |
|
117 | |||
119 | self.time_of_last_call = datetime.datetime.min |
|
118 | self.time_of_last_call = datetime.datetime.min | |
120 |
|
119 | |||
121 | def __call__(self, fn): |
|
120 | def __call__(self, fn): | |
122 | @wraps(fn) |
|
121 | @wraps(fn) | |
123 | def wrapper(*args, **kwargs): |
|
122 | def wrapper(*args, **kwargs): | |
124 | coerce = kwargs.pop('coerce', None) |
|
123 | coerce = kwargs.pop('coerce', None) | |
125 | if coerce: |
|
124 | if coerce: | |
126 | self.time_of_last_call = datetime.datetime.now() |
|
125 | self.time_of_last_call = datetime.datetime.now() | |
127 | return fn(*args, **kwargs) |
|
126 | return fn(*args, **kwargs) | |
128 | else: |
|
127 | else: | |
129 | now = datetime.datetime.now() |
|
128 | now = datetime.datetime.now() | |
130 | time_since_last_call = now - self.time_of_last_call |
|
129 | time_since_last_call = now - self.time_of_last_call | |
131 | time_left = self.throttle_period - time_since_last_call |
|
130 | time_left = self.throttle_period - time_since_last_call | |
132 |
|
131 | |||
133 | if time_left > datetime.timedelta(seconds=0): |
|
132 | if time_left > datetime.timedelta(seconds=0): | |
134 | return |
|
133 | return | |
135 |
|
134 | |||
136 | self.time_of_last_call = datetime.datetime.now() |
|
135 | self.time_of_last_call = datetime.datetime.now() | |
137 | return fn(*args, **kwargs) |
|
136 | return fn(*args, **kwargs) | |
138 |
|
137 | |||
139 | return wrapper |
|
138 | return wrapper | |
140 |
|
139 | |||
141 | def apply_throttle(value): |
|
140 | def apply_throttle(value): | |
142 |
|
141 | |||
143 | @Throttle(seconds=value) |
|
142 | @Throttle(seconds=value) | |
144 | def fnThrottled(fn): |
|
143 | def fnThrottled(fn): | |
145 | fn() |
|
144 | fn() | |
146 |
|
145 | |||
147 | return fnThrottled |
|
146 | return fnThrottled | |
148 |
|
147 | |||
149 |
|
148 | |||
150 | @MPDecorator |
|
149 | @MPDecorator | |
151 | class Plot(Operation): |
|
150 | class Plot(Operation): | |
152 | """Base class for Schain plotting operations |
|
151 | """Base class for Schain plotting operations | |
153 |
|
152 | |||
154 | This class should never be use directtly you must subclass a new operation, |
|
153 | This class should never be use directtly you must subclass a new operation, | |
155 | children classes must be defined as follow: |
|
154 | children classes must be defined as follow: | |
156 |
|
155 | |||
157 | ExamplePlot(Plot): |
|
156 | ExamplePlot(Plot): | |
158 |
|
157 | |||
159 | CODE = 'code' |
|
158 | CODE = 'code' | |
160 | colormap = 'jet' |
|
159 | colormap = 'jet' | |
161 | plot_type = 'pcolor' # options are ('pcolor', 'pcolorbuffer', 'scatter', 'scatterbuffer') |
|
160 | plot_type = 'pcolor' # options are ('pcolor', 'pcolorbuffer', 'scatter', 'scatterbuffer') | |
162 |
|
161 | |||
163 | def setup(self): |
|
162 | def setup(self): | |
164 | pass |
|
163 | pass | |
165 |
|
164 | |||
166 | def plot(self): |
|
165 | def plot(self): | |
167 | pass |
|
166 | pass | |
168 |
|
167 | |||
169 | """ |
|
168 | """ | |
170 |
|
169 | |||
171 | CODE = 'Figure' |
|
170 | CODE = 'Figure' | |
172 | colormap = 'jet' |
|
171 | colormap = 'jet' | |
173 | bgcolor = 'white' |
|
172 | bgcolor = 'white' | |
174 | buffering = True |
|
173 | buffering = True | |
175 | __missing = 1E30 |
|
174 | __missing = 1E30 | |
176 |
|
175 | |||
177 | __attrs__ = ['show', 'save', 'ymin', 'ymax', 'zmin', 'zmax', 'title', |
|
176 | __attrs__ = ['show', 'save', 'ymin', 'ymax', 'zmin', 'zmax', 'title', | |
178 | 'showprofile'] |
|
177 | 'showprofile'] | |
179 |
|
178 | |||
180 | def __init__(self): |
|
179 | def __init__(self): | |
181 |
|
180 | |||
182 | Operation.__init__(self) |
|
181 | Operation.__init__(self) | |
183 | self.isConfig = False |
|
182 | self.isConfig = False | |
184 | self.isPlotConfig = False |
|
183 | self.isPlotConfig = False | |
185 | self.save_time = 0 |
|
184 | self.save_time = 0 | |
186 | self.sender_time = 0 |
|
185 | self.sender_time = 0 | |
187 | self.data = None |
|
186 | self.data = None | |
188 | self.firsttime = True |
|
187 | self.firsttime = True | |
189 |
self.sender_queue = |
|
188 | self.sender_queue = deque(maxlen=10) | |
190 | self.plots_adjust = {'left': 0.125, 'right': 0.9, 'bottom': 0.15, 'top': 0.9, 'wspace': 0.2, 'hspace': 0.2} |
|
189 | self.plots_adjust = {'left': 0.125, 'right': 0.9, 'bottom': 0.15, 'top': 0.9, 'wspace': 0.2, 'hspace': 0.2} | |
191 |
|
190 | |||
192 | def __fmtTime(self, x, pos): |
|
191 | def __fmtTime(self, x, pos): | |
193 | ''' |
|
192 | ''' | |
194 | ''' |
|
193 | ''' | |
195 |
|
194 | |||
196 | return '{}'.format(self.getDateTime(x).strftime('%H:%M')) |
|
195 | return '{}'.format(self.getDateTime(x).strftime('%H:%M')) | |
197 |
|
196 | |||
198 | def __setup(self, **kwargs): |
|
197 | def __setup(self, **kwargs): | |
199 | ''' |
|
198 | ''' | |
200 | Initialize variables |
|
199 | Initialize variables | |
201 | ''' |
|
200 | ''' | |
202 |
|
201 | |||
203 | self.figures = [] |
|
202 | self.figures = [] | |
204 | self.axes = [] |
|
203 | self.axes = [] | |
205 | self.cb_axes = [] |
|
204 | self.cb_axes = [] | |
206 | self.localtime = kwargs.pop('localtime', True) |
|
205 | self.localtime = kwargs.pop('localtime', True) | |
207 | self.show = kwargs.get('show', True) |
|
206 | self.show = kwargs.get('show', True) | |
208 | self.save = kwargs.get('save', False) |
|
207 | self.save = kwargs.get('save', False) | |
209 | self.save_period = kwargs.get('save_period', 0) |
|
208 | self.save_period = kwargs.get('save_period', 0) | |
210 | self.colormap = kwargs.get('colormap', self.colormap) |
|
209 | self.colormap = kwargs.get('colormap', self.colormap) | |
211 | self.colormap_coh = kwargs.get('colormap_coh', 'jet') |
|
210 | self.colormap_coh = kwargs.get('colormap_coh', 'jet') | |
212 | self.colormap_phase = kwargs.get('colormap_phase', 'RdBu_r') |
|
211 | self.colormap_phase = kwargs.get('colormap_phase', 'RdBu_r') | |
213 | self.colormaps = kwargs.get('colormaps', None) |
|
212 | self.colormaps = kwargs.get('colormaps', None) | |
214 | self.bgcolor = kwargs.get('bgcolor', self.bgcolor) |
|
213 | self.bgcolor = kwargs.get('bgcolor', self.bgcolor) | |
215 | self.showprofile = kwargs.get('showprofile', False) |
|
214 | self.showprofile = kwargs.get('showprofile', False) | |
216 | self.title = kwargs.get('wintitle', self.CODE.upper()) |
|
215 | self.title = kwargs.get('wintitle', self.CODE.upper()) | |
217 | self.cb_label = kwargs.get('cb_label', None) |
|
216 | self.cb_label = kwargs.get('cb_label', None) | |
218 | self.cb_labels = kwargs.get('cb_labels', None) |
|
217 | self.cb_labels = kwargs.get('cb_labels', None) | |
219 | self.labels = kwargs.get('labels', None) |
|
218 | self.labels = kwargs.get('labels', None) | |
220 | self.xaxis = kwargs.get('xaxis', 'frequency') |
|
219 | self.xaxis = kwargs.get('xaxis', 'frequency') | |
221 | self.zmin = kwargs.get('zmin', None) |
|
220 | self.zmin = kwargs.get('zmin', None) | |
222 | self.zmax = kwargs.get('zmax', None) |
|
221 | self.zmax = kwargs.get('zmax', None) | |
223 | self.zlimits = kwargs.get('zlimits', None) |
|
222 | self.zlimits = kwargs.get('zlimits', None) | |
224 | self.xmin = kwargs.get('xmin', None) |
|
223 | self.xmin = kwargs.get('xmin', None) | |
225 | self.xmax = kwargs.get('xmax', None) |
|
224 | self.xmax = kwargs.get('xmax', None) | |
226 | self.xrange = kwargs.get('xrange', 12) |
|
225 | self.xrange = kwargs.get('xrange', 12) | |
227 | self.xscale = kwargs.get('xscale', None) |
|
226 | self.xscale = kwargs.get('xscale', None) | |
228 | self.ymin = kwargs.get('ymin', None) |
|
227 | self.ymin = kwargs.get('ymin', None) | |
229 | self.ymax = kwargs.get('ymax', None) |
|
228 | self.ymax = kwargs.get('ymax', None) | |
230 | self.yscale = kwargs.get('yscale', None) |
|
229 | self.yscale = kwargs.get('yscale', None) | |
231 | self.xlabel = kwargs.get('xlabel', None) |
|
230 | self.xlabel = kwargs.get('xlabel', None) | |
232 | self.attr_time = kwargs.get('attr_time', 'utctime') |
|
231 | self.attr_time = kwargs.get('attr_time', 'utctime') | |
|
232 | self.attr_data = kwargs.get('attr_data', 'data_param') | |||
233 | self.decimation = kwargs.get('decimation', None) |
|
233 | self.decimation = kwargs.get('decimation', None) | |
234 | self.showSNR = kwargs.get('showSNR', False) |
|
234 | self.showSNR = kwargs.get('showSNR', False) | |
235 | self.oneFigure = kwargs.get('oneFigure', True) |
|
235 | self.oneFigure = kwargs.get('oneFigure', True) | |
236 | self.width = kwargs.get('width', None) |
|
236 | self.width = kwargs.get('width', None) | |
237 | self.height = kwargs.get('height', None) |
|
237 | self.height = kwargs.get('height', None) | |
238 | self.colorbar = kwargs.get('colorbar', True) |
|
238 | self.colorbar = kwargs.get('colorbar', True) | |
239 | self.factors = kwargs.get('factors', [1, 1, 1, 1, 1, 1, 1, 1]) |
|
239 | self.factors = kwargs.get('factors', [1, 1, 1, 1, 1, 1, 1, 1]) | |
240 | self.channels = kwargs.get('channels', None) |
|
240 | self.channels = kwargs.get('channels', None) | |
241 | self.titles = kwargs.get('titles', []) |
|
241 | self.titles = kwargs.get('titles', []) | |
242 | self.polar = False |
|
242 | self.polar = False | |
243 | self.type = kwargs.get('type', 'iq') |
|
243 | self.type = kwargs.get('type', 'iq') | |
244 | self.grid = kwargs.get('grid', False) |
|
244 | self.grid = kwargs.get('grid', False) | |
245 | self.pause = kwargs.get('pause', False) |
|
245 | self.pause = kwargs.get('pause', False) | |
246 | self.save_code = kwargs.get('save_code', self.CODE) |
|
246 | self.save_code = kwargs.get('save_code', self.CODE) | |
247 | self.throttle = kwargs.get('throttle', 0) |
|
247 | self.throttle = kwargs.get('throttle', 0) | |
248 | self.exp_code = kwargs.get('exp_code', None) |
|
248 | self.exp_code = kwargs.get('exp_code', None) | |
249 | self.server = kwargs.get('server', False) |
|
249 | self.server = kwargs.get('server', False) | |
250 | self.sender_period = kwargs.get('sender_period', 60) |
|
250 | self.sender_period = kwargs.get('sender_period', 60) | |
251 | self.tag = kwargs.get('tag', '') |
|
251 | self.tag = kwargs.get('tag', '') | |
252 | self.height_index = kwargs.get('height_index', None) |
|
252 | self.height_index = kwargs.get('height_index', None) | |
253 | self.__throttle_plot = apply_throttle(self.throttle) |
|
253 | self.__throttle_plot = apply_throttle(self.throttle) | |
254 | self.data = PlotterData( |
|
254 | code = self.attr_data if self.attr_data else self.CODE | |
255 | self.CODE, self.throttle, self.exp_code, self.localtime, self.buffering, snr=self.showSNR) |
|
255 | self.data = PlotterData(self.CODE, self.exp_code, self.localtime) | |
256 |
|
256 | |||
257 | if self.server: |
|
257 | if self.server: | |
258 | if not self.server.startswith('tcp://'): |
|
258 | if not self.server.startswith('tcp://'): | |
259 | self.server = 'tcp://{}'.format(self.server) |
|
259 | self.server = 'tcp://{}'.format(self.server) | |
260 | log.success( |
|
260 | log.success( | |
261 | 'Sending to server: {}'.format(self.server), |
|
261 | 'Sending to server: {}'.format(self.server), | |
262 | self.name |
|
262 | self.name | |
263 | ) |
|
263 | ) | |
264 |
|
264 | |||
265 | def __setup_plot(self): |
|
265 | def __setup_plot(self): | |
266 | ''' |
|
266 | ''' | |
267 | Common setup for all figures, here figures and axes are created |
|
267 | Common setup for all figures, here figures and axes are created | |
268 | ''' |
|
268 | ''' | |
269 |
|
269 | |||
270 | self.setup() |
|
270 | self.setup() | |
271 |
|
271 | |||
272 | self.time_label = 'LT' if self.localtime else 'UTC' |
|
272 | self.time_label = 'LT' if self.localtime else 'UTC' | |
273 |
|
273 | |||
274 | if self.width is None: |
|
274 | if self.width is None: | |
275 | self.width = 8 |
|
275 | self.width = 8 | |
276 |
|
276 | |||
277 | self.figures = [] |
|
277 | self.figures = [] | |
278 | self.axes = [] |
|
278 | self.axes = [] | |
279 | self.cb_axes = [] |
|
279 | self.cb_axes = [] | |
280 | self.pf_axes = [] |
|
280 | self.pf_axes = [] | |
281 | self.cmaps = [] |
|
281 | self.cmaps = [] | |
282 |
|
282 | |||
283 | size = '15%' if self.ncols == 1 else '30%' |
|
283 | size = '15%' if self.ncols == 1 else '30%' | |
284 | pad = '4%' if self.ncols == 1 else '8%' |
|
284 | pad = '4%' if self.ncols == 1 else '8%' | |
285 |
|
285 | |||
286 | if self.oneFigure: |
|
286 | if self.oneFigure: | |
287 | if self.height is None: |
|
287 | if self.height is None: | |
288 | self.height = 1.4 * self.nrows + 1 |
|
288 | self.height = 1.4 * self.nrows + 1 | |
289 | fig = plt.figure(figsize=(self.width, self.height), |
|
289 | fig = plt.figure(figsize=(self.width, self.height), | |
290 | edgecolor='k', |
|
290 | edgecolor='k', | |
291 | facecolor='w') |
|
291 | facecolor='w') | |
292 | self.figures.append(fig) |
|
292 | self.figures.append(fig) | |
293 | for n in range(self.nplots): |
|
293 | for n in range(self.nplots): | |
294 | ax = fig.add_subplot(self.nrows, self.ncols, |
|
294 | ax = fig.add_subplot(self.nrows, self.ncols, | |
295 | n + 1, polar=self.polar) |
|
295 | n + 1, polar=self.polar) | |
296 | ax.tick_params(labelsize=8) |
|
296 | ax.tick_params(labelsize=8) | |
297 | ax.firsttime = True |
|
297 | ax.firsttime = True | |
298 | ax.index = 0 |
|
298 | ax.index = 0 | |
299 | ax.press = None |
|
299 | ax.press = None | |
300 | self.axes.append(ax) |
|
300 | self.axes.append(ax) | |
301 | if self.showprofile: |
|
301 | if self.showprofile: | |
302 | cax = self.__add_axes(ax, size=size, pad=pad) |
|
302 | cax = self.__add_axes(ax, size=size, pad=pad) | |
303 | cax.tick_params(labelsize=8) |
|
303 | cax.tick_params(labelsize=8) | |
304 | self.pf_axes.append(cax) |
|
304 | self.pf_axes.append(cax) | |
305 | else: |
|
305 | else: | |
306 | if self.height is None: |
|
306 | if self.height is None: | |
307 | self.height = 3 |
|
307 | self.height = 3 | |
308 | for n in range(self.nplots): |
|
308 | for n in range(self.nplots): | |
309 | fig = plt.figure(figsize=(self.width, self.height), |
|
309 | fig = plt.figure(figsize=(self.width, self.height), | |
310 | edgecolor='k', |
|
310 | edgecolor='k', | |
311 | facecolor='w') |
|
311 | facecolor='w') | |
312 | ax = fig.add_subplot(1, 1, 1, polar=self.polar) |
|
312 | ax = fig.add_subplot(1, 1, 1, polar=self.polar) | |
313 | ax.tick_params(labelsize=8) |
|
313 | ax.tick_params(labelsize=8) | |
314 | ax.firsttime = True |
|
314 | ax.firsttime = True | |
315 | ax.index = 0 |
|
315 | ax.index = 0 | |
316 | ax.press = None |
|
316 | ax.press = None | |
317 | self.figures.append(fig) |
|
317 | self.figures.append(fig) | |
318 | self.axes.append(ax) |
|
318 | self.axes.append(ax) | |
319 | if self.showprofile: |
|
319 | if self.showprofile: | |
320 | cax = self.__add_axes(ax, size=size, pad=pad) |
|
320 | cax = self.__add_axes(ax, size=size, pad=pad) | |
321 | cax.tick_params(labelsize=8) |
|
321 | cax.tick_params(labelsize=8) | |
322 | self.pf_axes.append(cax) |
|
322 | self.pf_axes.append(cax) | |
323 |
|
323 | |||
324 | for n in range(self.nrows): |
|
324 | for n in range(self.nrows): | |
325 | if self.colormaps is not None: |
|
325 | if self.colormaps is not None: | |
326 | cmap = plt.get_cmap(self.colormaps[n]) |
|
326 | cmap = plt.get_cmap(self.colormaps[n]) | |
327 | else: |
|
327 | else: | |
328 | cmap = plt.get_cmap(self.colormap) |
|
328 | cmap = plt.get_cmap(self.colormap) | |
329 | cmap.set_bad(self.bgcolor, 1.) |
|
329 | cmap.set_bad(self.bgcolor, 1.) | |
330 | self.cmaps.append(cmap) |
|
330 | self.cmaps.append(cmap) | |
331 |
|
331 | |||
332 | def __add_axes(self, ax, size='30%', pad='8%'): |
|
332 | def __add_axes(self, ax, size='30%', pad='8%'): | |
333 | ''' |
|
333 | ''' | |
334 | Add new axes to the given figure |
|
334 | Add new axes to the given figure | |
335 | ''' |
|
335 | ''' | |
336 | divider = make_axes_locatable(ax) |
|
336 | divider = make_axes_locatable(ax) | |
337 | nax = divider.new_horizontal(size=size, pad=pad) |
|
337 | nax = divider.new_horizontal(size=size, pad=pad) | |
338 | ax.figure.add_axes(nax) |
|
338 | ax.figure.add_axes(nax) | |
339 | return nax |
|
339 | return nax | |
340 |
|
340 | |||
341 | def fill_gaps(self, x_buffer, y_buffer, z_buffer): |
|
341 | def fill_gaps(self, x_buffer, y_buffer, z_buffer): | |
342 | ''' |
|
342 | ''' | |
343 | Create a masked array for missing data |
|
343 | Create a masked array for missing data | |
344 | ''' |
|
344 | ''' | |
345 | if x_buffer.shape[0] < 2: |
|
345 | if x_buffer.shape[0] < 2: | |
346 | return x_buffer, y_buffer, z_buffer |
|
346 | return x_buffer, y_buffer, z_buffer | |
347 |
|
347 | |||
348 | deltas = x_buffer[1:] - x_buffer[0:-1] |
|
348 | deltas = x_buffer[1:] - x_buffer[0:-1] | |
349 | x_median = numpy.median(deltas) |
|
349 | x_median = numpy.median(deltas) | |
350 |
|
350 | |||
351 | index = numpy.where(deltas > 5 * x_median) |
|
351 | index = numpy.where(deltas > 5 * x_median) | |
352 |
|
352 | |||
353 | if len(index[0]) != 0: |
|
353 | if len(index[0]) != 0: | |
354 | z_buffer[::, index[0], ::] = self.__missing |
|
354 | z_buffer[::, index[0], ::] = self.__missing | |
355 | z_buffer = numpy.ma.masked_inside(z_buffer, |
|
355 | z_buffer = numpy.ma.masked_inside(z_buffer, | |
356 | 0.99 * self.__missing, |
|
356 | 0.99 * self.__missing, | |
357 | 1.01 * self.__missing) |
|
357 | 1.01 * self.__missing) | |
358 |
|
358 | |||
359 | return x_buffer, y_buffer, z_buffer |
|
359 | return x_buffer, y_buffer, z_buffer | |
360 |
|
360 | |||
361 | def decimate(self): |
|
361 | def decimate(self): | |
362 |
|
362 | |||
363 | # dx = int(len(self.x)/self.__MAXNUMX) + 1 |
|
363 | # dx = int(len(self.x)/self.__MAXNUMX) + 1 | |
364 | dy = int(len(self.y) / self.decimation) + 1 |
|
364 | dy = int(len(self.y) / self.decimation) + 1 | |
365 |
|
365 | |||
366 | # x = self.x[::dx] |
|
366 | # x = self.x[::dx] | |
367 | x = self.x |
|
367 | x = self.x | |
368 | y = self.y[::dy] |
|
368 | y = self.y[::dy] | |
369 | z = self.z[::, ::, ::dy] |
|
369 | z = self.z[::, ::, ::dy] | |
370 |
|
370 | |||
371 | return x, y, z |
|
371 | return x, y, z | |
372 |
|
372 | |||
373 | def format(self): |
|
373 | def format(self): | |
374 | ''' |
|
374 | ''' | |
375 | Set min and max values, labels, ticks and titles |
|
375 | Set min and max values, labels, ticks and titles | |
376 | ''' |
|
376 | ''' | |
377 |
|
377 | |||
378 | for n, ax in enumerate(self.axes): |
|
378 | for n, ax in enumerate(self.axes): | |
379 | if ax.firsttime: |
|
379 | if ax.firsttime: | |
380 | if self.xaxis != 'time': |
|
380 | if self.xaxis != 'time': | |
381 | xmin = self.xmin |
|
381 | xmin = self.xmin | |
382 | xmax = self.xmax |
|
382 | xmax = self.xmax | |
383 | else: |
|
383 | else: | |
384 | xmin = self.tmin |
|
384 | xmin = self.tmin | |
385 | xmax = self.tmin + self.xrange*60*60 |
|
385 | xmax = self.tmin + self.xrange*60*60 | |
386 | ax.xaxis.set_major_formatter(FuncFormatter(self.__fmtTime)) |
|
386 | ax.xaxis.set_major_formatter(FuncFormatter(self.__fmtTime)) | |
387 | ax.xaxis.set_major_locator(LinearLocator(9)) |
|
387 | ax.xaxis.set_major_locator(LinearLocator(9)) | |
388 | ymin = self.ymin if self.ymin else numpy.nanmin(self.y) |
|
388 | ymin = self.ymin if self.ymin is not None else numpy.nanmin(self.y[numpy.isfinite(self.y)]) | |
389 | ymax = self.ymax if self.ymax else numpy.nanmax(self.y) |
|
389 | ymax = self.ymax if self.ymax is not None else numpy.nanmax(self.y[numpy.isfinite(self.y)]) | |
390 | ax.set_facecolor(self.bgcolor) |
|
390 | ax.set_facecolor(self.bgcolor) | |
391 | if self.xscale: |
|
391 | if self.xscale: | |
392 | ax.xaxis.set_major_formatter(FuncFormatter( |
|
392 | ax.xaxis.set_major_formatter(FuncFormatter( | |
393 | lambda x, pos: '{0:g}'.format(x*self.xscale))) |
|
393 | lambda x, pos: '{0:g}'.format(x*self.xscale))) | |
394 | if self.yscale: |
|
394 | if self.yscale: | |
395 | ax.yaxis.set_major_formatter(FuncFormatter( |
|
395 | ax.yaxis.set_major_formatter(FuncFormatter( | |
396 | lambda x, pos: '{0:g}'.format(x*self.yscale))) |
|
396 | lambda x, pos: '{0:g}'.format(x*self.yscale))) | |
397 | if self.xlabel is not None: |
|
397 | if self.xlabel is not None: | |
398 | ax.set_xlabel(self.xlabel) |
|
398 | ax.set_xlabel(self.xlabel) | |
399 | if self.ylabel is not None: |
|
399 | if self.ylabel is not None: | |
400 | ax.set_ylabel(self.ylabel) |
|
400 | ax.set_ylabel(self.ylabel) | |
401 | if self.showprofile: |
|
401 | if self.showprofile: | |
402 | self.pf_axes[n].set_ylim(ymin, ymax) |
|
402 | self.pf_axes[n].set_ylim(ymin, ymax) | |
403 | self.pf_axes[n].set_xlim(self.zmin, self.zmax) |
|
403 | self.pf_axes[n].set_xlim(self.zmin, self.zmax) | |
404 | self.pf_axes[n].set_xlabel('dB') |
|
404 | self.pf_axes[n].set_xlabel('dB') | |
405 | self.pf_axes[n].grid(b=True, axis='x') |
|
405 | self.pf_axes[n].grid(b=True, axis='x') | |
406 | [tick.set_visible(False) |
|
406 | [tick.set_visible(False) | |
407 | for tick in self.pf_axes[n].get_yticklabels()] |
|
407 | for tick in self.pf_axes[n].get_yticklabels()] | |
408 | if self.colorbar: |
|
408 | if self.colorbar: | |
409 | ax.cbar = plt.colorbar( |
|
409 | ax.cbar = plt.colorbar( | |
410 | ax.plt, ax=ax, fraction=0.05, pad=0.02, aspect=10) |
|
410 | ax.plt, ax=ax, fraction=0.05, pad=0.02, aspect=10) | |
411 | ax.cbar.ax.tick_params(labelsize=8) |
|
411 | ax.cbar.ax.tick_params(labelsize=8) | |
412 | ax.cbar.ax.press = None |
|
412 | ax.cbar.ax.press = None | |
413 | if self.cb_label: |
|
413 | if self.cb_label: | |
414 | ax.cbar.set_label(self.cb_label, size=8) |
|
414 | ax.cbar.set_label(self.cb_label, size=8) | |
415 | elif self.cb_labels: |
|
415 | elif self.cb_labels: | |
416 | ax.cbar.set_label(self.cb_labels[n], size=8) |
|
416 | ax.cbar.set_label(self.cb_labels[n], size=8) | |
417 | else: |
|
417 | else: | |
418 | ax.cbar = None |
|
418 | ax.cbar = None | |
419 | ax.set_xlim(xmin, xmax) |
|
419 | ax.set_xlim(xmin, xmax) | |
420 | ax.set_ylim(ymin, ymax) |
|
420 | ax.set_ylim(ymin, ymax) | |
421 | ax.firsttime = False |
|
421 | ax.firsttime = False | |
422 | if self.grid: |
|
422 | if self.grid: | |
423 | ax.grid(True) |
|
423 | ax.grid(True) | |
424 | if not self.polar: |
|
424 | if not self.polar: | |
425 | ax.set_title('{} {} {}'.format( |
|
425 | ax.set_title('{} {} {}'.format( | |
426 | self.titles[n], |
|
426 | self.titles[n], | |
427 | self.getDateTime(self.data.max_time).strftime( |
|
427 | self.getDateTime(self.data.max_time).strftime( | |
428 | '%Y-%m-%d %H:%M:%S'), |
|
428 | '%Y-%m-%d %H:%M:%S'), | |
429 | self.time_label), |
|
429 | self.time_label), | |
430 | size=8) |
|
430 | size=8) | |
431 | else: |
|
431 | else: | |
432 | ax.set_title('{}'.format(self.titles[n]), size=8) |
|
432 | ax.set_title('{}'.format(self.titles[n]), size=8) | |
433 | ax.set_ylim(0, 90) |
|
433 | ax.set_ylim(0, 90) | |
434 | ax.set_yticks(numpy.arange(0, 90, 20)) |
|
434 | ax.set_yticks(numpy.arange(0, 90, 20)) | |
435 | ax.yaxis.labelpad = 40 |
|
435 | ax.yaxis.labelpad = 40 | |
436 |
|
436 | |||
437 | if self.firsttime: |
|
437 | if self.firsttime: | |
438 | for n, fig in enumerate(self.figures): |
|
438 | for n, fig in enumerate(self.figures): | |
439 | fig.subplots_adjust(**self.plots_adjust) |
|
439 | fig.subplots_adjust(**self.plots_adjust) | |
440 | self.firsttime = False |
|
440 | self.firsttime = False | |
441 |
|
441 | |||
442 | def clear_figures(self): |
|
442 | def clear_figures(self): | |
443 | ''' |
|
443 | ''' | |
444 | Reset axes for redraw plots |
|
444 | Reset axes for redraw plots | |
445 | ''' |
|
445 | ''' | |
446 |
|
446 | |||
447 | for ax in self.axes+self.pf_axes+self.cb_axes: |
|
447 | for ax in self.axes+self.pf_axes+self.cb_axes: | |
448 | ax.clear() |
|
448 | ax.clear() | |
449 | ax.firsttime = True |
|
449 | ax.firsttime = True | |
450 | if hasattr(ax, 'cbar') and ax.cbar: |
|
450 | if hasattr(ax, 'cbar') and ax.cbar: | |
451 | ax.cbar.remove() |
|
451 | ax.cbar.remove() | |
452 |
|
452 | |||
453 | def __plot(self): |
|
453 | def __plot(self): | |
454 | ''' |
|
454 | ''' | |
455 | Main function to plot, format and save figures |
|
455 | Main function to plot, format and save figures | |
456 | ''' |
|
456 | ''' | |
457 |
|
457 | |||
458 | self.plot() |
|
458 | self.plot() | |
459 | self.format() |
|
459 | self.format() | |
460 |
|
460 | |||
461 | for n, fig in enumerate(self.figures): |
|
461 | for n, fig in enumerate(self.figures): | |
462 | if self.nrows == 0 or self.nplots == 0: |
|
462 | if self.nrows == 0 or self.nplots == 0: | |
463 | log.warning('No data', self.name) |
|
463 | log.warning('No data', self.name) | |
464 | fig.text(0.5, 0.5, 'No Data', fontsize='large', ha='center') |
|
464 | fig.text(0.5, 0.5, 'No Data', fontsize='large', ha='center') | |
465 | fig.canvas.manager.set_window_title(self.CODE) |
|
465 | fig.canvas.manager.set_window_title(self.CODE) | |
466 | continue |
|
466 | continue | |
467 |
|
467 | |||
468 | fig.canvas.manager.set_window_title('{} - {}'.format(self.title, |
|
468 | fig.canvas.manager.set_window_title('{} - {}'.format(self.title, | |
469 | self.getDateTime(self.data.max_time).strftime('%Y/%m/%d'))) |
|
469 | self.getDateTime(self.data.max_time).strftime('%Y/%m/%d'))) | |
470 | fig.canvas.draw() |
|
470 | fig.canvas.draw() | |
471 | if self.show: |
|
471 | if self.show: | |
472 | fig.show() |
|
472 | fig.show() | |
473 | figpause(0.01) |
|
473 | figpause(0.01) | |
474 |
|
474 | |||
475 | if self.save: |
|
475 | if self.save: | |
476 | self.save_figure(n) |
|
476 | self.save_figure(n) | |
477 |
|
477 | |||
478 | if self.server: |
|
478 | if self.server: | |
479 | self.send_to_server() |
|
479 | self.send_to_server() | |
480 |
|
480 | |||
|
481 | def __update(self, dataOut, timestamp): | |||
|
482 | ''' | |||
|
483 | ''' | |||
|
484 | ||||
|
485 | metadata = { | |||
|
486 | 'yrange': dataOut.heightList, | |||
|
487 | 'interval': dataOut.timeInterval, | |||
|
488 | 'channels': dataOut.channelList | |||
|
489 | } | |||
|
490 | ||||
|
491 | data, meta = self.update(dataOut) | |||
|
492 | metadata.update(meta) | |||
|
493 | self.data.update(data, timestamp, metadata) | |||
|
494 | ||||
481 | def save_figure(self, n): |
|
495 | def save_figure(self, n): | |
482 | ''' |
|
496 | ''' | |
483 | ''' |
|
497 | ''' | |
484 |
|
498 | |||
485 | if (self.data.tm - self.save_time) <= self.save_period: |
|
499 | if (self.data.max_time - self.save_time) <= self.save_period: | |
486 | return |
|
500 | return | |
487 |
|
501 | |||
488 | self.save_time = self.data.tm |
|
502 | self.save_time = self.data.max_time | |
489 |
|
503 | |||
490 | fig = self.figures[n] |
|
504 | fig = self.figures[n] | |
491 |
|
505 | |||
492 | figname = os.path.join( |
|
506 | figname = os.path.join( | |
493 | self.save, |
|
507 | self.save, | |
494 | self.save_code, |
|
508 | self.save_code, | |
495 | '{}_{}.png'.format( |
|
509 | '{}_{}.png'.format( | |
496 | self.save_code, |
|
510 | self.save_code, | |
497 | self.getDateTime(self.data.max_time).strftime( |
|
511 | self.getDateTime(self.data.max_time).strftime( | |
498 | '%Y%m%d_%H%M%S' |
|
512 | '%Y%m%d_%H%M%S' | |
499 | ), |
|
513 | ), | |
500 | ) |
|
514 | ) | |
501 | ) |
|
515 | ) | |
502 | log.log('Saving figure: {}'.format(figname), self.name) |
|
516 | log.log('Saving figure: {}'.format(figname), self.name) | |
503 | if not os.path.isdir(os.path.dirname(figname)): |
|
517 | if not os.path.isdir(os.path.dirname(figname)): | |
504 | os.makedirs(os.path.dirname(figname)) |
|
518 | os.makedirs(os.path.dirname(figname)) | |
505 | fig.savefig(figname) |
|
519 | fig.savefig(figname) | |
506 |
|
520 | |||
507 | if self.throttle == 0: |
|
521 | if self.throttle == 0: | |
508 | figname = os.path.join( |
|
522 | figname = os.path.join( | |
509 | self.save, |
|
523 | self.save, | |
510 | '{}_{}.png'.format( |
|
524 | '{}_{}.png'.format( | |
511 | self.save_code, |
|
525 | self.save_code, | |
512 | self.getDateTime(self.data.min_time).strftime( |
|
526 | self.getDateTime(self.data.min_time).strftime( | |
513 | '%Y%m%d' |
|
527 | '%Y%m%d' | |
514 | ), |
|
528 | ), | |
515 | ) |
|
529 | ) | |
516 | ) |
|
530 | ) | |
517 | fig.savefig(figname) |
|
531 | fig.savefig(figname) | |
518 |
|
532 | |||
519 | def send_to_server(self): |
|
533 | def send_to_server(self): | |
520 | ''' |
|
534 | ''' | |
521 | ''' |
|
535 | ''' | |
522 |
|
536 | |||
523 | interval = self.data.tm - self.sender_time |
|
537 | if self.exp_code == None: | |
|
538 | log.warning('Missing `exp_code` skipping sending to server...') | |||
|
539 | ||||
|
540 | last_time = self.data.max_time | |||
|
541 | interval = last_time - self.sender_time | |||
524 | if interval < self.sender_period: |
|
542 | if interval < self.sender_period: | |
525 | return |
|
543 | return | |
526 |
|
544 | |||
527 |
self.sender_time = |
|
545 | self.sender_time = last_time | |
528 |
|
546 | |||
529 | attrs = ['titles', 'zmin', 'zmax', 'tag', 'ymin', 'ymax'] |
|
547 | attrs = ['titles', 'zmin', 'zmax', 'tag', 'ymin', 'ymax'] | |
530 | for attr in attrs: |
|
548 | for attr in attrs: | |
531 | value = getattr(self, attr) |
|
549 | value = getattr(self, attr) | |
532 | if value: |
|
550 | if value: | |
533 | if isinstance(value, (numpy.float32, numpy.float64)): |
|
551 | if isinstance(value, (numpy.float32, numpy.float64)): | |
534 | value = round(float(value), 2) |
|
552 | value = round(float(value), 2) | |
535 | self.data.meta[attr] = value |
|
553 | self.data.meta[attr] = value | |
536 | if self.colormap == 'jet': |
|
554 | if self.colormap == 'jet': | |
537 | self.data.meta['colormap'] = 'Jet' |
|
555 | self.data.meta['colormap'] = 'Jet' | |
538 | elif 'RdBu' in self.colormap: |
|
556 | elif 'RdBu' in self.colormap: | |
539 | self.data.meta['colormap'] = 'RdBu' |
|
557 | self.data.meta['colormap'] = 'RdBu' | |
540 | else: |
|
558 | else: | |
541 | self.data.meta['colormap'] = 'Viridis' |
|
559 | self.data.meta['colormap'] = 'Viridis' | |
542 | self.data.meta['interval'] = int(interval) |
|
560 | self.data.meta['interval'] = int(interval) | |
543 |
|
561 | |||
544 | try: |
|
562 | self.sender_queue.append(last_time) | |
545 | self.sender_queue.put(self.data.tm, block=False) |
|
|||
546 | except: |
|
|||
547 | tm = self.sender_queue.get() |
|
|||
548 | self.sender_queue.put(self.data.tm) |
|
|||
549 |
|
563 | |||
550 | while True: |
|
564 | while True: | |
551 | if self.sender_queue.empty(): |
|
|||
552 | break |
|
|||
553 | tm = self.sender_queue.get() |
|
|||
554 | try: |
|
565 | try: | |
555 | msg = self.data.jsonify(tm, self.save_code, self.plot_type) |
|
566 | tm = self.sender_queue.popleft() | |
556 | except: |
|
567 | except IndexError: | |
557 |
|
|
568 | break | |
|
569 | msg = self.data.jsonify(tm, self.save_code, self.plot_type) | |||
558 | self.socket.send_string(msg) |
|
570 | self.socket.send_string(msg) | |
559 |
socks = dict(self.poll.poll( |
|
571 | socks = dict(self.poll.poll(2000)) | |
560 | if socks.get(self.socket) == zmq.POLLIN: |
|
572 | if socks.get(self.socket) == zmq.POLLIN: | |
561 | reply = self.socket.recv_string() |
|
573 | reply = self.socket.recv_string() | |
562 | if reply == 'ok': |
|
574 | if reply == 'ok': | |
563 | log.log("Response from server ok", self.name) |
|
575 | log.log("Response from server ok", self.name) | |
564 |
time.sleep(0. |
|
576 | time.sleep(0.1) | |
565 | continue |
|
577 | continue | |
566 | else: |
|
578 | else: | |
567 | log.warning( |
|
579 | log.warning( | |
568 | "Malformed reply from server: {}".format(reply), self.name) |
|
580 | "Malformed reply from server: {}".format(reply), self.name) | |
569 | else: |
|
581 | else: | |
570 | log.warning( |
|
582 | log.warning( | |
571 | "No response from server, retrying...", self.name) |
|
583 | "No response from server, retrying...", self.name) | |
572 |
|
|
584 | self.sender_queue.appendleft(tm) | |
573 | self.socket.setsockopt(zmq.LINGER, 0) |
|
585 | self.socket.setsockopt(zmq.LINGER, 0) | |
574 | self.socket.close() |
|
586 | self.socket.close() | |
575 | self.poll.unregister(self.socket) |
|
587 | self.poll.unregister(self.socket) | |
576 | time.sleep(0.1) |
|
|||
577 | self.socket = self.context.socket(zmq.REQ) |
|
588 | self.socket = self.context.socket(zmq.REQ) | |
578 | self.socket.connect(self.server) |
|
589 | self.socket.connect(self.server) | |
579 | self.poll.register(self.socket, zmq.POLLIN) |
|
590 | self.poll.register(self.socket, zmq.POLLIN) | |
580 | break |
|
591 | break | |
581 |
|
592 | |||
582 | def setup(self): |
|
593 | def setup(self): | |
583 | ''' |
|
594 | ''' | |
584 | This method should be implemented in the child class, the following |
|
595 | This method should be implemented in the child class, the following | |
585 | attributes should be set: |
|
596 | attributes should be set: | |
586 |
|
597 | |||
587 | self.nrows: number of rows |
|
598 | self.nrows: number of rows | |
588 | self.ncols: number of cols |
|
599 | self.ncols: number of cols | |
589 | self.nplots: number of plots (channels or pairs) |
|
600 | self.nplots: number of plots (channels or pairs) | |
590 | self.ylabel: label for Y axes |
|
601 | self.ylabel: label for Y axes | |
591 | self.titles: list of axes title |
|
602 | self.titles: list of axes title | |
592 |
|
603 | |||
593 | ''' |
|
604 | ''' | |
594 | raise NotImplementedError |
|
605 | raise NotImplementedError | |
595 |
|
606 | |||
596 | def plot(self): |
|
607 | def plot(self): | |
597 | ''' |
|
608 | ''' | |
598 | Must be defined in the child class |
|
609 | Must be defined in the child class, the actual plotting method | |
599 | ''' |
|
610 | ''' | |
600 | raise NotImplementedError |
|
611 | raise NotImplementedError | |
|
612 | ||||
|
613 | def update(self, dataOut): | |||
|
614 | ''' | |||
|
615 | Must be defined in the child class, update self.data with new data | |||
|
616 | ''' | |||
|
617 | ||||
|
618 | data = { | |||
|
619 | self.CODE: getattr(dataOut, 'data_{}'.format(self.CODE)) | |||
|
620 | } | |||
|
621 | meta = {} | |||
|
622 | ||||
|
623 | return data, meta | |||
601 |
|
624 | |||
602 | def run(self, dataOut, **kwargs): |
|
625 | def run(self, dataOut, **kwargs): | |
603 | ''' |
|
626 | ''' | |
604 | Main plotting routine |
|
627 | Main plotting routine | |
605 | ''' |
|
628 | ''' | |
606 |
|
629 | |||
607 | if self.isConfig is False: |
|
630 | if self.isConfig is False: | |
608 | self.__setup(**kwargs) |
|
631 | self.__setup(**kwargs) | |
609 |
|
632 | |||
610 | if self.localtime: |
|
633 | if self.localtime: | |
611 | self.getDateTime = datetime.datetime.fromtimestamp |
|
634 | self.getDateTime = datetime.datetime.fromtimestamp | |
612 | else: |
|
635 | else: | |
613 | self.getDateTime = datetime.datetime.utcfromtimestamp |
|
636 | self.getDateTime = datetime.datetime.utcfromtimestamp | |
614 |
|
637 | |||
615 | self.data.setup() |
|
638 | self.data.setup() | |
616 | self.isConfig = True |
|
639 | self.isConfig = True | |
617 | if self.server: |
|
640 | if self.server: | |
618 | self.context = zmq.Context() |
|
641 | self.context = zmq.Context() | |
619 | self.socket = self.context.socket(zmq.REQ) |
|
642 | self.socket = self.context.socket(zmq.REQ) | |
620 | self.socket.connect(self.server) |
|
643 | self.socket.connect(self.server) | |
621 | self.poll = zmq.Poller() |
|
644 | self.poll = zmq.Poller() | |
622 | self.poll.register(self.socket, zmq.POLLIN) |
|
645 | self.poll.register(self.socket, zmq.POLLIN) | |
623 |
|
646 | |||
624 | tm = getattr(dataOut, self.attr_time) |
|
647 | tm = getattr(dataOut, self.attr_time) | |
625 |
|
648 | |||
626 |
if self.data and 'time' in self.xaxis and (tm - self.tmin) >= self.xrange*60*60: |
|
649 | if self.data and 'time' in self.xaxis and (tm - self.tmin) >= self.xrange*60*60: | |
627 | self.save_time = tm |
|
650 | self.save_time = tm | |
628 | self.__plot() |
|
651 | self.__plot() | |
629 | self.tmin += self.xrange*60*60 |
|
652 | self.tmin += self.xrange*60*60 | |
630 | self.data.setup() |
|
653 | self.data.setup() | |
631 | self.clear_figures() |
|
654 | self.clear_figures() | |
632 |
|
655 | |||
633 |
self. |
|
656 | self.__update(dataOut, tm) | |
634 |
|
657 | |||
635 | if self.isPlotConfig is False: |
|
658 | if self.isPlotConfig is False: | |
636 | self.__setup_plot() |
|
659 | self.__setup_plot() | |
637 | self.isPlotConfig = True |
|
660 | self.isPlotConfig = True | |
638 | if self.xaxis == 'time': |
|
661 | if self.xaxis == 'time': | |
639 | dt = self.getDateTime(tm) |
|
662 | dt = self.getDateTime(tm) | |
640 | if self.xmin is None: |
|
663 | if self.xmin is None: | |
641 | self.tmin = tm |
|
664 | self.tmin = tm | |
642 | self.xmin = dt.hour |
|
665 | self.xmin = dt.hour | |
643 | minutes = (self.xmin-int(self.xmin)) * 60 |
|
666 | minutes = (self.xmin-int(self.xmin)) * 60 | |
644 | seconds = (minutes - int(minutes)) * 60 |
|
667 | seconds = (minutes - int(minutes)) * 60 | |
645 | self.tmin = (dt.replace(hour=int(self.xmin), minute=int(minutes), second=int(seconds)) - |
|
668 | self.tmin = (dt.replace(hour=int(self.xmin), minute=int(minutes), second=int(seconds)) - | |
646 | datetime.datetime(1970, 1, 1)).total_seconds() |
|
669 | datetime.datetime(1970, 1, 1)).total_seconds() | |
647 | if self.localtime: |
|
670 | if self.localtime: | |
648 | self.tmin += time.timezone |
|
671 | self.tmin += time.timezone | |
649 |
|
672 | |||
650 | if self.xmin is not None and self.xmax is not None: |
|
673 | if self.xmin is not None and self.xmax is not None: | |
651 | self.xrange = self.xmax - self.xmin |
|
674 | self.xrange = self.xmax - self.xmin | |
652 |
|
675 | |||
653 | if self.throttle == 0: |
|
676 | if self.throttle == 0: | |
654 | self.__plot() |
|
677 | self.__plot() | |
655 | else: |
|
678 | else: | |
656 | self.__throttle_plot(self.__plot)#, coerce=coerce) |
|
679 | self.__throttle_plot(self.__plot)#, coerce=coerce) | |
657 |
|
680 | |||
658 | def close(self): |
|
681 | def close(self): | |
659 |
|
682 | |||
660 | if self.data and not self.data.flagNoData: |
|
683 | if self.data and not self.data.flagNoData: | |
661 | self.save_time = self.data.tm |
|
684 | self.save_time = self.data.max_time | |
662 | self.__plot() |
|
685 | self.__plot() | |
663 | if self.data and not self.data.flagNoData and self.pause: |
|
686 | if self.data and not self.data.flagNoData and self.pause: | |
664 | figpause(10) |
|
687 | figpause(10) | |
665 |
|
688 |
@@ -1,342 +1,101 | |||||
1 | ''' |
|
1 | # Copyright (c) 2012-2020 Jicamarca Radio Observatory | |
2 | Created on Jul 9, 2014 |
|
2 | # All rights reserved. | |
|
3 | # | |||
|
4 | # Distributed under the terms of the BSD 3-clause license. | |||
|
5 | """Classes to plo Specra Heis data | |||
3 |
|
6 | |||
4 | @author: roj-idl71 |
|
7 | """ | |
5 | ''' |
|
|||
6 | import os |
|
|||
7 | import datetime |
|
|||
8 | import numpy |
|
|||
9 |
|
||||
10 | from schainpy.model.graphics.jroplot_base import Plot |
|
|||
11 |
|
||||
12 |
|
||||
13 | class SpectraHeisScope(Plot): |
|
|||
14 |
|
||||
15 |
|
||||
16 | isConfig = None |
|
|||
17 | __nsubplots = None |
|
|||
18 |
|
||||
19 | WIDTHPROF = None |
|
|||
20 | HEIGHTPROF = None |
|
|||
21 | PREFIX = 'spc' |
|
|||
22 |
|
||||
23 | def __init__(self):#, **kwargs): |
|
|||
24 |
|
||||
25 | Plot.__init__(self)#, **kwargs) |
|
|||
26 | self.isConfig = False |
|
|||
27 | self.__nsubplots = 1 |
|
|||
28 |
|
||||
29 | self.WIDTH = 230 |
|
|||
30 | self.HEIGHT = 250 |
|
|||
31 | self.WIDTHPROF = 120 |
|
|||
32 | self.HEIGHTPROF = 0 |
|
|||
33 | self.counter_imagwr = 0 |
|
|||
34 |
|
||||
35 | self.PLOT_CODE = SPEC_CODE |
|
|||
36 |
|
||||
37 | def getSubplots(self): |
|
|||
38 |
|
||||
39 | ncol = int(numpy.sqrt(self.nplots)+0.9) |
|
|||
40 | nrow = int(self.nplots*1./ncol + 0.9) |
|
|||
41 |
|
||||
42 | return nrow, ncol |
|
|||
43 |
|
||||
44 | def setup(self, id, nplots, wintitle, show): |
|
|||
45 |
|
||||
46 | showprofile = False |
|
|||
47 | self.__showprofile = showprofile |
|
|||
48 | self.nplots = nplots |
|
|||
49 |
|
||||
50 | ncolspan = 1 |
|
|||
51 | colspan = 1 |
|
|||
52 | if showprofile: |
|
|||
53 | ncolspan = 3 |
|
|||
54 | colspan = 2 |
|
|||
55 | self.__nsubplots = 2 |
|
|||
56 |
|
||||
57 | self.createFigure(id = id, |
|
|||
58 | wintitle = wintitle, |
|
|||
59 | widthplot = self.WIDTH + self.WIDTHPROF, |
|
|||
60 | heightplot = self.HEIGHT + self.HEIGHTPROF, |
|
|||
61 | show = show) |
|
|||
62 |
|
||||
63 | nrow, ncol = self.getSubplots() |
|
|||
64 |
|
||||
65 | counter = 0 |
|
|||
66 | for y in range(nrow): |
|
|||
67 | for x in range(ncol): |
|
|||
68 |
|
||||
69 | if counter >= self.nplots: |
|
|||
70 | break |
|
|||
71 |
|
||||
72 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1) |
|
|||
73 |
|
||||
74 | if showprofile: |
|
|||
75 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1) |
|
|||
76 |
|
||||
77 | counter += 1 |
|
|||
78 |
|
||||
79 |
|
||||
80 | def run(self, dataOut, id, wintitle="", channelList=None, |
|
|||
81 | xmin=None, xmax=None, ymin=None, ymax=None, save=False, |
|
|||
82 | figpath='./', figfile=None, ftp=False, wr_period=1, show=True, |
|
|||
83 | server=None, folder=None, username=None, password=None, |
|
|||
84 | ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0): |
|
|||
85 |
|
||||
86 | """ |
|
|||
87 |
|
||||
88 | Input: |
|
|||
89 | dataOut : |
|
|||
90 | id : |
|
|||
91 | wintitle : |
|
|||
92 | channelList : |
|
|||
93 | xmin : None, |
|
|||
94 | xmax : None, |
|
|||
95 | ymin : None, |
|
|||
96 | ymax : None, |
|
|||
97 | """ |
|
|||
98 |
|
||||
99 | if dataOut.flagNoData: |
|
|||
100 | return dataOut |
|
|||
101 |
|
||||
102 | if dataOut.realtime: |
|
|||
103 | if not(isRealtime(utcdatatime = dataOut.utctime)): |
|
|||
104 | print('Skipping this plot function') |
|
|||
105 | return |
|
|||
106 |
|
||||
107 | if channelList == None: |
|
|||
108 | channelIndexList = dataOut.channelIndexList |
|
|||
109 | else: |
|
|||
110 | channelIndexList = [] |
|
|||
111 | for channel in channelList: |
|
|||
112 | if channel not in dataOut.channelList: |
|
|||
113 | raise ValueError("Channel %d is not in dataOut.channelList") |
|
|||
114 | channelIndexList.append(dataOut.channelList.index(channel)) |
|
|||
115 |
|
||||
116 | # x = dataOut.heightList |
|
|||
117 | c = 3E8 |
|
|||
118 | deltaHeight = dataOut.heightList[1] - dataOut.heightList[0] |
|
|||
119 | #deberia cambiar para el caso de 1Mhz y 100KHz |
|
|||
120 | x = numpy.arange(-1*dataOut.nHeights/2.,dataOut.nHeights/2.)*(c/(2*deltaHeight*dataOut.nHeights*1000)) |
|
|||
121 | #para 1Mhz descomentar la siguiente linea |
|
|||
122 | #x= x/(10000.0) |
|
|||
123 | # y = dataOut.data[channelIndexList,:] * numpy.conjugate(dataOut.data[channelIndexList,:]) |
|
|||
124 | # y = y.real |
|
|||
125 | factor = dataOut.normFactor |
|
|||
126 | data = dataOut.data_spc / factor |
|
|||
127 | datadB = 10.*numpy.log10(data) |
|
|||
128 | y = datadB |
|
|||
129 |
|
||||
130 | #thisDatetime = dataOut.datatime |
|
|||
131 | thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0]) |
|
|||
132 | title = wintitle + " Scope: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) |
|
|||
133 | xlabel = "" |
|
|||
134 | #para 1Mhz descomentar la siguiente linea |
|
|||
135 | #xlabel = "Frequency x 10000" |
|
|||
136 | ylabel = "Intensity (dB)" |
|
|||
137 |
|
||||
138 | if not self.isConfig: |
|
|||
139 | nplots = len(channelIndexList) |
|
|||
140 |
|
||||
141 | self.setup(id=id, |
|
|||
142 | nplots=nplots, |
|
|||
143 | wintitle=wintitle, |
|
|||
144 | show=show) |
|
|||
145 |
|
||||
146 | if xmin == None: xmin = numpy.nanmin(x) |
|
|||
147 | if xmax == None: xmax = numpy.nanmax(x) |
|
|||
148 | if ymin == None: ymin = numpy.nanmin(y) |
|
|||
149 | if ymax == None: ymax = numpy.nanmax(y) |
|
|||
150 |
|
||||
151 | self.FTP_WEI = ftp_wei |
|
|||
152 | self.EXP_CODE = exp_code |
|
|||
153 | self.SUB_EXP_CODE = sub_exp_code |
|
|||
154 | self.PLOT_POS = plot_pos |
|
|||
155 |
|
||||
156 | self.isConfig = True |
|
|||
157 |
|
||||
158 | self.setWinTitle(title) |
|
|||
159 |
|
||||
160 | for i in range(len(self.axesList)): |
|
|||
161 | ychannel = y[i,:] |
|
|||
162 | str_datetime = '%s %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S")) |
|
|||
163 | title = "Channel %d: %4.2fdB: %s" %(dataOut.channelList[channelIndexList[i]], numpy.max(ychannel), str_datetime) |
|
|||
164 | axes = self.axesList[i] |
|
|||
165 | axes.pline(x, ychannel, |
|
|||
166 | xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, |
|
|||
167 | xlabel=xlabel, ylabel=ylabel, title=title, grid='both') |
|
|||
168 |
|
||||
169 |
|
||||
170 | self.draw() |
|
|||
171 |
|
||||
172 | self.save(figpath=figpath, |
|
|||
173 | figfile=figfile, |
|
|||
174 | save=save, |
|
|||
175 | ftp=ftp, |
|
|||
176 | wr_period=wr_period, |
|
|||
177 | thisDatetime=thisDatetime) |
|
|||
178 |
|
||||
179 | return dataOut |
|
|||
180 |
|
||||
181 |
|
||||
182 | class RTIfromSpectraHeis(Plot): |
|
|||
183 |
|
||||
184 | isConfig = None |
|
|||
185 | __nsubplots = None |
|
|||
186 |
|
||||
187 | PREFIX = 'rtinoise' |
|
|||
188 |
|
||||
189 | def __init__(self):#, **kwargs): |
|
|||
190 | Plot.__init__(self)#, **kwargs) |
|
|||
191 | self.timerange = 24*60*60 |
|
|||
192 | self.isConfig = False |
|
|||
193 | self.__nsubplots = 1 |
|
|||
194 |
|
||||
195 | self.WIDTH = 820 |
|
|||
196 | self.HEIGHT = 200 |
|
|||
197 | self.WIDTHPROF = 120 |
|
|||
198 | self.HEIGHTPROF = 0 |
|
|||
199 | self.counter_imagwr = 0 |
|
|||
200 | self.xdata = None |
|
|||
201 | self.ydata = None |
|
|||
202 | self.figfile = None |
|
|||
203 |
|
||||
204 | self.PLOT_CODE = RTI_CODE |
|
|||
205 |
|
||||
206 | def getSubplots(self): |
|
|||
207 |
|
||||
208 | ncol = 1 |
|
|||
209 | nrow = 1 |
|
|||
210 |
|
||||
211 | return nrow, ncol |
|
|||
212 |
|
||||
213 | def setup(self, id, nplots, wintitle, showprofile=True, show=True): |
|
|||
214 |
|
||||
215 | self.__showprofile = showprofile |
|
|||
216 | self.nplots = nplots |
|
|||
217 |
|
||||
218 | ncolspan = 7 |
|
|||
219 | colspan = 6 |
|
|||
220 | self.__nsubplots = 2 |
|
|||
221 |
|
||||
222 | self.createFigure(id = id, |
|
|||
223 | wintitle = wintitle, |
|
|||
224 | widthplot = self.WIDTH+self.WIDTHPROF, |
|
|||
225 | heightplot = self.HEIGHT+self.HEIGHTPROF, |
|
|||
226 | show = show) |
|
|||
227 |
|
||||
228 | nrow, ncol = self.getSubplots() |
|
|||
229 |
|
||||
230 | self.addAxes(nrow, ncol*ncolspan, 0, 0, colspan, 1) |
|
|||
231 |
|
8 | |||
|
9 | import numpy | |||
232 |
|
10 | |||
233 | def run(self, dataOut, id, wintitle="", channelList=None, showprofile='True', |
|
11 | from schainpy.model.graphics.jroplot_base import Plot, plt | |
234 | xmin=None, xmax=None, ymin=None, ymax=None, |
|
|||
235 | timerange=None, |
|
|||
236 | save=False, figpath='./', figfile=None, ftp=False, wr_period=1, show=True, |
|
|||
237 | server=None, folder=None, username=None, password=None, |
|
|||
238 | ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0): |
|
|||
239 |
|
12 | |||
240 | if dataOut.flagNoData: |
|
|||
241 | return dataOut |
|
|||
242 |
|
13 | |||
|
14 | class SpectraHeisPlot(Plot): | |||
243 |
|
15 | |||
244 | if channelList == None: |
|
16 | CODE = 'spc_heis' | |
245 | channelIndexList = dataOut.channelIndexList |
|
|||
246 | channelList = dataOut.channelList |
|
|||
247 | else: |
|
|||
248 | channelIndexList = [] |
|
|||
249 | for channel in channelList: |
|
|||
250 | if channel not in dataOut.channelList: |
|
|||
251 | raise ValueError("Channel %d is not in dataOut.channelList") |
|
|||
252 | channelIndexList.append(dataOut.channelList.index(channel)) |
|
|||
253 |
|
17 | |||
254 | if timerange != None: |
|
18 | def setup(self): | |
255 | self.timerange = timerange |
|
|||
256 |
|
19 | |||
257 | x = dataOut.getTimeRange() |
|
20 | self.nplots = len(self.data.channels) | |
258 | y = dataOut.heightList |
|
21 | self.ncols = int(numpy.sqrt(self.nplots) + 0.9) | |
|
22 | self.nrows = int((1.0 * self.nplots / self.ncols) + 0.9) | |||
|
23 | self.height = 2.6 * self.nrows | |||
|
24 | self.width = 3.5 * self.ncols | |||
|
25 | self.plots_adjust.update({'wspace': 0.4, 'hspace':0.4, 'left': 0.1, 'right': 0.95, 'bottom': 0.08}) | |||
|
26 | self.ylabel = 'Intensity [dB]' | |||
|
27 | self.xlabel = 'Frequency [KHz]' | |||
|
28 | self.colorbar = False | |||
259 |
|
29 | |||
260 | factor = dataOut.normFactor |
|
30 | def update(self, dataOut): | |
261 | data = dataOut.data_spc / factor |
|
|||
262 | data = numpy.average(data,axis=1) |
|
|||
263 | datadB = 10*numpy.log10(data) |
|
|||
264 |
|
31 | |||
265 | # factor = dataOut.normFactor |
|
32 | data = {} | |
266 | # noise = dataOut.getNoise()/factor |
|
33 | meta = {} | |
267 | # noisedB = 10*numpy.log10(noise) |
|
34 | spc = 10*numpy.log10(dataOut.data_spc / dataOut.normFactor) | |
|
35 | data['spc_heis'] = spc | |||
|
36 | ||||
|
37 | return data, meta | |||
268 |
|
38 | |||
269 | #thisDatetime = dataOut.datatime |
|
39 | def plot(self): | |
270 | thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0]) |
|
|||
271 | title = wintitle + " RTI: %s" %(thisDatetime.strftime("%d-%b-%Y")) |
|
|||
272 | xlabel = "Local Time" |
|
|||
273 | ylabel = "Intensity (dB)" |
|
|||
274 |
|
40 | |||
275 | if not self.isConfig: |
|
41 | c = 3E8 | |
|
42 | deltaHeight = self.data.yrange[1] - self.data.yrange[0] | |||
|
43 | x = numpy.arange(-1*len(self.data.yrange)/2., len(self.data.yrange)/2.)*(c/(2*deltaHeight*len(self.data.yrange)*1000)) | |||
|
44 | self.y = self.data[-1]['spc_heis'] | |||
|
45 | self.titles = [] | |||
276 |
|
46 | |||
277 | nplots = 1 |
|
47 | for n, ax in enumerate(self.axes): | |
|
48 | ychannel = self.y[n,:] | |||
|
49 | if ax.firsttime: | |||
|
50 | self.xmin = min(x) if self.xmin is None else self.xmin | |||
|
51 | self.xmax = max(x) if self.xmax is None else self.xmax | |||
|
52 | ax.plt = ax.plot(x, ychannel, lw=1, color='b')[0] | |||
|
53 | else: | |||
|
54 | ax.plt.set_data(x, ychannel) | |||
278 |
|
55 | |||
279 | self.setup(id=id, |
|
56 | self.titles.append("Channel {}: {:4.2f}dB".format(n, numpy.max(ychannel))) | |
280 | nplots=nplots, |
|
|||
281 | wintitle=wintitle, |
|
|||
282 | showprofile=showprofile, |
|
|||
283 | show=show) |
|
|||
284 |
|
57 | |||
285 | self.tmin, self.tmax = self.getTimeLim(x, xmin, xmax) |
|
|||
286 |
|
58 | |||
287 | if ymin == None: ymin = numpy.nanmin(datadB) |
|
59 | class RTIHeisPlot(Plot): | |
288 | if ymax == None: ymax = numpy.nanmax(datadB) |
|
|||
289 |
|
60 | |||
290 | self.name = thisDatetime.strftime("%Y%m%d_%H%M%S") |
|
61 | CODE = 'rti_heis' | |
291 | self.isConfig = True |
|
|||
292 | self.figfile = figfile |
|
|||
293 | self.xdata = numpy.array([]) |
|
|||
294 | self.ydata = numpy.array([]) |
|
|||
295 |
|
62 | |||
296 | self.FTP_WEI = ftp_wei |
|
63 | def setup(self): | |
297 | self.EXP_CODE = exp_code |
|
|||
298 | self.SUB_EXP_CODE = sub_exp_code |
|
|||
299 | self.PLOT_POS = plot_pos |
|
|||
300 |
|
64 | |||
301 | self.setWinTitle(title) |
|
65 | self.xaxis = 'time' | |
|
66 | self.ncols = 1 | |||
|
67 | self.nrows = 1 | |||
|
68 | self.nplots = 1 | |||
|
69 | self.ylabel = 'Intensity [dB]' | |||
|
70 | self.xlabel = 'Time' | |||
|
71 | self.titles = ['RTI'] | |||
|
72 | self.colorbar = False | |||
|
73 | self.height = 4 | |||
|
74 | self.plots_adjust.update({'right': 0.85 }) | |||
302 |
|
75 | |||
|
76 | def update(self, dataOut): | |||
303 |
|
77 | |||
304 | # title = "RTI %s" %(thisDatetime.strftime("%d-%b-%Y")) |
|
78 | data = {} | |
305 | title = "RTI - %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) |
|
79 | meta = {} | |
|
80 | spc = dataOut.data_spc / dataOut.normFactor | |||
|
81 | spc = 10*numpy.log10(numpy.average(spc, axis=1)) | |||
|
82 | data['rti_heis'] = spc | |||
|
83 | ||||
|
84 | return data, meta | |||
306 |
|
85 | |||
307 | legendlabels = ["channel %d"%idchannel for idchannel in channelList] |
|
86 | def plot(self): | |
308 | axes = self.axesList[0] |
|
|||
309 |
|
87 | |||
310 | self.xdata = numpy.hstack((self.xdata, x[0:1])) |
|
88 | x = self.data.times | |
|
89 | Y = self.data['rti_heis'] | |||
311 |
|
90 | |||
312 | if len(self.ydata)==0: |
|
91 | if self.axes[0].firsttime: | |
313 | self.ydata = datadB[channelIndexList].reshape(-1,1) |
|
92 | self.ymin = numpy.nanmin(Y) - 5 if self.ymin == None else self.ymin | |
|
93 | self.ymax = numpy.nanmax(Y) + 5 if self.ymax == None else self.ymax | |||
|
94 | for ch in self.data.channels: | |||
|
95 | y = Y[ch] | |||
|
96 | self.axes[0].plot(x, y, lw=1, label='Ch{}'.format(ch)) | |||
|
97 | plt.legend(bbox_to_anchor=(1.18, 1.0)) | |||
314 | else: |
|
98 | else: | |
315 | self.ydata = numpy.hstack((self.ydata, datadB[channelIndexList].reshape(-1,1))) |
|
99 | for ch in self.data.channels: | |
316 |
|
100 | y = Y[ch] | ||
317 |
|
101 | self.axes[0].lines[ch].set_data(x, y) | ||
318 | axes.pmultilineyaxis(x=self.xdata, y=self.ydata, |
|
|||
319 | xmin=self.tmin, xmax=self.tmax, ymin=ymin, ymax=ymax, |
|
|||
320 | xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels, marker='.', markersize=8, linestyle="solid", grid='both', |
|
|||
321 | XAxisAsTime=True |
|
|||
322 | ) |
|
|||
323 |
|
||||
324 | self.draw() |
|
|||
325 |
|
||||
326 | update_figfile = False |
|
|||
327 |
|
||||
328 | if dataOut.ltctime >= self.tmax: |
|
|||
329 | self.counter_imagwr = wr_period |
|
|||
330 | self.isConfig = False |
|
|||
331 | update_figfile = True |
|
|||
332 |
|
||||
333 | self.save(figpath=figpath, |
|
|||
334 | figfile=figfile, |
|
|||
335 | save=save, |
|
|||
336 | ftp=ftp, |
|
|||
337 | wr_period=wr_period, |
|
|||
338 | thisDatetime=thisDatetime, |
|
|||
339 | update_figfile=update_figfile) |
|
|||
340 |
|
||||
341 |
|
||||
342 | return dataOut No newline at end of file |
|
@@ -1,339 +1,358 | |||||
1 | import os |
|
1 | import os | |
2 | import datetime |
|
2 | import datetime | |
3 | import numpy |
|
3 | import numpy | |
4 |
|
4 | |||
5 | from schainpy.model.graphics.jroplot_base import Plot, plt |
|
5 | from schainpy.model.graphics.jroplot_base import Plot, plt | |
6 | from schainpy.model.graphics.jroplot_spectra import SpectraPlot, RTIPlot, CoherencePlot |
|
6 | from schainpy.model.graphics.jroplot_spectra import SpectraPlot, RTIPlot, CoherencePlot | |
7 | from schainpy.utils import log |
|
7 | from schainpy.utils import log | |
8 |
|
8 | |||
9 | EARTH_RADIUS = 6.3710e3 |
|
9 | EARTH_RADIUS = 6.3710e3 | |
10 |
|
10 | |||
11 |
|
11 | |||
12 | def ll2xy(lat1, lon1, lat2, lon2): |
|
12 | def ll2xy(lat1, lon1, lat2, lon2): | |
13 |
|
13 | |||
14 | p = 0.017453292519943295 |
|
14 | p = 0.017453292519943295 | |
15 | a = 0.5 - numpy.cos((lat2 - lat1) * p)/2 + numpy.cos(lat1 * p) * \ |
|
15 | a = 0.5 - numpy.cos((lat2 - lat1) * p)/2 + numpy.cos(lat1 * p) * \ | |
16 | numpy.cos(lat2 * p) * (1 - numpy.cos((lon2 - lon1) * p)) / 2 |
|
16 | numpy.cos(lat2 * p) * (1 - numpy.cos((lon2 - lon1) * p)) / 2 | |
17 | r = 12742 * numpy.arcsin(numpy.sqrt(a)) |
|
17 | r = 12742 * numpy.arcsin(numpy.sqrt(a)) | |
18 | theta = numpy.arctan2(numpy.sin((lon2-lon1)*p)*numpy.cos(lat2*p), numpy.cos(lat1*p) |
|
18 | theta = numpy.arctan2(numpy.sin((lon2-lon1)*p)*numpy.cos(lat2*p), numpy.cos(lat1*p) | |
19 | * numpy.sin(lat2*p)-numpy.sin(lat1*p)*numpy.cos(lat2*p)*numpy.cos((lon2-lon1)*p)) |
|
19 | * numpy.sin(lat2*p)-numpy.sin(lat1*p)*numpy.cos(lat2*p)*numpy.cos((lon2-lon1)*p)) | |
20 | theta = -theta + numpy.pi/2 |
|
20 | theta = -theta + numpy.pi/2 | |
21 | return r*numpy.cos(theta), r*numpy.sin(theta) |
|
21 | return r*numpy.cos(theta), r*numpy.sin(theta) | |
22 |
|
22 | |||
23 |
|
23 | |||
24 | def km2deg(km): |
|
24 | def km2deg(km): | |
25 | ''' |
|
25 | ''' | |
26 | Convert distance in km to degrees |
|
26 | Convert distance in km to degrees | |
27 | ''' |
|
27 | ''' | |
28 |
|
28 | |||
29 | return numpy.rad2deg(km/EARTH_RADIUS) |
|
29 | return numpy.rad2deg(km/EARTH_RADIUS) | |
30 |
|
30 | |||
31 |
|
31 | |||
32 |
|
32 | |||
33 | class SpectralMomentsPlot(SpectraPlot): |
|
33 | class SpectralMomentsPlot(SpectraPlot): | |
34 | ''' |
|
34 | ''' | |
35 | Plot for Spectral Moments |
|
35 | Plot for Spectral Moments | |
36 | ''' |
|
36 | ''' | |
37 | CODE = 'spc_moments' |
|
37 | CODE = 'spc_moments' | |
38 | colormap = 'jet' |
|
38 | colormap = 'jet' | |
39 | plot_type = 'pcolor' |
|
39 | plot_type = 'pcolor' | |
40 |
|
40 | |||
41 |
|
41 | |||
42 | class SnrPlot(RTIPlot): |
|
42 | class SnrPlot(RTIPlot): | |
43 | ''' |
|
43 | ''' | |
44 | Plot for SNR Data |
|
44 | Plot for SNR Data | |
45 | ''' |
|
45 | ''' | |
46 |
|
46 | |||
47 | CODE = 'snr' |
|
47 | CODE = 'snr' | |
48 | colormap = 'jet' |
|
48 | colormap = 'jet' | |
49 |
|
49 | |||
|
50 | def update(self, dataOut): | |||
|
51 | ||||
|
52 | data = { | |||
|
53 | 'snr': 10*numpy.log10(dataOut.data_snr) | |||
|
54 | } | |||
|
55 | ||||
|
56 | return data, {} | |||
50 |
|
57 | |||
51 | class DopplerPlot(RTIPlot): |
|
58 | class DopplerPlot(RTIPlot): | |
52 | ''' |
|
59 | ''' | |
53 | Plot for DOPPLER Data (1st moment) |
|
60 | Plot for DOPPLER Data (1st moment) | |
54 | ''' |
|
61 | ''' | |
55 |
|
62 | |||
56 | CODE = 'dop' |
|
63 | CODE = 'dop' | |
57 | colormap = 'jet' |
|
64 | colormap = 'jet' | |
58 |
|
65 | |||
|
66 | def update(self, dataOut): | |||
|
67 | ||||
|
68 | data = { | |||
|
69 | 'dop': 10*numpy.log10(dataOut.data_dop) | |||
|
70 | } | |||
|
71 | ||||
|
72 | return data, {} | |||
59 |
|
73 | |||
60 | class PowerPlot(RTIPlot): |
|
74 | class PowerPlot(RTIPlot): | |
61 | ''' |
|
75 | ''' | |
62 | Plot for Power Data (0 moment) |
|
76 | Plot for Power Data (0 moment) | |
63 | ''' |
|
77 | ''' | |
64 |
|
78 | |||
65 | CODE = 'pow' |
|
79 | CODE = 'pow' | |
66 | colormap = 'jet' |
|
80 | colormap = 'jet' | |
67 |
|
81 | |||
|
82 | def update(self, dataOut): | |||
|
83 | ||||
|
84 | data = { | |||
|
85 | 'pow': 10*numpy.log10(dataOut.data_pow) | |||
|
86 | } | |||
|
87 | ||||
|
88 | return data, {} | |||
68 |
|
89 | |||
69 | class SpectralWidthPlot(RTIPlot): |
|
90 | class SpectralWidthPlot(RTIPlot): | |
70 | ''' |
|
91 | ''' | |
71 | Plot for Spectral Width Data (2nd moment) |
|
92 | Plot for Spectral Width Data (2nd moment) | |
72 | ''' |
|
93 | ''' | |
73 |
|
94 | |||
74 | CODE = 'width' |
|
95 | CODE = 'width' | |
75 | colormap = 'jet' |
|
96 | colormap = 'jet' | |
76 |
|
97 | |||
|
98 | def update(self, dataOut): | |||
|
99 | ||||
|
100 | data = { | |||
|
101 | 'width': dataOut.data_width | |||
|
102 | } | |||
|
103 | ||||
|
104 | return data, {} | |||
77 |
|
105 | |||
78 | class SkyMapPlot(Plot): |
|
106 | class SkyMapPlot(Plot): | |
79 | ''' |
|
107 | ''' | |
80 | Plot for meteors detection data |
|
108 | Plot for meteors detection data | |
81 | ''' |
|
109 | ''' | |
82 |
|
110 | |||
83 | CODE = 'param' |
|
111 | CODE = 'param' | |
84 |
|
112 | |||
85 | def setup(self): |
|
113 | def setup(self): | |
86 |
|
114 | |||
87 | self.ncols = 1 |
|
115 | self.ncols = 1 | |
88 | self.nrows = 1 |
|
116 | self.nrows = 1 | |
89 | self.width = 7.2 |
|
117 | self.width = 7.2 | |
90 | self.height = 7.2 |
|
118 | self.height = 7.2 | |
91 | self.nplots = 1 |
|
119 | self.nplots = 1 | |
92 | self.xlabel = 'Zonal Zenith Angle (deg)' |
|
120 | self.xlabel = 'Zonal Zenith Angle (deg)' | |
93 | self.ylabel = 'Meridional Zenith Angle (deg)' |
|
121 | self.ylabel = 'Meridional Zenith Angle (deg)' | |
94 | self.polar = True |
|
122 | self.polar = True | |
95 | self.ymin = -180 |
|
123 | self.ymin = -180 | |
96 | self.ymax = 180 |
|
124 | self.ymax = 180 | |
97 | self.colorbar = False |
|
125 | self.colorbar = False | |
98 |
|
126 | |||
99 | def plot(self): |
|
127 | def plot(self): | |
100 |
|
128 | |||
101 | arrayParameters = numpy.concatenate(self.data['param']) |
|
129 | arrayParameters = numpy.concatenate(self.data['param']) | |
102 | error = arrayParameters[:, -1] |
|
130 | error = arrayParameters[:, -1] | |
103 | indValid = numpy.where(error == 0)[0] |
|
131 | indValid = numpy.where(error == 0)[0] | |
104 | finalMeteor = arrayParameters[indValid, :] |
|
132 | finalMeteor = arrayParameters[indValid, :] | |
105 | finalAzimuth = finalMeteor[:, 3] |
|
133 | finalAzimuth = finalMeteor[:, 3] | |
106 | finalZenith = finalMeteor[:, 4] |
|
134 | finalZenith = finalMeteor[:, 4] | |
107 |
|
135 | |||
108 | x = finalAzimuth * numpy.pi / 180 |
|
136 | x = finalAzimuth * numpy.pi / 180 | |
109 | y = finalZenith |
|
137 | y = finalZenith | |
110 |
|
138 | |||
111 | ax = self.axes[0] |
|
139 | ax = self.axes[0] | |
112 |
|
140 | |||
113 | if ax.firsttime: |
|
141 | if ax.firsttime: | |
114 | ax.plot = ax.plot(x, y, 'bo', markersize=5)[0] |
|
142 | ax.plot = ax.plot(x, y, 'bo', markersize=5)[0] | |
115 | else: |
|
143 | else: | |
116 | ax.plot.set_data(x, y) |
|
144 | ax.plot.set_data(x, y) | |
117 |
|
145 | |||
118 | dt1 = self.getDateTime(self.data.min_time).strftime('%y/%m/%d %H:%M:%S') |
|
146 | dt1 = self.getDateTime(self.data.min_time).strftime('%y/%m/%d %H:%M:%S') | |
119 | dt2 = self.getDateTime(self.data.max_time).strftime('%y/%m/%d %H:%M:%S') |
|
147 | dt2 = self.getDateTime(self.data.max_time).strftime('%y/%m/%d %H:%M:%S') | |
120 | title = 'Meteor Detection Sky Map\n %s - %s \n Number of events: %5.0f\n' % (dt1, |
|
148 | title = 'Meteor Detection Sky Map\n %s - %s \n Number of events: %5.0f\n' % (dt1, | |
121 | dt2, |
|
149 | dt2, | |
122 | len(x)) |
|
150 | len(x)) | |
123 | self.titles[0] = title |
|
151 | self.titles[0] = title | |
124 |
|
152 | |||
125 |
|
153 | |||
126 |
class |
|
154 | class GenericRTIPlot(Plot): | |
127 | ''' |
|
155 | ''' | |
128 |
Plot for data_ |
|
156 | Plot for data_xxxx object | |
129 | ''' |
|
157 | ''' | |
130 |
|
158 | |||
131 | CODE = 'param' |
|
159 | CODE = 'param' | |
132 |
colormap = ' |
|
160 | colormap = 'viridis' | |
|
161 | plot_type = 'pcolorbuffer' | |||
133 |
|
162 | |||
134 | def setup(self): |
|
163 | def setup(self): | |
135 | self.xaxis = 'time' |
|
164 | self.xaxis = 'time' | |
136 | self.ncols = 1 |
|
165 | self.ncols = 1 | |
137 |
self.nrows = self.data.shape(self. |
|
166 | self.nrows = self.data.shape(self.attr_data)[0] | |
138 | self.nplots = self.nrows |
|
167 | self.nplots = self.nrows | |
139 | self.plots_adjust.update({'hspace':0.8, 'left': 0.1, 'bottom': 0.08, 'right':0.95, 'top': 0.95}) |
|
168 | self.plots_adjust.update({'hspace':0.8, 'left': 0.1, 'bottom': 0.08, 'right':0.95, 'top': 0.95}) | |
140 |
|
169 | |||
141 | if not self.xlabel: |
|
170 | if not self.xlabel: | |
142 | self.xlabel = 'Time' |
|
171 | self.xlabel = 'Time' | |
143 |
|
||||
144 | if self.showSNR: |
|
|||
145 | self.nrows += 1 |
|
|||
146 | self.nplots += 1 |
|
|||
147 |
|
172 | |||
148 | self.ylabel = 'Height [km]' |
|
173 | self.ylabel = 'Height [km]' | |
149 | if not self.titles: |
|
174 | if not self.titles: | |
150 | self.titles = self.data.parameters \ |
|
175 | self.titles = self.data.parameters \ | |
151 | if self.data.parameters else ['Param {}'.format(x) for x in range(self.nrows)] |
|
176 | if self.data.parameters else ['Param {}'.format(x) for x in range(self.nrows)] | |
152 | if self.showSNR: |
|
|||
153 | self.titles.append('SNR') |
|
|||
154 |
|
177 | |||
|
178 | def update(self, dataOut): | |||
|
179 | ||||
|
180 | data = { | |||
|
181 | self.attr_data : getattr(dataOut, self.attr_data) | |||
|
182 | } | |||
|
183 | ||||
|
184 | meta = {} | |||
|
185 | ||||
|
186 | return data, meta | |||
|
187 | ||||
155 | def plot(self): |
|
188 | def plot(self): | |
156 | self.data.normalize_heights() |
|
189 | # self.data.normalize_heights() | |
157 | self.x = self.data.times |
|
190 | self.x = self.data.times | |
158 |
self.y = self.data. |
|
191 | self.y = self.data.yrange | |
159 | if self.showSNR: |
|
192 | self.z = self.data[self.attr_data] | |
160 | self.z = numpy.concatenate( |
|
|||
161 | (self.data[self.CODE], self.data['snr']) |
|
|||
162 | ) |
|
|||
163 | else: |
|
|||
164 | self.z = self.data[self.CODE] |
|
|||
165 |
|
193 | |||
166 | self.z = numpy.ma.masked_invalid(self.z) |
|
194 | self.z = numpy.ma.masked_invalid(self.z) | |
167 |
|
195 | |||
168 | if self.decimation is None: |
|
196 | if self.decimation is None: | |
169 | x, y, z = self.fill_gaps(self.x, self.y, self.z) |
|
197 | x, y, z = self.fill_gaps(self.x, self.y, self.z) | |
170 | else: |
|
198 | else: | |
171 | x, y, z = self.fill_gaps(*self.decimate()) |
|
199 | x, y, z = self.fill_gaps(*self.decimate()) | |
172 |
|
200 | |||
173 | for n, ax in enumerate(self.axes): |
|
201 | for n, ax in enumerate(self.axes): | |
174 |
|
202 | |||
175 | self.zmax = self.zmax if self.zmax is not None else numpy.max( |
|
203 | self.zmax = self.zmax if self.zmax is not None else numpy.max( | |
176 | self.z[n]) |
|
204 | self.z[n]) | |
177 | self.zmin = self.zmin if self.zmin is not None else numpy.min( |
|
205 | self.zmin = self.zmin if self.zmin is not None else numpy.min( | |
178 | self.z[n]) |
|
206 | self.z[n]) | |
179 |
|
207 | |||
180 | if ax.firsttime: |
|
208 | if ax.firsttime: | |
181 | if self.zlimits is not None: |
|
209 | if self.zlimits is not None: | |
182 | self.zmin, self.zmax = self.zlimits[n] |
|
210 | self.zmin, self.zmax = self.zlimits[n] | |
183 |
|
211 | |||
184 | ax.plt = ax.pcolormesh(x, y, z[n].T * self.factors[n], |
|
212 | ax.plt = ax.pcolormesh(x, y, z[n].T * self.factors[n], | |
185 | vmin=self.zmin, |
|
213 | vmin=self.zmin, | |
186 | vmax=self.zmax, |
|
214 | vmax=self.zmax, | |
187 | cmap=self.cmaps[n] |
|
215 | cmap=self.cmaps[n] | |
188 | ) |
|
216 | ) | |
189 | else: |
|
217 | else: | |
190 | if self.zlimits is not None: |
|
218 | if self.zlimits is not None: | |
191 | self.zmin, self.zmax = self.zlimits[n] |
|
219 | self.zmin, self.zmax = self.zlimits[n] | |
192 | ax.collections.remove(ax.collections[0]) |
|
220 | ax.collections.remove(ax.collections[0]) | |
193 | ax.plt = ax.pcolormesh(x, y, z[n].T * self.factors[n], |
|
221 | ax.plt = ax.pcolormesh(x, y, z[n].T * self.factors[n], | |
194 | vmin=self.zmin, |
|
222 | vmin=self.zmin, | |
195 | vmax=self.zmax, |
|
223 | vmax=self.zmax, | |
196 | cmap=self.cmaps[n] |
|
224 | cmap=self.cmaps[n] | |
197 | ) |
|
225 | ) | |
198 |
|
226 | |||
199 |
|
227 | |||
200 | class OutputPlot(ParametersPlot): |
|
|||
201 | ''' |
|
|||
202 | Plot data_output object |
|
|||
203 | ''' |
|
|||
204 |
|
||||
205 | CODE = 'output' |
|
|||
206 | colormap = 'seismic' |
|
|||
207 |
|
||||
208 |
|
||||
209 | class PolarMapPlot(Plot): |
|
228 | class PolarMapPlot(Plot): | |
210 | ''' |
|
229 | ''' | |
211 | Plot for weather radar |
|
230 | Plot for weather radar | |
212 | ''' |
|
231 | ''' | |
213 |
|
232 | |||
214 | CODE = 'param' |
|
233 | CODE = 'param' | |
215 | colormap = 'seismic' |
|
234 | colormap = 'seismic' | |
216 |
|
235 | |||
217 | def setup(self): |
|
236 | def setup(self): | |
218 | self.ncols = 1 |
|
237 | self.ncols = 1 | |
219 | self.nrows = 1 |
|
238 | self.nrows = 1 | |
220 | self.width = 9 |
|
239 | self.width = 9 | |
221 | self.height = 8 |
|
240 | self.height = 8 | |
222 | self.mode = self.data.meta['mode'] |
|
241 | self.mode = self.data.meta['mode'] | |
223 | if self.channels is not None: |
|
242 | if self.channels is not None: | |
224 | self.nplots = len(self.channels) |
|
243 | self.nplots = len(self.channels) | |
225 | self.nrows = len(self.channels) |
|
244 | self.nrows = len(self.channels) | |
226 | else: |
|
245 | else: | |
227 | self.nplots = self.data.shape(self.CODE)[0] |
|
246 | self.nplots = self.data.shape(self.CODE)[0] | |
228 | self.nrows = self.nplots |
|
247 | self.nrows = self.nplots | |
229 | self.channels = list(range(self.nplots)) |
|
248 | self.channels = list(range(self.nplots)) | |
230 | if self.mode == 'E': |
|
249 | if self.mode == 'E': | |
231 | self.xlabel = 'Longitude' |
|
250 | self.xlabel = 'Longitude' | |
232 | self.ylabel = 'Latitude' |
|
251 | self.ylabel = 'Latitude' | |
233 | else: |
|
252 | else: | |
234 | self.xlabel = 'Range (km)' |
|
253 | self.xlabel = 'Range (km)' | |
235 | self.ylabel = 'Height (km)' |
|
254 | self.ylabel = 'Height (km)' | |
236 | self.bgcolor = 'white' |
|
255 | self.bgcolor = 'white' | |
237 | self.cb_labels = self.data.meta['units'] |
|
256 | self.cb_labels = self.data.meta['units'] | |
238 | self.lat = self.data.meta['latitude'] |
|
257 | self.lat = self.data.meta['latitude'] | |
239 | self.lon = self.data.meta['longitude'] |
|
258 | self.lon = self.data.meta['longitude'] | |
240 | self.xmin, self.xmax = float( |
|
259 | self.xmin, self.xmax = float( | |
241 | km2deg(self.xmin) + self.lon), float(km2deg(self.xmax) + self.lon) |
|
260 | km2deg(self.xmin) + self.lon), float(km2deg(self.xmax) + self.lon) | |
242 | self.ymin, self.ymax = float( |
|
261 | self.ymin, self.ymax = float( | |
243 | km2deg(self.ymin) + self.lat), float(km2deg(self.ymax) + self.lat) |
|
262 | km2deg(self.ymin) + self.lat), float(km2deg(self.ymax) + self.lat) | |
244 | # self.polar = True |
|
263 | # self.polar = True | |
245 |
|
264 | |||
246 | def plot(self): |
|
265 | def plot(self): | |
247 |
|
266 | |||
248 | for n, ax in enumerate(self.axes): |
|
267 | for n, ax in enumerate(self.axes): | |
249 | data = self.data['param'][self.channels[n]] |
|
268 | data = self.data['param'][self.channels[n]] | |
250 |
|
269 | |||
251 | zeniths = numpy.linspace( |
|
270 | zeniths = numpy.linspace( | |
252 | 0, self.data.meta['max_range'], data.shape[1]) |
|
271 | 0, self.data.meta['max_range'], data.shape[1]) | |
253 | if self.mode == 'E': |
|
272 | if self.mode == 'E': | |
254 |
azimuths = -numpy.radians(self.data. |
|
273 | azimuths = -numpy.radians(self.data.yrange)+numpy.pi/2 | |
255 | r, theta = numpy.meshgrid(zeniths, azimuths) |
|
274 | r, theta = numpy.meshgrid(zeniths, azimuths) | |
256 | x, y = r*numpy.cos(theta)*numpy.cos(numpy.radians(self.data.meta['elevation'])), r*numpy.sin( |
|
275 | x, y = r*numpy.cos(theta)*numpy.cos(numpy.radians(self.data.meta['elevation'])), r*numpy.sin( | |
257 | theta)*numpy.cos(numpy.radians(self.data.meta['elevation'])) |
|
276 | theta)*numpy.cos(numpy.radians(self.data.meta['elevation'])) | |
258 | x = km2deg(x) + self.lon |
|
277 | x = km2deg(x) + self.lon | |
259 | y = km2deg(y) + self.lat |
|
278 | y = km2deg(y) + self.lat | |
260 | else: |
|
279 | else: | |
261 |
azimuths = numpy.radians(self.data. |
|
280 | azimuths = numpy.radians(self.data.yrange) | |
262 | r, theta = numpy.meshgrid(zeniths, azimuths) |
|
281 | r, theta = numpy.meshgrid(zeniths, azimuths) | |
263 | x, y = r*numpy.cos(theta), r*numpy.sin(theta) |
|
282 | x, y = r*numpy.cos(theta), r*numpy.sin(theta) | |
264 | self.y = zeniths |
|
283 | self.y = zeniths | |
265 |
|
284 | |||
266 | if ax.firsttime: |
|
285 | if ax.firsttime: | |
267 | if self.zlimits is not None: |
|
286 | if self.zlimits is not None: | |
268 | self.zmin, self.zmax = self.zlimits[n] |
|
287 | self.zmin, self.zmax = self.zlimits[n] | |
269 | ax.plt = ax.pcolormesh( # r, theta, numpy.ma.array(data, mask=numpy.isnan(data)), |
|
288 | ax.plt = ax.pcolormesh( # r, theta, numpy.ma.array(data, mask=numpy.isnan(data)), | |
270 | x, y, numpy.ma.array(data, mask=numpy.isnan(data)), |
|
289 | x, y, numpy.ma.array(data, mask=numpy.isnan(data)), | |
271 | vmin=self.zmin, |
|
290 | vmin=self.zmin, | |
272 | vmax=self.zmax, |
|
291 | vmax=self.zmax, | |
273 | cmap=self.cmaps[n]) |
|
292 | cmap=self.cmaps[n]) | |
274 | else: |
|
293 | else: | |
275 | if self.zlimits is not None: |
|
294 | if self.zlimits is not None: | |
276 | self.zmin, self.zmax = self.zlimits[n] |
|
295 | self.zmin, self.zmax = self.zlimits[n] | |
277 | ax.collections.remove(ax.collections[0]) |
|
296 | ax.collections.remove(ax.collections[0]) | |
278 | ax.plt = ax.pcolormesh( # r, theta, numpy.ma.array(data, mask=numpy.isnan(data)), |
|
297 | ax.plt = ax.pcolormesh( # r, theta, numpy.ma.array(data, mask=numpy.isnan(data)), | |
279 | x, y, numpy.ma.array(data, mask=numpy.isnan(data)), |
|
298 | x, y, numpy.ma.array(data, mask=numpy.isnan(data)), | |
280 | vmin=self.zmin, |
|
299 | vmin=self.zmin, | |
281 | vmax=self.zmax, |
|
300 | vmax=self.zmax, | |
282 | cmap=self.cmaps[n]) |
|
301 | cmap=self.cmaps[n]) | |
283 |
|
302 | |||
284 | if self.mode == 'A': |
|
303 | if self.mode == 'A': | |
285 | continue |
|
304 | continue | |
286 |
|
305 | |||
287 | # plot district names |
|
306 | # plot district names | |
288 | f = open('/data/workspace/schain_scripts/distrito.csv') |
|
307 | f = open('/data/workspace/schain_scripts/distrito.csv') | |
289 | for line in f: |
|
308 | for line in f: | |
290 | label, lon, lat = [s.strip() for s in line.split(',') if s] |
|
309 | label, lon, lat = [s.strip() for s in line.split(',') if s] | |
291 | lat = float(lat) |
|
310 | lat = float(lat) | |
292 | lon = float(lon) |
|
311 | lon = float(lon) | |
293 | # ax.plot(lon, lat, '.b', ms=2) |
|
312 | # ax.plot(lon, lat, '.b', ms=2) | |
294 | ax.text(lon, lat, label.decode('utf8'), ha='center', |
|
313 | ax.text(lon, lat, label.decode('utf8'), ha='center', | |
295 | va='bottom', size='8', color='black') |
|
314 | va='bottom', size='8', color='black') | |
296 |
|
315 | |||
297 | # plot limites |
|
316 | # plot limites | |
298 | limites = [] |
|
317 | limites = [] | |
299 | tmp = [] |
|
318 | tmp = [] | |
300 | for line in open('/data/workspace/schain_scripts/lima.csv'): |
|
319 | for line in open('/data/workspace/schain_scripts/lima.csv'): | |
301 | if '#' in line: |
|
320 | if '#' in line: | |
302 | if tmp: |
|
321 | if tmp: | |
303 | limites.append(tmp) |
|
322 | limites.append(tmp) | |
304 | tmp = [] |
|
323 | tmp = [] | |
305 | continue |
|
324 | continue | |
306 | values = line.strip().split(',') |
|
325 | values = line.strip().split(',') | |
307 | tmp.append((float(values[0]), float(values[1]))) |
|
326 | tmp.append((float(values[0]), float(values[1]))) | |
308 | for points in limites: |
|
327 | for points in limites: | |
309 | ax.add_patch( |
|
328 | ax.add_patch( | |
310 | Polygon(points, ec='k', fc='none', ls='--', lw=0.5)) |
|
329 | Polygon(points, ec='k', fc='none', ls='--', lw=0.5)) | |
311 |
|
330 | |||
312 | # plot Cuencas |
|
331 | # plot Cuencas | |
313 | for cuenca in ('rimac', 'lurin', 'mala', 'chillon', 'chilca', 'chancay-huaral'): |
|
332 | for cuenca in ('rimac', 'lurin', 'mala', 'chillon', 'chilca', 'chancay-huaral'): | |
314 | f = open('/data/workspace/schain_scripts/{}.csv'.format(cuenca)) |
|
333 | f = open('/data/workspace/schain_scripts/{}.csv'.format(cuenca)) | |
315 | values = [line.strip().split(',') for line in f] |
|
334 | values = [line.strip().split(',') for line in f] | |
316 | points = [(float(s[0]), float(s[1])) for s in values] |
|
335 | points = [(float(s[0]), float(s[1])) for s in values] | |
317 | ax.add_patch(Polygon(points, ec='b', fc='none')) |
|
336 | ax.add_patch(Polygon(points, ec='b', fc='none')) | |
318 |
|
337 | |||
319 | # plot grid |
|
338 | # plot grid | |
320 | for r in (15, 30, 45, 60): |
|
339 | for r in (15, 30, 45, 60): | |
321 | ax.add_artist(plt.Circle((self.lon, self.lat), |
|
340 | ax.add_artist(plt.Circle((self.lon, self.lat), | |
322 | km2deg(r), color='0.6', fill=False, lw=0.2)) |
|
341 | km2deg(r), color='0.6', fill=False, lw=0.2)) | |
323 | ax.text( |
|
342 | ax.text( | |
324 | self.lon + (km2deg(r))*numpy.cos(60*numpy.pi/180), |
|
343 | self.lon + (km2deg(r))*numpy.cos(60*numpy.pi/180), | |
325 | self.lat + (km2deg(r))*numpy.sin(60*numpy.pi/180), |
|
344 | self.lat + (km2deg(r))*numpy.sin(60*numpy.pi/180), | |
326 | '{}km'.format(r), |
|
345 | '{}km'.format(r), | |
327 | ha='center', va='bottom', size='8', color='0.6', weight='heavy') |
|
346 | ha='center', va='bottom', size='8', color='0.6', weight='heavy') | |
328 |
|
347 | |||
329 | if self.mode == 'E': |
|
348 | if self.mode == 'E': | |
330 | title = 'El={}$^\circ$'.format(self.data.meta['elevation']) |
|
349 | title = 'El={}$^\circ$'.format(self.data.meta['elevation']) | |
331 | label = 'E{:02d}'.format(int(self.data.meta['elevation'])) |
|
350 | label = 'E{:02d}'.format(int(self.data.meta['elevation'])) | |
332 | else: |
|
351 | else: | |
333 | title = 'Az={}$^\circ$'.format(self.data.meta['azimuth']) |
|
352 | title = 'Az={}$^\circ$'.format(self.data.meta['azimuth']) | |
334 | label = 'A{:02d}'.format(int(self.data.meta['azimuth'])) |
|
353 | label = 'A{:02d}'.format(int(self.data.meta['azimuth'])) | |
335 |
|
354 | |||
336 | self.save_labels = ['{}-{}'.format(lbl, label) for lbl in self.labels] |
|
355 | self.save_labels = ['{}-{}'.format(lbl, label) for lbl in self.labels] | |
337 | self.titles = ['{} {}'.format( |
|
356 | self.titles = ['{} {}'.format( | |
338 | self.data.parameters[x], title) for x in self.channels] |
|
357 | self.data.parameters[x], title) for x in self.channels] | |
339 |
|
358 |
@@ -1,641 +1,702 | |||||
1 | ''' |
|
1 | # Copyright (c) 2012-2020 Jicamarca Radio Observatory | |
2 | Created on Jul 9, 2014 |
|
2 | # All rights reserved. | |
3 | Modified on May 10, 2020 |
|
3 | # | |
|
4 | # Distributed under the terms of the BSD 3-clause license. | |||
|
5 | """Classes to plot Spectra data | |||
4 |
|
6 | |||
5 | @author: Juan C. Espinoza |
|
7 | """ | |
6 | ''' |
|
|||
7 |
|
8 | |||
8 | import os |
|
9 | import os | |
9 | import datetime |
|
|||
10 | import numpy |
|
10 | import numpy | |
11 |
|
11 | |||
12 | from schainpy.model.graphics.jroplot_base import Plot, plt |
|
12 | from schainpy.model.graphics.jroplot_base import Plot, plt, log | |
13 |
|
13 | |||
14 |
|
14 | |||
15 | class SpectraPlot(Plot): |
|
15 | class SpectraPlot(Plot): | |
16 | ''' |
|
16 | ''' | |
17 | Plot for Spectra data |
|
17 | Plot for Spectra data | |
18 | ''' |
|
18 | ''' | |
19 |
|
19 | |||
20 | CODE = 'spc' |
|
20 | CODE = 'spc' | |
21 | colormap = 'jet' |
|
21 | colormap = 'jet' | |
22 | plot_type = 'pcolor' |
|
22 | plot_type = 'pcolor' | |
|
23 | buffering = False | |||
23 |
|
24 | |||
24 | def setup(self): |
|
25 | def setup(self): | |
25 | self.nplots = len(self.data.channels) |
|
26 | self.nplots = len(self.data.channels) | |
26 | self.ncols = int(numpy.sqrt(self.nplots) + 0.9) |
|
27 | self.ncols = int(numpy.sqrt(self.nplots) + 0.9) | |
27 | self.nrows = int((1.0 * self.nplots / self.ncols) + 0.9) |
|
28 | self.nrows = int((1.0 * self.nplots / self.ncols) + 0.9) | |
28 | self.height = 2.6 * self.nrows |
|
29 | self.height = 2.6 * self.nrows | |
29 | self.cb_label = 'dB' |
|
30 | self.cb_label = 'dB' | |
30 | if self.showprofile: |
|
31 | if self.showprofile: | |
31 | self.width = 4 * self.ncols |
|
32 | self.width = 4 * self.ncols | |
32 | else: |
|
33 | else: | |
33 | self.width = 3.5 * self.ncols |
|
34 | self.width = 3.5 * self.ncols | |
34 | self.plots_adjust.update({'wspace': 0.4, 'hspace':0.4, 'left': 0.1, 'right': 0.9, 'bottom': 0.08}) |
|
35 | self.plots_adjust.update({'wspace': 0.4, 'hspace':0.4, 'left': 0.1, 'right': 0.9, 'bottom': 0.08}) | |
35 | self.ylabel = 'Range [km]' |
|
36 | self.ylabel = 'Range [km]' | |
36 |
|
37 | |||
|
38 | def update(self, dataOut): | |||
|
39 | ||||
|
40 | data = {} | |||
|
41 | meta = {} | |||
|
42 | spc = 10*numpy.log10(dataOut.data_spc/dataOut.normFactor) | |||
|
43 | data['spc'] = spc | |||
|
44 | data['rti'] = dataOut.getPower() | |||
|
45 | data['noise'] = 10*numpy.log10(dataOut.getNoise()/dataOut.normFactor) | |||
|
46 | meta['xrange'] = (dataOut.getFreqRange(1)/1000., dataOut.getAcfRange(1), dataOut.getVelRange(1)) | |||
|
47 | if self.CODE == 'spc_moments': | |||
|
48 | data['moments'] = dataOut.moments | |||
|
49 | ||||
|
50 | return data, meta | |||
|
51 | ||||
37 | def plot(self): |
|
52 | def plot(self): | |
38 | if self.xaxis == "frequency": |
|
53 | if self.xaxis == "frequency": | |
39 | x = self.data.xrange[0] |
|
54 | x = self.data.xrange[0] | |
40 | self.xlabel = "Frequency (kHz)" |
|
55 | self.xlabel = "Frequency (kHz)" | |
41 | elif self.xaxis == "time": |
|
56 | elif self.xaxis == "time": | |
42 | x = self.data.xrange[1] |
|
57 | x = self.data.xrange[1] | |
43 | self.xlabel = "Time (ms)" |
|
58 | self.xlabel = "Time (ms)" | |
44 | else: |
|
59 | else: | |
45 | x = self.data.xrange[2] |
|
60 | x = self.data.xrange[2] | |
46 | self.xlabel = "Velocity (m/s)" |
|
61 | self.xlabel = "Velocity (m/s)" | |
47 |
|
62 | |||
48 | if self.CODE == 'spc_moments': |
|
63 | if self.CODE == 'spc_moments': | |
49 | x = self.data.xrange[2] |
|
64 | x = self.data.xrange[2] | |
50 | self.xlabel = "Velocity (m/s)" |
|
65 | self.xlabel = "Velocity (m/s)" | |
51 |
|
66 | |||
52 | self.titles = [] |
|
67 | self.titles = [] | |
53 |
|
68 | |||
54 |
y = self.data. |
|
69 | y = self.data.yrange | |
55 | self.y = y |
|
70 | self.y = y | |
56 | z = self.data['spc'] |
|
71 | ||
|
72 | data = self.data[-1] | |||
|
73 | z = data['spc'] | |||
57 |
|
74 | |||
58 | for n, ax in enumerate(self.axes): |
|
75 | for n, ax in enumerate(self.axes): | |
59 |
noise = |
|
76 | noise = data['noise'][n] | |
60 | if self.CODE == 'spc_moments': |
|
77 | if self.CODE == 'spc_moments': | |
61 |
mean = |
|
78 | mean = data['moments'][n, 2] | |
62 | if ax.firsttime: |
|
79 | if ax.firsttime: | |
63 | self.xmax = self.xmax if self.xmax else numpy.nanmax(x) |
|
80 | self.xmax = self.xmax if self.xmax else numpy.nanmax(x) | |
64 | self.xmin = self.xmin if self.xmin else -self.xmax |
|
81 | self.xmin = self.xmin if self.xmin else -self.xmax | |
65 | self.zmin = self.zmin if self.zmin else numpy.nanmin(z) |
|
82 | self.zmin = self.zmin if self.zmin else numpy.nanmin(z) | |
66 | self.zmax = self.zmax if self.zmax else numpy.nanmax(z) |
|
83 | self.zmax = self.zmax if self.zmax else numpy.nanmax(z) | |
67 | ax.plt = ax.pcolormesh(x, y, z[n].T, |
|
84 | ax.plt = ax.pcolormesh(x, y, z[n].T, | |
68 | vmin=self.zmin, |
|
85 | vmin=self.zmin, | |
69 | vmax=self.zmax, |
|
86 | vmax=self.zmax, | |
70 | cmap=plt.get_cmap(self.colormap) |
|
87 | cmap=plt.get_cmap(self.colormap) | |
71 | ) |
|
88 | ) | |
72 |
|
89 | |||
73 | if self.showprofile: |
|
90 | if self.showprofile: | |
74 | ax.plt_profile = self.pf_axes[n].plot( |
|
91 | ax.plt_profile = self.pf_axes[n].plot( | |
75 |
|
|
92 | data['rti'][n], y)[0] | |
76 | ax.plt_noise = self.pf_axes[n].plot(numpy.repeat(noise, len(y)), y, |
|
93 | ax.plt_noise = self.pf_axes[n].plot(numpy.repeat(noise, len(y)), y, | |
77 | color="k", linestyle="dashed", lw=1)[0] |
|
94 | color="k", linestyle="dashed", lw=1)[0] | |
78 | if self.CODE == 'spc_moments': |
|
95 | if self.CODE == 'spc_moments': | |
79 | ax.plt_mean = ax.plot(mean, y, color='k')[0] |
|
96 | ax.plt_mean = ax.plot(mean, y, color='k')[0] | |
80 | else: |
|
97 | else: | |
81 | ax.plt.set_array(z[n].T.ravel()) |
|
98 | ax.plt.set_array(z[n].T.ravel()) | |
82 | if self.showprofile: |
|
99 | if self.showprofile: | |
83 |
ax.plt_profile.set_data( |
|
100 | ax.plt_profile.set_data(data['rti'][n], y) | |
84 | ax.plt_noise.set_data(numpy.repeat(noise, len(y)), y) |
|
101 | ax.plt_noise.set_data(numpy.repeat(noise, len(y)), y) | |
85 | if self.CODE == 'spc_moments': |
|
102 | if self.CODE == 'spc_moments': | |
86 | ax.plt_mean.set_data(mean, y) |
|
103 | ax.plt_mean.set_data(mean, y) | |
87 | self.titles.append('CH {}: {:3.2f}dB'.format(n, noise)) |
|
104 | self.titles.append('CH {}: {:3.2f}dB'.format(n, noise)) | |
88 |
|
105 | |||
89 |
|
106 | |||
90 | class CrossSpectraPlot(Plot): |
|
107 | class CrossSpectraPlot(Plot): | |
91 |
|
108 | |||
92 | CODE = 'cspc' |
|
109 | CODE = 'cspc' | |
93 | colormap = 'jet' |
|
110 | colormap = 'jet' | |
94 | plot_type = 'pcolor' |
|
111 | plot_type = 'pcolor' | |
95 | zmin_coh = None |
|
112 | zmin_coh = None | |
96 | zmax_coh = None |
|
113 | zmax_coh = None | |
97 | zmin_phase = None |
|
114 | zmin_phase = None | |
98 | zmax_phase = None |
|
115 | zmax_phase = None | |
99 |
|
116 | |||
100 | def setup(self): |
|
117 | def setup(self): | |
101 |
|
118 | |||
102 | self.ncols = 4 |
|
119 | self.ncols = 4 | |
103 |
self.n |
|
120 | self.nplots = len(self.data.pairs) * 2 | |
104 | self.nplots = self.nrows * 4 |
|
121 | self.nrows = int((1.0 * self.nplots / self.ncols) + 0.9) | |
105 | self.width = 3.1 * self.ncols |
|
122 | self.width = 3.1 * self.ncols | |
106 | self.height = 2.6 * self.nrows |
|
123 | self.height = 2.6 * self.nrows | |
107 | self.ylabel = 'Range [km]' |
|
124 | self.ylabel = 'Range [km]' | |
108 | self.showprofile = False |
|
125 | self.showprofile = False | |
109 | self.plots_adjust.update({'left': 0.08, 'right': 0.92, 'wspace': 0.5, 'hspace':0.4, 'top':0.95, 'bottom': 0.08}) |
|
126 | self.plots_adjust.update({'left': 0.08, 'right': 0.92, 'wspace': 0.5, 'hspace':0.4, 'top':0.95, 'bottom': 0.08}) | |
110 |
|
127 | |||
|
128 | def update(self, dataOut): | |||
|
129 | ||||
|
130 | data = {} | |||
|
131 | meta = {} | |||
|
132 | ||||
|
133 | spc = dataOut.data_spc | |||
|
134 | cspc = dataOut.data_cspc | |||
|
135 | meta['xrange'] = (dataOut.getFreqRange(1)/1000., dataOut.getAcfRange(1), dataOut.getVelRange(1)) | |||
|
136 | meta['pairs'] = dataOut.pairsList | |||
|
137 | ||||
|
138 | tmp = [] | |||
|
139 | ||||
|
140 | for n, pair in enumerate(meta['pairs']): | |||
|
141 | out = cspc[n] / numpy.sqrt(spc[pair[0]] * spc[pair[1]]) | |||
|
142 | coh = numpy.abs(out) | |||
|
143 | phase = numpy.arctan2(out.imag, out.real) * 180 / numpy.pi | |||
|
144 | tmp.append(coh) | |||
|
145 | tmp.append(phase) | |||
|
146 | ||||
|
147 | data['cspc'] = numpy.array(tmp) | |||
|
148 | ||||
|
149 | return data, meta | |||
|
150 | ||||
111 | def plot(self): |
|
151 | def plot(self): | |
112 |
|
152 | |||
113 | if self.xaxis == "frequency": |
|
153 | if self.xaxis == "frequency": | |
114 | x = self.data.xrange[0] |
|
154 | x = self.data.xrange[0] | |
115 | self.xlabel = "Frequency (kHz)" |
|
155 | self.xlabel = "Frequency (kHz)" | |
116 | elif self.xaxis == "time": |
|
156 | elif self.xaxis == "time": | |
117 | x = self.data.xrange[1] |
|
157 | x = self.data.xrange[1] | |
118 | self.xlabel = "Time (ms)" |
|
158 | self.xlabel = "Time (ms)" | |
119 | else: |
|
159 | else: | |
120 | x = self.data.xrange[2] |
|
160 | x = self.data.xrange[2] | |
121 | self.xlabel = "Velocity (m/s)" |
|
161 | self.xlabel = "Velocity (m/s)" | |
122 |
|
162 | |||
123 | self.titles = [] |
|
163 | self.titles = [] | |
124 |
|
164 | |||
125 |
y = self.data. |
|
165 | y = self.data.yrange | |
126 | self.y = y |
|
166 | self.y = y | |
127 | nspc = self.data['spc'] |
|
|||
128 | spc = self.data['cspc'][0] |
|
|||
129 | cspc = self.data['cspc'][1] |
|
|||
130 |
|
167 | |||
131 | for n in range(self.nrows): |
|
168 | data = self.data[-1] | |
132 | noise = self.data['noise'][:,-1] |
|
169 | cspc = data['cspc'] | |
133 | pair = self.data.pairs[n] |
|
|||
134 | ax = self.axes[4 * n] |
|
|||
135 | if ax.firsttime: |
|
|||
136 | self.xmax = self.xmax if self.xmax else numpy.nanmax(x) |
|
|||
137 | self.xmin = self.xmin if self.xmin else -self.xmax |
|
|||
138 | self.zmin = self.zmin if self.zmin else numpy.nanmin(nspc) |
|
|||
139 | self.zmax = self.zmax if self.zmax else numpy.nanmax(nspc) |
|
|||
140 | ax.plt = ax.pcolormesh(x , y , nspc[pair[0]].T, |
|
|||
141 | vmin=self.zmin, |
|
|||
142 | vmax=self.zmax, |
|
|||
143 | cmap=plt.get_cmap(self.colormap) |
|
|||
144 | ) |
|
|||
145 | else: |
|
|||
146 | ax.plt.set_array(nspc[pair[0]].T.ravel()) |
|
|||
147 | self.titles.append('CH {}: {:3.2f}dB'.format(pair[0], noise[pair[0]])) |
|
|||
148 |
|
||||
149 | ax = self.axes[4 * n + 1] |
|
|||
150 | if ax.firsttime: |
|
|||
151 | ax.plt = ax.pcolormesh(x , y, nspc[pair[1]].T, |
|
|||
152 | vmin=self.zmin, |
|
|||
153 | vmax=self.zmax, |
|
|||
154 | cmap=plt.get_cmap(self.colormap) |
|
|||
155 | ) |
|
|||
156 | else: |
|
|||
157 | ax.plt.set_array(nspc[pair[1]].T.ravel()) |
|
|||
158 | self.titles.append('CH {}: {:3.2f}dB'.format(pair[1], noise[pair[1]])) |
|
|||
159 |
|
||||
160 | out = cspc[n] / numpy.sqrt(spc[pair[0]] * spc[pair[1]]) |
|
|||
161 | coh = numpy.abs(out) |
|
|||
162 | phase = numpy.arctan2(out.imag, out.real) * 180 / numpy.pi |
|
|||
163 |
|
170 | |||
164 | ax = self.axes[4 * n + 2] |
|
171 | for n in range(len(self.data.pairs)): | |
|
172 | pair = self.data.pairs[n] | |||
|
173 | coh = cspc[n*2] | |||
|
174 | phase = cspc[n*2+1] | |||
|
175 | ax = self.axes[2 * n] | |||
165 | if ax.firsttime: |
|
176 | if ax.firsttime: | |
166 | ax.plt = ax.pcolormesh(x, y, coh.T, |
|
177 | ax.plt = ax.pcolormesh(x, y, coh.T, | |
167 | vmin=0, |
|
178 | vmin=0, | |
168 | vmax=1, |
|
179 | vmax=1, | |
169 | cmap=plt.get_cmap(self.colormap_coh) |
|
180 | cmap=plt.get_cmap(self.colormap_coh) | |
170 | ) |
|
181 | ) | |
171 | else: |
|
182 | else: | |
172 | ax.plt.set_array(coh.T.ravel()) |
|
183 | ax.plt.set_array(coh.T.ravel()) | |
173 | self.titles.append( |
|
184 | self.titles.append( | |
174 | 'Coherence Ch{} * Ch{}'.format(pair[0], pair[1])) |
|
185 | 'Coherence Ch{} * Ch{}'.format(pair[0], pair[1])) | |
175 |
|
186 | |||
176 |
ax = self.axes[ |
|
187 | ax = self.axes[2 * n + 1] | |
177 | if ax.firsttime: |
|
188 | if ax.firsttime: | |
178 | ax.plt = ax.pcolormesh(x, y, phase.T, |
|
189 | ax.plt = ax.pcolormesh(x, y, phase.T, | |
179 | vmin=-180, |
|
190 | vmin=-180, | |
180 | vmax=180, |
|
191 | vmax=180, | |
181 | cmap=plt.get_cmap(self.colormap_phase) |
|
192 | cmap=plt.get_cmap(self.colormap_phase) | |
182 | ) |
|
193 | ) | |
183 | else: |
|
194 | else: | |
184 | ax.plt.set_array(phase.T.ravel()) |
|
195 | ax.plt.set_array(phase.T.ravel()) | |
185 | self.titles.append('Phase CH{} * CH{}'.format(pair[0], pair[1])) |
|
196 | self.titles.append('Phase CH{} * CH{}'.format(pair[0], pair[1])) | |
186 |
|
197 | |||
187 |
|
198 | |||
188 | class RTIPlot(Plot): |
|
199 | class RTIPlot(Plot): | |
189 | ''' |
|
200 | ''' | |
190 | Plot for RTI data |
|
201 | Plot for RTI data | |
191 | ''' |
|
202 | ''' | |
192 |
|
203 | |||
193 | CODE = 'rti' |
|
204 | CODE = 'rti' | |
194 | colormap = 'jet' |
|
205 | colormap = 'jet' | |
195 | plot_type = 'pcolorbuffer' |
|
206 | plot_type = 'pcolorbuffer' | |
196 |
|
207 | |||
197 | def setup(self): |
|
208 | def setup(self): | |
198 | self.xaxis = 'time' |
|
209 | self.xaxis = 'time' | |
199 | self.ncols = 1 |
|
210 | self.ncols = 1 | |
200 | self.nrows = len(self.data.channels) |
|
211 | self.nrows = len(self.data.channels) | |
201 | self.nplots = len(self.data.channels) |
|
212 | self.nplots = len(self.data.channels) | |
202 | self.ylabel = 'Range [km]' |
|
213 | self.ylabel = 'Range [km]' | |
203 | self.xlabel = 'Time' |
|
214 | self.xlabel = 'Time' | |
204 | self.cb_label = 'dB' |
|
215 | self.cb_label = 'dB' | |
205 | self.plots_adjust.update({'hspace':0.8, 'left': 0.1, 'bottom': 0.08, 'right':0.95}) |
|
216 | self.plots_adjust.update({'hspace':0.8, 'left': 0.1, 'bottom': 0.08, 'right':0.95}) | |
206 | self.titles = ['{} Channel {}'.format( |
|
217 | self.titles = ['{} Channel {}'.format( | |
207 | self.CODE.upper(), x) for x in range(self.nrows)] |
|
218 | self.CODE.upper(), x) for x in range(self.nrows)] | |
208 |
|
219 | |||
|
220 | def update(self, dataOut): | |||
|
221 | ||||
|
222 | data = {} | |||
|
223 | meta = {} | |||
|
224 | data['rti'] = dataOut.getPower() | |||
|
225 | data['noise'] = 10*numpy.log10(dataOut.getNoise()/dataOut.normFactor) | |||
|
226 | ||||
|
227 | return data, meta | |||
|
228 | ||||
209 | def plot(self): |
|
229 | def plot(self): | |
210 | self.x = self.data.times |
|
230 | self.x = self.data.times | |
211 |
self.y = self.data. |
|
231 | self.y = self.data.yrange | |
212 | self.z = self.data[self.CODE] |
|
232 | self.z = self.data[self.CODE] | |
213 | self.z = numpy.ma.masked_invalid(self.z) |
|
233 | self.z = numpy.ma.masked_invalid(self.z) | |
214 |
|
234 | |||
215 | if self.decimation is None: |
|
235 | if self.decimation is None: | |
216 | x, y, z = self.fill_gaps(self.x, self.y, self.z) |
|
236 | x, y, z = self.fill_gaps(self.x, self.y, self.z) | |
217 | else: |
|
237 | else: | |
218 | x, y, z = self.fill_gaps(*self.decimate()) |
|
238 | x, y, z = self.fill_gaps(*self.decimate()) | |
219 |
|
239 | |||
220 | for n, ax in enumerate(self.axes): |
|
240 | for n, ax in enumerate(self.axes): | |
221 | self.zmin = self.zmin if self.zmin else numpy.min(self.z) |
|
241 | self.zmin = self.zmin if self.zmin else numpy.min(self.z) | |
222 | self.zmax = self.zmax if self.zmax else numpy.max(self.z) |
|
242 | self.zmax = self.zmax if self.zmax else numpy.max(self.z) | |
|
243 | data = self.data[-1] | |||
223 | if ax.firsttime: |
|
244 | if ax.firsttime: | |
224 | ax.plt = ax.pcolormesh(x, y, z[n].T, |
|
245 | ax.plt = ax.pcolormesh(x, y, z[n].T, | |
225 | vmin=self.zmin, |
|
246 | vmin=self.zmin, | |
226 | vmax=self.zmax, |
|
247 | vmax=self.zmax, | |
227 | cmap=plt.get_cmap(self.colormap) |
|
248 | cmap=plt.get_cmap(self.colormap) | |
228 | ) |
|
249 | ) | |
229 | if self.showprofile: |
|
250 | if self.showprofile: | |
230 | ax.plot_profile = self.pf_axes[n].plot( |
|
251 | ax.plot_profile = self.pf_axes[n].plot( | |
231 |
|
|
252 | data['rti'][n], self.y)[0] | |
232 |
ax.plot_noise = self.pf_axes[n].plot(numpy.repeat( |
|
253 | ax.plot_noise = self.pf_axes[n].plot(numpy.repeat(data['noise'][n], len(self.y)), self.y, | |
233 | color="k", linestyle="dashed", lw=1)[0] |
|
254 | color="k", linestyle="dashed", lw=1)[0] | |
234 | else: |
|
255 | else: | |
235 | ax.collections.remove(ax.collections[0]) |
|
256 | ax.collections.remove(ax.collections[0]) | |
236 | ax.plt = ax.pcolormesh(x, y, z[n].T, |
|
257 | ax.plt = ax.pcolormesh(x, y, z[n].T, | |
237 | vmin=self.zmin, |
|
258 | vmin=self.zmin, | |
238 | vmax=self.zmax, |
|
259 | vmax=self.zmax, | |
239 | cmap=plt.get_cmap(self.colormap) |
|
260 | cmap=plt.get_cmap(self.colormap) | |
240 | ) |
|
261 | ) | |
241 | if self.showprofile: |
|
262 | if self.showprofile: | |
242 |
ax.plot_profile.set_data( |
|
263 | ax.plot_profile.set_data(data['rti'][n], self.y) | |
243 | ax.plot_noise.set_data(numpy.repeat( |
|
264 | ax.plot_noise.set_data(numpy.repeat( | |
244 |
|
|
265 | data['noise'][n], len(self.y)), self.y) | |
245 |
|
266 | |||
246 |
|
267 | |||
247 | class CoherencePlot(RTIPlot): |
|
268 | class CoherencePlot(RTIPlot): | |
248 | ''' |
|
269 | ''' | |
249 | Plot for Coherence data |
|
270 | Plot for Coherence data | |
250 | ''' |
|
271 | ''' | |
251 |
|
272 | |||
252 | CODE = 'coh' |
|
273 | CODE = 'coh' | |
253 |
|
274 | |||
254 | def setup(self): |
|
275 | def setup(self): | |
255 | self.xaxis = 'time' |
|
276 | self.xaxis = 'time' | |
256 | self.ncols = 1 |
|
277 | self.ncols = 1 | |
257 | self.nrows = len(self.data.pairs) |
|
278 | self.nrows = len(self.data.pairs) | |
258 | self.nplots = len(self.data.pairs) |
|
279 | self.nplots = len(self.data.pairs) | |
259 | self.ylabel = 'Range [km]' |
|
280 | self.ylabel = 'Range [km]' | |
260 | self.xlabel = 'Time' |
|
281 | self.xlabel = 'Time' | |
261 | self.plots_adjust.update({'hspace':0.6, 'left': 0.1, 'bottom': 0.1,'right':0.95}) |
|
282 | self.plots_adjust.update({'hspace':0.6, 'left': 0.1, 'bottom': 0.1,'right':0.95}) | |
262 | if self.CODE == 'coh': |
|
283 | if self.CODE == 'coh': | |
263 | self.cb_label = '' |
|
284 | self.cb_label = '' | |
264 | self.titles = [ |
|
285 | self.titles = [ | |
265 | 'Coherence Map Ch{} * Ch{}'.format(x[0], x[1]) for x in self.data.pairs] |
|
286 | 'Coherence Map Ch{} * Ch{}'.format(x[0], x[1]) for x in self.data.pairs] | |
266 | else: |
|
287 | else: | |
267 | self.cb_label = 'Degrees' |
|
288 | self.cb_label = 'Degrees' | |
268 | self.titles = [ |
|
289 | self.titles = [ | |
269 | 'Phase Map Ch{} * Ch{}'.format(x[0], x[1]) for x in self.data.pairs] |
|
290 | 'Phase Map Ch{} * Ch{}'.format(x[0], x[1]) for x in self.data.pairs] | |
270 |
|
291 | |||
|
292 | def update(self, dataOut): | |||
|
293 | ||||
|
294 | data = {} | |||
|
295 | meta = {} | |||
|
296 | data['coh'] = dataOut.getCoherence() | |||
|
297 | meta['pairs'] = dataOut.pairsList | |||
|
298 | ||||
|
299 | return data, meta | |||
271 |
|
300 | |||
272 | class PhasePlot(CoherencePlot): |
|
301 | class PhasePlot(CoherencePlot): | |
273 | ''' |
|
302 | ''' | |
274 | Plot for Phase map data |
|
303 | Plot for Phase map data | |
275 | ''' |
|
304 | ''' | |
276 |
|
305 | |||
277 | CODE = 'phase' |
|
306 | CODE = 'phase' | |
278 | colormap = 'seismic' |
|
307 | colormap = 'seismic' | |
279 |
|
308 | |||
|
309 | def update(self, dataOut): | |||
|
310 | ||||
|
311 | data = {} | |||
|
312 | meta = {} | |||
|
313 | data['phase'] = dataOut.getCoherence(phase=True) | |||
|
314 | meta['pairs'] = dataOut.pairsList | |||
|
315 | ||||
|
316 | return data, meta | |||
280 |
|
317 | |||
281 | class NoisePlot(Plot): |
|
318 | class NoisePlot(Plot): | |
282 | ''' |
|
319 | ''' | |
283 | Plot for noise |
|
320 | Plot for noise | |
284 | ''' |
|
321 | ''' | |
285 |
|
322 | |||
286 | CODE = 'noise' |
|
323 | CODE = 'noise' | |
287 | plot_type = 'scatterbuffer' |
|
324 | plot_type = 'scatterbuffer' | |
288 |
|
325 | |||
289 |
|
||||
290 | def setup(self): |
|
326 | def setup(self): | |
291 | self.xaxis = 'time' |
|
327 | self.xaxis = 'time' | |
292 | self.ncols = 1 |
|
328 | self.ncols = 1 | |
293 | self.nrows = 1 |
|
329 | self.nrows = 1 | |
294 | self.nplots = 1 |
|
330 | self.nplots = 1 | |
295 | self.ylabel = 'Intensity [dB]' |
|
331 | self.ylabel = 'Intensity [dB]' | |
296 | self.xlabel = 'Time' |
|
332 | self.xlabel = 'Time' | |
297 | self.titles = ['Noise'] |
|
333 | self.titles = ['Noise'] | |
298 | self.colorbar = False |
|
334 | self.colorbar = False | |
|
335 | self.plots_adjust.update({'right': 0.85 }) | |||
|
336 | ||||
|
337 | def update(self, dataOut): | |||
|
338 | ||||
|
339 | data = {} | |||
|
340 | meta = {} | |||
|
341 | data['noise'] = 10*numpy.log10(dataOut.getNoise()/dataOut.normFactor).reshape(dataOut.nChannels, 1) | |||
|
342 | meta['yrange'] = numpy.array([]) | |||
|
343 | ||||
|
344 | return data, meta | |||
299 |
|
345 | |||
300 | def plot(self): |
|
346 | def plot(self): | |
301 |
|
347 | |||
302 | x = self.data.times |
|
348 | x = self.data.times | |
303 | xmin = self.data.min_time |
|
349 | xmin = self.data.min_time | |
304 | xmax = xmin + self.xrange * 60 * 60 |
|
350 | xmax = xmin + self.xrange * 60 * 60 | |
305 |
Y = self.data[ |
|
351 | Y = self.data['noise'] | |
306 |
|
352 | |||
307 | if self.axes[0].firsttime: |
|
353 | if self.axes[0].firsttime: | |
|
354 | self.ymin = numpy.nanmin(Y) - 5 | |||
|
355 | self.ymax = numpy.nanmax(Y) + 5 | |||
308 | for ch in self.data.channels: |
|
356 | for ch in self.data.channels: | |
309 | y = Y[ch] |
|
357 | y = Y[ch] | |
310 | self.axes[0].plot(x, y, lw=1, label='Ch{}'.format(ch)) |
|
358 | self.axes[0].plot(x, y, lw=1, label='Ch{}'.format(ch)) | |
311 | plt.legend() |
|
359 | plt.legend(bbox_to_anchor=(1.18, 1.0)) | |
312 | else: |
|
360 | else: | |
313 | for ch in self.data.channels: |
|
361 | for ch in self.data.channels: | |
314 | y = Y[ch] |
|
362 | y = Y[ch] | |
315 | self.axes[0].lines[ch].set_data(x, y) |
|
363 | self.axes[0].lines[ch].set_data(x, y) | |
316 |
|
364 | |||
317 | self.ymin = numpy.nanmin(Y) - 5 |
|
365 | ||
318 | self.ymax = numpy.nanmax(Y) + 5 |
|
|||
319 |
|
||||
320 |
|
||||
321 | class PowerProfilePlot(Plot): |
|
366 | class PowerProfilePlot(Plot): | |
322 |
|
367 | |||
323 |
CODE = ' |
|
368 | CODE = 'pow_profile' | |
324 | plot_type = 'scatter' |
|
369 | plot_type = 'scatter' | |
325 | buffering = False |
|
|||
326 |
|
370 | |||
327 | def setup(self): |
|
371 | def setup(self): | |
328 |
|
372 | |||
329 | self.ncols = 1 |
|
373 | self.ncols = 1 | |
330 | self.nrows = 1 |
|
374 | self.nrows = 1 | |
331 | self.nplots = 1 |
|
375 | self.nplots = 1 | |
332 | self.height = 4 |
|
376 | self.height = 4 | |
333 | self.width = 3 |
|
377 | self.width = 3 | |
334 | self.ylabel = 'Range [km]' |
|
378 | self.ylabel = 'Range [km]' | |
335 | self.xlabel = 'Intensity [dB]' |
|
379 | self.xlabel = 'Intensity [dB]' | |
336 | self.titles = ['Power Profile'] |
|
380 | self.titles = ['Power Profile'] | |
337 | self.colorbar = False |
|
381 | self.colorbar = False | |
338 |
|
382 | |||
|
383 | def update(self, dataOut): | |||
|
384 | ||||
|
385 | data = {} | |||
|
386 | meta = {} | |||
|
387 | data[self.CODE] = dataOut.getPower() | |||
|
388 | ||||
|
389 | return data, meta | |||
|
390 | ||||
339 | def plot(self): |
|
391 | def plot(self): | |
340 |
|
392 | |||
341 |
y = self.data. |
|
393 | y = self.data.yrange | |
342 | self.y = y |
|
394 | self.y = y | |
343 |
|
395 | |||
344 |
x = self.data[ |
|
396 | x = self.data[-1][self.CODE] | |
345 |
|
397 | |||
346 | if self.xmin is None: self.xmin = numpy.nanmin(x)*0.9 |
|
398 | if self.xmin is None: self.xmin = numpy.nanmin(x)*0.9 | |
347 | if self.xmax is None: self.xmax = numpy.nanmax(x)*1.1 |
|
399 | if self.xmax is None: self.xmax = numpy.nanmax(x)*1.1 | |
348 |
|
400 | |||
349 | if self.axes[0].firsttime: |
|
401 | if self.axes[0].firsttime: | |
350 | for ch in self.data.channels: |
|
402 | for ch in self.data.channels: | |
351 | self.axes[0].plot(x[ch], y, lw=1, label='Ch{}'.format(ch)) |
|
403 | self.axes[0].plot(x[ch], y, lw=1, label='Ch{}'.format(ch)) | |
352 | plt.legend() |
|
404 | plt.legend() | |
353 | else: |
|
405 | else: | |
354 | for ch in self.data.channels: |
|
406 | for ch in self.data.channels: | |
355 | self.axes[0].lines[ch].set_data(x[ch], y) |
|
407 | self.axes[0].lines[ch].set_data(x[ch], y) | |
356 |
|
408 | |||
357 |
|
409 | |||
358 | class SpectraCutPlot(Plot): |
|
410 | class SpectraCutPlot(Plot): | |
359 |
|
411 | |||
360 | CODE = 'spc_cut' |
|
412 | CODE = 'spc_cut' | |
361 | plot_type = 'scatter' |
|
413 | plot_type = 'scatter' | |
362 | buffering = False |
|
414 | buffering = False | |
363 |
|
415 | |||
364 | def setup(self): |
|
416 | def setup(self): | |
365 |
|
417 | |||
366 | self.nplots = len(self.data.channels) |
|
418 | self.nplots = len(self.data.channels) | |
367 | self.ncols = int(numpy.sqrt(self.nplots) + 0.9) |
|
419 | self.ncols = int(numpy.sqrt(self.nplots) + 0.9) | |
368 | self.nrows = int((1.0 * self.nplots / self.ncols) + 0.9) |
|
420 | self.nrows = int((1.0 * self.nplots / self.ncols) + 0.9) | |
369 | self.width = 3.4 * self.ncols + 1.5 |
|
421 | self.width = 3.4 * self.ncols + 1.5 | |
370 | self.height = 3 * self.nrows |
|
422 | self.height = 3 * self.nrows | |
371 | self.ylabel = 'Power [dB]' |
|
423 | self.ylabel = 'Power [dB]' | |
372 | self.colorbar = False |
|
424 | self.colorbar = False | |
373 | self.plots_adjust.update({'left':0.1, 'hspace':0.3, 'right': 0.75, 'bottom':0.08}) |
|
425 | self.plots_adjust.update({'left':0.1, 'hspace':0.3, 'right': 0.75, 'bottom':0.08}) | |
374 |
|
426 | |||
|
427 | def update(self, dataOut): | |||
|
428 | ||||
|
429 | data = {} | |||
|
430 | meta = {} | |||
|
431 | spc = 10*numpy.log10(dataOut.data_spc/dataOut.normFactor) | |||
|
432 | data['spc'] = spc | |||
|
433 | meta['xrange'] = (dataOut.getFreqRange(1)/1000., dataOut.getAcfRange(1), dataOut.getVelRange(1)) | |||
|
434 | ||||
|
435 | return data, meta | |||
|
436 | ||||
375 | def plot(self): |
|
437 | def plot(self): | |
376 | if self.xaxis == "frequency": |
|
438 | if self.xaxis == "frequency": | |
377 | x = self.data.xrange[0][1:] |
|
439 | x = self.data.xrange[0][1:] | |
378 | self.xlabel = "Frequency (kHz)" |
|
440 | self.xlabel = "Frequency (kHz)" | |
379 | elif self.xaxis == "time": |
|
441 | elif self.xaxis == "time": | |
380 | x = self.data.xrange[1] |
|
442 | x = self.data.xrange[1] | |
381 | self.xlabel = "Time (ms)" |
|
443 | self.xlabel = "Time (ms)" | |
382 | else: |
|
444 | else: | |
383 | x = self.data.xrange[2] |
|
445 | x = self.data.xrange[2] | |
384 | self.xlabel = "Velocity (m/s)" |
|
446 | self.xlabel = "Velocity (m/s)" | |
385 |
|
447 | |||
386 | self.titles = [] |
|
448 | self.titles = [] | |
387 |
|
449 | |||
388 |
y = self.data. |
|
450 | y = self.data.yrange | |
389 | #self.y = y |
|
451 | z = self.data[-1]['spc'] | |
390 | z = self.data['spc_cut'] |
|
|||
391 |
|
452 | |||
392 | if self.height_index: |
|
453 | if self.height_index: | |
393 | index = numpy.array(self.height_index) |
|
454 | index = numpy.array(self.height_index) | |
394 | else: |
|
455 | else: | |
395 | index = numpy.arange(0, len(y), int((len(y))/9)) |
|
456 | index = numpy.arange(0, len(y), int((len(y))/9)) | |
396 |
|
457 | |||
397 | for n, ax in enumerate(self.axes): |
|
458 | for n, ax in enumerate(self.axes): | |
398 | if ax.firsttime: |
|
459 | if ax.firsttime: | |
399 | self.xmax = self.xmax if self.xmax else numpy.nanmax(x) |
|
460 | self.xmax = self.xmax if self.xmax else numpy.nanmax(x) | |
400 | self.xmin = self.xmin if self.xmin else -self.xmax |
|
461 | self.xmin = self.xmin if self.xmin else -self.xmax | |
401 | self.ymin = self.ymin if self.ymin else numpy.nanmin(z) |
|
462 | self.ymin = self.ymin if self.ymin else numpy.nanmin(z) | |
402 | self.ymax = self.ymax if self.ymax else numpy.nanmax(z) |
|
463 | self.ymax = self.ymax if self.ymax else numpy.nanmax(z) | |
403 | ax.plt = ax.plot(x, z[n, :, index].T) |
|
464 | ax.plt = ax.plot(x, z[n, :, index].T) | |
404 | labels = ['Range = {:2.1f}km'.format(y[i]) for i in index] |
|
465 | labels = ['Range = {:2.1f}km'.format(y[i]) for i in index] | |
405 | self.figures[0].legend(ax.plt, labels, loc='center right') |
|
466 | self.figures[0].legend(ax.plt, labels, loc='center right') | |
406 | else: |
|
467 | else: | |
407 | for i, line in enumerate(ax.plt): |
|
468 | for i, line in enumerate(ax.plt): | |
408 | line.set_data(x, z[n, :, i]) |
|
469 | line.set_data(x, z[n, :, i]) | |
409 | self.titles.append('CH {}'.format(n)) |
|
470 | self.titles.append('CH {}'.format(n)) | |
410 |
|
471 | |||
411 |
|
472 | |||
412 | class BeaconPhase(Plot): |
|
473 | class BeaconPhase(Plot): | |
413 |
|
474 | |||
414 | __isConfig = None |
|
475 | __isConfig = None | |
415 | __nsubplots = None |
|
476 | __nsubplots = None | |
416 |
|
477 | |||
417 | PREFIX = 'beacon_phase' |
|
478 | PREFIX = 'beacon_phase' | |
418 |
|
479 | |||
419 | def __init__(self): |
|
480 | def __init__(self): | |
420 | Plot.__init__(self) |
|
481 | Plot.__init__(self) | |
421 | self.timerange = 24*60*60 |
|
482 | self.timerange = 24*60*60 | |
422 | self.isConfig = False |
|
483 | self.isConfig = False | |
423 | self.__nsubplots = 1 |
|
484 | self.__nsubplots = 1 | |
424 | self.counter_imagwr = 0 |
|
485 | self.counter_imagwr = 0 | |
425 | self.WIDTH = 800 |
|
486 | self.WIDTH = 800 | |
426 | self.HEIGHT = 400 |
|
487 | self.HEIGHT = 400 | |
427 | self.WIDTHPROF = 120 |
|
488 | self.WIDTHPROF = 120 | |
428 | self.HEIGHTPROF = 0 |
|
489 | self.HEIGHTPROF = 0 | |
429 | self.xdata = None |
|
490 | self.xdata = None | |
430 | self.ydata = None |
|
491 | self.ydata = None | |
431 |
|
492 | |||
432 | self.PLOT_CODE = BEACON_CODE |
|
493 | self.PLOT_CODE = BEACON_CODE | |
433 |
|
494 | |||
434 | self.FTP_WEI = None |
|
495 | self.FTP_WEI = None | |
435 | self.EXP_CODE = None |
|
496 | self.EXP_CODE = None | |
436 | self.SUB_EXP_CODE = None |
|
497 | self.SUB_EXP_CODE = None | |
437 | self.PLOT_POS = None |
|
498 | self.PLOT_POS = None | |
438 |
|
499 | |||
439 | self.filename_phase = None |
|
500 | self.filename_phase = None | |
440 |
|
501 | |||
441 | self.figfile = None |
|
502 | self.figfile = None | |
442 |
|
503 | |||
443 | self.xmin = None |
|
504 | self.xmin = None | |
444 | self.xmax = None |
|
505 | self.xmax = None | |
445 |
|
506 | |||
446 | def getSubplots(self): |
|
507 | def getSubplots(self): | |
447 |
|
508 | |||
448 | ncol = 1 |
|
509 | ncol = 1 | |
449 | nrow = 1 |
|
510 | nrow = 1 | |
450 |
|
511 | |||
451 | return nrow, ncol |
|
512 | return nrow, ncol | |
452 |
|
513 | |||
453 | def setup(self, id, nplots, wintitle, showprofile=True, show=True): |
|
514 | def setup(self, id, nplots, wintitle, showprofile=True, show=True): | |
454 |
|
515 | |||
455 | self.__showprofile = showprofile |
|
516 | self.__showprofile = showprofile | |
456 | self.nplots = nplots |
|
517 | self.nplots = nplots | |
457 |
|
518 | |||
458 | ncolspan = 7 |
|
519 | ncolspan = 7 | |
459 | colspan = 6 |
|
520 | colspan = 6 | |
460 | self.__nsubplots = 2 |
|
521 | self.__nsubplots = 2 | |
461 |
|
522 | |||
462 | self.createFigure(id = id, |
|
523 | self.createFigure(id = id, | |
463 | wintitle = wintitle, |
|
524 | wintitle = wintitle, | |
464 | widthplot = self.WIDTH+self.WIDTHPROF, |
|
525 | widthplot = self.WIDTH+self.WIDTHPROF, | |
465 | heightplot = self.HEIGHT+self.HEIGHTPROF, |
|
526 | heightplot = self.HEIGHT+self.HEIGHTPROF, | |
466 | show=show) |
|
527 | show=show) | |
467 |
|
528 | |||
468 | nrow, ncol = self.getSubplots() |
|
529 | nrow, ncol = self.getSubplots() | |
469 |
|
530 | |||
470 | self.addAxes(nrow, ncol*ncolspan, 0, 0, colspan, 1) |
|
531 | self.addAxes(nrow, ncol*ncolspan, 0, 0, colspan, 1) | |
471 |
|
532 | |||
472 | def save_phase(self, filename_phase): |
|
533 | def save_phase(self, filename_phase): | |
473 | f = open(filename_phase,'w+') |
|
534 | f = open(filename_phase,'w+') | |
474 | f.write('\n\n') |
|
535 | f.write('\n\n') | |
475 | f.write('JICAMARCA RADIO OBSERVATORY - Beacon Phase \n') |
|
536 | f.write('JICAMARCA RADIO OBSERVATORY - Beacon Phase \n') | |
476 | f.write('DD MM YYYY HH MM SS pair(2,0) pair(2,1) pair(2,3) pair(2,4)\n\n' ) |
|
537 | f.write('DD MM YYYY HH MM SS pair(2,0) pair(2,1) pair(2,3) pair(2,4)\n\n' ) | |
477 | f.close() |
|
538 | f.close() | |
478 |
|
539 | |||
479 | def save_data(self, filename_phase, data, data_datetime): |
|
540 | def save_data(self, filename_phase, data, data_datetime): | |
480 | f=open(filename_phase,'a') |
|
541 | f=open(filename_phase,'a') | |
481 | timetuple_data = data_datetime.timetuple() |
|
542 | timetuple_data = data_datetime.timetuple() | |
482 | day = str(timetuple_data.tm_mday) |
|
543 | day = str(timetuple_data.tm_mday) | |
483 | month = str(timetuple_data.tm_mon) |
|
544 | month = str(timetuple_data.tm_mon) | |
484 | year = str(timetuple_data.tm_year) |
|
545 | year = str(timetuple_data.tm_year) | |
485 | hour = str(timetuple_data.tm_hour) |
|
546 | hour = str(timetuple_data.tm_hour) | |
486 | minute = str(timetuple_data.tm_min) |
|
547 | minute = str(timetuple_data.tm_min) | |
487 | second = str(timetuple_data.tm_sec) |
|
548 | second = str(timetuple_data.tm_sec) | |
488 | f.write(day+' '+month+' '+year+' '+hour+' '+minute+' '+second+' '+str(data[0])+' '+str(data[1])+' '+str(data[2])+' '+str(data[3])+'\n') |
|
549 | f.write(day+' '+month+' '+year+' '+hour+' '+minute+' '+second+' '+str(data[0])+' '+str(data[1])+' '+str(data[2])+' '+str(data[3])+'\n') | |
489 | f.close() |
|
550 | f.close() | |
490 |
|
551 | |||
491 | def plot(self): |
|
552 | def plot(self): | |
492 | log.warning('TODO: Not yet implemented...') |
|
553 | log.warning('TODO: Not yet implemented...') | |
493 |
|
554 | |||
494 | def run(self, dataOut, id, wintitle="", pairsList=None, showprofile='True', |
|
555 | def run(self, dataOut, id, wintitle="", pairsList=None, showprofile='True', | |
495 | xmin=None, xmax=None, ymin=None, ymax=None, hmin=None, hmax=None, |
|
556 | xmin=None, xmax=None, ymin=None, ymax=None, hmin=None, hmax=None, | |
496 | timerange=None, |
|
557 | timerange=None, | |
497 | save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1, |
|
558 | save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1, | |
498 | server=None, folder=None, username=None, password=None, |
|
559 | server=None, folder=None, username=None, password=None, | |
499 | ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0): |
|
560 | ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0): | |
500 |
|
561 | |||
501 | if dataOut.flagNoData: |
|
562 | if dataOut.flagNoData: | |
502 | return dataOut |
|
563 | return dataOut | |
503 |
|
564 | |||
504 | if not isTimeInHourRange(dataOut.datatime, xmin, xmax): |
|
565 | if not isTimeInHourRange(dataOut.datatime, xmin, xmax): | |
505 | return |
|
566 | return | |
506 |
|
567 | |||
507 | if pairsList == None: |
|
568 | if pairsList == None: | |
508 | pairsIndexList = dataOut.pairsIndexList[:10] |
|
569 | pairsIndexList = dataOut.pairsIndexList[:10] | |
509 | else: |
|
570 | else: | |
510 | pairsIndexList = [] |
|
571 | pairsIndexList = [] | |
511 | for pair in pairsList: |
|
572 | for pair in pairsList: | |
512 | if pair not in dataOut.pairsList: |
|
573 | if pair not in dataOut.pairsList: | |
513 | raise ValueError("Pair %s is not in dataOut.pairsList" %(pair)) |
|
574 | raise ValueError("Pair %s is not in dataOut.pairsList" %(pair)) | |
514 | pairsIndexList.append(dataOut.pairsList.index(pair)) |
|
575 | pairsIndexList.append(dataOut.pairsList.index(pair)) | |
515 |
|
576 | |||
516 | if pairsIndexList == []: |
|
577 | if pairsIndexList == []: | |
517 | return |
|
578 | return | |
518 |
|
579 | |||
519 | # if len(pairsIndexList) > 4: |
|
580 | # if len(pairsIndexList) > 4: | |
520 | # pairsIndexList = pairsIndexList[0:4] |
|
581 | # pairsIndexList = pairsIndexList[0:4] | |
521 |
|
582 | |||
522 | hmin_index = None |
|
583 | hmin_index = None | |
523 | hmax_index = None |
|
584 | hmax_index = None | |
524 |
|
585 | |||
525 | if hmin != None and hmax != None: |
|
586 | if hmin != None and hmax != None: | |
526 | indexes = numpy.arange(dataOut.nHeights) |
|
587 | indexes = numpy.arange(dataOut.nHeights) | |
527 | hmin_list = indexes[dataOut.heightList >= hmin] |
|
588 | hmin_list = indexes[dataOut.heightList >= hmin] | |
528 | hmax_list = indexes[dataOut.heightList <= hmax] |
|
589 | hmax_list = indexes[dataOut.heightList <= hmax] | |
529 |
|
590 | |||
530 | if hmin_list.any(): |
|
591 | if hmin_list.any(): | |
531 | hmin_index = hmin_list[0] |
|
592 | hmin_index = hmin_list[0] | |
532 |
|
593 | |||
533 | if hmax_list.any(): |
|
594 | if hmax_list.any(): | |
534 | hmax_index = hmax_list[-1]+1 |
|
595 | hmax_index = hmax_list[-1]+1 | |
535 |
|
596 | |||
536 | x = dataOut.getTimeRange() |
|
597 | x = dataOut.getTimeRange() | |
537 |
|
598 | |||
538 | thisDatetime = dataOut.datatime |
|
599 | thisDatetime = dataOut.datatime | |
539 |
|
600 | |||
540 | title = wintitle + " Signal Phase" # : %s" %(thisDatetime.strftime("%d-%b-%Y")) |
|
601 | title = wintitle + " Signal Phase" # : %s" %(thisDatetime.strftime("%d-%b-%Y")) | |
541 | xlabel = "Local Time" |
|
602 | xlabel = "Local Time" | |
542 | ylabel = "Phase (degrees)" |
|
603 | ylabel = "Phase (degrees)" | |
543 |
|
604 | |||
544 | update_figfile = False |
|
605 | update_figfile = False | |
545 |
|
606 | |||
546 | nplots = len(pairsIndexList) |
|
607 | nplots = len(pairsIndexList) | |
547 | #phase = numpy.zeros((len(pairsIndexList),len(dataOut.beacon_heiIndexList))) |
|
608 | #phase = numpy.zeros((len(pairsIndexList),len(dataOut.beacon_heiIndexList))) | |
548 | phase_beacon = numpy.zeros(len(pairsIndexList)) |
|
609 | phase_beacon = numpy.zeros(len(pairsIndexList)) | |
549 | for i in range(nplots): |
|
610 | for i in range(nplots): | |
550 | pair = dataOut.pairsList[pairsIndexList[i]] |
|
611 | pair = dataOut.pairsList[pairsIndexList[i]] | |
551 | ccf = numpy.average(dataOut.data_cspc[pairsIndexList[i], :, hmin_index:hmax_index], axis=0) |
|
612 | ccf = numpy.average(dataOut.data_cspc[pairsIndexList[i], :, hmin_index:hmax_index], axis=0) | |
552 | powa = numpy.average(dataOut.data_spc[pair[0], :, hmin_index:hmax_index], axis=0) |
|
613 | powa = numpy.average(dataOut.data_spc[pair[0], :, hmin_index:hmax_index], axis=0) | |
553 | powb = numpy.average(dataOut.data_spc[pair[1], :, hmin_index:hmax_index], axis=0) |
|
614 | powb = numpy.average(dataOut.data_spc[pair[1], :, hmin_index:hmax_index], axis=0) | |
554 | avgcoherenceComplex = ccf/numpy.sqrt(powa*powb) |
|
615 | avgcoherenceComplex = ccf/numpy.sqrt(powa*powb) | |
555 | phase = numpy.arctan2(avgcoherenceComplex.imag, avgcoherenceComplex.real)*180/numpy.pi |
|
616 | phase = numpy.arctan2(avgcoherenceComplex.imag, avgcoherenceComplex.real)*180/numpy.pi | |
556 |
|
617 | |||
557 | if dataOut.beacon_heiIndexList: |
|
618 | if dataOut.beacon_heiIndexList: | |
558 | phase_beacon[i] = numpy.average(phase[dataOut.beacon_heiIndexList]) |
|
619 | phase_beacon[i] = numpy.average(phase[dataOut.beacon_heiIndexList]) | |
559 | else: |
|
620 | else: | |
560 | phase_beacon[i] = numpy.average(phase) |
|
621 | phase_beacon[i] = numpy.average(phase) | |
561 |
|
622 | |||
562 | if not self.isConfig: |
|
623 | if not self.isConfig: | |
563 |
|
624 | |||
564 | nplots = len(pairsIndexList) |
|
625 | nplots = len(pairsIndexList) | |
565 |
|
626 | |||
566 | self.setup(id=id, |
|
627 | self.setup(id=id, | |
567 | nplots=nplots, |
|
628 | nplots=nplots, | |
568 | wintitle=wintitle, |
|
629 | wintitle=wintitle, | |
569 | showprofile=showprofile, |
|
630 | showprofile=showprofile, | |
570 | show=show) |
|
631 | show=show) | |
571 |
|
632 | |||
572 | if timerange != None: |
|
633 | if timerange != None: | |
573 | self.timerange = timerange |
|
634 | self.timerange = timerange | |
574 |
|
635 | |||
575 | self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange) |
|
636 | self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange) | |
576 |
|
637 | |||
577 | if ymin == None: ymin = 0 |
|
638 | if ymin == None: ymin = 0 | |
578 | if ymax == None: ymax = 360 |
|
639 | if ymax == None: ymax = 360 | |
579 |
|
640 | |||
580 | self.FTP_WEI = ftp_wei |
|
641 | self.FTP_WEI = ftp_wei | |
581 | self.EXP_CODE = exp_code |
|
642 | self.EXP_CODE = exp_code | |
582 | self.SUB_EXP_CODE = sub_exp_code |
|
643 | self.SUB_EXP_CODE = sub_exp_code | |
583 | self.PLOT_POS = plot_pos |
|
644 | self.PLOT_POS = plot_pos | |
584 |
|
645 | |||
585 | self.name = thisDatetime.strftime("%Y%m%d_%H%M%S") |
|
646 | self.name = thisDatetime.strftime("%Y%m%d_%H%M%S") | |
586 | self.isConfig = True |
|
647 | self.isConfig = True | |
587 | self.figfile = figfile |
|
648 | self.figfile = figfile | |
588 | self.xdata = numpy.array([]) |
|
649 | self.xdata = numpy.array([]) | |
589 | self.ydata = numpy.array([]) |
|
650 | self.ydata = numpy.array([]) | |
590 |
|
651 | |||
591 | update_figfile = True |
|
652 | update_figfile = True | |
592 |
|
653 | |||
593 | #open file beacon phase |
|
654 | #open file beacon phase | |
594 | path = '%s%03d' %(self.PREFIX, self.id) |
|
655 | path = '%s%03d' %(self.PREFIX, self.id) | |
595 | beacon_file = os.path.join(path,'%s.txt'%self.name) |
|
656 | beacon_file = os.path.join(path,'%s.txt'%self.name) | |
596 | self.filename_phase = os.path.join(figpath,beacon_file) |
|
657 | self.filename_phase = os.path.join(figpath,beacon_file) | |
597 | #self.save_phase(self.filename_phase) |
|
658 | #self.save_phase(self.filename_phase) | |
598 |
|
659 | |||
599 |
|
660 | |||
600 | #store data beacon phase |
|
661 | #store data beacon phase | |
601 | #self.save_data(self.filename_phase, phase_beacon, thisDatetime) |
|
662 | #self.save_data(self.filename_phase, phase_beacon, thisDatetime) | |
602 |
|
663 | |||
603 | self.setWinTitle(title) |
|
664 | self.setWinTitle(title) | |
604 |
|
665 | |||
605 |
|
666 | |||
606 | title = "Phase Plot %s" %(thisDatetime.strftime("%Y/%m/%d %H:%M:%S")) |
|
667 | title = "Phase Plot %s" %(thisDatetime.strftime("%Y/%m/%d %H:%M:%S")) | |
607 |
|
668 | |||
608 | legendlabels = ["Pair (%d,%d)"%(pair[0], pair[1]) for pair in dataOut.pairsList] |
|
669 | legendlabels = ["Pair (%d,%d)"%(pair[0], pair[1]) for pair in dataOut.pairsList] | |
609 |
|
670 | |||
610 | axes = self.axesList[0] |
|
671 | axes = self.axesList[0] | |
611 |
|
672 | |||
612 | self.xdata = numpy.hstack((self.xdata, x[0:1])) |
|
673 | self.xdata = numpy.hstack((self.xdata, x[0:1])) | |
613 |
|
674 | |||
614 | if len(self.ydata)==0: |
|
675 | if len(self.ydata)==0: | |
615 | self.ydata = phase_beacon.reshape(-1,1) |
|
676 | self.ydata = phase_beacon.reshape(-1,1) | |
616 | else: |
|
677 | else: | |
617 | self.ydata = numpy.hstack((self.ydata, phase_beacon.reshape(-1,1))) |
|
678 | self.ydata = numpy.hstack((self.ydata, phase_beacon.reshape(-1,1))) | |
618 |
|
679 | |||
619 |
|
680 | |||
620 | axes.pmultilineyaxis(x=self.xdata, y=self.ydata, |
|
681 | axes.pmultilineyaxis(x=self.xdata, y=self.ydata, | |
621 | xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, |
|
682 | xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, | |
622 | xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels, marker='x', markersize=8, linestyle="solid", |
|
683 | xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels, marker='x', markersize=8, linestyle="solid", | |
623 | XAxisAsTime=True, grid='both' |
|
684 | XAxisAsTime=True, grid='both' | |
624 | ) |
|
685 | ) | |
625 |
|
686 | |||
626 | self.draw() |
|
687 | self.draw() | |
627 |
|
688 | |||
628 | if dataOut.ltctime >= self.xmax: |
|
689 | if dataOut.ltctime >= self.xmax: | |
629 | self.counter_imagwr = wr_period |
|
690 | self.counter_imagwr = wr_period | |
630 | self.isConfig = False |
|
691 | self.isConfig = False | |
631 | update_figfile = True |
|
692 | update_figfile = True | |
632 |
|
693 | |||
633 | self.save(figpath=figpath, |
|
694 | self.save(figpath=figpath, | |
634 | figfile=figfile, |
|
695 | figfile=figfile, | |
635 | save=save, |
|
696 | save=save, | |
636 | ftp=ftp, |
|
697 | ftp=ftp, | |
637 | wr_period=wr_period, |
|
698 | wr_period=wr_period, | |
638 | thisDatetime=thisDatetime, |
|
699 | thisDatetime=thisDatetime, | |
639 | update_figfile=update_figfile) |
|
700 | update_figfile=update_figfile) | |
640 |
|
701 | |||
641 | return dataOut No newline at end of file |
|
702 | return dataOut |
@@ -1,297 +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_type = 'scatter' |
|
20 | plot_type = 'scatter' | |
21 |
|
21 | |||
22 | def setup(self): |
|
22 | def setup(self): | |
23 |
|
23 | |||
24 | self.xaxis = 'Range (Km)' |
|
24 | self.xaxis = 'Range (Km)' | |
25 | self.ncols = 1 |
|
25 | self.ncols = 1 | |
26 | self.nrows = 1 |
|
26 | self.nrows = 1 | |
27 | self.nplots = 1 |
|
27 | self.nplots = 1 | |
28 | self.ylabel = 'Intensity [dB]' |
|
28 | self.ylabel = 'Intensity [dB]' | |
29 | self.titles = ['Scope'] |
|
29 | self.titles = ['Scope'] | |
30 | self.colorbar = False |
|
30 | self.colorbar = False | |
31 | self.width = 6 |
|
31 | self.width = 6 | |
32 | self.height = 4 |
|
32 | self.height = 4 | |
33 |
|
33 | |||
|
34 | def update(self, dataOut): | |||
|
35 | ||||
|
36 | data = {} | |||
|
37 | meta = { | |||
|
38 | 'nProfiles': dataOut.nProfiles, | |||
|
39 | 'flagDataAsBlock': dataOut.flagDataAsBlock, | |||
|
40 | 'profileIndex': dataOut.profileIndex, | |||
|
41 | } | |||
|
42 | if self.CODE == 'scope': | |||
|
43 | data[self.CODE] = dataOut.data | |||
|
44 | elif self.CODE == 'pp_power': | |||
|
45 | data[self.CODE] = dataOut.dataPP_POWER | |||
|
46 | elif self.CODE == 'pp_signal': | |||
|
47 | data[self.CODE] = dataOut.dataPP_POW | |||
|
48 | elif self.CODE == 'pp_velocity': | |||
|
49 | data[self.CODE] = dataOut.dataPP_DOP | |||
|
50 | elif self.CODE == 'pp_specwidth': | |||
|
51 | data[self.CODE] = dataOut.dataPP_WIDTH | |||
|
52 | ||||
|
53 | return data, meta | |||
|
54 | ||||
34 | def plot_iq(self, x, y, channelIndexList, thisDatetime, wintitle): |
|
55 | def plot_iq(self, x, y, channelIndexList, thisDatetime, wintitle): | |
35 |
|
56 | |||
36 | yreal = y[channelIndexList,:].real |
|
57 | yreal = y[channelIndexList,:].real | |
37 | yimag = y[channelIndexList,:].imag |
|
58 | yimag = y[channelIndexList,:].imag | |
38 | title = wintitle + " Scope: %s" %(thisDatetime.strftime("%d-%b-%Y")) |
|
59 | title = wintitle + " Scope: %s" %(thisDatetime.strftime("%d-%b-%Y")) | |
39 | self.xlabel = "Range (Km)" |
|
60 | self.xlabel = "Range (Km)" | |
40 | self.ylabel = "Intensity - IQ" |
|
61 | self.ylabel = "Intensity - IQ" | |
41 |
|
62 | |||
42 | self.y = yreal |
|
63 | self.y = yreal | |
43 | self.x = x |
|
64 | self.x = x | |
44 | self.xmin = min(x) |
|
|||
45 | self.xmax = max(x) |
|
|||
46 |
|
||||
47 |
|
65 | |||
48 | self.titles[0] = title |
|
66 | self.titles[0] = title | |
49 |
|
67 | |||
50 | for i,ax in enumerate(self.axes): |
|
68 | for i,ax in enumerate(self.axes): | |
51 | title = "Channel %d" %(i) |
|
69 | title = "Channel %d" %(i) | |
52 | if ax.firsttime: |
|
70 | if ax.firsttime: | |
|
71 | self.xmin = min(x) | |||
|
72 | self.xmax = max(x) | |||
53 | ax.plt_r = ax.plot(x, yreal[i,:], color='b')[0] |
|
73 | ax.plt_r = ax.plot(x, yreal[i,:], color='b')[0] | |
54 | ax.plt_i = ax.plot(x, yimag[i,:], color='r')[0] |
|
74 | ax.plt_i = ax.plot(x, yimag[i,:], color='r')[0] | |
55 | else: |
|
75 | else: | |
56 | ax.plt_r.set_data(x, yreal[i,:]) |
|
76 | ax.plt_r.set_data(x, yreal[i,:]) | |
57 | ax.plt_i.set_data(x, yimag[i,:]) |
|
77 | ax.plt_i.set_data(x, yimag[i,:]) | |
58 |
|
78 | |||
59 | def plot_power(self, x, y, channelIndexList, thisDatetime, wintitle): |
|
79 | def plot_power(self, x, y, channelIndexList, thisDatetime, wintitle): | |
60 | y = y[channelIndexList,:] * numpy.conjugate(y[channelIndexList,:]) |
|
80 | y = y[channelIndexList,:] * numpy.conjugate(y[channelIndexList,:]) | |
61 | yreal = y.real |
|
81 | yreal = y.real | |
62 | yreal = 10*numpy.log10(yreal) |
|
82 | yreal = 10*numpy.log10(yreal) | |
63 | self.y = yreal |
|
83 | self.y = yreal | |
64 |
title = wintitle + " |
|
84 | title = wintitle + " Power: %s" %(thisDatetime.strftime("%d-%b-%Y")) | |
65 | self.xlabel = "Range (Km)" |
|
85 | self.xlabel = "Range (Km)" | |
66 | self.ylabel = "Intensity" |
|
86 | self.ylabel = "Intensity [dB]" | |
67 | self.xmin = min(x) |
|
|||
68 | self.xmax = max(x) |
|
|||
69 |
|
87 | |||
70 |
|
88 | |||
71 | self.titles[0] = title |
|
89 | self.titles[0] = title | |
72 |
|
90 | |||
73 | for i,ax in enumerate(self.axes): |
|
91 | for i,ax in enumerate(self.axes): | |
74 | title = "Channel %d" %(i) |
|
92 | title = "Channel %d" %(i) | |
75 |
|
||||
76 | ychannel = yreal[i,:] |
|
93 | ychannel = yreal[i,:] | |
77 |
|
94 | |||
78 | if ax.firsttime: |
|
95 | if ax.firsttime: | |
|
96 | self.xmin = min(x) | |||
|
97 | self.xmax = max(x) | |||
79 | ax.plt_r = ax.plot(x, ychannel)[0] |
|
98 | ax.plt_r = ax.plot(x, ychannel)[0] | |
80 | else: |
|
99 | else: | |
81 | #pass |
|
|||
82 | ax.plt_r.set_data(x, ychannel) |
|
100 | ax.plt_r.set_data(x, ychannel) | |
83 |
|
101 | |||
84 | def plot_weatherpower(self, x, y, channelIndexList, thisDatetime, wintitle): |
|
102 | def plot_weatherpower(self, x, y, channelIndexList, thisDatetime, wintitle): | |
85 |
|
103 | |||
86 |
|
104 | |||
87 | y = y[channelIndexList,:] |
|
105 | y = y[channelIndexList,:] | |
88 | yreal = y.real |
|
106 | yreal = y.real | |
89 | yreal = 10*numpy.log10(yreal) |
|
107 | yreal = 10*numpy.log10(yreal) | |
90 | self.y = yreal |
|
108 | self.y = yreal | |
91 | title = wintitle + " Scope: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) |
|
109 | title = wintitle + " Scope: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) | |
92 | self.xlabel = "Range (Km)" |
|
110 | self.xlabel = "Range (Km)" | |
93 | self.ylabel = "Intensity" |
|
111 | self.ylabel = "Intensity" | |
94 | self.xmin = min(x) |
|
112 | self.xmin = min(x) | |
95 | self.xmax = max(x) |
|
113 | self.xmax = max(x) | |
96 |
|
114 | |||
97 | self.titles[0] =title |
|
115 | self.titles[0] =title | |
98 | for i,ax in enumerate(self.axes): |
|
116 | for i,ax in enumerate(self.axes): | |
99 | title = "Channel %d" %(i) |
|
117 | title = "Channel %d" %(i) | |
100 |
|
118 | |||
101 | ychannel = yreal[i,:] |
|
119 | ychannel = yreal[i,:] | |
102 |
|
120 | |||
103 | if ax.firsttime: |
|
121 | if ax.firsttime: | |
104 | ax.plt_r = ax.plot(x, ychannel)[0] |
|
122 | ax.plt_r = ax.plot(x, ychannel)[0] | |
105 | else: |
|
123 | else: | |
106 | #pass |
|
124 | #pass | |
107 | ax.plt_r.set_data(x, ychannel) |
|
125 | ax.plt_r.set_data(x, ychannel) | |
108 |
|
126 | |||
109 | def plot_weathervelocity(self, x, y, channelIndexList, thisDatetime, wintitle): |
|
127 | def plot_weathervelocity(self, x, y, channelIndexList, thisDatetime, wintitle): | |
110 |
|
128 | |||
111 | x = x[channelIndexList,:] |
|
129 | x = x[channelIndexList,:] | |
112 | yreal = y |
|
130 | yreal = y | |
113 | self.y = yreal |
|
131 | self.y = yreal | |
114 | title = wintitle + " Scope: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) |
|
132 | title = wintitle + " Scope: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) | |
115 | self.xlabel = "Velocity (m/s)" |
|
133 | self.xlabel = "Velocity (m/s)" | |
116 | self.ylabel = "Range (Km)" |
|
134 | self.ylabel = "Range (Km)" | |
117 | self.xmin = numpy.min(x) |
|
135 | self.xmin = numpy.min(x) | |
118 | self.xmax = numpy.max(x) |
|
136 | self.xmax = numpy.max(x) | |
119 | self.titles[0] =title |
|
137 | self.titles[0] =title | |
120 | for i,ax in enumerate(self.axes): |
|
138 | for i,ax in enumerate(self.axes): | |
121 | title = "Channel %d" %(i) |
|
139 | title = "Channel %d" %(i) | |
122 | xchannel = x[i,:] |
|
140 | xchannel = x[i,:] | |
123 | if ax.firsttime: |
|
141 | if ax.firsttime: | |
124 | ax.plt_r = ax.plot(xchannel, yreal)[0] |
|
142 | ax.plt_r = ax.plot(xchannel, yreal)[0] | |
125 | else: |
|
143 | else: | |
126 | #pass |
|
144 | #pass | |
127 | ax.plt_r.set_data(xchannel, yreal) |
|
145 | ax.plt_r.set_data(xchannel, yreal) | |
128 |
|
146 | |||
129 | def plot_weatherspecwidth(self, x, y, channelIndexList, thisDatetime, wintitle): |
|
147 | def plot_weatherspecwidth(self, x, y, channelIndexList, thisDatetime, wintitle): | |
130 |
|
148 | |||
131 | x = x[channelIndexList,:] |
|
149 | x = x[channelIndexList,:] | |
132 | yreal = y |
|
150 | yreal = y | |
133 | self.y = yreal |
|
151 | self.y = yreal | |
134 | title = wintitle + " Scope: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) |
|
152 | title = wintitle + " Scope: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) | |
135 | self.xlabel = "width " |
|
153 | self.xlabel = "width " | |
136 | self.ylabel = "Range (Km)" |
|
154 | self.ylabel = "Range (Km)" | |
137 | self.xmin = numpy.min(x) |
|
155 | self.xmin = numpy.min(x) | |
138 | self.xmax = numpy.max(x) |
|
156 | self.xmax = numpy.max(x) | |
139 | self.titles[0] =title |
|
157 | self.titles[0] =title | |
140 | for i,ax in enumerate(self.axes): |
|
158 | for i,ax in enumerate(self.axes): | |
141 | title = "Channel %d" %(i) |
|
159 | title = "Channel %d" %(i) | |
142 | xchannel = x[i,:] |
|
160 | xchannel = x[i,:] | |
143 | if ax.firsttime: |
|
161 | if ax.firsttime: | |
144 | ax.plt_r = ax.plot(xchannel, yreal)[0] |
|
162 | ax.plt_r = ax.plot(xchannel, yreal)[0] | |
145 | else: |
|
163 | else: | |
146 | #pass |
|
164 | #pass | |
147 | ax.plt_r.set_data(xchannel, yreal) |
|
165 | ax.plt_r.set_data(xchannel, yreal) | |
148 |
|
166 | |||
149 | def plot(self): |
|
167 | def plot(self): | |
150 | if self.channels: |
|
168 | if self.channels: | |
151 | channels = self.channels |
|
169 | channels = self.channels | |
152 | else: |
|
170 | else: | |
153 | channels = self.data.channels |
|
171 | channels = self.data.channels | |
154 |
|
172 | |||
155 | thisDatetime = datetime.datetime.utcfromtimestamp(self.data.times[-1]) |
|
173 | thisDatetime = datetime.datetime.utcfromtimestamp(self.data.times[-1]) | |
156 | if self.CODE == "pp_power": |
|
174 | ||
157 |
|
|
175 | scope = self.data[-1][self.CODE] | |
158 | elif self.CODE == "pp_signal": |
|
|||
159 | scope = self.data["pp_signal"] |
|
|||
160 | elif self.CODE == "pp_velocity": |
|
|||
161 | scope = self.data["pp_velocity"] |
|
|||
162 | elif self.CODE == "pp_specwidth": |
|
|||
163 | scope = self.data["pp_specwidth"] |
|
|||
164 | else: |
|
|||
165 | scope =self.data["scope"] |
|
|||
166 |
|
176 | |||
167 | if self.data.flagDataAsBlock: |
|
177 | if self.data.flagDataAsBlock: | |
168 |
|
178 | |||
169 | for i in range(self.data.nProfiles): |
|
179 | for i in range(self.data.nProfiles): | |
170 |
|
180 | |||
171 | wintitle1 = " [Profile = %d] " %i |
|
181 | wintitle1 = " [Profile = %d] " %i | |
172 | if self.CODE =="scope": |
|
182 | if self.CODE =="scope": | |
173 | if self.type == "power": |
|
183 | if self.type == "power": | |
174 |
self.plot_power(self.data. |
|
184 | self.plot_power(self.data.yrange, | |
175 | scope[:,i,:], |
|
185 | scope[:,i,:], | |
176 | channels, |
|
186 | channels, | |
177 | thisDatetime, |
|
187 | thisDatetime, | |
178 | wintitle1 |
|
188 | wintitle1 | |
179 | ) |
|
189 | ) | |
180 |
|
190 | |||
181 | if self.type == "iq": |
|
191 | if self.type == "iq": | |
182 |
self.plot_iq(self.data. |
|
192 | self.plot_iq(self.data.yrange, | |
183 | scope[:,i,:], |
|
193 | scope[:,i,:], | |
184 | channels, |
|
194 | channels, | |
185 | thisDatetime, |
|
195 | thisDatetime, | |
186 | wintitle1 |
|
196 | wintitle1 | |
187 | ) |
|
197 | ) | |
188 | if self.CODE=="pp_power": |
|
198 | if self.CODE=="pp_power": | |
189 |
self.plot_weatherpower(self.data. |
|
199 | self.plot_weatherpower(self.data.yrange, | |
190 | scope[:,i,:], |
|
200 | scope[:,i,:], | |
191 | channels, |
|
201 | channels, | |
192 | thisDatetime, |
|
202 | thisDatetime, | |
193 | wintitle |
|
203 | wintitle | |
194 | ) |
|
204 | ) | |
195 | if self.CODE=="pp_signal": |
|
205 | if self.CODE=="pp_signal": | |
196 |
self.plot_weatherpower(self.data. |
|
206 | self.plot_weatherpower(self.data.yrange, | |
197 | scope[:,i,:], |
|
207 | scope[:,i,:], | |
198 | channels, |
|
208 | channels, | |
199 | thisDatetime, |
|
209 | thisDatetime, | |
200 | wintitle |
|
210 | wintitle | |
201 | ) |
|
211 | ) | |
202 | if self.CODE=="pp_velocity": |
|
212 | if self.CODE=="pp_velocity": | |
203 | self.plot_weathervelocity(scope[:,i,:], |
|
213 | self.plot_weathervelocity(scope[:,i,:], | |
204 |
self.data. |
|
214 | self.data.yrange, | |
205 | channels, |
|
215 | channels, | |
206 | thisDatetime, |
|
216 | thisDatetime, | |
207 | wintitle |
|
217 | wintitle | |
208 | ) |
|
218 | ) | |
209 | if self.CODE=="pp_spcwidth": |
|
219 | if self.CODE=="pp_spcwidth": | |
210 | self.plot_weatherspecwidth(scope[:,i,:], |
|
220 | self.plot_weatherspecwidth(scope[:,i,:], | |
211 |
self.data. |
|
221 | self.data.yrange, | |
212 | channels, |
|
222 | channels, | |
213 | thisDatetime, |
|
223 | thisDatetime, | |
214 | wintitle |
|
224 | wintitle | |
215 | ) |
|
225 | ) | |
216 | else: |
|
226 | else: | |
217 | wintitle = " [Profile = %d] " %self.data.profileIndex |
|
227 | wintitle = " [Profile = %d] " %self.data.profileIndex | |
218 | if self.CODE== "scope": |
|
228 | if self.CODE== "scope": | |
219 | if self.type == "power": |
|
229 | if self.type == "power": | |
220 |
self.plot_power(self.data. |
|
230 | self.plot_power(self.data.yrange, | |
221 | scope, |
|
231 | scope, | |
222 | channels, |
|
232 | channels, | |
223 | thisDatetime, |
|
233 | thisDatetime, | |
224 | wintitle |
|
234 | wintitle | |
225 | ) |
|
235 | ) | |
226 |
|
236 | |||
227 | if self.type == "iq": |
|
237 | if self.type == "iq": | |
228 |
self.plot_iq(self.data. |
|
238 | self.plot_iq(self.data.yrange, | |
229 | scope, |
|
239 | scope, | |
230 | channels, |
|
240 | channels, | |
231 | thisDatetime, |
|
241 | thisDatetime, | |
232 | wintitle |
|
242 | wintitle | |
233 | ) |
|
243 | ) | |
234 | if self.CODE=="pp_power": |
|
244 | if self.CODE=="pp_power": | |
235 |
self.plot_weatherpower(self.data. |
|
245 | self.plot_weatherpower(self.data.yrange, | |
236 | scope, |
|
246 | scope, | |
237 | channels, |
|
247 | channels, | |
238 | thisDatetime, |
|
248 | thisDatetime, | |
239 | wintitle |
|
249 | wintitle | |
240 | ) |
|
250 | ) | |
241 | if self.CODE=="pp_signal": |
|
251 | if self.CODE=="pp_signal": | |
242 |
self.plot_weatherpower(self.data. |
|
252 | self.plot_weatherpower(self.data.yrange, | |
243 | scope, |
|
253 | scope, | |
244 | channels, |
|
254 | channels, | |
245 | thisDatetime, |
|
255 | thisDatetime, | |
246 | wintitle |
|
256 | wintitle | |
247 | ) |
|
257 | ) | |
248 | if self.CODE=="pp_velocity": |
|
258 | if self.CODE=="pp_velocity": | |
249 | self.plot_weathervelocity(scope, |
|
259 | self.plot_weathervelocity(scope, | |
250 |
self.data. |
|
260 | self.data.yrange, | |
251 | channels, |
|
261 | channels, | |
252 | thisDatetime, |
|
262 | thisDatetime, | |
253 | wintitle |
|
263 | wintitle | |
254 | ) |
|
264 | ) | |
255 | if self.CODE=="pp_specwidth": |
|
265 | if self.CODE=="pp_specwidth": | |
256 | self.plot_weatherspecwidth(scope, |
|
266 | self.plot_weatherspecwidth(scope, | |
257 |
self.data. |
|
267 | self.data.yrange, | |
258 | channels, |
|
268 | channels, | |
259 | thisDatetime, |
|
269 | thisDatetime, | |
260 | wintitle |
|
270 | wintitle | |
261 | ) |
|
271 | ) | |
262 |
|
272 | |||
263 |
|
273 | |||
264 |
|
||||
265 | class PulsepairPowerPlot(ScopePlot): |
|
274 | class PulsepairPowerPlot(ScopePlot): | |
266 | ''' |
|
275 | ''' | |
267 | Plot for P= S+N |
|
276 | Plot for P= S+N | |
268 | ''' |
|
277 | ''' | |
269 |
|
278 | |||
270 | CODE = 'pp_power' |
|
279 | CODE = 'pp_power' | |
271 | plot_type = 'scatter' |
|
280 | plot_type = 'scatter' | |
272 | buffering = False |
|
|||
273 |
|
281 | |||
274 | class PulsepairVelocityPlot(ScopePlot): |
|
282 | class PulsepairVelocityPlot(ScopePlot): | |
275 | ''' |
|
283 | ''' | |
276 | Plot for VELOCITY |
|
284 | Plot for VELOCITY | |
277 | ''' |
|
285 | ''' | |
278 | CODE = 'pp_velocity' |
|
286 | CODE = 'pp_velocity' | |
279 | plot_type = 'scatter' |
|
287 | plot_type = 'scatter' | |
280 | buffering = False |
|
|||
281 |
|
288 | |||
282 | class PulsepairSpecwidthPlot(ScopePlot): |
|
289 | class PulsepairSpecwidthPlot(ScopePlot): | |
283 | ''' |
|
290 | ''' | |
284 | Plot for WIDTH |
|
291 | Plot for WIDTH | |
285 | ''' |
|
292 | ''' | |
286 | CODE = 'pp_specwidth' |
|
293 | CODE = 'pp_specwidth' | |
287 | plot_type = 'scatter' |
|
294 | plot_type = 'scatter' | |
288 | buffering = False |
|
|||
289 |
|
295 | |||
290 | class PulsepairSignalPlot(ScopePlot): |
|
296 | class PulsepairSignalPlot(ScopePlot): | |
291 | ''' |
|
297 | ''' | |
292 | Plot for S |
|
298 | Plot for S | |
293 | ''' |
|
299 | ''' | |
294 |
|
300 | |||
295 | CODE = 'pp_signal' |
|
301 | CODE = 'pp_signal' | |
296 | plot_type = 'scatter' |
|
302 | plot_type = 'scatter' | |
297 | buffering = False |
|
@@ -1,355 +1,355 | |||||
1 | ''' |
|
1 | ''' | |
2 | Created on Nov 9, 2016 |
|
2 | Created on Nov 9, 2016 | |
3 |
|
3 | |||
4 | @author: roj- LouVD |
|
4 | @author: roj- LouVD | |
5 | ''' |
|
5 | ''' | |
6 |
|
6 | |||
7 |
|
7 | |||
8 | import os |
|
8 | import os | |
9 | import sys |
|
9 | import sys | |
10 | import time |
|
10 | import time | |
11 | import glob |
|
11 | import glob | |
12 | import datetime |
|
12 | import datetime | |
13 |
|
13 | |||
14 | import numpy |
|
14 | import numpy | |
15 |
|
15 | |||
16 | import schainpy.admin |
|
16 | import schainpy.admin | |
17 | from schainpy.model.proc.jroproc_base import ProcessingUnit, MPDecorator |
|
17 | from schainpy.model.proc.jroproc_base import ProcessingUnit, MPDecorator | |
18 | from schainpy.model.data.jrodata import Parameters |
|
18 | from schainpy.model.data.jrodata import Parameters | |
19 | from schainpy.model.io.jroIO_base import Reader |
|
19 | from schainpy.model.io.jroIO_base import Reader | |
20 | from schainpy.utils import log |
|
20 | from schainpy.utils import log | |
21 |
|
21 | |||
22 | FILE_HEADER_STRUCTURE = numpy.dtype([ |
|
22 | FILE_HEADER_STRUCTURE = numpy.dtype([ | |
23 | ('FMN', '<u4'), |
|
23 | ('FMN', '<u4'), | |
24 | ('nrec', '<u4'), |
|
24 | ('nrec', '<u4'), | |
25 | ('fr_offset', '<u4'), |
|
25 | ('fr_offset', '<u4'), | |
26 | ('id', '<u4'), |
|
26 | ('id', '<u4'), | |
27 | ('site', 'u1', (32,)) |
|
27 | ('site', 'u1', (32,)) | |
28 | ]) |
|
28 | ]) | |
29 |
|
29 | |||
30 | REC_HEADER_STRUCTURE = numpy.dtype([ |
|
30 | REC_HEADER_STRUCTURE = numpy.dtype([ | |
31 | ('rmn', '<u4'), |
|
31 | ('rmn', '<u4'), | |
32 | ('rcounter', '<u4'), |
|
32 | ('rcounter', '<u4'), | |
33 | ('nr_offset', '<u4'), |
|
33 | ('nr_offset', '<u4'), | |
34 | ('tr_offset', '<u4'), |
|
34 | ('tr_offset', '<u4'), | |
35 | ('time', '<u4'), |
|
35 | ('time', '<u4'), | |
36 | ('time_msec', '<u4'), |
|
36 | ('time_msec', '<u4'), | |
37 | ('tag', 'u1', (32,)), |
|
37 | ('tag', 'u1', (32,)), | |
38 | ('comments', 'u1', (32,)), |
|
38 | ('comments', 'u1', (32,)), | |
39 | ('lat', '<f4'), |
|
39 | ('lat', '<f4'), | |
40 | ('lon', '<f4'), |
|
40 | ('lon', '<f4'), | |
41 | ('gps_status', '<u4'), |
|
41 | ('gps_status', '<u4'), | |
42 | ('freq', '<u4'), |
|
42 | ('freq', '<u4'), | |
43 | ('freq0', '<u4'), |
|
43 | ('freq0', '<u4'), | |
44 | ('nchan', '<u4'), |
|
44 | ('nchan', '<u4'), | |
45 | ('delta_r', '<u4'), |
|
45 | ('delta_r', '<u4'), | |
46 | ('nranges', '<u4'), |
|
46 | ('nranges', '<u4'), | |
47 | ('r0', '<u4'), |
|
47 | ('r0', '<u4'), | |
48 | ('prf', '<u4'), |
|
48 | ('prf', '<u4'), | |
49 | ('ncoh', '<u4'), |
|
49 | ('ncoh', '<u4'), | |
50 | ('npoints', '<u4'), |
|
50 | ('npoints', '<u4'), | |
51 | ('polarization', '<i4'), |
|
51 | ('polarization', '<i4'), | |
52 | ('rx_filter', '<u4'), |
|
52 | ('rx_filter', '<u4'), | |
53 | ('nmodes', '<u4'), |
|
53 | ('nmodes', '<u4'), | |
54 | ('dmode_index', '<u4'), |
|
54 | ('dmode_index', '<u4'), | |
55 | ('dmode_rngcorr', '<u4'), |
|
55 | ('dmode_rngcorr', '<u4'), | |
56 | ('nrxs', '<u4'), |
|
56 | ('nrxs', '<u4'), | |
57 | ('acf_length', '<u4'), |
|
57 | ('acf_length', '<u4'), | |
58 | ('acf_lags', '<u4'), |
|
58 | ('acf_lags', '<u4'), | |
59 | ('sea_to_atmos', '<f4'), |
|
59 | ('sea_to_atmos', '<f4'), | |
60 | ('sea_notch', '<u4'), |
|
60 | ('sea_notch', '<u4'), | |
61 | ('lh_sea', '<u4'), |
|
61 | ('lh_sea', '<u4'), | |
62 | ('hh_sea', '<u4'), |
|
62 | ('hh_sea', '<u4'), | |
63 | ('nbins_sea', '<u4'), |
|
63 | ('nbins_sea', '<u4'), | |
64 | ('min_snr', '<f4'), |
|
64 | ('min_snr', '<f4'), | |
65 | ('min_cc', '<f4'), |
|
65 | ('min_cc', '<f4'), | |
66 | ('max_time_diff', '<f4') |
|
66 | ('max_time_diff', '<f4') | |
67 | ]) |
|
67 | ]) | |
68 |
|
68 | |||
69 | DATA_STRUCTURE = numpy.dtype([ |
|
69 | DATA_STRUCTURE = numpy.dtype([ | |
70 | ('range', '<u4'), |
|
70 | ('range', '<u4'), | |
71 | ('status', '<u4'), |
|
71 | ('status', '<u4'), | |
72 | ('zonal', '<f4'), |
|
72 | ('zonal', '<f4'), | |
73 | ('meridional', '<f4'), |
|
73 | ('meridional', '<f4'), | |
74 | ('vertical', '<f4'), |
|
74 | ('vertical', '<f4'), | |
75 | ('zonal_a', '<f4'), |
|
75 | ('zonal_a', '<f4'), | |
76 | ('meridional_a', '<f4'), |
|
76 | ('meridional_a', '<f4'), | |
77 | ('corrected_fading', '<f4'), # seconds |
|
77 | ('corrected_fading', '<f4'), # seconds | |
78 | ('uncorrected_fading', '<f4'), # seconds |
|
78 | ('uncorrected_fading', '<f4'), # seconds | |
79 | ('time_diff', '<f4'), |
|
79 | ('time_diff', '<f4'), | |
80 | ('major_axis', '<f4'), |
|
80 | ('major_axis', '<f4'), | |
81 | ('axial_ratio', '<f4'), |
|
81 | ('axial_ratio', '<f4'), | |
82 | ('orientation', '<f4'), |
|
82 | ('orientation', '<f4'), | |
83 | ('sea_power', '<u4'), |
|
83 | ('sea_power', '<u4'), | |
84 | ('sea_algorithm', '<u4') |
|
84 | ('sea_algorithm', '<u4') | |
85 | ]) |
|
85 | ]) | |
86 |
|
86 | |||
87 |
|
87 | |||
88 | class BLTRParamReader(Reader, ProcessingUnit): |
|
88 | class BLTRParamReader(Reader, ProcessingUnit): | |
89 | ''' |
|
89 | ''' | |
90 | Boundary Layer and Tropospheric Radar (BLTR) reader, Wind velocities and SNR |
|
90 | Boundary Layer and Tropospheric Radar (BLTR) reader, Wind velocities and SNR | |
91 | from *.sswma files |
|
91 | from *.sswma files | |
92 | ''' |
|
92 | ''' | |
93 |
|
93 | |||
94 | ext = '.sswma' |
|
94 | ext = '.sswma' | |
95 |
|
95 | |||
96 | def __init__(self): |
|
96 | def __init__(self): | |
97 |
|
97 | |||
98 | ProcessingUnit.__init__(self) |
|
98 | ProcessingUnit.__init__(self) | |
99 |
|
99 | |||
100 | self.dataOut = Parameters() |
|
100 | self.dataOut = Parameters() | |
101 | self.dataOut.timezone = 300 |
|
101 | self.dataOut.timezone = 300 | |
102 | self.counter_records = 0 |
|
102 | self.counter_records = 0 | |
103 | self.flagNoMoreFiles = 0 |
|
103 | self.flagNoMoreFiles = 0 | |
104 | self.isConfig = False |
|
104 | self.isConfig = False | |
105 | self.filename = None |
|
105 | self.filename = None | |
106 | self.status_value = 0 |
|
106 | self.status_value = 0 | |
107 | self.datatime = datetime.datetime(1900,1,1) |
|
107 | self.datatime = datetime.datetime(1900,1,1) | |
108 | self.filefmt = "*********%Y%m%d******" |
|
108 | self.filefmt = "*********%Y%m%d******" | |
109 |
|
109 | |||
110 | def setup(self, **kwargs): |
|
110 | def setup(self, **kwargs): | |
111 |
|
111 | |||
112 | self.set_kwargs(**kwargs) |
|
112 | self.set_kwargs(**kwargs) | |
113 |
|
113 | |||
114 | if self.path is None: |
|
114 | if self.path is None: | |
115 | raise ValueError("The path is not valid") |
|
115 | raise ValueError("The path is not valid") | |
116 |
|
116 | |||
117 | if self.online: |
|
117 | if self.online: | |
118 | log.log("Searching files in online mode...", self.name) |
|
118 | log.log("Searching files in online mode...", self.name) | |
119 |
|
119 | |||
120 | for nTries in range(self.nTries): |
|
120 | for nTries in range(self.nTries): | |
121 | fullpath = self.searchFilesOnLine(self.path, self.startDate, |
|
121 | fullpath = self.searchFilesOnLine(self.path, self.startDate, | |
122 | self.endDate, self.expLabel, self.ext, self.walk, |
|
122 | self.endDate, self.expLabel, self.ext, self.walk, | |
123 | self.filefmt, self.folderfmt) |
|
123 | self.filefmt, self.folderfmt) | |
124 | try: |
|
124 | try: | |
125 | fullpath = next(fullpath) |
|
125 | fullpath = next(fullpath) | |
126 | except: |
|
126 | except: | |
127 | fullpath = None |
|
127 | fullpath = None | |
128 |
|
128 | |||
129 | if fullpath: |
|
129 | if fullpath: | |
130 | self.fileSize = os.path.getsize(fullpath) |
|
130 | self.fileSize = os.path.getsize(fullpath) | |
131 | self.filename = fullpath |
|
131 | self.filename = fullpath | |
132 | self.flagIsNewFile = 1 |
|
132 | self.flagIsNewFile = 1 | |
133 | if self.fp != None: |
|
133 | if self.fp != None: | |
134 | self.fp.close() |
|
134 | self.fp.close() | |
135 | self.fp = self.open_file(fullpath, self.open_mode) |
|
135 | self.fp = self.open_file(fullpath, self.open_mode) | |
136 | self.flagNoMoreFiles = 0 |
|
136 | self.flagNoMoreFiles = 0 | |
137 | break |
|
137 | break | |
138 |
|
138 | |||
139 | log.warning( |
|
139 | log.warning( | |
140 | 'Waiting {} sec for a valid file in {}: try {} ...'.format( |
|
140 | 'Waiting {} sec for a valid file in {}: try {} ...'.format( | |
141 | self.delay, self.path, nTries + 1), |
|
141 | self.delay, self.path, nTries + 1), | |
142 | self.name) |
|
142 | self.name) | |
143 | time.sleep(self.delay) |
|
143 | time.sleep(self.delay) | |
144 |
|
144 | |||
145 | if not(fullpath): |
|
145 | if not(fullpath): | |
146 | raise schainpy.admin.SchainError( |
|
146 | raise schainpy.admin.SchainError( | |
147 | 'There isn\'t any valid file in {}'.format(self.path)) |
|
147 | 'There isn\'t any valid file in {}'.format(self.path)) | |
148 | self.readFirstHeader() |
|
148 | self.readFirstHeader() | |
149 | else: |
|
149 | else: | |
150 | log.log("Searching files in {}".format(self.path), self.name) |
|
150 | log.log("Searching files in {}".format(self.path), self.name) | |
151 | self.filenameList = self.searchFilesOffLine(self.path, self.startDate, |
|
151 | self.filenameList = self.searchFilesOffLine(self.path, self.startDate, | |
152 | self.endDate, self.expLabel, self.ext, self.walk, self.filefmt, self.folderfmt) |
|
152 | self.endDate, self.expLabel, self.ext, self.walk, self.filefmt, self.folderfmt) | |
153 | self.setNextFile() |
|
153 | self.setNextFile() | |
154 |
|
154 | |||
155 | def checkForRealPath(self, nextFile, nextDay): |
|
155 | def checkForRealPath(self, nextFile, nextDay): | |
156 | ''' |
|
156 | ''' | |
157 | ''' |
|
157 | ''' | |
158 |
|
158 | |||
159 | dt = self.datatime + datetime.timedelta(1) |
|
159 | dt = self.datatime + datetime.timedelta(1) | |
160 | filename = '{}.{}{}'.format(self.siteFile, dt.strftime('%Y%m%d'), self.ext) |
|
160 | filename = '{}.{}{}'.format(self.siteFile, dt.strftime('%Y%m%d'), self.ext) | |
161 | fullfilename = os.path.join(self.path, filename) |
|
161 | fullfilename = os.path.join(self.path, filename) | |
162 | if os.path.exists(fullfilename): |
|
162 | if os.path.exists(fullfilename): | |
163 | return fullfilename, filename |
|
163 | return fullfilename, filename | |
164 | return None, filename |
|
164 | return None, filename | |
165 |
|
165 | |||
166 |
|
166 | |||
167 | def readFirstHeader(self): |
|
167 | def readFirstHeader(self): | |
168 | ''' |
|
168 | ''' | |
169 | ''' |
|
169 | ''' | |
170 |
|
170 | |||
171 | # 'peru2' ---> Piura - 'peru1' ---> Huancayo or Porcuya |
|
171 | # 'peru2' ---> Piura - 'peru1' ---> Huancayo or Porcuya | |
172 | self.siteFile = self.filename.split('/')[-1].split('.')[0] |
|
172 | self.siteFile = self.filename.split('/')[-1].split('.')[0] | |
173 | self.header_file = numpy.fromfile(self.fp, FILE_HEADER_STRUCTURE, 1) |
|
173 | self.header_file = numpy.fromfile(self.fp, FILE_HEADER_STRUCTURE, 1) | |
174 | self.nrecords = self.header_file['nrec'][0] |
|
174 | self.nrecords = self.header_file['nrec'][0] | |
175 | self.counter_records = 0 |
|
175 | self.counter_records = 0 | |
176 | self.flagIsNewFile = 0 |
|
176 | self.flagIsNewFile = 0 | |
177 | self.fileIndex += 1 |
|
177 | self.fileIndex += 1 | |
178 |
|
178 | |||
179 | def readNextBlock(self): |
|
179 | def readNextBlock(self): | |
180 |
|
180 | |||
181 | while True: |
|
181 | while True: | |
182 | if not self.online and self.counter_records == self.nrecords: |
|
182 | if not self.online and self.counter_records == self.nrecords: | |
183 | self.flagIsNewFile = 1 |
|
183 | self.flagIsNewFile = 1 | |
184 | if not self.setNextFile(): |
|
184 | if not self.setNextFile(): | |
185 | return 0 |
|
185 | return 0 | |
186 | try: |
|
186 | try: | |
187 | pointer = self.fp.tell() |
|
187 | pointer = self.fp.tell() | |
188 | self.readBlock() |
|
188 | self.readBlock() | |
189 | except: |
|
189 | except: | |
190 | if self.online and self.waitDataBlock(pointer, 38512) == 1: |
|
190 | if self.online and self.waitDataBlock(pointer, 38512) == 1: | |
191 | continue |
|
191 | continue | |
192 | else: |
|
192 | else: | |
193 | if not self.setNextFile(): |
|
193 | if not self.setNextFile(): | |
194 | return 0 |
|
194 | return 0 | |
195 |
|
195 | |||
196 | if (self.datatime < datetime.datetime.combine(self.startDate, self.startTime)) or \ |
|
196 | if (self.datatime < datetime.datetime.combine(self.startDate, self.startTime)) or \ | |
197 | (self.datatime > datetime.datetime.combine(self.endDate, self.endTime)): |
|
197 | (self.datatime > datetime.datetime.combine(self.endDate, self.endTime)): | |
198 | log.warning( |
|
198 | log.warning( | |
199 | 'Reading Record No. {}/{} -> {} [Skipping]'.format( |
|
199 | 'Reading Record No. {}/{} -> {} [Skipping]'.format( | |
200 | self.counter_records, |
|
200 | self.counter_records, | |
201 | self.nrecords, |
|
201 | self.nrecords, | |
202 | self.datatime.ctime()), |
|
202 | self.datatime.ctime()), | |
203 | 'BLTRParamReader') |
|
203 | 'BLTRParamReader') | |
204 | continue |
|
204 | continue | |
205 | break |
|
205 | break | |
206 |
|
206 | |||
207 | log.log('Reading Record No. {} -> {}'.format( |
|
207 | log.log('Reading Record No. {} -> {}'.format( | |
208 | self.counter_records, |
|
208 | self.counter_records, | |
209 | self.datatime.ctime()), 'BLTRParamReader') |
|
209 | self.datatime.ctime()), 'BLTRParamReader') | |
210 |
|
210 | |||
211 | return 1 |
|
211 | return 1 | |
212 |
|
212 | |||
213 | def readBlock(self): |
|
213 | def readBlock(self): | |
214 |
|
214 | |||
215 | pointer = self.fp.tell() |
|
215 | pointer = self.fp.tell() | |
216 | header_rec = numpy.fromfile(self.fp, REC_HEADER_STRUCTURE, 1) |
|
216 | header_rec = numpy.fromfile(self.fp, REC_HEADER_STRUCTURE, 1) | |
217 | self.nchannels = int(header_rec['nchan'][0] / 2) |
|
217 | self.nchannels = int(header_rec['nchan'][0] / 2) | |
218 | self.kchan = header_rec['nrxs'][0] |
|
218 | self.kchan = header_rec['nrxs'][0] | |
219 | self.nmodes = header_rec['nmodes'][0] |
|
219 | self.nmodes = header_rec['nmodes'][0] | |
220 | self.nranges = header_rec['nranges'][0] |
|
220 | self.nranges = header_rec['nranges'][0] | |
221 | self.fp.seek(pointer) |
|
221 | self.fp.seek(pointer) | |
222 | self.height = numpy.empty((self.nmodes, self.nranges)) |
|
222 | self.height = numpy.empty((self.nmodes, self.nranges)) | |
223 | self.snr = numpy.empty((self.nmodes, int(self.nchannels), self.nranges)) |
|
223 | self.snr = numpy.empty((self.nmodes, int(self.nchannels), self.nranges)) | |
224 | self.buffer = numpy.empty((self.nmodes, 3, self.nranges)) |
|
224 | self.buffer = numpy.empty((self.nmodes, 3, self.nranges)) | |
225 | self.flagDiscontinuousBlock = 0 |
|
225 | self.flagDiscontinuousBlock = 0 | |
226 |
|
226 | |||
227 | for mode in range(self.nmodes): |
|
227 | for mode in range(self.nmodes): | |
228 | self.readHeader() |
|
228 | self.readHeader() | |
229 | data = self.readData() |
|
229 | data = self.readData() | |
230 | self.height[mode] = (data[0] - self.correction) / 1000. |
|
230 | self.height[mode] = (data[0] - self.correction) / 1000. | |
231 | self.buffer[mode] = data[1] |
|
231 | self.buffer[mode] = data[1] | |
232 | self.snr[mode] = data[2] |
|
232 | self.snr[mode] = data[2] | |
233 |
|
233 | |||
234 | self.counter_records = self.counter_records + self.nmodes |
|
234 | self.counter_records = self.counter_records + self.nmodes | |
235 |
|
235 | |||
236 | return |
|
236 | return | |
237 |
|
237 | |||
238 | def readHeader(self): |
|
238 | def readHeader(self): | |
239 | ''' |
|
239 | ''' | |
240 | RecordHeader of BLTR rawdata file |
|
240 | RecordHeader of BLTR rawdata file | |
241 | ''' |
|
241 | ''' | |
242 |
|
242 | |||
243 | header_structure = numpy.dtype( |
|
243 | header_structure = numpy.dtype( | |
244 | REC_HEADER_STRUCTURE.descr + [ |
|
244 | REC_HEADER_STRUCTURE.descr + [ | |
245 | ('antenna_coord', 'f4', (2, int(self.nchannels))), |
|
245 | ('antenna_coord', 'f4', (2, int(self.nchannels))), | |
246 | ('rx_gains', 'u4', (int(self.nchannels),)), |
|
246 | ('rx_gains', 'u4', (int(self.nchannels),)), | |
247 | ('rx_analysis', 'u4', (int(self.nchannels),)) |
|
247 | ('rx_analysis', 'u4', (int(self.nchannels),)) | |
248 | ] |
|
248 | ] | |
249 | ) |
|
249 | ) | |
250 |
|
250 | |||
251 | self.header_rec = numpy.fromfile(self.fp, header_structure, 1) |
|
251 | self.header_rec = numpy.fromfile(self.fp, header_structure, 1) | |
252 | self.lat = self.header_rec['lat'][0] |
|
252 | self.lat = self.header_rec['lat'][0] | |
253 | self.lon = self.header_rec['lon'][0] |
|
253 | self.lon = self.header_rec['lon'][0] | |
254 | self.delta = self.header_rec['delta_r'][0] |
|
254 | self.delta = self.header_rec['delta_r'][0] | |
255 | self.correction = self.header_rec['dmode_rngcorr'][0] |
|
255 | self.correction = self.header_rec['dmode_rngcorr'][0] | |
256 | self.imode = self.header_rec['dmode_index'][0] |
|
256 | self.imode = self.header_rec['dmode_index'][0] | |
257 | self.antenna = self.header_rec['antenna_coord'] |
|
257 | self.antenna = self.header_rec['antenna_coord'] | |
258 | self.rx_gains = self.header_rec['rx_gains'] |
|
258 | self.rx_gains = self.header_rec['rx_gains'] | |
259 | self.time = self.header_rec['time'][0] |
|
259 | self.time = self.header_rec['time'][0] | |
260 | dt = datetime.datetime.utcfromtimestamp(self.time) |
|
260 | dt = datetime.datetime.utcfromtimestamp(self.time) | |
261 | if dt.date()>self.datatime.date(): |
|
261 | if dt.date()>self.datatime.date(): | |
262 | self.flagDiscontinuousBlock = 1 |
|
262 | self.flagDiscontinuousBlock = 1 | |
263 | self.datatime = dt |
|
263 | self.datatime = dt | |
264 |
|
264 | |||
265 | def readData(self): |
|
265 | def readData(self): | |
266 | ''' |
|
266 | ''' | |
267 | Reading and filtering data block record of BLTR rawdata file, |
|
267 | Reading and filtering data block record of BLTR rawdata file, | |
268 | filtering is according to status_value. |
|
268 | filtering is according to status_value. | |
269 |
|
269 | |||
270 | Input: |
|
270 | Input: | |
271 | status_value - Array data is set to NAN for values that are not |
|
271 | status_value - Array data is set to NAN for values that are not | |
272 | equal to status_value |
|
272 | equal to status_value | |
273 |
|
273 | |||
274 | ''' |
|
274 | ''' | |
275 | self.nchannels = int(self.nchannels) |
|
275 | self.nchannels = int(self.nchannels) | |
276 |
|
276 | |||
277 | data_structure = numpy.dtype( |
|
277 | data_structure = numpy.dtype( | |
278 | DATA_STRUCTURE.descr + [ |
|
278 | DATA_STRUCTURE.descr + [ | |
279 | ('rx_saturation', 'u4', (self.nchannels,)), |
|
279 | ('rx_saturation', 'u4', (self.nchannels,)), | |
280 | ('chan_offset', 'u4', (2 * self.nchannels,)), |
|
280 | ('chan_offset', 'u4', (2 * self.nchannels,)), | |
281 | ('rx_amp', 'u4', (self.nchannels,)), |
|
281 | ('rx_amp', 'u4', (self.nchannels,)), | |
282 | ('rx_snr', 'f4', (self.nchannels,)), |
|
282 | ('rx_snr', 'f4', (self.nchannels,)), | |
283 | ('cross_snr', 'f4', (self.kchan,)), |
|
283 | ('cross_snr', 'f4', (self.kchan,)), | |
284 | ('sea_power_relative', 'f4', (self.kchan,))] |
|
284 | ('sea_power_relative', 'f4', (self.kchan,))] | |
285 | ) |
|
285 | ) | |
286 |
|
286 | |||
287 | data = numpy.fromfile(self.fp, data_structure, self.nranges) |
|
287 | data = numpy.fromfile(self.fp, data_structure, self.nranges) | |
288 |
|
288 | |||
289 | height = data['range'] |
|
289 | height = data['range'] | |
290 | winds = numpy.array( |
|
290 | winds = numpy.array( | |
291 | (data['zonal'], data['meridional'], data['vertical'])) |
|
291 | (data['zonal'], data['meridional'], data['vertical'])) | |
292 | snr = data['rx_snr'].T |
|
292 | snr = data['rx_snr'].T | |
293 |
|
293 | |||
294 | winds[numpy.where(winds == -9999.)] = numpy.nan |
|
294 | winds[numpy.where(winds == -9999.)] = numpy.nan | |
295 | winds[:, numpy.where(data['status'] != self.status_value)] = numpy.nan |
|
295 | winds[:, numpy.where(data['status'] != self.status_value)] = numpy.nan | |
296 | snr[numpy.where(snr == -9999.)] = numpy.nan |
|
296 | snr[numpy.where(snr == -9999.)] = numpy.nan | |
297 | snr[:, numpy.where(data['status'] != self.status_value)] = numpy.nan |
|
297 | snr[:, numpy.where(data['status'] != self.status_value)] = numpy.nan | |
298 | snr = numpy.power(10, snr / 10) |
|
298 | snr = numpy.power(10, snr / 10) | |
299 |
|
299 | |||
300 | return height, winds, snr |
|
300 | return height, winds, snr | |
301 |
|
301 | |||
302 | def set_output(self): |
|
302 | def set_output(self): | |
303 | ''' |
|
303 | ''' | |
304 | Storing data from databuffer to dataOut object |
|
304 | Storing data from databuffer to dataOut object | |
305 | ''' |
|
305 | ''' | |
306 |
|
306 | |||
307 |
self.dataOut.data_ |
|
307 | self.dataOut.data_snr = self.snr | |
308 | self.dataOut.height = self.height |
|
308 | self.dataOut.height = self.height | |
309 | self.dataOut.data = self.buffer |
|
309 | self.dataOut.data = self.buffer | |
310 | self.dataOut.utctimeInit = self.time |
|
310 | self.dataOut.utctimeInit = self.time | |
311 | self.dataOut.utctime = self.dataOut.utctimeInit |
|
311 | self.dataOut.utctime = self.dataOut.utctimeInit | |
312 | self.dataOut.useLocalTime = False |
|
312 | self.dataOut.useLocalTime = False | |
313 | self.dataOut.paramInterval = 157 |
|
313 | self.dataOut.paramInterval = 157 | |
314 | self.dataOut.site = self.siteFile |
|
314 | self.dataOut.site = self.siteFile | |
315 | self.dataOut.nrecords = self.nrecords / self.nmodes |
|
315 | self.dataOut.nrecords = self.nrecords / self.nmodes | |
316 | self.dataOut.lat = self.lat |
|
316 | self.dataOut.lat = self.lat | |
317 | self.dataOut.lon = self.lon |
|
317 | self.dataOut.lon = self.lon | |
318 | self.dataOut.channelList = list(range(self.nchannels)) |
|
318 | self.dataOut.channelList = list(range(self.nchannels)) | |
319 | self.dataOut.kchan = self.kchan |
|
319 | self.dataOut.kchan = self.kchan | |
320 | self.dataOut.delta = self.delta |
|
320 | self.dataOut.delta = self.delta | |
321 | self.dataOut.correction = self.correction |
|
321 | self.dataOut.correction = self.correction | |
322 | self.dataOut.nmodes = self.nmodes |
|
322 | self.dataOut.nmodes = self.nmodes | |
323 | self.dataOut.imode = self.imode |
|
323 | self.dataOut.imode = self.imode | |
324 | self.dataOut.antenna = self.antenna |
|
324 | self.dataOut.antenna = self.antenna | |
325 | self.dataOut.rx_gains = self.rx_gains |
|
325 | self.dataOut.rx_gains = self.rx_gains | |
326 | self.dataOut.flagNoData = False |
|
326 | self.dataOut.flagNoData = False | |
327 | self.dataOut.flagDiscontinuousBlock = self.flagDiscontinuousBlock |
|
327 | self.dataOut.flagDiscontinuousBlock = self.flagDiscontinuousBlock | |
328 |
|
328 | |||
329 | def getData(self): |
|
329 | def getData(self): | |
330 | ''' |
|
330 | ''' | |
331 | Storing data from databuffer to dataOut object |
|
331 | Storing data from databuffer to dataOut object | |
332 | ''' |
|
332 | ''' | |
333 | if self.flagNoMoreFiles: |
|
333 | if self.flagNoMoreFiles: | |
334 | self.dataOut.flagNoData = True |
|
334 | self.dataOut.flagNoData = True | |
335 | return 0 |
|
335 | return 0 | |
336 |
|
336 | |||
337 | if not self.readNextBlock(): |
|
337 | if not self.readNextBlock(): | |
338 | self.dataOut.flagNoData = True |
|
338 | self.dataOut.flagNoData = True | |
339 | return 0 |
|
339 | return 0 | |
340 |
|
340 | |||
341 | self.set_output() |
|
341 | self.set_output() | |
342 |
|
342 | |||
343 | return 1 |
|
343 | return 1 | |
344 |
|
344 | |||
345 | def run(self, **kwargs): |
|
345 | def run(self, **kwargs): | |
346 | ''' |
|
346 | ''' | |
347 | ''' |
|
347 | ''' | |
348 |
|
348 | |||
349 | if not(self.isConfig): |
|
349 | if not(self.isConfig): | |
350 | self.setup(**kwargs) |
|
350 | self.setup(**kwargs) | |
351 | self.isConfig = True |
|
351 | self.isConfig = True | |
352 |
|
352 | |||
353 | self.getData() |
|
353 | self.getData() | |
354 |
|
354 | |||
355 | return No newline at end of file |
|
355 | return |
@@ -1,626 +1,627 | |||||
1 | import os |
|
1 | import os | |
2 | import time |
|
2 | import time | |
3 | import datetime |
|
3 | import datetime | |
4 |
|
4 | |||
5 | import numpy |
|
5 | import numpy | |
6 | import h5py |
|
6 | import h5py | |
7 |
|
7 | |||
8 | import schainpy.admin |
|
8 | import schainpy.admin | |
9 | from schainpy.model.data.jrodata import * |
|
9 | from schainpy.model.data.jrodata import * | |
10 | from schainpy.model.proc.jroproc_base import ProcessingUnit, Operation, MPDecorator |
|
10 | from schainpy.model.proc.jroproc_base import ProcessingUnit, Operation, MPDecorator | |
11 | from schainpy.model.io.jroIO_base import * |
|
11 | from schainpy.model.io.jroIO_base import * | |
12 | from schainpy.utils import log |
|
12 | from schainpy.utils import log | |
13 |
|
13 | |||
14 |
|
14 | |||
15 | class HDFReader(Reader, ProcessingUnit): |
|
15 | class HDFReader(Reader, ProcessingUnit): | |
16 | """Processing unit to read HDF5 format files |
|
16 | """Processing unit to read HDF5 format files | |
17 |
|
17 | |||
18 | This unit reads HDF5 files created with `HDFWriter` operation contains |
|
18 | This unit reads HDF5 files created with `HDFWriter` operation contains | |
19 | by default two groups Data and Metadata all variables would be saved as `dataOut` |
|
19 | by default two groups Data and Metadata all variables would be saved as `dataOut` | |
20 | attributes. |
|
20 | attributes. | |
21 | It is possible to read any HDF5 file by given the structure in the `description` |
|
21 | It is possible to read any HDF5 file by given the structure in the `description` | |
22 | parameter, also you can add extra values to metadata with the parameter `extras`. |
|
22 | parameter, also you can add extra values to metadata with the parameter `extras`. | |
23 |
|
23 | |||
24 | Parameters: |
|
24 | Parameters: | |
25 | ----------- |
|
25 | ----------- | |
26 | path : str |
|
26 | path : str | |
27 | Path where files are located. |
|
27 | Path where files are located. | |
28 | startDate : date |
|
28 | startDate : date | |
29 | Start date of the files |
|
29 | Start date of the files | |
30 | endDate : list |
|
30 | endDate : list | |
31 | End date of the files |
|
31 | End date of the files | |
32 | startTime : time |
|
32 | startTime : time | |
33 | Start time of the files |
|
33 | Start time of the files | |
34 | endTime : time |
|
34 | endTime : time | |
35 | End time of the files |
|
35 | End time of the files | |
36 | description : dict, optional |
|
36 | description : dict, optional | |
37 | Dictionary with the description of the HDF5 file |
|
37 | Dictionary with the description of the HDF5 file | |
38 | extras : dict, optional |
|
38 | extras : dict, optional | |
39 | Dictionary with extra metadata to be be added to `dataOut` |
|
39 | Dictionary with extra metadata to be be added to `dataOut` | |
40 |
|
40 | |||
41 | Examples |
|
41 | Examples | |
42 | -------- |
|
42 | -------- | |
43 |
|
43 | |||
44 | desc = { |
|
44 | desc = { | |
45 | 'Data': { |
|
45 | 'Data': { | |
46 | 'data_output': ['u', 'v', 'w'], |
|
46 | 'data_output': ['u', 'v', 'w'], | |
47 | 'utctime': 'timestamps', |
|
47 | 'utctime': 'timestamps', | |
48 | } , |
|
48 | } , | |
49 | 'Metadata': { |
|
49 | 'Metadata': { | |
50 | 'heightList': 'heights' |
|
50 | 'heightList': 'heights' | |
51 | } |
|
51 | } | |
52 | } |
|
52 | } | |
53 |
|
53 | |||
54 | desc = { |
|
54 | desc = { | |
55 | 'Data': { |
|
55 | 'Data': { | |
56 | 'data_output': 'winds', |
|
56 | 'data_output': 'winds', | |
57 | 'utctime': 'timestamps' |
|
57 | 'utctime': 'timestamps' | |
58 | }, |
|
58 | }, | |
59 | 'Metadata': { |
|
59 | 'Metadata': { | |
60 | 'heightList': 'heights' |
|
60 | 'heightList': 'heights' | |
61 | } |
|
61 | } | |
62 | } |
|
62 | } | |
63 |
|
63 | |||
64 | extras = { |
|
64 | extras = { | |
65 | 'timeZone': 300 |
|
65 | 'timeZone': 300 | |
66 | } |
|
66 | } | |
67 |
|
67 | |||
68 | reader = project.addReadUnit( |
|
68 | reader = project.addReadUnit( | |
69 | name='HDFReader', |
|
69 | name='HDFReader', | |
70 | path='/path/to/files', |
|
70 | path='/path/to/files', | |
71 | startDate='2019/01/01', |
|
71 | startDate='2019/01/01', | |
72 | endDate='2019/01/31', |
|
72 | endDate='2019/01/31', | |
73 | startTime='00:00:00', |
|
73 | startTime='00:00:00', | |
74 | endTime='23:59:59', |
|
74 | endTime='23:59:59', | |
75 | # description=json.dumps(desc), |
|
75 | # description=json.dumps(desc), | |
76 | # extras=json.dumps(extras), |
|
76 | # extras=json.dumps(extras), | |
77 | ) |
|
77 | ) | |
78 |
|
78 | |||
79 | """ |
|
79 | """ | |
80 |
|
80 | |||
81 | __attrs__ = ['path', 'startDate', 'endDate', 'startTime', 'endTime', 'description', 'extras'] |
|
81 | __attrs__ = ['path', 'startDate', 'endDate', 'startTime', 'endTime', 'description', 'extras'] | |
82 |
|
82 | |||
83 | def __init__(self): |
|
83 | def __init__(self): | |
84 | ProcessingUnit.__init__(self) |
|
84 | ProcessingUnit.__init__(self) | |
85 | self.dataOut = Parameters() |
|
85 | self.dataOut = Parameters() | |
86 | self.ext = ".hdf5" |
|
86 | self.ext = ".hdf5" | |
87 | self.optchar = "D" |
|
87 | self.optchar = "D" | |
88 | self.meta = {} |
|
88 | self.meta = {} | |
89 | self.data = {} |
|
89 | self.data = {} | |
90 | self.open_file = h5py.File |
|
90 | self.open_file = h5py.File | |
91 | self.open_mode = 'r' |
|
91 | self.open_mode = 'r' | |
92 | self.description = {} |
|
92 | self.description = {} | |
93 | self.extras = {} |
|
93 | self.extras = {} | |
94 | self.filefmt = "*%Y%j***" |
|
94 | self.filefmt = "*%Y%j***" | |
95 | self.folderfmt = "*%Y%j" |
|
95 | self.folderfmt = "*%Y%j" | |
96 |
|
96 | |||
97 | def setup(self, **kwargs): |
|
97 | def setup(self, **kwargs): | |
98 |
|
98 | |||
99 | self.set_kwargs(**kwargs) |
|
99 | self.set_kwargs(**kwargs) | |
100 | if not self.ext.startswith('.'): |
|
100 | if not self.ext.startswith('.'): | |
101 | self.ext = '.{}'.format(self.ext) |
|
101 | self.ext = '.{}'.format(self.ext) | |
102 |
|
102 | |||
103 | if self.online: |
|
103 | if self.online: | |
104 | log.log("Searching files in online mode...", self.name) |
|
104 | log.log("Searching files in online mode...", self.name) | |
105 |
|
105 | |||
106 | for nTries in range(self.nTries): |
|
106 | for nTries in range(self.nTries): | |
107 | fullpath = self.searchFilesOnLine(self.path, self.startDate, |
|
107 | fullpath = self.searchFilesOnLine(self.path, self.startDate, | |
108 | self.endDate, self.expLabel, self.ext, self.walk, |
|
108 | self.endDate, self.expLabel, self.ext, self.walk, | |
109 | self.filefmt, self.folderfmt) |
|
109 | self.filefmt, self.folderfmt) | |
110 | try: |
|
110 | try: | |
111 | fullpath = next(fullpath) |
|
111 | fullpath = next(fullpath) | |
112 | except: |
|
112 | except: | |
113 | fullpath = None |
|
113 | fullpath = None | |
114 |
|
114 | |||
115 | if fullpath: |
|
115 | if fullpath: | |
116 | break |
|
116 | break | |
117 |
|
117 | |||
118 | log.warning( |
|
118 | log.warning( | |
119 | 'Waiting {} sec for a valid file in {}: try {} ...'.format( |
|
119 | 'Waiting {} sec for a valid file in {}: try {} ...'.format( | |
120 | self.delay, self.path, nTries + 1), |
|
120 | self.delay, self.path, nTries + 1), | |
121 | self.name) |
|
121 | self.name) | |
122 | time.sleep(self.delay) |
|
122 | time.sleep(self.delay) | |
123 |
|
123 | |||
124 | if not(fullpath): |
|
124 | if not(fullpath): | |
125 | raise schainpy.admin.SchainError( |
|
125 | raise schainpy.admin.SchainError( | |
126 | 'There isn\'t any valid file in {}'.format(self.path)) |
|
126 | 'There isn\'t any valid file in {}'.format(self.path)) | |
127 |
|
127 | |||
128 | pathname, filename = os.path.split(fullpath) |
|
128 | pathname, filename = os.path.split(fullpath) | |
129 | self.year = int(filename[1:5]) |
|
129 | self.year = int(filename[1:5]) | |
130 | self.doy = int(filename[5:8]) |
|
130 | self.doy = int(filename[5:8]) | |
131 | self.set = int(filename[8:11]) - 1 |
|
131 | self.set = int(filename[8:11]) - 1 | |
132 | else: |
|
132 | else: | |
133 | log.log("Searching files in {}".format(self.path), self.name) |
|
133 | log.log("Searching files in {}".format(self.path), self.name) | |
134 | self.filenameList = self.searchFilesOffLine(self.path, self.startDate, |
|
134 | self.filenameList = self.searchFilesOffLine(self.path, self.startDate, | |
135 | self.endDate, self.expLabel, self.ext, self.walk, self.filefmt, self.folderfmt) |
|
135 | self.endDate, self.expLabel, self.ext, self.walk, self.filefmt, self.folderfmt) | |
136 |
|
136 | |||
137 | self.setNextFile() |
|
137 | self.setNextFile() | |
138 |
|
138 | |||
139 | return |
|
139 | return | |
140 |
|
140 | |||
141 | def readFirstHeader(self): |
|
141 | def readFirstHeader(self): | |
142 | '''Read metadata and data''' |
|
142 | '''Read metadata and data''' | |
143 |
|
143 | |||
144 | self.__readMetadata() |
|
144 | self.__readMetadata() | |
145 | self.__readData() |
|
145 | self.__readData() | |
146 | self.__setBlockList() |
|
146 | self.__setBlockList() | |
147 |
|
147 | |||
148 | if 'type' in self.meta: |
|
148 | if 'type' in self.meta: | |
149 | self.dataOut = eval(self.meta['type'])() |
|
149 | self.dataOut = eval(self.meta['type'])() | |
150 |
|
150 | |||
151 | for attr in self.meta: |
|
151 | for attr in self.meta: | |
152 | setattr(self.dataOut, attr, self.meta[attr]) |
|
152 | setattr(self.dataOut, attr, self.meta[attr]) | |
153 |
|
153 | |||
154 | self.blockIndex = 0 |
|
154 | self.blockIndex = 0 | |
155 |
|
155 | |||
156 | return |
|
156 | return | |
157 |
|
157 | |||
158 | def __setBlockList(self): |
|
158 | def __setBlockList(self): | |
159 | ''' |
|
159 | ''' | |
160 | Selects the data within the times defined |
|
160 | Selects the data within the times defined | |
161 |
|
161 | |||
162 | self.fp |
|
162 | self.fp | |
163 | self.startTime |
|
163 | self.startTime | |
164 | self.endTime |
|
164 | self.endTime | |
165 | self.blockList |
|
165 | self.blockList | |
166 | self.blocksPerFile |
|
166 | self.blocksPerFile | |
167 |
|
167 | |||
168 | ''' |
|
168 | ''' | |
169 |
|
169 | |||
170 | startTime = self.startTime |
|
170 | startTime = self.startTime | |
171 | endTime = self.endTime |
|
171 | endTime = self.endTime | |
172 |
|
172 | |||
173 | thisUtcTime = self.data['utctime'] |
|
173 | thisUtcTime = self.data['utctime'] | |
174 | self.interval = numpy.min(thisUtcTime[1:] - thisUtcTime[:-1]) |
|
174 | self.interval = numpy.min(thisUtcTime[1:] - thisUtcTime[:-1]) | |
175 |
|
175 | |||
176 | thisDatetime = datetime.datetime.utcfromtimestamp(thisUtcTime[0]) |
|
176 | thisDatetime = datetime.datetime.utcfromtimestamp(thisUtcTime[0]) | |
177 |
|
177 | |||
178 | thisDate = thisDatetime.date() |
|
178 | thisDate = thisDatetime.date() | |
179 | thisTime = thisDatetime.time() |
|
179 | thisTime = thisDatetime.time() | |
180 |
|
180 | |||
181 | startUtcTime = (datetime.datetime.combine(thisDate, startTime) - datetime.datetime(1970, 1, 1)).total_seconds() |
|
181 | startUtcTime = (datetime.datetime.combine(thisDate, startTime) - datetime.datetime(1970, 1, 1)).total_seconds() | |
182 | endUtcTime = (datetime.datetime.combine(thisDate, endTime) - datetime.datetime(1970, 1, 1)).total_seconds() |
|
182 | endUtcTime = (datetime.datetime.combine(thisDate, endTime) - datetime.datetime(1970, 1, 1)).total_seconds() | |
183 |
|
183 | |||
184 | ind = numpy.where(numpy.logical_and(thisUtcTime >= startUtcTime, thisUtcTime < endUtcTime))[0] |
|
184 | ind = numpy.where(numpy.logical_and(thisUtcTime >= startUtcTime, thisUtcTime < endUtcTime))[0] | |
185 |
|
185 | |||
186 | self.blockList = ind |
|
186 | self.blockList = ind | |
187 | self.blocksPerFile = len(ind) |
|
187 | self.blocksPerFile = len(ind) | |
188 | return |
|
188 | return | |
189 |
|
189 | |||
190 | def __readMetadata(self): |
|
190 | def __readMetadata(self): | |
191 | ''' |
|
191 | ''' | |
192 | Reads Metadata |
|
192 | Reads Metadata | |
193 | ''' |
|
193 | ''' | |
194 |
|
194 | |||
195 | meta = {} |
|
195 | meta = {} | |
196 |
|
196 | |||
197 | if self.description: |
|
197 | if self.description: | |
198 | for key, value in self.description['Metadata'].items(): |
|
198 | for key, value in self.description['Metadata'].items(): | |
199 | meta[key] = self.fp[value].value |
|
199 | meta[key] = self.fp[value].value | |
200 | else: |
|
200 | else: | |
201 | grp = self.fp['Metadata'] |
|
201 | grp = self.fp['Metadata'] | |
202 | for name in grp: |
|
202 | for name in grp: | |
203 | meta[name] = grp[name].value |
|
203 | meta[name] = grp[name].value | |
204 |
|
204 | |||
205 | if self.extras: |
|
205 | if self.extras: | |
206 | for key, value in self.extras.items(): |
|
206 | for key, value in self.extras.items(): | |
207 | meta[key] = value |
|
207 | meta[key] = value | |
208 | self.meta = meta |
|
208 | self.meta = meta | |
209 |
|
209 | |||
210 | return |
|
210 | return | |
211 |
|
211 | |||
212 | def __readData(self): |
|
212 | def __readData(self): | |
213 |
|
213 | |||
214 | data = {} |
|
214 | data = {} | |
215 |
|
215 | |||
216 | if self.description: |
|
216 | if self.description: | |
217 | for key, value in self.description['Data'].items(): |
|
217 | for key, value in self.description['Data'].items(): | |
218 | if isinstance(value, str): |
|
218 | if isinstance(value, str): | |
219 | if isinstance(self.fp[value], h5py.Dataset): |
|
219 | if isinstance(self.fp[value], h5py.Dataset): | |
220 | data[key] = self.fp[value].value |
|
220 | data[key] = self.fp[value].value | |
221 | elif isinstance(self.fp[value], h5py.Group): |
|
221 | elif isinstance(self.fp[value], h5py.Group): | |
222 | array = [] |
|
222 | array = [] | |
223 | for ch in self.fp[value]: |
|
223 | for ch in self.fp[value]: | |
224 | array.append(self.fp[value][ch].value) |
|
224 | array.append(self.fp[value][ch].value) | |
225 | data[key] = numpy.array(array) |
|
225 | data[key] = numpy.array(array) | |
226 | elif isinstance(value, list): |
|
226 | elif isinstance(value, list): | |
227 | array = [] |
|
227 | array = [] | |
228 | for ch in value: |
|
228 | for ch in value: | |
229 | array.append(self.fp[ch].value) |
|
229 | array.append(self.fp[ch].value) | |
230 | data[key] = numpy.array(array) |
|
230 | data[key] = numpy.array(array) | |
231 | else: |
|
231 | else: | |
232 | grp = self.fp['Data'] |
|
232 | grp = self.fp['Data'] | |
233 | for name in grp: |
|
233 | for name in grp: | |
234 | if isinstance(grp[name], h5py.Dataset): |
|
234 | if isinstance(grp[name], h5py.Dataset): | |
235 | array = grp[name].value |
|
235 | array = grp[name].value | |
236 | elif isinstance(grp[name], h5py.Group): |
|
236 | elif isinstance(grp[name], h5py.Group): | |
237 | array = [] |
|
237 | array = [] | |
238 | for ch in grp[name]: |
|
238 | for ch in grp[name]: | |
239 | array.append(grp[name][ch].value) |
|
239 | array.append(grp[name][ch].value) | |
240 | array = numpy.array(array) |
|
240 | array = numpy.array(array) | |
241 | else: |
|
241 | else: | |
242 | log.warning('Unknown type: {}'.format(name)) |
|
242 | log.warning('Unknown type: {}'.format(name)) | |
243 |
|
243 | |||
244 | if name in self.description: |
|
244 | if name in self.description: | |
245 | key = self.description[name] |
|
245 | key = self.description[name] | |
246 | else: |
|
246 | else: | |
247 | key = name |
|
247 | key = name | |
248 | data[key] = array |
|
248 | data[key] = array | |
249 |
|
249 | |||
250 | self.data = data |
|
250 | self.data = data | |
251 | return |
|
251 | return | |
252 |
|
252 | |||
253 | def getData(self): |
|
253 | def getData(self): | |
254 |
|
254 | |||
255 | for attr in self.data: |
|
255 | for attr in self.data: | |
256 | if self.data[attr].ndim == 1: |
|
256 | if self.data[attr].ndim == 1: | |
257 | setattr(self.dataOut, attr, self.data[attr][self.blockIndex]) |
|
257 | setattr(self.dataOut, attr, self.data[attr][self.blockIndex]) | |
258 | else: |
|
258 | else: | |
259 | setattr(self.dataOut, attr, self.data[attr][:, self.blockIndex]) |
|
259 | setattr(self.dataOut, attr, self.data[attr][:, self.blockIndex]) | |
260 |
|
260 | |||
261 | self.dataOut.flagNoData = False |
|
261 | self.dataOut.flagNoData = False | |
262 | self.blockIndex += 1 |
|
262 | self.blockIndex += 1 | |
263 |
|
263 | |||
264 | log.log("Block No. {}/{} -> {}".format( |
|
264 | log.log("Block No. {}/{} -> {}".format( | |
265 | self.blockIndex, |
|
265 | self.blockIndex, | |
266 | self.blocksPerFile, |
|
266 | self.blocksPerFile, | |
267 | self.dataOut.datatime.ctime()), self.name) |
|
267 | self.dataOut.datatime.ctime()), self.name) | |
268 |
|
268 | |||
269 | return |
|
269 | return | |
270 |
|
270 | |||
271 | def run(self, **kwargs): |
|
271 | def run(self, **kwargs): | |
272 |
|
272 | |||
273 | if not(self.isConfig): |
|
273 | if not(self.isConfig): | |
274 | self.setup(**kwargs) |
|
274 | self.setup(**kwargs) | |
275 | self.isConfig = True |
|
275 | self.isConfig = True | |
276 |
|
276 | |||
277 | if self.blockIndex == self.blocksPerFile: |
|
277 | if self.blockIndex == self.blocksPerFile: | |
278 | self.setNextFile() |
|
278 | self.setNextFile() | |
279 |
|
279 | |||
280 | self.getData() |
|
280 | self.getData() | |
281 |
|
281 | |||
282 | return |
|
282 | return | |
283 |
|
283 | |||
284 | @MPDecorator |
|
284 | @MPDecorator | |
285 | class HDFWriter(Operation): |
|
285 | class HDFWriter(Operation): | |
286 | """Operation to write HDF5 files. |
|
286 | """Operation to write HDF5 files. | |
287 |
|
287 | |||
288 | The HDF5 file contains by default two groups Data and Metadata where |
|
288 | The HDF5 file contains by default two groups Data and Metadata where | |
289 | you can save any `dataOut` attribute specified by `dataList` and `metadataList` |
|
289 | you can save any `dataOut` attribute specified by `dataList` and `metadataList` | |
290 | parameters, data attributes are normaly time dependent where the metadata |
|
290 | parameters, data attributes are normaly time dependent where the metadata | |
291 | are not. |
|
291 | are not. | |
292 | It is possible to customize the structure of the HDF5 file with the |
|
292 | It is possible to customize the structure of the HDF5 file with the | |
293 | optional description parameter see the examples. |
|
293 | optional description parameter see the examples. | |
294 |
|
294 | |||
295 | Parameters: |
|
295 | Parameters: | |
296 | ----------- |
|
296 | ----------- | |
297 | path : str |
|
297 | path : str | |
298 | Path where files will be saved. |
|
298 | Path where files will be saved. | |
299 | blocksPerFile : int |
|
299 | blocksPerFile : int | |
300 | Number of blocks per file |
|
300 | Number of blocks per file | |
301 | metadataList : list |
|
301 | metadataList : list | |
302 | List of the dataOut attributes that will be saved as metadata |
|
302 | List of the dataOut attributes that will be saved as metadata | |
303 | dataList : int |
|
303 | dataList : int | |
304 | List of the dataOut attributes that will be saved as data |
|
304 | List of the dataOut attributes that will be saved as data | |
305 | setType : bool |
|
305 | setType : bool | |
306 | If True the name of the files corresponds to the timestamp of the data |
|
306 | If True the name of the files corresponds to the timestamp of the data | |
307 | description : dict, optional |
|
307 | description : dict, optional | |
308 | Dictionary with the desired description of the HDF5 file |
|
308 | Dictionary with the desired description of the HDF5 file | |
309 |
|
309 | |||
310 | Examples |
|
310 | Examples | |
311 | -------- |
|
311 | -------- | |
312 |
|
312 | |||
313 | desc = { |
|
313 | desc = { | |
314 | 'data_output': {'winds': ['z', 'w', 'v']}, |
|
314 | 'data_output': {'winds': ['z', 'w', 'v']}, | |
315 | 'utctime': 'timestamps', |
|
315 | 'utctime': 'timestamps', | |
316 | 'heightList': 'heights' |
|
316 | 'heightList': 'heights' | |
317 | } |
|
317 | } | |
318 | desc = { |
|
318 | desc = { | |
319 | 'data_output': ['z', 'w', 'v'], |
|
319 | 'data_output': ['z', 'w', 'v'], | |
320 | 'utctime': 'timestamps', |
|
320 | 'utctime': 'timestamps', | |
321 | 'heightList': 'heights' |
|
321 | 'heightList': 'heights' | |
322 | } |
|
322 | } | |
323 | desc = { |
|
323 | desc = { | |
324 | 'Data': { |
|
324 | 'Data': { | |
325 | 'data_output': 'winds', |
|
325 | 'data_output': 'winds', | |
326 | 'utctime': 'timestamps' |
|
326 | 'utctime': 'timestamps' | |
327 | }, |
|
327 | }, | |
328 | 'Metadata': { |
|
328 | 'Metadata': { | |
329 | 'heightList': 'heights' |
|
329 | 'heightList': 'heights' | |
330 | } |
|
330 | } | |
331 | } |
|
331 | } | |
332 |
|
332 | |||
333 | writer = proc_unit.addOperation(name='HDFWriter') |
|
333 | writer = proc_unit.addOperation(name='HDFWriter') | |
334 | writer.addParameter(name='path', value='/path/to/file') |
|
334 | writer.addParameter(name='path', value='/path/to/file') | |
335 | writer.addParameter(name='blocksPerFile', value='32') |
|
335 | writer.addParameter(name='blocksPerFile', value='32') | |
336 | writer.addParameter(name='metadataList', value='heightList,timeZone') |
|
336 | writer.addParameter(name='metadataList', value='heightList,timeZone') | |
337 | writer.addParameter(name='dataList',value='data_output,utctime') |
|
337 | writer.addParameter(name='dataList',value='data_output,utctime') | |
338 | # writer.addParameter(name='description',value=json.dumps(desc)) |
|
338 | # writer.addParameter(name='description',value=json.dumps(desc)) | |
339 |
|
339 | |||
340 | """ |
|
340 | """ | |
341 |
|
341 | |||
342 | ext = ".hdf5" |
|
342 | ext = ".hdf5" | |
343 | optchar = "D" |
|
343 | optchar = "D" | |
344 | filename = None |
|
344 | filename = None | |
345 | path = None |
|
345 | path = None | |
346 | setFile = None |
|
346 | setFile = None | |
347 | fp = None |
|
347 | fp = None | |
348 | firsttime = True |
|
348 | firsttime = True | |
349 | #Configurations |
|
349 | #Configurations | |
350 | blocksPerFile = None |
|
350 | blocksPerFile = None | |
351 | blockIndex = None |
|
351 | blockIndex = None | |
352 | dataOut = None |
|
352 | dataOut = None | |
353 | #Data Arrays |
|
353 | #Data Arrays | |
354 | dataList = None |
|
354 | dataList = None | |
355 | metadataList = None |
|
355 | metadataList = None | |
356 | currentDay = None |
|
356 | currentDay = None | |
357 | lastTime = None |
|
357 | lastTime = None | |
358 |
|
358 | |||
359 | def __init__(self): |
|
359 | def __init__(self): | |
360 |
|
360 | |||
361 | Operation.__init__(self) |
|
361 | Operation.__init__(self) | |
362 | return |
|
362 | return | |
363 |
|
363 | |||
364 | def setup(self, path=None, blocksPerFile=10, metadataList=None, dataList=None, setType=None, description=None): |
|
364 | def setup(self, path=None, blocksPerFile=10, metadataList=None, dataList=None, setType=None, description=None): | |
365 | self.path = path |
|
365 | self.path = path | |
366 | self.blocksPerFile = blocksPerFile |
|
366 | self.blocksPerFile = blocksPerFile | |
367 | self.metadataList = metadataList |
|
367 | self.metadataList = metadataList | |
368 | self.dataList = [s.strip() for s in dataList] |
|
368 | self.dataList = [s.strip() for s in dataList] | |
369 | self.setType = setType |
|
369 | self.setType = setType | |
370 | self.description = description |
|
370 | self.description = description | |
371 |
|
371 | |||
372 | if self.metadataList is None: |
|
372 | if self.metadataList is None: | |
373 | self.metadataList = self.dataOut.metadata_list |
|
373 | self.metadataList = self.dataOut.metadata_list | |
374 |
|
374 | |||
375 | tableList = [] |
|
375 | tableList = [] | |
376 | dsList = [] |
|
376 | dsList = [] | |
377 |
|
377 | |||
378 | for i in range(len(self.dataList)): |
|
378 | for i in range(len(self.dataList)): | |
379 | dsDict = {} |
|
379 | dsDict = {} | |
380 | if hasattr(self.dataOut, self.dataList[i]): |
|
380 | if hasattr(self.dataOut, self.dataList[i]): | |
381 | dataAux = getattr(self.dataOut, self.dataList[i]) |
|
381 | dataAux = getattr(self.dataOut, self.dataList[i]) | |
382 | dsDict['variable'] = self.dataList[i] |
|
382 | dsDict['variable'] = self.dataList[i] | |
383 | else: |
|
383 | else: | |
384 | log.warning('Attribute {} not found in dataOut', self.name) |
|
384 | log.warning('Attribute {} not found in dataOut', self.name) | |
385 | continue |
|
385 | continue | |
386 |
|
386 | |||
387 | if dataAux is None: |
|
387 | if dataAux is None: | |
388 | continue |
|
388 | continue | |
389 | elif isinstance(dataAux, (int, float, numpy.integer, numpy.float)): |
|
389 | elif isinstance(dataAux, (int, float, numpy.integer, numpy.float)): | |
390 | dsDict['nDim'] = 0 |
|
390 | dsDict['nDim'] = 0 | |
391 | else: |
|
391 | else: | |
392 | dsDict['nDim'] = len(dataAux.shape) |
|
392 | dsDict['nDim'] = len(dataAux.shape) | |
393 | dsDict['shape'] = dataAux.shape |
|
393 | dsDict['shape'] = dataAux.shape | |
394 | dsDict['dsNumber'] = dataAux.shape[0] |
|
394 | dsDict['dsNumber'] = dataAux.shape[0] | |
395 | dsDict['dtype'] = dataAux.dtype |
|
395 | dsDict['dtype'] = dataAux.dtype | |
396 |
|
396 | |||
397 | dsList.append(dsDict) |
|
397 | dsList.append(dsDict) | |
398 |
|
398 | |||
399 | self.dsList = dsList |
|
399 | self.dsList = dsList | |
400 | self.currentDay = self.dataOut.datatime.date() |
|
400 | self.currentDay = self.dataOut.datatime.date() | |
401 |
|
401 | |||
402 | def timeFlag(self): |
|
402 | def timeFlag(self): | |
403 | currentTime = self.dataOut.utctime |
|
403 | currentTime = self.dataOut.utctime | |
404 | timeTuple = time.localtime(currentTime) |
|
404 | timeTuple = time.localtime(currentTime) | |
405 | dataDay = timeTuple.tm_yday |
|
405 | dataDay = timeTuple.tm_yday | |
406 |
|
406 | |||
407 | if self.lastTime is None: |
|
407 | if self.lastTime is None: | |
408 | self.lastTime = currentTime |
|
408 | self.lastTime = currentTime | |
409 | self.currentDay = dataDay |
|
409 | self.currentDay = dataDay | |
410 | return False |
|
410 | return False | |
411 |
|
411 | |||
412 | timeDiff = currentTime - self.lastTime |
|
412 | timeDiff = currentTime - self.lastTime | |
413 |
|
413 | |||
414 | #Si el dia es diferente o si la diferencia entre un dato y otro supera la hora |
|
414 | #Si el dia es diferente o si la diferencia entre un dato y otro supera la hora | |
415 | if dataDay != self.currentDay: |
|
415 | if dataDay != self.currentDay: | |
416 | self.currentDay = dataDay |
|
416 | self.currentDay = dataDay | |
417 | return True |
|
417 | return True | |
418 | elif timeDiff > 3*60*60: |
|
418 | elif timeDiff > 3*60*60: | |
419 | self.lastTime = currentTime |
|
419 | self.lastTime = currentTime | |
420 | return True |
|
420 | return True | |
421 | else: |
|
421 | else: | |
422 | self.lastTime = currentTime |
|
422 | self.lastTime = currentTime | |
423 | return False |
|
423 | return False | |
424 |
|
424 | |||
425 | def run(self, dataOut, path, blocksPerFile=10, metadataList=None, |
|
425 | def run(self, dataOut, path, blocksPerFile=10, metadataList=None, | |
426 | dataList=[], setType=None, description={}): |
|
426 | dataList=[], setType=None, description={}): | |
427 |
|
427 | |||
428 | self.dataOut = dataOut |
|
428 | self.dataOut = dataOut | |
429 | if not(self.isConfig): |
|
429 | if not(self.isConfig): | |
430 | self.setup(path=path, blocksPerFile=blocksPerFile, |
|
430 | self.setup(path=path, blocksPerFile=blocksPerFile, | |
431 | metadataList=metadataList, dataList=dataList, |
|
431 | metadataList=metadataList, dataList=dataList, | |
432 | setType=setType, description=description) |
|
432 | setType=setType, description=description) | |
433 |
|
433 | |||
434 | self.isConfig = True |
|
434 | self.isConfig = True | |
435 | self.setNextFile() |
|
435 | self.setNextFile() | |
436 |
|
436 | |||
437 | self.putData() |
|
437 | self.putData() | |
438 | return |
|
438 | return | |
439 |
|
439 | |||
440 | def setNextFile(self): |
|
440 | def setNextFile(self): | |
441 |
|
441 | |||
442 | ext = self.ext |
|
442 | ext = self.ext | |
443 | path = self.path |
|
443 | path = self.path | |
444 | setFile = self.setFile |
|
444 | setFile = self.setFile | |
445 |
|
445 | |||
446 | timeTuple = time.localtime(self.dataOut.utctime) |
|
446 | timeTuple = time.localtime(self.dataOut.utctime) | |
447 | subfolder = 'd%4.4d%3.3d' % (timeTuple.tm_year,timeTuple.tm_yday) |
|
447 | subfolder = 'd%4.4d%3.3d' % (timeTuple.tm_year,timeTuple.tm_yday) | |
448 | fullpath = os.path.join(path, subfolder) |
|
448 | fullpath = os.path.join(path, subfolder) | |
449 |
|
449 | |||
450 | if os.path.exists(fullpath): |
|
450 | if os.path.exists(fullpath): | |
451 | filesList = os.listdir(fullpath) |
|
451 | filesList = os.listdir(fullpath) | |
452 | filesList = [k for k in filesList if k.startswith(self.optchar)] |
|
452 | filesList = [k for k in filesList if k.startswith(self.optchar)] | |
453 | if len( filesList ) > 0: |
|
453 | if len( filesList ) > 0: | |
454 | filesList = sorted(filesList, key=str.lower) |
|
454 | filesList = sorted(filesList, key=str.lower) | |
455 | filen = filesList[-1] |
|
455 | filen = filesList[-1] | |
456 | # el filename debera tener el siguiente formato |
|
456 | # el filename debera tener el siguiente formato | |
457 | # 0 1234 567 89A BCDE (hex) |
|
457 | # 0 1234 567 89A BCDE (hex) | |
458 | # x YYYY DDD SSS .ext |
|
458 | # x YYYY DDD SSS .ext | |
459 | if isNumber(filen[8:11]): |
|
459 | if isNumber(filen[8:11]): | |
460 | setFile = int(filen[8:11]) #inicializo mi contador de seteo al seteo del ultimo file |
|
460 | setFile = int(filen[8:11]) #inicializo mi contador de seteo al seteo del ultimo file | |
461 | else: |
|
461 | else: | |
462 | setFile = -1 |
|
462 | setFile = -1 | |
463 | else: |
|
463 | else: | |
464 | setFile = -1 #inicializo mi contador de seteo |
|
464 | setFile = -1 #inicializo mi contador de seteo | |
465 | else: |
|
465 | else: | |
466 | os.makedirs(fullpath) |
|
466 | os.makedirs(fullpath) | |
467 | setFile = -1 #inicializo mi contador de seteo |
|
467 | setFile = -1 #inicializo mi contador de seteo | |
468 |
|
468 | |||
469 | if self.setType is None: |
|
469 | if self.setType is None: | |
470 | setFile += 1 |
|
470 | setFile += 1 | |
471 | file = '%s%4.4d%3.3d%03d%s' % (self.optchar, |
|
471 | file = '%s%4.4d%3.3d%03d%s' % (self.optchar, | |
472 | timeTuple.tm_year, |
|
472 | timeTuple.tm_year, | |
473 | timeTuple.tm_yday, |
|
473 | timeTuple.tm_yday, | |
474 | setFile, |
|
474 | setFile, | |
475 | ext ) |
|
475 | ext ) | |
476 | else: |
|
476 | else: | |
477 | setFile = timeTuple.tm_hour*60+timeTuple.tm_min |
|
477 | setFile = timeTuple.tm_hour*60+timeTuple.tm_min | |
478 | file = '%s%4.4d%3.3d%04d%s' % (self.optchar, |
|
478 | file = '%s%4.4d%3.3d%04d%s' % (self.optchar, | |
479 | timeTuple.tm_year, |
|
479 | timeTuple.tm_year, | |
480 | timeTuple.tm_yday, |
|
480 | timeTuple.tm_yday, | |
481 | setFile, |
|
481 | setFile, | |
482 | ext ) |
|
482 | ext ) | |
483 |
|
483 | |||
484 | self.filename = os.path.join( path, subfolder, file ) |
|
484 | self.filename = os.path.join( path, subfolder, file ) | |
485 |
|
485 | |||
486 | #Setting HDF5 File |
|
486 | #Setting HDF5 File | |
487 | self.fp = h5py.File(self.filename, 'w') |
|
487 | self.fp = h5py.File(self.filename, 'w') | |
488 | #write metadata |
|
488 | #write metadata | |
489 | self.writeMetadata(self.fp) |
|
489 | self.writeMetadata(self.fp) | |
490 | #Write data |
|
490 | #Write data | |
491 | self.writeData(self.fp) |
|
491 | self.writeData(self.fp) | |
492 |
|
492 | |||
493 | def getLabel(self, name, x=None): |
|
493 | def getLabel(self, name, x=None): | |
494 |
|
494 | |||
495 | if x is None: |
|
495 | if x is None: | |
496 | if 'Data' in self.description: |
|
496 | if 'Data' in self.description: | |
497 | data = self.description['Data'] |
|
497 | data = self.description['Data'] | |
498 | if 'Metadata' in self.description: |
|
498 | if 'Metadata' in self.description: | |
499 | data.update(self.description['Metadata']) |
|
499 | data.update(self.description['Metadata']) | |
500 | else: |
|
500 | else: | |
501 | data = self.description |
|
501 | data = self.description | |
502 | if name in data: |
|
502 | if name in data: | |
503 | if isinstance(data[name], str): |
|
503 | if isinstance(data[name], str): | |
504 | return data[name] |
|
504 | return data[name] | |
505 | elif isinstance(data[name], list): |
|
505 | elif isinstance(data[name], list): | |
506 | return None |
|
506 | return None | |
507 | elif isinstance(data[name], dict): |
|
507 | elif isinstance(data[name], dict): | |
508 | for key, value in data[name].items(): |
|
508 | for key, value in data[name].items(): | |
509 | return key |
|
509 | return key | |
510 | return name |
|
510 | return name | |
511 | else: |
|
511 | else: | |
512 | if 'Metadata' in self.description: |
|
512 | if 'Metadata' in self.description: | |
513 | meta = self.description['Metadata'] |
|
513 | meta = self.description['Metadata'] | |
514 | else: |
|
514 | else: | |
515 | meta = self.description |
|
515 | meta = self.description | |
516 | if name in meta: |
|
516 | if name in meta: | |
517 | if isinstance(meta[name], list): |
|
517 | if isinstance(meta[name], list): | |
518 | return meta[name][x] |
|
518 | return meta[name][x] | |
519 | elif isinstance(meta[name], dict): |
|
519 | elif isinstance(meta[name], dict): | |
520 | for key, value in meta[name].items(): |
|
520 | for key, value in meta[name].items(): | |
521 | return value[x] |
|
521 | return value[x] | |
522 | if 'cspc' in name: |
|
522 | if 'cspc' in name: | |
523 | return 'pair{:02d}'.format(x) |
|
523 | return 'pair{:02d}'.format(x) | |
524 | else: |
|
524 | else: | |
525 | return 'channel{:02d}'.format(x) |
|
525 | return 'channel{:02d}'.format(x) | |
526 |
|
526 | |||
527 | def writeMetadata(self, fp): |
|
527 | def writeMetadata(self, fp): | |
528 |
|
528 | |||
529 | if self.description: |
|
529 | if self.description: | |
530 | if 'Metadata' in self.description: |
|
530 | if 'Metadata' in self.description: | |
531 | grp = fp.create_group('Metadata') |
|
531 | grp = fp.create_group('Metadata') | |
532 | else: |
|
532 | else: | |
533 | grp = fp |
|
533 | grp = fp | |
534 | else: |
|
534 | else: | |
535 | grp = fp.create_group('Metadata') |
|
535 | grp = fp.create_group('Metadata') | |
536 |
|
536 | |||
537 | for i in range(len(self.metadataList)): |
|
537 | for i in range(len(self.metadataList)): | |
538 | if not hasattr(self.dataOut, self.metadataList[i]): |
|
538 | if not hasattr(self.dataOut, self.metadataList[i]): | |
539 | log.warning('Metadata: `{}` not found'.format(self.metadataList[i]), self.name) |
|
539 | log.warning('Metadata: `{}` not found'.format(self.metadataList[i]), self.name) | |
540 | continue |
|
540 | continue | |
541 | value = getattr(self.dataOut, self.metadataList[i]) |
|
541 | value = getattr(self.dataOut, self.metadataList[i]) | |
542 | if isinstance(value, bool): |
|
542 | if isinstance(value, bool): | |
543 | if value is True: |
|
543 | if value is True: | |
544 | value = 1 |
|
544 | value = 1 | |
545 | else: |
|
545 | else: | |
546 | value = 0 |
|
546 | value = 0 | |
547 | grp.create_dataset(self.getLabel(self.metadataList[i]), data=value) |
|
547 | grp.create_dataset(self.getLabel(self.metadataList[i]), data=value) | |
548 | return |
|
548 | return | |
549 |
|
549 | |||
550 | def writeData(self, fp): |
|
550 | def writeData(self, fp): | |
551 |
|
551 | |||
552 | if self.description: |
|
552 | if self.description: | |
553 | if 'Data' in self.description: |
|
553 | if 'Data' in self.description: | |
554 | grp = fp.create_group('Data') |
|
554 | grp = fp.create_group('Data') | |
555 | else: |
|
555 | else: | |
556 | grp = fp |
|
556 | grp = fp | |
557 | else: |
|
557 | else: | |
558 | grp = fp.create_group('Data') |
|
558 | grp = fp.create_group('Data') | |
559 |
|
559 | |||
560 | dtsets = [] |
|
560 | dtsets = [] | |
561 | data = [] |
|
561 | data = [] | |
562 |
|
562 | |||
563 | for dsInfo in self.dsList: |
|
563 | for dsInfo in self.dsList: | |
564 | if dsInfo['nDim'] == 0: |
|
564 | if dsInfo['nDim'] == 0: | |
565 | ds = grp.create_dataset( |
|
565 | ds = grp.create_dataset( | |
566 | self.getLabel(dsInfo['variable']), |
|
566 | self.getLabel(dsInfo['variable']), | |
567 | (self.blocksPerFile, ), |
|
567 | (self.blocksPerFile, ), | |
568 | chunks=True, |
|
568 | chunks=True, | |
569 | dtype=numpy.float64) |
|
569 | dtype=numpy.float64) | |
570 | dtsets.append(ds) |
|
570 | dtsets.append(ds) | |
571 | data.append((dsInfo['variable'], -1)) |
|
571 | data.append((dsInfo['variable'], -1)) | |
572 | else: |
|
572 | else: | |
573 | label = self.getLabel(dsInfo['variable']) |
|
573 | label = self.getLabel(dsInfo['variable']) | |
574 | if label is not None: |
|
574 | if label is not None: | |
575 | sgrp = grp.create_group(label) |
|
575 | sgrp = grp.create_group(label) | |
576 | else: |
|
576 | else: | |
577 | sgrp = grp |
|
577 | sgrp = grp | |
578 | for i in range(dsInfo['dsNumber']): |
|
578 | for i in range(dsInfo['dsNumber']): | |
579 | ds = sgrp.create_dataset( |
|
579 | ds = sgrp.create_dataset( | |
580 | self.getLabel(dsInfo['variable'], i), |
|
580 | self.getLabel(dsInfo['variable'], i), | |
581 | (self.blocksPerFile, ) + dsInfo['shape'][1:], |
|
581 | (self.blocksPerFile, ) + dsInfo['shape'][1:], | |
582 | chunks=True, |
|
582 | chunks=True, | |
583 | dtype=dsInfo['dtype']) |
|
583 | dtype=dsInfo['dtype']) | |
584 | dtsets.append(ds) |
|
584 | dtsets.append(ds) | |
585 | data.append((dsInfo['variable'], i)) |
|
585 | data.append((dsInfo['variable'], i)) | |
586 | fp.flush() |
|
586 | fp.flush() | |
587 |
|
587 | |||
588 | log.log('Creating file: {}'.format(fp.filename), self.name) |
|
588 | log.log('Creating file: {}'.format(fp.filename), self.name) | |
589 |
|
589 | |||
590 | self.ds = dtsets |
|
590 | self.ds = dtsets | |
591 | self.data = data |
|
591 | self.data = data | |
592 | self.firsttime = True |
|
592 | self.firsttime = True | |
593 | self.blockIndex = 0 |
|
593 | self.blockIndex = 0 | |
594 | return |
|
594 | return | |
595 |
|
595 | |||
596 | def putData(self): |
|
596 | def putData(self): | |
597 |
|
597 | |||
598 | if (self.blockIndex == self.blocksPerFile) or self.timeFlag(): |
|
598 | if (self.blockIndex == self.blocksPerFile) or self.timeFlag(): | |
599 | self.closeFile() |
|
599 | self.closeFile() | |
600 | self.setNextFile() |
|
600 | self.setNextFile() | |
601 |
|
601 | |||
602 | for i, ds in enumerate(self.ds): |
|
602 | for i, ds in enumerate(self.ds): | |
603 | attr, ch = self.data[i] |
|
603 | attr, ch = self.data[i] | |
604 | if ch == -1: |
|
604 | if ch == -1: | |
605 | ds[self.blockIndex] = getattr(self.dataOut, attr) |
|
605 | ds[self.blockIndex] = getattr(self.dataOut, attr) | |
606 | else: |
|
606 | else: | |
607 | ds[self.blockIndex] = getattr(self.dataOut, attr)[ch] |
|
607 | ds[self.blockIndex] = getattr(self.dataOut, attr)[ch] | |
608 |
|
608 | |||
609 | self.fp.flush() |
|
609 | self.fp.flush() | |
610 | self.blockIndex += 1 |
|
610 | self.blockIndex += 1 | |
611 | log.log('Block No. {}/{}'.format(self.blockIndex, self.blocksPerFile), self.name) |
|
611 | log.log('Block No. {}/{}'.format(self.blockIndex, self.blocksPerFile), self.name) | |
612 |
|
612 | |||
613 | return |
|
613 | return | |
614 |
|
614 | |||
615 | def closeFile(self): |
|
615 | def closeFile(self): | |
616 |
|
616 | |||
617 | if self.blockIndex != self.blocksPerFile: |
|
617 | if self.blockIndex != self.blocksPerFile: | |
618 | for ds in self.ds: |
|
618 | for ds in self.ds: | |
619 | ds.resize(self.blockIndex, axis=0) |
|
619 | ds.resize(self.blockIndex, axis=0) | |
620 |
|
620 | |||
621 |
self.fp |
|
621 | if self.fp: | |
622 |
self.fp. |
|
622 | self.fp.flush() | |
|
623 | self.fp.close() | |||
623 |
|
624 | |||
624 | def close(self): |
|
625 | def close(self): | |
625 |
|
626 | |||
626 | self.closeFile() |
|
627 | self.closeFile() |
@@ -1,343 +1,343 | |||||
1 | ''' |
|
1 | ''' | |
2 | Created on Set 10, 2017 |
|
2 | Created on Set 10, 2017 | |
3 |
|
3 | |||
4 | @author: Juan C. Espinoza |
|
4 | @author: Juan C. Espinoza | |
5 | ''' |
|
5 | ''' | |
6 |
|
6 | |||
7 |
|
7 | |||
8 | import os |
|
8 | import os | |
9 | import sys |
|
9 | import sys | |
10 | import time |
|
10 | import time | |
11 | import glob |
|
11 | import glob | |
12 | import datetime |
|
12 | import datetime | |
13 |
|
13 | |||
14 | import numpy |
|
14 | import numpy | |
15 |
|
15 | |||
16 | from schainpy.model.proc.jroproc_base import ProcessingUnit |
|
16 | from schainpy.model.proc.jroproc_base import ProcessingUnit | |
17 | from schainpy.model.data.jrodata import Parameters |
|
17 | from schainpy.model.data.jrodata import Parameters | |
18 | from schainpy.model.io.jroIO_base import JRODataReader, isNumber |
|
18 | from schainpy.model.io.jroIO_base import JRODataReader, isNumber | |
19 | from schainpy.utils import log |
|
19 | from schainpy.utils import log | |
20 |
|
20 | |||
21 | FILE_HEADER_STRUCTURE = numpy.dtype([ |
|
21 | FILE_HEADER_STRUCTURE = numpy.dtype([ | |
22 | ('year', 'f'), |
|
22 | ('year', 'f'), | |
23 | ('doy', 'f'), |
|
23 | ('doy', 'f'), | |
24 | ('nint', 'f'), |
|
24 | ('nint', 'f'), | |
25 | ('navg', 'f'), |
|
25 | ('navg', 'f'), | |
26 | ('fh', 'f'), |
|
26 | ('fh', 'f'), | |
27 | ('dh', 'f'), |
|
27 | ('dh', 'f'), | |
28 | ('nheights', 'f'), |
|
28 | ('nheights', 'f'), | |
29 | ('ipp', 'f') |
|
29 | ('ipp', 'f') | |
30 | ]) |
|
30 | ]) | |
31 |
|
31 | |||
32 | REC_HEADER_STRUCTURE = numpy.dtype([ |
|
32 | REC_HEADER_STRUCTURE = numpy.dtype([ | |
33 | ('magic', 'f'), |
|
33 | ('magic', 'f'), | |
34 | ('hours', 'f'), |
|
34 | ('hours', 'f'), | |
35 | ('interval', 'f'), |
|
35 | ('interval', 'f'), | |
36 | ('h0', 'f'), |
|
36 | ('h0', 'f'), | |
37 | ('nheights', 'f'), |
|
37 | ('nheights', 'f'), | |
38 | ('snr1', 'f'), |
|
38 | ('snr1', 'f'), | |
39 | ('snr2', 'f'), |
|
39 | ('snr2', 'f'), | |
40 | ('snr', 'f'), |
|
40 | ('snr', 'f'), | |
41 | ]) |
|
41 | ]) | |
42 |
|
42 | |||
43 | DATA_STRUCTURE = numpy.dtype([ |
|
43 | DATA_STRUCTURE = numpy.dtype([ | |
44 | ('range', '<u4'), |
|
44 | ('range', '<u4'), | |
45 | ('status', '<u4'), |
|
45 | ('status', '<u4'), | |
46 | ('zonal', '<f4'), |
|
46 | ('zonal', '<f4'), | |
47 | ('meridional', '<f4'), |
|
47 | ('meridional', '<f4'), | |
48 | ('vertical', '<f4'), |
|
48 | ('vertical', '<f4'), | |
49 | ('zonal_a', '<f4'), |
|
49 | ('zonal_a', '<f4'), | |
50 | ('meridional_a', '<f4'), |
|
50 | ('meridional_a', '<f4'), | |
51 | ('corrected_fading', '<f4'), # seconds |
|
51 | ('corrected_fading', '<f4'), # seconds | |
52 | ('uncorrected_fading', '<f4'), # seconds |
|
52 | ('uncorrected_fading', '<f4'), # seconds | |
53 | ('time_diff', '<f4'), |
|
53 | ('time_diff', '<f4'), | |
54 | ('major_axis', '<f4'), |
|
54 | ('major_axis', '<f4'), | |
55 | ('axial_ratio', '<f4'), |
|
55 | ('axial_ratio', '<f4'), | |
56 | ('orientation', '<f4'), |
|
56 | ('orientation', '<f4'), | |
57 | ('sea_power', '<u4'), |
|
57 | ('sea_power', '<u4'), | |
58 | ('sea_algorithm', '<u4') |
|
58 | ('sea_algorithm', '<u4') | |
59 | ]) |
|
59 | ]) | |
60 |
|
60 | |||
61 |
|
61 | |||
62 | class JULIAParamReader(JRODataReader, ProcessingUnit): |
|
62 | class JULIAParamReader(JRODataReader, ProcessingUnit): | |
63 | ''' |
|
63 | ''' | |
64 | Julia data (eej, spf, 150km) *.dat files |
|
64 | Julia data (eej, spf, 150km) *.dat files | |
65 | ''' |
|
65 | ''' | |
66 |
|
66 | |||
67 | ext = '.dat' |
|
67 | ext = '.dat' | |
68 |
|
68 | |||
69 | def __init__(self, **kwargs): |
|
69 | def __init__(self, **kwargs): | |
70 |
|
70 | |||
71 | ProcessingUnit.__init__(self, **kwargs) |
|
71 | ProcessingUnit.__init__(self, **kwargs) | |
72 |
|
72 | |||
73 | self.dataOut = Parameters() |
|
73 | self.dataOut = Parameters() | |
74 | self.counter_records = 0 |
|
74 | self.counter_records = 0 | |
75 | self.flagNoMoreFiles = 0 |
|
75 | self.flagNoMoreFiles = 0 | |
76 | self.isConfig = False |
|
76 | self.isConfig = False | |
77 | self.filename = None |
|
77 | self.filename = None | |
78 | self.clockpulse = 0.15 |
|
78 | self.clockpulse = 0.15 | |
79 | self.kd = 213.6 |
|
79 | self.kd = 213.6 | |
80 |
|
80 | |||
81 | def setup(self, |
|
81 | def setup(self, | |
82 | path=None, |
|
82 | path=None, | |
83 | startDate=None, |
|
83 | startDate=None, | |
84 | endDate=None, |
|
84 | endDate=None, | |
85 | ext=None, |
|
85 | ext=None, | |
86 | startTime=datetime.time(0, 0, 0), |
|
86 | startTime=datetime.time(0, 0, 0), | |
87 | endTime=datetime.time(23, 59, 59), |
|
87 | endTime=datetime.time(23, 59, 59), | |
88 | timezone=0, |
|
88 | timezone=0, | |
89 | format=None, |
|
89 | format=None, | |
90 | **kwargs): |
|
90 | **kwargs): | |
91 |
|
91 | |||
92 | self.path = path |
|
92 | self.path = path | |
93 | self.startDate = startDate |
|
93 | self.startDate = startDate | |
94 | self.endDate = endDate |
|
94 | self.endDate = endDate | |
95 | self.startTime = startTime |
|
95 | self.startTime = startTime | |
96 | self.endTime = endTime |
|
96 | self.endTime = endTime | |
97 | self.datatime = datetime.datetime(1900, 1, 1) |
|
97 | self.datatime = datetime.datetime(1900, 1, 1) | |
98 | self.format = format |
|
98 | self.format = format | |
99 |
|
99 | |||
100 | if self.path is None: |
|
100 | if self.path is None: | |
101 | raise ValueError("The path is not valid") |
|
101 | raise ValueError("The path is not valid") | |
102 |
|
102 | |||
103 | if ext is None: |
|
103 | if ext is None: | |
104 | ext = self.ext |
|
104 | ext = self.ext | |
105 |
|
105 | |||
106 | self.search_files(self.path, startDate, endDate, ext) |
|
106 | self.search_files(self.path, startDate, endDate, ext) | |
107 | self.timezone = timezone |
|
107 | self.timezone = timezone | |
108 | self.fileIndex = 0 |
|
108 | self.fileIndex = 0 | |
109 |
|
109 | |||
110 | if not self.fileList: |
|
110 | if not self.fileList: | |
111 | log.warning('There is no files matching these date in the folder: {}'.format( |
|
111 | log.warning('There is no files matching these date in the folder: {}'.format( | |
112 | path), self.name) |
|
112 | path), self.name) | |
113 |
|
113 | |||
114 | self.setNextFile() |
|
114 | self.setNextFile() | |
115 |
|
115 | |||
116 | def search_files(self, path, startDate, endDate, ext): |
|
116 | def search_files(self, path, startDate, endDate, ext): | |
117 | ''' |
|
117 | ''' | |
118 | Searching for BLTR rawdata file in path |
|
118 | Searching for BLTR rawdata file in path | |
119 | Creating a list of file to proces included in [startDate,endDate] |
|
119 | Creating a list of file to proces included in [startDate,endDate] | |
120 |
|
120 | |||
121 | Input: |
|
121 | Input: | |
122 | path - Path to find BLTR rawdata files |
|
122 | path - Path to find BLTR rawdata files | |
123 | startDate - Select file from this date |
|
123 | startDate - Select file from this date | |
124 | enDate - Select file until this date |
|
124 | enDate - Select file until this date | |
125 | ext - Extension of the file to read |
|
125 | ext - Extension of the file to read | |
126 | ''' |
|
126 | ''' | |
127 |
|
127 | |||
128 | log.success('Searching files in {} '.format(path), self.name) |
|
128 | log.success('Searching files in {} '.format(path), self.name) | |
129 | fileList0 = glob.glob1(path, '{}*{}'.format(self.format.upper(), ext)) |
|
129 | fileList0 = glob.glob1(path, '{}*{}'.format(self.format.upper(), ext)) | |
130 | fileList0.sort() |
|
130 | fileList0.sort() | |
131 |
|
131 | |||
132 | self.fileList = [] |
|
132 | self.fileList = [] | |
133 | self.dateFileList = [] |
|
133 | self.dateFileList = [] | |
134 |
|
134 | |||
135 | for thisFile in fileList0: |
|
135 | for thisFile in fileList0: | |
136 | year = thisFile[2:4] |
|
136 | year = thisFile[2:4] | |
137 | if not isNumber(year): |
|
137 | if not isNumber(year): | |
138 | continue |
|
138 | continue | |
139 |
|
139 | |||
140 | month = thisFile[4:6] |
|
140 | month = thisFile[4:6] | |
141 | if not isNumber(month): |
|
141 | if not isNumber(month): | |
142 | continue |
|
142 | continue | |
143 |
|
143 | |||
144 | day = thisFile[6:8] |
|
144 | day = thisFile[6:8] | |
145 | if not isNumber(day): |
|
145 | if not isNumber(day): | |
146 | continue |
|
146 | continue | |
147 |
|
147 | |||
148 | year, month, day = int(year), int(month), int(day) |
|
148 | year, month, day = int(year), int(month), int(day) | |
149 | dateFile = datetime.date(year+2000, month, day) |
|
149 | dateFile = datetime.date(year+2000, month, day) | |
150 |
|
150 | |||
151 | if (startDate > dateFile) or (endDate < dateFile): |
|
151 | if (startDate > dateFile) or (endDate < dateFile): | |
152 | continue |
|
152 | continue | |
153 |
|
153 | |||
154 | self.fileList.append(thisFile) |
|
154 | self.fileList.append(thisFile) | |
155 | self.dateFileList.append(dateFile) |
|
155 | self.dateFileList.append(dateFile) | |
156 |
|
156 | |||
157 | return |
|
157 | return | |
158 |
|
158 | |||
159 | def setNextFile(self): |
|
159 | def setNextFile(self): | |
160 |
|
160 | |||
161 | file_id = self.fileIndex |
|
161 | file_id = self.fileIndex | |
162 |
|
162 | |||
163 | if file_id == len(self.fileList): |
|
163 | if file_id == len(self.fileList): | |
164 | log.success('No more files in the folder', self.name) |
|
164 | log.success('No more files in the folder', self.name) | |
165 | self.flagNoMoreFiles = 1 |
|
165 | self.flagNoMoreFiles = 1 | |
166 | return 0 |
|
166 | return 0 | |
167 |
|
167 | |||
168 | log.success('Opening {}'.format(self.fileList[file_id]), self.name) |
|
168 | log.success('Opening {}'.format(self.fileList[file_id]), self.name) | |
169 | filename = os.path.join(self.path, self.fileList[file_id]) |
|
169 | filename = os.path.join(self.path, self.fileList[file_id]) | |
170 |
|
170 | |||
171 | dirname, name = os.path.split(filename) |
|
171 | dirname, name = os.path.split(filename) | |
172 | self.siteFile = name.split('.')[0] |
|
172 | self.siteFile = name.split('.')[0] | |
173 | if self.filename is not None: |
|
173 | if self.filename is not None: | |
174 | self.fp.close() |
|
174 | self.fp.close() | |
175 | self.filename = filename |
|
175 | self.filename = filename | |
176 | self.fp = open(self.filename, 'rb') |
|
176 | self.fp = open(self.filename, 'rb') | |
177 |
|
177 | |||
178 | self.header_file = numpy.fromfile(self.fp, FILE_HEADER_STRUCTURE, 1) |
|
178 | self.header_file = numpy.fromfile(self.fp, FILE_HEADER_STRUCTURE, 1) | |
179 | yy = self.header_file['year'] - 1900 * (self.header_file['year'] > 3000) |
|
179 | yy = self.header_file['year'] - 1900 * (self.header_file['year'] > 3000) | |
180 | self.year = int(yy + 1900 * (yy < 1000)) |
|
180 | self.year = int(yy + 1900 * (yy < 1000)) | |
181 | self.doy = int(self.header_file['doy']) |
|
181 | self.doy = int(self.header_file['doy']) | |
182 | self.dH = round(self.header_file['dh'], 2) |
|
182 | self.dH = round(self.header_file['dh'], 2) | |
183 | self.ipp = round(self.header_file['ipp'], 2) |
|
183 | self.ipp = round(self.header_file['ipp'], 2) | |
184 | self.sizeOfFile = os.path.getsize(self.filename) |
|
184 | self.sizeOfFile = os.path.getsize(self.filename) | |
185 | self.counter_records = 0 |
|
185 | self.counter_records = 0 | |
186 | self.flagIsNewFile = 0 |
|
186 | self.flagIsNewFile = 0 | |
187 | self.fileIndex += 1 |
|
187 | self.fileIndex += 1 | |
188 |
|
188 | |||
189 | return 1 |
|
189 | return 1 | |
190 |
|
190 | |||
191 | def readNextBlock(self): |
|
191 | def readNextBlock(self): | |
192 |
|
192 | |||
193 | while True: |
|
193 | while True: | |
194 | if not self.readBlock(): |
|
194 | if not self.readBlock(): | |
195 | self.flagIsNewFile = 1 |
|
195 | self.flagIsNewFile = 1 | |
196 | if not self.setNextFile(): |
|
196 | if not self.setNextFile(): | |
197 | return 0 |
|
197 | return 0 | |
198 |
|
198 | |||
199 | if (self.datatime < datetime.datetime.combine(self.startDate, self.startTime)) or \ |
|
199 | if (self.datatime < datetime.datetime.combine(self.startDate, self.startTime)) or \ | |
200 | (self.datatime > datetime.datetime.combine(self.endDate, self.endTime)): |
|
200 | (self.datatime > datetime.datetime.combine(self.endDate, self.endTime)): | |
201 | log.warning( |
|
201 | log.warning( | |
202 | 'Reading Record No. {} -> {} [Skipping]'.format( |
|
202 | 'Reading Record No. {} -> {} [Skipping]'.format( | |
203 | self.counter_records, |
|
203 | self.counter_records, | |
204 | self.datatime.ctime()), |
|
204 | self.datatime.ctime()), | |
205 | self.name) |
|
205 | self.name) | |
206 | continue |
|
206 | continue | |
207 | break |
|
207 | break | |
208 |
|
208 | |||
209 | log.log('Reading Record No. {} -> {}'.format( |
|
209 | log.log('Reading Record No. {} -> {}'.format( | |
210 | self.counter_records, |
|
210 | self.counter_records, | |
211 | self.datatime.ctime()), self.name) |
|
211 | self.datatime.ctime()), self.name) | |
212 |
|
212 | |||
213 | return 1 |
|
213 | return 1 | |
214 |
|
214 | |||
215 | def readBlock(self): |
|
215 | def readBlock(self): | |
216 |
|
216 | |||
217 | pointer = self.fp.tell() |
|
217 | pointer = self.fp.tell() | |
218 | heights, dt = self.readHeader() |
|
218 | heights, dt = self.readHeader() | |
219 | self.fp.seek(pointer) |
|
219 | self.fp.seek(pointer) | |
220 | buffer_h = [] |
|
220 | buffer_h = [] | |
221 | buffer_d = [] |
|
221 | buffer_d = [] | |
222 | while True: |
|
222 | while True: | |
223 | pointer = self.fp.tell() |
|
223 | pointer = self.fp.tell() | |
224 | if pointer == self.sizeOfFile: |
|
224 | if pointer == self.sizeOfFile: | |
225 | return 0 |
|
225 | return 0 | |
226 | heights, datatime = self.readHeader() |
|
226 | heights, datatime = self.readHeader() | |
227 | if dt == datatime: |
|
227 | if dt == datatime: | |
228 | buffer_h.append(heights) |
|
228 | buffer_h.append(heights) | |
229 | buffer_d.append(self.readData(len(heights))) |
|
229 | buffer_d.append(self.readData(len(heights))) | |
230 | continue |
|
230 | continue | |
231 | self.fp.seek(pointer) |
|
231 | self.fp.seek(pointer) | |
232 | break |
|
232 | break | |
233 |
|
233 | |||
234 | if dt.date() > self.datatime.date(): |
|
234 | if dt.date() > self.datatime.date(): | |
235 | self.flagDiscontinuousBlock = 1 |
|
235 | self.flagDiscontinuousBlock = 1 | |
236 | self.datatime = dt |
|
236 | self.datatime = dt | |
237 | self.time = (dt - datetime.datetime(1970, 1, 1)).total_seconds() + time.timezone |
|
237 | self.time = (dt - datetime.datetime(1970, 1, 1)).total_seconds() + time.timezone | |
238 | self.heights = numpy.concatenate(buffer_h) |
|
238 | self.heights = numpy.concatenate(buffer_h) | |
239 | self.buffer = numpy.zeros((5, len(self.heights))) + numpy.nan |
|
239 | self.buffer = numpy.zeros((5, len(self.heights))) + numpy.nan | |
240 | self.buffer[0, :] = numpy.concatenate([buf[0] for buf in buffer_d]) |
|
240 | self.buffer[0, :] = numpy.concatenate([buf[0] for buf in buffer_d]) | |
241 | self.buffer[1, :] = numpy.concatenate([buf[1] for buf in buffer_d]) |
|
241 | self.buffer[1, :] = numpy.concatenate([buf[1] for buf in buffer_d]) | |
242 | self.buffer[2, :] = numpy.concatenate([buf[2] for buf in buffer_d]) |
|
242 | self.buffer[2, :] = numpy.concatenate([buf[2] for buf in buffer_d]) | |
243 | self.buffer[3, :] = numpy.concatenate([buf[3] for buf in buffer_d]) |
|
243 | self.buffer[3, :] = numpy.concatenate([buf[3] for buf in buffer_d]) | |
244 | self.buffer[4, :] = numpy.concatenate([buf[4] for buf in buffer_d]) |
|
244 | self.buffer[4, :] = numpy.concatenate([buf[4] for buf in buffer_d]) | |
245 |
|
245 | |||
246 | self.counter_records += 1 |
|
246 | self.counter_records += 1 | |
247 |
|
247 | |||
248 | return 1 |
|
248 | return 1 | |
249 |
|
249 | |||
250 | def readHeader(self): |
|
250 | def readHeader(self): | |
251 | ''' |
|
251 | ''' | |
252 | Parse recordHeader |
|
252 | Parse recordHeader | |
253 | ''' |
|
253 | ''' | |
254 |
|
254 | |||
255 | self.header_rec = numpy.fromfile(self.fp, REC_HEADER_STRUCTURE, 1) |
|
255 | self.header_rec = numpy.fromfile(self.fp, REC_HEADER_STRUCTURE, 1) | |
256 | self.interval = self.header_rec['interval'] |
|
256 | self.interval = self.header_rec['interval'] | |
257 | if self.header_rec['magic'] == 888.: |
|
257 | if self.header_rec['magic'] == 888.: | |
258 | self.header_rec['h0'] = round(self.header_rec['h0'], 2) |
|
258 | self.header_rec['h0'] = round(self.header_rec['h0'], 2) | |
259 | nheights = int(self.header_rec['nheights']) |
|
259 | nheights = int(self.header_rec['nheights']) | |
260 | hours = float(self.header_rec['hours'][0]) |
|
260 | hours = float(self.header_rec['hours'][0]) | |
261 | heights = numpy.arange(nheights) * self.dH + self.header_rec['h0'] |
|
261 | heights = numpy.arange(nheights) * self.dH + self.header_rec['h0'] | |
262 | datatime = datetime.datetime(self.year, 1, 1) + datetime.timedelta(days=self.doy-1, hours=hours) |
|
262 | datatime = datetime.datetime(self.year, 1, 1) + datetime.timedelta(days=self.doy-1, hours=hours) | |
263 | return heights, datatime |
|
263 | return heights, datatime | |
264 | else: |
|
264 | else: | |
265 | return False |
|
265 | return False | |
266 |
|
266 | |||
267 | def readData(self, N): |
|
267 | def readData(self, N): | |
268 | ''' |
|
268 | ''' | |
269 | Parse data |
|
269 | Parse data | |
270 | ''' |
|
270 | ''' | |
271 |
|
271 | |||
272 | buffer = numpy.fromfile(self.fp, 'f', 8*N).reshape(N, 8) |
|
272 | buffer = numpy.fromfile(self.fp, 'f', 8*N).reshape(N, 8) | |
273 |
|
273 | |||
274 | pow0 = buffer[:, 0] |
|
274 | pow0 = buffer[:, 0] | |
275 | pow1 = buffer[:, 1] |
|
275 | pow1 = buffer[:, 1] | |
276 | acf0 = (buffer[:,2] + buffer[:,3]*1j) / pow0 |
|
276 | acf0 = (buffer[:,2] + buffer[:,3]*1j) / pow0 | |
277 | acf1 = (buffer[:,4] + buffer[:,5]*1j) / pow1 |
|
277 | acf1 = (buffer[:,4] + buffer[:,5]*1j) / pow1 | |
278 | dccf = (buffer[:,6] + buffer[:,7]*1j) / (pow0*pow1) |
|
278 | dccf = (buffer[:,6] + buffer[:,7]*1j) / (pow0*pow1) | |
279 |
|
279 | |||
280 | ### SNR |
|
280 | ### SNR | |
281 | sno = (pow0 + pow1 - self.header_rec['snr']) / self.header_rec['snr'] |
|
281 | sno = (pow0 + pow1 - self.header_rec['snr']) / self.header_rec['snr'] | |
282 | sno10 = numpy.log10(sno) |
|
282 | sno10 = numpy.log10(sno) | |
283 | # dsno = 1.0 / numpy.sqrt(self.header_file['nint'] * self.header_file['navg']) * (1 + (1 / sno)) |
|
283 | # dsno = 1.0 / numpy.sqrt(self.header_file['nint'] * self.header_file['navg']) * (1 + (1 / sno)) | |
284 |
|
284 | |||
285 | ### Vertical Drift |
|
285 | ### Vertical Drift | |
286 | sp = numpy.sqrt(numpy.abs(acf0)*numpy.abs(acf1)) |
|
286 | sp = numpy.sqrt(numpy.abs(acf0)*numpy.abs(acf1)) | |
287 | sp[numpy.where(numpy.abs(sp) >= 1.0)] = numpy.sqrt(0.9999) |
|
287 | sp[numpy.where(numpy.abs(sp) >= 1.0)] = numpy.sqrt(0.9999) | |
288 |
|
288 | |||
289 | vzo = -numpy.arctan2(acf0.imag + acf1.imag,acf0.real + acf1.real)*1.5E5*1.5/(self.ipp*numpy.pi) |
|
289 | vzo = -numpy.arctan2(acf0.imag + acf1.imag,acf0.real + acf1.real)*1.5E5*1.5/(self.ipp*numpy.pi) | |
290 | dvzo = numpy.sqrt(1.0 - sp*sp)*0.338*1.5E5/(numpy.sqrt(self.header_file['nint']*self.header_file['navg'])*sp*self.ipp) |
|
290 | dvzo = numpy.sqrt(1.0 - sp*sp)*0.338*1.5E5/(numpy.sqrt(self.header_file['nint']*self.header_file['navg'])*sp*self.ipp) | |
291 | err = numpy.where(dvzo <= 0.1) |
|
291 | err = numpy.where(dvzo <= 0.1) | |
292 | dvzo[err] = 0.1 |
|
292 | dvzo[err] = 0.1 | |
293 |
|
293 | |||
294 | #Zonal Drifts |
|
294 | #Zonal Drifts | |
295 | dt = self.header_file['nint']*self.ipp / 1.5E5 |
|
295 | dt = self.header_file['nint']*self.ipp / 1.5E5 | |
296 | coh = numpy.sqrt(numpy.abs(dccf)) |
|
296 | coh = numpy.sqrt(numpy.abs(dccf)) | |
297 | err = numpy.where(coh >= 1.0) |
|
297 | err = numpy.where(coh >= 1.0) | |
298 | coh[err] = numpy.sqrt(0.99999) |
|
298 | coh[err] = numpy.sqrt(0.99999) | |
299 |
|
299 | |||
300 | err = numpy.where(coh <= 0.1) |
|
300 | err = numpy.where(coh <= 0.1) | |
301 | coh[err] = numpy.sqrt(0.1) |
|
301 | coh[err] = numpy.sqrt(0.1) | |
302 |
|
302 | |||
303 | vxo = numpy.arctan2(dccf.imag, dccf.real)*self.header_rec['h0']*1.0E3/(self.kd*dt) |
|
303 | vxo = numpy.arctan2(dccf.imag, dccf.real)*self.header_rec['h0']*1.0E3/(self.kd*dt) | |
304 | dvxo = numpy.sqrt(1.0 - coh*coh)*self.header_rec['h0']*1.0E3/(numpy.sqrt(self.header_file['nint']*self.header_file['navg'])*coh*self.kd*dt) |
|
304 | dvxo = numpy.sqrt(1.0 - coh*coh)*self.header_rec['h0']*1.0E3/(numpy.sqrt(self.header_file['nint']*self.header_file['navg'])*coh*self.kd*dt) | |
305 |
|
305 | |||
306 | err = numpy.where(dvxo <= 0.1) |
|
306 | err = numpy.where(dvxo <= 0.1) | |
307 | dvxo[err] = 0.1 |
|
307 | dvxo[err] = 0.1 | |
308 |
|
308 | |||
309 | return vzo, dvzo, vxo, dvxo, sno10 |
|
309 | return vzo, dvzo, vxo, dvxo, sno10 | |
310 |
|
310 | |||
311 | def set_output(self): |
|
311 | def set_output(self): | |
312 | ''' |
|
312 | ''' | |
313 | Storing data from databuffer to dataOut object |
|
313 | Storing data from databuffer to dataOut object | |
314 | ''' |
|
314 | ''' | |
315 |
|
315 | |||
316 |
self.dataOut.data_ |
|
316 | self.dataOut.data_snr = self.buffer[4].reshape(1, -1) | |
317 | self.dataOut.heightList = self.heights |
|
317 | self.dataOut.heightList = self.heights | |
318 | self.dataOut.data_param = self.buffer[0:4,] |
|
318 | self.dataOut.data_param = self.buffer[0:4,] | |
319 | self.dataOut.utctimeInit = self.time |
|
319 | self.dataOut.utctimeInit = self.time | |
320 | self.dataOut.utctime = self.time |
|
320 | self.dataOut.utctime = self.time | |
321 | self.dataOut.useLocalTime = True |
|
321 | self.dataOut.useLocalTime = True | |
322 | self.dataOut.paramInterval = self.interval |
|
322 | self.dataOut.paramInterval = self.interval | |
323 | self.dataOut.timezone = self.timezone |
|
323 | self.dataOut.timezone = self.timezone | |
324 | self.dataOut.sizeOfFile = self.sizeOfFile |
|
324 | self.dataOut.sizeOfFile = self.sizeOfFile | |
325 | self.dataOut.flagNoData = False |
|
325 | self.dataOut.flagNoData = False | |
326 | self.dataOut.flagDiscontinuousBlock = self.flagDiscontinuousBlock |
|
326 | self.dataOut.flagDiscontinuousBlock = self.flagDiscontinuousBlock | |
327 |
|
327 | |||
328 | def getData(self): |
|
328 | def getData(self): | |
329 | ''' |
|
329 | ''' | |
330 | Storing data from databuffer to dataOut object |
|
330 | Storing data from databuffer to dataOut object | |
331 | ''' |
|
331 | ''' | |
332 | if self.flagNoMoreFiles: |
|
332 | if self.flagNoMoreFiles: | |
333 | self.dataOut.flagNoData = True |
|
333 | self.dataOut.flagNoData = True | |
334 | log.success('No file left to process', self.name) |
|
334 | log.success('No file left to process', self.name) | |
335 | return 0 |
|
335 | return 0 | |
336 |
|
336 | |||
337 | if not self.readNextBlock(): |
|
337 | if not self.readNextBlock(): | |
338 | self.dataOut.flagNoData = True |
|
338 | self.dataOut.flagNoData = True | |
339 | return 0 |
|
339 | return 0 | |
340 |
|
340 | |||
341 | self.set_output() |
|
341 | self.set_output() | |
342 |
|
342 | |||
343 | return 1 No newline at end of file |
|
343 | return 1 |
@@ -1,402 +1,402 | |||||
1 | ''' |
|
1 | ''' | |
2 | Created on Oct 24, 2016 |
|
2 | Created on Oct 24, 2016 | |
3 |
|
3 | |||
4 | @author: roj- LouVD |
|
4 | @author: roj- LouVD | |
5 | ''' |
|
5 | ''' | |
6 |
|
6 | |||
7 | import numpy |
|
7 | import numpy | |
8 | import copy |
|
8 | import copy | |
9 | import datetime |
|
9 | import datetime | |
10 | import time |
|
10 | import time | |
11 | from time import gmtime |
|
11 | from time import gmtime | |
12 |
|
12 | |||
13 | from numpy import transpose |
|
13 | from numpy import transpose | |
14 |
|
14 | |||
15 | from schainpy.model.proc.jroproc_base import ProcessingUnit, Operation, MPDecorator |
|
15 | from schainpy.model.proc.jroproc_base import ProcessingUnit, Operation, MPDecorator | |
16 | from schainpy.model.data.jrodata import Parameters |
|
16 | from schainpy.model.data.jrodata import Parameters | |
17 |
|
17 | |||
18 |
|
18 | |||
19 | class BLTRParametersProc(ProcessingUnit): |
|
19 | class BLTRParametersProc(ProcessingUnit): | |
20 | ''' |
|
20 | ''' | |
21 | Processing unit for BLTR parameters data (winds) |
|
21 | Processing unit for BLTR parameters data (winds) | |
22 |
|
22 | |||
23 | Inputs: |
|
23 | Inputs: | |
24 | self.dataOut.nmodes - Number of operation modes |
|
24 | self.dataOut.nmodes - Number of operation modes | |
25 | self.dataOut.nchannels - Number of channels |
|
25 | self.dataOut.nchannels - Number of channels | |
26 | self.dataOut.nranges - Number of ranges |
|
26 | self.dataOut.nranges - Number of ranges | |
27 |
|
27 | |||
28 |
self.dataOut.data_ |
|
28 | self.dataOut.data_snr - SNR array | |
29 | self.dataOut.data_output - Zonal, Vertical and Meridional velocity array |
|
29 | self.dataOut.data_output - Zonal, Vertical and Meridional velocity array | |
30 | self.dataOut.height - Height array (km) |
|
30 | self.dataOut.height - Height array (km) | |
31 | self.dataOut.time - Time array (seconds) |
|
31 | self.dataOut.time - Time array (seconds) | |
32 |
|
32 | |||
33 | self.dataOut.fileIndex -Index of the file currently read |
|
33 | self.dataOut.fileIndex -Index of the file currently read | |
34 | self.dataOut.lat - Latitude coordinate of BLTR location |
|
34 | self.dataOut.lat - Latitude coordinate of BLTR location | |
35 |
|
35 | |||
36 | self.dataOut.doy - Experiment doy (number of the day in the current year) |
|
36 | self.dataOut.doy - Experiment doy (number of the day in the current year) | |
37 | self.dataOut.month - Experiment month |
|
37 | self.dataOut.month - Experiment month | |
38 | self.dataOut.day - Experiment day |
|
38 | self.dataOut.day - Experiment day | |
39 | self.dataOut.year - Experiment year |
|
39 | self.dataOut.year - Experiment year | |
40 | ''' |
|
40 | ''' | |
41 |
|
41 | |||
42 | def __init__(self): |
|
42 | def __init__(self): | |
43 | ''' |
|
43 | ''' | |
44 | Inputs: None |
|
44 | Inputs: None | |
45 | ''' |
|
45 | ''' | |
46 | ProcessingUnit.__init__(self) |
|
46 | ProcessingUnit.__init__(self) | |
47 | self.dataOut = Parameters() |
|
47 | self.dataOut = Parameters() | |
48 |
|
48 | |||
49 | def setup(self, mode): |
|
49 | def setup(self, mode): | |
50 | ''' |
|
50 | ''' | |
51 | ''' |
|
51 | ''' | |
52 | self.dataOut.mode = mode |
|
52 | self.dataOut.mode = mode | |
53 |
|
53 | |||
54 | def run(self, mode, snr_threshold=None): |
|
54 | def run(self, mode, snr_threshold=None): | |
55 | ''' |
|
55 | ''' | |
56 | Inputs: |
|
56 | Inputs: | |
57 | mode = High resolution (0) or Low resolution (1) data |
|
57 | mode = High resolution (0) or Low resolution (1) data | |
58 | snr_threshold = snr filter value |
|
58 | snr_threshold = snr filter value | |
59 | ''' |
|
59 | ''' | |
60 |
|
60 | |||
61 | if not self.isConfig: |
|
61 | if not self.isConfig: | |
62 | self.setup(mode) |
|
62 | self.setup(mode) | |
63 | self.isConfig = True |
|
63 | self.isConfig = True | |
64 |
|
64 | |||
65 | if self.dataIn.type == 'Parameters': |
|
65 | if self.dataIn.type == 'Parameters': | |
66 | self.dataOut.copy(self.dataIn) |
|
66 | self.dataOut.copy(self.dataIn) | |
67 |
|
67 | |||
68 | self.dataOut.data_param = self.dataOut.data[mode] |
|
68 | self.dataOut.data_param = self.dataOut.data[mode] | |
69 | self.dataOut.heightList = self.dataOut.height[0] |
|
69 | self.dataOut.heightList = self.dataOut.height[0] | |
70 |
self.dataOut.data_ |
|
70 | self.dataOut.data_snr = self.dataOut.data_snr[mode] | |
71 |
|
71 | |||
72 | if snr_threshold is not None: |
|
72 | if snr_threshold is not None: | |
73 |
SNRavg = numpy.average(self.dataOut.data_ |
|
73 | SNRavg = numpy.average(self.dataOut.data_snr, axis=0) | |
74 | SNRavgdB = 10*numpy.log10(SNRavg) |
|
74 | SNRavgdB = 10*numpy.log10(SNRavg) | |
75 | for i in range(3): |
|
75 | for i in range(3): | |
76 | self.dataOut.data_param[i][SNRavgdB <= snr_threshold] = numpy.nan |
|
76 | self.dataOut.data_param[i][SNRavgdB <= snr_threshold] = numpy.nan | |
77 |
|
77 | |||
78 | # TODO |
|
78 | # TODO | |
79 |
|
79 | |||
80 | class OutliersFilter(Operation): |
|
80 | class OutliersFilter(Operation): | |
81 |
|
81 | |||
82 | def __init__(self): |
|
82 | def __init__(self): | |
83 | ''' |
|
83 | ''' | |
84 | ''' |
|
84 | ''' | |
85 | Operation.__init__(self) |
|
85 | Operation.__init__(self) | |
86 |
|
86 | |||
87 | def run(self, svalue2, method, factor, filter, npoints=9): |
|
87 | def run(self, svalue2, method, factor, filter, npoints=9): | |
88 | ''' |
|
88 | ''' | |
89 | Inputs: |
|
89 | Inputs: | |
90 | svalue - string to select array velocity |
|
90 | svalue - string to select array velocity | |
91 | svalue2 - string to choose axis filtering |
|
91 | svalue2 - string to choose axis filtering | |
92 | method - 0 for SMOOTH or 1 for MEDIAN |
|
92 | method - 0 for SMOOTH or 1 for MEDIAN | |
93 | factor - number used to set threshold |
|
93 | factor - number used to set threshold | |
94 | filter - 1 for data filtering using the standard deviation criteria else 0 |
|
94 | filter - 1 for data filtering using the standard deviation criteria else 0 | |
95 | npoints - number of points for mask filter |
|
95 | npoints - number of points for mask filter | |
96 | ''' |
|
96 | ''' | |
97 |
|
97 | |||
98 | print(' Outliers Filter {} {} / threshold = {}'.format(svalue, svalue, factor)) |
|
98 | print(' Outliers Filter {} {} / threshold = {}'.format(svalue, svalue, factor)) | |
99 |
|
99 | |||
100 |
|
100 | |||
101 | yaxis = self.dataOut.heightList |
|
101 | yaxis = self.dataOut.heightList | |
102 | xaxis = numpy.array([[self.dataOut.utctime]]) |
|
102 | xaxis = numpy.array([[self.dataOut.utctime]]) | |
103 |
|
103 | |||
104 | # Zonal |
|
104 | # Zonal | |
105 | value_temp = self.dataOut.data_output[0] |
|
105 | value_temp = self.dataOut.data_output[0] | |
106 |
|
106 | |||
107 | # Zonal |
|
107 | # Zonal | |
108 | value_temp = self.dataOut.data_output[1] |
|
108 | value_temp = self.dataOut.data_output[1] | |
109 |
|
109 | |||
110 | # Vertical |
|
110 | # Vertical | |
111 | value_temp = numpy.transpose(self.dataOut.data_output[2]) |
|
111 | value_temp = numpy.transpose(self.dataOut.data_output[2]) | |
112 |
|
112 | |||
113 | htemp = yaxis |
|
113 | htemp = yaxis | |
114 | std = value_temp |
|
114 | std = value_temp | |
115 | for h in range(len(htemp)): |
|
115 | for h in range(len(htemp)): | |
116 | nvalues_valid = len(numpy.where(numpy.isfinite(value_temp[h]))[0]) |
|
116 | nvalues_valid = len(numpy.where(numpy.isfinite(value_temp[h]))[0]) | |
117 | minvalid = npoints |
|
117 | minvalid = npoints | |
118 |
|
118 | |||
119 | #only if valid values greater than the minimum required (10%) |
|
119 | #only if valid values greater than the minimum required (10%) | |
120 | if nvalues_valid > minvalid: |
|
120 | if nvalues_valid > minvalid: | |
121 |
|
121 | |||
122 | if method == 0: |
|
122 | if method == 0: | |
123 | #SMOOTH |
|
123 | #SMOOTH | |
124 | w = value_temp[h] - self.Smooth(input=value_temp[h], width=npoints, edge_truncate=1) |
|
124 | w = value_temp[h] - self.Smooth(input=value_temp[h], width=npoints, edge_truncate=1) | |
125 |
|
125 | |||
126 |
|
126 | |||
127 | if method == 1: |
|
127 | if method == 1: | |
128 | #MEDIAN |
|
128 | #MEDIAN | |
129 | w = value_temp[h] - self.Median(input=value_temp[h], width = npoints) |
|
129 | w = value_temp[h] - self.Median(input=value_temp[h], width = npoints) | |
130 |
|
130 | |||
131 | dw = numpy.std(w[numpy.where(numpy.isfinite(w))],ddof = 1) |
|
131 | dw = numpy.std(w[numpy.where(numpy.isfinite(w))],ddof = 1) | |
132 |
|
132 | |||
133 | threshold = dw*factor |
|
133 | threshold = dw*factor | |
134 | value_temp[numpy.where(w > threshold),h] = numpy.nan |
|
134 | value_temp[numpy.where(w > threshold),h] = numpy.nan | |
135 | value_temp[numpy.where(w < -1*threshold),h] = numpy.nan |
|
135 | value_temp[numpy.where(w < -1*threshold),h] = numpy.nan | |
136 |
|
136 | |||
137 |
|
137 | |||
138 | #At the end |
|
138 | #At the end | |
139 | if svalue2 == 'inHeight': |
|
139 | if svalue2 == 'inHeight': | |
140 | value_temp = numpy.transpose(value_temp) |
|
140 | value_temp = numpy.transpose(value_temp) | |
141 | output_array[:,m] = value_temp |
|
141 | output_array[:,m] = value_temp | |
142 |
|
142 | |||
143 | if svalue == 'zonal': |
|
143 | if svalue == 'zonal': | |
144 | self.dataOut.data_output[0] = output_array |
|
144 | self.dataOut.data_output[0] = output_array | |
145 |
|
145 | |||
146 | elif svalue == 'meridional': |
|
146 | elif svalue == 'meridional': | |
147 | self.dataOut.data_output[1] = output_array |
|
147 | self.dataOut.data_output[1] = output_array | |
148 |
|
148 | |||
149 | elif svalue == 'vertical': |
|
149 | elif svalue == 'vertical': | |
150 | self.dataOut.data_output[2] = output_array |
|
150 | self.dataOut.data_output[2] = output_array | |
151 |
|
151 | |||
152 | return self.dataOut.data_output |
|
152 | return self.dataOut.data_output | |
153 |
|
153 | |||
154 |
|
154 | |||
155 | def Median(self,input,width): |
|
155 | def Median(self,input,width): | |
156 | ''' |
|
156 | ''' | |
157 | Inputs: |
|
157 | Inputs: | |
158 | input - Velocity array |
|
158 | input - Velocity array | |
159 | width - Number of points for mask filter |
|
159 | width - Number of points for mask filter | |
160 |
|
160 | |||
161 | ''' |
|
161 | ''' | |
162 |
|
162 | |||
163 | if numpy.mod(width,2) == 1: |
|
163 | if numpy.mod(width,2) == 1: | |
164 | pc = int((width - 1) / 2) |
|
164 | pc = int((width - 1) / 2) | |
165 | cont = 0 |
|
165 | cont = 0 | |
166 | output = [] |
|
166 | output = [] | |
167 |
|
167 | |||
168 | for i in range(len(input)): |
|
168 | for i in range(len(input)): | |
169 | if i >= pc and i < len(input) - pc: |
|
169 | if i >= pc and i < len(input) - pc: | |
170 | new2 = input[i-pc:i+pc+1] |
|
170 | new2 = input[i-pc:i+pc+1] | |
171 | temp = numpy.where(numpy.isfinite(new2)) |
|
171 | temp = numpy.where(numpy.isfinite(new2)) | |
172 | new = new2[temp] |
|
172 | new = new2[temp] | |
173 | value = numpy.median(new) |
|
173 | value = numpy.median(new) | |
174 | output.append(value) |
|
174 | output.append(value) | |
175 |
|
175 | |||
176 | output = numpy.array(output) |
|
176 | output = numpy.array(output) | |
177 | output = numpy.hstack((input[0:pc],output)) |
|
177 | output = numpy.hstack((input[0:pc],output)) | |
178 | output = numpy.hstack((output,input[-pc:len(input)])) |
|
178 | output = numpy.hstack((output,input[-pc:len(input)])) | |
179 |
|
179 | |||
180 | return output |
|
180 | return output | |
181 |
|
181 | |||
182 | def Smooth(self,input,width,edge_truncate = None): |
|
182 | def Smooth(self,input,width,edge_truncate = None): | |
183 | ''' |
|
183 | ''' | |
184 | Inputs: |
|
184 | Inputs: | |
185 | input - Velocity array |
|
185 | input - Velocity array | |
186 | width - Number of points for mask filter |
|
186 | width - Number of points for mask filter | |
187 | edge_truncate - 1 for truncate the convolution product else |
|
187 | edge_truncate - 1 for truncate the convolution product else | |
188 |
|
188 | |||
189 | ''' |
|
189 | ''' | |
190 |
|
190 | |||
191 | if numpy.mod(width,2) == 0: |
|
191 | if numpy.mod(width,2) == 0: | |
192 | real_width = width + 1 |
|
192 | real_width = width + 1 | |
193 | nzeros = width / 2 |
|
193 | nzeros = width / 2 | |
194 | else: |
|
194 | else: | |
195 | real_width = width |
|
195 | real_width = width | |
196 | nzeros = (width - 1) / 2 |
|
196 | nzeros = (width - 1) / 2 | |
197 |
|
197 | |||
198 | half_width = int(real_width)/2 |
|
198 | half_width = int(real_width)/2 | |
199 | length = len(input) |
|
199 | length = len(input) | |
200 |
|
200 | |||
201 | gate = numpy.ones(real_width,dtype='float') |
|
201 | gate = numpy.ones(real_width,dtype='float') | |
202 | norm_of_gate = numpy.sum(gate) |
|
202 | norm_of_gate = numpy.sum(gate) | |
203 |
|
203 | |||
204 | nan_process = 0 |
|
204 | nan_process = 0 | |
205 | nan_id = numpy.where(numpy.isnan(input)) |
|
205 | nan_id = numpy.where(numpy.isnan(input)) | |
206 | if len(nan_id[0]) > 0: |
|
206 | if len(nan_id[0]) > 0: | |
207 | nan_process = 1 |
|
207 | nan_process = 1 | |
208 | pb = numpy.zeros(len(input)) |
|
208 | pb = numpy.zeros(len(input)) | |
209 | pb[nan_id] = 1. |
|
209 | pb[nan_id] = 1. | |
210 | input[nan_id] = 0. |
|
210 | input[nan_id] = 0. | |
211 |
|
211 | |||
212 | if edge_truncate == True: |
|
212 | if edge_truncate == True: | |
213 | output = numpy.convolve(input/norm_of_gate,gate,mode='same') |
|
213 | output = numpy.convolve(input/norm_of_gate,gate,mode='same') | |
214 | elif edge_truncate == False or edge_truncate == None: |
|
214 | elif edge_truncate == False or edge_truncate == None: | |
215 | output = numpy.convolve(input/norm_of_gate,gate,mode='valid') |
|
215 | output = numpy.convolve(input/norm_of_gate,gate,mode='valid') | |
216 | output = numpy.hstack((input[0:half_width],output)) |
|
216 | output = numpy.hstack((input[0:half_width],output)) | |
217 | output = numpy.hstack((output,input[len(input)-half_width:len(input)])) |
|
217 | output = numpy.hstack((output,input[len(input)-half_width:len(input)])) | |
218 |
|
218 | |||
219 | if nan_process: |
|
219 | if nan_process: | |
220 | pb = numpy.convolve(pb/norm_of_gate,gate,mode='valid') |
|
220 | pb = numpy.convolve(pb/norm_of_gate,gate,mode='valid') | |
221 | pb = numpy.hstack((numpy.zeros(half_width),pb)) |
|
221 | pb = numpy.hstack((numpy.zeros(half_width),pb)) | |
222 | pb = numpy.hstack((pb,numpy.zeros(half_width))) |
|
222 | pb = numpy.hstack((pb,numpy.zeros(half_width))) | |
223 | output[numpy.where(pb > 0.9999)] = numpy.nan |
|
223 | output[numpy.where(pb > 0.9999)] = numpy.nan | |
224 | input[nan_id] = numpy.nan |
|
224 | input[nan_id] = numpy.nan | |
225 | return output |
|
225 | return output | |
226 |
|
226 | |||
227 | def Average(self,aver=0,nhaver=1): |
|
227 | def Average(self,aver=0,nhaver=1): | |
228 | ''' |
|
228 | ''' | |
229 | Inputs: |
|
229 | Inputs: | |
230 | aver - Indicates the time period over which is averaged or consensus data |
|
230 | aver - Indicates the time period over which is averaged or consensus data | |
231 | nhaver - Indicates the decimation factor in heights |
|
231 | nhaver - Indicates the decimation factor in heights | |
232 |
|
232 | |||
233 | ''' |
|
233 | ''' | |
234 | nhpoints = 48 |
|
234 | nhpoints = 48 | |
235 |
|
235 | |||
236 | lat_piura = -5.17 |
|
236 | lat_piura = -5.17 | |
237 | lat_huancayo = -12.04 |
|
237 | lat_huancayo = -12.04 | |
238 | lat_porcuya = -5.8 |
|
238 | lat_porcuya = -5.8 | |
239 |
|
239 | |||
240 | if '%2.2f'%self.dataOut.lat == '%2.2f'%lat_piura: |
|
240 | if '%2.2f'%self.dataOut.lat == '%2.2f'%lat_piura: | |
241 | hcm = 3. |
|
241 | hcm = 3. | |
242 | if self.dataOut.year == 2003 : |
|
242 | if self.dataOut.year == 2003 : | |
243 | if self.dataOut.doy >= 25 and self.dataOut.doy < 64: |
|
243 | if self.dataOut.doy >= 25 and self.dataOut.doy < 64: | |
244 | nhpoints = 12 |
|
244 | nhpoints = 12 | |
245 |
|
245 | |||
246 | elif '%2.2f'%self.dataOut.lat == '%2.2f'%lat_huancayo: |
|
246 | elif '%2.2f'%self.dataOut.lat == '%2.2f'%lat_huancayo: | |
247 | hcm = 3. |
|
247 | hcm = 3. | |
248 | if self.dataOut.year == 2003 : |
|
248 | if self.dataOut.year == 2003 : | |
249 | if self.dataOut.doy >= 25 and self.dataOut.doy < 64: |
|
249 | if self.dataOut.doy >= 25 and self.dataOut.doy < 64: | |
250 | nhpoints = 12 |
|
250 | nhpoints = 12 | |
251 |
|
251 | |||
252 |
|
252 | |||
253 | elif '%2.2f'%self.dataOut.lat == '%2.2f'%lat_porcuya: |
|
253 | elif '%2.2f'%self.dataOut.lat == '%2.2f'%lat_porcuya: | |
254 | hcm = 5.#2 |
|
254 | hcm = 5.#2 | |
255 |
|
255 | |||
256 | pdata = 0.2 |
|
256 | pdata = 0.2 | |
257 | taver = [1,2,3,4,6,8,12,24] |
|
257 | taver = [1,2,3,4,6,8,12,24] | |
258 | t0 = 0 |
|
258 | t0 = 0 | |
259 | tf = 24 |
|
259 | tf = 24 | |
260 | ntime =(tf-t0)/taver[aver] |
|
260 | ntime =(tf-t0)/taver[aver] | |
261 | ti = numpy.arange(ntime) |
|
261 | ti = numpy.arange(ntime) | |
262 | tf = numpy.arange(ntime) + taver[aver] |
|
262 | tf = numpy.arange(ntime) + taver[aver] | |
263 |
|
263 | |||
264 |
|
264 | |||
265 | old_height = self.dataOut.heightList |
|
265 | old_height = self.dataOut.heightList | |
266 |
|
266 | |||
267 | if nhaver > 1: |
|
267 | if nhaver > 1: | |
268 | num_hei = len(self.dataOut.heightList)/nhaver/self.dataOut.nmodes |
|
268 | num_hei = len(self.dataOut.heightList)/nhaver/self.dataOut.nmodes | |
269 | deltha = 0.05*nhaver |
|
269 | deltha = 0.05*nhaver | |
270 | minhvalid = pdata*nhaver |
|
270 | minhvalid = pdata*nhaver | |
271 | for im in range(self.dataOut.nmodes): |
|
271 | for im in range(self.dataOut.nmodes): | |
272 | new_height = numpy.arange(num_hei)*deltha + self.dataOut.height[im,0] + deltha/2. |
|
272 | new_height = numpy.arange(num_hei)*deltha + self.dataOut.height[im,0] + deltha/2. | |
273 |
|
273 | |||
274 |
|
274 | |||
275 | data_fHeigths_List = [] |
|
275 | data_fHeigths_List = [] | |
276 | data_fZonal_List = [] |
|
276 | data_fZonal_List = [] | |
277 | data_fMeridional_List = [] |
|
277 | data_fMeridional_List = [] | |
278 | data_fVertical_List = [] |
|
278 | data_fVertical_List = [] | |
279 | startDTList = [] |
|
279 | startDTList = [] | |
280 |
|
280 | |||
281 |
|
281 | |||
282 | for i in range(ntime): |
|
282 | for i in range(ntime): | |
283 | height = old_height |
|
283 | height = old_height | |
284 |
|
284 | |||
285 | start = datetime.datetime(self.dataOut.year,self.dataOut.month,self.dataOut.day) + datetime.timedelta(hours = int(ti[i])) - datetime.timedelta(hours = 5) |
|
285 | start = datetime.datetime(self.dataOut.year,self.dataOut.month,self.dataOut.day) + datetime.timedelta(hours = int(ti[i])) - datetime.timedelta(hours = 5) | |
286 | stop = datetime.datetime(self.dataOut.year,self.dataOut.month,self.dataOut.day) + datetime.timedelta(hours = int(tf[i])) - datetime.timedelta(hours = 5) |
|
286 | stop = datetime.datetime(self.dataOut.year,self.dataOut.month,self.dataOut.day) + datetime.timedelta(hours = int(tf[i])) - datetime.timedelta(hours = 5) | |
287 |
|
287 | |||
288 |
|
288 | |||
289 | limit_sec1 = time.mktime(start.timetuple()) |
|
289 | limit_sec1 = time.mktime(start.timetuple()) | |
290 | limit_sec2 = time.mktime(stop.timetuple()) |
|
290 | limit_sec2 = time.mktime(stop.timetuple()) | |
291 |
|
291 | |||
292 | t1 = numpy.where(self.f_timesec >= limit_sec1) |
|
292 | t1 = numpy.where(self.f_timesec >= limit_sec1) | |
293 | t2 = numpy.where(self.f_timesec < limit_sec2) |
|
293 | t2 = numpy.where(self.f_timesec < limit_sec2) | |
294 | time_select = [] |
|
294 | time_select = [] | |
295 | for val_sec in t1[0]: |
|
295 | for val_sec in t1[0]: | |
296 | if val_sec in t2[0]: |
|
296 | if val_sec in t2[0]: | |
297 | time_select.append(val_sec) |
|
297 | time_select.append(val_sec) | |
298 |
|
298 | |||
299 |
|
299 | |||
300 | time_select = numpy.array(time_select,dtype = 'int') |
|
300 | time_select = numpy.array(time_select,dtype = 'int') | |
301 | minvalid = numpy.ceil(pdata*nhpoints) |
|
301 | minvalid = numpy.ceil(pdata*nhpoints) | |
302 |
|
302 | |||
303 | zon_aver = numpy.zeros([self.dataOut.nranges,self.dataOut.nmodes],dtype='f4') + numpy.nan |
|
303 | zon_aver = numpy.zeros([self.dataOut.nranges,self.dataOut.nmodes],dtype='f4') + numpy.nan | |
304 | mer_aver = numpy.zeros([self.dataOut.nranges,self.dataOut.nmodes],dtype='f4') + numpy.nan |
|
304 | mer_aver = numpy.zeros([self.dataOut.nranges,self.dataOut.nmodes],dtype='f4') + numpy.nan | |
305 | ver_aver = numpy.zeros([self.dataOut.nranges,self.dataOut.nmodes],dtype='f4') + numpy.nan |
|
305 | ver_aver = numpy.zeros([self.dataOut.nranges,self.dataOut.nmodes],dtype='f4') + numpy.nan | |
306 |
|
306 | |||
307 | if nhaver > 1: |
|
307 | if nhaver > 1: | |
308 | new_zon_aver = numpy.zeros([num_hei,self.dataOut.nmodes],dtype='f4') + numpy.nan |
|
308 | new_zon_aver = numpy.zeros([num_hei,self.dataOut.nmodes],dtype='f4') + numpy.nan | |
309 | new_mer_aver = numpy.zeros([num_hei,self.dataOut.nmodes],dtype='f4') + numpy.nan |
|
309 | new_mer_aver = numpy.zeros([num_hei,self.dataOut.nmodes],dtype='f4') + numpy.nan | |
310 | new_ver_aver = numpy.zeros([num_hei,self.dataOut.nmodes],dtype='f4') + numpy.nan |
|
310 | new_ver_aver = numpy.zeros([num_hei,self.dataOut.nmodes],dtype='f4') + numpy.nan | |
311 |
|
311 | |||
312 | if len(time_select) > minvalid: |
|
312 | if len(time_select) > minvalid: | |
313 | time_average = self.f_timesec[time_select] |
|
313 | time_average = self.f_timesec[time_select] | |
314 |
|
314 | |||
315 | for im in range(self.dataOut.nmodes): |
|
315 | for im in range(self.dataOut.nmodes): | |
316 |
|
316 | |||
317 | for ih in range(self.dataOut.nranges): |
|
317 | for ih in range(self.dataOut.nranges): | |
318 | if numpy.sum(numpy.isfinite(self.f_zon[time_select,ih,im])) >= minvalid: |
|
318 | if numpy.sum(numpy.isfinite(self.f_zon[time_select,ih,im])) >= minvalid: | |
319 | zon_aver[ih,im] = numpy.nansum(self.f_zon[time_select,ih,im]) / numpy.sum(numpy.isfinite(self.f_zon[time_select,ih,im])) |
|
319 | zon_aver[ih,im] = numpy.nansum(self.f_zon[time_select,ih,im]) / numpy.sum(numpy.isfinite(self.f_zon[time_select,ih,im])) | |
320 |
|
320 | |||
321 | if numpy.sum(numpy.isfinite(self.f_mer[time_select,ih,im])) >= minvalid: |
|
321 | if numpy.sum(numpy.isfinite(self.f_mer[time_select,ih,im])) >= minvalid: | |
322 | mer_aver[ih,im] = numpy.nansum(self.f_mer[time_select,ih,im]) / numpy.sum(numpy.isfinite(self.f_mer[time_select,ih,im])) |
|
322 | mer_aver[ih,im] = numpy.nansum(self.f_mer[time_select,ih,im]) / numpy.sum(numpy.isfinite(self.f_mer[time_select,ih,im])) | |
323 |
|
323 | |||
324 | if numpy.sum(numpy.isfinite(self.f_ver[time_select,ih,im])) >= minvalid: |
|
324 | if numpy.sum(numpy.isfinite(self.f_ver[time_select,ih,im])) >= minvalid: | |
325 | ver_aver[ih,im] = numpy.nansum(self.f_ver[time_select,ih,im]) / numpy.sum(numpy.isfinite(self.f_ver[time_select,ih,im])) |
|
325 | ver_aver[ih,im] = numpy.nansum(self.f_ver[time_select,ih,im]) / numpy.sum(numpy.isfinite(self.f_ver[time_select,ih,im])) | |
326 |
|
326 | |||
327 | if nhaver > 1: |
|
327 | if nhaver > 1: | |
328 | for ih in range(num_hei): |
|
328 | for ih in range(num_hei): | |
329 | hvalid = numpy.arange(nhaver) + nhaver*ih |
|
329 | hvalid = numpy.arange(nhaver) + nhaver*ih | |
330 |
|
330 | |||
331 | if numpy.sum(numpy.isfinite(zon_aver[hvalid,im])) >= minvalid: |
|
331 | if numpy.sum(numpy.isfinite(zon_aver[hvalid,im])) >= minvalid: | |
332 | new_zon_aver[ih,im] = numpy.nansum(zon_aver[hvalid,im]) / numpy.sum(numpy.isfinite(zon_aver[hvalid,im])) |
|
332 | new_zon_aver[ih,im] = numpy.nansum(zon_aver[hvalid,im]) / numpy.sum(numpy.isfinite(zon_aver[hvalid,im])) | |
333 |
|
333 | |||
334 | if numpy.sum(numpy.isfinite(mer_aver[hvalid,im])) >= minvalid: |
|
334 | if numpy.sum(numpy.isfinite(mer_aver[hvalid,im])) >= minvalid: | |
335 | new_mer_aver[ih,im] = numpy.nansum(mer_aver[hvalid,im]) / numpy.sum(numpy.isfinite(mer_aver[hvalid,im])) |
|
335 | new_mer_aver[ih,im] = numpy.nansum(mer_aver[hvalid,im]) / numpy.sum(numpy.isfinite(mer_aver[hvalid,im])) | |
336 |
|
336 | |||
337 | if numpy.sum(numpy.isfinite(ver_aver[hvalid,im])) >= minvalid: |
|
337 | if numpy.sum(numpy.isfinite(ver_aver[hvalid,im])) >= minvalid: | |
338 | new_ver_aver[ih,im] = numpy.nansum(ver_aver[hvalid,im]) / numpy.sum(numpy.isfinite(ver_aver[hvalid,im])) |
|
338 | new_ver_aver[ih,im] = numpy.nansum(ver_aver[hvalid,im]) / numpy.sum(numpy.isfinite(ver_aver[hvalid,im])) | |
339 | if nhaver > 1: |
|
339 | if nhaver > 1: | |
340 | zon_aver = new_zon_aver |
|
340 | zon_aver = new_zon_aver | |
341 | mer_aver = new_mer_aver |
|
341 | mer_aver = new_mer_aver | |
342 | ver_aver = new_ver_aver |
|
342 | ver_aver = new_ver_aver | |
343 | height = new_height |
|
343 | height = new_height | |
344 |
|
344 | |||
345 |
|
345 | |||
346 | tstart = time_average[0] |
|
346 | tstart = time_average[0] | |
347 | tend = time_average[-1] |
|
347 | tend = time_average[-1] | |
348 | startTime = time.gmtime(tstart) |
|
348 | startTime = time.gmtime(tstart) | |
349 |
|
349 | |||
350 | year = startTime.tm_year |
|
350 | year = startTime.tm_year | |
351 | month = startTime.tm_mon |
|
351 | month = startTime.tm_mon | |
352 | day = startTime.tm_mday |
|
352 | day = startTime.tm_mday | |
353 | hour = startTime.tm_hour |
|
353 | hour = startTime.tm_hour | |
354 | minute = startTime.tm_min |
|
354 | minute = startTime.tm_min | |
355 | second = startTime.tm_sec |
|
355 | second = startTime.tm_sec | |
356 |
|
356 | |||
357 | startDTList.append(datetime.datetime(year,month,day,hour,minute,second)) |
|
357 | startDTList.append(datetime.datetime(year,month,day,hour,minute,second)) | |
358 |
|
358 | |||
359 |
|
359 | |||
360 | o_height = numpy.array([]) |
|
360 | o_height = numpy.array([]) | |
361 | o_zon_aver = numpy.array([]) |
|
361 | o_zon_aver = numpy.array([]) | |
362 | o_mer_aver = numpy.array([]) |
|
362 | o_mer_aver = numpy.array([]) | |
363 | o_ver_aver = numpy.array([]) |
|
363 | o_ver_aver = numpy.array([]) | |
364 | if self.dataOut.nmodes > 1: |
|
364 | if self.dataOut.nmodes > 1: | |
365 | for im in range(self.dataOut.nmodes): |
|
365 | for im in range(self.dataOut.nmodes): | |
366 |
|
366 | |||
367 | if im == 0: |
|
367 | if im == 0: | |
368 | h_select = numpy.where(numpy.bitwise_and(height[0,:] >=0,height[0,:] <= hcm,numpy.isfinite(height[0,:]))) |
|
368 | h_select = numpy.where(numpy.bitwise_and(height[0,:] >=0,height[0,:] <= hcm,numpy.isfinite(height[0,:]))) | |
369 | else: |
|
369 | else: | |
370 | h_select = numpy.where(numpy.bitwise_and(height[1,:] > hcm,height[1,:] < 20,numpy.isfinite(height[1,:]))) |
|
370 | h_select = numpy.where(numpy.bitwise_and(height[1,:] > hcm,height[1,:] < 20,numpy.isfinite(height[1,:]))) | |
371 |
|
371 | |||
372 |
|
372 | |||
373 | ht = h_select[0] |
|
373 | ht = h_select[0] | |
374 |
|
374 | |||
375 | o_height = numpy.hstack((o_height,height[im,ht])) |
|
375 | o_height = numpy.hstack((o_height,height[im,ht])) | |
376 | o_zon_aver = numpy.hstack((o_zon_aver,zon_aver[ht,im])) |
|
376 | o_zon_aver = numpy.hstack((o_zon_aver,zon_aver[ht,im])) | |
377 | o_mer_aver = numpy.hstack((o_mer_aver,mer_aver[ht,im])) |
|
377 | o_mer_aver = numpy.hstack((o_mer_aver,mer_aver[ht,im])) | |
378 | o_ver_aver = numpy.hstack((o_ver_aver,ver_aver[ht,im])) |
|
378 | o_ver_aver = numpy.hstack((o_ver_aver,ver_aver[ht,im])) | |
379 |
|
379 | |||
380 | data_fHeigths_List.append(o_height) |
|
380 | data_fHeigths_List.append(o_height) | |
381 | data_fZonal_List.append(o_zon_aver) |
|
381 | data_fZonal_List.append(o_zon_aver) | |
382 | data_fMeridional_List.append(o_mer_aver) |
|
382 | data_fMeridional_List.append(o_mer_aver) | |
383 | data_fVertical_List.append(o_ver_aver) |
|
383 | data_fVertical_List.append(o_ver_aver) | |
384 |
|
384 | |||
385 |
|
385 | |||
386 | else: |
|
386 | else: | |
387 | h_select = numpy.where(numpy.bitwise_and(height[0,:] <= hcm,numpy.isfinite(height[0,:]))) |
|
387 | h_select = numpy.where(numpy.bitwise_and(height[0,:] <= hcm,numpy.isfinite(height[0,:]))) | |
388 | ht = h_select[0] |
|
388 | ht = h_select[0] | |
389 | o_height = numpy.hstack((o_height,height[im,ht])) |
|
389 | o_height = numpy.hstack((o_height,height[im,ht])) | |
390 | o_zon_aver = numpy.hstack((o_zon_aver,zon_aver[ht,im])) |
|
390 | o_zon_aver = numpy.hstack((o_zon_aver,zon_aver[ht,im])) | |
391 | o_mer_aver = numpy.hstack((o_mer_aver,mer_aver[ht,im])) |
|
391 | o_mer_aver = numpy.hstack((o_mer_aver,mer_aver[ht,im])) | |
392 | o_ver_aver = numpy.hstack((o_ver_aver,ver_aver[ht,im])) |
|
392 | o_ver_aver = numpy.hstack((o_ver_aver,ver_aver[ht,im])) | |
393 |
|
393 | |||
394 | data_fHeigths_List.append(o_height) |
|
394 | data_fHeigths_List.append(o_height) | |
395 | data_fZonal_List.append(o_zon_aver) |
|
395 | data_fZonal_List.append(o_zon_aver) | |
396 | data_fMeridional_List.append(o_mer_aver) |
|
396 | data_fMeridional_List.append(o_mer_aver) | |
397 | data_fVertical_List.append(o_ver_aver) |
|
397 | data_fVertical_List.append(o_ver_aver) | |
398 |
|
398 | |||
399 |
|
399 | |||
400 | return startDTList, data_fHeigths_List, data_fZonal_List, data_fMeridional_List, data_fVertical_List |
|
400 | return startDTList, data_fHeigths_List, data_fZonal_List, data_fMeridional_List, data_fVertical_List | |
401 |
|
401 | |||
402 |
|
402 |
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,876 +1,898 | |||||
1 | # Copyright (c) 2012-2020 Jicamarca Radio Observatory |
|
1 | # Copyright (c) 2012-2020 Jicamarca Radio Observatory | |
2 | # All rights reserved. |
|
2 | # All rights reserved. | |
3 | # |
|
3 | # | |
4 | # Distributed under the terms of the BSD 3-clause license. |
|
4 | # Distributed under the terms of the BSD 3-clause license. | |
5 | """Spectra processing Unit and operations |
|
5 | """Spectra processing Unit and operations | |
6 |
|
6 | |||
7 | Here you will find the processing unit `SpectraProc` and several operations |
|
7 | Here you will find the processing unit `SpectraProc` and several operations | |
8 | to work with Spectra data type |
|
8 | to work with Spectra data type | |
9 | """ |
|
9 | """ | |
10 |
|
10 | |||
11 | import time |
|
11 | import time | |
12 | import itertools |
|
12 | import itertools | |
13 |
|
13 | |||
14 | import numpy |
|
14 | import numpy | |
15 |
|
15 | |||
16 | from schainpy.model.proc.jroproc_base import ProcessingUnit, MPDecorator, Operation |
|
16 | from schainpy.model.proc.jroproc_base import ProcessingUnit, MPDecorator, Operation | |
17 | from schainpy.model.data.jrodata import Spectra |
|
17 | from schainpy.model.data.jrodata import Spectra | |
18 | from schainpy.model.data.jrodata import hildebrand_sekhon |
|
18 | from schainpy.model.data.jrodata import hildebrand_sekhon | |
19 | from schainpy.utils import log |
|
19 | from schainpy.utils import log | |
20 |
|
20 | |||
21 |
|
21 | |||
22 | class SpectraProc(ProcessingUnit): |
|
22 | class SpectraProc(ProcessingUnit): | |
23 |
|
23 | |||
24 | def __init__(self): |
|
24 | def __init__(self): | |
25 |
|
25 | |||
26 | ProcessingUnit.__init__(self) |
|
26 | ProcessingUnit.__init__(self) | |
27 |
|
27 | |||
28 | self.buffer = None |
|
28 | self.buffer = None | |
29 | self.firstdatatime = None |
|
29 | self.firstdatatime = None | |
30 | self.profIndex = 0 |
|
30 | self.profIndex = 0 | |
31 | self.dataOut = Spectra() |
|
31 | self.dataOut = Spectra() | |
32 | self.id_min = None |
|
32 | self.id_min = None | |
33 | self.id_max = None |
|
33 | self.id_max = None | |
34 | self.setupReq = False #Agregar a todas las unidades de proc |
|
34 | self.setupReq = False #Agregar a todas las unidades de proc | |
35 |
|
35 | |||
36 | def __updateSpecFromVoltage(self): |
|
36 | def __updateSpecFromVoltage(self): | |
37 |
|
37 | |||
38 | self.dataOut.timeZone = self.dataIn.timeZone |
|
38 | self.dataOut.timeZone = self.dataIn.timeZone | |
39 | self.dataOut.dstFlag = self.dataIn.dstFlag |
|
39 | self.dataOut.dstFlag = self.dataIn.dstFlag | |
40 | self.dataOut.errorCount = self.dataIn.errorCount |
|
40 | self.dataOut.errorCount = self.dataIn.errorCount | |
41 | self.dataOut.useLocalTime = self.dataIn.useLocalTime |
|
41 | self.dataOut.useLocalTime = self.dataIn.useLocalTime | |
42 | try: |
|
42 | try: | |
43 | self.dataOut.processingHeaderObj = self.dataIn.processingHeaderObj.copy() |
|
43 | self.dataOut.processingHeaderObj = self.dataIn.processingHeaderObj.copy() | |
44 | except: |
|
44 | except: | |
45 | pass |
|
45 | pass | |
46 | self.dataOut.radarControllerHeaderObj = self.dataIn.radarControllerHeaderObj.copy() |
|
46 | self.dataOut.radarControllerHeaderObj = self.dataIn.radarControllerHeaderObj.copy() | |
47 | self.dataOut.systemHeaderObj = self.dataIn.systemHeaderObj.copy() |
|
47 | self.dataOut.systemHeaderObj = self.dataIn.systemHeaderObj.copy() | |
48 | self.dataOut.channelList = self.dataIn.channelList |
|
48 | self.dataOut.channelList = self.dataIn.channelList | |
49 | self.dataOut.heightList = self.dataIn.heightList |
|
49 | self.dataOut.heightList = self.dataIn.heightList | |
50 | self.dataOut.dtype = numpy.dtype([('real', '<f4'), ('imag', '<f4')]) |
|
50 | self.dataOut.dtype = numpy.dtype([('real', '<f4'), ('imag', '<f4')]) | |
51 | self.dataOut.nProfiles = self.dataOut.nFFTPoints |
|
51 | self.dataOut.nProfiles = self.dataOut.nFFTPoints | |
52 | self.dataOut.flagDiscontinuousBlock = self.dataIn.flagDiscontinuousBlock |
|
52 | self.dataOut.flagDiscontinuousBlock = self.dataIn.flagDiscontinuousBlock | |
53 | self.dataOut.utctime = self.firstdatatime |
|
53 | self.dataOut.utctime = self.firstdatatime | |
54 | self.dataOut.flagDecodeData = self.dataIn.flagDecodeData |
|
54 | self.dataOut.flagDecodeData = self.dataIn.flagDecodeData | |
55 | self.dataOut.flagDeflipData = self.dataIn.flagDeflipData |
|
55 | self.dataOut.flagDeflipData = self.dataIn.flagDeflipData | |
56 | self.dataOut.flagShiftFFT = False |
|
56 | self.dataOut.flagShiftFFT = False | |
57 | self.dataOut.nCohInt = self.dataIn.nCohInt |
|
57 | self.dataOut.nCohInt = self.dataIn.nCohInt | |
58 | self.dataOut.nIncohInt = 1 |
|
58 | self.dataOut.nIncohInt = 1 | |
59 | self.dataOut.windowOfFilter = self.dataIn.windowOfFilter |
|
59 | self.dataOut.windowOfFilter = self.dataIn.windowOfFilter | |
60 | self.dataOut.frequency = self.dataIn.frequency |
|
60 | self.dataOut.frequency = self.dataIn.frequency | |
61 | self.dataOut.realtime = self.dataIn.realtime |
|
61 | self.dataOut.realtime = self.dataIn.realtime | |
62 | self.dataOut.azimuth = self.dataIn.azimuth |
|
62 | self.dataOut.azimuth = self.dataIn.azimuth | |
63 | self.dataOut.zenith = self.dataIn.zenith |
|
63 | self.dataOut.zenith = self.dataIn.zenith | |
64 | self.dataOut.beam.codeList = self.dataIn.beam.codeList |
|
64 | self.dataOut.beam.codeList = self.dataIn.beam.codeList | |
65 | self.dataOut.beam.azimuthList = self.dataIn.beam.azimuthList |
|
65 | self.dataOut.beam.azimuthList = self.dataIn.beam.azimuthList | |
66 | self.dataOut.beam.zenithList = self.dataIn.beam.zenithList |
|
66 | self.dataOut.beam.zenithList = self.dataIn.beam.zenithList | |
67 |
|
67 | |||
68 | def __getFft(self): |
|
68 | def __getFft(self): | |
69 | """ |
|
69 | """ | |
70 | Convierte valores de Voltaje a Spectra |
|
70 | Convierte valores de Voltaje a Spectra | |
71 |
|
71 | |||
72 | Affected: |
|
72 | Affected: | |
73 | self.dataOut.data_spc |
|
73 | self.dataOut.data_spc | |
74 | self.dataOut.data_cspc |
|
74 | self.dataOut.data_cspc | |
75 | self.dataOut.data_dc |
|
75 | self.dataOut.data_dc | |
76 | self.dataOut.heightList |
|
76 | self.dataOut.heightList | |
77 | self.profIndex |
|
77 | self.profIndex | |
78 | self.buffer |
|
78 | self.buffer | |
79 | self.dataOut.flagNoData |
|
79 | self.dataOut.flagNoData | |
80 | """ |
|
80 | """ | |
81 | fft_volt = numpy.fft.fft( |
|
81 | fft_volt = numpy.fft.fft( | |
82 | self.buffer, n=self.dataOut.nFFTPoints, axis=1) |
|
82 | self.buffer, n=self.dataOut.nFFTPoints, axis=1) | |
83 | fft_volt = fft_volt.astype(numpy.dtype('complex')) |
|
83 | fft_volt = fft_volt.astype(numpy.dtype('complex')) | |
84 | dc = fft_volt[:, 0, :] |
|
84 | dc = fft_volt[:, 0, :] | |
85 |
|
85 | |||
86 | # calculo de self-spectra |
|
86 | # calculo de self-spectra | |
87 | fft_volt = numpy.fft.fftshift(fft_volt, axes=(1,)) |
|
87 | fft_volt = numpy.fft.fftshift(fft_volt, axes=(1,)) | |
88 | spc = fft_volt * numpy.conjugate(fft_volt) |
|
88 | spc = fft_volt * numpy.conjugate(fft_volt) | |
89 | spc = spc.real |
|
89 | spc = spc.real | |
90 |
|
90 | |||
91 | blocksize = 0 |
|
91 | blocksize = 0 | |
92 | blocksize += dc.size |
|
92 | blocksize += dc.size | |
93 | blocksize += spc.size |
|
93 | blocksize += spc.size | |
94 |
|
94 | |||
95 | cspc = None |
|
95 | cspc = None | |
96 | pairIndex = 0 |
|
96 | pairIndex = 0 | |
97 | if self.dataOut.pairsList != None: |
|
97 | if self.dataOut.pairsList != None: | |
98 | # calculo de cross-spectra |
|
98 | # calculo de cross-spectra | |
99 | cspc = numpy.zeros( |
|
99 | cspc = numpy.zeros( | |
100 | (self.dataOut.nPairs, self.dataOut.nFFTPoints, self.dataOut.nHeights), dtype='complex') |
|
100 | (self.dataOut.nPairs, self.dataOut.nFFTPoints, self.dataOut.nHeights), dtype='complex') | |
101 | for pair in self.dataOut.pairsList: |
|
101 | for pair in self.dataOut.pairsList: | |
102 | if pair[0] not in self.dataOut.channelList: |
|
102 | if pair[0] not in self.dataOut.channelList: | |
103 | raise ValueError("Error getting CrossSpectra: pair 0 of %s is not in channelList = %s" % ( |
|
103 | raise ValueError("Error getting CrossSpectra: pair 0 of %s is not in channelList = %s" % ( | |
104 | str(pair), str(self.dataOut.channelList))) |
|
104 | str(pair), str(self.dataOut.channelList))) | |
105 | if pair[1] not in self.dataOut.channelList: |
|
105 | if pair[1] not in self.dataOut.channelList: | |
106 | raise ValueError("Error getting CrossSpectra: pair 1 of %s is not in channelList = %s" % ( |
|
106 | raise ValueError("Error getting CrossSpectra: pair 1 of %s is not in channelList = %s" % ( | |
107 | str(pair), str(self.dataOut.channelList))) |
|
107 | str(pair), str(self.dataOut.channelList))) | |
108 |
|
108 | |||
109 | cspc[pairIndex, :, :] = fft_volt[pair[0], :, :] * \ |
|
109 | cspc[pairIndex, :, :] = fft_volt[pair[0], :, :] * \ | |
110 | numpy.conjugate(fft_volt[pair[1], :, :]) |
|
110 | numpy.conjugate(fft_volt[pair[1], :, :]) | |
111 | pairIndex += 1 |
|
111 | pairIndex += 1 | |
112 | blocksize += cspc.size |
|
112 | blocksize += cspc.size | |
113 |
|
113 | |||
114 | self.dataOut.data_spc = spc |
|
114 | self.dataOut.data_spc = spc | |
115 | self.dataOut.data_cspc = cspc |
|
115 | self.dataOut.data_cspc = cspc | |
116 | self.dataOut.data_dc = dc |
|
116 | self.dataOut.data_dc = dc | |
117 | self.dataOut.blockSize = blocksize |
|
117 | self.dataOut.blockSize = blocksize | |
118 | self.dataOut.flagShiftFFT = False |
|
118 | self.dataOut.flagShiftFFT = False | |
119 |
|
119 | |||
120 | def run(self, nProfiles=None, nFFTPoints=None, pairsList=None, ippFactor=None, shift_fft=False): |
|
120 | def run(self, nProfiles=None, nFFTPoints=None, pairsList=None, ippFactor=None, shift_fft=False): | |
121 |
|
121 | |||
122 | if self.dataIn.type == "Spectra": |
|
122 | if self.dataIn.type == "Spectra": | |
123 | self.dataOut.copy(self.dataIn) |
|
123 | self.dataOut.copy(self.dataIn) | |
124 | if shift_fft: |
|
124 | if shift_fft: | |
125 | #desplaza a la derecha en el eje 2 determinadas posiciones |
|
125 | #desplaza a la derecha en el eje 2 determinadas posiciones | |
126 | shift = int(self.dataOut.nFFTPoints/2) |
|
126 | shift = int(self.dataOut.nFFTPoints/2) | |
127 | self.dataOut.data_spc = numpy.roll(self.dataOut.data_spc, shift , axis=1) |
|
127 | self.dataOut.data_spc = numpy.roll(self.dataOut.data_spc, shift , axis=1) | |
128 |
|
128 | |||
129 | if self.dataOut.data_cspc is not None: |
|
129 | if self.dataOut.data_cspc is not None: | |
130 | #desplaza a la derecha en el eje 2 determinadas posiciones |
|
130 | #desplaza a la derecha en el eje 2 determinadas posiciones | |
131 | self.dataOut.data_cspc = numpy.roll(self.dataOut.data_cspc, shift, axis=1) |
|
131 | self.dataOut.data_cspc = numpy.roll(self.dataOut.data_cspc, shift, axis=1) | |
132 | if pairsList: |
|
132 | if pairsList: | |
133 | self.__selectPairs(pairsList) |
|
133 | self.__selectPairs(pairsList) | |
134 |
|
134 | |||
135 | elif self.dataIn.type == "Voltage": |
|
135 | elif self.dataIn.type == "Voltage": | |
136 |
|
136 | |||
137 | self.dataOut.flagNoData = True |
|
137 | self.dataOut.flagNoData = True | |
138 |
|
138 | |||
139 | if nFFTPoints == None: |
|
139 | if nFFTPoints == None: | |
140 | raise ValueError("This SpectraProc.run() need nFFTPoints input variable") |
|
140 | raise ValueError("This SpectraProc.run() need nFFTPoints input variable") | |
141 |
|
141 | |||
142 | if nProfiles == None: |
|
142 | if nProfiles == None: | |
143 | nProfiles = nFFTPoints |
|
143 | nProfiles = nFFTPoints | |
144 |
|
144 | |||
145 | if ippFactor == None: |
|
145 | if ippFactor == None: | |
146 | self.dataOut.ippFactor = 1 |
|
146 | self.dataOut.ippFactor = 1 | |
147 |
|
147 | |||
148 | self.dataOut.nFFTPoints = nFFTPoints |
|
148 | self.dataOut.nFFTPoints = nFFTPoints | |
149 |
|
149 | |||
150 | if self.buffer is None: |
|
150 | if self.buffer is None: | |
151 | self.buffer = numpy.zeros((self.dataIn.nChannels, |
|
151 | self.buffer = numpy.zeros((self.dataIn.nChannels, | |
152 | nProfiles, |
|
152 | nProfiles, | |
153 | self.dataIn.nHeights), |
|
153 | self.dataIn.nHeights), | |
154 | dtype='complex') |
|
154 | dtype='complex') | |
155 |
|
155 | |||
156 | if self.dataIn.flagDataAsBlock: |
|
156 | if self.dataIn.flagDataAsBlock: | |
157 | nVoltProfiles = self.dataIn.data.shape[1] |
|
157 | nVoltProfiles = self.dataIn.data.shape[1] | |
158 |
|
158 | |||
159 | if nVoltProfiles == nProfiles: |
|
159 | if nVoltProfiles == nProfiles: | |
160 | self.buffer = self.dataIn.data.copy() |
|
160 | self.buffer = self.dataIn.data.copy() | |
161 | self.profIndex = nVoltProfiles |
|
161 | self.profIndex = nVoltProfiles | |
162 |
|
162 | |||
163 | elif nVoltProfiles < nProfiles: |
|
163 | elif nVoltProfiles < nProfiles: | |
164 |
|
164 | |||
165 | if self.profIndex == 0: |
|
165 | if self.profIndex == 0: | |
166 | self.id_min = 0 |
|
166 | self.id_min = 0 | |
167 | self.id_max = nVoltProfiles |
|
167 | self.id_max = nVoltProfiles | |
168 |
|
168 | |||
169 | self.buffer[:, self.id_min:self.id_max, |
|
169 | self.buffer[:, self.id_min:self.id_max, | |
170 | :] = self.dataIn.data |
|
170 | :] = self.dataIn.data | |
171 | self.profIndex += nVoltProfiles |
|
171 | self.profIndex += nVoltProfiles | |
172 | self.id_min += nVoltProfiles |
|
172 | self.id_min += nVoltProfiles | |
173 | self.id_max += nVoltProfiles |
|
173 | self.id_max += nVoltProfiles | |
174 | else: |
|
174 | else: | |
175 | raise ValueError("The type object %s has %d profiles, it should just has %d profiles" % ( |
|
175 | raise ValueError("The type object %s has %d profiles, it should just has %d profiles" % ( | |
176 | self.dataIn.type, self.dataIn.data.shape[1], nProfiles)) |
|
176 | self.dataIn.type, self.dataIn.data.shape[1], nProfiles)) | |
177 | self.dataOut.flagNoData = True |
|
177 | self.dataOut.flagNoData = True | |
178 | else: |
|
178 | else: | |
179 | self.buffer[:, self.profIndex, :] = self.dataIn.data.copy() |
|
179 | self.buffer[:, self.profIndex, :] = self.dataIn.data.copy() | |
180 | self.profIndex += 1 |
|
180 | self.profIndex += 1 | |
181 |
|
181 | |||
182 | if self.firstdatatime == None: |
|
182 | if self.firstdatatime == None: | |
183 | self.firstdatatime = self.dataIn.utctime |
|
183 | self.firstdatatime = self.dataIn.utctime | |
184 |
|
184 | |||
185 | if self.profIndex == nProfiles: |
|
185 | if self.profIndex == nProfiles: | |
186 | self.__updateSpecFromVoltage() |
|
186 | self.__updateSpecFromVoltage() | |
187 | if pairsList == None: |
|
187 | if pairsList == None: | |
188 | self.dataOut.pairsList = [pair for pair in itertools.combinations(self.dataOut.channelList, 2)] |
|
188 | self.dataOut.pairsList = [pair for pair in itertools.combinations(self.dataOut.channelList, 2)] | |
189 | else: |
|
189 | else: | |
190 | self.dataOut.pairsList = pairsList |
|
190 | self.dataOut.pairsList = pairsList | |
191 | self.__getFft() |
|
191 | self.__getFft() | |
192 | self.dataOut.flagNoData = False |
|
192 | self.dataOut.flagNoData = False | |
193 | self.firstdatatime = None |
|
193 | self.firstdatatime = None | |
194 | self.profIndex = 0 |
|
194 | self.profIndex = 0 | |
195 | else: |
|
195 | else: | |
196 | raise ValueError("The type of input object '%s' is not valid".format( |
|
196 | raise ValueError("The type of input object '%s' is not valid".format( | |
197 | self.dataIn.type)) |
|
197 | self.dataIn.type)) | |
198 |
|
198 | |||
199 | def __selectPairs(self, pairsList): |
|
199 | def __selectPairs(self, pairsList): | |
200 |
|
200 | |||
201 | if not pairsList: |
|
201 | if not pairsList: | |
202 | return |
|
202 | return | |
203 |
|
203 | |||
204 | pairs = [] |
|
204 | pairs = [] | |
205 | pairsIndex = [] |
|
205 | pairsIndex = [] | |
206 |
|
206 | |||
207 | for pair in pairsList: |
|
207 | for pair in pairsList: | |
208 | if pair[0] not in self.dataOut.channelList or pair[1] not in self.dataOut.channelList: |
|
208 | if pair[0] not in self.dataOut.channelList or pair[1] not in self.dataOut.channelList: | |
209 | continue |
|
209 | continue | |
210 | pairs.append(pair) |
|
210 | pairs.append(pair) | |
211 | pairsIndex.append(pairs.index(pair)) |
|
211 | pairsIndex.append(pairs.index(pair)) | |
212 |
|
212 | |||
213 | self.dataOut.data_cspc = self.dataOut.data_cspc[pairsIndex] |
|
213 | self.dataOut.data_cspc = self.dataOut.data_cspc[pairsIndex] | |
214 | self.dataOut.pairsList = pairs |
|
214 | self.dataOut.pairsList = pairs | |
215 |
|
215 | |||
216 | return |
|
216 | return | |
217 |
|
217 | |||
218 | def selectFFTs(self, minFFT, maxFFT ): |
|
218 | def selectFFTs(self, minFFT, maxFFT ): | |
219 | """ |
|
219 | """ | |
220 | Selecciona un bloque de datos en base a un grupo de valores de puntos FFTs segun el rango |
|
220 | Selecciona un bloque de datos en base a un grupo de valores de puntos FFTs segun el rango | |
221 | minFFT<= FFT <= maxFFT |
|
221 | minFFT<= FFT <= maxFFT | |
222 | """ |
|
222 | """ | |
223 |
|
223 | |||
224 | if (minFFT > maxFFT): |
|
224 | if (minFFT > maxFFT): | |
225 | raise ValueError("Error selecting heights: Height range (%d,%d) is not valid" % (minFFT, maxFFT)) |
|
225 | raise ValueError("Error selecting heights: Height range (%d,%d) is not valid" % (minFFT, maxFFT)) | |
226 |
|
226 | |||
227 | if (minFFT < self.dataOut.getFreqRange()[0]): |
|
227 | if (minFFT < self.dataOut.getFreqRange()[0]): | |
228 | minFFT = self.dataOut.getFreqRange()[0] |
|
228 | minFFT = self.dataOut.getFreqRange()[0] | |
229 |
|
229 | |||
230 | if (maxFFT > self.dataOut.getFreqRange()[-1]): |
|
230 | if (maxFFT > self.dataOut.getFreqRange()[-1]): | |
231 | maxFFT = self.dataOut.getFreqRange()[-1] |
|
231 | maxFFT = self.dataOut.getFreqRange()[-1] | |
232 |
|
232 | |||
233 | minIndex = 0 |
|
233 | minIndex = 0 | |
234 | maxIndex = 0 |
|
234 | maxIndex = 0 | |
235 | FFTs = self.dataOut.getFreqRange() |
|
235 | FFTs = self.dataOut.getFreqRange() | |
236 |
|
236 | |||
237 | inda = numpy.where(FFTs >= minFFT) |
|
237 | inda = numpy.where(FFTs >= minFFT) | |
238 | indb = numpy.where(FFTs <= maxFFT) |
|
238 | indb = numpy.where(FFTs <= maxFFT) | |
239 |
|
239 | |||
240 | try: |
|
240 | try: | |
241 | minIndex = inda[0][0] |
|
241 | minIndex = inda[0][0] | |
242 | except: |
|
242 | except: | |
243 | minIndex = 0 |
|
243 | minIndex = 0 | |
244 |
|
244 | |||
245 | try: |
|
245 | try: | |
246 | maxIndex = indb[0][-1] |
|
246 | maxIndex = indb[0][-1] | |
247 | except: |
|
247 | except: | |
248 | maxIndex = len(FFTs) |
|
248 | maxIndex = len(FFTs) | |
249 |
|
249 | |||
250 | self.selectFFTsByIndex(minIndex, maxIndex) |
|
250 | self.selectFFTsByIndex(minIndex, maxIndex) | |
251 |
|
251 | |||
252 | return 1 |
|
252 | return 1 | |
253 |
|
253 | |||
254 | def getBeaconSignal(self, tauindex=0, channelindex=0, hei_ref=None): |
|
254 | def getBeaconSignal(self, tauindex=0, channelindex=0, hei_ref=None): | |
255 | newheis = numpy.where( |
|
255 | newheis = numpy.where( | |
256 | self.dataOut.heightList > self.dataOut.radarControllerHeaderObj.Taus[tauindex]) |
|
256 | self.dataOut.heightList > self.dataOut.radarControllerHeaderObj.Taus[tauindex]) | |
257 |
|
257 | |||
258 | if hei_ref != None: |
|
258 | if hei_ref != None: | |
259 | newheis = numpy.where(self.dataOut.heightList > hei_ref) |
|
259 | newheis = numpy.where(self.dataOut.heightList > hei_ref) | |
260 |
|
260 | |||
261 | minIndex = min(newheis[0]) |
|
261 | minIndex = min(newheis[0]) | |
262 | maxIndex = max(newheis[0]) |
|
262 | maxIndex = max(newheis[0]) | |
263 | data_spc = self.dataOut.data_spc[:, :, minIndex:maxIndex + 1] |
|
263 | data_spc = self.dataOut.data_spc[:, :, minIndex:maxIndex + 1] | |
264 | heightList = self.dataOut.heightList[minIndex:maxIndex + 1] |
|
264 | heightList = self.dataOut.heightList[minIndex:maxIndex + 1] | |
265 |
|
265 | |||
266 | # determina indices |
|
266 | # determina indices | |
267 | nheis = int(self.dataOut.radarControllerHeaderObj.txB / |
|
267 | nheis = int(self.dataOut.radarControllerHeaderObj.txB / | |
268 | (self.dataOut.heightList[1] - self.dataOut.heightList[0])) |
|
268 | (self.dataOut.heightList[1] - self.dataOut.heightList[0])) | |
269 | avg_dB = 10 * \ |
|
269 | avg_dB = 10 * \ | |
270 | numpy.log10(numpy.sum(data_spc[channelindex, :, :], axis=0)) |
|
270 | numpy.log10(numpy.sum(data_spc[channelindex, :, :], axis=0)) | |
271 | beacon_dB = numpy.sort(avg_dB)[-nheis:] |
|
271 | beacon_dB = numpy.sort(avg_dB)[-nheis:] | |
272 | beacon_heiIndexList = [] |
|
272 | beacon_heiIndexList = [] | |
273 | for val in avg_dB.tolist(): |
|
273 | for val in avg_dB.tolist(): | |
274 | if val >= beacon_dB[0]: |
|
274 | if val >= beacon_dB[0]: | |
275 | beacon_heiIndexList.append(avg_dB.tolist().index(val)) |
|
275 | beacon_heiIndexList.append(avg_dB.tolist().index(val)) | |
276 |
|
276 | |||
277 | #data_spc = data_spc[:,:,beacon_heiIndexList] |
|
277 | #data_spc = data_spc[:,:,beacon_heiIndexList] | |
278 | data_cspc = None |
|
278 | data_cspc = None | |
279 | if self.dataOut.data_cspc is not None: |
|
279 | if self.dataOut.data_cspc is not None: | |
280 | data_cspc = self.dataOut.data_cspc[:, :, minIndex:maxIndex + 1] |
|
280 | data_cspc = self.dataOut.data_cspc[:, :, minIndex:maxIndex + 1] | |
281 | #data_cspc = data_cspc[:,:,beacon_heiIndexList] |
|
281 | #data_cspc = data_cspc[:,:,beacon_heiIndexList] | |
282 |
|
282 | |||
283 | data_dc = None |
|
283 | data_dc = None | |
284 | if self.dataOut.data_dc is not None: |
|
284 | if self.dataOut.data_dc is not None: | |
285 | data_dc = self.dataOut.data_dc[:, minIndex:maxIndex + 1] |
|
285 | data_dc = self.dataOut.data_dc[:, minIndex:maxIndex + 1] | |
286 | #data_dc = data_dc[:,beacon_heiIndexList] |
|
286 | #data_dc = data_dc[:,beacon_heiIndexList] | |
287 |
|
287 | |||
288 | self.dataOut.data_spc = data_spc |
|
288 | self.dataOut.data_spc = data_spc | |
289 | self.dataOut.data_cspc = data_cspc |
|
289 | self.dataOut.data_cspc = data_cspc | |
290 | self.dataOut.data_dc = data_dc |
|
290 | self.dataOut.data_dc = data_dc | |
291 | self.dataOut.heightList = heightList |
|
291 | self.dataOut.heightList = heightList | |
292 | self.dataOut.beacon_heiIndexList = beacon_heiIndexList |
|
292 | self.dataOut.beacon_heiIndexList = beacon_heiIndexList | |
293 |
|
293 | |||
294 | return 1 |
|
294 | return 1 | |
295 |
|
295 | |||
296 | def selectFFTsByIndex(self, minIndex, maxIndex): |
|
296 | def selectFFTsByIndex(self, minIndex, maxIndex): | |
297 | """ |
|
297 | """ | |
298 |
|
298 | |||
299 | """ |
|
299 | """ | |
300 |
|
300 | |||
301 | if (minIndex < 0) or (minIndex > maxIndex): |
|
301 | if (minIndex < 0) or (minIndex > maxIndex): | |
302 | raise ValueError("Error selecting heights: Index range (%d,%d) is not valid" % (minIndex, maxIndex)) |
|
302 | raise ValueError("Error selecting heights: Index range (%d,%d) is not valid" % (minIndex, maxIndex)) | |
303 |
|
303 | |||
304 | if (maxIndex >= self.dataOut.nProfiles): |
|
304 | if (maxIndex >= self.dataOut.nProfiles): | |
305 | maxIndex = self.dataOut.nProfiles-1 |
|
305 | maxIndex = self.dataOut.nProfiles-1 | |
306 |
|
306 | |||
307 | #Spectra |
|
307 | #Spectra | |
308 | data_spc = self.dataOut.data_spc[:,minIndex:maxIndex+1,:] |
|
308 | data_spc = self.dataOut.data_spc[:,minIndex:maxIndex+1,:] | |
309 |
|
309 | |||
310 | data_cspc = None |
|
310 | data_cspc = None | |
311 | if self.dataOut.data_cspc is not None: |
|
311 | if self.dataOut.data_cspc is not None: | |
312 | data_cspc = self.dataOut.data_cspc[:,minIndex:maxIndex+1,:] |
|
312 | data_cspc = self.dataOut.data_cspc[:,minIndex:maxIndex+1,:] | |
313 |
|
313 | |||
314 | data_dc = None |
|
314 | data_dc = None | |
315 | if self.dataOut.data_dc is not None: |
|
315 | if self.dataOut.data_dc is not None: | |
316 | data_dc = self.dataOut.data_dc[minIndex:maxIndex+1,:] |
|
316 | data_dc = self.dataOut.data_dc[minIndex:maxIndex+1,:] | |
317 |
|
317 | |||
318 | self.dataOut.data_spc = data_spc |
|
318 | self.dataOut.data_spc = data_spc | |
319 | self.dataOut.data_cspc = data_cspc |
|
319 | self.dataOut.data_cspc = data_cspc | |
320 | self.dataOut.data_dc = data_dc |
|
320 | self.dataOut.data_dc = data_dc | |
321 |
|
321 | |||
322 | self.dataOut.ippSeconds = self.dataOut.ippSeconds*(self.dataOut.nFFTPoints / numpy.shape(data_cspc)[1]) |
|
322 | self.dataOut.ippSeconds = self.dataOut.ippSeconds*(self.dataOut.nFFTPoints / numpy.shape(data_cspc)[1]) | |
323 | self.dataOut.nFFTPoints = numpy.shape(data_cspc)[1] |
|
323 | self.dataOut.nFFTPoints = numpy.shape(data_cspc)[1] | |
324 | self.dataOut.profilesPerBlock = numpy.shape(data_cspc)[1] |
|
324 | self.dataOut.profilesPerBlock = numpy.shape(data_cspc)[1] | |
325 |
|
325 | |||
326 | return 1 |
|
326 | return 1 | |
327 |
|
327 | |||
328 | def getNoise(self, minHei=None, maxHei=None, minVel=None, maxVel=None): |
|
328 | def getNoise(self, minHei=None, maxHei=None, minVel=None, maxVel=None): | |
329 | # validacion de rango |
|
329 | # validacion de rango | |
330 | if minHei == None: |
|
330 | if minHei == None: | |
331 | minHei = self.dataOut.heightList[0] |
|
331 | minHei = self.dataOut.heightList[0] | |
332 |
|
332 | |||
333 | if maxHei == None: |
|
333 | if maxHei == None: | |
334 | maxHei = self.dataOut.heightList[-1] |
|
334 | maxHei = self.dataOut.heightList[-1] | |
335 |
|
335 | |||
336 | if (minHei < self.dataOut.heightList[0]) or (minHei > maxHei): |
|
336 | if (minHei < self.dataOut.heightList[0]) or (minHei > maxHei): | |
337 | print('minHei: %.2f is out of the heights range' % (minHei)) |
|
337 | print('minHei: %.2f is out of the heights range' % (minHei)) | |
338 | print('minHei is setting to %.2f' % (self.dataOut.heightList[0])) |
|
338 | print('minHei is setting to %.2f' % (self.dataOut.heightList[0])) | |
339 | minHei = self.dataOut.heightList[0] |
|
339 | minHei = self.dataOut.heightList[0] | |
340 |
|
340 | |||
341 | if (maxHei > self.dataOut.heightList[-1]) or (maxHei < minHei): |
|
341 | if (maxHei > self.dataOut.heightList[-1]) or (maxHei < minHei): | |
342 | print('maxHei: %.2f is out of the heights range' % (maxHei)) |
|
342 | print('maxHei: %.2f is out of the heights range' % (maxHei)) | |
343 | print('maxHei is setting to %.2f' % (self.dataOut.heightList[-1])) |
|
343 | print('maxHei is setting to %.2f' % (self.dataOut.heightList[-1])) | |
344 | maxHei = self.dataOut.heightList[-1] |
|
344 | maxHei = self.dataOut.heightList[-1] | |
345 |
|
345 | |||
346 | # validacion de velocidades |
|
346 | # validacion de velocidades | |
347 | velrange = self.dataOut.getVelRange(1) |
|
347 | velrange = self.dataOut.getVelRange(1) | |
348 |
|
348 | |||
349 | if minVel == None: |
|
349 | if minVel == None: | |
350 | minVel = velrange[0] |
|
350 | minVel = velrange[0] | |
351 |
|
351 | |||
352 | if maxVel == None: |
|
352 | if maxVel == None: | |
353 | maxVel = velrange[-1] |
|
353 | maxVel = velrange[-1] | |
354 |
|
354 | |||
355 | if (minVel < velrange[0]) or (minVel > maxVel): |
|
355 | if (minVel < velrange[0]) or (minVel > maxVel): | |
356 | print('minVel: %.2f is out of the velocity range' % (minVel)) |
|
356 | print('minVel: %.2f is out of the velocity range' % (minVel)) | |
357 | print('minVel is setting to %.2f' % (velrange[0])) |
|
357 | print('minVel is setting to %.2f' % (velrange[0])) | |
358 | minVel = velrange[0] |
|
358 | minVel = velrange[0] | |
359 |
|
359 | |||
360 | if (maxVel > velrange[-1]) or (maxVel < minVel): |
|
360 | if (maxVel > velrange[-1]) or (maxVel < minVel): | |
361 | print('maxVel: %.2f is out of the velocity range' % (maxVel)) |
|
361 | print('maxVel: %.2f is out of the velocity range' % (maxVel)) | |
362 | print('maxVel is setting to %.2f' % (velrange[-1])) |
|
362 | print('maxVel is setting to %.2f' % (velrange[-1])) | |
363 | maxVel = velrange[-1] |
|
363 | maxVel = velrange[-1] | |
364 |
|
364 | |||
365 | # seleccion de indices para rango |
|
365 | # seleccion de indices para rango | |
366 | minIndex = 0 |
|
366 | minIndex = 0 | |
367 | maxIndex = 0 |
|
367 | maxIndex = 0 | |
368 | heights = self.dataOut.heightList |
|
368 | heights = self.dataOut.heightList | |
369 |
|
369 | |||
370 | inda = numpy.where(heights >= minHei) |
|
370 | inda = numpy.where(heights >= minHei) | |
371 | indb = numpy.where(heights <= maxHei) |
|
371 | indb = numpy.where(heights <= maxHei) | |
372 |
|
372 | |||
373 | try: |
|
373 | try: | |
374 | minIndex = inda[0][0] |
|
374 | minIndex = inda[0][0] | |
375 | except: |
|
375 | except: | |
376 | minIndex = 0 |
|
376 | minIndex = 0 | |
377 |
|
377 | |||
378 | try: |
|
378 | try: | |
379 | maxIndex = indb[0][-1] |
|
379 | maxIndex = indb[0][-1] | |
380 | except: |
|
380 | except: | |
381 | maxIndex = len(heights) |
|
381 | maxIndex = len(heights) | |
382 |
|
382 | |||
383 | if (minIndex < 0) or (minIndex > maxIndex): |
|
383 | if (minIndex < 0) or (minIndex > maxIndex): | |
384 | raise ValueError("some value in (%d,%d) is not valid" % ( |
|
384 | raise ValueError("some value in (%d,%d) is not valid" % ( | |
385 | minIndex, maxIndex)) |
|
385 | minIndex, maxIndex)) | |
386 |
|
386 | |||
387 | if (maxIndex >= self.dataOut.nHeights): |
|
387 | if (maxIndex >= self.dataOut.nHeights): | |
388 | maxIndex = self.dataOut.nHeights - 1 |
|
388 | maxIndex = self.dataOut.nHeights - 1 | |
389 |
|
389 | |||
390 | # seleccion de indices para velocidades |
|
390 | # seleccion de indices para velocidades | |
391 | indminvel = numpy.where(velrange >= minVel) |
|
391 | indminvel = numpy.where(velrange >= minVel) | |
392 | indmaxvel = numpy.where(velrange <= maxVel) |
|
392 | indmaxvel = numpy.where(velrange <= maxVel) | |
393 | try: |
|
393 | try: | |
394 | minIndexVel = indminvel[0][0] |
|
394 | minIndexVel = indminvel[0][0] | |
395 | except: |
|
395 | except: | |
396 | minIndexVel = 0 |
|
396 | minIndexVel = 0 | |
397 |
|
397 | |||
398 | try: |
|
398 | try: | |
399 | maxIndexVel = indmaxvel[0][-1] |
|
399 | maxIndexVel = indmaxvel[0][-1] | |
400 | except: |
|
400 | except: | |
401 | maxIndexVel = len(velrange) |
|
401 | maxIndexVel = len(velrange) | |
402 |
|
402 | |||
403 | # seleccion del espectro |
|
403 | # seleccion del espectro | |
404 | data_spc = self.dataOut.data_spc[:, |
|
404 | data_spc = self.dataOut.data_spc[:, | |
405 | minIndexVel:maxIndexVel + 1, minIndex:maxIndex + 1] |
|
405 | minIndexVel:maxIndexVel + 1, minIndex:maxIndex + 1] | |
406 | # estimacion de ruido |
|
406 | # estimacion de ruido | |
407 | noise = numpy.zeros(self.dataOut.nChannels) |
|
407 | noise = numpy.zeros(self.dataOut.nChannels) | |
408 |
|
408 | |||
409 | for channel in range(self.dataOut.nChannels): |
|
409 | for channel in range(self.dataOut.nChannels): | |
410 | daux = data_spc[channel, :, :] |
|
410 | daux = data_spc[channel, :, :] | |
411 | sortdata = numpy.sort(daux, axis=None) |
|
411 | sortdata = numpy.sort(daux, axis=None) | |
412 | noise[channel] = hildebrand_sekhon(sortdata, self.dataOut.nIncohInt) |
|
412 | noise[channel] = hildebrand_sekhon(sortdata, self.dataOut.nIncohInt) | |
413 |
|
413 | |||
414 | self.dataOut.noise_estimation = noise.copy() |
|
414 | self.dataOut.noise_estimation = noise.copy() | |
415 |
|
415 | |||
416 | return 1 |
|
416 | return 1 | |
417 |
|
417 | |||
418 | class removeDC(Operation): |
|
418 | class removeDC(Operation): | |
419 |
|
419 | |||
420 | def run(self, dataOut, mode=2): |
|
420 | def run(self, dataOut, mode=2): | |
421 | self.dataOut = dataOut |
|
421 | self.dataOut = dataOut | |
422 | jspectra = self.dataOut.data_spc |
|
422 | jspectra = self.dataOut.data_spc | |
423 | jcspectra = self.dataOut.data_cspc |
|
423 | jcspectra = self.dataOut.data_cspc | |
424 |
|
424 | |||
425 | num_chan = jspectra.shape[0] |
|
425 | num_chan = jspectra.shape[0] | |
426 | num_hei = jspectra.shape[2] |
|
426 | num_hei = jspectra.shape[2] | |
427 |
|
427 | |||
428 | if jcspectra is not None: |
|
428 | if jcspectra is not None: | |
429 | jcspectraExist = True |
|
429 | jcspectraExist = True | |
430 | num_pairs = jcspectra.shape[0] |
|
430 | num_pairs = jcspectra.shape[0] | |
431 | else: |
|
431 | else: | |
432 | jcspectraExist = False |
|
432 | jcspectraExist = False | |
433 |
|
433 | |||
434 | freq_dc = int(jspectra.shape[1] / 2) |
|
434 | freq_dc = int(jspectra.shape[1] / 2) | |
435 | ind_vel = numpy.array([-2, -1, 1, 2]) + freq_dc |
|
435 | ind_vel = numpy.array([-2, -1, 1, 2]) + freq_dc | |
436 | ind_vel = ind_vel.astype(int) |
|
436 | ind_vel = ind_vel.astype(int) | |
437 |
|
437 | |||
438 | if ind_vel[0] < 0: |
|
438 | if ind_vel[0] < 0: | |
439 | ind_vel[list(range(0, 1))] = ind_vel[list(range(0, 1))] + self.num_prof |
|
439 | ind_vel[list(range(0, 1))] = ind_vel[list(range(0, 1))] + self.num_prof | |
440 |
|
440 | |||
441 | if mode == 1: |
|
441 | if mode == 1: | |
442 | jspectra[:, freq_dc, :] = ( |
|
442 | jspectra[:, freq_dc, :] = ( | |
443 | jspectra[:, ind_vel[1], :] + jspectra[:, ind_vel[2], :]) / 2 # CORRECCION |
|
443 | jspectra[:, ind_vel[1], :] + jspectra[:, ind_vel[2], :]) / 2 # CORRECCION | |
444 |
|
444 | |||
445 | if jcspectraExist: |
|
445 | if jcspectraExist: | |
446 | jcspectra[:, freq_dc, :] = ( |
|
446 | jcspectra[:, freq_dc, :] = ( | |
447 | jcspectra[:, ind_vel[1], :] + jcspectra[:, ind_vel[2], :]) / 2 |
|
447 | jcspectra[:, ind_vel[1], :] + jcspectra[:, ind_vel[2], :]) / 2 | |
448 |
|
448 | |||
449 | if mode == 2: |
|
449 | if mode == 2: | |
450 |
|
450 | |||
451 | vel = numpy.array([-2, -1, 1, 2]) |
|
451 | vel = numpy.array([-2, -1, 1, 2]) | |
452 | xx = numpy.zeros([4, 4]) |
|
452 | xx = numpy.zeros([4, 4]) | |
453 |
|
453 | |||
454 | for fil in range(4): |
|
454 | for fil in range(4): | |
455 | xx[fil, :] = vel[fil]**numpy.asarray(list(range(4))) |
|
455 | xx[fil, :] = vel[fil]**numpy.asarray(list(range(4))) | |
456 |
|
456 | |||
457 | xx_inv = numpy.linalg.inv(xx) |
|
457 | xx_inv = numpy.linalg.inv(xx) | |
458 | xx_aux = xx_inv[0, :] |
|
458 | xx_aux = xx_inv[0, :] | |
459 |
|
459 | |||
460 | for ich in range(num_chan): |
|
460 | for ich in range(num_chan): | |
461 | yy = jspectra[ich, ind_vel, :] |
|
461 | yy = jspectra[ich, ind_vel, :] | |
462 | jspectra[ich, freq_dc, :] = numpy.dot(xx_aux, yy) |
|
462 | jspectra[ich, freq_dc, :] = numpy.dot(xx_aux, yy) | |
463 |
|
463 | |||
464 | junkid = jspectra[ich, freq_dc, :] <= 0 |
|
464 | junkid = jspectra[ich, freq_dc, :] <= 0 | |
465 | cjunkid = sum(junkid) |
|
465 | cjunkid = sum(junkid) | |
466 |
|
466 | |||
467 | if cjunkid.any(): |
|
467 | if cjunkid.any(): | |
468 | jspectra[ich, freq_dc, junkid.nonzero()] = ( |
|
468 | jspectra[ich, freq_dc, junkid.nonzero()] = ( | |
469 | jspectra[ich, ind_vel[1], junkid] + jspectra[ich, ind_vel[2], junkid]) / 2 |
|
469 | jspectra[ich, ind_vel[1], junkid] + jspectra[ich, ind_vel[2], junkid]) / 2 | |
470 |
|
470 | |||
471 | if jcspectraExist: |
|
471 | if jcspectraExist: | |
472 | for ip in range(num_pairs): |
|
472 | for ip in range(num_pairs): | |
473 | yy = jcspectra[ip, ind_vel, :] |
|
473 | yy = jcspectra[ip, ind_vel, :] | |
474 | jcspectra[ip, freq_dc, :] = numpy.dot(xx_aux, yy) |
|
474 | jcspectra[ip, freq_dc, :] = numpy.dot(xx_aux, yy) | |
475 |
|
475 | |||
476 | self.dataOut.data_spc = jspectra |
|
476 | self.dataOut.data_spc = jspectra | |
477 | self.dataOut.data_cspc = jcspectra |
|
477 | self.dataOut.data_cspc = jcspectra | |
478 |
|
478 | |||
479 | return self.dataOut |
|
479 | return self.dataOut | |
480 |
|
480 | |||
481 | class removeInterference(Operation): |
|
481 | class removeInterference(Operation): | |
482 |
|
482 | |||
483 | def removeInterference2(self): |
|
483 | def removeInterference2(self): | |
484 |
|
484 | |||
485 | cspc = self.dataOut.data_cspc |
|
485 | cspc = self.dataOut.data_cspc | |
486 | spc = self.dataOut.data_spc |
|
486 | spc = self.dataOut.data_spc | |
487 | Heights = numpy.arange(cspc.shape[2]) |
|
487 | Heights = numpy.arange(cspc.shape[2]) | |
488 | realCspc = numpy.abs(cspc) |
|
488 | realCspc = numpy.abs(cspc) | |
489 |
|
489 | |||
490 | for i in range(cspc.shape[0]): |
|
490 | for i in range(cspc.shape[0]): | |
491 | LinePower= numpy.sum(realCspc[i], axis=0) |
|
491 | LinePower= numpy.sum(realCspc[i], axis=0) | |
492 | Threshold = numpy.amax(LinePower)-numpy.sort(LinePower)[len(Heights)-int(len(Heights)*0.1)] |
|
492 | Threshold = numpy.amax(LinePower)-numpy.sort(LinePower)[len(Heights)-int(len(Heights)*0.1)] | |
493 | SelectedHeights = Heights[ numpy.where( LinePower < Threshold ) ] |
|
493 | SelectedHeights = Heights[ numpy.where( LinePower < Threshold ) ] | |
494 | InterferenceSum = numpy.sum( realCspc[i,:,SelectedHeights], axis=0 ) |
|
494 | InterferenceSum = numpy.sum( realCspc[i,:,SelectedHeights], axis=0 ) | |
495 | InterferenceThresholdMin = numpy.sort(InterferenceSum)[int(len(InterferenceSum)*0.98)] |
|
495 | InterferenceThresholdMin = numpy.sort(InterferenceSum)[int(len(InterferenceSum)*0.98)] | |
496 | InterferenceThresholdMax = numpy.sort(InterferenceSum)[int(len(InterferenceSum)*0.99)] |
|
496 | InterferenceThresholdMax = numpy.sort(InterferenceSum)[int(len(InterferenceSum)*0.99)] | |
497 |
|
497 | |||
498 |
|
498 | |||
499 | InterferenceRange = numpy.where( ([InterferenceSum > InterferenceThresholdMin]))# , InterferenceSum < InterferenceThresholdMax]) ) |
|
499 | InterferenceRange = numpy.where( ([InterferenceSum > InterferenceThresholdMin]))# , InterferenceSum < InterferenceThresholdMax]) ) | |
500 | #InterferenceRange = numpy.where( ([InterferenceRange < InterferenceThresholdMax])) |
|
500 | #InterferenceRange = numpy.where( ([InterferenceRange < InterferenceThresholdMax])) | |
501 | if len(InterferenceRange)<int(cspc.shape[1]*0.3): |
|
501 | if len(InterferenceRange)<int(cspc.shape[1]*0.3): | |
502 | cspc[i,InterferenceRange,:] = numpy.NaN |
|
502 | cspc[i,InterferenceRange,:] = numpy.NaN | |
503 |
|
503 | |||
504 | self.dataOut.data_cspc = cspc |
|
504 | self.dataOut.data_cspc = cspc | |
505 |
|
505 | |||
506 | def removeInterference(self, interf = 2, hei_interf = None, nhei_interf = None, offhei_interf = None): |
|
506 | def removeInterference(self, interf = 2, hei_interf = None, nhei_interf = None, offhei_interf = None): | |
507 |
|
507 | |||
508 | jspectra = self.dataOut.data_spc |
|
508 | jspectra = self.dataOut.data_spc | |
509 | jcspectra = self.dataOut.data_cspc |
|
509 | jcspectra = self.dataOut.data_cspc | |
510 | jnoise = self.dataOut.getNoise() |
|
510 | jnoise = self.dataOut.getNoise() | |
511 | num_incoh = self.dataOut.nIncohInt |
|
511 | num_incoh = self.dataOut.nIncohInt | |
512 |
|
512 | |||
513 | num_channel = jspectra.shape[0] |
|
513 | num_channel = jspectra.shape[0] | |
514 | num_prof = jspectra.shape[1] |
|
514 | num_prof = jspectra.shape[1] | |
515 | num_hei = jspectra.shape[2] |
|
515 | num_hei = jspectra.shape[2] | |
516 |
|
516 | |||
517 | # hei_interf |
|
517 | # hei_interf | |
518 | if hei_interf is None: |
|
518 | if hei_interf is None: | |
519 | count_hei = int(num_hei / 2) |
|
519 | count_hei = int(num_hei / 2) | |
520 | hei_interf = numpy.asmatrix(list(range(count_hei))) + num_hei - count_hei |
|
520 | hei_interf = numpy.asmatrix(list(range(count_hei))) + num_hei - count_hei | |
521 | hei_interf = numpy.asarray(hei_interf)[0] |
|
521 | hei_interf = numpy.asarray(hei_interf)[0] | |
522 | # nhei_interf |
|
522 | # nhei_interf | |
523 | if (nhei_interf == None): |
|
523 | if (nhei_interf == None): | |
524 | nhei_interf = 5 |
|
524 | nhei_interf = 5 | |
525 | if (nhei_interf < 1): |
|
525 | if (nhei_interf < 1): | |
526 | nhei_interf = 1 |
|
526 | nhei_interf = 1 | |
527 | if (nhei_interf > count_hei): |
|
527 | if (nhei_interf > count_hei): | |
528 | nhei_interf = count_hei |
|
528 | nhei_interf = count_hei | |
529 | if (offhei_interf == None): |
|
529 | if (offhei_interf == None): | |
530 | offhei_interf = 0 |
|
530 | offhei_interf = 0 | |
531 |
|
531 | |||
532 | ind_hei = list(range(num_hei)) |
|
532 | ind_hei = list(range(num_hei)) | |
533 | # mask_prof = numpy.asarray(range(num_prof - 2)) + 1 |
|
533 | # mask_prof = numpy.asarray(range(num_prof - 2)) + 1 | |
534 | # mask_prof[range(num_prof/2 - 1,len(mask_prof))] += 1 |
|
534 | # mask_prof[range(num_prof/2 - 1,len(mask_prof))] += 1 | |
535 | mask_prof = numpy.asarray(list(range(num_prof))) |
|
535 | mask_prof = numpy.asarray(list(range(num_prof))) | |
536 | num_mask_prof = mask_prof.size |
|
536 | num_mask_prof = mask_prof.size | |
537 | comp_mask_prof = [0, num_prof / 2] |
|
537 | comp_mask_prof = [0, num_prof / 2] | |
538 |
|
538 | |||
539 | # noise_exist: Determina si la variable jnoise ha sido definida y contiene la informacion del ruido de cada canal |
|
539 | # noise_exist: Determina si la variable jnoise ha sido definida y contiene la informacion del ruido de cada canal | |
540 | if (jnoise.size < num_channel or numpy.isnan(jnoise).any()): |
|
540 | if (jnoise.size < num_channel or numpy.isnan(jnoise).any()): | |
541 | jnoise = numpy.nan |
|
541 | jnoise = numpy.nan | |
542 | noise_exist = jnoise[0] < numpy.Inf |
|
542 | noise_exist = jnoise[0] < numpy.Inf | |
543 |
|
543 | |||
544 | # Subrutina de Remocion de la Interferencia |
|
544 | # Subrutina de Remocion de la Interferencia | |
545 | for ich in range(num_channel): |
|
545 | for ich in range(num_channel): | |
546 | # Se ordena los espectros segun su potencia (menor a mayor) |
|
546 | # Se ordena los espectros segun su potencia (menor a mayor) | |
547 | power = jspectra[ich, mask_prof, :] |
|
547 | power = jspectra[ich, mask_prof, :] | |
548 | power = power[:, hei_interf] |
|
548 | power = power[:, hei_interf] | |
549 | power = power.sum(axis=0) |
|
549 | power = power.sum(axis=0) | |
550 | psort = power.ravel().argsort() |
|
550 | psort = power.ravel().argsort() | |
551 |
|
551 | |||
552 | # Se estima la interferencia promedio en los Espectros de Potencia empleando |
|
552 | # Se estima la interferencia promedio en los Espectros de Potencia empleando | |
553 | junkspc_interf = jspectra[ich, :, hei_interf[psort[list(range( |
|
553 | junkspc_interf = jspectra[ich, :, hei_interf[psort[list(range( | |
554 | offhei_interf, nhei_interf + offhei_interf))]]] |
|
554 | offhei_interf, nhei_interf + offhei_interf))]]] | |
555 |
|
555 | |||
556 | if noise_exist: |
|
556 | if noise_exist: | |
557 | # tmp_noise = jnoise[ich] / num_prof |
|
557 | # tmp_noise = jnoise[ich] / num_prof | |
558 | tmp_noise = jnoise[ich] |
|
558 | tmp_noise = jnoise[ich] | |
559 | junkspc_interf = junkspc_interf - tmp_noise |
|
559 | junkspc_interf = junkspc_interf - tmp_noise | |
560 | #junkspc_interf[:,comp_mask_prof] = 0 |
|
560 | #junkspc_interf[:,comp_mask_prof] = 0 | |
561 |
|
561 | |||
562 | jspc_interf = junkspc_interf.sum(axis=0) / nhei_interf |
|
562 | jspc_interf = junkspc_interf.sum(axis=0) / nhei_interf | |
563 | jspc_interf = jspc_interf.transpose() |
|
563 | jspc_interf = jspc_interf.transpose() | |
564 | # Calculando el espectro de interferencia promedio |
|
564 | # Calculando el espectro de interferencia promedio | |
565 | noiseid = numpy.where( |
|
565 | noiseid = numpy.where( | |
566 | jspc_interf <= tmp_noise / numpy.sqrt(num_incoh)) |
|
566 | jspc_interf <= tmp_noise / numpy.sqrt(num_incoh)) | |
567 | noiseid = noiseid[0] |
|
567 | noiseid = noiseid[0] | |
568 | cnoiseid = noiseid.size |
|
568 | cnoiseid = noiseid.size | |
569 | interfid = numpy.where( |
|
569 | interfid = numpy.where( | |
570 | jspc_interf > tmp_noise / numpy.sqrt(num_incoh)) |
|
570 | jspc_interf > tmp_noise / numpy.sqrt(num_incoh)) | |
571 | interfid = interfid[0] |
|
571 | interfid = interfid[0] | |
572 | cinterfid = interfid.size |
|
572 | cinterfid = interfid.size | |
573 |
|
573 | |||
574 | if (cnoiseid > 0): |
|
574 | if (cnoiseid > 0): | |
575 | jspc_interf[noiseid] = 0 |
|
575 | jspc_interf[noiseid] = 0 | |
576 |
|
576 | |||
577 | # Expandiendo los perfiles a limpiar |
|
577 | # Expandiendo los perfiles a limpiar | |
578 | if (cinterfid > 0): |
|
578 | if (cinterfid > 0): | |
579 | new_interfid = ( |
|
579 | new_interfid = ( | |
580 | numpy.r_[interfid - 1, interfid, interfid + 1] + num_prof) % num_prof |
|
580 | numpy.r_[interfid - 1, interfid, interfid + 1] + num_prof) % num_prof | |
581 | new_interfid = numpy.asarray(new_interfid) |
|
581 | new_interfid = numpy.asarray(new_interfid) | |
582 | new_interfid = {x for x in new_interfid} |
|
582 | new_interfid = {x for x in new_interfid} | |
583 | new_interfid = numpy.array(list(new_interfid)) |
|
583 | new_interfid = numpy.array(list(new_interfid)) | |
584 | new_cinterfid = new_interfid.size |
|
584 | new_cinterfid = new_interfid.size | |
585 | else: |
|
585 | else: | |
586 | new_cinterfid = 0 |
|
586 | new_cinterfid = 0 | |
587 |
|
587 | |||
588 | for ip in range(new_cinterfid): |
|
588 | for ip in range(new_cinterfid): | |
589 | ind = junkspc_interf[:, new_interfid[ip]].ravel().argsort() |
|
589 | ind = junkspc_interf[:, new_interfid[ip]].ravel().argsort() | |
590 | jspc_interf[new_interfid[ip] |
|
590 | jspc_interf[new_interfid[ip] | |
591 | ] = junkspc_interf[ind[nhei_interf // 2], new_interfid[ip]] |
|
591 | ] = junkspc_interf[ind[nhei_interf // 2], new_interfid[ip]] | |
592 |
|
592 | |||
593 | jspectra[ich, :, ind_hei] = jspectra[ich, :, |
|
593 | jspectra[ich, :, ind_hei] = jspectra[ich, :, | |
594 | ind_hei] - jspc_interf # Corregir indices |
|
594 | ind_hei] - jspc_interf # Corregir indices | |
595 |
|
595 | |||
596 | # Removiendo la interferencia del punto de mayor interferencia |
|
596 | # Removiendo la interferencia del punto de mayor interferencia | |
597 | ListAux = jspc_interf[mask_prof].tolist() |
|
597 | ListAux = jspc_interf[mask_prof].tolist() | |
598 | maxid = ListAux.index(max(ListAux)) |
|
598 | maxid = ListAux.index(max(ListAux)) | |
599 |
|
599 | |||
600 | if cinterfid > 0: |
|
600 | if cinterfid > 0: | |
601 | for ip in range(cinterfid * (interf == 2) - 1): |
|
601 | for ip in range(cinterfid * (interf == 2) - 1): | |
602 | ind = (jspectra[ich, interfid[ip], :] < tmp_noise * |
|
602 | ind = (jspectra[ich, interfid[ip], :] < tmp_noise * | |
603 | (1 + 1 / numpy.sqrt(num_incoh))).nonzero() |
|
603 | (1 + 1 / numpy.sqrt(num_incoh))).nonzero() | |
604 | cind = len(ind) |
|
604 | cind = len(ind) | |
605 |
|
605 | |||
606 | if (cind > 0): |
|
606 | if (cind > 0): | |
607 | jspectra[ich, interfid[ip], ind] = tmp_noise * \ |
|
607 | jspectra[ich, interfid[ip], ind] = tmp_noise * \ | |
608 | (1 + (numpy.random.uniform(cind) - 0.5) / |
|
608 | (1 + (numpy.random.uniform(cind) - 0.5) / | |
609 | numpy.sqrt(num_incoh)) |
|
609 | numpy.sqrt(num_incoh)) | |
610 |
|
610 | |||
611 | ind = numpy.array([-2, -1, 1, 2]) |
|
611 | ind = numpy.array([-2, -1, 1, 2]) | |
612 | xx = numpy.zeros([4, 4]) |
|
612 | xx = numpy.zeros([4, 4]) | |
613 |
|
613 | |||
614 | for id1 in range(4): |
|
614 | for id1 in range(4): | |
615 | xx[:, id1] = ind[id1]**numpy.asarray(list(range(4))) |
|
615 | xx[:, id1] = ind[id1]**numpy.asarray(list(range(4))) | |
616 |
|
616 | |||
617 | xx_inv = numpy.linalg.inv(xx) |
|
617 | xx_inv = numpy.linalg.inv(xx) | |
618 | xx = xx_inv[:, 0] |
|
618 | xx = xx_inv[:, 0] | |
619 | ind = (ind + maxid + num_mask_prof) % num_mask_prof |
|
619 | ind = (ind + maxid + num_mask_prof) % num_mask_prof | |
620 | yy = jspectra[ich, mask_prof[ind], :] |
|
620 | yy = jspectra[ich, mask_prof[ind], :] | |
621 | jspectra[ich, mask_prof[maxid], :] = numpy.dot( |
|
621 | jspectra[ich, mask_prof[maxid], :] = numpy.dot( | |
622 | yy.transpose(), xx) |
|
622 | yy.transpose(), xx) | |
623 |
|
623 | |||
624 | indAux = (jspectra[ich, :, :] < tmp_noise * |
|
624 | indAux = (jspectra[ich, :, :] < tmp_noise * | |
625 | (1 - 1 / numpy.sqrt(num_incoh))).nonzero() |
|
625 | (1 - 1 / numpy.sqrt(num_incoh))).nonzero() | |
626 | jspectra[ich, indAux[0], indAux[1]] = tmp_noise * \ |
|
626 | jspectra[ich, indAux[0], indAux[1]] = tmp_noise * \ | |
627 | (1 - 1 / numpy.sqrt(num_incoh)) |
|
627 | (1 - 1 / numpy.sqrt(num_incoh)) | |
628 |
|
628 | |||
629 | # Remocion de Interferencia en el Cross Spectra |
|
629 | # Remocion de Interferencia en el Cross Spectra | |
630 | if jcspectra is None: |
|
630 | if jcspectra is None: | |
631 | return jspectra, jcspectra |
|
631 | return jspectra, jcspectra | |
632 | num_pairs = int(jcspectra.size / (num_prof * num_hei)) |
|
632 | num_pairs = int(jcspectra.size / (num_prof * num_hei)) | |
633 | jcspectra = jcspectra.reshape(num_pairs, num_prof, num_hei) |
|
633 | jcspectra = jcspectra.reshape(num_pairs, num_prof, num_hei) | |
634 |
|
634 | |||
635 | for ip in range(num_pairs): |
|
635 | for ip in range(num_pairs): | |
636 |
|
636 | |||
637 | #------------------------------------------- |
|
637 | #------------------------------------------- | |
638 |
|
638 | |||
639 | cspower = numpy.abs(jcspectra[ip, mask_prof, :]) |
|
639 | cspower = numpy.abs(jcspectra[ip, mask_prof, :]) | |
640 | cspower = cspower[:, hei_interf] |
|
640 | cspower = cspower[:, hei_interf] | |
641 | cspower = cspower.sum(axis=0) |
|
641 | cspower = cspower.sum(axis=0) | |
642 |
|
642 | |||
643 | cspsort = cspower.ravel().argsort() |
|
643 | cspsort = cspower.ravel().argsort() | |
644 | junkcspc_interf = jcspectra[ip, :, hei_interf[cspsort[list(range( |
|
644 | junkcspc_interf = jcspectra[ip, :, hei_interf[cspsort[list(range( | |
645 | offhei_interf, nhei_interf + offhei_interf))]]] |
|
645 | offhei_interf, nhei_interf + offhei_interf))]]] | |
646 | junkcspc_interf = junkcspc_interf.transpose() |
|
646 | junkcspc_interf = junkcspc_interf.transpose() | |
647 | jcspc_interf = junkcspc_interf.sum(axis=1) / nhei_interf |
|
647 | jcspc_interf = junkcspc_interf.sum(axis=1) / nhei_interf | |
648 |
|
648 | |||
649 | ind = numpy.abs(jcspc_interf[mask_prof]).ravel().argsort() |
|
649 | ind = numpy.abs(jcspc_interf[mask_prof]).ravel().argsort() | |
650 |
|
650 | |||
651 | median_real = int(numpy.median(numpy.real( |
|
651 | median_real = int(numpy.median(numpy.real( | |
652 | junkcspc_interf[mask_prof[ind[list(range(3 * num_prof // 4))]], :]))) |
|
652 | junkcspc_interf[mask_prof[ind[list(range(3 * num_prof // 4))]], :]))) | |
653 | median_imag = int(numpy.median(numpy.imag( |
|
653 | median_imag = int(numpy.median(numpy.imag( | |
654 | junkcspc_interf[mask_prof[ind[list(range(3 * num_prof // 4))]], :]))) |
|
654 | junkcspc_interf[mask_prof[ind[list(range(3 * num_prof // 4))]], :]))) | |
655 | comp_mask_prof = [int(e) for e in comp_mask_prof] |
|
655 | comp_mask_prof = [int(e) for e in comp_mask_prof] | |
656 | junkcspc_interf[comp_mask_prof, :] = numpy.complex( |
|
656 | junkcspc_interf[comp_mask_prof, :] = numpy.complex( | |
657 | median_real, median_imag) |
|
657 | median_real, median_imag) | |
658 |
|
658 | |||
659 | for iprof in range(num_prof): |
|
659 | for iprof in range(num_prof): | |
660 | ind = numpy.abs(junkcspc_interf[iprof, :]).ravel().argsort() |
|
660 | ind = numpy.abs(junkcspc_interf[iprof, :]).ravel().argsort() | |
661 | jcspc_interf[iprof] = junkcspc_interf[iprof, ind[nhei_interf // 2]] |
|
661 | jcspc_interf[iprof] = junkcspc_interf[iprof, ind[nhei_interf // 2]] | |
662 |
|
662 | |||
663 | # Removiendo la Interferencia |
|
663 | # Removiendo la Interferencia | |
664 | jcspectra[ip, :, ind_hei] = jcspectra[ip, |
|
664 | jcspectra[ip, :, ind_hei] = jcspectra[ip, | |
665 | :, ind_hei] - jcspc_interf |
|
665 | :, ind_hei] - jcspc_interf | |
666 |
|
666 | |||
667 | ListAux = numpy.abs(jcspc_interf[mask_prof]).tolist() |
|
667 | ListAux = numpy.abs(jcspc_interf[mask_prof]).tolist() | |
668 | maxid = ListAux.index(max(ListAux)) |
|
668 | maxid = ListAux.index(max(ListAux)) | |
669 |
|
669 | |||
670 | ind = numpy.array([-2, -1, 1, 2]) |
|
670 | ind = numpy.array([-2, -1, 1, 2]) | |
671 | xx = numpy.zeros([4, 4]) |
|
671 | xx = numpy.zeros([4, 4]) | |
672 |
|
672 | |||
673 | for id1 in range(4): |
|
673 | for id1 in range(4): | |
674 | xx[:, id1] = ind[id1]**numpy.asarray(list(range(4))) |
|
674 | xx[:, id1] = ind[id1]**numpy.asarray(list(range(4))) | |
675 |
|
675 | |||
676 | xx_inv = numpy.linalg.inv(xx) |
|
676 | xx_inv = numpy.linalg.inv(xx) | |
677 | xx = xx_inv[:, 0] |
|
677 | xx = xx_inv[:, 0] | |
678 |
|
678 | |||
679 | ind = (ind + maxid + num_mask_prof) % num_mask_prof |
|
679 | ind = (ind + maxid + num_mask_prof) % num_mask_prof | |
680 | yy = jcspectra[ip, mask_prof[ind], :] |
|
680 | yy = jcspectra[ip, mask_prof[ind], :] | |
681 | jcspectra[ip, mask_prof[maxid], :] = numpy.dot(yy.transpose(), xx) |
|
681 | jcspectra[ip, mask_prof[maxid], :] = numpy.dot(yy.transpose(), xx) | |
682 |
|
682 | |||
683 | # Guardar Resultados |
|
683 | # Guardar Resultados | |
684 | self.dataOut.data_spc = jspectra |
|
684 | self.dataOut.data_spc = jspectra | |
685 | self.dataOut.data_cspc = jcspectra |
|
685 | self.dataOut.data_cspc = jcspectra | |
686 |
|
686 | |||
687 | return 1 |
|
687 | return 1 | |
688 |
|
688 | |||
689 | def run(self, dataOut, interf = 2,hei_interf = None, nhei_interf = None, offhei_interf = None, mode=1): |
|
689 | def run(self, dataOut, interf = 2,hei_interf = None, nhei_interf = None, offhei_interf = None, mode=1): | |
690 |
|
690 | |||
691 | self.dataOut = dataOut |
|
691 | self.dataOut = dataOut | |
692 |
|
692 | |||
693 | if mode == 1: |
|
693 | if mode == 1: | |
694 | self.removeInterference(interf = 2,hei_interf = None, nhei_interf = None, offhei_interf = None) |
|
694 | self.removeInterference(interf = 2,hei_interf = None, nhei_interf = None, offhei_interf = None) | |
695 | elif mode == 2: |
|
695 | elif mode == 2: | |
696 | self.removeInterference2() |
|
696 | self.removeInterference2() | |
697 |
|
697 | |||
698 | return self.dataOut |
|
698 | return self.dataOut | |
699 |
|
699 | |||
700 |
|
700 | |||
701 | class IncohInt(Operation): |
|
701 | class IncohInt(Operation): | |
702 |
|
702 | |||
703 | __profIndex = 0 |
|
703 | __profIndex = 0 | |
704 | __withOverapping = False |
|
704 | __withOverapping = False | |
705 |
|
705 | |||
706 | __byTime = False |
|
706 | __byTime = False | |
707 | __initime = None |
|
707 | __initime = None | |
708 | __lastdatatime = None |
|
708 | __lastdatatime = None | |
709 | __integrationtime = None |
|
709 | __integrationtime = None | |
710 |
|
710 | |||
711 | __buffer_spc = None |
|
711 | __buffer_spc = None | |
712 | __buffer_cspc = None |
|
712 | __buffer_cspc = None | |
713 | __buffer_dc = None |
|
713 | __buffer_dc = None | |
714 |
|
714 | |||
715 | __dataReady = False |
|
715 | __dataReady = False | |
716 |
|
716 | |||
717 | __timeInterval = None |
|
717 | __timeInterval = None | |
718 |
|
718 | |||
719 | n = None |
|
719 | n = None | |
720 |
|
720 | |||
721 | def __init__(self): |
|
721 | def __init__(self): | |
722 |
|
722 | |||
723 | Operation.__init__(self) |
|
723 | Operation.__init__(self) | |
724 |
|
724 | |||
725 | def setup(self, n=None, timeInterval=None, overlapping=False): |
|
725 | def setup(self, n=None, timeInterval=None, overlapping=False): | |
726 | """ |
|
726 | """ | |
727 | Set the parameters of the integration class. |
|
727 | Set the parameters of the integration class. | |
728 |
|
728 | |||
729 | Inputs: |
|
729 | Inputs: | |
730 |
|
730 | |||
731 | n : Number of coherent integrations |
|
731 | n : Number of coherent integrations | |
732 | timeInterval : Time of integration. If the parameter "n" is selected this one does not work |
|
732 | timeInterval : Time of integration. If the parameter "n" is selected this one does not work | |
733 | overlapping : |
|
733 | overlapping : | |
734 |
|
734 | |||
735 | """ |
|
735 | """ | |
736 |
|
736 | |||
737 | self.__initime = None |
|
737 | self.__initime = None | |
738 | self.__lastdatatime = 0 |
|
738 | self.__lastdatatime = 0 | |
739 |
|
739 | |||
740 | self.__buffer_spc = 0 |
|
740 | self.__buffer_spc = 0 | |
741 | self.__buffer_cspc = 0 |
|
741 | self.__buffer_cspc = 0 | |
742 | self.__buffer_dc = 0 |
|
742 | self.__buffer_dc = 0 | |
743 |
|
743 | |||
744 | self.__profIndex = 0 |
|
744 | self.__profIndex = 0 | |
745 | self.__dataReady = False |
|
745 | self.__dataReady = False | |
746 | self.__byTime = False |
|
746 | self.__byTime = False | |
747 |
|
747 | |||
748 | if n is None and timeInterval is None: |
|
748 | if n is None and timeInterval is None: | |
749 | raise ValueError("n or timeInterval should be specified ...") |
|
749 | raise ValueError("n or timeInterval should be specified ...") | |
750 |
|
750 | |||
751 | if n is not None: |
|
751 | if n is not None: | |
752 | self.n = int(n) |
|
752 | self.n = int(n) | |
753 | else: |
|
753 | else: | |
754 |
|
754 | |||
755 | self.__integrationtime = int(timeInterval) |
|
755 | self.__integrationtime = int(timeInterval) | |
756 | self.n = None |
|
756 | self.n = None | |
757 | self.__byTime = True |
|
757 | self.__byTime = True | |
758 |
|
758 | |||
759 | def putData(self, data_spc, data_cspc, data_dc): |
|
759 | def putData(self, data_spc, data_cspc, data_dc): | |
760 | """ |
|
760 | """ | |
761 | Add a profile to the __buffer_spc and increase in one the __profileIndex |
|
761 | Add a profile to the __buffer_spc and increase in one the __profileIndex | |
762 |
|
762 | |||
763 | """ |
|
763 | """ | |
764 |
|
764 | |||
765 | self.__buffer_spc += data_spc |
|
765 | self.__buffer_spc += data_spc | |
766 |
|
766 | |||
767 | if data_cspc is None: |
|
767 | if data_cspc is None: | |
768 | self.__buffer_cspc = None |
|
768 | self.__buffer_cspc = None | |
769 | else: |
|
769 | else: | |
770 | self.__buffer_cspc += data_cspc |
|
770 | self.__buffer_cspc += data_cspc | |
771 |
|
771 | |||
772 | if data_dc is None: |
|
772 | if data_dc is None: | |
773 | self.__buffer_dc = None |
|
773 | self.__buffer_dc = None | |
774 | else: |
|
774 | else: | |
775 | self.__buffer_dc += data_dc |
|
775 | self.__buffer_dc += data_dc | |
776 |
|
776 | |||
777 | self.__profIndex += 1 |
|
777 | self.__profIndex += 1 | |
778 |
|
778 | |||
779 | return |
|
779 | return | |
780 |
|
780 | |||
781 | def pushData(self): |
|
781 | def pushData(self): | |
782 | """ |
|
782 | """ | |
783 | Return the sum of the last profiles and the profiles used in the sum. |
|
783 | Return the sum of the last profiles and the profiles used in the sum. | |
784 |
|
784 | |||
785 | Affected: |
|
785 | Affected: | |
786 |
|
786 | |||
787 | self.__profileIndex |
|
787 | self.__profileIndex | |
788 |
|
788 | |||
789 | """ |
|
789 | """ | |
790 |
|
790 | |||
791 | data_spc = self.__buffer_spc |
|
791 | data_spc = self.__buffer_spc | |
792 | data_cspc = self.__buffer_cspc |
|
792 | data_cspc = self.__buffer_cspc | |
793 | data_dc = self.__buffer_dc |
|
793 | data_dc = self.__buffer_dc | |
794 | n = self.__profIndex |
|
794 | n = self.__profIndex | |
795 |
|
795 | |||
796 | self.__buffer_spc = 0 |
|
796 | self.__buffer_spc = 0 | |
797 | self.__buffer_cspc = 0 |
|
797 | self.__buffer_cspc = 0 | |
798 | self.__buffer_dc = 0 |
|
798 | self.__buffer_dc = 0 | |
799 | self.__profIndex = 0 |
|
799 | self.__profIndex = 0 | |
800 |
|
800 | |||
801 | return data_spc, data_cspc, data_dc, n |
|
801 | return data_spc, data_cspc, data_dc, n | |
802 |
|
802 | |||
803 | def byProfiles(self, *args): |
|
803 | def byProfiles(self, *args): | |
804 |
|
804 | |||
805 | self.__dataReady = False |
|
805 | self.__dataReady = False | |
806 | avgdata_spc = None |
|
806 | avgdata_spc = None | |
807 | avgdata_cspc = None |
|
807 | avgdata_cspc = None | |
808 | avgdata_dc = None |
|
808 | avgdata_dc = None | |
809 |
|
809 | |||
810 | self.putData(*args) |
|
810 | self.putData(*args) | |
811 |
|
811 | |||
812 | if self.__profIndex == self.n: |
|
812 | if self.__profIndex == self.n: | |
813 |
|
813 | |||
814 | avgdata_spc, avgdata_cspc, avgdata_dc, n = self.pushData() |
|
814 | avgdata_spc, avgdata_cspc, avgdata_dc, n = self.pushData() | |
815 | self.n = n |
|
815 | self.n = n | |
816 | self.__dataReady = True |
|
816 | self.__dataReady = True | |
817 |
|
817 | |||
818 | return avgdata_spc, avgdata_cspc, avgdata_dc |
|
818 | return avgdata_spc, avgdata_cspc, avgdata_dc | |
819 |
|
819 | |||
820 | def byTime(self, datatime, *args): |
|
820 | def byTime(self, datatime, *args): | |
821 |
|
821 | |||
822 | self.__dataReady = False |
|
822 | self.__dataReady = False | |
823 | avgdata_spc = None |
|
823 | avgdata_spc = None | |
824 | avgdata_cspc = None |
|
824 | avgdata_cspc = None | |
825 | avgdata_dc = None |
|
825 | avgdata_dc = None | |
826 |
|
826 | |||
827 | self.putData(*args) |
|
827 | self.putData(*args) | |
828 |
|
828 | |||
829 | if (datatime - self.__initime) >= self.__integrationtime: |
|
829 | if (datatime - self.__initime) >= self.__integrationtime: | |
830 | avgdata_spc, avgdata_cspc, avgdata_dc, n = self.pushData() |
|
830 | avgdata_spc, avgdata_cspc, avgdata_dc, n = self.pushData() | |
831 | self.n = n |
|
831 | self.n = n | |
832 | self.__dataReady = True |
|
832 | self.__dataReady = True | |
833 |
|
833 | |||
834 | return avgdata_spc, avgdata_cspc, avgdata_dc |
|
834 | return avgdata_spc, avgdata_cspc, avgdata_dc | |
835 |
|
835 | |||
836 | def integrate(self, datatime, *args): |
|
836 | def integrate(self, datatime, *args): | |
837 |
|
837 | |||
838 | if self.__profIndex == 0: |
|
838 | if self.__profIndex == 0: | |
839 | self.__initime = datatime |
|
839 | self.__initime = datatime | |
840 |
|
840 | |||
841 | if self.__byTime: |
|
841 | if self.__byTime: | |
842 | avgdata_spc, avgdata_cspc, avgdata_dc = self.byTime( |
|
842 | avgdata_spc, avgdata_cspc, avgdata_dc = self.byTime( | |
843 | datatime, *args) |
|
843 | datatime, *args) | |
844 | else: |
|
844 | else: | |
845 | avgdata_spc, avgdata_cspc, avgdata_dc = self.byProfiles(*args) |
|
845 | avgdata_spc, avgdata_cspc, avgdata_dc = self.byProfiles(*args) | |
846 |
|
846 | |||
847 | if not self.__dataReady: |
|
847 | if not self.__dataReady: | |
848 | return None, None, None, None |
|
848 | return None, None, None, None | |
849 |
|
849 | |||
850 | return self.__initime, avgdata_spc, avgdata_cspc, avgdata_dc |
|
850 | return self.__initime, avgdata_spc, avgdata_cspc, avgdata_dc | |
851 |
|
851 | |||
852 | def run(self, dataOut, n=None, timeInterval=None, overlapping=False): |
|
852 | def run(self, dataOut, n=None, timeInterval=None, overlapping=False): | |
853 | if n == 1: |
|
853 | if n == 1: | |
854 | return dataOut |
|
854 | return dataOut | |
855 |
|
855 | |||
856 | dataOut.flagNoData = True |
|
856 | dataOut.flagNoData = True | |
857 |
|
857 | |||
858 | if not self.isConfig: |
|
858 | if not self.isConfig: | |
859 | self.setup(n, timeInterval, overlapping) |
|
859 | self.setup(n, timeInterval, overlapping) | |
860 | self.isConfig = True |
|
860 | self.isConfig = True | |
861 |
|
861 | |||
862 | avgdatatime, avgdata_spc, avgdata_cspc, avgdata_dc = self.integrate(dataOut.utctime, |
|
862 | avgdatatime, avgdata_spc, avgdata_cspc, avgdata_dc = self.integrate(dataOut.utctime, | |
863 | dataOut.data_spc, |
|
863 | dataOut.data_spc, | |
864 | dataOut.data_cspc, |
|
864 | dataOut.data_cspc, | |
865 | dataOut.data_dc) |
|
865 | dataOut.data_dc) | |
866 |
|
866 | |||
867 | if self.__dataReady: |
|
867 | if self.__dataReady: | |
868 |
|
868 | |||
869 | dataOut.data_spc = avgdata_spc |
|
869 | dataOut.data_spc = avgdata_spc | |
870 | dataOut.data_cspc = avgdata_cspc |
|
870 | dataOut.data_cspc = avgdata_cspc | |
871 | dataOut.data_dc = avgdata_dc |
|
871 | dataOut.data_dc = avgdata_dc | |
872 | dataOut.nIncohInt *= self.n |
|
872 | dataOut.nIncohInt *= self.n | |
873 | dataOut.utctime = avgdatatime |
|
873 | dataOut.utctime = avgdatatime | |
874 | dataOut.flagNoData = False |
|
874 | dataOut.flagNoData = False | |
875 |
|
875 | |||
876 | return dataOut No newline at end of file |
|
876 | return dataOut | |
|
877 | ||||
|
878 | class dopplerFlip(Operation): | |||
|
879 | ||||
|
880 | def run(self, dataOut): | |||
|
881 | # arreglo 1: (num_chan, num_profiles, num_heights) | |||
|
882 | self.dataOut = dataOut | |||
|
883 | # JULIA-oblicua, indice 2 | |||
|
884 | # arreglo 2: (num_profiles, num_heights) | |||
|
885 | jspectra = self.dataOut.data_spc[2] | |||
|
886 | jspectra_tmp = numpy.zeros(jspectra.shape) | |||
|
887 | num_profiles = jspectra.shape[0] | |||
|
888 | freq_dc = int(num_profiles / 2) | |||
|
889 | # Flip con for | |||
|
890 | for j in range(num_profiles): | |||
|
891 | jspectra_tmp[num_profiles-j-1]= jspectra[j] | |||
|
892 | # Intercambio perfil de DC con perfil inmediato anterior | |||
|
893 | jspectra_tmp[freq_dc-1]= jspectra[freq_dc-1] | |||
|
894 | jspectra_tmp[freq_dc]= jspectra[freq_dc] | |||
|
895 | # canal modificado es re-escrito en el arreglo de canales | |||
|
896 | self.dataOut.data_spc[2] = jspectra_tmp | |||
|
897 | ||||
|
898 | return self.dataOut No newline at end of file |
@@ -1,1629 +1,1625 | |||||
1 | import sys |
|
1 | import sys | |
2 | import numpy,math |
|
2 | import numpy,math | |
3 | from scipy import interpolate |
|
3 | from scipy import interpolate | |
4 | from schainpy.model.proc.jroproc_base import ProcessingUnit, Operation, MPDecorator |
|
4 | from schainpy.model.proc.jroproc_base import ProcessingUnit, Operation, MPDecorator | |
5 | from schainpy.model.data.jrodata import Voltage,hildebrand_sekhon |
|
5 | from schainpy.model.data.jrodata import Voltage,hildebrand_sekhon | |
6 | from schainpy.utils import log |
|
6 | from schainpy.utils import log | |
7 | from time import time |
|
7 | from time import time | |
8 |
|
8 | |||
9 |
|
9 | |||
10 |
|
10 | |||
11 | class VoltageProc(ProcessingUnit): |
|
11 | class VoltageProc(ProcessingUnit): | |
12 |
|
12 | |||
13 | def __init__(self): |
|
13 | def __init__(self): | |
14 |
|
14 | |||
15 | ProcessingUnit.__init__(self) |
|
15 | ProcessingUnit.__init__(self) | |
16 |
|
16 | |||
17 | self.dataOut = Voltage() |
|
17 | self.dataOut = Voltage() | |
18 | self.flip = 1 |
|
18 | self.flip = 1 | |
19 | self.setupReq = False |
|
19 | self.setupReq = False | |
20 |
|
20 | |||
21 | def run(self): |
|
21 | def run(self): | |
22 |
|
22 | |||
23 | if self.dataIn.type == 'AMISR': |
|
23 | if self.dataIn.type == 'AMISR': | |
24 | self.__updateObjFromAmisrInput() |
|
24 | self.__updateObjFromAmisrInput() | |
25 |
|
25 | |||
26 | if self.dataIn.type == 'Voltage': |
|
26 | if self.dataIn.type == 'Voltage': | |
27 | self.dataOut.copy(self.dataIn) |
|
27 | self.dataOut.copy(self.dataIn) | |
28 |
|
28 | |||
29 | def __updateObjFromAmisrInput(self): |
|
29 | def __updateObjFromAmisrInput(self): | |
30 |
|
30 | |||
31 | self.dataOut.timeZone = self.dataIn.timeZone |
|
31 | self.dataOut.timeZone = self.dataIn.timeZone | |
32 | self.dataOut.dstFlag = self.dataIn.dstFlag |
|
32 | self.dataOut.dstFlag = self.dataIn.dstFlag | |
33 | self.dataOut.errorCount = self.dataIn.errorCount |
|
33 | self.dataOut.errorCount = self.dataIn.errorCount | |
34 | self.dataOut.useLocalTime = self.dataIn.useLocalTime |
|
34 | self.dataOut.useLocalTime = self.dataIn.useLocalTime | |
35 |
|
35 | |||
36 | self.dataOut.flagNoData = self.dataIn.flagNoData |
|
36 | self.dataOut.flagNoData = self.dataIn.flagNoData | |
37 | self.dataOut.data = self.dataIn.data |
|
37 | self.dataOut.data = self.dataIn.data | |
38 | self.dataOut.utctime = self.dataIn.utctime |
|
38 | self.dataOut.utctime = self.dataIn.utctime | |
39 | self.dataOut.channelList = self.dataIn.channelList |
|
39 | self.dataOut.channelList = self.dataIn.channelList | |
40 | #self.dataOut.timeInterval = self.dataIn.timeInterval |
|
40 | #self.dataOut.timeInterval = self.dataIn.timeInterval | |
41 | self.dataOut.heightList = self.dataIn.heightList |
|
41 | self.dataOut.heightList = self.dataIn.heightList | |
42 | self.dataOut.nProfiles = self.dataIn.nProfiles |
|
42 | self.dataOut.nProfiles = self.dataIn.nProfiles | |
43 |
|
43 | |||
44 | self.dataOut.nCohInt = self.dataIn.nCohInt |
|
44 | self.dataOut.nCohInt = self.dataIn.nCohInt | |
45 | self.dataOut.ippSeconds = self.dataIn.ippSeconds |
|
45 | self.dataOut.ippSeconds = self.dataIn.ippSeconds | |
46 | self.dataOut.frequency = self.dataIn.frequency |
|
46 | self.dataOut.frequency = self.dataIn.frequency | |
47 |
|
47 | |||
48 | self.dataOut.azimuth = self.dataIn.azimuth |
|
48 | self.dataOut.azimuth = self.dataIn.azimuth | |
49 | self.dataOut.zenith = self.dataIn.zenith |
|
49 | self.dataOut.zenith = self.dataIn.zenith | |
50 |
|
50 | |||
51 | self.dataOut.beam.codeList = self.dataIn.beam.codeList |
|
51 | self.dataOut.beam.codeList = self.dataIn.beam.codeList | |
52 | self.dataOut.beam.azimuthList = self.dataIn.beam.azimuthList |
|
52 | self.dataOut.beam.azimuthList = self.dataIn.beam.azimuthList | |
53 | self.dataOut.beam.zenithList = self.dataIn.beam.zenithList |
|
53 | self.dataOut.beam.zenithList = self.dataIn.beam.zenithList | |
54 |
|
54 | |||
55 |
|
55 | |||
56 | class selectChannels(Operation): |
|
56 | class selectChannels(Operation): | |
57 |
|
57 | |||
58 | def run(self, dataOut, channelList): |
|
58 | def run(self, dataOut, channelList): | |
59 |
|
59 | |||
60 | channelIndexList = [] |
|
60 | channelIndexList = [] | |
61 | self.dataOut = dataOut |
|
61 | self.dataOut = dataOut | |
62 | for channel in channelList: |
|
62 | for channel in channelList: | |
63 | if channel not in self.dataOut.channelList: |
|
63 | if channel not in self.dataOut.channelList: | |
64 | raise ValueError("Channel %d is not in %s" %(channel, str(self.dataOut.channelList))) |
|
64 | raise ValueError("Channel %d is not in %s" %(channel, str(self.dataOut.channelList))) | |
65 |
|
65 | |||
66 | index = self.dataOut.channelList.index(channel) |
|
66 | index = self.dataOut.channelList.index(channel) | |
67 | channelIndexList.append(index) |
|
67 | channelIndexList.append(index) | |
68 | self.selectChannelsByIndex(channelIndexList) |
|
68 | self.selectChannelsByIndex(channelIndexList) | |
69 | return self.dataOut |
|
69 | return self.dataOut | |
70 |
|
70 | |||
71 | def selectChannelsByIndex(self, channelIndexList): |
|
71 | def selectChannelsByIndex(self, channelIndexList): | |
72 | """ |
|
72 | """ | |
73 | Selecciona un bloque de datos en base a canales segun el channelIndexList |
|
73 | Selecciona un bloque de datos en base a canales segun el channelIndexList | |
74 |
|
74 | |||
75 | Input: |
|
75 | Input: | |
76 | channelIndexList : lista sencilla de canales a seleccionar por ej. [2,3,7] |
|
76 | channelIndexList : lista sencilla de canales a seleccionar por ej. [2,3,7] | |
77 |
|
77 | |||
78 | Affected: |
|
78 | Affected: | |
79 | self.dataOut.data |
|
79 | self.dataOut.data | |
80 | self.dataOut.channelIndexList |
|
80 | self.dataOut.channelIndexList | |
81 | self.dataOut.nChannels |
|
81 | self.dataOut.nChannels | |
82 | self.dataOut.m_ProcessingHeader.totalSpectra |
|
82 | self.dataOut.m_ProcessingHeader.totalSpectra | |
83 | self.dataOut.systemHeaderObj.numChannels |
|
83 | self.dataOut.systemHeaderObj.numChannels | |
84 | self.dataOut.m_ProcessingHeader.blockSize |
|
84 | self.dataOut.m_ProcessingHeader.blockSize | |
85 |
|
85 | |||
86 | Return: |
|
86 | Return: | |
87 | None |
|
87 | None | |
88 | """ |
|
88 | """ | |
89 |
|
89 | |||
90 | for channelIndex in channelIndexList: |
|
90 | for channelIndex in channelIndexList: | |
91 | if channelIndex not in self.dataOut.channelIndexList: |
|
91 | if channelIndex not in self.dataOut.channelIndexList: | |
92 | raise ValueError("The value %d in channelIndexList is not valid" %channelIndex) |
|
92 | raise ValueError("The value %d in channelIndexList is not valid" %channelIndex) | |
93 |
|
93 | |||
94 | if self.dataOut.type == 'Voltage': |
|
94 | if self.dataOut.type == 'Voltage': | |
95 | if self.dataOut.flagDataAsBlock: |
|
95 | if self.dataOut.flagDataAsBlock: | |
96 | """ |
|
96 | """ | |
97 | Si la data es obtenida por bloques, dimension = [nChannels, nProfiles, nHeis] |
|
97 | Si la data es obtenida por bloques, dimension = [nChannels, nProfiles, nHeis] | |
98 | """ |
|
98 | """ | |
99 | data = self.dataOut.data[channelIndexList,:,:] |
|
99 | data = self.dataOut.data[channelIndexList,:,:] | |
100 | else: |
|
100 | else: | |
101 | data = self.dataOut.data[channelIndexList,:] |
|
101 | data = self.dataOut.data[channelIndexList,:] | |
102 |
|
102 | |||
103 | self.dataOut.data = data |
|
103 | self.dataOut.data = data | |
104 | # self.dataOut.channelList = [self.dataOut.channelList[i] for i in channelIndexList] |
|
104 | # self.dataOut.channelList = [self.dataOut.channelList[i] for i in channelIndexList] | |
105 | self.dataOut.channelList = range(len(channelIndexList)) |
|
105 | self.dataOut.channelList = range(len(channelIndexList)) | |
106 |
|
106 | |||
107 | elif self.dataOut.type == 'Spectra': |
|
107 | elif self.dataOut.type == 'Spectra': | |
108 | data_spc = self.dataOut.data_spc[channelIndexList, :] |
|
108 | data_spc = self.dataOut.data_spc[channelIndexList, :] | |
109 | data_dc = self.dataOut.data_dc[channelIndexList, :] |
|
109 | data_dc = self.dataOut.data_dc[channelIndexList, :] | |
110 |
|
110 | |||
111 | self.dataOut.data_spc = data_spc |
|
111 | self.dataOut.data_spc = data_spc | |
112 | self.dataOut.data_dc = data_dc |
|
112 | self.dataOut.data_dc = data_dc | |
113 |
|
113 | |||
114 | # self.dataOut.channelList = [self.dataOut.channelList[i] for i in channelIndexList] |
|
114 | # self.dataOut.channelList = [self.dataOut.channelList[i] for i in channelIndexList] | |
115 | self.dataOut.channelList = range(len(channelIndexList)) |
|
115 | self.dataOut.channelList = range(len(channelIndexList)) | |
116 | self.__selectPairsByChannel(channelIndexList) |
|
116 | self.__selectPairsByChannel(channelIndexList) | |
117 |
|
117 | |||
118 | return 1 |
|
118 | return 1 | |
119 |
|
119 | |||
120 | def __selectPairsByChannel(self, channelList=None): |
|
120 | def __selectPairsByChannel(self, channelList=None): | |
121 |
|
121 | |||
122 | if channelList == None: |
|
122 | if channelList == None: | |
123 | return |
|
123 | return | |
124 |
|
124 | |||
125 | pairsIndexListSelected = [] |
|
125 | pairsIndexListSelected = [] | |
126 | for pairIndex in self.dataOut.pairsIndexList: |
|
126 | for pairIndex in self.dataOut.pairsIndexList: | |
127 | # First pair |
|
127 | # First pair | |
128 | if self.dataOut.pairsList[pairIndex][0] not in channelList: |
|
128 | if self.dataOut.pairsList[pairIndex][0] not in channelList: | |
129 | continue |
|
129 | continue | |
130 | # Second pair |
|
130 | # Second pair | |
131 | if self.dataOut.pairsList[pairIndex][1] not in channelList: |
|
131 | if self.dataOut.pairsList[pairIndex][1] not in channelList: | |
132 | continue |
|
132 | continue | |
133 |
|
133 | |||
134 | pairsIndexListSelected.append(pairIndex) |
|
134 | pairsIndexListSelected.append(pairIndex) | |
135 |
|
135 | |||
136 | if not pairsIndexListSelected: |
|
136 | if not pairsIndexListSelected: | |
137 | self.dataOut.data_cspc = None |
|
137 | self.dataOut.data_cspc = None | |
138 | self.dataOut.pairsList = [] |
|
138 | self.dataOut.pairsList = [] | |
139 | return |
|
139 | return | |
140 |
|
140 | |||
141 | self.dataOut.data_cspc = self.dataOut.data_cspc[pairsIndexListSelected] |
|
141 | self.dataOut.data_cspc = self.dataOut.data_cspc[pairsIndexListSelected] | |
142 | self.dataOut.pairsList = [self.dataOut.pairsList[i] |
|
142 | self.dataOut.pairsList = [self.dataOut.pairsList[i] | |
143 | for i in pairsIndexListSelected] |
|
143 | for i in pairsIndexListSelected] | |
144 |
|
144 | |||
145 | return |
|
145 | return | |
146 |
|
146 | |||
147 | class selectHeights(Operation): |
|
147 | class selectHeights(Operation): | |
148 |
|
148 | |||
149 | def run(self, dataOut, minHei=None, maxHei=None): |
|
149 | def run(self, dataOut, minHei=None, maxHei=None, minIndex=None, maxIndex=None): | |
150 | """ |
|
150 | """ | |
151 | Selecciona un bloque de datos en base a un grupo de valores de alturas segun el rango |
|
151 | Selecciona un bloque de datos en base a un grupo de valores de alturas segun el rango | |
152 | minHei <= height <= maxHei |
|
152 | minHei <= height <= maxHei | |
153 |
|
153 | |||
154 | Input: |
|
154 | Input: | |
155 | minHei : valor minimo de altura a considerar |
|
155 | minHei : valor minimo de altura a considerar | |
156 | maxHei : valor maximo de altura a considerar |
|
156 | maxHei : valor maximo de altura a considerar | |
157 |
|
157 | |||
158 | Affected: |
|
158 | Affected: | |
159 | Indirectamente son cambiados varios valores a travez del metodo selectHeightsByIndex |
|
159 | Indirectamente son cambiados varios valores a travez del metodo selectHeightsByIndex | |
160 |
|
160 | |||
161 | Return: |
|
161 | Return: | |
162 | 1 si el metodo se ejecuto con exito caso contrario devuelve 0 |
|
162 | 1 si el metodo se ejecuto con exito caso contrario devuelve 0 | |
163 | """ |
|
163 | """ | |
164 |
|
164 | |||
165 | self.dataOut = dataOut |
|
165 | self.dataOut = dataOut | |
166 |
|
166 | |||
167 |
if minHei |
|
167 | if minHei and maxHei: | |
168 | minHei = self.dataOut.heightList[0] |
|
|||
169 |
|
168 | |||
170 | if maxHei == None: |
|
169 | if (minHei < self.dataOut.heightList[0]): | |
171 |
|
|
170 | minHei = self.dataOut.heightList[0] | |
172 |
|
171 | |||
173 |
if (m |
|
172 | if (maxHei > self.dataOut.heightList[-1]): | |
174 |
|
|
173 | maxHei = self.dataOut.heightList[-1] | |
175 |
|
174 | |||
176 | if (maxHei > self.dataOut.heightList[-1]): |
|
175 | minIndex = 0 | |
177 | maxHei = self.dataOut.heightList[-1] |
|
176 | maxIndex = 0 | |
178 |
|
177 | heights = self.dataOut.heightList | ||
179 | minIndex = 0 |
|
|||
180 | maxIndex = 0 |
|
|||
181 | heights = self.dataOut.heightList |
|
|||
182 |
|
178 | |||
183 | inda = numpy.where(heights >= minHei) |
|
179 | inda = numpy.where(heights >= minHei) | |
184 | indb = numpy.where(heights <= maxHei) |
|
180 | indb = numpy.where(heights <= maxHei) | |
185 |
|
181 | |||
186 | try: |
|
182 | try: | |
187 | minIndex = inda[0][0] |
|
183 | minIndex = inda[0][0] | |
188 | except: |
|
184 | except: | |
189 | minIndex = 0 |
|
185 | minIndex = 0 | |
190 |
|
186 | |||
191 | try: |
|
187 | try: | |
192 | maxIndex = indb[0][-1] |
|
188 | maxIndex = indb[0][-1] | |
193 | except: |
|
189 | except: | |
194 | maxIndex = len(heights) |
|
190 | maxIndex = len(heights) | |
195 |
|
191 | |||
196 | self.selectHeightsByIndex(minIndex, maxIndex) |
|
192 | self.selectHeightsByIndex(minIndex, maxIndex) | |
197 |
|
193 | |||
198 | return self.dataOut |
|
194 | return self.dataOut | |
199 |
|
195 | |||
200 | def selectHeightsByIndex(self, minIndex, maxIndex): |
|
196 | def selectHeightsByIndex(self, minIndex, maxIndex): | |
201 | """ |
|
197 | """ | |
202 | Selecciona un bloque de datos en base a un grupo indices de alturas segun el rango |
|
198 | Selecciona un bloque de datos en base a un grupo indices de alturas segun el rango | |
203 | minIndex <= index <= maxIndex |
|
199 | minIndex <= index <= maxIndex | |
204 |
|
200 | |||
205 | Input: |
|
201 | Input: | |
206 | minIndex : valor de indice minimo de altura a considerar |
|
202 | minIndex : valor de indice minimo de altura a considerar | |
207 | maxIndex : valor de indice maximo de altura a considerar |
|
203 | maxIndex : valor de indice maximo de altura a considerar | |
208 |
|
204 | |||
209 | Affected: |
|
205 | Affected: | |
210 | self.dataOut.data |
|
206 | self.dataOut.data | |
211 | self.dataOut.heightList |
|
207 | self.dataOut.heightList | |
212 |
|
208 | |||
213 | Return: |
|
209 | Return: | |
214 | 1 si el metodo se ejecuto con exito caso contrario devuelve 0 |
|
210 | 1 si el metodo se ejecuto con exito caso contrario devuelve 0 | |
215 | """ |
|
211 | """ | |
216 |
|
212 | |||
217 | if self.dataOut.type == 'Voltage': |
|
213 | if self.dataOut.type == 'Voltage': | |
218 | if (minIndex < 0) or (minIndex > maxIndex): |
|
214 | if (minIndex < 0) or (minIndex > maxIndex): | |
219 | raise ValueError("Height index range (%d,%d) is not valid" % (minIndex, maxIndex)) |
|
215 | raise ValueError("Height index range (%d,%d) is not valid" % (minIndex, maxIndex)) | |
220 |
|
216 | |||
221 | if (maxIndex >= self.dataOut.nHeights): |
|
217 | if (maxIndex >= self.dataOut.nHeights): | |
222 | maxIndex = self.dataOut.nHeights |
|
218 | maxIndex = self.dataOut.nHeights | |
223 |
|
219 | |||
224 | #voltage |
|
220 | #voltage | |
225 | if self.dataOut.flagDataAsBlock: |
|
221 | if self.dataOut.flagDataAsBlock: | |
226 | """ |
|
222 | """ | |
227 | Si la data es obtenida por bloques, dimension = [nChannels, nProfiles, nHeis] |
|
223 | Si la data es obtenida por bloques, dimension = [nChannels, nProfiles, nHeis] | |
228 | """ |
|
224 | """ | |
229 | data = self.dataOut.data[:,:, minIndex:maxIndex] |
|
225 | data = self.dataOut.data[:,:, minIndex:maxIndex] | |
230 | else: |
|
226 | else: | |
231 | data = self.dataOut.data[:, minIndex:maxIndex] |
|
227 | data = self.dataOut.data[:, minIndex:maxIndex] | |
232 |
|
228 | |||
233 | # firstHeight = self.dataOut.heightList[minIndex] |
|
229 | # firstHeight = self.dataOut.heightList[minIndex] | |
234 |
|
230 | |||
235 | self.dataOut.data = data |
|
231 | self.dataOut.data = data | |
236 | self.dataOut.heightList = self.dataOut.heightList[minIndex:maxIndex] |
|
232 | self.dataOut.heightList = self.dataOut.heightList[minIndex:maxIndex] | |
237 |
|
233 | |||
238 | if self.dataOut.nHeights <= 1: |
|
234 | if self.dataOut.nHeights <= 1: | |
239 | raise ValueError("selectHeights: Too few heights. Current number of heights is %d" %(self.dataOut.nHeights)) |
|
235 | raise ValueError("selectHeights: Too few heights. Current number of heights is %d" %(self.dataOut.nHeights)) | |
240 | elif self.dataOut.type == 'Spectra': |
|
236 | elif self.dataOut.type == 'Spectra': | |
241 | if (minIndex < 0) or (minIndex > maxIndex): |
|
237 | if (minIndex < 0) or (minIndex > maxIndex): | |
242 | raise ValueError("Error selecting heights: Index range (%d,%d) is not valid" % ( |
|
238 | raise ValueError("Error selecting heights: Index range (%d,%d) is not valid" % ( | |
243 | minIndex, maxIndex)) |
|
239 | minIndex, maxIndex)) | |
244 |
|
240 | |||
245 | if (maxIndex >= self.dataOut.nHeights): |
|
241 | if (maxIndex >= self.dataOut.nHeights): | |
246 | maxIndex = self.dataOut.nHeights - 1 |
|
242 | maxIndex = self.dataOut.nHeights - 1 | |
247 |
|
243 | |||
248 | # Spectra |
|
244 | # Spectra | |
249 | data_spc = self.dataOut.data_spc[:, :, minIndex:maxIndex + 1] |
|
245 | data_spc = self.dataOut.data_spc[:, :, minIndex:maxIndex + 1] | |
250 |
|
246 | |||
251 | data_cspc = None |
|
247 | data_cspc = None | |
252 | if self.dataOut.data_cspc is not None: |
|
248 | if self.dataOut.data_cspc is not None: | |
253 | data_cspc = self.dataOut.data_cspc[:, :, minIndex:maxIndex + 1] |
|
249 | data_cspc = self.dataOut.data_cspc[:, :, minIndex:maxIndex + 1] | |
254 |
|
250 | |||
255 | data_dc = None |
|
251 | data_dc = None | |
256 | if self.dataOut.data_dc is not None: |
|
252 | if self.dataOut.data_dc is not None: | |
257 | data_dc = self.dataOut.data_dc[:, minIndex:maxIndex + 1] |
|
253 | data_dc = self.dataOut.data_dc[:, minIndex:maxIndex + 1] | |
258 |
|
254 | |||
259 | self.dataOut.data_spc = data_spc |
|
255 | self.dataOut.data_spc = data_spc | |
260 | self.dataOut.data_cspc = data_cspc |
|
256 | self.dataOut.data_cspc = data_cspc | |
261 | self.dataOut.data_dc = data_dc |
|
257 | self.dataOut.data_dc = data_dc | |
262 |
|
258 | |||
263 | self.dataOut.heightList = self.dataOut.heightList[minIndex:maxIndex + 1] |
|
259 | self.dataOut.heightList = self.dataOut.heightList[minIndex:maxIndex + 1] | |
264 |
|
260 | |||
265 | return 1 |
|
261 | return 1 | |
266 |
|
262 | |||
267 |
|
263 | |||
268 | class filterByHeights(Operation): |
|
264 | class filterByHeights(Operation): | |
269 |
|
265 | |||
270 | def run(self, dataOut, window): |
|
266 | def run(self, dataOut, window): | |
271 |
|
267 | |||
272 | deltaHeight = dataOut.heightList[1] - dataOut.heightList[0] |
|
268 | deltaHeight = dataOut.heightList[1] - dataOut.heightList[0] | |
273 |
|
269 | |||
274 | if window == None: |
|
270 | if window == None: | |
275 | window = (dataOut.radarControllerHeaderObj.txA/dataOut.radarControllerHeaderObj.nBaud) / deltaHeight |
|
271 | window = (dataOut.radarControllerHeaderObj.txA/dataOut.radarControllerHeaderObj.nBaud) / deltaHeight | |
276 |
|
272 | |||
277 | newdelta = deltaHeight * window |
|
273 | newdelta = deltaHeight * window | |
278 | r = dataOut.nHeights % window |
|
274 | r = dataOut.nHeights % window | |
279 | newheights = (dataOut.nHeights-r)/window |
|
275 | newheights = (dataOut.nHeights-r)/window | |
280 |
|
276 | |||
281 | if newheights <= 1: |
|
277 | if newheights <= 1: | |
282 | raise ValueError("filterByHeights: Too few heights. Current number of heights is %d and window is %d" %(dataOut.nHeights, window)) |
|
278 | raise ValueError("filterByHeights: Too few heights. Current number of heights is %d and window is %d" %(dataOut.nHeights, window)) | |
283 |
|
279 | |||
284 | if dataOut.flagDataAsBlock: |
|
280 | if dataOut.flagDataAsBlock: | |
285 | """ |
|
281 | """ | |
286 | Si la data es obtenida por bloques, dimension = [nChannels, nProfiles, nHeis] |
|
282 | Si la data es obtenida por bloques, dimension = [nChannels, nProfiles, nHeis] | |
287 | """ |
|
283 | """ | |
288 | buffer = dataOut.data[:, :, 0:int(dataOut.nHeights-r)] |
|
284 | buffer = dataOut.data[:, :, 0:int(dataOut.nHeights-r)] | |
289 | buffer = buffer.reshape(dataOut.nChannels, dataOut.nProfiles, int(dataOut.nHeights/window), window) |
|
285 | buffer = buffer.reshape(dataOut.nChannels, dataOut.nProfiles, int(dataOut.nHeights/window), window) | |
290 | buffer = numpy.sum(buffer,3) |
|
286 | buffer = numpy.sum(buffer,3) | |
291 |
|
287 | |||
292 | else: |
|
288 | else: | |
293 | buffer = dataOut.data[:,0:int(dataOut.nHeights-r)] |
|
289 | buffer = dataOut.data[:,0:int(dataOut.nHeights-r)] | |
294 | buffer = buffer.reshape(dataOut.nChannels,int(dataOut.nHeights/window),int(window)) |
|
290 | buffer = buffer.reshape(dataOut.nChannels,int(dataOut.nHeights/window),int(window)) | |
295 | buffer = numpy.sum(buffer,2) |
|
291 | buffer = numpy.sum(buffer,2) | |
296 |
|
292 | |||
297 | dataOut.data = buffer |
|
293 | dataOut.data = buffer | |
298 | dataOut.heightList = dataOut.heightList[0] + numpy.arange( newheights )*newdelta |
|
294 | dataOut.heightList = dataOut.heightList[0] + numpy.arange( newheights )*newdelta | |
299 | dataOut.windowOfFilter = window |
|
295 | dataOut.windowOfFilter = window | |
300 |
|
296 | |||
301 | return dataOut |
|
297 | return dataOut | |
302 |
|
298 | |||
303 |
|
299 | |||
304 | class setH0(Operation): |
|
300 | class setH0(Operation): | |
305 |
|
301 | |||
306 | def run(self, dataOut, h0, deltaHeight = None): |
|
302 | def run(self, dataOut, h0, deltaHeight = None): | |
307 |
|
303 | |||
308 | if not deltaHeight: |
|
304 | if not deltaHeight: | |
309 | deltaHeight = dataOut.heightList[1] - dataOut.heightList[0] |
|
305 | deltaHeight = dataOut.heightList[1] - dataOut.heightList[0] | |
310 |
|
306 | |||
311 | nHeights = dataOut.nHeights |
|
307 | nHeights = dataOut.nHeights | |
312 |
|
308 | |||
313 | newHeiRange = h0 + numpy.arange(nHeights)*deltaHeight |
|
309 | newHeiRange = h0 + numpy.arange(nHeights)*deltaHeight | |
314 |
|
310 | |||
315 | dataOut.heightList = newHeiRange |
|
311 | dataOut.heightList = newHeiRange | |
316 |
|
312 | |||
317 | return dataOut |
|
313 | return dataOut | |
318 |
|
314 | |||
319 |
|
315 | |||
320 | class deFlip(Operation): |
|
316 | class deFlip(Operation): | |
321 |
|
317 | |||
322 | def run(self, dataOut, channelList = []): |
|
318 | def run(self, dataOut, channelList = []): | |
323 |
|
319 | |||
324 | data = dataOut.data.copy() |
|
320 | data = dataOut.data.copy() | |
325 |
|
321 | |||
326 | if dataOut.flagDataAsBlock: |
|
322 | if dataOut.flagDataAsBlock: | |
327 | flip = self.flip |
|
323 | flip = self.flip | |
328 | profileList = list(range(dataOut.nProfiles)) |
|
324 | profileList = list(range(dataOut.nProfiles)) | |
329 |
|
325 | |||
330 | if not channelList: |
|
326 | if not channelList: | |
331 | for thisProfile in profileList: |
|
327 | for thisProfile in profileList: | |
332 | data[:,thisProfile,:] = data[:,thisProfile,:]*flip |
|
328 | data[:,thisProfile,:] = data[:,thisProfile,:]*flip | |
333 | flip *= -1.0 |
|
329 | flip *= -1.0 | |
334 | else: |
|
330 | else: | |
335 | for thisChannel in channelList: |
|
331 | for thisChannel in channelList: | |
336 | if thisChannel not in dataOut.channelList: |
|
332 | if thisChannel not in dataOut.channelList: | |
337 | continue |
|
333 | continue | |
338 |
|
334 | |||
339 | for thisProfile in profileList: |
|
335 | for thisProfile in profileList: | |
340 | data[thisChannel,thisProfile,:] = data[thisChannel,thisProfile,:]*flip |
|
336 | data[thisChannel,thisProfile,:] = data[thisChannel,thisProfile,:]*flip | |
341 | flip *= -1.0 |
|
337 | flip *= -1.0 | |
342 |
|
338 | |||
343 | self.flip = flip |
|
339 | self.flip = flip | |
344 |
|
340 | |||
345 | else: |
|
341 | else: | |
346 | if not channelList: |
|
342 | if not channelList: | |
347 | data[:,:] = data[:,:]*self.flip |
|
343 | data[:,:] = data[:,:]*self.flip | |
348 | else: |
|
344 | else: | |
349 | for thisChannel in channelList: |
|
345 | for thisChannel in channelList: | |
350 | if thisChannel not in dataOut.channelList: |
|
346 | if thisChannel not in dataOut.channelList: | |
351 | continue |
|
347 | continue | |
352 |
|
348 | |||
353 | data[thisChannel,:] = data[thisChannel,:]*self.flip |
|
349 | data[thisChannel,:] = data[thisChannel,:]*self.flip | |
354 |
|
350 | |||
355 | self.flip *= -1. |
|
351 | self.flip *= -1. | |
356 |
|
352 | |||
357 | dataOut.data = data |
|
353 | dataOut.data = data | |
358 |
|
354 | |||
359 | return dataOut |
|
355 | return dataOut | |
360 |
|
356 | |||
361 |
|
357 | |||
362 | class setAttribute(Operation): |
|
358 | class setAttribute(Operation): | |
363 | ''' |
|
359 | ''' | |
364 | Set an arbitrary attribute(s) to dataOut |
|
360 | Set an arbitrary attribute(s) to dataOut | |
365 | ''' |
|
361 | ''' | |
366 |
|
362 | |||
367 | def __init__(self): |
|
363 | def __init__(self): | |
368 |
|
364 | |||
369 | Operation.__init__(self) |
|
365 | Operation.__init__(self) | |
370 | self._ready = False |
|
366 | self._ready = False | |
371 |
|
367 | |||
372 | def run(self, dataOut, **kwargs): |
|
368 | def run(self, dataOut, **kwargs): | |
373 |
|
369 | |||
374 | for key, value in kwargs.items(): |
|
370 | for key, value in kwargs.items(): | |
375 | setattr(dataOut, key, value) |
|
371 | setattr(dataOut, key, value) | |
376 |
|
372 | |||
377 | return dataOut |
|
373 | return dataOut | |
378 |
|
374 | |||
379 |
|
375 | |||
380 | @MPDecorator |
|
376 | @MPDecorator | |
381 | class printAttribute(Operation): |
|
377 | class printAttribute(Operation): | |
382 | ''' |
|
378 | ''' | |
383 | Print an arbitrary attribute of dataOut |
|
379 | Print an arbitrary attribute of dataOut | |
384 | ''' |
|
380 | ''' | |
385 |
|
381 | |||
386 | def __init__(self): |
|
382 | def __init__(self): | |
387 |
|
383 | |||
388 | Operation.__init__(self) |
|
384 | Operation.__init__(self) | |
389 |
|
385 | |||
390 | def run(self, dataOut, attributes): |
|
386 | def run(self, dataOut, attributes): | |
391 |
|
387 | |||
392 | if isinstance(attributes, str): |
|
388 | if isinstance(attributes, str): | |
393 | attributes = [attributes] |
|
389 | attributes = [attributes] | |
394 | for attr in attributes: |
|
390 | for attr in attributes: | |
395 | if hasattr(dataOut, attr): |
|
391 | if hasattr(dataOut, attr): | |
396 | log.log(getattr(dataOut, attr), attr) |
|
392 | log.log(getattr(dataOut, attr), attr) | |
397 |
|
393 | |||
398 |
|
394 | |||
399 | class interpolateHeights(Operation): |
|
395 | class interpolateHeights(Operation): | |
400 |
|
396 | |||
401 | def run(self, dataOut, topLim, botLim): |
|
397 | def run(self, dataOut, topLim, botLim): | |
402 | #69 al 72 para julia |
|
398 | #69 al 72 para julia | |
403 | #82-84 para meteoros |
|
399 | #82-84 para meteoros | |
404 | if len(numpy.shape(dataOut.data))==2: |
|
400 | if len(numpy.shape(dataOut.data))==2: | |
405 | sampInterp = (dataOut.data[:,botLim-1] + dataOut.data[:,topLim+1])/2 |
|
401 | sampInterp = (dataOut.data[:,botLim-1] + dataOut.data[:,topLim+1])/2 | |
406 | sampInterp = numpy.transpose(numpy.tile(sampInterp,(topLim-botLim + 1,1))) |
|
402 | sampInterp = numpy.transpose(numpy.tile(sampInterp,(topLim-botLim + 1,1))) | |
407 | #dataOut.data[:,botLim:limSup+1] = sampInterp |
|
403 | #dataOut.data[:,botLim:limSup+1] = sampInterp | |
408 | dataOut.data[:,botLim:topLim+1] = sampInterp |
|
404 | dataOut.data[:,botLim:topLim+1] = sampInterp | |
409 | else: |
|
405 | else: | |
410 | nHeights = dataOut.data.shape[2] |
|
406 | nHeights = dataOut.data.shape[2] | |
411 | x = numpy.hstack((numpy.arange(botLim),numpy.arange(topLim+1,nHeights))) |
|
407 | x = numpy.hstack((numpy.arange(botLim),numpy.arange(topLim+1,nHeights))) | |
412 | y = dataOut.data[:,:,list(range(botLim))+list(range(topLim+1,nHeights))] |
|
408 | y = dataOut.data[:,:,list(range(botLim))+list(range(topLim+1,nHeights))] | |
413 | f = interpolate.interp1d(x, y, axis = 2) |
|
409 | f = interpolate.interp1d(x, y, axis = 2) | |
414 | xnew = numpy.arange(botLim,topLim+1) |
|
410 | xnew = numpy.arange(botLim,topLim+1) | |
415 | ynew = f(xnew) |
|
411 | ynew = f(xnew) | |
416 | dataOut.data[:,:,botLim:topLim+1] = ynew |
|
412 | dataOut.data[:,:,botLim:topLim+1] = ynew | |
417 |
|
413 | |||
418 | return dataOut |
|
414 | return dataOut | |
419 |
|
415 | |||
420 |
|
416 | |||
421 | class CohInt(Operation): |
|
417 | class CohInt(Operation): | |
422 |
|
418 | |||
423 | isConfig = False |
|
419 | isConfig = False | |
424 | __profIndex = 0 |
|
420 | __profIndex = 0 | |
425 | __byTime = False |
|
421 | __byTime = False | |
426 | __initime = None |
|
422 | __initime = None | |
427 | __lastdatatime = None |
|
423 | __lastdatatime = None | |
428 | __integrationtime = None |
|
424 | __integrationtime = None | |
429 | __buffer = None |
|
425 | __buffer = None | |
430 | __bufferStride = [] |
|
426 | __bufferStride = [] | |
431 | __dataReady = False |
|
427 | __dataReady = False | |
432 | __profIndexStride = 0 |
|
428 | __profIndexStride = 0 | |
433 | __dataToPutStride = False |
|
429 | __dataToPutStride = False | |
434 | n = None |
|
430 | n = None | |
435 |
|
431 | |||
436 | def __init__(self, **kwargs): |
|
432 | def __init__(self, **kwargs): | |
437 |
|
433 | |||
438 | Operation.__init__(self, **kwargs) |
|
434 | Operation.__init__(self, **kwargs) | |
439 |
|
435 | |||
440 | def setup(self, n=None, timeInterval=None, stride=None, overlapping=False, byblock=False): |
|
436 | def setup(self, n=None, timeInterval=None, stride=None, overlapping=False, byblock=False): | |
441 | """ |
|
437 | """ | |
442 | Set the parameters of the integration class. |
|
438 | Set the parameters of the integration class. | |
443 |
|
439 | |||
444 | Inputs: |
|
440 | Inputs: | |
445 |
|
441 | |||
446 | n : Number of coherent integrations |
|
442 | n : Number of coherent integrations | |
447 | timeInterval : Time of integration. If the parameter "n" is selected this one does not work |
|
443 | timeInterval : Time of integration. If the parameter "n" is selected this one does not work | |
448 | overlapping : |
|
444 | overlapping : | |
449 | """ |
|
445 | """ | |
450 |
|
446 | |||
451 | self.__initime = None |
|
447 | self.__initime = None | |
452 | self.__lastdatatime = 0 |
|
448 | self.__lastdatatime = 0 | |
453 | self.__buffer = None |
|
449 | self.__buffer = None | |
454 | self.__dataReady = False |
|
450 | self.__dataReady = False | |
455 | self.byblock = byblock |
|
451 | self.byblock = byblock | |
456 | self.stride = stride |
|
452 | self.stride = stride | |
457 |
|
453 | |||
458 | if n == None and timeInterval == None: |
|
454 | if n == None and timeInterval == None: | |
459 | raise ValueError("n or timeInterval should be specified ...") |
|
455 | raise ValueError("n or timeInterval should be specified ...") | |
460 |
|
456 | |||
461 | if n != None: |
|
457 | if n != None: | |
462 | self.n = n |
|
458 | self.n = n | |
463 | self.__byTime = False |
|
459 | self.__byTime = False | |
464 | else: |
|
460 | else: | |
465 | self.__integrationtime = timeInterval #* 60. #if (type(timeInterval)!=integer) -> change this line |
|
461 | self.__integrationtime = timeInterval #* 60. #if (type(timeInterval)!=integer) -> change this line | |
466 | self.n = 9999 |
|
462 | self.n = 9999 | |
467 | self.__byTime = True |
|
463 | self.__byTime = True | |
468 |
|
464 | |||
469 | if overlapping: |
|
465 | if overlapping: | |
470 | self.__withOverlapping = True |
|
466 | self.__withOverlapping = True | |
471 | self.__buffer = None |
|
467 | self.__buffer = None | |
472 | else: |
|
468 | else: | |
473 | self.__withOverlapping = False |
|
469 | self.__withOverlapping = False | |
474 | self.__buffer = 0 |
|
470 | self.__buffer = 0 | |
475 |
|
471 | |||
476 | self.__profIndex = 0 |
|
472 | self.__profIndex = 0 | |
477 |
|
473 | |||
478 | def putData(self, data): |
|
474 | def putData(self, data): | |
479 |
|
475 | |||
480 | """ |
|
476 | """ | |
481 | Add a profile to the __buffer and increase in one the __profileIndex |
|
477 | Add a profile to the __buffer and increase in one the __profileIndex | |
482 |
|
478 | |||
483 | """ |
|
479 | """ | |
484 |
|
480 | |||
485 | if not self.__withOverlapping: |
|
481 | if not self.__withOverlapping: | |
486 | self.__buffer += data.copy() |
|
482 | self.__buffer += data.copy() | |
487 | self.__profIndex += 1 |
|
483 | self.__profIndex += 1 | |
488 | return |
|
484 | return | |
489 |
|
485 | |||
490 | #Overlapping data |
|
486 | #Overlapping data | |
491 | nChannels, nHeis = data.shape |
|
487 | nChannels, nHeis = data.shape | |
492 | data = numpy.reshape(data, (1, nChannels, nHeis)) |
|
488 | data = numpy.reshape(data, (1, nChannels, nHeis)) | |
493 |
|
489 | |||
494 | #If the buffer is empty then it takes the data value |
|
490 | #If the buffer is empty then it takes the data value | |
495 | if self.__buffer is None: |
|
491 | if self.__buffer is None: | |
496 | self.__buffer = data |
|
492 | self.__buffer = data | |
497 | self.__profIndex += 1 |
|
493 | self.__profIndex += 1 | |
498 | return |
|
494 | return | |
499 |
|
495 | |||
500 | #If the buffer length is lower than n then stakcing the data value |
|
496 | #If the buffer length is lower than n then stakcing the data value | |
501 | if self.__profIndex < self.n: |
|
497 | if self.__profIndex < self.n: | |
502 | self.__buffer = numpy.vstack((self.__buffer, data)) |
|
498 | self.__buffer = numpy.vstack((self.__buffer, data)) | |
503 | self.__profIndex += 1 |
|
499 | self.__profIndex += 1 | |
504 | return |
|
500 | return | |
505 |
|
501 | |||
506 | #If the buffer length is equal to n then replacing the last buffer value with the data value |
|
502 | #If the buffer length is equal to n then replacing the last buffer value with the data value | |
507 | self.__buffer = numpy.roll(self.__buffer, -1, axis=0) |
|
503 | self.__buffer = numpy.roll(self.__buffer, -1, axis=0) | |
508 | self.__buffer[self.n-1] = data |
|
504 | self.__buffer[self.n-1] = data | |
509 | self.__profIndex = self.n |
|
505 | self.__profIndex = self.n | |
510 | return |
|
506 | return | |
511 |
|
507 | |||
512 |
|
508 | |||
513 | def pushData(self): |
|
509 | def pushData(self): | |
514 | """ |
|
510 | """ | |
515 | Return the sum of the last profiles and the profiles used in the sum. |
|
511 | Return the sum of the last profiles and the profiles used in the sum. | |
516 |
|
512 | |||
517 | Affected: |
|
513 | Affected: | |
518 |
|
514 | |||
519 | self.__profileIndex |
|
515 | self.__profileIndex | |
520 |
|
516 | |||
521 | """ |
|
517 | """ | |
522 |
|
518 | |||
523 | if not self.__withOverlapping: |
|
519 | if not self.__withOverlapping: | |
524 | data = self.__buffer |
|
520 | data = self.__buffer | |
525 | n = self.__profIndex |
|
521 | n = self.__profIndex | |
526 |
|
522 | |||
527 | self.__buffer = 0 |
|
523 | self.__buffer = 0 | |
528 | self.__profIndex = 0 |
|
524 | self.__profIndex = 0 | |
529 |
|
525 | |||
530 | return data, n |
|
526 | return data, n | |
531 |
|
527 | |||
532 | #Integration with Overlapping |
|
528 | #Integration with Overlapping | |
533 | data = numpy.sum(self.__buffer, axis=0) |
|
529 | data = numpy.sum(self.__buffer, axis=0) | |
534 | # print data |
|
530 | # print data | |
535 | # raise |
|
531 | # raise | |
536 | n = self.__profIndex |
|
532 | n = self.__profIndex | |
537 |
|
533 | |||
538 | return data, n |
|
534 | return data, n | |
539 |
|
535 | |||
540 | def byProfiles(self, data): |
|
536 | def byProfiles(self, data): | |
541 |
|
537 | |||
542 | self.__dataReady = False |
|
538 | self.__dataReady = False | |
543 | avgdata = None |
|
539 | avgdata = None | |
544 | # n = None |
|
540 | # n = None | |
545 | # print data |
|
541 | # print data | |
546 | # raise |
|
542 | # raise | |
547 | self.putData(data) |
|
543 | self.putData(data) | |
548 |
|
544 | |||
549 | if self.__profIndex == self.n: |
|
545 | if self.__profIndex == self.n: | |
550 | avgdata, n = self.pushData() |
|
546 | avgdata, n = self.pushData() | |
551 | self.__dataReady = True |
|
547 | self.__dataReady = True | |
552 |
|
548 | |||
553 | return avgdata |
|
549 | return avgdata | |
554 |
|
550 | |||
555 | def byTime(self, data, datatime): |
|
551 | def byTime(self, data, datatime): | |
556 |
|
552 | |||
557 | self.__dataReady = False |
|
553 | self.__dataReady = False | |
558 | avgdata = None |
|
554 | avgdata = None | |
559 | n = None |
|
555 | n = None | |
560 |
|
556 | |||
561 | self.putData(data) |
|
557 | self.putData(data) | |
562 |
|
558 | |||
563 | if (datatime - self.__initime) >= self.__integrationtime: |
|
559 | if (datatime - self.__initime) >= self.__integrationtime: | |
564 | avgdata, n = self.pushData() |
|
560 | avgdata, n = self.pushData() | |
565 | self.n = n |
|
561 | self.n = n | |
566 | self.__dataReady = True |
|
562 | self.__dataReady = True | |
567 |
|
563 | |||
568 | return avgdata |
|
564 | return avgdata | |
569 |
|
565 | |||
570 | def integrateByStride(self, data, datatime): |
|
566 | def integrateByStride(self, data, datatime): | |
571 | # print data |
|
567 | # print data | |
572 | if self.__profIndex == 0: |
|
568 | if self.__profIndex == 0: | |
573 | self.__buffer = [[data.copy(), datatime]] |
|
569 | self.__buffer = [[data.copy(), datatime]] | |
574 | else: |
|
570 | else: | |
575 | self.__buffer.append([data.copy(),datatime]) |
|
571 | self.__buffer.append([data.copy(),datatime]) | |
576 | self.__profIndex += 1 |
|
572 | self.__profIndex += 1 | |
577 | self.__dataReady = False |
|
573 | self.__dataReady = False | |
578 |
|
574 | |||
579 | if self.__profIndex == self.n * self.stride : |
|
575 | if self.__profIndex == self.n * self.stride : | |
580 | self.__dataToPutStride = True |
|
576 | self.__dataToPutStride = True | |
581 | self.__profIndexStride = 0 |
|
577 | self.__profIndexStride = 0 | |
582 | self.__profIndex = 0 |
|
578 | self.__profIndex = 0 | |
583 | self.__bufferStride = [] |
|
579 | self.__bufferStride = [] | |
584 | for i in range(self.stride): |
|
580 | for i in range(self.stride): | |
585 | current = self.__buffer[i::self.stride] |
|
581 | current = self.__buffer[i::self.stride] | |
586 | data = numpy.sum([t[0] for t in current], axis=0) |
|
582 | data = numpy.sum([t[0] for t in current], axis=0) | |
587 | avgdatatime = numpy.average([t[1] for t in current]) |
|
583 | avgdatatime = numpy.average([t[1] for t in current]) | |
588 | # print data |
|
584 | # print data | |
589 | self.__bufferStride.append((data, avgdatatime)) |
|
585 | self.__bufferStride.append((data, avgdatatime)) | |
590 |
|
586 | |||
591 | if self.__dataToPutStride: |
|
587 | if self.__dataToPutStride: | |
592 | self.__dataReady = True |
|
588 | self.__dataReady = True | |
593 | self.__profIndexStride += 1 |
|
589 | self.__profIndexStride += 1 | |
594 | if self.__profIndexStride == self.stride: |
|
590 | if self.__profIndexStride == self.stride: | |
595 | self.__dataToPutStride = False |
|
591 | self.__dataToPutStride = False | |
596 | # print self.__bufferStride[self.__profIndexStride - 1] |
|
592 | # print self.__bufferStride[self.__profIndexStride - 1] | |
597 | # raise |
|
593 | # raise | |
598 | return self.__bufferStride[self.__profIndexStride - 1] |
|
594 | return self.__bufferStride[self.__profIndexStride - 1] | |
599 |
|
595 | |||
600 |
|
596 | |||
601 | return None, None |
|
597 | return None, None | |
602 |
|
598 | |||
603 | def integrate(self, data, datatime=None): |
|
599 | def integrate(self, data, datatime=None): | |
604 |
|
600 | |||
605 | if self.__initime == None: |
|
601 | if self.__initime == None: | |
606 | self.__initime = datatime |
|
602 | self.__initime = datatime | |
607 |
|
603 | |||
608 | if self.__byTime: |
|
604 | if self.__byTime: | |
609 | avgdata = self.byTime(data, datatime) |
|
605 | avgdata = self.byTime(data, datatime) | |
610 | else: |
|
606 | else: | |
611 | avgdata = self.byProfiles(data) |
|
607 | avgdata = self.byProfiles(data) | |
612 |
|
608 | |||
613 |
|
609 | |||
614 | self.__lastdatatime = datatime |
|
610 | self.__lastdatatime = datatime | |
615 |
|
611 | |||
616 | if avgdata is None: |
|
612 | if avgdata is None: | |
617 | return None, None |
|
613 | return None, None | |
618 |
|
614 | |||
619 | avgdatatime = self.__initime |
|
615 | avgdatatime = self.__initime | |
620 |
|
616 | |||
621 | deltatime = datatime - self.__lastdatatime |
|
617 | deltatime = datatime - self.__lastdatatime | |
622 |
|
618 | |||
623 | if not self.__withOverlapping: |
|
619 | if not self.__withOverlapping: | |
624 | self.__initime = datatime |
|
620 | self.__initime = datatime | |
625 | else: |
|
621 | else: | |
626 | self.__initime += deltatime |
|
622 | self.__initime += deltatime | |
627 |
|
623 | |||
628 | return avgdata, avgdatatime |
|
624 | return avgdata, avgdatatime | |
629 |
|
625 | |||
630 | def integrateByBlock(self, dataOut): |
|
626 | def integrateByBlock(self, dataOut): | |
631 |
|
627 | |||
632 | times = int(dataOut.data.shape[1]/self.n) |
|
628 | times = int(dataOut.data.shape[1]/self.n) | |
633 | avgdata = numpy.zeros((dataOut.nChannels, times, dataOut.nHeights), dtype=numpy.complex) |
|
629 | avgdata = numpy.zeros((dataOut.nChannels, times, dataOut.nHeights), dtype=numpy.complex) | |
634 |
|
630 | |||
635 | id_min = 0 |
|
631 | id_min = 0 | |
636 | id_max = self.n |
|
632 | id_max = self.n | |
637 |
|
633 | |||
638 | for i in range(times): |
|
634 | for i in range(times): | |
639 | junk = dataOut.data[:,id_min:id_max,:] |
|
635 | junk = dataOut.data[:,id_min:id_max,:] | |
640 | avgdata[:,i,:] = junk.sum(axis=1) |
|
636 | avgdata[:,i,:] = junk.sum(axis=1) | |
641 | id_min += self.n |
|
637 | id_min += self.n | |
642 | id_max += self.n |
|
638 | id_max += self.n | |
643 |
|
639 | |||
644 | timeInterval = dataOut.ippSeconds*self.n |
|
640 | timeInterval = dataOut.ippSeconds*self.n | |
645 | avgdatatime = (times - 1) * timeInterval + dataOut.utctime |
|
641 | avgdatatime = (times - 1) * timeInterval + dataOut.utctime | |
646 | self.__dataReady = True |
|
642 | self.__dataReady = True | |
647 | return avgdata, avgdatatime |
|
643 | return avgdata, avgdatatime | |
648 |
|
644 | |||
649 | def run(self, dataOut, n=None, timeInterval=None, stride=None, overlapping=False, byblock=False, **kwargs): |
|
645 | def run(self, dataOut, n=None, timeInterval=None, stride=None, overlapping=False, byblock=False, **kwargs): | |
650 |
|
646 | |||
651 | if not self.isConfig: |
|
647 | if not self.isConfig: | |
652 | self.setup(n=n, stride=stride, timeInterval=timeInterval, overlapping=overlapping, byblock=byblock, **kwargs) |
|
648 | self.setup(n=n, stride=stride, timeInterval=timeInterval, overlapping=overlapping, byblock=byblock, **kwargs) | |
653 | self.isConfig = True |
|
649 | self.isConfig = True | |
654 |
|
650 | |||
655 | if dataOut.flagDataAsBlock: |
|
651 | if dataOut.flagDataAsBlock: | |
656 | """ |
|
652 | """ | |
657 | Si la data es leida por bloques, dimension = [nChannels, nProfiles, nHeis] |
|
653 | Si la data es leida por bloques, dimension = [nChannels, nProfiles, nHeis] | |
658 | """ |
|
654 | """ | |
659 | avgdata, avgdatatime = self.integrateByBlock(dataOut) |
|
655 | avgdata, avgdatatime = self.integrateByBlock(dataOut) | |
660 | dataOut.nProfiles /= self.n |
|
656 | dataOut.nProfiles /= self.n | |
661 | else: |
|
657 | else: | |
662 | if stride is None: |
|
658 | if stride is None: | |
663 | avgdata, avgdatatime = self.integrate(dataOut.data, dataOut.utctime) |
|
659 | avgdata, avgdatatime = self.integrate(dataOut.data, dataOut.utctime) | |
664 | else: |
|
660 | else: | |
665 | avgdata, avgdatatime = self.integrateByStride(dataOut.data, dataOut.utctime) |
|
661 | avgdata, avgdatatime = self.integrateByStride(dataOut.data, dataOut.utctime) | |
666 |
|
662 | |||
667 |
|
663 | |||
668 | # dataOut.timeInterval *= n |
|
664 | # dataOut.timeInterval *= n | |
669 | dataOut.flagNoData = True |
|
665 | dataOut.flagNoData = True | |
670 |
|
666 | |||
671 | if self.__dataReady: |
|
667 | if self.__dataReady: | |
672 | dataOut.data = avgdata |
|
668 | dataOut.data = avgdata | |
673 | if not dataOut.flagCohInt: |
|
669 | if not dataOut.flagCohInt: | |
674 | dataOut.nCohInt *= self.n |
|
670 | dataOut.nCohInt *= self.n | |
675 | dataOut.flagCohInt = True |
|
671 | dataOut.flagCohInt = True | |
676 | dataOut.utctime = avgdatatime |
|
672 | dataOut.utctime = avgdatatime | |
677 | # print avgdata, avgdatatime |
|
673 | # print avgdata, avgdatatime | |
678 | # raise |
|
674 | # raise | |
679 | # dataOut.timeInterval = dataOut.ippSeconds * dataOut.nCohInt |
|
675 | # dataOut.timeInterval = dataOut.ippSeconds * dataOut.nCohInt | |
680 | dataOut.flagNoData = False |
|
676 | dataOut.flagNoData = False | |
681 | return dataOut |
|
677 | return dataOut | |
682 |
|
678 | |||
683 | class Decoder(Operation): |
|
679 | class Decoder(Operation): | |
684 |
|
680 | |||
685 | isConfig = False |
|
681 | isConfig = False | |
686 | __profIndex = 0 |
|
682 | __profIndex = 0 | |
687 |
|
683 | |||
688 | code = None |
|
684 | code = None | |
689 |
|
685 | |||
690 | nCode = None |
|
686 | nCode = None | |
691 | nBaud = None |
|
687 | nBaud = None | |
692 |
|
688 | |||
693 | def __init__(self, **kwargs): |
|
689 | def __init__(self, **kwargs): | |
694 |
|
690 | |||
695 | Operation.__init__(self, **kwargs) |
|
691 | Operation.__init__(self, **kwargs) | |
696 |
|
692 | |||
697 | self.times = None |
|
693 | self.times = None | |
698 | self.osamp = None |
|
694 | self.osamp = None | |
699 | # self.__setValues = False |
|
695 | # self.__setValues = False | |
700 | self.isConfig = False |
|
696 | self.isConfig = False | |
701 | self.setupReq = False |
|
697 | self.setupReq = False | |
702 | def setup(self, code, osamp, dataOut): |
|
698 | def setup(self, code, osamp, dataOut): | |
703 |
|
699 | |||
704 | self.__profIndex = 0 |
|
700 | self.__profIndex = 0 | |
705 |
|
701 | |||
706 | self.code = code |
|
702 | self.code = code | |
707 |
|
703 | |||
708 | self.nCode = len(code) |
|
704 | self.nCode = len(code) | |
709 | self.nBaud = len(code[0]) |
|
705 | self.nBaud = len(code[0]) | |
710 |
|
706 | |||
711 | if (osamp != None) and (osamp >1): |
|
707 | if (osamp != None) and (osamp >1): | |
712 | self.osamp = osamp |
|
708 | self.osamp = osamp | |
713 | self.code = numpy.repeat(code, repeats=self.osamp, axis=1) |
|
709 | self.code = numpy.repeat(code, repeats=self.osamp, axis=1) | |
714 | self.nBaud = self.nBaud*self.osamp |
|
710 | self.nBaud = self.nBaud*self.osamp | |
715 |
|
711 | |||
716 | self.__nChannels = dataOut.nChannels |
|
712 | self.__nChannels = dataOut.nChannels | |
717 | self.__nProfiles = dataOut.nProfiles |
|
713 | self.__nProfiles = dataOut.nProfiles | |
718 | self.__nHeis = dataOut.nHeights |
|
714 | self.__nHeis = dataOut.nHeights | |
719 |
|
715 | |||
720 | if self.__nHeis < self.nBaud: |
|
716 | if self.__nHeis < self.nBaud: | |
721 | raise ValueError('Number of heights (%d) should be greater than number of bauds (%d)' %(self.__nHeis, self.nBaud)) |
|
717 | raise ValueError('Number of heights (%d) should be greater than number of bauds (%d)' %(self.__nHeis, self.nBaud)) | |
722 |
|
718 | |||
723 | #Frequency |
|
719 | #Frequency | |
724 | __codeBuffer = numpy.zeros((self.nCode, self.__nHeis), dtype=numpy.complex) |
|
720 | __codeBuffer = numpy.zeros((self.nCode, self.__nHeis), dtype=numpy.complex) | |
725 |
|
721 | |||
726 | __codeBuffer[:,0:self.nBaud] = self.code |
|
722 | __codeBuffer[:,0:self.nBaud] = self.code | |
727 |
|
723 | |||
728 | self.fft_code = numpy.conj(numpy.fft.fft(__codeBuffer, axis=1)) |
|
724 | self.fft_code = numpy.conj(numpy.fft.fft(__codeBuffer, axis=1)) | |
729 |
|
725 | |||
730 | if dataOut.flagDataAsBlock: |
|
726 | if dataOut.flagDataAsBlock: | |
731 |
|
727 | |||
732 | self.ndatadec = self.__nHeis #- self.nBaud + 1 |
|
728 | self.ndatadec = self.__nHeis #- self.nBaud + 1 | |
733 |
|
729 | |||
734 | self.datadecTime = numpy.zeros((self.__nChannels, self.__nProfiles, self.ndatadec), dtype=numpy.complex) |
|
730 | self.datadecTime = numpy.zeros((self.__nChannels, self.__nProfiles, self.ndatadec), dtype=numpy.complex) | |
735 |
|
731 | |||
736 | else: |
|
732 | else: | |
737 |
|
733 | |||
738 | #Time |
|
734 | #Time | |
739 | self.ndatadec = self.__nHeis #- self.nBaud + 1 |
|
735 | self.ndatadec = self.__nHeis #- self.nBaud + 1 | |
740 |
|
736 | |||
741 | self.datadecTime = numpy.zeros((self.__nChannels, self.ndatadec), dtype=numpy.complex) |
|
737 | self.datadecTime = numpy.zeros((self.__nChannels, self.ndatadec), dtype=numpy.complex) | |
742 |
|
738 | |||
743 | def __convolutionInFreq(self, data): |
|
739 | def __convolutionInFreq(self, data): | |
744 |
|
740 | |||
745 | fft_code = self.fft_code[self.__profIndex].reshape(1,-1) |
|
741 | fft_code = self.fft_code[self.__profIndex].reshape(1,-1) | |
746 |
|
742 | |||
747 | fft_data = numpy.fft.fft(data, axis=1) |
|
743 | fft_data = numpy.fft.fft(data, axis=1) | |
748 |
|
744 | |||
749 | conv = fft_data*fft_code |
|
745 | conv = fft_data*fft_code | |
750 |
|
746 | |||
751 | data = numpy.fft.ifft(conv,axis=1) |
|
747 | data = numpy.fft.ifft(conv,axis=1) | |
752 |
|
748 | |||
753 | return data |
|
749 | return data | |
754 |
|
750 | |||
755 | def __convolutionInFreqOpt(self, data): |
|
751 | def __convolutionInFreqOpt(self, data): | |
756 |
|
752 | |||
757 | raise NotImplementedError |
|
753 | raise NotImplementedError | |
758 |
|
754 | |||
759 | def __convolutionInTime(self, data): |
|
755 | def __convolutionInTime(self, data): | |
760 |
|
756 | |||
761 | code = self.code[self.__profIndex] |
|
757 | code = self.code[self.__profIndex] | |
762 | for i in range(self.__nChannels): |
|
758 | for i in range(self.__nChannels): | |
763 | self.datadecTime[i,:] = numpy.correlate(data[i,:], code, mode='full')[self.nBaud-1:] |
|
759 | self.datadecTime[i,:] = numpy.correlate(data[i,:], code, mode='full')[self.nBaud-1:] | |
764 |
|
760 | |||
765 | return self.datadecTime |
|
761 | return self.datadecTime | |
766 |
|
762 | |||
767 | def __convolutionByBlockInTime(self, data): |
|
763 | def __convolutionByBlockInTime(self, data): | |
768 |
|
764 | |||
769 | repetitions = int(self.__nProfiles / self.nCode) |
|
765 | repetitions = int(self.__nProfiles / self.nCode) | |
770 | junk = numpy.lib.stride_tricks.as_strided(self.code, (repetitions, self.code.size), (0, self.code.itemsize)) |
|
766 | junk = numpy.lib.stride_tricks.as_strided(self.code, (repetitions, self.code.size), (0, self.code.itemsize)) | |
771 | junk = junk.flatten() |
|
767 | junk = junk.flatten() | |
772 | code_block = numpy.reshape(junk, (self.nCode*repetitions, self.nBaud)) |
|
768 | code_block = numpy.reshape(junk, (self.nCode*repetitions, self.nBaud)) | |
773 | profilesList = range(self.__nProfiles) |
|
769 | profilesList = range(self.__nProfiles) | |
774 |
|
770 | |||
775 | for i in range(self.__nChannels): |
|
771 | for i in range(self.__nChannels): | |
776 | for j in profilesList: |
|
772 | for j in profilesList: | |
777 | self.datadecTime[i,j,:] = numpy.correlate(data[i,j,:], code_block[j,:], mode='full')[self.nBaud-1:] |
|
773 | self.datadecTime[i,j,:] = numpy.correlate(data[i,j,:], code_block[j,:], mode='full')[self.nBaud-1:] | |
778 | return self.datadecTime |
|
774 | return self.datadecTime | |
779 |
|
775 | |||
780 | def __convolutionByBlockInFreq(self, data): |
|
776 | def __convolutionByBlockInFreq(self, data): | |
781 |
|
777 | |||
782 | raise NotImplementedError("Decoder by frequency fro Blocks not implemented") |
|
778 | raise NotImplementedError("Decoder by frequency fro Blocks not implemented") | |
783 |
|
779 | |||
784 |
|
780 | |||
785 | fft_code = self.fft_code[self.__profIndex].reshape(1,-1) |
|
781 | fft_code = self.fft_code[self.__profIndex].reshape(1,-1) | |
786 |
|
782 | |||
787 | fft_data = numpy.fft.fft(data, axis=2) |
|
783 | fft_data = numpy.fft.fft(data, axis=2) | |
788 |
|
784 | |||
789 | conv = fft_data*fft_code |
|
785 | conv = fft_data*fft_code | |
790 |
|
786 | |||
791 | data = numpy.fft.ifft(conv,axis=2) |
|
787 | data = numpy.fft.ifft(conv,axis=2) | |
792 |
|
788 | |||
793 | return data |
|
789 | return data | |
794 |
|
790 | |||
795 |
|
791 | |||
796 | def run(self, dataOut, code=None, nCode=None, nBaud=None, mode = 0, osamp=None, times=None): |
|
792 | def run(self, dataOut, code=None, nCode=None, nBaud=None, mode = 0, osamp=None, times=None): | |
797 |
|
793 | |||
798 | if dataOut.flagDecodeData: |
|
794 | if dataOut.flagDecodeData: | |
799 | print("This data is already decoded, recoding again ...") |
|
795 | print("This data is already decoded, recoding again ...") | |
800 |
|
796 | |||
801 | if not self.isConfig: |
|
797 | if not self.isConfig: | |
802 |
|
798 | |||
803 | if code is None: |
|
799 | if code is None: | |
804 | if dataOut.code is None: |
|
800 | if dataOut.code is None: | |
805 | raise ValueError("Code could not be read from %s instance. Enter a value in Code parameter" %dataOut.type) |
|
801 | raise ValueError("Code could not be read from %s instance. Enter a value in Code parameter" %dataOut.type) | |
806 |
|
802 | |||
807 | code = dataOut.code |
|
803 | code = dataOut.code | |
808 | else: |
|
804 | else: | |
809 | code = numpy.array(code).reshape(nCode,nBaud) |
|
805 | code = numpy.array(code).reshape(nCode,nBaud) | |
810 | self.setup(code, osamp, dataOut) |
|
806 | self.setup(code, osamp, dataOut) | |
811 |
|
807 | |||
812 | self.isConfig = True |
|
808 | self.isConfig = True | |
813 |
|
809 | |||
814 | if mode == 3: |
|
810 | if mode == 3: | |
815 | sys.stderr.write("Decoder Warning: mode=%d is not valid, using mode=0\n" %mode) |
|
811 | sys.stderr.write("Decoder Warning: mode=%d is not valid, using mode=0\n" %mode) | |
816 |
|
812 | |||
817 | if times != None: |
|
813 | if times != None: | |
818 | sys.stderr.write("Decoder Warning: Argument 'times' in not used anymore\n") |
|
814 | sys.stderr.write("Decoder Warning: Argument 'times' in not used anymore\n") | |
819 |
|
815 | |||
820 | if self.code is None: |
|
816 | if self.code is None: | |
821 | print("Fail decoding: Code is not defined.") |
|
817 | print("Fail decoding: Code is not defined.") | |
822 | return |
|
818 | return | |
823 |
|
819 | |||
824 | self.__nProfiles = dataOut.nProfiles |
|
820 | self.__nProfiles = dataOut.nProfiles | |
825 | datadec = None |
|
821 | datadec = None | |
826 |
|
822 | |||
827 | if mode == 3: |
|
823 | if mode == 3: | |
828 | mode = 0 |
|
824 | mode = 0 | |
829 |
|
825 | |||
830 | if dataOut.flagDataAsBlock: |
|
826 | if dataOut.flagDataAsBlock: | |
831 | """ |
|
827 | """ | |
832 | Decoding when data have been read as block, |
|
828 | Decoding when data have been read as block, | |
833 | """ |
|
829 | """ | |
834 |
|
830 | |||
835 | if mode == 0: |
|
831 | if mode == 0: | |
836 | datadec = self.__convolutionByBlockInTime(dataOut.data) |
|
832 | datadec = self.__convolutionByBlockInTime(dataOut.data) | |
837 | if mode == 1: |
|
833 | if mode == 1: | |
838 | datadec = self.__convolutionByBlockInFreq(dataOut.data) |
|
834 | datadec = self.__convolutionByBlockInFreq(dataOut.data) | |
839 | else: |
|
835 | else: | |
840 | """ |
|
836 | """ | |
841 | Decoding when data have been read profile by profile |
|
837 | Decoding when data have been read profile by profile | |
842 | """ |
|
838 | """ | |
843 | if mode == 0: |
|
839 | if mode == 0: | |
844 | datadec = self.__convolutionInTime(dataOut.data) |
|
840 | datadec = self.__convolutionInTime(dataOut.data) | |
845 |
|
841 | |||
846 | if mode == 1: |
|
842 | if mode == 1: | |
847 | datadec = self.__convolutionInFreq(dataOut.data) |
|
843 | datadec = self.__convolutionInFreq(dataOut.data) | |
848 |
|
844 | |||
849 | if mode == 2: |
|
845 | if mode == 2: | |
850 | datadec = self.__convolutionInFreqOpt(dataOut.data) |
|
846 | datadec = self.__convolutionInFreqOpt(dataOut.data) | |
851 |
|
847 | |||
852 | if datadec is None: |
|
848 | if datadec is None: | |
853 | raise ValueError("Codification mode selected is not valid: mode=%d. Try selecting 0 or 1" %mode) |
|
849 | raise ValueError("Codification mode selected is not valid: mode=%d. Try selecting 0 or 1" %mode) | |
854 |
|
850 | |||
855 | dataOut.code = self.code |
|
851 | dataOut.code = self.code | |
856 | dataOut.nCode = self.nCode |
|
852 | dataOut.nCode = self.nCode | |
857 | dataOut.nBaud = self.nBaud |
|
853 | dataOut.nBaud = self.nBaud | |
858 |
|
854 | |||
859 | dataOut.data = datadec |
|
855 | dataOut.data = datadec | |
860 |
|
856 | |||
861 | dataOut.heightList = dataOut.heightList[0:datadec.shape[-1]] |
|
857 | dataOut.heightList = dataOut.heightList[0:datadec.shape[-1]] | |
862 |
|
858 | |||
863 | dataOut.flagDecodeData = True #asumo q la data esta decodificada |
|
859 | dataOut.flagDecodeData = True #asumo q la data esta decodificada | |
864 |
|
860 | |||
865 | if self.__profIndex == self.nCode-1: |
|
861 | if self.__profIndex == self.nCode-1: | |
866 | self.__profIndex = 0 |
|
862 | self.__profIndex = 0 | |
867 | return dataOut |
|
863 | return dataOut | |
868 |
|
864 | |||
869 | self.__profIndex += 1 |
|
865 | self.__profIndex += 1 | |
870 |
|
866 | |||
871 | return dataOut |
|
867 | return dataOut | |
872 | # dataOut.flagDeflipData = True #asumo q la data no esta sin flip |
|
868 | # dataOut.flagDeflipData = True #asumo q la data no esta sin flip | |
873 |
|
869 | |||
874 |
|
870 | |||
875 | class ProfileConcat(Operation): |
|
871 | class ProfileConcat(Operation): | |
876 |
|
872 | |||
877 | isConfig = False |
|
873 | isConfig = False | |
878 | buffer = None |
|
874 | buffer = None | |
879 |
|
875 | |||
880 | def __init__(self, **kwargs): |
|
876 | def __init__(self, **kwargs): | |
881 |
|
877 | |||
882 | Operation.__init__(self, **kwargs) |
|
878 | Operation.__init__(self, **kwargs) | |
883 | self.profileIndex = 0 |
|
879 | self.profileIndex = 0 | |
884 |
|
880 | |||
885 | def reset(self): |
|
881 | def reset(self): | |
886 | self.buffer = numpy.zeros_like(self.buffer) |
|
882 | self.buffer = numpy.zeros_like(self.buffer) | |
887 | self.start_index = 0 |
|
883 | self.start_index = 0 | |
888 | self.times = 1 |
|
884 | self.times = 1 | |
889 |
|
885 | |||
890 | def setup(self, data, m, n=1): |
|
886 | def setup(self, data, m, n=1): | |
891 | self.buffer = numpy.zeros((data.shape[0],data.shape[1]*m),dtype=type(data[0,0])) |
|
887 | self.buffer = numpy.zeros((data.shape[0],data.shape[1]*m),dtype=type(data[0,0])) | |
892 | self.nHeights = data.shape[1]#.nHeights |
|
888 | self.nHeights = data.shape[1]#.nHeights | |
893 | self.start_index = 0 |
|
889 | self.start_index = 0 | |
894 | self.times = 1 |
|
890 | self.times = 1 | |
895 |
|
891 | |||
896 | def concat(self, data): |
|
892 | def concat(self, data): | |
897 |
|
893 | |||
898 | self.buffer[:,self.start_index:self.nHeights*self.times] = data.copy() |
|
894 | self.buffer[:,self.start_index:self.nHeights*self.times] = data.copy() | |
899 | self.start_index = self.start_index + self.nHeights |
|
895 | self.start_index = self.start_index + self.nHeights | |
900 |
|
896 | |||
901 | def run(self, dataOut, m): |
|
897 | def run(self, dataOut, m): | |
902 | dataOut.flagNoData = True |
|
898 | dataOut.flagNoData = True | |
903 |
|
899 | |||
904 | if not self.isConfig: |
|
900 | if not self.isConfig: | |
905 | self.setup(dataOut.data, m, 1) |
|
901 | self.setup(dataOut.data, m, 1) | |
906 | self.isConfig = True |
|
902 | self.isConfig = True | |
907 |
|
903 | |||
908 | if dataOut.flagDataAsBlock: |
|
904 | if dataOut.flagDataAsBlock: | |
909 | raise ValueError("ProfileConcat can only be used when voltage have been read profile by profile, getBlock = False") |
|
905 | raise ValueError("ProfileConcat can only be used when voltage have been read profile by profile, getBlock = False") | |
910 |
|
906 | |||
911 | else: |
|
907 | else: | |
912 | self.concat(dataOut.data) |
|
908 | self.concat(dataOut.data) | |
913 | self.times += 1 |
|
909 | self.times += 1 | |
914 | if self.times > m: |
|
910 | if self.times > m: | |
915 | dataOut.data = self.buffer |
|
911 | dataOut.data = self.buffer | |
916 | self.reset() |
|
912 | self.reset() | |
917 | dataOut.flagNoData = False |
|
913 | dataOut.flagNoData = False | |
918 | # se deben actualizar mas propiedades del header y del objeto dataOut, por ejemplo, las alturas |
|
914 | # se deben actualizar mas propiedades del header y del objeto dataOut, por ejemplo, las alturas | |
919 | deltaHeight = dataOut.heightList[1] - dataOut.heightList[0] |
|
915 | deltaHeight = dataOut.heightList[1] - dataOut.heightList[0] | |
920 | xf = dataOut.heightList[0] + dataOut.nHeights * deltaHeight * m |
|
916 | xf = dataOut.heightList[0] + dataOut.nHeights * deltaHeight * m | |
921 | dataOut.heightList = numpy.arange(dataOut.heightList[0], xf, deltaHeight) |
|
917 | dataOut.heightList = numpy.arange(dataOut.heightList[0], xf, deltaHeight) | |
922 | dataOut.ippSeconds *= m |
|
918 | dataOut.ippSeconds *= m | |
923 | return dataOut |
|
919 | return dataOut | |
924 |
|
920 | |||
925 | class ProfileSelector(Operation): |
|
921 | class ProfileSelector(Operation): | |
926 |
|
922 | |||
927 | profileIndex = None |
|
923 | profileIndex = None | |
928 | # Tamanho total de los perfiles |
|
924 | # Tamanho total de los perfiles | |
929 | nProfiles = None |
|
925 | nProfiles = None | |
930 |
|
926 | |||
931 | def __init__(self, **kwargs): |
|
927 | def __init__(self, **kwargs): | |
932 |
|
928 | |||
933 | Operation.__init__(self, **kwargs) |
|
929 | Operation.__init__(self, **kwargs) | |
934 | self.profileIndex = 0 |
|
930 | self.profileIndex = 0 | |
935 |
|
931 | |||
936 | def incProfileIndex(self): |
|
932 | def incProfileIndex(self): | |
937 |
|
933 | |||
938 | self.profileIndex += 1 |
|
934 | self.profileIndex += 1 | |
939 |
|
935 | |||
940 | if self.profileIndex >= self.nProfiles: |
|
936 | if self.profileIndex >= self.nProfiles: | |
941 | self.profileIndex = 0 |
|
937 | self.profileIndex = 0 | |
942 |
|
938 | |||
943 | def isThisProfileInRange(self, profileIndex, minIndex, maxIndex): |
|
939 | def isThisProfileInRange(self, profileIndex, minIndex, maxIndex): | |
944 |
|
940 | |||
945 | if profileIndex < minIndex: |
|
941 | if profileIndex < minIndex: | |
946 | return False |
|
942 | return False | |
947 |
|
943 | |||
948 | if profileIndex > maxIndex: |
|
944 | if profileIndex > maxIndex: | |
949 | return False |
|
945 | return False | |
950 |
|
946 | |||
951 | return True |
|
947 | return True | |
952 |
|
948 | |||
953 | def isThisProfileInList(self, profileIndex, profileList): |
|
949 | def isThisProfileInList(self, profileIndex, profileList): | |
954 |
|
950 | |||
955 | if profileIndex not in profileList: |
|
951 | if profileIndex not in profileList: | |
956 | return False |
|
952 | return False | |
957 |
|
953 | |||
958 | return True |
|
954 | return True | |
959 |
|
955 | |||
960 | def run(self, dataOut, profileList=None, profileRangeList=None, beam=None, byblock=False, rangeList = None, nProfiles=None): |
|
956 | def run(self, dataOut, profileList=None, profileRangeList=None, beam=None, byblock=False, rangeList = None, nProfiles=None): | |
961 |
|
957 | |||
962 | """ |
|
958 | """ | |
963 | ProfileSelector: |
|
959 | ProfileSelector: | |
964 |
|
960 | |||
965 | Inputs: |
|
961 | Inputs: | |
966 | profileList : Index of profiles selected. Example: profileList = (0,1,2,7,8) |
|
962 | profileList : Index of profiles selected. Example: profileList = (0,1,2,7,8) | |
967 |
|
963 | |||
968 | profileRangeList : Minimum and maximum profile indexes. Example: profileRangeList = (4, 30) |
|
964 | profileRangeList : Minimum and maximum profile indexes. Example: profileRangeList = (4, 30) | |
969 |
|
965 | |||
970 | rangeList : List of profile ranges. Example: rangeList = ((4, 30), (32, 64), (128, 256)) |
|
966 | rangeList : List of profile ranges. Example: rangeList = ((4, 30), (32, 64), (128, 256)) | |
971 |
|
967 | |||
972 | """ |
|
968 | """ | |
973 |
|
969 | |||
974 | if rangeList is not None: |
|
970 | if rangeList is not None: | |
975 | if type(rangeList[0]) not in (tuple, list): |
|
971 | if type(rangeList[0]) not in (tuple, list): | |
976 | rangeList = [rangeList] |
|
972 | rangeList = [rangeList] | |
977 |
|
973 | |||
978 | dataOut.flagNoData = True |
|
974 | dataOut.flagNoData = True | |
979 |
|
975 | |||
980 | if dataOut.flagDataAsBlock: |
|
976 | if dataOut.flagDataAsBlock: | |
981 | """ |
|
977 | """ | |
982 | data dimension = [nChannels, nProfiles, nHeis] |
|
978 | data dimension = [nChannels, nProfiles, nHeis] | |
983 | """ |
|
979 | """ | |
984 | if profileList != None: |
|
980 | if profileList != None: | |
985 | dataOut.data = dataOut.data[:,profileList,:] |
|
981 | dataOut.data = dataOut.data[:,profileList,:] | |
986 |
|
982 | |||
987 | if profileRangeList != None: |
|
983 | if profileRangeList != None: | |
988 | minIndex = profileRangeList[0] |
|
984 | minIndex = profileRangeList[0] | |
989 | maxIndex = profileRangeList[1] |
|
985 | maxIndex = profileRangeList[1] | |
990 | profileList = list(range(minIndex, maxIndex+1)) |
|
986 | profileList = list(range(minIndex, maxIndex+1)) | |
991 |
|
987 | |||
992 | dataOut.data = dataOut.data[:,minIndex:maxIndex+1,:] |
|
988 | dataOut.data = dataOut.data[:,minIndex:maxIndex+1,:] | |
993 |
|
989 | |||
994 | if rangeList != None: |
|
990 | if rangeList != None: | |
995 |
|
991 | |||
996 | profileList = [] |
|
992 | profileList = [] | |
997 |
|
993 | |||
998 | for thisRange in rangeList: |
|
994 | for thisRange in rangeList: | |
999 | minIndex = thisRange[0] |
|
995 | minIndex = thisRange[0] | |
1000 | maxIndex = thisRange[1] |
|
996 | maxIndex = thisRange[1] | |
1001 |
|
997 | |||
1002 | profileList.extend(list(range(minIndex, maxIndex+1))) |
|
998 | profileList.extend(list(range(minIndex, maxIndex+1))) | |
1003 |
|
999 | |||
1004 | dataOut.data = dataOut.data[:,profileList,:] |
|
1000 | dataOut.data = dataOut.data[:,profileList,:] | |
1005 |
|
1001 | |||
1006 | dataOut.nProfiles = len(profileList) |
|
1002 | dataOut.nProfiles = len(profileList) | |
1007 | dataOut.profileIndex = dataOut.nProfiles - 1 |
|
1003 | dataOut.profileIndex = dataOut.nProfiles - 1 | |
1008 | dataOut.flagNoData = False |
|
1004 | dataOut.flagNoData = False | |
1009 |
|
1005 | |||
1010 | return dataOut |
|
1006 | return dataOut | |
1011 |
|
1007 | |||
1012 | """ |
|
1008 | """ | |
1013 | data dimension = [nChannels, nHeis] |
|
1009 | data dimension = [nChannels, nHeis] | |
1014 | """ |
|
1010 | """ | |
1015 |
|
1011 | |||
1016 | if profileList != None: |
|
1012 | if profileList != None: | |
1017 |
|
1013 | |||
1018 | if self.isThisProfileInList(dataOut.profileIndex, profileList): |
|
1014 | if self.isThisProfileInList(dataOut.profileIndex, profileList): | |
1019 |
|
1015 | |||
1020 | self.nProfiles = len(profileList) |
|
1016 | self.nProfiles = len(profileList) | |
1021 | dataOut.nProfiles = self.nProfiles |
|
1017 | dataOut.nProfiles = self.nProfiles | |
1022 | dataOut.profileIndex = self.profileIndex |
|
1018 | dataOut.profileIndex = self.profileIndex | |
1023 | dataOut.flagNoData = False |
|
1019 | dataOut.flagNoData = False | |
1024 |
|
1020 | |||
1025 | self.incProfileIndex() |
|
1021 | self.incProfileIndex() | |
1026 | return dataOut |
|
1022 | return dataOut | |
1027 |
|
1023 | |||
1028 | if profileRangeList != None: |
|
1024 | if profileRangeList != None: | |
1029 |
|
1025 | |||
1030 | minIndex = profileRangeList[0] |
|
1026 | minIndex = profileRangeList[0] | |
1031 | maxIndex = profileRangeList[1] |
|
1027 | maxIndex = profileRangeList[1] | |
1032 |
|
1028 | |||
1033 | if self.isThisProfileInRange(dataOut.profileIndex, minIndex, maxIndex): |
|
1029 | if self.isThisProfileInRange(dataOut.profileIndex, minIndex, maxIndex): | |
1034 |
|
1030 | |||
1035 | self.nProfiles = maxIndex - minIndex + 1 |
|
1031 | self.nProfiles = maxIndex - minIndex + 1 | |
1036 | dataOut.nProfiles = self.nProfiles |
|
1032 | dataOut.nProfiles = self.nProfiles | |
1037 | dataOut.profileIndex = self.profileIndex |
|
1033 | dataOut.profileIndex = self.profileIndex | |
1038 | dataOut.flagNoData = False |
|
1034 | dataOut.flagNoData = False | |
1039 |
|
1035 | |||
1040 | self.incProfileIndex() |
|
1036 | self.incProfileIndex() | |
1041 | return dataOut |
|
1037 | return dataOut | |
1042 |
|
1038 | |||
1043 | if rangeList != None: |
|
1039 | if rangeList != None: | |
1044 |
|
1040 | |||
1045 | nProfiles = 0 |
|
1041 | nProfiles = 0 | |
1046 |
|
1042 | |||
1047 | for thisRange in rangeList: |
|
1043 | for thisRange in rangeList: | |
1048 | minIndex = thisRange[0] |
|
1044 | minIndex = thisRange[0] | |
1049 | maxIndex = thisRange[1] |
|
1045 | maxIndex = thisRange[1] | |
1050 |
|
1046 | |||
1051 | nProfiles += maxIndex - minIndex + 1 |
|
1047 | nProfiles += maxIndex - minIndex + 1 | |
1052 |
|
1048 | |||
1053 | for thisRange in rangeList: |
|
1049 | for thisRange in rangeList: | |
1054 |
|
1050 | |||
1055 | minIndex = thisRange[0] |
|
1051 | minIndex = thisRange[0] | |
1056 | maxIndex = thisRange[1] |
|
1052 | maxIndex = thisRange[1] | |
1057 |
|
1053 | |||
1058 | if self.isThisProfileInRange(dataOut.profileIndex, minIndex, maxIndex): |
|
1054 | if self.isThisProfileInRange(dataOut.profileIndex, minIndex, maxIndex): | |
1059 |
|
1055 | |||
1060 | self.nProfiles = nProfiles |
|
1056 | self.nProfiles = nProfiles | |
1061 | dataOut.nProfiles = self.nProfiles |
|
1057 | dataOut.nProfiles = self.nProfiles | |
1062 | dataOut.profileIndex = self.profileIndex |
|
1058 | dataOut.profileIndex = self.profileIndex | |
1063 | dataOut.flagNoData = False |
|
1059 | dataOut.flagNoData = False | |
1064 |
|
1060 | |||
1065 | self.incProfileIndex() |
|
1061 | self.incProfileIndex() | |
1066 |
|
1062 | |||
1067 | break |
|
1063 | break | |
1068 |
|
1064 | |||
1069 | return dataOut |
|
1065 | return dataOut | |
1070 |
|
1066 | |||
1071 |
|
1067 | |||
1072 | if beam != None: #beam is only for AMISR data |
|
1068 | if beam != None: #beam is only for AMISR data | |
1073 | if self.isThisProfileInList(dataOut.profileIndex, dataOut.beamRangeDict[beam]): |
|
1069 | if self.isThisProfileInList(dataOut.profileIndex, dataOut.beamRangeDict[beam]): | |
1074 | dataOut.flagNoData = False |
|
1070 | dataOut.flagNoData = False | |
1075 | dataOut.profileIndex = self.profileIndex |
|
1071 | dataOut.profileIndex = self.profileIndex | |
1076 |
|
1072 | |||
1077 | self.incProfileIndex() |
|
1073 | self.incProfileIndex() | |
1078 |
|
1074 | |||
1079 | return dataOut |
|
1075 | return dataOut | |
1080 |
|
1076 | |||
1081 | raise ValueError("ProfileSelector needs profileList, profileRangeList or rangeList parameter") |
|
1077 | raise ValueError("ProfileSelector needs profileList, profileRangeList or rangeList parameter") | |
1082 |
|
1078 | |||
1083 |
|
1079 | |||
1084 | class Reshaper(Operation): |
|
1080 | class Reshaper(Operation): | |
1085 |
|
1081 | |||
1086 | def __init__(self, **kwargs): |
|
1082 | def __init__(self, **kwargs): | |
1087 |
|
1083 | |||
1088 | Operation.__init__(self, **kwargs) |
|
1084 | Operation.__init__(self, **kwargs) | |
1089 |
|
1085 | |||
1090 | self.__buffer = None |
|
1086 | self.__buffer = None | |
1091 | self.__nitems = 0 |
|
1087 | self.__nitems = 0 | |
1092 |
|
1088 | |||
1093 | def __appendProfile(self, dataOut, nTxs): |
|
1089 | def __appendProfile(self, dataOut, nTxs): | |
1094 |
|
1090 | |||
1095 | if self.__buffer is None: |
|
1091 | if self.__buffer is None: | |
1096 | shape = (dataOut.nChannels, int(dataOut.nHeights/nTxs) ) |
|
1092 | shape = (dataOut.nChannels, int(dataOut.nHeights/nTxs) ) | |
1097 | self.__buffer = numpy.empty(shape, dtype = dataOut.data.dtype) |
|
1093 | self.__buffer = numpy.empty(shape, dtype = dataOut.data.dtype) | |
1098 |
|
1094 | |||
1099 | ini = dataOut.nHeights * self.__nitems |
|
1095 | ini = dataOut.nHeights * self.__nitems | |
1100 | end = ini + dataOut.nHeights |
|
1096 | end = ini + dataOut.nHeights | |
1101 |
|
1097 | |||
1102 | self.__buffer[:, ini:end] = dataOut.data |
|
1098 | self.__buffer[:, ini:end] = dataOut.data | |
1103 |
|
1099 | |||
1104 | self.__nitems += 1 |
|
1100 | self.__nitems += 1 | |
1105 |
|
1101 | |||
1106 | return int(self.__nitems*nTxs) |
|
1102 | return int(self.__nitems*nTxs) | |
1107 |
|
1103 | |||
1108 | def __getBuffer(self): |
|
1104 | def __getBuffer(self): | |
1109 |
|
1105 | |||
1110 | if self.__nitems == int(1./self.__nTxs): |
|
1106 | if self.__nitems == int(1./self.__nTxs): | |
1111 |
|
1107 | |||
1112 | self.__nitems = 0 |
|
1108 | self.__nitems = 0 | |
1113 |
|
1109 | |||
1114 | return self.__buffer.copy() |
|
1110 | return self.__buffer.copy() | |
1115 |
|
1111 | |||
1116 | return None |
|
1112 | return None | |
1117 |
|
1113 | |||
1118 | def __checkInputs(self, dataOut, shape, nTxs): |
|
1114 | def __checkInputs(self, dataOut, shape, nTxs): | |
1119 |
|
1115 | |||
1120 | if shape is None and nTxs is None: |
|
1116 | if shape is None and nTxs is None: | |
1121 | raise ValueError("Reshaper: shape of factor should be defined") |
|
1117 | raise ValueError("Reshaper: shape of factor should be defined") | |
1122 |
|
1118 | |||
1123 | if nTxs: |
|
1119 | if nTxs: | |
1124 | if nTxs < 0: |
|
1120 | if nTxs < 0: | |
1125 | raise ValueError("nTxs should be greater than 0") |
|
1121 | raise ValueError("nTxs should be greater than 0") | |
1126 |
|
1122 | |||
1127 | if nTxs < 1 and dataOut.nProfiles % (1./nTxs) != 0: |
|
1123 | if nTxs < 1 and dataOut.nProfiles % (1./nTxs) != 0: | |
1128 | raise ValueError("nProfiles= %d is not divisibled by (1./nTxs) = %f" %(dataOut.nProfiles, (1./nTxs))) |
|
1124 | raise ValueError("nProfiles= %d is not divisibled by (1./nTxs) = %f" %(dataOut.nProfiles, (1./nTxs))) | |
1129 |
|
1125 | |||
1130 | shape = [dataOut.nChannels, dataOut.nProfiles*nTxs, dataOut.nHeights/nTxs] |
|
1126 | shape = [dataOut.nChannels, dataOut.nProfiles*nTxs, dataOut.nHeights/nTxs] | |
1131 |
|
1127 | |||
1132 | return shape, nTxs |
|
1128 | return shape, nTxs | |
1133 |
|
1129 | |||
1134 | if len(shape) != 2 and len(shape) != 3: |
|
1130 | if len(shape) != 2 and len(shape) != 3: | |
1135 | 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)) |
|
1131 | 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)) | |
1136 |
|
1132 | |||
1137 | if len(shape) == 2: |
|
1133 | if len(shape) == 2: | |
1138 | shape_tuple = [dataOut.nChannels] |
|
1134 | shape_tuple = [dataOut.nChannels] | |
1139 | shape_tuple.extend(shape) |
|
1135 | shape_tuple.extend(shape) | |
1140 | else: |
|
1136 | else: | |
1141 | shape_tuple = list(shape) |
|
1137 | shape_tuple = list(shape) | |
1142 |
|
1138 | |||
1143 | nTxs = 1.0*shape_tuple[1]/dataOut.nProfiles |
|
1139 | nTxs = 1.0*shape_tuple[1]/dataOut.nProfiles | |
1144 |
|
1140 | |||
1145 | return shape_tuple, nTxs |
|
1141 | return shape_tuple, nTxs | |
1146 |
|
1142 | |||
1147 | def run(self, dataOut, shape=None, nTxs=None): |
|
1143 | def run(self, dataOut, shape=None, nTxs=None): | |
1148 |
|
1144 | |||
1149 | shape_tuple, self.__nTxs = self.__checkInputs(dataOut, shape, nTxs) |
|
1145 | shape_tuple, self.__nTxs = self.__checkInputs(dataOut, shape, nTxs) | |
1150 |
|
1146 | |||
1151 | dataOut.flagNoData = True |
|
1147 | dataOut.flagNoData = True | |
1152 | profileIndex = None |
|
1148 | profileIndex = None | |
1153 |
|
1149 | |||
1154 | if dataOut.flagDataAsBlock: |
|
1150 | if dataOut.flagDataAsBlock: | |
1155 |
|
1151 | |||
1156 | dataOut.data = numpy.reshape(dataOut.data, shape_tuple) |
|
1152 | dataOut.data = numpy.reshape(dataOut.data, shape_tuple) | |
1157 | dataOut.flagNoData = False |
|
1153 | dataOut.flagNoData = False | |
1158 |
|
1154 | |||
1159 | profileIndex = int(dataOut.nProfiles*self.__nTxs) - 1 |
|
1155 | profileIndex = int(dataOut.nProfiles*self.__nTxs) - 1 | |
1160 |
|
1156 | |||
1161 | else: |
|
1157 | else: | |
1162 |
|
1158 | |||
1163 | if self.__nTxs < 1: |
|
1159 | if self.__nTxs < 1: | |
1164 |
|
1160 | |||
1165 | self.__appendProfile(dataOut, self.__nTxs) |
|
1161 | self.__appendProfile(dataOut, self.__nTxs) | |
1166 | new_data = self.__getBuffer() |
|
1162 | new_data = self.__getBuffer() | |
1167 |
|
1163 | |||
1168 | if new_data is not None: |
|
1164 | if new_data is not None: | |
1169 | dataOut.data = new_data |
|
1165 | dataOut.data = new_data | |
1170 | dataOut.flagNoData = False |
|
1166 | dataOut.flagNoData = False | |
1171 |
|
1167 | |||
1172 | profileIndex = dataOut.profileIndex*nTxs |
|
1168 | profileIndex = dataOut.profileIndex*nTxs | |
1173 |
|
1169 | |||
1174 | else: |
|
1170 | else: | |
1175 | raise ValueError("nTxs should be greater than 0 and lower than 1, or use VoltageReader(..., getblock=True)") |
|
1171 | raise ValueError("nTxs should be greater than 0 and lower than 1, or use VoltageReader(..., getblock=True)") | |
1176 |
|
1172 | |||
1177 | deltaHeight = dataOut.heightList[1] - dataOut.heightList[0] |
|
1173 | deltaHeight = dataOut.heightList[1] - dataOut.heightList[0] | |
1178 |
|
1174 | |||
1179 | dataOut.heightList = numpy.arange(dataOut.nHeights/self.__nTxs) * deltaHeight + dataOut.heightList[0] |
|
1175 | dataOut.heightList = numpy.arange(dataOut.nHeights/self.__nTxs) * deltaHeight + dataOut.heightList[0] | |
1180 |
|
1176 | |||
1181 | dataOut.nProfiles = int(dataOut.nProfiles*self.__nTxs) |
|
1177 | dataOut.nProfiles = int(dataOut.nProfiles*self.__nTxs) | |
1182 |
|
1178 | |||
1183 | dataOut.profileIndex = profileIndex |
|
1179 | dataOut.profileIndex = profileIndex | |
1184 |
|
1180 | |||
1185 | dataOut.ippSeconds /= self.__nTxs |
|
1181 | dataOut.ippSeconds /= self.__nTxs | |
1186 |
|
1182 | |||
1187 | return dataOut |
|
1183 | return dataOut | |
1188 |
|
1184 | |||
1189 | class SplitProfiles(Operation): |
|
1185 | class SplitProfiles(Operation): | |
1190 |
|
1186 | |||
1191 | def __init__(self, **kwargs): |
|
1187 | def __init__(self, **kwargs): | |
1192 |
|
1188 | |||
1193 | Operation.__init__(self, **kwargs) |
|
1189 | Operation.__init__(self, **kwargs) | |
1194 |
|
1190 | |||
1195 | def run(self, dataOut, n): |
|
1191 | def run(self, dataOut, n): | |
1196 |
|
1192 | |||
1197 | dataOut.flagNoData = True |
|
1193 | dataOut.flagNoData = True | |
1198 | profileIndex = None |
|
1194 | profileIndex = None | |
1199 |
|
1195 | |||
1200 | if dataOut.flagDataAsBlock: |
|
1196 | if dataOut.flagDataAsBlock: | |
1201 |
|
1197 | |||
1202 | #nchannels, nprofiles, nsamples |
|
1198 | #nchannels, nprofiles, nsamples | |
1203 | shape = dataOut.data.shape |
|
1199 | shape = dataOut.data.shape | |
1204 |
|
1200 | |||
1205 | if shape[2] % n != 0: |
|
1201 | if shape[2] % n != 0: | |
1206 | raise ValueError("Could not split the data, n=%d has to be multiple of %d" %(n, shape[2])) |
|
1202 | raise ValueError("Could not split the data, n=%d has to be multiple of %d" %(n, shape[2])) | |
1207 |
|
1203 | |||
1208 | new_shape = shape[0], shape[1]*n, int(shape[2]/n) |
|
1204 | new_shape = shape[0], shape[1]*n, int(shape[2]/n) | |
1209 |
|
1205 | |||
1210 | dataOut.data = numpy.reshape(dataOut.data, new_shape) |
|
1206 | dataOut.data = numpy.reshape(dataOut.data, new_shape) | |
1211 | dataOut.flagNoData = False |
|
1207 | dataOut.flagNoData = False | |
1212 |
|
1208 | |||
1213 | profileIndex = int(dataOut.nProfiles/n) - 1 |
|
1209 | profileIndex = int(dataOut.nProfiles/n) - 1 | |
1214 |
|
1210 | |||
1215 | else: |
|
1211 | else: | |
1216 |
|
1212 | |||
1217 | raise ValueError("Could not split the data when is read Profile by Profile. Use VoltageReader(..., getblock=True)") |
|
1213 | raise ValueError("Could not split the data when is read Profile by Profile. Use VoltageReader(..., getblock=True)") | |
1218 |
|
1214 | |||
1219 | deltaHeight = dataOut.heightList[1] - dataOut.heightList[0] |
|
1215 | deltaHeight = dataOut.heightList[1] - dataOut.heightList[0] | |
1220 |
|
1216 | |||
1221 | dataOut.heightList = numpy.arange(dataOut.nHeights/n) * deltaHeight + dataOut.heightList[0] |
|
1217 | dataOut.heightList = numpy.arange(dataOut.nHeights/n) * deltaHeight + dataOut.heightList[0] | |
1222 |
|
1218 | |||
1223 | dataOut.nProfiles = int(dataOut.nProfiles*n) |
|
1219 | dataOut.nProfiles = int(dataOut.nProfiles*n) | |
1224 |
|
1220 | |||
1225 | dataOut.profileIndex = profileIndex |
|
1221 | dataOut.profileIndex = profileIndex | |
1226 |
|
1222 | |||
1227 | dataOut.ippSeconds /= n |
|
1223 | dataOut.ippSeconds /= n | |
1228 |
|
1224 | |||
1229 | return dataOut |
|
1225 | return dataOut | |
1230 |
|
1226 | |||
1231 | class CombineProfiles(Operation): |
|
1227 | class CombineProfiles(Operation): | |
1232 | def __init__(self, **kwargs): |
|
1228 | def __init__(self, **kwargs): | |
1233 |
|
1229 | |||
1234 | Operation.__init__(self, **kwargs) |
|
1230 | Operation.__init__(self, **kwargs) | |
1235 |
|
1231 | |||
1236 | self.__remData = None |
|
1232 | self.__remData = None | |
1237 | self.__profileIndex = 0 |
|
1233 | self.__profileIndex = 0 | |
1238 |
|
1234 | |||
1239 | def run(self, dataOut, n): |
|
1235 | def run(self, dataOut, n): | |
1240 |
|
1236 | |||
1241 | dataOut.flagNoData = True |
|
1237 | dataOut.flagNoData = True | |
1242 | profileIndex = None |
|
1238 | profileIndex = None | |
1243 |
|
1239 | |||
1244 | if dataOut.flagDataAsBlock: |
|
1240 | if dataOut.flagDataAsBlock: | |
1245 |
|
1241 | |||
1246 | #nchannels, nprofiles, nsamples |
|
1242 | #nchannels, nprofiles, nsamples | |
1247 | shape = dataOut.data.shape |
|
1243 | shape = dataOut.data.shape | |
1248 | new_shape = shape[0], shape[1]/n, shape[2]*n |
|
1244 | new_shape = shape[0], shape[1]/n, shape[2]*n | |
1249 |
|
1245 | |||
1250 | if shape[1] % n != 0: |
|
1246 | if shape[1] % n != 0: | |
1251 | raise ValueError("Could not split the data, n=%d has to be multiple of %d" %(n, shape[1])) |
|
1247 | raise ValueError("Could not split the data, n=%d has to be multiple of %d" %(n, shape[1])) | |
1252 |
|
1248 | |||
1253 | dataOut.data = numpy.reshape(dataOut.data, new_shape) |
|
1249 | dataOut.data = numpy.reshape(dataOut.data, new_shape) | |
1254 | dataOut.flagNoData = False |
|
1250 | dataOut.flagNoData = False | |
1255 |
|
1251 | |||
1256 | profileIndex = int(dataOut.nProfiles*n) - 1 |
|
1252 | profileIndex = int(dataOut.nProfiles*n) - 1 | |
1257 |
|
1253 | |||
1258 | else: |
|
1254 | else: | |
1259 |
|
1255 | |||
1260 | #nchannels, nsamples |
|
1256 | #nchannels, nsamples | |
1261 | if self.__remData is None: |
|
1257 | if self.__remData is None: | |
1262 | newData = dataOut.data |
|
1258 | newData = dataOut.data | |
1263 | else: |
|
1259 | else: | |
1264 | newData = numpy.concatenate((self.__remData, dataOut.data), axis=1) |
|
1260 | newData = numpy.concatenate((self.__remData, dataOut.data), axis=1) | |
1265 |
|
1261 | |||
1266 | self.__profileIndex += 1 |
|
1262 | self.__profileIndex += 1 | |
1267 |
|
1263 | |||
1268 | if self.__profileIndex < n: |
|
1264 | if self.__profileIndex < n: | |
1269 | self.__remData = newData |
|
1265 | self.__remData = newData | |
1270 | #continue |
|
1266 | #continue | |
1271 | return |
|
1267 | return | |
1272 |
|
1268 | |||
1273 | self.__profileIndex = 0 |
|
1269 | self.__profileIndex = 0 | |
1274 | self.__remData = None |
|
1270 | self.__remData = None | |
1275 |
|
1271 | |||
1276 | dataOut.data = newData |
|
1272 | dataOut.data = newData | |
1277 | dataOut.flagNoData = False |
|
1273 | dataOut.flagNoData = False | |
1278 |
|
1274 | |||
1279 | profileIndex = dataOut.profileIndex/n |
|
1275 | profileIndex = dataOut.profileIndex/n | |
1280 |
|
1276 | |||
1281 |
|
1277 | |||
1282 | deltaHeight = dataOut.heightList[1] - dataOut.heightList[0] |
|
1278 | deltaHeight = dataOut.heightList[1] - dataOut.heightList[0] | |
1283 |
|
1279 | |||
1284 | dataOut.heightList = numpy.arange(dataOut.nHeights*n) * deltaHeight + dataOut.heightList[0] |
|
1280 | dataOut.heightList = numpy.arange(dataOut.nHeights*n) * deltaHeight + dataOut.heightList[0] | |
1285 |
|
1281 | |||
1286 | dataOut.nProfiles = int(dataOut.nProfiles/n) |
|
1282 | dataOut.nProfiles = int(dataOut.nProfiles/n) | |
1287 |
|
1283 | |||
1288 | dataOut.profileIndex = profileIndex |
|
1284 | dataOut.profileIndex = profileIndex | |
1289 |
|
1285 | |||
1290 | dataOut.ippSeconds *= n |
|
1286 | dataOut.ippSeconds *= n | |
1291 |
|
1287 | |||
1292 | return dataOut |
|
1288 | return dataOut | |
1293 |
|
1289 | |||
1294 | class PulsePairVoltage(Operation): |
|
1290 | class PulsePairVoltage(Operation): | |
1295 | ''' |
|
1291 | ''' | |
1296 | Function PulsePair(Signal Power, Velocity) |
|
1292 | Function PulsePair(Signal Power, Velocity) | |
1297 | The real component of Lag[0] provides Intensity Information |
|
1293 | The real component of Lag[0] provides Intensity Information | |
1298 | The imag component of Lag[1] Phase provides Velocity Information |
|
1294 | The imag component of Lag[1] Phase provides Velocity Information | |
1299 |
|
1295 | |||
1300 | Configuration Parameters: |
|
1296 | Configuration Parameters: | |
1301 | nPRF = Number of Several PRF |
|
1297 | nPRF = Number of Several PRF | |
1302 | theta = Degree Azimuth angel Boundaries |
|
1298 | theta = Degree Azimuth angel Boundaries | |
1303 |
|
1299 | |||
1304 | Input: |
|
1300 | Input: | |
1305 | self.dataOut |
|
1301 | self.dataOut | |
1306 | lag[N] |
|
1302 | lag[N] | |
1307 | Affected: |
|
1303 | Affected: | |
1308 | self.dataOut.spc |
|
1304 | self.dataOut.spc | |
1309 | ''' |
|
1305 | ''' | |
1310 | isConfig = False |
|
1306 | isConfig = False | |
1311 | __profIndex = 0 |
|
1307 | __profIndex = 0 | |
1312 | __initime = None |
|
1308 | __initime = None | |
1313 | __lastdatatime = None |
|
1309 | __lastdatatime = None | |
1314 | __buffer = None |
|
1310 | __buffer = None | |
1315 | noise = None |
|
1311 | noise = None | |
1316 | __dataReady = False |
|
1312 | __dataReady = False | |
1317 | n = None |
|
1313 | n = None | |
1318 | __nch = 0 |
|
1314 | __nch = 0 | |
1319 | __nHeis = 0 |
|
1315 | __nHeis = 0 | |
1320 | removeDC = False |
|
1316 | removeDC = False | |
1321 | ipp = None |
|
1317 | ipp = None | |
1322 | lambda_ = 0 |
|
1318 | lambda_ = 0 | |
1323 |
|
1319 | |||
1324 | def __init__(self,**kwargs): |
|
1320 | def __init__(self,**kwargs): | |
1325 | Operation.__init__(self,**kwargs) |
|
1321 | Operation.__init__(self,**kwargs) | |
1326 |
|
1322 | |||
1327 | def setup(self, dataOut, n = None, removeDC=False): |
|
1323 | def setup(self, dataOut, n = None, removeDC=False): | |
1328 | ''' |
|
1324 | ''' | |
1329 | n= Numero de PRF's de entrada |
|
1325 | n= Numero de PRF's de entrada | |
1330 | ''' |
|
1326 | ''' | |
1331 | self.__initime = None |
|
1327 | self.__initime = None | |
1332 | self.__lastdatatime = 0 |
|
1328 | self.__lastdatatime = 0 | |
1333 | self.__dataReady = False |
|
1329 | self.__dataReady = False | |
1334 | self.__buffer = 0 |
|
1330 | self.__buffer = 0 | |
1335 | self.__profIndex = 0 |
|
1331 | self.__profIndex = 0 | |
1336 | self.noise = None |
|
1332 | self.noise = None | |
1337 | self.__nch = dataOut.nChannels |
|
1333 | self.__nch = dataOut.nChannels | |
1338 | self.__nHeis = dataOut.nHeights |
|
1334 | self.__nHeis = dataOut.nHeights | |
1339 | self.removeDC = removeDC |
|
1335 | self.removeDC = removeDC | |
1340 | self.lambda_ = 3.0e8/(9345.0e6) |
|
1336 | self.lambda_ = 3.0e8/(9345.0e6) | |
1341 | self.ippSec = dataOut.ippSeconds |
|
1337 | self.ippSec = dataOut.ippSeconds | |
1342 | self.nCohInt = dataOut.nCohInt |
|
1338 | self.nCohInt = dataOut.nCohInt | |
1343 | print("IPPseconds",dataOut.ippSeconds) |
|
1339 | print("IPPseconds",dataOut.ippSeconds) | |
1344 |
|
1340 | |||
1345 | print("ELVALOR DE n es:", n) |
|
1341 | print("ELVALOR DE n es:", n) | |
1346 | if n == None: |
|
1342 | if n == None: | |
1347 | raise ValueError("n should be specified.") |
|
1343 | raise ValueError("n should be specified.") | |
1348 |
|
1344 | |||
1349 | if n != None: |
|
1345 | if n != None: | |
1350 | if n<2: |
|
1346 | if n<2: | |
1351 | raise ValueError("n should be greater than 2") |
|
1347 | raise ValueError("n should be greater than 2") | |
1352 |
|
1348 | |||
1353 | self.n = n |
|
1349 | self.n = n | |
1354 | self.__nProf = n |
|
1350 | self.__nProf = n | |
1355 |
|
1351 | |||
1356 | self.__buffer = numpy.zeros((dataOut.nChannels, |
|
1352 | self.__buffer = numpy.zeros((dataOut.nChannels, | |
1357 | n, |
|
1353 | n, | |
1358 | dataOut.nHeights), |
|
1354 | dataOut.nHeights), | |
1359 | dtype='complex') |
|
1355 | dtype='complex') | |
1360 |
|
1356 | |||
1361 | def putData(self,data): |
|
1357 | def putData(self,data): | |
1362 | ''' |
|
1358 | ''' | |
1363 | Add a profile to he __buffer and increase in one the __profiel Index |
|
1359 | Add a profile to he __buffer and increase in one the __profiel Index | |
1364 | ''' |
|
1360 | ''' | |
1365 | self.__buffer[:,self.__profIndex,:]= data |
|
1361 | self.__buffer[:,self.__profIndex,:]= data | |
1366 | self.__profIndex += 1 |
|
1362 | self.__profIndex += 1 | |
1367 | return |
|
1363 | return | |
1368 |
|
1364 | |||
1369 | def pushData(self,dataOut): |
|
1365 | def pushData(self,dataOut): | |
1370 | ''' |
|
1366 | ''' | |
1371 | Return the PULSEPAIR and the profiles used in the operation |
|
1367 | Return the PULSEPAIR and the profiles used in the operation | |
1372 | Affected : self.__profileIndex |
|
1368 | Affected : self.__profileIndex | |
1373 | ''' |
|
1369 | ''' | |
1374 | #----------------- Remove DC----------------------------------- |
|
1370 | #----------------- Remove DC----------------------------------- | |
1375 | if self.removeDC==True: |
|
1371 | if self.removeDC==True: | |
1376 | mean = numpy.mean(self.__buffer,1) |
|
1372 | mean = numpy.mean(self.__buffer,1) | |
1377 | tmp = mean.reshape(self.__nch,1,self.__nHeis) |
|
1373 | tmp = mean.reshape(self.__nch,1,self.__nHeis) | |
1378 | dc= numpy.tile(tmp,[1,self.__nProf,1]) |
|
1374 | dc= numpy.tile(tmp,[1,self.__nProf,1]) | |
1379 | self.__buffer = self.__buffer - dc |
|
1375 | self.__buffer = self.__buffer - dc | |
1380 | #------------------Calculo de Potencia ------------------------ |
|
1376 | #------------------Calculo de Potencia ------------------------ | |
1381 | pair0 = self.__buffer*numpy.conj(self.__buffer) |
|
1377 | pair0 = self.__buffer*numpy.conj(self.__buffer) | |
1382 | pair0 = pair0.real |
|
1378 | pair0 = pair0.real | |
1383 | lag_0 = numpy.sum(pair0,1) |
|
1379 | lag_0 = numpy.sum(pair0,1) | |
1384 | #------------------Calculo de Ruido x canal-------------------- |
|
1380 | #------------------Calculo de Ruido x canal-------------------- | |
1385 | self.noise = numpy.zeros(self.__nch) |
|
1381 | self.noise = numpy.zeros(self.__nch) | |
1386 | for i in range(self.__nch): |
|
1382 | for i in range(self.__nch): | |
1387 | daux = numpy.sort(pair0[i,:,:],axis= None) |
|
1383 | daux = numpy.sort(pair0[i,:,:],axis= None) | |
1388 | self.noise[i]=hildebrand_sekhon( daux ,self.nCohInt) |
|
1384 | self.noise[i]=hildebrand_sekhon( daux ,self.nCohInt) | |
1389 |
|
1385 | |||
1390 | self.noise = self.noise.reshape(self.__nch,1) |
|
1386 | self.noise = self.noise.reshape(self.__nch,1) | |
1391 | self.noise = numpy.tile(self.noise,[1,self.__nHeis]) |
|
1387 | self.noise = numpy.tile(self.noise,[1,self.__nHeis]) | |
1392 | noise_buffer = self.noise.reshape(self.__nch,1,self.__nHeis) |
|
1388 | noise_buffer = self.noise.reshape(self.__nch,1,self.__nHeis) | |
1393 | noise_buffer = numpy.tile(noise_buffer,[1,self.__nProf,1]) |
|
1389 | noise_buffer = numpy.tile(noise_buffer,[1,self.__nProf,1]) | |
1394 | #------------------ Potencia recibida= P , Potencia senal = S , Ruido= N-- |
|
1390 | #------------------ Potencia recibida= P , Potencia senal = S , Ruido= N-- | |
1395 | #------------------ P= S+N ,P=lag_0/N --------------------------------- |
|
1391 | #------------------ P= S+N ,P=lag_0/N --------------------------------- | |
1396 | #-------------------- Power -------------------------------------------------- |
|
1392 | #-------------------- Power -------------------------------------------------- | |
1397 | data_power = lag_0/(self.n*self.nCohInt) |
|
1393 | data_power = lag_0/(self.n*self.nCohInt) | |
1398 | #------------------ Senal --------------------------------------------------- |
|
1394 | #------------------ Senal --------------------------------------------------- | |
1399 | data_intensity = pair0 - noise_buffer |
|
1395 | data_intensity = pair0 - noise_buffer | |
1400 | data_intensity = numpy.sum(data_intensity,axis=1)*(self.n*self.nCohInt)#*self.nCohInt) |
|
1396 | data_intensity = numpy.sum(data_intensity,axis=1)*(self.n*self.nCohInt)#*self.nCohInt) | |
1401 | #data_intensity = (lag_0-self.noise*self.n)*(self.n*self.nCohInt) |
|
1397 | #data_intensity = (lag_0-self.noise*self.n)*(self.n*self.nCohInt) | |
1402 | for i in range(self.__nch): |
|
1398 | for i in range(self.__nch): | |
1403 | for j in range(self.__nHeis): |
|
1399 | for j in range(self.__nHeis): | |
1404 | if data_intensity[i][j] < 0: |
|
1400 | if data_intensity[i][j] < 0: | |
1405 | data_intensity[i][j] = numpy.min(numpy.absolute(data_intensity[i][j])) |
|
1401 | data_intensity[i][j] = numpy.min(numpy.absolute(data_intensity[i][j])) | |
1406 |
|
1402 | |||
1407 | #----------------- Calculo de Frecuencia y Velocidad doppler-------- |
|
1403 | #----------------- Calculo de Frecuencia y Velocidad doppler-------- | |
1408 | pair1 = self.__buffer[:,:-1,:]*numpy.conjugate(self.__buffer[:,1:,:]) |
|
1404 | pair1 = self.__buffer[:,:-1,:]*numpy.conjugate(self.__buffer[:,1:,:]) | |
1409 | lag_1 = numpy.sum(pair1,1) |
|
1405 | lag_1 = numpy.sum(pair1,1) | |
1410 | data_freq = (-1/(2.0*math.pi*self.ippSec*self.nCohInt))*numpy.angle(lag_1) |
|
1406 | data_freq = (-1/(2.0*math.pi*self.ippSec*self.nCohInt))*numpy.angle(lag_1) | |
1411 | data_velocity = (self.lambda_/2.0)*data_freq |
|
1407 | data_velocity = (self.lambda_/2.0)*data_freq | |
1412 |
|
1408 | |||
1413 | #---------------- Potencia promedio estimada de la Senal----------- |
|
1409 | #---------------- Potencia promedio estimada de la Senal----------- | |
1414 | lag_0 = lag_0/self.n |
|
1410 | lag_0 = lag_0/self.n | |
1415 | S = lag_0-self.noise |
|
1411 | S = lag_0-self.noise | |
1416 |
|
1412 | |||
1417 | #---------------- Frecuencia Doppler promedio --------------------- |
|
1413 | #---------------- Frecuencia Doppler promedio --------------------- | |
1418 | lag_1 = lag_1/(self.n-1) |
|
1414 | lag_1 = lag_1/(self.n-1) | |
1419 | R1 = numpy.abs(lag_1) |
|
1415 | R1 = numpy.abs(lag_1) | |
1420 |
|
1416 | |||
1421 | #---------------- Calculo del SNR---------------------------------- |
|
1417 | #---------------- Calculo del SNR---------------------------------- | |
1422 | data_snrPP = S/self.noise |
|
1418 | data_snrPP = S/self.noise | |
1423 | for i in range(self.__nch): |
|
1419 | for i in range(self.__nch): | |
1424 | for j in range(self.__nHeis): |
|
1420 | for j in range(self.__nHeis): | |
1425 | if data_snrPP[i][j] < 1.e-20: |
|
1421 | if data_snrPP[i][j] < 1.e-20: | |
1426 | data_snrPP[i][j] = 1.e-20 |
|
1422 | data_snrPP[i][j] = 1.e-20 | |
1427 |
|
1423 | |||
1428 | #----------------- Calculo del ancho espectral ---------------------- |
|
1424 | #----------------- Calculo del ancho espectral ---------------------- | |
1429 | L = S/R1 |
|
1425 | L = S/R1 | |
1430 | L = numpy.where(L<0,1,L) |
|
1426 | L = numpy.where(L<0,1,L) | |
1431 | L = numpy.log(L) |
|
1427 | L = numpy.log(L) | |
1432 | tmp = numpy.sqrt(numpy.absolute(L)) |
|
1428 | tmp = numpy.sqrt(numpy.absolute(L)) | |
1433 | data_specwidth = (self.lambda_/(2*math.sqrt(2)*math.pi*self.ippSec*self.nCohInt))*tmp*numpy.sign(L) |
|
1429 | data_specwidth = (self.lambda_/(2*math.sqrt(2)*math.pi*self.ippSec*self.nCohInt))*tmp*numpy.sign(L) | |
1434 | n = self.__profIndex |
|
1430 | n = self.__profIndex | |
1435 |
|
1431 | |||
1436 | self.__buffer = numpy.zeros((self.__nch, self.__nProf,self.__nHeis), dtype='complex') |
|
1432 | self.__buffer = numpy.zeros((self.__nch, self.__nProf,self.__nHeis), dtype='complex') | |
1437 | self.__profIndex = 0 |
|
1433 | self.__profIndex = 0 | |
1438 | return data_power,data_intensity,data_velocity,data_snrPP,data_specwidth,n |
|
1434 | return data_power,data_intensity,data_velocity,data_snrPP,data_specwidth,n | |
1439 |
|
1435 | |||
1440 |
|
1436 | |||
1441 | def pulsePairbyProfiles(self,dataOut): |
|
1437 | def pulsePairbyProfiles(self,dataOut): | |
1442 |
|
1438 | |||
1443 | self.__dataReady = False |
|
1439 | self.__dataReady = False | |
1444 | data_power = None |
|
1440 | data_power = None | |
1445 | data_intensity = None |
|
1441 | data_intensity = None | |
1446 | data_velocity = None |
|
1442 | data_velocity = None | |
1447 | data_specwidth = None |
|
1443 | data_specwidth = None | |
1448 | data_snrPP = None |
|
1444 | data_snrPP = None | |
1449 | self.putData(data=dataOut.data) |
|
1445 | self.putData(data=dataOut.data) | |
1450 | if self.__profIndex == self.n: |
|
1446 | if self.__profIndex == self.n: | |
1451 | data_power,data_intensity, data_velocity,data_snrPP,data_specwidth, n = self.pushData(dataOut=dataOut) |
|
1447 | data_power,data_intensity, data_velocity,data_snrPP,data_specwidth, n = self.pushData(dataOut=dataOut) | |
1452 | self.__dataReady = True |
|
1448 | self.__dataReady = True | |
1453 |
|
1449 | |||
1454 | return data_power, data_intensity, data_velocity, data_snrPP, data_specwidth |
|
1450 | return data_power, data_intensity, data_velocity, data_snrPP, data_specwidth | |
1455 |
|
1451 | |||
1456 |
|
1452 | |||
1457 | def pulsePairOp(self, dataOut, datatime= None): |
|
1453 | def pulsePairOp(self, dataOut, datatime= None): | |
1458 |
|
1454 | |||
1459 | if self.__initime == None: |
|
1455 | if self.__initime == None: | |
1460 | self.__initime = datatime |
|
1456 | self.__initime = datatime | |
1461 | data_power, data_intensity, data_velocity, data_snrPP, data_specwidth = self.pulsePairbyProfiles(dataOut) |
|
1457 | data_power, data_intensity, data_velocity, data_snrPP, data_specwidth = self.pulsePairbyProfiles(dataOut) | |
1462 | self.__lastdatatime = datatime |
|
1458 | self.__lastdatatime = datatime | |
1463 |
|
1459 | |||
1464 | if data_power is None: |
|
1460 | if data_power is None: | |
1465 | return None, None, None,None,None,None |
|
1461 | return None, None, None,None,None,None | |
1466 |
|
1462 | |||
1467 | avgdatatime = self.__initime |
|
1463 | avgdatatime = self.__initime | |
1468 | deltatime = datatime - self.__lastdatatime |
|
1464 | deltatime = datatime - self.__lastdatatime | |
1469 | self.__initime = datatime |
|
1465 | self.__initime = datatime | |
1470 |
|
1466 | |||
1471 | return data_power, data_intensity, data_velocity, data_snrPP, data_specwidth, avgdatatime |
|
1467 | return data_power, data_intensity, data_velocity, data_snrPP, data_specwidth, avgdatatime | |
1472 |
|
1468 | |||
1473 | def run(self, dataOut,n = None,removeDC= False, overlapping= False,**kwargs): |
|
1469 | def run(self, dataOut,n = None,removeDC= False, overlapping= False,**kwargs): | |
1474 |
|
1470 | |||
1475 | if not self.isConfig: |
|
1471 | if not self.isConfig: | |
1476 | self.setup(dataOut = dataOut, n = n , removeDC=removeDC , **kwargs) |
|
1472 | self.setup(dataOut = dataOut, n = n , removeDC=removeDC , **kwargs) | |
1477 | self.isConfig = True |
|
1473 | self.isConfig = True | |
1478 | data_power, data_intensity, data_velocity,data_snrPP,data_specwidth, avgdatatime = self.pulsePairOp(dataOut, dataOut.utctime) |
|
1474 | data_power, data_intensity, data_velocity,data_snrPP,data_specwidth, avgdatatime = self.pulsePairOp(dataOut, dataOut.utctime) | |
1479 | dataOut.flagNoData = True |
|
1475 | dataOut.flagNoData = True | |
1480 |
|
1476 | |||
1481 | if self.__dataReady: |
|
1477 | if self.__dataReady: | |
1482 | dataOut.nCohInt *= self.n |
|
1478 | dataOut.nCohInt *= self.n | |
1483 | dataOut.dataPP_POW = data_intensity # S |
|
1479 | dataOut.dataPP_POW = data_intensity # S | |
1484 | dataOut.dataPP_POWER = data_power # P |
|
1480 | dataOut.dataPP_POWER = data_power # P | |
1485 | dataOut.dataPP_DOP = data_velocity |
|
1481 | dataOut.dataPP_DOP = data_velocity | |
1486 | dataOut.dataPP_SNR = data_snrPP |
|
1482 | dataOut.dataPP_SNR = data_snrPP | |
1487 | dataOut.dataPP_WIDTH = data_specwidth |
|
1483 | dataOut.dataPP_WIDTH = data_specwidth | |
1488 | dataOut.PRFbyAngle = self.n #numero de PRF*cada angulo rotado que equivale a un tiempo. |
|
1484 | dataOut.PRFbyAngle = self.n #numero de PRF*cada angulo rotado que equivale a un tiempo. | |
1489 | dataOut.utctime = avgdatatime |
|
1485 | dataOut.utctime = avgdatatime | |
1490 | dataOut.flagNoData = False |
|
1486 | dataOut.flagNoData = False | |
1491 | return dataOut |
|
1487 | return dataOut | |
1492 |
|
1488 | |||
1493 |
|
1489 | |||
1494 |
|
1490 | |||
1495 | # import collections |
|
1491 | # import collections | |
1496 | # from scipy.stats import mode |
|
1492 | # from scipy.stats import mode | |
1497 | # |
|
1493 | # | |
1498 | # class Synchronize(Operation): |
|
1494 | # class Synchronize(Operation): | |
1499 | # |
|
1495 | # | |
1500 | # isConfig = False |
|
1496 | # isConfig = False | |
1501 | # __profIndex = 0 |
|
1497 | # __profIndex = 0 | |
1502 | # |
|
1498 | # | |
1503 | # def __init__(self, **kwargs): |
|
1499 | # def __init__(self, **kwargs): | |
1504 | # |
|
1500 | # | |
1505 | # Operation.__init__(self, **kwargs) |
|
1501 | # Operation.__init__(self, **kwargs) | |
1506 | # # self.isConfig = False |
|
1502 | # # self.isConfig = False | |
1507 | # self.__powBuffer = None |
|
1503 | # self.__powBuffer = None | |
1508 | # self.__startIndex = 0 |
|
1504 | # self.__startIndex = 0 | |
1509 | # self.__pulseFound = False |
|
1505 | # self.__pulseFound = False | |
1510 | # |
|
1506 | # | |
1511 | # def __findTxPulse(self, dataOut, channel=0, pulse_with = None): |
|
1507 | # def __findTxPulse(self, dataOut, channel=0, pulse_with = None): | |
1512 | # |
|
1508 | # | |
1513 | # #Read data |
|
1509 | # #Read data | |
1514 | # |
|
1510 | # | |
1515 | # powerdB = dataOut.getPower(channel = channel) |
|
1511 | # powerdB = dataOut.getPower(channel = channel) | |
1516 | # noisedB = dataOut.getNoise(channel = channel)[0] |
|
1512 | # noisedB = dataOut.getNoise(channel = channel)[0] | |
1517 | # |
|
1513 | # | |
1518 | # self.__powBuffer.extend(powerdB.flatten()) |
|
1514 | # self.__powBuffer.extend(powerdB.flatten()) | |
1519 | # |
|
1515 | # | |
1520 | # dataArray = numpy.array(self.__powBuffer) |
|
1516 | # dataArray = numpy.array(self.__powBuffer) | |
1521 | # |
|
1517 | # | |
1522 | # filteredPower = numpy.correlate(dataArray, dataArray[0:self.__nSamples], "same") |
|
1518 | # filteredPower = numpy.correlate(dataArray, dataArray[0:self.__nSamples], "same") | |
1523 | # |
|
1519 | # | |
1524 | # maxValue = numpy.nanmax(filteredPower) |
|
1520 | # maxValue = numpy.nanmax(filteredPower) | |
1525 | # |
|
1521 | # | |
1526 | # if maxValue < noisedB + 10: |
|
1522 | # if maxValue < noisedB + 10: | |
1527 | # #No se encuentra ningun pulso de transmision |
|
1523 | # #No se encuentra ningun pulso de transmision | |
1528 | # return None |
|
1524 | # return None | |
1529 | # |
|
1525 | # | |
1530 | # maxValuesIndex = numpy.where(filteredPower > maxValue - 0.1*abs(maxValue))[0] |
|
1526 | # maxValuesIndex = numpy.where(filteredPower > maxValue - 0.1*abs(maxValue))[0] | |
1531 | # |
|
1527 | # | |
1532 | # if len(maxValuesIndex) < 2: |
|
1528 | # if len(maxValuesIndex) < 2: | |
1533 | # #Solo se encontro un solo pulso de transmision de un baudio, esperando por el siguiente TX |
|
1529 | # #Solo se encontro un solo pulso de transmision de un baudio, esperando por el siguiente TX | |
1534 | # return None |
|
1530 | # return None | |
1535 | # |
|
1531 | # | |
1536 | # phasedMaxValuesIndex = maxValuesIndex - self.__nSamples |
|
1532 | # phasedMaxValuesIndex = maxValuesIndex - self.__nSamples | |
1537 | # |
|
1533 | # | |
1538 | # #Seleccionar solo valores con un espaciamiento de nSamples |
|
1534 | # #Seleccionar solo valores con un espaciamiento de nSamples | |
1539 | # pulseIndex = numpy.intersect1d(maxValuesIndex, phasedMaxValuesIndex) |
|
1535 | # pulseIndex = numpy.intersect1d(maxValuesIndex, phasedMaxValuesIndex) | |
1540 | # |
|
1536 | # | |
1541 | # if len(pulseIndex) < 2: |
|
1537 | # if len(pulseIndex) < 2: | |
1542 | # #Solo se encontro un pulso de transmision con ancho mayor a 1 |
|
1538 | # #Solo se encontro un pulso de transmision con ancho mayor a 1 | |
1543 | # return None |
|
1539 | # return None | |
1544 | # |
|
1540 | # | |
1545 | # spacing = pulseIndex[1:] - pulseIndex[:-1] |
|
1541 | # spacing = pulseIndex[1:] - pulseIndex[:-1] | |
1546 | # |
|
1542 | # | |
1547 | # #remover senales que se distancien menos de 10 unidades o muestras |
|
1543 | # #remover senales que se distancien menos de 10 unidades o muestras | |
1548 | # #(No deberian existir IPP menor a 10 unidades) |
|
1544 | # #(No deberian existir IPP menor a 10 unidades) | |
1549 | # |
|
1545 | # | |
1550 | # realIndex = numpy.where(spacing > 10 )[0] |
|
1546 | # realIndex = numpy.where(spacing > 10 )[0] | |
1551 | # |
|
1547 | # | |
1552 | # if len(realIndex) < 2: |
|
1548 | # if len(realIndex) < 2: | |
1553 | # #Solo se encontro un pulso de transmision con ancho mayor a 1 |
|
1549 | # #Solo se encontro un pulso de transmision con ancho mayor a 1 | |
1554 | # return None |
|
1550 | # return None | |
1555 | # |
|
1551 | # | |
1556 | # #Eliminar pulsos anchos (deja solo la diferencia entre IPPs) |
|
1552 | # #Eliminar pulsos anchos (deja solo la diferencia entre IPPs) | |
1557 | # realPulseIndex = pulseIndex[realIndex] |
|
1553 | # realPulseIndex = pulseIndex[realIndex] | |
1558 | # |
|
1554 | # | |
1559 | # period = mode(realPulseIndex[1:] - realPulseIndex[:-1])[0][0] |
|
1555 | # period = mode(realPulseIndex[1:] - realPulseIndex[:-1])[0][0] | |
1560 | # |
|
1556 | # | |
1561 | # print "IPP = %d samples" %period |
|
1557 | # print "IPP = %d samples" %period | |
1562 | # |
|
1558 | # | |
1563 | # self.__newNSamples = dataOut.nHeights #int(period) |
|
1559 | # self.__newNSamples = dataOut.nHeights #int(period) | |
1564 | # self.__startIndex = int(realPulseIndex[0]) |
|
1560 | # self.__startIndex = int(realPulseIndex[0]) | |
1565 | # |
|
1561 | # | |
1566 | # return 1 |
|
1562 | # return 1 | |
1567 | # |
|
1563 | # | |
1568 | # |
|
1564 | # | |
1569 | # def setup(self, nSamples, nChannels, buffer_size = 4): |
|
1565 | # def setup(self, nSamples, nChannels, buffer_size = 4): | |
1570 | # |
|
1566 | # | |
1571 | # self.__powBuffer = collections.deque(numpy.zeros( buffer_size*nSamples,dtype=numpy.float), |
|
1567 | # self.__powBuffer = collections.deque(numpy.zeros( buffer_size*nSamples,dtype=numpy.float), | |
1572 | # maxlen = buffer_size*nSamples) |
|
1568 | # maxlen = buffer_size*nSamples) | |
1573 | # |
|
1569 | # | |
1574 | # bufferList = [] |
|
1570 | # bufferList = [] | |
1575 | # |
|
1571 | # | |
1576 | # for i in range(nChannels): |
|
1572 | # for i in range(nChannels): | |
1577 | # bufferByChannel = collections.deque(numpy.zeros( buffer_size*nSamples, dtype=numpy.complex) + numpy.NAN, |
|
1573 | # bufferByChannel = collections.deque(numpy.zeros( buffer_size*nSamples, dtype=numpy.complex) + numpy.NAN, | |
1578 | # maxlen = buffer_size*nSamples) |
|
1574 | # maxlen = buffer_size*nSamples) | |
1579 | # |
|
1575 | # | |
1580 | # bufferList.append(bufferByChannel) |
|
1576 | # bufferList.append(bufferByChannel) | |
1581 | # |
|
1577 | # | |
1582 | # self.__nSamples = nSamples |
|
1578 | # self.__nSamples = nSamples | |
1583 | # self.__nChannels = nChannels |
|
1579 | # self.__nChannels = nChannels | |
1584 | # self.__bufferList = bufferList |
|
1580 | # self.__bufferList = bufferList | |
1585 | # |
|
1581 | # | |
1586 | # def run(self, dataOut, channel = 0): |
|
1582 | # def run(self, dataOut, channel = 0): | |
1587 | # |
|
1583 | # | |
1588 | # if not self.isConfig: |
|
1584 | # if not self.isConfig: | |
1589 | # nSamples = dataOut.nHeights |
|
1585 | # nSamples = dataOut.nHeights | |
1590 | # nChannels = dataOut.nChannels |
|
1586 | # nChannels = dataOut.nChannels | |
1591 | # self.setup(nSamples, nChannels) |
|
1587 | # self.setup(nSamples, nChannels) | |
1592 | # self.isConfig = True |
|
1588 | # self.isConfig = True | |
1593 | # |
|
1589 | # | |
1594 | # #Append new data to internal buffer |
|
1590 | # #Append new data to internal buffer | |
1595 | # for thisChannel in range(self.__nChannels): |
|
1591 | # for thisChannel in range(self.__nChannels): | |
1596 | # bufferByChannel = self.__bufferList[thisChannel] |
|
1592 | # bufferByChannel = self.__bufferList[thisChannel] | |
1597 | # bufferByChannel.extend(dataOut.data[thisChannel]) |
|
1593 | # bufferByChannel.extend(dataOut.data[thisChannel]) | |
1598 | # |
|
1594 | # | |
1599 | # if self.__pulseFound: |
|
1595 | # if self.__pulseFound: | |
1600 | # self.__startIndex -= self.__nSamples |
|
1596 | # self.__startIndex -= self.__nSamples | |
1601 | # |
|
1597 | # | |
1602 | # #Finding Tx Pulse |
|
1598 | # #Finding Tx Pulse | |
1603 | # if not self.__pulseFound: |
|
1599 | # if not self.__pulseFound: | |
1604 | # indexFound = self.__findTxPulse(dataOut, channel) |
|
1600 | # indexFound = self.__findTxPulse(dataOut, channel) | |
1605 | # |
|
1601 | # | |
1606 | # if indexFound == None: |
|
1602 | # if indexFound == None: | |
1607 | # dataOut.flagNoData = True |
|
1603 | # dataOut.flagNoData = True | |
1608 | # return |
|
1604 | # return | |
1609 | # |
|
1605 | # | |
1610 | # self.__arrayBuffer = numpy.zeros((self.__nChannels, self.__newNSamples), dtype = numpy.complex) |
|
1606 | # self.__arrayBuffer = numpy.zeros((self.__nChannels, self.__newNSamples), dtype = numpy.complex) | |
1611 | # self.__pulseFound = True |
|
1607 | # self.__pulseFound = True | |
1612 | # self.__startIndex = indexFound |
|
1608 | # self.__startIndex = indexFound | |
1613 | # |
|
1609 | # | |
1614 | # #If pulse was found ... |
|
1610 | # #If pulse was found ... | |
1615 | # for thisChannel in range(self.__nChannels): |
|
1611 | # for thisChannel in range(self.__nChannels): | |
1616 | # bufferByChannel = self.__bufferList[thisChannel] |
|
1612 | # bufferByChannel = self.__bufferList[thisChannel] | |
1617 | # #print self.__startIndex |
|
1613 | # #print self.__startIndex | |
1618 | # x = numpy.array(bufferByChannel) |
|
1614 | # x = numpy.array(bufferByChannel) | |
1619 | # self.__arrayBuffer[thisChannel] = x[self.__startIndex:self.__startIndex+self.__newNSamples] |
|
1615 | # self.__arrayBuffer[thisChannel] = x[self.__startIndex:self.__startIndex+self.__newNSamples] | |
1620 | # |
|
1616 | # | |
1621 | # deltaHeight = dataOut.heightList[1] - dataOut.heightList[0] |
|
1617 | # deltaHeight = dataOut.heightList[1] - dataOut.heightList[0] | |
1622 | # dataOut.heightList = numpy.arange(self.__newNSamples)*deltaHeight |
|
1618 | # dataOut.heightList = numpy.arange(self.__newNSamples)*deltaHeight | |
1623 | # # dataOut.ippSeconds = (self.__newNSamples / deltaHeight)/1e6 |
|
1619 | # # dataOut.ippSeconds = (self.__newNSamples / deltaHeight)/1e6 | |
1624 | # |
|
1620 | # | |
1625 | # dataOut.data = self.__arrayBuffer |
|
1621 | # dataOut.data = self.__arrayBuffer | |
1626 | # |
|
1622 | # | |
1627 | # self.__startIndex += self.__newNSamples |
|
1623 | # self.__startIndex += self.__newNSamples | |
1628 | # |
|
1624 | # | |
1629 | # return |
|
1625 | # return |
General Comments 0
You need to be logged in to leave comments.
Login now