DimensionKeyDict

class lsst.daf.butler.DimensionKeyDict(other=None, *, universe=None, keys=None, factory=None, where=None)

Bases: collections.abc.Mapping

An immutable mapping that uses DimensionElement instances as keys.

Parameters:
other : Mapping

Another mapping from which to copy keys and values. Keys that are string names will be converted into DimensionElement instances.

universe : DimensionGraph, optional

All known dimensions; must be provided if keys is not a DimensionGraph or DimensionSet and other is not itself a DimensionKeyDict.

keys : iterable of DimensionElement, optional

The exact keys that should be present in the constructed dictionary. If not provided, defaults to the keys in other. If provided, keys in other that are not in keys will be ignored, and keys missing from other will associated with values constructed by calling factory.

factory : callable, optional

A no-argument callable that should be used to construct values for keys not provided.

where : callable, optional

A predicate taking a single DimensionElement argument that indicates (by returning True) whether a value for that element should be copied from other or (by returning False) constructed by calling factory. Passing None (default) uses a callable that always returns True.

Notes

As with most other operations involving dimension objects, string names can be used lieu of DimensionElement instances in lookup (get, __getitem__, __contains__).

Because DimensionKeyDict instances are themselves immutable (in that new keys and values cannot be added, and the value associated with a key cannot be modified), they are frequently used to hold mutable values, such as set or dict objects, giving them a specific and limited kind of overall mutability (sometimes referred to as “interior” mutability). This is particularly useful in the dimension system, where in many contexts the set of relevant dimensions cannot change but the information associated with them can.

Attributes Summary

universe All known dimensions, including those not represented by this dict (DimensionGraph).

Methods Summary

get(k[,d])
items()
keys()
updateValues(other) Update nested dictionaries or sets from those in another nested mapping.
values()

Attributes Documentation

universe

All known dimensions, including those not represented by this dict (DimensionGraph).

Methods Documentation

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
updateValues(other)

Update nested dictionaries or sets from those in another nested mapping.

Parameters:
other : Mapping

Mapping containing values that should be used to update the corresponding values in self. May have either DimensionElement or str names (or both) as keys.

Returns:
missing : set

Any keys present in other that were not present in self.

Notes

This method assumes the values of self are objects with an update method (such as dict or set), and that the values of other are appropriate arguments to those update methods (i.e. typically also dict or set).

values() → an object providing a view on D's values