LSST Applications 24.1.5,g02d81e74bb+fa3a7a026e,g180d380827+a53a32eff8,g2079a07aa2+86d27d4dc4,g2305ad1205+c0501b3732,g295015adf3+7d3e92f0ec,g2bbee38e9b+0e5473021a,g337abbeb29+0e5473021a,g33d1c0ed96+0e5473021a,g3a166c0a6a+0e5473021a,g3ddfee87b4+5dd1654d75,g48712c4677+3bf1020dcb,g487adcacf7+065c13d9cf,g50ff169b8f+96c6868917,g52b1c1532d+585e252eca,g591dd9f2cf+d7ac436cfb,g5a732f18d5+53520f316c,g64a986408d+fa3a7a026e,g858d7b2824+fa3a7a026e,g8a8a8dda67+585e252eca,g99cad8db69+a5a909b84f,g9ddcbc5298+9a081db1e4,ga1e77700b3+15fc3df1f7,ga8c6da7877+4cf350ccb2,gb0e22166c9+60f28cb32d,gba4ed39666+c2a2e4ac27,gbb8dafda3b+f991a0b59f,gc120e1dc64+9ccbfdb8be,gc28159a63d+0e5473021a,gcf0d15dbbd+5dd1654d75,gd96a1ce819+42fd0ee607,gdaeeff99f8+f9a426f77a,ge6526c86ff+0d71447b4b,ge79ae78c31+0e5473021a,gee10cc3b42+585e252eca,gff1a9f87cc+fa3a7a026e
LSST Data Management Base Package
Loading...
Searching...
No Matches
Public Member Functions | Public Attributes | Static Public Attributes | Protected Member Functions | List of all members
lsst.pex.config.configDictField.ConfigDictField Class Reference
Inheritance diagram for lsst.pex.config.configDictField.ConfigDictField:
lsst.pex.config.dictField.DictField lsst.pex.config.config.Field lsst.pex.config.dictField.Dict

Public Member Functions

 __init__ (self, doc, keytype, itemtype, default=None, optional=False, dictCheck=None, itemCheck=None, deprecated=None)
 
 rename (self, instance)
 
 validate (self, instance)
 
 toDict (self, instance)
 
 save (self, outfile, instance)
 
 freeze (self, instance)
 

Public Attributes

 keytype
 
 itemtype
 
 dictCheck
 
 itemCheck
 
 name
 

Static Public Attributes

 DictClass = ConfigDict
 

Protected Member Functions

 _collectImports (self, instance, imports)
 
 _compare (self, instance1, instance2, shortcut, rtol, atol, output)
 

Detailed Description

A configuration field (`~lsst.pex.config.Field` subclass) that is a
mapping of keys to `~lsst.pex.config.Config` instances.

``ConfigDictField`` behaves like `DictField` except that the
``itemtype`` must be a `~lsst.pex.config.Config` subclass.

Parameters
----------
doc : `str`
    A description of the configuration field.
keytype : {`int`, `float`, `complex`, `bool`, `str`}
    The type of the mapping keys. All keys must have this type.
itemtype : `lsst.pex.config.Config`-type
    The type of the values in the mapping. This must be
    `~lsst.pex.config.Config` or a subclass.
default : optional
    Unknown.
default : ``itemtype``-dtype, optional
    Default value of this field.
optional : `bool`, optional
    If `True`, this configuration `~lsst.pex.config.Field` is *optional*.
    Default is `True`.
dictCheck : `~collections.abc.Callable` or `None`, optional
    Callable to check a dict.
itemCheck : `~collections.abc.Callable` or `None`, optional
    Callable to check an item.
deprecated : None or `str`, optional
    A description of why this Field is deprecated, including removal date.
    If not None, the string is appended to the docstring for this Field.

Raises
------
ValueError
    Raised if the inputs are invalid:

    - ``keytype`` or ``itemtype`` arguments are not supported types
      (members of `ConfigDictField.supportedTypes`.
    - ``dictCheck`` or ``itemCheck`` is not a callable function.

See Also
--------
ChoiceField
ConfigChoiceField
ConfigField
ConfigurableField
DictField
Field
ListField
RangeField
RegistryField

Notes
-----
You can use ``ConfigDictField`` to create name-to-config mappings. One use
case is for configuring mappings for dataset types in a Butler. In this
case, the dataset type names are arbitrary and user-selected while the
mapping configurations are known and fixed.

Definition at line 109 of file configDictField.py.

Constructor & Destructor Documentation

◆ __init__()

lsst.pex.config.configDictField.ConfigDictField.__init__ ( self,
doc,
keytype,
itemtype,
default = None,
optional = False,
dictCheck = None,
itemCheck = None,
deprecated = None )

Reimplemented from lsst.pex.config.dictField.DictField.

Definition at line 171 of file configDictField.py.

181 ):
182 source = getStackFrame()
183 self._setup(
184 doc=doc,
185 dtype=ConfigDict,
186 default=default,
187 check=None,
188 optional=optional,
189 source=source,
190 deprecated=deprecated,
191 )
192 if keytype not in self.supportedTypes:
193 raise ValueError("'keytype' %s is not a supported type" % _typeStr(keytype))
194 elif not issubclass(itemtype, Config):
195 raise ValueError("'itemtype' %s is not a supported type" % _typeStr(itemtype))
196 if dictCheck is not None and not hasattr(dictCheck, "__call__"):
197 raise ValueError("'dictCheck' must be callable")
198 if itemCheck is not None and not hasattr(itemCheck, "__call__"):
199 raise ValueError("'itemCheck' must be callable")
200
201 self.keytype = keytype
202 self.itemtype = itemtype
203 self.dictCheck = dictCheck
204 self.itemCheck = itemCheck
205

