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
¶ Storage 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 parameters used to plot
- Type:
dict of dict
-
_generators
¶ Methods to generate derived data, keyed by tuple of data names that the method produces.
- Type:
-
keys
()[source]¶ Get the names of all data items. Allows use of **datastore to get key-value pairs, imitating functionality of a dictionary.
-
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.
-