CXIProtocol#

class pyrost.CXIProtocol(datatypes, load_paths, kinds)#

CXI protocol class. Contains a CXI file tree path with the paths written to all the data attributes necessary for the pyrost.STData detector data container, their corresponding attributes’ data types, and data structure.

Parameters
  • datatypes (Dict[str, str]) – Dictionary with attributes’ datatypes. ‘float’, ‘int’, ‘uint’, or ‘bool’ are allowed.

  • load_paths (Dict[str, List[str]]) – Dictionary with attributes’ CXI default file paths.

  • kinds (Dict[str, str]) –

    The attribute’s kind, that specifies data dimensionality. The following keywords are allowed:

    • scalar : Data is either 0D, 1D, or 2D. The data is saved and loaded plainly without any transforms or indexing.

    • sequence : A time sequence array. Data is either 1D, 2D, or 3D. The data is indexed, so the first dimension of the data array must be a time dimension. The data points for the given index are not transformed.

    • frame : Frame array. Data must be 2D, it may be transformed with any of pyrost.Transform objects. The data shape is identical to the detector pixel grid.

    • stack : A time sequnce of frame arrays. The data must be 3D. It’s indexed in the same way as sequence attributes. Each frame array may be transformed with any of pyrost.Transform objects.

cast(attr, array)#

Cast the attribute’s data to the right data type.

Parameters
  • attr (str) – The data attribute.

  • array (ndarray) – The attribute’s data.

Return type

ndarray

Returns

Data array casted to the right data type.

contents()#

Return a list of the attributes stored in the container that are initialised.

Return type

List[str]

Returns

List of the attributes stored in the container.

find_path(attr, cxi_file)#

Find attribute’s path in a CXI file cxi_file.

Parameters
  • attr (str) – Data attribute.

  • cxi_file (File) – h5py.File object of the CXI file.

Return type

str

Returns

Attribute’s path in the CXI file, returns an empty string if the attribute is not found.

get(attr, value=None)#

Retrieve a dataset, return value if the attribute is not found.

Parameters
  • attr (str) – Data attribute.

  • value (Optional[Any]) – Data which is returned if the attribute is not found.

Return type

Any

Returns

Attribute’s data stored in the container, value if attr is not found.

get_dtype(attr, dtype=None)#

Return the attribute’s data type. Return dtype if the attribute’s data type is not found.

Parameters
  • attr (str) – The data attribute.

  • dtype (Optional[dtype]) – Data type which is returned if the attribute’s data type is not found.

Return type

type

Returns

Attribute’s data type.

get_kind(attr, value='scalar')#

Return the attribute’s kind, that specifies data dimensionality. Return value if the attribute is not found.

Parameters
  • attr (str) – The data attribute.

  • value (str) – value which is returned if the attr is not found.

Return type

str

Returns

The attribute’s kind, that specifies data dimensionality. The following keywords are allowed:

  • scalar : Data is either 0D, 1D, or 2D. The data is saved and loaded plainly without any transforms or indexing.

  • sequence : A time sequence array. Data is either 1D, 2D, or 3D. The data is indexed, so the first dimension of the data array must be a time dimension. The data points for the given index are not transformed.

  • frame : Frame array. Data must be 2D, it may be transformed with any of pyrost.Transform objects. The data shape is identical to the detector pixel grid.

  • stack : A time sequnce of frame arrays. The data must be 3D. It’s indexed in the same way as sequence attributes. Each frame array may be transformed with any of pyrost.Transform objects.

get_load_paths(attr, value=None)#

Return the attribute’s default path in the CXI file. Return value if attr is not found.

Parameters
  • attr (str) – The attribute to look for.

  • value (Optional[List[str]]) – Value which is returned if the attr is not found.

Return type

List[str]

Returns

Attribute’s cxi file path.

get_ndim(attr, value=0)#

Return the acceptable number of dimensions that the attribute’s data may have.

Parameters
  • attr (str) – The data attribute.

  • value (int) – value which is returned if the attr is not found.

Return type

Tuple[int, …]

Returns

Number of dimensions acceptable for the attribute.

classmethod import_default()#

Return the default CXIProtocol object.

Return type

CXIProtocol

Returns

A CXIProtocol object with the default parameters.

classmethod import_ini(ini_file)#

Initialize the container object with an INI file ini_file.

Parameters

ini_file (str) – Path to the ini file.

Return type

~I

Returns

A new container with all the attributes imported from the ini file.

items()#

Return (key, value) pairs of the datasets stored in the container.

Return type

ItemsView

Returns

(key, value) pairs of the datasets stored in the container.

keys()#

Return a list of the attributes available in the container.

Return type

List[str]

Returns

List of the attributes available in the container.

read_attribute_indices(attr, cxi_files)#

Return a set of indices of the dataset containing the attribute’s data inside a set of files.

Parameters
  • attr (str) – Attribute’s name.

  • cxi_files (List[File]) – A list of HDF5 file objects.

Return type

ndarray

Returns

Dataset indices of the data pertined to the attribute attr.

read_attribute_shapes(attr, cxi_file)#

Return a shape of the dataset containing the attribute’s data inside a file.

Parameters
  • attr (str) – Attribute’s name.

  • cxi_file (File) – HDF5 file object.

Return type

Dict[str, Tuple[int, …]]

Returns

List of all the datasets and their shapes inside cxi_file.

static read_dataset_shapes(cxi_path, cxi_file)#

Visit recursively all the underlying datasets and return their names and shapes.

Parameters
  • cxi_path (str) – Path of the dataset inside the cxi_file.

  • cxi_file (File) – HDF5 file handler.

Return type

Dict[str, Tuple[int, …]]

Returns

List of all the datasets and their shapes under the cxi_path of the cxi_file HDF5 file.

replace(**kwargs)#

Return a new container object with a set of attributes replaced.

Parameters

kwargs (Any) – A set of attributes and the values to to replace.

Return type

~D

Returns

A new container object with updated attributes.

static str_to_list(strings)#

Convert strings to a list of strings.

Parameters

strings (Union[str, List[str]]) – String or a list of strings

Return type

List[str]

Returns

List of strings.

to_ini(ini_file)#

Save all the attributes stored in the container to an INI file ini_file.

Parameters

ini_file (str) – Path to the ini file.

values()#

Return the attributes’ data stored in the container.

Return type

ValuesView

Returns

List of data stored in the container.