Commit 909ab5d1 authored by root's avatar root
Browse files

first accelerated electrons measured with linux and bokeh

parent e6665fe3
{
"cells": [],
"metadata": {},
"nbformat": 4,
"nbformat_minor": 2
}
{
"cells": [],
"metadata": {},
"nbformat": 4,
"nbformat_minor": 2
}
......@@ -65,15 +65,15 @@ class DRS4:
def getTriggerMode(self):
return caget('FIN-LSCP-DRS1:TRIG_MODE')
def trigger(self):
self.socket.sendto('drsstart\n'.encode(), ('wd017.psi.ch', 3000))
#def trigger(self):
# self.socket.sendto('drsstart\n'.encode(), ('wd017.psi.ch', 3000))
def measure(self):
import time
time.sleep(self.delay)
self.trigger()
import datetime
time = str(datetime.datetime.now()).replace(':','-').replace(' ','_')
measurement = {'time': time}
return measurement
#def measure(self):
# import time
# time.sleep(self.delay)
# self.trigger()
# import datetime
# time = str(datetime.datetime.now()).replace(':','-').replace(' ','_')
# measurement = {'time': time}
# return measurement
\ No newline at end of file
import numpy as np
import matplotlib.pyplot as plt
from Devices.PeriscopeTools.PyAPT import APTMotor
import sys
sys.path.append('../pyAPT/')
from pyAPT import Z806
'''
config file:
......@@ -14,7 +17,7 @@ measurement file (n.a)
class ParabolicMirror:
def __init__(self, config, home = False):
import time
time.sleep(1)
time.sleep(0.1)
try:
self.connect_motors()
print ('Connnection with motors sucessful!')
......@@ -29,55 +32,59 @@ class ParabolicMirror:
def set_config(self,config):
self.Pay.mAbs(config['pos_Pay'])
self.Paz.mAbs(config['pos_Paz'])
self.Pay.goto(config['pos_Pay'])
self.Paz.goto(config['pos_Paz'])
def get_config(self):
config = {}
config['pos_Pay'] = float(self.Pay.getPos())
config['pos_Paz'] = float(self.Paz.getPos())
config['pos_Pay'] = float(self.Pay.position())
config['pos_Paz'] = float(self.Paz.position())
return config
def connect_motors(self):
self.Paz = APTMotor(27001714, HWTYPE=31)
self.Pay = APTMotor(27250866, HWTYPE=31)
self.Paz = Z806(83835804)
self.Pay = Z806(83835879)
self.motors = [self.Pay, self.Paz]
def home(self):
for motor in self.motors:
motor.go_home()
motor.home()
def optimize(self, focus, laser, per, wanted_focus_um, n_av = 10, sleep_time = 0.2, output = True, maxiter = 100):
def optimize(self, focus, laser, Cz, wanted_focus_um, n_av = 10, sleep_time = 0.2, output = True, maxiter = 100):
#this variable is necessary to compensate the attenuation of the laser
global intmult
intmult = 1.
global reduce_int
reduce_int = False
def to_min():
global intmult
FWHMxs = []
FWHMys = []
maxits = []
maxints = []
for i in range(n_av):
measurement = focus.measure()
FWHMxs.append(measurement['FWHMx'])
FWHMys.append(measurement['FWHMy'])
maxits.append(measurement['maxit'])
maxints.append(measurement['maxit'])
if output:
focus.plot_measure(measurement)
plt.pause(0.01)
#if output:
# focus.plot_measure(measurement)
# plt.pause(0.01)
del measurement
if output:
print ('FWHMxs: ',FWHMxs)
print ('maxits: ',maxits)
print ('maxints: ',maxints)
res = np.sqrt(np.array(FWHMxs)**2 + np.array(FWHMys)**2)/np.sqrt(2)*4096/np.array(maxits)*intmult
res = np.sqrt(np.array(FWHMxs)**2 + np.array(FWHMys)**2)/np.sqrt(2)*4096/np.array(maxints)*intmult
mean, error = np.mean(res), np.std(res, ddof = -1)
if mean > 4e3:
config_laser = laser.get_config()
config_laser['attenuation'] = config_laser['attenuation']/1.4
laser.set_config(config_laser)
intmult *= 1.4
if np.mean(maxints) > 4e3:
redurce_int = True
if output:
print ('mean: ',mean,'error: ', error)
......@@ -87,6 +94,9 @@ class ParabolicMirror:
return
return mean, error
def change_parameter(y, z, zc):
print ('Parameters: ',(y, z, zc))
......@@ -94,10 +104,11 @@ class ParabolicMirror:
self.set_config(config)
config_per = per.get_config()
#config_per = per.get_config()
config_per['deltaz_Cz'] = zc
per.set_config(config_per)
#config_per['deltaz_Cz'] = zc
Cz.goto(zc)
#per.set_config(config_per)
return True
def opt_f(x):
......@@ -115,17 +126,31 @@ class ParabolicMirror:
return to_min()[0]
config0 = self.get_config()
config_per0 = per.get_config()
#config_per0 = per.get_config()
config0_focus = focus.get_config()
config0_focus['measure_full']=True
focus.set_config(config0_focus)
x0 = [config0['pos_Pay'],
config0['pos_Paz'],
config_per0['deltaz_Cz']]
Cz.position()]
#config_per0['deltaz_Cz']]
def after_it(res):
print ('###################')
print ('step done')
global reduce_int
if reduce_int:
config_laser = laser.get_config()
config_laser['attenuation'] = config_laser['attenuation']/1.2
laser.set_config(config_laser)
intmult *= 1.2
reduce_int = False
print ('laser attenuated')
# directly Nedler-Mead
import scipy.optimize
res = scipy.optimize.minimize(opt_f, x0, method='Nelder-Mead', options={'disp': output,
res = scipy.optimize.minimize(opt_f, x0, method='Nelder-Mead',callback = after_it, options={'disp': output,
'initial_simplex': None,
'maxiter': maxiter,
'xatol': 0.00005,
......
......@@ -107,15 +107,31 @@ class Periscope:
self.zmin = max((max((self.deltaz_Mz, self.deltaz_Cz)), 0))
def connect_motors(self):
self.Mz = Z825B(83835879)
self.Mz = Z825B(83829619) #Z825B(83835879)
self.Pz = Z825B(83832249)
self.Py = Z825B(83832219)
self.Px = Z825B(83835886)
self.Cz = Z825B(83829619)
class dummmotor():
def __init__(self):
print ('dummmotor used')
self.pos = 0.
def position(self):
return self.pos
def goto(self,z):
self.pos = z
return True
def home(self):
self.pos = 0.
return True
self.Cz = dummmotor()#Z825B(83829619)
self.motors = [self.Px, self.Py, self.Pz, self.Mz, self.Cz]
def get_pos_motor(self):
return np.array([motor.getPos() for motor in self.motors])
return np.array([motor.position() for motor in self.motors])
def home(self):
for motor in self.motors:
motor.home()
......@@ -160,7 +176,7 @@ class Periscope:
self.history_g += [self.position_g]
self.position_l += np.array([np.float64(dx), np.float64(dy), np.float64(dz)])
self.position_g = [-Px.getPos(), Py.getPos(), Pz.getPos()]
self.position_g = [-Px.position(), Py.position(), Pz.position()]
def _mxAbs(self, x):
assert (self.Px.goto(-x)), 'Motor Px failed'
......
No preview for this file type
No preview for this file type
No preview for this file type
This diff is collapsed.
......@@ -43,13 +43,10 @@ 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)
......
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"hu\n"
]
}
],
"source": [
"import sys\n",
"sys.path.append('../pyAPT/')\n",
"from pyAPT import Z825B\n",
" \n",
"Cz = Z825B(83829619)"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"send message\n",
"message: b'\\x11\\x04\\x01\\x00P\\x01'\n",
"done\n",
"reading loop\n",
"done\n",
"reading loop\n",
"done\n"
]
},
{
"data": {
"text/plain": [
"2.5135552705223883"
]
},
"execution_count": 3,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"Cz.position()"
]
},
{
"cell_type": "code",
"execution_count": 21,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"send message\n",
"message: b'l\\x04\\x00\\x00P\\x01'\n",
"done\n",
"send message\n",
"message: b'S\\x04\\x06\\x00\\xd0\\x01\\x01\\x003\\xba\\x01\\x00'\n",
"done\n",
"reading loop\n",
"done\n",
"reading loop\n",
"done\n"
]
},
{
"data": {
"text/plain": [
"<pyAPT.controller.ControllerStatus at 0x7fd358de4f60>"
]
},
"execution_count": 21,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"Cz.goto(3.3)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.6.0"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
......@@ -2,11 +2,18 @@
"cells": [
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"execution_count": 3,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"The autoreload extension is already loaded. To reload it, use:\n",
" %reload_ext autoreload\n"
]
}
],
"source": [
"%matplotlib inline\n",
"import matplotlib.pyplot as plt\n",
......@@ -21,18 +28,49 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 22,
"metadata": {
"scrolled": true
},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"http://localhost:5006/?bokeh-session-id=QFsyjTymTmdFXFhBdSWrxCCrQ0OmoGngJUJDbtnAsTDm\n"
]
},
{
"data": {
"text/html": [
"<script type='text/javascript'>window.open('http://localhost:5006/?bokeh-session-id=QFsyjTymTmdFXFhBdSWrxCCrQ0OmoGngJUJDbtnAsTDm', '_blank','width=800, height=500');</script>"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"/home/data/anaconda3/lib/python3.6/site-packages/bokeh/models/sources.py:81: BokehUserWarning: ColumnDataSource's columns must be of the same length\n",
" lambda: warnings.warn(\"ColumnDataSource's columns must be of the same length\", BokehUserWarning))\n",
"/home/data/anaconda3/lib/python3.6/site-packages/bokeh/models/sources.py:81: BokehUserWarning: ColumnDataSource's columns must be of the same length\n",
" lambda: warnings.warn(\"ColumnDataSource's columns must be of the same length\", BokehUserWarning))\n",
"/home/data/anaconda3/lib/python3.6/site-packages/bokeh/models/sources.py:81: BokehUserWarning: ColumnDataSource's columns must be of the same length\n",
" lambda: warnings.warn(\"ColumnDataSource's columns must be of the same length\", BokehUserWarning))\n",
"/home/data/anaconda3/lib/python3.6/site-packages/bokeh/models/sources.py:81: BokehUserWarning: ColumnDataSource's columns must be of the same length\n",
" lambda: warnings.warn(\"ColumnDataSource's columns must be of the same length\", BokehUserWarning))\n"
]
}
],
"source": [
"ps1 = Plot1DServer({'title':'test', 'xlabel':'numbers', 'ylabel':'ja'})"
]
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 28,
"metadata": {
"collapsed": true,
"scrolled": true
......@@ -44,18 +82,33 @@
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"execution_count": 29,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"http://localhost:5006/?bokeh-session-id=bPofw8ggnL2HHsCaEaWWL01Y0aTFz89RgQ8OLVPWkfKM\n"
]
},
{
"data": {
"text/html": [
"<script type='text/javascript'>window.open('http://localhost:5006/?bokeh-session-id=bPofw8ggnL2HHsCaEaWWL01Y0aTFz89RgQ8OLVPWkfKM', '_blank','width=500, height=500');</script>"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"ps2d = Plot2DServer({'title':'test', 'xlabel':'numbers', 'ylabel':'ja'})"
]
},
{
"cell_type": "code",
"execution_count": 21,
"execution_count": 39,
"metadata": {
"collapsed": true
},
......@@ -64,45 +117,6 @@
"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']"
]
},
{
"cell_type": "code",
"execution_count": null,
......@@ -110,9 +124,7 @@
"collapsed": true
},
"outputs": [],
"source": [
"p.plot_height = 250"
]
"source": []
}
],
"metadata": {
......
......@@ -2,18 +2,11 @@
"cells": [
{
"cell_type": "code",
"execution_count": 6,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"The autoreload extension is already loaded. To reload it, use:\n",
" %reload_ext autoreload\n"
]
}
],
"execution_count": 1,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"import sys\n",
"%load_ext autoreload\n",
......@@ -22,7 +15,7 @@
},
{
"cell_type": "code",
"execution_count": 7,
"execution_count": 2,
"metadata": {
"collapsed": true
},
......@@ -33,7 +26,7 @@
},
{
"cell_type": "code",
"execution_count": 8,
"execution_count": 3,
"metadata": {
"collapsed": true
},
......@@ -44,8 +37,10 @@
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {},
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"c = pyAPT.Z825B(serial_number=83835879)"
......@@ -53,23 +48,44 @@
},
{
"cell_type": "code",
"execution_count": 10,
"metadata": {},
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [