Advertisement
Guest User

Untitled

a guest
Jul 6th, 2015
155
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.86 KB | None | 0 0
  1. {
  2. "cells": [
  3. {
  4. "metadata": {
  5. "trusted": true,
  6. "collapsed": false
  7. },
  8. "cell_type": "code",
  9. "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",
  10. "execution_count": 1,
  11. "outputs": [
  12. {
  13. "output_type": "stream",
  14. "text": ":0: FutureWarning: IPython widgets are experimental and may change in the future.\n",
  15. "name": "stderr"
  16. }
  17. ]
  18. },
  19. {
  20. "metadata": {
  21. "trusted": true,
  22. "collapsed": true
  23. },
  24. "cell_type": "code",
  25. "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))",
  26. "execution_count": 2,
  27. "outputs": []
  28. },
  29. {
  30. "metadata": {
  31. "trusted": true,
  32. "collapsed": false
  33. },
  34. "cell_type": "code",
  35. "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')",
  36. "execution_count": 3,
  37. "outputs": [
  38. {
  39. "output_type": "stream",
  40. "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",
  41. "name": "stdout"
  42. }
  43. ]
  44. },
  45. {
  46. "metadata": {
  47. "trusted": true,
  48. "collapsed": true
  49. },
  50. "cell_type": "code",
  51. "source": "",
  52. "execution_count": null,
  53. "outputs": []
  54. }
  55. ],
  56. "metadata": {
  57. "kernelspec": {
  58. "name": "python3",
  59. "display_name": "Python 3",
  60. "language": "python"
  61. },
  62. "language_info": {
  63. "mimetype": "text/x-python",
  64. "name": "python",
  65. "codemirror_mode": {
  66. "version": 3,
  67. "name": "ipython"
  68. },
  69. "nbconvert_exporter": "python",
  70. "version": "3.4.3",
  71. "file_extension": ".py",
  72. "pygments_lexer": "ipython3"
  73. },
  74. "gist_id": "a549a83346aa53ffd801"
  75. },
  76. "nbformat": 4,
  77. "nbformat_minor": 0
  78. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement