Skip to content

Fixes to Biomass draft#1494

Merged
davidorme merged 1 commit into1482-feature-branch-for-biomass-related-functionalityfrom
1493-error-in-biomass-implementation
Apr 1, 2026
Merged

Fixes to Biomass draft#1494
davidorme merged 1 commit into1482-feature-branch-for-biomass-related-functionalityfrom
1493-error-in-biomass-implementation

Conversation

@davidorme
Copy link
Copy Markdown
Collaborator

@davidorme davidorme commented Mar 31, 2026

Description

This PR:

  • Fixes a stupid mistake: the new BiomassTissue classes should not extract turnover - the biomass carbon is untouched by turnover, that's the whole point. So the tissue_turnover and extract_turnover methods are removed and collapse back into a single get_turnover method that returns the nutrient turnover losses for inclusion in the whole stem nutrient balancing.

    ETA: To clarify - I had setup the BiomassTissue.extract_turnover abstract method description and then the implementations in the subclasses to actually remove carbon and nutrient masses from the Tissue. This isn't what happens in turnover - a quantity of carbon is allocated to replace old tissue but the tissue mass is maintained. We need to know those masses to pass turnover into the correct pools but the tissue biomasses are unchanged. The method does also need to record the nutrient loss so that the stoichiometric balance of the individual can be resolved after all allocation has occurred.

  • Updates the functionality of elements_needed_for_growth. Back in Stoichiometry this just reported the elemental masses for nutrient balancing - however with Biomasses it makes more sense for this function to also be responsible for adding growth allocation to the carbon biomasses and similarly increasing nutrient allocations to tissues. This function also returns the new nutrient allocation for inclusion in whole stem element balancing. The method is renamed apply_growth.

These new BiomassTissue methods are now called by the relevant functions in the Biomasses class and the tests are updated to cover the new functionality and naming.

Fixes #1493

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

@davidorme
Copy link
Copy Markdown
Collaborator Author

@sallymatson I think there are some things about the internal representations that can be made more efficient, but this feels to me like it's shaking down into something fairly solid. I also think some of the code repetition can be reduced, but I'm going to worry about that later.

@davidorme davidorme requested a review from sallymatson March 31, 2026 19:58
@codecov-commenter
Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 94.99%. Comparing base (47f5007) to head (df77892).

Additional details and impacted files
@@                                    Coverage Diff                                    @@
##           1482-feature-branch-for-biomass-related-functionality    #1494      +/-   ##
=========================================================================================
- Coverage                                                  94.99%   94.99%   -0.01%     
=========================================================================================
  Files                                                         72       72              
  Lines                                                       7790     7787       -3     
=========================================================================================
- Hits                                                        7400     7397       -3     
  Misses                                                       390      390              

☔ 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

@sallymatson sallymatson left a comment

Choose a reason for hiding this comment

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

All looks sensible to me.

A bit hard to get my head around everything to give a 100% full review, but I trust the details etc and I agree that it's moving in a great direction.

@sallymatson
Copy link
Copy Markdown
Collaborator

Can you just clarify what you mean by this? "Fixes a stupid mistake: the new BiomassTissue classes should not extract turnover - the biomass carbon is untouched by turnover, that's the whole point."

@davidorme
Copy link
Copy Markdown
Collaborator Author

Yup - I've updated the PR description.

@davidorme davidorme merged commit fccbf75 into 1482-feature-branch-for-biomass-related-functionality Apr 1, 2026
13 checks passed
@davidorme davidorme deleted the 1493-error-in-biomass-implementation branch April 1, 2026 11:01
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