eradiate.contexts.KernelDictContext#

class eradiate.contexts.KernelDictContext(**kwargs)[source]#

Bases: eradiate.contexts.Context

Kernel dictionary evaluation context data structure. This class is used e.g. to store information about the spectral configuration to apply when generating kernel dictionaries associated with a SceneElement instance.

A number of static fields are defined and automatically initialised upon instantiation. In addition, the dynamic field stores a dictionary in which arbitrary data can be stored.

Both the static and dynamic data can be accessed as attributes. However, since instances are frozen, the recommended way to update a KernelDictContext is to use its evolve() method and create a copy.

Although adding just any dynamic field to a KernelDictContext instance is possible, this class also holds a registry of known dynamic fields (see KernelDictContext: List of registered dynamic context fields).

Parameters
  • spectral_ctx (SpectralContext or dict, default: SpectralContext.new()) – Spectral context (used to evaluate quantities with any degree or kind of dependency vs spectrally varying quantities).

  • ref (bool, default: True) – If True, use references when relevant during kernel dictionary generation.

  • dynamic (dict, default: {}) – A dynamic table containing specific context data.

Fields
  • spectral_ctx (SpectralContext) – Spectral context (used to evaluate quantities with any degree or kind of dependency vs spectrally varying quantities).

  • ref (bool) – If True, use references when relevant during kernel dictionary generation.

  • dynamic (dict) – A dynamic table containing specific context data.

Notes

In the unlikely (pointless but technically possible) event of a dynamic data field having the same name as a static field, the former takes precedence when using attribute access.

Examples

In addition to the regular initialisation pattern (i.e. passing field values as arguments to the constructor), the dynamic dictionary can also be populated by passing additional keyword arguments. For instance, the two following init patterns are equivalent:

>>> KernelDictContext(dynamic={"foo": "bar"})
KernelDictContext(..., dynamic={'foo': 'bar'})
>>> KernelDictContext(foo="bar")
KernelDictContext(..., dynamic={'foo': 'bar'})

Access to dynamic data can go through direct query of the dictionary, or using attributes:

>>> ctx = KernelDictContext(foo="bar")
>>> ctx.dynamic["foo"]
'bar'
>>> ctx.foo
'bar'
class DynamicFieldRegistry(data=_Nothing.NOTHING)[source]#

Bases: object

Record a list of dynamic fields.

Parameters

data (dict, default: {}) – Registry data. Each entry associates a dynamic field name to the fully qualified name of the function which registered it.

Fields

data (dict) – Registry data.

register(*field_names)[source]#

This decorator can be used to annotate a function and register one or several dynamic fields.

evolve(**changes)[source]#

Create a copy of self with changes applied. As for the constructor, updates to the dynamic table can be passed as keyword arguments. This is the recommended way.

DYNAMIC_FIELDS = KernelDictContext.DynamicFieldRegistry(data={'atmosphere_medium_id': ['eradiate.scenes.measure._perspective.PerspectiveCameraMeasure.kernel_dict', 'eradiate.scenes.measure._radiancemeter.RadiancemeterMeasure.kernel_dict']})#

Class instance of DynamicFieldRegistry which keeps track of dynamic context fields declared by functions in Eradiate.