Landscape Module¶
The BaseCell Class¶
-
class
src.biosim.landscape.BaseCell[source]¶ -
herbivores¶ Type: list
-
carnivores¶ Type: list
-
fodder¶ Type: float
-
death_list¶ list for stats
Type: list
-
birth_list¶ list for stats
Type: list
Initializes the cell and creates empty lists for herbivores and carnivores. Creates attribute for fodder
-
add_animals(animal_list)[source] Adds a new population from a list of dictionaries to the Cell In the dictionaries the species, age and weight of each animal resides.
Parameters: animal_list (list) – List of Dictionaries
-
add_migrated_carn(carnivore)[source] Add carnivore to list of carnivores
-
add_migrated_herb(herbivore)[source] Add herbivore to list of herbivores
-
age_pop()[source] Adds a increment of 1 to the animals age attribute
-
chain_lists()[source] Chains list of cell.herbivores with cell.carnivores lists
-
die()[source] Iterates through animals, adds them to a death list.
Iterates through death list and removes them from the cell’s appropriate list by object instance.
-
BaseAnimal.death()¶ Returns bool
Returns: - death_list_herb (list) – Herbivore instances that died
- death_list_carn (list) – Carnivore instances that died
-
-
feed_all()[source] Makes all animals eat
-
feed_carnivores()[source] Sorts herbivores by fitness Sorts carnivores by fitness
The fittest carnivore feeds first with sorted list of herbivores as input.
Sets the returned list as the new list for herbivores.
-
feed(least_fit_herbivores)¶ Returns list of herbivores that are still living
-
-
feed_herbivores()[source] Herbivores is sorted by fitness thereafter goes through the updated list in reverse. This makes the most fit animals first to feed.
Updated the cells amount of food(fodder) after each animal has fed.
-
feed()
-
-
grow()[source] Grows fodder in cell
-
lose_weight()[source] Makes animals in cell lose_weight
-
meat_for_carnivores¶ Sum the weight of all herbivores in cell
Type: Property
-
migrate(prob_herb, prob_carn)[source] Goes through herbivores, migrates, appends to moved_herb. Goes through carnivores, migrates, appends to moved_carn. Deletes the animal that has moved from the list of class.
Parameters: - prob_herb (list of tuples) – Location (y, x) and Probability
- prob_carn (list of tuples) – Location (y, x) and Probability
Returns: - moved_herb (list of tuples) – New position (y, x) and animal instance
- moved_carn (list of tuples) – New position (y, x) and animal instance
-
num_animals¶ sum of all num_carnivores and num_herbivores
Type: Property
-
num_carnivores¶ number of carnivores derived from len of list
Type: Property
-
num_herbivores¶ number of herbivores derived from len of list
Type: Property
-
procreate()[source] Goes through herbivores and carnivores if there is more than one animal the same list.
Calls birth method, and if offspring returned appends the offspring to the cells appropriate list.
-
birth(num_of_same_species)¶
Returns: - birth_list_herb (list) – list of offspring
- birth_list_carn (list) – list of offspring
-
-
propensity¶ Property of each cell, calculates each year once because of self._calculate_propensity
if cell is not passable propensities will be zero
Propensity is calculated by:
\[\epsilon_k = \frac{f_k}{(n_k + 1)F'}\]\[\pi_k = e^{\gamma\epsilon_j}\]\[\pi_j = \frac{\pi_j}{\sum\epsilon_C(i)}\]sets self.calculate_propensity to False when propensity is calculated
Returns: self._propensity – key - str containing class.__name__ and value - propensity Return type: dict
-
remove_migrated_carn(carnivore)[source] Remove carnivore from list of carnivores
-
remove_migrated_herb(herbivore)[source] Remove herbivore from list of herbivores
-
reset_calculate_propensity()[source] Sets _calculate_propensity to True
-
classmethod
set_parameters(passable=None, f_max=None, alpha=None)[source]¶ Method for changing one or all parameters with a dictionary for class of BaseCell class By checking all parameters first, set parameters does not change any parameters before it is sure that all parameters are valid
Parameters: - passable (bool) – If Animals can enter cell
- f_max (float) – Maximum amount of fodder in cell
- alpha (float) – Growth rate for fodder
-
static
sort_by_fitness(animal_list)[source] Sort list of animals by fitness
-