cfelpyutils.geometry_utils module

Utilities to load, manipulate and apply geometry information to detector pixel data.

Exports:

Functions:

compute_pixel_maps: turn a CrystFEL geometry object into pixel
maps.
apply_pixel_maps: apply pixel maps to a data array. Return an
array containing data with the geometry applied.
compute_minimum_array_size: compute the minimum array size that
is required to store data to which a geometry has been applied.
adjust_pixel_maps_for_pyqtgraph: ajust pixel maps to be used in
a PyQtGraph’s ImageView widget.
class cfelpyutils.geometry_utils.PixelMaps(x, y, r)

Bases: tuple

Pixel maps storing data geometry.

A namedtuple that stores the pixel maps describing the geometry of a dataset. The first two fields, named “x” and “y” respectively, store the pixel maps for the x coordinate and the y coordinate. The third field, named “r”, is instead a pixel map storing the distance of each pixel in the data array from the center of the reference system.

r

Alias for field number 2

x

Alias for field number 0

y

Alias for field number 1

cfelpyutils.geometry_utils.adjust_pixel_maps_for_pyqtgraph(pixel_maps)

Adjust pixel maps for visualization of the data in a pyqtgraph widget.

The adjusted maps can be used for a Pyqtgraph ImageView widget.

Parameters:pixel_maps (PixelMaps) – a PixelMaps tuple.
Returns:
A Pixelmaps tuple containing the adjusted pixel
maps. The first two fields, named “x” and “y” respectively, store the pixel maps for the x coordinate and the y coordinate. The third field (“r”) is just set to None.
Return type:PixelMaps
cfelpyutils.geometry_utils.apply_pixel_maps(data, pixel_maps, output_array=None)

Apply geometry to the input data.

Apply the geometry (in pixel maps format) to the data. In other words, turn an array of detector pixel values into an array containing a representation of the physical layout of the detector.

Parameters:
  • data (ndarray) – array containing the data on which the geometry will be applied.
  • pixel_maps (PixelMaps) – a PixelMaps tuple.
  • output_array (Optional[ndarray]) – a preallocated array (of dtype numpy.float32) to store the function output. If provided, this array will be filled by the function and and returned to the user. If not provided, the function will create a new array automatically and return it to the user. Defaults to None (No array provided).
Returns:

a numpy.float32 array containing the data with the geometry applied (i.e.: a representation of the physical layout of the detector).

Return type:

ndarray

cfelpyutils.geometry_utils.compute_minimum_array_size(pixel_maps)

Compute the minimum array size storing data with applied geometry.

Return the minimum size of an array that can store data on which the geometry information described by the pixel maps has been applied.

The returned array shape is big enough to display all the input pixel values in the reference system of the physical detector. The array is also supposed to be centered at the center of the reference system of the detector (i.e: the beam interaction point).

Parameters:[PixelMaps] (pixel_maps) – a PixelMaps tuple.
Returns:a numpy-style shape tuple storing the minimum array size.
Return type:Tuple[int, int]
cfelpyutils.geometry_utils.compute_pixel_maps(geometry)

Compute pixel maps from a CrystFEL geometry object.

Take as input a CrystFEL-style geometry object (A dictionary returned by the function load_crystfel_geometry function in the crystfel_utils module) and return a PixelMap tuple . The origin the reference system used by the pixel maps is set at the beam interaction point.

Parameters:geometry (dict) – A CrystFEL geometry object (A dictionary returned by the cfelpyutils.crystfel_utils.load_crystfel_geometry function).
Returns:A PixelMaps tuple.
Return type:PixelMaps