LSST Applications g0265f82a02+0e5473021a,g02d81e74bb+f5613e8b4f,g1470d8bcf6+190ad2ba91,g14a832a312+311607e4ab,g2079a07aa2+86d27d4dc4,g2305ad1205+a8e3196225,g295015adf3+b67ee847e5,g2bbee38e9b+0e5473021a,g337abbeb29+0e5473021a,g3ddfee87b4+a761f810f3,g487adcacf7+17c8fdbcbd,g50ff169b8f+96c6868917,g52b1c1532d+585e252eca,g591dd9f2cf+65b5bd823e,g5a732f18d5+53520f316c,g64a986408d+f5613e8b4f,g6c1bc301e9+51106c2951,g858d7b2824+f5613e8b4f,g8a8a8dda67+585e252eca,g99cad8db69+6729933424,g9ddcbc5298+9a081db1e4,ga1e77700b3+15fc3df1f7,ga8c6da7877+ef4e3a5875,gb0e22166c9+60f28cb32d,gb6a65358fc+0e5473021a,gba4ed39666+c2a2e4ac27,gbb8dafda3b+e9bba80f27,gc120e1dc64+eee469a5e5,gc28159a63d+0e5473021a,gcf0d15dbbd+a761f810f3,gdaeeff99f8+f9a426f77a,ge6526c86ff+d4c1d4bfef,ge79ae78c31+0e5473021a,gee10cc3b42+585e252eca,gf1cff7945b+f5613e8b4f,w.2024.16
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.configurableActions._configurableActionStructField.ConfigurableActionStructField Class Reference
Inheritance diagram for lsst.pex.config.configurableActions._configurableActionStructField.ConfigurableActionStructField:
lsst.pex.config.config.Field

Public Member Functions

 __init__ (self, str doc, Mapping[str, ConfigurableAction]|None default=None, bool optional=False, deprecated=None)
 
 __class_getitem__ (cls, params)
 
 __set__ (self, Config instance,(None|Mapping[str, ConfigurableAction]|SimpleNamespace|ConfigurableActionStruct|ConfigurableActionStructField|type[ConfigurableActionStructField]) value, Iterable[StackFrame] at=None, str label="assigment")
 
ConfigurableActionStruct[ActionTypeVar] __get__ (self, None instance, Any owner=None, Any at=None, str label="default")
 
ConfigurableActionStruct[ActionTypeVar] __get__ (self, Config instance, Any owner=None, Any at=None, str label="default")
 
 __get__ (self, instance, owner=None, at=None, label="default")
 
 rename (self, Config instance)
 
 validate (self, Config instance)
 
 toDict (self, instance)
 
 save (self, outfile, instance)
 
 freeze (self, instance)
 

Public Attributes

 default
 
 name
 

Static Public Attributes

 StructClass = ConfigurableActionStruct
 
str name
 
Mapping default [str, ConfigurableAction] | None
 

Protected Member Functions

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

Detailed Description

`ConfigurableActionStructField` is a `~lsst.pex.config.Field` subclass
that allows a `ConfigurableAction` to be organized in a
`~lsst.pex.config.Config` class in a manner similar to how a
`~lsst.pipe.base.Struct` works.

This class uses a `ConfigurableActionStruct` as an intermediary object to
organize the `ConfigurableAction`. See its documentation for further
information.

Parameters
----------
doc : `str`
    Documentation string.
default : `~collections.abc.Mapping` [ `str`, `ConfigurableAction` ] \
        or `None`, optional
    Default value.
optional : `bool`, optional
    If `True`, the field doesn't need to have a set value.
deprecated : `bool` or `None`, 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.

Definition at line 249 of file _configurableActionStructField.py.

Constructor & Destructor Documentation

◆ __init__()

lsst.pex.config.configurableActions._configurableActionStructField.ConfigurableActionStructField.__init__ ( self,
str doc,
Mapping[str, ConfigurableAction] | None default = None,
bool optional = False,
deprecated = None )

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

