@@ -1,707 +1,714 | |||||
1 | # Copyright (c) 2012-2020 Jicamarca Radio Observatory |
|
1 | # Copyright (c) 2012-2020 Jicamarca Radio Observatory | |
2 | # All rights reserved. |
|
2 | # All rights reserved. | |
3 | # |
|
3 | # | |
4 | # Distributed under the terms of the BSD 3-clause license. |
|
4 | # Distributed under the terms of the BSD 3-clause license. | |
5 | """Base class to create plot operations |
|
5 | """Base class to create plot operations | |
6 |
|
6 | |||
7 | """ |
|
7 | """ | |
8 |
|
8 | |||
9 | import os |
|
9 | import os | |
10 | import sys |
|
10 | import sys | |
11 | import zmq |
|
11 | import zmq | |
12 | import time |
|
12 | import time | |
13 | import numpy |
|
13 | import numpy | |
14 | import datetime |
|
14 | import datetime | |
15 | from collections import deque |
|
15 | from collections import deque | |
16 | from functools import wraps |
|
16 | from functools import wraps | |
17 | from threading import Thread |
|
17 | from threading import Thread | |
18 | import matplotlib |
|
18 | import matplotlib | |
19 |
|
19 | |||
20 | if 'BACKEND' in os.environ: |
|
20 | if 'BACKEND' in os.environ: | |
21 | matplotlib.use(os.environ['BACKEND']) |
|
21 | matplotlib.use(os.environ['BACKEND']) | |
22 | elif 'linux' in sys.platform: |
|
22 | elif 'linux' in sys.platform: | |
23 | matplotlib.use("TkAgg") |
|
23 | matplotlib.use("TkAgg") | |
24 | elif 'darwin' in sys.platform: |
|
24 | elif 'darwin' in sys.platform: | |
25 | matplotlib.use('MacOSX') |
|
25 | matplotlib.use('MacOSX') | |
26 | else: |
|
26 | else: | |
27 | from schainpy.utils import log |
|
27 | from schainpy.utils import log | |
28 | log.warning('Using default Backend="Agg"', 'INFO') |
|
28 | log.warning('Using default Backend="Agg"', 'INFO') | |
29 | matplotlib.use('Agg') |
|
29 | matplotlib.use('Agg') | |
30 |
|
30 | |||
31 | import matplotlib.pyplot as plt |
|
31 | import matplotlib.pyplot as plt | |
32 | from matplotlib.patches import Polygon |
|
32 | from matplotlib.patches import Polygon | |
33 | from mpl_toolkits.axes_grid1 import make_axes_locatable |
|
33 | from mpl_toolkits.axes_grid1 import make_axes_locatable | |
34 | from matplotlib.ticker import FuncFormatter, LinearLocator, MultipleLocator |
|
34 | from matplotlib.ticker import FuncFormatter, LinearLocator, MultipleLocator | |
35 |
|
35 | |||
36 | from schainpy.model.data.jrodata import PlotterData |
|
36 | from schainpy.model.data.jrodata import PlotterData | |
37 | from schainpy.model.proc.jroproc_base import ProcessingUnit, Operation, MPDecorator |
|
37 | from schainpy.model.proc.jroproc_base import ProcessingUnit, Operation, MPDecorator | |
38 | from schainpy.utils import log |
|
38 | from schainpy.utils import log | |
39 |
|
39 | |||
40 | jet_values = matplotlib.pyplot.get_cmap('jet', 100)(numpy.arange(100))[10:90] |
|
40 | jet_values = matplotlib.pyplot.get_cmap('jet', 100)(numpy.arange(100))[10:90] | |
41 | blu_values = matplotlib.pyplot.get_cmap( |
|
41 | blu_values = matplotlib.pyplot.get_cmap( | |
42 | 'seismic_r', 20)(numpy.arange(20))[10:15] |
|
42 | 'seismic_r', 20)(numpy.arange(20))[10:15] | |
43 | ncmap = matplotlib.colors.LinearSegmentedColormap.from_list( |
|
43 | ncmap = matplotlib.colors.LinearSegmentedColormap.from_list( | |
44 | 'jro', numpy.vstack((blu_values, jet_values))) |
|
44 | 'jro', numpy.vstack((blu_values, jet_values))) | |
45 | matplotlib.pyplot.register_cmap(cmap=ncmap) |
|
45 | matplotlib.pyplot.register_cmap(cmap=ncmap) | |
46 |
|
46 | |||
47 | CMAPS = [plt.get_cmap(s) for s in ('jro', 'jet', 'viridis', |
|
47 | CMAPS = [plt.get_cmap(s) for s in ('jro', 'jet', 'viridis', | |
48 | 'plasma', 'inferno', 'Greys', 'seismic', 'bwr', 'coolwarm')] |
|
48 | 'plasma', 'inferno', 'Greys', 'seismic', 'bwr', 'coolwarm')] | |
49 |
|
49 | |||
50 | EARTH_RADIUS = 6.3710e3 |
|
50 | EARTH_RADIUS = 6.3710e3 | |
51 |
|
51 | |||
52 | def ll2xy(lat1, lon1, lat2, lon2): |
|
52 | def ll2xy(lat1, lon1, lat2, lon2): | |
53 |
|
53 | |||
54 | p = 0.017453292519943295 |
|
54 | p = 0.017453292519943295 | |
55 | a = 0.5 - numpy.cos((lat2 - lat1) * p)/2 + numpy.cos(lat1 * p) * \ |
|
55 | a = 0.5 - numpy.cos((lat2 - lat1) * p)/2 + numpy.cos(lat1 * p) * \ | |
56 | numpy.cos(lat2 * p) * (1 - numpy.cos((lon2 - lon1) * p)) / 2 |
|
56 | numpy.cos(lat2 * p) * (1 - numpy.cos((lon2 - lon1) * p)) / 2 | |
57 | r = 12742 * numpy.arcsin(numpy.sqrt(a)) |
|
57 | r = 12742 * numpy.arcsin(numpy.sqrt(a)) | |
58 | theta = numpy.arctan2(numpy.sin((lon2-lon1)*p)*numpy.cos(lat2*p), numpy.cos(lat1*p) |
|
58 | theta = numpy.arctan2(numpy.sin((lon2-lon1)*p)*numpy.cos(lat2*p), numpy.cos(lat1*p) | |
59 | * numpy.sin(lat2*p)-numpy.sin(lat1*p)*numpy.cos(lat2*p)*numpy.cos((lon2-lon1)*p)) |
|
59 | * numpy.sin(lat2*p)-numpy.sin(lat1*p)*numpy.cos(lat2*p)*numpy.cos((lon2-lon1)*p)) | |
60 | theta = -theta + numpy.pi/2 |
|
60 | theta = -theta + numpy.pi/2 | |
61 | return r*numpy.cos(theta), r*numpy.sin(theta) |
|
61 | return r*numpy.cos(theta), r*numpy.sin(theta) | |
62 |
|
62 | |||
63 |
|
63 | |||
64 | def km2deg(km): |
|
64 | def km2deg(km): | |
65 | ''' |
|
65 | ''' | |
66 | Convert distance in km to degrees |
|
66 | Convert distance in km to degrees | |
67 | ''' |
|
67 | ''' | |
68 |
|
68 | |||
69 | return numpy.rad2deg(km/EARTH_RADIUS) |
|
69 | return numpy.rad2deg(km/EARTH_RADIUS) | |
70 |
|
70 | |||
71 |
|
71 | |||
72 | def figpause(interval): |
|
72 | def figpause(interval): | |
73 | backend = plt.rcParams['backend'] |
|
73 | backend = plt.rcParams['backend'] | |
74 | if backend in matplotlib.rcsetup.interactive_bk: |
|
74 | if backend in matplotlib.rcsetup.interactive_bk: | |
75 | figManager = matplotlib._pylab_helpers.Gcf.get_active() |
|
75 | figManager = matplotlib._pylab_helpers.Gcf.get_active() | |
76 | if figManager is not None: |
|
76 | if figManager is not None: | |
77 | canvas = figManager.canvas |
|
77 | canvas = figManager.canvas | |
78 | if canvas.figure.stale: |
|
78 | if canvas.figure.stale: | |
79 | canvas.draw() |
|
79 | canvas.draw() | |
80 | try: |
|
80 | try: | |
81 | canvas.start_event_loop(interval) |
|
81 | canvas.start_event_loop(interval) | |
82 | except: |
|
82 | except: | |
83 | pass |
|
83 | pass | |
84 | return |
|
84 | return | |
85 |
|
85 | |||
86 | def popup(message): |
|
86 | def popup(message): | |
87 | ''' |
|
87 | ''' | |
88 | ''' |
|
88 | ''' | |
89 |
|
89 | |||
90 | fig = plt.figure(figsize=(12, 8), facecolor='r') |
|
90 | fig = plt.figure(figsize=(12, 8), facecolor='r') | |
91 | text = '\n'.join([s.strip() for s in message.split(':')]) |
|
91 | text = '\n'.join([s.strip() for s in message.split(':')]) | |
92 | fig.text(0.01, 0.5, text, ha='left', va='center', |
|
92 | fig.text(0.01, 0.5, text, ha='left', va='center', | |
93 | size='20', weight='heavy', color='w') |
|
93 | size='20', weight='heavy', color='w') | |
94 | fig.show() |
|
94 | fig.show() | |
95 | figpause(1000) |
|
95 | figpause(1000) | |
96 |
|
96 | |||
97 |
|
97 | |||
98 | class Throttle(object): |
|
98 | class Throttle(object): | |
99 | ''' |
|
99 | ''' | |
100 | Decorator that prevents a function from being called more than once every |
|
100 | Decorator that prevents a function from being called more than once every | |
101 | time period. |
|
101 | time period. | |
102 | To create a function that cannot be called more than once a minute, but |
|
102 | To create a function that cannot be called more than once a minute, but | |
103 | will sleep until it can be called: |
|
103 | will sleep until it can be called: | |
104 | @Throttle(minutes=1) |
|
104 | @Throttle(minutes=1) | |
105 | def foo(): |
|
105 | def foo(): | |
106 | pass |
|
106 | pass | |
107 |
|
107 | |||
108 | for i in range(10): |
|
108 | for i in range(10): | |
109 | foo() |
|
109 | foo() | |
110 | print "This function has run %s times." % i |
|
110 | print "This function has run %s times." % i | |
111 | ''' |
|
111 | ''' | |
112 |
|
112 | |||
113 | def __init__(self, seconds=0, minutes=0, hours=0): |
|
113 | def __init__(self, seconds=0, minutes=0, hours=0): | |
114 | self.throttle_period = datetime.timedelta( |
|
114 | self.throttle_period = datetime.timedelta( | |
115 | seconds=seconds, minutes=minutes, hours=hours |
|
115 | seconds=seconds, minutes=minutes, hours=hours | |
116 | ) |
|
116 | ) | |
117 |
|
117 | |||
118 | self.time_of_last_call = datetime.datetime.min |
|
118 | self.time_of_last_call = datetime.datetime.min | |
119 |
|
119 | |||
120 | def __call__(self, fn): |
|
120 | def __call__(self, fn): | |
121 | @wraps(fn) |
|
121 | @wraps(fn) | |
122 | def wrapper(*args, **kwargs): |
|
122 | def wrapper(*args, **kwargs): | |
123 | coerce = kwargs.pop('coerce', None) |
|
123 | coerce = kwargs.pop('coerce', None) | |
124 | if coerce: |
|
124 | if coerce: | |
125 | self.time_of_last_call = datetime.datetime.now() |
|
125 | self.time_of_last_call = datetime.datetime.now() | |
126 | return fn(*args, **kwargs) |
|
126 | return fn(*args, **kwargs) | |
127 | else: |
|
127 | else: | |
128 | now = datetime.datetime.now() |
|
128 | now = datetime.datetime.now() | |
129 | time_since_last_call = now - self.time_of_last_call |
|
129 | time_since_last_call = now - self.time_of_last_call | |
130 | time_left = self.throttle_period - time_since_last_call |
|
130 | time_left = self.throttle_period - time_since_last_call | |
131 |
|
131 | |||
132 | if time_left > datetime.timedelta(seconds=0): |
|
132 | if time_left > datetime.timedelta(seconds=0): | |
133 | return |
|
133 | return | |
134 |
|
134 | |||
135 | self.time_of_last_call = datetime.datetime.now() |
|
135 | self.time_of_last_call = datetime.datetime.now() | |
136 | return fn(*args, **kwargs) |
|
136 | return fn(*args, **kwargs) | |
137 |
|
137 | |||
138 | return wrapper |
|
138 | return wrapper | |
139 |
|
139 | |||
140 | def apply_throttle(value): |
|
140 | def apply_throttle(value): | |
141 |
|
141 | |||
142 | @Throttle(seconds=value) |
|
142 | @Throttle(seconds=value) | |
143 | def fnThrottled(fn): |
|
143 | def fnThrottled(fn): | |
144 | fn() |
|
144 | fn() | |
145 |
|
145 | |||
146 | return fnThrottled |
|
146 | return fnThrottled | |
147 |
|
147 | |||
148 |
|
148 | |||
149 | @MPDecorator |
|
149 | @MPDecorator | |
150 | class Plot(Operation): |
|
150 | class Plot(Operation): | |
151 | """Base class for Schain plotting operations |
|
151 | """Base class for Schain plotting operations | |
152 |
|
152 | |||
153 | This class should never be use directtly you must subclass a new operation, |
|
153 | This class should never be use directtly you must subclass a new operation, | |
154 | children classes must be defined as follow: |
|
154 | children classes must be defined as follow: | |
155 |
|
155 | |||
156 | ExamplePlot(Plot): |
|
156 | ExamplePlot(Plot): | |
157 |
|
157 | |||
158 | CODE = 'code' |
|
158 | CODE = 'code' | |
159 | colormap = 'jet' |
|
159 | colormap = 'jet' | |
160 | plot_type = 'pcolor' # options are ('pcolor', 'pcolorbuffer', 'scatter', 'scatterbuffer') |
|
160 | plot_type = 'pcolor' # options are ('pcolor', 'pcolorbuffer', 'scatter', 'scatterbuffer') | |
161 |
|
161 | |||
162 | def setup(self): |
|
162 | def setup(self): | |
163 | pass |
|
163 | pass | |
164 |
|
164 | |||
165 | def plot(self): |
|
165 | def plot(self): | |
166 | pass |
|
166 | pass | |
167 |
|
167 | |||
168 | """ |
|
168 | """ | |
169 |
|
169 | |||
170 | CODE = 'Figure' |
|
170 | CODE = 'Figure' | |
171 | colormap = 'jet' |
|
171 | colormap = 'jet' | |
172 | bgcolor = 'white' |
|
172 | bgcolor = 'white' | |
173 | buffering = True |
|
173 | buffering = True | |
174 | __missing = 1E30 |
|
174 | __missing = 1E30 | |
175 |
|
175 | |||
176 | __attrs__ = ['show', 'save', 'ymin', 'ymax', 'zmin', 'zmax', 'title', |
|
176 | __attrs__ = ['show', 'save', 'ymin', 'ymax', 'zmin', 'zmax', 'title', | |
177 | 'showprofile'] |
|
177 | 'showprofile'] | |
178 |
|
178 | |||
179 | def __init__(self): |
|
179 | def __init__(self): | |
180 |
|
180 | |||
181 | Operation.__init__(self) |
|
181 | Operation.__init__(self) | |
182 | self.isConfig = False |
|
182 | self.isConfig = False | |
183 | self.isPlotConfig = False |
|
183 | self.isPlotConfig = False | |
184 | self.save_time = 0 |
|
184 | self.save_time = 0 | |
185 | self.sender_time = 0 |
|
185 | self.sender_time = 0 | |
186 | self.data = None |
|
186 | self.data = None | |
187 | self.firsttime = True |
|
187 | self.firsttime = True | |
188 | self.sender_queue = deque(maxlen=10) |
|
188 | self.sender_queue = deque(maxlen=10) | |
189 | self.plots_adjust = {'left': 0.125, 'right': 0.9, 'bottom': 0.15, 'top': 0.9, 'wspace': 0.2, 'hspace': 0.2} |
|
189 | self.plots_adjust = {'left': 0.125, 'right': 0.9, 'bottom': 0.15, 'top': 0.9, 'wspace': 0.2, 'hspace': 0.2} | |
190 |
|
190 | |||
191 | def __fmtTime(self, x, pos): |
|
191 | def __fmtTime(self, x, pos): | |
192 | ''' |
|
192 | ''' | |
193 | ''' |
|
193 | ''' | |
194 |
|
194 | |||
195 | return '{}'.format(self.getDateTime(x).strftime('%H:%M')) |
|
195 | return '{}'.format(self.getDateTime(x).strftime('%H:%M')) | |
196 |
|
196 | |||
197 | def __setup(self, **kwargs): |
|
197 | def __setup(self, **kwargs): | |
198 | ''' |
|
198 | ''' | |
199 | Initialize variables |
|
199 | Initialize variables | |
200 | ''' |
|
200 | ''' | |
201 |
|
201 | |||
202 | self.figures = [] |
|
202 | self.figures = [] | |
203 | self.axes = [] |
|
203 | self.axes = [] | |
204 | self.cb_axes = [] |
|
204 | self.cb_axes = [] | |
205 | self.localtime = kwargs.pop('localtime', True) |
|
205 | self.localtime = kwargs.pop('localtime', True) | |
206 | self.show = kwargs.get('show', True) |
|
206 | self.show = kwargs.get('show', True) | |
207 | self.save = kwargs.get('save', False) |
|
207 | self.save = kwargs.get('save', False) | |
208 | self.save_period = kwargs.get('save_period', 0) |
|
208 | self.save_period = kwargs.get('save_period', 0) | |
209 | self.colormap = kwargs.get('colormap', self.colormap) |
|
209 | self.colormap = kwargs.get('colormap', self.colormap) | |
210 | self.colormap_coh = kwargs.get('colormap_coh', 'jet') |
|
210 | self.colormap_coh = kwargs.get('colormap_coh', 'jet') | |
211 | self.colormap_phase = kwargs.get('colormap_phase', 'RdBu_r') |
|
211 | self.colormap_phase = kwargs.get('colormap_phase', 'RdBu_r') | |
212 | self.colormaps = kwargs.get('colormaps', None) |
|
212 | self.colormaps = kwargs.get('colormaps', None) | |
213 | self.bgcolor = kwargs.get('bgcolor', self.bgcolor) |
|
213 | self.bgcolor = kwargs.get('bgcolor', self.bgcolor) | |
214 | self.showprofile = kwargs.get('showprofile', False) |
|
214 | self.showprofile = kwargs.get('showprofile', False) | |
215 | self.title = kwargs.get('wintitle', self.CODE.upper()) |
|
215 | self.title = kwargs.get('wintitle', self.CODE.upper()) | |
216 | self.cb_label = kwargs.get('cb_label', None) |
|
216 | self.cb_label = kwargs.get('cb_label', None) | |
217 | self.cb_labels = kwargs.get('cb_labels', None) |
|
217 | self.cb_labels = kwargs.get('cb_labels', None) | |
218 | self.labels = kwargs.get('labels', None) |
|
218 | self.labels = kwargs.get('labels', None) | |
219 | self.xaxis = kwargs.get('xaxis', 'frequency') |
|
219 | self.xaxis = kwargs.get('xaxis', 'frequency') | |
220 | self.zmin = kwargs.get('zmin', None) |
|
220 | self.zmin = kwargs.get('zmin', None) | |
221 | self.zmax = kwargs.get('zmax', None) |
|
221 | self.zmax = kwargs.get('zmax', None) | |
222 | self.zlimits = kwargs.get('zlimits', None) |
|
222 | self.zlimits = kwargs.get('zlimits', None) | |
223 | self.xmin = kwargs.get('xmin', None) |
|
223 | self.xmin = kwargs.get('xmin', None) | |
224 | self.xmax = kwargs.get('xmax', None) |
|
224 | self.xmax = kwargs.get('xmax', None) | |
225 | self.xrange = kwargs.get('xrange', 12) |
|
225 | self.xrange = kwargs.get('xrange', 12) | |
226 | self.xscale = kwargs.get('xscale', None) |
|
226 | self.xscale = kwargs.get('xscale', None) | |
227 | self.ymin = kwargs.get('ymin', None) |
|
227 | self.ymin = kwargs.get('ymin', None) | |
228 | self.ymax = kwargs.get('ymax', None) |
|
228 | self.ymax = kwargs.get('ymax', None) | |
229 | self.yscale = kwargs.get('yscale', None) |
|
229 | self.yscale = kwargs.get('yscale', None) | |
230 | self.xlabel = kwargs.get('xlabel', None) |
|
230 | self.xlabel = kwargs.get('xlabel', None) | |
231 | self.attr_time = kwargs.get('attr_time', 'utctime') |
|
231 | self.attr_time = kwargs.get('attr_time', 'utctime') | |
232 | self.attr_data = kwargs.get('attr_data', 'data_param') |
|
232 | self.attr_data = kwargs.get('attr_data', 'data_param') | |
233 | self.decimation = kwargs.get('decimation', None) |
|
233 | self.decimation = kwargs.get('decimation', None) | |
234 | self.oneFigure = kwargs.get('oneFigure', True) |
|
234 | self.oneFigure = kwargs.get('oneFigure', True) | |
235 | self.width = kwargs.get('width', None) |
|
235 | self.width = kwargs.get('width', None) | |
236 | self.height = kwargs.get('height', None) |
|
236 | self.height = kwargs.get('height', None) | |
237 | self.colorbar = kwargs.get('colorbar', True) |
|
237 | self.colorbar = kwargs.get('colorbar', True) | |
238 | self.factors = kwargs.get('factors', [1, 1, 1, 1, 1, 1, 1, 1]) |
|
238 | self.factors = kwargs.get('factors', [1, 1, 1, 1, 1, 1, 1, 1]) | |
239 | self.channels = kwargs.get('channels', None) |
|
239 | self.channels = kwargs.get('channels', None) | |
240 | self.titles = kwargs.get('titles', []) |
|
240 | self.titles = kwargs.get('titles', []) | |
241 | self.polar = False |
|
241 | self.polar = False | |
242 | self.type = kwargs.get('type', 'iq') |
|
242 | self.type = kwargs.get('type', 'iq') | |
243 | self.grid = kwargs.get('grid', False) |
|
243 | self.grid = kwargs.get('grid', False) | |
244 | self.pause = kwargs.get('pause', False) |
|
244 | self.pause = kwargs.get('pause', False) | |
245 | self.save_code = kwargs.get('save_code', self.CODE) |
|
245 | self.save_code = kwargs.get('save_code', self.CODE) | |
246 | self.throttle = kwargs.get('throttle', 0) |
|
246 | self.throttle = kwargs.get('throttle', 0) | |
247 | self.exp_code = kwargs.get('exp_code', None) |
|
247 | self.exp_code = kwargs.get('exp_code', None) | |
248 | self.server = kwargs.get('server', False) |
|
248 | self.server = kwargs.get('server', False) | |
249 | self.sender_period = kwargs.get('sender_period', 60) |
|
249 | self.sender_period = kwargs.get('sender_period', 60) | |
250 | self.tag = kwargs.get('tag', '') |
|
250 | self.tag = kwargs.get('tag', '') | |
251 | self.height_index = kwargs.get('height_index', None) |
|
251 | self.height_index = kwargs.get('height_index', None) | |
252 | self.__throttle_plot = apply_throttle(self.throttle) |
|
252 | self.__throttle_plot = apply_throttle(self.throttle) | |
253 | code = self.attr_data if self.attr_data else self.CODE |
|
253 | code = self.attr_data if self.attr_data else self.CODE | |
254 | self.data = PlotterData(self.CODE, self.exp_code, self.localtime) |
|
254 | self.data = PlotterData(self.CODE, self.exp_code, self.localtime) | |
255 | self.ang_min = kwargs.get('ang_min', None) |
|
255 | self.ang_min = kwargs.get('ang_min', None) | |
256 | self.ang_max = kwargs.get('ang_max', None) |
|
256 | self.ang_max = kwargs.get('ang_max', None) | |
|
257 | self.mode = kwargs.get('mode', None) | |||
257 |
|
258 | |||
258 |
|
259 | |||
259 | if self.server: |
|
260 | if self.server: | |
260 | if not self.server.startswith('tcp://'): |
|
261 | if not self.server.startswith('tcp://'): | |
261 | self.server = 'tcp://{}'.format(self.server) |
|
262 | self.server = 'tcp://{}'.format(self.server) | |
262 | log.success( |
|
263 | log.success( | |
263 | 'Sending to server: {}'.format(self.server), |
|
264 | 'Sending to server: {}'.format(self.server), | |
264 | self.name |
|
265 | self.name | |
265 | ) |
|
266 | ) | |
266 |
|
267 | |||
267 | if isinstance(self.attr_data, str): |
|
268 | if isinstance(self.attr_data, str): | |
268 | self.attr_data = [self.attr_data] |
|
269 | self.attr_data = [self.attr_data] | |
269 |
|
270 | |||
270 | def __setup_plot(self): |
|
271 | def __setup_plot(self): | |
271 | ''' |
|
272 | ''' | |
272 | Common setup for all figures, here figures and axes are created |
|
273 | Common setup for all figures, here figures and axes are created | |
273 | ''' |
|
274 | ''' | |
274 |
|
275 | |||
275 | self.setup() |
|
276 | self.setup() | |
276 |
|
277 | |||
277 | self.time_label = 'LT' if self.localtime else 'UTC' |
|
278 | self.time_label = 'LT' if self.localtime else 'UTC' | |
278 |
|
279 | |||
279 | if self.width is None: |
|
280 | if self.width is None: | |
280 | self.width = 8 |
|
281 | self.width = 8 | |
281 |
|
282 | |||
282 | self.figures = [] |
|
283 | self.figures = [] | |
283 | self.axes = [] |
|
284 | self.axes = [] | |
284 | self.cb_axes = [] |
|
285 | self.cb_axes = [] | |
285 | self.pf_axes = [] |
|
286 | self.pf_axes = [] | |
286 | self.cmaps = [] |
|
287 | self.cmaps = [] | |
287 |
|
288 | |||
288 | size = '15%' if self.ncols == 1 else '30%' |
|
289 | size = '15%' if self.ncols == 1 else '30%' | |
289 | pad = '4%' if self.ncols == 1 else '8%' |
|
290 | pad = '4%' if self.ncols == 1 else '8%' | |
290 |
|
291 | |||
291 | if self.oneFigure: |
|
292 | if self.oneFigure: | |
292 | if self.height is None: |
|
293 | if self.height is None: | |
293 | self.height = 1.4 * self.nrows + 1 |
|
294 | self.height = 1.4 * self.nrows + 1 | |
294 | fig = plt.figure(figsize=(self.width, self.height), |
|
295 | fig = plt.figure(figsize=(self.width, self.height), | |
295 | edgecolor='k', |
|
296 | edgecolor='k', | |
296 | facecolor='w') |
|
297 | facecolor='w') | |
297 | self.figures.append(fig) |
|
298 | self.figures.append(fig) | |
298 | for n in range(self.nplots): |
|
299 | for n in range(self.nplots): | |
299 | ax = fig.add_subplot(self.nrows, self.ncols, |
|
300 | ax = fig.add_subplot(self.nrows, self.ncols, | |
300 | n + 1, polar=self.polar) |
|
301 | n + 1, polar=self.polar) | |
301 | ax.tick_params(labelsize=8) |
|
302 | ax.tick_params(labelsize=8) | |
302 | ax.firsttime = True |
|
303 | ax.firsttime = True | |
303 | ax.index = 0 |
|
304 | ax.index = 0 | |
304 | ax.press = None |
|
305 | ax.press = None | |
305 | self.axes.append(ax) |
|
306 | self.axes.append(ax) | |
306 | if self.showprofile: |
|
307 | if self.showprofile: | |
307 | cax = self.__add_axes(ax, size=size, pad=pad) |
|
308 | cax = self.__add_axes(ax, size=size, pad=pad) | |
308 | cax.tick_params(labelsize=8) |
|
309 | cax.tick_params(labelsize=8) | |
309 | self.pf_axes.append(cax) |
|
310 | self.pf_axes.append(cax) | |
310 | else: |
|
311 | else: | |
311 | if self.height is None: |
|
312 | if self.height is None: | |
312 | self.height = 3 |
|
313 | self.height = 3 | |
313 | for n in range(self.nplots): |
|
314 | for n in range(self.nplots): | |
314 | fig = plt.figure(figsize=(self.width, self.height), |
|
315 | fig = plt.figure(figsize=(self.width, self.height), | |
315 | edgecolor='k', |
|
316 | edgecolor='k', | |
316 | facecolor='w') |
|
317 | facecolor='w') | |
317 | ax = fig.add_subplot(1, 1, 1, polar=self.polar) |
|
318 | ax = fig.add_subplot(1, 1, 1, polar=self.polar) | |
318 | ax.tick_params(labelsize=8) |
|
319 | ax.tick_params(labelsize=8) | |
319 | ax.firsttime = True |
|
320 | ax.firsttime = True | |
320 | ax.index = 0 |
|
321 | ax.index = 0 | |
321 | ax.press = None |
|
322 | ax.press = None | |
322 | self.figures.append(fig) |
|
323 | self.figures.append(fig) | |
323 | self.axes.append(ax) |
|
324 | self.axes.append(ax) | |
324 | if self.showprofile: |
|
325 | if self.showprofile: | |
325 | cax = self.__add_axes(ax, size=size, pad=pad) |
|
326 | cax = self.__add_axes(ax, size=size, pad=pad) | |
326 | cax.tick_params(labelsize=8) |
|
327 | cax.tick_params(labelsize=8) | |
327 | self.pf_axes.append(cax) |
|
328 | self.pf_axes.append(cax) | |
328 |
|
329 | |||
329 | for n in range(self.nrows): |
|
330 | for n in range(self.nrows): | |
330 | if self.colormaps is not None: |
|
331 | if self.colormaps is not None: | |
331 | cmap = plt.get_cmap(self.colormaps[n]) |
|
332 | cmap = plt.get_cmap(self.colormaps[n]) | |
332 | else: |
|
333 | else: | |
333 | cmap = plt.get_cmap(self.colormap) |
|
334 | cmap = plt.get_cmap(self.colormap) | |
334 | cmap.set_bad(self.bgcolor, 1.) |
|
335 | cmap.set_bad(self.bgcolor, 1.) | |
335 | self.cmaps.append(cmap) |
|
336 | self.cmaps.append(cmap) | |
336 |
|
337 | |||
337 | def __add_axes(self, ax, size='30%', pad='8%'): |
|
338 | def __add_axes(self, ax, size='30%', pad='8%'): | |
338 | ''' |
|
339 | ''' | |
339 | Add new axes to the given figure |
|
340 | Add new axes to the given figure | |
340 | ''' |
|
341 | ''' | |
341 | divider = make_axes_locatable(ax) |
|
342 | divider = make_axes_locatable(ax) | |
342 | nax = divider.new_horizontal(size=size, pad=pad) |
|
343 | nax = divider.new_horizontal(size=size, pad=pad) | |
343 | ax.figure.add_axes(nax) |
|
344 | ax.figure.add_axes(nax) | |
344 | return nax |
|
345 | return nax | |
345 |
|
346 | |||
346 | def fill_gaps(self, x_buffer, y_buffer, z_buffer): |
|
347 | def fill_gaps(self, x_buffer, y_buffer, z_buffer): | |
347 | ''' |
|
348 | ''' | |
348 | Create a masked array for missing data |
|
349 | Create a masked array for missing data | |
349 | ''' |
|
350 | ''' | |
350 | if x_buffer.shape[0] < 2: |
|
351 | if x_buffer.shape[0] < 2: | |
351 | return x_buffer, y_buffer, z_buffer |
|
352 | return x_buffer, y_buffer, z_buffer | |
352 |
|
353 | |||
353 | deltas = x_buffer[1:] - x_buffer[0:-1] |
|
354 | deltas = x_buffer[1:] - x_buffer[0:-1] | |
354 | x_median = numpy.median(deltas) |
|
355 | x_median = numpy.median(deltas) | |
355 |
|
356 | |||
356 | index = numpy.where(deltas > 5 * x_median) |
|
357 | index = numpy.where(deltas > 5 * x_median) | |
357 |
|
358 | |||
358 | if len(index[0]) != 0: |
|
359 | if len(index[0]) != 0: | |
359 | z_buffer[::, index[0], ::] = self.__missing |
|
360 | z_buffer[::, index[0], ::] = self.__missing | |
360 | z_buffer = numpy.ma.masked_inside(z_buffer, |
|
361 | z_buffer = numpy.ma.masked_inside(z_buffer, | |
361 | 0.99 * self.__missing, |
|
362 | 0.99 * self.__missing, | |
362 | 1.01 * self.__missing) |
|
363 | 1.01 * self.__missing) | |
363 |
|
364 | |||
364 | return x_buffer, y_buffer, z_buffer |
|
365 | return x_buffer, y_buffer, z_buffer | |
365 |
|
366 | |||
366 | def decimate(self): |
|
367 | def decimate(self): | |
367 |
|
368 | |||
368 | # dx = int(len(self.x)/self.__MAXNUMX) + 1 |
|
369 | # dx = int(len(self.x)/self.__MAXNUMX) + 1 | |
369 | dy = int(len(self.y) / self.decimation) + 1 |
|
370 | dy = int(len(self.y) / self.decimation) + 1 | |
370 |
|
371 | |||
371 | # x = self.x[::dx] |
|
372 | # x = self.x[::dx] | |
372 | x = self.x |
|
373 | x = self.x | |
373 | y = self.y[::dy] |
|
374 | y = self.y[::dy] | |
374 | z = self.z[::, ::, ::dy] |
|
375 | z = self.z[::, ::, ::dy] | |
375 |
|
376 | |||
376 | return x, y, z |
|
377 | return x, y, z | |
377 |
|
378 | |||
378 | def format(self): |
|
379 | def format(self): | |
379 | ''' |
|
380 | ''' | |
380 | Set min and max values, labels, ticks and titles |
|
381 | Set min and max values, labels, ticks and titles | |
381 | ''' |
|
382 | ''' | |
382 |
|
383 | |||
383 | for n, ax in enumerate(self.axes): |
|
384 | for n, ax in enumerate(self.axes): | |
384 | if ax.firsttime: |
|
385 | if ax.firsttime: | |
385 | if self.xaxis != 'time': |
|
386 | if self.xaxis != 'time': | |
386 | xmin = self.xmin |
|
387 | xmin = self.xmin | |
387 | xmax = self.xmax |
|
388 | xmax = self.xmax | |
388 | else: |
|
389 | else: | |
389 | xmin = self.tmin |
|
390 | xmin = self.tmin | |
390 | xmax = self.tmin + self.xrange*60*60 |
|
391 | xmax = self.tmin + self.xrange*60*60 | |
391 | ax.xaxis.set_major_formatter(FuncFormatter(self.__fmtTime)) |
|
392 | ax.xaxis.set_major_formatter(FuncFormatter(self.__fmtTime)) | |
392 | ax.xaxis.set_major_locator(LinearLocator(9)) |
|
393 | ax.xaxis.set_major_locator(LinearLocator(9)) | |
393 | ymin = self.ymin if self.ymin is not None else numpy.nanmin(self.y[numpy.isfinite(self.y)]) |
|
394 | ymin = self.ymin if self.ymin is not None else numpy.nanmin(self.y[numpy.isfinite(self.y)]) | |
394 | ymax = self.ymax if self.ymax is not None else numpy.nanmax(self.y[numpy.isfinite(self.y)]) |
|
395 | ymax = self.ymax if self.ymax is not None else numpy.nanmax(self.y[numpy.isfinite(self.y)]) | |
395 | ax.set_facecolor(self.bgcolor) |
|
396 | ax.set_facecolor(self.bgcolor) | |
396 | if self.xscale: |
|
397 | if self.xscale: | |
397 | ax.xaxis.set_major_formatter(FuncFormatter( |
|
398 | ax.xaxis.set_major_formatter(FuncFormatter( | |
398 | lambda x, pos: '{0:g}'.format(x*self.xscale))) |
|
399 | lambda x, pos: '{0:g}'.format(x*self.xscale))) | |
399 | if self.yscale: |
|
400 | if self.yscale: | |
400 | ax.yaxis.set_major_formatter(FuncFormatter( |
|
401 | ax.yaxis.set_major_formatter(FuncFormatter( | |
401 | lambda x, pos: '{0:g}'.format(x*self.yscale))) |
|
402 | lambda x, pos: '{0:g}'.format(x*self.yscale))) | |
402 | if self.xlabel is not None: |
|
403 | if self.xlabel is not None: | |
403 | ax.set_xlabel(self.xlabel) |
|
404 | ax.set_xlabel(self.xlabel) | |
404 | if self.ylabel is not None: |
|
405 | if self.ylabel is not None: | |
405 | ax.set_ylabel(self.ylabel) |
|
406 | ax.set_ylabel(self.ylabel) | |
406 | if self.showprofile: |
|
407 | if self.showprofile: | |
407 | self.pf_axes[n].set_ylim(ymin, ymax) |
|
408 | self.pf_axes[n].set_ylim(ymin, ymax) | |
408 | self.pf_axes[n].set_xlim(self.zmin, self.zmax) |
|
409 | self.pf_axes[n].set_xlim(self.zmin, self.zmax) | |
409 | self.pf_axes[n].set_xlabel('dB') |
|
410 | self.pf_axes[n].set_xlabel('dB') | |
410 | self.pf_axes[n].grid(b=True, axis='x') |
|
411 | self.pf_axes[n].grid(b=True, axis='x') | |
411 | [tick.set_visible(False) |
|
412 | [tick.set_visible(False) | |
412 | for tick in self.pf_axes[n].get_yticklabels()] |
|
413 | for tick in self.pf_axes[n].get_yticklabels()] | |
413 | if self.colorbar: |
|
414 | if self.colorbar: | |
414 | ax.cbar = plt.colorbar( |
|
415 | ax.cbar = plt.colorbar( | |
415 | ax.plt, ax=ax, fraction=0.05, pad=0.02, aspect=10) |
|
416 | ax.plt, ax=ax, fraction=0.05, pad=0.02, aspect=10) | |
416 | ax.cbar.ax.tick_params(labelsize=8) |
|
417 | ax.cbar.ax.tick_params(labelsize=8) | |
417 | ax.cbar.ax.press = None |
|
418 | ax.cbar.ax.press = None | |
418 | if self.cb_label: |
|
419 | if self.cb_label: | |
419 | ax.cbar.set_label(self.cb_label, size=8) |
|
420 | ax.cbar.set_label(self.cb_label, size=8) | |
420 | elif self.cb_labels: |
|
421 | elif self.cb_labels: | |
421 | ax.cbar.set_label(self.cb_labels[n], size=8) |
|
422 | ax.cbar.set_label(self.cb_labels[n], size=8) | |
422 | else: |
|
423 | else: | |
423 | ax.cbar = None |
|
424 | ax.cbar = None | |
424 | ax.set_xlim(xmin, xmax) |
|
425 | ax.set_xlim(xmin, xmax) | |
425 | ax.set_ylim(ymin, ymax) |
|
426 | ax.set_ylim(ymin, ymax) | |
426 | ax.firsttime = False |
|
427 | ax.firsttime = False | |
427 | if self.grid: |
|
428 | if self.grid: | |
428 | ax.grid(True) |
|
429 | ax.grid(True) | |
429 | if not self.polar: |
|
430 | if not self.polar: | |
430 | ax.set_title('{} {} {}'.format( |
|
431 | ax.set_title('{} {} {}'.format( | |
431 | self.titles[n], |
|
432 | self.titles[n], | |
432 | self.getDateTime(self.data.max_time).strftime( |
|
433 | self.getDateTime(self.data.max_time).strftime( | |
433 | '%Y-%m-%d %H:%M:%S'), |
|
434 | '%Y-%m-%d %H:%M:%S'), | |
434 | self.time_label), |
|
435 | self.time_label), | |
435 | size=8) |
|
436 | size=8) | |
436 | else: |
|
437 | else: | |
437 | ax.set_title('{}'.format(self.titles[n]), size=8) |
|
438 | #ax.set_title('{}'.format(self.titles[n]), size=8) | |
438 |
ax.set_ |
|
439 | ax.set_title('{} {} {}'.format( | |
439 | ax.set_yticks(numpy.arange(0, 90, 20)) |
|
440 | self.titles[n], | |
|
441 | self.getDateTime(self.data.max_time).strftime( | |||
|
442 | '%Y-%m-%d %H:%M:%S'), | |||
|
443 | self.time_label), | |||
|
444 | size=8) | |||
|
445 | ax.set_ylim(0, self.ymax) | |||
|
446 | #ax.set_yticks(numpy.arange(0, self.ymax, 20)) | |||
440 | ax.yaxis.labelpad = 40 |
|
447 | ax.yaxis.labelpad = 40 | |
441 |
|
448 | |||
442 | if self.firsttime: |
|
449 | if self.firsttime: | |
443 | for n, fig in enumerate(self.figures): |
|
450 | for n, fig in enumerate(self.figures): | |
444 | fig.subplots_adjust(**self.plots_adjust) |
|
451 | fig.subplots_adjust(**self.plots_adjust) | |
445 | self.firsttime = False |
|
452 | self.firsttime = False | |
446 |
|
453 | |||
447 | def clear_figures(self): |
|
454 | def clear_figures(self): | |
448 | ''' |
|
455 | ''' | |
449 | Reset axes for redraw plots |
|
456 | Reset axes for redraw plots | |
450 | ''' |
|
457 | ''' | |
451 |
|
458 | |||
452 | for ax in self.axes+self.pf_axes+self.cb_axes: |
|
459 | for ax in self.axes+self.pf_axes+self.cb_axes: | |
453 | ax.clear() |
|
460 | ax.clear() | |
454 | ax.firsttime = True |
|
461 | ax.firsttime = True | |
455 | if hasattr(ax, 'cbar') and ax.cbar: |
|
462 | if hasattr(ax, 'cbar') and ax.cbar: | |
456 | ax.cbar.remove() |
|
463 | ax.cbar.remove() | |
457 |
|
464 | |||
458 | def __plot(self): |
|
465 | def __plot(self): | |
459 | ''' |
|
466 | ''' | |
460 | Main function to plot, format and save figures |
|
467 | Main function to plot, format and save figures | |
461 | ''' |
|
468 | ''' | |
462 |
|
469 | |||
463 | self.plot() |
|
470 | self.plot() | |
464 | self.format() |
|
471 | self.format() | |
465 |
|
472 | |||
466 | for n, fig in enumerate(self.figures): |
|
473 | for n, fig in enumerate(self.figures): | |
467 | if self.nrows == 0 or self.nplots == 0: |
|
474 | if self.nrows == 0 or self.nplots == 0: | |
468 | log.warning('No data', self.name) |
|
475 | log.warning('No data', self.name) | |
469 | fig.text(0.5, 0.5, 'No Data', fontsize='large', ha='center') |
|
476 | fig.text(0.5, 0.5, 'No Data', fontsize='large', ha='center') | |
470 | fig.canvas.manager.set_window_title(self.CODE) |
|
477 | fig.canvas.manager.set_window_title(self.CODE) | |
471 | continue |
|
478 | continue | |
472 |
|
479 | |||
473 | fig.canvas.manager.set_window_title('{} - {}'.format(self.title, |
|
480 | fig.canvas.manager.set_window_title('{} - {}'.format(self.title, | |
474 | self.getDateTime(self.data.max_time).strftime('%Y/%m/%d'))) |
|
481 | self.getDateTime(self.data.max_time).strftime('%Y/%m/%d'))) | |
475 | fig.canvas.draw() |
|
482 | fig.canvas.draw() | |
476 | if self.show: |
|
483 | if self.show: | |
477 | fig.show() |
|
484 | fig.show() | |
478 | figpause(0.01) |
|
485 | figpause(0.01) | |
479 |
|
486 | |||
480 | if self.save: |
|
487 | if self.save: | |
481 | self.save_figure(n) |
|
488 | self.save_figure(n) | |
482 |
|
489 | |||
483 | if self.server: |
|
490 | if self.server: | |
484 | self.send_to_server() |
|
491 | self.send_to_server() | |
485 |
|
492 | |||
486 | def __update(self, dataOut, timestamp): |
|
493 | def __update(self, dataOut, timestamp): | |
487 | ''' |
|
494 | ''' | |
488 | ''' |
|
495 | ''' | |
489 |
|
496 | |||
490 | metadata = { |
|
497 | metadata = { | |
491 | 'yrange': dataOut.heightList, |
|
498 | 'yrange': dataOut.heightList, | |
492 | 'interval': dataOut.timeInterval, |
|
499 | 'interval': dataOut.timeInterval, | |
493 | 'channels': dataOut.channelList |
|
500 | 'channels': dataOut.channelList | |
494 | } |
|
501 | } | |
495 |
|
502 | |||
496 | data, meta = self.update(dataOut) |
|
503 | data, meta = self.update(dataOut) | |
497 | metadata.update(meta) |
|
504 | metadata.update(meta) | |
498 | self.data.update(data, timestamp, metadata) |
|
505 | self.data.update(data, timestamp, metadata) | |
499 |
|
506 | |||
500 | def save_figure(self, n): |
|
507 | def save_figure(self, n): | |
501 | ''' |
|
508 | ''' | |
502 | ''' |
|
509 | ''' | |
503 | if self.oneFigure: |
|
510 | if self.oneFigure: | |
504 | if (self.data.max_time - self.save_time) <= self.save_period: |
|
511 | if (self.data.max_time - self.save_time) <= self.save_period: | |
505 | return |
|
512 | return | |
506 |
|
513 | |||
507 | self.save_time = self.data.max_time |
|
514 | self.save_time = self.data.max_time | |
508 |
|
515 | |||
509 | fig = self.figures[n] |
|
516 | fig = self.figures[n] | |
510 | if self.throttle == 0: |
|
517 | if self.throttle == 0: | |
511 | if self.oneFigure: |
|
518 | if self.oneFigure: | |
512 | figname = os.path.join( |
|
519 | figname = os.path.join( | |
513 | self.save, |
|
520 | self.save, | |
514 | self.save_code, |
|
521 | self.save_code, | |
515 | '{}_{}.png'.format( |
|
522 | '{}_{}.png'.format( | |
516 | self.save_code, |
|
523 | self.save_code, | |
517 | self.getDateTime(self.data.max_time).strftime( |
|
524 | self.getDateTime(self.data.max_time).strftime( | |
518 | '%Y%m%d_%H%M%S' |
|
525 | '%Y%m%d_%H%M%S' | |
519 | ), |
|
526 | ), | |
520 | ) |
|
527 | ) | |
521 | ) |
|
528 | ) | |
522 | else: |
|
529 | else: | |
523 | figname = os.path.join( |
|
530 | figname = os.path.join( | |
524 | self.save, |
|
531 | self.save, | |
525 | self.save_code, |
|
532 | self.save_code, | |
526 | '{}_ch{}_{}.png'.format( |
|
533 | '{}_ch{}_{}.png'.format( | |
527 | self.save_code,n, |
|
534 | self.save_code,n, | |
528 | self.getDateTime(self.data.max_time).strftime( |
|
535 | self.getDateTime(self.data.max_time).strftime( | |
529 | '%Y%m%d_%H%M%S' |
|
536 | '%Y%m%d_%H%M%S' | |
530 | ), |
|
537 | ), | |
531 | ) |
|
538 | ) | |
532 | ) |
|
539 | ) | |
533 | log.log('Saving figure: {}'.format(figname), self.name) |
|
540 | log.log('Saving figure: {}'.format(figname), self.name) | |
534 | if not os.path.isdir(os.path.dirname(figname)): |
|
541 | if not os.path.isdir(os.path.dirname(figname)): | |
535 | os.makedirs(os.path.dirname(figname)) |
|
542 | os.makedirs(os.path.dirname(figname)) | |
536 | fig.savefig(figname) |
|
543 | fig.savefig(figname) | |
537 |
|
544 | |||
538 | figname = os.path.join( |
|
545 | figname = os.path.join( | |
539 | self.save, |
|
546 | self.save, | |
540 | '{}_{}.png'.format( |
|
547 | '{}_{}.png'.format( | |
541 | self.save_code, |
|
548 | self.save_code, | |
542 | self.getDateTime(self.data.min_time).strftime( |
|
549 | self.getDateTime(self.data.min_time).strftime( | |
543 | '%Y%m%d' |
|
550 | '%Y%m%d' | |
544 | ), |
|
551 | ), | |
545 | ) |
|
552 | ) | |
546 | ) |
|
553 | ) | |
547 |
|
554 | |||
548 | log.log('Saving figure: {}'.format(figname), self.name) |
|
555 | log.log('Saving figure: {}'.format(figname), self.name) | |
549 | if not os.path.isdir(os.path.dirname(figname)): |
|
556 | if not os.path.isdir(os.path.dirname(figname)): | |
550 | os.makedirs(os.path.dirname(figname)) |
|
557 | os.makedirs(os.path.dirname(figname)) | |
551 | fig.savefig(figname) |
|
558 | fig.savefig(figname) | |
552 |
|
559 | |||
553 | def send_to_server(self): |
|
560 | def send_to_server(self): | |
554 | ''' |
|
561 | ''' | |
555 | ''' |
|
562 | ''' | |
556 |
|
563 | |||
557 | if self.exp_code == None: |
|
564 | if self.exp_code == None: | |
558 | log.warning('Missing `exp_code` skipping sending to server...') |
|
565 | log.warning('Missing `exp_code` skipping sending to server...') | |
559 |
|
566 | |||
560 | last_time = self.data.max_time |
|
567 | last_time = self.data.max_time | |
561 | interval = last_time - self.sender_time |
|
568 | interval = last_time - self.sender_time | |
562 | if interval < self.sender_period: |
|
569 | if interval < self.sender_period: | |
563 | return |
|
570 | return | |
564 |
|
571 | |||
565 | self.sender_time = last_time |
|
572 | self.sender_time = last_time | |
566 |
|
573 | |||
567 | attrs = ['titles', 'zmin', 'zmax', 'tag', 'ymin', 'ymax'] |
|
574 | attrs = ['titles', 'zmin', 'zmax', 'tag', 'ymin', 'ymax'] | |
568 | for attr in attrs: |
|
575 | for attr in attrs: | |
569 | value = getattr(self, attr) |
|
576 | value = getattr(self, attr) | |
570 | if value: |
|
577 | if value: | |
571 | if isinstance(value, (numpy.float32, numpy.float64)): |
|
578 | if isinstance(value, (numpy.float32, numpy.float64)): | |
572 | value = round(float(value), 2) |
|
579 | value = round(float(value), 2) | |
573 | self.data.meta[attr] = value |
|
580 | self.data.meta[attr] = value | |
574 | if self.colormap == 'jet': |
|
581 | if self.colormap == 'jet': | |
575 | self.data.meta['colormap'] = 'Jet' |
|
582 | self.data.meta['colormap'] = 'Jet' | |
576 | elif 'RdBu' in self.colormap: |
|
583 | elif 'RdBu' in self.colormap: | |
577 | self.data.meta['colormap'] = 'RdBu' |
|
584 | self.data.meta['colormap'] = 'RdBu' | |
578 | else: |
|
585 | else: | |
579 | self.data.meta['colormap'] = 'Viridis' |
|
586 | self.data.meta['colormap'] = 'Viridis' | |
580 | self.data.meta['interval'] = int(interval) |
|
587 | self.data.meta['interval'] = int(interval) | |
581 |
|
588 | |||
582 | self.sender_queue.append(last_time) |
|
589 | self.sender_queue.append(last_time) | |
583 |
|
590 | |||
584 | while True: |
|
591 | while True: | |
585 | try: |
|
592 | try: | |
586 | tm = self.sender_queue.popleft() |
|
593 | tm = self.sender_queue.popleft() | |
587 | except IndexError: |
|
594 | except IndexError: | |
588 | break |
|
595 | break | |
589 | msg = self.data.jsonify(tm, self.save_code, self.plot_type) |
|
596 | msg = self.data.jsonify(tm, self.save_code, self.plot_type) | |
590 | self.socket.send_string(msg) |
|
597 | self.socket.send_string(msg) | |
591 | socks = dict(self.poll.poll(2000)) |
|
598 | socks = dict(self.poll.poll(2000)) | |
592 | if socks.get(self.socket) == zmq.POLLIN: |
|
599 | if socks.get(self.socket) == zmq.POLLIN: | |
593 | reply = self.socket.recv_string() |
|
600 | reply = self.socket.recv_string() | |
594 | if reply == 'ok': |
|
601 | if reply == 'ok': | |
595 | log.log("Response from server ok", self.name) |
|
602 | log.log("Response from server ok", self.name) | |
596 | time.sleep(0.1) |
|
603 | time.sleep(0.1) | |
597 | continue |
|
604 | continue | |
598 | else: |
|
605 | else: | |
599 | log.warning( |
|
606 | log.warning( | |
600 | "Malformed reply from server: {}".format(reply), self.name) |
|
607 | "Malformed reply from server: {}".format(reply), self.name) | |
601 | else: |
|
608 | else: | |
602 | log.warning( |
|
609 | log.warning( | |
603 | "No response from server, retrying...", self.name) |
|
610 | "No response from server, retrying...", self.name) | |
604 | self.sender_queue.appendleft(tm) |
|
611 | self.sender_queue.appendleft(tm) | |
605 | self.socket.setsockopt(zmq.LINGER, 0) |
|
612 | self.socket.setsockopt(zmq.LINGER, 0) | |
606 | self.socket.close() |
|
613 | self.socket.close() | |
607 | self.poll.unregister(self.socket) |
|
614 | self.poll.unregister(self.socket) | |
608 | self.socket = self.context.socket(zmq.REQ) |
|
615 | self.socket = self.context.socket(zmq.REQ) | |
609 | self.socket.connect(self.server) |
|
616 | self.socket.connect(self.server) | |
610 | self.poll.register(self.socket, zmq.POLLIN) |
|
617 | self.poll.register(self.socket, zmq.POLLIN) | |
611 | break |
|
618 | break | |
612 |
|
619 | |||
613 | def setup(self): |
|
620 | def setup(self): | |
614 | ''' |
|
621 | ''' | |
615 | This method should be implemented in the child class, the following |
|
622 | This method should be implemented in the child class, the following | |
616 | attributes should be set: |
|
623 | attributes should be set: | |
617 |
|
624 | |||
618 | self.nrows: number of rows |
|
625 | self.nrows: number of rows | |
619 | self.ncols: number of cols |
|
626 | self.ncols: number of cols | |
620 | self.nplots: number of plots (channels or pairs) |
|
627 | self.nplots: number of plots (channels or pairs) | |
621 | self.ylabel: label for Y axes |
|
628 | self.ylabel: label for Y axes | |
622 | self.titles: list of axes title |
|
629 | self.titles: list of axes title | |
623 |
|
630 | |||
624 | ''' |
|
631 | ''' | |
625 | raise NotImplementedError |
|
632 | raise NotImplementedError | |
626 |
|
633 | |||
627 | def plot(self): |
|
634 | def plot(self): | |
628 | ''' |
|
635 | ''' | |
629 | Must be defined in the child class, the actual plotting method |
|
636 | Must be defined in the child class, the actual plotting method | |
630 | ''' |
|
637 | ''' | |
631 | raise NotImplementedError |
|
638 | raise NotImplementedError | |
632 |
|
639 | |||
633 | def update(self, dataOut): |
|
640 | def update(self, dataOut): | |
634 | ''' |
|
641 | ''' | |
635 | Must be defined in the child class, update self.data with new data |
|
642 | Must be defined in the child class, update self.data with new data | |
636 | ''' |
|
643 | ''' | |
637 |
|
644 | |||
638 | data = { |
|
645 | data = { | |
639 | self.CODE: getattr(dataOut, 'data_{}'.format(self.CODE)) |
|
646 | self.CODE: getattr(dataOut, 'data_{}'.format(self.CODE)) | |
640 | } |
|
647 | } | |
641 | meta = {} |
|
648 | meta = {} | |
642 |
|
649 | |||
643 | return data, meta |
|
650 | return data, meta | |
644 |
|
651 | |||
645 | def run(self, dataOut, **kwargs): |
|
652 | def run(self, dataOut, **kwargs): | |
646 | ''' |
|
653 | ''' | |
647 | Main plotting routine |
|
654 | Main plotting routine | |
648 | ''' |
|
655 | ''' | |
649 |
|
656 | |||
650 | if self.isConfig is False: |
|
657 | if self.isConfig is False: | |
651 | self.__setup(**kwargs) |
|
658 | self.__setup(**kwargs) | |
652 |
|
659 | |||
653 | if self.localtime: |
|
660 | if self.localtime: | |
654 | self.getDateTime = datetime.datetime.fromtimestamp |
|
661 | self.getDateTime = datetime.datetime.fromtimestamp | |
655 | else: |
|
662 | else: | |
656 | self.getDateTime = datetime.datetime.utcfromtimestamp |
|
663 | self.getDateTime = datetime.datetime.utcfromtimestamp | |
657 |
|
664 | |||
658 | self.data.setup() |
|
665 | self.data.setup() | |
659 | self.isConfig = True |
|
666 | self.isConfig = True | |
660 | if self.server: |
|
667 | if self.server: | |
661 | self.context = zmq.Context() |
|
668 | self.context = zmq.Context() | |
662 | self.socket = self.context.socket(zmq.REQ) |
|
669 | self.socket = self.context.socket(zmq.REQ) | |
663 | self.socket.connect(self.server) |
|
670 | self.socket.connect(self.server) | |
664 | self.poll = zmq.Poller() |
|
671 | self.poll = zmq.Poller() | |
665 | self.poll.register(self.socket, zmq.POLLIN) |
|
672 | self.poll.register(self.socket, zmq.POLLIN) | |
666 |
|
673 | |||
667 | tm = getattr(dataOut, self.attr_time) |
|
674 | tm = getattr(dataOut, self.attr_time) | |
668 |
|
675 | |||
669 | if self.data and 'time' in self.xaxis and (tm - self.tmin) >= self.xrange*60*60: |
|
676 | if self.data and 'time' in self.xaxis and (tm - self.tmin) >= self.xrange*60*60: | |
670 | self.save_time = tm |
|
677 | self.save_time = tm | |
671 | self.__plot() |
|
678 | self.__plot() | |
672 | self.tmin += self.xrange*60*60 |
|
679 | self.tmin += self.xrange*60*60 | |
673 | self.data.setup() |
|
680 | self.data.setup() | |
674 | self.clear_figures() |
|
681 | self.clear_figures() | |
675 |
|
682 | |||
676 | self.__update(dataOut, tm) |
|
683 | self.__update(dataOut, tm) | |
677 |
|
684 | |||
678 | if self.isPlotConfig is False: |
|
685 | if self.isPlotConfig is False: | |
679 | self.__setup_plot() |
|
686 | self.__setup_plot() | |
680 | self.isPlotConfig = True |
|
687 | self.isPlotConfig = True | |
681 | if self.xaxis == 'time': |
|
688 | if self.xaxis == 'time': | |
682 | dt = self.getDateTime(tm) |
|
689 | dt = self.getDateTime(tm) | |
683 | if self.xmin is None: |
|
690 | if self.xmin is None: | |
684 | self.tmin = tm |
|
691 | self.tmin = tm | |
685 | self.xmin = dt.hour |
|
692 | self.xmin = dt.hour | |
686 | minutes = (self.xmin-int(self.xmin)) * 60 |
|
693 | minutes = (self.xmin-int(self.xmin)) * 60 | |
687 | seconds = (minutes - int(minutes)) * 60 |
|
694 | seconds = (minutes - int(minutes)) * 60 | |
688 | self.tmin = (dt.replace(hour=int(self.xmin), minute=int(minutes), second=int(seconds)) - |
|
695 | self.tmin = (dt.replace(hour=int(self.xmin), minute=int(minutes), second=int(seconds)) - | |
689 | datetime.datetime(1970, 1, 1)).total_seconds() |
|
696 | datetime.datetime(1970, 1, 1)).total_seconds() | |
690 | if self.localtime: |
|
697 | if self.localtime: | |
691 | self.tmin += time.timezone |
|
698 | self.tmin += time.timezone | |
692 |
|
699 | |||
693 | if self.xmin is not None and self.xmax is not None: |
|
700 | if self.xmin is not None and self.xmax is not None: | |
694 | self.xrange = self.xmax - self.xmin |
|
701 | self.xrange = self.xmax - self.xmin | |
695 |
|
702 | |||
696 | if self.throttle == 0: |
|
703 | if self.throttle == 0: | |
697 | self.__plot() |
|
704 | self.__plot() | |
698 | else: |
|
705 | else: | |
699 | self.__throttle_plot(self.__plot)#, coerce=coerce) |
|
706 | self.__throttle_plot(self.__plot)#, coerce=coerce) | |
700 |
|
707 | |||
701 | def close(self): |
|
708 | def close(self): | |
702 |
|
709 | |||
703 | if self.data and not self.data.flagNoData: |
|
710 | if self.data and not self.data.flagNoData: | |
704 | self.save_time = 0 |
|
711 | self.save_time = 0 | |
705 | self.__plot() |
|
712 | self.__plot() | |
706 | if self.data and not self.data.flagNoData and self.pause: |
|
713 | if self.data and not self.data.flagNoData and self.pause: | |
707 | figpause(10) |
|
714 | figpause(10) |
@@ -1,2378 +1,2522 | |||||
1 | import os |
|
1 | import os | |
2 | import datetime |
|
2 | import datetime | |
3 | import numpy |
|
3 | import numpy | |
4 | from mpl_toolkits.axisartist.grid_finder import FixedLocator, DictFormatter |
|
4 | from mpl_toolkits.axisartist.grid_finder import FixedLocator, DictFormatter | |
5 |
|
5 | |||
6 | from schainpy.model.graphics.jroplot_base import Plot, plt |
|
6 | from schainpy.model.graphics.jroplot_base import Plot, plt | |
7 | from schainpy.model.graphics.jroplot_spectra import SpectraPlot, RTIPlot, CoherencePlot, SpectraCutPlot |
|
7 | from schainpy.model.graphics.jroplot_spectra import SpectraPlot, RTIPlot, CoherencePlot, SpectraCutPlot | |
8 | from schainpy.utils import log |
|
8 | from schainpy.utils import log | |
9 | # libreria wradlib |
|
9 | # libreria wradlib | |
10 | import wradlib as wrl |
|
10 | import wradlib as wrl | |
11 |
|
11 | |||
12 | EARTH_RADIUS = 6.3710e3 |
|
12 | EARTH_RADIUS = 6.3710e3 | |
13 |
|
13 | |||
14 |
|
14 | |||
15 | def ll2xy(lat1, lon1, lat2, lon2): |
|
15 | def ll2xy(lat1, lon1, lat2, lon2): | |
16 |
|
16 | |||
17 | p = 0.017453292519943295 |
|
17 | p = 0.017453292519943295 | |
18 | a = 0.5 - numpy.cos((lat2 - lat1) * p)/2 + numpy.cos(lat1 * p) * \ |
|
18 | a = 0.5 - numpy.cos((lat2 - lat1) * p)/2 + numpy.cos(lat1 * p) * \ | |
19 | numpy.cos(lat2 * p) * (1 - numpy.cos((lon2 - lon1) * p)) / 2 |
|
19 | numpy.cos(lat2 * p) * (1 - numpy.cos((lon2 - lon1) * p)) / 2 | |
20 | r = 12742 * numpy.arcsin(numpy.sqrt(a)) |
|
20 | r = 12742 * numpy.arcsin(numpy.sqrt(a)) | |
21 | theta = numpy.arctan2(numpy.sin((lon2-lon1)*p)*numpy.cos(lat2*p), numpy.cos(lat1*p) |
|
21 | theta = numpy.arctan2(numpy.sin((lon2-lon1)*p)*numpy.cos(lat2*p), numpy.cos(lat1*p) | |
22 | * numpy.sin(lat2*p)-numpy.sin(lat1*p)*numpy.cos(lat2*p)*numpy.cos((lon2-lon1)*p)) |
|
22 | * numpy.sin(lat2*p)-numpy.sin(lat1*p)*numpy.cos(lat2*p)*numpy.cos((lon2-lon1)*p)) | |
23 | theta = -theta + numpy.pi/2 |
|
23 | theta = -theta + numpy.pi/2 | |
24 | return r*numpy.cos(theta), r*numpy.sin(theta) |
|
24 | return r*numpy.cos(theta), r*numpy.sin(theta) | |
25 |
|
25 | |||
26 |
|
26 | |||
27 | def km2deg(km): |
|
27 | def km2deg(km): | |
28 | ''' |
|
28 | ''' | |
29 | Convert distance in km to degrees |
|
29 | Convert distance in km to degrees | |
30 | ''' |
|
30 | ''' | |
31 |
|
31 | |||
32 | return numpy.rad2deg(km/EARTH_RADIUS) |
|
32 | return numpy.rad2deg(km/EARTH_RADIUS) | |
33 |
|
33 | |||
34 |
|
34 | |||
35 |
|
35 | |||
36 | class SpectralMomentsPlot(SpectraPlot): |
|
36 | class SpectralMomentsPlot(SpectraPlot): | |
37 | ''' |
|
37 | ''' | |
38 | Plot for Spectral Moments |
|
38 | Plot for Spectral Moments | |
39 | ''' |
|
39 | ''' | |
40 | CODE = 'spc_moments' |
|
40 | CODE = 'spc_moments' | |
41 | # colormap = 'jet' |
|
41 | # colormap = 'jet' | |
42 | # plot_type = 'pcolor' |
|
42 | # plot_type = 'pcolor' | |
43 |
|
43 | |||
44 | class DobleGaussianPlot(SpectraPlot): |
|
44 | class DobleGaussianPlot(SpectraPlot): | |
45 | ''' |
|
45 | ''' | |
46 | Plot for Double Gaussian Plot |
|
46 | Plot for Double Gaussian Plot | |
47 | ''' |
|
47 | ''' | |
48 | CODE = 'gaussian_fit' |
|
48 | CODE = 'gaussian_fit' | |
49 | # colormap = 'jet' |
|
49 | # colormap = 'jet' | |
50 | # plot_type = 'pcolor' |
|
50 | # plot_type = 'pcolor' | |
51 |
|
51 | |||
52 | class DoubleGaussianSpectraCutPlot(SpectraCutPlot): |
|
52 | class DoubleGaussianSpectraCutPlot(SpectraCutPlot): | |
53 | ''' |
|
53 | ''' | |
54 | Plot SpectraCut with Double Gaussian Fit |
|
54 | Plot SpectraCut with Double Gaussian Fit | |
55 | ''' |
|
55 | ''' | |
56 | CODE = 'cut_gaussian_fit' |
|
56 | CODE = 'cut_gaussian_fit' | |
57 |
|
57 | |||
58 | class SnrPlot(RTIPlot): |
|
58 | class SnrPlot(RTIPlot): | |
59 | ''' |
|
59 | ''' | |
60 | Plot for SNR Data |
|
60 | Plot for SNR Data | |
61 | ''' |
|
61 | ''' | |
62 |
|
62 | |||
63 | CODE = 'snr' |
|
63 | CODE = 'snr' | |
64 | colormap = 'jet' |
|
64 | colormap = 'jet' | |
65 |
|
65 | |||
66 | def update(self, dataOut): |
|
66 | def update(self, dataOut): | |
67 |
|
67 | |||
68 | data = { |
|
68 | data = { | |
69 | 'snr': 10*numpy.log10(dataOut.data_snr) |
|
69 | 'snr': 10*numpy.log10(dataOut.data_snr) | |
70 | } |
|
70 | } | |
71 |
|
71 | |||
72 | return data, {} |
|
72 | return data, {} | |
73 |
|
73 | |||
74 | class DopplerPlot(RTIPlot): |
|
74 | class DopplerPlot(RTIPlot): | |
75 | ''' |
|
75 | ''' | |
76 | Plot for DOPPLER Data (1st moment) |
|
76 | Plot for DOPPLER Data (1st moment) | |
77 | ''' |
|
77 | ''' | |
78 |
|
78 | |||
79 | CODE = 'dop' |
|
79 | CODE = 'dop' | |
80 | colormap = 'jet' |
|
80 | colormap = 'jet' | |
81 |
|
81 | |||
82 | def update(self, dataOut): |
|
82 | def update(self, dataOut): | |
83 |
|
83 | |||
84 | data = { |
|
84 | data = { | |
85 | 'dop': 10*numpy.log10(dataOut.data_dop) |
|
85 | 'dop': 10*numpy.log10(dataOut.data_dop) | |
86 | } |
|
86 | } | |
87 |
|
87 | |||
88 | return data, {} |
|
88 | return data, {} | |
89 |
|
89 | |||
90 | class PowerPlot(RTIPlot): |
|
90 | class PowerPlot(RTIPlot): | |
91 | ''' |
|
91 | ''' | |
92 | Plot for Power Data (0 moment) |
|
92 | Plot for Power Data (0 moment) | |
93 | ''' |
|
93 | ''' | |
94 |
|
94 | |||
95 | CODE = 'pow' |
|
95 | CODE = 'pow' | |
96 | colormap = 'jet' |
|
96 | colormap = 'jet' | |
97 |
|
97 | |||
98 | def update(self, dataOut): |
|
98 | def update(self, dataOut): | |
99 | data = { |
|
99 | data = { | |
100 | 'pow': 10*numpy.log10(dataOut.data_pow/dataOut.normFactor) |
|
100 | 'pow': 10*numpy.log10(dataOut.data_pow/dataOut.normFactor) | |
101 | } |
|
101 | } | |
102 | return data, {} |
|
102 | return data, {} | |
103 |
|
103 | |||
104 | class SpectralWidthPlot(RTIPlot): |
|
104 | class SpectralWidthPlot(RTIPlot): | |
105 | ''' |
|
105 | ''' | |
106 | Plot for Spectral Width Data (2nd moment) |
|
106 | Plot for Spectral Width Data (2nd moment) | |
107 | ''' |
|
107 | ''' | |
108 |
|
108 | |||
109 | CODE = 'width' |
|
109 | CODE = 'width' | |
110 | colormap = 'jet' |
|
110 | colormap = 'jet' | |
111 |
|
111 | |||
112 | def update(self, dataOut): |
|
112 | def update(self, dataOut): | |
113 |
|
113 | |||
114 | data = { |
|
114 | data = { | |
115 | 'width': dataOut.data_width |
|
115 | 'width': dataOut.data_width | |
116 | } |
|
116 | } | |
117 |
|
117 | |||
118 | return data, {} |
|
118 | return data, {} | |
119 |
|
119 | |||
120 | class SkyMapPlot(Plot): |
|
120 | class SkyMapPlot(Plot): | |
121 | ''' |
|
121 | ''' | |
122 | Plot for meteors detection data |
|
122 | Plot for meteors detection data | |
123 | ''' |
|
123 | ''' | |
124 |
|
124 | |||
125 | CODE = 'param' |
|
125 | CODE = 'param' | |
126 |
|
126 | |||
127 | def setup(self): |
|
127 | def setup(self): | |
128 |
|
128 | |||
129 | self.ncols = 1 |
|
129 | self.ncols = 1 | |
130 | self.nrows = 1 |
|
130 | self.nrows = 1 | |
131 | self.width = 7.2 |
|
131 | self.width = 7.2 | |
132 | self.height = 7.2 |
|
132 | self.height = 7.2 | |
133 | self.nplots = 1 |
|
133 | self.nplots = 1 | |
134 | self.xlabel = 'Zonal Zenith Angle (deg)' |
|
134 | self.xlabel = 'Zonal Zenith Angle (deg)' | |
135 | self.ylabel = 'Meridional Zenith Angle (deg)' |
|
135 | self.ylabel = 'Meridional Zenith Angle (deg)' | |
136 | self.polar = True |
|
136 | self.polar = True | |
137 | self.ymin = -180 |
|
137 | self.ymin = -180 | |
138 | self.ymax = 180 |
|
138 | self.ymax = 180 | |
139 | self.colorbar = False |
|
139 | self.colorbar = False | |
140 |
|
140 | |||
141 | def plot(self): |
|
141 | def plot(self): | |
142 |
|
142 | |||
143 | arrayParameters = numpy.concatenate(self.data['param']) |
|
143 | arrayParameters = numpy.concatenate(self.data['param']) | |
144 | error = arrayParameters[:, -1] |
|
144 | error = arrayParameters[:, -1] | |
145 | indValid = numpy.where(error == 0)[0] |
|
145 | indValid = numpy.where(error == 0)[0] | |
146 | finalMeteor = arrayParameters[indValid, :] |
|
146 | finalMeteor = arrayParameters[indValid, :] | |
147 | finalAzimuth = finalMeteor[:, 3] |
|
147 | finalAzimuth = finalMeteor[:, 3] | |
148 | finalZenith = finalMeteor[:, 4] |
|
148 | finalZenith = finalMeteor[:, 4] | |
149 |
|
149 | |||
150 | x = finalAzimuth * numpy.pi / 180 |
|
150 | x = finalAzimuth * numpy.pi / 180 | |
151 | y = finalZenith |
|
151 | y = finalZenith | |
152 |
|
152 | |||
153 | ax = self.axes[0] |
|
153 | ax = self.axes[0] | |
154 |
|
154 | |||
155 | if ax.firsttime: |
|
155 | if ax.firsttime: | |
156 | ax.plot = ax.plot(x, y, 'bo', markersize=5)[0] |
|
156 | ax.plot = ax.plot(x, y, 'bo', markersize=5)[0] | |
157 | else: |
|
157 | else: | |
158 | ax.plot.set_data(x, y) |
|
158 | ax.plot.set_data(x, y) | |
159 |
|
159 | |||
160 | dt1 = self.getDateTime(self.data.min_time).strftime('%y/%m/%d %H:%M:%S') |
|
160 | dt1 = self.getDateTime(self.data.min_time).strftime('%y/%m/%d %H:%M:%S') | |
161 | dt2 = self.getDateTime(self.data.max_time).strftime('%y/%m/%d %H:%M:%S') |
|
161 | dt2 = self.getDateTime(self.data.max_time).strftime('%y/%m/%d %H:%M:%S') | |
162 | title = 'Meteor Detection Sky Map\n %s - %s \n Number of events: %5.0f\n' % (dt1, |
|
162 | title = 'Meteor Detection Sky Map\n %s - %s \n Number of events: %5.0f\n' % (dt1, | |
163 | dt2, |
|
163 | dt2, | |
164 | len(x)) |
|
164 | len(x)) | |
165 | self.titles[0] = title |
|
165 | self.titles[0] = title | |
166 |
|
166 | |||
167 |
|
167 | |||
168 | class GenericRTIPlot(Plot): |
|
168 | class GenericRTIPlot(Plot): | |
169 | ''' |
|
169 | ''' | |
170 | Plot for data_xxxx object |
|
170 | Plot for data_xxxx object | |
171 | ''' |
|
171 | ''' | |
172 |
|
172 | |||
173 | CODE = 'param' |
|
173 | CODE = 'param' | |
174 | colormap = 'viridis' |
|
174 | colormap = 'viridis' | |
175 | plot_type = 'pcolorbuffer' |
|
175 | plot_type = 'pcolorbuffer' | |
176 |
|
176 | |||
177 | def setup(self): |
|
177 | def setup(self): | |
178 | self.xaxis = 'time' |
|
178 | self.xaxis = 'time' | |
179 | self.ncols = 1 |
|
179 | self.ncols = 1 | |
180 | self.nrows = self.data.shape('param')[0] |
|
180 | self.nrows = self.data.shape('param')[0] | |
181 | self.nplots = self.nrows |
|
181 | self.nplots = self.nrows | |
182 | self.plots_adjust.update({'hspace':0.8, 'left': 0.1, 'bottom': 0.08, 'right':0.95, 'top': 0.95}) |
|
182 | self.plots_adjust.update({'hspace':0.8, 'left': 0.1, 'bottom': 0.08, 'right':0.95, 'top': 0.95}) | |
183 |
|
183 | |||
184 | if not self.xlabel: |
|
184 | if not self.xlabel: | |
185 | self.xlabel = 'Time' |
|
185 | self.xlabel = 'Time' | |
186 |
|
186 | |||
187 | self.ylabel = 'Range [km]' |
|
187 | self.ylabel = 'Range [km]' | |
188 | if not self.titles: |
|
188 | if not self.titles: | |
189 | self.titles = ['Param {}'.format(x) for x in range(self.nrows)] |
|
189 | self.titles = ['Param {}'.format(x) for x in range(self.nrows)] | |
190 |
|
190 | |||
191 | def update(self, dataOut): |
|
191 | def update(self, dataOut): | |
192 |
|
192 | |||
193 | data = { |
|
193 | data = { | |
194 | 'param' : numpy.concatenate([getattr(dataOut, attr) for attr in self.attr_data], axis=0) |
|
194 | 'param' : numpy.concatenate([getattr(dataOut, attr) for attr in self.attr_data], axis=0) | |
195 | } |
|
195 | } | |
196 |
|
196 | |||
197 | meta = {} |
|
197 | meta = {} | |
198 |
|
198 | |||
199 | return data, meta |
|
199 | return data, meta | |
200 |
|
200 | |||
201 | def plot(self): |
|
201 | def plot(self): | |
202 | # self.data.normalize_heights() |
|
202 | # self.data.normalize_heights() | |
203 | self.x = self.data.times |
|
203 | self.x = self.data.times | |
204 | self.y = self.data.yrange |
|
204 | self.y = self.data.yrange | |
205 | self.z = self.data['param'] |
|
205 | self.z = self.data['param'] | |
206 | self.z = 10*numpy.log10(self.z) |
|
206 | self.z = 10*numpy.log10(self.z) | |
207 | self.z = numpy.ma.masked_invalid(self.z) |
|
207 | self.z = numpy.ma.masked_invalid(self.z) | |
208 |
|
208 | |||
209 | if self.decimation is None: |
|
209 | if self.decimation is None: | |
210 | x, y, z = self.fill_gaps(self.x, self.y, self.z) |
|
210 | x, y, z = self.fill_gaps(self.x, self.y, self.z) | |
211 | else: |
|
211 | else: | |
212 | x, y, z = self.fill_gaps(*self.decimate()) |
|
212 | x, y, z = self.fill_gaps(*self.decimate()) | |
213 |
|
213 | |||
214 | for n, ax in enumerate(self.axes): |
|
214 | for n, ax in enumerate(self.axes): | |
215 |
|
215 | |||
216 | self.zmax = self.zmax if self.zmax is not None else numpy.max( |
|
216 | self.zmax = self.zmax if self.zmax is not None else numpy.max( | |
217 | self.z[n]) |
|
217 | self.z[n]) | |
218 | self.zmin = self.zmin if self.zmin is not None else numpy.min( |
|
218 | self.zmin = self.zmin if self.zmin is not None else numpy.min( | |
219 | self.z[n]) |
|
219 | self.z[n]) | |
220 |
|
220 | |||
221 | if ax.firsttime: |
|
221 | if ax.firsttime: | |
222 | if self.zlimits is not None: |
|
222 | if self.zlimits is not None: | |
223 | self.zmin, self.zmax = self.zlimits[n] |
|
223 | self.zmin, self.zmax = self.zlimits[n] | |
224 |
|
224 | |||
225 | ax.plt = ax.pcolormesh(x, y, z[n].T * self.factors[n], |
|
225 | ax.plt = ax.pcolormesh(x, y, z[n].T * self.factors[n], | |
226 | vmin=self.zmin, |
|
226 | vmin=self.zmin, | |
227 | vmax=self.zmax, |
|
227 | vmax=self.zmax, | |
228 | cmap=self.cmaps[n] |
|
228 | cmap=self.cmaps[n] | |
229 | ) |
|
229 | ) | |
230 | else: |
|
230 | else: | |
231 | if self.zlimits is not None: |
|
231 | if self.zlimits is not None: | |
232 | self.zmin, self.zmax = self.zlimits[n] |
|
232 | self.zmin, self.zmax = self.zlimits[n] | |
233 | ax.collections.remove(ax.collections[0]) |
|
233 | ax.collections.remove(ax.collections[0]) | |
234 | ax.plt = ax.pcolormesh(x, y, z[n].T * self.factors[n], |
|
234 | ax.plt = ax.pcolormesh(x, y, z[n].T * self.factors[n], | |
235 | vmin=self.zmin, |
|
235 | vmin=self.zmin, | |
236 | vmax=self.zmax, |
|
236 | vmax=self.zmax, | |
237 | cmap=self.cmaps[n] |
|
237 | cmap=self.cmaps[n] | |
238 | ) |
|
238 | ) | |
239 |
|
239 | |||
240 |
|
240 | |||
241 | class PolarMapPlot(Plot): |
|
241 | class PolarMapPlot(Plot): | |
242 | ''' |
|
242 | ''' | |
243 | Plot for weather radar |
|
243 | Plot for weather radar | |
244 | ''' |
|
244 | ''' | |
245 |
|
245 | |||
246 | CODE = 'param' |
|
246 | CODE = 'param' | |
247 | colormap = 'seismic' |
|
247 | colormap = 'seismic' | |
248 |
|
248 | |||
249 | def setup(self): |
|
249 | def setup(self): | |
250 | self.ncols = 1 |
|
250 | self.ncols = 1 | |
251 | self.nrows = 1 |
|
251 | self.nrows = 1 | |
252 | self.width = 9 |
|
252 | self.width = 9 | |
253 | self.height = 8 |
|
253 | self.height = 8 | |
254 | self.mode = self.data.meta['mode'] |
|
254 | self.mode = self.data.meta['mode'] | |
255 | if self.channels is not None: |
|
255 | if self.channels is not None: | |
256 | self.nplots = len(self.channels) |
|
256 | self.nplots = len(self.channels) | |
257 | self.nrows = len(self.channels) |
|
257 | self.nrows = len(self.channels) | |
258 | else: |
|
258 | else: | |
259 | self.nplots = self.data.shape(self.CODE)[0] |
|
259 | self.nplots = self.data.shape(self.CODE)[0] | |
260 | self.nrows = self.nplots |
|
260 | self.nrows = self.nplots | |
261 | self.channels = list(range(self.nplots)) |
|
261 | self.channels = list(range(self.nplots)) | |
262 | if self.mode == 'E': |
|
262 | if self.mode == 'E': | |
263 | self.xlabel = 'Longitude' |
|
263 | self.xlabel = 'Longitude' | |
264 | self.ylabel = 'Latitude' |
|
264 | self.ylabel = 'Latitude' | |
265 | else: |
|
265 | else: | |
266 | self.xlabel = 'Range (km)' |
|
266 | self.xlabel = 'Range (km)' | |
267 | self.ylabel = 'Height (km)' |
|
267 | self.ylabel = 'Height (km)' | |
268 | self.bgcolor = 'white' |
|
268 | self.bgcolor = 'white' | |
269 | self.cb_labels = self.data.meta['units'] |
|
269 | self.cb_labels = self.data.meta['units'] | |
270 | self.lat = self.data.meta['latitude'] |
|
270 | self.lat = self.data.meta['latitude'] | |
271 | self.lon = self.data.meta['longitude'] |
|
271 | self.lon = self.data.meta['longitude'] | |
272 | self.xmin, self.xmax = float( |
|
272 | self.xmin, self.xmax = float( | |
273 | km2deg(self.xmin) + self.lon), float(km2deg(self.xmax) + self.lon) |
|
273 | km2deg(self.xmin) + self.lon), float(km2deg(self.xmax) + self.lon) | |
274 | self.ymin, self.ymax = float( |
|
274 | self.ymin, self.ymax = float( | |
275 | km2deg(self.ymin) + self.lat), float(km2deg(self.ymax) + self.lat) |
|
275 | km2deg(self.ymin) + self.lat), float(km2deg(self.ymax) + self.lat) | |
276 | # self.polar = True |
|
276 | # self.polar = True | |
277 |
|
277 | |||
278 | def plot(self): |
|
278 | def plot(self): | |
279 |
|
279 | |||
280 | for n, ax in enumerate(self.axes): |
|
280 | for n, ax in enumerate(self.axes): | |
281 | data = self.data['param'][self.channels[n]] |
|
281 | data = self.data['param'][self.channels[n]] | |
282 |
|
282 | |||
283 | zeniths = numpy.linspace( |
|
283 | zeniths = numpy.linspace( | |
284 | 0, self.data.meta['max_range'], data.shape[1]) |
|
284 | 0, self.data.meta['max_range'], data.shape[1]) | |
285 | if self.mode == 'E': |
|
285 | if self.mode == 'E': | |
286 | azimuths = -numpy.radians(self.data.yrange)+numpy.pi/2 |
|
286 | azimuths = -numpy.radians(self.data.yrange)+numpy.pi/2 | |
287 | r, theta = numpy.meshgrid(zeniths, azimuths) |
|
287 | r, theta = numpy.meshgrid(zeniths, azimuths) | |
288 | x, y = r*numpy.cos(theta)*numpy.cos(numpy.radians(self.data.meta['elevation'])), r*numpy.sin( |
|
288 | x, y = r*numpy.cos(theta)*numpy.cos(numpy.radians(self.data.meta['elevation'])), r*numpy.sin( | |
289 | theta)*numpy.cos(numpy.radians(self.data.meta['elevation'])) |
|
289 | theta)*numpy.cos(numpy.radians(self.data.meta['elevation'])) | |
290 | x = km2deg(x) + self.lon |
|
290 | x = km2deg(x) + self.lon | |
291 | y = km2deg(y) + self.lat |
|
291 | y = km2deg(y) + self.lat | |
292 | else: |
|
292 | else: | |
293 | azimuths = numpy.radians(self.data.yrange) |
|
293 | azimuths = numpy.radians(self.data.yrange) | |
294 | r, theta = numpy.meshgrid(zeniths, azimuths) |
|
294 | r, theta = numpy.meshgrid(zeniths, azimuths) | |
295 | x, y = r*numpy.cos(theta), r*numpy.sin(theta) |
|
295 | x, y = r*numpy.cos(theta), r*numpy.sin(theta) | |
296 | self.y = zeniths |
|
296 | self.y = zeniths | |
297 |
|
297 | |||
298 | if ax.firsttime: |
|
298 | if ax.firsttime: | |
299 | if self.zlimits is not None: |
|
299 | if self.zlimits is not None: | |
300 | self.zmin, self.zmax = self.zlimits[n] |
|
300 | self.zmin, self.zmax = self.zlimits[n] | |
301 | ax.plt = ax.pcolormesh( # r, theta, numpy.ma.array(data, mask=numpy.isnan(data)), |
|
301 | ax.plt = ax.pcolormesh( # r, theta, numpy.ma.array(data, mask=numpy.isnan(data)), | |
302 | x, y, numpy.ma.array(data, mask=numpy.isnan(data)), |
|
302 | x, y, numpy.ma.array(data, mask=numpy.isnan(data)), | |
303 | vmin=self.zmin, |
|
303 | vmin=self.zmin, | |
304 | vmax=self.zmax, |
|
304 | vmax=self.zmax, | |
305 | cmap=self.cmaps[n]) |
|
305 | cmap=self.cmaps[n]) | |
306 | else: |
|
306 | else: | |
307 | if self.zlimits is not None: |
|
307 | if self.zlimits is not None: | |
308 | self.zmin, self.zmax = self.zlimits[n] |
|
308 | self.zmin, self.zmax = self.zlimits[n] | |
309 | ax.collections.remove(ax.collections[0]) |
|
309 | ax.collections.remove(ax.collections[0]) | |
310 | ax.plt = ax.pcolormesh( # r, theta, numpy.ma.array(data, mask=numpy.isnan(data)), |
|
310 | ax.plt = ax.pcolormesh( # r, theta, numpy.ma.array(data, mask=numpy.isnan(data)), | |
311 | x, y, numpy.ma.array(data, mask=numpy.isnan(data)), |
|
311 | x, y, numpy.ma.array(data, mask=numpy.isnan(data)), | |
312 | vmin=self.zmin, |
|
312 | vmin=self.zmin, | |
313 | vmax=self.zmax, |
|
313 | vmax=self.zmax, | |
314 | cmap=self.cmaps[n]) |
|
314 | cmap=self.cmaps[n]) | |
315 |
|
315 | |||
316 | if self.mode == 'A': |
|
316 | if self.mode == 'A': | |
317 | continue |
|
317 | continue | |
318 |
|
318 | |||
319 | # plot district names |
|
319 | # plot district names | |
320 | f = open('/data/workspace/schain_scripts/distrito.csv') |
|
320 | f = open('/data/workspace/schain_scripts/distrito.csv') | |
321 | for line in f: |
|
321 | for line in f: | |
322 | label, lon, lat = [s.strip() for s in line.split(',') if s] |
|
322 | label, lon, lat = [s.strip() for s in line.split(',') if s] | |
323 | lat = float(lat) |
|
323 | lat = float(lat) | |
324 | lon = float(lon) |
|
324 | lon = float(lon) | |
325 | # ax.plot(lon, lat, '.b', ms=2) |
|
325 | # ax.plot(lon, lat, '.b', ms=2) | |
326 | ax.text(lon, lat, label.decode('utf8'), ha='center', |
|
326 | ax.text(lon, lat, label.decode('utf8'), ha='center', | |
327 | va='bottom', size='8', color='black') |
|
327 | va='bottom', size='8', color='black') | |
328 |
|
328 | |||
329 | # plot limites |
|
329 | # plot limites | |
330 | limites = [] |
|
330 | limites = [] | |
331 | tmp = [] |
|
331 | tmp = [] | |
332 | for line in open('/data/workspace/schain_scripts/lima.csv'): |
|
332 | for line in open('/data/workspace/schain_scripts/lima.csv'): | |
333 | if '#' in line: |
|
333 | if '#' in line: | |
334 | if tmp: |
|
334 | if tmp: | |
335 | limites.append(tmp) |
|
335 | limites.append(tmp) | |
336 | tmp = [] |
|
336 | tmp = [] | |
337 | continue |
|
337 | continue | |
338 | values = line.strip().split(',') |
|
338 | values = line.strip().split(',') | |
339 | tmp.append((float(values[0]), float(values[1]))) |
|
339 | tmp.append((float(values[0]), float(values[1]))) | |
340 | for points in limites: |
|
340 | for points in limites: | |
341 | ax.add_patch( |
|
341 | ax.add_patch( | |
342 | Polygon(points, ec='k', fc='none', ls='--', lw=0.5)) |
|
342 | Polygon(points, ec='k', fc='none', ls='--', lw=0.5)) | |
343 |
|
343 | |||
344 | # plot Cuencas |
|
344 | # plot Cuencas | |
345 | for cuenca in ('rimac', 'lurin', 'mala', 'chillon', 'chilca', 'chancay-huaral'): |
|
345 | for cuenca in ('rimac', 'lurin', 'mala', 'chillon', 'chilca', 'chancay-huaral'): | |
346 | f = open('/data/workspace/schain_scripts/{}.csv'.format(cuenca)) |
|
346 | f = open('/data/workspace/schain_scripts/{}.csv'.format(cuenca)) | |
347 | values = [line.strip().split(',') for line in f] |
|
347 | values = [line.strip().split(',') for line in f] | |
348 | points = [(float(s[0]), float(s[1])) for s in values] |
|
348 | points = [(float(s[0]), float(s[1])) for s in values] | |
349 | ax.add_patch(Polygon(points, ec='b', fc='none')) |
|
349 | ax.add_patch(Polygon(points, ec='b', fc='none')) | |
350 |
|
350 | |||
351 | # plot grid |
|
351 | # plot grid | |
352 | for r in (15, 30, 45, 60): |
|
352 | for r in (15, 30, 45, 60): | |
353 | ax.add_artist(plt.Circle((self.lon, self.lat), |
|
353 | ax.add_artist(plt.Circle((self.lon, self.lat), | |
354 | km2deg(r), color='0.6', fill=False, lw=0.2)) |
|
354 | km2deg(r), color='0.6', fill=False, lw=0.2)) | |
355 | ax.text( |
|
355 | ax.text( | |
356 | self.lon + (km2deg(r))*numpy.cos(60*numpy.pi/180), |
|
356 | self.lon + (km2deg(r))*numpy.cos(60*numpy.pi/180), | |
357 | self.lat + (km2deg(r))*numpy.sin(60*numpy.pi/180), |
|
357 | self.lat + (km2deg(r))*numpy.sin(60*numpy.pi/180), | |
358 | '{}km'.format(r), |
|
358 | '{}km'.format(r), | |
359 | ha='center', va='bottom', size='8', color='0.6', weight='heavy') |
|
359 | ha='center', va='bottom', size='8', color='0.6', weight='heavy') | |
360 |
|
360 | |||
361 | if self.mode == 'E': |
|
361 | if self.mode == 'E': | |
362 | title = 'El={}$^\circ$'.format(self.data.meta['elevation']) |
|
362 | title = 'El={}$^\circ$'.format(self.data.meta['elevation']) | |
363 | label = 'E{:02d}'.format(int(self.data.meta['elevation'])) |
|
363 | label = 'E{:02d}'.format(int(self.data.meta['elevation'])) | |
364 | else: |
|
364 | else: | |
365 | title = 'Az={}$^\circ$'.format(self.data.meta['azimuth']) |
|
365 | title = 'Az={}$^\circ$'.format(self.data.meta['azimuth']) | |
366 | label = 'A{:02d}'.format(int(self.data.meta['azimuth'])) |
|
366 | label = 'A{:02d}'.format(int(self.data.meta['azimuth'])) | |
367 |
|
367 | |||
368 | self.save_labels = ['{}-{}'.format(lbl, label) for lbl in self.labels] |
|
368 | self.save_labels = ['{}-{}'.format(lbl, label) for lbl in self.labels] | |
369 | self.titles = ['{} {}'.format( |
|
369 | self.titles = ['{} {}'.format( | |
370 | self.data.parameters[x], title) for x in self.channels] |
|
370 | self.data.parameters[x], title) for x in self.channels] | |
371 |
|
371 | |||
372 | class WeatherPlot(Plot): |
|
372 | class WeatherPlot(Plot): | |
373 | CODE = 'weather' |
|
373 | CODE = 'weather' | |
374 | plot_name = 'weather' |
|
374 | plot_name = 'weather' | |
375 | plot_type = 'ppistyle' |
|
375 | plot_type = 'ppistyle' | |
376 | buffering = False |
|
376 | buffering = False | |
377 |
|
377 | |||
378 | def setup(self): |
|
378 | def setup(self): | |
379 | self.ncols = 1 |
|
379 | self.ncols = 1 | |
380 | self.nrows = 1 |
|
380 | self.nrows = 1 | |
381 | self.width =8 |
|
381 | self.width =8 | |
382 | self.height =8 |
|
382 | self.height =8 | |
383 | self.nplots= 1 |
|
383 | self.nplots= 1 | |
384 | self.ylabel= 'Range [Km]' |
|
384 | self.ylabel= 'Range [Km]' | |
385 | self.titles= ['Weather'] |
|
385 | self.titles= ['Weather'] | |
386 | self.colorbar=False |
|
386 | self.colorbar=False | |
387 | self.ini =0 |
|
387 | self.ini =0 | |
388 | self.len_azi =0 |
|
388 | self.len_azi =0 | |
389 | self.buffer_ini = None |
|
389 | self.buffer_ini = None | |
390 | self.buffer_azi = None |
|
390 | self.buffer_azi = None | |
391 | self.plots_adjust.update({'wspace': 0.4, 'hspace':0.4, 'left': 0.1, 'right': 0.9, 'bottom': 0.08}) |
|
391 | self.plots_adjust.update({'wspace': 0.4, 'hspace':0.4, 'left': 0.1, 'right': 0.9, 'bottom': 0.08}) | |
392 | self.flag =0 |
|
392 | self.flag =0 | |
393 | self.indicador= 0 |
|
393 | self.indicador= 0 | |
394 | self.last_data_azi = None |
|
394 | self.last_data_azi = None | |
395 | self.val_mean = None |
|
395 | self.val_mean = None | |
396 |
|
396 | |||
397 | def update(self, dataOut): |
|
397 | def update(self, dataOut): | |
398 |
|
398 | |||
399 | data = {} |
|
399 | data = {} | |
400 | meta = {} |
|
400 | meta = {} | |
401 | if hasattr(dataOut, 'dataPP_POWER'): |
|
401 | if hasattr(dataOut, 'dataPP_POWER'): | |
402 | factor = 1 |
|
402 | factor = 1 | |
403 | if hasattr(dataOut, 'nFFTPoints'): |
|
403 | if hasattr(dataOut, 'nFFTPoints'): | |
404 | factor = dataOut.normFactor |
|
404 | factor = dataOut.normFactor | |
405 | #print("DIME EL SHAPE PORFAVOR",dataOut.data_360.shape) |
|
405 | #print("DIME EL SHAPE PORFAVOR",dataOut.data_360.shape) | |
406 | data['weather'] = 10*numpy.log10(dataOut.data_360[1]/(factor)) |
|
406 | data['weather'] = 10*numpy.log10(dataOut.data_360[1]/(factor)) | |
407 | data['azi'] = dataOut.data_azi |
|
407 | data['azi'] = dataOut.data_azi | |
408 | data['ele'] = dataOut.data_ele |
|
408 | data['ele'] = dataOut.data_ele | |
409 | return data, meta |
|
409 | return data, meta | |
410 |
|
410 | |||
411 | def get2List(self,angulos): |
|
411 | def get2List(self,angulos): | |
412 | list1=[] |
|
412 | list1=[] | |
413 | list2=[] |
|
413 | list2=[] | |
414 | for i in reversed(range(len(angulos))): |
|
414 | for i in reversed(range(len(angulos))): | |
415 | diff_ = angulos[i]-angulos[i-1] |
|
415 | diff_ = angulos[i]-angulos[i-1] | |
416 | if diff_ >1.5: |
|
416 | if diff_ >1.5: | |
417 | list1.append(i-1) |
|
417 | list1.append(i-1) | |
418 | list2.append(diff_) |
|
418 | list2.append(diff_) | |
419 | return list(reversed(list1)),list(reversed(list2)) |
|
419 | return list(reversed(list1)),list(reversed(list2)) | |
420 |
|
420 | |||
421 | def fixData360(self,list_,ang_): |
|
421 | def fixData360(self,list_,ang_): | |
422 | if list_[0]==-1: |
|
422 | if list_[0]==-1: | |
423 | vec = numpy.where(ang_<ang_[0]) |
|
423 | vec = numpy.where(ang_<ang_[0]) | |
424 | ang_[vec] = ang_[vec]+360 |
|
424 | ang_[vec] = ang_[vec]+360 | |
425 | return ang_ |
|
425 | return ang_ | |
426 | return ang_ |
|
426 | return ang_ | |
427 |
|
427 | |||
428 | def fixData360HL(self,angulos): |
|
428 | def fixData360HL(self,angulos): | |
429 | vec = numpy.where(angulos>=360) |
|
429 | vec = numpy.where(angulos>=360) | |
430 | angulos[vec]=angulos[vec]-360 |
|
430 | angulos[vec]=angulos[vec]-360 | |
431 | return angulos |
|
431 | return angulos | |
432 |
|
432 | |||
433 | def search_pos(self,pos,list_): |
|
433 | def search_pos(self,pos,list_): | |
434 | for i in range(len(list_)): |
|
434 | for i in range(len(list_)): | |
435 | if pos == list_[i]: |
|
435 | if pos == list_[i]: | |
436 | return True,i |
|
436 | return True,i | |
437 | i=None |
|
437 | i=None | |
438 | return False,i |
|
438 | return False,i | |
439 |
|
439 | |||
440 | def fixDataComp(self,ang_,list1_,list2_): |
|
440 | def fixDataComp(self,ang_,list1_,list2_): | |
441 | size = len(ang_) |
|
441 | size = len(ang_) | |
442 | size2 = 0 |
|
442 | size2 = 0 | |
443 | for i in range(len(list2_)): |
|
443 | for i in range(len(list2_)): | |
444 | size2=size2+round(list2_[i])-1 |
|
444 | size2=size2+round(list2_[i])-1 | |
445 | new_size= size+size2 |
|
445 | new_size= size+size2 | |
446 | ang_new = numpy.zeros(new_size) |
|
446 | ang_new = numpy.zeros(new_size) | |
447 | ang_new2 = numpy.zeros(new_size) |
|
447 | ang_new2 = numpy.zeros(new_size) | |
448 |
|
448 | |||
449 | tmp = 0 |
|
449 | tmp = 0 | |
450 | c = 0 |
|
450 | c = 0 | |
451 | for i in range(len(ang_)): |
|
451 | for i in range(len(ang_)): | |
452 | ang_new[tmp +c] = ang_[i] |
|
452 | ang_new[tmp +c] = ang_[i] | |
453 | ang_new2[tmp+c] = ang_[i] |
|
453 | ang_new2[tmp+c] = ang_[i] | |
454 | condition , value = self.search_pos(i,list1_) |
|
454 | condition , value = self.search_pos(i,list1_) | |
455 | if condition: |
|
455 | if condition: | |
456 | pos = tmp + c + 1 |
|
456 | pos = tmp + c + 1 | |
457 | for k in range(round(list2_[value])-1): |
|
457 | for k in range(round(list2_[value])-1): | |
458 | ang_new[pos+k] = ang_new[pos+k-1]+1 |
|
458 | ang_new[pos+k] = ang_new[pos+k-1]+1 | |
459 | ang_new2[pos+k] = numpy.nan |
|
459 | ang_new2[pos+k] = numpy.nan | |
460 | tmp = pos +k |
|
460 | tmp = pos +k | |
461 | c = 0 |
|
461 | c = 0 | |
462 | c=c+1 |
|
462 | c=c+1 | |
463 | return ang_new,ang_new2 |
|
463 | return ang_new,ang_new2 | |
464 |
|
464 | |||
465 | def globalCheckPED(self,angulos): |
|
465 | def globalCheckPED(self,angulos): | |
466 | l1,l2 = self.get2List(angulos) |
|
466 | l1,l2 = self.get2List(angulos) | |
467 | if len(l1)>0: |
|
467 | if len(l1)>0: | |
468 | angulos2 = self.fixData360(list_=l1,ang_=angulos) |
|
468 | angulos2 = self.fixData360(list_=l1,ang_=angulos) | |
469 | l1,l2 = self.get2List(angulos2) |
|
469 | l1,l2 = self.get2List(angulos2) | |
470 |
|
470 | |||
471 | ang1_,ang2_ = self.fixDataComp(ang_=angulos2,list1_=l1,list2_=l2) |
|
471 | ang1_,ang2_ = self.fixDataComp(ang_=angulos2,list1_=l1,list2_=l2) | |
472 | ang1_ = self.fixData360HL(ang1_) |
|
472 | ang1_ = self.fixData360HL(ang1_) | |
473 | ang2_ = self.fixData360HL(ang2_) |
|
473 | ang2_ = self.fixData360HL(ang2_) | |
474 | else: |
|
474 | else: | |
475 | ang1_= angulos |
|
475 | ang1_= angulos | |
476 | ang2_= angulos |
|
476 | ang2_= angulos | |
477 | return ang1_,ang2_ |
|
477 | return ang1_,ang2_ | |
478 |
|
478 | |||
479 | def analizeDATA(self,data_azi): |
|
479 | def analizeDATA(self,data_azi): | |
480 | list1 = [] |
|
480 | list1 = [] | |
481 | list2 = [] |
|
481 | list2 = [] | |
482 | dat = data_azi |
|
482 | dat = data_azi | |
483 | for i in reversed(range(1,len(dat))): |
|
483 | for i in reversed(range(1,len(dat))): | |
484 | if dat[i]>dat[i-1]: |
|
484 | if dat[i]>dat[i-1]: | |
485 | diff = int(dat[i])-int(dat[i-1]) |
|
485 | diff = int(dat[i])-int(dat[i-1]) | |
486 | else: |
|
486 | else: | |
487 | diff = 360+int(dat[i])-int(dat[i-1]) |
|
487 | diff = 360+int(dat[i])-int(dat[i-1]) | |
488 | if diff > 1: |
|
488 | if diff > 1: | |
489 | list1.append(i-1) |
|
489 | list1.append(i-1) | |
490 | list2.append(diff-1) |
|
490 | list2.append(diff-1) | |
491 | return list1,list2 |
|
491 | return list1,list2 | |
492 |
|
492 | |||
493 | def fixDATANEW(self,data_azi,data_weather): |
|
493 | def fixDATANEW(self,data_azi,data_weather): | |
494 | list1,list2 = self.analizeDATA(data_azi) |
|
494 | list1,list2 = self.analizeDATA(data_azi) | |
495 | if len(list1)== 0: |
|
495 | if len(list1)== 0: | |
496 | return data_azi,data_weather |
|
496 | return data_azi,data_weather | |
497 | else: |
|
497 | else: | |
498 | resize = 0 |
|
498 | resize = 0 | |
499 | for i in range(len(list2)): |
|
499 | for i in range(len(list2)): | |
500 | resize= resize + list2[i] |
|
500 | resize= resize + list2[i] | |
501 | new_data_azi = numpy.resize(data_azi,resize) |
|
501 | new_data_azi = numpy.resize(data_azi,resize) | |
502 | new_data_weather= numpy.resize(date_weather,resize) |
|
502 | new_data_weather= numpy.resize(date_weather,resize) | |
503 |
|
503 | |||
504 | for i in range(len(list2)): |
|
504 | for i in range(len(list2)): | |
505 | j=0 |
|
505 | j=0 | |
506 | position=list1[i]+1 |
|
506 | position=list1[i]+1 | |
507 | for j in range(list2[i]): |
|
507 | for j in range(list2[i]): | |
508 | new_data_azi[position+j]=new_data_azi[position+j-1]+1 |
|
508 | new_data_azi[position+j]=new_data_azi[position+j-1]+1 | |
509 | return new_data_azi |
|
509 | return new_data_azi | |
510 |
|
510 | |||
511 | def fixDATA(self,data_azi): |
|
511 | def fixDATA(self,data_azi): | |
512 | data=data_azi |
|
512 | data=data_azi | |
513 | for i in range(len(data)): |
|
513 | for i in range(len(data)): | |
514 | if numpy.isnan(data[i]): |
|
514 | if numpy.isnan(data[i]): | |
515 | data[i]=data[i-1]+1 |
|
515 | data[i]=data[i-1]+1 | |
516 | return data |
|
516 | return data | |
517 |
|
517 | |||
518 | def replaceNAN(self,data_weather,data_azi,val): |
|
518 | def replaceNAN(self,data_weather,data_azi,val): | |
519 | data= data_azi |
|
519 | data= data_azi | |
520 | data_T= data_weather |
|
520 | data_T= data_weather | |
521 | if data.shape[0]> data_T.shape[0]: |
|
521 | if data.shape[0]> data_T.shape[0]: | |
522 | data_N = numpy.ones( [data.shape[0],data_T.shape[1]]) |
|
522 | data_N = numpy.ones( [data.shape[0],data_T.shape[1]]) | |
523 | c = 0 |
|
523 | c = 0 | |
524 | for i in range(len(data)): |
|
524 | for i in range(len(data)): | |
525 | if numpy.isnan(data[i]): |
|
525 | if numpy.isnan(data[i]): | |
526 | data_N[i,:]=numpy.ones(data_T.shape[1])*numpy.nan |
|
526 | data_N[i,:]=numpy.ones(data_T.shape[1])*numpy.nan | |
527 | else: |
|
527 | else: | |
528 | data_N[i,:]=data_T[c,:] |
|
528 | data_N[i,:]=data_T[c,:] | |
529 | c=c+1 |
|
529 | c=c+1 | |
530 | return data_N |
|
530 | return data_N | |
531 | else: |
|
531 | else: | |
532 | for i in range(len(data)): |
|
532 | for i in range(len(data)): | |
533 | if numpy.isnan(data[i]): |
|
533 | if numpy.isnan(data[i]): | |
534 | data_T[i,:]=numpy.ones(data_T.shape[1])*numpy.nan |
|
534 | data_T[i,:]=numpy.ones(data_T.shape[1])*numpy.nan | |
535 | return data_T |
|
535 | return data_T | |
536 |
|
536 | |||
537 | def const_ploteo(self,data_weather,data_azi,step,res): |
|
537 | def const_ploteo(self,data_weather,data_azi,step,res): | |
538 | if self.ini==0: |
|
538 | if self.ini==0: | |
539 | #------- |
|
539 | #------- | |
540 | n = (360/res)-len(data_azi) |
|
540 | n = (360/res)-len(data_azi) | |
541 | #--------------------- new ------------------------- |
|
541 | #--------------------- new ------------------------- | |
542 | data_azi_new ,data_azi_old= self.globalCheckPED(data_azi) |
|
542 | data_azi_new ,data_azi_old= self.globalCheckPED(data_azi) | |
543 | #------------------------ |
|
543 | #------------------------ | |
544 | start = data_azi_new[-1] + res |
|
544 | start = data_azi_new[-1] + res | |
545 | end = data_azi_new[0] - res |
|
545 | end = data_azi_new[0] - res | |
546 | #------ new |
|
546 | #------ new | |
547 | self.last_data_azi = end |
|
547 | self.last_data_azi = end | |
548 | if start>end: |
|
548 | if start>end: | |
549 | end = end + 360 |
|
549 | end = end + 360 | |
550 | azi_vacia = numpy.linspace(start,end,int(n)) |
|
550 | azi_vacia = numpy.linspace(start,end,int(n)) | |
551 | azi_vacia = numpy.where(azi_vacia>360,azi_vacia-360,azi_vacia) |
|
551 | azi_vacia = numpy.where(azi_vacia>360,azi_vacia-360,azi_vacia) | |
552 | data_azi = numpy.hstack((data_azi_new,azi_vacia)) |
|
552 | data_azi = numpy.hstack((data_azi_new,azi_vacia)) | |
553 | # RADAR |
|
553 | # RADAR | |
554 | val_mean = numpy.mean(data_weather[:,-1]) |
|
554 | val_mean = numpy.mean(data_weather[:,-1]) | |
555 | self.val_mean = val_mean |
|
555 | self.val_mean = val_mean | |
556 | data_weather_cmp = numpy.ones([(360-data_weather.shape[0]),data_weather.shape[1]])*val_mean |
|
556 | data_weather_cmp = numpy.ones([(360-data_weather.shape[0]),data_weather.shape[1]])*val_mean | |
557 | data_weather = self.replaceNAN(data_weather=data_weather,data_azi=data_azi_old,val=self.val_mean) |
|
557 | data_weather = self.replaceNAN(data_weather=data_weather,data_azi=data_azi_old,val=self.val_mean) | |
558 | data_weather = numpy.vstack((data_weather,data_weather_cmp)) |
|
558 | data_weather = numpy.vstack((data_weather,data_weather_cmp)) | |
559 | else: |
|
559 | else: | |
560 | # azimuth |
|
560 | # azimuth | |
561 | flag=0 |
|
561 | flag=0 | |
562 | start_azi = self.res_azi[0] |
|
562 | start_azi = self.res_azi[0] | |
563 | #-----------new------------ |
|
563 | #-----------new------------ | |
564 | data_azi ,data_azi_old= self.globalCheckPED(data_azi) |
|
564 | data_azi ,data_azi_old= self.globalCheckPED(data_azi) | |
565 | data_weather = self.replaceNAN(data_weather=data_weather,data_azi=data_azi_old,val=self.val_mean) |
|
565 | data_weather = self.replaceNAN(data_weather=data_weather,data_azi=data_azi_old,val=self.val_mean) | |
566 | #-------------------------- |
|
566 | #-------------------------- | |
567 | start = data_azi[0] |
|
567 | start = data_azi[0] | |
568 | end = data_azi[-1] |
|
568 | end = data_azi[-1] | |
569 | self.last_data_azi= end |
|
569 | self.last_data_azi= end | |
570 | if start< start_azi: |
|
570 | if start< start_azi: | |
571 | start = start +360 |
|
571 | start = start +360 | |
572 | if end <start_azi: |
|
572 | if end <start_azi: | |
573 | end = end +360 |
|
573 | end = end +360 | |
574 |
|
574 | |||
575 | pos_ini = int((start-start_azi)/res) |
|
575 | pos_ini = int((start-start_azi)/res) | |
576 | len_azi = len(data_azi) |
|
576 | len_azi = len(data_azi) | |
577 | if (360-pos_ini)<len_azi: |
|
577 | if (360-pos_ini)<len_azi: | |
578 | if pos_ini+1==360: |
|
578 | if pos_ini+1==360: | |
579 | pos_ini=0 |
|
579 | pos_ini=0 | |
580 | else: |
|
580 | else: | |
581 | flag=1 |
|
581 | flag=1 | |
582 | dif= 360-pos_ini |
|
582 | dif= 360-pos_ini | |
583 | comp= len_azi-dif |
|
583 | comp= len_azi-dif | |
584 | #----------------- |
|
584 | #----------------- | |
585 | if flag==0: |
|
585 | if flag==0: | |
586 | # AZIMUTH |
|
586 | # AZIMUTH | |
587 | self.res_azi[pos_ini:pos_ini+len_azi] = data_azi |
|
587 | self.res_azi[pos_ini:pos_ini+len_azi] = data_azi | |
588 | # RADAR |
|
588 | # RADAR | |
589 | self.res_weather[pos_ini:pos_ini+len_azi,:] = data_weather |
|
589 | self.res_weather[pos_ini:pos_ini+len_azi,:] = data_weather | |
590 | else: |
|
590 | else: | |
591 | # AZIMUTH |
|
591 | # AZIMUTH | |
592 | self.res_azi[pos_ini:pos_ini+dif] = data_azi[0:dif] |
|
592 | self.res_azi[pos_ini:pos_ini+dif] = data_azi[0:dif] | |
593 | self.res_azi[0:comp] = data_azi[dif:] |
|
593 | self.res_azi[0:comp] = data_azi[dif:] | |
594 | # RADAR |
|
594 | # RADAR | |
595 | self.res_weather[pos_ini:pos_ini+dif,:] = data_weather[0:dif,:] |
|
595 | self.res_weather[pos_ini:pos_ini+dif,:] = data_weather[0:dif,:] | |
596 | self.res_weather[0:comp,:] = data_weather[dif:,:] |
|
596 | self.res_weather[0:comp,:] = data_weather[dif:,:] | |
597 | flag=0 |
|
597 | flag=0 | |
598 | data_azi = self.res_azi |
|
598 | data_azi = self.res_azi | |
599 | data_weather = self.res_weather |
|
599 | data_weather = self.res_weather | |
600 |
|
600 | |||
601 | return data_weather,data_azi |
|
601 | return data_weather,data_azi | |
602 |
|
602 | |||
603 | def plot(self): |
|
603 | def plot(self): | |
604 | thisDatetime = datetime.datetime.utcfromtimestamp(self.data.times[-1]).strftime('%Y-%m-%d %H:%M:%S') |
|
604 | thisDatetime = datetime.datetime.utcfromtimestamp(self.data.times[-1]).strftime('%Y-%m-%d %H:%M:%S') | |
605 | data = self.data[-1] |
|
605 | data = self.data[-1] | |
606 | r = self.data.yrange |
|
606 | r = self.data.yrange | |
607 | delta_height = r[1]-r[0] |
|
607 | delta_height = r[1]-r[0] | |
608 | r_mask = numpy.where(r>=0)[0] |
|
608 | r_mask = numpy.where(r>=0)[0] | |
609 | r = numpy.arange(len(r_mask))*delta_height |
|
609 | r = numpy.arange(len(r_mask))*delta_height | |
610 | self.y = 2*r |
|
610 | self.y = 2*r | |
611 | # RADAR |
|
611 | # RADAR | |
612 | #data_weather = data['weather'] |
|
612 | #data_weather = data['weather'] | |
613 | # PEDESTAL |
|
613 | # PEDESTAL | |
614 | #data_azi = data['azi'] |
|
614 | #data_azi = data['azi'] | |
615 | res = 1 |
|
615 | res = 1 | |
616 | # STEP |
|
616 | # STEP | |
617 | step = (360/(res*data['weather'].shape[0])) |
|
617 | step = (360/(res*data['weather'].shape[0])) | |
618 |
|
618 | |||
619 | self.res_weather, self.res_azi = self.const_ploteo(data_weather=data['weather'][:,r_mask],data_azi=data['azi'],step=step,res=res) |
|
619 | self.res_weather, self.res_azi = self.const_ploteo(data_weather=data['weather'][:,r_mask],data_azi=data['azi'],step=step,res=res) | |
620 | self.res_ele = numpy.mean(data['ele']) |
|
620 | self.res_ele = numpy.mean(data['ele']) | |
621 | ################# PLOTEO ################### |
|
621 | ################# PLOTEO ################### | |
622 | for i,ax in enumerate(self.axes): |
|
622 | for i,ax in enumerate(self.axes): | |
623 | if ax.firsttime: |
|
623 | if ax.firsttime: | |
624 | plt.clf() |
|
624 | plt.clf() | |
625 | cgax, pm = wrl.vis.plot_ppi(self.res_weather,r=r,az=self.res_azi,fig=self.figures[0], proj='cg', vmin=20, vmax=80) |
|
625 | cgax, pm = wrl.vis.plot_ppi(self.res_weather,r=r,az=self.res_azi,fig=self.figures[0], proj='cg', vmin=20, vmax=80) | |
626 | else: |
|
626 | else: | |
627 | plt.clf() |
|
627 | plt.clf() | |
628 | cgax, pm = wrl.vis.plot_ppi(self.res_weather,r=r,az=self.res_azi,fig=self.figures[0], proj='cg', vmin=20, vmax=80) |
|
628 | cgax, pm = wrl.vis.plot_ppi(self.res_weather,r=r,az=self.res_azi,fig=self.figures[0], proj='cg', vmin=20, vmax=80) | |
629 | caax = cgax.parasites[0] |
|
629 | caax = cgax.parasites[0] | |
630 | paax = cgax.parasites[1] |
|
630 | paax = cgax.parasites[1] | |
631 | cbar = plt.gcf().colorbar(pm, pad=0.075) |
|
631 | cbar = plt.gcf().colorbar(pm, pad=0.075) | |
632 | caax.set_xlabel('x_range [km]') |
|
632 | caax.set_xlabel('x_range [km]') | |
633 | caax.set_ylabel('y_range [km]') |
|
633 | caax.set_ylabel('y_range [km]') | |
634 | plt.text(1.0, 1.05, 'Azimuth '+str(thisDatetime)+" Step "+str(self.ini)+ " Elev: "+str(round(self.res_ele,2)), transform=caax.transAxes, va='bottom',ha='right') |
|
634 | plt.text(1.0, 1.05, 'Azimuth '+str(thisDatetime)+" Step "+str(self.ini)+ " Elev: "+str(round(self.res_ele,2)), transform=caax.transAxes, va='bottom',ha='right') | |
635 |
|
635 | |||
636 | self.ini= self.ini+1 |
|
636 | self.ini= self.ini+1 | |
637 |
|
637 | |||
638 |
|
638 | |||
639 | class WeatherRHIPlot(Plot): |
|
639 | class WeatherRHIPlot(Plot): | |
640 | CODE = 'weather' |
|
640 | CODE = 'weather' | |
641 | plot_name = 'weather' |
|
641 | plot_name = 'weather' | |
642 | plot_type = 'rhistyle' |
|
642 | plot_type = 'rhistyle' | |
643 | buffering = False |
|
643 | buffering = False | |
644 | data_ele_tmp = None |
|
644 | data_ele_tmp = None | |
645 |
|
645 | |||
646 | def setup(self): |
|
646 | def setup(self): | |
647 | print("********************") |
|
647 | print("********************") | |
648 | print("********************") |
|
648 | print("********************") | |
649 | print("********************") |
|
649 | print("********************") | |
650 | print("SETUP WEATHER PLOT") |
|
650 | print("SETUP WEATHER PLOT") | |
651 | self.ncols = 1 |
|
651 | self.ncols = 1 | |
652 | self.nrows = 1 |
|
652 | self.nrows = 1 | |
653 | self.nplots= 1 |
|
653 | self.nplots= 1 | |
654 | self.ylabel= 'Range [Km]' |
|
654 | self.ylabel= 'Range [Km]' | |
655 | self.titles= ['Weather'] |
|
655 | self.titles= ['Weather'] | |
656 | if self.channels is not None: |
|
656 | if self.channels is not None: | |
657 | self.nplots = len(self.channels) |
|
657 | self.nplots = len(self.channels) | |
658 | self.nrows = len(self.channels) |
|
658 | self.nrows = len(self.channels) | |
659 | else: |
|
659 | else: | |
660 | self.nplots = self.data.shape(self.CODE)[0] |
|
660 | self.nplots = self.data.shape(self.CODE)[0] | |
661 | self.nrows = self.nplots |
|
661 | self.nrows = self.nplots | |
662 | self.channels = list(range(self.nplots)) |
|
662 | self.channels = list(range(self.nplots)) | |
663 | print("channels",self.channels) |
|
663 | print("channels",self.channels) | |
664 | print("que saldra", self.data.shape(self.CODE)[0]) |
|
664 | print("que saldra", self.data.shape(self.CODE)[0]) | |
665 | self.titles = ['{} Channel {}'.format(self.CODE.upper(), x) for x in range(self.nrows)] |
|
665 | self.titles = ['{} Channel {}'.format(self.CODE.upper(), x) for x in range(self.nrows)] | |
666 | print("self.titles",self.titles) |
|
666 | print("self.titles",self.titles) | |
667 | self.colorbar=False |
|
667 | self.colorbar=False | |
668 | self.width =8 |
|
668 | self.width =8 | |
669 | self.height =8 |
|
669 | self.height =8 | |
670 | self.ini =0 |
|
670 | self.ini =0 | |
671 | self.len_azi =0 |
|
671 | self.len_azi =0 | |
672 | self.buffer_ini = None |
|
672 | self.buffer_ini = None | |
673 | self.buffer_ele = None |
|
673 | self.buffer_ele = None | |
674 | self.plots_adjust.update({'wspace': 0.4, 'hspace':0.4, 'left': 0.1, 'right': 0.9, 'bottom': 0.08}) |
|
674 | self.plots_adjust.update({'wspace': 0.4, 'hspace':0.4, 'left': 0.1, 'right': 0.9, 'bottom': 0.08}) | |
675 | self.flag =0 |
|
675 | self.flag =0 | |
676 | self.indicador= 0 |
|
676 | self.indicador= 0 | |
677 | self.last_data_ele = None |
|
677 | self.last_data_ele = None | |
678 | self.val_mean = None |
|
678 | self.val_mean = None | |
679 |
|
679 | |||
680 | def update(self, dataOut): |
|
680 | def update(self, dataOut): | |
681 |
|
681 | |||
682 | data = {} |
|
682 | data = {} | |
683 | meta = {} |
|
683 | meta = {} | |
684 | if hasattr(dataOut, 'dataPP_POWER'): |
|
684 | if hasattr(dataOut, 'dataPP_POWER'): | |
685 | factor = 1 |
|
685 | factor = 1 | |
686 | if hasattr(dataOut, 'nFFTPoints'): |
|
686 | if hasattr(dataOut, 'nFFTPoints'): | |
687 | factor = dataOut.normFactor |
|
687 | factor = dataOut.normFactor | |
688 | print("dataOut",dataOut.data_360.shape) |
|
688 | print("dataOut",dataOut.data_360.shape) | |
689 | # |
|
689 | # | |
690 | data['weather'] = 10*numpy.log10(dataOut.data_360/(factor)) |
|
690 | data['weather'] = 10*numpy.log10(dataOut.data_360/(factor)) | |
691 | # |
|
691 | # | |
692 | #data['weather'] = 10*numpy.log10(dataOut.data_360[1]/(factor)) |
|
692 | #data['weather'] = 10*numpy.log10(dataOut.data_360[1]/(factor)) | |
693 | data['azi'] = dataOut.data_azi |
|
693 | data['azi'] = dataOut.data_azi | |
694 | data['ele'] = dataOut.data_ele |
|
694 | data['ele'] = dataOut.data_ele | |
695 | #print("UPDATE") |
|
695 | #print("UPDATE") | |
696 | #print("data[weather]",data['weather'].shape) |
|
696 | #print("data[weather]",data['weather'].shape) | |
697 | #print("data[azi]",data['azi']) |
|
697 | #print("data[azi]",data['azi']) | |
698 | return data, meta |
|
698 | return data, meta | |
699 |
|
699 | |||
700 | def get2List(self,angulos): |
|
700 | def get2List(self,angulos): | |
701 | list1=[] |
|
701 | list1=[] | |
702 | list2=[] |
|
702 | list2=[] | |
703 | for i in reversed(range(len(angulos))): |
|
703 | for i in reversed(range(len(angulos))): | |
704 | if not i==0:#el caso de i=0 evalula el primero de la lista con el ultimo y no es relevante |
|
704 | if not i==0:#el caso de i=0 evalula el primero de la lista con el ultimo y no es relevante | |
705 | diff_ = angulos[i]-angulos[i-1] |
|
705 | diff_ = angulos[i]-angulos[i-1] | |
706 | if abs(diff_) >1.5: |
|
706 | if abs(diff_) >1.5: | |
707 | list1.append(i-1) |
|
707 | list1.append(i-1) | |
708 | list2.append(diff_) |
|
708 | list2.append(diff_) | |
709 | return list(reversed(list1)),list(reversed(list2)) |
|
709 | return list(reversed(list1)),list(reversed(list2)) | |
710 |
|
710 | |||
711 | def fixData90(self,list_,ang_): |
|
711 | def fixData90(self,list_,ang_): | |
712 | if list_[0]==-1: |
|
712 | if list_[0]==-1: | |
713 | vec = numpy.where(ang_<ang_[0]) |
|
713 | vec = numpy.where(ang_<ang_[0]) | |
714 | ang_[vec] = ang_[vec]+90 |
|
714 | ang_[vec] = ang_[vec]+90 | |
715 | return ang_ |
|
715 | return ang_ | |
716 | return ang_ |
|
716 | return ang_ | |
717 |
|
717 | |||
718 | def fixData90HL(self,angulos): |
|
718 | def fixData90HL(self,angulos): | |
719 | vec = numpy.where(angulos>=90) |
|
719 | vec = numpy.where(angulos>=90) | |
720 | angulos[vec]=angulos[vec]-90 |
|
720 | angulos[vec]=angulos[vec]-90 | |
721 | return angulos |
|
721 | return angulos | |
722 |
|
722 | |||
723 |
|
723 | |||
724 | def search_pos(self,pos,list_): |
|
724 | def search_pos(self,pos,list_): | |
725 | for i in range(len(list_)): |
|
725 | for i in range(len(list_)): | |
726 | if pos == list_[i]: |
|
726 | if pos == list_[i]: | |
727 | return True,i |
|
727 | return True,i | |
728 | i=None |
|
728 | i=None | |
729 | return False,i |
|
729 | return False,i | |
730 |
|
730 | |||
731 | def fixDataComp(self,ang_,list1_,list2_,tipo_case): |
|
731 | def fixDataComp(self,ang_,list1_,list2_,tipo_case): | |
732 | size = len(ang_) |
|
732 | size = len(ang_) | |
733 | size2 = 0 |
|
733 | size2 = 0 | |
734 | for i in range(len(list2_)): |
|
734 | for i in range(len(list2_)): | |
735 | size2=size2+round(abs(list2_[i]))-1 |
|
735 | size2=size2+round(abs(list2_[i]))-1 | |
736 | new_size= size+size2 |
|
736 | new_size= size+size2 | |
737 | ang_new = numpy.zeros(new_size) |
|
737 | ang_new = numpy.zeros(new_size) | |
738 | ang_new2 = numpy.zeros(new_size) |
|
738 | ang_new2 = numpy.zeros(new_size) | |
739 |
|
739 | |||
740 | tmp = 0 |
|
740 | tmp = 0 | |
741 | c = 0 |
|
741 | c = 0 | |
742 | for i in range(len(ang_)): |
|
742 | for i in range(len(ang_)): | |
743 | ang_new[tmp +c] = ang_[i] |
|
743 | ang_new[tmp +c] = ang_[i] | |
744 | ang_new2[tmp+c] = ang_[i] |
|
744 | ang_new2[tmp+c] = ang_[i] | |
745 | condition , value = self.search_pos(i,list1_) |
|
745 | condition , value = self.search_pos(i,list1_) | |
746 | if condition: |
|
746 | if condition: | |
747 | pos = tmp + c + 1 |
|
747 | pos = tmp + c + 1 | |
748 | for k in range(round(abs(list2_[value]))-1): |
|
748 | for k in range(round(abs(list2_[value]))-1): | |
749 | if tipo_case==0 or tipo_case==3:#subida |
|
749 | if tipo_case==0 or tipo_case==3:#subida | |
750 | ang_new[pos+k] = ang_new[pos+k-1]+1 |
|
750 | ang_new[pos+k] = ang_new[pos+k-1]+1 | |
751 | ang_new2[pos+k] = numpy.nan |
|
751 | ang_new2[pos+k] = numpy.nan | |
752 | elif tipo_case==1 or tipo_case==2:#bajada |
|
752 | elif tipo_case==1 or tipo_case==2:#bajada | |
753 | ang_new[pos+k] = ang_new[pos+k-1]-1 |
|
753 | ang_new[pos+k] = ang_new[pos+k-1]-1 | |
754 | ang_new2[pos+k] = numpy.nan |
|
754 | ang_new2[pos+k] = numpy.nan | |
755 |
|
755 | |||
756 | tmp = pos +k |
|
756 | tmp = pos +k | |
757 | c = 0 |
|
757 | c = 0 | |
758 | c=c+1 |
|
758 | c=c+1 | |
759 | return ang_new,ang_new2 |
|
759 | return ang_new,ang_new2 | |
760 |
|
760 | |||
761 | def globalCheckPED(self,angulos,tipo_case): |
|
761 | def globalCheckPED(self,angulos,tipo_case): | |
762 | l1,l2 = self.get2List(angulos) |
|
762 | l1,l2 = self.get2List(angulos) | |
763 | ##print("l1",l1) |
|
763 | ##print("l1",l1) | |
764 | ##print("l2",l2) |
|
764 | ##print("l2",l2) | |
765 | if len(l1)>0: |
|
765 | if len(l1)>0: | |
766 | #angulos2 = self.fixData90(list_=l1,ang_=angulos) |
|
766 | #angulos2 = self.fixData90(list_=l1,ang_=angulos) | |
767 | #l1,l2 = self.get2List(angulos2) |
|
767 | #l1,l2 = self.get2List(angulos2) | |
768 | ang1_,ang2_ = self.fixDataComp(ang_=angulos,list1_=l1,list2_=l2,tipo_case=tipo_case) |
|
768 | ang1_,ang2_ = self.fixDataComp(ang_=angulos,list1_=l1,list2_=l2,tipo_case=tipo_case) | |
769 | #ang1_ = self.fixData90HL(ang1_) |
|
769 | #ang1_ = self.fixData90HL(ang1_) | |
770 | #ang2_ = self.fixData90HL(ang2_) |
|
770 | #ang2_ = self.fixData90HL(ang2_) | |
771 | else: |
|
771 | else: | |
772 | ang1_= angulos |
|
772 | ang1_= angulos | |
773 | ang2_= angulos |
|
773 | ang2_= angulos | |
774 | return ang1_,ang2_ |
|
774 | return ang1_,ang2_ | |
775 |
|
775 | |||
776 |
|
776 | |||
777 | def replaceNAN(self,data_weather,data_ele,val): |
|
777 | def replaceNAN(self,data_weather,data_ele,val): | |
778 | data= data_ele |
|
778 | data= data_ele | |
779 | data_T= data_weather |
|
779 | data_T= data_weather | |
780 | if data.shape[0]> data_T.shape[0]: |
|
780 | if data.shape[0]> data_T.shape[0]: | |
781 | data_N = numpy.ones( [data.shape[0],data_T.shape[1]]) |
|
781 | data_N = numpy.ones( [data.shape[0],data_T.shape[1]]) | |
782 | c = 0 |
|
782 | c = 0 | |
783 | for i in range(len(data)): |
|
783 | for i in range(len(data)): | |
784 | if numpy.isnan(data[i]): |
|
784 | if numpy.isnan(data[i]): | |
785 | data_N[i,:]=numpy.ones(data_T.shape[1])*numpy.nan |
|
785 | data_N[i,:]=numpy.ones(data_T.shape[1])*numpy.nan | |
786 | else: |
|
786 | else: | |
787 | data_N[i,:]=data_T[c,:] |
|
787 | data_N[i,:]=data_T[c,:] | |
788 | c=c+1 |
|
788 | c=c+1 | |
789 | return data_N |
|
789 | return data_N | |
790 | else: |
|
790 | else: | |
791 | for i in range(len(data)): |
|
791 | for i in range(len(data)): | |
792 | if numpy.isnan(data[i]): |
|
792 | if numpy.isnan(data[i]): | |
793 | data_T[i,:]=numpy.ones(data_T.shape[1])*numpy.nan |
|
793 | data_T[i,:]=numpy.ones(data_T.shape[1])*numpy.nan | |
794 | return data_T |
|
794 | return data_T | |
795 |
|
795 | |||
796 | def check_case(self,data_ele,ang_max,ang_min): |
|
796 | def check_case(self,data_ele,ang_max,ang_min): | |
797 | start = data_ele[0] |
|
797 | start = data_ele[0] | |
798 | end = data_ele[-1] |
|
798 | end = data_ele[-1] | |
799 | number = (end-start) |
|
799 | number = (end-start) | |
800 | len_ang=len(data_ele) |
|
800 | len_ang=len(data_ele) | |
801 | print("start",start) |
|
801 | print("start",start) | |
802 | print("end",end) |
|
802 | print("end",end) | |
803 | print("number",number) |
|
803 | print("number",number) | |
804 |
|
804 | |||
805 | print("len_ang",len_ang) |
|
805 | print("len_ang",len_ang) | |
806 |
|
806 | |||
807 | #exit(1) |
|
807 | #exit(1) | |
808 |
|
808 | |||
809 | if start<end and (round(abs(number)+1)>=len_ang or (numpy.argmin(data_ele)==0)):#caso subida |
|
809 | if start<end and (round(abs(number)+1)>=len_ang or (numpy.argmin(data_ele)==0)):#caso subida | |
810 | return 0 |
|
810 | return 0 | |
811 | #elif start>end and (round(abs(number)+1)>=len_ang or(numpy.argmax(data_ele)==0)):#caso bajada |
|
811 | #elif start>end and (round(abs(number)+1)>=len_ang or(numpy.argmax(data_ele)==0)):#caso bajada | |
812 | # return 1 |
|
812 | # return 1 | |
813 | elif round(abs(number)+1)>=len_ang and (start>end or(numpy.argmax(data_ele)==0)):#caso bajada |
|
813 | elif round(abs(number)+1)>=len_ang and (start>end or(numpy.argmax(data_ele)==0)):#caso bajada | |
814 | return 1 |
|
814 | return 1 | |
815 | elif round(abs(number)+1)<len_ang and data_ele[-2]>data_ele[-1]:# caso BAJADA CAMBIO ANG MAX |
|
815 | elif round(abs(number)+1)<len_ang and data_ele[-2]>data_ele[-1]:# caso BAJADA CAMBIO ANG MAX | |
816 | return 2 |
|
816 | return 2 | |
817 | elif round(abs(number)+1)<len_ang and data_ele[-2]<data_ele[-1] :# caso SUBIDA CAMBIO ANG MIN |
|
817 | elif round(abs(number)+1)<len_ang and data_ele[-2]<data_ele[-1] :# caso SUBIDA CAMBIO ANG MIN | |
818 | return 3 |
|
818 | return 3 | |
819 |
|
819 | |||
820 |
|
820 | |||
821 | def const_ploteo(self,val_ch,data_weather,data_ele,step,res,ang_max,ang_min): |
|
821 | def const_ploteo(self,val_ch,data_weather,data_ele,step,res,ang_max,ang_min): | |
822 | ang_max= ang_max |
|
822 | ang_max= ang_max | |
823 | ang_min= ang_min |
|
823 | ang_min= ang_min | |
824 | data_weather=data_weather |
|
824 | data_weather=data_weather | |
825 | val_ch=val_ch |
|
825 | val_ch=val_ch | |
826 | ##print("*********************DATA WEATHER**************************************") |
|
826 | ##print("*********************DATA WEATHER**************************************") | |
827 | ##print(data_weather) |
|
827 | ##print(data_weather) | |
828 | if self.ini==0: |
|
828 | if self.ini==0: | |
829 | ''' |
|
829 | ''' | |
830 | print("**********************************************") |
|
830 | print("**********************************************") | |
831 | print("**********************************************") |
|
831 | print("**********************************************") | |
832 | print("***************ini**************") |
|
832 | print("***************ini**************") | |
833 | print("**********************************************") |
|
833 | print("**********************************************") | |
834 | print("**********************************************") |
|
834 | print("**********************************************") | |
835 | ''' |
|
835 | ''' | |
836 | #print("data_ele",data_ele) |
|
836 | #print("data_ele",data_ele) | |
837 | #---------------------------------------------------------- |
|
837 | #---------------------------------------------------------- | |
838 | tipo_case = self.check_case(data_ele,ang_max,ang_min) |
|
838 | tipo_case = self.check_case(data_ele,ang_max,ang_min) | |
839 | print("check_case",tipo_case) |
|
839 | print("check_case",tipo_case) | |
840 | #exit(1) |
|
840 | #exit(1) | |
841 | #--------------------- new ------------------------- |
|
841 | #--------------------- new ------------------------- | |
842 | data_ele_new ,data_ele_old= self.globalCheckPED(data_ele,tipo_case) |
|
842 | data_ele_new ,data_ele_old= self.globalCheckPED(data_ele,tipo_case) | |
843 |
|
843 | |||
844 | #-------------------------CAMBIOS RHI--------------------------------- |
|
844 | #-------------------------CAMBIOS RHI--------------------------------- | |
845 | start= ang_min |
|
845 | start= ang_min | |
846 | end = ang_max |
|
846 | end = ang_max | |
847 | n= (ang_max-ang_min)/res |
|
847 | n= (ang_max-ang_min)/res | |
848 | #------ new |
|
848 | #------ new | |
849 | self.start_data_ele = data_ele_new[0] |
|
849 | self.start_data_ele = data_ele_new[0] | |
850 | self.end_data_ele = data_ele_new[-1] |
|
850 | self.end_data_ele = data_ele_new[-1] | |
851 | if tipo_case==0 or tipo_case==3: # SUBIDA |
|
851 | if tipo_case==0 or tipo_case==3: # SUBIDA | |
852 | n1= round(self.start_data_ele)- start |
|
852 | n1= round(self.start_data_ele)- start | |
853 | n2= end - round(self.end_data_ele) |
|
853 | n2= end - round(self.end_data_ele) | |
854 | print(self.start_data_ele) |
|
854 | print(self.start_data_ele) | |
855 | print(self.end_data_ele) |
|
855 | print(self.end_data_ele) | |
856 | if n1>0: |
|
856 | if n1>0: | |
857 | ele1= numpy.linspace(ang_min+1,self.start_data_ele-1,n1) |
|
857 | ele1= numpy.linspace(ang_min+1,self.start_data_ele-1,n1) | |
858 | ele1_nan= numpy.ones(n1)*numpy.nan |
|
858 | ele1_nan= numpy.ones(n1)*numpy.nan | |
859 | data_ele = numpy.hstack((ele1,data_ele_new)) |
|
859 | data_ele = numpy.hstack((ele1,data_ele_new)) | |
860 | print("ele1_nan",ele1_nan.shape) |
|
860 | print("ele1_nan",ele1_nan.shape) | |
861 | print("data_ele_old",data_ele_old.shape) |
|
861 | print("data_ele_old",data_ele_old.shape) | |
862 | data_ele_old = numpy.hstack((ele1_nan,data_ele_old)) |
|
862 | data_ele_old = numpy.hstack((ele1_nan,data_ele_old)) | |
863 | if n2>0: |
|
863 | if n2>0: | |
864 | ele2= numpy.linspace(self.end_data_ele+1,end,n2) |
|
864 | ele2= numpy.linspace(self.end_data_ele+1,end,n2) | |
865 | ele2_nan= numpy.ones(n2)*numpy.nan |
|
865 | ele2_nan= numpy.ones(n2)*numpy.nan | |
866 | data_ele = numpy.hstack((data_ele,ele2)) |
|
866 | data_ele = numpy.hstack((data_ele,ele2)) | |
867 | print("ele2_nan",ele2_nan.shape) |
|
867 | print("ele2_nan",ele2_nan.shape) | |
868 | print("data_ele_old",data_ele_old.shape) |
|
868 | print("data_ele_old",data_ele_old.shape) | |
869 | data_ele_old = numpy.hstack((data_ele_old,ele2_nan)) |
|
869 | data_ele_old = numpy.hstack((data_ele_old,ele2_nan)) | |
870 |
|
870 | |||
871 | if tipo_case==1 or tipo_case==2: # BAJADA |
|
871 | if tipo_case==1 or tipo_case==2: # BAJADA | |
872 | data_ele_new = data_ele_new[::-1] # reversa |
|
872 | data_ele_new = data_ele_new[::-1] # reversa | |
873 | data_ele_old = data_ele_old[::-1]# reversa |
|
873 | data_ele_old = data_ele_old[::-1]# reversa | |
874 | data_weather = data_weather[::-1,:]# reversa |
|
874 | data_weather = data_weather[::-1,:]# reversa | |
875 | vec= numpy.where(data_ele_new<ang_max) |
|
875 | vec= numpy.where(data_ele_new<ang_max) | |
876 | data_ele_new = data_ele_new[vec] |
|
876 | data_ele_new = data_ele_new[vec] | |
877 | data_ele_old = data_ele_old[vec] |
|
877 | data_ele_old = data_ele_old[vec] | |
878 | data_weather = data_weather[vec[0]] |
|
878 | data_weather = data_weather[vec[0]] | |
879 | vec2= numpy.where(0<data_ele_new) |
|
879 | vec2= numpy.where(0<data_ele_new) | |
880 | data_ele_new = data_ele_new[vec2] |
|
880 | data_ele_new = data_ele_new[vec2] | |
881 | data_ele_old = data_ele_old[vec2] |
|
881 | data_ele_old = data_ele_old[vec2] | |
882 | data_weather = data_weather[vec2[0]] |
|
882 | data_weather = data_weather[vec2[0]] | |
883 | self.start_data_ele = data_ele_new[0] |
|
883 | self.start_data_ele = data_ele_new[0] | |
884 | self.end_data_ele = data_ele_new[-1] |
|
884 | self.end_data_ele = data_ele_new[-1] | |
885 |
|
885 | |||
886 | n1= round(self.start_data_ele)- start |
|
886 | n1= round(self.start_data_ele)- start | |
887 | n2= end - round(self.end_data_ele)-1 |
|
887 | n2= end - round(self.end_data_ele)-1 | |
888 | print(self.start_data_ele) |
|
888 | print(self.start_data_ele) | |
889 | print(self.end_data_ele) |
|
889 | print(self.end_data_ele) | |
890 | if n1>0: |
|
890 | if n1>0: | |
891 | ele1= numpy.linspace(ang_min+1,self.start_data_ele-1,n1) |
|
891 | ele1= numpy.linspace(ang_min+1,self.start_data_ele-1,n1) | |
892 | ele1_nan= numpy.ones(n1)*numpy.nan |
|
892 | ele1_nan= numpy.ones(n1)*numpy.nan | |
893 | data_ele = numpy.hstack((ele1,data_ele_new)) |
|
893 | data_ele = numpy.hstack((ele1,data_ele_new)) | |
894 | data_ele_old = numpy.hstack((ele1_nan,data_ele_old)) |
|
894 | data_ele_old = numpy.hstack((ele1_nan,data_ele_old)) | |
895 | if n2>0: |
|
895 | if n2>0: | |
896 | ele2= numpy.linspace(self.end_data_ele+1,end,n2) |
|
896 | ele2= numpy.linspace(self.end_data_ele+1,end,n2) | |
897 | ele2_nan= numpy.ones(n2)*numpy.nan |
|
897 | ele2_nan= numpy.ones(n2)*numpy.nan | |
898 | data_ele = numpy.hstack((data_ele,ele2)) |
|
898 | data_ele = numpy.hstack((data_ele,ele2)) | |
899 | data_ele_old = numpy.hstack((data_ele_old,ele2_nan)) |
|
899 | data_ele_old = numpy.hstack((data_ele_old,ele2_nan)) | |
900 | # RADAR |
|
900 | # RADAR | |
901 | # NOTA data_ele y data_weather es la variable que retorna |
|
901 | # NOTA data_ele y data_weather es la variable que retorna | |
902 | val_mean = numpy.mean(data_weather[:,-1]) |
|
902 | val_mean = numpy.mean(data_weather[:,-1]) | |
903 | self.val_mean = val_mean |
|
903 | self.val_mean = val_mean | |
904 | data_weather = self.replaceNAN(data_weather=data_weather,data_ele=data_ele_old,val=self.val_mean) |
|
904 | data_weather = self.replaceNAN(data_weather=data_weather,data_ele=data_ele_old,val=self.val_mean) | |
905 | self.data_ele_tmp[val_ch]= data_ele_old |
|
905 | self.data_ele_tmp[val_ch]= data_ele_old | |
906 | else: |
|
906 | else: | |
907 | #print("**********************************************") |
|
907 | #print("**********************************************") | |
908 | #print("****************VARIABLE**********************") |
|
908 | #print("****************VARIABLE**********************") | |
909 | #-------------------------CAMBIOS RHI--------------------------------- |
|
909 | #-------------------------CAMBIOS RHI--------------------------------- | |
910 | #--------------------------------------------------------------------- |
|
910 | #--------------------------------------------------------------------- | |
911 | ##print("INPUT data_ele",data_ele) |
|
911 | ##print("INPUT data_ele",data_ele) | |
912 | flag=0 |
|
912 | flag=0 | |
913 | start_ele = self.res_ele[0] |
|
913 | start_ele = self.res_ele[0] | |
914 | tipo_case = self.check_case(data_ele,ang_max,ang_min) |
|
914 | tipo_case = self.check_case(data_ele,ang_max,ang_min) | |
915 | #print("TIPO DE DATA",tipo_case) |
|
915 | #print("TIPO DE DATA",tipo_case) | |
916 | #-----------new------------ |
|
916 | #-----------new------------ | |
917 | data_ele ,data_ele_old = self.globalCheckPED(data_ele,tipo_case) |
|
917 | data_ele ,data_ele_old = self.globalCheckPED(data_ele,tipo_case) | |
918 | data_weather = self.replaceNAN(data_weather=data_weather,data_ele=data_ele_old,val=self.val_mean) |
|
918 | data_weather = self.replaceNAN(data_weather=data_weather,data_ele=data_ele_old,val=self.val_mean) | |
919 |
|
919 | |||
920 | #-------------------------------NEW RHI ITERATIVO------------------------- |
|
920 | #-------------------------------NEW RHI ITERATIVO------------------------- | |
921 |
|
921 | |||
922 | if tipo_case==0 : # SUBIDA |
|
922 | if tipo_case==0 : # SUBIDA | |
923 | vec = numpy.where(data_ele<ang_max) |
|
923 | vec = numpy.where(data_ele<ang_max) | |
924 | data_ele = data_ele[vec] |
|
924 | data_ele = data_ele[vec] | |
925 | data_ele_old = data_ele_old[vec] |
|
925 | data_ele_old = data_ele_old[vec] | |
926 | data_weather = data_weather[vec[0]] |
|
926 | data_weather = data_weather[vec[0]] | |
927 |
|
927 | |||
928 | vec2 = numpy.where(0<data_ele) |
|
928 | vec2 = numpy.where(0<data_ele) | |
929 | data_ele= data_ele[vec2] |
|
929 | data_ele= data_ele[vec2] | |
930 | data_ele_old= data_ele_old[vec2] |
|
930 | data_ele_old= data_ele_old[vec2] | |
931 | ##print(data_ele_new) |
|
931 | ##print(data_ele_new) | |
932 | data_weather= data_weather[vec2[0]] |
|
932 | data_weather= data_weather[vec2[0]] | |
933 |
|
933 | |||
934 | new_i_ele = int(round(data_ele[0])) |
|
934 | new_i_ele = int(round(data_ele[0])) | |
935 | new_f_ele = int(round(data_ele[-1])) |
|
935 | new_f_ele = int(round(data_ele[-1])) | |
936 | #print(new_i_ele) |
|
936 | #print(new_i_ele) | |
937 | #print(new_f_ele) |
|
937 | #print(new_f_ele) | |
938 | #print(data_ele,len(data_ele)) |
|
938 | #print(data_ele,len(data_ele)) | |
939 | #print(data_ele_old,len(data_ele_old)) |
|
939 | #print(data_ele_old,len(data_ele_old)) | |
940 | if new_i_ele< 2: |
|
940 | if new_i_ele< 2: | |
941 | self.data_ele_tmp[val_ch] = numpy.ones(ang_max-ang_min)*numpy.nan |
|
941 | self.data_ele_tmp[val_ch] = numpy.ones(ang_max-ang_min)*numpy.nan | |
942 | self.res_weather[val_ch] = self.replaceNAN(data_weather=self.res_weather[val_ch],data_ele=self.data_ele_tmp[val_ch],val=self.val_mean) |
|
942 | self.res_weather[val_ch] = self.replaceNAN(data_weather=self.res_weather[val_ch],data_ele=self.data_ele_tmp[val_ch],val=self.val_mean) | |
943 | self.data_ele_tmp[val_ch][new_i_ele:new_i_ele+len(data_ele)]=data_ele_old |
|
943 | self.data_ele_tmp[val_ch][new_i_ele:new_i_ele+len(data_ele)]=data_ele_old | |
944 | self.res_ele[new_i_ele:new_i_ele+len(data_ele)]= data_ele |
|
944 | self.res_ele[new_i_ele:new_i_ele+len(data_ele)]= data_ele | |
945 | self.res_weather[val_ch][new_i_ele:new_i_ele+len(data_ele),:]= data_weather |
|
945 | self.res_weather[val_ch][new_i_ele:new_i_ele+len(data_ele),:]= data_weather | |
946 | data_ele = self.res_ele |
|
946 | data_ele = self.res_ele | |
947 | data_weather = self.res_weather[val_ch] |
|
947 | data_weather = self.res_weather[val_ch] | |
948 |
|
948 | |||
949 | elif tipo_case==1 : #BAJADA |
|
949 | elif tipo_case==1 : #BAJADA | |
950 | data_ele = data_ele[::-1] # reversa |
|
950 | data_ele = data_ele[::-1] # reversa | |
951 | data_ele_old = data_ele_old[::-1]# reversa |
|
951 | data_ele_old = data_ele_old[::-1]# reversa | |
952 | data_weather = data_weather[::-1,:]# reversa |
|
952 | data_weather = data_weather[::-1,:]# reversa | |
953 | vec= numpy.where(data_ele<ang_max) |
|
953 | vec= numpy.where(data_ele<ang_max) | |
954 | data_ele = data_ele[vec] |
|
954 | data_ele = data_ele[vec] | |
955 | data_ele_old = data_ele_old[vec] |
|
955 | data_ele_old = data_ele_old[vec] | |
956 | data_weather = data_weather[vec[0]] |
|
956 | data_weather = data_weather[vec[0]] | |
957 | vec2= numpy.where(0<data_ele) |
|
957 | vec2= numpy.where(0<data_ele) | |
958 | data_ele = data_ele[vec2] |
|
958 | data_ele = data_ele[vec2] | |
959 | data_ele_old = data_ele_old[vec2] |
|
959 | data_ele_old = data_ele_old[vec2] | |
960 | data_weather = data_weather[vec2[0]] |
|
960 | data_weather = data_weather[vec2[0]] | |
961 |
|
961 | |||
962 |
|
962 | |||
963 | new_i_ele = int(round(data_ele[0])) |
|
963 | new_i_ele = int(round(data_ele[0])) | |
964 | new_f_ele = int(round(data_ele[-1])) |
|
964 | new_f_ele = int(round(data_ele[-1])) | |
965 | #print(data_ele) |
|
965 | #print(data_ele) | |
966 | #print(ang_max) |
|
966 | #print(ang_max) | |
967 | #print(data_ele_old) |
|
967 | #print(data_ele_old) | |
968 | if new_i_ele <= 1: |
|
968 | if new_i_ele <= 1: | |
969 | new_i_ele = 1 |
|
969 | new_i_ele = 1 | |
970 | if round(data_ele[-1])>=ang_max-1: |
|
970 | if round(data_ele[-1])>=ang_max-1: | |
971 | self.data_ele_tmp[val_ch] = numpy.ones(ang_max-ang_min)*numpy.nan |
|
971 | self.data_ele_tmp[val_ch] = numpy.ones(ang_max-ang_min)*numpy.nan | |
972 | self.res_weather[val_ch] = self.replaceNAN(data_weather=self.res_weather[val_ch],data_ele=self.data_ele_tmp[val_ch],val=self.val_mean) |
|
972 | self.res_weather[val_ch] = self.replaceNAN(data_weather=self.res_weather[val_ch],data_ele=self.data_ele_tmp[val_ch],val=self.val_mean) | |
973 | self.data_ele_tmp[val_ch][new_i_ele-1:new_i_ele+len(data_ele)-1]=data_ele_old |
|
973 | self.data_ele_tmp[val_ch][new_i_ele-1:new_i_ele+len(data_ele)-1]=data_ele_old | |
974 | self.res_ele[new_i_ele-1:new_i_ele+len(data_ele)-1]= data_ele |
|
974 | self.res_ele[new_i_ele-1:new_i_ele+len(data_ele)-1]= data_ele | |
975 | self.res_weather[val_ch][new_i_ele-1:new_i_ele+len(data_ele)-1,:]= data_weather |
|
975 | self.res_weather[val_ch][new_i_ele-1:new_i_ele+len(data_ele)-1,:]= data_weather | |
976 | data_ele = self.res_ele |
|
976 | data_ele = self.res_ele | |
977 | data_weather = self.res_weather[val_ch] |
|
977 | data_weather = self.res_weather[val_ch] | |
978 |
|
978 | |||
979 | elif tipo_case==2: #bajada |
|
979 | elif tipo_case==2: #bajada | |
980 | vec = numpy.where(data_ele<ang_max) |
|
980 | vec = numpy.where(data_ele<ang_max) | |
981 | data_ele = data_ele[vec] |
|
981 | data_ele = data_ele[vec] | |
982 | data_weather= data_weather[vec[0]] |
|
982 | data_weather= data_weather[vec[0]] | |
983 |
|
983 | |||
984 | len_vec = len(vec) |
|
984 | len_vec = len(vec) | |
985 | data_ele_new = data_ele[::-1] # reversa |
|
985 | data_ele_new = data_ele[::-1] # reversa | |
986 | data_weather = data_weather[::-1,:] |
|
986 | data_weather = data_weather[::-1,:] | |
987 | new_i_ele = int(data_ele_new[0]) |
|
987 | new_i_ele = int(data_ele_new[0]) | |
988 | new_f_ele = int(data_ele_new[-1]) |
|
988 | new_f_ele = int(data_ele_new[-1]) | |
989 |
|
989 | |||
990 | n1= new_i_ele- ang_min |
|
990 | n1= new_i_ele- ang_min | |
991 | n2= ang_max - new_f_ele-1 |
|
991 | n2= ang_max - new_f_ele-1 | |
992 | if n1>0: |
|
992 | if n1>0: | |
993 | ele1= numpy.linspace(ang_min+1,new_i_ele-1,n1) |
|
993 | ele1= numpy.linspace(ang_min+1,new_i_ele-1,n1) | |
994 | ele1_nan= numpy.ones(n1)*numpy.nan |
|
994 | ele1_nan= numpy.ones(n1)*numpy.nan | |
995 | data_ele = numpy.hstack((ele1,data_ele_new)) |
|
995 | data_ele = numpy.hstack((ele1,data_ele_new)) | |
996 | data_ele_old = numpy.hstack((ele1_nan,data_ele_new)) |
|
996 | data_ele_old = numpy.hstack((ele1_nan,data_ele_new)) | |
997 | if n2>0: |
|
997 | if n2>0: | |
998 | ele2= numpy.linspace(new_f_ele+1,ang_max,n2) |
|
998 | ele2= numpy.linspace(new_f_ele+1,ang_max,n2) | |
999 | ele2_nan= numpy.ones(n2)*numpy.nan |
|
999 | ele2_nan= numpy.ones(n2)*numpy.nan | |
1000 | data_ele = numpy.hstack((data_ele,ele2)) |
|
1000 | data_ele = numpy.hstack((data_ele,ele2)) | |
1001 | data_ele_old = numpy.hstack((data_ele_old,ele2_nan)) |
|
1001 | data_ele_old = numpy.hstack((data_ele_old,ele2_nan)) | |
1002 |
|
1002 | |||
1003 | self.data_ele_tmp[val_ch] = data_ele_old |
|
1003 | self.data_ele_tmp[val_ch] = data_ele_old | |
1004 | self.res_ele = data_ele |
|
1004 | self.res_ele = data_ele | |
1005 | self.res_weather[val_ch] = self.replaceNAN(data_weather=data_weather,data_ele=data_ele_old,val=self.val_mean) |
|
1005 | self.res_weather[val_ch] = self.replaceNAN(data_weather=data_weather,data_ele=data_ele_old,val=self.val_mean) | |
1006 | data_ele = self.res_ele |
|
1006 | data_ele = self.res_ele | |
1007 | data_weather = self.res_weather[val_ch] |
|
1007 | data_weather = self.res_weather[val_ch] | |
1008 |
|
1008 | |||
1009 | elif tipo_case==3:#subida |
|
1009 | elif tipo_case==3:#subida | |
1010 | vec = numpy.where(0<data_ele) |
|
1010 | vec = numpy.where(0<data_ele) | |
1011 | data_ele= data_ele[vec] |
|
1011 | data_ele= data_ele[vec] | |
1012 | data_ele_new = data_ele |
|
1012 | data_ele_new = data_ele | |
1013 | data_ele_old= data_ele_old[vec] |
|
1013 | data_ele_old= data_ele_old[vec] | |
1014 | data_weather= data_weather[vec[0]] |
|
1014 | data_weather= data_weather[vec[0]] | |
1015 | pos_ini = numpy.argmin(data_ele) |
|
1015 | pos_ini = numpy.argmin(data_ele) | |
1016 | if pos_ini>0: |
|
1016 | if pos_ini>0: | |
1017 | len_vec= len(data_ele) |
|
1017 | len_vec= len(data_ele) | |
1018 | vec3 = numpy.linspace(pos_ini,len_vec-1,len_vec-pos_ini).astype(int) |
|
1018 | vec3 = numpy.linspace(pos_ini,len_vec-1,len_vec-pos_ini).astype(int) | |
1019 | #print(vec3) |
|
1019 | #print(vec3) | |
1020 | data_ele= data_ele[vec3] |
|
1020 | data_ele= data_ele[vec3] | |
1021 | data_ele_new = data_ele |
|
1021 | data_ele_new = data_ele | |
1022 | data_ele_old= data_ele_old[vec3] |
|
1022 | data_ele_old= data_ele_old[vec3] | |
1023 | data_weather= data_weather[vec3] |
|
1023 | data_weather= data_weather[vec3] | |
1024 |
|
1024 | |||
1025 | new_i_ele = int(data_ele_new[0]) |
|
1025 | new_i_ele = int(data_ele_new[0]) | |
1026 | new_f_ele = int(data_ele_new[-1]) |
|
1026 | new_f_ele = int(data_ele_new[-1]) | |
1027 | n1= new_i_ele- ang_min |
|
1027 | n1= new_i_ele- ang_min | |
1028 | n2= ang_max - new_f_ele-1 |
|
1028 | n2= ang_max - new_f_ele-1 | |
1029 | if n1>0: |
|
1029 | if n1>0: | |
1030 | ele1= numpy.linspace(ang_min+1,new_i_ele-1,n1) |
|
1030 | ele1= numpy.linspace(ang_min+1,new_i_ele-1,n1) | |
1031 | ele1_nan= numpy.ones(n1)*numpy.nan |
|
1031 | ele1_nan= numpy.ones(n1)*numpy.nan | |
1032 | data_ele = numpy.hstack((ele1,data_ele_new)) |
|
1032 | data_ele = numpy.hstack((ele1,data_ele_new)) | |
1033 | data_ele_old = numpy.hstack((ele1_nan,data_ele_new)) |
|
1033 | data_ele_old = numpy.hstack((ele1_nan,data_ele_new)) | |
1034 | if n2>0: |
|
1034 | if n2>0: | |
1035 | ele2= numpy.linspace(new_f_ele+1,ang_max,n2) |
|
1035 | ele2= numpy.linspace(new_f_ele+1,ang_max,n2) | |
1036 | ele2_nan= numpy.ones(n2)*numpy.nan |
|
1036 | ele2_nan= numpy.ones(n2)*numpy.nan | |
1037 | data_ele = numpy.hstack((data_ele,ele2)) |
|
1037 | data_ele = numpy.hstack((data_ele,ele2)) | |
1038 | data_ele_old = numpy.hstack((data_ele_old,ele2_nan)) |
|
1038 | data_ele_old = numpy.hstack((data_ele_old,ele2_nan)) | |
1039 |
|
1039 | |||
1040 | self.data_ele_tmp[val_ch] = data_ele_old |
|
1040 | self.data_ele_tmp[val_ch] = data_ele_old | |
1041 | self.res_ele = data_ele |
|
1041 | self.res_ele = data_ele | |
1042 | self.res_weather[val_ch] = self.replaceNAN(data_weather=data_weather,data_ele=data_ele_old,val=self.val_mean) |
|
1042 | self.res_weather[val_ch] = self.replaceNAN(data_weather=data_weather,data_ele=data_ele_old,val=self.val_mean) | |
1043 | data_ele = self.res_ele |
|
1043 | data_ele = self.res_ele | |
1044 | data_weather = self.res_weather[val_ch] |
|
1044 | data_weather = self.res_weather[val_ch] | |
1045 | #print("self.data_ele_tmp",self.data_ele_tmp) |
|
1045 | #print("self.data_ele_tmp",self.data_ele_tmp) | |
1046 | return data_weather,data_ele |
|
1046 | return data_weather,data_ele | |
1047 |
|
1047 | |||
1048 |
|
1048 | |||
1049 | def plot(self): |
|
1049 | def plot(self): | |
1050 | thisDatetime = datetime.datetime.utcfromtimestamp(self.data.times[-1]).strftime('%Y-%m-%d %H:%M:%S') |
|
1050 | thisDatetime = datetime.datetime.utcfromtimestamp(self.data.times[-1]).strftime('%Y-%m-%d %H:%M:%S') | |
1051 | data = self.data[-1] |
|
1051 | data = self.data[-1] | |
1052 | r = self.data.yrange |
|
1052 | r = self.data.yrange | |
1053 | delta_height = r[1]-r[0] |
|
1053 | delta_height = r[1]-r[0] | |
1054 | r_mask = numpy.where(r>=0)[0] |
|
1054 | r_mask = numpy.where(r>=0)[0] | |
1055 | ##print("delta_height",delta_height) |
|
1055 | ##print("delta_height",delta_height) | |
1056 | #print("r_mask",r_mask,len(r_mask)) |
|
1056 | #print("r_mask",r_mask,len(r_mask)) | |
1057 | r = numpy.arange(len(r_mask))*delta_height |
|
1057 | r = numpy.arange(len(r_mask))*delta_height | |
1058 | self.y = 2*r |
|
1058 | self.y = 2*r | |
1059 | res = 1 |
|
1059 | res = 1 | |
1060 | ###print("data['weather'].shape[0]",data['weather'].shape[0]) |
|
1060 | ###print("data['weather'].shape[0]",data['weather'].shape[0]) | |
1061 | ang_max = self.ang_max |
|
1061 | ang_max = self.ang_max | |
1062 | ang_min = self.ang_min |
|
1062 | ang_min = self.ang_min | |
1063 | var_ang =ang_max - ang_min |
|
1063 | var_ang =ang_max - ang_min | |
1064 | step = (int(var_ang)/(res*data['weather'].shape[0])) |
|
1064 | step = (int(var_ang)/(res*data['weather'].shape[0])) | |
1065 | ###print("step",step) |
|
1065 | ###print("step",step) | |
1066 | #-------------------------------------------------------- |
|
1066 | #-------------------------------------------------------- | |
1067 | ##print('weather',data['weather'].shape) |
|
1067 | ##print('weather',data['weather'].shape) | |
1068 | ##print('ele',data['ele'].shape) |
|
1068 | ##print('ele',data['ele'].shape) | |
1069 |
|
1069 | |||
1070 | ###self.res_weather, self.res_ele = self.const_ploteo(data_weather=data['weather'][:,r_mask],data_ele=data['ele'],step=step,res=res,ang_max=ang_max,ang_min=ang_min) |
|
1070 | ###self.res_weather, self.res_ele = self.const_ploteo(data_weather=data['weather'][:,r_mask],data_ele=data['ele'],step=step,res=res,ang_max=ang_max,ang_min=ang_min) | |
1071 | ###self.res_azi = numpy.mean(data['azi']) |
|
1071 | ###self.res_azi = numpy.mean(data['azi']) | |
1072 | ###print("self.res_ele",self.res_ele) |
|
1072 | ###print("self.res_ele",self.res_ele) | |
1073 | plt.clf() |
|
1073 | plt.clf() | |
1074 | subplots = [121, 122] |
|
1074 | subplots = [121, 122] | |
1075 | if self.ini==0: |
|
1075 | if self.ini==0: | |
1076 | self.data_ele_tmp = numpy.ones([self.nplots,int(var_ang)])*numpy.nan |
|
1076 | self.data_ele_tmp = numpy.ones([self.nplots,int(var_ang)])*numpy.nan | |
1077 | self.res_weather= numpy.ones([self.nplots,int(var_ang),len(r_mask)])*numpy.nan |
|
1077 | self.res_weather= numpy.ones([self.nplots,int(var_ang),len(r_mask)])*numpy.nan | |
1078 | print("SHAPE",self.data_ele_tmp.shape) |
|
1078 | print("SHAPE",self.data_ele_tmp.shape) | |
1079 |
|
1079 | |||
1080 | for i,ax in enumerate(self.axes): |
|
1080 | for i,ax in enumerate(self.axes): | |
1081 | self.res_weather[i], self.res_ele = self.const_ploteo(val_ch=i, data_weather=data['weather'][i][:,r_mask],data_ele=data['ele'],step=step,res=res,ang_max=ang_max,ang_min=ang_min) |
|
1081 | self.res_weather[i], self.res_ele = self.const_ploteo(val_ch=i, data_weather=data['weather'][i][:,r_mask],data_ele=data['ele'],step=step,res=res,ang_max=ang_max,ang_min=ang_min) | |
1082 | self.res_azi = numpy.mean(data['azi']) |
|
1082 | self.res_azi = numpy.mean(data['azi']) | |
1083 | if i==0: |
|
1083 | if i==0: | |
1084 | print("*****************************************************************************to plot**************************",self.res_weather[i].shape) |
|
1084 | print("*****************************************************************************to plot**************************",self.res_weather[i].shape) | |
1085 | if ax.firsttime: |
|
1085 | if ax.firsttime: | |
1086 | #plt.clf() |
|
1086 | #plt.clf() | |
1087 | cgax, pm = wrl.vis.plot_rhi(self.res_weather[i],r=r,th=self.res_ele,ax=subplots[i], proj='cg',vmin=20, vmax=80) |
|
1087 | cgax, pm = wrl.vis.plot_rhi(self.res_weather[i],r=r,th=self.res_ele,ax=subplots[i], proj='cg',vmin=20, vmax=80) | |
1088 | #fig=self.figures[0] |
|
1088 | #fig=self.figures[0] | |
1089 | else: |
|
1089 | else: | |
1090 | #plt.clf() |
|
1090 | #plt.clf() | |
1091 | if i==0: |
|
1091 | if i==0: | |
1092 | print(self.res_weather[i]) |
|
1092 | print(self.res_weather[i]) | |
1093 | print(self.res_ele) |
|
1093 | print(self.res_ele) | |
1094 | cgax, pm = wrl.vis.plot_rhi(self.res_weather[i],r=r,th=self.res_ele,ax=subplots[i], proj='cg',vmin=20, vmax=80) |
|
1094 | cgax, pm = wrl.vis.plot_rhi(self.res_weather[i],r=r,th=self.res_ele,ax=subplots[i], proj='cg',vmin=20, vmax=80) | |
1095 | caax = cgax.parasites[0] |
|
1095 | caax = cgax.parasites[0] | |
1096 | paax = cgax.parasites[1] |
|
1096 | paax = cgax.parasites[1] | |
1097 | cbar = plt.gcf().colorbar(pm, pad=0.075) |
|
1097 | cbar = plt.gcf().colorbar(pm, pad=0.075) | |
1098 | caax.set_xlabel('x_range [km]') |
|
1098 | caax.set_xlabel('x_range [km]') | |
1099 | caax.set_ylabel('y_range [km]') |
|
1099 | caax.set_ylabel('y_range [km]') | |
1100 | plt.text(1.0, 1.05, 'Elevacion '+str(thisDatetime)+" Step "+str(self.ini)+ " Azi: "+str(round(self.res_azi,2)), transform=caax.transAxes, va='bottom',ha='right') |
|
1100 | plt.text(1.0, 1.05, 'Elevacion '+str(thisDatetime)+" Step "+str(self.ini)+ " Azi: "+str(round(self.res_azi,2)), transform=caax.transAxes, va='bottom',ha='right') | |
1101 | print("***************************self.ini****************************",self.ini) |
|
1101 | print("***************************self.ini****************************",self.ini) | |
1102 | self.ini= self.ini+1 |
|
1102 | self.ini= self.ini+1 | |
1103 |
|
1103 | |||
1104 | class WeatherRHI_vRF2_Plot(Plot): |
|
1104 | class WeatherRHI_vRF2_Plot(Plot): | |
1105 | CODE = 'weather' |
|
1105 | CODE = 'weather' | |
1106 | plot_name = 'weather' |
|
1106 | plot_name = 'weather' | |
1107 | plot_type = 'rhistyle' |
|
1107 | plot_type = 'rhistyle' | |
1108 | buffering = False |
|
1108 | buffering = False | |
1109 | data_ele_tmp = None |
|
1109 | data_ele_tmp = None | |
1110 |
|
1110 | |||
1111 | def setup(self): |
|
1111 | def setup(self): | |
1112 | print("********************") |
|
1112 | print("********************") | |
1113 | print("********************") |
|
1113 | print("********************") | |
1114 | print("********************") |
|
1114 | print("********************") | |
1115 | print("SETUP WEATHER PLOT") |
|
1115 | print("SETUP WEATHER PLOT") | |
1116 | self.ncols = 1 |
|
1116 | self.ncols = 1 | |
1117 | self.nrows = 1 |
|
1117 | self.nrows = 1 | |
1118 | self.nplots= 1 |
|
1118 | self.nplots= 1 | |
1119 | self.ylabel= 'Range [Km]' |
|
1119 | self.ylabel= 'Range [Km]' | |
1120 | self.titles= ['Weather'] |
|
1120 | self.titles= ['Weather'] | |
1121 | if self.channels is not None: |
|
1121 | if self.channels is not None: | |
1122 | self.nplots = len(self.channels) |
|
1122 | self.nplots = len(self.channels) | |
1123 | self.nrows = len(self.channels) |
|
1123 | self.nrows = len(self.channels) | |
1124 | else: |
|
1124 | else: | |
1125 | self.nplots = self.data.shape(self.CODE)[0] |
|
1125 | self.nplots = self.data.shape(self.CODE)[0] | |
1126 | self.nrows = self.nplots |
|
1126 | self.nrows = self.nplots | |
1127 | self.channels = list(range(self.nplots)) |
|
1127 | self.channels = list(range(self.nplots)) | |
1128 | print("channels",self.channels) |
|
1128 | print("channels",self.channels) | |
1129 | print("que saldra", self.data.shape(self.CODE)[0]) |
|
1129 | print("que saldra", self.data.shape(self.CODE)[0]) | |
1130 | self.titles = ['{} Channel {}'.format(self.CODE.upper(), x) for x in range(self.nrows)] |
|
1130 | self.titles = ['{} Channel {}'.format(self.CODE.upper(), x) for x in range(self.nrows)] | |
1131 | print("self.titles",self.titles) |
|
1131 | print("self.titles",self.titles) | |
1132 | self.colorbar=False |
|
1132 | self.colorbar=False | |
1133 | self.width =8 |
|
1133 | self.width =8 | |
1134 | self.height =8 |
|
1134 | self.height =8 | |
1135 | self.ini =0 |
|
1135 | self.ini =0 | |
1136 | self.len_azi =0 |
|
1136 | self.len_azi =0 | |
1137 | self.buffer_ini = None |
|
1137 | self.buffer_ini = None | |
1138 | self.buffer_ele = None |
|
1138 | self.buffer_ele = None | |
1139 | self.plots_adjust.update({'wspace': 0.4, 'hspace':0.4, 'left': 0.1, 'right': 0.9, 'bottom': 0.08}) |
|
1139 | self.plots_adjust.update({'wspace': 0.4, 'hspace':0.4, 'left': 0.1, 'right': 0.9, 'bottom': 0.08}) | |
1140 | self.flag =0 |
|
1140 | self.flag =0 | |
1141 | self.indicador= 0 |
|
1141 | self.indicador= 0 | |
1142 | self.last_data_ele = None |
|
1142 | self.last_data_ele = None | |
1143 | self.val_mean = None |
|
1143 | self.val_mean = None | |
1144 |
|
1144 | |||
1145 | def update(self, dataOut): |
|
1145 | def update(self, dataOut): | |
1146 |
|
1146 | |||
1147 | data = {} |
|
1147 | data = {} | |
1148 | meta = {} |
|
1148 | meta = {} | |
1149 | if hasattr(dataOut, 'dataPP_POWER'): |
|
1149 | if hasattr(dataOut, 'dataPP_POWER'): | |
1150 | factor = 1 |
|
1150 | factor = 1 | |
1151 | if hasattr(dataOut, 'nFFTPoints'): |
|
1151 | if hasattr(dataOut, 'nFFTPoints'): | |
1152 | factor = dataOut.normFactor |
|
1152 | factor = dataOut.normFactor | |
1153 | print("dataOut",dataOut.data_360.shape) |
|
1153 | print("dataOut",dataOut.data_360.shape) | |
1154 | # |
|
1154 | # | |
1155 | data['weather'] = 10*numpy.log10(dataOut.data_360/(factor)) |
|
1155 | data['weather'] = 10*numpy.log10(dataOut.data_360/(factor)) | |
1156 | # |
|
1156 | # | |
1157 | #data['weather'] = 10*numpy.log10(dataOut.data_360[1]/(factor)) |
|
1157 | #data['weather'] = 10*numpy.log10(dataOut.data_360[1]/(factor)) | |
1158 | data['azi'] = dataOut.data_azi |
|
1158 | data['azi'] = dataOut.data_azi | |
1159 | data['ele'] = dataOut.data_ele |
|
1159 | data['ele'] = dataOut.data_ele | |
1160 | data['case_flag'] = dataOut.case_flag |
|
1160 | data['case_flag'] = dataOut.case_flag | |
1161 | #print("UPDATE") |
|
1161 | #print("UPDATE") | |
1162 | #print("data[weather]",data['weather'].shape) |
|
1162 | #print("data[weather]",data['weather'].shape) | |
1163 | #print("data[azi]",data['azi']) |
|
1163 | #print("data[azi]",data['azi']) | |
1164 | return data, meta |
|
1164 | return data, meta | |
1165 |
|
1165 | |||
1166 | def get2List(self,angulos): |
|
1166 | def get2List(self,angulos): | |
1167 | list1=[] |
|
1167 | list1=[] | |
1168 | list2=[] |
|
1168 | list2=[] | |
1169 | for i in reversed(range(len(angulos))): |
|
1169 | for i in reversed(range(len(angulos))): | |
1170 | if not i==0:#el caso de i=0 evalula el primero de la lista con el ultimo y no es relevante |
|
1170 | if not i==0:#el caso de i=0 evalula el primero de la lista con el ultimo y no es relevante | |
1171 | diff_ = angulos[i]-angulos[i-1] |
|
1171 | diff_ = angulos[i]-angulos[i-1] | |
1172 | if abs(diff_) >1.5: |
|
1172 | if abs(diff_) >1.5: | |
1173 | list1.append(i-1) |
|
1173 | list1.append(i-1) | |
1174 | list2.append(diff_) |
|
1174 | list2.append(diff_) | |
1175 | return list(reversed(list1)),list(reversed(list2)) |
|
1175 | return list(reversed(list1)),list(reversed(list2)) | |
1176 |
|
1176 | |||
1177 | def fixData90(self,list_,ang_): |
|
1177 | def fixData90(self,list_,ang_): | |
1178 | if list_[0]==-1: |
|
1178 | if list_[0]==-1: | |
1179 | vec = numpy.where(ang_<ang_[0]) |
|
1179 | vec = numpy.where(ang_<ang_[0]) | |
1180 | ang_[vec] = ang_[vec]+90 |
|
1180 | ang_[vec] = ang_[vec]+90 | |
1181 | return ang_ |
|
1181 | return ang_ | |
1182 | return ang_ |
|
1182 | return ang_ | |
1183 |
|
1183 | |||
1184 | def fixData90HL(self,angulos): |
|
1184 | def fixData90HL(self,angulos): | |
1185 | vec = numpy.where(angulos>=90) |
|
1185 | vec = numpy.where(angulos>=90) | |
1186 | angulos[vec]=angulos[vec]-90 |
|
1186 | angulos[vec]=angulos[vec]-90 | |
1187 | return angulos |
|
1187 | return angulos | |
1188 |
|
1188 | |||
1189 |
|
1189 | |||
1190 | def search_pos(self,pos,list_): |
|
1190 | def search_pos(self,pos,list_): | |
1191 | for i in range(len(list_)): |
|
1191 | for i in range(len(list_)): | |
1192 | if pos == list_[i]: |
|
1192 | if pos == list_[i]: | |
1193 | return True,i |
|
1193 | return True,i | |
1194 | i=None |
|
1194 | i=None | |
1195 | return False,i |
|
1195 | return False,i | |
1196 |
|
1196 | |||
1197 | def fixDataComp(self,ang_,list1_,list2_,tipo_case): |
|
1197 | def fixDataComp(self,ang_,list1_,list2_,tipo_case): | |
1198 | size = len(ang_) |
|
1198 | size = len(ang_) | |
1199 | size2 = 0 |
|
1199 | size2 = 0 | |
1200 | for i in range(len(list2_)): |
|
1200 | for i in range(len(list2_)): | |
1201 | size2=size2+round(abs(list2_[i]))-1 |
|
1201 | size2=size2+round(abs(list2_[i]))-1 | |
1202 | new_size= size+size2 |
|
1202 | new_size= size+size2 | |
1203 | ang_new = numpy.zeros(new_size) |
|
1203 | ang_new = numpy.zeros(new_size) | |
1204 | ang_new2 = numpy.zeros(new_size) |
|
1204 | ang_new2 = numpy.zeros(new_size) | |
1205 |
|
1205 | |||
1206 | tmp = 0 |
|
1206 | tmp = 0 | |
1207 | c = 0 |
|
1207 | c = 0 | |
1208 | for i in range(len(ang_)): |
|
1208 | for i in range(len(ang_)): | |
1209 | ang_new[tmp +c] = ang_[i] |
|
1209 | ang_new[tmp +c] = ang_[i] | |
1210 | ang_new2[tmp+c] = ang_[i] |
|
1210 | ang_new2[tmp+c] = ang_[i] | |
1211 | condition , value = self.search_pos(i,list1_) |
|
1211 | condition , value = self.search_pos(i,list1_) | |
1212 | if condition: |
|
1212 | if condition: | |
1213 | pos = tmp + c + 1 |
|
1213 | pos = tmp + c + 1 | |
1214 | for k in range(round(abs(list2_[value]))-1): |
|
1214 | for k in range(round(abs(list2_[value]))-1): | |
1215 | if tipo_case==0 or tipo_case==3:#subida |
|
1215 | if tipo_case==0 or tipo_case==3:#subida | |
1216 | ang_new[pos+k] = ang_new[pos+k-1]+1 |
|
1216 | ang_new[pos+k] = ang_new[pos+k-1]+1 | |
1217 | ang_new2[pos+k] = numpy.nan |
|
1217 | ang_new2[pos+k] = numpy.nan | |
1218 | elif tipo_case==1 or tipo_case==2:#bajada |
|
1218 | elif tipo_case==1 or tipo_case==2:#bajada | |
1219 | ang_new[pos+k] = ang_new[pos+k-1]-1 |
|
1219 | ang_new[pos+k] = ang_new[pos+k-1]-1 | |
1220 | ang_new2[pos+k] = numpy.nan |
|
1220 | ang_new2[pos+k] = numpy.nan | |
1221 |
|
1221 | |||
1222 | tmp = pos +k |
|
1222 | tmp = pos +k | |
1223 | c = 0 |
|
1223 | c = 0 | |
1224 | c=c+1 |
|
1224 | c=c+1 | |
1225 | return ang_new,ang_new2 |
|
1225 | return ang_new,ang_new2 | |
1226 |
|
1226 | |||
1227 | def globalCheckPED(self,angulos,tipo_case): |
|
1227 | def globalCheckPED(self,angulos,tipo_case): | |
1228 | l1,l2 = self.get2List(angulos) |
|
1228 | l1,l2 = self.get2List(angulos) | |
1229 | ##print("l1",l1) |
|
1229 | ##print("l1",l1) | |
1230 | ##print("l2",l2) |
|
1230 | ##print("l2",l2) | |
1231 | if len(l1)>0: |
|
1231 | if len(l1)>0: | |
1232 | #angulos2 = self.fixData90(list_=l1,ang_=angulos) |
|
1232 | #angulos2 = self.fixData90(list_=l1,ang_=angulos) | |
1233 | #l1,l2 = self.get2List(angulos2) |
|
1233 | #l1,l2 = self.get2List(angulos2) | |
1234 | ang1_,ang2_ = self.fixDataComp(ang_=angulos,list1_=l1,list2_=l2,tipo_case=tipo_case) |
|
1234 | ang1_,ang2_ = self.fixDataComp(ang_=angulos,list1_=l1,list2_=l2,tipo_case=tipo_case) | |
1235 | #ang1_ = self.fixData90HL(ang1_) |
|
1235 | #ang1_ = self.fixData90HL(ang1_) | |
1236 | #ang2_ = self.fixData90HL(ang2_) |
|
1236 | #ang2_ = self.fixData90HL(ang2_) | |
1237 | else: |
|
1237 | else: | |
1238 | ang1_= angulos |
|
1238 | ang1_= angulos | |
1239 | ang2_= angulos |
|
1239 | ang2_= angulos | |
1240 | return ang1_,ang2_ |
|
1240 | return ang1_,ang2_ | |
1241 |
|
1241 | |||
1242 |
|
1242 | |||
1243 | def replaceNAN(self,data_weather,data_ele,val): |
|
1243 | def replaceNAN(self,data_weather,data_ele,val): | |
1244 | data= data_ele |
|
1244 | data= data_ele | |
1245 | data_T= data_weather |
|
1245 | data_T= data_weather | |
1246 | if data.shape[0]> data_T.shape[0]: |
|
1246 | if data.shape[0]> data_T.shape[0]: | |
1247 | data_N = numpy.ones( [data.shape[0],data_T.shape[1]]) |
|
1247 | data_N = numpy.ones( [data.shape[0],data_T.shape[1]]) | |
1248 | c = 0 |
|
1248 | c = 0 | |
1249 | for i in range(len(data)): |
|
1249 | for i in range(len(data)): | |
1250 | if numpy.isnan(data[i]): |
|
1250 | if numpy.isnan(data[i]): | |
1251 | data_N[i,:]=numpy.ones(data_T.shape[1])*numpy.nan |
|
1251 | data_N[i,:]=numpy.ones(data_T.shape[1])*numpy.nan | |
1252 | else: |
|
1252 | else: | |
1253 | data_N[i,:]=data_T[c,:] |
|
1253 | data_N[i,:]=data_T[c,:] | |
1254 | c=c+1 |
|
1254 | c=c+1 | |
1255 | return data_N |
|
1255 | return data_N | |
1256 | else: |
|
1256 | else: | |
1257 | for i in range(len(data)): |
|
1257 | for i in range(len(data)): | |
1258 | if numpy.isnan(data[i]): |
|
1258 | if numpy.isnan(data[i]): | |
1259 | data_T[i,:]=numpy.ones(data_T.shape[1])*numpy.nan |
|
1259 | data_T[i,:]=numpy.ones(data_T.shape[1])*numpy.nan | |
1260 | return data_T |
|
1260 | return data_T | |
1261 |
|
1261 | |||
1262 | def check_case(self,data_ele,ang_max,ang_min): |
|
1262 | def check_case(self,data_ele,ang_max,ang_min): | |
1263 | start = data_ele[0] |
|
1263 | start = data_ele[0] | |
1264 | end = data_ele[-1] |
|
1264 | end = data_ele[-1] | |
1265 | number = (end-start) |
|
1265 | number = (end-start) | |
1266 | len_ang=len(data_ele) |
|
1266 | len_ang=len(data_ele) | |
1267 | print("start",start) |
|
1267 | print("start",start) | |
1268 | print("end",end) |
|
1268 | print("end",end) | |
1269 | print("number",number) |
|
1269 | print("number",number) | |
1270 |
|
1270 | |||
1271 | print("len_ang",len_ang) |
|
1271 | print("len_ang",len_ang) | |
1272 |
|
1272 | |||
1273 | #exit(1) |
|
1273 | #exit(1) | |
1274 |
|
1274 | |||
1275 | if start<end and (round(abs(number)+1)>=len_ang or (numpy.argmin(data_ele)==0)):#caso subida |
|
1275 | if start<end and (round(abs(number)+1)>=len_ang or (numpy.argmin(data_ele)==0)):#caso subida | |
1276 | return 0 |
|
1276 | return 0 | |
1277 | #elif start>end and (round(abs(number)+1)>=len_ang or(numpy.argmax(data_ele)==0)):#caso bajada |
|
1277 | #elif start>end and (round(abs(number)+1)>=len_ang or(numpy.argmax(data_ele)==0)):#caso bajada | |
1278 | # return 1 |
|
1278 | # return 1 | |
1279 | elif round(abs(number)+1)>=len_ang and (start>end or(numpy.argmax(data_ele)==0)):#caso bajada |
|
1279 | elif round(abs(number)+1)>=len_ang and (start>end or(numpy.argmax(data_ele)==0)):#caso bajada | |
1280 | return 1 |
|
1280 | return 1 | |
1281 | elif round(abs(number)+1)<len_ang and data_ele[-2]>data_ele[-1]:# caso BAJADA CAMBIO ANG MAX |
|
1281 | elif round(abs(number)+1)<len_ang and data_ele[-2]>data_ele[-1]:# caso BAJADA CAMBIO ANG MAX | |
1282 | return 2 |
|
1282 | return 2 | |
1283 | elif round(abs(number)+1)<len_ang and data_ele[-2]<data_ele[-1] :# caso SUBIDA CAMBIO ANG MIN |
|
1283 | elif round(abs(number)+1)<len_ang and data_ele[-2]<data_ele[-1] :# caso SUBIDA CAMBIO ANG MIN | |
1284 | return 3 |
|
1284 | return 3 | |
1285 |
|
1285 | |||
1286 |
|
1286 | |||
1287 | def const_ploteo(self,val_ch,data_weather,data_ele,step,res,ang_max,ang_min,case_flag): |
|
1287 | def const_ploteo(self,val_ch,data_weather,data_ele,step,res,ang_max,ang_min,case_flag): | |
1288 | ang_max= ang_max |
|
1288 | ang_max= ang_max | |
1289 | ang_min= ang_min |
|
1289 | ang_min= ang_min | |
1290 | data_weather=data_weather |
|
1290 | data_weather=data_weather | |
1291 | val_ch=val_ch |
|
1291 | val_ch=val_ch | |
1292 | ##print("*********************DATA WEATHER**************************************") |
|
1292 | ##print("*********************DATA WEATHER**************************************") | |
1293 | ##print(data_weather) |
|
1293 | ##print(data_weather) | |
1294 | if self.ini==0: |
|
1294 | if self.ini==0: | |
1295 | ''' |
|
1295 | ''' | |
1296 | print("**********************************************") |
|
1296 | print("**********************************************") | |
1297 | print("**********************************************") |
|
1297 | print("**********************************************") | |
1298 | print("***************ini**************") |
|
1298 | print("***************ini**************") | |
1299 | print("**********************************************") |
|
1299 | print("**********************************************") | |
1300 | print("**********************************************") |
|
1300 | print("**********************************************") | |
1301 | ''' |
|
1301 | ''' | |
1302 | #print("data_ele",data_ele) |
|
1302 | #print("data_ele",data_ele) | |
1303 | #---------------------------------------------------------- |
|
1303 | #---------------------------------------------------------- | |
1304 | tipo_case = case_flag[-1] |
|
1304 | tipo_case = case_flag[-1] | |
1305 | #tipo_case = self.check_case(data_ele,ang_max,ang_min) |
|
1305 | #tipo_case = self.check_case(data_ele,ang_max,ang_min) | |
1306 | print("check_case",tipo_case) |
|
1306 | print("check_case",tipo_case) | |
1307 | #exit(1) |
|
1307 | #exit(1) | |
1308 | #--------------------- new ------------------------- |
|
1308 | #--------------------- new ------------------------- | |
1309 | data_ele_new ,data_ele_old= self.globalCheckPED(data_ele,tipo_case) |
|
1309 | data_ele_new ,data_ele_old= self.globalCheckPED(data_ele,tipo_case) | |
1310 |
|
1310 | |||
1311 | #-------------------------CAMBIOS RHI--------------------------------- |
|
1311 | #-------------------------CAMBIOS RHI--------------------------------- | |
1312 | start= ang_min |
|
1312 | start= ang_min | |
1313 | end = ang_max |
|
1313 | end = ang_max | |
1314 | n= (ang_max-ang_min)/res |
|
1314 | n= (ang_max-ang_min)/res | |
1315 | #------ new |
|
1315 | #------ new | |
1316 | self.start_data_ele = data_ele_new[0] |
|
1316 | self.start_data_ele = data_ele_new[0] | |
1317 | self.end_data_ele = data_ele_new[-1] |
|
1317 | self.end_data_ele = data_ele_new[-1] | |
1318 | if tipo_case==0 or tipo_case==3: # SUBIDA |
|
1318 | if tipo_case==0 or tipo_case==3: # SUBIDA | |
1319 | n1= round(self.start_data_ele)- start |
|
1319 | n1= round(self.start_data_ele)- start | |
1320 | n2= end - round(self.end_data_ele) |
|
1320 | n2= end - round(self.end_data_ele) | |
1321 | print(self.start_data_ele) |
|
1321 | print(self.start_data_ele) | |
1322 | print(self.end_data_ele) |
|
1322 | print(self.end_data_ele) | |
1323 | if n1>0: |
|
1323 | if n1>0: | |
1324 | ele1= numpy.linspace(ang_min+1,self.start_data_ele-1,n1) |
|
1324 | ele1= numpy.linspace(ang_min+1,self.start_data_ele-1,n1) | |
1325 | ele1_nan= numpy.ones(n1)*numpy.nan |
|
1325 | ele1_nan= numpy.ones(n1)*numpy.nan | |
1326 | data_ele = numpy.hstack((ele1,data_ele_new)) |
|
1326 | data_ele = numpy.hstack((ele1,data_ele_new)) | |
1327 | print("ele1_nan",ele1_nan.shape) |
|
1327 | print("ele1_nan",ele1_nan.shape) | |
1328 | print("data_ele_old",data_ele_old.shape) |
|
1328 | print("data_ele_old",data_ele_old.shape) | |
1329 | data_ele_old = numpy.hstack((ele1_nan,data_ele_old)) |
|
1329 | data_ele_old = numpy.hstack((ele1_nan,data_ele_old)) | |
1330 | if n2>0: |
|
1330 | if n2>0: | |
1331 | ele2= numpy.linspace(self.end_data_ele+1,end,n2) |
|
1331 | ele2= numpy.linspace(self.end_data_ele+1,end,n2) | |
1332 | ele2_nan= numpy.ones(n2)*numpy.nan |
|
1332 | ele2_nan= numpy.ones(n2)*numpy.nan | |
1333 | data_ele = numpy.hstack((data_ele,ele2)) |
|
1333 | data_ele = numpy.hstack((data_ele,ele2)) | |
1334 | print("ele2_nan",ele2_nan.shape) |
|
1334 | print("ele2_nan",ele2_nan.shape) | |
1335 | print("data_ele_old",data_ele_old.shape) |
|
1335 | print("data_ele_old",data_ele_old.shape) | |
1336 | data_ele_old = numpy.hstack((data_ele_old,ele2_nan)) |
|
1336 | data_ele_old = numpy.hstack((data_ele_old,ele2_nan)) | |
1337 |
|
1337 | |||
1338 | if tipo_case==1 or tipo_case==2: # BAJADA |
|
1338 | if tipo_case==1 or tipo_case==2: # BAJADA | |
1339 | data_ele_new = data_ele_new[::-1] # reversa |
|
1339 | data_ele_new = data_ele_new[::-1] # reversa | |
1340 | data_ele_old = data_ele_old[::-1]# reversa |
|
1340 | data_ele_old = data_ele_old[::-1]# reversa | |
1341 | data_weather = data_weather[::-1,:]# reversa |
|
1341 | data_weather = data_weather[::-1,:]# reversa | |
1342 | vec= numpy.where(data_ele_new<ang_max) |
|
1342 | vec= numpy.where(data_ele_new<ang_max) | |
1343 | data_ele_new = data_ele_new[vec] |
|
1343 | data_ele_new = data_ele_new[vec] | |
1344 | data_ele_old = data_ele_old[vec] |
|
1344 | data_ele_old = data_ele_old[vec] | |
1345 | data_weather = data_weather[vec[0]] |
|
1345 | data_weather = data_weather[vec[0]] | |
1346 | vec2= numpy.where(0<data_ele_new) |
|
1346 | vec2= numpy.where(0<data_ele_new) | |
1347 | data_ele_new = data_ele_new[vec2] |
|
1347 | data_ele_new = data_ele_new[vec2] | |
1348 | data_ele_old = data_ele_old[vec2] |
|
1348 | data_ele_old = data_ele_old[vec2] | |
1349 | data_weather = data_weather[vec2[0]] |
|
1349 | data_weather = data_weather[vec2[0]] | |
1350 | self.start_data_ele = data_ele_new[0] |
|
1350 | self.start_data_ele = data_ele_new[0] | |
1351 | self.end_data_ele = data_ele_new[-1] |
|
1351 | self.end_data_ele = data_ele_new[-1] | |
1352 |
|
1352 | |||
1353 | n1= round(self.start_data_ele)- start |
|
1353 | n1= round(self.start_data_ele)- start | |
1354 | n2= end - round(self.end_data_ele)-1 |
|
1354 | n2= end - round(self.end_data_ele)-1 | |
1355 | print(self.start_data_ele) |
|
1355 | print(self.start_data_ele) | |
1356 | print(self.end_data_ele) |
|
1356 | print(self.end_data_ele) | |
1357 | if n1>0: |
|
1357 | if n1>0: | |
1358 | ele1= numpy.linspace(ang_min+1,self.start_data_ele-1,n1) |
|
1358 | ele1= numpy.linspace(ang_min+1,self.start_data_ele-1,n1) | |
1359 | ele1_nan= numpy.ones(n1)*numpy.nan |
|
1359 | ele1_nan= numpy.ones(n1)*numpy.nan | |
1360 | data_ele = numpy.hstack((ele1,data_ele_new)) |
|
1360 | data_ele = numpy.hstack((ele1,data_ele_new)) | |
1361 | data_ele_old = numpy.hstack((ele1_nan,data_ele_old)) |
|
1361 | data_ele_old = numpy.hstack((ele1_nan,data_ele_old)) | |
1362 | if n2>0: |
|
1362 | if n2>0: | |
1363 | ele2= numpy.linspace(self.end_data_ele+1,end,n2) |
|
1363 | ele2= numpy.linspace(self.end_data_ele+1,end,n2) | |
1364 | ele2_nan= numpy.ones(n2)*numpy.nan |
|
1364 | ele2_nan= numpy.ones(n2)*numpy.nan | |
1365 | data_ele = numpy.hstack((data_ele,ele2)) |
|
1365 | data_ele = numpy.hstack((data_ele,ele2)) | |
1366 | data_ele_old = numpy.hstack((data_ele_old,ele2_nan)) |
|
1366 | data_ele_old = numpy.hstack((data_ele_old,ele2_nan)) | |
1367 | # RADAR |
|
1367 | # RADAR | |
1368 | # NOTA data_ele y data_weather es la variable que retorna |
|
1368 | # NOTA data_ele y data_weather es la variable que retorna | |
1369 | val_mean = numpy.mean(data_weather[:,-1]) |
|
1369 | val_mean = numpy.mean(data_weather[:,-1]) | |
1370 | self.val_mean = val_mean |
|
1370 | self.val_mean = val_mean | |
1371 | data_weather = self.replaceNAN(data_weather=data_weather,data_ele=data_ele_old,val=self.val_mean) |
|
1371 | data_weather = self.replaceNAN(data_weather=data_weather,data_ele=data_ele_old,val=self.val_mean) | |
1372 | print("eleold",data_ele_old) |
|
1372 | print("eleold",data_ele_old) | |
1373 | print(self.data_ele_tmp[val_ch]) |
|
1373 | print(self.data_ele_tmp[val_ch]) | |
1374 | print(data_ele_old.shape[0]) |
|
1374 | print(data_ele_old.shape[0]) | |
1375 | print(self.data_ele_tmp[val_ch].shape[0]) |
|
1375 | print(self.data_ele_tmp[val_ch].shape[0]) | |
1376 | if (data_ele_old.shape[0]==91 or self.data_ele_tmp[val_ch].shape[0]==91): |
|
1376 | if (data_ele_old.shape[0]==91 or self.data_ele_tmp[val_ch].shape[0]==91): | |
1377 | import sys |
|
1377 | import sys | |
1378 | print("EXIT",self.ini) |
|
1378 | print("EXIT",self.ini) | |
1379 |
|
1379 | |||
1380 | sys.exit(1) |
|
1380 | sys.exit(1) | |
1381 | self.data_ele_tmp[val_ch]= data_ele_old |
|
1381 | self.data_ele_tmp[val_ch]= data_ele_old | |
1382 | else: |
|
1382 | else: | |
1383 | #print("**********************************************") |
|
1383 | #print("**********************************************") | |
1384 | #print("****************VARIABLE**********************") |
|
1384 | #print("****************VARIABLE**********************") | |
1385 | #-------------------------CAMBIOS RHI--------------------------------- |
|
1385 | #-------------------------CAMBIOS RHI--------------------------------- | |
1386 | #--------------------------------------------------------------------- |
|
1386 | #--------------------------------------------------------------------- | |
1387 | ##print("INPUT data_ele",data_ele) |
|
1387 | ##print("INPUT data_ele",data_ele) | |
1388 | flag=0 |
|
1388 | flag=0 | |
1389 | start_ele = self.res_ele[0] |
|
1389 | start_ele = self.res_ele[0] | |
1390 | #tipo_case = self.check_case(data_ele,ang_max,ang_min) |
|
1390 | #tipo_case = self.check_case(data_ele,ang_max,ang_min) | |
1391 | tipo_case = case_flag[-1] |
|
1391 | tipo_case = case_flag[-1] | |
1392 | #print("TIPO DE DATA",tipo_case) |
|
1392 | #print("TIPO DE DATA",tipo_case) | |
1393 | #-----------new------------ |
|
1393 | #-----------new------------ | |
1394 | data_ele ,data_ele_old = self.globalCheckPED(data_ele,tipo_case) |
|
1394 | data_ele ,data_ele_old = self.globalCheckPED(data_ele,tipo_case) | |
1395 | data_weather = self.replaceNAN(data_weather=data_weather,data_ele=data_ele_old,val=self.val_mean) |
|
1395 | data_weather = self.replaceNAN(data_weather=data_weather,data_ele=data_ele_old,val=self.val_mean) | |
1396 |
|
1396 | |||
1397 | #-------------------------------NEW RHI ITERATIVO------------------------- |
|
1397 | #-------------------------------NEW RHI ITERATIVO------------------------- | |
1398 |
|
1398 | |||
1399 | if tipo_case==0 : # SUBIDA |
|
1399 | if tipo_case==0 : # SUBIDA | |
1400 | vec = numpy.where(data_ele<ang_max) |
|
1400 | vec = numpy.where(data_ele<ang_max) | |
1401 | data_ele = data_ele[vec] |
|
1401 | data_ele = data_ele[vec] | |
1402 | data_ele_old = data_ele_old[vec] |
|
1402 | data_ele_old = data_ele_old[vec] | |
1403 | data_weather = data_weather[vec[0]] |
|
1403 | data_weather = data_weather[vec[0]] | |
1404 |
|
1404 | |||
1405 | vec2 = numpy.where(0<data_ele) |
|
1405 | vec2 = numpy.where(0<data_ele) | |
1406 | data_ele= data_ele[vec2] |
|
1406 | data_ele= data_ele[vec2] | |
1407 | data_ele_old= data_ele_old[vec2] |
|
1407 | data_ele_old= data_ele_old[vec2] | |
1408 | ##print(data_ele_new) |
|
1408 | ##print(data_ele_new) | |
1409 | data_weather= data_weather[vec2[0]] |
|
1409 | data_weather= data_weather[vec2[0]] | |
1410 |
|
1410 | |||
1411 | new_i_ele = int(round(data_ele[0])) |
|
1411 | new_i_ele = int(round(data_ele[0])) | |
1412 | new_f_ele = int(round(data_ele[-1])) |
|
1412 | new_f_ele = int(round(data_ele[-1])) | |
1413 | #print(new_i_ele) |
|
1413 | #print(new_i_ele) | |
1414 | #print(new_f_ele) |
|
1414 | #print(new_f_ele) | |
1415 | #print(data_ele,len(data_ele)) |
|
1415 | #print(data_ele,len(data_ele)) | |
1416 | #print(data_ele_old,len(data_ele_old)) |
|
1416 | #print(data_ele_old,len(data_ele_old)) | |
1417 | if new_i_ele< 2: |
|
1417 | if new_i_ele< 2: | |
1418 | self.data_ele_tmp[val_ch] = numpy.ones(ang_max-ang_min)*numpy.nan |
|
1418 | self.data_ele_tmp[val_ch] = numpy.ones(ang_max-ang_min)*numpy.nan | |
1419 | self.res_weather[val_ch] = self.replaceNAN(data_weather=self.res_weather[val_ch],data_ele=self.data_ele_tmp[val_ch],val=self.val_mean) |
|
1419 | self.res_weather[val_ch] = self.replaceNAN(data_weather=self.res_weather[val_ch],data_ele=self.data_ele_tmp[val_ch],val=self.val_mean) | |
1420 | self.data_ele_tmp[val_ch][new_i_ele:new_i_ele+len(data_ele)]=data_ele_old |
|
1420 | self.data_ele_tmp[val_ch][new_i_ele:new_i_ele+len(data_ele)]=data_ele_old | |
1421 | self.res_ele[new_i_ele:new_i_ele+len(data_ele)]= data_ele |
|
1421 | self.res_ele[new_i_ele:new_i_ele+len(data_ele)]= data_ele | |
1422 | self.res_weather[val_ch][new_i_ele:new_i_ele+len(data_ele),:]= data_weather |
|
1422 | self.res_weather[val_ch][new_i_ele:new_i_ele+len(data_ele),:]= data_weather | |
1423 | data_ele = self.res_ele |
|
1423 | data_ele = self.res_ele | |
1424 | data_weather = self.res_weather[val_ch] |
|
1424 | data_weather = self.res_weather[val_ch] | |
1425 |
|
1425 | |||
1426 | elif tipo_case==1 : #BAJADA |
|
1426 | elif tipo_case==1 : #BAJADA | |
1427 | data_ele = data_ele[::-1] # reversa |
|
1427 | data_ele = data_ele[::-1] # reversa | |
1428 | data_ele_old = data_ele_old[::-1]# reversa |
|
1428 | data_ele_old = data_ele_old[::-1]# reversa | |
1429 | data_weather = data_weather[::-1,:]# reversa |
|
1429 | data_weather = data_weather[::-1,:]# reversa | |
1430 | vec= numpy.where(data_ele<ang_max) |
|
1430 | vec= numpy.where(data_ele<ang_max) | |
1431 | data_ele = data_ele[vec] |
|
1431 | data_ele = data_ele[vec] | |
1432 | data_ele_old = data_ele_old[vec] |
|
1432 | data_ele_old = data_ele_old[vec] | |
1433 | data_weather = data_weather[vec[0]] |
|
1433 | data_weather = data_weather[vec[0]] | |
1434 | vec2= numpy.where(0<data_ele) |
|
1434 | vec2= numpy.where(0<data_ele) | |
1435 | data_ele = data_ele[vec2] |
|
1435 | data_ele = data_ele[vec2] | |
1436 | data_ele_old = data_ele_old[vec2] |
|
1436 | data_ele_old = data_ele_old[vec2] | |
1437 | data_weather = data_weather[vec2[0]] |
|
1437 | data_weather = data_weather[vec2[0]] | |
1438 |
|
1438 | |||
1439 |
|
1439 | |||
1440 | new_i_ele = int(round(data_ele[0])) |
|
1440 | new_i_ele = int(round(data_ele[0])) | |
1441 | new_f_ele = int(round(data_ele[-1])) |
|
1441 | new_f_ele = int(round(data_ele[-1])) | |
1442 | #print(data_ele) |
|
1442 | #print(data_ele) | |
1443 | #print(ang_max) |
|
1443 | #print(ang_max) | |
1444 | #print(data_ele_old) |
|
1444 | #print(data_ele_old) | |
1445 | if new_i_ele <= 1: |
|
1445 | if new_i_ele <= 1: | |
1446 | new_i_ele = 1 |
|
1446 | new_i_ele = 1 | |
1447 | if round(data_ele[-1])>=ang_max-1: |
|
1447 | if round(data_ele[-1])>=ang_max-1: | |
1448 | self.data_ele_tmp[val_ch] = numpy.ones(ang_max-ang_min)*numpy.nan |
|
1448 | self.data_ele_tmp[val_ch] = numpy.ones(ang_max-ang_min)*numpy.nan | |
1449 | self.res_weather[val_ch] = self.replaceNAN(data_weather=self.res_weather[val_ch],data_ele=self.data_ele_tmp[val_ch],val=self.val_mean) |
|
1449 | self.res_weather[val_ch] = self.replaceNAN(data_weather=self.res_weather[val_ch],data_ele=self.data_ele_tmp[val_ch],val=self.val_mean) | |
1450 | self.data_ele_tmp[val_ch][new_i_ele-1:new_i_ele+len(data_ele)-1]=data_ele_old |
|
1450 | self.data_ele_tmp[val_ch][new_i_ele-1:new_i_ele+len(data_ele)-1]=data_ele_old | |
1451 | self.res_ele[new_i_ele-1:new_i_ele+len(data_ele)-1]= data_ele |
|
1451 | self.res_ele[new_i_ele-1:new_i_ele+len(data_ele)-1]= data_ele | |
1452 | self.res_weather[val_ch][new_i_ele-1:new_i_ele+len(data_ele)-1,:]= data_weather |
|
1452 | self.res_weather[val_ch][new_i_ele-1:new_i_ele+len(data_ele)-1,:]= data_weather | |
1453 | data_ele = self.res_ele |
|
1453 | data_ele = self.res_ele | |
1454 | data_weather = self.res_weather[val_ch] |
|
1454 | data_weather = self.res_weather[val_ch] | |
1455 |
|
1455 | |||
1456 | elif tipo_case==2: #bajada |
|
1456 | elif tipo_case==2: #bajada | |
1457 | vec = numpy.where(data_ele<ang_max) |
|
1457 | vec = numpy.where(data_ele<ang_max) | |
1458 | data_ele = data_ele[vec] |
|
1458 | data_ele = data_ele[vec] | |
1459 | data_weather= data_weather[vec[0]] |
|
1459 | data_weather= data_weather[vec[0]] | |
1460 |
|
1460 | |||
1461 | len_vec = len(vec) |
|
1461 | len_vec = len(vec) | |
1462 | data_ele_new = data_ele[::-1] # reversa |
|
1462 | data_ele_new = data_ele[::-1] # reversa | |
1463 | data_weather = data_weather[::-1,:] |
|
1463 | data_weather = data_weather[::-1,:] | |
1464 | new_i_ele = int(data_ele_new[0]) |
|
1464 | new_i_ele = int(data_ele_new[0]) | |
1465 | new_f_ele = int(data_ele_new[-1]) |
|
1465 | new_f_ele = int(data_ele_new[-1]) | |
1466 |
|
1466 | |||
1467 | n1= new_i_ele- ang_min |
|
1467 | n1= new_i_ele- ang_min | |
1468 | n2= ang_max - new_f_ele-1 |
|
1468 | n2= ang_max - new_f_ele-1 | |
1469 | if n1>0: |
|
1469 | if n1>0: | |
1470 | ele1= numpy.linspace(ang_min+1,new_i_ele-1,n1) |
|
1470 | ele1= numpy.linspace(ang_min+1,new_i_ele-1,n1) | |
1471 | ele1_nan= numpy.ones(n1)*numpy.nan |
|
1471 | ele1_nan= numpy.ones(n1)*numpy.nan | |
1472 | data_ele = numpy.hstack((ele1,data_ele_new)) |
|
1472 | data_ele = numpy.hstack((ele1,data_ele_new)) | |
1473 | data_ele_old = numpy.hstack((ele1_nan,data_ele_new)) |
|
1473 | data_ele_old = numpy.hstack((ele1_nan,data_ele_new)) | |
1474 | if n2>0: |
|
1474 | if n2>0: | |
1475 | ele2= numpy.linspace(new_f_ele+1,ang_max,n2) |
|
1475 | ele2= numpy.linspace(new_f_ele+1,ang_max,n2) | |
1476 | ele2_nan= numpy.ones(n2)*numpy.nan |
|
1476 | ele2_nan= numpy.ones(n2)*numpy.nan | |
1477 | data_ele = numpy.hstack((data_ele,ele2)) |
|
1477 | data_ele = numpy.hstack((data_ele,ele2)) | |
1478 | data_ele_old = numpy.hstack((data_ele_old,ele2_nan)) |
|
1478 | data_ele_old = numpy.hstack((data_ele_old,ele2_nan)) | |
1479 |
|
1479 | |||
1480 | self.data_ele_tmp[val_ch] = data_ele_old |
|
1480 | self.data_ele_tmp[val_ch] = data_ele_old | |
1481 | self.res_ele = data_ele |
|
1481 | self.res_ele = data_ele | |
1482 | self.res_weather[val_ch] = self.replaceNAN(data_weather=data_weather,data_ele=data_ele_old,val=self.val_mean) |
|
1482 | self.res_weather[val_ch] = self.replaceNAN(data_weather=data_weather,data_ele=data_ele_old,val=self.val_mean) | |
1483 | data_ele = self.res_ele |
|
1483 | data_ele = self.res_ele | |
1484 | data_weather = self.res_weather[val_ch] |
|
1484 | data_weather = self.res_weather[val_ch] | |
1485 |
|
1485 | |||
1486 | elif tipo_case==3:#subida |
|
1486 | elif tipo_case==3:#subida | |
1487 | vec = numpy.where(0<data_ele) |
|
1487 | vec = numpy.where(0<data_ele) | |
1488 | data_ele= data_ele[vec] |
|
1488 | data_ele= data_ele[vec] | |
1489 | data_ele_new = data_ele |
|
1489 | data_ele_new = data_ele | |
1490 | data_ele_old= data_ele_old[vec] |
|
1490 | data_ele_old= data_ele_old[vec] | |
1491 | data_weather= data_weather[vec[0]] |
|
1491 | data_weather= data_weather[vec[0]] | |
1492 | pos_ini = numpy.argmin(data_ele) |
|
1492 | pos_ini = numpy.argmin(data_ele) | |
1493 | if pos_ini>0: |
|
1493 | if pos_ini>0: | |
1494 | len_vec= len(data_ele) |
|
1494 | len_vec= len(data_ele) | |
1495 | vec3 = numpy.linspace(pos_ini,len_vec-1,len_vec-pos_ini).astype(int) |
|
1495 | vec3 = numpy.linspace(pos_ini,len_vec-1,len_vec-pos_ini).astype(int) | |
1496 | #print(vec3) |
|
1496 | #print(vec3) | |
1497 | data_ele= data_ele[vec3] |
|
1497 | data_ele= data_ele[vec3] | |
1498 | data_ele_new = data_ele |
|
1498 | data_ele_new = data_ele | |
1499 | data_ele_old= data_ele_old[vec3] |
|
1499 | data_ele_old= data_ele_old[vec3] | |
1500 | data_weather= data_weather[vec3] |
|
1500 | data_weather= data_weather[vec3] | |
1501 |
|
1501 | |||
1502 | new_i_ele = int(data_ele_new[0]) |
|
1502 | new_i_ele = int(data_ele_new[0]) | |
1503 | new_f_ele = int(data_ele_new[-1]) |
|
1503 | new_f_ele = int(data_ele_new[-1]) | |
1504 | n1= new_i_ele- ang_min |
|
1504 | n1= new_i_ele- ang_min | |
1505 | n2= ang_max - new_f_ele-1 |
|
1505 | n2= ang_max - new_f_ele-1 | |
1506 | if n1>0: |
|
1506 | if n1>0: | |
1507 | ele1= numpy.linspace(ang_min+1,new_i_ele-1,n1) |
|
1507 | ele1= numpy.linspace(ang_min+1,new_i_ele-1,n1) | |
1508 | ele1_nan= numpy.ones(n1)*numpy.nan |
|
1508 | ele1_nan= numpy.ones(n1)*numpy.nan | |
1509 | data_ele = numpy.hstack((ele1,data_ele_new)) |
|
1509 | data_ele = numpy.hstack((ele1,data_ele_new)) | |
1510 | data_ele_old = numpy.hstack((ele1_nan,data_ele_new)) |
|
1510 | data_ele_old = numpy.hstack((ele1_nan,data_ele_new)) | |
1511 | if n2>0: |
|
1511 | if n2>0: | |
1512 | ele2= numpy.linspace(new_f_ele+1,ang_max,n2) |
|
1512 | ele2= numpy.linspace(new_f_ele+1,ang_max,n2) | |
1513 | ele2_nan= numpy.ones(n2)*numpy.nan |
|
1513 | ele2_nan= numpy.ones(n2)*numpy.nan | |
1514 | data_ele = numpy.hstack((data_ele,ele2)) |
|
1514 | data_ele = numpy.hstack((data_ele,ele2)) | |
1515 | data_ele_old = numpy.hstack((data_ele_old,ele2_nan)) |
|
1515 | data_ele_old = numpy.hstack((data_ele_old,ele2_nan)) | |
1516 |
|
1516 | |||
1517 | self.data_ele_tmp[val_ch] = data_ele_old |
|
1517 | self.data_ele_tmp[val_ch] = data_ele_old | |
1518 | self.res_ele = data_ele |
|
1518 | self.res_ele = data_ele | |
1519 | self.res_weather[val_ch] = self.replaceNAN(data_weather=data_weather,data_ele=data_ele_old,val=self.val_mean) |
|
1519 | self.res_weather[val_ch] = self.replaceNAN(data_weather=data_weather,data_ele=data_ele_old,val=self.val_mean) | |
1520 | data_ele = self.res_ele |
|
1520 | data_ele = self.res_ele | |
1521 | data_weather = self.res_weather[val_ch] |
|
1521 | data_weather = self.res_weather[val_ch] | |
1522 | #print("self.data_ele_tmp",self.data_ele_tmp) |
|
1522 | #print("self.data_ele_tmp",self.data_ele_tmp) | |
1523 | return data_weather,data_ele |
|
1523 | return data_weather,data_ele | |
1524 |
|
1524 | |||
1525 |
|
1525 | |||
1526 | def plot(self): |
|
1526 | def plot(self): | |
1527 | thisDatetime = datetime.datetime.utcfromtimestamp(self.data.times[-1]).strftime('%Y-%m-%d %H:%M:%S') |
|
1527 | thisDatetime = datetime.datetime.utcfromtimestamp(self.data.times[-1]).strftime('%Y-%m-%d %H:%M:%S') | |
1528 | data = self.data[-1] |
|
1528 | data = self.data[-1] | |
1529 | r = self.data.yrange |
|
1529 | r = self.data.yrange | |
1530 | delta_height = r[1]-r[0] |
|
1530 | delta_height = r[1]-r[0] | |
1531 | r_mask = numpy.where(r>=0)[0] |
|
1531 | r_mask = numpy.where(r>=0)[0] | |
1532 | ##print("delta_height",delta_height) |
|
1532 | ##print("delta_height",delta_height) | |
1533 | #print("r_mask",r_mask,len(r_mask)) |
|
1533 | #print("r_mask",r_mask,len(r_mask)) | |
1534 | r = numpy.arange(len(r_mask))*delta_height |
|
1534 | r = numpy.arange(len(r_mask))*delta_height | |
1535 | self.y = 2*r |
|
1535 | self.y = 2*r | |
1536 | res = 1 |
|
1536 | res = 1 | |
1537 | ###print("data['weather'].shape[0]",data['weather'].shape[0]) |
|
1537 | ###print("data['weather'].shape[0]",data['weather'].shape[0]) | |
1538 | ang_max = self.ang_max |
|
1538 | ang_max = self.ang_max | |
1539 | ang_min = self.ang_min |
|
1539 | ang_min = self.ang_min | |
1540 | var_ang =ang_max - ang_min |
|
1540 | var_ang =ang_max - ang_min | |
1541 | step = (int(var_ang)/(res*data['weather'].shape[0])) |
|
1541 | step = (int(var_ang)/(res*data['weather'].shape[0])) | |
1542 | ###print("step",step) |
|
1542 | ###print("step",step) | |
1543 | #-------------------------------------------------------- |
|
1543 | #-------------------------------------------------------- | |
1544 | ##print('weather',data['weather'].shape) |
|
1544 | ##print('weather',data['weather'].shape) | |
1545 | ##print('ele',data['ele'].shape) |
|
1545 | ##print('ele',data['ele'].shape) | |
1546 |
|
1546 | |||
1547 | ###self.res_weather, self.res_ele = self.const_ploteo(data_weather=data['weather'][:,r_mask],data_ele=data['ele'],step=step,res=res,ang_max=ang_max,ang_min=ang_min) |
|
1547 | ###self.res_weather, self.res_ele = self.const_ploteo(data_weather=data['weather'][:,r_mask],data_ele=data['ele'],step=step,res=res,ang_max=ang_max,ang_min=ang_min) | |
1548 | ###self.res_azi = numpy.mean(data['azi']) |
|
1548 | ###self.res_azi = numpy.mean(data['azi']) | |
1549 | ###print("self.res_ele",self.res_ele) |
|
1549 | ###print("self.res_ele",self.res_ele) | |
1550 | plt.clf() |
|
1550 | plt.clf() | |
1551 | subplots = [121, 122] |
|
1551 | subplots = [121, 122] | |
1552 | try: |
|
1552 | try: | |
1553 | if self.data[-2]['ele'].max()<data['ele'].max(): |
|
1553 | if self.data[-2]['ele'].max()<data['ele'].max(): | |
1554 | self.ini=0 |
|
1554 | self.ini=0 | |
1555 | except: |
|
1555 | except: | |
1556 | pass |
|
1556 | pass | |
1557 | if self.ini==0: |
|
1557 | if self.ini==0: | |
1558 | self.data_ele_tmp = numpy.ones([self.nplots,int(var_ang)])*numpy.nan |
|
1558 | self.data_ele_tmp = numpy.ones([self.nplots,int(var_ang)])*numpy.nan | |
1559 | self.res_weather= numpy.ones([self.nplots,int(var_ang),len(r_mask)])*numpy.nan |
|
1559 | self.res_weather= numpy.ones([self.nplots,int(var_ang),len(r_mask)])*numpy.nan | |
1560 | print("SHAPE",self.data_ele_tmp.shape) |
|
1560 | print("SHAPE",self.data_ele_tmp.shape) | |
1561 |
|
1561 | |||
1562 | for i,ax in enumerate(self.axes): |
|
1562 | for i,ax in enumerate(self.axes): | |
1563 | self.res_weather[i], self.res_ele = self.const_ploteo(val_ch=i, data_weather=data['weather'][i][:,r_mask],data_ele=data['ele'],step=step,res=res,ang_max=ang_max,ang_min=ang_min,case_flag=self.data['case_flag']) |
|
1563 | self.res_weather[i], self.res_ele = self.const_ploteo(val_ch=i, data_weather=data['weather'][i][:,r_mask],data_ele=data['ele'],step=step,res=res,ang_max=ang_max,ang_min=ang_min,case_flag=self.data['case_flag']) | |
1564 | self.res_azi = numpy.mean(data['azi']) |
|
1564 | self.res_azi = numpy.mean(data['azi']) | |
1565 |
|
1565 | |||
1566 | if ax.firsttime: |
|
1566 | if ax.firsttime: | |
1567 | #plt.clf() |
|
1567 | #plt.clf() | |
1568 | print("Frist Plot") |
|
1568 | print("Frist Plot") | |
1569 | cgax, pm = wrl.vis.plot_rhi(self.res_weather[i],r=r,th=self.res_ele,ax=subplots[i], proj='cg',vmin=20, vmax=80) |
|
1569 | cgax, pm = wrl.vis.plot_rhi(self.res_weather[i],r=r,th=self.res_ele,ax=subplots[i], proj='cg',vmin=20, vmax=80) | |
1570 | #fig=self.figures[0] |
|
1570 | #fig=self.figures[0] | |
1571 | else: |
|
1571 | else: | |
1572 | #plt.clf() |
|
1572 | #plt.clf() | |
1573 | print("ELSE PLOT") |
|
1573 | print("ELSE PLOT") | |
1574 | cgax, pm = wrl.vis.plot_rhi(self.res_weather[i],r=r,th=self.res_ele,ax=subplots[i], proj='cg',vmin=20, vmax=80) |
|
1574 | cgax, pm = wrl.vis.plot_rhi(self.res_weather[i],r=r,th=self.res_ele,ax=subplots[i], proj='cg',vmin=20, vmax=80) | |
1575 | caax = cgax.parasites[0] |
|
1575 | caax = cgax.parasites[0] | |
1576 | paax = cgax.parasites[1] |
|
1576 | paax = cgax.parasites[1] | |
1577 | cbar = plt.gcf().colorbar(pm, pad=0.075) |
|
1577 | cbar = plt.gcf().colorbar(pm, pad=0.075) | |
1578 | caax.set_xlabel('x_range [km]') |
|
1578 | caax.set_xlabel('x_range [km]') | |
1579 | caax.set_ylabel('y_range [km]') |
|
1579 | caax.set_ylabel('y_range [km]') | |
1580 | plt.text(1.0, 1.05, 'Elevacion '+str(thisDatetime)+" Step "+str(self.ini)+ " Azi: "+str(round(self.res_azi,2)), transform=caax.transAxes, va='bottom',ha='right') |
|
1580 | plt.text(1.0, 1.05, 'Elevacion '+str(thisDatetime)+" Step "+str(self.ini)+ " Azi: "+str(round(self.res_azi,2)), transform=caax.transAxes, va='bottom',ha='right') | |
1581 | print("***************************self.ini****************************",self.ini) |
|
1581 | print("***************************self.ini****************************",self.ini) | |
1582 | self.ini= self.ini+1 |
|
1582 | self.ini= self.ini+1 | |
1583 |
|
1583 | |||
1584 | class WeatherRHI_vRF_Plot(Plot): |
|
1584 | class WeatherRHI_vRF_Plot(Plot): | |
1585 | CODE = 'weather' |
|
1585 | CODE = 'weather' | |
1586 | plot_name = 'weather' |
|
1586 | plot_name = 'weather' | |
1587 | plot_type = 'rhistyle' |
|
1587 | plot_type = 'rhistyle' | |
1588 | buffering = False |
|
1588 | buffering = False | |
1589 | data_ele_tmp = None |
|
1589 | data_ele_tmp = None | |
1590 |
|
1590 | |||
1591 | def setup(self): |
|
1591 | def setup(self): | |
1592 | print("********************") |
|
1592 | print("********************") | |
1593 | print("********************") |
|
1593 | print("********************") | |
1594 | print("********************") |
|
1594 | print("********************") | |
1595 | print("SETUP WEATHER PLOT") |
|
1595 | print("SETUP WEATHER PLOT") | |
1596 | self.ncols = 1 |
|
1596 | self.ncols = 1 | |
1597 | self.nrows = 1 |
|
1597 | self.nrows = 1 | |
1598 | self.nplots= 1 |
|
1598 | self.nplots= 1 | |
1599 | self.ylabel= 'Range [Km]' |
|
1599 | self.ylabel= 'Range [Km]' | |
1600 | self.titles= ['Weather'] |
|
1600 | self.titles= ['Weather'] | |
1601 | if self.channels is not None: |
|
1601 | if self.channels is not None: | |
1602 | self.nplots = len(self.channels) |
|
1602 | self.nplots = len(self.channels) | |
1603 | self.nrows = len(self.channels) |
|
1603 | self.nrows = len(self.channels) | |
1604 | else: |
|
1604 | else: | |
1605 | self.nplots = self.data.shape(self.CODE)[0] |
|
1605 | self.nplots = self.data.shape(self.CODE)[0] | |
1606 | self.nrows = self.nplots |
|
1606 | self.nrows = self.nplots | |
1607 | self.channels = list(range(self.nplots)) |
|
1607 | self.channels = list(range(self.nplots)) | |
1608 | print("channels",self.channels) |
|
1608 | print("channels",self.channels) | |
1609 | print("que saldra", self.data.shape(self.CODE)[0]) |
|
1609 | print("que saldra", self.data.shape(self.CODE)[0]) | |
1610 | self.titles = ['{} Channel {}'.format(self.CODE.upper(), x) for x in range(self.nrows)] |
|
1610 | self.titles = ['{} Channel {}'.format(self.CODE.upper(), x) for x in range(self.nrows)] | |
1611 | print("self.titles",self.titles) |
|
1611 | print("self.titles",self.titles) | |
1612 | self.colorbar=False |
|
1612 | self.colorbar=False | |
1613 | self.width =8 |
|
1613 | self.width =8 | |
1614 | self.height =8 |
|
1614 | self.height =8 | |
1615 | self.ini =0 |
|
1615 | self.ini =0 | |
1616 | self.len_azi =0 |
|
1616 | self.len_azi =0 | |
1617 | self.buffer_ini = None |
|
1617 | self.buffer_ini = None | |
1618 | self.buffer_ele = None |
|
1618 | self.buffer_ele = None | |
1619 | self.plots_adjust.update({'wspace': 0.4, 'hspace':0.4, 'left': 0.1, 'right': 0.9, 'bottom': 0.08}) |
|
1619 | self.plots_adjust.update({'wspace': 0.4, 'hspace':0.4, 'left': 0.1, 'right': 0.9, 'bottom': 0.08}) | |
1620 | self.flag =0 |
|
1620 | self.flag =0 | |
1621 | self.indicador= 0 |
|
1621 | self.indicador= 0 | |
1622 | self.last_data_ele = None |
|
1622 | self.last_data_ele = None | |
1623 | self.val_mean = None |
|
1623 | self.val_mean = None | |
1624 |
|
1624 | |||
1625 | def update(self, dataOut): |
|
1625 | def update(self, dataOut): | |
1626 |
|
1626 | |||
1627 | data = {} |
|
1627 | data = {} | |
1628 | meta = {} |
|
1628 | meta = {} | |
1629 | if hasattr(dataOut, 'dataPP_POWER'): |
|
1629 | if hasattr(dataOut, 'dataPP_POWER'): | |
1630 | factor = 1 |
|
1630 | factor = 1 | |
1631 | if hasattr(dataOut, 'nFFTPoints'): |
|
1631 | if hasattr(dataOut, 'nFFTPoints'): | |
1632 | factor = dataOut.normFactor |
|
1632 | factor = dataOut.normFactor | |
1633 | print("dataOut",dataOut.data_360.shape) |
|
1633 | print("dataOut",dataOut.data_360.shape) | |
1634 | # |
|
1634 | # | |
1635 | data['weather'] = 10*numpy.log10(dataOut.data_360/(factor)) |
|
1635 | data['weather'] = 10*numpy.log10(dataOut.data_360/(factor)) | |
1636 | # |
|
1636 | # | |
1637 | #data['weather'] = 10*numpy.log10(dataOut.data_360[1]/(factor)) |
|
1637 | #data['weather'] = 10*numpy.log10(dataOut.data_360[1]/(factor)) | |
1638 | data['azi'] = dataOut.data_azi |
|
1638 | data['azi'] = dataOut.data_azi | |
1639 | data['ele'] = dataOut.data_ele |
|
1639 | data['ele'] = dataOut.data_ele | |
1640 | data['case_flag'] = dataOut.case_flag |
|
1640 | data['case_flag'] = dataOut.case_flag | |
1641 | #print("UPDATE") |
|
1641 | #print("UPDATE") | |
1642 | #print("data[weather]",data['weather'].shape) |
|
1642 | #print("data[weather]",data['weather'].shape) | |
1643 | #print("data[azi]",data['azi']) |
|
1643 | #print("data[azi]",data['azi']) | |
1644 | return data, meta |
|
1644 | return data, meta | |
1645 |
|
1645 | |||
1646 | def get2List(self,angulos): |
|
1646 | def get2List(self,angulos): | |
1647 | list1=[] |
|
1647 | list1=[] | |
1648 | list2=[] |
|
1648 | list2=[] | |
1649 | #print(angulos) |
|
1649 | #print(angulos) | |
1650 | #exit(1) |
|
1650 | #exit(1) | |
1651 | for i in reversed(range(len(angulos))): |
|
1651 | for i in reversed(range(len(angulos))): | |
1652 | if not i==0:#el caso de i=0 evalula el primero de la lista con el ultimo y no es relevante |
|
1652 | if not i==0:#el caso de i=0 evalula el primero de la lista con el ultimo y no es relevante | |
1653 | diff_ = angulos[i]-angulos[i-1] |
|
1653 | diff_ = angulos[i]-angulos[i-1] | |
1654 | if abs(diff_) >1.5: |
|
1654 | if abs(diff_) >1.5: | |
1655 | list1.append(i-1) |
|
1655 | list1.append(i-1) | |
1656 | list2.append(diff_) |
|
1656 | list2.append(diff_) | |
1657 | return list(reversed(list1)),list(reversed(list2)) |
|
1657 | return list(reversed(list1)),list(reversed(list2)) | |
1658 |
|
1658 | |||
1659 | def fixData90(self,list_,ang_): |
|
1659 | def fixData90(self,list_,ang_): | |
1660 | if list_[0]==-1: |
|
1660 | if list_[0]==-1: | |
1661 | vec = numpy.where(ang_<ang_[0]) |
|
1661 | vec = numpy.where(ang_<ang_[0]) | |
1662 | ang_[vec] = ang_[vec]+90 |
|
1662 | ang_[vec] = ang_[vec]+90 | |
1663 | return ang_ |
|
1663 | return ang_ | |
1664 | return ang_ |
|
1664 | return ang_ | |
1665 |
|
1665 | |||
1666 | def fixData90HL(self,angulos): |
|
1666 | def fixData90HL(self,angulos): | |
1667 | vec = numpy.where(angulos>=90) |
|
1667 | vec = numpy.where(angulos>=90) | |
1668 | angulos[vec]=angulos[vec]-90 |
|
1668 | angulos[vec]=angulos[vec]-90 | |
1669 | return angulos |
|
1669 | return angulos | |
1670 |
|
1670 | |||
1671 |
|
1671 | |||
1672 | def search_pos(self,pos,list_): |
|
1672 | def search_pos(self,pos,list_): | |
1673 | for i in range(len(list_)): |
|
1673 | for i in range(len(list_)): | |
1674 | if pos == list_[i]: |
|
1674 | if pos == list_[i]: | |
1675 | return True,i |
|
1675 | return True,i | |
1676 | i=None |
|
1676 | i=None | |
1677 | return False,i |
|
1677 | return False,i | |
1678 |
|
1678 | |||
1679 | def fixDataComp(self,ang_,list1_,list2_,tipo_case): |
|
1679 | def fixDataComp(self,ang_,list1_,list2_,tipo_case): | |
1680 | size = len(ang_) |
|
1680 | size = len(ang_) | |
1681 | size2 = 0 |
|
1681 | size2 = 0 | |
1682 | for i in range(len(list2_)): |
|
1682 | for i in range(len(list2_)): | |
1683 | size2=size2+round(abs(list2_[i]))-1 |
|
1683 | size2=size2+round(abs(list2_[i]))-1 | |
1684 | new_size= size+size2 |
|
1684 | new_size= size+size2 | |
1685 | ang_new = numpy.zeros(new_size) |
|
1685 | ang_new = numpy.zeros(new_size) | |
1686 | ang_new2 = numpy.zeros(new_size) |
|
1686 | ang_new2 = numpy.zeros(new_size) | |
1687 |
|
1687 | |||
1688 | tmp = 0 |
|
1688 | tmp = 0 | |
1689 | c = 0 |
|
1689 | c = 0 | |
1690 | for i in range(len(ang_)): |
|
1690 | for i in range(len(ang_)): | |
1691 | ang_new[tmp +c] = ang_[i] |
|
1691 | ang_new[tmp +c] = ang_[i] | |
1692 | ang_new2[tmp+c] = ang_[i] |
|
1692 | ang_new2[tmp+c] = ang_[i] | |
1693 | condition , value = self.search_pos(i,list1_) |
|
1693 | condition , value = self.search_pos(i,list1_) | |
1694 | if condition: |
|
1694 | if condition: | |
1695 | pos = tmp + c + 1 |
|
1695 | pos = tmp + c + 1 | |
1696 | for k in range(round(abs(list2_[value]))-1): |
|
1696 | for k in range(round(abs(list2_[value]))-1): | |
1697 | if tipo_case==0 or tipo_case==3:#subida |
|
1697 | if tipo_case==0 or tipo_case==3:#subida | |
1698 | ang_new[pos+k] = ang_new[pos+k-1]+1 |
|
1698 | ang_new[pos+k] = ang_new[pos+k-1]+1 | |
1699 | ang_new2[pos+k] = numpy.nan |
|
1699 | ang_new2[pos+k] = numpy.nan | |
1700 | elif tipo_case==1 or tipo_case==2:#bajada |
|
1700 | elif tipo_case==1 or tipo_case==2:#bajada | |
1701 | ang_new[pos+k] = ang_new[pos+k-1]-1 |
|
1701 | ang_new[pos+k] = ang_new[pos+k-1]-1 | |
1702 | ang_new2[pos+k] = numpy.nan |
|
1702 | ang_new2[pos+k] = numpy.nan | |
1703 |
|
1703 | |||
1704 | tmp = pos +k |
|
1704 | tmp = pos +k | |
1705 | c = 0 |
|
1705 | c = 0 | |
1706 | c=c+1 |
|
1706 | c=c+1 | |
1707 | return ang_new,ang_new2 |
|
1707 | return ang_new,ang_new2 | |
1708 |
|
1708 | |||
1709 | def globalCheckPED(self,angulos,tipo_case): |
|
1709 | def globalCheckPED(self,angulos,tipo_case): | |
1710 | l1,l2 = self.get2List(angulos) |
|
1710 | l1,l2 = self.get2List(angulos) | |
1711 | print("l1",l1) |
|
1711 | print("l1",l1) | |
1712 | print("l2",l2) |
|
1712 | print("l2",l2) | |
1713 | if len(l1)>0: |
|
1713 | if len(l1)>0: | |
1714 | #angulos2 = self.fixData90(list_=l1,ang_=angulos) |
|
1714 | #angulos2 = self.fixData90(list_=l1,ang_=angulos) | |
1715 | #l1,l2 = self.get2List(angulos2) |
|
1715 | #l1,l2 = self.get2List(angulos2) | |
1716 | ang1_,ang2_ = self.fixDataComp(ang_=angulos,list1_=l1,list2_=l2,tipo_case=tipo_case) |
|
1716 | ang1_,ang2_ = self.fixDataComp(ang_=angulos,list1_=l1,list2_=l2,tipo_case=tipo_case) | |
1717 | #ang1_ = self.fixData90HL(ang1_) |
|
1717 | #ang1_ = self.fixData90HL(ang1_) | |
1718 | #ang2_ = self.fixData90HL(ang2_) |
|
1718 | #ang2_ = self.fixData90HL(ang2_) | |
1719 | else: |
|
1719 | else: | |
1720 | ang1_= angulos |
|
1720 | ang1_= angulos | |
1721 | ang2_= angulos |
|
1721 | ang2_= angulos | |
1722 | return ang1_,ang2_ |
|
1722 | return ang1_,ang2_ | |
1723 |
|
1723 | |||
1724 |
|
1724 | |||
1725 | def replaceNAN(self,data_weather,data_ele,val): |
|
1725 | def replaceNAN(self,data_weather,data_ele,val): | |
1726 | data= data_ele |
|
1726 | data= data_ele | |
1727 | data_T= data_weather |
|
1727 | data_T= data_weather | |
1728 | #print(data.shape[0]) |
|
1728 | #print(data.shape[0]) | |
1729 | #print(data_T.shape[0]) |
|
1729 | #print(data_T.shape[0]) | |
1730 | #exit(1) |
|
1730 | #exit(1) | |
1731 | if data.shape[0]> data_T.shape[0]: |
|
1731 | if data.shape[0]> data_T.shape[0]: | |
1732 | data_N = numpy.ones( [data.shape[0],data_T.shape[1]]) |
|
1732 | data_N = numpy.ones( [data.shape[0],data_T.shape[1]]) | |
1733 | c = 0 |
|
1733 | c = 0 | |
1734 | for i in range(len(data)): |
|
1734 | for i in range(len(data)): | |
1735 | if numpy.isnan(data[i]): |
|
1735 | if numpy.isnan(data[i]): | |
1736 | data_N[i,:]=numpy.ones(data_T.shape[1])*numpy.nan |
|
1736 | data_N[i,:]=numpy.ones(data_T.shape[1])*numpy.nan | |
1737 | else: |
|
1737 | else: | |
1738 | data_N[i,:]=data_T[c,:] |
|
1738 | data_N[i,:]=data_T[c,:] | |
1739 | c=c+1 |
|
1739 | c=c+1 | |
1740 | return data_N |
|
1740 | return data_N | |
1741 | else: |
|
1741 | else: | |
1742 | for i in range(len(data)): |
|
1742 | for i in range(len(data)): | |
1743 | if numpy.isnan(data[i]): |
|
1743 | if numpy.isnan(data[i]): | |
1744 | data_T[i,:]=numpy.ones(data_T.shape[1])*numpy.nan |
|
1744 | data_T[i,:]=numpy.ones(data_T.shape[1])*numpy.nan | |
1745 | return data_T |
|
1745 | return data_T | |
1746 |
|
1746 | |||
1747 |
|
1747 | |||
1748 | def const_ploteo(self,val_ch,data_weather,data_ele,step,res,ang_max,ang_min,case_flag): |
|
1748 | def const_ploteo(self,val_ch,data_weather,data_ele,step,res,ang_max,ang_min,case_flag): | |
1749 | ang_max= ang_max |
|
1749 | ang_max= ang_max | |
1750 | ang_min= ang_min |
|
1750 | ang_min= ang_min | |
1751 | data_weather=data_weather |
|
1751 | data_weather=data_weather | |
1752 | val_ch=val_ch |
|
1752 | val_ch=val_ch | |
1753 | ##print("*********************DATA WEATHER**************************************") |
|
1753 | ##print("*********************DATA WEATHER**************************************") | |
1754 | ##print(data_weather) |
|
1754 | ##print(data_weather) | |
1755 |
|
1755 | |||
1756 | ''' |
|
1756 | ''' | |
1757 | print("**********************************************") |
|
1757 | print("**********************************************") | |
1758 | print("**********************************************") |
|
1758 | print("**********************************************") | |
1759 | print("***************ini**************") |
|
1759 | print("***************ini**************") | |
1760 | print("**********************************************") |
|
1760 | print("**********************************************") | |
1761 | print("**********************************************") |
|
1761 | print("**********************************************") | |
1762 | ''' |
|
1762 | ''' | |
1763 | #print("data_ele",data_ele) |
|
1763 | #print("data_ele",data_ele) | |
1764 | #---------------------------------------------------------- |
|
1764 | #---------------------------------------------------------- | |
1765 |
|
1765 | |||
1766 | #exit(1) |
|
1766 | #exit(1) | |
1767 | tipo_case = case_flag[-1] |
|
1767 | tipo_case = case_flag[-1] | |
1768 | print("tipo_case",tipo_case) |
|
1768 | print("tipo_case",tipo_case) | |
1769 | #--------------------- new ------------------------- |
|
1769 | #--------------------- new ------------------------- | |
1770 | data_ele_new ,data_ele_old= self.globalCheckPED(data_ele,tipo_case) |
|
1770 | data_ele_new ,data_ele_old= self.globalCheckPED(data_ele,tipo_case) | |
1771 |
|
1771 | |||
1772 | #-------------------------CAMBIOS RHI--------------------------------- |
|
1772 | #-------------------------CAMBIOS RHI--------------------------------- | |
1773 |
|
1773 | |||
1774 | vec = numpy.where(data_ele<ang_max) |
|
1774 | vec = numpy.where(data_ele<ang_max) | |
1775 | data_ele = data_ele[vec] |
|
1775 | data_ele = data_ele[vec] | |
1776 | data_weather= data_weather[vec[0]] |
|
1776 | data_weather= data_weather[vec[0]] | |
1777 |
|
1777 | |||
1778 | len_vec = len(vec) |
|
1778 | len_vec = len(vec) | |
1779 | data_ele_new = data_ele[::-1] # reversa |
|
1779 | data_ele_new = data_ele[::-1] # reversa | |
1780 | data_weather = data_weather[::-1,:] |
|
1780 | data_weather = data_weather[::-1,:] | |
1781 | new_i_ele = int(data_ele_new[0]) |
|
1781 | new_i_ele = int(data_ele_new[0]) | |
1782 | new_f_ele = int(data_ele_new[-1]) |
|
1782 | new_f_ele = int(data_ele_new[-1]) | |
1783 |
|
1783 | |||
1784 | n1= new_i_ele- ang_min |
|
1784 | n1= new_i_ele- ang_min | |
1785 | n2= ang_max - new_f_ele-1 |
|
1785 | n2= ang_max - new_f_ele-1 | |
1786 | if n1>0: |
|
1786 | if n1>0: | |
1787 | ele1= numpy.linspace(ang_min+1,new_i_ele-1,n1) |
|
1787 | ele1= numpy.linspace(ang_min+1,new_i_ele-1,n1) | |
1788 | ele1_nan= numpy.ones(n1)*numpy.nan |
|
1788 | ele1_nan= numpy.ones(n1)*numpy.nan | |
1789 | data_ele = numpy.hstack((ele1,data_ele_new)) |
|
1789 | data_ele = numpy.hstack((ele1,data_ele_new)) | |
1790 | data_ele_old = numpy.hstack((ele1_nan,data_ele_new)) |
|
1790 | data_ele_old = numpy.hstack((ele1_nan,data_ele_new)) | |
1791 | if n2>0: |
|
1791 | if n2>0: | |
1792 | ele2= numpy.linspace(new_f_ele+1,ang_max,n2) |
|
1792 | ele2= numpy.linspace(new_f_ele+1,ang_max,n2) | |
1793 | ele2_nan= numpy.ones(n2)*numpy.nan |
|
1793 | ele2_nan= numpy.ones(n2)*numpy.nan | |
1794 | data_ele = numpy.hstack((data_ele,ele2)) |
|
1794 | data_ele = numpy.hstack((data_ele,ele2)) | |
1795 | data_ele_old = numpy.hstack((data_ele_old,ele2_nan)) |
|
1795 | data_ele_old = numpy.hstack((data_ele_old,ele2_nan)) | |
1796 |
|
1796 | |||
1797 |
|
1797 | |||
1798 | print("ele shape",data_ele.shape) |
|
1798 | print("ele shape",data_ele.shape) | |
1799 | print(data_ele) |
|
1799 | print(data_ele) | |
1800 |
|
1800 | |||
1801 | #print("self.data_ele_tmp",self.data_ele_tmp) |
|
1801 | #print("self.data_ele_tmp",self.data_ele_tmp) | |
1802 | val_mean = numpy.mean(data_weather[:,-1]) |
|
1802 | val_mean = numpy.mean(data_weather[:,-1]) | |
1803 | self.val_mean = val_mean |
|
1803 | self.val_mean = val_mean | |
1804 | data_weather = self.replaceNAN(data_weather=data_weather,data_ele=data_ele_old,val=self.val_mean) |
|
1804 | data_weather = self.replaceNAN(data_weather=data_weather,data_ele=data_ele_old,val=self.val_mean) | |
1805 | self.data_ele_tmp[val_ch]= data_ele_old |
|
1805 | self.data_ele_tmp[val_ch]= data_ele_old | |
1806 |
|
1806 | |||
1807 |
|
1807 | |||
1808 | print("data_weather shape",data_weather.shape) |
|
1808 | print("data_weather shape",data_weather.shape) | |
1809 | print(data_weather) |
|
1809 | print(data_weather) | |
1810 | #exit(1) |
|
1810 | #exit(1) | |
1811 | return data_weather,data_ele |
|
1811 | return data_weather,data_ele | |
1812 |
|
1812 | |||
1813 |
|
1813 | |||
1814 | def plot(self): |
|
1814 | def plot(self): | |
1815 | thisDatetime = datetime.datetime.utcfromtimestamp(self.data.times[-1]).strftime('%Y-%m-%d %H:%M:%S') |
|
1815 | thisDatetime = datetime.datetime.utcfromtimestamp(self.data.times[-1]).strftime('%Y-%m-%d %H:%M:%S') | |
1816 | data = self.data[-1] |
|
1816 | data = self.data[-1] | |
1817 | r = self.data.yrange |
|
1817 | r = self.data.yrange | |
1818 | delta_height = r[1]-r[0] |
|
1818 | delta_height = r[1]-r[0] | |
1819 | r_mask = numpy.where(r>=0)[0] |
|
1819 | r_mask = numpy.where(r>=0)[0] | |
1820 | ##print("delta_height",delta_height) |
|
1820 | ##print("delta_height",delta_height) | |
1821 | #print("r_mask",r_mask,len(r_mask)) |
|
1821 | #print("r_mask",r_mask,len(r_mask)) | |
1822 | r = numpy.arange(len(r_mask))*delta_height |
|
1822 | r = numpy.arange(len(r_mask))*delta_height | |
1823 | self.y = 2*r |
|
1823 | self.y = 2*r | |
1824 | res = 1 |
|
1824 | res = 1 | |
1825 | ###print("data['weather'].shape[0]",data['weather'].shape[0]) |
|
1825 | ###print("data['weather'].shape[0]",data['weather'].shape[0]) | |
1826 | ang_max = self.ang_max |
|
1826 | ang_max = self.ang_max | |
1827 | ang_min = self.ang_min |
|
1827 | ang_min = self.ang_min | |
1828 | var_ang =ang_max - ang_min |
|
1828 | var_ang =ang_max - ang_min | |
1829 | step = (int(var_ang)/(res*data['weather'].shape[0])) |
|
1829 | step = (int(var_ang)/(res*data['weather'].shape[0])) | |
1830 | ###print("step",step) |
|
1830 | ###print("step",step) | |
1831 | #-------------------------------------------------------- |
|
1831 | #-------------------------------------------------------- | |
1832 | ##print('weather',data['weather'].shape) |
|
1832 | ##print('weather',data['weather'].shape) | |
1833 | ##print('ele',data['ele'].shape) |
|
1833 | ##print('ele',data['ele'].shape) | |
1834 |
|
1834 | |||
1835 | ###self.res_weather, self.res_ele = self.const_ploteo(data_weather=data['weather'][:,r_mask],data_ele=data['ele'],step=step,res=res,ang_max=ang_max,ang_min=ang_min) |
|
1835 | ###self.res_weather, self.res_ele = self.const_ploteo(data_weather=data['weather'][:,r_mask],data_ele=data['ele'],step=step,res=res,ang_max=ang_max,ang_min=ang_min) | |
1836 | ###self.res_azi = numpy.mean(data['azi']) |
|
1836 | ###self.res_azi = numpy.mean(data['azi']) | |
1837 | ###print("self.res_ele",self.res_ele) |
|
1837 | ###print("self.res_ele",self.res_ele) | |
1838 | plt.clf() |
|
1838 | plt.clf() | |
1839 | subplots = [121, 122] |
|
1839 | subplots = [121, 122] | |
1840 | if self.ini==0: |
|
1840 | if self.ini==0: | |
1841 | self.data_ele_tmp = numpy.ones([self.nplots,int(var_ang)])*numpy.nan |
|
1841 | self.data_ele_tmp = numpy.ones([self.nplots,int(var_ang)])*numpy.nan | |
1842 | self.res_weather= numpy.ones([self.nplots,int(var_ang),len(r_mask)])*numpy.nan |
|
1842 | self.res_weather= numpy.ones([self.nplots,int(var_ang),len(r_mask)])*numpy.nan | |
1843 | print("SHAPE",self.data_ele_tmp.shape) |
|
1843 | print("SHAPE",self.data_ele_tmp.shape) | |
1844 |
|
1844 | |||
1845 | for i,ax in enumerate(self.axes): |
|
1845 | for i,ax in enumerate(self.axes): | |
1846 | self.res_weather[i], self.res_ele = self.const_ploteo(val_ch=i, data_weather=data['weather'][i][:,r_mask],data_ele=data['ele'],step=step,res=res,ang_max=ang_max,ang_min=ang_min,case_flag=self.data['case_flag']) |
|
1846 | self.res_weather[i], self.res_ele = self.const_ploteo(val_ch=i, data_weather=data['weather'][i][:,r_mask],data_ele=data['ele'],step=step,res=res,ang_max=ang_max,ang_min=ang_min,case_flag=self.data['case_flag']) | |
1847 | self.res_azi = numpy.mean(data['azi']) |
|
1847 | self.res_azi = numpy.mean(data['azi']) | |
1848 |
|
1848 | |||
1849 | print(self.res_ele) |
|
1849 | print(self.res_ele) | |
1850 | #exit(1) |
|
1850 | #exit(1) | |
1851 | if ax.firsttime: |
|
1851 | if ax.firsttime: | |
1852 | #plt.clf() |
|
1852 | #plt.clf() | |
1853 | cgax, pm = wrl.vis.plot_rhi(self.res_weather[i],r=r,th=self.res_ele,ax=subplots[i], proj='cg',vmin=20, vmax=80) |
|
1853 | cgax, pm = wrl.vis.plot_rhi(self.res_weather[i],r=r,th=self.res_ele,ax=subplots[i], proj='cg',vmin=20, vmax=80) | |
1854 | #fig=self.figures[0] |
|
1854 | #fig=self.figures[0] | |
1855 | else: |
|
1855 | else: | |
1856 |
|
1856 | |||
1857 | #plt.clf() |
|
1857 | #plt.clf() | |
1858 | cgax, pm = wrl.vis.plot_rhi(self.res_weather[i],r=r,th=self.res_ele,ax=subplots[i], proj='cg',vmin=20, vmax=80) |
|
1858 | cgax, pm = wrl.vis.plot_rhi(self.res_weather[i],r=r,th=self.res_ele,ax=subplots[i], proj='cg',vmin=20, vmax=80) | |
1859 | caax = cgax.parasites[0] |
|
1859 | caax = cgax.parasites[0] | |
1860 | paax = cgax.parasites[1] |
|
1860 | paax = cgax.parasites[1] | |
1861 | cbar = plt.gcf().colorbar(pm, pad=0.075) |
|
1861 | cbar = plt.gcf().colorbar(pm, pad=0.075) | |
1862 | caax.set_xlabel('x_range [km]') |
|
1862 | caax.set_xlabel('x_range [km]') | |
1863 | caax.set_ylabel('y_range [km]') |
|
1863 | caax.set_ylabel('y_range [km]') | |
1864 | plt.text(1.0, 1.05, 'Elevacion '+str(thisDatetime)+" Step "+str(self.ini)+ " Azi: "+str(round(self.res_azi,2)), transform=caax.transAxes, va='bottom',ha='right') |
|
1864 | plt.text(1.0, 1.05, 'Elevacion '+str(thisDatetime)+" Step "+str(self.ini)+ " Azi: "+str(round(self.res_azi,2)), transform=caax.transAxes, va='bottom',ha='right') | |
1865 | print("***************************self.ini****************************",self.ini) |
|
1865 | print("***************************self.ini****************************",self.ini) | |
1866 | self.ini= self.ini+1 |
|
1866 | self.ini= self.ini+1 | |
1867 |
|
1867 | |||
1868 | class WeatherRHI_vRF3_Plot(Plot): |
|
1868 | class WeatherRHI_vRF3_Plot(Plot): | |
1869 | CODE = 'weather' |
|
1869 | CODE = 'weather' | |
1870 | plot_name = 'weather' |
|
1870 | plot_name = 'weather' | |
1871 | plot_type = 'rhistyle' |
|
1871 | plot_type = 'rhistyle' | |
1872 | buffering = False |
|
1872 | buffering = False | |
1873 | data_ele_tmp = None |
|
1873 | data_ele_tmp = None | |
1874 |
|
1874 | |||
1875 | def setup(self): |
|
1875 | def setup(self): | |
1876 | print("********************") |
|
1876 | print("********************") | |
1877 | print("********************") |
|
1877 | print("********************") | |
1878 | print("********************") |
|
1878 | print("********************") | |
1879 | print("SETUP WEATHER PLOT") |
|
1879 | print("SETUP WEATHER PLOT") | |
1880 | self.ncols = 1 |
|
1880 | self.ncols = 1 | |
1881 | self.nrows = 1 |
|
1881 | self.nrows = 1 | |
1882 | self.nplots= 1 |
|
1882 | self.nplots= 1 | |
1883 | self.ylabel= 'Range [Km]' |
|
1883 | self.ylabel= 'Range [Km]' | |
1884 | self.titles= ['Weather'] |
|
1884 | self.titles= ['Weather'] | |
1885 | if self.channels is not None: |
|
1885 | if self.channels is not None: | |
1886 | self.nplots = len(self.channels) |
|
1886 | self.nplots = len(self.channels) | |
1887 | self.nrows = len(self.channels) |
|
1887 | self.nrows = len(self.channels) | |
1888 | else: |
|
1888 | else: | |
1889 | self.nplots = self.data.shape(self.CODE)[0] |
|
1889 | self.nplots = self.data.shape(self.CODE)[0] | |
1890 | self.nrows = self.nplots |
|
1890 | self.nrows = self.nplots | |
1891 | self.channels = list(range(self.nplots)) |
|
1891 | self.channels = list(range(self.nplots)) | |
1892 | print("channels",self.channels) |
|
1892 | print("channels",self.channels) | |
1893 | print("que saldra", self.data.shape(self.CODE)[0]) |
|
1893 | print("que saldra", self.data.shape(self.CODE)[0]) | |
1894 | self.titles = ['{} Channel {}'.format(self.CODE.upper(), x) for x in range(self.nrows)] |
|
1894 | self.titles = ['{} Channel {}'.format(self.CODE.upper(), x) for x in range(self.nrows)] | |
1895 | print("self.titles",self.titles) |
|
1895 | print("self.titles",self.titles) | |
1896 | self.colorbar=False |
|
1896 | self.colorbar=False | |
1897 | self.width =8 |
|
1897 | self.width =8 | |
1898 | self.height =8 |
|
1898 | self.height =8 | |
1899 | self.ini =0 |
|
1899 | self.ini =0 | |
1900 | self.len_azi =0 |
|
1900 | self.len_azi =0 | |
1901 | self.buffer_ini = None |
|
1901 | self.buffer_ini = None | |
1902 | self.buffer_ele = None |
|
1902 | self.buffer_ele = None | |
1903 | self.plots_adjust.update({'wspace': 0.4, 'hspace':0.4, 'left': 0.1, 'right': 0.9, 'bottom': 0.08}) |
|
1903 | self.plots_adjust.update({'wspace': 0.4, 'hspace':0.4, 'left': 0.1, 'right': 0.9, 'bottom': 0.08}) | |
1904 | self.flag =0 |
|
1904 | self.flag =0 | |
1905 | self.indicador= 0 |
|
1905 | self.indicador= 0 | |
1906 | self.last_data_ele = None |
|
1906 | self.last_data_ele = None | |
1907 | self.val_mean = None |
|
1907 | self.val_mean = None | |
1908 |
|
1908 | |||
1909 | def update(self, dataOut): |
|
1909 | def update(self, dataOut): | |
1910 |
|
1910 | |||
1911 | data = {} |
|
1911 | data = {} | |
1912 | meta = {} |
|
1912 | meta = {} | |
1913 | if hasattr(dataOut, 'dataPP_POWER'): |
|
1913 | if hasattr(dataOut, 'dataPP_POWER'): | |
1914 | factor = 1 |
|
1914 | factor = 1 | |
1915 | if hasattr(dataOut, 'nFFTPoints'): |
|
1915 | if hasattr(dataOut, 'nFFTPoints'): | |
1916 | factor = dataOut.normFactor |
|
1916 | factor = dataOut.normFactor | |
1917 | print("dataOut",dataOut.data_360.shape) |
|
1917 | print("dataOut",dataOut.data_360.shape) | |
1918 | # |
|
1918 | # | |
1919 | data['weather'] = 10*numpy.log10(dataOut.data_360/(factor)) |
|
1919 | data['weather'] = 10*numpy.log10(dataOut.data_360/(factor)) | |
1920 | # |
|
1920 | # | |
1921 | #data['weather'] = 10*numpy.log10(dataOut.data_360[1]/(factor)) |
|
1921 | #data['weather'] = 10*numpy.log10(dataOut.data_360[1]/(factor)) | |
1922 | data['azi'] = dataOut.data_azi |
|
1922 | data['azi'] = dataOut.data_azi | |
1923 | data['ele'] = dataOut.data_ele |
|
1923 | data['ele'] = dataOut.data_ele | |
1924 | #data['case_flag'] = dataOut.case_flag |
|
1924 | #data['case_flag'] = dataOut.case_flag | |
1925 | #print("UPDATE") |
|
1925 | #print("UPDATE") | |
1926 | #print("data[weather]",data['weather'].shape) |
|
1926 | #print("data[weather]",data['weather'].shape) | |
1927 | #print("data[azi]",data['azi']) |
|
1927 | #print("data[azi]",data['azi']) | |
1928 | return data, meta |
|
1928 | return data, meta | |
1929 |
|
1929 | |||
1930 | def get2List(self,angulos): |
|
1930 | def get2List(self,angulos): | |
1931 | list1=[] |
|
1931 | list1=[] | |
1932 | list2=[] |
|
1932 | list2=[] | |
1933 | for i in reversed(range(len(angulos))): |
|
1933 | for i in reversed(range(len(angulos))): | |
1934 | if not i==0:#el caso de i=0 evalula el primero de la lista con el ultimo y no es relevante |
|
1934 | if not i==0:#el caso de i=0 evalula el primero de la lista con el ultimo y no es relevante | |
1935 | diff_ = angulos[i]-angulos[i-1] |
|
1935 | diff_ = angulos[i]-angulos[i-1] | |
1936 | if abs(diff_) >1.5: |
|
1936 | if abs(diff_) >1.5: | |
1937 | list1.append(i-1) |
|
1937 | list1.append(i-1) | |
1938 | list2.append(diff_) |
|
1938 | list2.append(diff_) | |
1939 | return list(reversed(list1)),list(reversed(list2)) |
|
1939 | return list(reversed(list1)),list(reversed(list2)) | |
1940 |
|
1940 | |||
1941 | def fixData90(self,list_,ang_): |
|
1941 | def fixData90(self,list_,ang_): | |
1942 | if list_[0]==-1: |
|
1942 | if list_[0]==-1: | |
1943 | vec = numpy.where(ang_<ang_[0]) |
|
1943 | vec = numpy.where(ang_<ang_[0]) | |
1944 | ang_[vec] = ang_[vec]+90 |
|
1944 | ang_[vec] = ang_[vec]+90 | |
1945 | return ang_ |
|
1945 | return ang_ | |
1946 | return ang_ |
|
1946 | return ang_ | |
1947 |
|
1947 | |||
1948 | def fixData90HL(self,angulos): |
|
1948 | def fixData90HL(self,angulos): | |
1949 | vec = numpy.where(angulos>=90) |
|
1949 | vec = numpy.where(angulos>=90) | |
1950 | angulos[vec]=angulos[vec]-90 |
|
1950 | angulos[vec]=angulos[vec]-90 | |
1951 | return angulos |
|
1951 | return angulos | |
1952 |
|
1952 | |||
1953 |
|
1953 | |||
1954 | def search_pos(self,pos,list_): |
|
1954 | def search_pos(self,pos,list_): | |
1955 | for i in range(len(list_)): |
|
1955 | for i in range(len(list_)): | |
1956 | if pos == list_[i]: |
|
1956 | if pos == list_[i]: | |
1957 | return True,i |
|
1957 | return True,i | |
1958 | i=None |
|
1958 | i=None | |
1959 | return False,i |
|
1959 | return False,i | |
1960 |
|
1960 | |||
1961 | def fixDataComp(self,ang_,list1_,list2_,tipo_case): |
|
1961 | def fixDataComp(self,ang_,list1_,list2_,tipo_case): | |
1962 | size = len(ang_) |
|
1962 | size = len(ang_) | |
1963 | size2 = 0 |
|
1963 | size2 = 0 | |
1964 | for i in range(len(list2_)): |
|
1964 | for i in range(len(list2_)): | |
1965 | size2=size2+round(abs(list2_[i]))-1 |
|
1965 | size2=size2+round(abs(list2_[i]))-1 | |
1966 | new_size= size+size2 |
|
1966 | new_size= size+size2 | |
1967 | ang_new = numpy.zeros(new_size) |
|
1967 | ang_new = numpy.zeros(new_size) | |
1968 | ang_new2 = numpy.zeros(new_size) |
|
1968 | ang_new2 = numpy.zeros(new_size) | |
1969 |
|
1969 | |||
1970 | tmp = 0 |
|
1970 | tmp = 0 | |
1971 | c = 0 |
|
1971 | c = 0 | |
1972 | for i in range(len(ang_)): |
|
1972 | for i in range(len(ang_)): | |
1973 | ang_new[tmp +c] = ang_[i] |
|
1973 | ang_new[tmp +c] = ang_[i] | |
1974 | ang_new2[tmp+c] = ang_[i] |
|
1974 | ang_new2[tmp+c] = ang_[i] | |
1975 | condition , value = self.search_pos(i,list1_) |
|
1975 | condition , value = self.search_pos(i,list1_) | |
1976 | if condition: |
|
1976 | if condition: | |
1977 | pos = tmp + c + 1 |
|
1977 | pos = tmp + c + 1 | |
1978 | for k in range(round(abs(list2_[value]))-1): |
|
1978 | for k in range(round(abs(list2_[value]))-1): | |
1979 | if tipo_case==0 or tipo_case==3:#subida |
|
1979 | if tipo_case==0 or tipo_case==3:#subida | |
1980 | ang_new[pos+k] = ang_new[pos+k-1]+1 |
|
1980 | ang_new[pos+k] = ang_new[pos+k-1]+1 | |
1981 | ang_new2[pos+k] = numpy.nan |
|
1981 | ang_new2[pos+k] = numpy.nan | |
1982 | elif tipo_case==1 or tipo_case==2:#bajada |
|
1982 | elif tipo_case==1 or tipo_case==2:#bajada | |
1983 | ang_new[pos+k] = ang_new[pos+k-1]-1 |
|
1983 | ang_new[pos+k] = ang_new[pos+k-1]-1 | |
1984 | ang_new2[pos+k] = numpy.nan |
|
1984 | ang_new2[pos+k] = numpy.nan | |
1985 |
|
1985 | |||
1986 | tmp = pos +k |
|
1986 | tmp = pos +k | |
1987 | c = 0 |
|
1987 | c = 0 | |
1988 | c=c+1 |
|
1988 | c=c+1 | |
1989 | return ang_new,ang_new2 |
|
1989 | return ang_new,ang_new2 | |
1990 |
|
1990 | |||
1991 | def globalCheckPED(self,angulos,tipo_case): |
|
1991 | def globalCheckPED(self,angulos,tipo_case): | |
1992 | l1,l2 = self.get2List(angulos) |
|
1992 | l1,l2 = self.get2List(angulos) | |
1993 | ##print("l1",l1) |
|
1993 | ##print("l1",l1) | |
1994 | ##print("l2",l2) |
|
1994 | ##print("l2",l2) | |
1995 | if len(l1)>0: |
|
1995 | if len(l1)>0: | |
1996 | #angulos2 = self.fixData90(list_=l1,ang_=angulos) |
|
1996 | #angulos2 = self.fixData90(list_=l1,ang_=angulos) | |
1997 | #l1,l2 = self.get2List(angulos2) |
|
1997 | #l1,l2 = self.get2List(angulos2) | |
1998 | ang1_,ang2_ = self.fixDataComp(ang_=angulos,list1_=l1,list2_=l2,tipo_case=tipo_case) |
|
1998 | ang1_,ang2_ = self.fixDataComp(ang_=angulos,list1_=l1,list2_=l2,tipo_case=tipo_case) | |
1999 | #ang1_ = self.fixData90HL(ang1_) |
|
1999 | #ang1_ = self.fixData90HL(ang1_) | |
2000 | #ang2_ = self.fixData90HL(ang2_) |
|
2000 | #ang2_ = self.fixData90HL(ang2_) | |
2001 | else: |
|
2001 | else: | |
2002 | ang1_= angulos |
|
2002 | ang1_= angulos | |
2003 | ang2_= angulos |
|
2003 | ang2_= angulos | |
2004 | return ang1_,ang2_ |
|
2004 | return ang1_,ang2_ | |
2005 |
|
2005 | |||
2006 |
|
2006 | |||
2007 | def replaceNAN(self,data_weather,data_ele,val): |
|
2007 | def replaceNAN(self,data_weather,data_ele,val): | |
2008 | data= data_ele |
|
2008 | data= data_ele | |
2009 | data_T= data_weather |
|
2009 | data_T= data_weather | |
2010 |
|
2010 | |||
2011 | if data.shape[0]> data_T.shape[0]: |
|
2011 | if data.shape[0]> data_T.shape[0]: | |
2012 | print("IF") |
|
2012 | print("IF") | |
2013 | data_N = numpy.ones( [data.shape[0],data_T.shape[1]]) |
|
2013 | data_N = numpy.ones( [data.shape[0],data_T.shape[1]]) | |
2014 | c = 0 |
|
2014 | c = 0 | |
2015 | for i in range(len(data)): |
|
2015 | for i in range(len(data)): | |
2016 | if numpy.isnan(data[i]): |
|
2016 | if numpy.isnan(data[i]): | |
2017 | data_N[i,:]=numpy.ones(data_T.shape[1])*numpy.nan |
|
2017 | data_N[i,:]=numpy.ones(data_T.shape[1])*numpy.nan | |
2018 | else: |
|
2018 | else: | |
2019 | data_N[i,:]=data_T[c,:] |
|
2019 | data_N[i,:]=data_T[c,:] | |
2020 | c=c+1 |
|
2020 | c=c+1 | |
2021 | return data_N |
|
2021 | return data_N | |
2022 | else: |
|
2022 | else: | |
2023 | print("else") |
|
2023 | print("else") | |
2024 | for i in range(len(data)): |
|
2024 | for i in range(len(data)): | |
2025 | if numpy.isnan(data[i]): |
|
2025 | if numpy.isnan(data[i]): | |
2026 | data_T[i,:]=numpy.ones(data_T.shape[1])*numpy.nan |
|
2026 | data_T[i,:]=numpy.ones(data_T.shape[1])*numpy.nan | |
2027 | return data_T |
|
2027 | return data_T | |
2028 |
|
2028 | |||
2029 | def check_case(self,data_ele,ang_max,ang_min): |
|
2029 | def check_case(self,data_ele,ang_max,ang_min): | |
2030 | start = data_ele[0] |
|
2030 | start = data_ele[0] | |
2031 | end = data_ele[-1] |
|
2031 | end = data_ele[-1] | |
2032 | number = (end-start) |
|
2032 | number = (end-start) | |
2033 | len_ang=len(data_ele) |
|
2033 | len_ang=len(data_ele) | |
2034 | print("start",start) |
|
2034 | print("start",start) | |
2035 | print("end",end) |
|
2035 | print("end",end) | |
2036 | print("number",number) |
|
2036 | print("number",number) | |
2037 |
|
2037 | |||
2038 | print("len_ang",len_ang) |
|
2038 | print("len_ang",len_ang) | |
2039 |
|
2039 | |||
2040 | #exit(1) |
|
2040 | #exit(1) | |
2041 |
|
2041 | |||
2042 | if start<end and (round(abs(number)+1)>=len_ang or (numpy.argmin(data_ele)==0)):#caso subida |
|
2042 | if start<end and (round(abs(number)+1)>=len_ang or (numpy.argmin(data_ele)==0)):#caso subida | |
2043 | return 0 |
|
2043 | return 0 | |
2044 | #elif start>end and (round(abs(number)+1)>=len_ang or(numpy.argmax(data_ele)==0)):#caso bajada |
|
2044 | #elif start>end and (round(abs(number)+1)>=len_ang or(numpy.argmax(data_ele)==0)):#caso bajada | |
2045 | # return 1 |
|
2045 | # return 1 | |
2046 | elif round(abs(number)+1)>=len_ang and (start>end or(numpy.argmax(data_ele)==0)):#caso bajada |
|
2046 | elif round(abs(number)+1)>=len_ang and (start>end or(numpy.argmax(data_ele)==0)):#caso bajada | |
2047 | return 1 |
|
2047 | return 1 | |
2048 | elif round(abs(number)+1)<len_ang and data_ele[-2]>data_ele[-1]:# caso BAJADA CAMBIO ANG MAX |
|
2048 | elif round(abs(number)+1)<len_ang and data_ele[-2]>data_ele[-1]:# caso BAJADA CAMBIO ANG MAX | |
2049 | return 2 |
|
2049 | return 2 | |
2050 | elif round(abs(number)+1)<len_ang and data_ele[-2]<data_ele[-1] :# caso SUBIDA CAMBIO ANG MIN |
|
2050 | elif round(abs(number)+1)<len_ang and data_ele[-2]<data_ele[-1] :# caso SUBIDA CAMBIO ANG MIN | |
2051 | return 3 |
|
2051 | return 3 | |
2052 |
|
2052 | |||
2053 |
|
2053 | |||
2054 | def const_ploteo(self,val_ch,data_weather,data_ele,step,res,ang_max,ang_min,case_flag): |
|
2054 | def const_ploteo(self,val_ch,data_weather,data_ele,step,res,ang_max,ang_min,case_flag): | |
2055 | ang_max= ang_max |
|
2055 | ang_max= ang_max | |
2056 | ang_min= ang_min |
|
2056 | ang_min= ang_min | |
2057 | data_weather=data_weather |
|
2057 | data_weather=data_weather | |
2058 | val_ch=val_ch |
|
2058 | val_ch=val_ch | |
2059 | ##print("*********************DATA WEATHER**************************************") |
|
2059 | ##print("*********************DATA WEATHER**************************************") | |
2060 | ##print(data_weather) |
|
2060 | ##print(data_weather) | |
2061 | if self.ini==0: |
|
2061 | if self.ini==0: | |
2062 |
|
2062 | |||
2063 | #--------------------- new ------------------------- |
|
2063 | #--------------------- new ------------------------- | |
2064 | data_ele_new ,data_ele_old= self.globalCheckPED(data_ele,tipo_case) |
|
2064 | data_ele_new ,data_ele_old= self.globalCheckPED(data_ele,tipo_case) | |
2065 |
|
2065 | |||
2066 | #-------------------------CAMBIOS RHI--------------------------------- |
|
2066 | #-------------------------CAMBIOS RHI--------------------------------- | |
2067 | start= ang_min |
|
2067 | start= ang_min | |
2068 | end = ang_max |
|
2068 | end = ang_max | |
2069 | n= (ang_max-ang_min)/res |
|
2069 | n= (ang_max-ang_min)/res | |
2070 | #------ new |
|
2070 | #------ new | |
2071 | self.start_data_ele = data_ele_new[0] |
|
2071 | self.start_data_ele = data_ele_new[0] | |
2072 | self.end_data_ele = data_ele_new[-1] |
|
2072 | self.end_data_ele = data_ele_new[-1] | |
2073 | if tipo_case==0 or tipo_case==3: # SUBIDA |
|
2073 | if tipo_case==0 or tipo_case==3: # SUBIDA | |
2074 | n1= round(self.start_data_ele)- start |
|
2074 | n1= round(self.start_data_ele)- start | |
2075 | n2= end - round(self.end_data_ele) |
|
2075 | n2= end - round(self.end_data_ele) | |
2076 | print(self.start_data_ele) |
|
2076 | print(self.start_data_ele) | |
2077 | print(self.end_data_ele) |
|
2077 | print(self.end_data_ele) | |
2078 | if n1>0: |
|
2078 | if n1>0: | |
2079 | ele1= numpy.linspace(ang_min+1,self.start_data_ele-1,n1) |
|
2079 | ele1= numpy.linspace(ang_min+1,self.start_data_ele-1,n1) | |
2080 | ele1_nan= numpy.ones(n1)*numpy.nan |
|
2080 | ele1_nan= numpy.ones(n1)*numpy.nan | |
2081 | data_ele = numpy.hstack((ele1,data_ele_new)) |
|
2081 | data_ele = numpy.hstack((ele1,data_ele_new)) | |
2082 | print("ele1_nan",ele1_nan.shape) |
|
2082 | print("ele1_nan",ele1_nan.shape) | |
2083 | print("data_ele_old",data_ele_old.shape) |
|
2083 | print("data_ele_old",data_ele_old.shape) | |
2084 | data_ele_old = numpy.hstack((ele1_nan,data_ele_old)) |
|
2084 | data_ele_old = numpy.hstack((ele1_nan,data_ele_old)) | |
2085 | if n2>0: |
|
2085 | if n2>0: | |
2086 | ele2= numpy.linspace(self.end_data_ele+1,end,n2) |
|
2086 | ele2= numpy.linspace(self.end_data_ele+1,end,n2) | |
2087 | ele2_nan= numpy.ones(n2)*numpy.nan |
|
2087 | ele2_nan= numpy.ones(n2)*numpy.nan | |
2088 | data_ele = numpy.hstack((data_ele,ele2)) |
|
2088 | data_ele = numpy.hstack((data_ele,ele2)) | |
2089 | print("ele2_nan",ele2_nan.shape) |
|
2089 | print("ele2_nan",ele2_nan.shape) | |
2090 | print("data_ele_old",data_ele_old.shape) |
|
2090 | print("data_ele_old",data_ele_old.shape) | |
2091 | data_ele_old = numpy.hstack((data_ele_old,ele2_nan)) |
|
2091 | data_ele_old = numpy.hstack((data_ele_old,ele2_nan)) | |
2092 |
|
2092 | |||
2093 | if tipo_case==1 or tipo_case==2: # BAJADA |
|
2093 | if tipo_case==1 or tipo_case==2: # BAJADA | |
2094 | data_ele_new = data_ele_new[::-1] # reversa |
|
2094 | data_ele_new = data_ele_new[::-1] # reversa | |
2095 | data_ele_old = data_ele_old[::-1]# reversa |
|
2095 | data_ele_old = data_ele_old[::-1]# reversa | |
2096 | data_weather = data_weather[::-1,:]# reversa |
|
2096 | data_weather = data_weather[::-1,:]# reversa | |
2097 | vec= numpy.where(data_ele_new<ang_max) |
|
2097 | vec= numpy.where(data_ele_new<ang_max) | |
2098 | data_ele_new = data_ele_new[vec] |
|
2098 | data_ele_new = data_ele_new[vec] | |
2099 | data_ele_old = data_ele_old[vec] |
|
2099 | data_ele_old = data_ele_old[vec] | |
2100 | data_weather = data_weather[vec[0]] |
|
2100 | data_weather = data_weather[vec[0]] | |
2101 | vec2= numpy.where(0<data_ele_new) |
|
2101 | vec2= numpy.where(0<data_ele_new) | |
2102 | data_ele_new = data_ele_new[vec2] |
|
2102 | data_ele_new = data_ele_new[vec2] | |
2103 | data_ele_old = data_ele_old[vec2] |
|
2103 | data_ele_old = data_ele_old[vec2] | |
2104 | data_weather = data_weather[vec2[0]] |
|
2104 | data_weather = data_weather[vec2[0]] | |
2105 | self.start_data_ele = data_ele_new[0] |
|
2105 | self.start_data_ele = data_ele_new[0] | |
2106 | self.end_data_ele = data_ele_new[-1] |
|
2106 | self.end_data_ele = data_ele_new[-1] | |
2107 |
|
2107 | |||
2108 | n1= round(self.start_data_ele)- start |
|
2108 | n1= round(self.start_data_ele)- start | |
2109 | n2= end - round(self.end_data_ele)-1 |
|
2109 | n2= end - round(self.end_data_ele)-1 | |
2110 | print(self.start_data_ele) |
|
2110 | print(self.start_data_ele) | |
2111 | print(self.end_data_ele) |
|
2111 | print(self.end_data_ele) | |
2112 | if n1>0: |
|
2112 | if n1>0: | |
2113 | ele1= numpy.linspace(ang_min+1,self.start_data_ele-1,n1) |
|
2113 | ele1= numpy.linspace(ang_min+1,self.start_data_ele-1,n1) | |
2114 | ele1_nan= numpy.ones(n1)*numpy.nan |
|
2114 | ele1_nan= numpy.ones(n1)*numpy.nan | |
2115 | data_ele = numpy.hstack((ele1,data_ele_new)) |
|
2115 | data_ele = numpy.hstack((ele1,data_ele_new)) | |
2116 | data_ele_old = numpy.hstack((ele1_nan,data_ele_old)) |
|
2116 | data_ele_old = numpy.hstack((ele1_nan,data_ele_old)) | |
2117 | if n2>0: |
|
2117 | if n2>0: | |
2118 | ele2= numpy.linspace(self.end_data_ele+1,end,n2) |
|
2118 | ele2= numpy.linspace(self.end_data_ele+1,end,n2) | |
2119 | ele2_nan= numpy.ones(n2)*numpy.nan |
|
2119 | ele2_nan= numpy.ones(n2)*numpy.nan | |
2120 | data_ele = numpy.hstack((data_ele,ele2)) |
|
2120 | data_ele = numpy.hstack((data_ele,ele2)) | |
2121 | data_ele_old = numpy.hstack((data_ele_old,ele2_nan)) |
|
2121 | data_ele_old = numpy.hstack((data_ele_old,ele2_nan)) | |
2122 | # RADAR |
|
2122 | # RADAR | |
2123 | # NOTA data_ele y data_weather es la variable que retorna |
|
2123 | # NOTA data_ele y data_weather es la variable que retorna | |
2124 | val_mean = numpy.mean(data_weather[:,-1]) |
|
2124 | val_mean = numpy.mean(data_weather[:,-1]) | |
2125 | self.val_mean = val_mean |
|
2125 | self.val_mean = val_mean | |
2126 | data_weather = self.replaceNAN(data_weather=data_weather,data_ele=data_ele_old,val=self.val_mean) |
|
2126 | data_weather = self.replaceNAN(data_weather=data_weather,data_ele=data_ele_old,val=self.val_mean) | |
2127 | print("eleold",data_ele_old) |
|
2127 | print("eleold",data_ele_old) | |
2128 | print(self.data_ele_tmp[val_ch]) |
|
2128 | print(self.data_ele_tmp[val_ch]) | |
2129 | print(data_ele_old.shape[0]) |
|
2129 | print(data_ele_old.shape[0]) | |
2130 | print(self.data_ele_tmp[val_ch].shape[0]) |
|
2130 | print(self.data_ele_tmp[val_ch].shape[0]) | |
2131 | if (data_ele_old.shape[0]==91 or self.data_ele_tmp[val_ch].shape[0]==91): |
|
2131 | if (data_ele_old.shape[0]==91 or self.data_ele_tmp[val_ch].shape[0]==91): | |
2132 | import sys |
|
2132 | import sys | |
2133 | print("EXIT",self.ini) |
|
2133 | print("EXIT",self.ini) | |
2134 |
|
2134 | |||
2135 | sys.exit(1) |
|
2135 | sys.exit(1) | |
2136 | self.data_ele_tmp[val_ch]= data_ele_old |
|
2136 | self.data_ele_tmp[val_ch]= data_ele_old | |
2137 | else: |
|
2137 | else: | |
2138 | #print("**********************************************") |
|
2138 | #print("**********************************************") | |
2139 | #print("****************VARIABLE**********************") |
|
2139 | #print("****************VARIABLE**********************") | |
2140 | #-------------------------CAMBIOS RHI--------------------------------- |
|
2140 | #-------------------------CAMBIOS RHI--------------------------------- | |
2141 | #--------------------------------------------------------------------- |
|
2141 | #--------------------------------------------------------------------- | |
2142 | ##print("INPUT data_ele",data_ele) |
|
2142 | ##print("INPUT data_ele",data_ele) | |
2143 | flag=0 |
|
2143 | flag=0 | |
2144 | start_ele = self.res_ele[0] |
|
2144 | start_ele = self.res_ele[0] | |
2145 | #tipo_case = self.check_case(data_ele,ang_max,ang_min) |
|
2145 | #tipo_case = self.check_case(data_ele,ang_max,ang_min) | |
2146 | tipo_case = case_flag[-1] |
|
2146 | tipo_case = case_flag[-1] | |
2147 | #print("TIPO DE DATA",tipo_case) |
|
2147 | #print("TIPO DE DATA",tipo_case) | |
2148 | #-----------new------------ |
|
2148 | #-----------new------------ | |
2149 | data_ele ,data_ele_old = self.globalCheckPED(data_ele,tipo_case) |
|
2149 | data_ele ,data_ele_old = self.globalCheckPED(data_ele,tipo_case) | |
2150 | data_weather = self.replaceNAN(data_weather=data_weather,data_ele=data_ele_old,val=self.val_mean) |
|
2150 | data_weather = self.replaceNAN(data_weather=data_weather,data_ele=data_ele_old,val=self.val_mean) | |
2151 |
|
2151 | |||
2152 | #-------------------------------NEW RHI ITERATIVO------------------------- |
|
2152 | #-------------------------------NEW RHI ITERATIVO------------------------- | |
2153 |
|
2153 | |||
2154 | if tipo_case==0 : # SUBIDA |
|
2154 | if tipo_case==0 : # SUBIDA | |
2155 | vec = numpy.where(data_ele<ang_max) |
|
2155 | vec = numpy.where(data_ele<ang_max) | |
2156 | data_ele = data_ele[vec] |
|
2156 | data_ele = data_ele[vec] | |
2157 | data_ele_old = data_ele_old[vec] |
|
2157 | data_ele_old = data_ele_old[vec] | |
2158 | data_weather = data_weather[vec[0]] |
|
2158 | data_weather = data_weather[vec[0]] | |
2159 |
|
2159 | |||
2160 | vec2 = numpy.where(0<data_ele) |
|
2160 | vec2 = numpy.where(0<data_ele) | |
2161 | data_ele= data_ele[vec2] |
|
2161 | data_ele= data_ele[vec2] | |
2162 | data_ele_old= data_ele_old[vec2] |
|
2162 | data_ele_old= data_ele_old[vec2] | |
2163 | ##print(data_ele_new) |
|
2163 | ##print(data_ele_new) | |
2164 | data_weather= data_weather[vec2[0]] |
|
2164 | data_weather= data_weather[vec2[0]] | |
2165 |
|
2165 | |||
2166 | new_i_ele = int(round(data_ele[0])) |
|
2166 | new_i_ele = int(round(data_ele[0])) | |
2167 | new_f_ele = int(round(data_ele[-1])) |
|
2167 | new_f_ele = int(round(data_ele[-1])) | |
2168 | #print(new_i_ele) |
|
2168 | #print(new_i_ele) | |
2169 | #print(new_f_ele) |
|
2169 | #print(new_f_ele) | |
2170 | #print(data_ele,len(data_ele)) |
|
2170 | #print(data_ele,len(data_ele)) | |
2171 | #print(data_ele_old,len(data_ele_old)) |
|
2171 | #print(data_ele_old,len(data_ele_old)) | |
2172 | if new_i_ele< 2: |
|
2172 | if new_i_ele< 2: | |
2173 | self.data_ele_tmp[val_ch] = numpy.ones(ang_max-ang_min)*numpy.nan |
|
2173 | self.data_ele_tmp[val_ch] = numpy.ones(ang_max-ang_min)*numpy.nan | |
2174 | self.res_weather[val_ch] = self.replaceNAN(data_weather=self.res_weather[val_ch],data_ele=self.data_ele_tmp[val_ch],val=self.val_mean) |
|
2174 | self.res_weather[val_ch] = self.replaceNAN(data_weather=self.res_weather[val_ch],data_ele=self.data_ele_tmp[val_ch],val=self.val_mean) | |
2175 | self.data_ele_tmp[val_ch][new_i_ele:new_i_ele+len(data_ele)]=data_ele_old |
|
2175 | self.data_ele_tmp[val_ch][new_i_ele:new_i_ele+len(data_ele)]=data_ele_old | |
2176 | self.res_ele[new_i_ele:new_i_ele+len(data_ele)]= data_ele |
|
2176 | self.res_ele[new_i_ele:new_i_ele+len(data_ele)]= data_ele | |
2177 | self.res_weather[val_ch][new_i_ele:new_i_ele+len(data_ele),:]= data_weather |
|
2177 | self.res_weather[val_ch][new_i_ele:new_i_ele+len(data_ele),:]= data_weather | |
2178 | data_ele = self.res_ele |
|
2178 | data_ele = self.res_ele | |
2179 | data_weather = self.res_weather[val_ch] |
|
2179 | data_weather = self.res_weather[val_ch] | |
2180 |
|
2180 | |||
2181 | elif tipo_case==1 : #BAJADA |
|
2181 | elif tipo_case==1 : #BAJADA | |
2182 | data_ele = data_ele[::-1] # reversa |
|
2182 | data_ele = data_ele[::-1] # reversa | |
2183 | data_ele_old = data_ele_old[::-1]# reversa |
|
2183 | data_ele_old = data_ele_old[::-1]# reversa | |
2184 | data_weather = data_weather[::-1,:]# reversa |
|
2184 | data_weather = data_weather[::-1,:]# reversa | |
2185 | vec= numpy.where(data_ele<ang_max) |
|
2185 | vec= numpy.where(data_ele<ang_max) | |
2186 | data_ele = data_ele[vec] |
|
2186 | data_ele = data_ele[vec] | |
2187 | data_ele_old = data_ele_old[vec] |
|
2187 | data_ele_old = data_ele_old[vec] | |
2188 | data_weather = data_weather[vec[0]] |
|
2188 | data_weather = data_weather[vec[0]] | |
2189 | vec2= numpy.where(0<data_ele) |
|
2189 | vec2= numpy.where(0<data_ele) | |
2190 | data_ele = data_ele[vec2] |
|
2190 | data_ele = data_ele[vec2] | |
2191 | data_ele_old = data_ele_old[vec2] |
|
2191 | data_ele_old = data_ele_old[vec2] | |
2192 | data_weather = data_weather[vec2[0]] |
|
2192 | data_weather = data_weather[vec2[0]] | |
2193 |
|
2193 | |||
2194 |
|
2194 | |||
2195 | new_i_ele = int(round(data_ele[0])) |
|
2195 | new_i_ele = int(round(data_ele[0])) | |
2196 | new_f_ele = int(round(data_ele[-1])) |
|
2196 | new_f_ele = int(round(data_ele[-1])) | |
2197 | #print(data_ele) |
|
2197 | #print(data_ele) | |
2198 | #print(ang_max) |
|
2198 | #print(ang_max) | |
2199 | #print(data_ele_old) |
|
2199 | #print(data_ele_old) | |
2200 | if new_i_ele <= 1: |
|
2200 | if new_i_ele <= 1: | |
2201 | new_i_ele = 1 |
|
2201 | new_i_ele = 1 | |
2202 | if round(data_ele[-1])>=ang_max-1: |
|
2202 | if round(data_ele[-1])>=ang_max-1: | |
2203 | self.data_ele_tmp[val_ch] = numpy.ones(ang_max-ang_min)*numpy.nan |
|
2203 | self.data_ele_tmp[val_ch] = numpy.ones(ang_max-ang_min)*numpy.nan | |
2204 | self.res_weather[val_ch] = self.replaceNAN(data_weather=self.res_weather[val_ch],data_ele=self.data_ele_tmp[val_ch],val=self.val_mean) |
|
2204 | self.res_weather[val_ch] = self.replaceNAN(data_weather=self.res_weather[val_ch],data_ele=self.data_ele_tmp[val_ch],val=self.val_mean) | |
2205 | self.data_ele_tmp[val_ch][new_i_ele-1:new_i_ele+len(data_ele)-1]=data_ele_old |
|
2205 | self.data_ele_tmp[val_ch][new_i_ele-1:new_i_ele+len(data_ele)-1]=data_ele_old | |
2206 | self.res_ele[new_i_ele-1:new_i_ele+len(data_ele)-1]= data_ele |
|
2206 | self.res_ele[new_i_ele-1:new_i_ele+len(data_ele)-1]= data_ele | |
2207 | self.res_weather[val_ch][new_i_ele-1:new_i_ele+len(data_ele)-1,:]= data_weather |
|
2207 | self.res_weather[val_ch][new_i_ele-1:new_i_ele+len(data_ele)-1,:]= data_weather | |
2208 | data_ele = self.res_ele |
|
2208 | data_ele = self.res_ele | |
2209 | data_weather = self.res_weather[val_ch] |
|
2209 | data_weather = self.res_weather[val_ch] | |
2210 |
|
2210 | |||
2211 | elif tipo_case==2: #bajada |
|
2211 | elif tipo_case==2: #bajada | |
2212 | vec = numpy.where(data_ele<ang_max) |
|
2212 | vec = numpy.where(data_ele<ang_max) | |
2213 | data_ele = data_ele[vec] |
|
2213 | data_ele = data_ele[vec] | |
2214 | data_weather= data_weather[vec[0]] |
|
2214 | data_weather= data_weather[vec[0]] | |
2215 |
|
2215 | |||
2216 | len_vec = len(vec) |
|
2216 | len_vec = len(vec) | |
2217 | data_ele_new = data_ele[::-1] # reversa |
|
2217 | data_ele_new = data_ele[::-1] # reversa | |
2218 | data_weather = data_weather[::-1,:] |
|
2218 | data_weather = data_weather[::-1,:] | |
2219 | new_i_ele = int(data_ele_new[0]) |
|
2219 | new_i_ele = int(data_ele_new[0]) | |
2220 | new_f_ele = int(data_ele_new[-1]) |
|
2220 | new_f_ele = int(data_ele_new[-1]) | |
2221 |
|
2221 | |||
2222 | n1= new_i_ele- ang_min |
|
2222 | n1= new_i_ele- ang_min | |
2223 | n2= ang_max - new_f_ele-1 |
|
2223 | n2= ang_max - new_f_ele-1 | |
2224 | if n1>0: |
|
2224 | if n1>0: | |
2225 | ele1= numpy.linspace(ang_min+1,new_i_ele-1,n1) |
|
2225 | ele1= numpy.linspace(ang_min+1,new_i_ele-1,n1) | |
2226 | ele1_nan= numpy.ones(n1)*numpy.nan |
|
2226 | ele1_nan= numpy.ones(n1)*numpy.nan | |
2227 | data_ele = numpy.hstack((ele1,data_ele_new)) |
|
2227 | data_ele = numpy.hstack((ele1,data_ele_new)) | |
2228 | data_ele_old = numpy.hstack((ele1_nan,data_ele_new)) |
|
2228 | data_ele_old = numpy.hstack((ele1_nan,data_ele_new)) | |
2229 | if n2>0: |
|
2229 | if n2>0: | |
2230 | ele2= numpy.linspace(new_f_ele+1,ang_max,n2) |
|
2230 | ele2= numpy.linspace(new_f_ele+1,ang_max,n2) | |
2231 | ele2_nan= numpy.ones(n2)*numpy.nan |
|
2231 | ele2_nan= numpy.ones(n2)*numpy.nan | |
2232 | data_ele = numpy.hstack((data_ele,ele2)) |
|
2232 | data_ele = numpy.hstack((data_ele,ele2)) | |
2233 | data_ele_old = numpy.hstack((data_ele_old,ele2_nan)) |
|
2233 | data_ele_old = numpy.hstack((data_ele_old,ele2_nan)) | |
2234 |
|
2234 | |||
2235 | self.data_ele_tmp[val_ch] = data_ele_old |
|
2235 | self.data_ele_tmp[val_ch] = data_ele_old | |
2236 | self.res_ele = data_ele |
|
2236 | self.res_ele = data_ele | |
2237 | self.res_weather[val_ch] = self.replaceNAN(data_weather=data_weather,data_ele=data_ele_old,val=self.val_mean) |
|
2237 | self.res_weather[val_ch] = self.replaceNAN(data_weather=data_weather,data_ele=data_ele_old,val=self.val_mean) | |
2238 | data_ele = self.res_ele |
|
2238 | data_ele = self.res_ele | |
2239 | data_weather = self.res_weather[val_ch] |
|
2239 | data_weather = self.res_weather[val_ch] | |
2240 |
|
2240 | |||
2241 | elif tipo_case==3:#subida |
|
2241 | elif tipo_case==3:#subida | |
2242 | vec = numpy.where(0<data_ele) |
|
2242 | vec = numpy.where(0<data_ele) | |
2243 | data_ele= data_ele[vec] |
|
2243 | data_ele= data_ele[vec] | |
2244 | data_ele_new = data_ele |
|
2244 | data_ele_new = data_ele | |
2245 | data_ele_old= data_ele_old[vec] |
|
2245 | data_ele_old= data_ele_old[vec] | |
2246 | data_weather= data_weather[vec[0]] |
|
2246 | data_weather= data_weather[vec[0]] | |
2247 | pos_ini = numpy.argmin(data_ele) |
|
2247 | pos_ini = numpy.argmin(data_ele) | |
2248 | if pos_ini>0: |
|
2248 | if pos_ini>0: | |
2249 | len_vec= len(data_ele) |
|
2249 | len_vec= len(data_ele) | |
2250 | vec3 = numpy.linspace(pos_ini,len_vec-1,len_vec-pos_ini).astype(int) |
|
2250 | vec3 = numpy.linspace(pos_ini,len_vec-1,len_vec-pos_ini).astype(int) | |
2251 | #print(vec3) |
|
2251 | #print(vec3) | |
2252 | data_ele= data_ele[vec3] |
|
2252 | data_ele= data_ele[vec3] | |
2253 | data_ele_new = data_ele |
|
2253 | data_ele_new = data_ele | |
2254 | data_ele_old= data_ele_old[vec3] |
|
2254 | data_ele_old= data_ele_old[vec3] | |
2255 | data_weather= data_weather[vec3] |
|
2255 | data_weather= data_weather[vec3] | |
2256 |
|
2256 | |||
2257 | new_i_ele = int(data_ele_new[0]) |
|
2257 | new_i_ele = int(data_ele_new[0]) | |
2258 | new_f_ele = int(data_ele_new[-1]) |
|
2258 | new_f_ele = int(data_ele_new[-1]) | |
2259 | n1= new_i_ele- ang_min |
|
2259 | n1= new_i_ele- ang_min | |
2260 | n2= ang_max - new_f_ele-1 |
|
2260 | n2= ang_max - new_f_ele-1 | |
2261 | if n1>0: |
|
2261 | if n1>0: | |
2262 | ele1= numpy.linspace(ang_min+1,new_i_ele-1,n1) |
|
2262 | ele1= numpy.linspace(ang_min+1,new_i_ele-1,n1) | |
2263 | ele1_nan= numpy.ones(n1)*numpy.nan |
|
2263 | ele1_nan= numpy.ones(n1)*numpy.nan | |
2264 | data_ele = numpy.hstack((ele1,data_ele_new)) |
|
2264 | data_ele = numpy.hstack((ele1,data_ele_new)) | |
2265 | data_ele_old = numpy.hstack((ele1_nan,data_ele_new)) |
|
2265 | data_ele_old = numpy.hstack((ele1_nan,data_ele_new)) | |
2266 | if n2>0: |
|
2266 | if n2>0: | |
2267 | ele2= numpy.linspace(new_f_ele+1,ang_max,n2) |
|
2267 | ele2= numpy.linspace(new_f_ele+1,ang_max,n2) | |
2268 | ele2_nan= numpy.ones(n2)*numpy.nan |
|
2268 | ele2_nan= numpy.ones(n2)*numpy.nan | |
2269 | data_ele = numpy.hstack((data_ele,ele2)) |
|
2269 | data_ele = numpy.hstack((data_ele,ele2)) | |
2270 | data_ele_old = numpy.hstack((data_ele_old,ele2_nan)) |
|
2270 | data_ele_old = numpy.hstack((data_ele_old,ele2_nan)) | |
2271 |
|
2271 | |||
2272 | self.data_ele_tmp[val_ch] = data_ele_old |
|
2272 | self.data_ele_tmp[val_ch] = data_ele_old | |
2273 | self.res_ele = data_ele |
|
2273 | self.res_ele = data_ele | |
2274 | self.res_weather[val_ch] = self.replaceNAN(data_weather=data_weather,data_ele=data_ele_old,val=self.val_mean) |
|
2274 | self.res_weather[val_ch] = self.replaceNAN(data_weather=data_weather,data_ele=data_ele_old,val=self.val_mean) | |
2275 | data_ele = self.res_ele |
|
2275 | data_ele = self.res_ele | |
2276 | data_weather = self.res_weather[val_ch] |
|
2276 | data_weather = self.res_weather[val_ch] | |
2277 | #print("self.data_ele_tmp",self.data_ele_tmp) |
|
2277 | #print("self.data_ele_tmp",self.data_ele_tmp) | |
2278 | return data_weather,data_ele |
|
2278 | return data_weather,data_ele | |
2279 |
|
2279 | |||
2280 | def const_ploteo_vRF(self,val_ch,data_weather,data_ele,res,ang_max,ang_min): |
|
2280 | def const_ploteo_vRF(self,val_ch,data_weather,data_ele,res,ang_max,ang_min): | |
2281 |
|
2281 | |||
2282 | data_ele_new ,data_ele_old= self.globalCheckPED(data_ele,1) |
|
2282 | data_ele_new ,data_ele_old= self.globalCheckPED(data_ele,1) | |
2283 |
|
2283 | |||
2284 | data_ele = data_ele_old.copy() |
|
2284 | data_ele = data_ele_old.copy() | |
2285 |
|
2285 | |||
2286 | diff_1 = ang_max - data_ele[0] |
|
2286 | diff_1 = ang_max - data_ele[0] | |
2287 | angles_1_nan = numpy.linspace(ang_max,data_ele[0]+1,int(diff_1)-1)#*numpy.nan |
|
2287 | angles_1_nan = numpy.linspace(ang_max,data_ele[0]+1,int(diff_1)-1)#*numpy.nan | |
2288 |
|
2288 | |||
2289 | diff_2 = data_ele[-1]-ang_min |
|
2289 | diff_2 = data_ele[-1]-ang_min | |
2290 | angles_2_nan = numpy.linspace(data_ele[-1]-1,ang_min,int(diff_2)-1)#*numpy.nan |
|
2290 | angles_2_nan = numpy.linspace(data_ele[-1]-1,ang_min,int(diff_2)-1)#*numpy.nan | |
2291 |
|
2291 | |||
2292 | angles_filled = numpy.concatenate((angles_1_nan,data_ele,angles_2_nan)) |
|
2292 | angles_filled = numpy.concatenate((angles_1_nan,data_ele,angles_2_nan)) | |
2293 |
|
2293 | |||
2294 | print(angles_filled) |
|
2294 | print(angles_filled) | |
2295 |
|
2295 | |||
2296 | data_1_nan = numpy.ones([angles_1_nan.shape[0],len(self.r_mask)])*numpy.nan |
|
2296 | data_1_nan = numpy.ones([angles_1_nan.shape[0],len(self.r_mask)])*numpy.nan | |
2297 | data_2_nan = numpy.ones([angles_2_nan.shape[0],len(self.r_mask)])*numpy.nan |
|
2297 | data_2_nan = numpy.ones([angles_2_nan.shape[0],len(self.r_mask)])*numpy.nan | |
2298 |
|
2298 | |||
2299 | data_filled = numpy.concatenate((data_1_nan,data_weather,data_2_nan),axis=0) |
|
2299 | data_filled = numpy.concatenate((data_1_nan,data_weather,data_2_nan),axis=0) | |
2300 | #val_mean = numpy.mean(data_weather[:,-1]) |
|
2300 | #val_mean = numpy.mean(data_weather[:,-1]) | |
2301 | #self.val_mean = val_mean |
|
2301 | #self.val_mean = val_mean | |
2302 | print(data_filled) |
|
2302 | print(data_filled) | |
2303 | data_filled = self.replaceNAN(data_weather=data_filled,data_ele=angles_filled,val=numpy.nan) |
|
2303 | data_filled = self.replaceNAN(data_weather=data_filled,data_ele=angles_filled,val=numpy.nan) | |
2304 |
|
2304 | |||
2305 | print(data_filled) |
|
2305 | print(data_filled) | |
2306 | print(data_filled.shape) |
|
2306 | print(data_filled.shape) | |
2307 | print(angles_filled.shape) |
|
2307 | print(angles_filled.shape) | |
2308 |
|
2308 | |||
2309 | return data_filled,angles_filled |
|
2309 | return data_filled,angles_filled | |
2310 |
|
2310 | |||
2311 | def plot(self): |
|
2311 | def plot(self): | |
2312 | thisDatetime = datetime.datetime.utcfromtimestamp(self.data.times[-1]).strftime('%Y-%m-%d %H:%M:%S') |
|
2312 | thisDatetime = datetime.datetime.utcfromtimestamp(self.data.times[-1]).strftime('%Y-%m-%d %H:%M:%S') | |
2313 | data = self.data[-1] |
|
2313 | data = self.data[-1] | |
2314 | r = self.data.yrange |
|
2314 | r = self.data.yrange | |
2315 | delta_height = r[1]-r[0] |
|
2315 | delta_height = r[1]-r[0] | |
2316 | r_mask = numpy.where(r>=0)[0] |
|
2316 | r_mask = numpy.where(r>=0)[0] | |
2317 | self.r_mask =r_mask |
|
2317 | self.r_mask =r_mask | |
2318 | ##print("delta_height",delta_height) |
|
2318 | ##print("delta_height",delta_height) | |
2319 | #print("r_mask",r_mask,len(r_mask)) |
|
2319 | #print("r_mask",r_mask,len(r_mask)) | |
2320 | r = numpy.arange(len(r_mask))*delta_height |
|
2320 | r = numpy.arange(len(r_mask))*delta_height | |
2321 | self.y = 2*r |
|
2321 | self.y = 2*r | |
2322 | res = 1 |
|
2322 | res = 1 | |
2323 | ###print("data['weather'].shape[0]",data['weather'].shape[0]) |
|
2323 | ###print("data['weather'].shape[0]",data['weather'].shape[0]) | |
2324 | ang_max = self.ang_max |
|
2324 | ang_max = self.ang_max | |
2325 | ang_min = self.ang_min |
|
2325 | ang_min = self.ang_min | |
2326 | var_ang =ang_max - ang_min |
|
2326 | var_ang =ang_max - ang_min | |
2327 | step = (int(var_ang)/(res*data['weather'].shape[0])) |
|
2327 | step = (int(var_ang)/(res*data['weather'].shape[0])) | |
2328 | ###print("step",step) |
|
2328 | ###print("step",step) | |
2329 | #-------------------------------------------------------- |
|
2329 | #-------------------------------------------------------- | |
2330 | ##print('weather',data['weather'].shape) |
|
2330 | ##print('weather',data['weather'].shape) | |
2331 | ##print('ele',data['ele'].shape) |
|
2331 | ##print('ele',data['ele'].shape) | |
2332 |
|
2332 | |||
2333 | ###self.res_weather, self.res_ele = self.const_ploteo(data_weather=data['weather'][:,r_mask],data_ele=data['ele'],step=step,res=res,ang_max=ang_max,ang_min=ang_min) |
|
2333 | ###self.res_weather, self.res_ele = self.const_ploteo(data_weather=data['weather'][:,r_mask],data_ele=data['ele'],step=step,res=res,ang_max=ang_max,ang_min=ang_min) | |
2334 | ###self.res_azi = numpy.mean(data['azi']) |
|
2334 | ###self.res_azi = numpy.mean(data['azi']) | |
2335 | ###print("self.res_ele",self.res_ele) |
|
2335 | ###print("self.res_ele",self.res_ele) | |
2336 |
|
2336 | |||
2337 | plt.clf() |
|
2337 | plt.clf() | |
2338 | subplots = [121, 122] |
|
2338 | subplots = [121, 122] | |
2339 | #if self.ini==0: |
|
2339 | #if self.ini==0: | |
2340 | #self.res_weather= numpy.ones([self.nplots,int(var_ang),len(r_mask)])*numpy.nan |
|
2340 | #self.res_weather= numpy.ones([self.nplots,int(var_ang),len(r_mask)])*numpy.nan | |
2341 | #print("SHAPE",self.data_ele_tmp.shape) |
|
2341 | #print("SHAPE",self.data_ele_tmp.shape) | |
2342 |
|
2342 | |||
2343 | for i,ax in enumerate(self.axes): |
|
2343 | for i,ax in enumerate(self.axes): | |
2344 | res_weather, self.res_ele = self.const_ploteo_vRF(val_ch=i, data_weather=data['weather'][i][:,r_mask],data_ele=data['ele'],res=res,ang_max=ang_max,ang_min=ang_min) |
|
2344 | res_weather, self.res_ele = self.const_ploteo_vRF(val_ch=i, data_weather=data['weather'][i][:,r_mask],data_ele=data['ele'],res=res,ang_max=ang_max,ang_min=ang_min) | |
2345 | self.res_azi = numpy.mean(data['azi']) |
|
2345 | self.res_azi = numpy.mean(data['azi']) | |
2346 |
|
2346 | |||
2347 | if ax.firsttime: |
|
2347 | if ax.firsttime: | |
2348 | #plt.clf() |
|
2348 | #plt.clf() | |
2349 | print("Frist Plot") |
|
2349 | print("Frist Plot") | |
2350 | print(data['weather'][i][:,r_mask].shape) |
|
2350 | print(data['weather'][i][:,r_mask].shape) | |
2351 | print(data['ele'].shape) |
|
2351 | print(data['ele'].shape) | |
2352 | cgax, pm = wrl.vis.plot_rhi(res_weather,r=r,th=self.res_ele,ax=subplots[i], proj='cg',vmin=20, vmax=80) |
|
2352 | cgax, pm = wrl.vis.plot_rhi(res_weather,r=r,th=self.res_ele,ax=subplots[i], proj='cg',vmin=20, vmax=80) | |
2353 | #cgax, pm = wrl.vis.plot_rhi(data['weather'][i][:,r_mask],r=r,th=data['ele'],ax=subplots[i], proj='cg',vmin=20, vmax=80) |
|
2353 | #cgax, pm = wrl.vis.plot_rhi(data['weather'][i][:,r_mask],r=r,th=data['ele'],ax=subplots[i], proj='cg',vmin=20, vmax=80) | |
2354 | gh = cgax.get_grid_helper() |
|
2354 | gh = cgax.get_grid_helper() | |
2355 | locs = numpy.linspace(ang_min,ang_max,var_ang+1) |
|
2355 | locs = numpy.linspace(ang_min,ang_max,var_ang+1) | |
2356 | gh.grid_finder.grid_locator1 = FixedLocator(locs) |
|
2356 | gh.grid_finder.grid_locator1 = FixedLocator(locs) | |
2357 | gh.grid_finder.tick_formatter1 = DictFormatter(dict([(i, r"${0:.0f}^\circ$".format(i)) for i in locs])) |
|
2357 | gh.grid_finder.tick_formatter1 = DictFormatter(dict([(i, r"${0:.0f}^\circ$".format(i)) for i in locs])) | |
2358 |
|
2358 | |||
2359 |
|
2359 | |||
2360 | #fig=self.figures[0] |
|
2360 | #fig=self.figures[0] | |
2361 | else: |
|
2361 | else: | |
2362 | #plt.clf() |
|
2362 | #plt.clf() | |
2363 | print("ELSE PLOT") |
|
2363 | print("ELSE PLOT") | |
2364 | cgax, pm = wrl.vis.plot_rhi(res_weather,r=r,th=self.res_ele,ax=subplots[i], proj='cg',vmin=20, vmax=80) |
|
2364 | cgax, pm = wrl.vis.plot_rhi(res_weather,r=r,th=self.res_ele,ax=subplots[i], proj='cg',vmin=20, vmax=80) | |
2365 | #cgax, pm = wrl.vis.plot_rhi(data['weather'][i][:,r_mask],r=r,th=data['ele'],ax=subplots[i], proj='cg',vmin=20, vmax=80) |
|
2365 | #cgax, pm = wrl.vis.plot_rhi(data['weather'][i][:,r_mask],r=r,th=data['ele'],ax=subplots[i], proj='cg',vmin=20, vmax=80) | |
2366 | gh = cgax.get_grid_helper() |
|
2366 | gh = cgax.get_grid_helper() | |
2367 | locs = numpy.linspace(ang_min,ang_max,var_ang+1) |
|
2367 | locs = numpy.linspace(ang_min,ang_max,var_ang+1) | |
2368 | gh.grid_finder.grid_locator1 = FixedLocator(locs) |
|
2368 | gh.grid_finder.grid_locator1 = FixedLocator(locs) | |
2369 | gh.grid_finder.tick_formatter1 = DictFormatter(dict([(i, r"${0:.0f}^\circ$".format(i)) for i in locs])) |
|
2369 | gh.grid_finder.tick_formatter1 = DictFormatter(dict([(i, r"${0:.0f}^\circ$".format(i)) for i in locs])) | |
2370 |
|
2370 | |||
2371 | caax = cgax.parasites[0] |
|
2371 | caax = cgax.parasites[0] | |
2372 | paax = cgax.parasites[1] |
|
2372 | paax = cgax.parasites[1] | |
2373 | cbar = plt.gcf().colorbar(pm, pad=0.075) |
|
2373 | cbar = plt.gcf().colorbar(pm, pad=0.075) | |
2374 | caax.set_xlabel('x_range [km]') |
|
2374 | caax.set_xlabel('x_range [km]') | |
2375 | caax.set_ylabel('y_range [km]') |
|
2375 | caax.set_ylabel('y_range [km]') | |
2376 | plt.text(1.0, 1.05, 'Elevacion '+str(thisDatetime)+" Step "+str(self.ini)+ " Azi: "+str(round(self.res_azi,2)), transform=caax.transAxes, va='bottom',ha='right') |
|
2376 | plt.text(1.0, 1.05, 'Elevacion '+str(thisDatetime)+" Step "+str(self.ini)+ " Azi: "+str(round(self.res_azi,2)), transform=caax.transAxes, va='bottom',ha='right') | |
2377 | print("***************************self.ini****************************",self.ini) |
|
2377 | print("***************************self.ini****************************",self.ini) | |
2378 | self.ini= self.ini+1 |
|
2378 | self.ini= self.ini+1 | |
|
2379 | ||||
|
2380 | class WeatherRHI_vRF4_Plot(Plot): | |||
|
2381 | CODE = 'weather' | |||
|
2382 | plot_name = 'weather' | |||
|
2383 | #plot_type = 'rhistyle' | |||
|
2384 | buffering = False | |||
|
2385 | data_ele_tmp = None | |||
|
2386 | ||||
|
2387 | def setup(self): | |||
|
2388 | ||||
|
2389 | self.ncols = 1 | |||
|
2390 | self.nrows = 1 | |||
|
2391 | self.nplots= 1 | |||
|
2392 | self.ylabel= 'Range [Km]' | |||
|
2393 | self.titles= ['Weather'] | |||
|
2394 | self.polar = True | |||
|
2395 | if self.channels is not None: | |||
|
2396 | self.nplots = len(self.channels) | |||
|
2397 | self.nrows = len(self.channels) | |||
|
2398 | else: | |||
|
2399 | self.nplots = self.data.shape(self.CODE)[0] | |||
|
2400 | self.nrows = self.nplots | |||
|
2401 | self.channels = list(range(self.nplots)) | |||
|
2402 | #print("JERE") | |||
|
2403 | #exit(1) | |||
|
2404 | #print("channels",self.channels) | |||
|
2405 | #print("que saldra", self.data.shape(self.CODE)[0]) | |||
|
2406 | #self.titles = ['{} Channel {}'.format(self.CODE.upper(), x) for x in range(self.nrows)] | |||
|
2407 | ||||
|
2408 | #print("self.titles",self.titles) | |||
|
2409 | if self.CODE == 'Power': | |||
|
2410 | self.cb_label = r'Power (dB)' | |||
|
2411 | elif self.CODE == 'Doppler': | |||
|
2412 | self.cb_label = r'Velocity (m/s)' | |||
|
2413 | self.colorbar=True | |||
|
2414 | self.width =8 | |||
|
2415 | self.height =8 | |||
|
2416 | self.ini =0 | |||
|
2417 | self.len_azi =0 | |||
|
2418 | self.buffer_ini = None | |||
|
2419 | self.buffer_ele = None | |||
|
2420 | self.plots_adjust.update({'wspace': 0.4, 'hspace':0.4, 'left': 0.1, 'right': 0.9, 'bottom': 0.08}) | |||
|
2421 | self.flag =0 | |||
|
2422 | self.indicador= 0 | |||
|
2423 | self.last_data_ele = None | |||
|
2424 | self.val_mean = None | |||
|
2425 | ||||
|
2426 | def update(self, dataOut): | |||
|
2427 | ||||
|
2428 | if self.mode == 'Power': | |||
|
2429 | self.CODE = 'Power' | |||
|
2430 | elif self.mode == 'Doppler': | |||
|
2431 | self.CODE = 'Doppler' | |||
|
2432 | ||||
|
2433 | data = {} | |||
|
2434 | meta = {} | |||
|
2435 | if hasattr(dataOut, 'dataPP_POWER'): | |||
|
2436 | factor = 1 | |||
|
2437 | if hasattr(dataOut, 'nFFTPoints'): | |||
|
2438 | factor = dataOut.normFactor | |||
|
2439 | ||||
|
2440 | if self.CODE == 'Power': | |||
|
2441 | data[self.CODE] = 10*numpy.log10(dataOut.data_360_Power/(factor)) | |||
|
2442 | elif self.CODE == 'Doppler': | |||
|
2443 | data[self.CODE] = dataOut.data_360_Velocity/(factor) | |||
|
2444 | ||||
|
2445 | data['azi'] = dataOut.data_azi | |||
|
2446 | data['ele'] = dataOut.data_ele | |||
|
2447 | ||||
|
2448 | return data, meta | |||
|
2449 | ||||
|
2450 | def plot(self): | |||
|
2451 | thisDatetime = datetime.datetime.utcfromtimestamp(self.data.times[-1]).strftime('%Y-%m-%d %H:%M:%S') | |||
|
2452 | data = self.data[-1] | |||
|
2453 | r = self.data.yrange | |||
|
2454 | delta_height = r[1]-r[0] | |||
|
2455 | r_mask = numpy.where(r>=0)[0] | |||
|
2456 | self.r_mask =r_mask | |||
|
2457 | r = numpy.arange(len(r_mask))*delta_height | |||
|
2458 | self.y = 2*r | |||
|
2459 | res = 1 | |||
|
2460 | ang_max = self.ang_max | |||
|
2461 | ang_min = self.ang_min | |||
|
2462 | var_ang =ang_max - ang_min | |||
|
2463 | step = (int(var_ang)/(res*data[self.CODE].shape[0])) | |||
|
2464 | ||||
|
2465 | z = data[self.CODE][self.channels[0]][:,r_mask] | |||
|
2466 | ||||
|
2467 | #print(z[2,:]) | |||
|
2468 | self.titles = [] | |||
|
2469 | ||||
|
2470 | #exit(1) | |||
|
2471 | ||||
|
2472 | if self.CODE == 'Power': | |||
|
2473 | cmap = 'jet' | |||
|
2474 | elif self.CODE == 'Doppler': | |||
|
2475 | cmap = 'RdBu' | |||
|
2476 | ||||
|
2477 | self.ymax = self.ymax if self.ymax else numpy.nanmax(r) | |||
|
2478 | self.ymin = self.ymin if self.ymin else numpy.nanmin(r) | |||
|
2479 | self.zmax = self.zmax if self.zmax else numpy.nanmax(z) | |||
|
2480 | self.zmin = self.zmin if self.zmin else numpy.nanmin(z) | |||
|
2481 | ||||
|
2482 | #plt.clf() | |||
|
2483 | subplots = [121, 122] | |||
|
2484 | ||||
|
2485 | r, theta = numpy.meshgrid(r, numpy.radians(data['ele']) ) | |||
|
2486 | ||||
|
2487 | points_cb = 200 | |||
|
2488 | mylevs_cbar = list(numpy.linspace(self.zmin,self.zmax,points_cb)) #niveles de la barra de colores | |||
|
2489 | ||||
|
2490 | for i,ax in enumerate(self.axes): | |||
|
2491 | ||||
|
2492 | if ax.firsttime: | |||
|
2493 | ax.set_xlim(numpy.radians(self.ang_min),numpy.radians(self.ang_max)) | |||
|
2494 | ax.plt = ax.contourf(theta, r, z, points_cb, cmap=cmap, vmin=self.zmin, vmax=self.zmax, levels=mylevs_cbar) | |||
|
2495 | #print(ax.plt) | |||
|
2496 | #exit(1) | |||
|
2497 | ''' | |||
|
2498 | self.figures[-1].colorbar(plt, orientation="vertical", fraction=0.025, pad=0.07) | |||
|
2499 | print(self.figures[0]) | |||
|
2500 | print(self.figures) | |||
|
2501 | print(plt) | |||
|
2502 | print(ax) | |||
|
2503 | exit(1) | |||
|
2504 | ''' | |||
|
2505 | ||||
|
2506 | else: | |||
|
2507 | ax.set_xlim(numpy.radians(self.ang_min),numpy.radians(self.ang_max)) | |||
|
2508 | ax.plt = ax.contourf(theta, r, z, points_cb, cmap=cmap, vmin=self.zmin, vmax=self.zmax, levels=mylevs_cbar) | |||
|
2509 | #self.figures[0].colorbar(plt, orientation="vertical", fraction=0.025, pad=0.07) | |||
|
2510 | ||||
|
2511 | #print(self.titles) | |||
|
2512 | if len(self.channels) !=1: | |||
|
2513 | self.titles = ['{} Azi: {} Channel {}'.format(self.CODE.upper(), str(round(numpy.mean(data['azi']),2)), x) for x in range(self.nrows)] | |||
|
2514 | else: | |||
|
2515 | self.titles = ['{} Azi: {} Channel {}'.format(self.CODE.upper(), str(round(numpy.mean(data['azi']),2)), self.channels[0])] | |||
|
2516 | #self.titles.append('Azi: {}'.format(str(round(numpy.mean(data['azi']),2)))) | |||
|
2517 | #self.titles.append(str(round(numpy.mean(data['azi']),2))) | |||
|
2518 | #print(self.titles) | |||
|
2519 | #plt.text(1.0, 1.05, str(thisDatetime)+ " Azi: "+str(round(numpy.mean(data['azi']),2)), transform=caax.transAxes, va='bottom',ha='right') | |||
|
2520 | #print("***************************self.ini****************************",self.ini) | |||
|
2521 | #self.figures[-1].colorbar(plt, orientation="vertical", fraction=0.025, pad=0.07) | |||
|
2522 | #self.ini= self.ini+1 |
@@ -1,703 +1,714 | |||||
1 | import os |
|
1 | import os | |
2 | import time |
|
2 | import time | |
3 | import datetime |
|
3 | import datetime | |
4 |
|
4 | |||
5 | import numpy |
|
5 | import numpy | |
6 | import h5py |
|
6 | import h5py | |
7 |
|
7 | |||
8 | import schainpy.admin |
|
8 | import schainpy.admin | |
9 | from schainpy.model.data.jrodata import * |
|
9 | from schainpy.model.data.jrodata import * | |
10 | from schainpy.model.proc.jroproc_base import ProcessingUnit, Operation, MPDecorator |
|
10 | from schainpy.model.proc.jroproc_base import ProcessingUnit, Operation, MPDecorator | |
11 | from schainpy.model.io.jroIO_base import * |
|
11 | from schainpy.model.io.jroIO_base import * | |
12 | from schainpy.utils import log |
|
12 | from schainpy.utils import log | |
13 |
|
13 | |||
14 |
|
14 | |||
15 | class HDFReader(Reader, ProcessingUnit): |
|
15 | class HDFReader(Reader, ProcessingUnit): | |
16 | """Processing unit to read HDF5 format files |
|
16 | """Processing unit to read HDF5 format files | |
17 |
|
17 | |||
18 | This unit reads HDF5 files created with `HDFWriter` operation contains |
|
18 | This unit reads HDF5 files created with `HDFWriter` operation contains | |
19 | by default two groups Data and Metadata all variables would be saved as `dataOut` |
|
19 | by default two groups Data and Metadata all variables would be saved as `dataOut` | |
20 | attributes. |
|
20 | attributes. | |
21 | It is possible to read any HDF5 file by given the structure in the `description` |
|
21 | It is possible to read any HDF5 file by given the structure in the `description` | |
22 | parameter, also you can add extra values to metadata with the parameter `extras`. |
|
22 | parameter, also you can add extra values to metadata with the parameter `extras`. | |
23 |
|
23 | |||
24 | Parameters: |
|
24 | Parameters: | |
25 | ----------- |
|
25 | ----------- | |
26 | path : str |
|
26 | path : str | |
27 | Path where files are located. |
|
27 | Path where files are located. | |
28 | startDate : date |
|
28 | startDate : date | |
29 | Start date of the files |
|
29 | Start date of the files | |
30 | endDate : list |
|
30 | endDate : list | |
31 | End date of the files |
|
31 | End date of the files | |
32 | startTime : time |
|
32 | startTime : time | |
33 | Start time of the files |
|
33 | Start time of the files | |
34 | endTime : time |
|
34 | endTime : time | |
35 | End time of the files |
|
35 | End time of the files | |
36 | description : dict, optional |
|
36 | description : dict, optional | |
37 | Dictionary with the description of the HDF5 file |
|
37 | Dictionary with the description of the HDF5 file | |
38 | extras : dict, optional |
|
38 | extras : dict, optional | |
39 | Dictionary with extra metadata to be be added to `dataOut` |
|
39 | Dictionary with extra metadata to be be added to `dataOut` | |
40 |
|
40 | |||
41 | Examples |
|
41 | Examples | |
42 | -------- |
|
42 | -------- | |
43 |
|
43 | |||
44 | desc = { |
|
44 | desc = { | |
45 | 'Data': { |
|
45 | 'Data': { | |
46 | 'data_output': ['u', 'v', 'w'], |
|
46 | 'data_output': ['u', 'v', 'w'], | |
47 | 'utctime': 'timestamps', |
|
47 | 'utctime': 'timestamps', | |
48 | } , |
|
48 | } , | |
49 | 'Metadata': { |
|
49 | 'Metadata': { | |
50 | 'heightList': 'heights' |
|
50 | 'heightList': 'heights' | |
51 | } |
|
51 | } | |
52 | } |
|
52 | } | |
53 |
|
53 | |||
54 | desc = { |
|
54 | desc = { | |
55 | 'Data': { |
|
55 | 'Data': { | |
56 | 'data_output': 'winds', |
|
56 | 'data_output': 'winds', | |
57 | 'utctime': 'timestamps' |
|
57 | 'utctime': 'timestamps' | |
58 | }, |
|
58 | }, | |
59 | 'Metadata': { |
|
59 | 'Metadata': { | |
60 | 'heightList': 'heights' |
|
60 | 'heightList': 'heights' | |
61 | } |
|
61 | } | |
62 | } |
|
62 | } | |
63 |
|
63 | |||
64 | extras = { |
|
64 | extras = { | |
65 | 'timeZone': 300 |
|
65 | 'timeZone': 300 | |
66 | } |
|
66 | } | |
67 |
|
67 | |||
68 | reader = project.addReadUnit( |
|
68 | reader = project.addReadUnit( | |
69 | name='HDFReader', |
|
69 | name='HDFReader', | |
70 | path='/path/to/files', |
|
70 | path='/path/to/files', | |
71 | startDate='2019/01/01', |
|
71 | startDate='2019/01/01', | |
72 | endDate='2019/01/31', |
|
72 | endDate='2019/01/31', | |
73 | startTime='00:00:00', |
|
73 | startTime='00:00:00', | |
74 | endTime='23:59:59', |
|
74 | endTime='23:59:59', | |
75 | # description=json.dumps(desc), |
|
75 | # description=json.dumps(desc), | |
76 | # extras=json.dumps(extras), |
|
76 | # extras=json.dumps(extras), | |
77 | ) |
|
77 | ) | |
78 |
|
78 | |||
79 | """ |
|
79 | """ | |
80 |
|
80 | |||
81 | __attrs__ = ['path', 'startDate', 'endDate', 'startTime', 'endTime', 'description', 'extras'] |
|
81 | __attrs__ = ['path', 'startDate', 'endDate', 'startTime', 'endTime', 'description', 'extras'] | |
82 |
|
82 | |||
83 | def __init__(self): |
|
83 | def __init__(self): | |
84 | ProcessingUnit.__init__(self) |
|
84 | ProcessingUnit.__init__(self) | |
85 | self.dataOut = Parameters() |
|
85 | self.dataOut = Parameters() | |
86 | self.ext = ".hdf5" |
|
86 | self.ext = ".hdf5" | |
87 | self.optchar = "D" |
|
87 | self.optchar = "D" | |
88 | self.meta = {} |
|
88 | self.meta = {} | |
89 | self.data = {} |
|
89 | self.data = {} | |
90 | self.open_file = h5py.File |
|
90 | self.open_file = h5py.File | |
91 | self.open_mode = 'r' |
|
91 | self.open_mode = 'r' | |
92 | self.description = {} |
|
92 | self.description = {} | |
93 | self.extras = {} |
|
93 | self.extras = {} | |
94 | self.filefmt = "*%Y%j***" |
|
94 | self.filefmt = "*%Y%j***" | |
95 | self.folderfmt = "*%Y%j" |
|
95 | self.folderfmt = "*%Y%j" | |
96 | self.utcoffset = 0 |
|
96 | self.utcoffset = 0 | |
97 |
|
97 | |||
98 | def setup(self, **kwargs): |
|
98 | def setup(self, **kwargs): | |
99 |
|
99 | |||
100 | self.set_kwargs(**kwargs) |
|
100 | self.set_kwargs(**kwargs) | |
101 | if not self.ext.startswith('.'): |
|
101 | if not self.ext.startswith('.'): | |
102 | self.ext = '.{}'.format(self.ext) |
|
102 | self.ext = '.{}'.format(self.ext) | |
103 |
|
103 | |||
104 | if self.online: |
|
104 | if self.online: | |
105 | log.log("Searching files in online mode...", self.name) |
|
105 | log.log("Searching files in online mode...", self.name) | |
106 |
|
106 | |||
107 | for nTries in range(self.nTries): |
|
107 | for nTries in range(self.nTries): | |
108 | fullpath = self.searchFilesOnLine(self.path, self.startDate, |
|
108 | fullpath = self.searchFilesOnLine(self.path, self.startDate, | |
109 | self.endDate, self.expLabel, self.ext, self.walk, |
|
109 | self.endDate, self.expLabel, self.ext, self.walk, | |
110 | self.filefmt, self.folderfmt) |
|
110 | self.filefmt, self.folderfmt) | |
111 | try: |
|
111 | try: | |
112 | fullpath = next(fullpath) |
|
112 | fullpath = next(fullpath) | |
113 | except: |
|
113 | except: | |
114 | fullpath = None |
|
114 | fullpath = None | |
115 |
|
115 | |||
116 | if fullpath: |
|
116 | if fullpath: | |
117 | break |
|
117 | break | |
118 |
|
118 | |||
119 | log.warning( |
|
119 | log.warning( | |
120 | 'Waiting {} sec for a valid file in {}: try {} ...'.format( |
|
120 | 'Waiting {} sec for a valid file in {}: try {} ...'.format( | |
121 | self.delay, self.path, nTries + 1), |
|
121 | self.delay, self.path, nTries + 1), | |
122 | self.name) |
|
122 | self.name) | |
123 | time.sleep(self.delay) |
|
123 | time.sleep(self.delay) | |
124 |
|
124 | |||
125 | if not(fullpath): |
|
125 | if not(fullpath): | |
126 | raise schainpy.admin.SchainError( |
|
126 | raise schainpy.admin.SchainError( | |
127 | 'There isn\'t any valid file in {}'.format(self.path)) |
|
127 | 'There isn\'t any valid file in {}'.format(self.path)) | |
128 |
|
128 | |||
129 | pathname, filename = os.path.split(fullpath) |
|
129 | pathname, filename = os.path.split(fullpath) | |
130 | self.year = int(filename[1:5]) |
|
130 | self.year = int(filename[1:5]) | |
131 | self.doy = int(filename[5:8]) |
|
131 | self.doy = int(filename[5:8]) | |
132 | self.set = int(filename[8:11]) - 1 |
|
132 | self.set = int(filename[8:11]) - 1 | |
133 | else: |
|
133 | else: | |
134 | log.log("Searching files in {}".format(self.path), self.name) |
|
134 | log.log("Searching files in {}".format(self.path), self.name) | |
135 | self.filenameList = self.searchFilesOffLine(self.path, self.startDate, |
|
135 | self.filenameList = self.searchFilesOffLine(self.path, self.startDate, | |
136 | self.endDate, self.expLabel, self.ext, self.walk, self.filefmt, self.folderfmt) |
|
136 | self.endDate, self.expLabel, self.ext, self.walk, self.filefmt, self.folderfmt) | |
137 |
|
137 | |||
138 | self.setNextFile() |
|
138 | self.setNextFile() | |
139 |
|
139 | |||
140 | return |
|
140 | return | |
141 |
|
141 | |||
142 | def readFirstHeader(self): |
|
142 | def readFirstHeader(self): | |
143 | '''Read metadata and data''' |
|
143 | '''Read metadata and data''' | |
144 |
|
144 | |||
145 | self.__readMetadata() |
|
145 | self.__readMetadata() | |
146 | self.__readData() |
|
146 | self.__readData() | |
147 | self.__setBlockList() |
|
147 | self.__setBlockList() | |
148 |
|
148 | |||
149 | if 'type' in self.meta: |
|
149 | if 'type' in self.meta: | |
150 | self.dataOut = eval(self.meta['type'])() |
|
150 | self.dataOut = eval(self.meta['type'])() | |
151 |
|
151 | |||
152 | for attr in self.meta: |
|
152 | for attr in self.meta: | |
153 | setattr(self.dataOut, attr, self.meta[attr]) |
|
153 | setattr(self.dataOut, attr, self.meta[attr]) | |
154 |
|
154 | |||
155 | self.blockIndex = 0 |
|
155 | self.blockIndex = 0 | |
156 |
|
156 | |||
157 | return |
|
157 | return | |
158 |
|
158 | |||
159 | def __setBlockList(self): |
|
159 | def __setBlockList(self): | |
160 | ''' |
|
160 | ''' | |
161 | Selects the data within the times defined |
|
161 | Selects the data within the times defined | |
162 |
|
162 | |||
163 | self.fp |
|
163 | self.fp | |
164 | self.startTime |
|
164 | self.startTime | |
165 | self.endTime |
|
165 | self.endTime | |
166 | self.blockList |
|
166 | self.blockList | |
167 | self.blocksPerFile |
|
167 | self.blocksPerFile | |
168 |
|
168 | |||
169 | ''' |
|
169 | ''' | |
170 |
|
170 | |||
171 | startTime = self.startTime |
|
171 | startTime = self.startTime | |
172 | endTime = self.endTime |
|
172 | endTime = self.endTime | |
173 | thisUtcTime = self.data['utctime'] + self.utcoffset |
|
173 | thisUtcTime = self.data['utctime'] + self.utcoffset | |
174 | self.interval = numpy.min(thisUtcTime[1:] - thisUtcTime[:-1]) |
|
174 | self.interval = numpy.min(thisUtcTime[1:] - thisUtcTime[:-1]) | |
175 | thisDatetime = datetime.datetime.utcfromtimestamp(thisUtcTime[0]) |
|
175 | thisDatetime = datetime.datetime.utcfromtimestamp(thisUtcTime[0]) | |
176 |
|
176 | |||
177 | thisDate = thisDatetime.date() |
|
177 | thisDate = thisDatetime.date() | |
178 | thisTime = thisDatetime.time() |
|
178 | thisTime = thisDatetime.time() | |
179 |
|
179 | |||
180 | startUtcTime = (datetime.datetime.combine(thisDate, startTime) - datetime.datetime(1970, 1, 1)).total_seconds() |
|
180 | startUtcTime = (datetime.datetime.combine(thisDate, startTime) - datetime.datetime(1970, 1, 1)).total_seconds() | |
181 | endUtcTime = (datetime.datetime.combine(thisDate, endTime) - datetime.datetime(1970, 1, 1)).total_seconds() |
|
181 | endUtcTime = (datetime.datetime.combine(thisDate, endTime) - datetime.datetime(1970, 1, 1)).total_seconds() | |
182 |
|
182 | |||
183 | ind = numpy.where(numpy.logical_and(thisUtcTime >= startUtcTime, thisUtcTime < endUtcTime))[0] |
|
183 | ind = numpy.where(numpy.logical_and(thisUtcTime >= startUtcTime, thisUtcTime < endUtcTime))[0] | |
184 |
|
184 | |||
185 | self.blockList = ind |
|
185 | self.blockList = ind | |
186 | self.blocksPerFile = len(ind) |
|
186 | self.blocksPerFile = len(ind) | |
187 | return |
|
187 | return | |
188 |
|
188 | |||
189 | def __readMetadata(self): |
|
189 | def __readMetadata(self): | |
190 | ''' |
|
190 | ''' | |
191 | Reads Metadata |
|
191 | Reads Metadata | |
192 | ''' |
|
192 | ''' | |
193 |
|
193 | |||
194 | meta = {} |
|
194 | meta = {} | |
195 |
|
195 | |||
196 | if self.description: |
|
196 | if self.description: | |
197 | for key, value in self.description['Metadata'].items(): |
|
197 | for key, value in self.description['Metadata'].items(): | |
198 | meta[key] = self.fp[value][()] |
|
198 | meta[key] = self.fp[value][()] | |
199 | else: |
|
199 | else: | |
200 | grp = self.fp['Metadata'] |
|
200 | grp = self.fp['Metadata'] | |
201 | for name in grp: |
|
201 | for name in grp: | |
202 | meta[name] = grp[name][()] |
|
202 | meta[name] = grp[name][()] | |
203 |
|
203 | |||
204 | if self.extras: |
|
204 | if self.extras: | |
205 | for key, value in self.extras.items(): |
|
205 | for key, value in self.extras.items(): | |
206 | meta[key] = value |
|
206 | meta[key] = value | |
207 | self.meta = meta |
|
207 | self.meta = meta | |
208 |
|
208 | |||
209 | return |
|
209 | return | |
210 |
|
210 | |||
211 | def __readData(self): |
|
211 | def __readData(self): | |
212 |
|
212 | |||
213 | data = {} |
|
213 | data = {} | |
214 |
|
214 | |||
215 | if self.description: |
|
215 | if self.description: | |
216 | for key, value in self.description['Data'].items(): |
|
216 | for key, value in self.description['Data'].items(): | |
217 | if isinstance(value, str): |
|
217 | if isinstance(value, str): | |
218 | if isinstance(self.fp[value], h5py.Dataset): |
|
218 | if isinstance(self.fp[value], h5py.Dataset): | |
219 | data[key] = self.fp[value][()] |
|
219 | data[key] = self.fp[value][()] | |
220 | elif isinstance(self.fp[value], h5py.Group): |
|
220 | elif isinstance(self.fp[value], h5py.Group): | |
221 | array = [] |
|
221 | array = [] | |
222 | for ch in self.fp[value]: |
|
222 | for ch in self.fp[value]: | |
223 | array.append(self.fp[value][ch][()]) |
|
223 | array.append(self.fp[value][ch][()]) | |
224 | data[key] = numpy.array(array) |
|
224 | data[key] = numpy.array(array) | |
225 | elif isinstance(value, list): |
|
225 | elif isinstance(value, list): | |
226 | array = [] |
|
226 | array = [] | |
227 | for ch in value: |
|
227 | for ch in value: | |
228 | array.append(self.fp[ch][()]) |
|
228 | array.append(self.fp[ch][()]) | |
229 | data[key] = numpy.array(array) |
|
229 | data[key] = numpy.array(array) | |
230 | else: |
|
230 | else: | |
231 | grp = self.fp['Data'] |
|
231 | grp = self.fp['Data'] | |
232 | for name in grp: |
|
232 | for name in grp: | |
233 | if isinstance(grp[name], h5py.Dataset): |
|
233 | if isinstance(grp[name], h5py.Dataset): | |
234 | array = grp[name][()] |
|
234 | array = grp[name][()] | |
235 | elif isinstance(grp[name], h5py.Group): |
|
235 | elif isinstance(grp[name], h5py.Group): | |
236 | array = [] |
|
236 | array = [] | |
237 | for ch in grp[name]: |
|
237 | for ch in grp[name]: | |
238 | array.append(grp[name][ch][()]) |
|
238 | array.append(grp[name][ch][()]) | |
239 | array = numpy.array(array) |
|
239 | array = numpy.array(array) | |
240 | else: |
|
240 | else: | |
241 | log.warning('Unknown type: {}'.format(name)) |
|
241 | log.warning('Unknown type: {}'.format(name)) | |
242 |
|
242 | |||
243 | if name in self.description: |
|
243 | if name in self.description: | |
244 | key = self.description[name] |
|
244 | key = self.description[name] | |
245 | else: |
|
245 | else: | |
246 | key = name |
|
246 | key = name | |
247 | data[key] = array |
|
247 | data[key] = array | |
248 |
|
248 | |||
249 | self.data = data |
|
249 | self.data = data | |
250 | return |
|
250 | return | |
251 |
|
251 | |||
252 | def getData(self): |
|
252 | def getData(self): | |
253 |
|
253 | |||
254 | for attr in self.data: |
|
254 | for attr in self.data: | |
255 | if self.data[attr].ndim == 1: |
|
255 | if self.data[attr].ndim == 1: | |
256 | setattr(self.dataOut, attr, self.data[attr][self.blockIndex]) |
|
256 | setattr(self.dataOut, attr, self.data[attr][self.blockIndex]) | |
257 | else: |
|
257 | else: | |
258 | setattr(self.dataOut, attr, self.data[attr][:, self.blockIndex]) |
|
258 | setattr(self.dataOut, attr, self.data[attr][:, self.blockIndex]) | |
259 |
|
259 | |||
260 | self.dataOut.flagNoData = False |
|
260 | self.dataOut.flagNoData = False | |
261 | self.blockIndex += 1 |
|
261 | self.blockIndex += 1 | |
262 |
|
262 | |||
263 | log.log("Block No. {}/{} -> {}".format( |
|
263 | log.log("Block No. {}/{} -> {}".format( | |
264 | self.blockIndex, |
|
264 | self.blockIndex, | |
265 | self.blocksPerFile, |
|
265 | self.blocksPerFile, | |
266 | self.dataOut.datatime.ctime()), self.name) |
|
266 | self.dataOut.datatime.ctime()), self.name) | |
267 |
|
267 | |||
268 | return |
|
268 | return | |
269 |
|
269 | |||
270 | def run(self, **kwargs): |
|
270 | def run(self, **kwargs): | |
271 |
|
271 | |||
272 | if not(self.isConfig): |
|
272 | if not(self.isConfig): | |
273 | self.setup(**kwargs) |
|
273 | self.setup(**kwargs) | |
274 | self.isConfig = True |
|
274 | self.isConfig = True | |
275 |
|
275 | |||
276 | if self.blockIndex == self.blocksPerFile: |
|
276 | if self.blockIndex == self.blocksPerFile: | |
277 | self.setNextFile() |
|
277 | self.setNextFile() | |
278 |
|
278 | |||
279 | self.getData() |
|
279 | self.getData() | |
280 |
|
280 | |||
281 | return |
|
281 | return | |
282 |
|
282 | |||
283 | @MPDecorator |
|
283 | @MPDecorator | |
284 | class HDFWriter(Operation): |
|
284 | class HDFWriter(Operation): | |
285 | """Operation to write HDF5 files. |
|
285 | """Operation to write HDF5 files. | |
286 |
|
286 | |||
287 | The HDF5 file contains by default two groups Data and Metadata where |
|
287 | The HDF5 file contains by default two groups Data and Metadata where | |
288 | you can save any `dataOut` attribute specified by `dataList` and `metadataList` |
|
288 | you can save any `dataOut` attribute specified by `dataList` and `metadataList` | |
289 | parameters, data attributes are normaly time dependent where the metadata |
|
289 | parameters, data attributes are normaly time dependent where the metadata | |
290 | are not. |
|
290 | are not. | |
291 | It is possible to customize the structure of the HDF5 file with the |
|
291 | It is possible to customize the structure of the HDF5 file with the | |
292 | optional description parameter see the examples. |
|
292 | optional description parameter see the examples. | |
293 |
|
293 | |||
294 | Parameters: |
|
294 | Parameters: | |
295 | ----------- |
|
295 | ----------- | |
296 | path : str |
|
296 | path : str | |
297 | Path where files will be saved. |
|
297 | Path where files will be saved. | |
298 | blocksPerFile : int |
|
298 | blocksPerFile : int | |
299 | Number of blocks per file |
|
299 | Number of blocks per file | |
300 | metadataList : list |
|
300 | metadataList : list | |
301 | List of the dataOut attributes that will be saved as metadata |
|
301 | List of the dataOut attributes that will be saved as metadata | |
302 | dataList : int |
|
302 | dataList : int | |
303 | List of the dataOut attributes that will be saved as data |
|
303 | List of the dataOut attributes that will be saved as data | |
304 | setType : bool |
|
304 | setType : bool | |
305 | If True the name of the files corresponds to the timestamp of the data |
|
305 | If True the name of the files corresponds to the timestamp of the data | |
306 | description : dict, optional |
|
306 | description : dict, optional | |
307 | Dictionary with the desired description of the HDF5 file |
|
307 | Dictionary with the desired description of the HDF5 file | |
308 |
|
308 | |||
309 | Examples |
|
309 | Examples | |
310 | -------- |
|
310 | -------- | |
311 |
|
311 | |||
312 | desc = { |
|
312 | desc = { | |
313 | 'data_output': {'winds': ['z', 'w', 'v']}, |
|
313 | 'data_output': {'winds': ['z', 'w', 'v']}, | |
314 | 'utctime': 'timestamps', |
|
314 | 'utctime': 'timestamps', | |
315 | 'heightList': 'heights' |
|
315 | 'heightList': 'heights' | |
316 | } |
|
316 | } | |
317 | desc = { |
|
317 | desc = { | |
318 | 'data_output': ['z', 'w', 'v'], |
|
318 | 'data_output': ['z', 'w', 'v'], | |
319 | 'utctime': 'timestamps', |
|
319 | 'utctime': 'timestamps', | |
320 | 'heightList': 'heights' |
|
320 | 'heightList': 'heights' | |
321 | } |
|
321 | } | |
322 | desc = { |
|
322 | desc = { | |
323 | 'Data': { |
|
323 | 'Data': { | |
324 | 'data_output': 'winds', |
|
324 | 'data_output': 'winds', | |
325 | 'utctime': 'timestamps' |
|
325 | 'utctime': 'timestamps' | |
326 | }, |
|
326 | }, | |
327 | 'Metadata': { |
|
327 | 'Metadata': { | |
328 | 'heightList': 'heights' |
|
328 | 'heightList': 'heights' | |
329 | } |
|
329 | } | |
330 | } |
|
330 | } | |
331 |
|
331 | |||
332 | writer = proc_unit.addOperation(name='HDFWriter') |
|
332 | writer = proc_unit.addOperation(name='HDFWriter') | |
333 | writer.addParameter(name='path', value='/path/to/file') |
|
333 | writer.addParameter(name='path', value='/path/to/file') | |
334 | writer.addParameter(name='blocksPerFile', value='32') |
|
334 | writer.addParameter(name='blocksPerFile', value='32') | |
335 | writer.addParameter(name='metadataList', value='heightList,timeZone') |
|
335 | writer.addParameter(name='metadataList', value='heightList,timeZone') | |
336 | writer.addParameter(name='dataList',value='data_output,utctime') |
|
336 | writer.addParameter(name='dataList',value='data_output,utctime') | |
337 | # writer.addParameter(name='description',value=json.dumps(desc)) |
|
337 | # writer.addParameter(name='description',value=json.dumps(desc)) | |
338 |
|
338 | |||
339 | """ |
|
339 | """ | |
340 |
|
340 | |||
341 | ext = ".hdf5" |
|
341 | ext = ".hdf5" | |
342 | optchar = "D" |
|
342 | optchar = "D" | |
343 | filename = None |
|
343 | filename = None | |
344 | path = None |
|
344 | path = None | |
345 | setFile = None |
|
345 | setFile = None | |
346 | fp = None |
|
346 | fp = None | |
347 | firsttime = True |
|
347 | firsttime = True | |
348 | #Configurations |
|
348 | #Configurations | |
349 | blocksPerFile = None |
|
349 | blocksPerFile = None | |
350 | blockIndex = None |
|
350 | blockIndex = None | |
351 | dataOut = None |
|
351 | dataOut = None | |
352 | #Data Arrays |
|
352 | #Data Arrays | |
353 | dataList = None |
|
353 | dataList = None | |
354 | metadataList = None |
|
354 | metadataList = None | |
355 | currentDay = None |
|
355 | currentDay = None | |
356 | lastTime = None |
|
356 | lastTime = None | |
357 | last_Azipos = None |
|
357 | last_Azipos = None | |
358 | last_Elepos = None |
|
358 | last_Elepos = None | |
359 | mode = None |
|
359 | mode = None | |
360 | #----------------------- |
|
360 | #----------------------- | |
361 | Typename = None |
|
361 | Typename = None | |
362 |
|
362 | |||
363 |
|
363 | |||
364 |
|
364 | |||
365 | def __init__(self): |
|
365 | def __init__(self): | |
366 |
|
366 | |||
367 | Operation.__init__(self) |
|
367 | Operation.__init__(self) | |
368 | return |
|
368 | return | |
369 |
|
369 | |||
370 |
|
370 | |||
371 | def set_kwargs(self, **kwargs): |
|
371 | def set_kwargs(self, **kwargs): | |
372 |
|
372 | |||
373 | for key, value in kwargs.items(): |
|
373 | for key, value in kwargs.items(): | |
374 | setattr(self, key, value) |
|
374 | setattr(self, key, value) | |
375 |
|
375 | |||
376 | def set_kwargs_obj(self,obj, **kwargs): |
|
376 | def set_kwargs_obj(self,obj, **kwargs): | |
377 |
|
377 | |||
378 | for key, value in kwargs.items(): |
|
378 | for key, value in kwargs.items(): | |
379 | setattr(obj, key, value) |
|
379 | setattr(obj, key, value) | |
380 |
|
380 | |||
381 | def generalFlag(self): |
|
381 | def generalFlag(self): | |
382 | ####rint("GENERALFLAG") |
|
382 | ####rint("GENERALFLAG") | |
383 | if self.mode== "weather": |
|
383 | if self.mode== "weather": | |
384 | if self.last_Azipos == None: |
|
384 | if self.last_Azipos == None: | |
385 | tmp = self.dataOut.azimuth |
|
385 | tmp = self.dataOut.azimuth | |
386 | ####print("ang azimuth writer",tmp) |
|
386 | ####print("ang azimuth writer",tmp) | |
387 | self.last_Azipos = tmp |
|
387 | self.last_Azipos = tmp | |
388 | flag = False |
|
388 | flag = False | |
389 | return flag |
|
389 | return flag | |
390 | ####print("ang_azimuth writer",self.dataOut.azimuth) |
|
390 | ####print("ang_azimuth writer",self.dataOut.azimuth) | |
391 | result = self.dataOut.azimuth - self.last_Azipos |
|
391 | result = self.dataOut.azimuth - self.last_Azipos | |
392 | self.last_Azipos = self.dataOut.azimuth |
|
392 | self.last_Azipos = self.dataOut.azimuth | |
393 | if result<0: |
|
393 | if result<0: | |
394 | flag = True |
|
394 | flag = True | |
395 | return flag |
|
395 | return flag | |
396 |
|
396 | |||
|
397 | def generalFlag_vRF(self): | |||
|
398 | ####rint("GENERALFLAG") | |||
|
399 | ||||
|
400 | try: | |||
|
401 | self.dataOut.flagBlock360Done | |||
|
402 | return self.dataOut.flagBlock360Done | |||
|
403 | except: | |||
|
404 | return 0 | |||
|
405 | ||||
|
406 | ||||
397 | def setup(self, path=None, blocksPerFile=10, metadataList=None, dataList=None, setType=None, description=None,type_data=None,**kwargs): |
|
407 | def setup(self, path=None, blocksPerFile=10, metadataList=None, dataList=None, setType=None, description=None,type_data=None,**kwargs): | |
398 | self.path = path |
|
408 | self.path = path | |
399 | self.blocksPerFile = blocksPerFile |
|
409 | self.blocksPerFile = blocksPerFile | |
400 | self.metadataList = metadataList |
|
410 | self.metadataList = metadataList | |
401 | self.dataList = [s.strip() for s in dataList] |
|
411 | self.dataList = [s.strip() for s in dataList] | |
|
412 | self.setType = setType | |||
402 | if self.mode == "weather": |
|
413 | if self.mode == "weather": | |
403 | self.setType = "weather" |
|
414 | self.setType = "weather" | |
404 | #---------------------------------------- |
|
415 | #---------------------------------------- | |
405 | self.set_kwargs(**kwargs) |
|
416 | self.set_kwargs(**kwargs) | |
406 | self.set_kwargs_obj(self.dataOut,**kwargs) |
|
417 | self.set_kwargs_obj(self.dataOut,**kwargs) | |
407 | #print("-----------------------------------------------------------",self.Typename) |
|
418 | #print("-----------------------------------------------------------",self.Typename) | |
408 | #print("hola",self.ContactInformation) |
|
419 | #print("hola",self.ContactInformation) | |
409 |
|
420 | |||
410 | self.description = description |
|
421 | self.description = description | |
411 | self.type_data=type_data |
|
422 | self.type_data=type_data | |
412 |
|
423 | |||
413 | if self.metadataList is None: |
|
424 | if self.metadataList is None: | |
414 | self.metadataList = self.dataOut.metadata_list |
|
425 | self.metadataList = self.dataOut.metadata_list | |
415 |
|
426 | |||
416 | tableList = [] |
|
427 | tableList = [] | |
417 | dsList = [] |
|
428 | dsList = [] | |
418 |
|
429 | |||
419 | for i in range(len(self.dataList)): |
|
430 | for i in range(len(self.dataList)): | |
420 | dsDict = {} |
|
431 | dsDict = {} | |
421 | if hasattr(self.dataOut, self.dataList[i]): |
|
432 | if hasattr(self.dataOut, self.dataList[i]): | |
422 | dataAux = getattr(self.dataOut, self.dataList[i]) |
|
433 | dataAux = getattr(self.dataOut, self.dataList[i]) | |
423 | dsDict['variable'] = self.dataList[i] |
|
434 | dsDict['variable'] = self.dataList[i] | |
424 | else: |
|
435 | else: | |
425 | log.warning('Attribute {} not found in dataOut', self.name) |
|
436 | log.warning('Attribute {} not found in dataOut', self.name) | |
426 | continue |
|
437 | continue | |
427 |
|
438 | |||
428 | if dataAux is None: |
|
439 | if dataAux is None: | |
429 | continue |
|
440 | continue | |
430 | elif isinstance(dataAux, (int, float, numpy.integer, numpy.float)): |
|
441 | elif isinstance(dataAux, (int, float, numpy.integer, numpy.float)): | |
431 | dsDict['nDim'] = 0 |
|
442 | dsDict['nDim'] = 0 | |
432 | else: |
|
443 | else: | |
433 | dsDict['nDim'] = len(dataAux.shape) |
|
444 | dsDict['nDim'] = len(dataAux.shape) | |
434 | dsDict['shape'] = dataAux.shape |
|
445 | dsDict['shape'] = dataAux.shape | |
435 | dsDict['dsNumber'] = dataAux.shape[0] |
|
446 | dsDict['dsNumber'] = dataAux.shape[0] | |
436 | dsDict['dtype'] = dataAux.dtype |
|
447 | dsDict['dtype'] = dataAux.dtype | |
437 |
|
448 | |||
438 | dsList.append(dsDict) |
|
449 | dsList.append(dsDict) | |
439 |
|
450 | |||
440 | self.dsList = dsList |
|
451 | self.dsList = dsList | |
441 | self.currentDay = self.dataOut.datatime.date() |
|
452 | self.currentDay = self.dataOut.datatime.date() | |
442 |
|
453 | |||
443 | def timeFlag(self): |
|
454 | def timeFlag(self): | |
444 | currentTime = self.dataOut.utctime |
|
455 | currentTime = self.dataOut.utctime | |
445 | timeTuple = time.localtime(currentTime) |
|
456 | timeTuple = time.localtime(currentTime) | |
446 | dataDay = timeTuple.tm_yday |
|
457 | dataDay = timeTuple.tm_yday | |
447 |
|
458 | |||
448 | if self.lastTime is None: |
|
459 | if self.lastTime is None: | |
449 | self.lastTime = currentTime |
|
460 | self.lastTime = currentTime | |
450 | self.currentDay = dataDay |
|
461 | self.currentDay = dataDay | |
451 | return False |
|
462 | return False | |
452 |
|
463 | |||
453 | timeDiff = currentTime - self.lastTime |
|
464 | timeDiff = currentTime - self.lastTime | |
454 |
|
465 | |||
455 | #Si el dia es diferente o si la diferencia entre un dato y otro supera la hora |
|
466 | #Si el dia es diferente o si la diferencia entre un dato y otro supera la hora | |
456 | if dataDay != self.currentDay: |
|
467 | if dataDay != self.currentDay: | |
457 | self.currentDay = dataDay |
|
468 | self.currentDay = dataDay | |
458 | return True |
|
469 | return True | |
459 | elif timeDiff > 3*60*60: |
|
470 | elif timeDiff > 3*60*60: | |
460 | self.lastTime = currentTime |
|
471 | self.lastTime = currentTime | |
461 | return True |
|
472 | return True | |
462 | else: |
|
473 | else: | |
463 | self.lastTime = currentTime |
|
474 | self.lastTime = currentTime | |
464 | return False |
|
475 | return False | |
465 |
|
476 | |||
466 | def run(self, dataOut, path, blocksPerFile=10, metadataList=None, |
|
477 | def run(self, dataOut, path, blocksPerFile=10, metadataList=None, | |
467 | dataList=[], setType=None, description={},mode= None,type_data=None,**kwargs): |
|
478 | dataList=[], setType=None, description={},mode= None,type_data=None,**kwargs): | |
468 |
|
479 | |||
469 | ###print("VOY A ESCRIBIR----------------------") |
|
480 | ###print("VOY A ESCRIBIR----------------------") | |
470 | #print("CHECKTHIS------------------------------------------------------------------*****---",**kwargs) |
|
481 | #print("CHECKTHIS------------------------------------------------------------------*****---",**kwargs) | |
471 | self.dataOut = dataOut |
|
482 | self.dataOut = dataOut | |
472 | self.mode = mode |
|
483 | self.mode = mode | |
473 | if not(self.isConfig): |
|
484 | if not(self.isConfig): | |
474 | self.setup(path=path, blocksPerFile=blocksPerFile, |
|
485 | self.setup(path=path, blocksPerFile=blocksPerFile, | |
475 | metadataList=metadataList, dataList=dataList, |
|
486 | metadataList=metadataList, dataList=dataList, | |
476 | setType=setType, description=description,type_data=type_data,**kwargs) |
|
487 | setType=setType, description=description,type_data=type_data,**kwargs) | |
477 |
|
488 | |||
478 | self.isConfig = True |
|
489 | self.isConfig = True | |
479 | self.setNextFile() |
|
490 | self.setNextFile() | |
480 |
|
491 | |||
481 | self.putData() |
|
492 | self.putData() | |
482 | return |
|
493 | return | |
483 |
|
494 | |||
484 | def setNextFile(self): |
|
495 | def setNextFile(self): | |
485 | ###print("HELLO WORLD--------------------------------") |
|
496 | ###print("HELLO WORLD--------------------------------") | |
486 | ext = self.ext |
|
497 | ext = self.ext | |
487 | path = self.path |
|
498 | path = self.path | |
488 | setFile = self.setFile |
|
499 | setFile = self.setFile | |
489 | type_data = self.type_data |
|
500 | type_data = self.type_data | |
490 |
|
501 | |||
491 | timeTuple = time.localtime(self.dataOut.utctime) |
|
502 | timeTuple = time.localtime(self.dataOut.utctime) | |
492 | subfolder = 'd%4.4d%3.3d' % (timeTuple.tm_year,timeTuple.tm_yday) |
|
503 | subfolder = 'd%4.4d%3.3d' % (timeTuple.tm_year,timeTuple.tm_yday) | |
493 | fullpath = os.path.join(path, subfolder) |
|
504 | fullpath = os.path.join(path, subfolder) | |
494 |
|
505 | |||
495 | if os.path.exists(fullpath): |
|
506 | if os.path.exists(fullpath): | |
496 | filesList = os.listdir(fullpath) |
|
507 | filesList = os.listdir(fullpath) | |
497 | filesList = [k for k in filesList if k.startswith(self.optchar)] |
|
508 | filesList = [k for k in filesList if k.startswith(self.optchar)] | |
498 | if len( filesList ) > 0: |
|
509 | if len( filesList ) > 0: | |
499 | filesList = sorted(filesList, key=str.lower) |
|
510 | filesList = sorted(filesList, key=str.lower) | |
500 | filen = filesList[-1] |
|
511 | filen = filesList[-1] | |
501 | # el filename debera tener el siguiente formato |
|
512 | # el filename debera tener el siguiente formato | |
502 | # 0 1234 567 89A BCDE (hex) |
|
513 | # 0 1234 567 89A BCDE (hex) | |
503 | # x YYYY DDD SSS .ext |
|
514 | # x YYYY DDD SSS .ext | |
504 | if isNumber(filen[8:11]): |
|
515 | if isNumber(filen[8:11]): | |
505 | setFile = int(filen[8:11]) #inicializo mi contador de seteo al seteo del ultimo file |
|
516 | setFile = int(filen[8:11]) #inicializo mi contador de seteo al seteo del ultimo file | |
506 | else: |
|
517 | else: | |
507 | setFile = -1 |
|
518 | setFile = -1 | |
508 | else: |
|
519 | else: | |
509 | setFile = -1 #inicializo mi contador de seteo |
|
520 | setFile = -1 #inicializo mi contador de seteo | |
510 | else: |
|
521 | else: | |
511 | os.makedirs(fullpath) |
|
522 | os.makedirs(fullpath) | |
512 | setFile = -1 #inicializo mi contador de seteo |
|
523 | setFile = -1 #inicializo mi contador de seteo | |
513 |
|
524 | |||
514 | ###print("**************************",self.setType) |
|
525 | ###print("**************************",self.setType) | |
515 | if self.setType is None: |
|
526 | if self.setType is None: | |
516 | setFile += 1 |
|
527 | setFile += 1 | |
517 | file = '%s%4.4d%3.3d%03d%s' % (self.optchar, |
|
528 | file = '%s%4.4d%3.3d%03d%s' % (self.optchar, | |
518 | timeTuple.tm_year, |
|
529 | timeTuple.tm_year, | |
519 | timeTuple.tm_yday, |
|
530 | timeTuple.tm_yday, | |
520 | setFile, |
|
531 | setFile, | |
521 | ext ) |
|
532 | ext ) | |
522 | elif self.setType == "weather": |
|
533 | elif self.setType == "weather": | |
523 | print("HOLA AMIGOS") |
|
534 | print("HOLA AMIGOS") | |
524 | wr_exp = self.dataOut.wr_exp |
|
535 | wr_exp = self.dataOut.wr_exp | |
525 | if wr_exp== "PPI": |
|
536 | if wr_exp== "PPI": | |
526 | wr_type = 'E' |
|
537 | wr_type = 'E' | |
527 | ang_ = numpy.mean(self.dataOut.elevation) |
|
538 | ang_ = numpy.mean(self.dataOut.elevation) | |
528 | else: |
|
539 | else: | |
529 | wr_type = 'A' |
|
540 | wr_type = 'A' | |
530 | ang_ = numpy.mean(self.dataOut.azimuth) |
|
541 | ang_ = numpy.mean(self.dataOut.azimuth) | |
531 |
|
542 | |||
532 | wr_writer = '%s%s%2.1f%s'%('-', |
|
543 | wr_writer = '%s%s%2.1f%s'%('-', | |
533 | wr_type, |
|
544 | wr_type, | |
534 | ang_, |
|
545 | ang_, | |
535 | '-') |
|
546 | '-') | |
536 | ###print("wr_writer********************",wr_writer) |
|
547 | ###print("wr_writer********************",wr_writer) | |
537 | file = '%s%4.4d%2.2d%2.2d%s%2.2d%2.2d%2.2d%s%s%s' % (self.optchar, |
|
548 | file = '%s%4.4d%2.2d%2.2d%s%2.2d%2.2d%2.2d%s%s%s' % (self.optchar, | |
538 | timeTuple.tm_year, |
|
549 | timeTuple.tm_year, | |
539 | timeTuple.tm_mon, |
|
550 | timeTuple.tm_mon, | |
540 | timeTuple.tm_mday, |
|
551 | timeTuple.tm_mday, | |
541 | '-', |
|
552 | '-', | |
542 | timeTuple.tm_hour, |
|
553 | timeTuple.tm_hour, | |
543 | timeTuple.tm_min, |
|
554 | timeTuple.tm_min, | |
544 | timeTuple.tm_sec, |
|
555 | timeTuple.tm_sec, | |
545 | wr_writer, |
|
556 | wr_writer, | |
546 | type_data, |
|
557 | type_data, | |
547 | ext ) |
|
558 | ext ) | |
548 | ###print("FILENAME", file) |
|
559 | ###print("FILENAME", file) | |
549 |
|
560 | |||
550 |
|
561 | |||
551 | else: |
|
562 | else: | |
552 | setFile = timeTuple.tm_hour*60+timeTuple.tm_min |
|
563 | setFile = timeTuple.tm_hour*60+timeTuple.tm_min | |
553 | file = '%s%4.4d%3.3d%04d%s' % (self.optchar, |
|
564 | file = '%s%4.4d%3.3d%04d%s' % (self.optchar, | |
554 | timeTuple.tm_year, |
|
565 | timeTuple.tm_year, | |
555 | timeTuple.tm_yday, |
|
566 | timeTuple.tm_yday, | |
556 | setFile, |
|
567 | setFile, | |
557 | ext ) |
|
568 | ext ) | |
558 |
|
569 | |||
559 | self.filename = os.path.join( path, subfolder, file ) |
|
570 | self.filename = os.path.join( path, subfolder, file ) | |
560 |
|
571 | |||
561 | #Setting HDF5 File |
|
572 | #Setting HDF5 File | |
562 |
|
573 | |||
563 | self.fp = h5py.File(self.filename, 'w') |
|
574 | self.fp = h5py.File(self.filename, 'w') | |
564 | #write metadata |
|
575 | #write metadata | |
565 | self.writeMetadata(self.fp) |
|
576 | self.writeMetadata(self.fp) | |
566 | #Write data |
|
577 | #Write data | |
567 | self.writeData(self.fp) |
|
578 | self.writeData(self.fp) | |
568 |
|
579 | |||
569 | def getLabel(self, name, x=None): |
|
580 | def getLabel(self, name, x=None): | |
570 |
|
581 | |||
571 | if x is None: |
|
582 | if x is None: | |
572 | if 'Data' in self.description: |
|
583 | if 'Data' in self.description: | |
573 | data = self.description['Data'] |
|
584 | data = self.description['Data'] | |
574 | if 'Metadata' in self.description: |
|
585 | if 'Metadata' in self.description: | |
575 | data.update(self.description['Metadata']) |
|
586 | data.update(self.description['Metadata']) | |
576 | else: |
|
587 | else: | |
577 | data = self.description |
|
588 | data = self.description | |
578 | if name in data: |
|
589 | if name in data: | |
579 | if isinstance(data[name], str): |
|
590 | if isinstance(data[name], str): | |
580 | return data[name] |
|
591 | return data[name] | |
581 | elif isinstance(data[name], list): |
|
592 | elif isinstance(data[name], list): | |
582 | return None |
|
593 | return None | |
583 | elif isinstance(data[name], dict): |
|
594 | elif isinstance(data[name], dict): | |
584 | for key, value in data[name].items(): |
|
595 | for key, value in data[name].items(): | |
585 | return key |
|
596 | return key | |
586 | return name |
|
597 | return name | |
587 | else: |
|
598 | else: | |
588 | if 'Metadata' in self.description: |
|
599 | if 'Metadata' in self.description: | |
589 | meta = self.description['Metadata'] |
|
600 | meta = self.description['Metadata'] | |
590 | else: |
|
601 | else: | |
591 | meta = self.description |
|
602 | meta = self.description | |
592 | if name in meta: |
|
603 | if name in meta: | |
593 | if isinstance(meta[name], list): |
|
604 | if isinstance(meta[name], list): | |
594 | return meta[name][x] |
|
605 | return meta[name][x] | |
595 | elif isinstance(meta[name], dict): |
|
606 | elif isinstance(meta[name], dict): | |
596 | for key, value in meta[name].items(): |
|
607 | for key, value in meta[name].items(): | |
597 | return value[x] |
|
608 | return value[x] | |
598 | if 'cspc' in name: |
|
609 | if 'cspc' in name: | |
599 | return 'pair{:02d}'.format(x) |
|
610 | return 'pair{:02d}'.format(x) | |
600 | else: |
|
611 | else: | |
601 | return 'channel{:02d}'.format(x) |
|
612 | return 'channel{:02d}'.format(x) | |
602 |
|
613 | |||
603 | def writeMetadata(self, fp): |
|
614 | def writeMetadata(self, fp): | |
604 |
|
615 | |||
605 | if self.description: |
|
616 | if self.description: | |
606 | if 'Metadata' in self.description: |
|
617 | if 'Metadata' in self.description: | |
607 | grp = fp.create_group('Metadata') |
|
618 | grp = fp.create_group('Metadata') | |
608 | else: |
|
619 | else: | |
609 | grp = fp |
|
620 | grp = fp | |
610 | else: |
|
621 | else: | |
611 | grp = fp.create_group('Metadata') |
|
622 | grp = fp.create_group('Metadata') | |
612 |
|
623 | |||
613 | for i in range(len(self.metadataList)): |
|
624 | for i in range(len(self.metadataList)): | |
614 | if not hasattr(self.dataOut, self.metadataList[i]): |
|
625 | if not hasattr(self.dataOut, self.metadataList[i]): | |
615 | log.warning('Metadata: `{}` not found'.format(self.metadataList[i]), self.name) |
|
626 | log.warning('Metadata: `{}` not found'.format(self.metadataList[i]), self.name) | |
616 | continue |
|
627 | continue | |
617 | value = getattr(self.dataOut, self.metadataList[i]) |
|
628 | value = getattr(self.dataOut, self.metadataList[i]) | |
618 | if isinstance(value, bool): |
|
629 | if isinstance(value, bool): | |
619 | if value is True: |
|
630 | if value is True: | |
620 | value = 1 |
|
631 | value = 1 | |
621 | else: |
|
632 | else: | |
622 | value = 0 |
|
633 | value = 0 | |
623 | grp.create_dataset(self.getLabel(self.metadataList[i]), data=value) |
|
634 | grp.create_dataset(self.getLabel(self.metadataList[i]), data=value) | |
624 | return |
|
635 | return | |
625 |
|
636 | |||
626 | def writeData(self, fp): |
|
637 | def writeData(self, fp): | |
627 |
|
638 | print("writing data") | ||
628 | if self.description: |
|
639 | if self.description: | |
629 | if 'Data' in self.description: |
|
640 | if 'Data' in self.description: | |
630 | grp = fp.create_group('Data') |
|
641 | grp = fp.create_group('Data') | |
631 | else: |
|
642 | else: | |
632 | grp = fp |
|
643 | grp = fp | |
633 | else: |
|
644 | else: | |
634 | grp = fp.create_group('Data') |
|
645 | grp = fp.create_group('Data') | |
635 |
|
646 | |||
636 | dtsets = [] |
|
647 | dtsets = [] | |
637 | data = [] |
|
648 | data = [] | |
638 |
|
649 | |||
639 | for dsInfo in self.dsList: |
|
650 | for dsInfo in self.dsList: | |
640 | if dsInfo['nDim'] == 0: |
|
651 | if dsInfo['nDim'] == 0: | |
641 | ds = grp.create_dataset( |
|
652 | ds = grp.create_dataset( | |
642 | self.getLabel(dsInfo['variable']), |
|
653 | self.getLabel(dsInfo['variable']), | |
643 | (self.blocksPerFile, ), |
|
654 | (self.blocksPerFile, ), | |
644 | chunks=True, |
|
655 | chunks=True, | |
645 | dtype=numpy.float64) |
|
656 | dtype=numpy.float64) | |
646 | dtsets.append(ds) |
|
657 | dtsets.append(ds) | |
647 | data.append((dsInfo['variable'], -1)) |
|
658 | data.append((dsInfo['variable'], -1)) | |
648 | else: |
|
659 | else: | |
649 | label = self.getLabel(dsInfo['variable']) |
|
660 | label = self.getLabel(dsInfo['variable']) | |
650 | if label is not None: |
|
661 | if label is not None: | |
651 | sgrp = grp.create_group(label) |
|
662 | sgrp = grp.create_group(label) | |
652 | else: |
|
663 | else: | |
653 | sgrp = grp |
|
664 | sgrp = grp | |
654 | for i in range(dsInfo['dsNumber']): |
|
665 | for i in range(dsInfo['dsNumber']): | |
655 | ds = sgrp.create_dataset( |
|
666 | ds = sgrp.create_dataset( | |
656 | self.getLabel(dsInfo['variable'], i), |
|
667 | self.getLabel(dsInfo['variable'], i), | |
657 | (self.blocksPerFile, ) + dsInfo['shape'][1:], |
|
668 | (self.blocksPerFile, ) + dsInfo['shape'][1:], | |
658 | chunks=True, |
|
669 | chunks=True, | |
659 | dtype=dsInfo['dtype']) |
|
670 | dtype=dsInfo['dtype']) | |
660 | dtsets.append(ds) |
|
671 | dtsets.append(ds) | |
661 | data.append((dsInfo['variable'], i)) |
|
672 | data.append((dsInfo['variable'], i)) | |
662 | fp.flush() |
|
673 | fp.flush() | |
663 |
|
674 | |||
664 | log.log('Creating file: {}'.format(fp.filename), self.name) |
|
675 | log.log('Creating file: {}'.format(fp.filename), self.name) | |
665 |
|
676 | |||
666 | self.ds = dtsets |
|
677 | self.ds = dtsets | |
667 | self.data = data |
|
678 | self.data = data | |
668 | self.firsttime = True |
|
679 | self.firsttime = True | |
669 | self.blockIndex = 0 |
|
680 | self.blockIndex = 0 | |
670 | return |
|
681 | return | |
671 |
|
682 | |||
672 | def putData(self): |
|
683 | def putData(self): | |
673 | ###print("**************************PUT DATA***************************************************") |
|
684 | ###print("**************************PUT DATA***************************************************") | |
674 |
if (self.blockIndex == self.blocksPerFile) or self.timeFlag() |
|
685 | if (self.blockIndex == self.blocksPerFile) or self.timeFlag():# or self.generalFlag_vRF(): | |
675 | self.closeFile() |
|
686 | self.closeFile() | |
676 | self.setNextFile() |
|
687 | self.setNextFile() | |
677 |
|
688 | |||
678 | for i, ds in enumerate(self.ds): |
|
689 | for i, ds in enumerate(self.ds): | |
679 | attr, ch = self.data[i] |
|
690 | attr, ch = self.data[i] | |
680 | if ch == -1: |
|
691 | if ch == -1: | |
681 | ds[self.blockIndex] = getattr(self.dataOut, attr) |
|
692 | ds[self.blockIndex] = getattr(self.dataOut, attr) | |
682 | else: |
|
693 | else: | |
683 | ds[self.blockIndex] = getattr(self.dataOut, attr)[ch] |
|
694 | ds[self.blockIndex] = getattr(self.dataOut, attr)[ch] | |
684 |
|
695 | |||
685 | self.fp.flush() |
|
696 | self.fp.flush() | |
686 | self.blockIndex += 1 |
|
697 | self.blockIndex += 1 | |
687 | log.log('Block No. {}/{}'.format(self.blockIndex, self.blocksPerFile), self.name) |
|
698 | log.log('Block No. {}/{}'.format(self.blockIndex, self.blocksPerFile), self.name) | |
688 |
|
699 | |||
689 | return |
|
700 | return | |
690 |
|
701 | |||
691 | def closeFile(self): |
|
702 | def closeFile(self): | |
692 |
|
703 | |||
693 | if self.blockIndex != self.blocksPerFile: |
|
704 | if self.blockIndex != self.blocksPerFile: | |
694 | for ds in self.ds: |
|
705 | for ds in self.ds: | |
695 | ds.resize(self.blockIndex, axis=0) |
|
706 | ds.resize(self.blockIndex, axis=0) | |
696 |
|
707 | |||
697 | if self.fp: |
|
708 | if self.fp: | |
698 | self.fp.flush() |
|
709 | self.fp.flush() | |
699 | self.fp.close() |
|
710 | self.fp.close() | |
700 |
|
711 | |||
701 | def close(self): |
|
712 | def close(self): | |
702 |
|
713 | |||
703 | self.closeFile() |
|
714 | self.closeFile() |
@@ -1,206 +1,208 | |||||
1 | ''' |
|
1 | ''' | |
2 | Base clases to create Processing units and operations, the MPDecorator |
|
2 | Base clases to create Processing units and operations, the MPDecorator | |
3 | must be used in plotting and writing operations to allow to run as an |
|
3 | must be used in plotting and writing operations to allow to run as an | |
4 | external process. |
|
4 | external process. | |
5 | ''' |
|
5 | ''' | |
6 |
|
6 | |||
|
7 | import os | |||
7 | import inspect |
|
8 | import inspect | |
8 | import zmq |
|
9 | import zmq | |
9 | import time |
|
10 | import time | |
10 | import pickle |
|
11 | import pickle | |
11 | import traceback |
|
12 | import traceback | |
12 | from threading import Thread |
|
13 | from threading import Thread | |
13 | from multiprocessing import Process, Queue |
|
14 | from multiprocessing import Process, Queue | |
14 | from schainpy.utils import log |
|
15 | from schainpy.utils import log | |
15 |
|
16 | |||
|
17 | QUEUE_SIZE = int(os.environ.get('QUEUE_MAX_SIZE', '10')) | |||
16 |
|
18 | |||
17 | class ProcessingUnit(object): |
|
19 | class ProcessingUnit(object): | |
18 | ''' |
|
20 | ''' | |
19 | Base class to create Signal Chain Units |
|
21 | Base class to create Signal Chain Units | |
20 | ''' |
|
22 | ''' | |
21 |
|
23 | |||
22 | proc_type = 'processing' |
|
24 | proc_type = 'processing' | |
23 |
|
25 | |||
24 | def __init__(self): |
|
26 | def __init__(self): | |
25 |
|
27 | |||
26 | self.dataIn = None |
|
28 | self.dataIn = None | |
27 | self.dataOut = None |
|
29 | self.dataOut = None | |
28 | self.isConfig = False |
|
30 | self.isConfig = False | |
29 | self.operations = [] |
|
31 | self.operations = [] | |
30 |
|
32 | |||
31 | def setInput(self, unit): |
|
33 | def setInput(self, unit): | |
32 |
|
34 | |||
33 | self.dataIn = unit.dataOut |
|
35 | self.dataIn = unit.dataOut | |
34 |
|
36 | |||
35 | def getAllowedArgs(self): |
|
37 | def getAllowedArgs(self): | |
36 | if hasattr(self, '__attrs__'): |
|
38 | if hasattr(self, '__attrs__'): | |
37 | return self.__attrs__ |
|
39 | return self.__attrs__ | |
38 | else: |
|
40 | else: | |
39 | return inspect.getargspec(self.run).args |
|
41 | return inspect.getargspec(self.run).args | |
40 |
|
42 | |||
41 | def addOperation(self, conf, operation): |
|
43 | def addOperation(self, conf, operation): | |
42 | ''' |
|
44 | ''' | |
43 | ''' |
|
45 | ''' | |
44 |
|
46 | |||
45 | self.operations.append((operation, conf.type, conf.getKwargs())) |
|
47 | self.operations.append((operation, conf.type, conf.getKwargs())) | |
46 |
|
48 | |||
47 | def getOperationObj(self, objId): |
|
49 | def getOperationObj(self, objId): | |
48 |
|
50 | |||
49 | if objId not in list(self.operations.keys()): |
|
51 | if objId not in list(self.operations.keys()): | |
50 | return None |
|
52 | return None | |
51 |
|
53 | |||
52 | return self.operations[objId] |
|
54 | return self.operations[objId] | |
53 |
|
55 | |||
54 | def call(self, **kwargs): |
|
56 | def call(self, **kwargs): | |
55 | ''' |
|
57 | ''' | |
56 | ''' |
|
58 | ''' | |
57 |
|
59 | |||
58 | try: |
|
60 | try: | |
59 | if self.dataIn is not None and self.dataIn.flagNoData and not self.dataIn.error: |
|
61 | if self.dataIn is not None and self.dataIn.flagNoData and not self.dataIn.error: | |
60 | return self.dataIn.isReady() |
|
62 | return self.dataIn.isReady() | |
61 | elif self.dataIn is None or not self.dataIn.error: |
|
63 | elif self.dataIn is None or not self.dataIn.error: | |
62 | self.run(**kwargs) |
|
64 | self.run(**kwargs) | |
63 | elif self.dataIn.error: |
|
65 | elif self.dataIn.error: | |
64 | self.dataOut.error = self.dataIn.error |
|
66 | self.dataOut.error = self.dataIn.error | |
65 | self.dataOut.flagNoData = True |
|
67 | self.dataOut.flagNoData = True | |
66 | except: |
|
68 | except: | |
67 | err = traceback.format_exc() |
|
69 | err = traceback.format_exc() | |
68 | if 'SchainWarning' in err: |
|
70 | if 'SchainWarning' in err: | |
69 | log.warning(err.split('SchainWarning:')[-1].split('\n')[0].strip(), self.name) |
|
71 | log.warning(err.split('SchainWarning:')[-1].split('\n')[0].strip(), self.name) | |
70 | elif 'SchainError' in err: |
|
72 | elif 'SchainError' in err: | |
71 | log.error(err.split('SchainError:')[-1].split('\n')[0].strip(), self.name) |
|
73 | log.error(err.split('SchainError:')[-1].split('\n')[0].strip(), self.name) | |
72 | else: |
|
74 | else: | |
73 | log.error(err, self.name) |
|
75 | log.error(err, self.name) | |
74 | self.dataOut.error = True |
|
76 | self.dataOut.error = True | |
75 | ##### correcion de la declaracion Out |
|
77 | ##### correcion de la declaracion Out | |
76 | for op, optype, opkwargs in self.operations: |
|
78 | for op, optype, opkwargs in self.operations: | |
77 | aux = self.dataOut.copy() |
|
79 | aux = self.dataOut.copy() | |
78 | if optype == 'other' and not self.dataOut.flagNoData: |
|
80 | if optype == 'other' and not self.dataOut.flagNoData: | |
79 | self.dataOut = op.run(self.dataOut, **opkwargs) |
|
81 | self.dataOut = op.run(self.dataOut, **opkwargs) | |
80 | elif optype == 'external' and not self.dataOut.flagNoData: |
|
82 | elif optype == 'external' and not self.dataOut.flagNoData: | |
81 | #op.queue.put(self.dataOut) |
|
83 | #op.queue.put(self.dataOut) | |
82 | op.queue.put(aux) |
|
84 | op.queue.put(aux) | |
83 | elif optype == 'external' and self.dataOut.error: |
|
85 | elif optype == 'external' and self.dataOut.error: | |
84 | #op.queue.put(self.dataOut) |
|
86 | #op.queue.put(self.dataOut) | |
85 | op.queue.put(aux) |
|
87 | op.queue.put(aux) | |
86 |
|
88 | |||
87 | return 'Error' if self.dataOut.error else self.dataOut.isReady() |
|
89 | return 'Error' if self.dataOut.error else self.dataOut.isReady() | |
88 |
|
90 | |||
89 | def setup(self): |
|
91 | def setup(self): | |
90 |
|
92 | |||
91 | raise NotImplementedError |
|
93 | raise NotImplementedError | |
92 |
|
94 | |||
93 | def run(self): |
|
95 | def run(self): | |
94 |
|
96 | |||
95 | raise NotImplementedError |
|
97 | raise NotImplementedError | |
96 |
|
98 | |||
97 | def close(self): |
|
99 | def close(self): | |
98 |
|
100 | |||
99 | return |
|
101 | return | |
100 |
|
102 | |||
101 |
|
103 | |||
102 | class Operation(object): |
|
104 | class Operation(object): | |
103 |
|
105 | |||
104 | ''' |
|
106 | ''' | |
105 | ''' |
|
107 | ''' | |
106 |
|
108 | |||
107 | proc_type = 'operation' |
|
109 | proc_type = 'operation' | |
108 |
|
110 | |||
109 | def __init__(self): |
|
111 | def __init__(self): | |
110 |
|
112 | |||
111 | self.id = None |
|
113 | self.id = None | |
112 | self.isConfig = False |
|
114 | self.isConfig = False | |
113 |
|
115 | |||
114 | if not hasattr(self, 'name'): |
|
116 | if not hasattr(self, 'name'): | |
115 | self.name = self.__class__.__name__ |
|
117 | self.name = self.__class__.__name__ | |
116 |
|
118 | |||
117 | def getAllowedArgs(self): |
|
119 | def getAllowedArgs(self): | |
118 | if hasattr(self, '__attrs__'): |
|
120 | if hasattr(self, '__attrs__'): | |
119 | return self.__attrs__ |
|
121 | return self.__attrs__ | |
120 | else: |
|
122 | else: | |
121 | return inspect.getargspec(self.run).args |
|
123 | return inspect.getargspec(self.run).args | |
122 |
|
124 | |||
123 | def setup(self): |
|
125 | def setup(self): | |
124 |
|
126 | |||
125 | self.isConfig = True |
|
127 | self.isConfig = True | |
126 |
|
128 | |||
127 | raise NotImplementedError |
|
129 | raise NotImplementedError | |
128 |
|
130 | |||
129 | def run(self, dataIn, **kwargs): |
|
131 | def run(self, dataIn, **kwargs): | |
130 | """ |
|
132 | """ | |
131 | Realiza las operaciones necesarias sobre la dataIn.data y actualiza los |
|
133 | Realiza las operaciones necesarias sobre la dataIn.data y actualiza los | |
132 | atributos del objeto dataIn. |
|
134 | atributos del objeto dataIn. | |
133 |
|
135 | |||
134 | Input: |
|
136 | Input: | |
135 |
|
137 | |||
136 | dataIn : objeto del tipo JROData |
|
138 | dataIn : objeto del tipo JROData | |
137 |
|
139 | |||
138 | Return: |
|
140 | Return: | |
139 |
|
141 | |||
140 | None |
|
142 | None | |
141 |
|
143 | |||
142 | Affected: |
|
144 | Affected: | |
143 | __buffer : buffer de recepcion de datos. |
|
145 | __buffer : buffer de recepcion de datos. | |
144 |
|
146 | |||
145 | """ |
|
147 | """ | |
146 | if not self.isConfig: |
|
148 | if not self.isConfig: | |
147 | self.setup(**kwargs) |
|
149 | self.setup(**kwargs) | |
148 |
|
150 | |||
149 | raise NotImplementedError |
|
151 | raise NotImplementedError | |
150 |
|
152 | |||
151 | def close(self): |
|
153 | def close(self): | |
152 |
|
154 | |||
153 | return |
|
155 | return | |
154 |
|
156 | |||
155 |
|
157 | |||
156 | def MPDecorator(BaseClass): |
|
158 | def MPDecorator(BaseClass): | |
157 | """ |
|
159 | """ | |
158 | Multiprocessing class decorator |
|
160 | Multiprocessing class decorator | |
159 |
|
161 | |||
160 | This function add multiprocessing features to a BaseClass. |
|
162 | This function add multiprocessing features to a BaseClass. | |
161 | """ |
|
163 | """ | |
162 |
|
164 | |||
163 | class MPClass(BaseClass, Process): |
|
165 | class MPClass(BaseClass, Process): | |
164 |
|
166 | |||
165 | def __init__(self, *args, **kwargs): |
|
167 | def __init__(self, *args, **kwargs): | |
166 | super(MPClass, self).__init__() |
|
168 | super(MPClass, self).__init__() | |
167 | Process.__init__(self) |
|
169 | Process.__init__(self) | |
168 |
|
170 | |||
169 | self.args = args |
|
171 | self.args = args | |
170 | self.kwargs = kwargs |
|
172 | self.kwargs = kwargs | |
171 | self.t = time.time() |
|
173 | self.t = time.time() | |
172 | self.op_type = 'external' |
|
174 | self.op_type = 'external' | |
173 | self.name = BaseClass.__name__ |
|
175 | self.name = BaseClass.__name__ | |
174 | self.__doc__ = BaseClass.__doc__ |
|
176 | self.__doc__ = BaseClass.__doc__ | |
175 |
|
177 | |||
176 | if 'plot' in self.name.lower() and not self.name.endswith('_'): |
|
178 | if 'plot' in self.name.lower() and not self.name.endswith('_'): | |
177 | self.name = '{}{}'.format(self.CODE.upper(), 'Plot') |
|
179 | self.name = '{}{}'.format(self.CODE.upper(), 'Plot') | |
178 |
|
180 | |||
179 | self.start_time = time.time() |
|
181 | self.start_time = time.time() | |
180 | self.err_queue = args[3] |
|
182 | self.err_queue = args[3] | |
181 |
self.queue = Queue(maxsize= |
|
183 | self.queue = Queue(maxsize=QUEUE_SIZE) | |
182 | self.myrun = BaseClass.run |
|
184 | self.myrun = BaseClass.run | |
183 |
|
185 | |||
184 | def run(self): |
|
186 | def run(self): | |
185 |
|
187 | |||
186 | while True: |
|
188 | while True: | |
187 |
|
189 | |||
188 | dataOut = self.queue.get() |
|
190 | dataOut = self.queue.get() | |
189 |
|
191 | |||
190 | if not dataOut.error: |
|
192 | if not dataOut.error: | |
191 | try: |
|
193 | try: | |
192 | BaseClass.run(self, dataOut, **self.kwargs) |
|
194 | BaseClass.run(self, dataOut, **self.kwargs) | |
193 | except: |
|
195 | except: | |
194 | err = traceback.format_exc() |
|
196 | err = traceback.format_exc() | |
195 | log.error(err, self.name) |
|
197 | log.error(err, self.name) | |
196 | else: |
|
198 | else: | |
197 | break |
|
199 | break | |
198 |
|
200 | |||
199 | self.close() |
|
201 | self.close() | |
200 |
|
202 | |||
201 | def close(self): |
|
203 | def close(self): | |
202 |
|
204 | |||
203 | BaseClass.close(self) |
|
205 | BaseClass.close(self) | |
204 | log.success('Done...(Time:{:4.2f} secs)'.format(time.time()-self.start_time), self.name) |
|
206 | log.success('Done...(Time:{:4.2f} secs)'.format(time.time()-self.start_time), self.name) | |
205 |
|
207 | |||
206 | return MPClass |
|
208 | return MPClass |
@@ -1,4708 +1,4821 | |||||
1 |
|
1 | |||
2 | import os |
|
2 | import os | |
3 | import time |
|
3 | import time | |
4 | import math |
|
4 | import math | |
5 |
|
5 | |||
6 | import re |
|
6 | import re | |
7 | import datetime |
|
7 | import datetime | |
8 | import copy |
|
8 | import copy | |
9 | import sys |
|
9 | import sys | |
10 | import importlib |
|
10 | import importlib | |
11 | import itertools |
|
11 | import itertools | |
12 |
|
12 | |||
13 | from multiprocessing import Pool, TimeoutError |
|
13 | from multiprocessing import Pool, TimeoutError | |
14 | from multiprocessing.pool import ThreadPool |
|
14 | from multiprocessing.pool import ThreadPool | |
15 | import numpy |
|
15 | import numpy | |
16 | import glob |
|
16 | import glob | |
17 | import scipy |
|
17 | import scipy | |
18 | import h5py |
|
18 | import h5py | |
19 | from scipy.optimize import fmin_l_bfgs_b #optimize with bounds on state papameters |
|
19 | from scipy.optimize import fmin_l_bfgs_b #optimize with bounds on state papameters | |
20 | from .jroproc_base import ProcessingUnit, Operation, MPDecorator |
|
20 | from .jroproc_base import ProcessingUnit, Operation, MPDecorator | |
21 | from schainpy.model.data.jrodata import Parameters, hildebrand_sekhon |
|
21 | from schainpy.model.data.jrodata import Parameters, hildebrand_sekhon | |
22 | from scipy import asarray as ar,exp |
|
22 | from scipy import asarray as ar,exp | |
23 | from scipy.optimize import curve_fit |
|
23 | from scipy.optimize import curve_fit | |
24 | from schainpy.utils import log |
|
24 | from schainpy.utils import log | |
25 | import schainpy.admin |
|
25 | import schainpy.admin | |
26 | import warnings |
|
26 | import warnings | |
27 | from scipy import optimize, interpolate, signal, stats, ndimage |
|
27 | from scipy import optimize, interpolate, signal, stats, ndimage | |
28 | from scipy.optimize.optimize import OptimizeWarning |
|
28 | from scipy.optimize.optimize import OptimizeWarning | |
29 | warnings.filterwarnings('ignore') |
|
29 | warnings.filterwarnings('ignore') | |
30 |
|
30 | |||
31 |
|
31 | |||
32 | SPEED_OF_LIGHT = 299792458 |
|
32 | SPEED_OF_LIGHT = 299792458 | |
33 |
|
33 | |||
34 | '''solving pickling issue''' |
|
34 | '''solving pickling issue''' | |
35 |
|
35 | |||
36 | def _pickle_method(method): |
|
36 | def _pickle_method(method): | |
37 | func_name = method.__func__.__name__ |
|
37 | func_name = method.__func__.__name__ | |
38 | obj = method.__self__ |
|
38 | obj = method.__self__ | |
39 | cls = method.__self__.__class__ |
|
39 | cls = method.__self__.__class__ | |
40 | return _unpickle_method, (func_name, obj, cls) |
|
40 | return _unpickle_method, (func_name, obj, cls) | |
41 |
|
41 | |||
42 | def _unpickle_method(func_name, obj, cls): |
|
42 | def _unpickle_method(func_name, obj, cls): | |
43 | for cls in cls.mro(): |
|
43 | for cls in cls.mro(): | |
44 | try: |
|
44 | try: | |
45 | func = cls.__dict__[func_name] |
|
45 | func = cls.__dict__[func_name] | |
46 | except KeyError: |
|
46 | except KeyError: | |
47 | pass |
|
47 | pass | |
48 | else: |
|
48 | else: | |
49 | break |
|
49 | break | |
50 | return func.__get__(obj, cls) |
|
50 | return func.__get__(obj, cls) | |
51 |
|
51 | |||
52 | def isNumber(str): |
|
52 | def isNumber(str): | |
53 | try: |
|
53 | try: | |
54 | float(str) |
|
54 | float(str) | |
55 | return True |
|
55 | return True | |
56 | except: |
|
56 | except: | |
57 | return False |
|
57 | return False | |
58 |
|
58 | |||
59 | class ParametersProc(ProcessingUnit): |
|
59 | class ParametersProc(ProcessingUnit): | |
60 |
|
60 | |||
61 | METHODS = {} |
|
61 | METHODS = {} | |
62 | nSeconds = None |
|
62 | nSeconds = None | |
63 |
|
63 | |||
64 | def __init__(self): |
|
64 | def __init__(self): | |
65 | ProcessingUnit.__init__(self) |
|
65 | ProcessingUnit.__init__(self) | |
66 |
|
66 | |||
67 | # self.objectDict = {} |
|
67 | # self.objectDict = {} | |
68 | self.buffer = None |
|
68 | self.buffer = None | |
69 | self.firstdatatime = None |
|
69 | self.firstdatatime = None | |
70 | self.profIndex = 0 |
|
70 | self.profIndex = 0 | |
71 | self.dataOut = Parameters() |
|
71 | self.dataOut = Parameters() | |
72 | self.setupReq = False #Agregar a todas las unidades de proc |
|
72 | self.setupReq = False #Agregar a todas las unidades de proc | |
73 |
|
73 | |||
74 | def __updateObjFromInput(self): |
|
74 | def __updateObjFromInput(self): | |
75 |
|
75 | |||
76 | self.dataOut.inputUnit = self.dataIn.type |
|
76 | self.dataOut.inputUnit = self.dataIn.type | |
77 |
|
77 | |||
78 | self.dataOut.timeZone = self.dataIn.timeZone |
|
78 | self.dataOut.timeZone = self.dataIn.timeZone | |
79 | self.dataOut.dstFlag = self.dataIn.dstFlag |
|
79 | self.dataOut.dstFlag = self.dataIn.dstFlag | |
80 | self.dataOut.errorCount = self.dataIn.errorCount |
|
80 | self.dataOut.errorCount = self.dataIn.errorCount | |
81 | self.dataOut.useLocalTime = self.dataIn.useLocalTime |
|
81 | self.dataOut.useLocalTime = self.dataIn.useLocalTime | |
82 |
|
82 | |||
83 | self.dataOut.radarControllerHeaderObj = self.dataIn.radarControllerHeaderObj.copy() |
|
83 | self.dataOut.radarControllerHeaderObj = self.dataIn.radarControllerHeaderObj.copy() | |
84 | self.dataOut.systemHeaderObj = self.dataIn.systemHeaderObj.copy() |
|
84 | self.dataOut.systemHeaderObj = self.dataIn.systemHeaderObj.copy() | |
85 | self.dataOut.channelList = self.dataIn.channelList |
|
85 | self.dataOut.channelList = self.dataIn.channelList | |
86 | self.dataOut.heightList = self.dataIn.heightList |
|
86 | self.dataOut.heightList = self.dataIn.heightList | |
87 | self.dataOut.dtype = numpy.dtype([('real','<f4'),('imag','<f4')]) |
|
87 | self.dataOut.dtype = numpy.dtype([('real','<f4'),('imag','<f4')]) | |
88 | # self.dataOut.nHeights = self.dataIn.nHeights |
|
88 | # self.dataOut.nHeights = self.dataIn.nHeights | |
89 | # self.dataOut.nChannels = self.dataIn.nChannels |
|
89 | # self.dataOut.nChannels = self.dataIn.nChannels | |
90 | # self.dataOut.nBaud = self.dataIn.nBaud |
|
90 | # self.dataOut.nBaud = self.dataIn.nBaud | |
91 | # self.dataOut.nCode = self.dataIn.nCode |
|
91 | # self.dataOut.nCode = self.dataIn.nCode | |
92 | # self.dataOut.code = self.dataIn.code |
|
92 | # self.dataOut.code = self.dataIn.code | |
93 | # self.dataOut.nProfiles = self.dataOut.nFFTPoints |
|
93 | # self.dataOut.nProfiles = self.dataOut.nFFTPoints | |
94 | self.dataOut.flagDiscontinuousBlock = self.dataIn.flagDiscontinuousBlock |
|
94 | self.dataOut.flagDiscontinuousBlock = self.dataIn.flagDiscontinuousBlock | |
95 | # self.dataOut.utctime = self.firstdatatime |
|
95 | # self.dataOut.utctime = self.firstdatatime | |
96 | self.dataOut.utctime = self.dataIn.utctime |
|
96 | self.dataOut.utctime = self.dataIn.utctime | |
97 | self.dataOut.flagDecodeData = self.dataIn.flagDecodeData #asumo q la data esta decodificada |
|
97 | self.dataOut.flagDecodeData = self.dataIn.flagDecodeData #asumo q la data esta decodificada | |
98 | self.dataOut.flagDeflipData = self.dataIn.flagDeflipData #asumo q la data esta sin flip |
|
98 | self.dataOut.flagDeflipData = self.dataIn.flagDeflipData #asumo q la data esta sin flip | |
99 | self.dataOut.nCohInt = self.dataIn.nCohInt |
|
99 | self.dataOut.nCohInt = self.dataIn.nCohInt | |
100 | # self.dataOut.nIncohInt = 1 |
|
100 | # self.dataOut.nIncohInt = 1 | |
101 | # self.dataOut.ippSeconds = self.dataIn.ippSeconds |
|
101 | # self.dataOut.ippSeconds = self.dataIn.ippSeconds | |
102 | # self.dataOut.windowOfFilter = self.dataIn.windowOfFilter |
|
102 | # self.dataOut.windowOfFilter = self.dataIn.windowOfFilter | |
103 | self.dataOut.timeInterval1 = self.dataIn.timeInterval |
|
103 | self.dataOut.timeInterval1 = self.dataIn.timeInterval | |
104 | self.dataOut.heightList = self.dataIn.heightList |
|
104 | self.dataOut.heightList = self.dataIn.heightList | |
105 | self.dataOut.frequency = self.dataIn.frequency |
|
105 | self.dataOut.frequency = self.dataIn.frequency | |
106 | # self.dataOut.noise = self.dataIn.noise |
|
106 | # self.dataOut.noise = self.dataIn.noise | |
107 |
|
107 | |||
108 | def run(self): |
|
108 | def run(self): | |
109 |
|
109 | |||
110 |
|
110 | |||
111 | #print("HOLA MUNDO SOY YO") |
|
111 | #print("HOLA MUNDO SOY YO") | |
112 | #---------------------- Voltage Data --------------------------- |
|
112 | #---------------------- Voltage Data --------------------------- | |
113 |
|
113 | |||
114 | if self.dataIn.type == "Voltage": |
|
114 | if self.dataIn.type == "Voltage": | |
115 |
|
115 | |||
116 | self.__updateObjFromInput() |
|
116 | self.__updateObjFromInput() | |
117 | self.dataOut.data_pre = self.dataIn.data.copy() |
|
117 | self.dataOut.data_pre = self.dataIn.data.copy() | |
118 | self.dataOut.flagNoData = False |
|
118 | self.dataOut.flagNoData = False | |
119 | self.dataOut.utctimeInit = self.dataIn.utctime |
|
119 | self.dataOut.utctimeInit = self.dataIn.utctime | |
120 | self.dataOut.paramInterval = self.dataIn.nProfiles*self.dataIn.nCohInt*self.dataIn.ippSeconds |
|
120 | self.dataOut.paramInterval = self.dataIn.nProfiles*self.dataIn.nCohInt*self.dataIn.ippSeconds | |
121 |
|
121 | |||
122 | if hasattr(self.dataIn, 'flagDataAsBlock'): |
|
122 | if hasattr(self.dataIn, 'flagDataAsBlock'): | |
123 | self.dataOut.flagDataAsBlock = self.dataIn.flagDataAsBlock |
|
123 | self.dataOut.flagDataAsBlock = self.dataIn.flagDataAsBlock | |
124 |
|
124 | |||
125 | if hasattr(self.dataIn, 'profileIndex'): |
|
125 | if hasattr(self.dataIn, 'profileIndex'): | |
126 | self.dataOut.profileIndex = self.dataIn.profileIndex |
|
126 | self.dataOut.profileIndex = self.dataIn.profileIndex | |
127 |
|
127 | |||
128 | if hasattr(self.dataIn, 'dataPP_POW'): |
|
128 | if hasattr(self.dataIn, 'dataPP_POW'): | |
129 | self.dataOut.dataPP_POW = self.dataIn.dataPP_POW |
|
129 | self.dataOut.dataPP_POW = self.dataIn.dataPP_POW | |
130 |
|
130 | |||
131 | if hasattr(self.dataIn, 'dataPP_POWER'): |
|
131 | if hasattr(self.dataIn, 'dataPP_POWER'): | |
132 | self.dataOut.dataPP_POWER = self.dataIn.dataPP_POWER |
|
132 | self.dataOut.dataPP_POWER = self.dataIn.dataPP_POWER | |
133 |
|
133 | |||
134 | if hasattr(self.dataIn, 'dataPP_DOP'): |
|
134 | if hasattr(self.dataIn, 'dataPP_DOP'): | |
135 | self.dataOut.dataPP_DOP = self.dataIn.dataPP_DOP |
|
135 | self.dataOut.dataPP_DOP = self.dataIn.dataPP_DOP | |
136 |
|
136 | |||
137 | if hasattr(self.dataIn, 'dataPP_SNR'): |
|
137 | if hasattr(self.dataIn, 'dataPP_SNR'): | |
138 | self.dataOut.dataPP_SNR = self.dataIn.dataPP_SNR |
|
138 | self.dataOut.dataPP_SNR = self.dataIn.dataPP_SNR | |
139 |
|
139 | |||
140 | if hasattr(self.dataIn, 'dataPP_WIDTH'): |
|
140 | if hasattr(self.dataIn, 'dataPP_WIDTH'): | |
141 | self.dataOut.dataPP_WIDTH = self.dataIn.dataPP_WIDTH |
|
141 | self.dataOut.dataPP_WIDTH = self.dataIn.dataPP_WIDTH | |
142 | return |
|
142 | return | |
143 |
|
143 | |||
144 | #---------------------- Spectra Data --------------------------- |
|
144 | #---------------------- Spectra Data --------------------------- | |
145 |
|
145 | |||
146 | if self.dataIn.type == "Spectra": |
|
146 | if self.dataIn.type == "Spectra": | |
147 | #print("que paso en spectra") |
|
147 | #print("que paso en spectra") | |
148 | self.dataOut.data_pre = [self.dataIn.data_spc, self.dataIn.data_cspc] |
|
148 | self.dataOut.data_pre = [self.dataIn.data_spc, self.dataIn.data_cspc] | |
149 | self.dataOut.data_spc = self.dataIn.data_spc |
|
149 | self.dataOut.data_spc = self.dataIn.data_spc | |
150 | self.dataOut.data_cspc = self.dataIn.data_cspc |
|
150 | self.dataOut.data_cspc = self.dataIn.data_cspc | |
151 | self.dataOut.nProfiles = self.dataIn.nProfiles |
|
151 | self.dataOut.nProfiles = self.dataIn.nProfiles | |
152 | self.dataOut.nIncohInt = self.dataIn.nIncohInt |
|
152 | self.dataOut.nIncohInt = self.dataIn.nIncohInt | |
153 | self.dataOut.nFFTPoints = self.dataIn.nFFTPoints |
|
153 | self.dataOut.nFFTPoints = self.dataIn.nFFTPoints | |
154 | self.dataOut.ippFactor = self.dataIn.ippFactor |
|
154 | self.dataOut.ippFactor = self.dataIn.ippFactor | |
155 | self.dataOut.abscissaList = self.dataIn.getVelRange(1) |
|
155 | self.dataOut.abscissaList = self.dataIn.getVelRange(1) | |
156 | self.dataOut.spc_noise = self.dataIn.getNoise() |
|
156 | self.dataOut.spc_noise = self.dataIn.getNoise() | |
157 | self.dataOut.spc_range = (self.dataIn.getFreqRange(1) , self.dataIn.getAcfRange(1) , self.dataIn.getVelRange(1)) |
|
157 | self.dataOut.spc_range = (self.dataIn.getFreqRange(1) , self.dataIn.getAcfRange(1) , self.dataIn.getVelRange(1)) | |
158 | # self.dataOut.normFactor = self.dataIn.normFactor |
|
158 | # self.dataOut.normFactor = self.dataIn.normFactor | |
159 | self.dataOut.pairsList = self.dataIn.pairsList |
|
159 | self.dataOut.pairsList = self.dataIn.pairsList | |
160 | self.dataOut.groupList = self.dataIn.pairsList |
|
160 | self.dataOut.groupList = self.dataIn.pairsList | |
161 | self.dataOut.flagNoData = False |
|
161 | self.dataOut.flagNoData = False | |
162 |
|
162 | |||
163 | if hasattr(self.dataIn, 'flagDataAsBlock'): |
|
163 | if hasattr(self.dataIn, 'flagDataAsBlock'): | |
164 | self.dataOut.flagDataAsBlock = self.dataIn.flagDataAsBlock |
|
164 | self.dataOut.flagDataAsBlock = self.dataIn.flagDataAsBlock | |
165 |
|
165 | |||
166 | if hasattr(self.dataIn, 'ChanDist'): #Distances of receiver channels |
|
166 | if hasattr(self.dataIn, 'ChanDist'): #Distances of receiver channels | |
167 | self.dataOut.ChanDist = self.dataIn.ChanDist |
|
167 | self.dataOut.ChanDist = self.dataIn.ChanDist | |
168 | else: self.dataOut.ChanDist = None |
|
168 | else: self.dataOut.ChanDist = None | |
169 |
|
169 | |||
170 | #if hasattr(self.dataIn, 'VelRange'): #Velocities range |
|
170 | #if hasattr(self.dataIn, 'VelRange'): #Velocities range | |
171 | # self.dataOut.VelRange = self.dataIn.VelRange |
|
171 | # self.dataOut.VelRange = self.dataIn.VelRange | |
172 | #else: self.dataOut.VelRange = None |
|
172 | #else: self.dataOut.VelRange = None | |
173 |
|
173 | |||
174 | if hasattr(self.dataIn, 'RadarConst'): #Radar Constant |
|
174 | if hasattr(self.dataIn, 'RadarConst'): #Radar Constant | |
175 | self.dataOut.RadarConst = self.dataIn.RadarConst |
|
175 | self.dataOut.RadarConst = self.dataIn.RadarConst | |
176 |
|
176 | |||
177 | if hasattr(self.dataIn, 'NPW'): #NPW |
|
177 | if hasattr(self.dataIn, 'NPW'): #NPW | |
178 | self.dataOut.NPW = self.dataIn.NPW |
|
178 | self.dataOut.NPW = self.dataIn.NPW | |
179 |
|
179 | |||
180 | if hasattr(self.dataIn, 'COFA'): #COFA |
|
180 | if hasattr(self.dataIn, 'COFA'): #COFA | |
181 | self.dataOut.COFA = self.dataIn.COFA |
|
181 | self.dataOut.COFA = self.dataIn.COFA | |
182 |
|
182 | |||
183 |
|
183 | |||
184 |
|
184 | |||
185 | #---------------------- Correlation Data --------------------------- |
|
185 | #---------------------- Correlation Data --------------------------- | |
186 |
|
186 | |||
187 | if self.dataIn.type == "Correlation": |
|
187 | if self.dataIn.type == "Correlation": | |
188 | acf_ind, ccf_ind, acf_pairs, ccf_pairs, data_acf, data_ccf = self.dataIn.splitFunctions() |
|
188 | acf_ind, ccf_ind, acf_pairs, ccf_pairs, data_acf, data_ccf = self.dataIn.splitFunctions() | |
189 |
|
189 | |||
190 | self.dataOut.data_pre = (self.dataIn.data_cf[acf_ind,:], self.dataIn.data_cf[ccf_ind,:,:]) |
|
190 | self.dataOut.data_pre = (self.dataIn.data_cf[acf_ind,:], self.dataIn.data_cf[ccf_ind,:,:]) | |
191 | self.dataOut.normFactor = (self.dataIn.normFactor[acf_ind,:], self.dataIn.normFactor[ccf_ind,:]) |
|
191 | self.dataOut.normFactor = (self.dataIn.normFactor[acf_ind,:], self.dataIn.normFactor[ccf_ind,:]) | |
192 | self.dataOut.groupList = (acf_pairs, ccf_pairs) |
|
192 | self.dataOut.groupList = (acf_pairs, ccf_pairs) | |
193 |
|
193 | |||
194 | self.dataOut.abscissaList = self.dataIn.lagRange |
|
194 | self.dataOut.abscissaList = self.dataIn.lagRange | |
195 | self.dataOut.noise = self.dataIn.noise |
|
195 | self.dataOut.noise = self.dataIn.noise | |
196 | self.dataOut.data_snr = self.dataIn.SNR |
|
196 | self.dataOut.data_snr = self.dataIn.SNR | |
197 | self.dataOut.flagNoData = False |
|
197 | self.dataOut.flagNoData = False | |
198 | self.dataOut.nAvg = self.dataIn.nAvg |
|
198 | self.dataOut.nAvg = self.dataIn.nAvg | |
199 |
|
199 | |||
200 | #---------------------- Parameters Data --------------------------- |
|
200 | #---------------------- Parameters Data --------------------------- | |
201 |
|
201 | |||
202 | if self.dataIn.type == "Parameters": |
|
202 | if self.dataIn.type == "Parameters": | |
203 | self.dataOut.copy(self.dataIn) |
|
203 | self.dataOut.copy(self.dataIn) | |
204 | self.dataOut.flagNoData = False |
|
204 | self.dataOut.flagNoData = False | |
205 | #print("yo si entre") |
|
205 | #print("yo si entre") | |
206 |
|
206 | |||
207 | return True |
|
207 | return True | |
208 |
|
208 | |||
209 | self.__updateObjFromInput() |
|
209 | self.__updateObjFromInput() | |
210 | #print("yo si entre2") |
|
210 | #print("yo si entre2") | |
211 |
|
211 | |||
212 | self.dataOut.utctimeInit = self.dataIn.utctime |
|
212 | self.dataOut.utctimeInit = self.dataIn.utctime | |
213 | self.dataOut.paramInterval = self.dataIn.timeInterval |
|
213 | self.dataOut.paramInterval = self.dataIn.timeInterval | |
214 | #print("soy spectra ",self.dataOut.utctimeInit) |
|
214 | #print("soy spectra ",self.dataOut.utctimeInit) | |
215 | return |
|
215 | return | |
216 |
|
216 | |||
217 |
|
217 | |||
218 | def target(tups): |
|
218 | def target(tups): | |
219 |
|
219 | |||
220 | obj, args = tups |
|
220 | obj, args = tups | |
221 |
|
221 | |||
222 | return obj.FitGau(args) |
|
222 | return obj.FitGau(args) | |
223 |
|
223 | |||
224 | class RemoveWideGC(Operation): |
|
224 | class RemoveWideGC(Operation): | |
225 | ''' This class remove the wide clutter and replace it with a simple interpolation points |
|
225 | ''' This class remove the wide clutter and replace it with a simple interpolation points | |
226 | This mainly applies to CLAIRE radar |
|
226 | This mainly applies to CLAIRE radar | |
227 |
|
227 | |||
228 | ClutterWidth : Width to look for the clutter peak |
|
228 | ClutterWidth : Width to look for the clutter peak | |
229 |
|
229 | |||
230 | Input: |
|
230 | Input: | |
231 |
|
231 | |||
232 | self.dataOut.data_pre : SPC and CSPC |
|
232 | self.dataOut.data_pre : SPC and CSPC | |
233 | self.dataOut.spc_range : To select wind and rainfall velocities |
|
233 | self.dataOut.spc_range : To select wind and rainfall velocities | |
234 |
|
234 | |||
235 | Affected: |
|
235 | Affected: | |
236 |
|
236 | |||
237 | self.dataOut.data_pre : It is used for the new SPC and CSPC ranges of wind |
|
237 | self.dataOut.data_pre : It is used for the new SPC and CSPC ranges of wind | |
238 |
|
238 | |||
239 | Written by D. ScipiΓ³n 25.02.2021 |
|
239 | Written by D. ScipiΓ³n 25.02.2021 | |
240 | ''' |
|
240 | ''' | |
241 | def __init__(self): |
|
241 | def __init__(self): | |
242 | Operation.__init__(self) |
|
242 | Operation.__init__(self) | |
243 | self.i = 0 |
|
243 | self.i = 0 | |
244 | self.ich = 0 |
|
244 | self.ich = 0 | |
245 | self.ir = 0 |
|
245 | self.ir = 0 | |
246 |
|
246 | |||
247 | def run(self, dataOut, ClutterWidth=2.5): |
|
247 | def run(self, dataOut, ClutterWidth=2.5): | |
248 | # print ('Entering RemoveWideGC ... ') |
|
248 | # print ('Entering RemoveWideGC ... ') | |
249 |
|
249 | |||
250 | self.spc = dataOut.data_pre[0].copy() |
|
250 | self.spc = dataOut.data_pre[0].copy() | |
251 | self.spc_out = dataOut.data_pre[0].copy() |
|
251 | self.spc_out = dataOut.data_pre[0].copy() | |
252 | self.Num_Chn = self.spc.shape[0] |
|
252 | self.Num_Chn = self.spc.shape[0] | |
253 | self.Num_Hei = self.spc.shape[2] |
|
253 | self.Num_Hei = self.spc.shape[2] | |
254 | VelRange = dataOut.spc_range[2][:-1] |
|
254 | VelRange = dataOut.spc_range[2][:-1] | |
255 | dv = VelRange[1]-VelRange[0] |
|
255 | dv = VelRange[1]-VelRange[0] | |
256 |
|
256 | |||
257 | # Find the velocities that corresponds to zero |
|
257 | # Find the velocities that corresponds to zero | |
258 | gc_values = numpy.squeeze(numpy.where(numpy.abs(VelRange) <= ClutterWidth)) |
|
258 | gc_values = numpy.squeeze(numpy.where(numpy.abs(VelRange) <= ClutterWidth)) | |
259 |
|
259 | |||
260 | # Removing novalid data from the spectra |
|
260 | # Removing novalid data from the spectra | |
261 | for ich in range(self.Num_Chn) : |
|
261 | for ich in range(self.Num_Chn) : | |
262 | for ir in range(self.Num_Hei) : |
|
262 | for ir in range(self.Num_Hei) : | |
263 | # Estimate the noise at each range |
|
263 | # Estimate the noise at each range | |
264 | HSn = hildebrand_sekhon(self.spc[ich,:,ir],dataOut.nIncohInt) |
|
264 | HSn = hildebrand_sekhon(self.spc[ich,:,ir],dataOut.nIncohInt) | |
265 |
|
265 | |||
266 | # Removing the noise floor at each range |
|
266 | # Removing the noise floor at each range | |
267 | novalid = numpy.where(self.spc[ich,:,ir] < HSn) |
|
267 | novalid = numpy.where(self.spc[ich,:,ir] < HSn) | |
268 | self.spc[ich,novalid,ir] = HSn |
|
268 | self.spc[ich,novalid,ir] = HSn | |
269 |
|
269 | |||
270 | junk = numpy.append(numpy.insert(numpy.squeeze(self.spc[ich,gc_values,ir]),0,HSn),HSn) |
|
270 | junk = numpy.append(numpy.insert(numpy.squeeze(self.spc[ich,gc_values,ir]),0,HSn),HSn) | |
271 | j1index = numpy.squeeze(numpy.where(numpy.diff(junk)>0)) |
|
271 | j1index = numpy.squeeze(numpy.where(numpy.diff(junk)>0)) | |
272 | j2index = numpy.squeeze(numpy.where(numpy.diff(junk)<0)) |
|
272 | j2index = numpy.squeeze(numpy.where(numpy.diff(junk)<0)) | |
273 | if ((numpy.size(j1index)<=1) | (numpy.size(j2index)<=1)) : |
|
273 | if ((numpy.size(j1index)<=1) | (numpy.size(j2index)<=1)) : | |
274 | continue |
|
274 | continue | |
275 | junk3 = numpy.squeeze(numpy.diff(j1index)) |
|
275 | junk3 = numpy.squeeze(numpy.diff(j1index)) | |
276 | junk4 = numpy.squeeze(numpy.diff(j2index)) |
|
276 | junk4 = numpy.squeeze(numpy.diff(j2index)) | |
277 |
|
277 | |||
278 | valleyindex = j2index[numpy.where(junk4>1)] |
|
278 | valleyindex = j2index[numpy.where(junk4>1)] | |
279 | peakindex = j1index[numpy.where(junk3>1)] |
|
279 | peakindex = j1index[numpy.where(junk3>1)] | |
280 |
|
280 | |||
281 | isvalid = numpy.squeeze(numpy.where(numpy.abs(VelRange[gc_values[peakindex]]) <= 2.5*dv)) |
|
281 | isvalid = numpy.squeeze(numpy.where(numpy.abs(VelRange[gc_values[peakindex]]) <= 2.5*dv)) | |
282 | if numpy.size(isvalid) == 0 : |
|
282 | if numpy.size(isvalid) == 0 : | |
283 | continue |
|
283 | continue | |
284 | if numpy.size(isvalid) >1 : |
|
284 | if numpy.size(isvalid) >1 : | |
285 | vindex = numpy.argmax(self.spc[ich,gc_values[peakindex[isvalid]],ir]) |
|
285 | vindex = numpy.argmax(self.spc[ich,gc_values[peakindex[isvalid]],ir]) | |
286 | isvalid = isvalid[vindex] |
|
286 | isvalid = isvalid[vindex] | |
287 |
|
287 | |||
288 | # clutter peak |
|
288 | # clutter peak | |
289 | gcpeak = peakindex[isvalid] |
|
289 | gcpeak = peakindex[isvalid] | |
290 | vl = numpy.where(valleyindex < gcpeak) |
|
290 | vl = numpy.where(valleyindex < gcpeak) | |
291 | if numpy.size(vl) == 0: |
|
291 | if numpy.size(vl) == 0: | |
292 | continue |
|
292 | continue | |
293 | gcvl = valleyindex[vl[0][-1]] |
|
293 | gcvl = valleyindex[vl[0][-1]] | |
294 | vr = numpy.where(valleyindex > gcpeak) |
|
294 | vr = numpy.where(valleyindex > gcpeak) | |
295 | if numpy.size(vr) == 0: |
|
295 | if numpy.size(vr) == 0: | |
296 | continue |
|
296 | continue | |
297 | gcvr = valleyindex[vr[0][0]] |
|
297 | gcvr = valleyindex[vr[0][0]] | |
298 |
|
298 | |||
299 | # Removing the clutter |
|
299 | # Removing the clutter | |
300 | interpindex = numpy.array([gc_values[gcvl], gc_values[gcvr]]) |
|
300 | interpindex = numpy.array([gc_values[gcvl], gc_values[gcvr]]) | |
301 | gcindex = gc_values[gcvl+1:gcvr-1] |
|
301 | gcindex = gc_values[gcvl+1:gcvr-1] | |
302 | self.spc_out[ich,gcindex,ir] = numpy.interp(VelRange[gcindex],VelRange[interpindex],self.spc[ich,interpindex,ir]) |
|
302 | self.spc_out[ich,gcindex,ir] = numpy.interp(VelRange[gcindex],VelRange[interpindex],self.spc[ich,interpindex,ir]) | |
303 |
|
303 | |||
304 | dataOut.data_pre[0] = self.spc_out |
|
304 | dataOut.data_pre[0] = self.spc_out | |
305 | #print ('Leaving RemoveWideGC ... ') |
|
305 | #print ('Leaving RemoveWideGC ... ') | |
306 | return dataOut |
|
306 | return dataOut | |
307 |
|
307 | |||
308 | class SpectralFilters(Operation): |
|
308 | class SpectralFilters(Operation): | |
309 | ''' This class allows to replace the novalid values with noise for each channel |
|
309 | ''' This class allows to replace the novalid values with noise for each channel | |
310 | This applies to CLAIRE RADAR |
|
310 | This applies to CLAIRE RADAR | |
311 |
|
311 | |||
312 | PositiveLimit : RightLimit of novalid data |
|
312 | PositiveLimit : RightLimit of novalid data | |
313 | NegativeLimit : LeftLimit of novalid data |
|
313 | NegativeLimit : LeftLimit of novalid data | |
314 |
|
314 | |||
315 | Input: |
|
315 | Input: | |
316 |
|
316 | |||
317 | self.dataOut.data_pre : SPC and CSPC |
|
317 | self.dataOut.data_pre : SPC and CSPC | |
318 | self.dataOut.spc_range : To select wind and rainfall velocities |
|
318 | self.dataOut.spc_range : To select wind and rainfall velocities | |
319 |
|
319 | |||
320 | Affected: |
|
320 | Affected: | |
321 |
|
321 | |||
322 | self.dataOut.data_pre : It is used for the new SPC and CSPC ranges of wind |
|
322 | self.dataOut.data_pre : It is used for the new SPC and CSPC ranges of wind | |
323 |
|
323 | |||
324 | Written by D. ScipiΓ³n 29.01.2021 |
|
324 | Written by D. ScipiΓ³n 29.01.2021 | |
325 | ''' |
|
325 | ''' | |
326 | def __init__(self): |
|
326 | def __init__(self): | |
327 | Operation.__init__(self) |
|
327 | Operation.__init__(self) | |
328 | self.i = 0 |
|
328 | self.i = 0 | |
329 |
|
329 | |||
330 | def run(self, dataOut, ): |
|
330 | def run(self, dataOut, ): | |
331 |
|
331 | |||
332 | self.spc = dataOut.data_pre[0].copy() |
|
332 | self.spc = dataOut.data_pre[0].copy() | |
333 | self.Num_Chn = self.spc.shape[0] |
|
333 | self.Num_Chn = self.spc.shape[0] | |
334 | VelRange = dataOut.spc_range[2] |
|
334 | VelRange = dataOut.spc_range[2] | |
335 |
|
335 | |||
336 | # novalid corresponds to data within the Negative and PositiveLimit |
|
336 | # novalid corresponds to data within the Negative and PositiveLimit | |
337 |
|
337 | |||
338 |
|
338 | |||
339 | # Removing novalid data from the spectra |
|
339 | # Removing novalid data from the spectra | |
340 | for i in range(self.Num_Chn): |
|
340 | for i in range(self.Num_Chn): | |
341 | self.spc[i,novalid,:] = dataOut.noise[i] |
|
341 | self.spc[i,novalid,:] = dataOut.noise[i] | |
342 | dataOut.data_pre[0] = self.spc |
|
342 | dataOut.data_pre[0] = self.spc | |
343 | return dataOut |
|
343 | return dataOut | |
344 |
|
344 | |||
345 | class GaussianFit(Operation): |
|
345 | class GaussianFit(Operation): | |
346 |
|
346 | |||
347 | ''' |
|
347 | ''' | |
348 | Function that fit of one and two generalized gaussians (gg) based |
|
348 | Function that fit of one and two generalized gaussians (gg) based | |
349 | on the PSD shape across an "power band" identified from a cumsum of |
|
349 | on the PSD shape across an "power band" identified from a cumsum of | |
350 | the measured spectrum - noise. |
|
350 | the measured spectrum - noise. | |
351 |
|
351 | |||
352 | Input: |
|
352 | Input: | |
353 | self.dataOut.data_pre : SelfSpectra |
|
353 | self.dataOut.data_pre : SelfSpectra | |
354 |
|
354 | |||
355 | Output: |
|
355 | Output: | |
356 | self.dataOut.SPCparam : SPC_ch1, SPC_ch2 |
|
356 | self.dataOut.SPCparam : SPC_ch1, SPC_ch2 | |
357 |
|
357 | |||
358 | ''' |
|
358 | ''' | |
359 | def __init__(self): |
|
359 | def __init__(self): | |
360 | Operation.__init__(self) |
|
360 | Operation.__init__(self) | |
361 | self.i=0 |
|
361 | self.i=0 | |
362 |
|
362 | |||
363 |
|
363 | |||
364 | # def run(self, dataOut, num_intg=7, pnoise=1., SNRlimit=-9): #num_intg: Incoherent integrations, pnoise: Noise, vel_arr: range of velocities, similar to the ftt points |
|
364 | # def run(self, dataOut, num_intg=7, pnoise=1., SNRlimit=-9): #num_intg: Incoherent integrations, pnoise: Noise, vel_arr: range of velocities, similar to the ftt points | |
365 | def run(self, dataOut, SNRdBlimit=-9, method='generalized'): |
|
365 | def run(self, dataOut, SNRdBlimit=-9, method='generalized'): | |
366 | """This routine will find a couple of generalized Gaussians to a power spectrum |
|
366 | """This routine will find a couple of generalized Gaussians to a power spectrum | |
367 | methods: generalized, squared |
|
367 | methods: generalized, squared | |
368 | input: spc |
|
368 | input: spc | |
369 | output: |
|
369 | output: | |
370 | noise, amplitude0,shift0,width0,p0,Amplitude1,shift1,width1,p1 |
|
370 | noise, amplitude0,shift0,width0,p0,Amplitude1,shift1,width1,p1 | |
371 | """ |
|
371 | """ | |
372 | print ('Entering ',method,' double Gaussian fit') |
|
372 | print ('Entering ',method,' double Gaussian fit') | |
373 | self.spc = dataOut.data_pre[0].copy() |
|
373 | self.spc = dataOut.data_pre[0].copy() | |
374 | self.Num_Hei = self.spc.shape[2] |
|
374 | self.Num_Hei = self.spc.shape[2] | |
375 | self.Num_Bin = self.spc.shape[1] |
|
375 | self.Num_Bin = self.spc.shape[1] | |
376 | self.Num_Chn = self.spc.shape[0] |
|
376 | self.Num_Chn = self.spc.shape[0] | |
377 |
|
377 | |||
378 | start_time = time.time() |
|
378 | start_time = time.time() | |
379 |
|
379 | |||
380 | pool = Pool(processes=self.Num_Chn) |
|
380 | pool = Pool(processes=self.Num_Chn) | |
381 | args = [(dataOut.spc_range[2], ich, dataOut.spc_noise[ich], dataOut.nIncohInt, SNRdBlimit) for ich in range(self.Num_Chn)] |
|
381 | args = [(dataOut.spc_range[2], ich, dataOut.spc_noise[ich], dataOut.nIncohInt, SNRdBlimit) for ich in range(self.Num_Chn)] | |
382 | objs = [self for __ in range(self.Num_Chn)] |
|
382 | objs = [self for __ in range(self.Num_Chn)] | |
383 | attrs = list(zip(objs, args)) |
|
383 | attrs = list(zip(objs, args)) | |
384 | DGauFitParam = pool.map(target, attrs) |
|
384 | DGauFitParam = pool.map(target, attrs) | |
385 | # Parameters: |
|
385 | # Parameters: | |
386 | # 0. Noise, 1. Amplitude, 2. Shift, 3. Width 4. Power |
|
386 | # 0. Noise, 1. Amplitude, 2. Shift, 3. Width 4. Power | |
387 | dataOut.DGauFitParams = numpy.asarray(DGauFitParam) |
|
387 | dataOut.DGauFitParams = numpy.asarray(DGauFitParam) | |
388 |
|
388 | |||
389 | # Double Gaussian Curves |
|
389 | # Double Gaussian Curves | |
390 | gau0 = numpy.zeros([self.Num_Chn,self.Num_Bin,self.Num_Hei]) |
|
390 | gau0 = numpy.zeros([self.Num_Chn,self.Num_Bin,self.Num_Hei]) | |
391 | gau0[:] = numpy.NaN |
|
391 | gau0[:] = numpy.NaN | |
392 | gau1 = numpy.zeros([self.Num_Chn,self.Num_Bin,self.Num_Hei]) |
|
392 | gau1 = numpy.zeros([self.Num_Chn,self.Num_Bin,self.Num_Hei]) | |
393 | gau1[:] = numpy.NaN |
|
393 | gau1[:] = numpy.NaN | |
394 | x_mtr = numpy.transpose(numpy.tile(dataOut.getVelRange(1)[:-1], (self.Num_Hei,1))) |
|
394 | x_mtr = numpy.transpose(numpy.tile(dataOut.getVelRange(1)[:-1], (self.Num_Hei,1))) | |
395 | for iCh in range(self.Num_Chn): |
|
395 | for iCh in range(self.Num_Chn): | |
396 | N0 = numpy.transpose(numpy.transpose([dataOut.DGauFitParams[iCh][0,:,0]] * self.Num_Bin)) |
|
396 | N0 = numpy.transpose(numpy.transpose([dataOut.DGauFitParams[iCh][0,:,0]] * self.Num_Bin)) | |
397 | N1 = numpy.transpose(numpy.transpose([dataOut.DGauFitParams[iCh][0,:,1]] * self.Num_Bin)) |
|
397 | N1 = numpy.transpose(numpy.transpose([dataOut.DGauFitParams[iCh][0,:,1]] * self.Num_Bin)) | |
398 | A0 = numpy.transpose(numpy.transpose([dataOut.DGauFitParams[iCh][1,:,0]] * self.Num_Bin)) |
|
398 | A0 = numpy.transpose(numpy.transpose([dataOut.DGauFitParams[iCh][1,:,0]] * self.Num_Bin)) | |
399 | A1 = numpy.transpose(numpy.transpose([dataOut.DGauFitParams[iCh][1,:,1]] * self.Num_Bin)) |
|
399 | A1 = numpy.transpose(numpy.transpose([dataOut.DGauFitParams[iCh][1,:,1]] * self.Num_Bin)) | |
400 | v0 = numpy.transpose(numpy.transpose([dataOut.DGauFitParams[iCh][2,:,0]] * self.Num_Bin)) |
|
400 | v0 = numpy.transpose(numpy.transpose([dataOut.DGauFitParams[iCh][2,:,0]] * self.Num_Bin)) | |
401 | v1 = numpy.transpose(numpy.transpose([dataOut.DGauFitParams[iCh][2,:,1]] * self.Num_Bin)) |
|
401 | v1 = numpy.transpose(numpy.transpose([dataOut.DGauFitParams[iCh][2,:,1]] * self.Num_Bin)) | |
402 | s0 = numpy.transpose(numpy.transpose([dataOut.DGauFitParams[iCh][3,:,0]] * self.Num_Bin)) |
|
402 | s0 = numpy.transpose(numpy.transpose([dataOut.DGauFitParams[iCh][3,:,0]] * self.Num_Bin)) | |
403 | s1 = numpy.transpose(numpy.transpose([dataOut.DGauFitParams[iCh][3,:,1]] * self.Num_Bin)) |
|
403 | s1 = numpy.transpose(numpy.transpose([dataOut.DGauFitParams[iCh][3,:,1]] * self.Num_Bin)) | |
404 | if method == 'genealized': |
|
404 | if method == 'genealized': | |
405 | p0 = numpy.transpose(numpy.transpose([dataOut.DGauFitParams[iCh][4,:,0]] * self.Num_Bin)) |
|
405 | p0 = numpy.transpose(numpy.transpose([dataOut.DGauFitParams[iCh][4,:,0]] * self.Num_Bin)) | |
406 | p1 = numpy.transpose(numpy.transpose([dataOut.DGauFitParams[iCh][4,:,1]] * self.Num_Bin)) |
|
406 | p1 = numpy.transpose(numpy.transpose([dataOut.DGauFitParams[iCh][4,:,1]] * self.Num_Bin)) | |
407 | elif method == 'squared': |
|
407 | elif method == 'squared': | |
408 | p0 = 2. |
|
408 | p0 = 2. | |
409 | p1 = 2. |
|
409 | p1 = 2. | |
410 | gau0[iCh] = A0*numpy.exp(-0.5*numpy.abs((x_mtr-v0)/s0)**p0)+N0 |
|
410 | gau0[iCh] = A0*numpy.exp(-0.5*numpy.abs((x_mtr-v0)/s0)**p0)+N0 | |
411 | gau1[iCh] = A1*numpy.exp(-0.5*numpy.abs((x_mtr-v1)/s1)**p1)+N1 |
|
411 | gau1[iCh] = A1*numpy.exp(-0.5*numpy.abs((x_mtr-v1)/s1)**p1)+N1 | |
412 | dataOut.GaussFit0 = gau0 |
|
412 | dataOut.GaussFit0 = gau0 | |
413 | dataOut.GaussFit1 = gau1 |
|
413 | dataOut.GaussFit1 = gau1 | |
414 |
|
414 | |||
415 | print('Leaving ',method ,' double Gaussian fit') |
|
415 | print('Leaving ',method ,' double Gaussian fit') | |
416 | return dataOut |
|
416 | return dataOut | |
417 |
|
417 | |||
418 | def FitGau(self, X): |
|
418 | def FitGau(self, X): | |
419 | # print('Entering FitGau') |
|
419 | # print('Entering FitGau') | |
420 | # Assigning the variables |
|
420 | # Assigning the variables | |
421 | Vrange, ch, wnoise, num_intg, SNRlimit = X |
|
421 | Vrange, ch, wnoise, num_intg, SNRlimit = X | |
422 | # Noise Limits |
|
422 | # Noise Limits | |
423 | noisebl = wnoise * 0.9 |
|
423 | noisebl = wnoise * 0.9 | |
424 | noisebh = wnoise * 1.1 |
|
424 | noisebh = wnoise * 1.1 | |
425 | # Radar Velocity |
|
425 | # Radar Velocity | |
426 | Va = max(Vrange) |
|
426 | Va = max(Vrange) | |
427 | deltav = Vrange[1] - Vrange[0] |
|
427 | deltav = Vrange[1] - Vrange[0] | |
428 | x = numpy.arange(self.Num_Bin) |
|
428 | x = numpy.arange(self.Num_Bin) | |
429 |
|
429 | |||
430 | # print ('stop 0') |
|
430 | # print ('stop 0') | |
431 |
|
431 | |||
432 | # 5 parameters, 2 Gaussians |
|
432 | # 5 parameters, 2 Gaussians | |
433 | DGauFitParam = numpy.zeros([5, self.Num_Hei,2]) |
|
433 | DGauFitParam = numpy.zeros([5, self.Num_Hei,2]) | |
434 | DGauFitParam[:] = numpy.NaN |
|
434 | DGauFitParam[:] = numpy.NaN | |
435 |
|
435 | |||
436 | # SPCparam = [] |
|
436 | # SPCparam = [] | |
437 | # SPC_ch1 = numpy.zeros([self.Num_Bin,self.Num_Hei]) |
|
437 | # SPC_ch1 = numpy.zeros([self.Num_Bin,self.Num_Hei]) | |
438 | # SPC_ch2 = numpy.zeros([self.Num_Bin,self.Num_Hei]) |
|
438 | # SPC_ch2 = numpy.zeros([self.Num_Bin,self.Num_Hei]) | |
439 | # SPC_ch1[:] = 0 #numpy.NaN |
|
439 | # SPC_ch1[:] = 0 #numpy.NaN | |
440 | # SPC_ch2[:] = 0 #numpy.NaN |
|
440 | # SPC_ch2[:] = 0 #numpy.NaN | |
441 | # print ('stop 1') |
|
441 | # print ('stop 1') | |
442 | for ht in range(self.Num_Hei): |
|
442 | for ht in range(self.Num_Hei): | |
443 | # print (ht) |
|
443 | # print (ht) | |
444 | # print ('stop 2') |
|
444 | # print ('stop 2') | |
445 | # Spectra at each range |
|
445 | # Spectra at each range | |
446 | spc = numpy.asarray(self.spc)[ch,:,ht] |
|
446 | spc = numpy.asarray(self.spc)[ch,:,ht] | |
447 | snr = ( spc.mean() - wnoise ) / wnoise |
|
447 | snr = ( spc.mean() - wnoise ) / wnoise | |
448 | snrdB = 10.*numpy.log10(snr) |
|
448 | snrdB = 10.*numpy.log10(snr) | |
449 |
|
449 | |||
450 | #print ('stop 3') |
|
450 | #print ('stop 3') | |
451 | if snrdB < SNRlimit : |
|
451 | if snrdB < SNRlimit : | |
452 | # snr = numpy.NaN |
|
452 | # snr = numpy.NaN | |
453 | # SPC_ch1[:,ht] = 0#numpy.NaN |
|
453 | # SPC_ch1[:,ht] = 0#numpy.NaN | |
454 | # SPC_ch1[:,ht] = 0#numpy.NaN |
|
454 | # SPC_ch1[:,ht] = 0#numpy.NaN | |
455 | # SPCparam = (SPC_ch1,SPC_ch2) |
|
455 | # SPCparam = (SPC_ch1,SPC_ch2) | |
456 | # print ('SNR less than SNRth') |
|
456 | # print ('SNR less than SNRth') | |
457 | continue |
|
457 | continue | |
458 | # wnoise = hildebrand_sekhon(spc,num_intg) |
|
458 | # wnoise = hildebrand_sekhon(spc,num_intg) | |
459 | # print ('stop 2.01') |
|
459 | # print ('stop 2.01') | |
460 | ############################################# |
|
460 | ############################################# | |
461 | # normalizing spc and noise |
|
461 | # normalizing spc and noise | |
462 | # This part differs from gg1 |
|
462 | # This part differs from gg1 | |
463 | # spc_norm_max = max(spc) #commented by D. ScipiΓ³n 19.03.2021 |
|
463 | # spc_norm_max = max(spc) #commented by D. ScipiΓ³n 19.03.2021 | |
464 | #spc = spc / spc_norm_max |
|
464 | #spc = spc / spc_norm_max | |
465 | # pnoise = pnoise #/ spc_norm_max #commented by D. ScipiΓ³n 19.03.2021 |
|
465 | # pnoise = pnoise #/ spc_norm_max #commented by D. ScipiΓ³n 19.03.2021 | |
466 | ############################################# |
|
466 | ############################################# | |
467 |
|
467 | |||
468 | # print ('stop 2.1') |
|
468 | # print ('stop 2.1') | |
469 | fatspectra=1.0 |
|
469 | fatspectra=1.0 | |
470 | # noise per channel.... we might want to use the noise at each range |
|
470 | # noise per channel.... we might want to use the noise at each range | |
471 |
|
471 | |||
472 | # wnoise = noise_ #/ spc_norm_max #commented by D. ScipiΓ³n 19.03.2021 |
|
472 | # wnoise = noise_ #/ spc_norm_max #commented by D. ScipiΓ³n 19.03.2021 | |
473 | #wnoise,stdv,i_max,index =enoise(spc,num_intg) #noise estimate using Hildebrand Sekhon, only wnoise is used |
|
473 | #wnoise,stdv,i_max,index =enoise(spc,num_intg) #noise estimate using Hildebrand Sekhon, only wnoise is used | |
474 | #if wnoise>1.1*pnoise: # to be tested later |
|
474 | #if wnoise>1.1*pnoise: # to be tested later | |
475 | # wnoise=pnoise |
|
475 | # wnoise=pnoise | |
476 | # noisebl = wnoise*0.9 |
|
476 | # noisebl = wnoise*0.9 | |
477 | # noisebh = wnoise*1.1 |
|
477 | # noisebh = wnoise*1.1 | |
478 | spc = spc - wnoise # signal |
|
478 | spc = spc - wnoise # signal | |
479 |
|
479 | |||
480 | # print ('stop 2.2') |
|
480 | # print ('stop 2.2') | |
481 | minx = numpy.argmin(spc) |
|
481 | minx = numpy.argmin(spc) | |
482 | #spcs=spc.copy() |
|
482 | #spcs=spc.copy() | |
483 | spcs = numpy.roll(spc,-minx) |
|
483 | spcs = numpy.roll(spc,-minx) | |
484 | cum = numpy.cumsum(spcs) |
|
484 | cum = numpy.cumsum(spcs) | |
485 | # tot_noise = wnoise * self.Num_Bin #64; |
|
485 | # tot_noise = wnoise * self.Num_Bin #64; | |
486 |
|
486 | |||
487 | # print ('stop 2.3') |
|
487 | # print ('stop 2.3') | |
488 | # snr = sum(spcs) / tot_noise |
|
488 | # snr = sum(spcs) / tot_noise | |
489 | # snrdB = 10.*numpy.log10(snr) |
|
489 | # snrdB = 10.*numpy.log10(snr) | |
490 | #print ('stop 3') |
|
490 | #print ('stop 3') | |
491 | # if snrdB < SNRlimit : |
|
491 | # if snrdB < SNRlimit : | |
492 | # snr = numpy.NaN |
|
492 | # snr = numpy.NaN | |
493 | # SPC_ch1[:,ht] = 0#numpy.NaN |
|
493 | # SPC_ch1[:,ht] = 0#numpy.NaN | |
494 | # SPC_ch1[:,ht] = 0#numpy.NaN |
|
494 | # SPC_ch1[:,ht] = 0#numpy.NaN | |
495 | # SPCparam = (SPC_ch1,SPC_ch2) |
|
495 | # SPCparam = (SPC_ch1,SPC_ch2) | |
496 | # print ('SNR less than SNRth') |
|
496 | # print ('SNR less than SNRth') | |
497 | # continue |
|
497 | # continue | |
498 |
|
498 | |||
499 |
|
499 | |||
500 | #if snrdB<-18 or numpy.isnan(snrdB) or num_intg<4: |
|
500 | #if snrdB<-18 or numpy.isnan(snrdB) or num_intg<4: | |
501 | # return [None,]*4,[None,]*4,None,snrdB,None,None,[None,]*5,[None,]*9,None |
|
501 | # return [None,]*4,[None,]*4,None,snrdB,None,None,[None,]*5,[None,]*9,None | |
502 | # print ('stop 4') |
|
502 | # print ('stop 4') | |
503 | cummax = max(cum) |
|
503 | cummax = max(cum) | |
504 | epsi = 0.08 * fatspectra # cumsum to narrow down the energy region |
|
504 | epsi = 0.08 * fatspectra # cumsum to narrow down the energy region | |
505 | cumlo = cummax * epsi |
|
505 | cumlo = cummax * epsi | |
506 | cumhi = cummax * (1-epsi) |
|
506 | cumhi = cummax * (1-epsi) | |
507 | powerindex = numpy.array(numpy.where(numpy.logical_and(cum>cumlo, cum<cumhi))[0]) |
|
507 | powerindex = numpy.array(numpy.where(numpy.logical_and(cum>cumlo, cum<cumhi))[0]) | |
508 |
|
508 | |||
509 | # print ('stop 5') |
|
509 | # print ('stop 5') | |
510 | if len(powerindex) < 1:# case for powerindex 0 |
|
510 | if len(powerindex) < 1:# case for powerindex 0 | |
511 | # print ('powerindex < 1') |
|
511 | # print ('powerindex < 1') | |
512 | continue |
|
512 | continue | |
513 | powerlo = powerindex[0] |
|
513 | powerlo = powerindex[0] | |
514 | powerhi = powerindex[-1] |
|
514 | powerhi = powerindex[-1] | |
515 | powerwidth = powerhi-powerlo |
|
515 | powerwidth = powerhi-powerlo | |
516 | if powerwidth <= 1: |
|
516 | if powerwidth <= 1: | |
517 | # print('powerwidth <= 1') |
|
517 | # print('powerwidth <= 1') | |
518 | continue |
|
518 | continue | |
519 |
|
519 | |||
520 | # print ('stop 6') |
|
520 | # print ('stop 6') | |
521 | firstpeak = powerlo + powerwidth/10.# first gaussian energy location |
|
521 | firstpeak = powerlo + powerwidth/10.# first gaussian energy location | |
522 | secondpeak = powerhi - powerwidth/10. #second gaussian energy location |
|
522 | secondpeak = powerhi - powerwidth/10. #second gaussian energy location | |
523 | midpeak = (firstpeak + secondpeak)/2. |
|
523 | midpeak = (firstpeak + secondpeak)/2. | |
524 | firstamp = spcs[int(firstpeak)] |
|
524 | firstamp = spcs[int(firstpeak)] | |
525 | secondamp = spcs[int(secondpeak)] |
|
525 | secondamp = spcs[int(secondpeak)] | |
526 | midamp = spcs[int(midpeak)] |
|
526 | midamp = spcs[int(midpeak)] | |
527 |
|
527 | |||
528 | y_data = spc + wnoise |
|
528 | y_data = spc + wnoise | |
529 |
|
529 | |||
530 | ''' single Gaussian ''' |
|
530 | ''' single Gaussian ''' | |
531 | shift0 = numpy.mod(midpeak+minx, self.Num_Bin ) |
|
531 | shift0 = numpy.mod(midpeak+minx, self.Num_Bin ) | |
532 | width0 = powerwidth/4.#Initialization entire power of spectrum divided by 4 |
|
532 | width0 = powerwidth/4.#Initialization entire power of spectrum divided by 4 | |
533 | power0 = 2. |
|
533 | power0 = 2. | |
534 | amplitude0 = midamp |
|
534 | amplitude0 = midamp | |
535 | state0 = [shift0,width0,amplitude0,power0,wnoise] |
|
535 | state0 = [shift0,width0,amplitude0,power0,wnoise] | |
536 | bnds = ((0,self.Num_Bin-1),(1,powerwidth),(0,None),(0.5,3.),(noisebl,noisebh)) |
|
536 | bnds = ((0,self.Num_Bin-1),(1,powerwidth),(0,None),(0.5,3.),(noisebl,noisebh)) | |
537 | lsq1 = fmin_l_bfgs_b(self.misfit1, state0, args=(y_data,x,num_intg), bounds=bnds, approx_grad=True) |
|
537 | lsq1 = fmin_l_bfgs_b(self.misfit1, state0, args=(y_data,x,num_intg), bounds=bnds, approx_grad=True) | |
538 | # print ('stop 7.1') |
|
538 | # print ('stop 7.1') | |
539 | # print (bnds) |
|
539 | # print (bnds) | |
540 |
|
540 | |||
541 | chiSq1=lsq1[1] |
|
541 | chiSq1=lsq1[1] | |
542 |
|
542 | |||
543 | # print ('stop 8') |
|
543 | # print ('stop 8') | |
544 | if fatspectra<1.0 and powerwidth<4: |
|
544 | if fatspectra<1.0 and powerwidth<4: | |
545 | choice=0 |
|
545 | choice=0 | |
546 | Amplitude0=lsq1[0][2] |
|
546 | Amplitude0=lsq1[0][2] | |
547 | shift0=lsq1[0][0] |
|
547 | shift0=lsq1[0][0] | |
548 | width0=lsq1[0][1] |
|
548 | width0=lsq1[0][1] | |
549 | p0=lsq1[0][3] |
|
549 | p0=lsq1[0][3] | |
550 | Amplitude1=0. |
|
550 | Amplitude1=0. | |
551 | shift1=0. |
|
551 | shift1=0. | |
552 | width1=0. |
|
552 | width1=0. | |
553 | p1=0. |
|
553 | p1=0. | |
554 | noise=lsq1[0][4] |
|
554 | noise=lsq1[0][4] | |
555 | #return (numpy.array([shift0,width0,Amplitude0,p0]), |
|
555 | #return (numpy.array([shift0,width0,Amplitude0,p0]), | |
556 | # numpy.array([shift1,width1,Amplitude1,p1]),noise,snrdB,chiSq1,6.,sigmas1,[None,]*9,choice) |
|
556 | # numpy.array([shift1,width1,Amplitude1,p1]),noise,snrdB,chiSq1,6.,sigmas1,[None,]*9,choice) | |
557 |
|
557 | |||
558 | # print ('stop 9') |
|
558 | # print ('stop 9') | |
559 | ''' two Gaussians ''' |
|
559 | ''' two Gaussians ''' | |
560 | #shift0=numpy.mod(firstpeak+minx,64); shift1=numpy.mod(secondpeak+minx,64) |
|
560 | #shift0=numpy.mod(firstpeak+minx,64); shift1=numpy.mod(secondpeak+minx,64) | |
561 | shift0 = numpy.mod(firstpeak+minx, self.Num_Bin ) |
|
561 | shift0 = numpy.mod(firstpeak+minx, self.Num_Bin ) | |
562 | shift1 = numpy.mod(secondpeak+minx, self.Num_Bin ) |
|
562 | shift1 = numpy.mod(secondpeak+minx, self.Num_Bin ) | |
563 | width0 = powerwidth/6. |
|
563 | width0 = powerwidth/6. | |
564 | width1 = width0 |
|
564 | width1 = width0 | |
565 | power0 = 2. |
|
565 | power0 = 2. | |
566 | power1 = power0 |
|
566 | power1 = power0 | |
567 | amplitude0 = firstamp |
|
567 | amplitude0 = firstamp | |
568 | amplitude1 = secondamp |
|
568 | amplitude1 = secondamp | |
569 | state0 = [shift0,width0,amplitude0,power0,shift1,width1,amplitude1,power1,wnoise] |
|
569 | state0 = [shift0,width0,amplitude0,power0,shift1,width1,amplitude1,power1,wnoise] | |
570 | #bnds=((0,63),(1,powerwidth/2.),(0,None),(0.5,3.),(0,63),(1,powerwidth/2.),(0,None),(0.5,3.),(noisebl,noisebh)) |
|
570 | #bnds=((0,63),(1,powerwidth/2.),(0,None),(0.5,3.),(0,63),(1,powerwidth/2.),(0,None),(0.5,3.),(noisebl,noisebh)) | |
571 | bnds=((0,self.Num_Bin-1),(1,powerwidth/2.),(0,None),(0.5,3.),(0,self.Num_Bin-1),(1,powerwidth/2.),(0,None),(0.5,3.),(noisebl,noisebh)) |
|
571 | bnds=((0,self.Num_Bin-1),(1,powerwidth/2.),(0,None),(0.5,3.),(0,self.Num_Bin-1),(1,powerwidth/2.),(0,None),(0.5,3.),(noisebl,noisebh)) | |
572 | #bnds=(( 0,(self.Num_Bin-1) ),(1,powerwidth/2.),(0,None),(0.5,3.),( 0,(self.Num_Bin-1)),(1,powerwidth/2.),(0,None),(0.5,3.),(0.1,0.5)) |
|
572 | #bnds=(( 0,(self.Num_Bin-1) ),(1,powerwidth/2.),(0,None),(0.5,3.),( 0,(self.Num_Bin-1)),(1,powerwidth/2.),(0,None),(0.5,3.),(0.1,0.5)) | |
573 |
|
573 | |||
574 | # print ('stop 10') |
|
574 | # print ('stop 10') | |
575 | lsq2 = fmin_l_bfgs_b( self.misfit2 , state0 , args=(y_data,x,num_intg) , bounds=bnds , approx_grad=True ) |
|
575 | lsq2 = fmin_l_bfgs_b( self.misfit2 , state0 , args=(y_data,x,num_intg) , bounds=bnds , approx_grad=True ) | |
576 |
|
576 | |||
577 | # print ('stop 11') |
|
577 | # print ('stop 11') | |
578 | chiSq2 = lsq2[1] |
|
578 | chiSq2 = lsq2[1] | |
579 |
|
579 | |||
580 | # print ('stop 12') |
|
580 | # print ('stop 12') | |
581 |
|
581 | |||
582 | oneG = (chiSq1<5 and chiSq1/chiSq2<2.0) and (abs(lsq2[0][0]-lsq2[0][4])<(lsq2[0][1]+lsq2[0][5])/3. or abs(lsq2[0][0]-lsq2[0][4])<10) |
|
582 | oneG = (chiSq1<5 and chiSq1/chiSq2<2.0) and (abs(lsq2[0][0]-lsq2[0][4])<(lsq2[0][1]+lsq2[0][5])/3. or abs(lsq2[0][0]-lsq2[0][4])<10) | |
583 |
|
583 | |||
584 | # print ('stop 13') |
|
584 | # print ('stop 13') | |
585 | if snrdB>-12: # when SNR is strong pick the peak with least shift (LOS velocity) error |
|
585 | if snrdB>-12: # when SNR is strong pick the peak with least shift (LOS velocity) error | |
586 | if oneG: |
|
586 | if oneG: | |
587 | choice = 0 |
|
587 | choice = 0 | |
588 | else: |
|
588 | else: | |
589 | w1 = lsq2[0][1]; w2 = lsq2[0][5] |
|
589 | w1 = lsq2[0][1]; w2 = lsq2[0][5] | |
590 | a1 = lsq2[0][2]; a2 = lsq2[0][6] |
|
590 | a1 = lsq2[0][2]; a2 = lsq2[0][6] | |
591 | p1 = lsq2[0][3]; p2 = lsq2[0][7] |
|
591 | p1 = lsq2[0][3]; p2 = lsq2[0][7] | |
592 | s1 = (2**(1+1./p1))*scipy.special.gamma(1./p1)/p1 |
|
592 | s1 = (2**(1+1./p1))*scipy.special.gamma(1./p1)/p1 | |
593 | s2 = (2**(1+1./p2))*scipy.special.gamma(1./p2)/p2 |
|
593 | s2 = (2**(1+1./p2))*scipy.special.gamma(1./p2)/p2 | |
594 | gp1 = a1*w1*s1; gp2 = a2*w2*s2 # power content of each ggaussian with proper p scaling |
|
594 | gp1 = a1*w1*s1; gp2 = a2*w2*s2 # power content of each ggaussian with proper p scaling | |
595 |
|
595 | |||
596 | if gp1>gp2: |
|
596 | if gp1>gp2: | |
597 | if a1>0.7*a2: |
|
597 | if a1>0.7*a2: | |
598 | choice = 1 |
|
598 | choice = 1 | |
599 | else: |
|
599 | else: | |
600 | choice = 2 |
|
600 | choice = 2 | |
601 | elif gp2>gp1: |
|
601 | elif gp2>gp1: | |
602 | if a2>0.7*a1: |
|
602 | if a2>0.7*a1: | |
603 | choice = 2 |
|
603 | choice = 2 | |
604 | else: |
|
604 | else: | |
605 | choice = 1 |
|
605 | choice = 1 | |
606 | else: |
|
606 | else: | |
607 | choice = numpy.argmax([a1,a2])+1 |
|
607 | choice = numpy.argmax([a1,a2])+1 | |
608 | #else: |
|
608 | #else: | |
609 | #choice=argmin([std2a,std2b])+1 |
|
609 | #choice=argmin([std2a,std2b])+1 | |
610 |
|
610 | |||
611 | else: # with low SNR go to the most energetic peak |
|
611 | else: # with low SNR go to the most energetic peak | |
612 | choice = numpy.argmax([lsq1[0][2]*lsq1[0][1],lsq2[0][2]*lsq2[0][1],lsq2[0][6]*lsq2[0][5]]) |
|
612 | choice = numpy.argmax([lsq1[0][2]*lsq1[0][1],lsq2[0][2]*lsq2[0][1],lsq2[0][6]*lsq2[0][5]]) | |
613 |
|
613 | |||
614 | # print ('stop 14') |
|
614 | # print ('stop 14') | |
615 | shift0 = lsq2[0][0] |
|
615 | shift0 = lsq2[0][0] | |
616 | vel0 = Vrange[0] + shift0 * deltav |
|
616 | vel0 = Vrange[0] + shift0 * deltav | |
617 | shift1 = lsq2[0][4] |
|
617 | shift1 = lsq2[0][4] | |
618 | # vel1=Vrange[0] + shift1 * deltav |
|
618 | # vel1=Vrange[0] + shift1 * deltav | |
619 |
|
619 | |||
620 | # max_vel = 1.0 |
|
620 | # max_vel = 1.0 | |
621 | # Va = max(Vrange) |
|
621 | # Va = max(Vrange) | |
622 | # deltav = Vrange[1]-Vrange[0] |
|
622 | # deltav = Vrange[1]-Vrange[0] | |
623 | # print ('stop 15') |
|
623 | # print ('stop 15') | |
624 | #first peak will be 0, second peak will be 1 |
|
624 | #first peak will be 0, second peak will be 1 | |
625 | # if vel0 > -1.0 and vel0 < max_vel : #first peak is in the correct range # Commented by D.ScipiΓ³n 19.03.2021 |
|
625 | # if vel0 > -1.0 and vel0 < max_vel : #first peak is in the correct range # Commented by D.ScipiΓ³n 19.03.2021 | |
626 | if vel0 > -Va and vel0 < Va : #first peak is in the correct range |
|
626 | if vel0 > -Va and vel0 < Va : #first peak is in the correct range | |
627 | shift0 = lsq2[0][0] |
|
627 | shift0 = lsq2[0][0] | |
628 | width0 = lsq2[0][1] |
|
628 | width0 = lsq2[0][1] | |
629 | Amplitude0 = lsq2[0][2] |
|
629 | Amplitude0 = lsq2[0][2] | |
630 | p0 = lsq2[0][3] |
|
630 | p0 = lsq2[0][3] | |
631 |
|
631 | |||
632 | shift1 = lsq2[0][4] |
|
632 | shift1 = lsq2[0][4] | |
633 | width1 = lsq2[0][5] |
|
633 | width1 = lsq2[0][5] | |
634 | Amplitude1 = lsq2[0][6] |
|
634 | Amplitude1 = lsq2[0][6] | |
635 | p1 = lsq2[0][7] |
|
635 | p1 = lsq2[0][7] | |
636 | noise = lsq2[0][8] |
|
636 | noise = lsq2[0][8] | |
637 | else: |
|
637 | else: | |
638 | shift1 = lsq2[0][0] |
|
638 | shift1 = lsq2[0][0] | |
639 | width1 = lsq2[0][1] |
|
639 | width1 = lsq2[0][1] | |
640 | Amplitude1 = lsq2[0][2] |
|
640 | Amplitude1 = lsq2[0][2] | |
641 | p1 = lsq2[0][3] |
|
641 | p1 = lsq2[0][3] | |
642 |
|
642 | |||
643 | shift0 = lsq2[0][4] |
|
643 | shift0 = lsq2[0][4] | |
644 | width0 = lsq2[0][5] |
|
644 | width0 = lsq2[0][5] | |
645 | Amplitude0 = lsq2[0][6] |
|
645 | Amplitude0 = lsq2[0][6] | |
646 | p0 = lsq2[0][7] |
|
646 | p0 = lsq2[0][7] | |
647 | noise = lsq2[0][8] |
|
647 | noise = lsq2[0][8] | |
648 |
|
648 | |||
649 | if Amplitude0<0.05: # in case the peak is noise |
|
649 | if Amplitude0<0.05: # in case the peak is noise | |
650 | shift0,width0,Amplitude0,p0 = 4*[numpy.NaN] |
|
650 | shift0,width0,Amplitude0,p0 = 4*[numpy.NaN] | |
651 | if Amplitude1<0.05: |
|
651 | if Amplitude1<0.05: | |
652 | shift1,width1,Amplitude1,p1 = 4*[numpy.NaN] |
|
652 | shift1,width1,Amplitude1,p1 = 4*[numpy.NaN] | |
653 |
|
653 | |||
654 | # print ('stop 16 ') |
|
654 | # print ('stop 16 ') | |
655 | # SPC_ch1[:,ht] = noise + Amplitude0*numpy.exp(-0.5*(abs(x-shift0)/width0)**p0) |
|
655 | # SPC_ch1[:,ht] = noise + Amplitude0*numpy.exp(-0.5*(abs(x-shift0)/width0)**p0) | |
656 | # SPC_ch2[:,ht] = noise + Amplitude1*numpy.exp(-0.5*(abs(x-shift1)/width1)**p1) |
|
656 | # SPC_ch2[:,ht] = noise + Amplitude1*numpy.exp(-0.5*(abs(x-shift1)/width1)**p1) | |
657 | # SPCparam = (SPC_ch1,SPC_ch2) |
|
657 | # SPCparam = (SPC_ch1,SPC_ch2) | |
658 |
|
658 | |||
659 | DGauFitParam[0,ht,0] = noise |
|
659 | DGauFitParam[0,ht,0] = noise | |
660 | DGauFitParam[0,ht,1] = noise |
|
660 | DGauFitParam[0,ht,1] = noise | |
661 | DGauFitParam[1,ht,0] = Amplitude0 |
|
661 | DGauFitParam[1,ht,0] = Amplitude0 | |
662 | DGauFitParam[1,ht,1] = Amplitude1 |
|
662 | DGauFitParam[1,ht,1] = Amplitude1 | |
663 | DGauFitParam[2,ht,0] = Vrange[0] + shift0 * deltav |
|
663 | DGauFitParam[2,ht,0] = Vrange[0] + shift0 * deltav | |
664 | DGauFitParam[2,ht,1] = Vrange[0] + shift1 * deltav |
|
664 | DGauFitParam[2,ht,1] = Vrange[0] + shift1 * deltav | |
665 | DGauFitParam[3,ht,0] = width0 * deltav |
|
665 | DGauFitParam[3,ht,0] = width0 * deltav | |
666 | DGauFitParam[3,ht,1] = width1 * deltav |
|
666 | DGauFitParam[3,ht,1] = width1 * deltav | |
667 | DGauFitParam[4,ht,0] = p0 |
|
667 | DGauFitParam[4,ht,0] = p0 | |
668 | DGauFitParam[4,ht,1] = p1 |
|
668 | DGauFitParam[4,ht,1] = p1 | |
669 |
|
669 | |||
670 | # print (DGauFitParam.shape) |
|
670 | # print (DGauFitParam.shape) | |
671 | # print ('Leaving FitGau') |
|
671 | # print ('Leaving FitGau') | |
672 | return DGauFitParam |
|
672 | return DGauFitParam | |
673 | # return SPCparam |
|
673 | # return SPCparam | |
674 | # return GauSPC |
|
674 | # return GauSPC | |
675 |
|
675 | |||
676 | def y_model1(self,x,state): |
|
676 | def y_model1(self,x,state): | |
677 | shift0, width0, amplitude0, power0, noise = state |
|
677 | shift0, width0, amplitude0, power0, noise = state | |
678 | model0 = amplitude0*numpy.exp(-0.5*abs((x - shift0)/width0)**power0) |
|
678 | model0 = amplitude0*numpy.exp(-0.5*abs((x - shift0)/width0)**power0) | |
679 | model0u = amplitude0*numpy.exp(-0.5*abs((x - shift0 - self.Num_Bin)/width0)**power0) |
|
679 | model0u = amplitude0*numpy.exp(-0.5*abs((x - shift0 - self.Num_Bin)/width0)**power0) | |
680 | model0d = amplitude0*numpy.exp(-0.5*abs((x - shift0 + self.Num_Bin)/width0)**power0) |
|
680 | model0d = amplitude0*numpy.exp(-0.5*abs((x - shift0 + self.Num_Bin)/width0)**power0) | |
681 | return model0 + model0u + model0d + noise |
|
681 | return model0 + model0u + model0d + noise | |
682 |
|
682 | |||
683 | def y_model2(self,x,state): #Equation for two generalized Gaussians with Nyquist |
|
683 | def y_model2(self,x,state): #Equation for two generalized Gaussians with Nyquist | |
684 | shift0, width0, amplitude0, power0, shift1, width1, amplitude1, power1, noise = state |
|
684 | shift0, width0, amplitude0, power0, shift1, width1, amplitude1, power1, noise = state | |
685 | model0 = amplitude0*numpy.exp(-0.5*abs((x-shift0)/width0)**power0) |
|
685 | model0 = amplitude0*numpy.exp(-0.5*abs((x-shift0)/width0)**power0) | |
686 | model0u = amplitude0*numpy.exp(-0.5*abs((x - shift0 - self.Num_Bin)/width0)**power0) |
|
686 | model0u = amplitude0*numpy.exp(-0.5*abs((x - shift0 - self.Num_Bin)/width0)**power0) | |
687 | model0d = amplitude0*numpy.exp(-0.5*abs((x - shift0 + self.Num_Bin)/width0)**power0) |
|
687 | model0d = amplitude0*numpy.exp(-0.5*abs((x - shift0 + self.Num_Bin)/width0)**power0) | |
688 |
|
688 | |||
689 | model1 = amplitude1*numpy.exp(-0.5*abs((x - shift1)/width1)**power1) |
|
689 | model1 = amplitude1*numpy.exp(-0.5*abs((x - shift1)/width1)**power1) | |
690 | model1u = amplitude1*numpy.exp(-0.5*abs((x - shift1 - self.Num_Bin)/width1)**power1) |
|
690 | model1u = amplitude1*numpy.exp(-0.5*abs((x - shift1 - self.Num_Bin)/width1)**power1) | |
691 | model1d = amplitude1*numpy.exp(-0.5*abs((x - shift1 + self.Num_Bin)/width1)**power1) |
|
691 | model1d = amplitude1*numpy.exp(-0.5*abs((x - shift1 + self.Num_Bin)/width1)**power1) | |
692 | return model0 + model0u + model0d + model1 + model1u + model1d + noise |
|
692 | return model0 + model0u + model0d + model1 + model1u + model1d + noise | |
693 |
|
693 | |||
694 | def misfit1(self,state,y_data,x,num_intg): # This function compares how close real data is with the model data, the close it is, the better it is. |
|
694 | def misfit1(self,state,y_data,x,num_intg): # This function compares how close real data is with the model data, the close it is, the better it is. | |
695 |
|
695 | |||
696 | return num_intg*sum((numpy.log(y_data)-numpy.log(self.y_model1(x,state)))**2)#/(64-5.) # /(64-5.) can be commented |
|
696 | return num_intg*sum((numpy.log(y_data)-numpy.log(self.y_model1(x,state)))**2)#/(64-5.) # /(64-5.) can be commented | |
697 |
|
697 | |||
698 | def misfit2(self,state,y_data,x,num_intg): |
|
698 | def misfit2(self,state,y_data,x,num_intg): | |
699 | return num_intg*sum((numpy.log(y_data)-numpy.log(self.y_model2(x,state)))**2)#/(64-9.) |
|
699 | return num_intg*sum((numpy.log(y_data)-numpy.log(self.y_model2(x,state)))**2)#/(64-9.) | |
700 |
|
700 | |||
701 |
|
701 | |||
702 |
|
702 | |||
703 | class PrecipitationProc(Operation): |
|
703 | class PrecipitationProc(Operation): | |
704 |
|
704 | |||
705 | ''' |
|
705 | ''' | |
706 | Operator that estimates Reflectivity factor (Z), and estimates rainfall Rate (R) |
|
706 | Operator that estimates Reflectivity factor (Z), and estimates rainfall Rate (R) | |
707 |
|
707 | |||
708 | Input: |
|
708 | Input: | |
709 | self.dataOut.data_pre : SelfSpectra |
|
709 | self.dataOut.data_pre : SelfSpectra | |
710 |
|
710 | |||
711 | Output: |
|
711 | Output: | |
712 |
|
712 | |||
713 | self.dataOut.data_output : Reflectivity factor, rainfall Rate |
|
713 | self.dataOut.data_output : Reflectivity factor, rainfall Rate | |
714 |
|
714 | |||
715 |
|
715 | |||
716 | Parameters affected: |
|
716 | Parameters affected: | |
717 | ''' |
|
717 | ''' | |
718 |
|
718 | |||
719 | def __init__(self): |
|
719 | def __init__(self): | |
720 | Operation.__init__(self) |
|
720 | Operation.__init__(self) | |
721 | self.i=0 |
|
721 | self.i=0 | |
722 |
|
722 | |||
723 | def run(self, dataOut, radar=None, Pt=5000, Gt=295.1209, Gr=70.7945, Lambda=0.6741, aL=2.5118, |
|
723 | def run(self, dataOut, radar=None, Pt=5000, Gt=295.1209, Gr=70.7945, Lambda=0.6741, aL=2.5118, | |
724 | tauW=4e-06, ThetaT=0.1656317, ThetaR=0.36774087, Km2 = 0.93, Altitude=3350,SNRdBlimit=-30): |
|
724 | tauW=4e-06, ThetaT=0.1656317, ThetaR=0.36774087, Km2 = 0.93, Altitude=3350,SNRdBlimit=-30): | |
725 |
|
725 | |||
726 | # print ('Entering PrecepitationProc ... ') |
|
726 | # print ('Entering PrecepitationProc ... ') | |
727 |
|
727 | |||
728 | if radar == "MIRA35C" : |
|
728 | if radar == "MIRA35C" : | |
729 |
|
729 | |||
730 | self.spc = dataOut.data_pre[0].copy() |
|
730 | self.spc = dataOut.data_pre[0].copy() | |
731 | self.Num_Hei = self.spc.shape[2] |
|
731 | self.Num_Hei = self.spc.shape[2] | |
732 | self.Num_Bin = self.spc.shape[1] |
|
732 | self.Num_Bin = self.spc.shape[1] | |
733 | self.Num_Chn = self.spc.shape[0] |
|
733 | self.Num_Chn = self.spc.shape[0] | |
734 | Ze = self.dBZeMODE2(dataOut) |
|
734 | Ze = self.dBZeMODE2(dataOut) | |
735 |
|
735 | |||
736 | else: |
|
736 | else: | |
737 |
|
737 | |||
738 | self.spc = dataOut.data_pre[0].copy() |
|
738 | self.spc = dataOut.data_pre[0].copy() | |
739 |
|
739 | |||
740 | #NOTA SE DEBE REMOVER EL RANGO DEL PULSO TX |
|
740 | #NOTA SE DEBE REMOVER EL RANGO DEL PULSO TX | |
741 | self.spc[:,:,0:7]= numpy.NaN |
|
741 | self.spc[:,:,0:7]= numpy.NaN | |
742 |
|
742 | |||
743 | self.Num_Hei = self.spc.shape[2] |
|
743 | self.Num_Hei = self.spc.shape[2] | |
744 | self.Num_Bin = self.spc.shape[1] |
|
744 | self.Num_Bin = self.spc.shape[1] | |
745 | self.Num_Chn = self.spc.shape[0] |
|
745 | self.Num_Chn = self.spc.shape[0] | |
746 |
|
746 | |||
747 | VelRange = dataOut.spc_range[2] |
|
747 | VelRange = dataOut.spc_range[2] | |
748 |
|
748 | |||
749 | ''' Se obtiene la constante del RADAR ''' |
|
749 | ''' Se obtiene la constante del RADAR ''' | |
750 |
|
750 | |||
751 | self.Pt = Pt |
|
751 | self.Pt = Pt | |
752 | self.Gt = Gt |
|
752 | self.Gt = Gt | |
753 | self.Gr = Gr |
|
753 | self.Gr = Gr | |
754 | self.Lambda = Lambda |
|
754 | self.Lambda = Lambda | |
755 | self.aL = aL |
|
755 | self.aL = aL | |
756 | self.tauW = tauW |
|
756 | self.tauW = tauW | |
757 | self.ThetaT = ThetaT |
|
757 | self.ThetaT = ThetaT | |
758 | self.ThetaR = ThetaR |
|
758 | self.ThetaR = ThetaR | |
759 | self.GSys = 10**(36.63/10) # Ganancia de los LNA 36.63 dB |
|
759 | self.GSys = 10**(36.63/10) # Ganancia de los LNA 36.63 dB | |
760 | self.lt = 10**(1.67/10) # Perdida en cables Tx 1.67 dB |
|
760 | self.lt = 10**(1.67/10) # Perdida en cables Tx 1.67 dB | |
761 | self.lr = 10**(5.73/10) # Perdida en cables Rx 5.73 dB |
|
761 | self.lr = 10**(5.73/10) # Perdida en cables Rx 5.73 dB | |
762 |
|
762 | |||
763 | Numerator = ( (4*numpy.pi)**3 * aL**2 * 16 * numpy.log(2) ) |
|
763 | Numerator = ( (4*numpy.pi)**3 * aL**2 * 16 * numpy.log(2) ) | |
764 | Denominator = ( Pt * Gt * Gr * Lambda**2 * SPEED_OF_LIGHT * tauW * numpy.pi * ThetaT * ThetaR) |
|
764 | Denominator = ( Pt * Gt * Gr * Lambda**2 * SPEED_OF_LIGHT * tauW * numpy.pi * ThetaT * ThetaR) | |
765 | RadarConstant = 10e-26 * Numerator / Denominator # |
|
765 | RadarConstant = 10e-26 * Numerator / Denominator # | |
766 | ExpConstant = 10**(40/10) #Constante Experimental |
|
766 | ExpConstant = 10**(40/10) #Constante Experimental | |
767 |
|
767 | |||
768 | SignalPower = numpy.zeros([self.Num_Chn,self.Num_Bin,self.Num_Hei]) |
|
768 | SignalPower = numpy.zeros([self.Num_Chn,self.Num_Bin,self.Num_Hei]) | |
769 | for i in range(self.Num_Chn): |
|
769 | for i in range(self.Num_Chn): | |
770 | SignalPower[i,:,:] = self.spc[i,:,:] - dataOut.noise[i] |
|
770 | SignalPower[i,:,:] = self.spc[i,:,:] - dataOut.noise[i] | |
771 | SignalPower[numpy.where(SignalPower < 0)] = 1e-20 |
|
771 | SignalPower[numpy.where(SignalPower < 0)] = 1e-20 | |
772 |
|
772 | |||
773 | SPCmean = numpy.mean(SignalPower, 0) |
|
773 | SPCmean = numpy.mean(SignalPower, 0) | |
774 | Pr = SPCmean[:,:]/dataOut.normFactor |
|
774 | Pr = SPCmean[:,:]/dataOut.normFactor | |
775 |
|
775 | |||
776 | # Declaring auxiliary variables |
|
776 | # Declaring auxiliary variables | |
777 | Range = dataOut.heightList*1000. #Range in m |
|
777 | Range = dataOut.heightList*1000. #Range in m | |
778 | # replicate the heightlist to obtain a matrix [Num_Bin,Num_Hei] |
|
778 | # replicate the heightlist to obtain a matrix [Num_Bin,Num_Hei] | |
779 | rMtrx = numpy.transpose(numpy.transpose([dataOut.heightList*1000.] * self.Num_Bin)) |
|
779 | rMtrx = numpy.transpose(numpy.transpose([dataOut.heightList*1000.] * self.Num_Bin)) | |
780 | zMtrx = rMtrx+Altitude |
|
780 | zMtrx = rMtrx+Altitude | |
781 | # replicate the VelRange to obtain a matrix [Num_Bin,Num_Hei] |
|
781 | # replicate the VelRange to obtain a matrix [Num_Bin,Num_Hei] | |
782 | VelMtrx = numpy.transpose(numpy.tile(VelRange[:-1], (self.Num_Hei,1))) |
|
782 | VelMtrx = numpy.transpose(numpy.tile(VelRange[:-1], (self.Num_Hei,1))) | |
783 |
|
783 | |||
784 | # height dependence to air density Foote and Du Toit (1969) |
|
784 | # height dependence to air density Foote and Du Toit (1969) | |
785 | delv_z = 1 + 3.68e-5 * zMtrx + 1.71e-9 * zMtrx**2 |
|
785 | delv_z = 1 + 3.68e-5 * zMtrx + 1.71e-9 * zMtrx**2 | |
786 | VMtrx = VelMtrx / delv_z #Normalized velocity |
|
786 | VMtrx = VelMtrx / delv_z #Normalized velocity | |
787 | VMtrx[numpy.where(VMtrx> 9.6)] = numpy.NaN |
|
787 | VMtrx[numpy.where(VMtrx> 9.6)] = numpy.NaN | |
788 | # Diameter is related to the fall speed of falling drops |
|
788 | # Diameter is related to the fall speed of falling drops | |
789 | D_Vz = -1.667 * numpy.log( 0.9369 - 0.097087 * VMtrx ) # D in [mm] |
|
789 | D_Vz = -1.667 * numpy.log( 0.9369 - 0.097087 * VMtrx ) # D in [mm] | |
790 | # Only valid for D>= 0.16 mm |
|
790 | # Only valid for D>= 0.16 mm | |
791 | D_Vz[numpy.where(D_Vz < 0.16)] = numpy.NaN |
|
791 | D_Vz[numpy.where(D_Vz < 0.16)] = numpy.NaN | |
792 |
|
792 | |||
793 | #Calculate Radar Reflectivity ETAn |
|
793 | #Calculate Radar Reflectivity ETAn | |
794 | ETAn = (RadarConstant *ExpConstant) * Pr * rMtrx**2 #Reflectivity (ETA) |
|
794 | ETAn = (RadarConstant *ExpConstant) * Pr * rMtrx**2 #Reflectivity (ETA) | |
795 | ETAd = ETAn * 6.18 * exp( -0.6 * D_Vz ) * delv_z |
|
795 | ETAd = ETAn * 6.18 * exp( -0.6 * D_Vz ) * delv_z | |
796 | # Radar Cross Section |
|
796 | # Radar Cross Section | |
797 | sigmaD = Km2 * (D_Vz * 1e-3 )**6 * numpy.pi**5 / Lambda**4 |
|
797 | sigmaD = Km2 * (D_Vz * 1e-3 )**6 * numpy.pi**5 / Lambda**4 | |
798 | # Drop Size Distribution |
|
798 | # Drop Size Distribution | |
799 | DSD = ETAn / sigmaD |
|
799 | DSD = ETAn / sigmaD | |
800 | # Equivalente Reflectivy |
|
800 | # Equivalente Reflectivy | |
801 | Ze_eqn = numpy.nansum( DSD * D_Vz**6 ,axis=0) |
|
801 | Ze_eqn = numpy.nansum( DSD * D_Vz**6 ,axis=0) | |
802 | Ze_org = numpy.nansum(ETAn * Lambda**4, axis=0) / (1e-18*numpy.pi**5 * Km2) # [mm^6 /m^3] |
|
802 | Ze_org = numpy.nansum(ETAn * Lambda**4, axis=0) / (1e-18*numpy.pi**5 * Km2) # [mm^6 /m^3] | |
803 | # RainFall Rate |
|
803 | # RainFall Rate | |
804 | RR = 0.0006*numpy.pi * numpy.nansum( D_Vz**3 * DSD * VelMtrx ,0) #mm/hr |
|
804 | RR = 0.0006*numpy.pi * numpy.nansum( D_Vz**3 * DSD * VelMtrx ,0) #mm/hr | |
805 |
|
805 | |||
806 | # Censoring the data |
|
806 | # Censoring the data | |
807 | # Removing data with SNRth < 0dB se debe considerar el SNR por canal |
|
807 | # Removing data with SNRth < 0dB se debe considerar el SNR por canal | |
808 | SNRth = 10**(SNRdBlimit/10) #-30dB |
|
808 | SNRth = 10**(SNRdBlimit/10) #-30dB | |
809 | novalid = numpy.where((dataOut.data_snr[0,:] <SNRth) | (dataOut.data_snr[1,:] <SNRth) | (dataOut.data_snr[2,:] <SNRth)) # AND condition. Maybe OR condition better |
|
809 | novalid = numpy.where((dataOut.data_snr[0,:] <SNRth) | (dataOut.data_snr[1,:] <SNRth) | (dataOut.data_snr[2,:] <SNRth)) # AND condition. Maybe OR condition better | |
810 | W = numpy.nanmean(dataOut.data_dop,0) |
|
810 | W = numpy.nanmean(dataOut.data_dop,0) | |
811 | W[novalid] = numpy.NaN |
|
811 | W[novalid] = numpy.NaN | |
812 | Ze_org[novalid] = numpy.NaN |
|
812 | Ze_org[novalid] = numpy.NaN | |
813 | RR[novalid] = numpy.NaN |
|
813 | RR[novalid] = numpy.NaN | |
814 |
|
814 | |||
815 | dataOut.data_output = RR[8] |
|
815 | dataOut.data_output = RR[8] | |
816 | dataOut.data_param = numpy.ones([3,self.Num_Hei]) |
|
816 | dataOut.data_param = numpy.ones([3,self.Num_Hei]) | |
817 | dataOut.channelList = [0,1,2] |
|
817 | dataOut.channelList = [0,1,2] | |
818 |
|
818 | |||
819 | dataOut.data_param[0]=10*numpy.log10(Ze_org) |
|
819 | dataOut.data_param[0]=10*numpy.log10(Ze_org) | |
820 | dataOut.data_param[1]=-W |
|
820 | dataOut.data_param[1]=-W | |
821 | dataOut.data_param[2]=RR |
|
821 | dataOut.data_param[2]=RR | |
822 |
|
822 | |||
823 | # print ('Leaving PrecepitationProc ... ') |
|
823 | # print ('Leaving PrecepitationProc ... ') | |
824 | return dataOut |
|
824 | return dataOut | |
825 |
|
825 | |||
826 | def dBZeMODE2(self, dataOut): # Processing for MIRA35C |
|
826 | def dBZeMODE2(self, dataOut): # Processing for MIRA35C | |
827 |
|
827 | |||
828 | NPW = dataOut.NPW |
|
828 | NPW = dataOut.NPW | |
829 | COFA = dataOut.COFA |
|
829 | COFA = dataOut.COFA | |
830 |
|
830 | |||
831 | SNR = numpy.array([self.spc[0,:,:] / NPW[0]]) #, self.spc[1,:,:] / NPW[1]]) |
|
831 | SNR = numpy.array([self.spc[0,:,:] / NPW[0]]) #, self.spc[1,:,:] / NPW[1]]) | |
832 | RadarConst = dataOut.RadarConst |
|
832 | RadarConst = dataOut.RadarConst | |
833 | #frequency = 34.85*10**9 |
|
833 | #frequency = 34.85*10**9 | |
834 |
|
834 | |||
835 | ETA = numpy.zeros(([self.Num_Chn ,self.Num_Hei])) |
|
835 | ETA = numpy.zeros(([self.Num_Chn ,self.Num_Hei])) | |
836 | data_output = numpy.ones([self.Num_Chn , self.Num_Hei])*numpy.NaN |
|
836 | data_output = numpy.ones([self.Num_Chn , self.Num_Hei])*numpy.NaN | |
837 |
|
837 | |||
838 | ETA = numpy.sum(SNR,1) |
|
838 | ETA = numpy.sum(SNR,1) | |
839 |
|
839 | |||
840 | ETA = numpy.where(ETA != 0. , ETA, numpy.NaN) |
|
840 | ETA = numpy.where(ETA != 0. , ETA, numpy.NaN) | |
841 |
|
841 | |||
842 | Ze = numpy.ones([self.Num_Chn, self.Num_Hei] ) |
|
842 | Ze = numpy.ones([self.Num_Chn, self.Num_Hei] ) | |
843 |
|
843 | |||
844 | for r in range(self.Num_Hei): |
|
844 | for r in range(self.Num_Hei): | |
845 |
|
845 | |||
846 | Ze[0,r] = ( ETA[0,r] ) * COFA[0,r][0] * RadarConst * ((r/5000.)**2) |
|
846 | Ze[0,r] = ( ETA[0,r] ) * COFA[0,r][0] * RadarConst * ((r/5000.)**2) | |
847 | #Ze[1,r] = ( ETA[1,r] ) * COFA[1,r][0] * RadarConst * ((r/5000.)**2) |
|
847 | #Ze[1,r] = ( ETA[1,r] ) * COFA[1,r][0] * RadarConst * ((r/5000.)**2) | |
848 |
|
848 | |||
849 | return Ze |
|
849 | return Ze | |
850 |
|
850 | |||
851 | # def GetRadarConstant(self): |
|
851 | # def GetRadarConstant(self): | |
852 | # |
|
852 | # | |
853 | # """ |
|
853 | # """ | |
854 | # Constants: |
|
854 | # Constants: | |
855 | # |
|
855 | # | |
856 | # Pt: Transmission Power dB 5kW 5000 |
|
856 | # Pt: Transmission Power dB 5kW 5000 | |
857 | # Gt: Transmission Gain dB 24.7 dB 295.1209 |
|
857 | # Gt: Transmission Gain dB 24.7 dB 295.1209 | |
858 | # Gr: Reception Gain dB 18.5 dB 70.7945 |
|
858 | # Gr: Reception Gain dB 18.5 dB 70.7945 | |
859 | # Lambda: Wavelenght m 0.6741 m 0.6741 |
|
859 | # Lambda: Wavelenght m 0.6741 m 0.6741 | |
860 | # aL: Attenuation loses dB 4dB 2.5118 |
|
860 | # aL: Attenuation loses dB 4dB 2.5118 | |
861 | # tauW: Width of transmission pulse s 4us 4e-6 |
|
861 | # tauW: Width of transmission pulse s 4us 4e-6 | |
862 | # ThetaT: Transmission antenna bean angle rad 0.1656317 rad 0.1656317 |
|
862 | # ThetaT: Transmission antenna bean angle rad 0.1656317 rad 0.1656317 | |
863 | # ThetaR: Reception antenna beam angle rad 0.36774087 rad 0.36774087 |
|
863 | # ThetaR: Reception antenna beam angle rad 0.36774087 rad 0.36774087 | |
864 | # |
|
864 | # | |
865 | # """ |
|
865 | # """ | |
866 | # |
|
866 | # | |
867 | # Numerator = ( (4*numpy.pi)**3 * aL**2 * 16 * numpy.log(2) ) |
|
867 | # Numerator = ( (4*numpy.pi)**3 * aL**2 * 16 * numpy.log(2) ) | |
868 | # Denominator = ( Pt * Gt * Gr * Lambda**2 * SPEED_OF_LIGHT * TauW * numpy.pi * ThetaT * TheraR) |
|
868 | # Denominator = ( Pt * Gt * Gr * Lambda**2 * SPEED_OF_LIGHT * TauW * numpy.pi * ThetaT * TheraR) | |
869 | # RadarConstant = Numerator / Denominator |
|
869 | # RadarConstant = Numerator / Denominator | |
870 | # |
|
870 | # | |
871 | # return RadarConstant |
|
871 | # return RadarConstant | |
872 |
|
872 | |||
873 |
|
873 | |||
874 |
|
874 | |||
875 | class FullSpectralAnalysis(Operation): |
|
875 | class FullSpectralAnalysis(Operation): | |
876 |
|
876 | |||
877 | """ |
|
877 | """ | |
878 | Function that implements Full Spectral Analysis technique. |
|
878 | Function that implements Full Spectral Analysis technique. | |
879 |
|
879 | |||
880 | Input: |
|
880 | Input: | |
881 | self.dataOut.data_pre : SelfSpectra and CrossSpectra data |
|
881 | self.dataOut.data_pre : SelfSpectra and CrossSpectra data | |
882 | self.dataOut.groupList : Pairlist of channels |
|
882 | self.dataOut.groupList : Pairlist of channels | |
883 | self.dataOut.ChanDist : Physical distance between receivers |
|
883 | self.dataOut.ChanDist : Physical distance between receivers | |
884 |
|
884 | |||
885 |
|
885 | |||
886 | Output: |
|
886 | Output: | |
887 |
|
887 | |||
888 | self.dataOut.data_output : Zonal wind, Meridional wind, and Vertical wind |
|
888 | self.dataOut.data_output : Zonal wind, Meridional wind, and Vertical wind | |
889 |
|
889 | |||
890 |
|
890 | |||
891 | Parameters affected: Winds, height range, SNR |
|
891 | Parameters affected: Winds, height range, SNR | |
892 |
|
892 | |||
893 | """ |
|
893 | """ | |
894 | def run(self, dataOut, Xi01=None, Xi02=None, Xi12=None, Eta01=None, Eta02=None, Eta12=None, SNRdBlimit=-30, |
|
894 | def run(self, dataOut, Xi01=None, Xi02=None, Xi12=None, Eta01=None, Eta02=None, Eta12=None, SNRdBlimit=-30, | |
895 | minheight=None, maxheight=None, NegativeLimit=None, PositiveLimit=None): |
|
895 | minheight=None, maxheight=None, NegativeLimit=None, PositiveLimit=None): | |
896 |
|
896 | |||
897 | spc = dataOut.data_pre[0].copy() |
|
897 | spc = dataOut.data_pre[0].copy() | |
898 | cspc = dataOut.data_pre[1] |
|
898 | cspc = dataOut.data_pre[1] | |
899 | nHeights = spc.shape[2] |
|
899 | nHeights = spc.shape[2] | |
900 |
|
900 | |||
901 | # first_height = 0.75 #km (ref: data header 20170822) |
|
901 | # first_height = 0.75 #km (ref: data header 20170822) | |
902 | # resolution_height = 0.075 #km |
|
902 | # resolution_height = 0.075 #km | |
903 | ''' |
|
903 | ''' | |
904 | finding height range. check this when radar parameters are changed! |
|
904 | finding height range. check this when radar parameters are changed! | |
905 | ''' |
|
905 | ''' | |
906 | if maxheight is not None: |
|
906 | if maxheight is not None: | |
907 | # range_max = math.ceil((maxheight - first_height) / resolution_height) # theoretical |
|
907 | # range_max = math.ceil((maxheight - first_height) / resolution_height) # theoretical | |
908 | range_max = math.ceil(13.26 * maxheight - 3) # empirical, works better |
|
908 | range_max = math.ceil(13.26 * maxheight - 3) # empirical, works better | |
909 | else: |
|
909 | else: | |
910 | range_max = nHeights |
|
910 | range_max = nHeights | |
911 | if minheight is not None: |
|
911 | if minheight is not None: | |
912 | # range_min = int((minheight - first_height) / resolution_height) # theoretical |
|
912 | # range_min = int((minheight - first_height) / resolution_height) # theoretical | |
913 | range_min = int(13.26 * minheight - 5) # empirical, works better |
|
913 | range_min = int(13.26 * minheight - 5) # empirical, works better | |
914 | if range_min < 0: |
|
914 | if range_min < 0: | |
915 | range_min = 0 |
|
915 | range_min = 0 | |
916 | else: |
|
916 | else: | |
917 | range_min = 0 |
|
917 | range_min = 0 | |
918 |
|
918 | |||
919 | pairsList = dataOut.groupList |
|
919 | pairsList = dataOut.groupList | |
920 | if dataOut.ChanDist is not None : |
|
920 | if dataOut.ChanDist is not None : | |
921 | ChanDist = dataOut.ChanDist |
|
921 | ChanDist = dataOut.ChanDist | |
922 | else: |
|
922 | else: | |
923 | ChanDist = numpy.array([[Xi01, Eta01],[Xi02,Eta02],[Xi12,Eta12]]) |
|
923 | ChanDist = numpy.array([[Xi01, Eta01],[Xi02,Eta02],[Xi12,Eta12]]) | |
924 |
|
924 | |||
925 | # 4 variables: zonal, meridional, vertical, and average SNR |
|
925 | # 4 variables: zonal, meridional, vertical, and average SNR | |
926 | data_param = numpy.zeros([4,nHeights]) * numpy.NaN |
|
926 | data_param = numpy.zeros([4,nHeights]) * numpy.NaN | |
927 | velocityX = numpy.zeros([nHeights]) * numpy.NaN |
|
927 | velocityX = numpy.zeros([nHeights]) * numpy.NaN | |
928 | velocityY = numpy.zeros([nHeights]) * numpy.NaN |
|
928 | velocityY = numpy.zeros([nHeights]) * numpy.NaN | |
929 | velocityZ = numpy.zeros([nHeights]) * numpy.NaN |
|
929 | velocityZ = numpy.zeros([nHeights]) * numpy.NaN | |
930 |
|
930 | |||
931 | dbSNR = 10*numpy.log10(numpy.average(dataOut.data_snr,0)) |
|
931 | dbSNR = 10*numpy.log10(numpy.average(dataOut.data_snr,0)) | |
932 |
|
932 | |||
933 | '''***********************************************WIND ESTIMATION**************************************''' |
|
933 | '''***********************************************WIND ESTIMATION**************************************''' | |
934 | for Height in range(nHeights): |
|
934 | for Height in range(nHeights): | |
935 |
|
935 | |||
936 | if Height >= range_min and Height < range_max: |
|
936 | if Height >= range_min and Height < range_max: | |
937 | # error_code will be useful in future analysis |
|
937 | # error_code will be useful in future analysis | |
938 | [Vzon,Vmer,Vver, error_code] = self.WindEstimation(spc[:,:,Height], cspc[:,:,Height], pairsList, |
|
938 | [Vzon,Vmer,Vver, error_code] = self.WindEstimation(spc[:,:,Height], cspc[:,:,Height], pairsList, | |
939 | ChanDist, Height, dataOut.noise, dataOut.spc_range, dbSNR[Height], SNRdBlimit, NegativeLimit, PositiveLimit,dataOut.frequency) |
|
939 | ChanDist, Height, dataOut.noise, dataOut.spc_range, dbSNR[Height], SNRdBlimit, NegativeLimit, PositiveLimit,dataOut.frequency) | |
940 |
|
940 | |||
941 | if abs(Vzon) < 100. and abs(Vmer) < 100.: |
|
941 | if abs(Vzon) < 100. and abs(Vmer) < 100.: | |
942 | velocityX[Height] = Vzon |
|
942 | velocityX[Height] = Vzon | |
943 | velocityY[Height] = -Vmer |
|
943 | velocityY[Height] = -Vmer | |
944 | velocityZ[Height] = Vver |
|
944 | velocityZ[Height] = Vver | |
945 |
|
945 | |||
946 | # Censoring data with SNR threshold |
|
946 | # Censoring data with SNR threshold | |
947 | dbSNR [dbSNR < SNRdBlimit] = numpy.NaN |
|
947 | dbSNR [dbSNR < SNRdBlimit] = numpy.NaN | |
948 |
|
948 | |||
949 | data_param[0] = velocityX |
|
949 | data_param[0] = velocityX | |
950 | data_param[1] = velocityY |
|
950 | data_param[1] = velocityY | |
951 | data_param[2] = velocityZ |
|
951 | data_param[2] = velocityZ | |
952 | data_param[3] = dbSNR |
|
952 | data_param[3] = dbSNR | |
953 | dataOut.data_param = data_param |
|
953 | dataOut.data_param = data_param | |
954 | return dataOut |
|
954 | return dataOut | |
955 |
|
955 | |||
956 | def moving_average(self,x, N=2): |
|
956 | def moving_average(self,x, N=2): | |
957 | """ convolution for smoothenig data. note that last N-1 values are convolution with zeroes """ |
|
957 | """ convolution for smoothenig data. note that last N-1 values are convolution with zeroes """ | |
958 | return numpy.convolve(x, numpy.ones((N,))/N)[(N-1):] |
|
958 | return numpy.convolve(x, numpy.ones((N,))/N)[(N-1):] | |
959 |
|
959 | |||
960 | def gaus(self,xSamples,Amp,Mu,Sigma): |
|
960 | def gaus(self,xSamples,Amp,Mu,Sigma): | |
961 | return Amp * numpy.exp(-0.5*((xSamples - Mu)/Sigma)**2) |
|
961 | return Amp * numpy.exp(-0.5*((xSamples - Mu)/Sigma)**2) | |
962 |
|
962 | |||
963 | def Moments(self, ySamples, xSamples): |
|
963 | def Moments(self, ySamples, xSamples): | |
964 | Power = numpy.nanmean(ySamples) # Power, 0th Moment |
|
964 | Power = numpy.nanmean(ySamples) # Power, 0th Moment | |
965 | yNorm = ySamples / numpy.nansum(ySamples) |
|
965 | yNorm = ySamples / numpy.nansum(ySamples) | |
966 | RadVel = numpy.nansum(xSamples * yNorm) # Radial Velocity, 1st Moment |
|
966 | RadVel = numpy.nansum(xSamples * yNorm) # Radial Velocity, 1st Moment | |
967 | Sigma2 = numpy.nansum(yNorm * (xSamples - RadVel)**2) # Spectral Width, 2nd Moment |
|
967 | Sigma2 = numpy.nansum(yNorm * (xSamples - RadVel)**2) # Spectral Width, 2nd Moment | |
968 | StdDev = numpy.sqrt(numpy.abs(Sigma2)) # Desv. Estandar, Ancho espectral |
|
968 | StdDev = numpy.sqrt(numpy.abs(Sigma2)) # Desv. Estandar, Ancho espectral | |
969 | return numpy.array([Power,RadVel,StdDev]) |
|
969 | return numpy.array([Power,RadVel,StdDev]) | |
970 |
|
970 | |||
971 | def StopWindEstimation(self, error_code): |
|
971 | def StopWindEstimation(self, error_code): | |
972 | Vzon = numpy.NaN |
|
972 | Vzon = numpy.NaN | |
973 | Vmer = numpy.NaN |
|
973 | Vmer = numpy.NaN | |
974 | Vver = numpy.NaN |
|
974 | Vver = numpy.NaN | |
975 | return Vzon, Vmer, Vver, error_code |
|
975 | return Vzon, Vmer, Vver, error_code | |
976 |
|
976 | |||
977 | def AntiAliasing(self, interval, maxstep): |
|
977 | def AntiAliasing(self, interval, maxstep): | |
978 | """ |
|
978 | """ | |
979 | function to prevent errors from aliased values when computing phaseslope |
|
979 | function to prevent errors from aliased values when computing phaseslope | |
980 | """ |
|
980 | """ | |
981 | antialiased = numpy.zeros(len(interval)) |
|
981 | antialiased = numpy.zeros(len(interval)) | |
982 | copyinterval = interval.copy() |
|
982 | copyinterval = interval.copy() | |
983 |
|
983 | |||
984 | antialiased[0] = copyinterval[0] |
|
984 | antialiased[0] = copyinterval[0] | |
985 |
|
985 | |||
986 | for i in range(1,len(antialiased)): |
|
986 | for i in range(1,len(antialiased)): | |
987 | step = interval[i] - interval[i-1] |
|
987 | step = interval[i] - interval[i-1] | |
988 | if step > maxstep: |
|
988 | if step > maxstep: | |
989 | copyinterval -= 2*numpy.pi |
|
989 | copyinterval -= 2*numpy.pi | |
990 | antialiased[i] = copyinterval[i] |
|
990 | antialiased[i] = copyinterval[i] | |
991 | elif step < maxstep*(-1): |
|
991 | elif step < maxstep*(-1): | |
992 | copyinterval += 2*numpy.pi |
|
992 | copyinterval += 2*numpy.pi | |
993 | antialiased[i] = copyinterval[i] |
|
993 | antialiased[i] = copyinterval[i] | |
994 | else: |
|
994 | else: | |
995 | antialiased[i] = copyinterval[i].copy() |
|
995 | antialiased[i] = copyinterval[i].copy() | |
996 |
|
996 | |||
997 | return antialiased |
|
997 | return antialiased | |
998 |
|
998 | |||
999 | def WindEstimation(self, spc, cspc, pairsList, ChanDist, Height, noise, AbbsisaRange, dbSNR, SNRlimit, NegativeLimit, PositiveLimit, radfreq): |
|
999 | def WindEstimation(self, spc, cspc, pairsList, ChanDist, Height, noise, AbbsisaRange, dbSNR, SNRlimit, NegativeLimit, PositiveLimit, radfreq): | |
1000 | """ |
|
1000 | """ | |
1001 | Function that Calculates Zonal, Meridional and Vertical wind velocities. |
|
1001 | Function that Calculates Zonal, Meridional and Vertical wind velocities. | |
1002 | Initial Version by E. Bocanegra updated by J. Zibell until Nov. 2019. |
|
1002 | Initial Version by E. Bocanegra updated by J. Zibell until Nov. 2019. | |
1003 |
|
1003 | |||
1004 | Input: |
|
1004 | Input: | |
1005 | spc, cspc : self spectra and cross spectra data. In Briggs notation something like S_i*(S_i)_conj, (S_j)_conj respectively. |
|
1005 | spc, cspc : self spectra and cross spectra data. In Briggs notation something like S_i*(S_i)_conj, (S_j)_conj respectively. | |
1006 | pairsList : Pairlist of channels |
|
1006 | pairsList : Pairlist of channels | |
1007 | ChanDist : array of xi_ij and eta_ij |
|
1007 | ChanDist : array of xi_ij and eta_ij | |
1008 | Height : height at which data is processed |
|
1008 | Height : height at which data is processed | |
1009 | noise : noise in [channels] format for specific height |
|
1009 | noise : noise in [channels] format for specific height | |
1010 | Abbsisarange : range of the frequencies or velocities |
|
1010 | Abbsisarange : range of the frequencies or velocities | |
1011 | dbSNR, SNRlimit : signal to noise ratio in db, lower limit |
|
1011 | dbSNR, SNRlimit : signal to noise ratio in db, lower limit | |
1012 |
|
1012 | |||
1013 | Output: |
|
1013 | Output: | |
1014 | Vzon, Vmer, Vver : wind velocities |
|
1014 | Vzon, Vmer, Vver : wind velocities | |
1015 | error_code : int that states where code is terminated |
|
1015 | error_code : int that states where code is terminated | |
1016 |
|
1016 | |||
1017 | 0 : no error detected |
|
1017 | 0 : no error detected | |
1018 | 1 : Gaussian of mean spc exceeds widthlimit |
|
1018 | 1 : Gaussian of mean spc exceeds widthlimit | |
1019 | 2 : no Gaussian of mean spc found |
|
1019 | 2 : no Gaussian of mean spc found | |
1020 | 3 : SNR to low or velocity to high -> prec. e.g. |
|
1020 | 3 : SNR to low or velocity to high -> prec. e.g. | |
1021 | 4 : at least one Gaussian of cspc exceeds widthlimit |
|
1021 | 4 : at least one Gaussian of cspc exceeds widthlimit | |
1022 | 5 : zero out of three cspc Gaussian fits converged |
|
1022 | 5 : zero out of three cspc Gaussian fits converged | |
1023 | 6 : phase slope fit could not be found |
|
1023 | 6 : phase slope fit could not be found | |
1024 | 7 : arrays used to fit phase have different length |
|
1024 | 7 : arrays used to fit phase have different length | |
1025 | 8 : frequency range is either too short (len <= 5) or very long (> 30% of cspc) |
|
1025 | 8 : frequency range is either too short (len <= 5) or very long (> 30% of cspc) | |
1026 |
|
1026 | |||
1027 | """ |
|
1027 | """ | |
1028 |
|
1028 | |||
1029 | error_code = 0 |
|
1029 | error_code = 0 | |
1030 |
|
1030 | |||
1031 | nChan = spc.shape[0] |
|
1031 | nChan = spc.shape[0] | |
1032 | nProf = spc.shape[1] |
|
1032 | nProf = spc.shape[1] | |
1033 | nPair = cspc.shape[0] |
|
1033 | nPair = cspc.shape[0] | |
1034 |
|
1034 | |||
1035 | SPC_Samples = numpy.zeros([nChan, nProf]) # for normalized spc values for one height |
|
1035 | SPC_Samples = numpy.zeros([nChan, nProf]) # for normalized spc values for one height | |
1036 | CSPC_Samples = numpy.zeros([nPair, nProf], dtype=numpy.complex_) # for normalized cspc values |
|
1036 | CSPC_Samples = numpy.zeros([nPair, nProf], dtype=numpy.complex_) # for normalized cspc values | |
1037 | phase = numpy.zeros([nPair, nProf]) # phase between channels |
|
1037 | phase = numpy.zeros([nPair, nProf]) # phase between channels | |
1038 | PhaseSlope = numpy.zeros(nPair) # slope of the phases, channelwise |
|
1038 | PhaseSlope = numpy.zeros(nPair) # slope of the phases, channelwise | |
1039 | PhaseInter = numpy.zeros(nPair) # intercept to the slope of the phases, channelwise |
|
1039 | PhaseInter = numpy.zeros(nPair) # intercept to the slope of the phases, channelwise | |
1040 | xFrec = AbbsisaRange[0][:-1] # frequency range |
|
1040 | xFrec = AbbsisaRange[0][:-1] # frequency range | |
1041 | xVel = AbbsisaRange[2][:-1] # velocity range |
|
1041 | xVel = AbbsisaRange[2][:-1] # velocity range | |
1042 | xSamples = xFrec # the frequency range is taken |
|
1042 | xSamples = xFrec # the frequency range is taken | |
1043 | delta_x = xSamples[1] - xSamples[0] # delta_f or delta_x |
|
1043 | delta_x = xSamples[1] - xSamples[0] # delta_f or delta_x | |
1044 |
|
1044 | |||
1045 | # only consider velocities with in NegativeLimit and PositiveLimit |
|
1045 | # only consider velocities with in NegativeLimit and PositiveLimit | |
1046 | if (NegativeLimit is None): |
|
1046 | if (NegativeLimit is None): | |
1047 | NegativeLimit = numpy.min(xVel) |
|
1047 | NegativeLimit = numpy.min(xVel) | |
1048 | if (PositiveLimit is None): |
|
1048 | if (PositiveLimit is None): | |
1049 | PositiveLimit = numpy.max(xVel) |
|
1049 | PositiveLimit = numpy.max(xVel) | |
1050 | xvalid = numpy.where((xVel > NegativeLimit) & (xVel < PositiveLimit)) |
|
1050 | xvalid = numpy.where((xVel > NegativeLimit) & (xVel < PositiveLimit)) | |
1051 | xSamples_zoom = xSamples[xvalid] |
|
1051 | xSamples_zoom = xSamples[xvalid] | |
1052 |
|
1052 | |||
1053 | '''Getting Eij and Nij''' |
|
1053 | '''Getting Eij and Nij''' | |
1054 | Xi01, Xi02, Xi12 = ChanDist[:,0] |
|
1054 | Xi01, Xi02, Xi12 = ChanDist[:,0] | |
1055 | Eta01, Eta02, Eta12 = ChanDist[:,1] |
|
1055 | Eta01, Eta02, Eta12 = ChanDist[:,1] | |
1056 |
|
1056 | |||
1057 | # spwd limit - updated by D. ScipiΓ³n 30.03.2021 |
|
1057 | # spwd limit - updated by D. ScipiΓ³n 30.03.2021 | |
1058 | widthlimit = 10 |
|
1058 | widthlimit = 10 | |
1059 | '''************************* SPC is normalized ********************************''' |
|
1059 | '''************************* SPC is normalized ********************************''' | |
1060 | spc_norm = spc.copy() |
|
1060 | spc_norm = spc.copy() | |
1061 | # For each channel |
|
1061 | # For each channel | |
1062 | for i in range(nChan): |
|
1062 | for i in range(nChan): | |
1063 | spc_sub = spc_norm[i,:] - noise[i] # only the signal power |
|
1063 | spc_sub = spc_norm[i,:] - noise[i] # only the signal power | |
1064 | SPC_Samples[i] = spc_sub / (numpy.nansum(spc_sub) * delta_x) |
|
1064 | SPC_Samples[i] = spc_sub / (numpy.nansum(spc_sub) * delta_x) | |
1065 |
|
1065 | |||
1066 | '''********************** FITTING MEAN SPC GAUSSIAN **********************''' |
|
1066 | '''********************** FITTING MEAN SPC GAUSSIAN **********************''' | |
1067 |
|
1067 | |||
1068 | """ the gaussian of the mean: first subtract noise, then normalize. this is legal because |
|
1068 | """ the gaussian of the mean: first subtract noise, then normalize. this is legal because | |
1069 | you only fit the curve and don't need the absolute value of height for calculation, |
|
1069 | you only fit the curve and don't need the absolute value of height for calculation, | |
1070 | only for estimation of width. for normalization of cross spectra, you need initial, |
|
1070 | only for estimation of width. for normalization of cross spectra, you need initial, | |
1071 | unnormalized self-spectra With noise. |
|
1071 | unnormalized self-spectra With noise. | |
1072 |
|
1072 | |||
1073 | Technically, you don't even need to normalize the self-spectra, as you only need the |
|
1073 | Technically, you don't even need to normalize the self-spectra, as you only need the | |
1074 | width of the peak. However, it was left this way. Note that the normalization has a flaw: |
|
1074 | width of the peak. However, it was left this way. Note that the normalization has a flaw: | |
1075 | due to subtraction of the noise, some values are below zero. Raw "spc" values should be |
|
1075 | due to subtraction of the noise, some values are below zero. Raw "spc" values should be | |
1076 | >= 0, as it is the modulus squared of the signals (complex * it's conjugate) |
|
1076 | >= 0, as it is the modulus squared of the signals (complex * it's conjugate) | |
1077 | """ |
|
1077 | """ | |
1078 | # initial conditions |
|
1078 | # initial conditions | |
1079 | popt = [1e-10,0,1e-10] |
|
1079 | popt = [1e-10,0,1e-10] | |
1080 | # Spectra average |
|
1080 | # Spectra average | |
1081 | SPCMean = numpy.average(SPC_Samples,0) |
|
1081 | SPCMean = numpy.average(SPC_Samples,0) | |
1082 | # Moments in frequency |
|
1082 | # Moments in frequency | |
1083 | SPCMoments = self.Moments(SPCMean[xvalid], xSamples_zoom) |
|
1083 | SPCMoments = self.Moments(SPCMean[xvalid], xSamples_zoom) | |
1084 |
|
1084 | |||
1085 | # Gauss Fit SPC in frequency domain |
|
1085 | # Gauss Fit SPC in frequency domain | |
1086 | if dbSNR > SNRlimit: # only if SNR > SNRth |
|
1086 | if dbSNR > SNRlimit: # only if SNR > SNRth | |
1087 | try: |
|
1087 | try: | |
1088 | popt,pcov = curve_fit(self.gaus,xSamples_zoom,SPCMean[xvalid],p0=SPCMoments) |
|
1088 | popt,pcov = curve_fit(self.gaus,xSamples_zoom,SPCMean[xvalid],p0=SPCMoments) | |
1089 | if popt[2] <= 0 or popt[2] > widthlimit: # CONDITION |
|
1089 | if popt[2] <= 0 or popt[2] > widthlimit: # CONDITION | |
1090 | return self.StopWindEstimation(error_code = 1) |
|
1090 | return self.StopWindEstimation(error_code = 1) | |
1091 | FitGauss = self.gaus(xSamples_zoom,*popt) |
|
1091 | FitGauss = self.gaus(xSamples_zoom,*popt) | |
1092 | except :#RuntimeError: |
|
1092 | except :#RuntimeError: | |
1093 | return self.StopWindEstimation(error_code = 2) |
|
1093 | return self.StopWindEstimation(error_code = 2) | |
1094 | else: |
|
1094 | else: | |
1095 | return self.StopWindEstimation(error_code = 3) |
|
1095 | return self.StopWindEstimation(error_code = 3) | |
1096 |
|
1096 | |||
1097 | '''***************************** CSPC Normalization ************************* |
|
1097 | '''***************************** CSPC Normalization ************************* | |
1098 | The Spc spectra are used to normalize the crossspectra. Peaks from precipitation |
|
1098 | The Spc spectra are used to normalize the crossspectra. Peaks from precipitation | |
1099 | influence the norm which is not desired. First, a range is identified where the |
|
1099 | influence the norm which is not desired. First, a range is identified where the | |
1100 | wind peak is estimated -> sum_wind is sum of those frequencies. Next, the area |
|
1100 | wind peak is estimated -> sum_wind is sum of those frequencies. Next, the area | |
1101 | around it gets cut off and values replaced by mean determined by the boundary |
|
1101 | around it gets cut off and values replaced by mean determined by the boundary | |
1102 | data -> sum_noise (spc is not normalized here, thats why the noise is important) |
|
1102 | data -> sum_noise (spc is not normalized here, thats why the noise is important) | |
1103 |
|
1103 | |||
1104 | The sums are then added and multiplied by range/datapoints, because you need |
|
1104 | The sums are then added and multiplied by range/datapoints, because you need | |
1105 | an integral and not a sum for normalization. |
|
1105 | an integral and not a sum for normalization. | |
1106 |
|
1106 | |||
1107 | A norm is found according to Briggs 92. |
|
1107 | A norm is found according to Briggs 92. | |
1108 | ''' |
|
1108 | ''' | |
1109 | # for each pair |
|
1109 | # for each pair | |
1110 | for i in range(nPair): |
|
1110 | for i in range(nPair): | |
1111 | cspc_norm = cspc[i,:].copy() |
|
1111 | cspc_norm = cspc[i,:].copy() | |
1112 | chan_index0 = pairsList[i][0] |
|
1112 | chan_index0 = pairsList[i][0] | |
1113 | chan_index1 = pairsList[i][1] |
|
1113 | chan_index1 = pairsList[i][1] | |
1114 | CSPC_Samples[i] = cspc_norm / (numpy.sqrt(numpy.nansum(spc_norm[chan_index0])*numpy.nansum(spc_norm[chan_index1])) * delta_x) |
|
1114 | CSPC_Samples[i] = cspc_norm / (numpy.sqrt(numpy.nansum(spc_norm[chan_index0])*numpy.nansum(spc_norm[chan_index1])) * delta_x) | |
1115 | phase[i] = numpy.arctan2(CSPC_Samples[i].imag, CSPC_Samples[i].real) |
|
1115 | phase[i] = numpy.arctan2(CSPC_Samples[i].imag, CSPC_Samples[i].real) | |
1116 |
|
1116 | |||
1117 | CSPCmoments = numpy.vstack([self.Moments(numpy.abs(CSPC_Samples[0,xvalid]), xSamples_zoom), |
|
1117 | CSPCmoments = numpy.vstack([self.Moments(numpy.abs(CSPC_Samples[0,xvalid]), xSamples_zoom), | |
1118 | self.Moments(numpy.abs(CSPC_Samples[1,xvalid]), xSamples_zoom), |
|
1118 | self.Moments(numpy.abs(CSPC_Samples[1,xvalid]), xSamples_zoom), | |
1119 | self.Moments(numpy.abs(CSPC_Samples[2,xvalid]), xSamples_zoom)]) |
|
1119 | self.Moments(numpy.abs(CSPC_Samples[2,xvalid]), xSamples_zoom)]) | |
1120 |
|
1120 | |||
1121 | popt01, popt02, popt12 = [1e-10,0,1e-10], [1e-10,0,1e-10] ,[1e-10,0,1e-10] |
|
1121 | popt01, popt02, popt12 = [1e-10,0,1e-10], [1e-10,0,1e-10] ,[1e-10,0,1e-10] | |
1122 | FitGauss01, FitGauss02, FitGauss12 = numpy.zeros(len(xSamples)), numpy.zeros(len(xSamples)), numpy.zeros(len(xSamples)) |
|
1122 | FitGauss01, FitGauss02, FitGauss12 = numpy.zeros(len(xSamples)), numpy.zeros(len(xSamples)), numpy.zeros(len(xSamples)) | |
1123 |
|
1123 | |||
1124 | '''*******************************FIT GAUSS CSPC************************************''' |
|
1124 | '''*******************************FIT GAUSS CSPC************************************''' | |
1125 | try: |
|
1125 | try: | |
1126 | popt01,pcov = curve_fit(self.gaus,xSamples_zoom,numpy.abs(CSPC_Samples[0][xvalid]),p0=CSPCmoments[0]) |
|
1126 | popt01,pcov = curve_fit(self.gaus,xSamples_zoom,numpy.abs(CSPC_Samples[0][xvalid]),p0=CSPCmoments[0]) | |
1127 | if popt01[2] > widthlimit: # CONDITION |
|
1127 | if popt01[2] > widthlimit: # CONDITION | |
1128 | return self.StopWindEstimation(error_code = 4) |
|
1128 | return self.StopWindEstimation(error_code = 4) | |
1129 | popt02,pcov = curve_fit(self.gaus,xSamples_zoom,numpy.abs(CSPC_Samples[1][xvalid]),p0=CSPCmoments[1]) |
|
1129 | popt02,pcov = curve_fit(self.gaus,xSamples_zoom,numpy.abs(CSPC_Samples[1][xvalid]),p0=CSPCmoments[1]) | |
1130 | if popt02[2] > widthlimit: # CONDITION |
|
1130 | if popt02[2] > widthlimit: # CONDITION | |
1131 | return self.StopWindEstimation(error_code = 4) |
|
1131 | return self.StopWindEstimation(error_code = 4) | |
1132 | popt12,pcov = curve_fit(self.gaus,xSamples_zoom,numpy.abs(CSPC_Samples[2][xvalid]),p0=CSPCmoments[2]) |
|
1132 | popt12,pcov = curve_fit(self.gaus,xSamples_zoom,numpy.abs(CSPC_Samples[2][xvalid]),p0=CSPCmoments[2]) | |
1133 | if popt12[2] > widthlimit: # CONDITION |
|
1133 | if popt12[2] > widthlimit: # CONDITION | |
1134 | return self.StopWindEstimation(error_code = 4) |
|
1134 | return self.StopWindEstimation(error_code = 4) | |
1135 |
|
1135 | |||
1136 | FitGauss01 = self.gaus(xSamples_zoom, *popt01) |
|
1136 | FitGauss01 = self.gaus(xSamples_zoom, *popt01) | |
1137 | FitGauss02 = self.gaus(xSamples_zoom, *popt02) |
|
1137 | FitGauss02 = self.gaus(xSamples_zoom, *popt02) | |
1138 | FitGauss12 = self.gaus(xSamples_zoom, *popt12) |
|
1138 | FitGauss12 = self.gaus(xSamples_zoom, *popt12) | |
1139 | except: |
|
1139 | except: | |
1140 | return self.StopWindEstimation(error_code = 5) |
|
1140 | return self.StopWindEstimation(error_code = 5) | |
1141 |
|
1141 | |||
1142 |
|
1142 | |||
1143 | '''************* Getting Fij ***************''' |
|
1143 | '''************* Getting Fij ***************''' | |
1144 | # x-axis point of the gaussian where the center is located from GaussFit of spectra |
|
1144 | # x-axis point of the gaussian where the center is located from GaussFit of spectra | |
1145 | GaussCenter = popt[1] |
|
1145 | GaussCenter = popt[1] | |
1146 | ClosestCenter = xSamples_zoom[numpy.abs(xSamples_zoom-GaussCenter).argmin()] |
|
1146 | ClosestCenter = xSamples_zoom[numpy.abs(xSamples_zoom-GaussCenter).argmin()] | |
1147 | PointGauCenter = numpy.where(xSamples_zoom==ClosestCenter)[0][0] |
|
1147 | PointGauCenter = numpy.where(xSamples_zoom==ClosestCenter)[0][0] | |
1148 |
|
1148 | |||
1149 | # Point where e^-1 is located in the gaussian |
|
1149 | # Point where e^-1 is located in the gaussian | |
1150 | PeMinus1 = numpy.max(FitGauss) * numpy.exp(-1) |
|
1150 | PeMinus1 = numpy.max(FitGauss) * numpy.exp(-1) | |
1151 | FijClosest = FitGauss[numpy.abs(FitGauss-PeMinus1).argmin()] # The closest point to"Peminus1" in "FitGauss" |
|
1151 | FijClosest = FitGauss[numpy.abs(FitGauss-PeMinus1).argmin()] # The closest point to"Peminus1" in "FitGauss" | |
1152 | PointFij = numpy.where(FitGauss==FijClosest)[0][0] |
|
1152 | PointFij = numpy.where(FitGauss==FijClosest)[0][0] | |
1153 | Fij = numpy.abs(xSamples_zoom[PointFij] - xSamples_zoom[PointGauCenter]) |
|
1153 | Fij = numpy.abs(xSamples_zoom[PointFij] - xSamples_zoom[PointGauCenter]) | |
1154 |
|
1154 | |||
1155 | '''********** Taking frequency ranges from mean SPCs **********''' |
|
1155 | '''********** Taking frequency ranges from mean SPCs **********''' | |
1156 | GauWidth = popt[2] * 3/2 # Bandwidth of Gau01 |
|
1156 | GauWidth = popt[2] * 3/2 # Bandwidth of Gau01 | |
1157 | Range = numpy.empty(2) |
|
1157 | Range = numpy.empty(2) | |
1158 | Range[0] = GaussCenter - GauWidth |
|
1158 | Range[0] = GaussCenter - GauWidth | |
1159 | Range[1] = GaussCenter + GauWidth |
|
1159 | Range[1] = GaussCenter + GauWidth | |
1160 | # Point in x-axis where the bandwidth is located (min:max) |
|
1160 | # Point in x-axis where the bandwidth is located (min:max) | |
1161 | ClosRangeMin = xSamples_zoom[numpy.abs(xSamples_zoom-Range[0]).argmin()] |
|
1161 | ClosRangeMin = xSamples_zoom[numpy.abs(xSamples_zoom-Range[0]).argmin()] | |
1162 | ClosRangeMax = xSamples_zoom[numpy.abs(xSamples_zoom-Range[1]).argmin()] |
|
1162 | ClosRangeMax = xSamples_zoom[numpy.abs(xSamples_zoom-Range[1]).argmin()] | |
1163 | PointRangeMin = numpy.where(xSamples_zoom==ClosRangeMin)[0][0] |
|
1163 | PointRangeMin = numpy.where(xSamples_zoom==ClosRangeMin)[0][0] | |
1164 | PointRangeMax = numpy.where(xSamples_zoom==ClosRangeMax)[0][0] |
|
1164 | PointRangeMax = numpy.where(xSamples_zoom==ClosRangeMax)[0][0] | |
1165 | Range = numpy.array([ PointRangeMin, PointRangeMax ]) |
|
1165 | Range = numpy.array([ PointRangeMin, PointRangeMax ]) | |
1166 | FrecRange = xSamples_zoom[ Range[0] : Range[1] ] |
|
1166 | FrecRange = xSamples_zoom[ Range[0] : Range[1] ] | |
1167 |
|
1167 | |||
1168 | '''************************** Getting Phase Slope ***************************''' |
|
1168 | '''************************** Getting Phase Slope ***************************''' | |
1169 | for i in range(nPair): |
|
1169 | for i in range(nPair): | |
1170 | if len(FrecRange) > 5: |
|
1170 | if len(FrecRange) > 5: | |
1171 | PhaseRange = phase[i, xvalid[0][Range[0]:Range[1]]].copy() |
|
1171 | PhaseRange = phase[i, xvalid[0][Range[0]:Range[1]]].copy() | |
1172 | mask = ~numpy.isnan(FrecRange) & ~numpy.isnan(PhaseRange) |
|
1172 | mask = ~numpy.isnan(FrecRange) & ~numpy.isnan(PhaseRange) | |
1173 | if len(FrecRange) == len(PhaseRange): |
|
1173 | if len(FrecRange) == len(PhaseRange): | |
1174 | try: |
|
1174 | try: | |
1175 | slope, intercept, _, _, _ = stats.linregress(FrecRange[mask], self.AntiAliasing(PhaseRange[mask], 4.5)) |
|
1175 | slope, intercept, _, _, _ = stats.linregress(FrecRange[mask], self.AntiAliasing(PhaseRange[mask], 4.5)) | |
1176 | PhaseSlope[i] = slope |
|
1176 | PhaseSlope[i] = slope | |
1177 | PhaseInter[i] = intercept |
|
1177 | PhaseInter[i] = intercept | |
1178 | except: |
|
1178 | except: | |
1179 | return self.StopWindEstimation(error_code = 6) |
|
1179 | return self.StopWindEstimation(error_code = 6) | |
1180 | else: |
|
1180 | else: | |
1181 | return self.StopWindEstimation(error_code = 7) |
|
1181 | return self.StopWindEstimation(error_code = 7) | |
1182 | else: |
|
1182 | else: | |
1183 | return self.StopWindEstimation(error_code = 8) |
|
1183 | return self.StopWindEstimation(error_code = 8) | |
1184 |
|
1184 | |||
1185 | '''*** Constants A-H correspond to the convention as in Briggs and Vincent 1992 ***''' |
|
1185 | '''*** Constants A-H correspond to the convention as in Briggs and Vincent 1992 ***''' | |
1186 |
|
1186 | |||
1187 | '''Getting constant C''' |
|
1187 | '''Getting constant C''' | |
1188 | cC=(Fij*numpy.pi)**2 |
|
1188 | cC=(Fij*numpy.pi)**2 | |
1189 |
|
1189 | |||
1190 | '''****** Getting constants F and G ******''' |
|
1190 | '''****** Getting constants F and G ******''' | |
1191 | MijEijNij = numpy.array([[Xi02,Eta02], [Xi12,Eta12]]) |
|
1191 | MijEijNij = numpy.array([[Xi02,Eta02], [Xi12,Eta12]]) | |
1192 | # MijEijNij = numpy.array([[Xi01,Eta01], [Xi02,Eta02], [Xi12,Eta12]]) |
|
1192 | # MijEijNij = numpy.array([[Xi01,Eta01], [Xi02,Eta02], [Xi12,Eta12]]) | |
1193 | # MijResult0 = (-PhaseSlope[0] * cC) / (2*numpy.pi) |
|
1193 | # MijResult0 = (-PhaseSlope[0] * cC) / (2*numpy.pi) | |
1194 | MijResult1 = (-PhaseSlope[1] * cC) / (2*numpy.pi) |
|
1194 | MijResult1 = (-PhaseSlope[1] * cC) / (2*numpy.pi) | |
1195 | MijResult2 = (-PhaseSlope[2] * cC) / (2*numpy.pi) |
|
1195 | MijResult2 = (-PhaseSlope[2] * cC) / (2*numpy.pi) | |
1196 | # MijResults = numpy.array([MijResult0, MijResult1, MijResult2]) |
|
1196 | # MijResults = numpy.array([MijResult0, MijResult1, MijResult2]) | |
1197 | MijResults = numpy.array([MijResult1, MijResult2]) |
|
1197 | MijResults = numpy.array([MijResult1, MijResult2]) | |
1198 | (cF,cG) = numpy.linalg.solve(MijEijNij, MijResults) |
|
1198 | (cF,cG) = numpy.linalg.solve(MijEijNij, MijResults) | |
1199 |
|
1199 | |||
1200 | '''****** Getting constants A, B and H ******''' |
|
1200 | '''****** Getting constants A, B and H ******''' | |
1201 | W01 = numpy.nanmax( FitGauss01 ) |
|
1201 | W01 = numpy.nanmax( FitGauss01 ) | |
1202 | W02 = numpy.nanmax( FitGauss02 ) |
|
1202 | W02 = numpy.nanmax( FitGauss02 ) | |
1203 | W12 = numpy.nanmax( FitGauss12 ) |
|
1203 | W12 = numpy.nanmax( FitGauss12 ) | |
1204 |
|
1204 | |||
1205 | WijResult01 = ((cF * Xi01 + cG * Eta01)**2)/cC - numpy.log(W01 / numpy.sqrt(numpy.pi / cC)) |
|
1205 | WijResult01 = ((cF * Xi01 + cG * Eta01)**2)/cC - numpy.log(W01 / numpy.sqrt(numpy.pi / cC)) | |
1206 | WijResult02 = ((cF * Xi02 + cG * Eta02)**2)/cC - numpy.log(W02 / numpy.sqrt(numpy.pi / cC)) |
|
1206 | WijResult02 = ((cF * Xi02 + cG * Eta02)**2)/cC - numpy.log(W02 / numpy.sqrt(numpy.pi / cC)) | |
1207 | WijResult12 = ((cF * Xi12 + cG * Eta12)**2)/cC - numpy.log(W12 / numpy.sqrt(numpy.pi / cC)) |
|
1207 | WijResult12 = ((cF * Xi12 + cG * Eta12)**2)/cC - numpy.log(W12 / numpy.sqrt(numpy.pi / cC)) | |
1208 | WijResults = numpy.array([WijResult01, WijResult02, WijResult12]) |
|
1208 | WijResults = numpy.array([WijResult01, WijResult02, WijResult12]) | |
1209 |
|
1209 | |||
1210 | WijEijNij = numpy.array([ [Xi01**2, Eta01**2, 2*Xi01*Eta01] , [Xi02**2, Eta02**2, 2*Xi02*Eta02] , [Xi12**2, Eta12**2, 2*Xi12*Eta12] ]) |
|
1210 | WijEijNij = numpy.array([ [Xi01**2, Eta01**2, 2*Xi01*Eta01] , [Xi02**2, Eta02**2, 2*Xi02*Eta02] , [Xi12**2, Eta12**2, 2*Xi12*Eta12] ]) | |
1211 | (cA,cB,cH) = numpy.linalg.solve(WijEijNij, WijResults) |
|
1211 | (cA,cB,cH) = numpy.linalg.solve(WijEijNij, WijResults) | |
1212 |
|
1212 | |||
1213 | VxVy = numpy.array([[cA,cH],[cH,cB]]) |
|
1213 | VxVy = numpy.array([[cA,cH],[cH,cB]]) | |
1214 | VxVyResults = numpy.array([-cF,-cG]) |
|
1214 | VxVyResults = numpy.array([-cF,-cG]) | |
1215 | (Vmer,Vzon) = numpy.linalg.solve(VxVy, VxVyResults) |
|
1215 | (Vmer,Vzon) = numpy.linalg.solve(VxVy, VxVyResults) | |
1216 | Vver = -SPCMoments[1]*SPEED_OF_LIGHT/(2*radfreq) |
|
1216 | Vver = -SPCMoments[1]*SPEED_OF_LIGHT/(2*radfreq) | |
1217 | error_code = 0 |
|
1217 | error_code = 0 | |
1218 |
|
1218 | |||
1219 | return Vzon, Vmer, Vver, error_code |
|
1219 | return Vzon, Vmer, Vver, error_code | |
1220 |
|
1220 | |||
1221 | class SpectralMoments(Operation): |
|
1221 | class SpectralMoments(Operation): | |
1222 |
|
1222 | |||
1223 | ''' |
|
1223 | ''' | |
1224 | Function SpectralMoments() |
|
1224 | Function SpectralMoments() | |
1225 |
|
1225 | |||
1226 | Calculates moments (power, mean, standard deviation) and SNR of the signal |
|
1226 | Calculates moments (power, mean, standard deviation) and SNR of the signal | |
1227 |
|
1227 | |||
1228 | Type of dataIn: Spectra |
|
1228 | Type of dataIn: Spectra | |
1229 |
|
1229 | |||
1230 | Configuration Parameters: |
|
1230 | Configuration Parameters: | |
1231 |
|
1231 | |||
1232 | dirCosx : Cosine director in X axis |
|
1232 | dirCosx : Cosine director in X axis | |
1233 | dirCosy : Cosine director in Y axis |
|
1233 | dirCosy : Cosine director in Y axis | |
1234 |
|
1234 | |||
1235 | elevation : |
|
1235 | elevation : | |
1236 | azimuth : |
|
1236 | azimuth : | |
1237 |
|
1237 | |||
1238 | Input: |
|
1238 | Input: | |
1239 | channelList : simple channel list to select e.g. [2,3,7] |
|
1239 | channelList : simple channel list to select e.g. [2,3,7] | |
1240 | self.dataOut.data_pre : Spectral data |
|
1240 | self.dataOut.data_pre : Spectral data | |
1241 | self.dataOut.abscissaList : List of frequencies |
|
1241 | self.dataOut.abscissaList : List of frequencies | |
1242 | self.dataOut.noise : Noise level per channel |
|
1242 | self.dataOut.noise : Noise level per channel | |
1243 |
|
1243 | |||
1244 | Affected: |
|
1244 | Affected: | |
1245 | self.dataOut.moments : Parameters per channel |
|
1245 | self.dataOut.moments : Parameters per channel | |
1246 | self.dataOut.data_snr : SNR per channel |
|
1246 | self.dataOut.data_snr : SNR per channel | |
1247 |
|
1247 | |||
1248 | ''' |
|
1248 | ''' | |
1249 |
|
1249 | |||
1250 | def run(self, dataOut): |
|
1250 | def run(self, dataOut): | |
1251 |
|
1251 | |||
1252 | data = dataOut.data_pre[0] |
|
1252 | data = dataOut.data_pre[0] | |
1253 | absc = dataOut.abscissaList[:-1] |
|
1253 | absc = dataOut.abscissaList[:-1] | |
1254 | noise = dataOut.noise |
|
1254 | noise = dataOut.noise | |
1255 | nChannel = data.shape[0] |
|
1255 | nChannel = data.shape[0] | |
1256 | data_param = numpy.zeros((nChannel, 4, data.shape[2])) |
|
1256 | data_param = numpy.zeros((nChannel, 4, data.shape[2])) | |
1257 |
|
1257 | |||
1258 | for ind in range(nChannel): |
|
1258 | for ind in range(nChannel): | |
1259 | data_param[ind,:,:] = self.__calculateMoments( data[ind,:,:] , absc , noise[ind] ) |
|
1259 | data_param[ind,:,:] = self.__calculateMoments( data[ind,:,:] , absc , noise[ind] ) | |
1260 |
|
1260 | |||
1261 | dataOut.moments = data_param[:,1:,:] |
|
1261 | dataOut.moments = data_param[:,1:,:] | |
1262 | dataOut.data_snr = data_param[:,0] |
|
1262 | dataOut.data_snr = data_param[:,0] | |
1263 | dataOut.data_pow = data_param[:,1] |
|
1263 | dataOut.data_pow = data_param[:,1] | |
1264 | dataOut.data_dop = data_param[:,2] |
|
1264 | dataOut.data_dop = data_param[:,2] | |
1265 | dataOut.data_width = data_param[:,3] |
|
1265 | dataOut.data_width = data_param[:,3] | |
1266 | return dataOut |
|
1266 | return dataOut | |
1267 |
|
1267 | |||
1268 | def __calculateMoments(self, oldspec, oldfreq, n0, |
|
1268 | def __calculateMoments(self, oldspec, oldfreq, n0, | |
1269 | nicoh = None, graph = None, smooth = None, type1 = None, fwindow = None, snrth = None, dc = None, aliasing = None, oldfd = None, wwauto = None): |
|
1269 | nicoh = None, graph = None, smooth = None, type1 = None, fwindow = None, snrth = None, dc = None, aliasing = None, oldfd = None, wwauto = None): | |
1270 |
|
1270 | |||
1271 | if (nicoh is None): nicoh = 1 |
|
1271 | if (nicoh is None): nicoh = 1 | |
1272 | if (graph is None): graph = 0 |
|
1272 | if (graph is None): graph = 0 | |
1273 | if (smooth is None): smooth = 0 |
|
1273 | if (smooth is None): smooth = 0 | |
1274 | elif (self.smooth < 3): smooth = 0 |
|
1274 | elif (self.smooth < 3): smooth = 0 | |
1275 |
|
1275 | |||
1276 | if (type1 is None): type1 = 0 |
|
1276 | if (type1 is None): type1 = 0 | |
1277 | if (fwindow is None): fwindow = numpy.zeros(oldfreq.size) + 1 |
|
1277 | if (fwindow is None): fwindow = numpy.zeros(oldfreq.size) + 1 | |
1278 | if (snrth is None): snrth = -3 |
|
1278 | if (snrth is None): snrth = -3 | |
1279 | if (dc is None): dc = 0 |
|
1279 | if (dc is None): dc = 0 | |
1280 | if (aliasing is None): aliasing = 0 |
|
1280 | if (aliasing is None): aliasing = 0 | |
1281 | if (oldfd is None): oldfd = 0 |
|
1281 | if (oldfd is None): oldfd = 0 | |
1282 | if (wwauto is None): wwauto = 0 |
|
1282 | if (wwauto is None): wwauto = 0 | |
1283 |
|
1283 | |||
1284 | if (n0 < 1.e-20): n0 = 1.e-20 |
|
1284 | if (n0 < 1.e-20): n0 = 1.e-20 | |
1285 |
|
1285 | |||
1286 | freq = oldfreq |
|
1286 | freq = oldfreq | |
1287 | vec_power = numpy.zeros(oldspec.shape[1]) |
|
1287 | vec_power = numpy.zeros(oldspec.shape[1]) | |
1288 | vec_fd = numpy.zeros(oldspec.shape[1]) |
|
1288 | vec_fd = numpy.zeros(oldspec.shape[1]) | |
1289 | vec_w = numpy.zeros(oldspec.shape[1]) |
|
1289 | vec_w = numpy.zeros(oldspec.shape[1]) | |
1290 | vec_snr = numpy.zeros(oldspec.shape[1]) |
|
1290 | vec_snr = numpy.zeros(oldspec.shape[1]) | |
1291 |
|
1291 | |||
1292 | # oldspec = numpy.ma.masked_invalid(oldspec) |
|
1292 | # oldspec = numpy.ma.masked_invalid(oldspec) | |
1293 | for ind in range(oldspec.shape[1]): |
|
1293 | for ind in range(oldspec.shape[1]): | |
1294 |
|
1294 | |||
1295 | spec = oldspec[:,ind] |
|
1295 | spec = oldspec[:,ind] | |
1296 | aux = spec*fwindow |
|
1296 | aux = spec*fwindow | |
1297 | max_spec = aux.max() |
|
1297 | max_spec = aux.max() | |
1298 | m = aux.tolist().index(max_spec) |
|
1298 | m = aux.tolist().index(max_spec) | |
1299 |
|
1299 | |||
1300 | # Smooth |
|
1300 | # Smooth | |
1301 | if (smooth == 0): |
|
1301 | if (smooth == 0): | |
1302 | spec2 = spec |
|
1302 | spec2 = spec | |
1303 | else: |
|
1303 | else: | |
1304 | spec2 = scipy.ndimage.filters.uniform_filter1d(spec,size=smooth) |
|
1304 | spec2 = scipy.ndimage.filters.uniform_filter1d(spec,size=smooth) | |
1305 |
|
1305 | |||
1306 | # Moments Estimation |
|
1306 | # Moments Estimation | |
1307 | bb = spec2[numpy.arange(m,spec2.size)] |
|
1307 | bb = spec2[numpy.arange(m,spec2.size)] | |
1308 | bb = (bb<n0).nonzero() |
|
1308 | bb = (bb<n0).nonzero() | |
1309 | bb = bb[0] |
|
1309 | bb = bb[0] | |
1310 |
|
1310 | |||
1311 | ss = spec2[numpy.arange(0,m + 1)] |
|
1311 | ss = spec2[numpy.arange(0,m + 1)] | |
1312 | ss = (ss<n0).nonzero() |
|
1312 | ss = (ss<n0).nonzero() | |
1313 | ss = ss[0] |
|
1313 | ss = ss[0] | |
1314 |
|
1314 | |||
1315 | if (bb.size == 0): |
|
1315 | if (bb.size == 0): | |
1316 | bb0 = spec.size - 1 - m |
|
1316 | bb0 = spec.size - 1 - m | |
1317 | else: |
|
1317 | else: | |
1318 | bb0 = bb[0] - 1 |
|
1318 | bb0 = bb[0] - 1 | |
1319 | if (bb0 < 0): |
|
1319 | if (bb0 < 0): | |
1320 | bb0 = 0 |
|
1320 | bb0 = 0 | |
1321 |
|
1321 | |||
1322 | if (ss.size == 0): |
|
1322 | if (ss.size == 0): | |
1323 | ss1 = 1 |
|
1323 | ss1 = 1 | |
1324 | else: |
|
1324 | else: | |
1325 | ss1 = max(ss) + 1 |
|
1325 | ss1 = max(ss) + 1 | |
1326 |
|
1326 | |||
1327 | if (ss1 > m): |
|
1327 | if (ss1 > m): | |
1328 | ss1 = m |
|
1328 | ss1 = m | |
1329 |
|
1329 | |||
1330 | #valid = numpy.arange(int(m + bb0 - ss1 + 1)) + ss1 |
|
1330 | #valid = numpy.arange(int(m + bb0 - ss1 + 1)) + ss1 | |
1331 | valid = numpy.arange(1,oldspec.shape[0])# valid perfil completo igual pulsepair |
|
1331 | valid = numpy.arange(1,oldspec.shape[0])# valid perfil completo igual pulsepair | |
1332 | signal_power = ((spec2[valid] - n0) * fwindow[valid]).mean() # D. ScipiΓ³n added with correct definition |
|
1332 | signal_power = ((spec2[valid] - n0) * fwindow[valid]).mean() # D. ScipiΓ³n added with correct definition | |
1333 | total_power = (spec2[valid] * fwindow[valid]).mean() # D. ScipiΓ³n added with correct definition |
|
1333 | total_power = (spec2[valid] * fwindow[valid]).mean() # D. ScipiΓ³n added with correct definition | |
1334 | power = ((spec2[valid] - n0) * fwindow[valid]).sum() |
|
1334 | power = ((spec2[valid] - n0) * fwindow[valid]).sum() | |
1335 | fd = ((spec2[valid]- n0)*freq[valid] * fwindow[valid]).sum() / power |
|
1335 | fd = ((spec2[valid]- n0)*freq[valid] * fwindow[valid]).sum() / power | |
1336 | w = numpy.sqrt(((spec2[valid] - n0)*fwindow[valid]*(freq[valid]- fd)**2).sum() / power) |
|
1336 | w = numpy.sqrt(((spec2[valid] - n0)*fwindow[valid]*(freq[valid]- fd)**2).sum() / power) | |
1337 | snr = (spec2.mean()-n0)/n0 |
|
1337 | snr = (spec2.mean()-n0)/n0 | |
1338 | if (snr < 1.e-20) : |
|
1338 | if (snr < 1.e-20) : | |
1339 | snr = 1.e-20 |
|
1339 | snr = 1.e-20 | |
1340 |
|
1340 | |||
1341 | # vec_power[ind] = power #D. ScipiΓ³n replaced with the line below |
|
1341 | # vec_power[ind] = power #D. ScipiΓ³n replaced with the line below | |
1342 | vec_power[ind] = total_power |
|
1342 | vec_power[ind] = total_power | |
1343 | vec_fd[ind] = fd |
|
1343 | vec_fd[ind] = fd | |
1344 | vec_w[ind] = w |
|
1344 | vec_w[ind] = w | |
1345 | vec_snr[ind] = snr |
|
1345 | vec_snr[ind] = snr | |
1346 |
|
1346 | |||
1347 | return numpy.vstack((vec_snr, vec_power, vec_fd, vec_w)) |
|
1347 | return numpy.vstack((vec_snr, vec_power, vec_fd, vec_w)) | |
1348 |
|
1348 | |||
1349 | #------------------ Get SA Parameters -------------------------- |
|
1349 | #------------------ Get SA Parameters -------------------------- | |
1350 |
|
1350 | |||
1351 | def GetSAParameters(self): |
|
1351 | def GetSAParameters(self): | |
1352 | #SA en frecuencia |
|
1352 | #SA en frecuencia | |
1353 | pairslist = self.dataOut.groupList |
|
1353 | pairslist = self.dataOut.groupList | |
1354 | num_pairs = len(pairslist) |
|
1354 | num_pairs = len(pairslist) | |
1355 |
|
1355 | |||
1356 | vel = self.dataOut.abscissaList |
|
1356 | vel = self.dataOut.abscissaList | |
1357 | spectra = self.dataOut.data_pre |
|
1357 | spectra = self.dataOut.data_pre | |
1358 | cspectra = self.dataIn.data_cspc |
|
1358 | cspectra = self.dataIn.data_cspc | |
1359 | delta_v = vel[1] - vel[0] |
|
1359 | delta_v = vel[1] - vel[0] | |
1360 |
|
1360 | |||
1361 | #Calculating the power spectrum |
|
1361 | #Calculating the power spectrum | |
1362 | spc_pow = numpy.sum(spectra, 3)*delta_v |
|
1362 | spc_pow = numpy.sum(spectra, 3)*delta_v | |
1363 | #Normalizing Spectra |
|
1363 | #Normalizing Spectra | |
1364 | norm_spectra = spectra/spc_pow |
|
1364 | norm_spectra = spectra/spc_pow | |
1365 | #Calculating the norm_spectra at peak |
|
1365 | #Calculating the norm_spectra at peak | |
1366 | max_spectra = numpy.max(norm_spectra, 3) |
|
1366 | max_spectra = numpy.max(norm_spectra, 3) | |
1367 |
|
1367 | |||
1368 | #Normalizing Cross Spectra |
|
1368 | #Normalizing Cross Spectra | |
1369 | norm_cspectra = numpy.zeros(cspectra.shape) |
|
1369 | norm_cspectra = numpy.zeros(cspectra.shape) | |
1370 |
|
1370 | |||
1371 | for i in range(num_chan): |
|
1371 | for i in range(num_chan): | |
1372 | norm_cspectra[i,:,:] = cspectra[i,:,:]/numpy.sqrt(spc_pow[pairslist[i][0],:]*spc_pow[pairslist[i][1],:]) |
|
1372 | norm_cspectra[i,:,:] = cspectra[i,:,:]/numpy.sqrt(spc_pow[pairslist[i][0],:]*spc_pow[pairslist[i][1],:]) | |
1373 |
|
1373 | |||
1374 | max_cspectra = numpy.max(norm_cspectra,2) |
|
1374 | max_cspectra = numpy.max(norm_cspectra,2) | |
1375 | max_cspectra_index = numpy.argmax(norm_cspectra, 2) |
|
1375 | max_cspectra_index = numpy.argmax(norm_cspectra, 2) | |
1376 |
|
1376 | |||
1377 | for i in range(num_pairs): |
|
1377 | for i in range(num_pairs): | |
1378 | cspc_par[i,:,:] = __calculateMoments(norm_cspectra) |
|
1378 | cspc_par[i,:,:] = __calculateMoments(norm_cspectra) | |
1379 | #------------------- Get Lags ---------------------------------- |
|
1379 | #------------------- Get Lags ---------------------------------- | |
1380 |
|
1380 | |||
1381 | class SALags(Operation): |
|
1381 | class SALags(Operation): | |
1382 | ''' |
|
1382 | ''' | |
1383 | Function GetMoments() |
|
1383 | Function GetMoments() | |
1384 |
|
1384 | |||
1385 | Input: |
|
1385 | Input: | |
1386 | self.dataOut.data_pre |
|
1386 | self.dataOut.data_pre | |
1387 | self.dataOut.abscissaList |
|
1387 | self.dataOut.abscissaList | |
1388 | self.dataOut.noise |
|
1388 | self.dataOut.noise | |
1389 | self.dataOut.normFactor |
|
1389 | self.dataOut.normFactor | |
1390 | self.dataOut.data_snr |
|
1390 | self.dataOut.data_snr | |
1391 | self.dataOut.groupList |
|
1391 | self.dataOut.groupList | |
1392 | self.dataOut.nChannels |
|
1392 | self.dataOut.nChannels | |
1393 |
|
1393 | |||
1394 | Affected: |
|
1394 | Affected: | |
1395 | self.dataOut.data_param |
|
1395 | self.dataOut.data_param | |
1396 |
|
1396 | |||
1397 | ''' |
|
1397 | ''' | |
1398 | def run(self, dataOut): |
|
1398 | def run(self, dataOut): | |
1399 | data_acf = dataOut.data_pre[0] |
|
1399 | data_acf = dataOut.data_pre[0] | |
1400 | data_ccf = dataOut.data_pre[1] |
|
1400 | data_ccf = dataOut.data_pre[1] | |
1401 | normFactor_acf = dataOut.normFactor[0] |
|
1401 | normFactor_acf = dataOut.normFactor[0] | |
1402 | normFactor_ccf = dataOut.normFactor[1] |
|
1402 | normFactor_ccf = dataOut.normFactor[1] | |
1403 | pairs_acf = dataOut.groupList[0] |
|
1403 | pairs_acf = dataOut.groupList[0] | |
1404 | pairs_ccf = dataOut.groupList[1] |
|
1404 | pairs_ccf = dataOut.groupList[1] | |
1405 |
|
1405 | |||
1406 | nHeights = dataOut.nHeights |
|
1406 | nHeights = dataOut.nHeights | |
1407 | absc = dataOut.abscissaList |
|
1407 | absc = dataOut.abscissaList | |
1408 | noise = dataOut.noise |
|
1408 | noise = dataOut.noise | |
1409 | SNR = dataOut.data_snr |
|
1409 | SNR = dataOut.data_snr | |
1410 | nChannels = dataOut.nChannels |
|
1410 | nChannels = dataOut.nChannels | |
1411 | # pairsList = dataOut.groupList |
|
1411 | # pairsList = dataOut.groupList | |
1412 | # pairsAutoCorr, pairsCrossCorr = self.__getPairsAutoCorr(pairsList, nChannels) |
|
1412 | # pairsAutoCorr, pairsCrossCorr = self.__getPairsAutoCorr(pairsList, nChannels) | |
1413 |
|
1413 | |||
1414 | for l in range(len(pairs_acf)): |
|
1414 | for l in range(len(pairs_acf)): | |
1415 | data_acf[l,:,:] = data_acf[l,:,:]/normFactor_acf[l,:] |
|
1415 | data_acf[l,:,:] = data_acf[l,:,:]/normFactor_acf[l,:] | |
1416 |
|
1416 | |||
1417 | for l in range(len(pairs_ccf)): |
|
1417 | for l in range(len(pairs_ccf)): | |
1418 | data_ccf[l,:,:] = data_ccf[l,:,:]/normFactor_ccf[l,:] |
|
1418 | data_ccf[l,:,:] = data_ccf[l,:,:]/normFactor_ccf[l,:] | |
1419 |
|
1419 | |||
1420 | dataOut.data_param = numpy.zeros((len(pairs_ccf)*2 + 1, nHeights)) |
|
1420 | dataOut.data_param = numpy.zeros((len(pairs_ccf)*2 + 1, nHeights)) | |
1421 | dataOut.data_param[:-1,:] = self.__calculateTaus(data_acf, data_ccf, absc) |
|
1421 | dataOut.data_param[:-1,:] = self.__calculateTaus(data_acf, data_ccf, absc) | |
1422 | dataOut.data_param[-1,:] = self.__calculateLag1Phase(data_acf, absc) |
|
1422 | dataOut.data_param[-1,:] = self.__calculateLag1Phase(data_acf, absc) | |
1423 | return |
|
1423 | return | |
1424 |
|
1424 | |||
1425 | # def __getPairsAutoCorr(self, pairsList, nChannels): |
|
1425 | # def __getPairsAutoCorr(self, pairsList, nChannels): | |
1426 | # |
|
1426 | # | |
1427 | # pairsAutoCorr = numpy.zeros(nChannels, dtype = 'int')*numpy.nan |
|
1427 | # pairsAutoCorr = numpy.zeros(nChannels, dtype = 'int')*numpy.nan | |
1428 | # |
|
1428 | # | |
1429 | # for l in range(len(pairsList)): |
|
1429 | # for l in range(len(pairsList)): | |
1430 | # firstChannel = pairsList[l][0] |
|
1430 | # firstChannel = pairsList[l][0] | |
1431 | # secondChannel = pairsList[l][1] |
|
1431 | # secondChannel = pairsList[l][1] | |
1432 | # |
|
1432 | # | |
1433 | # #Obteniendo pares de Autocorrelacion |
|
1433 | # #Obteniendo pares de Autocorrelacion | |
1434 | # if firstChannel == secondChannel: |
|
1434 | # if firstChannel == secondChannel: | |
1435 | # pairsAutoCorr[firstChannel] = int(l) |
|
1435 | # pairsAutoCorr[firstChannel] = int(l) | |
1436 | # |
|
1436 | # | |
1437 | # pairsAutoCorr = pairsAutoCorr.astype(int) |
|
1437 | # pairsAutoCorr = pairsAutoCorr.astype(int) | |
1438 | # |
|
1438 | # | |
1439 | # pairsCrossCorr = range(len(pairsList)) |
|
1439 | # pairsCrossCorr = range(len(pairsList)) | |
1440 | # pairsCrossCorr = numpy.delete(pairsCrossCorr,pairsAutoCorr) |
|
1440 | # pairsCrossCorr = numpy.delete(pairsCrossCorr,pairsAutoCorr) | |
1441 | # |
|
1441 | # | |
1442 | # return pairsAutoCorr, pairsCrossCorr |
|
1442 | # return pairsAutoCorr, pairsCrossCorr | |
1443 |
|
1443 | |||
1444 | def __calculateTaus(self, data_acf, data_ccf, lagRange): |
|
1444 | def __calculateTaus(self, data_acf, data_ccf, lagRange): | |
1445 |
|
1445 | |||
1446 | lag0 = data_acf.shape[1]/2 |
|
1446 | lag0 = data_acf.shape[1]/2 | |
1447 | #Funcion de Autocorrelacion |
|
1447 | #Funcion de Autocorrelacion | |
1448 | mean_acf = stats.nanmean(data_acf, axis = 0) |
|
1448 | mean_acf = stats.nanmean(data_acf, axis = 0) | |
1449 |
|
1449 | |||
1450 | #Obtencion Indice de TauCross |
|
1450 | #Obtencion Indice de TauCross | |
1451 | ind_ccf = data_ccf.argmax(axis = 1) |
|
1451 | ind_ccf = data_ccf.argmax(axis = 1) | |
1452 | #Obtencion Indice de TauAuto |
|
1452 | #Obtencion Indice de TauAuto | |
1453 | ind_acf = numpy.zeros(ind_ccf.shape,dtype = 'int') |
|
1453 | ind_acf = numpy.zeros(ind_ccf.shape,dtype = 'int') | |
1454 | ccf_lag0 = data_ccf[:,lag0,:] |
|
1454 | ccf_lag0 = data_ccf[:,lag0,:] | |
1455 |
|
1455 | |||
1456 | for i in range(ccf_lag0.shape[0]): |
|
1456 | for i in range(ccf_lag0.shape[0]): | |
1457 | ind_acf[i,:] = numpy.abs(mean_acf - ccf_lag0[i,:]).argmin(axis = 0) |
|
1457 | ind_acf[i,:] = numpy.abs(mean_acf - ccf_lag0[i,:]).argmin(axis = 0) | |
1458 |
|
1458 | |||
1459 | #Obtencion de TauCross y TauAuto |
|
1459 | #Obtencion de TauCross y TauAuto | |
1460 | tau_ccf = lagRange[ind_ccf] |
|
1460 | tau_ccf = lagRange[ind_ccf] | |
1461 | tau_acf = lagRange[ind_acf] |
|
1461 | tau_acf = lagRange[ind_acf] | |
1462 |
|
1462 | |||
1463 | Nan1, Nan2 = numpy.where(tau_ccf == lagRange[0]) |
|
1463 | Nan1, Nan2 = numpy.where(tau_ccf == lagRange[0]) | |
1464 |
|
1464 | |||
1465 | tau_ccf[Nan1,Nan2] = numpy.nan |
|
1465 | tau_ccf[Nan1,Nan2] = numpy.nan | |
1466 | tau_acf[Nan1,Nan2] = numpy.nan |
|
1466 | tau_acf[Nan1,Nan2] = numpy.nan | |
1467 | tau = numpy.vstack((tau_ccf,tau_acf)) |
|
1467 | tau = numpy.vstack((tau_ccf,tau_acf)) | |
1468 |
|
1468 | |||
1469 | return tau |
|
1469 | return tau | |
1470 |
|
1470 | |||
1471 | def __calculateLag1Phase(self, data, lagTRange): |
|
1471 | def __calculateLag1Phase(self, data, lagTRange): | |
1472 | data1 = stats.nanmean(data, axis = 0) |
|
1472 | data1 = stats.nanmean(data, axis = 0) | |
1473 | lag1 = numpy.where(lagTRange == 0)[0][0] + 1 |
|
1473 | lag1 = numpy.where(lagTRange == 0)[0][0] + 1 | |
1474 |
|
1474 | |||
1475 | phase = numpy.angle(data1[lag1,:]) |
|
1475 | phase = numpy.angle(data1[lag1,:]) | |
1476 |
|
1476 | |||
1477 | return phase |
|
1477 | return phase | |
1478 |
|
1478 | |||
1479 | class SpectralFitting(Operation): |
|
1479 | class SpectralFitting(Operation): | |
1480 | ''' |
|
1480 | ''' | |
1481 | Function GetMoments() |
|
1481 | Function GetMoments() | |
1482 |
|
1482 | |||
1483 | Input: |
|
1483 | Input: | |
1484 | Output: |
|
1484 | Output: | |
1485 | Variables modified: |
|
1485 | Variables modified: | |
1486 | ''' |
|
1486 | ''' | |
1487 |
|
1487 | |||
1488 | def run(self, dataOut, getSNR = True, path=None, file=None, groupList=None): |
|
1488 | def run(self, dataOut, getSNR = True, path=None, file=None, groupList=None): | |
1489 |
|
1489 | |||
1490 |
|
1490 | |||
1491 | if path != None: |
|
1491 | if path != None: | |
1492 | sys.path.append(path) |
|
1492 | sys.path.append(path) | |
1493 | self.dataOut.library = importlib.import_module(file) |
|
1493 | self.dataOut.library = importlib.import_module(file) | |
1494 |
|
1494 | |||
1495 | #To be inserted as a parameter |
|
1495 | #To be inserted as a parameter | |
1496 | groupArray = numpy.array(groupList) |
|
1496 | groupArray = numpy.array(groupList) | |
1497 | # groupArray = numpy.array([[0,1],[2,3]]) |
|
1497 | # groupArray = numpy.array([[0,1],[2,3]]) | |
1498 | self.dataOut.groupList = groupArray |
|
1498 | self.dataOut.groupList = groupArray | |
1499 |
|
1499 | |||
1500 | nGroups = groupArray.shape[0] |
|
1500 | nGroups = groupArray.shape[0] | |
1501 | nChannels = self.dataIn.nChannels |
|
1501 | nChannels = self.dataIn.nChannels | |
1502 | nHeights=self.dataIn.heightList.size |
|
1502 | nHeights=self.dataIn.heightList.size | |
1503 |
|
1503 | |||
1504 | #Parameters Array |
|
1504 | #Parameters Array | |
1505 | self.dataOut.data_param = None |
|
1505 | self.dataOut.data_param = None | |
1506 |
|
1506 | |||
1507 | #Set constants |
|
1507 | #Set constants | |
1508 | constants = self.dataOut.library.setConstants(self.dataIn) |
|
1508 | constants = self.dataOut.library.setConstants(self.dataIn) | |
1509 | self.dataOut.constants = constants |
|
1509 | self.dataOut.constants = constants | |
1510 | M = self.dataIn.normFactor |
|
1510 | M = self.dataIn.normFactor | |
1511 | N = self.dataIn.nFFTPoints |
|
1511 | N = self.dataIn.nFFTPoints | |
1512 | ippSeconds = self.dataIn.ippSeconds |
|
1512 | ippSeconds = self.dataIn.ippSeconds | |
1513 | K = self.dataIn.nIncohInt |
|
1513 | K = self.dataIn.nIncohInt | |
1514 | pairsArray = numpy.array(self.dataIn.pairsList) |
|
1514 | pairsArray = numpy.array(self.dataIn.pairsList) | |
1515 |
|
1515 | |||
1516 | #List of possible combinations |
|
1516 | #List of possible combinations | |
1517 | listComb = itertools.combinations(numpy.arange(groupArray.shape[1]),2) |
|
1517 | listComb = itertools.combinations(numpy.arange(groupArray.shape[1]),2) | |
1518 | indCross = numpy.zeros(len(list(listComb)), dtype = 'int') |
|
1518 | indCross = numpy.zeros(len(list(listComb)), dtype = 'int') | |
1519 |
|
1519 | |||
1520 | if getSNR: |
|
1520 | if getSNR: | |
1521 | listChannels = groupArray.reshape((groupArray.size)) |
|
1521 | listChannels = groupArray.reshape((groupArray.size)) | |
1522 | listChannels.sort() |
|
1522 | listChannels.sort() | |
1523 | noise = self.dataIn.getNoise() |
|
1523 | noise = self.dataIn.getNoise() | |
1524 | self.dataOut.data_snr = self.__getSNR(self.dataIn.data_spc[listChannels,:,:], noise[listChannels]) |
|
1524 | self.dataOut.data_snr = self.__getSNR(self.dataIn.data_spc[listChannels,:,:], noise[listChannels]) | |
1525 |
|
1525 | |||
1526 | for i in range(nGroups): |
|
1526 | for i in range(nGroups): | |
1527 | coord = groupArray[i,:] |
|
1527 | coord = groupArray[i,:] | |
1528 |
|
1528 | |||
1529 | #Input data array |
|
1529 | #Input data array | |
1530 | data = self.dataIn.data_spc[coord,:,:]/(M*N) |
|
1530 | data = self.dataIn.data_spc[coord,:,:]/(M*N) | |
1531 | data = data.reshape((data.shape[0]*data.shape[1],data.shape[2])) |
|
1531 | data = data.reshape((data.shape[0]*data.shape[1],data.shape[2])) | |
1532 |
|
1532 | |||
1533 | #Cross Spectra data array for Covariance Matrixes |
|
1533 | #Cross Spectra data array for Covariance Matrixes | |
1534 | ind = 0 |
|
1534 | ind = 0 | |
1535 | for pairs in listComb: |
|
1535 | for pairs in listComb: | |
1536 | pairsSel = numpy.array([coord[x],coord[y]]) |
|
1536 | pairsSel = numpy.array([coord[x],coord[y]]) | |
1537 | indCross[ind] = int(numpy.where(numpy.all(pairsArray == pairsSel, axis = 1))[0][0]) |
|
1537 | indCross[ind] = int(numpy.where(numpy.all(pairsArray == pairsSel, axis = 1))[0][0]) | |
1538 | ind += 1 |
|
1538 | ind += 1 | |
1539 | dataCross = self.dataIn.data_cspc[indCross,:,:]/(M*N) |
|
1539 | dataCross = self.dataIn.data_cspc[indCross,:,:]/(M*N) | |
1540 | dataCross = dataCross**2/K |
|
1540 | dataCross = dataCross**2/K | |
1541 |
|
1541 | |||
1542 | for h in range(nHeights): |
|
1542 | for h in range(nHeights): | |
1543 |
|
1543 | |||
1544 | #Input |
|
1544 | #Input | |
1545 | d = data[:,h] |
|
1545 | d = data[:,h] | |
1546 |
|
1546 | |||
1547 | #Covariance Matrix |
|
1547 | #Covariance Matrix | |
1548 | D = numpy.diag(d**2/K) |
|
1548 | D = numpy.diag(d**2/K) | |
1549 | ind = 0 |
|
1549 | ind = 0 | |
1550 | for pairs in listComb: |
|
1550 | for pairs in listComb: | |
1551 | #Coordinates in Covariance Matrix |
|
1551 | #Coordinates in Covariance Matrix | |
1552 | x = pairs[0] |
|
1552 | x = pairs[0] | |
1553 | y = pairs[1] |
|
1553 | y = pairs[1] | |
1554 | #Channel Index |
|
1554 | #Channel Index | |
1555 | S12 = dataCross[ind,:,h] |
|
1555 | S12 = dataCross[ind,:,h] | |
1556 | D12 = numpy.diag(S12) |
|
1556 | D12 = numpy.diag(S12) | |
1557 | #Completing Covariance Matrix with Cross Spectras |
|
1557 | #Completing Covariance Matrix with Cross Spectras | |
1558 | D[x*N:(x+1)*N,y*N:(y+1)*N] = D12 |
|
1558 | D[x*N:(x+1)*N,y*N:(y+1)*N] = D12 | |
1559 | D[y*N:(y+1)*N,x*N:(x+1)*N] = D12 |
|
1559 | D[y*N:(y+1)*N,x*N:(x+1)*N] = D12 | |
1560 | ind += 1 |
|
1560 | ind += 1 | |
1561 | Dinv=numpy.linalg.inv(D) |
|
1561 | Dinv=numpy.linalg.inv(D) | |
1562 | L=numpy.linalg.cholesky(Dinv) |
|
1562 | L=numpy.linalg.cholesky(Dinv) | |
1563 | LT=L.T |
|
1563 | LT=L.T | |
1564 |
|
1564 | |||
1565 | dp = numpy.dot(LT,d) |
|
1565 | dp = numpy.dot(LT,d) | |
1566 |
|
1566 | |||
1567 | #Initial values |
|
1567 | #Initial values | |
1568 | data_spc = self.dataIn.data_spc[coord,:,h] |
|
1568 | data_spc = self.dataIn.data_spc[coord,:,h] | |
1569 |
|
1569 | |||
1570 | if (h>0)and(error1[3]<5): |
|
1570 | if (h>0)and(error1[3]<5): | |
1571 | p0 = self.dataOut.data_param[i,:,h-1] |
|
1571 | p0 = self.dataOut.data_param[i,:,h-1] | |
1572 | else: |
|
1572 | else: | |
1573 | p0 = numpy.array(self.dataOut.library.initialValuesFunction(data_spc, constants, i)) |
|
1573 | p0 = numpy.array(self.dataOut.library.initialValuesFunction(data_spc, constants, i)) | |
1574 |
|
1574 | |||
1575 | try: |
|
1575 | try: | |
1576 | #Least Squares |
|
1576 | #Least Squares | |
1577 | minp,covp,infodict,mesg,ier = optimize.leastsq(self.__residFunction,p0,args=(dp,LT,constants),full_output=True) |
|
1577 | minp,covp,infodict,mesg,ier = optimize.leastsq(self.__residFunction,p0,args=(dp,LT,constants),full_output=True) | |
1578 | # minp,covp = optimize.leastsq(self.__residFunction,p0,args=(dp,LT,constants)) |
|
1578 | # minp,covp = optimize.leastsq(self.__residFunction,p0,args=(dp,LT,constants)) | |
1579 | #Chi square error |
|
1579 | #Chi square error | |
1580 | error0 = numpy.sum(infodict['fvec']**2)/(2*N) |
|
1580 | error0 = numpy.sum(infodict['fvec']**2)/(2*N) | |
1581 | #Error with Jacobian |
|
1581 | #Error with Jacobian | |
1582 | error1 = self.dataOut.library.errorFunction(minp,constants,LT) |
|
1582 | error1 = self.dataOut.library.errorFunction(minp,constants,LT) | |
1583 | except: |
|
1583 | except: | |
1584 | minp = p0*numpy.nan |
|
1584 | minp = p0*numpy.nan | |
1585 | error0 = numpy.nan |
|
1585 | error0 = numpy.nan | |
1586 | error1 = p0*numpy.nan |
|
1586 | error1 = p0*numpy.nan | |
1587 |
|
1587 | |||
1588 | #Save |
|
1588 | #Save | |
1589 | if self.dataOut.data_param is None: |
|
1589 | if self.dataOut.data_param is None: | |
1590 | self.dataOut.data_param = numpy.zeros((nGroups, p0.size, nHeights))*numpy.nan |
|
1590 | self.dataOut.data_param = numpy.zeros((nGroups, p0.size, nHeights))*numpy.nan | |
1591 | self.dataOut.data_error = numpy.zeros((nGroups, p0.size + 1, nHeights))*numpy.nan |
|
1591 | self.dataOut.data_error = numpy.zeros((nGroups, p0.size + 1, nHeights))*numpy.nan | |
1592 |
|
1592 | |||
1593 | self.dataOut.data_error[i,:,h] = numpy.hstack((error0,error1)) |
|
1593 | self.dataOut.data_error[i,:,h] = numpy.hstack((error0,error1)) | |
1594 | self.dataOut.data_param[i,:,h] = minp |
|
1594 | self.dataOut.data_param[i,:,h] = minp | |
1595 | return |
|
1595 | return | |
1596 |
|
1596 | |||
1597 | def __residFunction(self, p, dp, LT, constants): |
|
1597 | def __residFunction(self, p, dp, LT, constants): | |
1598 |
|
1598 | |||
1599 | fm = self.dataOut.library.modelFunction(p, constants) |
|
1599 | fm = self.dataOut.library.modelFunction(p, constants) | |
1600 | fmp=numpy.dot(LT,fm) |
|
1600 | fmp=numpy.dot(LT,fm) | |
1601 |
|
1601 | |||
1602 | return dp-fmp |
|
1602 | return dp-fmp | |
1603 |
|
1603 | |||
1604 | def __getSNR(self, z, noise): |
|
1604 | def __getSNR(self, z, noise): | |
1605 |
|
1605 | |||
1606 | avg = numpy.average(z, axis=1) |
|
1606 | avg = numpy.average(z, axis=1) | |
1607 | SNR = (avg.T-noise)/noise |
|
1607 | SNR = (avg.T-noise)/noise | |
1608 | SNR = SNR.T |
|
1608 | SNR = SNR.T | |
1609 | return SNR |
|
1609 | return SNR | |
1610 |
|
1610 | |||
1611 | def __chisq(p,chindex,hindex): |
|
1611 | def __chisq(p,chindex,hindex): | |
1612 | #similar to Resid but calculates CHI**2 |
|
1612 | #similar to Resid but calculates CHI**2 | |
1613 | [LT,d,fm]=setupLTdfm(p,chindex,hindex) |
|
1613 | [LT,d,fm]=setupLTdfm(p,chindex,hindex) | |
1614 | dp=numpy.dot(LT,d) |
|
1614 | dp=numpy.dot(LT,d) | |
1615 | fmp=numpy.dot(LT,fm) |
|
1615 | fmp=numpy.dot(LT,fm) | |
1616 | chisq=numpy.dot((dp-fmp).T,(dp-fmp)) |
|
1616 | chisq=numpy.dot((dp-fmp).T,(dp-fmp)) | |
1617 | return chisq |
|
1617 | return chisq | |
1618 |
|
1618 | |||
1619 | class WindProfiler(Operation): |
|
1619 | class WindProfiler(Operation): | |
1620 |
|
1620 | |||
1621 | __isConfig = False |
|
1621 | __isConfig = False | |
1622 |
|
1622 | |||
1623 | __initime = None |
|
1623 | __initime = None | |
1624 | __lastdatatime = None |
|
1624 | __lastdatatime = None | |
1625 | __integrationtime = None |
|
1625 | __integrationtime = None | |
1626 |
|
1626 | |||
1627 | __buffer = None |
|
1627 | __buffer = None | |
1628 |
|
1628 | |||
1629 | __dataReady = False |
|
1629 | __dataReady = False | |
1630 |
|
1630 | |||
1631 | __firstdata = None |
|
1631 | __firstdata = None | |
1632 |
|
1632 | |||
1633 | n = None |
|
1633 | n = None | |
1634 |
|
1634 | |||
1635 | def __init__(self): |
|
1635 | def __init__(self): | |
1636 | Operation.__init__(self) |
|
1636 | Operation.__init__(self) | |
1637 |
|
1637 | |||
1638 | def __calculateCosDir(self, elev, azim): |
|
1638 | def __calculateCosDir(self, elev, azim): | |
1639 | zen = (90 - elev)*numpy.pi/180 |
|
1639 | zen = (90 - elev)*numpy.pi/180 | |
1640 | azim = azim*numpy.pi/180 |
|
1640 | azim = azim*numpy.pi/180 | |
1641 | cosDirX = numpy.sqrt((1-numpy.cos(zen)**2)/((1+numpy.tan(azim)**2))) |
|
1641 | cosDirX = numpy.sqrt((1-numpy.cos(zen)**2)/((1+numpy.tan(azim)**2))) | |
1642 | cosDirY = numpy.sqrt(1-numpy.cos(zen)**2-cosDirX**2) |
|
1642 | cosDirY = numpy.sqrt(1-numpy.cos(zen)**2-cosDirX**2) | |
1643 |
|
1643 | |||
1644 | signX = numpy.sign(numpy.cos(azim)) |
|
1644 | signX = numpy.sign(numpy.cos(azim)) | |
1645 | signY = numpy.sign(numpy.sin(azim)) |
|
1645 | signY = numpy.sign(numpy.sin(azim)) | |
1646 |
|
1646 | |||
1647 | cosDirX = numpy.copysign(cosDirX, signX) |
|
1647 | cosDirX = numpy.copysign(cosDirX, signX) | |
1648 | cosDirY = numpy.copysign(cosDirY, signY) |
|
1648 | cosDirY = numpy.copysign(cosDirY, signY) | |
1649 | return cosDirX, cosDirY |
|
1649 | return cosDirX, cosDirY | |
1650 |
|
1650 | |||
1651 | def __calculateAngles(self, theta_x, theta_y, azimuth): |
|
1651 | def __calculateAngles(self, theta_x, theta_y, azimuth): | |
1652 |
|
1652 | |||
1653 | dir_cosw = numpy.sqrt(1-theta_x**2-theta_y**2) |
|
1653 | dir_cosw = numpy.sqrt(1-theta_x**2-theta_y**2) | |
1654 | zenith_arr = numpy.arccos(dir_cosw) |
|
1654 | zenith_arr = numpy.arccos(dir_cosw) | |
1655 | azimuth_arr = numpy.arctan2(theta_x,theta_y) + azimuth*math.pi/180 |
|
1655 | azimuth_arr = numpy.arctan2(theta_x,theta_y) + azimuth*math.pi/180 | |
1656 |
|
1656 | |||
1657 | dir_cosu = numpy.sin(azimuth_arr)*numpy.sin(zenith_arr) |
|
1657 | dir_cosu = numpy.sin(azimuth_arr)*numpy.sin(zenith_arr) | |
1658 | dir_cosv = numpy.cos(azimuth_arr)*numpy.sin(zenith_arr) |
|
1658 | dir_cosv = numpy.cos(azimuth_arr)*numpy.sin(zenith_arr) | |
1659 |
|
1659 | |||
1660 | return azimuth_arr, zenith_arr, dir_cosu, dir_cosv, dir_cosw |
|
1660 | return azimuth_arr, zenith_arr, dir_cosu, dir_cosv, dir_cosw | |
1661 |
|
1661 | |||
1662 | def __calculateMatA(self, dir_cosu, dir_cosv, dir_cosw, horOnly): |
|
1662 | def __calculateMatA(self, dir_cosu, dir_cosv, dir_cosw, horOnly): | |
1663 |
|
1663 | |||
1664 | # |
|
1664 | # | |
1665 | if horOnly: |
|
1665 | if horOnly: | |
1666 | A = numpy.c_[dir_cosu,dir_cosv] |
|
1666 | A = numpy.c_[dir_cosu,dir_cosv] | |
1667 | else: |
|
1667 | else: | |
1668 | A = numpy.c_[dir_cosu,dir_cosv,dir_cosw] |
|
1668 | A = numpy.c_[dir_cosu,dir_cosv,dir_cosw] | |
1669 | A = numpy.asmatrix(A) |
|
1669 | A = numpy.asmatrix(A) | |
1670 | A1 = numpy.linalg.inv(A.transpose()*A)*A.transpose() |
|
1670 | A1 = numpy.linalg.inv(A.transpose()*A)*A.transpose() | |
1671 |
|
1671 | |||
1672 | return A1 |
|
1672 | return A1 | |
1673 |
|
1673 | |||
1674 | def __correctValues(self, heiRang, phi, velRadial, SNR): |
|
1674 | def __correctValues(self, heiRang, phi, velRadial, SNR): | |
1675 | listPhi = phi.tolist() |
|
1675 | listPhi = phi.tolist() | |
1676 | maxid = listPhi.index(max(listPhi)) |
|
1676 | maxid = listPhi.index(max(listPhi)) | |
1677 | minid = listPhi.index(min(listPhi)) |
|
1677 | minid = listPhi.index(min(listPhi)) | |
1678 |
|
1678 | |||
1679 | rango = list(range(len(phi))) |
|
1679 | rango = list(range(len(phi))) | |
1680 | # rango = numpy.delete(rango,maxid) |
|
1680 | # rango = numpy.delete(rango,maxid) | |
1681 |
|
1681 | |||
1682 | heiRang1 = heiRang*math.cos(phi[maxid]) |
|
1682 | heiRang1 = heiRang*math.cos(phi[maxid]) | |
1683 | heiRangAux = heiRang*math.cos(phi[minid]) |
|
1683 | heiRangAux = heiRang*math.cos(phi[minid]) | |
1684 | indOut = (heiRang1 < heiRangAux[0]).nonzero() |
|
1684 | indOut = (heiRang1 < heiRangAux[0]).nonzero() | |
1685 | heiRang1 = numpy.delete(heiRang1,indOut) |
|
1685 | heiRang1 = numpy.delete(heiRang1,indOut) | |
1686 |
|
1686 | |||
1687 | velRadial1 = numpy.zeros([len(phi),len(heiRang1)]) |
|
1687 | velRadial1 = numpy.zeros([len(phi),len(heiRang1)]) | |
1688 | SNR1 = numpy.zeros([len(phi),len(heiRang1)]) |
|
1688 | SNR1 = numpy.zeros([len(phi),len(heiRang1)]) | |
1689 |
|
1689 | |||
1690 | for i in rango: |
|
1690 | for i in rango: | |
1691 | x = heiRang*math.cos(phi[i]) |
|
1691 | x = heiRang*math.cos(phi[i]) | |
1692 | y1 = velRadial[i,:] |
|
1692 | y1 = velRadial[i,:] | |
1693 | f1 = interpolate.interp1d(x,y1,kind = 'cubic') |
|
1693 | f1 = interpolate.interp1d(x,y1,kind = 'cubic') | |
1694 |
|
1694 | |||
1695 | x1 = heiRang1 |
|
1695 | x1 = heiRang1 | |
1696 | y11 = f1(x1) |
|
1696 | y11 = f1(x1) | |
1697 |
|
1697 | |||
1698 | y2 = SNR[i,:] |
|
1698 | y2 = SNR[i,:] | |
1699 | f2 = interpolate.interp1d(x,y2,kind = 'cubic') |
|
1699 | f2 = interpolate.interp1d(x,y2,kind = 'cubic') | |
1700 | y21 = f2(x1) |
|
1700 | y21 = f2(x1) | |
1701 |
|
1701 | |||
1702 | velRadial1[i,:] = y11 |
|
1702 | velRadial1[i,:] = y11 | |
1703 | SNR1[i,:] = y21 |
|
1703 | SNR1[i,:] = y21 | |
1704 |
|
1704 | |||
1705 | return heiRang1, velRadial1, SNR1 |
|
1705 | return heiRang1, velRadial1, SNR1 | |
1706 |
|
1706 | |||
1707 | def __calculateVelUVW(self, A, velRadial): |
|
1707 | def __calculateVelUVW(self, A, velRadial): | |
1708 |
|
1708 | |||
1709 | #Operacion Matricial |
|
1709 | #Operacion Matricial | |
1710 | # velUVW = numpy.zeros((velRadial.shape[1],3)) |
|
1710 | # velUVW = numpy.zeros((velRadial.shape[1],3)) | |
1711 | # for ind in range(velRadial.shape[1]): |
|
1711 | # for ind in range(velRadial.shape[1]): | |
1712 | # velUVW[ind,:] = numpy.dot(A,velRadial[:,ind]) |
|
1712 | # velUVW[ind,:] = numpy.dot(A,velRadial[:,ind]) | |
1713 | # velUVW = velUVW.transpose() |
|
1713 | # velUVW = velUVW.transpose() | |
1714 | velUVW = numpy.zeros((A.shape[0],velRadial.shape[1])) |
|
1714 | velUVW = numpy.zeros((A.shape[0],velRadial.shape[1])) | |
1715 | velUVW[:,:] = numpy.dot(A,velRadial) |
|
1715 | velUVW[:,:] = numpy.dot(A,velRadial) | |
1716 |
|
1716 | |||
1717 |
|
1717 | |||
1718 | return velUVW |
|
1718 | return velUVW | |
1719 |
|
1719 | |||
1720 | # def techniqueDBS(self, velRadial0, dirCosx, disrCosy, azimuth, correct, horizontalOnly, heiRang, SNR0): |
|
1720 | # def techniqueDBS(self, velRadial0, dirCosx, disrCosy, azimuth, correct, horizontalOnly, heiRang, SNR0): | |
1721 |
|
1721 | |||
1722 | def techniqueDBS(self, kwargs): |
|
1722 | def techniqueDBS(self, kwargs): | |
1723 | """ |
|
1723 | """ | |
1724 | Function that implements Doppler Beam Swinging (DBS) technique. |
|
1724 | Function that implements Doppler Beam Swinging (DBS) technique. | |
1725 |
|
1725 | |||
1726 | Input: Radial velocities, Direction cosines (x and y) of the Beam, Antenna azimuth, |
|
1726 | Input: Radial velocities, Direction cosines (x and y) of the Beam, Antenna azimuth, | |
1727 | Direction correction (if necessary), Ranges and SNR |
|
1727 | Direction correction (if necessary), Ranges and SNR | |
1728 |
|
1728 | |||
1729 | Output: Winds estimation (Zonal, Meridional and Vertical) |
|
1729 | Output: Winds estimation (Zonal, Meridional and Vertical) | |
1730 |
|
1730 | |||
1731 | Parameters affected: Winds, height range, SNR |
|
1731 | Parameters affected: Winds, height range, SNR | |
1732 | """ |
|
1732 | """ | |
1733 | velRadial0 = kwargs['velRadial'] |
|
1733 | velRadial0 = kwargs['velRadial'] | |
1734 | heiRang = kwargs['heightList'] |
|
1734 | heiRang = kwargs['heightList'] | |
1735 | SNR0 = kwargs['SNR'] |
|
1735 | SNR0 = kwargs['SNR'] | |
1736 |
|
1736 | |||
1737 | if 'dirCosx' in kwargs and 'dirCosy' in kwargs: |
|
1737 | if 'dirCosx' in kwargs and 'dirCosy' in kwargs: | |
1738 | theta_x = numpy.array(kwargs['dirCosx']) |
|
1738 | theta_x = numpy.array(kwargs['dirCosx']) | |
1739 | theta_y = numpy.array(kwargs['dirCosy']) |
|
1739 | theta_y = numpy.array(kwargs['dirCosy']) | |
1740 | else: |
|
1740 | else: | |
1741 | elev = numpy.array(kwargs['elevation']) |
|
1741 | elev = numpy.array(kwargs['elevation']) | |
1742 | azim = numpy.array(kwargs['azimuth']) |
|
1742 | azim = numpy.array(kwargs['azimuth']) | |
1743 | theta_x, theta_y = self.__calculateCosDir(elev, azim) |
|
1743 | theta_x, theta_y = self.__calculateCosDir(elev, azim) | |
1744 | azimuth = kwargs['correctAzimuth'] |
|
1744 | azimuth = kwargs['correctAzimuth'] | |
1745 | if 'horizontalOnly' in kwargs: |
|
1745 | if 'horizontalOnly' in kwargs: | |
1746 | horizontalOnly = kwargs['horizontalOnly'] |
|
1746 | horizontalOnly = kwargs['horizontalOnly'] | |
1747 | else: horizontalOnly = False |
|
1747 | else: horizontalOnly = False | |
1748 | if 'correctFactor' in kwargs: |
|
1748 | if 'correctFactor' in kwargs: | |
1749 | correctFactor = kwargs['correctFactor'] |
|
1749 | correctFactor = kwargs['correctFactor'] | |
1750 | else: correctFactor = 1 |
|
1750 | else: correctFactor = 1 | |
1751 | if 'channelList' in kwargs: |
|
1751 | if 'channelList' in kwargs: | |
1752 | channelList = kwargs['channelList'] |
|
1752 | channelList = kwargs['channelList'] | |
1753 | if len(channelList) == 2: |
|
1753 | if len(channelList) == 2: | |
1754 | horizontalOnly = True |
|
1754 | horizontalOnly = True | |
1755 | arrayChannel = numpy.array(channelList) |
|
1755 | arrayChannel = numpy.array(channelList) | |
1756 | param = param[arrayChannel,:,:] |
|
1756 | param = param[arrayChannel,:,:] | |
1757 | theta_x = theta_x[arrayChannel] |
|
1757 | theta_x = theta_x[arrayChannel] | |
1758 | theta_y = theta_y[arrayChannel] |
|
1758 | theta_y = theta_y[arrayChannel] | |
1759 |
|
1759 | |||
1760 | azimuth_arr, zenith_arr, dir_cosu, dir_cosv, dir_cosw = self.__calculateAngles(theta_x, theta_y, azimuth) |
|
1760 | azimuth_arr, zenith_arr, dir_cosu, dir_cosv, dir_cosw = self.__calculateAngles(theta_x, theta_y, azimuth) | |
1761 | heiRang1, velRadial1, SNR1 = self.__correctValues(heiRang, zenith_arr, correctFactor*velRadial0, SNR0) |
|
1761 | heiRang1, velRadial1, SNR1 = self.__correctValues(heiRang, zenith_arr, correctFactor*velRadial0, SNR0) | |
1762 | A = self.__calculateMatA(dir_cosu, dir_cosv, dir_cosw, horizontalOnly) |
|
1762 | A = self.__calculateMatA(dir_cosu, dir_cosv, dir_cosw, horizontalOnly) | |
1763 |
|
1763 | |||
1764 | #Calculo de Componentes de la velocidad con DBS |
|
1764 | #Calculo de Componentes de la velocidad con DBS | |
1765 | winds = self.__calculateVelUVW(A,velRadial1) |
|
1765 | winds = self.__calculateVelUVW(A,velRadial1) | |
1766 |
|
1766 | |||
1767 | return winds, heiRang1, SNR1 |
|
1767 | return winds, heiRang1, SNR1 | |
1768 |
|
1768 | |||
1769 | def __calculateDistance(self, posx, posy, pairs_ccf, azimuth = None): |
|
1769 | def __calculateDistance(self, posx, posy, pairs_ccf, azimuth = None): | |
1770 |
|
1770 | |||
1771 | nPairs = len(pairs_ccf) |
|
1771 | nPairs = len(pairs_ccf) | |
1772 | posx = numpy.asarray(posx) |
|
1772 | posx = numpy.asarray(posx) | |
1773 | posy = numpy.asarray(posy) |
|
1773 | posy = numpy.asarray(posy) | |
1774 |
|
1774 | |||
1775 | #Rotacion Inversa para alinear con el azimuth |
|
1775 | #Rotacion Inversa para alinear con el azimuth | |
1776 | if azimuth!= None: |
|
1776 | if azimuth!= None: | |
1777 | azimuth = azimuth*math.pi/180 |
|
1777 | azimuth = azimuth*math.pi/180 | |
1778 | posx1 = posx*math.cos(azimuth) + posy*math.sin(azimuth) |
|
1778 | posx1 = posx*math.cos(azimuth) + posy*math.sin(azimuth) | |
1779 | posy1 = -posx*math.sin(azimuth) + posy*math.cos(azimuth) |
|
1779 | posy1 = -posx*math.sin(azimuth) + posy*math.cos(azimuth) | |
1780 | else: |
|
1780 | else: | |
1781 | posx1 = posx |
|
1781 | posx1 = posx | |
1782 | posy1 = posy |
|
1782 | posy1 = posy | |
1783 |
|
1783 | |||
1784 | #Calculo de Distancias |
|
1784 | #Calculo de Distancias | |
1785 | distx = numpy.zeros(nPairs) |
|
1785 | distx = numpy.zeros(nPairs) | |
1786 | disty = numpy.zeros(nPairs) |
|
1786 | disty = numpy.zeros(nPairs) | |
1787 | dist = numpy.zeros(nPairs) |
|
1787 | dist = numpy.zeros(nPairs) | |
1788 | ang = numpy.zeros(nPairs) |
|
1788 | ang = numpy.zeros(nPairs) | |
1789 |
|
1789 | |||
1790 | for i in range(nPairs): |
|
1790 | for i in range(nPairs): | |
1791 | distx[i] = posx1[pairs_ccf[i][1]] - posx1[pairs_ccf[i][0]] |
|
1791 | distx[i] = posx1[pairs_ccf[i][1]] - posx1[pairs_ccf[i][0]] | |
1792 | disty[i] = posy1[pairs_ccf[i][1]] - posy1[pairs_ccf[i][0]] |
|
1792 | disty[i] = posy1[pairs_ccf[i][1]] - posy1[pairs_ccf[i][0]] | |
1793 | dist[i] = numpy.sqrt(distx[i]**2 + disty[i]**2) |
|
1793 | dist[i] = numpy.sqrt(distx[i]**2 + disty[i]**2) | |
1794 | ang[i] = numpy.arctan2(disty[i],distx[i]) |
|
1794 | ang[i] = numpy.arctan2(disty[i],distx[i]) | |
1795 |
|
1795 | |||
1796 | return distx, disty, dist, ang |
|
1796 | return distx, disty, dist, ang | |
1797 | #Calculo de Matrices |
|
1797 | #Calculo de Matrices | |
1798 | # nPairs = len(pairs) |
|
1798 | # nPairs = len(pairs) | |
1799 | # ang1 = numpy.zeros((nPairs, 2, 1)) |
|
1799 | # ang1 = numpy.zeros((nPairs, 2, 1)) | |
1800 | # dist1 = numpy.zeros((nPairs, 2, 1)) |
|
1800 | # dist1 = numpy.zeros((nPairs, 2, 1)) | |
1801 | # |
|
1801 | # | |
1802 | # for j in range(nPairs): |
|
1802 | # for j in range(nPairs): | |
1803 | # dist1[j,0,0] = dist[pairs[j][0]] |
|
1803 | # dist1[j,0,0] = dist[pairs[j][0]] | |
1804 | # dist1[j,1,0] = dist[pairs[j][1]] |
|
1804 | # dist1[j,1,0] = dist[pairs[j][1]] | |
1805 | # ang1[j,0,0] = ang[pairs[j][0]] |
|
1805 | # ang1[j,0,0] = ang[pairs[j][0]] | |
1806 | # ang1[j,1,0] = ang[pairs[j][1]] |
|
1806 | # ang1[j,1,0] = ang[pairs[j][1]] | |
1807 | # |
|
1807 | # | |
1808 | # return distx,disty, dist1,ang1 |
|
1808 | # return distx,disty, dist1,ang1 | |
1809 |
|
1809 | |||
1810 |
|
1810 | |||
1811 | def __calculateVelVer(self, phase, lagTRange, _lambda): |
|
1811 | def __calculateVelVer(self, phase, lagTRange, _lambda): | |
1812 |
|
1812 | |||
1813 | Ts = lagTRange[1] - lagTRange[0] |
|
1813 | Ts = lagTRange[1] - lagTRange[0] | |
1814 | velW = -_lambda*phase/(4*math.pi*Ts) |
|
1814 | velW = -_lambda*phase/(4*math.pi*Ts) | |
1815 |
|
1815 | |||
1816 | return velW |
|
1816 | return velW | |
1817 |
|
1817 | |||
1818 | def __calculateVelHorDir(self, dist, tau1, tau2, ang): |
|
1818 | def __calculateVelHorDir(self, dist, tau1, tau2, ang): | |
1819 | nPairs = tau1.shape[0] |
|
1819 | nPairs = tau1.shape[0] | |
1820 | nHeights = tau1.shape[1] |
|
1820 | nHeights = tau1.shape[1] | |
1821 | vel = numpy.zeros((nPairs,3,nHeights)) |
|
1821 | vel = numpy.zeros((nPairs,3,nHeights)) | |
1822 | dist1 = numpy.reshape(dist, (dist.size,1)) |
|
1822 | dist1 = numpy.reshape(dist, (dist.size,1)) | |
1823 |
|
1823 | |||
1824 | angCos = numpy.cos(ang) |
|
1824 | angCos = numpy.cos(ang) | |
1825 | angSin = numpy.sin(ang) |
|
1825 | angSin = numpy.sin(ang) | |
1826 |
|
1826 | |||
1827 | vel0 = dist1*tau1/(2*tau2**2) |
|
1827 | vel0 = dist1*tau1/(2*tau2**2) | |
1828 | vel[:,0,:] = (vel0*angCos).sum(axis = 1) |
|
1828 | vel[:,0,:] = (vel0*angCos).sum(axis = 1) | |
1829 | vel[:,1,:] = (vel0*angSin).sum(axis = 1) |
|
1829 | vel[:,1,:] = (vel0*angSin).sum(axis = 1) | |
1830 |
|
1830 | |||
1831 | ind = numpy.where(numpy.isinf(vel)) |
|
1831 | ind = numpy.where(numpy.isinf(vel)) | |
1832 | vel[ind] = numpy.nan |
|
1832 | vel[ind] = numpy.nan | |
1833 |
|
1833 | |||
1834 | return vel |
|
1834 | return vel | |
1835 |
|
1835 | |||
1836 | # def __getPairsAutoCorr(self, pairsList, nChannels): |
|
1836 | # def __getPairsAutoCorr(self, pairsList, nChannels): | |
1837 | # |
|
1837 | # | |
1838 | # pairsAutoCorr = numpy.zeros(nChannels, dtype = 'int')*numpy.nan |
|
1838 | # pairsAutoCorr = numpy.zeros(nChannels, dtype = 'int')*numpy.nan | |
1839 | # |
|
1839 | # | |
1840 | # for l in range(len(pairsList)): |
|
1840 | # for l in range(len(pairsList)): | |
1841 | # firstChannel = pairsList[l][0] |
|
1841 | # firstChannel = pairsList[l][0] | |
1842 | # secondChannel = pairsList[l][1] |
|
1842 | # secondChannel = pairsList[l][1] | |
1843 | # |
|
1843 | # | |
1844 | # #Obteniendo pares de Autocorrelacion |
|
1844 | # #Obteniendo pares de Autocorrelacion | |
1845 | # if firstChannel == secondChannel: |
|
1845 | # if firstChannel == secondChannel: | |
1846 | # pairsAutoCorr[firstChannel] = int(l) |
|
1846 | # pairsAutoCorr[firstChannel] = int(l) | |
1847 | # |
|
1847 | # | |
1848 | # pairsAutoCorr = pairsAutoCorr.astype(int) |
|
1848 | # pairsAutoCorr = pairsAutoCorr.astype(int) | |
1849 | # |
|
1849 | # | |
1850 | # pairsCrossCorr = range(len(pairsList)) |
|
1850 | # pairsCrossCorr = range(len(pairsList)) | |
1851 | # pairsCrossCorr = numpy.delete(pairsCrossCorr,pairsAutoCorr) |
|
1851 | # pairsCrossCorr = numpy.delete(pairsCrossCorr,pairsAutoCorr) | |
1852 | # |
|
1852 | # | |
1853 | # return pairsAutoCorr, pairsCrossCorr |
|
1853 | # return pairsAutoCorr, pairsCrossCorr | |
1854 |
|
1854 | |||
1855 | # def techniqueSA(self, pairsSelected, pairsList, nChannels, tau, azimuth, _lambda, position_x, position_y, lagTRange, correctFactor): |
|
1855 | # def techniqueSA(self, pairsSelected, pairsList, nChannels, tau, azimuth, _lambda, position_x, position_y, lagTRange, correctFactor): | |
1856 | def techniqueSA(self, kwargs): |
|
1856 | def techniqueSA(self, kwargs): | |
1857 |
|
1857 | |||
1858 | """ |
|
1858 | """ | |
1859 | Function that implements Spaced Antenna (SA) technique. |
|
1859 | Function that implements Spaced Antenna (SA) technique. | |
1860 |
|
1860 | |||
1861 | Input: Radial velocities, Direction cosines (x and y) of the Beam, Antenna azimuth, |
|
1861 | Input: Radial velocities, Direction cosines (x and y) of the Beam, Antenna azimuth, | |
1862 | Direction correction (if necessary), Ranges and SNR |
|
1862 | Direction correction (if necessary), Ranges and SNR | |
1863 |
|
1863 | |||
1864 | Output: Winds estimation (Zonal, Meridional and Vertical) |
|
1864 | Output: Winds estimation (Zonal, Meridional and Vertical) | |
1865 |
|
1865 | |||
1866 | Parameters affected: Winds |
|
1866 | Parameters affected: Winds | |
1867 | """ |
|
1867 | """ | |
1868 | position_x = kwargs['positionX'] |
|
1868 | position_x = kwargs['positionX'] | |
1869 | position_y = kwargs['positionY'] |
|
1869 | position_y = kwargs['positionY'] | |
1870 | azimuth = kwargs['azimuth'] |
|
1870 | azimuth = kwargs['azimuth'] | |
1871 |
|
1871 | |||
1872 | if 'correctFactor' in kwargs: |
|
1872 | if 'correctFactor' in kwargs: | |
1873 | correctFactor = kwargs['correctFactor'] |
|
1873 | correctFactor = kwargs['correctFactor'] | |
1874 | else: |
|
1874 | else: | |
1875 | correctFactor = 1 |
|
1875 | correctFactor = 1 | |
1876 |
|
1876 | |||
1877 | groupList = kwargs['groupList'] |
|
1877 | groupList = kwargs['groupList'] | |
1878 | pairs_ccf = groupList[1] |
|
1878 | pairs_ccf = groupList[1] | |
1879 | tau = kwargs['tau'] |
|
1879 | tau = kwargs['tau'] | |
1880 | _lambda = kwargs['_lambda'] |
|
1880 | _lambda = kwargs['_lambda'] | |
1881 |
|
1881 | |||
1882 | #Cross Correlation pairs obtained |
|
1882 | #Cross Correlation pairs obtained | |
1883 | # pairsAutoCorr, pairsCrossCorr = self.__getPairsAutoCorr(pairssList, nChannels) |
|
1883 | # pairsAutoCorr, pairsCrossCorr = self.__getPairsAutoCorr(pairssList, nChannels) | |
1884 | # pairsArray = numpy.array(pairsList)[pairsCrossCorr] |
|
1884 | # pairsArray = numpy.array(pairsList)[pairsCrossCorr] | |
1885 | # pairsSelArray = numpy.array(pairsSelected) |
|
1885 | # pairsSelArray = numpy.array(pairsSelected) | |
1886 | # pairs = [] |
|
1886 | # pairs = [] | |
1887 | # |
|
1887 | # | |
1888 | # #Wind estimation pairs obtained |
|
1888 | # #Wind estimation pairs obtained | |
1889 | # for i in range(pairsSelArray.shape[0]/2): |
|
1889 | # for i in range(pairsSelArray.shape[0]/2): | |
1890 | # ind1 = numpy.where(numpy.all(pairsArray == pairsSelArray[2*i], axis = 1))[0][0] |
|
1890 | # ind1 = numpy.where(numpy.all(pairsArray == pairsSelArray[2*i], axis = 1))[0][0] | |
1891 | # ind2 = numpy.where(numpy.all(pairsArray == pairsSelArray[2*i + 1], axis = 1))[0][0] |
|
1891 | # ind2 = numpy.where(numpy.all(pairsArray == pairsSelArray[2*i + 1], axis = 1))[0][0] | |
1892 | # pairs.append((ind1,ind2)) |
|
1892 | # pairs.append((ind1,ind2)) | |
1893 |
|
1893 | |||
1894 | indtau = tau.shape[0]/2 |
|
1894 | indtau = tau.shape[0]/2 | |
1895 | tau1 = tau[:indtau,:] |
|
1895 | tau1 = tau[:indtau,:] | |
1896 | tau2 = tau[indtau:-1,:] |
|
1896 | tau2 = tau[indtau:-1,:] | |
1897 | # tau1 = tau1[pairs,:] |
|
1897 | # tau1 = tau1[pairs,:] | |
1898 | # tau2 = tau2[pairs,:] |
|
1898 | # tau2 = tau2[pairs,:] | |
1899 | phase1 = tau[-1,:] |
|
1899 | phase1 = tau[-1,:] | |
1900 |
|
1900 | |||
1901 | #--------------------------------------------------------------------- |
|
1901 | #--------------------------------------------------------------------- | |
1902 | #Metodo Directo |
|
1902 | #Metodo Directo | |
1903 | distx, disty, dist, ang = self.__calculateDistance(position_x, position_y, pairs_ccf,azimuth) |
|
1903 | distx, disty, dist, ang = self.__calculateDistance(position_x, position_y, pairs_ccf,azimuth) | |
1904 | winds = self.__calculateVelHorDir(dist, tau1, tau2, ang) |
|
1904 | winds = self.__calculateVelHorDir(dist, tau1, tau2, ang) | |
1905 | winds = stats.nanmean(winds, axis=0) |
|
1905 | winds = stats.nanmean(winds, axis=0) | |
1906 | #--------------------------------------------------------------------- |
|
1906 | #--------------------------------------------------------------------- | |
1907 | #Metodo General |
|
1907 | #Metodo General | |
1908 | # distx, disty, dist = self.calculateDistance(position_x,position_y,pairsCrossCorr, pairsList, azimuth) |
|
1908 | # distx, disty, dist = self.calculateDistance(position_x,position_y,pairsCrossCorr, pairsList, azimuth) | |
1909 | # #Calculo Coeficientes de Funcion de Correlacion |
|
1909 | # #Calculo Coeficientes de Funcion de Correlacion | |
1910 | # F,G,A,B,H = self.calculateCoef(tau1,tau2,distx,disty,n) |
|
1910 | # F,G,A,B,H = self.calculateCoef(tau1,tau2,distx,disty,n) | |
1911 | # #Calculo de Velocidades |
|
1911 | # #Calculo de Velocidades | |
1912 | # winds = self.calculateVelUV(F,G,A,B,H) |
|
1912 | # winds = self.calculateVelUV(F,G,A,B,H) | |
1913 |
|
1913 | |||
1914 | #--------------------------------------------------------------------- |
|
1914 | #--------------------------------------------------------------------- | |
1915 | winds[2,:] = self.__calculateVelVer(phase1, lagTRange, _lambda) |
|
1915 | winds[2,:] = self.__calculateVelVer(phase1, lagTRange, _lambda) | |
1916 | winds = correctFactor*winds |
|
1916 | winds = correctFactor*winds | |
1917 | return winds |
|
1917 | return winds | |
1918 |
|
1918 | |||
1919 | def __checkTime(self, currentTime, paramInterval, outputInterval): |
|
1919 | def __checkTime(self, currentTime, paramInterval, outputInterval): | |
1920 |
|
1920 | |||
1921 | dataTime = currentTime + paramInterval |
|
1921 | dataTime = currentTime + paramInterval | |
1922 | deltaTime = dataTime - self.__initime |
|
1922 | deltaTime = dataTime - self.__initime | |
1923 |
|
1923 | |||
1924 | if deltaTime >= outputInterval or deltaTime < 0: |
|
1924 | if deltaTime >= outputInterval or deltaTime < 0: | |
1925 | self.__dataReady = True |
|
1925 | self.__dataReady = True | |
1926 | return |
|
1926 | return | |
1927 |
|
1927 | |||
1928 | def techniqueMeteors(self, arrayMeteor, meteorThresh, heightMin, heightMax): |
|
1928 | def techniqueMeteors(self, arrayMeteor, meteorThresh, heightMin, heightMax): | |
1929 | ''' |
|
1929 | ''' | |
1930 | Function that implements winds estimation technique with detected meteors. |
|
1930 | Function that implements winds estimation technique with detected meteors. | |
1931 |
|
1931 | |||
1932 | Input: Detected meteors, Minimum meteor quantity to wind estimation |
|
1932 | Input: Detected meteors, Minimum meteor quantity to wind estimation | |
1933 |
|
1933 | |||
1934 | Output: Winds estimation (Zonal and Meridional) |
|
1934 | Output: Winds estimation (Zonal and Meridional) | |
1935 |
|
1935 | |||
1936 | Parameters affected: Winds |
|
1936 | Parameters affected: Winds | |
1937 | ''' |
|
1937 | ''' | |
1938 | #Settings |
|
1938 | #Settings | |
1939 | nInt = (heightMax - heightMin)/2 |
|
1939 | nInt = (heightMax - heightMin)/2 | |
1940 | nInt = int(nInt) |
|
1940 | nInt = int(nInt) | |
1941 | winds = numpy.zeros((2,nInt))*numpy.nan |
|
1941 | winds = numpy.zeros((2,nInt))*numpy.nan | |
1942 |
|
1942 | |||
1943 | #Filter errors |
|
1943 | #Filter errors | |
1944 | error = numpy.where(arrayMeteor[:,-1] == 0)[0] |
|
1944 | error = numpy.where(arrayMeteor[:,-1] == 0)[0] | |
1945 | finalMeteor = arrayMeteor[error,:] |
|
1945 | finalMeteor = arrayMeteor[error,:] | |
1946 |
|
1946 | |||
1947 | #Meteor Histogram |
|
1947 | #Meteor Histogram | |
1948 | finalHeights = finalMeteor[:,2] |
|
1948 | finalHeights = finalMeteor[:,2] | |
1949 | hist = numpy.histogram(finalHeights, bins = nInt, range = (heightMin,heightMax)) |
|
1949 | hist = numpy.histogram(finalHeights, bins = nInt, range = (heightMin,heightMax)) | |
1950 | nMeteorsPerI = hist[0] |
|
1950 | nMeteorsPerI = hist[0] | |
1951 | heightPerI = hist[1] |
|
1951 | heightPerI = hist[1] | |
1952 |
|
1952 | |||
1953 | #Sort of meteors |
|
1953 | #Sort of meteors | |
1954 | indSort = finalHeights.argsort() |
|
1954 | indSort = finalHeights.argsort() | |
1955 | finalMeteor2 = finalMeteor[indSort,:] |
|
1955 | finalMeteor2 = finalMeteor[indSort,:] | |
1956 |
|
1956 | |||
1957 | # Calculating winds |
|
1957 | # Calculating winds | |
1958 | ind1 = 0 |
|
1958 | ind1 = 0 | |
1959 | ind2 = 0 |
|
1959 | ind2 = 0 | |
1960 |
|
1960 | |||
1961 | for i in range(nInt): |
|
1961 | for i in range(nInt): | |
1962 | nMet = nMeteorsPerI[i] |
|
1962 | nMet = nMeteorsPerI[i] | |
1963 | ind1 = ind2 |
|
1963 | ind1 = ind2 | |
1964 | ind2 = ind1 + nMet |
|
1964 | ind2 = ind1 + nMet | |
1965 |
|
1965 | |||
1966 | meteorAux = finalMeteor2[ind1:ind2,:] |
|
1966 | meteorAux = finalMeteor2[ind1:ind2,:] | |
1967 |
|
1967 | |||
1968 | if meteorAux.shape[0] >= meteorThresh: |
|
1968 | if meteorAux.shape[0] >= meteorThresh: | |
1969 | vel = meteorAux[:, 6] |
|
1969 | vel = meteorAux[:, 6] | |
1970 | zen = meteorAux[:, 4]*numpy.pi/180 |
|
1970 | zen = meteorAux[:, 4]*numpy.pi/180 | |
1971 | azim = meteorAux[:, 3]*numpy.pi/180 |
|
1971 | azim = meteorAux[:, 3]*numpy.pi/180 | |
1972 |
|
1972 | |||
1973 | n = numpy.cos(zen) |
|
1973 | n = numpy.cos(zen) | |
1974 | # m = (1 - n**2)/(1 - numpy.tan(azim)**2) |
|
1974 | # m = (1 - n**2)/(1 - numpy.tan(azim)**2) | |
1975 | # l = m*numpy.tan(azim) |
|
1975 | # l = m*numpy.tan(azim) | |
1976 | l = numpy.sin(zen)*numpy.sin(azim) |
|
1976 | l = numpy.sin(zen)*numpy.sin(azim) | |
1977 | m = numpy.sin(zen)*numpy.cos(azim) |
|
1977 | m = numpy.sin(zen)*numpy.cos(azim) | |
1978 |
|
1978 | |||
1979 | A = numpy.vstack((l, m)).transpose() |
|
1979 | A = numpy.vstack((l, m)).transpose() | |
1980 | A1 = numpy.dot(numpy.linalg.inv( numpy.dot(A.transpose(),A) ),A.transpose()) |
|
1980 | A1 = numpy.dot(numpy.linalg.inv( numpy.dot(A.transpose(),A) ),A.transpose()) | |
1981 | windsAux = numpy.dot(A1, vel) |
|
1981 | windsAux = numpy.dot(A1, vel) | |
1982 |
|
1982 | |||
1983 | winds[0,i] = windsAux[0] |
|
1983 | winds[0,i] = windsAux[0] | |
1984 | winds[1,i] = windsAux[1] |
|
1984 | winds[1,i] = windsAux[1] | |
1985 |
|
1985 | |||
1986 | return winds, heightPerI[:-1] |
|
1986 | return winds, heightPerI[:-1] | |
1987 |
|
1987 | |||
1988 | def techniqueNSM_SA(self, **kwargs): |
|
1988 | def techniqueNSM_SA(self, **kwargs): | |
1989 | metArray = kwargs['metArray'] |
|
1989 | metArray = kwargs['metArray'] | |
1990 | heightList = kwargs['heightList'] |
|
1990 | heightList = kwargs['heightList'] | |
1991 | timeList = kwargs['timeList'] |
|
1991 | timeList = kwargs['timeList'] | |
1992 |
|
1992 | |||
1993 | rx_location = kwargs['rx_location'] |
|
1993 | rx_location = kwargs['rx_location'] | |
1994 | groupList = kwargs['groupList'] |
|
1994 | groupList = kwargs['groupList'] | |
1995 | azimuth = kwargs['azimuth'] |
|
1995 | azimuth = kwargs['azimuth'] | |
1996 | dfactor = kwargs['dfactor'] |
|
1996 | dfactor = kwargs['dfactor'] | |
1997 | k = kwargs['k'] |
|
1997 | k = kwargs['k'] | |
1998 |
|
1998 | |||
1999 | azimuth1, dist = self.__calculateAzimuth1(rx_location, groupList, azimuth) |
|
1999 | azimuth1, dist = self.__calculateAzimuth1(rx_location, groupList, azimuth) | |
2000 | d = dist*dfactor |
|
2000 | d = dist*dfactor | |
2001 | #Phase calculation |
|
2001 | #Phase calculation | |
2002 | metArray1 = self.__getPhaseSlope(metArray, heightList, timeList) |
|
2002 | metArray1 = self.__getPhaseSlope(metArray, heightList, timeList) | |
2003 |
|
2003 | |||
2004 | metArray1[:,-2] = metArray1[:,-2]*metArray1[:,2]*1000/(k*d[metArray1[:,1].astype(int)]) #angles into velocities |
|
2004 | metArray1[:,-2] = metArray1[:,-2]*metArray1[:,2]*1000/(k*d[metArray1[:,1].astype(int)]) #angles into velocities | |
2005 |
|
2005 | |||
2006 | velEst = numpy.zeros((heightList.size,2))*numpy.nan |
|
2006 | velEst = numpy.zeros((heightList.size,2))*numpy.nan | |
2007 | azimuth1 = azimuth1*numpy.pi/180 |
|
2007 | azimuth1 = azimuth1*numpy.pi/180 | |
2008 |
|
2008 | |||
2009 | for i in range(heightList.size): |
|
2009 | for i in range(heightList.size): | |
2010 | h = heightList[i] |
|
2010 | h = heightList[i] | |
2011 | indH = numpy.where((metArray1[:,2] == h)&(numpy.abs(metArray1[:,-2]) < 100))[0] |
|
2011 | indH = numpy.where((metArray1[:,2] == h)&(numpy.abs(metArray1[:,-2]) < 100))[0] | |
2012 | metHeight = metArray1[indH,:] |
|
2012 | metHeight = metArray1[indH,:] | |
2013 | if metHeight.shape[0] >= 2: |
|
2013 | if metHeight.shape[0] >= 2: | |
2014 | velAux = numpy.asmatrix(metHeight[:,-2]).T #Radial Velocities |
|
2014 | velAux = numpy.asmatrix(metHeight[:,-2]).T #Radial Velocities | |
2015 | iazim = metHeight[:,1].astype(int) |
|
2015 | iazim = metHeight[:,1].astype(int) | |
2016 | azimAux = numpy.asmatrix(azimuth1[iazim]).T #Azimuths |
|
2016 | azimAux = numpy.asmatrix(azimuth1[iazim]).T #Azimuths | |
2017 | A = numpy.hstack((numpy.cos(azimAux),numpy.sin(azimAux))) |
|
2017 | A = numpy.hstack((numpy.cos(azimAux),numpy.sin(azimAux))) | |
2018 | A = numpy.asmatrix(A) |
|
2018 | A = numpy.asmatrix(A) | |
2019 | A1 = numpy.linalg.pinv(A.transpose()*A)*A.transpose() |
|
2019 | A1 = numpy.linalg.pinv(A.transpose()*A)*A.transpose() | |
2020 | velHor = numpy.dot(A1,velAux) |
|
2020 | velHor = numpy.dot(A1,velAux) | |
2021 |
|
2021 | |||
2022 | velEst[i,:] = numpy.squeeze(velHor) |
|
2022 | velEst[i,:] = numpy.squeeze(velHor) | |
2023 | return velEst |
|
2023 | return velEst | |
2024 |
|
2024 | |||
2025 | def __getPhaseSlope(self, metArray, heightList, timeList): |
|
2025 | def __getPhaseSlope(self, metArray, heightList, timeList): | |
2026 | meteorList = [] |
|
2026 | meteorList = [] | |
2027 | #utctime sec1 height SNR velRad ph0 ph1 ph2 coh0 coh1 coh2 |
|
2027 | #utctime sec1 height SNR velRad ph0 ph1 ph2 coh0 coh1 coh2 | |
2028 | #Putting back together the meteor matrix |
|
2028 | #Putting back together the meteor matrix | |
2029 | utctime = metArray[:,0] |
|
2029 | utctime = metArray[:,0] | |
2030 | uniqueTime = numpy.unique(utctime) |
|
2030 | uniqueTime = numpy.unique(utctime) | |
2031 |
|
2031 | |||
2032 | phaseDerThresh = 0.5 |
|
2032 | phaseDerThresh = 0.5 | |
2033 | ippSeconds = timeList[1] - timeList[0] |
|
2033 | ippSeconds = timeList[1] - timeList[0] | |
2034 | sec = numpy.where(timeList>1)[0][0] |
|
2034 | sec = numpy.where(timeList>1)[0][0] | |
2035 | nPairs = metArray.shape[1] - 6 |
|
2035 | nPairs = metArray.shape[1] - 6 | |
2036 | nHeights = len(heightList) |
|
2036 | nHeights = len(heightList) | |
2037 |
|
2037 | |||
2038 | for t in uniqueTime: |
|
2038 | for t in uniqueTime: | |
2039 | metArray1 = metArray[utctime==t,:] |
|
2039 | metArray1 = metArray[utctime==t,:] | |
2040 | # phaseDerThresh = numpy.pi/4 #reducir Phase thresh |
|
2040 | # phaseDerThresh = numpy.pi/4 #reducir Phase thresh | |
2041 | tmet = metArray1[:,1].astype(int) |
|
2041 | tmet = metArray1[:,1].astype(int) | |
2042 | hmet = metArray1[:,2].astype(int) |
|
2042 | hmet = metArray1[:,2].astype(int) | |
2043 |
|
2043 | |||
2044 | metPhase = numpy.zeros((nPairs, heightList.size, timeList.size - 1)) |
|
2044 | metPhase = numpy.zeros((nPairs, heightList.size, timeList.size - 1)) | |
2045 | metPhase[:,:] = numpy.nan |
|
2045 | metPhase[:,:] = numpy.nan | |
2046 | metPhase[:,hmet,tmet] = metArray1[:,6:].T |
|
2046 | metPhase[:,hmet,tmet] = metArray1[:,6:].T | |
2047 |
|
2047 | |||
2048 | #Delete short trails |
|
2048 | #Delete short trails | |
2049 | metBool = ~numpy.isnan(metPhase[0,:,:]) |
|
2049 | metBool = ~numpy.isnan(metPhase[0,:,:]) | |
2050 | heightVect = numpy.sum(metBool, axis = 1) |
|
2050 | heightVect = numpy.sum(metBool, axis = 1) | |
2051 | metBool[heightVect<sec,:] = False |
|
2051 | metBool[heightVect<sec,:] = False | |
2052 | metPhase[:,heightVect<sec,:] = numpy.nan |
|
2052 | metPhase[:,heightVect<sec,:] = numpy.nan | |
2053 |
|
2053 | |||
2054 | #Derivative |
|
2054 | #Derivative | |
2055 | metDer = numpy.abs(metPhase[:,:,1:] - metPhase[:,:,:-1]) |
|
2055 | metDer = numpy.abs(metPhase[:,:,1:] - metPhase[:,:,:-1]) | |
2056 | phDerAux = numpy.dstack((numpy.full((nPairs,nHeights,1), False, dtype=bool),metDer > phaseDerThresh)) |
|
2056 | phDerAux = numpy.dstack((numpy.full((nPairs,nHeights,1), False, dtype=bool),metDer > phaseDerThresh)) | |
2057 | metPhase[phDerAux] = numpy.nan |
|
2057 | metPhase[phDerAux] = numpy.nan | |
2058 |
|
2058 | |||
2059 | #--------------------------METEOR DETECTION ----------------------------------------- |
|
2059 | #--------------------------METEOR DETECTION ----------------------------------------- | |
2060 | indMet = numpy.where(numpy.any(metBool,axis=1))[0] |
|
2060 | indMet = numpy.where(numpy.any(metBool,axis=1))[0] | |
2061 |
|
2061 | |||
2062 | for p in numpy.arange(nPairs): |
|
2062 | for p in numpy.arange(nPairs): | |
2063 | phase = metPhase[p,:,:] |
|
2063 | phase = metPhase[p,:,:] | |
2064 | phDer = metDer[p,:,:] |
|
2064 | phDer = metDer[p,:,:] | |
2065 |
|
2065 | |||
2066 | for h in indMet: |
|
2066 | for h in indMet: | |
2067 | height = heightList[h] |
|
2067 | height = heightList[h] | |
2068 | phase1 = phase[h,:] #82 |
|
2068 | phase1 = phase[h,:] #82 | |
2069 | phDer1 = phDer[h,:] |
|
2069 | phDer1 = phDer[h,:] | |
2070 |
|
2070 | |||
2071 | phase1[~numpy.isnan(phase1)] = numpy.unwrap(phase1[~numpy.isnan(phase1)]) #Unwrap |
|
2071 | phase1[~numpy.isnan(phase1)] = numpy.unwrap(phase1[~numpy.isnan(phase1)]) #Unwrap | |
2072 |
|
2072 | |||
2073 | indValid = numpy.where(~numpy.isnan(phase1))[0] |
|
2073 | indValid = numpy.where(~numpy.isnan(phase1))[0] | |
2074 | initMet = indValid[0] |
|
2074 | initMet = indValid[0] | |
2075 | endMet = 0 |
|
2075 | endMet = 0 | |
2076 |
|
2076 | |||
2077 | for i in range(len(indValid)-1): |
|
2077 | for i in range(len(indValid)-1): | |
2078 |
|
2078 | |||
2079 | #Time difference |
|
2079 | #Time difference | |
2080 | inow = indValid[i] |
|
2080 | inow = indValid[i] | |
2081 | inext = indValid[i+1] |
|
2081 | inext = indValid[i+1] | |
2082 | idiff = inext - inow |
|
2082 | idiff = inext - inow | |
2083 | #Phase difference |
|
2083 | #Phase difference | |
2084 | phDiff = numpy.abs(phase1[inext] - phase1[inow]) |
|
2084 | phDiff = numpy.abs(phase1[inext] - phase1[inow]) | |
2085 |
|
2085 | |||
2086 | if idiff>sec or phDiff>numpy.pi/4 or inext==indValid[-1]: #End of Meteor |
|
2086 | if idiff>sec or phDiff>numpy.pi/4 or inext==indValid[-1]: #End of Meteor | |
2087 | sizeTrail = inow - initMet + 1 |
|
2087 | sizeTrail = inow - initMet + 1 | |
2088 | if sizeTrail>3*sec: #Too short meteors |
|
2088 | if sizeTrail>3*sec: #Too short meteors | |
2089 | x = numpy.arange(initMet,inow+1)*ippSeconds |
|
2089 | x = numpy.arange(initMet,inow+1)*ippSeconds | |
2090 | y = phase1[initMet:inow+1] |
|
2090 | y = phase1[initMet:inow+1] | |
2091 | ynnan = ~numpy.isnan(y) |
|
2091 | ynnan = ~numpy.isnan(y) | |
2092 | x = x[ynnan] |
|
2092 | x = x[ynnan] | |
2093 | y = y[ynnan] |
|
2093 | y = y[ynnan] | |
2094 | slope, intercept, r_value, p_value, std_err = stats.linregress(x,y) |
|
2094 | slope, intercept, r_value, p_value, std_err = stats.linregress(x,y) | |
2095 | ylin = x*slope + intercept |
|
2095 | ylin = x*slope + intercept | |
2096 | rsq = r_value**2 |
|
2096 | rsq = r_value**2 | |
2097 | if rsq > 0.5: |
|
2097 | if rsq > 0.5: | |
2098 | vel = slope#*height*1000/(k*d) |
|
2098 | vel = slope#*height*1000/(k*d) | |
2099 | estAux = numpy.array([utctime,p,height, vel, rsq]) |
|
2099 | estAux = numpy.array([utctime,p,height, vel, rsq]) | |
2100 | meteorList.append(estAux) |
|
2100 | meteorList.append(estAux) | |
2101 | initMet = inext |
|
2101 | initMet = inext | |
2102 | metArray2 = numpy.array(meteorList) |
|
2102 | metArray2 = numpy.array(meteorList) | |
2103 |
|
2103 | |||
2104 | return metArray2 |
|
2104 | return metArray2 | |
2105 |
|
2105 | |||
2106 | def __calculateAzimuth1(self, rx_location, pairslist, azimuth0): |
|
2106 | def __calculateAzimuth1(self, rx_location, pairslist, azimuth0): | |
2107 |
|
2107 | |||
2108 | azimuth1 = numpy.zeros(len(pairslist)) |
|
2108 | azimuth1 = numpy.zeros(len(pairslist)) | |
2109 | dist = numpy.zeros(len(pairslist)) |
|
2109 | dist = numpy.zeros(len(pairslist)) | |
2110 |
|
2110 | |||
2111 | for i in range(len(rx_location)): |
|
2111 | for i in range(len(rx_location)): | |
2112 | ch0 = pairslist[i][0] |
|
2112 | ch0 = pairslist[i][0] | |
2113 | ch1 = pairslist[i][1] |
|
2113 | ch1 = pairslist[i][1] | |
2114 |
|
2114 | |||
2115 | diffX = rx_location[ch0][0] - rx_location[ch1][0] |
|
2115 | diffX = rx_location[ch0][0] - rx_location[ch1][0] | |
2116 | diffY = rx_location[ch0][1] - rx_location[ch1][1] |
|
2116 | diffY = rx_location[ch0][1] - rx_location[ch1][1] | |
2117 | azimuth1[i] = numpy.arctan2(diffY,diffX)*180/numpy.pi |
|
2117 | azimuth1[i] = numpy.arctan2(diffY,diffX)*180/numpy.pi | |
2118 | dist[i] = numpy.sqrt(diffX**2 + diffY**2) |
|
2118 | dist[i] = numpy.sqrt(diffX**2 + diffY**2) | |
2119 |
|
2119 | |||
2120 | azimuth1 -= azimuth0 |
|
2120 | azimuth1 -= azimuth0 | |
2121 | return azimuth1, dist |
|
2121 | return azimuth1, dist | |
2122 |
|
2122 | |||
2123 | def techniqueNSM_DBS(self, **kwargs): |
|
2123 | def techniqueNSM_DBS(self, **kwargs): | |
2124 | metArray = kwargs['metArray'] |
|
2124 | metArray = kwargs['metArray'] | |
2125 | heightList = kwargs['heightList'] |
|
2125 | heightList = kwargs['heightList'] | |
2126 | timeList = kwargs['timeList'] |
|
2126 | timeList = kwargs['timeList'] | |
2127 | azimuth = kwargs['azimuth'] |
|
2127 | azimuth = kwargs['azimuth'] | |
2128 | theta_x = numpy.array(kwargs['theta_x']) |
|
2128 | theta_x = numpy.array(kwargs['theta_x']) | |
2129 | theta_y = numpy.array(kwargs['theta_y']) |
|
2129 | theta_y = numpy.array(kwargs['theta_y']) | |
2130 |
|
2130 | |||
2131 | utctime = metArray[:,0] |
|
2131 | utctime = metArray[:,0] | |
2132 | cmet = metArray[:,1].astype(int) |
|
2132 | cmet = metArray[:,1].astype(int) | |
2133 | hmet = metArray[:,3].astype(int) |
|
2133 | hmet = metArray[:,3].astype(int) | |
2134 | SNRmet = metArray[:,4] |
|
2134 | SNRmet = metArray[:,4] | |
2135 | vmet = metArray[:,5] |
|
2135 | vmet = metArray[:,5] | |
2136 | spcmet = metArray[:,6] |
|
2136 | spcmet = metArray[:,6] | |
2137 |
|
2137 | |||
2138 | nChan = numpy.max(cmet) + 1 |
|
2138 | nChan = numpy.max(cmet) + 1 | |
2139 | nHeights = len(heightList) |
|
2139 | nHeights = len(heightList) | |
2140 |
|
2140 | |||
2141 | azimuth_arr, zenith_arr, dir_cosu, dir_cosv, dir_cosw = self.__calculateAngles(theta_x, theta_y, azimuth) |
|
2141 | azimuth_arr, zenith_arr, dir_cosu, dir_cosv, dir_cosw = self.__calculateAngles(theta_x, theta_y, azimuth) | |
2142 | hmet = heightList[hmet] |
|
2142 | hmet = heightList[hmet] | |
2143 | h1met = hmet*numpy.cos(zenith_arr[cmet]) #Corrected heights |
|
2143 | h1met = hmet*numpy.cos(zenith_arr[cmet]) #Corrected heights | |
2144 |
|
2144 | |||
2145 | velEst = numpy.zeros((heightList.size,2))*numpy.nan |
|
2145 | velEst = numpy.zeros((heightList.size,2))*numpy.nan | |
2146 |
|
2146 | |||
2147 | for i in range(nHeights - 1): |
|
2147 | for i in range(nHeights - 1): | |
2148 | hmin = heightList[i] |
|
2148 | hmin = heightList[i] | |
2149 | hmax = heightList[i + 1] |
|
2149 | hmax = heightList[i + 1] | |
2150 |
|
2150 | |||
2151 | thisH = (h1met>=hmin) & (h1met<hmax) & (cmet!=2) & (SNRmet>8) & (vmet<50) & (spcmet<10) |
|
2151 | thisH = (h1met>=hmin) & (h1met<hmax) & (cmet!=2) & (SNRmet>8) & (vmet<50) & (spcmet<10) | |
2152 | indthisH = numpy.where(thisH) |
|
2152 | indthisH = numpy.where(thisH) | |
2153 |
|
2153 | |||
2154 | if numpy.size(indthisH) > 3: |
|
2154 | if numpy.size(indthisH) > 3: | |
2155 |
|
2155 | |||
2156 | vel_aux = vmet[thisH] |
|
2156 | vel_aux = vmet[thisH] | |
2157 | chan_aux = cmet[thisH] |
|
2157 | chan_aux = cmet[thisH] | |
2158 | cosu_aux = dir_cosu[chan_aux] |
|
2158 | cosu_aux = dir_cosu[chan_aux] | |
2159 | cosv_aux = dir_cosv[chan_aux] |
|
2159 | cosv_aux = dir_cosv[chan_aux] | |
2160 | cosw_aux = dir_cosw[chan_aux] |
|
2160 | cosw_aux = dir_cosw[chan_aux] | |
2161 |
|
2161 | |||
2162 | nch = numpy.size(numpy.unique(chan_aux)) |
|
2162 | nch = numpy.size(numpy.unique(chan_aux)) | |
2163 | if nch > 1: |
|
2163 | if nch > 1: | |
2164 | A = self.__calculateMatA(cosu_aux, cosv_aux, cosw_aux, True) |
|
2164 | A = self.__calculateMatA(cosu_aux, cosv_aux, cosw_aux, True) | |
2165 | velEst[i,:] = numpy.dot(A,vel_aux) |
|
2165 | velEst[i,:] = numpy.dot(A,vel_aux) | |
2166 |
|
2166 | |||
2167 | return velEst |
|
2167 | return velEst | |
2168 |
|
2168 | |||
2169 | def run(self, dataOut, technique, nHours=1, hmin=70, hmax=110, **kwargs): |
|
2169 | def run(self, dataOut, technique, nHours=1, hmin=70, hmax=110, **kwargs): | |
2170 |
|
2170 | |||
2171 | param = dataOut.data_param |
|
2171 | param = dataOut.data_param | |
2172 | if dataOut.abscissaList != None: |
|
2172 | if dataOut.abscissaList != None: | |
2173 | absc = dataOut.abscissaList[:-1] |
|
2173 | absc = dataOut.abscissaList[:-1] | |
2174 | # noise = dataOut.noise |
|
2174 | # noise = dataOut.noise | |
2175 | heightList = dataOut.heightList |
|
2175 | heightList = dataOut.heightList | |
2176 | SNR = dataOut.data_snr |
|
2176 | SNR = dataOut.data_snr | |
2177 |
|
2177 | |||
2178 | if technique == 'DBS': |
|
2178 | if technique == 'DBS': | |
2179 |
|
2179 | |||
2180 | kwargs['velRadial'] = param[:,1,:] #Radial velocity |
|
2180 | kwargs['velRadial'] = param[:,1,:] #Radial velocity | |
2181 | kwargs['heightList'] = heightList |
|
2181 | kwargs['heightList'] = heightList | |
2182 | kwargs['SNR'] = SNR |
|
2182 | kwargs['SNR'] = SNR | |
2183 |
|
2183 | |||
2184 | dataOut.data_output, dataOut.heightList, dataOut.data_snr = self.techniqueDBS(kwargs) #DBS Function |
|
2184 | dataOut.data_output, dataOut.heightList, dataOut.data_snr = self.techniqueDBS(kwargs) #DBS Function | |
2185 | dataOut.utctimeInit = dataOut.utctime |
|
2185 | dataOut.utctimeInit = dataOut.utctime | |
2186 | dataOut.outputInterval = dataOut.paramInterval |
|
2186 | dataOut.outputInterval = dataOut.paramInterval | |
2187 |
|
2187 | |||
2188 | elif technique == 'SA': |
|
2188 | elif technique == 'SA': | |
2189 |
|
2189 | |||
2190 | #Parameters |
|
2190 | #Parameters | |
2191 | # position_x = kwargs['positionX'] |
|
2191 | # position_x = kwargs['positionX'] | |
2192 | # position_y = kwargs['positionY'] |
|
2192 | # position_y = kwargs['positionY'] | |
2193 | # azimuth = kwargs['azimuth'] |
|
2193 | # azimuth = kwargs['azimuth'] | |
2194 | # |
|
2194 | # | |
2195 | # if kwargs.has_key('crosspairsList'): |
|
2195 | # if kwargs.has_key('crosspairsList'): | |
2196 | # pairs = kwargs['crosspairsList'] |
|
2196 | # pairs = kwargs['crosspairsList'] | |
2197 | # else: |
|
2197 | # else: | |
2198 | # pairs = None |
|
2198 | # pairs = None | |
2199 | # |
|
2199 | # | |
2200 | # if kwargs.has_key('correctFactor'): |
|
2200 | # if kwargs.has_key('correctFactor'): | |
2201 | # correctFactor = kwargs['correctFactor'] |
|
2201 | # correctFactor = kwargs['correctFactor'] | |
2202 | # else: |
|
2202 | # else: | |
2203 | # correctFactor = 1 |
|
2203 | # correctFactor = 1 | |
2204 |
|
2204 | |||
2205 | # tau = dataOut.data_param |
|
2205 | # tau = dataOut.data_param | |
2206 | # _lambda = dataOut.C/dataOut.frequency |
|
2206 | # _lambda = dataOut.C/dataOut.frequency | |
2207 | # pairsList = dataOut.groupList |
|
2207 | # pairsList = dataOut.groupList | |
2208 | # nChannels = dataOut.nChannels |
|
2208 | # nChannels = dataOut.nChannels | |
2209 |
|
2209 | |||
2210 | kwargs['groupList'] = dataOut.groupList |
|
2210 | kwargs['groupList'] = dataOut.groupList | |
2211 | kwargs['tau'] = dataOut.data_param |
|
2211 | kwargs['tau'] = dataOut.data_param | |
2212 | kwargs['_lambda'] = dataOut.C/dataOut.frequency |
|
2212 | kwargs['_lambda'] = dataOut.C/dataOut.frequency | |
2213 | # dataOut.data_output = self.techniqueSA(pairs, pairsList, nChannels, tau, azimuth, _lambda, position_x, position_y, absc, correctFactor) |
|
2213 | # dataOut.data_output = self.techniqueSA(pairs, pairsList, nChannels, tau, azimuth, _lambda, position_x, position_y, absc, correctFactor) | |
2214 | dataOut.data_output = self.techniqueSA(kwargs) |
|
2214 | dataOut.data_output = self.techniqueSA(kwargs) | |
2215 | dataOut.utctimeInit = dataOut.utctime |
|
2215 | dataOut.utctimeInit = dataOut.utctime | |
2216 | dataOut.outputInterval = dataOut.timeInterval |
|
2216 | dataOut.outputInterval = dataOut.timeInterval | |
2217 |
|
2217 | |||
2218 | elif technique == 'Meteors': |
|
2218 | elif technique == 'Meteors': | |
2219 | dataOut.flagNoData = True |
|
2219 | dataOut.flagNoData = True | |
2220 | self.__dataReady = False |
|
2220 | self.__dataReady = False | |
2221 |
|
2221 | |||
2222 | if 'nHours' in kwargs: |
|
2222 | if 'nHours' in kwargs: | |
2223 | nHours = kwargs['nHours'] |
|
2223 | nHours = kwargs['nHours'] | |
2224 | else: |
|
2224 | else: | |
2225 | nHours = 1 |
|
2225 | nHours = 1 | |
2226 |
|
2226 | |||
2227 | if 'meteorsPerBin' in kwargs: |
|
2227 | if 'meteorsPerBin' in kwargs: | |
2228 | meteorThresh = kwargs['meteorsPerBin'] |
|
2228 | meteorThresh = kwargs['meteorsPerBin'] | |
2229 | else: |
|
2229 | else: | |
2230 | meteorThresh = 6 |
|
2230 | meteorThresh = 6 | |
2231 |
|
2231 | |||
2232 | if 'hmin' in kwargs: |
|
2232 | if 'hmin' in kwargs: | |
2233 | hmin = kwargs['hmin'] |
|
2233 | hmin = kwargs['hmin'] | |
2234 | else: hmin = 70 |
|
2234 | else: hmin = 70 | |
2235 | if 'hmax' in kwargs: |
|
2235 | if 'hmax' in kwargs: | |
2236 | hmax = kwargs['hmax'] |
|
2236 | hmax = kwargs['hmax'] | |
2237 | else: hmax = 110 |
|
2237 | else: hmax = 110 | |
2238 |
|
2238 | |||
2239 | dataOut.outputInterval = nHours*3600 |
|
2239 | dataOut.outputInterval = nHours*3600 | |
2240 |
|
2240 | |||
2241 | if self.__isConfig == False: |
|
2241 | if self.__isConfig == False: | |
2242 | # self.__initime = dataOut.datatime.replace(minute = 0, second = 0, microsecond = 03) |
|
2242 | # self.__initime = dataOut.datatime.replace(minute = 0, second = 0, microsecond = 03) | |
2243 | #Get Initial LTC time |
|
2243 | #Get Initial LTC time | |
2244 | self.__initime = datetime.datetime.utcfromtimestamp(dataOut.utctime) |
|
2244 | self.__initime = datetime.datetime.utcfromtimestamp(dataOut.utctime) | |
2245 | self.__initime = (self.__initime.replace(minute = 0, second = 0, microsecond = 0) - datetime.datetime(1970, 1, 1)).total_seconds() |
|
2245 | self.__initime = (self.__initime.replace(minute = 0, second = 0, microsecond = 0) - datetime.datetime(1970, 1, 1)).total_seconds() | |
2246 |
|
2246 | |||
2247 | self.__isConfig = True |
|
2247 | self.__isConfig = True | |
2248 |
|
2248 | |||
2249 | if self.__buffer is None: |
|
2249 | if self.__buffer is None: | |
2250 | self.__buffer = dataOut.data_param |
|
2250 | self.__buffer = dataOut.data_param | |
2251 | self.__firstdata = copy.copy(dataOut) |
|
2251 | self.__firstdata = copy.copy(dataOut) | |
2252 |
|
2252 | |||
2253 | else: |
|
2253 | else: | |
2254 | self.__buffer = numpy.vstack((self.__buffer, dataOut.data_param)) |
|
2254 | self.__buffer = numpy.vstack((self.__buffer, dataOut.data_param)) | |
2255 |
|
2255 | |||
2256 | self.__checkTime(dataOut.utctime, dataOut.paramInterval, dataOut.outputInterval) #Check if the buffer is ready |
|
2256 | self.__checkTime(dataOut.utctime, dataOut.paramInterval, dataOut.outputInterval) #Check if the buffer is ready | |
2257 |
|
2257 | |||
2258 | if self.__dataReady: |
|
2258 | if self.__dataReady: | |
2259 | dataOut.utctimeInit = self.__initime |
|
2259 | dataOut.utctimeInit = self.__initime | |
2260 |
|
2260 | |||
2261 | self.__initime += dataOut.outputInterval #to erase time offset |
|
2261 | self.__initime += dataOut.outputInterval #to erase time offset | |
2262 |
|
2262 | |||
2263 | dataOut.data_output, dataOut.heightList = self.techniqueMeteors(self.__buffer, meteorThresh, hmin, hmax) |
|
2263 | dataOut.data_output, dataOut.heightList = self.techniqueMeteors(self.__buffer, meteorThresh, hmin, hmax) | |
2264 | dataOut.flagNoData = False |
|
2264 | dataOut.flagNoData = False | |
2265 | self.__buffer = None |
|
2265 | self.__buffer = None | |
2266 |
|
2266 | |||
2267 | elif technique == 'Meteors1': |
|
2267 | elif technique == 'Meteors1': | |
2268 | dataOut.flagNoData = True |
|
2268 | dataOut.flagNoData = True | |
2269 | self.__dataReady = False |
|
2269 | self.__dataReady = False | |
2270 |
|
2270 | |||
2271 | if 'nMins' in kwargs: |
|
2271 | if 'nMins' in kwargs: | |
2272 | nMins = kwargs['nMins'] |
|
2272 | nMins = kwargs['nMins'] | |
2273 | else: nMins = 20 |
|
2273 | else: nMins = 20 | |
2274 | if 'rx_location' in kwargs: |
|
2274 | if 'rx_location' in kwargs: | |
2275 | rx_location = kwargs['rx_location'] |
|
2275 | rx_location = kwargs['rx_location'] | |
2276 | else: rx_location = [(0,1),(1,1),(1,0)] |
|
2276 | else: rx_location = [(0,1),(1,1),(1,0)] | |
2277 | if 'azimuth' in kwargs: |
|
2277 | if 'azimuth' in kwargs: | |
2278 | azimuth = kwargs['azimuth'] |
|
2278 | azimuth = kwargs['azimuth'] | |
2279 | else: azimuth = 51.06 |
|
2279 | else: azimuth = 51.06 | |
2280 | if 'dfactor' in kwargs: |
|
2280 | if 'dfactor' in kwargs: | |
2281 | dfactor = kwargs['dfactor'] |
|
2281 | dfactor = kwargs['dfactor'] | |
2282 | if 'mode' in kwargs: |
|
2282 | if 'mode' in kwargs: | |
2283 | mode = kwargs['mode'] |
|
2283 | mode = kwargs['mode'] | |
2284 | if 'theta_x' in kwargs: |
|
2284 | if 'theta_x' in kwargs: | |
2285 | theta_x = kwargs['theta_x'] |
|
2285 | theta_x = kwargs['theta_x'] | |
2286 | if 'theta_y' in kwargs: |
|
2286 | if 'theta_y' in kwargs: | |
2287 | theta_y = kwargs['theta_y'] |
|
2287 | theta_y = kwargs['theta_y'] | |
2288 | else: mode = 'SA' |
|
2288 | else: mode = 'SA' | |
2289 |
|
2289 | |||
2290 | #Borrar luego esto |
|
2290 | #Borrar luego esto | |
2291 | if dataOut.groupList is None: |
|
2291 | if dataOut.groupList is None: | |
2292 | dataOut.groupList = [(0,1),(0,2),(1,2)] |
|
2292 | dataOut.groupList = [(0,1),(0,2),(1,2)] | |
2293 | groupList = dataOut.groupList |
|
2293 | groupList = dataOut.groupList | |
2294 | C = 3e8 |
|
2294 | C = 3e8 | |
2295 | freq = 50e6 |
|
2295 | freq = 50e6 | |
2296 | lamb = C/freq |
|
2296 | lamb = C/freq | |
2297 | k = 2*numpy.pi/lamb |
|
2297 | k = 2*numpy.pi/lamb | |
2298 |
|
2298 | |||
2299 | timeList = dataOut.abscissaList |
|
2299 | timeList = dataOut.abscissaList | |
2300 | heightList = dataOut.heightList |
|
2300 | heightList = dataOut.heightList | |
2301 |
|
2301 | |||
2302 | if self.__isConfig == False: |
|
2302 | if self.__isConfig == False: | |
2303 | dataOut.outputInterval = nMins*60 |
|
2303 | dataOut.outputInterval = nMins*60 | |
2304 | # self.__initime = dataOut.datatime.replace(minute = 0, second = 0, microsecond = 03) |
|
2304 | # self.__initime = dataOut.datatime.replace(minute = 0, second = 0, microsecond = 03) | |
2305 | #Get Initial LTC time |
|
2305 | #Get Initial LTC time | |
2306 | initime = datetime.datetime.utcfromtimestamp(dataOut.utctime) |
|
2306 | initime = datetime.datetime.utcfromtimestamp(dataOut.utctime) | |
2307 | minuteAux = initime.minute |
|
2307 | minuteAux = initime.minute | |
2308 | minuteNew = int(numpy.floor(minuteAux/nMins)*nMins) |
|
2308 | minuteNew = int(numpy.floor(minuteAux/nMins)*nMins) | |
2309 | self.__initime = (initime.replace(minute = minuteNew, second = 0, microsecond = 0) - datetime.datetime(1970, 1, 1)).total_seconds() |
|
2309 | self.__initime = (initime.replace(minute = minuteNew, second = 0, microsecond = 0) - datetime.datetime(1970, 1, 1)).total_seconds() | |
2310 |
|
2310 | |||
2311 | self.__isConfig = True |
|
2311 | self.__isConfig = True | |
2312 |
|
2312 | |||
2313 | if self.__buffer is None: |
|
2313 | if self.__buffer is None: | |
2314 | self.__buffer = dataOut.data_param |
|
2314 | self.__buffer = dataOut.data_param | |
2315 | self.__firstdata = copy.copy(dataOut) |
|
2315 | self.__firstdata = copy.copy(dataOut) | |
2316 |
|
2316 | |||
2317 | else: |
|
2317 | else: | |
2318 | self.__buffer = numpy.vstack((self.__buffer, dataOut.data_param)) |
|
2318 | self.__buffer = numpy.vstack((self.__buffer, dataOut.data_param)) | |
2319 |
|
2319 | |||
2320 | self.__checkTime(dataOut.utctime, dataOut.paramInterval, dataOut.outputInterval) #Check if the buffer is ready |
|
2320 | self.__checkTime(dataOut.utctime, dataOut.paramInterval, dataOut.outputInterval) #Check if the buffer is ready | |
2321 |
|
2321 | |||
2322 | if self.__dataReady: |
|
2322 | if self.__dataReady: | |
2323 | dataOut.utctimeInit = self.__initime |
|
2323 | dataOut.utctimeInit = self.__initime | |
2324 | self.__initime += dataOut.outputInterval #to erase time offset |
|
2324 | self.__initime += dataOut.outputInterval #to erase time offset | |
2325 |
|
2325 | |||
2326 | metArray = self.__buffer |
|
2326 | metArray = self.__buffer | |
2327 | if mode == 'SA': |
|
2327 | if mode == 'SA': | |
2328 | dataOut.data_output = self.techniqueNSM_SA(rx_location=rx_location, groupList=groupList, azimuth=azimuth, dfactor=dfactor, k=k,metArray=metArray, heightList=heightList,timeList=timeList) |
|
2328 | dataOut.data_output = self.techniqueNSM_SA(rx_location=rx_location, groupList=groupList, azimuth=azimuth, dfactor=dfactor, k=k,metArray=metArray, heightList=heightList,timeList=timeList) | |
2329 | elif mode == 'DBS': |
|
2329 | elif mode == 'DBS': | |
2330 | dataOut.data_output = self.techniqueNSM_DBS(metArray=metArray,heightList=heightList,timeList=timeList, azimuth=azimuth, theta_x=theta_x, theta_y=theta_y) |
|
2330 | dataOut.data_output = self.techniqueNSM_DBS(metArray=metArray,heightList=heightList,timeList=timeList, azimuth=azimuth, theta_x=theta_x, theta_y=theta_y) | |
2331 | dataOut.data_output = dataOut.data_output.T |
|
2331 | dataOut.data_output = dataOut.data_output.T | |
2332 | dataOut.flagNoData = False |
|
2332 | dataOut.flagNoData = False | |
2333 | self.__buffer = None |
|
2333 | self.__buffer = None | |
2334 |
|
2334 | |||
2335 | return |
|
2335 | return | |
2336 |
|
2336 | |||
2337 | class EWDriftsEstimation(Operation): |
|
2337 | class EWDriftsEstimation(Operation): | |
2338 |
|
2338 | |||
2339 | def __init__(self): |
|
2339 | def __init__(self): | |
2340 | Operation.__init__(self) |
|
2340 | Operation.__init__(self) | |
2341 |
|
2341 | |||
2342 | def __correctValues(self, heiRang, phi, velRadial, SNR): |
|
2342 | def __correctValues(self, heiRang, phi, velRadial, SNR): | |
2343 | listPhi = phi.tolist() |
|
2343 | listPhi = phi.tolist() | |
2344 | maxid = listPhi.index(max(listPhi)) |
|
2344 | maxid = listPhi.index(max(listPhi)) | |
2345 | minid = listPhi.index(min(listPhi)) |
|
2345 | minid = listPhi.index(min(listPhi)) | |
2346 |
|
2346 | |||
2347 | rango = list(range(len(phi))) |
|
2347 | rango = list(range(len(phi))) | |
2348 | # rango = numpy.delete(rango,maxid) |
|
2348 | # rango = numpy.delete(rango,maxid) | |
2349 |
|
2349 | |||
2350 | heiRang1 = heiRang*math.cos(phi[maxid]) |
|
2350 | heiRang1 = heiRang*math.cos(phi[maxid]) | |
2351 | heiRangAux = heiRang*math.cos(phi[minid]) |
|
2351 | heiRangAux = heiRang*math.cos(phi[minid]) | |
2352 | indOut = (heiRang1 < heiRangAux[0]).nonzero() |
|
2352 | indOut = (heiRang1 < heiRangAux[0]).nonzero() | |
2353 | heiRang1 = numpy.delete(heiRang1,indOut) |
|
2353 | heiRang1 = numpy.delete(heiRang1,indOut) | |
2354 |
|
2354 | |||
2355 | velRadial1 = numpy.zeros([len(phi),len(heiRang1)]) |
|
2355 | velRadial1 = numpy.zeros([len(phi),len(heiRang1)]) | |
2356 | SNR1 = numpy.zeros([len(phi),len(heiRang1)]) |
|
2356 | SNR1 = numpy.zeros([len(phi),len(heiRang1)]) | |
2357 |
|
2357 | |||
2358 | for i in rango: |
|
2358 | for i in rango: | |
2359 | x = heiRang*math.cos(phi[i]) |
|
2359 | x = heiRang*math.cos(phi[i]) | |
2360 | y1 = velRadial[i,:] |
|
2360 | y1 = velRadial[i,:] | |
2361 | f1 = interpolate.interp1d(x,y1,kind = 'cubic') |
|
2361 | f1 = interpolate.interp1d(x,y1,kind = 'cubic') | |
2362 |
|
2362 | |||
2363 | x1 = heiRang1 |
|
2363 | x1 = heiRang1 | |
2364 | y11 = f1(x1) |
|
2364 | y11 = f1(x1) | |
2365 |
|
2365 | |||
2366 | y2 = SNR[i,:] |
|
2366 | y2 = SNR[i,:] | |
2367 | f2 = interpolate.interp1d(x,y2,kind = 'cubic') |
|
2367 | f2 = interpolate.interp1d(x,y2,kind = 'cubic') | |
2368 | y21 = f2(x1) |
|
2368 | y21 = f2(x1) | |
2369 |
|
2369 | |||
2370 | velRadial1[i,:] = y11 |
|
2370 | velRadial1[i,:] = y11 | |
2371 | SNR1[i,:] = y21 |
|
2371 | SNR1[i,:] = y21 | |
2372 |
|
2372 | |||
2373 | return heiRang1, velRadial1, SNR1 |
|
2373 | return heiRang1, velRadial1, SNR1 | |
2374 |
|
2374 | |||
2375 | def run(self, dataOut, zenith, zenithCorrection): |
|
2375 | def run(self, dataOut, zenith, zenithCorrection): | |
2376 | heiRang = dataOut.heightList |
|
2376 | heiRang = dataOut.heightList | |
2377 | velRadial = dataOut.data_param[:,3,:] |
|
2377 | velRadial = dataOut.data_param[:,3,:] | |
2378 | SNR = dataOut.data_snr |
|
2378 | SNR = dataOut.data_snr | |
2379 |
|
2379 | |||
2380 | zenith = numpy.array(zenith) |
|
2380 | zenith = numpy.array(zenith) | |
2381 | zenith -= zenithCorrection |
|
2381 | zenith -= zenithCorrection | |
2382 | zenith *= numpy.pi/180 |
|
2382 | zenith *= numpy.pi/180 | |
2383 |
|
2383 | |||
2384 | heiRang1, velRadial1, SNR1 = self.__correctValues(heiRang, numpy.abs(zenith), velRadial, SNR) |
|
2384 | heiRang1, velRadial1, SNR1 = self.__correctValues(heiRang, numpy.abs(zenith), velRadial, SNR) | |
2385 |
|
2385 | |||
2386 | alp = zenith[0] |
|
2386 | alp = zenith[0] | |
2387 | bet = zenith[1] |
|
2387 | bet = zenith[1] | |
2388 |
|
2388 | |||
2389 | w_w = velRadial1[0,:] |
|
2389 | w_w = velRadial1[0,:] | |
2390 | w_e = velRadial1[1,:] |
|
2390 | w_e = velRadial1[1,:] | |
2391 |
|
2391 | |||
2392 | w = (w_w*numpy.sin(bet) - w_e*numpy.sin(alp))/(numpy.cos(alp)*numpy.sin(bet) - numpy.cos(bet)*numpy.sin(alp)) |
|
2392 | w = (w_w*numpy.sin(bet) - w_e*numpy.sin(alp))/(numpy.cos(alp)*numpy.sin(bet) - numpy.cos(bet)*numpy.sin(alp)) | |
2393 | u = (w_w*numpy.cos(bet) - w_e*numpy.cos(alp))/(numpy.sin(alp)*numpy.cos(bet) - numpy.sin(bet)*numpy.cos(alp)) |
|
2393 | u = (w_w*numpy.cos(bet) - w_e*numpy.cos(alp))/(numpy.sin(alp)*numpy.cos(bet) - numpy.sin(bet)*numpy.cos(alp)) | |
2394 |
|
2394 | |||
2395 | winds = numpy.vstack((u,w)) |
|
2395 | winds = numpy.vstack((u,w)) | |
2396 |
|
2396 | |||
2397 | dataOut.heightList = heiRang1 |
|
2397 | dataOut.heightList = heiRang1 | |
2398 | dataOut.data_output = winds |
|
2398 | dataOut.data_output = winds | |
2399 | dataOut.data_snr = SNR1 |
|
2399 | dataOut.data_snr = SNR1 | |
2400 |
|
2400 | |||
2401 | dataOut.utctimeInit = dataOut.utctime |
|
2401 | dataOut.utctimeInit = dataOut.utctime | |
2402 | dataOut.outputInterval = dataOut.timeInterval |
|
2402 | dataOut.outputInterval = dataOut.timeInterval | |
2403 | return |
|
2403 | return | |
2404 |
|
2404 | |||
2405 | #--------------- Non Specular Meteor ---------------- |
|
2405 | #--------------- Non Specular Meteor ---------------- | |
2406 |
|
2406 | |||
2407 | class NonSpecularMeteorDetection(Operation): |
|
2407 | class NonSpecularMeteorDetection(Operation): | |
2408 |
|
2408 | |||
2409 | def run(self, dataOut, mode, SNRthresh=8, phaseDerThresh=0.5, cohThresh=0.8, allData = False): |
|
2409 | def run(self, dataOut, mode, SNRthresh=8, phaseDerThresh=0.5, cohThresh=0.8, allData = False): | |
2410 | data_acf = dataOut.data_pre[0] |
|
2410 | data_acf = dataOut.data_pre[0] | |
2411 | data_ccf = dataOut.data_pre[1] |
|
2411 | data_ccf = dataOut.data_pre[1] | |
2412 | pairsList = dataOut.groupList[1] |
|
2412 | pairsList = dataOut.groupList[1] | |
2413 |
|
2413 | |||
2414 | lamb = dataOut.C/dataOut.frequency |
|
2414 | lamb = dataOut.C/dataOut.frequency | |
2415 | tSamp = dataOut.ippSeconds*dataOut.nCohInt |
|
2415 | tSamp = dataOut.ippSeconds*dataOut.nCohInt | |
2416 | paramInterval = dataOut.paramInterval |
|
2416 | paramInterval = dataOut.paramInterval | |
2417 |
|
2417 | |||
2418 | nChannels = data_acf.shape[0] |
|
2418 | nChannels = data_acf.shape[0] | |
2419 | nLags = data_acf.shape[1] |
|
2419 | nLags = data_acf.shape[1] | |
2420 | nProfiles = data_acf.shape[2] |
|
2420 | nProfiles = data_acf.shape[2] | |
2421 | nHeights = dataOut.nHeights |
|
2421 | nHeights = dataOut.nHeights | |
2422 | nCohInt = dataOut.nCohInt |
|
2422 | nCohInt = dataOut.nCohInt | |
2423 | sec = numpy.round(nProfiles/dataOut.paramInterval) |
|
2423 | sec = numpy.round(nProfiles/dataOut.paramInterval) | |
2424 | heightList = dataOut.heightList |
|
2424 | heightList = dataOut.heightList | |
2425 | ippSeconds = dataOut.ippSeconds*dataOut.nCohInt*dataOut.nAvg |
|
2425 | ippSeconds = dataOut.ippSeconds*dataOut.nCohInt*dataOut.nAvg | |
2426 | utctime = dataOut.utctime |
|
2426 | utctime = dataOut.utctime | |
2427 |
|
2427 | |||
2428 | dataOut.abscissaList = numpy.arange(0,paramInterval+ippSeconds,ippSeconds) |
|
2428 | dataOut.abscissaList = numpy.arange(0,paramInterval+ippSeconds,ippSeconds) | |
2429 |
|
2429 | |||
2430 | #------------------------ SNR -------------------------------------- |
|
2430 | #------------------------ SNR -------------------------------------- | |
2431 | power = data_acf[:,0,:,:].real |
|
2431 | power = data_acf[:,0,:,:].real | |
2432 | noise = numpy.zeros(nChannels) |
|
2432 | noise = numpy.zeros(nChannels) | |
2433 | SNR = numpy.zeros(power.shape) |
|
2433 | SNR = numpy.zeros(power.shape) | |
2434 | for i in range(nChannels): |
|
2434 | for i in range(nChannels): | |
2435 | noise[i] = hildebrand_sekhon(power[i,:], nCohInt) |
|
2435 | noise[i] = hildebrand_sekhon(power[i,:], nCohInt) | |
2436 | SNR[i] = (power[i]-noise[i])/noise[i] |
|
2436 | SNR[i] = (power[i]-noise[i])/noise[i] | |
2437 | SNRm = numpy.nanmean(SNR, axis = 0) |
|
2437 | SNRm = numpy.nanmean(SNR, axis = 0) | |
2438 | SNRdB = 10*numpy.log10(SNR) |
|
2438 | SNRdB = 10*numpy.log10(SNR) | |
2439 |
|
2439 | |||
2440 | if mode == 'SA': |
|
2440 | if mode == 'SA': | |
2441 | dataOut.groupList = dataOut.groupList[1] |
|
2441 | dataOut.groupList = dataOut.groupList[1] | |
2442 | nPairs = data_ccf.shape[0] |
|
2442 | nPairs = data_ccf.shape[0] | |
2443 | #---------------------- Coherence and Phase -------------------------- |
|
2443 | #---------------------- Coherence and Phase -------------------------- | |
2444 | phase = numpy.zeros(data_ccf[:,0,:,:].shape) |
|
2444 | phase = numpy.zeros(data_ccf[:,0,:,:].shape) | |
2445 | # phase1 = numpy.copy(phase) |
|
2445 | # phase1 = numpy.copy(phase) | |
2446 | coh1 = numpy.zeros(data_ccf[:,0,:,:].shape) |
|
2446 | coh1 = numpy.zeros(data_ccf[:,0,:,:].shape) | |
2447 |
|
2447 | |||
2448 | for p in range(nPairs): |
|
2448 | for p in range(nPairs): | |
2449 | ch0 = pairsList[p][0] |
|
2449 | ch0 = pairsList[p][0] | |
2450 | ch1 = pairsList[p][1] |
|
2450 | ch1 = pairsList[p][1] | |
2451 | ccf = data_ccf[p,0,:,:]/numpy.sqrt(data_acf[ch0,0,:,:]*data_acf[ch1,0,:,:]) |
|
2451 | ccf = data_ccf[p,0,:,:]/numpy.sqrt(data_acf[ch0,0,:,:]*data_acf[ch1,0,:,:]) | |
2452 | phase[p,:,:] = ndimage.median_filter(numpy.angle(ccf), size = (5,1)) #median filter |
|
2452 | phase[p,:,:] = ndimage.median_filter(numpy.angle(ccf), size = (5,1)) #median filter | |
2453 | # phase1[p,:,:] = numpy.angle(ccf) #median filter |
|
2453 | # phase1[p,:,:] = numpy.angle(ccf) #median filter | |
2454 | coh1[p,:,:] = ndimage.median_filter(numpy.abs(ccf), 5) #median filter |
|
2454 | coh1[p,:,:] = ndimage.median_filter(numpy.abs(ccf), 5) #median filter | |
2455 | # coh1[p,:,:] = numpy.abs(ccf) #median filter |
|
2455 | # coh1[p,:,:] = numpy.abs(ccf) #median filter | |
2456 | coh = numpy.nanmax(coh1, axis = 0) |
|
2456 | coh = numpy.nanmax(coh1, axis = 0) | |
2457 | # struc = numpy.ones((5,1)) |
|
2457 | # struc = numpy.ones((5,1)) | |
2458 | # coh = ndimage.morphology.grey_dilation(coh, size=(10,1)) |
|
2458 | # coh = ndimage.morphology.grey_dilation(coh, size=(10,1)) | |
2459 | #---------------------- Radial Velocity ---------------------------- |
|
2459 | #---------------------- Radial Velocity ---------------------------- | |
2460 | phaseAux = numpy.mean(numpy.angle(data_acf[:,1,:,:]), axis = 0) |
|
2460 | phaseAux = numpy.mean(numpy.angle(data_acf[:,1,:,:]), axis = 0) | |
2461 | velRad = phaseAux*lamb/(4*numpy.pi*tSamp) |
|
2461 | velRad = phaseAux*lamb/(4*numpy.pi*tSamp) | |
2462 |
|
2462 | |||
2463 | if allData: |
|
2463 | if allData: | |
2464 | boolMetFin = ~numpy.isnan(SNRm) |
|
2464 | boolMetFin = ~numpy.isnan(SNRm) | |
2465 | # coh[:-1,:] = numpy.nanmean(numpy.abs(phase[:,1:,:] - phase[:,:-1,:]),axis=0) |
|
2465 | # coh[:-1,:] = numpy.nanmean(numpy.abs(phase[:,1:,:] - phase[:,:-1,:]),axis=0) | |
2466 | else: |
|
2466 | else: | |
2467 | #------------------------ Meteor mask --------------------------------- |
|
2467 | #------------------------ Meteor mask --------------------------------- | |
2468 | # #SNR mask |
|
2468 | # #SNR mask | |
2469 | # boolMet = (SNRdB>SNRthresh)#|(~numpy.isnan(SNRdB)) |
|
2469 | # boolMet = (SNRdB>SNRthresh)#|(~numpy.isnan(SNRdB)) | |
2470 | # |
|
2470 | # | |
2471 | # #Erase small objects |
|
2471 | # #Erase small objects | |
2472 | # boolMet1 = self.__erase_small(boolMet, 2*sec, 5) |
|
2472 | # boolMet1 = self.__erase_small(boolMet, 2*sec, 5) | |
2473 | # |
|
2473 | # | |
2474 | # auxEEJ = numpy.sum(boolMet1,axis=0) |
|
2474 | # auxEEJ = numpy.sum(boolMet1,axis=0) | |
2475 | # indOver = auxEEJ>nProfiles*0.8 #Use this later |
|
2475 | # indOver = auxEEJ>nProfiles*0.8 #Use this later | |
2476 | # indEEJ = numpy.where(indOver)[0] |
|
2476 | # indEEJ = numpy.where(indOver)[0] | |
2477 | # indNEEJ = numpy.where(~indOver)[0] |
|
2477 | # indNEEJ = numpy.where(~indOver)[0] | |
2478 | # |
|
2478 | # | |
2479 | # boolMetFin = boolMet1 |
|
2479 | # boolMetFin = boolMet1 | |
2480 | # |
|
2480 | # | |
2481 | # if indEEJ.size > 0: |
|
2481 | # if indEEJ.size > 0: | |
2482 | # boolMet1[:,indEEJ] = False #Erase heights with EEJ |
|
2482 | # boolMet1[:,indEEJ] = False #Erase heights with EEJ | |
2483 | # |
|
2483 | # | |
2484 | # boolMet2 = coh > cohThresh |
|
2484 | # boolMet2 = coh > cohThresh | |
2485 | # boolMet2 = self.__erase_small(boolMet2, 2*sec,5) |
|
2485 | # boolMet2 = self.__erase_small(boolMet2, 2*sec,5) | |
2486 | # |
|
2486 | # | |
2487 | # #Final Meteor mask |
|
2487 | # #Final Meteor mask | |
2488 | # boolMetFin = boolMet1|boolMet2 |
|
2488 | # boolMetFin = boolMet1|boolMet2 | |
2489 |
|
2489 | |||
2490 | #Coherence mask |
|
2490 | #Coherence mask | |
2491 | boolMet1 = coh > 0.75 |
|
2491 | boolMet1 = coh > 0.75 | |
2492 | struc = numpy.ones((30,1)) |
|
2492 | struc = numpy.ones((30,1)) | |
2493 | boolMet1 = ndimage.morphology.binary_dilation(boolMet1, structure=struc) |
|
2493 | boolMet1 = ndimage.morphology.binary_dilation(boolMet1, structure=struc) | |
2494 |
|
2494 | |||
2495 | #Derivative mask |
|
2495 | #Derivative mask | |
2496 | derPhase = numpy.nanmean(numpy.abs(phase[:,1:,:] - phase[:,:-1,:]),axis=0) |
|
2496 | derPhase = numpy.nanmean(numpy.abs(phase[:,1:,:] - phase[:,:-1,:]),axis=0) | |
2497 | boolMet2 = derPhase < 0.2 |
|
2497 | boolMet2 = derPhase < 0.2 | |
2498 | # boolMet2 = ndimage.morphology.binary_opening(boolMet2) |
|
2498 | # boolMet2 = ndimage.morphology.binary_opening(boolMet2) | |
2499 | # boolMet2 = ndimage.morphology.binary_closing(boolMet2, structure = numpy.ones((10,1))) |
|
2499 | # boolMet2 = ndimage.morphology.binary_closing(boolMet2, structure = numpy.ones((10,1))) | |
2500 | boolMet2 = ndimage.median_filter(boolMet2,size=5) |
|
2500 | boolMet2 = ndimage.median_filter(boolMet2,size=5) | |
2501 | boolMet2 = numpy.vstack((boolMet2,numpy.full((1,nHeights), True, dtype=bool))) |
|
2501 | boolMet2 = numpy.vstack((boolMet2,numpy.full((1,nHeights), True, dtype=bool))) | |
2502 | # #Final mask |
|
2502 | # #Final mask | |
2503 | # boolMetFin = boolMet2 |
|
2503 | # boolMetFin = boolMet2 | |
2504 | boolMetFin = boolMet1&boolMet2 |
|
2504 | boolMetFin = boolMet1&boolMet2 | |
2505 | # boolMetFin = ndimage.morphology.binary_dilation(boolMetFin) |
|
2505 | # boolMetFin = ndimage.morphology.binary_dilation(boolMetFin) | |
2506 | #Creating data_param |
|
2506 | #Creating data_param | |
2507 | coordMet = numpy.where(boolMetFin) |
|
2507 | coordMet = numpy.where(boolMetFin) | |
2508 |
|
2508 | |||
2509 | tmet = coordMet[0] |
|
2509 | tmet = coordMet[0] | |
2510 | hmet = coordMet[1] |
|
2510 | hmet = coordMet[1] | |
2511 |
|
2511 | |||
2512 | data_param = numpy.zeros((tmet.size, 6 + nPairs)) |
|
2512 | data_param = numpy.zeros((tmet.size, 6 + nPairs)) | |
2513 | data_param[:,0] = utctime |
|
2513 | data_param[:,0] = utctime | |
2514 | data_param[:,1] = tmet |
|
2514 | data_param[:,1] = tmet | |
2515 | data_param[:,2] = hmet |
|
2515 | data_param[:,2] = hmet | |
2516 | data_param[:,3] = SNRm[tmet,hmet] |
|
2516 | data_param[:,3] = SNRm[tmet,hmet] | |
2517 | data_param[:,4] = velRad[tmet,hmet] |
|
2517 | data_param[:,4] = velRad[tmet,hmet] | |
2518 | data_param[:,5] = coh[tmet,hmet] |
|
2518 | data_param[:,5] = coh[tmet,hmet] | |
2519 | data_param[:,6:] = phase[:,tmet,hmet].T |
|
2519 | data_param[:,6:] = phase[:,tmet,hmet].T | |
2520 |
|
2520 | |||
2521 | elif mode == 'DBS': |
|
2521 | elif mode == 'DBS': | |
2522 | dataOut.groupList = numpy.arange(nChannels) |
|
2522 | dataOut.groupList = numpy.arange(nChannels) | |
2523 |
|
2523 | |||
2524 | #Radial Velocities |
|
2524 | #Radial Velocities | |
2525 | phase = numpy.angle(data_acf[:,1,:,:]) |
|
2525 | phase = numpy.angle(data_acf[:,1,:,:]) | |
2526 | # phase = ndimage.median_filter(numpy.angle(data_acf[:,1,:,:]), size = (1,5,1)) |
|
2526 | # phase = ndimage.median_filter(numpy.angle(data_acf[:,1,:,:]), size = (1,5,1)) | |
2527 | velRad = phase*lamb/(4*numpy.pi*tSamp) |
|
2527 | velRad = phase*lamb/(4*numpy.pi*tSamp) | |
2528 |
|
2528 | |||
2529 | #Spectral width |
|
2529 | #Spectral width | |
2530 | # acf1 = ndimage.median_filter(numpy.abs(data_acf[:,1,:,:]), size = (1,5,1)) |
|
2530 | # acf1 = ndimage.median_filter(numpy.abs(data_acf[:,1,:,:]), size = (1,5,1)) | |
2531 | # acf2 = ndimage.median_filter(numpy.abs(data_acf[:,2,:,:]), size = (1,5,1)) |
|
2531 | # acf2 = ndimage.median_filter(numpy.abs(data_acf[:,2,:,:]), size = (1,5,1)) | |
2532 | acf1 = data_acf[:,1,:,:] |
|
2532 | acf1 = data_acf[:,1,:,:] | |
2533 | acf2 = data_acf[:,2,:,:] |
|
2533 | acf2 = data_acf[:,2,:,:] | |
2534 |
|
2534 | |||
2535 | spcWidth = (lamb/(2*numpy.sqrt(6)*numpy.pi*tSamp))*numpy.sqrt(numpy.log(acf1/acf2)) |
|
2535 | spcWidth = (lamb/(2*numpy.sqrt(6)*numpy.pi*tSamp))*numpy.sqrt(numpy.log(acf1/acf2)) | |
2536 | # velRad = ndimage.median_filter(velRad, size = (1,5,1)) |
|
2536 | # velRad = ndimage.median_filter(velRad, size = (1,5,1)) | |
2537 | if allData: |
|
2537 | if allData: | |
2538 | boolMetFin = ~numpy.isnan(SNRdB) |
|
2538 | boolMetFin = ~numpy.isnan(SNRdB) | |
2539 | else: |
|
2539 | else: | |
2540 | #SNR |
|
2540 | #SNR | |
2541 | boolMet1 = (SNRdB>SNRthresh) #SNR mask |
|
2541 | boolMet1 = (SNRdB>SNRthresh) #SNR mask | |
2542 | boolMet1 = ndimage.median_filter(boolMet1, size=(1,5,5)) |
|
2542 | boolMet1 = ndimage.median_filter(boolMet1, size=(1,5,5)) | |
2543 |
|
2543 | |||
2544 | #Radial velocity |
|
2544 | #Radial velocity | |
2545 | boolMet2 = numpy.abs(velRad) < 20 |
|
2545 | boolMet2 = numpy.abs(velRad) < 20 | |
2546 | boolMet2 = ndimage.median_filter(boolMet2, (1,5,5)) |
|
2546 | boolMet2 = ndimage.median_filter(boolMet2, (1,5,5)) | |
2547 |
|
2547 | |||
2548 | #Spectral Width |
|
2548 | #Spectral Width | |
2549 | boolMet3 = spcWidth < 30 |
|
2549 | boolMet3 = spcWidth < 30 | |
2550 | boolMet3 = ndimage.median_filter(boolMet3, (1,5,5)) |
|
2550 | boolMet3 = ndimage.median_filter(boolMet3, (1,5,5)) | |
2551 | # boolMetFin = self.__erase_small(boolMet1, 10,5) |
|
2551 | # boolMetFin = self.__erase_small(boolMet1, 10,5) | |
2552 | boolMetFin = boolMet1&boolMet2&boolMet3 |
|
2552 | boolMetFin = boolMet1&boolMet2&boolMet3 | |
2553 |
|
2553 | |||
2554 | #Creating data_param |
|
2554 | #Creating data_param | |
2555 | coordMet = numpy.where(boolMetFin) |
|
2555 | coordMet = numpy.where(boolMetFin) | |
2556 |
|
2556 | |||
2557 | cmet = coordMet[0] |
|
2557 | cmet = coordMet[0] | |
2558 | tmet = coordMet[1] |
|
2558 | tmet = coordMet[1] | |
2559 | hmet = coordMet[2] |
|
2559 | hmet = coordMet[2] | |
2560 |
|
2560 | |||
2561 | data_param = numpy.zeros((tmet.size, 7)) |
|
2561 | data_param = numpy.zeros((tmet.size, 7)) | |
2562 | data_param[:,0] = utctime |
|
2562 | data_param[:,0] = utctime | |
2563 | data_param[:,1] = cmet |
|
2563 | data_param[:,1] = cmet | |
2564 | data_param[:,2] = tmet |
|
2564 | data_param[:,2] = tmet | |
2565 | data_param[:,3] = hmet |
|
2565 | data_param[:,3] = hmet | |
2566 | data_param[:,4] = SNR[cmet,tmet,hmet].T |
|
2566 | data_param[:,4] = SNR[cmet,tmet,hmet].T | |
2567 | data_param[:,5] = velRad[cmet,tmet,hmet].T |
|
2567 | data_param[:,5] = velRad[cmet,tmet,hmet].T | |
2568 | data_param[:,6] = spcWidth[cmet,tmet,hmet].T |
|
2568 | data_param[:,6] = spcWidth[cmet,tmet,hmet].T | |
2569 |
|
2569 | |||
2570 | # self.dataOut.data_param = data_int |
|
2570 | # self.dataOut.data_param = data_int | |
2571 | if len(data_param) == 0: |
|
2571 | if len(data_param) == 0: | |
2572 | dataOut.flagNoData = True |
|
2572 | dataOut.flagNoData = True | |
2573 | else: |
|
2573 | else: | |
2574 | dataOut.data_param = data_param |
|
2574 | dataOut.data_param = data_param | |
2575 |
|
2575 | |||
2576 | def __erase_small(self, binArray, threshX, threshY): |
|
2576 | def __erase_small(self, binArray, threshX, threshY): | |
2577 | labarray, numfeat = ndimage.measurements.label(binArray) |
|
2577 | labarray, numfeat = ndimage.measurements.label(binArray) | |
2578 | binArray1 = numpy.copy(binArray) |
|
2578 | binArray1 = numpy.copy(binArray) | |
2579 |
|
2579 | |||
2580 | for i in range(1,numfeat + 1): |
|
2580 | for i in range(1,numfeat + 1): | |
2581 | auxBin = (labarray==i) |
|
2581 | auxBin = (labarray==i) | |
2582 | auxSize = auxBin.sum() |
|
2582 | auxSize = auxBin.sum() | |
2583 |
|
2583 | |||
2584 | x,y = numpy.where(auxBin) |
|
2584 | x,y = numpy.where(auxBin) | |
2585 | widthX = x.max() - x.min() |
|
2585 | widthX = x.max() - x.min() | |
2586 | widthY = y.max() - y.min() |
|
2586 | widthY = y.max() - y.min() | |
2587 |
|
2587 | |||
2588 | #width X: 3 seg -> 12.5*3 |
|
2588 | #width X: 3 seg -> 12.5*3 | |
2589 | #width Y: |
|
2589 | #width Y: | |
2590 |
|
2590 | |||
2591 | if (auxSize < 50) or (widthX < threshX) or (widthY < threshY): |
|
2591 | if (auxSize < 50) or (widthX < threshX) or (widthY < threshY): | |
2592 | binArray1[auxBin] = False |
|
2592 | binArray1[auxBin] = False | |
2593 |
|
2593 | |||
2594 | return binArray1 |
|
2594 | return binArray1 | |
2595 |
|
2595 | |||
2596 | #--------------- Specular Meteor ---------------- |
|
2596 | #--------------- Specular Meteor ---------------- | |
2597 |
|
2597 | |||
2598 | class SMDetection(Operation): |
|
2598 | class SMDetection(Operation): | |
2599 | ''' |
|
2599 | ''' | |
2600 | Function DetectMeteors() |
|
2600 | Function DetectMeteors() | |
2601 | Project developed with paper: |
|
2601 | Project developed with paper: | |
2602 | HOLDSWORTH ET AL. 2004 |
|
2602 | HOLDSWORTH ET AL. 2004 | |
2603 |
|
2603 | |||
2604 | Input: |
|
2604 | Input: | |
2605 | self.dataOut.data_pre |
|
2605 | self.dataOut.data_pre | |
2606 |
|
2606 | |||
2607 | centerReceiverIndex: From the channels, which is the center receiver |
|
2607 | centerReceiverIndex: From the channels, which is the center receiver | |
2608 |
|
2608 | |||
2609 | hei_ref: Height reference for the Beacon signal extraction |
|
2609 | hei_ref: Height reference for the Beacon signal extraction | |
2610 | tauindex: |
|
2610 | tauindex: | |
2611 | predefinedPhaseShifts: Predefined phase offset for the voltge signals |
|
2611 | predefinedPhaseShifts: Predefined phase offset for the voltge signals | |
2612 |
|
2612 | |||
2613 | cohDetection: Whether to user Coherent detection or not |
|
2613 | cohDetection: Whether to user Coherent detection or not | |
2614 | cohDet_timeStep: Coherent Detection calculation time step |
|
2614 | cohDet_timeStep: Coherent Detection calculation time step | |
2615 | cohDet_thresh: Coherent Detection phase threshold to correct phases |
|
2615 | cohDet_thresh: Coherent Detection phase threshold to correct phases | |
2616 |
|
2616 | |||
2617 | noise_timeStep: Noise calculation time step |
|
2617 | noise_timeStep: Noise calculation time step | |
2618 | noise_multiple: Noise multiple to define signal threshold |
|
2618 | noise_multiple: Noise multiple to define signal threshold | |
2619 |
|
2619 | |||
2620 | multDet_timeLimit: Multiple Detection Removal time limit in seconds |
|
2620 | multDet_timeLimit: Multiple Detection Removal time limit in seconds | |
2621 | multDet_rangeLimit: Multiple Detection Removal range limit in km |
|
2621 | multDet_rangeLimit: Multiple Detection Removal range limit in km | |
2622 |
|
2622 | |||
2623 | phaseThresh: Maximum phase difference between receiver to be consider a meteor |
|
2623 | phaseThresh: Maximum phase difference between receiver to be consider a meteor | |
2624 | SNRThresh: Minimum SNR threshold of the meteor signal to be consider a meteor |
|
2624 | SNRThresh: Minimum SNR threshold of the meteor signal to be consider a meteor | |
2625 |
|
2625 | |||
2626 | hmin: Minimum Height of the meteor to use it in the further wind estimations |
|
2626 | hmin: Minimum Height of the meteor to use it in the further wind estimations | |
2627 | hmax: Maximum Height of the meteor to use it in the further wind estimations |
|
2627 | hmax: Maximum Height of the meteor to use it in the further wind estimations | |
2628 | azimuth: Azimuth angle correction |
|
2628 | azimuth: Azimuth angle correction | |
2629 |
|
2629 | |||
2630 | Affected: |
|
2630 | Affected: | |
2631 | self.dataOut.data_param |
|
2631 | self.dataOut.data_param | |
2632 |
|
2632 | |||
2633 | Rejection Criteria (Errors): |
|
2633 | Rejection Criteria (Errors): | |
2634 | 0: No error; analysis OK |
|
2634 | 0: No error; analysis OK | |
2635 | 1: SNR < SNR threshold |
|
2635 | 1: SNR < SNR threshold | |
2636 | 2: angle of arrival (AOA) ambiguously determined |
|
2636 | 2: angle of arrival (AOA) ambiguously determined | |
2637 | 3: AOA estimate not feasible |
|
2637 | 3: AOA estimate not feasible | |
2638 | 4: Large difference in AOAs obtained from different antenna baselines |
|
2638 | 4: Large difference in AOAs obtained from different antenna baselines | |
2639 | 5: echo at start or end of time series |
|
2639 | 5: echo at start or end of time series | |
2640 | 6: echo less than 5 examples long; too short for analysis |
|
2640 | 6: echo less than 5 examples long; too short for analysis | |
2641 | 7: echo rise exceeds 0.3s |
|
2641 | 7: echo rise exceeds 0.3s | |
2642 | 8: echo decay time less than twice rise time |
|
2642 | 8: echo decay time less than twice rise time | |
2643 | 9: large power level before echo |
|
2643 | 9: large power level before echo | |
2644 | 10: large power level after echo |
|
2644 | 10: large power level after echo | |
2645 | 11: poor fit to amplitude for estimation of decay time |
|
2645 | 11: poor fit to amplitude for estimation of decay time | |
2646 | 12: poor fit to CCF phase variation for estimation of radial drift velocity |
|
2646 | 12: poor fit to CCF phase variation for estimation of radial drift velocity | |
2647 | 13: height unresolvable echo: not valid height within 70 to 110 km |
|
2647 | 13: height unresolvable echo: not valid height within 70 to 110 km | |
2648 | 14: height ambiguous echo: more then one possible height within 70 to 110 km |
|
2648 | 14: height ambiguous echo: more then one possible height within 70 to 110 km | |
2649 | 15: radial drift velocity or projected horizontal velocity exceeds 200 m/s |
|
2649 | 15: radial drift velocity or projected horizontal velocity exceeds 200 m/s | |
2650 | 16: oscilatory echo, indicating event most likely not an underdense echo |
|
2650 | 16: oscilatory echo, indicating event most likely not an underdense echo | |
2651 |
|
2651 | |||
2652 | 17: phase difference in meteor Reestimation |
|
2652 | 17: phase difference in meteor Reestimation | |
2653 |
|
2653 | |||
2654 | Data Storage: |
|
2654 | Data Storage: | |
2655 | Meteors for Wind Estimation (8): |
|
2655 | Meteors for Wind Estimation (8): | |
2656 | Utc Time | Range Height |
|
2656 | Utc Time | Range Height | |
2657 | Azimuth Zenith errorCosDir |
|
2657 | Azimuth Zenith errorCosDir | |
2658 | VelRad errorVelRad |
|
2658 | VelRad errorVelRad | |
2659 | Phase0 Phase1 Phase2 Phase3 |
|
2659 | Phase0 Phase1 Phase2 Phase3 | |
2660 | TypeError |
|
2660 | TypeError | |
2661 |
|
2661 | |||
2662 | ''' |
|
2662 | ''' | |
2663 |
|
2663 | |||
2664 | def run(self, dataOut, hei_ref = None, tauindex = 0, |
|
2664 | def run(self, dataOut, hei_ref = None, tauindex = 0, | |
2665 | phaseOffsets = None, |
|
2665 | phaseOffsets = None, | |
2666 | cohDetection = False, cohDet_timeStep = 1, cohDet_thresh = 25, |
|
2666 | cohDetection = False, cohDet_timeStep = 1, cohDet_thresh = 25, | |
2667 | noise_timeStep = 4, noise_multiple = 4, |
|
2667 | noise_timeStep = 4, noise_multiple = 4, | |
2668 | multDet_timeLimit = 1, multDet_rangeLimit = 3, |
|
2668 | multDet_timeLimit = 1, multDet_rangeLimit = 3, | |
2669 | phaseThresh = 20, SNRThresh = 5, |
|
2669 | phaseThresh = 20, SNRThresh = 5, | |
2670 | hmin = 50, hmax=150, azimuth = 0, |
|
2670 | hmin = 50, hmax=150, azimuth = 0, | |
2671 | channelPositions = None) : |
|
2671 | channelPositions = None) : | |
2672 |
|
2672 | |||
2673 |
|
2673 | |||
2674 | #Getting Pairslist |
|
2674 | #Getting Pairslist | |
2675 | if channelPositions is None: |
|
2675 | if channelPositions is None: | |
2676 | # channelPositions = [(2.5,0), (0,2.5), (0,0), (0,4.5), (-2,0)] #T |
|
2676 | # channelPositions = [(2.5,0), (0,2.5), (0,0), (0,4.5), (-2,0)] #T | |
2677 | channelPositions = [(4.5,2), (2,4.5), (2,2), (2,0), (0,2)] #Estrella |
|
2677 | channelPositions = [(4.5,2), (2,4.5), (2,2), (2,0), (0,2)] #Estrella | |
2678 | meteorOps = SMOperations() |
|
2678 | meteorOps = SMOperations() | |
2679 | pairslist0, distances = meteorOps.getPhasePairs(channelPositions) |
|
2679 | pairslist0, distances = meteorOps.getPhasePairs(channelPositions) | |
2680 | heiRang = dataOut.heightList |
|
2680 | heiRang = dataOut.heightList | |
2681 | #Get Beacon signal - No Beacon signal anymore |
|
2681 | #Get Beacon signal - No Beacon signal anymore | |
2682 | # newheis = numpy.where(self.dataOut.heightList>self.dataOut.radarControllerHeaderObj.Taus[tauindex]) |
|
2682 | # newheis = numpy.where(self.dataOut.heightList>self.dataOut.radarControllerHeaderObj.Taus[tauindex]) | |
2683 | # |
|
2683 | # | |
2684 | # if hei_ref != None: |
|
2684 | # if hei_ref != None: | |
2685 | # newheis = numpy.where(self.dataOut.heightList>hei_ref) |
|
2685 | # newheis = numpy.where(self.dataOut.heightList>hei_ref) | |
2686 | # |
|
2686 | # | |
2687 |
|
2687 | |||
2688 |
|
2688 | |||
2689 | #****************REMOVING HARDWARE PHASE DIFFERENCES*************** |
|
2689 | #****************REMOVING HARDWARE PHASE DIFFERENCES*************** | |
2690 | # see if the user put in pre defined phase shifts |
|
2690 | # see if the user put in pre defined phase shifts | |
2691 | voltsPShift = dataOut.data_pre.copy() |
|
2691 | voltsPShift = dataOut.data_pre.copy() | |
2692 |
|
2692 | |||
2693 | # if predefinedPhaseShifts != None: |
|
2693 | # if predefinedPhaseShifts != None: | |
2694 | # hardwarePhaseShifts = numpy.array(predefinedPhaseShifts)*numpy.pi/180 |
|
2694 | # hardwarePhaseShifts = numpy.array(predefinedPhaseShifts)*numpy.pi/180 | |
2695 | # |
|
2695 | # | |
2696 | # # elif beaconPhaseShifts: |
|
2696 | # # elif beaconPhaseShifts: | |
2697 | # # #get hardware phase shifts using beacon signal |
|
2697 | # # #get hardware phase shifts using beacon signal | |
2698 | # # hardwarePhaseShifts = self.__getHardwarePhaseDiff(self.dataOut.data_pre, pairslist, newheis, 10) |
|
2698 | # # hardwarePhaseShifts = self.__getHardwarePhaseDiff(self.dataOut.data_pre, pairslist, newheis, 10) | |
2699 | # # hardwarePhaseShifts = numpy.insert(hardwarePhaseShifts,centerReceiverIndex,0) |
|
2699 | # # hardwarePhaseShifts = numpy.insert(hardwarePhaseShifts,centerReceiverIndex,0) | |
2700 | # |
|
2700 | # | |
2701 | # else: |
|
2701 | # else: | |
2702 | # hardwarePhaseShifts = numpy.zeros(5) |
|
2702 | # hardwarePhaseShifts = numpy.zeros(5) | |
2703 | # |
|
2703 | # | |
2704 | # voltsPShift = numpy.zeros((self.dataOut.data_pre.shape[0],self.dataOut.data_pre.shape[1],self.dataOut.data_pre.shape[2]), dtype = 'complex') |
|
2704 | # voltsPShift = numpy.zeros((self.dataOut.data_pre.shape[0],self.dataOut.data_pre.shape[1],self.dataOut.data_pre.shape[2]), dtype = 'complex') | |
2705 | # for i in range(self.dataOut.data_pre.shape[0]): |
|
2705 | # for i in range(self.dataOut.data_pre.shape[0]): | |
2706 | # voltsPShift[i,:,:] = self.__shiftPhase(self.dataOut.data_pre[i,:,:], hardwarePhaseShifts[i]) |
|
2706 | # voltsPShift[i,:,:] = self.__shiftPhase(self.dataOut.data_pre[i,:,:], hardwarePhaseShifts[i]) | |
2707 |
|
2707 | |||
2708 | #******************END OF REMOVING HARDWARE PHASE DIFFERENCES********* |
|
2708 | #******************END OF REMOVING HARDWARE PHASE DIFFERENCES********* | |
2709 |
|
2709 | |||
2710 | #Remove DC |
|
2710 | #Remove DC | |
2711 | voltsDC = numpy.mean(voltsPShift,1) |
|
2711 | voltsDC = numpy.mean(voltsPShift,1) | |
2712 | voltsDC = numpy.mean(voltsDC,1) |
|
2712 | voltsDC = numpy.mean(voltsDC,1) | |
2713 | for i in range(voltsDC.shape[0]): |
|
2713 | for i in range(voltsDC.shape[0]): | |
2714 | voltsPShift[i] = voltsPShift[i] - voltsDC[i] |
|
2714 | voltsPShift[i] = voltsPShift[i] - voltsDC[i] | |
2715 |
|
2715 | |||
2716 | #Don't considerate last heights, theyre used to calculate Hardware Phase Shift |
|
2716 | #Don't considerate last heights, theyre used to calculate Hardware Phase Shift | |
2717 | # voltsPShift = voltsPShift[:,:,:newheis[0][0]] |
|
2717 | # voltsPShift = voltsPShift[:,:,:newheis[0][0]] | |
2718 |
|
2718 | |||
2719 | #************ FIND POWER OF DATA W/COH OR NON COH DETECTION (3.4) ********** |
|
2719 | #************ FIND POWER OF DATA W/COH OR NON COH DETECTION (3.4) ********** | |
2720 | #Coherent Detection |
|
2720 | #Coherent Detection | |
2721 | if cohDetection: |
|
2721 | if cohDetection: | |
2722 | #use coherent detection to get the net power |
|
2722 | #use coherent detection to get the net power | |
2723 | cohDet_thresh = cohDet_thresh*numpy.pi/180 |
|
2723 | cohDet_thresh = cohDet_thresh*numpy.pi/180 | |
2724 | voltsPShift = self.__coherentDetection(voltsPShift, cohDet_timeStep, dataOut.timeInterval, pairslist0, cohDet_thresh) |
|
2724 | voltsPShift = self.__coherentDetection(voltsPShift, cohDet_timeStep, dataOut.timeInterval, pairslist0, cohDet_thresh) | |
2725 |
|
2725 | |||
2726 | #Non-coherent detection! |
|
2726 | #Non-coherent detection! | |
2727 | powerNet = numpy.nansum(numpy.abs(voltsPShift[:,:,:])**2,0) |
|
2727 | powerNet = numpy.nansum(numpy.abs(voltsPShift[:,:,:])**2,0) | |
2728 | #********** END OF COH/NON-COH POWER CALCULATION********************** |
|
2728 | #********** END OF COH/NON-COH POWER CALCULATION********************** | |
2729 |
|
2729 | |||
2730 | #********** FIND THE NOISE LEVEL AND POSSIBLE METEORS **************** |
|
2730 | #********** FIND THE NOISE LEVEL AND POSSIBLE METEORS **************** | |
2731 | #Get noise |
|
2731 | #Get noise | |
2732 | noise, noise1 = self.__getNoise(powerNet, noise_timeStep, dataOut.timeInterval) |
|
2732 | noise, noise1 = self.__getNoise(powerNet, noise_timeStep, dataOut.timeInterval) | |
2733 | # noise = self.getNoise1(powerNet, noise_timeStep, self.dataOut.timeInterval) |
|
2733 | # noise = self.getNoise1(powerNet, noise_timeStep, self.dataOut.timeInterval) | |
2734 | #Get signal threshold |
|
2734 | #Get signal threshold | |
2735 | signalThresh = noise_multiple*noise |
|
2735 | signalThresh = noise_multiple*noise | |
2736 | #Meteor echoes detection |
|
2736 | #Meteor echoes detection | |
2737 | listMeteors = self.__findMeteors(powerNet, signalThresh) |
|
2737 | listMeteors = self.__findMeteors(powerNet, signalThresh) | |
2738 | #******* END OF NOISE LEVEL AND POSSIBLE METEORS CACULATION ********** |
|
2738 | #******* END OF NOISE LEVEL AND POSSIBLE METEORS CACULATION ********** | |
2739 |
|
2739 | |||
2740 | #************** REMOVE MULTIPLE DETECTIONS (3.5) *************************** |
|
2740 | #************** REMOVE MULTIPLE DETECTIONS (3.5) *************************** | |
2741 | #Parameters |
|
2741 | #Parameters | |
2742 | heiRange = dataOut.heightList |
|
2742 | heiRange = dataOut.heightList | |
2743 | rangeInterval = heiRange[1] - heiRange[0] |
|
2743 | rangeInterval = heiRange[1] - heiRange[0] | |
2744 | rangeLimit = multDet_rangeLimit/rangeInterval |
|
2744 | rangeLimit = multDet_rangeLimit/rangeInterval | |
2745 | timeLimit = multDet_timeLimit/dataOut.timeInterval |
|
2745 | timeLimit = multDet_timeLimit/dataOut.timeInterval | |
2746 | #Multiple detection removals |
|
2746 | #Multiple detection removals | |
2747 | listMeteors1 = self.__removeMultipleDetections(listMeteors, rangeLimit, timeLimit) |
|
2747 | listMeteors1 = self.__removeMultipleDetections(listMeteors, rangeLimit, timeLimit) | |
2748 | #************ END OF REMOVE MULTIPLE DETECTIONS ********************** |
|
2748 | #************ END OF REMOVE MULTIPLE DETECTIONS ********************** | |
2749 |
|
2749 | |||
2750 | #********************* METEOR REESTIMATION (3.7, 3.8, 3.9, 3.10) ******************** |
|
2750 | #********************* METEOR REESTIMATION (3.7, 3.8, 3.9, 3.10) ******************** | |
2751 | #Parameters |
|
2751 | #Parameters | |
2752 | phaseThresh = phaseThresh*numpy.pi/180 |
|
2752 | phaseThresh = phaseThresh*numpy.pi/180 | |
2753 | thresh = [phaseThresh, noise_multiple, SNRThresh] |
|
2753 | thresh = [phaseThresh, noise_multiple, SNRThresh] | |
2754 | #Meteor reestimation (Errors N 1, 6, 12, 17) |
|
2754 | #Meteor reestimation (Errors N 1, 6, 12, 17) | |
2755 | listMeteors2, listMeteorsPower, listMeteorsVolts = self.__meteorReestimation(listMeteors1, voltsPShift, pairslist0, thresh, noise, dataOut.timeInterval, dataOut.frequency) |
|
2755 | listMeteors2, listMeteorsPower, listMeteorsVolts = self.__meteorReestimation(listMeteors1, voltsPShift, pairslist0, thresh, noise, dataOut.timeInterval, dataOut.frequency) | |
2756 | # listMeteors2, listMeteorsPower, listMeteorsVolts = self.meteorReestimation3(listMeteors2, listMeteorsPower, listMeteorsVolts, voltsPShift, pairslist, thresh, noise) |
|
2756 | # listMeteors2, listMeteorsPower, listMeteorsVolts = self.meteorReestimation3(listMeteors2, listMeteorsPower, listMeteorsVolts, voltsPShift, pairslist, thresh, noise) | |
2757 | #Estimation of decay times (Errors N 7, 8, 11) |
|
2757 | #Estimation of decay times (Errors N 7, 8, 11) | |
2758 | listMeteors3 = self.__estimateDecayTime(listMeteors2, listMeteorsPower, dataOut.timeInterval, dataOut.frequency) |
|
2758 | listMeteors3 = self.__estimateDecayTime(listMeteors2, listMeteorsPower, dataOut.timeInterval, dataOut.frequency) | |
2759 | #******************* END OF METEOR REESTIMATION ******************* |
|
2759 | #******************* END OF METEOR REESTIMATION ******************* | |
2760 |
|
2760 | |||
2761 | #********************* METEOR PARAMETERS CALCULATION (3.11, 3.12, 3.13) ************************** |
|
2761 | #********************* METEOR PARAMETERS CALCULATION (3.11, 3.12, 3.13) ************************** | |
2762 | #Calculating Radial Velocity (Error N 15) |
|
2762 | #Calculating Radial Velocity (Error N 15) | |
2763 | radialStdThresh = 10 |
|
2763 | radialStdThresh = 10 | |
2764 | listMeteors4 = self.__getRadialVelocity(listMeteors3, listMeteorsVolts, radialStdThresh, pairslist0, dataOut.timeInterval) |
|
2764 | listMeteors4 = self.__getRadialVelocity(listMeteors3, listMeteorsVolts, radialStdThresh, pairslist0, dataOut.timeInterval) | |
2765 |
|
2765 | |||
2766 | if len(listMeteors4) > 0: |
|
2766 | if len(listMeteors4) > 0: | |
2767 | #Setting New Array |
|
2767 | #Setting New Array | |
2768 | date = dataOut.utctime |
|
2768 | date = dataOut.utctime | |
2769 | arrayParameters = self.__setNewArrays(listMeteors4, date, heiRang) |
|
2769 | arrayParameters = self.__setNewArrays(listMeteors4, date, heiRang) | |
2770 |
|
2770 | |||
2771 | #Correcting phase offset |
|
2771 | #Correcting phase offset | |
2772 | if phaseOffsets != None: |
|
2772 | if phaseOffsets != None: | |
2773 | phaseOffsets = numpy.array(phaseOffsets)*numpy.pi/180 |
|
2773 | phaseOffsets = numpy.array(phaseOffsets)*numpy.pi/180 | |
2774 | arrayParameters[:,8:12] = numpy.unwrap(arrayParameters[:,8:12] + phaseOffsets) |
|
2774 | arrayParameters[:,8:12] = numpy.unwrap(arrayParameters[:,8:12] + phaseOffsets) | |
2775 |
|
2775 | |||
2776 | #Second Pairslist |
|
2776 | #Second Pairslist | |
2777 | pairsList = [] |
|
2777 | pairsList = [] | |
2778 | pairx = (0,1) |
|
2778 | pairx = (0,1) | |
2779 | pairy = (2,3) |
|
2779 | pairy = (2,3) | |
2780 | pairsList.append(pairx) |
|
2780 | pairsList.append(pairx) | |
2781 | pairsList.append(pairy) |
|
2781 | pairsList.append(pairy) | |
2782 |
|
2782 | |||
2783 | jph = numpy.array([0,0,0,0]) |
|
2783 | jph = numpy.array([0,0,0,0]) | |
2784 | h = (hmin,hmax) |
|
2784 | h = (hmin,hmax) | |
2785 | arrayParameters = meteorOps.getMeteorParams(arrayParameters, azimuth, h, pairsList, distances, jph) |
|
2785 | arrayParameters = meteorOps.getMeteorParams(arrayParameters, azimuth, h, pairsList, distances, jph) | |
2786 |
|
2786 | |||
2787 | # #Calculate AOA (Error N 3, 4) |
|
2787 | # #Calculate AOA (Error N 3, 4) | |
2788 | # #JONES ET AL. 1998 |
|
2788 | # #JONES ET AL. 1998 | |
2789 | # error = arrayParameters[:,-1] |
|
2789 | # error = arrayParameters[:,-1] | |
2790 | # AOAthresh = numpy.pi/8 |
|
2790 | # AOAthresh = numpy.pi/8 | |
2791 | # phases = -arrayParameters[:,9:13] |
|
2791 | # phases = -arrayParameters[:,9:13] | |
2792 | # arrayParameters[:,4:7], arrayParameters[:,-1] = meteorOps.getAOA(phases, pairsList, error, AOAthresh, azimuth) |
|
2792 | # arrayParameters[:,4:7], arrayParameters[:,-1] = meteorOps.getAOA(phases, pairsList, error, AOAthresh, azimuth) | |
2793 | # |
|
2793 | # | |
2794 | # #Calculate Heights (Error N 13 and 14) |
|
2794 | # #Calculate Heights (Error N 13 and 14) | |
2795 | # error = arrayParameters[:,-1] |
|
2795 | # error = arrayParameters[:,-1] | |
2796 | # Ranges = arrayParameters[:,2] |
|
2796 | # Ranges = arrayParameters[:,2] | |
2797 | # zenith = arrayParameters[:,5] |
|
2797 | # zenith = arrayParameters[:,5] | |
2798 | # arrayParameters[:,3], arrayParameters[:,-1] = meteorOps.getHeights(Ranges, zenith, error, hmin, hmax) |
|
2798 | # arrayParameters[:,3], arrayParameters[:,-1] = meteorOps.getHeights(Ranges, zenith, error, hmin, hmax) | |
2799 | # error = arrayParameters[:,-1] |
|
2799 | # error = arrayParameters[:,-1] | |
2800 | #********************* END OF PARAMETERS CALCULATION ************************** |
|
2800 | #********************* END OF PARAMETERS CALCULATION ************************** | |
2801 |
|
2801 | |||
2802 | #***************************+ PASS DATA TO NEXT STEP ********************** |
|
2802 | #***************************+ PASS DATA TO NEXT STEP ********************** | |
2803 | # arrayFinal = arrayParameters.reshape((1,arrayParameters.shape[0],arrayParameters.shape[1])) |
|
2803 | # arrayFinal = arrayParameters.reshape((1,arrayParameters.shape[0],arrayParameters.shape[1])) | |
2804 | dataOut.data_param = arrayParameters |
|
2804 | dataOut.data_param = arrayParameters | |
2805 |
|
2805 | |||
2806 | if arrayParameters is None: |
|
2806 | if arrayParameters is None: | |
2807 | dataOut.flagNoData = True |
|
2807 | dataOut.flagNoData = True | |
2808 | else: |
|
2808 | else: | |
2809 | dataOut.flagNoData = True |
|
2809 | dataOut.flagNoData = True | |
2810 |
|
2810 | |||
2811 | return |
|
2811 | return | |
2812 |
|
2812 | |||
2813 | def __getHardwarePhaseDiff(self, voltage0, pairslist, newheis, n): |
|
2813 | def __getHardwarePhaseDiff(self, voltage0, pairslist, newheis, n): | |
2814 |
|
2814 | |||
2815 | minIndex = min(newheis[0]) |
|
2815 | minIndex = min(newheis[0]) | |
2816 | maxIndex = max(newheis[0]) |
|
2816 | maxIndex = max(newheis[0]) | |
2817 |
|
2817 | |||
2818 | voltage = voltage0[:,:,minIndex:maxIndex+1] |
|
2818 | voltage = voltage0[:,:,minIndex:maxIndex+1] | |
2819 | nLength = voltage.shape[1]/n |
|
2819 | nLength = voltage.shape[1]/n | |
2820 | nMin = 0 |
|
2820 | nMin = 0 | |
2821 | nMax = 0 |
|
2821 | nMax = 0 | |
2822 | phaseOffset = numpy.zeros((len(pairslist),n)) |
|
2822 | phaseOffset = numpy.zeros((len(pairslist),n)) | |
2823 |
|
2823 | |||
2824 | for i in range(n): |
|
2824 | for i in range(n): | |
2825 | nMax += nLength |
|
2825 | nMax += nLength | |
2826 | phaseCCF = -numpy.angle(self.__calculateCCF(voltage[:,nMin:nMax,:], pairslist, [0])) |
|
2826 | phaseCCF = -numpy.angle(self.__calculateCCF(voltage[:,nMin:nMax,:], pairslist, [0])) | |
2827 | phaseCCF = numpy.mean(phaseCCF, axis = 2) |
|
2827 | phaseCCF = numpy.mean(phaseCCF, axis = 2) | |
2828 | phaseOffset[:,i] = phaseCCF.transpose() |
|
2828 | phaseOffset[:,i] = phaseCCF.transpose() | |
2829 | nMin = nMax |
|
2829 | nMin = nMax | |
2830 | # phaseDiff, phaseArrival = self.estimatePhaseDifference(voltage, pairslist) |
|
2830 | # phaseDiff, phaseArrival = self.estimatePhaseDifference(voltage, pairslist) | |
2831 |
|
2831 | |||
2832 | #Remove Outliers |
|
2832 | #Remove Outliers | |
2833 | factor = 2 |
|
2833 | factor = 2 | |
2834 | wt = phaseOffset - signal.medfilt(phaseOffset,(1,5)) |
|
2834 | wt = phaseOffset - signal.medfilt(phaseOffset,(1,5)) | |
2835 | dw = numpy.std(wt,axis = 1) |
|
2835 | dw = numpy.std(wt,axis = 1) | |
2836 | dw = dw.reshape((dw.size,1)) |
|
2836 | dw = dw.reshape((dw.size,1)) | |
2837 | ind = numpy.where(numpy.logical_or(wt>dw*factor,wt<-dw*factor)) |
|
2837 | ind = numpy.where(numpy.logical_or(wt>dw*factor,wt<-dw*factor)) | |
2838 | phaseOffset[ind] = numpy.nan |
|
2838 | phaseOffset[ind] = numpy.nan | |
2839 | phaseOffset = stats.nanmean(phaseOffset, axis=1) |
|
2839 | phaseOffset = stats.nanmean(phaseOffset, axis=1) | |
2840 |
|
2840 | |||
2841 | return phaseOffset |
|
2841 | return phaseOffset | |
2842 |
|
2842 | |||
2843 | def __shiftPhase(self, data, phaseShift): |
|
2843 | def __shiftPhase(self, data, phaseShift): | |
2844 | #this will shift the phase of a complex number |
|
2844 | #this will shift the phase of a complex number | |
2845 | dataShifted = numpy.abs(data) * numpy.exp((numpy.angle(data)+phaseShift)*1j) |
|
2845 | dataShifted = numpy.abs(data) * numpy.exp((numpy.angle(data)+phaseShift)*1j) | |
2846 | return dataShifted |
|
2846 | return dataShifted | |
2847 |
|
2847 | |||
2848 | def __estimatePhaseDifference(self, array, pairslist): |
|
2848 | def __estimatePhaseDifference(self, array, pairslist): | |
2849 | nChannel = array.shape[0] |
|
2849 | nChannel = array.shape[0] | |
2850 | nHeights = array.shape[2] |
|
2850 | nHeights = array.shape[2] | |
2851 | numPairs = len(pairslist) |
|
2851 | numPairs = len(pairslist) | |
2852 | # phaseCCF = numpy.zeros((nChannel, 5, nHeights)) |
|
2852 | # phaseCCF = numpy.zeros((nChannel, 5, nHeights)) | |
2853 | phaseCCF = numpy.angle(self.__calculateCCF(array, pairslist, [-2,-1,0,1,2])) |
|
2853 | phaseCCF = numpy.angle(self.__calculateCCF(array, pairslist, [-2,-1,0,1,2])) | |
2854 |
|
2854 | |||
2855 | #Correct phases |
|
2855 | #Correct phases | |
2856 | derPhaseCCF = phaseCCF[:,1:,:] - phaseCCF[:,0:-1,:] |
|
2856 | derPhaseCCF = phaseCCF[:,1:,:] - phaseCCF[:,0:-1,:] | |
2857 | indDer = numpy.where(numpy.abs(derPhaseCCF) > numpy.pi) |
|
2857 | indDer = numpy.where(numpy.abs(derPhaseCCF) > numpy.pi) | |
2858 |
|
2858 | |||
2859 | if indDer[0].shape[0] > 0: |
|
2859 | if indDer[0].shape[0] > 0: | |
2860 | for i in range(indDer[0].shape[0]): |
|
2860 | for i in range(indDer[0].shape[0]): | |
2861 | signo = -numpy.sign(derPhaseCCF[indDer[0][i],indDer[1][i],indDer[2][i]]) |
|
2861 | signo = -numpy.sign(derPhaseCCF[indDer[0][i],indDer[1][i],indDer[2][i]]) | |
2862 | phaseCCF[indDer[0][i],indDer[1][i]+1:,:] += signo*2*numpy.pi |
|
2862 | phaseCCF[indDer[0][i],indDer[1][i]+1:,:] += signo*2*numpy.pi | |
2863 |
|
2863 | |||
2864 | # for j in range(numSides): |
|
2864 | # for j in range(numSides): | |
2865 | # phaseCCFAux = self.calculateCCF(arrayCenter, arraySides[j,:,:], [-2,1,0,1,2]) |
|
2865 | # phaseCCFAux = self.calculateCCF(arrayCenter, arraySides[j,:,:], [-2,1,0,1,2]) | |
2866 | # phaseCCF[j,:,:] = numpy.angle(phaseCCFAux) |
|
2866 | # phaseCCF[j,:,:] = numpy.angle(phaseCCFAux) | |
2867 | # |
|
2867 | # | |
2868 | #Linear |
|
2868 | #Linear | |
2869 | phaseInt = numpy.zeros((numPairs,1)) |
|
2869 | phaseInt = numpy.zeros((numPairs,1)) | |
2870 | angAllCCF = phaseCCF[:,[0,1,3,4],0] |
|
2870 | angAllCCF = phaseCCF[:,[0,1,3,4],0] | |
2871 | for j in range(numPairs): |
|
2871 | for j in range(numPairs): | |
2872 | fit = stats.linregress([-2,-1,1,2],angAllCCF[j,:]) |
|
2872 | fit = stats.linregress([-2,-1,1,2],angAllCCF[j,:]) | |
2873 | phaseInt[j] = fit[1] |
|
2873 | phaseInt[j] = fit[1] | |
2874 | #Phase Differences |
|
2874 | #Phase Differences | |
2875 | phaseDiff = phaseInt - phaseCCF[:,2,:] |
|
2875 | phaseDiff = phaseInt - phaseCCF[:,2,:] | |
2876 | phaseArrival = phaseInt.reshape(phaseInt.size) |
|
2876 | phaseArrival = phaseInt.reshape(phaseInt.size) | |
2877 |
|
2877 | |||
2878 | #Dealias |
|
2878 | #Dealias | |
2879 | phaseArrival = numpy.angle(numpy.exp(1j*phaseArrival)) |
|
2879 | phaseArrival = numpy.angle(numpy.exp(1j*phaseArrival)) | |
2880 | # indAlias = numpy.where(phaseArrival > numpy.pi) |
|
2880 | # indAlias = numpy.where(phaseArrival > numpy.pi) | |
2881 | # phaseArrival[indAlias] -= 2*numpy.pi |
|
2881 | # phaseArrival[indAlias] -= 2*numpy.pi | |
2882 | # indAlias = numpy.where(phaseArrival < -numpy.pi) |
|
2882 | # indAlias = numpy.where(phaseArrival < -numpy.pi) | |
2883 | # phaseArrival[indAlias] += 2*numpy.pi |
|
2883 | # phaseArrival[indAlias] += 2*numpy.pi | |
2884 |
|
2884 | |||
2885 | return phaseDiff, phaseArrival |
|
2885 | return phaseDiff, phaseArrival | |
2886 |
|
2886 | |||
2887 | def __coherentDetection(self, volts, timeSegment, timeInterval, pairslist, thresh): |
|
2887 | def __coherentDetection(self, volts, timeSegment, timeInterval, pairslist, thresh): | |
2888 | #this function will run the coherent detection used in Holdworth et al. 2004 and return the net power |
|
2888 | #this function will run the coherent detection used in Holdworth et al. 2004 and return the net power | |
2889 | #find the phase shifts of each channel over 1 second intervals |
|
2889 | #find the phase shifts of each channel over 1 second intervals | |
2890 | #only look at ranges below the beacon signal |
|
2890 | #only look at ranges below the beacon signal | |
2891 | numProfPerBlock = numpy.ceil(timeSegment/timeInterval) |
|
2891 | numProfPerBlock = numpy.ceil(timeSegment/timeInterval) | |
2892 | numBlocks = int(volts.shape[1]/numProfPerBlock) |
|
2892 | numBlocks = int(volts.shape[1]/numProfPerBlock) | |
2893 | numHeights = volts.shape[2] |
|
2893 | numHeights = volts.shape[2] | |
2894 | nChannel = volts.shape[0] |
|
2894 | nChannel = volts.shape[0] | |
2895 | voltsCohDet = volts.copy() |
|
2895 | voltsCohDet = volts.copy() | |
2896 |
|
2896 | |||
2897 | pairsarray = numpy.array(pairslist) |
|
2897 | pairsarray = numpy.array(pairslist) | |
2898 | indSides = pairsarray[:,1] |
|
2898 | indSides = pairsarray[:,1] | |
2899 | # indSides = numpy.array(range(nChannel)) |
|
2899 | # indSides = numpy.array(range(nChannel)) | |
2900 | # indSides = numpy.delete(indSides, indCenter) |
|
2900 | # indSides = numpy.delete(indSides, indCenter) | |
2901 | # |
|
2901 | # | |
2902 | # listCenter = numpy.array_split(volts[indCenter,:,:], numBlocks, 0) |
|
2902 | # listCenter = numpy.array_split(volts[indCenter,:,:], numBlocks, 0) | |
2903 | listBlocks = numpy.array_split(volts, numBlocks, 1) |
|
2903 | listBlocks = numpy.array_split(volts, numBlocks, 1) | |
2904 |
|
2904 | |||
2905 | startInd = 0 |
|
2905 | startInd = 0 | |
2906 | endInd = 0 |
|
2906 | endInd = 0 | |
2907 |
|
2907 | |||
2908 | for i in range(numBlocks): |
|
2908 | for i in range(numBlocks): | |
2909 | startInd = endInd |
|
2909 | startInd = endInd | |
2910 | endInd = endInd + listBlocks[i].shape[1] |
|
2910 | endInd = endInd + listBlocks[i].shape[1] | |
2911 |
|
2911 | |||
2912 | arrayBlock = listBlocks[i] |
|
2912 | arrayBlock = listBlocks[i] | |
2913 | # arrayBlockCenter = listCenter[i] |
|
2913 | # arrayBlockCenter = listCenter[i] | |
2914 |
|
2914 | |||
2915 | #Estimate the Phase Difference |
|
2915 | #Estimate the Phase Difference | |
2916 | phaseDiff, aux = self.__estimatePhaseDifference(arrayBlock, pairslist) |
|
2916 | phaseDiff, aux = self.__estimatePhaseDifference(arrayBlock, pairslist) | |
2917 | #Phase Difference RMS |
|
2917 | #Phase Difference RMS | |
2918 | arrayPhaseRMS = numpy.abs(phaseDiff) |
|
2918 | arrayPhaseRMS = numpy.abs(phaseDiff) | |
2919 | phaseRMSaux = numpy.sum(arrayPhaseRMS < thresh,0) |
|
2919 | phaseRMSaux = numpy.sum(arrayPhaseRMS < thresh,0) | |
2920 | indPhase = numpy.where(phaseRMSaux==4) |
|
2920 | indPhase = numpy.where(phaseRMSaux==4) | |
2921 | #Shifting |
|
2921 | #Shifting | |
2922 | if indPhase[0].shape[0] > 0: |
|
2922 | if indPhase[0].shape[0] > 0: | |
2923 | for j in range(indSides.size): |
|
2923 | for j in range(indSides.size): | |
2924 | arrayBlock[indSides[j],:,indPhase] = self.__shiftPhase(arrayBlock[indSides[j],:,indPhase], phaseDiff[j,indPhase].transpose()) |
|
2924 | arrayBlock[indSides[j],:,indPhase] = self.__shiftPhase(arrayBlock[indSides[j],:,indPhase], phaseDiff[j,indPhase].transpose()) | |
2925 | voltsCohDet[:,startInd:endInd,:] = arrayBlock |
|
2925 | voltsCohDet[:,startInd:endInd,:] = arrayBlock | |
2926 |
|
2926 | |||
2927 | return voltsCohDet |
|
2927 | return voltsCohDet | |
2928 |
|
2928 | |||
2929 | def __calculateCCF(self, volts, pairslist ,laglist): |
|
2929 | def __calculateCCF(self, volts, pairslist ,laglist): | |
2930 |
|
2930 | |||
2931 | nHeights = volts.shape[2] |
|
2931 | nHeights = volts.shape[2] | |
2932 | nPoints = volts.shape[1] |
|
2932 | nPoints = volts.shape[1] | |
2933 | voltsCCF = numpy.zeros((len(pairslist), len(laglist), nHeights),dtype = 'complex') |
|
2933 | voltsCCF = numpy.zeros((len(pairslist), len(laglist), nHeights),dtype = 'complex') | |
2934 |
|
2934 | |||
2935 | for i in range(len(pairslist)): |
|
2935 | for i in range(len(pairslist)): | |
2936 | volts1 = volts[pairslist[i][0]] |
|
2936 | volts1 = volts[pairslist[i][0]] | |
2937 | volts2 = volts[pairslist[i][1]] |
|
2937 | volts2 = volts[pairslist[i][1]] | |
2938 |
|
2938 | |||
2939 | for t in range(len(laglist)): |
|
2939 | for t in range(len(laglist)): | |
2940 | idxT = laglist[t] |
|
2940 | idxT = laglist[t] | |
2941 | if idxT >= 0: |
|
2941 | if idxT >= 0: | |
2942 | vStacked = numpy.vstack((volts2[idxT:,:], |
|
2942 | vStacked = numpy.vstack((volts2[idxT:,:], | |
2943 | numpy.zeros((idxT, nHeights),dtype='complex'))) |
|
2943 | numpy.zeros((idxT, nHeights),dtype='complex'))) | |
2944 | else: |
|
2944 | else: | |
2945 | vStacked = numpy.vstack((numpy.zeros((-idxT, nHeights),dtype='complex'), |
|
2945 | vStacked = numpy.vstack((numpy.zeros((-idxT, nHeights),dtype='complex'), | |
2946 | volts2[:(nPoints + idxT),:])) |
|
2946 | volts2[:(nPoints + idxT),:])) | |
2947 | voltsCCF[i,t,:] = numpy.sum((numpy.conjugate(volts1)*vStacked),axis=0) |
|
2947 | voltsCCF[i,t,:] = numpy.sum((numpy.conjugate(volts1)*vStacked),axis=0) | |
2948 |
|
2948 | |||
2949 | vStacked = None |
|
2949 | vStacked = None | |
2950 | return voltsCCF |
|
2950 | return voltsCCF | |
2951 |
|
2951 | |||
2952 | def __getNoise(self, power, timeSegment, timeInterval): |
|
2952 | def __getNoise(self, power, timeSegment, timeInterval): | |
2953 | numProfPerBlock = numpy.ceil(timeSegment/timeInterval) |
|
2953 | numProfPerBlock = numpy.ceil(timeSegment/timeInterval) | |
2954 | numBlocks = int(power.shape[0]/numProfPerBlock) |
|
2954 | numBlocks = int(power.shape[0]/numProfPerBlock) | |
2955 | numHeights = power.shape[1] |
|
2955 | numHeights = power.shape[1] | |
2956 |
|
2956 | |||
2957 | listPower = numpy.array_split(power, numBlocks, 0) |
|
2957 | listPower = numpy.array_split(power, numBlocks, 0) | |
2958 | noise = numpy.zeros((power.shape[0], power.shape[1])) |
|
2958 | noise = numpy.zeros((power.shape[0], power.shape[1])) | |
2959 | noise1 = numpy.zeros((power.shape[0], power.shape[1])) |
|
2959 | noise1 = numpy.zeros((power.shape[0], power.shape[1])) | |
2960 |
|
2960 | |||
2961 | startInd = 0 |
|
2961 | startInd = 0 | |
2962 | endInd = 0 |
|
2962 | endInd = 0 | |
2963 |
|
2963 | |||
2964 | for i in range(numBlocks): #split por canal |
|
2964 | for i in range(numBlocks): #split por canal | |
2965 | startInd = endInd |
|
2965 | startInd = endInd | |
2966 | endInd = endInd + listPower[i].shape[0] |
|
2966 | endInd = endInd + listPower[i].shape[0] | |
2967 |
|
2967 | |||
2968 | arrayBlock = listPower[i] |
|
2968 | arrayBlock = listPower[i] | |
2969 | noiseAux = numpy.mean(arrayBlock, 0) |
|
2969 | noiseAux = numpy.mean(arrayBlock, 0) | |
2970 | # noiseAux = numpy.median(noiseAux) |
|
2970 | # noiseAux = numpy.median(noiseAux) | |
2971 | # noiseAux = numpy.mean(arrayBlock) |
|
2971 | # noiseAux = numpy.mean(arrayBlock) | |
2972 | noise[startInd:endInd,:] = noise[startInd:endInd,:] + noiseAux |
|
2972 | noise[startInd:endInd,:] = noise[startInd:endInd,:] + noiseAux | |
2973 |
|
2973 | |||
2974 | noiseAux1 = numpy.mean(arrayBlock) |
|
2974 | noiseAux1 = numpy.mean(arrayBlock) | |
2975 | noise1[startInd:endInd,:] = noise1[startInd:endInd,:] + noiseAux1 |
|
2975 | noise1[startInd:endInd,:] = noise1[startInd:endInd,:] + noiseAux1 | |
2976 |
|
2976 | |||
2977 | return noise, noise1 |
|
2977 | return noise, noise1 | |
2978 |
|
2978 | |||
2979 | def __findMeteors(self, power, thresh): |
|
2979 | def __findMeteors(self, power, thresh): | |
2980 | nProf = power.shape[0] |
|
2980 | nProf = power.shape[0] | |
2981 | nHeights = power.shape[1] |
|
2981 | nHeights = power.shape[1] | |
2982 | listMeteors = [] |
|
2982 | listMeteors = [] | |
2983 |
|
2983 | |||
2984 | for i in range(nHeights): |
|
2984 | for i in range(nHeights): | |
2985 | powerAux = power[:,i] |
|
2985 | powerAux = power[:,i] | |
2986 | threshAux = thresh[:,i] |
|
2986 | threshAux = thresh[:,i] | |
2987 |
|
2987 | |||
2988 | indUPthresh = numpy.where(powerAux > threshAux)[0] |
|
2988 | indUPthresh = numpy.where(powerAux > threshAux)[0] | |
2989 | indDNthresh = numpy.where(powerAux <= threshAux)[0] |
|
2989 | indDNthresh = numpy.where(powerAux <= threshAux)[0] | |
2990 |
|
2990 | |||
2991 | j = 0 |
|
2991 | j = 0 | |
2992 |
|
2992 | |||
2993 | while (j < indUPthresh.size - 2): |
|
2993 | while (j < indUPthresh.size - 2): | |
2994 | if (indUPthresh[j + 2] == indUPthresh[j] + 2): |
|
2994 | if (indUPthresh[j + 2] == indUPthresh[j] + 2): | |
2995 | indDNAux = numpy.where(indDNthresh > indUPthresh[j]) |
|
2995 | indDNAux = numpy.where(indDNthresh > indUPthresh[j]) | |
2996 | indDNthresh = indDNthresh[indDNAux] |
|
2996 | indDNthresh = indDNthresh[indDNAux] | |
2997 |
|
2997 | |||
2998 | if (indDNthresh.size > 0): |
|
2998 | if (indDNthresh.size > 0): | |
2999 | indEnd = indDNthresh[0] - 1 |
|
2999 | indEnd = indDNthresh[0] - 1 | |
3000 | indInit = indUPthresh[j] |
|
3000 | indInit = indUPthresh[j] | |
3001 |
|
3001 | |||
3002 | meteor = powerAux[indInit:indEnd + 1] |
|
3002 | meteor = powerAux[indInit:indEnd + 1] | |
3003 | indPeak = meteor.argmax() + indInit |
|
3003 | indPeak = meteor.argmax() + indInit | |
3004 | FLA = sum(numpy.conj(meteor)*numpy.hstack((meteor[1:],0))) |
|
3004 | FLA = sum(numpy.conj(meteor)*numpy.hstack((meteor[1:],0))) | |
3005 |
|
3005 | |||
3006 | listMeteors.append(numpy.array([i,indInit,indPeak,indEnd,FLA])) #CHEQUEAR!!!!! |
|
3006 | listMeteors.append(numpy.array([i,indInit,indPeak,indEnd,FLA])) #CHEQUEAR!!!!! | |
3007 | j = numpy.where(indUPthresh == indEnd)[0] + 1 |
|
3007 | j = numpy.where(indUPthresh == indEnd)[0] + 1 | |
3008 | else: j+=1 |
|
3008 | else: j+=1 | |
3009 | else: j+=1 |
|
3009 | else: j+=1 | |
3010 |
|
3010 | |||
3011 | return listMeteors |
|
3011 | return listMeteors | |
3012 |
|
3012 | |||
3013 | def __removeMultipleDetections(self,listMeteors, rangeLimit, timeLimit): |
|
3013 | def __removeMultipleDetections(self,listMeteors, rangeLimit, timeLimit): | |
3014 |
|
3014 | |||
3015 | arrayMeteors = numpy.asarray(listMeteors) |
|
3015 | arrayMeteors = numpy.asarray(listMeteors) | |
3016 | listMeteors1 = [] |
|
3016 | listMeteors1 = [] | |
3017 |
|
3017 | |||
3018 | while arrayMeteors.shape[0] > 0: |
|
3018 | while arrayMeteors.shape[0] > 0: | |
3019 | FLAs = arrayMeteors[:,4] |
|
3019 | FLAs = arrayMeteors[:,4] | |
3020 | maxFLA = FLAs.argmax() |
|
3020 | maxFLA = FLAs.argmax() | |
3021 | listMeteors1.append(arrayMeteors[maxFLA,:]) |
|
3021 | listMeteors1.append(arrayMeteors[maxFLA,:]) | |
3022 |
|
3022 | |||
3023 | MeteorInitTime = arrayMeteors[maxFLA,1] |
|
3023 | MeteorInitTime = arrayMeteors[maxFLA,1] | |
3024 | MeteorEndTime = arrayMeteors[maxFLA,3] |
|
3024 | MeteorEndTime = arrayMeteors[maxFLA,3] | |
3025 | MeteorHeight = arrayMeteors[maxFLA,0] |
|
3025 | MeteorHeight = arrayMeteors[maxFLA,0] | |
3026 |
|
3026 | |||
3027 | #Check neighborhood |
|
3027 | #Check neighborhood | |
3028 | maxHeightIndex = MeteorHeight + rangeLimit |
|
3028 | maxHeightIndex = MeteorHeight + rangeLimit | |
3029 | minHeightIndex = MeteorHeight - rangeLimit |
|
3029 | minHeightIndex = MeteorHeight - rangeLimit | |
3030 | minTimeIndex = MeteorInitTime - timeLimit |
|
3030 | minTimeIndex = MeteorInitTime - timeLimit | |
3031 | maxTimeIndex = MeteorEndTime + timeLimit |
|
3031 | maxTimeIndex = MeteorEndTime + timeLimit | |
3032 |
|
3032 | |||
3033 | #Check Heights |
|
3033 | #Check Heights | |
3034 | indHeight = numpy.logical_and(arrayMeteors[:,0] >= minHeightIndex, arrayMeteors[:,0] <= maxHeightIndex) |
|
3034 | indHeight = numpy.logical_and(arrayMeteors[:,0] >= minHeightIndex, arrayMeteors[:,0] <= maxHeightIndex) | |
3035 | indTime = numpy.logical_and(arrayMeteors[:,3] >= minTimeIndex, arrayMeteors[:,1] <= maxTimeIndex) |
|
3035 | indTime = numpy.logical_and(arrayMeteors[:,3] >= minTimeIndex, arrayMeteors[:,1] <= maxTimeIndex) | |
3036 | indBoth = numpy.where(numpy.logical_and(indTime,indHeight)) |
|
3036 | indBoth = numpy.where(numpy.logical_and(indTime,indHeight)) | |
3037 |
|
3037 | |||
3038 | arrayMeteors = numpy.delete(arrayMeteors, indBoth, axis = 0) |
|
3038 | arrayMeteors = numpy.delete(arrayMeteors, indBoth, axis = 0) | |
3039 |
|
3039 | |||
3040 | return listMeteors1 |
|
3040 | return listMeteors1 | |
3041 |
|
3041 | |||
3042 | def __meteorReestimation(self, listMeteors, volts, pairslist, thresh, noise, timeInterval,frequency): |
|
3042 | def __meteorReestimation(self, listMeteors, volts, pairslist, thresh, noise, timeInterval,frequency): | |
3043 | numHeights = volts.shape[2] |
|
3043 | numHeights = volts.shape[2] | |
3044 | nChannel = volts.shape[0] |
|
3044 | nChannel = volts.shape[0] | |
3045 |
|
3045 | |||
3046 | thresholdPhase = thresh[0] |
|
3046 | thresholdPhase = thresh[0] | |
3047 | thresholdNoise = thresh[1] |
|
3047 | thresholdNoise = thresh[1] | |
3048 | thresholdDB = float(thresh[2]) |
|
3048 | thresholdDB = float(thresh[2]) | |
3049 |
|
3049 | |||
3050 | thresholdDB1 = 10**(thresholdDB/10) |
|
3050 | thresholdDB1 = 10**(thresholdDB/10) | |
3051 | pairsarray = numpy.array(pairslist) |
|
3051 | pairsarray = numpy.array(pairslist) | |
3052 | indSides = pairsarray[:,1] |
|
3052 | indSides = pairsarray[:,1] | |
3053 |
|
3053 | |||
3054 | pairslist1 = list(pairslist) |
|
3054 | pairslist1 = list(pairslist) | |
3055 | pairslist1.append((0,1)) |
|
3055 | pairslist1.append((0,1)) | |
3056 | pairslist1.append((3,4)) |
|
3056 | pairslist1.append((3,4)) | |
3057 |
|
3057 | |||
3058 | listMeteors1 = [] |
|
3058 | listMeteors1 = [] | |
3059 | listPowerSeries = [] |
|
3059 | listPowerSeries = [] | |
3060 | listVoltageSeries = [] |
|
3060 | listVoltageSeries = [] | |
3061 | #volts has the war data |
|
3061 | #volts has the war data | |
3062 |
|
3062 | |||
3063 | if frequency == 30e6: |
|
3063 | if frequency == 30e6: | |
3064 | timeLag = 45*10**-3 |
|
3064 | timeLag = 45*10**-3 | |
3065 | else: |
|
3065 | else: | |
3066 | timeLag = 15*10**-3 |
|
3066 | timeLag = 15*10**-3 | |
3067 | lag = numpy.ceil(timeLag/timeInterval) |
|
3067 | lag = numpy.ceil(timeLag/timeInterval) | |
3068 |
|
3068 | |||
3069 | for i in range(len(listMeteors)): |
|
3069 | for i in range(len(listMeteors)): | |
3070 |
|
3070 | |||
3071 | ###################### 3.6 - 3.7 PARAMETERS REESTIMATION ######################### |
|
3071 | ###################### 3.6 - 3.7 PARAMETERS REESTIMATION ######################### | |
3072 | meteorAux = numpy.zeros(16) |
|
3072 | meteorAux = numpy.zeros(16) | |
3073 |
|
3073 | |||
3074 | #Loading meteor Data (mHeight, mStart, mPeak, mEnd) |
|
3074 | #Loading meteor Data (mHeight, mStart, mPeak, mEnd) | |
3075 | mHeight = listMeteors[i][0] |
|
3075 | mHeight = listMeteors[i][0] | |
3076 | mStart = listMeteors[i][1] |
|
3076 | mStart = listMeteors[i][1] | |
3077 | mPeak = listMeteors[i][2] |
|
3077 | mPeak = listMeteors[i][2] | |
3078 | mEnd = listMeteors[i][3] |
|
3078 | mEnd = listMeteors[i][3] | |
3079 |
|
3079 | |||
3080 | #get the volt data between the start and end times of the meteor |
|
3080 | #get the volt data between the start and end times of the meteor | |
3081 | meteorVolts = volts[:,mStart:mEnd+1,mHeight] |
|
3081 | meteorVolts = volts[:,mStart:mEnd+1,mHeight] | |
3082 | meteorVolts = meteorVolts.reshape(meteorVolts.shape[0], meteorVolts.shape[1], 1) |
|
3082 | meteorVolts = meteorVolts.reshape(meteorVolts.shape[0], meteorVolts.shape[1], 1) | |
3083 |
|
3083 | |||
3084 | #3.6. Phase Difference estimation |
|
3084 | #3.6. Phase Difference estimation | |
3085 | phaseDiff, aux = self.__estimatePhaseDifference(meteorVolts, pairslist) |
|
3085 | phaseDiff, aux = self.__estimatePhaseDifference(meteorVolts, pairslist) | |
3086 |
|
3086 | |||
3087 | #3.7. Phase difference removal & meteor start, peak and end times reestimated |
|
3087 | #3.7. Phase difference removal & meteor start, peak and end times reestimated | |
3088 | #meteorVolts0.- all Channels, all Profiles |
|
3088 | #meteorVolts0.- all Channels, all Profiles | |
3089 | meteorVolts0 = volts[:,:,mHeight] |
|
3089 | meteorVolts0 = volts[:,:,mHeight] | |
3090 | meteorThresh = noise[:,mHeight]*thresholdNoise |
|
3090 | meteorThresh = noise[:,mHeight]*thresholdNoise | |
3091 | meteorNoise = noise[:,mHeight] |
|
3091 | meteorNoise = noise[:,mHeight] | |
3092 | meteorVolts0[indSides,:] = self.__shiftPhase(meteorVolts0[indSides,:], phaseDiff) #Phase Shifting |
|
3092 | meteorVolts0[indSides,:] = self.__shiftPhase(meteorVolts0[indSides,:], phaseDiff) #Phase Shifting | |
3093 | powerNet0 = numpy.nansum(numpy.abs(meteorVolts0)**2, axis = 0) #Power |
|
3093 | powerNet0 = numpy.nansum(numpy.abs(meteorVolts0)**2, axis = 0) #Power | |
3094 |
|
3094 | |||
3095 | #Times reestimation |
|
3095 | #Times reestimation | |
3096 | mStart1 = numpy.where(powerNet0[:mPeak] < meteorThresh[:mPeak])[0] |
|
3096 | mStart1 = numpy.where(powerNet0[:mPeak] < meteorThresh[:mPeak])[0] | |
3097 | if mStart1.size > 0: |
|
3097 | if mStart1.size > 0: | |
3098 | mStart1 = mStart1[-1] + 1 |
|
3098 | mStart1 = mStart1[-1] + 1 | |
3099 |
|
3099 | |||
3100 | else: |
|
3100 | else: | |
3101 | mStart1 = mPeak |
|
3101 | mStart1 = mPeak | |
3102 |
|
3102 | |||
3103 | mEnd1 = numpy.where(powerNet0[mPeak:] < meteorThresh[mPeak:])[0][0] + mPeak - 1 |
|
3103 | mEnd1 = numpy.where(powerNet0[mPeak:] < meteorThresh[mPeak:])[0][0] + mPeak - 1 | |
3104 | mEndDecayTime1 = numpy.where(powerNet0[mPeak:] < meteorNoise[mPeak:])[0] |
|
3104 | mEndDecayTime1 = numpy.where(powerNet0[mPeak:] < meteorNoise[mPeak:])[0] | |
3105 | if mEndDecayTime1.size == 0: |
|
3105 | if mEndDecayTime1.size == 0: | |
3106 | mEndDecayTime1 = powerNet0.size |
|
3106 | mEndDecayTime1 = powerNet0.size | |
3107 | else: |
|
3107 | else: | |
3108 | mEndDecayTime1 = mEndDecayTime1[0] + mPeak - 1 |
|
3108 | mEndDecayTime1 = mEndDecayTime1[0] + mPeak - 1 | |
3109 | # mPeak1 = meteorVolts0[mStart1:mEnd1 + 1].argmax() |
|
3109 | # mPeak1 = meteorVolts0[mStart1:mEnd1 + 1].argmax() | |
3110 |
|
3110 | |||
3111 | #meteorVolts1.- all Channels, from start to end |
|
3111 | #meteorVolts1.- all Channels, from start to end | |
3112 | meteorVolts1 = meteorVolts0[:,mStart1:mEnd1 + 1] |
|
3112 | meteorVolts1 = meteorVolts0[:,mStart1:mEnd1 + 1] | |
3113 | meteorVolts2 = meteorVolts0[:,mPeak + lag:mEnd1 + 1] |
|
3113 | meteorVolts2 = meteorVolts0[:,mPeak + lag:mEnd1 + 1] | |
3114 | if meteorVolts2.shape[1] == 0: |
|
3114 | if meteorVolts2.shape[1] == 0: | |
3115 | meteorVolts2 = meteorVolts0[:,mPeak:mEnd1 + 1] |
|
3115 | meteorVolts2 = meteorVolts0[:,mPeak:mEnd1 + 1] | |
3116 | meteorVolts1 = meteorVolts1.reshape(meteorVolts1.shape[0], meteorVolts1.shape[1], 1) |
|
3116 | meteorVolts1 = meteorVolts1.reshape(meteorVolts1.shape[0], meteorVolts1.shape[1], 1) | |
3117 | meteorVolts2 = meteorVolts2.reshape(meteorVolts2.shape[0], meteorVolts2.shape[1], 1) |
|
3117 | meteorVolts2 = meteorVolts2.reshape(meteorVolts2.shape[0], meteorVolts2.shape[1], 1) | |
3118 | ##################### END PARAMETERS REESTIMATION ######################### |
|
3118 | ##################### END PARAMETERS REESTIMATION ######################### | |
3119 |
|
3119 | |||
3120 | ##################### 3.8 PHASE DIFFERENCE REESTIMATION ######################## |
|
3120 | ##################### 3.8 PHASE DIFFERENCE REESTIMATION ######################## | |
3121 | # if mEnd1 - mStart1 > 4: #Error Number 6: echo less than 5 samples long; too short for analysis |
|
3121 | # if mEnd1 - mStart1 > 4: #Error Number 6: echo less than 5 samples long; too short for analysis | |
3122 | if meteorVolts2.shape[1] > 0: |
|
3122 | if meteorVolts2.shape[1] > 0: | |
3123 | #Phase Difference re-estimation |
|
3123 | #Phase Difference re-estimation | |
3124 | phaseDiff1, phaseDiffint = self.__estimatePhaseDifference(meteorVolts2, pairslist1) #Phase Difference Estimation |
|
3124 | phaseDiff1, phaseDiffint = self.__estimatePhaseDifference(meteorVolts2, pairslist1) #Phase Difference Estimation | |
3125 | # phaseDiff1, phaseDiffint = self.estimatePhaseDifference(meteorVolts2, pairslist) |
|
3125 | # phaseDiff1, phaseDiffint = self.estimatePhaseDifference(meteorVolts2, pairslist) | |
3126 | meteorVolts2 = meteorVolts2.reshape(meteorVolts2.shape[0], meteorVolts2.shape[1]) |
|
3126 | meteorVolts2 = meteorVolts2.reshape(meteorVolts2.shape[0], meteorVolts2.shape[1]) | |
3127 | phaseDiff11 = numpy.reshape(phaseDiff1, (phaseDiff1.shape[0],1)) |
|
3127 | phaseDiff11 = numpy.reshape(phaseDiff1, (phaseDiff1.shape[0],1)) | |
3128 | meteorVolts2[indSides,:] = self.__shiftPhase(meteorVolts2[indSides,:], phaseDiff11[0:4]) #Phase Shifting |
|
3128 | meteorVolts2[indSides,:] = self.__shiftPhase(meteorVolts2[indSides,:], phaseDiff11[0:4]) #Phase Shifting | |
3129 |
|
3129 | |||
3130 | #Phase Difference RMS |
|
3130 | #Phase Difference RMS | |
3131 | phaseRMS1 = numpy.sqrt(numpy.mean(numpy.square(phaseDiff1))) |
|
3131 | phaseRMS1 = numpy.sqrt(numpy.mean(numpy.square(phaseDiff1))) | |
3132 | powerNet1 = numpy.nansum(numpy.abs(meteorVolts1[:,:])**2,0) |
|
3132 | powerNet1 = numpy.nansum(numpy.abs(meteorVolts1[:,:])**2,0) | |
3133 | #Data from Meteor |
|
3133 | #Data from Meteor | |
3134 | mPeak1 = powerNet1.argmax() + mStart1 |
|
3134 | mPeak1 = powerNet1.argmax() + mStart1 | |
3135 | mPeakPower1 = powerNet1.max() |
|
3135 | mPeakPower1 = powerNet1.max() | |
3136 | noiseAux = sum(noise[mStart1:mEnd1 + 1,mHeight]) |
|
3136 | noiseAux = sum(noise[mStart1:mEnd1 + 1,mHeight]) | |
3137 | mSNR1 = (sum(powerNet1)-noiseAux)/noiseAux |
|
3137 | mSNR1 = (sum(powerNet1)-noiseAux)/noiseAux | |
3138 | Meteor1 = numpy.array([mHeight, mStart1, mPeak1, mEnd1, mPeakPower1, mSNR1, phaseRMS1]) |
|
3138 | Meteor1 = numpy.array([mHeight, mStart1, mPeak1, mEnd1, mPeakPower1, mSNR1, phaseRMS1]) | |
3139 | Meteor1 = numpy.hstack((Meteor1,phaseDiffint)) |
|
3139 | Meteor1 = numpy.hstack((Meteor1,phaseDiffint)) | |
3140 | PowerSeries = powerNet0[mStart1:mEndDecayTime1 + 1] |
|
3140 | PowerSeries = powerNet0[mStart1:mEndDecayTime1 + 1] | |
3141 | #Vectorize |
|
3141 | #Vectorize | |
3142 | meteorAux[0:7] = [mHeight, mStart1, mPeak1, mEnd1, mPeakPower1, mSNR1, phaseRMS1] |
|
3142 | meteorAux[0:7] = [mHeight, mStart1, mPeak1, mEnd1, mPeakPower1, mSNR1, phaseRMS1] | |
3143 | meteorAux[7:11] = phaseDiffint[0:4] |
|
3143 | meteorAux[7:11] = phaseDiffint[0:4] | |
3144 |
|
3144 | |||
3145 | #Rejection Criterions |
|
3145 | #Rejection Criterions | |
3146 | if phaseRMS1 > thresholdPhase: #Error Number 17: Phase variation |
|
3146 | if phaseRMS1 > thresholdPhase: #Error Number 17: Phase variation | |
3147 | meteorAux[-1] = 17 |
|
3147 | meteorAux[-1] = 17 | |
3148 | elif mSNR1 < thresholdDB1: #Error Number 1: SNR < threshold dB |
|
3148 | elif mSNR1 < thresholdDB1: #Error Number 1: SNR < threshold dB | |
3149 | meteorAux[-1] = 1 |
|
3149 | meteorAux[-1] = 1 | |
3150 |
|
3150 | |||
3151 |
|
3151 | |||
3152 | else: |
|
3152 | else: | |
3153 | meteorAux[0:4] = [mHeight, mStart, mPeak, mEnd] |
|
3153 | meteorAux[0:4] = [mHeight, mStart, mPeak, mEnd] | |
3154 | meteorAux[-1] = 6 #Error Number 6: echo less than 5 samples long; too short for analysis |
|
3154 | meteorAux[-1] = 6 #Error Number 6: echo less than 5 samples long; too short for analysis | |
3155 | PowerSeries = 0 |
|
3155 | PowerSeries = 0 | |
3156 |
|
3156 | |||
3157 | listMeteors1.append(meteorAux) |
|
3157 | listMeteors1.append(meteorAux) | |
3158 | listPowerSeries.append(PowerSeries) |
|
3158 | listPowerSeries.append(PowerSeries) | |
3159 | listVoltageSeries.append(meteorVolts1) |
|
3159 | listVoltageSeries.append(meteorVolts1) | |
3160 |
|
3160 | |||
3161 | return listMeteors1, listPowerSeries, listVoltageSeries |
|
3161 | return listMeteors1, listPowerSeries, listVoltageSeries | |
3162 |
|
3162 | |||
3163 | def __estimateDecayTime(self, listMeteors, listPower, timeInterval, frequency): |
|
3163 | def __estimateDecayTime(self, listMeteors, listPower, timeInterval, frequency): | |
3164 |
|
3164 | |||
3165 | threshError = 10 |
|
3165 | threshError = 10 | |
3166 | #Depending if it is 30 or 50 MHz |
|
3166 | #Depending if it is 30 or 50 MHz | |
3167 | if frequency == 30e6: |
|
3167 | if frequency == 30e6: | |
3168 | timeLag = 45*10**-3 |
|
3168 | timeLag = 45*10**-3 | |
3169 | else: |
|
3169 | else: | |
3170 | timeLag = 15*10**-3 |
|
3170 | timeLag = 15*10**-3 | |
3171 | lag = numpy.ceil(timeLag/timeInterval) |
|
3171 | lag = numpy.ceil(timeLag/timeInterval) | |
3172 |
|
3172 | |||
3173 | listMeteors1 = [] |
|
3173 | listMeteors1 = [] | |
3174 |
|
3174 | |||
3175 | for i in range(len(listMeteors)): |
|
3175 | for i in range(len(listMeteors)): | |
3176 | meteorPower = listPower[i] |
|
3176 | meteorPower = listPower[i] | |
3177 | meteorAux = listMeteors[i] |
|
3177 | meteorAux = listMeteors[i] | |
3178 |
|
3178 | |||
3179 | if meteorAux[-1] == 0: |
|
3179 | if meteorAux[-1] == 0: | |
3180 |
|
3180 | |||
3181 | try: |
|
3181 | try: | |
3182 | indmax = meteorPower.argmax() |
|
3182 | indmax = meteorPower.argmax() | |
3183 | indlag = indmax + lag |
|
3183 | indlag = indmax + lag | |
3184 |
|
3184 | |||
3185 | y = meteorPower[indlag:] |
|
3185 | y = meteorPower[indlag:] | |
3186 | x = numpy.arange(0, y.size)*timeLag |
|
3186 | x = numpy.arange(0, y.size)*timeLag | |
3187 |
|
3187 | |||
3188 | #first guess |
|
3188 | #first guess | |
3189 | a = y[0] |
|
3189 | a = y[0] | |
3190 | tau = timeLag |
|
3190 | tau = timeLag | |
3191 | #exponential fit |
|
3191 | #exponential fit | |
3192 | popt, pcov = optimize.curve_fit(self.__exponential_function, x, y, p0 = [a, tau]) |
|
3192 | popt, pcov = optimize.curve_fit(self.__exponential_function, x, y, p0 = [a, tau]) | |
3193 | y1 = self.__exponential_function(x, *popt) |
|
3193 | y1 = self.__exponential_function(x, *popt) | |
3194 | #error estimation |
|
3194 | #error estimation | |
3195 | error = sum((y - y1)**2)/(numpy.var(y)*(y.size - popt.size)) |
|
3195 | error = sum((y - y1)**2)/(numpy.var(y)*(y.size - popt.size)) | |
3196 |
|
3196 | |||
3197 | decayTime = popt[1] |
|
3197 | decayTime = popt[1] | |
3198 | riseTime = indmax*timeInterval |
|
3198 | riseTime = indmax*timeInterval | |
3199 | meteorAux[11:13] = [decayTime, error] |
|
3199 | meteorAux[11:13] = [decayTime, error] | |
3200 |
|
3200 | |||
3201 | #Table items 7, 8 and 11 |
|
3201 | #Table items 7, 8 and 11 | |
3202 | if (riseTime > 0.3): #Number 7: Echo rise exceeds 0.3s |
|
3202 | if (riseTime > 0.3): #Number 7: Echo rise exceeds 0.3s | |
3203 | meteorAux[-1] = 7 |
|
3203 | meteorAux[-1] = 7 | |
3204 | elif (decayTime < 2*riseTime) : #Number 8: Echo decay time less than than twice rise time |
|
3204 | elif (decayTime < 2*riseTime) : #Number 8: Echo decay time less than than twice rise time | |
3205 | meteorAux[-1] = 8 |
|
3205 | meteorAux[-1] = 8 | |
3206 | if (error > threshError): #Number 11: Poor fit to amplitude for estimation of decay time |
|
3206 | if (error > threshError): #Number 11: Poor fit to amplitude for estimation of decay time | |
3207 | meteorAux[-1] = 11 |
|
3207 | meteorAux[-1] = 11 | |
3208 |
|
3208 | |||
3209 |
|
3209 | |||
3210 | except: |
|
3210 | except: | |
3211 | meteorAux[-1] = 11 |
|
3211 | meteorAux[-1] = 11 | |
3212 |
|
3212 | |||
3213 |
|
3213 | |||
3214 | listMeteors1.append(meteorAux) |
|
3214 | listMeteors1.append(meteorAux) | |
3215 |
|
3215 | |||
3216 | return listMeteors1 |
|
3216 | return listMeteors1 | |
3217 |
|
3217 | |||
3218 | #Exponential Function |
|
3218 | #Exponential Function | |
3219 |
|
3219 | |||
3220 | def __exponential_function(self, x, a, tau): |
|
3220 | def __exponential_function(self, x, a, tau): | |
3221 | y = a*numpy.exp(-x/tau) |
|
3221 | y = a*numpy.exp(-x/tau) | |
3222 | return y |
|
3222 | return y | |
3223 |
|
3223 | |||
3224 | def __getRadialVelocity(self, listMeteors, listVolts, radialStdThresh, pairslist, timeInterval): |
|
3224 | def __getRadialVelocity(self, listMeteors, listVolts, radialStdThresh, pairslist, timeInterval): | |
3225 |
|
3225 | |||
3226 | pairslist1 = list(pairslist) |
|
3226 | pairslist1 = list(pairslist) | |
3227 | pairslist1.append((0,1)) |
|
3227 | pairslist1.append((0,1)) | |
3228 | pairslist1.append((3,4)) |
|
3228 | pairslist1.append((3,4)) | |
3229 | numPairs = len(pairslist1) |
|
3229 | numPairs = len(pairslist1) | |
3230 | #Time Lag |
|
3230 | #Time Lag | |
3231 | timeLag = 45*10**-3 |
|
3231 | timeLag = 45*10**-3 | |
3232 | c = 3e8 |
|
3232 | c = 3e8 | |
3233 | lag = numpy.ceil(timeLag/timeInterval) |
|
3233 | lag = numpy.ceil(timeLag/timeInterval) | |
3234 | freq = 30e6 |
|
3234 | freq = 30e6 | |
3235 |
|
3235 | |||
3236 | listMeteors1 = [] |
|
3236 | listMeteors1 = [] | |
3237 |
|
3237 | |||
3238 | for i in range(len(listMeteors)): |
|
3238 | for i in range(len(listMeteors)): | |
3239 | meteorAux = listMeteors[i] |
|
3239 | meteorAux = listMeteors[i] | |
3240 | if meteorAux[-1] == 0: |
|
3240 | if meteorAux[-1] == 0: | |
3241 | mStart = listMeteors[i][1] |
|
3241 | mStart = listMeteors[i][1] | |
3242 | mPeak = listMeteors[i][2] |
|
3242 | mPeak = listMeteors[i][2] | |
3243 | mLag = mPeak - mStart + lag |
|
3243 | mLag = mPeak - mStart + lag | |
3244 |
|
3244 | |||
3245 | #get the volt data between the start and end times of the meteor |
|
3245 | #get the volt data between the start and end times of the meteor | |
3246 | meteorVolts = listVolts[i] |
|
3246 | meteorVolts = listVolts[i] | |
3247 | meteorVolts = meteorVolts.reshape(meteorVolts.shape[0], meteorVolts.shape[1], 1) |
|
3247 | meteorVolts = meteorVolts.reshape(meteorVolts.shape[0], meteorVolts.shape[1], 1) | |
3248 |
|
3248 | |||
3249 | #Get CCF |
|
3249 | #Get CCF | |
3250 | allCCFs = self.__calculateCCF(meteorVolts, pairslist1, [-2,-1,0,1,2]) |
|
3250 | allCCFs = self.__calculateCCF(meteorVolts, pairslist1, [-2,-1,0,1,2]) | |
3251 |
|
3251 | |||
3252 | #Method 2 |
|
3252 | #Method 2 | |
3253 | slopes = numpy.zeros(numPairs) |
|
3253 | slopes = numpy.zeros(numPairs) | |
3254 | time = numpy.array([-2,-1,1,2])*timeInterval |
|
3254 | time = numpy.array([-2,-1,1,2])*timeInterval | |
3255 | angAllCCF = numpy.angle(allCCFs[:,[0,1,3,4],0]) |
|
3255 | angAllCCF = numpy.angle(allCCFs[:,[0,1,3,4],0]) | |
3256 |
|
3256 | |||
3257 | #Correct phases |
|
3257 | #Correct phases | |
3258 | derPhaseCCF = angAllCCF[:,1:] - angAllCCF[:,0:-1] |
|
3258 | derPhaseCCF = angAllCCF[:,1:] - angAllCCF[:,0:-1] | |
3259 | indDer = numpy.where(numpy.abs(derPhaseCCF) > numpy.pi) |
|
3259 | indDer = numpy.where(numpy.abs(derPhaseCCF) > numpy.pi) | |
3260 |
|
3260 | |||
3261 | if indDer[0].shape[0] > 0: |
|
3261 | if indDer[0].shape[0] > 0: | |
3262 | for i in range(indDer[0].shape[0]): |
|
3262 | for i in range(indDer[0].shape[0]): | |
3263 | signo = -numpy.sign(derPhaseCCF[indDer[0][i],indDer[1][i]]) |
|
3263 | signo = -numpy.sign(derPhaseCCF[indDer[0][i],indDer[1][i]]) | |
3264 | angAllCCF[indDer[0][i],indDer[1][i]+1:] += signo*2*numpy.pi |
|
3264 | angAllCCF[indDer[0][i],indDer[1][i]+1:] += signo*2*numpy.pi | |
3265 |
|
3265 | |||
3266 | # fit = scipy.stats.linregress(numpy.array([-2,-1,1,2])*timeInterval, numpy.array([phaseLagN2s[i],phaseLagN1s[i],phaseLag1s[i],phaseLag2s[i]])) |
|
3266 | # fit = scipy.stats.linregress(numpy.array([-2,-1,1,2])*timeInterval, numpy.array([phaseLagN2s[i],phaseLagN1s[i],phaseLag1s[i],phaseLag2s[i]])) | |
3267 | for j in range(numPairs): |
|
3267 | for j in range(numPairs): | |
3268 | fit = stats.linregress(time, angAllCCF[j,:]) |
|
3268 | fit = stats.linregress(time, angAllCCF[j,:]) | |
3269 | slopes[j] = fit[0] |
|
3269 | slopes[j] = fit[0] | |
3270 |
|
3270 | |||
3271 | #Remove Outlier |
|
3271 | #Remove Outlier | |
3272 | # indOut = numpy.argmax(numpy.abs(slopes - numpy.mean(slopes))) |
|
3272 | # indOut = numpy.argmax(numpy.abs(slopes - numpy.mean(slopes))) | |
3273 | # slopes = numpy.delete(slopes,indOut) |
|
3273 | # slopes = numpy.delete(slopes,indOut) | |
3274 | # indOut = numpy.argmax(numpy.abs(slopes - numpy.mean(slopes))) |
|
3274 | # indOut = numpy.argmax(numpy.abs(slopes - numpy.mean(slopes))) | |
3275 | # slopes = numpy.delete(slopes,indOut) |
|
3275 | # slopes = numpy.delete(slopes,indOut) | |
3276 |
|
3276 | |||
3277 | radialVelocity = -numpy.mean(slopes)*(0.25/numpy.pi)*(c/freq) |
|
3277 | radialVelocity = -numpy.mean(slopes)*(0.25/numpy.pi)*(c/freq) | |
3278 | radialError = numpy.std(slopes)*(0.25/numpy.pi)*(c/freq) |
|
3278 | radialError = numpy.std(slopes)*(0.25/numpy.pi)*(c/freq) | |
3279 | meteorAux[-2] = radialError |
|
3279 | meteorAux[-2] = radialError | |
3280 | meteorAux[-3] = radialVelocity |
|
3280 | meteorAux[-3] = radialVelocity | |
3281 |
|
3281 | |||
3282 | #Setting Error |
|
3282 | #Setting Error | |
3283 | #Number 15: Radial Drift velocity or projected horizontal velocity exceeds 200 m/s |
|
3283 | #Number 15: Radial Drift velocity or projected horizontal velocity exceeds 200 m/s | |
3284 | if numpy.abs(radialVelocity) > 200: |
|
3284 | if numpy.abs(radialVelocity) > 200: | |
3285 | meteorAux[-1] = 15 |
|
3285 | meteorAux[-1] = 15 | |
3286 | #Number 12: Poor fit to CCF variation for estimation of radial drift velocity |
|
3286 | #Number 12: Poor fit to CCF variation for estimation of radial drift velocity | |
3287 | elif radialError > radialStdThresh: |
|
3287 | elif radialError > radialStdThresh: | |
3288 | meteorAux[-1] = 12 |
|
3288 | meteorAux[-1] = 12 | |
3289 |
|
3289 | |||
3290 | listMeteors1.append(meteorAux) |
|
3290 | listMeteors1.append(meteorAux) | |
3291 | return listMeteors1 |
|
3291 | return listMeteors1 | |
3292 |
|
3292 | |||
3293 | def __setNewArrays(self, listMeteors, date, heiRang): |
|
3293 | def __setNewArrays(self, listMeteors, date, heiRang): | |
3294 |
|
3294 | |||
3295 | #New arrays |
|
3295 | #New arrays | |
3296 | arrayMeteors = numpy.array(listMeteors) |
|
3296 | arrayMeteors = numpy.array(listMeteors) | |
3297 | arrayParameters = numpy.zeros((len(listMeteors), 13)) |
|
3297 | arrayParameters = numpy.zeros((len(listMeteors), 13)) | |
3298 |
|
3298 | |||
3299 | #Date inclusion |
|
3299 | #Date inclusion | |
3300 | # date = re.findall(r'\((.*?)\)', date) |
|
3300 | # date = re.findall(r'\((.*?)\)', date) | |
3301 | # date = date[0].split(',') |
|
3301 | # date = date[0].split(',') | |
3302 | # date = map(int, date) |
|
3302 | # date = map(int, date) | |
3303 | # |
|
3303 | # | |
3304 | # if len(date)<6: |
|
3304 | # if len(date)<6: | |
3305 | # date.append(0) |
|
3305 | # date.append(0) | |
3306 | # |
|
3306 | # | |
3307 | # date = [date[0]*10000 + date[1]*100 + date[2], date[3]*10000 + date[4]*100 + date[5]] |
|
3307 | # date = [date[0]*10000 + date[1]*100 + date[2], date[3]*10000 + date[4]*100 + date[5]] | |
3308 | # arrayDate = numpy.tile(date, (len(listMeteors), 1)) |
|
3308 | # arrayDate = numpy.tile(date, (len(listMeteors), 1)) | |
3309 | arrayDate = numpy.tile(date, (len(listMeteors))) |
|
3309 | arrayDate = numpy.tile(date, (len(listMeteors))) | |
3310 |
|
3310 | |||
3311 | #Meteor array |
|
3311 | #Meteor array | |
3312 | # arrayMeteors[:,0] = heiRang[arrayMeteors[:,0].astype(int)] |
|
3312 | # arrayMeteors[:,0] = heiRang[arrayMeteors[:,0].astype(int)] | |
3313 | # arrayMeteors = numpy.hstack((arrayDate, arrayMeteors)) |
|
3313 | # arrayMeteors = numpy.hstack((arrayDate, arrayMeteors)) | |
3314 |
|
3314 | |||
3315 | #Parameters Array |
|
3315 | #Parameters Array | |
3316 | arrayParameters[:,0] = arrayDate #Date |
|
3316 | arrayParameters[:,0] = arrayDate #Date | |
3317 | arrayParameters[:,1] = heiRang[arrayMeteors[:,0].astype(int)] #Range |
|
3317 | arrayParameters[:,1] = heiRang[arrayMeteors[:,0].astype(int)] #Range | |
3318 | arrayParameters[:,6:8] = arrayMeteors[:,-3:-1] #Radial velocity and its error |
|
3318 | arrayParameters[:,6:8] = arrayMeteors[:,-3:-1] #Radial velocity and its error | |
3319 | arrayParameters[:,8:12] = arrayMeteors[:,7:11] #Phases |
|
3319 | arrayParameters[:,8:12] = arrayMeteors[:,7:11] #Phases | |
3320 | arrayParameters[:,-1] = arrayMeteors[:,-1] #Error |
|
3320 | arrayParameters[:,-1] = arrayMeteors[:,-1] #Error | |
3321 |
|
3321 | |||
3322 |
|
3322 | |||
3323 | return arrayParameters |
|
3323 | return arrayParameters | |
3324 |
|
3324 | |||
3325 | class CorrectSMPhases(Operation): |
|
3325 | class CorrectSMPhases(Operation): | |
3326 |
|
3326 | |||
3327 | def run(self, dataOut, phaseOffsets, hmin = 50, hmax = 150, azimuth = 45, channelPositions = None): |
|
3327 | def run(self, dataOut, phaseOffsets, hmin = 50, hmax = 150, azimuth = 45, channelPositions = None): | |
3328 |
|
3328 | |||
3329 | arrayParameters = dataOut.data_param |
|
3329 | arrayParameters = dataOut.data_param | |
3330 | pairsList = [] |
|
3330 | pairsList = [] | |
3331 | pairx = (0,1) |
|
3331 | pairx = (0,1) | |
3332 | pairy = (2,3) |
|
3332 | pairy = (2,3) | |
3333 | pairsList.append(pairx) |
|
3333 | pairsList.append(pairx) | |
3334 | pairsList.append(pairy) |
|
3334 | pairsList.append(pairy) | |
3335 | jph = numpy.zeros(4) |
|
3335 | jph = numpy.zeros(4) | |
3336 |
|
3336 | |||
3337 | phaseOffsets = numpy.array(phaseOffsets)*numpy.pi/180 |
|
3337 | phaseOffsets = numpy.array(phaseOffsets)*numpy.pi/180 | |
3338 | # arrayParameters[:,8:12] = numpy.unwrap(arrayParameters[:,8:12] + phaseOffsets) |
|
3338 | # arrayParameters[:,8:12] = numpy.unwrap(arrayParameters[:,8:12] + phaseOffsets) | |
3339 | arrayParameters[:,8:12] = numpy.angle(numpy.exp(1j*(arrayParameters[:,8:12] + phaseOffsets))) |
|
3339 | arrayParameters[:,8:12] = numpy.angle(numpy.exp(1j*(arrayParameters[:,8:12] + phaseOffsets))) | |
3340 |
|
3340 | |||
3341 | meteorOps = SMOperations() |
|
3341 | meteorOps = SMOperations() | |
3342 | if channelPositions is None: |
|
3342 | if channelPositions is None: | |
3343 | # channelPositions = [(2.5,0), (0,2.5), (0,0), (0,4.5), (-2,0)] #T |
|
3343 | # channelPositions = [(2.5,0), (0,2.5), (0,0), (0,4.5), (-2,0)] #T | |
3344 | channelPositions = [(4.5,2), (2,4.5), (2,2), (2,0), (0,2)] #Estrella |
|
3344 | channelPositions = [(4.5,2), (2,4.5), (2,2), (2,0), (0,2)] #Estrella | |
3345 |
|
3345 | |||
3346 | pairslist0, distances = meteorOps.getPhasePairs(channelPositions) |
|
3346 | pairslist0, distances = meteorOps.getPhasePairs(channelPositions) | |
3347 | h = (hmin,hmax) |
|
3347 | h = (hmin,hmax) | |
3348 |
|
3348 | |||
3349 | arrayParameters = meteorOps.getMeteorParams(arrayParameters, azimuth, h, pairsList, distances, jph) |
|
3349 | arrayParameters = meteorOps.getMeteorParams(arrayParameters, azimuth, h, pairsList, distances, jph) | |
3350 |
|
3350 | |||
3351 | dataOut.data_param = arrayParameters |
|
3351 | dataOut.data_param = arrayParameters | |
3352 | return |
|
3352 | return | |
3353 |
|
3353 | |||
3354 | class SMPhaseCalibration(Operation): |
|
3354 | class SMPhaseCalibration(Operation): | |
3355 |
|
3355 | |||
3356 | __buffer = None |
|
3356 | __buffer = None | |
3357 |
|
3357 | |||
3358 | __initime = None |
|
3358 | __initime = None | |
3359 |
|
3359 | |||
3360 | __dataReady = False |
|
3360 | __dataReady = False | |
3361 |
|
3361 | |||
3362 | __isConfig = False |
|
3362 | __isConfig = False | |
3363 |
|
3363 | |||
3364 | def __checkTime(self, currentTime, initTime, paramInterval, outputInterval): |
|
3364 | def __checkTime(self, currentTime, initTime, paramInterval, outputInterval): | |
3365 |
|
3365 | |||
3366 | dataTime = currentTime + paramInterval |
|
3366 | dataTime = currentTime + paramInterval | |
3367 | deltaTime = dataTime - initTime |
|
3367 | deltaTime = dataTime - initTime | |
3368 |
|
3368 | |||
3369 | if deltaTime >= outputInterval or deltaTime < 0: |
|
3369 | if deltaTime >= outputInterval or deltaTime < 0: | |
3370 | return True |
|
3370 | return True | |
3371 |
|
3371 | |||
3372 | return False |
|
3372 | return False | |
3373 |
|
3373 | |||
3374 | def __getGammas(self, pairs, d, phases): |
|
3374 | def __getGammas(self, pairs, d, phases): | |
3375 | gammas = numpy.zeros(2) |
|
3375 | gammas = numpy.zeros(2) | |
3376 |
|
3376 | |||
3377 | for i in range(len(pairs)): |
|
3377 | for i in range(len(pairs)): | |
3378 |
|
3378 | |||
3379 | pairi = pairs[i] |
|
3379 | pairi = pairs[i] | |
3380 |
|
3380 | |||
3381 | phip3 = phases[:,pairi[0]] |
|
3381 | phip3 = phases[:,pairi[0]] | |
3382 | d3 = d[pairi[0]] |
|
3382 | d3 = d[pairi[0]] | |
3383 | phip2 = phases[:,pairi[1]] |
|
3383 | phip2 = phases[:,pairi[1]] | |
3384 | d2 = d[pairi[1]] |
|
3384 | d2 = d[pairi[1]] | |
3385 | #Calculating gamma |
|
3385 | #Calculating gamma | |
3386 | # jdcos = alp1/(k*d1) |
|
3386 | # jdcos = alp1/(k*d1) | |
3387 | # jgamma = numpy.angle(numpy.exp(1j*(d0*alp1/d1 - alp0))) |
|
3387 | # jgamma = numpy.angle(numpy.exp(1j*(d0*alp1/d1 - alp0))) | |
3388 | jgamma = -phip2*d3/d2 - phip3 |
|
3388 | jgamma = -phip2*d3/d2 - phip3 | |
3389 | jgamma = numpy.angle(numpy.exp(1j*jgamma)) |
|
3389 | jgamma = numpy.angle(numpy.exp(1j*jgamma)) | |
3390 | # jgamma[jgamma>numpy.pi] -= 2*numpy.pi |
|
3390 | # jgamma[jgamma>numpy.pi] -= 2*numpy.pi | |
3391 | # jgamma[jgamma<-numpy.pi] += 2*numpy.pi |
|
3391 | # jgamma[jgamma<-numpy.pi] += 2*numpy.pi | |
3392 |
|
3392 | |||
3393 | #Revised distribution |
|
3393 | #Revised distribution | |
3394 | jgammaArray = numpy.hstack((jgamma,jgamma+0.5*numpy.pi,jgamma-0.5*numpy.pi)) |
|
3394 | jgammaArray = numpy.hstack((jgamma,jgamma+0.5*numpy.pi,jgamma-0.5*numpy.pi)) | |
3395 |
|
3395 | |||
3396 | #Histogram |
|
3396 | #Histogram | |
3397 | nBins = 64 |
|
3397 | nBins = 64 | |
3398 | rmin = -0.5*numpy.pi |
|
3398 | rmin = -0.5*numpy.pi | |
3399 | rmax = 0.5*numpy.pi |
|
3399 | rmax = 0.5*numpy.pi | |
3400 | phaseHisto = numpy.histogram(jgammaArray, bins=nBins, range=(rmin,rmax)) |
|
3400 | phaseHisto = numpy.histogram(jgammaArray, bins=nBins, range=(rmin,rmax)) | |
3401 |
|
3401 | |||
3402 | meteorsY = phaseHisto[0] |
|
3402 | meteorsY = phaseHisto[0] | |
3403 | phasesX = phaseHisto[1][:-1] |
|
3403 | phasesX = phaseHisto[1][:-1] | |
3404 | width = phasesX[1] - phasesX[0] |
|
3404 | width = phasesX[1] - phasesX[0] | |
3405 | phasesX += width/2 |
|
3405 | phasesX += width/2 | |
3406 |
|
3406 | |||
3407 | #Gaussian aproximation |
|
3407 | #Gaussian aproximation | |
3408 | bpeak = meteorsY.argmax() |
|
3408 | bpeak = meteorsY.argmax() | |
3409 | peak = meteorsY.max() |
|
3409 | peak = meteorsY.max() | |
3410 | jmin = bpeak - 5 |
|
3410 | jmin = bpeak - 5 | |
3411 | jmax = bpeak + 5 + 1 |
|
3411 | jmax = bpeak + 5 + 1 | |
3412 |
|
3412 | |||
3413 | if jmin<0: |
|
3413 | if jmin<0: | |
3414 | jmin = 0 |
|
3414 | jmin = 0 | |
3415 | jmax = 6 |
|
3415 | jmax = 6 | |
3416 | elif jmax > meteorsY.size: |
|
3416 | elif jmax > meteorsY.size: | |
3417 | jmin = meteorsY.size - 6 |
|
3417 | jmin = meteorsY.size - 6 | |
3418 | jmax = meteorsY.size |
|
3418 | jmax = meteorsY.size | |
3419 |
|
3419 | |||
3420 | x0 = numpy.array([peak,bpeak,50]) |
|
3420 | x0 = numpy.array([peak,bpeak,50]) | |
3421 | coeff = optimize.leastsq(self.__residualFunction, x0, args=(meteorsY[jmin:jmax], phasesX[jmin:jmax])) |
|
3421 | coeff = optimize.leastsq(self.__residualFunction, x0, args=(meteorsY[jmin:jmax], phasesX[jmin:jmax])) | |
3422 |
|
3422 | |||
3423 | #Gammas |
|
3423 | #Gammas | |
3424 | gammas[i] = coeff[0][1] |
|
3424 | gammas[i] = coeff[0][1] | |
3425 |
|
3425 | |||
3426 | return gammas |
|
3426 | return gammas | |
3427 |
|
3427 | |||
3428 | def __residualFunction(self, coeffs, y, t): |
|
3428 | def __residualFunction(self, coeffs, y, t): | |
3429 |
|
3429 | |||
3430 | return y - self.__gauss_function(t, coeffs) |
|
3430 | return y - self.__gauss_function(t, coeffs) | |
3431 |
|
3431 | |||
3432 | def __gauss_function(self, t, coeffs): |
|
3432 | def __gauss_function(self, t, coeffs): | |
3433 |
|
3433 | |||
3434 | return coeffs[0]*numpy.exp(-0.5*((t - coeffs[1]) / coeffs[2])**2) |
|
3434 | return coeffs[0]*numpy.exp(-0.5*((t - coeffs[1]) / coeffs[2])**2) | |
3435 |
|
3435 | |||
3436 | def __getPhases(self, azimuth, h, pairsList, d, gammas, meteorsArray): |
|
3436 | def __getPhases(self, azimuth, h, pairsList, d, gammas, meteorsArray): | |
3437 | meteorOps = SMOperations() |
|
3437 | meteorOps = SMOperations() | |
3438 | nchan = 4 |
|
3438 | nchan = 4 | |
3439 | pairx = pairsList[0] #x es 0 |
|
3439 | pairx = pairsList[0] #x es 0 | |
3440 | pairy = pairsList[1] #y es 1 |
|
3440 | pairy = pairsList[1] #y es 1 | |
3441 | center_xangle = 0 |
|
3441 | center_xangle = 0 | |
3442 | center_yangle = 0 |
|
3442 | center_yangle = 0 | |
3443 | range_angle = numpy.array([10*numpy.pi,numpy.pi,numpy.pi/2,numpy.pi/4]) |
|
3443 | range_angle = numpy.array([10*numpy.pi,numpy.pi,numpy.pi/2,numpy.pi/4]) | |
3444 | ntimes = len(range_angle) |
|
3444 | ntimes = len(range_angle) | |
3445 |
|
3445 | |||
3446 | nstepsx = 20 |
|
3446 | nstepsx = 20 | |
3447 | nstepsy = 20 |
|
3447 | nstepsy = 20 | |
3448 |
|
3448 | |||
3449 | for iz in range(ntimes): |
|
3449 | for iz in range(ntimes): | |
3450 | min_xangle = -range_angle[iz]/2 + center_xangle |
|
3450 | min_xangle = -range_angle[iz]/2 + center_xangle | |
3451 | max_xangle = range_angle[iz]/2 + center_xangle |
|
3451 | max_xangle = range_angle[iz]/2 + center_xangle | |
3452 | min_yangle = -range_angle[iz]/2 + center_yangle |
|
3452 | min_yangle = -range_angle[iz]/2 + center_yangle | |
3453 | max_yangle = range_angle[iz]/2 + center_yangle |
|
3453 | max_yangle = range_angle[iz]/2 + center_yangle | |
3454 |
|
3454 | |||
3455 | inc_x = (max_xangle-min_xangle)/nstepsx |
|
3455 | inc_x = (max_xangle-min_xangle)/nstepsx | |
3456 | inc_y = (max_yangle-min_yangle)/nstepsy |
|
3456 | inc_y = (max_yangle-min_yangle)/nstepsy | |
3457 |
|
3457 | |||
3458 | alpha_y = numpy.arange(nstepsy)*inc_y + min_yangle |
|
3458 | alpha_y = numpy.arange(nstepsy)*inc_y + min_yangle | |
3459 | alpha_x = numpy.arange(nstepsx)*inc_x + min_xangle |
|
3459 | alpha_x = numpy.arange(nstepsx)*inc_x + min_xangle | |
3460 | penalty = numpy.zeros((nstepsx,nstepsy)) |
|
3460 | penalty = numpy.zeros((nstepsx,nstepsy)) | |
3461 | jph_array = numpy.zeros((nchan,nstepsx,nstepsy)) |
|
3461 | jph_array = numpy.zeros((nchan,nstepsx,nstepsy)) | |
3462 | jph = numpy.zeros(nchan) |
|
3462 | jph = numpy.zeros(nchan) | |
3463 |
|
3463 | |||
3464 | # Iterations looking for the offset |
|
3464 | # Iterations looking for the offset | |
3465 | for iy in range(int(nstepsy)): |
|
3465 | for iy in range(int(nstepsy)): | |
3466 | for ix in range(int(nstepsx)): |
|
3466 | for ix in range(int(nstepsx)): | |
3467 | d3 = d[pairsList[1][0]] |
|
3467 | d3 = d[pairsList[1][0]] | |
3468 | d2 = d[pairsList[1][1]] |
|
3468 | d2 = d[pairsList[1][1]] | |
3469 | d5 = d[pairsList[0][0]] |
|
3469 | d5 = d[pairsList[0][0]] | |
3470 | d4 = d[pairsList[0][1]] |
|
3470 | d4 = d[pairsList[0][1]] | |
3471 |
|
3471 | |||
3472 | alp2 = alpha_y[iy] #gamma 1 |
|
3472 | alp2 = alpha_y[iy] #gamma 1 | |
3473 | alp4 = alpha_x[ix] #gamma 0 |
|
3473 | alp4 = alpha_x[ix] #gamma 0 | |
3474 |
|
3474 | |||
3475 | alp3 = -alp2*d3/d2 - gammas[1] |
|
3475 | alp3 = -alp2*d3/d2 - gammas[1] | |
3476 | alp5 = -alp4*d5/d4 - gammas[0] |
|
3476 | alp5 = -alp4*d5/d4 - gammas[0] | |
3477 | # jph[pairy[1]] = alpha_y[iy] |
|
3477 | # jph[pairy[1]] = alpha_y[iy] | |
3478 | # jph[pairy[0]] = -gammas[1] - alpha_y[iy]*d[pairy[1]]/d[pairy[0]] |
|
3478 | # jph[pairy[0]] = -gammas[1] - alpha_y[iy]*d[pairy[1]]/d[pairy[0]] | |
3479 |
|
3479 | |||
3480 | # jph[pairx[1]] = alpha_x[ix] |
|
3480 | # jph[pairx[1]] = alpha_x[ix] | |
3481 | # jph[pairx[0]] = -gammas[0] - alpha_x[ix]*d[pairx[1]]/d[pairx[0]] |
|
3481 | # jph[pairx[0]] = -gammas[0] - alpha_x[ix]*d[pairx[1]]/d[pairx[0]] | |
3482 | jph[pairsList[0][1]] = alp4 |
|
3482 | jph[pairsList[0][1]] = alp4 | |
3483 | jph[pairsList[0][0]] = alp5 |
|
3483 | jph[pairsList[0][0]] = alp5 | |
3484 | jph[pairsList[1][0]] = alp3 |
|
3484 | jph[pairsList[1][0]] = alp3 | |
3485 | jph[pairsList[1][1]] = alp2 |
|
3485 | jph[pairsList[1][1]] = alp2 | |
3486 | jph_array[:,ix,iy] = jph |
|
3486 | jph_array[:,ix,iy] = jph | |
3487 | # d = [2.0,2.5,2.5,2.0] |
|
3487 | # d = [2.0,2.5,2.5,2.0] | |
3488 | #falta chequear si va a leer bien los meteoros |
|
3488 | #falta chequear si va a leer bien los meteoros | |
3489 | meteorsArray1 = meteorOps.getMeteorParams(meteorsArray, azimuth, h, pairsList, d, jph) |
|
3489 | meteorsArray1 = meteorOps.getMeteorParams(meteorsArray, azimuth, h, pairsList, d, jph) | |
3490 | error = meteorsArray1[:,-1] |
|
3490 | error = meteorsArray1[:,-1] | |
3491 | ind1 = numpy.where(error==0)[0] |
|
3491 | ind1 = numpy.where(error==0)[0] | |
3492 | penalty[ix,iy] = ind1.size |
|
3492 | penalty[ix,iy] = ind1.size | |
3493 |
|
3493 | |||
3494 | i,j = numpy.unravel_index(penalty.argmax(), penalty.shape) |
|
3494 | i,j = numpy.unravel_index(penalty.argmax(), penalty.shape) | |
3495 | phOffset = jph_array[:,i,j] |
|
3495 | phOffset = jph_array[:,i,j] | |
3496 |
|
3496 | |||
3497 | center_xangle = phOffset[pairx[1]] |
|
3497 | center_xangle = phOffset[pairx[1]] | |
3498 | center_yangle = phOffset[pairy[1]] |
|
3498 | center_yangle = phOffset[pairy[1]] | |
3499 |
|
3499 | |||
3500 | phOffset = numpy.angle(numpy.exp(1j*jph_array[:,i,j])) |
|
3500 | phOffset = numpy.angle(numpy.exp(1j*jph_array[:,i,j])) | |
3501 | phOffset = phOffset*180/numpy.pi |
|
3501 | phOffset = phOffset*180/numpy.pi | |
3502 | return phOffset |
|
3502 | return phOffset | |
3503 |
|
3503 | |||
3504 |
|
3504 | |||
3505 | def run(self, dataOut, hmin, hmax, channelPositions=None, nHours = 1): |
|
3505 | def run(self, dataOut, hmin, hmax, channelPositions=None, nHours = 1): | |
3506 |
|
3506 | |||
3507 | dataOut.flagNoData = True |
|
3507 | dataOut.flagNoData = True | |
3508 | self.__dataReady = False |
|
3508 | self.__dataReady = False | |
3509 | dataOut.outputInterval = nHours*3600 |
|
3509 | dataOut.outputInterval = nHours*3600 | |
3510 |
|
3510 | |||
3511 | if self.__isConfig == False: |
|
3511 | if self.__isConfig == False: | |
3512 | # self.__initime = dataOut.datatime.replace(minute = 0, second = 0, microsecond = 03) |
|
3512 | # self.__initime = dataOut.datatime.replace(minute = 0, second = 0, microsecond = 03) | |
3513 | #Get Initial LTC time |
|
3513 | #Get Initial LTC time | |
3514 | self.__initime = datetime.datetime.utcfromtimestamp(dataOut.utctime) |
|
3514 | self.__initime = datetime.datetime.utcfromtimestamp(dataOut.utctime) | |
3515 | self.__initime = (self.__initime.replace(minute = 0, second = 0, microsecond = 0) - datetime.datetime(1970, 1, 1)).total_seconds() |
|
3515 | self.__initime = (self.__initime.replace(minute = 0, second = 0, microsecond = 0) - datetime.datetime(1970, 1, 1)).total_seconds() | |
3516 |
|
3516 | |||
3517 | self.__isConfig = True |
|
3517 | self.__isConfig = True | |
3518 |
|
3518 | |||
3519 | if self.__buffer is None: |
|
3519 | if self.__buffer is None: | |
3520 | self.__buffer = dataOut.data_param.copy() |
|
3520 | self.__buffer = dataOut.data_param.copy() | |
3521 |
|
3521 | |||
3522 | else: |
|
3522 | else: | |
3523 | self.__buffer = numpy.vstack((self.__buffer, dataOut.data_param)) |
|
3523 | self.__buffer = numpy.vstack((self.__buffer, dataOut.data_param)) | |
3524 |
|
3524 | |||
3525 | self.__dataReady = self.__checkTime(dataOut.utctime, self.__initime, dataOut.paramInterval, dataOut.outputInterval) #Check if the buffer is ready |
|
3525 | self.__dataReady = self.__checkTime(dataOut.utctime, self.__initime, dataOut.paramInterval, dataOut.outputInterval) #Check if the buffer is ready | |
3526 |
|
3526 | |||
3527 | if self.__dataReady: |
|
3527 | if self.__dataReady: | |
3528 | dataOut.utctimeInit = self.__initime |
|
3528 | dataOut.utctimeInit = self.__initime | |
3529 | self.__initime += dataOut.outputInterval #to erase time offset |
|
3529 | self.__initime += dataOut.outputInterval #to erase time offset | |
3530 |
|
3530 | |||
3531 | freq = dataOut.frequency |
|
3531 | freq = dataOut.frequency | |
3532 | c = dataOut.C #m/s |
|
3532 | c = dataOut.C #m/s | |
3533 | lamb = c/freq |
|
3533 | lamb = c/freq | |
3534 | k = 2*numpy.pi/lamb |
|
3534 | k = 2*numpy.pi/lamb | |
3535 | azimuth = 0 |
|
3535 | azimuth = 0 | |
3536 | h = (hmin, hmax) |
|
3536 | h = (hmin, hmax) | |
3537 | # pairs = ((0,1),(2,3)) #Estrella |
|
3537 | # pairs = ((0,1),(2,3)) #Estrella | |
3538 | # pairs = ((1,0),(2,3)) #T |
|
3538 | # pairs = ((1,0),(2,3)) #T | |
3539 |
|
3539 | |||
3540 | if channelPositions is None: |
|
3540 | if channelPositions is None: | |
3541 | # channelPositions = [(2.5,0), (0,2.5), (0,0), (0,4.5), (-2,0)] #T |
|
3541 | # channelPositions = [(2.5,0), (0,2.5), (0,0), (0,4.5), (-2,0)] #T | |
3542 | channelPositions = [(4.5,2), (2,4.5), (2,2), (2,0), (0,2)] #Estrella |
|
3542 | channelPositions = [(4.5,2), (2,4.5), (2,2), (2,0), (0,2)] #Estrella | |
3543 | meteorOps = SMOperations() |
|
3543 | meteorOps = SMOperations() | |
3544 | pairslist0, distances = meteorOps.getPhasePairs(channelPositions) |
|
3544 | pairslist0, distances = meteorOps.getPhasePairs(channelPositions) | |
3545 |
|
3545 | |||
3546 | #Checking correct order of pairs |
|
3546 | #Checking correct order of pairs | |
3547 | pairs = [] |
|
3547 | pairs = [] | |
3548 | if distances[1] > distances[0]: |
|
3548 | if distances[1] > distances[0]: | |
3549 | pairs.append((1,0)) |
|
3549 | pairs.append((1,0)) | |
3550 | else: |
|
3550 | else: | |
3551 | pairs.append((0,1)) |
|
3551 | pairs.append((0,1)) | |
3552 |
|
3552 | |||
3553 | if distances[3] > distances[2]: |
|
3553 | if distances[3] > distances[2]: | |
3554 | pairs.append((3,2)) |
|
3554 | pairs.append((3,2)) | |
3555 | else: |
|
3555 | else: | |
3556 | pairs.append((2,3)) |
|
3556 | pairs.append((2,3)) | |
3557 | # distances1 = [-distances[0]*lamb, distances[1]*lamb, -distances[2]*lamb, distances[3]*lamb] |
|
3557 | # distances1 = [-distances[0]*lamb, distances[1]*lamb, -distances[2]*lamb, distances[3]*lamb] | |
3558 |
|
3558 | |||
3559 | meteorsArray = self.__buffer |
|
3559 | meteorsArray = self.__buffer | |
3560 | error = meteorsArray[:,-1] |
|
3560 | error = meteorsArray[:,-1] | |
3561 | boolError = (error==0)|(error==3)|(error==4)|(error==13)|(error==14) |
|
3561 | boolError = (error==0)|(error==3)|(error==4)|(error==13)|(error==14) | |
3562 | ind1 = numpy.where(boolError)[0] |
|
3562 | ind1 = numpy.where(boolError)[0] | |
3563 | meteorsArray = meteorsArray[ind1,:] |
|
3563 | meteorsArray = meteorsArray[ind1,:] | |
3564 | meteorsArray[:,-1] = 0 |
|
3564 | meteorsArray[:,-1] = 0 | |
3565 | phases = meteorsArray[:,8:12] |
|
3565 | phases = meteorsArray[:,8:12] | |
3566 |
|
3566 | |||
3567 | #Calculate Gammas |
|
3567 | #Calculate Gammas | |
3568 | gammas = self.__getGammas(pairs, distances, phases) |
|
3568 | gammas = self.__getGammas(pairs, distances, phases) | |
3569 | # gammas = numpy.array([-21.70409463,45.76935864])*numpy.pi/180 |
|
3569 | # gammas = numpy.array([-21.70409463,45.76935864])*numpy.pi/180 | |
3570 | #Calculate Phases |
|
3570 | #Calculate Phases | |
3571 | phasesOff = self.__getPhases(azimuth, h, pairs, distances, gammas, meteorsArray) |
|
3571 | phasesOff = self.__getPhases(azimuth, h, pairs, distances, gammas, meteorsArray) | |
3572 | phasesOff = phasesOff.reshape((1,phasesOff.size)) |
|
3572 | phasesOff = phasesOff.reshape((1,phasesOff.size)) | |
3573 | dataOut.data_output = -phasesOff |
|
3573 | dataOut.data_output = -phasesOff | |
3574 | dataOut.flagNoData = False |
|
3574 | dataOut.flagNoData = False | |
3575 | self.__buffer = None |
|
3575 | self.__buffer = None | |
3576 |
|
3576 | |||
3577 |
|
3577 | |||
3578 | return |
|
3578 | return | |
3579 |
|
3579 | |||
3580 | class SMOperations(): |
|
3580 | class SMOperations(): | |
3581 |
|
3581 | |||
3582 | def __init__(self): |
|
3582 | def __init__(self): | |
3583 |
|
3583 | |||
3584 | return |
|
3584 | return | |
3585 |
|
3585 | |||
3586 | def getMeteorParams(self, arrayParameters0, azimuth, h, pairsList, distances, jph): |
|
3586 | def getMeteorParams(self, arrayParameters0, azimuth, h, pairsList, distances, jph): | |
3587 |
|
3587 | |||
3588 | arrayParameters = arrayParameters0.copy() |
|
3588 | arrayParameters = arrayParameters0.copy() | |
3589 | hmin = h[0] |
|
3589 | hmin = h[0] | |
3590 | hmax = h[1] |
|
3590 | hmax = h[1] | |
3591 |
|
3591 | |||
3592 | #Calculate AOA (Error N 3, 4) |
|
3592 | #Calculate AOA (Error N 3, 4) | |
3593 | #JONES ET AL. 1998 |
|
3593 | #JONES ET AL. 1998 | |
3594 | AOAthresh = numpy.pi/8 |
|
3594 | AOAthresh = numpy.pi/8 | |
3595 | error = arrayParameters[:,-1] |
|
3595 | error = arrayParameters[:,-1] | |
3596 | phases = -arrayParameters[:,8:12] + jph |
|
3596 | phases = -arrayParameters[:,8:12] + jph | |
3597 | # phases = numpy.unwrap(phases) |
|
3597 | # phases = numpy.unwrap(phases) | |
3598 | arrayParameters[:,3:6], arrayParameters[:,-1] = self.__getAOA(phases, pairsList, distances, error, AOAthresh, azimuth) |
|
3598 | arrayParameters[:,3:6], arrayParameters[:,-1] = self.__getAOA(phases, pairsList, distances, error, AOAthresh, azimuth) | |
3599 |
|
3599 | |||
3600 | #Calculate Heights (Error N 13 and 14) |
|
3600 | #Calculate Heights (Error N 13 and 14) | |
3601 | error = arrayParameters[:,-1] |
|
3601 | error = arrayParameters[:,-1] | |
3602 | Ranges = arrayParameters[:,1] |
|
3602 | Ranges = arrayParameters[:,1] | |
3603 | zenith = arrayParameters[:,4] |
|
3603 | zenith = arrayParameters[:,4] | |
3604 | arrayParameters[:,2], arrayParameters[:,-1] = self.__getHeights(Ranges, zenith, error, hmin, hmax) |
|
3604 | arrayParameters[:,2], arrayParameters[:,-1] = self.__getHeights(Ranges, zenith, error, hmin, hmax) | |
3605 |
|
3605 | |||
3606 | #----------------------- Get Final data ------------------------------------ |
|
3606 | #----------------------- Get Final data ------------------------------------ | |
3607 | # error = arrayParameters[:,-1] |
|
3607 | # error = arrayParameters[:,-1] | |
3608 | # ind1 = numpy.where(error==0)[0] |
|
3608 | # ind1 = numpy.where(error==0)[0] | |
3609 | # arrayParameters = arrayParameters[ind1,:] |
|
3609 | # arrayParameters = arrayParameters[ind1,:] | |
3610 |
|
3610 | |||
3611 | return arrayParameters |
|
3611 | return arrayParameters | |
3612 |
|
3612 | |||
3613 | def __getAOA(self, phases, pairsList, directions, error, AOAthresh, azimuth): |
|
3613 | def __getAOA(self, phases, pairsList, directions, error, AOAthresh, azimuth): | |
3614 |
|
3614 | |||
3615 | arrayAOA = numpy.zeros((phases.shape[0],3)) |
|
3615 | arrayAOA = numpy.zeros((phases.shape[0],3)) | |
3616 | cosdir0, cosdir = self.__getDirectionCosines(phases, pairsList,directions) |
|
3616 | cosdir0, cosdir = self.__getDirectionCosines(phases, pairsList,directions) | |
3617 |
|
3617 | |||
3618 | arrayAOA[:,:2] = self.__calculateAOA(cosdir, azimuth) |
|
3618 | arrayAOA[:,:2] = self.__calculateAOA(cosdir, azimuth) | |
3619 | cosDirError = numpy.sum(numpy.abs(cosdir0 - cosdir), axis = 1) |
|
3619 | cosDirError = numpy.sum(numpy.abs(cosdir0 - cosdir), axis = 1) | |
3620 | arrayAOA[:,2] = cosDirError |
|
3620 | arrayAOA[:,2] = cosDirError | |
3621 |
|
3621 | |||
3622 | azimuthAngle = arrayAOA[:,0] |
|
3622 | azimuthAngle = arrayAOA[:,0] | |
3623 | zenithAngle = arrayAOA[:,1] |
|
3623 | zenithAngle = arrayAOA[:,1] | |
3624 |
|
3624 | |||
3625 | #Setting Error |
|
3625 | #Setting Error | |
3626 | indError = numpy.where(numpy.logical_or(error == 3, error == 4))[0] |
|
3626 | indError = numpy.where(numpy.logical_or(error == 3, error == 4))[0] | |
3627 | error[indError] = 0 |
|
3627 | error[indError] = 0 | |
3628 | #Number 3: AOA not fesible |
|
3628 | #Number 3: AOA not fesible | |
3629 | indInvalid = numpy.where(numpy.logical_and((numpy.logical_or(numpy.isnan(zenithAngle), numpy.isnan(azimuthAngle))),error == 0))[0] |
|
3629 | indInvalid = numpy.where(numpy.logical_and((numpy.logical_or(numpy.isnan(zenithAngle), numpy.isnan(azimuthAngle))),error == 0))[0] | |
3630 | error[indInvalid] = 3 |
|
3630 | error[indInvalid] = 3 | |
3631 | #Number 4: Large difference in AOAs obtained from different antenna baselines |
|
3631 | #Number 4: Large difference in AOAs obtained from different antenna baselines | |
3632 | indInvalid = numpy.where(numpy.logical_and(cosDirError > AOAthresh,error == 0))[0] |
|
3632 | indInvalid = numpy.where(numpy.logical_and(cosDirError > AOAthresh,error == 0))[0] | |
3633 | error[indInvalid] = 4 |
|
3633 | error[indInvalid] = 4 | |
3634 | return arrayAOA, error |
|
3634 | return arrayAOA, error | |
3635 |
|
3635 | |||
3636 | def __getDirectionCosines(self, arrayPhase, pairsList, distances): |
|
3636 | def __getDirectionCosines(self, arrayPhase, pairsList, distances): | |
3637 |
|
3637 | |||
3638 | #Initializing some variables |
|
3638 | #Initializing some variables | |
3639 | ang_aux = numpy.array([-8,-7,-6,-5,-4,-3,-2,-1,0,1,2,3,4,5,6,7,8])*2*numpy.pi |
|
3639 | ang_aux = numpy.array([-8,-7,-6,-5,-4,-3,-2,-1,0,1,2,3,4,5,6,7,8])*2*numpy.pi | |
3640 | ang_aux = ang_aux.reshape(1,ang_aux.size) |
|
3640 | ang_aux = ang_aux.reshape(1,ang_aux.size) | |
3641 |
|
3641 | |||
3642 | cosdir = numpy.zeros((arrayPhase.shape[0],2)) |
|
3642 | cosdir = numpy.zeros((arrayPhase.shape[0],2)) | |
3643 | cosdir0 = numpy.zeros((arrayPhase.shape[0],2)) |
|
3643 | cosdir0 = numpy.zeros((arrayPhase.shape[0],2)) | |
3644 |
|
3644 | |||
3645 |
|
3645 | |||
3646 | for i in range(2): |
|
3646 | for i in range(2): | |
3647 | ph0 = arrayPhase[:,pairsList[i][0]] |
|
3647 | ph0 = arrayPhase[:,pairsList[i][0]] | |
3648 | ph1 = arrayPhase[:,pairsList[i][1]] |
|
3648 | ph1 = arrayPhase[:,pairsList[i][1]] | |
3649 | d0 = distances[pairsList[i][0]] |
|
3649 | d0 = distances[pairsList[i][0]] | |
3650 | d1 = distances[pairsList[i][1]] |
|
3650 | d1 = distances[pairsList[i][1]] | |
3651 |
|
3651 | |||
3652 | ph0_aux = ph0 + ph1 |
|
3652 | ph0_aux = ph0 + ph1 | |
3653 | ph0_aux = numpy.angle(numpy.exp(1j*ph0_aux)) |
|
3653 | ph0_aux = numpy.angle(numpy.exp(1j*ph0_aux)) | |
3654 | # ph0_aux[ph0_aux > numpy.pi] -= 2*numpy.pi |
|
3654 | # ph0_aux[ph0_aux > numpy.pi] -= 2*numpy.pi | |
3655 | # ph0_aux[ph0_aux < -numpy.pi] += 2*numpy.pi |
|
3655 | # ph0_aux[ph0_aux < -numpy.pi] += 2*numpy.pi | |
3656 | #First Estimation |
|
3656 | #First Estimation | |
3657 | cosdir0[:,i] = (ph0_aux)/(2*numpy.pi*(d0 - d1)) |
|
3657 | cosdir0[:,i] = (ph0_aux)/(2*numpy.pi*(d0 - d1)) | |
3658 |
|
3658 | |||
3659 | #Most-Accurate Second Estimation |
|
3659 | #Most-Accurate Second Estimation | |
3660 | phi1_aux = ph0 - ph1 |
|
3660 | phi1_aux = ph0 - ph1 | |
3661 | phi1_aux = phi1_aux.reshape(phi1_aux.size,1) |
|
3661 | phi1_aux = phi1_aux.reshape(phi1_aux.size,1) | |
3662 | #Direction Cosine 1 |
|
3662 | #Direction Cosine 1 | |
3663 | cosdir1 = (phi1_aux + ang_aux)/(2*numpy.pi*(d0 + d1)) |
|
3663 | cosdir1 = (phi1_aux + ang_aux)/(2*numpy.pi*(d0 + d1)) | |
3664 |
|
3664 | |||
3665 | #Searching the correct Direction Cosine |
|
3665 | #Searching the correct Direction Cosine | |
3666 | cosdir0_aux = cosdir0[:,i] |
|
3666 | cosdir0_aux = cosdir0[:,i] | |
3667 | cosdir0_aux = cosdir0_aux.reshape(cosdir0_aux.size,1) |
|
3667 | cosdir0_aux = cosdir0_aux.reshape(cosdir0_aux.size,1) | |
3668 | #Minimum Distance |
|
3668 | #Minimum Distance | |
3669 | cosDiff = (cosdir1 - cosdir0_aux)**2 |
|
3669 | cosDiff = (cosdir1 - cosdir0_aux)**2 | |
3670 | indcos = cosDiff.argmin(axis = 1) |
|
3670 | indcos = cosDiff.argmin(axis = 1) | |
3671 | #Saving Value obtained |
|
3671 | #Saving Value obtained | |
3672 | cosdir[:,i] = cosdir1[numpy.arange(len(indcos)),indcos] |
|
3672 | cosdir[:,i] = cosdir1[numpy.arange(len(indcos)),indcos] | |
3673 |
|
3673 | |||
3674 | return cosdir0, cosdir |
|
3674 | return cosdir0, cosdir | |
3675 |
|
3675 | |||
3676 | def __calculateAOA(self, cosdir, azimuth): |
|
3676 | def __calculateAOA(self, cosdir, azimuth): | |
3677 | cosdirX = cosdir[:,0] |
|
3677 | cosdirX = cosdir[:,0] | |
3678 | cosdirY = cosdir[:,1] |
|
3678 | cosdirY = cosdir[:,1] | |
3679 |
|
3679 | |||
3680 | zenithAngle = numpy.arccos(numpy.sqrt(1 - cosdirX**2 - cosdirY**2))*180/numpy.pi |
|
3680 | zenithAngle = numpy.arccos(numpy.sqrt(1 - cosdirX**2 - cosdirY**2))*180/numpy.pi | |
3681 | azimuthAngle = numpy.arctan2(cosdirX,cosdirY)*180/numpy.pi + azimuth#0 deg north, 90 deg east |
|
3681 | azimuthAngle = numpy.arctan2(cosdirX,cosdirY)*180/numpy.pi + azimuth#0 deg north, 90 deg east | |
3682 | angles = numpy.vstack((azimuthAngle, zenithAngle)).transpose() |
|
3682 | angles = numpy.vstack((azimuthAngle, zenithAngle)).transpose() | |
3683 |
|
3683 | |||
3684 | return angles |
|
3684 | return angles | |
3685 |
|
3685 | |||
3686 | def __getHeights(self, Ranges, zenith, error, minHeight, maxHeight): |
|
3686 | def __getHeights(self, Ranges, zenith, error, minHeight, maxHeight): | |
3687 |
|
3687 | |||
3688 | Ramb = 375 #Ramb = c/(2*PRF) |
|
3688 | Ramb = 375 #Ramb = c/(2*PRF) | |
3689 | Re = 6371 #Earth Radius |
|
3689 | Re = 6371 #Earth Radius | |
3690 | heights = numpy.zeros(Ranges.shape) |
|
3690 | heights = numpy.zeros(Ranges.shape) | |
3691 |
|
3691 | |||
3692 | R_aux = numpy.array([0,1,2])*Ramb |
|
3692 | R_aux = numpy.array([0,1,2])*Ramb | |
3693 | R_aux = R_aux.reshape(1,R_aux.size) |
|
3693 | R_aux = R_aux.reshape(1,R_aux.size) | |
3694 |
|
3694 | |||
3695 | Ranges = Ranges.reshape(Ranges.size,1) |
|
3695 | Ranges = Ranges.reshape(Ranges.size,1) | |
3696 |
|
3696 | |||
3697 | Ri = Ranges + R_aux |
|
3697 | Ri = Ranges + R_aux | |
3698 | hi = numpy.sqrt(Re**2 + Ri**2 + (2*Re*numpy.cos(zenith*numpy.pi/180)*Ri.transpose()).transpose()) - Re |
|
3698 | hi = numpy.sqrt(Re**2 + Ri**2 + (2*Re*numpy.cos(zenith*numpy.pi/180)*Ri.transpose()).transpose()) - Re | |
3699 |
|
3699 | |||
3700 | #Check if there is a height between 70 and 110 km |
|
3700 | #Check if there is a height between 70 and 110 km | |
3701 | h_bool = numpy.sum(numpy.logical_and(hi > minHeight, hi < maxHeight), axis = 1) |
|
3701 | h_bool = numpy.sum(numpy.logical_and(hi > minHeight, hi < maxHeight), axis = 1) | |
3702 | ind_h = numpy.where(h_bool == 1)[0] |
|
3702 | ind_h = numpy.where(h_bool == 1)[0] | |
3703 |
|
3703 | |||
3704 | hCorr = hi[ind_h, :] |
|
3704 | hCorr = hi[ind_h, :] | |
3705 | ind_hCorr = numpy.where(numpy.logical_and(hi > minHeight, hi < maxHeight)) |
|
3705 | ind_hCorr = numpy.where(numpy.logical_and(hi > minHeight, hi < maxHeight)) | |
3706 |
|
3706 | |||
3707 | hCorr = hi[ind_hCorr][:len(ind_h)] |
|
3707 | hCorr = hi[ind_hCorr][:len(ind_h)] | |
3708 | heights[ind_h] = hCorr |
|
3708 | heights[ind_h] = hCorr | |
3709 |
|
3709 | |||
3710 | #Setting Error |
|
3710 | #Setting Error | |
3711 | #Number 13: Height unresolvable echo: not valid height within 70 to 110 km |
|
3711 | #Number 13: Height unresolvable echo: not valid height within 70 to 110 km | |
3712 | #Number 14: Height ambiguous echo: more than one possible height within 70 to 110 km |
|
3712 | #Number 14: Height ambiguous echo: more than one possible height within 70 to 110 km | |
3713 | indError = numpy.where(numpy.logical_or(error == 13, error == 14))[0] |
|
3713 | indError = numpy.where(numpy.logical_or(error == 13, error == 14))[0] | |
3714 | error[indError] = 0 |
|
3714 | error[indError] = 0 | |
3715 | indInvalid2 = numpy.where(numpy.logical_and(h_bool > 1, error == 0))[0] |
|
3715 | indInvalid2 = numpy.where(numpy.logical_and(h_bool > 1, error == 0))[0] | |
3716 | error[indInvalid2] = 14 |
|
3716 | error[indInvalid2] = 14 | |
3717 | indInvalid1 = numpy.where(numpy.logical_and(h_bool == 0, error == 0))[0] |
|
3717 | indInvalid1 = numpy.where(numpy.logical_and(h_bool == 0, error == 0))[0] | |
3718 | error[indInvalid1] = 13 |
|
3718 | error[indInvalid1] = 13 | |
3719 |
|
3719 | |||
3720 | return heights, error |
|
3720 | return heights, error | |
3721 |
|
3721 | |||
3722 | def getPhasePairs(self, channelPositions): |
|
3722 | def getPhasePairs(self, channelPositions): | |
3723 | chanPos = numpy.array(channelPositions) |
|
3723 | chanPos = numpy.array(channelPositions) | |
3724 | listOper = list(itertools.combinations(list(range(5)),2)) |
|
3724 | listOper = list(itertools.combinations(list(range(5)),2)) | |
3725 |
|
3725 | |||
3726 | distances = numpy.zeros(4) |
|
3726 | distances = numpy.zeros(4) | |
3727 | axisX = [] |
|
3727 | axisX = [] | |
3728 | axisY = [] |
|
3728 | axisY = [] | |
3729 | distX = numpy.zeros(3) |
|
3729 | distX = numpy.zeros(3) | |
3730 | distY = numpy.zeros(3) |
|
3730 | distY = numpy.zeros(3) | |
3731 | ix = 0 |
|
3731 | ix = 0 | |
3732 | iy = 0 |
|
3732 | iy = 0 | |
3733 |
|
3733 | |||
3734 | pairX = numpy.zeros((2,2)) |
|
3734 | pairX = numpy.zeros((2,2)) | |
3735 | pairY = numpy.zeros((2,2)) |
|
3735 | pairY = numpy.zeros((2,2)) | |
3736 |
|
3736 | |||
3737 | for i in range(len(listOper)): |
|
3737 | for i in range(len(listOper)): | |
3738 | pairi = listOper[i] |
|
3738 | pairi = listOper[i] | |
3739 |
|
3739 | |||
3740 | posDif = numpy.abs(chanPos[pairi[0],:] - chanPos[pairi[1],:]) |
|
3740 | posDif = numpy.abs(chanPos[pairi[0],:] - chanPos[pairi[1],:]) | |
3741 |
|
3741 | |||
3742 | if posDif[0] == 0: |
|
3742 | if posDif[0] == 0: | |
3743 | axisY.append(pairi) |
|
3743 | axisY.append(pairi) | |
3744 | distY[iy] = posDif[1] |
|
3744 | distY[iy] = posDif[1] | |
3745 | iy += 1 |
|
3745 | iy += 1 | |
3746 | elif posDif[1] == 0: |
|
3746 | elif posDif[1] == 0: | |
3747 | axisX.append(pairi) |
|
3747 | axisX.append(pairi) | |
3748 | distX[ix] = posDif[0] |
|
3748 | distX[ix] = posDif[0] | |
3749 | ix += 1 |
|
3749 | ix += 1 | |
3750 |
|
3750 | |||
3751 | for i in range(2): |
|
3751 | for i in range(2): | |
3752 | if i==0: |
|
3752 | if i==0: | |
3753 | dist0 = distX |
|
3753 | dist0 = distX | |
3754 | axis0 = axisX |
|
3754 | axis0 = axisX | |
3755 | else: |
|
3755 | else: | |
3756 | dist0 = distY |
|
3756 | dist0 = distY | |
3757 | axis0 = axisY |
|
3757 | axis0 = axisY | |
3758 |
|
3758 | |||
3759 | side = numpy.argsort(dist0)[:-1] |
|
3759 | side = numpy.argsort(dist0)[:-1] | |
3760 | axis0 = numpy.array(axis0)[side,:] |
|
3760 | axis0 = numpy.array(axis0)[side,:] | |
3761 | chanC = int(numpy.intersect1d(axis0[0,:], axis0[1,:])[0]) |
|
3761 | chanC = int(numpy.intersect1d(axis0[0,:], axis0[1,:])[0]) | |
3762 | axis1 = numpy.unique(numpy.reshape(axis0,4)) |
|
3762 | axis1 = numpy.unique(numpy.reshape(axis0,4)) | |
3763 | side = axis1[axis1 != chanC] |
|
3763 | side = axis1[axis1 != chanC] | |
3764 | diff1 = chanPos[chanC,i] - chanPos[side[0],i] |
|
3764 | diff1 = chanPos[chanC,i] - chanPos[side[0],i] | |
3765 | diff2 = chanPos[chanC,i] - chanPos[side[1],i] |
|
3765 | diff2 = chanPos[chanC,i] - chanPos[side[1],i] | |
3766 | if diff1<0: |
|
3766 | if diff1<0: | |
3767 | chan2 = side[0] |
|
3767 | chan2 = side[0] | |
3768 | d2 = numpy.abs(diff1) |
|
3768 | d2 = numpy.abs(diff1) | |
3769 | chan1 = side[1] |
|
3769 | chan1 = side[1] | |
3770 | d1 = numpy.abs(diff2) |
|
3770 | d1 = numpy.abs(diff2) | |
3771 | else: |
|
3771 | else: | |
3772 | chan2 = side[1] |
|
3772 | chan2 = side[1] | |
3773 | d2 = numpy.abs(diff2) |
|
3773 | d2 = numpy.abs(diff2) | |
3774 | chan1 = side[0] |
|
3774 | chan1 = side[0] | |
3775 | d1 = numpy.abs(diff1) |
|
3775 | d1 = numpy.abs(diff1) | |
3776 |
|
3776 | |||
3777 | if i==0: |
|
3777 | if i==0: | |
3778 | chanCX = chanC |
|
3778 | chanCX = chanC | |
3779 | chan1X = chan1 |
|
3779 | chan1X = chan1 | |
3780 | chan2X = chan2 |
|
3780 | chan2X = chan2 | |
3781 | distances[0:2] = numpy.array([d1,d2]) |
|
3781 | distances[0:2] = numpy.array([d1,d2]) | |
3782 | else: |
|
3782 | else: | |
3783 | chanCY = chanC |
|
3783 | chanCY = chanC | |
3784 | chan1Y = chan1 |
|
3784 | chan1Y = chan1 | |
3785 | chan2Y = chan2 |
|
3785 | chan2Y = chan2 | |
3786 | distances[2:4] = numpy.array([d1,d2]) |
|
3786 | distances[2:4] = numpy.array([d1,d2]) | |
3787 | # axisXsides = numpy.reshape(axisX[ix,:],4) |
|
3787 | # axisXsides = numpy.reshape(axisX[ix,:],4) | |
3788 | # |
|
3788 | # | |
3789 | # channelCentX = int(numpy.intersect1d(pairX[0,:], pairX[1,:])[0]) |
|
3789 | # channelCentX = int(numpy.intersect1d(pairX[0,:], pairX[1,:])[0]) | |
3790 | # channelCentY = int(numpy.intersect1d(pairY[0,:], pairY[1,:])[0]) |
|
3790 | # channelCentY = int(numpy.intersect1d(pairY[0,:], pairY[1,:])[0]) | |
3791 | # |
|
3791 | # | |
3792 | # ind25X = numpy.where(pairX[0,:] != channelCentX)[0][0] |
|
3792 | # ind25X = numpy.where(pairX[0,:] != channelCentX)[0][0] | |
3793 | # ind20X = numpy.where(pairX[1,:] != channelCentX)[0][0] |
|
3793 | # ind20X = numpy.where(pairX[1,:] != channelCentX)[0][0] | |
3794 | # channel25X = int(pairX[0,ind25X]) |
|
3794 | # channel25X = int(pairX[0,ind25X]) | |
3795 | # channel20X = int(pairX[1,ind20X]) |
|
3795 | # channel20X = int(pairX[1,ind20X]) | |
3796 | # ind25Y = numpy.where(pairY[0,:] != channelCentY)[0][0] |
|
3796 | # ind25Y = numpy.where(pairY[0,:] != channelCentY)[0][0] | |
3797 | # ind20Y = numpy.where(pairY[1,:] != channelCentY)[0][0] |
|
3797 | # ind20Y = numpy.where(pairY[1,:] != channelCentY)[0][0] | |
3798 | # channel25Y = int(pairY[0,ind25Y]) |
|
3798 | # channel25Y = int(pairY[0,ind25Y]) | |
3799 | # channel20Y = int(pairY[1,ind20Y]) |
|
3799 | # channel20Y = int(pairY[1,ind20Y]) | |
3800 |
|
3800 | |||
3801 | # pairslist = [(channelCentX, channel25X),(channelCentX, channel20X),(channelCentY,channel25Y),(channelCentY, channel20Y)] |
|
3801 | # pairslist = [(channelCentX, channel25X),(channelCentX, channel20X),(channelCentY,channel25Y),(channelCentY, channel20Y)] | |
3802 | pairslist = [(chanCX, chan1X),(chanCX, chan2X),(chanCY,chan1Y),(chanCY, chan2Y)] |
|
3802 | pairslist = [(chanCX, chan1X),(chanCX, chan2X),(chanCY,chan1Y),(chanCY, chan2Y)] | |
3803 |
|
3803 | |||
3804 | return pairslist, distances |
|
3804 | return pairslist, distances | |
3805 | # def __getAOA(self, phases, pairsList, error, AOAthresh, azimuth): |
|
3805 | # def __getAOA(self, phases, pairsList, error, AOAthresh, azimuth): | |
3806 | # |
|
3806 | # | |
3807 | # arrayAOA = numpy.zeros((phases.shape[0],3)) |
|
3807 | # arrayAOA = numpy.zeros((phases.shape[0],3)) | |
3808 | # cosdir0, cosdir = self.__getDirectionCosines(phases, pairsList) |
|
3808 | # cosdir0, cosdir = self.__getDirectionCosines(phases, pairsList) | |
3809 | # |
|
3809 | # | |
3810 | # arrayAOA[:,:2] = self.__calculateAOA(cosdir, azimuth) |
|
3810 | # arrayAOA[:,:2] = self.__calculateAOA(cosdir, azimuth) | |
3811 | # cosDirError = numpy.sum(numpy.abs(cosdir0 - cosdir), axis = 1) |
|
3811 | # cosDirError = numpy.sum(numpy.abs(cosdir0 - cosdir), axis = 1) | |
3812 | # arrayAOA[:,2] = cosDirError |
|
3812 | # arrayAOA[:,2] = cosDirError | |
3813 | # |
|
3813 | # | |
3814 | # azimuthAngle = arrayAOA[:,0] |
|
3814 | # azimuthAngle = arrayAOA[:,0] | |
3815 | # zenithAngle = arrayAOA[:,1] |
|
3815 | # zenithAngle = arrayAOA[:,1] | |
3816 | # |
|
3816 | # | |
3817 | # #Setting Error |
|
3817 | # #Setting Error | |
3818 | # #Number 3: AOA not fesible |
|
3818 | # #Number 3: AOA not fesible | |
3819 | # indInvalid = numpy.where(numpy.logical_and((numpy.logical_or(numpy.isnan(zenithAngle), numpy.isnan(azimuthAngle))),error == 0))[0] |
|
3819 | # indInvalid = numpy.where(numpy.logical_and((numpy.logical_or(numpy.isnan(zenithAngle), numpy.isnan(azimuthAngle))),error == 0))[0] | |
3820 | # error[indInvalid] = 3 |
|
3820 | # error[indInvalid] = 3 | |
3821 | # #Number 4: Large difference in AOAs obtained from different antenna baselines |
|
3821 | # #Number 4: Large difference in AOAs obtained from different antenna baselines | |
3822 | # indInvalid = numpy.where(numpy.logical_and(cosDirError > AOAthresh,error == 0))[0] |
|
3822 | # indInvalid = numpy.where(numpy.logical_and(cosDirError > AOAthresh,error == 0))[0] | |
3823 | # error[indInvalid] = 4 |
|
3823 | # error[indInvalid] = 4 | |
3824 | # return arrayAOA, error |
|
3824 | # return arrayAOA, error | |
3825 | # |
|
3825 | # | |
3826 | # def __getDirectionCosines(self, arrayPhase, pairsList): |
|
3826 | # def __getDirectionCosines(self, arrayPhase, pairsList): | |
3827 | # |
|
3827 | # | |
3828 | # #Initializing some variables |
|
3828 | # #Initializing some variables | |
3829 | # ang_aux = numpy.array([-8,-7,-6,-5,-4,-3,-2,-1,0,1,2,3,4,5,6,7,8])*2*numpy.pi |
|
3829 | # ang_aux = numpy.array([-8,-7,-6,-5,-4,-3,-2,-1,0,1,2,3,4,5,6,7,8])*2*numpy.pi | |
3830 | # ang_aux = ang_aux.reshape(1,ang_aux.size) |
|
3830 | # ang_aux = ang_aux.reshape(1,ang_aux.size) | |
3831 | # |
|
3831 | # | |
3832 | # cosdir = numpy.zeros((arrayPhase.shape[0],2)) |
|
3832 | # cosdir = numpy.zeros((arrayPhase.shape[0],2)) | |
3833 | # cosdir0 = numpy.zeros((arrayPhase.shape[0],2)) |
|
3833 | # cosdir0 = numpy.zeros((arrayPhase.shape[0],2)) | |
3834 | # |
|
3834 | # | |
3835 | # |
|
3835 | # | |
3836 | # for i in range(2): |
|
3836 | # for i in range(2): | |
3837 | # #First Estimation |
|
3837 | # #First Estimation | |
3838 | # phi0_aux = arrayPhase[:,pairsList[i][0]] + arrayPhase[:,pairsList[i][1]] |
|
3838 | # phi0_aux = arrayPhase[:,pairsList[i][0]] + arrayPhase[:,pairsList[i][1]] | |
3839 | # #Dealias |
|
3839 | # #Dealias | |
3840 | # indcsi = numpy.where(phi0_aux > numpy.pi) |
|
3840 | # indcsi = numpy.where(phi0_aux > numpy.pi) | |
3841 | # phi0_aux[indcsi] -= 2*numpy.pi |
|
3841 | # phi0_aux[indcsi] -= 2*numpy.pi | |
3842 | # indcsi = numpy.where(phi0_aux < -numpy.pi) |
|
3842 | # indcsi = numpy.where(phi0_aux < -numpy.pi) | |
3843 | # phi0_aux[indcsi] += 2*numpy.pi |
|
3843 | # phi0_aux[indcsi] += 2*numpy.pi | |
3844 | # #Direction Cosine 0 |
|
3844 | # #Direction Cosine 0 | |
3845 | # cosdir0[:,i] = -(phi0_aux)/(2*numpy.pi*0.5) |
|
3845 | # cosdir0[:,i] = -(phi0_aux)/(2*numpy.pi*0.5) | |
3846 | # |
|
3846 | # | |
3847 | # #Most-Accurate Second Estimation |
|
3847 | # #Most-Accurate Second Estimation | |
3848 | # phi1_aux = arrayPhase[:,pairsList[i][0]] - arrayPhase[:,pairsList[i][1]] |
|
3848 | # phi1_aux = arrayPhase[:,pairsList[i][0]] - arrayPhase[:,pairsList[i][1]] | |
3849 | # phi1_aux = phi1_aux.reshape(phi1_aux.size,1) |
|
3849 | # phi1_aux = phi1_aux.reshape(phi1_aux.size,1) | |
3850 | # #Direction Cosine 1 |
|
3850 | # #Direction Cosine 1 | |
3851 | # cosdir1 = -(phi1_aux + ang_aux)/(2*numpy.pi*4.5) |
|
3851 | # cosdir1 = -(phi1_aux + ang_aux)/(2*numpy.pi*4.5) | |
3852 | # |
|
3852 | # | |
3853 | # #Searching the correct Direction Cosine |
|
3853 | # #Searching the correct Direction Cosine | |
3854 | # cosdir0_aux = cosdir0[:,i] |
|
3854 | # cosdir0_aux = cosdir0[:,i] | |
3855 | # cosdir0_aux = cosdir0_aux.reshape(cosdir0_aux.size,1) |
|
3855 | # cosdir0_aux = cosdir0_aux.reshape(cosdir0_aux.size,1) | |
3856 | # #Minimum Distance |
|
3856 | # #Minimum Distance | |
3857 | # cosDiff = (cosdir1 - cosdir0_aux)**2 |
|
3857 | # cosDiff = (cosdir1 - cosdir0_aux)**2 | |
3858 | # indcos = cosDiff.argmin(axis = 1) |
|
3858 | # indcos = cosDiff.argmin(axis = 1) | |
3859 | # #Saving Value obtained |
|
3859 | # #Saving Value obtained | |
3860 | # cosdir[:,i] = cosdir1[numpy.arange(len(indcos)),indcos] |
|
3860 | # cosdir[:,i] = cosdir1[numpy.arange(len(indcos)),indcos] | |
3861 | # |
|
3861 | # | |
3862 | # return cosdir0, cosdir |
|
3862 | # return cosdir0, cosdir | |
3863 | # |
|
3863 | # | |
3864 | # def __calculateAOA(self, cosdir, azimuth): |
|
3864 | # def __calculateAOA(self, cosdir, azimuth): | |
3865 | # cosdirX = cosdir[:,0] |
|
3865 | # cosdirX = cosdir[:,0] | |
3866 | # cosdirY = cosdir[:,1] |
|
3866 | # cosdirY = cosdir[:,1] | |
3867 | # |
|
3867 | # | |
3868 | # zenithAngle = numpy.arccos(numpy.sqrt(1 - cosdirX**2 - cosdirY**2))*180/numpy.pi |
|
3868 | # zenithAngle = numpy.arccos(numpy.sqrt(1 - cosdirX**2 - cosdirY**2))*180/numpy.pi | |
3869 | # azimuthAngle = numpy.arctan2(cosdirX,cosdirY)*180/numpy.pi + azimuth #0 deg north, 90 deg east |
|
3869 | # azimuthAngle = numpy.arctan2(cosdirX,cosdirY)*180/numpy.pi + azimuth #0 deg north, 90 deg east | |
3870 | # angles = numpy.vstack((azimuthAngle, zenithAngle)).transpose() |
|
3870 | # angles = numpy.vstack((azimuthAngle, zenithAngle)).transpose() | |
3871 | # |
|
3871 | # | |
3872 | # return angles |
|
3872 | # return angles | |
3873 | # |
|
3873 | # | |
3874 | # def __getHeights(self, Ranges, zenith, error, minHeight, maxHeight): |
|
3874 | # def __getHeights(self, Ranges, zenith, error, minHeight, maxHeight): | |
3875 | # |
|
3875 | # | |
3876 | # Ramb = 375 #Ramb = c/(2*PRF) |
|
3876 | # Ramb = 375 #Ramb = c/(2*PRF) | |
3877 | # Re = 6371 #Earth Radius |
|
3877 | # Re = 6371 #Earth Radius | |
3878 | # heights = numpy.zeros(Ranges.shape) |
|
3878 | # heights = numpy.zeros(Ranges.shape) | |
3879 | # |
|
3879 | # | |
3880 | # R_aux = numpy.array([0,1,2])*Ramb |
|
3880 | # R_aux = numpy.array([0,1,2])*Ramb | |
3881 | # R_aux = R_aux.reshape(1,R_aux.size) |
|
3881 | # R_aux = R_aux.reshape(1,R_aux.size) | |
3882 | # |
|
3882 | # | |
3883 | # Ranges = Ranges.reshape(Ranges.size,1) |
|
3883 | # Ranges = Ranges.reshape(Ranges.size,1) | |
3884 | # |
|
3884 | # | |
3885 | # Ri = Ranges + R_aux |
|
3885 | # Ri = Ranges + R_aux | |
3886 | # hi = numpy.sqrt(Re**2 + Ri**2 + (2*Re*numpy.cos(zenith*numpy.pi/180)*Ri.transpose()).transpose()) - Re |
|
3886 | # hi = numpy.sqrt(Re**2 + Ri**2 + (2*Re*numpy.cos(zenith*numpy.pi/180)*Ri.transpose()).transpose()) - Re | |
3887 | # |
|
3887 | # | |
3888 | # #Check if there is a height between 70 and 110 km |
|
3888 | # #Check if there is a height between 70 and 110 km | |
3889 | # h_bool = numpy.sum(numpy.logical_and(hi > minHeight, hi < maxHeight), axis = 1) |
|
3889 | # h_bool = numpy.sum(numpy.logical_and(hi > minHeight, hi < maxHeight), axis = 1) | |
3890 | # ind_h = numpy.where(h_bool == 1)[0] |
|
3890 | # ind_h = numpy.where(h_bool == 1)[0] | |
3891 | # |
|
3891 | # | |
3892 | # hCorr = hi[ind_h, :] |
|
3892 | # hCorr = hi[ind_h, :] | |
3893 | # ind_hCorr = numpy.where(numpy.logical_and(hi > minHeight, hi < maxHeight)) |
|
3893 | # ind_hCorr = numpy.where(numpy.logical_and(hi > minHeight, hi < maxHeight)) | |
3894 | # |
|
3894 | # | |
3895 | # hCorr = hi[ind_hCorr] |
|
3895 | # hCorr = hi[ind_hCorr] | |
3896 | # heights[ind_h] = hCorr |
|
3896 | # heights[ind_h] = hCorr | |
3897 | # |
|
3897 | # | |
3898 | # #Setting Error |
|
3898 | # #Setting Error | |
3899 | # #Number 13: Height unresolvable echo: not valid height within 70 to 110 km |
|
3899 | # #Number 13: Height unresolvable echo: not valid height within 70 to 110 km | |
3900 | # #Number 14: Height ambiguous echo: more than one possible height within 70 to 110 km |
|
3900 | # #Number 14: Height ambiguous echo: more than one possible height within 70 to 110 km | |
3901 | # |
|
3901 | # | |
3902 | # indInvalid2 = numpy.where(numpy.logical_and(h_bool > 1, error == 0))[0] |
|
3902 | # indInvalid2 = numpy.where(numpy.logical_and(h_bool > 1, error == 0))[0] | |
3903 | # error[indInvalid2] = 14 |
|
3903 | # error[indInvalid2] = 14 | |
3904 | # indInvalid1 = numpy.where(numpy.logical_and(h_bool == 0, error == 0))[0] |
|
3904 | # indInvalid1 = numpy.where(numpy.logical_and(h_bool == 0, error == 0))[0] | |
3905 | # error[indInvalid1] = 13 |
|
3905 | # error[indInvalid1] = 13 | |
3906 | # |
|
3906 | # | |
3907 | # return heights, error |
|
3907 | # return heights, error | |
3908 |
|
3908 | |||
3909 |
|
3909 | |||
3910 | class WeatherRadar(Operation): |
|
3910 | class WeatherRadar(Operation): | |
3911 | ''' |
|
3911 | ''' | |
3912 | Function tat implements Weather Radar operations- |
|
3912 | Function tat implements Weather Radar operations- | |
3913 | Input: |
|
3913 | Input: | |
3914 | Output: |
|
3914 | Output: | |
3915 | Parameters affected: |
|
3915 | Parameters affected: | |
3916 | ''' |
|
3916 | ''' | |
3917 | isConfig = False |
|
3917 | isConfig = False | |
3918 | variableList = None |
|
3918 | variableList = None | |
3919 |
|
3919 | |||
3920 | def __init__(self): |
|
3920 | def __init__(self): | |
3921 | Operation.__init__(self) |
|
3921 | Operation.__init__(self) | |
3922 |
|
3922 | |||
3923 | def setup(self,dataOut,variableList= None,Pt=0,Gt=0,Gr=0,lambda_=0, aL=0, |
|
3923 | def setup(self,dataOut,variableList= None,Pt=0,Gt=0,Gr=0,lambda_=0, aL=0, | |
3924 | tauW= 0,thetaT=0,thetaR=0,Km =0): |
|
3924 | tauW= 0,thetaT=0,thetaR=0,Km =0): | |
3925 | self.nCh = dataOut.nChannels |
|
3925 | self.nCh = dataOut.nChannels | |
3926 | self.nHeis = dataOut.nHeights |
|
3926 | self.nHeis = dataOut.nHeights | |
3927 | deltaHeight = dataOut.heightList[1] - dataOut.heightList[0] |
|
3927 | deltaHeight = dataOut.heightList[1] - dataOut.heightList[0] | |
3928 | self.Range = numpy.arange(dataOut.nHeights)*deltaHeight + dataOut.heightList[0] |
|
3928 | self.Range = numpy.arange(dataOut.nHeights)*deltaHeight + dataOut.heightList[0] | |
3929 | self.Range = self.Range.reshape(1,self.nHeis) |
|
3929 | self.Range = self.Range.reshape(1,self.nHeis) | |
3930 | self.Range = numpy.tile(self.Range,[self.nCh,1]) |
|
3930 | self.Range = numpy.tile(self.Range,[self.nCh,1]) | |
3931 | '''-----------1 Constante del Radar----------''' |
|
3931 | '''-----------1 Constante del Radar----------''' | |
3932 | self.Pt = Pt |
|
3932 | self.Pt = Pt | |
3933 | self.Gt = Gt |
|
3933 | self.Gt = Gt | |
3934 | self.Gr = Gr |
|
3934 | self.Gr = Gr | |
3935 | self.lambda_ = lambda_ |
|
3935 | self.lambda_ = lambda_ | |
3936 | self.aL = aL |
|
3936 | self.aL = aL | |
3937 | self.tauW = tauW |
|
3937 | self.tauW = tauW | |
3938 | self.thetaT = thetaT |
|
3938 | self.thetaT = thetaT | |
3939 | self.thetaR = thetaR |
|
3939 | self.thetaR = thetaR | |
3940 | self.Km = Km |
|
3940 | self.Km = Km | |
3941 | Numerator = ((4*numpy.pi)**3 * aL**2 * 16 *numpy.log(2)) |
|
3941 | Numerator = ((4*numpy.pi)**3 * aL**2 * 16 *numpy.log(2)) | |
3942 | Denominator = (Pt * Gt * Gr * lambda_**2 * SPEED_OF_LIGHT * tauW * numpy.pi*thetaT*thetaR) |
|
3942 | Denominator = (Pt * Gt * Gr * lambda_**2 * SPEED_OF_LIGHT * tauW * numpy.pi*thetaT*thetaR) | |
3943 | self.RadarConstant = Numerator/Denominator |
|
3943 | self.RadarConstant = Numerator/Denominator | |
3944 | self.variableList= variableList |
|
3944 | self.variableList= variableList | |
3945 |
|
3945 | |||
3946 | def setMoments(self,dataOut,i): |
|
3946 | def setMoments(self,dataOut,i): | |
3947 |
|
3947 | |||
3948 | type = dataOut.inputUnit |
|
3948 | type = dataOut.inputUnit | |
3949 | nCh = dataOut.nChannels |
|
3949 | nCh = dataOut.nChannels | |
3950 | nHeis = dataOut.nHeights |
|
3950 | nHeis = dataOut.nHeights | |
3951 | data_param = numpy.zeros((nCh,4,nHeis)) |
|
3951 | data_param = numpy.zeros((nCh,4,nHeis)) | |
3952 | if type == "Voltage": |
|
3952 | if type == "Voltage": | |
3953 | factor = dataOut.normFactor |
|
3953 | factor = dataOut.normFactor | |
3954 | data_param[:,0,:] = dataOut.dataPP_POW/(factor) |
|
3954 | data_param[:,0,:] = dataOut.dataPP_POW/(factor) | |
3955 | data_param[:,1,:] = dataOut.dataPP_DOP |
|
3955 | data_param[:,1,:] = dataOut.dataPP_DOP | |
3956 | data_param[:,2,:] = dataOut.dataPP_WIDTH |
|
3956 | data_param[:,2,:] = dataOut.dataPP_WIDTH | |
3957 | data_param[:,3,:] = dataOut.dataPP_SNR |
|
3957 | data_param[:,3,:] = dataOut.dataPP_SNR | |
3958 | if type == "Spectra": |
|
3958 | if type == "Spectra": | |
3959 | data_param[:,0,:] = dataOut.data_POW |
|
3959 | data_param[:,0,:] = dataOut.data_POW | |
3960 | data_param[:,1,:] = dataOut.data_DOP |
|
3960 | data_param[:,1,:] = dataOut.data_DOP | |
3961 | data_param[:,2,:] = dataOut.data_WIDTH |
|
3961 | data_param[:,2,:] = dataOut.data_WIDTH | |
3962 | data_param[:,3,:] = dataOut.data_SNR |
|
3962 | data_param[:,3,:] = dataOut.data_SNR | |
3963 |
|
3963 | |||
3964 | return data_param[:,i,:] |
|
3964 | return data_param[:,i,:] | |
3965 |
|
3965 | |||
3966 | def getCoeficienteCorrelacionROhv_R(self,dataOut): |
|
3966 | def getCoeficienteCorrelacionROhv_R(self,dataOut): | |
3967 | type = dataOut.inputUnit |
|
3967 | type = dataOut.inputUnit | |
3968 | nHeis = dataOut.nHeights |
|
3968 | nHeis = dataOut.nHeights | |
3969 | data_RhoHV_R = numpy.zeros((nHeis)) |
|
3969 | data_RhoHV_R = numpy.zeros((nHeis)) | |
3970 | if type == "Voltage": |
|
3970 | if type == "Voltage": | |
3971 | powa = dataOut.dataPP_POWER[0] |
|
3971 | powa = dataOut.dataPP_POWER[0] | |
3972 | powb = dataOut.dataPP_POWER[1] |
|
3972 | powb = dataOut.dataPP_POWER[1] | |
3973 | ccf = dataOut.dataPP_CCF |
|
3973 | ccf = dataOut.dataPP_CCF | |
3974 | avgcoherenceComplex = ccf / numpy.sqrt(powa * powb) |
|
3974 | avgcoherenceComplex = ccf / numpy.sqrt(powa * powb) | |
3975 | data_RhoHV_R = numpy.abs(avgcoherenceComplex) |
|
3975 | data_RhoHV_R = numpy.abs(avgcoherenceComplex) | |
3976 | if type == "Spectra": |
|
3976 | if type == "Spectra": | |
3977 | data_RhoHV_R = dataOut.getCoherence() |
|
3977 | data_RhoHV_R = dataOut.getCoherence() | |
3978 |
|
3978 | |||
3979 | return data_RhoHV_R |
|
3979 | return data_RhoHV_R | |
3980 |
|
3980 | |||
3981 | def getFasediferencialPhiD_P(self,dataOut,phase= True): |
|
3981 | def getFasediferencialPhiD_P(self,dataOut,phase= True): | |
3982 | type = dataOut.inputUnit |
|
3982 | type = dataOut.inputUnit | |
3983 | nHeis = dataOut.nHeights |
|
3983 | nHeis = dataOut.nHeights | |
3984 | data_PhiD_P = numpy.zeros((nHeis)) |
|
3984 | data_PhiD_P = numpy.zeros((nHeis)) | |
3985 | if type == "Voltage": |
|
3985 | if type == "Voltage": | |
3986 | powa = dataOut.dataPP_POWER[0] |
|
3986 | powa = dataOut.dataPP_POWER[0] | |
3987 | powb = dataOut.dataPP_POWER[1] |
|
3987 | powb = dataOut.dataPP_POWER[1] | |
3988 | ccf = dataOut.dataPP_CCF |
|
3988 | ccf = dataOut.dataPP_CCF | |
3989 | avgcoherenceComplex = ccf / numpy.sqrt(powa * powb) |
|
3989 | avgcoherenceComplex = ccf / numpy.sqrt(powa * powb) | |
3990 | if phase: |
|
3990 | if phase: | |
3991 | data_PhiD_P = numpy.arctan2(avgcoherenceComplex.imag, |
|
3991 | data_PhiD_P = numpy.arctan2(avgcoherenceComplex.imag, | |
3992 | avgcoherenceComplex.real) * 180 / numpy.pi |
|
3992 | avgcoherenceComplex.real) * 180 / numpy.pi | |
3993 | if type == "Spectra": |
|
3993 | if type == "Spectra": | |
3994 | data_PhiD_P = dataOut.getCoherence(phase = phase) |
|
3994 | data_PhiD_P = dataOut.getCoherence(phase = phase) | |
3995 |
|
3995 | |||
3996 | return data_PhiD_P |
|
3996 | return data_PhiD_P | |
3997 |
|
3997 | |||
3998 | def getReflectividad_D(self,dataOut): |
|
3998 | def getReflectividad_D(self,dataOut): | |
3999 | '''-----------------------------Potencia de Radar -Signal S-----------------------------''' |
|
3999 | '''-----------------------------Potencia de Radar -Signal S-----------------------------''' | |
4000 |
|
4000 | |||
4001 | Pr = self.setMoments(dataOut,0) |
|
4001 | Pr = self.setMoments(dataOut,0) | |
4002 |
|
4002 | |||
4003 | '''-----------2 Reflectividad del Radar y Factor de Reflectividad------''' |
|
4003 | '''-----------2 Reflectividad del Radar y Factor de Reflectividad------''' | |
4004 | self.n_radar = numpy.zeros((self.nCh,self.nHeis)) |
|
4004 | self.n_radar = numpy.zeros((self.nCh,self.nHeis)) | |
4005 | self.Z_radar = numpy.zeros((self.nCh,self.nHeis)) |
|
4005 | self.Z_radar = numpy.zeros((self.nCh,self.nHeis)) | |
4006 | for R in range(self.nHeis): |
|
4006 | for R in range(self.nHeis): | |
4007 | self.n_radar[:,R] = self.RadarConstant*Pr[:,R]* (self.Range[:,R])**2 |
|
4007 | self.n_radar[:,R] = self.RadarConstant*Pr[:,R]* (self.Range[:,R])**2 | |
4008 |
|
4008 | |||
4009 | self.Z_radar[:,R] = self.n_radar[:,R]* self.lambda_**4/( numpy.pi**5 * self.Km**2) |
|
4009 | self.Z_radar[:,R] = self.n_radar[:,R]* self.lambda_**4/( numpy.pi**5 * self.Km**2) | |
4010 |
|
4010 | |||
4011 | '''----------- Factor de Reflectividad Equivalente lamda_ < 10 cm , lamda_= 3.2cm-------''' |
|
4011 | '''----------- Factor de Reflectividad Equivalente lamda_ < 10 cm , lamda_= 3.2cm-------''' | |
4012 | Zeh = self.Z_radar |
|
4012 | Zeh = self.Z_radar | |
4013 | dBZeh = 10*numpy.log10(Zeh) |
|
4013 | dBZeh = 10*numpy.log10(Zeh) | |
4014 | Zdb_D = dBZeh[0] - dBZeh[1] |
|
4014 | Zdb_D = dBZeh[0] - dBZeh[1] | |
4015 | return Zdb_D |
|
4015 | return Zdb_D | |
4016 |
|
4016 | |||
4017 | def getRadialVelocity_V(self,dataOut): |
|
4017 | def getRadialVelocity_V(self,dataOut): | |
4018 | velRadial_V = self.setMoments(dataOut,1) |
|
4018 | velRadial_V = self.setMoments(dataOut,1) | |
4019 | return velRadial_V |
|
4019 | return velRadial_V | |
4020 |
|
4020 | |||
4021 | def getAnchoEspectral_W(self,dataOut): |
|
4021 | def getAnchoEspectral_W(self,dataOut): | |
4022 | Sigmav_W = self.setMoments(dataOut,2) |
|
4022 | Sigmav_W = self.setMoments(dataOut,2) | |
4023 | return Sigmav_W |
|
4023 | return Sigmav_W | |
4024 |
|
4024 | |||
4025 |
|
4025 | |||
4026 | def run(self,dataOut,variableList=None,Pt=25,Gt=200.0,Gr=50.0,lambda_=0.32, aL=2.5118, |
|
4026 | def run(self,dataOut,variableList=None,Pt=25,Gt=200.0,Gr=50.0,lambda_=0.32, aL=2.5118, | |
4027 | tauW= 4.0e-6,thetaT=0.165,thetaR=0.367,Km =0.93): |
|
4027 | tauW= 4.0e-6,thetaT=0.165,thetaR=0.367,Km =0.93): | |
4028 |
|
4028 | |||
4029 | if not self.isConfig: |
|
4029 | if not self.isConfig: | |
4030 | self.setup(dataOut= dataOut,variableList=None,Pt=25,Gt=200.0,Gr=50.0,lambda_=0.32, aL=2.5118, |
|
4030 | self.setup(dataOut= dataOut,variableList=None,Pt=25,Gt=200.0,Gr=50.0,lambda_=0.32, aL=2.5118, | |
4031 | tauW= 4.0e-6,thetaT=0.165,thetaR=0.367,Km =0.93) |
|
4031 | tauW= 4.0e-6,thetaT=0.165,thetaR=0.367,Km =0.93) | |
4032 | self.isConfig = True |
|
4032 | self.isConfig = True | |
4033 |
|
4033 | |||
4034 | for i in range(len(self.variableList)): |
|
4034 | for i in range(len(self.variableList)): | |
4035 | if self.variableList[i]=='ReflectividadDiferencial': |
|
4035 | if self.variableList[i]=='ReflectividadDiferencial': | |
4036 | dataOut.Zdb_D =self.getReflectividad_D(dataOut=dataOut) |
|
4036 | dataOut.Zdb_D =self.getReflectividad_D(dataOut=dataOut) | |
4037 | if self.variableList[i]=='FaseDiferencial': |
|
4037 | if self.variableList[i]=='FaseDiferencial': | |
4038 | dataOut.PhiD_P =self.getFasediferencialPhiD_P(dataOut=dataOut, phase=True) |
|
4038 | dataOut.PhiD_P =self.getFasediferencialPhiD_P(dataOut=dataOut, phase=True) | |
4039 | if self.variableList[i] == "CoeficienteCorrelacion": |
|
4039 | if self.variableList[i] == "CoeficienteCorrelacion": | |
4040 | dataOut.RhoHV_R = self.getCoeficienteCorrelacionROhv_R(dataOut) |
|
4040 | dataOut.RhoHV_R = self.getCoeficienteCorrelacionROhv_R(dataOut) | |
4041 | if self.variableList[i] =="VelocidadRadial": |
|
4041 | if self.variableList[i] =="VelocidadRadial": | |
4042 | dataOut.velRadial_V = self.getRadialVelocity_V(dataOut) |
|
4042 | dataOut.velRadial_V = self.getRadialVelocity_V(dataOut) | |
4043 | if self.variableList[i] =="AnchoEspectral": |
|
4043 | if self.variableList[i] =="AnchoEspectral": | |
4044 | dataOut.Sigmav_W = self.getAnchoEspectral_W(dataOut) |
|
4044 | dataOut.Sigmav_W = self.getAnchoEspectral_W(dataOut) | |
4045 | return dataOut |
|
4045 | return dataOut | |
4046 |
|
4046 | |||
4047 | class PedestalInformation(Operation): |
|
4047 | class PedestalInformation(Operation): | |
4048 |
|
4048 | |||
4049 | def __init__(self): |
|
4049 | def __init__(self): | |
4050 | Operation.__init__(self) |
|
4050 | Operation.__init__(self) | |
4051 | self.filename = False |
|
4051 | self.filename = False | |
4052 |
|
4052 | |||
4053 | def find_file(self, timestamp): |
|
4053 | def find_file(self, timestamp): | |
4054 |
|
4054 | |||
4055 | dt = datetime.datetime.utcfromtimestamp(timestamp) |
|
4055 | dt = datetime.datetime.utcfromtimestamp(timestamp) | |
4056 | path = os.path.join(self.path, dt.strftime('%Y-%m-%dT%H-00-00')) |
|
4056 | path = os.path.join(self.path, dt.strftime('%Y-%m-%dT%H-00-00')) | |
4057 |
|
4057 | |||
4058 | if not os.path.exists(path): |
|
4058 | if not os.path.exists(path): | |
4059 | return False, False |
|
4059 | return False, False | |
4060 | fileList = glob.glob(os.path.join(path, '*.h5')) |
|
4060 | fileList = glob.glob(os.path.join(path, '*.h5')) | |
4061 | fileList.sort() |
|
4061 | fileList.sort() | |
4062 | for fullname in fileList: |
|
4062 | for fullname in fileList: | |
4063 | filename = fullname.split('/')[-1] |
|
4063 | filename = fullname.split('/')[-1] | |
4064 | number = int(filename[4:14]) |
|
4064 | number = int(filename[4:14]) | |
4065 | if number <= timestamp: |
|
4065 | if number <= timestamp: | |
4066 | return number, fullname |
|
4066 | return number, fullname | |
4067 | return False, False |
|
4067 | return False, False | |
4068 |
|
4068 | |||
4069 | def find_next_file(self): |
|
4069 | def find_next_file(self): | |
4070 |
|
4070 | |||
4071 | while True: |
|
4071 | while True: | |
4072 |
file_size = len(self.fp['Data']['utc']) |
|
4072 | file_size = len(self.fp['Data']['utc']) | |
4073 | if self.utctime < self.utcfile+file_size*self.interval: |
|
4073 | if self.utctime < self.utcfile+file_size*self.interval: | |
4074 | break |
|
4074 | break | |
4075 | self.utcfile += file_size*self.interval |
|
4075 | self.utcfile += file_size*self.interval | |
4076 | dt = datetime.datetime.utcfromtimestamp(self.utctime) |
|
4076 | dt = datetime.datetime.utcfromtimestamp(self.utctime) | |
4077 | path = os.path.join(self.path, dt.strftime('%Y-%m-%dT%H-00-00')) |
|
4077 | path = os.path.join(self.path, dt.strftime('%Y-%m-%dT%H-00-00')) | |
4078 | self.filename = os.path.join(path, 'pos@{}.000.h5'.format(int(self.utcfile))) |
|
4078 | self.filename = os.path.join(path, 'pos@{}.000.h5'.format(int(self.utcfile))) | |
4079 | if not os.path.exists(self.filename): |
|
4079 | if not os.path.exists(self.filename): | |
4080 | log.warning('Waiting for position files...', self.name) |
|
4080 | log.warning('Waiting for position files...', self.name) | |
4081 |
|
4081 | |||
4082 | if not os.path.exists(self.filename): |
|
4082 | if not os.path.exists(self.filename): | |
4083 |
|
4083 | |||
4084 | raise IOError('No new position files found in {}'.format(path)) |
|
4084 | raise IOError('No new position files found in {}'.format(path)) | |
4085 | self.fp.close() |
|
4085 | self.fp.close() | |
4086 | self.fp = h5py.File(self.filename, 'r') |
|
4086 | self.fp = h5py.File(self.filename, 'r') | |
4087 | log.log('Opening file: {}'.format(self.filename), self.name) |
|
4087 | log.log('Opening file: {}'.format(self.filename), self.name) | |
4088 |
|
4088 | |||
4089 | def get_values(self): |
|
4089 | def get_values(self): | |
4090 |
|
4090 | |||
4091 | index = int((self.utctime-self.utcfile)/self.interval) |
|
4091 | index = int((self.utctime-self.utcfile)/self.interval) | |
4092 | return self.fp['Data']['azi_pos'][index], self.fp['Data']['ele_pos'][index] |
|
4092 | return self.fp['Data']['azi_pos'][index], self.fp['Data']['ele_pos'][index] | |
4093 |
|
4093 | |||
4094 | def setup(self, dataOut, path, conf, samples, interval, wr_exp): |
|
4094 | def setup(self, dataOut, path, conf, samples, interval, wr_exp): | |
4095 |
|
4095 | |||
4096 | self.path = path |
|
4096 | self.path = path | |
4097 | self.conf = conf |
|
4097 | self.conf = conf | |
4098 | self.samples = samples |
|
4098 | self.samples = samples | |
4099 | self.interval = interval |
|
4099 | self.interval = interval | |
4100 | self.utcfile, self.filename = self.find_file(dataOut.utctime) |
|
4100 | self.utcfile, self.filename = self.find_file(dataOut.utctime) | |
4101 |
|
4101 | |||
4102 | if not self.filename: |
|
4102 | if not self.filename: | |
4103 | log.error('No position files found in {}'.format(path), self.name) |
|
4103 | log.error('No position files found in {}'.format(path), self.name) | |
4104 | raise IOError('No position files found in {}'.format(path)) |
|
4104 | raise IOError('No position files found in {}'.format(path)) | |
4105 | else: |
|
4105 | else: | |
4106 | log.log('Opening file: {}'.format(self.filename), self.name) |
|
4106 | log.log('Opening file: {}'.format(self.filename), self.name) | |
4107 | self.fp = h5py.File(self.filename, 'r') |
|
4107 | self.fp = h5py.File(self.filename, 'r') | |
4108 |
|
4108 | |||
4109 | def run(self, dataOut, path, conf=None, samples=1500, interval=0.04, wr_exp=None): |
|
4109 | def run(self, dataOut, path, conf=None, samples=1500, interval=0.04, wr_exp=None): | |
4110 |
|
4110 | |||
4111 | if not self.isConfig: |
|
4111 | if not self.isConfig: | |
4112 | self.setup(dataOut, path, conf, samples, interval, wr_exp) |
|
4112 | self.setup(dataOut, path, conf, samples, interval, wr_exp) | |
4113 | self.isConfig = True |
|
4113 | self.isConfig = True | |
4114 |
|
4114 | |||
4115 | self.utctime = dataOut.utctime |
|
4115 | self.utctime = dataOut.utctime | |
4116 |
|
4116 | |||
4117 | self.find_next_file() |
|
4117 | self.find_next_file() | |
4118 |
|
4118 | |||
4119 | az, el = self.get_values() |
|
4119 | az, el = self.get_values() | |
4120 | dataOut.flagNoData = False |
|
4120 | dataOut.flagNoData = False | |
4121 |
|
4121 | |||
4122 | if numpy.isnan(az) or numpy.isnan(el) : |
|
4122 | if numpy.isnan(az) or numpy.isnan(el) : | |
4123 | dataOut.flagNoData = True |
|
4123 | dataOut.flagNoData = True | |
4124 | return dataOut |
|
4124 | return dataOut | |
4125 |
|
4125 | |||
4126 | dataOut.azimuth = az |
|
4126 | dataOut.azimuth = az | |
4127 | dataOut.elevation = el |
|
4127 | dataOut.elevation = el | |
4128 | # print('AZ: ', az, ' EL: ', el) |
|
4128 | # print('AZ: ', az, ' EL: ', el) | |
4129 | return dataOut |
|
4129 | return dataOut | |
4130 |
|
4130 | |||
4131 | class Block360(Operation): |
|
4131 | class Block360(Operation): | |
4132 | ''' |
|
4132 | ''' | |
4133 | ''' |
|
4133 | ''' | |
4134 | isConfig = False |
|
4134 | isConfig = False | |
4135 | __profIndex = 0 |
|
4135 | __profIndex = 0 | |
4136 | __initime = None |
|
4136 | __initime = None | |
4137 | __lastdatatime = None |
|
4137 | __lastdatatime = None | |
4138 | __buffer = None |
|
4138 | __buffer = None | |
4139 | __dataReady = False |
|
4139 | __dataReady = False | |
4140 | n = None |
|
4140 | n = None | |
4141 | __nch = 0 |
|
4141 | __nch = 0 | |
4142 | __nHeis = 0 |
|
4142 | __nHeis = 0 | |
4143 | index = 0 |
|
4143 | index = 0 | |
4144 | mode = 0 |
|
4144 | mode = 0 | |
4145 |
|
4145 | |||
4146 | def __init__(self,**kwargs): |
|
4146 | def __init__(self,**kwargs): | |
4147 | Operation.__init__(self,**kwargs) |
|
4147 | Operation.__init__(self,**kwargs) | |
4148 |
|
4148 | |||
4149 | def setup(self, dataOut, n = None, mode = None): |
|
4149 | def setup(self, dataOut, n = None, mode = None): | |
4150 | ''' |
|
4150 | ''' | |
4151 | n= Numero de PRF's de entrada |
|
4151 | n= Numero de PRF's de entrada | |
4152 | ''' |
|
4152 | ''' | |
4153 | self.__initime = None |
|
4153 | self.__initime = None | |
4154 | self.__lastdatatime = 0 |
|
4154 | self.__lastdatatime = 0 | |
4155 | self.__dataReady = False |
|
4155 | self.__dataReady = False | |
4156 | self.__buffer = 0 |
|
4156 | self.__buffer = 0 | |
4157 | self.__buffer_1D = 0 |
|
4157 | self.__buffer_1D = 0 | |
4158 | self.__profIndex = 0 |
|
4158 | self.__profIndex = 0 | |
4159 | self.index = 0 |
|
4159 | self.index = 0 | |
4160 | self.__nch = dataOut.nChannels |
|
4160 | self.__nch = dataOut.nChannels | |
4161 | self.__nHeis = dataOut.nHeights |
|
4161 | self.__nHeis = dataOut.nHeights | |
4162 | ##print("ELVALOR DE n es:", n) |
|
4162 | ##print("ELVALOR DE n es:", n) | |
4163 | if n == None: |
|
4163 | if n == None: | |
4164 | raise ValueError("n should be specified.") |
|
4164 | raise ValueError("n should be specified.") | |
4165 |
|
4165 | |||
4166 | if mode == None: |
|
4166 | if mode == None: | |
4167 | raise ValueError("mode should be specified.") |
|
4167 | raise ValueError("mode should be specified.") | |
4168 |
|
4168 | |||
4169 | if n != None: |
|
4169 | if n != None: | |
4170 | if n<1: |
|
4170 | if n<1: | |
4171 | print("n should be greater than 2") |
|
4171 | print("n should be greater than 2") | |
4172 | raise ValueError("n should be greater than 2") |
|
4172 | raise ValueError("n should be greater than 2") | |
4173 |
|
4173 | |||
4174 | self.n = n |
|
4174 | self.n = n | |
4175 | self.mode = mode |
|
4175 | self.mode = mode | |
4176 | #print("self.mode",self.mode) |
|
4176 | #print("self.mode",self.mode) | |
4177 | #print("nHeights") |
|
4177 | #print("nHeights") | |
4178 | self.__buffer = numpy.zeros(( dataOut.nChannels,n, dataOut.nHeights)) |
|
4178 | self.__buffer = numpy.zeros(( dataOut.nChannels,n, dataOut.nHeights)) | |
4179 | self.__buffer2 = numpy.zeros(n) |
|
4179 | self.__buffer2 = numpy.zeros(n) | |
4180 | self.__buffer3 = numpy.zeros(n) |
|
4180 | self.__buffer3 = numpy.zeros(n) | |
4181 |
|
4181 | |||
4182 |
|
4182 | |||
4183 |
|
4183 | |||
4184 |
|
4184 | |||
4185 | def putData(self,data,mode): |
|
4185 | def putData(self,data,mode): | |
4186 | ''' |
|
4186 | ''' | |
4187 | Add a profile to he __buffer and increase in one the __profiel Index |
|
4187 | Add a profile to he __buffer and increase in one the __profiel Index | |
4188 | ''' |
|
4188 | ''' | |
4189 | #print("line 4049",data.dataPP_POW.shape,data.dataPP_POW[:10]) |
|
4189 | #print("line 4049",data.dataPP_POW.shape,data.dataPP_POW[:10]) | |
4190 | #print("line 4049",data.azimuth.shape,data.azimuth) |
|
4190 | #print("line 4049",data.azimuth.shape,data.azimuth) | |
4191 | if self.mode==0: |
|
4191 | if self.mode==0: | |
4192 | self.__buffer[:,self.__profIndex,:]= data.dataPP_POWER# PRIMER MOMENTO |
|
4192 | self.__buffer[:,self.__profIndex,:]= data.dataPP_POWER# PRIMER MOMENTO | |
4193 | if self.mode==1: |
|
4193 | if self.mode==1: | |
4194 | self.__buffer[:,self.__profIndex,:]= data.data_pow |
|
4194 | self.__buffer[:,self.__profIndex,:]= data.data_pow | |
4195 | #print("me casi",self.index,data.azimuth[self.index]) |
|
4195 | #print("me casi",self.index,data.azimuth[self.index]) | |
4196 | #print(self.__profIndex, self.index , data.azimuth[self.index] ) |
|
4196 | #print(self.__profIndex, self.index , data.azimuth[self.index] ) | |
4197 | #print("magic",data.profileIndex) |
|
4197 | #print("magic",data.profileIndex) | |
4198 | #print(data.azimuth[self.index]) |
|
4198 | #print(data.azimuth[self.index]) | |
4199 | #print("index",self.index) |
|
4199 | #print("index",self.index) | |
4200 |
|
4200 | |||
4201 | #####self.__buffer2[self.__profIndex] = data.azimuth[self.index] |
|
4201 | #####self.__buffer2[self.__profIndex] = data.azimuth[self.index] | |
4202 | self.__buffer2[self.__profIndex] = data.azimuth |
|
4202 | self.__buffer2[self.__profIndex] = data.azimuth | |
4203 | self.__buffer3[self.__profIndex] = data.elevation |
|
4203 | self.__buffer3[self.__profIndex] = data.elevation | |
4204 | #print("q pasa") |
|
4204 | #print("q pasa") | |
4205 | #####self.index+=1 |
|
4205 | #####self.index+=1 | |
4206 | #print("index",self.index,data.azimuth[:10]) |
|
4206 | #print("index",self.index,data.azimuth[:10]) | |
4207 | self.__profIndex += 1 |
|
4207 | self.__profIndex += 1 | |
4208 | return #Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β· Remove DCΒ·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β· |
|
4208 | return #Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β· Remove DCΒ·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β· | |
4209 |
|
4209 | |||
4210 | def pushData(self,data): |
|
4210 | def pushData(self,data): | |
4211 | ''' |
|
4211 | ''' | |
4212 | Return the PULSEPAIR and the profiles used in the operation |
|
4212 | Return the PULSEPAIR and the profiles used in the operation | |
4213 | Affected : self.__profileIndex |
|
4213 | Affected : self.__profileIndex | |
4214 | ''' |
|
4214 | ''' | |
4215 | #print("pushData") |
|
4215 | #print("pushData") | |
4216 |
|
4216 | |||
4217 | data_360 = self.__buffer |
|
4217 | data_360 = self.__buffer | |
4218 | data_p = self.__buffer2 |
|
4218 | data_p = self.__buffer2 | |
4219 | data_e = self.__buffer3 |
|
4219 | data_e = self.__buffer3 | |
4220 | n = self.__profIndex |
|
4220 | n = self.__profIndex | |
4221 |
|
4221 | |||
4222 | self.__buffer = numpy.zeros((self.__nch, self.n,self.__nHeis)) |
|
4222 | self.__buffer = numpy.zeros((self.__nch, self.n,self.__nHeis)) | |
4223 | self.__buffer2 = numpy.zeros(self.n) |
|
4223 | self.__buffer2 = numpy.zeros(self.n) | |
4224 | self.__buffer3 = numpy.zeros(self.n) |
|
4224 | self.__buffer3 = numpy.zeros(self.n) | |
4225 | self.__profIndex = 0 |
|
4225 | self.__profIndex = 0 | |
4226 | #print("pushData") |
|
4226 | #print("pushData") | |
4227 | return data_360,n,data_p,data_e |
|
4227 | return data_360,n,data_p,data_e | |
4228 |
|
4228 | |||
4229 |
|
4229 | |||
4230 | def byProfiles(self,dataOut): |
|
4230 | def byProfiles(self,dataOut): | |
4231 |
|
4231 | |||
4232 | self.__dataReady = False |
|
4232 | self.__dataReady = False | |
4233 | data_360 = None |
|
4233 | data_360 = None | |
4234 | data_p = None |
|
4234 | data_p = None | |
4235 | data_e = None |
|
4235 | data_e = None | |
4236 | #print("dataOu",dataOut.dataPP_POW) |
|
4236 | #print("dataOu",dataOut.dataPP_POW) | |
4237 | self.putData(data=dataOut,mode = self.mode) |
|
4237 | self.putData(data=dataOut,mode = self.mode) | |
4238 | ##### print("profIndex",self.__profIndex) |
|
4238 | ##### print("profIndex",self.__profIndex) | |
4239 | if self.__profIndex == self.n: |
|
4239 | if self.__profIndex == self.n: | |
4240 | data_360,n,data_p,data_e = self.pushData(data=dataOut) |
|
4240 | data_360,n,data_p,data_e = self.pushData(data=dataOut) | |
4241 | self.__dataReady = True |
|
4241 | self.__dataReady = True | |
4242 |
|
4242 | |||
4243 | return data_360,data_p,data_e |
|
4243 | return data_360,data_p,data_e | |
4244 |
|
4244 | |||
4245 |
|
4245 | |||
4246 | def blockOp(self, dataOut, datatime= None): |
|
4246 | def blockOp(self, dataOut, datatime= None): | |
4247 | if self.__initime == None: |
|
4247 | if self.__initime == None: | |
4248 | self.__initime = datatime |
|
4248 | self.__initime = datatime | |
4249 | data_360,data_p,data_e = self.byProfiles(dataOut) |
|
4249 | data_360,data_p,data_e = self.byProfiles(dataOut) | |
4250 | self.__lastdatatime = datatime |
|
4250 | self.__lastdatatime = datatime | |
4251 |
|
4251 | |||
4252 | if data_360 is None: |
|
4252 | if data_360 is None: | |
4253 | return None, None,None,None |
|
4253 | return None, None,None,None | |
4254 |
|
4254 | |||
4255 |
|
4255 | |||
4256 | avgdatatime = self.__initime |
|
4256 | avgdatatime = self.__initime | |
4257 | if self.n==1: |
|
4257 | if self.n==1: | |
4258 | avgdatatime = datatime |
|
4258 | avgdatatime = datatime | |
4259 | deltatime = datatime - self.__lastdatatime |
|
4259 | deltatime = datatime - self.__lastdatatime | |
4260 | self.__initime = datatime |
|
4260 | self.__initime = datatime | |
4261 | #print(data_360.shape,avgdatatime,data_p.shape) |
|
4261 | #print(data_360.shape,avgdatatime,data_p.shape) | |
4262 | return data_360,avgdatatime,data_p,data_e |
|
4262 | return data_360,avgdatatime,data_p,data_e | |
4263 |
|
4263 | |||
4264 | def run(self, dataOut,n = None,mode=None,**kwargs): |
|
4264 | def run(self, dataOut,n = None,mode=None,**kwargs): | |
4265 | #print("BLOCK 360 HERE WE GO MOMENTOS") |
|
4265 | #print("BLOCK 360 HERE WE GO MOMENTOS") | |
4266 | print("Block 360") |
|
4266 | print("Block 360") | |
4267 | #exit(1) |
|
4267 | #exit(1) | |
4268 | if not self.isConfig: |
|
4268 | if not self.isConfig: | |
4269 | self.setup(dataOut = dataOut, n = n ,mode= mode ,**kwargs) |
|
4269 | self.setup(dataOut = dataOut, n = n ,mode= mode ,**kwargs) | |
4270 | ####self.index = 0 |
|
4270 | ####self.index = 0 | |
4271 | #print("comova",self.isConfig) |
|
4271 | #print("comova",self.isConfig) | |
4272 | self.isConfig = True |
|
4272 | self.isConfig = True | |
4273 | ####if self.index==dataOut.azimuth.shape[0]: |
|
4273 | ####if self.index==dataOut.azimuth.shape[0]: | |
4274 | #### self.index=0 |
|
4274 | #### self.index=0 | |
4275 | data_360, avgdatatime,data_p,data_e = self.blockOp(dataOut, dataOut.utctime) |
|
4275 | data_360, avgdatatime,data_p,data_e = self.blockOp(dataOut, dataOut.utctime) | |
4276 | dataOut.flagNoData = True |
|
4276 | dataOut.flagNoData = True | |
4277 |
|
4277 | |||
4278 | if self.__dataReady: |
|
4278 | if self.__dataReady: | |
4279 | dataOut.data_360 = data_360 # S |
|
4279 | dataOut.data_360 = data_360 # S | |
4280 | #print("DATA 360") |
|
4280 | #print("DATA 360") | |
4281 | #print(dataOut.data_360) |
|
4281 | #print(dataOut.data_360) | |
4282 | #print("---------------------------------------------------------------------------------") |
|
4282 | #print("---------------------------------------------------------------------------------") | |
4283 | print("---------------------------DATAREADY---------------------------------------------") |
|
4283 | print("---------------------------DATAREADY---------------------------------------------") | |
4284 | #print("---------------------------------------------------------------------------------") |
|
4284 | #print("---------------------------------------------------------------------------------") | |
4285 | #print("data_360",dataOut.data_360.shape) |
|
4285 | #print("data_360",dataOut.data_360.shape) | |
4286 | dataOut.data_azi = data_p |
|
4286 | dataOut.data_azi = data_p | |
4287 | dataOut.data_ele = data_e |
|
4287 | dataOut.data_ele = data_e | |
4288 | ###print("azi: ",dataOut.data_azi) |
|
4288 | ###print("azi: ",dataOut.data_azi) | |
4289 | #print("ele: ",dataOut.data_ele) |
|
4289 | #print("ele: ",dataOut.data_ele) | |
4290 | #print("jroproc_parameters",data_p[0],data_p[-1])#,data_360.shape,avgdatatime) |
|
4290 | #print("jroproc_parameters",data_p[0],data_p[-1])#,data_360.shape,avgdatatime) | |
4291 | dataOut.utctime = avgdatatime |
|
4291 | dataOut.utctime = avgdatatime | |
4292 | dataOut.flagNoData = False |
|
4292 | dataOut.flagNoData = False | |
4293 | return dataOut |
|
4293 | return dataOut | |
4294 |
|
4294 | |||
4295 | class Block360_vRF(Operation): |
|
4295 | class Block360_vRF(Operation): | |
4296 | ''' |
|
4296 | ''' | |
4297 | ''' |
|
4297 | ''' | |
4298 | isConfig = False |
|
4298 | isConfig = False | |
4299 | __profIndex = 0 |
|
4299 | __profIndex = 0 | |
4300 | __initime = None |
|
4300 | __initime = None | |
4301 | __lastdatatime = None |
|
4301 | __lastdatatime = None | |
4302 | __buffer = None |
|
4302 | __buffer = None | |
4303 | __dataReady = False |
|
4303 | __dataReady = False | |
4304 | n = None |
|
4304 | n = None | |
4305 | __nch = 0 |
|
4305 | __nch = 0 | |
4306 | __nHeis = 0 |
|
4306 | __nHeis = 0 | |
4307 | index = 0 |
|
4307 | index = 0 | |
4308 | mode = 0 |
|
4308 | mode = 0 | |
4309 |
|
4309 | |||
4310 | def __init__(self,**kwargs): |
|
4310 | def __init__(self,**kwargs): | |
4311 | Operation.__init__(self,**kwargs) |
|
4311 | Operation.__init__(self,**kwargs) | |
4312 |
|
4312 | |||
4313 | def setup(self, dataOut, n = None, mode = None): |
|
4313 | def setup(self, dataOut, n = None, mode = None): | |
4314 | ''' |
|
4314 | ''' | |
4315 | n= Numero de PRF's de entrada |
|
4315 | n= Numero de PRF's de entrada | |
4316 | ''' |
|
4316 | ''' | |
4317 | self.__initime = None |
|
4317 | self.__initime = None | |
4318 | self.__lastdatatime = 0 |
|
4318 | self.__lastdatatime = 0 | |
4319 | self.__dataReady = False |
|
4319 | self.__dataReady = False | |
4320 | self.__buffer = 0 |
|
4320 | self.__buffer = 0 | |
4321 | self.__buffer_1D = 0 |
|
4321 | self.__buffer_1D = 0 | |
4322 | self.__profIndex = 0 |
|
4322 | self.__profIndex = 0 | |
4323 | self.index = 0 |
|
4323 | self.index = 0 | |
4324 | self.__nch = dataOut.nChannels |
|
4324 | self.__nch = dataOut.nChannels | |
4325 | self.__nHeis = dataOut.nHeights |
|
4325 | self.__nHeis = dataOut.nHeights | |
4326 | ##print("ELVALOR DE n es:", n) |
|
4326 | ##print("ELVALOR DE n es:", n) | |
4327 | if n == None: |
|
4327 | if n == None: | |
4328 | raise ValueError("n should be specified.") |
|
4328 | raise ValueError("n should be specified.") | |
4329 |
|
4329 | |||
4330 | if mode == None: |
|
4330 | if mode == None: | |
4331 | raise ValueError("mode should be specified.") |
|
4331 | raise ValueError("mode should be specified.") | |
4332 |
|
4332 | |||
4333 | if n != None: |
|
4333 | if n != None: | |
4334 | if n<1: |
|
4334 | if n<1: | |
4335 | print("n should be greater than 2") |
|
4335 | print("n should be greater than 2") | |
4336 | raise ValueError("n should be greater than 2") |
|
4336 | raise ValueError("n should be greater than 2") | |
4337 |
|
4337 | |||
4338 | self.n = n |
|
4338 | self.n = n | |
4339 | self.mode = mode |
|
4339 | self.mode = mode | |
4340 | #print("self.mode",self.mode) |
|
4340 | #print("self.mode",self.mode) | |
4341 | #print("nHeights") |
|
4341 | #print("nHeights") | |
4342 | self.__buffer = numpy.zeros(( dataOut.nChannels,n, dataOut.nHeights)) |
|
4342 | self.__buffer = numpy.zeros(( dataOut.nChannels,n, dataOut.nHeights)) | |
4343 | self.__buffer2 = numpy.zeros(n) |
|
4343 | self.__buffer2 = numpy.zeros(n) | |
4344 | self.__buffer3 = numpy.zeros(n) |
|
4344 | self.__buffer3 = numpy.zeros(n) | |
4345 |
|
4345 | |||
4346 |
|
4346 | |||
4347 |
|
4347 | |||
4348 |
|
4348 | |||
4349 | def putData(self,data,mode): |
|
4349 | def putData(self,data,mode): | |
4350 | ''' |
|
4350 | ''' | |
4351 | Add a profile to he __buffer and increase in one the __profiel Index |
|
4351 | Add a profile to he __buffer and increase in one the __profiel Index | |
4352 | ''' |
|
4352 | ''' | |
4353 | #print("line 4049",data.dataPP_POW.shape,data.dataPP_POW[:10]) |
|
4353 | #print("line 4049",data.dataPP_POW.shape,data.dataPP_POW[:10]) | |
4354 | #print("line 4049",data.azimuth.shape,data.azimuth) |
|
4354 | #print("line 4049",data.azimuth.shape,data.azimuth) | |
4355 | if self.mode==0: |
|
4355 | if self.mode==0: | |
4356 | self.__buffer[:,self.__profIndex,:]= data.dataPP_POWER# PRIMER MOMENTO |
|
4356 | self.__buffer[:,self.__profIndex,:]= data.dataPP_POWER# PRIMER MOMENTO | |
4357 | if self.mode==1: |
|
4357 | if self.mode==1: | |
4358 | self.__buffer[:,self.__profIndex,:]= data.data_pow |
|
4358 | self.__buffer[:,self.__profIndex,:]= data.data_pow | |
4359 | #print("me casi",self.index,data.azimuth[self.index]) |
|
4359 | #print("me casi",self.index,data.azimuth[self.index]) | |
4360 | #print(self.__profIndex, self.index , data.azimuth[self.index] ) |
|
4360 | #print(self.__profIndex, self.index , data.azimuth[self.index] ) | |
4361 | #print("magic",data.profileIndex) |
|
4361 | #print("magic",data.profileIndex) | |
4362 | #print(data.azimuth[self.index]) |
|
4362 | #print(data.azimuth[self.index]) | |
4363 | #print("index",self.index) |
|
4363 | #print("index",self.index) | |
4364 |
|
4364 | |||
4365 | #####self.__buffer2[self.__profIndex] = data.azimuth[self.index] |
|
4365 | #####self.__buffer2[self.__profIndex] = data.azimuth[self.index] | |
4366 | self.__buffer2[self.__profIndex] = data.azimuth |
|
4366 | self.__buffer2[self.__profIndex] = data.azimuth | |
4367 | self.__buffer3[self.__profIndex] = data.elevation |
|
4367 | self.__buffer3[self.__profIndex] = data.elevation | |
4368 | #print("q pasa") |
|
4368 | #print("q pasa") | |
4369 | #####self.index+=1 |
|
4369 | #####self.index+=1 | |
4370 | #print("index",self.index,data.azimuth[:10]) |
|
4370 | #print("index",self.index,data.azimuth[:10]) | |
4371 | self.__profIndex += 1 |
|
4371 | self.__profIndex += 1 | |
4372 | return #Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β· Remove DCΒ·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β· |
|
4372 | return #Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β· Remove DCΒ·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β· | |
4373 |
|
4373 | |||
4374 | def pushData(self,data): |
|
4374 | def pushData(self,data): | |
4375 | ''' |
|
4375 | ''' | |
4376 | Return the PULSEPAIR and the profiles used in the operation |
|
4376 | Return the PULSEPAIR and the profiles used in the operation | |
4377 | Affected : self.__profileIndex |
|
4377 | Affected : self.__profileIndex | |
4378 | ''' |
|
4378 | ''' | |
4379 | #print("pushData") |
|
4379 | #print("pushData") | |
4380 |
|
4380 | |||
4381 | data_360 = self.__buffer |
|
4381 | data_360 = self.__buffer | |
4382 | data_p = self.__buffer2 |
|
4382 | data_p = self.__buffer2 | |
4383 | data_e = self.__buffer3 |
|
4383 | data_e = self.__buffer3 | |
4384 | n = self.__profIndex |
|
4384 | n = self.__profIndex | |
4385 |
|
4385 | |||
4386 | self.__buffer = numpy.zeros((self.__nch, self.n,self.__nHeis)) |
|
4386 | self.__buffer = numpy.zeros((self.__nch, self.n,self.__nHeis)) | |
4387 | self.__buffer2 = numpy.zeros(self.n) |
|
4387 | self.__buffer2 = numpy.zeros(self.n) | |
4388 | self.__buffer3 = numpy.zeros(self.n) |
|
4388 | self.__buffer3 = numpy.zeros(self.n) | |
4389 | self.__profIndex = 0 |
|
4389 | self.__profIndex = 0 | |
4390 | #print("pushData") |
|
4390 | #print("pushData") | |
4391 | return data_360,n,data_p,data_e |
|
4391 | return data_360,n,data_p,data_e | |
4392 |
|
4392 | |||
4393 |
|
4393 | |||
4394 | def byProfiles(self,dataOut): |
|
4394 | def byProfiles(self,dataOut): | |
4395 |
|
4395 | |||
4396 | self.__dataReady = False |
|
4396 | self.__dataReady = False | |
4397 | data_360 = None |
|
4397 | data_360 = None | |
4398 | data_p = None |
|
4398 | data_p = None | |
4399 | data_e = None |
|
4399 | data_e = None | |
4400 | #print("dataOu",dataOut.dataPP_POW) |
|
4400 | #print("dataOu",dataOut.dataPP_POW) | |
4401 | self.putData(data=dataOut,mode = self.mode) |
|
4401 | self.putData(data=dataOut,mode = self.mode) | |
4402 | ##### print("profIndex",self.__profIndex) |
|
4402 | ##### print("profIndex",self.__profIndex) | |
4403 | if self.__profIndex == self.n: |
|
4403 | if self.__profIndex == self.n: | |
4404 | data_360,n,data_p,data_e = self.pushData(data=dataOut) |
|
4404 | data_360,n,data_p,data_e = self.pushData(data=dataOut) | |
4405 | self.__dataReady = True |
|
4405 | self.__dataReady = True | |
4406 |
|
4406 | |||
4407 | return data_360,data_p,data_e |
|
4407 | return data_360,data_p,data_e | |
4408 |
|
4408 | |||
4409 |
|
4409 | |||
4410 | def blockOp(self, dataOut, datatime= None): |
|
4410 | def blockOp(self, dataOut, datatime= None): | |
4411 | if self.__initime == None: |
|
4411 | if self.__initime == None: | |
4412 | self.__initime = datatime |
|
4412 | self.__initime = datatime | |
4413 | data_360,data_p,data_e = self.byProfiles(dataOut) |
|
4413 | data_360,data_p,data_e = self.byProfiles(dataOut) | |
4414 | self.__lastdatatime = datatime |
|
4414 | self.__lastdatatime = datatime | |
4415 |
|
4415 | |||
4416 | if data_360 is None: |
|
4416 | if data_360 is None: | |
4417 | return None, None,None,None |
|
4417 | return None, None,None,None | |
4418 |
|
4418 | |||
4419 |
|
4419 | |||
4420 | avgdatatime = self.__initime |
|
4420 | avgdatatime = self.__initime | |
4421 | if self.n==1: |
|
4421 | if self.n==1: | |
4422 | avgdatatime = datatime |
|
4422 | avgdatatime = datatime | |
4423 | deltatime = datatime - self.__lastdatatime |
|
4423 | deltatime = datatime - self.__lastdatatime | |
4424 | self.__initime = datatime |
|
4424 | self.__initime = datatime | |
4425 | #print(data_360.shape,avgdatatime,data_p.shape) |
|
4425 | #print(data_360.shape,avgdatatime,data_p.shape) | |
4426 | return data_360,avgdatatime,data_p,data_e |
|
4426 | return data_360,avgdatatime,data_p,data_e | |
4427 |
|
4427 | |||
4428 | def checkcase(self,data_ele): |
|
4428 | def checkcase(self,data_ele): | |
4429 | start = data_ele[0] |
|
4429 | start = data_ele[0] | |
4430 | end = data_ele[-1] |
|
4430 | end = data_ele[-1] | |
4431 | diff_angle = (end-start) |
|
4431 | diff_angle = (end-start) | |
4432 | len_ang=len(data_ele) |
|
4432 | len_ang=len(data_ele) | |
4433 | print("start",start) |
|
4433 | print("start",start) | |
4434 | print("end",end) |
|
4434 | print("end",end) | |
4435 | print("number",diff_angle) |
|
4435 | print("number",diff_angle) | |
4436 |
|
4436 | |||
4437 | print("len_ang",len_ang) |
|
4437 | print("len_ang",len_ang) | |
4438 |
|
4438 | |||
4439 | aux = (data_ele<0).any(axis=0) |
|
4439 | aux = (data_ele<0).any(axis=0) | |
4440 |
|
4440 | |||
4441 | #exit(1) |
|
4441 | #exit(1) | |
4442 | if diff_angle<0 and aux!=1: #Bajada |
|
4442 | if diff_angle<0 and aux!=1: #Bajada | |
4443 | return 1 |
|
4443 | return 1 | |
4444 | elif diff_angle<0 and aux==1: #Bajada con angulos negativos |
|
4444 | elif diff_angle<0 and aux==1: #Bajada con angulos negativos | |
4445 | return 0 |
|
4445 | return 0 | |
4446 | elif diff_angle == 0: # This case happens when the angle reaches the max_angle if n = 2 |
|
4446 | elif diff_angle == 0: # This case happens when the angle reaches the max_angle if n = 2 | |
4447 | self.flagEraseFirstData = 1 |
|
4447 | self.flagEraseFirstData = 1 | |
4448 | print("ToDO this case") |
|
4448 | print("ToDO this case") | |
4449 | exit(1) |
|
4449 | exit(1) | |
4450 | elif diff_angle>0: #Subida |
|
4450 | elif diff_angle>0: #Subida | |
4451 | return 0 |
|
4451 | return 0 | |
4452 |
|
4452 | |||
4453 | def run(self, dataOut,n = None,mode=None,**kwargs): |
|
4453 | def run(self, dataOut,n = None,mode=None,**kwargs): | |
4454 | #print("BLOCK 360 HERE WE GO MOMENTOS") |
|
4454 | #print("BLOCK 360 HERE WE GO MOMENTOS") | |
4455 | print("Block 360") |
|
4455 | print("Block 360") | |
4456 |
|
4456 | |||
4457 | #exit(1) |
|
4457 | #exit(1) | |
4458 | if not self.isConfig: |
|
4458 | if not self.isConfig: | |
4459 | if n == 1: |
|
4459 | if n == 1: | |
4460 | print("*******************Min Value is 2. Setting n = 2*******************") |
|
4460 | print("*******************Min Value is 2. Setting n = 2*******************") | |
4461 | n = 2 |
|
4461 | n = 2 | |
4462 | #exit(1) |
|
4462 | #exit(1) | |
4463 | print(n) |
|
4463 | print(n) | |
4464 | self.setup(dataOut = dataOut, n = n ,mode= mode ,**kwargs) |
|
4464 | self.setup(dataOut = dataOut, n = n ,mode= mode ,**kwargs) | |
4465 | ####self.index = 0 |
|
4465 | ####self.index = 0 | |
4466 | #print("comova",self.isConfig) |
|
4466 | #print("comova",self.isConfig) | |
4467 | self.isConfig = True |
|
4467 | self.isConfig = True | |
4468 | ####if self.index==dataOut.azimuth.shape[0]: |
|
4468 | ####if self.index==dataOut.azimuth.shape[0]: | |
4469 | #### self.index=0 |
|
4469 | #### self.index=0 | |
4470 | data_360, avgdatatime,data_p,data_e = self.blockOp(dataOut, dataOut.utctime) |
|
4470 | data_360, avgdatatime,data_p,data_e = self.blockOp(dataOut, dataOut.utctime) | |
4471 | dataOut.flagNoData = True |
|
4471 | dataOut.flagNoData = True | |
4472 |
|
4472 | |||
4473 | if self.__dataReady: |
|
4473 | if self.__dataReady: | |
4474 | dataOut.data_360 = data_360 # S |
|
4474 | dataOut.data_360 = data_360 # S | |
4475 | #print("DATA 360") |
|
4475 | #print("DATA 360") | |
4476 | #print(dataOut.data_360) |
|
4476 | #print(dataOut.data_360) | |
4477 | #print("---------------------------------------------------------------------------------") |
|
4477 | #print("---------------------------------------------------------------------------------") | |
4478 | print("---------------------------DATAREADY---------------------------------------------") |
|
4478 | print("---------------------------DATAREADY---------------------------------------------") | |
4479 | #print("---------------------------------------------------------------------------------") |
|
4479 | #print("---------------------------------------------------------------------------------") | |
4480 | #print("data_360",dataOut.data_360.shape) |
|
4480 | #print("data_360",dataOut.data_360.shape) | |
4481 | dataOut.data_azi = data_p |
|
4481 | dataOut.data_azi = data_p | |
4482 | dataOut.data_ele = data_e |
|
4482 | dataOut.data_ele = data_e | |
4483 | ###print("azi: ",dataOut.data_azi) |
|
4483 | ###print("azi: ",dataOut.data_azi) | |
4484 | #print("ele: ",dataOut.data_ele) |
|
4484 | #print("ele: ",dataOut.data_ele) | |
4485 | #print("jroproc_parameters",data_p[0],data_p[-1])#,data_360.shape,avgdatatime) |
|
4485 | #print("jroproc_parameters",data_p[0],data_p[-1])#,data_360.shape,avgdatatime) | |
4486 | dataOut.utctime = avgdatatime |
|
4486 | dataOut.utctime = avgdatatime | |
4487 |
|
4487 | |||
4488 | dataOut.case_flag = self.checkcase(dataOut.data_ele) |
|
4488 | dataOut.case_flag = self.checkcase(dataOut.data_ele) | |
4489 | if dataOut.case_flag: #Si estΓ‘ de bajada empieza a plotear |
|
4489 | if dataOut.case_flag: #Si estΓ‘ de bajada empieza a plotear | |
4490 | print("INSIDE CASE FLAG BAJADA") |
|
4490 | print("INSIDE CASE FLAG BAJADA") | |
4491 | dataOut.flagNoData = False |
|
4491 | dataOut.flagNoData = False | |
4492 | else: |
|
4492 | else: | |
4493 | print("CASE SUBIDA") |
|
4493 | print("CASE SUBIDA") | |
4494 | dataOut.flagNoData = True |
|
4494 | dataOut.flagNoData = True | |
4495 |
|
4495 | |||
4496 | #dataOut.flagNoData = False |
|
4496 | #dataOut.flagNoData = False | |
4497 | return dataOut |
|
4497 | return dataOut | |
4498 |
|
4498 | |||
4499 | class Block360_vRF2(Operation): |
|
4499 | class Block360_vRF2(Operation): | |
4500 | ''' |
|
4500 | ''' | |
4501 | ''' |
|
4501 | ''' | |
4502 | isConfig = False |
|
4502 | isConfig = False | |
4503 | __profIndex = 0 |
|
4503 | __profIndex = 0 | |
4504 | __initime = None |
|
4504 | __initime = None | |
4505 | __lastdatatime = None |
|
4505 | __lastdatatime = None | |
4506 | __buffer = None |
|
4506 | __buffer = None | |
4507 | __dataReady = False |
|
4507 | __dataReady = False | |
4508 | n = None |
|
4508 | n = None | |
4509 | __nch = 0 |
|
4509 | __nch = 0 | |
4510 | __nHeis = 0 |
|
4510 | __nHeis = 0 | |
4511 | index = 0 |
|
4511 | index = 0 | |
4512 |
mode = |
|
4512 | mode = None | |
4513 |
|
4513 | |||
4514 | def __init__(self,**kwargs): |
|
4514 | def __init__(self,**kwargs): | |
4515 | Operation.__init__(self,**kwargs) |
|
4515 | Operation.__init__(self,**kwargs) | |
4516 |
|
4516 | |||
4517 | def setup(self, dataOut, n = None, mode = None): |
|
4517 | def setup(self, dataOut, n = None, mode = None): | |
4518 | ''' |
|
4518 | ''' | |
4519 | n= Numero de PRF's de entrada |
|
4519 | n= Numero de PRF's de entrada | |
4520 | ''' |
|
4520 | ''' | |
4521 | self.__initime = None |
|
4521 | self.__initime = None | |
4522 | self.__lastdatatime = 0 |
|
4522 | self.__lastdatatime = 0 | |
4523 | self.__dataReady = False |
|
4523 | self.__dataReady = False | |
4524 | self.__buffer = 0 |
|
4524 | self.__buffer = 0 | |
4525 | self.__buffer_1D = 0 |
|
4525 | self.__buffer_1D = 0 | |
4526 | #self.__profIndex = 0 |
|
4526 | #self.__profIndex = 0 | |
4527 | self.index = 0 |
|
4527 | self.index = 0 | |
4528 | self.__nch = dataOut.nChannels |
|
4528 | self.__nch = dataOut.nChannels | |
4529 | self.__nHeis = dataOut.nHeights |
|
4529 | self.__nHeis = dataOut.nHeights | |
4530 |
|
4530 | |||
4531 | self.mode = mode |
|
4531 | self.mode = mode | |
4532 | #print("self.mode",self.mode) |
|
4532 | #print("self.mode",self.mode) | |
4533 | #print("nHeights") |
|
4533 | #print("nHeights") | |
4534 | self.__buffer = [] |
|
4534 | self.__buffer = [] | |
4535 | self.__buffer2 = [] |
|
4535 | self.__buffer2 = [] | |
4536 | self.__buffer3 = [] |
|
4536 | self.__buffer3 = [] | |
|
4537 | self.__buffer4 = [] | |||
4537 |
|
4538 | |||
4538 | def putData(self,data,mode): |
|
4539 | def putData(self,data,mode): | |
4539 | ''' |
|
4540 | ''' | |
4540 | Add a profile to he __buffer and increase in one the __profiel Index |
|
4541 | Add a profile to he __buffer and increase in one the __profiel Index | |
4541 | ''' |
|
4542 | ''' | |
4542 | #print("line 4049",data.dataPP_POW.shape,data.dataPP_POW[:10]) |
|
4543 | ||
4543 | #print("line 4049",data.azimuth.shape,data.azimuth) |
|
|||
4544 | if self.mode==0: |
|
4544 | if self.mode==0: | |
4545 | self.__buffer.append(data.dataPP_POWER)# PRIMER MOMENTO |
|
4545 | self.__buffer.append(data.dataPP_POWER)# PRIMER MOMENTO | |
4546 | if self.mode==1: |
|
4546 | if self.mode==1: | |
4547 | self.__buffer.append(data.data_pow) |
|
4547 | self.__buffer.append(data.data_pow) | |
4548 | #print("me casi",self.index,data.azimuth[self.index]) |
|
|||
4549 | #print(self.__profIndex, self.index , data.azimuth[self.index] ) |
|
|||
4550 | #print("magic",data.profileIndex) |
|
|||
4551 | #print(data.azimuth[self.index]) |
|
|||
4552 | #print("index",self.index) |
|
|||
4553 |
|
4548 | |||
4554 | #####self.__buffer2[self.__profIndex] = data.azimuth[self.index] |
|
4549 | self.__buffer4.append(data.dataPP_DOP) | |
|
4550 | ||||
4555 | self.__buffer2.append(data.azimuth) |
|
4551 | self.__buffer2.append(data.azimuth) | |
4556 | self.__buffer3.append(data.elevation) |
|
4552 | self.__buffer3.append(data.elevation) | |
4557 | self.__profIndex += 1 |
|
4553 | self.__profIndex += 1 | |
4558 | #print("q pasa") |
|
4554 | ||
4559 | return numpy.array(self.__buffer3) #Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β· Remove DCΒ·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β· |
|
4555 | return numpy.array(self.__buffer3) #Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β· Remove DCΒ·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β· | |
4560 |
|
4556 | |||
4561 | def pushData(self,data): |
|
4557 | def pushData(self,data): | |
4562 | ''' |
|
4558 | ''' | |
4563 | Return the PULSEPAIR and the profiles used in the operation |
|
4559 | Return the PULSEPAIR and the profiles used in the operation | |
4564 | Affected : self.__profileIndex |
|
4560 | Affected : self.__profileIndex | |
4565 | ''' |
|
4561 | ''' | |
4566 | #print("pushData") |
|
|||
4567 |
|
4562 | |||
4568 | data_360 = numpy.array(self.__buffer).transpose(1,0,2) |
|
4563 | data_360_Power = numpy.array(self.__buffer).transpose(1,0,2) | |
|
4564 | data_360_Velocity = numpy.array(self.__buffer4).transpose(1,0,2) | |||
4569 | data_p = numpy.array(self.__buffer2) |
|
4565 | data_p = numpy.array(self.__buffer2) | |
4570 | data_e = numpy.array(self.__buffer3) |
|
4566 | data_e = numpy.array(self.__buffer3) | |
4571 | n = self.__profIndex |
|
4567 | n = self.__profIndex | |
4572 |
|
4568 | |||
4573 |
self.__buffer |
|
4569 | self.__buffer = [] | |
|
4570 | self.__buffer4 = [] | |||
4574 | self.__buffer2 = [] |
|
4571 | self.__buffer2 = [] | |
4575 | self.__buffer3 = [] |
|
4572 | self.__buffer3 = [] | |
4576 | self.__profIndex = 0 |
|
4573 | self.__profIndex = 0 | |
4577 | #print("pushData") |
|
4574 | return data_360_Power,data_360_Velocity,n,data_p,data_e | |
4578 | return data_360,n,data_p,data_e |
|
|||
4579 |
|
4575 | |||
4580 |
|
4576 | |||
4581 | def byProfiles(self,dataOut): |
|
4577 | def byProfiles(self,dataOut): | |
4582 |
|
4578 | |||
4583 | self.__dataReady = False |
|
4579 | self.__dataReady = False | |
4584 |
data_360 = |
|
4580 | data_360_Power = [] | |
|
4581 | data_360_Velocity = [] | |||
4585 | data_p = None |
|
4582 | data_p = None | |
4586 | data_e = None |
|
4583 | data_e = None | |
4587 | #print("dataOu",dataOut.dataPP_POW) |
|
|||
4588 |
|
4584 | |||
4589 | elevations = self.putData(data=dataOut,mode = self.mode) |
|
4585 | elevations = self.putData(data=dataOut,mode = self.mode) | |
4590 | ##### print("profIndex",self.__profIndex) |
|
|||
4591 |
|
||||
4592 |
|
4586 | |||
4593 | if self.__profIndex > 1: |
|
4587 | if self.__profIndex > 1: | |
4594 | case_flag = self.checkcase(elevations) |
|
4588 | case_flag = self.checkcase(elevations) | |
4595 |
|
4589 | |||
4596 | if case_flag == 0: #Subida |
|
4590 | if case_flag == 0: #Subida | |
4597 | #Se borra el dato anterior para liberar buffer y comparar el dato actual con el siguiente |
|
4591 | ||
4598 | if len(self.__buffer) == 2: #Cuando estΓ‘ de subida |
|
4592 | if len(self.__buffer) == 2: #Cuando estΓ‘ de subida | |
|
4593 | #Se borra el dato anterior para liberar buffer y comparar el dato actual con el siguiente | |||
4599 | self.__buffer.pop(0) #Erase first data |
|
4594 | self.__buffer.pop(0) #Erase first data | |
4600 | self.__buffer2.pop(0) |
|
4595 | self.__buffer2.pop(0) | |
4601 | self.__buffer3.pop(0) |
|
4596 | self.__buffer3.pop(0) | |
|
4597 | self.__buffer4.pop(0) | |||
4602 | self.__profIndex -= 1 |
|
4598 | self.__profIndex -= 1 | |
4603 | else: #Cuando ha estado de bajada y ha vuelto a subir |
|
4599 | else: #Cuando ha estado de bajada y ha vuelto a subir | |
4604 | #print("else",self.__buffer3) |
|
4600 | #Se borra el ΓΊltimo dato | |
4605 | self.__buffer.pop() #Erase last data |
|
4601 | self.__buffer.pop() #Erase last data | |
4606 | self.__buffer2.pop() |
|
4602 | self.__buffer2.pop() | |
4607 | self.__buffer3.pop() |
|
4603 | self.__buffer3.pop() | |
4608 | data_360,n,data_p,data_e = self.pushData(data=dataOut) |
|
4604 | self.__buffer4.pop() | |
4609 | #print(data_360.shape) |
|
4605 | data_360_Power,data_360_Velocity,n,data_p,data_e = self.pushData(data=dataOut) | |
4610 | #print(data_e.shape) |
|
4606 | ||
4611 | #exit(1) |
|
|||
4612 | self.__dataReady = True |
|
4607 | self.__dataReady = True | |
4613 | ''' |
|
4608 | ||
4614 | elif elevations[-1]<0.: |
|
4609 | return data_360_Power,data_360_Velocity,data_p,data_e | |
4615 | if len(self.__buffer) == 2: |
|
4610 | ||
|
4611 | ||||
|
4612 | def blockOp(self, dataOut, datatime= None): | |||
|
4613 | if self.__initime == None: | |||
|
4614 | self.__initime = datatime | |||
|
4615 | data_360_Power,data_360_Velocity,data_p,data_e = self.byProfiles(dataOut) | |||
|
4616 | self.__lastdatatime = datatime | |||
|
4617 | ||||
|
4618 | avgdatatime = self.__initime | |||
|
4619 | if self.n==1: | |||
|
4620 | avgdatatime = datatime | |||
|
4621 | deltatime = datatime - self.__lastdatatime | |||
|
4622 | self.__initime = datatime | |||
|
4623 | return data_360_Power,data_360_Velocity,avgdatatime,data_p,data_e | |||
|
4624 | ||||
|
4625 | def checkcase(self,data_ele): | |||
|
4626 | #print(data_ele) | |||
|
4627 | start = data_ele[-2] | |||
|
4628 | end = data_ele[-1] | |||
|
4629 | diff_angle = (end-start) | |||
|
4630 | len_ang=len(data_ele) | |||
|
4631 | ||||
|
4632 | if diff_angle > 0: #Subida | |||
|
4633 | return 0 | |||
|
4634 | ||||
|
4635 | def run(self, dataOut,mode='Power',**kwargs): | |||
|
4636 | #print("BLOCK 360 HERE WE GO MOMENTOS") | |||
|
4637 | #print("Block 360") | |||
|
4638 | dataOut.mode = mode | |||
|
4639 | ||||
|
4640 | if not self.isConfig: | |||
|
4641 | self.setup(dataOut = dataOut ,mode= mode ,**kwargs) | |||
|
4642 | self.isConfig = True | |||
|
4643 | ||||
|
4644 | ||||
|
4645 | data_360_Power, data_360_Velocity, avgdatatime,data_p,data_e = self.blockOp(dataOut, dataOut.utctime) | |||
|
4646 | ||||
|
4647 | ||||
|
4648 | dataOut.flagNoData = True | |||
|
4649 | ||||
|
4650 | ||||
|
4651 | if self.__dataReady: | |||
|
4652 | dataOut.data_360_Power = data_360_Power # S | |||
|
4653 | dataOut.data_360_Velocity = data_360_Velocity | |||
|
4654 | dataOut.data_azi = data_p | |||
|
4655 | dataOut.data_ele = data_e | |||
|
4656 | dataOut.utctime = avgdatatime | |||
|
4657 | dataOut.flagNoData = False | |||
|
4658 | ||||
|
4659 | return dataOut | |||
|
4660 | ||||
|
4661 | class Block360_vRF3(Operation): | |||
|
4662 | ''' | |||
|
4663 | ''' | |||
|
4664 | isConfig = False | |||
|
4665 | __profIndex = 0 | |||
|
4666 | __initime = None | |||
|
4667 | __lastdatatime = None | |||
|
4668 | __buffer = None | |||
|
4669 | __dataReady = False | |||
|
4670 | n = None | |||
|
4671 | __nch = 0 | |||
|
4672 | __nHeis = 0 | |||
|
4673 | index = 0 | |||
|
4674 | mode = None | |||
|
4675 | ||||
|
4676 | def __init__(self,**kwargs): | |||
|
4677 | Operation.__init__(self,**kwargs) | |||
|
4678 | ||||
|
4679 | def setup(self, dataOut, n = None, mode = None): | |||
|
4680 | ''' | |||
|
4681 | n= Numero de PRF's de entrada | |||
|
4682 | ''' | |||
|
4683 | self.__initime = None | |||
|
4684 | self.__lastdatatime = 0 | |||
|
4685 | self.__dataReady = False | |||
|
4686 | self.__buffer = 0 | |||
|
4687 | self.__buffer_1D = 0 | |||
|
4688 | #self.__profIndex = 0 | |||
|
4689 | self.index = 0 | |||
|
4690 | self.__nch = dataOut.nChannels | |||
|
4691 | self.__nHeis = dataOut.nHeights | |||
|
4692 | ||||
|
4693 | self.mode = mode | |||
|
4694 | #print("self.mode",self.mode) | |||
|
4695 | #print("nHeights") | |||
|
4696 | self.__buffer = [] | |||
|
4697 | self.__buffer2 = [] | |||
|
4698 | self.__buffer3 = [] | |||
|
4699 | self.__buffer4 = [] | |||
|
4700 | ||||
|
4701 | def putData(self,data,mode): | |||
|
4702 | ''' | |||
|
4703 | Add a profile to he __buffer and increase in one the __profiel Index | |||
|
4704 | ''' | |||
|
4705 | ||||
|
4706 | if self.mode==0: | |||
|
4707 | self.__buffer.append(data.dataPP_POWER)# PRIMER MOMENTO | |||
|
4708 | if self.mode==1: | |||
|
4709 | self.__buffer.append(data.data_pow) | |||
|
4710 | ||||
|
4711 | self.__buffer4.append(data.dataPP_DOP) | |||
|
4712 | ||||
|
4713 | self.__buffer2.append(data.azimuth) | |||
|
4714 | self.__buffer3.append(data.elevation) | |||
|
4715 | self.__profIndex += 1 | |||
|
4716 | ||||
|
4717 | return numpy.array(self.__buffer3) #Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β· Remove DCΒ·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β· | |||
|
4718 | ||||
|
4719 | def pushData(self,data): | |||
|
4720 | ''' | |||
|
4721 | Return the PULSEPAIR and the profiles used in the operation | |||
|
4722 | Affected : self.__profileIndex | |||
|
4723 | ''' | |||
|
4724 | ||||
|
4725 | data_360_Power = numpy.array(self.__buffer).transpose(1,0,2) | |||
|
4726 | data_360_Velocity = numpy.array(self.__buffer4).transpose(1,0,2) | |||
|
4727 | data_p = numpy.array(self.__buffer2) | |||
|
4728 | data_e = numpy.array(self.__buffer3) | |||
|
4729 | n = self.__profIndex | |||
|
4730 | ||||
|
4731 | self.__buffer = [] | |||
|
4732 | self.__buffer4 = [] | |||
|
4733 | self.__buffer2 = [] | |||
|
4734 | self.__buffer3 = [] | |||
|
4735 | self.__profIndex = 0 | |||
|
4736 | return data_360_Power,data_360_Velocity,n,data_p,data_e | |||
|
4737 | ||||
|
4738 | ||||
|
4739 | def byProfiles(self,dataOut): | |||
|
4740 | ||||
|
4741 | self.__dataReady = False | |||
|
4742 | data_360_Power = [] | |||
|
4743 | data_360_Velocity = [] | |||
|
4744 | data_p = None | |||
|
4745 | data_e = None | |||
|
4746 | ||||
|
4747 | elevations = self.putData(data=dataOut,mode = self.mode) | |||
|
4748 | ||||
|
4749 | if self.__profIndex > 1: | |||
|
4750 | case_flag = self.checkcase(elevations) | |||
|
4751 | ||||
|
4752 | if case_flag == 0: #Subida | |||
|
4753 | ||||
|
4754 | if len(self.__buffer) == 2: #Cuando estΓ‘ de subida | |||
|
4755 | #Se borra el dato anterior para liberar buffer y comparar el dato actual con el siguiente | |||
4616 | self.__buffer.pop(0) #Erase first data |
|
4756 | self.__buffer.pop(0) #Erase first data | |
4617 | self.__buffer2.pop(0) |
|
4757 | self.__buffer2.pop(0) | |
4618 | self.__buffer3.pop(0) |
|
4758 | self.__buffer3.pop(0) | |
|
4759 | self.__buffer4.pop(0) | |||
4619 | self.__profIndex -= 1 |
|
4760 | self.__profIndex -= 1 | |
4620 | else: |
|
4761 | else: #Cuando ha estado de bajada y ha vuelto a subir | |
|
4762 | #Se borra el ΓΊltimo dato | |||
4621 | self.__buffer.pop() #Erase last data |
|
4763 | self.__buffer.pop() #Erase last data | |
4622 | self.__buffer2.pop() |
|
4764 | self.__buffer2.pop() | |
4623 | self.__buffer3.pop() |
|
4765 | self.__buffer3.pop() | |
4624 | data_360,n,data_p,data_e = self.pushData(data=dataOut) |
|
4766 | self.__buffer4.pop() | |
4625 | self.__dataReady = True |
|
4767 | data_360_Power,data_360_Velocity,n,data_p,data_e = self.pushData(data=dataOut) | |
4626 | ''' |
|
|||
4627 |
|
||||
4628 |
|
4768 | |||
4629 | ''' |
|
4769 | self.__dataReady = True | |
4630 | if self.__profIndex == self.n: |
|
|||
4631 | data_360,n,data_p,data_e = self.pushData(data=dataOut) |
|
|||
4632 | self.__dataReady = True |
|
|||
4633 | ''' |
|
|||
4634 |
|
4770 | |||
4635 | return data_360,data_p,data_e |
|
4771 | return data_360_Power,data_360_Velocity,data_p,data_e | |
4636 |
|
4772 | |||
4637 |
|
4773 | |||
4638 | def blockOp(self, dataOut, datatime= None): |
|
4774 | def blockOp(self, dataOut, datatime= None): | |
4639 | if self.__initime == None: |
|
4775 | if self.__initime == None: | |
4640 | self.__initime = datatime |
|
4776 | self.__initime = datatime | |
4641 | data_360,data_p,data_e = self.byProfiles(dataOut) |
|
4777 | data_360_Power,data_360_Velocity,data_p,data_e = self.byProfiles(dataOut) | |
4642 | self.__lastdatatime = datatime |
|
4778 | self.__lastdatatime = datatime | |
4643 |
|
4779 | |||
4644 | if data_360 is None: |
|
|||
4645 | return None, None,None,None |
|
|||
4646 |
|
||||
4647 |
|
||||
4648 | avgdatatime = self.__initime |
|
4780 | avgdatatime = self.__initime | |
4649 | if self.n==1: |
|
4781 | if self.n==1: | |
4650 | avgdatatime = datatime |
|
4782 | avgdatatime = datatime | |
4651 | deltatime = datatime - self.__lastdatatime |
|
4783 | deltatime = datatime - self.__lastdatatime | |
4652 | self.__initime = datatime |
|
4784 | self.__initime = datatime | |
4653 |
|
|
4785 | return data_360_Power,data_360_Velocity,avgdatatime,data_p,data_e | |
4654 | return data_360,avgdatatime,data_p,data_e |
|
|||
4655 |
|
4786 | |||
4656 | def checkcase(self,data_ele): |
|
4787 | def checkcase(self,data_ele): | |
4657 | print(data_ele) |
|
4788 | #print(data_ele) | |
4658 | start = data_ele[-2] |
|
4789 | start = data_ele[-2] | |
4659 | end = data_ele[-1] |
|
4790 | end = data_ele[-1] | |
4660 | diff_angle = (end-start) |
|
4791 | diff_angle = (end-start) | |
4661 | len_ang=len(data_ele) |
|
4792 | len_ang=len(data_ele) | |
4662 |
|
4793 | |||
4663 | if diff_angle > 0: #Subida |
|
4794 | if diff_angle > 0: #Subida | |
4664 | return 0 |
|
4795 | return 0 | |
4665 |
|
4796 | |||
4666 |
def run(self, dataOut, |
|
4797 | def run(self, dataOut,mode='Power',**kwargs): | |
4667 | #print("BLOCK 360 HERE WE GO MOMENTOS") |
|
4798 | #print("BLOCK 360 HERE WE GO MOMENTOS") | |
4668 | print("Block 360") |
|
4799 | #print("Block 360") | |
|
4800 | dataOut.mode = mode | |||
4669 |
|
4801 | |||
4670 | #exit(1) |
|
|||
4671 | if not self.isConfig: |
|
4802 | if not self.isConfig: | |
4672 |
|
||||
4673 | print(n) |
|
|||
4674 | self.setup(dataOut = dataOut ,mode= mode ,**kwargs) |
|
4803 | self.setup(dataOut = dataOut ,mode= mode ,**kwargs) | |
4675 | ####self.index = 0 |
|
|||
4676 | #print("comova",self.isConfig) |
|
|||
4677 | self.isConfig = True |
|
4804 | self.isConfig = True | |
4678 | ####if self.index==dataOut.azimuth.shape[0]: |
|
|||
4679 | #### self.index=0 |
|
|||
4680 |
|
||||
4681 | data_360, avgdatatime,data_p,data_e = self.blockOp(dataOut, dataOut.utctime) |
|
|||
4682 |
|
4805 | |||
4683 |
|
4806 | |||
|
4807 | data_360_Power, data_360_Velocity, avgdatatime,data_p,data_e = self.blockOp(dataOut, dataOut.utctime) | |||
4684 |
|
4808 | |||
4685 |
|
4809 | |||
4686 | dataOut.flagNoData = True |
|
4810 | dataOut.flagNoData = True | |
4687 |
|
4811 | |||
|
4812 | ||||
4688 | if self.__dataReady: |
|
4813 | if self.__dataReady: | |
4689 | dataOut.data_360 = data_360 # S |
|
4814 | dataOut.data_360_Power = data_360_Power # S | |
4690 | #print("DATA 360") |
|
4815 | dataOut.data_360_Velocity = data_360_Velocity | |
4691 | #print(dataOut.data_360) |
|
|||
4692 | #print("---------------------------------------------------------------------------------") |
|
|||
4693 | print("---------------------------DATAREADY---------------------------------------------") |
|
|||
4694 | #print("---------------------------------------------------------------------------------") |
|
|||
4695 | #print("data_360",dataOut.data_360.shape) |
|
|||
4696 | print(data_e) |
|
|||
4697 | #exit(1) |
|
|||
4698 | dataOut.data_azi = data_p |
|
4816 | dataOut.data_azi = data_p | |
4699 | dataOut.data_ele = data_e |
|
4817 | dataOut.data_ele = data_e | |
4700 | ###print("azi: ",dataOut.data_azi) |
|
|||
4701 | #print("ele: ",dataOut.data_ele) |
|
|||
4702 | #print("jroproc_parameters",data_p[0],data_p[-1])#,data_360.shape,avgdatatime) |
|
|||
4703 | dataOut.utctime = avgdatatime |
|
4818 | dataOut.utctime = avgdatatime | |
4704 |
|
||||
4705 |
|
||||
4706 |
|
||||
4707 | dataOut.flagNoData = False |
|
4819 | dataOut.flagNoData = False | |
|
4820 | ||||
4708 | return dataOut |
|
4821 | return dataOut |
General Comments 0
You need to be logged in to leave comments.
Login now