cfelpyutils package

Submodules

cfelpyutils.crystfel_utils module

Utilities for interoperability with the CrystFEL software package.

This module contains reimplementation of Crystfel functions and utilities.

cfelpyutils.crystfel_utils.load_crystfel_geometry(filename)

Load a CrystFEL geometry file into a dictionary.

Reimplementation of the get_detector_geometry_2 function from CrystFEL almost verbatim. Returns a dictionary with the geometry information. Entries in the geometry file appears as keys in the returned dictionary. For a full documentation on the CrystFEL geometry format, see:

tfel/manual-crystfel_geometry.html

he code of this function is synced with the code of the function ‘get_detector_geometry_2’ in CrystFEL at commit 41a8fa9819010fe8ddeb66676fee717f5226c7b8.

Parameters:filename (str) – filename of the geometry file.
Returns:dictionary with the geometry loaded from the file.
Return type:detector (dict)

cfelpyutils.geometry_utils module

Utilities for CrystFEL-style geometry files.

This module contains utilities for the processing of CrystFEL-style geometry files.

class cfelpyutils.geometry_utils.ImageShape(ss, fs)

Bases: tuple

fs

Alias for field number 1

ss

Alias for field number 0

class cfelpyutils.geometry_utils.PixelMaps(x, y, r)

Bases: tuple

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.

Adjust the pixel maps for use in a Pyqtgraph’s ImageView widget. Essentially, the origin of the reference system is moved to the top-left of the image.

Parameters:pixel_maps (tuple) – pixel maps, as returned by the compute_pixel_maps function in this module.
Returns:
a three-element tuple containing two float32 numpy arrays
(‘slab’-like pixel maps) with respectively x, y coordinates of the data pixels as the first two elements, and None as the third.
Return type:tuple
cfelpyutils.geometry_utils.apply_pixel_maps(data_as_slab, pixel_maps, output_array=None)

Apply geometry in pixel map format to the input data.

Applies geometry, described by pixel maps, to input data in ‘slab’ format. Turns a 2d array of pixel values into an array containing a representation of the physical layout of the geometry, keeping the origin of the reference system at the beam interaction point.

Parameters:
  • data_as_slab (ndarray) – the pixel values on which to apply the geometry, in ‘slab’ format.
  • pixel_maps (tuple) – pixel maps, as returned by the compute_pixel_maps function in this module.
  • output_array (Optional[numpy.ndarray]) – array to hold the output. If the array is not provided, one will be generated automatically. Defaults to None (No array provided).
Returns:

Array with the same dtype as the input data containing a

representation of the physical layout of the geometry (i.e.: the geometry information applied to the input data).

Return type:

ndarray

cfelpyutils.geometry_utils.compute_minimum_image_size(pixel_maps)

Compute the minimum size of an image that can represent the geometry.

Compute the minimum size of an image that can contain a representation of the geometry described by the pixel maps, assuming that the image is center at the center of the reference system.

Parameters:
  • pixel_maps (tuple) – pixel maps, as returned by the
  • function in this module. (compute_pixel_maps) –
Returns:

numpy shape object describing the minimum image size.

Return type:

tuple

cfelpyutils.geometry_utils.compute_pixel_maps(geometry)

Create pixel maps from a CrystFEL geometry object.

Compute pixel maps from a CrystFEL-style geometry object (A dictionary returned by the load_crystfel_geometry function from the crystfel_utils module). The pixel maps can be used to create a representation of the physical layout of the geometry, keeping the origin of the reference system at the beam interaction point.

Parameters:geometry (dict) – A CrystFEL geometry object (A dictionary returned by the load_crystfel_geometry function from the crystfel_utils module).
Returns:
a tuple containing three float32 numpy arrays (‘slab’-like pixel
maps) with respectively x, y coordinates of the data pixels and distance of each pixel from the center of the reference system.
Return type:tuple

cfelpyutils.hdf5_utils module

Utilities for HDF5 files.

This module contains utilities for the processing of HDF5. This module builds on what the h5py module already provides.

cfelpyutils.hdf5_utils.load_nparray_from_hdf5_file(data_filename, data_group)

Load a numpy.ndarray from an HDF5 file.

Parameters:
  • data_filename (str) – filename of the file to read.
  • data_group (str) – internal HDF5 path of the data block containing
  • array to load. (the) –
Returns:

numpy array with the data read from the file.

Return type:

ndarray

cfelpyutils.parameter_utils module

Utilities for parsing command line options and configuration files.

This module contains utilities for parsing of command line options and configuration files.

cfelpyutils.parameter_utils.convert_parameters(config_dict)

Convert strings in parameter dictionaries to the corrent data type.

Read a parameter dictionary returned by the ConfigParser python module, and assign correct types to the parameters, without changing the structure of the dictionary.

Try to interpret each entry in the dictionary according to the following rules. The first rule that returns an valid result determines the type in which the entry will be converted.

  • If the entry starts and ends with a single quote or double quote, it is interpreted as a string.

  • If the entry starts and ends with a square bracket, it is interpreted as a list.

  • If the entry starts and ends with a brace, it is interpreted as a dictionary.

  • If the entry is the word None, without quotes, then the entry is interpreted as NoneType.

  • If the entry is the word False, without quotes, then the entry is interpreted as a boolean False.

  • If the entry is the word True, without quotes, then the entry is interpreted as a boolean True.

  • If none of the previous options match the content of the entry, the parser tries to interpret the entry in order as:

    • An integer number.
    • A float number.
    • A string.
Parameters:config (dict) – a dictionary containing the parameters as strings (the dictionary as returned by COnfig Parser).
Returns:
dictionary with the same structure as the input
dictionary, but with correct types assigned to each entry.
Return type:dict

cfelpyutils.psana_utils module

Utilities for the psana python module.

This module provides utilities that build on the functionality provided by the psana python module (developed at the SLAC National Laboratories).

cfelpyutils.psana_utils.first_event_inspection(source)

Inspect the content of the first psana event.

Takes psana source string (e.g. exp=CXI/cxix….) and inspect the content in the first event in the data described by the string. Print information about the the content of the event.

Parameters:source (str) – a psana source string (e.g. exp=CXI/cxix….).

Module contents

Utilities for CFEL software projects.

This module provides utilities (functions, classes, etc.) used by many CFEL projects.

It contains the following submodules (non of which are automatically imported):

cfelfabio: utilities based on the fabio python module (a module that allows python to work with several file format used in x-ray imaging).

cfelgeom: utilities for processing CrystFEL-style geometry files.

cfelhdf5: utilities for processing HDF5 files (based on the h5py python module).

cfeloptarg: utilities to parse command line arguments and parameter files.

cfelpsana: utilities that expand the functionality of the psana python module.