Definition at line 282 of file _configurableActionStructField.py.

288 ):
289 source = getStackFrame()
290 self._setup(
291 doc=doc,
292 dtype=self.__class__,
293 default=default,
294 check=None,
295 optional=optional,
296 source=source,
297 deprecated=deprecated,
298 )
299

Member Function Documentation

◆ __class_getitem__()

lsst.pex.config.configurableActions._configurableActionStructField.ConfigurableActionStructField.__class_getitem__ ( cls,
params )

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

Definition at line 300 of file _configurableActionStructField.py.

300 def __class_getitem__(cls, params):
301 return GenericAlias(cls, params)
302

◆ __get__() [1/3]

ConfigurableActionStruct[ActionTypeVar] lsst.pex.config.configurableActions._configurableActionStructField.ConfigurableActionStructField.__get__ ( self,
Config instance,
Any owner = None,
Any at = None,
str label = "default" )

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

Definition at line 361 of file _configurableActionStructField.py.

363 ) -> ConfigurableActionStruct[ActionTypeVar]:
364 ...
365

◆ __get__() [2/3]

lsst.pex.config.configurableActions._configurableActionStructField.ConfigurableActionStructField.__get__ ( self,
instance,
owner = None,
at = None,
label = "default" )

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

Definition at line 366 of file _configurableActionStructField.py.

366 def __get__(self, instance, owner=None, at=None, label="default"):
367 if instance is None or not isinstance(instance, Config):
368 return self
369 else:
370 field: ConfigurableActionStruct | None = instance._storage[self.name]
371 return field
372

◆ __get__() [3/3]

ConfigurableActionStruct[ActionTypeVar] lsst.pex.config.configurableActions._configurableActionStructField.ConfigurableActionStructField.__get__ ( self,
None instance,
Any owner = None,
Any at = None,
str label = "default" )

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

Definition at line 355 of file _configurableActionStructField.py.

357 ) -> ConfigurableActionStruct[ActionTypeVar]:
358 ...
359

◆ __set__()

lsst.pex.config.configurableActions._configurableActionStructField.ConfigurableActionStructField.__set__ ( self,
Config instance,
( None | Mapping[str, ConfigurableAction] | SimpleNamespace | ConfigurableActionStruct | ConfigurableActionStructField | type[ConfigurableActionStructField] ) value,
Iterable[StackFrame] at = None,
str label = "assigment" )
Set an attribute on the config instance.

Parameters
----------
instance : `lsst.pex.config.Config`
    The config instance that contains this field.
value : obj
    Value to set on this field.
at : `list` of `~lsst.pex.config.callStack.StackFrame` or `None`,\
        optional
    The call stack (created by
    `lsst.pex.config.callStack.getCallStack`).
label : `str`, optional
    Event label for the history.

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

Derived `~lsst.pex.config.Field` classes may need to override the
behavior. When overriding ``__set__``, `~lsst.pex.config.Field` authors
should follow the following rules:

- Do not allow modification of frozen configs.
- Validate the new value **before** modifying the field. Except if the
  new value is `None`. `None` is special and no attempt should be made
  to validate it until `lsst.pex.config.Config.validate` is called.
- Do not modify the `~lsst.pex.config.Config` instance to contain
  invalid values.
- If the field is modified, update the history of the
  `lsst.pex.config.field.Field` to reflect the changes.

In order to decrease the need to implement this method in derived
`~lsst.pex.config.Field` types, value validation is performed in the
`lsst.pex.config.Field._validateValue`. If only the validation step
differs in the derived `~lsst.pex.config.Field`, it is simpler to
implement `lsst.pex.config.Field._validateValue` than to reimplement
``__set__``. More complicated behavior, however, may require
reimplementation.

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

Definition at line 303 of file _configurableActionStructField.py.

