eradiate.scenes.core.KernelDict#

class eradiate.scenes.core.KernelDict(data=_Nothing.NOTHING, post_load=_Nothing.NOTHING, variant=_Nothing.NOTHING)[source]#

Bases: collections.abc.MutableMapping

A dictionary-like object designed to contain a scene specification appropriate for instantiation with load_dict().

KernelDict keeps track of the variant it has been created with and performs minimal checks to help prevent inconsistent scene creation.

Parameters
  • data (dict, default: {}) – Scene dictionary.

  • post_load (dict, default: {}) – Post-load update dictionary.

  • variant (str, default: mitsuba.set_variant()) – Kernel variant for which the dictionary is created. Defaults to currently active variant (if any; otherwise raises).

Fields
  • data (dict) – Scene dictionary.

  • post_load (dict) – Post-load update dictionary.

  • variant (str) – Kernel variant for which the dictionary is created.

add(*elements, ctx)[source]#

Merge the content of a SceneElement or another dictionary object with the current KernelDict.

Parameters
  • *elements (SceneElement) – SceneElement instances to add to the scene dictionary.

  • ctx (KernelDictContext) – A context data structure containing parameters relevant for kernel dictionary generation. This argument is keyword-only and required.

check()[source]#

Perform basic checks on the dictionary:

  • check that the "type" parameter is included;

  • check if the variant for which the kernel dictionary was created is the same as the current one.

Raises
  • ValueError – If the "type" parameter is missing.

  • .KernelVariantError – If the variant for which the kernel dictionary was created is not the same as the current one

clear() None.  Remove all items from D.#
classmethod from_elements(*elements, ctx)[source]#

Create a new KernelDict from one or more scene elements.

Parameters
  • *elements (SceneElement) – SceneElement instances to add to the scene dictionary.

  • ctx (KernelDictContext) – A context data structure containing parameters relevant for kernel dictionary generation. This argument is keyword-only and required.

Returns

KernelDict – Created scene kernel dictionary.

get(k[, d]) D[k] if k in D, else d.  d defaults to None.#
items() a set-like object providing a view on D's items#
keys() a set-like object providing a view on D's keys#
load(strip=True, post_load_update=True)[source]#

Call load_dict() on self. In addition, a post-load update can be applied.

If the encapsulated dictionary misses a "type" key, it will be promoted to a scene dictionary through the addition of {"type": "scene"}. For instance, it means that

{
    "shape1": {"type": "sphere"},
    "shape2": {"type": "sphere"},
}

will be interpreted as

{
    "type": "scene",
    "shape1": {"type": "sphere"},
    "shape2": {"type": "sphere"},
}

Note

Requires a valid selected operational mode.

Parameters
  • strip (bool) – If True, if data has no 'type' entry and if data consists of one nested dictionary, it will be loaded directly. For instance, it means that

    {"phase": {"type": "rayleigh"}}
    

    will be stripped to

    {"type": "rayleigh"}
    
  • post_load_update (bool) – If True, use traverse() and update loaded scene parameters according to data stored in post_load.

Returns

mitsuba.core.Object – Loaded Mitsuba object.

merge(other)[source]#

Merge another KernelDict with the current one.

Parameters

other (KernelDict) – A kernel dictionary whose main and post-load dictionaries will be used to update the current one.

pop(k[, d]) v, remove specified key and return the corresponding value.#

If key is not found, d is returned if given, otherwise KeyError is raised.

popitem() (k, v), remove and return some (key, value) pair#

as a 2-tuple; but raise KeyError if D is empty.

setdefault(k[, d]) D.get(k,d), also set D[k]=d if k not in D#
update([E, ]**F) None.  Update D from mapping/iterable E and F.#

If E present and has a .keys() method, does: for k in E: D[k] = E[k] If E present and lacks .keys() method, does: for (k, v) in E: D[k] = v In either case, this is followed by: for k, v in F.items(): D[k] = v

values() an object providing a view on D's values#