STLoader

class pyrost.STLoader(protocol, load_paths=None, policy=None)

Speckle Tracking data loader class. Loads data from a CXI file and returns a STData container or a dict with the data. Search data in the paths provided by protocol and load_paths.

Parameters
  • protocol (Protocol) – Protocol object.

  • load_paths (dict, optional) – Extra paths to the data attributes in a CXI file, which override protocol. Accepts only the attributes enlisted in protocol.

  • policy (dict, optional) – A dictionary with loading policy. Contains all the attributes that are available in protocol and the corresponding flags. If a flag is True, the attribute will be loaded from a file. By default only the attributes necessary for a STData container will be loaded.

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.

  • load_paths (dict) – Extra set of paths to the attributes enlisted in datatypes.

  • policy (dict) – Loading policy.

See also

protocol

Full list of data attributes and configuration parameters.

STData

Data container with all the data necessary for Speckle Tracking.

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

find_path(attr, cxi_file)

Find attribute’s path in a CXI file cxi_file.

Parameters
Returns

Atrribute’s path in the CXI file, return None if the attribute is not found.

Return type

str or None

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

get_load_paths(attr, value=None)

Return the atrribute’s 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

Set of attribute’s paths.

Return type

list

get_protocol()

Return a CXI protocol from the loader.

Returns

CXI protocol.

Return type

Protocol

classmethod import_ini(protocol_file)

Initialize an STLoader object class with an ini file.

Parameters

protocol_file (str) – Path to the file.

Returns

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

Return type

STLoader

load(path, **kwargs)

Load a CXI file and return an STData class object.

Parameters
  • path (str) – Path to the cxi file.

  • **kwargs (dict) – Dictionary of attribute values, which will be parsed to the STData object instead.

Returns

Data container object with all the necessary data for the Speckle Tracking algorithm.

Return type

STData

load_dict(path, **kwargs)

Load a CXI file and return a dict with all the data fetched from the file.

Parameters
  • path (str) – Path to the cxi file.

  • **kwargs (dict, optional) – Dictionary of attribute values, which will be parsed to the STData object instead.

Returns

Dictionary with all the data fetched from the CXI file.

Return type

dict

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.