Skip to content

Commit 3fc14dd

Browse files
committed
Try adding generic plan for energy scan
1 parent b0e9160 commit 3fc14dd

File tree

1 file changed

+52
-1
lines changed

1 file changed

+52
-1
lines changed

startup/49-ESM_monochromator.py

Lines changed: 52 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
import IPython
2+
import functools
23
import numpy as np
34
import pandas as pd
45
import matplotlib.pyplot as plt
56
from scipy.interpolate import interp1d
67
import scipy.optimize as opt
78
import os
89
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
1012
from bluesky.preprocessors import baseline_decorator, subs_decorator
1113
# from bluesky.callbacks import LiveTable,LivePlot, CallbackBase
1214
#from pyOlog.SimpleOlogClient import SimpleOlogClient
@@ -832,3 +834,52 @@ def scan_energy(detectors, energies, grating='800', branch='A', EPU='57', LP='LH
832834
yield from count(detectors)
833835

834836

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

Comments
 (0)