316 ):
317 if instance._frozen:
318 msg = "Cannot modify a frozen Config. " "Attempting to set field to value %s" % value
319 raise FieldValidationError(self, instance, msg)
320
321 if at is None:
322 at = getCallStack()
323
324 if value is None or (self.default is not None and self.default == value):
325 value = self.StructClass(instance, self, value, at=at, label=label)
326 else:
327 # An actual value is being assigned check for what it is
328 if isinstance(value, self.StructClass):
329 # If this is a ConfigurableActionStruct, we need to make our
330 # own copy that references this current field
331 value = self.StructClass(instance, self, value._attrs, at=at, label=label)
332 elif isinstance(value, SimpleNamespace):
333 # If this is a a python analogous container, we need to make
334 # a ConfigurableActionStruct initialized with this data
335 value = self.StructClass(instance, self, vars(value), at=at, label=label)
336
337 elif type(value) is ConfigurableActionStructField:
338 raise ValueError(
339 "ConfigurableActionStructFields can only be used in a class body declaration"
340 f"Use a {self.StructClass}, SimpleNamespace or Struct"
341 )
342 else:
343 raise ValueError(f"Unrecognized value {value}, cannot be assigned to this field")
344
345 history = instance._history.setdefault(self.name, [])
346 history.append((value, at, label))
347
348 if not isinstance(value, ConfigurableActionStruct):
349 raise FieldValidationError(
350 self, instance, "Can only assign things that are subclasses of Configurable Action"
351 )
352 instance._storage[self.name] = value
353

◆ _collectImports()

lsst.pex.config.configurableActions._configurableActionStructField.ConfigurableActionStructField._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 416 of file _configurableActionStructField.py.

416 def _collectImports(self, instance, imports):
417 # docstring inherited from Field
418 actionStruct = self.__get__(instance)
419 for v in actionStruct:
420 v._collectImports()
421 imports |= v._imports
422

◆ _compare()

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

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.config.Field.

Definition at line 423 of file _configurableActionStructField.py.

423 def _compare(self, instance1, instance2, shortcut, rtol, atol, output):
424 """Compare two fields for equality.
425
426 Parameters
427 ----------
428 instance1 : `lsst.pex.config.Config`
429 Left-hand side config instance to compare.
430 instance2 : `lsst.pex.config.Config`
431 Right-hand side config instance to compare.
432 shortcut : `bool`
433 If `True`, this function returns as soon as an inequality if found.
434 rtol : `float`
435 Relative tolerance for floating point comparisons.
436 atol : `float`
437 Absolute tolerance for floating point comparisons.
438 output : callable
439 A callable that takes a string, used (possibly repeatedly) to
440 report inequalities.
441
442 Returns
443 -------
444 isEqual : bool
445 `True` if the fields are equal, `False` otherwise.
446
447 Notes
448 -----
449 Floating point comparisons are performed by `numpy.allclose`.
450 """
451 d1: ConfigurableActionStruct = getattr(instance1, self.name)
452 d2: ConfigurableActionStruct = getattr(instance2, self.name)
453 name = getComparisonName(
454 _joinNamePath(instance1._name, self.name), _joinNamePath(instance2._name, self.name)
455 )
456 if not compareScalars(f"keys for {name}", set(d1.fieldNames), set(d2.fieldNames), output=output):
457 return False
458 equal = True
459 for k, v1 in d1.items():
460 v2 = getattr(d2, k)
461 result = compareConfigs(
462 f"{name}.{k}", v1, v2, shortcut=shortcut, rtol=rtol, atol=atol, output=output
463 )
464 if not result and shortcut:
465 return False
466 equal = equal and result
467 return equal
daf::base::PropertySet * set
Definition fits.cc:931

◆ freeze()

lsst.pex.config.configurableActions._configurableActionStructField.ConfigurableActionStructField.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 410 of file _configurableActionStructField.py.

410 def freeze(self, instance):
411 actionStruct = self.__get__(instance)
412 if actionStruct is not None:
413 for v in actionStruct:
414 v.freeze()
415

