|
1 | 1 | import IPython |
| 2 | +import functools |
2 | 3 | import numpy as np |
3 | 4 | import pandas as pd |
4 | 5 | import matplotlib.pyplot as plt |
5 | 6 | from scipy.interpolate import interp1d |
6 | 7 | import scipy.optimize as opt |
7 | 8 | import os |
8 | 9 | from bluesky.plans import count, scan, adaptive_scan, spiral_fermat, spiral,scan_nd |
9 | | -from bluesky.plan_stubs import abs_set, mv |
| 10 | +from bluesky.plan_stubs import abs_set, mv, trigger_and_read |
| 11 | +from bluesky.utils import short_uid, Msg |
10 | 12 | from bluesky.preprocessors import baseline_decorator, subs_decorator |
11 | 13 | # from bluesky.callbacks import LiveTable,LivePlot, CallbackBase |
12 | 14 | #from pyOlog.SimpleOlogClient import SimpleOlogClient |
@@ -832,3 +834,52 @@ def scan_energy(detectors, energies, grating='800', branch='A', EPU='57', LP='LH |
832 | 834 | yield from count(detectors) |
833 | 835 |
|
834 | 836 |
|
| 837 | +def move_per_step_with_energy(step, pos_cache, grating="800", branch="A", EPU="57", LP="LH", c="constant", shutter="close"): |
| 838 | + """Move per step that allows for energy moves (which require a custom move_to function)""" |
| 839 | + yield Msg("checkpoint") |
| 840 | + grp = short_uid("set") |
| 841 | + for device, pos in pos_cache.items(): |
| 842 | + if pos == pos_cache[device]: |
| 843 | + continue |
| 844 | + if isinstance(device, ESM_monochromator_device): |
| 845 | + yield from device.move_to(pos, grating=grating, branch=branch, EPU=EPU, LP=LP, c=c, shutter=shutter) |
| 846 | + else: |
| 847 | + yield Msg("set", device, pos, group=grp) |
| 848 | + yield Msg("wait", None, group=grp) |
| 849 | + |
| 850 | + |
| 851 | +def one_nd_step_with_energy(detectors, step, pos_cache, take_reading=None, grating="800", branch="A", EPU="57", LP="LH", c="constant", shutter="close"): |
| 852 | + """One ND step with possible energy move""" |
| 853 | + take_reading = trigger_and_read if take_reading is None else take_reading |
| 854 | + motors = [device for device in pos_cache.keys() if not isinstance(device, ESM_monochromator_device)] |
| 855 | + yield from move_per_step_with_energy(step, pos_cache, grating=grating, branch=branch, EPU=EPU, LP=LP, c=c, shutter=shutter) |
| 856 | + yield from take_reading(list(detectors) + list(motors)) |
| 857 | + |
| 858 | + |
| 859 | +def run_with_energy(plan, detectors, *args, grating="800", branch="A", EPU="57", LP="LH", c="constant", shutter="close", **kwargs): |
| 860 | + """ |
| 861 | + Run a plan with possible energy moves. |
| 862 | +
|
| 863 | + Parameters |
| 864 | + ---------- |
| 865 | + plan : Generator |
| 866 | + The plan to run. Must have a per_step argument. |
| 867 | + detectors : list |
| 868 | + The detectors to read. |
| 869 | + *args : list |
| 870 | + The arguments to pass to the plan. Typically a list of motor or energy positions to scan over. |
| 871 | + **kwargs : dict |
| 872 | + The keyword arguments to pass to the plan. |
| 873 | + |
| 874 | + Examples |
| 875 | + -------- |
| 876 | + Scan over energy from 280 to 300 in 100 steps. |
| 877 | + >>> from bluesky.plans import scan |
| 878 | + >>> RE(run_with_energy(scan, [mbs], Eph, 280, 300, num=100)) |
| 879 | +
|
| 880 | + 3D grid scan over energy from 280 to 300 in 100 steps, LT.X and LT.Y from 0 to 5 in 10 steps each. |
| 881 | + >>> from bluesky.plans import grid_scan |
| 882 | + >>> RE(run_with_energy(grid_scan, [mbs], Eph, 280, 300, 100, LT.X, 0, 5, 10, LT.Y, 0, 5, 10, snake_axes=False)) |
| 883 | + """ |
| 884 | + per_step = functools.partial(one_nd_step_with_energy, grating=grating, branch=branch, EPU=EPU, LP=LP, c=c, shutter=shutter) |
| 885 | + yield from plan(detectors, *args, per_step=per_step, **kwargs) |
0 commit comments