FormatterFactory

class lsst.daf.butler.FormatterFactory

Bases: object

Factory for Formatter instances.

Methods Summary

getFormatter(entity, *args, **kwargs)

Get a new formatter instance.

getFormatterClass(entity)

Get the matching formatter class.

getFormatterClassWithMatch(entity)

Get the matching formatter class along with the matching registry key.

getFormatterWithMatch(entity, *args, **kwargs)

Get a new formatter instance along with the matching registry key.

getLookupKeys()

Retrieve the look up keys for all the registry entries.

registerFormatter(type_, formatter)

Register a Formatter.

registerFormatters(config, *, universe)

Bulk register formatters from a config.

Methods Documentation

getFormatter(entity: Union[lsst.daf.butler.core.datasets.DatasetType, lsst.daf.butler.core.datasets.DatasetRef, lsst.daf.butler.core.storageClass.StorageClass, str], *args, **kwargs) → lsst.daf.butler.core.formatter.Formatter

Get a new formatter instance.

Parameters
entityDatasetRef, DatasetType, StorageClass, or str

Entity to use to determine the formatter to return. StorageClass will be used as a last resort if DatasetRef or DatasetType instance is provided. Supports instrument override if a DatasetRef is provided configured with an instrument value for the data ID.

argstuple

Positional arguments to use pass to the object constructor.

kwargsdict

Keyword arguments to pass to object constructor.

Returns
formatterFormatter

An instance of the registered formatter.

getFormatterClass(entity: Union[lsst.daf.butler.core.datasets.DatasetType, lsst.daf.butler.core.datasets.DatasetRef, lsst.daf.butler.core.storageClass.StorageClass, str]) → Type

Get the matching formatter class.

Parameters
entityDatasetRef, DatasetType, StorageClass, or str

Entity to use to determine the formatter to return. StorageClass will be used as a last resort if DatasetRef or DatasetType instance is provided. Supports instrument override if a DatasetRef is provided configured with an instrument value for the data ID.

Returns
formattertype

The class of the registered formatter.

getFormatterClassWithMatch(entity: Union[lsst.daf.butler.core.datasets.DatasetType, lsst.daf.butler.core.datasets.DatasetRef, lsst.daf.butler.core.storageClass.StorageClass, str]) → Tuple[lsst.daf.butler.core.configSupport.LookupKey, Type]

Get the matching formatter class along with the matching registry key.

Parameters
entityDatasetRef, DatasetType, StorageClass, or str

Entity to use to determine the formatter to return. StorageClass will be used as a last resort if DatasetRef or DatasetType instance is provided. Supports instrument override if a DatasetRef is provided configured with an instrument value for the data ID.

Returns
matchKeyLookupKey

The key that resulted in the successful match.

formattertype

The class of the registered formatter.

getFormatterWithMatch(entity: Union[lsst.daf.butler.core.datasets.DatasetType, lsst.daf.butler.core.datasets.DatasetRef, lsst.daf.butler.core.storageClass.StorageClass, str], *args, **kwargs) → Tuple[lsst.daf.butler.core.configSupport.LookupKey, lsst.daf.butler.core.formatter.Formatter]

Get a new formatter instance along with the matching registry key.

Parameters
entityDatasetRef, DatasetType, StorageClass, or str

Entity to use to determine the formatter to return. StorageClass will be used as a last resort if DatasetRef or DatasetType instance is provided. Supports instrument override if a DatasetRef is provided configured with an instrument value for the data ID.

argstuple

Positional arguments to use pass to the object constructor.

kwargsdict

Keyword arguments to pass to object constructor.

Returns
matchKeyLookupKey

The key that resulted in the successful match.

formatterFormatter

An instance of the registered formatter.

getLookupKeys() → Set[lsst.daf.butler.core.configSupport.LookupKey]

Retrieve the look up keys for all the registry entries.

Returns
keysset of LookupKey

The keys available for matching in the registry.

registerFormatter(type_: Union[lsst.daf.butler.core.configSupport.LookupKey, str, lsst.daf.butler.core.storageClass.StorageClass, lsst.daf.butler.core.datasets.DatasetType], formatter: str) → None

Register a Formatter.

Parameters
type_LookupKey, str, StorageClass or DatasetType

Type for which this formatter is to be used. If a LookupKey is not provided, one will be constructed from the supplied string or by using the name property of the supplied entity.

formatterstr

Identifies a Formatter subclass to use for reading and writing Datasets of this type.

Raises
ValueError

Raised if the formatter does not name a valid formatter type.

registerFormatters(config: lsst.daf.butler.core.config.Config, *, universe: lsst.daf.butler.core.dimensions.universe.DimensionUniverse) → None

Bulk register formatters from a config.

Parameters
configConfig

formatters section of a configuration.

universeDimensionUniverse, optional

Set of all known dimensions, used to expand and validate any used in lookup keys.

Notes

The configuration can include one level of hierarchy where an instrument-specific section can be defined to override more general template specifications. This is represented in YAML using a key of form instrument<name> which can then define templates that will be returned if a DatasetRef contains a matching instrument name in the data ID.

The config is parsed using the function processLookupConfigs.