DatasetRef¶
-
class
lsst.daf.butler.DatasetRef(datasetType: lsst.daf.butler.core.datasets.type.DatasetType, dataId: lsst.daf.butler.core.dimensions._coordinate.DataCoordinate, *, id: Optional[int] = None, run: Optional[str] = None, conform: bool = True)¶ Bases:
objectReference to a Dataset in a
Registry.A
DatasetRefmay point to a Dataset that currently does not yet exist (e.g., because it is a predicted input for provenance).Parameters: - datasetType :
DatasetType The
DatasetTypefor this Dataset.- dataId :
DataCoordinate A mapping of dimensions that labels the Dataset within a Collection.
- id :
int, optional The unique integer identifier assigned when the dataset is created.
- run :
str, optional The name of the run this dataset was associated with when it was created. Must be provided if
idis.- conform :
bool, optional If
True(default), callDataCoordinate.standardizeto ensure that the data ID’s dimensions are consistent with the dataset type’s.DatasetRefinstances for which those dimensions are not equal should not be created in new code, but are still supported for backwards compatibility. New code should only passFalseif it can guarantee that the dimensions are already consistent.
Raises: - ValueError
Raised if
runis provided butidis not, or ifidis provided butrunis not.
Attributes Summary
dataIdA mapping of Dimensionprimary key values that labels the dataset within a Collection (DataCoordinate).datasetTypeThe definition of this dataset ( DatasetType).dimensionsDimensions associated with the underlying DatasetType.idPrimary key of the dataset ( intorNone).runThe name of the run that produced the dataset. Methods Summary
expanded(dataId)Return a new DatasetRefwith the given expanded data ID.from_json(json_str, universe, registry)Return new class from JSON string. from_simple(simple, universe, registry)Construct a new object from simplified form. getCheckedId()Return self.id, or raise if it isNone.groupByType(refs)Group an iterable of DatasetRefbyDatasetType.isComponent()Indicate whether this DatasetRefrefers to a component.isComposite()Boolean indicating whether this DatasetRefis a composite type.makeComponentRef(name)Create a DatasetRefthat corresponds to a component.makeCompositeRef()Create a DatasetRefof the composite from a component ref.resolved(id, run)Return resolved DatasetRef.to_json(minimal)Convert this class to JSON form. to_simple(minimal)Convert this class to a simple python type. unresolved()Return unresolved DatasetRef.Attributes Documentation
-
dataId¶ A mapping of
Dimensionprimary key values that labels the dataset within a Collection (DataCoordinate).Cannot be changed after a
DatasetRefis constructed.
-
datasetType¶ The definition of this dataset (
DatasetType).Cannot be changed after a
DatasetRefis constructed.
-
dimensions¶ Dimensions associated with the underlying
DatasetType.
-
id¶ Primary key of the dataset (
intorNone).Cannot be changed after a
DatasetRefis constructed; useresolvedorunresolvedto add or remove this information when creating a newDatasetRef.
-
run¶ The name of the run that produced the dataset.
Cannot be changed after a
DatasetRefis constructed; useresolvedorunresolvedto add or remove this information when creating a newDatasetRef.
Methods Documentation
-
expanded(dataId: lsst.daf.butler.core.dimensions._coordinate.DataCoordinate) → lsst.daf.butler.core.datasets.ref.DatasetRef¶ Return a new
DatasetRefwith the given expanded data ID.Parameters: - dataId :
DataCoordinate Data ID for the new
DatasetRef. Must compare equal to the original data ID.
Returns: - ref :
DatasetRef A new
DatasetRefwith the given data ID.
- 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().
Returns: - constructed : Any
Newly-constructed object.
- json_str :
-
classmethod
from_simple(simple: Dict, universe: Optional[DimensionUniverse] = None, registry: Optional[Registry] = None) → DatasetRef¶ Construct a new object from simplified form.
Generally this is data returned from the
to_simplemethod.Parameters: - simple :
dictof [str,Any] The value returned by
to_simple().- universe :
DimensionUniverse The special graph of all known dimensions. Can be
Noneif a registry is provided.- registry :
lsst.daf.butler.Registry, optional Registry to use to convert simple form of a DatasetRef to a full
DatasetRef. Can beNoneif a full description of the type is provided along with a universe.
Returns: - ref :
DatasetRef Newly-constructed object.
- simple :
-
getCheckedId() → int¶ Return
self.id, or raise if it isNone.This trivial method exists to allow operations that would otherwise be natural list comprehensions to check that the ID is not
Noneas well.Returns: Raises: - AmbiguousDatasetError
Raised if
ref.idisNone.
-
static
groupByType(refs: Iterable[lsst.daf.butler.core.datasets.ref.DatasetRef]) → lsst.daf.butler.core.named.NamedKeyDict[lsst.daf.butler.core.datasets.type.DatasetType, typing.List[lsst.daf.butler.core.datasets.ref.DatasetRef]][lsst.daf.butler.core.datasets.type.DatasetType, List[lsst.daf.butler.core.datasets.ref.DatasetRef]]¶ Group an iterable of
DatasetRefbyDatasetType.Parameters: - refs :
Iterable[DatasetRef] DatasetRefinstances to group.
Returns: - grouped :
NamedKeyDict[DatasetType,list[DatasetRef] ] Grouped
DatasetRefinstances.
- refs :
-
isComponent() → bool¶ Indicate whether this
DatasetRefrefers to a component.Returns: - isComponent :
bool Trueif thisDatasetRefis a component,Falseotherwise.
- isComponent :
-
isComposite() → bool¶ Boolean indicating whether this
DatasetRefis a composite type.Returns: - isComposite :
bool Trueif thisDatasetRefis a composite type,Falseotherwise.
- isComposite :
-
makeComponentRef(name: str) → lsst.daf.butler.core.datasets.ref.DatasetRef¶ Create a
DatasetRefthat corresponds to a component.Parameters: - name :
str Name of the component.
Returns: - ref :
DatasetRef A
DatasetRefwith a dataset type that corresponds to the given component, and the same ID and run (which may beNone, if they areNoneinself).
- name :
-
makeCompositeRef() → lsst.daf.butler.core.datasets.ref.DatasetRef¶ Create a
DatasetRefof the composite from a component ref.Requires that this
DatasetRefis a component.Returns: - ref :
DatasetRef A
DatasetRefwith a dataset type that corresponds to the composite parent of this component, and the same ID and run (which may beNone, if they areNoneinself).
- ref :
-
resolved(id: int, run: str) → lsst.daf.butler.core.datasets.ref.DatasetRef¶ Return resolved
DatasetRef.This is a new
DatasetRefwith the same data ID and dataset type and the given ID and run.Parameters: Returns: - ref :
DatasetRef A new
DatasetRef.
- ref :
-
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) → Dict[KT, VT]¶ Convert this class to a simple python type.
This makes it suitable for serialization.
Parameters: - minimal :
bool, optional Use minimal serialization. Requires Registry to convert back to a full type.
Returns: - minimal :
-
unresolved() → lsst.daf.butler.core.datasets.ref.DatasetRef¶ Return unresolved
DatasetRef.This is a new
DatasetRefwith the same data ID and dataset type, but no ID or run.Returns: - ref :
DatasetRef A new
DatasetRef.
Notes
This can be used to compare only the data ID and dataset type of a pair of
DatasetRefinstances, regardless of whether either is resolved:if ref1.unresolved() == ref2.unresolved(): ...
- ref :
- datasetType :