Skip to content

Instantly share code, notes, and snippets.

@CJ-Wright
Last active July 24, 2018 22:08
Show Gist options
  • Save CJ-Wright/319bf777d6c92bcfd16e632e01be89a5 to your computer and use it in GitHub Desktop.
Save CJ-Wright/319bf777d6c92bcfd16e632e01be89a5 to your computer and use it in GitHub Desktop.
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
#if motor == cryostat1:
# for (low, hi), heater_pos in heater_dict.items():
# if low < pos <= hi:
# yield Msg('set', cryostat1.heater, heater_pos, group=grp)
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()
for k, v in sub_sample_dict.items():
if np.abs(sample_motor.get().user_readback - k) < 1.5:
inner_dict = v
break
else:
inner_dict = {'exposure': .1, 'wait': 1}
print(inner_dict)
_configure_area_det(inner_dict['exposure'])
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)
yield from bps.sleep(inner_dict['wait'])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment