Island Module

The Island Class

class src.biosim.island.Island(island_map_string, ini_pop, store_stats=False)[source]

Initiates the Island class: holds method for updating the map Class attribute map_params holds information of which letter relates to which class of landscape.py

Parameters:
  • island_map_string (multilinestring) – Multiple lines of string with characters representing cell type
  • ini_pop (dict) – Key: location - Value: list of dict of species, age, and weight
map

calls method make_map, map creation from a multilinestring

Type:dict
herbivore_tot_data

Total number of herbivores indexed by year

Type:list
carnivore_tot_data

Total number of carnivore indexed by year

Type:list
stats

multiple nested dicts, stores all data on dead/ born animals.

Type:dict

Initializes instance of Island

Parameters:
  • island_map_string (str) – Multilinestring of map
  • ini_pop (dict) – key : location - Value : list of dict
  • store_stats (bool) –
add_carn_to_new_cell(new_loc, carnivore)[source]

Add herbivore to cell in new location

add_herb_to_new_cell(new_loc, herbivore)[source]

Add herbivore to cell in new location

add_population(population)[source]

Feeds a dictionary of population to cell by position.

Parameters:population (list) – loc: tuple pop: dict
BaseCell.add_animals()
age_animals()[source]

Calls age_pop in all cells of Island.map

static clean_multi_line_string(island_map_string)[source]

Strips and splits a multilinestring and checks for equal length of lines and specific letters at the edges: in this case ‘O’. Raises ValueError if criteria are not met.

Parameters:island_map_string (multilinestring) – Lines is row, letter is column
Returns:lines – Lines of strings (cleaned)
Return type:list
create_and_update_stats_structure()[source]

Creates data structure for stats

die()[source]

Calls die in all cells of Island.map, adds dead to stats

feed()[source]

Calls feed_all in all cells of Island.map

lose_weight()[source]

Calls lose_weight in all cells of Island.map

make_map(island_map_string)[source]

Creates a dictionary data frame that stores instances of cells by key: a tuple of (y, x)-coordinates

Also saves the length and with of the island

Parameters:island_map_string (str) – string of multiple lines
Returns:map – key : tuple, value : instance of subclass of BaseCell
Return type:dict
migrate()[source]

Goes through the map attribute of Island and calculates probabilities for herbivores and carnivores, with position and name of class.

calls migrate method in instance of subclass of BaseCell .. method:: BaseCell.migrate()

probability_calc(pos, animal)[source]

Notes

Adds herbivores and carnivores that has migrated to new cells

num_animals

Total number of animals on island.

Returns:num_animals
Return type:int
num_animals_per_species

Number of animals per species in island, as dictionary.

Returns:num_animals_per_species
Return type:dictionary
probability_calc(pos, animal)[source]

Finds the preposition for all neighbouring cells within dx +- 1 and dy +-1. This means we have the positions North, West, South and East of the current position.

Then calculates the probability for the type of animal.

If the animal has nowhere to move, it returns None :param pos: Position of current cell :type pos: tuple :param animal: Name of the animal :type animal: str

Returns:prob_list – (Coordinate(y, x), and probabilities)
Return type:list of tuples
procreate()[source]

Calls procreate in all cells of Island.map, adds born to stats

ready_for_new_year()[source]

Resets each cell in Island.map .. method:: BaseCell.grow

BaseCell.reset_calculate_propensity()
BaseAnimal.reset_has_moved()
simulate_one_year()[source]

Simulates a whole year by the following sequence

update_data_list()[source]

Updates list for use in visualization

year

Last year simulated.

Functions outside classes

src.biosim.island.check_length(lines)[source]

Compares length of all lines in a list of lines to the first

Parameters:lines (list) – lines
Returns:False if not equal length, True if length is equal
Return type:bool