Cellular Automata Plots

This module provides plotting functions to visualize cellular automata.

utopya.plot_funcs.ca.imshow_hexagonal(data: xarray.core.dataarray.DataArray, *, hlpr: utopya.plotting.PlotHelper, colormap: Union[str, matplotlib.colors.Colormap], **kwargs) matplotlib.image.AxesImage[source]

Display data as an image, i.e., on a 2D hexagonal grid.

Parameters
  • data (xr.DataArray) – The array-like data to plot as image.

  • hlpr (PlotHelper) – The plot helper.

  • colormap (str or mpl.colors.Colormap) – The colormap to use.

Returns

The RegularPolyCollection representing the hexgrid.

utopya.plot_funcs.ca.state(dm: utopya.datamanager.DataManager, *, uni: utopya.datagroup.UniverseGroup, hlpr: utopya.plotting.PlotHelper, model_name: str, to_plot: dict, time_idx: int, transform_data: Optional[dict] = None, transformations_log_level: int = 10, preprocess_funcs: Optional[Dict[str, Callable]] = None, default_imshow_kwargs: Optional[dict] = None)[source]

Plots the state of the cellular automaton as a 2D heat map. This plot function can be used for a single plot, but also supports animation.

Which properties of the state to plot can be defined in to_plot.

Parameters
  • dm (DataManager) – The DataManager that holds all loaded data

  • uni (UniverseGroup) – The currently selected universe, parsed by the UniversePlotCreator.

  • hlpr (PlotHelper) – The plot helper

  • model_name (str) – The name of the model of which the data is to be plotted

  • to_plot (dict) –

    Which data to plot and how. The keys of this dict refer to a path within the data and can include forward slashes to navigate to data of submodels. Each of these keys is expected to hold yet another dict, supporting the following configuration options (all optional):

    • cmap (str or dict): The colormap to use. If it is a dict, a

      discrete colormap is assumed. The keys will be the labels and the values the color. Association happens in the order of entries.

    • title (str): The title for this sub-plot

    • limits (2-tuple, list): The fixed heat map limits of this

      property; if not given, limits will be auto-scaled.

    • **imshow_kwargs: passed on to imshow invocation

  • time_idx (int) – Which time index to plot the data of. Is ignored when creating an animation.

  • transform_data (dict, optional) – Transformations to apply to the data. The top-level entries must correspond to the entries of to_plot. This can be used for dimensionality reduction of the data, but also for other operations, e.g. to selecting a slice. For available parameters, see utopya.dataprocessing.transform()

  • transformations_log_level (int, optional) – The logging level of all the data transformation operations.

  • preprocess_funcs (Dict[str, Callable], optional) – A dictionary of pre- processing callables, where keys need to correspond to the property name in to_plot that is to be pre-processed. This argument can be used to implement model-specific preprocessing by implementing another plot function, which defines this dict and passes it to this function. NOTE If possible, use transform_data.

  • default_imshow_kwargs (dict, optional) – The default parameters passed to the underlying imshow plotting function. These are updated by the values given via to_plot.

Raises

ValueError – Shape mismatch of data selected by to_plot

Warns

Use of transform_data and preprocess_funcs (is called in this order)


Spatial Representation

For a spatial representation of a cellular automaton, there is the ca.state method. It works with the PlotHelper interface and supports an animation update. For information on how to configure it such that it performs an animation, see Animations.

utopya.plot_funcs.ca.state(dm: utopya.datamanager.DataManager, *, uni: utopya.datagroup.UniverseGroup, hlpr: utopya.plotting.PlotHelper, model_name: str, to_plot: dict, time_idx: int, transform_data: Optional[dict] = None, transformations_log_level: int = 10, preprocess_funcs: Optional[Dict[str, Callable]] = None, default_imshow_kwargs: Optional[dict] = None)[source]

Plots the state of the cellular automaton as a 2D heat map. This plot function can be used for a single plot, but also supports animation.

Which properties of the state to plot can be defined in to_plot.

Parameters
  • dm (DataManager) – The DataManager that holds all loaded data

  • uni (UniverseGroup) – The currently selected universe, parsed by the UniversePlotCreator.

  • hlpr (PlotHelper) – The plot helper

  • model_name (str) – The name of the model of which the data is to be plotted

  • to_plot (dict) –

    Which data to plot and how. The keys of this dict refer to a path within the data and can include forward slashes to navigate to data of submodels. Each of these keys is expected to hold yet another dict, supporting the following configuration options (all optional):

    • cmap (str or dict): The colormap to use. If it is a dict, a

      discrete colormap is assumed. The keys will be the labels and the values the color. Association happens in the order of entries.

    • title (str): The title for this sub-plot

    • limits (2-tuple, list): The fixed heat map limits of this

      property; if not given, limits will be auto-scaled.

    • **imshow_kwargs: passed on to imshow invocation

  • time_idx (int) – Which time index to plot the data of. Is ignored when creating an animation.

  • transform_data (dict, optional) – Transformations to apply to the data. The top-level entries must correspond to the entries of to_plot. This can be used for dimensionality reduction of the data, but also for other operations, e.g. to selecting a slice. For available parameters, see utopya.dataprocessing.transform()

  • transformations_log_level (int, optional) – The logging level of all the data transformation operations.

  • preprocess_funcs (Dict[str, Callable], optional) – A dictionary of pre- processing callables, where keys need to correspond to the property name in to_plot that is to be pre-processed. This argument can be used to implement model-specific preprocessing by implementing another plot function, which defines this dict and passes it to this function. NOTE If possible, use transform_data.

  • default_imshow_kwargs (dict, optional) – The default parameters passed to the underlying imshow plotting function. These are updated by the values given via to_plot.

Raises

ValueError – Shape mismatch of data selected by to_plot

Warns

Use of transform_data and preprocess_funcs (is called in this order)