DataCoordinate¶
- class lsst.daf.butler.DataCoordinate¶
Bases:
NamedKeyMapping[Dimension,int|str|None]A validated data ID.
DataCoordinate guarantees that its key-value pairs identify at least all required dimensions in a
DimensionGroup.Notes
DataCoordinateis an ABC, but it providesstaticmethodfactory functions for private concrete implementations that should be sufficient for most purposes.standardizeis the most flexible and safe of these; the others (make_empty,from_required_values, andfrom_full_values) are more specialized and perform little or no checking of inputs.Lookups for implied dimensions (those in
self.dimensions.implied) are supported if and only ifhas_full_valuesisTrue. This also sets the keys of themappingattribute. This means thatDataCoordinateequality is not the same as testing for equality on themappingattribute (instead, it is the same as testing for equality on therequiredattribute).See also Data IDs
Attributes Summary
Dimensions identified by this data ID (
DimensionGroup).Return mapping for all dimensions in
self.dimensions.The full values (only) of this data ID as a tuple.
Dimensions identified by this data ID (
DimensionGraph).A mapping view of the data ID with keys for all dimensions it has values for.
Names of the required dimensions identified by this data ID.
A mapping that contains
DimensionRecordobjects for all elements identified by this data ID.Spatial region associated with this data ID.
A mapping view of the data ID with keys for just its required dimensions.
The required values (only) of this data ID as a tuple.
Temporal interval associated with this data ID.
Universe that defines all known compatible dimensions.
Methods Summary
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_full_values(dimensions, values)Construct a
DataCoordinatefrom all dimension values.from_json(json_str[, universe, registry])Convert from JSON to a pydantic model.
from_required_values(dimensions, values)Construct a
DataCoordinatefrom required dimension values.from_simple(simple[, universe, registry])Construct a new object from the simplified form.
hasFull()Whether this data ID contains implied and required values.
Whether this data ID contains records.
keys()Deprecated since version v27.
makeEmpty(universe)Return an empty
DataCoordinate.make_empty(universe)Return an empty
DataCoordinate.standardize([mapping, dimensions, graph, ...])Standardize the supplied dataId.
subset(dimensions)Return a
DataCoordinatewhose graph is a subset ofself.graph.to_json([minimal])Convert this class to JSON assuming that the
to_simple()returns a pydantic model.to_simple([minimal])Convert this class to a simple python type.
union(other)Combine two data IDs.
Return the required values (only) of this data ID as a tuple.
Attributes Documentation
- dimensions¶
Dimensions identified by this data ID (
DimensionGroup).Note that values are only required to be present for dimensions in
self.dimensions.required; all others may be retrieved (from aRegistry) given these.
- full¶
Return mapping for all dimensions in
self.dimensions.The mapping includes key-value pairs for all dimensions in
self.dimensions, including implied.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.Deprecated since version v27: DataCoordinate.full is deprecated in favor of .mapping, and will be dropped after v27.
- full_values¶
The full values (only) of this data ID as a tuple.
Element order is consistent with
DimensionGroup.data_coordinate_keys, i.e. all required dimensions followed by all implied dimensions.
- 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.Deprecated since version v27: DataCoordinate.graph is deprecated in favor of .dimensions, and will be dropped after v27.
- mapping¶
A mapping view of the data ID with keys for all dimensions it has values for.
- names¶
Names of the required dimensions identified by this data ID.
They are returned in the same order as
keys(collections.abc.Set[str]).Deprecated since version v27: DataCoordinate.names is deprecated in favor of the .dimensions attribute, and will be dropped after v27.
- records¶
A mapping that contains
DimensionRecordobjects for all elements identified by this data ID.This mapping will become a regular
Mappingwithstrkeys after v27.Notes
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.dimensions.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.
- required¶
A mapping view of the data ID with keys for just its required dimensions.
- required_values¶
The required values (only) of this data ID as a tuple.
Element order is consistent with
required.In contexts where all data IDs have the same dimensions, comparing and hashing these tuples can be much faster than comparing the original
DataCoordinateinstances.
- timespan¶
Temporal interval associated with this data ID.
This is
Noneif and only ifself.dimensions.temporalis 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 universe will be compatible with this coordinate (
DimensionUniverse).
Methods Documentation
- abstract expanded(records: NamedKeyMapping[DimensionElement, DimensionRecord | None] | Mapping[str, DimensionRecord | None]) 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. Passing aNamedKeyMappingis deprecated and will not be supported after v27.
- records
- static fromFullValues(graph: DimensionGraph, values: tuple[int | str | None, ...]) DataCoordinate¶
Construct a
DataCoordinatefrom all dimension values.This method is deprecated in favor of
from_full_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 always returnTrue.dataId.hasRecords()will only returnTrueifgraphis empty.
Deprecated since version v27: fromFullValues is deprecated in favor of from_full_values, which takes a DimensionGroup instead of a DimensionGraph. It will be removed after v27.
- dataId
- static fromRequiredValues(graph: DimensionGraph, values: tuple[int | str | None, ...]) DataCoordinate¶
Construct a
DataCoordinatefrom required dimension values.This method is deprecated in favor of
from_required_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 returnTrueonly ifgraph.impliedis empty.dataId.hasRecords()will returnTrueif and only ifgraphis empty.
Deprecated since version v27: fromRequiredValues is deprecated in favor of from_required_values, which takes a DimensionGroup instead of a DimensionGraph. It will be removed after v27.
- dataId
- static from_full_values(dimensions: DimensionGroup, values: tuple[int | str | None, ...]) 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:
- dimensions
DimensionGroup 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.
- dimensions
- Returns:
- data_id
DataCoordinate A data ID object that identifies the given dimensions.
dataId.hasFull()will always returnTrue.dataId.hasRecords()will only returnTrueifdimensionsis empty.
- data_id
- classmethod from_json(json_str: str, universe: DimensionUniverse | None = None, registry: Registry | None = None) SupportsSimple¶
Convert from JSON to a pydantic model.
- Parameters:
- cls_
typeofSupportsSimple The Python type being created.
- json_str
str The JSON string representing this object.
- universe
DimensionUniverseorNone, optional The universe required to instantiate some models. Required if
registryisNone.- registry
RegistryorNone, optional Registry from which to obtain the dimension universe if an explicit universe has not been given.
- cls_
- Returns:
- model
SupportsSimple Pydantic model constructed from JSON and validated.
- model
- static from_required_values(dimensions: DimensionGroup, values: tuple[int | str | None, ...]) 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:
- dimensions
DimensionGroup Dimensions this data ID will identify.
- values
tuple[intorstr] Tuple of primary key values corresponding to
graph.required, in that order.
- dimensions
- Returns:
- data_id
DataCoordinate A data ID object that identifies the given dimensions.
dataId.hasFull()will returnTrueonly ifdimensions.impliedis empty.dataId.hasRecords()will returnTrueif and only ifgraphis empty.
- data_id
- classmethod from_simple(simple: SerializedDataCoordinate, universe: DimensionUniverse | None = None, registry: Registry | None = 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 Object that manages 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
- 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.
- keys() NamedValueAbstractSet[Dimension]¶
Deprecated since version v27: Using DataCoordinate as a Mapping is deprecated in favor of the .mapping and .required attributes, and will be dropped after v27.
- 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
- static make_empty(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:
- data_id
DataCoordinate A data ID object that identifies no dimensions.
hasFullandhasRecordsare guaranteed to returnTrue, because bothfullandrecordsare just empty mappings.
- data_id
- static standardize(mapping: NameLookupMapping[Dimension, DataIdValue] | None = None, *, dimensions: Iterable[str] | DimensionGroup | DimensionGraph | None = None, graph: DimensionGraph | None = None, universe: DimensionUniverse | None = None, defaults: DataCoordinate | None = 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).- dimensions
Iterable[str],DimensionGrouporDimensionGraph, optional 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.- graph
DimensionGraph, optional Like
dimensions, but requires aDimensionGraphinstance. Ignored ifdimensionsis provided. Deprecated and will be removed after v27.- 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(dimensions: DimensionGraph | DimensionGroup | Iterable[str]) DataCoordinate¶
Return a
DataCoordinatewhose graph is a subset ofself.graph.- Parameters:
- dimensions
DimensionGraph,DimensionGroup, orIterable[str] The dimensions identified by the returned
DataCoordinate. Passing aDimensionGraphis deprecated and support will be dropped after v27.
- dimensions
- 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 even if the required subset of the new dimensions are not a subset of the dimensions actually known by this data ID.. As an example, 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 if
self.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 assuming that the
to_simple()returns a pydantic model.- Parameters:
- minimal
bool Return minimal possible representation.
- minimal
- to_simple(minimal: bool = False) SerializedDataCoordinate¶
Convert this class to a simple python type.
This is suitable for serialization.
- Parameters:
- minimal
bool, optional Use minimal serialization. If set the records will not be attached.
- minimal
- Returns:
- simple
SerializedDataCoordinate The object converted to simple form.
- simple
- abstract union(other: DataCoordinate) 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.dimensions == self.dimensions.union(other.dimensions). 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_tuple() tuple[int | str | None, ...]¶
Return the required values (only) of this data ID as a tuple.
In contexts where all data IDs have the same dimensions, comparing and hashing these tuples can be much faster than comparing the original
DataCoordinateinstances.Deprecated since version v27: DataCoordinate.values_tuple() is deprecated in favor of .required_values, and will be dropped after v27.