|
LSST Applications g00d0e8bbd7+edbf708997,g03191d30f7+6b31559d11,g118115db7c+ac820e85d2,g199a45376c+5137f08352,g1fd858c14a+90100aa1a7,g262e1987ae+64df5f6984,g29ae962dfc+1eb4aece83,g2cef7863aa+73c82f25e4,g3541666cd7+1e37cdad5c,g35bb328faa+edbf708997,g3fd5ace14f+fb4e2866cc,g47891489e3+19fcc35de2,g53246c7159+edbf708997,g5b326b94bb+d622351b67,g64539dfbff+dfe1dff262,g67b6fd64d1+19fcc35de2,g74acd417e5+cfdc02aca8,g786e29fd12+af89c03590,g7aefaa3e3d+dc1a598170,g87389fa792+a4172ec7da,g88cb488625+60ba2c3075,g89139ef638+19fcc35de2,g8d4809ba88+dfe1dff262,g8d7436a09f+db94b797be,g8ea07a8fe4+79658f16ab,g90f42f885a+6577634e1f,g9722cb1a7f+d8f85438e7,g98df359435+7fdd888faa,ga2180abaac+edbf708997,ga9e74d7ce9+128cc68277,gbf99507273+edbf708997,gca7fc764a6+19fcc35de2,gd7ef33dd92+19fcc35de2,gdab6d2f7ff+cfdc02aca8,gdbb4c4dda9+dfe1dff262,ge410e46f29+19fcc35de2,ge41e95a9f2+dfe1dff262,geaed405ab2+062dfc8cdc,w.2025.46
LSST Data Management Base Package
|
Public Member Functions | |
| __init__ (self, configBaseType=Config) | |
| register (self, name, target, ConfigClass=None) | |
| __getitem__ (self, key) | |
| __len__ (self) | |
| __iter__ (self) | |
| __contains__ (self, key) | |
| makeField (self, doc, default=None, optional=False, multi=False, on_none=None) | |
Protected Attributes | |
| _configBaseType = configBaseType | |
| dict | _dict = {} |
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
Definition at line 59 of file registry.py.
| lsst.pex.config.registry.Registry.__init__ | ( | self, | |
| configBaseType = Config ) |
Definition at line 123 of file registry.py.
| lsst.pex.config.registry.Registry.__contains__ | ( | self, | |
| key ) |
Definition at line 181 of file registry.py.
| lsst.pex.config.registry.Registry.__getitem__ | ( | self, | |
| key ) |
Definition at line 172 of file registry.py.
| lsst.pex.config.registry.Registry.__iter__ | ( | self | ) |
Definition at line 178 of file registry.py.
| lsst.pex.config.registry.Registry.__len__ | ( | self | ) |
Definition at line 175 of file registry.py.
| 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.
Reimplemented in lsst.meas.base.pluginRegistry.PluginRegistry.
Definition at line 184 of file registry.py.
| lsst.pex.config.registry.Registry.register | ( | self, | |
| name, | |||
| target, | |||
| ConfigClass = None ) |
Add a new configurable target to the registry.
Parameters
----------
name : `str`
Name that the ``target`` is registered under. The target can
be accessed later with `dict`-like patterns using ``name`` as
the key.
target : obj
A configurable type, usually a subclass of `lsst.pipe.base.Task`.
ConfigClass : `lsst.pex.config.Config`-type, optional
A subclass of `lsst.pex.config.Config` used to configure the
configurable. If `None` then the configurable's ``ConfigClass``
attribute is used.
Raises
------
RuntimeError
Raised if an item with ``name`` is already in the registry.
AttributeError
Raised if ``ConfigClass`` is `None` and ``target`` does not have
a ``ConfigClass`` attribute.
Notes
-----
If ``ConfigClass`` is provided then the ``target`` configurable is
wrapped in a new object that forwards function calls to it. Otherwise
the original ``target`` is stored.
Reimplemented in lsst.meas.base.pluginRegistry.PluginRegistry.
Definition at line 129 of file registry.py.
|
protected |
Definition at line 126 of file registry.py.
|
protected |
Definition at line 127 of file registry.py.