LSST Applications g034a557a3c+dd8dd8f11d,g0afe43252f+b86e4b8053,g11f7dcd041+017865fdd3,g1cd03abf6b+8446defddb,g1ce3e0751c+f991eae79d,g28da252d5a+ca8a1a9fb3,g2bbee38e9b+b6588ad223,g2bc492864f+b6588ad223,g2cdde0e794+8523d0dbb4,g347aa1857d+b6588ad223,g35bb328faa+b86e4b8053,g3a166c0a6a+b6588ad223,g461a3dce89+b86e4b8053,g52b1c1532d+b86e4b8053,g7f3b0d46df+ad13c1b82d,g80478fca09+f29c5d6c70,g858d7b2824+293f439f82,g8cd86fa7b1+af721d2595,g965a9036f2+293f439f82,g979bb04a14+51ed57f74c,g9ddcbc5298+f24b38b85a,gae0086650b+b86e4b8053,gbb886bcc26+b97e247655,gc28159a63d+b6588ad223,gc30aee3386+a2f0f6cab9,gcaf7e4fdec+293f439f82,gcd45df26be+293f439f82,gcdd4ae20e8+70b5def7e6,gce08ada175+da9c58a417,gcf0d15dbbd+70b5def7e6,gdaeeff99f8+006e14e809,gdbce86181e+6a170ce272,ge3d4d395c2+224150c836,ge5f7162a3a+bb2241c923,ge6cb8fbbf7+d119aed356,ge79ae78c31+b6588ad223,gf048a9a2f4+40ffced2b8,gf0baf85859+b4cca3d10f,w.2024.30
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 360 of file _configurableActionStructField.py.

362 ) -> ConfigurableActionStruct[ActionTypeVar]: ...
363

◆ __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 364 of file _configurableActionStructField.py.

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

◆ __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

◆ __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. " f"Attempting to set field to value {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 414 of file _configurableActionStructField.py.

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

◆ _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 421 of file _configurableActionStructField.py.

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

◆ 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 408 of file _configurableActionStructField.py.

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

◆ 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 371 of file _configurableActionStructField.py.

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

◆ 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 394 of file _configurableActionStructField.py.

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

◆ 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 385 of file _configurableActionStructField.py.

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

◆ 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 379 of file _configurableActionStructField.py.

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

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 452 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: