LogContainer#

class cbclib.LogContainer(protocol=<factory>, log_attr=<factory>, log_data=<factory>, idxs=None, translations=None)[source]#

Log data container class. Takes a log protocol cbclib.LogProtocol and provides an interface to read the log files and generate a an array of sample translations and a set of scan samples cbclib.ScanSamples.

Parameters
  • protocol (LogProtocol) – A log protocol object

  • log_attr (Dict[str, Dict[str, Any]]) – A dictionary of log attributes imported from a log file.

  • log_data (Dict[str, Any]) – A dictionary of log data imported from a log file.

  • idxs (Optional[ndarray]) – A set of indices of the scan steps imported from a log file.

  • translations (Optional[ndarray]) – An array of sample translations.

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_log_attribute(attr, part_key=None)[source]#

Find a value in the log attributes corresponding to an attribute name attr.

Parameters
  • attr (str) – A name of the attribute to find.

  • part_key (Optional[str]) – Search in the given part of the log dictionary if provided.

Return type

Optional[Any]

Returns

Value of the log attribute. Returns None if nothing is found.

find_log_dataset(attr)[source]#

Find a dataset in the log data corresponding to an attribute name attr.

Parameters

attr (str) – A name of the attribute to find.

Return type

Optional[ndarray]

Returns

Dataset for the given attribute. Returns None if nothing is found.

find_log_part_key(attr)[source]#

Find a name of the log dictionary corresponding to an attribute name attr.

Parameters

attr (str) – A name of the attribute to find.

Return type

Optional[str]

Returns

A name of the log dictionary, corresponding to the given attribute name attr.

generate_samples(dist, setup)[source]#

Generate a cbclib.ScanSamples object from the sample translations.

Parameters
  • dist (float) – Initial focus-to-sample distance in meters.

  • setup (ScanSetup) – Experimental setup.

Raises

ValueError – If translations is missing.

Return type

~L

Returns

A scan samples object.

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.

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_logs(log_path, idxs=None)[source]#

Read a log file under the path log_path. Read out only the frame indices defined by idxs. If idxs is None, read the whole log file.

Parameters
  • log_path (str) – Path to the log file.

  • idxs (Optional[Iterable[int]]) – List of indices to read. Read the whole log file if None.

Return type

~L

Returns

A new log container with log_attr, log_data, and idxs updated.

read_translations()[source]#

Generate sample translations based on the log data.

Raises

ValueError – If log_data is missing.

Return type

~L

Returns

A new log container with translations updated.

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.

simulate_translations()[source]#

Simulate sample translations based on the log attributes.

Raises

ValueError – If log_attr is missing.

Return type

~L

Returns

A new log container with translations updated.

values()#

Return the attributes’ data stored in the container.

Return type

ValuesView

Returns

List of data stored in the container.