Extensible Plans

pswalker has quite a few useful plans that may be extensible to other systems besides skywalker.

Scans

pswalker.plans.fitwalk(detectors, motor, models, target, naive_step=None, average=120, filters=None, drop_missing=True, tolerance=10, delay=None, max_steps=10)
Parameters:
  • detectors (list) – List of detectors to read at each step of walk
  • motor (ophyd.Object) – Ophyd object that supports the set and wait. This should have a one to one relationship with the independent variable in the model you plan to optimize
  • models (list) – List of models to evaluate during the walk
  • target (float) – Desired end position for the walk
  • naive_step (bluesky.plan, optional) – Plan to execute when there is not an accurate enough model available. By default this is mv(0.01)
  • average (int, optional) – Number of readings to take and average at each event. Models are allowed to take a subset of each reading and average, however if the two settings will create an average over multiple steps in the walk the LiveBuild.average setting is automatically updated. For example, if the walk is told to average over 10 events, your model can either average over 10, 5, 2, or 1 shots.
  • filters (dict, optional) – Key, callable pairs of event keys and single input functions that evaluate to True or False. For more infromation see apply_filters()
  • drop_missing (bool, optional) – Choice to include events where event keys are missing
  • tolerance (float, optional) – Maximum distance from target considered successful
  • delay (float, optional) – Mininum time between consecutive readings
  • max_steps (int, optional) – Maximum number of steps the scan will attempt before faulting. There is a max of 10 by default, but you may disable this by setting this option to None. Note that this may cause the walk to run indefinitely.
pswalker.plans.walk_to_pixel(detector, motor, target, filters=None, start=None, gradient=None, models=[], target_fields=['centroid_x', 'alpha'], first_step=1.0, tolerance=20, system=None, average=1, delay=None, max_steps=None, drop_missing=True)

Step a motor until a specific threshold is reached on the detector

This function assumes a linear relationship between the position of the given motor and the position on the YAG. While at the onset of the plan, we don’t know anything about the physical setup of the system, we can track the steps as they happen and use our prior attempts to inform future ones.

The first step of the plan makes a move out into the unknown parameter space of the model. Using the two data points of the initial centroid and the result of our first step we can form a coarse model by simply drawing a line through each point. A new step is calculated based on this rudimentary model, and the centroid is measured again now at a third point. As we gather more data points on successive attempts at alignment our linear fit improves. The iteration stops when the algorithm has centered the beam within the specified tolerance.

There are ways to seed the walk with the known information to make the first step the algorithm takes more fruitful. The most naive is to give it a logical first step size that will keep the object you are trying to center within the image. However, in some cases we may know enough to have a reasonable first guess at the relationship between pitch and centroid. In this case the algorithm accepts the gradient parameter that is then used to calculate the optimal first step.

Parameters:
  • detector (BeamDetector) – YAG to make measure beam centroid
  • motor (FlatMirror) – Mirror to adjust pitch mechanism
  • target (int) – Target pixel for beam centroid
  • start (float) – Starting position for pitch mechanism
  • first_step (float, optional) – Initial step to attempt
  • gradient (float, optional) – Assume an initial gradient for the relationship between pitch and beam center
  • target_fields (iterable, optional) – (detector, motor) fields to average and calculate line of best fit
  • models (list, optional) – Additional models to include in the fitwalk()
  • system (list, optional) – Extra detectors to include in the datastream as we measure the average
  • tolerance (int, optional) – Number of pixels the final centroid position is allowed to differ from the target
  • average (int, optional) – Number of images to average together for each step along the scan
  • max_steps (int, optional) – Limit the number of steps the walk will take before exiting

Measurements

pswalker.plans.measure(detectors, num=1, delay=None, filters=None, drop_missing=True, max_dropped=50)

Gather a fixed number of measurements from a group of detectors

Parameters:
  • detectors (list) – List of detector objects to read and bundle
  • num (int) – Number of measurements that pass filters
  • delay (float) – Minimum time between consecutive reads of the detectors.
  • filters (dict, optional) – Key, callable pairs of event keys and single input functions that evaluate to True or False. For more infromation see apply_filters()
  • drop_missing (bool, optional) – Choice to include events where event keys are missing
  • max_dropped (int, optional) – Maximum number of events to drop before raising a ValueError
Returns:

data – List of mock-event documents

Return type:

list

pswalker.plans.measure_average(detectors, num=1, filters=None, delay=None, drop_missing=True)

Gather a series of measurements from a list of detectors and return the average over the number of shots. :param detectors: List of detectors to measure at each event :type detectors: list :param num: Number of samples to average together for each step along the scan :type num: int, optional :param delay: Time delay between successive readings :type delay: iterable or scalar, optional

Returns:average – A dictionary of all the measurements taken from the supplied detectors averaged over num shots. In the event that a field is a string, or can not be averaged the last shot is returned
Return type:dict

See also

measure()