dantro.plot._cfg module

A module containing tools for generating plot configurations

dantro.plot._cfg._check_visited(visited: Sequence[Tuple[str, str]], *, next_visit: Tuple[str, str]) → Sequence[Tuple[str, str]][source]

Performs cycle detection on the sequence of visited entries and raises an error if there will be a cycle. Otherwise, returns the new visiting sequence by appending the next_visit to the given sequence of visited entries.

dantro.plot._cfg._find_in_pool(name: str, *, base_pools: collections.OrderedDict, skip: Sequence[Tuple[str, str]] = ()) → Tuple[str, dict, Tuple[str, dict]][source]

Looks up a plot configuration in the given pool and returns the name of the pool, the found configuration, and the subset of pools that were not yet looked up.

With skip, certain entries can be skipped, e.g. the entry from which the current based_on is resolved from.

dantro.plot._cfg._resolve_based_on(pcfg: Union[dict, paramspace.paramspace.ParamSpace], *, base_pools: collections.OrderedDict, _visited: Sequence[Tuple[str, str]]) → Union[dict, paramspace.paramspace.ParamSpace][source]

Assembles a single plot’s configuration by recursively resolving its based_on entry from a pool of available base plot configurations.

This function always works on a deep copy of pcfg and will remove any potentially existing based_on entry on the root level of pcfg.

Furthermore, it accepts ParamSpace objects for plot configuration entries, recursively updating their dict representation and again creating a ParamSpace object from them afterwards.

dantro.plot._cfg.resolve_based_on(plots_cfg: Dict[str, Union[dict, paramspace.paramspace.ParamSpace]], *, label: str, base_pools: Union[collections.OrderedDict, Sequence[Tuple[str, dict]]]) → Dict[str, dict][source]

Resolves the based_on entries of all plot configurations in the given plot configurations dictionary plots_cfg.

The procedure is as follows:

  • Iterate over root-level entries in the plots_cfg dict

  • For each entry, check if a based_on entry is present and needs to be resolved.

  • If so, recursively resolve the configuration entry, starting from the first entry in the based_on sequence and recursively updating it with content of the following elements. The final recursive update is that of the plot configuration given in plots_cfg.

Lookups happen from a pool of plot configurations: the base_pools, combined with the given plots_cfg itself. The based_on entries are looked up by name using the following rules:

  • Other plot configurations within plots_cfg have highest precedence.

  • If no name is found there, lookups happen from within base_pools, iterating over it in reverse, meaning that entries later in the ordered dict take precedence over those earlier.

  • If entries in a base pool are again using based_on, these will be looked up using the same rules, but with the pool restricted to entries with lower precedence than that pool.

  • Lookups within the same pool will exclude the name of the currently updated plot configuration. Example: some_plot: {based_on: some_plot} will look for some_plot in some lower-precedence pool.

The resolution of plot configurations works on deep copies of the given plots_cfg and all the based_on entries to avoid mutability issues between parts of these highly nested dictionaries.

For integrated use of this functionality, see Plot Configuration Inheritance.

Parameters
  • plots_cfg (dict) – A dict with multiple plot configurations to resolve the based_on entries of. Root-level keys are assumed to correspond to individual plot configurations. If this argument evaluates to False, will silently assume an empty plots configuration.

  • label (str) – The label to use for the given plots configuration when adding it to the base configuration pool.

  • base_pools (Union[OrderedDict, Sequence[Tuple[str, dict]]]) – The base configuration pools to look up the based_on entries in. This needs to be an OrderedDict or a type that can be converted into one. Keys will be used as labels for the individual pools. The order of this pool is relevant, see above.

Raises

PlotConfigError – Upon missing based_on values or dependency loops.

dantro.plot._cfg.resolve_based_on_single(*, name: str, based_on: Union[str, Sequence[str]], plot_cfg: dict, **resolve_based_on_kwargs) → dict[source]

Wrapper for resolve_based_on() for cases of single independent plot configurations.

Parameters
  • name (str) – The name of the single plot

  • based_on (Union[str, Sequence[str]]) – The extracted based_on argument.

  • plot_cfg (dict) – The rest of the single plot’s configuration. This may not include based_on! If this argument evaluates to False, will silently assume an empty plots configuration.

  • **resolve_based_on_kwargs – Passed on