Member Function Documentation

◆ _collectImports()

lsst.pex.config.configDictField.ConfigDictField._collectImports ( self,
instance,
imports )
protected
Call the _collectImports method on all config
objects the field may own, and union them with the supplied imports
set.

Parameters
----------
instance : instance or subclass of `lsst.pex.config.Config`
    A config object that has this field defined on it
imports : `set`
    Set of python modules that need imported after persistence

Reimplemented from lsst.pex.config.config.Field.

Definition at line 235 of file configDictField.py.

235 def _collectImports(self, instance, imports):
236 # docstring inherited from Field
237 configDict = self.__get__(instance)
238 if configDict is not None:
239 for v in configDict.values():
240 v._collectImports()
241 imports |= v._imports
242

◆ _compare()

lsst.pex.config.configDictField.ConfigDictField._compare ( self,
instance1,
instance2,
shortcut,
rtol,
atol,
output )
protected
Compare two fields for equality.

Used by `lsst.pex.ConfigDictField.compare`.

Parameters
----------
instance1 : `lsst.pex.config.Config`
    Left-hand side config instance to compare.
instance2 : `lsst.pex.config.Config`
    Right-hand side config instance to compare.
shortcut : `bool`
    If `True`, this function returns as soon as an inequality if found.
rtol : `float`
    Relative tolerance for floating point comparisons.
atol : `float`
    Absolute tolerance for floating point comparisons.
output : callable
    A callable that takes a string, used (possibly repeatedly) to
    report inequalities.

Returns
-------
isEqual : bool
    `True` if the fields are equal, `False` otherwise.

Notes
-----
Floating point comparisons are performed by `numpy.allclose`.

Reimplemented from lsst.pex.config.dictField.DictField.

Definition at line 261 of file configDictField.py.

261 def _compare(self, instance1, instance2, shortcut, rtol, atol, output):
262 """Compare two fields for equality.
263
264 Used by `lsst.pex.ConfigDictField.compare`.
265
266 Parameters
267 ----------
268 instance1 : `lsst.pex.config.Config`
269 Left-hand side config instance to compare.
270 instance2 : `lsst.pex.config.Config`
271 Right-hand side config instance to compare.
272 shortcut : `bool`
273 If `True`, this function returns as soon as an inequality if found.
274 rtol : `float`
275 Relative tolerance for floating point comparisons.
276 atol : `float`
277 Absolute tolerance for floating point comparisons.
278 output : callable
279 A callable that takes a string, used (possibly repeatedly) to
280 report inequalities.
281
282 Returns
283 -------
284 isEqual : bool
285 `True` if the fields are equal, `False` otherwise.
286
287 Notes
288 -----
289 Floating point comparisons are performed by `numpy.allclose`.
290 """
291 d1 = getattr(instance1, self.name)
292 d2 = getattr(instance2, self.name)
293 name = getComparisonName(
294 _joinNamePath(instance1._name, self.name), _joinNamePath(instance2._name, self.name)
295 )
296 if not compareScalars("keys for %s" % name, set(d1.keys()), set(d2.keys()), output=output):
297 return False
298 equal = True
299 for k, v1 in d1.items():
300 v2 = d2[k]
301 result = compareConfigs(
302 f"{name}[{k!r}]", v1, v2, shortcut=shortcut, rtol=rtol, atol=atol, output=output
303 )
304 if not result and shortcut:
305 return False
306 equal = equal and result
307 return equal
daf::base::PropertySet * set
Definition fits.cc:931

◆ freeze()

lsst.pex.config.configDictField.ConfigDictField.freeze ( self,
instance )
Make this field read-only (for internal use only).

Parameters
----------
instance : `lsst.pex.config.Config`
    The config instance that contains this field.

Notes
-----
Freezing is only relevant for fields that hold subconfigs. Fields which
hold subconfigs should freeze each subconfig.

**Subclasses should implement this method.**

Reimplemented from lsst.pex.config.config.Field.

Definition at line 255 of file configDictField.py.

255 def freeze(self, instance):
256 configDict = self.__get__(instance)
257 if configDict is not None:
258 for k in configDict:
259 configDict[k].freeze()
260

◆ rename()

