Protocol

class pyrost.Protocol(datatypes=None, default_paths=None, float_precision='float64')

CXI protocol class. Contains a CXI file tree path with the paths written to all the data attributes necessary for the Speckle Tracking algorithm, corresponding attributes’ data types, and floating point precision.

Parameters
  • datatypes (dict, optional) – Dictionary with attributes’ datatypes. ‘float’, ‘int’, or ‘bool’ are allowed.

  • default_paths (dict, optional) – Dictionary with attributes’ CXI default file paths.

  • float_precision ({'float32', 'float64'}, optional) – Floating point precision.

Variables
  • config (dict) – Protocol configuration.

  • datatypes (dict) – Dictionary with attributes’ datatypes. ‘float’, ‘int’, or ‘bool’ are allowed.

  • default_paths (dict) – Dictionary with attributes’ CXI default file paths.

See also

protocol

Full list of data attributes and configuration parameters.

export_dict()

Return a dict object with all the attributes.

Returns

Dictionary with all the attributes conntained in the object.

Return type

dict

classmethod export_ini(**kwargs)

Return a configparser.ConfigParser object with all the attributes exported the class.

Parameters

**kwargs (dict) – Extra parameters to export to the configparser.ConfigParser object.

Returns

A parser object with all the attributes contained in attr_dict.

Return type

configparser.ConfigParser

get_default_path(attr, value=None)

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

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

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

Returns

Attribute’s cxi file path.

Return type

str or None

get_dtype(attr, value=None)

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

Parameters
  • attr (str) – The data attribute.

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

Returns

Attribute’s data type.

Return type

type or None

classmethod import_ini(protocol_file)

Initialize an Protocol object class with an ini file.

Parameters

protocol_file (str) – Path to the file.

Returns

An Protocol object with all the attributes imported from the INI file.

Return type

Protocol

parser_from_template(path)

Return a configparser.ConfigParser object using an ini file template.

Parameters

path (str) – Path to the ini file template.

Returns

Parser object with the attributes populated according to the protocol.

Return type

configparser.ConfigParser

read_cxi(attr, cxi_file, cxi_path=None, dtype=None)

Read attr from the CXI file cxi_file at the path defined by the protocol. If cxi_path or dtype argument are provided, it will override the protocol.

Parameters
  • attr (str) – Data attribute.

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

  • cxi_path (str, optional) – Path to the data attribute. If cxi_path is None, the path will be inferred according to the protocol.

  • dtype (type, optional) – Data type of the attribute. If dtype is None, the type will be inferred according to the protocol.

Returns

The value of the attribute extracted from the CXI file.

Return type

numpy.ndarray or None

write_cxi(attr, data, cxi_file, overwrite=True, cxi_path=None, dtype=None)

Write data to the CXI file cxi_file under the path specified by the protocol. If cxi_path or dtype argument are provided, it will override the protocol.

Parameters
  • attr (str) – Data attribute.

  • data (numpy.ndarray) – Data which is bound to be saved.

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

  • overwrite (bool, optional) – Overwrite the content of cxi_file if it’s True.

  • cxi_path (str, optional) – Path to the data attribute. If cxi_path is None, the path will be inferred according to the protocol.

  • dtype (type, optional) – Data type of the attribute. If dtype is None, the type will be inferred according to the protocol.

Raises

ValueError – If overwrite is False and the data is already present at the given location in cxi_file.