Skip to content

Trophic record exporter#1270

Merged
TaranRallings merged 18 commits intodevelopfrom
1247-animal-model---trophic-interaction-output
Jan 22, 2026
Merged

Trophic record exporter#1270
TaranRallings merged 18 commits intodevelopfrom
1247-animal-model---trophic-interaction-output

Conversation

@TaranRallings
Copy link
Copy Markdown
Collaborator

Description

This PR builds on the existing cohort exporter to export a second csv file detailing every trophic interaction that occurs over the course of the model run. The purpose of this data export is so that the data team can build food web time-series.

The way it works is that each cohort has a new dict attribute called trophic_record. Every trophic interaction the cohort has is stored in this dict. At the end of each time step, this information is dumped into the csv and then the attribute is reset.

New additions:

  • trophic_record cohort attribute
  • write-to-record functionality built into foraging system
  • trophic_output system built into exporter, mirroring the existing cohort_output system
  • supporting tests

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
  • Relevant documentation reviewed and updated

@codecov-commenter
Copy link
Copy Markdown

codecov-commenter commented Jan 21, 2026

Codecov Report

❌ Patch coverage is 93.61702% with 6 lines in your changes missing coverage. Please review.
✅ Project coverage is 94.97%. Comparing base (40d4456) to head (1af2cc4).

Files with missing lines Patch % Lines
virtual_ecosystem/models/animal/exporter.py 92.75% 5 Missing ⚠️
virtual_ecosystem/models/animal/animal_cohorts.py 94.11% 1 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #1270      +/-   ##
===========================================
- Coverage    95.02%   94.97%   -0.05%     
===========================================
  Files           71       71              
  Lines         7274     7344      +70     
===========================================
+ Hits          6912     6975      +63     
- Misses         362      369       +7     

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

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Copy Markdown
Collaborator

@davidorme davidorme left a comment

Choose a reason for hiding this comment

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

LGTM - just one question.

Comment on lines +144 to +148
# Internal state (match your refactor)
exporter._cohort_output_mode = "w"
exporter._trophic_output_mode = "w"
exporter._write_cohort_header = True
exporter._write_trophic_header = True
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Are these separated because it is possible that you might start outputting only to cohorts and not get interactions until later. For example, if you only had adult varanids in the simulation, and they just get hungrier and hungrier until some baby varanids turn up to eat?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

My thinking at the time was simply that keeping them distinct helps with debugging and updating down the road. I suppose it could be used for that as well.

@TaranRallings TaranRallings merged commit bde5e9a into develop Jan 22, 2026
13 checks passed
@TaranRallings TaranRallings deleted the 1247-animal-model---trophic-interaction-output branch January 22, 2026 13:39
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.

Animal Model - Trophic interaction output

4 participants