zasim.config - Generate configs from different sources

Inheritance diagram of zasim.config

This module implements different ways to create configurations.

The idea behind the API is, to let the user set any settings in the constructor of any Configuration instance and to let the Target instance pass a size hint and datatype when generating the config.

This way, the Target doesn’t have to know anything about what configuration to generate and how to do it.

By letting the Target only supply a size_hint, the Configuration is allowed to dictate what size the configuration should have. This is important especially for loading configurations from files.

class zasim.config.BaseConfiguration[source]

Bases: object

This class defines the interface that initial configuration generators should have to the outside.

generate(size_hint=None, dtype=<type 'numpy.int32'>)[source]

Generate the configuration.

Parameters:
  • size_hint

    What size to generate. This can be None, if the generator may choose the dimensionality and sizes of each dimension freely, or a tuple containing None or a number for each dimension. If one or all of the dimensions are None, their size will be decided by the generator.

    The size_hint may be ignored by the generator for cases like loading a configuration from a file.

  • dtype – The dtype to use for the array.
Returns:

A numpy array to be used as the configuration.

class zasim.config.BaseRandomConfiguration(base=2, *percentages)[source]

Bases: zasim.config.BaseConfiguration

Create a random initial configuration with values from 0 to base-1 inclusive and, if positional arguments are given, use the supplied percentages for the different states.

size_hint_to_size(size_hint=None)[source]
generate(size_hint=None, dtype=<type 'numpy.int32'>)[source]
make_percentages_cumulative(percentages)[source]
class zasim.config.RandomConfiguration(base=2, *percentages)[source]

Bases: zasim.config.BaseRandomConfiguration

Create a random initial configuration with values from 0 to base-1 inclusive and, if positional arguments are given, use the supplied percentages for the different states.

class zasim.config.RandomConfigurationFromPalette(values, *percentages)[source]

Bases: zasim.config.BaseRandomConfiguration

Create a random initial configuration with the given values and, if positional arguments are given, use the supplied percentages for the different states.

class zasim.config.BaseAsciiConfiguration(strdata, palette)[source]

Bases: zasim.config.BaseConfiguration

Generate a configuration from an ascii string.

The palette is either a dictionary, mapping value to representation or a list with representation values. If no palette is supplied, the PALETTE value from BaseConsolePainter is used.

generate(size_hint=None, dtype=<type 'numpy.int32'>)[source]
class zasim.config.FileAsciiConfiguration(file_or_name, palette=None)[source]

Bases: zasim.config.BaseAsciiConfiguration

Import an ascii-based file with a palette, as generated by zasim.display.console.BaseConsolePainter.export.

generate(**kwargs)[source]
class zasim.config.ImageConfiguration(filename, scale=1, palette=None, fuzz=False)[source]

Bases: zasim.config.BaseConfiguration

Import an image file as a configuration.

generate(size_hint=None, dtype=<type 'numpy.int32'>)[source]
class zasim.config.PatternConfiguration(patterns, layout)[source]

Bases: zasim.config.BaseConfiguration

This generator accepts different patterns as lists of values and a layout that defines how those patterns make up the whole configuration.

Pattern 0 will be used to fill the whole background, all others will be embedded centered in the configuration according to layout.

generate(size_hint=None, dtype=<type 'numpy.int32'>)[source]
zasim.config.function_of_radius(function, max_dist='diagonal')[source]

Turns a function that takes the radius and maximum distance as arguments into a function compatible with the DensityDistributedConfiguration class.

class zasim.config.DensityDistributedConfiguration(prob_dist_fun)[source]

Bases: zasim.config.RandomConfiguration

Create a distribution from functions giving the probability for each field to have a given value.

For prob_dist_fun, supply a dictionary with one entry per value you want to end up in the configuration as the key. The value is a lambda from position and config size to relative probability at that position.

For each position in the configuration, every function is called and the results added up to figure out, what value would be 100% for that cell, then the relative probabilities are divided and used for choosing a value.

If a value is an integer, rather than a callable, then it will be interpreted as a constant function instead.

generate(size_hint=None, dtype=<type 'numpy.int32'>)[source]

Previous topic

Common interface for Simulator classes

Next topic

zasim.display - Package for displaying configs

This Page