DataCoordinate¶
-
class
lsst.daf.butler.DataCoordinate(*args, **kwds)¶ Bases:
lsst.daf.butler.NamedKeyMapping[lsst.daf.butler.Dimension,Optional[Union[str,int]]]Data ID dictionary.
An immutable data ID dictionary that guarantees that its key-value pairs identify at least all required dimensions in a
DimensionGraph.DataCoordinateSetitself is an ABC, but providesstaticmethodfactory functions for private concrete implementations that should be sufficient for most purposes.standardizeis the most flexible and safe of these; the others (makeEmpty,fromRequiredValues, andfromFullValues) are more specialized and perform little or no checking of inputs.Notes
Like any data ID class,
DataCoordinatebehaves like a dictionary, but with some subtleties:Both
Dimensioninstances andstrnames thereof may be used as keys in lookup operations, but iteration (andkeys) will yieldDimensioninstances. Thenamesproperty can be used to obtain the correspondingstrnames.Lookups for implied dimensions (those in
self.graph.implied) are supported if and only ifhasFullreturnsTrue, and are never included in iteration orkeys. Thefullproperty may be used to obtain a mapping whose keys do include implied dimensions.Equality comparison with other mappings is supported, but it always considers only required dimensions (as well as requiring both operands to identify the same dimensions). This is not quite consistent with the way mappings usually work - normally differing keys imply unequal mappings - but it makes sense in this context because data IDs with the same values for required dimensions but different values for implied dimensions represent a serious problem with the data that
DataCoordinatecannot generally recognize on its own, and a data ID that knows implied dimension values should still be able to compare as equal to one that does not. This is of course not the way comparisons between simpledictdata IDs work, and hence using aDataCoordinateinstance for at least one operand in any data ID comparison is strongly recommended.
Attributes Summary
Return mapping for all dimensions in
self.graph.Dimensions identified by this data ID (
DimensionGraph).Names of the required dimensions identified by this data ID.
Return the records.
Spatial region associated with this data ID.
Temporal interval associated with this data ID.
Universe that defines all known compatible dimensions.
Methods Summary
byName()Return a
Mappingwith names as keys and theselfvalues.expanded(records)Return a
DataCoordinatethat holds the given records.fromFullValues(graph, values)Construct a
DataCoordinatefrom all dimension values.fromRequiredValues(graph, values)Construct a
DataCoordinatefrom required dimension values.from_json(json_str[, universe, registry])Return new class from JSON string.
from_simple(simple[, universe, registry])Construct a new object from the simplified form.
get(k[,d])hasFull()Whether this data ID contains implied and required values.
Whether this data ID contains records.
items()keys()makeEmpty(universe)Return an empty
DataCoordinate.pack(name, *[, returnMaxBits])Pack this data ID into an integer.
standardize([mapping, graph, universe, defaults])Standardize the supplied dataId.
subset(graph)Return a
DataCoordinatewhose graph is a subset ofself.graph.to_json([minimal])Convert this class to JSON form.
to_simple([minimal])Convert this class to a simple python type.
union(other)Combine two data IDs.
values()Attributes Documentation
-
full¶ Return mapping for all dimensions in
self.graph.The mapping includes key-value pairs for all dimensions in
self.graph, including implied (NamedKeyMapping).Accessing this attribute if
hasFullreturnsFalseis a logic error that may raise an exception of unspecified type either immediately or when implied keys are accessed via the returned mapping, depending on the implementation and whether assertions are enabled.
-
graph¶ Dimensions identified by this data ID (
DimensionGraph).Note that values are only required to be present for dimensions in
self.graph.required; all others may be retrieved (from aRegistry) given these.
-
names¶ Names of the required dimensions identified by this data ID.
They are returned in the same order as
keys(collections.abc.Set[str]).
-
records¶ Return the records.
Returns a mapping that contains
DimensionRecordobjects for all elements identified by this data ID (NamedKeyMapping).The values of this mapping may be
Noneif and only if there is no record for that element with these dimensions in the database (which means some foreign key field must have a NULL value).Accessing this attribute if
hasRecordsreturnsFalseis a logic error that may raise an exception of unspecified type either immediately or when the returned mapping is used, depending on the implementation and whether assertions are enabled.
-
region¶ Spatial region associated with this data ID.
(
lsst.sphgeom.RegionorNone).This is
Noneif and only ifself.graph.spatialis empty.Accessing this attribute if
hasRecordsreturnsFalseis a logic error that may or may not raise an exception, depending on the implementation and whether assertions are enabled.
-
timespan¶ Temporal interval associated with this data ID.
This is
Noneif and only ifself.graph.timespanis empty.Accessing this attribute if
hasRecordsreturnsFalseis a logic error that may or may not raise an exception, depending on the implementation and whether assertions are enabled.
-
universe¶ Universe that defines all known compatible dimensions.
The univers will be compatible with this coordinate (
DimensionUniverse).
Methods Documentation
-
abstract
expanded(records: Union[lsst.daf.butler.NamedKeyMapping[lsst.daf.butler.DimensionElement, Optional[lsst.daf.butler.DimensionRecord]], Mapping[str, Optional[lsst.daf.butler.DimensionRecord]]]) →lsst.daf.butler.DataCoordinate¶ Return a
DataCoordinatethat holds the given records.Guarantees that
hasRecordsreturnsTrue.This is a low-level interface with at most assertion-level checking of inputs. Most callers should use
Registry.expandDataIdinstead.- Parameters
- records
Mapping[str,DimensionRecordorNone] A
NamedKeyMappingwithDimensionElementkeys or a regularMappingwithstr(DimensionElementname) keys andDimensionRecordvalues. Keys must cover all elements inself.graph.elements. Values may beNone, but only to reflect actual NULL values in the database, not just records that have not been fetched.
- records
-
static
fromFullValues(graph:lsst.daf.butler.DimensionGraph, values: Tuple[Optional[Union[str, int]], …]) →lsst.daf.butler.DataCoordinate¶ Construct a
DataCoordinatefrom all dimension values.This is a low-level interface with at most assertion-level checking of inputs. Most callers should use
standardizeinstead.- Parameters
- graph
DimensionGraph Dimensions this data ID will identify.
- values
tuple[intorstr] Tuple of primary key values corresponding to
itertools.chain(graph.required, graph.implied), in that order. Note that this is _not_ the same order asgraph.dimensions, though these contain the same elements.
- graph
- Returns
- dataId
DataCoordinate A data ID object that identifies the given dimensions.
dataId.hasFull()will returnTrueif and only ifgraph.impliedis empty, anddataId.hasRecords()will never returnTrue.
- dataId
-
static
fromRequiredValues(graph:lsst.daf.butler.DimensionGraph, values: Tuple[Optional[Union[str, int]], …]) →lsst.daf.butler.DataCoordinate¶ Construct a
DataCoordinatefrom required dimension values.This is a low-level interface with at most assertion-level checking of inputs. Most callers should use
standardizeinstead.- Parameters
- graph
DimensionGraph Dimensions this data ID will identify.
- values
tuple[intorstr] Tuple of primary key values corresponding to
graph.required, in that order.
- graph
- Returns
- dataId
DataCoordinate A data ID object that identifies the given dimensions.
dataId.hasFull()will returnTrueif and only ifgraph.impliedis empty, anddataId.hasRecords()will never returnTrue.
- dataId
-
classmethod
from_json(json_str: str, universe: Optional[DimensionUniverse] = None, registry: Optional[Registry] = None) → SupportsSimple¶ Return new class from JSON string.
Converts 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().
- json_str
- Returns
- constructedAny
Newly-constructed object.
-
classmethod
from_simple(simple: Dict[str, Any], universe: Optional[DimensionUniverse] = None, registry: Optional[Registry] = None) → DataCoordinate¶ Construct a new object from the simplified form.
The data is assumed to be of the form returned from the
to_simplemethod.- Parameters
- simple
dictof [str,Any] The
dictreturned byto_simple().- universe
DimensionUniverse The special graph of all known dimensions.
- registry
lsst.daf.butler.Registry, optional Registry from which a universe can be extracted. Can be
Noneif universe is provided explicitly.
- simple
- Returns
- dataId
DataCoordinate Newly-constructed object.
- dataId
-
get(k[, d]) → D[k] if k in D, else d. d defaults to None.¶
-
abstract
hasFull() → bool¶ Whether this data ID contains implied and required values.
- Returns
- state
bool If
True,__getitem__,get, and__contains__(but notkeys!) will act as though the mapping includes key-value pairs for implied dimensions, and thefullproperty may be used. IfFalse, these operations only include key-value pairs for required dimensions, and accessingfullis an error. AlwaysTrueif there are no implied dimensions.
- state
-
abstract
hasRecords() → bool¶ Whether this data ID contains records.
These are the records for all of the dimension elements it identifies.
-
items() → a set-like object providing a view on D’s items¶
-
keys() → a set-like object providing a view on D’s keys¶
-
static
makeEmpty(universe: DimensionUniverse) → DataCoordinate¶ Return an empty
DataCoordinate.It identifies the null set of dimensions.
- Parameters
- universe
DimensionUniverse Universe to which this null dimension set belongs.
- universe
- Returns
- dataId
DataCoordinate A data ID object that identifies no dimensions.
hasFullandhasRecordsare guaranteed to returnTrue, because bothfullandrecordsare just empty mappings.
- dataId
-
pack(name: str, *, returnMaxBits: bool = False) → Union[Tuple[int, int], int]¶ Pack this data ID into an integer.
- Parameters
- name
str Name of the
DimensionPackeralgorithm (as defined in the dimension configuration).- returnMaxBits
bool, optional If
True(Falseis default), return the maximum number of nonzero bits in the returned integer across all data IDs.
- name
- Returns
Notes
Accessing this attribute if
hasRecordsreturnsFalseis a logic error that may or may not raise an exception, depending on the implementation and whether assertions are enabled.
-
static
standardize(mapping: Optional[NameLookupMapping[Dimension, DataIdValue]] = None, *, graph: Optional[DimensionGraph] = None, universe: Optional[DimensionUniverse] = None, defaults: Optional[DataCoordinate] = None, **kwargs: Any) → DataCoordinate¶ Standardize the supplied dataId.
Adapts an arbitrary mapping and/or additional arguments into a true
DataCoordinate, or augment an existing one.- Parameters
- mapping
Mapping, optional An informal data ID that maps dimensions or dimension names to their primary key values (may also be a true
DataCoordinate).- graph
DimensionGraph The dimensions to be identified by the new
DataCoordinate. If not provided, will be inferred from the keys ofmappingand**kwargs, anduniversemust be provided unlessmappingis already aDataCoordinate.- universe
DimensionUniverse All known dimensions and their relationships; used to expand and validate dependencies when
graphis not provided.- defaults
DataCoordinate, optional Default dimension key-value pairs to use when needed. These are never used to infer
graph, and are ignored if a different value is provided for the same key inmappingor**kwargs`.- **kwargs
Additional keyword arguments are treated like additional key-value pairs in
mapping.
- mapping
- Returns
- coordinate
DataCoordinate A validated
DataCoordinateinstance.
- coordinate
- Raises
- TypeError
Raised if the set of optional arguments provided is not supported.
- KeyError
Raised if a key-value pair for a required dimension is missing.
-
abstract
subset(graph:lsst.daf.butler.DimensionGraph) →lsst.daf.butler.DataCoordinate¶ Return a
DataCoordinatewhose graph is a subset ofself.graph.- Parameters
- graph
DimensionGraph The dimensions identified by the returned
DataCoordinate.
- graph
- Returns
- coordinate
DataCoordinate A
DataCoordinateinstance that identifies only the given dimensions. May beselfifgraph == self.graph.
- coordinate
- Raises
- KeyError
Raised if the primary key value for one or more required dimensions is unknown. This may happen if
graph.issubset(self.graph)isFalse, or even ifgraph.issubset(self.graph)isTrue, ifself.hasFull()isFalseandgraph.required.issubset(self.graph.required)isFalse. As an example of the latter case, consider trying to go from a data ID with dimensions {instrument, physical_filter, band} to just {instrument, band}; band is implied by physical_filter and hence would have no value in the original data ID ifself.hasFull()isFalse.
Notes
If
hasFullandhasRecordsreturnTrueonself, they will returnTrue(respectively) on the returnedDataCoordinateas well. The converse does not hold.
-
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.
-
to_simple(minimal: bool = False) → Dict¶ Convert this class to a simple python type.
This is suitable for serialization.
-
abstract
union(other:lsst.daf.butler.DataCoordinate) →lsst.daf.butler.DataCoordinate¶ Combine two data IDs.
Yields a new one that identifies all dimensions that either of them identify.
- Parameters
- other
DataCoordinate Data ID to combine with
self.
- other
- Returns
- unioned
DataCoordinate A
DataCoordinateinstance that satisfiesunioned.graph == self.graph.union(other.graph). Will preservehasFullandhasRecordswhenever possible.
- unioned
Notes
No checking for consistency is performed on values for keys that
selfandotherhave in common, and which value is included in the returned data ID is not specified.
-
values() → an object providing a view on D’s values¶