def test_no_rewind_device(): class FakeSig: def get(self): return False det = SynGauss("det", motor, "motor", center=0, Imax=1, sigma=1) det.rewindable = FakeSig() assert not all_safe_rewind([det])
def test_no_rewind_device(): class FakeSig: def get(self): return False det = SynGauss('det', motor, 'motor', center=0, Imax=1, sigma=1) det.rewindable = FakeSig() assert not all_safe_rewind([det])
def test_duplicate_keys(): # two detectors, same data keys det1 = SynGauss('det', motor, 'motor', center=0, Imax=1, sigma=1) det2 = SynGauss('det', motor, 'motor', center=0, Imax=1, sigma=1) def gen(): yield(Msg('open_run')) yield(Msg('create')) yield(Msg('trigger', det1)) yield(Msg('trigger', det2)) yield(Msg('read', det1)) yield(Msg('read', det2)) yield(Msg('save')) with assert_raises(ValueError): RE(gen())
def _make_unrewindable_suspender_marker(): class UnReplayableSynGauss(SynGauss): def pause(self): raise NoReplayAllowed() motor = Mover('motor', {'motor': lambda x: x}, {'x': 0}) def test_plan(motor, det): yield Msg('set', motor, 0) yield Msg('trigger', det) yield Msg('sleep', None, 1) yield Msg('set', motor, 0) yield Msg('trigger', det) inps = [] inps.append((test_plan, motor, UnReplayableSynGauss('det', motor, 'motor', center=0, Imax=1), ['set', 'trigger', 'sleep', 'wait_for', 'set', 'trigger'])) inps.append( (test_plan, motor, SynGauss('det', motor, 'motor', center=0, Imax=1), [ 'set', 'trigger', 'sleep', 'wait_for', 'set', 'trigger', 'sleep', 'set', 'trigger' ])) return pytest.mark.parametrize('plan,motor,det,msg_seq', inps)
def test_center(): assert_true(not RE._run_is_open) det = SynGauss('det', motor, 'motor', 0, 1000, 1, 'poisson', True) d = {} cen = Center([det], 'det', motor, 0.1, 1.1, 0.01, d) RE(cen) assert_less(abs(d['center']), 0.1)
def test_timeout(RE): from ophyd.positioner import SoftPositioner from bluesky.examples import SynGauss from ophyd import StatusBase mot = SoftPositioner(name='mot') mot.set(0) det = SynGauss('det', mot, 'mot', 0, 3) def kickoff(): # This process should take a total of 5 seconds, but it will be # interrupted after 0.1 seconds via the timeout keyword passed to # ramp_plan below. yield Msg('null') for j in range(100): RE.loop.call_later(.05 * j, lambda j=j: mot.set(j)) return StatusBase() def inner_plan(): yield from trigger_and_read([det]) g = ramp_plan(kickoff(), mot, inner_plan, period=.01, timeout=.1) start = time.time() with pytest.raises(RampFail): RE(g) stop = time.time() elapsed = stop - start # This test has a tendency to randomly fail, so we're giving it plenty of # time to run. 4, though much greater than 0.1, is still less than 5. assert .1 < elapsed < 4
def test_timeout(RE): from ophyd.positioner import SoftPositioner from bluesky.examples import SynGauss from ophyd import StatusBase mot = SoftPositioner(name='mot') mot.set(0) det = SynGauss('det', mot, 'mot', 0, 3) def kickoff(): yield Msg('null') for j in range(5): RE.loop.call_later(.05 * j, lambda j=j: mot.set(j)) return StatusBase() def inner_plan(): yield from trigger_and_read([det]) g = ramp_plan(kickoff(), mot, inner_plan, period=.01, timeout=.1) start = time.time() with pytest.raises(RampFail): RE(g) stop = time.time() elapsed = stop - start assert .1 < elapsed < .2
def motor_det(request): motor = Mover('motor', {'motor': lambda x: x}, {'x': 0}) det = SynGauss('det', motor, 'motor', center=0, Imax=1, sigma=1, exposure_time=0) return motor, det
def test_center(): try: import lmfit except ImportError: raise SkipTest("requires lmfit") assert_true(not RE._run_is_open) det = SynGauss('det', motor, 'motor', 0, 1000, 1, 'poisson', True) d = {} cen = Center([det], 'det', motor, 0.1, 1.1, 0.01, d) RE(cen) assert_less(abs(d['center']), 0.1)
def test_relative_spiral(fresh_RE): motor = Mover('motor', {'motor': lambda x: x}, {'x': 0}) motor1 = Mover('motor1', {'motor1': lambda x: x}, {'x': 0}) motor2 = Mover('motor2', {'motor2': lambda x: x}, {'x': 0}) det = SynGauss('det', motor, 'motor', center=0, Imax=1, sigma=1) start_x = 1.0 start_y = 1.0 motor1.set(start_x) motor2.set(start_y) scan = RelativeSpiralScan([det], motor1, motor2, 1.0, 1.0, 0.1, 1.0, 0.0) approx_multi_traj_checker(fresh_RE, scan, _get_spiral_data(start_x, start_y), decimal=2)
def test_absolute_spiral(fresh_RE): motor = Mover('motor', {'motor': lambda x: x}, {'x': 0}) motor1 = Mover('motor1', {'motor1': lambda x: x}, {'x': 0}) motor2 = Mover('motor2', {'motor2': lambda x: x}, {'x': 0}) det = SynGauss('det', motor, 'motor', center=0, Imax=1, sigma=1) motor1.set(1.0) motor2.set(1.0) scan = SpiralScan([det], motor1, motor2, 0.0, 0.0, 1.0, 1.0, 0.1, 1.0, 0.0) approx_multi_traj_checker(fresh_RE, scan, _get_spiral_data(0.0, 0.0), decimal=2) scan = SpiralScan([det], motor1, motor2, 0.5, 0.5, 1.0, 1.0, 0.1, 1.0, 0.0) approx_multi_traj_checker(fresh_RE, scan, _get_spiral_data(0.5, 0.5), decimal=2)
def test_ramp(RE, db): from ophyd.positioner import SoftPositioner from ophyd import StatusBase from bluesky.examples import SynGauss tt = SoftPositioner(name='mot') tt.set(0) dd = SynGauss('det', tt, 'mot', 0, 3) st = StatusBase() def kickoff(): yield Msg('null') for j, v in enumerate(np.linspace(-5, 5, 10)): RE.loop.call_later(.1 * j, lambda v=v: tt.set(v)) RE.loop.call_later(1.2, st._finished) return st def inner_plan(): yield from trigger_and_read([dd]) g = ramp_plan(kickoff(), tt, inner_plan, period=0.08) RE.subscribe('all', db.mds.insert) RE.msg_hook = MsgCollector() rs_uid, = RE(g) hdr = db[-1] assert hdr.start.uid == rs_uid assert len(hdr.descriptors) == 2 assert set([d['name'] for d in hdr.descriptors]) == \ set(['primary', 'mot_monitor']) primary_events = list(db.get_events(hdr, stream_name='primary')) assert len(primary_events) > 11 monitor_events = list(db.get_events(hdr, stream_name='mot_monitor')) assert len(monitor_events) == 10
import matplotlib.pyplot as plt from bluesky import RunEngine from bluesky.scans import AdaptiveAscan from bluesky.examples import Mover, SynGauss from bluesky.callbacks import LivePlot, LiveTable from bluesky.tests.utils import setup_test_run_engine #plt.ion() RE = setup_test_run_engine() motor = Mover('motor', ['pos']) det = SynGauss('det', motor, 'pos', center=0, Imax=1, sigma=1) #fig, ax = plt.subplots() #ax.set_xlim([-15, 5]) #ax.set_ylim([0, 2]) # Point the function to our axes above, and specify what to plot. #my_plotter = LivePlot('det', 'pos') table = LiveTable(['det', 'pos']) ad_scan = AdaptiveAscan([det], 'det', motor, -15, 5, .01, 1, .05, True) RE(ad_scan, subscriptions={'all': [table]}) #, my_plotter})
from bluesky.examples import Mover, SynGauss, Syn2DGauss import bluesky.simple_scans as bss import bluesky.spec_api as bsa import bluesky.callbacks from bluesky.standard_config import gs import bluesky.qt_kicker # motors theta = Mover('theta', ['theta']) gamma = Mover('gamma', ['gamma']) # synthetic detectors coupled to one motor theta_det = SynGauss('theta_det', theta, 'theta', center=0, Imax=1, sigma=1) gamma_det = SynGauss('gamma_det', gamma, 'gamma', center=0, Imax=1, sigma=1) # synthetic detector coupled to two detectors tgd = Syn2DGauss('theta_gamma_det', theta, 'theta', gamma, 'gamma', center=(0, 0), Imax=1) # set up the default detectors gs.DETS = [theta_det, gamma_det, tgd] ysteps = 25 xsteps = 20 # hook up the live raster callback