A base class for global registries, which map names to configurables.
A registry acts like a read-only dictionary with an additional `register`
method to add targets. Targets in the registry are configurables (see
*Notes*).
Parameters
----------
configBaseType : `lsst.pex.config.Config`-type
The base class for config classes in the registry.
Notes
-----
A configurable is a callable with call signature ``(config, *args)``
Configurables typically create an algorithm or are themselves the
algorithm. Often configurables are `lsst.pipe.base.Task` subclasses, but
this is not required.
A ``Registry`` has these requirements:
- All configurables added to a particular registry have the same call
signature.
- All configurables in a registry typically share something important
in common. For example, all configurables in ``psfMatchingRegistry``
return a PSF matching class that has a ``psfMatch`` method with a
particular call signature.
Examples
--------
This examples creates a configurable class ``Foo`` and adds it to a
registry. First, creating the configurable:
>>> from lsst.pex.config import Registry, Config
>>> class FooConfig(Config):
... val = Field(dtype=int, default=3, doc="parameter for Foo")
...
>>> class Foo:
... ConfigClass = FooConfig
... def __init__(self, config):
... self.config = config
... def addVal(self, num):
... return self.config.val + num
...
Next, create a ``Registry`` instance called ``registry`` and register the
``Foo`` configurable under the ``"foo"`` key:
>>> registry = Registry()
>>> registry.register("foo", Foo)
>>> print(list(registry.keys()))
["foo"]
Now ``Foo`` is conveniently accessible from the registry itself.
Finally, use the registry to get the configurable class and create an
instance of it:
>>> FooConfigurable = registry["foo"]
>>> foo = FooConfigurable(FooConfigurable.ConfigClass())
>>> foo.addVal(5)
8
lsst.pex.config.registry.Registry.makeField |
( |
| self, |
|
|
| doc, |
|
|
| default = None, |
|
|
| optional = False, |
|
|
| multi = False, |
|
|
| on_none = None ) |
Create a `RegistryField` configuration field from this registry.
Parameters
----------
doc : `str`
A description of the field.
default : object, optional
The default target for the field.
optional : `bool`, optional
When `False`, `lsst.pex.config.Config.validate` fails if the
field's value is `None`.
multi : `bool`, optional
A flag to allow multiple selections in the `RegistryField` if
`True`.
on_none : `Callable`, optional
A callable that should be invoked when ``apply`` is called but the
selected name or names is `None`. Will be passed the field
attribute proxy (`RegistryInstanceDict`) and then all positional
and keyword arguments passed to ``apply``.
Returns
-------
field : `lsst.pex.config.RegistryField`
`~lsst.pex.config.RegistryField` Configuration field.