FormatterFactory

class lsst.daf.butler.FormatterFactory

Bases: object

Factory for Formatter instances.

Methods Summary

getFormatter(entity) Get a new formatter instance.
getFormatterWithMatch(entity) Get a new formatter instance along with the matching registry key.
getLookupKeys() Retrieve the look up keys for all the registry entries.
normalizeDimensions(universe) Normalize formatter lookups that use dimensions.
registerFormatter(type_, formatter) Register a Formatter.
registerFormatters(config[, universe]) Bulk register formatters from a config.

Methods Documentation

getFormatter(entity)

Get a new formatter instance.

Parameters:
entity : DatasetRef, DatasetType or 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:
formatter : Formatter

An instance of the registered formatter.

getFormatterWithMatch(entity)

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

Parameters:
entity : DatasetRef, DatasetType or 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:
matchKey : LookupKey

The key that resulted in the successful match.

formatter : Formatter

An instance of the registered formatter.

getLookupKeys()

Retrieve the look up keys for all the registry entries.

Returns:
keys : set of LookupKey

The keys available for matching in the registry.

normalizeDimensions(universe)

Normalize formatter lookups that use dimensions.

Parameters:
universe : DimensionUniverse

The set of all known dimensions. If None, returns without action.

Raises:
ValueError

Raised if a key exists where a dimension is not part of the universe.

Notes

Goes through all registered formatters, and for keys that include dimensions, rewrites those keys to use a verified set of dimensions.

Returns without action if the formatter keys have already been normalized.

registerFormatter(type_, formatter)

Register a Formatter.

Parameters:
type_ : LookupKey, str or 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.

formatter : str

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, universe=None)

Bulk register formatters from a config.

Parameters:
config : Config

formatters section of a configuration.

universe : DimensionUniverse, optional

The set of all known dimensions. If not None, any look up keys involving dimensions will be normalized. The normalization flag will be cleared each time this method is called without a universe.

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.