eradiate.contexts.KernelDictContext
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 itsevolve()
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
ordict
, default:SpectralContext.new()
) – Spectral context (used to evaluate quantities with any degree or kind of dependency vs spectrally varying quantities).ref (
bool
, default:True
) – IfTrue
, 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
) – IfTrue
, 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.
- 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.