Processes

Scanning

concert.processes.scan(param, feedback, minimum=None, maximum=None, intervals=64, convert=<function <lambda> at 0x7f3919920f50>)

Scan the parameter object in intervals steps between minimum and maximum and call feedback at each step. If minimum or maximum is None, ParameterValue.lower or ParameterValue.upper is used.

Set convert to a callable that transforms the parameter value prior to setting it.

Generates futures which resolve to tuples containing the set and feedback values (x, y).

concert.processes.ascan(param_list, n_intervals, handler, initial_values=None)

For each of the n_intervals and for each of the (parameter, start, stop) tuples in param_list, calculate a set value from (stop - start) / n_intervals and set parameter to it:

ascan([(motor['position'], 0 * q.mm, 2 * q.mm)], 5, handler)

When all devices have reached the set point handler is called with a list of the parameters as its first argument.

If initial_values is given, it must be a list with the same length as devices containing start values from where each device is scanned.

concert.processes.dscan(parameter_list, n_intervals, handler)

For each of the n_intervals and for each of the (parameter, start, stop) tuples in param_list, calculate a set value from (stop - start) / n_intervals and set parameter.

concert.processes.scan_param_feedback(scan_param, feedback_param, minimum=None, maximum=None, intervals=64, convert=<function <lambda> at 0x7f391992b0c8>)

Convenience function to scan one parameter and measure another.

Scan the scan_param object and measure feedback_param at each of the intervals steps between minimum and maximum.

Returns a tuple (x, y) with scanned parameter and measured values.

Focusing

concert.processes.focus()

Alignment

concert.processes.align_rotation_axis(*args, **kwargs)
concert.processes.center_to_beam(*args, **kwargs)

Tries to center the camera cam to the beam by moving with the motors xmotor and zmotor. It starts by searching the beam inside the search-area defined by xborder and zborder. Argument pixelsize is needed to convert pixelcoordinates into realworld-coordinates of the motors. Exceptions are raised on fail.

Optional arguments xstep, zstep, thres, tolerance and max_iterations are passed to the functions ‘find_beam(...)’ and ‘center2beam(...)’.

concert.processes.drift_to_beam(cam, xmotor, zmotor, pixelsize, tolerance=5, max_iterations=100)

Moves the camera cam with motors xmotor and zmotor until the center of mass is nearer than tolerance-pixels to the center of the frame or max_iterations is reached.

To convert pixelcoordinates to realworld-coordinates of the motors the pixelsize (scalar or 2-element array-like, e.g. [4*q.um, 5*q.um]) is needed.

concert.processes.find_beam()

Coroutines

concert.coroutines.base.broadcast(*consumers)

Forward data to all consumers.

concert.coroutines.base.coroutine(func)

Start a coroutine automatically without the need to call next() or send(None) first.

concert.coroutines.base.inject(generator, consumer)

Let a generator produce a value and forward it to consumer.

Sinks

class concert.coroutines.sinks.Accumulate

Accumulate items in a list.

class concert.coroutines.sinks.Result

The object is callable and when called it becomes a coroutine which accepts items and stores them in a variable which allows the user to obtain the last stored item at any time point.

concert.coroutines.sinks.null()

A black-hole.

Filters

class concert.coroutines.filters.PickSlice(index)

Pick a slice from a 3D volume.

class concert.coroutines.filters.Timer

Timer object measures execution times of coroutine-based workflows. It measures the time from when this object receives data until all the subsequent stages finish, e.g.:

acquire(timer(process()))

would measure only the time of process, no matter how complicated it is and whether it invokes subsequent coroutines. Everything what happens in process is taken into account. This timer does not treat asynchronous operations in a special way, i.e. if you use it like this:

def long_but_async_operation():
    @async
    def process(data):
        long_op(data)

    while True:
        item = yield
        process(item)

timer(long_but_async_operation())

the time you truly measure is only the time to forward the data to long_but_async_operation and the time to start the asynchronous operation (e.g. spawning a thread).

duration

