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

Adding non-predation mortality and semelparity to the Animal Module. #422

Merged
merged 18 commits into from
May 31, 2024

Conversation

TaranRallings
Copy link
Collaborator

Description

This adds a new trait to functional groups, reproductive type, which is broken into two variations, iteroparity (reproducing multiple times) and semelparity (reproducing once and then dying). Iteroparous organisms reproduce as before, semelparous organisms also use some of their non-reproductive mass in the reproductive event and then the cohort dies.

This PR also expands non-predation mortality to include a fixed background mortality, senescence mortality, and starvation mortality. There were small errors in the Madingley paper for the latter two mortalities so you may notice an excess of diagnostics in the testing from when I was trying to figure out if I had gone mad. I left them in, in case they might be useful later. Let me know if you think I should remove them.

Fixes # (issue)

Type of change

  • New feature (non-breaking change which adds functionality)
  • Optimization (back-end change that speeds up the code)
  • Bug fix (non-breaking change which fixes an issue)

Key checklist

  • Make sure you've run the pre-commit checks: $ pre-commit run -a
  • All tests pass: $ poetry run pytest

Further checks

  • Code is commented, particularly in hard-to-understand areas
  • Tests added that prove fix is effective or that feature works

@codecov-commenter
Copy link

codecov-commenter commented May 17, 2024

Codecov Report

Attention: Patch coverage is 96.15385% with 3 lines in your changes are missing coverage. Please review.

Project coverage is 94.69%. Comparing base (626476b) to head (f0d1a4a).

Files Patch % Lines
...ual_ecosystem/models/animals/animal_communities.py 88.23% 2 Missing ⚠️
virtual_ecosystem/models/animals/animal_cohorts.py 96.55% 1 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##           develop     #422      +/-   ##
===========================================
+ Coverage    94.62%   94.69%   +0.06%     
===========================================
  Files           69       69              
  Lines         3666     3732      +66     
===========================================
+ Hits          3469     3534      +65     
- Misses         197      198       +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Collaborator

@dalonsoa dalonsoa left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've added a few comments here and there, bur it looks good to me. To be honest, it's a fascinating topic!

virtual_ecosystem/models/animals/animal_cohorts.py Outdated Show resolved Hide resolved
Comment on lines +809 to +810
# TODO: the use of ceil here might have unintended outcomes, keep an eye on it
number_dead = ceil(pop_size * (1 - exp(-u_t * dt)))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm curious: what are the unexpected consequences?

pop_size * (1 - exp(-u_t * dt)) can be, at most, pop_size, so there's no risk of going above the population size when using ceil. And I guess that, at the lower end, it makes sense that a fraction of individual dead is a full individual dead, so sort a reasonable behaviour also there, right?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The issue is more apparent when you consider very large bodied animals. Consider, for example, a cohort of 20 mature adult elephants. The non-predation mortality will always be >0 and mortality is calculated every month with our current time-stepping. This means that, at minimum, one adult elephant dies every month regardless of environmental quality, a mortality rate significantly higher than real realized mortality rates.

I was considering a random draw for results under 1 individual, does that make sense to you?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see...

You're already using probabilistic events in other parts of the code, so I guess it might make sense. In that case, you will have a certain number of dead individuals for sure (might be none) and 1 more that might or might not be dead. This would be rather irrelevant for ants but might make a whole difference for elephants, as you say.

virtual_ecosystem/models/animals/animal_communities.py Outdated Show resolved Hide resolved
) -> float:
"""Mortality from body-mass loss.

There is a error in the madingley paper that does not follow their source code. The
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The paper seems to be full of errors 😄

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There have been some unpleasant surprises! When I get to doing the final parametrization, I'm going to comb through all of their actual C# code to make sure.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It should be them publishing an addendum...

Copy link
Collaborator

@dalonsoa dalonsoa left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All good!

@TaranRallings TaranRallings merged commit 5621b8d into develop May 31, 2024
9 checks passed
@TaranRallings TaranRallings deleted the feature/birth_and_mortality branch May 31, 2024 14:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants