Questions learning lsst.pex.config

I am now learning lsst.pex.config
When I follow the code Example config class and usage, I got error:

(lsst-scipipe-0.7.0) [yu@localhost ~]$ setup lsst_distrib
(lsst-scipipe-0.7.0) [yu@localhost ~]$ python
Python 3.8.8 | packaged by conda-forge | (default, Feb 20 2021, 16:22:27)
[GCC 9.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import lsst.pex.config as pexConfig
>>> class IsrTaskConfig(pexConfig.Config):
...     doWrite = pexConfig.Field(
...         doc="Write output?",
...         dtype=bool,
...         default=True)
...     fwhm = pexConfig.Field(
...         doc="FWHM of PSF (arcsec)",
...         dtype=float,
...         default=1.0)
...     saturatedMaskName = pexConfig.Field(
...         doc="Name of mask plane to use in saturation detection",
...         dtype=str,
...         default="SAT")
...     flatScalingType = pexConfig.ChoiceField(
...         doc="The method for scaling the flat on the fly.",
...         dtypye=str,
...         default='USER',
...         allowed={
...             "USER": "User defined scaling",
...             "MEAN": "Scale by the inverse of the mean",
...             "MEDIAN": "Scale by the inverse of the median",
...         })
...     keysToRemoveFromAssembledCcd = pexConfig.ListField(
...         doc="fields to remove from the metadata of the assembled ccd.",
...         dtype=str,
...         default=[])
...
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "<stdin>", line 14, in IsrTaskConfig
TypeError: __init__() got an unexpected keyword argument 'dtypye'
>>> class IsrTaskConfig(pexConfig.Config):
...     flatScalingType = pexConfig.ChoiceField(
...         doc="The method for scaling the flat on the fly.",
...         dtypye=str,
...         default='USER',
...         allowed={
...             "USER": "User defined scaling",
...             "MEAN": "Scale by the inverse of the mean",
...             "MEDIAN": "Scale by the inverse of the median",
...         })
...
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "<stdin>", line 2, in IsrTaskConfig
TypeError: __init__() got an unexpected keyword argument 'dtypye'

Thing is wrong with the flatScalingType, So, What cause it?

Thank you!

This is a simple typo: dtypye=str should be dtype=str.

1 Like

There are some sentences that I can not understand it’s meaning when I read Overview of lsst.pex.config

Forgive me about the stupid questions I ask

First sentences I can not understand

This override file looks like Python code because it is . The root variable refers to the config instance that called its load method, which is the config variable in the doIsrTask example. In more advanced cases a configuration field’s value can itself be a config instance, so there will be a hierarchical namespace of configurations, like:

config.configField.fieldOnConfigField = 'value'

I want to know more detali about the advanced cases,

And The second sentence

Config configuration objects are hierarchical (see ConfigField), so calling code can embed the configuration definitions of called code.

What’s the meaning of calling code can embed the configuration definitions of called code?

Configurations are not input data. They should not be used in place of function or method arguments, nor are they intended to replace ordinary dictionary data structures. A good rule of thumb is that if a particular parameter does not have a useful default, it is probably an input rather than a configuration parameter. Another rule of thumb is that configuration parameters should generally not be set in algorithmic code, only in initialization or user interface code. In fact, changing configuration after a configurable object (such as Task) has been initialized can lead to incorrect behavior.

And in this sentence, I can not understand the real meaning of configurable object(such as Task) What’s the meaning of configurable object?

Thank you!

Hierarchy:

Just like Python dictionaries can contain other Python dictionaries:

>>> a = {"b": {"c": 3}, "foo": "bar"}
>>> print(a["b"]["c"])
3

Configs can contain other Configs via the mentioned ConfigField class or related classes (like ConfigDictField).

Typically this is used so that the Config that configures a Task can also configure subtasks (other Tasks) or functions that that Task calls. For example, the Config class for the WarpAndPsfMatchTask contains a ConfigField for the warper that it calls. For subtasks, which often have multiple choices of plugins, each with their own configuration, a ConfigurableField is usually used.

Any Python object that accepts a Config instance to configure itself is a “configurable object”. Typically these are Tasks, but sometimes they are other classes (like the lsst.afw.math.Warper mentioned above).

1 Like