defdap.utils module

defdap.utils.reportProgress(message='')[source]

Decorator for reporting progress of given function

Parameters:

message (str) – Message to display (prefixed by ‘Starting ‘, progress percentage and then ‘Finished ‘

References

Inspiration from : https://gist.github.com/Garfounkel/20aa1f06234e1eedd419efe93137c004

class defdap.utils.Datastore[source]

Bases: object

Storage of data and metadata, with methods to allow derived data to be calculated only when accessed.

_store

Staorage for data and metadata, keyed by data name. Each item is a dict with at least a data key, all other items are metadata, possibly including:

typestr
Type of data stored:

map - at least a 2-axis array, trailing axes are spatial

orderint

Tensor order of the data

unitstr

Measurement unit the data is stored in

plot_paramsdict

Dictionary of the default paramenters used to plot

Type:

dict of dict

_generators

Methods to generate derived data, keyed by tuple of data names that the method produces.

Type:

dict

keys()[source]

Get the names of all data items. Allows use of **datastore to get key-value pairs, imitating functionality of a dictionary.

add(key, data, **kwargs)[source]

Add an item to the datastore.

Parameters:
  • key (str) – Name of the data.

  • data (any) – Data to store.

  • kwargs (dict) – Key-value pairs stored as the items metadata.

add_generator(keys, func, metadatas=None, **kwargs)[source]

Add a data generator method that produces one or more data.

Parameters:
  • keys (str or tuple of str) – Name(s) of data that the generator produces.

  • func (callable) – Method that produces the data. Should return the same number of values as there are keys.

  • metadatas (list of dict) – Metadata dicts for each of data items produced.

  • kwargs (dict) – Key-value pairs stored as the items metadata for every data item produced.

generate(key)[source]

Generate data from the associated data generation method and store if metadata save is not set to False.

Parameters:

key (str) – Name of the data to generate.

Returns:

Return type:

Requested data after generating.

update(other, priority=None)[source]

Update with data items stored in other.

Parameters:
  • other (defdap.utils.Datastore) –

  • priority (str) – Which datastore to keep an item from if the same name exists in both. Default is to prioritise other.

get_metadata(key, attr, value=None)[source]

Get metadata value with a default returned if it does not exist. Imitating the get() method of a dictionary.

Parameters:
  • key (str) – Name of the data item.

  • attr (str) – Metadata to get.

  • value (any) – Default value to return if metadata does not exist.

Returns:

Return type:

Metadata value or the default value.