MetaDict#

class sunpy.util.MetaDict(*args, save_original=True)[source]#

Bases: OrderedDict

A class to hold metadata associated with a sunpy.map.Map derivative.

This class handles everything in lower case. This allows case insensitive indexing.

If the key ‘keycomments’ exists, its value must be a dictionary mapping keys in the MetaDict to their comments. The casing of keys in the keycomments dictionary is not significant. If a key is removed from the MetaDict, it will also be removed from the keycomments dictionary. Additionally, any extraneous keycomments will be removed when the MetaDict is instantiated.

Parameters:

save_original (bool, optional) – If True (the default), a copy of the original metadata will be saved to the original_meta property. Note that this keyword argument is required as an implementation detail to avoid recursion when saving the original contents.

Attributes Summary

added_items

Items added since initialisation.

modified_items

Items modified since initialisation.

original_meta

A copy of the dictionary from when it was initialised.

removed_items

Items removed since initialisation.

Methods Summary

copy()

Shallow copies this instance.

get(key[, default])

Override .get() indexing.

has_key(key)

Override .has_key() to perform case-insensitively.

item_hash()

Create a hash based on the stored items.

pop(key[, default])

Override .pop() to perform case-insensitively.

popitem(last)

Remove and return a (key, value) pair from the dictionary.

setdefault(key[, default])

Override .setdefault() to perform case-insensitively.

update(d2)

Override .update() to perform case-insensitively.

Attributes Documentation

added_items#

Items added since initialisation.

modified_items#

Items modified since initialisation.

This is a mapping from key to [original_value, current_value].

original_meta#

A copy of the dictionary from when it was initialised.

removed_items#

Items removed since initialisation.

Methods Documentation

copy()[source]#

Shallow copies this instance.

get(key, default=None)[source]#

Override .get() indexing.

has_key(key)[source]#

Override .has_key() to perform case-insensitively.

item_hash()[source]#

Create a hash based on the stored items.

This relies on all the items themselves being hashable. For this reason the ‘keycomments’ item, which is a dict, is excluded from the hash.

If creating the hash fails, returns None.

pop(key, default=None)[source]#

Override .pop() to perform case-insensitively.

popitem(last)[source]#

Remove and return a (key, value) pair from the dictionary.

Pairs are returned in LIFO order if last is true or FIFO order if false.

setdefault(key, default=None)[source]#

Override .setdefault() to perform case-insensitively.

update(d2)[source]#

Override .update() to perform case-insensitively.