2 Created on Tue Feb 2 09:39:35 2016
9 bokeh serve --show bokeh_display.py
11 bokeh serve --port 8081 --host hippo6.obspm.fr:8081 bokeh_display.py
12 then, open a web browser and connect to http://hippo6.obspm.fr:8081/bokeh_display.py
23 from bokeh.plotting
import Figure, figure
24 from bokeh.models
import Range1d, ColumnDataSource, HoverTool
25 from bokeh.models.widgets
import Select, Slider, CheckboxButtonGroup, Panel, Tabs, Button, Dialog, Paragraph, RadioButtonGroup, TextInput
26 from bokeh.io
import curdoc
27 from bokeh.models.layouts
import HBox, VBox
28 from bokeh.models.widgets
import DataTable, DateFormatter, TableColumn
29 from bokeh.client
import push_session
31 import matplotlib.pyplot
as plt
32 import matplotlib
as mpl
33 from scipy.sparse
import csr_matrix
35 sys.path.insert(0, os.environ[
"SHESHA_ROOT"] +
"/test/gamora/")
48 files = glob.glob(
"/home/fferreira/public_html/roket_display*")
54 self.
datapath =
"/home/fferreira/Data/correlation/"
60 self.
f_list.append(f.split(
'/')[-1])
62 self.
f = h5py.File(self.
files[0], mode=
'r+')
65 self.
Btt = self.
f[
"Btt"][:]
67 self.
IF = csr_matrix((self.
f[
"IF.data"][:], self.
f[
"IF.indices"][:],
68 self.
f[
"IF.indptr"][:]))
71 self.
P = self.
f[
"P"][:]
74 self.
pup = np.zeros((self.
f[
"dm_dim"].value, self.
f[
"dm_dim"].value))
76 self.
niter = self.
f[
"noise"][:].shape[1]
84 "noise",
"aliasing",
"tomography",
"filtered modes",
"bandwidth",
88 self.
cov = self.
f[
"cov"][:]
89 self.
cor = self.
f[
"cor"][:]
96 self.
basis = [
"Actuators",
"Btt"]
97 self.
url =
"http://hippo6.obspm.fr/~fferreira/roket_display"
107 self.
dialog = Dialog(closable=
False, visible=
False, title=
"Dialog Box",
111 self.
comsTags = Paragraph(text=
"Commands type", height=25)
115 self.
DB_button = Button(label=
"Load DB", type=
"success")
122 self.
plusTag = Paragraph(text=
"Add :", height=25)
124 labels=self.
coms_list + [
"fitting",
"CORRECT"],
125 active=[0, 1, 2, 3, 4, 5, 6])
126 self.
moinsTag = Paragraph(text=
"Substract :", height=25)
137 self.
power = Slider(title=
"Abs(covmat)**X", start=0.1, end=1., step=0.1,
139 self.
cmin = Slider(title=
"vmin", start=1, end=10, step=1)
140 self.
cmax = Slider(title=
"vmax", start=1, end=10, step=1)
141 self.
rescale = Button(label=
"Rescale !", type=
"primary")
142 self.
draw = Button(label=
"Draw !", type=
"success")
143 self.
diag = Button(label=
"Plot diag !", type=
"primary")
144 self.
cut = Button(label=
"Cut !", type=
"primary")
145 self.
axiscut = Slider(title=
"X/Y cut", start=0, end=1, step=1)
146 self.
XY = RadioButtonGroup(labels=[
"X",
"Y"], active=0)
148 "Type",
"Noise",
"Truncature",
"Aliasing",
"FilteredModes",
"Bandwidth",
154 data=dict(Type=[], Noise=[], Truncature=[], Aliasing=[],
155 FilteredModes=[], Bandwidth=[], Tomography=[]))
157 data=dict(Type=[], Noise=[], Truncature=[], Aliasing=[],
158 FilteredModes=[], Bandwidth=[], Tomography=[]))
164 data=dict(image=[], x=[], y=[], dw=[], dh=[]))
166 data=dict(image=[], x=[], y=[], dw=[], dh=[]))
167 self.
xdr4 = Range1d(start=0, end=6)
168 self.
ydr4 = Range1d(start=0, end=6)
169 self.
pcov = figure(x_range=self.
xdr4, y_range=self.
ydr4, x_axis_location=
"above")
170 self.
pcov.image(
"image",
"x",
"y",
"dw",
"dh", palette=
"Spectral11",
172 self.
pcor = figure(x_range=self.
xdr4, y_range=self.
ydr4, x_axis_location=
"above")
173 self.
pcor.image(
"image",
"x",
"y",
"dw",
"dh", palette=
"Spectral11",
187 self.
independence = CheckboxButtonGroup(labels=[
"Independence"], active=[])
189 title=
"PSF display", value=
"COMPASS", options=[
190 "COMPASS",
"ROKET",
"Vii",
"Fitting",
"OTF Telescope",
"OTF res"
193 options=[
"Vii",
"ROKET"])
194 self.
gamora_tag = Paragraph(text=
"PSF reconstruction :", height=25)
197 active=[0, 1, 2, 3, 4, 5, 6])
201 "filtered modes":
"green",
202 "bandwidth":
"orange",
204 "tomography":
"purple",
205 "non linearity":
"cyan",
209 self.
source1 = ColumnDataSource(data=dict(x=[], y=[], color=[], typec=[]))
210 self.
source2 = ColumnDataSource(data=dict(x=[], y=[], color=[]))
211 self.
source3 = ColumnDataSource(data=dict(x=[], y=[], color=[]))
212 self.
sourcepsf = ColumnDataSource(data=dict(x=[], y=[], color=[]))
214 self.
hover = HoverTool(tooltips=[(
"x",
"@x"), (
"y",
"@y"), (
"type",
"@typec")])
215 self.
hoverlog = HoverTool(tooltips=[(
"x",
"@x"), (
"y",
"@y"), (
"type",
217 TOOLS =
"resize,save,pan,box_zoom,tap, box_select, wheel_zoom, lasso_select,reset"
219 self.
plog = Figure(plot_height=600, plot_width=800, y_range=[1e-6, 10],
220 y_axis_type=
"log", tools=[TOOLS, self.
hoverlog])
221 self.
psum = Figure(plot_height=600, plot_width=800)
223 self.
plog.line(legend=c, line_color=self.
colors[c])
225 self.
plog.multi_line(
"x",
"y", color=
"color", source=self.
source1)
226 self.
psum.line(legend=
"Image SR", line_color=
"red")
227 self.
psum.line(legend=
"Phase SR ", line_color=
"purple")
228 self.
psum.line(legend=
"Var(X+Y)", line_color=
"blue")
229 self.
psum.line(legend=
"Var(X)+var(Y)", line_color=
"green")
231 self.
psum.multi_line(
"x",
"y", color=
"color", source=self.
source3)
232 self.
psum.yaxis.axis_label =
"Strehl Ratio"
236 self.
p2 = figure(x_range=self.
xdr, y_range=self.
ydr, x_axis_location=
"above")
238 self.
p3 = Figure(plot_height=600, plot_width=800)
239 self.
p3.line(x=
"x", y=
"y", source=self.
source2)
241 self.
xdr2 = Range1d(start=0, end=self.
pup.shape[0])
242 self.
ydr2 = Range1d(start=self.
pup.shape[1], end=0)
244 x_axis_location=
"above")
245 self.
pmodes.image_url(url=[], x=0, y=0, w=self.
pup.shape[0], h=self.
pup.shape[1])
251 self.
ppsf = figure(x_range=self.
xdr3, y_range=self.
ydr3, x_axis_location=
"above")
254 self.
pcutpsf = Figure(plot_height=600, plot_width=800, y_range=[1e-9, 1],
256 self.
pcutpsf.line(legend=
"COMPASS", line_color=
"blue")
257 self.
pcutpsf.line(legend=
"PSF rec", line_color=
"red")
262 control.on_change(
'value', self.
update)
264 button.on_change(
'active', self.
update)
303 child=HBox(self.
inputs, VBox(self.
plog, self.
psum)), title=
"Breakdown")
308 HBox(self.cov_table, self.
pcov),
309 HBox(self.cor_table, self.
pcor))), title=
"Cov/cor")
319 self.
update(
None,
None,
None)
321 curdoc().add_root(self.
tabs)
322 curdoc().add_root(self.
dialog)
332 self.
dialog.visible =
False
333 self.
dialog.content =
"Loading database..."
334 self.
dialog.visible =
True
338 self.
Btt = self.
f[
"Btt"][:]
340 self.
IF = csr_matrix((self.
f[
"IF.data"][:], self.
f[
"IF.indices"][:],
341 self.
f[
"IF.indptr"][:]))
344 self.
P = self.
f[
"P"][:]
349 self.
pup = np.zeros((self.
f[
"dm_dim"].value, self.
f[
"dm_dim"].value))
351 self.
niter = self.
f[
"noise"][:].shape[1]
352 self.
nactus = self.
f[
"noise"][:].shape[0]
354 self.
cov = self.
f[
"cov"][:]
355 self.
cor = self.
f[
"cor"][:]
357 self.
psf_fitting = np.fft.fftshift(self.
f[
"psfortho"][:])
363 self.
plot_type = [
"Commands",
"Variance"]
367 self.
update(
None,
None,
None)
370 self.
dialog.visible =
False
374 self.
source1.data = dict(x=[], y=[], color=[], typec=[])
376 coms_active = self.
coms.active
385 for jj
in coms_active:
388 if (plot_val == b
"Commands"):
389 if (basis_val == b
"Actuators"):
390 yi.append(data[:, iteration].tolist())
391 self.
plog.xaxis.axis_label =
"Actuators"
392 elif (basis_val == b
"Btt"):
393 yi.append(np.dot(self.
P, data[:, iteration])[self.
swap].tolist())
394 self.
plog.xaxis.axis_label =
"Modes"
395 xi.append(list(range(len(data[:, iteration]))))
396 typec.append([j] * len(data[:, iteration]))
397 coloris.append(self.
colors[j])
398 self.
plog.yaxis.axis_label =
"Volts"
400 elif (plot_val == b
"Variance"):
401 if (basis_val == b
"Actuators"):
402 yi.append(np.var(data, axis=1).tolist())
403 self.
plog.xaxis.axis_label =
"Actuators"
404 elif (basis_val == b
"Btt"):
405 yi.append(np.var(np.dot(self.
P, data), axis=1)[self.
swap].tolist())
406 self.
plog.xaxis.axis_label =
"Modes"
407 xi.append(list(range(len(np.var(data, axis=1)))))
408 typec.append([j] * len(np.var(data, axis=1)))
409 coloris.append(self.
colors[j])
410 self.
plog.yaxis.axis_label =
"Variance"
412 self.
source1.data = dict(x=xi, y=yi, color=coloris, typec=typec)
414 print(
"Plots updated")
417 self.
dialog.visible =
False
420 err = self.
f[
"noise"][:] * 0.
421 covmodes = err.dot(err.T)
424 self.
dialog.content =
"Computing covariance matrix..."
425 self.
dialog.visible =
True
432 covmodes += data.dot(data.T) / err.shape[1]
436 if (psf_type == b
"Vii"):
437 self.
dialog.content =
"Reconstructing PSF with Vii (may take a while)..."
447 if (psf_type == b
"ROKET"):
448 self.
dialog.content =
"Reconstructing PSF from ROKET file (may take a while)..."
449 self.
dialog.visible =
True
450 self.
psf, self.
gamora = gamora.psf_rec_roket_file(
453 self.
dialog.content =
"PSF reconstruction is available with Vii or ROKET methods only"
454 self.
dialog.visible =
True
460 list(range(self.
psf.shape[0]))
463 self.
psf[self.
psf.shape[0] / 2, :]
464 ], color=[
"blue",
"red"])
465 self.
dialog.visible =
False
468 self.
dialog.visible =
False
469 self.
dialog.content =
"Updating PSF display..."
470 self.
dialog.visible =
True
473 if (psf_type == b
"COMPASS"):
475 if (psf_type == b
"Vii" or psf_type == b
"ROKET"):
476 image = np.log10(self.
psf)
477 if (psf_type == b
"Fitting"):
479 if (psf_type == b
"OTF Telescope"):
480 image = np.fft.fftshift(self.
otftel)
481 if (psf_type == b
"OTF res"):
482 image = np.fft.fftshift(self.
otf2)
484 if (image
is not None):
488 time = str(datetime.datetime.now().strftime(
'%Y-%m-%d_%H_%M_%f'))
489 self.
old =
"/home/fferreira/public_html/roket_display" + time +
".png"
490 mpl.image.imsave(self.
old, image)
492 url=dict(value=self.
url + time +
".png"), x=0, y=0, w=image.shape[0],
495 self.
dialog.visible =
False
498 self.
dialog.visible =
False
499 vmin = self.
cmin.value
500 vmax = self.
cmax.value
501 self.
dialog.content =
"Updating matrix..."
502 self.
dialog.visible =
True
505 time = str(datetime.datetime.now().strftime(
'%Y-%m-%d_%H_%M_%f'))
506 self.
old =
"/home/fferreira/public_html/roket_display" + time +
".png"
507 mpl.image.imsave(self.
old, self.
covmat, vmin=vmin, vmax=vmax)
509 url=dict(value=self.
url + time +
".png"), x=0, y=0,
511 self.
dialog.visible =
False
514 x = np.arange(self.
covmat.shape[0])
516 self.
source2.data = dict(x=x, y=y)
519 XorY = self.
XY.labels[self.
XY.active]
525 x = np.arange(data.size)
526 self.
source2.data = dict(x=x, y=data)
529 self.
dialog.visible =
False
536 powa = self.
power.value
537 self.
dialog.content =
"Computing and loading matrix..."
538 self.
dialog.visible =
True
540 A_cov = self.
f[A_val][:]
541 B_cov = self.
f[B_val][:]
542 A_cov -= np.tile(np.mean(A_cov, axis=1), (A_cov.shape[1], 1)).T
543 B_cov -= np.tile(np.mean(B_cov, axis=1), (B_cov.shape[1], 1)).T
544 if (basis == b
"Btt"):
545 A_cov = np.dot(self.
P, A_cov)
546 B_cov = np.dot(self.
P, B_cov)
548 self.
covmat = (np.dot(A_cov, B_cov.T) / B_cov.shape[1])
549 print(
"dot product ok")
552 print(
"scale adjusted")
556 self.
cmin.step = (self.
cmin.end - self.
cmin.start) / 100.
562 time = str(datetime.datetime.now().strftime(
'%Y-%m-%d_%H_%M_%f'))
563 self.
old =
"/home/fferreira/public_html/roket_display" + time +
".png"
566 url=dict(value=self.
url + time +
".png"), x=0, y=0,
571 print(
"Matrix updated2")
572 self.
dialog.visible =
False
575 self.
dialog.visible =
False
583 self.
dialog.content =
"Loading..."
584 self.
dialog.visible =
True
586 if (basis == b
"Actuators"):
587 pup = self.
pup.flatten()
589 self.
pup = pup.reshape(self.
pup.shape)
590 elif (basis == b
"Btt"):
591 pup = self.
pup.flatten()
593 self.
pup = pup.reshape(self.
pup.shape)
594 time = str(datetime.datetime.now().strftime(
'%Y-%m-%d_%H_%M_%f'))
595 self.
old =
"/home/fferreira/public_html/roket_display" + time +
".png"
596 mpl.image.imsave(self.
old, self.
pup)
598 url=dict(value=self.
url + time +
".png"), x=0, y=0, w=self.
pup.shape[0],
603 print(
"Mode updated")
604 self.
dialog.visible =
False
620 self.
dialog.visible =
False
621 self.
dialog.content =
"Computing..."
622 self.
dialog.visible =
True
630 if (plot_val == b
"Commands"):
631 data = np.zeros(self.
nactus)
632 x = list(range(self.
nactus))
633 elif (plot_val == b
"Variance"):
635 data2 = np.zeros(self.
nmodes)
636 x = list(range(self.
nmodes))
645 if (plot_val == b
"Commands"):
646 data += np.dot(self.
P,
648 elif (plot_val == b
"Variance"):
649 data += np.dot(self.
P, self.
f[self.
coms_list[i]][:])
651 np.dot(self.
P, self.
f[self.
coms_list[i]][:]), axis=1)
654 self.
f.attrs[
"wfs.ypos"][0] / self.
f.attrs[
"wfs.xpos"][0])
655 theta -= (self.
f.attrs[
"winddir"][0] * np.pi / 180.)
656 r0 = self.
f.attrs[
"r0"] * (self.
f.attrs[
"target.Lambda"][0] /
657 self.
f.attrs[
"wfs.Lambda"][0])**(6. / 5.)
658 RASC = 180 / np.pi * 3600.
662 dt = self.
f.attrs[
"ittime"]
663 g = self.
f.attrs[
"gain"][0]
664 for k
in range(self.
f.attrs[
"nscreens"]):
665 H = self.
f.attrs[
"atm.alt"][k]
666 v = self.
f.attrs[
"windspeed"][k]
667 frac = self.
f.attrs[
"frac"][k]
668 htheta = np.sqrt(self.
f.attrs[
"wfs.xpos"][0]**2 +
669 self.
f.attrs[
"wfs.ypos"][0]**2) / RASC * H
670 Dtomo += 6.88 * (htheta / r0)**(5. / 3.)
671 Dbp += 6.88 * (v * dt / g / r0)**(5. / 3.)
672 rho = np.sqrt(htheta**2 + (v * dt / g)**2 -
673 2 * htheta * v * dt / g * np.cos(np.pi - theta))
674 Dcov += 6.88 * (rho / r0)**(5. / 3.)
675 covar = (Dbp + Dtomo - Dcov) * 0.5 * frac
683 if (plot_val == b
"Commands"):
684 data -= np.dot(self.
P, self.
f[self.
coms_list[i]][:][:, iteration])
685 elif (plot_val == b
"Variance"):
686 data -= np.dot(self.
P, self.
f[self.
coms_list[i]][:])
687 data2 -= np.var(np.dot(self.
P, self.
f[self.
coms_list[i]][:]), axis=1)
693 if (plot_val == b
"Variance"):
694 data = np.var(data, axis=1)
695 data = np.cumsum(data[self.
swap])
701 data2 = np.cumsum(data2[self.
swap])
702 data2 = np.exp(-data2 * (2 * np.pi / self.
Lambda_tar)**2)
703 print(
"data2 : ", data2)
704 data = np.exp(-data * (2 * np.pi / self.
Lambda_tar)**2)
705 if (fitp
and list(self.
f.keys()).count(
"fitting")):
706 data *= np.exp(-self.
f[
"fitting"].value)
707 data2 *= np.exp(-self.
f[
"fitting"].value)
708 print(
"data2 : ", data2)
709 if (fitm
and list(self.
f.keys()).count(
"fitting")):
710 data /= np.exp(-self.
f[
"fitting"].value)
711 data2 /= np.exp(-self.
f[
"fitting"].value)
712 if (list(self.
f.keys()).count(
"SR2")):
716 np.ones(len(x)) * self.
f[
"SR"].value,
717 np.ones(len(x)) * self.
f[
"SR2"].value, data2
718 ], color=[
"blue",
"red",
"purple",
"green"])
720 if (list(self.
f.keys()).count(
"SR")):
724 np.ones(len(x)) * self.
f[
"SR"].value, data2],
725 color=[
"blue",
"red",
"green"])
727 self.
source3.data = dict(x=x, y=data)
729 self.
dialog.visible =
False
732 cov = np.zeros((6, 6))
734 "0": self.
f[
"noise"][:],
735 "1": self.
f[
"non linearity"][:],
736 "2": self.
f[
"aliasing"][:],
737 "3": self.
f[
"filtered modes"][:],
738 "4": self.
f[
"bandwidth"][:],
739 "5": self.
f[
"tomography"][:]
741 for i
in range(cov.shape[0]):
742 for j
in range(cov.shape[1]):
744 tmpi = self.
P.dot(bufdict[str(i)])
745 tmpj = self.
P.dot(bufdict[str(j)])
747 np.mean(tmpi * tmpj, axis=1) -
748 np.mean(tmpi, axis=1) * np.mean(tmpj, axis=1))
750 cov[i, j] = cov[j, i]
752 s = np.reshape(np.diag(cov), (cov.shape[0], 1))
754 cor = cov / np.sqrt(sst)
760 tmp = [TableColumn(field=
"Type", title=
"Covariance")]
762 tmp.append(TableColumn(field=item, title=item))
765 cov_table = DataTable(source=self.
table_cov_source, columns=columns, width=1200,
767 tmp[0] = TableColumn(field=
"Type", title=
"Correlation")
768 cor_table = DataTable(source=self.
table_cor_source, columns=columns, width=1200,
772 TableColumn(field=
"Parameter", title=
"Parameter"),
773 TableColumn(field=
"Value", title=
"Value")
778 return cov_table, cor_table, param_table
783 Truncature=self.
cov[:, 1], Aliasing=self.
cov[:, 2],
784 FilteredModes=self.
cov[:, 3], Bandwidth=self.
cov[:, 4],
785 Tomography=self.
cov[:, 5])
788 Truncature=self.
cor[:, 1], Aliasing=self.
cor[:, 2],
789 FilteredModes=self.
cor[:, 3], Bandwidth=self.
cor[:, 4],
790 Tomography=self.
cor[:, 5])
791 params = list(self.
f.attrs.keys())
795 values.append(self.
f.attrs[k])
798 self.
pcov_source.data = dict(image=[self.
cov], x=[0], y=[0], dw=[6], dh=[6],
799 palette=
"Spectral11")
800 self.
pcor_source.data = dict(image=[self.
cor], x=[0], y=[0], dw=[6], dh=[6],
801 palette=
"Spectral11")
803 files = glob.glob(
"/home/fferreira/public_html/roket_display*")