cfelpyutils package

Submodules

cfelpyutils.cfelfabio module

cfelpyutils.cfelgeom module

Utilities for CrystFEL-style geometry files.

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

cfelpyutils.cfelgeom.apply_geometry_from_file(data_as_slab, geometry_filename)

Parse a geometry file and applies the geometry to detector data in ‘slab’ format. Turns a 2d array of pixel values into an array containing a representation of the physical layout of the detector, keeping the origin of the reference system at the beam interaction point.

Parameters:
  • data_as_slab (numpy.ndarray) – the pixel values to which geometry is to be applied.
  • geometry_filename (str) – geometry filename.
Returns:

im_out – Array containing a representation of the physical layout of the detector, with the origin of the reference system at the beam interaction point.

Return type:

numpy.ndarray data_as_slab.dtype

cfelpyutils.cfelgeom.apply_geometry_from_pixel_maps(data_as_slab, yx, im_out=None)

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

Parameters:
  • data_as_slab (numpy.ndarray) – the pixel values to which geometry is to be applied.
  • yx (tuple) – the yx pixel maps describing the geometry of the detector; each map is a numpy.ndarray.
  • im_out (Optional[numpy.ndarray]) – array to hold the output; if not provided, one will be generated automatically.
Returns:

im_out – Array containing a representation of the physical layout of the detector, with the origin of the reference system at the beam interaction point.

Return type:

numpy.ndarray data_as_slab.dtype

cfelpyutils.cfelgeom.coffset_from_geometry_file(fnam)
Extracts detector distance offset information from a CrystFEL-style
geometry file.
Parameters:fnam (str) – geometry filename.
Returns:coffset – the detector distance offset
Return type:float
cfelpyutils.cfelgeom.parse_xy(string)

Parse the x, y values from strings that have the format: ‘1x + 2.0y’.

Parameters:string (str) – the string to be parsed.
Returns:x, y – the values of x and y.
Return type:float, float
cfelpyutils.cfelgeom.pixel_maps_for_image_view(geometry_filename)

Parse the geometry file and pixel maps for an array in ‘slab’ format containing pixel values. The pixel maps can be used to create a representation of the physical layout of the detector in a pyqtgraph ImageView widget (i.e. they apply the detector geometry setting the origin of the reference system is in the top left corner of the output array).

Parameters:geometry_filename (str) – geometry filename.
Returns:(y, x) – pixel maps

slab_shape tuple (int, int): shape of the original geometry uncorrected array (the pixel values in “slab” format).

img_shape tuple (int, int): shape of the array needed to contain the representation of the physical layout of the detector.

Return type:numpy.ndarray int, numpy.ndarray int
cfelpyutils.cfelgeom.pixel_maps_from_geometry_file(fnam)

Extracts pixel maps from a CrystFEL-style geometry file. The pixel maps can be used to create a representation of the physical layout of the detector, keeping the origin of the reference system at the beam interaction point.

Parameters:fnam (str) – geometry filename.
Returns:x,y,r

slab-like pixel maps with respectively x, y coordinates of the pixel and distance of the pixel from the center of the reference system

Return type:numpy.ndarray float, numpy.ndarray float, numpy.ndarray float
cfelpyutils.cfelgeom.res_from_geometry_file(fnam)
Extracts pixel resolution information from a CrystFEL-style
geometry file.
Parameters:fnam (str) – geometry filename.
Returns:res – the pixel resolution
Return type:float

cfelpyutils.cfelhdf5 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.cfelhdf5.load_nparray_from_hdf5_file(data_filename, data_group)

Loads 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 to read.
Returns:

nparray – numpy array with the data read from the file.

Return type:

numpy.ndarray

cfelpyutils.cfeloptarg module

Utilities for parsing command line options and configuration files.

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

cfelpyutils.cfeloptarg.parse_parameters(config)

Sets correct types for parameter dictionaries.

Reads a parameter dictionary returned by the ConfigParser python modue, and assigns correct types to parameters, without changing the structure of the dictionary.

The parser tries to interpret each entry in the dictionary according to the following rules:

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

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

    The first choice that succeeds determines the entry type.

Parameters:config (class RawConfigParser) – ConfigParser instance.
Returns:monitor_params – dictionary with the same structure as the input dictionary, but with correct types assigned to each entry.
Return type:dict

cfelpyutils.cfelpsana module

Utilities based on the psana python module.

This module provides utilities that build on the functionality provided by the psana python module.

cfelpyutils.cfelpsana.dirname_from_source_runs(source)

Returns a directory name based on a psana source string.

Takes a psana source string (e.g exp=CXI/cxix....) and returns a string that can be used as a subdirectory name or a prefix for files and directories.

Parameters:source (str) – a psana source string (e.g. exp=CXI/cxi....).
Returns:dirname – a string that can be used as a filename or a prefix .
Return type:str
cfelpyutils.cfelpsana.psana_event_inspection(source)

Prints the structure of psana events.

Takes a psana source string (e.g. exp=CXI/cxix....) and inspects the structure of the first event in the data, printing information about the the content of the event.

Parameters:source (str) – a psana source string (e.g. exp=CXI/cxix....).
cfelpyutils.cfelpsana.psana_obj_from_string(name)

Converts a string into a psana object type.

Takes a string and returns the python object type described by the string.

Parameters:name (str) – a string describing a python type.
Returns:mod – the python type described by the string.
Return type:type

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.