All iterations summed up.

mean

Mean iteration execution time.

reset()

Reset the timer.

concert.coroutines.filters.absorptivity(consumer)

Get the absorptivity from a flat corrected stream of images. The intensity after the object is defined as \(I = I_0 \cdot e^{-\mu t}\) and we extract the absorptivity \(\mu t\) from the stream of flat corrected images \(I / I_0\).

concert.coroutines.filters.average_images(consumer)

Average images as they come and send them to consumer.

concert.coroutines.filters.backproject(center, consumer)

Filtered backprojection filter. The filter receives a sinogram, filters it and based on center of rotation it backprojects it. The slice is then sent to consumer.

concert.coroutines.filters.downsize(consumer, x_slice=None, y_slice=None, z_slice=None)

Downsize images in 3D and send them to consumer. Every argument is either a tuple (start, stop, step). x_slice operates on image width, y_slice on its height and z_slice on the incoming images, i.e. it creates the third time dimension.

Note: the start index is included in the data and the stop index is excluded.

concert.coroutines.filters.flat_correct(flat, consumer, dark=None)

Flat correcting corounte, which takes a flat field, a dark field (if given), calculates a flat corrected radiograph and forwards it to consumer.

concert.coroutines.filters.queue(consumer)

Store the incoming data in a queue and dispatch in a separate thread which prevents the stalling on the “main” data stream.

concert.coroutines.filters.sinograms(num_radiographs, consumer, sinograms_volume=None)

Convert num_radiographs into sinograms and send them to consumer. The sinograms are sent every time a new radiograph arrives. If there is more than num_radiographs radiographs, the sinograms are rewritten in a ring-buffer fashion. If sinograms_volume is given, it must be a 3D array and it is used to store the sinograms.

concert.coroutines.filters.stall(consumer, per_shot=10, flush_at=None)

Send items once enough is collected. Collect per_shot items and send them to consumer. The incoming data might represent a collection of some kind. If the last item is supposed to be sent regardless the current number of collected items, use flush_at by which you specify the collection size and every time the current item counter % flush_at == 0 the item is sent.

Optimization

Optimization is a procedure to iteratively find the best possible match to

\[y = f(x).\]

This module provides execution routines and algorithms for optimization.

concert.optimization.bfgs(function, x_0, **kwargs)

Broyde-Fletcher-Goldfarb-Shanno (BFGS) algorithm from scipy.optimize.fmin_bfgs(). Please refer to the scipy function for additional arguments information.

concert.optimization.down_hill(function, x_0, **kwargs)

Downhill simplex algorithm from scipy.optimize.fmin(). Please refer to the scipy function for additional arguments information.

concert.optimization.halver(function, x_0, initial_step=None, epsilon=None, max_iterations=100)

Halving the interval, evaluate function based on param. Use initial_step, epsilon precision and max_iterations.

concert.optimization.least_squares(function, x_0, **kwargs)

Least squares algorithm from scipy.optimize.leastsq(). Please refer to the scipy function for additional arguments information.

concert.optimization.nonlinear_conjugate(function, x_0, **kwargs)

Nonlinear conjugate gradient algorithm from scipy.optimize.fmin_cg(). Please refer to the scipy function for additional arguments information.

concert.optimization.optimize(*args, **kwargs)

Optimize y = function (x), where x_0 is the initial guess. algorithm is the optimization algorithm to be used:

algorithm(x_0, *alg_args, **alg_kwargs)

consumer receives all the (x, y) values as they are obtained.

concert.optimization.optimize_parameter(parameter, feedback, x_0, algorithm, alg_args=(), alg_kwargs=None, consumer=None)

Optimize parameter and use the feedback (a callable) as a result. Other arguments are the same as by optimize(). The function to be optimized is determined as follows:

parameter.set(x)
y = feedback()

consumer is the same as by optimize().

concert.optimization.powell(function, x_0, **kwargs)

Powell’s algorithm from scipy.optimize.fmin_powell(). Please refer to the scipy function for additional arguments information.