ImageMetaTag.ImageDict¶
+ImageMetaTag.ImageDict¶
This submodule contains the ImageMetaTag.ImageDict
class, and
functions for preparing instances of it.
The purpose of an ImageMetaTag.ImageDict
is to sort the image
@@ -58,10 +54,10 @@
Navigation
(C) Crown copyright Met Office. All rights reserved. Released under BSD 3-Clause License. See LICENSE for more details.
The ImageDict Class¶
+The ImageDict Class¶
- -class ImageMetaTag.ImageDict(input_dict, level_names=None, selector_widths=None, selector_animated=None, animation_direction=None)[source]¶ +class ImageMetaTag.ImageDict(input_dict, level_names=None, selector_widths=None, selector_animated=None, animation_direction=None)[source]¶
A class which holds a heirachical dictionary of dictionaries, and the associated methods for appending/removing dictionaries from it.
The expected use case for the dictionary is to represent a large set of @@ -92,7 +88,7 @@
The ImageDict Class
- -append(new_dict, devmode=False, skip_key_relist=False)[source]¶
+append(new_dict, devmode=False, skip_key_relist=False)[source]¶appends a new dictionary (with a single element in each layer!) into a current ImageDict.
The skip_key_relist option can be set to True to stop the @@ -101,27 +97,27 @@
The ImageDict Class
- -copy_except_dict_and_keys()[source]¶
+copy_except_dict_and_keys()[source]¶returns a copy of an ImageDict except it will have null values for the dict and keys
- -dict_depth(uniform_depth=False)[source]¶ +dict_depth(uniform_depth=False)[source]¶
Uses dict_depths to get the depth of all branches of the plot_dict and, if required, checks they all equal the max.
- -dict_depths(in_dict, depth=0)[source]¶ +dict_depths(in_dict, depth=0)[source]¶
Recursively finds the depth of a ImageDict, returns a list of lists
- -dict_index_array(devmode=False, maxdepth=None, verbose=False)[source]¶ +dict_index_array(devmode=False, maxdepth=None, verbose=False)[source]¶
Using the list of dictionary keys (at each level of a uniform_depth dictionary of dictionaries), this produces a list of the indices that can be used to reference the keys to get the result for each element.
@@ -135,14 +131,14 @@The ImageDict Class
- -dict_print(in_dict, indent=0, outstr='')[source]¶
+dict_print(in_dict, indent=0, outstr='')[source]¶recursively details a dictionary of dictionaries, with indentation, to a string
- -dict_prune(in_dict, dicts_pruned=False)[source]¶ +dict_prune(in_dict, dicts_pruned=False)[source]¶
Prunes the ImageDict of empty, unterminated, branches (which occur after parts have been removed). Returns True if a dict was pruned, False if not.
@@ -150,7 +146,7 @@The ImageDict Class
- -dict_remove(in_dict, rm_dict)[source]¶
+dict_remove(in_dict, rm_dict)[source]¶removes a dictionary of dictionaries from another, larger, one. This can leave empty branches, at multiple levels of the dict, so needs cleaning up afterwards.
@@ -158,25 +154,25 @@The ImageDict Class
- -dict_union(in_dict, new_dict)[source]¶
+dict_union(in_dict, new_dict)[source]¶produces the union of a dictionary of dictionaries
- -flatten_lists(in_list)[source]¶ +flatten_lists(in_list)[source]¶
Recursively flattens a list of lists:
- -key_at_depth(in_dict, depth)[source]¶ +key_at_depth(in_dict, depth)[source]¶
returns the keys of a dictionary, at a given depth
- -keys_by_depth(in_dict, depth=0, keys=None, subdirs=None)[source]¶ +keys_by_depth(in_dict, depth=0, keys=None, subdirs=None)[source]¶
Returns:
a dictionary of sets, containing the keys at each level of the dictionary (keyed by the level number).
@@ -186,7 +182,7 @@ - -list_keys_by_depth(devmode=False)[source]¶ +list_keys_by_depth(devmode=False)[source]¶
Lists the keys of the dictionary to create a list of keys, for each level of the dictionary, up to its depth.
It is usually much faster to create an ImageDict by appending images @@ -200,7 +196,7 @@
The ImageDict Class
- -mergedicts(dict1, dict2)[source]¶
+mergedicts(dict1, dict2)[source]¶Alternative version of dict_union using generators which is much faster for large dicts but needs to be converted to a dict when it’s called: new_dict = dict(mergdicts(dict1,dict))
@@ -208,7 +204,7 @@The ImageDict Class
- -remove(rm_dict, skip_key_relist=False)[source]¶
+remove(rm_dict, skip_key_relist=False)[source]¶removes a dictionary from within an ImageDict. The skip_key_relist option can be set to True to stop the regeneration of key lists.
@@ -221,7 +217,7 @@The ImageDict Class
- -return_from_list(vals_at_depth)[source]¶
+return_from_list(vals_at_depth)[source]¶Returns the end values of ImageDict, when given a list of values for the keys at different depths. Returns None if the set of values is not contained in the ImageDict.
@@ -232,7 +228,7 @@The ImageDict Class
- -return_key_inds(in_dict, out_array=None, this_set_of_inds=None, depth=None, level=None, verbose=False, devmode=False)[source]¶
+return_key_inds(in_dict, out_array=None, this_set_of_inds=None, depth=None, level=None, verbose=False, devmode=False)[source]¶Does the work for dict_index_array, by recursively adding indices to the keys to a current list, and branching where required, and adding compelted lists to the out_array
@@ -240,7 +236,7 @@The ImageDict Class
- -sort_keys(sort_methods, devmode=False)[source]¶
+sort_keys(sort_methods, devmode=False)[source]¶Sorts the keys of a plot dictionary, according to a particular sort method (or a list of sort methods that matches the number of keys).
Valid sort methods so far are mostly focused on meteorological terms, @@ -261,10 +257,10 @@
The ImageDict Class -
Functions useful in preparing ImageDicts¶
+Functions useful in preparing ImageDicts¶
- -ImageMetaTag.readmeta_from_image(img_file, img_format=None, keep_reserved_tags=False)[source]¶ +ImageMetaTag.readmeta_from_image(img_file, img_format=None, keep_reserved_tags=False)[source]¶
Reads the metadata added by the ImageMetaTag savefig, from an image file, and returns a dictionary of tag_name: value pairs
By default tag names that cannot be written by ImageMetaTag savefig @@ -274,7 +270,7 @@
Functions useful in preparing ImageDicts
- -ImageMetaTag.dict_heirachy_from_list(in_dict, payload, heirachy)[source]¶
+ImageMetaTag.dict_heirachy_from_list(in_dict, payload, heirachy)[source]¶Converts a flat dictionary of tagname: value pairs, into an ordered dictionary of dictionaries according to the input heirachy (which is a list of tagnames).
@@ -289,7 +285,7 @@Functions useful in preparing ImageDicts
- -ImageMetaTag.dict_split(in_dict, n_split=None, size_split=None, extra_opts=None)[source]¶
+ImageMetaTag.dict_split(in_dict, n_split=None, size_split=None, extra_opts=None)[source]¶Generator that breaks up a flat dictionary and yields a set of sub-dictionaries in n_split chunks, or size_split in size. It is split on it’s first level, not recursively.
@@ -313,7 +309,7 @@Functions useful in preparing ImageDicts
- -ImageMetaTag.simple_dict_filter(simple_dict, tests, raise_key_mismatch=False)[source]¶
+ImageMetaTag.simple_dict_filter(simple_dict, tests, raise_key_mismatch=False)[source]¶Tests the contents of a simple, un-heirachical dict (properties an image) against a set of tests.
An example set of tests:
@@ -347,7 +343,7 @@Functions useful in preparing ImageDicts
- -ImageMetaTag.check_for_required_keys(img_info, req_keys)[source]¶
+ImageMetaTag.check_for_required_keys(img_info, req_keys)[source]¶Checks an img_info dictionary has a set of required keys, specifed as a list of strings
Returns True or False accordingly.
@@ -453,13 +449,13 @@Navigation
- previous |
- +
The ImageDict Class