Skip to content

Animal-Plant piping class draft#986

Merged
TaranRallings merged 16 commits intodevelopfrom
908-animal---animal-plant-piping-update
Aug 29, 2025
Merged

Animal-Plant piping class draft#986
TaranRallings merged 16 commits intodevelopfrom
908-animal---animal-plant-piping-update

Conversation

@TaranRallings
Copy link
Copy Markdown
Collaborator

Description

There are two basic options that I'm exploring for making this work.

  1. Aggregate by plant functional type into classes containing different resource types. (plant_resources_2.py)
  2. Aggregate by resource type into classes containing different plant functional types. (plant_resources_3.py)

I suspect that the second approach will be more computationally effective. Most trophic relationships are done by resource type, not functional type. This makes it easier to sort through, say, a dictionary of fallen seeds in a grid cell to find the appropriate seeds than sorting through a list of plant functional types to see if each has seeds and then if you can even eat those specific seeds.

Feedback I am looking for:

  1. Which approach makes more sense to you?
  2. Help sorting through the data format for plants. I am having some trouble figuring out what exactly the plant data looks like when I get access to it such that I can allocate it properly. The draft code I've provided is sort of half made up to give a sense of what I'm trying to do.
    `

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

@TaranRallings TaranRallings requested a review from davidorme August 4, 2025 15:40
@TaranRallings TaranRallings self-assigned this Aug 4, 2025
@TaranRallings TaranRallings linked an issue Aug 4, 2025 that may be closed by this pull request
@davidorme
Copy link
Copy Markdown
Collaborator

I suspect that the second approach will be more computationally effective. Most trophic relationships are done by resource type, not functional type. This makes it easier to sort through, say, a dictionary of fallen seeds in a grid cell to find the appropriate seeds than sorting through a list of plant functional types to see if each has seeds and then if you can even eat those specific seeds.

At the moment, the PlantsModel isn't exposing very much at the plant functional type level through Data.

  • The two propagule arrays do have a PFT dimension - they potentially have different sizes.
  • layer_leaf_mass is aggregated across PFTs, although we could disaggregate by PFT
  • The subcanopy vegetation does not have PFTs at the moment - sosubcanopy_vegetation_biomass and subcanopy_seedbank_biomass are not structured that way.

The main worry I have right now is the stoichiometry. Each cohort will have stochiometric ratios. We can take the mass weighted average across resources to give "average" leaves/fruit - either across all PFTs like in the layer_leaf_mass or by PFTs like in the propagules. That's certainly the easiest solution! Ultimately though, animals might want to selectively feed on the most nutritious trees/fruit. That would force us to move to a per cohort resource rather than per PFT. The ugly thing there is that once you're at a cohort level, the data arrays are ragged which is all sorts of not very xarray but that may be something we just have to solve.

I don't have strong feelings about the two alternative implementations but I think your intuition about the integrated one is right. We're going to have to have that logic somewhere and I think it is going to be cleaner to set up resources where there is an established mapping between the existing animal foraging requirements and the available resources.

Minor things:

  • I don't think you have to handle trapping missing variable names. If they aren't defined, the PlantsModel is screwed up.
  • IIRC, the values in the data layers are per cell not per m2, so you don't have to scale by cell area.

@TaranRallings
Copy link
Copy Markdown
Collaborator Author

Ah interesting, so for now I can ignore PFTs for everything but propagules?

I am happy to do the easiest and simplest version right now and worry about more guided foraging patterns in the future.

I will go with the resource-type integrated classes for now then.

Copy link
Copy Markdown
Collaborator

@jacobcook1995 jacobcook1995 left a comment

Choose a reason for hiding this comment

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

Approach to fungal fruiting bodies looks sensible to me, I just had a couple of queries

# Build resource collections based on diet flags
plant_list: list[Resource] = []
prey_list: list[AnimalCohort] = []
# mushroom_list: list[Resource] = []
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.

why has this be added commented out?

cohort.forage_cohort(
plant_list=plant_list,
animal_list=prey_list,
mushroom_list=[],
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.

I think you would want to populate this based on self.fungal_fruiting_bodies

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.

(or something similar)

@TaranRallings TaranRallings merged commit 392d20e into develop Aug 29, 2025
4 of 5 checks passed
@TaranRallings TaranRallings deleted the 908-animal---animal-plant-piping-update branch January 9, 2026 15:00
@TaranRallings TaranRallings restored the 908-animal---animal-plant-piping-update branch January 9, 2026 15:00
@TaranRallings TaranRallings deleted the 908-animal---animal-plant-piping-update branch January 9, 2026 15:01
@davidorme davidorme mentioned this pull request Feb 5, 2026
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 - Animal-Plant Piping Update

3 participants