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_table(RE, hw): with _print_redirect() as fout: hw.det.precision = 2 hw.motor.precision = 2 hw.motor.setpoint.put(0.0) # Make dtype 'number' not 'integer'. hw.det.put(0.0) # Make dtype 'number' not 'integer'. assert hw.det.describe()["det"]["precision"] == 2 assert hw.motor.describe()["motor"]["precision"] == 2 assert hw.det.describe()["det"]["dtype"] == "number" assert hw.motor.describe()["motor"]["dtype"] == "number" table = LiveTable(["det", "motor"], min_width=16, extra_pad=2) ad_scan = bp.adaptive_scan([hw.det], "det", hw.motor, -15.0, 5., .01, 1, .05, True) # use lossless sub here because rows can get dropped token = RE.subscribe(table) RE(ad_scan) RE.unsubscribe_lossless(token) fout.seek(0) for ln, kn in zip(fout, KNOWN_TABLE.split("\n")): # this is to strip the `\n` from the print output ln = ln.rstrip() if ln[0] == "+": # test the full line on the divider lines assert ln == kn else: # skip the 'time' column on data rows # this is easier than faking up times in the scan! assert ln[:16] == kn[:16] assert ln[26:] == kn[26:]
def test_table(RE, hw): with _print_redirect() as fout: hw.det.precision = 2 hw.motor.precision = 2 hw.motor.setpoint.put(0.0) # Make dtype 'number' not 'integer'. hw.det.trigger() assert hw.det.describe()['det']['precision'] == 2 assert hw.motor.describe()['motor']['precision'] == 2 assert hw.det.describe()['det']['dtype'] == 'number' assert hw.motor.describe()['motor']['dtype'] == 'number' table = LiveTable(['det', 'motor'], min_width=16, extra_pad=2, separator_lines=False) ad_scan = bp.adaptive_scan([hw.det], 'det', hw.motor, -15.0, 5., .01, 1, .05, True) # use lossless sub here because rows can get dropped token = RE.subscribe(table) RE(ad_scan) RE.unsubscribe_lossless(token) fout.seek(0) _compare_tables(fout, KNOWN_TABLE)
def test_table(RE, hw): with _print_redirect() as fout: hw.det.precision = 2 hw.motor.precision = 2 hw.motor.setpoint.put(0.0) # Make dtype 'number' not 'integer'. hw.det.put(0.0) # Make dtype 'number' not 'integer'. assert hw.det.describe()['det']['precision'] == 2 assert hw.motor.describe()['motor']['precision'] == 2 assert hw.det.describe()['det']['dtype'] == 'number' assert hw.motor.describe()['motor']['dtype'] == 'number' table = LiveTable(['det', 'motor'], min_width=16, extra_pad=2) ad_scan = bp.adaptive_scan([hw.det], 'det', hw.motor, -15.0, 5., .01, 1, .05, True) # use lossless sub here because rows can get dropped token = RE.subscribe(table) RE(ad_scan) RE.unsubscribe_lossless(token) fout.seek(0) for ln, kn in zip(fout, KNOWN_TABLE.split('\n')): # this is to strip the `\n` from the print output ln = ln.rstrip() if ln[0] == '+': # test the full line on the divider lines assert ln == kn else: # skip the 'time' column on data rows # this is easier than faking up times in the scan! assert ln[:16] == kn[:16] assert ln[26:] == kn[26:]
def preFitScan(detectors, motor, alignRange, stepRange, targetDelta): yield from adaptive_scan([detectors], det_name, motor, start = alignRange[0], stop = alignRange[1], min_step = stepRange[0], max_step = stepRange[1], target_delta = targetDelta, backstep = True)
def test_table(RE, hw): with _print_redirect() as fout: hw.det.precision = 2 hw.motor.precision = 2 assert hw.det.describe()['det']['precision'] == 2 assert hw.motor.describe()['motor']['precision'] == 2 table = LiveTable(['det', 'motor'], min_width=16, extra_pad=2) ad_scan = bp.adaptive_scan([hw.det], 'det', hw.motor, -15, 5, .01, 1, .05, True) # use lossless sub here because rows can get dropped token = RE.subscribe(table) RE(ad_scan) RE.unsubscribe_lossless(token) fout.seek(0) for ln, kn in zip(fout, KNOWN_TABLE.split('\n')): # this is to strip the `\n` from the print output ln = ln.rstrip() if ln[0] == '+': # test the full line on the divider lines assert ln == kn else: # skip the 'time' column on data rows # this is easier than faking up times in the scan! assert ln[:16] == kn[:16] assert ln[26:] == kn[26:]
def describe_plans(self): from bluesky import RunEngine import bluesky.plans as bp from bluesky.callbacks.fitting import PeakStats from bact2.ophyd.utils.preprocessors.CounterSink import CounterSink cs = CounterSink(name = "cnt_b_cur", delay = .1) dep = self.DEVICES['booster_current'].cur1.current indep = self.DEVICES['inj_kicker'].offset md = { 'nickname' : 'injection_kicker_scan_adaptive' } start, end = 10.5, 12 min_step = 0.01 max_step = 0.05 min_change = 1 dets = [indep, dep, self.DEVICES['booster_current']] plan = bp.adaptive_scan(dets, dep, indep, start, end, min_step, max_step, min_change, False, md=md) self.PLANS.append(plan) start, end = 11, 11.5 steps = 101 plan2 = bp.scan(dets, indep, start, end, steps) self.PLANS.append(plan2)
def fineScan(detectors, motor, fRange, pts = 50): #Adaptive scan on region localized near peak yield from adaptive_scan([detector], detector_name, motor, start = fRange[0], stop = fRange[1], min_step = fStepRange[0], max_step = fStepRange[1], target_delta = thTargetDelta, backstep = False)
def _gen(self): return adaptive_scan(self.detectors, self.target_field, self.motor, self.start, self.stop, self.min_step, self.max_step, self.target_delta, self.backstep, self.threshold, md=self.md)
from bluesky.callbacks import LivePlot from ophyd.sim import motor, det # Do this if running the example interactively; # skip it when building the documentation. import os if 'BUILDING_DOCS' not in os.environ: from bluesky.utils import install_qt_kicker # for notebooks, qt -> nb install_qt_kicker() plt.ion() det.exposure_time = 0.5 # simulate slow exposures RE = RunEngine({}) RE( adaptive_scan([det], 'det', motor, start=-15, stop=10, min_step=0.01, max_step=5, target_delta=.05, backstep=True), LivePlot('det', 'motor', markersize=10, marker='o')) ############################################################################### # Observe how the scan lengthens its stride through the flat regions, oversteps # through the peak, moves back, samples it with smaller steps, and gradually # adopts a larger stride as the peak flattens out again.
from bluesky.plans import adaptive_scan from bluesky.callbacks import LivePlot from bluesky.examples import motor, det # Adaptive Rocking curve scan using just the neutron counts # (either total or ROI). This will not trigger the ADARA # system - therefore no NeXus file will be created. ## TODO : Update with realistic values for the steps, etc.... RE( adaptive_scan([bs_neutrons_roi], 'bs_neutrons_roi', bs_axis1, start=-15, stop=10, min_step=0.01, max_step=5, target_delta=.05, backstep=True), LivePlot('bs_neutrons_roi', 'bs_axis1', markersize=5, marker='o'))