Skip to content

Instantly share code, notes, and snippets.

@CJ-Wright
Last active July 25, 2018 03:38
Show Gist options
  • Save CJ-Wright/6a845e7b737bfc7aad3785063bc8b747 to your computer and use it in GitHub Desktop.
Save CJ-Wright/6a845e7b737bfc7aad3785063bc8b747 to your computer and use it in GitHub Desktop.
import bluesky.plans as bp
import bluesky.plan_stubs as bps
from bluesky.utils import Msg, short_uid as _short_uid
from bluesky.preprocessors import subs_wrapper
from bluesky.simulators import summarize_plan
from bluesky.callbacks import LiveTable
from xpdacq.xpdacq_conf import xpd_configuration
from xpdacq.xpdacq import glbl, CustomizedRunEngine
from xpdacq.beamtime import _configure_area_det
shutter = xpd_configuration['shutter']
sh_open = glbl['shutter_conf']['open']
sh_close = glbl['shutter_conf']['close']
sample_motor = spinner_goniohead.X
wait_time = 5
# vendor blusky nd_per_step
def light_dark_nd_step(detectors, step, pos_cache):
"""
Inner loop of an N-dimensional step scan
This is the default function for ``per_step`` param`` in ND plans.
Parameters
----------
detectors : iterable
devices to read
step : dict
mapping motors to positions in this step
pos_cache : dict
mapping motors to their last-set positions
"""
def move():
yield Msg('checkpoint')
grp = _short_uid('set')
for motor, pos in step.items():
if pos == pos_cache[motor]:
# This step does not move this motor.
continue
yield Msg('set', motor, pos, group=grp)
pos_cache[motor] = pos
yield Msg('wait', None, group=grp)
motors = step.keys()
yield from bps.abs_set(shutter, sh_close, wait=True)
yield from move()
yield from bps.sleep(wait_time)
yield from bps.trigger_and_read(list(detectors) + list(motors) +
[shutter], name='dark')
yield from bps.abs_set(shutter, sh_open, wait=True)
yield from bps.trigger_and_read(list(detectors) + list(motors) +
[shutter])
yield from bps.abs_set(shutter, sh_close, wait=True)
plan = bp.scan([pe1c, shutter, cryostat1], cryostat, 5, 500, 499,
per_step=light_dark_nd_step)
xrun(2, plan, subs=[LiveTable([pe1c, shutter, cryostat1])])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment