Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Animal - Feature/multi grid occupancy #530

Merged
merged 38 commits into from
Dec 4, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
9b88fe0
Basic outline of an Animal Territories class.
TaranRallings Jul 10, 2024
b963654
Added methods for initialize territory, territory size, updating terr…
TaranRallings Jul 10, 2024
e988161
Revised initialize_territory to use breadth-first search.
TaranRallings Jul 11, 2024
4b64df3
Merge branch 'develop' into feature/multi_grid_occupancy
TaranRallings Jul 11, 2024
11a8326
Added a Territory protocol to avoid circular reference.
TaranRallings Jul 11, 2024
0286b62
Added calls to initialize_territory to birth, migration, and metamorp…
TaranRallings Jul 11, 2024
0e3d2a3
Changed initialize_territory to use dynamic importing.
TaranRallings Jul 11, 2024
58a32a5
Added testing for AnimalTerritory.
TaranRallings Jul 11, 2024
67e0997
Refactored initialize_territory so that bfs_territory is a stand alon…
TaranRallings Jul 12, 2024
195417b
Added test for bfs_territory.
TaranRallings Jul 12, 2024
0aa128f
Added test for initialize_territory.
TaranRallings Jul 12, 2024
49ae8bb
Merge branch 'develop' into feature/multi_grid_occupancy
TaranRallings Jul 15, 2024
54639cb
Fixed test_calculate_potential_consumed_mass.
TaranRallings Jul 15, 2024
4c7fe4c
Reworking of types and protocols.
TaranRallings Jul 16, 2024
1766d88
Updated defecate for all pools in territory.
TaranRallings Jul 16, 2024
24f0c47
Merge branch 'develop' into feature/multi_grid_occupancy
TaranRallings Jul 17, 2024
aaa75e5
Many small changes to get typing to work between files/classes. This …
TaranRallings Jul 18, 2024
4ceba3c
die_individual now calls update_carcass_pools.
TaranRallings Jul 18, 2024
bb70dfb
Updated excrete for multi-grid.
TaranRallings Jul 18, 2024
1e93fc4
Added a community.occupancy attribute to track cohorts partially in a…
TaranRallings Jul 19, 2024
a896d0f
Added abandon_communities method to animal territory.
TaranRallings Jul 19, 2024
56ee5d0
Added a reinitialize_territory method and modified migrate.
TaranRallings Jul 19, 2024
d6313bf
Updated test_animal_territories.
TaranRallings Jul 22, 2024
6798997
Updated tests for animal_cohorts.
TaranRallings Jul 23, 2024
1eba4f2
Added all_occupying_cohorts method and revised test_forage_community.
TaranRallings Jul 24, 2024
1f85190
Revised test_inflict_non_predation_mortality.
TaranRallings Jul 25, 2024
af6bb16
Fully revised test_animal_communities for multi-grid.
TaranRallings Jul 25, 2024
c68a9e7
Updated animal model tests.
TaranRallings Jul 25, 2024
81cd1f4
Finished revising all animal tests for multi grid occupancy.
TaranRallings Jul 25, 2024
5b5708d
Merge branch 'develop' into feature/multi_grid_occupancy
TaranRallings Jul 26, 2024
4dbb2d8
Added temporary solution to problem with plant data and ve_run testing.
TaranRallings Jul 26, 2024
4efee34
Added test for reinitialize territory.
TaranRallings Jul 26, 2024
a777fc2
Small docstring fix in animal communities.
TaranRallings Jul 29, 2024
fbae47b
Added a mass check on forage_cohort.
TaranRallings Jul 30, 2024
dddfa6b
Adjusted defecate docstring to fix doc build errors.
TaranRallings Jul 30, 2024
1908f0a
Modified test_generate_animal_model to deal with stochastic warnings.
TaranRallings Jul 30, 2024
8c68c14
Fixed defecate docstring bug.
TaranRallings Jul 30, 2024
b979702
Merge branch 'develop' into feature/multi_grid_occupancy
TaranRallings Aug 2, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Updated defecate for all pools in territory.
  • Loading branch information
