DatasetProvenance¶
- class lsst.daf.butler.DatasetProvenance(*, inputs: list[lsst.daf.butler._dataset_ref.SerializedDatasetRef] = <factory>, quantum_id: ~uuid.UUID | None = None, extras: dict[uuid.UUID, dict[str, str | int | float | bool | None | uuid.UUID]] = <factory>)¶
Bases:
BaseModel
Provenance of a single
DatasetRef
.Attributes Summary
Configuration for the model, should be a dictionary conforming to [
ConfigDict
][pydantic.config.ConfigDict].Methods Summary
add_extra_provenance
(dataset_id, extra)Attach extra provenance to a specific dataset.
add_input
(ref)Add an input dataset to the provenance.
from_flat_dict
(prov_dict, butler)Create a provenance object from a provenance dictionary.
model_post_init
(context, /)This function is meant to behave like a BaseModel method to initialise private attributes.
strip_provenance_from_flat_dict
(prov_dict)Remove provenance keys from a mapping that had been populated by
to_flat_dict
.to_flat_dict
(ref, /, *[, prefix, sep, ...])Return provenance as a flattened dictionary.
Attributes Documentation
- model_config: ClassVar[ConfigDict] = {}¶
Configuration for the model, should be a dictionary conforming to [
ConfigDict
][pydantic.config.ConfigDict].
Methods Documentation
- add_extra_provenance(dataset_id: uuid.UUID, extra: Mapping[str, _PROV_TYPES]) None ¶
Attach extra provenance to a specific dataset.
- Parameters:
- dataset_id
uuid.UUID
The ID of the dataset to receive this provenance.
- extra
Mapping
[str
,typing.Any
] The extra provenance information as a dictionary. The values must be simple Python scalars or scalars that can be serialized by Pydantic and convert to a simple string value.
- dataset_id
Notes
The keys in the extra provenance can not include provenance keys of
run
,id
, ordatasettype
(in upper or lower case).
- add_input(ref: DatasetRef) None ¶
Add an input dataset to the provenance.
- Parameters:
- ref
DatasetRef
A dataset to register as an input.
- ref
- classmethod from_flat_dict(prov_dict: Mapping[str, Any], butler: Butler) tuple[Self, DatasetRef | None] ¶
Create a provenance object from a provenance dictionary.
- Parameters:
- prov_dict
collections.abc.Mapping
Dictionary populated by
to_flat_dict
.- butler
lsst.daf.butler.Butler
Butler to query to find references datasets.
- prov_dict
- Returns:
- prov
DatasetProvenance
Provenance extracted from this object.
- ref
DatasetRef
orNone
Dataset associated with this provenance. Can be
None
if no provenance found.
- prov
- Raises:
- ValueError
Raised if no provenance values are found in the dictionary.
- RuntimeError
Raised if a referenced dataset is not known to the given butler.
- model_post_init(context: Any, /) None ¶
This function is meant to behave like a BaseModel method to initialise private attributes.
It takes context as an argument since that’s what pydantic-core passes when calling it.
- Args:
self: The BaseModel instance. context: The context.
- classmethod strip_provenance_from_flat_dict(prov_dict: MutableMapping[str, Any]) None ¶
Remove provenance keys from a mapping that had been populated by
to_flat_dict
.- Parameters:
- prov_dict
collections.abc.MutableMapping
Dictionary to modify.
- prov_dict
- to_flat_dict(ref: DatasetRef | None, /, *, prefix: str = '', sep: str = '.', simple_types: bool = False, use_upper: bool | None = None) dict[str, str | int | float | bool | None | uuid.UUID] ¶
Return provenance as a flattened dictionary.
- Parameters:
- ref
DatasetRef
orNone
If given, a dataset for which this provenance is relevant and should be included.
- prefix
str
, optional A prefix to use for each key in the provenance dictionary.
- sep
str
, optional Separator to use to represent hierarchy. Must be a single character. Can not be a number, letter, or underscore (to avoid confusion with provenance keys themselves).
- simple_types
bool
, optional If
True
only simple Python types will be used in the returned dictionary, specifically UUIDs will be returned asstr
. IfFalse
, UUIDs will be returned asuuid.UUID
. Complex types found inDatasetProvenance.extras
will be cast to astr
ifTrue
.- use_upper
bool
orNone
, optional If
None
the case of the keys matches the case of the first character of the prefix (defined by whetherstr.isupper()
returns true, else they will be lower case). IfFalse
the case will be lower case, and ifTrue
the case will be upper case.
- ref
- Returns:
- prov
dict
Dictionary representing the provenance. The keys are defined in the notes below.
- prov
- Raises:
- ValueError
Raised if the separator is not a single character.
Notes
Keys from the given dataset (all optional if no dataset is given):
- Id:
UUID of the given dataset.
- Run:
Run of the given dataset.
- Datasettype:
Dataset type of the given dataset.
- Dataid x:
An entry for each required dimension, “x”, in the data ID.
Each input dataset will have the
id
,run
, anddatasettype
keys as defined above (but nodataid
key) with aninput N
prefix whereN
starts counting at 0.The quantum ID, if present, will use key
quantum
.Examples
>>> provenance.to_flat_dict( ... ref, prefix="lsst.butler", sep=".", simple_types=True ... ) { "lsst.butler.id": "ae0fa83d-cc89-41dd-9680-f97ede49f01e", "lsst.butler.run": "test_run", "lsst.butler.datasettype": "data", "lsst.butler.dataid.detector": 10, "lsst.butler.dataid.instrument": "LSSTCam", "lsst.butler.quantum": "d93a735b-08f0-477d-bc95-2cc32d6d898b", "lsst.butler.input.0.id": "3dfd7ba5-5e35-4565-9d87-4b33880ed06c", "lsst.butler.input.0.run": "other_run", "lsst.butler.input.0.datasettype": "astropy_parquet", "lsst.butler.input.1.id": "7a99f6e9-4035-3d68-842e-58ecce1dc935", "lsst.butler.input.1.run": "other_run", "lsst.butler.input.1.datasettype": "astropy_parquet", }