◆ rename()

lsst.pex.config.configurableActions._configurableActionStructField.ConfigurableActionStructField.rename ( self,
Config 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 373 of file _configurableActionStructField.py.

373 def rename(self, instance: Config):
374 actionStruct: ConfigurableActionStruct = self.__get__(instance)
375 if actionStruct is not None:
376 for k, v in actionStruct.items():
377 base_name = _joinNamePath(instance._name, self.name)
378 fullname = _joinNamePath(base_name, k)
379 v._rename(fullname)
380

◆ save()

lsst.pex.config.configurableActions._configurableActionStructField.ConfigurableActionStructField.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 396 of file _configurableActionStructField.py.

396 def save(self, outfile, instance):
397 actionStruct = self.__get__(instance)
398 fullname = _joinNamePath(instance._name, self.name)
399
400 # Ensure that a struct is always empty before assigning to it.
401 outfile.write(f"{fullname}=None\n")
402
403 if actionStruct is None:
404 return
405
406 for _, v in sorted(actionStruct.items()):
407 outfile.write(f"{v._name}={_typeStr(v)}()\n")
408 v._save(outfile)
409

◆ toDict()

lsst.pex.config.configurableActions._configurableActionStructField.ConfigurableActionStructField.toDict ( self,
instance )
Convert the field value so that it can be set as the value of an
item in a `dict` (for internal use only).

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

Returns
-------
value : object
    The field's value. See *Notes*.

Notes
-----
This method invoked by the owning `~lsst.pex.config.Config` object and
should not be called directly.

Simple values are passed through. Complex data structures must be
manipulated. For example, a `~lsst.pex.config.Field` holding a
subconfig should, instead of the subconfig object, return a `dict`
where the keys are the field names in the subconfig, and the values are
the field values in the subconfig.

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

Definition at line 387 of file _configurableActionStructField.py.

387 def toDict(self, instance):
388 actionStruct = self.__get__(instance)
389 if actionStruct is None:
390 return None
391
392 dict_ = {k: v.toDict() for k, v in actionStruct.items()}
393
394 return dict_
395

◆ validate()

lsst.pex.config.configurableActions._configurableActionStructField.ConfigurableActionStructField.validate ( self,
Config instance )
Validate the field (for internal use only).

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

Raises
------
lsst.pex.config.FieldValidationError
    Raised if verification fails.

Notes
-----
This method provides basic validation:

- Ensures that the value is not `None` if the field is not optional.
- Ensures type correctness.
- Ensures that the user-provided ``check`` function is valid.

Most `~lsst.pex.config.Field` subclasses should call
`lsst.pex.config.Field.validate` if they re-implement
`~lsst.pex.config.Field.validate`.

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

Definition at line 381 of file _configurableActionStructField.py.

381 def validate(self, instance: Config):
382 value = self.__get__(instance)
383 if value is not None:
384 for item in value:
385 item.validate()
386

Member Data Documentation

◆ default [1/2]

Mapping lsst.pex.config.configurableActions._configurableActionStructField.ConfigurableActionStructField.default [str, ConfigurableAction] | None
static

Definition at line 280 of file _configurableActionStructField.py.

◆ default [2/2]

lsst.pex.config.configurableActions._configurableActionStructField.ConfigurableActionStructField.default

Definition at line 324 of file _configurableActionStructField.py.

◆ name [1/2]

str lsst.pex.config.configurableActions._configurableActionStructField.ConfigurableActionStructField.name
static

Definition at line 279 of file _configurableActionStructField.py.

◆ name [2/2]

lsst.pex.config.configurableActions._configurableActionStructField.ConfigurableActionStructField.name

Definition at line 454 of file _configurableActionStructField.py.

◆ StructClass

lsst.pex.config.configurableActions._configurableActionStructField.ConfigurableActionStructField.StructClass = ConfigurableActionStruct
static

Definition at line 275 of file _configurableActionStructField.py.


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