Simulation Module

The BioSim Class

class src.biosim.simulation.BioSim(island_map=None, ini_pop=None, seed=None, ymax_animals=None, cmax_animals=None, img_base=None, img_fmt='png', movie_fmt='mp4', island_save_name=None, store_stats=False)[source]
Parameters:
  • island_map – Multi-line string specifying island geography
  • ini_pop – List of dictionaries specifying initial population
  • seed – Integer used as random number seed
  • ymax_animals – Number specifying y-axis limit for graph showing animal numbers
  • cmax_animals – Dict specifying color-code limits for animal densities
  • img_base – String with beginning of file name for figures, including path
  • img_fmt – String with file type for figures, e.g. ‘png’
  • island_save_name – Name of previously saved game, directory is already defined within the project.
  • store_stats – boolean statement, wether to store all dead and born animals overtime for analysis

If ymax_animals is None, the y-axis limit should be adjusted automatically.

If cmax_animals is None, sensible, fixed default values should be used. cmax_animals is a dict mapping species names to numbers, e.g.,

{‘Herbivore’: 50, ‘Carnivore’: 20}

If img_base is None, no figures are written to file. Filenames are formed as

‘{}_{:05d}.{}’.format(img_base, img_no, img_fmt)

where img_no are consecutive image numbers starting from 0. img_base should contain a path and beginning of a file name.

add_population(population)[source]

Add a population to the island Calls function from Island.py

Parameters:population – List of dictionaries specifying population
animal_distribution

Pandas DataFrame with animal count per species for each cell on island.

clean_simulation(num_years)[source]

A simulation without any visualization.

Parameters:num_years (int) –
island_stats()[source]

Creates dictionary for birth and death rate. Can be used as an example for extracting data from stats.

Returns:
  • death_rate_per_year_herb (dict) – key : year, value : float
  • death_rate_per_year_carn (dict) – key : year, value : float
  • birth_rate_per_year_herb (dict) – key : year, value : float
  • birth_rate_per_year_carn (dict) – key : year, value : float
make_movie()[source]

Create MPEG4 movie from visualization images saved.

num_animals

Total number of animals on island.

num_animals_per_species

Number of animals per species in island, as dictionary.

save_sim(name)[source]

Calls function: save_sim outside Simulation

static set_animal_parameters(species, params)[source]

Set parameters for animal species.

Parameters:
  • species – String, name of animal species
  • params – Dict with valid parameter specification for species
static set_landscape_parameters(landscape, params)[source]

Set parameters for landscape type.

Parameters:
  • landscape – String, code letter for landscape
  • params – Dict with valid parameter specification for landscape
simulate(num_years, vis_years=1, img_years=None)[source]

Run simulation while visualizing the result.

Parameters:
  • num_years – number of years to simulate
  • vis_years – years between visualization updates
  • img_years – years between visualizations saved to files (default: vis_years)

Image files will be numbered consecutively.

year

Last year simulated.

Functions outside classes

src.biosim.simulation.save_sim(simulation, name)[source]

Save a state of Simulation

Parameters:
  • simulation (object) – Instance of Simulation
  • name (str) – Save name
src.biosim.simulation.load_sim(name)[source]

Loads state of Simulation

Parameters:name (file) – Name of file
Returns:
Return type:Loaded file of Simulation