lsst.pex.config.configDictField.ConfigDictField.rename ( self,
instance )
Rename the field in a `~lsst.pex.config.Config` (for internal use
only).

Parameters
----------
instance : `lsst.pex.config.Config`
    The config instance that contains this field.

Notes
-----
This method is invoked by the `lsst.pex.config.Config` object that
contains this field and should not be called directly.

Renaming is only relevant for `~lsst.pex.config.Field` instances that
hold subconfigs. `~lsst.pex.config.Field`\s that hold subconfigs should
rename each subconfig with the full field name as generated by
`lsst.pex.config.config._joinNamePath`.

Reimplemented from lsst.pex.config.config.Field.

Definition at line 206 of file configDictField.py.

206 def rename(self, instance):
207 configDict = self.__get__(instance)
208 if configDict is not None:
209 for k in configDict:
210 fullname = _joinNamePath(instance._name, self.name, k)
211 configDict[k]._rename(fullname)
212

◆ save()

lsst.pex.config.configDictField.ConfigDictField.save ( self,
outfile,
instance )
Save this field to a file (for internal use only).

Parameters
----------
outfile : file-like object
    A writeable field handle.
instance : `~lsst.pex.config.Config`
    The `~lsst.pex.config.Config` instance that contains this field.

Notes
-----
This method is invoked by the `~lsst.pex.config.Config` object that
contains this field and should not be called directly.

The output consists of the documentation string
(`lsst.pex.config.Field.doc`) formatted as a Python comment. The second
line is formatted as an assignment: ``{fullname}={value}``.

This output can be executed with Python.

Reimplemented from lsst.pex.config.config.Field.

Definition at line 243 of file configDictField.py.

243 def save(self, outfile, instance):
244 configDict = self.__get__(instance)
245 fullname = _joinNamePath(instance._name, self.name)
246 if configDict is None:
247 outfile.write(f"{fullname}={configDict!r}\n")
248 return
249
250 outfile.write(f"{fullname}={{}}\n")
251 for v in configDict.values():
252 outfile.write(f"{v._name}={_typeStr(v)}()\n")
253 v._save(outfile)
254

◆ toDict()

lsst.pex.config.configDictField.ConfigDictField.toDict ( self,
instance )
Convert this field's key-value pairs into a regular `dict`.

Parameters
----------
instance : `lsst.pex.config.Config`
    The configuration that contains this field.

Returns
-------
result : `dict` or `None`
    If this field has a value of `None`, then this method returns
    `None`. Otherwise, this method returns the field's value as a
    regular Python `dict`.

Reimplemented from lsst.pex.config.dictField.DictField.

Definition at line 224 of file configDictField.py.

224 def toDict(self, instance):
225 configDict = self.__get__(instance)
226 if configDict is None:
227 return None
228
229 dict_ = {}
230 for k in configDict:
231 dict_[k] = configDict[k].toDict()
232
233 return dict_
234

◆ validate()

lsst.pex.config.configDictField.ConfigDictField.validate ( self,
instance )
Validate the field's value (for internal use only).

Parameters
----------
instance : `lsst.pex.config.Config`
    The configuration that contains this field.

Returns
-------
isValid : `bool`
    `True` is returned if the field passes validation criteria (see
    *Notes*). Otherwise `False`.

Notes
-----
This method validates values according to the following criteria:

- A non-optional field is not `None`.
- If a value is not `None`, is must pass the `ConfigField.dictCheck`
  user callback functon.

Individual item checks by the `ConfigField.itemCheck` user callback
function are done immediately when the value is set on a key. Those
checks are not repeated by this method.

Reimplemented from lsst.pex.config.dictField.DictField.

Definition at line 213 of file configDictField.py.

213 def validate(self, instance):
214 value = self.__get__(instance)
215 if value is not None:
216 for k in value:
217 item = value[k]
218 item.validate()
219 if self.itemCheck is not None and not self.itemCheck(item):
220 msg = f"Item at key {k!r} is not a valid value: {item}"
221 raise FieldValidationError(self, instance, msg)
222 DictField.validate(self, instance)
223

Member Data Documentation

◆ dictCheck

lsst.pex.config.configDictField.ConfigDictField.dictCheck

Definition at line 203 of file configDictField.py.

◆ DictClass

lsst.pex.config.configDictField.ConfigDictField.DictClass = ConfigDict
static

Definition at line 169 of file configDictField.py.

◆ itemCheck

lsst.pex.config.configDictField.ConfigDictField.itemCheck

Definition at line 204 of file configDictField.py.

◆ itemtype

lsst.pex.config.configDictField.ConfigDictField.itemtype

Definition at line 202 of file configDictField.py.

◆ keytype

lsst.pex.config.configDictField.ConfigDictField.keytype

Definition at line 201 of file configDictField.py.

◆ name

lsst.pex.config.configDictField.ConfigDictField.name

Definition at line 294 of file configDictField.py.


The documentation for this class was generated from the following file: