def test_outer_product_dscan_snaked(): scan = OuterProductDeltaScan([det], motor1, 1, 3, 3, motor2, 10, 20, 2, True) # Note: motor1 is the first motor specified, and so it is the "slow" # axis, matching the numpy convention. motor.set(0) motor1.set(5) motor2.set(8) expected_data = [{ 'motor2': 18.0, 'det': 1.0, 'motor1': 6.0 }, { 'motor2': 28.0, 'det': 1.0, 'motor1': 6.0 }, { 'motor2': 28.0, 'det': 1.0, 'motor1': 7.0 }, { 'motor2': 18.0, 'det': 1.0, 'motor1': 7.0 }, { 'motor2': 18.0, 'det': 1.0, 'motor1': 8.0 }, { 'motor2': 28.0, 'det': 1.0, 'motor1': 8.0 }] yield multi_traj_checker, scan, expected_data
def test_count(): actual_intensity = [] col = collector('det', actual_intensity) motor.set(0) scan = Count([det]) RE(scan, subs={'event': col}) assert actual_intensity[0] == 1. # multiple counts, via updating attribute actual_intensity = [] col = collector('det', actual_intensity) scan = Count([det], num=3, delay=0.05) RE(scan, subs={'event': col}) assert scan.num == 3 assert actual_intensity == [1., 1., 1.] # multiple counts, via passing arts to __call__ actual_intensity = [] col = collector('det', actual_intensity) scan = Count([det], num=3, delay=0.05) RE(scan(num=2), subs={'event': col}) assert actual_intensity == [1., 1.] # attribute should still be 3 assert scan.num == 3 actual_intensity = [] col = collector('det', actual_intensity) RE(scan, subs={'event': col}) assert actual_intensity == [1., 1., 1.]
def test_outer_product_ascan_snaked(): motor.set(0) scan = OuterProductAbsScanPlan([det], motor1, 1, 3, 3, motor2, 10, 20, 2, True) # Note: motor1 is the first motor specified, and so it is the "slow" # axis, matching the numpy convention. expected_data = [{ 'motor2': 10.0, 'det': 1.0, 'motor1': 1.0 }, { 'motor2': 20.0, 'det': 1.0, 'motor1': 1.0 }, { 'motor2': 20.0, 'det': 1.0, 'motor1': 2.0 }, { 'motor2': 10.0, 'det': 1.0, 'motor1': 2.0 }, { 'motor2': 10.0, 'det': 1.0, 'motor1': 3.0 }, { 'motor2': 20.0, 'det': 1.0, 'motor1': 3.0 }] for d in expected_data: d.update({'motor1_setpoint': d['motor1']}) d.update({'motor2_setpoint': d['motor2']}) multi_traj_checker(scan, expected_data)
def test_outer_product_ascan_snaked(): motor.set(0) scan = OuterProductAbsScan([det], motor1, 1, 3, 3, motor2, 10, 20, 2, True) # Note: motor1 is the first motor specified, and so it is the "slow" # axis, matching the numpy convention. expected_data = [{ 'motor2': 10.0, 'det': 1.0, 'motor1': 1.0 }, { 'motor2': 20.0, 'det': 1.0, 'motor1': 1.0 }, { 'motor2': 20.0, 'det': 1.0, 'motor1': 2.0 }, { 'motor2': 10.0, 'det': 1.0, 'motor1': 2.0 }, { 'motor2': 10.0, 'det': 1.0, 'motor1': 3.0 }, { 'motor2': 20.0, 'det': 1.0, 'motor1': 3.0 }] yield multi_traj_checker, scan, expected_data
def test_reset_positions_no_position_attr(fresh_RE): motor = DummyMover('motor') motor.set(5) msgs = [] def accumulator(msg): msgs.append(msg) fresh_RE.msg_hook = accumulator def plan(): yield from (m for m in [Msg('set', motor, 8)]) fresh_RE(reset_positions_wrapper(plan())) expected = [ Msg('read', motor), Msg('set', motor, 8), Msg('set', motor, 5), Msg('wait') ] for msg in msgs: msg.kwargs.pop('group', None) assert msgs == expected
def test_inner_product_ascan(): motor.set(0) scan = InnerProductAbsScan([det], 3, motor1, 1, 3, motor2, 10, 30) # Note: motor1 is the first motor specified, and so it is the "slow" # axis, matching the numpy convention. expected_data = [ {'motor2': 10.0, 'det': 1.0, 'motor1': 1.0}, {'motor2': 20.0, 'det': 1.0, 'motor1': 2.0}, {'motor2': 30.0, 'det': 1.0, 'motor1': 3.0}] yield multi_traj_checker, scan, expected_data
def test_inner_product_dscan(): motor.set(0) motor1.set(5) motor2.set(8) scan = InnerProductDeltaScan([det], 3, motor1, 1, 3, motor2, 10, 30) # Note: motor1 is the first motor specified, and so it is the "slow" # axis, matching the numpy convention. expected_data = [ {'motor2': 18.0, 'det': 1.0, 'motor1': 6.0}, {'motor2': 28.0, 'det': 1.0, 'motor1': 7.0}, {'motor2': 38.0, 'det': 1.0, 'motor1': 8.0}] yield multi_traj_checker, scan, expected_data
def test_outer_product_ascan_snaked(): motor.set(0) scan = OuterProductAbsScanPlan([det], motor1, 1, 3, 3, motor2, 10, 20, 2, True) # Note: motor1 is the first motor specified, and so it is the "slow" # axis, matching the numpy convention. expected_data = [ {'motor2': 10.0, 'det': 1.0, 'motor1': 1.0}, {'motor2': 20.0, 'det': 1.0, 'motor1': 1.0}, {'motor2': 20.0, 'det': 1.0, 'motor1': 2.0}, {'motor2': 10.0, 'det': 1.0, 'motor1': 2.0}, {'motor2': 10.0, 'det': 1.0, 'motor1': 3.0}, {'motor2': 20.0, 'det': 1.0, 'motor1': 3.0}] multi_traj_checker(scan, expected_data)
def test_inner_product_ascan(): motor.set(0) scan = InnerProductAbsScanPlan([det], 3, motor1, 1, 3, motor2, 10, 30) # Note: motor1 is the first motor specified, and so it is the "slow" # axis, matching the numpy convention. expected_data = [ {'motor2': 10.0, 'det': 1.0, 'motor1': 1.0}, {'motor2': 20.0, 'det': 1.0, 'motor1': 2.0}, {'motor2': 30.0, 'det': 1.0, 'motor1': 3.0}] for d in expected_data: d.update({'motor1_setpoint': d['motor1']}) d.update({'motor2_setpoint': d['motor2']}) multi_traj_checker(scan, expected_data)
def test_count(): actual_intensity = [] col = collector('det', actual_intensity) motor.set(0) scan = Count([det]) RE(scan, subs={'event': col}) assert_equal(actual_intensity[0], 1.) # multiple counts actual_intensity = [] col = collector('det', actual_intensity) scan = Count([det], num=3, delay=0.05) RE(scan, subs={'event': col}) assert_equal(scan.num, 3) assert_equal(actual_intensity, [1., 1., 1.])
def test_outer_product_dscan_snaked(): scan = OuterProductDeltaScanPlan([det], motor1, 1, 3, 3, motor2, 10, 20, 2, True) # Note: motor1 is the first motor specified, and so it is the "slow" # axis, matching the numpy convention. motor.set(0) motor1.set(5) motor2.set(8) expected_data = [ {'motor2': 18.0, 'det': 1.0, 'motor1': 6.0}, {'motor2': 28.0, 'det': 1.0, 'motor1': 6.0}, {'motor2': 28.0, 'det': 1.0, 'motor1': 7.0}, {'motor2': 18.0, 'det': 1.0, 'motor1': 7.0}, {'motor2': 18.0, 'det': 1.0, 'motor1': 8.0}, {'motor2': 28.0, 'det': 1.0, 'motor1': 8.0}] multi_traj_checker(scan, expected_data)
def test_outer_product_dscan(): scan = OuterProductDeltaScanPlan([det], motor1, 1, 3, 3, motor2, 10, 20, 2, False) # Note: motor1 is the first motor specified, and so it is the "slow" # axis, matching the numpy convention. motor.set(0) motor1.set(5) motor2.set(8) expected_data = [ {'motor2': 18.0, 'det': 1.0, 'motor1': 6.0}, {'motor2': 28.0, 'det': 1.0, 'motor1': 6.0}, {'motor2': 18.0, 'det': 1.0, 'motor1': 7.0}, {'motor2': 28.0, 'det': 1.0, 'motor1': 7.0}, {'motor2': 18.0, 'det': 1.0, 'motor1': 8.0}, {'motor2': 28.0, 'det': 1.0, 'motor1': 8.0}] for d in expected_data: d.update({'motor1_setpoint': d['motor1']}) d.update({'motor2_setpoint': d['motor2']}) multi_traj_checker(scan, expected_data)
def test_adaptive_dscan(): scan1 = AdaptiveDeltaScan([det], 'det', motor, 0, 5, 0.1, 1, 0.1, True) scan2 = AdaptiveDeltaScan([det], 'det', motor, 0, 5, 0.1, 1, 0.2, True) scan3 = AdaptiveDeltaScan([det], 'det', motor, 0, 5, 0.1, 1, 0.1, False) actual_traj = [] col = collector('motor', actual_traj) counter1 = CallbackCounter() counter2 = CallbackCounter() motor.set(1) RE(scan1, subs={'event': [col, counter1]}) RE(scan2, subs={'event': counter2}) assert_greater(counter1.value, counter2.value) assert_equal(actual_traj[0], 1) actual_traj = [] col = collector('motor', actual_traj) RE(scan3, {'event': col}) monotonic_increasing = np.all(np.diff(actual_traj) > 0) assert_true(monotonic_increasing)
def test_relative_set_no_position_attr(fresh_RE): motor = DummyMover("motor") motor.set(5) msgs = [] def accumulator(msg): msgs.append(msg) fresh_RE.msg_hook = accumulator def plan(): yield from (m for m in [Msg("set", motor, 8)]) fresh_RE(relative_set_wrapper(plan())) expected = [Msg("read", motor), Msg("set", motor, 13)] for msg in msgs: msg.kwargs.pop("group", None) assert msgs == expected
def test_relative_set(fresh_RE): motor = Mover("a", {"a": lambda x: x}, {"x": 0}) motor.set(5) msgs = [] def accumulator(msg): msgs.append(msg) fresh_RE.msg_hook = accumulator def plan(): yield from (m for m in [Msg("set", motor, 8)]) fresh_RE(relative_set_wrapper(plan())) expected = [Msg("set", motor, 13)] for msg in msgs: msg.kwargs.pop("group", None) assert msgs == expected
def test_reset_positions(fresh_RE): motor = Mover('a', {'a': lambda x: x}, {'x': 0}) motor.set(5) msgs = [] def accumulator(msg): msgs.append(msg) fresh_RE.msg_hook = accumulator def plan(): yield from (m for m in [Msg('set', motor, 8)]) fresh_RE(reset_positions_wrapper(plan())) expected = [Msg('set', motor, 8), Msg('set', motor, 5), Msg('wait')] for msg in msgs: msg.kwargs.pop('group', None) assert msgs == expected
def test_relative_set(fresh_RE): motor = Mover('a', {'a': lambda x: x}, {'x': 0}) motor.set(5) msgs = [] def accumulator(msg): msgs.append(msg) fresh_RE.msg_hook = accumulator def plan(): yield from (m for m in [Msg('set', motor, 8)]) fresh_RE(relative_set_wrapper(plan())) expected = [Msg('set', motor, 13)] for msg in msgs: msg.kwargs.pop('group', None) assert msgs == expected
def test_reset_positions_no_position_attr(fresh_RE): motor = DummyMover('motor') motor.set(5) msgs = [] def accumulator(msg): msgs.append(msg) fresh_RE.msg_hook = accumulator def plan(): yield from (m for m in [Msg('set', motor, 8)]) fresh_RE(reset_positions_wrapper(plan())) expected = [Msg('read', motor), Msg('set', motor, 8), Msg('set', motor, 5), Msg('wait')] for msg in msgs: msg.kwargs.pop('group', None) assert msgs == expected
def test_outer_product_dscan(): scan = OuterProductDeltaScanPlan([det], motor1, 1, 3, 3, motor2, 10, 20, 2, False) # Note: motor1 is the first motor specified, and so it is the "slow" # axis, matching the numpy convention. motor.set(0) motor1.set(5) motor2.set(8) expected_data = [{ 'motor2': 18.0, 'det': 1.0, 'motor1': 6.0 }, { 'motor2': 28.0, 'det': 1.0, 'motor1': 6.0 }, { 'motor2': 18.0, 'det': 1.0, 'motor1': 7.0 }, { 'motor2': 28.0, 'det': 1.0, 'motor1': 7.0 }, { 'motor2': 18.0, 'det': 1.0, 'motor1': 8.0 }, { 'motor2': 28.0, 'det': 1.0, 'motor1': 8.0 }] for d in expected_data: d.update({'motor1_setpoint': d['motor1']}) d.update({'motor2_setpoint': d['motor2']}) multi_traj_checker(scan, expected_data)
def test_lin_dscan(): traj = np.linspace(0, 10, 5) + 6 motor.set(6) scan = DeltaScanPlan([det], motor, 0, 10, 5) traj_checker(scan, traj)
def test_log_dscan(): traj = np.logspace(0, 10, 5) + 6 motor.set(6) scan = LogDeltaScan([det], motor, 0, 10, 5) yield traj_checker, scan, traj
def test_dscan(): traj = np.array([1, 2, 3]) motor.set(-4) scan = DeltaListScan([det], motor, traj) yield traj_checker, scan, traj - 4
def test_dscan(): traj = np.array([1, 2, 3]) motor.set(-4) print(motor.read()) scan = DeltaListScanPlan([det], motor, traj) traj_checker(scan, traj - 4)
def test_dscan_list_input(): # GH225 traj = [1, 2, 3] motor.set(-4) scan = DeltaListScanPlan([det], motor, traj) traj_checker(scan, np.array(traj) - 4)
def test_dscan_list_input(): # GH225 traj = [1, 2, 3] motor.set(-4) scan = DeltaListScan([det], motor, traj) yield traj_checker, scan, np.array(traj) - 4