STLoader¶
-
class
pyrost.STLoader(protocol, load_paths=None, policy=None)¶ Speckle Tracking data loader class. Loads data from a CXI file and returns a
STDatacontainer or adictwith 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
STDatacontainer 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
-
export_dict()¶ Return a
dictobject with all the attributes.- Returns
Dictionary with all the attributes conntained in the object.
- Return type
-
classmethod
export_ini(**kwargs)¶ Return a
configparser.ConfigParserobject with all the attributes exported the class.- Parameters
**kwargs (dict) – Extra parameters to export to the
configparser.ConfigParserobject.- Returns
A parser object with all the attributes contained in attr_dict.
- Return type
-
find_path(attr, cxi_file)¶ Find attribute’s path in a CXI file cxi_file.
-
get_default_path(attr, value=None)¶ Return the atrribute’s default path in the CXI file. Return value if attr is not found.
-
get_dtype(attr, value=None)¶ Return the attribute’s data type. Return value if attr is not found.
-
get_load_paths(attr, value=None)¶ Return the atrribute’s path in the cxi file. Return value if attr is not found.
-
load_dict(path, **kwargs)¶ Load a CXI file and return a
dictwith all the data fetched from the file.
-
parser_from_template(path)¶ Return a
configparser.ConfigParserobject 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
-
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
-
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.
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.