MetadataProxy¶
- class Stoner.folders.metadata.MetadataProxy(folder)[source]¶
Bases:
MutableMapping
Provide methods to interact with a whole collection of metadataObjects’ metadata.
Attributes Summary
List all the metadata dictionaries in the Folder.
Return the set of metadata keys common to all objects int he Folder.
Return the set of metadata keys common to all objects int he Folder.
Return a dictionary of the common_keys that have common values.
Methods Summary
Return the result of indexing the metadata with all_keys().
all_keys
()Return the union of all the metadata keyus for all objects int he Folder.
Return the result of indexing the metadata with all_keys().
apply
(key, func)Evaluate a function for each item in the folder and store the return value in a metadata key.
clear
()get
(k[,d])items
()keys
()pop
(k[,d])If key is not found, d is returned if given, otherwise KeyError is raised.
popitem
()as a 2-tuple; but raise KeyError if D is empty.
setdefault
(k[,d])slice
(*args, **kwargs)Return a list of the metadata dictionaries for each item/file in the top level group.
update
([E, ]**F)If E present and has a .keys() method, does: for k in E: D[k] = E[k] If E present and lacks .keys() method, does: for (k, v) in E: D[k] = v In either case, this is followed by: for k, v in F.items(): D[k] = v
values
()Attributes Documentation
- all¶
List all the metadata dictionaries in the Folder.
- all_by_keys¶
Return the set of metadata keys common to all objects int he Folder.
- common_keys¶
Return the set of metadata keys common to all objects int he Folder.
- common_metadata¶
Return a dictionary of the common_keys that have common values.
Methods Documentation
- all_items()[source]¶
Return the result of indexing the metadata with all_keys().
- Yields:
key,self[key]
- apply(key, func)[source]¶
Evaluate a function for each item in the folder and store the return value in a metadata key.
- Parameters:
key (str) – The name of the key to store the result in.
func (callable) – The function to be evaluated.
- Returns:
(self) a copy of the combined metadata object to allow routines to be strung together.
Notes
The function should have a protoptye of the form:
def func(i,metadataObject):
where i is a counter that runs from 0 to the length of the current Folder and metadataObject will be each object in the Folder in turn.
- clear() None. Remove all items from D. ¶
- get(k[, d]) D[k] if k in D, else d. d defaults to None. ¶
- items() a set-like object providing a view on D's items ¶
- keys() a set-like object providing a view on D's keys ¶
- pop(k[, d]) v, remove specified key and return the corresponding value. ¶
If key is not found, d is returned if given, otherwise KeyError is raised.
- popitem() (k, v), remove and return some (key, value) pair ¶
as a 2-tuple; but raise KeyError if D is empty.
- setdefault(k[, d]) D.get(k,d), also set D[k]=d if k not in D ¶
- slice(*args, **kwargs)[source]¶
Return a list of the metadata dictionaries for each item/file in the top level group.
- Keyword Arguments:
*args (string, lmfit.Model class or instance or iterable of string, lmfit Models) – if given then only return the item(s) requested from the metadata
values_only (bool) – if given and output not set only return tuples of the dictionary values. Mostly useful when given a single key string
Controls the output format from slice_metadata. Possible values are
”dict” or dict - return a list of dictionary subsets of the metadata from each image
”list” or list - return a list of values of each item pf the metadata
”array” or np.array - return a single array - like list above, but returns as a numpy array. This can create a 2D array from multiple keys
”data” or Stoner.Data - returns the metadata in a Stoner.Data object where the column headers are the metadata keys.
”frame” - returns the metadata as a Pandas DataFrame object
”smart” - switch between dict and list depending whether there is one or more keys.
mask_missing (bool) – If true, then metadata entries missing in members of the folder are returned as masked values (or None), If False, then an exception is raised if any entries are missing.
- Returns:
ret(list of dict, tuple of values or
Stoner.Data
) – depending on values_only or (output* returns the sliced dictionaries or tuples/ values of the items
- update([E, ]**F) None. Update D from mapping/iterable E and F. ¶
If E present and has a .keys() method, does: for k in E: D[k] = E[k] If E present and lacks .keys() method, does: for (k, v) in E: D[k] = v In either case, this is followed by: for k, v in F.items(): D[k] = v
- values() an object providing a view on D's values ¶