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

device_pool, measurement_manager, io functional

parent 6a07bd76
......@@ -30,8 +30,9 @@
"metadata": {},
"outputs": [],
"source": [
"import Scripts.DevicePool as DP\n",
"from Scripts.GUI import DevicePoolInterface, IoInterface\n",
"from Scripts.DevicePool as DevicePool\n",
"from Scripts.MeasurementManager import MeasurementManager\n",
"from Scripts.GUI import DevicePoolInterface, IoInterface, MeasurementManagerInterface\n",
"from Scripts.DataManager import IO"
]
},
......@@ -43,7 +44,9 @@
},
"outputs": [],
"source": [
"device_pool = DP.DevicePool()"
"device_pool = DevicePool()\n",
"io = IO('Data/test/')\n",
"measurement_manager = MeasurementManager(device_pool, io)"
]
},
{
......@@ -53,10 +56,17 @@
"scrolled": false
},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"Widget Javascript not detected. It may not be installed or enabled properly.\n"
]
},
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "80a8015957734c7c8fe8347687e673ac"
"model_id": "2c5d127f5eb14fe8b2ba9a951309ab63"
}
},
"metadata": {},
......@@ -70,81 +80,57 @@
},
{
"cell_type": "code",
"execution_count": 12,
"execution_count": 11,
"metadata": {
"scrolled": false
},
"outputs": [],
"source": [
"io = IO('Data/test/')\n",
"\n",
"#Ionterface(io, device_pool, device_pool_interface).show()"
]
},
"outputs": [
{
"cell_type": "code",
"execution_count": 13,
"metadata": {},
"outputs": [],
"source": [
"from Scripts.MeasurementManager import MeasurementManager"
]
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "b9941677dffd4fb5a3fb4a16eafde98c"
}
},
{
"cell_type": "code",
"execution_count": 14,
"metadata": {},
"outputs": [],
"output_type": "display_data"
}
],
"source": [
"measurement_manager = MeasurementManager(device_pool, io)"
"IoInterface(io, device_pool, device_pool_interface).show()"
]
},
{
"cell_type": "code",
"execution_count": 15,
"execution_count": 26,
"metadata": {
"scrolled": false
"scrolled": true
},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"Process DeviceMeasurer-1:\n",
" File \"PyPylon/cython/factory.pyx\", line 231, in grab_images (cython/factory.cpp:5250)\n",
"Traceback (most recent call last):\n",
" File \"/home/data/anaconda3/lib/python3.5/multiprocessing/process.py\", line 249, in _bootstrap\n",
" self.run()\n",
" File \"/home/data/lwfaserver/Scripts/MeasurementManager.py\", line 100, in run\n",
" self.measure()\n",
" File \"/home/data/lwfaserver/Scripts/MeasurementManager.py\", line 104, in measure\n",
" device_measurement = self.device.measure()\n",
" File \"/home/data/lwfaserver/Scripts/DevicePool.py\", line 71, in measure\n",
" return self.obj.measure()\n",
" File \"/home/data/lwfaserver/Devices/PlasmaCamHorizontal.py\", line 91, in measure\n",
" for img in self.cam.grab_images(1):\n",
"RuntimeError: Unknown exception\n"
]
},
{
"ename": "KeyboardInterrupt",
"evalue": "",
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "e9b902c1c44c4839b5598c2ee6ea254f"
}
},
"metadata": {},
"output_type": "display_data"
},
{
"ename": "AttributeError",
"evalue": "'ParameterChooser' object has no attribute 'parameter'",
"output_type": "error",
"traceback": [
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[0;31mKeyboardInterrupt\u001b[0m Traceback (most recent call last)",
"\u001b[0;32m<ipython-input-15-b8be0dcff571>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m()\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0mmeasurement_manager\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mmeasure\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m",
"\u001b[0;32m/home/data/lwfaserver/Scripts/MeasurementManager.py\u001b[0m in \u001b[0;36mmeasure\u001b[0;34m(self, save, comment, plot_config)\u001b[0m\n\u001b[1;32m 44\u001b[0m \u001b[0;32mwhile\u001b[0m \u001b[0mlen\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mmeasurement\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;34m'measure'\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;34m<\u001b[0m \u001b[0mlen\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mdevices_to_measure\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 45\u001b[0m \u001b[0;32mfor\u001b[0m \u001b[0mdevice_name\u001b[0m \u001b[0;32min\u001b[0m \u001b[0mdevice_names\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m---> 46\u001b[0;31m \u001b[0;32mif\u001b[0m \u001b[0mmeasure_pipes\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0mdevice_name\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;36m1\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mpoll\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 47\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 48\u001b[0m \u001b[0mmeasurement\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;34m'measure'\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0mdevice_name\u001b[0m\u001b[0;34m]\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mmeasure_pipes\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0mdevice_name\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;36m1\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mrecv\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
"\u001b[0;32m/home/data/anaconda3/lib/python3.5/multiprocessing/connection.py\u001b[0m in \u001b[0;36mpoll\u001b[0;34m(self, timeout)\u001b[0m\n\u001b[1;32m 255\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_check_closed\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 256\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_check_readable\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 257\u001b[0;31m \u001b[0;32mreturn\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_poll\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mtimeout\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 258\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 259\u001b[0m \u001b[0;32mdef\u001b[0m \u001b[0m__enter__\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
"\u001b[0;32m/home/data/anaconda3/lib/python3.5/multiprocessing/connection.py\u001b[0m in \u001b[0;36m_poll\u001b[0;34m(self, timeout)\u001b[0m\n\u001b[1;32m 412\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 413\u001b[0m \u001b[0;32mdef\u001b[0m \u001b[0m_poll\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mtimeout\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 414\u001b[0;31m \u001b[0mr\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mwait\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mtimeout\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 415\u001b[0m \u001b[0;32mreturn\u001b[0m \u001b[0mbool\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mr\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 416\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n",
"\u001b[0;32m/home/data/anaconda3/lib/python3.5/multiprocessing/connection.py\u001b[0m in \u001b[0;36mwait\u001b[0;34m(object_list, timeout)\u001b[0m\n\u001b[1;32m 909\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 910\u001b[0m \u001b[0;32mwhile\u001b[0m \u001b[0;32mTrue\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 911\u001b[0;31m \u001b[0mready\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mselector\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mselect\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mtimeout\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 912\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0mready\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 913\u001b[0m \u001b[0;32mreturn\u001b[0m \u001b[0;34m[\u001b[0m\u001b[0mkey\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mfileobj\u001b[0m \u001b[0;32mfor\u001b[0m \u001b[0;34m(\u001b[0m\u001b[0mkey\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mevents\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;32min\u001b[0m \u001b[0mready\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
"\u001b[0;32m/home/data/anaconda3/lib/python3.5/selectors.py\u001b[0m in \u001b[0;36mselect\u001b[0;34m(self, timeout)\u001b[0m\n\u001b[1;32m 374\u001b[0m \u001b[0mready\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;34m[\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 375\u001b[0m \u001b[0;32mtry\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 376\u001b[0;31m \u001b[0mfd_event_list\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_poll\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mpoll\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mtimeout\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 377\u001b[0m \u001b[0;32mexcept\u001b[0m \u001b[0mInterruptedError\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 378\u001b[0m \u001b[0;32mreturn\u001b[0m \u001b[0mready\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
"\u001b[0;31mKeyboardInterrupt\u001b[0m: "
"\u001b[0;31mAttributeError\u001b[0m Traceback (most recent call last)",
"\u001b[0;32m/home/data/lwfaserver/Scripts/GUI.py\u001b[0m in \u001b[0;36mscan\u001b[0;34m(self, bt)\u001b[0m\n\u001b[1;32m 424\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 425\u001b[0m \u001b[0;32mdef\u001b[0m \u001b[0mscan\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mbt\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;32mNone\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 426\u001b[0;31m self.measurement_manager.scan(self.scan_configurator.parameters,\n\u001b[0m\u001b[1;32m 427\u001b[0m \u001b[0mn_loop\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mn_loop_int\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mvalue\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 428\u001b[0m \u001b[0mrate\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mrate_float\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mvalue\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
"\u001b[0;32m/home/data/lwfaserver/Scripts/GUI.py\u001b[0m in \u001b[0;36mparameters\u001b[0;34m(self)\u001b[0m\n\u001b[1;32m 540\u001b[0m \u001b[0;32mdef\u001b[0m \u001b[0mparameters\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 541\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 542\u001b[0;31m \u001b[0;32mreturn\u001b[0m \u001b[0;34m[\u001b[0m\u001b[0mpc\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mparameter\u001b[0m \u001b[0;32mfor\u001b[0m \u001b[0mpc\u001b[0m \u001b[0;32min\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mparameter_choosers\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 543\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 544\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n",
"\u001b[0;32m/home/data/lwfaserver/Scripts/GUI.py\u001b[0m in \u001b[0;36m<listcomp>\u001b[0;34m(.0)\u001b[0m\n\u001b[1;32m 540\u001b[0m \u001b[0;32mdef\u001b[0m \u001b[0mparameters\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 541\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 542\u001b[0;31m \u001b[0;32mreturn\u001b[0m \u001b[0;34m[\u001b[0m\u001b[0mpc\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mparameter\u001b[0m \u001b[0;32mfor\u001b[0m \u001b[0mpc\u001b[0m \u001b[0;32min\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mparameter_choosers\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 543\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 544\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n",
"\u001b[0;31mAttributeError\u001b[0m: 'ParameterChooser' object has no attribute 'parameter'"
]
}
],
"source": [
"measurement_manager.measure()"
"MeasurementManagerInterface(measurement_manager).show()"
]
},
{
......@@ -3059,6 +3045,28 @@
"device_pool['PlasmaCamHorizontal'].measure()"
]
},
{
"cell_type": "code",
"execution_count": 23,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"False"
]
},
"execution_count": 23,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"a = {'b': 1}\n",
"\n",
"'a' in a"
]
},
{
"cell_type": "code",
"execution_count": null,
......
......@@ -107,6 +107,15 @@ class DevicePool:
return [device for name, device in self.devices.items() if device.connected & device.make_measurement & device.make_plot]
@property
def plotable_devices(self):
return [device for name, device in self.devices.items() if device.measureable]
@property
def measureable_devices(self):
return [device for name, device in self.devices.items() if device.plotable]
def import_devices(self):
device_scripts = glob.glob(os.getcwd()+'/Devices/*.py')
......
......@@ -206,27 +206,6 @@ class DevicePoolInterface:
self.device_interfaces[device_name].refresh()
class PlotConfigTool:
def __init__ (self, variable_name, value, plot_config):
self.variable_name = variable_name
self.value = value
self.plot_config = plot_config
layout_bt = widgets.Layout(width = '20px')
layout_text = widgets.Layout(width = 'auto')
if np.dtype(type(value)) == np.dtype('float64') or np.dtype(type(value)) == np.dtype('int64') or np.dtype(type(value)) == np.dtype('int32'):
self.plot_config[variable_name] = False
self.cb = widgets.Checkbox(description=variable_name, layout = layout_text)
self.cb.observe(self.change_bool, names = 'value')
self.widget = self.cb
else:
self.widget = widgets.HTML(variable_name+' not history plottalbe ('+str(np.dtype(type(value)))+')')
def change_bool(self, new):
self.plot_config[self.variable_name] = new['new']
class ConfigLoader:
def __init__(self, config, device_pool, device_pool_interface = None):
......@@ -375,19 +354,101 @@ class IoInterface:
class plot_configurator:
def __init__(self, configset):
self.configset = configset
class MeasurementManagerInterface:
def __init__(self, measurement_manager):
self.measurement_manager = measurement_manager
self.device_pool = self.measurement_manager.device_pool
self.plot_configurator = PlotConfigurator(self.measurement_manager)
self.scan_configurator = ScanConfigurator(self.measurement_manager)
self.make_widget()
def make_widget(self):
heading = widgets.HTML('<b><br>Measurement Manager Interface</b>')
self.switch_style = {True: 'success', False: 'danger'}
self.save_check = widgets.ToggleButton(value=True,
description='save',
button_style='success',
tooltip='Description')
self.save_check.observe(self.button_checked, 'value')
self.clear_hist_bt = widgets.Button(description = 'clear history')
self.clear_hist_bt.on_click(self.clear_hist)
general = widgets.VBox([heading, widgets.HBox([self.save_check, self.clear_hist_bt])])
self.meas_bt = widgets.Button(description = 'measure')
self.meas_bt.on_click(self.measure)
self.loop_inttext = widgets.IntText(value = 1, description = 'loop')
self.rate_text = widgets.FloatText(value = 3, description = 'rate')
self.loop_bt = widgets.Button(description = 'loop')
self.loop_wg = widgets.VBox([widgets.HBox([self.loop_inttext, self.rate_text]), self.loop_bt])
self.loop_bt.on_click(self.loop)
self.bt_scan = widgets.Button(description = 'scan')
self.bt_scan.on_click(self.scan)
self.widget = widgets.VBox([general,
self.meas_bt, self.loop_wg, self.plot_configurator.widget,
self.scan_configurator.widget, self.bt_scan])
def button_checked(self, bt):
bt['owner'].button_style = self.switch_style[bt['new']]
def show(self):
display(self.widget)
def measure(self,bt = None):
self.measurement_manager.measure(save = self.save_check.value,
plot_config = self.plot_configurator.plot_config)
def loop(self,bt = None):
self.measurement_manager.loop(self.loop_inttext.value,self.rate_text.value, save = self.save_check.value,
plot_config = self.plot_configurator.plot_config)
def scan(self, bt = None):
self.measurement_manager.scan(self.scan_configurator.parameters,
n_loop = self.loop_inttext.value,
rate = self.rate_text.value,
save = self.save_check.value,
plot_config = self.plot_configurator.plot_config)
def clear_hist(self, bt = None):
self.measurement_manager.plot_hist = {}
class PlotConfigurator:
def __init__(self, measurement_manager):
self.measurement_manager = measurement_manager
self.device_pool = self.measurement_manager.device_pool
self.plot_config = {}
self.make_widget()
def make_widget(self):
heading = widgets.HTML('<b><br>Plot measurement configuration</b>')
self.bt_plot_config_init = widgets.Button(description='Measure to initialize')
self.bt_plot_config_init.on_click(self.initialize)
self.vb_plot_config = widgets.VBox([self.bt_plot_config_init])
......@@ -403,180 +464,101 @@ class plot_configurator:
plot_meas_check = {}
devices2measure = self.configset.find_devices2measure()
devices_to_measure = self.device_pool.devices_to_measure
measurement = dm.measure(devices2measure)
device_names = [device.name for device in devices_to_measure]
measurement = self.measurement_manager.measure()
for i in range(len(devices2measure)):
device_name = type(devices2measure[i]).__name__
for device_name in device_names:
self.plot_config[device_name] = {}
wgs = []
for item in sorted(measurement['measure'][device_name].items()):
wgs += [plot_config_tool(item[0],
item[1],
for parameter, value in sorted(measurement['measure'][device_name].items()):
wgs += [PlotConfigTool(parameter,
value,
self.plot_config[device_name]).widget]
if hasattr(devices2measure[i], 'plot_measure'):
if device_name in [device.name for device in self.device_pool.plotable_devices]:
wgs += [plot_config_tool('plot_measure',
wgs += [PlotConfigTool('plot_measure',
0,
self.plot_config[device_name]).widget]
vbs += [widgets.VBox(wgs)]
names[i] = [type(devices2measure[i]).__name__]
measure_tab = widgets.Tab(children = vbs, _titles= names)
self.vb_plot_config.children = [self.bt_plot_config_init, measure_tab]
class measureset:
def __init__(self, configset, plot_configurator, configio):
self.plot_configurator = plot_configurator
self.configio = configio
self.configset = configset
self.devices = configset.devices
self.io = configset.io
self.make_widget()
def make_widget(self):
heading = widgets.HTML('<b><br>Make measurements</b>')
self.loop_inttext = widgets.IntText(value = 1, description = 'loop')
self.output_check = widgets.Checkbox(description = 'output')
measure_tab = widgets.Tab(children = vbs, _titles= dict(enumerate(device_names)))
self.vb_plot_config.children = [self.bt_plot_config_init, measure_tab]
self.save_check = widgets.Checkbox(description = 'save')
class PlotConfigTool:
self.measure_bh = widgets.HBox([self.loop_inttext,
self.output_check,
self.save_check])
self.rate_text = widgets.FloatText(value = 3, description = 'rate')
self.save_folder = widgets.Text(description = 'save in ',value = self.io.path)
def __init__ (self, variable_name, value, plot_config):
self.variable_name = variable_name
self.value = value
self.plot_config = plot_config
layout_bt = widgets.Layout(width = '20px')
layout_text = widgets.Layout(width = 'auto')
if np.dtype(type(value)) == np.dtype('float64') or np.dtype(type(value)) == np.dtype('int64') or np.dtype(type(value)) == np.dtype('int32'):
self.plot_config[variable_name] = False
self.cb = widgets.Checkbox(description=variable_name, layout = layout_text)
self.cb.observe(self.change_bool, names = 'value')
self.save_folder.on_submit(self.change_path)
self.widget = self.cb
self.save_folder_text = widgets.HTML('<b> current: '+self.io.path+'</b>')
self.meas_bt = widgets.Button(description = 'measure')
else:
self.widget = widgets.HTML(variable_name+' not history plottalbe ('+str(np.dtype(type(value)))+')')
def change_bool(self, new):
self.plot_config[self.variable_name] = new['new']
self.clear_hist_bt = widgets.Button(description = 'clear history')
class ScanConfigurator:
self.meas_bt.on_click(self.measure)
self.clear_hist_bt.on_click(self.clear_hist)
def __init__(self, measurement_manager):
self.widget = widgets.VBox([heading,
self.measure_bh,
self.rate_text,
self.save_folder,
widgets.HBox([self.meas_bt,
self.clear_hist_bt]) ])
def change_path(self, dum = None):
import os
self.measurement_manager = measurement_manager
if not os.path.isdir(self.save_folder.value):
os.mkdir(self.save_folder.value)
self.io.path = self.save_folder.value
self.save_folder_text.value = '<b> current: '+self.io.path+'</b>'
self.make_widget()
self.configio.select_restore.options = self.configio.get_all()
def make_widget(self):
def show(self):
display(self.widget)
heading = widgets.HTML('<b>Scanning Tool</b>')
def measure(self, bt = None, comment = '', name = None, delete = True):
devices2measure = self.configset.find_devices2measure()
parallel = False
#initialize parallelization
if parallel:
from multiprocessing import Process, Pipe
class DataStreamProcess(Process):
def __init__(self, connec, *args, **kwargs):
self.connec = connec
Process.__init__(self, *args, **kwargs)
def run(self):
loop_measure(parallel = True, connec = self.connec)
#loop measure
def loop_measure(parallel = False, connec = None):
measurements = []
for i in range(self.loop_inttext.value):
if delete:
import IPython
IPython.display.clear_output(wait = True)
import time
t = time.time()
#getting data from devices
measurement = dm.measure(self.devices, devices2measure = self.configset.find_devices2measure())
#save data
if self.save_check.value:
if name == None:
self.io.save(measurement,
kind = 'measure', comment = comment)
else:
self.io.save(measurement,
kind = 'measure', comment = comment, name = name+'_'+str(i))
if parallel:
connec.send(measurement)
elif self.output_check.value:
dm.plot_measure(measurement,
self.configset.find_devices2measure(),
self.plot_configurator.plot_config, 0.01)
print ('maximal possible rate: ',np.round(1/(time.time() - t),1))
if (1/self.rate_text.value - (time.time() - t) < 0):
print ('set rate cannot be reached.')
else:
time.sleep(1/self.rate_text.value - (time.time() -t))
measurements += [measurement]
self.dimensions_text = widgets.IntSlider(value=1,
min=0,
max=10,
step=1,
description='Number of Parameters:')
self.dimensions_text.observe(self.set_dimension)
return measurements
self.scanning_tool_box = widgets.HBox([])
self.set_dimension()
self.widget = widgets.VBox([heading, self.dimensions_text, self.scanning_tool_box])
@property
def parameters(self):
return [pc.parameter for pc in self.parameter_choosers]
if self.output_check.value and parallel:
conn1, conn2 = Pipe()
data_stream = DataStreamProcess(conn1)
data_stream.start()
while True:
if not(conn2.poll(0.1)):
if not(data_stream.is_alive()):
break
else:
continue
measurement = conn2.recv()
def set_dimension(self, dum = None):
dm.plot_measure(measurement, devices2measure,plot_config, 0.01)
plt.pause(0.001)
plt.draw_all(force = True)
else:
return loop_measure()
self.parameter_choosers = [ParameterChooser('Parameter '+str(i+1),self.measurement_manager) for i in range(self.dimensions_text.value)]
self.scanning_tool_box.children = [pc.widget for pc in self.parameter_choosers]
def clear_hist(self, bt = None):
import Globals
Globals.plot_hist = {}
class parameter_chooser:
class ParameterChooser:
def __init__(self, title, devices):
def __init__(self, title, measurement_manager):
self.title = title
self.devices = devices
device_dict = {}
for device in self.devices:
device_dict[type(device).__name__] = device
self.measurement_manager = measurement_manager
self.device_pool = measurement_manager.device_pool
self.device_dict = device_dict
self.device_dict = self.device_pool.devices
self.make_widget()
......@@ -610,19 +592,17 @@ class parameter_chooser:
self.minv,
self.maxv,
self.nsteps], layout = box_layout)
def info(self):
return self.select_parameter.value+'_'+str(self.minv.value)+'-'+str(self.maxv.value)+'_'+str(self.nsteps.value)+'+'
def on_value_change_device(self, dum= None):
device = self.select_device.value
config = dm.get_config([device])
config = self.device_pool.config
scannable = []
for item in config[type(device).__name__].items():
if np.dtype(type(item[1])) == np.dtype('float64') or np.dtype(type(item[1])) == np.dtype(int):
scannable += [item[0]]
for name, variable in config[device.name].items():
if np.dtype(type(variable)) == np.dtype('float64') or np.dtype(type(variable)) == np.dtype(int):
scannable += [name]
......@@ -639,8 +619,9 @@ class parameter_chooser:
try:
device = self.select_device.value
config = dm.get_config([device])
current_value = config[type(device).__name__][parameter]
config = device.config
current_value = config[device.name][parameter]
self.current_value.value = '<b> current value: '+str(current_value)+' </b>'
......@@ -649,95 +630,16 @@ class parameter_chooser:
except:
print ('Choose parameter!!!')
def get_linspace(self):
return np.linspace(self.minv.value, self.maxv.value, self.nsteps.value)