The requested changes are too big and content was truncated. Show full diff
@@ -1,517 +1,517 | |||
|
1 | 1 | import os |
|
2 | 2 | import datetime |
|
3 | 3 | import numpy |
|
4 | 4 | |
|
5 | 5 | from schainpy.model.graphics.jroplot_base import Plot, plt |
|
6 | 6 | from schainpy.model.graphics.jroplot_spectra import SpectraPlot, RTIPlot, CoherencePlot, SpectraCutPlot |
|
7 | 7 | from schainpy.utils import log |
|
8 | 8 | # libreria wradlib |
|
9 | 9 | import wradlib as wrl |
|
10 | 10 | |
|
11 | 11 | EARTH_RADIUS = 6.3710e3 |
|
12 | 12 | |
|
13 | 13 | |
|
14 | 14 | def ll2xy(lat1, lon1, lat2, lon2): |
|
15 | 15 | |
|
16 | 16 | p = 0.017453292519943295 |
|
17 | 17 | a = 0.5 - numpy.cos((lat2 - lat1) * p)/2 + numpy.cos(lat1 * p) * \ |
|
18 | 18 | numpy.cos(lat2 * p) * (1 - numpy.cos((lon2 - lon1) * p)) / 2 |
|
19 | 19 | r = 12742 * numpy.arcsin(numpy.sqrt(a)) |
|
20 | 20 | theta = numpy.arctan2(numpy.sin((lon2-lon1)*p)*numpy.cos(lat2*p), numpy.cos(lat1*p) |
|
21 | 21 | * numpy.sin(lat2*p)-numpy.sin(lat1*p)*numpy.cos(lat2*p)*numpy.cos((lon2-lon1)*p)) |
|
22 | 22 | theta = -theta + numpy.pi/2 |
|
23 | 23 | return r*numpy.cos(theta), r*numpy.sin(theta) |
|
24 | 24 | |
|
25 | 25 | |
|
26 | 26 | def km2deg(km): |
|
27 | 27 | ''' |
|
28 | 28 | Convert distance in km to degrees |
|
29 | 29 | ''' |
|
30 | 30 | |
|
31 | 31 | return numpy.rad2deg(km/EARTH_RADIUS) |
|
32 | 32 | |
|
33 | 33 | |
|
34 | 34 | |
|
35 | 35 | class SpectralMomentsPlot(SpectraPlot): |
|
36 | 36 | ''' |
|
37 | 37 | Plot for Spectral Moments |
|
38 | 38 | ''' |
|
39 | 39 | CODE = 'spc_moments' |
|
40 | 40 | # colormap = 'jet' |
|
41 | 41 | # plot_type = 'pcolor' |
|
42 | 42 | |
|
43 | 43 | class DobleGaussianPlot(SpectraPlot): |
|
44 | 44 | ''' |
|
45 | 45 | Plot for Double Gaussian Plot |
|
46 | 46 | ''' |
|
47 | 47 | CODE = 'gaussian_fit' |
|
48 | 48 | # colormap = 'jet' |
|
49 | 49 | # plot_type = 'pcolor' |
|
50 | 50 | |
|
51 | 51 | class DoubleGaussianSpectraCutPlot(SpectraCutPlot): |
|
52 | 52 | ''' |
|
53 | 53 | Plot SpectraCut with Double Gaussian Fit |
|
54 | 54 | ''' |
|
55 | 55 | CODE = 'cut_gaussian_fit' |
|
56 | 56 | |
|
57 | 57 | class SnrPlot(RTIPlot): |
|
58 | 58 | ''' |
|
59 | 59 | Plot for SNR Data |
|
60 | 60 | ''' |
|
61 | 61 | |
|
62 | 62 | CODE = 'snr' |
|
63 | 63 | colormap = 'jet' |
|
64 | 64 | |
|
65 | 65 | def update(self, dataOut): |
|
66 | 66 | |
|
67 | 67 | data = { |
|
68 | 68 | 'snr': 10*numpy.log10(dataOut.data_snr) |
|
69 | 69 | } |
|
70 | 70 | |
|
71 | 71 | return data, {} |
|
72 | 72 | |
|
73 | 73 | class DopplerPlot(RTIPlot): |
|
74 | 74 | ''' |
|
75 | 75 | Plot for DOPPLER Data (1st moment) |
|
76 | 76 | ''' |
|
77 | 77 | |
|
78 | 78 | CODE = 'dop' |
|
79 | 79 | colormap = 'jet' |
|
80 | 80 | |
|
81 | 81 | def update(self, dataOut): |
|
82 | 82 | |
|
83 | 83 | data = { |
|
84 | 84 | 'dop': 10*numpy.log10(dataOut.data_dop) |
|
85 | 85 | } |
|
86 | 86 | |
|
87 | 87 | return data, {} |
|
88 | 88 | |
|
89 | 89 | class PowerPlot(RTIPlot): |
|
90 | 90 | ''' |
|
91 | 91 | Plot for Power Data (0 moment) |
|
92 | 92 | ''' |
|
93 | 93 | |
|
94 | 94 | CODE = 'pow' |
|
95 | 95 | colormap = 'jet' |
|
96 | 96 | |
|
97 | 97 | def update(self, dataOut): |
|
98 | 98 | data = { |
|
99 | 99 | 'pow': 10*numpy.log10(dataOut.data_pow/dataOut.normFactor) |
|
100 | 100 | } |
|
101 | 101 | return data, {} |
|
102 | 102 | |
|
103 | 103 | class SpectralWidthPlot(RTIPlot): |
|
104 | 104 | ''' |
|
105 | 105 | Plot for Spectral Width Data (2nd moment) |
|
106 | 106 | ''' |
|
107 | 107 | |
|
108 | 108 | CODE = 'width' |
|
109 | 109 | colormap = 'jet' |
|
110 | 110 | |
|
111 | 111 | def update(self, dataOut): |
|
112 | 112 | |
|
113 | 113 | data = { |
|
114 | 114 | 'width': dataOut.data_width |
|
115 | 115 | } |
|
116 | 116 | |
|
117 | 117 | return data, {} |
|
118 | 118 | |
|
119 | 119 | class SkyMapPlot(Plot): |
|
120 | 120 | ''' |
|
121 | 121 | Plot for meteors detection data |
|
122 | 122 | ''' |
|
123 | 123 | |
|
124 | 124 | CODE = 'param' |
|
125 | 125 | |
|
126 | 126 | def setup(self): |
|
127 | 127 | |
|
128 | 128 | self.ncols = 1 |
|
129 | 129 | self.nrows = 1 |
|
130 | 130 | self.width = 7.2 |
|
131 | 131 | self.height = 7.2 |
|
132 | 132 | self.nplots = 1 |
|
133 | 133 | self.xlabel = 'Zonal Zenith Angle (deg)' |
|
134 | 134 | self.ylabel = 'Meridional Zenith Angle (deg)' |
|
135 | 135 | self.polar = True |
|
136 | 136 | self.ymin = -180 |
|
137 | 137 | self.ymax = 180 |
|
138 | 138 | self.colorbar = False |
|
139 | 139 | |
|
140 | 140 | def plot(self): |
|
141 | 141 | |
|
142 | 142 | arrayParameters = numpy.concatenate(self.data['param']) |
|
143 | 143 | error = arrayParameters[:, -1] |
|
144 | 144 | indValid = numpy.where(error == 0)[0] |
|
145 | 145 | finalMeteor = arrayParameters[indValid, :] |
|
146 | 146 | finalAzimuth = finalMeteor[:, 3] |
|
147 | 147 | finalZenith = finalMeteor[:, 4] |
|
148 | 148 | |
|
149 | 149 | x = finalAzimuth * numpy.pi / 180 |
|
150 | 150 | y = finalZenith |
|
151 | 151 | |
|
152 | 152 | ax = self.axes[0] |
|
153 | 153 | |
|
154 | 154 | if ax.firsttime: |
|
155 | 155 | ax.plot = ax.plot(x, y, 'bo', markersize=5)[0] |
|
156 | 156 | else: |
|
157 | 157 | ax.plot.set_data(x, y) |
|
158 | 158 | |
|
159 | 159 | dt1 = self.getDateTime(self.data.min_time).strftime('%y/%m/%d %H:%M:%S') |
|
160 | 160 | dt2 = self.getDateTime(self.data.max_time).strftime('%y/%m/%d %H:%M:%S') |
|
161 | 161 | title = 'Meteor Detection Sky Map\n %s - %s \n Number of events: %5.0f\n' % (dt1, |
|
162 | 162 | dt2, |
|
163 | 163 | len(x)) |
|
164 | 164 | self.titles[0] = title |
|
165 | 165 | |
|
166 | 166 | |
|
167 | 167 | class GenericRTIPlot(Plot): |
|
168 | 168 | ''' |
|
169 | 169 | Plot for data_xxxx object |
|
170 | 170 | ''' |
|
171 | 171 | |
|
172 | 172 | CODE = 'param' |
|
173 | 173 | colormap = 'viridis' |
|
174 | 174 | plot_type = 'pcolorbuffer' |
|
175 | 175 | |
|
176 | 176 | def setup(self): |
|
177 | 177 | self.xaxis = 'time' |
|
178 | 178 | self.ncols = 1 |
|
179 | 179 | self.nrows = self.data.shape('param')[0] |
|
180 | 180 | self.nplots = self.nrows |
|
181 | 181 | self.plots_adjust.update({'hspace':0.8, 'left': 0.1, 'bottom': 0.08, 'right':0.95, 'top': 0.95}) |
|
182 | 182 | |
|
183 | 183 | if not self.xlabel: |
|
184 | 184 | self.xlabel = 'Time' |
|
185 | 185 | |
|
186 | 186 | self.ylabel = 'Range [km]' |
|
187 | 187 | if not self.titles: |
|
188 | 188 | self.titles = ['Param {}'.format(x) for x in range(self.nrows)] |
|
189 | 189 | |
|
190 | 190 | def update(self, dataOut): |
|
191 | 191 | |
|
192 | 192 | data = { |
|
193 | 193 | 'param' : numpy.concatenate([getattr(dataOut, attr) for attr in self.attr_data], axis=0) |
|
194 | 194 | } |
|
195 | 195 | |
|
196 | 196 | meta = {} |
|
197 | 197 | |
|
198 | 198 | return data, meta |
|
199 | 199 | |
|
200 | 200 | def plot(self): |
|
201 | 201 | # self.data.normalize_heights() |
|
202 | 202 | self.x = self.data.times |
|
203 | 203 | self.y = self.data.yrange |
|
204 | 204 | self.z = self.data['param'] |
|
205 | 205 | self.z = 10*numpy.log10(self.z) |
|
206 | 206 | self.z = numpy.ma.masked_invalid(self.z) |
|
207 | 207 | |
|
208 | 208 | if self.decimation is None: |
|
209 | 209 | x, y, z = self.fill_gaps(self.x, self.y, self.z) |
|
210 | 210 | else: |
|
211 | 211 | x, y, z = self.fill_gaps(*self.decimate()) |
|
212 | 212 | |
|
213 | 213 | for n, ax in enumerate(self.axes): |
|
214 | 214 | |
|
215 | 215 | self.zmax = self.zmax if self.zmax is not None else numpy.max( |
|
216 | 216 | self.z[n]) |
|
217 | 217 | self.zmin = self.zmin if self.zmin is not None else numpy.min( |
|
218 | 218 | self.z[n]) |
|
219 | 219 | |
|
220 | 220 | if ax.firsttime: |
|
221 | 221 | if self.zlimits is not None: |
|
222 | 222 | self.zmin, self.zmax = self.zlimits[n] |
|
223 | 223 | |
|
224 | 224 | ax.plt = ax.pcolormesh(x, y, z[n].T * self.factors[n], |
|
225 | 225 | vmin=self.zmin, |
|
226 | 226 | vmax=self.zmax, |
|
227 | 227 | cmap=self.cmaps[n] |
|
228 | 228 | ) |
|
229 | 229 | else: |
|
230 | 230 | if self.zlimits is not None: |
|
231 | 231 | self.zmin, self.zmax = self.zlimits[n] |
|
232 | 232 | ax.collections.remove(ax.collections[0]) |
|
233 | 233 | ax.plt = ax.pcolormesh(x, y, z[n].T * self.factors[n], |
|
234 | 234 | vmin=self.zmin, |
|
235 | 235 | vmax=self.zmax, |
|
236 | 236 | cmap=self.cmaps[n] |
|
237 | 237 | ) |
|
238 | 238 | |
|
239 | 239 | |
|
240 | 240 | class PolarMapPlot(Plot): |
|
241 | 241 | ''' |
|
242 | 242 | Plot for weather radar |
|
243 | 243 | ''' |
|
244 | 244 | |
|
245 | 245 | CODE = 'param' |
|
246 | 246 | colormap = 'seismic' |
|
247 | 247 | |
|
248 | 248 | def setup(self): |
|
249 | 249 | self.ncols = 1 |
|
250 | 250 | self.nrows = 1 |
|
251 | 251 | self.width = 9 |
|
252 | 252 | self.height = 8 |
|
253 | 253 | self.mode = self.data.meta['mode'] |
|
254 | 254 | if self.channels is not None: |
|
255 | 255 | self.nplots = len(self.channels) |
|
256 | 256 | self.nrows = len(self.channels) |
|
257 | 257 | else: |
|
258 | 258 | self.nplots = self.data.shape(self.CODE)[0] |
|
259 | 259 | self.nrows = self.nplots |
|
260 | 260 | self.channels = list(range(self.nplots)) |
|
261 | 261 | if self.mode == 'E': |
|
262 | 262 | self.xlabel = 'Longitude' |
|
263 | 263 | self.ylabel = 'Latitude' |
|
264 | 264 | else: |
|
265 | 265 | self.xlabel = 'Range (km)' |
|
266 | 266 | self.ylabel = 'Height (km)' |
|
267 | 267 | self.bgcolor = 'white' |
|
268 | 268 | self.cb_labels = self.data.meta['units'] |
|
269 | 269 | self.lat = self.data.meta['latitude'] |
|
270 | 270 | self.lon = self.data.meta['longitude'] |
|
271 | 271 | self.xmin, self.xmax = float( |
|
272 | 272 | km2deg(self.xmin) + self.lon), float(km2deg(self.xmax) + self.lon) |
|
273 | 273 | self.ymin, self.ymax = float( |
|
274 | 274 | km2deg(self.ymin) + self.lat), float(km2deg(self.ymax) + self.lat) |
|
275 | 275 | # self.polar = True |
|
276 | 276 | |
|
277 | 277 | def plot(self): |
|
278 | 278 | |
|
279 | 279 | for n, ax in enumerate(self.axes): |
|
280 | 280 | data = self.data['param'][self.channels[n]] |
|
281 | 281 | |
|
282 | 282 | zeniths = numpy.linspace( |
|
283 | 283 | 0, self.data.meta['max_range'], data.shape[1]) |
|
284 | 284 | if self.mode == 'E': |
|
285 | 285 | azimuths = -numpy.radians(self.data.yrange)+numpy.pi/2 |
|
286 | 286 | r, theta = numpy.meshgrid(zeniths, azimuths) |
|
287 | 287 | x, y = r*numpy.cos(theta)*numpy.cos(numpy.radians(self.data.meta['elevation'])), r*numpy.sin( |
|
288 | 288 | theta)*numpy.cos(numpy.radians(self.data.meta['elevation'])) |
|
289 | 289 | x = km2deg(x) + self.lon |
|
290 | 290 | y = km2deg(y) + self.lat |
|
291 | 291 | else: |
|
292 | 292 | azimuths = numpy.radians(self.data.yrange) |
|
293 | 293 | r, theta = numpy.meshgrid(zeniths, azimuths) |
|
294 | 294 | x, y = r*numpy.cos(theta), r*numpy.sin(theta) |
|
295 | 295 | self.y = zeniths |
|
296 | 296 | |
|
297 | 297 | if ax.firsttime: |
|
298 | 298 | if self.zlimits is not None: |
|
299 | 299 | self.zmin, self.zmax = self.zlimits[n] |
|
300 | 300 | ax.plt = ax.pcolormesh( # r, theta, numpy.ma.array(data, mask=numpy.isnan(data)), |
|
301 | 301 | x, y, numpy.ma.array(data, mask=numpy.isnan(data)), |
|
302 | 302 | vmin=self.zmin, |
|
303 | 303 | vmax=self.zmax, |
|
304 | 304 | cmap=self.cmaps[n]) |
|
305 | 305 | else: |
|
306 | 306 | if self.zlimits is not None: |
|
307 | 307 | self.zmin, self.zmax = self.zlimits[n] |
|
308 | 308 | ax.collections.remove(ax.collections[0]) |
|
309 | 309 | ax.plt = ax.pcolormesh( # r, theta, numpy.ma.array(data, mask=numpy.isnan(data)), |
|
310 | 310 | x, y, numpy.ma.array(data, mask=numpy.isnan(data)), |
|
311 | 311 | vmin=self.zmin, |
|
312 | 312 | vmax=self.zmax, |
|
313 | 313 | cmap=self.cmaps[n]) |
|
314 | 314 | |
|
315 | 315 | if self.mode == 'A': |
|
316 | 316 | continue |
|
317 | 317 | |
|
318 | 318 | # plot district names |
|
319 | 319 | f = open('/data/workspace/schain_scripts/distrito.csv') |
|
320 | 320 | for line in f: |
|
321 | 321 | label, lon, lat = [s.strip() for s in line.split(',') if s] |
|
322 | 322 | lat = float(lat) |
|
323 | 323 | lon = float(lon) |
|
324 | 324 | # ax.plot(lon, lat, '.b', ms=2) |
|
325 | 325 | ax.text(lon, lat, label.decode('utf8'), ha='center', |
|
326 | 326 | va='bottom', size='8', color='black') |
|
327 | 327 | |
|
328 | 328 | # plot limites |
|
329 | 329 | limites = [] |
|
330 | 330 | tmp = [] |
|
331 | 331 | for line in open('/data/workspace/schain_scripts/lima.csv'): |
|
332 | 332 | if '#' in line: |
|
333 | 333 | if tmp: |
|
334 | 334 | limites.append(tmp) |
|
335 | 335 | tmp = [] |
|
336 | 336 | continue |
|
337 | 337 | values = line.strip().split(',') |
|
338 | 338 | tmp.append((float(values[0]), float(values[1]))) |
|
339 | 339 | for points in limites: |
|
340 | 340 | ax.add_patch( |
|
341 | 341 | Polygon(points, ec='k', fc='none', ls='--', lw=0.5)) |
|
342 | 342 | |
|
343 | 343 | # plot Cuencas |
|
344 | 344 | for cuenca in ('rimac', 'lurin', 'mala', 'chillon', 'chilca', 'chancay-huaral'): |
|
345 | 345 | f = open('/data/workspace/schain_scripts/{}.csv'.format(cuenca)) |
|
346 | 346 | values = [line.strip().split(',') for line in f] |
|
347 | 347 | points = [(float(s[0]), float(s[1])) for s in values] |
|
348 | 348 | ax.add_patch(Polygon(points, ec='b', fc='none')) |
|
349 | 349 | |
|
350 | 350 | # plot grid |
|
351 | 351 | for r in (15, 30, 45, 60): |
|
352 | 352 | ax.add_artist(plt.Circle((self.lon, self.lat), |
|
353 | 353 | km2deg(r), color='0.6', fill=False, lw=0.2)) |
|
354 | 354 | ax.text( |
|
355 | 355 | self.lon + (km2deg(r))*numpy.cos(60*numpy.pi/180), |
|
356 | 356 | self.lat + (km2deg(r))*numpy.sin(60*numpy.pi/180), |
|
357 | 357 | '{}km'.format(r), |
|
358 | 358 | ha='center', va='bottom', size='8', color='0.6', weight='heavy') |
|
359 | 359 | |
|
360 | 360 | if self.mode == 'E': |
|
361 | 361 | title = 'El={}$^\circ$'.format(self.data.meta['elevation']) |
|
362 | 362 | label = 'E{:02d}'.format(int(self.data.meta['elevation'])) |
|
363 | 363 | else: |
|
364 | 364 | title = 'Az={}$^\circ$'.format(self.data.meta['azimuth']) |
|
365 | 365 | label = 'A{:02d}'.format(int(self.data.meta['azimuth'])) |
|
366 | 366 | |
|
367 | 367 | self.save_labels = ['{}-{}'.format(lbl, label) for lbl in self.labels] |
|
368 | 368 | self.titles = ['{} {}'.format( |
|
369 | 369 | self.data.parameters[x], title) for x in self.channels] |
|
370 | 370 | |
|
371 | 371 | class WeatherPlot(Plot): |
|
372 | 372 | CODE = 'weather' |
|
373 | 373 | plot_name = 'weather' |
|
374 | 374 | plot_type = 'ppistyle' |
|
375 | 375 | buffering = False |
|
376 | 376 | |
|
377 | 377 | def setup(self): |
|
378 | 378 | self.ncols = 1 |
|
379 | 379 | self.nrows = 1 |
|
380 | 380 | self.nplots= 1 |
|
381 | 381 | self.ylabel= 'Range [Km]' |
|
382 | 382 | self.titles= ['Weather'] |
|
383 | 383 | self.colorbar=False |
|
384 | 384 | self.width =8 |
|
385 | 385 | self.height =8 |
|
386 | 386 | self.ini =0 |
|
387 | 387 | self.len_azi =0 |
|
388 | 388 | self.buffer_ini = None |
|
389 | 389 | self.buffer_azi = None |
|
390 | 390 | self.plots_adjust.update({'wspace': 0.4, 'hspace':0.4, 'left': 0.1, 'right': 0.9, 'bottom': 0.08}) |
|
391 | 391 | self.flag =0 |
|
392 | 392 | self.indicador= 0 |
|
393 | 393 | |
|
394 | 394 | def update(self, dataOut): |
|
395 | 395 | |
|
396 | 396 | data = {} |
|
397 | 397 | meta = {} |
|
398 | 398 | if hasattr(dataOut, 'dataPP_POWER'): |
|
399 | 399 | factor = 1 |
|
400 | 400 | |
|
401 | 401 | if hasattr(dataOut, 'nFFTPoints'): |
|
402 | 402 | factor = dataOut.normFactor |
|
403 | 403 | |
|
404 | print("factor",factor) | |
|
404 | ####print("factor",factor) | |
|
405 | 405 | data['weather'] = 10*numpy.log10(dataOut.data_360[0]/(factor)) |
|
406 | 406 | print("weather",data['weather']) |
|
407 | 407 | data['azi'] = dataOut.data_azi |
|
408 | 408 | return data, meta |
|
409 | 409 | |
|
410 | 410 | def const_ploteo(self,data_weather,data_azi,step,res): |
|
411 | 411 | if self.ini==0: |
|
412 | 412 | #------- AZIMUTH |
|
413 | 413 | n = (360/res)-len(data_azi) |
|
414 | 414 | start = data_azi[-1] + res |
|
415 | 415 | end = data_azi[0] - res |
|
416 | 416 | if start>end: |
|
417 | 417 | end = end + 360 |
|
418 | 418 | azi_vacia = numpy.linspace(start,end,int(n)) |
|
419 | 419 | azi_vacia = numpy.where(azi_vacia>360,azi_vacia-360,azi_vacia) |
|
420 | 420 | data_azi = numpy.hstack((data_azi,azi_vacia)) |
|
421 | 421 | # RADAR |
|
422 | 422 | val_mean = numpy.mean(data_weather[:,0]) |
|
423 | 423 | data_weather_cmp = numpy.ones([(360-data_weather.shape[0]),data_weather.shape[1]])*val_mean |
|
424 | 424 | data_weather = numpy.vstack((data_weather,data_weather_cmp)) |
|
425 | 425 | else: |
|
426 | 426 | # azimuth |
|
427 | 427 | flag=0 |
|
428 | 428 | start_azi = self.res_azi[0] |
|
429 | 429 | start = data_azi[0] |
|
430 | 430 | end = data_azi[-1] |
|
431 | 431 | print("start",start) |
|
432 | 432 | print("end",end) |
|
433 | 433 | if start< start_azi: |
|
434 | 434 | start = start +360 |
|
435 | 435 | if end <start_azi: |
|
436 | 436 | end = end +360 |
|
437 | 437 | |
|
438 | 438 | print("start",start) |
|
439 | 439 | print("end",end) |
|
440 | 440 | #### AQUI SERA LA MAGIA |
|
441 | 441 | pos_ini = int((start-start_azi)/res) |
|
442 | 442 | len_azi = len(data_azi) |
|
443 | 443 | if (360-pos_ini)<len_azi: |
|
444 | 444 | if pos_ini+1==360: |
|
445 | 445 | pos_ini=0 |
|
446 | 446 | else: |
|
447 | 447 | flag=1 |
|
448 | 448 | dif= 360-pos_ini |
|
449 | 449 | comp= len_azi-dif |
|
450 | 450 | |
|
451 | 451 | print(pos_ini) |
|
452 | 452 | print(len_azi) |
|
453 | 453 | print("shape",self.res_azi.shape) |
|
454 | 454 | if flag==0: |
|
455 | 455 | # AZIMUTH |
|
456 | 456 | self.res_azi[pos_ini:pos_ini+len_azi] = data_azi |
|
457 | 457 | # RADAR |
|
458 | 458 | self.res_weather[pos_ini:pos_ini+len_azi,:] = data_weather |
|
459 | 459 | else: |
|
460 | 460 | # AZIMUTH |
|
461 | 461 | self.res_azi[pos_ini:pos_ini+dif] = data_azi[0:dif] |
|
462 | 462 | self.res_azi[0:comp] = data_azi[dif:] |
|
463 | 463 | # RADAR |
|
464 | 464 | self.res_weather[pos_ini:pos_ini+dif,:] = data_weather[0:dif,:] |
|
465 | 465 | self.res_weather[0:comp,:] = data_weather[dif:,:] |
|
466 | 466 | flag=0 |
|
467 | 467 | data_azi = self.res_azi |
|
468 | 468 | data_weather = self.res_weather |
|
469 | 469 | |
|
470 | 470 | return data_weather,data_azi |
|
471 | 471 | |
|
472 | 472 | def plot(self): |
|
473 | 473 | print("--------------------------------------",self.ini,"-----------------------------------") |
|
474 | 474 | #numpy.set_printoptions(suppress=True) |
|
475 | 475 | #print(self.data.times) |
|
476 | 476 | thisDatetime = datetime.datetime.utcfromtimestamp(self.data.times[-1]) |
|
477 | 477 | data = self.data[-1] |
|
478 | 478 | # ALTURA altura_tmp_h |
|
479 | 479 | altura_h = (data['weather'].shape[1])/10.0 |
|
480 | 480 | stoprange = float(altura_h*1.5)#stoprange = float(33*1.5) por ahora 400 |
|
481 | 481 | rangestep = float(0.15) |
|
482 | 482 | r = numpy.arange(0, stoprange, rangestep) |
|
483 | 483 | self.y = 2*r |
|
484 | 484 | # RADAR |
|
485 | 485 | #data_weather = data['weather'] |
|
486 | 486 | # PEDESTAL |
|
487 | 487 | #data_azi = data['azi'] |
|
488 | 488 | res = 1 |
|
489 | 489 | # STEP |
|
490 | 490 | step = (360/(res*data['weather'].shape[0])) |
|
491 | 491 | #print("shape wr_data", wr_data.shape) |
|
492 | 492 | #print("shape wr_azi",wr_azi.shape) |
|
493 | 493 | #print("step",step) |
|
494 | 494 | print("Time---->",self.data.times[-1],thisDatetime) |
|
495 | 495 | #print("alturas", len(self.y)) |
|
496 | 496 | self.res_weather, self.res_azi = self.const_ploteo(data_weather=data['weather'],data_azi=data['azi'],step=step,res=res) |
|
497 | 497 | #numpy.set_printoptions(suppress=True) |
|
498 | 498 | #print("resultado",self.res_azi) |
|
499 | 499 | ########################################################## |
|
500 | 500 | ################# PLOTEO ################### |
|
501 | 501 | ########################################################## |
|
502 | 502 | |
|
503 | 503 | for i,ax in enumerate(self.axes): |
|
504 | 504 | if ax.firsttime: |
|
505 | 505 | plt.clf() |
|
506 | 506 | cgax, pm = wrl.vis.plot_ppi(self.res_weather,r=r,az=self.res_azi,fig=self.figures[0], proj='cg', vmin=1, vmax=60) |
|
507 | 507 | else: |
|
508 | 508 | plt.clf() |
|
509 | 509 | cgax, pm = wrl.vis.plot_ppi(self.res_weather,r=r,az=self.res_azi,fig=self.figures[0], proj='cg', vmin=1, vmax=60) |
|
510 | 510 | caax = cgax.parasites[0] |
|
511 | 511 | paax = cgax.parasites[1] |
|
512 | 512 | cbar = plt.gcf().colorbar(pm, pad=0.075) |
|
513 | 513 | caax.set_xlabel('x_range [km]') |
|
514 | 514 | caax.set_ylabel('y_range [km]') |
|
515 | 515 | plt.text(1.0, 1.05, 'azimuth '+str(thisDatetime)+"step"+str(self.ini), transform=caax.transAxes, va='bottom',ha='right') |
|
516 | 516 | |
|
517 | 517 | self.ini= self.ini+1 |
|
1 | NO CONTENT: modified file | |
The requested commit or file is too big and content was truncated. Show full diff |
@@ -1,1628 +1,1627 | |||
|
1 | 1 | import sys |
|
2 | 2 | import numpy,math |
|
3 | 3 | from scipy import interpolate |
|
4 | 4 | from schainpy.model.proc.jroproc_base import ProcessingUnit, Operation, MPDecorator |
|
5 | 5 | from schainpy.model.data.jrodata import Voltage,hildebrand_sekhon |
|
6 | 6 | from schainpy.utils import log |
|
7 | 7 | from time import time |
|
8 | 8 | |
|
9 | 9 | |
|
10 | 10 | |
|
11 | 11 | class VoltageProc(ProcessingUnit): |
|
12 | 12 | |
|
13 | 13 | def __init__(self): |
|
14 | 14 | |
|
15 | 15 | ProcessingUnit.__init__(self) |
|
16 | 16 | |
|
17 | 17 | self.dataOut = Voltage() |
|
18 | 18 | self.flip = 1 |
|
19 | 19 | self.setupReq = False |
|
20 | 20 | |
|
21 | 21 | def run(self): |
|
22 | 22 | |
|
23 | 23 | if self.dataIn.type == 'AMISR': |
|
24 | 24 | self.__updateObjFromAmisrInput() |
|
25 | 25 | |
|
26 | 26 | if self.dataIn.type == 'Voltage': |
|
27 | 27 | self.dataOut.copy(self.dataIn) |
|
28 | 28 | |
|
29 | 29 | def __updateObjFromAmisrInput(self): |
|
30 | 30 | |
|
31 | 31 | self.dataOut.timeZone = self.dataIn.timeZone |
|
32 | 32 | self.dataOut.dstFlag = self.dataIn.dstFlag |
|
33 | 33 | self.dataOut.errorCount = self.dataIn.errorCount |
|
34 | 34 | self.dataOut.useLocalTime = self.dataIn.useLocalTime |
|
35 | 35 | |
|
36 | 36 | self.dataOut.flagNoData = self.dataIn.flagNoData |
|
37 | 37 | self.dataOut.data = self.dataIn.data |
|
38 | 38 | self.dataOut.utctime = self.dataIn.utctime |
|
39 | 39 | self.dataOut.channelList = self.dataIn.channelList |
|
40 | 40 | #self.dataOut.timeInterval = self.dataIn.timeInterval |
|
41 | 41 | self.dataOut.heightList = self.dataIn.heightList |
|
42 | 42 | self.dataOut.nProfiles = self.dataIn.nProfiles |
|
43 | 43 | |
|
44 | 44 | self.dataOut.nCohInt = self.dataIn.nCohInt |
|
45 | 45 | self.dataOut.ippSeconds = self.dataIn.ippSeconds |
|
46 | 46 | self.dataOut.frequency = self.dataIn.frequency |
|
47 | 47 | |
|
48 | 48 | self.dataOut.azimuth = self.dataIn.azimuth |
|
49 | 49 | self.dataOut.zenith = self.dataIn.zenith |
|
50 | 50 | |
|
51 | 51 | self.dataOut.beam.codeList = self.dataIn.beam.codeList |
|
52 | 52 | self.dataOut.beam.azimuthList = self.dataIn.beam.azimuthList |
|
53 | 53 | self.dataOut.beam.zenithList = self.dataIn.beam.zenithList |
|
54 | 54 | |
|
55 | 55 | |
|
56 | 56 | class selectChannels(Operation): |
|
57 | 57 | |
|
58 | 58 | def run(self, dataOut, channelList): |
|
59 | 59 | |
|
60 | 60 | channelIndexList = [] |
|
61 | 61 | self.dataOut = dataOut |
|
62 | 62 | for channel in channelList: |
|
63 | 63 | if channel not in self.dataOut.channelList: |
|
64 | 64 | raise ValueError("Channel %d is not in %s" %(channel, str(self.dataOut.channelList))) |
|
65 | 65 | |
|
66 | 66 | index = self.dataOut.channelList.index(channel) |
|
67 | 67 | channelIndexList.append(index) |
|
68 | 68 | self.selectChannelsByIndex(channelIndexList) |
|
69 | 69 | return self.dataOut |
|
70 | 70 | |
|
71 | 71 | def selectChannelsByIndex(self, channelIndexList): |
|
72 | 72 | """ |
|
73 | 73 | Selecciona un bloque de datos en base a canales segun el channelIndexList |
|
74 | 74 | |
|
75 | 75 | Input: |
|
76 | 76 | channelIndexList : lista sencilla de canales a seleccionar por ej. [2,3,7] |
|
77 | 77 | |
|
78 | 78 | Affected: |
|
79 | 79 | self.dataOut.data |
|
80 | 80 | self.dataOut.channelIndexList |
|
81 | 81 | self.dataOut.nChannels |
|
82 | 82 | self.dataOut.m_ProcessingHeader.totalSpectra |
|
83 | 83 | self.dataOut.systemHeaderObj.numChannels |
|
84 | 84 | self.dataOut.m_ProcessingHeader.blockSize |
|
85 | 85 | |
|
86 | 86 | Return: |
|
87 | 87 | None |
|
88 | 88 | """ |
|
89 | 89 | |
|
90 | 90 | for channelIndex in channelIndexList: |
|
91 | 91 | if channelIndex not in self.dataOut.channelIndexList: |
|
92 | 92 | raise ValueError("The value %d in channelIndexList is not valid" %channelIndex) |
|
93 | 93 | |
|
94 | 94 | if self.dataOut.type == 'Voltage': |
|
95 | 95 | if self.dataOut.flagDataAsBlock: |
|
96 | 96 | """ |
|
97 | 97 | Si la data es obtenida por bloques, dimension = [nChannels, nProfiles, nHeis] |
|
98 | 98 | """ |
|
99 | 99 | data = self.dataOut.data[channelIndexList,:,:] |
|
100 | 100 | else: |
|
101 | 101 | data = self.dataOut.data[channelIndexList,:] |
|
102 | 102 | |
|
103 | 103 | self.dataOut.data = data |
|
104 | 104 | # self.dataOut.channelList = [self.dataOut.channelList[i] for i in channelIndexList] |
|
105 | 105 | self.dataOut.channelList = range(len(channelIndexList)) |
|
106 | 106 | |
|
107 | 107 | elif self.dataOut.type == 'Spectra': |
|
108 | 108 | data_spc = self.dataOut.data_spc[channelIndexList, :] |
|
109 | 109 | data_dc = self.dataOut.data_dc[channelIndexList, :] |
|
110 | 110 | |
|
111 | 111 | self.dataOut.data_spc = data_spc |
|
112 | 112 | self.dataOut.data_dc = data_dc |
|
113 | 113 | |
|
114 | 114 | # self.dataOut.channelList = [self.dataOut.channelList[i] for i in channelIndexList] |
|
115 | 115 | self.dataOut.channelList = range(len(channelIndexList)) |
|
116 | 116 | self.__selectPairsByChannel(channelIndexList) |
|
117 | 117 | |
|
118 | 118 | return 1 |
|
119 | 119 | |
|
120 | 120 | def __selectPairsByChannel(self, channelList=None): |
|
121 | 121 | |
|
122 | 122 | if channelList == None: |
|
123 | 123 | return |
|
124 | 124 | |
|
125 | 125 | pairsIndexListSelected = [] |
|
126 | 126 | for pairIndex in self.dataOut.pairsIndexList: |
|
127 | 127 | # First pair |
|
128 | 128 | if self.dataOut.pairsList[pairIndex][0] not in channelList: |
|
129 | 129 | continue |
|
130 | 130 | # Second pair |
|
131 | 131 | if self.dataOut.pairsList[pairIndex][1] not in channelList: |
|
132 | 132 | continue |
|
133 | 133 | |
|
134 | 134 | pairsIndexListSelected.append(pairIndex) |
|
135 | 135 | |
|
136 | 136 | if not pairsIndexListSelected: |
|
137 | 137 | self.dataOut.data_cspc = None |
|
138 | 138 | self.dataOut.pairsList = [] |
|
139 | 139 | return |
|
140 | 140 | |
|
141 | 141 | self.dataOut.data_cspc = self.dataOut.data_cspc[pairsIndexListSelected] |
|
142 | 142 | self.dataOut.pairsList = [self.dataOut.pairsList[i] |
|
143 | 143 | for i in pairsIndexListSelected] |
|
144 | 144 | |
|
145 | 145 | return |
|
146 | 146 | |
|
147 | 147 | class selectHeights(Operation): |
|
148 | 148 | |
|
149 | 149 | def run(self, dataOut, minHei=None, maxHei=None, minIndex=None, maxIndex=None): |
|
150 | 150 | """ |
|
151 | 151 | Selecciona un bloque de datos en base a un grupo de valores de alturas segun el rango |
|
152 | 152 | minHei <= height <= maxHei |
|
153 | 153 | |
|
154 | 154 | Input: |
|
155 | 155 | minHei : valor minimo de altura a considerar |
|
156 | 156 | maxHei : valor maximo de altura a considerar |
|
157 | 157 | |
|
158 | 158 | Affected: |
|
159 | 159 | Indirectamente son cambiados varios valores a travez del metodo selectHeightsByIndex |
|
160 | 160 | |
|
161 | 161 | Return: |
|
162 | 162 | 1 si el metodo se ejecuto con exito caso contrario devuelve 0 |
|
163 | 163 | """ |
|
164 | 164 | |
|
165 | 165 | self.dataOut = dataOut |
|
166 | 166 | |
|
167 | 167 | if minHei and maxHei: |
|
168 | 168 | |
|
169 | 169 | if (minHei < self.dataOut.heightList[0]): |
|
170 | 170 | minHei = self.dataOut.heightList[0] |
|
171 | 171 | |
|
172 | 172 | if (maxHei > self.dataOut.heightList[-1]): |
|
173 | 173 | maxHei = self.dataOut.heightList[-1] |
|
174 | 174 | |
|
175 | 175 | minIndex = 0 |
|
176 | 176 | maxIndex = 0 |
|
177 | 177 | heights = self.dataOut.heightList |
|
178 | 178 | |
|
179 | 179 | inda = numpy.where(heights >= minHei) |
|
180 | 180 | indb = numpy.where(heights <= maxHei) |
|
181 | 181 | |
|
182 | 182 | try: |
|
183 | 183 | minIndex = inda[0][0] |
|
184 | 184 | except: |
|
185 | 185 | minIndex = 0 |
|
186 | 186 | |
|
187 | 187 | try: |
|
188 | 188 | maxIndex = indb[0][-1] |
|
189 | 189 | except: |
|
190 | 190 | maxIndex = len(heights) |
|
191 | 191 | |
|
192 | 192 | self.selectHeightsByIndex(minIndex, maxIndex) |
|
193 | 193 | |
|
194 | 194 | return self.dataOut |
|
195 | 195 | |
|
196 | 196 | def selectHeightsByIndex(self, minIndex, maxIndex): |
|
197 | 197 | """ |
|
198 | 198 | Selecciona un bloque de datos en base a un grupo indices de alturas segun el rango |
|
199 | 199 | minIndex <= index <= maxIndex |
|
200 | 200 | |
|
201 | 201 | Input: |
|
202 | 202 | minIndex : valor de indice minimo de altura a considerar |
|
203 | 203 | maxIndex : valor de indice maximo de altura a considerar |
|
204 | 204 | |
|
205 | 205 | Affected: |
|
206 | 206 | self.dataOut.data |
|
207 | 207 | self.dataOut.heightList |
|
208 | 208 | |
|
209 | 209 | Return: |
|
210 | 210 | 1 si el metodo se ejecuto con exito caso contrario devuelve 0 |
|
211 | 211 | """ |
|
212 | 212 | |
|
213 | 213 | if self.dataOut.type == 'Voltage': |
|
214 | 214 | if (minIndex < 0) or (minIndex > maxIndex): |
|
215 | 215 | raise ValueError("Height index range (%d,%d) is not valid" % (minIndex, maxIndex)) |
|
216 | 216 | |
|
217 | 217 | if (maxIndex >= self.dataOut.nHeights): |
|
218 | 218 | maxIndex = self.dataOut.nHeights |
|
219 | 219 | |
|
220 | 220 | #voltage |
|
221 | 221 | if self.dataOut.flagDataAsBlock: |
|
222 | 222 | """ |
|
223 | 223 | Si la data es obtenida por bloques, dimension = [nChannels, nProfiles, nHeis] |
|
224 | 224 | """ |
|
225 | 225 | data = self.dataOut.data[:,:, minIndex:maxIndex] |
|
226 | 226 | else: |
|
227 | 227 | data = self.dataOut.data[:, minIndex:maxIndex] |
|
228 | 228 | |
|
229 | 229 | # firstHeight = self.dataOut.heightList[minIndex] |
|
230 | 230 | |
|
231 | 231 | self.dataOut.data = data |
|
232 | 232 | self.dataOut.heightList = self.dataOut.heightList[minIndex:maxIndex] |
|
233 | 233 | |
|
234 | 234 | if self.dataOut.nHeights <= 1: |
|
235 | 235 | raise ValueError("selectHeights: Too few heights. Current number of heights is %d" %(self.dataOut.nHeights)) |
|
236 | 236 | elif self.dataOut.type == 'Spectra': |
|
237 | 237 | if (minIndex < 0) or (minIndex > maxIndex): |
|
238 | 238 | raise ValueError("Error selecting heights: Index range (%d,%d) is not valid" % ( |
|
239 | 239 | minIndex, maxIndex)) |
|
240 | 240 | |
|
241 | 241 | if (maxIndex >= self.dataOut.nHeights): |
|
242 | 242 | maxIndex = self.dataOut.nHeights - 1 |
|
243 | 243 | |
|
244 | 244 | # Spectra |
|
245 | 245 | data_spc = self.dataOut.data_spc[:, :, minIndex:maxIndex + 1] |
|
246 | 246 | |
|
247 | 247 | data_cspc = None |
|
248 | 248 | if self.dataOut.data_cspc is not None: |
|
249 | 249 | data_cspc = self.dataOut.data_cspc[:, :, minIndex:maxIndex + 1] |
|
250 | 250 | |
|
251 | 251 | data_dc = None |
|
252 | 252 | if self.dataOut.data_dc is not None: |
|
253 | 253 | data_dc = self.dataOut.data_dc[:, minIndex:maxIndex + 1] |
|
254 | 254 | |
|
255 | 255 | self.dataOut.data_spc = data_spc |
|
256 | 256 | self.dataOut.data_cspc = data_cspc |
|
257 | 257 | self.dataOut.data_dc = data_dc |
|
258 | 258 | |
|
259 | 259 | self.dataOut.heightList = self.dataOut.heightList[minIndex:maxIndex + 1] |
|
260 | 260 | |
|
261 | 261 | return 1 |
|
262 | 262 | |
|
263 | 263 | |
|
264 | 264 | class filterByHeights(Operation): |
|
265 | 265 | |
|
266 | 266 | def run(self, dataOut, window): |
|
267 | 267 | |
|
268 | 268 | deltaHeight = dataOut.heightList[1] - dataOut.heightList[0] |
|
269 | 269 | |
|
270 | 270 | if window == None: |
|
271 | 271 | window = (dataOut.radarControllerHeaderObj.txA/dataOut.radarControllerHeaderObj.nBaud) / deltaHeight |
|
272 | 272 | |
|
273 | 273 | newdelta = deltaHeight * window |
|
274 | 274 | r = dataOut.nHeights % window |
|
275 | 275 | newheights = (dataOut.nHeights-r)/window |
|
276 | 276 | |
|
277 | 277 | if newheights <= 1: |
|
278 | 278 | raise ValueError("filterByHeights: Too few heights. Current number of heights is %d and window is %d" %(dataOut.nHeights, window)) |
|
279 | 279 | |
|
280 | 280 | if dataOut.flagDataAsBlock: |
|
281 | 281 | """ |
|
282 | 282 | Si la data es obtenida por bloques, dimension = [nChannels, nProfiles, nHeis] |
|
283 | 283 | """ |
|
284 | 284 | buffer = dataOut.data[:, :, 0:int(dataOut.nHeights-r)] |
|
285 | 285 | buffer = buffer.reshape(dataOut.nChannels, dataOut.nProfiles, int(dataOut.nHeights/window), window) |
|
286 | 286 | buffer = numpy.sum(buffer,3) |
|
287 | 287 | |
|
288 | 288 | else: |
|
289 | 289 | buffer = dataOut.data[:,0:int(dataOut.nHeights-r)] |
|
290 | 290 | buffer = buffer.reshape(dataOut.nChannels,int(dataOut.nHeights/window),int(window)) |
|
291 | 291 | buffer = numpy.sum(buffer,2) |
|
292 | 292 | |
|
293 | 293 | dataOut.data = buffer |
|
294 | 294 | dataOut.heightList = dataOut.heightList[0] + numpy.arange( newheights )*newdelta |
|
295 | 295 | dataOut.windowOfFilter = window |
|
296 | 296 | |
|
297 | 297 | return dataOut |
|
298 | 298 | |
|
299 | 299 | |
|
300 | 300 | class setH0(Operation): |
|
301 | 301 | |
|
302 | 302 | def run(self, dataOut, h0, deltaHeight = None): |
|
303 | 303 | |
|
304 | 304 | if not deltaHeight: |
|
305 | 305 | deltaHeight = dataOut.heightList[1] - dataOut.heightList[0] |
|
306 | 306 | |
|
307 | 307 | nHeights = dataOut.nHeights |
|
308 | 308 | |
|
309 | 309 | newHeiRange = h0 + numpy.arange(nHeights)*deltaHeight |
|
310 | 310 | |
|
311 | 311 | dataOut.heightList = newHeiRange |
|
312 | 312 | |
|
313 | 313 | return dataOut |
|
314 | 314 | |
|
315 | 315 | |
|
316 | 316 | class deFlip(Operation): |
|
317 | 317 | |
|
318 | 318 | def run(self, dataOut, channelList = []): |
|
319 | 319 | |
|
320 | 320 | data = dataOut.data.copy() |
|
321 | 321 | |
|
322 | 322 | if dataOut.flagDataAsBlock: |
|
323 | 323 | flip = self.flip |
|
324 | 324 | profileList = list(range(dataOut.nProfiles)) |
|
325 | 325 | |
|
326 | 326 | if not channelList: |
|
327 | 327 | for thisProfile in profileList: |
|
328 | 328 | data[:,thisProfile,:] = data[:,thisProfile,:]*flip |
|
329 | 329 | flip *= -1.0 |
|
330 | 330 | else: |
|
331 | 331 | for thisChannel in channelList: |
|
332 | 332 | if thisChannel not in dataOut.channelList: |
|
333 | 333 | continue |
|
334 | 334 | |
|
335 | 335 | for thisProfile in profileList: |
|
336 | 336 | data[thisChannel,thisProfile,:] = data[thisChannel,thisProfile,:]*flip |
|
337 | 337 | flip *= -1.0 |
|
338 | 338 | |
|
339 | 339 | self.flip = flip |
|
340 | 340 | |
|
341 | 341 | else: |
|
342 | 342 | if not channelList: |
|
343 | 343 | data[:,:] = data[:,:]*self.flip |
|
344 | 344 | else: |
|
345 | 345 | for thisChannel in channelList: |
|
346 | 346 | if thisChannel not in dataOut.channelList: |
|
347 | 347 | continue |
|
348 | 348 | |
|
349 | 349 | data[thisChannel,:] = data[thisChannel,:]*self.flip |
|
350 | 350 | |
|
351 | 351 | self.flip *= -1. |
|
352 | 352 | |
|
353 | 353 | dataOut.data = data |
|
354 | 354 | |
|
355 | 355 | return dataOut |
|
356 | 356 | |
|
357 | 357 | |
|
358 | 358 | class setAttribute(Operation): |
|
359 | 359 | ''' |
|
360 | 360 | Set an arbitrary attribute(s) to dataOut |
|
361 | 361 | ''' |
|
362 | 362 | |
|
363 | 363 | def __init__(self): |
|
364 | 364 | |
|
365 | 365 | Operation.__init__(self) |
|
366 | 366 | self._ready = False |
|
367 | 367 | |
|
368 | 368 | def run(self, dataOut, **kwargs): |
|
369 | 369 | |
|
370 | 370 | for key, value in kwargs.items(): |
|
371 | 371 | setattr(dataOut, key, value) |
|
372 | 372 | |
|
373 | 373 | return dataOut |
|
374 | 374 | |
|
375 | 375 | |
|
376 | 376 | @MPDecorator |
|
377 | 377 | class printAttribute(Operation): |
|
378 | 378 | ''' |
|
379 | 379 | Print an arbitrary attribute of dataOut |
|
380 | 380 | ''' |
|
381 | 381 | |
|
382 | 382 | def __init__(self): |
|
383 | 383 | |
|
384 | 384 | Operation.__init__(self) |
|
385 | 385 | |
|
386 | 386 | def run(self, dataOut, attributes): |
|
387 | 387 | |
|
388 | 388 | if isinstance(attributes, str): |
|
389 | 389 | attributes = [attributes] |
|
390 | 390 | for attr in attributes: |
|
391 | 391 | if hasattr(dataOut, attr): |
|
392 | 392 | log.log(getattr(dataOut, attr), attr) |
|
393 | 393 | |
|
394 | 394 | |
|
395 | 395 | class interpolateHeights(Operation): |
|
396 | 396 | |
|
397 | 397 | def run(self, dataOut, topLim, botLim): |
|
398 | 398 | #69 al 72 para julia |
|
399 | 399 | #82-84 para meteoros |
|
400 | 400 | if len(numpy.shape(dataOut.data))==2: |
|
401 | 401 | sampInterp = (dataOut.data[:,botLim-1] + dataOut.data[:,topLim+1])/2 |
|
402 | 402 | sampInterp = numpy.transpose(numpy.tile(sampInterp,(topLim-botLim + 1,1))) |
|
403 | 403 | #dataOut.data[:,botLim:limSup+1] = sampInterp |
|
404 | 404 | dataOut.data[:,botLim:topLim+1] = sampInterp |
|
405 | 405 | else: |
|
406 | 406 | nHeights = dataOut.data.shape[2] |
|
407 | 407 | x = numpy.hstack((numpy.arange(botLim),numpy.arange(topLim+1,nHeights))) |
|
408 | 408 | y = dataOut.data[:,:,list(range(botLim))+list(range(topLim+1,nHeights))] |
|
409 | 409 | f = interpolate.interp1d(x, y, axis = 2) |
|
410 | 410 | xnew = numpy.arange(botLim,topLim+1) |
|
411 | 411 | ynew = f(xnew) |
|
412 | 412 | dataOut.data[:,:,botLim:topLim+1] = ynew |
|
413 | 413 | |
|
414 | 414 | return dataOut |
|
415 | 415 | |
|
416 | 416 | |
|
417 | 417 | class CohInt(Operation): |
|
418 | 418 | |
|
419 | 419 | isConfig = False |
|
420 | 420 | __profIndex = 0 |
|
421 | 421 | __byTime = False |
|
422 | 422 | __initime = None |
|
423 | 423 | __lastdatatime = None |
|
424 | 424 | __integrationtime = None |
|
425 | 425 | __buffer = None |
|
426 | 426 | __bufferStride = [] |
|
427 | 427 | __dataReady = False |
|
428 | 428 | __profIndexStride = 0 |
|
429 | 429 | __dataToPutStride = False |
|
430 | 430 | n = None |
|
431 | 431 | |
|
432 | 432 | def __init__(self, **kwargs): |
|
433 | 433 | |
|
434 | 434 | Operation.__init__(self, **kwargs) |
|
435 | 435 | |
|
436 | 436 | def setup(self, n=None, timeInterval=None, stride=None, overlapping=False, byblock=False): |
|
437 | 437 | """ |
|
438 | 438 | Set the parameters of the integration class. |
|
439 | 439 | |
|
440 | 440 | Inputs: |
|
441 | 441 | |
|
442 | 442 | n : Number of coherent integrations |
|
443 | 443 | timeInterval : Time of integration. If the parameter "n" is selected this one does not work |
|
444 | 444 | overlapping : |
|
445 | 445 | """ |
|
446 | 446 | |
|
447 | 447 | self.__initime = None |
|
448 | 448 | self.__lastdatatime = 0 |
|
449 | 449 | self.__buffer = None |
|
450 | 450 | self.__dataReady = False |
|
451 | 451 | self.byblock = byblock |
|
452 | 452 | self.stride = stride |
|
453 | 453 | |
|
454 | 454 | if n == None and timeInterval == None: |
|
455 | 455 | raise ValueError("n or timeInterval should be specified ...") |
|
456 | 456 | |
|
457 | 457 | if n != None: |
|
458 | 458 | self.n = n |
|
459 | 459 | self.__byTime = False |
|
460 | 460 | else: |
|
461 | 461 | self.__integrationtime = timeInterval #* 60. #if (type(timeInterval)!=integer) -> change this line |
|
462 | 462 | self.n = 9999 |
|
463 | 463 | self.__byTime = True |
|
464 | 464 | |
|
465 | 465 | if overlapping: |
|
466 | 466 | self.__withOverlapping = True |
|
467 | 467 | self.__buffer = None |
|
468 | 468 | else: |
|
469 | 469 | self.__withOverlapping = False |
|
470 | 470 | self.__buffer = 0 |
|
471 | 471 | |
|
472 | 472 | self.__profIndex = 0 |
|
473 | 473 | |
|
474 | 474 | def putData(self, data): |
|
475 | 475 | |
|
476 | 476 | """ |
|
477 | 477 | Add a profile to the __buffer and increase in one the __profileIndex |
|
478 | 478 | |
|
479 | 479 | """ |
|
480 | 480 | |
|
481 | 481 | if not self.__withOverlapping: |
|
482 | 482 | self.__buffer += data.copy() |
|
483 | 483 | self.__profIndex += 1 |
|
484 | 484 | return |
|
485 | 485 | |
|
486 | 486 | #Overlapping data |
|
487 | 487 | nChannels, nHeis = data.shape |
|
488 | 488 | data = numpy.reshape(data, (1, nChannels, nHeis)) |
|
489 | 489 | |
|
490 | 490 | #If the buffer is empty then it takes the data value |
|
491 | 491 | if self.__buffer is None: |
|
492 | 492 | self.__buffer = data |
|
493 | 493 | self.__profIndex += 1 |
|
494 | 494 | return |
|
495 | 495 | |
|
496 | 496 | #If the buffer length is lower than n then stakcing the data value |
|
497 | 497 | if self.__profIndex < self.n: |
|
498 | 498 | self.__buffer = numpy.vstack((self.__buffer, data)) |
|
499 | 499 | self.__profIndex += 1 |
|
500 | 500 | return |
|
501 | 501 | |
|
502 | 502 | #If the buffer length is equal to n then replacing the last buffer value with the data value |
|
503 | 503 | self.__buffer = numpy.roll(self.__buffer, -1, axis=0) |
|
504 | 504 | self.__buffer[self.n-1] = data |
|
505 | 505 | self.__profIndex = self.n |
|
506 | 506 | return |
|
507 | 507 | |
|
508 | 508 | |
|
509 | 509 | def pushData(self): |
|
510 | 510 | """ |
|
511 | 511 | Return the sum of the last profiles and the profiles used in the sum. |
|
512 | 512 | |
|
513 | 513 | Affected: |
|
514 | 514 | |
|
515 | 515 | self.__profileIndex |
|
516 | 516 | |
|
517 | 517 | """ |
|
518 | 518 | |
|
519 | 519 | if not self.__withOverlapping: |
|
520 | 520 | data = self.__buffer |
|
521 | 521 | n = self.__profIndex |
|
522 | 522 | |
|
523 | 523 | self.__buffer = 0 |
|
524 | 524 | self.__profIndex = 0 |
|
525 | 525 | |
|
526 | 526 | return data, n |
|
527 | 527 | |
|
528 | 528 | #Integration with Overlapping |
|
529 | 529 | data = numpy.sum(self.__buffer, axis=0) |
|
530 | 530 | # print data |
|
531 | 531 | # raise |
|
532 | 532 | n = self.__profIndex |
|
533 | 533 | |
|
534 | 534 | return data, n |
|
535 | 535 | |
|
536 | 536 | def byProfiles(self, data): |
|
537 | 537 | |
|
538 | 538 | self.__dataReady = False |
|
539 | 539 | avgdata = None |
|
540 | 540 | # n = None |
|
541 | 541 | # print data |
|
542 | 542 | # raise |
|
543 | 543 | self.putData(data) |
|
544 | 544 | |
|
545 | 545 | if self.__profIndex == self.n: |
|
546 | 546 | avgdata, n = self.pushData() |
|
547 | 547 | self.__dataReady = True |
|
548 | 548 | |
|
549 | 549 | return avgdata |
|
550 | 550 | |
|
551 | 551 | def byTime(self, data, datatime): |
|
552 | 552 | |
|
553 | 553 | self.__dataReady = False |
|
554 | 554 | avgdata = None |
|
555 | 555 | n = None |
|
556 | 556 | |
|
557 | 557 | self.putData(data) |
|
558 | 558 | |
|
559 | 559 | if (datatime - self.__initime) >= self.__integrationtime: |
|
560 | 560 | avgdata, n = self.pushData() |
|
561 | 561 | self.n = n |
|
562 | 562 | self.__dataReady = True |
|
563 | 563 | |
|
564 | 564 | return avgdata |
|
565 | 565 | |
|
566 | 566 | def integrateByStride(self, data, datatime): |
|
567 | 567 | # print data |
|
568 | 568 | if self.__profIndex == 0: |
|
569 | 569 | self.__buffer = [[data.copy(), datatime]] |
|
570 | 570 | else: |
|
571 | 571 | self.__buffer.append([data.copy(),datatime]) |
|
572 | 572 | self.__profIndex += 1 |
|
573 | 573 | self.__dataReady = False |
|
574 | 574 | |
|
575 | 575 | if self.__profIndex == self.n * self.stride : |
|
576 | 576 | self.__dataToPutStride = True |
|
577 | 577 | self.__profIndexStride = 0 |
|
578 | 578 | self.__profIndex = 0 |
|
579 | 579 | self.__bufferStride = [] |
|
580 | 580 | for i in range(self.stride): |
|
581 | 581 | current = self.__buffer[i::self.stride] |
|
582 | 582 | data = numpy.sum([t[0] for t in current], axis=0) |
|
583 | 583 | avgdatatime = numpy.average([t[1] for t in current]) |
|
584 | 584 | # print data |
|
585 | 585 | self.__bufferStride.append((data, avgdatatime)) |
|
586 | 586 | |
|
587 | 587 | if self.__dataToPutStride: |
|
588 | 588 | self.__dataReady = True |
|
589 | 589 | self.__profIndexStride += 1 |
|
590 | 590 | if self.__profIndexStride == self.stride: |
|
591 | 591 | self.__dataToPutStride = False |
|
592 | 592 | # print self.__bufferStride[self.__profIndexStride - 1] |
|
593 | 593 | # raise |
|
594 | 594 | return self.__bufferStride[self.__profIndexStride - 1] |
|
595 | 595 | |
|
596 | 596 | |
|
597 | 597 | return None, None |
|
598 | 598 | |
|
599 | 599 | def integrate(self, data, datatime=None): |
|
600 | 600 | |
|
601 | 601 | if self.__initime == None: |
|
602 | 602 | self.__initime = datatime |
|
603 | 603 | |
|
604 | 604 | if self.__byTime: |
|
605 | 605 | avgdata = self.byTime(data, datatime) |
|
606 | 606 | else: |
|
607 | 607 | avgdata = self.byProfiles(data) |
|
608 | 608 | |
|
609 | 609 | |
|
610 | 610 | self.__lastdatatime = datatime |
|
611 | 611 | |
|
612 | 612 | if avgdata is None: |
|
613 | 613 | return None, None |
|
614 | 614 | |
|
615 | 615 | avgdatatime = self.__initime |
|
616 | 616 | |
|
617 | 617 | deltatime = datatime - self.__lastdatatime |
|
618 | 618 | |
|
619 | 619 | if not self.__withOverlapping: |
|
620 | 620 | self.__initime = datatime |
|
621 | 621 | else: |
|
622 | 622 | self.__initime += deltatime |
|
623 | 623 | |
|
624 | 624 | return avgdata, avgdatatime |
|
625 | 625 | |
|
626 | 626 | def integrateByBlock(self, dataOut): |
|
627 | 627 | |
|
628 | 628 | times = int(dataOut.data.shape[1]/self.n) |
|
629 | 629 | avgdata = numpy.zeros((dataOut.nChannels, times, dataOut.nHeights), dtype=numpy.complex) |
|
630 | 630 | |
|
631 | 631 | id_min = 0 |
|
632 | 632 | id_max = self.n |
|
633 | 633 | |
|
634 | 634 | for i in range(times): |
|
635 | 635 | junk = dataOut.data[:,id_min:id_max,:] |
|
636 | 636 | avgdata[:,i,:] = junk.sum(axis=1) |
|
637 | 637 | id_min += self.n |
|
638 | 638 | id_max += self.n |
|
639 | 639 | |
|
640 | 640 | timeInterval = dataOut.ippSeconds*self.n |
|
641 | 641 | avgdatatime = (times - 1) * timeInterval + dataOut.utctime |
|
642 | 642 | self.__dataReady = True |
|
643 | 643 | return avgdata, avgdatatime |
|
644 | 644 | |
|
645 | 645 | def run(self, dataOut, n=None, timeInterval=None, stride=None, overlapping=False, byblock=False, **kwargs): |
|
646 | 646 | |
|
647 | 647 | if not self.isConfig: |
|
648 | 648 | self.setup(n=n, stride=stride, timeInterval=timeInterval, overlapping=overlapping, byblock=byblock, **kwargs) |
|
649 | 649 | self.isConfig = True |
|
650 | 650 | |
|
651 | 651 | if dataOut.flagDataAsBlock: |
|
652 | 652 | """ |
|
653 | 653 | Si la data es leida por bloques, dimension = [nChannels, nProfiles, nHeis] |
|
654 | 654 | """ |
|
655 | 655 | avgdata, avgdatatime = self.integrateByBlock(dataOut) |
|
656 | 656 | dataOut.nProfiles /= self.n |
|
657 | 657 | else: |
|
658 | 658 | if stride is None: |
|
659 | 659 | avgdata, avgdatatime = self.integrate(dataOut.data, dataOut.utctime) |
|
660 | 660 | else: |
|
661 | 661 | avgdata, avgdatatime = self.integrateByStride(dataOut.data, dataOut.utctime) |
|
662 | 662 | |
|
663 | 663 | |
|
664 | 664 | # dataOut.timeInterval *= n |
|
665 | 665 | dataOut.flagNoData = True |
|
666 | 666 | |
|
667 | 667 | if self.__dataReady: |
|
668 | 668 | dataOut.data = avgdata |
|
669 | 669 | if not dataOut.flagCohInt: |
|
670 | 670 | dataOut.nCohInt *= self.n |
|
671 | 671 | dataOut.flagCohInt = True |
|
672 | 672 | dataOut.utctime = avgdatatime |
|
673 | 673 | # print avgdata, avgdatatime |
|
674 | 674 | # raise |
|
675 | 675 | # dataOut.timeInterval = dataOut.ippSeconds * dataOut.nCohInt |
|
676 | 676 | dataOut.flagNoData = False |
|
677 | 677 | return dataOut |
|
678 | 678 | |
|
679 | 679 | class Decoder(Operation): |
|
680 | 680 | |
|
681 | 681 | isConfig = False |
|
682 | 682 | __profIndex = 0 |
|
683 | 683 | |
|
684 | 684 | code = None |
|
685 | 685 | |
|
686 | 686 | nCode = None |
|
687 | 687 | nBaud = None |
|
688 | 688 | |
|
689 | 689 | def __init__(self, **kwargs): |
|
690 | 690 | |
|
691 | 691 | Operation.__init__(self, **kwargs) |
|
692 | 692 | |
|
693 | 693 | self.times = None |
|
694 | 694 | self.osamp = None |
|
695 | 695 | # self.__setValues = False |
|
696 | 696 | self.isConfig = False |
|
697 | 697 | self.setupReq = False |
|
698 | 698 | def setup(self, code, osamp, dataOut): |
|
699 | 699 | |
|
700 | 700 | self.__profIndex = 0 |
|
701 | 701 | |
|
702 | 702 | self.code = code |
|
703 | 703 | |
|
704 | 704 | self.nCode = len(code) |
|
705 | 705 | self.nBaud = len(code[0]) |
|
706 | 706 | |
|
707 | 707 | if (osamp != None) and (osamp >1): |
|
708 | 708 | self.osamp = osamp |
|
709 | 709 | self.code = numpy.repeat(code, repeats=self.osamp, axis=1) |
|
710 | 710 | self.nBaud = self.nBaud*self.osamp |
|
711 | 711 | |
|
712 | 712 | self.__nChannels = dataOut.nChannels |
|
713 | 713 | self.__nProfiles = dataOut.nProfiles |
|
714 | 714 | self.__nHeis = dataOut.nHeights |
|
715 | 715 | |
|
716 | 716 | if self.__nHeis < self.nBaud: |
|
717 | 717 | raise ValueError('Number of heights (%d) should be greater than number of bauds (%d)' %(self.__nHeis, self.nBaud)) |
|
718 | 718 | |
|
719 | 719 | #Frequency |
|
720 | 720 | __codeBuffer = numpy.zeros((self.nCode, self.__nHeis), dtype=numpy.complex) |
|
721 | 721 | |
|
722 | 722 | __codeBuffer[:,0:self.nBaud] = self.code |
|
723 | 723 | |
|
724 | 724 | self.fft_code = numpy.conj(numpy.fft.fft(__codeBuffer, axis=1)) |
|
725 | 725 | |
|
726 | 726 | if dataOut.flagDataAsBlock: |
|
727 | 727 | |
|
728 | 728 | self.ndatadec = self.__nHeis #- self.nBaud + 1 |
|
729 | 729 | |
|
730 | 730 | self.datadecTime = numpy.zeros((self.__nChannels, self.__nProfiles, self.ndatadec), dtype=numpy.complex) |
|
731 | 731 | |
|
732 | 732 | else: |
|
733 | 733 | |
|
734 | 734 | #Time |
|
735 | 735 | self.ndatadec = self.__nHeis #- self.nBaud + 1 |
|
736 | 736 | |
|
737 | 737 | self.datadecTime = numpy.zeros((self.__nChannels, self.ndatadec), dtype=numpy.complex) |
|
738 | 738 | |
|
739 | 739 | def __convolutionInFreq(self, data): |
|
740 | 740 | |
|
741 | 741 | fft_code = self.fft_code[self.__profIndex].reshape(1,-1) |
|
742 | 742 | |
|
743 | 743 | fft_data = numpy.fft.fft(data, axis=1) |
|
744 | 744 | |
|
745 | 745 | conv = fft_data*fft_code |
|
746 | 746 | |
|
747 | 747 | data = numpy.fft.ifft(conv,axis=1) |
|
748 | 748 | |
|
749 | 749 | return data |
|
750 | 750 | |
|
751 | 751 | def __convolutionInFreqOpt(self, data): |
|
752 | 752 | |
|
753 | 753 | raise NotImplementedError |
|
754 | 754 | |
|
755 | 755 | def __convolutionInTime(self, data): |
|
756 | 756 | |
|
757 | 757 | code = self.code[self.__profIndex] |
|
758 | 758 | for i in range(self.__nChannels): |
|
759 | 759 | self.datadecTime[i,:] = numpy.correlate(data[i,:], code, mode='full')[self.nBaud-1:] |
|
760 | 760 | |
|
761 | 761 | return self.datadecTime |
|
762 | 762 | |
|
763 | 763 | def __convolutionByBlockInTime(self, data): |
|
764 | 764 | |
|
765 | 765 | repetitions = int(self.__nProfiles / self.nCode) |
|
766 | 766 | junk = numpy.lib.stride_tricks.as_strided(self.code, (repetitions, self.code.size), (0, self.code.itemsize)) |
|
767 | 767 | junk = junk.flatten() |
|
768 | 768 | code_block = numpy.reshape(junk, (self.nCode*repetitions, self.nBaud)) |
|
769 | 769 | profilesList = range(self.__nProfiles) |
|
770 | 770 | |
|
771 | 771 | for i in range(self.__nChannels): |
|
772 | 772 | for j in profilesList: |
|
773 | 773 | self.datadecTime[i,j,:] = numpy.correlate(data[i,j,:], code_block[j,:], mode='full')[self.nBaud-1:] |
|
774 | 774 | return self.datadecTime |
|
775 | 775 | |
|
776 | 776 | def __convolutionByBlockInFreq(self, data): |
|
777 | 777 | |
|
778 | 778 | raise NotImplementedError("Decoder by frequency fro Blocks not implemented") |
|
779 | 779 | |
|
780 | 780 | |
|
781 | 781 | fft_code = self.fft_code[self.__profIndex].reshape(1,-1) |
|
782 | 782 | |
|
783 | 783 | fft_data = numpy.fft.fft(data, axis=2) |
|
784 | 784 | |
|
785 | 785 | conv = fft_data*fft_code |
|
786 | 786 | |
|
787 | 787 | data = numpy.fft.ifft(conv,axis=2) |
|
788 | 788 | |
|
789 | 789 | return data |
|
790 | 790 | |
|
791 | 791 | |
|
792 | 792 | def run(self, dataOut, code=None, nCode=None, nBaud=None, mode = 0, osamp=None, times=None): |
|
793 | 793 | |
|
794 | 794 | if dataOut.flagDecodeData: |
|
795 | 795 | print("This data is already decoded, recoding again ...") |
|
796 | 796 | |
|
797 | 797 | if not self.isConfig: |
|
798 | 798 | |
|
799 | 799 | if code is None: |
|
800 | 800 | if dataOut.code is None: |
|
801 | 801 | raise ValueError("Code could not be read from %s instance. Enter a value in Code parameter" %dataOut.type) |
|
802 | 802 | |
|
803 | 803 | code = dataOut.code |
|
804 | 804 | else: |
|
805 | 805 | code = numpy.array(code).reshape(nCode,nBaud) |
|
806 | 806 | self.setup(code, osamp, dataOut) |
|
807 | 807 | |
|
808 | 808 | self.isConfig = True |
|
809 | 809 | |
|
810 | 810 | if mode == 3: |
|
811 | 811 | sys.stderr.write("Decoder Warning: mode=%d is not valid, using mode=0\n" %mode) |
|
812 | 812 | |
|
813 | 813 | if times != None: |
|
814 | 814 | sys.stderr.write("Decoder Warning: Argument 'times' in not used anymore\n") |
|
815 | 815 | |
|
816 | 816 | if self.code is None: |
|
817 | 817 | print("Fail decoding: Code is not defined.") |
|
818 | 818 | return |
|
819 | 819 | |
|
820 | 820 | self.__nProfiles = dataOut.nProfiles |
|
821 | 821 | datadec = None |
|
822 | 822 | |
|
823 | 823 | if mode == 3: |
|
824 | 824 | mode = 0 |
|
825 | 825 | |
|
826 | 826 | if dataOut.flagDataAsBlock: |
|
827 | 827 | """ |
|
828 | 828 | Decoding when data have been read as block, |
|
829 | 829 | """ |
|
830 | 830 | |
|
831 | 831 | if mode == 0: |
|
832 | 832 | datadec = self.__convolutionByBlockInTime(dataOut.data) |
|
833 | 833 | if mode == 1: |
|
834 | 834 | datadec = self.__convolutionByBlockInFreq(dataOut.data) |
|
835 | 835 | else: |
|
836 | 836 | """ |
|
837 | 837 | Decoding when data have been read profile by profile |
|
838 | 838 | """ |
|
839 | 839 | if mode == 0: |
|
840 | 840 | datadec = self.__convolutionInTime(dataOut.data) |
|
841 | 841 | |
|
842 | 842 | if mode == 1: |
|
843 | 843 | datadec = self.__convolutionInFreq(dataOut.data) |
|
844 | 844 | |
|
845 | 845 | if mode == 2: |
|
846 | 846 | datadec = self.__convolutionInFreqOpt(dataOut.data) |
|
847 | 847 | |
|
848 | 848 | if datadec is None: |
|
849 | 849 | raise ValueError("Codification mode selected is not valid: mode=%d. Try selecting 0 or 1" %mode) |
|
850 | 850 | |
|
851 | 851 | dataOut.code = self.code |
|
852 | 852 | dataOut.nCode = self.nCode |
|
853 | 853 | dataOut.nBaud = self.nBaud |
|
854 | 854 | |
|
855 | 855 | dataOut.data = datadec |
|
856 | 856 | |
|
857 | 857 | dataOut.heightList = dataOut.heightList[0:datadec.shape[-1]] |
|
858 | 858 | |
|
859 | 859 | dataOut.flagDecodeData = True #asumo q la data esta decodificada |
|
860 | 860 | |
|
861 | 861 | if self.__profIndex == self.nCode-1: |
|
862 | 862 | self.__profIndex = 0 |
|
863 | 863 | return dataOut |
|
864 | 864 | |
|
865 | 865 | self.__profIndex += 1 |
|
866 | 866 | |
|
867 | 867 | return dataOut |
|
868 | 868 | # dataOut.flagDeflipData = True #asumo q la data no esta sin flip |
|
869 | 869 | |
|
870 | 870 | |
|
871 | 871 | class ProfileConcat(Operation): |
|
872 | 872 | |
|
873 | 873 | isConfig = False |
|
874 | 874 | buffer = None |
|
875 | 875 | |
|
876 | 876 | def __init__(self, **kwargs): |
|
877 | 877 | |
|
878 | 878 | Operation.__init__(self, **kwargs) |
|
879 | 879 | self.profileIndex = 0 |
|
880 | 880 | |
|
881 | 881 | def reset(self): |
|
882 | 882 | self.buffer = numpy.zeros_like(self.buffer) |
|
883 | 883 | self.start_index = 0 |
|
884 | 884 | self.times = 1 |
|
885 | 885 | |
|
886 | 886 | def setup(self, data, m, n=1): |
|
887 | 887 | self.buffer = numpy.zeros((data.shape[0],data.shape[1]*m),dtype=type(data[0,0])) |
|
888 | 888 | self.nHeights = data.shape[1]#.nHeights |
|
889 | 889 | self.start_index = 0 |
|
890 | 890 | self.times = 1 |
|
891 | 891 | |
|
892 | 892 | def concat(self, data): |
|
893 | 893 | |
|
894 | 894 | self.buffer[:,self.start_index:self.nHeights*self.times] = data.copy() |
|
895 | 895 | self.start_index = self.start_index + self.nHeights |
|
896 | 896 | |
|
897 | 897 | def run(self, dataOut, m): |
|
898 | 898 | dataOut.flagNoData = True |
|
899 | 899 | |
|
900 | 900 | if not self.isConfig: |
|
901 | 901 | self.setup(dataOut.data, m, 1) |
|
902 | 902 | self.isConfig = True |
|
903 | 903 | |
|
904 | 904 | if dataOut.flagDataAsBlock: |
|
905 | 905 | raise ValueError("ProfileConcat can only be used when voltage have been read profile by profile, getBlock = False") |
|
906 | 906 | |
|
907 | 907 | else: |
|
908 | 908 | self.concat(dataOut.data) |
|
909 | 909 | self.times += 1 |
|
910 | 910 | if self.times > m: |
|
911 | 911 | dataOut.data = self.buffer |
|
912 | 912 | self.reset() |
|
913 | 913 | dataOut.flagNoData = False |
|
914 | 914 | # se deben actualizar mas propiedades del header y del objeto dataOut, por ejemplo, las alturas |
|
915 | 915 | deltaHeight = dataOut.heightList[1] - dataOut.heightList[0] |
|
916 | 916 | xf = dataOut.heightList[0] + dataOut.nHeights * deltaHeight * m |
|
917 | 917 | dataOut.heightList = numpy.arange(dataOut.heightList[0], xf, deltaHeight) |
|
918 | 918 | dataOut.ippSeconds *= m |
|
919 | 919 | return dataOut |
|
920 | 920 | |
|
921 | 921 | class ProfileSelector(Operation): |
|
922 | 922 | |
|
923 | 923 | profileIndex = None |
|
924 | 924 | # Tamanho total de los perfiles |
|
925 | 925 | nProfiles = None |
|
926 | 926 | |
|
927 | 927 | def __init__(self, **kwargs): |
|
928 | 928 | |
|
929 | 929 | Operation.__init__(self, **kwargs) |
|
930 | 930 | self.profileIndex = 0 |
|
931 | 931 | |
|
932 | 932 | def incProfileIndex(self): |
|
933 | 933 | |
|
934 | 934 | self.profileIndex += 1 |
|
935 | 935 | |
|
936 | 936 | if self.profileIndex >= self.nProfiles: |
|
937 | 937 | self.profileIndex = 0 |
|
938 | 938 | |
|
939 | 939 | def isThisProfileInRange(self, profileIndex, minIndex, maxIndex): |
|
940 | 940 | |
|
941 | 941 | if profileIndex < minIndex: |
|
942 | 942 | return False |
|
943 | 943 | |
|
944 | 944 | if profileIndex > maxIndex: |
|
945 | 945 | return False |
|
946 | 946 | |
|
947 | 947 | return True |
|
948 | 948 | |
|
949 | 949 | def isThisProfileInList(self, profileIndex, profileList): |
|
950 | 950 | |
|
951 | 951 | if profileIndex not in profileList: |
|
952 | 952 | return False |
|
953 | 953 | |
|
954 | 954 | return True |
|
955 | 955 | |
|
956 | 956 | def run(self, dataOut, profileList=None, profileRangeList=None, beam=None, byblock=False, rangeList = None, nProfiles=None): |
|
957 | 957 | |
|
958 | 958 | """ |
|
959 | 959 | ProfileSelector: |
|
960 | 960 | |
|
961 | 961 | Inputs: |
|
962 | 962 | profileList : Index of profiles selected. Example: profileList = (0,1,2,7,8) |
|
963 | 963 | |
|
964 | 964 | profileRangeList : Minimum and maximum profile indexes. Example: profileRangeList = (4, 30) |
|
965 | 965 | |
|
966 | 966 | rangeList : List of profile ranges. Example: rangeList = ((4, 30), (32, 64), (128, 256)) |
|
967 | 967 | |
|
968 | 968 | """ |
|
969 | 969 | |
|
970 | 970 | if rangeList is not None: |
|
971 | 971 | if type(rangeList[0]) not in (tuple, list): |
|
972 | 972 | rangeList = [rangeList] |
|
973 | 973 | |
|
974 | 974 | dataOut.flagNoData = True |
|
975 | 975 | |
|
976 | 976 | if dataOut.flagDataAsBlock: |
|
977 | 977 | """ |
|
978 | 978 | data dimension = [nChannels, nProfiles, nHeis] |
|
979 | 979 | """ |
|
980 | 980 | if profileList != None: |
|
981 | 981 | dataOut.data = dataOut.data[:,profileList,:] |
|
982 | 982 | |
|
983 | 983 | if profileRangeList != None: |
|
984 | 984 | minIndex = profileRangeList[0] |
|
985 | 985 | maxIndex = profileRangeList[1] |
|
986 | 986 | profileList = list(range(minIndex, maxIndex+1)) |
|
987 | 987 | |
|
988 | 988 | dataOut.data = dataOut.data[:,minIndex:maxIndex+1,:] |
|
989 | 989 | |
|
990 | 990 | if rangeList != None: |
|
991 | 991 | |
|
992 | 992 | profileList = [] |
|
993 | 993 | |
|
994 | 994 | for thisRange in rangeList: |
|
995 | 995 | minIndex = thisRange[0] |
|
996 | 996 | maxIndex = thisRange[1] |
|
997 | 997 | |
|
998 | 998 | profileList.extend(list(range(minIndex, maxIndex+1))) |
|
999 | 999 | |
|
1000 | 1000 | dataOut.data = dataOut.data[:,profileList,:] |
|
1001 | 1001 | |
|
1002 | 1002 | dataOut.nProfiles = len(profileList) |
|
1003 | 1003 | dataOut.profileIndex = dataOut.nProfiles - 1 |
|
1004 | 1004 | dataOut.flagNoData = False |
|
1005 | 1005 | |
|
1006 | 1006 | return dataOut |
|
1007 | 1007 | |
|
1008 | 1008 | """ |
|
1009 | 1009 | data dimension = [nChannels, nHeis] |
|
1010 | 1010 | """ |
|
1011 | 1011 | |
|
1012 | 1012 | if profileList != None: |
|
1013 | 1013 | |
|
1014 | 1014 | if self.isThisProfileInList(dataOut.profileIndex, profileList): |
|
1015 | 1015 | |
|
1016 | 1016 | self.nProfiles = len(profileList) |
|
1017 | 1017 | dataOut.nProfiles = self.nProfiles |
|
1018 | 1018 | dataOut.profileIndex = self.profileIndex |
|
1019 | 1019 | dataOut.flagNoData = False |
|
1020 | 1020 | |
|
1021 | 1021 | self.incProfileIndex() |
|
1022 | 1022 | return dataOut |
|
1023 | 1023 | |
|
1024 | 1024 | if profileRangeList != None: |
|
1025 | 1025 | |
|
1026 | 1026 | minIndex = profileRangeList[0] |
|
1027 | 1027 | maxIndex = profileRangeList[1] |
|
1028 | 1028 | |
|
1029 | 1029 | if self.isThisProfileInRange(dataOut.profileIndex, minIndex, maxIndex): |
|
1030 | 1030 | |
|
1031 | 1031 | self.nProfiles = maxIndex - minIndex + 1 |
|
1032 | 1032 | dataOut.nProfiles = self.nProfiles |
|
1033 | 1033 | dataOut.profileIndex = self.profileIndex |
|
1034 | 1034 | dataOut.flagNoData = False |
|
1035 | 1035 | |
|
1036 | 1036 | self.incProfileIndex() |
|
1037 | 1037 | return dataOut |
|
1038 | 1038 | |
|
1039 | 1039 | if rangeList != None: |
|
1040 | 1040 | |
|
1041 | 1041 | nProfiles = 0 |
|
1042 | 1042 | |
|
1043 | 1043 | for thisRange in rangeList: |
|
1044 | 1044 | minIndex = thisRange[0] |
|
1045 | 1045 | maxIndex = thisRange[1] |
|
1046 | 1046 | |
|
1047 | 1047 | nProfiles += maxIndex - minIndex + 1 |
|
1048 | 1048 | |
|
1049 | 1049 | for thisRange in rangeList: |
|
1050 | 1050 | |
|
1051 | 1051 | minIndex = thisRange[0] |
|
1052 | 1052 | maxIndex = thisRange[1] |
|
1053 | 1053 | |
|
1054 | 1054 | if self.isThisProfileInRange(dataOut.profileIndex, minIndex, maxIndex): |
|
1055 | 1055 | |
|
1056 | 1056 | self.nProfiles = nProfiles |
|
1057 | 1057 | dataOut.nProfiles = self.nProfiles |
|
1058 | 1058 | dataOut.profileIndex = self.profileIndex |
|
1059 | 1059 | dataOut.flagNoData = False |
|
1060 | 1060 | |
|
1061 | 1061 | self.incProfileIndex() |
|
1062 | 1062 | |
|
1063 | 1063 | break |
|
1064 | 1064 | |
|
1065 | 1065 | return dataOut |
|
1066 | 1066 | |
|
1067 | 1067 | |
|
1068 | 1068 | if beam != None: #beam is only for AMISR data |
|
1069 | 1069 | if self.isThisProfileInList(dataOut.profileIndex, dataOut.beamRangeDict[beam]): |
|
1070 | 1070 | dataOut.flagNoData = False |
|
1071 | 1071 | dataOut.profileIndex = self.profileIndex |
|
1072 | 1072 | |
|
1073 | 1073 | self.incProfileIndex() |
|
1074 | 1074 | |
|
1075 | 1075 | return dataOut |
|
1076 | 1076 | |
|
1077 | 1077 | raise ValueError("ProfileSelector needs profileList, profileRangeList or rangeList parameter") |
|
1078 | 1078 | |
|
1079 | 1079 | |
|
1080 | 1080 | class Reshaper(Operation): |
|
1081 | 1081 | |
|
1082 | 1082 | def __init__(self, **kwargs): |
|
1083 | 1083 | |
|
1084 | 1084 | Operation.__init__(self, **kwargs) |
|
1085 | 1085 | |
|
1086 | 1086 | self.__buffer = None |
|
1087 | 1087 | self.__nitems = 0 |
|
1088 | 1088 | |
|
1089 | 1089 | def __appendProfile(self, dataOut, nTxs): |
|
1090 | 1090 | |
|
1091 | 1091 | if self.__buffer is None: |
|
1092 | 1092 | shape = (dataOut.nChannels, int(dataOut.nHeights/nTxs) ) |
|
1093 | 1093 | self.__buffer = numpy.empty(shape, dtype = dataOut.data.dtype) |
|
1094 | 1094 | |
|
1095 | 1095 | ini = dataOut.nHeights * self.__nitems |
|
1096 | 1096 | end = ini + dataOut.nHeights |
|
1097 | 1097 | |
|
1098 | 1098 | self.__buffer[:, ini:end] = dataOut.data |
|
1099 | 1099 | |
|
1100 | 1100 | self.__nitems += 1 |
|
1101 | 1101 | |
|
1102 | 1102 | return int(self.__nitems*nTxs) |
|
1103 | 1103 | |
|
1104 | 1104 | def __getBuffer(self): |
|
1105 | 1105 | |
|
1106 | 1106 | if self.__nitems == int(1./self.__nTxs): |
|
1107 | 1107 | |
|
1108 | 1108 | self.__nitems = 0 |
|
1109 | 1109 | |
|
1110 | 1110 | return self.__buffer.copy() |
|
1111 | 1111 | |
|
1112 | 1112 | return None |
|
1113 | 1113 | |
|
1114 | 1114 | def __checkInputs(self, dataOut, shape, nTxs): |
|
1115 | 1115 | |
|
1116 | 1116 | if shape is None and nTxs is None: |
|
1117 | 1117 | raise ValueError("Reshaper: shape of factor should be defined") |
|
1118 | 1118 | |
|
1119 | 1119 | if nTxs: |
|
1120 | 1120 | if nTxs < 0: |
|
1121 | 1121 | raise ValueError("nTxs should be greater than 0") |
|
1122 | 1122 | |
|
1123 | 1123 | if nTxs < 1 and dataOut.nProfiles % (1./nTxs) != 0: |
|
1124 | 1124 | raise ValueError("nProfiles= %d is not divisibled by (1./nTxs) = %f" %(dataOut.nProfiles, (1./nTxs))) |
|
1125 | 1125 | |
|
1126 | 1126 | shape = [dataOut.nChannels, dataOut.nProfiles*nTxs, dataOut.nHeights/nTxs] |
|
1127 | 1127 | |
|
1128 | 1128 | return shape, nTxs |
|
1129 | 1129 | |
|
1130 | 1130 | if len(shape) != 2 and len(shape) != 3: |
|
1131 | 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)) |
|
1132 | 1132 | |
|
1133 | 1133 | if len(shape) == 2: |
|
1134 | 1134 | shape_tuple = [dataOut.nChannels] |
|
1135 | 1135 | shape_tuple.extend(shape) |
|
1136 | 1136 | else: |
|
1137 | 1137 | shape_tuple = list(shape) |
|
1138 | 1138 | |
|
1139 | 1139 | nTxs = 1.0*shape_tuple[1]/dataOut.nProfiles |
|
1140 | 1140 | |
|
1141 | 1141 | return shape_tuple, nTxs |
|
1142 | 1142 | |
|
1143 | 1143 | def run(self, dataOut, shape=None, nTxs=None): |
|
1144 | 1144 | |
|
1145 | 1145 | shape_tuple, self.__nTxs = self.__checkInputs(dataOut, shape, nTxs) |
|
1146 | 1146 | |
|
1147 | 1147 | dataOut.flagNoData = True |
|
1148 | 1148 | profileIndex = None |
|
1149 | 1149 | |
|
1150 | 1150 | if dataOut.flagDataAsBlock: |
|
1151 | 1151 | |
|
1152 | 1152 | dataOut.data = numpy.reshape(dataOut.data, shape_tuple) |
|
1153 | 1153 | dataOut.flagNoData = False |
|
1154 | 1154 | |
|
1155 | 1155 | profileIndex = int(dataOut.nProfiles*self.__nTxs) - 1 |
|
1156 | 1156 | |
|
1157 | 1157 | else: |
|
1158 | 1158 | |
|
1159 | 1159 | if self.__nTxs < 1: |
|
1160 | 1160 | |
|
1161 | 1161 | self.__appendProfile(dataOut, self.__nTxs) |
|
1162 | 1162 | new_data = self.__getBuffer() |
|
1163 | 1163 | |
|
1164 | 1164 | if new_data is not None: |
|
1165 | 1165 | dataOut.data = new_data |
|
1166 | 1166 | dataOut.flagNoData = False |
|
1167 | 1167 | |
|
1168 | 1168 | profileIndex = dataOut.profileIndex*nTxs |
|
1169 | 1169 | |
|
1170 | 1170 | else: |
|
1171 | 1171 | raise ValueError("nTxs should be greater than 0 and lower than 1, or use VoltageReader(..., getblock=True)") |
|
1172 | 1172 | |
|
1173 | 1173 | deltaHeight = dataOut.heightList[1] - dataOut.heightList[0] |
|
1174 | 1174 | |
|
1175 | 1175 | dataOut.heightList = numpy.arange(dataOut.nHeights/self.__nTxs) * deltaHeight + dataOut.heightList[0] |
|
1176 | 1176 | |
|
1177 | 1177 | dataOut.nProfiles = int(dataOut.nProfiles*self.__nTxs) |
|
1178 | 1178 | |
|
1179 | 1179 | dataOut.profileIndex = profileIndex |
|
1180 | 1180 | |
|
1181 | 1181 | dataOut.ippSeconds /= self.__nTxs |
|
1182 | 1182 | |
|
1183 | 1183 | return dataOut |
|
1184 | 1184 | |
|
1185 | 1185 | class SplitProfiles(Operation): |
|
1186 | 1186 | |
|
1187 | 1187 | def __init__(self, **kwargs): |
|
1188 | 1188 | |
|
1189 | 1189 | Operation.__init__(self, **kwargs) |
|
1190 | 1190 | |
|
1191 | 1191 | def run(self, dataOut, n): |
|
1192 | 1192 | |
|
1193 | 1193 | dataOut.flagNoData = True |
|
1194 | 1194 | profileIndex = None |
|
1195 | 1195 | |
|
1196 | 1196 | if dataOut.flagDataAsBlock: |
|
1197 | 1197 | |
|
1198 | 1198 | #nchannels, nprofiles, nsamples |
|
1199 | 1199 | shape = dataOut.data.shape |
|
1200 | 1200 | |
|
1201 | 1201 | if shape[2] % n != 0: |
|
1202 | 1202 | raise ValueError("Could not split the data, n=%d has to be multiple of %d" %(n, shape[2])) |
|
1203 | 1203 | |
|
1204 | 1204 | new_shape = shape[0], shape[1]*n, int(shape[2]/n) |
|
1205 | 1205 | |
|
1206 | 1206 | dataOut.data = numpy.reshape(dataOut.data, new_shape) |
|
1207 | 1207 | dataOut.flagNoData = False |
|
1208 | 1208 | |
|
1209 | 1209 | profileIndex = int(dataOut.nProfiles/n) - 1 |
|
1210 | 1210 | |
|
1211 | 1211 | else: |
|
1212 | 1212 | |
|
1213 | 1213 | raise ValueError("Could not split the data when is read Profile by Profile. Use VoltageReader(..., getblock=True)") |
|
1214 | 1214 | |
|
1215 | 1215 | deltaHeight = dataOut.heightList[1] - dataOut.heightList[0] |
|
1216 | 1216 | |
|
1217 | 1217 | dataOut.heightList = numpy.arange(dataOut.nHeights/n) * deltaHeight + dataOut.heightList[0] |
|
1218 | 1218 | |
|
1219 | 1219 | dataOut.nProfiles = int(dataOut.nProfiles*n) |
|
1220 | 1220 | |
|
1221 | 1221 | dataOut.profileIndex = profileIndex |
|
1222 | 1222 | |
|
1223 | 1223 | dataOut.ippSeconds /= n |
|
1224 | 1224 | |
|
1225 | 1225 | return dataOut |
|
1226 | 1226 | |
|
1227 | 1227 | class CombineProfiles(Operation): |
|
1228 | 1228 | def __init__(self, **kwargs): |
|
1229 | 1229 | |
|
1230 | 1230 | Operation.__init__(self, **kwargs) |
|
1231 | 1231 | |
|
1232 | 1232 | self.__remData = None |
|
1233 | 1233 | self.__profileIndex = 0 |
|
1234 | 1234 | |
|
1235 | 1235 | def run(self, dataOut, n): |
|
1236 | 1236 | |
|
1237 | 1237 | dataOut.flagNoData = True |
|
1238 | 1238 | profileIndex = None |
|
1239 | 1239 | |
|
1240 | 1240 | if dataOut.flagDataAsBlock: |
|
1241 | 1241 | |
|
1242 | 1242 | #nchannels, nprofiles, nsamples |
|
1243 | 1243 | shape = dataOut.data.shape |
|
1244 | 1244 | new_shape = shape[0], shape[1]/n, shape[2]*n |
|
1245 | 1245 | |
|
1246 | 1246 | if shape[1] % n != 0: |
|
1247 | 1247 | raise ValueError("Could not split the data, n=%d has to be multiple of %d" %(n, shape[1])) |
|
1248 | 1248 | |
|
1249 | 1249 | dataOut.data = numpy.reshape(dataOut.data, new_shape) |
|
1250 | 1250 | dataOut.flagNoData = False |
|
1251 | 1251 | |
|
1252 | 1252 | profileIndex = int(dataOut.nProfiles*n) - 1 |
|
1253 | 1253 | |
|
1254 | 1254 | else: |
|
1255 | 1255 | |
|
1256 | 1256 | #nchannels, nsamples |
|
1257 | 1257 | if self.__remData is None: |
|
1258 | 1258 | newData = dataOut.data |
|
1259 | 1259 | else: |
|
1260 | 1260 | newData = numpy.concatenate((self.__remData, dataOut.data), axis=1) |
|
1261 | 1261 | |
|
1262 | 1262 | self.__profileIndex += 1 |
|
1263 | 1263 | |
|
1264 | 1264 | if self.__profileIndex < n: |
|
1265 | 1265 | self.__remData = newData |
|
1266 | 1266 | #continue |
|
1267 | 1267 | return |
|
1268 | 1268 | |
|
1269 | 1269 | self.__profileIndex = 0 |
|
1270 | 1270 | self.__remData = None |
|
1271 | 1271 | |
|
1272 | 1272 | dataOut.data = newData |
|
1273 | 1273 | dataOut.flagNoData = False |
|
1274 | 1274 | |
|
1275 | 1275 | profileIndex = dataOut.profileIndex/n |
|
1276 | 1276 | |
|
1277 | 1277 | |
|
1278 | 1278 | deltaHeight = dataOut.heightList[1] - dataOut.heightList[0] |
|
1279 | 1279 | |
|
1280 | 1280 | dataOut.heightList = numpy.arange(dataOut.nHeights*n) * deltaHeight + dataOut.heightList[0] |
|
1281 | 1281 | |
|
1282 | 1282 | dataOut.nProfiles = int(dataOut.nProfiles/n) |
|
1283 | 1283 | |
|
1284 | 1284 | dataOut.profileIndex = profileIndex |
|
1285 | 1285 | |
|
1286 | 1286 | dataOut.ippSeconds *= n |
|
1287 | 1287 | |
|
1288 | 1288 | return dataOut |
|
1289 | 1289 | |
|
1290 | 1290 | class PulsePair(Operation): |
|
1291 | 1291 | ''' |
|
1292 | 1292 | Function PulsePair(Signal Power, Velocity) |
|
1293 | 1293 | The real component of Lag[0] provides Intensity Information |
|
1294 | 1294 | The imag component of Lag[1] Phase provides Velocity Information |
|
1295 | 1295 | |
|
1296 | 1296 | Configuration Parameters: |
|
1297 | 1297 | nPRF = Number of Several PRF |
|
1298 | 1298 | theta = Degree Azimuth angel Boundaries |
|
1299 | 1299 | |
|
1300 | 1300 | Input: |
|
1301 | 1301 | self.dataOut |
|
1302 | 1302 | lag[N] |
|
1303 | 1303 | Affected: |
|
1304 | 1304 | self.dataOut.spc |
|
1305 | 1305 | ''' |
|
1306 | 1306 | isConfig = False |
|
1307 | 1307 | __profIndex = 0 |
|
1308 | 1308 | __initime = None |
|
1309 | 1309 | __lastdatatime = None |
|
1310 | 1310 | __buffer = None |
|
1311 | 1311 | noise = None |
|
1312 | 1312 | __dataReady = False |
|
1313 | 1313 | n = None |
|
1314 | 1314 | __nch = 0 |
|
1315 | 1315 | __nHeis = 0 |
|
1316 | 1316 | removeDC = False |
|
1317 | 1317 | ipp = None |
|
1318 | 1318 | lambda_ = 0 |
|
1319 | 1319 | |
|
1320 | 1320 | def __init__(self,**kwargs): |
|
1321 | 1321 | Operation.__init__(self,**kwargs) |
|
1322 | 1322 | |
|
1323 | 1323 | def setup(self, dataOut, n = None, removeDC=False): |
|
1324 | 1324 | ''' |
|
1325 | 1325 | n= Numero de PRF's de entrada |
|
1326 | 1326 | ''' |
|
1327 | 1327 | print("[INICIO]-setup del METODO PULSE PAIR") |
|
1328 | 1328 | self.__initime = None |
|
1329 | 1329 | self.__lastdatatime = 0 |
|
1330 | 1330 | self.__dataReady = False |
|
1331 | 1331 | self.__buffer = 0 |
|
1332 | 1332 | self.__profIndex = 0 |
|
1333 | 1333 | self.noise = None |
|
1334 | 1334 | self.__nch = dataOut.nChannels |
|
1335 | 1335 | self.__nHeis = dataOut.nHeights |
|
1336 | 1336 | self.removeDC = removeDC |
|
1337 | 1337 | self.lambda_ = 3.0e8/(9345.0e6) |
|
1338 | 1338 | self.ippSec = dataOut.ippSeconds |
|
1339 | 1339 | self.nCohInt = dataOut.nCohInt |
|
1340 | 1340 | print("IPPseconds",dataOut.ippSeconds) |
|
1341 | 1341 | |
|
1342 | 1342 | print("ELVALOR DE n es:", n) |
|
1343 | 1343 | if n == None: |
|
1344 | 1344 | raise ValueError("n should be specified.") |
|
1345 | 1345 | |
|
1346 | 1346 | if n != None: |
|
1347 | 1347 | if n<2: |
|
1348 | 1348 | raise ValueError("n should be greater than 2") |
|
1349 | 1349 | |
|
1350 | 1350 | self.n = n |
|
1351 | 1351 | self.__nProf = n |
|
1352 | 1352 | |
|
1353 | 1353 | self.__buffer = numpy.zeros((dataOut.nChannels, |
|
1354 | 1354 | n, |
|
1355 | 1355 | dataOut.nHeights), |
|
1356 | 1356 | dtype='complex') |
|
1357 | 1357 | |
|
1358 | 1358 | def putData(self,data): |
|
1359 | 1359 | ''' |
|
1360 | 1360 | Add a profile to he __buffer and increase in one the __profiel Index |
|
1361 | 1361 | ''' |
|
1362 | 1362 | self.__buffer[:,self.__profIndex,:]= data |
|
1363 | 1363 | self.__profIndex += 1 |
|
1364 | 1364 | return |
|
1365 | 1365 | |
|
1366 | 1366 | def pushData(self,dataOut): |
|
1367 | 1367 | ''' |
|
1368 | 1368 | Return the PULSEPAIR and the profiles used in the operation |
|
1369 | 1369 | Affected : self.__profileIndex |
|
1370 | 1370 | ''' |
|
1371 | 1371 | #----------------- Remove DC----------------------------------- |
|
1372 | 1372 | if self.removeDC==True: |
|
1373 | 1373 | mean = numpy.mean(self.__buffer,1) |
|
1374 | 1374 | tmp = mean.reshape(self.__nch,1,self.__nHeis) |
|
1375 | 1375 | dc= numpy.tile(tmp,[1,self.__nProf,1]) |
|
1376 | 1376 | self.__buffer = self.__buffer - dc |
|
1377 | 1377 | #------------------Calculo de Potencia ------------------------ |
|
1378 | 1378 | pair0 = self.__buffer*numpy.conj(self.__buffer) |
|
1379 | 1379 | pair0 = pair0.real |
|
1380 | 1380 | lag_0 = numpy.sum(pair0,1) |
|
1381 | 1381 | #------------------Calculo de Ruido x canal-------------------- |
|
1382 | 1382 | self.noise = numpy.zeros(self.__nch) |
|
1383 | 1383 | for i in range(self.__nch): |
|
1384 | 1384 | daux = numpy.sort(pair0[i,:,:],axis= None) |
|
1385 | 1385 | self.noise[i]=hildebrand_sekhon( daux ,self.nCohInt) |
|
1386 | 1386 | |
|
1387 | 1387 | self.noise = self.noise.reshape(self.__nch,1) |
|
1388 | 1388 | self.noise = numpy.tile(self.noise,[1,self.__nHeis]) |
|
1389 | 1389 | noise_buffer = self.noise.reshape(self.__nch,1,self.__nHeis) |
|
1390 | 1390 | noise_buffer = numpy.tile(noise_buffer,[1,self.__nProf,1]) |
|
1391 | 1391 | #------------------ Potencia recibida= P , Potencia senal = S , Ruido= N-- |
|
1392 | 1392 | #------------------ P= S+N ,P=lag_0/N --------------------------------- |
|
1393 | 1393 | #-------------------- Power -------------------------------------------------- |
|
1394 | 1394 | data_power = lag_0/(self.n*self.nCohInt) |
|
1395 | 1395 | #------------------ Senal --------------------------------------------------- |
|
1396 | 1396 | data_intensity = pair0 - noise_buffer |
|
1397 | 1397 | data_intensity = numpy.sum(data_intensity,axis=1)*(self.n*self.nCohInt)#*self.nCohInt) |
|
1398 | 1398 | #data_intensity = (lag_0-self.noise*self.n)*(self.n*self.nCohInt) |
|
1399 | 1399 | for i in range(self.__nch): |
|
1400 | 1400 | for j in range(self.__nHeis): |
|
1401 | 1401 | if data_intensity[i][j] < 0: |
|
1402 | 1402 | data_intensity[i][j] = numpy.min(numpy.absolute(data_intensity[i][j])) |
|
1403 | 1403 | |
|
1404 | 1404 | #----------------- Calculo de Frecuencia y Velocidad doppler-------- |
|
1405 | 1405 | pair1 = self.__buffer[:,:-1,:]*numpy.conjugate(self.__buffer[:,1:,:]) |
|
1406 | 1406 | lag_1 = numpy.sum(pair1,1) |
|
1407 | 1407 | data_freq = (-1/(2.0*math.pi*self.ippSec*self.nCohInt))*numpy.angle(lag_1) |
|
1408 | 1408 | data_velocity = (self.lambda_/2.0)*data_freq |
|
1409 | 1409 | |
|
1410 | 1410 | #---------------- Potencia promedio estimada de la Senal----------- |
|
1411 | 1411 | lag_0 = lag_0/self.n |
|
1412 | 1412 | S = lag_0-self.noise |
|
1413 | 1413 | |
|
1414 | 1414 | #---------------- Frecuencia Doppler promedio --------------------- |
|
1415 | 1415 | lag_1 = lag_1/(self.n-1) |
|
1416 | 1416 | R1 = numpy.abs(lag_1) |
|
1417 | 1417 | |
|
1418 | 1418 | #---------------- Calculo del SNR---------------------------------- |
|
1419 | 1419 | data_snrPP = S/self.noise |
|
1420 | 1420 | for i in range(self.__nch): |
|
1421 | 1421 | for j in range(self.__nHeis): |
|
1422 | 1422 | if data_snrPP[i][j] < 1.e-20: |
|
1423 | 1423 | data_snrPP[i][j] = 1.e-20 |
|
1424 | 1424 | |
|
1425 | 1425 | #----------------- Calculo del ancho espectral ---------------------- |
|
1426 | 1426 | L = S/R1 |
|
1427 | 1427 | L = numpy.where(L<0,1,L) |
|
1428 | 1428 | L = numpy.log(L) |
|
1429 | 1429 | tmp = numpy.sqrt(numpy.absolute(L)) |
|
1430 | 1430 | data_specwidth = (self.lambda_/(2*math.sqrt(2)*math.pi*self.ippSec*self.nCohInt))*tmp*numpy.sign(L) |
|
1431 | 1431 | n = self.__profIndex |
|
1432 | 1432 | |
|
1433 | 1433 | self.__buffer = numpy.zeros((self.__nch, self.__nProf,self.__nHeis), dtype='complex') |
|
1434 | 1434 | self.__profIndex = 0 |
|
1435 | 1435 | return data_power,data_intensity,data_velocity,data_snrPP,data_specwidth,n |
|
1436 | 1436 | |
|
1437 | 1437 | |
|
1438 | 1438 | def pulsePairbyProfiles(self,dataOut): |
|
1439 | 1439 | |
|
1440 | 1440 | self.__dataReady = False |
|
1441 | 1441 | data_power = None |
|
1442 | 1442 | data_intensity = None |
|
1443 | 1443 | data_velocity = None |
|
1444 | 1444 | data_specwidth = None |
|
1445 | 1445 | data_snrPP = None |
|
1446 | 1446 | self.putData(data=dataOut.data) |
|
1447 | 1447 | if self.__profIndex == self.n: |
|
1448 | 1448 | data_power,data_intensity, data_velocity,data_snrPP,data_specwidth, n = self.pushData(dataOut=dataOut) |
|
1449 | 1449 | self.__dataReady = True |
|
1450 | 1450 | |
|
1451 | 1451 | return data_power, data_intensity, data_velocity, data_snrPP, data_specwidth |
|
1452 | 1452 | |
|
1453 | 1453 | |
|
1454 | 1454 | def pulsePairOp(self, dataOut, datatime= None): |
|
1455 | 1455 | |
|
1456 | 1456 | if self.__initime == None: |
|
1457 | 1457 | self.__initime = datatime |
|
1458 | 1458 | data_power, data_intensity, data_velocity, data_snrPP, data_specwidth = self.pulsePairbyProfiles(dataOut) |
|
1459 | 1459 | self.__lastdatatime = datatime |
|
1460 | 1460 | |
|
1461 | 1461 | if data_power is None: |
|
1462 | 1462 | return None, None, None,None,None,None |
|
1463 | 1463 | |
|
1464 | 1464 | avgdatatime = self.__initime |
|
1465 | 1465 | deltatime = datatime - self.__lastdatatime |
|
1466 | 1466 | self.__initime = datatime |
|
1467 | 1467 | |
|
1468 | 1468 | return data_power, data_intensity, data_velocity, data_snrPP, data_specwidth, avgdatatime |
|
1469 | 1469 | |
|
1470 | 1470 | def run(self, dataOut,n = None,removeDC= False, overlapping= False,**kwargs): |
|
1471 | 1471 | |
|
1472 | 1472 | if not self.isConfig: |
|
1473 | 1473 | self.setup(dataOut = dataOut, n = n , removeDC=removeDC , **kwargs) |
|
1474 | 1474 | self.isConfig = True |
|
1475 | 1475 | data_power, data_intensity, data_velocity,data_snrPP,data_specwidth, avgdatatime = self.pulsePairOp(dataOut, dataOut.utctime) |
|
1476 | 1476 | dataOut.flagNoData = True |
|
1477 | 1477 | |
|
1478 | 1478 | if self.__dataReady: |
|
1479 | 1479 | dataOut.nCohInt *= self.n |
|
1480 | 1480 | dataOut.dataPP_POW = data_intensity # S |
|
1481 | print("help",data_power) | |
|
1482 | dataOut.dataPP_POWER = data_power # P | |
|
1481 | dataOut.dataPP_POWER = data_power # P valor que corresponde a POTENCIA MOMENTO | |
|
1483 | 1482 | dataOut.dataPP_DOP = data_velocity |
|
1484 | 1483 | dataOut.dataPP_SNR = data_snrPP |
|
1485 | 1484 | dataOut.dataPP_WIDTH = data_specwidth |
|
1486 | 1485 | dataOut.PRFbyAngle = self.n #numero de PRF*cada angulo rotado que equivale a un tiempo. |
|
1487 | 1486 | dataOut.nProfiles = int(dataOut.nProfiles/n) |
|
1488 | 1487 | dataOut.utctime = avgdatatime |
|
1489 | 1488 | dataOut.flagNoData = False |
|
1490 | 1489 | return dataOut |
|
1491 | 1490 | |
|
1492 | 1491 | |
|
1493 | 1492 | |
|
1494 | 1493 | # import collections |
|
1495 | 1494 | # from scipy.stats import mode |
|
1496 | 1495 | # |
|
1497 | 1496 | # class Synchronize(Operation): |
|
1498 | 1497 | # |
|
1499 | 1498 | # isConfig = False |
|
1500 | 1499 | # __profIndex = 0 |
|
1501 | 1500 | # |
|
1502 | 1501 | # def __init__(self, **kwargs): |
|
1503 | 1502 | # |
|
1504 | 1503 | # Operation.__init__(self, **kwargs) |
|
1505 | 1504 | # # self.isConfig = False |
|
1506 | 1505 | # self.__powBuffer = None |
|
1507 | 1506 | # self.__startIndex = 0 |
|
1508 | 1507 | # self.__pulseFound = False |
|
1509 | 1508 | # |
|
1510 | 1509 | # def __findTxPulse(self, dataOut, channel=0, pulse_with = None): |
|
1511 | 1510 | # |
|
1512 | 1511 | # #Read data |
|
1513 | 1512 | # |
|
1514 | 1513 | # powerdB = dataOut.getPower(channel = channel) |
|
1515 | 1514 | # noisedB = dataOut.getNoise(channel = channel)[0] |
|
1516 | 1515 | # |
|
1517 | 1516 | # self.__powBuffer.extend(powerdB.flatten()) |
|
1518 | 1517 | # |
|
1519 | 1518 | # dataArray = numpy.array(self.__powBuffer) |
|
1520 | 1519 | # |
|
1521 | 1520 | # filteredPower = numpy.correlate(dataArray, dataArray[0:self.__nSamples], "same") |
|
1522 | 1521 | # |
|
1523 | 1522 | # maxValue = numpy.nanmax(filteredPower) |
|
1524 | 1523 | # |
|
1525 | 1524 | # if maxValue < noisedB + 10: |
|
1526 | 1525 | # #No se encuentra ningun pulso de transmision |
|
1527 | 1526 | # return None |
|
1528 | 1527 | # |
|
1529 | 1528 | # maxValuesIndex = numpy.where(filteredPower > maxValue - 0.1*abs(maxValue))[0] |
|
1530 | 1529 | # |
|
1531 | 1530 | # if len(maxValuesIndex) < 2: |
|
1532 | 1531 | # #Solo se encontro un solo pulso de transmision de un baudio, esperando por el siguiente TX |
|
1533 | 1532 | # return None |
|
1534 | 1533 | # |
|
1535 | 1534 | # phasedMaxValuesIndex = maxValuesIndex - self.__nSamples |
|
1536 | 1535 | # |
|
1537 | 1536 | # #Seleccionar solo valores con un espaciamiento de nSamples |
|
1538 | 1537 | # pulseIndex = numpy.intersect1d(maxValuesIndex, phasedMaxValuesIndex) |
|
1539 | 1538 | # |
|
1540 | 1539 | # if len(pulseIndex) < 2: |
|
1541 | 1540 | # #Solo se encontro un pulso de transmision con ancho mayor a 1 |
|
1542 | 1541 | # return None |
|
1543 | 1542 | # |
|
1544 | 1543 | # spacing = pulseIndex[1:] - pulseIndex[:-1] |
|
1545 | 1544 | # |
|
1546 | 1545 | # #remover senales que se distancien menos de 10 unidades o muestras |
|
1547 | 1546 | # #(No deberian existir IPP menor a 10 unidades) |
|
1548 | 1547 | # |
|
1549 | 1548 | # realIndex = numpy.where(spacing > 10 )[0] |
|
1550 | 1549 | # |
|
1551 | 1550 | # if len(realIndex) < 2: |
|
1552 | 1551 | # #Solo se encontro un pulso de transmision con ancho mayor a 1 |
|
1553 | 1552 | # return None |
|
1554 | 1553 | # |
|
1555 | 1554 | # #Eliminar pulsos anchos (deja solo la diferencia entre IPPs) |
|
1556 | 1555 | # realPulseIndex = pulseIndex[realIndex] |
|
1557 | 1556 | # |
|
1558 | 1557 | # period = mode(realPulseIndex[1:] - realPulseIndex[:-1])[0][0] |
|
1559 | 1558 | # |
|
1560 | 1559 | # print "IPP = %d samples" %period |
|
1561 | 1560 | # |
|
1562 | 1561 | # self.__newNSamples = dataOut.nHeights #int(period) |
|
1563 | 1562 | # self.__startIndex = int(realPulseIndex[0]) |
|
1564 | 1563 | # |
|
1565 | 1564 | # return 1 |
|
1566 | 1565 | # |
|
1567 | 1566 | # |
|
1568 | 1567 | # def setup(self, nSamples, nChannels, buffer_size = 4): |
|
1569 | 1568 | # |
|
1570 | 1569 | # self.__powBuffer = collections.deque(numpy.zeros( buffer_size*nSamples,dtype=numpy.float), |
|
1571 | 1570 | # maxlen = buffer_size*nSamples) |
|
1572 | 1571 | # |
|
1573 | 1572 | # bufferList = [] |
|
1574 | 1573 | # |
|
1575 | 1574 | # for i in range(nChannels): |
|
1576 | 1575 | # bufferByChannel = collections.deque(numpy.zeros( buffer_size*nSamples, dtype=numpy.complex) + numpy.NAN, |
|
1577 | 1576 | # maxlen = buffer_size*nSamples) |
|
1578 | 1577 | # |
|
1579 | 1578 | # bufferList.append(bufferByChannel) |
|
1580 | 1579 | # |
|
1581 | 1580 | # self.__nSamples = nSamples |
|
1582 | 1581 | # self.__nChannels = nChannels |
|
1583 | 1582 | # self.__bufferList = bufferList |
|
1584 | 1583 | # |
|
1585 | 1584 | # def run(self, dataOut, channel = 0): |
|
1586 | 1585 | # |
|
1587 | 1586 | # if not self.isConfig: |
|
1588 | 1587 | # nSamples = dataOut.nHeights |
|
1589 | 1588 | # nChannels = dataOut.nChannels |
|
1590 | 1589 | # self.setup(nSamples, nChannels) |
|
1591 | 1590 | # self.isConfig = True |
|
1592 | 1591 | # |
|
1593 | 1592 | # #Append new data to internal buffer |
|
1594 | 1593 | # for thisChannel in range(self.__nChannels): |
|
1595 | 1594 | # bufferByChannel = self.__bufferList[thisChannel] |
|
1596 | 1595 | # bufferByChannel.extend(dataOut.data[thisChannel]) |
|
1597 | 1596 | # |
|
1598 | 1597 | # if self.__pulseFound: |
|
1599 | 1598 | # self.__startIndex -= self.__nSamples |
|
1600 | 1599 | # |
|
1601 | 1600 | # #Finding Tx Pulse |
|
1602 | 1601 | # if not self.__pulseFound: |
|
1603 | 1602 | # indexFound = self.__findTxPulse(dataOut, channel) |
|
1604 | 1603 | # |
|
1605 | 1604 | # if indexFound == None: |
|
1606 | 1605 | # dataOut.flagNoData = True |
|
1607 | 1606 | # return |
|
1608 | 1607 | # |
|
1609 | 1608 | # self.__arrayBuffer = numpy.zeros((self.__nChannels, self.__newNSamples), dtype = numpy.complex) |
|
1610 | 1609 | # self.__pulseFound = True |
|
1611 | 1610 | # self.__startIndex = indexFound |
|
1612 | 1611 | # |
|
1613 | 1612 | # #If pulse was found ... |
|
1614 | 1613 | # for thisChannel in range(self.__nChannels): |
|
1615 | 1614 | # bufferByChannel = self.__bufferList[thisChannel] |
|
1616 | 1615 | # #print self.__startIndex |
|
1617 | 1616 | # x = numpy.array(bufferByChannel) |
|
1618 | 1617 | # self.__arrayBuffer[thisChannel] = x[self.__startIndex:self.__startIndex+self.__newNSamples] |
|
1619 | 1618 | # |
|
1620 | 1619 | # deltaHeight = dataOut.heightList[1] - dataOut.heightList[0] |
|
1621 | 1620 | # dataOut.heightList = numpy.arange(self.__newNSamples)*deltaHeight |
|
1622 | 1621 | # # dataOut.ippSeconds = (self.__newNSamples / deltaHeight)/1e6 |
|
1623 | 1622 | # |
|
1624 | 1623 | # dataOut.data = self.__arrayBuffer |
|
1625 | 1624 | # |
|
1626 | 1625 | # self.__startIndex += self.__newNSamples |
|
1627 | 1626 | # |
|
1628 | 1627 | # return |
@@ -1,217 +1,217 | |||
|
1 | 1 | # Ing. AVP |
|
2 | 2 | # 06/10/2021 |
|
3 | 3 | # ARCHIVO DE LECTURA |
|
4 | 4 | import os, sys |
|
5 | 5 | import datetime |
|
6 | 6 | import time |
|
7 | 7 | from schainpy.controller import Project |
|
8 | 8 | #### NOTA########################################### |
|
9 | 9 | # INPUT : |
|
10 | 10 | # VELOCIDAD PARAMETRO : V = 2Β°/seg |
|
11 | 11 | # MODO PULSE PAIR O MOMENTOS: 0 : Pulse Pair ,1 : Momentos |
|
12 | 12 | ###################################################### |
|
13 | 13 | ##### PROCESAMIENTO ################################## |
|
14 | 14 | ##### OJO TENER EN CUENTA EL n= para el Pulse Pair ## |
|
15 | 15 | ##### O EL n= nFFTPoints ### |
|
16 | 16 | ###################################################### |
|
17 | 17 | ######## BUSCAMOS EL numero de IPP equivalente 1Β°##### |
|
18 | 18 | ######## Sea V la velocidad del Pedestal en Β°/seg##### |
|
19 | 19 | ######## 1Β° sera Recorrido en un tiempo de 1/V ###### |
|
20 | 20 | ######## IPP del Radar 400 useg --> 60 Km ############ |
|
21 | 21 | ######## n = 1/(V(Β°/seg)*IPP(Km)) , NUMERO DE IPP ## |
|
22 | 22 | ######## n = 1/(V*IPP) ############################# |
|
23 | 23 | ######## VELOCIDAD DEL PEDESTAL ###################### |
|
24 | 24 | print("SETUP- RADAR METEOROLOGICO") |
|
25 | 25 | V = 10 |
|
26 |
mode = |
|
|
26 | mode = 0 | |
|
27 | 27 | #path = '/DATA_RM/23/6v' |
|
28 | 28 | #path = '/DATA_RM/TEST_INTEGRACION_2M' |
|
29 | 29 | path = '/DATA_RM/WR_20_OCT' |
|
30 | 30 | |
|
31 | 31 | #path_ped='/DATA_RM/TEST_PEDESTAL/P20211012-082745' |
|
32 | 32 | path_ped='/DATA_RM/TEST_PEDESTAL/P20211020-131248' |
|
33 | 33 | |
|
34 | 34 | figpath_pp = "/home/soporte/Pictures/TEST_PP" |
|
35 | 35 | figpath_mom = "/home/soporte/Pictures/TEST_MOM" |
|
36 | 36 | plot = 0 |
|
37 | 37 | integration = 1 |
|
38 | 38 | save = 0 |
|
39 | 39 | if save == 1: |
|
40 | 40 | if mode==0: |
|
41 | 41 | path_save = '/DATA_RM/TEST_HDF5_PP_23/6v' |
|
42 | 42 | path_save = '/DATA_RM/TEST_HDF5_PP' |
|
43 | 43 | path_save = '/DATA_RM/TEST_HDF5_PP_100' |
|
44 | 44 | else: |
|
45 | 45 | path_save = '/DATA_RM/TEST_HDF5_SPEC_23_V2/6v' |
|
46 | 46 | |
|
47 | 47 | print("* PATH data ADQ :", path) |
|
48 | 48 | print("* Velocidad Pedestal :",V,"Β°/seg") |
|
49 | 49 | ############################ NRO Perfiles PROCESAMIENTO ################### |
|
50 | 50 | V=V |
|
51 | 51 | IPP=400*1e-6 |
|
52 | 52 | n= int(1/(V*IPP)) |
|
53 | 53 | print("* n - NRO Perfiles Proc:", n ) |
|
54 | 54 | ################################## MODE ################################### |
|
55 | 55 | print("* Modo de Operacion :",mode) |
|
56 | 56 | if mode ==0: |
|
57 | 57 | print("* Met. Seleccionado : Pulse Pair") |
|
58 | 58 | else: |
|
59 | 59 | print("* Met. Momentos : Momentos") |
|
60 | 60 | |
|
61 | 61 | ################################## MODE ################################### |
|
62 | 62 | print("* Grabado de datos :",save) |
|
63 | 63 | if save ==1: |
|
64 | 64 | if mode==0: |
|
65 | 65 | ope= "Pulse Pair" |
|
66 | 66 | else: |
|
67 | 67 | ope= "Momentos" |
|
68 | 68 | print("* Path-Save Data -", ope , path_save) |
|
69 | 69 | |
|
70 | 70 | print("* Integracion de datos :",integration) |
|
71 | 71 | |
|
72 | 72 | time.sleep(5) |
|
73 | 73 | #remotefolder = "/home/wmaster/graficos" |
|
74 | 74 | ####################################################################### |
|
75 | 75 | ################# RANGO DE PLOTEO###################################### |
|
76 | 76 | dBmin = '1' |
|
77 | 77 | dBmax = '85' |
|
78 | 78 | xmin = '15' |
|
79 | 79 | xmax = '15.25' |
|
80 | 80 | ymin = '0' |
|
81 | 81 | ymax = '600' |
|
82 | 82 | ####################################################################### |
|
83 | 83 | ########################FECHA########################################## |
|
84 | 84 | str = datetime.date.today() |
|
85 | 85 | today = str.strftime("%Y/%m/%d") |
|
86 | 86 | str2 = str - datetime.timedelta(days=1) |
|
87 | 87 | yesterday = str2.strftime("%Y/%m/%d") |
|
88 | 88 | ####################################################################### |
|
89 | 89 | ########################SIGNAL CHAIN ################################## |
|
90 | 90 | ####################################################################### |
|
91 | 91 | desc = "USRP_test" |
|
92 | 92 | filename = "USRP_processing.xml" |
|
93 | 93 | controllerObj = Project() |
|
94 | 94 | controllerObj.setup(id = '191', name='Test_USRP', description=desc) |
|
95 | 95 | ####################################################################### |
|
96 | 96 | ######################## UNIDAD DE LECTURA############################# |
|
97 | 97 | ####################################################################### |
|
98 | 98 | readUnitConfObj = controllerObj.addReadUnit(datatype='DigitalRFReader', |
|
99 | 99 | path=path, |
|
100 | 100 | startDate="2021/01/01",#today, |
|
101 | 101 | endDate="2021/12/30",#today, |
|
102 | 102 | startTime='00:00:00', |
|
103 | 103 | endTime='23:59:59', |
|
104 | 104 | delay=0, |
|
105 | 105 | #set=0, |
|
106 | 106 | online=0, |
|
107 | 107 | walk=1, |
|
108 | 108 | ippKm = 60) |
|
109 | 109 | |
|
110 | 110 | opObj11 = readUnitConfObj.addOperation(name='printInfo') |
|
111 | 111 | |
|
112 | 112 | procUnitConfObjA = controllerObj.addProcUnit(datatype='VoltageProc', inputId=readUnitConfObj.getId()) |
|
113 | 113 | |
|
114 | 114 | if mode ==0: |
|
115 | 115 | ####################### METODO PULSE PAIR ###################################################################### |
|
116 | 116 | opObj11 = procUnitConfObjA.addOperation(name='PulsePair', optype='other') |
|
117 | 117 | opObj11.addParameter(name='n', value=int(n), format='int')#10 VOY A USAR 250 DADO QUE LA VELOCIDAD ES 10 GRADOS |
|
118 | 118 | #opObj11.addParameter(name='removeDC', value=1, format='int') |
|
119 | 119 | ####################### METODO Parametros ###################################################################### |
|
120 | 120 | procUnitConfObjB= controllerObj.addProcUnit(datatype='ParametersProc',inputId=procUnitConfObjA.getId()) |
|
121 | 121 | if plot==1: |
|
122 | 122 | opObj11 = procUnitConfObjB.addOperation(name='GenericRTIPlot',optype='external') |
|
123 | 123 | opObj11.addParameter(name='attr_data', value='dataPP_POW') |
|
124 | 124 | opObj11.addParameter(name='colormap', value='jet') |
|
125 | 125 | opObj11.addParameter(name='xmin', value=xmin) |
|
126 | 126 | opObj11.addParameter(name='xmax', value=xmax) |
|
127 | 127 | opObj11.addParameter(name='zmin', value=dBmin) |
|
128 | 128 | opObj11.addParameter(name='zmax', value=dBmax) |
|
129 | 129 | opObj11.addParameter(name='save', value=figpath_pp) |
|
130 | 130 | opObj11.addParameter(name='showprofile', value=0) |
|
131 | 131 | opObj11.addParameter(name='save_period', value=50) |
|
132 | 132 | |
|
133 | 133 | ####################### METODO ESCRITURA ####################################################################### |
|
134 | 134 | if save==1: |
|
135 | 135 | opObj10 = procUnitConfObjB.addOperation(name='HDFWriter') |
|
136 | 136 | opObj10.addParameter(name='path',value=path_save) |
|
137 | 137 | #opObj10.addParameter(name='mode',value=0) |
|
138 | 138 | opObj10.addParameter(name='blocksPerFile',value='100',format='int') |
|
139 | 139 | opObj10.addParameter(name='metadataList',value='utctimeInit,timeZone,paramInterval,profileIndex,channelList,heightList,flagDataAsBlock',format='list') |
|
140 | 140 | opObj10.addParameter(name='dataList',value='dataPP_POW,dataPP_DOP,utctime',format='list')#,format='list' |
|
141 | 141 | if integration==1: |
|
142 | 142 | V=10 |
|
143 | 143 | blocksPerfile=360 |
|
144 | 144 | print("* Velocidad del Pedestal:",V) |
|
145 | 145 | tmp_blocksPerfile = 100 |
|
146 | 146 | f_a_p= int(tmp_blocksPerfile/V) |
|
147 | 147 | |
|
148 | 148 | opObj11 = procUnitConfObjB.addOperation(name='PedestalInformation') |
|
149 | 149 | opObj11.addParameter(name='path_ped', value=path_ped) |
|
150 | 150 | #opObj11.addParameter(name='path_adq', value=path_adq) |
|
151 | 151 | opObj11.addParameter(name='t_Interval_p', value='0.01', format='float') |
|
152 | 152 | opObj11.addParameter(name='blocksPerfile', value=blocksPerfile, format='int') |
|
153 | 153 | opObj11.addParameter(name='n_Muestras_p', value='100', format='float') |
|
154 | 154 | opObj11.addParameter(name='f_a_p', value=f_a_p, format='int') |
|
155 | 155 | opObj11.addParameter(name='online', value='0', format='int') |
|
156 | 156 | |
|
157 | 157 | opObj11 = procUnitConfObjB.addOperation(name='Block360') |
|
158 | 158 | opObj11.addParameter(name='n', value='10', format='int') |
|
159 | 159 | opObj11.addParameter(name='mode', value=mode, format='int') |
|
160 | 160 | |
|
161 | 161 | # este bloque funciona bien con divisores de 360 no olvidar 0 10 20 30 40 60 90 120 180 |
|
162 | 162 | |
|
163 | 163 | opObj11= procUnitConfObjB.addOperation(name='WeatherPlot',optype='other') |
|
164 | 164 | |
|
165 | 165 | |
|
166 | 166 | else: |
|
167 | 167 | ####################### METODO SPECTROS ###################################################################### |
|
168 | 168 | procUnitConfObjB = controllerObj.addProcUnit(datatype='SpectraProc', inputId=procUnitConfObjA.getId()) |
|
169 | 169 | procUnitConfObjB.addParameter(name='nFFTPoints', value=n, format='int') |
|
170 | 170 | procUnitConfObjB.addParameter(name='nProfiles' , value=n, format='int') |
|
171 | 171 | |
|
172 | 172 | procUnitConfObjC = controllerObj.addProcUnit(datatype='ParametersProc',inputId=procUnitConfObjB.getId()) |
|
173 | 173 | procUnitConfObjC.addOperation(name='SpectralMoments') |
|
174 | 174 | if plot==1: |
|
175 | 175 | dBmin = '1' |
|
176 | 176 | dBmax = '65' |
|
177 | 177 | opObj11 = procUnitConfObjC.addOperation(name='PowerPlot',optype='external') |
|
178 | 178 | opObj11.addParameter(name='xmin', value=xmin) |
|
179 | 179 | opObj11.addParameter(name='xmax', value=xmax) |
|
180 | 180 | opObj11.addParameter(name='zmin', value=dBmin) |
|
181 | 181 | opObj11.addParameter(name='zmax', value=dBmax) |
|
182 | 182 | opObj11.addParameter(name='save', value=figpath_mom) |
|
183 | 183 | opObj11.addParameter(name='showprofile', value=0) |
|
184 | 184 | opObj11.addParameter(name='save_period', value=100) |
|
185 | 185 | |
|
186 | 186 | if save==1: |
|
187 | 187 | opObj10 = procUnitConfObjC.addOperation(name='HDFWriter') |
|
188 | 188 | opObj10.addParameter(name='path',value=path_save) |
|
189 | 189 | #opObj10.addParameter(name='mode',value=0) |
|
190 | 190 | opObj10.addParameter(name='blocksPerFile',value='360',format='int') |
|
191 | 191 | #opObj10.addParameter(name='metadataList',value='utctimeInit,heightList,nIncohInt,nCohInt,nProfiles,channelList',format='list')#profileIndex |
|
192 | 192 | opObj10.addParameter(name='metadataList',value='utctimeInit,heightList,nIncohInt,nCohInt,nProfiles,channelList',format='list')#profileIndex |
|
193 | 193 | opObj10.addParameter(name='dataList',value='data_pow,data_dop,utctime',format='list')#,format='list' |
|
194 | 194 | |
|
195 | 195 | if integration==1: |
|
196 | 196 | V=10 |
|
197 | 197 | blocksPerfile=360 |
|
198 | 198 | print("* Velocidad del Pedestal:",V) |
|
199 | 199 | tmp_blocksPerfile = 100 |
|
200 | 200 | f_a_p= int(tmp_blocksPerfile/V) |
|
201 | 201 | |
|
202 | 202 | opObj11 = procUnitConfObjC.addOperation(name='PedestalInformation') |
|
203 | 203 | opObj11.addParameter(name='path_ped', value=path_ped) |
|
204 | 204 | #opObj11.addParameter(name='path_adq', value=path_adq) |
|
205 | 205 | opObj11.addParameter(name='t_Interval_p', value='0.01', format='float') |
|
206 | 206 | opObj11.addParameter(name='blocksPerfile', value=blocksPerfile, format='int') |
|
207 | 207 | opObj11.addParameter(name='n_Muestras_p', value='100', format='float') |
|
208 | 208 | opObj11.addParameter(name='f_a_p', value=f_a_p, format='int') |
|
209 | 209 | opObj11.addParameter(name='online', value='0', format='int') |
|
210 | 210 | |
|
211 | 211 | opObj11 = procUnitConfObjC.addOperation(name='Block360') |
|
212 | 212 | opObj11.addParameter(name='n', value='10', format='int') |
|
213 | 213 | opObj11.addParameter(name='mode', value=mode, format='int') |
|
214 | 214 | |
|
215 | 215 | # este bloque funciona bien con divisores de 360 no olvidar 0 10 20 30 40 60 90 120 180 |
|
216 | 216 | opObj11= procUnitConfObjC.addOperation(name='WeatherPlot',optype='other') |
|
217 | 217 | controllerObj.start() |
General Comments 0
You need to be logged in to leave comments.
Login now