Guest User

Untitled

a guest
Mar 18th, 2018
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.65 KB | None | 0 0
  1. from bluesky.callbacks import LivePlot
  2.  
  3. # LivePlot does not provide very good hooks for doing anything
  4. # beyond very simple data processing. For example, it can't combine
  5. # values from two different fields. Here, we cargo cult most of
  6. # LivePlot.event, but we expect the 'y' value to be a string.
  7.  
  8. class ExprPlot(LivePlot):
  9. def event(self, doc):
  10. "Unpack data from the event and call self.update()."
  11. # This outer try/except block is needed because multiple event
  12. # streams will be emitted by the RunEngine and not all event
  13. # streams will have the keys we want.
  14. try:
  15. # This inner try/except block handles seq_num and time, which could
  16. # be keys in the data or accessing the standard entries in every
  17. # event.
  18. try:
  19. new_x = doc['data'][self.x]
  20. except KeyError:
  21. if self.x in ('time', 'seq_num'):
  22. new_x = doc[self.x]
  23. else:
  24. raise
  25. new_y = eval(self.y, doc['data'])
  26. except KeyError:
  27. # wrong event stream, skip it
  28. return
  29.  
  30. # Special-case 'time' to plot against against experiment epoch, not
  31. # UNIX epoch.
  32. if self.x == 'time' and self._epoch == 'run':
  33. new_x -= self._epoch_offset
  34.  
  35. self.update_caches(new_x, new_y)
  36. self.update_plot()
  37.  
  38. ### DEMO ###
  39.  
  40. from bluesky import RunEngine
  41. from bluesky.utils import install_kicker
  42. install_kicker()
  43. RE = RunEngine({})
  44. from bluesky.plans import rel_scan
  45. from ophyd.sim import det, det2, motor
  46.  
  47.  
  48.  
  49. cb = ExprPlot('100 * det / det2')
  50. RE(rel_scan([det, det2], motor, -1, 1, 5), cb)
Add Comment
Please, Sign In to add comment