TaranRallings committed Jul 16, 2024
commit 1766d883d8367c96d19c2fb390d780f0e07c288e
55 changes: 33 additions & 22 deletions virtual_ecosystem/models/animal/animal_cohorts.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,10 +172,10 @@ def respire(self, excreta_mass: float) -> float:

def defecate(
self,
excrement_pool: DecayPool,
excrement_pools: Sequence[DecayPool],
mass_consumed: float,
) -> None:
"""Transfer waste mass from an animal cohort to the excrement pool.
"""Transfer waste mass from an animal cohort to the excrement pools.

Currently, this function is in an inbetween state where mass is removed from
the animal cohort but it is recieved by the litter pool as energy. This will be
Expand All @@ -187,21 +187,32 @@ def defecate(
TODO: MGO - rework for territories (if need be)

Args:
excrement_pool: The local ExcrementSoil pool in which waste is deposited.
excrement_pools: The ExcrementPool objects in the cohort's territory in
which waste is deposited.
mass_consumed: The amount of mass flowing through cohort digestion.
"""
# Find total waste mass, the total amount of waste is then found by the
# average cohort member * number individuals.
waste_energy = mass_consumed * self.functional_group.conversion_efficiency
# the number of communities over which the feces are to be distributed
number_communities = len(excrement_pools)

# This total waste is then split between decay and scavengeable excrement
excrement_pool.scavengeable_energy += (
(1 - self.decay_fraction_excrement) * waste_energy * self.individuals
)
excrement_pool.decomposed_energy += (
self.decay_fraction_excrement * waste_energy * self.individuals
# Find total waste mass, the total amount of waste is found by the
# average cohort member * number individuals.
waste_energy = (
mass_consumed
* self.functional_group.conversion_efficiency
* self.individuals
)

waste_energy_per_community = waste_energy / number_communities

for excrement_pool in excrement_pools:
# This total waste is then split between decay and scavengeable excrement
excrement_pool.scavengeable_energy += (
1 - self.decay_fraction_excrement
) * waste_energy_per_community
excrement_pool.decomposed_energy += (
self.decay_fraction_excrement * waste_energy_per_community
)

def increase_age(self, dt: timedelta64) -> None:
"""The function to modify cohort age as time passes and flag maturity.

Expand Down Expand Up @@ -564,7 +575,7 @@ def calculate_consumed_mass_predation(
def delta_mass_predation(
self,
animal_list: Sequence[Consumer],
excrement_pool: DecayPool,
excrement_pools: Sequence[DecayPool],
carcass_pool: CarcassPool,
) -> float:
"""This method handles mass assimilation from predation.
Expand All @@ -576,7 +587,7 @@ def delta_mass_predation(
Args:
animal_list: A sequence of animal cohorts that can be consumed by the
predator.
excrement_pool: A pool representing the excrement in the grid cell.
excrement_pools: The pools representing the excrement in the territory.
carcass_pool: A pool representing the animal carcasses in the grid cell.

Returns:
Expand All @@ -598,7 +609,7 @@ def delta_mass_predation(
total_consumed_mass += actual_consumed_mass

# Process waste generated from predation, separate from herbivory b/c diff waste
self.defecate(excrement_pool, total_consumed_mass)
self.defecate(excrement_pools, total_consumed_mass)
return total_consumed_mass

def calculate_consumed_mass_herbivory(
Expand Down Expand Up @@ -629,15 +640,15 @@ def calculate_consumed_mass_herbivory(
return consumed_mass

def delta_mass_herbivory(
self, plant_list: Sequence[Resource], excrement_pool: DecayPool
self, plant_list: Sequence[Resource], excrement_pools: Sequence[DecayPool]
) -> float:
"""This method handles mass assimilation from herbivory.

TODO: update name

Args:
plant_list: A sequence of plant resources available for herbivory.
excrement_pool: A pool representing the excrement in the grid cell.
excrement_pools: The pools representing the excrement in the territory.

Returns:
A float of the total plant mass consumed by the animal cohort in g.
Expand All @@ -649,7 +660,7 @@ def delta_mass_herbivory(
# Calculate the mass to be consumed from this plant
consumed_mass = self.calculate_consumed_mass_herbivory(plant_list, plant)
# Update the plant resource's state based on consumed mass
actual_consumed_mass = plant.get_eaten(consumed_mass, self, excrement_pool)
actual_consumed_mass = plant.get_eaten(consumed_mass, self, excrement_pools)
# Update total mass gained by the herbivore
total_consumed_mass += actual_consumed_mass

Expand All @@ -659,15 +670,15 @@ def forage_cohort(
self,
plant_list: Sequence[Resource],
animal_list: Sequence[Consumer],
excrement_pool: DecayPool,
excrement_pools: Sequence[DecayPool],
carcass_pool: CarcassPool,
) -> None:
"""This function handles selection of resources from a list for consumption.

Args:
plant_list: A sequence of plant resources available for herbivory.
animal_list: A sequence of animal cohorts available for predation.
excrement_pool: A pool representing the excrement in the grid cell.
excrement_pools: A pool representing the excrement in the grid cell.
carcass_pool: A pool representing the carcasses in the grid cell.

Return:
Expand All @@ -680,15 +691,15 @@ def forage_cohort(
# Herbivore diet
if self.functional_group.diet == DietType.HERBIVORE and plant_list:
consumed_mass = self.delta_mass_herbivory(
plant_list, excrement_pool
plant_list, excrement_pools
) # Directly modifies the plant mass
self.eat(consumed_mass) # Accumulate net mass gain from each plant

# Carnivore diet
elif self.functional_group.diet == DietType.CARNIVORE and animal_list:
# Calculate the mass gained from predation
consumed_mass = self.delta_mass_predation(
animal_list, excrement_pool, carcass_pool
animal_list, excrement_pools, carcass_pool
)
# Update the predator's mass with the total gained mass
self.eat(consumed_mass)
Expand Down
6 changes: 3 additions & 3 deletions virtual_ecosystem/models/animal/animal_communities.py
Original file line number Diff line number Diff line change
Expand Up @@ -339,14 +339,14 @@ def forage_community(self) -> None:
raise ValueError("The cohort's territory hasn't been defined.")
prey_list = consumer_cohort.territory.get_prey(consumer_cohort)
plant_list = consumer_cohort.territory.get_plant_resources()
# excrement_list = consumer_cohort.territory.get_excrement_pools()
excrement_list = consumer_cohort.territory.get_excrement_pools()
# carcass_list = consumer_cohort.territory.get_carcass_pools()

# Initiate foraging for the consumer cohort with the prepared resources
consumer_cohort.forage_cohort(
plant_list=plant_list,
animal_list=prey_list,
excrement_pool=self.excrement_pool,
excrement_pools=excrement_list,
carcass_pool=self.carcass_pool,
)

Expand All @@ -366,7 +366,7 @@ def collect_prey(
consumer_cohort: The AnimalCohort for which a prey list is being collected

Returns:
A list of AnimalCohorts that can be preyed upon.
A sequence of AnimalCohorts that can be preyed upon.

TODO: MGO - collect prey over territory

Expand Down
2 changes: 1 addition & 1 deletion virtual_ecosystem/models/animal/protocols.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class Resource(Protocol):
mass_current: float

def get_eaten(
self, consumed_mass: float, consumer: Consumer, pool: DecayPool
self, consumed_mass: float, consumer: Consumer, pools: Sequence[DecayPool]
) -> float:
"""The get_eaten method defines a resource."""
...
Expand Down