DatasetRef¶
- class lsst.daf.butler.DatasetRef(datasetType: DatasetType, dataId: DataCoordinate, *, id: UUID | None = None, run: str | None = None, conform: bool = True, id_generation_mode: DatasetIdGenEnum = DatasetIdGenEnum.UNIQUE)¶
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
DatasetId, optional The unique identifier assigned when the dataset is created. If
runis specified andidis not specified, an ID will be 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.- id_generation_mode
DatasetIdGenEnum ID generation option.
UNIQUEmakes a random UUID4-type ID.DATAID_TYPEmakes a deterministic UUID5-type ID based on a dataset type name anddataId.DATAID_TYPE_RUNmakes a deterministic UUID5-type ID based on a dataset type name, run collection name, anddataId.
- datasetType
- Raises:
- ValueError
Raised if
runis provided butidis not, or ifidis provided butrunis not.
See also
Attributes Summary
A mapping of
Dimensionprimary key values that labels the dataset within a Collection (DataCoordinate).The definition of this dataset (
DatasetType).Dimensions associated with the underlying
DatasetType.Primary key of the dataset (
DatasetIdorNone).The 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])Convert from JSON to a pydantic model.
from_simple(simple[, universe, registry, ...])Construct a new object from simplified form.
Return
self.id, or raise if it isNone.groupByType(refs)Group an iterable of
DatasetRefbyDatasetType.Indicate whether this
DatasetRefrefers to a component.Boolean indicating whether this
DatasetRefis a composite type.makeComponentRef(name)Create a
DatasetRefthat corresponds to a component.Create a
DatasetRefof the composite from a component ref.overrideStorageClass(storageClass)Create a new
DatasetReffrom this one, but with a modifiedDatasetTypethat has a differentStorageClass.resolved(id, run)Return resolved
DatasetRef.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.
Return unresolved
DatasetRef.Attributes Documentation
- dataId: DataCoordinate¶
A mapping of
Dimensionprimary key values that labels the dataset within a Collection (DataCoordinate).Cannot be changed after a
DatasetRefis constructed.
- datasetType: DatasetType¶
The definition of this dataset (
DatasetType).Cannot be changed after a
DatasetRefis constructed.
- dimensions¶
Dimensions associated with the underlying
DatasetType.
- id: DatasetId | None¶
Primary key of the dataset (
DatasetIdorNone).Cannot be changed after a
DatasetRefis constructed; useresolvedorunresolvedto add or remove this information when creating a newDatasetRef.
- run: str | None¶
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: DataCoordinate) 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.
- dataId
- Returns:
- ref
DatasetRef A new
DatasetRefwith the given data ID.
- ref
- classmethod from_json(json_str: str, universe: DimensionUniverse | None = None, registry: Registry | None = None) SupportsSimple¶
Convert from JSON to a pydantic model.
- classmethod from_simple(simple: SerializedDatasetRef, universe: DimensionUniverse | None = None, registry: Registry | None = None, datasetType: DatasetType | None = 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.- datasetTypeDatasetType, optional
If datasetType is supplied, this will be used as the datasetType object in the resulting DatasetRef instead of being read from the
SerializedDatasetRef. This is useful when many refs share the same type as memory can be saved. Defaults to None.
- simple
- Returns:
- ref
DatasetRef Newly-constructed object.
- ref
- getCheckedId() UUID¶
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.
- static groupByType(refs: Iterable[DatasetRef]) NamedKeyDict[DatasetType, List[DatasetRef]]¶
Group an iterable of
DatasetRefbyDatasetType.- Parameters:
- refs
Iterable[DatasetRef] DatasetRefinstances to group.
- refs
- Returns:
- grouped
NamedKeyDict[DatasetType,list[DatasetRef] ] Grouped
DatasetRefinstances.
- grouped
- 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) DatasetRef¶
Create a
DatasetRefthat corresponds to a component.- Parameters:
- name
str Name of the component.
- name
- 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).
- ref
- makeCompositeRef() 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
- overrideStorageClass(storageClass: str | StorageClass) DatasetRef¶
Create a new
DatasetReffrom this one, but with a modifiedDatasetTypethat has a differentStorageClass.- Parameters:
- storageClass
strorStorageClass The new storage class.
- storageClass
- Returns:
- modified
DatasetRef A new dataset reference that is the same as the current one but with a different storage class in the
DatasetType.
- modified
- resolved(id: UUID, run: str) DatasetRef¶
Return resolved
DatasetRef.This is a new
DatasetRefwith the same data ID and dataset type and the given ID and run.- Parameters:
- id
DatasetId The unique identifier assigned when the dataset is created.
- run
str The run this dataset was associated with when it was created.
- id
- Returns:
- ref
DatasetRef A new
DatasetRef.
Deprecated since version 26.0: This method will soon be a no-op since it will be impossible to create an unresolved ref.
- ref
- to_json(minimal: bool = False) str¶
Convert this class to JSON assuming that the
to_simple()returns a pydantic model.
- to_simple(minimal: bool = False) SerializedDatasetRef¶
Convert this class to a simple python type.
This makes it suitable for serialization.
- unresolved() 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.
- ref
Deprecated since version 26.0: Support for unresolved refs will soon be removed. Please contact middleware developers with advice on how to modify your code.