cfelpyutils package¶
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.
Submodules¶
cfelpyutils.cfelfabio module¶
Utilities based on the fabio python module
This module contains utilities derived from the fabio python module. This module allows python to understand and process several file format used in x-ray crystallography. The utilites in this modules expand on what the fabio module alread provides.
-
cfelpyutils.cfelfabio.
read_cbf_from_stream
(stream)¶ “Reads a cbfimage object out of a data string buffer.
Read a data string buffer received as a payload from the PETRAIII P11 sender, and creates a cbfimage object from it (See the documentation of the fabio python module).
Parameters: stream (str) – a data string buffer received from the PETRAIII P11 sender. Returns: cbf_obj – a cbfimage object containing the data extracted from the string buffer. Return type: fabio.cbfimage
cfelpyutils.cfelgeom module¶
Utilities for CrystFEL-style geometry files.
This module contains utilities for the processing of CrystFEL-style geometry files.
-
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.
pixel_maps_from_geometry_file
(fnam)¶ Extracts pixel maps from a CrystFEL-style geometry file.
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 (usually the beam position). 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_cmdline_args
()¶ Parses command line arguments for source and monitor.ini file.
Uses the argparse module to parse command line arguments. It parses the following arguments:
source (1st positional argument): data source (file list, psana source string, etc.).
configuration file (-i/–ini): file containing user-provided parameters.
-
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 (dict) – parameter dictionary returned by ConfigParser. 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