DimensionGraph¶
-
class
lsst.daf.butler.DimensionGraph¶ Bases:
objectAn immutable, dependency-complete collection of dimensions.
DimensionGraphbehaves in many respects like a set ofDimensioninstances that maintains several special subsets and supersets of relatedDimensionElementinstances. It does not fully implement thecollections.abc.Setinterface, as its automatic expansion of dependencies would make set difference and XOR operations behave surprisingly.It also provides dict-like lookup of
DimensionElementinstances from their names.Parameters: - universe :
DimensionUniverse The special graph of all known dimensions of which this graph will be a subset.
- dimensions : iterable of
Dimension, optional An iterable of
Dimensioninstances that must be included in the graph. All (recursive) dependencies of these dimensions will also be included. At most one ofdimensionsandnamesmust be provided.- names : iterable of
str, optional An iterable of the names of dimensiosn that must be included in the graph. All (recursive) dependencies of these dimensions will also be included. At most one of
dimensionsandnamesmust be provided.- conform :
bool, optional If
True(default), expand to include dependencies.Falseshould only be used for callers that can guarantee that other arguments are already correctly expanded, and is primarily for internal use.
Notes
DimensionGraphshould be used instead of other collections in most contexts where a collection of dimensions is required and aDimensionUniverseis available. Exceptions include cases where order matters (and is different from the consistent ordering defined by theDimensionUniverse), or completeSetsemantics are required.Attributes Summary
namesA set of the names of all dimensions in the graph ( KeysView).primaryKeyTraversalOrderReturn a tuple of all elements in an order allows records to be found given their primary keys, starting from only the primary keys of required dimensions ( tuple[DimensionRecord]).spatialThe SPATIALfamilies represented by the elements in this graph.temporalThe TEMPORALfamilies represented by the elements in this graph.Methods Summary
from_json(json_str, universe, registry)Convert a JSON string created by to_jsonand return something of the supplied class.from_simple(names, universe, registry)Construct a new object from the data returned from the to_simplemethod.get(name, default)Return the element with the given name. intersection(*others)Construct a new graph containing only dimensions in all of the operands. isdisjoint(other)Test whether the intersection of two graphs is empty. issubset(other)Test whether all dimensions in selfare also inother.issuperset(other)Test whether all dimensions in otherare also inself.to_json(minimal)Convert this class to JSON form. to_simple(minimal)Convert this class to a simple python type suitable for serialization. union(*others)Construct a new graph containing all dimensions in any of the operands. Attributes Documentation
-
names¶ A set of the names of all dimensions in the graph (
KeysView).
-
primaryKeyTraversalOrder¶ Return a tuple of all elements in an order allows records to be found given their primary keys, starting from only the primary keys of required dimensions (
tuple[DimensionRecord]).Unlike the table definition/topological order (which is what DimensionUniverse.sorted gives you), when dimension A implies dimension B, dimension A appears first.
Methods Documentation
-
classmethod
from_json(json_str: str, universe: Optional[DimensionUniverse] = None, registry: Optional[Registry] = None) → SupportsSimple¶ Convert a JSON string created by
to_jsonand return something of the supplied class.Parameters: - json_str :
str Representation of the dimensions in JSON format as created by
to_json().- universe :
DimensionUniverse, optional The special graph of all known dimensions. Passed directly to
from_simple().- registry :
lsst.daf.butler.Registry, optional Registry to use to convert simple name of a DatasetType to a full
DatasetType. Passed directly tofrom_simple().
Returns: - constructed : Any
Newly-constructed object.
- json_str :
-
classmethod
from_simple(names: List[str], universe: Optional[DimensionUniverse] = None, registry: Optional[Registry] = None) → DimensionGraph¶ Construct a new object from the data returned from the
to_simplemethod.Parameters: - names :
listofstr The names of the dimensions.
- universe :
DimensionUniverse The special graph of all known dimensions of which this graph will be a subset. Can be
NoneifRegistryis provided.- registry :
lsst.daf.butler.Registry, optional Registry from which a universe can be extracted. Can be
Noneif universe is provided explicitly.
Returns: - graph :
DimensionGraph Newly-constructed object.
- names :
-
get(name: str, default: Any = None) → DimensionElement¶ Return the element with the given name.
This lookup covers all
DimensionElementinstances inself.elements, not just trueDimensioninstances).
-
intersection(*others) → lsst.daf.butler.core.dimensions._graph.DimensionGraph¶ Construct a new graph containing only dimensions in all of the operands.
-
isdisjoint(other: lsst.daf.butler.core.dimensions._graph.DimensionGraph) → bool¶ Test whether the intersection of two graphs is empty.
Returns
Trueif either operand is the empty.
-
issubset(other: lsst.daf.butler.core.dimensions._graph.DimensionGraph) → bool¶ Test whether all dimensions in
selfare also inother.Returns
Trueifselfis empty.
-
issuperset(other: lsst.daf.butler.core.dimensions._graph.DimensionGraph) → bool¶ Test whether all dimensions in
otherare also inself.Returns
Trueifotheris empty.
-
to_json(minimal: bool = False) → str¶ Convert this class to JSON form.
The class type is not recorded in the JSON so the JSON decoder must know which class is represented.
Parameters: - minimal :
bool, optional Use minimal serialization. Requires Registry to convert back to a full type.
Returns: - json :
str The class in JSON string format.
- minimal :
-
to_simple(minimal: bool = False) → List[str]¶ Convert this class to a simple python type suitable for serialization.
Parameters: - minimal :
bool, optional Use minimal serialization. Has no effect on for this class.
Returns: - names :
list The names of the dimensions.
- minimal :
-
union(*others) → lsst.daf.butler.core.dimensions._graph.DimensionGraph¶ Construct a new graph containing all dimensions in any of the operands.
The elements of the returned graph may exceed the naive union of their elements, as some
DimensionElementinstances are included in graphs whenever multiple dimensions are present, and those dependency dimensions could have been provided by different operands.
- universe :