Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

walk_to_pixel #6

Open
teddyrendahl opened this issue Apr 13, 2018 · 0 comments
Open

walk_to_pixel #6

teddyrendahl opened this issue Apr 13, 2018 · 0 comments
Labels
enhancement New feature or request
Milestone

Comments

@teddyrendahl
Copy link
Contributor

Description

This is really just a call of fitwalk. Specify a detector, motor an lmfit.Model that describes the relationship between the motor and the detector. Have our motor walk to target using the model as a guide.

def 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
        :attr:`.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
        :meth:`.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.
    """

def walk_to_pixel(detector, motor, target, filters=None,
                  start=None, gradient=None, models=[],
                  target_fields=['centroid_x', 'alpha'],
                  first_step=1., 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 : :class:`.BeamDetector`
        YAG to make measure beam centroid
    motor : :class:`.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 :func:`.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
    """
@teddyrendahl teddyrendahl added the enhancement New feature or request label Apr 13, 2018
@teddyrendahl teddyrendahl added this to the HXRSnD milestone Apr 13, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant