Skip to content

Commit

Permalink
better aggregations and updating on every step now, instead of just J…
Browse files Browse the repository at this point in the history
…OTR step, which is obviously a poor choice as evidenced by my comment lol
  • Loading branch information
GondekNP committed Jan 8, 2025
1 parent 219a7ae commit 55a2867
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 11 deletions.
13 changes: 7 additions & 6 deletions vegetation/patch/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ def step(self):
)

# Update underlying patch
intersecting_cell.update_occupancy(self)
intersecting_cell.add_agent_link(self)

# Disperse
if self.life_stage == LifeStage.BREEDING:
Expand Down Expand Up @@ -264,10 +264,6 @@ def update_metrics(self):
mean_age = self.agents.select(agent_type=JoshuaTreeAgent).agg("age", np.mean)
self.mean_age = mean_age

# Number of agents (JoshuaTreeAgent)
n_agents = len(self.agents.select(agent_type=JoshuaTreeAgent))
self.n_agents = n_agents

# Number of agents by life stage
count_dict = (
self.agents.select(agent_type=JoshuaTreeAgent).groupby("life_stage").count()
Expand All @@ -277,6 +273,11 @@ def update_metrics(self):
self.n_juveniles = count_dict.get(LifeStage.JUVENILE, 0)
self.n_adults = count_dict.get(LifeStage.ADULT, 0)
self.n_breeding = count_dict.get(LifeStage.BREEDING, 0)
self.n_dead = count_dict.get(LifeStage.DEAD, 0)

# Number of agents (JoshuaTreeAgent)
n_agents = len(self.agents.select(agent_type=JoshuaTreeAgent))
self.n_agents = n_agents - self.n_dead

# Number of refugia cells occupied by JoshuaTreeAgents
count_dict = (
Expand All @@ -289,7 +290,7 @@ def update_metrics(self):

def step(self):
# Print timestep header
timestep_str = f"# {STD_INDENT*0}🕰️ Time passes. It is the year {self.steps} #"
timestep_str = f"# {STD_INDENT*0}🕰️ Time passes. It is the year {self.steps}. #"
nchar_timestep_str = len(timestep_str)
print("#" * (nchar_timestep_str - 1))
print(timestep_str)
Expand Down
14 changes: 9 additions & 5 deletions vegetation/patch/space.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
import logging
import time

from config.stages import LifeStage

# from patch.model import JoshuaTreeAgent
# import rioxarray as rxr

Expand Down Expand Up @@ -47,15 +49,17 @@ def __init__(

def step(self):
# Right now, this cell is being updated by the JOTR agent step, but it probably shouldn't be
# self.update_occupancy()
self.update_occupancy()
pass

def update_occupancy(self):
# Very clunky way to exclude dead agents
alive_jotr_agents = [agent for agent in self.jotr_agents if agent.life_stage != LifeStage.DEAD]
self.occupied_by_jotr_agents = True if len(alive_jotr_agents) > 0 else False


def update_occupancy(self, jotr_agent):
def add_agent_link(self, jotr_agent):
if jotr_agent.life_stage and jotr_agent not in self.jotr_agents:
self.jotr_agents.append(jotr_agent)
self.occupied_by_jotr_agents = True if len(self.jotr_agents) > 0 else False


class StudyArea(mg.GeoSpace):
def __init__(self, bounds, epsg, model):
Expand Down

0 comments on commit 55a2867

Please sign in to comment.