StorageClassDelegate

class lsst.daf.butler.StorageClassDelegate(storageClass: StorageClass)

Bases: object

Delegate class for StorageClass components and parameters.

This class delegates the handling of components and parameters for the python type associated with a particular StorageClass.

A delegate is required for any storage class that defines components (derived or otherwise) or support read parameters. It is used for composite disassembly and assembly.

Parameters:
storageClassStorageClass

StorageClass to be used with this delegate.

Attributes:
storageClassStorageClass

Methods Summary

assemble(components[, pytype])

Construct an object from components based on storageClass.

disassemble(composite[, subset, override])

Disassembler a composite.

getComponent(composite, componentName)

Attempt to retrieve component from composite object by heuristic.

getValidComponents(composite)

Extract all non-None components from a composite.

handleParameters(inMemoryDataset[, parameters])

Modify the in-memory dataset using the supplied parameters.

selectResponsibleComponent(derivedComponent, ...)

Select the best component for calculating a derived component.

Methods Documentation

assemble(components: Dict[str, Any], pytype: Type | None = None) Any

Construct an object from components based on storageClass.

This generic implementation assumes that instances of objects can be created either by passing all the components to a constructor or by calling setter methods with the name.

Parameters:
componentsdict

Collection of components from which to assemble a new composite object. Keys correspond to composite names in the StorageClass.

pytypetype, optional

Override the type from the StorageClassDelegate.storageClass to use when assembling the final object.

Returns:
compositeobject

New composite object assembled from components.

Raises:
ValueError

Some components could not be used to create the object or, alternatively, some components were not defined in the associated StorageClass.

disassemble(composite: Any, subset: Iterable | None = None, override: Any | None = None) Dict[str, DatasetComponent]

Disassembler a composite.

This is a generic implementation of a disassembler. This implementation attempts to extract components from the parent by looking for attributes of the same name or getter methods derived from the component name.

Parameters:
compositeobject

Parent composite object consisting of components to be extracted.

subsetiterable, optional

Iterable containing subset of components to extract from composite. Must be a subset of those defined in StorageClassDelegate.storageClass.

overrideobject, optional

Object to use for disassembly instead of parent. This can be useful when called from subclasses that have composites in a hierarchy.

Returns:
componentsdict

dict with keys matching the components defined in StorageClassDelegate.storageClass and values being DatasetComponent instances describing the component.

Raises:
ValueError

A requested component can not be found in the parent using generic lookups.

TypeError

The parent object does not match the supplied StorageClassDelegate.storageClass.

getComponent(composite: Any, componentName: str) Any

Attempt to retrieve component from composite object by heuristic.

Will attempt a direct attribute retrieval, or else getter methods of the form “get_componentName” and “getComponentName”.

Parameters:
compositeobject

Item to query for the component.

componentNamestr

Name of component to retrieve.

Returns:
componentobject

Component extracted from composite.

Raises:
AttributeError

The attribute could not be read from the composite.

getValidComponents(composite: Any) Dict[str, Any]

Extract all non-None components from a composite.

Parameters:
compositeobject

Composite from which to extract components.

Returns:
compsdict

Non-None components extracted from the composite, indexed by the component name as derived from the StorageClassDelegate.storageClass.

handleParameters(inMemoryDataset: Any, parameters: Mapping[str, Any] | None = None) Any

Modify the in-memory dataset using the supplied parameters.

Can return a possibly new object.

For safety, if any parameters are given to this method an exception will be raised. This is to protect the user from thinking that parameters have been applied when they have not been applied.

Parameters:
inMemoryDatasetobject

Object to modify based on the parameters.

parametersdict

Parameters to apply. Values are specific to the parameter. Supported parameters are defined in the associated StorageClass. If no relevant parameters are specified the inMemoryDataset will be return unchanged.

Returns:
inMemoryDatasetobject

Updated form of supplied in-memory dataset, after parameters have been used.

Raises:
ValueError

Parameters have been provided to this default implementation.

classmethod selectResponsibleComponent(derivedComponent: str, fromComponents: Set[str | None]) str

Select the best component for calculating a derived component.

Given a possible set of components to choose from, return the component that should be used to calculate the requested derived component.

Parameters:
derivedComponentstr

The derived component that is being requested.

fromComponentsset of str

The available set of component options from which that derived component can be computed. None can be included but should be ignored.

Returns:
requiredstr

The component that should be used.

Raises:
NotImplementedError

Raised if this delegate refuses to answer the question.

ValueError

Raised if this delegate can not determine a relevant component from the supplied options.