##// END OF EJS Templates
kwargs restantes. Templates y changelog actualizado
José Chávez -
r1080:af3edc5dd0e9
parent child
Show More

The requested changes are too big and content was truncated. Show full diff

@@ -1,88 +1,90
1 1 basic = '''from schainpy.controller import Project
2 2
3 3 desc = "{desc}"
4 4 project = Project()
5 5 project.setup(id='200', name="{name}", description=desc)
6 6
7 7 voltage_reader = project.addReadUnit(datatype='VoltageReader',
8 8 path="{path}",
9 9 startDate="{startDate}",
10 10 endDate="{endDate}",
11 11 startTime="{startHour}",
12 12 endTime="{endHour}",
13 13 online=0,
14 14 verbose=1,
15 15 walk=1,
16 16 )
17 17
18 18 voltage_proc = project.addProcUnit(datatype='VoltageProc', inputId=voltage_reader.getId())
19 19
20 20 profile = voltage_proc.addOperation(name='ProfileSelector', optype='other')
21 21 profile.addParameter(name='profileRangeList', value='120,183', format='intlist')
22 22
23 23 rti = voltage_proc.addOperation(name='RTIPlot', optype='other')
24 24 rti.addParameter(name='wintitle', value='Jicamarca Radio Observatory', format='str')
25 25 rti.addParameter(name='showprofile', value='0', format='int')
26 26 rti.addParameter(name='xmin', value='0', format='int')
27 27 rti.addParameter(name='xmax', value='24', format='int')
28 28 rti.addParameter(name='figpath', value="{figpath}", format='str')
29 29 rti.addParameter(name='wr_period', value='5', format='int')
30 30 rti.addParameter(name='exp_code', value='22', format='int')
31 31
32 32
33 33 controller.start()
34 34 '''
35 35
36 36 multiprocess = '''from schainpy.controller import Project, MPProject
37 37 from time import sleep
38 38 desc = "{desc}"
39 39
40 40 ####################
41 41 # PLOTTER RECEIVER #
42 42 ####################
43 43 plotter = Project()
44 44 plotter.setup(id='100', name='receiver', description=desc)
45 45
46 receiver_proc = plotter.addProcUnit(name='PlotterReceiver')
47 receiver_proc.addParameter(name='throttle', value=20, format='int')
46 receiver_plot = plotter.addProcUnit(name='PlotterReceiver')
47 receiver_plot.addParameter(name='throttle', value=20, format='int')
48 receiver_plot.addParameter(name='plottypes', value='rti', format='str')
48 49
49 rti = receiver_proc.addOperation(name='PlotRTIData', optype='other')
50 rti = receiver_plot.addOperation(name='PlotRTIData', optype='other')
50 51 rti.addParameter(name='zmin', value='-40.0', format='float')
51 52 rti.addParameter(name='zmax', value='100.0', format='float')
53 rti.addParameter(name='decimation', value='200', format='int')
52 54 rti.addParameter(name='xmin', value='0.0', format='int')
53 55 rti.addParameter(name='colormap', value='jet', format='str')
54 56
55 57 plotter.start()
56 58
57 59 sleep(2)
58 60
59 61 ################
60 62 # DATA EMITTER #
61 63 ################
62 64 project = Project()
63 65 project.setup(id='200', name="{name}", description=desc)
64 66
65 67 spectra_reader = project.addReadUnit(datatype='SpectraReader',
66 68 path="{path}",
67 69 startDate={startDate},
68 70 endDate={endDate},
69 71 startTime="{startHour}",
70 72 endTime="{endHour}",
71 73 online=0,
72 74 verbose=1,
73 75 walk=1,
74 76 )
75 77
76 78 spectra_proc = project.addProcUnit(datatype='Spectra', inputId=spectra_reader.getId())
77 79
78 80 parameters_proc = project.addProcUnit(datatype='ParametersProc', inputId=spectra_proc.getId())
79 81 moments = parameters_proc.addOperation(name='SpectralMoments', optype='other')
80 82
81 83 publish = parameters_proc.addOperation(name='PublishData', optype='other')
82 84 publish.addParameter(name='zeromq', value=1, format='int')
83 85 publish.addParameter(name='verbose', value=0, format='bool')
84 86
85 87 MPProject(project, 16)
86 88
87 89
88 90 '''
@@ -1,109 +1,109
1 1 ## CHANGELOG:
2 2
3 3 ### 2.3
4 * Added high order function `multiSchain` for multiprocessing scripts.
4 * Added high order function `MPProject` for multiprocessing scripts.
5 5 * Added two new Processing Units `PublishData` and `ReceiverData` for receiving and sending dataOut through multiple ways (tcp, ipc, inproc).
6 6 * Added a new graphics Processing Unit `PlotterReceiver`. It is decoupled from normal processing sequence with support for data generated by multiprocessing scripts.
7 7 * Added support for sending realtime graphic to web server.
8 * GUI command `schain` is now `schainGUI`.
8 * GUI command `schain` is now `schainGUI`.
9 9 * Added a CLI tool named `schain`.
10 10 * Scripts templates can be now generated with `schain generate`.
11 11 * Now it is possible to search Processing Units and Operations with `schain search [module]` to get the right name and its allowed parameters.
12 12 * `schain xml` to run xml scripts.
13 13 * Added suggestions when parameters are poorly written.
14 14 * `Controller.start()` now runs in a different process than the process calling it.
15 15 * Added `schainpy.utils.log` for log standarization.
16 16 * Running script on online mode no longer ignores date and hour. Issue #1109.
17 17 * Added support for receving voltage data directly from JARS (tcp, ipc).
18 18 * Updated README for MAC OS GUI installation.
19 19 * Setup now installs numpy.
20 20
21 21 ### 2.2.6
22 22 * Graphics generated by the GUI are now the same as generated by scripts. Issue #1074.
23 23 * Added support for C extensions.
24 24 * Function `hildebrand_sehkon` optimized with a C wrapper.
25 25 * Numpy version updated.
26 26 * Migration to GIT.
27 27
28 28 ### 2.2.5:
29 29 * splitProfiles and combineProfiles modules were added to VoltageProc and Signal Chain GUI.
30 30 * nProfiles of USRP data (hdf5) is the number of profiles thera are in one second.
31 31 * jroPlotter works directly with data objects instead of dictionaries
32 32 * script "schain" was added to Signal Chain installer
33 33
34 34 ### 2.2.4.1:
35 35 * jroIO_usrp.py is update to read Sandra's data
36 36 * decimation in Spectra and RTI plots is always enabled.
37 37 * time* window option added to GUI
38 38
39 39 ### 2.2.4:
40 40 * jroproc_spectra_lags.py added to schainpy
41 41 * Bug fixed in schainGUI: ProcUnit was created with the same id in some cases.
42 42 * Bug fixed in jroHeaderIO: Header size validation.
43 43
44 44 ### 2.2.3.1:
45 45 * Filtering block by time has been added.
46 46 * Bug fixed plotting RTI, CoherenceMap and others using xmin and xmax parameters. The first day worked
47 47 properly but the next days did not.
48 48
49 49 ### 2.2.3:
50 50 * Bug fixed in GUI: Error getting(reading) Code value
51 51 * Bug fixed in GUI: Flip option always needs channelList field
52 52 * Bug fixed in jrodata: when one branch modified a value in "dataOut" (example: dataOut.code) this value
53 53 was modified for every branch (because this was a reference). It was modified in data.copy()
54 54 * Bug fixed in jroproc_voltage.profileSelector(): rangeList replaces to profileRangeList.
55 55
56 56 ### 2.2.2:
57 57 * VoltageProc: ProfileSelector, Reshape, Decoder with nTxs!=1 and getblock=True was tested
58 58 * Rawdata and testRawdata.py added to Signal Chain project
59 59
60 60 ### 2.2.1:
61 61 * Bugs fixed in GUI
62 62 * Views were improved in GUI
63 63 * Support to MST* ISR experiments
64 64 * Bug fixed getting noise using hyldebrant. (minimum number of points > 20%)
65 65 * handleError added to jroplotter.py
66 66
67 67 ### 2.2.0:
68 68 * GUI: use of external plotter
69 69 * Compatible with matplotlib 1.5.0
70 70
71 71 ### 2.1.5:
72 72 * serializer module added to Signal Chain
73 73 * jroplotter.py added to Signal Chain
74 74
75 75 ### 2.1.4.2:
76 76 * A new Plotter Class was added
77 77 * Project.start() does not accept filename as a parameter anymore
78 78
79 79 ### 2.1.4.1:
80 80 * Send notifications when an error different to ValueError is detected
81 81
82 82 ### 2.1.4:
83 83 * Sending error notifications to signal chain administrator
84 84 * Login to email server added
85 85
86 86 ### 2.1.3.3:
87 87 * Colored Button Icons were added to GUI
88 88
89 89 ### 2.1.3.2:
90 90 * GUI: user interaction enhanced
91 91 * controller_api.py: Safe access to ControllerThead
92 92
93 93 ### 2.1.3.1:
94 94 * GUI: every icon were resized
95 95 * jroproc_voltage.py: Print a message when "Read from code" option is selected and the code is not defined inside data file
96 96
97 97 ### 2.1.3:
98 98 * jroplot_heispectra.py: SpectraHeisScope was not showing the right channels
99 99 * jroproc_voltage.py: Bug fixed selecting profiles (self.nProfiles took a wrong value),
100 100 Bug fixed selecting heights by block (selecting profiles instead heights)
101 101 * jroproc_voltage.py: New feature added: decoding data by block using FFT.
102 102 * jroIO_heispectra.py: Bug fixed in FitsReader. Using local Fits instance instead schainpy.mode.data.jrodata.Fits.
103 103 * jroIO_heispectra.py: Channel index list does not exist.
104 104
105 105 ### 2.1.2:
106 106 * jroutils_ftp.py: Bug fixed, Any error sending file stopped the Server Thread
107 107 Server thread opens and closes remote server each time file list is sent
108 108 * jroplot_spectra.py: Noise path was not being created when noise data is saved.
109 109 * jroIO_base.py: startTime can be greater than endTime. Example: SpreadF [18:00 * 07:00] No newline at end of file
@@ -1,819 +1,843
1 1
2 2 import os
3 3 import time
4 4 import glob
5 5 import datetime
6 6 from multiprocessing import Process
7 7
8 8 import zmq
9 9 import numpy
10 10 import matplotlib
11 11 import matplotlib.pyplot as plt
12 12 from mpl_toolkits.axes_grid1 import make_axes_locatable
13 13 from matplotlib.ticker import FuncFormatter, LinearLocator, MultipleLocator
14 14
15 15 from schainpy.model.proc.jroproc_base import Operation
16 16 from schainpy.utils import log
17 17
18 18 jet_values = matplotlib.pyplot.get_cmap("jet", 100)(numpy.arange(100))[10:90]
19 blu_values = matplotlib.pyplot.get_cmap("seismic_r", 20)(numpy.arange(20))[10:15]
20 ncmap = matplotlib.colors.LinearSegmentedColormap.from_list("jro", numpy.vstack((blu_values, jet_values)))
19 blu_values = matplotlib.pyplot.get_cmap(
20 "seismic_r", 20)(numpy.arange(20))[10:15]
21 ncmap = matplotlib.colors.LinearSegmentedColormap.from_list(
22 "jro", numpy.vstack((blu_values, jet_values)))
21 23 matplotlib.pyplot.register_cmap(cmap=ncmap)
22 24
23 func = lambda x, pos: '{}'.format(datetime.datetime.fromtimestamp(x).strftime('%H:%M'))
24 25
25 UT1970 = datetime.datetime(1970, 1, 1) - datetime.timedelta(seconds=time.timezone)
26 def func(x, pos): return '{}'.format(
27 datetime.datetime.fromtimestamp(x).strftime('%H:%M'))
28
29
30 UT1970 = datetime.datetime(1970, 1, 1) - \
31 datetime.timedelta(seconds=time.timezone)
26 32
27 33 CMAPS = [plt.get_cmap(s) for s in ('jro', 'jet', 'RdBu_r', 'seismic')]
28 34
35
29 36 class PlotData(Operation, Process):
30 37 '''
31 38 Base class for Schain plotting operations
32 39 '''
33 40
34 41 CODE = 'Figure'
35 42 colormap = 'jro'
36 43 bgcolor = 'white'
37 44 CONFLATE = False
38 45 __MAXNUMX = 80
39 46 __missing = 1E30
40 47
41 48 def __init__(self, **kwargs):
42 49
43 50 Operation.__init__(self, plot=True, **kwargs)
44 51 Process.__init__(self)
45 52 self.kwargs['code'] = self.CODE
46 53 self.mp = False
47 54 self.data = None
48 self.isConfig = False
55 self.isConfig = False
49 56 self.figures = []
50 57 self.axes = []
51 58 self.cb_axes = []
52 59 self.localtime = kwargs.pop('localtime', True)
53 60 self.show = kwargs.get('show', True)
54 61 self.save = kwargs.get('save', False)
55 62 self.colormap = kwargs.get('colormap', self.colormap)
56 63 self.colormap_coh = kwargs.get('colormap_coh', 'jet')
57 64 self.colormap_phase = kwargs.get('colormap_phase', 'RdBu_r')
58 65 self.colormaps = kwargs.get('colormaps', None)
59 66 self.bgcolor = kwargs.get('bgcolor', self.bgcolor)
60 67 self.showprofile = kwargs.get('showprofile', False)
61 68 self.title = kwargs.get('wintitle', self.CODE.upper())
62 69 self.cb_label = kwargs.get('cb_label', None)
63 70 self.cb_labels = kwargs.get('cb_labels', None)
64 71 self.xaxis = kwargs.get('xaxis', 'frequency')
65 72 self.zmin = kwargs.get('zmin', None)
66 73 self.zmax = kwargs.get('zmax', None)
67 74 self.zlimits = kwargs.get('zlimits', None)
68 self.xmin = kwargs.get('xmin', None)
75 self.xmin = kwargs.get('xmin', None)
69 76 self.xmax = kwargs.get('xmax', None)
70 77 self.xrange = kwargs.get('xrange', 24)
71 78 self.ymin = kwargs.get('ymin', None)
72 79 self.ymax = kwargs.get('ymax', None)
73 80 self.xlabel = kwargs.get('xlabel', None)
74 self.__MAXNUMY = kwargs.get('decimation', 100)
81 self.__MAXNUMY = kwargs.get('decimation', 100)
75 82 self.showSNR = kwargs.get('showSNR', False)
76 83 self.oneFigure = kwargs.get('oneFigure', True)
77 84 self.width = kwargs.get('width', None)
78 85 self.height = kwargs.get('height', None)
79 86 self.colorbar = kwargs.get('colorbar', True)
80 87 self.factors = kwargs.get('factors', [1, 1, 1, 1, 1, 1, 1, 1])
81 88 self.titles = ['' for __ in range(16)]
82 89
83 90 def __setup(self):
84 91 '''
85 92 Common setup for all figures, here figures and axes are created
86 93 '''
87 94
88 95 self.setup()
89 96
90 97 self.time_label = 'LT' if self.localtime else 'UTC'
91 98
92 99 if self.width is None:
93 100 self.width = 8
94 101
95 102 self.figures = []
96 103 self.axes = []
97 104 self.cb_axes = []
98 105 self.pf_axes = []
99 106 self.cmaps = []
100 107
101 size = '15%' if self.ncols==1 else '30%'
102 pad = '4%' if self.ncols==1 else '8%'
108 size = '15%' if self.ncols == 1 else '30%'
109 pad = '4%' if self.ncols == 1 else '8%'
103 110
104 111 if self.oneFigure:
105 112 if self.height is None:
106 self.height = 1.4*self.nrows + 1
113 self.height = 1.4 * self.nrows + 1
107 114 fig = plt.figure(figsize=(self.width, self.height),
108 115 edgecolor='k',
109 116 facecolor='w')
110 117 self.figures.append(fig)
111 for n in range(self.nplots):
112 ax = fig.add_subplot(self.nrows, self.ncols, n+1)
118 for n in range(self.nplots):
119 ax = fig.add_subplot(self.nrows, self.ncols, n + 1)
113 120 ax.tick_params(labelsize=8)
114 121 ax.firsttime = True
115 122 ax.index = 0
116 self.axes.append(ax)
123 self.axes.append(ax)
117 124 if self.showprofile:
118 125 cax = self.__add_axes(ax, size=size, pad=pad)
119 cax.tick_params(labelsize=8)
126 cax.tick_params(labelsize=8)
120 127 self.pf_axes.append(cax)
121 128 else:
122 129 if self.height is None:
123 130 self.height = 3
124 131 for n in range(self.nplots):
125 132 fig = plt.figure(figsize=(self.width, self.height),
126 edgecolor='k',
127 facecolor='w')
133 edgecolor='k',
134 facecolor='w')
128 135 ax = fig.add_subplot(1, 1, 1)
129 136 ax.tick_params(labelsize=8)
130 137 ax.firsttime = True
131 138 ax.index = 0
132 self.figures.append(fig)
139 self.figures.append(fig)
133 140 self.axes.append(ax)
134 141 if self.showprofile:
135 142 cax = self.__add_axes(ax, size=size, pad=pad)
136 cax.tick_params(labelsize=8)
143 cax.tick_params(labelsize=8)
137 144 self.pf_axes.append(cax)
138
145
139 146 for n in range(self.nrows):
140 147 if self.colormaps is not None:
141 cmap = plt.get_cmap(self.colormaps[n])
148 cmap = plt.get_cmap(self.colormaps[n])
142 149 else:
143 150 cmap = plt.get_cmap(self.colormap)
144 151 cmap.set_bad(self.bgcolor, 1.)
145 152 self.cmaps.append(cmap)
146 153
147 154 for fig in self.figures:
148 155 fig.canvas.mpl_connect('key_press_event', self.event_key_press)
149 156
150 157 def event_key_press(self, event):
151 158 '''
152 159 '''
153 160
154 161 for ax in self.axes:
155 162 if ax == event.inaxes:
156 163 if event.key == 'down':
157 164 ax.index += 1
158 165 elif event.key == 'up':
159 166 ax.index -= 1
160 167 if ax.index < 0:
161 ax.index = len(CMAPS) - 1
168 ax.index = len(CMAPS) - 1
162 169 elif ax.index == len(CMAPS):
163 170 ax.index = 0
164 171 cmap = CMAPS[ax.index]
165 172 ax.cbar.set_cmap(cmap)
166 173 ax.cbar.draw_all()
167 ax.plt.set_cmap(cmap)
174 ax.plt.set_cmap(cmap)
168 175 ax.cbar.patch.figure.canvas.draw()
169 176
170 177 def __add_axes(self, ax, size='30%', pad='8%'):
171 178 '''
172 179 Add new axes to the given figure
173 180 '''
174 181 divider = make_axes_locatable(ax)
175 182 nax = divider.new_horizontal(size=size, pad=pad)
176 ax.figure.add_axes(nax)
183 ax.figure.add_axes(nax)
177 184 return nax
178 185
179 186 self.setup()
180 187
181 188 def setup(self):
182 189 '''
183 190 This method should be implemented in the child class, the following
184 191 attributes should be set:
185
192
186 193 self.nrows: number of rows
187 194 self.ncols: number of cols
188 195 self.nplots: number of plots (channels or pairs)
189 196 self.ylabel: label for Y axes
190 197 self.titles: list of axes title
191 198
192 199 '''
193 200 raise(NotImplementedError, 'Implement this method in child class')
194 201
195 202 def fill_gaps(self, x_buffer, y_buffer, z_buffer):
196 203 '''
197 204 Create a masked array for missing data
198 205 '''
199 206 if x_buffer.shape[0] < 2:
200 207 return x_buffer, y_buffer, z_buffer
201 208
202 209 deltas = x_buffer[1:] - x_buffer[0:-1]
203 210 x_median = numpy.median(deltas)
204 211
205 index = numpy.where(deltas > 5*x_median)
212 index = numpy.where(deltas > 5 * x_median)
206 213
207 214 if len(index[0]) != 0:
208 215 z_buffer[::, index[0], ::] = self.__missing
209 216 z_buffer = numpy.ma.masked_inside(z_buffer,
210 0.99*self.__missing,
211 1.01*self.__missing)
217 0.99 * self.__missing,
218 1.01 * self.__missing)
212 219
213 220 return x_buffer, y_buffer, z_buffer
214 221
215 222 def decimate(self):
216 223
217 224 # dx = int(len(self.x)/self.__MAXNUMX) + 1
218 dy = int(len(self.y)/self.__MAXNUMY) + 1
225 dy = int(len(self.y) / self.__MAXNUMY) + 1
219 226
220 227 # x = self.x[::dx]
221 228 x = self.x
222 229 y = self.y[::dy]
223 230 z = self.z[::, ::, ::dy]
224
231
225 232 return x, y, z
226 233
227 234 def format(self):
228 235 '''
229 236 Set min and max values, labels, ticks and titles
230 237 '''
231 238
232 239 if self.xmin is None:
233 240 xmin = self.min_time
234 241 else:
235 242 if self.xaxis is 'time':
236 243 dt = datetime.datetime.fromtimestamp(self.min_time)
237 244 xmin = (datetime.datetime.combine(dt.date(),
238 datetime.time(int(self.xmin), 0, 0))-UT1970).total_seconds()
245 datetime.time(int(self.xmin), 0, 0)) - UT1970).total_seconds()
239 246 else:
240 247 xmin = self.xmin
241 248
242 249 if self.xmax is None:
243 xmax = xmin+self.xrange*60*60
250 xmax = xmin + self.xrange * 60 * 60
244 251 else:
245 252 if self.xaxis is 'time':
246 253 dt = datetime.datetime.fromtimestamp(self.min_time)
247 254 xmax = (datetime.datetime.combine(dt.date(),
248 datetime.time(int(self.xmax), 0, 0))-UT1970).total_seconds()
255 datetime.time(int(self.xmax), 0, 0)) - UT1970).total_seconds()
249 256 else:
250 257 xmax = self.xmax
251
258
252 259 ymin = self.ymin if self.ymin else numpy.nanmin(self.y)
253 260 ymax = self.ymax if self.ymax else numpy.nanmax(self.y)
254
255 ystep = 200 if ymax>= 800 else 100 if ymax>=400 else 50 if ymax>=200 else 20
256 261
257 for n, ax in enumerate(self.axes):
262 ystep = 200 if ymax >= 800 else 100 if ymax >= 400 else 50 if ymax >= 200 else 20
263
264 for n, ax in enumerate(self.axes):
258 265 if ax.firsttime:
259 266 ax.set_facecolor(self.bgcolor)
260 267 ax.yaxis.set_major_locator(MultipleLocator(ystep))
261 if self.xaxis is 'time':
268 if self.xaxis is 'time':
262 269 ax.xaxis.set_major_formatter(FuncFormatter(func))
263 ax.xaxis.set_major_locator(LinearLocator(9))
270 ax.xaxis.set_major_locator(LinearLocator(9))
264 271 if self.xlabel is not None:
265 272 ax.set_xlabel(self.xlabel)
266 ax.set_ylabel(self.ylabel)
273 ax.set_ylabel(self.ylabel)
267 274 ax.firsttime = False
268 275 if self.showprofile:
269 276 self.pf_axes[n].set_ylim(ymin, ymax)
270 self.pf_axes[n].set_xlim(self.zmin, self.zmax)
277 self.pf_axes[n].set_xlim(self.zmin, self.zmax)
271 278 self.pf_axes[n].set_xlabel('dB')
272 279 self.pf_axes[n].grid(b=True, axis='x')
273 [tick.set_visible(False) for tick in self.pf_axes[n].get_yticklabels()]
280 [tick.set_visible(False)
281 for tick in self.pf_axes[n].get_yticklabels()]
274 282 if self.colorbar:
275 283 ax.cbar = plt.colorbar(ax.plt, ax=ax, pad=0.02, aspect=10)
276 284 ax.cbar.ax.tick_params(labelsize=8)
277 285 if self.cb_label:
278 286 ax.cbar.set_label(self.cb_label, size=8)
279 287 elif self.cb_labels:
280 288 ax.cbar.set_label(self.cb_labels[n], size=8)
281
289
282 290 ax.set_title('{} - {} {}'.format(
283 self.titles[n],
284 datetime.datetime.fromtimestamp(self.max_time).strftime('%H:%M:%S'),
285 self.time_label),
291 self.titles[n],
292 datetime.datetime.fromtimestamp(
293 self.max_time).strftime('%H:%M:%S'),
294 self.time_label),
286 295 size=8)
287 296 ax.set_xlim(xmin, xmax)
288 297 ax.set_ylim(ymin, ymax)
289 298
290 299 def __plot(self):
291 300 '''
292 301 '''
293 302 log.success('Plotting', self.name)
294
303
295 304 self.plot()
296 305 self.format()
297
306
298 307 for n, fig in enumerate(self.figures):
299 308 if self.nrows == 0 or self.nplots == 0:
300 309 log.warning('No data', self.name)
301 310 continue
302 311 if self.show:
303 312 fig.show()
304
313
305 314 fig.tight_layout()
306 fig.canvas.manager.set_window_title('{} - {}'.format(self.title,
315 fig.canvas.manager.set_window_title('{} - {}'.format(self.title,
307 316 datetime.datetime.fromtimestamp(self.max_time).strftime('%Y/%m/%d')))
308 317 # fig.canvas.draw()
309
318
310 319 if self.save and self.data.ended:
311 320 channels = range(self.nrows)
312 321 if self.oneFigure:
313 322 label = ''
314 323 else:
315 324 label = '_{}'.format(channels[n])
316 325 figname = os.path.join(
317 326 self.save,
318 327 '{}{}_{}.png'.format(
319 328 self.CODE,
320 329 label,
321 datetime.datetime.fromtimestamp(self.saveTime).strftime('%y%m%d_%H%M%S')
330 datetime.datetime.fromtimestamp(
331 self.saveTime).strftime('%y%m%d_%H%M%S')
322 332 )
323 333 )
324 334 print 'Saving figure: {}'.format(figname)
325 335 fig.savefig(figname)
326 336
327 337 def plot(self):
328 338 '''
329 339 '''
330 340 raise(NotImplementedError, 'Implement this method in child class')
331 341
332 342 def run(self):
333 343
334 344 log.success('Starting', self.name)
335 345
336 346 context = zmq.Context()
337 347 receiver = context.socket(zmq.SUB)
338 348 receiver.setsockopt(zmq.SUBSCRIBE, '')
339 349 receiver.setsockopt(zmq.CONFLATE, self.CONFLATE)
340 350
341 351 if 'server' in self.kwargs['parent']:
342 receiver.connect('ipc:///tmp/{}.plots'.format(self.kwargs['parent']['server']))
352 receiver.connect(
353 'ipc:///tmp/{}.plots'.format(self.kwargs['parent']['server']))
343 354 else:
344 receiver.connect("ipc:///tmp/zmq.plots")
355 receiver.connect("ipc:///tmp/zmq.plots")
345 356
346 357 while True:
347 358 try:
348 359 self.data = receiver.recv_pyobj(flags=zmq.NOBLOCK)
349
360
350 361 if self.localtime:
351 362 self.times = self.data.times - time.timezone
352 363 else:
353 364 self.times = self.data.times
354
365
355 366 self.min_time = self.times[0]
356 367 self.max_time = self.times[-1]
357 368
358 369 if self.isConfig is False:
359 370 self.__setup()
360 371 self.isConfig = True
361
372
362 373 self.__plot()
363 374
364 375 except zmq.Again as e:
365 376 log.log('Waiting for data...')
366 377 if self.data:
367 378 plt.pause(self.data.throttle)
368 379 else:
369 380 time.sleep(2)
370 381
371 382 def close(self):
372 383 if self.data:
373 384 self.__plot()
374 385
386
375 387 class PlotSpectraData(PlotData):
376 388 '''
377 389 Plot for Spectra data
378 390 '''
379 391
380 392 CODE = 'spc'
381 colormap = 'jro'
393 colormap = 'jro'
382 394
383 395 def setup(self):
384 396 self.nplots = len(self.data.channels)
385 self.ncols = int(numpy.sqrt(self.nplots)+ 0.9)
386 self.nrows = int((1.0*self.nplots/self.ncols) + 0.9)
387 self.width = 3.4*self.ncols
388 self.height = 3*self.nrows
397 self.ncols = int(numpy.sqrt(self.nplots) + 0.9)
398 self.nrows = int((1.0 * self.nplots / self.ncols) + 0.9)
399 self.width = 3.4 * self.ncols
400 self.height = 3 * self.nrows
389 401 self.cb_label = 'dB'
390 if self.showprofile:
391 self.width += 0.8*self.ncols
402 if self.showprofile:
403 self.width += 0.8 * self.ncols
392 404
393 405 self.ylabel = 'Range [Km]'
394 406
395 407 def plot(self):
396 408 if self.xaxis == "frequency":
397 409 x = self.data.xrange[0]
398 410 self.xlabel = "Frequency (kHz)"
399 411 elif self.xaxis == "time":
400 412 x = self.data.xrange[1]
401 413 self.xlabel = "Time (ms)"
402 414 else:
403 415 x = self.data.xrange[2]
404 416 self.xlabel = "Velocity (m/s)"
405 417
406 418 if self.CODE == 'spc_mean':
407 419 x = self.data.xrange[2]
408 420 self.xlabel = "Velocity (m/s)"
409 421
410 422 self.titles = []
411 423
412 424 y = self.data.heights
413 425 self.y = y
414 426 z = self.data['spc']
415
427
416 428 for n, ax in enumerate(self.axes):
417 429 noise = self.data['noise'][n][-1]
418 430 if self.CODE == 'spc_mean':
419 431 mean = self.data['mean'][n][-1]
420 432 if ax.firsttime:
421 433 self.xmax = self.xmax if self.xmax else numpy.nanmax(x)
422 434 self.xmin = self.xmin if self.xmin else -self.xmax
423 435 self.zmin = self.zmin if self.zmin else numpy.nanmin(z)
424 436 self.zmax = self.zmax if self.zmax else numpy.nanmax(z)
425 437 ax.plt = ax.pcolormesh(x, y, z[n].T,
426 vmin=self.zmin,
427 vmax=self.zmax,
428 cmap=plt.get_cmap(self.colormap)
429 )
438 vmin=self.zmin,
439 vmax=self.zmax,
440 cmap=plt.get_cmap(self.colormap)
441 )
430 442
431 443 if self.showprofile:
432 ax.plt_profile= self.pf_axes[n].plot(self.data['rti'][n][-1], y)[0]
444 ax.plt_profile = self.pf_axes[n].plot(
445 self.data['rti'][n][-1], y)[0]
433 446 ax.plt_noise = self.pf_axes[n].plot(numpy.repeat(noise, len(y)), y,
434 color="k", linestyle="dashed", lw=1)[0]
447 color="k", linestyle="dashed", lw=1)[0]
435 448 if self.CODE == 'spc_mean':
436 449 ax.plt_mean = ax.plot(mean, y, color='k')[0]
437 450 else:
438 451 ax.plt.set_array(z[n].T.ravel())
439 452 if self.showprofile:
440 453 ax.plt_profile.set_data(self.data['rti'][n][-1], y)
441 454 ax.plt_noise.set_data(numpy.repeat(noise, len(y)), y)
442 455 if self.CODE == 'spc_mean':
443 456 ax.plt_mean.set_data(mean, y)
444 457
445 458 self.titles.append('CH {}: {:3.2f}dB'.format(n, noise))
446 459 self.saveTime = self.max_time
447 460
448 461
449 462 class PlotCrossSpectraData(PlotData):
450 463
451 464 CODE = 'cspc'
452 465 zmin_coh = None
453 466 zmax_coh = None
454 467 zmin_phase = None
455 zmax_phase = None
468 zmax_phase = None
456 469
457 470 def setup(self):
458 471
459 472 self.ncols = 4
460 473 self.nrows = len(self.data.pairs)
461 self.nplots = self.nrows*4
462 self.width = 3.4*self.ncols
463 self.height = 3*self.nrows
474 self.nplots = self.nrows * 4
475 self.width = 3.4 * self.ncols
476 self.height = 3 * self.nrows
464 477 self.ylabel = 'Range [Km]'
465 self.showprofile = False
478 self.showprofile = False
466 479
467 480 def plot(self):
468 481
469 482 if self.xaxis == "frequency":
470 483 x = self.data.xrange[0]
471 484 self.xlabel = "Frequency (kHz)"
472 485 elif self.xaxis == "time":
473 486 x = self.data.xrange[1]
474 487 self.xlabel = "Time (ms)"
475 488 else:
476 489 x = self.data.xrange[2]
477 490 self.xlabel = "Velocity (m/s)"
478 491
479 492 self.titles = []
480 493
481 494 y = self.data.heights
482 495 self.y = y
483 496 spc = self.data['spc']
484 497 cspc = self.data['cspc']
485 498
486 499 for n in range(self.nrows):
487 500 noise = self.data['noise'][n][-1]
488 501 pair = self.data.pairs[n]
489 ax = self.axes[4*n]
490 ax3 = self.axes[4*n+3]
502 ax = self.axes[4 * n]
503 ax3 = self.axes[4 * n + 3]
491 504 if ax.firsttime:
492 505 self.xmax = self.xmax if self.xmax else numpy.nanmax(x)
493 506 self.xmin = self.xmin if self.xmin else -self.xmax
494 507 self.zmin = self.zmin if self.zmin else numpy.nanmin(spc)
495 self.zmax = self.zmax if self.zmax else numpy.nanmax(spc)
508 self.zmax = self.zmax if self.zmax else numpy.nanmax(spc)
496 509 ax.plt = ax.pcolormesh(x, y, spc[pair[0]].T,
497 510 vmin=self.zmin,
498 511 vmax=self.zmax,
499 512 cmap=plt.get_cmap(self.colormap)
500 )
513 )
501 514 else:
502 515 ax.plt.set_array(spc[pair[0]].T.ravel())
503 516 self.titles.append('CH {}: {:3.2f}dB'.format(n, noise))
504 517
505 ax = self.axes[4*n+1]
506 if ax.firsttime:
518 ax = self.axes[4 * n + 1]
519 if ax.firsttime:
507 520 ax.plt = ax.pcolormesh(x, y, spc[pair[1]].T,
508 521 vmin=self.zmin,
509 522 vmax=self.zmax,
510 523 cmap=plt.get_cmap(self.colormap)
511 524 )
512 525 else:
513 526 ax.plt.set_array(spc[pair[1]].T.ravel())
514 527 self.titles.append('CH {}: {:3.2f}dB'.format(n, noise))
515 528
516 out = cspc[n]/numpy.sqrt(spc[pair[0]]*spc[pair[1]])
529 out = cspc[n] / numpy.sqrt(spc[pair[0]] * spc[pair[1]])
517 530 coh = numpy.abs(out)
518 phase = numpy.arctan2(out.imag, out.real)*180/numpy.pi
519
520 ax = self.axes[4*n+2]
521 if ax.firsttime:
531 phase = numpy.arctan2(out.imag, out.real) * 180 / numpy.pi
532
533 ax = self.axes[4 * n + 2]
534 if ax.firsttime:
522 535 ax.plt = ax.pcolormesh(x, y, coh.T,
523 536 vmin=0,
524 537 vmax=1,
525 538 cmap=plt.get_cmap(self.colormap_coh)
526 539 )
527 540 else:
528 541 ax.plt.set_array(coh.T.ravel())
529 self.titles.append('Coherence Ch{} * Ch{}'.format(pair[0], pair[1]))
542 self.titles.append(
543 'Coherence Ch{} * Ch{}'.format(pair[0], pair[1]))
530 544
531 ax = self.axes[4*n+3]
545 ax = self.axes[4 * n + 3]
532 546 if ax.firsttime:
533 547 ax.plt = ax.pcolormesh(x, y, phase.T,
534 548 vmin=-180,
535 549 vmax=180,
536 550 cmap=plt.get_cmap(self.colormap_phase)
537 551 )
538 552 else:
539 553 ax.plt.set_array(phase.T.ravel())
540 554 self.titles.append('Phase CH{} * CH{}'.format(pair[0], pair[1]))
541
555
542 556 self.saveTime = self.max_time
543 557
544 558
545 559 class PlotSpectraMeanData(PlotSpectraData):
546 560 '''
547 561 Plot for Spectra and Mean
548 562 '''
549 563 CODE = 'spc_mean'
550 564 colormap = 'jro'
551 565
552 566
553 567 class PlotRTIData(PlotData):
554 568 '''
555 569 Plot for RTI data
556 570 '''
557 571
558 572 CODE = 'rti'
559 573 colormap = 'jro'
560 574
561 575 def setup(self):
562 576 self.xaxis = 'time'
563 self.ncols = 1
577 self.ncols = 1
564 578 self.nrows = len(self.data.channels)
565 579 self.nplots = len(self.data.channels)
566 580 self.ylabel = 'Range [Km]'
567 581 self.cb_label = 'dB'
568 self.titles = ['{} Channel {}'.format(self.CODE.upper(), x) for x in range(self.nrows)]
582 self.titles = ['{} Channel {}'.format(
583 self.CODE.upper(), x) for x in range(self.nrows)]
569 584
570 585 def plot(self):
571 586 self.x = self.times
572 587 self.y = self.data.heights
573 588 self.z = self.data[self.CODE]
574 589 self.z = numpy.ma.masked_invalid(self.z)
575 590
576 591 for n, ax in enumerate(self.axes):
577 x, y, z = self.fill_gaps(*self.decimate())
592 x, y, z = self.fill_gaps(*self.decimate())
578 593 self.zmin = self.zmin if self.zmin else numpy.min(self.z)
579 594 self.zmax = self.zmax if self.zmax else numpy.max(self.z)
580 if ax.firsttime:
595 if ax.firsttime:
581 596 ax.plt = ax.pcolormesh(x, y, z[n].T,
582 vmin=self.zmin,
583 vmax=self.zmax,
584 cmap=plt.get_cmap(self.colormap)
585 )
597 vmin=self.zmin,
598 vmax=self.zmax,
599 cmap=plt.get_cmap(self.colormap)
600 )
586 601 if self.showprofile:
587 ax.plot_profile= self.pf_axes[n].plot(self.data['rti'][n][-1], self.y)[0]
602 ax.plot_profile = self.pf_axes[n].plot(
603 self.data['rti'][n][-1], self.y)[0]
588 604 ax.plot_noise = self.pf_axes[n].plot(numpy.repeat(self.data['noise'][n][-1], len(self.y)), self.y,
589 605 color="k", linestyle="dashed", lw=1)[0]
590 606 else:
591 607 ax.collections.remove(ax.collections[0])
592 608 ax.plt = ax.pcolormesh(x, y, z[n].T,
593 609 vmin=self.zmin,
594 610 vmax=self.zmax,
595 611 cmap=plt.get_cmap(self.colormap)
596 )
612 )
597 613 if self.showprofile:
598 614 ax.plot_profile.set_data(self.data['rti'][n][-1], self.y)
599 ax.plot_noise.set_data(numpy.repeat(self.data['noise'][n][-1], len(self.y)), self.y)
615 ax.plot_noise.set_data(numpy.repeat(
616 self.data['noise'][n][-1], len(self.y)), self.y)
600 617
601 self.saveTime = self.min_time
618 self.saveTime = self.min_time
602 619
603 620
604 621 class PlotCOHData(PlotRTIData):
605 622 '''
606 623 Plot for Coherence data
607 624 '''
608 625
609 626 CODE = 'coh'
610 627
611 628 def setup(self):
612 629 self.xaxis = 'time'
613 630 self.ncols = 1
614 631 self.nrows = len(self.data.pairs)
615 632 self.nplots = len(self.data.pairs)
616 self.ylabel = 'Range [Km]'
633 self.ylabel = 'Range [Km]'
617 634 if self.CODE == 'coh':
618 635 self.cb_label = ''
619 self.titles = ['Coherence Map Ch{} * Ch{}'.format(x[0], x[1]) for x in self.data.pairs]
636 self.titles = [
637 'Coherence Map Ch{} * Ch{}'.format(x[0], x[1]) for x in self.data.pairs]
620 638 else:
621 639 self.cb_label = 'Degrees'
622 self.titles = ['Phase Map Ch{} * Ch{}'.format(x[0], x[1]) for x in self.data.pairs]
640 self.titles = [
641 'Phase Map Ch{} * Ch{}'.format(x[0], x[1]) for x in self.data.pairs]
623 642
624 643
625 644 class PlotPHASEData(PlotCOHData):
626 645 '''
627 646 Plot for Phase map data
628 647 '''
629 648
630 649 CODE = 'phase'
631 650 colormap = 'seismic'
632 651
633 652
634 653 class PlotNoiseData(PlotData):
635 654 '''
636 655 Plot for noise
637 656 '''
638 657
639 658 CODE = 'noise'
640 659
641 660 def setup(self):
642 661 self.xaxis = 'time'
643 662 self.ncols = 1
644 663 self.nrows = 1
645 664 self.nplots = 1
646 665 self.ylabel = 'Intensity [dB]'
647 666 self.titles = ['Noise']
648 667 self.colorbar = False
649 668
650 669 def plot(self):
651 670
652 671 x = self.times
653 672 xmin = self.min_time
654 xmax = xmin+self.xrange*60*60
673 xmax = xmin + self.xrange * 60 * 60
655 674 Y = self.data[self.CODE]
656
675
657 676 if self.axes[0].firsttime:
658 677 for ch in self.data.channels:
659 678 y = Y[ch]
660 679 self.axes[0].plot(x, y, lw=1, label='Ch{}'.format(ch))
661 680 plt.legend()
662 681 else:
663 682 for ch in self.data.channels:
664 683 y = Y[ch]
665 684 self.axes[0].lines[ch].set_data(x, y)
666
685
667 686 self.ymin = numpy.nanmin(Y) - 5
668 687 self.ymax = numpy.nanmax(Y) + 5
669 688 self.saveTime = self.min_time
670 689
671 690
672 691 class PlotSNRData(PlotRTIData):
673 692 '''
674 693 Plot for SNR Data
675 694 '''
676 695
677 696 CODE = 'snr'
678 697 colormap = 'jet'
679 698
680 699
681 700 class PlotDOPData(PlotRTIData):
682 701 '''
683 702 Plot for DOPPLER Data
684 703 '''
685 704
686 705 CODE = 'dop'
687 706 colormap = 'jet'
688 707
689 708
690 709 class PlotSkyMapData(PlotData):
691 710 '''
692 711 Plot for meteors detection data
693 712 '''
694 713
695 714 CODE = 'met'
696 715
697 716 def setup(self):
698 717
699 718 self.ncols = 1
700 719 self.nrows = 1
701 720 self.width = 7.2
702 721 self.height = 7.2
703 722
704 723 self.xlabel = 'Zonal Zenith Angle (deg)'
705 724 self.ylabel = 'Meridional Zenith Angle (deg)'
706 725
707 726 if self.figure is None:
708 727 self.figure = plt.figure(figsize=(self.width, self.height),
709 728 edgecolor='k',
710 729 facecolor='w')
711 730 else:
712 731 self.figure.clf()
713 732
714 self.ax = plt.subplot2grid((self.nrows, self.ncols), (0, 0), 1, 1, polar=True)
733 self.ax = plt.subplot2grid(
734 (self.nrows, self.ncols), (0, 0), 1, 1, polar=True)
715 735 self.ax.firsttime = True
716 736
717
718 737 def plot(self):
719 738
720 arrayParameters = numpy.concatenate([self.data['param'][t] for t in self.times])
721 error = arrayParameters[:,-1]
739 arrayParameters = numpy.concatenate(
740 [self.data['param'][t] for t in self.times])
741 error = arrayParameters[:, -1]
722 742 indValid = numpy.where(error == 0)[0]
723 finalMeteor = arrayParameters[indValid,:]
724 finalAzimuth = finalMeteor[:,3]
725 finalZenith = finalMeteor[:,4]
743 finalMeteor = arrayParameters[indValid, :]
744 finalAzimuth = finalMeteor[:, 3]
745 finalZenith = finalMeteor[:, 4]
726 746
727 x = finalAzimuth*numpy.pi/180
747 x = finalAzimuth * numpy.pi / 180
728 748 y = finalZenith
729 749
730 750 if self.ax.firsttime:
731 751 self.ax.plot = self.ax.plot(x, y, 'bo', markersize=5)[0]
732 self.ax.set_ylim(0,90)
733 self.ax.set_yticks(numpy.arange(0,90,20))
752 self.ax.set_ylim(0, 90)
753 self.ax.set_yticks(numpy.arange(0, 90, 20))
734 754 self.ax.set_xlabel(self.xlabel)
735 755 self.ax.set_ylabel(self.ylabel)
736 756 self.ax.yaxis.labelpad = 40
737 757 self.ax.firsttime = False
738 758 else:
739 759 self.ax.plot.set_data(x, y)
740 760
741
742 dt1 = datetime.datetime.fromtimestamp(self.min_time).strftime('%y/%m/%d %H:%M:%S')
743 dt2 = datetime.datetime.fromtimestamp(self.max_time).strftime('%y/%m/%d %H:%M:%S')
761 dt1 = datetime.datetime.fromtimestamp(
762 self.min_time).strftime('%y/%m/%d %H:%M:%S')
763 dt2 = datetime.datetime.fromtimestamp(
764 self.max_time).strftime('%y/%m/%d %H:%M:%S')
744 765 title = 'Meteor Detection Sky Map\n %s - %s \n Number of events: %5.0f\n' % (dt1,
745 766 dt2,
746 767 len(x))
747 768 self.ax.set_title(title, size=8)
748 769
749 770 self.saveTime = self.max_time
750 771
772
751 773 class PlotParamData(PlotRTIData):
752 774 '''
753 775 Plot for data_param object
754 776 '''
755 777
756 778 CODE = 'param'
757 779 colormap = 'seismic'
758 780
759 781 def setup(self):
760 782 self.xaxis = 'time'
761 783 self.ncols = 1
762 784 self.nrows = self.data.shape(self.CODE)[0]
763 785 self.nplots = self.nrows
764 786 if self.showSNR:
765 787 self.nrows += 1
766 788 self.nplots += 1
767
789
768 790 self.ylabel = 'Height [Km]'
769 791 self.titles = self.data.parameters \
770 792 if self.data.parameters else ['Param {}'.format(x) for x in xrange(self.nrows)]
771 793 if self.showSNR:
772 794 self.titles.append('SNR')
773 795
774 796 def plot(self):
775 self.data.normalize_heights()
797 self.data.normalize_heights()
776 798 self.x = self.times
777 799 self.y = self.data.heights
778 if self.showSNR:
800 if self.showSNR:
779 801 self.z = numpy.concatenate(
780 802 (self.data[self.CODE], self.data['snr'])
781 803 )
782 804 else:
783 805 self.z = self.data[self.CODE]
784 806
785 807 self.z = numpy.ma.masked_invalid(self.z)
786 808
787 809 for n, ax in enumerate(self.axes):
788 810
789 811 x, y, z = self.fill_gaps(*self.decimate())
790 812
791 813 if ax.firsttime:
792 814 if self.zlimits is not None:
793 815 self.zmin, self.zmax = self.zlimits[n]
794 self.zmax = self.zmax if self.zmax is not None else numpy.nanmax(abs(self.z[:-1, :]))
816 self.zmax = self.zmax if self.zmax is not None else numpy.nanmax(
817 abs(self.z[:-1, :]))
795 818 self.zmin = self.zmin if self.zmin is not None else -self.zmax
796 ax.plt = ax.pcolormesh(x, y, z[n, :, :].T*self.factors[n],
819 ax.plt = ax.pcolormesh(x, y, z[n, :, :].T * self.factors[n],
797 820 vmin=self.zmin,
798 821 vmax=self.zmax,
799 822 cmap=self.cmaps[n]
800 )
823 )
801 824 else:
802 825 if self.zlimits is not None:
803 826 self.zmin, self.zmax = self.zlimits[n]
804 827 ax.collections.remove(ax.collections[0])
805 ax.plt = ax.pcolormesh(x, y, z[n, :, :].T*self.factors[n],
828 ax.plt = ax.pcolormesh(x, y, z[n, :, :].T * self.factors[n],
806 829 vmin=self.zmin,
807 830 vmax=self.zmax,
808 831 cmap=self.cmaps[n]
809 )
832 )
810 833
811 834 self.saveTime = self.min_time
812 835
836
813 837 class PlotOuputData(PlotParamData):
814 838 '''
815 839 Plot data_output object
816 840 '''
817 841
818 842 CODE = 'output'
819 843 colormap = 'seismic'
@@ -1,141 +1,143
1 1 '''
2 2 @author: Daniel Suarez
3 3 '''
4 4 import numpy
5 5 from jroproc_base import ProcessingUnit, Operation
6 6 from schainpy.model.data.jroamisr import AMISR
7 7
8 8 class AMISRProc(ProcessingUnit):
9 def __init__(self):
10 ProcessingUnit.__init__(self)
9 def __init__(self, **kwargs):
10 ProcessingUnit.__init__(self, **kwargs)
11 11 self.objectDict = {}
12 12 self.dataOut = AMISR()
13 13
14 14 def run(self):
15 15 if self.dataIn.type == 'AMISR':
16 16 self.dataOut.copy(self.dataIn)
17 17
18 18
19 19 class PrintInfo(Operation):
20 def __init__(self):
20 def __init__(self, **kwargs):
21 Operation.__init__(self, **kwargs)
21 22 self.__isPrinted = False
22 23
23 24 def run(self, dataOut):
24 25
25 26 if not self.__isPrinted:
26 27 print 'Number of Records by File: %d'%dataOut.nRecords
27 28 print 'Number of Pulses: %d'%dataOut.nProfiles
28 29 print 'Number of Pulses by Frame: %d'%dataOut.npulseByFrame
29 30 print 'Number of Samples by Pulse: %d'%len(dataOut.heightList)
30 31 print 'Ipp Seconds: %f'%dataOut.ippSeconds
31 32 print 'Number of Beams: %d'%dataOut.nBeams
32 33 print 'BeamCodes:'
33 34 beamStrList = ['Beam %d -> Code=%d, azimuth=%2.2f, zenith=%2.2f, gain=%2.2f'%(k,v[0],v[1],v[2],v[3]) for k,v in dataOut.beamCodeDict.items()]
34 35 for b in beamStrList:
35 36 print b
36 37 self.__isPrinted = True
37 38
38 39 return
39 40
40 41
41 42 class BeamSelector(Operation):
42 43 profileIndex = None
43 44 nProfiles = None
44 45
45 def __init__(self):
46
46 def __init__(self, **kwargs):
47 Operation.__init__(self, **kwargs)
47 48 self.profileIndex = 0
48 49 self.__isConfig = False
49 50
50 51 def incIndex(self):
51 52 self.profileIndex += 1
52 53
53 54 if self.profileIndex >= self.nProfiles:
54 55 self.profileIndex = 0
55 56
56 57 def isProfileInRange(self, minIndex, maxIndex):
57 58
58 59 if self.profileIndex < minIndex:
59 60 return False
60 61
61 62 if self.profileIndex > maxIndex:
62 63 return False
63 64
64 65 return True
65 66
66 67 def isProfileInList(self, profileList):
67 68
68 69 if self.profileIndex not in profileList:
69 70 return False
70 71
71 72 return True
72 73
73 74 def run(self, dataOut, beam=None):
74 75
75 76 dataOut.flagNoData = True
76 77
77 78 if not(self.__isConfig):
78 79
79 80 self.nProfiles = dataOut.nProfiles
80 81 self.profileIndex = dataOut.profileIndex
81 82 self.__isConfig = True
82 83
83 84 if beam != None:
84 85 if self.isProfileInList(dataOut.beamRangeDict[beam]):
85 86 beamInfo = dataOut.beamCodeDict[beam]
86 87 dataOut.azimuth = beamInfo[1]
87 88 dataOut.zenith = beamInfo[2]
88 89 dataOut.gain = beamInfo[3]
89 90 dataOut.flagNoData = False
90 91
91 92 self.incIndex()
92 93 return 1
93 94
94 95 else:
95 96 raise ValueError, "BeamSelector needs beam value"
96 97
97 98 return 0
98 99
99 100 class ProfileToChannels(Operation):
100 101
101 def __init__(self):
102 def __init__(self, **kwargs):
103 Operation.__init__(self, **kwargs)
102 104 self.__isConfig = False
103 105 self.__counter_chan = 0
104 106 self.buffer = None
105 107
106 108 def isProfileInList(self, profileList):
107 109
108 110 if self.profileIndex not in profileList:
109 111 return False
110 112
111 113 return True
112 114
113 115 def run(self, dataOut):
114 116
115 117 dataOut.flagNoData = True
116 118
117 119 if not(self.__isConfig):
118 120 nchannels = len(dataOut.beamRangeDict.keys())
119 121 nsamples = dataOut.nHeights
120 122 self.buffer = numpy.zeros((nchannels, nsamples), dtype = 'complex128')
121 123 dataOut.beam.codeList = [dataOut.beamCodeDict[x][0] for x in range(nchannels)]
122 124 dataOut.beam.azimuthList = [dataOut.beamCodeDict[x][1] for x in range(nchannels)]
123 125 dataOut.beam.zenithList = [dataOut.beamCodeDict[x][2] for x in range(nchannels)]
124 126 self.__isConfig = True
125 127
126 128 for i in range(self.buffer.shape[0]):
127 129 if dataOut.profileIndex in dataOut.beamRangeDict[i]:
128 130 self.buffer[i,:] = dataOut.data
129 131 break
130 132
131 133
132 134 self.__counter_chan += 1
133 135
134 136 if self.__counter_chan >= self.buffer.shape[0]:
135 137 self.__counter_chan = 0
136 138 dataOut.data = self.buffer.copy()
137 139 dataOut.channelList = range(self.buffer.shape[0])
138 140 self.__isConfig = False
139 141 dataOut.flagNoData = False
140 142 pass
141 143 No newline at end of file
1 NO CONTENT: modified file
The requested commit or file is too big and content was truncated. Show full diff
General Comments 0
You need to be logged in to leave comments. Login now