Commit e6665fe3 authored by Nick Sauerwein's avatar Nick Sauerwein
Browse files

plotting server polished

parent 26c53b33
This source diff could not be displayed because it is too large. You can view the blob instead.
......@@ -126,7 +126,7 @@ class FocusCamera:
assert('camera not found')
cam.properties['GevSCPSPacketSize']=8000
#cam.properties['GevSCPSPacketSize']=9015
cam.properties['TriggerMode']='Off'
cam.properties['PixelFormat'] = 'Mono12'
cam.properties['AcquisitionFrameRateEnable']=False
......
......@@ -27,10 +27,10 @@ import Devices.InterferometerTools.routines as r
config file:
xmax: maximal x in mm
xmin: minimal x in mm
ymax: maximal y in mm
ymin: minimal y in mm
zmax: maximal z in mm
zmin: minimal z in mm
ExposureTimeAbs: exposure time in us
TriggerMode: On/Off
TriggerMode: On/Off
measurement file:
time: time (datetime object)
......@@ -53,20 +53,24 @@ class Interferometer:
print ('done')
self.set_config(config)
self.plot_server_im = None
self.plot_server_ph = None
def set_config(self,config):
self.cam.properties['ExposureTimeAbs']=config['ExposureTimeAbs']
self.cam.properties['TriggerMode']=config['TriggerMode']
self.xmin, self.xmax, self.ymin, self.ymax = (config['xmin'], config['xmax'],
config['ymin'], config['ymax'])
self.xmin, self.xmax, self.zmin, self.zmax = (config['xmin'], config['xmax'],
config['zmin'], config['zmax'])
self.set_frame(config['xmin'], config['xmax'],
config['ymin'], config['ymax'])
config['zmin'], config['zmax'])
def get_config(self):
config = {}
config['ExposureTimeAbs'] = self.cam.properties['ExposureTimeAbs']
config['TriggerMode'] = self.cam.properties['TriggerMode']
config['xmin'], config['xmax'],config['ymin'], config['ymax']= (self.xmin, self.xmax, self.ymin, self.ymax)
config['xmin'], config['xmax'],config['zmin'], config['zmax']= (self.xmin, self.xmax, self.zmin, self.zmax)
return config
def measure(self):
import datetime
......@@ -85,30 +89,33 @@ class Interferometer:
def plot_measure(self, measurement, config = None):
if config != None:
ymin = config['ymin']
ymax = config['ymax']
zmin = config['zmin']
zmax = config['zmax']
xmin = config['xmin']
xmax = config['xmax']
else:
ymin = self.ymin
ymax = self.ymax
zmin = self.zmin
zmax = self.zmax
xmin = self.xmin
xmax = self.xmax
from PlottingServers import Plot2DServer
if self.plot_server_im == None:
self.plot_server_im = Plot2DServer({'title':'Interferometer Image', 'xlabel':'z [mm]', 'ylabel': 'x [mm]'})
if self.plot_server_ph == None:
self.plot_server_ph = Plot2DServer({'title':'Interferometer Phase', 'xlabel':'z [mm]', 'ylabel': 'x [mm]'})
im1 = measurement['im1']
shape = measurement['im1'].shape
plt.figure('measurement: Interferometer')
plt.clf()
plt.imshow(measurement['im1'],
extent=self.psize*np.array([0.,shape[1], 0., shape[0]]))
self.plot_server_im.update(np.flipud(im1),extent=self.psize*np.array([0.,shape[1], 0., shape[0]]))
alpha= self.Alpha(measurement['im1'],measurement['im2'])
plt.figure('measurement: Interferometer Phase Projection')
plt.clf()
plt.imshow(alpha, extent=[ymin, ymax, xmin, xmax])
#plt.imshow(D[1], extent=psize*np.array([0.,img.shape[1], 0., img.shape[0]]))
plt.colorbar(shrink=0.3)
plt.title("Phase from measurement "+str(measurement['time']))
self.plot_server_ph.update(alpha[zmin/self.psize:zmax/self.psize, xmin/self.psize:xmax/self.psize], extent=[zmin, zmax, xmin, xmax])
def turn_off(self):
self.cam.close()
......
......@@ -38,7 +38,6 @@ class Laser:
def set_attenuation(self, percent):
phi = np.arccos(percent/100)*90/np.pi + self.max_angle
print (phi)
caput('F10HU-LMOT715:MOT.VAL', phi)
def get_attenuation(self):
......
No preview for this file type
No preview for this file type
This source diff could not be displayed because it is too large. You can view the blob instead.
......@@ -23,9 +23,9 @@ def plot_server_1d( connecx = None, connecy = None, config = {'xlabel' : '','yla
y = np.linspace(0,1,2)
p = figure(title = config['title'],tools =
'box_zoom,,wheel_zoom,save,crosshair,resize,reset,hover')
'pan,box_zoom,wheel_zoom,save,crosshair,resize,reset,hover')
p.plot_height = 250
p.plot_height = 300
p.plot_width = 500
......@@ -43,16 +43,18 @@ def plot_server_1d( connecx = None, connecy = None, config = {'xlabel' : '','yla
def update():
# updating a single column of the the *same length* is OK
if connecx.poll(0.1):
print (p.plot_height)
r1.data_source.data["x"] = connecx.recv()
r2.data_source.data["x"] = r1.data_source.data["x"]
r1.data_source.data["y"] = connecy.recv()
r2.data_source.data["y"] = r1.data_source.data["y"]
p.plot_height = int(np.round(r1.data_source.data["y"][0]*1000))
doc.add_periodic_callback(update, 50)
session.show(p)# open the document in a browser
doc.add_root(p)
open_window('http://localhost:5006/?bokeh-session-id='+str(session.id))
......@@ -92,9 +94,11 @@ def plot_server_2d(connecim = None,connecext = None, config = {'xlabel' : '','yl
p = figure(title = config['title'],
x_range=[0, img.shape[0]], y_range=[0, img.shape[1]],
tools = 'box_zoom,wheel_zoom,save,crosshair,resize,reset')
p.plot_height = 270
p.plot_width = 270
tools = 'pan,wheel_zoom,save,crosshair,resize,reset')
from bokeh.models.tools import BoxZoomTool
p.add_tools(BoxZoomTool(match_aspect = True))
p.plot_height = 400
p.plot_width = 400
from bokeh.palettes import Viridis256
r1 = p.image(image=[np.flipud(img)], x=[0], y=[0],
dw=[img.shape[0]], dh=[img.shape[1]],palette = Viridis256)
......@@ -112,23 +116,20 @@ def plot_server_2d(connecim = None,connecext = None, config = {'xlabel' : '','yl
r1.data_source.data["image"] = [connecim.recv()]
extent = connecext.recv()
p.x_range.start = extent[0]
p.x_range.end = extent[1]
p.y_range.start = extent[2]
p.y_range.end = extent[3]
r1.data_source.data["x"] = [extent[0]]
r1.data_source.data["dw"] = [extent[1] - extent[0]]
r1.data_source.data["y"] = [extent[2]]
r1.data_source.data["dh"] = [extent[3] - extent[2]]
x = [extent[0],extent[1], extent[0], extent[1]]
y = [extent[2],extent[2], extent[3], extent[3]]
set_aspect(p, x, y, aspect=1)
doc.add_periodic_callback(update, 50)
session.show(p)# open the document in a browser
doc.add_root(p)
open_window('http://localhost:5006/?bokeh-session-id='+str(session.id), width = 500)
......@@ -149,4 +150,40 @@ class Plot2DServer:
def close(self):
self.data_stream.join()
\ No newline at end of file
self.data_stream.join()
from bokeh.models import Range1d
def set_aspect(fig, x, y, aspect=1, margin=0.0):
"""Set the plot ranges to achieve a given aspect ratio.
Args:
fig (bokeh Figure): The figure object to modify.
x (iterable): The x-coordinates of the displayed data.
y (iterable): The y-coordinates of the displayed data.
aspect (float, optional): The desired aspect ratio. Defaults to 1.
Values larger than 1 mean the plot is squeezed horizontally.
margin (float, optional): The margin to add for glyphs (as a fraction
of the total plot range). Defaults to 0.1
"""
xmin = min(xi for xi in x)
xmax = max(xi for xi in x)
ymin = min(yi for yi in y)
ymax = max(yi for yi in y)
width = (xmax - xmin)*(1+2*margin)
if width <= 0:
width = 1.0
height = (ymax - ymin)*(1+2*margin)
if height <= 0:
height = 1.0
xcenter = 0.5*(xmax + xmin)
ycenter = 0.5*(ymax + ymin)
r = aspect*(fig.plot_width/fig.plot_height)
if width < r*height:
width = r*height
else:
height = width/r
fig.x_range.start = xcenter-0.5*width
fig.x_range.end = xcenter+0.5*width
fig.y_range.start = ycenter-0.5*height
fig.y_range.end = ycenter+0.5*height
\ No newline at end of file
......@@ -2,8 +2,10 @@
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"%matplotlib inline\n",
......@@ -19,34 +21,20 @@
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"http://localhost:5006/?bokeh-session-id=0kr8nSLs5jUaAU5ZEUttSZlM1G1nhlQ1jyVyZDlmZUli\n"
]
},
{
"data": {
"text/html": [
"<script type='text/javascript'>window.open('http://localhost:5006/?bokeh-session-id=0kr8nSLs5jUaAU5ZEUttSZlM1G1nhlQ1jyVyZDlmZUli', '_blank','width=800, height=400');</script>"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"execution_count": null,
"metadata": {
"scrolled": true
},
"outputs": [],
"source": [
"ps1 = Plot1DServer({'title':'test', 'xlabel':'numbers', 'ylabel':'ja'})"
]
},
{
"cell_type": "code",
"execution_count": 4,
"execution_count": null,
"metadata": {
"collapsed": true,
"scrolled": true
},
"outputs": [],
......@@ -56,37 +44,63 @@
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"http://localhost:5006/?bokeh-session-id=lAjDmOI7Om2ZRvkAzb2tAtV1MWklMdXZXYlJ44RnaM2N\n"
]
},
{
"data": {
"text/html": [
"<script type='text/javascript'>window.open('http://localhost:5006/?bokeh-session-id=lAjDmOI7Om2ZRvkAzb2tAtV1MWklMdXZXYlJ44RnaM2N', '_blank','width=500, height=400');</script>"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"ps2d = Plot2DServer({'title':'test', 'xlabel':'numbers', 'ylabel':'ja'})"
]
},
{
"cell_type": "code",
"execution_count": 78,
"metadata": {},
"execution_count": 21,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"ps2d.update(np.random.random((50,100))*100,[0,2,0,1])"
"ps2d.update(np.random.random((70,100))*100,[0,2,0,5])"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"import numpy as np\n",
"\n",
"from bokeh.client import push_session\n",
"from bokeh.plotting import figure\n",
"from bokeh.document import Document\n",
"\n",
"from multiprocessing import Process, Pipe\n",
"from bokeh.driving import count\n",
"\n",
"from NotebookTools import open_window\n",
"doc = Document()\n",
"\n",
"config = {'title':'test', 'xlabel':'numbers', 'ylabel':'ja'}\n",
"doc.title = config['title']\n",
"x = np.linspace(0,1,2)\n",
"y = np.linspace(0,1,2)\n",
"\n",
"p = figure(title = config['title'],tools = \n",
"'box_zoom,,wheel_zoom,save,crosshair,resize,reset,hover')\n",
"\n",
"p.plot_height = 250\n",
"p.plot_width = 500\n",
"\n",
"\n",
"r1 = p.square(x, y, fill_color=None, line_color=\"green\")\n",
"r2 = p.line(x, y, line_color=\"green\")\n",
"\n",
"p.xaxis.axis_label = config['xlabel']\n",
"p.yaxis.axis_label = config['ylabel']"
]
},
{
......@@ -96,7 +110,9 @@
"collapsed": true
},
"outputs": [],
"source": []
"source": [
"p.plot_height = 250"
]
}
],
"metadata": {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment