2 Created on Wed Oct 5 14:28:23 2016
10 from bokeh.plotting
import Figure, figure
11 from bokeh.models
import Range1d, ColumnDataSource, HoverTool
12 from bokeh.models.widgets
import Select, Slider, CheckboxButtonGroup, Panel, Tabs, Button, Dialog, Paragraph, RadioButtonGroup, TextInput
13 from bokeh.io
import curdoc
14 from bokeh.models.layouts
import HBox, VBox
15 from bokeh.models.widgets
import DataTable, DateFormatter, TableColumn
16 from bokeh.client
import push_session
18 import matplotlib.pyplot
as plt
19 from scipy.special
import jv
25 (5. / 3.)) * (1.1183343328701949 -
Ij0t83(r * (np.pi / x0), tabx, taby)) * (
26 2 * (2 * np.pi)**(8 / 3.) * 0.0228956)
35 if (x < np.exp(-3.0)):
36 return 0.75 * x**(1. / 3) * (1 - x**2 / 112.)
38 return np.interp(x, tabx, taby)
51 t = np.linspace(-4, 10, n)
52 dt = (t[-1] - t[0]) / (n - 1)
54 A = 0.75 * smallx**(1. / 3) * (1 - smallx**2 / 112.)
57 Y = (np.exp(2 * t) + (1. / L0)**2)**(-8. / 6.) *
unMoinsJ0(X) * np.exp(t)
58 Y[1:] = np.cumsum(Y[:-1] + np.diff(Y) / 2.)
66 k2 = 1.00563491799858928388289314170833
67 k3 = 1.25331413731550012081
68 a1 = 0.22222222222222222222
69 a2 = -0.08641975308641974829
70 a3 = 0.08001828989483310284
73 res = k2 - k3 * np.exp(-x) * x**(1. / 3.) * (1.0 + x_1 * (a1 + x_1 *
85 0, 12.067619015983075, 5.17183672113560444, 0.795667187867016068,
86 0.0628158306210802181, 0.00301515986981185091, 9.72632216068338833e-05,
87 2.25320204494595251e-06, 3.93000356676612095e-08, 5.34694362825451923e-10,
88 5.83302941264329804e-12
92 -3.74878707653729304, -2.04479295083852408, -0.360845814853857083,
93 -0.0313778969438136685, -0.001622994669507603, -5.56455315259749673e-05,
94 -1.35720808599938951e-06, -2.47515152461894642e-08, -3.50257291219662472e-10,
95 -3.95770950530691961e-12, -3.65327031259100284e-14
105 for n
in np.arange(10) + 1:
107 s += (Gma[n] * x2a + Ga[n]) * x2n
115 k1 = 0.1716613621245709486
116 dprf0 = (2 * np.pi / L0) * r
117 if (dprf0 > 4.71239):
122 res *= k1 * L0**(5. / 3.)
127 def variance(f, contributors, method="Default"):
128 """ Return the error variance of specified contributors
130 f : (h5py.File) : roket hdf5 file opened with h5py
131 contributors : (list of string) : list of the contributors
132 method : (optional, default="Default") : if "Independence", the
133 function returns ths sum of the contributors variances.
134 If "Default", it returns the variance of the contributors sum
138 swap = np.arange(nmodes) - 2
139 swap[0:2] = [nmodes - 2, nmodes - 1]
140 if (method == b
"Default"):
141 err = f[contributors[0]][:] * 0.
142 for c
in contributors:
144 return np.var(P.dot(err), axis=1)[swap], np.var(
145 P.dot(f[
"tomography"][:]),
146 axis=1)[swap], np.var(P.dot(f[
"bandwidth"][:]), axis=1)[swap]
148 elif (method == b
"Independence"):
151 for c
in contributors:
152 v += np.var(P.dot(f[c][:]), axis=1)
156 raise TypeError(
"Wrong method input")
160 """ Return the variance computed from the sum of contributors of roket
161 files fs, ponderated by frac
163 fs : (list) : list of hdf5 files opened with h5py
164 frac_per_layer : (dict) : frac for each layer
165 contributors : (list of string) : list of the contributors
167 v : (np.array(dim=1)) : variance vector
172 swap = np.arange(nmodes) - 2
173 swap[0:2] = [nmodes - 2, nmodes - 1]
174 err = f[contributors[0]][:] * 0.
176 frac = frac_per_layer[f.attrs[
"atm.alt"][0]]
177 for c
in contributors:
178 err += np.sqrt(frac) * f[c][:]
180 return np.var(P.dot(err), axis=1)[swap]
184 """ Returns the cumulative Strehl ratio over the modes from the variance
187 v : (np.array(dim=1)) : variance vector
189 s : (np.array(dim=1)) : cumulative SR
192 s = np.exp(-s * (2 * np.pi / Lambda_tar)**2)
198 speed = speed_select.value
199 direction = dir_select.value
200 g = gain_select.value
201 xname = xaxis_select.value
202 yname = yaxis_select.value
207 ind = np.ones(ydata.shape[0])
208 if (direction !=
"All"):
209 ind *= (xmap[
"Winddir"] == float(direction))
211 ind *= (xmap[
"Windspeed"] == float(speed))
213 ind *= (xmap[
"Gain"] == float(g))
216 if (yname == b
"Var(t)"):
217 Hthetak = Htheta / xmap[
"Gain"]
218 y_model = np.ones(ind[0].shape[0])
220 for k
in range(ind[0].shape[0]):
221 y_model[k] =
dphi_lowpass(Htheta, 0.2, L0, tabx, taby) * (1 / r0)**(
223 if (yname == b
"Var(bp)"):
224 vdt = xmap[
"Windspeed"] * dt / xmap[
"Gain"]
225 y_model = np.zeros(vdt[ind].shape[0])
226 for k
in range(vdt[ind].shape[0]):
228 taby) * (1. / r0)**(5. / 3.) * 0.5
229 if (yname == b
"Covar"):
230 vdt = xmap[
"Windspeed"] * dt / xmap[
"Gain"]
231 Hthetak = Htheta / xmap[
"Gain"]
232 gamma = np.arctan2(ypos, xpos) - xmap[
"Winddir"] * np.pi / 180.
233 rho = np.sqrt(Htheta**2 + (vdt)**2 - 2 * Htheta * vdt * np.cos(gamma))
234 Drho = np.zeros(rho[ind].shape[0])
236 for k
in range(rho[ind].shape[0]):
238 taby) * (1 / r0)**(5. / 3.)
240 for k
in range(Dt.shape[0]):
241 Dt[k] =
dphi_lowpass(Htheta, 0.2, L0, tabx, taby) * (1 / r0)**(
244 Dbp = np.zeros(vdt[ind].shape[0])
245 for k
in range(vdt[ind].shape[0]):
246 Dbp[k] =
dphi_lowpass(vdt[ind][k], 0.2, L0, tabx, taby) * (1 / r0)**(5. / 3.)
248 y_model = 0.5 * (Dt + Dbp - Drho)
250 source.data = dict(x=x[ind], y=ydata[ind], speed=xmap[
"Windspeed"][ind],
251 theta=xmap[
"Winddir"][ind], gain=xmap[
"Gain"][ind])
252 source_model.data = dict(x=x[ind], y=y_model, speed=xmap[
"Windspeed"][ind],
253 theta=xmap[
"Winddir"][ind], gain=xmap[
"Gain"][ind])
256 datapath =
"/home/fferreira/Data/correlation/"
257 filenames = glob.glob(datapath +
"roket_8m_1layer_dir*_cpu.h5")
261 ff = h5py.File(f, mode=
'r')
265 nmodes = (files[0])[
"P"][:].shape[0]
266 xpos = files[0].attrs[
"wfs.xpos"][0]
267 ypos = files[0].attrs[
"wfs.ypos"][0]
268 contributors = [
"tomography",
"bandwidth"]
269 Lambda_tar = files[0].attrs[
"target.Lambda"][0]
270 Lambda_wfs = files[0].attrs[
"wfs.Lambda"][0]
271 L0 = files[0].attrs[
"L0"][0]
272 dt = files[0].attrs[
"ittime"]
273 H = files[0].attrs[
"atm.alt"][0]
274 RASC = 180 / np.pi * 3600.
275 Htheta = np.linalg.norm(
278 r0 = files[0].attrs[
"r0"] * (Lambda_tar / Lambda_wfs)**(6. / 5.)
280 data = np.zeros((nmodes, 4, nfiles))
281 theta = np.zeros(nfiles)
282 speeds = np.zeros(nfiles)
283 gain = np.zeros(nfiles)
293 data[:, 0, ind], data[:, 1, ind], data[:, 2, ind] =
variance(f, contributors)
294 data[:, 3, ind] =
variance(f, contributors, method=
"Independence")
295 theta[ind] = f.attrs[
"winddir"][0]
296 speeds[ind] = f.attrs[
"windspeed"][0]
297 gain[ind] = float(
'%.1f' % f.attrs[
"gain"][0])
299 data = data * ((2 * np.pi / Lambda_tar)**2)
300 covar = (data[:, 0, :] - data[:, 3, :]) / 2.
302 xaxis_select = Select(title=
"X-axis", value=
"Windspeed",
303 options=[
"Windspeed",
"Winddir",
"Gain"])
304 yaxis_select = Select(
305 title=
"Y-axis", value=
"Covar",
306 options=[
"Covar",
"Var(t+bp)",
"Var(t)",
"Var(bp)",
"Var(t)+Var(bp)"])
308 speed_select = Select(title=
"Windspeeds", value=
"All",
309 options=[
"All"] + [str(s)
for s
in np.unique(speeds)])
310 dir_select = Select(title=
"Winddirs", value=
"All",
311 options=[
"All"] + [str(s)
for s
in np.unique(theta)])
312 gain_select = Select(title=
"Gain", value=
"All",
313 options=[
"All"] + [str(s)[:3]
for s
in np.unique(gain)])
314 source = ColumnDataSource(data=dict(x=[], y=[], speed=[], theta=[], gain=[]))
315 source_model = ColumnDataSource(data=dict(x=[], y=[], speed=[], theta=[], gain=[]))
316 hover = HoverTool(tooltips=[(
"Speed",
"@speed"), (
"Winddir",
"@theta"), (
"Gain",
318 TOOLS =
"resize,save,pan,box_zoom,tap, box_select, wheel_zoom, lasso_select,reset"
320 p = figure(plot_height=600, plot_width=700, title=
"", tools=[hover, TOOLS])
321 p.circle(x=
"x", y=
"y", source=source, size=7, color=
"blue")
322 p.circle(x=
"x", y=
"y", source=source_model, size=7, color=
"red")
324 xmap = {
"Windspeed": speeds,
"Winddir": theta,
"Gain": gain}
326 "Covar": np.sum(covar, axis=0),
327 "Var(t+bp)": np.sum(data[:, 0, :], axis=0),
328 "Var(t)": np.sum(data[:, 1, :], axis=0),
329 "Var(bp)": np.sum(data[:, 2, :], axis=0),
330 "Var(t)+Var(bp)": np.sum(data[:, 3, :], axis=0)
333 buttons = [xaxis_select, speed_select, dir_select, yaxis_select, gain_select]
335 b.on_change(
'value', update)
340 HBox(VBox(xaxis_select, yaxis_select, speed_select, dir_select, gain_select), p))