def test_tune_centroid(RE, hw): det = hw.det motor = hw.motor scan1 = bp.tune_centroid([det], 'det', motor, 0, 5, 0.1, 10, snake=True) scan2 = bp.tune_centroid([det], 'det', motor, 0, 5, 0.01, 10, snake=True) scan3 = bp.tune_centroid([det], 'det', motor, 0, 5, 0.1, 10, snake=False) scan4 = bp.tune_centroid([det], 'det', motor, 5, 0, 0.1, 10, snake=False) actual_traj = [] col = collector('motor', actual_traj) counter1 = CallbackCounter() counter2 = CallbackCounter() RE(scan1, {'event': [col, counter1]}) RE(scan2, {'event': counter2}) #assert counter1.value > counter2.value assert actual_traj[0] == 0 actual_traj = [] col = collector('motor', actual_traj) RE(scan3, {'event': col}) monotonic_increasing = np.all(np.diff(actual_traj) > 0) assert not monotonic_increasing actual_traj = [] col = collector('motor', actual_traj) RE(scan4, {'event': col}) monotonic_decreasing = np.all(np.diff(actual_traj) < 0) assert not monotonic_decreasing with pytest.raises(ValueError): # min step < 0 scan5 = bp.tune_centroid([det], 'det', motor, 5, 0, -0.1, 10, snake=False) RE(scan5)
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_adaptive_ascan(RE, hw): scan1 = bp.adaptive_scan([hw.det], 'det', hw.motor, 0, 5, 0.1, 1, 0.1, True) scan2 = bp.adaptive_scan([hw.det], 'det', hw.motor, 0, 5, 0.1, 1, 0.2, True) scan3 = bp.adaptive_scan([hw.det], 'det', hw.motor, 0, 5, 0.1, 1, 0.1, False) scan4 = bp.adaptive_scan([hw.det], 'det', hw.motor, 5, 0, 0.1, 1, 0.1, False) actual_traj = [] col = collector('motor', actual_traj) counter1 = CallbackCounter() counter2 = CallbackCounter() RE(scan1, {'event': [col, counter1]}) RE(scan2, {'event': counter2}) assert counter1.value > counter2.value assert actual_traj[0] == 0 actual_traj = [] col = collector('motor', actual_traj) RE(scan3, {'event': col}) monotonic_increasing = np.all(np.diff(actual_traj) > 0) assert monotonic_increasing actual_traj = [] col = collector('motor', actual_traj) RE(scan4, {'event': col}) monotonic_decreasing = np.all(np.diff(actual_traj) < 0) assert monotonic_decreasing with pytest.raises(ValueError): # min step < 0 scan5 = bp.adaptive_scan([hw.det], 'det', hw.motor, 5, 0, -0.1, 1.0, 0.1, False) RE(scan5)
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_count(RE, hw): det = hw.det motor = hw.motor actual_intensity = [] col = collector('det', actual_intensity) motor.set(0) plan = bp.count([det]) RE(plan, {'event': col}) assert actual_intensity[0] == 1. # multiple counts, via updating attribute actual_intensity = [] col = collector('det', actual_intensity) plan = bp.count([det], num=3, delay=0.05) RE(plan, {'event': col}) assert actual_intensity == [1., 1., 1.]
def test_ami_scan(ami_det, RE): logger.debug('test_ami_scan') ami_det.min_duration = 1 ami_det.filter_string = '4<x<5' mean_list = [] coll = collector(ami_det.mean.name, mean_list) num = 5 RE(count([ami_det], num=num), {'event': coll}) assert len(mean_list) == num
def test_adaptive_ascan(): scan1 = AdaptiveAbsScan([det], 'det', motor, 0, 5, 0.1, 1, 0.1, True) scan2 = AdaptiveAbsScan([det], 'det', motor, 0, 5, 0.1, 1, 0.2, True) scan3 = AdaptiveAbsScan([det], 'det', motor, 0, 5, 0.1, 1, 0.1, False) actual_traj = [] col = collector('motor', actual_traj) counter1 = CallbackCounter() counter2 = CallbackCounter() RE(scan1, subs={'event': [col, counter1]}) RE(scan2, subs={'event': counter2}) assert_greater(counter1.value, counter2.value) assert_equal(actual_traj[0], 0) 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_adaptive_dscan(): scan1 = AdaptiveDeltaScanPlan([det], 'det', motor, 0, 5, 0.1, 1, 0.1, True) scan2 = AdaptiveDeltaScanPlan([det], 'det', motor, 0, 5, 0.1, 1, 0.2, True) scan3 = AdaptiveDeltaScanPlan([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 counter1.value > counter2.value assert 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 monotonic_increasing
def traj_checker(RE, scan, expected_traj): actual_traj = [] callback = collector('motor', actual_traj) RE(scan, {'event': callback}) assert actual_traj == list(expected_traj)
def traj_checker(scan, expected_traj): actual_traj = [] callback = collector('motor', actual_traj) RE(scan, subs={'event': callback}) assert_equal(actual_traj, list(expected_traj))
def test_xrun_with_xpdAcqPlans(self): exp = 5 # test with ct msg_list = [] def msg_rv(msg): msg_list.append(msg) self.xrun.msg_hook = msg_rv self.xrun({}, ScanPlan(self.bt, ct, exp)) open_run = [ el.kwargs for el in msg_list if el.command == "open_run" ].pop() self.assertEqual(open_run["sp_type"], "ct") self.assertEqual(open_run["sp_requested_exposure"], exp) # test with Tramp Tstart, Tstop, Tstep = 300, 200, 10 msg_list = [] def msg_rv(msg): msg_list.append(msg) self.xrun.msg_hook = msg_rv traj_list = [] # courtesy of bluesky test temp_controller = xpd_configuration["temp_controller"] callback = collector(temp_controller.readback.name, traj_list) self.xrun( {}, ScanPlan(self.bt, Tramp, exp, Tstart, Tstop, Tstep), subs={"event": callback}, ) # verify trajectory Num, diff = _nstep(Tstart, Tstop, Tstep) expected_traj = np.linspace(Tstart, Tstop, Num) assert np.all(traj_list == expected_traj) # verify md open_run = [ el.kwargs for el in msg_list if el.command == "open_run" ].pop() self.assertEqual(open_run["sp_type"], "Tramp") self.assertEqual(open_run["sp_requested_exposure"], exp) self.assertEqual(open_run["sp_startingT"], Tstart) self.assertEqual(open_run["sp_endingT"], Tstop) self.assertEqual(open_run["sp_requested_Tstep"], Tstep) # test with tseries delay, num = 0.1, 5 msg_list = [] def msg_rv(msg): msg_list.append(msg) self.xrun.msg_hook = msg_rv self.xrun({}, ScanPlan(self.bt, tseries, exp, delay, num)) open_run = [ el.kwargs for el in msg_list if el.command == "open_run" ].pop() self.assertEqual(open_run["sp_type"], "tseries") self.assertEqual(open_run["sp_requested_exposure"], exp) self.assertEqual(open_run["sp_requested_delay"], delay) self.assertEqual(open_run["sp_requested_num"], num) # test with Tlist T_list = [300, 256, 128] msg_list = [] def msg_rv(msg): msg_list.append(msg) traj_list = [] # courtesy of bluesky test temp_controller = xpd_configuration["temp_controller"] callback = collector(temp_controller.readback.name, traj_list) self.xrun.msg_hook = msg_rv self.xrun( {}, ScanPlan(self.bt, Tlist, exp, T_list), subs={"event": callback} ) # verify trajectory assert T_list == traj_list # verify md open_run = [ el.kwargs for el in msg_list if el.command == "open_run" ].pop() self.assertEqual(open_run["sp_type"], "Tlist") self.assertEqual(open_run["sp_requested_exposure"], exp) self.assertEqual(open_run["sp_T_list"], T_list)