Processes

Scanning

concert.processes.scan(param, feedback, minimum=None, maximum=None, intervals=64, convert=lambda x: x)

Scan the parameter object in intervals steps between minimum and maximum and call feedback at each step. feedback must return a value that is evaluated at the parameter position. 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.

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

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 0x616fb90>)

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(camera, motor, measure=<function std at 0x4a56b18>, opt_kwargs=None, plot_consumer=None, frame_consumer=None)

Focus camera by moving motor. measure is a callable that computes a scalar that has to be maximized from an image taken with camera. opt_kwargs are keyword arguments sent to the optimization algorithm. plot_consumer is fed with y values from the optimization and frame_consumer is fed with the incoming frames.

This function is returning a future encapsulating the focusing event. Note, that the camera is stopped from recording as soon as the optimal position is found.

Alignment

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

align_rotation_axis(camera, rotation_motor, x_motor=None, z_motor=None, measure=rotation_axis, num_frames=10, absolute_eps=0.1 * q.deg, max_iterations=5, flat=None, dark=None, frame_consumer=None)

Align rotation axis. camera is used to obtain frames, rotation_motor rotates the sample around the tomographic axis of rotation, x_motor turns the sample around x-axis, z_motor turns the sample around z-axis. measure provides axis of rotation angular misalignment data (a callable), num_frames defines how many frames are acquired and passed to the measure. absolute_eps is the threshold for stopping the procedure. If max_iterations is reached the procedure stops as well. flat and dark are the normalization frames applied on the acquired frames. frame_consumer is a coroutine which will receive the frames acquired at different sample positions.

The procedure finishes when it finds the minimum angle between an ellipse extracted from the sample movement and respective axes or the found angle drops below absolute_eps. The axis of rotation after the procedure is (0,1,0), which is the direction perpendicular to the beam direction and the lateral direction.

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(cam, xmotor, zmotor, pixelsize, xborder, zborder, xstep=None, zstep=None, thres=1000)

Scans the area defined by xborder and zborder for the beam until beam_visible returns True. Startpoint is the current motor-position if this position is inside the defined area else it start from the center of that area. It searches in a spiral around the startpoint.

cam is the camera-device, xmotor the motor-device horizontally aligned to the image and zmotor the motor-device vertically aligned to the image. pixelsize determines the realworld size of an image pixels (scalar or 2-element array-like, e.g. [4*q.um, 5*q.um]). xborder and zborder define the search area. Each constructed with a start- and an end-value (e.g. [-1.2*q.mm, 5.5*q.mm]).

Optional arguments xstep and zstep define the length of one movement in the specific direction. Defaults are calculated from cam_img.shape and pixelsize. Optional argument thres will be past to beam_visible().

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.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.

concert.coroutines.sinks.write_images(writer, prefix="image_{:>05}")

Write images on disk with specified writer and file name prefix. writer is a callable with the following nomenclature:

writer(file_name_prefix, data)

The file extension needs to be applied by a particular writer.

Filters

class concert.coroutines.filters.PickSlice(index)

Pick a slice from a 3D volume.

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.