DimensionSet¶
-
class
lsst.daf.butler.DimensionSet(universe, elements, expand=False, implied=False)¶ Bases:
collections.abc.SetA custom set/dict hybrid class for collections of
DimensionElements.DimensionSetobjects implement the full (immutable)collections.abc.Setinterface. In addition, likefrozenset, they are immutable and hashable, and also provide named-method versions of most operators. Unlike Python sets, they are deterministically sorted.Parameters: - universe :
DimensionGraph Ultimate-parent
DimensionGraphthat constructed the elements in this set.- elements : iterable of
DimensionElementorstr Elements to include in the set, or names thereof.
- expand :
bool If
True, recursively expand the set to include dependencies.- implied :
bool If
True, include implied dependencies in expansion. Ignored ifexpandisFalse.
Raises: - ValidationError
Raised if a Dimension is not part of the Universe.
Notes
DimensionSetcomparison operators and named-method relation operations accept other set-like objects and iterables containing eitherDimensionElementinstances or their string names; becauseDimensionElements cannot be directly constructed, APIs that accept them should generally accept a name as an alternative when the transformation to aDimensionElementcan be done internally. Operators that return new sets (|,&,^, and-) do requireDimensionSetoperands on both sides to avoid surprises in return types.Because the
DimensionElementobjects they hold always have a name,DimensionSets also supports somedict-like operations: including regular square-bracket indexing (__getitem__),get, and theinoperator (__contains__). Both names andDimensionElementobjects can be passed to any of these. Thenamesattribute can also be used to obtain aset-like object containing those names.DimensionSetinstances cannot be constructed directly; they can only be obtained (possibly indirectly) from a special “universe”DimensionGraphloaded from configuration.Attributes Summary
namesThe names of all elements ( set-like, immutable).universeThe graph of all dimensions compatible with self ( DimensionGraph).Methods Summary
difference(other)Return a new set containing all elements that are in selfbut not other.expanded([implied])Return a new DimensionSetthat has been expanded to include dependencies.findIf(predicate[, default])Return the element in selfthat matches the given predicate.get(key[, default])Return the element with the given name, or defaultif it does not exist.intersection(*others)Return a new set containing all elements that are in both selfand all of the other given sets.isdisjoint(other)Return Trueif there are no elements in bothselfandother, andFalseotherwise.issubset(other)Return Trueif all elements inselfare also inother.issuperset(other)Return Trueif all elements inotherare also inself, andFalseotherwise.links()Return the names of all fields that uniquely identify these dimensions in a data ID dict. symmetric_difference(other)Return a new set containing all elements that are in either selfor other, but not both.union(*others)Return a new set containing all elements that are in selfor any of the other given sets.Attributes Documentation
-
names¶ The names of all elements (
set-like, immutable).The order of the names is consistent with the iteration order of the
DimensionSetitself.
-
universe¶ The graph of all dimensions compatible with self (
DimensionGraph).
Methods Documentation
-
difference(other)¶ Return a new set containing all elements that are in
selfbut not other.Parameters: - other : iterable of
DimensionElementorstr. The other set containing elements that should not be included in the result.
Returns: - result :
DimensionNameSetorDimensionSet A new set containing elements in
selfbut notother. A fullDimensionSetis returned if any argument is a fullDimensionSetorDimensionGraph.
- other : iterable of
-
expanded(implied=False)¶ Return a new
DimensionSetthat has been expanded to include dependencies.Parameters: - implied :
bool Whether to include implied as well as required dependencies.
- implied :
-
findIf(predicate, default=None)¶ Return the element in
selfthat matches the given predicate.Parameters: - predicate : callable
Callable that takes a single
DimensionElementargument and returns abool, indicating whether the given value should be returned.- default :
DimensionElement, optional Object to return if no matching elements are found.
Returns: - matching :
DimensionElement Element matching the given predicate.
Raises: - ValueError
Raised if multiple elements match the given predicate.
-
get(key, default=None)¶ Return the element with the given name, or
defaultif it does not exist.keymay also be aDimensionElement, in which case an equivalent object will be returned if it is present in the set.
-
intersection(*others)¶ Return a new set containing all elements that are in both
selfand all of the other given sets.Parameters: - others : iterable over
DimensionElementorstr. Other sets whose elements may be included in the result.
Returns: - result :
DimensionNameSetorDimensionSet A new set containing any elements in all input sets. A full
DimensionSetis returned if any argument is a fullDimensionSetorDimensionGraph.
- others : iterable over
-
isdisjoint(other)¶ Return
Trueif there are no elements in bothselfandother, andFalseotherwise.All sets (including the empty set) are disjoint with the empty set.
-
issubset(other)¶ Return
Trueif all elements inselfare also inother.The empty set is a subset of all sets (including the empty set).
-
issuperset(other)¶ Return
Trueif all elements inotherare also inself, andFalseotherwise.All sets (including the empty set) are supersets of the empty set.
-
links()¶ Return the names of all fields that uniquely identify these dimensions in a data ID dict.
Returns:
-
symmetric_difference(other)¶ Return a new set containing all elements that are in either
selfor other, but not both.Parameters: - other : iterable of
DimensionElementorstr. The other set from which to draw potential result elements.
Returns: - result :
DimensionNameSetorDimensionSet A new set containing elements
selforother, but not both. A fullDimensionSetis returned if any argument is a fullDimensionSetorDimensionGraph.
- other : iterable of
-
union(*others)¶ Return a new set containing all elements that are in
selfor any of the other given sets.Parameters: - *others : iterable over
DimensionElementorstr. Other sets whose elements should be included in the result.
Returns: - result :
DimensionNameSetorDimensionSet A new set containing all elements in any input set. A full
DimensionSetis returned if any argument is a fullDimensionSetorDimensionGraph.
- *others : iterable over
- universe :