Skip to content

Instantly share code, notes, and snippets.

@ericdill
Last active August 29, 2015 14:22
Show Gist options
  • Save ericdill/a549a83346aa53ffd801 to your computer and use it in GitHub Desktop.
Save ericdill/a549a83346aa53ffd801 to your computer and use it in GitHub Desktop.
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"metadata": {
"trusted": true,
"collapsed": false
},
"cell_type": "code",
"source": "from bluesky import *\nfrom bluesky.examples import *\nfrom bluesky.callbacks import CallbackBase\nfrom bluesky.standard_config import RE\n# RE = RunEngine()\n# RE.memory['beamline_id'] = 'c08i'\nRE.verbose = False\nfrom collections import OrderedDict",
"execution_count": 1,
"outputs": [
{
"output_type": "stream",
"text": ":0: FutureWarning: IPython widgets are experimental and may change in the future.\n",
"name": "stderr"
}
]
},
{
"metadata": {
"trusted": true,
"collapsed": true
},
"cell_type": "code",
"source": "def doc_type(doc):\n \"\"\"Determine if 'doc' is a 'start', 'stop', 'event' or 'descriptor'\n\n Returns\n -------\n {'start', 'stop', 'event', descriptor'}\n \"\"\"\n # use an ordered dict to be a little faster with the assumption that\n # events are going to be the most common, then descriptors then\n # start/stops should come as pairs\n field_mapping = OrderedDict()\n field_mapping['event'] = ['seq_num', 'data']\n field_mapping['descriptor'] = ['data_keys', 'run_start']\n field_mapping['start'] = ['scan_id', 'beamline_config']\n field_mapping['stop'] = ['reason', 'exit_status']\n\n for doc_type, required_fields in field_mapping.items():\n could_be_this_one = True\n for field in required_fields:\n try:\n doc[field]\n except KeyError:\n could_be_this_one = False\n if could_be_this_one:\n print('document is a %s' % doc_type)\n return doc_type\n\n raise ValueError(\"Cannot determine the document type. Document I was \"\n \"given = {}\".format(doc))",
"execution_count": 2,
"outputs": []
},
{
"metadata": {
"trusted": true,
"collapsed": false
},
"cell_type": "code",
"source": "# callbacker = CallbackBase()\n# doc_type = callbacker.dispatch\ncb = doc_type\n\nRE(stepscan(motor, det), subs={'start': cb, \n 'stop': cb, \n 'event': cb,\n 'descriptor': cb}, beamline_id='c08i')",
"execution_count": 3,
"outputs": [
{
"output_type": "stream",
"text": "The following exceptions were raised during processing of the [[start]] queue\n\nError 0\n-------\nCannot determine the document type. Document I was given = {'scan_id': 1, 'time': 1433794634.8274412, 'beamline_id': 'c08i', 'uid': '5f4c3da8-e2b9-4100-95b6-75a511a6e193', 'owner': 'edill'}\n\n\tTraceback\n\t---------\n\t File \"/home/edill/Dropbox/dev/python/bluesky/bluesky/utils.py\", line 168, in process\n func(*args, **kwargs)\n\n\t File \"/home/edill/Dropbox/dev/python/bluesky/bluesky/utils.py\", line 249, in __call__\n return mtd(*args, **kwargs)\n\n\t File \"<ipython-input-2-17035da912a4>\", line 29, in doc_type\n \"given = {}\".format(doc))\n\ndocument is a descriptor\ndocument is a event\ndocument is a event\ndocument is a event\ndocument is a event\ndocument is a event\ndocument is a event\ndocument is a event\ndocument is a event\ndocument is a event\ndocument is a event\ndocument is a stop\n",
"name": "stdout"
}
]
},
{
"metadata": {
"trusted": true,
"collapsed": true
},
"cell_type": "code",
"source": "",
"execution_count": null,
"outputs": []
}
],
"metadata": {
"kernelspec": {
"name": "python3",
"display_name": "Python 3",
"language": "python"
},
"language_info": {
"mimetype": "text/x-python",
"name": "python",
"codemirror_mode": {
"version": 3,
"name": "ipython"
},
"nbconvert_exporter": "python",
"version": "3.4.3",
"file_extension": ".py",
"pygments_lexer": "ipython3"
},
"gist_id": "a549a83346aa53ffd801"
},
"nbformat": 4,
"nbformat_minor": 0
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment