Advertisement
Guest User

Untitled

a guest
Oct 27th, 2016
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.19 KB | None | 0 0
  1. ## customized count
  2. def delayed_count(detectors, shutter_config, interval=None, num=1, *, md=None):
  3. """
  4. Take one or more readings from detectors.
  5. Parameters
  6. ----------
  7. detectors : list
  8. list of 'readable' objects
  9. gasses : list of string
  10. name of gasses want to alterna
  11. shutter_config : tuple
  12. a tuple of shutter configuration, expected to be (shutter, open_satus, close_status)
  13. interval : float
  14. FIXME
  15. num : integer, optional
  16. number of readings to take; default is 1
  17. If None, capture data until canceled
  18. md : dict, optional
  19. metadata
  20. Note
  21. ----
  22. If ``delay`` is an iterable, it must have at least ``num - 1`` entries or
  23. the plan will raise a ``ValueError`` during iteration.
  24. """
  25. if md is None:
  26. md = {}
  27. md = ChainMap(
  28. md,
  29. {'detectors': [det.name for det in detectors],
  30. 'num_steps': num,
  31. 'plan_args': {'detectors': list(map(repr, detectors)), 'num': num},
  32. 'plan_name': 'count'})
  33.  
  34. # If delay is a scalar, repeat it forever. If it is an iterable, leave it.
  35. #if not isinstance(delay, Iterable):
  36. # delay = itertools.repeat(delay)
  37. #else:
  38. # delay = iter(delay)
  39.  
  40. # unpack shutter
  41. shutter, sh_open, sh_close = shutter_config
  42.  
  43.  
  44. @stage_decorator(detectors)
  45. @run_decorator(md=md)
  46. def finite_plan():
  47. for i in range(num):
  48.  
  49. ts1 = time.time()
  50.  
  51. # light frame
  52. yield Msg('checkpoint')
  53. yield from trigger_and_read(detectors)
  54.  
  55. # dark frame
  56. yield Msg('checkpoint')
  57. yield from abs_set(shutter, sh_close)
  58. yield from trigger_and_read(detectors)
  59. yield from abs_set(shutter, sh_open)
  60.  
  61. # delay time
  62. ts2 = time.time()
  63.  
  64. #try:
  65. # d = next(delay)
  66. #except StopIteration:
  67. # if i + 1 == num:
  68. # break
  69. # else:
  70. # # num specifies a number of iterations less than delay
  71. # raise ValueError("num=%r but delays only provides %r "
  72. # "entries" % (num, i))
  73. if interval is not None:
  74. yield Msg('sleep', None, ts1 + interval - ts2)
  75.  
  76. @stage_decorator(detectors)
  77. @run_decorator(md=md)
  78. def infinite_plan():
  79. while True:
  80. ts1 = time.time()
  81.  
  82. # light frame
  83. yield Msg('checkpoint')
  84. yield from trigger_and_read(detectors)
  85.  
  86. # dark frame
  87. yield Msg('checkpoint')
  88. yield from abs_set(shutter, sh_close)
  89. yield from trigger_and_read(detectors)
  90. yield from abs_set(shutter, sh_open)
  91.  
  92. #try:
  93. # d = next(delay)
  94. #except StopIteration:
  95. # break
  96. if interval is not None:
  97. yield Msg('sleep', None, ts1 + interval - ts2)
  98.  
  99. if num is None:
  100. return (yield from infinite_plan())
  101. else:
  102. return (yield from finite_plan())
  103.  
  104. ## customized TiffExporter
  105. class XpdLiveTiffExporter(LiveTiffExporter):
  106. """
  107. subclass to customize functionality
  108.  
  109. Save TIFF files.
  110. Incorporate metadata and data from individual data points in the filenames.
  111. Parameters
  112. ----------
  113. field : str
  114. a data key, e.g., 'image'
  115. template : str
  116. A templated file path, where curly brackets will be filled in with
  117. the attributes of 'start', 'event', and (for image stacks) 'i',
  118. a sequential number.
  119. e.g., "dir/scan{start.scan_id}_by_{start.experimenter}_{i}.tiff"
  120. dryrun : bool
  121. default to False; if True, do not write any files
  122. overwrite : bool
  123. default to False, raising an OSError if file exists
  124. db : Broker, optional
  125. The databroker instance to use, if not provided use databroker
  126. singleton
  127. Attributes
  128. ----------
  129. filenames : list of filenames written in ongoing or most recent run
  130. """
  131.  
  132. def _save_image(self, image, filename):
  133. fn_head, fn_tail = os.split(filename)
  134. if not os.path.isdir(fn_head):
  135. os.makedirs(fn_head, exist_ok=True)
  136.  
  137. super()._save_image(image, filename)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement